@sparkvault/sdk-js 8.15.0 → 9.0.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.
@@ -29,4 +29,4 @@ export { NotifyProductModule, NOTIFY_PRESETS, buildNotifyPresetSend } from './no
29
29
  export type { VerifyOptions, AttachOptions, VerifyResult, TokenClaims, AuthMethod, AuthContext, Theme, SdkConfig, SdkConfigBranding, MethodId, MethodMetadata, } from './identity';
30
30
  export { METHOD_REGISTRY, getMethodMetadata, enrichMethods } from './identity';
31
31
  export { IdentityApi, IdentityApiError } from './identity';
32
- export type { NotifyChannel, NotifyDeliveryMode, NotifyVerificationLevel, NotifyInteraction, NotifyPresetCategory, NotifyCategory, NotifyPresetName, NotifyPreset, NotifyRecipient, NotifyRecipientRef, NotifySendContent, NotifyIngotRef, NotifySendPolicy, NotifyEscalation, CreateNotifySendOptions, NotifySendResult, NotifyInboxView, NotifyInboxMarkState, NotifyInboxBulkMarkState, NotifyInboxRow, ListNotifyInboxOptions, ListNotifyInboxResponse, MarkNotifyInboxStateOptions, MarkNotifyInboxStateResponse, MarkNotifyInboxAllOptions, MarkNotifyInboxAllResponse, NotifySendStatus, NotifySendStatusRecipient, NotifySendStatusCounts, NotifyReceipt, NotifyReceiptEventType, NotifySendReceipt, ListNotifyReceiptsOptions, ListNotifyReceiptsResponse, NotifySendReceiptsResponse, NotifyConfig, NotifyConfigCategory, NotifyConfigDelivery, NotifyConfigRealtimeFallbackDelay, NotifyConfigReliability, NotifyConfigHistory, NotifyConfigSecurity, NotifyConfigPatch, NotifyConfigOverrides, NotifyConfigResponse, } from './notify';
32
+ export type { NotifyChannel, NotifyDeliveryMode, NotifyVerificationLevel, NotifyInteraction, NotifyPresetCategory, NotifyCategory, NotifyPresetName, NotifyPreset, NotifyRecipient, NotifyRecipientRef, NotifySendContent, NotifyIngotRef, NotifySendPolicy, NotifyEscalation, CreateNotifySendOptions, NotifySendResult, NotifyInboxView, NotifyInboxMarkState, NotifyInboxBulkMarkState, NotifyInboxRow, ListNotifyInboxOptions, ListNotifyInboxResponse, MarkNotifyInboxStateOptions, MarkNotifyInboxStateResponse, MarkNotifyInboxAllOptions, MarkNotifyInboxAllResponse, NotifySendStatus, NotifySendStatusRecipient, NotifySendStatusCounts, NotifySendState, NotifySendSummary, ListNotifySendsOptions, ListNotifySendsResponse, NotifyRecallMode, RecallNotifySendOptions, RecallNotifySendResponse, NotifyReceipt, NotifyReceiptEventType, NotifyReceiptSource, NotifySendReceipt, ListNotifyReceiptsOptions, ListNotifyReceiptsResponse, NotifySendReceiptsResponse, NotifyConfig, NotifyConfigCategory, NotifyConfigDelivery, NotifyConfigRealtimeFallbackDelay, NotifyConfigReliability, NotifyConfigHistory, NotifyConfigSecurity, NotifyConfigEvents, NotifyConfigEventsRead, NotifyConfigPatch, NotifyConfigOverrides, NotifyConfigResponse, } from './notify';
@@ -3,8 +3,9 @@
3
3
  *
4
4
  * The counterpart to `sv.notify`: where that module is session-scoped and reads
5
5
  * only the signed-in person's OWN inbox, this one is the account-scoped product
6
- * surface a tenant's BACKEND drives — send, sender-side inbox reads and state,
7
- * send status, receipts, and the account's Notify config. Every method maps to
6
+ * surface a tenant's BACKEND drives — send, send history, recall, sender-side
7
+ * inbox reads and state, send status, receipts, and the account's Notify config.
8
+ * Every method maps to
8
9
  * `/v1/products/notify/*` and is authorized by the caller's account, so the
9
10
  * recipient is supplied explicitly rather than derived from a session.
10
11
  *
@@ -17,7 +18,7 @@
17
18
  * and metadata.
