@sparkvault/sdk-js 5.0.0 → 5.0.2
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/config.d.ts +3 -0
- package/dist/index.d.ts +31 -0
- package/dist/products/identity/index.d.ts +16 -1
- package/dist/products/identity/renderer.d.ts +14 -0
- package/dist/products/identity/types.d.ts +13 -0
- package/dist/sparkvault.cjs.js +68 -3
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +68 -3
- 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
|
@@ -103,8 +103,11 @@ class PopupBlockedError extends SparkVaultError {
|
|
|
103
103
|
|
|
104
104
|
const SPARKVAULT_ROOT_DOMAIN = 'sparkvault.com';
|
|
105
105
|
|
|
106
|
+
/** The person-facing Identity portal host (auth.sv shell + hosted login). */
|
|
107
|
+
const SPARKVAULT_AUTH_HOST = 'auth.sv';
|
|
108
|
+
|
|
106
109
|
const SPARKVAULT_PLATFORM_SV_HOSTS = Object.freeze([
|
|
107
|
-
|
|
110
|
+
SPARKVAULT_AUTH_HOST,
|
|
108
111
|
'x.sv',
|
|
109
112
|
'files.sv',
|
|
110
113
|
'file.sv',
|
|
@@ -146,6 +149,7 @@ const DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS = [
|
|
|
146
149
|
];
|
|
147
150
|
const API_URL = 'https://api.sparkvault.com';
|
|
148
151
|
const IDENTITY_URL = 'https://api.sparkvault.com/v1/products/identity';
|
|
152
|
+
const PORTAL_URL = `https://${SPARKVAULT_AUTH_HOST}`;
|
|
149
153
|
function normalizeApiBaseUrl(url) {
|
|
150
154
|
const trimmed = url.replace(/\/+$/, '');
|
|
151
155
|
return trimmed.endsWith('/v1') ? trimmed.slice(0, -3) : trimmed;
|
|
@@ -159,6 +163,7 @@ function resolveConfig(config) {
|
|
|
159
163
|
timeout: config.timeout ?? 30000,
|
|
160
164
|
apiBaseUrl: normalizeApiBaseUrl(config.apiBaseUrl ?? API_URL),
|
|
161
165
|
identityBaseUrl: normalizeBaseUrl(config.identityBaseUrl ?? IDENTITY_URL),
|
|
166
|
+
portalBaseUrl: normalizeBaseUrl(config.portalBaseUrl ?? PORTAL_URL),
|
|
162
167
|
accessToken: config.accessToken,
|
|
163
168
|
getAccessToken: config.getAccessToken,
|
|
164
169
|
apiKey: config.apiKey,
|
|
@@ -5829,6 +5834,25 @@ class IdentityRenderer {
|
|
|
5829
5834
|
this.setState(this.viewStateForConfigError(error));
|
|
5830
5835
|
}
|
|
5831
5836
|
}
|
|
5837
|
+
/**
|
|
5838
|
+
* Surface a terminal startup failure *inside* the dialog instead of letting
|
|
5839
|
+
* it reject to the host.
|
|
5840
|
+
*
|
|
5841
|
+
* `start()` already routes config-fetch failures to an in-dialog view via its
|
|
5842
|
+
* own catch, but an unexpected throw (or a throw while rendering that view)
|
|
5843
|
+
* would otherwise escape. In the default embedded/dialog mode that escape is
|
|
5844
|
+
* exactly the "closes silently" failure: the host's `onError` runs, the
|
|
5845
|
+
* embedding page tears the iframe down, and the user is left with no message.
|
|
5846
|
+
* Render the error in the SparkVault dialog — consistent with how every
|
|
5847
|
+
* in-flow error already behaves — so the dialog stays open and the user can
|
|
5848
|
+
* retry or close it (→ onCancel).
|
|
5849
|
+
*/
|
|
5850
|
+
showStartupError(error) {
|
|
5851
|
+
if (!this.container.isOpen()) {
|
|
5852
|
+
this.container.createLoading({ backdropBlur: this.options.backdropBlur }, () => this.handleClose());
|
|
5853
|
+
}
|
|
5854
|
+
this.setState(this.viewStateForConfigError(error));
|
|
5855
|
+
}
|
|
5832
5856
|
/**
|
|
5833
5857
|
* Map a config-fetch error to the appropriate terminal view.
|
|
5834
5858
|
*
|
|
@@ -7687,6 +7711,7 @@ function attachClickHandler(selector, onClick) {
|
|
|
7687
7711
|
* @example Inline mode
|
|
7688
7712
|
* const result = await sv.products.identity.verify({ target: '#auth-container' });
|
|
7689
7713
|
*/
|
|
7714
|
+
const PORTAL_SECTIONS = ['home', 'contacts', 'security', 'sessions', 'sites'];
|
|
7690
7715
|
function isTokenClaims(payload) {
|
|
7691
7716
|
if (typeof payload !== 'object' || payload === null) {
|
|
7692
7717
|
return false;
|
|
@@ -7713,6 +7738,41 @@ class IdentityModule {
|
|
|
7713
7738
|
this.api.preloadConfig();
|
|
7714
7739
|
}
|
|
7715
7740
|
}
|
|
7741
|
+
/**
|
|
7742
|
+
* Build a deep link into the person's auth.sv Identity portal — where they
|
|
7743
|
+
* manage verified contacts, passkeys, sessions, and connected sites across
|
|
7744
|
+
* every SparkVault-integrated site. Send a signed-in user here to self-serve;
|
|
7745
|
+
* the portal authenticates them with their own SparkVault Identity.
|
|
7746
|
+
*
|
|
7747
|
+
* @example Manage this site (block/notifications/etc.)
|
|
7748
|
+
* window.location.href = sv.products.identity.portalUrl({ section: 'sites' });
|
|
7749
|
+
*
|
|
7750
|
+
* @example Open the security screen
|
|
7751
|
+
* sv.products.identity.portalUrl({ section: 'security' });
|
|
7752
|
+
*
|
|
7753
|
+
* @returns An absolute URL on the configured `portalBaseUrl` (default https://auth.sv).
|
|
7754
|
+
*/
|
|
7755
|
+
portalUrl(options = {}) {
|
|
7756
|
+
const section = options.section ?? 'home';
|
|
7757
|
+
if (!PORTAL_SECTIONS.includes(section)) {
|
|
7758
|
+
throw new ValidationError(`Unknown portal section: ${section}`, {
|
|
7759
|
+
field: 'section',
|
|
7760
|
+
received: section,
|
|
7761
|
+
});
|
|
7762
|
+
}
|
|
7763
|
+
let path;
|
|
7764
|
+
if (section === 'home') {
|
|
7765
|
+
path = '/';
|
|
7766
|
+
}
|
|
7767
|
+
else if (section === 'sites') {
|
|
7768
|
+
const site = (options.site ?? this.config.accountId).trim();
|
|
7769
|
+
path = site ? `/sites/${encodeURIComponent(site)}` : '/sites';
|
|
7770
|
+
}
|
|
7771
|
+
else {
|
|
7772
|
+
path = `/${section}`;
|
|
7773
|
+
}
|
|
7774
|
+
return new URL(path, this.config.portalBaseUrl).toString();
|
|
7775
|
+
}
|
|
7716
7776
|
/**
|
|
7717
7777
|
* Verify user identity.
|
|
7718
7778
|
*
|
|
@@ -7782,8 +7842,13 @@ class IdentityModule {
|
|
|
7782
7842
|
const startLocalRender = (container) => {
|
|
7783
7843
|
this.renderer = new IdentityRenderer(container, this.api, mergedOptions, hostCallbacks);
|
|
7784
7844
|
this.renderer.start().catch((error) => {
|
|
7785
|
-
|
|
7786
|
-
|
|
7845
|
+
// A startup failure must surface inside the SparkVault dialog, never
|
|
7846
|
+
// close it silently. Rejecting here would, in the default embedded
|
|
7847
|
+
// mode, run the host's onError and let the embedding page remove the
|
|
7848
|
+
// iframe — leaving the user with a vanished dialog and no error. Render
|
|
7849
|
+
// the error in-dialog instead (consistent with every in-flow error);
|
|
7850
|
+
// the promise settles later via the user's retry/close.
|
|
7851
|
+
this.renderer?.showStartupError(error);
|
|
7787
7852
|
});
|
|
7788
7853
|
};
|
|
7789
7854
|
if (!useLocal) {
|