@sparkvault/sdk-js 7.0.2 → 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 CHANGED
@@ -41,6 +41,35 @@ yarn add @sparkvault/sdk-js
41
41
  - `sparkvault.esm.js` — ES modules for modern bundlers
42
42
  - `sparkvault.cjs.js` — CommonJS for Node.js
43
43
 
44
+ ### Caching & version pinning
45
+
46
+ The CDN serves the browser bundle in two tiers:
47
+
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
+ | `sdk/v1/sparkvault.<hash>.js` | `immutable`, 1 year | You want a reproducible, forever-cached, integrity-pinned build. |
52
+
53
+ `sdk/v1/version.json` advertises the current immutable URL, its hash, and a
54
+ Subresource Integrity (SRI) digest:
55
+
56
+ ```json
57
+ { "version": "7.0.1", "hash": "f771160fa23a09d8", "umd": "sparkvault.f771160fa23a09d8.js", "integrity": "sha384-…" }
58
+ ```
59
+
60
+ To pin a build with integrity verification:
61
+
62
+ ```html
63
+ <script
64
+ src="https://cdn.sparkvault.com/sdk/v1/sparkvault.f771160fa23a09d8.js"
65
+ integrity="sha384-…"
66
+ crossorigin="anonymous"
67
+ ></script>
68
+ ```
69
+
70
+ Pinning trades automatic updates for a byte-stable, forever-cached asset — you
71
+ update by pointing at the next `version.json` entry.
72
+
44
73
  ## CDN Auto-Init
45
74
 
