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