@sparkvault/sdk-js 11.2.3 → 11.2.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 +205 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +55 -10
- package/dist/index.mjs +205 -76
- package/dist/index.mjs.map +1 -1
- package/dist/ingots/index.d.ts +23 -10
- package/dist/ingots/types.d.ts +17 -0
- package/dist/sparks/types.d.ts +17 -0
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/vaults/upload/api.d.ts +7 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2278,6 +2278,22 @@ interface Ingot {
|
|
|
2278
2278
|
id: string;
|
|
2279
2279
|
/** Ingot name */
|
|
2280
2280
|
name: string;
|
|
2281
|
+
/**
|
|
2282
|
+
* The name a download of the ingot saves under, as Forge names it: `name`,
|
|
2283
|
+
* kept as it is when the first word of the extension it shows (up to an
|
|
2284
|
+
* ASCII space, in any case) is one the MIME registry knows or holds a
|
|
2285
|
+
* character none of the registry's extensions is spelled with, which may
|
|
2286
|
+
* draw as one, and otherwise completed with the first extension the
|
|
2287
|
+
* registry lists for `contentType`, never one a saved copy must never open
|
|
2288
|
+
* as. Save a copy under it, handed to a browser as
|
|
2289
|
+
* `application/octet-stream` unless `contentType` is a raster image, audio,
|
|
2290
|
+
* video or PDF format (never SVG, a playlist or a stream redirector): a
|
|
2291
|
+
* browser renames a saved copy by the type it is handed (Chrome saves
|
|
2292
|
+
* `Invoice` typed `application/x-msdownload` as `Invoice.exe`), and
|
|
2293
|
+
* completes or replaces no extension of a copy handed as
|
|
2294
|
+
* `application/octet-stream`.
|
|
2295
|
+
*/
|
|
2296
|
+
downloadFilename: string;
|
|
2281
2297
|
/** Content type (MIME) */
|
|
2282
2298
|
contentType: string;
|
|
2283
2299
|
/** Size in bytes */
|
|
@@ -2683,10 +2699,13 @@ declare class IngotsModule {
|
|
|
2683
2699
|
* no longer holds (it expired, was cancelled, or its ingot was removed)
|
|
2684
2700
|
* rejects with code `session_gone`, and only a new upload session — a new
|
|
2685
2701
|
* {@link createUpload}, or {@link upload} again — can store the file. An
|
|
2686
|
-
* upload the server refused
|
|
2687
|
-
*
|
|
2688
|
-
* `
|
|
2689
|
-
*
|
|
2702
|
+
* upload the server refused (the account's storage pool cannot take it, a
|
|
2703
|
+
* later upload replaced it, or its vault is scheduled for deletion: a 409
|
|
2704
|
+
* `VAULT_DELETION_SCHEDULED`, whose session the server keeps until the
|
|
2705
|
+
* deletion runs or is cancelled, or the session lapses on its own) rejects
|
|
2706
|
+
* at once with code `upload_refused`, its message the server's own sentence
|
|
2707
|
+
* and its code in `details.coreCode`: a new upload is no remedy. A
|
|
2708
|
+
* publication the server
|
|
2690
2709
|
* still defers at the transfer's idle limit rejects with code
|
|
2691
2710
|
* `upload_received_publishing`: every byte is received, and the server
|
|
2692
2711
|
* finishes the publication on its own, so never upload the file again; a
|
|
@@ -2716,8 +2735,11 @@ declare class IngotsModule {
|
|
|
2716
2735
|
*
|
|
2717
2736
|
* It rejects as {@link sendUpload} does: `session_gone` once the server no
|
|
2718
2737
|
* longer holds the session (it expired, was cancelled, or ended when the
|
|
2719
|
-
* server refused to publish it), `upload_refused` for an upload
|
|
2720
|
-
*
|
|
2738
|
+
* server refused to publish it), `upload_refused` for an upload the server
|
|
2739
|
+
* refused (its storage pool, a later upload, or its vault scheduled for
|
|
2740
|
+
* deletion, a 409 `VAULT_DELETION_SCHEDULED` that keeps the session, so a
|
|
2741
|
+
* resume once the deletion is cancelled goes on while the session stands),
|
|
2742
|
+
* `upload_received_publishing` again for a publication the server
|
|
2721
2743
|
* still defers at the transfer's idle limit, which leaves the session to
|
|
2722
2744
|
* resume again later. A session URL that is not an upload session on an
|
|
2723
2745
|
* allowed transfer host is refused (`invalid_forge_url`), and one whose
|
|
@@ -2749,9 +2771,10 @@ declare class IngotsModule {
|
|
|
2749
2771
|
*
|
|
2750
2772
|
* Creates the upload session, streams the file to Forge over TUS, then
|
|
2751
2773
|
* confirms the server finalized the upload before resolving. A file the
|
|
2752
|
-
* server refused
|
|
2753
|
-
*
|
|
2754
|
-
*
|
|
2774
|
+
* server refused — another upload of it superseded this one, at its create
|
|
2775
|
+
* or while it streamed, the storage pool cannot take it, or its vault is
|
|
2776
|
+
* scheduled for deletion (a 409 `VAULT_DELETION_SCHEDULED`) — rejects with
|
|
2777
|
+
* code `upload_refused`, as {@link sendUpload} does.
|
|
2755
2778
|
*
|
|
2756
2779
|
* @example
|
|
2757
2780
|
* const ingot = await sv.ingots.upload(unsealed, {
|
|
@@ -2851,8 +2874,14 @@ declare class IngotsModule {
|
|
|
2851
2874
|
* and a link that is not a Forge decrypt URL on an allowed host, is final.
|
|
2852
2875
|
*
|
|
2853
2876
|
* @example
|
|
2877
|
+
* const ingot = await sv.ingots.get(unsealed, 'ing_abc');
|
|
2854
2878
|
* const blob = await sv.ingots.download(unsealed, 'ing_abc');
|
|
2855
|
-
*
|
|
2879
|
+
* // Saved under the name Forge would send, as opaque bytes, which no
|
|
2880
|
+
* // browser renames by a type (see Ingot.downloadFilename).
|
|
2881
|
+
* const link = document.createElement('a');
|
|
2882
|
+
* link.href = URL.createObjectURL(new Blob([blob], { type: 'application/octet-stream' }));
|
|
2883
|
+
* link.download = ingot.downloadFilename;
|
|
2884
|
+
* link.click();
|
|
2856
2885
|
*/
|
|
2857
2886
|
download(vault: UnsealedVault, ingotId: string): Promise<Blob>;
|
|
2858
2887
|
/**
|
|
@@ -3042,6 +3071,22 @@ interface Spark {
|
|
|
3042
3071
|
burnedAt: number;
|
|
3043
3072
|
/** Optional file name (for file payloads) */
|
|
3044
3073
|
filename?: string;
|
|
3074
|
+
/**
|
|
3075
|
+
* The name the payload saves under: `filename`, or `download` for a spark
|
|
3076
|
+
* with none, kept as it is when the first word of the extension it shows
|
|
3077
|
+
* (up to an ASCII space, in any case) is one the MIME registry knows or
|
|
3078
|
+
* holds a character none of the registry's extensions is spelled with,
|
|
3079
|
+
* which may draw as one, and otherwise completed with the first extension
|
|
3080
|
+
* the registry lists for `contentType`, never one a saved copy must never
|
|
3081
|
+
* open as. Save a copy under it, handed to a browser as
|
|
3082
|
+
* `application/octet-stream` unless `contentType` is a raster image, audio,
|
|
3083
|
+
* video or PDF format (never SVG, a playlist or a stream redirector): a
|
|
3084
|
+
* browser renames a saved copy by the type it is handed (Chrome saves
|
|
3085
|
+
* `Invoice` typed `application/x-msdownload` as `Invoice.exe`), and
|
|
3086
|
+
* completes or replaces no extension of a copy handed as
|
|
3087
|
+
* `application/octet-stream`.
|
|
3088
|
+
*/
|
|
3089
|
+
downloadFilename: string;
|
|
3045
3090
|
}
|
|
3046
3091
|
/** A newly created spark. */
|
|
3047
3092
|
interface CreatedSpark {
|
package/dist/index.mjs
CHANGED
|
@@ -29,7 +29,9 @@ function isTransientHttpStatus(status) {
|
|
|
29
29
|
* The upload publication contract between Forge and Core's activation, and
|
|
30
30
|
* the facts of a transfer token both services spell: its shape, the
|
|
31
31
|
* publication it is bound to (a content version, and the one an ingot row
|
|
32
|
-
* names),
|
|
32
|
+
* names), Core's revocation of an upload's token, and the refusals of Core's
|
|
33
|
+
* a transfer's answer names (the header, and the lock of a vault scheduled
|
|
34
|
+
* for deletion).
|
|
33
35
|
*
|
|
34
36
|
* Forge stamps UPLOAD_PUBLICATION_PROTOCOL on every upload session it creates
|
|
35
37
|
* and on the final state it hands Core's activation (POST
|
|
@@ -110,10 +112,37 @@ const UPLOAD_TOKEN_REVOCATION = Object.freeze({
|
|
|
110
112
|
Object.values(UPLOAD_TOKEN_REVOCATION.reasons);
|
|
111
113
|
|
|
112
114
|
/**
|
|
113
|
-
* The
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
115
|
+
* The code Core refuses every use of a vault's content with (409) while the
|
|
116
|
+
* vault is scheduled for deletion, until a company admin cancels the
|
|
117
|
+
* deletion or it runs and the vault is gone: a transfer token's use, each
|
|
118
|
+
* request of a transfer (Forge asks Core before every one and relays the
|
|
119
|
+
* refusal naming this code), and an upload's activation, which Forge defers.
|
|
120
|
+
* The lock refuses an upload's requests and never ends its session, so a
|
|
121
|
+
* client keeps the session and reports the lock. The session still lapses
|
|
122
|
+
* on its own idle window (upload-expiry.js), which is shorter than the
|
|
123
|
+
* deletion's delay: an upload resumed after a cancelled deletion goes on from
|
|
124
|
+
* its offset while the session stands, and starts over once it has lapsed.
|
|
125
|
+
*/
|
|
126
|
+
const VAULT_DELETION_SCHEDULED = 'VAULT_DELETION_SCHEDULED';
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The words a vault scheduled for deletion refuses every use of its content
|
|
130
|
+
* in (VAULT_DELETION_SCHEDULED), whichever service or client meets it:
|
|
131
|
+
* Core's refusal, and a client's report of it from an answer with no body
|
|
132
|
+
* to carry Core's (a HEAD's, naming the code in UPLOAD_REFUSAL_HEADER alone).
|
|
133
|
+
*/
|
|
134
|
+
const VAULT_DELETION_SCHEDULED_MESSAGE =
|
|
135
|
+
'This vault is scheduled for deletion. Cancel its deletion in vault settings before accessing its contents.';
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The response header that names the code of a refusal Core decided: Forge
|
|
139
|
+
* sends it on every terminal answer to a tus request (a 404, 410 or 412) and
|
|
140
|
+
* on every answer relaying Core's decision about a transfer's vault (the 409
|
|
141
|
+
* VAULT_DELETION_SCHEDULED, a 404 naming the vault), a download's and a
|
|
142
|
+
* HEAD's (which has no body) included, so a
|
|
143
|
+
* client tells an upload the owner's pool cannot take from one a later
|
|
144
|
+
* upload superseded, and Core's lock from another request holding the
|
|
145
|
+
* session's lease, without reading a body.
|
|
117
146
|
*/
|
|
118
147
|
const UPLOAD_REFUSAL_HEADER = 'X-Upload-Refusal';
|
|
119
148
|
|
|
@@ -138,20 +167,29 @@ const UPLOAD_REFUSAL_HEADER = 'X-Upload-Refusal';
|
|
|
138
167
|
* both bounds start over whenever the server confirms progress.
|
|
139
168
|
*
|
|
140
169
|
* Forge's own answers beyond the general rule:
|
|
141
|
-
* -
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* of the
|
|
152
|
-
* for
|
|
153
|
-
*
|
|
154
|
-
*
|
|
170
|
+
* - an answer naming a refusal Core decided names Core's code: a terminal
|
|
171
|
+
* answer (a 404, 410 or 412) the code Core ended the upload with, and a 409
|
|
172
|
+
* relaying Core's refusal of the transfer the code Core refused it with.
|
|
173
|
+
* Its error envelope names it in `error.details.coreCode` (for the refusals
|
|
174
|
+
* Forge words itself and the ones it relays from Core's check of a
|
|
175
|
+
* transfer), and every one of them in `X-Upload-Refusal`, which is all a
|
|
176
|
+
* HEAD's answer, having no body, can carry; the body's code wins when both
|
|
177
|
+
* name one;
|
|
178
|
+
* - the 409, in three kinds: one carrying `Upload-Offset` names where the
|
|
179
|
+
* session stands (continue from there); one naming Core's code is Core's
|
|
180
|
+
* refusal of the transfer in its vault's current state, a vault scheduled
|
|
181
|
+
* for deletion (VAULT_DELETION_SCHEDULED), which keeps the session (until
|
|
182
|
+
* it lapses on its 72 h idle window, upload-expiry.js) and which neither
|
|
183
|
+
* the same request nor a new upload gets past until a person cancels the
|
|
184
|
+
* deletion, so it is reported, never retried; and one naming
|
|
185
|
+
* neither means another request holds the session's write lease, a chunk
|
|
186
|
+
* or the finalization (retry after its `Retry-After`);
|
|
187
|
+
* - a terminal answer's code decides its verdict: a full storage pool or a
|
|
188
|
+
* later upload that replaced this one is a refusal no new upload of the
|
|
189
|
+
* same file remedies, and any other code (the file the upload was for
|
|
190
|
+
* gone, a retired contract, a replacement base that moved on, a code this
|
|
191
|
+
* policy does not know) ends the session, which a new upload can start
|
|
192
|
+
* over;
|
|
155
193
|
* - a 503 carrying `Retry-After` to the receipt (the PATCH at the final
|
|
156
194
|
* offset) is a deferral: Forge holds every byte and is still publishing,
|
|
157
195
|
* and finishes without the client, so it is asked again, each time after a
|
|
@@ -178,10 +216,10 @@ const TRANSFER_VERDICT = Object.freeze({
|
|
|
178
216
|
/** 2xx: the request did what it asked. */
|
|
179
217
|
OK: 'ok',
|
|
180
218
|
/**
|
|
181
|
-
* No answer (a reset, a timeout), 408, 425, 429, a 5xx, or a 409
|
|
182
|
-
* `Upload-Offset`
|
|
183
|
-
* never sooner than `Retry-After`, then ask
|
|
184
|
-
* sending a chunk again.
|
|
219
|
+
* No answer (a reset, a timeout), 408, 425, 429, a 5xx, or a 409 naming
|
|
220
|
+
* neither an `Upload-Offset` nor a code of Core's (another request holds
|
|
221
|
+
* the session's lease): back off, never sooner than `Retry-After`, then ask
|
|
222
|
+
* the server's offset before sending a chunk again.
|
|
185
223
|
*/
|
|
186
224
|
RETRY: 'retry',
|
|
187
225
|
/** 409 with `Upload-Offset`: the session stands elsewhere; continue from that offset at once. */
|
|
@@ -200,10 +238,11 @@ const TRANSFER_VERDICT = Object.freeze({
|
|
|
200
238
|
*/
|
|
201
239
|
GONE: 'gone',
|
|
202
240
|
/**
|
|
203
|
-
* Any other status,
|
|
204
|
-
* (`coreCode`: UPLOAD_POOL_FULL, UPLOAD_SUPERSEDED)
|
|
205
|
-
*
|
|
206
|
-
*
|
|
241
|
+
* Any other status, a 404, 410 or 412 naming a final refusal of Core's
|
|
242
|
+
* (`coreCode`: UPLOAD_POOL_FULL, UPLOAD_SUPERSEDED), or a 409 naming any
|
|
243
|
+
* code of Core's (`coreCode`: VAULT_DELETION_SCHEDULED, whose session
|
|
244
|
+
* stands): the server's verdict on this request, which repeating it, or a
|
|
245
|
+
* new upload of the same file, earns again.
|
|
207
246
|
*/
|
|
208
247
|
REFUSED: 'refused'
|
|
209
248
|
});
|
|
@@ -223,6 +262,12 @@ const SERVICE_UNAVAILABLE = 503;
|
|
|
223
262
|
*/
|
|
224
263
|
const TERMINAL_STATUSES = new Set([404, 410, 412]);
|
|
225
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Forge's 409: about where the session stands (`Upload-Offset`), another
|
|
267
|
+
* request's lease on it, or Core's refusal of the transfer, relayed.
|
|
268
|
+
*/
|
|
269
|
+
const CONFLICT = 409;
|
|
270
|
+
|
|
226
271
|
/** Core's error codes are upper-case words joined by underscores; anything else names no code. */
|
|
227
272
|
const CORE_CODE = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
228
273
|
|
|
@@ -263,12 +308,14 @@ const DEFAULT_MAX_CONSECUTIVE_FAILURES = 8;
|
|
|
263
308
|
* @property {number|null} retryAfterMs - The answer's `Retry-After`, in ms from
|
|
264
309
|
* the answer (an HTTP-date already past reads as 0); null when absent or unreadable
|
|
265
310
|
* @property {number|null} offset - The answer's `Upload-Offset`; null when absent or unreadable
|
|
266
|
-
* @property {string|null} coreCode - The code
|
|
267
|
-
*
|
|
268
|
-
* naming none, its `X-Upload-Refusal`): REFUSED for
|
|
269
|
-
* (`
|
|
270
|
-
* (`
|
|
271
|
-
*
|
|
311
|
+
* @property {string|null} coreCode - The code of the refusal Core decided, as
|
|
312
|
+
* the answer named it (a 404, 410 or 412, or a 409 naming no offset: its
|
|
313
|
+
* body's details or, those naming none, its `X-Upload-Refusal`): REFUSED for
|
|
314
|
+
* any code a 409 names (`VAULT_DELETION_SCHEDULED`) and for a terminal
|
|
315
|
+
* answer's final refusal (`UPLOAD_POOL_FULL`, `UPLOAD_SUPERSEDED`), GONE for
|
|
316
|
+
* any other code a terminal answer names (`NOT_FOUND`,
|
|
317
|
+
* `UPLOAD_PROTOCOL_RETIRED`, a 412's, one this policy does not know); null
|
|
318
|
+
* when the answer names none
|
|
272
319
|
*/
|
|
273
320
|
|
|
274
321
|
/**
|
|
@@ -307,7 +354,7 @@ function classifyTransferResponse({ status, headers = null, details = null, rece
|
|
|
307
354
|
}
|
|
308
355
|
const header = (name) => (headers === null ? null : headers(name));
|
|
309
356
|
const offset = readCount(header(UPLOAD_OFFSET_HEADER));
|
|
310
|
-
const coreCode =
|
|
357
|
+
const coreCode = mayNameCoreCode(status, offset)
|
|
311
358
|
? coreCodeIn(details) ?? coreCodeOf(header(UPLOAD_REFUSAL_HEADER))
|
|
312
359
|
: null;
|
|
313
360
|
const retryAfterMs = readRetryAfterMs(header(RETRY_AFTER_HEADER), now);
|
|
@@ -319,14 +366,28 @@ function classifyTransferResponse({ status, headers = null, details = null, rece
|
|
|
319
366
|
};
|
|
320
367
|
}
|
|
321
368
|
|
|
369
|
+
/**
|
|
370
|
+
* Whether an answer may name the code of a refusal Core decided: a terminal
|
|
371
|
+
* answer does, and so does a 409 naming no offset. A 409 carrying
|
|
372
|
+
* `Upload-Offset` is Forge's own, about where the session stands.
|
|
373
|
+
*/
|
|
374
|
+
function mayNameCoreCode(status, offset) {
|
|
375
|
+
return TERMINAL_STATUSES.has(status) || (status === CONFLICT && offset === null);
|
|
376
|
+
}
|
|
377
|
+
|
|
322
378
|
/**
|
|
323
379
|
* The verdict on a status that came with an answer: `offset` its readable
|
|
324
|
-
* `Upload-Offset`, `coreCode` the code of Core's
|
|
380
|
+
* `Upload-Offset`, `coreCode` the code of Core's the answer names,
|
|
325
381
|
* `deferral` whether it answered the receipt with a readable `Retry-After`.
|
|
326
382
|
*/
|
|
327
383
|
function verdictFor(status, { offset, coreCode, deferral }) {
|
|
328
384
|
if (status >= 200 && status < 300) return TRANSFER_VERDICT.OK;
|
|
329
|
-
if (status ===
|
|
385
|
+
if (status === CONFLICT) {
|
|
386
|
+
if (offset !== null) return TRANSFER_VERDICT.RESYNC;
|
|
387
|
+
// Core's 409 refuses the transfer in its vault's current state: the
|
|
388
|
+
// session stands, and the same request or a new upload earns it again.
|
|
389
|
+
return coreCode === null ? TRANSFER_VERDICT.RETRY : TRANSFER_VERDICT.REFUSED;
|
|
390
|
+
}
|
|
330
391
|
if (coreCode !== null) return UPLOAD_FINAL_REFUSAL_CODES.includes(coreCode) ? TRANSFER_VERDICT.REFUSED : TRANSFER_VERDICT.GONE;
|
|
331
392
|
if (status === 404 || status === 410) return TRANSFER_VERDICT.GONE;
|
|
332
393
|
if (deferral && status === SERVICE_UNAVAILABLE) return TRANSFER_VERDICT.DEFERRED;
|
|
@@ -11751,22 +11812,25 @@ const SESSION_GONE_MESSAGE = 'Upload could not be finished: the server has ended
|
|
|
11751
11812
|
*/
|
|
11752
11813
|
const RECEIVED_PUBLISHING_MESSAGE = 'The server received every byte of this file and is still saving it. It finishes on its own.';
|
|
11753
11814
|
/**
|
|
11754
|
-
* The copy a person reads for a
|
|
11755
|
-
*
|
|
11756
|
-
* `X-Upload-Refusal` alone): this SDK's own words for each
|
|
11815
|
+
* The copy a person reads for a refusal whose answer carried no sentence of
|
|
11816
|
+
* Core's (a HEAD's, which has no body, naming Core's code in
|
|
11817
|
+
* `X-Upload-Refusal` alone): this SDK's own words for each final refusal,
|
|
11818
|
+
* and Core's own for its lock of a vault scheduled for deletion, none of them
|
|
11757
11819
|
* asking for the file again.
|
|
11758
11820
|
*/
|
|
11759
11821
|
const REFUSAL_WORDING = new Map([
|
|
11760
11822
|
[UPLOAD_REFUSAL_CODES.UPLOAD_POOL_FULL, 'This upload could not be saved: the owner\'s storage cannot take the file.'],
|
|
11761
11823
|
[UPLOAD_REFUSAL_CODES.UPLOAD_SUPERSEDED, 'This upload was not saved: a newer upload of this file replaced it.'],
|
|
11824
|
+
[VAULT_DELETION_SCHEDULED, VAULT_DELETION_SCHEDULED_MESSAGE],
|
|
11762
11825
|
]);
|
|
11763
11826
|
/** The copy for a final refusal of a code this SDK has no words of its own for. */
|
|
11764
11827
|
const REFUSED_MESSAGE = 'This upload could not be saved: the server refused it.';
|
|
11765
11828
|
/**
|
|
11766
|
-
* The error of an upload Core refused
|
|
11767
|
-
*
|
|
11768
|
-
*
|
|
11769
|
-
*
|
|
11829
|
+
* The error of an upload Core refused (UPLOAD_FINAL_REFUSAL_CODES, or the 409
|
|
11830
|
+
* of a vault scheduled for deletion, VAULT_DELETION_SCHEDULED, whose session
|
|
11831
|
+
* stands): `upload_refused` in Core's own sentence, this SDK's for an answer
|
|
11832
|
+
* that carried none (a HEAD's), Core's code in `details.coreCode`; never
|
|
11833
|
+
* retried, and no new upload of the same file remedies it. The one reading of that
|
|
11770
11834
|
* verdict, whichever answer carries it: a transfer answer naming Core's code
|
|
11771
11835
|
* ({@link readTransferAnswer}), or Core's own refusal of the request that
|
|
11772
11836
|
* stages the upload ({@link stagingRefusal}).
|
|
@@ -12143,9 +12207,10 @@ class UploadApi extends SparkVaultApi {
|
|
|
12143
12207
|
* otherwise a HEAD after the backoff ({@link offsetAfterFailure}); a session
|
|
12144
12208
|
* the server no longer holds throws `session_gone`, which only a new upload
|
|
12145
12209
|
* recovers from (any code of Core's the server named rides
|
|
12146
|
-
* `details.coreCode`); an upload Core refused
|
|
12147
|
-
*
|
|
12148
|
-
*
|
|
12210
|
+
* `details.coreCode`); an upload Core refused (a full storage pool, a later
|
|
12211
|
+
* upload that replaced it, its vault scheduled for deletion, whose 409 names
|
|
12212
|
+
* Core's code) throws `upload_refused` in Core's words at once, which no new
|
|
12213
|
+
* upload recovers from. While the browser is offline, the loop
|
|
12149
12214
|
* waits for the network instead of spending attempts.
|
|
12150
12215
|
*
|
|
12151
12216
|
* Resolves only once the server has confirmed finalization
|
|
@@ -12355,8 +12420,9 @@ class UploadApi extends SparkVaultApi {
|
|
|
12355
12420
|
* the publication on its own. A 503 naming no `Retry-After` is no deferral
|
|
12356
12421
|
* of Forge's, so it is polled as a failure. A 400 is the server's verdict
|
|
12357
12422
|
* and fails immediately, as does the refusal Core decided
|
|
12358
|
-
* (`upload_refused
|
|
12359
|
-
* missing, and the upload continues from
|
|
12423
|
+
* (`upload_refused`, a 409 naming Core's code among them); a 409 naming an
|
|
12424
|
+
* earlier offset means bytes are missing, and the upload continues from
|
|
12425
|
+
* there.
|
|
12360
12426
|
*/
|
|
12361
12427
|
async confirmServerFinalized(transfer) {
|
|
12362
12428
|
let consecutiveTimeouts = 0;
|
|
@@ -14101,6 +14167,12 @@ function formatBytes(bytes, decimals = 1) {
|
|
|
14101
14167
|
* Orchestrates view state and rendering for vault upload flows.
|
|
14102
14168
|
* Manages the complete upload lifecycle: form, uploading, ceremony, completion.
|
|
14103
14169
|
*/
|
|
14170
|
+
/**
|
|
14171
|
+
* What an outside uploader reads when the vault is scheduled for deletion:
|
|
14172
|
+
* the vault takes no files now. Core's own sentence, which tells the vault's
|
|
14173
|
+
* admin how to cancel the deletion, is the console's, never this page's.
|
|
14174
|
+
*/
|
|
14175
|
+
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.';
|
|
14104
14176
|
/**
|
|
14105
14177
|
* Ceremony steps for the cryptographic visualization.
|
|
14106
14178
|
*/
|
|
@@ -14886,10 +14958,23 @@ class UploadRenderer {
|
|
|
14886
14958
|
statusCode: error.statusCode,
|
|
14887
14959
|
});
|
|
14888
14960
|
}
|
|
14961
|
+
else if (error.code === VAULT_DELETION_SCHEDULED || error.details?.coreCode === VAULT_DELETION_SCHEDULED) {
|
|
14962
|
+
// The vault is scheduled for deletion, refused at the upload's start
|
|
14963
|
+
// or while its bytes moved. Core's sentence tells the vault's admin
|
|
14964
|
+
// how to cancel the deletion; the person on this page is an outside
|
|
14965
|
+
// uploader, told only that the vault takes no files now.
|
|
14966
|
+
this.setState({
|
|
14967
|
+
view: 'error',
|
|
14968
|
+
title: 'Uploads Paused',
|
|
14969
|
+
message: VAULT_NOT_ACCEPTING_MESSAGE,
|
|
14970
|
+
code: error.code,
|
|
14971
|
+
statusCode: error.statusCode,
|
|
14972
|
+
});
|
|
14973
|
+
}
|
|
14889
14974
|
else if (error.code === 'upload_refused') {
|
|
14890
|
-
// Core refused the upload
|
|
14891
|
-
//
|
|
14892
|
-
//
|
|
14975
|
+
// Core refused the upload, in its own words (whom to contact about a
|
|
14976
|
+
// full storage pool, or the later upload that replaced this one): a
|
|
14977
|
+
// sentence that never asks for the file again.
|
|
14893
14978
|
this.setState({
|
|
14894
14979
|
view: 'error',
|
|
14895
14980
|
title: 'Upload Not Saved',
|
|
@@ -15700,21 +15785,35 @@ async function attemptWith(source, state, options) {
|
|
|
15700
15785
|
assertDownloadUrl(link, options.isAllowedHost);
|
|
15701
15786
|
}
|
|
15702
15787
|
catch (error) {
|
|
15703
|
-
|
|
15788
|
+
if (!(error instanceof SparkVaultError) || typeof error.statusCode !== 'number') {
|
|
15789
|
+
return { ok: false, error, outcome: UNANSWERED };
|
|
15790
|
+
}
|
|
15791
|
+
const outcome = mintOutcome(error, error.statusCode);
|
|
15792
|
+
return { ok: false, error: outcome.coreCode === null ? error : namingCoreCode(error, outcome.coreCode), outcome };
|
|
15704
15793
|
}
|
|
15705
15794
|
return attemptDownload(link, state, options);
|
|
15706
15795
|
}
|
|
15707
15796
|
/**
|
|
15708
|
-
* The transfer policy's reading of a
|
|
15709
|
-
* answer when it built the error: its status gives the verdict (a refused
|
|
15710
|
-
* is a 400, so final) and the `Retry-After` it named rides on the error
|
|
15797
|
+
* The transfer policy's reading of a mint Core refused. The HTTP client read
|
|
15798
|
+
* the answer when it built the error: its status gives the verdict (a refused
|
|
15799
|
+
* link is a 400, so final) and the `Retry-After` it named rides on the error
|
|
15711
15800
|
* (`retryAfterMs`), so a mint Core defers waits out Core's floor exactly as a
|
|
15712
|
-
* deferred Forge answer does.
|
|
15801
|
+
* deferred Forge answer does. Core's lock of a vault scheduled for deletion
|
|
15802
|
+
* (409 VAULT_DELETION_SCHEDULED) is read by its code, as the policy reads
|
|
15803
|
+
* Forge's relay of it on the download itself: final at once. Any other 409
|
|
15804
|
+
* keeps its status's reading.
|
|
15805
|
+
*/
|
|
15806
|
+
function mintOutcome(error, status) {
|
|
15807
|
+
const details = error.code === VAULT_DELETION_SCHEDULED ? { coreCode: error.code } : null;
|
|
15808
|
+
return { ...classifyTransferResponse({ status, details }), retryAfterMs: error.retryAfterMs };
|
|
15809
|
+
}
|
|
15810
|
+
/**
|
|
15811
|
+
* Core's refusal of a mint as its caller sees it: Core's sentence, code and
|
|
15812
|
+
* details, with the code in `details.coreCode`, where a refused download
|
|
15813
|
+
* names it too, so one reading tells the lock whichever answer met it.
|
|
15713
15814
|
*/
|
|
15714
|
-
function
|
|
15715
|
-
|
|
15716
|
-
return UNANSWERED;
|
|
15717
|
-
return { ...classifyTransferResponse({ status: error.statusCode }), retryAfterMs: error.retryAfterMs };
|
|
15815
|
+
function namingCoreCode(error, coreCode) {
|
|
15816
|
+
return new SparkVaultError(error.message, error.code, error.statusCode, { ...error.details, coreCode }, error.retryAfterMs);
|
|
15718
15817
|
}
|
|
15719
15818
|
/**
|
|
15720
15819
|
* Fetch one link: the rest of the file held, conditioned on its validator,
|
|
@@ -15749,11 +15848,8 @@ async function attemptDownload(link, state, options) {
|
|
|
15749
15848
|
? { signal: controller.signal, headers: { Range: `bytes=${resume.at}-`, 'If-Range': resume.validator } }
|
|
15750
15849
|
: { signal: controller.signal }), DOWNLOAD_TTFB_TIMEOUT_MS, controller, 'Download timed out waiting for response headers');
|
|
15751
15850
|
if (!response.ok) {
|
|
15752
|
-
|
|
15753
|
-
|
|
15754
|
-
error: new SparkVaultError(`Download failed with status ${response.status}`, 'download_failed', response.status),
|
|
15755
|
-
outcome: classifyTransferResponse({ status: response.status, headers: (name) => response.headers.get(name) }),
|
|
15756
|
-
};
|
|
15851
|
+
const outcome = classifyTransferResponse({ status: response.status, headers: (name) => response.headers.get(name) });
|
|
15852
|
+
return { ok: false, error: await refusedDownloadError(response, outcome, controller), outcome };
|
|
15757
15853
|
}
|
|
15758
15854
|
if (resume && response.status === 206) {
|
|
15759
15855
|
const continued = continuation(response, resume);
|
|
@@ -15809,6 +15905,24 @@ async function attemptDownload(link, state, options) {
|
|
|
15809
15905
|
signal?.removeEventListener('abort', abortFromCaller);
|
|
15810
15906
|
}
|
|
15811
15907
|
}
|
|
15908
|
+
/**
|
|
15909
|
+
* The error a download answered with a failure throws once nothing retries
|
|
15910
|
+
* it. A refusal Core decided names Core's code (the 409 of a vault scheduled
|
|
15911
|
+
* for deletion, in X-Upload-Refusal), and is reported in Core's own sentence,
|
|
15912
|
+
* read from the answer's body under the idle deadline, with the code in
|
|
15913
|
+
* `details.coreCode`; any other failure by its status.
|
|
15914
|
+
*/
|
|
15915
|
+
async function refusedDownloadError(response, outcome, controller) {
|
|
15916
|
+
const statusMessage = `Download failed with status ${response.status}`;
|
|
15917
|
+
const { coreCode } = outcome;
|
|
15918
|
+
if (outcome.verdict !== TRANSFER_VERDICT.REFUSED || coreCode === null) {
|
|
15919
|
+
return new SparkVaultError(statusMessage, 'download_failed', response.status);
|
|
15920
|
+
}
|
|
15921
|
+
const served = await withDeadline(readApiFailure(response), DOWNLOAD_IDLE_TIMEOUT_MS, controller, 'Download timed out reading the refusal');
|
|
15922
|
+
// Only a body naming the same code carries Core's sentence for it.
|
|
15923
|
+
const message = served.code === coreCode ? served.message : statusMessage;
|
|
15924
|
+
return new SparkVaultError(message, 'download_failed', response.status, { coreCode });
|
|
15925
|
+
}
|
|
15812
15926
|
/**
|
|
15813
15927
|
* The failure of a body that ended at a length other than the one its
|
|
15814
15928
|
* response declared: what the caller sees once the transfer can no longer
|
|
@@ -16218,10 +16332,13 @@ class IngotsModule {
|
|
|
16218
16332
|
* no longer holds (it expired, was cancelled, or its ingot was removed)
|
|
16219
16333
|
* rejects with code `session_gone`, and only a new upload session — a new
|
|
16220
16334
|
* {@link createUpload}, or {@link upload} again — can store the file. An
|
|
16221
|
-
* upload the server refused
|
|
16222
|
-
*
|
|
16223
|
-
* `
|
|
16224
|
-
*
|
|
16335
|
+
* upload the server refused (the account's storage pool cannot take it, a
|
|
16336
|
+
* later upload replaced it, or its vault is scheduled for deletion: a 409
|
|
16337
|
+
* `VAULT_DELETION_SCHEDULED`, whose session the server keeps until the
|
|
16338
|
+
* deletion runs or is cancelled, or the session lapses on its own) rejects
|
|
16339
|
+
* at once with code `upload_refused`, its message the server's own sentence
|
|
16340
|
+
* and its code in `details.coreCode`: a new upload is no remedy. A
|
|
16341
|
+
* publication the server
|
|
16225
16342
|
* still defers at the transfer's idle limit rejects with code
|
|
16226
16343
|
* `upload_received_publishing`: every byte is received, and the server
|
|
16227
16344
|
* finishes the publication on its own, so never upload the file again; a
|
|
@@ -16255,8 +16372,11 @@ class IngotsModule {
|
|
|
16255
16372
|
*
|
|
16256
16373
|
* It rejects as {@link sendUpload} does: `session_gone` once the server no
|
|
16257
16374
|
* longer holds the session (it expired, was cancelled, or ended when the
|
|
16258
|
-
* server refused to publish it), `upload_refused` for an upload
|
|
16259
|
-
*
|
|
16375
|
+
* server refused to publish it), `upload_refused` for an upload the server
|
|
16376
|
+
* refused (its storage pool, a later upload, or its vault scheduled for
|
|
16377
|
+
* deletion, a 409 `VAULT_DELETION_SCHEDULED` that keeps the session, so a
|
|
16378
|
+
* resume once the deletion is cancelled goes on while the session stands),
|
|
16379
|
+
* `upload_received_publishing` again for a publication the server
|
|
16260
16380
|
* still defers at the transfer's idle limit, which leaves the session to
|
|
16261
16381
|
* resume again later. A session URL that is not an upload session on an
|
|
16262
16382
|
* allowed transfer host is refused (`invalid_forge_url`), and one whose
|
|
@@ -16305,9 +16425,10 @@ class IngotsModule {
|
|
|
16305
16425
|
*
|
|
16306
16426
|
* Creates the upload session, streams the file to Forge over TUS, then
|
|
16307
16427
|
* confirms the server finalized the upload before resolving. A file the
|
|
16308
|
-
* server refused
|
|
16309
|
-
*
|
|
16310
|
-
*
|
|
16428
|
+
* server refused — another upload of it superseded this one, at its create
|
|
16429
|
+
* or while it streamed, the storage pool cannot take it, or its vault is
|
|
16430
|
+
* scheduled for deletion (a 409 `VAULT_DELETION_SCHEDULED`) — rejects with
|
|
16431
|
+
* code `upload_refused`, as {@link sendUpload} does.
|
|
16311
16432
|
*
|
|
16312
16433
|
* @example
|
|
16313
16434
|
* const ingot = await sv.ingots.upload(unsealed, {
|
|
@@ -16520,8 +16641,14 @@ class IngotsModule {
|
|
|
16520
16641
|
* and a link that is not a Forge decrypt URL on an allowed host, is final.
|
|
16521
16642
|
*
|
|
16522
16643
|
* @example
|
|
16644
|
+
* const ingot = await sv.ingots.get(unsealed, 'ing_abc');
|
|
16523
16645
|
* const blob = await sv.ingots.download(unsealed, 'ing_abc');
|
|
16524
|
-
*
|
|
16646
|
+
* // Saved under the name Forge would send, as opaque bytes, which no
|
|
16647
|
+
* // browser renames by a type (see Ingot.downloadFilename).
|
|
16648
|
+
* const link = document.createElement('a');
|
|
16649
|
+
* link.href = URL.createObjectURL(new Blob([blob], { type: 'application/octet-stream' }));
|
|
16650
|
+
* link.download = ingot.downloadFilename;
|
|
16651
|
+
* link.click();
|
|
16525
16652
|
*/
|
|
16526
16653
|
async download(vault, ingotId) {
|
|
16527
16654
|
const mint = async () => (await this.createDownloadLink(vault, ingotId)).downloadUrl;
|
|
@@ -16700,6 +16827,7 @@ function mapIngot(wire) {
|
|
|
16700
16827
|
return {
|
|
16701
16828
|
id: wire.ingot_id,
|
|
16702
16829
|
name: wire.name,
|
|
16830
|
+
downloadFilename: wire.download_filename,
|
|
16703
16831
|
contentType: wire.content_type,
|
|
16704
16832
|
size: wire.size_bytes,
|
|
16705
16833
|
status: wire.status ?? 'active',
|
|
@@ -16791,6 +16919,7 @@ class SparksModule {
|
|
|
16791
16919
|
createdAt: data.created_at,
|
|
16792
16920
|
burnedAt: data.burned_at,
|
|
16793
16921
|
filename: data.filename,
|
|
16922
|
+
downloadFilename: data.download_filename,
|
|
16794
16923
|
};
|
|
16795
16924
|
}
|
|
16796
16925
|
/**
|
|
@@ -17432,7 +17561,7 @@ class SparkVault {
|
|
|
17432
17561
|
}
|
|
17433
17562
|
/** Get the SDK version */
|
|
17434
17563
|
static get version() {
|
|
17435
|
-
return '11.2.
|
|
17564
|
+
return '11.2.5';
|
|
17436
17565
|
}
|
|
17437
17566
|
}
|
|
17438
17567
|
if (typeof window !== 'undefined') {
|