@sparkvault/sdk-js 2.2.1 → 2.2.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/api-base.d.ts +12 -0
- package/dist/http.d.ts +1 -24
- package/dist/identity/embedder.d.ts +8 -0
- package/dist/identity/index.d.ts +4 -1
- package/dist/identity/state.d.ts +2 -22
- package/dist/index.d.ts +16 -42
- package/dist/sparkvault.cjs.js +643 -911
- package/dist/sparkvault.cjs.js.map +1 -1
- package/dist/sparkvault.esm.js +643 -911
- package/dist/sparkvault.esm.js.map +1 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/utils/dom.d.ts +13 -4
- package/dist/vaults/index.d.ts +11 -0
- package/dist/vaults/upload/api.d.ts +31 -0
- package/dist/vaults/upload/chrome.d.ts +35 -0
- package/dist/vaults/upload/index.d.ts +3 -1
- package/dist/vaults/upload/inline-container.d.ts +0 -1
- package/dist/vaults/upload/modal.d.ts +0 -1
- package/dist/vaults/upload/renderer.d.ts +17 -8
- package/dist/vaults/upload/styles.d.ts +3 -11
- package/package.json +1 -1
- package/dist/utils/retry.d.ts +0 -32
package/dist/utils/dom.d.ts
CHANGED
|
@@ -10,8 +10,17 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function onDomReady(callback: () => void): void;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* Attach a click handler to every element matching `selector` — both elements
|
|
14
|
+
* present once the DOM is ready and elements added later (observed via
|
|
15
|
+
* MutationObserver).
|
|
16
|
+
*
|
|
17
|
+
* Each call is fully self-contained: the element bookkeeping lives in this
|
|
18
|
+
* closure, so the returned cleanup removes only the listeners this call
|
|
19
|
+
* registered. Multiple attachments — different selectors, or even the same
|
|
20
|
+
* element attached twice — never interfere with one another.
|
|
21
|
+
*
|
|
22
|
+
* @param selector - CSS selector for elements to attach to
|
|
23
|
+
* @param onClick - Click handler to register on every matching element
|
|
24
|
+
* @returns Cleanup function that removes this call's listeners and observer
|
|
16
25
|
*/
|
|
17
|
-
export declare function
|
|
26
|
+
export declare function attachClickHandler(selector: string, onClick: (event: Event) => void): () => void;
|
package/dist/vaults/index.d.ts
CHANGED
|
@@ -16,11 +16,22 @@ export interface UploadCallable {
|
|
|
16
16
|
(options: UploadOptions): Promise<UploadResult>;
|
|
17
17
|
attach(selector: string, options: UploadAttachOptions): () => void;
|
|
18
18
|
close(): void;
|
|
19
|
+
/** Open the upload widget as a popup. Equivalent to calling `upload(options)`. */
|
|
20
|
+
pop(options: UploadOptions): Promise<UploadResult>;
|
|
21
|
+
/** Render the upload widget inline. Equivalent to `upload({ ...options, target })`. */
|
|
22
|
+
render(options: UploadOptions): Promise<UploadResult>;
|
|
19
23
|
}
|
|
20
24
|
export declare class VaultsModule {
|
|
21
25
|
private readonly config;
|
|
22
26
|
private readonly http;
|
|
23
27
|
private readonly uploadModule;
|
|
28
|
+
/**
|
|
29
|
+
* Forge transfer client for authenticated ingot uploads. A dedicated
|
|
30
|
+
* instance: the widget's own client is session-scoped (reset/aborted with
|
|
31
|
+
* the widget lifecycle), and sharing it would let a widget close() abort
|
|
32
|
+
* an unrelated uploadIngot() transfer.
|
|
33
|
+
*/
|
|
34
|
+
private readonly uploadApi;
|
|
24
35
|
/**
|
|
25
36
|
* Upload to a vault with public upload enabled.
|
|
26
37
|
*
|
|
@@ -33,6 +33,37 @@ export declare class UploadApi extends SparkVaultApi {
|
|
|
33
33
|
forgeUrl: string;
|
|
34
34
|
ingotId: string;
|
|
35
35
|
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Upload a file to Forge over the TUS resumable protocol (v1.0.0).
|
|
38
|
+
*
|
|
39
|
+
* The single canonical browser transfer path — the upload widget and the
|
|
40
|
+
* authenticated `uploadIngot` flow both go through here (CLAUDE.md: one
|
|
41
|
+
* transfer path). Creates the session, PATCHes chunks sized by the server's
|
|
42
|
+
* `X-Chunk-Size` (50MB default, which keeps every request under CDN body
|
|
43
|
+
* caps such as Cloudflare's 100MB), validates every server-reported offset,
|
|
44
|
+
* and honors the session abort signal plus per-request timeouts.
|
|
45
|
+
*
|
|
46
|
+
* Returns the TUS session URL so the caller can confirm server-side
|
|
47
|
+
* finalization via {@link verifyUploadFinalized} before reporting success.
|
|
48
|
+
*/
|
|
49
|
+
uploadFileToForge(file: File | Blob, forgeUrl: string, onProgress?: (bytesUploaded: number, bytesTotal: number) => void): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Create the TUS upload session. Forge reads only `Tus-Resumable`,
|
|
52
|
+
* `Upload-Length`, and `X-ISTK` on create, and returns the session URL in
|
|
53
|
+
* `Location` (possibly relative) plus its chunk size in `X-Chunk-Size`.
|
|
54
|
+
*/
|
|
55
|
+
private createTusSession;
|
|
56
|
+
/**
|
|
57
|
+
* PATCH one chunk with XMLHttpRequest (fetch exposes no upload progress).
|
|
58
|
+
* Resolves with the server-confirmed offset for the next iteration.
|
|
59
|
+
*
|
|
60
|
+
* The server's `Upload-Offset` is validated, never trusted: it must be a
|
|
61
|
+
* finite number that strictly advances past this chunk's start (this client
|
|
62
|
+
* never sends an empty chunk, so a non-advancing 2xx would loop forever)
|
|
63
|
+
* and never exceeds the file size (an inflated offset would skip real
|
|
64
|
+
* chunks and report a partial upload as success).
|
|
65
|
+
*/
|
|
66
|
+
private patchChunk;
|
|
36
67
|
/**
|
|
37
68
|
* Confirm the upload was finalized SERVER-SIDE before reporting success.
|
|
38
69
|
*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Upload Widget Chrome
|
|
3
|
+
*
|
|
4
|
+
* Shared DOM builders for the branded chrome both upload containers render:
|
|
5
|
+
* brand header, "Secured by SparkVault" footer, and the Triple Zero-Trust
|
|
6
|
+
* security sidebar. One canonical copy — any branding/marketing/security-text
|
|
7
|
+
* change lands here and reaches modal and inline modes alike.
|
|
8
|
+
*/
|
|
9
|
+
import type { UploadBranding } from './types';
|
|
10
|
+
export interface BrandHeaderOptions {
|
|
11
|
+
branding: UploadBranding;
|
|
12
|
+
/** Pick the dark-mode logo variant when available. */
|
|
13
|
+
isDarkMode: boolean;
|
|
14
|
+
/** Render the close (×) button and wire `onClose` to its click. */
|
|
15
|
+
withCloseButton: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* id for the title node (logo screen-reader text or company name). The
|
|
18
|
+
* modal passes its `aria-labelledby` target id; inline omits it so a page
|
|
19
|
+
* embedding both never produces duplicate DOM ids.
|
|
20
|
+
*/
|
|
21
|
+
titleId?: string;
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build the branded header. Returns the close button (when rendered) so the
|
|
26
|
+
* container can detach `onClose` in its destroy() cleanup.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createBrandHeader(options: BrandHeaderOptions): {
|
|
29
|
+
header: HTMLDivElement;
|
|
30
|
+
closeBtn: HTMLButtonElement | null;
|
|
31
|
+
};
|
|
32
|
+
/** Build the "Secured by SparkVault" footer. */
|
|
33
|
+
export declare function createFooter(): HTMLDivElement;
|
|
34
|
+
/** Build the Triple Zero-Trust security sidebar shown during dark states. */
|
|
35
|
+
export declare function createSecuritySidebar(branding: UploadBranding): HTMLDivElement;
|
|
@@ -21,7 +21,6 @@ export declare class VaultUploadModule {
|
|
|
21
21
|
private readonly config;
|
|
22
22
|
private readonly api;
|
|
23
23
|
private renderer;
|
|
24
|
-
private attachedElements;
|
|
25
24
|
constructor(config: ResolvedConfig);
|
|
26
25
|
/**
|
|
27
26
|
* Upload a file to a vault.
|
|
@@ -60,6 +59,9 @@ export declare class VaultUploadModule {
|
|
|
60
59
|
attach(selector: string, options: UploadAttachOptions): () => void;
|
|
61
60
|
/**
|
|
62
61
|
* Close the upload dialog/inline UI if open.
|
|
62
|
+
*
|
|
63
|
+
* Programmatic close follows the cancel contract: the host's onCancel
|
|
64
|
+
* fires and the pending upload promise rejects with UserCancelledError.
|
|
63
65
|
*/
|
|
64
66
|
close(): void;
|
|
65
67
|
/**
|
|
@@ -58,7 +58,6 @@ export declare class UploadModalContainer implements UploadContainer {
|
|
|
58
58
|
* Show or hide the security sidebar.
|
|
59
59
|
*/
|
|
60
60
|
toggleSidebar(show: boolean): void;
|
|
61
|
-
private createSecuritySidebar;
|
|
62
61
|
private handleClose;
|
|
63
62
|
/**
|
|
64
63
|
* Get the modal body element for content rendering.
|
|
@@ -25,7 +25,8 @@ export declare class UploadRenderer {
|
|
|
25
25
|
private uploadModal;
|
|
26
26
|
private isInlineMode;
|
|
27
27
|
private hybridModalInitialized;
|
|
28
|
-
private
|
|
28
|
+
private closed;
|
|
29
|
+
private cancelled;
|
|
29
30
|
constructor(container: UploadContainer, api: UploadApi, options: UploadOptions, callbacks: RendererCallbacks);
|
|
30
31
|
/**
|
|
31
32
|
* Start the upload flow.
|
|
@@ -33,11 +34,25 @@ export declare class UploadRenderer {
|
|
|
33
34
|
start(): Promise<void>;
|
|
34
35
|
/**
|
|
35
36
|
* Close the upload flow.
|
|
36
|
-
* Cancels all pending API requests and active uploads
|
|
37
|
+
* Cancels all pending API requests and active uploads (aborting the session
|
|
38
|
+
* signal tears down any in-flight TUS chunk) to prevent orphaned operations.
|
|
37
39
|
*/
|
|
38
40
|
close(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Cancel the flow: tear everything down and fire the cancel contract
|
|
43
|
+
* exactly once. onCancel and onError are mutually exclusive — a deliberate
|
|
44
|
+
* cancellation (user close, programmatic close, or a new upload replacing
|
|
45
|
+
* this renderer) must never surface as an error to the host.
|
|
46
|
+
*/
|
|
47
|
+
cancel(): void;
|
|
39
48
|
private handleClose;
|
|
40
49
|
private setState;
|
|
50
|
+
/**
|
|
51
|
+
* Targeted DOM update for an already-rendered uploading view: progress fill
|
|
52
|
+
* width plus the percentage and byte-count labels. Returns false when the
|
|
53
|
+
* uploading view is not in the DOM, so the caller falls back to a full render.
|
|
54
|
+
*/
|
|
55
|
+
private updateUploadProgress;
|
|
41
56
|
private render;
|
|
42
57
|
/**
|
|
43
58
|
* Render uploading/ceremony states in a modal overlay (for inline mode).
|
|
@@ -57,12 +72,6 @@ export declare class UploadRenderer {
|
|
|
57
72
|
private setupPasteHandler;
|
|
58
73
|
private cleanupPasteHandler;
|
|
59
74
|
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
75
|
private runCeremony;
|
|
67
76
|
private handleApiError;
|
|
68
77
|
private escapeHtml;
|
|
@@ -4,17 +4,9 @@
|
|
|
4
4
|
* Enterprise-grade styling for the vault upload widget.
|
|
5
5
|
* Follows the same design principles as the identity modal.
|
|
6
6
|
*/
|
|
7
|
-
import type { UploadBranding } from './types';
|
|
8
|
-
export interface UploadStyleOptions {
|
|
9
|
-
branding?: UploadBranding;
|
|
10
|
-
backdropBlur?: boolean;
|
|
11
|
-
theme?: 'light' | 'dark';
|
|
12
|
-
}
|
|
13
7
|
/**
|
|
14
8
|
* Inject upload widget styles into the document head.
|
|
9
|
+
* Idempotent: the stylesheet is static and shared by every widget instance —
|
|
10
|
+
* per-instance behavior (backdrop blur, dark mode) is driven by class toggles.
|
|
15
11
|
*/
|
|
16
|
-
export declare function injectUploadStyles(
|
|
17
|
-
/**
|
|
18
|
-
* Remove upload widget styles.
|
|
19
|
-
*/
|
|
20
|
-
export declare function removeUploadStyles(): void;
|
|
12
|
+
export declare function injectUploadStyles(): void;
|
package/package.json
CHANGED
package/dist/utils/retry.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retry Utility with Exponential Backoff
|
|
3
|
-
*
|
|
4
|
-
* Per CLAUDE.md §7: Retries allowed only if idempotent, MUST use exponential backoff.
|
|
5
|
-
*/
|
|
6
|
-
export interface RetryOptions {
|
|
7
|
-
/** Maximum number of retry attempts (default: 3) */
|
|
8
|
-
maxAttempts?: number;
|
|
9
|
-
/** Base delay in milliseconds (default: 200) */
|
|
10
|
-
baseDelayMs?: number;
|
|
11
|
-
/** Maximum delay in milliseconds (default: 5000) */
|
|
12
|
-
maxDelayMs?: number;
|
|
13
|
-
/** Jitter factor 0-1 to randomize delays (default: 0.2) */
|
|
14
|
-
jitterFactor?: number;
|
|
15
|
-
/** Function to determine if error is retryable (default: checks for network/timeout/5xx) */
|
|
16
|
-
isRetryable?: (error: unknown) => boolean;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Execute an async function with retry logic and exponential backoff.
|
|
20
|
-
*
|
|
21
|
-
* @param fn - Async function to execute
|
|
22
|
-
* @param options - Retry configuration options
|
|
23
|
-
* @returns Promise resolving to the function result
|
|
24
|
-
* @throws The last error if all retries fail
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* const result = await withRetry(
|
|
28
|
-
* () => fetch('/api/data'),
|
|
29
|
-
* { maxAttempts: 3, baseDelayMs: 100 }
|
|
30
|
-
* );
|
|
31
|
-
*/
|
|
32
|
-
export declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
|