@sparkvault/sdk-js 8.6.1 → 8.8.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.
@@ -774,6 +774,91 @@ function generateState() {
774
774
  crypto.getRandomValues(array);
775
775
  return Array.from(array, (b) => b.toString(16).padStart(2, '0')).join('');
776
776
  }
777
+ /**
778
+ * Generate a PKCE code_verifier (RFC 7636): 32 random bytes, base64url —
779
+ * 43 URL-safe characters.
780
+ */
781
+ function generateCodeVerifier() {
782
+ const array = new Uint8Array(32);
783
+ crypto.getRandomValues(array);
784
+ return base64urlEncode(array);
785
+ }
786
+ /**
787
+ * Compute the S256 PKCE code_challenge for a verifier:
788
+ * base64url(SHA-256(verifier)).
789
+ */
790
+ async function computeS256Challenge(codeVerifier) {
791
+ const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(codeVerifier));
792
+ return arrayBufferToBase64url(digest);
793
+ }
794
+ /**
795
+ * Build the sign-in page URL on the Identity origin. Single source for BOTH
796
+ * delivery modes: the popup (opener + postMessage) and the same-tab redirect
797
+ * (redirect_uri + state + code_challenge → one-time code in the fragment).
798
+ */
799
+ function buildSigninUrl(config, options, extras) {
800
+ const params = new URLSearchParams({ origin: window.location.origin });
801
+ // Identifier prefill - the sign-in page collects it itself when absent.
802
+ if (options.email) {
803
+ params.set('email', options.email);
804
+ }
805
+ else if (options.phone) {
806
+ params.set('phone', options.phone);
807
+ }
808
+ // Auth context, in the query shape the sign-in page reads server-side:
809
+ // OIDC rides `auth_request`; simple redirect rides `mode=simple` + the
810
+ // opaque `session` (the page loads success/failure URLs from the session).
811
+ const authContext = options.authContext;
812
+ if (authContext?.authRequestId) {
813
+ params.set('auth_request', authContext.authRequestId);
814
+ }
815
+ else if (authContext?.simpleMode?.sessionId) {
816
+ params.set('mode', 'simple');
817
+ params.set('session', authContext.simpleMode.sessionId);
818
+ }
819
+ if (extras) {
820
+ params.set('redirect_uri', extras.redirectUri);
821
+ params.set('state', extras.state);
822
+ params.set('code_challenge', extras.codeChallenge);
823
+ }
824
+ return `${config.identityBaseUrl}/${config.accountId}/signin?${params}`;
825
+ }
826
+ /**
827
+ * Warm the connection to another origin by injecting `<link rel="preconnect">`
828
+ * hints (one plain for top-level navigations, one `crossorigin` for CORS
829
+ * fetches). The sign-in popup/redirect and every flow API call reuse the open
830
+ * connection, which removes the cold-connection stall mobile browsers hit on
831
+ * the first navigation to the Identity origin. No-op off-DOM, for the page's
832
+ * own origin, and when the hints already exist.
833
+ */
834
+ function ensurePreconnect(baseUrl) {
835
+ if (typeof document === 'undefined' || typeof window === 'undefined' || !document.head) {
836
+ return;
837
+ }
838
+ let origin;
839
+ try {
840
+ origin = new URL(baseUrl).origin;
841
+ }
842
+ catch {
843
+ return;
844
+ }
845
+ if (origin === window.location.origin) {
846
+ return;
847
+ }
848
+ for (const crossOrigin of [false, true]) {
849
+ const selector = `link[rel="preconnect"][href="${origin}"]${crossOrigin ? '[crossorigin]' : ':not([crossorigin])'}`;
850
+ if (document.head.querySelector(selector)) {
851
+ continue;
852
+ }
853
+ const link = document.createElement('link');
854
+ link.rel = 'preconnect';
855
+ link.href = origin;
856
+ if (crossOrigin) {
857
+ link.crossOrigin = 'anonymous';
858
+ }
859
+ document.head.appendChild(link);
860
+ }
861
+ }
777
862
 
778
863
  /**
779
864
  * Identity API Client
@@ -859,6 +944,19 @@ class IdentityApi extends SparkVaultApi {
859
944
  const body = identityType === 'phone' ? { phone: identity } : { email: identity };
860
945
  return this.request('POST', '/passkey/check', body);
861
946
  }
947
+ /**
948
+ * Redeem a one-time sign-in code (with its PKCE verifier) for the sign-in
949
+ * result — the shared return leg for `flow: 'redirect'` and the silent SSO
950
+ * self-heal. The code arrives in the URL fragment after the hosted page
951
+ * navigates back; it is single-use, 60s-lived, and bound to this page's
952
+ * origin server-side.
953
+ */
954
+ async redeemHandoffCode(code, codeVerifier) {
955
+ return this.request('POST', '/signin/redeem', {
956
+ code,
957
+ code_verifier: codeVerifier,
958
+ });
959
+ }
862
960
  /**
863
961
  * Build auth context params for API requests (OIDC/simple mode).
864
962
  * Converts AuthContext to snake_case params expected by backend.
@@ -1955,12 +2053,12 @@ class SparkLinkHandler {
1955
2053
  /**
1956
2054
  * Identity Modal Styles
1957
2055
  *
1958
- * Enterprise-grade styling following Stripe/Adobe design principles:
1959
- * - Clean, minimal aesthetic with purposeful whitespace
2056
+ * SparkVault design system, product register:
2057
+ * - Quiet slate neutrals; Action Blue carries all interactivity
1960
2058
  * - 4px base spacing unit for consistency
1961
- * - Subtle depth through shadows and borders (not gradients)
1962
- * - Professional typography with clear hierarchy
1963
- * - Refined color palette with single accent
2059
+ * - Hairline borders over shadows; shadows minimal and DS-weighted
2060
+ * - Restrained motion: 120-280ms, standard/decelerate curves only
2061
+ * - One accent per surface; tenant-tintable via --sv-primary
1964
2062
  */
1965
2063
  const STYLE_ID$1 = 'sparkvault-identity-styles';
