@sparkvault/sdk-js 8.0.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/index.d.ts +3 -3
- package/dist/products/identity/api.d.ts +7 -7
- 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/index.d.ts +1 -1
- 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 +6 -6
- 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 +95 -95
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +95 -95
- 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/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
|
/**
|
|
@@ -279,7 +279,7 @@ declare class PopupBlockedError extends SparkVaultError {
|
|
|
279
279
|
* Identity Module
|
|
280
280
|
*
|
|
281
281
|
* Provides identity verification through dialog or inline UI.
|
|
282
|
-
* Supports passkey,
|
|
282
|
+
* Supports passkey, OTP, SparkLink, and social authentication.
|
|
283
283
|
*
|
|
284
284
|
* @example Dialog mode (immediate)
|
|
285
285
|
* const result = await sv.products.identity.verify();
|
|
@@ -439,7 +439,7 @@ declare class IdentityModule {
|
|
|
439
439
|
*/
|
|
440
440
|
|
|
441
441
|
declare class ProductsModule {
|
|
442
|
-
/** Identity verification product (passkey,
|
|
442
|
+
/** Identity verification product (passkey, OTP, SparkLink, social). */
|
|
443
443
|
readonly identity: IdentityModule;
|
|
444
444
|
constructor(config: ResolvedConfig);
|
|
445
445
|
}
|
|
@@ -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.
|
|
@@ -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
|
}
|
|
@@ -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();
|
|
@@ -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
|
/**
|
|
@@ -170,7 +170,7 @@ export interface SdkConfigBranding {
|
|
|
170
170
|
themeMode?: 'light' | 'dark';
|
|
171
171
|
}
|
|
172
172
|
/** Method ID returned by config endpoint */
|
|
173
|
-
export type MethodId = '
|
|
173
|
+
export type MethodId = 'otp_email' | 'otp_sms' | 'otp_voice' | 'passkey' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
|
|
174
174
|
export interface SdkConfig {
|
|
175
175
|
accountId: string;
|
|
176
176
|
/** Branding configuration (optional in v1 - uses defaults if not provided) */
|
|
@@ -191,7 +191,7 @@ export interface SdkConfig {
|
|
|
191
191
|
/** Method metadata for SDK rendering (static lookup) */
|
|
192
192
|
export interface MethodMetadata {
|
|
193
193
|
id: MethodId;
|
|
194
|
-
type: '
|
|
194
|
+
type: 'otp' | 'passkey' | 'sparklink' | 'social';
|
|
195
195
|
/** Which identifier type this method requires. Passkeys are SVID-scoped and do not require one. */
|
|
196
196
|
identityType?: 'email' | 'phone';
|
|
197
197
|
name: string;
|
|
@@ -200,13 +200,13 @@ export interface MethodMetadata {
|
|
|
200
200
|
/** Provider name for social methods */
|
|
201
201
|
provider?: string;
|
|
202
202
|
}
|
|
203
|
-
export interface
|
|
203
|
+
export interface OtpSendResponse {
|
|
204
204
|
success: boolean;
|
|
205
205
|
kindling: string;
|
|
206
206
|
expires_at: number;
|
|
207
207
|
method: string;
|
|
208
208
|
}
|
|
209
|
-
export interface
|
|
209
|
+
export interface OtpVerifyResponse {
|
|
210
210
|
verified: boolean;
|
|
211
211
|
token?: string;
|
|
212
212
|
/** Identity (email or phone) - returned on success */
|
|
@@ -324,7 +324,7 @@ export type IdentityViewState = {
|
|
|
324
324
|
email: string;
|
|
325
325
|
methods: MethodMetadata[];
|
|
326
326
|
} | {
|
|
327
|
-
view: '
|
|
327
|
+
view: 'otp-verify';
|
|
328
328
|
email: string;
|
|
329
329
|
method: 'email' | 'sms' | 'voice';
|
|
330
330
|
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';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* OTP Verification View
|
|
3
3
|
*
|
|
4
|
-
* Collects and validates the 6-digit
|
|
4
|
+
* Collects and validates the 6-digit OTP code sent via email, SMS, or voice.
|
|
5
5
|
*/
|
|
6
6
|
import type { View } from './base';
|
|
7
|
-
export interface
|
|
7
|
+
export interface OtpVerifyViewProps {
|
|
8
8
|
email: string;
|
|
9
9
|
method: 'email' | 'sms' | 'voice';
|
|
10
10
|
error?: string;
|
|
@@ -14,7 +14,7 @@ export interface TotpVerifyViewProps {
|
|
|
14
14
|
onResend: () => void;
|
|
15
15
|
onBack: () => void;
|
|
16
16
|
}
|
|
17
|
-
export declare class
|
|
17
|
+
export declare class OtpVerifyView implements View {
|
|
18
18
|
private readonly props;
|
|
19
19
|
private inputElements;
|
|
20
20
|
private submitButton;
|
|
@@ -31,7 +31,7 @@ export declare class TotpVerifyView implements View {
|
|
|
31
31
|
private readonly boundHandleResend;
|
|
32
32
|
private readonly boundHandleSubmit;
|
|
33
33
|
private readonly inputHandlers;
|
|
34
|
-
constructor(props:
|
|
34
|
+
constructor(props: OtpVerifyViewProps);
|
|
35
35
|
render(): HTMLElement;
|
|
36
36
|
private createBackLink;
|
|
37
37
|
private createInputGroup;
|
package/dist/products/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type { ResolvedConfig } from '../config';
|
|
9
9
|
import { IdentityModule } from './identity';
|
|
10
10
|
export declare class ProductsModule {
|
|
11
|
-
/** Identity verification product (passkey,
|
|
11
|
+
/** Identity verification product (passkey, OTP, SparkLink, social). */
|
|
12
12
|
readonly identity: IdentityModule;
|
|
13
13
|
constructor(config: ResolvedConfig);
|
|
14
14
|
}
|