@sparkvault/sdk-js 8.1.0 → 8.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -126,6 +126,7 @@ Object.freeze([
126
126
  SPARKVAULT_ROOT_DOMAIN,
127
127
  'app.sparkvault.com',
128
128
  'api.sparkvault.com',
129
+ 'auth.sparkvault.com',
129
130
  'cdn.sparkvault.com',
130
131
  'forge.sparkvault.com',
131
132
  'img.sparkvault.com',
@@ -1380,6 +1381,7 @@ class PopupLauncher {
1380
1381
  reject(new PopupBlockedError());
1381
1382
  return;
1382
1383
  }
1384
+ options.onOpen?.(popup);
1383
1385
  let settled = false;
1384
1386
  const cleanup = () => {
1385
1387
  window.removeEventListener('message', handleMessage);
@@ -1393,6 +1395,11 @@ class PopupLauncher {
1393
1395
  return;
1394
1396
  }
1395
1397
  const data = event.data;
1398
+ // A "ready" ping confirms the window loaded; notify but don't settle.
1399
+ if (options.readyType && data?.type === options.readyType) {
1400
+ options.onReady?.();
1401
+ return;
1402
+ }
1396
1403
  if (data?.type !== options.resultType) {
1397
1404
  return;
1398
1405
  }
@@ -1922,12 +1929,13 @@ const STYLE_ID$1 = 'sparkvault-identity-styles';
1922
1929
  */
1923
1930
  function injectStyles(options) {
1924
1931
  if (document.getElementById(STYLE_ID$1)) {
1925
- updateThemeVariables(options.branding);
1932
+ applyBrandingTheme(options.branding);
1926
1933
  updateBlur(options.backdropBlur);
1927
1934
  return;
1928
1935
  }
1929
1936
  const style = document.createElement('style');
1930
1937
  style.id = STYLE_ID$1;
1938
+ style.dataset.svTheme = resolveTheme(options.branding);
1931
1939
  style.textContent = getStyles(options);
1932
1940
  document.head.appendChild(style);
1933
1941
  }
@@ -1942,8 +1950,26 @@ function updateBlur(enabled) {
1942
1950
  }
1943
1951
  }
1944
1952
  }
1945
- function updateThemeVariables(_branding) {
1946
- // v1 branding doesn't include customizable colors
1953
+ /**
1954
+ * Re-theme the injected stylesheet when the resolved theme (light/dark) changes.
1955
+ *
1956
+ * Styles are first injected with default branding before config loads (so the
1957
+ * UI paints instantly), then `updateBranding` calls this with the tenant's real
1958
+ * `themeMode`. The theme is baked into the generated CSS (not runtime CSS
1959
+ * variables), so a theme switch requires regenerating the stylesheet - a no-op
1960
+ * when the theme is unchanged.
1961
+ */
1962
+ function applyBrandingTheme(branding) {
1963
+ const style = document.getElementById(STYLE_ID$1);
1964
+ if (!style)
1965
+ return;
1966
+ const theme = resolveTheme(branding);
1967
+ if (style.dataset.svTheme === theme)
1968
+ return;
1969
+ style.dataset.svTheme = theme;
1970
+ style.textContent = getStyles({
1971
+ branding: branding ?? { companyName: '', logoLight: null, logoDark: null },
1972
+ });
1947
1973
  }
1948
1974
  function resolveTheme(branding) {
1949
1975
  // Use themeMode from server config, default to light
@@ -1953,12 +1979,20 @@ function getStyles(options) {
1953
1979
  const { branding, backdropBlur } = options;
1954
1980
  const isDark = resolveTheme(branding) === 'dark';
1955
1981
  const enableBlur = backdropBlur !== false;
1956
- // Design tokens
1982
+ // Design tokens.
1983
+ //
1984
+ // The brand accent is driven by the `--sv-primary` / `--sv-primary-hover`
1985
+ // CSS custom properties so a host page (e.g. the SparkVault sign-in page) can
1986
+ // tint the whole flow to the tenant's brand color by setting them on `:root`.
1987
+ // The literals are the fallback - when no host sets the variables the UI is
1988
+ // pixel-identical to before. The focus glow is derived from the same accent
1989
+ // via color-mix so it tracks the brand too.
1990
+ const accent = 'var(--sv-primary, #4F46E5)';
1957
1991
  const tokens = {
1958
1992
  // Colors
1959
- primary: '#4F46E5',
1960
- primaryHover: '#4338CA',
1961
- primaryLight: isDark ? 'rgba(99, 102, 241, 0.15)' : 'rgba(79, 70, 229, 0.08)',
1993
+ primary: accent,
1994
+ primaryHover: 'var(--sv-primary-hover, #4338CA)',
1995
+ primaryLight: `color-mix(in srgb, ${accent} ${isDark ? '20%' : '9%'}, transparent)`,
1962
1996
  error: '#DC2626',
1963
1997
  errorLight: isDark ? 'rgba(220, 38, 38, 0.15)' : '#FEF2F2',
1964
1998
  errorBorder: isDark ? 'rgba(220, 38, 38, 0.3)' : '#FECACA',
@@ -1970,7 +2004,7 @@ function getStyles(options) {
1970
2004
  // Borders
1971
2005
  border: isDark ? '#262626' : '#E5E5E5',
1972
2006
  borderHover: isDark ? '#404040' : '#D4D4D4',
1973
- borderFocus: '#4F46E5',
2007
+ borderFocus: accent,
1974
2008
  // Text
1975
2009
  textPrimary: isDark ? '#FAFAFA' : '#0A0A0A',
1976
2010
  textSecondary: isDark ? '#A3A3A3' : '#525252',
@@ -2068,11 +2102,11 @@ function getStyles(options) {
2068
2102
  display: flex;
2069
2103
  align-items: center;
2070
2104
  justify-content: center;
2071
- background: transparent;
2105
+ background: ${tokens.bgSubtle};
2072
2106
  border: none;
2073
2107
  border-radius: 8px;
2074
2108
  cursor: pointer;
2075
- color: ${tokens.textMuted};
2109
+ color: ${tokens.textSecondary};
2076
2110
  transition: background 0.15s ease, color 0.15s ease;
2077
2111
  }
2078
2112
 
@@ -2121,6 +2155,7 @@ function getStyles(options) {
2121
2155
  color: ${tokens.textSecondary};
2122
2156
  margin: 0 0 16px 0;
2123
2157
  text-align: center;
2158
+ text-wrap: balance;
2124
2159
  }
2125
2160
 
2126
2161
  .sv-subtitle strong {
@@ -3188,6 +3223,130 @@ function getStyles(options) {
3188
3223
  padding-right: 32px;
3189
3224
  }
3190
3225
 
3226
+ /* Bare mode: the host page owns the surface and chrome, so the container
3227
+ is transparent and edge-free and the body hugs its content. */
3228
+ .sv-inline-bare {
3229
+ border: none;
3230
+ border-radius: 0;
3231
+ background: transparent;
3232
+ height: auto;
3233
+ }
3234
+
3235
+ .sv-inline-bare > .sv-inline-body {
3236
+ min-height: 0;
3237
+ padding-left: 0;
3238
+ padding-right: 0;
3239
+ }
3240
+
3241
+ /* ========================================
3242
+ BRIDGE MODAL (host page, while the sign-in popup runs)
3243
+ ======================================== */
3244
+
3245
+ .sv-bridge {
3246
+ text-align: center;
3247
+ padding: 4px 4px 6px;
3248
+ }
3249
+
3250
+ .sv-bridge-dots {
3251
+ display: flex;
3252
+ gap: 6px;
3253
+ align-items: center;
3254
+ justify-content: center;
3255
+ margin-bottom: 20px;
3256
+ }
3257
+
3258
+ .sv-bridge-dots span {
3259
+ width: 7px;
3260
+ height: 7px;
3261
+ border-radius: 50%;
3262
+ background: ${tokens.primary};
3263
+ animation: sv-bridge-pulse 1.3s ease-in-out infinite;
3264
+ }
3265
+
3266
+ .sv-bridge-dots span:nth-child(2) { animation-delay: 0.16s; }
3267
+ .sv-bridge-dots span:nth-child(3) { animation-delay: 0.32s; }
3268
+
3269
+ @keyframes sv-bridge-pulse {
3270
+ 0%, 100% { opacity: 0.28; transform: translateY(0); }
3271
+ 50% { opacity: 1; transform: translateY(-3px); }
3272
+ }
3273
+
3274
+ /* Warning shown under the logo only when the popup can't be confirmed -
3275
+ blocked, closed, or no result after a few seconds. Hidden on the happy
3276
+ path; appears with a gentle fade. */
3277
+ .sv-bridge-alert {
3278
+ display: flex;
3279
+ align-items: flex-start;
3280
+ gap: 10px;
3281
+ text-align: left;
3282
+ margin: 0 0 22px;
3283
+ padding: 11px 13px;
3284
+ border: 1px solid ${tokens.border};
3285
+ border-radius: 10px;
3286
+ background: ${tokens.bgSubtle};
3287
+ font-size: 13px;
3288
+ line-height: 1.45;
3289
+ opacity: 0;
3290
+ max-height: 0;
3291
+ padding-top: 0;
3292
+ padding-bottom: 0;
3293
+ margin-bottom: 0;
3294
+ border-width: 0;
3295
+ overflow: hidden;
3296
+ transition: opacity 0.25s ease;
3297
+ }
3298
+
3299
+ .sv-bridge-alert.sv-shown {
3300
+ opacity: 1;
3301
+ max-height: 120px;
3302
+ padding-top: 11px;
3303
+ padding-bottom: 11px;
3304
+ margin-bottom: 22px;
3305
+ border-width: 1px;
3306
+ }
3307
+
3308
+ .sv-bridge-alert-icon {
3309
+ flex-shrink: 0;
3310
+ width: 17px;
3311
+ height: 17px;
3312
+ margin-top: 1px;
3313
+ color: #d97706;
3314
+ }
3315
+
3316
+ /* Text stacked over the action, so the message keeps the full width and
3317
+ never wraps to a lone word beside a right-aligned button. */
3318
+ .sv-bridge-alert-body {
3319
+ display: flex;
3320
+ flex-direction: column;
3321
+ align-items: flex-start;
3322
+ gap: 7px;
3323
+ flex: 1;
3324
+ min-width: 0;
3325
+ line-height: 1.35;
3326
+ }
3327
+
3328
+ .sv-bridge-alert-text { color: ${tokens.textSecondary}; }
3329
+
3330
+ .sv-bridge-retry {
3331
+ padding: 0;
3332
+ background: none;
3333
+ border: none;
3334
+ font-family: inherit;
3335
+ font-size: 13px;
3336
+ font-weight: 600;
3337
+ color: ${tokens.primary};
3338
+ text-decoration: underline;
3339
+ text-underline-offset: 2px;
3340
+ cursor: pointer;
3341
+ }
3342
+
3343
+ .sv-bridge-retry:hover { color: ${tokens.primaryHover}; }
3344
+ .sv-bridge-retry:focus-visible { outline: 2px solid ${tokens.borderFocus}; outline-offset: 2px; border-radius: 4px; }
3345
+
3346
+ @media (prefers-reduced-motion: reduce) {
3347
+ .sv-bridge-dots span { animation: none; opacity: 0.5; }
3348
+ }
3349
+
3191
3350
  /* ========================================
3192
3351
  RESPONSIVE
3193
3352
  ======================================== */
@@ -3544,7 +3703,7 @@ const MODAL_ID$1 = 'sparkvault-identity-modal';
3544
3703
  * Default branding used for immediate modal display before config loads.
3545
3704
  * Uses neutral styling that works with both light and dark themes.
3546
3705
  */
3547
- const DEFAULT_BRANDING$1 = {
3706
+ const DEFAULT_BRANDING$2 = {
3548
3707
  companyName: '',
3549
3708
  logoLight: null,
3550
3709
  logoDark: null,
@@ -3570,7 +3729,7 @@ class ModalContainer {
3570
3729
  */
3571
3730
  createLoading(options, onClose) {
3572
3731
  return this.create({
3573
- branding: DEFAULT_BRANDING$1,
3732
+ branding: DEFAULT_BRANDING$2,
3574
3733
  backdropBlur: options.backdropBlur,
3575
3734
  }, onClose);
3576
3735
  }
@@ -3582,6 +3741,9 @@ class ModalContainer {
3582
3741
  if (!this.elements)
3583
3742
  return;
3584
3743
  this.effectiveTheme = resolveTheme(branding);
3744
+ // Re-theme the stylesheet if the tenant's themeMode differs from the
3745
+ // default used at first paint.
3746
+ applyBrandingTheme(branding);
3585
3747
  // Update header with real branding
3586
3748
  const newHeader = this.createHeader(branding);
3587
3749
  if (this.headerElement?.parentNode) {
@@ -7215,19 +7377,77 @@ class IdentityRenderer {
7215
7377
  /**
7216
7378
  * Dialog Launcher
7217
7379
  *
7218
- * Host-side half of the popup login flow. Dialog (modal) verification renders a
7219
- * thin email/phone launcher in the SDK's own ModalContainer, then — inside the
7220
- * user's submit gesture — opens a TOP-LEVEL popup on the Identity origin that
7221
- * runs the full login flow. Because the popup is top-level on api.sparkvault.com,
7222
- * login completion's first-party `__Host-authsv_sso` cookie persists.
7380
+ * Host-side half of the popup login flow. Dialog-mode `verify()` opens a
7381
+ * TOP-LEVEL popup on the Identity origin **directly inside the triggering user
7382
+ * gesture** and, on the host page, shades it with a small branded **bridge
7383
+ * modal** ("continue in the secure window"). The popup (the `chrome: 'bare'`
7384
+ * sign-in page) collects the identifier and runs the whole flow first-party, so
7385
+ * login's `__Host-authsv_sso` cookie persists. Any `email`/`phone` passed to
7386
+ * `verify()` is forwarded as a prefill.
7223
7387
  *
7224
- * The launcher only collects an identifier and bridges the popup result back;
7225
- * the flow UI itself lives in the popup (the renderMode:'local' renderer).
7388
+ * The popup must open synchronously in the gesture or the browser blocks it as
7389
+ * programmatic. `verify()` reaches `start()` through microtask-only awaits (the
7390
+ * redirect-result check does no I/O; the preloaded config resolves from cache),
7391
+ * so transient activation survives.
7392
+ *
7393
+ * It is one dialog. The happy path is clean: logo, a subtle animation, and
7394
+ * "continue in the secure window". A single warning appears under the logo only
7395
+ * when the popup can't be confirmed: it was blocked, it closed, or it never
7396
+ * posted a "ready" ping within `OPEN_TIMEOUT_MS` (so the open/load failed). Its
7397
+ * "Try again" reopens the popup. The header's close ✕ (or backdrop/Escape)
7398
+ * aborts and closes the popup.
7226
7399
  */
7227
- /** `data.type` the login popup posts back to the opener. */
7400
+ /** `data.type` the sign-in popup posts back to the opener. */
7228
7401
  const LOGIN_RESULT_TYPE = 'sparkvault-login-result';
7402
+ /** `data.type` the sign-in page posts once it has loaded (a liveness ping). */
7403
+ const LOGIN_READY_TYPE = 'sparkvault-login-ready';
7404
+ const DEFAULT_BRANDING$1 = { companyName: '', logoLight: null, logoDark: null };
7229
7405
  /**
7230
- * Renders the email/phone launcher modal and opens the login popup on submit.
7406
+ * How long to wait for the popup's "ready" ping before warning that the open
7407
+ * may have failed. A real window loads the page and pings within ~1-2s, so this
7408
+ * never fires during normal use (however long the person then takes to sign in);
7409
+ * it only fires when the window opened but the page never loaded.
7410
+ */
7411
+ const OPEN_TIMEOUT_MS = 8000;
7412
+ const SVG_NS = 'http://www.w3.org/2000/svg';
7413
+ function el(tag, className, text) {
7414
+ const node = document.createElement(tag);
7415
+ if (className)
7416
+ node.className = className;
7417
+ if (text != null)
7418
+ node.textContent = text;
7419
+ return node;
7420
+ }
7421
+ /** Small inline warning triangle; `currentColor` lets the CSS tint it amber. */
7422
+ function warningIcon() {
7423
+ const svg = document.createElementNS(SVG_NS, 'svg');
7424
+ svg.setAttribute('viewBox', '0 0 20 20');
7425
+ svg.setAttribute('fill', 'none');
7426
+ svg.classList.add('sv-bridge-alert-icon');
7427
+ const path = (d, attrs) => {
7428
+ const p = document.createElementNS(SVG_NS, 'path');
7429
+ p.setAttribute('d', d);
7430
+ for (const [k, v] of Object.entries(attrs))
7431
+ p.setAttribute(k, v);
7432
+ return p;
7433
+ };
7434
+ svg.appendChild(path('M10 2.75 18.25 17.25H1.75L10 2.75Z', {
7435
+ stroke: 'currentColor', 'stroke-width': '1.5', 'stroke-linejoin': 'round',
7436
+ }));
7437
+ svg.appendChild(path('M10 8.25v3.25', {
7438
+ stroke: 'currentColor', 'stroke-width': '1.5', 'stroke-linecap': 'round',
7439
+ }));
7440
+ const dot = document.createElementNS(SVG_NS, 'circle');
7441
+ dot.setAttribute('cx', '10');
7442
+ dot.setAttribute('cy', '14.5');
7443
+ dot.setAttribute('r', '0.95');
7444
+ dot.setAttribute('fill', 'currentColor');
7445
+ svg.appendChild(dot);
7446
+ return svg;
7447
+ }
7448
+ /**
7449
+ * Opens the sign-in popup for dialog-mode `verify()` and bridges its result
7450
+ * back, behind a single branded host-page modal.
7231
7451
  */
7232
7452
  class DialogLauncher {
7233
7453
  constructor(config, api, options, callbacks) {
@@ -7235,98 +7455,81 @@ class DialogLauncher {
7235
7455
  this.api = api;
7236
7456
  this.options = options;
7237
7457
  this.callbacks = callbacks;
7238
- this.modal = new ModalContainer();
7239
7458
  this.popupLauncher = new PopupLauncher();
7240
- this.currentView = null;
7459
+ this.modal = null;
7460
+ this.alertEl = null;
7461
+ this.popupWindow = null;
7462
+ this.openTimer = null;
7241
7463
  this.settled = false;
7242
- this.allowedTypes = ['email'];
7464
+ // Bumped on every open so a superseded popup's late result or ready ping
7465
+ // (e.g. the prior window after "Try again") is ignored.
7466
+ this.generation = 0;
7243
7467
  this.trustedOrigin = new URL(this.config.identityBaseUrl).origin;
7244
7468
  }
7245
- /**
7246
- * Mount the modal, then load config to render the identifier input (or a
7247
- * terminal error view when config fails).
7248
- */
7469
+ /** Shade the host with the bridge and open the popup in the caller's gesture. */
7249
7470
  start() {
7250
- this.modal.createLoading({ backdropBlur: this.options.backdropBlur }, () => this.handleClose());
7251
- this.api
7252
- .getConfig()
7253
- .then((config) => this.renderInput(config))
7254
- .catch((error) => this.renderConfigError(error));
7471
+ this.showBridge();
7472
+ this.openPopup();
7473
+ this.loadBranding();
7255
7474
  }
7256
- /**
7257
- * Close the launcher and tear everything down. Cancels in-flight config
7258
- * requests so a late resolution can't render into a destroyed modal.
7259
- */
7475
+ /** Tear down the bridge modal and close any popup it opened. */
7260
7476
  close() {
7261
- this.api.abort();
7262
- this.currentView?.destroy?.();
7263
- this.currentView = null;
7264
- this.modal.destroy();
7265
- }
7266
- handleClose() {
7267
- this.close();
7268
- if (!this.settled) {
7269
- this.settled = true;
7270
- this.callbacks.onCancel();
7271
- }
7272
- }
7273
- renderInput(config) {
7274
- if (config.branding) {
7275
- this.modal.updateBranding(config.branding);
7276
- }
7277
- const resolvedBackdropBlur = this.options.backdropBlur !== undefined
7278
- ? this.options.backdropBlur
7279
- : config.branding?.backdrop_blur ?? true;
7280
- this.modal.updateBackdropBlur(resolvedBackdropBlur);
7281
- this.allowedTypes = (config.allowedIdentityTypes ?? ['email']);
7282
- this.mountInput(undefined);
7283
- }
7284
- /**
7285
- * Render the identifier input. The submit handler runs synchronously inside
7286
- * the user gesture, so the popup open is never treated as programmatic (and
7287
- * never blocked).
7288
- */
7289
- mountInput(error) {
7290
- this.mountView(new IdentityInputView({
7291
- allowedTypes: this.allowedTypes,
7292
- initialValue: this.options.email ?? this.options.phone,
7293
- error,
7294
- onSubmit: (result) => this.handleIdentitySubmit(result),
7295
- }));
7296
- }
7297
- /**
7298
- * Open the login popup for the submitted identifier. SYNCHRONOUS: no await
7299
- * precedes window.open, so the browser keeps the user-gesture grant.
7300
- */
7301
- handleIdentitySubmit(result) {
7477
+ this.clearOpenTimer();
7478
+ this.closePopup();
7479
+ this.modal?.destroy();
7480
+ this.modal = null;
7481
+ this.alertEl = null;
7482
+ }
7483
+ openPopup() {
7484
+ const generation = ++this.generation;
7302
7485
  this.popupLauncher
7303
7486
  .openPopup({
7304
- url: this.buildPopupUrl(result),
7487
+ url: this.buildPopupUrl(),
7305
7488
  windowName: 'sparkvault-login',
7306
7489
  resultType: LOGIN_RESULT_TYPE,
7490
+ readyType: LOGIN_READY_TYPE,
7307
7491
  trustedOrigin: this.trustedOrigin,
7492
+ onOpen: (popup) => {
7493
+ if (generation !== this.generation)
7494
+ return;
7495
+ this.popupWindow = popup;
7496
+ this.scheduleOpenWarning();
7497
+ },
7498
+ // The page loaded and pinged back — the open succeeded, so cancel the
7499
+ // open-failure warning no matter how long the person now takes.
7500
+ onReady: () => { if (generation === this.generation)
7501
+ this.clearOpenTimer(); },
7308
7502
  })
7309
- .then((message) => this.handlePopupResult(message))
7310
- .catch((error) => this.handlePopupError(error));
7503
+ .then((message) => { if (generation === this.generation)
7504
+ this.handleResult(message); })
7505
+ .catch((error) => { if (generation === this.generation)
7506
+ this.handleError(error); });
7311
7507
  }
7312
- buildPopupUrl(result) {
7508
+ buildPopupUrl() {
7313
7509
  const params = new URLSearchParams({ origin: window.location.origin });
7314
- params.set(result.type, result.value);
7510
+ // Identifier prefill - the popup collects it itself when absent.
7511
+ if (this.options.email) {
7512
+ params.set('email', this.options.email);
7513
+ }
7514
+ else if (this.options.phone) {
7515
+ params.set('phone', this.options.phone);
7516
+ }
7517
+ // Auth context, in the query shape the sign-in page reads server-side:
7518
+ // OIDC rides `auth_request`; simple redirect rides `mode=simple` + the
7519
+ // opaque `session` (the page loads success/failure URLs from the session).
7315
7520
  const authContext = this.options.authContext;
7316
7521
  if (authContext?.authRequestId) {
7317
- params.set('auth_request_id', authContext.authRequestId);
7522
+ params.set('auth_request', authContext.authRequestId);
7318
7523
  }
7319
- if (authContext?.simpleMode) {
7320
- params.set('simple_mode', JSON.stringify({
7321
- success_url: authContext.simpleMode.successUrl,
7322
- failure_url: authContext.simpleMode.failureUrl,
7323
- state: authContext.simpleMode.state,
7324
- session_id: authContext.simpleMode.sessionId,
7325
- }));
7524
+ else if (authContext?.simpleMode?.sessionId) {
7525
+ params.set('mode', 'simple');
7526
+ params.set('session', authContext.simpleMode.sessionId);
7326
7527
  }
7327
- return `${this.config.identityBaseUrl}/${this.config.accountId}/popup?${params}`;
7528
+ return `${this.config.identityBaseUrl}/${this.config.accountId}/signin?${params}`;
7328
7529
  }
7329
- handlePopupResult(message) {
7530
+ handleResult(message) {
7531
+ if (this.settled)
7532
+ return;
7330
7533
  if (message.success && message.data) {
7331
7534
  const result = {
7332
7535
  token: message.data.token || '',
@@ -7342,75 +7545,116 @@ class DialogLauncher {
7342
7545
  return;
7343
7546
  }
7344
7547
  if (message.error === 'cancelled') {
7345
- // User backed out inside the popup — re-render the input so they can
7346
- // retry from the still-open launcher.
7347
- this.reEnableInput(undefined);
7548
+ // The person explicitly backed out inside the popup — end the flow rather
7549
+ // than offer to reopen to the same place.
7550
+ this.finishCancel();
7348
7551
  return;
7349
7552
  }
7350
7553
  this.finish();
7351
7554
  this.callbacks.onError(new SparkVaultError(message.message || message.error || 'Verification failed', message.errorCode || message.error || 'verification_failed'));
7352
7555
  }
7353
- handlePopupError(error) {
7354
- if (error instanceof UserCancelledError) {
7355
- // Manual popup close — let the user retry from the still-open launcher.
7356
- this.reEnableInput(undefined);
7556
+ handleError(error) {
7557
+ if (this.settled)
7357
7558
  return;
7358
- }
7359
- if (error instanceof PopupBlockedError) {
7360
- // Same inline "allow popups" surface the passkey path shows.
7361
- this.reEnableInput(error.message);
7559
+ // Blocked (never opened) or closed (gone) - the popup can't be confirmed,
7560
+ // so surface the warning so the user can reopen it.
7561
+ if (error instanceof PopupBlockedError || error instanceof UserCancelledError) {
7562
+ this.showAlert();
7362
7563
  return;
7363
7564
  }
7364
7565
  this.finish();
7365
7566
  this.callbacks.onError(error instanceof Error ? error : new Error(String(error)));
7366
7567
  }
7367
- /**
7368
- * Re-render the input (its Continue button is disabled to "Please wait…" on
7369
- * submit) so it is interactive again after a cancelled or blocked popup.
7370
- */
7371
- reEnableInput(error) {
7372
- if (this.settled || !this.modal.isOpen())
7568
+ /** Create the bridge modal (once) and render its single happy-path body. */
7569
+ showBridge() {
7570
+ if (this.settled)
7373
7571
  return;
7374
- this.mountInput(error);
7375
- }
7376
- renderConfigError(error) {
7377
- this.mountView(this.viewForConfigError(error));
7378
- }
7379
- viewForConfigError(error) {
7380
- if (error instanceof IdentityApiError) {
7381
- if (error.code === 'product_not_configured') {
7382
- return new ProductNotConfiguredView({ onClose: () => this.handleClose() });
7383
- }
7384
- if (error.code === 'ORIGIN_NOT_ALLOWED') {
7385
- const origin = typeof error.details?.origin === 'string' ? error.details.origin : undefined;
7386
- return new OriginNotAllowedView({ origin, onClose: () => this.handleClose() });
7387
- }
7572
+ if (!this.modal) {
7573
+ this.modal = new ModalContainer();
7574
+ this.modal.create({ branding: DEFAULT_BRANDING$1, backdropBlur: this.options.backdropBlur }, () => this.abort());
7388
7575
  }
7389
- return new ServiceUnavailableView({
7390
- onRetry: () => this.retryConfig(),
7391
- onClose: () => this.handleClose(),
7392
- });
7393
- }
7394
- retryConfig() {
7395
- this.mountView(new LoadingView({ message: 'Loading...' }));
7396
- this.api
7397
- .getConfig()
7398
- .then((config) => this.renderInput(config))
7399
- .catch((err) => this.renderConfigError(err));
7400
- }
7401
- mountView(view) {
7402
7576
  const body = this.modal.getBody();
7403
7577
  if (!body)
7404
7578
  return;
7405
- this.currentView?.destroy?.();
7406
7579
  clearChildren(body);
7407
- this.currentView = view;
7408
- body.appendChild(view.render());
7580
+ const wrap = el('div', 'sv-bridge');
7581
+ // Warning under the logo - collapsed until the popup can't be confirmed.
7582
+ const alert = el('div', 'sv-bridge-alert');
7583
+ alert.appendChild(warningIcon());
7584
+ const alertBody = el('div', 'sv-bridge-alert-body');
7585
+ alertBody.appendChild(el('span', 'sv-bridge-alert-text', 'The sign-in window may not have opened.'));
7586
+ const retry = el('button', 'sv-bridge-retry', 'Try again');
7587
+ retry.type = 'button';
7588
+ retry.addEventListener('click', () => this.retry());
7589
+ alertBody.appendChild(retry);
7590
+ alert.appendChild(alertBody);
7591
+ this.alertEl = alert;
7592
+ const dots = el('div', 'sv-bridge-dots');
7593
+ dots.append(el('span'), el('span'), el('span'));
7594
+ wrap.append(alert, dots, el('h3', 'sv-title', 'Continue in the secure window'), el('p', 'sv-subtitle', 'Finish signing in there. This page updates on its own.'));
7595
+ body.appendChild(wrap);
7596
+ }
7597
+ showAlert() {
7598
+ this.clearOpenTimer();
7599
+ this.alertEl?.classList.add('sv-shown');
7600
+ }
7601
+ hideAlert() {
7602
+ this.alertEl?.classList.remove('sv-shown');
7603
+ }
7604
+ scheduleOpenWarning() {
7605
+ this.clearOpenTimer();
7606
+ this.openTimer = setTimeout(() => this.showAlert(), OPEN_TIMEOUT_MS);
7607
+ }
7608
+ clearOpenTimer() {
7609
+ if (this.openTimer) {
7610
+ clearTimeout(this.openTimer);
7611
+ this.openTimer = null;
7612
+ }
7613
+ }
7614
+ /** "Try again": close any current popup and reopen a fresh one. */
7615
+ retry() {
7616
+ this.hideAlert();
7617
+ this.closePopup();
7618
+ this.openPopup();
7619
+ }
7620
+ /** Fetch branding once and drop the tenant logo into the modal header. */
7621
+ loadBranding() {
7622
+ this.api
7623
+ .getConfig()
7624
+ .then((config) => {
7625
+ if (config.branding && this.modal)
7626
+ this.modal.updateBranding(config.branding);
7627
+ })
7628
+ .catch(() => {
7629
+ // Keep the default chrome - the popup itself is fully branded.
7630
+ });
7631
+ }
7632
+ closePopup() {
7633
+ if (this.popupWindow && !this.popupWindow.closed) {
7634
+ try {
7635
+ this.popupWindow.close();
7636
+ }
7637
+ catch {
7638
+ // Cross-origin navigation or already gone - nothing to close.
7639
+ }
7640
+ }
7641
+ this.popupWindow = null;
7642
+ }
7643
+ /** Explicit abort (close ✕, backdrop, Escape): close the popup and cancel. */
7644
+ abort() {
7645
+ this.finishCancel();
7409
7646
  }
7410
7647
  finish() {
7411
7648
  this.settled = true;
7412
7649
  this.close();
7413
7650
  }
7651
+ finishCancel() {
7652
+ if (this.settled)
7653
+ return;
7654
+ this.settled = true;
7655
+ this.close();
7656
+ this.callbacks.onCancel();
7657
+ }
7414
7658
  }
7415
7659
 
7416
7660
  /**
@@ -7460,7 +7704,9 @@ class InlineContainer {
7460
7704
  injectStyles(styleOptions);
7461
7705
  // Create main container
7462
7706
  this.container = document.createElement('div');
7463
- this.container.className = 'sv-inline-container';
7707
+ this.container.className = this.containerOptions.bare
7708
+ ? 'sv-inline-container sv-inline-bare'
7709
+ : 'sv-inline-container';
7464
7710
  // Create header if enabled
7465
7711
  if (this.containerOptions.showHeader) {
7466
7712
  this.header = this.createHeader({
@@ -7504,6 +7750,7 @@ class InlineContainer {
7504
7750
  if (!this.container)
7505
7751
  return;
7506
7752
  this.effectiveTheme = resolveTheme(branding);
7753
+ applyBrandingTheme(branding);
7507
7754
  // Update header with real branding
7508
7755
  if (this.containerOptions.showHeader && this.header) {
7509
7756
  const newHeader = this.createHeader(branding);
@@ -7944,7 +8191,9 @@ class IdentityModule {
7944
8191
  this.launcher.start();
7945
8192
  return settledPromise;
7946
8193
  }
7947
- startLocalRender(isInline ? this.createInlineContainer(options.target) : new ModalContainer());
8194
+ startLocalRender(isInline
8195
+ ? this.createInlineContainer(options.target, options.chrome === 'bare')
8196
+ : new ModalContainer());
7948
8197
  return settledPromise;
7949
8198
  }
7950
8199
  /**
@@ -8149,7 +8398,7 @@ class IdentityModule {
8149
8398
  /**
8150
8399
  * Resolve target to an HTMLElement.
8151
8400
  */
8152
- createInlineContainer(target) {
8401
+ createInlineContainer(target, bare = false) {
8153
8402
  let element;
8154
8403
  if (typeof target === 'string') {
8155
8404
  const found = document.querySelector(target);
@@ -8164,7 +8413,9 @@ class IdentityModule {
8164
8413
  else {
8165
8414
  throw new ValidationError('Target must be a CSS selector string or HTMLElement');
8166
8415
  }
8167
- return new InlineContainer(element);
8416
+ // Bare chrome: the host page owns logo + footer + background, so drop the
8417
+ // container's own surface and the SparkVault footer.
8418
+ return new InlineContainer(element, bare ? { bare: true, showFooter: false } : {});
8168
8419
  }
8169
8420
  // Public-API aliases. The documented method names in the customer-facing
8170
8421
  // SDK README and the API docs are pop() and render(); verify() is the