@sparkvault/sdk-js 7.0.0 → 7.0.1

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.
@@ -22,7 +22,12 @@ export interface PasskeyResult {
22
22
  result?: VerifyResult;
23
23
  error?: string;
24
24
  errorType?: 'cancelled' | 'not_found' | 'not_allowed' | 'popup_blocked' | 'unknown';
25
- /** Machine-readable API error code (e.g. 'identity_locked'). */
25
+ /**
26
+ * Machine-readable API error code (e.g. 'identity_locked',
27
+ * 'identity_trial_exhausted'). Forwarded unchanged from the inline ceremony
28
+ * and the popup so the renderer can route blocked-Identity codes to the
29
+ * dedicated interstitial.
30
+ */
26
31
  errorCode?: string;
27
32
  }
28
33
  /**
@@ -16,6 +16,9 @@ export interface SparkLinkSendResult {
16
16
  /** Login-ceremony handle used to reclaim the result if the WebSocket is lost. */
17
17
  kindling?: string;
18
18
  error?: string;
19
+ /** Machine-readable API error code (e.g. 'identity_trial_exhausted'); routes a
20
+ * blocked Identity to the terminal interstitial instead of a retryable error. */
21
+ errorCode?: string;
19
22
  }
20
23
  /**
21
24
  * Handles SparkLink sending
@@ -15,6 +15,13 @@ export interface TotpSendResult {
15
15
  kindling?: string;
16
16
  expiresAt?: number;
17
17
  error?: string;
18
+ /**
19
+ * Machine-readable API error code (e.g. 'identity_trial_exhausted'). Set when
20
+ * the send-boundary gate refuses to dispatch a code because the owner's
21
+ * Identity access is blocked, so the renderer can show the interstitial
22
+ * instead of a generic "failed to send" error.
23
+ */
24
+ errorCode?: string;
18
25
  }
19
26
  /**
20
27
  * Result of TOTP verify operation
@@ -113,6 +113,14 @@ export declare class IdentityRenderer {
113
113
  * opening a popup would be blocked.
114
114
  */
115
115
  private handleMethodSelect;
116
+ /**
117
+ * If the error code means the site owner's Identity access is blocked
118
+ * (trial exhausted/expired, or paid capacity wall), render the dedicated
119
+ * end-user interstitial and return true. The message is intentionally
120
+ * generic so no billing internals leak to the end user. Returns false for
121
+ * any other code so the caller falls through to its normal handling.
122
+ */
123
+ private renderBlockedInterstitial;
116
124
  private handleTotpSubmit;
117
125
  private handleSecondFactorSubmit;
118
126
  private handleTotpResend;
@@ -4,6 +4,15 @@
4
4
  * Professional enterprise-quality error display with clear visual hierarchy.
5
5
  */
6
6
  import type { View } from './base';
7
+ /**
8
+ * Error codes that mean the site owner's Identity access is blocked — the
9
+ * free trial was exhausted or expired, or a paid plan hit its capacity wall.
10
+ * The end user can do nothing about these, so the ErrorView renders a friendly,
11
+ * non-leaky interstitial (no "Try Again", no debug code badge) exactly like
12
+ * `identity_locked`. The owner is nudged to subscribe through their own
13
+ * dashboard, never through this end-user surface.
14
+ */
15
+ export declare const IDENTITY_BLOCKED_ERROR_CODES: readonly ["identity_trial_exhausted", "identity_trial_expired", "identity_capacity_blocked"];
7
16
  export interface ErrorViewProps {
8
17
  message: string;
9
18
  code: string;
@@ -1715,9 +1715,11 @@ class TotpHandler {
1715
1715
  }
1716
1716
  catch (error) {
1717
1717
  const message = error instanceof Error ? error.message : 'Failed to send code';
1718
+ const errorCode = error instanceof SparkVaultError ? error.code : undefined;
1718
1719
  return {
1719
1720
  success: false,
1720
1721
  error: message,
1722
+ errorCode,
1721
1723
  };
1722
1724
  }
1723
1725
  }
@@ -1748,9 +1750,11 @@ class TotpHandler {
1748
1750
  }
1749
1751
  catch (error) {
1750
1752
  const message = error instanceof Error ? error.message : 'Failed to resend code';
1753
+ const errorCode = error instanceof SparkVaultError ? error.code : undefined;
1751
1754
  return {
1752
1755
  success: false,
1753
1756
  error: `Failed to resend: ${message}`,
1757
+ errorCode,
1754
1758
  };
1755
1759
  }
