@sparkvault/sdk-js 12.0.2 → 12.0.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.
- package/dist/errors.d.ts +10 -0
- package/dist/index.cjs +365 -87
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +198 -81
- package/dist/index.mjs +364 -88
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/index.d.ts +54 -7
- package/dist/ingots/types.d.ts +55 -2
- package/dist/products/identity/index.d.ts +6 -2
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/upload/api.d.ts +9 -0
- package/dist/vaults/upload/renderer.d.ts +5 -0
- package/dist/vaults/upload/types.d.ts +16 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,8 @@ function isTransientHttpStatus(status) {
|
|
|
35
35
|
* publication it is bound to (a content version, and the one an ingot row
|
|
36
36
|
* names), Core's revocation of an upload's token, and the refusals of Core's
|
|
37
37
|
* a transfer's answer names (the header, and the lock of a vault scheduled
|
|
38
|
-
* for deletion).
|
|
38
|
+
* for deletion). Every client ends an upload it gives up by one rule here
|
|
39
|
+
* too: the upload id its delete is conditioned on (givenUpUploadId).
|
|
39
40
|
*
|
|
40
41
|
* Forge stamps UPLOAD_PUBLICATION_PROTOCOL on every upload session it creates
|
|
41
42
|
* and on the final state it hands Core's activation (POST
|
|
@@ -54,6 +55,38 @@ function isTransientHttpStatus(status) {
|
|
|
54
55
|
*/
|
|
55
56
|
|
|
56
57
|
|
|
58
|
+
/**
|
|
59
|
+
* An upload's id as both services spell it: `tus_` and the 32 lowercase hex
|
|
60
|
+
* digits of 16 random bytes. An encrypt token that names one (`upload_id`)
|
|
61
|
+
* was staged by Core under it, and Forge keys the upload's session, its chunk
|
|
62
|
+
* prefix and its VAK wrapping by it, so Core finds and settles the upload by
|
|
63
|
+
* the session's id.
|
|
64
|
+
*/
|
|
65
|
+
const UPLOAD_ID_PATTERN = /^tus_[0-9a-f]{32}$/;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The upload id under which a client that gives an upload up (its person
|
|
69
|
+
* cancelled it, or it failed for good) ends it with the file its create
|
|
70
|
+
* made: the `upload_id` that create answered, which Core's delete takes as
|
|
71
|
+
* its condition (`DELETE …/ingots/:ingot_id?upload_id=`), deleting the ingot
|
|
72
|
+
* only while it is still that upload's unfinished file and keeping (412) one
|
|
73
|
+
* the upload published, or a later upload took over. Null when the file is
|
|
74
|
+
* not the upload's to end: its create staged onto a row that already stood
|
|
75
|
+
* (`created` not true: another upload's unfinished file, or a published file
|
|
76
|
+
* the upload was replacing), or answered no upload id, without which the
|
|
77
|
+
* delete would take whatever file stands, one the upload published
|
|
78
|
+
* included. Every client sends a given-up upload's delete under this id
|
|
79
|
+
* alone, and sends none when it is null.
|
|
80
|
+
*
|
|
81
|
+
* @param {{ created?: boolean|null, uploadId?: string|null }} placement -
|
|
82
|
+
* What the upload's create answered: whether it made the file, and the
|
|
83
|
+
* upload it staged
|
|
84
|
+
* @returns {string|null}
|
|
85
|
+
*/
|
|
86
|
+
function givenUpUploadId({ created, uploadId }) {
|
|
87
|
+
return created === true && typeof uploadId === 'string' && UPLOAD_ID_PATTERN.test(uploadId) ? uploadId : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
57
90
|
/**
|
|
58
91
|
* The codes Core's activation refuses an upload with, which Forge's refusal
|
|
59
92
|
* map reads (the status is Core's):
|
|
@@ -830,6 +863,20 @@ class UserCancelledError extends SparkVaultError {
|
|
|
830
863
|
Object.setPrototypeOf(this, UserCancelledError.prototype);
|
|
831
864
|
}
|
|
832
865
|
}
|
|
866
|
+
/**
|
|
867
|
+
* The identity provider answered a FedCM sign-in with an error of its own
|
|
868
|
+
* (the browser's `IdentityCredentialError`), after the browser showed the
|
|
869
|
+
* person its error dialog: the request reached the provider, which refused or
|
|
870
|
+
* failed it, so it is no cancel. `code` is the provider's answer
|
|
871
|
+
* (`server_error`, `access_denied`, ...).
|
|
872
|
+
*/
|
|
873
|
+
class IdentityProviderError extends SparkVaultError {
|
|
874
|
+
constructor(code) {
|
|
875
|
+
super('The identity provider could not complete the sign-in.', code || 'identity_provider_error');
|
|
876
|
+
this.name = 'IdentityProviderError';
|
|
877
|
+
Object.setPrototypeOf(this, IdentityProviderError.prototype);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
833
880
|
class PopupBlockedError extends SparkVaultError {
|
|
834
881
|
constructor() {
|
|
835
882
|
super('Popup was blocked. Please allow popups for this site.', 'popup_blocked');
|
|
@@ -10194,6 +10241,20 @@ function decodeTokenSegment(segment, message) {
|
|
|
10194
10241
|
throw new ValidationError(message);
|
|
10195
10242
|
}
|
|
10196
10243
|
}
|
|
10244
|
+
/**
|
|
10245
|
+
* The provider's own answer to a FedCM id assertion, as the browser rejects
|
|
10246
|
+
* with it (an `IdentityCredentialError`, a DOMException read by its name, so
|
|
10247
|
+
* neither the class's presence nor the realm it was made in matters), or null
|
|
10248
|
+
* for any other rejection.
|
|
10249
|
+
*/
|
|
10250
|
+
function identityProviderErrorOf(error) {
|
|
10251
|
+
if (typeof error !== 'object' || error === null)
|
|
10252
|
+
return null;
|
|
10253
|
+
const { name, error: code } = error;
|
|
10254
|
+
if (name !== 'IdentityCredentialError')
|
|
10255
|
+
return null;
|
|
10256
|
+
return new IdentityProviderError(typeof code === 'string' ? code : '');
|
|
10257
|
+
}
|
|
10197
10258
|
class IdentityModule {
|
|
10198
10259
|
constructor(config) {
|
|
10199
10260
|
this.renderer = null;
|
|
@@ -10256,8 +10317,12 @@ class IdentityModule {
|
|
|
10256
10317
|
* `IdentityModule.isFedcmAvailable()` and fall back to `signIn()` otherwise.
|
|
10257
10318
|
*
|
|
10258
10319
|
* @returns the verified result, or `null` when the browser has no FedCM
|
|
10259
|
-
* support (so the caller can fall back). Throws `UserCancelledError` when
|
|
10260
|
-
*
|
|
10320
|
+
* support (so the caller can fall back). Throws `UserCancelledError` when
|
|
10321
|
+
* the browser ends the request without a credential: the person dismissed
|
|
10322
|
+
* the chooser, or the browser had no SparkVault account to offer (the
|
|
10323
|
+
* browser reports both alike). Throws `IdentityProviderError`, carrying
|
|
10324
|
+
* SparkVault's own error code, when SparkVault answered the sign-in with an
|
|
10325
|
+
* error.
|
|
10261
10326
|
*
|
|
10262
10327
|
* @example
|
|
10263
10328
|
* const result = (await sv.products.identity.isFedcmAvailable())
|
|
@@ -10291,9 +10356,12 @@ class IdentityModule {
|
|
|
10291
10356
|
credential = await getCredential(request);
|
|
10292
10357
|
}
|
|
10293
10358
|
catch (error) {
|
|
10294
|
-
// The
|
|
10295
|
-
//
|
|
10296
|
-
|
|
10359
|
+
// The provider's own answer to the id assertion is no cancel. Every other
|
|
10360
|
+
// rejection ends the request without a credential: the browser answers a
|
|
10361
|
+
// dismissed chooser and a provider with no account to offer with the same
|
|
10362
|
+
// NetworkError, so that is the SDK's cancel signal.
|
|
10363
|
+
throw identityProviderErrorOf(error)
|
|
10364
|
+
?? new UserCancelledError(error instanceof Error ? error.message : undefined);
|
|
10297
10365
|
}
|
|
10298
10366
|
const token = credential?.token;
|
|
10299
10367
|
if (!token) {
|
|
@@ -11939,6 +12007,38 @@ function waitUntilOnline(signal) {
|
|
|
11939
12007
|
settle(resolve);
|
|
11940
12008
|
});
|
|
11941
12009
|
}
|
|
12010
|
+
/**
|
|
12011
|
+
* The failures a transfer met once the server held every byte of its upload,
|
|
12012
|
+
* which leave the upload's end to the server ({@link isReceivedUploadFailure}).
|
|
12013
|
+
*/
|
|
12014
|
+
const receivedFailures = new WeakSet();
|
|
12015
|
+
/** The codes that end an upload whatever the server holds of it: its session gone, Core's refusal, the caller's cancel. */
|
|
12016
|
+
const UPLOAD_ENDING_CODES = new Set(['session_gone', 'upload_refused', 'cancelled']);
|
|
12017
|
+
/**
|
|
12018
|
+
* A failure of the receipt, which the transfer asks for only once the server
|
|
12019
|
+
* holds every byte: it leaves the upload's end to the server unless it ended
|
|
12020
|
+
* the upload itself (UPLOAD_ENDING_CODES) or named an earlier offset, bytes
|
|
12021
|
+
* the server lacks.
|
|
12022
|
+
*/
|
|
12023
|
+
function receiptFailure(error) {
|
|
12024
|
+
if (error instanceof UploadApiError &&
|
|
12025
|
+
!UPLOAD_ENDING_CODES.has(error.code) &&
|
|
12026
|
+
error.verdict !== TRANSFER_VERDICT.RESYNC) {
|
|
12027
|
+
receivedFailures.add(error);
|
|
12028
|
+
}
|
|
12029
|
+
return error;
|
|
12030
|
+
}
|
|
12031
|
+
/**
|
|
12032
|
+
* Whether a transfer failed once the server held every byte of its upload,
|
|
12033
|
+
* short of the upload's own end: `upload_received_publishing`, and any other
|
|
12034
|
+
* failure of the receipt that confirms publication (one refused, or one that
|
|
12035
|
+
* went unanswered), never a gone session, Core's refusal or a cancel. The
|
|
12036
|
+
* server publishes such an upload, or ends it, on its own, so its caller
|
|
12037
|
+
* neither sends it again nor gives it up (`ingots.endUpload`).
|
|
12038
|
+
*/
|
|
12039
|
+
function isReceivedUploadFailure(error) {
|
|
12040
|
+
return error instanceof UploadApiError && receivedFailures.has(error);
|
|
12041
|
+
}
|
|
11942
12042
|
/** A failed request of this upload's transfer; anything else is rethrown as it is. */
|
|
11943
12043
|
function transferFailure(error) {
|
|
11944
12044
|
if (error instanceof UploadApiError)
|
|
@@ -12336,7 +12436,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
12336
12436
|
// the server (a chunk's 204, a HEAD, a 409), publication is confirmed
|
|
12337
12437
|
// before the upload resolves.
|
|
12338
12438
|
if (offset === file.size) {
|
|
12339
|
-
const receipt = await this.confirmServerFinalized(transfer)
|
|
12439
|
+
const receipt = await this.confirmServerFinalized(transfer).catch((error) => {
|
|
12440
|
+
throw receiptFailure(error);
|
|
12441
|
+
});
|
|
12340
12442
|
if (receipt.published)
|
|
12341
12443
|
return;
|
|
12342
12444
|
offset = receipt.resumeAt;
|
|
@@ -14186,6 +14288,11 @@ function formatBytes(bytes, decimals = 1) {
|
|
|
14186
14288
|
* admin how to cancel the deletion, is the console's, never this page's.
|
|
14187
14289
|
*/
|
|
14188
14290
|
const VAULT_NOT_ACCEPTING_MESSAGE = 'This vault isn\'t accepting files right now, so your file was not saved. Please contact the person who shared this upload page with you.';
|
|
14291
|
+
/**
|
|
14292
|
+
* What an uploader reads for a file of no bytes, which Core never stores: said
|
|
14293
|
+
* on the form, where another file can be chosen, as the size limit is.
|
|
14294
|
+
*/
|
|
14295
|
+
const EMPTY_FILE_MESSAGE = 'This file is empty, so there is nothing to upload. Choose another file.';
|
|
14189
14296
|
/**
|
|
14190
14297
|
* Ceremony steps for the cryptographic visualization.
|
|
14191
14298
|
*/
|
|
@@ -14214,6 +14321,36 @@ function transferChannelLine(requestId) {
|
|
|
14214
14321
|
? ''
|
|
14215
14322
|
: `<p class="svu-forging-line">Secure Transfer Channel: <span class="svu-mono">${escapeHtml(requestId)}</span></p>`;
|
|
14216
14323
|
}
|
|
14324
|
+
/**
|
|
14325
|
+
* Refusals that say the vault takes no upload now, whichever file is chosen:
|
|
14326
|
+
* it is scheduled for deletion, its owner's plan lapsed, or its upload page is
|
|
14327
|
+
* gone or switched off. An error view after one offers no way on.
|
|
14328
|
+
*/
|
|
14329
|
+
function vaultTakesNoUpload(error) {
|
|
14330
|
+
return error.code === VAULT_DELETION_SCHEDULED
|
|
14331
|
+
|| error.details?.coreCode === VAULT_DELETION_SCHEDULED
|
|
14332
|
+
|| error.code === 'UPLOAD_SOURCE_DISABLED'
|
|
14333
|
+
|| error.statusCode === 402
|
|
14334
|
+
|| (error.statusCode === 404 && error.code !== 'session_gone');
|
|
14335
|
+
}
|
|
14336
|
+
/**
|
|
14337
|
+
* The way on an error view offers after an upload of the chosen file failed:
|
|
14338
|
+
* nothing while the vault takes no upload ({@link vaultTakesNoUpload}); the
|
|
14339
|
+
* same file again after a failure that may pass (no answer, a fault, a rate
|
|
14340
|
+
* limit); another file after a refusal of this one, or after one received
|
|
14341
|
+
* whole, which the server finishes saving on its own.
|
|
14342
|
+
*/
|
|
14343
|
+
function recoveryAfterUpload(error) {
|
|
14344
|
+
if (!(error instanceof UploadApiError))
|
|
14345
|
+
return { label: 'Try Again', keepFile: true };
|
|
14346
|
+
if (vaultTakesNoUpload(error))
|
|
14347
|
+
return null;
|
|
14348
|
+
if (error.code === RECEIVED_STILL_SAVING)
|
|
14349
|
+
return { label: 'Upload Another File', keepFile: false };
|
|
14350
|
+
const status = error.statusCode ?? 0;
|
|
14351
|
+
const mayPass = status === 0 || status === 429 || status >= 500;
|
|
14352
|
+
return mayPass ? { label: 'Try Again', keepFile: true } : { label: 'Choose Another File', keepFile: false };
|
|
14353
|
+
}
|
|
14217
14354
|
/**
|
|
14218
14355
|
* Whether an error represents a deliberate cancellation (user close,
|
|
14219
14356
|
* programmatic close, or session abort) rather than a genuine failure.
|
|
@@ -14266,11 +14403,13 @@ class UploadRenderer {
|
|
|
14266
14403
|
// (its own button, picker, or drop target) and hand the File to the SDK.
|
|
14267
14404
|
if (this.options.file) {
|
|
14268
14405
|
this.selectedFile = this.options.file;
|
|
14406
|
+
this.callbacks.onReady?.();
|
|
14269
14407
|
await this.startUpload(config);
|
|
14270
14408
|
return;
|
|
14271
14409
|
}
|
|
14272
14410
|
// Show form
|
|
14273
14411
|
this.setState({ view: 'form', config });
|
|
14412
|
+
this.callbacks.onReady?.();
|
|
14274
14413
|
}
|
|
14275
14414
|
catch (error) {
|
|
14276
14415
|
this.handleApiError(error);
|
|
@@ -14777,9 +14916,26 @@ class UploadRenderer {
|
|
|
14777
14916
|
<span class="svu-error-code-value">${escapeHtml(state.code)}</span>
|
|
14778
14917
|
</div>
|
|
14779
14918
|
`;
|
|
14919
|
+
const { action } = state;
|
|
14920
|
+
if (action && this.config) {
|
|
14921
|
+
const config = this.config;
|
|
14922
|
+
const recover = document.createElement('button');
|
|
14923
|
+
recover.className = 'svu-btn svu-btn-primary';
|
|
14924
|
+
recover.textContent = action.label;
|
|
14925
|
+
recover.addEventListener('click', () => {
|
|
14926
|
+
if (!action.keepFile)
|
|
14927
|
+
this.selectedFile = null;
|
|
14928
|
+
this.setState({ view: 'form', config });
|
|
14929
|
+
});
|
|
14930
|
+
div.appendChild(recover);
|
|
14931
|
+
}
|
|
14780
14932
|
return div;
|
|
14781
14933
|
}
|
|
14782
14934
|
handleFileSelect(file, config) {
|
|
14935
|
+
if (file.size === 0) {
|
|
14936
|
+
this.setState({ view: 'form', config, error: EMPTY_FILE_MESSAGE });
|
|
14937
|
+
return;
|
|
14938
|
+
}
|
|
14783
14939
|
// Validate file size
|
|
14784
14940
|
if (file.size > config.maxSizeBytes) {
|
|
14785
14941
|
this.setState({
|
|
@@ -14904,7 +15060,9 @@ class UploadRenderer {
|
|
|
14904
15060
|
this.callbacks.onSuccess(result);
|
|
14905
15061
|
}
|
|
14906
15062
|
catch (error) {
|
|
14907
|
-
|
|
15063
|
+
// A host that chose the file itself offers its own way on; the
|
|
15064
|
+
// widget's form is the way on only for a file chosen on it.
|
|
15065
|
+
this.handleApiError(error, this.options.file ? null : recoveryAfterUpload(error));
|
|
14908
15066
|
}
|
|
14909
15067
|
}
|
|
14910
15068
|
async runCeremony(file, ingotId, requestId) {
|
|
@@ -14936,7 +15094,11 @@ class UploadRenderer {
|
|
|
14936
15094
|
});
|
|
14937
15095
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
14938
15096
|
}
|
|
14939
|
-
|
|
15097
|
+
/**
|
|
15098
|
+
* Show a failure in the error view, with the way on it offers (`action`:
|
|
15099
|
+
* none for a page that could not load), and tell the host through onError.
|
|
15100
|
+
*/
|
|
15101
|
+
handleApiError(error, action = null) {
|
|
14940
15102
|
// A closed renderer must not surface errors: cancelling mid-transfer
|
|
14941
15103
|
// aborts the in-flight request, whose 'cancelled' rejection races the
|
|
14942
15104
|
// teardown. The host has already received onCancel — onCancel and
|
|
@@ -14952,6 +15114,7 @@ class UploadRenderer {
|
|
|
14952
15114
|
// points at the dashboard rather than the end user.
|
|
14953
15115
|
this.setState({
|
|
14954
15116
|
view: 'error',
|
|
15117
|
+
action,
|
|
14955
15118
|
title: 'Upload Widget Not Enabled',
|
|
14956
15119
|
message: 'This vault has not enabled the embedded upload widget. Enable it on the vault\'s settings page in the SparkVault dashboard to start accepting uploads here.',
|
|
14957
15120
|
code: 'UPLOAD_SOURCE_DISABLED',
|
|
@@ -14965,6 +15128,7 @@ class UploadRenderer {
|
|
|
14965
15128
|
// tells it never to upload the file again.
|
|
14966
15129
|
this.setState({
|
|
14967
15130
|
view: 'error',
|
|
15131
|
+
action,
|
|
14968
15132
|
title: 'Upload Received',
|
|
14969
15133
|
message: error.message,
|
|
14970
15134
|
code: error.code,
|
|
@@ -14978,6 +15142,7 @@ class UploadRenderer {
|
|
|
14978
15142
|
// uploader, told only that the vault takes no files now.
|
|
14979
15143
|
this.setState({
|
|
14980
15144
|
view: 'error',
|
|
15145
|
+
action,
|
|
14981
15146
|
title: 'Uploads Paused',
|
|
14982
15147
|
message: VAULT_NOT_ACCEPTING_MESSAGE,
|
|
14983
15148
|
code: error.code,
|
|
@@ -14990,6 +15155,7 @@ class UploadRenderer {
|
|
|
14990
15155
|
// sentence that never asks for the file again.
|
|
14991
15156
|
this.setState({
|
|
14992
15157
|
view: 'error',
|
|
15158
|
+
action,
|
|
14993
15159
|
title: 'Upload Not Saved',
|
|
14994
15160
|
message: error.message,
|
|
14995
15161
|
code: error.code,
|
|
@@ -15001,6 +15167,7 @@ class UploadRenderer {
|
|
|
15001
15167
|
// can answer 404 too, and its own sentence says what became of the file.
|
|
15002
15168
|
this.setState({
|
|
15003
15169
|
view: 'error',
|
|
15170
|
+
action,
|
|
15004
15171
|
title: 'Upload Page Not Found',
|
|
15005
15172
|
message: 'The requested upload endpoint could not be located. This may occur if the upload link has expired or was entered incorrectly.',
|
|
15006
15173
|
code: 'NOT_FOUND',
|
|
@@ -15010,6 +15177,7 @@ class UploadRenderer {
|
|
|
15010
15177
|
else if (error.statusCode === 402) {
|
|
15011
15178
|
this.setState({
|
|
15012
15179
|
view: 'error',
|
|
15180
|
+
action,
|
|
15013
15181
|
title: 'Service Unavailable',
|
|
15014
15182
|
message: 'This upload endpoint has been temporarily disabled due to an account billing issue. Please contact the organization\'s administrator.',
|
|
15015
15183
|
code: 'PAYMENT_REQUIRED',
|
|
@@ -15019,6 +15187,7 @@ class UploadRenderer {
|
|
|
15019
15187
|
else {
|
|
15020
15188
|
this.setState({
|
|
15021
15189
|
view: 'error',
|
|
15190
|
+
action,
|
|
15022
15191
|
title: 'Upload Failed',
|
|
15023
15192
|
message: error.message,
|
|
15024
15193
|
code: error.code,
|
|
@@ -15030,6 +15199,7 @@ class UploadRenderer {
|
|
|
15030
15199
|
else if (error instanceof Error) {
|
|
15031
15200
|
this.setState({
|
|
15032
15201
|
view: 'error',
|
|
15202
|
+
action,
|
|
15033
15203
|
title: 'Upload Failed',
|
|
15034
15204
|
message: error.message,
|
|
15035
15205
|
code: 'UNKNOWN_ERROR',
|
|
@@ -15040,6 +15210,7 @@ class UploadRenderer {
|
|
|
15040
15210
|
const err = new Error('An unexpected error occurred');
|
|
15041
15211
|
this.setState({
|
|
15042
15212
|
view: 'error',
|
|
15213
|
+
action,
|
|
15043
15214
|
title: 'Upload Failed',
|
|
15044
15215
|
message: err.message,
|
|
15045
15216
|
code: 'UNKNOWN_ERROR',
|
|
@@ -15126,6 +15297,7 @@ class VaultUploadModule {
|
|
|
15126
15297
|
reject(error);
|
|
15127
15298
|
},
|
|
15128
15299
|
onProgress: options.onProgress,
|
|
15300
|
+
onReady: options.onReady,
|
|
15129
15301
|
});
|
|
15130
15302
|
this.renderer.start().catch((error) => {
|
|
15131
15303
|
options.onError?.(error);
|
|
@@ -15658,6 +15830,74 @@ function readIngotAccess(entry) {
|
|
|
15658
15830
|
};
|
|
15659
15831
|
}
|
|
15660
15832
|
|
|
15833
|
+
/**
|
|
15834
|
+
* SparkVault Debug Logger
|
|
15835
|
+
*
|
|
15836
|
+
* Conditional logging that respects debug mode setting.
|
|
15837
|
+
* When debug is enabled, logs detailed information to console.
|
|
15838
|
+
* When disabled (default), only fatal errors are logged.
|
|
15839
|
+
*/
|
|
15840
|
+
let debugEnabled = false;
|
|
15841
|
+
/**
|
|
15842
|
+
* Enable or disable debug logging
|
|
15843
|
+
*/
|
|
15844
|
+
function setDebugMode(enabled) {
|
|
15845
|
+
debugEnabled = enabled;
|
|
15846
|
+
if (enabled) {
|
|
15847
|
+
log('info', 'Debug mode enabled');
|
|
15848
|
+
}
|
|
15849
|
+
}
|
|
15850
|
+
/**
|
|
15851
|
+
* Internal log function
|
|
15852
|
+
*/
|
|
15853
|
+
function log(level, message, ...args) {
|
|
15854
|
+
const prefix = '[SparkVault]';
|
|
15855
|
+
const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
|
|
15856
|
+
const formattedMessage = `${prefix} ${timestamp} ${message}`;
|
|
15857
|
+
switch (level) {
|
|
15858
|
+
case 'debug':
|
|
15859
|
+
if (debugEnabled) {
|
|
15860
|
+
console.debug(formattedMessage, ...args);
|
|
15861
|
+
}
|
|
15862
|
+
break;
|
|
15863
|
+
case 'info':
|
|
15864
|
+
if (debugEnabled) {
|
|
15865
|
+
console.log(formattedMessage, ...args);
|
|
15866
|
+
}
|
|
15867
|
+
break;
|
|
15868
|
+
case 'warn':
|
|
15869
|
+
if (debugEnabled) {
|
|
15870
|
+
console.warn(formattedMessage, ...args);
|
|
15871
|
+
}
|
|
15872
|
+
break;
|
|
15873
|
+
case 'error':
|
|
15874
|
+
// Always log errors (fatal)
|
|
15875
|
+
console.error(formattedMessage, ...args);
|
|
15876
|
+
break;
|
|
15877
|
+
}
|
|
15878
|
+
}
|
|
15879
|
+
/**
|
|
15880
|
+
* Logger object for convenient access
|
|
15881
|
+
*/
|
|
15882
|
+
const logger = {
|
|
15883
|
+
/**
|
|
15884
|
+
* Debug level - verbose details for troubleshooting
|
|
15885
|
+
*/
|
|
15886
|
+
debug: (message, ...args) => log('debug', message, ...args),
|
|
15887
|
+
/**
|
|
15888
|
+
* Info level - general information
|
|
15889
|
+
*/
|
|
15890
|
+
info: (message, ...args) => log('info', message, ...args),
|
|
15891
|
+
/**
|
|
15892
|
+
* Warn level - warnings that don't prevent operation
|
|
15893
|
+
*/
|
|
15894
|
+
warn: (message, ...args) => log('warn', message, ...args),
|
|
15895
|
+
/**
|
|
15896
|
+
* Error level - always logged regardless of debug mode
|
|
15897
|
+
*/
|
|
15898
|
+
error: (message, ...args) => log('error', message, ...args),
|
|
15899
|
+
};
|
|
15900
|
+
|
|
15661
15901
|
/**
|
|
15662
15902
|
* The one browser transfer for a signed ingot download link: fetch it into a
|
|
15663
15903
|
* Blob under liveness bounds, resuming from the bytes it holds when the caller
|
|
@@ -16337,7 +16577,9 @@ class IngotsModule {
|
|
|
16337
16577
|
* transfer yourself; otherwise prefer {@link upload}. A create another
|
|
16338
16578
|
* upload of the same file superseded before its token was issued rejects
|
|
16339
16579
|
* with code `upload_refused` (`details.coreCode` UPLOAD_SUPERSEDED): the
|
|
16340
|
-
* later upload is the one kept, so a new upload is no remedy.
|
|
16580
|
+
* later upload is the one kept, so a new upload is no remedy. An upload
|
|
16581
|
+
* you give up (you cancel its transfer, or it fails for good) ends with the
|
|
16582
|
+
* file its create made through {@link endUpload}, given this result.
|
|
16341
16583
|
*
|
|
16342
16584
|
* @example
|
|
16343
16585
|
* const session = await sv.ingots.createUpload({
|
|
@@ -16366,15 +16608,65 @@ class IngotsModule {
|
|
|
16366
16608
|
onNameConflict: options.onNameConflict,
|
|
16367
16609
|
});
|
|
16368
16610
|
return {
|
|
16369
|
-
|
|
16611
|
+
...placementOf(created),
|
|
16370
16612
|
name: created.name,
|
|
16371
16613
|
contentType: created.content_type,
|
|
16372
16614
|
size: created.size_bytes,
|
|
16373
16615
|
uploadUrl: created.forge_url,
|
|
16374
16616
|
expiresAt: created.expires_at,
|
|
16375
|
-
created: created.created,
|
|
16376
16617
|
};
|
|
16377
16618
|
}
|
|
16619
|
+
/**
|
|
16620
|
+
* End an upload you give up (you cancelled its transfer, or it failed for
|
|
16621
|
+
* good) with the file its create made ({@link createUpload}'s result): the
|
|
16622
|
+
* server deletes the ingot only while it is still that upload's unfinished
|
|
16623
|
+
* file, ending the upload first, so a publication racing the end is decided
|
|
16624
|
+
* before anything goes. Never give up one the server received whole
|
|
16625
|
+
* ({@link isReceivedUploadFailure}): the server publishes or ends it on its
|
|
16626
|
+
* own. Resolves `deleted` once the vault holds the file no longer, deleted
|
|
16627
|
+
* now or already gone. Resolves `kept` when this end deleted nothing, which
|
|
16628
|
+
* {@link get} shows as it is now: the upload published the file, or a later
|
|
16629
|
+
* upload took it over, before the end reached the server, or, with no
|
|
16630
|
+
* request sent, the create did not make it (`created: false`) or names no
|
|
16631
|
+
* upload (`uploadId: null`), since a delete without its upload would take
|
|
16632
|
+
* whatever file stands. Any other failure rejects, the file left as it was.
|
|
16633
|
+
* {@link upload} ends an upload it cannot finish this way by itself.
|
|
16634
|
+
*
|
|
16635
|
+
* @example
|
|
16636
|
+
* const upload = await sv.ingots.createUpload({ vault: unsealed, name: file.name,
|
|
16637
|
+
* contentType: file.type, sizeBytes: file.size });
|
|
16638
|
+
* try {
|
|
16639
|
+
* await sv.ingots.sendUpload(upload.uploadUrl, file, { signal: controller.signal });
|
|
16640
|
+
* } catch (error) {
|
|
16641
|
+
* if (!isReceivedUploadFailure(error) &&
|
|
16642
|
+
* await sv.ingots.endUpload(unsealed, upload) === 'kept') {
|
|
16643
|
+
* // The end deleted nothing (the upload published the file, say): show it as it is.
|
|
16644
|
+
* showIngot(await sv.ingots.get(unsealed, upload.id));
|
|
16645
|
+
* }
|
|
16646
|
+
* throw error;
|
|
16647
|
+
* }
|
|
16648
|
+
*/
|
|
16649
|
+
async endUpload(vault, upload) {
|
|
16650
|
+
const vaultId = requireVaultId(vault);
|
|
16651
|
+
const id = requireResourceId(upload.id, 'ingotId');
|
|
16652
|
+
const uploadId = givenUpUploadId(upload);
|
|
16653
|
+
if (uploadId === null)
|
|
16654
|
+
return 'kept';
|
|
16655
|
+
try {
|
|
16656
|
+
await this.http.delete(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, {
|
|
16657
|
+
vat: vault.vatToken,
|
|
16658
|
+
query: { upload_id: uploadId },
|
|
16659
|
+
});
|
|
16660
|
+
return 'deleted';
|
|
16661
|
+
}
|
|
16662
|
+
catch (error) {
|
|
16663
|
+
if (error instanceof SparkVaultError && error.statusCode === 404)
|
|
16664
|
+
return 'deleted';
|
|
16665
|
+
if (error instanceof SparkVaultError && error.statusCode === 412)
|
|
16666
|
+
return 'kept';
|
|
16667
|
+
throw error;
|
|
16668
|
+
}
|
|
16669
|
+
}
|
|
16378
16670
|
/**
|
|
16379
16671
|
* Send a file's bytes to an upload session — the `uploadUrl` a
|
|
16380
16672
|
* {@link createUpload} returned — over the resumable transfer every SDK
|
|
@@ -16482,7 +16774,11 @@ class IngotsModule {
|
|
|
16482
16774
|
* server refused — another upload of it superseded this one, at its create
|
|
16483
16775
|
* or while it streamed, the storage pool cannot take it, or its vault is
|
|
16484
16776
|
* scheduled for deletion (a 409 `VAULT_DELETION_SCHEDULED`) — rejects with
|
|
16485
|
-
* code `upload_refused`, as {@link sendUpload} does.
|
|
16777
|
+
* code `upload_refused`, as {@link sendUpload} does. An upload that rejects
|
|
16778
|
+
* any way but one the server received whole ({@link isReceivedUploadFailure}:
|
|
16779
|
+
* the server publishes or ends that one on its own) is given up: the end of
|
|
16780
|
+
* it with the file its create made ({@link endUpload}) starts as it
|
|
16781
|
+
* rejects, without holding up its own error.
|
|
16486
16782
|
*
|
|
16487
16783
|
* @example
|
|
16488
16784
|
* const ingot = await sv.ingots.upload(unsealed, {
|
|
@@ -16504,7 +16800,29 @@ class IngotsModule {
|
|
|
16504
16800
|
folderId: options.folderId,
|
|
16505
16801
|
onNameConflict: options.onNameConflict,
|
|
16506
16802
|
});
|
|
16507
|
-
|
|
16803
|
+
try {
|
|
16804
|
+
return await this.transferAndFinalize(created, created.created, options.file, options.onProgress);
|
|
16805
|
+
}
|
|
16806
|
+
catch (error) {
|
|
16807
|
+
// The caller holds no session to continue this upload in, so a transfer
|
|
16808
|
+
// that ends any way but received whole is given up, its file with it.
|
|
16809
|
+
if (!isReceivedUploadFailure(error))
|
|
16810
|
+
this.endGivenUp(vault, placementOf(created));
|
|
16811
|
+
throw error;
|
|
16812
|
+
}
|
|
16813
|
+
}
|
|
16814
|
+
/**
|
|
16815
|
+
* End an upload this flow gave up ({@link endUpload}) without holding up
|
|
16816
|
+
* the error its caller is answered with: an end that fails leaves the file
|
|
16817
|
+
* to the server's expiry of abandoned uploads, and is logged.
|
|
16818
|
+
*/
|
|
16819
|
+
endGivenUp(vault, upload) {
|
|
16820
|
+
this.endUpload(vault, upload).catch((error) => {
|
|
16821
|
+
logger.warn('A given-up upload could not be ended with its file; the server expires it', {
|
|
16822
|
+
ingotId: upload.id,
|
|
16823
|
+
code: error instanceof SparkVaultError ? error.code : undefined,
|
|
16824
|
+
});
|
|
16825
|
+
});
|
|
16508
16826
|
}
|
|
16509
16827
|
/**
|
|
16510
16828
|
* Replace an existing ingot's content (high-level flow). Rejects as
|
|
@@ -16742,8 +17060,11 @@ class IngotsModule {
|
|
|
16742
17060
|
return mapSharingConfig(response.data);
|
|
16743
17061
|
}
|
|
16744
17062
|
/**
|
|
16745
|
-
* Invite an identity to
|
|
16746
|
-
*
|
|
17063
|
+
* Invite an identity to an ingot's invite-only share, or share an ingot not
|
|
17064
|
+
* yet shared invite-only with it. A public or authenticated share refuses
|
|
17065
|
+
* it (a ValidationError) and changes nothing: set its visibility to
|
|
17066
|
+
* `invite_only` first. The identity type (email or phone) is inferred
|
|
17067
|
+
* server-side from the identity value.
|
|
16747
17068
|
*
|
|
16748
17069
|
* @example
|
|
16749
17070
|
* await sv.ingots.addInvite(unsealed, 'ing_abc', 'user@example.com');
|
|
@@ -16755,7 +17076,7 @@ class IngotsModule {
|
|
|
16755
17076
|
const vaultId = requireVaultId(vault);
|
|
16756
17077
|
const id = requireResourceId(ingotId, 'ingotId');
|
|
16757
17078
|
const response = await this.http.post(apiPath `/v1/vaults/${vaultId}/ingots/${id}/sharing/invite`, { identity }, { vat: vault.vatToken });
|
|
16758
|
-
return
|
|
17079
|
+
return mapInvitation(response.data);
|
|
16759
17080
|
}
|
|
16760
17081
|
/**
|
|
16761
17082
|
* Revoke an ingot sharing invite.
|
|
@@ -16841,6 +17162,8 @@ class IngotsModule {
|
|
|
16841
17162
|
throw stagingRefusalOf(error);
|
|
16842
17163
|
});
|
|
16843
17164
|
if (!response.data.forge_url) {
|
|
17165
|
+
// No upload can start without its URL: the file the create made goes too.
|
|
17166
|
+
this.endGivenUp(vault, placementOf(response.data));
|
|
16844
17167
|
throw new ValidationError('Upload endpoint did not return a Forge upload URL');
|
|
16845
17168
|
}
|
|
16846
17169
|
return response.data;
|
|
@@ -16871,6 +17194,14 @@ class IngotsModule {
|
|
|
16871
17194
|
}
|
|
16872
17195
|
}
|
|
16873
17196
|
}
|
|
17197
|
+
/**
|
|
17198
|
+
* What a create answered about the file it placed: its id, whether the create
|
|
17199
|
+
* made it, and the upload it staged there, which {@link IngotsModule.endUpload}
|
|
17200
|
+
* ends it by.
|
|
17201
|
+
*/
|
|
17202
|
+
function placementOf(created) {
|
|
17203
|
+
return { id: created.ingot_id, created: created.created, uploadId: created.upload_id ?? null };
|
|
17204
|
+
}
|
|
16874
17205
|
function getBlobName(file) {
|
|
16875
17206
|
if (typeof File !== 'undefined' && file instanceof File && file.name) {
|
|
16876
17207
|
return file.name;
|
|
@@ -16920,7 +17251,12 @@ function mapIngotPage(response) {
|
|
|
16920
17251
|
function mapSharingConfig(wire) {
|
|
16921
17252
|
return {
|
|
16922
17253
|
shared: wire.shared,
|
|
16923
|
-
visibility: wire.visibility,
|
|
17254
|
+
visibility: wire.visibility ?? undefined,
|
|
17255
|
+
publicUrl: wire.public_url,
|
|
17256
|
+
linkCode: wire.link_code,
|
|
17257
|
+
sharingEnabled: wire.sharing_enabled,
|
|
17258
|
+
vaultAllIngotsPublic: wire.vault_all_ingots_public,
|
|
17259
|
+
sessionLengthSeconds: wire.session_length_seconds,
|
|
16924
17260
|
invites: wire.invites?.map(mapInvite),
|
|
16925
17261
|
};
|
|
16926
17262
|
}
|
|
@@ -16929,6 +17265,14 @@ function mapInvite(wire) {
|
|
|
16929
17265
|
id: wire.invite_id,
|
|
16930
17266
|
identity: wire.identity,
|
|
16931
17267
|
identityType: wire.identity_type,
|
|
17268
|
+
invitedAt: wire.created_at,
|
|
17269
|
+
};
|
|
17270
|
+
}
|
|
17271
|
+
function mapInvitation(wire) {
|
|
17272
|
+
return {
|
|
17273
|
+
...mapInvite(wire),
|
|
17274
|
+
shareUrl: wire.share_url,
|
|
17275
|
+
delivered: wire.delivered,
|
|
16932
17276
|
};
|
|
16933
17277
|
}
|
|
16934
17278
|
|
|
@@ -17450,74 +17794,6 @@ class NotifyModule {
|
|
|
17450
17794
|
}
|
|
17451
17795
|
}
|
|
17452
17796
|
|
|
17453
|
-
/**
|
|
17454
|
-
* SparkVault Debug Logger
|
|
17455
|
-
*
|
|
17456
|
-
* Conditional logging that respects debug mode setting.
|
|
17457
|
-
* When debug is enabled, logs detailed information to console.
|
|
17458
|
-
* When disabled (default), only fatal errors are logged.
|
|
17459
|
-
*/
|
|
17460
|
-
let debugEnabled = false;
|
|
17461
|
-
/**
|
|
17462
|
-
* Enable or disable debug logging
|
|
17463
|
-
*/
|
|
17464
|
-
function setDebugMode(enabled) {
|
|
17465
|
-
debugEnabled = enabled;
|
|
17466
|
-
if (enabled) {
|
|
17467
|
-
log('info', 'Debug mode enabled');
|
|
17468
|
-
}
|
|
17469
|
-
}
|
|
17470
|
-
/**
|
|
17471
|
-
* Internal log function
|
|
17472
|
-
*/
|
|
17473
|
-
function log(level, message, ...args) {
|
|
17474
|
-
const prefix = '[SparkVault]';
|
|
17475
|
-
const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
|
|
17476
|
-
const formattedMessage = `${prefix} ${timestamp} ${message}`;
|
|
17477
|
-
switch (level) {
|
|
17478
|
-
case 'debug':
|
|
17479
|
-
if (debugEnabled) {
|
|
17480
|
-
console.debug(formattedMessage, ...args);
|
|
17481
|
-
}
|
|
17482
|
-
break;
|
|
17483
|
-
case 'info':
|
|
17484
|
-
if (debugEnabled) {
|
|
17485
|
-
console.log(formattedMessage, ...args);
|
|
17486
|
-
}
|
|
17487
|
-
break;
|
|
17488
|
-
case 'warn':
|
|
17489
|
-
if (debugEnabled) {
|
|
17490
|
-
console.warn(formattedMessage, ...args);
|
|
17491
|
-
}
|
|
17492
|
-
break;
|
|
17493
|
-
case 'error':
|
|
17494
|
-
// Always log errors (fatal)
|
|
17495
|
-
console.error(formattedMessage, ...args);
|
|
17496
|
-
break;
|
|
17497
|
-
}
|
|
17498
|
-
}
|
|
17499
|
-
/**
|
|
17500
|
-
* Logger object for convenient access
|
|
17501
|
-
*/
|
|
17502
|
-
const logger = {
|
|
17503
|
-
/**
|
|
17504
|
-
* Debug level - verbose details for troubleshooting
|
|
17505
|
-
*/
|
|
17506
|
-
debug: (message, ...args) => log('debug', message, ...args),
|
|
17507
|
-
/**
|
|
17508
|
-
* Info level - general information
|
|
17509
|
-
*/
|
|
17510
|
-
info: (message, ...args) => log('info', message, ...args),
|
|
17511
|
-
/**
|
|
17512
|
-
* Warn level - warnings that don't prevent operation
|
|
17513
|
-
*/
|
|
17514
|
-
warn: (message, ...args) => log('warn', message, ...args),
|
|
17515
|
-
/**
|
|
17516
|
-
* Error level - always logged regardless of debug mode
|
|
17517
|
-
*/
|
|
17518
|
-
error: (message, ...args) => log('error', message, ...args),
|
|
17519
|
-
};
|
|
17520
|
-
|
|
17521
17797
|
/**
|
|
17522
17798
|
* SparkVault Auto-Initialization
|
|
17523
17799
|
*
|
|
@@ -17652,7 +17928,7 @@ class SparkVault {
|
|
|
17652
17928
|
}
|
|
17653
17929
|
/** Get the SDK version */
|
|
17654
17930
|
static get version() {
|
|
17655
|
-
return '12.0.
|
|
17931
|
+
return '12.0.4';
|
|
17656
17932
|
}
|
|
17657
17933
|
}
|
|
17658
17934
|
if (typeof window !== 'undefined') {
|
|
@@ -17667,6 +17943,7 @@ exports.AuthorizationError = AuthorizationError;
|
|
|
17667
17943
|
exports.EntropyModule = EntropyModule;
|
|
17668
17944
|
exports.FoldersModule = FoldersModule;
|
|
17669
17945
|
exports.IdentityModule = IdentityModule;
|
|
17946
|
+
exports.IdentityProviderError = IdentityProviderError;
|
|
17670
17947
|
exports.IngotsModule = IngotsModule;
|
|
17671
17948
|
exports.NAME_CONFLICT_POLICIES = NAME_CONFLICT_POLICIES;
|
|
17672
17949
|
exports.NOTIFY_PRESETS = NOTIFY_PRESETS;
|
|
@@ -17688,6 +17965,7 @@ exports.VaultsModule = VaultsModule;
|
|
|
17688
17965
|
exports.buildNotifyPresetSend = buildNotifyPresetSend;
|
|
17689
17966
|
exports.default = SparkVault;
|
|
17690
17967
|
exports.fetchDownload = fetchDownload;
|
|
17968
|
+
exports.isReceivedUploadFailure = isReceivedUploadFailure;
|
|
17691
17969
|
exports.logger = logger;
|
|
17692
17970
|
exports.setDebugMode = setDebugMode;
|
|
17693
17971
|
//# sourceMappingURL=index.cjs.map
|