@sparkvault/sdk-js 2.2.2 → 2.2.4

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.
package/dist/errors.d.ts CHANGED
@@ -16,6 +16,29 @@ export declare class AuthorizationError extends SparkVaultError {
16
16
  export declare class ValidationError extends SparkVaultError {
17
17
  constructor(message: string, details?: Record<string, unknown>);
18
18
  }
19
+ /**
20
+ * The pooled-capacity resource a quota gate refers to.
21
+ * Storage and bandwidth gates surface low-capacity nudges and CTAs; seats and
22
+ * identity gate issuance (invites, DVAKs).
23
+ */
24
+ export type QuotaResource = 'storage' | 'bandwidth' | 'seats' | 'identity';
25
+ /**
26
+ * Plan required gate (402 PLAN_REQUIRED) — the account has no active
27
+ * subscription and attempted a billable/create action. Surface a subscribe CTA
28
+ * to admins, or "ask your account admin" to members.
29
+ */
30
+ export declare class PlanRequiredError extends SparkVaultError {
31
+ constructor(message: string, details?: Record<string, unknown>);
32
+ }
33
+ /**
34
+ * Quota exceeded gate (402 QUOTA_EXCEEDED) — a pooled-capacity or seat limit is
35
+ * exhausted. `resource` identifies which pool so callers can branch on the CTA
36
+ * (add a capacity block for storage/bandwidth, free a seat for seats).
37
+ */
38
+ export declare class QuotaExceededError extends SparkVaultError {
39
+ readonly resource?: QuotaResource;
40
+ constructor(message: string, details?: Record<string, unknown>);
41
+ }
19
42
  export declare class NetworkError extends SparkVaultError {
20
43
  constructor(message: string, details?: Record<string, unknown>);
21
44
  }
package/dist/http.d.ts CHANGED
@@ -8,8 +8,40 @@ export interface RequestOptions {
8
8
  body?: unknown;
9
9
  timeout?: number;
10
10
  }
11
+ /** Capacity state for a pool, driving low-capacity nudges in the UI. */
12
+ export type PoolState = 'ok' | 'notice' | 'warning' | 'exhausted';
13
+ /** Shared storage-pool capacity snapshot carried on `meta.pools`. */
14
+ export interface StoragePool {
15
+ used_gb: number;
16
+ limit_gb: number;
17
+ pct: number;
18
+ state: PoolState;
19
+ }
20
+ /** Shared bandwidth-pool capacity snapshot carried on `meta.pools`. */
21
+ export interface BandwidthPool {
22
+ used_gb: number;
23
+ limit_gb: number;
24
+ pct: number;
25
+ state: PoolState;
26
+ /** ISO timestamp when the bandwidth cycle resets. */
27
+ cycle_resets_at: string;
28
+ }
29
+ /** Pooled-capacity snapshot that rides on every response's `meta`. */
30
+ export interface PoolsMeta {
31
+ storage: StoragePool;
32
+ bandwidth: BandwidthPool;
33
+ }
34
+ /**
35
+ * Response envelope metadata. `pools` rides on responses so clients can render
36
+ * low-capacity nudges without a separate fetch. Unknown fields are preserved.
37
+ */
38
+ export interface ResponseMeta {
39
+ pools?: PoolsMeta;
40
+ [key: string]: unknown;
41
+ }
11
42
  export interface ApiResponse<T = unknown> {
12
43
  data: T;
44
+ meta?: ResponseMeta;
13
45
  status: number;
14
46
  headers: Headers;
15
47
  }
@@ -22,6 +54,11 @@ export declare class HttpClient {
22
54
  private parseResponse;
23
55
  private createErrorFromResponse;
24
56
  private unwrapApiResponse;
57
+ /**
58
+ * Pull the `meta` envelope (carrying `pools` capacity snapshots) off a
59
+ * standard `{ data, meta }` response. Returns undefined for bare responses.
60
+ */
61
+ private extractResponseMeta;
25
62
  get<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
26
63
  post<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
27
64
  delete<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
@@ -7,7 +7,7 @@
7
7
  import type { ResolvedConfig } from '../config';
8
8
  import { SparkVaultApi } from '../api-base';
9
9
  import { SparkVaultError } from '../errors';
10
- import type { SdkConfig, TotpSendResponse, TotpVerifyResponse, PasskeyChallengeResponse, PasskeyVerifyResponse, SecondFactorVerifyResponse, SparkLinkSendResponse, AuthContext } from './types';
10
+ import type { SdkConfig, TotpSendResponse, TotpVerifyResponse, PasskeyChallengeResponse, PasskeyVerifyResponse, SecondFactorVerifyResponse, SparkLinkSendResponse, AuthContext, VerifyResult } from './types';
11
11
  export declare class IdentityApi extends SparkVaultApi {
12
12
  private readonly config;
13
13
  /** Cached config promise - allows preloading and deduplication */
@@ -113,6 +113,14 @@ export declare class IdentityApi extends SparkVaultApi {
113
113
  * Includes connectionId for WebSocket push notification of verification result.
114
114
  */
115
115
  sendSparkLink(email: string, connectionId: string, authContext?: AuthContext): Promise<SparkLinkSendResponse>;
116
+ /**
117
+ * Claim the SparkLink verification result by kindling — the WebSocket-loss
118
+ * fallback. The SDK calls this when its socket was suspended with the tab and
119
+ * it refocuses. Returns the verified result, or null while still pending (not
120
+ * yet clicked) or already consumed. The read burns the server-side spark, so
121
+ * the result can be claimed exactly once.
122
+ */
123
+ consumeSparkLinkResult(kindling: string): Promise<VerifyResult | null>;
116
124
  }
117
125
  export declare class IdentityApiError extends SparkVaultError {
118
126
  constructor(message: string, code: string, statusCode: number, details?: Record<string, unknown>);
@@ -13,6 +13,8 @@ export interface SparkLinkSendResult {
13
13
  success: boolean;
14
14
  sparkId?: string;
15
15
  expiresAt?: number;
16
+ /** Login-ceremony handle used to reclaim the result if the WebSocket is lost. */
17
+ kindling?: string;
16
18
  error?: string;
17
19
  }
18
20
  /**
@@ -24,6 +24,10 @@ export declare class IdentityRenderer {
24
24
  private currentView;
25
25
  private focusTimeoutId;
26
26
  private sparkLinkWs;
27
+ private sparkLinkKindling;
28
+ private sparkLinkVisibilityHandler;
29
+ private sparkLinkClaiming;
30
+ private sparkLinkRetryTimer;
27
31
  constructor(container: Container, api: IdentityApi, options: VerifyOptions, callbacks: RendererCallbacks);
28
32
  /**
29
33
  * Fire the host's onSuccess callback, swallowing any exception so a
@@ -169,6 +173,23 @@ export declare class IdentityRenderer {
169
173
  * delegate navigation entirely to the SDK.
170
174
  */
171
175
  private handleSparkLinkVerified;
176
+ /**
177
+ * Arm the WebSocket-loss fallback for the waiting screen.
178
+ *
179
+ * While waiting for the emailed link, the socket can be dropped when the tab
180
+ * is suspended (mobile: the user leaves to the mail app). On refocus, if the
181
+ * socket is no longer open, reclaim the verified result once by kindling. A
182
+ * single ~2s retry covers returning before the server finished writing it.
183
+ * Deliberately NOT a polling loop — it fires only on refocus, and only when
184
+ * the socket is actually gone.
185
+ */
186
+ private armSparkLinkRefocusClaim;
187
+ /**
188
+ * Reclaim the verified result by kindling. Single attempt; if still pending
189
+ * and allowRetry, schedule exactly one ~2s retry, then stop (the next refocus
190
+ * or Resend can try again).
191
+ */
192
+ private claimSparkLinkResult;
172
193
  /**
173
194
  * Clean up SparkLink WebSocket connection.
174
195
  */
@@ -237,6 +237,8 @@ export interface SecondFactorVerifyResponse {
237
237
  export interface SparkLinkSendResponse {
238
238
  sparkId: string;
239
239
  expiresAt: number;
240
+ /** Login-ceremony handle for the WebSocket-loss fallback claim (see api.consumeSparkLinkResult). */
241
+ kindling?: string;
240
242
  }
241
243
  export type IdentityViewState = {
242
244
  view: 'loading';
package/dist/index.d.ts CHANGED
@@ -205,6 +205,29 @@ declare class AuthorizationError extends SparkVaultError {
205
205
  declare class ValidationError extends SparkVaultError {
206
206
  constructor(message: string, details?: Record<string, unknown>);
207
207
  }
208
+ /**
209
+ * The pooled-capacity resource a quota gate refers to.
210
+ * Storage and bandwidth gates surface low-capacity nudges and CTAs; seats and
211
+ * identity gate issuance (invites, DVAKs).
212
+ */
213
+ type QuotaResource = 'storage' | 'bandwidth' | 'seats' | 'identity';
214
+ /**
215
+ * Plan required gate (402 PLAN_REQUIRED) — the account has no active
216
+ * subscription and attempted a billable/create action. Surface a subscribe CTA
217
+ * to admins, or "ask your account admin" to members.
218
+ */
219
+ declare class PlanRequiredError extends SparkVaultError {
220
+ constructor(message: string, details?: Record<string, unknown>);
221
+ }
222
+ /**
223
+ * Quota exceeded gate (402 QUOTA_EXCEEDED) — a pooled-capacity or seat limit is
224
+ * exhausted. `resource` identifies which pool so callers can branch on the CTA
225
+ * (add a capacity block for storage/bandwidth, free a seat for seats).
226
+ */
227
+ declare class QuotaExceededError extends SparkVaultError {
228
+ readonly resource?: QuotaResource;
229
+ constructor(message: string, details?: Record<string, unknown>);
230
+ }
208
231
  declare class NetworkError extends SparkVaultError {
209
232
  constructor(message: string, details?: Record<string, unknown>);
210
233
  }
@@ -335,8 +358,40 @@ interface RequestOptions {
335
358
  body?: unknown;
336
359
  timeout?: number;
337
360
  }
361
+ /** Capacity state for a pool, driving low-capacity nudges in the UI. */
362
+ type PoolState = 'ok' | 'notice' | 'warning' | 'exhausted';
363
+ /** Shared storage-pool capacity snapshot carried on `meta.pools`. */
364
+ interface StoragePool {
365
+ used_gb: number;
366
+ limit_gb: number;
367
+ pct: number;
368
+ state: PoolState;
369
+ }
370
+ /** Shared bandwidth-pool capacity snapshot carried on `meta.pools`. */
371
+ interface BandwidthPool {
372
+ used_gb: number;
373
+ limit_gb: number;
374
+ pct: number;
375
+ state: PoolState;
376
+ /** ISO timestamp when the bandwidth cycle resets. */
377
+ cycle_resets_at: string;
378
+ }
379
+ /** Pooled-capacity snapshot that rides on every response's `meta`. */
380
+ interface PoolsMeta {
381
+ storage: StoragePool;
382
+ bandwidth: BandwidthPool;
383
+ }
384
+ /**
385
+ * Response envelope metadata. `pools` rides on responses so clients can render
386
+ * low-capacity nudges without a separate fetch. Unknown fields are preserved.
387
+ */
388
+ interface ResponseMeta {
389
+ pools?: PoolsMeta;
390
+ [key: string]: unknown;
391
+ }
338
392
  interface ApiResponse<T = unknown> {
339
393
  data: T;
394
+ meta?: ResponseMeta;
340
395
  status: number;
341
396
  headers: Headers;
342
397
  }
@@ -349,6 +404,11 @@ declare class HttpClient {
349
404
  private parseResponse;
350
405
  private createErrorFromResponse;
351
406
  private unwrapApiResponse;
407
+ /**
408
+ * Pull the `meta` envelope (carrying `pools` capacity snapshots) off a
409
+ * standard `{ data, meta }` response. Returns undefined for bare responses.
410
+ */
411
+ private extractResponseMeta;
352
412
  get<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
353
413
  post<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
354
414
  delete<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
@@ -792,5 +852,5 @@ declare global {
792
852
  }
793
853
  }
794
854
 
795
- export { AuthenticationError, AuthorizationError, NetworkError, PopupBlockedError, SparkVault, SparkVaultError, TimeoutError, UserCancelledError, ValidationError, SparkVault as default, logger, setDebugMode };
796
- export type { AuthMethod, CreateVaultOptions, CreatedIngot, HealthCheckOptions, HealthCheckResult, AttachOptions as IdentityAttachOptions, Ingot, SparkVaultConfig, Theme, TokenClaims, UnsealedVault, UploadAttachOptions, UploadBranding, UploadIngotOptions, UploadOptions, UploadProgress, UploadResult, Vault, VaultSummary, VaultUploadConfig, VerifyOptions, VerifyResult };
855
+ export { AuthenticationError, AuthorizationError, NetworkError, PlanRequiredError, PopupBlockedError, QuotaExceededError, SparkVault, SparkVaultError, TimeoutError, UserCancelledError, ValidationError, SparkVault as default, logger, setDebugMode };
856
+ export type { ApiResponse, AuthMethod, BandwidthPool, CreateVaultOptions, CreatedIngot, HealthCheckOptions, HealthCheckResult, AttachOptions as IdentityAttachOptions, Ingot, PoolState, PoolsMeta, QuotaResource, ResponseMeta, SparkVaultConfig, StoragePool, Theme, TokenClaims, UnsealedVault, UploadAttachOptions, UploadBranding, UploadIngotOptions, UploadOptions, UploadProgress, UploadResult, Vault, VaultSummary, VaultUploadConfig, VerifyOptions, VerifyResult };
@@ -36,6 +36,38 @@ class ValidationError extends SparkVaultError {
36
36
  Object.setPrototypeOf(this, ValidationError.prototype);
37
37
  }
38
38
  }
39
+ /**
40
+ * Plan required gate (402 PLAN_REQUIRED) — the account has no active
41
+ * subscription and attempted a billable/create action. Surface a subscribe CTA
42
+ * to admins, or "ask your account admin" to members.
43
+ */
44
+ class PlanRequiredError extends SparkVaultError {
45
+ constructor(message, details) {
46
+ super(message, 'PLAN_REQUIRED', 402, details);
47
+ this.name = 'PlanRequiredError';
48
+ Object.setPrototypeOf(this, PlanRequiredError.prototype);
49
+ }
50
+ }
51
+ /**
52
+ * Quota exceeded gate (402 QUOTA_EXCEEDED) — a pooled-capacity or seat limit is
53
+ * exhausted. `resource` identifies which pool so callers can branch on the CTA
54
+ * (add a capacity block for storage/bandwidth, free a seat for seats).
55
+ */
56
+ class QuotaExceededError extends SparkVaultError {
57
+ constructor(message, details) {
58
+ super(message, 'QUOTA_EXCEEDED', 402, details);
59
+ this.name = 'QuotaExceededError';
60
+ const resource = details?.resource;
61
+ this.resource =
62
+ resource === 'storage' ||
63
+ resource === 'bandwidth' ||
64
+ resource === 'seats' ||
65
+ resource === 'identity'
66
+ ? resource
67
+ : undefined;
68
+ Object.setPrototypeOf(this, QuotaExceededError.prototype);
69
+ }
70
+ }
39
71
  class NetworkError extends SparkVaultError {
40
72
  constructor(message, details) {
41
73
  super(message, 'network_error', undefined, details);
@@ -209,6 +241,7 @@ class HttpClient {
209
241
  }
210
242
  return {
211
243
  data: this.unwrapApiResponse(parsed),
244
+ meta: this.extractResponseMeta(parsed),
212
245
  status: response.status,
213
246
  headers: response.headers,
214
247
  };
@@ -269,6 +302,11 @@ class HttpClient {
269
302
  return new ValidationError(message, details);
270
303
  case 401:
271
304
  return new AuthenticationError(message, details);
305
+ case 402:
306
+ if (code === 'QUOTA_EXCEEDED')
307
+ return new QuotaExceededError(message, details);
308
+ // PLAN_REQUIRED is the canonical 402 gate; treat any other 402 as one too.
309
+ return new PlanRequiredError(message, details);
272
310
  case 403:
273
311
  return new AuthorizationError(message, details);
274
312
  default:
@@ -284,6 +322,19 @@ class HttpClient {
284
322
  }
285
323
  return data;
286
324
  }
325
+ /**
326
+ * Pull the `meta` envelope (carrying `pools` capacity snapshots) off a
327
+ * standard `{ data, meta }` response. Returns undefined for bare responses.
328
+ */
329
+ extractResponseMeta(data) {
330
+ if (typeof data === 'object' && data !== null) {
331
+ const record = data;
332
+ if (typeof record.meta === 'object' && record.meta !== null) {
333
+ return record.meta;
334
+ }
335
+ }
336
+ return undefined;
337
+ }
287
338
  get(path, options) {
288
339
  return this.request(path, { ...options, method: 'GET' });
289
340
  }
@@ -1043,6 +1094,28 @@ class IdentityApi extends SparkVaultApi {
1043
1094
  ...this.buildAuthContextParams(authContext),
1044
1095
  });
1045
1096
  }
1097
+ /**
1098
+ * Claim the SparkLink verification result by kindling — the WebSocket-loss
1099
+ * fallback. The SDK calls this when its socket was suspended with the tab and
1100
+ * it refocuses. Returns the verified result, or null while still pending (not
1101
+ * yet clicked) or already consumed. The read burns the server-side spark, so
1102
+ * the result can be claimed exactly once.
1103
+ */
1104
+ async consumeSparkLinkResult(kindling) {
1105
+ const data = await this.request('GET', `/sparklink/result?kindling=${encodeURIComponent(kindling)}`);
1106
+ if (!data || typeof data !== 'object' || typeof data.token !== 'string') {
1107
+ return null;
1108
+ }
1109
+ return {
1110
+ token: data.token,
1111
+ identity: data.identity,
1112
+ identityType: data.identityType || 'email',
1113
+ svid: typeof data.svid === 'string' ? data.svid : undefined,
1114
+ sessionId: typeof data.session_id === 'string' ? data.session_id : undefined,
1115
+ refreshToken: typeof data.refresh_token === 'string' ? data.refresh_token : undefined,
1116
+ redirect: typeof data.redirect === 'string' ? data.redirect : undefined,
1117
+ };
1118
+ }
1046
1119
  }
1047
1120
  class IdentityApiError extends SparkVaultError {
1048
1121
  constructor(message, code, statusCode, details) {
@@ -1795,6 +1868,7 @@ class SparkLinkHandler {
1795
1868
  success: true,
1796
1869
  sparkId: result.sparkId,
1797
1870
  expiresAt: result.expiresAt,
1871
+ kindling: result.kindling,
1798
1872
  };
1799
1873
  }
1800
1874
  catch (error) {
@@ -5533,6 +5607,13 @@ class IdentityRenderer {
5533
5607
  this.focusTimeoutId = null;
5534
5608
  // SparkLink WebSocket
5535
5609
  this.sparkLinkWs = null;
5610
+ // SparkLink WebSocket-loss fallback: the login kindling lets the SDK reclaim
5611
+ // the verified result if the socket was suspended with the tab (mobile). The
5612
+ // visibility handler fires the single re-check on refocus.
5613
+ this.sparkLinkKindling = null;
5614
+ this.sparkLinkVisibilityHandler = null;
5615
+ this.sparkLinkClaiming = false;
5616
+ this.sparkLinkRetryTimer = null;
5536
5617
  this.container = container;
5537
5618
  this.api = api;
5538
5619
  this.options = options;
@@ -5883,6 +5964,11 @@ class IdentityRenderer {
5883
5964
  * actual list of alternatives instead of bouncing back to passkey.
5884
5965
  */
5885
5966
  async showMethodSelect(options = {}) {
5967
+ // Leaving the SparkLink waiting view (e.g. "Choose another method") must
5968
+ // tear down its WebSocket + refocus listeners and clear the kindling, or a
5969
+ // later tab refocus would fire a stale claim for an abandoned flow.
5970
+ // Idempotent — a no-op when SparkLink was never armed.
5971
+ this.cleanupSparkLink();
5886
5972
  const autoRoute = options.autoRoute !== false;
5887
5973
  if (!this.sdkConfig)
5888
5974
  return;
@@ -6048,6 +6134,11 @@ class IdentityRenderer {
6048
6134
  });
6049
6135
  return;
6050
6136
  }
6137
+ // Arm the WebSocket-loss fallback: keep the kindling and re-check for
6138
+ // the result whenever the tab is brought back to the foreground with
6139
+ // a dead socket (the mobile email round-trip).
6140
+ this.sparkLinkKindling = result.kindling ?? null;
6141
+ this.armSparkLinkRefocusClaim();
6051
6142
  this.setState({
6052
6143
  view: 'sparklink-waiting',
6053
6144
  email: this.recipient,
@@ -6565,7 +6656,14 @@ class IdentityRenderer {
6565
6656
  * delegate navigation entirely to the SDK.
6566
6657
  */
6567
6658
  async handleSparkLinkVerified(result) {
6659
+ // Burn the server-side fallback spark so a completed login never leaves a
6660
+ // second claimable auth path floating around. Capture the kindling before
6661
+ // cleanup clears it; fire-and-forget (the WS path may already have it).
6662
+ const kindling = this.sparkLinkKindling;
6568
6663
  this.cleanupSparkLink();
6664
+ if (kindling) {
6665
+ void this.api.consumeSparkLinkResult(kindling).catch(() => { });
6666
+ }
6569
6667
  // Passkey upsell only when there's no redirect target — once we have
6570
6668
  // a destination we go there immediately, no upsell.
6571
6669
  if (!result.redirect && await this.shouldShowPasskeyPrompt()) {
@@ -6576,11 +6674,11 @@ class IdentityRenderer {
6576
6674
  });
6577
6675
  return;
6578
6676
  }
6579
- this.close();
6580
- // Hand the full result (including redirect) to the host first so the
6581
- // page-level handler can do app-specific work (logging, navigation,
6582
- // etc.) before we steal the browsing context with a navigation.
6677
+ // Hand the full result (including redirect) to the host BEFORE tearing down
6678
+ // the modal, so the host's onSuccess can act (logging, navigation) without
6679
+ // racing the teardown of the browsing context.
6583
6680
  this.safeOnSuccess(result);
6681
+ this.close();
6584
6682
  // SDK-side fallback navigation. If the host already navigated this is
6585
6683
  // a no-op (the document is already unloading); if not, this rescues
6586
6684
  // simple-mode flows whose host forgot to act on result.redirect.
@@ -6588,6 +6686,67 @@ class IdentityRenderer {
6588
6686
  navigateWith(this.options, result.redirect);
6589
6687
  }
6590
6688
  }
6689
+ /**
6690
+ * Arm the WebSocket-loss fallback for the waiting screen.
6691
+ *
6692
+ * While waiting for the emailed link, the socket can be dropped when the tab
6693
+ * is suspended (mobile: the user leaves to the mail app). On refocus, if the
6694
+ * socket is no longer open, reclaim the verified result once by kindling. A
6695
+ * single ~2s retry covers returning before the server finished writing it.
6696
+ * Deliberately NOT a polling loop — it fires only on refocus, and only when
6697
+ * the socket is actually gone.
6698
+ */
6699
+ armSparkLinkRefocusClaim() {
6700
+ if (this.sparkLinkVisibilityHandler || !this.sparkLinkKindling)
6701
+ return;
6702
+ if (typeof document === 'undefined')
6703
+ return;
6704
+ const handler = () => {
6705
+ if (typeof document !== 'undefined' && document.visibilityState !== 'visible')
6706
+ return;
6707
+ // Healthy socket → the push path owns completion; nothing to reclaim.
6708
+ if (this.sparkLinkWs && this.sparkLinkWs.readyState === WebSocket.OPEN)
6709
+ return;
6710
+ void this.claimSparkLinkResult(true);
6711
+ };
6712
+ this.sparkLinkVisibilityHandler = handler;
6713
+ document.addEventListener('visibilitychange', handler);
6714
+ if (typeof window !== 'undefined') {
6715
+ window.addEventListener('pageshow', handler);
6716
+ }
6717
+ }
6718
+ /**
6719
+ * Reclaim the verified result by kindling. Single attempt; if still pending
6720
+ * and allowRetry, schedule exactly one ~2s retry, then stop (the next refocus
6721
+ * or Resend can try again).
6722
+ */
6723
+ async claimSparkLinkResult(allowRetry) {
6724
+ const kindling = this.sparkLinkKindling;
6725
+ if (!kindling || this.sparkLinkClaiming)
6726
+ return;
6727
+ this.sparkLinkClaiming = true;
6728
+ let result = null;
6729
+ try {
6730
+ result = await this.api.consumeSparkLinkResult(kindling);
6731
+ }
6732
+ catch {
6733
+ result = null;
6734
+ }
6735
+ this.sparkLinkClaiming = false;
6736
+ if (result) {
6737
+ await this.handleSparkLinkVerified(result);
6738
+ return;
6739
+ }
6740
+ // Pending — the click may still be processing server-side. One short retry,
6741
+ // then stop. No ongoing polling. Tracked so cleanup can cancel it.
6742
+ if (allowRetry && this.sparkLinkKindling === kindling) {
6743
+ this.sparkLinkRetryTimer = setTimeout(() => {
6744
+ this.sparkLinkRetryTimer = null;
6745
+ if (this.sparkLinkKindling === kindling)
6746
+ void this.claimSparkLinkResult(false);
6747
+ }, 2000);
6748
+ }
6749
+ }
6591
6750
  /**
6592
6751
  * Clean up SparkLink WebSocket connection.
6593
6752
  */
@@ -6599,6 +6758,20 @@ class IdentityRenderer {
6599
6758
  this.sparkLinkWs.close();
6600
6759
  this.sparkLinkWs = null;
6601
6760
  }
6761
+ if (this.sparkLinkVisibilityHandler) {
6762
+ if (typeof document !== 'undefined') {
6763
+ document.removeEventListener('visibilitychange', this.sparkLinkVisibilityHandler);
6764
+ }
6765
+ if (typeof window !== 'undefined') {
6766
+ window.removeEventListener('pageshow', this.sparkLinkVisibilityHandler);
6767
+ }
6768
+ this.sparkLinkVisibilityHandler = null;
6769
+ }
6770
+ if (this.sparkLinkRetryTimer !== null) {
6771
+ clearTimeout(this.sparkLinkRetryTimer);
6772
+ this.sparkLinkRetryTimer = null;
6773
+ }
6774
+ this.sparkLinkKindling = null;
6602
6775
  }
6603
6776
  /**
6604
6777
  * Handle resending SparkLink.
@@ -6625,6 +6798,10 @@ class IdentityRenderer {
6625
6798
  }
6626
6799
  const result = await this.sparkLinkHandler.send(wsResult.connectionId);
6627
6800
  if (result.success) {
6801
+ // Re-arm the fallback against the resend's fresh kindling (openSparkLink-
6802
+ // WebSocket cleared the previous one).
6803
+ this.sparkLinkKindling = result.kindling ?? null;
6804
+ this.armSparkLinkRefocusClaim();
6628
6805
  this.setState({
6629
6806
  view: 'sparklink-waiting',
6630
6807
  email: this.recipient,
@@ -11178,7 +11355,9 @@ if (typeof window !== 'undefined') {
11178
11355
  exports.AuthenticationError = AuthenticationError;
11179
11356
  exports.AuthorizationError = AuthorizationError;
11180
11357
  exports.NetworkError = NetworkError;
11358
+ exports.PlanRequiredError = PlanRequiredError;
11181
11359
  exports.PopupBlockedError = PopupBlockedError;
11360
+ exports.QuotaExceededError = QuotaExceededError;
11182
11361
  exports.SparkVault = SparkVault;
11183
11362
  exports.SparkVaultError = SparkVaultError;
11184
11363
  exports.TimeoutError = TimeoutError;