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