@sparkvault/sdk-js 10.0.0 → 11.0.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.
Files changed (54) hide show
  1. package/README.md +9 -4
  2. package/dist/api-base.d.ts +46 -11
  3. package/dist/config.d.ts +5 -3
  4. package/dist/entropy/index.d.ts +0 -1
  5. package/dist/entropy/types.d.ts +1 -1
  6. package/dist/errors.d.ts +18 -2
  7. package/dist/folders/index.d.ts +3 -1
  8. package/dist/http.d.ts +11 -6
  9. package/dist/index.cjs +8209 -7265
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +514 -297
  12. package/dist/index.mjs +8208 -7266
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/ingots/fetch-download.d.ts +48 -0
  15. package/dist/ingots/index.d.ts +29 -14
  16. package/dist/ingots/types.d.ts +104 -43
  17. package/dist/notify/types.d.ts +7 -2
  18. package/dist/products/identity/api.d.ts +30 -14
  19. package/dist/products/identity/handlers/index.d.ts +1 -1
  20. package/dist/products/identity/handlers/passkey-handler.d.ts +4 -13
  21. package/dist/products/identity/handlers/sparklink-handler.d.ts +0 -1
  22. package/dist/products/identity/index.d.ts +23 -6
  23. package/dist/products/identity/inline-container.d.ts +13 -26
  24. package/dist/products/identity/modal.d.ts +16 -42
  25. package/dist/products/identity/renderer.d.ts +31 -10
  26. package/dist/products/identity/types.d.ts +17 -5
  27. package/dist/products/identity/types.test-d.d.ts +21 -0
  28. package/dist/products/identity/utils.d.ts +9 -16
  29. package/dist/products/identity/views/base.d.ts +4 -21
  30. package/dist/products/identity/views/identity-input.d.ts +4 -2
  31. package/dist/products/index.d.ts +1 -1
  32. package/dist/products/notify/index.d.ts +29 -19
  33. package/dist/products/notify/types.d.ts +74 -37
  34. package/dist/products/notify/types.test-d.d.ts +1 -0
  35. package/dist/request-path.d.ts +44 -0
  36. package/dist/sparkvault.js +1 -1
  37. package/dist/sparkvault.js.map +1 -1
  38. package/dist/ui/chrome.d.ts +16 -0
  39. package/dist/ui/ds-tokens.d.ts +58 -0
  40. package/dist/ui/inline-shell.d.ts +19 -0
  41. package/dist/ui/modal-shell.d.ts +36 -0
  42. package/dist/ui/target.d.ts +6 -0
  43. package/dist/vaults/index.d.ts +11 -6
  44. package/dist/vaults/upload/api.d.ts +21 -9
  45. package/dist/vaults/upload/chrome.d.ts +8 -22
  46. package/dist/vaults/upload/container.d.ts +0 -8
  47. package/dist/vaults/upload/index.d.ts +1 -1
  48. package/dist/vaults/upload/inline-container.d.ts +13 -42
  49. package/dist/vaults/upload/modal.d.ts +14 -33
  50. package/dist/vaults/upload/renderer.d.ts +0 -1
  51. package/dist/vaults/upload/styles.d.ts +4 -2
  52. package/dist/vaults/upload/types.d.ts +2 -2
  53. package/package.json +2 -2
  54. package/dist/utils/base64url.d.ts +0 -52
package/README.md CHANGED
@@ -53,7 +53,7 @@ The CDN serves the browser bundle in two tiers:
53
53
 
54
54
  | URL | Effective cache | Use when |
55
55
  |-----|-----------------|----------|
56
- | `sdk/v1/sparkvault.js` | Short-lived (Cloudflare edge TTL, ~4h) — bust with `?v=<version>` for immediate freshness | Default. Auto-updates each release; the `?v=<version>` query gives you the new build immediately. |
56
+ | `sdk/v1/sparkvault.js` | Short-lived (edge cache TTL, ~4h) — bust with `?v=<version>` for immediate freshness | Default. Auto-updates each release; the `?v=<version>` query gives you the new build immediately. |
57
57
  | `sdk/v1/sparkvault.<hash>.js` | `immutable`, 1 year | You want a reproducible, forever-cached, integrity-pinned build. |
58
58
 
59
59
  `sdk/v1/version.json` advertises the current immutable URL, its hash, and a
