@sparkvault/sdk-mobile 7.2.3 → 7.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.
@@ -1,6 +1,6 @@
1
1
  import { isResourceId } from './app-sdk/ids.js';
2
2
  import { SparkVaultValidationError } from './errors.js';
3
- import { SAVED_FILENAME_FALLBACK, toStorableFilename } from './app-sdk/filename.js';
3
+ import { FILENAME_PROBLEMS, SAVED_FILENAME_FALLBACK, storableFilenameProblem, toStorableFilename, } from './app-sdk/filename.js';
4
4
  /** Whether a value is a well-formed SparkVault resource id (the platform's one rule). */
5
5
  export { isResourceId as isSafeId };
6
6
  /**
@@ -39,7 +39,10 @@ const WINDOWS_RESERVED_NAMES = new Set([
39
39
  * can climb a directory, so a `..` inside a name is kept. On top of the rule,
40
40
  * for the device's file system: leading dots are stripped (a hidden file) and
41
41
  * Windows reserved names are prefixed. Falls back to the platform's one
42
- * fallback name (SAVED_FILENAME_FALLBACK) when nothing remains.
42
+ * fallback name (SAVED_FILENAME_FALLBACK) when nothing remains, or nothing
43
+ * but dots and spaces (storableFilenameProblem's ONLY_DOTS_OR_SPACES, which
44
+ * reads a name past its invisible characters): `. .` and `..<U+034F>` show
45
+ * nothing a device can name a file by.
43
46
  */
