@sparkvault/sdk-mobile 7.2.4 → 7.2.6

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.
@@ -62,9 +62,10 @@ const DROPPED_TRAILING_CHARACTER = /[\s.]/u;
62
62
  /**
63
63
  * `name` without the trailing dots and white space a save drops: "page.html."
64
64
  * and "page.html " are "page.html", "notes. ." is "notes", and a name of only
65
- * dots and white space is ''. lastExtension reads the extension in front of
66
- * them, and Forge completes a saved name after them (./media-type-node.js
67
- * withMediaTypeExtension: "notes." under text/plain saves as "notes.txt").
65
+ * dots and white space is ''. shownExtension and lastExtension read the
66
+ * extension in front of them, and Forge completes a saved name after them
67
+ * (./media-type-node.js withMediaTypeExtension: "notes." under text/plain
68
+ * saves as "notes.txt").
68
69
  *
69
70
  * @param {string} name
70
71
  * @returns {string}
@@ -88,7 +89,7 @@ const INVISIBLE_CHARACTERS = /\p{Default_Ignorable_Code_Point}/gu;
88
89
  * What `name` shows once saved: the name read past its invisible characters
89
90
  * (INVISIBLE_CHARACTERS), without the trailing dots and white space a save
90
91
  * drops (trimDroppedTrailing). The extension a name shows is read in it
91
- * (lastExtension), and a name it leaves nothing of is one of only dots or
92
+ * (shownExtension), and a name it leaves nothing of is one of only dots or
92
93
  * spaces (isOnlyDotsOrSpaces).
93
94
  *
94
95
  * @param {string} name
@@ -215,7 +216,7 @@ export const WHITEBOARD_MARKER_EXTENSION = '.whiteboard.svg';
215
216
  * shortened copy keeps it ("Plan (2).note.html", never "Plan.note (2).html")
216
217
  * and its title is still the part in front of it. No rule about what a file
217
218
  * is reads a marker: those read the content type (a document's kind,
218
- * ./ingot-kind.js) or the lastExtension (the extension a name shows).
219
+ * ./ingot-kind.js) or the lastExtension (the extension a saved copy opens as).
219
220
  */
220
221
  export const DOCUMENT_MARKER_EXTENSIONS = Object.freeze([WHITEBOARD_MARKER_EXTENSION, NOTE_MARKER_EXTENSION]);
221
222
 
@@ -239,34 +240,81 @@ export function splitExtension(name) {
239
240
  }
240
241
 
241
242
  /**
242
- * The extension `name` shows, lowercase and without its dot: what follows the
243
- * last dot of what the name shows once saved (nameAsShown: read past its
244
- * invisible characters, without the trailing dots and white space a save
245
- * drops). It is the extension a saved copy opens as wherever the name holds
246
- * no invisible character: "invoice.note.html" and
247
- * "page.html." open as 'html', "logs.tar.gz" as 'gz', ".html" as 'html'
248
- * (Windows reads a leading dot's extension), and a name with no dot as ''.
249
- * "Invoice.pdf<U+034F>" shows 'pdf', so no rule completes it with a second
250
- * extension a desktop that hides known extensions would not show. A character
251
- * that draws as blank space or as another letter yet is no invisible
252
- * character stays in the extension read ("Invoice.pdf<U+2800>", a braille
253
- * blank, reads 'pdf<U+2800>'; "Invoice.<U+0440>df", a Cyrillic er,
254
- * '<U+0440>df'), which no registry extension then is, and Forge completes no
255
- * such name (./media-type-node.js withMediaTypeExtension). Every rule
256
- * about what a name makes a file (a refused extension, an inline
257
- * disposition, the type Core stores for an untyped upload, whether Forge
258
- * completes a saved name and the type it serves it under:
259
- * ./media-type-node.js) reads this, never splitExtension.
243
+ * A run of the white space Firefox reads in a name it saves: the space
244
+ * separators and U+FEFF, and the line and paragraph separators, which it
245
+ * drops wherever they stand and which end no run.
246
+ */
247
+ const WHITE_SPACE_RUN = /[\p{Zs}\uFEFF\u2028\u2029]+/gu;
248
+
249
+ /** A run whose first space is an ideographic space (U+3000), the one space Firefox keeps. */
250
+ const RUN_FIREFOX_KEEPS = /^[\u2028\u2029]*\u3000/;
251
+
252
+ /**
253
+ * `name` with its white space closed up as Firefox closes it in what follows
254
+ * its last dot, under any type it is handed and in a blob's name alike
255
+ * (nsExternalHelperAppService::SanitizeFileName): it collapses a run of white
256
+ * space into the run's first character, an ideographic space kept as it is
257
+ * and any other made an ASCII space, then strips the ASCII spaces from what
258
+ * follows the last dot. So a run there is dropped whole unless it starts with
259
+ * an ideographic space: `evil.ex e` saves as `evil.exe`, `evil.ex<U+3000>e`
260
+ * as itself, `evil.ex <U+3000>e` as `evil.exe`. Closing up the whole name
261
+ * moves no dot, so what follows its last dot is what Firefox saves there.
260
262
  *
261
263
  * @param {string} name
262
264
  * @returns {string}
263
265
  */