1756
1760
  }
@@ -1852,6 +1856,7 @@ class SparkLinkHandler {
1852
1856
  return {
1853
1857
  success: false,
1854
1858
  error: message,
1859
+ errorCode: error instanceof SparkVaultError ? error.code : undefined,
1855
1860
  };
1856
1861
  }
1857
1862
  }
@@ -5181,6 +5186,22 @@ class SparkLinkWaitingView {
5181
5186
  *
5182
5187
  * Professional enterprise-quality error display with clear visual hierarchy.
5183
5188
  */
5189
+ /**
5190
+ * Error codes that mean the site owner's Identity access is blocked — the
5191
+ * free trial was exhausted or expired, or a paid plan hit its capacity wall.
5192
+ * The end user can do nothing about these, so the ErrorView renders a friendly,
5193
+ * non-leaky interstitial (no "Try Again", no debug code badge) exactly like
5194
+ * `identity_locked`. The owner is nudged to subscribe through their own
5195
+ * dashboard, never through this end-user surface.
5196
+ */
5197
+ const IDENTITY_BLOCKED_ERROR_CODES = [
5198
+ 'identity_trial_exhausted',
5199
+ 'identity_trial_expired',
5200
+ 'identity_capacity_blocked',
5201
+ ];
5202
+ function isBlockedCode(code) {
5203
+ return IDENTITY_BLOCKED_ERROR_CODES.includes(code);
5204
+ }
5184
5205
  class ErrorView {
5185
5206
  constructor(props) {
5186
5207
  this.retryButton = null;
@@ -5204,15 +5225,26 @@ class ErrorView {
5204
5225
  // title, no debug error-code badge, and no "Try Again" (retrying the
5205
5226
  // login cannot clear a lockdown — only managing it at auth.sv can).
5206
5227
  const isLocked = this.props.code === 'identity_locked';
5228
+ // A blocked Identity (trial exhausted/expired, or paid capacity wall) is
5229
+ // likewise terminal for the end user: retrying cannot restore access, only
5230
+ // the site owner subscribing can. Show a friendly, non-leaky interstitial.
5231
+ const isBlocked = isBlockedCode(this.props.code);
5232
+ // Both states are terminal — suppress the debug code badge and the retry
5233
+ // button, leaving only Close.
5234
+ const isTerminal = isLocked || isBlocked;
5207
5235
  const title = document.createElement('h3');
5208
5236
  title.className = 'sv-error-title';
5209
- title.textContent = isLocked ? 'This SparkVault Identity is locked' : 'Something went wrong';
5237
+ title.textContent = isLocked
5238
+ ? 'This SparkVault Identity is locked'
5239
+ : isBlocked
5240
+ ? 'Sign-in unavailable'
5241
+ : 'Something went wrong';
5210
5242
  const message = document.createElement('p');
5211
5243
  message.className = 'sv-error-message';
5212
5244
  message.textContent = this.props.message;
5213
5245
  contentSection.appendChild(title);
5214
5246
  contentSection.appendChild(message);
5215
- if (!isLocked) {
5247
+ if (!isTerminal) {
5216
5248
  // Error code badge — useful for debugging genuine errors only.
5217
5249
  const codeBadge = document.createElement('div');
5218
5250
  codeBadge.className = 'sv-error-code-badge';
@@ -5229,7 +5261,7 @@ class ErrorView {
5229
5261
  // Action buttons with proper styling
5230
5262
  const buttonContainer = div();
5231
5263
  buttonContainer.className = 'sv-error-actions';
5232
- if (!isLocked) {
5264
+ if (!isTerminal) {
5233
5265
  this.retryButton = document.createElement('button');
5234
5266
  this.retryButton.className = 'sv-btn sv-btn-error-primary';
5235
5267
  this.retryButton.textContent = 'Try Again';
@@ -5696,6 +5728,13 @@ class OriginNotAllowedView {
5696
5728
  * Orchestrates view state and rendering for identity verification flows.
5697
5729
  * Uses extracted handlers for TOTP and Passkey operations.
5698
5730
  */
5731
+ /**
5732
+ * End-user copy for a blocked Identity. Intentionally generic — it never names
5733
+ * the trial, billing, usage, or any owner-facing internal. The site owner is
5734
+ * nudged to subscribe through their own dashboard and emails, not here.
5735
+ */
5736
+ const IDENTITY_BLOCKED_END_USER_MESSAGE = "This app's sign-in is temporarily unavailable. Please contact the site owner.";
5737
+ const BLOCKED_ERROR_CODES = new Set(IDENTITY_BLOCKED_ERROR_CODES);
5699
5738
  const SPARKLINK_CSP_BLOCKED_ERROR = {
5700
5739
  message: [
5701
5740
  'Connection blocked by security policy.',
@@ -6229,6 +6268,8 @@ class IdentityRenderer {
6229
6268
  this.setState({ view: 'loading' });
6230
6269
  const result = await this.totpHandler.send(totpMethod);
6231
6270
  if (!result.success) {
6271
+ if (this.renderBlockedInterstitial(result.errorCode))
6272
+ return;
6232
6273
  this.setState({
6233
6274
  view: 'error',
6234
6275
  message: result.error ?? 'Failed to send code',
@@ -6287,6 +6328,12 @@ class IdentityRenderer {
6287
6328
  const result = await this.sparkLinkHandler.send(wsResult.connectionId);
6288
6329
  if (!result.success) {
6289
6330
  this.cleanupSparkLink();
6331
+ // A blocked Identity (trial exhausted/expired, paid capacity) is
6332
+ // terminal — show the "sign-in unavailable" interstitial, not a
6333
+ // retryable "Try Again" that invites retrying a permanently-blocked
6334
+ // login. Mirrors the totp send path.
6335
+ if (this.renderBlockedInterstitial(result.errorCode))
6336
+ return;
6290
6337
  this.setState({
6291
6338
  view: 'error',
6292
6339
  message: result.error ?? 'Failed to send SparkLink',
@@ -6324,6 +6371,24 @@ class IdentityRenderer {
6324
6371
  this.handleErrorWithRecovery(error, 'unknown');
6325
6372
  }
6326
6373
  }
6374
+ /**
6375
+ * If the error code means the site owner's Identity access is blocked
6376
+ * (trial exhausted/expired, or paid capacity wall), render the dedicated
6377
+ * end-user interstitial and return true. The message is intentionally
6378
+ * generic so no billing internals leak to the end user. Returns false for
6379
+ * any other code so the caller falls through to its normal handling.
6380
+ */
6381
+ renderBlockedInterstitial(code) {
6382
+ if (!code || !BLOCKED_ERROR_CODES.has(code)) {
6383
+ return false;
6384
+ }
6385
+ this.setState({
6386
+ view: 'error',
6387
+ code,
6388
+ message: IDENTITY_BLOCKED_END_USER_MESSAGE,
6389
+ });
6390
+ return true;
6391
+ }
6327
6392
  async handleTotpSubmit(code) {
6328
6393
  if (this.viewState.view !== 'totp-verify')
6329
6394
  return;
@@ -6340,6 +6405,7 @@ class IdentityRenderer {
6340
6405
  if (result.success && result.result) {
6341
6406
  this.runPostLogin(result.result);
6342
6407
  }
6408
+ else if (this.renderBlockedInterstitial(result.errorCode)) ;
6343
6409
  else if (result.errorCode === 'identity_locked') {
6344
6410
  // The identity is locked down — a dedicated, actionable state, not a
6345
6411
  // generic "invalid code" retry. The person must manage it at auth.sv.
@@ -6420,6 +6486,8 @@ class IdentityRenderer {
6420
6486
  const currentMethod = this.verificationState.totp.method ?? 'email';
6421
6487
  const result = await this.totpHandler.resend();
6422
6488
  if (!result.success) {
6489
+ if (this.renderBlockedInterstitial(result.errorCode))
6490
+ return;
6423
6491
  this.setState({
6424
6492
  view: 'totp-verify',
6425
6493
  email: this.recipient,
@@ -6462,6 +6530,7 @@ class IdentityRenderer {
6462
6530
  navigateWith(this.options, result.result.redirect);
6463
6531
  }
6464
6532
  }
6533
+ else if (this.renderBlockedInterstitial(result.errorCode)) ;
6465
6534
  else if (result.errorCode === 'identity_locked') {
6466
6535
  // Dedicated state — retrying cannot unlock the identity.
6467
6536
  this.setState({
@@ -7101,6 +7170,8 @@ class IdentityRenderer {
7101
7170
  this.setState({ view: 'loading' });
7102
7171
  const result = await this.totpHandler.send('email');
7103
7172
  if (!result.success) {
7173
+ if (this.renderBlockedInterstitial(result.errorCode))
7174
+ return;
7104
7175
  this.setState({
7105
7176
  view: 'error',
7106
7177
  message: result.error ?? 'Failed to send code',