@sparkvault/sdk-js 8.1.2 → 8.3.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.
- package/README.md +34 -33
- package/dist/config.d.ts +1 -1
- package/dist/index.d.ts +38 -33
- package/dist/products/identity/index.d.ts +30 -33
- package/dist/products/identity/types.d.ts +8 -0
- package/dist/sparkvault.cjs.js +158 -72
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +158 -72
- 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/README.md
CHANGED
|
@@ -95,7 +95,7 @@ update by pointing at the next `version.json` entry.
|
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
The script auto-initializes `SparkVault` with your account ID. Use
|
|
98
|
-
`SparkVault.products.identity.attach()` or `SparkVault.products.identity.
|
|
98
|
+
`SparkVault.products.identity.attach()` or `SparkVault.products.identity.signIn()` to open the
|
|
99
99
|
verification UI and handle the result.
|
|
100
100
|
|
|
101
101
|
### Data Attributes
|
|
@@ -139,7 +139,7 @@ verification UI and handle the result.
|
|
|
139
139
|
|
|
140
140
|
### Verification Result
|
|
141
141
|
|
|
142
|
-
The SDK returns this shape from `products.identity.
|
|
142
|
+
The SDK returns this shape from `products.identity.signIn()` and
|
|
143
143
|
`products.identity.attach()` callbacks:
|
|
144
144
|
|
|
145
145
|
```json
|
|
@@ -161,12 +161,12 @@ You can also trigger authentication programmatically using the `SparkVault` glob
|
|
|
161
161
|
|
|
162
162
|
```javascript
|
|
163
163
|
// Trigger authentication from anywhere in your code
|
|
164
|
-
const result = await SparkVault.identity.
|
|
164
|
+
const result = await SparkVault.products.identity.signIn();
|
|
165
165
|
await sendTokenToBackend(result.token);
|
|
166
166
|
```
|
|
167
167
|
|
|
168
168
|
```html
|
|
169
|
-
<button onclick="SparkVault.identity.
|
|
169
|
+
<button onclick="SparkVault.products.identity.signIn()">
|
|
170
170
|
Sign In with SparkVault
|
|
171
171
|
</button>
|
|
172
172
|
```
|
|
@@ -183,7 +183,7 @@ const sparkvault = SparkVault.init({
|
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
// The SDK is now ready to use
|
|
186
|
-
const result = await sparkvault.identity.
|
|
186
|
+
const result = await sparkvault.products.identity.signIn();
|
|
187
187
|
```
|
|
188
188
|
|
|
189
189
|
### Configuration Options
|
|
@@ -192,7 +192,7 @@ const result = await sparkvault.identity.pop();
|
|
|
192
192
|
|--------|------|---------|-------------|
|
|
193
193
|
| `accountId` | `string` | **required** | Your SparkVault account ID (starts with `acc_`) |
|
|
194
194
|
| `timeout` | `number` | `30000` | HTTP request timeout in milliseconds |
|
|
195
|
-
| `preloadConfig` | `boolean` | `true` | Preload Identity config for instant
|
|
195
|
+
| `preloadConfig` | `boolean` | `true` | Preload Identity config for instant popup |
|
|
196
196
|
|
|
197
197
|
### CDN Usage
|
|
198
198
|
|
|
@@ -204,7 +204,7 @@ const result = await sparkvault.identity.pop();
|
|
|
204
204
|
});
|
|
205
205
|
|
|
206
206
|
document.getElementById('login-btn').addEventListener('click', async () => {
|
|
207
|
-
const result = await sparkvault.identity.
|
|
207
|
+
const result = await sparkvault.products.identity.signIn();
|
|
208
208
|
console.log('Verified:', result.identity);
|
|
209
209
|
});
|
|
210
210
|
</script>
|
|
@@ -212,13 +212,13 @@ const result = await sparkvault.identity.pop();
|
|
|
212
212
|
|
|
213
213
|
## Identity Verification
|
|
214
214
|
|
|
215
|
-
The Identity module provides passwordless authentication through a
|
|
215
|
+
The Identity module provides passwordless authentication through a first-party SparkVault popup. Users can sign in via passkeys, email codes, SMS codes, SparkLink, or social providers.
|
|
216
216
|
|
|
217
217
|
### Basic Usage
|
|
218
218
|
|
|
219
219
|
```javascript
|
|
220
|
-
// Open the
|
|
221
|
-
const result = await sparkvault.identity.
|
|
220
|
+
// Open the sign-in popup
|
|
221
|
+
const result = await sparkvault.products.identity.signIn();
|
|
222
222
|
|
|
223
223
|
// User verified!
|
|
224
224
|
console.log(result.identity); // "user@example.com" or "+14155551234"
|
|
@@ -233,18 +233,18 @@ await fetch('/api/auth/login', {
|
|
|
233
233
|
});
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
-
###
|
|
236
|
+
### signIn() Options
|
|
237
237
|
|
|
238
238
|
| Option | Type | Description |
|
|
239
239
|
|--------|------|-------------|
|
|
240
240
|
| `email` | `string` | Pre-fill email address (mutually exclusive with phone) |
|
|
241
241
|
| `phone` | `string` | Pre-fill phone in E.164 format, e.g. `"+14155551234"` |
|
|
242
242
|
| `backdropBlur` | `boolean` | Override backdrop blur setting from app config |
|
|
243
|
-
| `onCancel` | `function` | Callback when
|
|
243
|
+
| `onCancel` | `function` | Callback when the person closes the popup without signing in |
|
|
244
244
|
| `onSuccess` | `function` | Callback on success (before promise resolves) |
|
|
245
245
|
| `onError` | `function` | Callback on error (before promise rejects) |
|
|
246
246
|
|
|
247
|
-
###
|
|
247
|
+
### signIn() Result
|
|
248
248
|
|
|
249
249
|
| Field | Type | Description |
|
|
250
250
|
|-------|------|-------------|
|
|
@@ -259,7 +259,7 @@ await fetch('/api/auth/login', {
|
|
|
259
259
|
|
|
260
260
|
```javascript
|
|
261
261
|
try {
|
|
262
|
-
const result = await sparkvault.identity.
|
|
262
|
+
const result = await sparkvault.products.identity.signIn({
|
|
263
263
|
// Pre-fill the email field
|
|
264
264
|
email: 'user@example.com',
|
|
265
265
|
|
|
@@ -274,7 +274,7 @@ try {
|
|
|
274
274
|
|
|
275
275
|
} catch (error) {
|
|
276
276
|
if (error.code === 'user_cancelled') {
|
|
277
|
-
//
|
|
277
|
+
// Person closed the popup
|
|
278
278
|
} else {
|
|
279
279
|
// Handle other errors
|
|
280
280
|
console.error('Verification failed:', error.message);
|
|
@@ -310,7 +310,7 @@ Authentication methods are configured in your Identity Product settings. The SDK
|
|
|
310
310
|
import * as jose from 'jose';
|
|
311
311
|
|
|
312
312
|
const ACCOUNT_ID = 'acc_YOUR_ACCOUNT_ID';
|
|
313
|
-
const IDENTITY_URL = 'https://
|
|
313
|
+
const IDENTITY_URL = 'https://auth.sparkvault.com';
|
|
314
314
|
|
|
315
315
|
app.post('/api/auth/login', async (req, res) => {
|
|
316
316
|
const { token } = req.body;
|
|
@@ -348,7 +348,7 @@ import jwt
|
|
|
348
348
|
from jwt import PyJWKClient
|
|
349
349
|
|
|
350
350
|
ACCOUNT_ID = 'acc_YOUR_ACCOUNT_ID'
|
|
351
|
-
IDENTITY_URL = 'https://
|
|
351
|
+
IDENTITY_URL = 'https://auth.sparkvault.com'
|
|
352
352
|
|
|
353
353
|
def verify_identity_token(token: str):
|
|
354
354
|
"""Verify a SparkVault Identity token and return the claims."""
|
|
@@ -403,7 +403,7 @@ import (
|
|
|
403
403
|
|
|
404
404
|
const (
|
|
405
405
|
AccountID = "acc_YOUR_ACCOUNT_ID"
|
|
406
|
-
IdentityURL = "https://
|
|
406
|
+
IdentityURL = "https://auth.sparkvault.com"
|
|
407
407
|
)
|
|
408
408
|
|
|
409
409
|
func verifyToken(tokenString string) (jwt.Token, error) {
|
|
@@ -458,7 +458,7 @@ require 'net/http'
|
|
|
458
458
|
require 'json'
|
|
459
459
|
|
|
460
460
|
ACCOUNT_ID = 'acc_YOUR_ACCOUNT_ID'
|
|
461
|
-
IDENTITY_URL = 'https://
|
|
461
|
+
IDENTITY_URL = 'https://auth.sparkvault.com'
|
|
462
462
|
|
|
463
463
|
def verify_identity_token(token)
|
|
464
464
|
jwks_url = "#{IDENTITY_URL}/#{ACCOUNT_ID}/.well-known/jwks.json"
|
|
@@ -506,7 +506,7 @@ When decoded, the JWT token contains these claims:
|
|
|
506
506
|
|
|
507
507
|
```json
|
|
508
508
|
{
|
|
509
|
-
"iss": "https://
|
|
509
|
+
"iss": "https://auth.sparkvault.com/acc_xxx",
|
|
510
510
|
"sub": "ing_019e66a4e27875f2822ede0e4f5d8792",
|
|
511
511
|
"aud": "acc_xxx",
|
|
512
512
|
"svid": "ing_019e66a4e27875f2822ede0e4f5d8792",
|
|
@@ -580,8 +580,8 @@ function useSparkVaultAuth() {
|
|
|
580
580
|
setError(null);
|
|
581
581
|
|
|
582
582
|
try {
|
|
583
|
-
// Open
|
|
584
|
-
const result = await sparkvault.identity.
|
|
583
|
+
// Open the sign-in popup
|
|
584
|
+
const result = await sparkvault.products.identity.signIn(options);
|
|
585
585
|
|
|
586
586
|
// Send token to backend
|
|
587
587
|
const response = await fetch('/api/auth/login', {
|
|
@@ -651,11 +651,11 @@ import SparkVault, {
|
|
|
651
651
|
} from '@sparkvault/sdk-js';
|
|
652
652
|
|
|
653
653
|
try {
|
|
654
|
-
const result = await sparkvault.identity.
|
|
654
|
+
const result = await sparkvault.products.identity.signIn();
|
|
655
655
|
} catch (error) {
|
|
656
656
|
switch (error.code) {
|
|
657
657
|
case 'user_cancelled':
|
|
658
|
-
//
|
|
658
|
+
// Person closed the popup — not necessarily an error
|
|
659
659
|
console.log('User cancelled verification');
|
|
660
660
|
break;
|
|
661
661
|
|
|
@@ -689,7 +689,7 @@ try {
|
|
|
689
689
|
|
|
690
690
|
| Error Class | Code | Description |
|
|
691
691
|
|-------------|------|-------------|
|
|
692
|
-
| `UserCancelledError` | `user_cancelled` |
|
|
692
|
+
| `UserCancelledError` | `user_cancelled` | Person closed the popup without completing sign-in |
|
|
693
693
|
| `ValidationError` | `validation_error` | Invalid input or configuration |
|
|
694
694
|
| `NetworkError` | `network_error` | Network connectivity failure |
|
|
695
695
|
| `TimeoutError` | `timeout_error` | Request exceeded timeout limit |
|
|
@@ -706,8 +706,8 @@ import SparkVault, {
|
|
|
706
706
|
SparkVaultConfig,
|
|
707
707
|
|
|
708
708
|
// Identity types
|
|
709
|
-
|
|
710
|
-
|
|
709
|
+
SignInOptions,
|
|
710
|
+
SignInResult,
|
|
711
711
|
TokenClaims,
|
|
712
712
|
|
|
713
713
|
// Error types
|
|
@@ -728,12 +728,12 @@ const config: SparkVaultConfig = {
|
|
|
728
728
|
const sparkvault = SparkVault.init(config);
|
|
729
729
|
|
|
730
730
|
// Fully typed options and result
|
|
731
|
-
const options:
|
|
731
|
+
const options: SignInOptions = {
|
|
732
732
|
email: 'user@example.com',
|
|
733
733
|
onCancel: () => console.log('Cancelled'),
|
|
734
734
|
};
|
|
735
735
|
|
|
736
|
-
const result:
|
|
736
|
+
const result: SignInResult = await sparkvault.products.identity.signIn(options);
|
|
737
737
|
// result.token: string
|
|
738
738
|
// result.identity: string
|
|
739
739
|
// result.identityType: 'email' | 'phone'
|
|
@@ -744,23 +744,24 @@ const result: VerifyResult = await sparkvault.identity.pop(options);
|
|
|
744
744
|
If your site uses a Content Security Policy, you must allow the SparkVault domains:
|
|
745
745
|
|
|
746
746
|
```
|
|
747
|
-
connect-src https://api.sparkvault.com wss://ws.sparkvault.com;
|
|
747
|
+
connect-src https://auth.sparkvault.com https://api.sparkvault.com wss://ws.sparkvault.com;
|
|
748
748
|
script-src https://cdn.sparkvault.com;
|
|
749
749
|
```
|
|
750
750
|
|
|
751
751
|
| Directive | Domain | Reason |
|
|
752
752
|
|-----------|--------|--------|
|
|
753
|
-
| `connect-src` | `https://
|
|
753
|
+
| `connect-src` | `https://auth.sparkvault.com` | Identity verification (config, OTP, passkey, SparkLink) |
|
|
754
|
+
| `connect-src` | `https://api.sparkvault.com` | SparkVault Core API (vaults, ingots, sessions) |
|
|
754
755
|
| `connect-src` | `wss://ws.sparkvault.com` | WebSocket for SparkLink push notifications |
|
|
755
756
|
| `script-src` | `https://cdn.sparkvault.com` | SDK script (if using CDN installation) |
|
|
756
757
|
|
|
757
758
|
## Best Practices
|
|
758
759
|
|
|
759
|
-
1. **Initialize Once** — Create the SparkVault instance once when your app loads, not on every login attempt. The SDK preloads configuration
|
|
760
|
+
1. **Initialize Once** — Create the SparkVault instance once when your app loads, not on every login attempt. The SDK preloads configuration so the popup opens instantly.
|
|
760
761
|
|
|
761
762
|
2. **Always Verify Server-Side** — Never trust client-side token validation in production. Always verify the JWT signature on your backend using the JWKS endpoint before trusting claims or issuing an app session.
|
|
762
763
|
|
|
763
|
-
3. **Handle Cancellation Gracefully** —
|
|
764
|
+
3. **Handle Cancellation Gracefully** — People may close the popup without completing sign-in. This throws a `UserCancelledError` — handle it gracefully rather than showing an error message.
|
|
764
765
|
|
|
765
766
|
4. **Key Users by SVID** — Use `svid` or `sub` as the canonical identity reference. Email and phone are user-facing attributes, not durable account keys.
|
|
766
767
|
|
package/dist/config.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface SparkVaultConfig {
|
|
|
6
6
|
accountId: string;
|
|
7
7
|
/** Core API origin. Defaults to https://api.sparkvault.com. A trailing /v1 is accepted and normalized. */
|
|
8
8
|
apiBaseUrl?: string;
|
|
9
|
-
/** Identity Product API base URL. Defaults to https://
|
|
9
|
+
/** Identity Product API base URL. Defaults to https://auth.sparkvault.com. */
|
|
10
10
|
identityBaseUrl?: string;
|
|
11
11
|
/** auth.sv portal origin for self-service deep links (`portalUrl()`). Defaults to https://auth.sv. */
|
|
12
12
|
portalBaseUrl?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ interface SparkVaultConfig {
|
|
|
6
6
|
accountId: string;
|
|
7
7
|
/** Core API origin. Defaults to https://api.sparkvault.com. A trailing /v1 is accepted and normalized. */
|
|
8
8
|
apiBaseUrl?: string;
|
|
9
|
-
/** Identity Product API base URL. Defaults to https://
|
|
9
|
+
/** Identity Product API base URL. Defaults to https://auth.sparkvault.com. */
|
|
10
10
|
identityBaseUrl?: string;
|
|
11
11
|
/** auth.sv portal origin for self-service deep links (`portalUrl()`). Defaults to https://auth.sv. */
|
|
12
12
|
portalBaseUrl?: string;
|
|
@@ -188,6 +188,14 @@ interface VerifyResult {
|
|
|
188
188
|
/** Ordered post-login nudges (default-mode logins only). */
|
|
189
189
|
recommendations?: Recommendation[];
|
|
190
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Options for `signIn()` — the customer-facing popup sign-in. The popup owns its
|
|
193
|
+
* rendering, so there is no inline `target`/`renderMode`/`chrome` here; those
|
|
194
|
+
* are internal to the SparkVault-hosted sign-in surfaces.
|
|
195
|
+
*/
|
|
196
|
+
type SignInOptions = Omit<VerifyOptions, 'target' | 'renderMode' | 'chrome'>;
|
|
197
|
+
/** The verified identity returned by `signIn()`. */
|
|
198
|
+
type SignInResult = VerifyResult;
|
|
191
199
|
interface TokenClaims {
|
|
192
200
|
/** Issuer */
|
|
193
201
|
iss: string;
|
|
@@ -272,17 +280,14 @@ declare class PopupBlockedError extends SparkVaultError {
|
|
|
272
280
|
/**
|
|
273
281
|
* Identity Module
|
|
274
282
|
*
|
|
275
|
-
*
|
|
283
|
+
* Passwordless sign-in through the first-party SparkVault popup.
|
|
276
284
|
* Supports passkey, OTP, SparkLink, and social authentication.
|
|
277
285
|
*
|
|
278
|
-
* @example
|
|
279
|
-
* const result = await sv.products.identity.
|
|
286
|
+
* @example Programmatic
|
|
287
|
+
* const result = await sv.products.identity.signIn();
|
|
280
288
|
*
|
|
281
|
-
* @example
|
|
289
|
+
* @example Attached to clicks
|
|
282
290
|
* sv.products.identity.attach('.login-btn');
|
|
283
|
-
*
|
|
284
|
-
* @example Inline mode
|
|
285
|
-
* const result = await sv.products.identity.verify({ target: '#auth-container' });
|
|
286
291
|
*/
|
|
287
292
|
|
|
288
293
|
declare class IdentityModule {
|
|
@@ -314,7 +319,7 @@ declare class IdentityModule {
|
|
|
314
319
|
* the browser surfaces a "Continue as …" prompt with no popup, redirect, or
|
|
315
320
|
* typing. Requires a registered `clientId` in the SDK config and a browser
|
|
316
321
|
* with FedCM support — callers should feature-detect with
|
|
317
|
-
* `IdentityModule.isFedcmAvailable()` and fall back to `
|
|
322
|
+
* `IdentityModule.isFedcmAvailable()` and fall back to `signIn()` otherwise.
|
|
318
323
|
*
|
|
319
324
|
* @returns the verified result, or `null` when the browser has no FedCM
|
|
320
325
|
* support (so the caller can fall back). Throws `UserCancelledError` when the
|
|
@@ -322,8 +327,8 @@ declare class IdentityModule {
|
|
|
322
327
|
*
|
|
323
328
|
* @example
|
|
324
329
|
* const result = (await sv.products.identity.isFedcmAvailable())
|
|
325
|
-
* ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.
|
|
326
|
-
* : await sv.products.identity.
|
|
330
|
+
* ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.signIn())
|
|
331
|
+
* : await sv.products.identity.signIn();
|
|
327
332
|
*/
|
|
328
333
|
signInWithFedcm(options?: {
|
|
329
334
|
mediation?: 'optional' | 'required' | 'silent';
|
|
@@ -332,22 +337,24 @@ declare class IdentityModule {
|
|
|
332
337
|
/** Whether this browser exposes the FedCM API (`navigator.credentials` + IdentityCredential). */
|
|
333
338
|
static isFedcmAvailable(): boolean;
|
|
334
339
|
/**
|
|
335
|
-
*
|
|
340
|
+
* Open the SparkVault sign-in popup and resolve with the verified identity.
|
|
336
341
|
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
342
|
+
* This is the single programmatic entry point; `attach()` binds it to element
|
|
343
|
+
* clicks. There is no inline/in-page mode — sign-in always runs in the
|
|
344
|
+
* first-party popup on the Identity origin, so login's `__Host-` hub cookie is
|
|
345
|
+
* a first-party write and cross-domain SSO works.
|
|
339
346
|
*
|
|
340
|
-
* @example
|
|
341
|
-
* const result = await sv.products.identity.
|
|
347
|
+
* @example
|
|
348
|
+
* const result = await sv.products.identity.signIn();
|
|
342
349
|
* console.log(result.token, result.identity);
|
|
343
|
-
*
|
|
344
|
-
* @example Inline mode
|
|
345
|
-
* const result = await sv.products.identity.verify({
|
|
346
|
-
* target: '#auth-container',
|
|
347
|
-
* email: 'user@example.com'
|
|
348
|
-
* });
|
|
349
350
|
*/
|
|
350
|
-
|
|
351
|
+
signIn(options?: SignInOptions): Promise<SignInResult>;
|
|
352
|
+
/**
|
|
353
|
+
* Core flow runner. Dialog mode (no `target`) opens the popup; local mode
|
|
354
|
+
* (`renderMode: 'local'` / `target`) renders into the current document and
|
|
355
|
+
* powers the SparkVault-hosted sign-in surfaces (see the internal `render`).
|
|
356
|
+
*/
|
|
357
|
+
private runFlow;
|
|
351
358
|
/**
|
|
352
359
|
* Attach identity verification to element clicks.
|
|
353
360
|
* When any matching element is clicked, opens the verification dialog.
|
|
@@ -376,7 +383,7 @@ declare class IdentityModule {
|
|
|
376
383
|
*
|
|
377
384
|
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
378
385
|
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
379
|
-
* (
|
|
386
|
+
* (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
380
387
|
*/
|
|
381
388
|
decodeToken(token: string): TokenClaims;
|
|
382
389
|
/**
|
|
@@ -410,16 +417,14 @@ declare class IdentityModule {
|
|
|
410
417
|
*/
|
|
411
418
|
private createInlineContainer;
|
|
412
419
|
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
* Render the identity verification UI inline into a target element.
|
|
419
|
-
* Equivalent to `verify({ ...options, target })`.
|
|
420
|
+
* Render the flow into a page element instead of a popup.
|
|
421
|
+
*
|
|
422
|
+
* @internal Used only by the SparkVault-hosted sign-in popup and hosted login
|
|
423
|
+
* page (which own their chrome and pass `renderMode: 'local'`). Customer
|
|
424
|
+
* integrations have no inline mode — use `signIn()` / `attach()`.
|
|
420
425
|
*/
|
|
421
426
|
render(options: VerifyOptions & {
|
|
422
|
-
target: HTMLElement;
|
|
427
|
+
target: string | HTMLElement;
|
|
423
428
|
}): Promise<VerifyResult>;
|
|
424
429
|
}
|
|
425
430
|
|
|
@@ -1787,7 +1792,7 @@ declare const logger: {
|
|
|
1787
1792
|
*
|
|
1788
1793
|
* const sv = SparkVault.init({ accountId: 'acc_your_account' });
|
|
1789
1794
|
*
|
|
1790
|
-
* const result = await sv.products.identity.
|
|
1795
|
+
* const result = await sv.products.identity.signIn();
|
|
1791
1796
|
* console.log(result.identity, result.identityType);
|
|
1792
1797
|
* ```
|
|
1793
1798
|
*/
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Identity Module
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Passwordless sign-in through the first-party SparkVault popup.
|
|
5
5
|
* Supports passkey, OTP, SparkLink, and social authentication.
|
|
6
6
|
*
|
|
7
|
-
* @example
|
|
8
|
-
* const result = await sv.products.identity.
|
|
7
|
+
* @example Programmatic
|
|
8
|
+
* const result = await sv.products.identity.signIn();
|
|
9
9
|
*
|
|
10
|
-
* @example
|
|
10
|
+
* @example Attached to clicks
|
|
11
11
|
* sv.products.identity.attach('.login-btn');
|
|
12
|
-
*
|
|
13
|
-
* @example Inline mode
|
|
14
|
-
* const result = await sv.products.identity.verify({ target: '#auth-container' });
|
|
15
12
|
*/
|
|
16
13
|
import type { ResolvedConfig } from '../../config';
|
|
17
|
-
import type { VerifyOptions, VerifyResult, TokenClaims, AttachOptions, PortalUrlOptions } from './types';
|
|
14
|
+
import type { VerifyOptions, VerifyResult, SignInOptions, SignInResult, TokenClaims, AttachOptions, PortalUrlOptions } from './types';
|
|
18
15
|
export declare class IdentityModule {
|
|
19
16
|
private readonly config;
|
|
20
17
|
private readonly api;
|
|
@@ -44,7 +41,7 @@ export declare class IdentityModule {
|
|
|
44
41
|
* the browser surfaces a "Continue as …" prompt with no popup, redirect, or
|
|
45
42
|
* typing. Requires a registered `clientId` in the SDK config and a browser
|
|
46
43
|
* with FedCM support — callers should feature-detect with
|
|
47
|
-
* `IdentityModule.isFedcmAvailable()` and fall back to `
|
|
44
|
+
* `IdentityModule.isFedcmAvailable()` and fall back to `signIn()` otherwise.
|
|
48
45
|
*
|
|
49
46
|
* @returns the verified result, or `null` when the browser has no FedCM
|
|
50
47
|
* support (so the caller can fall back). Throws `UserCancelledError` when the
|
|
@@ -52,8 +49,8 @@ export declare class IdentityModule {
|
|
|
52
49
|
*
|
|
53
50
|
* @example
|
|
54
51
|
* const result = (await sv.products.identity.isFedcmAvailable())
|
|
55
|
-
* ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.
|
|
56
|
-
* : await sv.products.identity.
|
|
52
|
+
* ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.signIn())
|
|
53
|
+
* : await sv.products.identity.signIn();
|
|
57
54
|
*/
|
|
58
55
|
signInWithFedcm(options?: {
|
|
59
56
|
mediation?: 'optional' | 'required' | 'silent';
|
|
@@ -62,22 +59,24 @@ export declare class IdentityModule {
|
|
|
62
59
|
/** Whether this browser exposes the FedCM API (`navigator.credentials` + IdentityCredential). */
|
|
63
60
|
static isFedcmAvailable(): boolean;
|
|
64
61
|
/**
|
|
65
|
-
*
|
|
62
|
+
* Open the SparkVault sign-in popup and resolve with the verified identity.
|
|
66
63
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
64
|
+
* This is the single programmatic entry point; `attach()` binds it to element
|
|
65
|
+
* clicks. There is no inline/in-page mode — sign-in always runs in the
|
|
66
|
+
* first-party popup on the Identity origin, so login's `__Host-` hub cookie is
|
|
67
|
+
* a first-party write and cross-domain SSO works.
|
|
69
68
|
*
|
|
70
|
-
* @example
|
|
71
|
-
* const result = await sv.products.identity.
|
|
69
|
+
* @example
|
|
70
|
+
* const result = await sv.products.identity.signIn();
|
|
72
71
|
* console.log(result.token, result.identity);
|
|
73
|
-
*
|
|
74
|
-
* @example Inline mode
|
|
75
|
-
* const result = await sv.products.identity.verify({
|
|
76
|
-
* target: '#auth-container',
|
|
77
|
-
* email: 'user@example.com'
|
|
78
|
-
* });
|
|
79
72
|
*/
|
|
80
|
-
|
|
73
|
+
signIn(options?: SignInOptions): Promise<SignInResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Core flow runner. Dialog mode (no `target`) opens the popup; local mode
|
|
76
|
+
* (`renderMode: 'local'` / `target`) renders into the current document and
|
|
77
|
+
* powers the SparkVault-hosted sign-in surfaces (see the internal `render`).
|
|
78
|
+
*/
|
|
79
|
+
private runFlow;
|
|
81
80
|
/**
|
|
82
81
|
* Attach identity verification to element clicks.
|
|
83
82
|
* When any matching element is clicked, opens the verification dialog.
|
|
@@ -106,7 +105,7 @@ export declare class IdentityModule {
|
|
|
106
105
|
*
|
|
107
106
|
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
108
107
|
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
109
|
-
* (
|
|
108
|
+
* (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
110
109
|
*/
|
|
111
110
|
decodeToken(token: string): TokenClaims;
|
|
112
111
|
/**
|
|
@@ -140,18 +139,16 @@ export declare class IdentityModule {
|
|
|
140
139
|
*/
|
|
141
140
|
private createInlineContainer;
|
|
142
141
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* Render the identity verification UI inline into a target element.
|
|
149
|
-
* Equivalent to `verify({ ...options, target })`.
|
|
142
|
+
* Render the flow into a page element instead of a popup.
|
|
143
|
+
*
|
|
144
|
+
* @internal Used only by the SparkVault-hosted sign-in popup and hosted login
|
|
145
|
+
* page (which own their chrome and pass `renderMode: 'local'`). Customer
|
|
146
|
+
* integrations have no inline mode — use `signIn()` / `attach()`.
|
|
150
147
|
*/
|
|
151
148
|
render(options: VerifyOptions & {
|
|
152
|
-
target: HTMLElement;
|
|
149
|
+
target: string | HTMLElement;
|
|
153
150
|
}): Promise<VerifyResult>;
|
|
154
151
|
}
|
|
155
|
-
export type {
|
|
152
|
+
export type { SignInOptions, SignInResult, AttachOptions, VerifyResult, VerifyOptions, TokenClaims, AuthMethod, AuthContext, Theme, SdkConfig, SdkConfigBranding, MethodId, MethodMetadata, } from './types';
|
|
156
153
|
export { METHOD_REGISTRY, getMethodMetadata, enrichMethods } from './methods';
|
|
157
154
|
export { IdentityApi, IdentityApiError } from './api';
|
|
@@ -116,6 +116,14 @@ export interface VerifyResult {
|
|
|
116
116
|
/** Ordered post-login nudges (default-mode logins only). */
|
|
117
117
|
recommendations?: Recommendation[];
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Options for `signIn()` — the customer-facing popup sign-in. The popup owns its
|
|
121
|
+
* rendering, so there is no inline `target`/`renderMode`/`chrome` here; those
|
|
122
|
+
* are internal to the SparkVault-hosted sign-in surfaces.
|
|
123
|
+
*/
|
|
124
|
+
export type SignInOptions = Omit<VerifyOptions, 'target' | 'renderMode' | 'chrome'>;
|
|
125
|
+
/** The verified identity returned by `signIn()`. */
|
|
126
|
+
export type SignInResult = VerifyResult;
|
|
119
127
|
/** Raw recommendation as the API returns it (snake_case). */
|
|
120
128
|
export interface RawRecommendation {
|
|
121
129
|
type: string;
|