@sparkvault/sdk-js 8.8.3 → 8.9.0

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.
@@ -1257,7 +1257,7 @@ const METHOD_REGISTRY = {
1257
1257
  type: 'passkey',
1258
1258
  name: 'Passkey',
1259
1259
  description: 'Use biometrics or security key',
1260
- icon: 'passkey',
1260
+ icon: 'fingerprint',
1261
1261
  },
1262
1262
  sparklink: {
1263
1263
  id: 'sparklink',
@@ -3731,12 +3731,22 @@ function createExpiredIcon() {
3731
3731
  return createAlertTriangleIcon('sv-expired-icon');
3732
3732
  }
3733
3733
  /**
3734
- * Method icons
3734
+ * Method icons. Every `MethodMetadata.icon` value in the registry must have a
3735
+ * case here. The returned glyph is tagged with `data-sv-method-icon` so a
3736
+ * mismatch is visible in the DOM (and assertable in tests) instead of a wrong
3737
+ * glyph silently standing in for the method.
3735
3738
  */
3736
3739
  function createMethodIcon(iconName) {
3740
+ const svg = methodIconGlyph(iconName);
3741
+ svg.setAttribute('data-sv-method-icon', iconName);
3742
+ return svg;
3743
+ }
3744
+ function methodIconGlyph(iconName) {
3737
3745
  switch (iconName) {
3738
3746
  case 'email':
3739
3747
  return createEmailIcon();
3748
+ case 'sms':
3749
+ return createSmsIcon();
3740
3750
  case 'phone':
3741
3751
  return createPhoneIcon();
3742
3752
  case 'fingerprint':
@@ -3760,7 +3770,9 @@ function createMethodIcon(iconName) {
3760
3770
  case 'users':
3761
3771
  return createUsersIcon();
3762
3772
  default:
3763
- return createEmailIcon();
3773
+ // Neutral placeholder — deliberately NOT the email envelope, so an
3774
+ // unmapped icon name surfaces the gap instead of impersonating email.
3775
+ return createGenericMethodIcon();
3764
3776
  }
3765
3777
  }
3766
3778
  function createEmailIcon() {
@@ -3773,6 +3785,20 @@ function createEmailIcon() {
3773
3785
  svg.appendChild(createPath('M18 5l-8 5.5L2 5'));
3774
3786
  return svg;
3775
3787
  }
3788
+ function createSmsIcon() {
3789
+ // Chat bubble — the text-message channel, distinct from the voice-call
3790
+ // handset (createPhoneIcon) so SMS and voice OTP read differently.
3791
+ const svg = createSvgElement('0 0 20 20', 20, 20);
3792
+ svg.setAttribute('stroke', 'currentColor');
3793
+ svg.setAttribute('stroke-width', '1.5');
3794
+ svg.setAttribute('stroke-linecap', 'round');
3795
+ svg.setAttribute('stroke-linejoin', 'round');
3796
+ svg.appendChild(createPath('M4 3.75h12A1.75 1.75 0 0117.75 5.5v5A1.75 1.75 0 0116 12.25H8.5L5 15.25V12.25H4A1.75 1.75 0 012.25 10.5v-5A1.75 1.75 0 014 3.75z'));
3797
+ svg.appendChild(createCircle(7, 8, 0.75, { fill: 'currentColor', stroke: 'none' }));
3798
+ svg.appendChild(createCircle(10, 8, 0.75, { fill: 'currentColor', stroke: 'none' }));
3799
+ svg.appendChild(createCircle(13, 8, 0.75, { fill: 'currentColor', stroke: 'none' }));
3800
+ return svg;
3801
+ }
3776
3802
  function createPhoneIcon() {
3777
3803
  const svg = createSvgElement('0 0 20 20', 20, 20);
3778
3804
  svg.setAttribute('stroke', 'currentColor');
@@ -3782,6 +3808,18 @@ function createPhoneIcon() {
3782
3808
  svg.appendChild(createPath('M18 14v2.5a1.5 1.5 0 01-1.64 1.5 14.85 14.85 0 01-6.47-2.3 14.63 14.63 0 01-4.5-4.5A14.85 14.85 0 013.1 4.64 1.5 1.5 0 014.59 3H7.1a1.5 1.5 0 011.5 1.29 9.63 9.63 0 00.52 2.11 1.5 1.5 0 01-.34 1.58l-.95.95a12 12 0 004.5 4.5l.95-.95a1.5 1.5 0 011.58-.34 9.63 9.63 0 002.11.52A1.5 1.5 0 0118 14z'));
3783
3809
  return svg;
3784
3810
  }
3811
+ function createGenericMethodIcon() {
3812
+ // Neutral rounded badge with a center dot — a placeholder for an unmapped
3813
+ // icon name, deliberately unlike any real method glyph.
3814
+ const svg = createSvgElement('0 0 20 20', 20, 20);
3815
+ svg.setAttribute('stroke', 'currentColor');
3816
+ svg.setAttribute('stroke-width', '1.5');
3817
+ svg.setAttribute('stroke-linecap', 'round');
3818
+ svg.setAttribute('stroke-linejoin', 'round');
3819
+ svg.appendChild(createPath('M6 2.75h8A3.25 3.25 0 0117.25 6v8A3.25 3.25 0 0114 17.25H6A3.25 3.25 0 012.75 14V6A3.25 3.25 0 016 2.75z'));
3820
+ svg.appendChild(createCircle(10, 10, 1.25, { fill: 'currentColor', stroke: 'none' }));
3821
+ return svg;
3822
+ }
3785
3823
  function createFingerprintIcon() {
3786
3824
  const svg = createSvgElement('0 0 20 20', 20, 20);
3787
3825
  svg.setAttribute('stroke', 'currentColor');
@@ -4573,7 +4611,8 @@ class MethodSelectView {
4573
4611
  const link = document.createElement('button');
4574
4612
  link.className = 'sv-back-link';
4575
4613
  link.appendChild(createBackArrowIcon());
4576
- link.appendChild(document.createTextNode(' Change email'));
4614
+ const label = this.props.identityType === 'phone' ? ' Change phone number' : ' Change email';
4615
+ link.appendChild(document.createTextNode(label));
4577
4616
  link.addEventListener('click', this.boundHandleBack);
4578
4617
  return link;
4579
4618
  }
@@ -6241,18 +6280,44 @@ class IdentityRenderer {
6241
6280
  this.passkeyHandler = new PasskeyHandler(api, this.verificationState);
6242
6281
  this.otpHandler = new OtpHandler(api, this.verificationState);
6243
6282
  this.sparkLinkHandler = new SparkLinkHandler(api, this.verificationState);
6244
- // Set initial identity from options
6245
- if (options.email) {
6246
- this.verificationState.setIdentity(options.email, 'email');
6247
- }
6248
- else if (options.phone) {
6249
- this.verificationState.setIdentity(options.phone, 'phone');
6250
- }
6283
+ // Seed the identity being verified from the render options.
6284
+ this.applyInitialIdentity();
6251
6285
  // Set auth context for OIDC/simple mode flows
6252
6286
  if (options.authContext) {
6253
6287
  this.verificationState.setAuthContext(options.authContext);
6254
6288
  }
6255
6289
  }
6290
+ /**
6291
+ * Seed the verification identity from the render options, deriving the
6292
+ * channel (email vs phone) from the value itself rather than trusting which
6293
+ * option field carried it. The hosted login forwards a simple-mode identity
6294
+ * hint — which may be a phone number — as `email`; keying off the value keeps
6295
+ * the method list AND the OTP delivery target aligned with the real channel
6296
+ * instead of falling back to the email methods. Normalizes to E.164 /
6297
+ * lowercased email so the code goes to the canonical identifier.
6298
+ */
6299
+ applyInitialIdentity() {
6300
+ const explicitPhone = typeof this.options.phone === 'string' && this.options.phone.length > 0;
6301
+ const raw = explicitPhone ? this.options.phone : this.options.email;
6302
+ if (!raw)
6303
+ return;
6304
+ if (explicitPhone || looksLikePhone(raw)) {
6305
+ this.verificationState.setIdentity(validatePhone(raw) ?? raw, 'phone');
6306
+ }
6307
+ else {
6308
+ this.verificationState.setIdentity(validateEmail(raw) ?? raw, 'email');
6309
+ }
6310
+ }
6311
+ /**
6312
+ * True when the identifier is fixed by the flow and the person must prove
6313
+ * that exact identity — the invite / simple-redirect case. There is no
6314
+ * identifier-entry step to return to, so the picker must not offer a
6315
+ * "change identity" back link that would let them verify a different
6316
+ * identifier than the one they were invited as.
6317
+ */
6318
+ isIdentityFixed() {
6319
+ return this.verificationState.authContext?.simpleMode !== undefined;
6320
+ }
6256
6321
  /**
6257
6322
  * Fire the host's onSuccess callback, swallowing any exception so a
6258
6323
  * misbehaving host handler can't block the post-success redirect the
@@ -6632,9 +6697,15 @@ class IdentityRenderer {
6632
6697
  case 'method-select':
6633
6698
  return new MethodSelectView({
6634
6699
  email: state.email,
6700
+ identityType: this.identityType,
6635
6701
  methods: state.methods,
6636
6702
  onSelectMethod: (method) => this.handleMethodSelect(method, true),
6637
- onBack: state.email ? () => this.showIdentityInput() : undefined,
6703
+ // Offer "change identity" only when the person can actually enter a
6704
+ // different identifier. An invite/simple-redirect fixes the identity,
6705
+ // so there is no identifier-input step to return to.
6706
+ onBack: state.email && !this.isIdentityFixed()
6707
+ ? () => this.showIdentityInput()
6708
+ : undefined,
6638
6709
  });
6639
6710
  case 'otp-verify':
6640
6711
  return new OtpVerifyView({
@@ -6829,7 +6900,14 @@ class IdentityRenderer {
6829
6900
  void this.launchPasskeyVerify(true);
6830
6901
  return;
6831
6902
  }
6832
- if (methods.length === 1) {
6903
+ // A single enabled method normally auto-fires so the recipient skips a
6904
+ // redundant one-item picker. But when the identity is fixed by an invite,
6905
+ // auto-firing an OTP would silently send a code (another SMS/email) the
6906
+ // instant the recipient opens the link, with no consent and re-sent on every
6907
+ // reload. In that case render the picker as a one-tap consent gate instead;
6908
+ // the recipient taps to request the code. (Passkey auto-route above still
6909
+ // applies — a biometric prompt costs nothing and can be dismissed.)
6910
+ if (methods.length === 1 && !this.isIdentityFixed()) {
6833
6911
  this.handleMethodSelect(methods[0]);
6834
6912
  return;
6835
6913
  }