@sparkvault/sdk-js 9.2.0 → 9.2.2

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.
@@ -48,21 +48,46 @@ export declare class UploadApi extends SparkVaultApi {
48
48
  * offset rather than failing the whole transfer — see {@link CHUNK_MAX_ATTEMPTS}
49
49
  * and {@link readResumeOffset}.
50
50
  *
51
- * Returns the TUS session URL so the caller can confirm server-side
52
- * finalization via {@link verifyUploadFinalized} before reporting success.
51
+ * Resolves only once the server has confirmed finalization
52
+ * ({@link confirmServerFinalized}), so a caller that gets a resolved promise
53
+ * is always looking at a published ingot.
53
54
  */
54
- uploadFileToForge(file: File | Blob, forgeUrl: string, onProgress?: (bytesUploaded: number, bytesTotal: number) => void): Promise<string>;
55
+ uploadFileToForge(file: File | Blob, forgeUrl: string, onProgress?: (bytesUploaded: number, bytesTotal: number) => void): Promise<void>;
55
56
  /**
56
- * Read the offset a failed chunk should resume from.
57
+ * Confirm the server finalized a fully received upload — the one receipt
58
+ * every transfer ends on.
59
+ *
60
+ * The server persists the session's final offset BEFORE it finalizes, so a
61
+ * HEAD offset proves receipt and never publication: it can equal the file
62
+ * size while finalization failed or is still running, and reporting that as
63
+ * success would hand the user a stored file whose ingot was never published.
64
+ * The zero-length PATCH at the final offset is the server's finalization
65
+ * re-drive — it short-circuits to 204 on an already-finalized session, and
66
+ * on a received-but-unfinalized one it answers only after publication.
67
+ *
68
+ * A 409 means another writer is inside the finalizer right now; that is the
69
+ * outcome the budget exists for, so the retry waits it out rather than
70
+ * failing a transfer that is about to succeed. A 400 is the opposite — the
71
+ * server is behind the offset we claim — and fails immediately.
72
+ */
73
+ private confirmServerFinalized;
74
+ /**
75
+ * Read the offset a failed chunk should resume from — the one place a
76
+ * server-reported resume point is judged.
57
77
  *
58
78
  * Forge commits a chunk before it answers, so a PATCH that died in transit
59
79
  * may have landed in full or not at all (never in part — the chunk object
60
80
  * is written atomically before the offset advances); only the session's own
61
81
  * persisted offset knows which, and the client's arithmetic is worthless
62
- * here. An offset past the declared total is a protocol violation rather
63
- * than a resume point: honoring it would end the loop early and report a
64
- * partial upload as complete, the same trap {@link patchChunk} guards
65
- * against on a PATCH's own offset.
82
+ * here.
83
+ *
84
+ * Two contracts disqualify an answer. TUS sanity: an offset past the
85
+ * declared total would end the loop early and report a partial upload as
86
+ * complete, the same trap {@link patchChunk} guards against on a PATCH's own
87
+ * offset. Forge chunk granularity: a session advances only in whole
88
+ * committed chunks, so an offset that is neither chunk-aligned nor the file
89
+ * end is a corrupt session, and resuming from it would send a short
90
+ * non-final chunk Forge rejects anyway.
66
91
  */
67
92
  private readResumeOffset;
68
93
  /**
@@ -83,35 +108,22 @@ export declare class UploadApi extends SparkVaultApi {
83
108
  */
84
109
  private patchChunk;
85
110
  /**
86
- * Confirm the upload was finalized SERVER-SIDE before reporting success.
87
- *
88
- * The TUS PATCH loop trusts a server-provided `Upload-Offset`; a buggy or
89
- * malicious Forge could return an inflated offset before every chunk was
90
- * actually committed and encrypted. This re-reads the server's own
91
- * persisted offset via a TUS HEAD (which Forge only advances on a real S3
92
- * commit) and requires it to reach the declared total — the web equivalent
93
- * of the mobile SDK's `verifyIngotActive` (status === 'active') guarantee.
94
- *
95
- * Polls because the final chunk's commit and the offset write can lag the
96
- * PATCH acknowledgement by a moment. Throws on a non-2xx HEAD, on a session
97
- * that never reaches the expected offset within the poll budget, or on a
98
- * cancelled session — never reports a half-finished upload as done.
111
+ * Read the server's persisted upload offset via a TUS HEAD request — the one
112
+ * place the client asks Forge where a session really stands.
99
113
  *
100
- * @param uploadUrl - The TUS session URL (Forge `Location`, ISTK-bound).
101
- * @param expectedOffset - The declared total upload size in bytes.
114
+ * @param check - Which caller this read serves; shapes the failure copy.
102
115
  */
103
- verifyUploadFinalized(uploadUrl: string, expectedOffset: number): Promise<void>;
116
+ private headUploadOffset;
104
117
  /**
105
- * Read the server's persisted upload offset via a TUS HEAD request — the one
106
- * place the client asks Forge where a session really stands, for both
107
- * mid-upload resume and end-of-upload confirmation.
118
+ * Issue one bodyless TUS request — the single transport behind every
119
+ * non-chunk call this client makes (resume HEAD, finalization PATCH).
108
120
  *
109
- * Uses raw `fetch` rather than the JSON envelope helper: TUS responses
110
- * carry an empty body and surface state in the `Upload-Offset` header.
111
- * Honors the session abort signal and request timeout like every other
112
- * client call.
121
+ * Uses raw `fetch` rather than the JSON envelope helper: TUS responses carry
122
+ * an empty body and surface state in headers. Honors the session abort
123
+ * signal and request timeout like every other client call, and resolves only
124
+ * on a 2xx so no caller has to re-check `response.ok`.
113
125
  *
114
- * @param check - Which caller this read serves; shapes the failure copy.
126
+ * @param check - Which caller this request serves; shapes the failure copy.
115
127
  */
116
- private headUploadOffset;
128
+ private tusRequest;
117
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkvault/sdk-js",
3
- "version": "9.2.0",
3
+ "version": "9.2.2",
4
4
  "description": "SparkVault JavaScript SDK - Identity Verification and Encrypted Vaults",
5
5
  "type": "module",
6
6
  "exports": {