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