46
75
  ```html
@@ -260,9 +289,9 @@ Authentication methods are configured in your Identity Product settings. The SDK
260
289
  | Method | Description | Identity Type |
261
290
  |--------|-------------|---------------|
262
291
  | `passkey` | WebAuthn/FIDO2 biometric or security key | Email |
263
- | `totp_email` | 6-digit code sent via email | Email |
264
- | `totp_sms` | 6-digit code sent via SMS | Phone |
265
- | `totp_voice` | 6-digit code sent via voice call | Phone |
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 |
266
295
  | `sparklink` | One-click sign-in link via email | Email |
267
296
  | `social_google` | Sign in with Google | Social account |
268
297
  | `social_apple` | Sign in with Apple | Social account |
@@ -485,7 +514,7 @@ When decoded, the JWT token contains these claims:
485
514
  "token_version": 0,
486
515
  "identity": "user@example.com",
487
516
  "identity_type": "email",
488
- "method": "totp_email",
517
+ "method": "otp_email",
489
518
  "verified_at": 1703977195,
490
519
  "iat": 1703977200,
491
520
  "exp": 1703980800,
@@ -503,7 +532,7 @@ When decoded, the JWT token contains these claims:
503
532
  | `token_version` | `number` | Managed-session version used for revocation/introspection |
504
533
  | `identity` | `string` | The verified email address or phone number |
505
534
  | `identity_type` | `string` | `"email"` or `"phone"` |
506
- | `method` | `string` | Authentication method used (e.g., `"totp_email"`, `"passkey"`) |
535
+ | `method` | `string` | Authentication method used (e.g., `"otp_email"`, `"passkey"`) |
507
536
  | `verified_at` | `number` | Unix timestamp when identity was verified |
508
537
  | `iat` | `number` | Issued at timestamp |
509
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' | 'totp_email' | 'totp_sms' | 'totp_voice' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
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, TOTP, SparkLink, and social authentication.
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, TOTP, SparkLink, social). */
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, TotpSendResponse, TotpVerifyResponse, PasskeyChallengeResponse, PasskeyVerifyResponse, SecondFactorVerifyResponse, SparkLinkSendResponse, BackupSendResponse, BackupVerifyResponse, Recommendation, RecommendationKey, AuthContext, VerifyResult } from './types';
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 TOTP code to email or phone
56
+ * Send OTP code to email or phone
57
57
  */
58
- sendTotp(params: {
58
+ sendOtp(params: {
59
59
  recipient: string;
60
60
  method: 'email' | 'sms' | 'voice';
61
61
  authContext?: AuthContext;
62
- }): Promise<TotpSendResponse>;
62
+ }): Promise<OtpSendResponse>;
63
63
  /**
64
- * Verify TOTP code
64
+ * Verify OTP code
65
65
  */
66
- verifyTotp(params: {
66
+ verifyOtp(params: {
67
67
  kindling: string;
68
68
  pin: string;
69
69
  recipient: string;
70
70
  authContext?: AuthContext;
71
- }): Promise<TotpVerifyResponse>;
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 { TotpHandler, type TotpSendResult, type TotpVerifyResult } from './totp-handler';
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
- * TOTP Handler
2
+ * OTP Handler
3
3
  *
4
- * Single responsibility: TOTP code sending and verification.
5
- * Extracts TOTP logic from IdentityRenderer for better separation of concerns.
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 TOTP send operation
11
+ * Result of OTP send operation
12
12
  */
13
- export interface TotpSendResult {
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 TOTP verify operation
27
+ * Result of OTP verify operation
28
28
  */
29
- export interface TotpVerifyResult {
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 TOTP code sending and verification
51
+ * Handles OTP code sending and verification
52
52
  */
53
- export declare class TotpHandler {
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 TOTP code via email, SMS, or voice
58
+ * Send OTP code via email, SMS, or voice
59
59
  */
60
- send(method: 'email' | 'sms' | 'voice'): Promise<TotpSendResult>;
60
+ send(method: 'email' | 'sms' | 'voice'): Promise<OtpSendResult>;
61
61
  /**
62
- * Resend TOTP code
62
+ * Resend OTP code
63
63
  */
64
- resend(): Promise<TotpSendResult>;
64
+ resend(): Promise<OtpSendResult>;
65
65
  /**
66
- * Verify TOTP code
66
+ * Verify OTP code
67
67
  */
68
- verify(code: string): Promise<TotpVerifyResult>;
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, TOTP, SparkLink, and social authentication.
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 TOTP and Passkey operations.
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 totpHandler;
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 handleTotpSubmit;
124
+ private handleOtpSubmit;
125
125
  private handleSecondFactorSubmit;
126
- private handleTotpResend;
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 TOTP verification code.
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 TOTP */
19
+ /** Pending result when prompting for passkey registration after OTP */
20
20
  pendingResult: VerifyResult | null;
21
21
  }
22
22
  /**
23
- * TOTP-specific state
23
+ * OTP-specific state
24
24
  */
25
- interface TotpState {
26
- /** Current kindling token for TOTP verification */
25
+ interface OtpState {
26
+ /** Current kindling token for OTP verification */
27
27
  kindling: string;
28
- /** Current TOTP method (email, sms, or voice) */
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 _totp;
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 totp(): Readonly<TotpState>;
57
+ get otp(): Readonly<OtpState>;
58
58
  setKindling(kindling: string): void;
59
- setTotpMethod(method: 'email' | 'sms' | 'voice'): void;
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' | 'totp_email' | 'totp_sms' | 'totp_voice' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
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 = 'totp_email' | 'totp_sms' | 'totp_voice' | 'passkey' | 'sparklink' | 'social_google' | 'social_apple' | 'social_microsoft' | 'social_github' | 'social_facebook' | 'social_linkedin';
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: 'totp' | 'passkey' | 'sparklink' | 'social';
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 TotpSendResponse {
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 TotpVerifyResponse {
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: 'totp-verify';
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 TOTP code format.
55
+ * Validate OTP code format.
56
56
  * Returns sanitized code or null if invalid.
57
57
  */
58
- export declare function validateTotpCode(code: string): string | null;
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 './totp-verify';
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
- * TOTP Verification View
2
+ * OTP Verification View
3
3
  *
4
- * Collects and validates the 6-digit TOTP code sent via email, SMS, or voice.
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 TotpVerifyViewProps {
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 TotpVerifyView implements View {
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: TotpVerifyViewProps);
34
+ constructor(props: OtpVerifyViewProps);
35
35
  render(): HTMLElement;
36
36
  private createBackLink;
37
37
  private createInputGroup;
@@ -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, TOTP, SparkLink, social). */
11
+ /** Identity verification product (passkey, OTP, SparkLink, social). */
12
12
  readonly identity: IdentityModule;
13
13
  constructor(config: ResolvedConfig);
14
14
  }