44
47
  export function sanitizeFilename(filename) {
45
48
  let sanitized = toStorableFilename(filename)
@@ -49,6 +52,8 @@ export function sanitizeFilename(filename) {
49
52
  if (WINDOWS_RESERVED_NAMES.has(baseName)) {
50
53
  sanitized = `_${sanitized}`;
51
54
  }
52
- return sanitized || SAVED_FILENAME_FALLBACK;
55
+ return sanitized === '' || storableFilenameProblem(sanitized) === FILENAME_PROBLEMS.ONLY_DOTS_OR_SPACES
56
+ ? SAVED_FILENAME_FALLBACK
57
+ : sanitized;
53
58
  }
54
59
  //# sourceMappingURL=validation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA,OAAO,E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CAAC,QAAgB;IAC/C,kBAAkB,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC;AACxD,CAAC;AAED,sDAAsD;AACtD,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IAC1B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IACtE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CACvE,CAAC,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,IAAI,SAAS,GAAG,kBAAkB,CAAC,QAAQ,CAAC;SACzC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;SACnB,IAAI,EAAE,CAAC;IAEV,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACvD,IAAI,sBAAsB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzC,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAC9B,CAAC;IAED,OAAO,SAAS,KAAK,EAAE,IAAI,uBAAuB,CAAC,SAAS,CAAC,KAAK,iBAAiB,CAAC,mBAAmB;QACrG,CAAC,CAAC,uBAAuB;QACzB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkvault/sdk-mobile",
3
- "version": "7.2.3",
3
+ "version": "7.2.5",
4
4
  "description": "Mobile SDK for SparkVault Identity, vault, folder, and ingot workflows",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -51,6 +51,53 @@ export function hasControlOrBidiCharacter(text) {
51
51
  /** Characters the file systems a name is saved to refuse. */
52
52
  const NON_PORTABLE_FILENAME_CHARACTERS = /[:*?"<>|]/;
53
53
 
54
+ /**
55
+ * A character a save drops from a name's end. Windows drops trailing dots and
56
+ * spaces from a name it saves ("page.html." is saved as "page.html"); any
57
+ * other trailing white space is dropped alike, so a name never hides the
58
+ * extension a saved copy could open as.
59
+ */
60
+ const DROPPED_TRAILING_CHARACTER = /[\s.]/u;
61
+
62
+ /**
63
+ * `name` without the trailing dots and white space a save drops: "page.html."
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").
68
+ *
69
+ * @param {string} name
70
+ * @returns {string}
71
+ */
72
+ export function trimDroppedTrailing(name) {
73
+ let end = name.length;
74
+ while (end > 0 && DROPPED_TRAILING_CHARACTER.test(name[end - 1])) end -= 1;
75
+ return name.slice(0, end);
76
+ }
77
+
78
+ /**
79
+ * Invisible characters (Unicode's Default_Ignorable_Code_Point): the joiners,
80
+ * variation selectors, tags and bidirectional controls, which display as
81
+ * nothing, and the Hangul fillers, which display as blank space. None shows
82
+ * in a name, and a save keeps several (`Invoice.pdf<U+034F>` saves as itself
83
+ * in Chromium and Firefox, and shows as `Invoice.pdf`).
84
+ */
85
+ const INVISIBLE_CHARACTERS = /\p{Default_Ignorable_Code_Point}/gu;
86
+
87
+ /**
88
+ * What `name` shows once saved: the name read past its invisible characters
89
+ * (INVISIBLE_CHARACTERS), without the trailing dots and white space a save
90
+ * 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
+ * spaces (isOnlyDotsOrSpaces).
93
+ *
94
+ * @param {string} name
95
+ * @returns {string}
96
+ */
97
+ function nameAsShown(name) {
98
+ return trimDroppedTrailing(name.replace(INVISIBLE_CHARACTERS, ''));
99
+ }
100
+
54
101
  /** Why a name cannot be stored, as storableFilenameProblem reports it. */
55
102
  export const FILENAME_PROBLEMS = Object.freeze({
56
103
  UNSAFE_CHARACTER: 'unsafe_character',
@@ -58,7 +105,20 @@ export const FILENAME_PROBLEMS = Object.freeze({
58
105
  ONLY_DOTS_OR_SPACES: 'only_dots_or_spaces'
59
106
  });
60
107
 
61
- const ONLY_DOTS_OR_SPACES = /^[\s.]+$/;
108
+ /**
109
+ * Whether `name` is one of only dots or spaces: a name that is not empty yet
110
+ * shows nothing once saved (nameAsShown), every character in it a dot, white
111
+ * space or an invisible character (`...` and ` . `, and `..<U+034F>` and
112
+ * `.<U+200B>.`, which show as `..`). No such name is stored
113
+ * (storableFilenameProblem), and a file that has one saves under the
114
+ * fallback name (savedFilename).
115
+ *
116
+ * @param {string} name
117
+ * @returns {boolean}
118
+ */
119
+ function isOnlyDotsOrSpaces(name) {
120
+ return name !== '' && nameAsShown(name) === '';
121
+ }
62
122
 
63
123
  /**
64
124
  * What stops `name` from being stored as a file name, or null when nothing
@@ -70,7 +130,7 @@ const ONLY_DOTS_OR_SPACES = /^[\s.]+$/;
70
130
  export function storableFilenameProblem(name) {
71
131
  if (UNSAFE_FILENAME_CHARACTERS.test(name)) return FILENAME_PROBLEMS.UNSAFE_CHARACTER;
72
132
  if (NON_PORTABLE_FILENAME_CHARACTERS.test(name)) return FILENAME_PROBLEMS.NON_PORTABLE_CHARACTER;
73
- if (ONLY_DOTS_OR_SPACES.test(name)) return FILENAME_PROBLEMS.ONLY_DOTS_OR_SPACES;
133
+ if (isOnlyDotsOrSpaces(name)) return FILENAME_PROBLEMS.ONLY_DOTS_OR_SPACES;
74
134
  return null;
75
135
  }
76
136
 
@@ -89,13 +149,21 @@ export const SAVED_FILENAME_FALLBACK = 'download';
89
149
 
90
150
  /**
91
151
  * The name a download is saved under: the file's own name by the saved-name
92
- * rule (toSavedFilename), or SAVED_FILENAME_FALLBACK when it has none.
152
+ * rule (toSavedFilename), or SAVED_FILENAME_FALLBACK when it has none, or one
153
+ * of only dots or spaces, invisible characters among them
154
+ * (isOnlyDotsOrSpaces): such a name, completed for its type
155
+ * (./media-type-node.js downloadFilename), would be an extension alone, which
156
+ * a browser saves without its leading dots (`...` completed for a text file
157
+ * is `.txt`, which saves as `txt`, and `..<U+034F>` is `..<U+034F>.txt`,
158
+ * which saves as `<U+034F>.txt` and shows as `.txt`).
93
159
  *
94
160
  * @param {string|null|undefined} name
95
161
  * @returns {string}
96
162
  */
97
163
  export function savedFilename(name) {
98
- return typeof name === 'string' && name !== '' ? toSavedFilename(name) : SAVED_FILENAME_FALLBACK;
164
+ return typeof name === 'string' && name !== '' && !isOnlyDotsOrSpaces(name)
165
+ ? toSavedFilename(name)
166
+ : SAVED_FILENAME_FALLBACK;
99
167
  }
100
168
 
101
169
  /**
@@ -103,11 +171,18 @@ export function savedFilename(name) {
103
171
  * that cannot import an ES module (the x.sv reveal page): it declares
104
172
  * `savedFilename` and everything it reads at the script's top level, built
105
173
  * from the functions and constants above, so the page runs this rule, not a
106
- * copy. A new module-scope binding the rule reads must be added here.
174
+ * copy. A new module-scope binding the rule reads must be added here. Marked
175
+ * pure so a bundle that never reads it (the console's, the help desk portal's)
176
+ * drops it.
107
177
  */
108
- export const SAVED_FILENAME_SCRIPT = [
178
+ export const SAVED_FILENAME_SCRIPT = /* @__PURE__ */ [
109
179
  `var UNSAFE_FILENAME_CHARACTERS = ${UNSAFE_FILENAME_CHARACTERS};`,
180
+ `var DROPPED_TRAILING_CHARACTER = ${DROPPED_TRAILING_CHARACTER};`,
181
+ `var INVISIBLE_CHARACTERS = ${INVISIBLE_CHARACTERS};`,
110
182
  `var SAVED_FILENAME_FALLBACK = ${JSON.stringify(SAVED_FILENAME_FALLBACK)};`,
183
+ trimDroppedTrailing,
184
+ nameAsShown,
185
+ isOnlyDotsOrSpaces,
111
186
  toSavedFilename,
112
187
  savedFilename
113
188
  ].join('\n');
@@ -164,44 +239,11 @@ export function splitExtension(name) {
164
239
  }
165
240
 
166
241
  /**
167
- * A character a save drops from a name's end. Windows drops trailing dots and
168
- * spaces from a name it saves ("page.html." is saved as "page.html"); any
169
- * other trailing white space is dropped alike, so a name never hides the
170
- * extension a saved copy could open as.
171
- */
172
- const DROPPED_TRAILING_CHARACTER = /[\s.]/u;
173
-
174
- /**
175
- * `name` without the trailing dots and white space a save drops: "page.html."
176
- * and "page.html " are "page.html", "notes. ." is "notes", and a name of only
177
- * dots and white space is ''. lastExtension reads the extension in front of
178
- * them, and Forge completes a saved name after them (./media-type-node.js
179
- * withMediaTypeExtension: "notes." under text/plain saves as "notes.txt").
180
- *
181
- * @param {string} name
182
- * @returns {string}
183
- */
184
- export function trimDroppedTrailing(name) {
185
- let end = name.length;
186
- while (end > 0 && DROPPED_TRAILING_CHARACTER.test(name[end - 1])) end -= 1;
187
- return name.slice(0, end);
188
- }
189
-
190
- /**
191
- * Invisible characters (Unicode's Default_Ignorable_Code_Point): the joiners,
192
- * variation selectors, tags and bidirectional controls, which display as
193
- * nothing, and the Hangul fillers, which display as blank space. None shows
194
- * in a name, and a save keeps several (`Invoice.pdf<U+034F>` saves as itself
195
- * in Chromium and Firefox, and shows as `Invoice.pdf`).
196
- */
197
- const INVISIBLE_CHARACTERS = /\p{Default_Ignorable_Code_Point}/gu;
198
-
199
- /**
200
- * The extension `name` shows, lowercase and without its dot: what follows its
201
- * last dot once its invisible characters are read past and the
202
- * trailing dots and white space a save drops are trimmed
203
- * (trimDroppedTrailing). It is the extension a saved copy opens as wherever
204
- * the name holds no invisible character: "invoice.note.html" and
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
205
247
  * "page.html." open as 'html', "logs.tar.gz" as 'gz', ".html" as 'html'
206
248
  * (Windows reads a leading dot's extension), and a name with no dot as ''.
207
249
  * "Invoice.pdf<U+034F>" shows 'pdf', so no rule completes it with a second
@@ -220,9 +262,9 @@ const INVISIBLE_CHARACTERS = /\p{Default_Ignorable_Code_Point}/gu;
220
262
  * @returns {string}
221
263
  */
222
264
  export function lastExtension(name) {
223
- const kept = trimDroppedTrailing(name.replace(INVISIBLE_CHARACTERS, ''));
224
- const dot = kept.lastIndexOf('.');
225
- return dot === -1 ? '' : kept.slice(dot + 1).toLowerCase();
265
+ const shown = nameAsShown(name);
266
+ const dot = shown.lastIndexOf('.');
267
+ return dot === -1 ? '' : shown.slice(dot + 1).toLowerCase();
226
268
  }
227
269
 
228
270
  /**
@@ -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
  }
@@ -55,6 +55,7 @@ export type IngotsWireContract = [
55
55
  keyof Ingot,
56
56
  | 'ingot_id'
57
57
  | 'name'
58
+ | 'download_filename'
58
59
  | 'content_type'
59
60
  | 'size_bytes'
60
61
  | 'status'
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> {