Repository navigation
Affonso
Typed Affonso affiliate-marketing API client for Deno, Bun, Node.js and Cloudflare Workers. Run your affiliate program from your backend: create and manage affiliates and sign them into the hosted portal, track clicks, signups and conversions server-side (with refunds), manage referrals, commissions, bonuses, payouts and coupons, read your program, and verify webhook signatures.
Affonso is an affiliate platform for SaaS. Its pixel tracks visits in the
browser; this connect covers the server side — the REST API at
https://api.affonso.io/v1 and the signed webhooks it sends back.
| Area | Methods |
|---|---|
| Affiliates |
listAffiliates, listAllAffiliates, getAffiliate, createAffiliate, updateAffiliate, deleteAffiliate, createPortalToken
|
| Tracking |
trackClick, recordSignup, createConversion, refundConversion
|
| Referrals |
listReferrals, listAllReferrals, getReferral, createReferral, updateReferral, deleteReferral
|
| Commissions |
listCommissions, listAllCommissions, getCommission, createCommission, createBonus, updateCommission, deleteCommission
|
| Payouts |
listPayouts, listAllPayouts, getPayout, updatePayout
|
| Coupons |
listCoupons, listAllCoupons, getCoupon, createCoupon, deleteCoupon
|
| Program | getProgram |
| Webhooks | verifyWebhook |
Things worth knowing up front:
-
One API key, one program. The key (
sk_live_...) selects the program, and its permissions (read:affiliates,write:referrals, ...) decide what it can call — a missing one isFORBIDDEN. Affonso has no sandbox yet, so every write lands in your real program. -
Amounts are decimals in major units —
99.00is ninety-nine dollars. -
Field names follow the wire. Mostly snake_case; payouts and clicks are
camelCase. List pagination is normalized for you (Affonso spells it both
ways), and
listAll*iterators walk every page.
import { Affonso } from '@tundraconnect/affonso';
const client = new Affonso({
auth: { type: 'BEARER', token: 'sk_live_your_api_key' },
});
const program = await client.getProgram();
console.log(program.name, program.plan.tier);Your tests don't need to fake HTTP. Have your code take an Affonso instance
and pass in a stand-in that returns the shapes from
@tundraconnect/affonso/schemas or throws a real AffonsoError:
import { AffonsoError } from '@tundraconnect/affonso/errors';
const outage = new AffonsoError('SERVICE_UNAVAILABLE', { status: 503 });
console.log(outage.code, outage.transient);To exercise the client itself against a fake transport, pass a fetch
function in the constructor options. The client sends every request
through it, so the same option fits a proxy, a tracing wrapper or an
SSRF-pinned fetch.
| Topic | Description |
|---|---|
| API | Client configuration and endpoint methods |
| Errors | Error codes and diagnostic metadata |
| Schemas | Public Guardian schemas and inferred types |
Deno:
deno add jsr:@tundraconnect/affonsoBun:
bunx jsr add @tundraconnect/affonsoNode.js:
npx jsr add @tundraconnect/affonsoconst affiliate = await client.createAffiliate({
name: 'Jane Smith',
email: 'jane@example.com',
tracking_id: 'jane-smith', // their ?ref= code; generated when omitted
payout_method: 'paypal',
payout_details: { email: 'jane@example.com' },
});
// Later: a one-click, 5-minute link into the hosted affiliate portal.
const { portalUrl } = await client.createPortalToken(affiliate.id);
console.log(portalUrl);// A visitor arrives on an affiliate link: record the click, keep its id.
const click = await client.trackClick({
trackingId: 'jane-smith',
referrer: 'https://janes-blog.example/review',
utmSource: 'blog',
});
// They sign up: the click becomes a lead.
const lead = await client.recordSignup({
click_id: click.id,
email: 'customer@example.com',
external_user_id: 'user_42',
});
if (lead.status === 'rejected') console.warn('blocked by a fraud rule');Affonso finds the referral, matches the incentive and calculates the
commission. external_event_id makes retries safe — the same value returns
the existing conversion instead of creating a second one.
const conversion = await client.createConversion({
external_user_id: 'user_42',
sale_amount: 99,
sale_amount_currency: 'USD',
external_event_id: 'in_2026_000145', // e.g. your invoice id
is_subscription: true,
interval: 'monthly',
});
console.log(conversion.commission_created, conversion.commission_amount);
// The customer is refunded half: the commission shrinks with it.
await client.refundConversion(conversion.id, {
amount: 49.5,
external_event_id: 're_2026_000017',
});for await (const payout of client.listAllPayouts({ status: 'pending' })) {
// ...send the money, then record it. Completing a payout marks every
// commission in it paid.
await client.updatePayout(payout.id, {
status: 'processing',
});
}Pass the raw body — await req.text(), never re-serialized JSON — and
the endpoint's signing secret, as-is:
async function handle(req: Request): Promise<Response> {
const event = await client.verifyWebhook({
payload: await req.text(),
headers: req.headers,
secret: 'your-64-char-hex-signing-secret',
});
if (event.type === 'referral.converted') {
console.log('converted', event.data.referralId);
}
return Response.json({ received: true });
}
console.log(typeof handle);Deliveries are retried for up to 48 hours, so dedupe on event.id.
MIT. Part of Tundra Connect, typed vendor API clients for Deno, Bun, Node.js and Cloudflare Workers.
- Affonso
- Algolia
- AviationWeather
- AzureBlob
- Binance
- CloudflareDNS
- CloudflareEmail
- CloudflareKV
- CloudflareSaaS
- CloudflareTurnstile
- CoinGecko
- Deribit
- Discord
- DodoPayments
- EIA
- GCS
- GoogleAnalytics
- GoogleCertificateManager
- GoogleWebRisk
- Kalshi
- ntfy
- OpenExchange
- OpenMeteo
- OpenWeatherMap
- Paddle
- PayPal
- Polymarket
- Pyth
- Razorpay
- Resend
- S3
- SendGrid
- Sentry
- Slack
- Stripe
- Telegram
- Twilio
- UpstashRedis
- URLhaus