@sparkvault/sdk-js 5.0.1 → 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.
@@ -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
- 'auth.sv',
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,
@@ -7706,6 +7711,7 @@ function attachClickHandler(selector, onClick) {
7706
7711
  * @example Inline mode
7707
7712
  * const result = await sv.products.identity.verify({ target: '#auth-container' });
7708
7713
  */
7714
+ const PORTAL_SECTIONS = ['home', 'contacts', 'security', 'sessions', 'sites'];
7709
7715
  function isTokenClaims(payload) {
7710
7716
  if (typeof payload !== 'object' || payload === null) {
7711
7717
  return false;
@@ -7732,6 +7738,41 @@ class IdentityModule {
7732
7738
  this.api.preloadConfig();
7733
7739
  }
7734
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
+ }
7735
7776
  /**
7736
7777
  * Verify user identity.
7737
7778
  *