@sparkvault/sdk-js 2.2.4 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/auto-init.d.ts +1 -1
  2. package/dist/entropy/index.d.ts +28 -0
  3. package/dist/entropy/types.d.ts +32 -0
  4. package/dist/folders/index.d.ts +77 -0
  5. package/dist/folders/types.d.ts +64 -0
  6. package/dist/http.d.ts +3 -1
  7. package/dist/index.d.ts +994 -78
  8. package/dist/ingots/index.d.ts +183 -0
  9. package/dist/ingots/types.d.ts +286 -0
  10. package/dist/{identity → products/identity}/api.d.ts +40 -4
  11. package/dist/{identity → products/identity}/embedder.d.ts +1 -1
  12. package/dist/{identity → products/identity}/handlers/totp-handler.d.ts +1 -1
  13. package/dist/{identity → products/identity}/index.d.ts +7 -7
  14. package/dist/{identity → products/identity}/renderer.d.ts +49 -3
  15. package/dist/{identity → products/identity}/state.d.ts +0 -17
  16. package/dist/{identity → products/identity}/types.d.ts +53 -0
  17. package/dist/{identity → products/identity}/utils.d.ts +1 -1
  18. package/dist/products/identity/views/backup-verify.d.ts +41 -0
  19. package/dist/{identity → products/identity}/views/index.d.ts +1 -0
  20. package/dist/products/index.d.ts +18 -0
  21. package/dist/sparks/index.d.ts +65 -0
  22. package/dist/sparks/types.d.ts +174 -0
  23. package/dist/sparkvault.cjs.js +1573 -366
  24. package/dist/sparkvault.cjs.js.map +1 -1
  25. package/dist/sparkvault.esm.js +1567 -367
  26. package/dist/sparkvault.esm.js.map +1 -1
  27. package/dist/sparkvault.js +1 -1
  28. package/dist/sparkvault.js.map +1 -1
  29. package/dist/vaults/index.d.ts +102 -34
  30. package/dist/vaults/types.d.ts +121 -57
  31. package/dist/vaults/upload/api.d.ts +1 -1
  32. package/package.json +1 -1
  33. /package/dist/{identity → products/identity}/container.d.ts +0 -0
  34. /package/dist/{identity → products/identity}/handlers/index.d.ts +0 -0
  35. /package/dist/{identity → products/identity}/handlers/passkey-handler.d.ts +0 -0
  36. /package/dist/{identity → products/identity}/handlers/sparklink-handler.d.ts +0 -0
  37. /package/dist/{identity → products/identity}/inline-container.d.ts +0 -0
  38. /package/dist/{identity → products/identity}/methods.d.ts +0 -0
  39. /package/dist/{identity → products/identity}/modal.d.ts +0 -0
  40. /package/dist/{identity → products/identity}/styles.d.ts +0 -0
  41. /package/dist/{identity → products/identity}/utils/cooldown-timer.d.ts +0 -0
  42. /package/dist/{identity → products/identity}/utils/index.d.ts +0 -0
  43. /package/dist/{identity → products/identity}/views/base.d.ts +0 -0
  44. /package/dist/{identity → products/identity}/views/error.d.ts +0 -0
  45. /package/dist/{identity → products/identity}/views/icons.d.ts +0 -0
  46. /package/dist/{identity → products/identity}/views/identity-input.d.ts +0 -0
  47. /package/dist/{identity → products/identity}/views/loading.d.ts +0 -0
  48. /package/dist/{identity → products/identity}/views/method-select.d.ts +0 -0
  49. /package/dist/{identity → products/identity}/views/origin-not-allowed.d.ts +0 -0
  50. /package/dist/{identity → products/identity}/views/passkey-prompt.d.ts +0 -0
  51. /package/dist/{identity → products/identity}/views/passkey.d.ts +0 -0
  52. /package/dist/{identity → products/identity}/views/product-not-configured.d.ts +0 -0
  53. /package/dist/{identity → products/identity}/views/service-unavailable.d.ts +0 -0
  54. /package/dist/{identity → products/identity}/views/sparklink-waiting.d.ts +0 -0
  55. /package/dist/{identity → products/identity}/views/totp-verify.d.ts +0 -0
  56. /package/dist/{identity → products/identity}/views/two-factor.d.ts +0 -0