1966
2064
  /**
@@ -2023,56 +2121,69 @@ function getStyles(options) {
2023
2121
  // The brand accent is driven by the `--sv-primary` / `--sv-primary-hover`
2024
2122
  // CSS custom properties so a host page (e.g. the SparkVault sign-in page) can
2025
2123
  // tint the whole flow to the tenant's brand color by setting them on `:root`.
2026
- // The literals are the fallback - when no host sets the variables the UI is
2027
- // pixel-identical to before. The focus glow is derived from the same accent
2028
- // via color-mix so it tracks the brand too.
2029
- const accent = 'var(--sv-primary, #4F46E5)';
2124
+ // The literals are the fallback - when no host sets the variables the flow
2125
+ // renders in SparkVault Action Blue. The soft focus glow and the two-tone
2126
+ // focus ring are both derived from the same accent via color-mix so they
2127
+ // track the tenant tint too.
2128
+ const accent = 'var(--sv-primary, #216bde)';
2129
+ const surface = isDark ? '#030712' : '#ffffff';
2130
+ // Lightened accent for the outer ring of the two-tone focus indicator
2131
+ // (lands on the design system's #4383eb at the default accent).
2132
+ const focusRingColor = `color-mix(in srgb, ${accent} 80%, white)`;
2030
2133
  const tokens = {
2031
2134
  // Colors
2032
2135
  primary: accent,
2033
- primaryHover: 'var(--sv-primary-hover, #4338CA)',
2136
+ primaryHover: 'var(--sv-primary-hover, #0d5bcd)',
2034
2137
  primaryLight: `color-mix(in srgb, ${accent} ${isDark ? '20%' : '9%'}, transparent)`,
2035
- error: '#DC2626',
2036
- errorLight: isDark ? 'rgba(220, 38, 38, 0.15)' : '#FEF2F2',
2037
- errorBorder: isDark ? 'rgba(220, 38, 38, 0.3)' : '#FECACA',
2138
+ error: isDark ? '#e6443d' : '#b02b27',
2139
+ errorLight: isDark ? 'rgba(230, 68, 61, 0.12)' : '#fee2e2',
2140
+ errorBorder: isDark ? 'rgba(230, 68, 61, 0.35)' : '#fecaca',
2141
+ // Filled danger buttons stay on the fixed danger tier (white label, AA in
2142
+ // both themes).
2143
+ danger: '#b02b27',
2144
+ dangerHover: '#9a221f',
2145
+ warningIcon: isDark ? '#e6ad00' : '#8a5600',
2038
2146
  // Backgrounds
2039
- bg: isDark ? '#0F0F0F' : '#FFFFFF',
2040
- bgSubtle: isDark ? '#171717' : '#FAFAFA',
2041
- bgHover: isDark ? '#1A1A1A' : '#F5F5F5',
2042
- bgInput: isDark ? '#0F0F0F' : '#FFFFFF',
2147
+ bg: surface,
2148
+ bgSubtle: isDark ? 'rgba(255, 255, 255, 0.05)' : '#f8fafc',
2149
+ bgHover: isDark ? 'rgba(255, 255, 255, 0.08)' : '#f1f5f9',
2150
+ bgInput: isDark ? 'rgba(255, 255, 255, 0.04)' : '#ffffff',
2043
2151
  // Borders
2044
- border: isDark ? '#262626' : '#E5E5E5',
2045
- borderHover: isDark ? '#404040' : '#D4D4D4',
2152
+ border: isDark ? 'rgba(255, 255, 255, 0.10)' : '#e2e8f0',
2153
+ borderHover: isDark ? 'rgba(255, 255, 255, 0.18)' : '#cbd5e1',
2046
2154
  borderFocus: accent,
2155
+ chevron: isDark ? 'rgba(255, 255, 255, 0.35)' : '#cbd5e1',
2047
2156
  // Text
2048
- textPrimary: isDark ? '#FAFAFA' : '#0A0A0A',
2049
- textSecondary: isDark ? '#A3A3A3' : '#525252',
2050
- textMuted: isDark ? '#737373' : '#737373',
2051
- textOnPrimary: '#FFFFFF',
2052
- // Shadows
2157
+ textPrimary: isDark ? 'rgba(255, 255, 255, 0.92)' : '#0f172a',
2158
+ textSecondary: isDark ? 'rgba(255, 255, 255, 0.62)' : '#475569',
2159
+ textMuted: isDark ? 'rgba(255, 255, 255, 0.45)' : '#64748b',
2160
+ textOnPrimary: '#ffffff',
2161
+ // Focus — two-tone ring: inner surface gap + accent-derived outer ring.
2162
+ focusRing: `0 0 0 2px ${surface}, 0 0 0 4px ${focusRingColor}`,
2163
+ // Shadows — DS-weight: lean on hairlines, keep elevation subtle.
2053
2164
  shadowSm: isDark
2054
2165
  ? '0 1px 2px rgba(0, 0, 0, 0.4)'
2055
- : '0 1px 2px rgba(0, 0, 0, 0.04)',
2166
+ : '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
2056
2167
  shadowLg: isDark
2057
- ? '0 8px 24px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.05)'
2058
- : '0 8px 24px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04)',
2168
+ ? '0 8px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.10)'
2169
+ : '0 8px 24px rgba(15, 23, 42, 0.12)',
2059
2170
  };
2060
2171
  return `
2061
2172
  /* ========================================
2062
2173
  MOTION SYSTEM — shared duration/easing tokens so every transition in
2063
- the flow is consistent. Enters decelerate (ease-out-expo), exits
2064
- accelerate, spring is reserved for the success moment.
2174
+ the flow is consistent. 120/180/280ms tiers; standard and decelerate
2175
+ curves only, never overshoot.
2065
2176
  ======================================== */
2066
2177
  :root {
2067
- --sv-dur-instant: 80ms;
2068
- --sv-dur-fast: 140ms;
2069
- --sv-dur-base: 220ms;
2070
- --sv-dur-slow: 320ms;
2071
- --sv-dur-slower: 480ms;
2178
+ --sv-dur-instant: 120ms;
2179
+ --sv-dur-fast: 120ms;
2180
+ --sv-dur-base: 180ms;
2181
+ --sv-dur-slow: 280ms;
2182
+ --sv-dur-slower: 280ms;
2072
2183
  --sv-ease-standard: cubic-bezier(0.2, 0, 0, 1);
2073
- --sv-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
2074
- --sv-ease-accelerate: cubic-bezier(0.3, 0, 1, 1);
2075
- --sv-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
2184
+ --sv-ease-out: cubic-bezier(0, 0, 0.2, 1);
2185
+ --sv-ease-accelerate: cubic-bezier(0.2, 0, 0, 1);
2186
+ --sv-ease-spring: cubic-bezier(0.2, 0, 0, 1);
2076
2187
  }
2077
2188
 
2078
2189
  /* Each mounted view enters with a calm fade + rise. Applied by the renderer
@@ -2097,7 +2208,7 @@ function getStyles(options) {
2097
2208
  .sv-overlay {
2098
2209
  position: fixed;
2099
2210
  inset: 0;
2100
- background: rgba(0, 0, 0, ${isDark ? '0.7' : '0.5'});
2211
+ background: ${isDark ? 'rgba(0, 0, 0, 0.7)' : 'rgba(15, 23, 42, 0.6)'};
2101
2212
  display: flex;
2102
2213
  align-items: center;
2103
2214
  justify-content: center;
@@ -2116,7 +2227,7 @@ function getStyles(options) {
2116
2227
 
2117
2228
  .sv-modal {
2118
2229
  background: ${tokens.bg};
2119
- border-radius: 16px;
2230
+ border-radius: 12px;
2120
2231
  box-shadow: ${tokens.shadowLg};
2121
2232
  width: 100%;
2122
2233
  max-width: 400px;
@@ -2137,7 +2248,7 @@ function getStyles(options) {
2137
2248
  padding: 14px 20px;
2138
2249
  border-bottom: 1px solid ${tokens.border};
2139
2250
  background: ${tokens.bg};
2140
- border-radius: 16px 16px 0 0;
2251
+ border-radius: 12px 12px 0 0;
2141
2252
  flex-shrink: 0;
2142
2253
  }
2143
2254
 
@@ -2175,10 +2286,10 @@ function getStyles(options) {
2175
2286
  justify-content: center;
2176
2287
  background: ${tokens.bgSubtle};
2177
2288
  border: none;
2178
- border-radius: 8px;
2289
+ border-radius: 6px;
2179
2290
  cursor: pointer;
2180
2291
  color: ${tokens.textSecondary};
2181
- transition: background 0.15s ease, color 0.15s ease;
2292
+ transition: background var(--sv-dur-fast) var(--sv-ease-standard), color var(--sv-dur-fast) var(--sv-ease-standard);
2182
2293
  }
2183
2294
 
2184
2295
  .sv-close-btn:hover {
@@ -2187,12 +2298,8 @@ function getStyles(options) {
2187
2298
  }
2188
2299
 
2189
2300
  .sv-close-btn:focus-visible {
2190
- outline: 2px solid ${tokens.borderFocus};
2191
- outline-offset: 2px;
2192
- }
2193
-
2194
- .sv-close-btn:active {
2195
- transform: scale(0.96);
2301
+ outline: none;
2302
+ box-shadow: ${tokens.focusRing};
2196
2303
  }
2197
2304
 
2198
2305
  /* ========================================
@@ -2212,10 +2319,10 @@ function getStyles(options) {
2212
2319
  .sv-title {
2213
2320
  font-size: 21px;
2214
2321
  font-weight: 600;
2215
- letter-spacing: -0.021em;
2322
+ letter-spacing: -0.02em;
2216
2323
  line-height: 1.22;
2217
2324
  margin: 0 0 7px 0;
2218
- text-align: center;
2325
+ text-align: left;
2219
2326
  color: ${tokens.textPrimary};
2220
2327
  }
2221
2328
 
@@ -2225,10 +2332,17 @@ function getStyles(options) {
2225
2332
  line-height: 1.5;
2226
2333
  color: ${tokens.textSecondary};
2227
2334
  margin: 0 0 16px 0;
2228
- text-align: center;
2335
+ text-align: left;
2229
2336
  text-wrap: balance;
2230
2337
  }
2231
2338
 
2339
+ /* Icon-led ceremony screens (passkey set-up / sign-in) are a fully
2340
+ centered composition: the headline and subtitle follow the glyph. */
2341
+ div:has(> .sv-passkey-icon) ~ .sv-title,
2342
+ div:has(> .sv-passkey-icon) ~ .sv-subtitle {
2343
+ text-align: center;
2344
+ }
2345
+
2232
2346
  .sv-subtitle strong {
2233
2347
  color: ${tokens.textPrimary};
2234
2348
  font-weight: 500;
@@ -2257,12 +2371,12 @@ function getStyles(options) {
2257
2371
  font-size: 15px;
2258
2372
  font-weight: 400;
2259
2373
  line-height: 1.4;
2260
- border: 1px solid ${tokens.borderHover};
2261
- border-radius: 10px;
2374
+ border: 1px solid ${tokens.border};
2375
+ border-radius: 8px;
2262
2376
  background: ${tokens.bgInput};
2263
2377
  color: ${tokens.textPrimary};
2264
2378
  box-sizing: border-box;
2265
- box-shadow: 0 1px 1px ${isDark ? 'rgba(0,0,0,0.3)' : 'rgba(10,10,10,0.04)'};
2379
+ box-shadow: ${tokens.shadowSm};
2266
2380
  transition: border-color var(--sv-dur-fast) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard);
2267
2381
  }
