@sparkvault/sdk-mobile 9.0.10 → 10.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/src/index.ts CHANGED
@@ -98,7 +98,6 @@ export {
98
98
  MobileUsersClient,
99
99
  } from './users.js';
100
100
  export {
101
- isSessionExpired,
102
101
  isSessionGone,
103
102
  MobileTusUploader,
104
103
  parseForgeUrl,
package/src/ingots.ts CHANGED
@@ -122,12 +122,6 @@ export interface UploadFromUriOptions extends UploadOptions {
122
122
  * attempt or a relaunch instead of re-sending bytes Forge already holds.
123
123
  */
124
124
  onSessionCreated?: (session: IngotUploadSession) => void;
125
- /**
126
- * Invoked whenever the session's expiry changes (see
127
- * `TusUploadFromUriOptions.onSessionExpiry`): a caller that persists the
128
- * session keeps its `expiresAt` current with it.
129
- */
130
- onSessionExpiry?: (expiresAt: number | null) => void;
131
125
  /** See `UploadTransport`; default `foreground`. */
132
126
  transport?: UploadTransport;
133
127
  /** Network policy for the OS transfer engine; see `UploadTransferPolicy`. Default: both allowed. */
@@ -197,13 +191,11 @@ export interface ResumeUploadOptions {
197
191
  fileSize: number;
198
192
  name: string;
199
193
  /**
200
- * The persisted tus session handed to `onSessionCreated`, with the expiry
201
- * the caller keeps for it (`onSessionExpiry`): a session past it is
202
- * refused as `sessionLost` before any request.
194
+ * The persisted tus session handed to `onSessionCreated`. Forge is asked
195
+ * (HEAD) whether it still holds it, whatever its age: a session it no
196
+ * longer has is `sessionLost`.
203
197
  */
204
- session: { uploadUrl: string; istk: string; expiresAt?: number | null };
205
- /** See `UploadFromUriOptions.onSessionExpiry`. */
206
- onSessionExpiry?: (expiresAt: number | null) => void;
198
+ session: { uploadUrl: string; istk: string };
207
199
  /** See `UploadTransport`; default `foreground`. */
208
200
  transport?: UploadTransport;
209
201
  /** Network policy for the OS transfer engine; see `UploadTransferPolicy`. Default: both allowed. */
@@ -245,10 +237,12 @@ export interface DownloadToFileResult {
245
237
  /** A vault search; every option left out narrows nothing. */
246
238
  export interface SearchIngotsOptions {
247
239
  /**
248
- * The ingot's whole file name, matched ignoring letter case, accent
249
- * composition and Unicode compatibility forms (`Straße` matches `STRASSE`):
250
- * never a prefix, a substring or a fuzzy match. A name no ingot can hold is
251
- * refused (400).
240
+ * A part of the ingot's file name, matched ignoring letter case, accents
241
+ * and Unicode compatibility forms (`resume` matches `Résumé.pdf`, `strasse`
242
+ * matches `Straße.txt`); a whole name matches too. Results come in creation
243
+ * order, newest first unless `sort_order` is `asc`, and a page can hold none
244
+ * while `next_cursor` is set: follow it. Text no name can hold is refused
245
+ * (400).
252
246
  */
253
247
  q?: string;
254
248
  /**
@@ -463,14 +457,6 @@ function uploadIdOf(uploadUrl: string): string {
463
457
  }
464
458
 
465
459
  export class MobileIngotsClient {
466
- // Server-side finalization (encryption) of a just-uploaded ingot runs
467
- // asynchronously and scales with file size, so a large video can sit in
468
- // `processing` for well over a minute. Poll with backoff up to a generous
469
- // budget for a terminal state; the initial/max/budget are wall-clock, not a
470
- // fixed attempt count, so the wait tracks real finalization time.
471
- private static readonly INGOT_STATUS_POLL_INITIAL_MS = 1000;
472
- private static readonly INGOT_STATUS_POLL_MAX_MS = 5000;
473
- private static readonly INGOT_STATUS_POLL_BUDGET_MS = 120000;
474
460
  private static readonly DOWNLOAD_MAX_ATTEMPTS = 3;
475
461
  private static readonly DOWNLOAD_RETRY_BASE_MS = 1000;
476
462
 
@@ -521,7 +507,6 @@ export class MobileIngotsClient {
521
507
  forgeUrl: init.forgeUrl,
522
508
  onSessionCreated: session =>
523
509
  options.onSessionCreated?.({ ...session, ingotId: init.ingotId, created, uploadId: uploadIdOf(session.uploadUrl) }),
524
- onSessionExpiry: options.onSessionExpiry,
525
510
  transport: options.transport,
526
511
  transferPolicy: options.transferPolicy,
527
512
  sourceAssetId: options.sourceAssetId,
@@ -543,8 +528,7 @@ export class MobileIngotsClient {
543
528
 
544
529
  const ingot = await this.verifyIngotActive(
545
530
  { vaultId: options.vaultId, ingotId: init.ingotId, vat: options.vat },
546
- { filename: name, fileSize: options.fileSize },
547
- options.debug
531
+ { filename: name, fileSize: options.fileSize }
548
532
  );
549
533
 
550
534
  return {
@@ -583,7 +567,6 @@ export class MobileIngotsClient {
583
567
  fileSize: options.fileSize,
584
568
  filename: options.name,
585
569
  resume: options.session,
586
- onSessionExpiry: options.onSessionExpiry,
587
570
  transport: options.transport,
588
571
  transferPolicy: options.transferPolicy,
589
572
  sourceAssetId: options.sourceAssetId,
@@ -595,8 +578,7 @@ export class MobileIngotsClient {
595
578
 
596
579
  const ingot = await this.verifyIngotActive(
597
580
  { vaultId: options.vaultId, ingotId: options.ingotId, vat: options.vat },
598
- { filename: options.name, fileSize: options.fileSize },
599
- options.debug
581
+ { filename: options.name, fileSize: options.fileSize }
600
582
  );
601
583
 
602
584
  return {
@@ -772,7 +754,6 @@ export class MobileIngotsClient {
772
754
  // A replace never mints an ingot: the row is the caller's existing one.
773
755
  onSessionCreated: session =>
774
756
  options.onSessionCreated?.({ ...session, ingotId, created: false, uploadId: uploadIdOf(session.uploadUrl) }),
775
- onSessionExpiry: options.onSessionExpiry,
776
757
  transport: options.transport,
777
758
  transferPolicy: options.transferPolicy,
778
759
  sourceAssetId: options.sourceAssetId,
@@ -784,8 +765,7 @@ export class MobileIngotsClient {
784
765
 
785
766
  const ingot = await this.verifyIngotActive(
786
767
  { vaultId, ingotId: response.data.ingot_id, vat },
787
- { filename: name, fileSize },
788
- debug
768
+ { filename: name, fileSize }
789
769
  );
790
770
 
791
771
  return {
@@ -1113,54 +1093,32 @@ export class MobileIngotsClient {
1113
1093
  }
1114
1094
 
1115
1095
  /**
1116
- * Read a just-uploaded ingot until the server reports it `active`.
1096
+ * Read a just-uploaded ingot once and require it `active`.
1117
1097
  *
1118
1098
  * The upload resolved on Forge's receipt (a 2xx to the PATCH at the final
1119
- * offset, which Forge answers only once the ingot is published), so a read
1120
- * that is not `active` yet is a read lagging that publication, which the
1121
- * poll waits out. It never re-creates or re-uploads anything. A row still
1122
- * not `active` past the poll budget is never reported as a success: it
1123
- * throws a `TusUploadError` whose `retryLater` is set (every byte is
1124
- * received, publication is unconfirmed), so the caller resumes the session
1125
- * it persisted later, which asks Forge for the receipt again and sends no
1126
- * bytes, rather than recording a backup the vault may not hold.
1127
- *
1128
- * Every read is strongly consistent: an eventually consistent read can
1129
- * still serve the row as it stood before this upload published, and a
1130
- * replaced row reads `active` throughout, so that stale image would pass
1131
- * the status check and report a `content_version` older than this
1132
- * upload's. A consistent read reports the version at the read, which a
1133
- * later writer's publication can already have replaced: the upload's own
1134
- * publication is its session's `uploadId`.
1099
+ * offset, which Forge answers only once the ingot is published), and the
1100
+ * read is strongly consistent, so it cannot lag that publication: an
1101
+ * eventually consistent read could still serve the row as it stood before
1102
+ * this upload published, and a replaced row reads `active` throughout, so
1103
+ * that stale image would pass the status check and report a
1104
+ * `content_version` older than this upload's. A row the read finds in any
1105
+ * other status is never reported as a success, which would record a
1106
+ * backup the vault may not hold. The read reports the version at the read,
1107
+ * which a later writer's publication can already have replaced: the
1108
+ * upload's own publication is its session's `uploadId`.
1135
1109
  */
1136
1110
  private async verifyIngotActive(
1137
1111
  ingotRef: { vaultId: string; ingotId: string; vat: string },
1138
- upload: { filename: string; fileSize: number },
1139
- debug?: DebugLogger
1112
+ upload: { filename: string; fileSize: number }
1140
1113
  ): Promise<Ingot> {
1141
1114
  const { vaultId, ingotId, vat } = ingotRef;
1142
- const deadline = Date.now() + MobileIngotsClient.INGOT_STATUS_POLL_BUDGET_MS;
1143
- let delay = MobileIngotsClient.INGOT_STATUS_POLL_INITIAL_MS;
1144
- let ingot = await this.get(vaultId, ingotId, vat, { consistent: true });
1145
-
1146
- while (ingot.status !== 'active') {
1147
- const remaining = deadline - Date.now();
1148
- if (remaining <= 0) {
1149
- debug?.log(
1150
- `Ingot ${ingotId} still '${ingot.status}' after ${MobileIngotsClient.INGOT_STATUS_POLL_BUDGET_MS}ms; ` +
1151
- 'the upload is received and will be confirmed on a later attempt'
1152
- );
1153
- throw new TusUploadError(
1154
- `Upload received; the vault has not confirmed ingot ${ingotId} published yet (status ${ingot.status ?? 'unknown'})`,
1155
- { ...upload, phase: 'finalize', retryLater: true }
1156
- );
1157
- }
1158
-
1159
- await new Promise(resolve => setTimeout(resolve, Math.min(delay, remaining)));
1160
- delay = Math.min(delay * 2, MobileIngotsClient.INGOT_STATUS_POLL_MAX_MS);
1161
- ingot = await this.get(vaultId, ingotId, vat, { consistent: true });
1115
+ const ingot = await this.get(vaultId, ingotId, vat, { consistent: true });
1116
+ if (ingot.status !== 'active') {
1117
+ throw new TusUploadError(
1118
+ `Upload received, but the vault reads ingot ${ingotId} as '${ingot.status ?? 'unknown'}', not published`,
1119
+ { ...upload, phase: 'finalize' }
1120
+ );
1162
1121
  }
1163
-
1164
1122
  return ingot;
1165
1123
  }
1166
1124