264
- export function lastExtension(name) {
266
+ function closeUpSpaces(name) {
267
+ return name.replace(WHITE_SPACE_RUN, (run) => (RUN_FIREFOX_KEEPS.test(run) ? '\u3000' : ''));
268
+ }
269
+
270
+ /**
271
+ * The extension `name` shows, its spaces kept, lowercase and without its dot:
272
+ * what follows the last dot of what the name shows once saved (nameAsShown:
273
+ * read past its invisible characters, without the trailing dots and white
274
+ * space a save drops). "invoice.note.html" and "page.html." show 'html',
275
+ * "logs.tar.gz" 'gz', ".html" 'html' (Windows reads a leading dot's
276
+ * extension), "Invoice.pdf (1)" 'pdf (1)', and a name with no dot ''. It is
277
+ * what Chromium's copy shows, since Chromium saves a name as sent:
278
+ * "Invoice.pdf<U+034F>" shows 'pdf', and a character that draws as blank
279
+ * space or as another letter yet is no invisible character stays in it
280
+ * ("Invoice.pdf<U+2800>", a braille blank, shows 'pdf<U+2800>';
281
+ * "Invoice.<U+0440>df", a Cyrillic er, '<U+0440>df'). Only whether a saved
282
+ * name is completed reads it, by where its first word ends
283
+ * (./media-type-node.js withMediaTypeExtension), since completion ends a name
284
+ * in its type's own extension, which holds no space for Firefox to close up;
285
+ * every rule about what a name makes a file reads lastExtension.
286
+ *
287
+ * @param {string} name
288
+ * @returns {string}
289
+ */
290
+ export function shownExtension(name) {
265
291
  const shown = nameAsShown(name);
266
292
  const dot = shown.lastIndexOf('.');
267
293
  return dot === -1 ? '' : shown.slice(dot + 1).toLowerCase();
268
294
  }
269
295
 
296
+ /**
297
+ * The extension a saved copy of `name` opens as, lowercase and without its
298
+ * dot: the one it shows (shownExtension) once its spaces are closed up as
299
+ * Firefox, the browser that changes a saved name most, closes them
300
+ * (closeUpSpaces). "evil.ex e", "evil.ex<U+00A0>e" and "evil. exe" open as
301
+ * 'exe', "Scan. pdf" as 'pdf', "Invoice.pdf (1)" as 'pdf(1)' and "Acme Inc.
302
+ * Contract" as 'contract', though Chromium saves each as sent. Every rule
303
+ * about what a name makes a file (a refused extension, an inline
304
+ * disposition, the type Core stores for an untyped upload, the type Forge
305
+ * serves a download under: ./media-type-node.js) reads this, never
306
+ * splitExtension.
307
+ *
308
+ * @param {string} name
309
+ * @returns {string}
310
+ */
311
+ export function lastExtension(name) {
312
+ // Closed up before its invisible characters are read past: Firefox counts
313
+ // U+FEFF, one of them, as white space (`evil.ex<U+FEFF><U+3000>e` saves as
314
+ // `evil.exe`).
315
+ return shownExtension(closeUpSpaces(name));
316
+ }
317
+
270
318
  /**
271
319
  * The longest prefix of `text` within `maxLength` UTF-16 units that splits no
272
320
  * character.
@@ -23,20 +23,29 @@
23
23
  * both bounds start over whenever the server confirms progress.
24
24
  *
25
25
  * Forge's own answers beyond the general rule:
26
- * - the 409, in two kinds: one carrying `Upload-Offset` names where the
27
- * session stands (continue from there), and one without it means another
28
- * request holds the session's write lease, a chunk or the finalization
29
- * (retry after its `Retry-After`);
30
- * - a terminal answer (a 404, 410 or 412) names the code Core ended the
31
- * upload with: its error envelope in `error.details.coreCode` for the
32
- * refusals it words itself, and every one of them in `X-Upload-Refusal`,
33
- * which is all a HEAD's answer, having no body, can carry; the body's code
34
- * wins when both name one. The code decides the verdict: a full storage
35
- * pool or a later upload that replaced this one is a refusal no new upload
36
- * of the same file remedies, and any other code (the file the upload was
37
- * for gone, a retired contract, a replacement base that moved on, a code
38
- * this policy does not know) ends the session, which a new upload can
39
- * start over;
26
+ * - an answer naming a refusal Core decided names Core's code: a terminal
27
+ * answer (a 404, 410 or 412) the code Core ended the upload with, and a 409
28
+ * relaying Core's refusal of the transfer the code Core refused it with.
29
+ * Its error envelope names it in `error.details.coreCode` (for the refusals
30
+ * Forge words itself and the ones it relays from Core's check of a
31
+ * transfer), and every one of them in `X-Upload-Refusal`, which is all a
32
+ * HEAD's answer, having no body, can carry; the body's code wins when both
33
+ * name one;
34
+ * - the 409, in three kinds: one carrying `Upload-Offset` names where the
35
+ * session stands (continue from there); one naming Core's code is Core's
36
+ * refusal of the transfer in its vault's current state, a vault scheduled
37
+ * for deletion (VAULT_DELETION_SCHEDULED), which keeps the session (until
38
+ * it lapses on its 72 h idle window, upload-expiry.js) and which neither
39
+ * the same request nor a new upload gets past until a person cancels the
40
+ * deletion, so it is reported, never retried; and one naming
41
+ * neither means another request holds the session's write lease, a chunk
42
+ * or the finalization (retry after its `Retry-After`);
43
+ * - a terminal answer's code decides its verdict: a full storage pool or a
44
+ * later upload that replaced this one is a refusal no new upload of the
45
+ * same file remedies, and any other code (the file the upload was for
46
+ * gone, a retired contract, a replacement base that moved on, a code this
47
+ * policy does not know) ends the session, which a new upload can start
48
+ * over;
40
49
  * - a 503 carrying `Retry-After` to the receipt (the PATCH at the final
41
50
  * offset) is a deferral: Forge holds every byte and is still publishing,
42
51
  * and finishes without the client, so it is asked again, each time after a
@@ -65,10 +74,10 @@ export const TRANSFER_VERDICT = Object.freeze({
65
74
  /** 2xx: the request did what it asked. */
66
75
  OK: 'ok',
67
76
  /**
68
- * No answer (a reset, a timeout), 408, 425, 429, a 5xx, or a 409 without
69
- * `Upload-Offset` (another request holds the session's lease): back off,
70
- * never sooner than `Retry-After`, then ask the server's offset before
71
- * sending a chunk again.
77
+ * No answer (a reset, a timeout), 408, 425, 429, a 5xx, or a 409 naming
78
+ * neither an `Upload-Offset` nor a code of Core's (another request holds
79
+ * the session's lease): back off, never sooner than `Retry-After`, then ask
80
+ * the server's offset before sending a chunk again.
72
81
  */
73
82
  RETRY: 'retry',
74
83
  /** 409 with `Upload-Offset`: the session stands elsewhere; continue from that offset at once. */
@@ -87,10 +96,11 @@ export const TRANSFER_VERDICT = Object.freeze({
87
96
  */
88
97
  GONE: 'gone',
89
98
  /**
90
- * Any other status, or a 404, 410 or 412 naming a final refusal of Core's
91
- * (`coreCode`: UPLOAD_POOL_FULL, UPLOAD_SUPERSEDED): the server's verdict on
92
- * this request, which repeating it, or a new upload of the same file,
93
- * earns again.
99
+ * Any other status, a 404, 410 or 412 naming a final refusal of Core's
100
+ * (`coreCode`: UPLOAD_POOL_FULL, UPLOAD_SUPERSEDED), or a 409 naming any
101
+ * code of Core's (`coreCode`: VAULT_DELETION_SCHEDULED, whose session
102
+ * stands): the server's verdict on this request, which repeating it, or a
103
+ * new upload of the same file, earns again.
94
104
  */
95
105
  REFUSED: 'refused'
96
106
  });
@@ -110,6 +120,12 @@ const SERVICE_UNAVAILABLE = 503;
110
120
  */
111
121
  const TERMINAL_STATUSES = new Set([404, 410, 412]);
112
122
 
123
+ /**
124
+ * Forge's 409: about where the session stands (`Upload-Offset`), another
125
+ * request's lease on it, or Core's refusal of the transfer, relayed.
126
+ */
127
+ const CONFLICT = 409;
128
+
113
129
  /** Core's error codes are upper-case words joined by underscores; anything else names no code. */
114
130
  const CORE_CODE = /^[A-Z][A-Z0-9_]{0,63}$/;
115
131
 
@@ -153,12 +169,14 @@ const DEFAULT_MAX_CONSECUTIVE_FAILURES = 8;
153
169
  * @property {number|null} retryAfterMs - The answer's `Retry-After`, in ms from
154
170
  * the answer (an HTTP-date already past reads as 0); null when absent or unreadable
155
171
  * @property {number|null} offset - The answer's `Upload-Offset`; null when absent or unreadable
156
- * @property {string|null} coreCode - The code Core ended the upload with, as a
157
- * terminal answer named it (a 404, 410 or 412: its body's details or, those
158
- * naming none, its `X-Upload-Refusal`): REFUSED for a final refusal
159
- * (`UPLOAD_POOL_FULL`, `UPLOAD_SUPERSEDED`), GONE for any other code
160
- * (`NOT_FOUND`, `UPLOAD_PROTOCOL_RETIRED`, a 412's, one this policy does not
161
- * know); null when the answer names none
172
+ * @property {string|null} coreCode - The code of the refusal Core decided, as
173
+ * the answer named it (a 404, 410 or 412, or a 409 naming no offset: its
174
+ * body's details or, those naming none, its `X-Upload-Refusal`): REFUSED for
175
+ * any code a 409 names (`VAULT_DELETION_SCHEDULED`) and for a terminal
176
+ * answer's final refusal (`UPLOAD_POOL_FULL`, `UPLOAD_SUPERSEDED`), GONE for
177
+ * any other code a terminal answer names (`NOT_FOUND`,
178
+ * `UPLOAD_PROTOCOL_RETIRED`, a 412's, one this policy does not know); null
179
+ * when the answer names none
162
180
  */
163
181
 
164
182
  /**
@@ -197,7 +215,7 @@ export function classifyTransferResponse({ status, headers = null, details = nul
197
215
  }
198
216
  const header = (name) => (headers === null ? null : headers(name));
199
217
  const offset = readCount(header(UPLOAD_OFFSET_HEADER));
200
- const coreCode = TERMINAL_STATUSES.has(status)
218
+ const coreCode = mayNameCoreCode(status, offset)
201
219
  ? coreCodeIn(details) ?? coreCodeOf(header(UPLOAD_REFUSAL_HEADER))
202
220
  : null;
203
221
  const retryAfterMs = readRetryAfterMs(header(RETRY_AFTER_HEADER), now);
@@ -209,14 +227,28 @@ export function classifyTransferResponse({ status, headers = null, details = nul
209
227
  };
210
228
  }
211
229
 
230
+ /**
231
+ * Whether an answer may name the code of a refusal Core decided: a terminal
232
+ * answer does, and so does a 409 naming no offset. A 409 carrying
233
+ * `Upload-Offset` is Forge's own, about where the session stands.
234
+ */
235
+ function mayNameCoreCode(status, offset) {
236
+ return TERMINAL_STATUSES.has(status) || (status === CONFLICT && offset === null);
237
+ }
238
+
212
239
  /**
213
240
  * The verdict on a status that came with an answer: `offset` its readable
214
- * `Upload-Offset`, `coreCode` the code of Core's a terminal answer names,
241
+ * `Upload-Offset`, `coreCode` the code of Core's the answer names,
215
242
  * `deferral` whether it answered the receipt with a readable `Retry-After`.
216
243
  */
217
244
  function verdictFor(status, { offset, coreCode, deferral }) {
218
245
  if (status >= 200 && status < 300) return TRANSFER_VERDICT.OK;
219
- if (status === 409) return offset === null ? TRANSFER_VERDICT.RETRY : TRANSFER_VERDICT.RESYNC;
246
+ if (status === CONFLICT) {
247
+ if (offset !== null) return TRANSFER_VERDICT.RESYNC;
248
+ // Core's 409 refuses the transfer in its vault's current state: the
249
+ // session stands, and the same request or a new upload earns it again.
250
+ return coreCode === null ? TRANSFER_VERDICT.RETRY : TRANSFER_VERDICT.REFUSED;
251
+ }
220
252
  if (coreCode !== null) return UPLOAD_FINAL_REFUSAL_CODES.includes(coreCode) ? TRANSFER_VERDICT.REFUSED : TRANSFER_VERDICT.GONE;
221
253
  if (status === 404 || status === 410) return TRANSFER_VERDICT.GONE;
222
254
  if (deferral && status === SERVICE_UNAVAILABLE) return TRANSFER_VERDICT.DEFERRED;
@@ -6,7 +6,9 @@
6
6
  * The upload publication contract between Forge and Core's activation, and
7
7
  * the facts of a transfer token both services spell: its shape, the
8
8
  * publication it is bound to (a content version, and the one an ingot row
9
- * names), and Core's revocation of an upload's token.
9
+ * names), Core's revocation of an upload's token, and the refusals of Core's
10
+ * a transfer's answer names (the header, and the lock of a vault scheduled
11
+ * for deletion).
10
12
  *
11
13
  * Forge stamps UPLOAD_PUBLICATION_PROTOCOL on every upload session it creates
12
14
  * and on the final state it hands Core's activation (POST
@@ -188,9 +190,36 @@ export function uploadTokenRevocationReason(record) {
188
190
  }
189
191
 
190
192
  /**
191
- * The response header that names the code Core refused an upload with for
192
- * good: Forge sends it on every terminal answer to a tus request, a HEAD's
193
- * (which has no body) included, so a client tells an upload the owner's pool
194
- * cannot take from one a later upload superseded without reading a body.
193
+ * The code Core refuses every use of a vault's content with (409) while the
194
+ * vault is scheduled for deletion, until a company admin cancels the
195
+ * deletion or it runs and the vault is gone: a transfer token's use, each
196
+ * request of a transfer (Forge asks Core before every one and relays the
197
+ * refusal naming this code), and an upload's activation, which Forge defers.
198
+ * The lock refuses an upload's requests and never ends its session, so a
199
+ * client keeps the session and reports the lock. The session still lapses
200
+ * on its own idle window (upload-expiry.js), which is shorter than the
201
+ * deletion's delay: an upload resumed after a cancelled deletion goes on from
202
+ * its offset while the session stands, and starts over once it has lapsed.
203
+ */
204
+ export const VAULT_DELETION_SCHEDULED = 'VAULT_DELETION_SCHEDULED';
205
+
206
+ /**
207
+ * The words a vault scheduled for deletion refuses every use of its content
208
+ * in (VAULT_DELETION_SCHEDULED), whichever service or client meets it:
209
+ * Core's refusal, and a client's report of it from an answer with no body
210
+ * to carry Core's (a HEAD's, naming the code in UPLOAD_REFUSAL_HEADER alone).
211
+ */
212
+ export const VAULT_DELETION_SCHEDULED_MESSAGE =
213
+ 'This vault is scheduled for deletion. Cancel its deletion in vault settings before accessing its contents.';
214
+
215
+ /**
216
+ * The response header that names the code of a refusal Core decided: Forge
217
+ * sends it on every terminal answer to a tus request (a 404, 410 or 412) and
218
+ * on every answer relaying Core's decision about a transfer's vault (the 409
219
+ * VAULT_DELETION_SCHEDULED, a 404 naming the vault), a download's and a
220
+ * HEAD's (which has no body) included, so a
221
+ * client tells an upload the owner's pool cannot take from one a later
222
+ * upload superseded, and Core's lock from another request holding the
223
+ * session's lease, without reading a body.
195
224
  */
196
225
  export const UPLOAD_REFUSAL_HEADER = 'X-Upload-Refusal';
package/src/errors.ts CHANGED
@@ -201,13 +201,17 @@ export class TusUploadError extends SparkVaultMobileError {
201
201
  */
202
202
  readonly retryLater: boolean;
203
203
  /**
204
- * The code Core ended this upload with, as Forge named it. With code
205
- * `upload_refused` a final refusal (`UPLOAD_POOL_FULL`: the account's
206
- * storage pool cannot take it; `UPLOAD_SUPERSEDED`: a later upload replaced
207
- * it), whose message is Core's own sentence and which no new upload of the
208
- * same file remedies; with `sessionLost` any other code (`NOT_FOUND`: the
209
- * file the upload was for is gone; `UPLOAD_PROTOCOL_RETIRED`; a 412's),
210
- * which a fresh upload starts over from. Null when the answer named none.
204
+ * The code Core refused or ended this upload with, as Forge named it. With
205
+ * code `upload_refused` a refusal no new upload of the same file remedies,
206
+ * whose message is Core's own sentence: a final one (`UPLOAD_POOL_FULL`:
207
+ * the account's storage pool cannot take it; `UPLOAD_SUPERSEDED`: a later
208
+ * upload replaced it), or the lock of a vault scheduled for deletion
209
+ * (`VAULT_DELETION_SCHEDULED`, a 409: the session stands, and the upload
210
+ * can go on once the deletion is cancelled, from its offset while the
211
+ * session has not lapsed on its idle window); with `sessionLost` any
212
+ * other code (`NOT_FOUND`: the file the upload was for is gone;
213
+ * `UPLOAD_PROTOCOL_RETIRED`; a 412's), which a fresh upload starts over
214
+ * from. Null when the answer named none.
211
215
  */
212
216
  readonly coreCode: string | null;
213
217
 
@@ -278,6 +282,12 @@ export class BackgroundTransferError extends Error {
278
282
  readonly offset: number;
279
283
  readonly httpStatus?: number;
280
284
  readonly body?: string;
285
+ /**
286
+ * The answer's `X-Upload-Refusal` as received (an `http` failure): the code
287
+ * of a refusal Core decided, which an answer with no body names nowhere
288
+ * else, so the SDK reads it as it reads the header on the XHR path.
289
+ */
290
+ readonly uploadRefusal?: string;
281
291
  readonly cause: Error | null;
282
292
 
283
293
  constructor(
@@ -287,6 +297,7 @@ export class BackgroundTransferError extends Error {
287
297
  offset: number;
288
298
  httpStatus?: number;
289
299
  body?: string;
300
+ uploadRefusal?: string;
290
301
  cause?: Error | null;
291
302
  }
292
303
  ) {
@@ -296,6 +307,7 @@ export class BackgroundTransferError extends Error {
296
307
  this.offset = options.offset;
297
308
  this.httpStatus = options.httpStatus;
298
309
  this.body = options.body;
310
+ this.uploadRefusal = options.uploadRefusal;
299
311
  this.cause = options.cause ?? null;
300
312
  Object.setPrototypeOf(this, BackgroundTransferError.prototype);
301
313
  }
package/src/tus.ts CHANGED
@@ -14,7 +14,12 @@ import {
14
14
  transferJitterKey,
15
15
  } from './app-sdk/transfer-retry.js';
16
16
  import type { TransferBudget, TransferOutcome } from './app-sdk/transfer-retry.js';
17
- import { UPLOAD_REFUSAL_CODES } from './app-sdk/upload-publication.js';
17
+ import {
18
+ UPLOAD_REFUSAL_CODES,
19
+ UPLOAD_REFUSAL_HEADER,
20
+ VAULT_DELETION_SCHEDULED,
21
+ VAULT_DELETION_SCHEDULED_MESSAGE,
22
+ } from './app-sdk/upload-publication.js';
18
23
  import {
19
24
  BackgroundTransferError,
20
25
  gateErrorFromBody,
@@ -412,20 +417,24 @@ const RECEIVED_PUBLISHING_MESSAGE =
412
417
  'Upload received: Forge holds every byte and is still saving the file; it finishes without this device';
413
418
 
414
419
  /**
415
- * What a caller reads for a final refusal whose answer carried no sentence of
420
+ * What a caller reads for a refusal whose answer carried no sentence of
416
421
  * Core's (a HEAD's, which has no body, naming Core's code in
417
- * `X-Upload-Refusal` alone): this SDK's own words for each code.
422
+ * `X-Upload-Refusal` alone): this SDK's own words for each final refusal,
423
+ * and Core's own for its lock of a vault scheduled for deletion.
418
424
  */
419
425
  const REFUSAL_WORDING: ReadonlyMap<string, string> = new Map([
420
426
  [UPLOAD_REFUSAL_CODES.UPLOAD_POOL_FULL, 'This upload could not be saved: the owner\'s storage cannot take the file'],
421
427
  [UPLOAD_REFUSAL_CODES.UPLOAD_SUPERSEDED, 'This upload was not saved: a newer upload of this file replaced it'],
428
+ [VAULT_DELETION_SCHEDULED, VAULT_DELETION_SCHEDULED_MESSAGE],
422
429
  ]);
423
430
 
424
431
  /**
425
- * Core refused the upload for good, in its own words (the answer's body,
432
+ * Core refused the upload, in its own words (the answer's body,
426
433
  * `details.coreCode` naming Core's code) or, for an answer with no body (a
427
434
  * HEAD's, naming the code in `X-Upload-Refusal`), in this SDK's: the
428
- * account's storage pool cannot take it, or a later upload replaced it. Not
435
+ * account's storage pool cannot take it, a later upload replaced it, or its
436
+ * vault is scheduled for deletion (a 409, whose session stands until the
437
+ * deletion runs or is cancelled, or it lapses on its idle window). Not
429
438
  * `sessionLost`: a new upload of the same file is no remedy.
430
439
  */
431
440
  function refusedError(
@@ -439,7 +448,7 @@ function refusedError(
439
448
  const coreMessage = envelope.error?.message;
440
449
  const message = typeof coreMessage === 'string' && coreMessage
441
450
  ? coreMessage
442
- : REFUSAL_WORDING.get(coreCode) ?? `Forge did not save this upload: Core refused it for good (${coreCode})`;
451
+ : REFUSAL_WORDING.get(coreCode) ?? `Forge did not save this upload: Core refused it (${coreCode})`;
443
452
  return new TusUploadError(message, { cause, httpStatus: status, code: 'upload_refused', coreCode, ...context, phase });
444
453
  }
445
454
 
@@ -990,13 +999,13 @@ async function sendWholeFileInBackground(
990
999
  /**
991
1000
  * Translate what the OS transfer adapter reports into the SDK's one error
992
1001
  * taxonomy, so a caller sees the same `TusUploadError` phases and typed gate
993
- * errors whichever engine carried the bytes. Forge's status and body ride
994
- * through untouched: the refusal Core decided is `upload_refused` in Core's
995
- * words as on the XHR path, a 402 becomes the gate error the XHR path
996
- * throws, a status `isSessionGone` recognises marks the session lost exactly
997
- * as HEAD would, and any other status keeps its number for the caller's own policy
998
- * (a 409 during finalize is a retry-later, not a lost session). The
999
- * remaining kinds are transport
1002
+ * errors whichever engine carried the bytes. Forge's status, body and
1003
+ * `X-Upload-Refusal` ride through untouched: the refusal Core decided is
1004
+ * `upload_refused` in Core's words as on the XHR path, a 402 becomes the
1005
+ * gate error the XHR path throws, a status `isSessionGone` recognises marks
1006
+ * the session lost exactly as HEAD would, and any other status keeps its
1007
+ * number for the caller's own policy (a 409 during finalize is a
1008
+ * retry-later, not a lost session). The remaining kinds are transport
1000
1009
  * outcomes: the caller's own abort is `cancelled`; an OS-ended task
1001
1010
  * (`interrupted`) is a network failure, because the right response is the
1002
1011
  * same as for a dropped connection: resume from the server offset. Anything
@@ -1021,8 +1030,12 @@ export function mapBackgroundTransferError(
1021
1030
  const body = err.body ?? '';
1022
1031
  if (status !== undefined) {
1023
1032
  const envelope = parseErrorBody(body);
1033
+ // The engine hands over the one header a refusal Core decided is
1034
+ // named in, so a bodiless answer reads as it does on the XHR path.
1035
+ const header = (name: string) =>
1036
+ name.toLowerCase() === UPLOAD_REFUSAL_HEADER.toLowerCase() ? err.uploadRefusal ?? null : null;
1024
1037
  const outcome = Number.isSafeInteger(status) && status > 0
1025
- ? classifyTransferResponse({ status, details: envelope.error?.details ?? null })
1038
+ ? classifyTransferResponse({ status, headers: header, details: envelope.error?.details ?? null })
1026
1039
  : null;
1027
1040
  if (outcome?.verdict === TRANSFER_VERDICT.REFUSED && outcome.coreCode !== null) {
1028
1041
  return refusedError(status, envelope, outcome.coreCode, context, 'upload', err);
@@ -1106,17 +1119,22 @@ export class MobileTusUploader {
1106
1119
  * 425, 429, a 5xx or a lease-held 409 waits its backoff (never shorter than
1107
1120
  * `Retry-After`), then asks Forge where the session stands (HEAD) and sends
1108
1121
  * from there; a 409 carrying `Upload-Offset` continues from that offset at
1109
- * once; a receipt Forge defers (503 with `Retry-After`) is asked again,
1110
- * each time after a longer backoff, without spending a failure until the
1111
- * idle limit ends the upload as `upload_received_publishing`
1112
- * (`retryLater`); a gone session is `sessionLost` (`coreCode` naming the
1113
- * code Core ended it with, when the answer named one); a final refusal of
1114
- * Core's (`UPLOAD_POOL_FULL`, `UPLOAD_SUPERSEDED`) is `upload_refused` in
1115
- * Core's words (`coreCode`); any other 4xx ends the upload with the
1116
- * server's answer. No chunk is ever sent at an offset the server did not just name. While the device is offline (`isOnline`), a request that got
1117
- * no answer spends nothing: the upload waits for the network. The OS
1118
- * transfer engine's range is the exception: the engine chains its own
1119
- * requests, and its failure ends the call for the caller's own retry.
1122
+ * once; a 409 naming Core's code (Core's lock of a vault scheduled for
1123
+ * deletion, `VAULT_DELETION_SCHEDULED`) ends the upload at once as
1124
+ * `upload_refused` in Core's words (`coreCode`), its session kept until it
1125
+ * lapses on its 72 h idle window; a receipt Forge defers (503 with
1126
+ * `Retry-After`) is asked again, each time after a longer backoff, without
1127
+ * spending a failure until the idle limit ends the upload as
1128
+ * `upload_received_publishing` (`retryLater`); a gone session is
1129
+ * `sessionLost` (`coreCode` naming the code Core ended it with, when the
1130
+ * answer named one); a final refusal of Core's (`UPLOAD_POOL_FULL`,
1131
+ * `UPLOAD_SUPERSEDED`) is `upload_refused` in Core's words (`coreCode`);
1132
+ * any other 4xx ends the upload with the server's answer. No chunk is ever
1133
+ * sent at an offset the server did not just name. While the device is
1134
+ * offline (`isOnline`), a request that got no answer spends nothing: the
1135
+ * upload waits for the network. The OS transfer engine's range is the
1136
+ * exception: the engine chains its own requests, and its failure ends the
1137
+ * call for the caller's own retry.
1120
1138
  */
1121
1139
  async uploadFromUri(options: TusUploadFromUriOptions): Promise<void> {
1122
1140
  const fileReader = this.config.fileReader;
@@ -1537,7 +1555,8 @@ export class MobileTusUploader {
1537
1555
  * as `upload_received_publishing` (`retryLater`); a 503 naming no
1538
1556
  * `Retry-After` is no deferral of Forge's, asked again as a failure. A 409
1539
1557
  * naming an earlier offset means bytes are missing, and the upload
1540
- * continues from there. Forge answers it only after its own call to Core,
1558
+ * continues from there; one naming Core's code is Core's refusal, never
1559
+ * asked again. Forge answers it only after its own call to Core,
1541
1560
  * so it waits `HEAD_AND_RECEIPT_TIMEOUT_MS`, as a HEAD does.
1542
1561
  */
1543
1562
  private async confirmReceipt(transfer: TusTransfer): Promise<TransferPosition> {
package/src/types.ts CHANGED
@@ -1015,8 +1015,8 @@ export interface BackgroundTransferJob {
1015
1015
  * Why an OS transfer ended without reaching the final offset: the engine's
1016
1016
  * own failure kinds plus `cancelled`, which only the app adapter produces
1017
1017
  * for the caller's own abort (the engine never reports a cancel it was asked
1018
- * for). `http` carries Forge's status and body (the SDK maps gates and lost
1019
- * sessions from them); `interrupted` is the OS ending the task without being
1018
+ * for). `http` carries Forge's status, body and `X-Upload-Refusal` (the SDK
1019
+ * maps gates, lost sessions and Core's refusals from them); `interrupted` is the OS ending the task without being
1020
1020
  * asked (a relaunch, a system cancel); `stalled` is a 2xx whose offset did
1021
1021
  * not advance; `file` is a source the engine could not read.
1022
1022
  */