2268
2382
 
@@ -2292,7 +2406,7 @@ function getStyles(options) {
2292
2406
 
2293
2407
  .sv-input.sv-input-error:focus,
2294
2408
  .sv-input.sv-email-input-error:focus {
2295
- box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
2409
+ box-shadow: 0 0 0 3px ${tokens.errorLight};
2296
2410
  }
2297
2411
 
2298
2412
  /* ========================================
@@ -2311,15 +2425,15 @@ function getStyles(options) {
2311
2425
  letter-spacing: -0.006em;
2312
2426
  line-height: 1.35;
2313
2427
  border: none;
2314
- border-radius: 10px;
2428
+ border-radius: 8px;
2315
2429
  cursor: pointer;
2316
- transition: background var(--sv-dur-fast) var(--sv-ease-standard), transform var(--sv-dur-instant) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard);
2430
+ transition: background var(--sv-dur-fast) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard);
2317
2431
  box-sizing: border-box;
2318
2432
  }
2319
2433
 
2320
2434
  .sv-btn:focus-visible {
2321
- outline: 2px solid ${tokens.borderFocus};
2322
- outline-offset: 2px;
2435
+ outline: none;
2436
+ box-shadow: ${tokens.focusRing};
2323
2437
  }
2324
2438
 
2325
2439
  .sv-btn:disabled {
@@ -2327,8 +2441,9 @@ function getStyles(options) {
2327
2441
  cursor: not-allowed;
2328
2442
  }
2329
2443
 
2444
+ /* Press = visual compression via an inset shadow, never scale. */
2330
2445
  .sv-btn:active:not(:disabled) {
2331
- transform: scale(0.98);
2446
+ box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.2);
2332
2447
  }
2333
2448
 
2334
2449
  /* Primary Button */
@@ -2344,7 +2459,7 @@ function getStyles(options) {
2344
2459
  background: ${tokens.primaryHover};
2345
2460
  }
2346
2461
 
