@sparkvault/sdk-js 12.0.5 → 13.0.1

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.
@@ -19,16 +19,28 @@
19
19
  */
20
20
  import type { NotificationRow, ListNotificationsResponse, MarkNotificationStateResponse, NotificationInboxState, NotificationMarkState, NotificationBulkMarkState } from '../../notify/types';
21
21
  import type { UnsealedVault } from '../../vaults/types';
22
- /** Every transport the dispatch seam can carry a notification on. */
22
+ /**
23
+ * Every transport the dispatch seam can carry a notification on: what a send's
24
+ * status, a stored ladder and a config read can name. An organization's own
25
+ * send, and its config's ladders, may name only two of them:
26
+ *
27
+ * | Channel | An organization's send |
28
+ * | --- | --- |
29
+ * | `in_app` | Delivered by the notification's row in your Notify inbox, which your app reads through `getInbox`: the inbox lists a recipient's row when their `in_app` step runs, at once when it leads the ladder and only when that step comes due when it follows `email` (a stop that ends the ladder first, such as an unsubscribe on a non-critical send or a recall, leaves it unlisted), so a send naming `email` alone lists nothing there, and neither does one to a recipient who switched In-app off for your site on auth.sv (any send but a `security` one, which crosses that switch) |
30
+ * | `email` | Goes out from your organization's own sender (`getEmailSender`) |
31
+ * | `sms`, `voice`, `whatsapp`, `rcs` | Refused 403 `NOTIFY_CHANNEL_NOT_AVAILABLE`: Notify delivers no text, call or chat message |
32
+ * | `push`, `web_push` | Refused 403 `NOTIFY_CHANNEL_NOT_AVAILABLE`: SparkVault's own devices only |
33
+ * | `webhook`, `slack`, `teams` | Refused 403 `NOTIFY_CHANNEL_NOT_AVAILABLE`: SparkVault's own destinations only |
34
+ */
23
35
  export type NotifyChannel = 'in_app' | 'email' | 'sms' | 'push' | 'web_push' | 'voice' | 'whatsapp' | 'rcs' | 'webhook' | 'slack' | 'teams';
24
36
  /**
25
37
  * How a send's content reaches the recipient.
26
38
  * - `sealed` (default): content is sealed into a Spark behind a single-use
27
39
  * SparkLink; channels carry only the pointer ("tap to view").
28
40
  * - `plaintext`: a short non-confidential body rendered INLINE in the channel
29
- * payload. Fail-closed — restricted to inline-capable channels
30
- * (`in_app`/`push`/`web_push`/`email`), at most 50 recipients, and never
31
- * allowed on a confidential category.
41
+ * payload. Fail-closed — at most 50 recipients, never allowed on a
42
+ * confidential category, and on the inline-capable channels alone, which
43
+ * for an organization's send are both of its own (`in_app` and `email`).
32
44
  */
33
45
  export type NotifyDeliveryMode = 'sealed' | 'plaintext';
34
46
  /**
@@ -48,9 +60,14 @@ export type NotifyVerificationLevel = 'none' | 'identifier' | 'passkey';
48
60
  /** What the recipient does at the reveal — the interaction the receipt attests to. */
49
61
  export type NotifyInteraction = 'view' | 'acknowledge' | 'sign' | 'approve' | 'reply';
50
62
  /**
51
- * The fixed categories the five presets classify their sends as. These are
52
- * interaction bundles, not account topics — they are independent of
53
- * `config.categories`.
63
+ * The fixed categories the five presets classify their sends as. Each is seeded
64
+ * into the account's `config.categories` like any other topic, so its
65
+ * `required` flag decides whether a recipient may mute it and whether it sits on
66
+ * the compliance floor: `secure`, `approval` and `signature` are seeded
67
+ * required, `alert` and `conversation` are not. A tenant may demote or tombstone
68
+ * any of them (only `security` is reserved). The send endpoint accepts a preset
69
+ * category whatever the map holds, so an edit changes what the category
70
+ * derives, never whether it can be sent.
54
71
  */
55
72
  export type NotifyPresetCategory = 'alert' | 'secure' | 'conversation' | 'approval' | 'signature';
56
73
  /**
@@ -63,17 +80,44 @@ export type NotifyCategory = NotifyPresetCategory | (string & Record<never, neve
63
80
  /** The five secure-by-default preset bundles. */
64
81
  export type NotifyPresetName = 'alert' | 'secureMessage' | 'conversation' | 'approval' | 'signatureRequest';
65
82
  /**
66
- * A recipient addressed by the handles the SENDER knows them by. `id` is the
67
- * stable inbox partition key (an SVID `ing_*`, a console user id `usr_*`, or the
68
- * tenant's own key); `email` / `phone` are the deliverable handles. A bare string
69
- * is an identifier that is its own invite.
83
+ * A recipient addressed by the handles the SENDER knows them by. `id` is your
84
+ * own key for them, or their Identity id (SVID, `ing_*`); `email` is where the
85
+ * email channel delivers and the address a sealed send's recipient proves to
86
+ * open it. A bare string is an email address or an SVID: a bare address is
87
+ * also the address its recipient proves, while a bare SVID keys the person's
88
+ * inbox row and carries no address to verify.
89
+ *
90
+ * The recipient's key is its `id`, else its `email`, trimmed, with an email
91
+ * address lowercased the way Identity stores it: it names their row in your
92
+ * Notify inbox, and `getSendStatus` and `getSendReceipts` report it as
93
+ * `recipient_id`.
70
94
  *
71
- * Recipient preferences and device-channel capability are resolved from the id,
72
- * so addressing by SVID is what makes per-person preferences apply.
95
+ * A person's stored notification preferences apply however you address them:
96
+ * an SVID `id` names the person, and each address a recipient carries is
97
+ * resolved to the person who holds it through Identity's directory.
98
+ *
99
+ * Refused with one 400 (`serviceCode` `VALIDATION_ERROR`) naming each such entry
100
+ * by index: a SparkVault user id (`usr_*`), which only SparkVault's own
101
+ * notifications address; a recipient with no email address that a phone number
102
+ * would key (a bare number, `{ phone }`, or an `id` that is an E.164 number);
103
+ * on a sealed send, one whose only handle is a phone (`{ id, phone }`); and, on
104
+ * a sealed send at the default `identifier` level or at `passkey`, one with no
105
+ * address to verify (a bare SVID, or an `id` alone): give it `{ id, email }`,
106
+ * or send at `verificationLevel: 'none'`.
73
107
  */
