@atlasauth/backend 0.11.0 → 0.13.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlasauth/backend changelog
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Added
6
+
7
+ - **Two-way referral sync.** Referral settings carry two-way sync: `inbound` (`url`, `secret_set`, `endpoint_id`, `last_event`) on reads, write-only `inbound_secret` and `inbound_endpoint_id` on updates (null clears), and provider capability `inbound`.
8
+ - `signReferralUpdatedEvent(...)` (and `referralUpdatedEvent` on `createTestIssuer()`): builds and signs a `referral.updated` event for a referral platform reporting changes to `POST /v1/webhooks/referrals/{instance_id}`.
9
+
10
+ ## 0.12.0
11
+ - **Referral attribution v2.** `referrals.retryFailed({ kind?, error_code? }, idempotencyKey?)` (`POST /v1/instance/referrals/calls/retry_failed`, `ReferralRetryFailedResult` with `requeued`), `referrals.simulate({ code? })` (`POST /v1/instance/referrals/simulate`, `ReferralSimulateResult`: `call_id`, `customer_ref`, `result`, `response`), `referrals.backfill({ since, codes?, code_metadata_path? }, idempotencyKey?)` and `referrals.getBackfill(id)` (`POST /v1/instance/referrals/backfill`, `GET /v1/instance/referrals/backfill/:id`, `ReferralBackfillJob`: `users_scanned`, `users_skipped`, `calls_queued`, `truncated`, `next_since`, `calls`), and `referrals.getForUser(userId)` (`GET /v1/users/:id/referral`, `UserReferralResult`).
12
+ - **Settings.** `ReferralSettings` and `UpdateReferralSettingsBody` gain `tracking_token`, `code_lookup_url`, `signup_code_field`, `forward_lifecycle`, `mirror_to_public_metadata` and `include_referral_claims`. `provider` can be `referally`. `ReferralProviderCapabilities` gains `alias`, `user` and `ping`; `needs` can list `tracking_token`. `ReferralConnectionStatus` gains `last_ping` (`ReferralPing`) and `alert` (`signature_rejected` or `connection_paused`). `ReferralConnectionTest` gains `ping`, `method` and `warnings`.
13
+ - **Call log.** `ReferralCallKind` adds `alias`, `user` and `ping`. `ReferralCall` gains `latency_ms`, `error_code`, `response`, `highlights`, `request_id` and `batch_id`. `ListReferralCallsParams` gains `error_code` and `starting_after`; `limit` goes up to 1000.
14
+ - **Users.** `users.setExternalId(id, externalId | null)` (`PATCH /v1/users/:id`); with referrals on, Atlas forwards the change to the platform as an alias. `UpdateUserBody` gains `external_id`. `UserReferral` gains `partner_external_ref`, `referral_status` and `notes`; `status` is now the attribution status (`pending`, `attributed`, `none`, `failed`, `held`, `flagged`), and the platform's own status moved to `referral_status`. New `UserReferralResolvedEvent` types the `data` of `user.referral_resolved`.
15
+ - **before_user_create hook.** New `userHooks` namespace: `getBeforeUserCreate()`, `updateBeforeUserCreate(body)` and `testBeforeUserCreate()` (`/v1/instance/hooks/before_user_create`; `BeforeUserCreateHook`, `UpdateBeforeUserCreateHookBody`, `BeforeUserCreateHookTest`).
16
+ - **Referral protocol receiver.** `verifyReferralRequest` accepts the new operations `alias` (`/aliases`, `ReferralAliasPayload`), `user` (`/users`, `ReferralUserPayload`) and `ping` (`/ping`, `ReferralPingPayload`; answer `ReferralPingResponse`), and returns `protocolVersion` (the `Atlas-Referrals-Version` header). `ReferralSignupResponse` gains optional `notes`. New constants `REFERRAL_PROTOCOL_VERSION` (`2026-10-21`) and `REFERRAL_PROTOCOL_VERSION_HEADER`.
17
+ - **Test calls.** `createTestIssuer()` gains `referralCall(options)` (an Atlas referral protocol call, signed as an instance signs it) and `referallyCall(options)` (a Referally connection call: `x-referally-signature` over the raw body, or the raw query string for `export`, with `referally-version`). Also standalone: `signAtlasReferralCall`, `signReferallyCall`, `referallySignature`, `referralEmailHash`, `REFERALLY_API_VERSION`; types `SignedReferralCall`, `AtlasReferralCallOptions`, `ReferallyCallOptions`, `ReferallyCallOp`.
18
+ - **Compatible.** New methods, types, optional fields and constants. One meaning changed on the server: `user.referral.status` is the attribution status; read the platform's status from `referral_status`.
19
+
3
20
  ## 0.11.0