18
19
  */
19
20
  import { HttpClient } from '../../http';
20
- import type { CreateNotifySendOptions, NotifySendResult, NotifyPreset, NotifyPresetName, ListNotifyInboxOptions, ListNotifyInboxResponse, MarkNotifyInboxStateOptions, MarkNotifyInboxStateResponse, MarkNotifyInboxAllOptions, MarkNotifyInboxAllResponse, NotifySendStatus, ListNotifyReceiptsOptions, ListNotifyReceiptsResponse, NotifySendReceiptsResponse, NotifyConfigPatch, NotifyConfigResponse } from './types';
21
+ import type { CreateNotifySendOptions, NotifySendResult, NotifyPreset, NotifyPresetName, ListNotifyInboxOptions, ListNotifyInboxResponse, MarkNotifyInboxStateOptions, MarkNotifyInboxStateResponse, MarkNotifyInboxAllOptions, MarkNotifyInboxAllResponse, NotifySendStatus, ListNotifySendsOptions, ListNotifySendsResponse, RecallNotifySendOptions, RecallNotifySendResponse, ListNotifyReceiptsOptions, ListNotifyReceiptsResponse, NotifySendReceiptsResponse, NotifyConfigPatch, NotifyConfigResponse } from './types';
21
22
  /**
22
23
  * The five secure-by-default preset bundles, mirroring the server's table.
23
24
  *
@@ -74,9 +75,9 @@ export declare class NotifyProductModule {
74
75
  sendSecureMessage(options: CreateNotifySendOptions): Promise<NotifySendResult>;
75
76
  /** Two-way thread: identifier-verified reveal plus an encrypted reply. */
76
77
  sendConversation(options: CreateNotifySendOptions): Promise<NotifySendResult>;
77
- /** High-stakes approve/deny — passkey-verified, with `action_hash` binding. */
78
+ /** High-stakes approve/deny — identifier-verified, with `action_hash` binding. */
78
79
  sendApproval(options: CreateNotifySendOptions): Promise<NotifySendResult>;
79
- /** Signature-on-delivery — passkey-verified, with `action_hash` binding. */
80
+ /** Signature-on-delivery — identifier-verified, with `action_hash` binding. */
80
81
  sendSignatureRequest(options: CreateNotifySendOptions): Promise<NotifySendResult>;
81
82
  /**
82
83
  * Read one recipient's metadata-only feed, newest first. Rows are pointers: a
@@ -119,6 +120,56 @@ export declare class NotifyProductModule {
119
120
  * } while (cursor);
120
121
  */
121
122
  markInboxAll(options: MarkNotifyInboxAllOptions): Promise<MarkNotifyInboxAllResponse>;