2347
- /* Secondary Button */
2462
+ /* Secondary Button — quiet: subtle fill, hairline border */
2348
2463
  .sv-btn-secondary {
2349
2464
  background: ${tokens.bgSubtle};
2350
2465
  color: ${tokens.textPrimary};
@@ -2356,25 +2471,26 @@ function getStyles(options) {
2356
2471
  border-color: ${tokens.borderHover};
2357
2472
  }
2358
2473
 
2359
- /* Method Button — a full-width row that lifts on hover with a nudging
2360
- chevron affordance (added via ::after so no DOM change is needed). */
2474
+ /* Method Button — a full-width row with a nudging chevron affordance
2475
+ (added via ::after so no DOM change is needed). The card itself stays
2476
+ planted: hover is a quiet fill + border shift, no translate. */
2361
2477
  .sv-btn-method {
2362
2478
  position: relative;
2363
2479
  background: ${tokens.bg};
2364
- border: 1px solid ${tokens.borderHover};
2365
- border-radius: 12px;
2480
+ border: 1px solid ${tokens.border};
2481
+ border-radius: 10px;
2366
2482
  color: ${tokens.textPrimary};
2367
2483
  text-align: left;
2368
2484
  padding: 15px 40px 15px 14px;
2369
2485
  margin-bottom: 9px;
2370
- /* Inset 2px on either side so the focus outline (drawn outside the
2486
+ /* Inset 2px on either side so the focus ring (drawn outside the
2371
2487
  border-box) has room to render without clipping against the
2372
2488
  dialog's container edges. width:auto pairs with this to prevent
2373
2489
  the row from forcing horizontal overflow. */
2374
2490
  margin-left: 2px;
2375
2491
  margin-right: 2px;
2376
2492
  width: calc(100% - 4px);
2377
- transition: transform var(--sv-dur-base) var(--sv-ease-out), background var(--sv-dur-fast) var(--sv-ease-standard), border-color var(--sv-dur-fast) var(--sv-ease-standard);
2493
+ transition: background var(--sv-dur-fast) var(--sv-ease-standard), border-color var(--sv-dur-fast) var(--sv-ease-standard);
2378
2494
  }
2379
2495
 
2380
2496
  .sv-btn-method::after {
@@ -2384,29 +2500,25 @@ function getStyles(options) {
2384
2500
  top: 50%;
2385
2501
  width: 8px;
2386
2502
  height: 8px;
2387
- border-right: 1.6px solid ${tokens.textMuted};
2388
- border-top: 1.6px solid ${tokens.textMuted};
2503
+ border-right: 1.6px solid ${tokens.chevron};
2504
+ border-top: 1.6px solid ${tokens.chevron};
2389
2505
  transform: translateY(-50%) rotate(45deg);
2390
2506
  transition: transform var(--sv-dur-base) var(--sv-ease-out), border-color var(--sv-dur-fast) var(--sv-ease-standard);
2391
2507
  }
2392
2508
 
2393
2509
  .sv-btn-method:hover:not(:disabled)::after {
2394
2510
  transform: translateY(-50%) translateX(3px) rotate(45deg);
2395
- border-color: ${tokens.textSecondary};
2511
+ border-color: ${tokens.primary};
2396
2512
  }
2397
2513
 
2398
- /* The shared .sv-btn focus rule sets outline-offset:2px which sits
2399
- outside the row's edges and gets clipped by the parent. Method
2400
- rows are full-width by design, so render the focus indicator
2401
- flush against the border instead. */
2402
2514
  .sv-btn-method:focus-visible {
2403
- outline-offset: 0;
2515
+ outline: none;
2516
+ box-shadow: ${tokens.focusRing};
2404
2517
  }
2405
2518
 
2406
2519
  .sv-btn-method:hover:not(:disabled) {
2407
2520
  background: ${tokens.bgSubtle};
2408
- border-color: ${tokens.border};
2409
- transform: translateY(-2px);
2521
+ border-color: ${tokens.borderHover};
2410
2522
  }
2411
2523
 
2412
2524
  .sv-btn-method:last-child {
@@ -2415,13 +2527,13 @@ function getStyles(options) {
2415
2527
 
2416
2528
  /* Error Buttons */
2417
2529
  .sv-btn-error-primary {
2418
- background: ${tokens.error};
2530
+ background: ${tokens.danger};
2419
2531
  color: ${tokens.textOnPrimary};
2420
2532
  box-shadow: ${tokens.shadowSm};
2421
2533
  }
2422
2534
 
2423
2535
  .sv-btn-error-primary:hover:not(:disabled) {
2424
- background: #B91C1C;
2536
+ background: ${tokens.dangerHover};
2425
2537
  }
2426
2538
 
2427
2539
  .sv-btn-error-secondary {
@@ -2446,26 +2558,26 @@ function getStyles(options) {
2446
2558
  width: 100%;
2447
2559
  }
2448
2560
 
2561
+ /* Bare glyph slot — no container chrome. Quiet slate stroke that takes
2562
+ the accent on row hover. */
2449
2563
  .sv-method-icon {
2450
- width: 36px;
2451
- height: 36px;
2564
+ width: 20px;
2565
+ height: 20px;
2452
2566
  flex-shrink: 0;
2453
2567
  display: flex;
2454
2568
  align-items: center;
2455
2569
  justify-content: center;
2456
- border-radius: 9px;
2457
- background: ${tokens.bgSubtle};
2458
- color: ${tokens.textSecondary};
2459
- transition: background var(--sv-dur-fast) var(--sv-ease-standard);
2570
+ color: ${tokens.textMuted};
2571
+ transition: color var(--sv-dur-fast) var(--sv-ease-standard);
2460
2572
  }
2461
2573
 
2462
2574
  .sv-btn-method:hover:not(:disabled) .sv-method-icon {
2463
- background: ${tokens.bg};
2575
+ color: ${tokens.primary};
2464
2576
  }
2465
2577
 
2466
2578
  .sv-method-icon svg {
2467
- width: 19px;
2468
- height: 19px;
2579
+ width: 20px;
2580
+ height: 20px;
2469
2581
  }
2470
2582
 
2471
2583
  .sv-method-text {
@@ -2474,13 +2586,13 @@ function getStyles(options) {
2474
2586
  }
2475
2587
 
2476
2588
  .sv-method-name {
2477
- font-weight: 500;
2478
- font-size: 14px;
2589
+ font-weight: 600;
2590
+ font-size: 15px;
2479
2591
  color: ${tokens.textPrimary};
2480
2592
  }
2481
2593
 
2482
2594
  .sv-method-description {
2483
- font-size: 12px;
2595
+ font-size: 13px;
2484
2596
  color: ${tokens.textMuted};
2485
2597
  margin-top: 1px;
2486
2598
  }
@@ -2505,12 +2617,12 @@ function getStyles(options) {
2505
2617
  letter-spacing: 0;
2506
2618
  font-variant-numeric: tabular-nums;
2507
2619
  caret-color: transparent;
2508
- border: 1px solid ${tokens.borderHover};
2509
- border-radius: 11px;
2620
+ border: 1px solid ${tokens.border};
2621
+ border-radius: 8px;
2510
2622
  background: ${tokens.bgInput};
2511
2623
  color: ${tokens.textPrimary};
2512
2624
  box-sizing: border-box;
2513
- transition: border-color var(--sv-dur-fast) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard), transform var(--sv-dur-fast) var(--sv-ease-spring);
2625
+ transition: border-color var(--sv-dur-fast) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard);
2514
2626
  }
2515
2627
 
2516
2628
  .sv-otp-digit:hover:not(:focus):not(:disabled) {
@@ -2521,7 +2633,6 @@ function getStyles(options) {
2521
2633
  outline: none;
2522
2634
  border-color: ${tokens.borderFocus};
2523
2635
  box-shadow: 0 0 0 3px ${tokens.primaryLight};
2524
- transform: translateY(-2px);
2525
2636
  }
2526
2637
 
2527
2638
  .sv-otp-digit:disabled {
@@ -2546,7 +2657,7 @@ function getStyles(options) {
2546
2657
  border: none;
2547
2658
  padding: 0;
2548
2659
  margin-bottom: 16px;
2549
- transition: color 0.15s ease;
2660
+ transition: color var(--sv-dur-fast) var(--sv-ease-standard);
2550
2661
  }
2551
2662
 
2552
2663
  .sv-back-link:hover:not(:disabled) {
@@ -2574,7 +2685,7 @@ function getStyles(options) {
2574
2685
  padding: 10px 12px;
2575
2686
  border-radius: 8px;
2576
2687
  font-size: 13px;
2577
- font-weight: 450;
2688
+ font-weight: 500;
2578
2689
  margin-bottom: 16px;
2579
2690
  }
2580
2691
 
@@ -2630,7 +2741,7 @@ function getStyles(options) {
2630
2741
  color: ${tokens.textSecondary};
2631
2742
  text-decoration: none;
2632
2743
  font-weight: 500;
2633
- transition: color 0.15s ease;
2744
+ transition: color var(--sv-dur-fast) var(--sv-ease-standard);
2634
2745
  }
2635
2746
 
2636
2747
  .sv-footer-link:hover {
@@ -2690,7 +2801,7 @@ function getStyles(options) {
2690
2801
  background: ${tokens.bgInput};
2691
2802
  color: ${tokens.textPrimary};
2692
2803
  box-sizing: border-box;
2693
- transition: border-color 0.15s ease, box-shadow 0.15s ease;
2804
+ transition: border-color var(--sv-dur-fast) var(--sv-ease-standard), box-shadow var(--sv-dur-fast) var(--sv-ease-standard);
2694
2805
  }
2695
2806
 
2696
2807
  .sv-email-input:hover:not(:focus):not(:disabled) {
@@ -2712,7 +2823,7 @@ function getStyles(options) {
2712
2823
  }
2713
2824
 
2714
2825
  .sv-email-input-error:focus {
2715
- box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
2826
+ box-shadow: 0 0 0 3px ${tokens.errorLight};
2716
2827
  }
2717
2828
 
2718
2829
  /* ========================================
@@ -2767,14 +2878,14 @@ function getStyles(options) {
2767
2878
  .sv-error-code-label {
2768
2879
  font-size: 10px;
2769
2880
  font-weight: 600;
2770
- color: ${isDark ? '#F87171' : '#991B1B'};
2881
+ color: ${isDark ? '#e6443d' : '#991b1b'};
2771
2882
  text-transform: uppercase;
2772
2883
  letter-spacing: 0.05em;
2773
2884
  }
2774
2885
 
2775
2886
  .sv-error-code-value {
2776
2887
  font-size: 11px;
2777
- font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, 'Cascadia Mono', monospace;
2888
+ font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, 'Cascadia Mono', monospace;
2778
2889
  color: ${tokens.error};
2779
2890
  font-weight: 500;
2780
2891
  }
@@ -2871,10 +2982,10 @@ function getStyles(options) {
2871
2982
  justify-content: center;
2872
2983
  background: transparent;
2873
2984
  border: none;
2874
- border-radius: 8px;
2985
+ border-radius: 6px;
2875
2986
  cursor: pointer;
2876
2987
  color: ${tokens.textMuted};
2877
- transition: background 0.15s ease, color 0.15s ease;
2988
+ transition: background var(--sv-dur-fast) var(--sv-ease-standard), color var(--sv-dur-fast) var(--sv-ease-standard);
2878
2989
  z-index: 1;
2879
2990
  }
2880
2991
 
@@ -2884,12 +2995,8 @@ function getStyles(options) {
2884
2995
  }
2885
2996
 
2886
2997
  .sv-floating-close:focus-visible {
2887
- outline: 2px solid ${tokens.borderFocus};
2888
- outline-offset: 2px;
2889
- }
2890
-
2891
- .sv-floating-close:active {
2892
- transform: scale(0.96);
2998
+ outline: none;
2999
+ box-shadow: ${tokens.focusRing};
2893
3000
  }
2894
3001
 
2895
3002
  /* ========================================
@@ -2949,7 +3056,7 @@ function getStyles(options) {
2949
3056
 
2950
3057
  .sv-not-activated-title {
2951
3058
  font-size: 22px;
2952
- font-weight: 700;
3059
+ font-weight: 600;
2953
3060
  letter-spacing: -0.02em;
2954
3061
  line-height: 1.2;
2955
3062
  margin: 0 0 10px 0;
@@ -2971,7 +3078,7 @@ function getStyles(options) {
2971
3078
  gap: 4px;
2972
3079
  padding: 14px 16px;
2973
3080
  border: 1px solid ${tokens.border};
2974
- border-radius: 12px;
3081
+ border-radius: 10px;
2975
3082
  background: ${tokens.bgSubtle};
2976
3083
  text-align: left;
2977
3084
  margin-bottom: 22px;
@@ -3019,7 +3126,7 @@ function getStyles(options) {
3019
3126
  font-size: 13px;
3020
3127
  font-weight: 500;
3021
3128
  color: ${tokens.textMuted};
3022
- transition: color 0.15s ease;
3129
+ transition: color var(--sv-dur-fast) var(--sv-ease-standard);
3023
3130
  align-self: center;
3024
3131
  }
3025
3132
 
@@ -3028,8 +3135,8 @@ function getStyles(options) {
3028
3135
  }
3029
3136
 
3030
3137
  .sv-not-activated-dismiss:focus-visible {
3031
- outline: 2px solid ${tokens.borderFocus};
3032
- outline-offset: 2px;
3138
+ outline: none;
3139
+ box-shadow: ${tokens.focusRing};
3033
3140
  border-radius: 6px;
3034
3141
  }
3035
3142
 
@@ -3074,7 +3181,7 @@ function getStyles(options) {
3074
3181
  border: none;
3075
3182
  padding: 12px 0 0 0;
3076
3183
  margin-top: 8px;
3077
- transition: color 0.15s ease;
3184
+ transition: color var(--sv-dur-fast) var(--sv-ease-standard);
3078
3185
  }
3079
3186
 
3080
3187
  .sv-fallback-link:hover {
@@ -3135,7 +3242,7 @@ function getStyles(options) {
3135
3242
  background: none;
3136
3243
  border: none;
3137
3244
  padding: 12px 0 0 0;
3138
- transition: color 0.15s ease;
3245
+ transition: color var(--sv-dur-fast) var(--sv-ease-standard);
3139
3246
  }
3140
3247
 
3141
3248
  .sv-skip-link:hover {
@@ -3153,14 +3260,11 @@ function getStyles(options) {
3153
3260
  margin-bottom: 16px;
3154
3261
  }
3155
3262
 
3263
+ /* Bare glyph — no tinted circle container. */
3156
3264
  .sv-sparklink-icon {
3157
- width: 56px;
3158
- height: 56px;
3159
- color: ${tokens.primary};
3160
- background: ${tokens.primaryLight};
3161
- padding: 14px;
3162
- border-radius: 50%;
3163
- box-sizing: content-box;
3265
+ width: 48px;
3266
+ height: 48px;
3267
+ color: ${tokens.textSecondary};
3164
3268
  }
3165
3269
 
3166
3270
  .sv-sparklink-waiting {
@@ -3186,7 +3290,7 @@ function getStyles(options) {
3186
3290
 
3187
3291
  .sv-sparklink-waiting-text {
3188
3292
  font-size: 13px;
3189
- font-weight: 450;
3293
+ font-weight: 500;
3190
3294
  color: ${tokens.textSecondary};
3191
3295
  }
3192
3296
 
@@ -3201,9 +3305,10 @@ function getStyles(options) {
3201
3305
  }
3202
3306
 
3203
3307
  .sv-sparklink-countdown-time {
3204
- font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, 'Cascadia Mono', monospace;
3308
+ font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Monaco, 'Cascadia Mono', monospace;
3205
3309
  font-weight: 600;
3206
3310
  font-size: 14px;
3311
+ font-variant-numeric: tabular-nums;
3207
3312
  color: ${tokens.textPrimary};
3208
3313
  min-width: 40px;
3209
3314
  }
@@ -3398,7 +3503,7 @@ function getStyles(options) {
3398
3503
  margin-bottom: 0;
3399
3504
  border-width: 0;
3400
3505
  overflow: hidden;
3401
- transition: opacity 0.25s ease;
3506
+ transition: opacity var(--sv-dur-slow) var(--sv-ease-standard);
3402
3507
  }
3403
3508
 
3404
3509
  .sv-bridge-alert.sv-shown {
@@ -3415,7 +3520,7 @@ function getStyles(options) {
3415
3520
  width: 17px;
3416
3521
  height: 17px;
3417
3522
  margin-top: 1px;
3418
- color: #d97706;
3523
+ color: ${tokens.warningIcon};
3419
3524
  }
3420
3525
 
3421
3526
  /* Text stacked over the action, so the message keeps the full width and
@@ -3446,7 +3551,7 @@ function getStyles(options) {
3446
3551
  }
3447
3552
 
3448
3553
  .sv-bridge-retry:hover { color: ${tokens.primaryHover}; }
3449
- .sv-bridge-retry:focus-visible { outline: 2px solid ${tokens.borderFocus}; outline-offset: 2px; border-radius: 4px; }
3554
+ .sv-bridge-retry:focus-visible { outline: none; box-shadow: ${tokens.focusRing}; border-radius: 4px; }
3450
3555
 
3451
3556
  @media (prefers-reduced-motion: reduce) {
3452
3557
  .sv-bridge-dots span { animation: none; opacity: 0.5; }
@@ -3499,8 +3604,9 @@ function getStyles(options) {
3499
3604
  /**
3500
3605
  * SVG Icon Factory
3501
3606
  *
3502
- * Enterprise-grade icons with clean, minimal design.
3503
- * Uses proper DOM element creation for security.
3607
+ * Bare outline glyphs per the SparkVault design system: stroke `currentColor`
3608
+ * so the stylesheet drives color, no tinted container backgrounds, round
3609
+ * caps/joins. Uses proper DOM element creation for security.
3504
3610
  */
3505
3611
  function createSvgElement(viewBox, width = 16, height = 16) {
3506
3612
  const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
@@ -3568,88 +3674,63 @@ function createCloseIcon() {
3568
3674
  return svg;
3569
3675
  }
3570
3676
  /**
3571
- * Passkey icon - simple key design
3677
+ * Passkey icon - bare outline key design
3572
3678
  */
3573
3679
  function createPasskeyIcon() {
3574
3680
  const svg = createSvgElement('0 0 56 56', 56, 56);
3575
3681
  svg.classList.add('sv-passkey-icon');
3576
- // Circle background
3577
- svg.appendChild(createCircle(28, 28, 26, {
3578
- fill: '#EEF2FF',
3579
- stroke: '#E0E7FF',
3580
- 'stroke-width': '1',
3581
- }));
3582
- // Key icon - centered at 28,28
3682
+ // Key glyph optically centered in the 56px box (footprint unchanged)
3583
3683
  const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
3584
- group.setAttribute('transform', 'translate(28, 28)');
3684
+ group.setAttribute('transform', 'translate(29.5, 26.5)');
3585
3685
  const strokeAttrs = {
3586
- stroke: '#4F46E5',
3587
- 'stroke-width': '2.5',
3686
+ stroke: 'currentColor',
3687
+ 'stroke-width': '3',
3588
3688
  'stroke-linecap': 'round',
3589
3689
  'stroke-linejoin': 'round',
3590
3690
  fill: 'none',
3591
3691
  };
3592
3692
  // Key head (circle)
3593
- group.appendChild(createCircle(-6, -6, 6, strokeAttrs));
3693
+ group.appendChild(createCircle(-9.5, -9.5, 9.5, strokeAttrs));
3594
3694
  // Key shaft
3595
- group.appendChild(createPath('M-1.5 -1.5L10 10', strokeAttrs));
3695
+ group.appendChild(createPath('M-2.8 -2.8L16 16', strokeAttrs));
3596
3696
  // Key teeth
3597
- group.appendChild(createPath('M6 6L6 10', strokeAttrs));
3598
- group.appendChild(createPath('M10 10L10 14', strokeAttrs));
3697
+ group.appendChild(createPath('M9.5 9.5L9.5 15.5', strokeAttrs));
3698
+ group.appendChild(createPath('M16 16L16 22', strokeAttrs));
3599
3699
  svg.appendChild(group);
3600
3700
  return svg;
3601
3701
  }
3602
3702
  /**
3603
- * Error icon - clean triangle alert
3703
+ * Bare outline alert triangle shared by the error and expired icons.
3704
+ * Color comes from `currentColor` via the class-specific stylesheet rules.
3604
3705
  */
3605
- function createErrorIcon() {
3706
+ function createAlertTriangleIcon(className) {
3606
3707
  const svg = createSvgElement('0 0 48 48', 48, 48);
3607
- svg.classList.add('sv-error-icon');
3608
- // Circle background
3609
- svg.appendChild(createCircle(24, 24, 22, {
3610
- fill: '#FEF2F2',
3611
- stroke: '#FECACA',
3612
- 'stroke-width': '1',
3613
- }));
3614
- // Alert triangle
3615
- const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
3616
- group.setAttribute('transform', 'translate(10, 12)');
3617
- group.appendChild(createPath('M14 4L2 24h24L14 4z', { fill: '#DC2626' }));
3618
- // Exclamation
3619
- group.appendChild(createPath('M14 10v5', {
3620
- stroke: '#FFFFFF',
3621
- 'stroke-width': '2',
3708
+ svg.classList.add(className);
3709
+ const strokeAttrs = {
3710
+ stroke: 'currentColor',
3711
+ 'stroke-width': '2.5',
3622
3712
  'stroke-linecap': 'round',
3623
- }));
3624
- group.appendChild(createCircle(14, 19, 1, { fill: '#FFFFFF' }));
3625
- svg.appendChild(group);
3713
+ 'stroke-linejoin': 'round',
3714
+ fill: 'none',
3715
+ };
3716
+ // Triangle outline
3717
+ svg.appendChild(createPath('M24 9L5.5 39h37L24 9z', strokeAttrs));
3718
+ // Exclamation
3719
+ svg.appendChild(createPath('M24 20v8', strokeAttrs));
3720
+ svg.appendChild(createCircle(24, 33.5, 1.5, { fill: 'currentColor' }));
3626
3721
  return svg;
3627
3722
  }
3628
3723
  /**
3629
- * Expired icon - grayscale triangle alert for expired states
3724
+ * Error icon - alert triangle for error states
3725
+ */
3726
+ function createErrorIcon() {
3727
+ return createAlertTriangleIcon('sv-error-icon');
3728
+ }
3729
+ /**
3730
+ * Expired icon - alert triangle for expired states
3630
3731
  */
3631
3732
  function createExpiredIcon() {
3632
- const svg = createSvgElement('0 0 48 48', 48, 48);
3633
- svg.classList.add('sv-expired-icon');
3634
- // Circle background - muted gray
3635
- svg.appendChild(createCircle(24, 24, 22, {
3636
- fill: '#F5F5F5',
3637
- stroke: '#E5E5E5',
3638
- 'stroke-width': '1',
3639
- }));
3640
- // Alert triangle - gray
3641
- const group = document.createElementNS('http://www.w3.org/2000/svg', 'g');
3642
- group.setAttribute('transform', 'translate(10, 12)');
3643
- group.appendChild(createPath('M14 4L2 24h24L14 4z', { fill: '#737373' }));
3644
- // Exclamation
3645
- group.appendChild(createPath('M14 10v5', {
3646
- stroke: '#FFFFFF',
3647
- 'stroke-width': '2',
3648
- 'stroke-linecap': 'round',
3649
- }));
3650
- group.appendChild(createCircle(14, 19, 1, { fill: '#FFFFFF' }));
3651
- svg.appendChild(group);
3652
- return svg;
3733
+ return createAlertTriangleIcon('sv-expired-icon');
3653
3734
  }
3654
3735
  /**
3655
3736
  * Method icons
@@ -7830,7 +7911,7 @@ class DialogLauncher {
7830
7911
  const generation = ++this.generation;
7831
7912
  this.popupLauncher
7832
7913
  .openPopup({
7833
- url: this.buildPopupUrl(),
7914
+ url: buildSigninUrl(this.config, this.options),
7834
7915
  windowName: 'sparkvault-login',
7835
7916
  resultType: LOGIN_RESULT_TYPE,
7836
7917
  readyType: LOGIN_READY_TYPE,
@@ -7851,28 +7932,6 @@ class DialogLauncher {
7851
7932
  .catch((error) => { if (generation === this.generation)
7852
7933
  this.handleError(error); });
7853
7934
  }
7854
- buildPopupUrl() {
7855
- const params = new URLSearchParams({ origin: window.location.origin });
7856
- // Identifier prefill - the popup collects it itself when absent.
7857
- if (this.options.email) {
7858
- params.set('email', this.options.email);
7859
- }
7860
- else if (this.options.phone) {
7861
- params.set('phone', this.options.phone);
7862
- }
7863
- // Auth context, in the query shape the sign-in page reads server-side:
7864
- // OIDC rides `auth_request`; simple redirect rides `mode=simple` + the
7865
- // opaque `session` (the page loads success/failure URLs from the session).
7866
- const authContext = this.options.authContext;
7867
- if (authContext?.authRequestId) {
7868
- params.set('auth_request', authContext.authRequestId);
7869
- }
7870
- else if (authContext?.simpleMode?.sessionId) {
7871
- params.set('mode', 'simple');
7872
- params.set('session', authContext.simpleMode.sessionId);
7873
- }
7874
- return `${this.config.identityBaseUrl}/${this.config.accountId}/signin?${params}`;
7875
- }
7876
7935
  handleResult(message) {
7877
7936
  if (this.settled)
7878
7937
  return;
@@ -8340,6 +8399,10 @@ class IdentityModule {
8340
8399
  if (config.preloadConfig) {
8341
8400
  this.api.preloadConfig();
8342
8401
  }
8402
+ // Warm the connection to the Identity origin before sign-in is invoked:
8403
+ // the popup/redirect navigation and every flow API call reuse it, removing
8404
+ // the cold-connection stall mobile browsers hit on first navigation.
8405
+ ensurePreconnect(config.identityBaseUrl);
8343
8406
  }
8344
8407
  /**
8345
8408
  * Build a deep link into the person's auth.sv Identity portal — where they
@@ -8446,12 +8509,18 @@ class IdentityModule {
8446
8509
  typeof navigator.credentials.get === 'function');
8447
8510
  }
8448
8511
  /**
8449
- * Open the SparkVault sign-in popup and resolve with the verified identity.
8512
+ * Sign in through the first-party SparkVault sign-in popup.
8450
8513
  *
8451
8514
  * This is the single programmatic entry point; `attach()` binds it to element
8452
- * clicks. There is no inline/in-page mode — sign-in always runs in the
8453
- * first-party popup on the Identity origin, so login's `__Host-` hub cookie is
8454
- * a first-party write and cross-domain SSO works.
8515
+ * clicks. The popup runs the flow top-level on the Identity origin (so
8516
+ * login's `__Host-` hub cookie is a first-party write and cross-domain SSO
8517
+ * works) and posts the result back — the promise resolves with it.
8518
+ *
8519
+ * Resilience: pair this with `handleRedirectResult()` on page load. If the
8520
+ * popup's result is ever lost (a mobile browser discards the backgrounded
8521
+ * opener tab), the next load silently self-heals from the SSO session the
8522
+ * login established. `flow: 'redirect'` opts a caller out of the popup into a
8523
+ * same-tab navigation instead.
8455
8524
  *
8456
8525
  * @example
8457
8526
  * const result = await sv.products.identity.signIn();
@@ -8461,9 +8530,10 @@ class IdentityModule {
8461
8530
  return this.runFlow(options);
8462
8531
  }
8463
8532
  /**
8464
- * Core flow runner. Dialog mode (no `target`) opens the popup; local mode
8465
- * (`renderMode: 'local'` / `target`) renders into the current document and
8466
- * powers the SparkVault-hosted sign-in surfaces (see the internal `render`).
8533
+ * Core flow runner. Default mode (no `target`) opens the popup; `flow:
8534
+ * 'redirect'` navigates the tab instead; local mode (`renderMode: 'local'` /
8535
+ * `target`) renders into the current document and powers the
8536
+ * SparkVault-hosted sign-in surfaces (see the internal `render`).
8467
8537
  */
8468
8538
  async runFlow(options = {}) {
8469
8539
  const redirectResult = await this.consumeRedirectResult();
@@ -8489,9 +8559,10 @@ class IdentityModule {
8489
8559
  backdropBlur: options.backdropBlur ?? this.config.backdropBlur,
8490
8560
  };
8491
8561
  // Inline rendering (target) and explicit local mode run the flow in this
8492
- // document. Dialog mode renders a thin launcher and opens a top-level popup
8493
- // on the Identity origin for the flow (so login's first-party SSO cookie
8494
- // persists). `renderMode: 'local'` is how the popup itself runs the flow.
8562
+ // document — that is how the SparkVault-hosted sign-in page itself runs
8563
+ // the flow. Otherwise sign-in leaves this page: a top-level redirect to
8564
+ // the sign-in page on the Identity origin (so login's first-party SSO
8565
+ // cookie persists), returning via handleRedirectResult().
8495
8566
  const isInline = !!options.target;
8496
8567
  const useLocal = options.renderMode === 'local' || isInline;
8497
8568
  let resolveRef;
@@ -8527,14 +8598,35 @@ class IdentityModule {
8527
8598
  if (!useLocal) {
8528
8599
  // When the preloaded config has already failed *permanently* — this origin
8529
8600
  // is not a verified domain, or the account hasn't configured Identity —
8530
- // the popup cannot help: the IdP will reject the unverified origin. Render
8601
+ // the flow cannot help: the IdP will reject the unverified origin. Render
8531
8602
  // the error dialog in-page right away instead. Transient failures fall
8532
- // through to the launcher, which surfaces them in its own dialog.
8603
+ // through, and the popup/sign-in page surfaces them in its own dialog.
8533
8604
  if (await this.preloadedConfigPermanentlyFailed()) {
8534
8605
  startLocalRender(new ModalContainer());
8535
8606
  return settledPromise;
8536
8607
  }
8537
- this.launcher = new DialogLauncher(this.config, this.api, mergedOptions, hostCallbacks);
8608
+ // Explicit `flow: 'redirect'` navigates this tab to the sign-in page and
8609
+ // returns via handleRedirectResult() (the escape hatch for hosts that
8610
+ // want to skip the popup on mobile). Then this page is unloading, so the
8611
+ // promise never settles on success; it rejects only if the redirect
8612
+ // cannot start.
8613
+ if (mergedOptions.flow === 'redirect') {
8614
+ if (!await this.startRedirectFlow(mergedOptions)) {
8615
+ hostCallbacks.onError(new ValidationError('Sign-in requires browser session storage. Enable site data for this site and try again.'));
8616
+ }
8617
+ return settledPromise;
8618
+ }
8619
+ // Default: the first-party popup on the Identity origin. Mark a sign-in
8620
+ // as in flight so that if its result is lost (a mobile browser discards
8621
+ // the backgrounded opener tab, killing the postMessage listener),
8622
+ // handleRedirectResult() can silently self-heal on the next load from
8623
+ // the SSO session the popup login established.
8624
+ this.markSignInPending();
8625
+ this.launcher = new DialogLauncher(this.config, this.api, mergedOptions, {
8626
+ onSuccess: (result) => { this.clearSignInPending(); hostCallbacks.onSuccess(result); },
8627
+ onError: (error) => { this.clearSignInPending(); hostCallbacks.onError(error); },
8628
+ onCancel: () => { this.clearSignInPending(); hostCallbacks.onCancel(); },
8629
+ });
8538
8630
  this.launcher.start();
8539
8631
  return settledPromise;
8540
8632
  }
@@ -8641,13 +8733,212 @@ class IdentityModule {
8641
8733
  return payload;
8642
8734
  }
8643
8735
  /**
8644
- * Complete full-page redirect results produced by social-login flows.
8645
- * The Identity Product redirects back with `#token=...` so the token does
8646
- * not hit server logs. Consume it once, run the unverified client-side decode
8647
- * (issuer/audience/expiry/alg sanity-check — NOT signature verification), then
8648
- * remove it from the URL bar. The host must still verify the token server-side
8649
- * via the Identity JWKS before trusting any claim.
8736
+ * Complete a sign-in on page load — the return leg of `signIn()`. Call once
8737
+ * on every page load; it resolves `null` when there is nothing to do.
8738
+ *
8739
+ * It handles two cases:
8740
+ * 1. A one-time code is in the URL fragment (`#sv_code=…`) — the popup's
8741
+ * result was lost and self-heal navigated here, or `flow: 'redirect'`
8742
+ * returned. Redeem it server-side and hand the full result to
8743
+ * `onSuccess` (and resolve with it).
8744
+ * 2. A sign-in was in flight but never delivered (a mobile browser
8745
+ * discarded the backgrounded opener tab, killing the popup's
8746
+ * postMessage) — silently re-mint from the SSO session the completed
8747
+ * popup login established, by navigating this tab through the silent SSO
8748
+ * endpoint and straight back with a code (case 1 on return). Nothing is
8749
+ * shown; if there is no live session it comes back logged-out, no oracle.
8750
+ *
8751
+ * The code is one-time, PKCE-bound, and origin-locked — never the token. The
8752
+ * host must still verify `result.token` server-side via the Identity JWKS.
8753
+ *
8754
+ * @example Call on page load; sign-in clicks stay unchanged.
8755
+ * sv.products.identity.handleRedirectResult({
8756
+ * onSuccess: (result) => createSession(result.token),
8757
+ * }).catch((error) => showError(error));
8650
8758
  */
8759
+ async handleRedirectResult(options = {}) {
8760
+ if (typeof window === 'undefined') {
8761
+ return null;
8762
+ }
8763
+ const params = new URLSearchParams((window.location.hash || '').slice(1));
8764
+ if (params.get('sv_code') || params.get('sv_error')) {
8765
+ return this.consumeHandoffFragment(params, options);
8766
+ }
8767
+ // A silent-SSO recovery that found no live session returns `#sso=…`; strip
8768
+ // it so the logged-out load is clean, and do not re-bounce (handled below).
8769
+ if (params.get('sso')) {
8770
+ this.clearUrlFragment();
8771
+ }
8772
+ // No returned result. If a sign-in was in flight and its result never
8773
+ // arrived, self-heal once from the SSO session (mobile opener-tab discard).
8774
+ if (this.consumeSignInPending()) {
8775
+ await this.startRecoveryBounce();
8776
+ }
8777
+ return null;
8778
+ }
8779
+ /** Redeem a returned `#sv_code` (or surface a returned `#sv_error`). */
8780
+ async consumeHandoffFragment(params, options) {
8781
+ const code = params.get('sv_code');
8782
+ const errorCode = params.get('sv_error');
8783
+ // A returned fragment means this sign-in resolved (redeem, cancel, or
8784
+ // error), so retire any pending marker — otherwise it could fire one
8785
+ // spurious silent bounce on a later load inside its TTL.
8786
+ this.clearSignInPending();
8787
+ // Consume exactly once: fragment and one-shot state/verifier are cleared
8788
+ // up front on every path, so a failing result cannot wedge future loads
8789
+ // (and a StrictMode double-invocation finds an empty hash and no-ops).
8790
+ let expectedState = null;
8791
+ let codeVerifier = null;
8792
+ try {
8793
+ expectedState = sessionStorage.getItem('sv_oauth_state');
8794
+ codeVerifier = sessionStorage.getItem('sv_pkce_verifier');
8795
+ sessionStorage.removeItem('sv_oauth_state');
8796
+ sessionStorage.removeItem('sv_pkce_verifier');
8797
+ }
8798
+ catch {
8799
+ // Storage disabled (private mode): state/verifier were never persisted.
8800
+ }
8801
+ this.clearUrlFragment();
8802
+ try {
8803
+ if (errorCode) {
8804
+ if (errorCode === 'cancelled') {
8805
+ options.onCancel?.();
8806
+ return null;
8807
+ }
8808
+ throw new SparkVaultError('Sign-in could not be completed. Please try again.', 'REDIRECT_SIGNIN_FAILED');
8809
+ }
8810
+ if (expectedState && params.get('state') !== expectedState) {
8811
+ throw new ValidationError('Invalid OAuth state');
8812
+ }
8813
+ if (!codeVerifier) {
8814
+ throw new ValidationError('Sign-in session was lost — please sign in again.');
8815
+ }
8816
+ const raw = await this.api.redeemHandoffCode(code, codeVerifier);
8817
+ const result = {
8818
+ token: raw.token,
8819
+ identity: raw.identity,
8820
+ identityType: raw.identity_type,
8821
+ svid: raw.svid ?? undefined,
8822
+ sessionId: raw.session_id ?? undefined,
8823
+ refreshToken: raw.refresh_token ?? undefined,
8824
+ };
8825
+ options.onSuccess?.(result);
8826
+ return result;
8827
+ }
8828
+ catch (error) {
8829
+ const err = error instanceof Error ? error : new Error(String(error));
8830
+ options.onError?.(err);
8831
+ throw err;
8832
+ }
8833
+ }
8834
+ /**
8835
+ * Silently re-mint the sign-in result from the SSO session the completed
8836
+ * popup login left behind. Navigates this tab through the silent SSO endpoint
8837
+ * (a top-level GET, so the `SameSite=Lax` hub cookie rides along) which,
8838
+ * PKCE-bound, returns a one-time code in the fragment — handled by case 1 on
8839
+ * return. No-op (stays put) if session storage or WebCrypto is unavailable,
8840
+ * so a hostile/degraded environment simply never recovers rather than
8841
+ * erroring.
8842
+ */
8843
+ async startRecoveryBounce() {
8844
+ const nav = await this.prepareHandoffNavigation(`${this.config.identityBaseUrl}/${this.config.accountId}/sso`);
8845
+ if (nav) {
8846
+ window.location.assign(nav);
8847
+ }
8848
+ }
8849
+ /**
8850
+ * Explicit `flow: 'redirect'` — navigate this tab to the interactive sign-in
8851
+ * page. Plain sign-in carries redirect_uri + state + PKCE challenge and
8852
+ * returns via the fragment code; OIDC/simple modes navigate bare (their
8853
+ * server-rendered pages drive the server-validated redirect back).
8854
+ *
8855
+ * @returns false when the return leg cannot be armed (no session storage or
8856
+ * WebCrypto) — the caller surfaces an actionable error instead of a
8857
+ * silent dead-end.
8858
+ */
8859
+ async startRedirectFlow(options) {
8860
+ const authContext = options.authContext;
8861
+ if (authContext?.authRequestId || authContext?.simpleMode?.sessionId) {
8862
+ window.location.assign(buildSigninUrl(this.config, options));
8863
+ return true;
8864
+ }
8865
+ const url = await this.prepareHandoffNavigation(buildSigninUrl(this.config, options), (extras) => buildSigninUrl(this.config, options, extras));
8866
+ if (!url) {
8867
+ return false;
8868
+ }
8869
+ window.location.assign(url);
8870
+ return true;
8871
+ }
8872
+ /**
8873
+ * Arm the PKCE + state return leg for a handoff navigation and return the URL
8874
+ * to navigate to (redirect_uri = this exact page; query preserved for app
8875
+ * state, fragment dropped since it is the result channel). Returns null when
8876
+ * session storage or WebCrypto is unavailable so callers can degrade.
8877
+ */
8878
+ async prepareHandoffNavigation(base, build) {
8879
+ const state = generateState();
8880
+ const codeVerifier = generateCodeVerifier();
8881
+ // Derive the challenge BEFORE persisting: a WebCrypto failure (insecure
8882
+ // context) then leaves no orphaned state/verifier behind in storage.
8883
+ let codeChallenge;
8884
+ try {
8885
+ codeChallenge = await computeS256Challenge(codeVerifier);
8886
+ }
8887
+ catch {
8888
+ return null;
8889
+ }
8890
+ try {
8891
+ sessionStorage.setItem('sv_oauth_state', state);
8892
+ sessionStorage.setItem('sv_pkce_verifier', codeVerifier);
8893
+ }
8894
+ catch {
8895
+ return null;
8896
+ }
8897
+ const redirectUri = `${window.location.origin}${window.location.pathname}${window.location.search}`;
8898
+ if (build) {
8899
+ return build({ redirectUri, state, codeChallenge });
8900
+ }
8901
+ const url = new URL(base);
8902
+ url.searchParams.set('redirect_uri', redirectUri);
8903
+ url.searchParams.set('state', state);
8904
+ url.searchParams.set('code_challenge', codeChallenge);
8905
+ return url.toString();
8906
+ }
8907
+ markSignInPending() {
8908
+ try {
8909
+ sessionStorage.setItem(IdentityModule.PENDING_KEY, String(Date.now()));
8910
+ }
8911
+ catch {
8912
+ // No storage → no self-heal; the popup still delivers when it can.
8913
+ }
8914
+ }
8915
+ clearSignInPending() {
8916
+ try {
8917
+ sessionStorage.removeItem(IdentityModule.PENDING_KEY);
8918
+ }
8919
+ catch {
8920
+ // Nothing to clear.
8921
+ }
8922
+ }
8923
+ /** True once (then cleared) if a recent sign-in is still awaiting its result. */
8924
+ consumeSignInPending() {
8925
+ let raw = null;
8926
+ try {
8927
+ raw = sessionStorage.getItem(IdentityModule.PENDING_KEY);
8928
+ sessionStorage.removeItem(IdentityModule.PENDING_KEY);
8929
+ }
8930
+ catch {
8931
+ return false;
8932
+ }
8933
+ const at = raw ? Number(raw) : NaN;
8934
+ return Number.isFinite(at) && Date.now() - at < IdentityModule.PENDING_TTL_MS;
8935
+ }
8936
+ /** Remove the result fragment from the URL bar (and history entry). */
8937
+ clearUrlFragment() {
8938
+ if (typeof window.history?.replaceState === 'function') {
8939
+ window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
8940
+ }
8941
+ }
8651
8942
  async consumeRedirectResult() {
8652
8943
  if (typeof window === 'undefined' || !window.location.hash) {
8653
8944
  return null;
@@ -8687,9 +8978,7 @@ class IdentityModule {
8687
8978
  };
8688
8979
  }
8689
8980
  finally {
8690
- if (typeof window.history?.replaceState === 'function') {
8691
- window.history.replaceState(window.history.state, document.title, `${window.location.pathname}${window.location.search}`);
8692
- }
8981
+ this.clearUrlFragment();
8693
8982
  try {
8694
8983
  sessionStorage.removeItem('sv_oauth_state');
8695
8984
  sessionStorage.removeItem('sv_oauth_email');
@@ -8775,6 +9064,11 @@ class IdentityModule {
8775
9064
  return this.runFlow(options);
8776
9065
  }
8777
9066
  }
9067
+ // A sign-in is "pending" from popup open until its result arrives; a marker
9068
+ // that outlives a lost result (mobile opener-tab discard clears the message
9069
+ // listener but not sessionStorage) is what lets the next load self-heal.
9070
+ IdentityModule.PENDING_KEY = 'sv_signin_pending';
9071
+ IdentityModule.PENDING_TTL_MS = 10 * 60 * 1000;
8778
9072
 
8779
9073
  /**
8780
9074
  * Products Module