@sparkvault/sdk-mobile 7.2.4 → 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.
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
  */