@sparkvault/sdk-js 1.24.4
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 +769 -0
- package/dist/api-base.d.ts +58 -0
- package/dist/auto-init.d.ts +32 -0
- package/dist/config.d.ts +41 -0
- package/dist/errors.d.ts +30 -0
- package/dist/health.d.ts +18 -0
- package/dist/http.d.ts +51 -0
- package/dist/identity/api.d.ts +110 -0
- package/dist/identity/container.d.ts +56 -0
- package/dist/identity/handlers/index.d.ts +9 -0
- package/dist/identity/handlers/passkey-handler.d.ts +69 -0
- package/dist/identity/handlers/sparklink-handler.d.ts +30 -0
- package/dist/identity/handlers/totp-handler.d.ts +52 -0
- package/dist/identity/index.d.ts +89 -0
- package/dist/identity/inline-container.d.ts +65 -0
- package/dist/identity/methods.d.ts +23 -0
- package/dist/identity/modal.d.ts +82 -0
- package/dist/identity/renderer.d.ts +146 -0
- package/dist/identity/state.d.ts +98 -0
- package/dist/identity/styles.d.ts +22 -0
- package/dist/identity/types.d.ts +221 -0
- package/dist/identity/utils/cooldown-timer.d.ts +73 -0
- package/dist/identity/utils/index.d.ts +5 -0
- package/dist/identity/utils.d.ts +39 -0
- package/dist/identity/views/app-not-activated.d.ts +21 -0
- package/dist/identity/views/base.d.ts +62 -0
- package/dist/identity/views/error.d.ts +25 -0
- package/dist/identity/views/icons.d.ts +38 -0
- package/dist/identity/views/identity-input.d.ts +48 -0
- package/dist/identity/views/index.d.ts +16 -0
- package/dist/identity/views/loading.d.ts +15 -0
- package/dist/identity/views/method-select.d.ts +29 -0
- package/dist/identity/views/passkey-prompt.d.ts +24 -0
- package/dist/identity/views/passkey.d.ts +38 -0
- package/dist/identity/views/service-unavailable.d.ts +21 -0
- package/dist/identity/views/sparklink-waiting.d.ts +40 -0
- package/dist/identity/views/totp-verify.d.ts +58 -0
- package/dist/index.d.ts +733 -0
- package/dist/logger.d.ts +45 -0
- package/dist/rng/index.d.ts +54 -0
- package/dist/rng/types.d.ts +26 -0
- package/dist/sparks/index.d.ts +37 -0
- package/dist/sparks/types.d.ts +56 -0
- package/dist/sparkvault.cjs.js +10167 -0
- package/dist/sparkvault.cjs.js.map +1 -0
- package/dist/sparkvault.esm.js +10152 -0
- package/dist/sparkvault.esm.js.map +1 -0
- package/dist/sparkvault.js +2 -0
- package/dist/sparkvault.js.map +1 -0
- package/dist/utils/base64url.d.ts +41 -0
- package/dist/utils/dom.d.ts +17 -0
- package/dist/utils/retry.d.ts +32 -0
- package/dist/vaults/index.d.ts +109 -0
- package/dist/vaults/types.d.ts +128 -0
- package/dist/vaults/upload/api.d.ts +36 -0
- package/dist/vaults/upload/container.d.ts +57 -0
- package/dist/vaults/upload/index.d.ts +75 -0
- package/dist/vaults/upload/inline-container.d.ts +75 -0
- package/dist/vaults/upload/modal.d.ts +79 -0
- package/dist/vaults/upload/renderer.d.ts +70 -0
- package/dist/vaults/upload/styles.d.ts +20 -0
- package/dist/vaults/upload/types.d.ts +182 -0
- package/package.json +63 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline Container
|
|
3
|
+
*
|
|
4
|
+
* Renders identity verification UI inline within a target element.
|
|
5
|
+
* Unlike ModalContainer which creates an overlay popup, this embeds
|
|
6
|
+
* directly into the customer's page/dialog where render() was called.
|
|
7
|
+
*
|
|
8
|
+
* Implements the Container interface for use with IdentityRenderer.
|
|
9
|
+
*/
|
|
10
|
+
import type { Container } from './container';
|
|
11
|
+
import type { SdkConfigBranding } from './types';
|
|
12
|
+
export interface InlineContainerOptions {
|
|
13
|
+
/** Show header with branding and optional close button */
|
|
14
|
+
showHeader?: boolean;
|
|
15
|
+
/** Show close button in header (requires showHeader) */
|
|
16
|
+
showCloseButton?: boolean;
|
|
17
|
+
/** Show footer with SparkVault branding */
|
|
18
|
+
showFooter?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class InlineContainer implements Container {
|
|
21
|
+
private readonly targetElement;
|
|
22
|
+
private readonly containerOptions;
|
|
23
|
+
private container;
|
|
24
|
+
private header;
|
|
25
|
+
private body;
|
|
26
|
+
private footer;
|
|
27
|
+
private closeBtn;
|
|
28
|
+
private onCloseCallback;
|
|
29
|
+
private closeBtnClickHandler;
|
|
30
|
+
private effectiveTheme;
|
|
31
|
+
constructor(targetElement: HTMLElement, options?: InlineContainerOptions);
|
|
32
|
+
/**
|
|
33
|
+
* Create the inline container with loading state.
|
|
34
|
+
*/
|
|
35
|
+
createLoading(_options: {
|
|
36
|
+
backdropBlur?: boolean;
|
|
37
|
+
}, onClose: () => void): void;
|
|
38
|
+
/**
|
|
39
|
+
* Update branding after SDK config loads.
|
|
40
|
+
*/
|
|
41
|
+
updateBranding(branding: SdkConfigBranding): void;
|
|
42
|
+
/**
|
|
43
|
+
* Update backdrop blur setting (no-op for inline container).
|
|
44
|
+
*/
|
|
45
|
+
updateBackdropBlur(_enabled: boolean): void;
|
|
46
|
+
/**
|
|
47
|
+
* Minimal-chrome toggle (no-op for inline container).
|
|
48
|
+
* Inline containers don't own page-level chrome to hide.
|
|
49
|
+
*/
|
|
50
|
+
setMinimalChrome(_enabled: boolean): void;
|
|
51
|
+
/**
|
|
52
|
+
* Get the body element for content rendering.
|
|
53
|
+
*/
|
|
54
|
+
getBody(): HTMLDivElement | null;
|
|
55
|
+
/**
|
|
56
|
+
* Check if the container is currently active.
|
|
57
|
+
*/
|
|
58
|
+
isOpen(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Destroy the container and clean up.
|
|
61
|
+
*/
|
|
62
|
+
destroy(): void;
|
|
63
|
+
private createHeader;
|
|
64
|
+
private handleClose;
|
|
65
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method Registry
|
|
3
|
+
*
|
|
4
|
+
* Static metadata for all authentication methods.
|
|
5
|
+
* API returns method IDs; SDK enriches with this metadata for rendering.
|
|
6
|
+
*/
|
|
7
|
+
import type { MethodId, MethodMetadata } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* Static method metadata registry
|
|
10
|
+
*/
|
|
11
|
+
export declare const METHOD_REGISTRY: Record<MethodId, MethodMetadata>;
|
|
12
|
+
/**
|
|
13
|
+
* Get method metadata by ID
|
|
14
|
+
* @param id - Method ID from config
|
|
15
|
+
* @returns Method metadata or undefined if not found
|
|
16
|
+
*/
|
|
17
|
+
export declare function getMethodMetadata(id: MethodId): MethodMetadata | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Enrich method IDs with full metadata
|
|
20
|
+
* @param ids - Array of method IDs from config
|
|
21
|
+
* @returns Array of method metadata objects
|
|
22
|
+
*/
|
|
23
|
+
export declare function enrichMethods(ids: MethodId[]): MethodMetadata[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity Modal Container
|
|
3
|
+
*
|
|
4
|
+
* Single responsibility: DOM modal container lifecycle.
|
|
5
|
+
* Creates, shows, hides, and destroys the modal overlay and container.
|
|
6
|
+
* Does NOT handle content rendering - that's the Renderer's job.
|
|
7
|
+
*/
|
|
8
|
+
import type { SdkConfigBranding } from './types';
|
|
9
|
+
import type { Container } from './container';
|
|
10
|
+
export interface ModalOptions {
|
|
11
|
+
branding: SdkConfigBranding;
|
|
12
|
+
/** Enable backdrop blur (default: true) */
|
|
13
|
+
backdropBlur?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface ModalContainerElements {
|
|
16
|
+
overlay: HTMLDivElement;
|
|
17
|
+
modal: HTMLDivElement;
|
|
18
|
+
header: HTMLDivElement;
|
|
19
|
+
body: HTMLDivElement;
|
|
20
|
+
footer: HTMLDivElement;
|
|
21
|
+
}
|
|
22
|
+
export declare class ModalContainer implements Container {
|
|
23
|
+
private elements;
|
|
24
|
+
private onCloseCallback;
|
|
25
|
+
private keydownHandler;
|
|
26
|
+
private overlayClickHandler;
|
|
27
|
+
private closeBtnClickHandler;
|
|
28
|
+
private closeBtn;
|
|
29
|
+
private backdropBlur;
|
|
30
|
+
private effectiveTheme;
|
|
31
|
+
private headerElement;
|
|
32
|
+
private floatingCloseBtn;
|
|
33
|
+
private floatingCloseHandler;
|
|
34
|
+
/**
|
|
35
|
+
* Create and show the modal immediately with loading state.
|
|
36
|
+
* Uses default branding until real config is loaded.
|
|
37
|
+
* This provides instant visual feedback to the user.
|
|
38
|
+
*/
|
|
39
|
+
createLoading(options: {
|
|
40
|
+
backdropBlur?: boolean;
|
|
41
|
+
}, onClose: () => void): ModalContainerElements;
|
|
42
|
+
/**
|
|
43
|
+
* Update the modal header and styles with real branding.
|
|
44
|
+
* Called after SDK config loads.
|
|
45
|
+
*/
|
|
46
|
+
updateBranding(branding: SdkConfigBranding): void;
|
|
47
|
+
/**
|
|
48
|
+
* Toggle minimal-chrome mode. In minimal mode the header (logo + close)
|
|
49
|
+
* is hidden and a floating close button is positioned over the modal so
|
|
50
|
+
* the body view can render edge-to-edge as its own full-dialog design.
|
|
51
|
+
*/
|
|
52
|
+
setMinimalChrome(enabled: boolean): void;
|
|
53
|
+
/**
|
|
54
|
+
* Update the backdrop blur setting.
|
|
55
|
+
* Called after SDK config loads with resolved value (client override > server config > default).
|
|
56
|
+
*/
|
|
57
|
+
updateBackdropBlur(enabled: boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* Create and show the modal container.
|
|
60
|
+
* Returns the container elements for the renderer to populate.
|
|
61
|
+
*/
|
|
62
|
+
create(options: ModalOptions, onClose: () => void): ModalContainerElements;
|
|
63
|
+
private createHeader;
|
|
64
|
+
private handleClose;
|
|
65
|
+
/**
|
|
66
|
+
* Get the modal body element for content rendering.
|
|
67
|
+
*/
|
|
68
|
+
getBody(): HTMLDivElement | null;
|
|
69
|
+
/**
|
|
70
|
+
* Check if the modal is currently open.
|
|
71
|
+
*/
|
|
72
|
+
isOpen(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Destroy the modal and clean up all event listeners.
|
|
75
|
+
*/
|
|
76
|
+
destroy(): void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Escape HTML to prevent XSS.
|
|
80
|
+
* Used for any user-provided content rendered in the modal.
|
|
81
|
+
*/
|
|
82
|
+
export declare function escapeHtml(str: string): string;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity View Renderer
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates view state and rendering for identity verification flows.
|
|
5
|
+
* Uses extracted handlers for TOTP and Passkey operations.
|
|
6
|
+
*/
|
|
7
|
+
import type { VerifyOptions, VerifyResult } from './types';
|
|
8
|
+
import { IdentityApi } from './api';
|
|
9
|
+
import type { Container } from './container';
|
|
10
|
+
interface RendererCallbacks {
|
|
11
|
+
onSuccess: (result: VerifyResult) => void;
|
|
12
|
+
onError: (error: Error) => void;
|
|
13
|
+
onCancel: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare class IdentityRenderer {
|
|
16
|
+
private readonly api;
|
|
17
|
+
private readonly container;
|
|
18
|
+
private readonly options;
|
|
19
|
+
private readonly callbacks;
|
|
20
|
+
private readonly verificationState;
|
|
21
|
+
private readonly passkeyHandler;
|
|
22
|
+
private readonly totpHandler;
|
|
23
|
+
private readonly sparkLinkHandler;
|
|
24
|
+
private currentView;
|
|
25
|
+
private focusTimeoutId;
|
|
26
|
+
private sparkLinkWs;
|
|
27
|
+
constructor(container: Container, api: IdentityApi, options: VerifyOptions, callbacks: RendererCallbacks);
|
|
28
|
+
private get recipient();
|
|
29
|
+
private get identityType();
|
|
30
|
+
private get sdkConfig();
|
|
31
|
+
/**
|
|
32
|
+
* Start the identity verification flow.
|
|
33
|
+
* If config was preloaded, opens modal and proceeds immediately.
|
|
34
|
+
* Otherwise shows loading state while fetching config.
|
|
35
|
+
*/
|
|
36
|
+
start(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Map a config-fetch error to the appropriate terminal view.
|
|
39
|
+
* `app_not_installed` is a misconfiguration (account hasn't installed the
|
|
40
|
+
* Identity app) — show a developer-targeted "Not Activated" screen with a
|
|
41
|
+
* link to SparkVault.com instead of the generic service-unavailable view.
|
|
42
|
+
*/
|
|
43
|
+
private viewStateForConfigError;
|
|
44
|
+
/**
|
|
45
|
+
* Fetch config with a single retry on network errors.
|
|
46
|
+
* Handles transient failures common during subdomain switches
|
|
47
|
+
* (DNS resolution, connection setup, Safari ITP).
|
|
48
|
+
*/
|
|
49
|
+
private fetchConfigWithRetry;
|
|
50
|
+
/**
|
|
51
|
+
* Retry loading config after a service-unavailable error.
|
|
52
|
+
* Shows loading state, re-fetches config, then proceeds normally.
|
|
53
|
+
*/
|
|
54
|
+
private retryConfigLoad;
|
|
55
|
+
/**
|
|
56
|
+
* Close the modal and clean up.
|
|
57
|
+
* Cancels all pending API requests to prevent orphaned operations.
|
|
58
|
+
*/
|
|
59
|
+
close(): void;
|
|
60
|
+
private handleClose;
|
|
61
|
+
private get viewState();
|
|
62
|
+
private setState;
|
|
63
|
+
private render;
|
|
64
|
+
private destroyCurrentView;
|
|
65
|
+
private createViewForState;
|
|
66
|
+
private showIdentityInput;
|
|
67
|
+
private showMethodSelect;
|
|
68
|
+
private handleIdentitySubmit;
|
|
69
|
+
private getAllowedIdentityTypes;
|
|
70
|
+
private handleMethodSelect;
|
|
71
|
+
private handleTotpSubmit;
|
|
72
|
+
private handleTotpResend;
|
|
73
|
+
private handlePasskeyStart;
|
|
74
|
+
/**
|
|
75
|
+
* Handle fallback from passkey to email/SMS code.
|
|
76
|
+
* User clicked "Having trouble? Use email code instead".
|
|
77
|
+
*/
|
|
78
|
+
private handlePasskeyFallback;
|
|
79
|
+
/**
|
|
80
|
+
* Handle skipping passkey registration when coming from passkey prompt.
|
|
81
|
+
* User clicked "Back" or cancelled registration after being prompted.
|
|
82
|
+
*/
|
|
83
|
+
private handlePasskeyRegistrationSkip;
|
|
84
|
+
private handleSocialLogin;
|
|
85
|
+
private normalizeError;
|
|
86
|
+
/**
|
|
87
|
+
* Check if error is a session/token expiration that should redirect to identity input.
|
|
88
|
+
*/
|
|
89
|
+
private isSessionExpiredError;
|
|
90
|
+
/**
|
|
91
|
+
* Handle errors - redirect to identity input for session errors, show error view otherwise.
|
|
92
|
+
*/
|
|
93
|
+
private handleErrorWithRecovery;
|
|
94
|
+
/**
|
|
95
|
+
* Check if we should show the passkey registration prompt after PIN verification.
|
|
96
|
+
*/
|
|
97
|
+
private shouldShowPasskeyPrompt;
|
|
98
|
+
/**
|
|
99
|
+
* Handle user clicking "Add Passkey" in the prompt.
|
|
100
|
+
* Directly triggers browser passkey creation without intermediate screen.
|
|
101
|
+
*/
|
|
102
|
+
private handlePasskeyPromptAdd;
|
|
103
|
+
/**
|
|
104
|
+
* Handle user clicking "Not now" / "Skip" in the prompt.
|
|
105
|
+
*/
|
|
106
|
+
private handlePasskeyPromptSkip;
|
|
107
|
+
/**
|
|
108
|
+
* Open a WebSocket connection and return the connectionId.
|
|
109
|
+
* The server echoes back the connectionId on init; this is used to route
|
|
110
|
+
* the SparkLink verification result back to this SDK instance.
|
|
111
|
+
*
|
|
112
|
+
* Returns:
|
|
113
|
+
* - { connectionId: string } on success
|
|
114
|
+
* - { error: 'csp' } if blocked by Content Security Policy
|
|
115
|
+
* - { error: 'connection' } for other connection failures
|
|
116
|
+
*/
|
|
117
|
+
private openSparkLinkWebSocket;
|
|
118
|
+
/**
|
|
119
|
+
* Set up WebSocket message handler for SparkLink verification results.
|
|
120
|
+
* Handles: sparklink_verified, sparklink_failed, sparklink_resent.
|
|
121
|
+
*/
|
|
122
|
+
private setupSparkLinkWsHandler;
|
|
123
|
+
/**
|
|
124
|
+
* Handle successful SparkLink verification via WebSocket push.
|
|
125
|
+
*
|
|
126
|
+
* Always invokes the host callback with the full result (including any
|
|
127
|
+
* redirect URL) before attempting top-level navigation. The host page
|
|
128
|
+
* is the source of truth for what should happen after verification:
|
|
129
|
+
* the SDK's window.location.href call is a fallback for hosts that
|
|
130
|
+
* delegate navigation entirely to the SDK.
|
|
131
|
+
*/
|
|
132
|
+
private handleSparkLinkVerified;
|
|
133
|
+
/**
|
|
134
|
+
* Clean up SparkLink WebSocket connection.
|
|
135
|
+
*/
|
|
136
|
+
private cleanupSparkLink;
|
|
137
|
+
/**
|
|
138
|
+
* Handle resending SparkLink.
|
|
139
|
+
*/
|
|
140
|
+
private handleSparkLinkResend;
|
|
141
|
+
/**
|
|
142
|
+
* Handle fallback from SparkLink to TOTP verification code.
|
|
143
|
+
*/
|
|
144
|
+
private handleSparkLinkFallback;
|
|
145
|
+
}
|
|
146
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification State Manager
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for all verification flow state.
|
|
5
|
+
* Centralizes scattered state from IdentityRenderer for:
|
|
6
|
+
* - Predictable state transitions
|
|
7
|
+
* - Easier debugging and testing
|
|
8
|
+
* - Clear data ownership
|
|
9
|
+
*/
|
|
10
|
+
import type { SdkConfig, VerifyResult, IdentityViewState, MethodMetadata, AuthContext } from './types';
|
|
11
|
+
import type { IdentityType } from './views';
|
|
12
|
+
/**
|
|
13
|
+
* Passkey-specific state
|
|
14
|
+
*/
|
|
15
|
+
interface PasskeyState {
|
|
16
|
+
/** Whether user has registered passkeys (null = unknown) */
|
|
17
|
+
hasPasskey: boolean | null;
|
|
18
|
+
/** Whether user fell back from passkey to another method */
|
|
19
|
+
isFallbackMode: boolean;
|
|
20
|
+
/** Pending result when prompting for passkey registration after TOTP */
|
|
21
|
+
pendingResult: VerifyResult | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* TOTP-specific state
|
|
25
|
+
*/
|
|
26
|
+
interface TotpState {
|
|
27
|
+
/** Current kindling token for TOTP verification */
|
|
28
|
+
kindling: string;
|
|
29
|
+
/** Current TOTP method (email or sms) */
|
|
30
|
+
method: 'email' | 'sms' | null;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Centralized verification state
|
|
34
|
+
*/
|
|
35
|
+
export declare class VerificationState {
|
|
36
|
+
private _sdkConfig;
|
|
37
|
+
private _viewState;
|
|
38
|
+
private _recipient;
|
|
39
|
+
private _identityType;
|
|
40
|
+
private _authContext;
|
|
41
|
+
private readonly _passkey;
|
|
42
|
+
private readonly _totp;
|
|
43
|
+
private readonly listeners;
|
|
44
|
+
/**
|
|
45
|
+
* Subscribe to state changes
|
|
46
|
+
* @param listener - Callback invoked on state change
|
|
47
|
+
* @returns Unsubscribe function
|
|
48
|
+
*/
|
|
49
|
+
subscribe(listener: (state: IdentityViewState) => void): () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Notify all listeners of state change
|
|
52
|
+
*/
|
|
53
|
+
private notify;
|
|
54
|
+
get sdkConfig(): SdkConfig | null;
|
|
55
|
+
setConfig(config: SdkConfig): void;
|
|
56
|
+
get accountId(): string;
|
|
57
|
+
/**
|
|
58
|
+
* Get enriched methods filtered by identity type
|
|
59
|
+
*/
|
|
60
|
+
getAvailableMethods(): MethodMetadata[];
|
|
61
|
+
/**
|
|
62
|
+
* Check if passkey method is enabled in config
|
|
63
|
+
*/
|
|
64
|
+
isPasskeyEnabled(): boolean;
|
|
65
|
+
get viewState(): IdentityViewState;
|
|
66
|
+
setViewState(state: IdentityViewState): void;
|
|
67
|
+
get recipient(): string;
|
|
68
|
+
get identityType(): IdentityType;
|
|
69
|
+
setIdentity(recipient: string, type: IdentityType): void;
|
|
70
|
+
getAllowedIdentityTypes(): IdentityType[];
|
|
71
|
+
get authContext(): AuthContext | undefined;
|
|
72
|
+
setAuthContext(context: AuthContext | undefined): void;
|
|
73
|
+
get passkey(): Readonly<PasskeyState>;
|
|
74
|
+
setPasskeyStatus(hasPasskey: boolean | null): void;
|
|
75
|
+
enablePasskeyFallback(): void;
|
|
76
|
+
setPendingResult(result: VerifyResult | null): void;
|
|
77
|
+
/**
|
|
78
|
+
* Check if we should show passkey registration prompt
|
|
79
|
+
* Based on: passkey enabled, user doesn't have one, not dismissed
|
|
80
|
+
*/
|
|
81
|
+
shouldShowPasskeyPrompt(): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Check if passkey prompt was dismissed (30-day cookie)
|
|
84
|
+
*/
|
|
85
|
+
private isPasskeyPromptDismissed;
|
|
86
|
+
/**
|
|
87
|
+
* Dismiss passkey prompt for 30 days
|
|
88
|
+
*/
|
|
89
|
+
dismissPasskeyPrompt(): void;
|
|
90
|
+
get totp(): Readonly<TotpState>;
|
|
91
|
+
setKindling(kindling: string): void;
|
|
92
|
+
setTotpMethod(method: 'email' | 'sms'): void;
|
|
93
|
+
/**
|
|
94
|
+
* Reset state for new verification attempt
|
|
95
|
+
*/
|
|
96
|
+
reset(): void;
|
|
97
|
+
}
|
|
98
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity Modal Styles
|
|
3
|
+
*
|
|
4
|
+
* Enterprise-grade styling following Stripe/Adobe design principles:
|
|
5
|
+
* - Clean, minimal aesthetic with purposeful whitespace
|
|
6
|
+
* - 4px base spacing unit for consistency
|
|
7
|
+
* - Subtle depth through shadows and borders (not gradients)
|
|
8
|
+
* - Professional typography with clear hierarchy
|
|
9
|
+
* - Refined color palette with single accent
|
|
10
|
+
*/
|
|
11
|
+
import type { SdkConfigBranding } from './types';
|
|
12
|
+
export interface StyleOptions {
|
|
13
|
+
branding: SdkConfigBranding;
|
|
14
|
+
backdropBlur?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Inject modal styles into the document head.
|
|
18
|
+
*/
|
|
19
|
+
export declare function injectStyles(options: StyleOptions): void;
|
|
20
|
+
export declare function updateThemeVariables(_branding: SdkConfigBranding | undefined | null): void;
|
|
21
|
+
export declare function removeStyles(): void;
|
|
22
|
+
export declare function resolveTheme(branding: SdkConfigBranding | undefined | null): 'light' | 'dark';
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity Module Types
|
|
3
|
+
*/
|
|
4
|
+
export type AuthMethod = 'passkey' | 'totp_email' | 'totp_sms' | 'totp_voice' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
|
|
5
|
+
export type Theme = 'light' | 'dark';
|
|
6
|
+
/**
|
|
7
|
+
* Auth context for OIDC or simple redirect flows.
|
|
8
|
+
* Used by hosted login pages to complete authorization flows.
|
|
9
|
+
*/
|
|
10
|
+
export interface AuthContext {
|
|
11
|
+
/** OIDC auth request ID for authorization code flow */
|
|
12
|
+
authRequestId?: string;
|
|
13
|
+
/** Simple redirect mode configuration */
|
|
14
|
+
simpleMode?: {
|
|
15
|
+
successUrl: string;
|
|
16
|
+
failureUrl: string;
|
|
17
|
+
state?: string;
|
|
18
|
+
/** Opaque server-side verify session backing success/failure URLs */
|
|
19
|
+
sessionId?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface VerifyOptions {
|
|
23
|
+
/** Pre-fill email address (mutually exclusive with phone) */
|
|
24
|
+
email?: string;
|
|
25
|
+
/** Pre-fill phone number in E.164 format, e.g. "+14155551234" (mutually exclusive with email) */
|
|
26
|
+
phone?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Target element for inline rendering. Can be:
|
|
29
|
+
* - A CSS selector string (e.g., "#auth-container")
|
|
30
|
+
* - An HTMLElement reference
|
|
31
|
+
* - Omitted for dialog mode (default)
|
|
32
|
+
*/
|
|
33
|
+
target?: string | HTMLElement;
|
|
34
|
+
/** Override backdrop blur for this dialog (uses global config if omitted) */
|
|
35
|
+
backdropBlur?: boolean;
|
|
36
|
+
/** Auth context for OIDC/simple mode flows (used by hosted login) */
|
|
37
|
+
authContext?: AuthContext;
|
|
38
|
+
/** Called when user cancels (if omitted, uses server-configured redirect) */
|
|
39
|
+
onCancel?: () => void;
|
|
40
|
+
/** Called when verification completes (if omitted, uses server-configured redirect) */
|
|
41
|
+
onSuccess?: (result: VerifyResult) => void;
|
|
42
|
+
/** Called on error (if omitted, uses server-configured redirect) */
|
|
43
|
+
onError?: (error: Error) => void;
|
|
44
|
+
}
|
|
45
|
+
/** Options for attach() - binds verification to element clicks */
|
|
46
|
+
export interface AttachOptions {
|
|
47
|
+
/** Pre-fill email address */
|
|
48
|
+
email?: string;
|
|
49
|
+
/** Pre-fill phone number in E.164 format */
|
|
50
|
+
phone?: string;
|
|
51
|
+
/** Auth context for OIDC/simple mode flows */
|
|
52
|
+
authContext?: AuthContext;
|
|
53
|
+
/** Called when user cancels */
|
|
54
|
+
onCancel?: () => void;
|
|
55
|
+
/** Called when verification completes */
|
|
56
|
+
onSuccess?: (result: VerifyResult) => void;
|
|
57
|
+
/** Called on error */
|
|
58
|
+
onError?: (error: Error) => void;
|
|
59
|
+
}
|
|
60
|
+
export interface VerifyResult {
|
|
61
|
+
/** Signed JWT token */
|
|
62
|
+
token: string;
|
|
63
|
+
/** Verified identity (email or phone) */
|
|
64
|
+
identity: string;
|
|
65
|
+
/** Type of identity verified */
|
|
66
|
+
identityType: 'email' | 'phone';
|
|
67
|
+
/** Redirect URL (only present for OIDC/simple mode flows) */
|
|
68
|
+
redirect?: string;
|
|
69
|
+
}
|
|
70
|
+
export interface TokenClaims {
|
|
71
|
+
/** Issuer */
|
|
72
|
+
iss: string;
|
|
73
|
+
/** Subject (hashed identity) */
|
|
74
|
+
sub: string;
|
|
75
|
+
/** Audience (account ID for simple tokens, client ID for OIDC) */
|
|
76
|
+
aud: string;
|
|
77
|
+
/** Expiry (Unix seconds) */
|
|
78
|
+
exp: number;
|
|
79
|
+
/** Issued at (Unix seconds) */
|
|
80
|
+
iat: number;
|
|
81
|
+
/** Unique token ID for replay protection */
|
|
82
|
+
jti?: string;
|
|
83
|
+
/** Verified identity (email or phone) */
|
|
84
|
+
identity: string;
|
|
85
|
+
/** Identity type */
|
|
86
|
+
identity_type: 'email' | 'phone';
|
|
87
|
+
/** Verification timestamp (Unix seconds) */
|
|
88
|
+
verified_at: number;
|
|
89
|
+
/** Authentication method used */
|
|
90
|
+
method: string;
|
|
91
|
+
}
|
|
92
|
+
export interface EmbedMessage {
|
|
93
|
+
type: 'sparkvault:identity:result' | 'sparkvault:identity:cancel' | 'sparkvault:identity:error' | 'sparkvault:identity:ready';
|
|
94
|
+
payload?: VerifyResult | {
|
|
95
|
+
error: string;
|
|
96
|
+
code: string;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export interface SdkConfigBranding {
|
|
100
|
+
companyName: string;
|
|
101
|
+
logoLight: string | null;
|
|
102
|
+
logoDark: string | null;
|
|
103
|
+
/** Backdrop blur setting (default: true) */
|
|
104
|
+
backdrop_blur?: boolean;
|
|
105
|
+
/** Theme mode from server config */
|
|
106
|
+
themeMode?: 'light' | 'dark';
|
|
107
|
+
}
|
|
108
|
+
/** Method ID returned by config endpoint */
|
|
109
|
+
export type MethodId = 'totp_email' | 'totp_sms' | 'totp_voice' | 'passkey' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
|
|
110
|
+
export interface SdkConfig {
|
|
111
|
+
accountId: string;
|
|
112
|
+
/** Branding configuration (optional in v1 - uses defaults if not provided) */
|
|
113
|
+
branding?: SdkConfigBranding;
|
|
114
|
+
/** Allowed identity types: 'email', 'phone', or both */
|
|
115
|
+
allowedIdentityTypes?: ('email' | 'phone')[];
|
|
116
|
+
/** Enabled method IDs */
|
|
117
|
+
methods: MethodId[];
|
|
118
|
+
/** WebSocket domain for SparkLink push notifications (e.g., 'ws.sparkvault.com') */
|
|
119
|
+
wsDomain?: string;
|
|
120
|
+
}
|
|
121
|
+
/** Method metadata for SDK rendering (static lookup) */
|
|
122
|
+
export interface MethodMetadata {
|
|
123
|
+
id: MethodId;
|
|
124
|
+
type: 'totp' | 'passkey' | 'sparklink' | 'social';
|
|
125
|
+
/** Which identity type this method requires */
|
|
126
|
+
identityType: 'email' | 'phone';
|
|
127
|
+
name: string;
|
|
128
|
+
description: string;
|
|
129
|
+
icon: string;
|
|
130
|
+
/** Provider name for social methods */
|
|
131
|
+
provider?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface TotpSendResponse {
|
|
134
|
+
success: boolean;
|
|
135
|
+
kindling: string;
|
|
136
|
+
expires_at: number;
|
|
137
|
+
method: string;
|
|
138
|
+
}
|
|
139
|
+
export interface TotpVerifyResponse {
|
|
140
|
+
verified: boolean;
|
|
141
|
+
token?: string;
|
|
142
|
+
/** Identity (email or phone) - returned on success */
|
|
143
|
+
identity?: string;
|
|
144
|
+
/** Identity type - 'email' or 'phone' */
|
|
145
|
+
identity_type?: 'email' | 'phone';
|
|
146
|
+
/** Redirect URL for OIDC/simple mode flows */
|
|
147
|
+
redirect?: string;
|
|
148
|
+
/** Returned on failure - new kindling for next attempt */
|
|
149
|
+
kindling?: string;
|
|
150
|
+
/** Returned on failure - seconds until next attempt allowed */
|
|
151
|
+
retry_after?: number;
|
|
152
|
+
/** Returned on failure - when the backoff expires */
|
|
153
|
+
expires_at?: number;
|
|
154
|
+
}
|
|
155
|
+
export interface PasskeyChallengeResponse {
|
|
156
|
+
challenge: string;
|
|
157
|
+
rpId: string;
|
|
158
|
+
rpName: string;
|
|
159
|
+
userId?: string;
|
|
160
|
+
userName?: string;
|
|
161
|
+
allowCredentials?: Array<{
|
|
162
|
+
id: string;
|
|
163
|
+
type: 'public-key';
|
|
164
|
+
}>;
|
|
165
|
+
timeout: number;
|
|
166
|
+
/** Session object to pass back in complete request */
|
|
167
|
+
session: Record<string, unknown>;
|
|
168
|
+
}
|
|
169
|
+
export interface PasskeyVerifyResponse {
|
|
170
|
+
token: string;
|
|
171
|
+
identity: string;
|
|
172
|
+
identity_type: 'email' | 'phone';
|
|
173
|
+
/** Redirect URL for OIDC/simple mode flows */
|
|
174
|
+
redirect?: string;
|
|
175
|
+
}
|
|
176
|
+
export interface SparkLinkSendResponse {
|
|
177
|
+
sparkId: string;
|
|
178
|
+
expiresAt: number;
|
|
179
|
+
}
|
|
180
|
+
export type IdentityViewState = {
|
|
181
|
+
view: 'loading';
|
|
182
|
+
} | {
|
|
183
|
+
view: 'identity-input';
|
|
184
|
+
error?: string;
|
|
185
|
+
} | {
|
|
186
|
+
view: 'method-select';
|
|
187
|
+
email: string;
|
|
188
|
+
methods: MethodMetadata[];
|
|
189
|
+
} | {
|
|
190
|
+
view: 'totp-verify';
|
|
191
|
+
email: string;
|
|
192
|
+
method: 'email' | 'sms';
|
|
193
|
+
kindling: string;
|
|
194
|
+
error?: string;
|
|
195
|
+
backoffExpires?: number;
|
|
196
|
+
} | {
|
|
197
|
+
view: 'passkey';
|
|
198
|
+
email: string;
|
|
199
|
+
mode: 'register' | 'verify';
|
|
200
|
+
error?: string;
|
|
201
|
+
} | {
|
|
202
|
+
view: 'passkey-prompt';
|
|
203
|
+
email: string;
|
|
204
|
+
pendingResult: VerifyResult;
|
|
205
|
+
error?: string;
|
|
206
|
+
} | {
|
|
207
|
+
view: 'sparklink-waiting';
|
|
208
|
+
email: string;
|
|
209
|
+
expiresAt: number;
|
|
210
|
+
} | {
|
|
211
|
+
view: 'oauth-pending';
|
|
212
|
+
provider: string;
|
|
213
|
+
} | {
|
|
214
|
+
view: 'error';
|
|
215
|
+
message: string;
|
|
216
|
+
code: string;
|
|
217
|
+
} | {
|
|
218
|
+
view: 'service-unavailable';
|
|
219
|
+
} | {
|
|
220
|
+
view: 'app-not-activated';
|
|
221
|
+
};
|