@sparkvault/sdk-js 8.1.2 → 8.2.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 +35 -41
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +35 -41
- 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/sparkvault.esm.js
CHANGED
|
@@ -149,7 +149,7 @@ const DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS = [
|
|
|
149
149
|
/\.cloudfront\.net$/i,
|
|
150
150
|
];
|
|
151
151
|
const API_URL = 'https://api.sparkvault.com';
|
|
152
|
-
const IDENTITY_URL = 'https://
|
|
152
|
+
const IDENTITY_URL = 'https://auth.sparkvault.com';
|
|
153
153
|
const PORTAL_URL = `https://${SPARKVAULT_AUTH_HOST}`;
|
|
154
154
|
function normalizeApiBaseUrl(url) {
|
|
155
155
|
const trimmed = url.replace(/\/+$/, '');
|
|
@@ -7966,17 +7966,14 @@ function attachClickHandler(selector, onClick) {
|
|
|
7966
7966
|
/**
|
|
7967
7967
|
* Identity Module
|
|
7968
7968
|
*
|
|
7969
|
-
*
|
|
7969
|
+
* Passwordless sign-in through the first-party SparkVault popup.
|
|
7970
7970
|
* Supports passkey, OTP, SparkLink, and social authentication.
|
|
7971
7971
|
*
|
|
7972
|
-
* @example
|
|
7973
|
-
* const result = await sv.products.identity.
|
|
7972
|
+
* @example Programmatic
|
|
7973
|
+
* const result = await sv.products.identity.signIn();
|
|
7974
7974
|
*
|
|
7975
|
-
* @example
|
|
7975
|
+
* @example Attached to clicks
|
|
7976
7976
|
* sv.products.identity.attach('.login-btn');
|
|
7977
|
-
*
|
|
7978
|
-
* @example Inline mode
|
|
7979
|
-
* const result = await sv.products.identity.verify({ target: '#auth-container' });
|
|
7980
7977
|
*/
|
|
7981
7978
|
const PORTAL_SECTIONS = ['home', 'identity', 'security', 'sessions', 'sites'];
|
|
7982
7979
|
function isTokenClaims(payload) {
|
|
@@ -8048,7 +8045,7 @@ class IdentityModule {
|
|
|
8048
8045
|
* the browser surfaces a "Continue as …" prompt with no popup, redirect, or
|
|
8049
8046
|
* typing. Requires a registered `clientId` in the SDK config and a browser
|
|
8050
8047
|
* with FedCM support — callers should feature-detect with
|
|
8051
|
-
* `IdentityModule.isFedcmAvailable()` and fall back to `
|
|
8048
|
+
* `IdentityModule.isFedcmAvailable()` and fall back to `signIn()` otherwise.
|
|
8052
8049
|
*
|
|
8053
8050
|
* @returns the verified result, or `null` when the browser has no FedCM
|
|
8054
8051
|
* support (so the caller can fall back). Throws `UserCancelledError` when the
|
|
@@ -8056,8 +8053,8 @@ class IdentityModule {
|
|
|
8056
8053
|
*
|
|
8057
8054
|
* @example
|
|
8058
8055
|
* const result = (await sv.products.identity.isFedcmAvailable())
|
|
8059
|
-
* ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.
|
|
8060
|
-
* : await sv.products.identity.
|
|
8056
|
+
* ? await sv.products.identity.signInWithFedcm().catch(() => sv.products.identity.signIn())
|
|
8057
|
+
* : await sv.products.identity.signIn();
|
|
8061
8058
|
*/
|
|
8062
8059
|
async signInWithFedcm(options = {}) {
|
|
8063
8060
|
if (!IdentityModule.isFedcmAvailable()) {
|
|
@@ -8110,22 +8107,26 @@ class IdentityModule {
|
|
|
8110
8107
|
typeof navigator.credentials.get === 'function');
|
|
8111
8108
|
}
|
|
8112
8109
|
/**
|
|
8113
|
-
*
|
|
8110
|
+
* Open the SparkVault sign-in popup and resolve with the verified identity.
|
|
8114
8111
|
*
|
|
8115
|
-
*
|
|
8116
|
-
*
|
|
8112
|
+
* This is the single programmatic entry point; `attach()` binds it to element
|
|
8113
|
+
* clicks. There is no inline/in-page mode — sign-in always runs in the
|
|
8114
|
+
* first-party popup on the Identity origin, so login's `__Host-` hub cookie is
|
|
8115
|
+
* a first-party write and cross-domain SSO works.
|
|
8117
8116
|
*
|
|
8118
|
-
* @example
|
|
8119
|
-
* const result = await sv.products.identity.
|
|
8117
|
+
* @example
|
|
8118
|
+
* const result = await sv.products.identity.signIn();
|
|
8120
8119
|
* console.log(result.token, result.identity);
|
|
8121
|
-
*
|
|
8122
|
-
* @example Inline mode
|
|
8123
|
-
* const result = await sv.products.identity.verify({
|
|
8124
|
-
* target: '#auth-container',
|
|
8125
|
-
* email: 'user@example.com'
|
|
8126
|
-
* });
|
|
8127
8120
|
*/
|
|
8128
|
-
async
|
|
8121
|
+
async signIn(options = {}) {
|
|
8122
|
+
return this.runFlow(options);
|
|
8123
|
+
}
|
|
8124
|
+
/**
|
|
8125
|
+
* Core flow runner. Dialog mode (no `target`) opens the popup; local mode
|
|
8126
|
+
* (`renderMode: 'local'` / `target`) renders into the current document and
|
|
8127
|
+
* powers the SparkVault-hosted sign-in surfaces (see the internal `render`).
|
|
8128
|
+
*/
|
|
8129
|
+
async runFlow(options = {}) {
|
|
8129
8130
|
const redirectResult = await this.consumeRedirectResult();
|
|
8130
8131
|
if (redirectResult) {
|
|
8131
8132
|
options.onSuccess?.(redirectResult);
|
|
@@ -8223,7 +8224,7 @@ class IdentityModule {
|
|
|
8223
8224
|
const handleClick = async (event) => {
|
|
8224
8225
|
event.preventDefault();
|
|
8225
8226
|
try {
|
|
8226
|
-
await this.
|
|
8227
|
+
await this.signIn({
|
|
8227
8228
|
email: options.email,
|
|
8228
8229
|
phone: options.phone,
|
|
8229
8230
|
authContext: options.authContext,
|
|
@@ -8262,7 +8263,7 @@ class IdentityModule {
|
|
|
8262
8263
|
*
|
|
8263
8264
|
* To trust a token (e.g. before keying records by `claims.svid`), verify the
|
|
8264
8265
|
* Ed25519 signature server-side against the Identity JWKS endpoint
|
|
8265
|
-
* (
|
|
8266
|
+
* (`https://auth.sparkvault.com/{account_id}/.well-known/jwks.json`). See docs/SDK.md.
|
|
8266
8267
|
*/
|
|
8267
8268
|
decodeToken(token) {
|
|
8268
8269
|
if (!token || typeof token !== 'string') {
|
|
@@ -8319,8 +8320,8 @@ class IdentityModule {
|
|
|
8319
8320
|
}
|
|
8320
8321
|
// Once a token is present it must be consumed exactly once: the hash and
|
|
8321
8322
|
// one-shot OAuth state are cleared whether validation succeeds or fails.
|
|
8322
|
-
// A failing token left in the URL would make every subsequent
|
|
8323
|
-
// re-consume and re-reject it before the dialog could ever open
|
|
8323
|
+
// A failing token left in the URL would make every subsequent signIn()
|
|
8324
|
+
// re-consume and re-reject it before the dialog could ever open, so login
|
|
8324
8325
|
// would stay wedged until the user manually edited the URL.
|
|
8325
8326
|
try {
|
|
8326
8327
|
let expectedState = null;
|
|
@@ -8424,22 +8425,15 @@ class IdentityModule {
|
|
|
8424
8425
|
// container's own surface and the SparkVault footer.
|
|
8425
8426
|
return new InlineContainer(element, bare ? { bare: true, showFooter: false } : {});
|
|
8426
8427
|
}
|
|
8427
|
-
// Public-API aliases. The documented method names in the customer-facing
|
|
8428
|
-
// SDK README and the API docs are pop() and render(); verify() is the
|
|
8429
|
-
// underlying primitive. Both remain canonical entry points.
|
|
8430
8428
|
/**
|
|
8431
|
-
*
|
|
8432
|
-
*
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
}
|
|
8437
|
-
/**
|
|
8438
|
-
* Render the identity verification UI inline into a target element.
|
|
8439
|
-
* Equivalent to `verify({ ...options, target })`.
|
|
8429
|
+
* Render the flow into a page element instead of a popup.
|
|
8430
|
+
*
|
|
8431
|
+
* @internal Used only by the SparkVault-hosted sign-in popup and hosted login
|
|
8432
|
+
* page (which own their chrome and pass `renderMode: 'local'`). Customer
|
|
8433
|
+
* integrations have no inline mode — use `signIn()` / `attach()`.
|
|
8440
8434
|
*/
|
|
8441
8435
|
async render(options) {
|
|
8442
|
-
return this.
|
|
8436
|
+
return this.runFlow(options);
|
|
8443
8437
|
}
|
|
8444
8438
|
}
|
|
8445
8439
|
|
|
@@ -12934,7 +12928,7 @@ function autoInit(SparkVaultClass) {
|
|
|
12934
12928
|
*
|
|
12935
12929
|
* const sv = SparkVault.init({ accountId: 'acc_your_account' });
|
|
12936
12930
|
*
|
|
12937
|
-
* const result = await sv.products.identity.
|
|
12931
|
+
* const result = await sv.products.identity.signIn();
|
|
12938
12932
|
* console.log(result.identity, result.identityType);
|
|
12939
12933
|
* ```
|
|
12940
12934
|
*/
|