@sparkvault/sdk-mobile 5.2.2 → 5.2.3

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/types.ts CHANGED
@@ -583,6 +583,21 @@ export interface UploadResult {
583
583
  name: string;
584
584
  size_bytes: number;
585
585
  storage_location: 's3';
586
+ /**
587
+ * Whether this upload minted the ingot (true) or was handed an existing row
588
+ * by the server's same-name upsert / a resumed session (false). A caller
589
+ * that discards its ingot on a failure path needs this to tell "mine to
590
+ * discard" from "someone else's live row".
591
+ */
592
+ created?: boolean;
593
+ /**
594
+ * The ingot status the upload last observed: `active` when the server
595
+ * confirmed activation. Anything else means the transfer completed but the
596
+ * activation poll budget ran out first - the ingot usually activates
597
+ * moments later, but a caller recording "backed up" must not take that on
598
+ * faith (resume the session later; Forge re-confirms finalization).
599
+ */
600
+ status?: string;
586
601
  }
587
602
 
588
603
  export interface IngotSharingConfig {
@@ -691,6 +706,119 @@ export interface MobileFileReader {
691
706
  readAsBase64(fileUri: string, options: { position: number; length: number }): Promise<string>;
692
707
  }
693
708
 
709
+ /**
710
+ * A tus upload session as Forge created it: the session URL, the per-upload
711
+ * token every request on it must carry, and the chunk geometry Forge fixed
712
+ * for it. Persist it to resume the upload after a failed attempt or a
713
+ * relaunch (`ingots.resumeUpload`) instead of re-sending bytes Forge holds.
714
+ */
715
+ export interface TusSessionInfo {
716
+ uploadUrl: string;
717
+ istk: string;
718
+ chunkSize: number;
719
+ }
720
+
721
+ /**
722
+ * The Forge tus session an ingot upload created, bound to the ingot the API
723
+ * minted (or handed back) for it. Everything `ingots.resumeUpload` needs.
724
+ */
725
+ export interface IngotUploadSession extends TusSessionInfo {
726
+ ingotId: string;
727
+ /** Whether the upload minted the ingot (see `UploadResult.created`). */
728
+ created: boolean;
729
+ }
730
+
731
+ /**
732
+ * Which transport a tus upload rides. `foreground` (the default) streams
733
+ * chunks over XHR with progress events, abort, and the stall watchdog.
734
+ * `background` asks for the transfer to survive the app being suspended, and
735
+ * resolves to the best engine the app provides, in order: the OS transfer
736
+ * engine (`backgroundTransfer`: any file size, any offset, progress and
737
+ * abort, chunks chained natively), else the single-chunk background adapter
738
+ * (`backgroundUploader`: only a file that fits one chunk, no progress, no
739
+ * abort), else plain XHR. The upload semantics are the same on every engine;
740
+ * only the guarantees against suspension differ.
741
+ */
742
+ export type UploadTransport = 'foreground' | 'background';
743
+
744
+ /**
745
+ * The remaining range of a tus session handed to the OS transfer engine:
746
+ * everything from `offset` to `fileSize`, PATCHed in `chunkSize` pieces with
747
+ * the four tus headers. The network flags ride on every request the engine
748
+ * sends, because the OS (not JS) is what waits for an acceptable network
749
+ * while the app is suspended.
750
+ */
751
+ export interface BackgroundTransferJob {
752
+ uploadUrl: string;
753
+ istk: string;
754
+ /** file:// URI of the whole source file; it must stay in place until the job completes. */
755
+ fileUri: string;
756
+ fileSize: number;
757
+ /** Forge X-Chunk-Size: every non-final PATCH body is exactly this many bytes. */
758
+ chunkSize: number;
759
+ /** Server offset to start from (0 after create; the HEAD offset on resume). */
760
+ offset: number;
761
+ allowsCellularAccess: boolean;
762
+ allowsConstrainedNetworkAccess: boolean;
763
+ }
764
+
765
+ /**
766
+ * Why an OS transfer ended without reaching the final offset. `http` carries
767
+ * Forge's status and body (the SDK maps gates and lost sessions from them);
768
+ * `cancelled` is the caller's own abort; `interrupted` is the OS ending the
769
+ * task without being asked (a relaunch, a system cancel); `stalled` is a 2xx
770
+ * whose offset did not advance; `file` is a source the engine could not read.
771
+ */
772
+ export type BackgroundTransferFailureKind = 'network' | 'http' | 'file' | 'cancelled' | 'stalled' | 'interrupted';
773
+
774
+ /** App adapter over an OS-driven background transfer engine (iOS background URLSession with native chunk chaining). */
775
+ export interface MobileBackgroundTransfer {
776
+ /** Resolves when the OS reports the final offset; rejects with BackgroundTransferError. Start-or-attach: the same uploadUrl attaches to a job already running. */
777
+ transfer(
778
+ job: BackgroundTransferJob,
779
+ options: { abortSignal?: AbortSignal; onProgress?: (offset: number) => void }
780
+ ): Promise<{ offset: number }>;
781
+ /** Cancel and forget the OS job for this session (no-op when none). */
782
+ cancel(uploadUrl: string): Promise<void>;
783
+ }
784
+
785
+ /** Network policy an upload carries into the OS transfer; ignored by the XHR paths (JS gates those). Defaults: both true. */
786
+ export interface UploadTransferPolicy {
787
+ allowsCellularAccess?: boolean;
788
+ allowsConstrainedNetworkAccess?: boolean;
789
+ }
790
+
791
+ /**
792
+ * What happens to the Forge tus session when an upload's `abortSignal` fires
793
+ * mid-transfer. `terminate` (the default) sends a tus DELETE so Forge drops
794
+ * the chunks it already holds: right for a user cancel, where the bytes will
795
+ * never be wanted again. `keep` leaves the session untouched on Forge, so a
796
+ * PAUSE (WiFi lost, low battery, app going to background) can stop the
797
+ * transfer now and `ingots.resumeUpload` it later from the server offset
798
+ * instead of re-sending the file. The caller owns a kept session: it is
799
+ * expected to persist it (`onSessionCreated`) and resume or terminate it,
800
+ * otherwise it only goes away when Forge's abandoned-session TTL reaps it.
801
+ * The cancellation error is identical either way.
802
+ */
803
+ export type UploadAbortBehavior = 'terminate' | 'keep';
804
+
805
+ /**
806
+ * App-provided adapter that PATCHes a whole local file as the request body
807
+ * on a background URLSession (expo-file-system legacy `uploadAsync` with
808
+ * `sessionType: BACKGROUND`), so a single-chunk upload finishes even when iOS
809
+ * suspends the app mid-transfer. The fallback behind `backgroundTransfer`:
810
+ * the tus uploader reaches for it only when no OS transfer engine is
811
+ * configured and the file fits one chunk; everything else keeps the
812
+ * streaming XHR path.
813
+ */
814
+ export interface MobileBackgroundUploader {
815
+ uploadFile(
816
+ url: string,
817
+ fileUri: string,
818
+ options: { method: 'PATCH'; headers: Record<string, string> }
819
+ ): Promise<{ status: number; headers: Record<string, string>; body: string }>;
820
+ }
821
+
694
822
  export interface MobileDownloadProgress {
695
823
  bytesWritten: number;
696
824
  bytesTotal?: number;