@atlasauth/backend 0.10.0 → 0.11.0
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 +8 -0
- package/README.md +55 -0
- package/dist/client/error.d.ts +4 -0
- package/dist/client/error.js +4 -0
- package/dist/client/error.js.map +1 -1
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/referrals.d.ts +210 -0
- package/dist/client/referrals.js +39 -0
- package/dist/client/referrals.js.map +1 -0
- package/dist/client/users.d.ts +85 -0
- package/dist/client/users.js +15 -0
- package/dist/client/users.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/referrals.d.ts +199 -0
- package/dist/referrals.js +121 -0
- package/dist/referrals.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlasauth/backend changelog
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
- **Referral attribution settings.** New `referrals` namespace: `get()` and `update(body, idempotencyKey?)` (`GET`/`PATCH /v1/instance/referrals`; `ReferralSettings`, `UpdateReferralSettingsBody` with nested `security`: `ReferralSecuritySettings` `challenge_referred_signups`, `on_high_risk`, `hold_until_email_verified`, `max_referred_signups_per_ip_hour`), `test()` (`ReferralConnectionTest`), `listCalls({ limit?, status?, kind?, user_id? })` (`ReferralCall`, `ListReferralCallsParams`) and `retryCall(id, idempotencyKey?)`. Also `ReferralProviderInfo`, `ReferralProviderCapabilities`, `ReferralConnectionStatus`, `ReferralRisk`, `ReferralCallKind`, `ReferralCallStatus`.
|
|
5
|
+
- **Users.** `User` gains optional `referral` (`UserReferral`: `partner_id`, `referrer_external_id`, `referrer_user_id`, `matched_via`, `status`, `risk_level`, `flagged`), `referral_code` and `referral_link`. `CreateUserBody` accepts `referral` (`CreateUserReferralInput`: `code`, `click_id`, `anon_id`) and `referral_code`; `UpdateUserBody` accepts `referral_code` (`null` clears). New `users.flagReferral(id, { reason? }, idempotencyKey?)` (`POST /v1/users/:id/referral/flag`, `UserReferralFlag`).
|
|
6
|
+
- **Webhooks.** `UserReferralAttributedEvent` types the `data` of the new `user.referral_attributed` event (the referral platform answered after `user.created`).
|
|
7
|
+
- **Error codes.** `AtlasErrorCodes` adds `REFERRALS_NOT_CONFIGURED` (422) and `REFERRAL_CODE_TAKEN` (409). Preflight can report `referrals_enabled_unverified` and `referrals_without_bot_protection`.
|
|
8
|
+
- **Referral protocol receiver.** `verifyReferralRequest({ body, headers, secret, path?, expectedOp?, now?, toleranceMs? })` verifies a call from Atlas to a referral platform (the webhook signature scheme; every call is a `POST` whose signed body carries `op` and `customerRef`) and returns `call` by operation (`ReferralProtocolCall`: `signup`, `erase`, `export` with `test`, `partner`, `signal`), plus `deliveryId`, `timestamp` and `idempotencyKey`. It refuses (`ReferralVerifyFailure`) a body that is not an object (`malformed_body`), a missing or unknown `op` (`missing_op`, `unknown_op`), a path that is not a protocol endpoint (`unknown_endpoint`) and an `op` that does not match the path or `expectedOp` (`op_mismatch`). Payload types: `ReferralSignupPayload`, `ReferralSignupResponse`, `ReferralErasePayload`, `ReferralExportPayload`, `ReferralPartnerPayload`, `ReferralSignalPayload`, `ReferralSignalType`, `ReferralContext`, `ReferralRiskVerdict`, `ReferralOp`; `referralOpForPath`; constants `REFERRAL_OP_ENDPOINTS`, `REFERRAL_CONNECTION_TEST_REF`, `REFERRAL_PROTOCOL_USER_AGENT`.
|
|
9
|
+
- **Compatible.** New methods, types, optional fields and constants only.
|
|
10
|
+
|
|
3
11
|
## 0.10.0
|
|
4
12
|
- **Trusted reverse proxy secret.** `instanceSecurity.getProxySecret()` (`ProxySecret`: `set`, `created_at`, `previous_expires_at`, `secret_header`, `client_ip_header`), `instanceSecurity.createProxySecret({ overlap_seconds? })` (`ProxySecretCreated`: adds `secret`, shown once, and `rotated`; `CreateProxySecretBody`) and `instanceSecurity.deleteProxySecret()`. A proxy that serves the Frontend API from your own origin sends the secret in `X-Atlas-Proxy-Secret` and the browser's IP in `X-Atlas-Client-IP`; Atlas then uses that IP for rate limits, lockout, risk signals, geo, audit logs and session metadata.
|
|
5
13
|
- **Managed email feedback on Resend.** `ManagedEmail.feedback_webhook` is now also returned for Resend (on create and verify): Atlas registers a bounce / complaint webhook on your own Resend account, so `usage.bounces` / `usage.complaints` count for Resend domains too.
|
package/README.md
CHANGED
|
@@ -401,3 +401,58 @@ To check the route end to end, `oauthClients.testBackchannelLogout(id)` sends a
|
|
|
401
401
|
`verifyWebhook` checks the signature on events Atlas sends to your webhook endpoints. You manage endpoints with `atlas.webhooks.endpoints`: create, update, reveal or rotate a secret, send a test event, and redeliver a past delivery.
|
|
402
402
|
|
|
403
403
|
The `atlas-signature` header can carry more than one signature, separated by spaces (`v1,<sig> v1,<sig>`). While an endpoint secret rotates, Atlas may sign each delivery with the old and the new secret. `verifyWebhook` accepts the delivery when any one signature matches your secret.
|
|
404
|
+
|
|
405
|
+
## Referral attribution
|
|
406
|
+
|
|
407
|
+
With referral attribution on, Atlas reports every interactive sign-up to your referral platform before `user.created` is sent. The answer lands on the user: `referral` (who referred them, or null), `referral_code` and `referral_link` (the user's own code and link, when they are a referrer).
|
|
408
|
+
|
|
409
|
+
```ts
|
|
410
|
+
await atlas.referrals.update({
|
|
411
|
+
enabled: true,
|
|
412
|
+
provider: 'webhook', // the Atlas referral protocol; or a built-in vendor adapter
|
|
413
|
+
endpoint_url: 'https://referrals.example.com/atlas',
|
|
414
|
+
signing_secret: process.env.REFERRAL_SIGNING_SECRET,
|
|
415
|
+
auto_enroll_users: true,
|
|
416
|
+
link_template: 'https://app.example.com/join?ref={code}',
|
|
417
|
+
security: { on_high_risk: 'hold' },
|
|
418
|
+
});
|
|
419
|
+
const test = await atlas.referrals.test(); // { ok, http_status, latency_ms, error? }
|
|
420
|
+
const failed = await atlas.referrals.listCalls({ status: 'failed', limit: 20 });
|
|
421
|
+
await atlas.referrals.retryCall(failed.data[0]!.id);
|
|
422
|
+
|
|
423
|
+
const user = await atlas.users.get('user_123');
|
|
424
|
+
user.referral?.referrer_user_id;
|
|
425
|
+
await atlas.users.update('user_123', { referral_code: 'ada-1' }); // 409 REFERRAL_CODE_TAKEN if held
|
|
426
|
+
await atlas.users.flagReferral('user_123', { reason: 'self-referral' });
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Enabling without what the provider needs is `422 REFERRALS_NOT_CONFIGURED`. When the platform answers late, Atlas sends the `user.referral_attributed` webhook (`UserReferralAttributedEvent`). Preflight may report `referrals_enabled_unverified` and `referrals_without_bot_protection`.
|
|
430
|
+
|
|
431
|
+
### Receive the referral protocol (referral platforms)
|
|
432
|
+
|
|
433
|
+
A referral platform that implements the Atlas referral protocol verifies Atlas's calls with `verifyReferralRequest`. Every call is a `POST` signed like a webhook, and its JSON body says which operation it is (`op`): `signup`, `erase`, `export`, `partner` or `signal`. Pass the path the call arrived on: a signed body whose `op` does not match the endpoint is refused (`op_mismatch`).
|
|
434
|
+
|
|
435
|
+
```ts
|
|
436
|
+
import { verifyReferralRequest } from '@atlasauth/backend';
|
|
437
|
+
|
|
438
|
+
app.post('/atlas/:endpoint', express.raw({ type: '*/*' }), async (req, res) => {
|
|
439
|
+
const { verified, call } = verifyReferralRequest({
|
|
440
|
+
body: req.body,
|
|
441
|
+
headers: req.headers,
|
|
442
|
+
secret: process.env.REFERRAL_SIGNING_SECRET!,
|
|
443
|
+
path: req.path, // or expectedOp: 'signup' on a handler for one endpoint
|
|
444
|
+
});
|
|
445
|
+
if (!verified || !call) return res.sendStatus(401);
|
|
446
|
+
switch (call.op) {
|
|
447
|
+
case 'signup': // ReferralSignupPayload → answer ReferralSignupResponse
|
|
448
|
+
return res.json({ referral: await match(call.payload), partner: await enroll(call.payload) });
|
|
449
|
+
case 'export': // the connection test sends test: true
|
|
450
|
+
return call.test ? res.sendStatus(404) : res.json(await exportFor(call.payload.customerRef));
|
|
451
|
+
default: // erase, partner, signal
|
|
452
|
+
await handle(call);
|
|
453
|
+
return res.sendStatus(204);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
A retry of one call keeps its `atlas-id` (`deliveryId`). Sign-ups are idempotent on `customerRef`: answer a retry the same way.
|
package/dist/client/error.d.ts
CHANGED
|
@@ -57,6 +57,10 @@ export declare const AtlasErrorCodes: {
|
|
|
57
57
|
readonly DEVELOPMENT_EMAIL_LIMIT_REACHED: "DEVELOPMENT_EMAIL_LIMIT_REACHED";
|
|
58
58
|
/** 422 — the development sender sends only Atlas's own sign-in emails, never custom templates. */
|
|
59
59
|
readonly DEVELOPMENT_EMAIL_TEMPLATE_NOT_ALLOWED: "DEVELOPMENT_EMAIL_TEMPLATE_NOT_ALLOWED";
|
|
60
|
+
/** 422 — referrals cannot be enabled until the provider's needs are set (`meta` names what is missing). */
|
|
61
|
+
readonly REFERRALS_NOT_CONFIGURED: "REFERRALS_NOT_CONFIGURED";
|
|
62
|
+
/** 409 — another user on the instance already holds that referral code. */
|
|
63
|
+
readonly REFERRAL_CODE_TAKEN: "REFERRAL_CODE_TAKEN";
|
|
60
64
|
/** The billing plan still has subscribers and cannot be removed. */
|
|
61
65
|
readonly PLAN_IN_USE: "PLAN_IN_USE";
|
|
62
66
|
/** The key is valid but for another API surface (e.g. a platform key on the Backend API). */
|
package/dist/client/error.js
CHANGED
|
@@ -53,6 +53,10 @@ exports.AtlasErrorCodes = {
|
|
|
53
53
|
DEVELOPMENT_EMAIL_LIMIT_REACHED: 'DEVELOPMENT_EMAIL_LIMIT_REACHED',
|
|
54
54
|
/** 422 — the development sender sends only Atlas's own sign-in emails, never custom templates. */
|
|
55
55
|
DEVELOPMENT_EMAIL_TEMPLATE_NOT_ALLOWED: 'DEVELOPMENT_EMAIL_TEMPLATE_NOT_ALLOWED',
|
|
56
|
+
/** 422 — referrals cannot be enabled until the provider's needs are set (`meta` names what is missing). */
|
|
57
|
+
REFERRALS_NOT_CONFIGURED: 'REFERRALS_NOT_CONFIGURED',
|
|
58
|
+
/** 409 — another user on the instance already holds that referral code. */
|
|
59
|
+
REFERRAL_CODE_TAKEN: 'REFERRAL_CODE_TAKEN',
|
|
56
60
|
/** The billing plan still has subscribers and cannot be removed. */
|
|
57
61
|
PLAN_IN_USE: 'PLAN_IN_USE',
|
|
58
62
|
/** The key is valid but for another API surface (e.g. a platform key on the Backend API). */
|
package/dist/client/error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/client/error.ts"],"names":[],"mappings":";;;AAoBA,MAAa,aAAc,SAAQ,KAAK;IACpB,IAAI,GAAG,eAAe,CAAC;IACzC,0CAA0C;IACjC,MAAM,CAAS;IACxB,8CAA8C;IACrC,MAAM,CAAmB;IAElC,YAAY,MAAc,EAAE,MAAwB,EAAE,OAAgB;QACpE,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,wCAAwC,MAAM,EAAE,CAAC,CAAC;QACzF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,uEAAuE;QACvE,sEAAsE;QACtE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,uEAAuE;IACvE,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;IAC9B,CAAC;IAED,yEAAyE;IACzE,OAAO,CAAC,IAAY;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAClD,CAAC;CACF;AAzBD,sCAyBC;AAED;;;;GAIG;AACU,QAAA,eAAe,GAAG;IAC7B,+EA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BAAmB;IACtC,gDAAgD;IAChD,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;IACtB,iBAAiB,EAAE,mBAAmB;IACtC,YAAY,EAAE,cAAc;IAC5B,4FAA4F;IAC5F,oBAAoB,EAAE,sBAAsB;IAC5C,yFAAyF;IACzF,cAAc,EAAE,gBAAgB;IAChC,eAAe,EAAE,iBAAiB;IAClC,oBAAoB,EAAE,sBAAsB;IAC5C,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,UAAU;CACZ,CAAC"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ declare function buildNamespaces(request: RequestFn): {
|
|
|
23
23
|
duration_in_seconds?: number;
|
|
24
24
|
}): Promise<import("./users").User>;
|
|
25
25
|
unlock(id: string): Promise<import("./users").User>;
|
|
26
|
+
flagReferral(id: string, body?: {
|
|
27
|
+
reason?: string;
|
|
28
|
+
}, idempotencyKey?: string): Promise<import("./users").UserReferralFlag>;
|
|
26
29
|
delete(id: string): Promise<import("./types").DeletedObject>;
|
|
27
30
|
resetMfa(id: string): Promise<{
|
|
28
31
|
object: "user";
|
|
@@ -970,6 +973,13 @@ declare function buildNamespaces(request: RequestFn): {
|
|
|
970
973
|
deleted: true;
|
|
971
974
|
}>;
|
|
972
975
|
};
|
|
976
|
+
referrals: {
|
|
977
|
+
get(): Promise<import("./referrals").ReferralSettings>;
|
|
978
|
+
update(body: import("./referrals").UpdateReferralSettingsBody, idempotencyKey?: string): Promise<import("./referrals").ReferralSettings>;
|
|
979
|
+
test(): Promise<import("./referrals").ReferralConnectionTest>;
|
|
980
|
+
listCalls(params?: import("./referrals").ListReferralCallsParams): Promise<import("./types").ListPage<import("./referrals").ReferralCall>>;
|
|
981
|
+
retryCall(id: string, idempotencyKey?: string): Promise<import("./referrals").ReferralCall>;
|
|
982
|
+
};
|
|
973
983
|
tokens: {
|
|
974
984
|
verify(body: import("./tokens").VerifyTokenBody): Promise<import("./tokens").TokenVerification>;
|
|
975
985
|
};
|
|
@@ -1320,6 +1330,7 @@ export * from './radius-clients';
|
|
|
1320
1330
|
export * from './lti-platforms';
|
|
1321
1331
|
export * from './instance';
|
|
1322
1332
|
export * from './instance-security';
|
|
1333
|
+
export * from './referrals';
|
|
1323
1334
|
export * from './tokens';
|
|
1324
1335
|
export * from './captcha';
|
|
1325
1336
|
export * from './design';
|
package/dist/client/index.js
CHANGED
|
@@ -60,6 +60,7 @@ const radius_clients_1 = require("./radius-clients");
|
|
|
60
60
|
const lti_platforms_1 = require("./lti-platforms");
|
|
61
61
|
const instance_1 = require("./instance");
|
|
62
62
|
const instance_security_1 = require("./instance-security");
|
|
63
|
+
const referrals_1 = require("./referrals");
|
|
63
64
|
const tokens_1 = require("./tokens");
|
|
64
65
|
const captcha_1 = require("./captcha");
|
|
65
66
|
const design_1 = require("./design");
|
|
@@ -147,6 +148,8 @@ function buildNamespaces(request) {
|
|
|
147
148
|
ltiPlatforms: (0, lti_platforms_1.ltiPlatformsResource)(request),
|
|
148
149
|
instance: (0, instance_1.instanceResource)(request),
|
|
149
150
|
instanceSecurity: (0, instance_security_1.instanceSecurityResource)(request),
|
|
151
|
+
// Referral attribution: the instance's referral platform connection and call log.
|
|
152
|
+
referrals: (0, referrals_1.referralsResource)(request),
|
|
150
153
|
tokens: (0, tokens_1.tokensResource)(request),
|
|
151
154
|
// §5 "captcha anywhere" — verify any CAPTCHA token against the instance's
|
|
152
155
|
// centrally-configured provider, server-side, with the secret held by Atlas.
|
|
@@ -236,6 +239,7 @@ __exportStar(require("./radius-clients"), exports);
|
|
|
236
239
|
__exportStar(require("./lti-platforms"), exports);
|
|
237
240
|
__exportStar(require("./instance"), exports);
|
|
238
241
|
__exportStar(require("./instance-security"), exports);
|
|
242
|
+
__exportStar(require("./referrals"), exports);
|
|
239
243
|
__exportStar(require("./tokens"), exports);
|
|
240
244
|
__exportStar(require("./captcha"), exports);
|
|
241
245
|
__exportStar(require("./design"), exports);
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA6EA,8CAQC;AArFD,uCAA6F;AAC7F,mCAAwC;AACxC,yCAA8C;AAC9C,mDAAwD;AACxD,mCAA6D;AAC7D,mDAAuD;AACvD,yDAA6D;AAC7D,uDAA2D;AAC3D,+CAAmD;AACnD,uCAA4C;AAC5C,yCAA8C;AAC9C,iDAAsE;AACtE,2DAA+D;AAC/D,iDAAqD;AACrD,+CAAoD;AACpD,yCAA8C;AAC9C,qDAAwD;AACxD,6CAAiD;AACjD,mDAAuD;AACvD,yCAA6C;AAC7C,yCAA8C;AAC9C,uDAA2D;AAC3D,qDAAyD;AACzD,2DAA+D;AAC/D,+BAAoC;AACpC,6CAAuD;AACvD,qDAAwD;AACxD,+CAAmD;AACnD,iDAAqD;AACrD,+CAAmD;AACnD,+CAAmD;AACnD,yCAA8C;AAC9C,uDAA2D;AAC3D,mDAAuD;AACvD,mDAAwD;AACxD,uCAA4C;AAC5C,mDAAkD;AAClD,2CAAgD;AAChD,mDAAuD;AACvD,mEAAsE;AACtE,qDAAyD;AACzD,mDAAuD;AACvD,yCAA8C;AAC9C,2DAA+D;AAC/D,2CAAgD;AAChD,qCAA0C;AAC1C,uCAA4C;AAC5C,qCAA0C;AAC1C,mEAAuE;AACvE,iEAAoE;AACpE,iFAAoF;AACpF,uDAA2D;AAC3D,uCAA4C;AAC5C,6CAAkD;AAClD,mDAAwD;AACxD,iDAAqD;AACrD,yCAAoF;AACpF,uEAA0E;AAC1E,+BAAoC;AACpC,+BAA0D;AAC1D,+CAA6D;AAC7D,mDAAuD;AACvD,mEAAsE;AACtE,uCAA4C;AAC5C,2CAA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AAC5B,kDAAgC;AAChC,0DAAwC;AACxC,mDAAiC;AACjC,kDAAgC;AAChC,6CAA2B;AAC3B,sDAAoC;AACpC,8CAA4B;AAC5B,2CAAyB;AACzB,4CAA0B;AAC1B,2CAAyB;AACzB,0DAAwC;AACxC,yDAAuC;AACvC,iEAA+C;AAC/C,oDAAkC;AAClC,4CAA0B;AAC1B,+CAA6B;AAC7B,kDAAgC;AAChC,iDAA+B;AAC/B,6CAA2B;AAC3B,wCAAsB;AACtB,wCAAsB;AACtB,gDAA8B;AAC9B,kDAAgC;AAChC,0DAAwC;AACxC,4CAA0B;AAC1B,8CAA4B;AAC5B,gDAA8B;AAC9B,4DAA0C;AAC1C,6CAA2B"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { type RequestFn } from './request';
|
|
2
|
+
import type { ListPage } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Referral attribution: the instance's connection to a referral platform.
|
|
5
|
+
*
|
|
6
|
+
* With referrals on, every interactive sign-up is reported to the platform
|
|
7
|
+
* before `user.created` is sent and before the session is issued. The
|
|
8
|
+
* platform's answer lands on the user (`referral`, `referral_code`,
|
|
9
|
+
* `referral_link`). A slow or failing platform never fails a sign-up: the
|
|
10
|
+
* call is retried, and `user.referral_attributed` is sent when it resolves.
|
|
11
|
+
*
|
|
12
|
+
* `provider` is `webhook` (the Atlas referral protocol, which any platform can
|
|
13
|
+
* implement; see {@link verifyReferralRequest}) or a built-in vendor adapter.
|
|
14
|
+
* `signing_secret` and `api_key` are write-only: reads return
|
|
15
|
+
* `signing_secret_set` / `api_key_set`.
|
|
16
|
+
*/
|
|
17
|
+
/** What a provider can do. An operation it lacks is recorded as `skipped`. */
|
|
18
|
+
export interface ReferralProviderCapabilities {
|
|
19
|
+
signup: boolean;
|
|
20
|
+
erase: boolean;
|
|
21
|
+
export: boolean;
|
|
22
|
+
partner: boolean;
|
|
23
|
+
auto_enroll: boolean;
|
|
24
|
+
signal: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** A referral provider Atlas supports. */
|
|
27
|
+
export interface ReferralProviderInfo {
|
|
28
|
+
/** `webhook` (the Atlas referral protocol) or a vendor adapter id (`dub`, `firstpromoter`, …). */
|
|
29
|
+
id: string;
|
|
30
|
+
name: string;
|
|
31
|
+
capabilities: ReferralProviderCapabilities;
|
|
32
|
+
/** What must be set before `enabled` can be true. */
|
|
33
|
+
needs: Array<'endpoint_url' | 'signing_secret' | 'api_key' | 'connection_id'>;
|
|
34
|
+
/** The vendor's own first-party tracking cookie, suggested when this provider is picked. */
|
|
35
|
+
default_context_cookie: string | null;
|
|
36
|
+
docs_url: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** Fraud and bot protection for referred sign-ups (`security` on the settings). */
|
|
39
|
+
export interface ReferralSecuritySettings {
|
|
40
|
+
/**
|
|
41
|
+
* `always` (default): a sign-up carrying a referral code must pass the bot
|
|
42
|
+
* challenge, even where the captcha is otherwise off. `inherit`: the
|
|
43
|
+
* instance captcha policy decides. With no working captcha, `always` behaves
|
|
44
|
+
* as `inherit` and preflight reports `referrals_without_bot_protection`.
|
|
45
|
+
*/
|
|
46
|
+
challenge_referred_signups: 'always' | 'inherit';
|
|
47
|
+
/**
|
|
48
|
+
* `flag` (default): report the sign-up with its risk. `strip`: report it as
|
|
49
|
+
* not referred, with `rejected.reason`. `hold`: report nothing until the
|
|
50
|
+
* email is proven, then re-assess.
|
|
51
|
+
*/
|
|
52
|
+
on_high_risk: 'flag' | 'strip' | 'hold';
|
|
53
|
+
/** Hold every referred sign-up until the email is proven. Default false. */
|
|
54
|
+
hold_until_email_verified: boolean;
|
|
55
|
+
/** Referred sign-ups per code from one IP network or device per hour before a velocity signal (1-1000, default 5). */
|
|
56
|
+
max_referred_signups_per_ip_hour: number;
|
|
57
|
+
}
|
|
58
|
+
/** The connection's health, as the settings read reports it. */
|
|
59
|
+
export interface ReferralConnectionStatus {
|
|
60
|
+
/** The last connection test, or null when never tested. */
|
|
61
|
+
last_test: {
|
|
62
|
+
ok: boolean;
|
|
63
|
+
at: number;
|
|
64
|
+
http_status: number | null;
|
|
65
|
+
error: string | null;
|
|
66
|
+
} | null;
|
|
67
|
+
/** Calls that failed permanently in the last 7 days. */
|
|
68
|
+
failed_calls_7d: number;
|
|
69
|
+
/** Calls waiting for a retry. */
|
|
70
|
+
retrying_calls: number;
|
|
71
|
+
/** Epoch ms of the last successful call, or null. */
|
|
72
|
+
last_success_at: number | null;
|
|
73
|
+
}
|
|
74
|
+
/** `GET /v1/instance/referrals`. */
|
|
75
|
+
export interface ReferralSettings {
|
|
76
|
+
object: 'referral_settings';
|
|
77
|
+
enabled: boolean;
|
|
78
|
+
/** `webhook` (the Atlas referral protocol) or a built-in vendor adapter id. */
|
|
79
|
+
provider: string;
|
|
80
|
+
/** Base URL of the platform connection (Atlas referral protocol). */
|
|
81
|
+
endpoint_url: string | null;
|
|
82
|
+
/** Passed through to the platform. */
|
|
83
|
+
program_id: string | null;
|
|
84
|
+
/** Your label for the connection on the platform side. */
|
|
85
|
+
connection_id: string | null;
|
|
86
|
+
/** Whether a signing secret is stored (the value is never returned). */
|
|
87
|
+
signing_secret_set: boolean;
|
|
88
|
+
/** Whether a vendor API key is stored (the value is never returned). */
|
|
89
|
+
api_key_set: boolean;
|
|
90
|
+
/** Query parameters that carry a referral code, in priority order (default `ref`, `via`, `aff`). */
|
|
91
|
+
url_params: string[];
|
|
92
|
+
/** First-party tracking cookie read under consent; null = never read a cookie. */
|
|
93
|
+
context_cookie: string | null;
|
|
94
|
+
consent_category: string;
|
|
95
|
+
consent_fallback_category: string | null;
|
|
96
|
+
/** Every new user becomes a referrer (gets a code and link from the platform). */
|
|
97
|
+
auto_enroll_users: boolean;
|
|
98
|
+
/** e.g. `https://app.example.com/join?ref={code}`; builds `referral_link`. */
|
|
99
|
+
link_template: string | null;
|
|
100
|
+
/** How long a sign-up waits for the platform (100-5000 ms, default 3000). */
|
|
101
|
+
timeout_ms: number;
|
|
102
|
+
security: ReferralSecuritySettings;
|
|
103
|
+
/** What the chosen provider still needs before referrals can be enabled. */
|
|
104
|
+
missing?: string[];
|
|
105
|
+
connection?: ReferralConnectionStatus | null;
|
|
106
|
+
providers: ReferralProviderInfo[];
|
|
107
|
+
updated_at?: number | null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* `PATCH /v1/instance/referrals`: only the fields sent change, `null` clears.
|
|
111
|
+
* Enabling without what the provider needs is `422 REFERRALS_NOT_CONFIGURED`.
|
|
112
|
+
*/
|
|
113
|
+
export interface UpdateReferralSettingsBody {
|
|
114
|
+
enabled?: boolean;
|
|
115
|
+
provider?: string;
|
|
116
|
+
/** https only (http only for localhost on a development instance). */
|
|
117
|
+
endpoint_url?: string | null;
|
|
118
|
+
program_id?: string | null;
|
|
119
|
+
connection_id?: string | null;
|
|
120
|
+
/** Write-only, 16-512 characters. */
|
|
121
|
+
signing_secret?: string | null;
|
|
122
|
+
/** Write-only vendor API key. */
|
|
123
|
+
api_key?: string | null;
|
|
124
|
+
/** 1-10 names of `[A-Za-z0-9_.-]{1,40}`. */
|
|
125
|
+
url_params?: string[];
|
|
126
|
+
context_cookie?: string | null;
|
|
127
|
+
consent_category?: string;
|
|
128
|
+
consent_fallback_category?: string | null;
|
|
129
|
+
auto_enroll_users?: boolean;
|
|
130
|
+
/** An https URL containing `{code}`. */
|
|
131
|
+
link_template?: string | null;
|
|
132
|
+
/** 100-5000. */
|
|
133
|
+
timeout_ms?: number;
|
|
134
|
+
/** Partial: only the security fields sent change. */
|
|
135
|
+
security?: Partial<ReferralSecuritySettings>;
|
|
136
|
+
}
|
|
137
|
+
/** `POST /v1/instance/referrals/test`. */
|
|
138
|
+
export interface ReferralConnectionTest {
|
|
139
|
+
ok: boolean;
|
|
140
|
+
http_status?: number | null;
|
|
141
|
+
latency_ms?: number | null;
|
|
142
|
+
/** e.g. `signature_rejected` (the platform answered 401/403), `timeout`, `network_error`, `url_blocked`, `http_500`. */
|
|
143
|
+
error?: {
|
|
144
|
+
code: string;
|
|
145
|
+
message: string;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export type ReferralCallKind = 'signup' | 'erase' | 'export' | 'partner' | 'signal' | 'test';
|
|
149
|
+
export type ReferralCallStatus = 'pending' | 'succeeded' | 'retrying' | 'failed' | 'held' | 'skipped';
|
|
150
|
+
/** The risk verdict sent with a sign-up (camelCase, as on the referral protocol). */
|
|
151
|
+
export interface ReferralRisk {
|
|
152
|
+
level: 'low' | 'medium' | 'high';
|
|
153
|
+
/** 0-100. */
|
|
154
|
+
score: number;
|
|
155
|
+
/**
|
|
156
|
+
* e.g. `self_referral`, `ip_velocity`, `device_velocity`, `disposable_email`,
|
|
157
|
+
* `datacenter_ip`, `tor_ip`, `captcha_not_passed`, `email_unverified`,
|
|
158
|
+
* `restricted_identifier`.
|
|
159
|
+
*/
|
|
160
|
+
signals: string[];
|
|
161
|
+
captcha: 'passed' | 'not_required' | 'not_configured';
|
|
162
|
+
emailVerified: boolean;
|
|
163
|
+
}
|
|
164
|
+
/** One call in the referral call log. */
|
|
165
|
+
export interface ReferralCall {
|
|
166
|
+
object: 'referral_call';
|
|
167
|
+
/** Also the signed `atlas-id` header of every attempt. */
|
|
168
|
+
id: string;
|
|
169
|
+
kind: ReferralCallKind;
|
|
170
|
+
status: ReferralCallStatus;
|
|
171
|
+
/** Sign-up calls: `referred`, `not_referred` or `stripped`. */
|
|
172
|
+
outcome?: string | null;
|
|
173
|
+
customer_ref: string;
|
|
174
|
+
user_id?: string | null;
|
|
175
|
+
http_status?: number | null;
|
|
176
|
+
last_error?: string | null;
|
|
177
|
+
attempts: number;
|
|
178
|
+
/** Epoch ms of the next retry, while pending or retrying. */
|
|
179
|
+
next_attempt_at?: number | null;
|
|
180
|
+
risk?: ReferralRisk | null;
|
|
181
|
+
/** What was sent (never secrets). */
|
|
182
|
+
payload?: Record<string, unknown>;
|
|
183
|
+
created_at: number;
|
|
184
|
+
updated_at?: number;
|
|
185
|
+
}
|
|
186
|
+
export interface ListReferralCallsParams {
|
|
187
|
+
/** 1-200, default 50, newest first. */
|
|
188
|
+
limit?: number;
|
|
189
|
+
status?: ReferralCallStatus;
|
|
190
|
+
kind?: ReferralCallKind;
|
|
191
|
+
user_id?: string;
|
|
192
|
+
}
|
|
193
|
+
export declare function referralsResource(request: RequestFn): {
|
|
194
|
+
/** `GET /v1/instance/referrals` — settings, connection status and the supported providers. */
|
|
195
|
+
get(): Promise<ReferralSettings>;
|
|
196
|
+
/** `PATCH /v1/instance/referrals` — partial update; secrets are write-only. */
|
|
197
|
+
update(body: UpdateReferralSettingsBody, idempotencyKey?: string): Promise<ReferralSettings>;
|
|
198
|
+
/**
|
|
199
|
+
* `POST /v1/instance/referrals/test` — a signed probe of the platform. `ok`
|
|
200
|
+
* when it answered 2xx or 404; `error.code` `signature_rejected` on 401/403.
|
|
201
|
+
*/
|
|
202
|
+
test(): Promise<ReferralConnectionTest>;
|
|
203
|
+
/** `GET /v1/instance/referrals/calls` — the call log, newest first. */
|
|
204
|
+
listCalls(params?: ListReferralCallsParams): Promise<ListPage<ReferralCall>>;
|
|
205
|
+
/**
|
|
206
|
+
* `POST /v1/instance/referrals/calls/:id/retry` — retry a failed, retrying
|
|
207
|
+
* or skipped call now (a connection test cannot be retried).
|
|
208
|
+
*/
|
|
209
|
+
retryCall(id: string, idempotencyKey?: string): Promise<ReferralCall>;
|
|
210
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.referralsResource = referralsResource;
|
|
4
|
+
const request_1 = require("./request");
|
|
5
|
+
function referralsResource(request) {
|
|
6
|
+
return {
|
|
7
|
+
/** `GET /v1/instance/referrals` — settings, connection status and the supported providers. */
|
|
8
|
+
get() {
|
|
9
|
+
return request({ method: 'GET', path: '/v1/instance/referrals' });
|
|
10
|
+
},
|
|
11
|
+
/** `PATCH /v1/instance/referrals` — partial update; secrets are write-only. */
|
|
12
|
+
update(body, idempotencyKey) {
|
|
13
|
+
return request({ method: 'PATCH', path: '/v1/instance/referrals', body, idempotencyKey });
|
|
14
|
+
},
|
|
15
|
+
/**
|
|
16
|
+
* `POST /v1/instance/referrals/test` — a signed probe of the platform. `ok`
|
|
17
|
+
* when it answered 2xx or 404; `error.code` `signature_rejected` on 401/403.
|
|
18
|
+
*/
|
|
19
|
+
test() {
|
|
20
|
+
return request({ method: 'POST', path: '/v1/instance/referrals/test' });
|
|
21
|
+
},
|
|
22
|
+
/** `GET /v1/instance/referrals/calls` — the call log, newest first. */
|
|
23
|
+
listCalls(params = {}) {
|
|
24
|
+
return request({ method: 'GET', path: '/v1/instance/referrals/calls', query: { ...params } });
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* `POST /v1/instance/referrals/calls/:id/retry` — retry a failed, retrying
|
|
28
|
+
* or skipped call now (a connection test cannot be retried).
|
|
29
|
+
*/
|
|
30
|
+
retryCall(id, idempotencyKey) {
|
|
31
|
+
return request({
|
|
32
|
+
method: 'POST',
|
|
33
|
+
path: `/v1/instance/referrals/calls/${(0, request_1.enc)(id)}/retry`,
|
|
34
|
+
idempotencyKey,
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=referrals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"referrals.js","sourceRoot":"","sources":["../../src/client/referrals.ts"],"names":[],"mappings":";;AAqMA,8CAiCC;AAtOD,uCAAgD;AAqMhD,SAAgB,iBAAiB,CAAC,OAAkB;IAClD,OAAO;QACL,8FAA8F;QAC9F,GAAG;YACD,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC;QACpE,CAAC;QACD,+EAA+E;QAC/E,MAAM,CAAC,IAAgC,EAAE,cAAuB;YAC9D,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QAC5F,CAAC;QACD;;;WAGG;QACH,IAAI;YACF,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,6BAA6B,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,uEAAuE;QACvE,SAAS,CAAC,SAAkC,EAAE;YAC5C,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,8BAA8B,EAAE,KAAK,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC;QAChG,CAAC;QACD;;;WAGG;QACH,SAAS,CAAC,EAAU,EAAE,cAAuB;YAC3C,OAAO,OAAO,CAAC;gBACb,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,gCAAgC,IAAA,aAAG,EAAC,EAAE,CAAC,QAAQ;gBACrD,cAAc;aACf,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/client/users.d.ts
CHANGED
|
@@ -22,6 +22,72 @@ export interface User {
|
|
|
22
22
|
* the one you hold. (Absent from servers older than this field.)
|
|
23
23
|
*/
|
|
24
24
|
version?: number;
|
|
25
|
+
/**
|
|
26
|
+
* How the user arrived through a referral program, when the instance has
|
|
27
|
+
* referral attribution on and the platform matched a referrer; null when not
|
|
28
|
+
* referred, not answered yet, or referrals are off. (Absent from servers
|
|
29
|
+
* older than this field.)
|
|
30
|
+
*/
|
|
31
|
+
referral?: UserReferral | null;
|
|
32
|
+
/** The user's own referral code, when they are a referrer. */
|
|
33
|
+
referral_code?: string | null;
|
|
34
|
+
/** The user's own referral link, when they are a referrer. */
|
|
35
|
+
referral_link?: string | null;
|
|
36
|
+
}
|
|
37
|
+
/** The inbound referral the referral platform matched for a user. */
|
|
38
|
+
export interface UserReferral {
|
|
39
|
+
/** The platform's id for the referring partner. */
|
|
40
|
+
partner_id: string | null;
|
|
41
|
+
/** The referrer as the platform knows them (your `external_id` for that user, or their Atlas id). */
|
|
42
|
+
referrer_external_id: string | null;
|
|
43
|
+
/** The referrer's Atlas user id, when they are a user of this instance. */
|
|
44
|
+
referrer_user_id: string | null;
|
|
45
|
+
/** How the platform matched the referral, e.g. `code`, `click`, `coupon`. */
|
|
46
|
+
matched_via: string | null;
|
|
47
|
+
/** The platform's own status for the referral. */
|
|
48
|
+
status: string | null;
|
|
49
|
+
/** The risk level Atlas assessed at sign-up, when one was. */
|
|
50
|
+
risk_level?: 'low' | 'medium' | 'high' | null;
|
|
51
|
+
/** An admin marked the referral fraudulent (`users.flagReferral`). */
|
|
52
|
+
flagged?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* An imported referral on `users.create`: how the user arrived. With referral
|
|
56
|
+
* attribution on, the user is reported to the referral platform. Each id is
|
|
57
|
+
* 3-64 characters of `A-Z a-z 0-9 _ -`.
|
|
58
|
+
*/
|
|
59
|
+
export interface CreateUserReferralInput {
|
|
60
|
+
code?: string;
|
|
61
|
+
click_id?: string;
|
|
62
|
+
anon_id?: string;
|
|
63
|
+
}
|
|
64
|
+
/** `POST /v1/users/:id/referral/flag`. */
|
|
65
|
+
export interface UserReferralFlag {
|
|
66
|
+
object: 'user_referral';
|
|
67
|
+
user_id: string;
|
|
68
|
+
/** `flagged` after this call. */
|
|
69
|
+
status: string;
|
|
70
|
+
flagged: boolean;
|
|
71
|
+
flag_reason: string | null;
|
|
72
|
+
/** Epoch ms. */
|
|
73
|
+
flagged_at: number | null;
|
|
74
|
+
risk_level: 'low' | 'medium' | 'high' | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The `data` of a `user.referral_attributed` webhook: the referral platform
|
|
78
|
+
* answered after `user.created` was sent.
|
|
79
|
+
*/
|
|
80
|
+
export interface UserReferralAttributedEvent {
|
|
81
|
+
object: 'user_referral';
|
|
82
|
+
user_id: string;
|
|
83
|
+
/** `attributed`, `not_referred`, `failed`, … (`not_referred`: the platform found no referrer). */
|
|
84
|
+
attribution_status: string;
|
|
85
|
+
referral: UserReferral | null;
|
|
86
|
+
referral_code: string | null;
|
|
87
|
+
referral_link: string | null;
|
|
88
|
+
/** Epoch ms. */
|
|
89
|
+
signed_up_at: number;
|
|
90
|
+
updated_at: number;
|
|
25
91
|
}
|
|
26
92
|
export interface EmailAddress {
|
|
27
93
|
object: 'email_address';
|
|
@@ -75,12 +141,21 @@ export interface CreateUserBody {
|
|
|
75
141
|
* guarantees no email, SMS or push is sent as a consequence of the create.
|
|
76
142
|
*/
|
|
77
143
|
notify?: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Import a referral (how the user arrived). With referral attribution on,
|
|
146
|
+
* the user is reported to the referral platform.
|
|
147
|
+
*/
|
|
148
|
+
referral?: CreateUserReferralInput;
|
|
149
|
+
/** The user's own referral code; unique per instance (`409 REFERRAL_CODE_TAKEN`). */
|
|
150
|
+
referral_code?: string;
|
|
78
151
|
}
|
|
79
152
|
export interface UpdateUserBody {
|
|
80
153
|
first_name?: string;
|
|
81
154
|
last_name?: string;
|
|
82
155
|
public_metadata?: Metadata;
|
|
83
156
|
private_metadata?: Metadata;
|
|
157
|
+
/** The user's own referral code; `null` clears. Unique per instance (`409 REFERRAL_CODE_TAKEN`). */
|
|
158
|
+
referral_code?: string | null;
|
|
84
159
|
}
|
|
85
160
|
export interface ReplaceUserMetadataBody {
|
|
86
161
|
public_metadata?: Metadata;
|
|
@@ -101,6 +176,16 @@ export declare function usersResource(request: RequestFn): {
|
|
|
101
176
|
duration_in_seconds?: number;
|
|
102
177
|
}): Promise<User>;
|
|
103
178
|
unlock(id: string): Promise<User>;
|
|
179
|
+
/**
|
|
180
|
+
* `POST /v1/users/:id/referral/flag` — mark the user's referral fraudulent.
|
|
181
|
+
* The referral reads `flagged: true`, the referral platform is sent a
|
|
182
|
+
* `fraud_confirmed` signal (when referrals are on) and the action is
|
|
183
|
+
* audited. The user's account is not changed. 404 when the user has no
|
|
184
|
+
* referral. `reason` (at most 500 characters) is sent to the platform.
|
|
185
|
+
*/
|
|
186
|
+
flagReferral(id: string, body?: {
|
|
187
|
+
reason?: string;
|
|
188
|
+
}, idempotencyKey?: string): Promise<UserReferralFlag>;
|
|
104
189
|
delete(id: string): Promise<DeletedObject>;
|
|
105
190
|
resetMfa(id: string): Promise<{
|
|
106
191
|
object: "user";
|
package/dist/client/users.js
CHANGED
|
@@ -33,6 +33,21 @@ function usersResource(request) {
|
|
|
33
33
|
unlock(id) {
|
|
34
34
|
return request({ method: 'POST', path: `/v1/users/${(0, request_1.enc)(id)}/unlock` });
|
|
35
35
|
},
|
|
36
|
+
/**
|
|
37
|
+
* `POST /v1/users/:id/referral/flag` — mark the user's referral fraudulent.
|
|
38
|
+
* The referral reads `flagged: true`, the referral platform is sent a
|
|
39
|
+
* `fraud_confirmed` signal (when referrals are on) and the action is
|
|
40
|
+
* audited. The user's account is not changed. 404 when the user has no
|
|
41
|
+
* referral. `reason` (at most 500 characters) is sent to the platform.
|
|
42
|
+
*/
|
|
43
|
+
flagReferral(id, body = {}, idempotencyKey) {
|
|
44
|
+
return request({
|
|
45
|
+
method: 'POST',
|
|
46
|
+
path: `/v1/users/${(0, request_1.enc)(id)}/referral/flag`,
|
|
47
|
+
body,
|
|
48
|
+
idempotencyKey,
|
|
49
|
+
});
|
|
50
|
+
},
|
|
36
51
|
delete(id) {
|
|
37
52
|
return request({ method: 'DELETE', path: `/v1/users/${(0, request_1.enc)(id)}` });
|
|
38
53
|
},
|
package/dist/client/users.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/client/users.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/client/users.ts"],"names":[],"mappings":";;AA6KA,sCA8bC;AA3mBD,uCAAgD;AA6KhD,SAAgB,aAAa,CAAC,OAAkB;IAC9C,OAAO;QACL,0CAA0C;QAC1C,IAAI,CAAC,SAA0B,EAAE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c, oidcCallback, oidcClearCookie, oidcLogoutUrl, oidcStart, oidcVerifyIdToken, resetOidcCaches, } from './oidc';
|
|
8
8
|
export type { AtlasOidc, AtlasOidcErrorCode, OidcCallbackOptions, OidcClientAuth, OidcIdentity, OidcLogoutUrlOptions, OidcStartOptions, OidcStartResult, VerifyIdTokenOptions, } from './oidc';
|
|
9
9
|
export * from './webhooks';
|
|
10
|
+
export * from './referrals';
|
|
10
11
|
export { createAtlasClient } from './client';
|
|
11
12
|
export type { AtlasClient } from './client';
|
|
12
13
|
export * from './client';
|
package/dist/index.js
CHANGED
|
@@ -48,6 +48,8 @@ Object.defineProperty(exports, "oidcVerifyIdToken", { enumerable: true, get: fun
|
|
|
48
48
|
Object.defineProperty(exports, "resetOidcCaches", { enumerable: true, get: function () { return oidc_1.resetOidcCaches; } });
|
|
49
49
|
// §12.2 inbound webhook verification for consumers.
|
|
50
50
|
__exportStar(require("./webhooks"), exports);
|
|
51
|
+
// The Atlas referral protocol, for a referral platform receiving Atlas's signed calls.
|
|
52
|
+
__exportStar(require("./referrals"), exports);
|
|
51
53
|
// The typed management client for the secret-key Backend API.
|
|
52
54
|
var client_1 = require("./client");
|
|
53
55
|
Object.defineProperty(exports, "createAtlasClient", { enumerable: true, get: function () { return client_1.createAtlasClient; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6DAA6D;AAC7D,+CAA6B;AAC7B,mEAAmE;AACnE,yCAA2G;AAAlG,2GAAA,cAAc,OAAA;AAAE,0GAAA,aAAa,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,yHAAA,4BAA4B,OAAA;AACrF,2CAAyB;AACzB,8CAA4B;AAE5B,6EAA6E;AAC7E,+CAOwB;AANtB,wHAAA,wBAAwB,OAAA;AACxB,+HAAA,+BAA+B,OAAA;AAC/B,4HAAA,4BAA4B,OA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B,iHAAA,iBAAiB,OAAA;AAUnB,sEAAsE;AACtE,iFAAiF;AACjF,+BAWgB;AAVd,sGAAA,cAAc,OAAA;AACd,wGAAA,gBAAgB,OAAA;AAChB,iHAAA,yBAAyB,OAAA;AACzB,4FAAA,IAAI,OAAA;AACJ,oGAAA,YAAY,OAAA;AACZ,uGAAA,eAAe,OAAA;AACf,qGAAA,aAAa,OAAA;AACb,iGAAA,SAAS,OAAA;AACT,yGAAA,iBAAiB,OAAA;AACjB,uGAAA,eAAe,OAAA;AAcjB,oDAAoD;AACpD,6CAA2B;AAE3B,uFAAuF;AACvF,8CAA4B;AAE5B,8DAA8D;AAC9D,mCAA6C;AAApC,2GAAA,iBAAiB,OAAA;AAE1B,2CAAyB;AAEzB,yEAAyE;AACzE,2EAA2E;AAC3E,iEAAiE;AACjE,qCAAiE;AAAxD,2GAAA,gBAAgB,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAU7C,wFAAwF;AACxF,2CAA2C;AAC3C,uCAA4C;AAAnC,sGAAA,YAAY,OAAA;AAErB,iDAA+E;AAAtE,yGAAA,UAAU,OAAA;AAAE,6GAAA,cAAc,OAAA;AAAE,6GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { type WebhookVerifyFailure } from './webhooks';
|
|
2
|
+
import type { ReferralRisk } from './client/referrals';
|
|
3
|
+
/**
|
|
4
|
+
* The Atlas referral protocol (v1), for a REFERRAL PLATFORM receiving calls
|
|
5
|
+
* from Atlas. An Atlas instance with referral attribution on (provider
|
|
6
|
+
* `webhook`) calls the platform's base URL. Every call is a signed POST whose
|
|
7
|
+
* JSON body says which operation it is (`op`) and which customer it is about:
|
|
8
|
+
*
|
|
9
|
+
* POST {base}/signups { op: 'signup', customerRef, … } → 200 ReferralSignupResponse
|
|
10
|
+
* POST {base}/erase { op: 'erase', customerRef } → 2xx (404 = already gone)
|
|
11
|
+
* POST {base}/export { op: 'export', customerRef, test } → 200 JSON (any shape) | 404
|
|
12
|
+
* POST {base}/partners { op: 'partner', customerRef, code, emailHash } → 2xx | 409 code taken | 404/405/501 unsupported
|
|
13
|
+
* POST {base}/signals { op: 'signal', customerRef, type, occurredAt, data } → 2xx | 404/405/501 unsupported
|
|
14
|
+
*
|
|
15
|
+
* The connection test is `POST {base}/export` with
|
|
16
|
+
* `{ op: 'export', customerRef: 'atlas_connection_test', test: true }` (answer
|
|
17
|
+
* 2xx or 404). Calls are signed exactly like Atlas webhooks (`atlas-id`,
|
|
18
|
+
* `atlas-timestamp`, `atlas-signature` over `<id>.<timestamp>.<raw body>`),
|
|
19
|
+
* with `Idempotency-Key` and `User-Agent: Atlas-Referrals/1`. `atlas-id` is the
|
|
20
|
+
* call id, the same on every retry of one call.
|
|
21
|
+
*
|
|
22
|
+
* The signature covers the body, not the URL, so everything that matters is in
|
|
23
|
+
* the body. Pass the path the request arrived on (or the operation you
|
|
24
|
+
* expect): a signed body whose `op` does not match it is refused, so a
|
|
25
|
+
* captured call cannot be replayed against another endpoint.
|
|
26
|
+
*/
|
|
27
|
+
/** `customerRef` of the connection test (`POST {base}/export` with `test: true`). */
|
|
28
|
+
export declare const REFERRAL_CONNECTION_TEST_REF = "atlas_connection_test";
|
|
29
|
+
/** The `User-Agent` Atlas sends on every referral call. */
|
|
30
|
+
export declare const REFERRAL_PROTOCOL_USER_AGENT = "Atlas-Referrals/1";
|
|
31
|
+
/** The referral captured at sign-up (from the page URL, or a tracking cookie under consent). Never trusted. */
|
|
32
|
+
export interface ReferralContext {
|
|
33
|
+
/** The referral code from the URL (or cookie), 3-64 of `A-Z a-z 0-9 _ -`. */
|
|
34
|
+
code: string | null;
|
|
35
|
+
/** The platform's click id, read from its cookie only under consent. */
|
|
36
|
+
clickId: string | null;
|
|
37
|
+
/** The platform's anonymous visitor id, read from its cookie only under consent. */
|
|
38
|
+
anonId: string | null;
|
|
39
|
+
/** ISO 8601. */
|
|
40
|
+
capturedAt: string;
|
|
41
|
+
/** `granted`: the cookie was read under consent. `not_required`: a URL code only. */
|
|
42
|
+
consent: 'granted' | 'not_required';
|
|
43
|
+
}
|
|
44
|
+
/** The risk verdict Atlas sends with a sign-up (the same shape as `ReferralCall.risk`). */
|
|
45
|
+
export type ReferralRiskVerdict = ReferralRisk;
|
|
46
|
+
/** `POST {base}/signups`. Idempotent on `customerRef` (`Idempotency-Key: signup:<customerRef>`). */
|
|
47
|
+
export interface ReferralSignupPayload {
|
|
48
|
+
op: 'signup';
|
|
49
|
+
/** The app's id for the user: its external_id when set, else the Atlas user id. */
|
|
50
|
+
customerRef: string;
|
|
51
|
+
/** sha256 hex of the lower-cased, trimmed primary email; null when the user has none. */
|
|
52
|
+
emailHash: string | null;
|
|
53
|
+
ip: string | null;
|
|
54
|
+
ua: string | null;
|
|
55
|
+
/** ISO 8601: the original sign-up time, the same on every retry. */
|
|
56
|
+
signedUpAt: string;
|
|
57
|
+
programId: string | null;
|
|
58
|
+
/** Make the user a referrer: answer with `partner { id, code, link }`. */
|
|
59
|
+
autoEnroll: boolean;
|
|
60
|
+
/** Null when the user arrived with no referral (reported because of `autoEnroll`), or when stripped. */
|
|
61
|
+
referral: ReferralContext | null;
|
|
62
|
+
risk?: ReferralRiskVerdict | null;
|
|
63
|
+
/** Set when Atlas stripped the referral because of its risk policy. */
|
|
64
|
+
rejected?: {
|
|
65
|
+
reason: string;
|
|
66
|
+
} | null;
|
|
67
|
+
}
|
|
68
|
+
/** The answer a platform gives to `POST {base}/signups`. */
|
|
69
|
+
export interface ReferralSignupResponse {
|
|
70
|
+
/** The matched referral, or null when not referred. */
|
|
71
|
+
referral: {
|
|
72
|
+
partnerId: string | null;
|
|
73
|
+
/** The referrer as the app knows them (their customerRef); Atlas maps it to a local user. */
|
|
74
|
+
referrerExternalRef: string | null;
|
|
75
|
+
/** e.g. `code`, `click`, `coupon`. */
|
|
76
|
+
matchedVia: string | null;
|
|
77
|
+
status: string | null;
|
|
78
|
+
} | null;
|
|
79
|
+
/** The user's own partner record when `autoEnroll` was true. `link` may be omitted: Atlas builds it from its link template. */
|
|
80
|
+
partner?: {
|
|
81
|
+
id: string | null;
|
|
82
|
+
code: string | null;
|
|
83
|
+
link?: string | null;
|
|
84
|
+
} | null;
|
|
85
|
+
}
|
|
86
|
+
/** `POST {base}/erase`. */
|
|
87
|
+
export interface ReferralErasePayload {
|
|
88
|
+
op: 'erase';
|
|
89
|
+
customerRef: string;
|
|
90
|
+
}
|
|
91
|
+
/** `POST {base}/export`: what you hold about a customer (answer any JSON, or 404). */
|
|
92
|
+
export interface ReferralExportPayload {
|
|
93
|
+
op: 'export';
|
|
94
|
+
customerRef: string;
|
|
95
|
+
/** True for the connection test (`customerRef` `atlas_connection_test`). */
|
|
96
|
+
test: boolean;
|
|
97
|
+
}
|
|
98
|
+
/** `POST {base}/partners`: the user's own referral code was set in Atlas. */
|
|
99
|
+
export interface ReferralPartnerPayload {
|
|
100
|
+
op: 'partner';
|
|
101
|
+
customerRef: string;
|
|
102
|
+
code: string;
|
|
103
|
+
emailHash: string | null;
|
|
104
|
+
}
|
|
105
|
+
/** The lifecycle signal types. */
|
|
106
|
+
export type ReferralSignalType = 'email_verified' | 'user_banned' | 'user_unbanned' | 'user_locked' | 'risk_elevated' | 'fraud_confirmed';
|
|
107
|
+
/** `POST {base}/signals`: a lifecycle update, so the platform can qualify, hold or void a commission. */
|
|
108
|
+
export interface ReferralSignalPayload {
|
|
109
|
+
op: 'signal';
|
|
110
|
+
customerRef: string;
|
|
111
|
+
type: ReferralSignalType | (string & {});
|
|
112
|
+
/** ISO 8601. */
|
|
113
|
+
occurredAt: string;
|
|
114
|
+
data: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
/** The operations of the referral protocol (the `op` of every call). */
|
|
117
|
+
export type ReferralOp = 'signup' | 'erase' | 'export' | 'partner' | 'signal';
|
|
118
|
+
/** The endpoint (last path segment) each operation is sent to. */
|
|
119
|
+
export declare const REFERRAL_OP_ENDPOINTS: Record<ReferralOp, string>;
|
|
120
|
+
/** A verified call, by operation. */
|
|
121
|
+
export type ReferralProtocolCall = {
|
|
122
|
+
op: 'signup';
|
|
123
|
+
payload: ReferralSignupPayload;
|
|
124
|
+
} | {
|
|
125
|
+
op: 'erase';
|
|
126
|
+
payload: ReferralErasePayload;
|
|
127
|
+
} | {
|
|
128
|
+
op: 'export';
|
|
129
|
+
payload: ReferralExportPayload;
|
|
130
|
+
/** The connection test (`customerRef` `atlas_connection_test`): answer 2xx or 404. */
|
|
131
|
+
test: boolean;
|
|
132
|
+
} | {
|
|
133
|
+
op: 'partner';
|
|
134
|
+
payload: ReferralPartnerPayload;
|
|
135
|
+
} | {
|
|
136
|
+
op: 'signal';
|
|
137
|
+
payload: ReferralSignalPayload;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Why a call was refused: a webhook signature failure, or
|
|
141
|
+
* `malformed_body` (not a JSON object), `missing_op`, `unknown_op`,
|
|
142
|
+
* `unknown_endpoint` (the path's last segment is not a protocol endpoint) or
|
|
143
|
+
* `op_mismatch` (the signed `op` is not the operation of the endpoint or the
|
|
144
|
+
* expected operation).
|
|
145
|
+
*/
|
|
146
|
+
export type ReferralVerifyFailure = WebhookVerifyFailure | 'malformed_body' | 'missing_op' | 'unknown_op' | 'unknown_endpoint' | 'op_mismatch';
|
|
147
|
+
type HeadersLike = Headers | Record<string, string | string[] | undefined>;
|
|
148
|
+
export interface VerifyReferralRequestInput {
|
|
149
|
+
/** The RAW request body (string or Buffer), before any JSON parse. */
|
|
150
|
+
body: string | Buffer;
|
|
151
|
+
headers: HeadersLike;
|
|
152
|
+
/** The signing secret configured on the Atlas instance's referral settings. */
|
|
153
|
+
secret: string;
|
|
154
|
+
/**
|
|
155
|
+
* The path (or full URL) the request arrived on, e.g. `req.path`. Its last
|
|
156
|
+
* segment (`signups`, `erase`, `export`, `partners`, `signals`) must match
|
|
157
|
+
* the signed `op`.
|
|
158
|
+
*/
|
|
159
|
+
path?: string;
|
|
160
|
+
/** The operation this handler serves; the signed `op` must equal it. */
|
|
161
|
+
expectedOp?: ReferralOp;
|
|
162
|
+
now?: Date;
|
|
163
|
+
/** Defaults to 5 minutes, as for webhooks. */
|
|
164
|
+
toleranceMs?: number;
|
|
165
|
+
}
|
|
166
|
+
export interface ReferralVerifyResult {
|
|
167
|
+
verified: boolean;
|
|
168
|
+
reason?: ReferralVerifyFailure;
|
|
169
|
+
/** The signed `atlas-id` (the call id): the same on every retry of one call. */
|
|
170
|
+
deliveryId?: string;
|
|
171
|
+
/** The signed `atlas-timestamp` (epoch ms). */
|
|
172
|
+
timestamp?: number;
|
|
173
|
+
/** The `Idempotency-Key` header (`signup:<customerRef>` on sign-ups). Not signed. */
|
|
174
|
+
idempotencyKey?: string;
|
|
175
|
+
/** The operation and its payload, present only when `verified`. */
|
|
176
|
+
call?: ReferralProtocolCall;
|
|
177
|
+
}
|
|
178
|
+
/** The operation of a path's last segment, or null when it is not a protocol endpoint. */
|
|
179
|
+
export declare function referralOpForPath(path: string): ReferralOp | null;
|
|
180
|
+
/**
|
|
181
|
+
* Verify a call from Atlas to your referral platform and tell which operation
|
|
182
|
+
* it is. Never throws: check `verified`. Verify over the RAW body, before any
|
|
183
|
+
* JSON parse, and pass the path it arrived on (or `expectedOp`) so a signed
|
|
184
|
+
* body cannot be replayed against another endpoint.
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* app.post('/atlas/:endpoint', express.raw({ type: '*\/*' }), async (req, res) => {
|
|
188
|
+
* const { verified, call } = verifyReferralRequest({
|
|
189
|
+
* body: req.body, headers: req.headers, secret, path: req.path,
|
|
190
|
+
* });
|
|
191
|
+
* if (!verified || !call) return res.sendStatus(401);
|
|
192
|
+
* if (call.op === 'export' && call.test) return res.sendStatus(404);
|
|
193
|
+
* if (call.op === 'signup') return res.json(await attribute(call.payload)); // ReferralSignupResponse
|
|
194
|
+
* // erase, export, partner, signal ...
|
|
195
|
+
* });
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export declare function verifyReferralRequest(input: VerifyReferralRequestInput): ReferralVerifyResult;
|
|
199
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFERRAL_OP_ENDPOINTS = exports.REFERRAL_PROTOCOL_USER_AGENT = exports.REFERRAL_CONNECTION_TEST_REF = void 0;
|
|
4
|
+
exports.referralOpForPath = referralOpForPath;
|
|
5
|
+
exports.verifyReferralRequest = verifyReferralRequest;
|
|
6
|
+
const webhooks_1 = require("./webhooks");
|
|
7
|
+
/**
|
|
8
|
+
* The Atlas referral protocol (v1), for a REFERRAL PLATFORM receiving calls
|
|
9
|
+
* from Atlas. An Atlas instance with referral attribution on (provider
|
|
10
|
+
* `webhook`) calls the platform's base URL. Every call is a signed POST whose
|
|
11
|
+
* JSON body says which operation it is (`op`) and which customer it is about:
|
|
12
|
+
*
|
|
13
|
+
* POST {base}/signups { op: 'signup', customerRef, … } → 200 ReferralSignupResponse
|
|
14
|
+
* POST {base}/erase { op: 'erase', customerRef } → 2xx (404 = already gone)
|
|
15
|
+
* POST {base}/export { op: 'export', customerRef, test } → 200 JSON (any shape) | 404
|
|
16
|
+
* POST {base}/partners { op: 'partner', customerRef, code, emailHash } → 2xx | 409 code taken | 404/405/501 unsupported
|
|
17
|
+
* POST {base}/signals { op: 'signal', customerRef, type, occurredAt, data } → 2xx | 404/405/501 unsupported
|
|
18
|
+
*
|
|
19
|
+
* The connection test is `POST {base}/export` with
|
|
20
|
+
* `{ op: 'export', customerRef: 'atlas_connection_test', test: true }` (answer
|
|
21
|
+
* 2xx or 404). Calls are signed exactly like Atlas webhooks (`atlas-id`,
|
|
22
|
+
* `atlas-timestamp`, `atlas-signature` over `<id>.<timestamp>.<raw body>`),
|
|
23
|
+
* with `Idempotency-Key` and `User-Agent: Atlas-Referrals/1`. `atlas-id` is the
|
|
24
|
+
* call id, the same on every retry of one call.
|
|
25
|
+
*
|
|
26
|
+
* The signature covers the body, not the URL, so everything that matters is in
|
|
27
|
+
* the body. Pass the path the request arrived on (or the operation you
|
|
28
|
+
* expect): a signed body whose `op` does not match it is refused, so a
|
|
29
|
+
* captured call cannot be replayed against another endpoint.
|
|
30
|
+
*/
|
|
31
|
+
/** `customerRef` of the connection test (`POST {base}/export` with `test: true`). */
|
|
32
|
+
exports.REFERRAL_CONNECTION_TEST_REF = 'atlas_connection_test';
|
|
33
|
+
/** The `User-Agent` Atlas sends on every referral call. */
|
|
34
|
+
exports.REFERRAL_PROTOCOL_USER_AGENT = 'Atlas-Referrals/1';
|
|
35
|
+
/** The endpoint (last path segment) each operation is sent to. */
|
|
36
|
+
exports.REFERRAL_OP_ENDPOINTS = {
|
|
37
|
+
signup: 'signups',
|
|
38
|
+
erase: 'erase',
|
|
39
|
+
export: 'export',
|
|
40
|
+
partner: 'partners',
|
|
41
|
+
signal: 'signals',
|
|
42
|
+
};
|
|
43
|
+
function header(headers, name) {
|
|
44
|
+
if (typeof headers.get === 'function')
|
|
45
|
+
return headers.get(name) ?? undefined;
|
|
46
|
+
const bag = headers;
|
|
47
|
+
const hit = Object.keys(bag).find((k) => k.toLowerCase() === name);
|
|
48
|
+
const v = hit ? bag[hit] : undefined;
|
|
49
|
+
return Array.isArray(v) ? v[0] : v;
|
|
50
|
+
}
|
|
51
|
+
const OPS = Object.keys(exports.REFERRAL_OP_ENDPOINTS);
|
|
52
|
+
/** The operation of a path's last segment, or null when it is not a protocol endpoint. */
|
|
53
|
+
function referralOpForPath(path) {
|
|
54
|
+
let pathname = path;
|
|
55
|
+
try {
|
|
56
|
+
pathname = new URL(path, 'http://referrals.invalid').pathname;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
/* use it as given */
|
|
60
|
+
}
|
|
61
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
62
|
+
const last = segments[segments.length - 1] ?? '';
|
|
63
|
+
return OPS.find((op) => exports.REFERRAL_OP_ENDPOINTS[op] === last) ?? null;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Verify a call from Atlas to your referral platform and tell which operation
|
|
67
|
+
* it is. Never throws: check `verified`. Verify over the RAW body, before any
|
|
68
|
+
* JSON parse, and pass the path it arrived on (or `expectedOp`) so a signed
|
|
69
|
+
* body cannot be replayed against another endpoint.
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* app.post('/atlas/:endpoint', express.raw({ type: '*\/*' }), async (req, res) => {
|
|
73
|
+
* const { verified, call } = verifyReferralRequest({
|
|
74
|
+
* body: req.body, headers: req.headers, secret, path: req.path,
|
|
75
|
+
* });
|
|
76
|
+
* if (!verified || !call) return res.sendStatus(401);
|
|
77
|
+
* if (call.op === 'export' && call.test) return res.sendStatus(404);
|
|
78
|
+
* if (call.op === 'signup') return res.json(await attribute(call.payload)); // ReferralSignupResponse
|
|
79
|
+
* // erase, export, partner, signal ...
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
function verifyReferralRequest(input) {
|
|
84
|
+
const result = (0, webhooks_1.verifyWebhook)({
|
|
85
|
+
body: input.body,
|
|
86
|
+
headers: input.headers,
|
|
87
|
+
secret: input.secret,
|
|
88
|
+
now: input.now,
|
|
89
|
+
toleranceMs: input.toleranceMs,
|
|
90
|
+
});
|
|
91
|
+
if (!result.verified)
|
|
92
|
+
return { verified: false, reason: result.reason };
|
|
93
|
+
const body = result.event;
|
|
94
|
+
if (!body || typeof body !== 'object' || Array.isArray(body))
|
|
95
|
+
return { verified: false, reason: 'malformed_body' };
|
|
96
|
+
const op = body.op;
|
|
97
|
+
if (op === undefined || op === null || op === '')
|
|
98
|
+
return { verified: false, reason: 'missing_op' };
|
|
99
|
+
if (typeof op !== 'string' || !OPS.includes(op))
|
|
100
|
+
return { verified: false, reason: 'unknown_op' };
|
|
101
|
+
if (input.path !== undefined) {
|
|
102
|
+
const endpointOp = referralOpForPath(input.path);
|
|
103
|
+
if (!endpointOp)
|
|
104
|
+
return { verified: false, reason: 'unknown_endpoint' };
|
|
105
|
+
if (endpointOp !== op)
|
|
106
|
+
return { verified: false, reason: 'op_mismatch' };
|
|
107
|
+
}
|
|
108
|
+
if (input.expectedOp !== undefined && input.expectedOp !== op)
|
|
109
|
+
return { verified: false, reason: 'op_mismatch' };
|
|
110
|
+
const call = op === 'export'
|
|
111
|
+
? { op, payload: body, test: body.test === true }
|
|
112
|
+
: { op, payload: body };
|
|
113
|
+
return {
|
|
114
|
+
verified: true,
|
|
115
|
+
deliveryId: result.deliveryId,
|
|
116
|
+
timestamp: result.timestamp,
|
|
117
|
+
idempotencyKey: header(input.headers, 'idempotency-key'),
|
|
118
|
+
call,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=referrals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"referrals.js","sourceRoot":"","sources":["../src/referrals.ts"],"names":[],"mappings":";;;AAqNA,8CAUC;AAoBD,sDA+BC;AAlRD,yCAAsE;AAGtE;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,qFAAqF;AACxE,QAAA,4BAA4B,GAAG,uBAAuB,CAAC;AAEpE,2DAA2D;AAC9C,QAAA,4BAA4B,GAAG,mBAAmB,CAAC;AAmGhE,kEAAkE;AACrD,QAAA,qBAAqB,GAA+B;IAC/D,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,SAAS;CAClB,CAAC;AAgEF,SAAS,MAAM,CAAC,OAAoB,EAAE,IAAY;IAChD,IAAI,OAAQ,OAAmB,CAAC,GAAG,KAAK,UAAU;QAAE,OAAQ,OAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC;IACvG,MAAM,GAAG,GAAG,OAAwD,CAAC;IACrE,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAA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