@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.
@@ -1711,9 +1711,11 @@ class TotpHandler {
1711
1711
  }
1712
1712
  catch (error) {
1713
1713
  const message = error instanceof Error ? error.message : 'Failed to send code';
1714
+ const errorCode = error instanceof SparkVaultError ? error.code : undefined;
1714
1715
  return {
1715
1716
  success: false,
1716
1717
  error: message,
1718
+ errorCode,
1717
1719
  };
1718
1720
  }
1719
1721
  }
@@ -1744,9 +1746,11 @@ class TotpHandler {
1744
1746
  }
1745
1747
  catch (error) {
1746
1748
  const message = error instanceof Error ? error.message : 'Failed to resend code';
1749
+ const errorCode = error instanceof SparkVaultError ? error.code : undefined;
1747
1750
  return {
1748
1751
  success: false,
1749
1752
  error: `Failed to resend: ${message}`,
1753
+ errorCode,
1750
1754
  };
1751
1755
  }
1752
1756
  }
@@ -1848,6 +1852,7 @@ class SparkLinkHandler {
1848
1852
  return {
1849
1853
  success: false,
1850
1854
  error: message,
1855
+ errorCode: error instanceof SparkVaultError ? error.code : undefined,
1851
1856
  };
1852
1857
  }
1853
1858
  }
