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