@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/dist/app-sdk/transfer-retry.d.ts +25 -20
- package/dist/app-sdk/transfer-retry.js +62 -32
- package/dist/app-sdk/transfer-retry.js.map +1 -1
- package/dist/app-sdk/upload-publication.d.ts +31 -5
- package/dist/app-sdk/upload-publication.js +31 -5
- package/dist/app-sdk/upload-publication.js.map +1 -1
- package/dist/errors.d.ts +18 -7
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/tus.d.ts +25 -19
- package/dist/tus.js +39 -26
- package/dist/tus.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/app-sdk/transfer-retry.js +63 -31
- package/src/app-sdk/upload-publication.js +34 -5
- package/src/errors.ts +19 -7
- package/src/tus.ts +45 -26
- package/src/types.ts +2 -2
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 {
|
|
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
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
994
|
-
* through untouched: the refusal Core decided is
|
|
995
|
-
* words as on the XHR path, a 402 becomes the
|
|
996
|
-
* throws, a status `isSessionGone` recognises marks
|
|
997
|
-
* as HEAD would, and any other status keeps its
|
|
998
|
-
* (a 409 during finalize is a
|
|
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
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1112
|
-
*
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1118
|
-
*
|
|
1119
|
-
*
|
|
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
|
|
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
|
|
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
|
*/
|