@sparkvault/sdk-js 8.13.1 → 8.15.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.
@@ -8,7 +8,7 @@
8
8
  * device push registration is intentionally omitted (Expo-only on mobile).
9
9
  */
10
10
  import { HttpClient } from '../http';
11
- import type { ListNotificationsOptions, ListNotificationsResponse, UnreadCountResponse, MarkNotificationStateOptions, MarkNotificationStateResponse, WebPushKeyResponse, WebPushSubscriptionInput, RegisterWebPushResponse, UnsubscribeWebPushResponse, SubscribeWebPushOptions, SubscribeWebPushResult } from './types';
11
+ import type { ListNotificationsOptions, ListNotificationsResponse, UnreadCountResponse, MarkNotificationStateOptions, MarkNotificationStateResponse, MarkAllNotificationsStateOptions, MarkAllNotificationsStateResponse, MarkAllReadResult, WebPushKeyResponse, WebPushSubscriptionInput, RegisterWebPushResponse, UnsubscribeWebPushResponse, SubscribeWebPushOptions, SubscribeWebPushResult } from './types';
12
12
  export declare class NotifyModule {
13
13
  private readonly http;
14
14
  constructor(http: HttpClient);
@@ -37,6 +37,36 @@ export declare class NotifyModule {
37
37
  * await sv.notify.markState('ntf_abc', { createdAt: row.created_at, state: 'read' });
38
38
  */
39
39
  markState(notificationId: string, options: MarkNotificationStateOptions): Promise<MarkNotificationStateResponse>;
40
+ /**
41
+ * Bulk-mark ONE bounded page of the caller's inbox and return the server's
42
+ * payload verbatim. `cursor` comes back non-null while rows remain — thread it
43
+ * into the next call. `archived` is per-row only (no GSI to page over), so the
44
+ * bulk states are `seen` and `read`.
45
+ *
46
+ * Prefer `markAllRead()` unless the caller needs to own the paging.
47
+ *
48
+ * @example
49
+ * let page = await sv.notify.markAllState({ state: 'seen' });
50
+ * while (page.cursor) page = await sv.notify.markAllState({ state: 'seen', cursor: page.cursor });
51
+ */
52
+ markAllState(options: MarkAllNotificationsStateOptions): Promise<MarkAllNotificationsStateResponse>;
53
+ /**
54
+ * Drain the caller's whole inbox to read: loop `markAllState` on the returned
55
+ * cursor until it comes back null, and return the total marked. Marking read
56
+ * clears the unseen marker too, so the badge zeroes with it. Idempotent.
57
+ *
58
+ * `complete` is false when the loop stopped at the page bound with rows still
59
+ * unmarked — an inbox deeper than the bound finishes on a second call. Without
60
+ * it a truncated drain looks exactly like a finished one.
61
+ *
62
+ * An error mid-drain propagates — the pages already marked stay marked, and a
63
+ * re-run picks up the remainder.
64
+ *
65
+ * @example
66
+ * let { updated, complete } = await sv.notify.markAllRead();
67
+ * while (!complete) ({ complete } = await sv.notify.markAllRead());
68
+ */
69
+ markAllRead(): Promise<MarkAllReadResult>;
40
70
  /**
41
71
  * Whether this environment can do Web Push (service worker + Push API +
42
72
  * Notifications). Feature-detect before showing an enable-notifications UI.
@@ -74,4 +104,4 @@ export declare class NotifyModule {
74
104
  */
75
105
  unsubscribeWebPush(options: SubscribeWebPushOptions): Promise<boolean>;
76
106
  }
77
- export type { NotificationInboxState, NotificationMarkState, NotificationRow, ListNotificationsOptions, ListNotificationsResponse, UnreadCountResponse, MarkNotificationStateOptions, MarkNotificationStateResponse, WebPushKeyResponse, WebPushSubscriptionInput, RegisterWebPushResponse, UnsubscribeWebPushResponse, SubscribeWebPushStatus, SubscribeWebPushOptions, SubscribeWebPushResult, } from './types';
107
+ export type { NotificationInboxState, NotificationMarkState, NotificationRow, ListNotificationsOptions, ListNotificationsResponse, UnreadCountResponse, MarkNotificationStateOptions, MarkNotificationStateResponse, NotificationBulkMarkState, MarkAllNotificationsStateOptions, MarkAllNotificationsStateResponse, MarkAllReadResult, WebPushKeyResponse, WebPushSubscriptionInput, RegisterWebPushResponse, UnsubscribeWebPushResponse, SubscribeWebPushStatus, SubscribeWebPushOptions, SubscribeWebPushResult, } from './types';
@@ -77,6 +77,33 @@ export interface MarkNotificationStateResponse {
77
77
  state: NotificationMarkState;
78
78
  updated_at: number;
79
79
  }
80
+ /**
81
+ * States a BULK drain can apply. `archived` is per-row only — it has no GSI for
82
+ * the server to page over, so the bulk endpoint rejects it.
83
+ */
84
+ export type NotificationBulkMarkState = 'seen' | 'read';
85
+ export interface MarkAllNotificationsStateOptions {
86
+ state: NotificationBulkMarkState;
87
+ /** Cursor from the prior page's response; omit to start at the newest page. */
88
+ cursor?: string;
89
+ }
90
+ export interface MarkAllNotificationsStateResponse {
91
+ /** Rows marked by THIS page — the server marks one bounded page per call. */
92
+ updated: number;
93
+ /** Cursor for the next page, or null once the inbox is drained. */
94
+ cursor: string | null;
95
+ }
96
+ /** Total across a full `markAllRead()` drain. */
97
+ export interface MarkAllReadResult {
98
+ updated: number;
99
+ /**
100
+ * True when the drain reached the end of the inbox (the server returned a null
101
+ * cursor). False when it stopped at the page bound with rows still unmarked —
102
+ * call again to continue. Without this a truncated drain is indistinguishable
103
+ * from a completed one.
104
+ */
105
+ complete: boolean;
106
+ }
80
107
  /** The platform VAPID public key needed for pushManager.subscribe(). */
81
108
  export interface WebPushKeyResponse {
82
109
  /** False until the VAPID keypair is provisioned server-side — hide the UI. */
@@ -180,13 +180,24 @@ export declare class IdentityModule {
180
180
  * session storage or WebCrypto is unavailable so callers can degrade.
181
181
  */
182
182
  private prepareHandoffNavigation;
183
+ /**
184
+ * Arm the self-heal marker for an in-flight sign-in. `hint` is the identifier
185
+ * (email or phone) the sign-in was started with, when the caller supplied
186
+ * one — the recovery bounce forwards it as the /sso `login_hint`, so with
187
+ * several hub sessions recovery re-mints the account this sign-in was for,
188
+ * never a different one.
189
+ */
183
190
  private markSignInPending;
184
191
  private clearSignInPending;
185
- /** True once (then cleared) if a recent sign-in is still awaiting its result. */
192
+ /**
193
+ * Consume the pending marker: `fresh` is true once (then cleared) if a recent
194
+ * sign-in is still awaiting its result; `hint` is the identifier that sign-in
195
+ * carried, for the recovery bounce's `login_hint`.
196
+ */
186
197
  private consumeSignInPending;
187
198
  /** Remove the result fragment from the URL bar (and history entry). */
188
199
  private clearUrlFragment;
189
- /** Drop the one-shot PKCE state/verifier a redirect bounce staged. */
200
+ /** Drop the one-shot PKCE state/verifier (+ recovery hint) a bounce staged. */
190
201
  private clearOneShotAuthState;
191
202
  private consumeRedirectResult;
192
203
  /**
@@ -51,6 +51,12 @@ export interface VerifyOptions {
51
51
  * hosts that prefer a full-page redirect over a popup on mobile.
52
52
  */
53
53
  flow?: 'auto' | 'popup' | 'redirect';
54
+ /**
55
+ * `'select_account'` always shows the sign-in page's account chooser instead
56
+ * of silently continuing as the current account — even when only one saved
57
+ * account exists. Any other value is dropped at URL serialization.
58
+ */
59
+ prompt?: 'select_account';
54
60
  /**
55
61
  * Rendering strategy (internal). `'local'` renders the flow directly in this
56
62
  * document — used inside the popup that runs the flow, and forced for inline
@@ -73,6 +79,8 @@ export interface AttachOptions {
73
79
  phone?: string;
74
80
  /** Auth context for OIDC/simple mode flows */
75
81
  authContext?: AuthContext;
82
+ /** `'select_account'` always shows the account chooser (see `VerifyOptions.prompt`) */
83
+ prompt?: 'select_account';
76
84
  /** Called when user cancels */
77
85
  onCancel?: () => void;
78
86
  /** Called when verification completes */
@@ -6,13 +6,27 @@
6
6
  * Currently exposes `identity`; future products attach here alongside it.
7
7
  */
8
8
  import type { ResolvedConfig } from '../config';
9
+ import { HttpClient } from '../http';
9
10
  import { IdentityModule } from './identity';
11
+ import { NotifyProductModule } from './notify';
10
12
  export declare class ProductsModule {
11
13
  /** Identity verification product (passkey, OTP, SparkLink, social). */
12
14
  readonly identity: IdentityModule;
13
- constructor(config: ResolvedConfig);
15
+ /**
16
+ * Notify product — the tenant/sender surface (send, sender-side inbox, status,
17
+ * receipts, config). Distinct from `sv.notify`, which is the signed-in
18
+ * recipient's own inbox.
19
+ */
20
+ readonly notify: NotifyProductModule;
21
+ /**
22
+ * `http` defaults to a client over the same resolved config so constructing
23
+ * this module standalone stays a one-argument call.
24
+ */
25
+ constructor(config: ResolvedConfig, http?: HttpClient);
14
26
  }
15
27
  export { IdentityModule } from './identity';
28
+ export { NotifyProductModule, NOTIFY_PRESETS, buildNotifyPresetSend } from './notify';
16
29
  export type { VerifyOptions, AttachOptions, VerifyResult, TokenClaims, AuthMethod, AuthContext, Theme, SdkConfig, SdkConfigBranding, MethodId, MethodMetadata, } from './identity';
17
30
  export { METHOD_REGISTRY, getMethodMetadata, enrichMethods } from './identity';
18
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';
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Notify Product Module — the TENANT (sender) surface.
3
+ *
4
+ * The counterpart to `sv.notify`: where that module is session-scoped and reads
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
8
+ * `/v1/products/notify/*` and is authorized by the caller's account, so the
9
+ * recipient is supplied explicitly rather than derived from a session.
10
+ *
11
+ * Intended for server-side use with an `apiKey` (sent as `X-API-Key`); a Core JWT
12
+ * works identically. Note the API prefers a Bearer JWT when both credentials are
13
+ * configured, so a server integration should set `apiKey` alone.
14
+ *
15
+ * Notify never touches crypto here: `send` seals content and mints one single-use
16
+ * SparkLink per recipient server-side, and the client only ever carries pointers
17
+ * and metadata.
18
+ */
19
+ 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
+ /**
22
+ * The five secure-by-default preset bundles, mirroring the server's table.
23
+ *
24
+ * There is no preset endpoint — presets are a merge over the one send contract,
25
+ * so they are applied client-side and produce an ordinary `send` request. Caller
26
+ * arguments always win over a preset's defaults; `channels` left unset lets the
27
+ * account config resolve the ladder per category.
28
+ *
29
+ * `alert` is the only plaintext preset: a non-confidential ping is read at a
30
+ * glance rather than behind a tap-to-view link. The other four seal.
31
+ */
32
+ export declare const NOTIFY_PRESETS: Readonly<Record<NotifyPresetName, NotifyPreset>>;
33
+ /**
34
+ * Merge a preset's bundle UNDER the caller's arguments, yielding ordinary send
35
+ * options. Exported so a caller can inspect (or further adjust) what a preset
36
+ * would send before sending it.
37
+ */
38
+ export declare function buildNotifyPresetSend(preset: NotifyPresetName, options: CreateNotifySendOptions): CreateNotifySendOptions;
39
+ export declare class NotifyProductModule {
40
+ private readonly http;
41
+ constructor(http: HttpClient);
42
+ /**
43
+ * Send a notification: seal the content, mint one single-use SparkLink per
44
+ * recipient, and enqueue delivery across the resolved channel ladder.
45
+ *
46
+ * `sendId` is the idempotency key. Replaying an existing one returns the stored
47
+ * send unchanged — never re-sealed, never re-delivered — flagged `idempotent`.
48
+ *
49
+ * @example
50
+ * const send = await sv.products.notify.send({
51
+ * sendId: `invoice:${invoice.id}`,
52
+ * recipients: [{ id: user.svid, email: user.email }],
53
+ * content: { payload: 'Your invoice is ready.' },
54
+ * policy: { verificationLevel: 'identifier', interaction: 'view' },
55
+ * title: 'Invoice ready',
56
+ * category: 'transactional',
57
+ * });
58
+ */
59
+ send(options: CreateNotifySendOptions): Promise<NotifySendResult>;
60
+ /**
61
+ * Frictionless informational ping — no verification, view-only, delivered
62
+ * INLINE (plaintext) so it is read at a glance. Channels resolve from the
63
+ * account config; plaintext requires an inline-capable channel.
64
+ *
65
+ * @example
66
+ * await sv.products.notify.sendAlert({
67
+ * recipients: [{ id: user.svid }],
68
+ * content: { payload: 'Your export finished.' },
69
+ * title: 'Export complete',
70
+ * });
71
+ */
72
+ sendAlert(options: CreateNotifySendOptions): Promise<NotifySendResult>;
73
+ /** Confidential content revealed after the recipient proves their identifier. */
74
+ sendSecureMessage(options: CreateNotifySendOptions): Promise<NotifySendResult>;
75
+ /** Two-way thread: identifier-verified reveal plus an encrypted reply. */
76
+ sendConversation(options: CreateNotifySendOptions): Promise<NotifySendResult>;
77
+ /** High-stakes approve/deny — passkey-verified, with `action_hash` binding. */
78
+ sendApproval(options: CreateNotifySendOptions): Promise<NotifySendResult>;
79
+ /** Signature-on-delivery — passkey-verified, with `action_hash` binding. */
80
+ sendSignatureRequest(options: CreateNotifySendOptions): Promise<NotifySendResult>;
81
+ /**
82
+ * Read one recipient's metadata-only feed, newest first. Rows are pointers: a
83
+ * sealed row carries only `sparklink_code`, never the content.
84
+ *
85
+ * A page can come back SHORT of `limit` yet still carry a non-null cursor —
86
+ * follow the cursor; never treat a short page as the end.
87
+ *
88
+ * @example
89
+ * const { notifications, cursor } = await sv.products.notify.getInbox({
90
+ * recipientId: user.svid,
91
+ * state: 'unread',
92
+ * });
93
+ */
94
+ getInbox(options: ListNotifyInboxOptions): Promise<ListNotifyInboxResponse>;
95
+ /**
96
+ * Apply a terminal display state to one row (idempotent). `createdAt` MUST be
97
+ * the row's own `created_at`, round-tripped from the feed or the webhook/push
98
+ * payload — the id alone cannot address the row.
99
+ *
100
+ * @example
101
+ * await sv.products.notify.markInboxState(row.notification_id, {
102
+ * recipientId: user.svid,
103
+ * createdAt: row.created_at,
104
+ * state: 'read',
105
+ * });
106
+ */
107
+ markInboxState(notificationId: string, options: MarkNotifyInboxStateOptions): Promise<MarkNotifyInboxStateResponse>;
108
+ /**
109
+ * Bulk-mark one bounded page of a recipient's inbox `seen` or `read`. Loop on
110
+ * the returned cursor until it is null. `archived` is per-row only.
111
+ *
112
+ * @example
113
+ * let cursor: string | undefined;
114
+ * do {
115
+ * const page = await sv.products.notify.markInboxAll({
116
+ * recipientId: user.svid, state: 'read', cursor,
117
+ * });
118
+ * cursor = page.cursor ?? undefined;
119
+ * } while (cursor);
120
+ */
121
+ markInboxAll(options: MarkNotifyInboxAllOptions): Promise<MarkNotifyInboxAllResponse>;
122
+ /**
123
+ * The sender's per-recipient delivery rollup for one send: who it reached and
124
+ * how far each recipient got. Metadata only — never the pointer or contacts.
125
+ *
126
+ * @example
127
+ * const { counts } = await sv.products.notify.getSendStatus(send.send_id);
128
+ */
129
+ getSendStatus(sendId: string): Promise<NotifySendStatus>;
130
+ /**
131
+ * The account's verified-interaction receipts (portable, JWKS-verifiable
132
+ * proofs), newest first. Follow `cursor` to page.
133
+ *
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.
138
+ *
139
+ * @example
140
+ * const { receipts, cursor } = await sv.products.notify.listReceipts({ interaction: 'approve' });
141
+ */
142
+ listReceipts(options?: ListNotifyReceiptsOptions): Promise<ListNotifyReceiptsResponse>;
143
+ /**
144
+ * Every receipt for one send, each attached to the recipient who produced it.
145
+ * The correlation scan is bounded: when `truncated` is true, some older
146
+ * receipts fall outside the scanned window — pass the returned `cursor` back in
147
+ * to resume the scan exactly where it stopped.
148
+ *
149
+ * @example
150
+ * const all: NotifySendReceipt[] = [];
151
+ * let cursor: string | undefined;
152
+ * do {
153
+ * const page = await sv.products.notify.getSendReceipts(send.send_id, { cursor });
154
+ * all.push(...page.receipts);
155
+ * cursor = page.truncated ? page.cursor ?? undefined : undefined;
156
+ * } while (cursor);
157
+ */
158
+ getSendReceipts(sendId: string, options?: {
159
+ cursor?: string;
160
+ }): Promise<NotifySendReceiptsResponse>;
161
+ /**
162
+ * The account's effective Notify config (secure defaults deep-merged with its
163
+ * overrides) plus the raw override delta, so an editor can show what is
164
+ * customized versus default.
165
+ *
166
+ * @example
167
+ * const { effective, overrides } = await sv.products.notify.getConfig();
168
+ */
169
+ getConfig(): Promise<NotifyConfigResponse>;
170
+ /**
171
+ * Merge a partial patch onto the account's config overrides. Owner-gated
172
+ * (`channel_credentials`) and unknown keys are rejected before any write.
173
+ *
174
+ * Delete a category by storing an explicit `null` TOMBSTONE — that is what keeps
175
+ * a seeded default from re-appearing on the next merge. The reserved `security`
176
+ * category can neither be removed nor made optional.
177
+ *
178
+ * @example
179
+ * await sv.products.notify.updateConfig({
180
+ * categories: {
181
+ * weekly_newsletter: { label: 'Weekly newsletter', required: false },
182
+ * marketing: null, // tombstone — remove the seeded default
183
+ * },
184
+ * });
185
+ */
186
+ updateConfig(patch: NotifyConfigPatch): Promise<NotifyConfigResponse>;
187
+ }
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';