@sparkvault/sdk-js 8.1.0 → 8.1.2
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 +407 -149
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +407 -149
- 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.esm.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
1946
|
-
|
|
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:
|
|
1960
|
-
primaryHover: '#4338CA',
|
|
1961
|
-
primaryLight:
|
|
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:
|
|
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:
|
|
2105
|
+
background: ${tokens.bgSubtle};
|
|
2072
2106
|
border: none;
|
|
2073
2107
|
border-radius: 8px;
|
|
2074
2108
|
cursor: pointer;
|
|
2075
|
-
color: ${tokens.
|
|
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$
|
|
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$
|
|
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) {
|
|
@@ -5773,11 +5935,18 @@ class OriginNotAllowedView {
|
|
|
5773
5935
|
* Uses extracted handlers for OTP and Passkey operations.
|
|
5774
5936
|
*/
|
|
5775
5937
|
/**
|
|
5776
|
-
* End-user copy for a blocked Identity. Intentionally
|
|
5777
|
-
* the trial, billing, usage, or any owner-facing internal.
|
|
5778
|
-
*
|
|
5938
|
+
* End-user copy for a blocked Identity. Intentionally non-leaky — it never names
|
|
5939
|
+
* the trial, billing, usage, or any owner-facing internal. When the site's
|
|
5940
|
+
* company name is known it is surfaced so the screen reads as the site's own and
|
|
5941
|
+
* the visitor is pointed back to the site for help (never to SparkVault). The
|
|
5942
|
+
* site owner is nudged to subscribe through their own dashboard and emails.
|
|
5779
5943
|
*/
|
|
5780
|
-
|
|
5944
|
+
function blockedSignInMessage(companyName) {
|
|
5945
|
+
const name = companyName?.trim();
|
|
5946
|
+
return name
|
|
5947
|
+
? `Sign-in for ${name} is temporarily unavailable. Please contact them for assistance.`
|
|
5948
|
+
: 'Sign-in is temporarily unavailable. Please contact the site owner for assistance.';
|
|
5949
|
+
}
|
|
5781
5950
|
const BLOCKED_ERROR_CODES = new Set(IDENTITY_BLOCKED_ERROR_CODES);
|
|
5782
5951
|
const SPARKLINK_CSP_BLOCKED_ERROR = {
|
|
5783
5952
|
message: [
|
|
@@ -6416,7 +6585,7 @@ class IdentityRenderer {
|
|
|
6416
6585
|
this.setState({
|
|
6417
6586
|
view: 'error',
|
|
6418
6587
|
code,
|
|
6419
|
-
message:
|
|
6588
|
+
message: blockedSignInMessage(this.verificationState.sdkConfig?.branding?.companyName),
|
|
6420
6589
|
});
|
|
6421
6590
|
return true;
|
|
6422
6591
|
}
|
|
@@ -7215,19 +7384,77 @@ class IdentityRenderer {
|
|
|
7215
7384
|
/**
|
|
7216
7385
|
* Dialog Launcher
|
|
7217
7386
|
*
|
|
7218
|
-
* Host-side half of the popup login flow. Dialog (
|
|
7219
|
-
*
|
|
7220
|
-
*
|
|
7221
|
-
*
|
|
7222
|
-
*
|
|
7387
|
+
* Host-side half of the popup login flow. Dialog-mode `verify()` opens a
|
|
7388
|
+
* TOP-LEVEL popup on the Identity origin **directly inside the triggering user
|
|
7389
|
+
* gesture** and, on the host page, shades it with a small branded **bridge
|
|
7390
|
+
* modal** ("continue in the secure window"). The popup (the `chrome: 'bare'`
|
|
7391
|
+
* sign-in page) collects the identifier and runs the whole flow first-party, so
|
|
7392
|
+
* login's `__Host-authsv_sso` cookie persists. Any `email`/`phone` passed to
|
|
7393
|
+
* `verify()` is forwarded as a prefill.
|
|
7394
|
+
*
|
|
7395
|
+
* The popup must open synchronously in the gesture or the browser blocks it as
|
|
7396
|
+
* programmatic. `verify()` reaches `start()` through microtask-only awaits (the
|
|
7397
|
+
* redirect-result check does no I/O; the preloaded config resolves from cache),
|
|
7398
|
+
* so transient activation survives.
|
|
7223
7399
|
*
|
|
7224
|
-
*
|
|
7225
|
-
* the
|
|
7400
|
+
* It is one dialog. The happy path is clean: logo, a subtle animation, and
|
|
7401
|
+
* "continue in the secure window". A single warning appears under the logo only
|
|
7402
|
+
* when the popup can't be confirmed: it was blocked, it closed, or it never
|
|
7403
|
+
* posted a "ready" ping within `OPEN_TIMEOUT_MS` (so the open/load failed). Its
|
|
7404
|
+
* "Try again" reopens the popup. The header's close ✕ (or backdrop/Escape)
|
|
7405
|
+
* aborts and closes the popup.
|
|
7226
7406
|
*/
|
|
7227
|
-
/** `data.type` the
|
|
7407
|
+
/** `data.type` the sign-in popup posts back to the opener. */
|
|
7228
7408
|
const LOGIN_RESULT_TYPE = 'sparkvault-login-result';
|
|
7409
|
+
/** `data.type` the sign-in page posts once it has loaded (a liveness ping). */
|
|
7410
|
+
const LOGIN_READY_TYPE = 'sparkvault-login-ready';
|
|
7411
|
+
const DEFAULT_BRANDING$1 = { companyName: '', logoLight: null, logoDark: null };
|
|
7229
7412
|
/**
|
|
7230
|
-
*
|
|
7413
|
+
* How long to wait for the popup's "ready" ping before warning that the open
|
|
7414
|
+
* may have failed. A real window loads the page and pings within ~1-2s, so this
|
|
7415
|
+
* never fires during normal use (however long the person then takes to sign in);
|
|
7416
|
+
* it only fires when the window opened but the page never loaded.
|
|
7417
|
+
*/
|
|
7418
|
+
const OPEN_TIMEOUT_MS = 8000;
|
|
7419
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
7420
|
+
function el(tag, className, text) {
|
|
7421
|
+
const node = document.createElement(tag);
|
|
7422
|
+
if (className)
|
|
7423
|
+
node.className = className;
|
|
7424
|
+
if (text != null)
|
|
7425
|
+
node.textContent = text;
|
|
7426
|
+
return node;
|
|
7427
|
+
}
|
|
7428
|
+
/** Small inline warning triangle; `currentColor` lets the CSS tint it amber. */
|
|
7429
|
+
function warningIcon() {
|
|
7430
|
+
const svg = document.createElementNS(SVG_NS, 'svg');
|
|
7431
|
+
svg.setAttribute('viewBox', '0 0 20 20');
|
|
7432
|
+
svg.setAttribute('fill', 'none');
|
|
7433
|
+
svg.classList.add('sv-bridge-alert-icon');
|
|
7434
|
+
const path = (d, attrs) => {
|
|
7435
|
+
const p = document.createElementNS(SVG_NS, 'path');
|
|
7436
|
+
p.setAttribute('d', d);
|
|
7437
|
+
for (const [k, v] of Object.entries(attrs))
|
|
7438
|
+
p.setAttribute(k, v);
|
|
7439
|
+
return p;
|
|
7440
|
+
};
|
|
7441
|
+
svg.appendChild(path('M10 2.75 18.25 17.25H1.75L10 2.75Z', {
|
|
7442
|
+
stroke: 'currentColor', 'stroke-width': '1.5', 'stroke-linejoin': 'round',
|
|
7443
|
+
}));
|
|
7444
|
+
svg.appendChild(path('M10 8.25v3.25', {
|
|
7445
|
+
stroke: 'currentColor', 'stroke-width': '1.5', 'stroke-linecap': 'round',
|
|
7446
|
+
}));
|
|
7447
|
+
const dot = document.createElementNS(SVG_NS, 'circle');
|
|
7448
|
+
dot.setAttribute('cx', '10');
|
|
7449
|
+
dot.setAttribute('cy', '14.5');
|
|
7450
|
+
dot.setAttribute('r', '0.95');
|
|
7451
|
+
dot.setAttribute('fill', 'currentColor');
|
|
7452
|
+
svg.appendChild(dot);
|
|
7453
|
+
return svg;
|
|
7454
|
+
}
|
|
7455
|
+
/**
|
|
7456
|
+
* Opens the sign-in popup for dialog-mode `verify()` and bridges its result
|
|
7457
|
+
* back, behind a single branded host-page modal.
|
|
7231
7458
|
*/
|
|
7232
7459
|
class DialogLauncher {
|
|
7233
7460
|
constructor(config, api, options, callbacks) {
|
|
@@ -7235,98 +7462,81 @@ class DialogLauncher {
|
|
|
7235
7462
|
this.api = api;
|
|
7236
7463
|
this.options = options;
|
|
7237
7464
|
this.callbacks = callbacks;
|
|
7238
|
-
this.modal = new ModalContainer();
|
|
7239
7465
|
this.popupLauncher = new PopupLauncher();
|
|
7240
|
-
this.
|
|
7466
|
+
this.modal = null;
|
|
7467
|
+
this.alertEl = null;
|
|
7468
|
+
this.popupWindow = null;
|
|
7469
|
+
this.openTimer = null;
|
|
7241
7470
|
this.settled = false;
|
|
7242
|
-
|
|
7471
|
+
// Bumped on every open so a superseded popup's late result or ready ping
|
|
7472
|
+
// (e.g. the prior window after "Try again") is ignored.
|
|
7473
|
+
this.generation = 0;
|
|
7243
7474
|
this.trustedOrigin = new URL(this.config.identityBaseUrl).origin;
|
|
7244
7475
|
}
|
|
7245
|
-
/**
|
|
7246
|
-
* Mount the modal, then load config to render the identifier input (or a
|
|
7247
|
-
* terminal error view when config fails).
|
|
7248
|
-
*/
|
|
7476
|
+
/** Shade the host with the bridge and open the popup in the caller's gesture. */
|
|
7249
7477
|
start() {
|
|
7250
|
-
this.
|
|
7251
|
-
this.
|
|
7252
|
-
|
|
7253
|
-
.then((config) => this.renderInput(config))
|
|
7254
|
-
.catch((error) => this.renderConfigError(error));
|
|
7478
|
+
this.showBridge();
|
|
7479
|
+
this.openPopup();
|
|
7480
|
+
this.loadBranding();
|
|
7255
7481
|
}
|
|
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
|
-
*/
|
|
7482
|
+
/** Tear down the bridge modal and close any popup it opened. */
|
|
7260
7483
|
close() {
|
|
7261
|
-
this.
|
|
7262
|
-
this.
|
|
7263
|
-
this.
|
|
7264
|
-
this.modal
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
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) {
|
|
7484
|
+
this.clearOpenTimer();
|
|
7485
|
+
this.closePopup();
|
|
7486
|
+
this.modal?.destroy();
|
|
7487
|
+
this.modal = null;
|
|
7488
|
+
this.alertEl = null;
|
|
7489
|
+
}
|
|
7490
|
+
openPopup() {
|
|
7491
|
+
const generation = ++this.generation;
|
|
7302
7492
|
this.popupLauncher
|
|
7303
7493
|
.openPopup({
|
|
7304
|
-
url: this.buildPopupUrl(
|
|
7494
|
+
url: this.buildPopupUrl(),
|
|
7305
7495
|
windowName: 'sparkvault-login',
|
|
7306
7496
|
resultType: LOGIN_RESULT_TYPE,
|
|
7497
|
+
readyType: LOGIN_READY_TYPE,
|
|
7307
7498
|
trustedOrigin: this.trustedOrigin,
|
|
7499
|
+
onOpen: (popup) => {
|
|
7500
|
+
if (generation !== this.generation)
|
|
7501
|
+
return;
|
|
7502
|
+
this.popupWindow = popup;
|
|
7503
|
+
this.scheduleOpenWarning();
|
|
7504
|
+
},
|
|
7505
|
+
// The page loaded and pinged back — the open succeeded, so cancel the
|
|
7506
|
+
// open-failure warning no matter how long the person now takes.
|
|
7507
|
+
onReady: () => { if (generation === this.generation)
|
|
7508
|
+
this.clearOpenTimer(); },
|
|
7308
7509
|
})
|
|
7309
|
-
.then((message) => this.
|
|
7310
|
-
.
|
|
7510
|
+
.then((message) => { if (generation === this.generation)
|
|
7511
|
+
this.handleResult(message); })
|
|
7512
|
+
.catch((error) => { if (generation === this.generation)
|
|
7513
|
+
this.handleError(error); });
|
|
7311
7514
|
}
|
|
7312
|
-
buildPopupUrl(
|
|
7515
|
+
buildPopupUrl() {
|
|
7313
7516
|
const params = new URLSearchParams({ origin: window.location.origin });
|
|
7314
|
-
|
|
7517
|
+
// Identifier prefill - the popup collects it itself when absent.
|
|
7518
|
+
if (this.options.email) {
|
|
7519
|
+
params.set('email', this.options.email);
|
|
7520
|
+
}
|
|
7521
|
+
else if (this.options.phone) {
|
|
7522
|
+
params.set('phone', this.options.phone);
|
|
7523
|
+
}
|
|
7524
|
+
// Auth context, in the query shape the sign-in page reads server-side:
|
|
7525
|
+
// OIDC rides `auth_request`; simple redirect rides `mode=simple` + the
|
|
7526
|
+
// opaque `session` (the page loads success/failure URLs from the session).
|
|
7315
7527
|
const authContext = this.options.authContext;
|
|
7316
7528
|
if (authContext?.authRequestId) {
|
|
7317
|
-
params.set('
|
|
7529
|
+
params.set('auth_request', authContext.authRequestId);
|
|
7318
7530
|
}
|
|
7319
|
-
if (authContext?.simpleMode) {
|
|
7320
|
-
params.set('
|
|
7321
|
-
|
|
7322
|
-
failure_url: authContext.simpleMode.failureUrl,
|
|
7323
|
-
state: authContext.simpleMode.state,
|
|
7324
|
-
session_id: authContext.simpleMode.sessionId,
|
|
7325
|
-
}));
|
|
7531
|
+
else if (authContext?.simpleMode?.sessionId) {
|
|
7532
|
+
params.set('mode', 'simple');
|
|
7533
|
+
params.set('session', authContext.simpleMode.sessionId);
|
|
7326
7534
|
}
|
|
7327
|
-
return `${this.config.identityBaseUrl}/${this.config.accountId}/
|
|
7535
|
+
return `${this.config.identityBaseUrl}/${this.config.accountId}/signin?${params}`;
|
|
7328
7536
|
}
|
|
7329
|
-
|
|
7537
|
+
handleResult(message) {
|
|
7538
|
+
if (this.settled)
|
|
7539
|
+
return;
|
|
7330
7540
|
if (message.success && message.data) {
|
|
7331
7541
|
const result = {
|
|
7332
7542
|
token: message.data.token || '',
|
|
@@ -7342,75 +7552,116 @@ class DialogLauncher {
|
|
|
7342
7552
|
return;
|
|
7343
7553
|
}
|
|
7344
7554
|
if (message.error === 'cancelled') {
|
|
7345
|
-
//
|
|
7346
|
-
//
|
|
7347
|
-
this.
|
|
7555
|
+
// The person explicitly backed out inside the popup — end the flow rather
|
|
7556
|
+
// than offer to reopen to the same place.
|
|
7557
|
+
this.finishCancel();
|
|
7348
7558
|
return;
|
|
7349
7559
|
}
|
|
7350
7560
|
this.finish();
|
|
7351
7561
|
this.callbacks.onError(new SparkVaultError(message.message || message.error || 'Verification failed', message.errorCode || message.error || 'verification_failed'));
|
|
7352
7562
|
}
|
|
7353
|
-
|
|
7354
|
-
if (
|
|
7355
|
-
// Manual popup close — let the user retry from the still-open launcher.
|
|
7356
|
-
this.reEnableInput(undefined);
|
|
7563
|
+
handleError(error) {
|
|
7564
|
+
if (this.settled)
|
|
7357
7565
|
return;
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
this.
|
|
7566
|
+
// Blocked (never opened) or closed (gone) - the popup can't be confirmed,
|
|
7567
|
+
// so surface the warning so the user can reopen it.
|
|
7568
|
+
if (error instanceof PopupBlockedError || error instanceof UserCancelledError) {
|
|
7569
|
+
this.showAlert();
|
|
7362
7570
|
return;
|
|
7363
7571
|
}
|
|
7364
7572
|
this.finish();
|
|
7365
7573
|
this.callbacks.onError(error instanceof Error ? error : new Error(String(error)));
|
|
7366
7574
|
}
|
|
7367
|
-
/**
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
*/
|
|
7371
|
-
reEnableInput(error) {
|
|
7372
|
-
if (this.settled || !this.modal.isOpen())
|
|
7575
|
+
/** Create the bridge modal (once) and render its single happy-path body. */
|
|
7576
|
+
showBridge() {
|
|
7577
|
+
if (this.settled)
|
|
7373
7578
|
return;
|
|
7374
|
-
this.
|
|
7375
|
-
|
|
7376
|
-
|
|
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
|
-
}
|
|
7579
|
+
if (!this.modal) {
|
|
7580
|
+
this.modal = new ModalContainer();
|
|
7581
|
+
this.modal.create({ branding: DEFAULT_BRANDING$1, backdropBlur: this.options.backdropBlur }, () => this.abort());
|
|
7388
7582
|
}
|
|
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
7583
|
const body = this.modal.getBody();
|
|
7403
7584
|
if (!body)
|
|
7404
7585
|
return;
|
|
7405
|
-
this.currentView?.destroy?.();
|
|
7406
7586
|
clearChildren(body);
|
|
7407
|
-
|
|
7408
|
-
|
|
7587
|
+
const wrap = el('div', 'sv-bridge');
|
|
7588
|
+
// Warning under the logo - collapsed until the popup can't be confirmed.
|
|
7589
|
+
const alert = el('div', 'sv-bridge-alert');
|
|
7590
|
+
alert.appendChild(warningIcon());
|
|
7591
|
+
const alertBody = el('div', 'sv-bridge-alert-body');
|
|
7592
|
+
alertBody.appendChild(el('span', 'sv-bridge-alert-text', 'The sign-in window may not have opened.'));
|
|
7593
|
+
const retry = el('button', 'sv-bridge-retry', 'Try again');
|
|
7594
|
+
retry.type = 'button';
|
|
7595
|
+
retry.addEventListener('click', () => this.retry());
|
|
7596
|
+
alertBody.appendChild(retry);
|
|
7597
|
+
alert.appendChild(alertBody);
|
|
7598
|
+
this.alertEl = alert;
|
|
7599
|
+
const dots = el('div', 'sv-bridge-dots');
|
|
7600
|
+
dots.append(el('span'), el('span'), el('span'));
|
|
7601
|
+
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.'));
|
|
7602
|
+
body.appendChild(wrap);
|
|
7603
|
+
}
|
|
7604
|
+
showAlert() {
|
|
7605
|
+
this.clearOpenTimer();
|
|
7606
|
+
this.alertEl?.classList.add('sv-shown');
|
|
7607
|
+
}
|
|
7608
|
+
hideAlert() {
|
|
7609
|
+
this.alertEl?.classList.remove('sv-shown');
|
|
7610
|
+
}
|
|
7611
|
+
scheduleOpenWarning() {
|
|
7612
|
+
this.clearOpenTimer();
|
|
7613
|
+
this.openTimer = setTimeout(() => this.showAlert(), OPEN_TIMEOUT_MS);
|
|
7614
|
+
}
|
|
7615
|
+
clearOpenTimer() {
|
|
7616
|
+
if (this.openTimer) {
|
|
7617
|
+
clearTimeout(this.openTimer);
|
|
7618
|
+
this.openTimer = null;
|
|
7619
|
+
}
|
|
7620
|
+
}
|
|
7621
|
+
/** "Try again": close any current popup and reopen a fresh one. */
|
|
7622
|
+
retry() {
|
|
7623
|
+
this.hideAlert();
|
|
7624
|
+
this.closePopup();
|
|
7625
|
+
this.openPopup();
|
|
7626
|
+
}
|
|
7627
|
+
/** Fetch branding once and drop the tenant logo into the modal header. */
|
|
7628
|
+
loadBranding() {
|
|
7629
|
+
this.api
|
|
7630
|
+
.getConfig()
|
|
7631
|
+
.then((config) => {
|
|
7632
|
+
if (config.branding && this.modal)
|
|
7633
|
+
this.modal.updateBranding(config.branding);
|
|
7634
|
+
})
|
|
7635
|
+
.catch(() => {
|
|
7636
|
+
// Keep the default chrome - the popup itself is fully branded.
|
|
7637
|
+
});
|
|
7638
|
+
}
|
|
7639
|
+
closePopup() {
|
|
7640
|
+
if (this.popupWindow && !this.popupWindow.closed) {
|
|
7641
|
+
try {
|
|
7642
|
+
this.popupWindow.close();
|
|
7643
|
+
}
|
|
7644
|
+
catch {
|
|
7645
|
+
// Cross-origin navigation or already gone - nothing to close.
|
|
7646
|
+
}
|
|
7647
|
+
}
|
|
7648
|
+
this.popupWindow = null;
|
|
7649
|
+
}
|
|
7650
|
+
/** Explicit abort (close ✕, backdrop, Escape): close the popup and cancel. */
|
|
7651
|
+
abort() {
|
|
7652
|
+
this.finishCancel();
|
|
7409
7653
|
}
|
|
7410
7654
|
finish() {
|
|
7411
7655
|
this.settled = true;
|
|
7412
7656
|
this.close();
|
|
7413
7657
|
}
|
|
7658
|
+
finishCancel() {
|
|
7659
|
+
if (this.settled)
|
|
7660
|
+
return;
|
|
7661
|
+
this.settled = true;
|
|
7662
|
+
this.close();
|
|
7663
|
+
this.callbacks.onCancel();
|
|
7664
|
+
}
|
|
7414
7665
|
}
|
|
7415
7666
|
|
|
7416
7667
|
/**
|
|
@@ -7460,7 +7711,9 @@ class InlineContainer {
|
|
|
7460
7711
|
injectStyles(styleOptions);
|
|
7461
7712
|
// Create main container
|
|
7462
7713
|
this.container = document.createElement('div');
|
|
7463
|
-
this.container.className =
|
|
7714
|
+
this.container.className = this.containerOptions.bare
|
|
7715
|
+
? 'sv-inline-container sv-inline-bare'
|
|
7716
|
+
: 'sv-inline-container';
|
|
7464
7717
|
// Create header if enabled
|
|
7465
7718
|
if (this.containerOptions.showHeader) {
|
|
7466
7719
|
this.header = this.createHeader({
|
|
@@ -7504,6 +7757,7 @@ class InlineContainer {
|
|
|
7504
7757
|
if (!this.container)
|
|
7505
7758
|
return;
|
|
7506
7759
|
this.effectiveTheme = resolveTheme(branding);
|
|
7760
|
+
applyBrandingTheme(branding);
|
|
7507
7761
|
// Update header with real branding
|
|
7508
7762
|
if (this.containerOptions.showHeader && this.header) {
|
|
7509
7763
|
const newHeader = this.createHeader(branding);
|
|
@@ -7944,7 +8198,9 @@ class IdentityModule {
|
|
|
7944
8198
|
this.launcher.start();
|
|
7945
8199
|
return settledPromise;
|
|
7946
8200
|
}
|
|
7947
|
-
startLocalRender(isInline
|
|
8201
|
+
startLocalRender(isInline
|
|
8202
|
+
? this.createInlineContainer(options.target, options.chrome === 'bare')
|
|
8203
|
+
: new ModalContainer());
|
|
7948
8204
|
return settledPromise;
|
|
7949
8205
|
}
|
|
7950
8206
|
/**
|
|
@@ -8149,7 +8405,7 @@ class IdentityModule {
|
|
|
8149
8405
|
/**
|
|
8150
8406
|
* Resolve target to an HTMLElement.
|
|
8151
8407
|
*/
|
|
8152
|
-
createInlineContainer(target) {
|
|
8408
|
+
createInlineContainer(target, bare = false) {
|
|
8153
8409
|
let element;
|
|
8154
8410
|
if (typeof target === 'string') {
|
|
8155
8411
|
const found = document.querySelector(target);
|
|
@@ -8164,7 +8420,9 @@ class IdentityModule {
|
|
|
8164
8420
|
else {
|
|
8165
8421
|
throw new ValidationError('Target must be a CSS selector string or HTMLElement');
|
|
8166
8422
|
}
|
|
8167
|
-
|
|
8423
|
+
// Bare chrome: the host page owns logo + footer + background, so drop the
|
|
8424
|
+
// container's own surface and the SparkVault footer.
|
|
8425
|
+
return new InlineContainer(element, bare ? { bare: true, showFooter: false } : {});
|
|
8168
8426
|
}
|
|
8169
8427
|
// Public-API aliases. The documented method names in the customer-facing
|
|
8170
8428
|
// SDK README and the API docs are pop() and render(); verify() is the
|