@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 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
  *
@@ -46,6 +46,20 @@ export declare class IdentityRenderer {
46
46
  * Otherwise shows loading state while fetching config.
47
47
  */
48
48
  start(): Promise<void>;
49
+ /**
50
+ * Surface a terminal startup failure *inside* the dialog instead of letting
51
+ * it reject to the host.
52
+ *
53
+ * `start()` already routes config-fetch failures to an in-dialog view via its
54
+ * own catch, but an unexpected throw (or a throw while rendering that view)
55
+ * would otherwise escape. In the default embedded/dialog mode that escape is
56
+ * exactly the "closes silently" failure: the host's `onError` runs, the
57
+ * embedding page tears the iframe down, and the user is left with no message.
58
+ * Render the error in the SparkVault dialog — consistent with how every
59
+ * in-flow error already behaves — so the dialog stays open and the user can
60
+ * retry or close it (→ onCancel).
61
+ */
62
+ showStartupError(error: unknown): void;
49
63
  /**
50
64
  * Map a config-fetch error to the appropriate terminal view.
51
65
  *
@@ -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,
@@ -5833,6 +5838,25 @@ class IdentityRenderer {
5833
5838
  this.setState(this.viewStateForConfigError(error));
5834
5839
  }
5835
5840
  }
5841
+ /**
5842
+ * Surface a terminal startup failure *inside* the dialog instead of letting
5843
+ * it reject to the host.
5844
+ *
5845
+ * `start()` already routes config-fetch failures to an in-dialog view via its
5846
+ * own catch, but an unexpected throw (or a throw while rendering that view)
5847
+ * would otherwise escape. In the default embedded/dialog mode that escape is
5848
+ * exactly the "closes silently" failure: the host's `onError` runs, the
5849
+ * embedding page tears the iframe down, and the user is left with no message.
5850
+ * Render the error in the SparkVault dialog — consistent with how every
5851
+ * in-flow error already behaves — so the dialog stays open and the user can
5852
+ * retry or close it (→ onCancel).
5853
+ */
5854
+ showStartupError(error) {
5855
+ if (!this.container.isOpen()) {
5856
+ this.container.createLoading({ backdropBlur: this.options.backdropBlur }, () => this.handleClose());
5857
+ }
5858
+ this.setState(this.viewStateForConfigError(error));
5859
+ }
5836
5860
  /**
5837
5861
  * Map a config-fetch error to the appropriate terminal view.
5838
5862
  *
@@ -7691,6 +7715,7 @@ function attachClickHandler(selector, onClick) {
7691
7715
  * @example Inline mode
7692
7716
  * const result = await sv.products.identity.verify({ target: '#auth-container' });
7693
7717
  */
7718
+ const PORTAL_SECTIONS = ['home', 'contacts', 'security', 'sessions', 'sites'];
7694
7719
  function isTokenClaims(payload) {
7695
7720
  if (typeof payload !== 'object' || payload === null) {
7696
7721
  return false;
@@ -7717,6 +7742,41 @@ class IdentityModule {
7717
7742
  this.api.preloadConfig();
7718
7743
  }
7719
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
+ }
7720
7780
  /**
7721
7781
  * Verify user identity.
7722
7782
  *
@@ -7786,8 +7846,13 @@ class IdentityModule {
7786
7846
  const startLocalRender = (container) => {
7787
7847
  this.renderer = new IdentityRenderer(container, this.api, mergedOptions, hostCallbacks);
7788
7848
  this.renderer.start().catch((error) => {
7789
- options.onError?.(error);
7790
- rejectRef(error);
7849
+ // A startup failure must surface inside the SparkVault dialog, never
7850
+ // close it silently. Rejecting here would, in the default embedded
7851
+ // mode, run the host's onError and let the embedding page remove the
7852
+ // iframe — leaving the user with a vanished dialog and no error. Render
7853
+ // the error in-dialog instead (consistent with every in-flow error);
7854
+ // the promise settles later via the user's retry/close.
7855
+ this.renderer?.showStartupError(error);
7791
7856
  });
7792
7857
  };
7793
7858
  if (!useLocal) {