@sparkvault/sdk-js 2.2.4 → 2.2.5
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/dist/identity/api.d.ts +37 -1
- package/dist/identity/handlers/totp-handler.d.ts +1 -1
- package/dist/identity/renderer.d.ts +49 -3
- package/dist/identity/state.d.ts +0 -17
- package/dist/identity/types.d.ts +53 -0
- package/dist/identity/views/backup-verify.d.ts +41 -0
- package/dist/identity/views/index.d.ts +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/sparkvault.cjs.js +416 -185
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +416 -185
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
package/dist/identity/api.d.ts
CHANGED
|
@@ -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, AuthContext, VerifyResult } from './types';
|
|
10
|
+
import type { SdkConfig, TotpSendResponse, TotpVerifyResponse, 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 */
|
|
@@ -104,6 +104,36 @@ export declare class IdentityApi extends SparkVaultApi {
|
|
|
104
104
|
credential: PublicKeyCredential;
|
|
105
105
|
authContext?: AuthContext;
|
|
106
106
|
}): Promise<PasskeyVerifyResponse>;
|
|
107
|
+
/**
|
|
108
|
+
* Send a one-time code to a new backup identifier (the inverse of the
|
|
109
|
+
* identifier just logged in with). Authorized by the login's verification
|
|
110
|
+
* token. Returns a pending-attach `session_id`, or `already_verified` when
|
|
111
|
+
* the identifier is already on the identity.
|
|
112
|
+
*/
|
|
113
|
+
sendBackupVerification(params: {
|
|
114
|
+
verificationToken: string;
|
|
115
|
+
type: 'email' | 'phone';
|
|
116
|
+
value: string;
|
|
117
|
+
method?: 'email' | 'sms' | 'voice';
|
|
118
|
+
}): Promise<BackupSendResponse>;
|
|
119
|
+
/**
|
|
120
|
+
* Confirm the backup-identifier code and attach it to the identity. A 409
|
|
121
|
+
* `backup_conflict` (identifier owned by another identity) surfaces as a
|
|
122
|
+
* thrown IdentityApiError with code `backup_conflict`.
|
|
123
|
+
*/
|
|
124
|
+
verifyBackupVerification(params: {
|
|
125
|
+
sessionId: string;
|
|
126
|
+
code: string;
|
|
127
|
+
}): Promise<BackupVerifyResponse>;
|
|
128
|
+
/**
|
|
129
|
+
* Skip a post-login recommendation, suppressing it server-side for 30 days.
|
|
130
|
+
* Authorized by the login's verification token. Best-effort — a failure here
|
|
131
|
+
* must not block completing the login.
|
|
132
|
+
*/
|
|
133
|
+
dismissRecommendation(params: {
|
|
134
|
+
verificationToken: string;
|
|
135
|
+
key: RecommendationKey;
|
|
136
|
+
}): Promise<void>;
|
|
107
137
|
/**
|
|
108
138
|
* Get OAuth redirect URL for social provider
|
|
109
139
|
*/
|
|
@@ -122,6 +152,12 @@ export declare class IdentityApi extends SparkVaultApi {
|
|
|
122
152
|
*/
|
|
123
153
|
consumeSparkLinkResult(kindling: string): Promise<VerifyResult | null>;
|
|
124
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Map the API's snake_case recommendation list to the SDK's typed shape,
|
|
157
|
+
* dropping any entries the SDK does not understand. Returns undefined when
|
|
158
|
+
* absent so callers treat it as "no nudges".
|
|
159
|
+
*/
|
|
160
|
+
export declare function mapRecommendations(raw: unknown): Recommendation[] | undefined;
|
|
125
161
|
export declare class IdentityApiError extends SparkVaultError {
|
|
126
162
|
constructor(message: string, code: string, statusCode: number, details?: Record<string, unknown>);
|
|
127
163
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Single responsibility: TOTP code sending and verification.
|
|
5
5
|
* Extracts TOTP logic from IdentityRenderer for better separation of concerns.
|
|
6
6
|
*/
|
|
7
|
-
import type
|
|
7
|
+
import { type IdentityApi } from '../api';
|
|
8
8
|
import type { VerifyResult } from '../types';
|
|
9
9
|
import type { VerificationState } from '../state';
|
|
10
10
|
/**
|
|
@@ -23,6 +23,8 @@ export declare class IdentityRenderer {
|
|
|
23
23
|
private readonly sparkLinkHandler;
|
|
24
24
|
private currentView;
|
|
25
25
|
private focusTimeoutId;
|
|
26
|
+
private postLoginResult;
|
|
27
|
+
private postLoginQueue;
|
|
26
28
|
private sparkLinkWs;
|
|
27
29
|
private sparkLinkKindling;
|
|
28
30
|
private sparkLinkVisibilityHandler;
|
|
@@ -135,16 +137,60 @@ export declare class IdentityRenderer {
|
|
|
135
137
|
*/
|
|
136
138
|
private handleErrorWithRecovery;
|
|
137
139
|
/**
|
|
138
|
-
*
|
|
140
|
+
* Run the post-login step pipeline for a completed primary login.
|
|
141
|
+
*
|
|
142
|
+
* The server returns an ordered `recommendations` list (passkey upsell,
|
|
143
|
+
* backup verification, …); this walks it, rendering the step views the SDK
|
|
144
|
+
* supports and finalizing when the queue drains. A redirect target skips the
|
|
145
|
+
* pipeline. A future nudge is one new recommendation type + view case — no
|
|
146
|
+
* primary-login handler changes.
|
|
147
|
+
*/
|
|
148
|
+
private runPostLogin;
|
|
149
|
+
/**
|
|
150
|
+
* Show the next supported recommendation, or finalize when the queue is
|
|
151
|
+
* empty. The single hand-off from each step back into the pipeline.
|
|
152
|
+
*/
|
|
153
|
+
private advancePostLogin;
|
|
154
|
+
/**
|
|
155
|
+
* Best-effort: tell the server the person skipped a recommendation so it is
|
|
156
|
+
* suppressed for 30 days. Never blocks completing the login.
|
|
157
|
+
*/
|
|
158
|
+
private dismissRecommendation;
|
|
159
|
+
/**
|
|
160
|
+
* Complete the login: hand the result to the host before tearing down the
|
|
161
|
+
* modal (so its onSuccess can act while the browsing context is alive), then
|
|
162
|
+
* navigate any redirect the flow returned.
|
|
163
|
+
*/
|
|
164
|
+
private finalizeLogin;
|
|
165
|
+
/**
|
|
166
|
+
* Send a code to the new backup identifier the person entered. Already-attached
|
|
167
|
+
* identifiers short-circuit straight to completion; otherwise advance to code
|
|
168
|
+
* entry.
|
|
169
|
+
*/
|
|
170
|
+
private handleBackupSubmit;
|
|
171
|
+
/**
|
|
172
|
+
* Verify the backup code and attach the identifier, then finish the original
|
|
173
|
+
* login. An identifier owned by another account (409 backup_conflict) bounces
|
|
174
|
+
* back to the input so the person can try a different one.
|
|
175
|
+
*/
|
|
176
|
+
private handleBackupCodeSubmit;
|
|
177
|
+
/**
|
|
178
|
+
* Resend the backup code, refreshing the pending-attach session.
|
|
179
|
+
*/
|
|
180
|
+
private handleBackupResend;
|
|
181
|
+
/**
|
|
182
|
+
* "Not now" on the backup prompt: suppress this identifier type for 30 days
|
|
183
|
+
* (server-side) and advance to the next step.
|
|
139
184
|
*/
|
|
140
|
-
private
|
|
185
|
+
private handleBackupSkip;
|
|
141
186
|
/**
|
|
142
187
|
* Handle user clicking "Add Passkey" in the prompt.
|
|
143
188
|
* Directly triggers browser passkey creation without intermediate screen.
|
|
144
189
|
*/
|
|
145
190
|
private handlePasskeyPromptAdd;
|
|
146
191
|
/**
|
|
147
|
-
* Handle user clicking "Not now" / "Skip" in the prompt
|
|
192
|
+
* Handle user clicking "Not now" / "Skip" in the passkey prompt: suppress it
|
|
193
|
+
* for 30 days (server-side) and advance to the next step.
|
|
148
194
|
*/
|
|
149
195
|
private handlePasskeyPromptSkip;
|
|
150
196
|
/**
|
package/dist/identity/state.d.ts
CHANGED
|
@@ -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;
|
package/dist/identity/types.d.ts
CHANGED
|
@@ -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;
|
|
@@ -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';
|
package/dist/index.d.ts
CHANGED
|
@@ -144,6 +144,16 @@ interface AttachOptions {
|
|
|
144
144
|
/** Called on error */
|
|
145
145
|
onError?: (error: Error) => void;
|
|
146
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* A server-decided post-login nudge. Computed once per login (default mode);
|
|
149
|
+
* clients render the steps they support, in order, before completing.
|
|
150
|
+
*/
|
|
151
|
+
type Recommendation = {
|
|
152
|
+
type: 'passkey';
|
|
153
|
+
} | {
|
|
154
|
+
type: 'backup_identifier';
|
|
155
|
+
missingType: 'email' | 'phone';
|
|
156
|
+
};
|
|
147
157
|
interface VerifyResult {
|
|
148
158
|
/** Signed JWT token */
|
|
149
159
|
token: string;
|
|
@@ -159,6 +169,8 @@ interface VerifyResult {
|
|
|
159
169
|
refreshToken?: string;
|
|
160
170
|
/** Redirect URL (only present for OIDC/simple mode flows) */
|
|
161
171
|
redirect?: string;
|
|
172
|
+
/** Ordered post-login nudges (default-mode logins only). */
|
|
173
|
+
recommendations?: Recommendation[];
|
|
162
174
|
}
|
|
163
175
|
interface TokenClaims {
|
|
164
176
|
/** Issuer */
|