@sparkvault/sdk-js 8.0.0 → 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/README.md +8 -8
- package/dist/index.d.ts +17 -32
- package/dist/products/identity/api.d.ts +7 -7
- package/dist/products/identity/dialog-launcher.d.ts +73 -0
- package/dist/products/identity/handlers/index.d.ts +1 -1
- package/dist/products/identity/handlers/{totp-handler.d.ts → otp-handler.d.ts} +15 -15
- package/dist/products/identity/handlers/passkey-handler.d.ts +3 -8
- package/dist/products/identity/index.d.ts +10 -11
- package/dist/products/identity/popup-launcher.d.ts +46 -0
- package/dist/products/identity/renderer.d.ts +5 -5
- package/dist/products/identity/state.d.ts +8 -8
- package/dist/products/identity/types.d.ts +11 -32
- package/dist/products/identity/views/base.d.ts +2 -2
- package/dist/products/identity/views/index.d.ts +1 -1
- package/dist/products/identity/views/{totp-verify.d.ts → otp-verify.d.ts} +5 -5
- package/dist/products/index.d.ts +1 -1
- package/dist/sparkvault.cjs.js +438 -513
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +438 -513
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +2 -2
- package/dist/products/identity/embedder.d.ts +0 -83
package/README.md
CHANGED
|
@@ -45,9 +45,9 @@ yarn add @sparkvault/sdk-js
|
|
|
45
45
|
|
|
46
46
|
The CDN serves the browser bundle in two tiers:
|
|
47
47
|
|
|
48
|
-
| URL |
|
|
49
|
-
|
|
50
|
-
| `sdk/v1/sparkvault.js` |
|
|
48
|
+
| URL | Effective cache | Use when |
|
|
49
|
+
|-----|-----------------|----------|
|
|
50
|
+
| `sdk/v1/sparkvault.js` | Short-lived (Cloudflare edge TTL, ~4h) — bust with `?v=<version>` for immediate freshness | Default. Auto-updates each release; the `?v=<version>` query gives you the new build immediately. |
|
|
51
51
|
| `sdk/v1/sparkvault.<hash>.js` | `immutable`, 1 year | You want a reproducible, forever-cached, integrity-pinned build. |
|
|
52
52
|
|
|
53
53
|
`sdk/v1/version.json` advertises the current immutable URL, its hash, and a
|
|
@@ -289,9 +289,9 @@ Authentication methods are configured in your Identity Product settings. The SDK
|
|
|
289
289
|
| Method | Description | Identity Type |
|
|
290
290
|
|--------|-------------|---------------|
|
|
291
291
|
| `passkey` | WebAuthn/FIDO2 biometric or security key | Email |
|
|
292
|
-
| `
|
|
293
|
-
| `
|
|
294
|
-
| `
|
|
292
|
+
| `otp_email` | 6-digit code sent via email | Email |
|
|
293
|
+
| `otp_sms` | 6-digit code sent via SMS | Phone |
|
|
294
|
+
| `otp_voice` | 6-digit code sent via voice call | Phone |
|
|
295
295
|
| `sparklink` | One-click sign-in link via email | Email |
|
|
296
296
|
| `social_google` | Sign in with Google | Social account |
|
|
297
297
|
| `social_apple` | Sign in with Apple | Social account |
|
|
@@ -514,7 +514,7 @@ When decoded, the JWT token contains these claims:
|
|
|
514
514
|
"token_version": 0,
|
|
515
515
|
"identity": "user@example.com",
|
|
516
516
|
"identity_type": "email",
|
|
517
|
-
"method": "
|
|
517
|
+
"method": "otp_email",
|
|
518
518
|
"verified_at": 1703977195,
|
|
519
519
|
"iat": 1703977200,
|
|
520
520
|
"exp": 1703980800,
|
|
@@ -532,7 +532,7 @@ When decoded, the JWT token contains these claims:
|
|
|
532
532
|
| `token_version` | `number` | Managed-session version used for revocation/introspection |
|
|
533
533
|
| `identity` | `string` | The verified email address or phone number |
|
|
534
534
|
| `identity_type` | `string` | `"email"` or `"phone"` |
|
|
535
|
-
| `method` | `string` | Authentication method used (e.g., `"
|
|
535
|
+
| `method` | `string` | Authentication method used (e.g., `"otp_email"`, `"passkey"`) |
|
|
536
536
|
| `verified_at` | `number` | Unix timestamp when identity was verified |
|
|
537
537
|
| `iat` | `number` | Issued at timestamp |
|
|
538
538
|
| `exp` | `number` | Expiration timestamp |
|
package/dist/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ declare class HealthModule {
|
|
|
75
75
|
/**
|
|
76
76
|
* Identity Module Types
|
|
77
77
|
*/
|
|
78
|
-
type AuthMethod = 'passkey' | '
|
|
78
|
+
type AuthMethod = 'passkey' | 'otp_email' | 'otp_sms' | 'otp_voice' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
|
|
79
79
|
type Theme = 'light' | 'dark';
|
|
80
80
|
type VerifiedIdentityType = 'email' | 'phone' | 'social';
|
|
81
81
|
/**
|
|
@@ -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
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
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?: '
|
|
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) */
|
|
@@ -279,7 +265,7 @@ declare class PopupBlockedError extends SparkVaultError {
|
|
|
279
265
|
* Identity Module
|
|
280
266
|
*
|
|
281
267
|
* Provides identity verification through dialog or inline UI.
|
|
282
|
-
* Supports passkey,
|
|
268
|
+
* Supports passkey, OTP, SparkLink, and social authentication.
|
|
283
269
|
*
|
|
284
270
|
* @example Dialog mode (immediate)
|
|
285
271
|
* const result = await sv.products.identity.verify();
|
|
@@ -295,7 +281,7 @@ declare class IdentityModule {
|
|
|
295
281
|
private readonly config;
|
|
296
282
|
private readonly api;
|
|
297
283
|
private renderer;
|
|
298
|
-
private
|
|
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
|
|
401
|
-
*
|
|
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
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
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
|
/**
|
|
@@ -439,7 +424,7 @@ declare class IdentityModule {
|
|
|
439
424
|
*/
|
|
440
425
|
|
|
441
426
|
declare class ProductsModule {
|
|
442
|
-
/** Identity verification product (passkey,
|
|
427
|
+
/** Identity verification product (passkey, OTP, SparkLink, social). */
|
|
443
428
|
readonly identity: IdentityModule;
|
|
444
429
|
constructor(config: ResolvedConfig);
|
|
445
430
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import type { ResolvedConfig } from '../../config';
|
|
8
8
|
import { SparkVaultApi } from '../../api-base';
|
|
9
9
|
import { SparkVaultError } from '../../errors';
|
|
10
|
-
import type { SdkConfig,
|
|
10
|
+
import type { SdkConfig, OtpSendResponse, OtpVerifyResponse, PasskeyChallengeResponse, PasskeyVerifyResponse, SecondFactorVerifyResponse, SparkLinkSendResponse, BackupSendResponse, BackupVerifyResponse, Recommendation, RecommendationKey, AuthContext, VerifyResult } from './types';
|
|
11
11
|
export declare class IdentityApi extends SparkVaultApi {
|
|
12
12
|
private readonly config;
|
|
13
13
|
/** Cached config promise - allows preloading and deduplication */
|
|
@@ -53,22 +53,22 @@ export declare class IdentityApi extends SparkVaultApi {
|
|
|
53
53
|
*/
|
|
54
54
|
private buildAuthContextParams;
|
|
55
55
|
/**
|
|
56
|
-
* Send
|
|
56
|
+
* Send OTP code to email or phone
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
sendOtp(params: {
|
|
59
59
|
recipient: string;
|
|
60
60
|
method: 'email' | 'sms' | 'voice';
|
|
61
61
|
authContext?: AuthContext;
|
|
62
|
-
}): Promise<
|
|
62
|
+
}): Promise<OtpSendResponse>;
|
|
63
63
|
/**
|
|
64
|
-
* Verify
|
|
64
|
+
* Verify OTP code
|
|
65
65
|
*/
|
|
66
|
-
|
|
66
|
+
verifyOtp(params: {
|
|
67
67
|
kindling: string;
|
|
68
68
|
pin: string;
|
|
69
69
|
recipient: string;
|
|
70
70
|
authContext?: AuthContext;
|
|
71
|
-
}): Promise<
|
|
71
|
+
}): Promise<OtpVerifyResponse>;
|
|
72
72
|
/**
|
|
73
73
|
* Submit a second factor (authenticator-app code or recovery code) to finish
|
|
74
74
|
* a login that the primary factor left in a `second_factor_required` state.
|
|
@@ -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 {};
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* Each handler has a single responsibility.
|
|
6
6
|
*/
|
|
7
7
|
export { PasskeyHandler, type PasskeyResult, type PasskeyCheckResult } from './passkey-handler';
|
|
8
|
-
export {
|
|
8
|
+
export { OtpHandler, type OtpSendResult, type OtpVerifyResult } from './otp-handler';
|
|
9
9
|
export { SparkLinkHandler, type SparkLinkSendResult } from './sparklink-handler';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* OTP Handler
|
|
3
3
|
*
|
|
4
|
-
* Single responsibility:
|
|
5
|
-
* Extracts
|
|
4
|
+
* Single responsibility: OTP code sending and verification.
|
|
5
|
+
* Extracts OTP logic from IdentityRenderer for better separation of concerns.
|
|
6
6
|
*/
|
|
7
7
|
import { type IdentityApi } from '../api';
|
|
8
8
|
import type { VerifyResult } from '../types';
|
|
9
9
|
import type { VerificationState } from '../state';
|
|
10
10
|
/**
|
|
11
|
-
* Result of
|
|
11
|
+
* Result of OTP send operation
|
|
12
12
|
*/
|
|
13
|
-
export interface
|
|
13
|
+
export interface OtpSendResult {
|
|
14
14
|
success: boolean;
|
|
15
15
|
kindling?: string;
|
|
16
16
|
expiresAt?: number;
|
|
@@ -24,9 +24,9 @@ export interface TotpSendResult {
|
|
|
24
24
|
errorCode?: string;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Result of
|
|
27
|
+
* Result of OTP verify operation
|
|
28
28
|
*/
|
|
29
|
-
export interface
|
|
29
|
+
export interface OtpVerifyResult {
|
|
30
30
|
success: boolean;
|
|
31
31
|
result?: VerifyResult;
|
|
32
32
|
/** New kindling if verification failed (for retry) */
|
|
@@ -48,22 +48,22 @@ export interface TotpVerifyResult {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
* Handles
|
|
51
|
+
* Handles OTP code sending and verification
|
|
52
52
|
*/
|
|
53
|
-
export declare class
|
|
53
|
+
export declare class OtpHandler {
|
|
54
54
|
private readonly api;
|
|
55
55
|
private readonly state;
|
|
56
56
|
constructor(api: IdentityApi, state: VerificationState);
|
|
57
57
|
/**
|
|
58
|
-
* Send
|
|
58
|
+
* Send OTP code via email, SMS, or voice
|
|
59
59
|
*/
|
|
60
|
-
send(method: 'email' | 'sms' | 'voice'): Promise<
|
|
60
|
+
send(method: 'email' | 'sms' | 'voice'): Promise<OtpSendResult>;
|
|
61
61
|
/**
|
|
62
|
-
* Resend
|
|
62
|
+
* Resend OTP code
|
|
63
63
|
*/
|
|
64
|
-
resend(): Promise<
|
|
64
|
+
resend(): Promise<OtpSendResult>;
|
|
65
65
|
/**
|
|
66
|
-
* Verify
|
|
66
|
+
* Verify OTP code
|
|
67
67
|
*/
|
|
68
|
-
verify(code: string): Promise<
|
|
68
|
+
verify(code: string): Promise<OtpVerifyResult>;
|
|
69
69
|
}
|
|
@@ -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
|
|
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
|
*/
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Identity Module
|
|
3
3
|
*
|
|
4
4
|
* Provides identity verification through dialog or inline UI.
|
|
5
|
-
* Supports passkey,
|
|
5
|
+
* Supports passkey, OTP, SparkLink, and social authentication.
|
|
6
6
|
*
|
|
7
7
|
* @example Dialog mode (immediate)
|
|
8
8
|
* const result = await sv.products.identity.verify();
|
|
@@ -19,7 +19,7 @@ export declare class IdentityModule {
|
|
|
19
19
|
private readonly config;
|
|
20
20
|
private readonly api;
|
|
21
21
|
private renderer;
|
|
22
|
-
private
|
|
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
|
|
125
|
-
*
|
|
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
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
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
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Identity View Renderer
|
|
3
3
|
*
|
|
4
4
|
* Orchestrates view state and rendering for identity verification flows.
|
|
5
|
-
* Uses extracted handlers for
|
|
5
|
+
* Uses extracted handlers for OTP and Passkey operations.
|
|
6
6
|
*/
|
|
7
7
|
import type { VerifyOptions, VerifyResult } from './types';
|
|
8
8
|
import { IdentityApi } from './api';
|
|
@@ -19,7 +19,7 @@ export declare class IdentityRenderer {
|
|
|
19
19
|
private readonly callbacks;
|
|
20
20
|
private readonly verificationState;
|
|
21
21
|
private readonly passkeyHandler;
|
|
22
|
-
private readonly
|
|
22
|
+
private readonly otpHandler;
|
|
23
23
|
private readonly sparkLinkHandler;
|
|
24
24
|
private currentView;
|
|
25
25
|
private focusTimeoutId;
|
|
@@ -121,9 +121,9 @@ export declare class IdentityRenderer {
|
|
|
121
121
|
* any other code so the caller falls through to its normal handling.
|
|
122
122
|
*/
|
|
123
123
|
private renderBlockedInterstitial;
|
|
124
|
-
private
|
|
124
|
+
private handleOtpSubmit;
|
|
125
125
|
private handleSecondFactorSubmit;
|
|
126
|
-
private
|
|
126
|
+
private handleOtpResend;
|
|
127
127
|
private handlePasskeyStart;
|
|
128
128
|
/**
|
|
129
129
|
* Open the verify popup straight from a live picker gesture, showing a
|
|
@@ -267,7 +267,7 @@ export declare class IdentityRenderer {
|
|
|
267
267
|
*/
|
|
268
268
|
private handleSparkLinkResend;
|
|
269
269
|
/**
|
|
270
|
-
* Handle fallback from SparkLink to
|
|
270
|
+
* Handle fallback from SparkLink to OTP verification code.
|
|
271
271
|
*/
|
|
272
272
|
private handleSparkLinkFallback;
|
|
273
273
|
}
|
|
@@ -16,16 +16,16 @@ interface PasskeyState {
|
|
|
16
16
|
hasPasskey: boolean | null;
|
|
17
17
|
/** Whether user fell back from passkey to another method */
|
|
18
18
|
isFallbackMode: boolean;
|
|
19
|
-
/** Pending result when prompting for passkey registration after
|
|
19
|
+
/** Pending result when prompting for passkey registration after OTP */
|
|
20
20
|
pendingResult: VerifyResult | null;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* OTP-specific state
|
|
24
24
|
*/
|
|
25
|
-
interface
|
|
26
|
-
/** Current kindling token for
|
|
25
|
+
interface OtpState {
|
|
26
|
+
/** Current kindling token for OTP verification */
|
|
27
27
|
kindling: string;
|
|
28
|
-
/** Current
|
|
28
|
+
/** Current OTP method (email, sms, or voice) */
|
|
29
29
|
method: 'email' | 'sms' | 'voice' | null;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
@@ -38,7 +38,7 @@ export declare class VerificationState {
|
|
|
38
38
|
private _identityType;
|
|
39
39
|
private _authContext;
|
|
40
40
|
private readonly _passkey;
|
|
41
|
-
private readonly
|
|
41
|
+
private readonly _otp;
|
|
42
42
|
get sdkConfig(): SdkConfig | null;
|
|
43
43
|
setConfig(config: SdkConfig): void;
|
|
44
44
|
get accountId(): string;
|
|
@@ -54,8 +54,8 @@ export declare class VerificationState {
|
|
|
54
54
|
setPasskeyStatus(hasPasskey: boolean | null): void;
|
|
55
55
|
enablePasskeyFallback(): void;
|
|
56
56
|
setPendingResult(result: VerifyResult | null): void;
|
|
57
|
-
get
|
|
57
|
+
get otp(): Readonly<OtpState>;
|
|
58
58
|
setKindling(kindling: string): void;
|
|
59
|
-
|
|
59
|
+
setOtpMethod(method: 'email' | 'sms' | 'voice'): void;
|
|
60
60
|
}
|
|
61
61
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Identity Module Types
|
|
3
3
|
*/
|
|
4
|
-
export type AuthMethod = 'passkey' | '
|
|
4
|
+
export type AuthMethod = 'passkey' | 'otp_email' | 'otp_sms' | 'otp_voice' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
|
|
5
5
|
export type Theme = 'light' | 'dark';
|
|
6
6
|
export type VerifiedIdentityType = 'email' | 'phone' | 'social';
|
|
7
7
|
/**
|
|
@@ -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
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
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?: '
|
|
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;
|
|
@@ -170,7 +149,7 @@ export interface SdkConfigBranding {
|
|
|
170
149
|
themeMode?: 'light' | 'dark';
|
|
171
150
|
}
|
|
172
151
|
/** Method ID returned by config endpoint */
|
|
173
|
-
export type MethodId = '
|
|
152
|
+
export type MethodId = 'otp_email' | 'otp_sms' | 'otp_voice' | 'passkey' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
|
|
174
153
|
export interface SdkConfig {
|
|
175
154
|
accountId: string;
|
|
176
155
|
/** Branding configuration (optional in v1 - uses defaults if not provided) */
|
|
@@ -191,7 +170,7 @@ export interface SdkConfig {
|
|
|
191
170
|
/** Method metadata for SDK rendering (static lookup) */
|
|
192
171
|
export interface MethodMetadata {
|
|
193
172
|
id: MethodId;
|
|
194
|
-
type: '
|
|
173
|
+
type: 'otp' | 'passkey' | 'sparklink' | 'social';
|
|
195
174
|
/** Which identifier type this method requires. Passkeys are SVID-scoped and do not require one. */
|
|
196
175
|
identityType?: 'email' | 'phone';
|
|
197
176
|
name: string;
|
|
@@ -200,13 +179,13 @@ export interface MethodMetadata {
|
|
|
200
179
|
/** Provider name for social methods */
|
|
201
180
|
provider?: string;
|
|
202
181
|
}
|
|
203
|
-
export interface
|
|
182
|
+
export interface OtpSendResponse {
|
|
204
183
|
success: boolean;
|
|
205
184
|
kindling: string;
|
|
206
185
|
expires_at: number;
|
|
207
186
|
method: string;
|
|
208
187
|
}
|
|
209
|
-
export interface
|
|
188
|
+
export interface OtpVerifyResponse {
|
|
210
189
|
verified: boolean;
|
|
211
190
|
token?: string;
|
|
212
191
|
/** Identity (email or phone) - returned on success */
|
|
@@ -324,7 +303,7 @@ export type IdentityViewState = {
|
|
|
324
303
|
email: string;
|
|
325
304
|
methods: MethodMetadata[];
|
|
326
305
|
} | {
|
|
327
|
-
view: '
|
|
306
|
+
view: 'otp-verify';
|
|
328
307
|
email: string;
|
|
329
308
|
method: 'email' | 'sms' | 'voice';
|
|
330
309
|
kindling: string;
|
|
@@ -52,10 +52,10 @@ export declare function formatPhoneDisplay(phone: string): string;
|
|
|
52
52
|
*/
|
|
53
53
|
export declare function looksLikePhone(input: string): boolean;
|
|
54
54
|
/**
|
|
55
|
-
* Validate
|
|
55
|
+
* Validate OTP code format.
|
|
56
56
|
* Returns sanitized code or null if invalid.
|
|
57
57
|
*/
|
|
58
|
-
export declare function
|
|
58
|
+
export declare function validateOtpCode(code: string): string | null;
|
|
59
59
|
/**
|
|
60
60
|
* Re-export escapeHtml for convenience.
|
|
61
61
|
*/
|
|
@@ -7,7 +7,7 @@ export * from './base';
|
|
|
7
7
|
export * from './loading';
|
|
8
8
|
export * from './identity-input';
|
|
9
9
|
export * from './method-select';
|
|
10
|
-
export * from './
|
|
10
|
+
export * from './otp-verify';
|
|
11
11
|
export * from './two-factor';
|
|
12
12
|
export * from './passkey';
|
|
13
13
|
export * from './passkey-prompt';
|