@sparkvault/sdk-js 12.0.3 → 12.0.5
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 +342 -90
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +196 -91
- package/dist/index.mjs +342 -91
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/index.d.ts +54 -7
- package/dist/ingots/types.d.ts +59 -4
- 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):
|
|
@@ -1876,14 +1909,14 @@ function defineEntropyLayout(fields) {
|
|
|
1876
1909
|
}
|
|
1877
1910
|
const names = new Set();
|
|
1878
1911
|
let bytes = 0;
|
|
1879
|
-
for (const [
|
|
1880
|
-
if (typeof
|
|
1881
|
-
throw new TypeError(`Entropy layout field names must be unique non-empty strings (${String(
|
|
1912
|
+
for (const [field, length] of fields) {
|
|
1913
|
+
if (typeof field !== 'string' || field.length === 0 || names.has(field)) {
|
|
1914
|
+
throw new TypeError(`Entropy layout field names must be unique non-empty strings (${String(field)})`);
|
|
1882
1915
|
}
|
|
1883
1916
|
if (!Number.isSafeInteger(length) || length <= 0) {
|
|
1884
|
-
throw new TypeError(`Entropy layout field ${
|
|
1917
|
+
throw new TypeError(`Entropy layout field ${field} must be a positive whole number of bytes`);
|
|
1885
1918
|
}
|
|
1886
|
-
names.add(
|
|
1919
|
+
names.add(field);
|
|
1887
1920
|
bytes += length;
|
|
1888
1921
|
}
|
|
1889
1922
|
if (bytes > MAX_DRAW_BYTES) {
|
|
@@ -3641,7 +3674,15 @@ class SparkLinkHandler {
|
|
|
3641
3674
|
* alike.
|
|
3642
3675
|
*/
|
|
3643
3676
|
|
|
3644
|
-
|
|
3677
|
+
/**
|
|
3678
|
+
* The characters an RFC 5322 dot-atom local part holds, in its canonical
|
|
3679
|
+
* (lowercase) form, as the body of a character class: the one set the
|
|
3680
|
+
* grammar below accepts and the log mask (./pii-mask.js) reads an address in
|
|
3681
|
+
* text by.
|
|
3682
|
+
*/
|
|
3683
|
+
const EMAIL_LOCAL_PART_CHARACTERS = "a-z0-9.!#$%&'*+/=?^_`{|}~-";
|
|
3684
|
+
|
|
3685
|
+
const LOCAL_PART = new RegExp(`^[${EMAIL_LOCAL_PART_CHARACTERS}]+$`);
|
|
3645
3686
|
const DOMAIN_LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
3646
3687
|
|
|
3647
3688
|
/** RFC 5321 length limits, in characters. */
|
|
@@ -11974,6 +12015,38 @@ function waitUntilOnline(signal) {
|
|
|
11974
12015
|
settle(resolve);
|
|
11975
12016
|
});
|
|
11976
12017
|
}
|
|
12018
|
+
/**
|
|
12019
|
+
* The failures a transfer met once the server held every byte of its upload,
|
|
12020
|
+
* which leave the upload's end to the server ({@link isReceivedUploadFailure}).
|
|
12021
|
+
*/
|
|
12022
|
+
const receivedFailures = new WeakSet();
|
|
12023
|
+
/** The codes that end an upload whatever the server holds of it: its session gone, Core's refusal, the caller's cancel. */
|
|
12024
|
+
const UPLOAD_ENDING_CODES = new Set(['session_gone', 'upload_refused', 'cancelled']);
|
|
12025
|
+
/**
|
|
12026
|
+
* A failure of the receipt, which the transfer asks for only once the server
|
|
12027
|
+
* holds every byte: it leaves the upload's end to the server unless it ended
|
|
12028
|
+
* the upload itself (UPLOAD_ENDING_CODES) or named an earlier offset, bytes
|
|
12029
|
+
* the server lacks.
|
|
12030
|
+
*/
|
|
12031
|
+
function receiptFailure(error) {
|
|
12032
|
+
if (error instanceof UploadApiError &&
|
|
12033
|
+
!UPLOAD_ENDING_CODES.has(error.code) &&
|
|
12034
|
+
error.verdict !== TRANSFER_VERDICT.RESYNC) {
|
|
12035
|
+
receivedFailures.add(error);
|
|
12036
|
+
}
|
|
12037
|
+
return error;
|
|
12038
|
+
}
|
|
12039
|
+
/**
|
|
12040
|
+
* Whether a transfer failed once the server held every byte of its upload,
|
|
12041
|
+
* short of the upload's own end: `upload_received_publishing`, and any other
|
|
12042
|
+
* failure of the receipt that confirms publication (one refused, or one that
|
|
12043
|
+
* went unanswered), never a gone session, Core's refusal or a cancel. The
|
|
12044
|
+
* server publishes such an upload, or ends it, on its own, so its caller
|
|
12045
|
+
* neither sends it again nor gives it up (`ingots.endUpload`).
|
|
12046
|
+
*/
|
|
12047
|
+
function isReceivedUploadFailure(error) {
|
|
12048
|
+
return error instanceof UploadApiError && receivedFailures.has(error);
|
|
12049
|
+
}
|
|
11977
12050
|
/** A failed request of this upload's transfer; anything else is rethrown as it is. */
|
|
11978
12051
|
function transferFailure(error) {
|
|
11979
12052
|
if (error instanceof UploadApiError)
|
|
@@ -12371,7 +12444,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
12371
12444
|
// the server (a chunk's 204, a HEAD, a 409), publication is confirmed
|
|
12372
12445
|
// before the upload resolves.
|
|
12373
12446
|
if (offset === file.size) {
|
|
12374
|
-
const receipt = await this.confirmServerFinalized(transfer)
|
|
12447
|
+
const receipt = await this.confirmServerFinalized(transfer).catch((error) => {
|
|
12448
|
+
throw receiptFailure(error);
|
|
12449
|
+
});
|
|
12375
12450
|
if (receipt.published)
|
|
12376
12451
|
return;
|
|
12377
12452
|
offset = receipt.resumeAt;
|
|
@@ -14221,6 +14296,11 @@ function formatBytes(bytes, decimals = 1) {
|
|
|
14221
14296
|
* admin how to cancel the deletion, is the console's, never this page's.
|
|
14222
14297
|
*/
|
|
14223
14298
|
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.';
|
|
14299
|
+
/**
|
|
14300
|
+
* What an uploader reads for a file of no bytes, which Core never stores: said
|
|
14301
|
+
* on the form, where another file can be chosen, as the size limit is.
|
|
14302
|
+
*/
|
|
14303
|
+
const EMPTY_FILE_MESSAGE = 'This file is empty, so there is nothing to upload. Choose another file.';
|
|
14224
14304
|
/**
|
|
14225
14305
|
* Ceremony steps for the cryptographic visualization.
|
|
14226
14306
|
*/
|
|
@@ -14249,6 +14329,36 @@ function transferChannelLine(requestId) {
|
|
|
14249
14329
|
? ''
|
|
14250
14330
|
: `<p class="svu-forging-line">Secure Transfer Channel: <span class="svu-mono">${escapeHtml(requestId)}</span></p>`;
|
|
14251
14331
|
}
|
|
14332
|
+
/**
|
|
14333
|
+
* Refusals that say the vault takes no upload now, whichever file is chosen:
|
|
14334
|
+
* it is scheduled for deletion, its owner's plan lapsed, or its upload page is
|
|
14335
|
+
* gone or switched off. An error view after one offers no way on.
|
|
14336
|
+
*/
|
|
14337
|
+
function vaultTakesNoUpload(error) {
|
|
14338
|
+
return error.code === VAULT_DELETION_SCHEDULED
|
|
14339
|
+
|| error.details?.coreCode === VAULT_DELETION_SCHEDULED
|
|
14340
|
+
|| error.code === 'UPLOAD_SOURCE_DISABLED'
|
|
14341
|
+
|| error.statusCode === 402
|
|
14342
|
+
|| (error.statusCode === 404 && error.code !== 'session_gone');
|
|
14343
|
+
}
|
|
14344
|
+
/**
|
|
14345
|
+
* The way on an error view offers after an upload of the chosen file failed:
|
|
14346
|
+
* nothing while the vault takes no upload ({@link vaultTakesNoUpload}); the
|
|
14347
|
+
* same file again after a failure that may pass (no answer, a fault, a rate
|
|
14348
|
+
* limit); another file after a refusal of this one, or after one received
|
|
14349
|
+
* whole, which the server finishes saving on its own.
|
|
14350
|
+
*/
|
|
14351
|
+
function recoveryAfterUpload(error) {
|
|
14352
|
+
if (!(error instanceof UploadApiError))
|
|
14353
|
+
return { label: 'Try Again', keepFile: true };
|
|
14354
|
+
if (vaultTakesNoUpload(error))
|
|
14355
|
+
return null;
|
|
14356
|
+
if (error.code === RECEIVED_STILL_SAVING)
|
|
14357
|
+
return { label: 'Upload Another File', keepFile: false };
|
|
14358
|
+
const status = error.statusCode ?? 0;
|
|
14359
|
+
const mayPass = status === 0 || status === 429 || status >= 500;
|
|
14360
|
+
return mayPass ? { label: 'Try Again', keepFile: true } : { label: 'Choose Another File', keepFile: false };
|
|
14361
|
+
}
|
|
14252
14362
|
/**
|
|
14253
14363
|
* Whether an error represents a deliberate cancellation (user close,
|
|
14254
14364
|
* programmatic close, or session abort) rather than a genuine failure.
|
|
@@ -14301,11 +14411,13 @@ class UploadRenderer {
|
|
|
14301
14411
|
// (its own button, picker, or drop target) and hand the File to the SDK.
|
|
14302
14412
|
if (this.options.file) {
|
|
14303
14413
|
this.selectedFile = this.options.file;
|
|
14414
|
+
this.callbacks.onReady?.();
|
|
14304
14415
|
await this.startUpload(config);
|
|
14305
14416
|
return;
|
|
14306
14417
|
}
|
|
14307
14418
|
// Show form
|
|
14308
14419
|
this.setState({ view: 'form', config });
|
|
14420
|
+
this.callbacks.onReady?.();
|
|
14309
14421
|
}
|
|
14310
14422
|
catch (error) {
|
|
14311
14423
|
this.handleApiError(error);
|
|
@@ -14812,9 +14924,26 @@ class UploadRenderer {
|
|
|
14812
14924
|
<span class="svu-error-code-value">${escapeHtml(state.code)}</span>
|
|
14813
14925
|
</div>
|
|
14814
14926
|
`;
|
|
14927
|
+
const { action } = state;
|
|
14928
|
+
if (action && this.config) {
|
|
14929
|
+
const config = this.config;
|
|
14930
|
+
const recover = document.createElement('button');
|
|
14931
|
+
recover.className = 'svu-btn svu-btn-primary';
|
|
14932
|
+
recover.textContent = action.label;
|
|
14933
|
+
recover.addEventListener('click', () => {
|
|
14934
|
+
if (!action.keepFile)
|
|
14935
|
+
this.selectedFile = null;
|
|
14936
|
+
this.setState({ view: 'form', config });
|
|
14937
|
+
});
|
|
14938
|
+
div.appendChild(recover);
|
|
14939
|
+
}
|
|
14815
14940
|
return div;
|
|
14816
14941
|
}
|
|
14817
14942
|
handleFileSelect(file, config) {
|
|
14943
|
+
if (file.size === 0) {
|
|
14944
|
+
this.setState({ view: 'form', config, error: EMPTY_FILE_MESSAGE });
|
|
14945
|
+
return;
|
|
14946
|
+
}
|
|
14818
14947
|
// Validate file size
|
|
14819
14948
|
if (file.size > config.maxSizeBytes) {
|
|
14820
14949
|
this.setState({
|
|
@@ -14939,7 +15068,9 @@ class UploadRenderer {
|
|
|
14939
15068
|
this.callbacks.onSuccess(result);
|
|
14940
15069
|
}
|
|
14941
15070
|
catch (error) {
|
|
14942
|
-
|
|
15071
|
+
// A host that chose the file itself offers its own way on; the
|
|
15072
|
+
// widget's form is the way on only for a file chosen on it.
|
|
15073
|
+
this.handleApiError(error, this.options.file ? null : recoveryAfterUpload(error));
|
|
14943
15074
|
}
|
|
14944
15075
|
}
|
|
14945
15076
|
async runCeremony(file, ingotId, requestId) {
|
|
@@ -14971,7 +15102,11 @@ class UploadRenderer {
|
|
|
14971
15102
|
});
|
|
14972
15103
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
14973
15104
|
}
|
|
14974
|
-
|
|
15105
|
+
/**
|
|
15106
|
+
* Show a failure in the error view, with the way on it offers (`action`:
|
|
15107
|
+
* none for a page that could not load), and tell the host through onError.
|
|
15108
|
+
*/
|
|
15109
|
+
handleApiError(error, action = null) {
|
|
14975
15110
|
// A closed renderer must not surface errors: cancelling mid-transfer
|
|
14976
15111
|
// aborts the in-flight request, whose 'cancelled' rejection races the
|
|
14977
15112
|
// teardown. The host has already received onCancel — onCancel and
|
|
@@ -14987,6 +15122,7 @@ class UploadRenderer {
|
|
|
14987
15122
|
// points at the dashboard rather than the end user.
|
|
14988
15123
|
this.setState({
|
|
14989
15124
|
view: 'error',
|
|
15125
|
+
action,
|
|
14990
15126
|
title: 'Upload Widget Not Enabled',
|
|
14991
15127
|
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
15128
|
code: 'UPLOAD_SOURCE_DISABLED',
|
|
@@ -15000,6 +15136,7 @@ class UploadRenderer {
|
|
|
15000
15136
|
// tells it never to upload the file again.
|
|
15001
15137
|
this.setState({
|
|
15002
15138
|
view: 'error',
|
|
15139
|
+
action,
|
|
15003
15140
|
title: 'Upload Received',
|
|
15004
15141
|
message: error.message,
|
|
15005
15142
|
code: error.code,
|
|
@@ -15013,6 +15150,7 @@ class UploadRenderer {
|
|
|
15013
15150
|
// uploader, told only that the vault takes no files now.
|
|
15014
15151
|
this.setState({
|
|
15015
15152
|
view: 'error',
|
|
15153
|
+
action,
|
|
15016
15154
|
title: 'Uploads Paused',
|
|
15017
15155
|
message: VAULT_NOT_ACCEPTING_MESSAGE,
|
|
15018
15156
|
code: error.code,
|
|
@@ -15025,6 +15163,7 @@ class UploadRenderer {
|
|
|
15025
15163
|
// sentence that never asks for the file again.
|
|
15026
15164
|
this.setState({
|
|
15027
15165
|
view: 'error',
|
|
15166
|
+
action,
|
|
15028
15167
|
title: 'Upload Not Saved',
|
|
15029
15168
|
message: error.message,
|
|
15030
15169
|
code: error.code,
|
|
@@ -15036,6 +15175,7 @@ class UploadRenderer {
|
|
|
15036
15175
|
// can answer 404 too, and its own sentence says what became of the file.
|
|
15037
15176
|
this.setState({
|
|
15038
15177
|
view: 'error',
|
|
15178
|
+
action,
|
|
15039
15179
|
title: 'Upload Page Not Found',
|
|
15040
15180
|
message: 'The requested upload endpoint could not be located. This may occur if the upload link has expired or was entered incorrectly.',
|
|
15041
15181
|
code: 'NOT_FOUND',
|
|
@@ -15045,6 +15185,7 @@ class UploadRenderer {
|
|
|
15045
15185
|
else if (error.statusCode === 402) {
|
|
15046
15186
|
this.setState({
|
|
15047
15187
|
view: 'error',
|
|
15188
|
+
action,
|
|
15048
15189
|
title: 'Service Unavailable',
|
|
15049
15190
|
message: 'This upload endpoint has been temporarily disabled due to an account billing issue. Please contact the organization\'s administrator.',
|
|
15050
15191
|
code: 'PAYMENT_REQUIRED',
|
|
@@ -15054,6 +15195,7 @@ class UploadRenderer {
|
|
|
15054
15195
|
else {
|
|
15055
15196
|
this.setState({
|
|
15056
15197
|
view: 'error',
|
|
15198
|
+
action,
|
|
15057
15199
|
title: 'Upload Failed',
|
|
15058
15200
|
message: error.message,
|
|
15059
15201
|
code: error.code,
|
|
@@ -15065,6 +15207,7 @@ class UploadRenderer {
|
|
|
15065
15207
|
else if (error instanceof Error) {
|
|
15066
15208
|
this.setState({
|
|
15067
15209
|
view: 'error',
|
|
15210
|
+
action,
|
|
15068
15211
|
title: 'Upload Failed',
|
|
15069
15212
|
message: error.message,
|
|
15070
15213
|
code: 'UNKNOWN_ERROR',
|
|
@@ -15075,6 +15218,7 @@ class UploadRenderer {
|
|
|
15075
15218
|
const err = new Error('An unexpected error occurred');
|
|
15076
15219
|
this.setState({
|
|
15077
15220
|
view: 'error',
|
|
15221
|
+
action,
|
|
15078
15222
|
title: 'Upload Failed',
|
|
15079
15223
|
message: err.message,
|
|
15080
15224
|
code: 'UNKNOWN_ERROR',
|
|
@@ -15161,6 +15305,7 @@ class VaultUploadModule {
|
|
|
15161
15305
|
reject(error);
|
|
15162
15306
|
},
|
|
15163
15307
|
onProgress: options.onProgress,
|
|
15308
|
+
onReady: options.onReady,
|
|
15164
15309
|
});
|
|
15165
15310
|
this.renderer.start().catch((error) => {
|
|
15166
15311
|
options.onError?.(error);
|
|
@@ -15693,6 +15838,74 @@ function readIngotAccess(entry) {
|
|
|
15693
15838
|
};
|
|
15694
15839
|
}
|
|
15695
15840
|
|
|
15841
|
+
/**
|
|
15842
|
+
* SparkVault Debug Logger
|
|
15843
|
+
*
|
|
15844
|
+
* Conditional logging that respects debug mode setting.
|
|
15845
|
+
* When debug is enabled, logs detailed information to console.
|
|
15846
|
+
* When disabled (default), only fatal errors are logged.
|
|
15847
|
+
*/
|
|
15848
|
+
let debugEnabled = false;
|
|
15849
|
+
/**
|
|
15850
|
+
* Enable or disable debug logging
|
|
15851
|
+
*/
|
|
15852
|
+
function setDebugMode(enabled) {
|
|
15853
|
+
debugEnabled = enabled;
|
|
15854
|
+
if (enabled) {
|
|
15855
|
+
log('info', 'Debug mode enabled');
|
|
15856
|
+
}
|
|
15857
|
+
}
|
|
15858
|
+
/**
|
|
15859
|
+
* Internal log function
|
|
15860
|
+
*/
|
|
15861
|
+
function log(level, message, ...args) {
|
|
15862
|
+
const prefix = '[SparkVault]';
|
|
15863
|
+
const timestamp = new Date().toISOString().split('T')[1].slice(0, -1);
|
|
15864
|
+
const formattedMessage = `${prefix} ${timestamp} ${message}`;
|
|
15865
|
+
switch (level) {
|
|
15866
|
+
case 'debug':
|
|
15867
|
+
if (debugEnabled) {
|
|
15868
|
+
console.debug(formattedMessage, ...args);
|
|
15869
|
+
}
|
|
15870
|
+
break;
|
|
15871
|
+
case 'info':
|
|
15872
|
+
if (debugEnabled) {
|
|
15873
|
+
console.log(formattedMessage, ...args);
|
|
15874
|
+
}
|
|
15875
|
+
break;
|
|
15876
|
+
case 'warn':
|
|
15877
|
+
if (debugEnabled) {
|
|
15878
|
+
console.warn(formattedMessage, ...args);
|
|
15879
|
+
}
|
|
15880
|
+
break;
|
|
15881
|
+
case 'error':
|
|
15882
|
+
// Always log errors (fatal)
|
|
15883
|
+
console.error(formattedMessage, ...args);
|
|
15884
|
+
break;
|
|
15885
|
+
}
|
|
15886
|
+
}
|
|
15887
|
+
/**
|
|
15888
|
+
* Logger object for convenient access
|
|
15889
|
+
*/
|
|
15890
|
+
const logger = {
|
|
15891
|
+
/**
|
|
15892
|
+
* Debug level - verbose details for troubleshooting
|
|
15893
|
+
*/
|
|
15894
|
+
debug: (message, ...args) => log('debug', message, ...args),
|
|
15895
|
+
/**
|
|
15896
|
+
* Info level - general information
|
|
15897
|
+
*/
|
|
15898
|
+
info: (message, ...args) => log('info', message, ...args),
|
|
15899
|
+
/**
|
|
15900
|
+
* Warn level - warnings that don't prevent operation
|
|
15901
|
+
*/
|
|
15902
|
+
warn: (message, ...args) => log('warn', message, ...args),
|
|
15903
|
+
/**
|
|
15904
|
+
* Error level - always logged regardless of debug mode
|
|
15905
|
+
*/
|
|
15906
|
+
error: (message, ...args) => log('error', message, ...args),
|
|
15907
|
+
};
|
|
15908
|
+
|
|
15696
15909
|
/**
|
|
15697
15910
|
* The one browser transfer for a signed ingot download link: fetch it into a
|
|
15698
15911
|
* Blob under liveness bounds, resuming from the bytes it holds when the caller
|
|
@@ -16336,8 +16549,10 @@ function mapFolder(wire) {
|
|
|
16336
16549
|
* - `upsert` (the server default): the upload replaces the holder's content.
|
|
16337
16550
|
* - `complete_pending`: a holder whose own upload never finalized is completed
|
|
16338
16551
|
* (`created: false`); a published holder is refused with a 409 CONFLICT whose
|
|
16339
|
-
* `details`
|
|
16340
|
-
*
|
|
16552
|
+
* `details.reason` is `'NAME_HELD'`, and is left untouched. The details
|
|
16553
|
+
* describe the holder (`ingot_id`, `status`, `size_bytes`) unless another
|
|
16554
|
+
* app manages it or another request claimed the name first, when they carry
|
|
16555
|
+
* the reason alone.
|
|
16341
16556
|
* - `refuse`: any holder, its upload finished or not, is refused with that
|
|
16342
16557
|
* same 409 and left untouched; the create only ever mints.
|
|
16343
16558
|
* - `new_name`: the holder is never touched; the ingot is minted under the
|
|
@@ -16372,7 +16587,9 @@ class IngotsModule {
|
|
|
16372
16587
|
* transfer yourself; otherwise prefer {@link upload}. A create another
|
|
16373
16588
|
* upload of the same file superseded before its token was issued rejects
|
|
16374
16589
|
* with code `upload_refused` (`details.coreCode` UPLOAD_SUPERSEDED): the
|
|
16375
|
-
* later upload is the one kept, so a new upload is no remedy.
|
|
16590
|
+
* later upload is the one kept, so a new upload is no remedy. An upload
|
|
16591
|
+
* you give up (you cancel its transfer, or it fails for good) ends with the
|
|
16592
|
+
* file its create made through {@link endUpload}, given this result.
|
|
16376
16593
|
*
|
|
16377
16594
|
* @example
|
|
16378
16595
|
* const session = await sv.ingots.createUpload({
|
|
@@ -16401,15 +16618,65 @@ class IngotsModule {
|
|
|
16401
16618
|
onNameConflict: options.onNameConflict,
|
|
16402
16619
|
});
|
|
16403
16620
|
return {
|
|
16404
|
-
|
|
16621
|
+
...placementOf(created),
|
|
16405
16622
|
name: created.name,
|
|
16406
16623
|
contentType: created.content_type,
|
|
16407
16624
|
size: created.size_bytes,
|
|
16408
16625
|
uploadUrl: created.forge_url,
|
|
16409
16626
|
expiresAt: created.expires_at,
|
|
16410
|
-
created: created.created,
|
|
16411
16627
|
};
|
|
16412
16628
|
}
|
|
16629
|
+
/**
|
|
16630
|
+
* End an upload you give up (you cancelled its transfer, or it failed for
|
|
16631
|
+
* good) with the file its create made ({@link createUpload}'s result): the
|
|
16632
|
+
* server deletes the ingot only while it is still that upload's unfinished
|
|
16633
|
+
* file, ending the upload first, so a publication racing the end is decided
|
|
16634
|
+
* before anything goes. Never give up one the server received whole
|
|
16635
|
+
* ({@link isReceivedUploadFailure}): the server publishes or ends it on its
|
|
16636
|
+
* own. Resolves `deleted` once the vault holds the file no longer, deleted
|
|
16637
|
+
* now or already gone. Resolves `kept` when this end deleted nothing, which
|
|
16638
|
+
* {@link get} shows as it is now: the upload published the file, or a later
|
|
16639
|
+
* upload took it over, before the end reached the server, or, with no
|
|
16640
|
+
* request sent, the create did not make it (`created: false`) or names no
|
|
16641
|
+
* upload (`uploadId: null`), since a delete without its upload would take
|
|
16642
|
+
* whatever file stands. Any other failure rejects, the file left as it was.
|
|
16643
|
+
* {@link upload} ends an upload it cannot finish this way by itself.
|
|
16644
|
+
*
|
|
16645
|
+
* @example
|
|
16646
|
+
* const upload = await sv.ingots.createUpload({ vault: unsealed, name: file.name,
|
|
16647
|
+
* contentType: file.type, sizeBytes: file.size });
|
|
16648
|
+
* try {
|
|
16649
|
+
* await sv.ingots.sendUpload(upload.uploadUrl, file, { signal: controller.signal });
|
|
16650
|
+
* } catch (error) {
|
|
16651
|
+
* if (!isReceivedUploadFailure(error) &&
|
|
16652
|
+
* await sv.ingots.endUpload(unsealed, upload) === 'kept') {
|
|
16653
|
+
* // The end deleted nothing (the upload published the file, say): show it as it is.
|
|
16654
|
+
* showIngot(await sv.ingots.get(unsealed, upload.id));
|
|
16655
|
+
* }
|
|
16656
|
+
* throw error;
|
|
16657
|
+
* }
|
|
16658
|
+
*/
|
|
16659
|
+
async endUpload(vault, upload) {
|
|
16660
|
+
const vaultId = requireVaultId(vault);
|
|
16661
|
+
const id = requireResourceId(upload.id, 'ingotId');
|
|
16662
|
+
const uploadId = givenUpUploadId(upload);
|
|
16663
|
+
if (uploadId === null)
|
|
16664
|
+
return 'kept';
|
|
16665
|
+
try {
|
|
16666
|
+
await this.http.delete(apiPath `/v1/vaults/${vaultId}/ingots/${id}`, {
|
|
16667
|
+
vat: vault.vatToken,
|
|
16668
|
+
query: { upload_id: uploadId },
|
|
16669
|
+
});
|
|
16670
|
+
return 'deleted';
|
|
16671
|
+
}
|
|
16672
|
+
catch (error) {
|
|
16673
|
+
if (error instanceof SparkVaultError && error.statusCode === 404)
|
|
16674
|
+
return 'deleted';
|
|
16675
|
+
if (error instanceof SparkVaultError && error.statusCode === 412)
|
|
16676
|
+
return 'kept';
|
|
16677
|
+
throw error;
|
|
16678
|
+
}
|
|
16679
|
+
}
|
|
16413
16680
|
/**
|
|
16414
16681
|
* Send a file's bytes to an upload session — the `uploadUrl` a
|
|
16415
16682
|
* {@link createUpload} returned — over the resumable transfer every SDK
|
|
@@ -16517,7 +16784,11 @@ class IngotsModule {
|
|
|
16517
16784
|
* server refused — another upload of it superseded this one, at its create
|
|
16518
16785
|
* or while it streamed, the storage pool cannot take it, or its vault is
|
|
16519
16786
|
* scheduled for deletion (a 409 `VAULT_DELETION_SCHEDULED`) — rejects with
|
|
16520
|
-
* code `upload_refused`, as {@link sendUpload} does.
|
|
16787
|
+
* code `upload_refused`, as {@link sendUpload} does. An upload that rejects
|
|
16788
|
+
* any way but one the server received whole ({@link isReceivedUploadFailure}:
|
|
16789
|
+
* the server publishes or ends that one on its own) is given up: the end of
|
|
16790
|
+
* it with the file its create made ({@link endUpload}) starts as it
|
|
16791
|
+
* rejects, without holding up its own error.
|
|
16521
16792
|
*
|
|
16522
16793
|
* @example
|
|
16523
16794
|
* const ingot = await sv.ingots.upload(unsealed, {
|
|
@@ -16539,7 +16810,29 @@ class IngotsModule {
|
|
|
16539
16810
|
folderId: options.folderId,
|
|
16540
16811
|
onNameConflict: options.onNameConflict,
|
|
16541
16812
|
});
|
|
16542
|
-
|
|
16813
|
+
try {
|
|
16814
|
+
return await this.transferAndFinalize(created, created.created, options.file, options.onProgress);
|
|
16815
|
+
}
|
|
16816
|
+
catch (error) {
|
|
16817
|
+
// The caller holds no session to continue this upload in, so a transfer
|
|
16818
|
+
// that ends any way but received whole is given up, its file with it.
|
|
16819
|
+
if (!isReceivedUploadFailure(error))
|
|
16820
|
+
this.endGivenUp(vault, placementOf(created));
|
|
16821
|
+
throw error;
|
|
16822
|
+
}
|
|
16823
|
+
}
|
|
16824
|
+
/**
|
|
16825
|
+
* End an upload this flow gave up ({@link endUpload}) without holding up
|
|
16826
|
+
* the error its caller is answered with: an end that fails leaves the file
|
|
16827
|
+
* to the server's expiry of abandoned uploads, and is logged.
|
|
16828
|
+
*/
|
|
16829
|
+
endGivenUp(vault, upload) {
|
|
16830
|
+
this.endUpload(vault, upload).catch((error) => {
|
|
16831
|
+
logger.warn('A given-up upload could not be ended with its file; the server expires it', {
|
|
16832
|
+
ingotId: upload.id,
|
|
16833
|
+
code: error instanceof SparkVaultError ? error.code : undefined,
|
|
16834
|
+
});
|
|
16835
|
+
});
|
|
16543
16836
|
}
|
|
16544
16837
|
/**
|
|
16545
16838
|
* Replace an existing ingot's content (high-level flow). Rejects as
|
|
@@ -16777,8 +17070,11 @@ class IngotsModule {
|
|
|
16777
17070
|
return mapSharingConfig(response.data);
|
|
16778
17071
|
}
|
|
16779
17072
|
/**
|
|
16780
|
-
* Invite an identity to
|
|
16781
|
-
*
|
|
17073
|
+
* Invite an identity to an ingot's invite-only share, or share an ingot not
|
|
17074
|
+
* yet shared invite-only with it. A public or authenticated share refuses
|
|
17075
|
+
* it (a ValidationError) and changes nothing: set its visibility to
|
|
17076
|
+
* `invite_only` first. The identity type (email or phone) is inferred
|
|
17077
|
+
* server-side from the identity value.
|
|
16782
17078
|
*
|
|
16783
17079
|
* @example
|
|
16784
17080
|
* await sv.ingots.addInvite(unsealed, 'ing_abc', 'user@example.com');
|
|
@@ -16790,7 +17086,7 @@ class IngotsModule {
|
|
|
16790
17086
|
const vaultId = requireVaultId(vault);
|
|
16791
17087
|
const id = requireResourceId(ingotId, 'ingotId');
|
|
16792
17088
|
const response = await this.http.post(apiPath `/v1/vaults/${vaultId}/ingots/${id}/sharing/invite`, { identity }, { vat: vault.vatToken });
|
|
16793
|
-
return
|
|
17089
|
+
return mapInvitation(response.data);
|
|
16794
17090
|
}
|
|
16795
17091
|
/**
|
|
16796
17092
|
* Revoke an ingot sharing invite.
|
|
@@ -16876,6 +17172,8 @@ class IngotsModule {
|
|
|
16876
17172
|
throw stagingRefusalOf(error);
|
|
16877
17173
|
});
|
|
16878
17174
|
if (!response.data.forge_url) {
|
|
17175
|
+
// No upload can start without its URL: the file the create made goes too.
|
|
17176
|
+
this.endGivenUp(vault, placementOf(response.data));
|
|
16879
17177
|
throw new ValidationError('Upload endpoint did not return a Forge upload URL');
|
|
16880
17178
|
}
|
|
16881
17179
|
return response.data;
|
|
@@ -16906,6 +17204,14 @@ class IngotsModule {
|
|
|
16906
17204
|
}
|
|
16907
17205
|
}
|
|
16908
17206
|
}
|
|
17207
|
+
/**
|
|
17208
|
+
* What a create answered about the file it placed: its id, whether the create
|
|
17209
|
+
* made it, and the upload it staged there, which {@link IngotsModule.endUpload}
|
|
17210
|
+
* ends it by.
|
|
17211
|
+
*/
|
|
17212
|
+
function placementOf(created) {
|
|
17213
|
+
return { id: created.ingot_id, created: created.created, uploadId: created.upload_id ?? null };
|
|
17214
|
+
}
|
|
16909
17215
|
function getBlobName(file) {
|
|
16910
17216
|
if (typeof File !== 'undefined' && file instanceof File && file.name) {
|
|
16911
17217
|
return file.name;
|
|
@@ -16955,7 +17261,12 @@ function mapIngotPage(response) {
|
|
|
16955
17261
|
function mapSharingConfig(wire) {
|
|
16956
17262
|
return {
|
|
16957
17263
|
shared: wire.shared,
|
|
16958
|
-
visibility: wire.visibility,
|
|
17264
|
+
visibility: wire.visibility ?? undefined,
|
|
17265
|
+
publicUrl: wire.public_url,
|
|
17266
|
+
linkCode: wire.link_code,
|
|
17267
|
+
sharingEnabled: wire.sharing_enabled,
|
|
17268
|
+
vaultAllIngotsPublic: wire.vault_all_ingots_public,
|
|
17269
|
+
sessionLengthSeconds: wire.session_length_seconds,
|
|
16959
17270
|
invites: wire.invites?.map(mapInvite),
|
|
16960
17271
|
};
|
|
16961
17272
|
}
|
|
@@ -16964,6 +17275,14 @@ function mapInvite(wire) {
|
|
|
16964
17275
|
id: wire.invite_id,
|
|
16965
17276
|
identity: wire.identity,
|
|
16966
17277
|
identityType: wire.identity_type,
|
|
17278
|
+
invitedAt: wire.created_at,
|
|
17279
|
+
};
|
|
17280
|
+
}
|
|
17281
|
+
function mapInvitation(wire) {
|
|
17282
|
+
return {
|
|
17283
|
+
...mapInvite(wire),
|
|
17284
|
+
shareUrl: wire.share_url,
|
|
17285
|
+
delivered: wire.delivered,
|
|
16967
17286
|
};
|
|
16968
17287
|
}
|
|
16969
17288
|
|
|
@@ -17485,74 +17804,6 @@ class NotifyModule {
|
|
|
17485
17804
|
}
|
|
17486
17805
|
}
|
|
17487
17806
|
|
|
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
17807
|
/**
|
|
17557
17808
|
* SparkVault Auto-Initialization
|
|
17558
17809
|
*
|
|
@@ -17687,7 +17938,7 @@ class SparkVault {
|
|
|
17687
17938
|
}
|
|
17688
17939
|
/** Get the SDK version */
|
|
17689
17940
|
static get version() {
|
|
17690
|
-
return '12.0.
|
|
17941
|
+
return '12.0.5';
|
|
17691
17942
|
}
|
|
17692
17943
|
}
|
|
17693
17944
|
if (typeof window !== 'undefined') {
|
|
@@ -17724,6 +17975,7 @@ exports.VaultsModule = VaultsModule;
|
|
|
17724
17975
|
exports.buildNotifyPresetSend = buildNotifyPresetSend;
|
|
17725
17976
|
exports.default = SparkVault;
|
|
17726
17977
|
exports.fetchDownload = fetchDownload;
|
|
17978
|
+
exports.isReceivedUploadFailure = isReceivedUploadFailure;
|
|
17727
17979
|
exports.logger = logger;
|
|
17728
17980
|
exports.setDebugMode = setDebugMode;
|
|
17729
17981
|
//# sourceMappingURL=index.cjs.map
|