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