@referalli/sdk 0.0.0-stage → 0.3.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +132 -0
- package/LICENSE +21 -0
- package/README.md +236 -2
- package/dist/cjs/attribution.d.ts +105 -0
- package/dist/cjs/attribution.js +200 -0
- package/dist/cjs/browser.d.ts +41 -0
- package/dist/cjs/browser.js +88 -0
- package/dist/cjs/client.d.ts +97 -0
- package/dist/cjs/client.js +301 -0
- package/dist/cjs/consent/adapters/cookiebot.d.ts +7 -0
- package/dist/cjs/consent/adapters/cookiebot.js +49 -0
- package/dist/cjs/consent/adapters/cookiemunch.d.ts +8 -0
- package/dist/cjs/consent/adapters/cookiemunch.js +56 -0
- package/dist/cjs/consent/adapters/custom.d.ts +8 -0
- package/dist/cjs/consent/adapters/custom.js +39 -0
- package/dist/cjs/consent/adapters/didomi.d.ts +9 -0
- package/dist/cjs/consent/adapters/didomi.js +67 -0
- package/dist/cjs/consent/adapters/gcm.d.ts +10 -0
- package/dist/cjs/consent/adapters/gcm.js +78 -0
- package/dist/cjs/consent/adapters/gpp.d.ts +9 -0
- package/dist/cjs/consent/adapters/gpp.js +92 -0
- package/dist/cjs/consent/adapters/none.d.ts +3 -0
- package/dist/cjs/consent/adapters/none.js +30 -0
- package/dist/cjs/consent/adapters/onetrust.d.ts +8 -0
- package/dist/cjs/consent/adapters/onetrust.js +71 -0
- package/dist/cjs/consent/adapters/osano.d.ts +9 -0
- package/dist/cjs/consent/adapters/osano.js +71 -0
- package/dist/cjs/consent/adapters/tcf.d.ts +8 -0
- package/dist/cjs/consent/adapters/tcf.js +79 -0
- package/dist/cjs/consent/adapters/termly.d.ts +10 -0
- package/dist/cjs/consent/adapters/termly.js +61 -0
- package/dist/cjs/consent/adapters/usercentrics.d.ts +9 -0
- package/dist/cjs/consent/adapters/usercentrics.js +106 -0
- package/dist/cjs/consent/conformance.d.ts +22 -0
- package/dist/cjs/consent/conformance.js +33 -0
- package/dist/cjs/consent/gate.d.ts +23 -0
- package/dist/cjs/consent/gate.js +220 -0
- package/dist/cjs/consent/port.d.ts +105 -0
- package/dist/cjs/consent/port.js +72 -0
- package/dist/cjs/consent/registry.d.ts +17 -0
- package/dist/cjs/consent/registry.js +61 -0
- package/dist/cjs/consent/served.d.ts +15 -0
- package/dist/cjs/consent/served.js +26 -0
- package/dist/cjs/core.d.ts +77 -0
- package/dist/cjs/core.js +64 -0
- package/dist/cjs/errors.d.ts +42 -0
- package/dist/cjs/errors.generated.d.ts +183 -0
- package/dist/cjs/errors.generated.js +279 -0
- package/dist/cjs/errors.js +47 -0
- package/dist/cjs/generated.d.ts +15151 -0
- package/dist/cjs/generated.js +625 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.js +93 -0
- package/dist/cjs/mobile.d.ts +66 -0
- package/dist/cjs/mobile.js +69 -0
- package/dist/cjs/node.d.ts +209 -0
- package/dist/cjs/node.js +140 -0
- package/dist/cjs/outbox.d.ts +186 -0
- package/dist/cjs/outbox.js +324 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/resources.generated.d.ts +6002 -0
- package/dist/cjs/resources.generated.js +2090 -0
- package/dist/cjs/served.d.ts +25 -0
- package/dist/cjs/served.js +214 -0
- package/dist/cjs/sha256.d.ts +2 -0
- package/dist/cjs/sha256.js +86 -0
- package/dist/cjs/snippet.d.ts +99 -0
- package/dist/cjs/snippet.js +213 -0
- package/dist/cjs/stripe-events.d.ts +25 -0
- package/dist/cjs/stripe-events.js +117 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/cjs/webhooks.d.ts +76 -0
- package/dist/cjs/webhooks.js +159 -0
- package/dist/esm/attribution.d.ts +105 -0
- package/dist/esm/attribution.js +186 -0
- package/dist/esm/browser.d.ts +41 -0
- package/dist/esm/browser.js +68 -0
- package/dist/esm/client.d.ts +97 -0
- package/dist/esm/client.js +297 -0
- package/dist/esm/consent/adapters/cookiebot.d.ts +7 -0
- package/dist/esm/consent/adapters/cookiebot.js +46 -0
- package/dist/esm/consent/adapters/cookiemunch.d.ts +8 -0
- package/dist/esm/consent/adapters/cookiemunch.js +53 -0
- package/dist/esm/consent/adapters/custom.d.ts +8 -0
- package/dist/esm/consent/adapters/custom.js +36 -0
- package/dist/esm/consent/adapters/didomi.d.ts +9 -0
- package/dist/esm/consent/adapters/didomi.js +64 -0
- package/dist/esm/consent/adapters/gcm.d.ts +10 -0
- package/dist/esm/consent/adapters/gcm.js +75 -0
- package/dist/esm/consent/adapters/gpp.d.ts +9 -0
- package/dist/esm/consent/adapters/gpp.js +89 -0
- package/dist/esm/consent/adapters/none.d.ts +3 -0
- package/dist/esm/consent/adapters/none.js +27 -0
- package/dist/esm/consent/adapters/onetrust.d.ts +8 -0
- package/dist/esm/consent/adapters/onetrust.js +68 -0
- package/dist/esm/consent/adapters/osano.d.ts +9 -0
- package/dist/esm/consent/adapters/osano.js +68 -0
- package/dist/esm/consent/adapters/tcf.d.ts +8 -0
- package/dist/esm/consent/adapters/tcf.js +76 -0
- package/dist/esm/consent/adapters/termly.d.ts +10 -0
- package/dist/esm/consent/adapters/termly.js +58 -0
- package/dist/esm/consent/adapters/usercentrics.d.ts +9 -0
- package/dist/esm/consent/adapters/usercentrics.js +103 -0
- package/dist/esm/consent/conformance.d.ts +22 -0
- package/dist/esm/consent/conformance.js +30 -0
- package/dist/esm/consent/gate.d.ts +23 -0
- package/dist/esm/consent/gate.js +217 -0
- package/dist/esm/consent/port.d.ts +105 -0
- package/dist/esm/consent/port.js +67 -0
- package/dist/esm/consent/registry.d.ts +17 -0
- package/dist/esm/consent/registry.js +55 -0
- package/dist/esm/consent/served.d.ts +15 -0
- package/dist/esm/consent/served.js +22 -0
- package/dist/esm/core.d.ts +77 -0
- package/dist/esm/core.js +60 -0
- package/dist/esm/errors.d.ts +42 -0
- package/dist/esm/errors.generated.d.ts +183 -0
- package/dist/esm/errors.generated.js +231 -0
- package/dist/esm/errors.js +40 -0
- package/dist/esm/generated.d.ts +15151 -0
- package/dist/esm/generated.js +622 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/mobile.d.ts +66 -0
- package/dist/esm/mobile.js +64 -0
- package/dist/esm/node.d.ts +209 -0
- package/dist/esm/node.js +135 -0
- package/dist/esm/outbox.d.ts +186 -0
- package/dist/esm/outbox.js +316 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/resources.generated.d.ts +6002 -0
- package/dist/esm/resources.generated.js +2086 -0
- package/dist/esm/served.d.ts +25 -0
- package/dist/esm/served.js +207 -0
- package/dist/esm/sha256.d.ts +2 -0
- package/dist/esm/sha256.js +82 -0
- package/dist/esm/snippet.d.ts +99 -0
- package/dist/esm/snippet.js +210 -0
- package/dist/esm/stripe-events.d.ts +25 -0
- package/dist/esm/stripe-events.js +114 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/dist/esm/webhooks.d.ts +76 -0
- package/dist/esm/webhooks.js +153 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/package.json +105 -4
- package/src/attribution.ts +216 -0
- package/src/browser.ts +107 -0
- package/src/client.ts +351 -0
- package/src/codegen.ts +130 -0
- package/src/consent/adapters/cookiebot.ts +42 -0
- package/src/consent/adapters/cookiemunch.ts +49 -0
- package/src/consent/adapters/custom.ts +37 -0
- package/src/consent/adapters/didomi.ts +59 -0
- package/src/consent/adapters/gcm.ts +68 -0
- package/src/consent/adapters/gpp.ts +81 -0
- package/src/consent/adapters/none.ts +28 -0
- package/src/consent/adapters/onetrust.ts +64 -0
- package/src/consent/adapters/osano.ts +63 -0
- package/src/consent/adapters/tcf.ts +67 -0
- package/src/consent/adapters/termly.ts +54 -0
- package/src/consent/adapters/usercentrics.ts +97 -0
- package/src/consent/conformance.ts +47 -0
- package/src/consent/gate.ts +216 -0
- package/src/consent/port.ts +148 -0
- package/src/consent/registry.ts +60 -0
- package/src/consent/served.ts +24 -0
- package/src/core.ts +127 -0
- package/src/errors.generated.ts +277 -0
- package/src/errors.ts +57 -0
- package/src/generated.ts +14545 -0
- package/src/index.ts +100 -0
- package/src/mobile.ts +96 -0
- package/src/node.ts +291 -0
- package/src/outbox.ts +452 -0
- package/src/resources.generated.ts +2097 -0
- package/src/served.ts +229 -0
- package/src/sha256.ts +82 -0
- package/src/snippet.ts +305 -0
- package/src/stripe-events.ts +130 -0
- package/src/version.ts +2 -0
- package/src/webhooks.ts +207 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.21 - 2026-11-19
|
|
4
|
+
|
|
5
|
+
- Generated types for the program setting `merchantCreditBps` (part of each commission line paid as merchant credit, the rest as cash).
|
|
6
|
+
|
|
7
|
+
## 0.3.20 - 2026-11-18
|
|
8
|
+
|
|
9
|
+
- Published as `@referalli/sdk`. The unscoped `referalli` package stays at 0.3.16; install `@referalli/sdk` and change imports from `referalli` (and `referalli/browser`, ...) to `@referalli/sdk` (`@referalli/sdk/browser`, ...). Nothing else changed.
|
|
10
|
+
- Generated types for the program settings `payoutTaxFormPolicy` and `recordCountry`, `enableWidget` / `widgetEnabled` on auth connections, the typed `GenericBillingEvent` (with top-level `customerCreatedAt`), native import row types (`NativeImportRow`) and its dry-run report, the referee reward `issueOn` option and the `referee_reward` sandbox scenario. 0.3.19 was never published to npm; this release includes its changes.
|
|
11
|
+
|
|
12
|
+
## 0.3.19 - 2026-11-18
|
|
13
|
+
|
|
14
|
+
- Generated types and methods for per-purchase attribution (`attributionScope`, `productMatch`), link `label`, `status`, `cookieWindowDays`, `commission` and `conditions`, lookups by `code`, `PATCH /v1/coupons/{id}`, per-link timeseries, `commissionBaseMinor` and `maxCommissionMinor` on billing events and mobile purchases, rule `capPerPayment`, `effectiveAt` and the `first_earning_payment_after_referral` recurring type, mirrored referee rewards and the `referee_reward.reversed` webhook, `riskPolicy.minCustomerAgeDays` / `requirePriorPayment`, `payoutTaxFormPolicy`, per-line hold and approve, the `daily` payout schedule, server touches with `customerRef`, `productRef`, `kind` and `metadata`, native import (`POST /v1/import/native`), and linked programs with `exclusiveWith` / `priority`.
|
|
15
|
+
|
|
16
|
+
## 0.3.18 - 2026-11-18
|
|
17
|
+
|
|
18
|
+
- Generated types and methods for deep links (`POST /v1/partner/links/deep`), smartlinks (`/v1/partner/smartlinks`), partner product and coupon feeds (`/v1/partner/feeds/products`, `/v1/partner/feeds/coupons`), the program `caps`, `countries`, `trafficSources` and `payPerCall` settings, pay-per-call connections, numbers and calls, and `trafficSources` / `promotionUrl` on partner applications. The served `aff.js` loads `calls.js` with `data-calls="swap"` to show a referred visitor the partner's phone number. 0.3.17 was never published to npm; this release includes its changes.
|
|
19
|
+
|
|
20
|
+
## 0.3.17 - 2026-11-18
|
|
21
|
+
|
|
22
|
+
- Generated types and methods for product-scoped promotions (`scope`), earnings `bonuses` on commission rules, the program `cartWindowDays` setting, and `GET /v1/partner/links/match`.
|
|
23
|
+
- The served `aff.js` adds `referalli.cartAdd({productId, sku, quantity})` and, with `data-cart="auto"`, records Shopify and WooCommerce add-to-cart events for the cart extension.
|
|
24
|
+
|
|
25
|
+
## 0.3.16 - 2026-11-18
|
|
26
|
+
|
|
27
|
+
- Generated types and methods for the product catalog (`/v1/catalog/items`, feeds and sync), one-step store setup (`/v1/programs/{id}/store-setup`), partner product search and one-click product links (`/v1/partner/catalog`, `/v1/partner/links/product`), partner storefronts and the public storefront, sub-ID filters on stats and product reports, and the program `storefronts` setting.
|
|
28
|
+
- The served `aff.js` records `sub` (a sub-ID) on referral visits and can show the opt-in partner "get link" bar (`data-partner-bar="on"`).
|
|
29
|
+
|
|
30
|
+
## 0.3.15 - 2026-11-18
|
|
31
|
+
|
|
32
|
+
- Generated types and methods for store affiliate programs: `rateCard` on commission rules (per-category rates, excluded categories, `productCategories`, `indirectBps`), `lines` on generic billing events, `productRef` on links, `lineItems` on `commission.earned`, and the product reports (`GET /v1/reports/products`, `GET /v1/partner/reports/products`).
|
|
33
|
+
|
|
34
|
+
## 0.3.14 - 2026-11-18
|
|
35
|
+
|
|
36
|
+
- Generated types for what the API added today: `draft` on commission rules and on `GET /v1/programs/{id}/terms`, a program's `creditRate` and `credits` on `commission.settled`, and `programIds` on DSAR executor keys.
|
|
37
|
+
|
|
38
|
+
## 0.3.13 - 2026-11-18
|
|
39
|
+
|
|
40
|
+
- `stripeEventToBillingEvents` maps `checkout.session.completed` and `checkout.session.async_payment_succeeded` for a paid one-time Checkout with no invoice (`mode: payment`, no `invoice_creation`) to an `invoice_paid` keyed by its payment intent, so a one-time price earns. A session with an invoice is left to `invoice.paid`, never both. A guest with no Stripe customer is filed under `client_reference_id`, else the payment intent, which the session's metadata then links. `charge.refunded` and `charge.dispute.created` with no invoice carry the payment intent too, so they reverse it.
|
|
41
|
+
- Generated types and methods for what the API added since 0.3.12: program email settings and their test send, `trackingToken` and `effectiveTrackingConsent` on a program, `capPerReferral`, `domainDetail`, the test-mode partner delete's `removed`, and `graceHours` on secret rotation.
|
|
42
|
+
|
|
43
|
+
## 0.3.12 - 2026-11-11
|
|
44
|
+
|
|
45
|
+
- `stripeEventToBillingEvents` reads an invoice's linked id from `parent.subscription_details.metadata` even when the event also has a top-level `subscription_details`; sources merge with the invoice's own metadata winning, then subscription details, then the first line.
|
|
46
|
+
- Generated types for the new fields: dry-run `linkedCustomerRef`/`linkedFrom`/`billingAccount`, auth connection `lastRejectedAt`/`lastRejectedReason`, health check `severity`, and the program link-domain routes.
|
|
47
|
+
|
|
48
|
+
## 0.3.11 - 2026-11-11
|
|
49
|
+
|
|
50
|
+
- `sqliteOutboxStore({ execute })`: a durable outbox for SQLite and libSQL apps, next to `pgOutboxStore`.
|
|
51
|
+
- Generated methods for the new routes: link update and repoint, Stripe event forwarding, billing dry-run, org alerts, and the new program fields (`brand`, `termsUrl`, `faqUrl`, `supportUrl`, `trackingConsent`, `notificationEmails`, `howItWorksMd`).
|
|
52
|
+
|
|
53
|
+
## 0.3.10 - 2026-11-07
|
|
54
|
+
|
|
55
|
+
- Generated method for `PUT /v1/programs/{id}/commission-rule`, which publishes a rule only if it changed.
|
|
56
|
+
|
|
57
|
+
## 0.3.9 - 2026-11-07
|
|
58
|
+
|
|
59
|
+
- The payment-limit warning has a rate for every current currency, so a Syrian pound or similar payment no longer warns as if each unit were a dollar.
|
|
60
|
+
|
|
61
|
+
## 0.3.8 - 2026-11-07
|
|
62
|
+
|
|
63
|
+
- The `enqueue` warning over the payment limit now converts the amount to approximate US dollars first, as the server does, so an ordinary rupiah or yen payment no longer warns. Refunds and other events never warn: only payments are held.
|
|
64
|
+
|
|
65
|
+
## 0.3.7 - 2026-11-05
|
|
66
|
+
|
|
67
|
+
- `createOutbox.enqueue` warns when `amountGross` is over 1,000,000,000 minor units, the server's default limit. The event is still sent: the server holds it for release instead of refusing it.
|
|
68
|
+
|
|
69
|
+
## 0.3.6 - 2026-11-05
|
|
70
|
+
|
|
71
|
+
- `createOutbox.enqueue` also throws on a negative `amountGross` and on a currency that isn't ISO 4217, matching the server.
|
|
72
|
+
|
|
73
|
+
## 0.3.5 - 2026-11-05
|
|
74
|
+
|
|
75
|
+
- `createOutbox.enqueue` throws on what the server could only refuse: an unknown type, a non-integer amount, a missing or unparseable `occurredAt`, a bad currency, a missing `customerRef`.
|
|
76
|
+
- A `400` or `422` on send marks the event dead at once and fires `onDead`. `401`, `403`, `404`, `429` and `5xx` keep retrying.
|
|
77
|
+
|
|
78
|
+
## 0.3.4 - 2026-11-05
|
|
79
|
+
|
|
80
|
+
- New `pgOutboxStore({ query, table })`: an `OutboxStore` on a Postgres table through your own query function, with `migrate()` and `dead()`. It claims rows with `FOR UPDATE SKIP LOCKED` and a 5-minute lease, so replicas don't send one row twice and a row held by a dead process is retried.
|
|
81
|
+
- `OutboxStore` gains an optional `claim(now, leaseMs)`; stores without it work as before. New `onDead` option on `createOutbox`, called when an event hits `maxAttempts`.
|
|
82
|
+
- New `stripeEventToBillingEvents(event, { customerRef })`: maps `invoice.paid`, `charge.refunded`, `charge.dispute.created`, `customer.subscription.created` and `.deleted` to generic billing events, with no `stripe` dependency.
|
|
83
|
+
- New `buildBillingEvent()`: throws on `amountMinor` (the field is `amountGross`).
|
|
84
|
+
- Fixed: the outbox's retry time is a whole number of milliseconds, so a `bigint` column accepts it. The signed route's send now times out after 60 s instead of hanging a flush.
|
|
85
|
+
|
|
86
|
+
## 0.3.3 - 2026-11-03
|
|
87
|
+
|
|
88
|
+
- Types for billing account renames and deletions: `previousAccountRef` on `PUT /v1/billing/accounts/{accountRef}/owner`, `DELETE /v1/billing/accounts/{accountRef}`, and `billing_account.owner_changed` with `previousAccountRef`, `deleted` and a nullable `ownerCustomerRef`.
|
|
89
|
+
|
|
90
|
+
## 0.3.2 - 2026-11-03
|
|
91
|
+
|
|
92
|
+
- Cookie-free hand-off: `getHandoffToken()` on `aff.js` (`window.aff`) and the `referalli/browser` tracker returns a signed token of the visit's referral context (24 h, consent rules apply); `associate({ handoffToken })` on the Node client, and `referalliAuthEvents`' `getReferral` can return one.
|
|
93
|
+
- Typed client for the new endpoints: `GET /v1/org/tracking-tokens`, `POST /v1/referrals/handoff-tokens`, `GET`/`PUT /v1/billing/accounts/{accountRef}`, and the `billing_account.owner_changed` webhook event; error class for `invalid_handoff_token`.
|
|
94
|
+
- New `createOutbox({ store, connectionId, secret? })`: a durable queue for `generic` billing events. `enqueue(event)` stores it, `flush()` sends what is due (signed `POST /webhooks/billing/{id}`, or `POST /v1/billing/connections/{id}/events` with the API key) and retries failures with backoff (30 s doubling to 1 h, 50 attempts by default). Redelivery is safe: events are keyed by `providerEventId`. Ships `memoryOutboxStore()` and the `OutboxStore` interface for your own table.
|
|
95
|
+
|
|
96
|
+
## 0.3.1 - 2026-11-03
|
|
97
|
+
|
|
98
|
+
- New endpoints: `POST /v1/billing/connections/{id}/events` (billing events with an API key), `GET /v1/programs/handle-availability`, `PUT /v1/auth/connections/{id}/origins`, `GET /v1/auth/connections/{id}`; `terms` on public program pages; the `signup_and_pay` sandbox scenario; `name` and `scopes` on `PATCH /v1/api-keys/{id}`.
|
|
99
|
+
- Served `aff.js`: `data-cookie-domain` is used only when the page's host is on that domain (and has two labels); a refused domain cookie is rewritten host-only.
|
|
100
|
+
|
|
101
|
+
## 0.3.0 - 2026-11-02
|
|
102
|
+
|
|
103
|
+
- New `referalli/webhooks` entry point: verify and parse webhook deliveries without the full client.
|
|
104
|
+
- API additions: one-call referrers (`POST /v1/programs/{id}/referrers`), partner summary, `GET /v1/programs?slug=`, `portalUrl` on the org, portal links, program-scoped API keys and the Stripe balance credit rail.
|
|
105
|
+
- New typed errors `ProgramScopedKeyError` (403), `RestrictedSessionError` (403) and `StripeKeyRequiredError`.
|
|
106
|
+
- Also in this release: API key rotate, `apiVersion: "latest"`, enrollment `mint`, partner upsert `matchedBy`, paused webhook create and `programId` filter, per-program Stripe credit key, Stripe credit requeue, `effectiveAt` filters on FX rates and Stripe fixture replay (`/v1/sandbox/stripe-fixtures`).
|
|
107
|
+
- New typed errors `StripeKeyInvalidError`, `StripeKeyWrongModeError`, `StripeKeyPermissionError` (422), `StripeUnavailableError` (502) and `ApiKeyExpiredError` (409).
|
|
108
|
+
- Fixed: `(id, options)` calls keep working when a method gains a query parameter (options passed in the query slot are moved back).
|
|
109
|
+
|
|
110
|
+
## 0.2.0 - 2026-10-24
|
|
111
|
+
|
|
112
|
+
- API 2026-11-01 additions: 56 new operations (inbound signup connectors, billing product filters, per-org SSO and partner-portal sign-in, support-tool context cards, data-rights executors, account closure, rewards, integration health, plans, the event feed and bulk webhook replay) and 2 webhook topics (`webhook_endpoint.failing`, `webhook_endpoint.recovered`).
|
|
113
|
+
- New error code `reauth_required` (401): sign in again before changing payout details.
|
|
114
|
+
- Consent: `aff.js` and `referalli/browser` follow the merchant's consent manager (Cookie Munch, IAB TCF v2.2/GPP, Google Consent Mode v2, OneTrust, Cookiebot, Usercentrics, Didomi, Osano, Termly or a custom callback).
|
|
115
|
+
- The attribution cookie is written as `referalli_ctx` and the legacy `referally_ctx` twin, and either is read.
|
|
116
|
+
|
|
117
|
+
## 0.1.1
|
|
118
|
+
|
|
119
|
+
- Fixed: the published package now points at the built `dist/` output. 0.1.0 was published with its entry points at TypeScript source and could not be imported; it is deprecated.
|
|
120
|
+
|
|
121
|
+
## 0.1.0 (2026-10-23)
|
|
122
|
+
|
|
123
|
+
First release as `referalli`.
|
|
124
|
+
|
|
125
|
+
- `Referalli` client generated from the OpenAPI document: all 376 `/v1` operations as typed methods grouped by resource (`referalli.programs.list()`, `referalli.referrals.void(id)`), with request, query and response types.
|
|
126
|
+
- Retries with exponential backoff and jitter for network errors, timeouts, 408, 429 and 5xx, honouring `Retry-After`. Only idempotent requests and requests with an idempotency key are retried. Every POST gets an idempotency key, and the same key is sent on each retry.
|
|
127
|
+
- Per-attempt timeouts, `AbortSignal` support, and one error class per API error code (`NotFoundError`, `RateLimitedError`, …).
|
|
128
|
+
- Auto-paging: list methods can be awaited for one page or iterated with `for await` to get every item.
|
|
129
|
+
- Webhooks: `webhooks.constructEvent()` (async, WebCrypto) returns typed events, and `verifyWebhook()` / `constructWebhookEvent()` (sync) work in every runtime. Both use constant-time comparison, a 5-minute tolerance and rotation-safe multiple secrets.
|
|
130
|
+
- `referalli/browser`: a small referral tracker (`createTracker`, `getReferral`).
|
|
131
|
+
- `referalli/attribution`: helpers for the first-party referral cookie, shared with `@referalli/next` and `@referalli/express`.
|
|
132
|
+
- Dual ESM/CJS with types. Runs on Node 20+, Bun, Deno and edge runtimes.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Referalli
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,237 @@
|
|
|
1
|
-
#
|
|
1
|
+
# referalli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official Referalli SDK for JavaScript and TypeScript. It calls every API operation with full types, verifies webhooks, and includes a small browser referral tracker.
|
|
4
|
+
|
|
5
|
+
- Every one of the 376 `/v1` operations, grouped by resource, with request, query and response types generated from the OpenAPI document
|
|
6
|
+
- Retries with backoff and jitter that honour `Retry-After`, timeouts, idempotency keys and typed errors
|
|
7
|
+
- Auto-paging with `for await`
|
|
8
|
+
- Webhook verification with typed events
|
|
9
|
+
- Runs on Node 20+, Bun, Deno, Cloudflare Workers, Vercel Edge and browsers (`referalli/browser`)
|
|
10
|
+
- ESM and CommonJS, no dependencies
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @referalli/sdk
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Framework kits: [`@referalli/react`](https://www.npmjs.com/package/@referalli/react), [`@referalli/next`](https://www.npmjs.com/package/@referalli/next), [`@referalli/express`](https://www.npmjs.com/package/@referalli/express).
|
|
17
|
+
|
|
18
|
+
## Quickstart
|
|
19
|
+
|
|
20
|
+
Keep your secret `rk_` key on your server.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { Referalli } from '@referalli/sdk';
|
|
24
|
+
|
|
25
|
+
const referalli = new Referalli({ apiKey: process.env.REFERALLI_API_KEY });
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Create a referral link
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
const partner = await referalli.partners.create({ email: 'dana@example.com', displayName: 'Dana' });
|
|
32
|
+
const link = await referalli.links.create({
|
|
33
|
+
programId: 'prg_...',
|
|
34
|
+
partnerId: partner.id,
|
|
35
|
+
destinationUrl: 'https://example.com/pricing',
|
|
36
|
+
});
|
|
37
|
+
console.log(link.shortUrl ?? `https://example.com/pricing?via=${link.code}`); // share this
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Track a signup and a conversion
|
|
41
|
+
|
|
42
|
+
When someone signs up, attribute them to the partner who referred them. The referral context comes from the browser tracker or from the `@referalli/next` and `@referalli/express` cookie middleware:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
await referalli.associate({
|
|
46
|
+
programId: 'prg_...',
|
|
47
|
+
customerRef: user.id, // the id your billing provider sees
|
|
48
|
+
anonId: referral.anonId,
|
|
49
|
+
referralToken: referral.clickId ?? undefined,
|
|
50
|
+
idempotencyKey: `signup:${user.id}`,
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Payments from a connected billing provider (Stripe, Paddle and others) earn commissions on their own. To report a product event that pays a bounty:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
await referalli.trackEvent({
|
|
58
|
+
programId: 'prg_...',
|
|
59
|
+
customerRef: user.id,
|
|
60
|
+
event: 'activation',
|
|
61
|
+
idempotencyKey: `activation:${user.id}`,
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
To report value facts for ROI, such as a payment that was partly covered by store credit:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
await referalli.reportPayment({
|
|
69
|
+
customerRef: user.id,
|
|
70
|
+
currency: 'usd',
|
|
71
|
+
cashMinor: 4900,
|
|
72
|
+
creditAppliedMinor: 1000,
|
|
73
|
+
externalId: invoice.id,
|
|
74
|
+
occurredAt: invoice.paidAt,
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Verify a webhook
|
|
79
|
+
|
|
80
|
+
Webhooks are signed with [Standard Webhooks](https://www.standardwebhooks.com). Verify the raw body exactly as you received it.
|
|
81
|
+
|
|
82
|
+
**Next.js (App Router):**
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
// app/api/referalli/route.ts
|
|
86
|
+
import { webhooks } from '@referalli/sdk';
|
|
87
|
+
|
|
88
|
+
export async function POST(req: Request) {
|
|
89
|
+
const event = await webhooks.constructEvent(await req.text(), req.headers, process.env.REFERALLI_WEBHOOK_SECRET!);
|
|
90
|
+
switch (event.topic) {
|
|
91
|
+
case 'referral.created':
|
|
92
|
+
// event.data is typed for this topic
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
return Response.json({ received: true });
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`@referalli/next` wraps this as `createWebhookHandler({ secret, on: { 'referral.created': … } })`.
|
|
100
|
+
|
|
101
|
+
**Express:**
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import express from 'express';
|
|
105
|
+
import { webhooks, WebhookVerificationError } from '@referalli/sdk';
|
|
106
|
+
|
|
107
|
+
app.post('/webhooks/referalli', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
108
|
+
try {
|
|
109
|
+
const event = await webhooks.constructEvent(req.body, req.headers, process.env.REFERALLI_WEBHOOK_SECRET!);
|
|
110
|
+
// handle event.topic
|
|
111
|
+
res.json({ received: true });
|
|
112
|
+
} catch (err) {
|
|
113
|
+
if (err instanceof WebhookVerificationError) return res.status(400).json({ error: err.message });
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`@referalli/express` wraps this as the `referalliWebhook({ secret })` middleware, which also handles the raw body.
|
|
120
|
+
|
|
121
|
+
Deliveries signed more than 5 minutes ago, or more than 5 minutes in the future, are rejected (set this with `toleranceSec`). While you rotate a secret, pass both secrets as an array. `verifyWebhook(rawBody, headers, secret)` is a synchronous version that returns a boolean.
|
|
122
|
+
|
|
123
|
+
### Queue billing events (outbox)
|
|
124
|
+
|
|
125
|
+
So an outage longer than the client's retries does not lose a payment, queue `generic` billing events and flush them:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { createOutbox } from '@referalli/sdk';
|
|
129
|
+
|
|
130
|
+
const outbox = createOutbox({ store, connectionId: 'bcon_...', secret: process.env.REFERALLI_BILLING_SECRET });
|
|
131
|
+
await outbox.enqueue({ providerEventId: invoice.id, type: 'invoice_paid', customerRef: user.id, amountGross: 4900, currency: 'usd', occurredAt: invoice.paidAt });
|
|
132
|
+
setInterval(() => void outbox.flush(), 60_000);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`store` is `pgOutboxStore({ query, table })` for Postgres, safe across replicas, `sqliteOutboxStore({ execute, table })` for SQLite or libSQL (Turso), or an `OutboxStore` (`add`, `due`, `markSent`, `markFailed`, optional `claim`) of your own; `memoryOutboxStore()` is for tests. Already receiving Stripe webhooks? `stripeEventToBillingEvents` maps them, refunds and disputes included: see [Billing providers](https://referalli.com/docs/billing-providers). Events are keyed by `providerEventId`, so a resend is recorded once. See [SDKs](https://referalli.com/docs/sdks#queue-billing-events-outbox) for a store of your own.
|
|
136
|
+
|
|
137
|
+
## Configuration
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
const referalli = new Referalli({
|
|
141
|
+
apiKey: 'rk_live_...', // default: process.env.REFERALLI_API_KEY
|
|
142
|
+
baseUrl: 'https://referalli.com', // default; or process.env.REFERALLI_BASE_URL
|
|
143
|
+
timeout: 60_000, // ms per attempt
|
|
144
|
+
maxRetries: 2, // retries after the first attempt
|
|
145
|
+
retryBaseDelay: 500, // ms, doubled per retry with jitter, max 8 s
|
|
146
|
+
apiVersion: '2026-11-01', // sent as referalli-version; default: the version this SDK was generated against
|
|
147
|
+
mode: 'test', // sent as referalli-mode (session auth only; a key's mode is fixed)
|
|
148
|
+
fetch: customFetch, // default: global fetch
|
|
149
|
+
headers: { 'x-team': 'growth' },
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
You can override settings for a single request in the last argument:
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
await referalli.partners.create(
|
|
157
|
+
{ email: 'kai@example.com' },
|
|
158
|
+
{ idempotencyKey: `invite:${id}`, timeout: 5_000, maxRetries: 0, signal: controller.signal },
|
|
159
|
+
);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Retries.** A request is retried when the network fails, when it times out, and on `408`, `429`, `500`, `502`, `503` and `504`. The wait is `Retry-After` when the API sends one. Only requests that are safe to repeat are retried: `GET`, `PUT` and `DELETE`, plus any request with an idempotency key. Every `POST` gets a generated key, and the same key is sent on each retry, so a retried POST is never applied twice.
|
|
163
|
+
|
|
164
|
+
## Errors
|
|
165
|
+
|
|
166
|
+
Every error extends `ReferalliError`.
|
|
167
|
+
|
|
168
|
+
| Class | When |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `ApiError` | The API answered with an error. It has `status`, `code`, `requestId`, `docsUrl`, `details` and `retryAfter`. |
|
|
171
|
+
| `NotFoundError`, `ValidationError`, `RateLimitedError`, `AuthenticationError`, `PermissionDeniedError`, `ConflictError`, … | One subclass of `ApiError` for each [error code](https://referalli.com/docs/errors-and-limits). |
|
|
172
|
+
| `ApiConnectionError` | The API could not be reached, after all retries. |
|
|
173
|
+
| `ApiTimeoutError` | The request timed out, after all retries. |
|
|
174
|
+
| `WebhookVerificationError` | A webhook failed verification. `reason` is `missing_headers`, `timestamp` or `signature`. |
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { NotFoundError, RateLimitedError } from '@referalli/sdk';
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
await referalli.partners.retrieve('ptr_missing');
|
|
181
|
+
} catch (err) {
|
|
182
|
+
if (err instanceof NotFoundError) console.log(err.code, err.requestId);
|
|
183
|
+
else if (err instanceof RateLimitedError) console.log('retry in', err.retryAfter, 's');
|
|
184
|
+
else throw err;
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Paging
|
|
189
|
+
|
|
190
|
+
A list method returns a `ListPromise`. You can use it in three ways:
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
// One page: { object: 'list', data, has_more, next_cursor }
|
|
194
|
+
const page = await referalli.partners.list({ limit: 50 });
|
|
195
|
+
|
|
196
|
+
// Every item, fetching pages as you go
|
|
197
|
+
for await (const partner of referalli.partners.list({ limit: 100 })) {
|
|
198
|
+
console.log(partner.id);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Into an array, with a cap
|
|
202
|
+
const all = await referalli.partners.list().toArray({ limit: 1_000 });
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
`.pages()` iterates page by page. Nothing is requested until you await or iterate.
|
|
206
|
+
|
|
207
|
+
## Every operation
|
|
208
|
+
|
|
209
|
+
Methods follow the API paths: `referalli.programs.enrollments.approve(programId, enrollmentId)`, `referalli.webhookEndpoints.rotateSecret(id)` and `referalli.analytics.overview()`. You can also call any operation by its `operationId`:
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
await referalli.call('getPartnersId', { path: { id: 'ptr_1' } });
|
|
213
|
+
for await (const r of referalli.listAll('getReferrals', { query: { limit: 100 } })) {}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
To send a raw request with the client's auth, retries and error handling, use `referalli.request({ method, path, query, body })`.
|
|
217
|
+
|
|
218
|
+
The API's types are exported from the package root (`import type { Partner, Program } from '@referalli/sdk'`) and from `referalli/types`.
|
|
219
|
+
|
|
220
|
+
## Browser tracker
|
|
221
|
+
|
|
222
|
+
Only your public tracking token goes in the browser, never an `rk_` key.
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
import { createTracker } from '@referalli/sdk/browser';
|
|
226
|
+
|
|
227
|
+
const tracker = await createTracker({ publishableKey: 'tk_...' });
|
|
228
|
+
tracker.getReferral(); // { anonId, code, clickId, ts }
|
|
229
|
+
// after signup:
|
|
230
|
+
await tracker.trackSignup({ customerRef: user.id, email: user.email });
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The tracker reads `?via=`, `?ref=` or `?aff=` and `ref_click_id` from the landing URL. It keeps the referral in a first-party cookie on your domain and records the visit. Options: `persist: 'referral-only'` (use before consent), `cookieDays`, `firstTouch` and `cookieDomain`. Call `tracker.forget()` when a visitor withdraws consent.
|
|
234
|
+
|
|
235
|
+
## License
|
|
236
|
+
|
|
237
|
+
MIT
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The first-party referral context, shared by the browser tracker (`aff.js`,
|
|
3
|
+
* `referalli/browser`) and the server kits (`@referalli/next`,
|
|
4
|
+
* `@referalli/express`): what it is, how a landing URL updates it, and how it
|
|
5
|
+
* is stored in a cookie on the merchant's own domain. Isomorphic and
|
|
6
|
+
* dependency-free.
|
|
7
|
+
*/
|
|
8
|
+
/** Cookie (and localStorage key) holding the context. A wire name shared with every `aff.js` install; don't change it. */
|
|
9
|
+
export declare const REFERRAL_COOKIE = "referalli_ctx";
|
|
10
|
+
/**
|
|
11
|
+
* The pre-rename name of the same context. The browser tracker (`aff.js`,
|
|
12
|
+
* `referalli/browser`) writes the context under BOTH names, with the same
|
|
13
|
+
* value, attributes and expiry, and reads either.
|
|
14
|
+
*
|
|
15
|
+
* Why: integrations that read the cookie themselves may still read the pre-rename
|
|
16
|
+
* name. Atlas's connector and Cookie Munch's preset both read `referalli_ctx` now.
|
|
17
|
+
* The twin is written until 2027-01-31, announced in the changelog and on
|
|
18
|
+
* /docs/renamed-from-referally, then dropped (reading stays tolerant).
|
|
19
|
+
*
|
|
20
|
+
* TODO(legacy-ctx, 2027-01-31): stop writing the legacy name; keep reading it for
|
|
21
|
+
* one more cookie window after that.
|
|
22
|
+
*/
|
|
23
|
+
export declare const LEGACY_REFERRAL_COOKIE = "referally_ctx";
|
|
24
|
+
/** Every name the context is written and read under, current first. */
|
|
25
|
+
export declare const REFERRAL_COOKIE_NAMES: readonly string[];
|
|
26
|
+
/** Query parameters that carry a partner's referral code, in priority order. */
|
|
27
|
+
export declare const REFERRAL_PARAMS: readonly string[];
|
|
28
|
+
/** Query parameter carrying a click id from a Referalli redirect link (`/go/...`). */
|
|
29
|
+
export declare const CLICK_ID_PARAM = "ref_click_id";
|
|
30
|
+
export declare const DEFAULT_COOKIE_DAYS = 60;
|
|
31
|
+
export interface ReferralContext {
|
|
32
|
+
/** This browser's anonymous id (`a_…`). */
|
|
33
|
+
anonId: string;
|
|
34
|
+
/** The partner's referral code from `?via=` / `?ref=` / `?aff=`. */
|
|
35
|
+
code: string | null;
|
|
36
|
+
/** The click id from a redirect link. */
|
|
37
|
+
clickId: string | null;
|
|
38
|
+
/** When the context was first created (epoch ms). */
|
|
39
|
+
ts: number;
|
|
40
|
+
}
|
|
41
|
+
/** The stored shape: the context plus when it expires (epoch ms). */
|
|
42
|
+
export type StoredReferral = ReferralContext & {
|
|
43
|
+
exp?: number;
|
|
44
|
+
};
|
|
45
|
+
export interface MergeOptions {
|
|
46
|
+
now?: number;
|
|
47
|
+
/** Lifetime, 1–400 days. Default 60. */
|
|
48
|
+
cookieDays?: number;
|
|
49
|
+
/** Keep an unexpired first referral instead of replacing it. */
|
|
50
|
+
firstTouch?: boolean;
|
|
51
|
+
randomId?: () => string;
|
|
52
|
+
}
|
|
53
|
+
export declare const clampDays: (days: number | undefined) => number;
|
|
54
|
+
/** A fresh anonymous id: `a_` + 20 random base-36 characters. */
|
|
55
|
+
export declare function newAnonId(): string;
|
|
56
|
+
/** The referral a URL carries: the first of `params` that is set, and `ref_click_id`. */
|
|
57
|
+
export declare function referralFromUrl(url: string | URL, params?: readonly string[]): {
|
|
58
|
+
code: string | null;
|
|
59
|
+
clickId: string | null;
|
|
60
|
+
};
|
|
61
|
+
/** Parse a stored context (the cookie's or localStorage's value, URI-encoded or not). Expired or malformed → null. */
|
|
62
|
+
export declare function parseReferral(raw: string | null | undefined, now?: number): StoredReferral | null;
|
|
63
|
+
/**
|
|
64
|
+
* The context from a `Cookie` request header. `names` are tried in order
|
|
65
|
+
* (default: `REFERRAL_COOKIE_NAMES`, the current name then the legacy one);
|
|
66
|
+
* add an older cookie name to keep reading contexts saved under it.
|
|
67
|
+
*/
|
|
68
|
+
export declare function referralFromCookieHeader(cookieHeader: string | null | undefined, now?: number, names?: readonly string[]): StoredReferral | null;
|
|
69
|
+
/**
|
|
70
|
+
* The context after a page view: a new referral in the URL replaces the
|
|
71
|
+
* stored one (unless `firstTouch` keeps an unexpired one), and a referral
|
|
72
|
+
* restarts the expiry window. Same rules as `aff.js`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function mergeReferral(stored: StoredReferral | null, fromUrl: {
|
|
75
|
+
code: string | null;
|
|
76
|
+
clickId: string | null;
|
|
77
|
+
}, opts?: MergeOptions): StoredReferral;
|
|
78
|
+
export interface CookieOptions {
|
|
79
|
+
cookieDays?: number;
|
|
80
|
+
/** Share with subdomains, e.g. `.example.com`. */
|
|
81
|
+
domain?: string;
|
|
82
|
+
/** Default true. Turn off only for plain-http local development. */
|
|
83
|
+
secure?: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A `Set-Cookie` header value for the context. Not HttpOnly on purpose: the
|
|
87
|
+
* browser tracker reads the same cookie.
|
|
88
|
+
*/
|
|
89
|
+
export declare function serializeReferralCookie(ctx: StoredReferral, opts?: CookieOptions): string;
|
|
90
|
+
/**
|
|
91
|
+
* `Set-Cookie` values for the context under every name: `referalli_ctx` and
|
|
92
|
+
* its legacy twin `referally_ctx`, same value, attributes and expiry (see
|
|
93
|
+
* LEGACY_REFERRAL_COOKIE). Server kits append each one.
|
|
94
|
+
*/
|
|
95
|
+
export declare function serializeReferralCookies(ctx: StoredReferral, opts?: CookieOptions): string[];
|
|
96
|
+
/** `Set-Cookie` values that delete the context under every name (consent denied or withdrawn). */
|
|
97
|
+
export declare function clearReferralCookies(opts?: Pick<CookieOptions, 'domain' | 'secure'>): string[];
|
|
98
|
+
/** Fields for `associate` (server-side attribution at signup) from a context. */
|
|
99
|
+
export declare function associateFields(ctx: ReferralContext | null | undefined): {
|
|
100
|
+
anonId?: string;
|
|
101
|
+
referralToken?: string;
|
|
102
|
+
couponCode?: string;
|
|
103
|
+
};
|
|
104
|
+
/** SHA-256 hex of a normalised (trimmed, lower-cased) email, for `emailHash` (WebCrypto). */
|
|
105
|
+
export declare function hashEmail(email: string): Promise<string>;
|