Backend Integration Guide (Node.js / TypeScript)
Installation
npm install @aldero/sdkInitialize (Server-Side)
import { AlderoClient } from '@aldero/sdk';
const aldero = new AlderoClient({
domain: 'aldero.io',
tenantSlug: 'myapp',
apiKey: process.env.BILLING_API_KEY, // bil_ prefixed key
});Check Entitlements
app.post('/api/premium-action', async (req, res) => {
const { userId } = req.auth;
const entitlements = await aldero.billing.getEntitlements(userId);
if (!entitlements.features.includes('pro_features')) {
return res.status(403).json({ error: 'Pro subscription required' });
}
// Proceed with premium action
});Consume Credits
app.post('/api/send-fax', async (req, res) => {
const { userId, pageCount, destination } = req.body;
try {
const balance = await aldero.billing.adjustCredits(userId, {
type: 'usage',
amount: -pageCount,
description: `Fax to ${destination} (${pageCount} pages)`,
referenceId: faxId,
});
// balance is the new remaining balance
// Proceed with sending fax
} catch (err) {
if (err instanceof AlderoError && err.statusCode === 402) {
return res.status(402).json({ error: 'Insufficient credits' });
}
throw err;
}
});Send Notifications
// Use a notification API key
const ntfClient = new AlderoClient({
domain: 'aldero.io',
tenantSlug: 'myapp',
apiKey: process.env.NOTIFICATION_API_KEY, // ntf_ prefixed key
});
// Send push notification
await ntfClient.notifications.send({
templateName: 'order-confirmation',
channel: 'push',
to: userId,
variables: {
orderNumber: '12345',
total: '$29.99',
},
});
// Send email
await ntfClient.notifications.send({
templateName: 'welcome-email',
channel: 'email',
to: 'user@example.com',
variables: { name: 'John' },
});Sync Entitlements from RevenueCat
// Useful for recovery or manual reconciliation
const result = await aldero.billing.syncUser(userId);
console.log(`Synced: ${result.synced.length}, Errors: ${result.errors.length}`);List Products (for Server-Rendered Pricing Pages)
const products = await aldero.billing.listProducts();
// Group by type
const creditPacks = products.filter(p => p.interval === 'one_time');
const subscriptions = products.filter(p => p.interval !== 'one_time');Multiple Services
Each service has its own API key prefix:
bil_— Billing servicentf_— Notification service
For operations spanning multiple services, create separate clients:
const billing = new AlderoClient({
domain: 'aldero.io',
tenantSlug: 'myapp',
apiKey: process.env.BILLING_API_KEY,
});
const notifications = new AlderoClient({
domain: 'aldero.io',
tenantSlug: 'myapp',
apiKey: process.env.NOTIFICATION_API_KEY,
});Environment Variables
ALDERO_DOMAIN=aldero.io
ALDERO_TENANT_SLUG=myapp
BILLING_API_KEY=bil_...
NOTIFICATION_API_KEY=ntf_...