@sparkvault/sdk-js 8.13.0 → 8.14.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.
@@ -63,6 +63,19 @@ class QuotaExceededError extends SparkVaultError {
63
63
  Object.setPrototypeOf(this, QuotaExceededError.prototype);
64
64
  }
65
65
  }
66
+ /**
67
+ * Notify subscription gate (403 NOTIFY_SUBSCRIPTION_REQUIRED) — the account has
68
+ * no active Notify subscription and attempted a send. Distinct from a generic
69
+ * authorization failure: the credential is fine and re-authenticating changes
70
+ * nothing, so surface a subscribe CTA rather than a sign-in prompt.
71
+ */
72
+ class NotifySubscriptionRequiredError extends SparkVaultError {
73
+ constructor(message, details) {
74
+ super(message, 'NOTIFY_SUBSCRIPTION_REQUIRED', 403, details);
75
+ this.name = 'NotifySubscriptionRequiredError';
76
+ Object.setPrototypeOf(this, NotifySubscriptionRequiredError.prototype);
77
+ }
78
+ }
66
79
  class NetworkError extends SparkVaultError {
67
80
  constructor(message, details) {
68
81
  super(message, 'network_error', undefined, details);
@@ -325,6 +338,11 @@ class HttpClient {
325
338
  // PLAN_REQUIRED is the canonical 402 gate; treat any other 402 as one too.
326
339
  return new PlanRequiredError(message, details);
327
340
  case 403:
341
+ // A Notify send refused for want of a subscription is a billing gate, not
342
+ // a credential problem — give it its own catchable type.
343
+ if (code === 'NOTIFY_SUBSCRIPTION_REQUIRED') {
344
+ return new NotifySubscriptionRequiredError(message, details);
345
+ }
328
346
  return new AuthorizationError(message, details);
329
347
  default:
330
348
  return new SparkVaultError(message, code, status, details);
@@ -9286,6 +9304,401 @@ class IdentityModule {
9286
9304
  }
9287
9305
  }
9288
9306
 
9307
+ /**
9308
+ * Notify Product Module — the TENANT (sender) surface.
9309
+ *
9310
+ * The counterpart to `sv.notify`: where that module is session-scoped and reads
9311
+ * only the signed-in person's OWN inbox, this one is the account-scoped product
9312
+ * surface a tenant's BACKEND drives — send, sender-side inbox reads and state,
9313
+ * send status, receipts, and the account's Notify config. Every method maps to
9314
+ * `/v1/products/notify/*` and is authorized by the caller's account, so the
9315
+ * recipient is supplied explicitly rather than derived from a session.
9316
+ *
9317
+ * Intended for server-side use with an `apiKey` (sent as `X-API-Key`); a Core JWT
9318
+ * works identically. Note the API prefers a Bearer JWT when both credentials are
9319
+ * configured, so a server integration should set `apiKey` alone.
9320
+ *
9321
+ * Notify never touches crypto here: `send` seals content and mints one single-use
9322
+ * SparkLink per recipient server-side, and the client only ever carries pointers
9323
+ * and metadata.
9324
+ */
9325
+ /** Root of every tenant-facing Notify route. */
9326
+ const BASE_PATH = '/v1/products/notify';
9327
+ /**
9328
+ * The caller-supplied idempotency key's accepted shape. Mirrors the server's
9329
+ * validation exactly so a malformed key fails locally instead of on the wire.
9330
+ */
9331
+ const SEND_ID_PATTERN = /^[A-Za-z0-9_.:-]{1,128}$/;
9332
+ const MARK_STATES$1 = ['seen', 'read', 'archived'];
9333
+ /**
9334
+ * Bulk drains ride the sparse unseen/unread GSIs. `archived` has no index, so it
9335
+ * is per-row only.
9336
+ */
9337
+ const BULK_MARK_STATES$1 = ['seen', 'read'];
9338
+ /**
9339
+ * The five secure-by-default preset bundles, mirroring the server's table.
9340
+ *
9341
+ * There is no preset endpoint — presets are a merge over the one send contract,
9342
+ * so they are applied client-side and produce an ordinary `send` request. Caller
9343
+ * arguments always win over a preset's defaults; `channels` left unset lets the
9344
+ * account config resolve the ladder per category.
9345
+ *
9346
+ * `alert` is the only plaintext preset: a non-confidential ping is read at a
9347
+ * glance rather than behind a tap-to-view link. The other four seal.
9348
+ */
9349
+ const NOTIFY_PRESETS = Object.freeze({
9350
+ alert: {
9351
+ category: 'alert',
9352
+ delivery: 'plaintext',
9353
+ policy: { verificationLevel: 'none', interaction: 'view' },
9354
+ },
9355
+ secureMessage: {
9356
+ category: 'secure',
9357
+ channels: ['push', 'web_push', 'email'],
9358
+ policy: { verificationLevel: 'identifier', interaction: 'view' },
9359
+ },
9360
+ conversation: {
9361
+ category: 'conversation',
9362
+ channels: ['in_app', 'push', 'web_push', 'email'],
9363
+ policy: { verificationLevel: 'identifier', interaction: 'reply' },
9364
+ },
9365
+ approval: {
9366
+ category: 'approval',
9367
+ channels: ['in_app', 'push', 'web_push', 'email'],
9368
+ policy: { verificationLevel: 'passkey', interaction: 'approve' },
9369
+ },
9370
+ signatureRequest: {
9371
+ category: 'signature',
9372
+ channels: ['in_app', 'push', 'web_push', 'email'],
9373
+ policy: { verificationLevel: 'passkey', interaction: 'sign' },
9374
+ },
9375
+ });
9376
+ /**
9377
+ * Merge a preset's bundle UNDER the caller's arguments, yielding ordinary send
9378
+ * options. Exported so a caller can inspect (or further adjust) what a preset
9379
+ * would send before sending it.
9380
+ */
9381
+ function buildNotifyPresetSend(preset, options) {
9382
+ const bundle = NOTIFY_PRESETS[preset];
9383
+ if (!bundle) {
9384
+ throw new ValidationError(`Unknown notify preset "${preset}" (valid: ${Object.keys(NOTIFY_PRESETS).join(', ')})`, { field: 'preset', received: preset });
9385
+ }
9386
+ const merged = {
9387
+ ...options,
9388
+ category: options.category || bundle.category,
9389
+ // A caller-supplied delivery wins (a sealed override of an alert is allowed);
9390
+ // otherwise the preset's mode, or the sealed default when it declares none.
9391
+ delivery: options.delivery ?? bundle.delivery,
9392
+ policy: { ...bundle.policy, ...(options.policy ?? {}) },
9393
+ };
9394
+ // Only set channels when the preset declares them and the caller did not
9395
+ // override — leaving it unset lets the account config resolve them per category.
9396
+ const channels = options.channels || bundle.channels;
9397
+ if (channels)
9398
+ merged.channels = channels;
9399
+ return merged;
9400
+ }
9401
+ class NotifyProductModule {
9402
+ constructor(http) {
9403
+ this.http = http;
9404
+ }
9405
+ // ── Send ────────────────────────────────────────────────────────────────────
9406
+ /**
9407
+ * Send a notification: seal the content, mint one single-use SparkLink per
9408
+ * recipient, and enqueue delivery across the resolved channel ladder.
9409
+ *
9410
+ * `sendId` is the idempotency key. Replaying an existing one returns the stored
9411
+ * send unchanged — never re-sealed, never re-delivered — flagged `idempotent`.
9412
+ *
9413
+ * @example
9414
+ * const send = await sv.products.notify.send({
9415
+ * sendId: `invoice:${invoice.id}`,
9416
+ * recipients: [{ id: user.svid, email: user.email }],
9417
+ * content: { payload: 'Your invoice is ready.' },
9418
+ * policy: { verificationLevel: 'identifier', interaction: 'view' },
9419
+ * title: 'Invoice ready',
9420
+ * category: 'transactional',
9421
+ * });
9422
+ */
9423
+ async send(options) {
9424
+ if (options?.sendId !== undefined) {
9425
+ if (typeof options.sendId !== 'string' || !SEND_ID_PATTERN.test(options.sendId)) {
9426
+ throw new ValidationError('sendId must be 1-128 characters of letters, digits, and _ . : -', { field: 'sendId', received: options.sendId });
9427
+ }
9428
+ }
9429
+ if (!Array.isArray(options?.recipients) || options.recipients.length === 0) {
9430
+ throw new ValidationError('recipients is required and must be non-empty', {
9431
+ field: 'recipients',
9432
+ });
9433
+ }
9434
+ if (Boolean(options.content) === Boolean(options.ingot)) {
9435
+ throw new ValidationError('Provide exactly one content source: content OR ingot');
9436
+ }
9437
+ const response = await this.http.post(`${BASE_PATH}/send`, toSendBody(options));
9438
+ return response.data;
9439
+ }
9440
+ /**
9441
+ * Frictionless informational ping — no verification, view-only, delivered
9442
+ * INLINE (plaintext) so it is read at a glance. Channels resolve from the
9443
+ * account config; plaintext requires an inline-capable channel.
9444
+ *
9445
+ * @example
9446
+ * await sv.products.notify.sendAlert({
9447
+ * recipients: [{ id: user.svid }],
9448
+ * content: { payload: 'Your export finished.' },
9449
+ * title: 'Export complete',
9450
+ * });
9451
+ */
9452
+ async sendAlert(options) {
9453
+ return this.send(buildNotifyPresetSend('alert', options));
9454
+ }
9455
+ /** Confidential content revealed after the recipient proves their identifier. */
9456
+ async sendSecureMessage(options) {
9457
+ return this.send(buildNotifyPresetSend('secureMessage', options));
9458
+ }
9459
+ /** Two-way thread: identifier-verified reveal plus an encrypted reply. */
9460
+ async sendConversation(options) {
9461
+ return this.send(buildNotifyPresetSend('conversation', options));
9462
+ }
9463
+ /** High-stakes approve/deny — passkey-verified, with `action_hash` binding. */
9464
+ async sendApproval(options) {
9465
+ return this.send(buildNotifyPresetSend('approval', options));
9466
+ }
9467
+ /** Signature-on-delivery — passkey-verified, with `action_hash` binding. */
9468
+ async sendSignatureRequest(options) {
9469
+ return this.send(buildNotifyPresetSend('signatureRequest', options));
9470
+ }
9471
+ // ── Inbox (sender-side) ─────────────────────────────────────────────────────
9472
+ /**
9473
+ * Read one recipient's metadata-only feed, newest first. Rows are pointers: a
9474
+ * sealed row carries only `sparklink_code`, never the content.
9475
+ *
9476
+ * A page can come back SHORT of `limit` yet still carry a non-null cursor —
9477
+ * follow the cursor; never treat a short page as the end.
9478
+ *
9479
+ * @example
9480
+ * const { notifications, cursor } = await sv.products.notify.getInbox({
9481
+ * recipientId: user.svid,
9482
+ * state: 'unread',
9483
+ * });
9484
+ */
9485
+ async getInbox(options) {
9486
+ requireRecipientId(options?.recipientId);
9487
+ const query = buildQuery$3({
9488
+ recipient_id: options.recipientId,
9489
+ state: options.state,
9490
+ limit: options.limit,
9491
+ cursor: options.cursor,
9492
+ });
9493
+ const response = await this.http.get(`${BASE_PATH}/inbox${query}`);
9494
+ return response.data;
9495
+ }
9496
+ /**
9497
+ * Apply a terminal display state to one row (idempotent). `createdAt` MUST be
9498
+ * the row's own `created_at`, round-tripped from the feed or the webhook/push
9499
+ * payload — the id alone cannot address the row.
9500
+ *
9501
+ * @example
9502
+ * await sv.products.notify.markInboxState(row.notification_id, {
9503
+ * recipientId: user.svid,
9504
+ * createdAt: row.created_at,
9505
+ * state: 'read',
9506
+ * });
9507
+ */
9508
+ async markInboxState(notificationId, options) {
9509
+ if (!notificationId || typeof notificationId !== 'string') {
9510
+ throw new ValidationError('notificationId is required', { field: 'notificationId' });
9511
+ }
9512
+ requireRecipientId(options?.recipientId);
9513
+ if (!Number.isInteger(options?.createdAt)) {
9514
+ throw new ValidationError("createdAt (the row's created_at) is required", {
9515
+ field: 'createdAt',
9516
+ received: options?.createdAt,
9517
+ });
9518
+ }
9519
+ if (!MARK_STATES$1.includes(options.state)) {
9520
+ throw new ValidationError(`state must be one of ${MARK_STATES$1.join(', ')}`, {
9521
+ field: 'state',
9522
+ received: options.state,
9523
+ });
9524
+ }
9525
+ const response = await this.http.post(`${BASE_PATH}/inbox/${encodeURIComponent(notificationId)}/state`, { recipient_id: options.recipientId, created_at: options.createdAt, state: options.state });
9526
+ return response.data;
9527
+ }
9528
+ /**
9529
+ * Bulk-mark one bounded page of a recipient's inbox `seen` or `read`. Loop on
9530
+ * the returned cursor until it is null. `archived` is per-row only.
9531
+ *
9532
+ * @example
9533
+ * let cursor: string | undefined;
9534
+ * do {
9535
+ * const page = await sv.products.notify.markInboxAll({
9536
+ * recipientId: user.svid, state: 'read', cursor,
9537
+ * });
9538
+ * cursor = page.cursor ?? undefined;
9539
+ * } while (cursor);
9540
+ */
9541
+ async markInboxAll(options) {
9542
+ requireRecipientId(options?.recipientId);
9543
+ if (!BULK_MARK_STATES$1.includes(options.state)) {
9544
+ throw new ValidationError(`state must be one of ${BULK_MARK_STATES$1.join(', ')} (archive per-row instead)`, { field: 'state', received: options.state });
9545
+ }
9546
+ const response = await this.http.post(`${BASE_PATH}/inbox/state`, {
9547
+ recipient_id: options.recipientId,
9548
+ state: options.state,
9549
+ cursor: options.cursor,
9550
+ });
9551
+ return response.data;
9552
+ }
9553
+ // ── Status & receipts ───────────────────────────────────────────────────────
9554
+ /**
9555
+ * The sender's per-recipient delivery rollup for one send: who it reached and
9556
+ * how far each recipient got. Metadata only — never the pointer or contacts.
9557
+ *
9558
+ * @example
9559
+ * const { counts } = await sv.products.notify.getSendStatus(send.send_id);
9560
+ */
9561
+ async getSendStatus(sendId) {
9562
+ requireSendId(sendId);
9563
+ const response = await this.http.get(`${BASE_PATH}/sends/${encodeURIComponent(sendId)}/status`);
9564
+ return response.data;
9565
+ }
9566
+ /**
9567
+ * The account's verified-interaction receipts (portable, JWKS-verifiable
9568
+ * proofs), newest first. Follow `cursor` to page.
9569
+ *
9570
+ * A page can come back SHORT of `limit` — even EMPTY — yet still carry a
9571
+ * non-null cursor: the receipt-subtype and `interaction` filters are applied
9572
+ * after the key query, so a page of non-matching rows yields no receipts and a
9573
+ * live cursor. Follow the cursor; never treat a short or empty page as the end.
9574
+ *
9575
+ * @example
9576
+ * const { receipts, cursor } = await sv.products.notify.listReceipts({ interaction: 'approve' });
9577
+ */
9578
+ async listReceipts(options = {}) {
9579
+ const query = buildQuery$3({
9580
+ limit: options.limit,
9581
+ cursor: options.cursor,
9582
+ interaction: options.interaction,
9583
+ });
9584
+ const response = await this.http.get(`${BASE_PATH}/receipts${query}`);
9585
+ return response.data;
9586
+ }
9587
+ /**
9588
+ * Every receipt for one send, each attached to the recipient who produced it.
9589
+ * The correlation scan is bounded: when `truncated` is true, some older
9590
+ * receipts fall outside the scanned window — pass the returned `cursor` back in
9591
+ * to resume the scan exactly where it stopped.
9592
+ *
9593
+ * @example
9594
+ * const all: NotifySendReceipt[] = [];
9595
+ * let cursor: string | undefined;
9596
+ * do {
9597
+ * const page = await sv.products.notify.getSendReceipts(send.send_id, { cursor });
9598
+ * all.push(...page.receipts);
9599
+ * cursor = page.truncated ? page.cursor ?? undefined : undefined;
9600
+ * } while (cursor);
9601
+ */
9602
+ async getSendReceipts(sendId, options = {}) {
9603
+ requireSendId(sendId);
9604
+ const query = buildQuery$3({ cursor: options.cursor });
9605
+ const response = await this.http.get(`${BASE_PATH}/sends/${encodeURIComponent(sendId)}/receipts${query}`);
9606
+ return response.data;
9607
+ }
9608
+ // ── Config ──────────────────────────────────────────────────────────────────
9609
+ /**
9610
+ * The account's effective Notify config (secure defaults deep-merged with its
9611
+ * overrides) plus the raw override delta, so an editor can show what is
9612
+ * customized versus default.
9613
+ *
9614
+ * @example
9615
+ * const { effective, overrides } = await sv.products.notify.getConfig();
9616
+ */
9617
+ async getConfig() {
9618
+ const response = await this.http.get(`${BASE_PATH}/config`);
9619
+ return response.data;
9620
+ }
9621
+ /**
9622
+ * Merge a partial patch onto the account's config overrides. Owner-gated
9623
+ * (`channel_credentials`) and unknown keys are rejected before any write.
9624
+ *
9625
+ * Delete a category by storing an explicit `null` TOMBSTONE — that is what keeps
9626
+ * a seeded default from re-appearing on the next merge. The reserved `security`
9627
+ * category can neither be removed nor made optional.
9628
+ *
9629
+ * @example
9630
+ * await sv.products.notify.updateConfig({
9631
+ * categories: {
9632
+ * weekly_newsletter: { label: 'Weekly newsletter', required: false },
9633
+ * marketing: null, // tombstone — remove the seeded default
9634
+ * },
9635
+ * });
9636
+ */
9637
+ async updateConfig(patch) {
9638
+ if (!patch || typeof patch !== 'object' || Array.isArray(patch)) {
9639
+ throw new ValidationError('config patch must be an object');
9640
+ }
9641
+ const response = await this.http.put(`${BASE_PATH}/config`, patch);
9642
+ return response.data;
9643
+ }
9644
+ }
9645
+ /**
9646
+ * Map the camelCase option bag onto the send body. Undefined fields drop out at
9647
+ * JSON serialization, so an omitted option is absent on the wire rather than null.
9648
+ */
9649
+ function toSendBody(options) {
9650
+ return {
9651
+ send_id: options.sendId,
9652
+ recipients: options.recipients,
9653
+ content: options.content
9654
+ ? {
9655
+ payload: options.content.payload,
9656
+ content_type: options.content.contentType,
9657
+ filename: options.content.filename,
9658
+ ttl_minutes: options.content.ttlMinutes,
9659
+ }
9660
+ : undefined,
9661
+ ingot: options.ingot
9662
+ ? { ingot_id: options.ingot.ingotId, vault_id: options.ingot.vaultId }
9663
+ : undefined,
9664
+ delivery: options.delivery,
9665
+ policy: options.policy
9666
+ ? {
9667
+ verification_level: options.policy.verificationLevel,
9668
+ interaction: options.policy.interaction,
9669
+ reveal_freshness_minutes: options.policy.revealFreshnessMinutes,
9670
+ }
9671
+ : undefined,
9672
+ channels: options.channels,
9673
+ escalation: options.escalation,
9674
+ title: options.title,
9675
+ category: options.category,
9676
+ type: options.type,
9677
+ instructions: options.instructions,
9678
+ history_ttl_days: options.historyTtlDays,
9679
+ };
9680
+ }
9681
+ function requireRecipientId(recipientId) {
9682
+ if (!recipientId || typeof recipientId !== 'string') {
9683
+ throw new ValidationError('recipientId is required', { field: 'recipientId' });
9684
+ }
9685
+ }
9686
+ function requireSendId(sendId) {
9687
+ if (!sendId || typeof sendId !== 'string') {
9688
+ throw new ValidationError('sendId is required', { field: 'sendId' });
9689
+ }
9690
+ }
9691
+ function buildQuery$3(params) {
9692
+ const search = new URLSearchParams();
9693
+ for (const [key, value] of Object.entries(params)) {
9694
+ if (value === undefined || value === '')
9695
+ continue;
9696
+ search.append(key, String(value));
9697
+ }
9698
+ const query = search.toString();
9699
+ return query ? `?${query}` : '';
9700
+ }
9701
+
9289
9702
  /**
9290
9703
  * Products Module
9291
9704
  *
@@ -9294,8 +9707,13 @@ class IdentityModule {
9294
9707
  * Currently exposes `identity`; future products attach here alongside it.
9295
9708
  */
9296
9709
  class ProductsModule {
9297
- constructor(config) {
9710
+ /**
9711
+ * `http` defaults to a client over the same resolved config so constructing
9712
+ * this module standalone stays a one-argument call.
9713
+ */
9714
+ constructor(config, http = new HttpClient(config)) {
9298
9715
  this.identity = new IdentityModule(config);
9716
+ this.notify = new NotifyProductModule(http);
9299
9717
  }
9300
9718
  }
9301
9719
 
@@ -9340,8 +9758,13 @@ function isInitiateUploadResponse(data) {
9340
9758
  }
9341
9759
  /** tus protocol version used for the resumable upload session. */
9342
9760
  const TUS_VERSION = '1.0.0';
9343
- /** Default TUS chunk size; the server may override via `X-Chunk-Size`. */
9344
- const DEFAULT_CHUNK_SIZE = 50 * 1024 * 1024;
9761
+ /** Strict positive-integer parse of Forge's advertised chunk size; anything else is `null`. */
9762
+ function parseChunkSizeHeader(raw) {
9763
+ if (raw === null || !/^\d+$/.test(raw.trim()))
9764
+ return null;
9765
+ const value = Number(raw);
9766
+ return Number.isSafeInteger(value) && value > 0 ? value : null;
9767
+ }
9345
9768
  /**
9346
9769
  * Abort a stalled chunk PATCH after this long with no upload progress.
9347
9770
  * XHR's own `timeout` measures total request duration, which would abort a
@@ -9436,10 +9859,11 @@ class UploadApi extends SparkVaultApi {
9436
9859
  *
9437
9860
  * The single canonical browser transfer path — the upload widget and the
9438
9861
  * authenticated `ingots.upload` flow both go through here (one canonical
9439
- * transfer path). Creates the session, PATCHes chunks sized by the server's
9440
- * `X-Chunk-Size` (50MB default, which keeps every request under CDN body
9441
- * caps such as Cloudflare's 100MB), validates every server-reported offset,
9442
- * and honors the session abort signal plus per-request timeouts.
9862
+ * transfer path). Creates the session, PATCHes chunks sized exactly by the
9863
+ * server's `X-Chunk-Size` (Forge fixes the geometry at 50MB, which keeps
9864
+ * every request under CDN body caps such as Cloudflare's 100MB), validates
9865
+ * every server-reported offset, and honors the session abort signal plus
9866
+ * per-request timeouts.
9443
9867
  *
9444
9868
  * Returns the TUS session URL so the caller can confirm server-side
9445
9869
  * finalization via {@link verifyUploadFinalized} before reporting success.
@@ -9493,12 +9917,15 @@ class UploadApi extends SparkVaultApi {
9493
9917
  if (!location) {
9494
9918
  throw new UploadApiError('Server did not return upload location', 'tus_create_failed', response.status);
9495
9919
  }
9920
+ // Forge fixes every session's chunk geometry and rejects any non-final
9921
+ // chunk that is not exactly the advertised size, so a client-side guess
9922
+ // could only ever be rejected: a missing header is a contract violation.
9496
9923
  const chunkSizeHeader = response.headers.get('X-Chunk-Size');
9497
- const chunkSize = chunkSizeHeader ? parseInt(chunkSizeHeader, 10) : NaN;
9498
- return {
9499
- location,
9500
- chunkSize: Number.isFinite(chunkSize) && chunkSize > 0 ? chunkSize : DEFAULT_CHUNK_SIZE,
9501
- };
9924
+ const chunkSize = parseChunkSizeHeader(chunkSizeHeader);
9925
+ if (chunkSize === null) {
9926
+ throw new UploadApiError('Server did not return a valid X-Chunk-Size', 'tus_create_failed', response.status, { header: 'X-Chunk-Size', received: chunkSizeHeader });
9927
+ }
9928
+ return { location, chunkSize };
9502
9929
  }
9503
9930
  catch (error) {
9504
9931
  if (error instanceof SparkVaultError)
@@ -13687,6 +14114,13 @@ class EntropyModule {
13687
14114
  * device push registration is intentionally omitted (Expo-only on mobile).
13688
14115
  */
13689
14116
  const MARK_STATES = ['seen', 'read', 'archived'];
14117
+ const BULK_MARK_STATES = ['seen', 'read'];
14118
+ /**
14119
+ * Hard bound on `markAllRead()`'s drain loop: 100 server pages of 100 rows. A
14120
+ * cursor that never resolves to null can therefore never spin forever, and an
14121
+ * inbox deeper than the bound finishes on a second call (the drain is idempotent).
14122
+ */
14123
+ const MARK_ALL_MAX_PAGES = 100;
13690
14124
  /**
13691
14125
  * Decode a base64url VAPID key into the Uint8Array `pushManager.subscribe`
13692
14126
  * requires for `applicationServerKey`. Standalone (no atob dependency on a
@@ -13776,6 +14210,65 @@ class NotifyModule {
13776
14210
  const response = await this.http.post(`/v1/me/notifications/${encodeURIComponent(notificationId)}/state`, { created_at: options.createdAt, state: options.state });
13777
14211
  return response.data;
13778
14212
  }
14213
+ /**
14214
+ * Bulk-mark ONE bounded page of the caller's inbox and return the server's
14215
+ * payload verbatim. `cursor` comes back non-null while rows remain — thread it
14216
+ * into the next call. `archived` is per-row only (no GSI to page over), so the
14217
+ * bulk states are `seen` and `read`.
14218
+ *
14219
+ * Prefer `markAllRead()` unless the caller needs to own the paging.
14220
+ *
14221
+ * @example
14222
+ * let page = await sv.notify.markAllState({ state: 'seen' });
14223
+ * while (page.cursor) page = await sv.notify.markAllState({ state: 'seen', cursor: page.cursor });
14224
+ */
14225
+ async markAllState(options) {
14226
+ if (!BULK_MARK_STATES.includes(options?.state)) {
14227
+ throw new ValidationError(`state must be one of ${BULK_MARK_STATES.join(', ')}`, {
14228
+ field: 'state',
14229
+ received: options?.state,
14230
+ });
14231
+ }
14232
+ if (options.cursor !== undefined && typeof options.cursor !== 'string') {
14233
+ throw new ValidationError('cursor must be the string cursor from a prior response', {
14234
+ field: 'cursor',
14235
+ received: options.cursor,
14236
+ });
14237
+ }
14238
+ const body = { state: options.state };
14239
+ if (options.cursor)
14240
+ body.cursor = options.cursor;
14241
+ const response = await this.http.post('/v1/me/notifications/state', body);
14242
+ return response.data;
14243
+ }
14244
+ /**
14245
+ * Drain the caller's whole inbox to read: loop `markAllState` on the returned
14246
+ * cursor until it comes back null, and return the total marked. Marking read
14247
+ * clears the unseen marker too, so the badge zeroes with it. Idempotent.
14248
+ *
14249
+ * `complete` is false when the loop stopped at the page bound with rows still
14250
+ * unmarked — an inbox deeper than the bound finishes on a second call. Without
14251
+ * it a truncated drain looks exactly like a finished one.
14252
+ *
14253
+ * An error mid-drain propagates — the pages already marked stay marked, and a
14254
+ * re-run picks up the remainder.
14255
+ *
14256
+ * @example
14257
+ * let { updated, complete } = await sv.notify.markAllRead();
14258
+ * while (!complete) ({ complete } = await sv.notify.markAllRead());
14259
+ */
14260
+ async markAllRead() {
14261
+ let cursor;
14262
+ let updated = 0;
14263
+ for (let page = 0; page < MARK_ALL_MAX_PAGES; page += 1) {
14264
+ const result = await this.markAllState(cursor ? { state: 'read', cursor } : { state: 'read' });
14265
+ updated += result?.updated ?? 0;
14266
+ if (!result?.cursor)
14267
+ return { updated, complete: true };
14268
+ cursor = result.cursor;
14269
+ }
14270
+ return { updated, complete: false };
14271
+ }
13779
14272
  // ── Browser Web Push ──────────────────────────────────────────────────────
13780
14273
  /**
13781
14274
  * Whether this environment can do Web Push (service worker + Push API +
@@ -14058,7 +14551,7 @@ class SparkVault {
14058
14551
  validateConfig(config);
14059
14552
  this.config = resolveConfig(config);
14060
14553
  const http = new HttpClient(this.config);
14061
- this.products = new ProductsModule(this.config);
14554
+ this.products = new ProductsModule(this.config, http);
14062
14555
  this.vaults = new VaultsModule(this.config, http);
14063
14556
  this.ingots = new IngotsModule(this.config, http);
14064
14557
  this.folders = new FoldersModule(http);
@@ -14110,8 +14603,11 @@ exports.EntropyModule = EntropyModule;
14110
14603
  exports.FoldersModule = FoldersModule;
14111
14604
  exports.IdentityModule = IdentityModule;
14112
14605
  exports.IngotsModule = IngotsModule;
14606
+ exports.NOTIFY_PRESETS = NOTIFY_PRESETS;
14113
14607
  exports.NetworkError = NetworkError;
14114
14608
  exports.NotifyModule = NotifyModule;
14609
+ exports.NotifyProductModule = NotifyProductModule;
14610
+ exports.NotifySubscriptionRequiredError = NotifySubscriptionRequiredError;
14115
14611
  exports.PlanRequiredError = PlanRequiredError;
14116
14612
  exports.PopupBlockedError = PopupBlockedError;
14117
14613
  exports.ProductsModule = ProductsModule;
@@ -14123,6 +14619,7 @@ exports.TimeoutError = TimeoutError;
14123
14619
  exports.UserCancelledError = UserCancelledError;
14124
14620
  exports.ValidationError = ValidationError;
14125
14621
  exports.VaultsModule = VaultsModule;
14622
+ exports.buildNotifyPresetSend = buildNotifyPresetSend;
14126
14623
  exports.default = SparkVault;
14127
14624
  exports.logger = logger;
14128
14625
  exports.setDebugMode = setDebugMode;