@sparkvault/sdk-mobile 8.0.6 → 9.0.0
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/README.md +84 -115
- package/dist/app-sdk/ids.d.ts +14 -0
- package/dist/app-sdk/ids.js +24 -4
- package/dist/app-sdk/ids.js.map +1 -1
- package/dist/app-sdk/platform-domains.d.ts +22 -5
- package/dist/app-sdk/platform-domains.js +28 -9
- package/dist/app-sdk/platform-domains.js.map +1 -1
- package/dist/app-sdk/upload-publication.d.ts +20 -6
- package/dist/app-sdk/upload-publication.js +20 -6
- package/dist/app-sdk/upload-publication.js.map +1 -1
- package/dist/config.d.ts +6 -4
- package/dist/config.js.map +1 -1
- package/dist/notify.d.ts +15 -11
- package/dist/notify.js +6 -4
- package/dist/notify.js.map +1 -1
- package/dist/notify.test-d.d.ts +12 -7
- package/dist/notify.test-d.js +12 -7
- package/dist/notify.test-d.js.map +1 -1
- package/dist/tus.d.ts +19 -16
- package/dist/tus.js +26 -22
- package/dist/tus.js.map +1 -1
- package/dist/types.d.ts +25 -12
- package/package.json +1 -1
- package/src/app-sdk/ids.js +28 -4
- package/src/app-sdk/platform-domains.js +30 -9
- package/src/app-sdk/upload-publication.js +21 -6
- package/src/config.ts +6 -4
- package/src/notify.test-d.ts +16 -10
- package/src/notify.ts +15 -11
- package/src/tus.ts +38 -32
- package/src/types.ts +25 -12
package/src/app-sdk/ids.js
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
*
|
|
19
19
|
* - `isResourceIdOf(kind, value)`: an id of that kind.
|
|
20
20
|
* - `isResourceId(value)`: an id of any kind, for a check that takes several.
|
|
21
|
+
* - `resourceIdPattern(kind)`: the same grammar as a regular-expression
|
|
22
|
+
* source, for a JSON Schema `pattern` beside `maxLength:
|
|
23
|
+
* RESOURCE_ID_MAX_LENGTH`, so a route schema and a check never disagree.
|
|
21
24
|
*
|
|
22
25
|
* Browser-safe and import-free: sdk-js bundles it, sdk-mobile mirrors it, and
|
|
23
26
|
* the apps, the console and the mobile app import it.
|
|
@@ -50,7 +53,30 @@ export const RESOURCE_ID_PREFIXES = Object.freeze({
|
|
|
50
53
|
/** The longest id, prefix included. */
|
|
51
54
|
export const RESOURCE_ID_MAX_LENGTH = 128;
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
/** The body every id carries after its prefix's underscore: the path-safe alphabet. */
|
|
57
|
+
const ID_BODY_SOURCE = '[A-Za-z0-9_-]+';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The pattern an id of the given kind matches, as a regular-expression source
|
|
61
|
+
* string: its prefix, '_' and a body of the path-safe alphabet. A JSON Schema
|
|
62
|
+
* reads it as `pattern`, with `maxLength: RESOURCE_ID_MAX_LENGTH`.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} kind - A key of RESOURCE_ID_PREFIXES
|
|
65
|
+
* @returns {string}
|
|
66
|
+
* @throws {TypeError} for a kind the grammar does not name: a misspelled kind
|
|
67
|
+
* would otherwise refuse every id without saying why
|
|
68
|
+
*/
|
|
69
|
+
export function resourceIdPattern(kind) {
|
|
70
|
+
if (!Object.hasOwn(RESOURCE_ID_PREFIXES, kind)) {
|
|
71
|
+
throw new TypeError(`No resource kind '${kind}'`);
|
|
72
|
+
}
|
|
73
|
+
return `^${RESOURCE_ID_PREFIXES[kind]}_${ID_BODY_SOURCE}$`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Each kind's pattern, compiled once. */
|
|
77
|
+
const ID_PATTERNS = Object.freeze(Object.fromEntries(
|
|
78
|
+
Object.keys(RESOURCE_ID_PREFIXES).map((kind) => [kind, new RegExp(resourceIdPattern(kind))])
|
|
79
|
+
));
|
|
54
80
|
|
|
55
81
|
/**
|
|
56
82
|
* Whether a value is an id of the given kind.
|
|
@@ -65,11 +91,9 @@ export function isResourceIdOf(kind, value) {
|
|
|
65
91
|
if (!Object.hasOwn(RESOURCE_ID_PREFIXES, kind)) {
|
|
66
92
|
throw new TypeError(`No resource kind '${kind}'`);
|
|
67
93
|
}
|
|
68
|
-
const prefix = `${RESOURCE_ID_PREFIXES[kind]}_`;
|
|
69
94
|
return typeof value === 'string'
|
|
70
95
|
&& value.length <= RESOURCE_ID_MAX_LENGTH
|
|
71
|
-
&&
|
|
72
|
-
&& ID_BODY.test(value.slice(prefix.length));
|
|
96
|
+
&& ID_PATTERNS[kind].test(value);
|
|
73
97
|
}
|
|
74
98
|
|
|
75
99
|
const KINDS = Object.freeze(Object.keys(RESOURCE_ID_PREFIXES));
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Keep platform domain decisions centralized: CSP, redirect safety, custom
|
|
9
9
|
* domain reservation, and Identity postMessage trust all read this registry.
|
|
10
10
|
* Trust follows the hosts the platform owns (isSparkVaultOwnedHostname);
|
|
11
|
-
* reservation covers those and
|
|
11
|
+
* reservation covers those and each product mail domain's subtree
|
|
12
12
|
* (isSparkVaultReservedDomain), whose hosts are SparkVault's to hand out but
|
|
13
13
|
* never trusted.
|
|
14
14
|
*/
|
|
@@ -42,12 +42,32 @@ export const SPARKVAULT_FILES_HOST = 'files.sv';
|
|
|
42
42
|
*/
|
|
43
43
|
export const SPARKVAULT_HELP_DESK_DOMAIN = 'help.sv';
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Notify's mail domain: each organization's Notify mail goes from a host under
|
|
47
|
+
* it, as its help desk's goes from one under the help-desk domain. On the web
|
|
48
|
+
* its apex and www redirect to the Notify product page (the send.sv Worker,
|
|
49
|
+
* infra/cloudflare/send). Like the help-desk domain, its whole subtree is
|
|
50
|
+
* reserved and none of its hosts is owned.
|
|
51
|
+
*/
|
|
52
|
+
export const SPARKVAULT_NOTIFY_SEND_DOMAIN = 'send.sv';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The product mail domains: one SES identity each, under which every
|
|
56
|
+
* organization's address for that product is its own host
|
|
57
|
+
* (@sparkvault/app-sdk/mail-products). Every name in each one's subtree is
|
|
58
|
+
* reserved, so no organization claims another's address host as its own
|
|
59
|
+
* domain, and none is owned.
|
|
60
|
+
*/
|
|
61
|
+
export const SPARKVAULT_PRODUCT_MAIL_DOMAINS = Object.freeze([
|
|
62
|
+
SPARKVAULT_HELP_DESK_DOMAIN,
|
|
63
|
+
SPARKVAULT_NOTIFY_SEND_DOMAIN
|
|
64
|
+
]);
|
|
65
|
+
|
|
45
66
|
export const SPARKVAULT_PLATFORM_SV_HOSTS = Object.freeze([
|
|
46
67
|
SPARKVAULT_AUTH_HOST,
|
|
47
68
|
SPARKVAULT_LINKS_HOST,
|
|
48
69
|
SPARKVAULT_FILES_HOST,
|
|
49
70
|
'file.sv',
|
|
50
|
-
'send.sv',
|
|
51
71
|
'spark.sv',
|
|
52
72
|
'by.sv',
|
|
53
73
|
'at.sv',
|
|
@@ -94,9 +114,9 @@ function isSparkVaultPlatformSvHost(hostname) {
|
|
|
94
114
|
return SPARKVAULT_PLATFORM_SV_HOSTS.includes(normalizeHostname(hostname));
|
|
95
115
|
}
|
|
96
116
|
|
|
97
|
-
function
|
|
117
|
+
function isProductMailDomainOrSubdomain(hostname) {
|
|
98
118
|
const normalized = normalizeHostname(hostname);
|
|
99
|
-
return normalized ===
|
|
119
|
+
return SPARKVAULT_PRODUCT_MAIL_DOMAINS.some((domain) => normalized === domain || normalized.endsWith(`.${domain}`));
|
|
100
120
|
}
|
|
101
121
|
|
|
102
122
|
export function isSparkVaultOwnedHostname(hostname) {
|
|
@@ -105,13 +125,14 @@ export function isSparkVaultOwnedHostname(hostname) {
|
|
|
105
125
|
|
|
106
126
|
/**
|
|
107
127
|
* Whether a domain is SparkVault's, so no organization may claim it as its
|
|
108
|
-
* own: every host the platform owns, and
|
|
109
|
-
* subtree. The
|
|
110
|
-
*
|
|
111
|
-
* is trusted as a platform
|
|
128
|
+
* own: every host the platform owns, and each product mail domain with its
|
|
129
|
+
* whole subtree. The hosts under a product mail domain are SparkVault's
|
|
130
|
+
* tenants' addresses, and the help-desk domain is also every custom
|
|
131
|
+
* help-desk domain's CNAME target, yet none of them is trusted as a platform
|
|
132
|
+
* host.
|
|
112
133
|
*/
|
|
113
134
|
export function isSparkVaultReservedDomain(hostname) {
|
|
114
|
-
return isSparkVaultOwnedHostname(hostname) ||
|
|
135
|
+
return isSparkVaultOwnedHostname(hostname) || isProductMailDomainOrSubdomain(hostname);
|
|
115
136
|
}
|
|
116
137
|
|
|
117
138
|
export function sparkVaultPlatformSvOrigins() {
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The upload publication contract between Forge and Core's activation, and
|
|
7
|
-
* the facts of a transfer
|
|
8
|
-
* publication
|
|
9
|
-
* names),
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* too: the upload id its delete is
|
|
7
|
+
* the facts of a transfer both services spell: its token's shape and the
|
|
8
|
+
* publication the token is bound to (a content version, and the one an ingot
|
|
9
|
+
* row names), its charge's ledger reference and category, Core's revocation
|
|
10
|
+
* of an upload's token, and the refusals of Core's a transfer's answer names
|
|
11
|
+
* (the header, and the lock of a vault scheduled for deletion). Every client
|
|
12
|
+
* ends an upload it gives up by one rule here too: the upload id its delete is
|
|
13
|
+
* conditioned on (givenUpUploadId).
|
|
13
14
|
*
|
|
14
15
|
* Forge stamps UPLOAD_PUBLICATION_PROTOCOL on every upload session it creates
|
|
15
16
|
* and on the final state it hands Core's activation (POST
|
|
@@ -130,6 +131,20 @@ export function uploadTransferReference(istk) {
|
|
|
130
131
|
return `forge_ingot_transfer_upload_${istk.slice(0, TRANSFER_REFERENCE_ISTK_CHARS)}`;
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
/**
|
|
135
|
+
* The usage-ledger category, and type, of a Forge transfer's charge, by
|
|
136
|
+
* direction. Every charge of one upload (Core's activation, Core's charge of
|
|
137
|
+
* an upload that never publishes, Forge's cancel) lands under the one
|
|
138
|
+
* reference uploadTransferReference names, so each spells its category from
|
|
139
|
+
* here, and the console counts both directions as the bandwidth the ledger
|
|
140
|
+
* measures. Each day's usage summary is keyed by category, so a category's
|
|
141
|
+
* spelling is the key its rows sum under.
|
|
142
|
+
*/
|
|
143
|
+
export const TRANSFER_CHARGE_CATEGORIES = Object.freeze({
|
|
144
|
+
UPLOAD: 'Ingot Transfer - Forge Encryption',
|
|
145
|
+
DOWNLOAD: 'Ingot Transfer - Forge Decryption'
|
|
146
|
+
});
|
|
147
|
+
|
|
133
148
|
/**
|
|
134
149
|
* The codes Core's activation refuses an upload with, which Forge's refusal
|
|
135
150
|
* map reads (the status is Core's):
|
package/src/config.ts
CHANGED
|
@@ -52,10 +52,12 @@ export interface SparkVaultMobileConfig {
|
|
|
52
52
|
*/
|
|
53
53
|
backgroundTransfer?: MobileBackgroundTransfer;
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
55
|
+
* Whole-file PATCH adapter (one request, no progress, no abort; see
|
|
56
|
+
* MobileBackgroundUploader on backing it with a background session), the
|
|
57
|
+
* fallback when no `backgroundTransfer` engine is configured. Used only by
|
|
58
|
+
* uploads that ask for it (`transport: 'background'`) and fit one chunk;
|
|
59
|
+
* every other upload, and every upload when this is unset, streams over
|
|
60
|
+
* XHR.
|
|
59
61
|
*/
|
|
60
62
|
backgroundUploader?: MobileBackgroundUploader;
|
|
61
63
|
/**
|
package/src/notify.test-d.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Notify wire-contract assertions — COMPILE-TIME ONLY.
|
|
3
3
|
*
|
|
4
|
-
* `NotificationRow` has no runtime, so a unit test can never
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* push and again on every SDK publish)
|
|
8
|
-
*
|
|
4
|
+
* `NotificationRow` has no runtime, so a unit test can never see how a field is
|
|
5
|
+
* typed: the transpiler strips it and every assertion passes. This file is the
|
|
6
|
+
* gate for that instead — `tsc --noEmit` (`pnpm typecheck`, which CI runs on
|
|
7
|
+
* every push and again on every SDK publish) refuses to compile the moment a
|
|
8
|
+
* member below stops being typed as stated there; the statements mirror
|
|
9
|
+
* `apps/api/src/notify/inbox.js` (`projectRow`) by hand.
|
|
10
|
+
*
|
|
11
|
+
* WHICH fields the row carries is gated across packages rather than here:
|
|
12
|
+
* tests/notify-contract.test.ts holds `NotificationRow` to
|
|
13
|
+
* `NOTIFY_RESPONSE_FIELDS.inboxRow` (`@sparkvault/app-sdk/notify-contract`),
|
|
14
|
+
* the list the Core API's suite holds its projection to.
|
|
9
15
|
*
|
|
10
16
|
* It is deliberately NOT a `*.test.ts`: that suffix is excluded from `tsconfig`,
|
|
11
17
|
* which would put these assertions exactly where the compiler cannot see them.
|
|
12
18
|
*
|
|
13
19
|
* The row shape is shared verbatim with `@sparkvault/sdk-js`, whose own contract
|
|
14
|
-
* file asserts the same four members
|
|
15
|
-
* server source is `apps/api/src/notify/inbox.js` (`projectRow`).
|
|
20
|
+
* file asserts the same four members, so both move together.
|
|
16
21
|
*/
|
|
17
22
|
|
|
18
23
|
import type { NotificationRow } from './notify.js';
|
|
@@ -34,10 +39,11 @@ export type NotifyWireContract = [
|
|
|
34
39
|
// it optional would let the app skip the "no longer available" branch and fall
|
|
35
40
|
// through to a reveal that opens nothing.
|
|
36
41
|
Assert<Equals<NotificationRow['recalled'], boolean>>,
|
|
37
|
-
// `locked` is
|
|
42
|
+
// `locked` is whether the row carries its pointer — always present.
|
|
38
43
|
Assert<Equals<NotificationRow['locked'], boolean>>,
|
|
39
|
-
// The pointer is
|
|
40
|
-
// it is optional in both directions and must be guarded
|
|
44
|
+
// The pointer is carried only while its grant still opens and is absent on a
|
|
45
|
+
// cleartext row, so it is optional in both directions and must be guarded
|
|
46
|
+
// before use.
|
|
41
47
|
Assert<Equals<NotificationRow['sparklink_code'], string | undefined>>,
|
|
42
48
|
// The URL the pointer opens travels with it: absent exactly when the pointer is.
|
|
43
49
|
Assert<Equals<NotificationRow['pointer_url'], string | undefined>>,
|
package/src/notify.ts
CHANGED
|
@@ -34,9 +34,11 @@ export interface NotificationRow {
|
|
|
34
34
|
archived_at: number | null;
|
|
35
35
|
/**
|
|
36
36
|
* The grant to open. Present only while a live reveal stands behind it — a
|
|
37
|
-
* SEALED (secure) send
|
|
38
|
-
*
|
|
39
|
-
*
|
|
37
|
+
* SEALED (secure) send whose grant still opens: not yet opened (on a send that
|
|
38
|
+
* asks for an answer, not yet answered), not expired, not gone and not
|
|
39
|
+
* recalled. A cleartext send delivers its content inline in the channel and
|
|
40
|
+
* mints no grant; once the reveal no longer opens, the pointer is withheld
|
|
41
|
+
* rather than echoed.
|
|
40
42
|
*/
|
|
41
43
|
sparklink_code?: string;
|
|
42
44
|
/**
|
|
@@ -47,9 +49,10 @@ export interface NotificationRow {
|
|
|
47
49
|
pointer_url?: string;
|
|
48
50
|
/**
|
|
49
51
|
* True only when there is a secure part left to reveal — exactly when
|
|
50
|
-
* `sparklink_code` is present. `false` does NOT mean "cleartext row": a
|
|
51
|
-
* row
|
|
52
|
-
*
|
|
52
|
+
* `sparklink_code` is present. `false` does NOT mean "cleartext row": a sealed
|
|
53
|
+
* row whose reveal no longer opens (opened, answered, expired or gone) is
|
|
54
|
+
* unlocked too, and so is a recalled one, with nothing behind it. Branch on
|
|
55
|
+
* `recalled` before treating an unlocked row as plain text.
|
|
53
56
|
*/
|
|
54
57
|
locked: boolean;
|
|
55
58
|
/**
|
|
@@ -58,7 +61,6 @@ export interface NotificationRow {
|
|
|
58
61
|
* tap-to-reveal that opens nothing.
|
|
59
62
|
*/
|
|
60
63
|
recalled: boolean;
|
|
61
|
-
thread_id?: string;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
export interface ListNotificationsOptions {
|
|
@@ -143,10 +145,12 @@ export interface RegisterDeviceResponse {
|
|
|
143
145
|
const MARK_ALL_MAX_PAGES = 100;
|
|
144
146
|
|
|
145
147
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
148
|
+
* SparkVault's first-party Notify surface: the metadata-only inbox of a user
|
|
149
|
+
* signed in to SparkVault itself, holding the notifications SparkVault delivered
|
|
150
|
+
* to them `in_app`, plus this device's push registration. The recipient is
|
|
151
|
+
* ALWAYS derived from the session on the server — no method takes a
|
|
152
|
+
* `recipient_id`, and any account/recipient a caller might try to supply is
|
|
153
|
+
* ignored.
|
|
150
154
|
*/
|
|
151
155
|
export class MobileNotifyClient {
|
|
152
156
|
private readonly http: MobileHttpClient;
|
package/src/tus.ts
CHANGED
|
@@ -104,19 +104,21 @@ export interface TusUploadFromUriOptions {
|
|
|
104
104
|
* Invoked whenever the session's expiry, as its latest answer named it,
|
|
105
105
|
* changes: Forge slides it forward with every committed chunk and names it
|
|
106
106
|
* on its answers (`Upload-Expires`). It is null (unknown) after an answer
|
|
107
|
-
* that named none, and from the hand-off of a request
|
|
108
|
-
*
|
|
109
|
-
* PATCH): either may have moved it unread. A caller
|
|
110
|
-
* session keeps its `expiresAt` current with this, so a
|
|
111
|
-
* expired (`isSessionExpired`) really is. A throw here
|
|
107
|
+
* that named none, and from the hand-off of a request JS cannot follow
|
|
108
|
+
* while it runs (the transfer engine's range, the single-chunk
|
|
109
|
+
* `backgroundUploader` PATCH): either may have moved it unread. A caller
|
|
110
|
+
* that persists the session keeps its `expiresAt` current with this, so a
|
|
111
|
+
* session it judges expired (`isSessionExpired`) really is. A throw here
|
|
112
|
+
* fails the upload.
|
|
112
113
|
*/
|
|
113
114
|
onSessionExpiry?: (expiresAt: number | null) => void;
|
|
114
115
|
/**
|
|
115
|
-
* `background`
|
|
116
|
-
*
|
|
117
|
-
* range of any file, else
|
|
118
|
-
* progress, no abort
|
|
119
|
-
*
|
|
116
|
+
* `background` asks for a transfer that survives suspension and rides the
|
|
117
|
+
* best engine the app provides: the OS transfer engine
|
|
118
|
+
* (`backgroundTransfer`) for the whole remaining range of any file, else
|
|
119
|
+
* the single-chunk `backgroundUploader` (no progress, no abort; whether it
|
|
120
|
+
* outlives a suspension is the uploader's) for a file that fits one chunk,
|
|
121
|
+
* else XHR. Default `foreground`: every chunk goes over XHR.
|
|
120
122
|
*/
|
|
121
123
|
transport?: UploadTransport;
|
|
122
124
|
/**
|
|
@@ -537,9 +539,11 @@ class SessionExpiry {
|
|
|
537
539
|
}
|
|
538
540
|
|
|
539
541
|
/**
|
|
540
|
-
* A request
|
|
541
|
-
*
|
|
542
|
-
* possibly while the app is not
|
|
542
|
+
* A request JS cannot follow while it runs is about to leave: the OS
|
|
543
|
+
* transfer engine's range, whose chunks commit (each sliding the expiry)
|
|
544
|
+
* with answers this upload never reads, possibly while the app is not
|
|
545
|
+
* running; or the single-chunk `backgroundUploader` PATCH, which reports
|
|
546
|
+
* nothing until it answers.
|
|
543
547
|
*/
|
|
544
548
|
forget(): void {
|
|
545
549
|
this.become(null);
|
|
@@ -958,11 +962,12 @@ function sendChunkOverXhr(
|
|
|
958
962
|
}
|
|
959
963
|
|
|
960
964
|
/**
|
|
961
|
-
* PATCH a whole file as the session's only chunk
|
|
962
|
-
*
|
|
963
|
-
*
|
|
964
|
-
*
|
|
965
|
-
* is read exactly like the
|
|
965
|
+
* PATCH a whole file as the session's only chunk through the app's
|
|
966
|
+
* single-request uploader (`backgroundUploader`) and resolve with Forge's
|
|
967
|
+
* answer, or with no answer when the adapter got none. The request reports
|
|
968
|
+
* no progress and takes no abort; whether it outlives a suspension is the
|
|
969
|
+
* uploader's (MobileBackgroundUploader). Its answer is read exactly like the
|
|
970
|
+
* XHR path's, so callers see one error taxonomy.
|
|
966
971
|
*/
|
|
967
972
|
async function sendWholeFileInBackground(
|
|
968
973
|
uploader: MobileBackgroundUploader,
|
|
@@ -1471,14 +1476,14 @@ export class MobileTusUploader {
|
|
|
1471
1476
|
private async sendChunk(transfer: TusTransfer, offset: number, chunks: ChunkSource): Promise<TransferAnswer> {
|
|
1472
1477
|
const backgroundUploader = chunks.transport === 'background' ? this.config.backgroundUploader : undefined;
|
|
1473
1478
|
if (backgroundUploader && this.fitsOneBackgroundRequest(offset, transfer.fileSize, transfer.chunkSize)) {
|
|
1474
|
-
// The
|
|
1475
|
-
// flight cannot stop it
|
|
1476
|
-
//
|
|
1477
|
-
//
|
|
1478
|
-
//
|
|
1479
|
-
//
|
|
1480
|
-
//
|
|
1481
|
-
//
|
|
1479
|
+
// The uploader takes no abort, so an abort that fires while this
|
|
1480
|
+
// request is in flight cannot stop it. It only ever carries a whole
|
|
1481
|
+
// single-chunk file, so a 2xx here means the transfer is complete: the
|
|
1482
|
+
// loop ends and the upload finishes normally (the caller verifies the
|
|
1483
|
+
// ingot), because a finished upload must never be reported as
|
|
1484
|
+
// cancelled, and a DELETE now would drop bytes Forge has already
|
|
1485
|
+
// finalized. Only an answer that leaves bytes missing reaches the abort
|
|
1486
|
+
// check before the next request.
|
|
1482
1487
|
transfer.expiry.forget();
|
|
1483
1488
|
return sendWholeFileInBackground(backgroundUploader, transfer, chunks.uri, offset);
|
|
1484
1489
|
}
|
|
@@ -1669,12 +1674,13 @@ export class MobileTusUploader {
|
|
|
1669
1674
|
}
|
|
1670
1675
|
|
|
1671
1676
|
/**
|
|
1672
|
-
* Whether the remaining transfer is ONE PATCH the
|
|
1673
|
-
* send: nothing uploaded yet and the whole file
|
|
1674
|
-
*
|
|
1675
|
-
* not exactly `X-Chunk-Size`, so a multi-chunk
|
|
1676
|
-
* request, and a partially uploaded session would
|
|
1677
|
-
* A zero-byte file stays on the XHR path (it
|
|
1677
|
+
* Whether the remaining transfer is ONE PATCH the single-request uploader
|
|
1678
|
+
* (`backgroundUploader`) can send: nothing uploaded yet and the whole file
|
|
1679
|
+
* inside a single chunk. The uploader sends whole files and Forge rejects
|
|
1680
|
+
* any non-final chunk that is not exactly `X-Chunk-Size`, so a multi-chunk
|
|
1681
|
+
* file has no legal single request, and a partially uploaded session would
|
|
1682
|
+
* resend bytes Forge holds. A zero-byte file stays on the XHR path (it
|
|
1683
|
+
* sends no PATCH at all there).
|
|
1678
1684
|
*/
|
|
1679
1685
|
private fitsOneBackgroundRequest(offset: number, fileSize: number, chunkSize: number): boolean {
|
|
1680
1686
|
return offset === 0 && fileSize > 0 && fileSize <= chunkSize;
|
package/src/types.ts
CHANGED
|
@@ -167,8 +167,10 @@ export interface ResendInviteResponse {
|
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
169
|
* Identity attempts usage. `attempts_cap` is the EFFECTIVE monthly allowance:
|
|
170
|
-
* the
|
|
171
|
-
* `attempts_cap_base` is
|
|
170
|
+
* the tier the period paid for, or the trial allowance while a trial is live.
|
|
171
|
+
* `attempts_cap_base` is the tier bought, as the subscription renews it: 0 on
|
|
172
|
+
* a trial, and the lower tier (0 for a cancel) while a decrease waits for the
|
|
173
|
+
* renewal, the period keeping the tier it paid for until then.
|
|
172
174
|
*/
|
|
173
175
|
export interface SubscriptionIdentityStatus {
|
|
174
176
|
attempts_cap: number | null;
|
|
@@ -226,13 +228,22 @@ export interface SparkVaultSubscription {
|
|
|
226
228
|
prepaid: boolean;
|
|
227
229
|
};
|
|
228
230
|
blocks: {
|
|
229
|
-
/** Effective capacity blocks
|
|
231
|
+
/** Effective capacity blocks: those this subscription holds for the
|
|
232
|
+
* period plus the add-on subscriptions' while a base Full License exists. */
|
|
230
233
|
storage: number;
|
|
231
234
|
bandwidth: number;
|
|
232
|
-
/** Blocks THIS subscription
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
/** Blocks THIS subscription renews with, as the subscription renews them. */
|
|
236
|
+
storage_base: number;
|
|
237
|
+
bandwidth_base: number;
|
|
238
|
+
/** Bandwidth blocks this subscription's current period paid for: above
|
|
239
|
+
* `bandwidth_base` while a dropped block waits for the renewal, the pool
|
|
240
|
+
* holding them until then. */
|
|
241
|
+
bandwidth_paid: number;
|
|
242
|
+
/** Blocks the account's capacity add-on subscriptions hold (bought on any
|
|
243
|
+
* rail, the App Store and Google Play among them): the tier a store's
|
|
244
|
+
* add-on sheet owns. */
|
|
245
|
+
storage_addon: number;
|
|
246
|
+
bandwidth_addon: number;
|
|
236
247
|
};
|
|
237
248
|
pools: SubscriptionPools;
|
|
238
249
|
identity: SubscriptionIdentityStatus;
|
|
@@ -999,10 +1010,12 @@ export interface IngotUploadSession extends TusSessionInfo {
|
|
|
999
1010
|
* `background` asks for the transfer to survive the app being suspended, and
|
|
1000
1011
|
* resolves to the best engine the app provides, in order: the OS transfer
|
|
1001
1012
|
* engine (`backgroundTransfer`: any file size, any offset, progress and
|
|
1002
|
-
* abort, chunks chained natively), else the
|
|
1003
|
-
* (`backgroundUploader`: only a file that fits one
|
|
1004
|
-
*
|
|
1005
|
-
*
|
|
1013
|
+
* abort, chunks chained natively while the app is suspended), else the
|
|
1014
|
+
* single-request uploader (`backgroundUploader`: only a file that fits one
|
|
1015
|
+
* chunk, sent as one PATCH with no progress and no abort; whether it
|
|
1016
|
+
* outlives a suspension is the uploader's, see MobileBackgroundUploader),
|
|
1017
|
+
* else plain XHR. The upload semantics are the same on every engine; only
|
|
1018
|
+
* what survives a suspension differs.
|
|
1006
1019
|
*/
|
|
1007
1020
|
export type UploadTransport = 'foreground' | 'background';
|
|
1008
1021
|
|
|
@@ -1057,7 +1070,7 @@ export interface MobileBackgroundTransfer {
|
|
|
1057
1070
|
cancel(uploadUrl: string): Promise<void>;
|
|
1058
1071
|
}
|
|
1059
1072
|
|
|
1060
|
-
/** Network policy an upload carries into the OS transfer; ignored by the XHR paths (JS gates those). Defaults: both true. */
|
|
1073
|
+
/** Network policy an upload carries into the OS transfer engine; ignored by the XHR and single-request paths (JS gates those). Defaults: both true. */
|
|
1061
1074
|
export interface UploadTransferPolicy {
|
|
1062
1075
|
allowsCellularAccess?: boolean;
|
|
1063
1076
|
allowsConstrainedNetworkAccess?: boolean;
|