@sparkvault/sdk-js 1.27.1 → 1.27.3

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.
@@ -967,12 +967,12 @@ class IdentityApi extends SparkVaultApi {
967
967
  return this.configCache !== null;
968
968
  }
969
969
  /**
970
- * Check if an identity (email or phone) has registered passkeys.
970
+ * Check whether the SVID resolved from an email or phone has registered passkeys.
971
971
  *
972
972
  * Returns:
973
973
  * - identity_valid: identity passes per-type validity check
974
974
  * (email: MX lookup; phone: E.164 format)
975
- * - has_passkey: whether any passkeys are registered for this identity
975
+ * - has_passkey: whether any passkeys are registered on the resolved SVID
976
976
  * (cross-tenant — single global RP)
977
977
  */
978
978
  async checkPasskey(identity, identityType = 'email') {
@@ -1022,7 +1022,7 @@ class IdentityApi extends SparkVaultApi {
1022
1022
  });
1023
1023
  }
1024
1024
  /**
1025
- * Start passkey registration for an identity (email or phone).
1025
+ * Start passkey registration from a freshly verified identifier.
1026
1026
  */
1027
1027
  async startPasskeyRegister(identity, identityType = 'email', registrationToken) {
1028
1028
  const body = identityType === 'phone'
@@ -1060,19 +1060,19 @@ class IdentityApi extends SparkVaultApi {
1060
1060
  });
1061
1061
  }
1062
1062
  /**
1063
- * Start passkey verification for an identity (email or phone).
1063
+ * Start discoverable passkey verification. Legacy identity parameters are
1064
+ * intentionally ignored; the credential userHandle routes completion to the
1065
+ * SVID.
1064
1066
  */