74
108
  export interface NotifyRecipientRef {
109
+ /** At most 256 bytes of UTF-8 with no control characters: it keys the recipient's inbox. */
75
110
  id?: string;
111
+ /**
112
+ * The address the email channel delivers to. A recipient with no `id` is keyed
113
+ * by its address, which is then held to the id's 256-byte bound: give an address
114
+ * longer than that an `id` of your own (`{ id, email }`), or the send is refused.
115
+ */
76
116
  email?: string;
117
+ /**
118
+ * E.164. Notify delivers nothing to a phone, so a recipient that names one
119
+ * also needs an `email`, or, on a plaintext send, an `id`.
120
+ */
77
121
  phone?: string;
78
122
  }
79
123
  export type NotifyRecipient = string | NotifyRecipientRef;
@@ -108,6 +152,10 @@ export interface NotifySendContent {
108
152
  * `AUTHENTICATION_ERROR`; an expired one 403 (`details.reason: 'VAT_EXPIRED'`,
109
153
  * unseal again and retry), a read-only one 403 (`'VAT_READ_ONLY'`), and one for
110
154
  * another vault 403 `FORBIDDEN`.
155
+ *
156
+ * Each code named here is the service's and arrives as the thrown error's
157
+ * `serviceCode`; a 400, 401 or 403 error's own `code` names its class
158
+ * (`validation_error`, `authentication_error`, `authorization_error`).
111
159
  */
112
160
  export interface NotifyIngotRef {
113
161
  ingotId: string;
@@ -124,6 +172,17 @@ export interface NotifySendPolicy {
124
172
  interaction?: NotifyInteraction;
125
173
  /** Require the recipient to have verified within N minutes of revealing. */
126
174
  revealFreshnessMinutes?: number;
175
+ /**
176
+ * What an `approve` or `sign` receipt attests the recipient acted on: 64
177
+ * lowercase hex, the SHA-256 of the canonical bytes of the thing being
178
+ * approved or signed. It is stamped onto every grant, and the signed receipt
179
+ * carries it verbatim as its `action_hash`, so a hash recomputed later from
180
+ * your own copy proves WHAT was approved. Without it the receipt carries a
181
+ * digest of the grant itself, which no hash of your document can match, so
182
+ * supply it on every approve and sign send. A value of another shape is
183
+ * refused with 400, `serviceCode` `VALIDATION_ERROR`.
184
+ */
185
+ actionHash?: string;
127
186
  }
128
187
  /**
129
188
  * Cumulative per-step delays in SECONDS from send time, one per channel step.
@@ -139,7 +198,12 @@ export interface CreateNotifySendOptions {
139
198
  /**
140
199
  * Idempotency key, `^[A-Za-z0-9_.:-]{1,128}$`. Replaying an existing id returns
141
200
  * the stored send unchanged — never re-sealed, never re-delivered — with
142
- * `idempotent: true`. Generated (`ntsnd_*`) when absent.
201
+ * `idempotent: true`. Generated (`ntsnd_*`) when absent. A replay must repeat
202
+ * what the recipient meets (the delivery mode, the content or ingot, the
203
+ * recipients and their handles, title, category, instructions, policy,
204
+ * channels and escalation): one that differs in any of them is refused 400
205
+ * (`serviceCode` `VALIDATION_ERROR`), and the stored send stands. `type` and
206
+ * `historyTtlDays` are not compared: the stored send keeps its own.
143
207
  */
144
208
  sendId?: string;
145
209
  /** 1-500 recipients. An ingot send accepts exactly one. */
@@ -151,10 +215,21 @@ export interface CreateNotifySendOptions {
151
215
  /** Defaults to `sealed`. */
152
216
  delivery?: NotifyDeliveryMode;
153
217
  policy?: NotifySendPolicy;
154
- /** Channel ladder override; omit to resolve from the account config per category. */
155
- channels?: NotifyChannel[];
218
+ /**
219
+ * Channel ladder override, in escalation order; omit to resolve from the
220
+ * account config per category. An organization's send names its own two
221
+ * channels (see `NotifyChannel`): any other is refused 403, `serviceCode`
222
+ * `NOTIFY_CHANNEL_NOT_AVAILABLE`, `details: { field: 'channels', channels }`.
223
+ */
224
+ channels?: Array<'in_app' | 'email'>;
156
225
  escalation?: NotifyEscalation;
157
- /** Channel-agnostic display title (rides the email subject). Truncated at 200 chars, never rejected. */
226
+ /**
227
+ * Channel-agnostic display title (rides the email subject). Cut to 200
228
+ * characters, never rejected for its length. A title that reads as SparkVault,
229
+ * or holds a text-direction control character, is refused 400 with
230
+ * `details: { field: 'title', reason: 'reserved_name' }`: the notification goes
231
+ * out in your organization's name.
232
+ */
158
233
  title?: string;
159
234
  /**
160
235
  * REQUIRED. The category this send is classified as — one of your configured
@@ -165,14 +240,21 @@ export interface CreateNotifySendOptions {
165
240
  * recipient consented to. The preset helpers stamp their own.
166
241
  */
167
242
  category: NotifyCategory;
168
- /** Free-form display type the tenant uses to classify the send. */
243
+ /**
244
+ * Display classifier the tenant tags the send with, at most 64 characters once
245
+ * folded to one line; a longer one is refused rather than cut short.
246
+ */
169
247
  type?: string;
170
248
  /**
171
249
  * NON-SECRET display text (≤500 chars) shown alongside a sealed send — e.g.
172
250
  * "verify with your passkey to open". It is never the sealed content.
173
251
  */
174
252
  instructions?: string;
175
- /** Inbox-row retention, default 30. A plaintext send is capped at 7. */
253
+ /**
254
+ * Inbox-row retention in days, 1 to 3650. Defaults to the account's
255
+ * `history.history_ttl_days` (30 unless configured); a value outside the
256
+ * range is refused 400. A plaintext send is capped at 7.
257
+ */
176
258
  historyTtlDays?: number;
177
259
  }
178
260
  /**
@@ -187,6 +269,11 @@ export interface NotifySendResult {
187
269
  send_id: string;
188
270
  /** Number of recipients the send was accepted for. */
189
271
  recipients: number;
272
+ /**
273
+ * `pending`: accepted for delivery. The send row's status is written once and
274
+ * never advances, so read how the send is landing from `getSendStatus` or
275
+ * `listSends`, whose state is derived.
276
+ */
190
277
  status: string;
191
278
  /**
192
279
  * Present (and `true`) ONLY on an idempotent replay of an existing `send_id`.
@@ -194,14 +281,18 @@ export interface NotifySendResult {
194
281
  */
195
282
  idempotent?: boolean;
196
283
  }
197
- /** One preset's fixed bundle, merged UNDER the caller's own arguments. */
284
+ /**
285
+ * One preset's fixed bundle, merged UNDER the caller's own arguments. The
286
+ * exported table is shared by every send in the process, so it is read-only:
287
+ * `buildNotifyPresetSend` hands back options of the caller's own to adjust.
288
+ */
198
289
  export interface NotifyPreset {
199
- category: NotifyPresetCategory;
200
- delivery?: NotifyDeliveryMode;
201
- channels?: NotifyChannel[];
202
- policy: {
203
- verificationLevel: NotifyVerificationLevel;
204
- interaction: NotifyInteraction;
290
+ readonly category: NotifyPresetCategory;
291
+ readonly delivery?: NotifyDeliveryMode;
292
+ readonly channels?: readonly NotifyChannel[];
293
+ readonly policy: {
294
+ readonly verificationLevel: NotifyVerificationLevel;
295
+ readonly interaction: NotifyInteraction;
205
296
  };
206
297
  }
207
298
  /** Inbox views the feed can be filtered to. `all` excludes archived rows. */
@@ -215,10 +306,11 @@ export type NotifyInboxMarkState = NotificationMarkState;
215
306
  export type NotifyInboxBulkMarkState = NotificationBulkMarkState;
216
307
  export interface ListNotifyInboxOptions {
217
308
  /**
218
- * The inbox owner, keyed EXACTLY as addressed on the send. Identity claim never
219
- * migrates or aliases prior email/phone-keyed rows, so a tenant that switches to
220
- * SVID addressing should also read the prior identifier partition for its
221
- * `history_ttl_days` window.
309
+ * The inbox owner: the recipient's key (see `NotifyRecipientRef`), or the id
310
+ * or address as the send named it, which is read in that form. Rows stay
311
+ * under the key they were sent to: none is moved or aliased when the person
312
+ * later gets an SVID, so a tenant that switches from email to SVID addressing
313
+ * should also read the email-keyed inbox for its `history_ttl_days` window.
222
314
  */
223
315
  recipientId: string;
224
316
  state?: NotifyInboxView;
@@ -256,26 +348,73 @@ export interface MarkNotifyInboxAllResponse {
256
348
  * The one answer for a recipient, derived from their row (never stored, so it
257
349
  * cannot drift from the facts it summarizes).
258
350
  *
259
- * - `pending` — still in flight, or not yet driven.
351
+ * - `pending` — still in flight, or not yet driven: the escalation ladder has a
352
+ * step left to run and nothing has settled them, whatever its steps so far
353
+ * recorded short of a delivery. A recipient whose first channel declined
354
+ * stays here while the next one waits its turn.
260
355
  * - `delivered` — a channel accepted it and no provider has repudiated that, or
261
356
  * the recipient opened the sealed content or marked it seen and a later
262
357
  * escalation step recorded that before any recall.
263
- * - `undeliverable` — every channel attempted declined (no handle, bounced, not
264
- * implemented). The recipient cannot be reached as addressed.
265
- * - `failed` — a channel exhausted its retries. OUR transport gave up; the
266
- * address may be perfectly good.
267
- * - `suppressed` — the PERSON chose silence (site off, category muted, every
268
- * offered channel opted out). Not a fault, and not something to route around.
269
- * - `rate_limited` — skipped by the per-recipient abuse ceiling for that minute.
270
- * - `recalled` — the sender took it back before a channel reached this recipient.
271
- * The reveal is revoked and no further delivery will be attempted. It ranks
272
- * BELOW `delivered`: a channel that already reached someone reached them, and
273
- * engagement an escalation step recorded before the recall stands too, so a
274
- * recall afterwards leaves them `delivered`. It covers recipients the recall
275
- * itself marked AND, on a whole-audience recall, everyone the fan-out was
276
- * stopped before ever writing a row for.
358
+ * - `undeliverable` — the ladder ran its course and every channel attempted
359
+ * declined (no handle, bounced, not implemented). The recipient cannot be
360
+ * reached as addressed. A hard bounce of their only delivery moves them here
361
+ * at once, even with a step left to run (or to `failed`, if another channel
362
+ * gave up), until a later step delivers it or records that they opened or
363
+ * marked it seen. A recipient whose grant expired before a channel reached
364
+ * them reads `undeliverable` too, unless a channel had already failed. Their
365
+ * address may be fine: the grant can expire before their first step goes, or
366
+ * while their email retries or is deferred, and then `channel_outcomes`
367
+ * record no decline.
368
+ * - `failed` — the ladder ran its course (or their grant expired, or a hard
369
+ * bounce of their only delivery settled them), every attempt ended, and a
370
+ * channel gave up: it exhausted its retries, or their deferred email could
371
+ * not go within 24 hours of the send. OUR transport gave up; the address may
372
+ * be perfectly good.
373
+ * - `suppressed` — taken out of the ladder by a decision, not a fault. Usually
374
+ * the PERSON chose silence (site off, category muted, every offered channel
375
+ * opted out, your site blocked on auth.sv for a sealed send, or the address
376
+ * unsubscribed); otherwise your account was suspended or began deleting before
377
+ * their next queued step came due. Not something to route around.
378
+ * - `rate_limited` — skipped by the per-recipient abuse ceiling for that minute,
379
+ * decided once per send and recipient.
380
+ * - `recalled` — the sender took it back, and nothing on this recipient's row
381
+ * outranks the recall. The reveal is revoked and no further delivery will be
382
+ * attempted. Recall cannot undo what already happened, so it ranks BELOW every
383
+ * answer the row already records: `delivered` (a channel reached them, or
384
+ * engagement an escalation step recorded before the recall), `suppressed`,
385
+ * `rate_limited`, and `undeliverable` / `failed` when no channel could reach
386
+ * them or their ladder ran its course with every channel declining or giving
387
+ * up before the recall. A recall that stops a ladder before it runs its course
388
+ * reads `recalled`, whatever its earlier steps recorded — so a recipient whose
389
+ * first channel skipped them and who was recalled before their next channel
390
+ * reads `recalled`. It also covers recipients with no row
391
+ * yet: everyone a whole-audience recall stopped the fan-out before reaching,
392
+ * and everyone a targeted recall named before the fan-out reached them.
277
393
  */
278
394
  export type NotifyRecipientState = 'pending' | 'delivered' | 'undeliverable' | 'failed' | 'suppressed' | 'rate_limited' | 'recalled';
395
+ /**
396
+ * Why the pipeline took a recipient out of the ladder, as a fixed token (never a
397
+ * transport's own words, so nothing recipient-identifying rides it).
398
+ *
399
+ * - `no_channels` — the send offered no usable channel at all.
400
+ * - `unreachable` — every offered channel lacks a handle for them.
401
+ * - `global_off` — the person switched this sender off entirely.
402
+ * - `category_muted` — the person muted this category.
403
+ * - `all_channels_opted_out` — the person opted out of every channel offered.
404
+ * - `site_blocked` — the person blocked your site on auth.sv, and the send was
405
+ * sealed: opening it asks them to prove the address it was sent to, a proof
406
+ * of address that signs them in to nothing and opens no session, and their
407
+ * block refuses that proof.
408
+ * - `identifier_unsubscribed` — a transport reported, mid-ladder, that the
409
+ * person unsubscribed the address the send was addressed to.
410
+ * - `account_unavailable` — your account was suspended or began deleting before
411
+ * the recipient's next queued step came due, so their ladder ended there.
412
+ *
413
+ * The first two roll up to the `undeliverable` state (they need an address that
414
+ * reaches them), the other six to `suppressed` (a decision, not a fault: the
415
+ * person asked to be left alone, or your account was stopped).
416
+ */
417
+ export type NotifySuppressionReason = 'no_channels' | 'unreachable' | 'global_off' | 'category_muted' | 'all_channels_opted_out' | 'site_blocked' | 'identifier_unsubscribed' | 'account_unavailable';
279
418
  export interface NotifySendStatusRecipient {
280
419
  recipient_id: string;
281
420
  /** The derived per-recipient state — the field to branch on. */
@@ -285,34 +424,68 @@ export interface NotifySendStatusRecipient {
285
424
  seen_at: number | null;
286
425
  read_at: number | null;
287
426
  archived_at: number | null;
288
- /** When the recipient's own preference took them out of the ladder. */
427
+ /**
428
+ * When the recipient was taken out of the ladder: by their own choice or their
429
+ * block of your site, for want of an address that reaches them, or by your
430
+ * account's stop. Not always an opt-out: `suppressed_reason` says why, and
431
+ * `state` already separates an unreachable recipient from one who opted out.
432
+ */
289
433
  suppressed_at: number | null;
434
+ /** Why the recipient was taken out of the ladder; null while `suppressed_at` is. */
435
+ suppressed_reason: NotifySuppressionReason | null;
290
436
  /**
291
- * When the per-recipient ceiling skipped them. Cleared if a later fan-out
292
- * drives them, so it never outlives the skip it describes.
437
+ * When the per-recipient ceiling skipped them, decided once per send and
438
+ * recipient. Only a delivery that raced the refusal (a retried fan-out that
439
+ * read them admitted before it landed) clears it, and then they read as any
440
+ * driven recipient.
293
441
  */
294
442
  rate_limited_at: number | null;
295
443
  /**
296
444
  * The latest dispatch outcome per attempted channel — the difference between a
297
445
  * notification that actually left the building and one whose every channel
298
446
  * declined. `{}` until the first dispatch is recorded. The adapter `detail`
299
- * string is deliberately NOT carried here: it can echo a provider response body
300
- * (and with it the recipient's raw contact), which this rollup never exposes.
447
+ * string is deliberately NOT carried here: it can echo a provider response body,
448
+ * and with it a phone number or address the rollup does not otherwise carry.
301
449
  */
302
450
  channel_outcomes: Partial<Record<NotifyChannel, {
303
451
  outcome: 'delivered' | 'skipped' | 'not_implemented' | 'retryable'
304
- /** The step exhausted its retries — terminal, unlike `retryable`. */
452
+ /**
453
+ * An email step that could not go yet, tried again at `retry_at` for
454
+ * its `reason` — not terminal: a step that cannot go within 24 hours
455
+ * of the send is recorded `failed` instead. Left out once the
456
+ * recipient's record holds a stop its step meets when it wakes (they
457
+ * saw the notification, it was recalled, or their ladder already
458
+ * ended undelivered), since that step sends nothing. A stop held on
459
+ * no record (their grant spent or expired, your account stopped) is
460
+ * met only when the step wakes, and the entry stays until then.
461
+ */
462
+ | 'deferred'
463
+ /**
464
+ * The step exhausted its retries, or was deferred and could not go
465
+ * within 24 hours of the send — terminal, unlike `retryable`. The
466
+ * ladder moves on to its next channel.
467
+ */
305
468
  | 'failed'
306
469
  /**
307
470
  * The provider repudiated a delivery it had accepted. It REPLACES the
308
- * channel's `delivered` entry: handing a message to SES was never
309
- * proof it reached a mailbox.
471
+ * channel's `delivered` entry: handing a message to the email provider
472
+ * was never proof it reached a mailbox.
310
473
  */
311
474
  | 'bounced';
312
475
  /** Epoch seconds the outcome was recorded. */
313
476
  at: number | null;
314
477
  /** Escalation step index the outcome came from. */
315
478
  step: number | null;
479
+ /** For a `deferred` step, epoch seconds it is tried again; null on every other outcome. */
480
+ retry_at: number | null;
481
+ /**
482
+ * For a `deferred` step, why it waits: the platform's per-second rate or
483
+ * its hourly email lane, your account's hourly email share, the provider
484
+ * refusing for its rate, the provider's sending paused, or the platform's
485
+ * own mail domain the email goes out from not verified for sending. Null
486
+ * on every other outcome.
487
+ */
488
+ reason: 'platform_rate' | 'platform_hourly' | 'account_hourly' | 'provider_throttled' | 'sending_paused' | 'sender_identity_unverified' | null;
316
489
  }>>;
317
490
  /**
318
491
  * At least one channel accepted the notification for this recipient. A
@@ -321,16 +494,19 @@ export interface NotifySendStatusRecipient {
321
494
  */
322
495
  delivered: boolean;
323
496
  /**
324
- * Every channel attempted for this recipient declined (`skipped`,
325
- * `not_implemented`, or `bounced`) and none delivered — a silent
326
- * non-delivery. False while nothing has been attempted yet and while a
327
- * `retryable` attempt is still in flight.
497
+ * Something was attempted, nothing delivered, and every recorded outcome
498
+ * declined (`skipped`, `not_implemented`, or `bounced`). False while nothing
499
+ * has been attempted yet and while a `retryable` attempt is still in flight. A
500
+ * transport fact about the attempts so far: while the ladder has a step left
501
+ * to run it can be true with `state` still `pending`.
328
502
  */
329
503
  undeliverable: boolean;
330
504
  /**
331
- * Every attempt is terminal, nothing delivered, and at least one channel
332
- * exhausted its retries. Distinct from `undeliverable`: this one is a
333
- * transport problem on our side, not an address that cannot receive.
505
+ * Every attempt is terminal, nothing delivered, and at least one channel's
506
+ * outcome is `failed`: it exhausted its retries, or was deferred and could
507
+ * not go within 24 hours of the send — a transport problem on our side, not
508
+ * an address that cannot receive. A transport fact about the attempts so
509
+ * far, like `undeliverable`.
334
510
  */
335
511
  failed: boolean;
336
512
  }
@@ -340,40 +516,58 @@ export interface NotifySendStatusCounts {
340
516
  seen: number;
341
517
  read: number;
342
518
  archived: number;
519
+ /**
520
+ * Recipients with a deferred email step, whatever their `state`: one no
521
+ * other channel reached reads `pending` until the step runs, and one
522
+ * another channel already reached reads `delivered` while it waits. A wait
523
+ * is not counted once the recipient's record holds a stop its step meets
524
+ * when it wakes (they saw the notification, it was recalled, or their
525
+ * ladder already ended undelivered): that step sends nothing. A stop held
526
+ * on no record (their grant spent or expired, your account stopped) is met
527
+ * only when the step wakes, and the wait is counted until then.
528
+ */
529
+ deferred: number;
343
530
  /**
344
531
  * The seven state counters below PARTITION the audience — one per
345
532
  * `NotifyRecipientState`:
346
533
  * `pending + delivered + undeliverable + failed + suppressed + rate_limited + recalled === total`.
347
- * (`enqueued` / `seen` / `read` / `archived` are independent progress markers
348
- * and do not partition anything.)
534
+ * (`enqueued` / `seen` / `read` / `archived` / `deferred` are independent
535
+ * progress markers and do not partition anything.)
349
536
  */
350
537
  pending: number;
351
538
  /** Recipients whose `state` is `delivered`. */
352
539
  delivered: number;
353
- /** Recipients whose every attempted channel declined — the silent-failure count. */
540
+ /** Recipients whose `state` is `undeliverable`. */
354
541
  undeliverable: number;
355
- /** Recipients whose ladder ended with a channel that exhausted its retries. */
542
+ /** Recipients whose `state` is `failed`. */
356
543
  failed: number;
357
- /** Recipients who opted out. Never a failure. */
544
+ /**
545
+ * Recipients taken out of the ladder by a decision: their own, or your
546
+ * account's stop. Never a delivery failure.
547
+ */
358
548
  suppressed: number;
359
549
  /** Recipients skipped by the per-recipient ceiling. */
360
550
  rate_limited: number;
361
551
  /**
362
- * Recipients the sender took back before a channel reached them. A recalled
552
+ * Recipients whose `state` is `recalled`: taken back by the sender with nothing
553
+ * on their row outranking the recall (see `NotifyRecipientState`). A recalled
363
554
  * send therefore settles instead of sitting on `pending` until it expires.
364
555
  */
365
556
  recalled: number;
366
557
  }
367
558
  /**
368
559
  * The sender's per-recipient delivery rollup. Metadata only by construction: it
369
- * never carries the SparkLink pointer, the recipient's raw contact, or policy
370
- * internals.
560
+ * never carries the SparkLink pointer, policy internals, or a contact you did not
561
+ * supply — `recipient_id` is the recipient's key (see `NotifyRecipientRef`), so a
562
+ * recipient addressed by email alone appears as that address, trimmed and
563
+ * lowercased. Address recipients as `{ id, email }` to keep their addresses out
564
+ * of the rollup.
371
565
  */
372
566
  export interface NotifySendStatus {
373
567
  send_id: string;
374
568
  /**
375
569
  * DERIVED, never stored — and by the SAME function the send-history list uses,
376
- * so a send cannot read one way in the list and another here.
570
+ * so the two never disagree about what a state means.
377
571
  *
378
572
  * - `unknown` — no audience denominator, so no honest statement about "all
379
573
  * recipients" can be made.
@@ -384,13 +578,13 @@ export interface NotifySendStatus {
384
578
  * - `partial` — every recipient resolved; some delivered, some did not.
385
579
  * - `failed` — every recipient resolved and none delivered.
386
580
  *
387
- * The list feeds it the send row's best-effort counters; this view recomputes
388
- * them from the authoritative per-recipient rows, so the list normally lags
389
- * rather than disagrees. A whole-audience RECALL is the exception: it stops the
390
- * fan-out where it stands, so the audience past that point never produces a row
391
- * or a counter — this view settles them `recalled`, while the list is left on
392
- * `sending` with counters nothing further will advance. This view is the one to
393
- * trust; for WHY a given recipient did not get it, read that recipient's `state`.
581
+ * A whole-audience recall resolves every recipient a channel had not already
582
+ * reached, so a recalled send reads `partial`, `failed` when nothing had been
583
+ * delivered, or `delivered` when every recipient already had been. The list
584
+ * feeds it the send's best-effort counters (and its `recalled_at`); this view
585
+ * recomputes them from the authoritative per-recipient rows. When the two
586
+ * differ, this view is the one to trust; for WHY a given recipient did not get
587
+ * it, read that recipient's `state`.
394
588
  */
395
589
  status: 'unknown' | 'pending' | 'sending' | 'delivered' | 'partial' | 'failed';
396
590
  channels: NotifyChannel[];
@@ -406,21 +600,30 @@ export interface NotifySendStatus {
406
600
  * write-once, so there is no stored lifecycle to read.
407
601
  *
408
602
  * `failed` counts every recipient who reached a terminal answer without being
409
- * delivered (declined, retries exhausted, opted out, rate limited, or a bounce
410
- * that repudiated a delivery), so `delivered + failed` is how many have
411
- * resolved; a recipient
412
- * still climbing the escalation ladder is in neither, which is why an in-flight
413
- * send reads `sending` rather than being scored early.
603
+ * delivered (declined, retries exhausted, opted out, rate limited, a bounce that
604
+ * repudiated a delivery, or a recall that ended their ladder), so
605
+ * `delivered + failed` is how many have resolved; a recipient still climbing
606
+ * the escalation ladder is in neither,
607
+ * which is why an in-flight send reads `sending` rather than being scored early.
608
+ * A whole-audience recall resolves every recipient a channel had not already
609
+ * reached, so a recalled send reads `partial` or `failed` (see `recalled_at`).
414
610
  *
415
- * `unknown` means the row predates the counters: the state is genuinely not
416
- * knowable, and is reported as such rather than guessed at.
611
+ * `unknown` means no statement about all of a send's recipients can be made:
612
+ * it carries no audience denominator (`recipient_count` null or 0), or its
613
+ * counters cannot be read (it is past its history horizon and its counters are
614
+ * already gone). The state is reported as not knowable rather than guessed at.
417
615
  */
418
616
  export type NotifySendState = 'unknown' | 'pending' | 'sending' | 'delivered' | 'partial' | 'failed';
419
617
  /**
420
618
  * One row of the account's send history. Metadata only: the audience is not
421
619
  * projected into the history index, so this shape cannot carry a recipient's
422
- * contact or the SparkLink pointer. Counters are `null` (never 0) on a send that
423
- * predates them — 0 delivered would report a failure that never happened.
620
+ * contact or the SparkLink pointer.
621
+ *
622
+ * A counter the send row does not carry is `null`, never an invented 0: each
623
+ * delivery counter is created by its first increment, so on a send with a
624
+ * `recipient_count` a null counter counts 0. An in-flight send reads
625
+ * `delivered_count: null` until its first delivery, and a send no recipient
626
+ * failed keeps `failed_count: null`.
424
627
  */
425
628
  export interface NotifySendSummary {
426
629
  send_id: string | null;
@@ -431,8 +634,13 @@ export interface NotifySendSummary {
431
634
  delivery: NotifyDeliveryMode | null;
432
635
  /** The sender name recipients saw. Display only — nothing routes on it. */
433
636
  display_sender_name: string | null;
434
- /** Audience size at accept — the denominator of the counters below. */
637
+ /**
638
+ * Audience size at accept — the denominator of the counters below. Null or 0
639
+ * only on a send that carries no audience count, which reads
640
+ * `state: 'unknown'`.
641
+ */
435
642
  recipient_count: number | null;
643
+ /** Recipients whose first delivery step was handed to delivery. */
436
644
  enqueued_count: number | null;
437
645
  /**
438
646
  * Recipients settled delivered, on the same evidence as the recipient
@@ -442,9 +650,21 @@ export interface NotifySendSummary {
442
650
  delivered_count: number | null;
443
651
  /**
444
652
  * Recipients who reached a terminal answer without being delivered: every
445
- * attempted channel declined or gave up, or they were suppressed or rate limited.
653
+ * attempted channel declined or gave up, they were suppressed or rate limited,
654
+ * or they were recalled before a channel reached them (counted when the next
655
+ * step of their ladder stops on the revoked grant).
446
656
  */
447
657
  failed_count: number | null;
658
+ /**
659
+ * Epoch seconds of a whole-audience recall; null when there was none (a
660
+ * targeted recall of named recipients never sets it: those recipients resolve
661
+ * through `failed_count`, and `getSendStatus` names them `recalled`). A
662
+ * recalled send settles: the remainder it withdrew counts as resolved without
663
+ * being delivered, so `state` reads `partial`, `failed` when nothing had been
664
+ * delivered, or `delivered` when every recipient already had been: this is
665
+ * what tells that recall apart from a delivery failure.
666
+ */
667
+ recalled_at: number | null;
448
668
  state: NotifySendState;
449
669
  }
450
670
  export interface ListNotifySendsOptions {
@@ -462,7 +682,9 @@ export interface ListNotifySendsResponse {
462
682
  * - `grant` (default): revoke the access grant; the content survives.
463
683
  * - `content`: hard-burn the sealed spark so the content is unreadable for
464
684
  * everyone, then drop the grant. Spark-backed sends only — an ingot send
465
- * references the owner's durable vault content and can only be grant-recalled.
685
+ * references the owner's durable vault content and can only be grant-recalled:
686
+ * a `content` recall of one is a 400, refused before anything is revoked or
687
+ * stopped.
466
688
  */
467
689
  export type NotifyRecallMode = 'grant' | 'content';
468
690
  export interface RecallNotifySendOptions {
@@ -482,6 +704,12 @@ export interface RecallNotifySendResponse {
482
704
  failed: number;
483
705
  /** Requested recipient ids that are not on this send's audience. */
484
706
  not_found: string[];
707
+ /**
708
+ * One entry per recipient whose recall failed (the rest still ran). `error`
709
+ * is the code the API answers that failure with on its own: a refusal's code
710
+ * (such as `VALIDATION_ERROR`), else `INTERNAL_ERROR` or a public server
711
+ * error code (such as `CRYPTOGRAPHIC_ERROR`); never the error's text.
712
+ */
485
713
  failures: Array<{
486
714
  recipient_id: string;
487
715
  error: string;
@@ -490,9 +718,20 @@ export interface RecallNotifySendResponse {
490
718
  /** The five verified-interaction receipt subtypes (SparkLink lifecycle events are not receipts). */
491
719
  export type NotifyReceiptEventType = 'sparklink_accessed' | 'sparklink_signed' | 'sparklink_approved' | 'sparklink_denied' | 'sparklink_replied';
492
720
  /**
493
- * A portable, JWKS-verifiable proof of a verified interaction. `signed_token` is
494
- * the Identity-signed EdDSA token; `action_hash` binds it to the approved/signed
495
- * action. `link_code` is masked (`abc123***`) exactly as stored.
721
+ * Every verification level a receipt can report: the levels a send may ask for,
722
+ * and `out_of_band` and `dual_control`, which no send can ask for but a stored
723
+ * grant may name, and is enforced at.
724
+ */
725
+ export type NotifyReportableVerificationLevel = NotifyVerificationLevel | 'out_of_band' | 'dual_control';
726
+ /**
727
+ * The receipt of a verified interaction. A ceremony's (acknowledge, sign,
728
+ * approve, reply) is portable proof: `signed_token` is the Identity-signed
729
+ * EdDSA token a third party verifies against the tenant's JWKS, and
730
+ * `action_hash` binds it to the action an approve or a sign answered. An
731
+ * open's (`sparklink_accessed`) is an unsigned access record: its
732
+ * `signed_token` is null. An acknowledge records `sparklink_signed`, as a sign
733
+ * does; `interaction` tells them apart. `link_code` is masked (`abc123***`)
734
+ * exactly as stored.
496
735
  */
497
736
  export interface NotifyReceipt {
498
737
  event_type: NotifyReceiptEventType | null;
@@ -503,22 +742,25 @@ export interface NotifyReceipt {
503
742
  vault_id: string | null;
504
743
  link_code: string | null;
505
744
  /**
506
- * The correlation key a `receipt.recorded` webhook event quotes: 32 hex of the
507
- * SHA-256 over the grant code, never the code itself. Null on a receipt
508
- * recorded before the key existed.
745
+ * The correlation key the interaction events quote (`notify.signed`,
746
+ * `notify.approved`, `notify.denied`, `notify.replied`): 32 hex of the SHA-256
747
+ * over the grant code, never the code itself. Match an event to its receipt on
748
+ * this, never on `link_code`. Null on a receipt stored without one, which only
749
+ * its `link_code` names.
509
750
  */
510
751
  link_code_hash: string | null;
511
752
  link_type: string | null;
512
- verification_level: NotifyVerificationLevel | null;
753
+ verification_level: NotifyReportableVerificationLevel | null;
513
754
  action_hash: string | null;
514
755
  signed_token: string | null;
515
756
  decision: string | null;
516
757
  thread_id: string | null;
517
758
  reply_spark_id: string | null;
518
759
  /**
519
- * The send whose grant produced this receipt, stamped at mint time — so it is
520
- * present for grants a Notify send created, and null for a standalone
521
- * SparkLink.
760
+ * The send whose grant produced this receipt, stamped at mint time: present on
761
+ * a `listReceipts` receipt of a grant a Notify send created, and null for a
762
+ * standalone SparkLink. Null on every `getSendReceipts` row, which is read from
763
+ * the audit rows; the send there is the one you asked for.
522
764
  */
523
765
  send_id: string | null;
524
766
  /** The send's display title, alongside `send_id` and under the same conditions. */
@@ -551,16 +793,14 @@ export interface NotifySendReceiptsResponse {
551
793
  send_id: string;
552
794
  receipts: NotifySendReceipt[];
553
795
  /**
554
- * True when the bounded correlation scan ended with grants still unmatched — the
555
- * result is bounded, not authoritative-complete. Absent on servers that do not
556
- * report it.
557
- */
558
- truncated?: boolean;
559
- /**
560
- * Continuation cursor for the correlation scan when it was truncated; null or
561
- * absent when the scan completed.
796
+ * True when the call's page cap stopped the walk before it reached the send's
797
+ * creation, so more receipts of this send may follow: re-call with `cursor`.
798
+ * False means `receipts` is the send's whole set — no receipt of a send
799
+ * predates it, so the walk never reads further back.
562
800
  */
563
- cursor?: string | null;
801
+ truncated: boolean;
802
+ /** Where the next call resumes a truncated walk; null when it is complete. */
803
+ cursor: string | null;
564
804
  }
565
805
  /** One notification topic. `required: true` is the compliance floor — unmutable by the recipient. */
566
806
  export interface NotifyConfigCategory {
@@ -570,11 +810,9 @@ export interface NotifyConfigCategory {
570
810
  description?: string;
571
811
  required?: boolean;
572
812
  }
573
- /** Each value is an integer number of minutes from send time, 0..1440 (24 hours). */
813
+ /** When the email step goes, in whole minutes from send time, 0..1440 (24 hours). */
574
814
  export interface NotifyConfigRealtimeFallbackDelay {
575
815
  email_minutes?: number;
576
- sms_minutes?: number;
577
- voice_minutes?: number;
578
816
  }
579
817
  export interface NotifyConfigDelivery {
580
818
  default_channels?: NotifyChannel[];
@@ -583,15 +821,34 @@ export interface NotifyConfigDelivery {
583
821
  realtime_fallback_delay?: NotifyConfigRealtimeFallbackDelay;
584
822
  escalation_enabled?: boolean;
585
823
  }
824
+ /**
825
+ * `delivery` as a patch writes it. Its ladders name an organization's own two
826
+ * channels, `in_app` and `email` (see `NotifyChannel`): any other is refused
827
+ * 403, `serviceCode` `NOTIFY_CHANNEL_NOT_AVAILABLE`, `details.field` naming the
828
+ * ladder's field (and `details.category` the category, for a category's ladder
829
+ * in `channel_priority`), and nothing is stored.
830
+ */
831
+ export interface NotifyConfigDeliveryPatch extends Omit<NotifyConfigDelivery, 'channel_priority'> {
832
+ /**
833
+ * Per-category channel order. Each ladder names at least one channel, each at
834
+ * most once; a NEW key must name a category a send can carry (one of the
835
+ * account's, one the same patch creates, or a preset category). `null` removes
836
+ * that category's ladder. At most 50 ladders.
837
+ */
838
+ channel_priority?: Record<string, NotifyChannel[] | null>;
839
+ }
586
840
  export interface NotifyConfigReliability {
587
841
  /**
588
- * Per `(account, recipient)` minute bucket, 1-600. An abuse/bug backstop the
589
- * tenant cannot switch off — 0 is rejected.
842
+ * Notifications per recipient per minute, 1-600, counted per person: a
843
+ * recipient counts against its own id and each email or phone it names. An
844
+ * abuse/bug backstop the tenant cannot switch off — 0 is rejected.
590
845
  */
591
846
  rate_limit_per_recipient_per_minute?: number;
592
847
  }
593
848
  export interface NotifyConfigHistory {
849
+ /** Inbox-row retention in whole days, 1 to 3650 (default 30). */
594
850
  history_ttl_days?: number;
851
+ /** Receipt retention in whole days, 1 to 3650 (default 365). */
595
852
  receipt_retention_days?: number;
596
853
  }
597
854
  export interface NotifyConfigSecurity {
@@ -606,8 +863,12 @@ export interface NotifyConfigSecurity {
606
863
  mandatory_seal_categories?: string[];
607
864
  }
608
865
  /**
609
- * The account's outbound EVENT webhook — how a backend learns that a recipient
610
- * opened, signed, approved, denied, or replied without polling for it.
866
+ * The account's outbound EVENT webhook — how a backend learns, without polling
867
+ * for it, that a recipient signed, approved, denied, or replied
868
+ * (`notify.signed`, `notify.approved`, `notify.denied`, `notify.replied`), and
869
+ * how delivery to each recipient turned out (`notify.delivered`,
870
+ * `notify.failed`, `notify.bounced`). Opening a notification emits no event:
871
+ * read view receipts with `listReceipts`.
611
872
  *
612
873
  * Both fields are required before anything is sent: an unsigned event is not
613
874
  * offered. `webhook_url` must be https on a public host (loopback, private,
@@ -641,6 +902,15 @@ export interface NotifyConfig {
641
902
  security: NotifyConfigSecurity;
642
903
  /** Absent until the account configures an event webhook. */
643
904
  events?: NotifyConfigEventsRead;
905
+ /**
906
+ * Who the organization's Notify email is from. `sending_domain` is the
907
+ * organization's own domain its email is selected to go out from (as
908
+ * `notify@{domain}`), or null for its handle under send.sv; `getEmailSender`
909
+ * says whether it serves now.
910
+ */
911
+ email: {
912
+ sending_domain: string | null;
913
+ };
644
914
  /** Tombstoned entries are already dropped — a deleted category is simply gone. */
645
915
  categories: Record<string, NotifyConfigCategory>;
646
916
  }
@@ -648,22 +918,37 @@ export interface NotifyConfig {
648
918
  * A partial PATCH of the account's config overrides. Only the sections present are
649
919
  * touched, and every field is validated server-side before any write.
650
920
  *
651
- * `categories.<key>: null` is a DELETE TOMBSTONE — it is what keeps a seeded
652
- * default (say `marketing`) from re-appearing on the next merge. Storing a normal
653
- * object under the same key later re-creates it. The reserved `security` category
654
- * can neither be removed nor made optional.
921
+ * `categories.<key>: null` DELETES a category. A seeded default's delete (say
922
+ * `marketing`) is stored as a tombstone, which keeps the default from
923
+ * re-appearing on the next merge; any other delete leaves no entry. Storing a
924
+ * normal object under the same key later re-creates it. The reserved `security`
925
+ * category can neither be removed nor made optional.
655
926
  */
656
927
  export interface NotifyConfigPatch {
657
- delivery?: NotifyConfigDelivery;
928
+ delivery?: NotifyConfigDeliveryPatch;
658
929
  reliability?: NotifyConfigReliability;
659
930
  history?: NotifyConfigHistory;
931
+ /** Admin only. */
660
932
  security?: NotifyConfigSecurity;
933
+ /** Admin only. */
661
934
  events?: NotifyConfigEvents;
935
+ /**
936
+ * Admin only. `sending_domain`: one of the organization's own domains, its
937
+ * ownership verified and its email sending ready, to send from as
938
+ * `notify@{domain}`; null sends from the organization's handle,
939
+ * `notify@{handle}.send.sv`. A domain the organization does not hold is
940
+ * refused 404, one not ready for Notify 409 `DOMAIN_NOT_READY`
941
+ * (`details: { domain, product: 'notify' }`), and a change past the
942
+ * organization's hourly sending-domain selections 429.
943
+ */
944
+ email?: {
945
+ sending_domain?: string | null;
946
+ };
662
947
  categories?: Record<string, NotifyConfigCategory | null>;
663
948
  }
664
949
  /**
665
- * The stored override delta, tombstones included, because that is what a write
666
- * merges onto. One value is held back: `events.secret` comes back as
950
+ * The stored override delta, seeded-category tombstones included, because that is
951
+ * what a write merges onto. One value is held back: `events.secret` comes back as
667
952
  * `secret_set`, never the secret — a patch never has to resend it.
668
953
  */
669
954
  export type NotifyConfigOverrides = Omit<NotifyConfigPatch, 'events'> & {