@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,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SparkVault API Base
|
|
3
|
+
*
|
|
4
|
+
* Shared lifecycle and HTTP plumbing for every internal API client in the
|
|
5
|
+
* SDK. Concrete clients (IdentityApi, UploadApi, ...) extend this and
|
|
6
|
+
* provide:
|
|
7
|
+
* - their own error factory via makeError()
|
|
8
|
+
* - their own typed endpoint methods that call rawRequest()
|
|
9
|
+
*
|
|
10
|
+
* Session lifecycle invariant: every user-facing session (a modal open, a
|
|
11
|
+
* verify flow, an upload widget invocation) starts with the owning Module
|
|
12
|
+
* calling resetSession(). close() aborts the current AbortController; the
|
|
13
|
+
* next resetSession() swaps in a fresh one. The Module is responsible for
|
|
14
|
+
* this; clients of the SDK never see any of it.
|
|
15
|
+
*/
|
|
16
|
+
import { SparkVaultError } from './errors';
|
|
17
|
+
export interface RawRequestOptions {
|
|
18
|
+
method: string;
|
|
19
|
+
body?: string;
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
export interface RawResponse {
|
|
23
|
+
data: unknown;
|
|
24
|
+
status: number;
|
|
25
|
+
}
|
|
26
|
+
export declare abstract class SparkVaultApi {
|
|
27
|
+
protected readonly timeoutMs: number;
|
|
28
|
+
/**
|
|
29
|
+
* Abort controller for the current session. Replaced by resetSession()
|
|
30
|
+
* at the start of every user-facing session — an aborted controller can
|
|
31
|
+
* never leak into the next session.
|
|
32
|
+
*/
|
|
33
|
+
private closeController;
|
|
34
|
+
constructor(timeoutMs?: number);
|
|
35
|
+
/** Abort all pending requests on this client. Called by the Module on close. */
|
|
36
|
+
abort(): void;
|
|
37
|
+
/** Whether the *current* session has been aborted. */
|
|
38
|
+
isAborted(): boolean;
|
|
39
|
+
/** The current session's abort signal — for callers that need to wire it into XHR/etc. */
|
|
40
|
+
getAbortSignal(): AbortSignal;
|
|
41
|
+
/**
|
|
42
|
+
* Swap in a fresh AbortController. The Module calls this at the start of
|
|
43
|
+
* every user-facing session. Long-lived per-client state (e.g. config
|
|
44
|
+
* caches) is intentionally NOT cleared here.
|
|
45
|
+
*/
|
|
46
|
+
resetSession(): void;
|
|
47
|
+
/** Subclass-specific error factory. */
|
|
48
|
+
protected abstract makeError(message: string, code: string, statusCode: number): SparkVaultError;
|
|
49
|
+
/**
|
|
50
|
+
* Issue an HTTP request with timeout + session abort + standard error
|
|
51
|
+
* mapping. Subclasses build URLs and unwrap response envelopes on top.
|
|
52
|
+
*
|
|
53
|
+
* Returns the parsed JSON body (whatever shape it takes) plus the
|
|
54
|
+
* status code. Throws subclass-typed errors via makeError() for: aborted
|
|
55
|
+
* sessions, timeouts, network failures, and non-2xx responses.
|
|
56
|
+
*/
|
|
57
|
+
protected rawRequest(url: string, options: RawRequestOptions): Promise<RawResponse>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SparkVault Auto-Initialization
|
|
3
|
+
*
|
|
4
|
+
* Auto-initializes the SDK from script tag data attributes.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```html
|
|
8
|
+
* <script
|
|
9
|
+
* src="https://cdn.sparkvault.com/sdk/v1/sparkvault.js"
|
|
10
|
+
* data-account-id="acc_your_account_id"
|
|
11
|
+
* ></script>
|
|
12
|
+
*
|
|
13
|
+
* <script>
|
|
14
|
+
* // SDK is ready - just use it
|
|
15
|
+
* SparkVault.identity.attach('.login-btn', {
|
|
16
|
+
* onSuccess: (result) => console.log('Verified:', result.identity)
|
|
17
|
+
* });
|
|
18
|
+
* </script>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Supported attributes:
|
|
22
|
+
* - data-account-id: Account ID (required for auto-init)
|
|
23
|
+
* - data-debug: Set to "true" to enable verbose console logging
|
|
24
|
+
*/
|
|
25
|
+
import type { SparkVault } from './index';
|
|
26
|
+
/**
|
|
27
|
+
* Initialize the SDK from script tag attributes.
|
|
28
|
+
*
|
|
29
|
+
* Called automatically when the script loads.
|
|
30
|
+
* Returns the initialized instance if data-account-id is present, null otherwise.
|
|
31
|
+
*/
|
|
32
|
+
export declare function autoInit(SparkVaultClass: typeof SparkVault): SparkVault | null;
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SparkVault SDK Configuration
|
|
3
|
+
*/
|
|
4
|
+
export interface SparkVaultConfig {
|
|
5
|
+
/** Account ID for Identity operations */
|
|
6
|
+
accountId: string;
|
|
7
|
+
/** Core API origin. Defaults to https://api.sparkvault.com. A trailing /v1 is accepted and normalized. */
|
|
8
|
+
apiBaseUrl?: string;
|
|
9
|
+
/** Identity App API base URL. Defaults to https://api.sparkvault.com/v1/apps/identity. */
|
|
10
|
+
identityBaseUrl?: string;
|
|
11
|
+
/** Static SparkVault Core access token for authenticated API calls. */
|
|
12
|
+
accessToken?: string;
|
|
13
|
+
/** Dynamic SparkVault Core access token provider for authenticated API calls. */
|
|
14
|
+
getAccessToken?: () => string | null | Promise<string | null>;
|
|
15
|
+
/** Optional API key for server-side SDK use. */
|
|
16
|
+
apiKey?: string;
|
|
17
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
18
|
+
timeout?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Preload Identity configuration on SDK init (default: true).
|
|
21
|
+
* When enabled, the /config call is made immediately when the SDK initializes,
|
|
22
|
+
* so verify() opens instantly without waiting for the config fetch.
|
|
23
|
+
* Set to false to defer config loading until verify() is called.
|
|
24
|
+
*/
|
|
25
|
+
preloadConfig?: boolean;
|
|
26
|
+
/** Enable backdrop blur on dialogs (default: true) */
|
|
27
|
+
backdropBlur?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface ResolvedConfig {
|
|
30
|
+
accountId: string;
|
|
31
|
+
timeout: number;
|
|
32
|
+
apiBaseUrl: string;
|
|
33
|
+
identityBaseUrl: string;
|
|
34
|
+
accessToken?: string;
|
|
35
|
+
getAccessToken?: () => string | null | Promise<string | null>;
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
preloadConfig: boolean;
|
|
38
|
+
backdropBlur: boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare function resolveConfig(config: SparkVaultConfig): ResolvedConfig;
|
|
41
|
+
export declare function validateConfig(config: SparkVaultConfig): void;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SparkVault SDK Error Types
|
|
3
|
+
*/
|
|
4
|
+
export declare class SparkVaultError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly statusCode?: number;
|
|
7
|
+
readonly details?: Record<string, unknown>;
|
|
8
|
+
constructor(message: string, code: string, statusCode?: number, details?: Record<string, unknown>);
|
|
9
|
+
}
|
|
10
|
+
export declare class AuthenticationError extends SparkVaultError {
|
|
11
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
12
|
+
}
|
|
13
|
+
export declare class AuthorizationError extends SparkVaultError {
|
|
14
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
15
|
+
}
|
|
16
|
+
export declare class ValidationError extends SparkVaultError {
|
|
17
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
18
|
+
}
|
|
19
|
+
export declare class NetworkError extends SparkVaultError {
|
|
20
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
21
|
+
}
|
|
22
|
+
export declare class TimeoutError extends SparkVaultError {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class UserCancelledError extends SparkVaultError {
|
|
26
|
+
constructor(message?: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class PopupBlockedError extends SparkVaultError {
|
|
29
|
+
constructor();
|
|
30
|
+
}
|
package/dist/health.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ResolvedConfig } from './config';
|
|
2
|
+
export interface HealthCheckOptions {
|
|
3
|
+
timeout?: number;
|
|
4
|
+
}
|
|
5
|
+
export interface HealthCheckResult {
|
|
6
|
+
online: boolean;
|
|
7
|
+
status: string;
|
|
8
|
+
httpStatus?: number;
|
|
9
|
+
checkedAt: number;
|
|
10
|
+
error?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class HealthModule {
|
|
13
|
+
private readonly config;
|
|
14
|
+
constructor(config: ResolvedConfig);
|
|
15
|
+
check(options?: HealthCheckOptions): Promise<HealthCheckResult>;
|
|
16
|
+
isOnline(options?: HealthCheckOptions): Promise<boolean>;
|
|
17
|
+
private readStatus;
|
|
18
|
+
}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SparkVault SDK HTTP Client
|
|
3
|
+
*/
|
|
4
|
+
import type { ResolvedConfig } from './config';
|
|
5
|
+
import { type RetryOptions } from './utils/retry';
|
|
6
|
+
export interface RequestOptions {
|
|
7
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/** Enable automatic retry with exponential backoff (per CLAUDE.md §7) */
|
|
12
|
+
retry?: boolean | RetryOptions;
|
|
13
|
+
}
|
|
14
|
+
export interface ApiResponse<T = unknown> {
|
|
15
|
+
data: T;
|
|
16
|
+
status: number;
|
|
17
|
+
headers: Headers;
|
|
18
|
+
}
|
|
19
|
+
export declare class HttpClient {
|
|
20
|
+
private readonly config;
|
|
21
|
+
constructor(config: ResolvedConfig);
|
|
22
|
+
private getDefaultHeaders;
|
|
23
|
+
private getAccessToken;
|
|
24
|
+
request<T = unknown>(path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
25
|
+
/**
|
|
26
|
+
* Execute the actual HTTP request (internal implementation)
|
|
27
|
+
*/
|
|
28
|
+
private executeRequest;
|
|
29
|
+
/**
|
|
30
|
+
* Check if an error is safe to retry
|
|
31
|
+
* Per CLAUDE.md §7: Only retry on transient/network errors, not client errors
|
|
32
|
+
*/
|
|
33
|
+
private isRetryableError;
|
|
34
|
+
private parseResponse;
|
|
35
|
+
private createErrorFromResponse;
|
|
36
|
+
private unwrapApiResponse;
|
|
37
|
+
get<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
|
|
38
|
+
post<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
|
|
39
|
+
put<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
|
|
40
|
+
patch<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
|
|
41
|
+
delete<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
|
|
42
|
+
/**
|
|
43
|
+
* Request raw binary data (e.g., file downloads).
|
|
44
|
+
* Returns a Blob instead of parsed JSON.
|
|
45
|
+
*/
|
|
46
|
+
requestRaw(path: string, options?: RequestOptions): Promise<Blob>;
|
|
47
|
+
/**
|
|
48
|
+
* Execute the actual raw HTTP request (internal implementation)
|
|
49
|
+
*/
|
|
50
|
+
private executeRequestRaw;
|
|
51
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity API Client
|
|
3
|
+
*
|
|
4
|
+
* Handles all HTTP communication with the Identity App endpoints.
|
|
5
|
+
* Single responsibility: API calls only.
|
|
6
|
+
*/
|
|
7
|
+
import type { ResolvedConfig } from '../config';
|
|
8
|
+
import { SparkVaultApi } from '../api-base';
|
|
9
|
+
import { SparkVaultError } from '../errors';
|
|
10
|
+
import type { SdkConfig, TotpSendResponse, TotpVerifyResponse, PasskeyChallengeResponse, PasskeyVerifyResponse, SparkLinkSendResponse, AuthContext } from './types';
|
|
11
|
+
export declare class IdentityApi extends SparkVaultApi {
|
|
12
|
+
private readonly config;
|
|
13
|
+
/** Cached config promise - allows preloading and deduplication */
|
|
14
|
+
private configCache;
|
|
15
|
+
constructor(config: ResolvedConfig, timeoutMs?: number);
|
|
16
|
+
private get baseUrl();
|
|
17
|
+
protected makeError(message: string, code: string, statusCode: number): IdentityApiError;
|
|
18
|
+
private request;
|
|
19
|
+
/**
|
|
20
|
+
* Fetch SDK configuration (branding, enabled methods).
|
|
21
|
+
* Uses caching to avoid redundant requests - safe to call multiple times.
|
|
22
|
+
* If a cached request failed (e.g., transient network error during preload),
|
|
23
|
+
* clears the cache and retries to avoid permanently caching a rejected promise.
|
|
24
|
+
*/
|
|
25
|
+
getConfig(): Promise<SdkConfig>;
|
|
26
|
+
/**
|
|
27
|
+
* Preload the SDK configuration in the background.
|
|
28
|
+
* Called on SDK init when preloadConfig is enabled.
|
|
29
|
+
* The result is cached and used when verify() is called.
|
|
30
|
+
* If preload fails, getConfig() will clear the cache and retry.
|
|
31
|
+
*/
|
|
32
|
+
preloadConfig(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Check if config has been preloaded and is ready.
|
|
35
|
+
*/
|
|
36
|
+
isConfigPreloaded(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Check if an identity (email or phone) has registered passkeys.
|
|
39
|
+
*
|
|
40
|
+
* Returns:
|
|
41
|
+
* - identity_valid: identity passes per-type validity check
|
|
42
|
+
* (email: MX lookup; phone: E.164 format)
|
|
43
|
+
* - has_passkey: whether any passkeys are registered for this identity
|
|
44
|
+
* (cross-tenant — single global RP)
|
|
45
|
+
* - email_valid: legacy alias for identity_valid, present for backward
|
|
46
|
+
* compatibility with older SDK versions
|
|
47
|
+
*/
|
|
48
|
+
checkPasskey(identity: string, identityType?: 'email' | 'phone'): Promise<{
|
|
49
|
+
identity_valid: boolean;
|
|
50
|
+
email_valid: boolean;
|
|
51
|
+
has_passkey: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* Build auth context params for API requests (OIDC/simple mode).
|
|
55
|
+
* Converts AuthContext to snake_case params expected by backend.
|
|
56
|
+
*/
|
|
57
|
+
private buildAuthContextParams;
|
|
58
|
+
/**
|
|
59
|
+
* Send TOTP code to email or phone
|
|
60
|
+
*/
|
|
61
|
+
sendTotp(params: {
|
|
62
|
+
recipient: string;
|
|
63
|
+
method: 'email' | 'sms' | 'voice';
|
|
64
|
+
authContext?: AuthContext;
|
|
65
|
+
}): Promise<TotpSendResponse>;
|
|
66
|
+
/**
|
|
67
|
+
* Verify TOTP code
|
|
68
|
+
*/
|
|
69
|
+
verifyTotp(params: {
|
|
70
|
+
kindling: string;
|
|
71
|
+
pin: string;
|
|
72
|
+
recipient: string;
|
|
73
|
+
authContext?: AuthContext;
|
|
74
|
+
}): Promise<TotpVerifyResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Start passkey registration for an identity (email or phone).
|
|
77
|
+
*/
|
|
78
|
+
startPasskeyRegister(identity: string, identityType?: 'email' | 'phone'): Promise<PasskeyChallengeResponse>;
|
|
79
|
+
/**
|
|
80
|
+
* Complete passkey registration
|
|
81
|
+
*/
|
|
82
|
+
completePasskeyRegister(params: {
|
|
83
|
+
session: Record<string, unknown>;
|
|
84
|
+
credential: PublicKeyCredential;
|
|
85
|
+
}): Promise<PasskeyVerifyResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Start passkey verification for an identity (email or phone).
|
|
88
|
+
*/
|
|
89
|
+
startPasskeyVerify(identity: string, identityType?: 'email' | 'phone', authContext?: AuthContext): Promise<PasskeyChallengeResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Complete passkey verification
|
|
92
|
+
*/
|
|
93
|
+
completePasskeyVerify(params: {
|
|
94
|
+
session: Record<string, unknown>;
|
|
95
|
+
credential: PublicKeyCredential;
|
|
96
|
+
authContext?: AuthContext;
|
|
97
|
+
}): Promise<PasskeyVerifyResponse>;
|
|
98
|
+
/**
|
|
99
|
+
* Get OAuth redirect URL for social provider
|
|
100
|
+
*/
|
|
101
|
+
getSocialAuthUrl(provider: string, redirectUri: string, state: string): string;
|
|
102
|
+
/**
|
|
103
|
+
* Send SparkLink email for identity verification.
|
|
104
|
+
* Includes connectionId for WebSocket push notification of verification result.
|
|
105
|
+
*/
|
|
106
|
+
sendSparkLink(email: string, connectionId: string, authContext?: AuthContext): Promise<SparkLinkSendResponse>;
|
|
107
|
+
}
|
|
108
|
+
export declare class IdentityApiError extends SparkVaultError {
|
|
109
|
+
constructor(message: string, code: string, statusCode: number);
|
|
110
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Container Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstract interface for identity UI containers.
|
|
5
|
+
* Allows switching between modal (popup) and inline rendering modes
|
|
6
|
+
* while reusing all view logic, state management, and handlers.
|
|
7
|
+
*/
|
|
8
|
+
import type { SdkConfigBranding } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Container options for initialization.
|
|
11
|
+
*/
|
|
12
|
+
export interface ContainerOptions {
|
|
13
|
+
branding?: SdkConfigBranding;
|
|
14
|
+
/** Enable backdrop blur (modal only) */
|
|
15
|
+
backdropBlur?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Container interface that both ModalContainer and InlineContainer implement.
|
|
19
|
+
* The renderer interacts with containers through this interface.
|
|
20
|
+
*/
|
|
21
|
+
export interface Container {
|
|
22
|
+
/**
|
|
23
|
+
* Create the container with loading state.
|
|
24
|
+
* Called immediately when verification starts.
|
|
25
|
+
*/
|
|
26
|
+
createLoading(options: {
|
|
27
|
+
backdropBlur?: boolean;
|
|
28
|
+
}, onClose: () => void): void;
|
|
29
|
+
/**
|
|
30
|
+
* Update branding after SDK config loads.
|
|
31
|
+
*/
|
|
32
|
+
updateBranding(branding: SdkConfigBranding): void;
|
|
33
|
+
/**
|
|
34
|
+
* Update backdrop blur setting (may be no-op for inline container).
|
|
35
|
+
*/
|
|
36
|
+
updateBackdropBlur(enabled: boolean): void;
|
|
37
|
+
/**
|
|
38
|
+
* Switch to minimal chrome mode for full-bleed views (e.g. terminal error
|
|
39
|
+
* screens). Hides the header (so customer branding doesn't appear on
|
|
40
|
+
* SparkVault-owned messaging) and exposes a floating close affordance.
|
|
41
|
+
* No-op for containers that don't have chrome to hide.
|
|
42
|
+
*/
|
|
43
|
+
setMinimalChrome(enabled: boolean): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get the body element where views are rendered.
|
|
46
|
+
*/
|
|
47
|
+
getBody(): HTMLDivElement | null;
|
|
48
|
+
/**
|
|
49
|
+
* Check if the container is currently active.
|
|
50
|
+
*/
|
|
51
|
+
isOpen(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Destroy the container and clean up event listeners.
|
|
54
|
+
*/
|
|
55
|
+
destroy(): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity Handlers
|
|
3
|
+
*
|
|
4
|
+
* Extracted handlers for specific authentication flows.
|
|
5
|
+
* Each handler has a single responsibility.
|
|
6
|
+
*/
|
|
7
|
+
export { PasskeyHandler, type PasskeyResult, type PasskeyCheckResult } from './passkey-handler';
|
|
8
|
+
export { TotpHandler, type TotpSendResult, type TotpVerifyResult } from './totp-handler';
|
|
9
|
+
export { SparkLinkHandler, type SparkLinkSendResult } from './sparklink-handler';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Passkey Handler
|
|
3
|
+
*
|
|
4
|
+
* Handles WebAuthn passkey registration and verification via popup.
|
|
5
|
+
* Uses a popup window on sparkvault.com domain to ensure WebAuthn works
|
|
6
|
+
* correctly when the SDK is embedded on third-party client domains.
|
|
7
|
+
*
|
|
8
|
+
* Flow:
|
|
9
|
+
* 1. SDK opens popup to sparkvault.com/passkey/popup
|
|
10
|
+
* 2. Popup executes WebAuthn (origin = sparkvault.com matches RP ID)
|
|
11
|
+
* 3. Popup sends result via postMessage
|
|
12
|
+
* 4. SDK receives result and returns to caller
|
|
13
|
+
*/
|
|
14
|
+
import type { IdentityApi } from '../api';
|
|
15
|
+
import type { VerifyResult } from '../types';
|
|
16
|
+
import type { VerificationState } from '../state';
|
|
17
|
+
/**
|
|
18
|
+
* Result of passkey operation
|
|
19
|
+
*/
|
|
20
|
+
export interface PasskeyResult {
|
|
21
|
+
success: boolean;
|
|
22
|
+
result?: VerifyResult;
|
|
23
|
+
error?: string;
|
|
24
|
+
errorType?: 'cancelled' | 'not_found' | 'not_allowed' | 'popup_blocked' | 'unknown';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result of passkey check operation
|
|
28
|
+
*/
|
|
29
|
+
export interface PasskeyCheckResult {
|
|
30
|
+
/** Whether the email domain is valid (has MX records) */
|
|
31
|
+
emailValid: boolean;
|
|
32
|
+
/** Whether the user has registered passkeys (only meaningful if emailValid is true) */
|
|
33
|
+
hasPasskey: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Handles WebAuthn passkey registration and verification via popup
|
|
37
|
+
*/
|
|
38
|
+
export declare class PasskeyHandler {
|
|
39
|
+
private readonly api;
|
|
40
|
+
private readonly state;
|
|
41
|
+
private readonly baseUrl;
|
|
42
|
+
private readonly accountId;
|
|
43
|
+
constructor(api: IdentityApi, state: VerificationState);
|
|
44
|
+
/**
|
|
45
|
+
* Check if user has registered passkeys and validate email domain
|
|
46
|
+
* @returns Check result with emailValid and hasPasskey, or null on error
|
|
47
|
+
*/
|
|
48
|
+
checkPasskey(): Promise<PasskeyCheckResult | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Register a new passkey for the user via popup
|
|
51
|
+
*/
|
|
52
|
+
register(): Promise<PasskeyResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Verify user with existing passkey via popup
|
|
55
|
+
*/
|
|
56
|
+
verify(): Promise<PasskeyResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Open passkey popup and wait for result
|
|
59
|
+
*/
|
|
60
|
+
private openPasskeyPopup;
|
|
61
|
+
/**
|
|
62
|
+
* Validate that a message origin is from sparkvault.com domain
|
|
63
|
+
*/
|
|
64
|
+
private isValidMessageOrigin;
|
|
65
|
+
/**
|
|
66
|
+
* Handle popup error response
|
|
67
|
+
*/
|
|
68
|
+
private handlePopupError;
|
|
69
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SparkLink Handler
|
|
3
|
+
*
|
|
4
|
+
* Single responsibility: SparkLink sending.
|
|
5
|
+
* Verification is handled via WebSocket push (no polling, no iframe).
|
|
6
|
+
*/
|
|
7
|
+
import type { IdentityApi } from '../api';
|
|
8
|
+
import type { VerificationState } from '../state';
|
|
9
|
+
/**
|
|
10
|
+
* Result of SparkLink send operation
|
|
11
|
+
*/
|
|
12
|
+
export interface SparkLinkSendResult {
|
|
13
|
+
success: boolean;
|
|
14
|
+
sparkId?: string;
|
|
15
|
+
expiresAt?: number;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Handles SparkLink sending
|
|
20
|
+
*/
|
|
21
|
+
export declare class SparkLinkHandler {
|
|
22
|
+
private readonly api;
|
|
23
|
+
private readonly state;
|
|
24
|
+
constructor(api: IdentityApi, state: VerificationState);
|
|
25
|
+
/**
|
|
26
|
+
* Send SparkLink to the user's email
|
|
27
|
+
* @param connectionId - WebSocket connectionId for push notification
|
|
28
|
+
*/
|
|
29
|
+
send(connectionId: string): Promise<SparkLinkSendResult>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TOTP Handler
|
|
3
|
+
*
|
|
4
|
+
* Single responsibility: TOTP code sending and verification.
|
|
5
|
+
* Extracts TOTP logic from IdentityRenderer for better separation of concerns.
|
|
6
|
+
*/
|
|
7
|
+
import type { IdentityApi } from '../api';
|
|
8
|
+
import type { VerifyResult } from '../types';
|
|
9
|
+
import type { VerificationState } from '../state';
|
|
10
|
+
/**
|
|
11
|
+
* Result of TOTP send operation
|
|
12
|
+
*/
|
|
13
|
+
export interface TotpSendResult {
|
|
14
|
+
success: boolean;
|
|
15
|
+
kindling?: string;
|
|
16
|
+
expiresAt?: number;
|
|
17
|
+
error?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Result of TOTP verify operation
|
|
21
|
+
*/
|
|
22
|
+
export interface TotpVerifyResult {
|
|
23
|
+
success: boolean;
|
|
24
|
+
result?: VerifyResult;
|
|
25
|
+
/** New kindling if verification failed (for retry) */
|
|
26
|
+
newKindling?: string;
|
|
27
|
+
/** Seconds until retry allowed (rate limiting) */
|
|
28
|
+
retryAfter?: number;
|
|
29
|
+
/** When backoff expires (Unix timestamp) */
|
|
30
|
+
backoffExpires?: number;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Handles TOTP code sending and verification
|
|
35
|
+
*/
|
|
36
|
+
export declare class TotpHandler {
|
|
37
|
+
private readonly api;
|
|
38
|
+
private readonly state;
|
|
39
|
+
constructor(api: IdentityApi, state: VerificationState);
|
|
40
|
+
/**
|
|
41
|
+
* Send TOTP code via email or SMS
|
|
42
|
+
*/
|
|
43
|
+
send(method: 'email' | 'sms'): Promise<TotpSendResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Resend TOTP code
|
|
46
|
+
*/
|
|
47
|
+
resend(): Promise<TotpSendResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Verify TOTP code
|
|
50
|
+
*/
|
|
51
|
+
verify(code: string): Promise<TotpVerifyResult>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity Module
|
|
3
|
+
*
|
|
4
|
+
* Provides identity verification through dialog or inline UI.
|
|
5
|
+
* Supports passkey, TOTP, SparkLink, and social authentication.
|
|
6
|
+
*
|
|
7
|
+
* @example Dialog mode (immediate)
|
|
8
|
+
* const result = await sv.identity.verify();
|
|
9
|
+
*
|
|
10
|
+
* @example Dialog mode (attached to clicks)
|
|
11
|
+
* sv.identity.attach('.login-btn');
|
|
12
|
+
*
|
|
13
|
+
* @example Inline mode
|
|
14
|
+
* const result = await sv.identity.verify({ target: '#auth-container' });
|
|
15
|
+
*/
|
|
16
|
+
import type { ResolvedConfig } from '../config';
|
|
17
|
+
import type { VerifyOptions, VerifyResult, TokenClaims, AttachOptions } from './types';
|
|
18
|
+
export declare class IdentityModule {
|
|
19
|
+
private readonly config;
|
|
20
|
+
private readonly api;
|
|
21
|
+
private renderer;
|
|
22
|
+
private attachedElements;
|
|
23
|
+
constructor(config: ResolvedConfig);
|
|
24
|
+
/**
|
|
25
|
+
* Verify user identity.
|
|
26
|
+
*
|
|
27
|
+
* - Without `target`: Opens a dialog (modal)
|
|
28
|
+
* - With `target`: Renders inline into the specified element
|
|
29
|
+
*
|
|
30
|
+
* @example Dialog mode
|
|
31
|
+
* const result = await sv.identity.verify();
|
|
32
|
+
* console.log(result.token, result.identity);
|
|
33
|
+
*
|
|
34
|
+
* @example Inline mode
|
|
35
|
+
* const result = await sv.identity.verify({
|
|
36
|
+
* target: '#auth-container',
|
|
37
|
+
* email: 'user@example.com'
|
|
38
|
+
* });
|
|
39
|
+
*/
|
|
40
|
+
verify(options?: VerifyOptions): Promise<VerifyResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Attach identity verification to element clicks.
|
|
43
|
+
* When any matching element is clicked, opens the verification dialog.
|
|
44
|
+
*
|
|
45
|
+
* @param selector - CSS selector for elements to attach to
|
|
46
|
+
* @param options - Verification options and callbacks
|
|
47
|
+
* @returns Cleanup function to remove event listeners
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const cleanup = sv.identity.attach('.login-btn', {
|
|
51
|
+
* onSuccess: (result) => console.log('Verified:', result.identity)
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Later, remove listeners
|
|
55
|
+
* cleanup();
|
|
56
|
+
*/
|
|
57
|
+
attach(selector: string, options?: AttachOptions): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Verify and decode an identity token.
|
|
60
|
+
* Validates the token structure, expiry, and issuer.
|
|
61
|
+
*
|
|
62
|
+
* Note: For production use, verify the Ed25519 signature server-side
|
|
63
|
+
* using the JWKS endpoint.
|
|
64
|
+
*/
|
|
65
|
+
verifyToken(token: string): Promise<TokenClaims>;
|
|
66
|
+
/**
|
|
67
|
+
* Close the identity dialog/inline UI if open.
|
|
68
|
+
*/
|
|
69
|
+
close(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Resolve target to an HTMLElement.
|
|
72
|
+
*/
|
|
73
|
+
private createInlineContainer;
|
|
74
|
+
/**
|
|
75
|
+
* Open the identity verification modal as a popup. Equivalent to
|
|
76
|
+
* `verify(options)`.
|
|
77
|
+
*/
|
|
78
|
+
pop(options?: VerifyOptions): Promise<VerifyResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Render the identity verification UI inline into a target element.
|
|
81
|
+
* Equivalent to `verify({ ...options, target })`.
|
|
82
|
+
*/
|
|
83
|
+
render(options: VerifyOptions & {
|
|
84
|
+
target: HTMLElement;
|
|
85
|
+
}): Promise<VerifyResult>;
|
|
86
|
+
}
|
|
87
|
+
export type { VerifyOptions, AttachOptions, VerifyResult, TokenClaims, AuthMethod, AuthContext, Theme, SdkConfig, SdkConfigBranding, MethodId, MethodMetadata, } from './types';
|
|
88
|
+
export { METHOD_REGISTRY, getMethodMetadata, enrichMethods } from './methods';
|
|
89
|
+
export { IdentityApi, IdentityApiError } from './api';
|