@@ -5177,6 +5182,22 @@ class SparkLinkWaitingView {
5177
5182
  *
5178
5183
  * Professional enterprise-quality error display with clear visual hierarchy.
5179
5184
  */
5185
+ /**
5186
+ * Error codes that mean the site owner's Identity access is blocked — the
5187
+ * free trial was exhausted or expired, or a paid plan hit its capacity wall.
5188
+ * The end user can do nothing about these, so the ErrorView renders a friendly,
5189
+ * non-leaky interstitial (no "Try Again", no debug code badge) exactly like
5190
+ * `identity_locked`. The owner is nudged to subscribe through their own
5191
+ * dashboard, never through this end-user surface.
5192
+ */
5193
+ const IDENTITY_BLOCKED_ERROR_CODES = [
5194
+ 'identity_trial_exhausted',
5195
+ 'identity_trial_expired',
5196
+ 'identity_capacity_blocked',
5197
+ ];
5198
+ function isBlockedCode(code) {
5199
+ return IDENTITY_BLOCKED_ERROR_CODES.includes(code);
5200
+ }
5180
5201
  class ErrorView {
5181
5202
  constructor(props) {
5182
5203
  this.retryButton = null;
@@ -5200,15 +5221,26 @@ class ErrorView {
5200
5221
  // title, no debug error-code badge, and no "Try Again" (retrying the
5201
5222
  // login cannot clear a lockdown — only managing it at auth.sv can).
5202
5223
  const isLocked = this.props.code === 'identity_locked';
5224
+ // A blocked Identity (trial exhausted/expired, or paid capacity wall) is
5225
+ // likewise terminal for the end user: retrying cannot restore access, only
5226
+ // the site owner subscribing can. Show a friendly, non-leaky interstitial.
5227
+ const isBlocked = isBlockedCode(this.props.code);
5228
+ // Both states are terminal — suppress the debug code badge and the retry
5229
+ // button, leaving only Close.
5230
+ const isTerminal = isLocked || isBlocked;
5203
5231
  const title = document.createElement('h3');
5204
5232
  title.className = 'sv-error-title';
5205
- title.textContent = isLocked ? 'This SparkVault Identity is locked' : 'Something went wrong';
5233
+ title.textContent = isLocked
5234
+ ? 'This SparkVault Identity is locked'
5235
+ : isBlocked
5236
+ ? 'Sign-in unavailable'
5237
+ : 'Something went wrong';
5206
5238
  const message = document.createElement('p');
5207
5239
  message.className = 'sv-error-message';
5208
5240
  message.textContent = this.props.message;
5209
5241
  contentSection.appendChild(title);
5210
5242
  contentSection.appendChild(message);
5211
- if (!isLocked) {
5243
+ if (!isTerminal) {
5212
5244
  // Error code badge — useful for debugging genuine errors only.
5213
5245
  const codeBadge = document.createElement('div');
5214
5246
  codeBadge.className = 'sv-error-code-badge';
@@ -5225,7 +5257,7 @@ class ErrorView {
5225
5257
  // Action buttons with proper styling
5226
5258
  const buttonContainer = div();
5227
5259
  buttonContainer.className = 'sv-error-actions';
5228
- if (!isLocked) {
5260
+ if (!isTerminal) {
5229
5261
  this.retryButton = document.createElement('button');
5230
5262
  this.retryButton.className = 'sv-btn sv-btn-error-primary';
5231
5263
  this.retryButton.textContent = 'Try Again';
@@ -5692,6 +5724,13 @@ class OriginNotAllowedView {
5692
5724
  * Orchestrates view state and rendering for identity verification flows.
5693
5725
  * Uses extracted handlers for TOTP and Passkey operations.
5694
5726
  */
5727
+ /**
5728
+ * End-user copy for a blocked Identity. Intentionally generic — it never names
5729
+ * the trial, billing, usage, or any owner-facing internal. The site owner is
5730
+ * nudged to subscribe through their own dashboard and emails, not here.
5731
+ */
5732
+ const IDENTITY_BLOCKED_END_USER_MESSAGE = "This app's sign-in is temporarily unavailable. Please contact the site owner.";
5733
+ const BLOCKED_ERROR_CODES = new Set(IDENTITY_BLOCKED_ERROR_CODES);
5695
5734
  const SPARKLINK_CSP_BLOCKED_ERROR = {
5696
5735
  message: [
5697
5736
  'Connection blocked by security policy.',
@@ -6225,6 +6264,8 @@ class IdentityRenderer {
6225
6264
  this.setState({ view: 'loading' });
6226
6265
  const result = await this.totpHandler.send(totpMethod);
6227
6266
  if (!result.success) {
6267
+ if (this.renderBlockedInterstitial(result.errorCode))
6268
+ return;
6228
6269
  this.setState({
6229
6270
  view: 'error',
6230
6271
  message: result.error ?? 'Failed to send code',
@@ -6283,6 +6324,12 @@ class IdentityRenderer {
6283
6324
  const result = await this.sparkLinkHandler.send(wsResult.connectionId);
6284
6325
  if (!result.success) {
6285
6326
  this.cleanupSparkLink();
6327
+ // A blocked Identity (trial exhausted/expired, paid capacity) is
6328
+ // terminal — show the "sign-in unavailable" interstitial, not a
6329
+ // retryable "Try Again" that invites retrying a permanently-blocked
6330
+ // login. Mirrors the totp send path.
6331
+ if (this.renderBlockedInterstitial(result.errorCode))
6332
+ return;
6286
6333
  this.setState({
6287
6334
  view: 'error',
6288
6335
  message: result.error ?? 'Failed to send SparkLink',
@@ -6320,6 +6367,24 @@ class IdentityRenderer {
6320
6367
  this.handleErrorWithRecovery(error, 'unknown');
6321
6368
  }
6322
6369
  }
6370
+ /**
6371
+ * If the error code means the site owner's Identity access is blocked
6372
+ * (trial exhausted/expired, or paid capacity wall), render the dedicated
6373
+ * end-user interstitial and return true. The message is intentionally
6374
+ * generic so no billing internals leak to the end user. Returns false for
6375
+ * any other code so the caller falls through to its normal handling.
6376
+ */
6377
+ renderBlockedInterstitial(code) {
6378
+ if (!code || !BLOCKED_ERROR_CODES.has(code)) {
6379
+ return false;
6380
+ }
6381
+ this.setState({
6382
+ view: 'error',
6383
+ code,
6384
+ message: IDENTITY_BLOCKED_END_USER_MESSAGE,
6385
+ });
6386
+ return true;
6387
+ }
6323
6388
  async handleTotpSubmit(code) {
6324
6389
  if (this.viewState.view !== 'totp-verify')
6325
6390
  return;
@@ -6336,6 +6401,7 @@ class IdentityRenderer {
6336
6401
  if (result.success && result.result) {
6337
6402
  this.runPostLogin(result.result);
6338
6403
  }
6404
+ else if (this.renderBlockedInterstitial(result.errorCode)) ;
6339
6405
  else if (result.errorCode === 'identity_locked') {
6340
6406
  // The identity is locked down — a dedicated, actionable state, not a
6341
6407
  // generic "invalid code" retry. The person must manage it at auth.sv.
@@ -6416,6 +6482,8 @@ class IdentityRenderer {
6416
6482
  const currentMethod = this.verificationState.totp.method ?? 'email';
6417
6483
  const result = await this.totpHandler.resend();
6418
6484
  if (!result.success) {
6485
+ if (this.renderBlockedInterstitial(result.errorCode))
6486
+ return;
6419
6487
  this.setState({
6420
6488
  view: 'totp-verify',
6421
6489
  email: this.recipient,
@@ -6458,6 +6526,7 @@ class IdentityRenderer {
6458
6526
  navigateWith(this.options, result.result.redirect);
6459
6527
  }
6460
6528
  }
6529
+ else if (this.renderBlockedInterstitial(result.errorCode)) ;
6461
6530
  else if (result.errorCode === 'identity_locked') {
6462
6531
  // Dedicated state — retrying cannot unlock the identity.
6463
6532
  this.setState({
@@ -7097,6 +7166,8 @@ class IdentityRenderer {
7097
7166
  this.setState({ view: 'loading' });
7098
7167
  const result = await this.totpHandler.send('email');
7099
7168
  if (!result.success) {
7169
+ if (this.renderBlockedInterstitial(result.errorCode))
7170
+ return;
7100
7171
  this.setState({
7101
7172
  view: 'error',
7102
7173
  message: result.error ?? 'Failed to send code',