@sparkvault/sdk-js 11.1.13 → 11.2.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.
- package/dist/index.cjs +250 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +92 -8
- package/dist/index.mjs +250 -30
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/index.d.ts +46 -3
- package/dist/ingots/types.d.ts +20 -0
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/index.d.ts +7 -4
- package/dist/vaults/types.d.ts +41 -8
- package/dist/vaults/upload/api.d.ts +39 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -765,7 +765,27 @@ interface UnsealedVault {
|
|
|
765
765
|
/** VAT lifetime in seconds */
|
|
766
766
|
ttlSeconds: number;
|
|
767
767
|
}
|
|
768
|
-
|
|
768
|
+
/** Lifecycle metadata, including the lockout and seven-day cancellation window. */
|
|
769
|
+
interface VaultLifecycle {
|
|
770
|
+
/** sealed, unsealed, deletion_scheduled, or deleting */
|
|
771
|
+
status: string;
|
|
772
|
+
/** Unix seconds when deletion was requested */
|
|
773
|
+
deletionRequestedAt?: number;
|
|
774
|
+
/** Unix seconds after which deletion cannot be cancelled */
|
|
775
|
+
deletionScheduledFor?: number;
|
|
776
|
+
deletionRequestedBy?: string;
|
|
777
|
+
/** Pass this exact schedule to cancelDeletion. */
|
|
778
|
+
deletionScheduleId?: string;
|
|
779
|
+
}
|
|
780
|
+
interface ScheduledVaultDeletion {
|
|
781
|
+
id: string;
|
|
782
|
+
status: 'deletion_scheduled';
|
|
783
|
+
deletionRequestedAt: number;
|
|
784
|
+
deletionScheduledFor: number;
|
|
785
|
+
deletionRequestedBy: string;
|
|
786
|
+
deletionScheduleId: string;
|
|
787
|
+
}
|
|
788
|
+
interface VaultSummary extends VaultLifecycle {
|
|
769
789
|
/** Vault ID */
|
|
770
790
|
id: string;
|
|
771
791
|
/** Vault name */
|
|
@@ -792,15 +812,13 @@ interface VaultPage {
|
|
|
792
812
|
nextCursor?: string;
|
|
793
813
|
}
|
|
794
814
|
/** A single vault's detail, as returned by get. */
|
|
795
|
-
interface VaultDetail {
|
|
815
|
+
interface VaultDetail extends VaultLifecycle {
|
|
796
816
|
/** Vault ID */
|
|
797
817
|
id: string;
|
|
798
818
|
/** Vault name */
|
|
799
819
|
name: string;
|
|
800
820
|
/** Optional description */
|
|
801
821
|
description: string | null;
|
|
802
|
-
/** Sealed/unsealed status */
|
|
803
|
-
status: string;
|
|
804
822
|
/** Number of ingots */
|
|
805
823
|
ingotCount: number;
|
|
806
824
|
/** Total storage used in bytes */
|
|
@@ -2069,7 +2087,8 @@ declare class VaultsModule {
|
|
|
2069
2087
|
*/
|
|
2070
2088
|
seal(vaultId: string): Promise<void>;
|
|
2071
2089
|
/**
|
|
2072
|
-
*
|
|
2090
|
+
* Schedule permanent deletion in seven days and immediately lock all vault access.
|
|
2091
|
+
* Company admins only; cancelDeletion can abort this schedule before its deadline.
|
|
2073
2092
|
*
|
|
2074
2093
|
* Requires the vault's exact name as confirmation, matched case-sensitively.
|
|
2075
2094
|
* The name is sent base64(UTF-8) as the `X-Confirm-Name-B64` header so a vault
|
|
@@ -2079,7 +2098,9 @@ declare class VaultsModule {
|
|
|
2079
2098
|
* @example
|
|
2080
2099
|
* await sv.vaults.delete('vlt_abc', 'My Vault');
|
|
2081
2100
|
*/
|
|
2082
|
-
delete(vaultId: string, name: string): Promise<
|
|
2101
|
+
delete(vaultId: string, name: string): Promise<ScheduledVaultDeletion>;
|
|
2102
|
+
/** Cancel this exact deletion schedule before its deadline; company admins only. */
|
|
2103
|
+
cancelDeletion(vaultId: string, deletionScheduleId: string): Promise<VaultDetail>;
|
|
2083
2104
|
/**
|
|
2084
2105
|
* Get a vault's public-sharing configuration.
|
|
2085
2106
|
*
|
|
@@ -2362,13 +2383,33 @@ interface UploadIngotOptions {
|
|
|
2362
2383
|
/** Progress callback for the Forge/TUS transfer */
|
|
2363
2384
|
onProgress?: (bytesUploaded: number, bytesTotal: number) => void;
|
|
2364
2385
|
}
|
|
2386
|
+
/**
|
|
2387
|
+
* The upload session a file's bytes go to, which `sendUpload` hands over once
|
|
2388
|
+
* Forge opens it (`onSessionCreated`): what `resumeUpload` continues the
|
|
2389
|
+
* upload in. Its URL addresses the upload itself (a request to it can end the
|
|
2390
|
+
* upload), so keep it in memory, never in a log or a URL a person shares.
|
|
2391
|
+
*/
|
|
2392
|
+
interface UploadSession {
|
|
2393
|
+
/** The session's URL on Forge. */
|
|
2394
|
+
readonly sessionUrl: string;
|
|
2395
|
+
}
|
|
2365
2396
|
/** Options for sendUpload. */
|
|
2366
2397
|
interface SendUploadOptions {
|
|
2367
2398
|
/** Cancels the transfer. */
|
|
2368
2399
|
signal?: AbortSignal;
|
|
2369
2400
|
/** Bytes sent so far and the file size; never runs backwards. */
|
|
2370
2401
|
onProgress?: (bytesUploaded: number, bytesTotal: number) => void;
|
|
2402
|
+
/**
|
|
2403
|
+
* Hands over the upload's session once Forge opens it, before the first
|
|
2404
|
+
* byte is sent, so the caller can `resumeUpload` the upload in it later:
|
|
2405
|
+
* after `upload_received_publishing`, to learn whether the server published
|
|
2406
|
+
* it, or after a failure, to send only the bytes the server lacks. A throw
|
|
2407
|
+
* here ends the transfer with that error.
|
|
2408
|
+
*/
|
|
2409
|
+
onSessionCreated?: (session: UploadSession) => void;
|
|
2371
2410
|
}
|
|
2411
|
+
/** Options for resumeUpload. */
|
|
2412
|
+
type ResumeUploadOptions = Omit<SendUploadOptions, 'onSessionCreated'>;
|
|
2372
2413
|
/** Options for replacing an existing ingot's content. */
|
|
2373
2414
|
interface ReplaceIngotOptions {
|
|
2374
2415
|
/** File or Blob to upload as the new content */
|
|
@@ -2631,11 +2672,15 @@ declare class IngotsModule {
|
|
|
2631
2672
|
* `details.coreCode`: a new upload is no remedy. A publication the server
|
|
2632
2673
|
* still defers at the transfer's idle limit rejects with code
|
|
2633
2674
|
* `upload_received_publishing`: every byte is received, and the server
|
|
2634
|
-
* finishes the publication on its own, so never upload the file again
|
|
2675
|
+
* finishes the publication on its own, so never upload the file again; a
|
|
2676
|
+
* caller that kept the session (`onSessionCreated`) learns what became of
|
|
2677
|
+
* it with {@link resumeUpload}.
|
|
2635
2678
|
*
|
|
2636
2679
|
* @param options.signal - Cancels this transfer (it rejects with code
|
|
2637
2680
|
* `cancelled`); other transfers carry on.
|
|
2638
2681
|
* @param options.onProgress - Bytes sent so far and the file size; never runs backwards.
|
|
2682
|
+
* @param options.onSessionCreated - Hands over the upload's session once
|
|
2683
|
+
* Forge opens it, before the first byte is sent.
|
|
2639
2684
|
*
|
|
2640
2685
|
* @example
|
|
2641
2686
|
* const session = await sv.ingots.createUpload({ vault: unsealed, name: file.name,
|
|
@@ -2643,6 +2688,45 @@ declare class IngotsModule {
|
|
|
2643
2688
|
* await sv.ingots.sendUpload(session.uploadUrl, file, { signal: controller.signal });
|
|
2644
2689
|
*/
|
|
2645
2690
|
sendUpload(uploadUrl: string, file: File | Blob, options?: SendUploadOptions): Promise<void>;
|
|
2691
|
+
/**
|
|
2692
|
+
* Continue an upload in the session a {@link sendUpload} opened for the same
|
|
2693
|
+
* file (the `session` its `onSessionCreated` handed over): Forge is asked
|
|
2694
|
+
* where the session stands, only the bytes it lacks are sent, and the
|
|
2695
|
+
* promise resolves once the server confirms the ingot is published. A
|
|
2696
|
+
* session that already holds every byte sends none and only asks: this is
|
|
2697
|
+
* how a caller follows an upload that ended `upload_received_publishing`
|
|
2698
|
+
* until the server publishes it or ends it.
|
|
2699
|
+
*
|
|
2700
|
+
* It rejects as {@link sendUpload} does: `session_gone` once the server no
|
|
2701
|
+
* longer holds the session (it expired, was cancelled, or ended when the
|
|
2702
|
+
* server refused to publish it), `upload_refused` for an upload refused for
|
|
2703
|
+
* good, `upload_received_publishing` again for a publication the server
|
|
2704
|
+
* still defers at the transfer's idle limit, which leaves the session to
|
|
2705
|
+
* resume again later. A session URL that is not an upload session on an
|
|
2706
|
+
* allowed transfer host is refused (`invalid_forge_url`), and one whose
|
|
2707
|
+
* upload is not this file's length (`session_mismatch`), before a byte is
|
|
2708
|
+
* sent.
|
|
2709
|
+
*
|
|
2710
|
+
* @param options.signal - Cancels this transfer (it rejects with code
|
|
2711
|
+
* `cancelled`); the session stays as it stands.
|
|
2712
|
+
* @param options.onProgress - Bytes the session holds so far and the file size; never runs backwards.
|
|
2713
|
+
*
|
|
2714
|
+
* @example
|
|
2715
|
+
* let session;
|
|
2716
|
+
* try {
|
|
2717
|
+
* await sv.ingots.sendUpload(upload.uploadUrl, file, { onSessionCreated: (s) => { session = s; } });
|
|
2718
|
+
* } catch (error) {
|
|
2719
|
+
* if (error.code !== 'upload_received_publishing') throw error;
|
|
2720
|
+
* await sv.ingots.resumeUpload(session, file);
|
|
2721
|
+
* }
|
|
2722
|
+
*/
|
|
2723
|
+
resumeUpload(session: UploadSession, file: File | Blob, options?: ResumeUploadOptions): Promise<void>;
|
|
2724
|
+
/**
|
|
2725
|
+
* Run one transfer on a transfer client of its own: its abort is scoped to
|
|
2726
|
+
* its own session, so cancelling one upload never touches another in
|
|
2727
|
+
* flight, and the caller's signal cancels it (code `cancelled`).
|
|
2728
|
+
*/
|
|
2729
|
+
private runTransfer;
|
|
2646
2730
|
/**
|
|
2647
2731
|
* Upload a file as a new ingot (high-level flow).
|
|
2648
2732
|
*
|
|
@@ -3444,4 +3528,4 @@ declare global {
|
|
|
3444
3528
|
}
|
|
3445
3529
|
|
|
3446
3530
|
export { AuthenticationError, AuthorizationError, EntropyModule, FoldersModule, IdentityModule, IngotsModule, NAME_CONFLICT_POLICIES, NOTIFY_PRESETS, NetworkError, NotifyModule, NotifyProductModule, NotifySubscriptionRequiredError, PlanRequiredError, PopupBlockedError, ProductsModule, QuotaExceededError, SparkVault, SparkVaultError, SparksModule, TimeoutError, UserCancelledError, ValidationError, VaultsModule, buildNotifyPresetSend, SparkVault as default, fetchDownload, logger, setDebugMode };
|
|
3447
|
-
export type { AccessLogRetention, AccessLogsOptions, CreateFolderOptions, CreateNotifySendOptions, CreateSparkOptions, CreateUploadOptions, CreateVaultOptions, CreatedIngot, CreatedSpark, EntropyFormat, EntropyResult, FetchDownloadOptions, FetchedDownload, Folder, FolderBreadcrumbItem, FolderContents, GenerateEntropyOptions, HealthCheckOptions, HealthCheckResult, AttachOptions as IdentityAttachOptions, Ingot, IngotAccessLog, IngotAccessLogPage, IngotDownloadLink, IngotInvite, IngotPage, IngotSharingConfig, IngotUpload, ListContentsOptions, ListIngotsOptions, ListNotificationsOptions, ListNotificationsResponse, ListNotifyInboxOptions, ListNotifyInboxResponse, ListNotifyReceiptsOptions, ListNotifyReceiptsResponse, ListNotifySendsOptions, ListNotifySendsResponse, ListSparksOptions, MarkAllNotificationsStateOptions, MarkAllNotificationsStateResponse, MarkAllReadResult, MarkNotificationStateOptions, MarkNotificationStateResponse, MarkNotifyInboxAllOptions, MarkNotifyInboxAllResponse, MarkNotifyInboxStateOptions, MarkNotifyInboxStateResponse, NameConflictPolicy, NotificationBulkMarkState, NotificationInboxState, NotificationMarkState, NotificationRow, NotifyCategory, NotifyChannel, NotifyConfig, NotifyConfigCategory, NotifyConfigDelivery, NotifyConfigEvents, NotifyConfigEventsRead, NotifyConfigHistory, NotifyConfigOverrides, NotifyConfigPatch, NotifyConfigRealtimeFallbackDelay, NotifyConfigReliability, NotifyConfigResponse, NotifyConfigSecurity, NotifyDeliveryMode, NotifyEscalation, NotifyInboxBulkMarkState, NotifyInboxMarkState, NotifyInboxRow, NotifyInboxView, NotifyIngotRef, NotifyInteraction, NotifyPreset, NotifyPresetCategory, NotifyPresetName, NotifyPresetSendOptions, NotifyRecallMode, NotifyReceipt, NotifyReceiptEventType, NotifyRecipient, NotifyRecipientRef, NotifySendContent, NotifySendPolicy, NotifySendReceipt, NotifySendReceiptsResponse, NotifySendResult, NotifySendState, NotifySendStatus, NotifySendStatusCounts, NotifySendStatusRecipient, NotifySendSummary, NotifyVerificationLevel, QuotaResource, RecallNotifySendOptions, RecallNotifySendResponse, RegisterWebPushResponse, ReplaceIngotOptions, SearchIngotsOptions, SendUploadOptions, ShareSparkOptions, Spark, SparkPage, SparkShare, SparkSummary, SparkVaultConfig, SparkVisibility, SubscribeWebPushOptions, SubscribeWebPushResult, SubscribeWebPushStatus, TokenClaims, UnreadCountResponse, UnsealedVault, UnsubscribeWebPushResponse, UpdateFolderOptions, UpdateIngotSharingOptions, UpdateVaultUploadOptions, UpdatedVault, UploadAttachOptions, UploadBranding, UploadIngotOptions, UploadOptions, UploadProgress, UploadResult, Vault, VaultDetail, VaultSharingConfig, VaultSharingOptions, VaultSummary, VaultUploadConfig, VaultUploadSettings, VerifyOptions, VerifyResult, WebPushKeyResponse, WebPushSubscriptionInput };
|
|
3531
|
+
export type { AccessLogRetention, AccessLogsOptions, CreateFolderOptions, CreateNotifySendOptions, CreateSparkOptions, CreateUploadOptions, CreateVaultOptions, CreatedIngot, CreatedSpark, EntropyFormat, EntropyResult, FetchDownloadOptions, FetchedDownload, Folder, FolderBreadcrumbItem, FolderContents, GenerateEntropyOptions, HealthCheckOptions, HealthCheckResult, AttachOptions as IdentityAttachOptions, Ingot, IngotAccessLog, IngotAccessLogPage, IngotDownloadLink, IngotInvite, IngotPage, IngotSharingConfig, IngotUpload, ListContentsOptions, ListIngotsOptions, ListNotificationsOptions, ListNotificationsResponse, ListNotifyInboxOptions, ListNotifyInboxResponse, ListNotifyReceiptsOptions, ListNotifyReceiptsResponse, ListNotifySendsOptions, ListNotifySendsResponse, ListSparksOptions, MarkAllNotificationsStateOptions, MarkAllNotificationsStateResponse, MarkAllReadResult, MarkNotificationStateOptions, MarkNotificationStateResponse, MarkNotifyInboxAllOptions, MarkNotifyInboxAllResponse, MarkNotifyInboxStateOptions, MarkNotifyInboxStateResponse, NameConflictPolicy, NotificationBulkMarkState, NotificationInboxState, NotificationMarkState, NotificationRow, NotifyCategory, NotifyChannel, NotifyConfig, NotifyConfigCategory, NotifyConfigDelivery, NotifyConfigEvents, NotifyConfigEventsRead, NotifyConfigHistory, NotifyConfigOverrides, NotifyConfigPatch, NotifyConfigRealtimeFallbackDelay, NotifyConfigReliability, NotifyConfigResponse, NotifyConfigSecurity, NotifyDeliveryMode, NotifyEscalation, NotifyInboxBulkMarkState, NotifyInboxMarkState, NotifyInboxRow, NotifyInboxView, NotifyIngotRef, NotifyInteraction, NotifyPreset, NotifyPresetCategory, NotifyPresetName, NotifyPresetSendOptions, NotifyRecallMode, NotifyReceipt, NotifyReceiptEventType, NotifyRecipient, NotifyRecipientRef, NotifySendContent, NotifySendPolicy, NotifySendReceipt, NotifySendReceiptsResponse, NotifySendResult, NotifySendState, NotifySendStatus, NotifySendStatusCounts, NotifySendStatusRecipient, NotifySendSummary, NotifyVerificationLevel, QuotaResource, RecallNotifySendOptions, RecallNotifySendResponse, RegisterWebPushResponse, ReplaceIngotOptions, ResumeUploadOptions, ScheduledVaultDeletion, SearchIngotsOptions, SendUploadOptions, ShareSparkOptions, Spark, SparkPage, SparkShare, SparkSummary, SparkVaultConfig, SparkVisibility, SubscribeWebPushOptions, SubscribeWebPushResult, SubscribeWebPushStatus, TokenClaims, UnreadCountResponse, UnsealedVault, UnsubscribeWebPushResponse, UpdateFolderOptions, UpdateIngotSharingOptions, UpdateVaultUploadOptions, UpdatedVault, UploadAttachOptions, UploadBranding, UploadIngotOptions, UploadOptions, UploadProgress, UploadResult, UploadSession, Vault, VaultDetail, VaultLifecycle, VaultSharingConfig, VaultSharingOptions, VaultSummary, VaultUploadConfig, VaultUploadSettings, VerifyOptions, VerifyResult, WebPushKeyResponse, WebPushSubscriptionInput };
|
package/dist/index.mjs
CHANGED
|
@@ -11563,6 +11563,27 @@ function resolveForgeSessionUrl(location, endpoint) {
|
|
|
11563
11563
|
return SESSION_ID_PATTERN.test(session) ? `${origin}${base.path}/${session}` : null;
|
|
11564
11564
|
}
|
|
11565
11565
|
|
|
11566
|
+
/**
|
|
11567
|
+
* Read a tus session URL a client kept to resume an upload: a session Forge
|
|
11568
|
+
* opened directly under the operation's endpoint on an allowed host, exactly
|
|
11569
|
+
* as resolveForgeSessionUrl placed it when the session was created. A resumed
|
|
11570
|
+
* session receives the ISTK and the file's bytes, so it is held to the rule a
|
|
11571
|
+
* created one was.
|
|
11572
|
+
*
|
|
11573
|
+
* @param {unknown} value
|
|
11574
|
+
* @param {Object} options
|
|
11575
|
+
* @param {'encrypt'|'decrypt'} options.operation - The transfer the session belongs to
|
|
11576
|
+
* @param {(hostname: string) => boolean} [options.isAllowedHost] - As for readForgeTransferUrl
|
|
11577
|
+
* @returns {{ ok: true, url: string } | { ok: false, reason: string }}
|
|
11578
|
+
*/
|
|
11579
|
+
function readForgeSessionUrl(value, { operation, isAllowedHost = isForgeHost }) {
|
|
11580
|
+
const url = readHttpsUrl(value);
|
|
11581
|
+
if (!url.ok) return url;
|
|
11582
|
+
if (!isAllowedHost(url.hostname)) return refused(FORGE_URL_REFUSAL.HOST);
|
|
11583
|
+
const session = resolveForgeSessionUrl(value, `https://${url.hostname}/${operation}`);
|
|
11584
|
+
return session === null ? refused(FORGE_URL_REFUSAL.OPERATION) : { ok: true, url: session };
|
|
11585
|
+
}
|
|
11586
|
+
|
|
11566
11587
|
/**
|
|
11567
11588
|
* Cut an https URL into its host name, path and query by string rules alone.
|
|
11568
11589
|
* @param {unknown} value
|
|
@@ -11691,6 +11712,13 @@ function parseChunkSizeHeader(raw) {
|
|
|
11691
11712
|
const value = Number(raw);
|
|
11692
11713
|
return Number.isSafeInteger(value) && value > 0 ? value : null;
|
|
11693
11714
|
}
|
|
11715
|
+
/** Strict whole-number parse of a session's `Upload-Length`; anything else is `null`. */
|
|
11716
|
+
function parseLengthHeader(raw) {
|
|
11717
|
+
if (raw === null || !/^\d+$/.test(raw.trim()))
|
|
11718
|
+
return null;
|
|
11719
|
+
const value = Number(raw);
|
|
11720
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
11721
|
+
}
|
|
11694
11722
|
/**
|
|
11695
11723
|
* Abort a stalled chunk PATCH after this long with no upload progress.
|
|
11696
11724
|
* XHR's own `timeout` measures total request duration, which would abort a
|
|
@@ -11771,6 +11799,12 @@ function stagingRefusalOf(error) {
|
|
|
11771
11799
|
function cancelledError() {
|
|
11772
11800
|
return new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
11773
11801
|
}
|
|
11802
|
+
/** Refuse a transfer where the browser's XMLHttpRequest is missing: a chunk's upload progress needs it. */
|
|
11803
|
+
function assertBrowserTransfer() {
|
|
11804
|
+
if (typeof XMLHttpRequest === 'undefined') {
|
|
11805
|
+
throw new UploadApiError('XMLHttpRequest is required for browser uploads', 'environment_unsupported', 0);
|
|
11806
|
+
}
|
|
11807
|
+
}
|
|
11774
11808
|
/**
|
|
11775
11809
|
* A delay that a cancel cuts short: resolves after `ms`, rejects with the
|
|
11776
11810
|
* canonical cancelled error the moment the signal aborts.
|
|
@@ -12111,12 +12145,13 @@ class UploadApi extends SparkVaultApi {
|
|
|
12111
12145
|
* Resolves only once the server has confirmed finalization
|
|
12112
12146
|
* ({@link confirmServerFinalized}), so a caller that gets a resolved promise
|
|
12113
12147
|
* is always looking at a published ingot; a publication the server still
|
|
12114
|
-
* defers at the idle limit throws `upload_received_publishing`.
|
|
12148
|
+
* defers at the idle limit throws `upload_received_publishing`. The
|
|
12149
|
+
* session's URL goes to `onSessionCreated` once Forge opens it, before the
|
|
12150
|
+
* first byte, so the caller can continue the upload in it
|
|
12151
|
+
* ({@link resumeUploadToForge}) whatever becomes of this transfer.
|
|
12115
12152
|
*/
|
|
12116
|
-
async uploadFileToForge(file, forgeUrl, onProgress) {
|
|
12117
|
-
|
|
12118
|
-
throw new UploadApiError('XMLHttpRequest is required for browser uploads', 'environment_unsupported', 0);
|
|
12119
|
-
}
|
|
12153
|
+
async uploadFileToForge(file, forgeUrl, onProgress, onSessionCreated) {
|
|
12154
|
+
assertBrowserTransfer();
|
|
12120
12155
|
const target = readForgeTransferUrl(forgeUrl, {
|
|
12121
12156
|
operation: 'encrypt',
|
|
12122
12157
|
isAllowedHost: (hostname) => isAllowedTransferHost(this.config, hostname),
|
|
@@ -12135,13 +12170,66 @@ class UploadApi extends SparkVaultApi {
|
|
|
12135
12170
|
if (!uploadUrl) {
|
|
12136
12171
|
throw new UploadApiError('Upload session is outside the upload endpoint', 'tus_create_failed', 0);
|
|
12137
12172
|
}
|
|
12138
|
-
|
|
12173
|
+
// Handed over before the first byte, so a caller can continue the upload
|
|
12174
|
+
// in this session whatever becomes of this transfer. It addresses the
|
|
12175
|
+
// upload itself, so it is never logged.
|
|
12176
|
+
onSessionCreated?.(uploadUrl);
|
|
12177
|
+
await this.sendFile(file, {
|
|
12139
12178
|
uploadUrl,
|
|
12140
12179
|
totalSize: file.size,
|
|
12141
12180
|
chunkSize: session.chunkSize,
|
|
12142
12181
|
budget,
|
|
12143
12182
|
sessionSignal,
|
|
12183
|
+
}, 0, onProgress);
|
|
12184
|
+
}
|
|
12185
|
+
/**
|
|
12186
|
+
* Continue an upload in the session {@link uploadFileToForge} opened for
|
|
12187
|
+
* `file` (the session URL its `onSessionCreated` handed over), through the same
|
|
12188
|
+
* transfer: Forge is asked where the session stands (a HEAD, retried under
|
|
12189
|
+
* the transfer policy as any request of the upload is), only the bytes it
|
|
12190
|
+
* lacks are sent, and the upload resolves on the same receipt, so a
|
|
12191
|
+
* resolved promise is a published ingot. A session at its full offset sends
|
|
12192
|
+
* no byte and only takes the receipt: this is how a caller learns what
|
|
12193
|
+
* became of an upload whose publication was still deferred
|
|
12194
|
+
* (`upload_received_publishing`). It throws as an upload does: `session_gone`
|
|
12195
|
+
* once Forge no longer holds the session (cancelled, expired, or ended when
|
|
12196
|
+
* Core refused its publication), `upload_refused` for a refusal Core
|
|
12197
|
+
* decided, `upload_received_publishing` again for a publication still
|
|
12198
|
+
* deferred at the idle limit. A session URL that is not an upload session
|
|
12199
|
+
* on an allowed transfer host is refused (`invalid_forge_url`), and one
|
|
12200
|
+
* whose upload is not this file's length (`session_mismatch`), before any
|
|
12201
|
+
* byte is sent.
|
|
12202
|
+
*/
|
|
12203
|
+
async resumeUploadToForge(file, sessionUrl, onProgress) {
|
|
12204
|
+
assertBrowserTransfer();
|
|
12205
|
+
const target = readForgeSessionUrl(sessionUrl, {
|
|
12206
|
+
operation: 'encrypt',
|
|
12207
|
+
isAllowedHost: (hostname) => isAllowedTransferHost(this.config, hostname),
|
|
12208
|
+
});
|
|
12209
|
+
if (!target.ok) {
|
|
12210
|
+
throw new UploadApiError('Forge upload session URL was refused', 'invalid_forge_url', 0, { reason: target.reason });
|
|
12211
|
+
}
|
|
12212
|
+
const sessionSignal = this.getAbortSignal();
|
|
12213
|
+
const budget = createTransferBudget();
|
|
12214
|
+
const standing = await this.readSessionStanding(target.url, budget, sessionSignal);
|
|
12215
|
+
if (standing.length !== file.size) {
|
|
12216
|
+
throw new UploadApiError('The upload session is for a file of another length', 'session_mismatch', 0, { sessionLength: standing.length, fileSize: file.size });
|
|
12217
|
+
}
|
|
12218
|
+
const transfer = {
|
|
12219
|
+
uploadUrl: target.url,
|
|
12220
|
+
totalSize: file.size,
|
|
12221
|
+
chunkSize: standing.chunkSize,
|
|
12222
|
+
budget,
|
|
12223
|
+
sessionSignal,
|
|
12144
12224
|
};
|
|
12225
|
+
await this.sendFile(file, transfer, this.checkResumeOffset(standing.offset, transfer), onProgress);
|
|
12226
|
+
}
|
|
12227
|
+
/**
|
|
12228
|
+
* Send `file` into its session from `offset` (0 for a session just opened,
|
|
12229
|
+
* the server's own offset for a resumed one) until the receipt confirms
|
|
12230
|
+
* publication: the one loop every transfer runs.
|
|
12231
|
+
*/
|
|
12232
|
+
async sendFile(file, transfer, offset, onProgress) {
|
|
12145
12233
|
// Retries make raw progress non-monotonic (a chunk that streamed to 90%
|
|
12146
12234
|
// then failed re-reports from its start on resend); callers get only the
|
|
12147
12235
|
// high-water mark so a progress bar never runs backwards.
|
|
@@ -12154,9 +12242,10 @@ class UploadApi extends SparkVaultApi {
|
|
|
12154
12242
|
}
|
|
12155
12243
|
}
|
|
12156
12244
|
: undefined;
|
|
12157
|
-
|
|
12245
|
+
// A resumed session already holds its first bytes.
|
|
12246
|
+
monotonicProgress?.(offset, file.size);
|
|
12158
12247
|
for (;;) {
|
|
12159
|
-
if (sessionSignal.aborted) {
|
|
12248
|
+
if (transfer.sessionSignal.aborted) {
|
|
12160
12249
|
throw cancelledError();
|
|
12161
12250
|
}
|
|
12162
12251
|
// One exit, one receipt: however the loop learned that every byte is on
|
|
@@ -12169,7 +12258,7 @@ class UploadApi extends SparkVaultApi {
|
|
|
12169
12258
|
offset = receipt.resumeAt;
|
|
12170
12259
|
continue;
|
|
12171
12260
|
}
|
|
12172
|
-
const chunkEnd = Math.min(offset +
|
|
12261
|
+
const chunkEnd = Math.min(offset + transfer.chunkSize, file.size);
|
|
12173
12262
|
try {
|
|
12174
12263
|
offset = await this.patchChunk(transfer, file.slice(offset, chunkEnd), offset, monotonicProgress);
|
|
12175
12264
|
transfer.budget.progressed();
|
|
@@ -12295,6 +12384,36 @@ class UploadApi extends SparkVaultApi {
|
|
|
12295
12384
|
}
|
|
12296
12385
|
}
|
|
12297
12386
|
}
|
|
12387
|
+
/**
|
|
12388
|
+
* Where a session a resume continues stands, from its HEAD: the bytes it
|
|
12389
|
+
* holds, the length of the upload it was opened for, and its chunk size
|
|
12390
|
+
* (Forge echoes `X-Chunk-Size` on a HEAD as on the create). A HEAD that
|
|
12391
|
+
* fails is asked again under the upload's budget as any request of it is;
|
|
12392
|
+
* a session the server no longer holds throws `session_gone`, and a refusal
|
|
12393
|
+
* Core decided its `upload_refused`.
|
|
12394
|
+
*/
|
|
12395
|
+
async readSessionStanding(sessionUrl, budget, sessionSignal) {
|
|
12396
|
+
for (;;) {
|
|
12397
|
+
try {
|
|
12398
|
+
const { response, outcome } = await this.tusRequest(sessionUrl, { method: 'HEAD', headers: { 'Tus-Resumable': TUS_VERSION } }, RESUME_CHECK);
|
|
12399
|
+
const chunkSizeHeader = response.headers.get('X-Chunk-Size');
|
|
12400
|
+
const chunkSize = parseChunkSizeHeader(chunkSizeHeader);
|
|
12401
|
+
if (chunkSize === null) {
|
|
12402
|
+
throw new UploadApiError('Server did not return a valid X-Chunk-Size', RESUME_CHECK.code, response.status, { header: 'X-Chunk-Size', received: chunkSizeHeader });
|
|
12403
|
+
}
|
|
12404
|
+
// The session stands: the server confirmed it.
|
|
12405
|
+
budget.progressed();
|
|
12406
|
+
return { offset: outcome.offset, length: parseLengthHeader(response.headers.get('Upload-Length')), chunkSize };
|
|
12407
|
+
}
|
|
12408
|
+
catch (error) {
|
|
12409
|
+
const failure = transferFailure(error);
|
|
12410
|
+
if (failure.verdict === TRANSFER_VERDICT.GONE) {
|
|
12411
|
+
throw sessionGoneError(failure);
|
|
12412
|
+
}
|
|
12413
|
+
await waitToRetry(budget, failure, sessionUrl, sessionSignal);
|
|
12414
|
+
}
|
|
12415
|
+
}
|
|
12416
|
+
}
|
|
12298
12417
|
/**
|
|
12299
12418
|
* Read the offset a failed chunk should resume from, from the session's
|
|
12300
12419
|
* HEAD. At the full offset it proves receipt only, published or not, so the
|
|
@@ -15071,6 +15190,7 @@ class VaultsModule {
|
|
|
15071
15190
|
createdAt: v.created_at,
|
|
15072
15191
|
ingotCount: v.ingot_count,
|
|
15073
15192
|
storageBytes: v.storage_bytes,
|
|
15193
|
+
...mapLifecycle(v),
|
|
15074
15194
|
})),
|
|
15075
15195
|
nextCursor: response.data.next_cursor,
|
|
15076
15196
|
};
|
|
@@ -15085,18 +15205,7 @@ class VaultsModule {
|
|
|
15085
15205
|
async get(vaultId) {
|
|
15086
15206
|
const id = requireResourceId(vaultId, 'vaultId');
|
|
15087
15207
|
const response = await this.http.get(apiPath `/v1/vaults/${id}`);
|
|
15088
|
-
|
|
15089
|
-
return {
|
|
15090
|
-
id: v.vault_id,
|
|
15091
|
-
name: v.name,
|
|
15092
|
-
description: v.description ?? null,
|
|
15093
|
-
status: v.status,
|
|
15094
|
-
ingotCount: v.ingot_count ?? 0,
|
|
15095
|
-
storageBytes: v.storage_bytes ?? 0,
|
|
15096
|
-
createdAt: v.created_at,
|
|
15097
|
-
lastUnsealedAt: v.last_unsealed_at ?? null,
|
|
15098
|
-
unsealCount: v.unseal_count ?? 0,
|
|
15099
|
-
};
|
|
15208
|
+
return mapVaultDetail(response.data);
|
|
15100
15209
|
}
|
|
15101
15210
|
/**
|
|
15102
15211
|
* Rename a vault.
|
|
@@ -15131,7 +15240,8 @@ class VaultsModule {
|
|
|
15131
15240
|
await this.http.post(apiPath `/v1/vaults/${id}/seal`);
|
|
15132
15241
|
}
|
|
15133
15242
|
/**
|
|
15134
|
-
*
|
|
15243
|
+
* Schedule permanent deletion in seven days and immediately lock all vault access.
|
|
15244
|
+
* Company admins only; cancelDeletion can abort this schedule before its deadline.
|
|
15135
15245
|
*
|
|
15136
15246
|
* Requires the vault's exact name as confirmation, matched case-sensitively.
|
|
15137
15247
|
* The name is sent base64(UTF-8) as the `X-Confirm-Name-B64` header so a vault
|
|
@@ -15146,9 +15256,32 @@ class VaultsModule {
|
|
|
15146
15256
|
if (!name) {
|
|
15147
15257
|
throw new ValidationError('Vault name is required to confirm deletion');
|
|
15148
15258
|
}
|
|
15149
|
-
await this.http.delete(apiPath `/v1/vaults/${id}`, {
|
|
15150
|
-
headers: {
|
|
15259
|
+
const response = await this.http.delete(apiPath `/v1/vaults/${id}`, {
|
|
15260
|
+
headers: {
|
|
15261
|
+
'X-Confirm-Name-B64': base64EncodeUtf8(name),
|
|
15262
|
+
'X-Vault-Deletion-Mode': 'schedule',
|
|
15263
|
+
},
|
|
15264
|
+
});
|
|
15265
|
+
const scheduled = response.data;
|
|
15266
|
+
return {
|
|
15267
|
+
id: scheduled.vault_id,
|
|
15268
|
+
status: scheduled.status,
|
|
15269
|
+
deletionRequestedAt: scheduled.deletion_requested_at,
|
|
15270
|
+
deletionScheduledFor: scheduled.deletion_scheduled_for,
|
|
15271
|
+
deletionRequestedBy: scheduled.deletion_requested_by,
|
|
15272
|
+
deletionScheduleId: scheduled.deletion_schedule_id,
|
|
15273
|
+
};
|
|
15274
|
+
}
|
|
15275
|
+
/** Cancel this exact deletion schedule before its deadline; company admins only. */
|
|
15276
|
+
async cancelDeletion(vaultId, deletionScheduleId) {
|
|
15277
|
+
const id = requireResourceId(vaultId, 'vaultId');
|
|
15278
|
+
if (!deletionScheduleId?.trim()) {
|
|
15279
|
+
throw new ValidationError('Deletion schedule is required to cancel deletion');
|
|
15280
|
+
}
|
|
15281
|
+
const response = await this.http.post(apiPath `/v1/vaults/${id}/deletion/cancel`, {
|
|
15282
|
+
deletion_schedule_id: deletionScheduleId,
|
|
15151
15283
|
});
|
|
15284
|
+
return mapVaultDetail(response.data);
|
|
15152
15285
|
}
|
|
15153
15286
|
/**
|
|
15154
15287
|
* Get a vault's public-sharing configuration.
|
|
@@ -15329,6 +15462,28 @@ class VaultsModule {
|
|
|
15329
15462
|
}
|
|
15330
15463
|
}
|
|
15331
15464
|
}
|
|
15465
|
+
function mapLifecycle(v) {
|
|
15466
|
+
return {
|
|
15467
|
+
status: v.status,
|
|
15468
|
+
deletionRequestedAt: v.deletion_requested_at,
|
|
15469
|
+
deletionScheduledFor: v.deletion_scheduled_for,
|
|
15470
|
+
deletionRequestedBy: v.deletion_requested_by,
|
|
15471
|
+
deletionScheduleId: v.deletion_schedule_id,
|
|
15472
|
+
};
|
|
15473
|
+
}
|
|
15474
|
+
function mapVaultDetail(v) {
|
|
15475
|
+
return {
|
|
15476
|
+
id: v.vault_id,
|
|
15477
|
+
name: v.name,
|
|
15478
|
+
description: v.description ?? null,
|
|
15479
|
+
...mapLifecycle(v),
|
|
15480
|
+
ingotCount: v.ingot_count ?? 0,
|
|
15481
|
+
storageBytes: v.storage_bytes ?? 0,
|
|
15482
|
+
createdAt: v.created_at,
|
|
15483
|
+
lastUnsealedAt: v.last_unsealed_at ?? null,
|
|
15484
|
+
unsealCount: v.unseal_count ?? 0,
|
|
15485
|
+
};
|
|
15486
|
+
}
|
|
15332
15487
|
function mapSharingConfig$1(wire) {
|
|
15333
15488
|
return {
|
|
15334
15489
|
vaultId: wire.vault_id,
|
|
@@ -15617,6 +15772,16 @@ async function attemptDownload(link, state, options) {
|
|
|
15617
15772
|
// next attempt what it needs to resume.
|
|
15618
15773
|
state.held = held;
|
|
15619
15774
|
await readBody(response, controller, state, held.total, onProgress);
|
|
15775
|
+
if (held.total > 0 && received.loaded !== held.total) {
|
|
15776
|
+
// A body that ended cleanly at any length but its declared one is not
|
|
15777
|
+
// the file: some hop reframed a cut transfer as a complete one. The
|
|
15778
|
+
// request counts as unanswered, so the next attempt resumes from the
|
|
15779
|
+
// bytes held, except after a body that ran past the declared length,
|
|
15780
|
+
// which no range can continue: it starts over.
|
|
15781
|
+
if (received.loaded > held.total)
|
|
15782
|
+
received.discard();
|
|
15783
|
+
return { ok: false, error: lengthMismatch(received.loaded, held.total), outcome: UNANSWERED };
|
|
15784
|
+
}
|
|
15620
15785
|
delivered = true;
|
|
15621
15786
|
return whole(held);
|
|
15622
15787
|
}
|
|
@@ -15638,6 +15803,14 @@ async function attemptDownload(link, state, options) {
|
|
|
15638
15803
|
signal?.removeEventListener('abort', abortFromCaller);
|
|
15639
15804
|
}
|
|
15640
15805
|
}
|
|
15806
|
+
/**
|
|
15807
|
+
* The failure of a body that ended at a length other than the one its
|
|
15808
|
+
* response declared: what the caller sees once the transfer can no longer
|
|
15809
|
+
* retry it (no link to mint, or the budget spent). Never a download.
|
|
15810
|
+
*/
|
|
15811
|
+
function lengthMismatch(received, total) {
|
|
15812
|
+
return new SparkVaultError(`The download ended after ${received} of ${total} bytes`, 'download_failed', undefined, { reason: 'length_mismatch', received, total });
|
|
15813
|
+
}
|
|
15641
15814
|
/** The resume point the bytes held allow, or null when the attempt fetches the whole file. */
|
|
15642
15815
|
function resumePoint(state) {
|
|
15643
15816
|
const { held, received } = state;
|
|
@@ -16045,11 +16218,15 @@ class IngotsModule {
|
|
|
16045
16218
|
* `details.coreCode`: a new upload is no remedy. A publication the server
|
|
16046
16219
|
* still defers at the transfer's idle limit rejects with code
|
|
16047
16220
|
* `upload_received_publishing`: every byte is received, and the server
|
|
16048
|
-
* finishes the publication on its own, so never upload the file again
|
|
16221
|
+
* finishes the publication on its own, so never upload the file again; a
|
|
16222
|
+
* caller that kept the session (`onSessionCreated`) learns what became of
|
|
16223
|
+
* it with {@link resumeUpload}.
|
|
16049
16224
|
*
|
|
16050
16225
|
* @param options.signal - Cancels this transfer (it rejects with code
|
|
16051
16226
|
* `cancelled`); other transfers carry on.
|
|
16052
16227
|
* @param options.onProgress - Bytes sent so far and the file size; never runs backwards.
|
|
16228
|
+
* @param options.onSessionCreated - Hands over the upload's session once
|
|
16229
|
+
* Forge opens it, before the first byte is sent.
|
|
16053
16230
|
*
|
|
16054
16231
|
* @example
|
|
16055
16232
|
* const session = await sv.ingots.createUpload({ vault: unsealed, name: file.name,
|
|
@@ -16058,17 +16235,60 @@ class IngotsModule {
|
|
|
16058
16235
|
*/
|
|
16059
16236
|
async sendUpload(uploadUrl, file, options = {}) {
|
|
16060
16237
|
this.validateFile(file);
|
|
16061
|
-
const {
|
|
16238
|
+
const { onProgress, onSessionCreated } = options;
|
|
16239
|
+
await this.runTransfer(options.signal, (transfer) => transfer.uploadFileToForge(file, uploadUrl, onProgress, onSessionCreated && ((sessionUrl) => onSessionCreated({ sessionUrl }))));
|
|
16240
|
+
}
|
|
16241
|
+
/**
|
|
16242
|
+
* Continue an upload in the session a {@link sendUpload} opened for the same
|
|
16243
|
+
* file (the `session` its `onSessionCreated` handed over): Forge is asked
|
|
16244
|
+
* where the session stands, only the bytes it lacks are sent, and the
|
|
16245
|
+
* promise resolves once the server confirms the ingot is published. A
|
|
16246
|
+
* session that already holds every byte sends none and only asks: this is
|
|
16247
|
+
* how a caller follows an upload that ended `upload_received_publishing`
|
|
16248
|
+
* until the server publishes it or ends it.
|
|
16249
|
+
*
|
|
16250
|
+
* It rejects as {@link sendUpload} does: `session_gone` once the server no
|
|
16251
|
+
* longer holds the session (it expired, was cancelled, or ended when the
|
|
16252
|
+
* server refused to publish it), `upload_refused` for an upload refused for
|
|
16253
|
+
* good, `upload_received_publishing` again for a publication the server
|
|
16254
|
+
* still defers at the transfer's idle limit, which leaves the session to
|
|
16255
|
+
* resume again later. A session URL that is not an upload session on an
|
|
16256
|
+
* allowed transfer host is refused (`invalid_forge_url`), and one whose
|
|
16257
|
+
* upload is not this file's length (`session_mismatch`), before a byte is
|
|
16258
|
+
* sent.
|
|
16259
|
+
*
|
|
16260
|
+
* @param options.signal - Cancels this transfer (it rejects with code
|
|
16261
|
+
* `cancelled`); the session stays as it stands.
|
|
16262
|
+
* @param options.onProgress - Bytes the session holds so far and the file size; never runs backwards.
|
|
16263
|
+
*
|
|
16264
|
+
* @example
|
|
16265
|
+
* let session;
|
|
16266
|
+
* try {
|
|
16267
|
+
* await sv.ingots.sendUpload(upload.uploadUrl, file, { onSessionCreated: (s) => { session = s; } });
|
|
16268
|
+
* } catch (error) {
|
|
16269
|
+
* if (error.code !== 'upload_received_publishing') throw error;
|
|
16270
|
+
* await sv.ingots.resumeUpload(session, file);
|
|
16271
|
+
* }
|
|
16272
|
+
*/
|
|
16273
|
+
async resumeUpload(session, file, options = {}) {
|
|
16274
|
+
this.validateFile(file);
|
|
16275
|
+
const { onProgress } = options;
|
|
16276
|
+
await this.runTransfer(options.signal, (transfer) => transfer.resumeUploadToForge(file, session.sessionUrl, onProgress));
|
|
16277
|
+
}
|
|
16278
|
+
/**
|
|
16279
|
+
* Run one transfer on a transfer client of its own: its abort is scoped to
|
|
16280
|
+
* its own session, so cancelling one upload never touches another in
|
|
16281
|
+
* flight, and the caller's signal cancels it (code `cancelled`).
|
|
16282
|
+
*/
|
|
16283
|
+
async runTransfer(signal, run) {
|
|
16062
16284
|
if (signal?.aborted) {
|
|
16063
16285
|
throw new UploadApiError('Upload cancelled', 'cancelled', 0);
|
|
16064
16286
|
}
|
|
16065
|
-
// One transfer client per call: its abort is scoped to its own session,
|
|
16066
|
-
// so cancelling one upload never touches another in flight.
|
|
16067
16287
|
const transfer = new UploadApi(this.config);
|
|
16068
16288
|
const cancel = () => transfer.abort();
|
|
16069
16289
|
signal?.addEventListener('abort', cancel, { once: true });
|
|
16070
16290
|
try {
|
|
16071
|
-
await transfer
|
|
16291
|
+
await run(transfer);
|
|
16072
16292
|
}
|
|
16073
16293
|
finally {
|
|
16074
16294
|
signal?.removeEventListener('abort', cancel);
|
|
@@ -17196,7 +17416,7 @@ class SparkVault {
|
|
|
17196
17416
|
}
|
|
17197
17417
|
/** Get the SDK version */
|
|
17198
17418
|
static get version() {
|
|
17199
|
-
return '11.
|
|
17419
|
+
return '11.2.0';
|
|
17200
17420
|
}
|
|
17201
17421
|
}
|
|
17202
17422
|
if (typeof window !== 'undefined') {
|