JavaScript SDK
A typed client for Node.js, Bun, Deno, and edge runtimes.
Install
npm install @referral-api/jsCreate a client
Prop
Type
Typed responses
Every method is fully typed. Hover over the code below to see the types.
import { } from '@referral-api/js';
const = new ({ : 'sk_test_51Hx' });
const { data } = await ..({ : 'unlocked' });
const owed = .((, ) => + ., 0);Errors
Failed requests throw a ReferralApiError with the same fields as the API error object.
import { ReferralApiError } from '@referral-api/js';
try {
await client.referrers.create({ programId: 'prog_8Hq2LmN4', externalId: 'user_1042', email: 'maya@example.com' });
} catch (error) {
if (error instanceof ReferralApiError && error.type === 'conflict') {
// this customer is already enrolled
}
}How is this guide?