123
+ /**
124
+ * The account's send history, newest first — what you sent, to how many, and
125
+ * how it landed.
126
+ *
127
+ * Metadata only by construction: the history index does not project the
128
+ * audience, so no recipient contact or SparkLink pointer can travel here. Take
129
+ * `getSendStatus(sendId)` for the per-recipient detail.
130
+ *
131
+ * Real pagination: a null `cursor` means the end of the account's history.
132
+ *
133
+ * @example
134
+ * let cursor: string | undefined;
135
+ * do {
136
+ * const page = await sv.products.notify.listSends({ cursor, limit: 50 });
137
+ * for (const send of page.sends) {
138
+ * console.log(send.created_at, send.title, send.state,
139
+ * `${send.delivered_count ?? '?'} / ${send.recipient_count ?? '?'}`);
140
+ * }
141
+ * cursor = page.cursor ?? undefined;
142
+ * } while (cursor);
143
+ */
144
+ listSends(options?: ListNotifySendsOptions): Promise<ListNotifySendsResponse>;
145
+ /**
146
+ * Recall a sealed send: revoke the single-use SparkLink grants it minted, so
147
+ * the content can no longer be revealed.
148
+ *
149
+ * `mode: 'grant'` (the default) drops access and leaves the content intact.
150
+ * `mode: 'content'` hard-burns the sealed spark so it is unreadable for
151
+ * everyone — spark-backed sends only, since an ingot send merely references the
152
+ * owner's durable vault content.
153
+ *
154
+ * Idempotent: a grant already revoked (or already consumed) counts as recalled,
155
+ * so a repeated call converges rather than accumulating failures. One
156
+ * recipient's failure never stops the rest — the response reports every one.
157
+ *
158
+ * PLAINTEXT SENDS CANNOT BE RECALLED (400): they delivered their body inline,
159
+ * in the clear, and minted no grant. There is nothing to revoke, and saying
160
+ * otherwise would be a lie about the one thing you are asking.
161
+ *
162
+ * @example
163
+ * // Whole audience, access only
164
+ * await sv.products.notify.recallSend(send.send_id);
165
+ *
166
+ * // One recipient, burn the content for everyone
167
+ * const { recalled, failed } = await sv.products.notify.recallSend(send.send_id, {
168
+ * recipientIds: [user.svid],
169
+ * mode: 'content',
170
+ * });
171
+ */
172
+ recallSend(sendId: string, options?: RecallNotifySendOptions): Promise<RecallNotifySendResponse>;
122
173
  /**
123
174
  * The sender's per-recipient delivery rollup for one send: who it reached and
124
175
  * how far each recipient got. Metadata only — never the pointer or contacts.
@@ -131,13 +182,14 @@ export declare class NotifyProductModule {
131
182
  * The account's verified-interaction receipts (portable, JWKS-verifiable
132
183
  * proofs), newest first. Follow `cursor` to page.
133
184
  *
134
- * A page can come back SHORT of `limit` — even EMPTY — yet still carry a
135
- * non-null cursor: the receipt-subtype and `interaction` filters are applied
136
- * after the key query, so a page of non-matching rows yields no receipts and a
137
- * live cursor. Follow the cursor; never treat a short or empty page as the end.
185
+ * `source` says which store answered. `receipt_index` is the normal path — a
186
+ * bounded query with real pagination. `legacy_scan` appears only for an account
187
+ * whose receipts all predate that index; it filters the account audit log, so
188
+ * it can hand back EMPTY pages that are nowhere near the end. On EITHER source,
189
+ * follow the cursor until it is null before concluding there are none.
138
190
  *
139
191
  * @example
140
- * const { receipts, cursor } = await sv.products.notify.listReceipts({ interaction: 'approve' });
192
+ * const { receipts, cursor, source } = await sv.products.notify.listReceipts({ interaction: 'approve' });
141
193
  */
142
194
  listReceipts(options?: ListNotifyReceiptsOptions): Promise<ListNotifyReceiptsResponse>;
143
195
  /**
@@ -175,14 +227,23 @@ export declare class NotifyProductModule {
175
227
  * a seeded default from re-appearing on the next merge. The reserved `security`
176
228
  * category can neither be removed nor made optional.
177
229
  *
230
+ * The `events` section configures the outbound event webhook: `webhook_url`
231
+ * must be https on a public host, and `secret` (16-256 chars) signs every event
232
+ * body as `X-SparkVault-Signature: hex(HMAC-SHA256(secret, rawBody))`. The
233
+ * secret is WRITE-ONLY — reads report `events.secret_set`, never the value.
234
+ *
178
235
  * @example
179
236
  * await sv.products.notify.updateConfig({
180
237
  * categories: {
181
238
  * weekly_newsletter: { label: 'Weekly newsletter', required: false },
182
239
  * marketing: null, // tombstone — remove the seeded default
183
240
  * },
241
+ * events: {
242
+ * webhook_url: 'https://api.example.com/hooks/sparkvault',
243
+ * secret: process.env.SPARKVAULT_EVENT_SECRET,
244
+ * },
184
245
  * });
185
246
  */
186
247
  updateConfig(patch: NotifyConfigPatch): Promise<NotifyConfigResponse>;
187
248
  }
