@sparkvault/sdk-js 7.0.2 → 8.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.
@@ -884,20 +884,20 @@ class IdentityApi extends SparkVaultApi {
884
884
  return params;
885
885
  }
886
886
  /**
887
- * Send TOTP code to email or phone
887
+ * Send OTP code to email or phone
888
888
  */
889
- async sendTotp(params) {
890
- return this.request('POST', '/totp/send', {
889
+ async sendOtp(params) {
890
+ return this.request('POST', '/otp/send', {
891
891
  recipient: params.recipient,
892
892
  method: params.method,
893
893
  ...this.buildAuthContextParams(params.authContext),
894
894
  });
895
895
  }
896
896
  /**
897
- * Verify TOTP code
897
+ * Verify OTP code
898
898
  */
899
- async verifyTotp(params) {
900
- return this.request('POST', '/totp/verify', {
899
+ async verifyOtp(params) {
900
+ return this.request('POST', '/otp/verify', {
901
901
  kindling: params.kindling,
902
902
  pin: params.pin,
903
903
  recipient: params.recipient,
@@ -1133,25 +1133,25 @@ class IdentityApiError extends SparkVaultError {
1133
1133
  */
1134
1134
  const METHOD_REGISTRY = {
1135
1135
  // Core methods
1136
- totp_email: {
1137
- id: 'totp_email',
1138
- type: 'totp',
1136
+ otp_email: {
1137
+ id: 'otp_email',
1138
+ type: 'otp',
1139
1139
  identityType: 'email',
1140
1140
  name: 'Email code',
1141
1141
  description: 'Get a one-time code via email',
1142
1142
  icon: 'email',
1143
1143
  },
1144
- totp_sms: {
1145
- id: 'totp_sms',
1146
- type: 'totp',
1144
+ otp_sms: {
1145
+ id: 'otp_sms',
1146
+ type: 'otp',
1147
1147
  identityType: 'phone',
1148
1148
  name: 'Text message',
1149
1149
  description: 'Get a one-time code via SMS',
1150
1150
  icon: 'sms',
1151
1151
  },
1152
- totp_voice: {
1153
- id: 'totp_voice',
1154
- type: 'totp',
1152
+ otp_voice: {
1153
+ id: 'otp_voice',
1154
+ type: 'otp',
1155
1155
  identityType: 'phone',
1156
1156
  name: 'Voice call',
1157
1157
  description: 'Get a one-time code via phone call',
@@ -1267,8 +1267,8 @@ class VerificationState {
1267
1267
  isFallbackMode: false,
1268
1268
  pendingResult: null,
1269
1269
  };
1270
- // TOTP state
1271
- this._totp = {
1270
+ // OTP state
1271
+ this._otp = {
1272
1272
  kindling: '',
1273
1273
  method: null,
1274
1274
  };
@@ -1327,15 +1327,15 @@ class VerificationState {
1327
1327
  setPendingResult(result) {
1328
1328
  this._passkey.pendingResult = result;
1329
1329
  }
1330
- // --- TOTP State ---
1331
- get totp() {
1332
- return this._totp;
1330
+ // --- OTP State ---
1331
+ get otp() {
1332
+ return this._otp;
1333
1333
  }
1334
1334
  setKindling(kindling) {
1335
- this._totp.kindling = kindling;
1335
+ this._otp.kindling = kindling;
1336
1336
  }
1337
- setTotpMethod(method) {
1338
- this._totp.method = method;
1337
+ setOtpMethod(method) {
1338
+ this._otp.method = method;
1339
1339
  }
1340
1340
  }
1341
1341
 
@@ -1682,32 +1682,32 @@ class PasskeyHandler {
1682
1682
  }
1683
1683
 
1684
1684
  /**
1685
- * TOTP Handler
1685
+ * OTP Handler
1686
1686
  *
1687
- * Single responsibility: TOTP code sending and verification.
1688
- * Extracts TOTP logic from IdentityRenderer for better separation of concerns.
1687
+ * Single responsibility: OTP code sending and verification.
1688
+ * Extracts OTP logic from IdentityRenderer for better separation of concerns.
1689
1689
  */
1690
1690
  /**
1691
- * Handles TOTP code sending and verification
1691
+ * Handles OTP code sending and verification
1692
1692
  */
1693
- class TotpHandler {
1693
+ class OtpHandler {
1694
1694
  constructor(api, state) {
1695
1695
  this.api = api;
1696
1696
  this.state = state;
1697
1697
  }
1698
1698
  /**
1699
- * Send TOTP code via email, SMS, or voice
1699
+ * Send OTP code via email, SMS, or voice
1700
1700
  */
1701
1701
  async send(method) {
1702
1702
  try {
1703
- const response = await this.api.sendTotp({
1703
+ const response = await this.api.sendOtp({
1704
1704
  recipient: this.state.recipient,
1705
1705
  method,
1706
1706
  authContext: this.state.authContext,
1707
1707
  });
1708
1708
  // Update state with kindling
1709
1709
  this.state.setKindling(response.kindling);
1710
- this.state.setTotpMethod(method);
1710
+ this.state.setOtpMethod(method);
1711
1711
  return {
1712
1712
  success: true,
1713
1713
  kindling: response.kindling,
@@ -1725,18 +1725,18 @@ class TotpHandler {
1725
1725
  }
1726
1726
  }
1727
1727
  /**
1728
- * Resend TOTP code
1728
+ * Resend OTP code
1729
1729
  */
1730
1730
  async resend() {
1731
- const method = this.state.totp.method;
1731
+ const method = this.state.otp.method;
1732
1732
  if (!method) {
1733
1733
  return {
1734
1734
  success: false,
1735
- error: 'No TOTP method set',
1735
+ error: 'No OTP method set',
1736
1736
  };
1737
1737
  }
1738
1738
  try {
1739
- const response = await this.api.sendTotp({
1739
+ const response = await this.api.sendOtp({
1740
1740
  recipient: this.state.recipient,
1741
1741
  method,
1742
1742
  authContext: this.state.authContext,
@@ -1760,10 +1760,10 @@ class TotpHandler {
1760
1760
  }
1761
1761
  }
1762
1762
  /**
1763
- * Verify TOTP code
1763
+ * Verify OTP code
1764
1764
  */
1765
1765
  async verify(code) {
1766
- const kindling = this.state.totp.kindling;
1766
+ const kindling = this.state.otp.kindling;
1767
1767
  if (!kindling) {
1768
1768
  return {
1769
1769
  success: false,
@@ -1771,7 +1771,7 @@ class TotpHandler {
1771
1771
  };
1772
1772
  }
1773
1773
  try {
1774
- const response = await this.api.verifyTotp({
1774
+ const response = await this.api.verifyOtp({
1775
1775
  kindling,
1776
1776
  pin: code,
1777
1777
  recipient: this.state.recipient,
@@ -2306,17 +2306,17 @@ function getStyles(options) {
2306
2306
  }
2307
2307
 
2308
2308
  /* ========================================
2309
- TOTP INPUT
2309
+ OTP INPUT
2310
2310
  ======================================== */
2311
2311
 
2312
- .sv-totp-input-group {
2312
+ .sv-otp-input-group {
2313
2313
  display: flex;
2314
2314
  gap: 8px;
2315
2315
  justify-content: center;
2316
2316
  margin-bottom: 16px;
2317
2317
  }
2318
2318
 
2319
- .sv-totp-digit {
2319
+ .sv-otp-digit {
2320
2320
  width: 44px;
2321
2321
  height: 52px;
2322
2322
  text-align: center;
@@ -2331,17 +2331,17 @@ function getStyles(options) {
2331
2331
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
2332
2332
  }
2333
2333
 
2334
- .sv-totp-digit:hover:not(:focus):not(:disabled) {
2334
+ .sv-otp-digit:hover:not(:focus):not(:disabled) {
2335
2335
  border-color: ${tokens.borderHover};
2336
2336
  }
2337
2337
 
2338
- .sv-totp-digit:focus {
2338
+ .sv-otp-digit:focus {
2339
2339
  outline: none;
2340
2340
  border-color: ${tokens.borderFocus};
2341
2341
  box-shadow: 0 0 0 3px ${tokens.primaryLight};
2342
2342
  }
2343
2343
 
2344
- .sv-totp-digit:disabled {
2344
+ .sv-otp-digit:disabled {
2345
2345
  opacity: 0.5;
2346
2346
  cursor: not-allowed;
2347
2347
  }
@@ -2851,7 +2851,7 @@ function getStyles(options) {
2851
2851
  }
2852
2852
 
2853
2853
  /* ========================================
2854
- TOTP VIEW
2854
+ OTP VIEW
2855
2855
  ======================================== */
2856
2856
 
2857
2857
  .sv-resend-container {
@@ -3164,7 +3164,7 @@ function getStyles(options) {
3164
3164
  padding: 24px 28px;
3165
3165
  }
3166
3166
 
3167
- .sv-totp-digit {
3167
+ .sv-otp-digit {
3168
3168
  width: 40px;
3169
3169
  height: 48px;
3170
3170
  font-size: 18px;
@@ -3176,11 +3176,11 @@ function getStyles(options) {
3176
3176
  }
3177
3177
 
3178
3178
  @media (max-width: 360px) {
3179
- .sv-totp-input-group {
3179
+ .sv-otp-input-group {
3180
3180
  gap: 6px;
3181
3181
  }
3182
3182
 
3183
- .sv-totp-digit {
3183
+ .sv-otp-digit {
3184
3184
  width: 36px;
3185
3185
  height: 44px;
3186
3186
  font-size: 16px;
@@ -3864,10 +3864,10 @@ function looksLikePhone(input) {
3864
3864
  return /^[+(\d]/.test(trimmed) && !/[@.]/.test(trimmed);
3865
3865
  }
3866
3866
  /**
3867
- * Validate TOTP code format.
3867
+ * Validate OTP code format.
3868
3868
  * Returns sanitized code or null if invalid.
3869
3869
  */
3870
- function validateTotpCode(code) {
3870
+ function validateOtpCode(code) {
3871
3871
  const digits = code.replace(/\D/g, '');
3872
3872
  if (digits.length === 6) {
3873
3873
  return digits;
@@ -4223,12 +4223,12 @@ class MethodSelectView {
4223
4223
  }
4224
4224
 
4225
4225
  /**
4226
- * TOTP Verification View
4226
+ * OTP Verification View
4227
4227
  *
4228
- * Collects and validates the 6-digit TOTP code sent via email, SMS, or voice.
4228
+ * Collects and validates the 6-digit OTP code sent via email, SMS, or voice.
4229
4229
  */
4230
4230
  const CODE_LENGTH = 6;
4231
- class TotpVerifyView {
4231
+ class OtpVerifyView {
4232
4232
  constructor(props) {
4233
4233
  this.inputElements = [];
4234
4234
  this.submitButton = null;
@@ -4305,14 +4305,14 @@ class TotpVerifyView {
4305
4305
  return link;
4306
4306
  }
4307
4307
  createInputGroup() {
4308
- const group = div('sv-totp-input-group');
4308
+ const group = div('sv-otp-input-group');
4309
4309
  for (let i = 0; i < CODE_LENGTH; i++) {
4310
4310
  const input = document.createElement('input');
4311
4311
  input.type = 'text';
4312
4312
  input.inputMode = 'numeric';
4313
4313
  input.pattern = '[0-9]*';
4314
4314
  input.maxLength = 1;
4315
- input.className = 'sv-totp-digit';
4315
+ input.className = 'sv-otp-digit';
4316
4316
  input.autocomplete = 'one-time-code';
4317
4317
  input.setAttribute('aria-label', `Digit ${i + 1} of ${CODE_LENGTH}`);
4318
4318
  // Create and store handlers for proper cleanup
@@ -4419,7 +4419,7 @@ class TotpVerifyView {
4419
4419
  return;
4420
4420
  }
4421
4421
  const code = this.getCode();
4422
- const validCode = validateTotpCode(code);
4422
+ const validCode = validateOtpCode(code);
4423
4423
  if (!validCode) {
4424
4424
  this.showError('Please enter the complete 6-digit code');
4425
4425
  return;
@@ -5727,7 +5727,7 @@ class OriginNotAllowedView {
5727
5727
  * Identity View Renderer
5728
5728
  *
5729
5729
  * Orchestrates view state and rendering for identity verification flows.
5730
- * Uses extracted handlers for TOTP and Passkey operations.
5730
+ * Uses extracted handlers for OTP and Passkey operations.
5731
5731
  */
5732
5732
  /**
5733
5733
  * End-user copy for a blocked Identity. Intentionally generic — it never names
@@ -5783,7 +5783,7 @@ class IdentityRenderer {
5783
5783
  this.verificationState = new VerificationState();
5784
5784
  // Initialize handlers with shared state
5785
5785
  this.passkeyHandler = new PasskeyHandler(api, this.verificationState);
5786
- this.totpHandler = new TotpHandler(api, this.verificationState);
5786
+ this.otpHandler = new OtpHandler(api, this.verificationState);
5787
5787
  this.sparkLinkHandler = new SparkLinkHandler(api, this.verificationState);
5788
5788
  // Set initial identity from options
5789
5789
  if (options.email) {
@@ -6050,14 +6050,14 @@ class IdentityRenderer {
6050
6050
  onSelectMethod: (method) => this.handleMethodSelect(method, true),
6051
6051
  onBack: state.email ? () => this.showIdentityInput() : undefined,
6052
6052
  });
6053
- case 'totp-verify':
6054
- return new TotpVerifyView({
6053
+ case 'otp-verify':
6054
+ return new OtpVerifyView({
6055
6055
  email: state.email,
6056
6056
  method: state.method,
6057
6057
  error: state.error,
6058
6058
  backoffExpires: state.backoffExpires,
6059
- onSubmit: (code) => this.handleTotpSubmit(code),
6060
- onResend: () => this.handleTotpResend(),
6059
+ onSubmit: (code) => this.handleOtpSubmit(code),
6060
+ onResend: () => this.handleOtpResend(),
6061
6061
  onBack: () => this.showMethodSelect(),
6062
6062
  });
6063
6063
  case 'two-factor':
@@ -6108,7 +6108,7 @@ class IdentityRenderer {
6108
6108
  onSkip: () => this.handleBackupSkip(),
6109
6109
  });
6110
6110
  case 'backup-code':
6111
- return new TotpVerifyView({
6111
+ return new OtpVerifyView({
6112
6112
  email: state.value,
6113
6113
  method: state.method,
6114
6114
  error: state.error,
@@ -6260,29 +6260,29 @@ class IdentityRenderer {
6260
6260
  async handleMethodSelect(method, userInitiated = false) {
6261
6261
  try {
6262
6262
  switch (method.type) {
6263
- case 'totp': {
6264
- const totpMethod = method.id === 'totp_sms'
6263
+ case 'otp': {
6264
+ const otpMethod = method.id === 'otp_sms'
6265
6265
  ? 'sms'
6266
- : method.id === 'totp_voice'
6266
+ : method.id === 'otp_voice'
6267
6267
  ? 'voice'
6268
6268
  : 'email';
6269
6269
  this.setState({ view: 'loading' });
6270
- const result = await this.totpHandler.send(totpMethod);
6270
+ const result = await this.otpHandler.send(otpMethod);
6271
6271
  if (!result.success) {
6272
6272
  if (this.renderBlockedInterstitial(result.errorCode))
6273
6273
  return;
6274
6274
  this.setState({
6275
6275
  view: 'error',
6276
6276
  message: result.error ?? 'Failed to send code',
6277
- code: 'totp_send_failed',
6277
+ code: 'otp_send_failed',
6278
6278
  });
6279
6279
  return;
6280
6280
  }
6281
6281
  this.setState({
6282
- view: 'totp-verify',
6282
+ view: 'otp-verify',
6283
6283
  email: this.recipient,
6284
- method: totpMethod,
6285
- kindling: this.verificationState.totp.kindling,
6284
+ method: otpMethod,
6285
+ kindling: this.verificationState.otp.kindling,
6286
6286
  });
6287
6287
  break;
6288
6288
  }
@@ -6332,7 +6332,7 @@ class IdentityRenderer {
6332
6332
  // A blocked Identity (trial exhausted/expired, paid capacity) is
6333
6333
  // terminal — show the "sign-in unavailable" interstitial, not a
6334
6334
  // retryable "Try Again" that invites retrying a permanently-blocked
6335
- // login. Mirrors the totp send path.
6335
+ // login. Mirrors the otp send path.
6336
6336
  if (this.renderBlockedInterstitial(result.errorCode))
6337
6337
  return;
6338
6338
  this.setState({
@@ -6390,11 +6390,11 @@ class IdentityRenderer {
6390
6390
  });
6391
6391
  return true;
6392
6392
  }
6393
- async handleTotpSubmit(code) {
6394
- if (this.viewState.view !== 'totp-verify')
6393
+ async handleOtpSubmit(code) {
6394
+ if (this.viewState.view !== 'otp-verify')
6395
6395
  return;
6396
- const currentMethod = this.verificationState.totp.method ?? 'email';
6397
- const result = await this.totpHandler.verify(code);
6396
+ const currentMethod = this.verificationState.otp.method ?? 'email';
6397
+ const result = await this.otpHandler.verify(code);
6398
6398
  if (result.secondFactor) {
6399
6399
  this.setState({
6400
6400
  view: 'two-factor',
@@ -6421,33 +6421,33 @@ class IdentityRenderer {
6421
6421
  const errorMsg = result.error?.toLowerCase() ?? '';
6422
6422
  if (errorMsg.includes('expired')) {
6423
6423
  // Auto-resend a new code
6424
- const resendResult = await this.totpHandler.resend();
6424
+ const resendResult = await this.otpHandler.resend();
6425
6425
  if (resendResult.success) {
6426
6426
  this.setState({
6427
- view: 'totp-verify',
6427
+ view: 'otp-verify',
6428
6428
  email: this.recipient,
6429
6429
  method: currentMethod,
6430
- kindling: this.verificationState.totp.kindling,
6430
+ kindling: this.verificationState.otp.kindling,
6431
6431
  error: 'Code expired. We\'ve sent a new one.',
6432
6432
  });
6433
6433
  return;
6434
6434
  }
6435
6435
  // Resend failed - show error
6436
6436
  this.setState({
6437
- view: 'totp-verify',
6437
+ view: 'otp-verify',
6438
6438
  email: this.recipient,
6439
6439
  method: currentMethod,
6440
- kindling: this.verificationState.totp.kindling,
6440
+ kindling: this.verificationState.otp.kindling,
6441
6441
  error: resendResult.error ?? 'Code expired and failed to resend.',
6442
6442
  });
6443
6443
  return;
6444
6444
  }
6445
6445
  // Other verification failure
6446
6446
  this.setState({
6447
- view: 'totp-verify',
6447
+ view: 'otp-verify',
6448
6448
  email: this.recipient,
6449
6449
  method: currentMethod,
6450
- kindling: this.verificationState.totp.kindling,
6450
+ kindling: this.verificationState.otp.kindling,
6451
6451
  error: result.error ?? 'Invalid code. Please try again.',
6452
6452
  backoffExpires: result.backoffExpires,
6453
6453
  });
@@ -6481,19 +6481,19 @@ class IdentityRenderer {
6481
6481
  this.setState({ view: 'two-factor', ticket, methods, error: message });
6482
6482
  }
6483
6483
  }
6484
- async handleTotpResend() {
6485
- if (this.viewState.view !== 'totp-verify')
6484
+ async handleOtpResend() {
6485
+ if (this.viewState.view !== 'otp-verify')
6486
6486
  return;
6487
- const currentMethod = this.verificationState.totp.method ?? 'email';
6488
- const result = await this.totpHandler.resend();
6487
+ const currentMethod = this.verificationState.otp.method ?? 'email';
6488
+ const result = await this.otpHandler.resend();
6489
6489
  if (!result.success) {
6490
6490
  if (this.renderBlockedInterstitial(result.errorCode))
6491
6491
  return;
6492
6492
  this.setState({
6493
- view: 'totp-verify',
6493
+ view: 'otp-verify',
6494
6494
  email: this.recipient,
6495
6495
  method: currentMethod,
6496
- kindling: this.verificationState.totp.kindling,
6496
+ kindling: this.verificationState.otp.kindling,
6497
6497
  error: result.error ?? 'Failed to resend code',
6498
6498
  });
6499
6499
  }
@@ -7164,27 +7164,27 @@ class IdentityRenderer {
7164
7164
  }
7165
7165
  }
7166
7166
  /**
7167
- * Handle fallback from SparkLink to TOTP verification code.
7167
+ * Handle fallback from SparkLink to OTP verification code.
7168
7168
  */
7169
7169
  async handleSparkLinkFallback() {
7170
7170
  this.cleanupSparkLink();
7171
7171
  this.setState({ view: 'loading' });
7172
- const result = await this.totpHandler.send('email');
7172
+ const result = await this.otpHandler.send('email');
7173
7173
  if (!result.success) {
7174
7174
  if (this.renderBlockedInterstitial(result.errorCode))
7175
7175
  return;
7176
7176
  this.setState({
7177
7177
  view: 'error',
7178
7178
  message: result.error ?? 'Failed to send code',
7179
- code: 'totp_send_failed',
7179
+ code: 'otp_send_failed',
7180
7180
  });
7181
7181
  return;
7182
7182
  }
7183
7183
  this.setState({
7184
- view: 'totp-verify',
7184
+ view: 'otp-verify',
7185
7185
  email: this.recipient,
7186
7186
  method: 'email',
7187
- kindling: this.verificationState.totp.kindling,
7187
+ kindling: this.verificationState.otp.kindling,
7188
7188
  });
7189
7189
  }
7190
7190
  }
@@ -7776,7 +7776,7 @@ function attachClickHandler(selector, onClick) {
7776
7776
  * Identity Module
7777
7777
  *
7778
7778
  * Provides identity verification through dialog or inline UI.
7779
- * Supports passkey, TOTP, SparkLink, and social authentication.
7779
+ * Supports passkey, OTP, SparkLink, and social authentication.
7780
7780
  *
7781
7781
  * @example Dialog mode (immediate)
7782
7782
  * const result = await sv.products.identity.verify();