@sparkvault/sdk-js 8.0.1 → 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 CHANGED
@@ -108,29 +108,23 @@ interface VerifyOptions {
108
108
  target?: string | HTMLElement;
109
109
  /** Override backdrop blur for this dialog (uses global config if omitted) */
110
110
  backdropBlur?: boolean;
111
- /** Auth context for OIDC/simple mode flows (used by hosted login) */
112
- authContext?: AuthContext;
113
- /**
114
- * Rendering strategy (internal).
115
- * - `'embed'` (default for dialog mode): inject a cross-origin iframe to the
116
- * SparkVault-hosted widget and bridge the result. Lets passkey login
117
- * complete in one tap with no popup.
118
- * - `'local'`: render the flow directly in this document. Used inside the
119
- * hosted widget itself, and forced for inline (`target`) rendering.
120
- */
121
- renderMode?: 'embed' | 'local';
122
111
  /**
123
- * Navigation override (internal). When the flow runs inside the embed
124
- * iframe, redirects (social, OIDC) are handed to the host's top window via
125
- * this hook instead of navigating the iframe. Omitted outside the iframe.
112
+ * Container chrome for inline (`target`) rendering. `'card'` (default) wraps
113
+ * the flow in a bordered, rounded surface with the SparkVault footer. `'bare'`
114
+ * drops the surface and footer so a host page (e.g. the SparkVault sign-in
115
+ * page) can supply its own full-window chrome — logo, background, footer.
116
+ * Ignored in dialog mode.
126
117
  */
127
- onNavigate?: (url: string) => void;
118
+ chrome?: 'card' | 'bare';
119
+ /** Auth context for OIDC/simple mode flows (used by hosted login) */
120
+ authContext?: AuthContext;
128
121
  /**
129
- * Social-login override (internal). When embedded, social must be started
130
- * from the host so its OAuth state and redirect_uri live on the customer's
131
- * top origin. The renderer hands the provider up instead of redirecting.
122
+ * Rendering strategy (internal). `'local'` renders the flow directly in this
123
+ * document — used inside the popup that runs the flow, and forced for inline
124
+ * (`target`) rendering. Dialog mode (omitted) renders a thin launcher and
125
+ * opens the popup.
132
126
  */
133
- onSocial?: (provider: string) => void;
127
+ renderMode?: 'local';
134
128
  /** Called when user cancels (if omitted, uses server-configured redirect) */
135
129
  onCancel?: () => void;
136
130
  /** Called when verification completes (if omitted, uses server-configured redirect) */
@@ -295,7 +289,7 @@ declare class IdentityModule {
295
289
  private readonly config;
296
290
  private readonly api;
297
291
  private renderer;
298
- private embedder;
292
+ private launcher;
299
293
  constructor(config: ResolvedConfig);
300
294
  /**
301
295
  * Build a deep link into the person's auth.sv Identity portal — where they
@@ -397,19 +391,18 @@ declare class IdentityModule {
397
391
  /**
398
392
  * Close the identity dialog/inline UI if open.
399
393
  *
400
- * Tears down whichever surface is active: the hosted-widget iframe
401
- * (default dialog mode — also releases the embedder's host scroll lock)
402
- * or the local renderer (inline / local mode).
394
+ * Tears down whichever surface is active: the dialog launcher (default dialog
395
+ * mode) or the local renderer (inline / local mode).
403
396
  */
404
397
  close(): void;
405
398
  /**
406
399
  * Whether the preloaded config has already settled as a *permanent* failure
407
- * the hosted widget can't surface (origin not allowed, or product not
408
- * configured). Used to skip the iframe and show the error dialog in-page
409
- * immediately. Returns false — proceed to embed — when config is not
410
- * preloaded, still in flight (raced against a short timeout so the common
411
- * path is never delayed), resolved, or failed only transiently (so one-tap
412
- * passkey login via the frame is preserved).
400
+ * the popup can't surface (origin not allowed, or product not configured).
401
+ * Used to skip the launcher and show the error dialog in-page immediately.
402
+ * Returns false — proceed to the launcher — when config is not preloaded,
403
+ * still in flight (raced against a short timeout so the common path is never
404
+ * delayed), resolved, or failed only transiently (the launcher surfaces a
405
+ * transient failure in its own dialog).
413
406
  */
414
407
  private preloadedConfigPermanentlyFailed;
415
408
  /**
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Dialog Launcher
3
+ *
4
+ * Host-side half of the popup login flow. Dialog-mode `verify()` opens a
5
+ * TOP-LEVEL popup on the Identity origin **directly inside the triggering user
6
+ * gesture** and, on the host page, shades it with a small branded **bridge
7
+ * modal** ("continue in the secure window"). The popup (the `chrome: 'bare'`
8
+ * sign-in page) collects the identifier and runs the whole flow first-party, so
9
+ * login's `__Host-authsv_sso` cookie persists. Any `email`/`phone` passed to
10
+ * `verify()` is forwarded as a prefill.
11
+ *
12
+ * The popup must open synchronously in the gesture or the browser blocks it as
13
+ * programmatic. `verify()` reaches `start()` through microtask-only awaits (the
14
+ * redirect-result check does no I/O; the preloaded config resolves from cache),
15
+ * so transient activation survives.
16
+ *
17
+ * It is one dialog. The happy path is clean: logo, a subtle animation, and
18
+ * "continue in the secure window". A single warning appears under the logo only
19
+ * when the popup can't be confirmed: it was blocked, it closed, or it never
20
+ * posted a "ready" ping within `OPEN_TIMEOUT_MS` (so the open/load failed). Its
21
+ * "Try again" reopens the popup. The header's close ✕ (or backdrop/Escape)
22
+ * aborts and closes the popup.
23
+ */
24
+ import type { ResolvedConfig } from '../../config';
25
+ import type { VerifyOptions, VerifyResult } from './types';
26
+ import type { IdentityApi } from './api';
27
+ interface LauncherCallbacks {
28
+ onSuccess: (result: VerifyResult) => void;
29
+ onError: (error: Error) => void;
30
+ onCancel: () => void;
31
+ }
32
+ /**
33
+ * Opens the sign-in popup for dialog-mode `verify()` and bridges its result
34
+ * back, behind a single branded host-page modal.
35
+ */
36
+ export declare class DialogLauncher {
37
+ private readonly config;
38
+ private readonly api;
39
+ private readonly options;
40
+ private readonly callbacks;
41
+ private readonly trustedOrigin;
42
+ private readonly popupLauncher;
43
+ private modal;
44
+ private alertEl;
45
+ private popupWindow;
46
+ private openTimer;
47
+ private settled;
48
+ private generation;
49
+ constructor(config: ResolvedConfig, api: IdentityApi, options: VerifyOptions, callbacks: LauncherCallbacks);
50
+ /** Shade the host with the bridge and open the popup in the caller's gesture. */
51
+ start(): void;
52
+ /** Tear down the bridge modal and close any popup it opened. */
53
+ close(): void;
54
+ private openPopup;
55
+ private buildPopupUrl;
56
+ private handleResult;
57
+ private handleError;
58
+ /** Create the bridge modal (once) and render its single happy-path body. */
59
+ private showBridge;
60
+ private showAlert;
61
+ private hideAlert;
62
+ private scheduleOpenWarning;
63
+ private clearOpenTimer;
64
+ /** "Try again": close any current popup and reopen a fresh one. */
65
+ private retry;
66
+ /** Fetch branding once and drop the tenant logo into the modal header. */
67
+ private loadBranding;
68
+ private closePopup;
69
+ /** Explicit abort (close ✕, backdrop, Escape): close the popup and cancel. */
70
+ private abort;
71
+ private finish;
72
+ private finishCancel;
73
+ }
74
+ export {};
@@ -53,6 +53,7 @@ export declare class PasskeyHandler {
53
53
  * unrelated SparkVault subdomain (XSS or subdomain-takeover relay).
54
54
  */
55
55
  private readonly trustedOrigin;
56
+ private readonly popupLauncher;
56
57
  constructor(api: IdentityApi, state: VerificationState);
57
58
  /**
58
59
  * Resolve the current identifier (email or phone) to its SVID and report
@@ -92,16 +93,10 @@ export declare class PasskeyHandler {
92
93
  */
93
94
  private mapInlineCeremonyError;
94
95
  /**
95
- * Open passkey popup and wait for result
96
+ * Open passkey popup (top-level on the Identity origin, so WebAuthn runs
97
+ * same-origin with the RP id) and wait for its result.
96
98
  */
97
99
  private openPasskeyPopup;
98
- /**
99
- * Validate that a postMessage came from the identity service's own
100
- * origin. We do not accept the broader sparkvault.com family - a popup
101
- * is only opened against `this.baseUrl`, so any other origin is
102
- * either an unrelated tab or a forgery attempt.
103
- */
104
- private isValidMessageOrigin;
105
100
  /**
106
101
  * Handle popup error response
107
102
  */
@@ -19,7 +19,7 @@ export declare class IdentityModule {
19
19
  private readonly config;
20
20
  private readonly api;
21
21
  private renderer;
22
- private embedder;
22
+ private launcher;
23
23
  constructor(config: ResolvedConfig);
24
24
  /**
25
25
  * Build a deep link into the person's auth.sv Identity portal — where they
@@ -121,19 +121,18 @@ export declare class IdentityModule {
121
121
  /**
122
122
  * Close the identity dialog/inline UI if open.
123
123
  *
124
- * Tears down whichever surface is active: the hosted-widget iframe
125
- * (default dialog mode — also releases the embedder's host scroll lock)
126
- * or the local renderer (inline / local mode).
124
+ * Tears down whichever surface is active: the dialog launcher (default dialog
125
+ * mode) or the local renderer (inline / local mode).
127
126
  */
128
127
  close(): void;
129
128
  /**
130
129
  * Whether the preloaded config has already settled as a *permanent* failure
131
- * the hosted widget can't surface (origin not allowed, or product not
132
- * configured). Used to skip the iframe and show the error dialog in-page
133
- * immediately. Returns false — proceed to embed — when config is not
134
- * preloaded, still in flight (raced against a short timeout so the common
135
- * path is never delayed), resolved, or failed only transiently (so one-tap
136
- * passkey login via the frame is preserved).
130
+ * the popup can't surface (origin not allowed, or product not configured).
131
+ * Used to skip the launcher and show the error dialog in-page immediately.
132
+ * Returns false — proceed to the launcher — when config is not preloaded,
133
+ * still in flight (raced against a short timeout so the common path is never
134
+ * delayed), resolved, or failed only transiently (the launcher surfaces a
135
+ * transient failure in its own dialog).
137
136
  */
138
137
  private preloadedConfigPermanentlyFailed;
139
138
  /**
@@ -16,6 +16,11 @@ export interface InlineContainerOptions {
16
16
  showCloseButton?: boolean;
17
17
  /** Show footer with SparkVault branding */
18
18
  showFooter?: boolean;
19
+ /**
20
+ * Bare mode: drop the container's own surface (border, radius, background)
21
+ * so it flows transparently inside a host page that owns the chrome.
22
+ */
23
+ bare?: boolean;
19
24
  }
20
25
  export declare class InlineContainer implements Container {
21
26
  private readonly targetElement;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Popup Launcher
3
+ *
4
+ * Opens a top-level popup on the Identity origin and bridges its result back
5
+ * over postMessage. Used by both the passkey ceremony (which needs a popup so
6
+ * WebAuthn runs same-origin with the RP id) and the dialog login flow (which
7
+ * needs a top-level window on the IdP origin so login's first-party SSO cookie
8
+ * persists).
9
+ *
10
+ * The single transfer path: synchronous `window.open` inside the user gesture
11
+ * (so the browser never blocks it), strict `event.origin` + `data.type`
12
+ * validation against the caller-supplied trusted origin, a 60s timeout, and a
13
+ * `window.closed` poll that surfaces a manual close as a cancellation.
14
+ */
15
+ /** Minimal shape every popup result envelope shares. */
16
+ export interface PopupResultEnvelope {
17
+ type: string;
18
+ [key: string]: unknown;
19
+ }
20
+ export interface OpenPopupOptions {
21
+ /** URL the popup navigates to (already includes the encoded origin param). */
22
+ url: string;
23
+ /** `window.open` target name. */
24
+ windowName: string;
25
+ /** `data.type` the opener accepts; any other message is ignored. */
26
+ resultType: string;
27
+ /** Exact origin the popup must postMessage from; any other origin is ignored. */
28
+ trustedOrigin: string;
29
+ /** Popup width in px (default 480). */
30
+ width?: number;
31
+ /** Popup height in px (default 640). */
32
+ height?: number;
33
+ /** Timeout in ms before giving up and closing the popup (default 60000). */
34
+ timeoutMs?: number;
35
+ /**
36
+ * Called synchronously with the popup window the moment it opens, so the
37
+ * opener can close or refocus it (e.g. an abort/"try again" control on a host
38
+ * bridge modal). Not called when the popup is blocked.
39
+ */
40
+ onOpen?: (popup: Window) => void;
41
+ /**
42
+ * `data.type` of a non-terminal "I've loaded" ping the popup posts so the
43
+ * opener can confirm the window actually opened and reached the page (vs.
44
+ * silently failing). Distinct from `resultType`; receiving it does not settle.
45
+ */
46
+ readyType?: string;
47
+ /** Called when a `readyType` message arrives from the trusted origin. */
48
+ onReady?: () => void;
49
+ }
50
+ /**
51
+ * Open a popup and resolve with the first validated result envelope it posts.
52
+ *
53
+ * Resolves with the raw `event.data` (the caller inspects its `success`/`error`
54
+ * fields). Rejects with `PopupBlockedError` when the browser blocked the popup,
55
+ * `UserCancelledError` when the user closed it manually, and `TimeoutError`
56
+ * when no result arrived within the timeout.
57
+ */
58
+ export declare class PopupLauncher {
59
+ openPopup<TData extends PopupResultEnvelope = PopupResultEnvelope>(options: OpenPopupOptions): Promise<TData>;
60
+ }
@@ -17,6 +17,15 @@ export interface StyleOptions {
17
17
  * Inject modal styles into the document head.
18
18
  */
19
19
  export declare function injectStyles(options: StyleOptions): void;
20
- export declare function updateThemeVariables(_branding: SdkConfigBranding | undefined | null): void;
20
+ /**
21
+ * Re-theme the injected stylesheet when the resolved theme (light/dark) changes.
22
+ *
23
+ * Styles are first injected with default branding before config loads (so the
24
+ * UI paints instantly), then `updateBranding` calls this with the tenant's real
25
+ * `themeMode`. The theme is baked into the generated CSS (not runtime CSS
26
+ * variables), so a theme switch requires regenerating the stylesheet - a no-op
27
+ * when the theme is unchanged.
28
+ */
29
+ export declare function applyBrandingTheme(branding: SdkConfigBranding | undefined | null): void;
21
30
  export declare function removeStyles(): void;
22
31
  export declare function resolveTheme(branding: SdkConfigBranding | undefined | null): 'light' | 'dark';
@@ -34,29 +34,23 @@ export interface VerifyOptions {
34
34
  target?: string | HTMLElement;
35
35
  /** Override backdrop blur for this dialog (uses global config if omitted) */
36
36
  backdropBlur?: boolean;
37
- /** Auth context for OIDC/simple mode flows (used by hosted login) */
38
- authContext?: AuthContext;
39
- /**
40
- * Rendering strategy (internal).
41
- * - `'embed'` (default for dialog mode): inject a cross-origin iframe to the
42
- * SparkVault-hosted widget and bridge the result. Lets passkey login
43
- * complete in one tap with no popup.
44
- * - `'local'`: render the flow directly in this document. Used inside the
45
- * hosted widget itself, and forced for inline (`target`) rendering.
46
- */
47
- renderMode?: 'embed' | 'local';
48
37
  /**
49
- * Navigation override (internal). When the flow runs inside the embed
50
- * iframe, redirects (social, OIDC) are handed to the host's top window via
51
- * this hook instead of navigating the iframe. Omitted outside the iframe.
38
+ * Container chrome for inline (`target`) rendering. `'card'` (default) wraps
39
+ * the flow in a bordered, rounded surface with the SparkVault footer. `'bare'`
40
+ * drops the surface and footer so a host page (e.g. the SparkVault sign-in
41
+ * page) can supply its own full-window chrome — logo, background, footer.
42
+ * Ignored in dialog mode.
52
43
  */
53
- onNavigate?: (url: string) => void;
44
+ chrome?: 'card' | 'bare';
45
+ /** Auth context for OIDC/simple mode flows (used by hosted login) */
46
+ authContext?: AuthContext;
54
47
  /**
55
- * Social-login override (internal). When embedded, social must be started
56
- * from the host so its OAuth state and redirect_uri live on the customer's
57
- * top origin. The renderer hands the provider up instead of redirecting.
48
+ * Rendering strategy (internal). `'local'` renders the flow directly in this
49
+ * document — used inside the popup that runs the flow, and forced for inline
50
+ * (`target`) rendering. Dialog mode (omitted) renders a thin launcher and
51
+ * opens the popup.
58
52
  */
59
- onSocial?: (provider: string) => void;
53
+ renderMode?: 'local';
60
54
  /** Called when user cancels (if omitted, uses server-configured redirect) */
61
55
  onCancel?: () => void;
62
56
  /** Called when verification completes (if omitted, uses server-configured redirect) */
@@ -153,13 +147,6 @@ export interface TokenClaims {
153
147
  /** Authentication method used */
154
148
  method: string;
155
149
  }
156
- export interface EmbedMessage {
157
- type: 'sparkvault:identity:result' | 'sparkvault:identity:cancel' | 'sparkvault:identity:error' | 'sparkvault:identity:ready';
158
- payload?: VerifyResult | {
159
- error: string;
160
- code: string;
161
- };
162
- }
163
150
  export interface SdkConfigBranding {
164
151
  companyName: string;
165
152
  logoLight: string | null;