188
- export type { NotifyChannel, NotifyDeliveryMode, NotifyVerificationLevel, NotifyInteraction, NotifyPresetCategory, NotifyCategory, NotifyPresetName, NotifyPreset, NotifyRecipient, NotifyRecipientRef, NotifySendContent, NotifyIngotRef, NotifySendPolicy, NotifyEscalation, CreateNotifySendOptions, NotifySendResult, NotifyInboxView, NotifyInboxMarkState, NotifyInboxBulkMarkState, NotifyInboxRow, ListNotifyInboxOptions, ListNotifyInboxResponse, MarkNotifyInboxStateOptions, MarkNotifyInboxStateResponse, MarkNotifyInboxAllOptions, MarkNotifyInboxAllResponse, NotifySendStatus, NotifySendStatusRecipient, NotifySendStatusCounts, NotifyReceipt, NotifyReceiptEventType, NotifySendReceipt, ListNotifyReceiptsOptions, ListNotifyReceiptsResponse, NotifySendReceiptsResponse, NotifyConfig, NotifyConfigCategory, NotifyConfigDelivery, NotifyConfigRealtimeFallbackDelay, NotifyConfigReliability, NotifyConfigHistory, NotifyConfigSecurity, NotifyConfigPatch, NotifyConfigOverrides, NotifyConfigResponse, } from './types';
249
+ export type { NotifyChannel, NotifyDeliveryMode, NotifyVerificationLevel, NotifyInteraction, NotifyPresetCategory, NotifyCategory, NotifyPresetName, NotifyPreset, NotifyRecipient, NotifyRecipientRef, NotifySendContent, NotifyIngotRef, NotifySendPolicy, NotifyEscalation, CreateNotifySendOptions, NotifySendResult, NotifyInboxView, NotifyInboxMarkState, NotifyInboxBulkMarkState, NotifyInboxRow, ListNotifyInboxOptions, ListNotifyInboxResponse, MarkNotifyInboxStateOptions, MarkNotifyInboxStateResponse, MarkNotifyInboxAllOptions, MarkNotifyInboxAllResponse, NotifySendStatus, NotifySendStatusRecipient, NotifySendStatusCounts, NotifySendState, NotifySendSummary, ListNotifySendsOptions, ListNotifySendsResponse, NotifyRecallMode, RecallNotifySendOptions, RecallNotifySendResponse, NotifyReceipt, NotifyReceiptEventType, NotifyReceiptSource, NotifySendReceipt, ListNotifyReceiptsOptions, ListNotifyReceiptsResponse, NotifySendReceiptsResponse, NotifyConfig, NotifyConfigCategory, NotifyConfigDelivery, NotifyConfigRealtimeFallbackDelay, NotifyConfigReliability, NotifyConfigHistory, NotifyConfigSecurity, NotifyConfigEvents, NotifyConfigEventsRead, NotifyConfigPatch, NotifyConfigOverrides, NotifyConfigResponse, } from './types';
@@ -30,8 +30,20 @@ export type NotifyChannel = 'in_app' | 'websocket' | 'email' | 'sms' | 'push' |
30
30
  * allowed on a confidential category.
31
31
  */
32
32
  export type NotifyDeliveryMode = 'sealed' | 'plaintext';
33
- /** What a recipient must prove before the SparkLink reveals its content. */
34
- export type NotifyVerificationLevel = 'none' | 'identifier' | 'passkey' | 'out_of_band' | 'dual_control';
33
+ /**
34
+ * What a recipient must prove before the SparkLink reveals its content.
35
+ *
36
+ * Three levels, because three is what the Identity ceremony can achieve, and the
37
+ * bar is enforced on the method the recipient ACHIEVED — a passkey-level grant is
38
+ * never satisfied by an identifier session. A level the reveal cannot satisfy is
39
+ * not a stronger guarantee; it is a send nobody can open.
40
+ *
41
+ * `identifier` is the platform default for a sealed send: unset here, the
42
+ * account config's `security.verification_level` applies, and it ships as
43
+ * `identifier` rather than `none` because a sealed pointer under no verification
44
+ * is a bearer token.
45
+ */
46
+ export type NotifyVerificationLevel = 'none' | 'identifier' | 'passkey';
35
47
  /** What the recipient does at the reveal — the interaction the receipt attests to. */
36
48
  export type NotifyInteraction = 'view' | 'acknowledge' | 'sign' | 'approve' | 'reply';
37
49
  /**
@@ -118,7 +130,15 @@ export interface CreateNotifySendOptions {
118
130
  escalation?: NotifyEscalation;
119
131
  /** Channel-agnostic display title (rides the email subject). Truncated at 200 chars, never rejected. */
120
132
  title?: string;
121
- category?: NotifyCategory;
133
+ /**
134
+ * REQUIRED. The category this send is classified as — one of your configured
135
+ * `categories`, or a preset category. It decides the channel ladder, whether a
136
+ * recipient may mute it, and whether the mail carries an unsubscribe
137
+ * affordance, so the server rejects a send without one rather than guessing:
138
+ * defaulting an uncategorized send either way silently changes what the
139
+ * recipient consented to. The preset helpers stamp their own.
140
+ */
141
+ category: NotifyCategory;
122
142
  /** Free-form display type the tenant uses to classify the send. */