@@ -700,9 +700,13 @@ try {
700
700
  | `UserCancelledError` | `user_cancelled` | Person closed the popup without completing sign-in |
701
701
  | `ValidationError` | `validation_error` | Invalid input or configuration |
702
702
  | `NetworkError` | `network_error` | Network connectivity failure |
703
- | `TimeoutError` | `timeout_error` | Request exceeded timeout limit |
703
+ | `TimeoutError` | `timeout_error` | Request exceeded timeout limit (the limit covers the whole response, body included) |
704
704
  | `PopupBlockedError` | `popup_blocked` | Browser blocked the popup window |
705
705
  | `AuthenticationError` | `authentication_error` | Authentication failed (e.g., expired token) |
706
+ | `SparkVaultError` | `download_failed` | The download host refused an ingot download (`statusCode` carries its status) |
707
+
708
+ A refused request is typed by its HTTP status even when a gateway answers with
709
+ a non-JSON body (an HTML 401 is still an `AuthenticationError`).
706
710
 
707
711
  ## TypeScript Support
708
712
 
@@ -752,14 +756,15 @@ const result: SignInResult = await sparkvault.products.identity.signIn(options);
752
756
  If your site uses a Content Security Policy, you must allow the SparkVault domains:
753
757
 
754
758
  ```
755
- connect-src https://auth.sparkvault.com https://api.sparkvault.com wss://ws.sparkvault.com;
759
+ connect-src https://auth.sparkvault.com https://api.sparkvault.com https://forge.sparkvault.com wss://ws.sparkvault.com;
756
760
  script-src https://cdn.sparkvault.com;
757
761
  ```
758
762
 
759
763
  | Directive | Domain | Reason |
760
764
  |-----------|--------|--------|
761
- | `connect-src` | `https://auth.sparkvault.com` | Identity verification (config, OTP, passkey, SparkLink) |
765
+ | `connect-src` | `https://auth.sparkvault.com` | Identity verification (config, OTP, passkey, SparkLink) and the entropy draw a sign-in binds its PKCE verifier, state and nonce with |
762
766
  | `connect-src` | `https://api.sparkvault.com` | SparkVault Core API (vaults, ingots, sessions) |
767
+ | `connect-src` | `https://forge.sparkvault.com` | Encrypted file transfers (the vault upload widget, `sv.ingots` uploads and downloads) |
763
768
  | `connect-src` | `wss://ws.sparkvault.com` | WebSocket for SparkLink push notifications |
764
769
  | `script-src` | `https://cdn.sparkvault.com` | SDK script (if using CDN installation) |
765
770
 
@@ -1,11 +1,10 @@
1
1
  /**
2
2
  * SparkVault API Base
3
3
  *
4
- * Shared lifecycle and HTTP plumbing for every internal API client in the
5
- * SDK. Concrete clients (IdentityApi, UploadApi, ...) extend this and
6
- * provide:
4
+ * The one transport every SDK request goes through, and the shared lifecycle
5
+ * for the internal API clients (IdentityApi, UploadApi, ...), which provide:
7
6
  * - their own error factory via makeError()
8
- * - their own typed endpoint methods that call rawRequest()
7
+ * - their own typed endpoint methods on top of rawRequest() and send()
9
8
  *
10
9
  * Session lifecycle invariant: every user-facing session (a modal open, a
11
10
  * verify flow, an upload widget invocation) starts with the owning Module
@@ -23,6 +22,23 @@ export interface RawResponse {
23
22
  data: unknown;
24
23
  status: number;
25
24
  }
25
+ /** Why a request produced no answer. */
26
+ export type TransportFailure = 'cancelled' | 'timeout' | 'network' | 'unknown';
27
+ export interface ExchangeOptions<T> {
28
+ timeoutMs: number;
29
+ /** The session's close signal, captured when the request starts. */
30
+ closeSignal?: AbortSignal;
31
+ /** Reads the response: runs under the same deadline and close signal as the request. */
32
+ read: (response: Response) => Promise<T>;
33
+ /** The SDK error for a request that produced no answer. */
34
+ fail: (failure: TransportFailure, cause: unknown) => SparkVaultError;
35
+ }
36
+ /** The copy a SparkVaultApi client shows for each way a request can produce no answer. */
37
+ export interface TransportCopy {
38
+ readonly cancelled: string;
39
+ readonly timeout: string;
40
+ readonly network: string;
41
+ }
26
42
  /**
27
43
  * Combine a fresh timeout with a session close signal into one AbortSignal.
28
44
  *
@@ -31,10 +47,23 @@ export interface RawResponse {
31
47
  * AbortSignal.any) so nothing leaks across requests. Callers discriminate
32
48
  * close-vs-timeout afterwards by checking the close signal's aborted flag.
33
49
  */
34
- export declare function combineTimeoutAndCloseSignals(timeoutMs: number, closeSignal: AbortSignal): {
50
+ export declare function combineTimeoutAndCloseSignals(timeoutMs: number, closeSignal?: AbortSignal): {
35
51
  signal: AbortSignal;
36
52
  dispose: () => void;
37
53
  };
54
+ /**
55
+ * One request under a deadline and an optional session close signal: the
56
+ * fetch every SDK transport makes.
57
+ *
58
+ * The whole exchange (the response headers AND whatever `read` consumes of the
59
+ * body) runs inside the deadline, so a body that stalls after its headers can
60
+ * never pin the caller. An already-closed session never reaches fetch. A
61
+ * failure with no answer is classified once: the close signal the caller
62
+ * captured says cancelled, otherwise an abort is the deadline, a TypeError is
63
+ * the network (browsers' "Failed to fetch" / "Load failed"), and anything else
64
+ * is unknown. SDK errors `read` throws pass through as they are.
65
+ */
66
+ export declare function exchange<T>(url: string, init: RequestInit, options: ExchangeOptions<T>): Promise<T>;
38
67
  export declare abstract class SparkVaultApi {
39
68
  protected readonly timeoutMs: number;
40
69
  /**
@@ -59,12 +88,18 @@ export declare abstract class SparkVaultApi {
59
88
  /** Subclass-specific error factory. */
60
89
  protected abstract makeError(message: string, code: string, statusCode: number, details?: Record<string, unknown>): SparkVaultError;
61
90
  /**
62
- * Issue an HTTP request with timeout + session abort + standard error
63
- * mapping. Subclasses build URLs and unwrap response envelopes on top.
64
- *
65
- * Returns the parsed JSON body (whatever shape it takes) plus the
66
- * status code. Throws subclass-typed errors via makeError() for: aborted
67
- * sessions, timeouts, network failures, and non-2xx responses.
91
+ * One request in the current session: `exchange` bound to this client's
92
+ * deadline, its error factory, and the session's close signal, captured
93
+ * here, when the request starts. resetSession() can swap the controller
94
+ * while the request is in flight, and reading the live one afterwards would
95
+ * misreport a genuine cancel as a timeout.
96
+ */
97
+ protected send<T>(url: string, init: RequestInit, copy: TransportCopy, read: (response: Response) => Promise<T>): Promise<T>;
98
+ /**
99
+ * Issue a JSON API request. Returns the parsed JSON body (whatever shape it
100
+ * takes; null when the body is not JSON) plus the status code. A non-2xx
101
+ * answer throws the subclass error carrying the server's code, message and
102
+ * details, read by the one error-body reader every transport shares.
68
103
  */
69
104
  protected rawRequest(url: string, options: RawRequestOptions): Promise<RawResponse>;
70
105
  }
package/dist/config.d.ts CHANGED
@@ -35,9 +35,9 @@ export interface SparkVaultConfig {
35
35
  /** Enable backdrop blur on dialogs (default: true) */
36
36
  backdropBlur?: boolean;
37
37
  /**
38
- * Host allowlist for backend-issued ingot download URLs. Defaults to the
39
- * canonical SparkVault Forge / S3 / CloudFront hosts. Override only when
40
- * pointing at a custom deployment.
38
+ * Host allowlist for the backend-issued Forge transfer URLs the SDK sends an
39
+ * ingot's ISTK to (downloads and uploads alike). Defaults to the SparkVault
40
+ * platform's own hosts; override only when pointing at another deployment.
41
41
  */
42
42
  allowedDownloadHostPatterns?: RegExp[];
43
43
  }
@@ -56,4 +56,6 @@ export interface ResolvedConfig {
56
56
  allowedDownloadHostPatterns: RegExp[];
57
57
  }
58
58
  export declare function resolveConfig(config: SparkVaultConfig): ResolvedConfig;
59
+ /** Whether the configured allowlist trusts the host of a backend-issued transfer URL. */
60
+ export declare function isAllowedTransferHost(config: ResolvedConfig, hostname: string): boolean;
59
61
  export declare function validateConfig(config: SparkVaultConfig): void;
@@ -31,6 +31,5 @@ export declare class EntropyModule {
31
31
  * const key = serverEntropy.map((b, i) => b ^ localEntropy[i]);
32
32
  */
33
33
  generateBytes(n: number): Promise<Uint8Array>;
34
- private validateByteCount;
35
34
  }
36
35
  export type { GenerateEntropyOptions, EntropyResult, EntropyFormat } from './types';
@@ -8,7 +8,7 @@
8
8
  export type EntropyFormat = 'hex' | 'base64' | 'base64url' | 'alphanumeric' | 'alphanumeric-mixed' | 'password' | 'numeric' | 'uuid' | 'bytes';
9
9
  /** Options for generate. */
10
10
  export interface GenerateEntropyOptions {
11
- /** Number of random bytes (1–1024) */
11
+ /** Number of random bytes: 1–1024, or 1–512 for alphanumeric, alphanumeric-mixed and password. */
12
12
  bytes: number;
13
13
  /** Output format. Defaults to hex. */
14
14
  format?: EntropyFormat;
package/dist/errors.d.ts CHANGED
@@ -18,8 +18,9 @@ export declare class ValidationError extends SparkVaultError {
18
18
  }
19
19
  /**
20
20
  * The pooled-capacity resource a quota gate refers to. Only the byte pools
21
- * hard-gate: flex licensing has no seat limit (inviting and licensing are
22
- * never quota-gated), and Identity soft-gates through its own path.
21
+ * hard-gate: licenses are assigned per member, never drawn from a pool
22
+ * (inviting and licensing are never quota-gated), and Identity soft-gates
23
+ * through its own path.
23
24
  */
24
25
  export type QuotaResource = 'storage' | 'bandwidth';
25
26
  /**
@@ -71,3 +72,18 @@ export declare class PopupBlockedError extends SparkVaultError {
71
72
  export declare class PopupSeveredError extends SparkVaultError {
72
73
  constructor();
73
74
  }
75
+ /** What a failed SparkVault API response says about itself. */
76
+ export interface ApiErrorBody {
77
+ message: string;
78
+ code: string;
79
+ details?: Record<string, unknown>;
80
+ }
81
+ /**
82
+ * Read a failed response's error body: the one reading every SDK transport
83
+ * shares. SparkVault services answer `{ error: { code, message, details } }`;
84
+ * a framework or gateway answers flat (`{ code, message }`, `{ message }`) or
85
+ * with no JSON at all, so each field falls back to its flat form and then to a
86
+ * default. The body is read leniently: a failure's status and class never
87
+ * depend on the body being JSON.
88
+ */
89
+ export declare function readApiErrorBody(response: Response): Promise<ApiErrorBody>;
@@ -6,7 +6,7 @@
6
6
  * with its short-lived Vault Access Token (VAT).
7
7
  */
8
8
  import { HttpClient } from '../http';
9
- import type { UnsealedVault, Folder, FolderBreadcrumbItem, CreateFolderOptions, UpdateFolderOptions } from './types';
9
+ import type { UnsealedVault, Folder, FolderBreadcrumbItem, CreateFolderOptions, UpdateFolderOptions, FolderWire } from './types';
10
10
  export declare class FoldersModule {
11
11
  private readonly http;
12
12
  constructor(http: HttpClient);
@@ -74,4 +74,6 @@ export declare class FoldersModule {
74
74
  */
75
75
  moveIngot(vault: UnsealedVault, ingotId: string, folderId: string | null): Promise<void>;
76
76
  }
77
+ /** A folder as the API sends it, in the SDK's shape (also the contents listing's subfolders). */
78
+ export declare function mapFolder(wire: FolderWire): Folder;
77
79
  export type { UnsealedVault, Folder, FolderBreadcrumbItem, CreateFolderOptions, UpdateFolderOptions, } from './types';
package/dist/http.d.ts CHANGED
@@ -2,10 +2,15 @@
2
2
  * SparkVault SDK HTTP Client
3
3
  */
4
4
  import type { ResolvedConfig } from './config';
5
+ import type { ApiPath, QueryParams } from './request-path';
5
6
  export interface RequestOptions {
6
7
  method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
7
8
  headers?: Record<string, string>;
8
9
  body?: unknown;
10
+ /** Query parameters appended to the path; empty values are left out. */
11
+ query?: QueryParams;
12
+ /** The unsealed vault's Vault Access Token, sent as `X-Vault-Access-Token`. */
13
+ vat?: string;
9
14
  timeout?: number;
10
15
  }
11
16
  /** Capacity state for a pool, driving low-capacity nudges in the UI. */
@@ -50,7 +55,7 @@ export declare class HttpClient {
50
55
  constructor(config: ResolvedConfig);
51
56
  private getDefaultHeaders;
52
57
  private getAccessToken;
53
- request<T = unknown>(path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
58
+ request<T = unknown>(path: ApiPath, options?: RequestOptions): Promise<ApiResponse<T>>;
54
59
  private parseResponse;
55
60
  private createErrorFromResponse;
56
61
  private unwrapApiResponse;
@@ -59,9 +64,9 @@ export declare class HttpClient {
59
64
  * standard `{ data, meta }` response. Returns undefined for bare responses.
60
65
  */
61
66
  private extractResponseMeta;
62
- get<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
63
- post<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
64
- put<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
65
- patch<T = unknown>(path: string, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
66
- delete<T = unknown>(path: string, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
67
+ get<T = unknown>(path: ApiPath, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
68
+ post<T = unknown>(path: ApiPath, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
69
+ put<T = unknown>(path: ApiPath, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
70
+ patch<T = unknown>(path: ApiPath, body?: unknown, options?: Omit<RequestOptions, 'method'>): Promise<ApiResponse<T>>;
71
+ delete<T = unknown>(path: ApiPath, options?: Omit<RequestOptions, 'method' | 'body'>): Promise<ApiResponse<T>>;
67
72
  }