@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.
package/dist/config.d.ts CHANGED
@@ -8,6 +8,8 @@ export interface SparkVaultConfig {
8
8
  apiBaseUrl?: string;
9
9
  /** Identity Product API base URL. Defaults to https://api.sparkvault.com/v1/products/identity. */
10
10
  identityBaseUrl?: string;
11
+ /** auth.sv portal origin for self-service deep links (`portalUrl()`). Defaults to https://auth.sv. */
12
+ portalBaseUrl?: string;
11
13
  /** Static SparkVault Core access token for authenticated API calls. */
12
14
  accessToken?: string;
13
15
  /** Dynamic SparkVault Core access token provider for authenticated API calls. */
@@ -37,6 +39,7 @@ export interface ResolvedConfig {
37
39
  timeout: number;
38
40
  apiBaseUrl: string;
39
41
  identityBaseUrl: string;
42
+ portalBaseUrl: string;
40
43
  accessToken?: string;
41
44
  getAccessToken?: () => string | null | Promise<string | null>;
42
45
  apiKey?: string;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,8 @@ interface SparkVaultConfig {
8
8
  apiBaseUrl?: string;
9
9
  /** Identity Product API base URL. Defaults to https://api.sparkvault.com/v1/products/identity. */
10
10
  identityBaseUrl?: string;
11
+ /** auth.sv portal origin for self-service deep links (`portalUrl()`). Defaults to https://auth.sv. */
12
+ portalBaseUrl?: string;
11
13
  /** Static SparkVault Core access token for authenticated API calls. */
12
14
  accessToken?: string;
13
15
  /** Dynamic SparkVault Core access token provider for authenticated API calls. */
@@ -37,6 +39,7 @@ interface ResolvedConfig {
37
39
  timeout: number;
38
40
  apiBaseUrl: string;
39
41
  identityBaseUrl: string;
42
+ portalBaseUrl: string;
40
43
  accessToken?: string;
41
44
  getAccessToken?: () => string | null | Promise<string | null>;
42
45
  apiKey?: string;
@@ -154,6 +157,19 @@ type Recommendation = {
154
157
  type: 'backup_identifier';
155
158
  missingType: 'email' | 'phone';
156
159
  };
160
+ /** A self-service screen in the auth.sv Identity portal. */
161
+ type PortalSection = 'home' | 'contacts' | 'security' | 'sessions' | 'sites';
162
+ /** Options for building an auth.sv portal deep link (`portalUrl()`). */
163
+ interface PortalUrlOptions {
164
+ /** Which portal screen to open. Defaults to `'home'`. */
165
+ section?: PortalSection;
166
+ /**
167
+ * Focus a specific connected site on the Sites screen (an `acc_…` account ID).
168
+ * When `section` is `'sites'` and `site` is omitted, defaults to this SDK's
169
+ * own `accountId` — i.e. "manage this site". Ignored for other sections.
170
+ */
171
+ site?: string;
172
+ }
157
173
  interface VerifyResult {
158
174
  /** Signed JWT token */
159
175
  token: string;
@@ -275,6 +291,21 @@ declare class IdentityModule {
275
291
  private renderer;
276
292
  private embedder;
277
293
  constructor(config: ResolvedConfig);
294
+ /**
295
+ * Build a deep link into the person's auth.sv Identity portal — where they
296
+ * manage verified contacts, passkeys, sessions, and connected sites across
297
+ * every SparkVault-integrated site. Send a signed-in user here to self-serve;
298
+ * the portal authenticates them with their own SparkVault Identity.
299
+ *
300
+ * @example Manage this site (block/notifications/etc.)
301
+ * window.location.href = sv.products.identity.portalUrl({ section: 'sites' });
302
+ *
303
+ * @example Open the security screen
304
+ * sv.products.identity.portalUrl({ section: 'security' });
305
+ *
306
+ * @returns An absolute URL on the configured `portalBaseUrl` (default https://auth.sv).
307
+ */
308
+ portalUrl(options?: PortalUrlOptions): string;
278
309
  /**
279
310
  * Verify user identity.
280
311
  *
@@ -14,13 +14,28 @@
14
14
  * const result = await sv.products.identity.verify({ target: '#auth-container' });
15
15
  */
16
16
  import type { ResolvedConfig } from '../../config';
17
- import type { VerifyOptions, VerifyResult, TokenClaims, AttachOptions } from './types';
17
+ import type { VerifyOptions, VerifyResult, TokenClaims, AttachOptions, PortalUrlOptions } from './types';
18
18
  export declare class IdentityModule {
19
19
  private readonly config;
20
20
  private readonly api;
21
21
  private renderer;
22
22
  private embedder;
23
23
  constructor(config: ResolvedConfig);
24
+ /**
25
+ * Build a deep link into the person's auth.sv Identity portal — where they
26
+ * manage verified contacts, passkeys, sessions, and connected sites across
27
+ * every SparkVault-integrated site. Send a signed-in user here to self-serve;
28
+ * the portal authenticates them with their own SparkVault Identity.
29
+ *
30
+ * @example Manage this site (block/notifications/etc.)
31
+ * window.location.href = sv.products.identity.portalUrl({ section: 'sites' });
32
+ *
33
+ * @example Open the security screen
34
+ * sv.products.identity.portalUrl({ section: 'security' });
35
+ *
36
+ * @returns An absolute URL on the configured `portalBaseUrl` (default https://auth.sv).
37
+ */
38
+ portalUrl(options?: PortalUrlOptions): string;
24
39
  /**
25
40
  * Verify user identity.
26
41
  *
@@ -91,6 +91,19 @@ export type Recommendation = {
91
91
  };
92
92
  /** Canonical dismiss key for a recommendation (suppresses it server-side 30d). */
93
93
  export type RecommendationKey = 'passkey' | 'backup_email' | 'backup_phone';
94
+ /** A self-service screen in the auth.sv Identity portal. */
95
+ export type PortalSection = 'home' | 'contacts' | 'security' | 'sessions' | 'sites';
96
+ /** Options for building an auth.sv portal deep link (`portalUrl()`). */
97
+ export interface PortalUrlOptions {
98
+ /** Which portal screen to open. Defaults to `'home'`. */
99
+ section?: PortalSection;
100
+ /**
101
+ * Focus a specific connected site on the Sites screen (an `acc_…` account ID).
102
+ * When `section` is `'sites'` and `site` is omitted, defaults to this SDK's
103
+ * own `accountId` — i.e. "manage this site". Ignored for other sections.
104
+ */
105
+ site?: string;
106
+ }
94
107
  export interface VerifyResult {
95
108
  /** Signed JWT token */
96
109
  token: string;
@@ -107,8 +107,11 @@ class PopupBlockedError extends SparkVaultError {
107
107
 
108
108
  const SPARKVAULT_ROOT_DOMAIN = 'sparkvault.com';
109
109
 
110
+ /** The person-facing Identity portal host (auth.sv shell + hosted login). */
111
+ const SPARKVAULT_AUTH_HOST = 'auth.sv';
112
+
110
113
  const SPARKVAULT_PLATFORM_SV_HOSTS = Object.freeze([
111
- 'auth.sv',
114
+ SPARKVAULT_AUTH_HOST,
112
115
  'x.sv',
113
116
  'files.sv',
114
117
  'file.sv',
@@ -150,6 +153,7 @@ const DEFAULT_ALLOWED_DOWNLOAD_HOST_PATTERNS = [
150
153
  ];
151
154
  const API_URL = 'https://api.sparkvault.com';
152
155
  const IDENTITY_URL = 'https://api.sparkvault.com/v1/products/identity';
156
+ const PORTAL_URL = `https://${SPARKVAULT_AUTH_HOST}`;
153
157
  function normalizeApiBaseUrl(url) {
154
158
  const trimmed = url.replace(/\/+$/, '');
155
159
  return trimmed.endsWith('/v1') ? trimmed.slice(0, -3) : trimmed;
@@ -163,6 +167,7 @@ function resolveConfig(config) {
163
167
  timeout: config.timeout ?? 30000,
164
168
  apiBaseUrl: normalizeApiBaseUrl(config.apiBaseUrl ?? API_URL),
165
169
  identityBaseUrl: normalizeBaseUrl(config.identityBaseUrl ?? IDENTITY_URL),
170
+ portalBaseUrl: normalizeBaseUrl(config.portalBaseUrl ?? PORTAL_URL),
166
171
  accessToken: config.accessToken,
167
172
  getAccessToken: config.getAccessToken,
168
173
  apiKey: config.apiKey,
@@ -7710,6 +7715,7 @@ function attachClickHandler(selector, onClick) {
7710
7715
  * @example Inline mode
7711
7716
  * const result = await sv.products.identity.verify({ target: '#auth-container' });
7712
7717
  */
7718
+ const PORTAL_SECTIONS = ['home', 'contacts', 'security', 'sessions', 'sites'];
7713
7719
  function isTokenClaims(payload) {
7714
7720
  if (typeof payload !== 'object' || payload === null) {
7715
7721
  return false;
@@ -7736,6 +7742,41 @@ class IdentityModule {
7736
7742
  this.api.preloadConfig();
7737
7743
  }
7738
7744
  }
7745
+ /**
7746
+ * Build a deep link into the person's auth.sv Identity portal — where they
7747
+ * manage verified contacts, passkeys, sessions, and connected sites across
7748
+ * every SparkVault-integrated site. Send a signed-in user here to self-serve;
7749
+ * the portal authenticates them with their own SparkVault Identity.
7750
+ *
7751
+ * @example Manage this site (block/notifications/etc.)
7752
+ * window.location.href = sv.products.identity.portalUrl({ section: 'sites' });
7753
+ *
7754
+ * @example Open the security screen
7755
+ * sv.products.identity.portalUrl({ section: 'security' });
7756
+ *
7757
+ * @returns An absolute URL on the configured `portalBaseUrl` (default https://auth.sv).
7758
+ */
7759
+ portalUrl(options = {}) {
7760
+ const section = options.section ?? 'home';
7761
+ if (!PORTAL_SECTIONS.includes(section)) {
7762
+ throw new ValidationError(`Unknown portal section: ${section}`, {
7763
+ field: 'section',
7764
+ received: section,
7765
+ });
7766
+ }
7767
+ let path;
7768
+ if (section === 'home') {
7769
+ path = '/';
7770
+ }
7771
+ else if (section === 'sites') {
7772
+ const site = (options.site ?? this.config.accountId).trim();
7773
+ path = site ? `/sites/${encodeURIComponent(site)}` : '/sites';
7774
+ }
7775
+ else {
7776
+ path = `/${section}`;
7777
+ }
7778
+ return new URL(path, this.config.portalBaseUrl).toString();
7779
+ }
7739
7780
  /**
7740
7781
  * Verify user identity.
7741
7782
  *