123
143
  type?: string;
124
144
  /**
@@ -198,13 +218,37 @@ export interface MarkNotifyInboxAllResponse {
198
218
  /** Next page, or null when the drain is complete. */
199
219
  cursor: string | null;
200
220
  }
221
+ /**
222
+ * The one answer for a recipient, derived from their row (never stored, so it
223
+ * cannot drift from the facts it summarizes).
224
+ *
225
+ * - `pending` — still in flight, or not yet driven.
226
+ * - `delivered` — a channel accepted it and no provider has repudiated that.
227
+ * - `undeliverable` — every channel attempted declined (no handle, bounced, not
228
+ * implemented). The recipient cannot be reached as addressed.
229
+ * - `failed` — a channel exhausted its retries. OUR transport gave up; the
230
+ * address may be perfectly good.
231
+ * - `suppressed` — the PERSON chose silence (site off, category muted, every
232
+ * offered channel opted out). Not a fault, and not something to route around.
233
+ * - `rate_limited` — skipped by the per-recipient abuse ceiling for that minute.
234
+ */
235
+ export type NotifyRecipientState = 'pending' | 'delivered' | 'undeliverable' | 'failed' | 'suppressed' | 'rate_limited';
201
236
  export interface NotifySendStatusRecipient {
202
237
  recipient_id: string;
238
+ /** The derived per-recipient state — the field to branch on. */
239
+ state: NotifyRecipientState;
203
240
  /** True once the recipient's first delivery step was enqueued. */
204
241
  enqueued: boolean;
205
242
  seen_at: number | null;
206
243
  read_at: number | null;
207
244
  archived_at: number | null;
245
+ /** When the recipient's own preference took them out of the ladder. */
246
+ suppressed_at: number | null;
247
+ /**
248
+ * When the per-recipient ceiling skipped them. Cleared if a later fan-out
249
+ * drives them, so it never outlives the skip it describes.
250
+ */
251
+ rate_limited_at: number | null;
208
252
  /**
209
253
  * The latest dispatch outcome per attempted channel — the difference between a
210
254
  * notification that actually left the building and one whose every channel
@@ -213,7 +257,15 @@ export interface NotifySendStatusRecipient {
213
257
  * (and with it the recipient's raw contact), which this rollup never exposes.
214
258
  */
215
259
  channel_outcomes: Partial<Record<NotifyChannel, {
216
- outcome: 'delivered' | 'skipped' | 'not_implemented' | 'retryable';
260
+ outcome: 'delivered' | 'skipped' | 'not_implemented' | 'retryable'
261
+ /** The step exhausted its retries — terminal, unlike `retryable`. */
262
+ | 'failed'
263
+ /**
264
+ * The provider repudiated a delivery it had accepted. It REPLACES the
265
+ * channel's `delivered` entry: handing a message to SES was never
266
+ * proof it reached a mailbox.
267
+ */
268
+ | 'bounced';
217
269
  /** Epoch seconds the outcome was recorded. */
218
270
  at: number | null;
219
271
  /** Escalation step index the outcome came from. */
@@ -222,12 +274,18 @@ export interface NotifySendStatusRecipient {
222
274
  /** At least one channel accepted the notification for this recipient. */
223
275
  delivered: boolean;
224
276
  /**
225
- * Every channel attempted for this recipient declined (`skipped` /
226
- * `not_implemented`) and none delivered — a silent non-delivery. False while
227
- * nothing has been attempted yet and while a `retryable` attempt is still in
228
- * flight.
277
+ * Every channel attempted for this recipient declined (`skipped`,
278
+ * `not_implemented`, or `bounced`) and none delivered — a silent
279
+ * non-delivery. False while nothing has been attempted yet and while a
280
+ * `retryable` attempt is still in flight.
229
281
  */
230
282
  undeliverable: boolean;
283
+ /**
284
+ * Every attempt is terminal, nothing delivered, and at least one channel
285
+ * exhausted its retries. Distinct from `undeliverable`: this one is a
286
+ * transport problem on our side, not an address that cannot receive.
287
+ */
288
+ failed: boolean;
231
289
  }
232
290
  export interface NotifySendStatusCounts {
233
291
  total: number;
@@ -235,10 +293,23 @@ export interface NotifySendStatusCounts {
235
293
  seen: number;
236
294
  read: number;
237
295
  archived: number;
296
+ /**
297
+ * The six state counters below PARTITION the audience:
298
+ * `pending + delivered + undeliverable + failed + suppressed + rate_limited === total`.
299
+ * (`enqueued` / `seen` / `read` / `archived` are independent progress markers
300
+ * and do not partition anything.)
301
+ */
302
+ pending: number;
238
303
  /** Recipients with at least one `delivered` channel outcome. */
239
304
  delivered: number;
240
305
  /** Recipients whose every attempted channel declined — the silent-failure count. */
241
306
  undeliverable: number;
307
+ /** Recipients whose ladder ended with a channel that exhausted its retries. */
308
+ failed: number;
309
+ /** Recipients who opted out. Never a failure. */
310
+ suppressed: number;
311
+ /** Recipients skipped by the per-recipient ceiling. */
312
+ rate_limited: number;
242
313
  }
243
314
  /**
244
315
  * The sender's per-recipient delivery rollup. Metadata only by construction: it
@@ -247,7 +318,24 @@ export interface NotifySendStatusCounts {
247
318
  */
248
319
  export interface NotifySendStatus {
249
320
  send_id: string;
250
- status: string;
321
+ /**
322
+ * DERIVED, never stored — and by the SAME function the send-history list uses,
323
+ * so a send cannot read one way in the list and another here.
324
+ *
325
+ * - `unknown` — no audience denominator, so no honest statement about "all
326
+ * recipients" can be made.
327
+ * - `pending` — accepted; nothing handed to delivery yet.
328
+ * - `sending` — in flight.
329
+ * - `delivered` — every recipient reached a channel that accepted.
330
+ * - `partial` — every recipient resolved; some delivered, some did not.
331
+ * - `failed` — every recipient resolved and none delivered.
332
+ *
333
+ * The list feeds it the send row's best-effort counters; this view recomputes
334
+ * them from the authoritative per-recipient rows, so the list can lag but the
335
+ * two can never contradict. For WHY a given recipient did not get it, read
336
+ * that recipient's `state`.
337
+ */
338
+ status: 'unknown' | 'pending' | 'sending' | 'delivered' | 'partial' | 'failed';
251
339
  channels: NotifyChannel[];
252
340
  created_at: number;
253
341
  title: string | null;
@@ -256,6 +344,82 @@ export interface NotifySendStatus {
256
344
  recipients: NotifySendStatusRecipient[];
257
345
  counts: NotifySendStatusCounts;
258
346
  }
347
+ /**
348
+ * A send's delivery state, DERIVED from its counters — the send row itself is
349
+ * write-once, so there is no stored lifecycle to read.
350
+ *
351
+ * `failed` counts recipients whose every attempted channel declined, so
352
+ * `delivered + failed` is how many have reached a terminal answer; a recipient
353
+ * still climbing the escalation ladder is in neither, which is why an in-flight
354
+ * send reads `sending` rather than being scored early.
355
+ *
356
+ * `unknown` means the row predates the counters: the state is genuinely not
357
+ * knowable, and is reported as such rather than guessed at.
358
+ */
359
+ export type NotifySendState = 'unknown' | 'pending' | 'sending' | 'delivered' | 'partial' | 'failed';
360
+ /**
361
+ * One row of the account's send history. Metadata only: the audience is not
362
+ * projected into the history index, so this shape cannot carry a recipient's
363
+ * contact or the SparkLink pointer. Counters are `null` (never 0) on a send that
364
+ * predates them — 0 delivered would report a failure that never happened.
365
+ */
366
+ export interface NotifySendSummary {
367
+ send_id: string | null;
368
+ /** Epoch seconds. */
369
+ created_at: number | null;
370
+ title: string | null;
371
+ category: string | null;
372
+ delivery: NotifyDeliveryMode | null;
373
+ /** The sender name recipients saw. Display only — nothing routes on it. */
374
+ display_sender_name: string | null;
375
+ /** Audience size at accept — the denominator of the counters below. */
376
+ recipient_count: number | null;
377
+ enqueued_count: number | null;
378
+ delivered_count: number | null;
379
+ /** Recipients whose every attempted channel declined. */
380
+ failed_count: number | null;
381
+ state: NotifySendState;
382
+ }
383
+ export interface ListNotifySendsOptions {
384
+ /** Page size, 1-100 (server default 50). */
385
+ limit?: number;
386
+ cursor?: string;
387
+ }
388
+ export interface ListNotifySendsResponse {
389
+ sends: NotifySendSummary[];
390
+ /** Next-page cursor, or null on the last page. This is a real key query: a full page means more may follow, a null cursor means the end. */
391
+ cursor: string | null;
392
+ }
393
+ /**
394
+ * Recall depth.
395
+ * - `grant` (default): revoke the access grant; the content survives.
396
+ * - `content`: hard-burn the sealed spark so the content is unreadable for
397
+ * everyone, then drop the grant. Spark-backed sends only — an ingot send
398
+ * references the owner's durable vault content and can only be grant-recalled.
399
+ */
400
+ export type NotifyRecallMode = 'grant' | 'content';
401
+ export interface RecallNotifySendOptions {
402
+ /**
403
+ * Recall only these recipients. OMIT to recall the whole audience — an empty
404
+ * array is rejected rather than guessed at, because "nobody" and "everybody"
405
+ * are both plausible readings of it on a destructive call.
406
+ */
407
+ recipientIds?: string[];
408
+ mode?: NotifyRecallMode;
409
+ }
410
+ export interface RecallNotifySendResponse {
411
+ send_id: string;
412
+ mode: NotifyRecallMode;
413
+ /** Grants revoked. An already-revoked grant counts here — recall is idempotent. */
414
+ recalled: number;
415
+ failed: number;
416
+ /** Requested recipient ids that are not on this send's audience. */
417
+ not_found: string[];
418
+ failures: Array<{
419
+ recipient_id: string;
420
+ error: string;
421
+ }>;
422
+ }
259
423
  /** The five verified-interaction receipt subtypes (SparkLink lifecycle events are not receipts). */
260
424
  export type NotifyReceiptEventType = 'sparklink_accessed' | 'sparklink_signed' | 'sparklink_approved' | 'sparklink_denied' | 'sparklink_replied';
261
425
  /**
@@ -264,7 +428,7 @@ export type NotifyReceiptEventType = 'sparklink_accessed' | 'sparklink_signed' |
264
428
  * action. `link_code` is masked (`abc123***`) exactly as stored.
265
429
  */
266
430
  export interface NotifyReceipt {
267
- event_type: NotifyReceiptEventType;
431
+ event_type: NotifyReceiptEventType | null;
268
432
  occurred_at: number | null;
269
433
  interaction: NotifyInteraction | null;
270
434
  identity: string | null;
@@ -278,7 +442,19 @@ export interface NotifyReceipt {
278
442
  decision: string | null;
279
443
  thread_id: string | null;
280
444
  reply_spark_id: string | null;
445
+ /**
446
+ * The send whose grant produced this receipt, stamped at mint time — so it is
447
+ * present for grants a Notify send created, and null for a standalone
448
+ * SparkLink or a receipt served from the legacy audit walk.
449
+ */
450
+ send_id: string | null;
451
+ /** The send's display title, alongside `send_id` and under the same conditions. */
452
+ title: string | null;
453
+ /** The receipt row's own id. Null on the legacy source. */
454
+ receipt_id: string | null;
281
455
  }
456
+ /** Which store answered a receipts listing (see `ListNotifyReceiptsResponse.source`). */
457
+ export type NotifyReceiptSource = 'receipt_index' | 'legacy_scan';
282
458
  /** A receipt correlated to the recipient whose grant produced it. */
283
459
  export interface NotifySendReceipt extends NotifyReceipt {
284
460
  recipient_id: string;
@@ -293,12 +469,26 @@ export interface ListNotifyReceiptsOptions {
293
469
  export interface ListNotifyReceiptsResponse {
294
470
  receipts: NotifyReceipt[];
295
471
  /**
296
- * Next-page cursor, or null on the last page. A page can be SHORT of `limit` —
297
- * even EMPTY — yet still carry a non-null cursor (the receipt-subtype and
298
- * `interaction` filters are applied after the key query) — follow the cursor;
299
- * never treat a short or empty page as the end.
472
+ * Next-page cursor, or null on the last page. A page can still come back SHORT
473
+ * of `limit` while more rows follow — `interaction` narrows with a DynamoDB
474
+ * filter applied after the key evaluation — so follow the cursor; never treat
475
+ * a short page as the end.
300
476
  */
301
477
  cursor: string | null;
478
+ /**
479
+ * Which store answered.
480
+ *
481
+ * `receipt_index` is the normal path: one bounded query on the account's
482
+ * receipt partition, with real pagination.
483
+ *
484
+ * `legacy_scan` appears only for an account whose receipts were all emitted
485
+ * before the receipt index existed. It walks the account audit log with a
486
+ * filter, so it can return EMPTY pages that are nowhere near the end of the
487
+ * data — on that source, keep following the cursor until it is null before
488
+ * concluding there are no receipts. The two sources are never merged into one
489
+ * page; the cursor stays on whichever source started the walk.
490
+ */
491
+ source: NotifyReceiptSource;
302
492
  }
303
493
  export interface NotifySendReceiptsResponse {
304
494
  send_id: string;
@@ -357,12 +547,42 @@ export interface NotifyConfigSecurity {
357
547
  */
358
548
  mandatory_seal_categories?: string[];
359
549
  }
550
+ /**
551
+ * The account's outbound EVENT webhook — how a backend learns that a recipient
552
+ * opened, signed, approved, denied, or replied without polling for it.
553
+ *
554
+ * Both fields are required before anything is sent: an unsigned event is not
555
+ * offered. `webhook_url` must be https on a public host (loopback, private,
556
+ * link-local, and CGNAT addresses are rejected server-side).
557
+ *
558
+ * Delivery is BEST EFFORT — one retry, then the event is dropped. Polling
559
+ * (`listSends`, `getSendStatus`, `listReceipts`) remains the source of truth;
560
+ * the webhook exists to make that poll rare, not to replace it.
561
+ */
562
+ export interface NotifyConfigEvents {
563
+ /** https only, ≤2048 chars. */
564
+ webhook_url?: string;
565
+ /**
566
+ * HMAC-SHA256 signing secret, 16-256 chars. Sent as the hex digest of the raw
567
+ * body in `X-SparkVault-Signature`. WRITE-ONLY: a config read reports
568
+ * `secret_set` instead of the value.
569
+ */
570
+ secret?: string;
571
+ }
572
+ /** `events` as it comes BACK from a read — the secret is never echoed. */
573
+ export interface NotifyConfigEventsRead {
574
+ webhook_url?: string;
575
+ /** Whether a signing secret is stored. The secret itself is never returned. */
576
+ secret_set?: boolean;
577
+ }
360
578
  /** The account's effective config: secure defaults deep-merged with its overrides. */
361
579
  export interface NotifyConfig {
362
580
  delivery: NotifyConfigDelivery;
363
581
  reliability: NotifyConfigReliability;
364
582
  history: NotifyConfigHistory;
365
583
  security: NotifyConfigSecurity;
584
+ /** Absent until the account configures an event webhook. */
585
+ events?: NotifyConfigEventsRead;
366
586
  /** Tombstoned entries are already dropped — a deleted category is simply gone. */
367
587
  categories: Record<string, NotifyConfigCategory>;
368
588
  /** Owner-managed SSM references. Readable, never account-writable. */
@@ -382,10 +602,17 @@ export interface NotifyConfigPatch {
382
602
  reliability?: NotifyConfigReliability;
383
603
  history?: NotifyConfigHistory;
384
604
  security?: NotifyConfigSecurity;
605
+ events?: NotifyConfigEvents;
385
606
  categories?: Record<string, NotifyConfigCategory | null>;
386
607
  }
387
- /** The stored override delta, verbatim — tombstones included, because that is what a write merges onto. */
388
- export type NotifyConfigOverrides = NotifyConfigPatch;
608
+ /**
609
+ * The stored override delta, tombstones included, because that is what a write
610
+ * merges onto. One value is held back: `events.secret` comes back as
611
+ * `secret_set`, never the secret — a patch never has to resend it.
612
+ */
613
+ export type NotifyConfigOverrides = Omit<NotifyConfigPatch, 'events'> & {
614
+ events?: NotifyConfigEventsRead;
615
+ };
389
616
  export interface NotifyConfigResponse {
390
617
  effective: NotifyConfig;
391
618
  overrides: NotifyConfigOverrides;