@sparkvault/sdk-js 8.0.1 → 8.1.0

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
@@ -111,26 +111,12 @@ interface VerifyOptions {
111
111
  /** Auth context for OIDC/simple mode flows (used by hosted login) */
112
112
  authContext?: AuthContext;
113
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.
114
+ * Rendering strategy (internal). `'local'` renders the flow directly in this
115
+ * document — used inside the popup that runs the flow, and forced for inline
116
+ * (`target`) rendering. Dialog mode (omitted) renders a thin launcher and
117
+ * opens the popup.
120
118
  */
121
- renderMode?: 'embed' | 'local';
122
- /**
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.
126
- */
127
- onNavigate?: (url: string) => void;
128
- /**
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.
132
- */
133
- onSocial?: (provider: string) => void;
119
+ renderMode?: 'local';
134
120
  /** Called when user cancels (if omitted, uses server-configured redirect) */
135
121
  onCancel?: () => void;
136
122
  /** Called when verification completes (if omitted, uses server-configured redirect) */
@@ -295,7 +281,7 @@ declare class IdentityModule {
295
281
  private readonly config;
296
282
  private readonly api;
297
283
  private renderer;
298
- private embedder;
284
+ private launcher;
299
285
  constructor(config: ResolvedConfig);
300
286
  /**
301
287
  * Build a deep link into the person's auth.sv Identity portal — where they
@@ -397,19 +383,18 @@ declare class IdentityModule {
397
383
  /**
398
384
  * Close the identity dialog/inline UI if open.
399
385
  *
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).
386
+ * Tears down whichever surface is active: the dialog launcher (default dialog
387
+ * mode) or the local renderer (inline / local mode).
403
388
  */
404
389
  close(): void;
405
390
  /**
406
391
  * 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).
392
+ * the popup can't surface (origin not allowed, or product not configured).
393
+ * Used to skip the launcher and show the error dialog in-page immediately.
394
+ * Returns false — proceed to the launcher — when config is not preloaded,
395
+ * still in flight (raced against a short timeout so the common path is never
396
+ * delayed), resolved, or failed only transiently (the launcher surfaces a
397
+ * transient failure in its own dialog).
413
398
  */
414
399
  private preloadedConfigPermanentlyFailed;
415
400
  /**
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Dialog Launcher
3
+ *
4
+ * Host-side half of the popup login flow. Dialog (modal) verification renders a
5
+ * thin email/phone launcher in the SDK's own ModalContainer, then — inside the
6
+ * user's submit gesture — opens a TOP-LEVEL popup on the Identity origin that
7
+ * runs the full login flow. Because the popup is top-level on api.sparkvault.com,
8
+ * login completion's first-party `__Host-authsv_sso` cookie persists.
9
+ *
10
+ * The launcher only collects an identifier and bridges the popup result back;
11
+ * the flow UI itself lives in the popup (the renderMode:'local' renderer).
12
+ */
13
+ import type { ResolvedConfig } from '../../config';
14
+ import type { VerifyOptions, VerifyResult } from './types';
15
+ import { IdentityApi } from './api';
16
+ interface LauncherCallbacks {
17
+ onSuccess: (result: VerifyResult) => void;
18
+ onError: (error: Error) => void;
19
+ onCancel: () => void;
20
+ }
21
+ /**
22
+ * Renders the email/phone launcher modal and opens the login popup on submit.
23
+ */
24
+ export declare class DialogLauncher {
25
+ private readonly config;
26
+ private readonly api;
27
+ private readonly options;
28
+ private readonly callbacks;
29
+ private readonly trustedOrigin;
30
+ private readonly modal;
31
+ private readonly popupLauncher;
32
+ private currentView;
33
+ private settled;
34
+ private allowedTypes;
35
+ constructor(config: ResolvedConfig, api: IdentityApi, options: VerifyOptions, callbacks: LauncherCallbacks);
36
+ /**
37
+ * Mount the modal, then load config to render the identifier input (or a
38
+ * terminal error view when config fails).
39
+ */
40
+ start(): void;
41
+ /**
42
+ * Close the launcher and tear everything down. Cancels in-flight config
43
+ * requests so a late resolution can't render into a destroyed modal.
44
+ */
45
+ close(): void;
46
+ private handleClose;
47
+ private renderInput;
48
+ /**
49
+ * Render the identifier input. The submit handler runs synchronously inside
50
+ * the user gesture, so the popup open is never treated as programmatic (and
51
+ * never blocked).
52
+ */
53
+ private mountInput;
54
+ /**
55
+ * Open the login popup for the submitted identifier. SYNCHRONOUS: no await
56
+ * precedes window.open, so the browser keeps the user-gesture grant.
57
+ */
58
+ private handleIdentitySubmit;
59
+ private buildPopupUrl;
60
+ private handlePopupResult;
61
+ private handlePopupError;
62
+ /**
63
+ * Re-render the input (its Continue button is disabled to "Please wait…" on
64
+ * submit) so it is interactive again after a cancelled or blocked popup.
65
+ */
66
+ private reEnableInput;
67
+ private renderConfigError;
68
+ private viewForConfigError;
69
+ private retryConfig;
70
+ private mountView;
71
+ private finish;
72
+ }
73
+ 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
  /**
@@ -0,0 +1,46 @@
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
+ /**
37
+ * Open a popup and resolve with the first validated result envelope it posts.
38
+ *
39
+ * Resolves with the raw `event.data` (the caller inspects its `success`/`error`
40
+ * fields). Rejects with `PopupBlockedError` when the browser blocked the popup,
41
+ * `UserCancelledError` when the user closed it manually, and `TimeoutError`
42
+ * when no result arrived within the timeout.
43
+ */
44
+ export declare class PopupLauncher {
45
+ openPopup<TData extends PopupResultEnvelope = PopupResultEnvelope>(options: OpenPopupOptions): Promise<TData>;
46
+ }
@@ -37,26 +37,12 @@ export interface VerifyOptions {
37
37
  /** Auth context for OIDC/simple mode flows (used by hosted login) */
38
38
  authContext?: AuthContext;
39
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.
40
+ * Rendering strategy (internal). `'local'` renders the flow directly in this
41
+ * document — used inside the popup that runs the flow, and forced for inline
42
+ * (`target`) rendering. Dialog mode (omitted) renders a thin launcher and
43
+ * opens the popup.
46
44
  */
47
- renderMode?: 'embed' | 'local';
48
- /**
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.
52
- */
53
- onNavigate?: (url: string) => void;
54
- /**
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.
58
- */
59
- onSocial?: (provider: string) => void;
45
+ renderMode?: 'local';
60
46
  /** Called when user cancels (if omitted, uses server-configured redirect) */
61
47
  onCancel?: () => void;
62
48
  /** Called when verification completes (if omitted, uses server-configured redirect) */
@@ -153,13 +139,6 @@ export interface TokenClaims {
153
139
  /** Authentication method used */
154
140
  method: string;
155
141
  }
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
142
  export interface SdkConfigBranding {
164
143
  companyName: string;
165
144
  logoLight: string | null;