@sparkvault/sdk-js 12.0.3 → 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/index.cjs +324 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +192 -89
- package/dist/index.mjs +324 -83
- 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/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):
|
|
@@ -11974,6 +12007,38 @@ function waitUntilOnline(signal) {
|
|
|
11974
12007
|
settle(resolve);
|
|
11975
12008
|
});
|
|
11976
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
|
+
}
|
|
11977
12042
|
/** A failed request of this upload's transfer; anything else is rethrown as it is. */
|
|
11978
12043
|
function transferFailure(error) {
|
|
11979
12044
|
if (error instanceof UploadApiError)
|
|
@@ -12371,7 +12436,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
12371
12436
|
// the server (a chunk's 204, a HEAD, a 409), publication is confirmed
|
|
12372
12437
|
// before the upload resolves.
|
|
12373
12438
|
if (offset === file.size) {
|
|
12374
|
-
const receipt = await this.confirmServerFinalized(transfer)
|
|
12439
|
+
const receipt = await this.confirmServerFinalized(transfer).catch((error) => {
|
|
12440
|
+
throw receiptFailure(error);
|
|
12441
|
+
});
|
|
12375
12442
|
if (receipt.published)
|
|
12376
12443
|
return;
|
|
12377
12444
|
offset = receipt.resumeAt;
|
|
@@ -14221,6 +14288,11 @@ function formatBytes(bytes, decimals = 1) {
|
|
|
14221
14288
|
* admin how to cancel the deletion, is the console's, never this page's.
|
|
14222
14289
|
*/
|
|
14223
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.';
|
|
14224
14296
|
/**
|
|
14225
14297
|
* Ceremony steps for the cryptographic visualization.
|
|
14226
14298
|
*/
|
|
@@ -14249,6 +14321,36 @@ function transferChannelLine(requestId) {
|
|
|
14249
14321
|
? ''
|
|
14250
14322
|
: `<p class="svu-forging-line">Secure Transfer Channel: <span class="svu-mono">${escapeHtml(requestId)}</span></p>`;
|
|
14251
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
|
+
}
|
|
14252
14354
|
/**
|
|
14253
14355
|
* Whether an error represents a deliberate cancellation (user close,
|
|
14254
14356
|
* programmatic close, or session abort) rather than a genuine failure.
|
|
@@ -14301,11 +14403,13 @@ class UploadRenderer {
|
|
|
14301
14403
|
// (its own button, picker, or drop target) and hand the File to the SDK.
|
|
14302
14404
|
if (this.options.file) {
|
|
14303
14405
|
this.selectedFile = this.options.file;
|
|
14406
|
+
this.callbacks.onReady?.();
|
|
14304
14407
|
await this.startUpload(config);
|
|
14305
14408
|
return;
|
|
14306
14409
|
}
|
|
14307
14410
|
// Show form
|
|
14308
14411
|
this.setState({ view: 'form', config });
|
|
14412
|
+
this.callbacks.onReady?.();
|
|
14309
14413
|
}
|
|
14310
14414
|
catch (error) {
|
|
14311
14415
|
this.handleApiError(error);
|
|
@@ -14812,9 +14916,26 @@ class UploadRenderer {
|
|
|
14812
14916
|
<span class="svu-error-code-value">${escapeHtml(state.code)}</span>
|
|
14813
14917
|
</div>
|
|
14814
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
|
+
}
|
|
14815
14932
|
return div;
|
|
14816
14933
|
}
|
|
14817
14934
|
handleFileSelect(file, config) {
|
|
14935
|
+
if (file.size === 0) {
|
|
14936
|
+
this.setState({ view: 'form', config, error: EMPTY_FILE_MESSAGE });
|
|
14937
|
+
return;
|
|
14938
|
+
}
|
|
14818
14939
|
// Validate file size
|
|
14819
14940
|
if (file.size > config.maxSizeBytes) {
|
|
14820
14941
|
this.setState({
|
|
@@ -14939,7 +15060,9 @@ class UploadRenderer {
|
|
|
14939
15060
|
this.callbacks.onSuccess(result);
|
|
14940
15061
|
}
|
|
14941
15062
|
catch (error) {
|
|
14942
|
-
|
|
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));
|
|
14943
15066
|
}
|
|
14944
15067
|
}
|
|
14945
15068
|
async runCeremony(file, ingotId, requestId) {
|
|
@@ -14971,7 +15094,11 @@ class UploadRenderer {
|
|
|
14971
15094
|
});
|
|
14972
15095
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
14973
15096
|
}
|
|
14974
|
-
|
|
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) {
|
|
14975
15102
|
// A closed renderer must not surface errors: cancelling mid-transfer
|
|
14976
15103
|
// aborts the in-flight request, whose 'cancelled' rejection races the
|
|
14977
15104
|
// teardown. The host has already received onCancel — onCancel and
|
|
@@ -14987,6 +15114,7 @@ class UploadRenderer {
|
|
|
14987
15114
|
// points at the dashboard rather than the end user.
|
|
14988
15115
|
this.setState({
|
|
14989
15116
|
view: 'error',
|
|
15117
|
+
action,
|
|
14990
15118
|
title: 'Upload Widget Not Enabled',
|
|
14991
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.',
|
|
14992
15120
|
code: 'UPLOAD_SOURCE_DISABLED',
|
|
@@ -15000,6 +15128,7 @@ class UploadRenderer {
|
|
|
15000
15128
|
// tells it never to upload the file again.
|
|
15001
15129
|
this.setState({
|
|
15002
15130
|
view: 'error',
|
|
15131
|
+
action,
|
|
15003
15132
|
title: 'Upload Received',
|
|
15004
15133
|
message: error.message,
|
|
15005
15134
|
code: error.code,
|
|
@@ -15013,6 +15142,7 @@ class UploadRenderer {
|
|
|
15013
15142
|
// uploader, told only that the vault takes no files now.
|
|
15014
15143
|
this.setState({
|
|
15015
15144
|
view: 'error',
|
|
15145
|
+
action,
|
|
15016
15146
|
title: 'Uploads Paused',
|
|
15017
15147
|
message: VAULT_NOT_ACCEPTING_MESSAGE,
|
|
15018
15148
|
code: error.code,
|
|
@@ -15025,6 +15155,7 @@ class UploadRenderer {
|
|
|
15025
15155
|
// sentence that never asks for the file again.
|
|
15026
15156
|
this.setState({
|
|
15027
15157
|
view: 'error',
|
|
15158
|
+
action,
|
|
15028
15159
|
title: 'Upload Not Saved',
|
|
15029
15160
|
message: error.message,
|
|
15030
15161
|
code: error.code,
|
|
@@ -15036,6 +15167,7 @@ class UploadRenderer {
|
|
|
15036
15167
|
// can answer 404 too, and its own sentence says what became of the file.
|
|
15037
15168
|
this.setState({
|
|
15038
15169
|
view: 'error',
|
|
15170
|
+
action,
|
|
15039
15171
|
title: 'Upload Page Not Found',
|
|
15040
15172
|
message: 'The requested upload endpoint could not be located. This may occur if the upload link has expired or was entered incorrectly.',
|
|
15041
15173
|
code: 'NOT_FOUND',
|
|
@@ -15045,6 +15177,7 @@ class UploadRenderer {
|
|
|
15045
15177
|
else if (error.statusCode === 402) {
|
|
15046
15178
|
this.setState({
|
|
15047
15179
|
view: 'error',
|
|
15180
|
+
action,
|
|
15048
15181
|
title: 'Service Unavailable',
|
|
15049
15182
|
message: 'This upload endpoint has been temporarily disabled due to an account billing issue. Please contact the organization\'s administrator.',
|
|
15050
15183
|
code: 'PAYMENT_REQUIRED',
|
|
@@ -15054,6 +15187,7 @@ class UploadRenderer {
|
|
|
15054
15187
|
else {
|
|
15055
15188
|
this.setState({
|
|
15056
15189
|
view: 'error',
|
|
15190
|
+
action,
|
|
15057
15191
|
title: 'Upload Failed',
|
|
15058
15192
|
message: error.message,
|
|
15059
15193
|
code: error.code,
|
|
@@ -15065,6 +15199,7 @@ class UploadRenderer {
|
|
|
15065
15199
|
else if (error instanceof Error) {
|
|
15066
15200
|
this.setState({
|
|
15067
15201
|
view: 'error',
|
|
15202
|
+
action,
|
|
15068
15203
|
title: 'Upload Failed',
|
|
15069
15204
|
message: error.message,
|
|
15070
15205
|
code: 'UNKNOWN_ERROR',
|
|
@@ -15075,6 +15210,7 @@ class UploadRenderer {
|
|
|
15075
15210
|
const err = new Error('An unexpected error occurred');
|
|
15076
15211
|
this.setState({
|
|
15077
15212
|
view: 'error',
|
|
15213
|
+
action,
|
|
15078
15214
|
title: 'Upload Failed',
|
|
15079
15215
|
message: err.message,
|
|
15080
15216
|
code: 'UNKNOWN_ERROR',
|
|
@@ -15161,6 +15297,7 @@ class VaultUploadModule {
|
|
|
15161
15297
|
reject(error);
|
|
15162
15298
|
},
|
|
15163
15299
|
onProgress: options.onProgress,
|
|
15300
|
+
onReady: options.onReady,
|
|
15164
15301
|
});
|
|
15165
15302
|
this.renderer.start().catch((error) => {
|
|
15166
15303
|
options.onError?.(error);
|
|
@@ -15693,6 +15830,74 @@ function readIngotAccess(entry) {
|
|
|
15693
15830
|
};
|
|
15694
15831
|
}
|
|
15695
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
|
+
|
|
15696
15901
|
/**
|
|
15697
15902
|
* The one browser transfer for a signed ingot download link: fetch it into a
|
|
15698
15903
|
* Blob under liveness bounds, resuming from the bytes it holds when the caller
|
|
@@ -16372,7 +16577,9 @@ class IngotsModule {
|
|
|
16372
16577
|
* transfer yourself; otherwise prefer {@link upload}. A create another
|
|
16373
16578
|
* upload of the same file superseded before its token was issued rejects
|
|
16374
16579
|
* with code `upload_refused` (`details.coreCode` UPLOAD_SUPERSEDED): the
|
|
16375
|
-
* 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.
|
|
16376
16583
|
*
|
|
16377
16584
|
* @example
|
|
16378
16585
|
* const session = await sv.ingots.createUpload({
|
|
@@ -16401,15 +16608,65 @@ class IngotsModule {
|
|
|
16401
16608
|
onNameConflict: options.onNameConflict,
|
|
16402
16609
|
});
|
|
16403
16610
|
return {
|
|
16404
|
-
|
|
16611
|
+
...placementOf(created),
|
|
16405
16612
|
name: created.name,
|
|
16406
16613
|
contentType: created.content_type,
|
|
16407
16614
|
size: created.size_bytes,
|
|
16408
16615
|
uploadUrl: created.forge_url,
|
|
16409
16616
|
expiresAt: created.expires_at,
|
|
16410
|
-
created: created.created,
|
|
16411
16617
|
};
|
|
16412
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
|
+
}
|
|
16413
16670
|
/**
|
|
16414
16671
|
* Send a file's bytes to an upload session — the `uploadUrl` a
|
|
16415
16672
|
* {@link createUpload} returned — over the resumable transfer every SDK
|
|
@@ -16517,7 +16774,11 @@ class IngotsModule {
|
|
|
16517
16774
|
* server refused — another upload of it superseded this one, at its create
|
|
16518
16775
|
* or while it streamed, the storage pool cannot take it, or its vault is
|
|
16519
16776
|
* scheduled for deletion (a 409 `VAULT_DELETION_SCHEDULED`) — rejects with
|
|
16520
|
-
* 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.
|
|
16521
16782
|
*
|
|
16522
16783
|
* @example
|
|
16523
16784
|
* const ingot = await sv.ingots.upload(unsealed, {
|
|
@@ -16539,7 +16800,29 @@ class IngotsModule {
|
|
|
16539
16800
|
folderId: options.folderId,
|
|
16540
16801
|
onNameConflict: options.onNameConflict,
|
|
16541
16802
|
});
|
|
16542
|
-
|
|
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
|
+
});
|
|
16543
16826
|
}
|
|
16544
16827
|
/**
|
|
16545
16828
|
* Replace an existing ingot's content (high-level flow). Rejects as
|
|
@@ -16777,8 +17060,11 @@ class IngotsModule {
|
|
|
16777
17060
|
return mapSharingConfig(response.data);
|
|
16778
17061
|
}
|
|
16779
17062
|
/**
|
|
16780
|
-
* Invite an identity to
|
|
16781
|
-
*
|
|
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.
|
|
16782
17068
|
*
|
|
16783
17069
|
* @example
|
|
16784
17070
|
* await sv.ingots.addInvite(unsealed, 'ing_abc', 'user@example.com');
|
|
@@ -16790,7 +17076,7 @@ class IngotsModule {
|
|
|
16790
17076
|
const vaultId = requireVaultId(vault);
|
|
16791
17077
|
const id = requireResourceId(ingotId, 'ingotId');
|
|
16792
17078
|
const response = await this.http.post(apiPath `/v1/vaults/${vaultId}/ingots/${id}/sharing/invite`, { identity }, { vat: vault.vatToken });
|
|
16793
|
-
return
|
|
17079
|
+
return mapInvitation(response.data);
|
|
16794
17080
|
}
|
|
16795
17081
|
/**
|
|
16796
17082
|
* Revoke an ingot sharing invite.
|
|
@@ -16876,6 +17162,8 @@ class IngotsModule {
|
|
|
16876
17162
|
throw stagingRefusalOf(error);
|
|
16877
17163
|
});
|
|
16878
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));
|
|
16879
17167
|
throw new ValidationError('Upload endpoint did not return a Forge upload URL');
|
|
16880
17168
|
}
|
|
16881
17169
|
return response.data;
|
|
@@ -16906,6 +17194,14 @@ class IngotsModule {
|
|
|
16906
17194
|
}
|
|
16907
17195
|
}
|
|
16908
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
|
+
}
|
|
16909
17205
|
function getBlobName(file) {
|
|
16910
17206
|
if (typeof File !== 'undefined' && file instanceof File && file.name) {
|
|
16911
17207
|
return file.name;
|
|
@@ -16955,7 +17251,12 @@ function mapIngotPage(response) {
|
|
|
16955
17251
|
function mapSharingConfig(wire) {
|
|
16956
17252
|
return {
|
|
16957
17253
|
shared: wire.shared,
|
|
16958
|
-
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,
|
|
16959
17260
|
invites: wire.invites?.map(mapInvite),
|
|
16960
17261
|
};
|
|
16961
17262
|
}
|
|
@@ -16964,6 +17265,14 @@ function mapInvite(wire) {
|
|
|
16964
17265
|
id: wire.invite_id,
|
|
16965
17266
|
identity: wire.identity,
|
|
16966
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,
|
|
16967
17276
|
};
|
|
16968
17277
|
}
|
|
16969
17278
|
|
|
@@ -17485,74 +17794,6 @@ class NotifyModule {
|
|
|
17485
17794
|
}
|
|
17486
17795
|
}
|
|
17487
17796
|
|
|
17488
|
-
/**
|
|
17489
|
-
* SparkVault Debug Logger
|
|
17490
|
-
*
|
|
17491
|
-
* Conditional logging that respects debug mode setting.
|
|
17492
|
-
* When debug is enabled, logs detailed information to console.
|
|
17493
|
-
* When disabled (default), only fatal errors are logged.
|
|
17494
|
-
*/
|
|
17495
|
-
let debugEnabled = false;
|
|
17496
|
-
/**
|
|
17497
|
-
* Enable or disable debug logging
|
|
17498
|
-
*/
|
|
17499
|
-
function setDebugMode(enabled) {
|
|
17500
|
-
debugEnabled = enabled;
|
|
17501
|
-
if (enabled) {
|
|
17502
|
-
log('info', 'Debug mode enabled');
|
|
17503
|
-
}
|
|
17504
|
-
}
|
|
17505
|
-
/**
|
|
17506
|
-
* Internal log function
|
|
17507
|
-
*/
|
|
17508
|
-
function log(level, message, ...args) {
|
|
17509
|
-
const prefix = '[SparkVault]';
|
|
17510
|
-
const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
|
|
17511
|
-
const formattedMessage = `${prefix} ${timestamp} ${message}`;
|
|
17512
|
-
switch (level) {
|
|
17513
|
-
case 'debug':
|
|
17514
|
-
if (debugEnabled) {
|
|
17515
|
-
console.debug(formattedMessage, ...args);
|
|
17516
|
-
}
|
|
17517
|
-
break;
|
|
17518
|
-
case 'info':
|
|
17519
|
-
if (debugEnabled) {
|
|
17520
|
-
console.log(formattedMessage, ...args);
|
|
17521
|
-
}
|
|
17522
|
-
break;
|
|
17523
|
-
case 'warn':
|
|
17524
|
-
if (debugEnabled) {
|
|
17525
|
-
console.warn(formattedMessage, ...args);
|
|
17526
|
-
}
|
|
17527
|
-
break;
|
|
17528
|
-
case 'error':
|
|
17529
|
-
// Always log errors (fatal)
|
|
17530
|
-
console.error(formattedMessage, ...args);
|
|
17531
|
-
break;
|
|
17532
|
-
}
|
|
17533
|
-
}
|
|
17534
|
-
/**
|
|
17535
|
-
* Logger object for convenient access
|
|
17536
|
-
*/
|
|
17537
|
-
const logger = {
|
|
17538
|
-
/**
|
|
17539
|
-
* Debug level - verbose details for troubleshooting
|
|
17540
|
-
*/
|
|
17541
|
-
debug: (message, ...args) => log('debug', message, ...args),
|
|
17542
|
-
/**
|
|
17543
|
-
* Info level - general information
|
|
17544
|
-
*/
|
|
17545
|
-
info: (message, ...args) => log('info', message, ...args),
|
|
17546
|
-
/**
|
|
17547
|
-
* Warn level - warnings that don't prevent operation
|
|
17548
|
-
*/
|
|
17549
|
-
warn: (message, ...args) => log('warn', message, ...args),
|
|
17550
|
-
/**
|
|
17551
|
-
* Error level - always logged regardless of debug mode
|
|
17552
|
-
*/
|
|
17553
|
-
error: (message, ...args) => log('error', message, ...args),
|
|
17554
|
-
};
|
|
17555
|
-
|
|
17556
17797
|
/**
|
|
17557
17798
|
* SparkVault Auto-Initialization
|
|
17558
17799
|
*
|
|
@@ -17687,7 +17928,7 @@ class SparkVault {
|
|
|
17687
17928
|
}
|
|
17688
17929
|
/** Get the SDK version */
|
|
17689
17930
|
static get version() {
|
|
17690
|
-
return '12.0.
|
|
17931
|
+
return '12.0.4';
|
|
17691
17932
|
}
|
|
17692
17933
|
}
|
|
17693
17934
|
if (typeof window !== 'undefined') {
|
|
@@ -17724,6 +17965,7 @@ exports.VaultsModule = VaultsModule;
|
|
|
17724
17965
|
exports.buildNotifyPresetSend = buildNotifyPresetSend;
|
|
17725
17966
|
exports.default = SparkVault;
|
|
17726
17967
|
exports.fetchDownload = fetchDownload;
|
|
17968
|
+
exports.isReceivedUploadFailure = isReceivedUploadFailure;
|
|
17727
17969
|
exports.logger = logger;
|
|
17728
17970
|
exports.setDebugMode = setDebugMode;
|
|
17729
17971
|
//# sourceMappingURL=index.cjs.map
|