@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.
@@ -33,6 +33,24 @@ export declare class IdentityRenderer {
33
33
  private sparkLinkClaiming;
34
34
  private sparkLinkRetryTimer;
35
35
  constructor(container: Container, api: IdentityApi, options: VerifyOptions, callbacks: RendererCallbacks);
36
+ /**
37
+ * Seed the verification identity from the render options, deriving the
38
+ * channel (email vs phone) from the value itself rather than trusting which
39
+ * option field carried it. The hosted login forwards a simple-mode identity
40
+ * hint — which may be a phone number — as `email`; keying off the value keeps
41
+ * the method list AND the OTP delivery target aligned with the real channel
42
+ * instead of falling back to the email methods. Normalizes to E.164 /
43
+ * lowercased email so the code goes to the canonical identifier.
44
+ */
45
+ private applyInitialIdentity;
46
+ /**
47
+ * True when the identifier is fixed by the flow and the person must prove
48
+ * that exact identity — the invite / simple-redirect case. There is no
49
+ * identifier-entry step to return to, so the picker must not offer a
50
+ * "change identity" back link that would let them verify a different
51
+ * identifier than the one they were invited as.
52
+ */
53
+ private isIdentityFixed;
36
54
  /**
37
55
  * Fire the host's onSuccess callback, swallowing any exception so a
38
56
  * misbehaving host handler can't block the post-success redirect the
@@ -34,6 +34,9 @@ export declare function createErrorIcon(): SVGSVGElement;
34
34
  */
35
35
  export declare function createExpiredIcon(): SVGSVGElement;
36
36
  /**
37
- * Method icons
37
+ * Method icons. Every `MethodMetadata.icon` value in the registry must have a
38
+ * case here. The returned glyph is tagged with `data-sv-method-icon` so a
39
+ * mismatch is visible in the DOM (and assertable in tests) instead of a wrong
40
+ * glyph silently standing in for the method.
38
41
  */
39
42
  export declare function createMethodIcon(iconName: string): SVGSVGElement;
@@ -4,9 +4,12 @@
4
4
  * Displays available authentication methods for the user to choose from.
5
5
  */
6
6
  import type { View } from './base';
7
+ import type { IdentityType } from './identity-input';
7
8
  import type { MethodMetadata } from '../types';
8
9
  export interface MethodSelectViewProps {
9
10
  email?: string;
11
+ /** Channel of the identifier being verified — drives the back-link label. */
12
+ identityType?: IdentityType;
10
13
  methods: MethodMetadata[];
11
14
  onSelectMethod: (method: MethodMetadata) => void;
12
15
  onBack?: () => void;
@@ -1261,7 +1261,7 @@ const METHOD_REGISTRY = {
1261
1261
  type: 'passkey',
1262
1262
  name: 'Passkey',
1263
1263
  description: 'Use biometrics or security key',
1264
- icon: 'passkey',
1264
+ icon: 'fingerprint',
1265
1265
  },
1266
1266
  sparklink: {
1267
1267
  id: 'sparklink',
@@ -3735,12 +3735,22 @@ function createExpiredIcon() {
3735
3735
  return createAlertTriangleIcon('sv-expired-icon');
3736
3736
  }
3737
3737
  /**
3738
- * Method icons
3738
+ * Method icons. Every `MethodMetadata.icon` value in the registry must have a
3739
+ * case here. The returned glyph is tagged with `data-sv-method-icon` so a
3740
+ * mismatch is visible in the DOM (and assertable in tests) instead of a wrong
3741
+ * glyph silently standing in for the method.
3739
3742
  */
3740
3743
  function createMethodIcon(iconName) {
3744
+ const svg = methodIconGlyph(iconName);
3745
+ svg.setAttribute('data-sv-method-icon', iconName);
3746
+ return svg;
3747
+ }
3748
+ function methodIconGlyph(iconName) {
3741
3749
  switch (iconName) {
3742
3750
  case 'email':
3743
3751
  return createEmailIcon();
3752
+ case 'sms':
3753
+ return createSmsIcon();
3744
3754
  case 'phone':
3745
3755
  return createPhoneIcon();
3746
3756
  case 'fingerprint':
@@ -3764,7 +3774,9 @@ function createMethodIcon(iconName) {
3764
3774
  case 'users':
3765
3775
  return createUsersIcon();
3766
3776
  default:
3767
- return createEmailIcon();
3777
+ // Neutral placeholder — deliberately NOT the email envelope, so an
3778
+ // unmapped icon name surfaces the gap instead of impersonating email.
3779
+ return createGenericMethodIcon();
3768
3780
  }
3769
3781
  }
3770
3782
  function createEmailIcon() {
@@ -3777,6 +3789,20 @@ function createEmailIcon() {
3777
3789
  svg.appendChild(createPath('M18 5l-8 5.5L2 5'));
3778
3790
  return svg;
3779
3791
  }
3792
+ function createSmsIcon() {
3793
+ // Chat bubble — the text-message channel, distinct from the voice-call
3794
+ // handset (createPhoneIcon) so SMS and voice OTP read differently.
3795
+ const svg = createSvgElement('0 0 20 20', 20, 20);
3796
+ svg.setAttribute('stroke', 'currentColor');
3797
+ svg.setAttribute('stroke-width', '1.5');
3798
+ svg.setAttribute('stroke-linecap', 'round');
3799
+ svg.setAttribute('stroke-linejoin', 'round');
3800
+ 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'));
3801
+ svg.appendChild(createCircle(7, 8, 0.75, { fill: 'currentColor', stroke: 'none' }));
3802
+ svg.appendChild(createCircle(10, 8, 0.75, { fill: 'currentColor', stroke: 'none' }));
3803
+ svg.appendChild(createCircle(13, 8, 0.75, { fill: 'currentColor', stroke: 'none' }));
3804
+ return svg;
3805
+ }
3780
3806
  function createPhoneIcon() {
3781
3807
  const svg = createSvgElement('0 0 20 20', 20, 20);
3782
3808
  svg.setAttribute('stroke', 'currentColor');
@@ -3786,6 +3812,18 @@ function createPhoneIcon() {
3786
3812
  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'));
3787
3813
  return svg;
3788
3814
  }
3815
+ function createGenericMethodIcon() {
3816
+ // Neutral rounded badge with a center dot — a placeholder for an unmapped
3817
+ // icon name, deliberately unlike any real method glyph.
3818
+ const svg = createSvgElement('0 0 20 20', 20, 20);
3819
+ svg.setAttribute('stroke', 'currentColor');
3820
+ svg.setAttribute('stroke-width', '1.5');
3821
+ svg.setAttribute('stroke-linecap', 'round');
3822
+ svg.setAttribute('stroke-linejoin', 'round');
3823
+ 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'));
3824
+ svg.appendChild(createCircle(10, 10, 1.25, { fill: 'currentColor', stroke: 'none' }));
3825
+ return svg;
3826
+ }
3789
3827
  function createFingerprintIcon() {
3790
3828
  const svg = createSvgElement('0 0 20 20', 20, 20);
3791
3829
  svg.setAttribute('stroke', 'currentColor');
@@ -4577,7 +4615,8 @@ class MethodSelectView {
4577
4615
  const link = document.createElement('button');
4578
4616
  link.className = 'sv-back-link';
4579
4617
  link.appendChild(createBackArrowIcon());
4580
- link.appendChild(document.createTextNode(' Change email'));
4618
+ const label = this.props.identityType === 'phone' ? ' Change phone number' : ' Change email';
4619
+ link.appendChild(document.createTextNode(label));
4581
4620
  link.addEventListener('click', this.boundHandleBack);
4582
4621
  return link;
4583
4622
  }
@@ -6245,18 +6284,44 @@ class IdentityRenderer {
6245
6284
  this.passkeyHandler = new PasskeyHandler(api, this.verificationState);
6246
6285
  this.otpHandler = new OtpHandler(api, this.verificationState);
6247
6286
  this.sparkLinkHandler = new SparkLinkHandler(api, this.verificationState);
6248
- // Set initial identity from options
6249
- if (options.email) {
6250
- this.verificationState.setIdentity(options.email, 'email');
6251
- }
6252
- else if (options.phone) {
6253
- this.verificationState.setIdentity(options.phone, 'phone');
6254
- }
6287
+ // Seed the identity being verified from the render options.
6288
+ this.applyInitialIdentity();
6255
6289
  // Set auth context for OIDC/simple mode flows
6256
6290
  if (options.authContext) {
6257
6291
  this.verificationState.setAuthContext(options.authContext);
6258
6292
  }
6259
6293
  }
6294
+ /**
6295
+ * Seed the verification identity from the render options, deriving the
6296
+ * channel (email vs phone) from the value itself rather than trusting which
6297
+ * option field carried it. The hosted login forwards a simple-mode identity
6298
+ * hint — which may be a phone number — as `email`; keying off the value keeps
6299
+ * the method list AND the OTP delivery target aligned with the real channel
6300
+ * instead of falling back to the email methods. Normalizes to E.164 /
6301
+ * lowercased email so the code goes to the canonical identifier.
6302
+ */
6303
+ applyInitialIdentity() {
6304
+ const explicitPhone = typeof this.options.phone === 'string' && this.options.phone.length > 0;
6305
+ const raw = explicitPhone ? this.options.phone : this.options.email;
6306
+ if (!raw)
6307
+ return;
6308
+ if (explicitPhone || looksLikePhone(raw)) {
6309
+ this.verificationState.setIdentity(validatePhone(raw) ?? raw, 'phone');
6310
+ }
6311
+ else {
6312
+ this.verificationState.setIdentity(validateEmail(raw) ?? raw, 'email');
6313
+ }
6314
+ }
6315
+ /**
6316
+ * True when the identifier is fixed by the flow and the person must prove
6317
+ * that exact identity — the invite / simple-redirect case. There is no
6318
+ * identifier-entry step to return to, so the picker must not offer a
6319
+ * "change identity" back link that would let them verify a different
6320
+ * identifier than the one they were invited as.
6321
+ */
6322
+ isIdentityFixed() {
6323
+ return this.verificationState.authContext?.simpleMode !== undefined;
6324
+ }
6260
6325
  /**
6261
6326
  * Fire the host's onSuccess callback, swallowing any exception so a
6262
6327
  * misbehaving host handler can't block the post-success redirect the
@@ -6636,9 +6701,15 @@ class IdentityRenderer {
6636
6701
  case 'method-select':
6637
6702
  return new MethodSelectView({
6638
6703
  email: state.email,
6704
+ identityType: this.identityType,
6639
6705
  methods: state.methods,
6640
6706
  onSelectMethod: (method) => this.handleMethodSelect(method, true),
6641
- onBack: state.email ? () => this.showIdentityInput() : undefined,
6707
+ // Offer "change identity" only when the person can actually enter a
6708
+ // different identifier. An invite/simple-redirect fixes the identity,
6709
+ // so there is no identifier-input step to return to.
6710
+ onBack: state.email && !this.isIdentityFixed()
6711
+ ? () => this.showIdentityInput()
6712
+ : undefined,
6642
6713
  });
6643
6714
  case 'otp-verify':
6644
6715
  return new OtpVerifyView({
@@ -6833,7 +6904,14 @@ class IdentityRenderer {
6833
6904
  void this.launchPasskeyVerify(true);
6834
6905
  return;
6835
6906
  }
6836
- if (methods.length === 1) {
6907
+ // A single enabled method normally auto-fires so the recipient skips a
6908
+ // redundant one-item picker. But when the identity is fixed by an invite,
6909
+ // auto-firing an OTP would silently send a code (another SMS/email) the
6910
+ // instant the recipient opens the link, with no consent and re-sent on every
6911
+ // reload. In that case render the picker as a one-tap consent gate instead;
6912
+ // the recipient taps to request the code. (Passkey auto-route above still
6913
+ // applies — a biometric prompt costs nothing and can be dismissed.)
6914
+ if (methods.length === 1 && !this.isIdentityFixed()) {
6837
6915
  this.handleMethodSelect(methods[0]);
6838
6916
  return;
6839
6917
  }