@sparkvault/sdk-js 2.0.4 → 2.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.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Widget Embedder
3
+ *
4
+ * Host-side half of the iframe architecture. For dialog (modal) verification,
5
+ * the SDK injects a borderless, transparent, full-viewport iframe pointing at
6
+ * the SparkVault-hosted widget page and bridges the result back over
7
+ * postMessage. Running the flow on the SparkVault origin lets passkey login
8
+ * complete in a single tap on every platform — the WebAuthn ceremony is
9
+ * same-origin with the RP id and the user's tap lives in the iframe document —
10
+ * without a popup.
11
+ *
12
+ * The widget renders the SDK's own modal (overlay, backdrop, chrome) inside the
13
+ * iframe, so the page sees only a transparent full-viewport frame: no border,
14
+ * no seam, visually identical to the in-page modal.
15
+ */
16
+ import type { ResolvedConfig } from '../config';
17
+ import type { VerifyOptions, VerifyResult } from './types';
18
+ interface EmbedderCallbacks {
19
+ onSuccess: (result: VerifyResult) => void;
20
+ onError: (error: Error) => void;
21
+ onCancel: () => void;
22
+ }
23
+ export declare class WidgetEmbedder {
24
+ private readonly config;
25
+ private readonly options;
26
+ private readonly callbacks;
27
+ private iframe;
28
+ private settled;
29
+ private previousBodyOverflow;
30
+ private readonly trustedOrigin;
31
+ private readonly boundHandleMessage;
32
+ constructor(config: ResolvedConfig, options: VerifyOptions, callbacks: EmbedderCallbacks);
33
+ start(): void;
34
+ close(): void;
35
+ private buildUrl;
36
+ private handleMessage;
37
+ }
38
+ export {};
@@ -60,9 +60,32 @@ export declare class PasskeyHandler {
60
60
  */
61
61
  register(registrationToken?: string): Promise<PasskeyResult>;
62
62
  /**
63
- * Verify user with existing passkey via popup
63
+ * Verify user with an existing passkey.
64
+ *
65
+ * On the Identity origin (the hosted widget / hosted login) the ceremony runs
66
+ * inline — same-origin with the RP id, one tap, no popup. On a third-party
67
+ * origin the rpId would not match the document, so it falls back to the popup
68
+ * served from the Identity origin. (Verification, unlike registration, is
69
+ * supported in cross-origin iframes, so the embedded widget uses the inline
70
+ * path.)
64
71
  */
65
72
  verify(): Promise<PasskeyResult>;
73
+ /**
74
+ * True when the SDK is running ON the Identity origin and the browser exposes
75
+ * WebAuthn — the only place an inline ceremony's rpId matches the document.
76
+ */
77
+ private canRunCeremonyInline;
78
+ /**
79
+ * Run the discoverable verification ceremony directly in this document and
80
+ * map the outcome onto the same PasskeyResult shape the popup produces.
81
+ */
82
+ private verifyInline;
83
+ /**
84
+ * Map a thrown inline-ceremony error onto PasskeyResult, mirroring the
85
+ * popup's error codes so the widget renders the same dedicated states
86
+ * (cancelled, identity locked, no passkey → registration).
87
+ */
88
+ private mapInlineCeremonyError;
66
89
  /**
67
90
  * Open passkey popup and wait for result
68
91
  */
@@ -19,6 +19,7 @@ export declare class IdentityModule {
19
19
  private readonly config;
20
20
  private readonly api;
21
21
  private renderer;
22
+ private embedder;
22
23
  private attachedElements;
23
24
  constructor(config: ResolvedConfig);
24
25
  /**
@@ -86,11 +86,29 @@ export declare class IdentityRenderer {
86
86
  private showMethodSelect;
87
87
  private handleIdentitySubmit;
88
88
  private getAllowedIdentityTypes;
89
+ /**
90
+ * @param userInitiated True when called from a live click on the picker, so
91
+ * a popup may be opened synchronously within that gesture. False when
92
+ * auto-selected after an async step (e.g. the single enabled method), where
93
+ * opening a popup would be blocked.
94
+ */
89
95
  private handleMethodSelect;
90
96
  private handleTotpSubmit;
91
97
  private handleSecondFactorSubmit;
92
98
  private handleTotpResend;
93
99
  private handlePasskeyStart;
100
+ /**
101
+ * Open the verify popup straight from a live picker gesture, showing a
102
+ * loading state while the ceremony runs. window.open inside verify() fires
103
+ * synchronously (before the first await), so it stays within the gesture.
104
+ */
105
+ private launchPasskeyVerify;
106
+ /**
107
+ * Apply a passkey ceremony result: complete on success, or route to the
108
+ * matching recovery state. Shared by the passkey view and the direct
109
+ * picker launch so both behave identically.
110
+ */
111
+ private applyPasskeyResult;
94
112
  /**
95
113
  * Handle fallback from passkey to an identifier-based code.
96
114
  * User clicked "Having trouble? Use a code instead".
@@ -36,6 +36,21 @@ export interface VerifyOptions {
36
36
  backdropBlur?: boolean;
37
37
  /** Auth context for OIDC/simple mode flows (used by hosted login) */
38
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
+ /**
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;
39
54
  /** Called when user cancels (if omitted, uses server-configured redirect) */
40
55
  onCancel?: () => void;
41
56
  /** Called when verification completes (if omitted, uses server-configured redirect) */
package/dist/index.d.ts CHANGED
@@ -101,6 +101,21 @@ interface VerifyOptions {
101
101
  backdropBlur?: boolean;
102
102
  /** Auth context for OIDC/simple mode flows (used by hosted login) */
103
103
  authContext?: AuthContext;
104
+ /**
105
+ * Rendering strategy (internal).
106
+ * - `'embed'` (default for dialog mode): inject a cross-origin iframe to the
107
+ * SparkVault-hosted widget and bridge the result. Lets passkey login
108
+ * complete in one tap with no popup.
109
+ * - `'local'`: render the flow directly in this document. Used inside the
110
+ * hosted widget itself, and forced for inline (`target`) rendering.
111
+ */
112
+ renderMode?: 'embed' | 'local';
113
+ /**
114
+ * Navigation override (internal). When the flow runs inside the embed
115
+ * iframe, redirects (social, OIDC) are handed to the host's top window via
116
+ * this hook instead of navigating the iframe. Omitted outside the iframe.
117
+ */
118
+ onNavigate?: (url: string) => void;
104
119
  /** Called when user cancels (if omitted, uses server-configured redirect) */
105
120
  onCancel?: () => void;
106
121
  /** Called when verification completes (if omitted, uses server-configured redirect) */
@@ -217,6 +232,7 @@ declare class IdentityModule {
217
232
  private readonly config;
218
233
  private readonly api;
219
234
  private renderer;
235
+ private embedder;
220
236
  private attachedElements;
221
237
  constructor(config: ResolvedConfig);
222
238
  /**