1065
- async startPasskeyVerify(identity, identityType = 'email', authContext) {
1066
- const identityField = identityType === 'phone' ? { phone: identity } : { email: identity };
1067
+ async startPasskeyVerify(_identity, _identityType = 'email', authContext) {
1067
1068
  // Backend returns { options: PublicKeyCredentialRequestOptions, session: {...} }
1068
1069
  // Extract and flatten to match PasskeyChallengeResponse
1069
- const response = await this.request('POST', '/passkey/verify', { ...identityField, ...this.buildAuthContextParams(authContext) });
1070
+ const response = await this.request('POST', '/passkey/verify', this.buildAuthContextParams(authContext));
1070
1071
  return {
1071
1072
  challenge: response.options.challenge,
1072
1073
  rpId: response.options.rpId,
1073
1074
  rpName: 'SparkVault Identity', // Not returned by verify endpoint
1074
1075
  timeout: response.options.timeout,
1075
- allowCredentials: response.options.allowCredentials,
1076
1076
  session: response.session,
1077
1077
  };
1078
1078
  }
@@ -1168,7 +1168,6 @@ const METHOD_REGISTRY = {
1168
1168
  passkey: {
1169
1169
  id: 'passkey',
1170
1170
  type: 'passkey',
1171
- identityType: 'email',
1172
1171
  name: 'Passkey',
1173
1172
  description: 'Use biometrics or security key',
1174
1173
  icon: 'passkey',
@@ -1313,19 +1312,20 @@ class VerificationState {
1313
1312
  return this._sdkConfig?.accountId ?? '';
1314
1313
  }
1315
1314
  /**
1316
- * Get enriched methods filtered by identity type
1315
+ * Get enriched methods filtered by the fallback identifier type.
1317
1316
  */
1318
1317
  getAvailableMethods() {
1319
1318
  if (!this._sdkConfig)
1320
1319
  return [];
1321
1320
  const methodIds = this._sdkConfig.methods ?? [];
1322
1321
  let methods = enrichMethods(methodIds);
1323
- // Filter by identity type
1322
+ // Filter by identifier type. Passkeys are SVID-scoped and remain
1323
+ // available regardless of whether the fallback identifier is email or phone.
1324
1324
  if (this._identityType === 'phone') {
1325
- methods = methods.filter((m) => m.type === 'totp' && m.id === 'totp_sms');
1325
+ methods = methods.filter((m) => m.type === 'passkey' || m.identityType === 'phone');
1326
1326
  }
1327
1327
  else {
1328
- methods = methods.filter((m) => m.identityType === 'email');
1328
+ methods = methods.filter((m) => m.identityType === 'email' || m.identityType === undefined);
1329
1329
  }
1330
1330
  return methods;
1331
1331
  }
@@ -1355,7 +1355,9 @@ class VerificationState {
1355
1355
  this._identityType = type;
1356
1356
  }
1357
1357
  getAllowedIdentityTypes() {
1358
- const allowed = this._sdkConfig?.allowedIdentityTypes ?? ['email'];
1358
+ if (!this._sdkConfig)
1359
+ return ['email'];
1360
+ const allowed = this._sdkConfig.allowedIdentityTypes ?? ['email'];
1359
1361
  return allowed;
1360
1362
  }
1361
1363
  // --- Auth Context (OIDC/simple mode) ---
@@ -1380,11 +1382,9 @@ class VerificationState {
1380
1382
  }
1381
1383
  /**
1382
1384
  * Check if we should show passkey registration prompt
1383
- * Based on: passkey enabled, user doesn't have one, not dismissed
1385
+ * Based on: passkey enabled, the current SVID doesn't have one, not dismissed
1384
1386
  */
1385
1387
  shouldShowPasskeyPrompt() {
1386
- if (this._identityType !== 'email')
1387
- return false;
1388
1388
  if (!this.isPasskeyEnabled())
1389
1389
  return false;
1390
1390
  if (this.isPasskeyPromptDismissed())
@@ -1468,7 +1468,7 @@ class PasskeyHandler {
1468
1468
  this.accountId = config.accountId;
1469
1469
  }
1470
1470
  /**
1471
- * Check if user has registered passkeys and validate email domain
1471
+ * Check if the current identifier resolves to an SVID with registered passkeys.
1472
1472
  * @returns Check result with emailValid and hasPasskey, or null on error
1473
1473
  */
1474
1474
  async checkPasskey() {
@@ -1508,14 +1508,17 @@ class PasskeyHandler {
1508
1508
  */
1509
1509
  async openPasskeyPopup(mode, registrationToken) {
1510
1510
  return new Promise((resolve) => {
1511
- // Build popup URL. Pass identity as `email` or `phone` (mutually
1512
- // exclusive) so the popup can render and POST the correct field.
1511
+ // Registration carries the freshly verified identifier so the backend
1512
+ // can attach the credential to that SVID. Verification is discoverable:
1513
+ // the credential userHandle routes completion to the SVID.
1513
1514
  const params = new URLSearchParams({
1514
1515
  mode,
1515
1516
  origin: window.location.origin,
1516
1517
  });
1517
- const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
1518
- params.set(identityParam, this.state.recipient);
1518
+ if (mode === 'register' && this.state.recipient) {
1519
+ const identityParam = this.state.identityType === 'phone' ? 'phone' : 'email';
1520
+ params.set(identityParam, this.state.recipient);
1521
+ }
1519
1522
  // Add auth context for OIDC/simple mode flows
1520
1523
  const authContext = this.state.authContext;
1521
1524
  if (authContext?.authRequestId) {
@@ -1572,6 +1575,9 @@ class PasskeyHandler {
1572
1575
  token: data.data.token || '',
1573
1576
  identity: data.data.identity || this.state.recipient,
1574
1577
  identityType: data.data.identity_type || 'email',
1578
+ svid: data.data.svid,
1579
+ sessionId: data.data.session_id,
1580
+ refreshToken: data.data.refresh_token,
1575
1581
  redirect: data.data.redirect,
1576
1582
  },
1577
1583
  });
@@ -1675,7 +1681,7 @@ class TotpHandler {
1675
1681
  this.state = state;
1676
1682
  }
1677
1683
  /**
1678
- * Send TOTP code via email or SMS
1684
+ * Send TOTP code via email, SMS, or voice
1679
1685
  */
1680
1686
  async send(method) {
1681
1687
  try {
@@ -1759,6 +1765,9 @@ class TotpHandler {
1759
1765
  token: response.token,
1760
1766
  identity: response.identity ?? this.state.recipient,
1761
1767
  identityType: response.identity_type ?? this.state.identityType,
1768
+ svid: response.svid,
1769
+ sessionId: response.session_id,
1770
+ refreshToken: response.refresh_token,
1762
1771
  redirect: response.redirect,
1763
1772
  },
1764
1773
  };
@@ -4099,26 +4108,33 @@ class MethodSelectView {
4099
4108
  this.methodClickHandlers = new Map();
4100
4109
  this.props = props;
4101
4110
  // Bind handlers once for proper removal
4102
- this.boundHandleBack = () => this.props.onBack();
4111
+ this.boundHandleBack = () => this.props.onBack?.();
4103
4112
  }
4104
4113
  render() {
4105
4114
  const container = div();
4106
- this.backLink = this.createBackLink();
4115
+ this.backLink = this.props.onBack ? this.createBackLink() : null;
4107
4116
  const title = document.createElement('h3');
4108
4117
  title.className = 'sv-title';
4109
4118
  title.textContent = 'Choose how to sign in';
4110
- const subtitle = document.createElement('p');
4111
- subtitle.className = 'sv-subtitle';
4112
- subtitle.textContent = escapeHtml(this.props.email);
4119
+ const email = this.props.email;
4120
+ const subtitle = email ? document.createElement('p') : null;
4121
+ if (subtitle && email) {
4122
+ subtitle.className = 'sv-subtitle';
4123
+ subtitle.textContent = escapeHtml(email);
4124
+ }
4113
4125
  const methodsContainer = div();
4114
4126
  for (const method of this.props.methods) {
4115
4127
  const methodButton = this.createMethodButton(method);
4116
4128
  this.methodButtons.push(methodButton);
4117
4129
  methodsContainer.appendChild(methodButton);
4118
4130
  }
4119
- container.appendChild(this.backLink);
4131
+ if (this.backLink) {
4132
+ container.appendChild(this.backLink);
4133
+ }
4120
4134
  container.appendChild(title);
4121
- container.appendChild(subtitle);
4135
+ if (subtitle) {
4136
+ container.appendChild(subtitle);
4137
+ }
4122
4138
  container.appendChild(methodsContainer);
4123
4139
  return container;
4124
4140
  }
@@ -4179,7 +4195,7 @@ class MethodSelectView {
4179
4195
  /**
4180
4196
  * TOTP Verification View
4181
4197
  *
4182
- * Collects and validates the 6-digit TOTP code sent via email or SMS.
4198
+ * Collects and validates the 6-digit TOTP code sent via email, SMS, or voice.
4183
4199
  */
4184
4200
  const CODE_LENGTH = 6;
4185
4201
  class TotpVerifyView {
@@ -4503,13 +4519,13 @@ class PasskeyView {
4503
4519
  this.fallbackLink = null;
4504
4520
  this.props = props;
4505
4521
  // Bind handlers once for proper removal
4506
- this.boundHandleBack = () => this.props.onBack();
4522
+ this.boundHandleBack = () => this.props.onBack?.();
4507
4523
  this.boundHandleStart = () => this.handleStart();
4508
4524
  this.boundHandleFallback = props.onFallback ? () => props.onFallback() : null;
4509
4525
  }
4510
4526
  render() {
4511
4527
  const container = div();
4512
- this.backLink = this.createBackLink();
4528
+ this.backLink = this.props.onBack ? this.createBackLink() : null;
4513
4529
  const iconContainer = div();
4514
4530
  iconContainer.appendChild(createPasskeyIcon());
4515
4531
  const title = document.createElement('h3');
@@ -4518,10 +4534,10 @@ class PasskeyView {
4518
4534
  const subtitle = document.createElement('p');
4519
4535
  subtitle.className = 'sv-subtitle';
4520
4536
  if (this.props.mode === 'register') {
4521
- subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.email)}</strong><br>to sign in faster next time`;
4537
+ subtitle.innerHTML = `Create a passkey for<br><strong>${escapeHtml(this.props.identityLabel)}</strong><br>to sign in faster next time`;
4522
4538
  }
4523
4539
  else {
4524
- subtitle.innerHTML = `Use your passkey to verify<br><strong>${escapeHtml(this.props.email)}</strong>`;
4540
+ subtitle.innerHTML = 'Use a passkey linked to your SparkVault Identity';
4525
4541
  }
4526
4542
  this.errorContainer = div();
4527
4543
  if (this.props.error) {
@@ -4538,7 +4554,9 @@ class PasskeyView {
4538
4554
  this.actionButton.className = 'sv-btn sv-btn-primary';
4539
4555
  this.actionButton.textContent = buttonText;
4540
4556
  this.actionButton.addEventListener('click', this.boundHandleStart);
4541
- container.appendChild(this.backLink);
4557
+ if (this.backLink) {
4558
+ container.appendChild(this.backLink);
4559
+ }
4542
4560
  container.appendChild(iconContainer);
4543
4561
  container.appendChild(title);
4544
4562
  container.appendChild(subtitle);
@@ -4554,7 +4572,7 @@ class PasskeyView {
4554
4572
  createFallbackLink() {
4555
4573
  const link = document.createElement('button');
4556
4574
  link.className = 'sv-fallback-link';
4557
- link.textContent = 'Having trouble? Use email code instead';
4575
+ link.textContent = 'Having trouble? Use a code instead';
4558
4576
  if (this.boundHandleFallback) {
4559
4577
  link.addEventListener('click', this.boundHandleFallback);
4560
4578
  }
@@ -4627,7 +4645,7 @@ class PasskeyPromptView {
4627
4645
  title.textContent = 'Add a passkey for faster sign-in?';
4628
4646
  const subtitle = document.createElement('p');
4629
4647
  subtitle.className = 'sv-subtitle';
4630
- subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.email)}</strong>`;
4648
+ subtitle.innerHTML = `Next time, sign in instantly as<br><strong>${escapeHtml(this.props.identityLabel)}</strong>`;
4631
4649
  // Error message if registration failed
4632
4650
  const errorContainer = div();
4633
4651
  if (this.props.error) {
@@ -5208,6 +5226,14 @@ class ProductNotConfiguredView {
5208
5226
  * Orchestrates view state and rendering for identity verification flows.
5209
5227
  * Uses extracted handlers for TOTP and Passkey operations.
5210
5228
  */
5229
+ const SPARKLINK_CSP_BLOCKED_ERROR = {
5230
+ message: [
5231
+ 'Connection blocked by security policy.',
5232
+ 'Please contact the site administrator to add wss://ws.sparkvault.com',
5233
+ 'to the Content-Security-Policy connect-src directive.',
5234
+ ].join(' '),
5235
+ code: 'sparklink_csp_blocked',
5236
+ };
5211
5237
  class IdentityRenderer {
5212
5238
  constructor(container, api, options, callbacks) {
5213
5239
  // View management
@@ -5247,7 +5273,6 @@ class IdentityRenderer {
5247
5273
  this.callbacks.onSuccess(result);
5248
5274
  }
5249
5275
  catch (err) {
5250
- // eslint-disable-next-line no-console
5251
5276
  console.warn('[SparkVault SDK] onSuccess threw, continuing to redirect', err);
5252
5277
  }
5253
5278
  }
@@ -5313,13 +5338,7 @@ class IdentityRenderer {
5313
5338
  ? config.branding.backdrop_blur
5314
5339
  : true;
5315
5340
  this.container.updateBackdropBlur(resolvedBackdropBlur);
5316
- // Proceed to appropriate view
5317
- if (this.recipient) {
5318
- this.showMethodSelect();
5319
- }
5320
- else {
5321
- this.showIdentityInput();
5322
- }
5341
+ await this.showInitialAuthStep();
5323
5342
  }
5324
5343
  catch (error) {
5325
5344
  this.setState(this.viewStateForConfigError(error));
@@ -5376,12 +5395,7 @@ class IdentityRenderer {
5376
5395
  ? config.branding.backdrop_blur
5377
5396
  : true;
5378
5397
  this.container.updateBackdropBlur(resolvedBackdropBlur);
5379
- if (this.recipient) {
5380
- this.showMethodSelect();
5381
- }
5382
- else {
5383
- this.showIdentityInput();
5384
- }
5398
+ await this.showInitialAuthStep();
5385
5399
  }
5386
5400
  catch (error) {
5387
5401
  this.setState(this.viewStateForConfigError(error));
@@ -5413,6 +5427,13 @@ class IdentityRenderer {
5413
5427
  this.verificationState.setViewState(state);
5414
5428
  this.render();
5415
5429
  }
5430
+ async showInitialAuthStep() {
5431
+ if (this.recipient || this.getAllowedIdentityTypes().length === 0) {
5432
+ await this.showMethodSelect();
5433
+ return;
5434
+ }
5435
+ this.showIdentityInput();
5436
+ }
5416
5437
  render() {
5417
5438
  const body = this.container.getBody();
5418
5439
  if (!body)
@@ -5461,7 +5482,7 @@ class IdentityRenderer {
5461
5482
  email: state.email,
5462
5483
  methods: state.methods,
5463
5484
  onSelectMethod: (method) => this.handleMethodSelect(method),
5464
- onBack: () => this.showIdentityInput(),
5485
+ onBack: state.email ? () => this.showIdentityInput() : undefined,
5465
5486
  });
5466
5487
  case 'totp-verify':
5467
5488
  return new TotpVerifyView({
@@ -5478,7 +5499,7 @@ class IdentityRenderer {
5478
5499
  const { passkey } = this.verificationState;
5479
5500
  const isFromPrompt = state.mode === 'register' && passkey.pendingResult !== null;
5480
5501
  return new PasskeyView({
5481
- email: state.email,
5502
+ identityLabel: state.recipient,
5482
5503
  mode: state.mode,
5483
5504
  error: state.error,
5484
5505
  onStart: () => this.handlePasskeyStart(),
@@ -5486,7 +5507,11 @@ class IdentityRenderer {
5486
5507
  ? () => this.handlePasskeyRegistrationSkip()
5487
5508
  : state.mode === 'verify'
5488
5509
  // From passkey verify, enable fallback so showMethodSelect doesn't loop back
5489
- ? () => this.handlePasskeyFallback()
5510
+ ? this.passkeyFallbackMethodsAvailable()
5511
+ ? () => this.handlePasskeyFallback()
5512
+ : this.recipient
5513
+ ? () => this.showIdentityInput()
5514
+ : undefined
5490
5515
  : () => this.showMethodSelect(),
5491
5516
  onFallback: passkey.hasPasskey && !passkey.isFallbackMode
5492
5517
  ? () => this.handlePasskeyFallback()
@@ -5495,7 +5520,7 @@ class IdentityRenderer {
5495
5520
  }
5496
5521
  case 'passkey-prompt':
5497
5522
  return new PasskeyPromptView({
5498
- email: state.email,
5523
+ identityLabel: state.recipient,
5499
5524
  onAddPasskey: () => this.handlePasskeyPromptAdd(state.pendingResult),
5500
5525
  onSkip: () => this.handlePasskeyPromptSkip(state.pendingResult),
5501
5526
  error: state.error,
@@ -5547,45 +5572,22 @@ class IdentityRenderer {
5547
5572
  }
5548
5573
  // Enrich method IDs with metadata from static registry
5549
5574
  let methods = enrichMethods(methodIds);
5550
- // Filter by identity type (phone users can only use SMS TOTP)
5551
- methods = methods.filter((m) => {
5552
- if (this.identityType === 'phone') {
5553
- // Phone users can only use SMS TOTP
5554
- return m.type === 'totp' && m.id === 'totp_sms';
5555
- }
5556
- // Email users can use email-based methods
5557
- return m.identityType === 'email' || m.identityType === undefined;
5558
- });
5559
- if (methods.length === 0) {
5560
- this.setState({
5561
- view: 'error',
5562
- message: 'No authentication methods available',
5563
- code: 'no_methods',
5575
+ if (this.recipient) {
5576
+ // Filter by identifier type. Passkeys are SVID-scoped, so they remain
5577
+ // available regardless of whether the fallback identifier is email or phone.
5578
+ methods = methods.filter((m) => {
5579
+ if (this.identityType === 'phone') {
5580
+ return m.type === 'passkey' || m.identityType === 'phone';
5581
+ }
5582
+ // Email users can use email-based methods
5583
+ return m.identityType === 'email' || m.identityType === undefined;
5564
5584
  });
5565
- return;
5566
5585
  }
5567
- // Check if passkeys are enabled and user is email-based
5568
- const hasPasskeyMethod = methods.some((m) => m.type === 'passkey');
5569
- const { passkey } = this.verificationState;
5570
- if (hasPasskeyMethod && this.identityType === 'email' && !passkey.isFallbackMode) {
5571
- this.setState({ view: 'loading' });
5572
- // Use passkey handler for the check (also validates email domain)
5573
- const checkResult = await this.passkeyHandler.checkPasskey();
5574
- // Handle invalid email domain
5575
- if (checkResult !== null && !checkResult.emailValid) {
5576
- this.showIdentityInput('This email domain cannot receive messages. Please check your email address.');
5577
- return;
5578
- }
5579
- if (checkResult?.hasPasskey === true) {
5580
- // User has passkey - go straight to passkey verification
5581
- this.setState({
5582
- view: 'passkey',
5583
- email: this.recipient,
5584
- mode: 'verify',
5585
- });
5586
- return;
5587
- }
5588
- // User doesn't have passkey - filter out passkey option
5586
+ else {
5587
+ // No PII prompt is needed when only SVID-routed methods are enabled.
5588
+ methods = methods.filter((m) => m.type === 'passkey' || m.type === 'social');
5589
+ }
5590
+ if (this.verificationState.passkey.isFallbackMode) {
5589
5591
  methods = methods.filter((m) => m.type !== 'passkey');
5590
5592
  }
5591
5593
  if (methods.length === 0) {
@@ -5617,7 +5619,11 @@ class IdentityRenderer {
5617
5619
  try {
5618
5620
  switch (method.type) {
5619
5621
  case 'totp': {
5620
- const totpMethod = method.id === 'totp_sms' ? 'sms' : 'email';
5622
+ const totpMethod = method.id === 'totp_sms'
5623
+ ? 'sms'
5624
+ : method.id === 'totp_voice'
5625
+ ? 'voice'
5626
+ : 'email';
5621
5627
  this.setState({ view: 'loading' });
5622
5628
  const result = await this.totpHandler.send(totpMethod);
5623
5629
  if (!result.success) {
@@ -5639,7 +5645,7 @@ class IdentityRenderer {
5639
5645
  case 'passkey': {
5640
5646
  this.setState({
5641
5647
  view: 'passkey',
5642
- email: this.recipient,
5648
+ recipient: this.recipient,
5643
5649
  mode: 'verify',
5644
5650
  });
5645
5651
  break;
@@ -5654,8 +5660,7 @@ class IdentityRenderer {
5654
5660
  // CSP blocking WebSocket - provide developer-friendly error
5655
5661
  this.setState({
5656
5662
  view: 'error',
5657
- message: 'Connection blocked by security policy. Please contact the site administrator to add wss://*.sparkvault.com to the Content-Security-Policy connect-src directive.',
5658
- code: 'sparklink_csp_blocked',
5663
+ ...SPARKLINK_CSP_BLOCKED_ERROR,
5659
5664
  });
5660
5665
  }
5661
5666
  else {
@@ -5713,7 +5718,7 @@ class IdentityRenderer {
5713
5718
  if (!result.result.redirect && await this.shouldShowPasskeyPrompt()) {
5714
5719
  this.setState({
5715
5720
  view: 'passkey-prompt',
5716
- email: this.recipient,
5721
+ recipient: this.recipient,
5717
5722
  pendingResult: result.result,
5718
5723
  });
5719
5724
  return;
@@ -5815,7 +5820,7 @@ class IdentityRenderer {
5815
5820
  if (result.errorType === 'not_found') {
5816
5821
  this.setState({
5817
5822
  view: 'passkey',
5818
- email: this.recipient,
5823
+ recipient: this.recipient,
5819
5824
  mode: 'register',
5820
5825
  error: result.error,
5821
5826
  });
@@ -5823,7 +5828,7 @@ class IdentityRenderer {
5823
5828
  else {
5824
5829
  this.setState({
5825
5830
  view: 'passkey',
5826
- email: this.recipient,
5831
+ recipient: this.recipient,
5827
5832
  mode: currentMode,
5828
5833
  error: result.error,
5829
5834
  });
@@ -5831,13 +5836,28 @@ class IdentityRenderer {
5831
5836
  }
5832
5837
  }
5833
5838
  /**
5834
- * Handle fallback from passkey to email/SMS code.
5835
- * User clicked "Having trouble? Use email code instead".
5839
+ * Handle fallback from passkey to an identifier-based code.
5840
+ * User clicked "Having trouble? Use a code instead".
5836
5841
  */
5837
5842
  async handlePasskeyFallback() {
5838
5843
  this.verificationState.enablePasskeyFallback();
5839
5844
  await this.showMethodSelect();
5840
5845
  }
5846
+ passkeyFallbackMethodsAvailable() {
5847
+ if (!this.sdkConfig)
5848
+ return false;
5849
+ const methods = enrichMethods(this.sdkConfig.methods ?? []);
5850
+ if (!this.recipient) {
5851
+ return methods.some((m) => m.type === 'social');
5852
+ }
5853
+ return methods.some((m) => {
5854
+ if (m.type === 'passkey')
5855
+ return false;
5856
+ if (this.identityType === 'phone')
5857
+ return m.identityType === 'phone';
5858
+ return m.identityType === 'email';
5859
+ });
5860
+ }
5841
5861
  /**
5842
5862
  * Handle skipping passkey registration when coming from passkey prompt.
5843
5863
  * User clicked "Back" or cancelled registration after being prompted.
@@ -5915,7 +5935,7 @@ class IdentityRenderer {
5915
5935
  const { passkey } = this.verificationState;
5916
5936
  if (passkey.hasPasskey === null) {
5917
5937
  const checkResult = await this.passkeyHandler.checkPasskey();
5918
- // Only prompt if email is valid and user doesn't have a passkey
5938
+ // Only prompt if the verified identifier resolves to an SVID without a passkey.
5919
5939
  return checkResult !== null && checkResult.emailValid && !checkResult.hasPasskey;
5920
5940
  }
5921
5941
  return !passkey.hasPasskey;
@@ -5943,7 +5963,7 @@ class IdentityRenderer {
5943
5963
  // User cancelled browser dialog - go back to prompt so they can skip or try again
5944
5964
  this.setState({
5945
5965
  view: 'passkey-prompt',
5946
- email: this.recipient,
5966
+ recipient: this.recipient,
5947
5967
  pendingResult,
5948
5968
  });
5949
5969
  }
@@ -5952,7 +5972,7 @@ class IdentityRenderer {
5952
5972
  const errorMessage = result.error || 'Failed to create passkey. Please try again.';
5953
5973
  this.setState({
5954
5974
  view: 'passkey-prompt',
5955
- email: this.recipient,
5975
+ recipient: this.recipient,
5956
5976
  pendingResult,
5957
5977
  error: errorMessage,
5958
5978
  });
@@ -6077,6 +6097,9 @@ class IdentityRenderer {
6077
6097
  token: data.token,
6078
6098
  identity: data.identity,
6079
6099
  identityType: data.identityType || 'email',
6100
+ svid: typeof data.svid === 'string' ? data.svid : undefined,
6101
+ sessionId: typeof data.session_id === 'string' ? data.session_id : undefined,
6102
+ refreshToken: typeof data.refresh_token === 'string' ? data.refresh_token : undefined,
6080
6103
  // For simple-mode flows the server also emits a signed
6081
6104
  // success-callback URL; without it the SDK has nowhere to send
6082
6105
  // the user after WebSocket success.
@@ -6123,7 +6146,7 @@ class IdentityRenderer {
6123
6146
  if (!result.redirect && await this.shouldShowPasskeyPrompt()) {
6124
6147
  this.setState({
6125
6148
  view: 'passkey-prompt',
6126
- email: this.recipient,
6149
+ recipient: this.recipient,
6127
6150
  pendingResult: result,
6128
6151
  });
6129
6152
  return;
@@ -6163,8 +6186,7 @@ class IdentityRenderer {
6163
6186
  if (wsResult.error === 'csp') {
6164
6187
  this.setState({
6165
6188
  view: 'error',
6166
- message: 'Connection blocked by security policy. Please contact the site administrator to add wss://*.sparkvault.com to the Content-Security-Policy connect-src directive.',
6167
- code: 'sparklink_csp_blocked',
6189
+ ...SPARKLINK_CSP_BLOCKED_ERROR,
6168
6190
  });
6169
6191
  }
6170
6192
  else {
@@ -6516,6 +6538,11 @@ class IdentityModule {
6516
6538
  * });
6517
6539
  */
6518
6540
  async verify(options = {}) {
6541
+ const redirectResult = await this.consumeRedirectResult();
6542
+ if (redirectResult) {
6543
+ options.onSuccess?.(redirectResult);
6544
+ return redirectResult;
6545
+ }
6519
6546
  if (this.renderer) {
6520
6547
  this.renderer.close();
6521
6548
  }
@@ -6627,8 +6654,19 @@ class IdentityModule {
6627
6654
  observer?.observe(document.body, { childList: true, subtree: true });
6628
6655
  });
6629
6656
  };
6630
- // Defer attachment until DOM is ready
6631
- onDomReady(attachToElements);
6657
+ // Defer attachment until DOM is ready, then complete any full-page
6658
+ // social-login redirect result before the user has to click again.
6659
+ onDomReady(() => {
6660
+ attachToElements();
6661
+ this.consumeRedirectResult()
6662
+ .then((result) => {
6663
+ if (result)
6664
+ options.onSuccess?.(result);
6665
+ })
6666
+ .catch((error) => {
6667
+ options.onError?.(error instanceof Error ? error : new Error(String(error)));
6668
+ });
6669
+ });
6632
6670
  // Return cleanup function
6633
6671
  return () => {
6634
6672
  observer?.disconnect();
@@ -6666,6 +6704,34 @@ class IdentityModule {
6666
6704
  }
6667
6705
  return payload;
6668
6706
  }
6707
+ /**
6708
+ * Complete full-page redirect results produced by social-login flows.
6709
+ * The Identity Product redirects back with `#token=...` so the token does
6710
+ * not hit server logs. Consume it once, validate the issuer/expiry shape,
6711
+ * then remove it from the URL bar.
6712
+ */
6713
+ async consumeRedirectResult() {
6714
+ if (typeof window === 'undefined' || !window.location.hash) {
6715
+ return null;
6716
+ }
6717
+ const params = new URLSearchParams(window.location.hash.slice(1));
6718
+ const token = params.get('token');
6719
+ if (!token) {
6720
+ return null;
6721
+ }
6722
+ const claims = await this.verifyToken(token);
6723
+ const result = {
6724
+ token,
6725
+ identity: claims.identity,
6726
+ identityType: claims.identity_type,
6727
+ svid: claims.svid,
6728
+ sessionId: claims.session_id,
6729
+ };
6730
+ if (typeof window.history?.replaceState === 'function') {
6731
+ window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
6732
+ }
6733
+ return result;
6734
+ }
6669
6735
  /**
6670
6736
  * Close the identity dialog/inline UI if open.
6671
6737
  */