@@ -42,10 +42,6 @@ export declare class VerificationState {
42
42
  get sdkConfig(): SdkConfig | null;
43
43
  setConfig(config: SdkConfig): void;
44
44
  get accountId(): string;
45
- /**
46
- * Check if passkey method is enabled in config
47
- */
48
- isPasskeyEnabled(): boolean;
49
45
  get viewState(): IdentityViewState;
50
46
  setViewState(state: IdentityViewState): void;
51
47
  get recipient(): string;
@@ -58,19 +54,6 @@ export declare class VerificationState {
58
54
  setPasskeyStatus(hasPasskey: boolean | null): void;
59
55
  enablePasskeyFallback(): void;
60
56
  setPendingResult(result: VerifyResult | null): void;
61
- /**
62
- * Check if we should show passkey registration prompt
63
- * Based on: passkey enabled, the current SVID doesn't have one, not dismissed
64
- */
65
- shouldShowPasskeyPrompt(): boolean;
66
- /**
67
- * Check if passkey prompt was dismissed (30-day cookie)
68
- */
69
- private isPasskeyPromptDismissed;
70
- /**
71
- * Dismiss passkey prompt for 30 days
72
- */
73
- dismissPasskeyPrompt(): void;
74
57
  get totp(): Readonly<TotpState>;
75
58
  setKindling(kindling: string): void;
76
59
  setTotpMethod(method: 'email' | 'sms' | 'voice'): void;
@@ -79,6 +79,18 @@ export interface AttachOptions {
79
79
  /** Called on error */
80
80
  onError?: (error: Error) => void;
81
81
  }
82
+ /**
83
+ * A server-decided post-login nudge. Computed once per login (default mode);
84
+ * clients render the steps they support, in order, before completing.
85
+ */
86
+ export type Recommendation = {
87
+ type: 'passkey';
88
+ } | {
89
+ type: 'backup_identifier';
90
+ missingType: 'email' | 'phone';
91
+ };
92
+ /** Canonical dismiss key for a recommendation (suppresses it server-side 30d). */
93
+ export type RecommendationKey = 'passkey' | 'backup_email' | 'backup_phone';
82
94
  export interface VerifyResult {
83
95
  /** Signed JWT token */
84
96
  token: string;
@@ -94,6 +106,13 @@ export interface VerifyResult {
94
106
  refreshToken?: string;
95
107
  /** Redirect URL (only present for OIDC/simple mode flows) */
96
108
  redirect?: string;
109
+ /** Ordered post-login nudges (default-mode logins only). */
110
+ recommendations?: Recommendation[];
111
+ }
112
+ /** Raw recommendation as the API returns it (snake_case). */
113
+ export interface RawRecommendation {
114
+ type: string;
115
+ missing_type?: 'email' | 'phone' | null;
97
116
  }
98
117
  export interface TokenClaims {
99
118
  /** Issuer */
@@ -195,6 +214,25 @@ export interface TotpVerifyResponse {
195
214
  ticket?: string;
196
215
  /** Second-factor methods the user can use, e.g. ['authenticator','recovery_code'] */
197
216
  methods?: string[];
217
+ /** Backup-identifier nudge hint (snake_case from the API). */
218
+ recommendations?: RawRecommendation[];
219
+ }
220
+ /** Response to POST /backup-verification/send. */
221
+ export interface BackupSendResponse {
222
+ /** Opaque pending-attach session id (present when a code was sent). */
223
+ session_id?: string;
224
+ /** Delivery channel actually used. */
225
+ method?: 'email' | 'sms' | 'voice';
226
+ /** Code expiry (Unix seconds). */
227
+ expires_at?: number;
228
+ /** True when the identifier is already on the identity — no code was sent. */
229
+ already_verified?: boolean;
230
+ }
231
+ /** Response to POST /backup-verification/verify. */
232
+ export interface BackupVerifyResponse {
233
+ verified: boolean;
234
+ type: 'email' | 'phone';
235
+ value: string;
198
236
  }
199
237
  export interface PasskeyChallengeResponse {
200
238
  challenge: string;
@@ -233,6 +271,8 @@ export interface SecondFactorVerifyResponse {
233
271
  refresh_token?: string;
234
272
  /** Redirect URL the caller should navigate to. */
235
273
  redirect?: string;
274
+ /** Backup-identifier nudge hint (snake_case from the API). */
275
+ recommendations?: RawRecommendation[];
236
276
  }
237
277
  export interface SparkLinkSendResponse {
238
278
  sparkId: string;
@@ -271,6 +311,19 @@ export type IdentityViewState = {
271
311
  recipient: string;
272
312
  pendingResult: VerifyResult;
273
313
  error?: string;
314
+ } | {
315
+ view: 'backup-verify';
316
+ missingType: 'email' | 'phone';
317
+ pendingResult: VerifyResult;
318
+ error?: string;
319
+ } | {
320
+ view: 'backup-code';
321
+ missingType: 'email' | 'phone';
322
+ value: string;
323
+ method: 'email' | 'sms' | 'voice';
324
+ sessionId: string;
325
+ pendingResult: VerifyResult;
326
+ error?: string;
274
327
  } | {
275
328
  view: 'sparklink-waiting';
276
329
  email: string;
@@ -6,7 +6,7 @@
6
6
  */
7
7
  export { CooldownTimer, ExpirationTimer } from './utils/cooldown-timer';
8
8
  export type { CooldownTimerConfig, ExpirationTimerConfig } from './utils/cooldown-timer';
9
- export { arrayBufferToBase64url, base64urlToArrayBuffer, base64urlToString, } from '../utils/base64url';
9
+ export { arrayBufferToBase64url, base64urlToArrayBuffer, base64urlToString, } from '../../utils/base64url';
10
10
  /**
11
11
  * Extract the root (registrable) domain from a hostname for cross-subdomain cookies.
12
12
  * Returns the domain prefixed with a dot (e.g., ".client.com") or null when
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Backup Verification Input View
3
+ *
4
+ * Post-login nudge to add the inverse identifier as a recovery backup:
5
+ * collects a new phone (for an email login) or email (for a phone login),
6
+ * then hands it off to send a one-time code. Includes a "Not now" skip that
7
+ * suppresses this method's prompt for 30 days (handled by the renderer).
8
+ *
9
+ * Sibling of PasskeyPromptView — same low-friction, skippable shape.
10
+ */
11
+ import type { View } from './base';
12
+ export interface BackupVerifyViewProps {
13
+ /** Which identifier to collect — the inverse of what they logged in with. */
14
+ missingType: 'email' | 'phone';
15
+ /** Submit the validated identifier to send a code. */
16
+ onSubmit: (value: string) => void;
17
+ /** Skip ("Not now") — suppresses this method for 30 days. */
18
+ onSkip: () => void;
19
+ /** Error to display (e.g. send failed, or identifier already in use). */
20
+ error?: string;
21
+ }
22
+ export declare class BackupVerifyView implements View {
23
+ private readonly props;
24
+ private inputElement;
25
+ private submitButton;
26
+ private skipLink;
27
+ private errorContainer;
28
+ private focusTimeoutId;
29
+ private readonly boundHandleInput;
30
+ private readonly boundHandleKeyDown;
31
+ private readonly boundHandleSubmit;
32
+ private readonly boundHandleSkip;
33
+ constructor(props: BackupVerifyViewProps);
34
+ private get isPhone();
35
+ render(): HTMLElement;
36
+ private handleInput;
37
+ private clearError;
38
+ private showError;
39
+ private handleSubmit;
40
+ destroy(): void;
41
+ }
@@ -11,6 +11,7 @@ export * from './totp-verify';
11
11
  export * from './two-factor';
12
12
  export * from './passkey';
13
13
  export * from './passkey-prompt';
14
+ export * from './backup-verify';
14
15
  export * from './sparklink-waiting';
15
16
  export * from './error';
16
17
  export * from './service-unavailable';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Products Module
3
+ *
4
+ * Namespace for SparkVault first-party products. Each product is a
5
+ * self-contained surface (UI + API) the account can enable independently.
6
+ * Currently exposes `identity`; future products attach here alongside it.
7
+ */
8
+ import type { ResolvedConfig } from '../config';
9
+ import { IdentityModule } from './identity';
10
+ export declare class ProductsModule {
11
+ /** Identity verification product (passkey, TOTP, SparkLink, social). */
12
+ readonly identity: IdentityModule;
13
+ constructor(config: ResolvedConfig);
14
+ }
15
+ export { IdentityModule } from './identity';
16
+ export type { VerifyOptions, AttachOptions, VerifyResult, TokenClaims, AuthMethod, AuthContext, Theme, SdkConfig, SdkConfigBranding, MethodId, MethodMetadata, } from './identity';
17
+ export { METHOD_REGISTRY, getMethodMetadata, enrichMethods } from './identity';
18
+ export { IdentityApi, IdentityApiError } from './identity';
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Sparks Module
3
+ *
4
+ * Create, read, share, and delete end-to-end encrypted, read-once ephemeral
5
+ * secrets. Sparks are account-scoped — no vault or VAT is involved.
6
+ */
7
+ import { HttpClient } from '../http';
8
+ import type { Spark, CreatedSpark, ListSparksOptions, SparkPage, CreateSparkOptions, ShareSparkOptions, SparkShare } from './types';
9
+ export declare class SparksModule {
10
+ private readonly http;
11
+ constructor(http: HttpClient);
12
+ /**
13
+ * List sparks for the account.
14
+ *
15
+ * @example
16
+ * const { sparks } = await sv.sparks.list();
17
+ */
18
+ list(options?: ListSparksOptions): Promise<SparkPage>;
19
+ /**
20
+ * Read (and burn) a spark. Reading is destructive — the spark can be read
21
+ * exactly once.
22
+ *
23
+ * @example
24
+ * const spark = await sv.sparks.get('spk_abc');
25
+ * console.log(spark.payload);
26
+ */
27
+ get(sparkId: string): Promise<Spark>;
28
+ /**
29
+ * Create a spark.
30
+ *
31
+ * @example
32
+ * const spark = await sv.sparks.create({ payload: 'top secret', ttlMinutes: 60 });
33
+ */
34
+ create(options: CreateSparkOptions): Promise<CreatedSpark>;
35
+ /**
36
+ * Delete a spark.
37
+ *
38
+ * @example
39
+ * await sv.sparks.delete('spk_abc');
40
+ */
41
+ delete(sparkId: string): Promise<void>;
42
+ /**
43
+ * Share a spark via a public SparkLink (x.sv URL).
44
+ *
45
+ * @example
46
+ * const share = await sv.sparks.share('spk_abc', { visibility: 'public' });
47
+ * console.log(share.shareUrl);
48
+ */
49
+ share(sparkId: string, options?: ShareSparkOptions): Promise<SparkShare>;
50
+ /**
51
+ * Get a spark's sharing status.
52
+ *
53
+ * @example
54
+ * const share = await sv.sparks.getShare('spk_abc');
55
+ */
56
+ getShare(sparkId: string): Promise<SparkShare>;
57
+ /**
58
+ * Unshare a spark (delete its SparkLink).
59
+ *
60
+ * @example
61
+ * await sv.sparks.unshare('spk_abc');
62
+ */
63
+ unshare(sparkId: string): Promise<SparkShare>;
64
+ }
65
+ export type { SparkSummary, Spark, CreatedSpark, ListSparksOptions, SparkPage, CreateSparkOptions, ShareSparkOptions, SparkShare, SparkVisibility, } from './types';
@@ -0,0 +1,174 @@
1
+ /**
2
+ * Sparks Module Types
3
+ *
4
+ * Sparks are end-to-end encrypted, read-once ephemeral secrets scoped to the
5
+ * account (no vault/VAT). Public domain objects are camelCase; wire shapes
6
+ * (snake_case) stay private to the module.
7
+ */
8
+ /** A spark summary as returned by list. */
9
+ export interface SparkSummary {
10
+ /** Spark ID */
11
+ id: string;
12
+ /** Content type (MIME) */
13
+ contentType: string;
14
+ /** Size in bytes */
15
+ size: number;
16
+ /** Lifecycle status (active | expired | ash) */
17
+ status: string;
18
+ /** Creation timestamp (Unix seconds) */
19
+ createdAt: number;
20
+ /** Expiry timestamp (Unix seconds) */
21
+ expiresAt: number;
22
+ /** Burn timestamp (Unix seconds), or null if not yet read */
23
+ burnedAt: number | null;
24
+ /** Seconds remaining until expiry */
25
+ timeRemaining: number;
26
+ /** Optional file name (for file payloads) */
27
+ filename?: string;
28
+ /** Optional kindling family ID */
29
+ kindling?: string;
30
+ }
31
+ /** The decrypted spark, returned by get (reading burns it). */
32
+ export interface Spark {
33
+ /** Spark ID */
34
+ id: string;
35
+ /** Decrypted payload (text, or base64 for binary content types) */
36
+ payload: string;
37
+ /** Content type (MIME) */
38
+ contentType: string;
39
+ /** Size in bytes */
40
+ size: number;
41
+ /** Lifecycle status after the read (ash) */
42
+ status: string;
43
+ /** Creation timestamp (Unix seconds) */
44
+ createdAt: number;
45
+ /** Burn timestamp (Unix seconds) */
46
+ burnedAt: number;
47
+ /** Optional file name (for file payloads) */
48
+ filename?: string;
49
+ }
50
+ /** A newly created spark. */
51
+ export interface CreatedSpark {
52
+ /** Spark ID */
53
+ id: string;
54
+ /** Size in bytes */
55
+ size: number;
56
+ /** Lifecycle status (active) */
57
+ status: string;
58
+ /** Creation timestamp (Unix seconds) */
59
+ createdAt: number;
60
+ /** Expiry timestamp (Unix seconds) */
61
+ expiresAt: number;
62
+ /** Time-to-live in minutes */
63
+ ttlMinutes: number;
64
+ /** Optional file name (echoed when provided) */
65
+ filename?: string;
66
+ /** Optional kindling family ID (echoed when provided) */
67
+ kindling?: string;
68
+ }
69
+ /** Options for list. */
70
+ export interface ListSparksOptions {
71
+ /** Filter to a kindling family */
72
+ kindling?: string;
73
+ /** Filter by status */
74
+ status?: string;
75
+ /** Page size */
76
+ limit?: number;
77
+ /** Pagination cursor */
78
+ cursor?: string;
79
+ }
80
+ /** A page of sparks. */
81
+ export interface SparkPage {
82
+ /** Sparks on this page */
83
+ sparks: SparkSummary[];
84
+ /** Cursor for the next page, when more results exist */
85
+ nextCursor?: string;
86
+ }
87
+ /** Options for create. */
88
+ export interface CreateSparkOptions {
89
+ /** Payload (text, or base64 for binary content types) */
90
+ payload: string;
91
+ /** Content type (MIME). Defaults to text/plain. */
92
+ contentType?: string;
93
+ /** Time-to-live in minutes. Defaults to 1440 (24h). */
94
+ ttlMinutes?: number;
95
+ /** Join an existing kindling family by ID */
96
+ kindling?: string;
97
+ /** Generate a new kindling family for this spark */
98
+ withKindling?: boolean;
99
+ /** Optional file name (for file payloads) */
100
+ filename?: string;
101
+ }
102
+ /** Visibility mode for a shared spark. */
103
+ export type SparkVisibility = 'public' | 'authenticated' | 'invite_only';
104
+ /** Options for share. */
105
+ export interface ShareSparkOptions {
106
+ /** Visibility mode. Defaults to public. */
107
+ visibility?: SparkVisibility;
108
+ /** Invited identities (emails/phones) */
109
+ invites?: string[];
110
+ /** Link lifetime in seconds */
111
+ expiresInSeconds?: number;
112
+ }
113
+ /** The result of sharing a spark. */
114
+ export interface SparkShare {
115
+ /** Whether the spark is shared */
116
+ shared: boolean;
117
+ /** Public share URL (x.sv link) */
118
+ shareUrl?: string;
119
+ /** Short link code */
120
+ linkCode?: string;
121
+ /** Visibility mode */
122
+ visibility?: SparkVisibility;
123
+ /** Invited identities */
124
+ invites?: string[];
125
+ /** Link expiry timestamp (Unix seconds) */
126
+ expiresAt?: number;
127
+ /** Link creation timestamp (Unix seconds) */
128
+ createdAt?: number;
129
+ }
130
+ export interface SparkSummaryWire {
131
+ spark_id: string;
132
+ content_type?: string;
133
+ size_bytes: number;
134
+ status: string;
135
+ created_at: number;
136
+ expires_at: number;
137
+ burned_at?: number | null;
138
+ time_remaining?: number;
139
+ filename?: string;
140
+ kindling?: string;
141
+ }
142
+ export interface ListSparksResponse {
143
+ sparks: SparkSummaryWire[];
144
+ next_cursor?: string;
145
+ }
146
+ export interface SparkResponse {
147
+ spark_id: string;
148
+ payload: string;
149
+ content_type?: string;
150
+ size_bytes: number;
151
+ status: string;
152
+ created_at: number;
153
+ burned_at: number;
154
+ filename?: string;
155
+ }
156
+ export interface CreateSparkResponse {
157
+ spark_id: string;
158
+ size_bytes: number;
159
+ status: string;
160
+ created_at: number;
161
+ expires_at: number;
162
+ ttl_minutes: number;
163
+ filename?: string;
164
+ kindling?: string;
165
+ }
166
+ export interface SparkShareResponse {
167
+ shared: boolean;
168
+ share_url?: string;
169
+ link_code?: string;
170
+ visibility?: SparkVisibility;
171
+ invites?: string[];
172
+ expires_at?: number;
173
+ created_at?: number;
174
+ }