@sparkvault/sdk-js 1.24.4

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 (63) hide show
  1. package/README.md +769 -0
  2. package/dist/api-base.d.ts +58 -0
  3. package/dist/auto-init.d.ts +32 -0
  4. package/dist/config.d.ts +41 -0
  5. package/dist/errors.d.ts +30 -0
  6. package/dist/health.d.ts +18 -0
  7. package/dist/http.d.ts +51 -0
  8. package/dist/identity/api.d.ts +110 -0
  9. package/dist/identity/container.d.ts +56 -0
  10. package/dist/identity/handlers/index.d.ts +9 -0
  11. package/dist/identity/handlers/passkey-handler.d.ts +69 -0
  12. package/dist/identity/handlers/sparklink-handler.d.ts +30 -0
  13. package/dist/identity/handlers/totp-handler.d.ts +52 -0
  14. package/dist/identity/index.d.ts +89 -0
  15. package/dist/identity/inline-container.d.ts +65 -0
  16. package/dist/identity/methods.d.ts +23 -0
  17. package/dist/identity/modal.d.ts +82 -0
  18. package/dist/identity/renderer.d.ts +146 -0
  19. package/dist/identity/state.d.ts +98 -0
  20. package/dist/identity/styles.d.ts +22 -0
  21. package/dist/identity/types.d.ts +221 -0
  22. package/dist/identity/utils/cooldown-timer.d.ts +73 -0
  23. package/dist/identity/utils/index.d.ts +5 -0
  24. package/dist/identity/utils.d.ts +39 -0
  25. package/dist/identity/views/app-not-activated.d.ts +21 -0
  26. package/dist/identity/views/base.d.ts +62 -0
  27. package/dist/identity/views/error.d.ts +25 -0
  28. package/dist/identity/views/icons.d.ts +38 -0
  29. package/dist/identity/views/identity-input.d.ts +48 -0
  30. package/dist/identity/views/index.d.ts +16 -0
  31. package/dist/identity/views/loading.d.ts +15 -0
  32. package/dist/identity/views/method-select.d.ts +29 -0
  33. package/dist/identity/views/passkey-prompt.d.ts +24 -0
  34. package/dist/identity/views/passkey.d.ts +38 -0
  35. package/dist/identity/views/service-unavailable.d.ts +21 -0
  36. package/dist/identity/views/sparklink-waiting.d.ts +40 -0
  37. package/dist/identity/views/totp-verify.d.ts +58 -0
  38. package/dist/index.d.ts +733 -0
  39. package/dist/logger.d.ts +45 -0
  40. package/dist/rng/index.d.ts +54 -0
  41. package/dist/rng/types.d.ts +26 -0
  42. package/dist/sparks/index.d.ts +37 -0
  43. package/dist/sparks/types.d.ts +56 -0
  44. package/dist/sparkvault.cjs.js +10167 -0
  45. package/dist/sparkvault.cjs.js.map +1 -0
  46. package/dist/sparkvault.esm.js +10152 -0
  47. package/dist/sparkvault.esm.js.map +1 -0
  48. package/dist/sparkvault.js +2 -0
  49. package/dist/sparkvault.js.map +1 -0
  50. package/dist/utils/base64url.d.ts +41 -0
  51. package/dist/utils/dom.d.ts +17 -0
  52. package/dist/utils/retry.d.ts +32 -0
  53. package/dist/vaults/index.d.ts +109 -0
  54. package/dist/vaults/types.d.ts +128 -0
  55. package/dist/vaults/upload/api.d.ts +36 -0
  56. package/dist/vaults/upload/container.d.ts +57 -0
  57. package/dist/vaults/upload/index.d.ts +75 -0
  58. package/dist/vaults/upload/inline-container.d.ts +75 -0
  59. package/dist/vaults/upload/modal.d.ts +79 -0
  60. package/dist/vaults/upload/renderer.d.ts +70 -0
  61. package/dist/vaults/upload/styles.d.ts +20 -0
  62. package/dist/vaults/upload/types.d.ts +182 -0
  63. package/package.json +63 -0
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Vaults Module Types
3
+ */
4
+ export interface CreateVaultOptions {
5
+ /** Vault name */
6
+ name: string;
7
+ /** Store VMK server-side (less secure, more convenient) */
8
+ hostedVmk?: boolean;
9
+ }
10
+ export interface Vault {
11
+ /** Vault ID */
12
+ id: string;
13
+ /** Vault name */
14
+ name: string;
15
+ /** Vault Master Key (24 chars) - STORE SECURELY! */
16
+ vmk: string;
17
+ /** Creation timestamp (Unix seconds) */
18
+ createdAt: number;
19
+ /** Whether VMK is hosted server-side */
20
+ hostedVmk: boolean;
21
+ }
22
+ export interface UnsealVaultOptions {
23
+ /** Vault ID */
24
+ vaultId: string;
25
+ /** Vault Master Key */
26
+ vmk: string;
27
+ }
28
+ export interface UnsealedVault {
29
+ /** Vault ID */
30
+ id: string;
31
+ /** Vault name */
32
+ name: string;
33
+ /** Vault Access Token (short-lived session) */
34
+ vatToken: string;
35
+ /** VAT expiry timestamp (Unix seconds) */
36
+ expiresAt: number;
37
+ /** Number of ingots in vault */
38
+ ingotCount: number;
39
+ /** Total storage used in bytes */
40
+ storageBytes: number;
41
+ }
42
+ export interface VaultSummary {
43
+ /** Vault ID */
44
+ id: string;
45
+ /** Vault name */
46
+ name: string;
47
+ /** Creation timestamp (Unix seconds) */
48
+ createdAt: number;
49
+ /** Number of ingots */
50
+ ingotCount: number;
51
+ /** Total storage used in bytes */
52
+ storageBytes: number;
53
+ /** Whether VMK is hosted server-side */
54
+ hostedVmk: boolean;
55
+ }
56
+ export interface Ingot {
57
+ /** Ingot ID */
58
+ id: string;
59
+ /** Ingot name */
60
+ name: string;
61
+ /** Content type (MIME) */
62
+ contentType: string;
63
+ /** Size in bytes */
64
+ size: number;
65
+ /** Creation timestamp (Unix seconds) */
66
+ createdAt: number;
67
+ /** Ingot type: 'standard' or 'structured' */
68
+ type: 'standard' | 'structured';
69
+ }
70
+ export interface UploadIngotOptions {
71
+ /** File to upload */
72
+ file: File | Blob;
73
+ /** Optional name (defaults to file name) */
74
+ name?: string;
75
+ /** Content type (auto-detected if not provided) */
76
+ contentType?: string;
77
+ /** Progress callback for Forge/TUS upload */
78
+ onProgress?: (bytesUploaded: number, bytesTotal: number) => void;
79
+ }
80
+ export interface CreateVaultResponse {
81
+ vault_id: string;
82
+ name: string;
83
+ vmk: string;
84
+ created_at: number;
85
+ hosted_vmk: boolean;
86
+ }
87
+ export interface UnsealVaultResponse {
88
+ vault_id: string;
89
+ name?: string;
90
+ vat_token?: string;
91
+ vat?: string;
92
+ expires_at: number;
93
+ ingot_count?: number;
94
+ storage_bytes?: number;
95
+ storage_used_bytes?: number;
96
+ }
97
+ export interface ListVaultsResponse {
98
+ vaults: {
99
+ vault_id: string;
100
+ name: string;
101
+ created_at: number;
102
+ ingot_count: number;
103
+ storage_bytes: number;
104
+ hosted_vmk: boolean;
105
+ }[];
106
+ }
107
+ export interface ListIngotsResponse {
108
+ ingots: {
109
+ ingot_id: string;
110
+ name: string;
111
+ content_type: string;
112
+ size_bytes: number;
113
+ created_at: number;
114
+ ingot_type: 'standard' | 'structured';
115
+ }[];
116
+ }
117
+ export interface CreateIngotResponse {
118
+ ingot_id: string;
119
+ name?: string;
120
+ content_type?: string;
121
+ size_bytes?: number;
122
+ created_at?: number;
123
+ ingot_type?: 'standard' | 'structured';
124
+ forge_url?: string;
125
+ }
126
+ export interface DownloadIngotResponse {
127
+ download_url: string;
128
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Upload API
3
+ *
4
+ * API client for vault upload operations.
5
+ */
6
+ import type { ResolvedConfig } from '../../config';
7
+ import { SparkVaultApi } from '../../api-base';
8
+ import { SparkVaultError } from '../../errors';
9
+ import type { VaultUploadConfig } from './types';
10
+ /**
11
+ * Error class for upload API errors. Inherits `code` and `statusCode` from
12
+ * SparkVaultError — no duplicate `httpStatus` field.
13
+ */
14
+ export declare class UploadApiError extends SparkVaultError {
15
+ constructor(message: string, code: string, statusCode: number);
16
+ }
17
+ export declare class UploadApi extends SparkVaultApi {
18
+ private readonly config;
19
+ constructor(config: ResolvedConfig);
20
+ protected makeError(message: string, code: string, statusCode: number): UploadApiError;
21
+ /**
22
+ * Issue a request and unwrap the standard `{ data, meta }` envelope.
23
+ */
24
+ private request;
25
+ /**
26
+ * Get vault upload info (public endpoint).
27
+ */
28
+ getVaultUploadInfo(vaultId: string): Promise<VaultUploadConfig>;
29
+ /**
30
+ * Initiate an upload to get Forge URL and ingot ID.
31
+ */
32
+ initiateUpload(vaultId: string, filename: string, sizeBytes: number, contentType: string): Promise<{
33
+ forgeUrl: string;
34
+ ingotId: string;
35
+ }>;
36
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Upload Container Interface
3
+ *
4
+ * Abstract interface for upload UI containers.
5
+ * Allows switching between modal (popup) and inline rendering modes
6
+ * while reusing all view logic, state management, and handlers.
7
+ */
8
+ import type { UploadBranding } from './types';
9
+ /**
10
+ * Container options for initialization.
11
+ */
12
+ export interface UploadContainerOptions {
13
+ branding?: UploadBranding;
14
+ /** Enable backdrop blur (modal only) */
15
+ backdropBlur?: boolean;
16
+ }
17
+ /**
18
+ * Container interface that both ModalContainer and InlineContainer implement.
19
+ * The renderer interacts with containers through this interface.
20
+ */
21
+ export interface UploadContainer {
22
+ /**
23
+ * Create the container with loading state.
24
+ * Called immediately when upload flow starts.
25
+ */
26
+ createLoading(options: {
27
+ backdropBlur?: boolean;
28
+ }, onClose: () => void): void;
29
+ /**
30
+ * Update branding after vault config loads.
31
+ */
32
+ updateBranding(branding: UploadBranding): void;
33
+ /**
34
+ * Update backdrop blur setting (may be no-op for inline container).
35
+ */
36
+ updateBackdropBlur(enabled: boolean): void;
37
+ /**
38
+ * Get the body element where views are rendered.
39
+ */
40
+ getBody(): HTMLDivElement | null;
41
+ /**
42
+ * Get the sidebar element for security info (optional).
43
+ */
44
+ getSidebar(): HTMLDivElement | null;
45
+ /**
46
+ * Show or hide the security sidebar.
47
+ */
48
+ toggleSidebar(show: boolean): void;
49
+ /**
50
+ * Check if the container is currently active.
51
+ */
52
+ isOpen(): boolean;
53
+ /**
54
+ * Destroy the container and clean up event listeners.
55
+ */
56
+ destroy(): void;
57
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Vault Upload Module
3
+ *
4
+ * Embedded upload widget for vaults with public upload enabled.
5
+ *
6
+ * @example Dialog mode (immediate)
7
+ * const result = await sv.vaults.upload({ vaultId: 'vlt_abc123' });
8
+ *
9
+ * @example Dialog mode (attached to clicks)
10
+ * sv.vaults.upload.attach('.upload-btn', { vaultId: 'vlt_abc123' });
11
+ *
12
+ * @example Inline mode
13
+ * const result = await sv.vaults.upload({
14
+ * vaultId: 'vlt_abc123',
15
+ * target: '#upload-container'
16
+ * });
17
+ */
18
+ import type { ResolvedConfig } from '../../config';
19
+ import type { UploadOptions, UploadAttachOptions, UploadResult } from './types';
20
+ export declare class VaultUploadModule {
21
+ private readonly config;
22
+ private readonly api;
23
+ private renderer;
24
+ private attachedElements;
25
+ constructor(config: ResolvedConfig);
26
+ /**
27
+ * Upload a file to a vault.
28
+ *
29
+ * - Without `target`: Opens a dialog (modal)
30
+ * - With `target`: Renders inline into the specified element
31
+ *
32
+ * @example Dialog mode
33
+ * const result = await sv.vaults.upload({ vaultId: 'vlt_abc123' });
34
+ * console.log('Uploaded:', result.ingotId);
35
+ *
36
+ * @example Inline mode
37
+ * const result = await sv.vaults.upload({
38
+ * vaultId: 'vlt_abc123',
39
+ * target: '#upload-container'
40
+ * });
41
+ */
42
+ upload(options: UploadOptions): Promise<UploadResult>;
43
+ /**
44
+ * Attach upload functionality to element clicks.
45
+ * When any matching element is clicked, opens the upload dialog.
46
+ *
47
+ * @param selector - CSS selector for elements to attach to
48
+ * @param options - Upload options including vaultId and callbacks
49
+ * @returns Cleanup function to remove event listeners
50
+ *
51
+ * @example
52
+ * const cleanup = sv.vaults.upload.attach('.upload-btn', {
53
+ * vaultId: 'vlt_abc123',
54
+ * onSuccess: (result) => console.log('Uploaded:', result.ingotId)
55
+ * });
56
+ *
57
+ * // Later, remove listeners
58
+ * cleanup();
59
+ */
60
+ attach(selector: string, options: UploadAttachOptions): () => void;
61
+ /**
62
+ * Close the upload dialog/inline UI if open.
63
+ */
64
+ close(): void;
65
+ /**
66
+ * Resolve target to an HTMLElement and create inline container.
67
+ */
68
+ private createInlineContainer;
69
+ /** Open the upload widget as a popup. Equivalent to `upload(options)`. */
70
+ pop(options: UploadOptions): Promise<UploadResult>;
71
+ /** Render the upload widget inline. Equivalent to `upload({ ...options, target })`. */
72
+ render(options: UploadOptions): Promise<UploadResult>;
73
+ }
74
+ export type { UploadOptions, UploadAttachOptions, UploadResult, UploadProgress, VaultUploadConfig, UploadBranding, EncryptionInfo, } from './types';
75
+ export { UploadApiError } from './api';
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Inline Upload Container
3
+ *
4
+ * Renders upload UI inline within a target element.
5
+ * Unlike UploadModalContainer which creates an overlay popup, this embeds
6
+ * directly into the customer's page where render() was called.
7
+ *
8
+ * Implements the UploadContainer interface for use with UploadRenderer.
9
+ */
10
+ import type { UploadContainer } from './container';
11
+ import type { UploadBranding } from './types';
12
+ export interface InlineContainerOptions {
13
+ /** Show header with branding and optional close button */
14
+ showHeader?: boolean;
15
+ /** Show close button in header (requires showHeader) */
16
+ showCloseButton?: boolean;
17
+ /** Show footer with SparkVault branding */
18
+ showFooter?: boolean;
19
+ }
20
+ export declare class UploadInlineContainer implements UploadContainer {
21
+ private readonly targetElement;
22
+ private readonly containerOptions;
23
+ private container;
24
+ private header;
25
+ private body;
26
+ private footer;
27
+ private sidebar;
28
+ private closeBtn;
29
+ private onCloseCallback;
30
+ private closeBtnClickHandler;
31
+ private isDarkMode;
32
+ private branding;
33
+ constructor(targetElement: HTMLElement, options?: InlineContainerOptions);
34
+ /**
35
+ * Create the inline container with loading state.
36
+ */
37
+ createLoading(_options: {
38
+ backdropBlur?: boolean;
39
+ }, onClose: () => void): void;
40
+ /**
41
+ * Update branding after vault config loads.
42
+ */
43
+ updateBranding(branding: UploadBranding): void;
44
+ /**
45
+ * Update backdrop blur setting (no-op for inline container).
46
+ */
47
+ updateBackdropBlur(_enabled: boolean): void;
48
+ /**
49
+ * Set dark mode for uploading/ceremony states.
50
+ */
51
+ setDarkMode(enabled: boolean): void;
52
+ /**
53
+ * Show or hide the security sidebar.
54
+ */
55
+ toggleSidebar(show: boolean): void;
56
+ /**
57
+ * Get the body element for content rendering.
58
+ */
59
+ getBody(): HTMLDivElement | null;
60
+ /**
61
+ * Get the sidebar element.
62
+ */
63
+ getSidebar(): HTMLDivElement | null;
64
+ /**
65
+ * Check if the container is currently active.
66
+ */
67
+ isOpen(): boolean;
68
+ /**
69
+ * Destroy the container and clean up.
70
+ */
71
+ destroy(): void;
72
+ private createHeader;
73
+ private createSecuritySidebar;
74
+ private handleClose;
75
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Upload Modal Container
3
+ *
4
+ * Single responsibility: DOM modal container lifecycle.
5
+ * Creates, shows, hides, and destroys the modal overlay and container.
6
+ * Does NOT handle content rendering - that's the Renderer's job.
7
+ */
8
+ import type { UploadBranding } from './types';
9
+ import type { UploadContainer } from './container';
10
+ export interface UploadModalOptions {
11
+ branding?: UploadBranding;
12
+ backdropBlur?: boolean;
13
+ }
14
+ export interface ModalContainerElements {
15
+ overlay: HTMLDivElement;
16
+ modal: HTMLDivElement;
17
+ main: HTMLDivElement;
18
+ header: HTMLDivElement;
19
+ body: HTMLDivElement;
20
+ footer: HTMLDivElement;
21
+ sidebar: HTMLDivElement | null;
22
+ }
23
+ export declare class UploadModalContainer implements UploadContainer {
24
+ private elements;
25
+ private onCloseCallback;
26
+ private keydownHandler;
27
+ private overlayClickHandler;
28
+ private closeBtnClickHandler;
29
+ private closeBtn;
30
+ private backdropBlur;
31
+ private isDarkMode;
32
+ private headerElement;
33
+ private branding;
34
+ /**
35
+ * Create and show the modal immediately with loading state.
36
+ */
37
+ createLoading(options: {
38
+ backdropBlur?: boolean;
39
+ }, onClose: () => void): void;
40
+ /**
41
+ * Create and show the modal container.
42
+ */
43
+ private create;
44
+ private createHeader;
45
+ /**
46
+ * Update branding after vault config loads.
47
+ */
48
+ updateBranding(branding: UploadBranding): void;
49
+ /**
50
+ * Update backdrop blur setting.
51
+ */
52
+ updateBackdropBlur(enabled: boolean): void;
53
+ /**
54
+ * Set dark mode for uploading/ceremony states.
55
+ */
56
+ setDarkMode(enabled: boolean): void;
57
+ /**
58
+ * Show or hide the security sidebar.
59
+ */
60
+ toggleSidebar(show: boolean): void;
61
+ private createSecuritySidebar;
62
+ private handleClose;
63
+ /**
64
+ * Get the modal body element for content rendering.
65
+ */
66
+ getBody(): HTMLDivElement | null;
67
+ /**
68
+ * Get the sidebar element.
69
+ */
70
+ getSidebar(): HTMLDivElement | null;
71
+ /**
72
+ * Check if the modal is currently open.
73
+ */
74
+ isOpen(): boolean;
75
+ /**
76
+ * Destroy the modal and clean up all event listeners.
77
+ */
78
+ destroy(): void;
79
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Upload Renderer
3
+ *
4
+ * Orchestrates view state and rendering for vault upload flows.
5
+ * Manages the complete upload lifecycle: form, uploading, ceremony, completion.
6
+ */
7
+ import type { UploadOptions, UploadResult, UploadProgress } from './types';
8
+ import type { UploadContainer } from './container';
9
+ import { UploadApi } from './api';
10
+ interface RendererCallbacks {
11
+ onSuccess: (result: UploadResult) => void;
12
+ onError: (error: Error) => void;
13
+ onCancel: () => void;
14
+ onProgress?: (progress: UploadProgress) => void;
15
+ }
16
+ export declare class UploadRenderer {
17
+ private readonly api;
18
+ private readonly container;
19
+ private readonly options;
20
+ private readonly callbacks;
21
+ private viewState;
22
+ private config;
23
+ private selectedFile;
24
+ private fileInputElement;
25
+ private uploadModal;
26
+ private isInlineMode;
27
+ private hybridModalInitialized;
28
+ private activeXhr;
29
+ constructor(container: UploadContainer, api: UploadApi, options: UploadOptions, callbacks: RendererCallbacks);
30
+ /**
31
+ * Start the upload flow.
32
+ */
33
+ start(): Promise<void>;
34
+ /**
35
+ * Close the upload flow.
36
+ * Cancels all pending API requests and active uploads to prevent orphaned operations.
37
+ */
38
+ close(): void;
39
+ private handleClose;
40
+ private setState;
41
+ private render;
42
+ /**
43
+ * Render uploading/ceremony states in a modal overlay (for inline mode).
44
+ * This provides the full polished experience during upload.
45
+ */
46
+ private renderInModal;
47
+ private renderLoading;
48
+ private renderForm;
49
+ private renderUploading;
50
+ private renderCeremony;
51
+ private renderComplete;
52
+ private renderError;
53
+ private handleFileSelect;
54
+ private openFileSelector;
55
+ private cleanupFileInput;
56
+ private pasteHandler;
57
+ private setupPasteHandler;
58
+ private cleanupPasteHandler;
59
+ private startUpload;
60
+ private uploadWithTus;
61
+ /**
62
+ * Upload a single chunk using XMLHttpRequest for progress tracking.
63
+ * Tracks the XHR so it can be cancelled if the renderer is closed.
64
+ */
65
+ private uploadChunkWithProgress;
66
+ private runCeremony;
67
+ private handleApiError;
68
+ private escapeHtml;
69
+ }
70
+ export {};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Upload Widget Styles
3
+ *
4
+ * Enterprise-grade styling for the vault upload widget.
5
+ * Follows the same design principles as the identity modal.
6
+ */
7
+ import type { UploadBranding } from './types';
8
+ export interface UploadStyleOptions {
9
+ branding?: UploadBranding;
10
+ backdropBlur?: boolean;
11
+ theme?: 'light' | 'dark';
12
+ }
13
+ /**
14
+ * Inject upload widget styles into the document head.
15
+ */
16
+ export declare function injectUploadStyles(options: UploadStyleOptions): void;
17
+ /**
18
+ * Remove upload widget styles.
19
+ */
20
+ export declare function removeUploadStyles(): void;