4
21
  - **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
22
  - **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`).
package/README.md CHANGED
@@ -456,3 +456,25 @@ app.post('/atlas/:endpoint', express.raw({ type: '*/*' }), async (req, res) => {
456
456
  ```
457
457
 
458
458
  A retry of one call keeps its `atlas-id` (`deliveryId`). Sign-ups are idempotent on `customerRef`: answer a retry the same way.
459
+
460
+ ### Two-way sync
461
+
462
+ A provider with the `inbound` capability can send referral changes made after sign-up back to Atlas. The settings report `inbound.url` (give it to the platform), `inbound.secret_set`, `inbound.endpoint_id` and `inbound.last_event` (`{ at, type, outcome }`). Store the platform's event secret with `inbound_secret` (write-only, 16-512 characters) and its subscription id with `inbound_endpoint_id`:
463
+
464
+ ```ts
465
+ await atlas.referrals.update({ inbound_secret: process.env.REFERRAL_INBOUND_SECRET, inbound_endpoint_id: 'we_123' });
466
+ const { inbound } = await atlas.referrals.get(); // inbound.last_event?.outcome: 'applied', 'stale', …
467
+ ```
468
+
469
+ A platform on the Atlas referral protocol sends a `referral.updated` event to `inbound.url`, signed like an Atlas webhook with the inbound secret (or the connection's signing secret when none is set). `signReferralUpdatedEvent` builds it:
470
+
471
+ ```ts
472
+ import { signReferralUpdatedEvent } from '@atlasauth/backend';
473
+
474
+ const e = signReferralUpdatedEvent({
475
+ inboundUrl: settings.inbound.url,
476
+ secret: process.env.REFERRAL_SIGNING_SECRET!,
477
+ event: { customerRef: 'user_123', referralId: 'ref_1', status: 'qualified' },
478
+ });
479
+ await fetch(e.request());
480
+ ```
@@ -16,6 +16,7 @@ declare function buildNamespaces(request: RequestFn): {
16
16
  get(id: string): Promise<import("./users").User>;
17
17
  create(body: import("./users").CreateUserBody, idempotencyKey?: string): Promise<import("./users").User>;
18
18
  update(id: string, body: import("./users").UpdateUserBody): Promise<import("./users").User>;
19
+ setExternalId(id: string, externalId: string | null): Promise<import("./users").User>;
19
20
  replaceMetadata(id: string, body: import("./users").ReplaceUserMetadataBody): Promise<import("./users").User>;
20
21
  ban(id: string): Promise<import("./users").User>;
21
22
  unban(id: string): Promise<import("./users").User>;
@@ -979,6 +980,21 @@ declare function buildNamespaces(request: RequestFn): {
979
980
  test(): Promise<import("./referrals").ReferralConnectionTest>;
980
981
  listCalls(params?: import("./referrals").ListReferralCallsParams): Promise<import("./types").ListPage<import("./referrals").ReferralCall>>;
981
982
  retryCall(id: string, idempotencyKey?: string): Promise<import("./referrals").ReferralCall>;
983
+ retryFailed(filter?: {
984
+ kind?: import("./referrals").ReferralCallKind;
985
+ error_code?: string;
986
+ }, idempotencyKey?: string): Promise<import("./referrals").ReferralRetryFailedResult>;
987
+ simulate(body?: {
988
+ code?: string;
989
+ }): Promise<import("./referrals").ReferralSimulateResult>;
990
+ backfill(body: import("./referrals").ReferralBackfillBody, idempotencyKey?: string): Promise<import("./referrals").ReferralBackfillJob>;
991
+ getBackfill(id: string): Promise<import("./referrals").ReferralBackfillJob>;
992
+ getForUser(userId: string): Promise<import("./users").UserReferralResult>;
993
+ };
994
+ userHooks: {
995
+ getBeforeUserCreate(): Promise<import("./user-hooks").BeforeUserCreateHook>;
996
+ updateBeforeUserCreate(body: import("./user-hooks").UpdateBeforeUserCreateHookBody): Promise<import("./user-hooks").BeforeUserCreateHook>;
997
+ testBeforeUserCreate(): Promise<import("./user-hooks").BeforeUserCreateHookTest>;
982
998
  };
983
999
  tokens: {
984
1000
  verify(body: import("./tokens").VerifyTokenBody): Promise<import("./tokens").TokenVerification>;
@@ -1331,6 +1347,7 @@ export * from './lti-platforms';
1331
1347
  export * from './instance';
1332
1348
  export * from './instance-security';
1333
1349
  export * from './referrals';
1350
+ export * from './user-hooks';
1334
1351
  export * from './tokens';
1335
1352
  export * from './captcha';
1336
1353
  export * from './design';
@@ -61,6 +61,7 @@ const lti_platforms_1 = require("./lti-platforms");
61
61
  const instance_1 = require("./instance");
62
62
  const instance_security_1 = require("./instance-security");
63
63
  const referrals_1 = require("./referrals");
64
+ const user_hooks_1 = require("./user-hooks");
64
65
  const tokens_1 = require("./tokens");
65
66
  const captcha_1 = require("./captcha");
66
67
  const design_1 = require("./design");
@@ -150,6 +151,8 @@ function buildNamespaces(request) {
150
151
  instanceSecurity: (0, instance_security_1.instanceSecurityResource)(request),
151
152
  // Referral attribution: the instance's referral platform connection and call log.
152
153
  referrals: (0, referrals_1.referralsResource)(request),
154
+ // The before_user_create hook (sets external_id before the user exists).
155
+ userHooks: (0, user_hooks_1.userHooksResource)(request),
153
156
  tokens: (0, tokens_1.tokensResource)(request),
154
157
  // §5 "captcha anywhere" — verify any CAPTCHA token against the instance's
155
158
  // centrally-configured provider, server-side, with the secret held by Atlas.
@@ -240,6 +243,7 @@ __exportStar(require("./lti-platforms"), exports);
240
243
  __exportStar(require("./instance"), exports);
241
244
  __exportStar(require("./instance-security"), exports);
242
245
  __exportStar(require("./referrals"), exports);
246
+ __exportStar(require("./user-hooks"), exports);
243
247
  __exportStar(require("./tokens"), exports);
244
248
  __exportStar(require("./captcha"), exports);
245
249
  __exportStar(require("./design"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","source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,gDAA8B;AAC9B,iDAA+B;AAC/B,gDAA8B;AAC9B,gDAA8B;AAC9B,6CAA2B;AAC3B,oDAAkC;AAClC,kDAAgC;AAChC,kDAAgC;AAChC,4CAA0B;AAC1B,kDAAgC;AAChC,8CAA4B;AAC5B,kDAAgC;AAChC,0DAAwC;AACxC,mDAAiC;AACjC,kDAAgC;AAChC,6CAA2B;AAC3B,sDAAoC;AACpC,8CAA4B;AAC5B,+CAA6B;AAC7B,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"}
@@ -1,5 +1,6 @@
1
1
  import { type RequestFn } from './request';
2
2
  import type { ListPage } from './types';
3
+ import type { UserReferralResult } from './users';
3
4
  /**
4
5
  * Referral attribution: the instance's connection to a referral platform.
5
6
  *
@@ -10,9 +11,16 @@ import type { ListPage } from './types';
10
11
  * call is retried, and `user.referral_attributed` is sent when it resolves.
11
12
  *
12
13
  * `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`.
14
+ * implement; see {@link verifyReferralRequest}), `referally` (the built-in
15
+ * Referally adapter: `endpoint_url` is your Referally base URL, plus
16
+ * `connection_id`, `signing_secret` and optionally `tracking_token`) or
17
+ * another built-in vendor adapter.
18
+ * `signing_secret`, `api_key` and `inbound_secret` are write-only: reads
19
+ * return `signing_secret_set` / `api_key_set` / `inbound.secret_set`.
20
+ *
21
+ * Two-way sync: a provider with the `inbound` capability sends referral
22
+ * changes made after sign-up to `inbound.url`; Atlas applies them to the
23
+ * user's referral and reports the latest one in `inbound.last_event`.
16
24
  */
17
25
  /** What a provider can do. An operation it lacks is recorded as `skipped`. */
18
26
  export interface ReferralProviderCapabilities {
@@ -22,6 +30,14 @@ export interface ReferralProviderCapabilities {
22
30
  partner: boolean;
23
31
  auto_enroll: boolean;
24
32
  signal: boolean;
33
+ /** Forwards an `external_id` change after sign-up (old id → new id). */
34
+ alias?: boolean;
35
+ /** Forwards email, name and ban/unban changes. */
36
+ user?: boolean;
37
+ /** Answers a ping (org, program, clock) for the connection test. */
38
+ ping?: boolean;
39
+ /** Sends referral changes made after sign-up to Atlas (two-way sync). */
40
+ inbound?: boolean;
25
41
  }
26
42
  /** A referral provider Atlas supports. */
27
43
  export interface ReferralProviderInfo {
@@ -30,7 +46,7 @@ export interface ReferralProviderInfo {
30
46
  name: string;
31
47
  capabilities: ReferralProviderCapabilities;
32
48
  /** What must be set before `enabled` can be true. */
33
- needs: Array<'endpoint_url' | 'signing_secret' | 'api_key' | 'connection_id'>;
49
+ needs: Array<'endpoint_url' | 'signing_secret' | 'api_key' | 'connection_id' | 'tracking_token'>;
34
50
  /** The vendor's own first-party tracking cookie, suggested when this provider is picked. */
35
51
  default_context_cookie: string | null;
36
52
  docs_url: string | null;
@@ -70,6 +86,56 @@ export interface ReferralConnectionStatus {
70
86
  retrying_calls: number;
71
87
  /** Epoch ms of the last successful call, or null. */
72
88
  last_success_at: number | null;
89
+ /** The last ping answer, when the provider supports ping. */
90
+ last_ping?: ReferralPing | null;
91
+ /**
92
+ * A refusal only a person can fix: `signature_rejected` (the platform
93
+ * answered 401: a rotated secret or clock skew) or `connection_paused`.
94
+ */
95
+ alert?: {
96
+ code: string;
97
+ message: string;
98
+ at: number;
99
+ call_id?: string;
100
+ } | null;
101
+ }
102
+ /** What Atlas did with an inbound referral event. */
103
+ export type ReferralInboundOutcome = 'applied' | 'unchanged' | 'stale' | 'unknown_customer' | 'other_program' | 'ignored';
104
+ /** Two-way sync (`inbound` on the settings). */
105
+ export interface ReferralInboundStatus {
106
+ /** Give this URL to the platform; null when the provider sends no events. */
107
+ url: string | null;
108
+ /** Whether an inbound secret is stored (the value is never returned). */
109
+ secret_set: boolean;
110
+ /** The platform's id for Atlas's event subscription, kept for reference. */
111
+ endpoint_id: string | null;
112
+ /** The latest event received, or null when none yet. */
113
+ last_event: {
114
+ at: number;
115
+ type: string;
116
+ outcome: ReferralInboundOutcome;
117
+ } | null;
118
+ }
119
+ /** What a platform answers to a ping. */
120
+ export interface ReferralPing {
121
+ ok: boolean;
122
+ connection_id?: string | null;
123
+ program_id?: string | null;
124
+ program_name?: string | null;
125
+ org_name?: string | null;
126
+ auto_enroll_users?: boolean | null;
127
+ /** The platform's clock, as it sent it. */
128
+ server_time?: string | number | null;
129
+ /** Platform clock minus Atlas clock, in ms. Over 60 s is a warning; over 5 minutes, signatures fail. */
130
+ clock_skew_ms?: number | null;
131
+ /** True when `clock_skew_ms` is over 60 seconds. */
132
+ clock_skew_warning?: boolean;
133
+ /** Epoch ms of the ping. */
134
+ at?: number | null;
135
+ http_status?: number | null;
136
+ latency_ms?: number | null;
137
+ error_code?: string | null;
138
+ error?: string | null;
73
139
  }
74
140
  /** `GET /v1/instance/referrals`. */
75
141
  export interface ReferralSettings {
@@ -100,9 +166,23 @@ export interface ReferralSettings {
100
166
  /** How long a sign-up waits for the platform (100-5000 ms, default 3000). */
101
167
  timeout_ms: number;
102
168
  security: ReferralSecuritySettings;
169
+ /** Public tracking token (the `referally` adapter derives the code lookup from it). */
170
+ tracking_token?: string | null;
171
+ /** Public, CORS-enabled lookup with `{code}` for "X invited you" on hosted sign-up. */
172
+ code_lookup_url?: string | null;
173
+ /** Show an optional "Referral code" field on hosted sign-up. */
174
+ signup_code_field?: boolean;
175
+ /** Forward email, name and ban/unban changes to the platform (default true). */
176
+ forward_lifecycle?: boolean;
177
+ /** Mirror the result into `public_metadata.referral` (default false). */
178
+ mirror_to_public_metadata?: boolean;
179
+ /** Add a `referral_code` claim (the user's own code) to ID tokens and sessions. */
180
+ include_referral_claims?: boolean;
103
181
  /** What the chosen provider still needs before referrals can be enabled. */
104
182
  missing?: string[];
105
183
  connection?: ReferralConnectionStatus | null;
184
+ /** Two-way sync: where the platform sends referral changes, and the latest one received. */
185
+ inbound?: ReferralInboundStatus;
106
186
  providers: ReferralProviderInfo[];
107
187
  updated_at?: number | null;
108
188
  }
@@ -121,6 +201,14 @@ export interface UpdateReferralSettingsBody {
121
201
  signing_secret?: string | null;
122
202
  /** Write-only vendor API key. */
123
203
  api_key?: string | null;
204
+ /**
205
+ * Write-only, 16-512 characters. Verifies the platform's events to
206
+ * `inbound.url`. Optional for the Atlas referral protocol (the signing
207
+ * secret is used when unset).
208
+ */
209
+ inbound_secret?: string | null;
210
+ /** The platform's id for Atlas's event subscription, kept for reference. */
211
+ inbound_endpoint_id?: string | null;
124
212
  /** 1-10 names of `[A-Za-z0-9_.-]{1,40}`. */
125
213
  url_params?: string[];
126
214
  context_cookie?: string | null;
@@ -133,6 +221,13 @@ export interface UpdateReferralSettingsBody {
133
221
  timeout_ms?: number;
134
222
  /** Partial: only the security fields sent change. */
135
223
  security?: Partial<ReferralSecuritySettings>;
224
+ tracking_token?: string | null;
225
+ /** An https URL containing `{code}`. */
226
+ code_lookup_url?: string | null;
227
+ signup_code_field?: boolean;
228
+ forward_lifecycle?: boolean;
229
+ mirror_to_public_metadata?: boolean;
230
+ include_referral_claims?: boolean;
136
231
  }
137
232
  /** `POST /v1/instance/referrals/test`. */
138
233
  export interface ReferralConnectionTest {
@@ -144,8 +239,91 @@ export interface ReferralConnectionTest {
144
239
  code: string;
145
240
  message: string;
146
241
  };
242
+ /** The ping answer, when the provider supports ping (the test is then a ping). */
243
+ ping?: ReferralPing | null;
244
+ /** `ping`, or `probe` (the older signed export probe). */
245
+ method?: 'ping' | 'probe';
246
+ /** Human warnings, e.g. a clock more than 60 seconds off. */
247
+ warnings?: string[];
248
+ }
249
+ /** `POST /v1/instance/referrals/simulate`: a sign-up call for a fake user, never stored. */
250
+ export interface ReferralSimulateResult {
251
+ object: 'referral_simulation';
252
+ ok: boolean;
253
+ /** The logged call, in the delivery log. */
254
+ call_id: string | null;
255
+ /** `atlas_test_<random>`. */
256
+ customer_ref: string;
257
+ http_status: number | null;
258
+ latency_ms: number | null;
259
+ /** The platform's answer, normalised (null when the call failed). */
260
+ result: {
261
+ referral: {
262
+ partner_id: string | null;
263
+ partner_external_ref: string | null;
264
+ matched_via: string | null;
265
+ status: string | null;
266
+ } | null;
267
+ partner: {
268
+ id: string | null;
269
+ code: string | null;
270
+ link: string | null;
271
+ } | null;
272
+ notes: string[];
273
+ } | null;
274
+ /** The platform's raw answer, personal fields removed. */
275
+ response: unknown;
276
+ error: {
277
+ code: string;
278
+ message: string;
279
+ } | null;
280
+ }
281
+ /** `POST /v1/instance/referrals/calls/retry_failed`. */
282
+ export interface ReferralRetryFailedResult {
283
+ object: 'referral_retry';
284
+ /** How many failed calls were queued to send now. */
285
+ requeued: number;
286
+ }
287
+ /** `POST /v1/instance/referrals/backfill`. */
288
+ export interface ReferralBackfillBody {
289
+ /** ISO 8601 date or date-time: users who signed up at or after it. */
290
+ since: string;
291
+ /** customerRef → code (a CSV, for example). Wins over `code_metadata_path`. */
292
+ codes?: Record<string, string>;
293
+ /** Where a stored code lives on the user, e.g. `public_metadata.referral_code`. */
294
+ code_metadata_path?: string;
295
+ }
296
+ /** A backfill job. Users already reported are skipped. */
297
+ export interface ReferralBackfillJob {
298
+ object: 'referral_backfill';
299
+ id: string;
300
+ /** `running` while any queued call is still to be sent, then `completed`. */
301
+ status: string;
302
+ /** Epoch ms. */
303
+ since: number;
304
+ code_metadata_path?: string | null;
305
+ /** How many codes were given in `codes`. */
306
+ codes_given?: number;
307
+ users_scanned: number;
308
+ /** Already reported, or no code while auto-enroll is off. */
309
+ users_skipped: number;
310
+ calls_queued: number;
311
+ /** True when the run stopped at its cap: start another from `next_since`. */
312
+ truncated: boolean;
313
+ /** Epoch ms, when `truncated`. */
314
+ next_since?: number | null;
315
+ /** Where the queued calls stand. */
316
+ calls: {
317
+ pending: number;
318
+ succeeded: number;
319
+ failed: number;
320
+ skipped: number;
321
+ held: number;
322
+ };
323
+ created_at: number;
324
+ finished_at?: number | null;
147
325
  }
148
- export type ReferralCallKind = 'signup' | 'erase' | 'export' | 'partner' | 'signal' | 'test';
326
+ export type ReferralCallKind = 'signup' | 'erase' | 'export' | 'partner' | 'signal' | 'alias' | 'user' | 'ping' | 'test';
149
327
  export type ReferralCallStatus = 'pending' | 'succeeded' | 'retrying' | 'failed' | 'held' | 'skipped';
150
328
  /** The risk verdict sent with a sign-up (camelCase, as on the referral protocol). */
151
329
  export interface ReferralRisk {
@@ -180,15 +358,39 @@ export interface ReferralCall {
180
358
  risk?: ReferralRisk | null;
181
359
  /** What was sent (never secrets). */
182
360
  payload?: Record<string, unknown>;
361
+ /** Round trip of the last attempt, in ms. */
362
+ latency_ms?: number | null;
363
+ /**
364
+ * Machine code of the last failure, e.g. `signature_rejected` (401, not
365
+ * retried), `connection_paused` (paused by the merchant, not retried),
366
+ * `rate_limited`, `timeout`, `network_error`.
367
+ */
368
+ error_code?: string | null;
369
+ /** The platform's last answer, with personal data removed. */
370
+ response?: unknown;
371
+ /** Sign-up calls: how the platform matched, the referrer and its notes. */
372
+ highlights?: {
373
+ matched_via: string | null;
374
+ partner_external_ref: string | null;
375
+ notes: string[];
376
+ } | null;
377
+ /** The platform's request id for its last answer, for its support team. */
378
+ request_id?: string | null;
379
+ /** The backfill job this call belongs to. */
380
+ batch_id?: string | null;
183
381
  created_at: number;
184
382
  updated_at?: number;
185
383
  }
186
384
  export interface ListReferralCallsParams {
187
- /** 1-200, default 50, newest first. */
385
+ /** 1-1000 (1-200 on servers before referral attribution v2), default 50, newest first. */
188
386
  limit?: number;
189
387
  status?: ReferralCallStatus;
190
388
  kind?: ReferralCallKind;
191
389
  user_id?: string;
390
+ /** e.g. `signature_rejected`. */
391
+ error_code?: string;
392
+ /** The id of the last call of the previous page. */
393
+ starting_after?: string;
192
394
  }
193
395
  export declare function referralsResource(request: RequestFn): {
194
396
  /** `GET /v1/instance/referrals` — settings, connection status and the supported providers. */
@@ -207,4 +409,30 @@ export declare function referralsResource(request: RequestFn): {
207
409
  * or skipped call now (a connection test cannot be retried).
208
410
  */
209
411
  retryCall(id: string, idempotencyKey?: string): Promise<ReferralCall>;
412
+ /** `POST /v1/instance/referrals/calls/retry_failed` — re-queue every failed call (not tests) to send now. */
413
+ retryFailed(filter?: {
414
+ kind?: ReferralCallKind;
415
+ error_code?: string;
416
+ }, idempotencyKey?: string): Promise<ReferralRetryFailedResult>;
417
+ /**
418
+ * `POST /v1/instance/referrals/simulate` — send a sign-up call for a fake
419
+ * user (`atlas_test_<random>`, never stored) with an optional code, and
420
+ * return what the platform answered.
421
+ */
422
+ simulate(body?: {
423
+ code?: string;
424
+ }): Promise<ReferralSimulateResult>;
425
+ /**
426
+ * `POST /v1/instance/referrals/backfill` — queue sign-up calls for existing
427
+ * users with their real sign-up time. Referrals must be on (`422
428
+ * REFERRALS_NOT_CONFIGURED` otherwise). Returns the job; poll {@link getBackfill}.
429
+ */
430
+ backfill(body: ReferralBackfillBody, idempotencyKey?: string): Promise<ReferralBackfillJob>;
431
+ /** `GET /v1/instance/referrals/backfill/:id`. */
432
+ getBackfill(id: string): Promise<ReferralBackfillJob>;
433
+ /**
434
+ * `GET /v1/users/:id/referral` — the stored result for one user (who
435
+ * referred them, how, their own code), with no call to the platform.
436
+ */
437
+ getForUser(userId: string): Promise<UserReferralResult>;
210
438
  };
@@ -34,6 +34,37 @@ function referralsResource(request) {
34
34
  idempotencyKey,
35
35
  });
36
36
  },
37
+ /** `POST /v1/instance/referrals/calls/retry_failed` — re-queue every failed call (not tests) to send now. */
38
+ retryFailed(filter = {}, idempotencyKey) {
39
+ return request({ method: 'POST', path: '/v1/instance/referrals/calls/retry_failed', body: filter, idempotencyKey });
40
+ },
41
+ /**
42
+ * `POST /v1/instance/referrals/simulate` — send a sign-up call for a fake
43
+ * user (`atlas_test_<random>`, never stored) with an optional code, and
44
+ * return what the platform answered.
45
+ */
46
+ simulate(body = {}) {
47
+ return request({ method: 'POST', path: '/v1/instance/referrals/simulate', body });
48
+ },
49
+ /**
50
+ * `POST /v1/instance/referrals/backfill` — queue sign-up calls for existing
51
+ * users with their real sign-up time. Referrals must be on (`422
52
+ * REFERRALS_NOT_CONFIGURED` otherwise). Returns the job; poll {@link getBackfill}.
53
+ */
54
+ backfill(body, idempotencyKey) {
55
+ return request({ method: 'POST', path: '/v1/instance/referrals/backfill', body, idempotencyKey });
56
+ },
57
+ /** `GET /v1/instance/referrals/backfill/:id`. */
58
+ getBackfill(id) {
59
+ return request({ method: 'GET', path: `/v1/instance/referrals/backfill/${(0, request_1.enc)(id)}` });
60
+ },
61
+ /**
62
+ * `GET /v1/users/:id/referral` — the stored result for one user (who
63
+ * referred them, how, their own code), with no call to the platform.
64
+ */
65
+ getForUser(userId) {
66
+ return request({ method: 'GET', path: `/v1/users/${(0, request_1.enc)(userId)}/referral` });
67
+ },
37
68
  };
38
69
  }
39
70
  //# sourceMappingURL=referrals.js.map
@@ -1 +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,IA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1
+ import type { RequestFn } from './request';
2
+ /**
3
+ * The `before_user_create` hook: just before Atlas creates a user from an
4
+ * interactive sign-up, it calls your endpoint (signed exactly like a webhook:
5
+ * `atlas-id`, `atlas-timestamp`, `atlas-signature`, verify with
6
+ * {@link verifyWebhook}) with an event of type `user.before_create`, and stamps
7
+ * the `external_id` and metadata you answer. A referral call then goes out
8
+ * with your id. Slow or failing hooks never block a sign-up.
9
+ *
10
+ * Answer `{ external_id?, public_metadata?, private_metadata?, unsafe_metadata? }`.
11
+ */
12
+ export interface BeforeUserCreateHook {
13
+ object: 'before_user_create_hook';
14
+ enabled: boolean;
15
+ url: string | null;
16
+ /** The secret is write-only. */
17
+ signing_secret_set: boolean;
18
+ /** At most 5000, default 3000. */
19
+ timeout_ms: number;
20
+ /** The last call Atlas made to the hook. */
21
+ last_call: {
22
+ at: number;
23
+ status: string | null;
24
+ error: string | null;
25
+ } | null;
26
+ updated_at: number | null;
27
+ }
28
+ export interface UpdateBeforeUserCreateHookBody {
29
+ enabled?: boolean;
30
+ /** https (http only for localhost on a development instance); `null` clears. */
31
+ url?: string | null;
32
+ /** Write-only; `null` clears. */
33
+ signing_secret?: string | null;
34
+ timeout_ms?: number;
35
+ }
36
+ /** `POST …/test`: a sample draft sent to the hook; nothing is stored. */
37
+ export interface BeforeUserCreateHookTest {
38
+ ok: boolean;
39
+ latency_ms: number;
40
+ answer?: {
41
+ external_id: string | null;
42
+ public_metadata: Record<string, unknown> | null;
43
+ private_metadata_set: boolean;
44
+ unsafe_metadata: Record<string, unknown> | null;
45
+ };
46
+ error?: {
47
+ code: string;
48
+ message: string;
49
+ };
50
+ }
51
+ export declare function userHooksResource(request: RequestFn): {
52
+ /** `GET /v1/instance/hooks/before_user_create`. */
53
+ getBeforeUserCreate(): Promise<BeforeUserCreateHook>;
54
+ /** `PATCH /v1/instance/hooks/before_user_create` — partial; the secret is write-only. */
55
+ updateBeforeUserCreate(body: UpdateBeforeUserCreateHookBody): Promise<BeforeUserCreateHook>;
56
+ /** `POST /v1/instance/hooks/before_user_create/test`. */
57
+ testBeforeUserCreate(): Promise<BeforeUserCreateHookTest>;
58
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.userHooksResource = userHooksResource;
4
+ const PATH = '/v1/instance/hooks/before_user_create';
5
+ function userHooksResource(request) {
6
+ return {
7
+ /** `GET /v1/instance/hooks/before_user_create`. */
8
+ getBeforeUserCreate() {
9
+ return request({ method: 'GET', path: PATH });
10
+ },
11
+ /** `PATCH /v1/instance/hooks/before_user_create` — partial; the secret is write-only. */
12
+ updateBeforeUserCreate(body) {
13
+ return request({ method: 'PATCH', path: PATH, body });
14
+ },
15
+ /** `POST /v1/instance/hooks/before_user_create/test`. */
16
+ testBeforeUserCreate() {
17
+ return request({ method: 'POST', path: `${PATH}/test` });
18
+ },
19
+ };
20
+ }
21
+ //# sourceMappingURL=user-hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-hooks.js","sourceRoot":"","sources":["../../src/client/user-hooks.ts"],"names":[],"mappings":";;AAkDA,8CAeC;AAjBD,MAAM,IAAI,GAAG,uCAAuC,CAAC;AAErD,SAAgB,iBAAiB,CAAC,OAAkB;IAClD,OAAO;QACL,mDAAmD;QACnD,mBAAmB;YACjB,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,yFAAyF;QACzF,sBAAsB,CAAC,IAAoC;YACzD,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,yDAAyD;QACzD,oBAAoB;YAClB,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,OAAO,EAAE,CAAC,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC"}