@needmoretruth/nmts-cli 0.44.0 → 0.46.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.
Files changed (248) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +73 -0
  3. package/README.ko.md +6 -3
  4. package/README.md +15 -3
  5. package/dist/api-advice.js +17 -2
  6. package/dist/api.d.ts +22 -0
  7. package/dist/api.js +49 -1
  8. package/dist/arg-options.d.ts +14 -0
  9. package/dist/args.js +11 -2
  10. package/dist/artifact-about.d.ts +1 -1
  11. package/dist/collision.d.ts +20 -3
  12. package/dist/collision.js +21 -3
  13. package/dist/commands/erase.js +1 -0
  14. package/dist/commands/get.d.ts +2 -0
  15. package/dist/commands/get.js +13 -1
  16. package/dist/commands/handover.d.ts +13 -0
  17. package/dist/commands/handover.js +328 -0
  18. package/dist/commands/heavy-run.d.ts +59 -0
  19. package/dist/commands/heavy-run.js +247 -0
  20. package/dist/commands/heavy.d.ts +7 -0
  21. package/dist/commands/heavy.js +123 -0
  22. package/dist/commands/ls.d.ts +7 -0
  23. package/dist/commands/ls.js +27 -6
  24. package/dist/commands/public-code.d.ts +6 -0
  25. package/dist/commands/public-code.js +46 -0
  26. package/dist/commands/push-heavy.d.ts +6 -0
  27. package/dist/commands/push-heavy.js +128 -0
  28. package/dist/commands/push-tree.d.ts +24 -0
  29. package/dist/commands/push-tree.js +91 -0
  30. package/dist/commands/push.d.ts +4 -13
  31. package/dist/commands/push.js +7 -77
  32. package/dist/commands/put-heavy.d.ts +9 -0
  33. package/dist/commands/put-heavy.js +120 -0
  34. package/dist/commands/put-payer.d.ts +21 -0
  35. package/dist/commands/put-payer.js +24 -0
  36. package/dist/commands/put-thumbnail.d.ts +4 -0
  37. package/dist/commands/put-thumbnail.js +119 -0
  38. package/dist/commands/put-wallet.d.ts +2 -0
  39. package/dist/commands/put-wallet.js +3 -2
  40. package/dist/commands/put.d.ts +10 -2
  41. package/dist/commands/put.js +13 -7
  42. package/dist/commands/receive.js +3 -3
  43. package/dist/commands/s3.js +44 -10
  44. package/dist/crypto-surface.d.ts +8 -0
  45. package/dist/crypto-surface.js +3 -0
  46. package/dist/crypto.d.ts +3 -0
  47. package/dist/crypto.js +3 -0
  48. package/dist/download-part.d.ts +32 -1
  49. package/dist/download-part.js +95 -6
  50. package/dist/download-range.d.ts +19 -0
  51. package/dist/download-range.js +108 -0
  52. package/dist/download-sink.d.ts +15 -0
  53. package/dist/download.d.ts +14 -0
  54. package/dist/download.js +19 -4
  55. package/dist/drive-edit/trash.js +5 -3
  56. package/dist/drive-edit/tree.d.ts +6 -0
  57. package/dist/drive-edit/tree.js +10 -0
  58. package/dist/drive-erase.js +2 -2
  59. package/dist/drive-paths.d.ts +2 -2
  60. package/dist/drive-paths.js +2 -2
  61. package/dist/handover.d.ts +44 -0
  62. package/dist/handover.js +199 -0
  63. package/dist/heavy-api.d.ts +36 -0
  64. package/dist/heavy-api.js +107 -0
  65. package/dist/heavy-copy.d.ts +72 -0
  66. package/dist/heavy-copy.js +108 -0
  67. package/dist/heavy-evm.d.ts +20 -0
  68. package/dist/heavy-evm.js +106 -0
  69. package/dist/heavy-self-pay.d.ts +92 -0
  70. package/dist/heavy-self-pay.js +167 -0
  71. package/dist/heavy-upload.d.ts +87 -0
  72. package/dist/heavy-upload.js +154 -0
  73. package/dist/heavy-wallet-pay.d.ts +39 -0
  74. package/dist/heavy-wallet-pay.js +73 -0
  75. package/dist/help-options.js +8 -2
  76. package/dist/help.js +16 -3
  77. package/dist/list-tier.d.ts +7 -0
  78. package/dist/list-tier.js +47 -0
  79. package/dist/main.js +14 -9
  80. package/dist/manifest-write.d.ts +4 -3
  81. package/dist/mcp-tools/files.js +21 -2
  82. package/dist/mcp-tools/reads.js +9 -1
  83. package/dist/platform-sign.d.ts +4 -4
  84. package/dist/platform-sign.js +3 -3
  85. package/dist/portable.d.ts +17 -1
  86. package/dist/portable.js +13 -1
  87. package/dist/product.d.ts +1 -1
  88. package/dist/product.js +1 -1
  89. package/dist/recovery-build.js +16 -0
  90. package/dist/recovery-map-part.d.ts +82 -0
  91. package/dist/recovery-map-part.js +83 -0
  92. package/dist/recovery-map.d.ts +5 -40
  93. package/dist/recovery-map.js +18 -1
  94. package/dist/recovery-source.d.ts +3 -0
  95. package/dist/recovery-source.js +9 -0
  96. package/dist/risk.d.ts +30 -0
  97. package/dist/risk.js +23 -2
  98. package/dist/run-log.d.ts +1 -1
  99. package/dist/run-log.js +7 -1
  100. package/dist/s3/address.d.ts +20 -0
  101. package/dist/s3/address.js +97 -0
  102. package/dist/s3/answer.d.ts +48 -0
  103. package/dist/s3/answer.js +330 -0
  104. package/dist/s3/body-deframe.d.ts +49 -0
  105. package/dist/s3/body-deframe.js +264 -0
  106. package/dist/s3/body-measure.d.ts +13 -0
  107. package/dist/s3/body-measure.js +48 -0
  108. package/dist/s3/body-plan.d.ts +31 -0
  109. package/dist/s3/body-plan.js +159 -0
  110. package/dist/s3/body.d.ts +46 -0
  111. package/dist/s3/body.js +117 -0
  112. package/dist/s3/call.d.ts +36 -0
  113. package/dist/s3/call.js +42 -0
  114. package/dist/s3/checksum.d.ts +26 -0
  115. package/dist/s3/checksum.js +176 -0
  116. package/dist/s3/content-type.d.ts +3 -0
  117. package/dist/s3/content-type.js +49 -0
  118. package/dist/s3/contract.d.ts +91 -14
  119. package/dist/s3/drive-conditions.d.ts +47 -0
  120. package/dist/s3/drive-conditions.js +134 -0
  121. package/dist/s3/drive-key.d.ts +11 -0
  122. package/dist/s3/drive-key.js +58 -0
  123. package/dist/s3/drive-limits.d.ts +33 -0
  124. package/dist/s3/drive-limits.js +53 -0
  125. package/dist/s3/drive-lock.d.ts +11 -0
  126. package/dist/s3/drive-lock.js +47 -0
  127. package/dist/s3/drive-trashed-name.d.ts +13 -0
  128. package/dist/s3/drive-trashed-name.js +59 -0
  129. package/dist/s3/drive-write.d.ts +38 -0
  130. package/dist/s3/drive-write.js +258 -0
  131. package/dist/s3/drive.d.ts +59 -25
  132. package/dist/s3/drive.js +46 -77
  133. package/dist/s3/listing.d.ts +27 -1
  134. package/dist/s3/listing.js +62 -20
  135. package/dist/s3/long-answer.d.ts +12 -0
  136. package/dist/s3/long-answer.js +104 -0
  137. package/dist/s3/multipart-assemble.d.ts +17 -0
  138. package/dist/s3/multipart-assemble.js +68 -0
  139. package/dist/s3/multipart-sweep.d.ts +15 -0
  140. package/dist/s3/multipart-sweep.js +87 -0
  141. package/dist/s3/multipart-view.d.ts +45 -0
  142. package/dist/s3/multipart-view.js +232 -0
  143. package/dist/s3/multipart.d.ts +26 -19
  144. package/dist/s3/multipart.js +193 -78
  145. package/dist/s3/object-read.d.ts +17 -0
  146. package/dist/s3/object-read.js +127 -0
  147. package/dist/s3/object-write.d.ts +35 -0
  148. package/dist/s3/object-write.js +198 -0
  149. package/dist/s3/range.d.ts +14 -0
  150. package/dist/s3/range.js +80 -0
  151. package/dist/s3/response-sink.d.ts +12 -2
  152. package/dist/s3/response-sink.js +71 -7
  153. package/dist/s3/routes.d.ts +0 -1
  154. package/dist/s3/routes.js +242 -217
  155. package/dist/s3/same-file.d.ts +4 -1
  156. package/dist/s3/same-file.js +12 -3
  157. package/dist/s3/server.d.ts +54 -4
  158. package/dist/s3/server.js +174 -14
  159. package/dist/s3/sigv4-canonical.d.ts +91 -0
  160. package/dist/s3/sigv4-canonical.js +148 -0
  161. package/dist/s3/sigv4-presigned.d.ts +13 -0
  162. package/dist/s3/sigv4-presigned.js +82 -0
  163. package/dist/s3/sigv4.d.ts +26 -27
  164. package/dist/s3/sigv4.js +137 -102
  165. package/dist/s3/spool.d.ts +37 -0
  166. package/dist/s3/spool.js +104 -0
  167. package/dist/s3/staging.d.ts +90 -7
  168. package/dist/s3/staging.js +97 -66
  169. package/dist/s3/xml-multipart.d.ts +38 -0
  170. package/dist/s3/xml-multipart.js +47 -0
  171. package/dist/s3/xml-read.d.ts +28 -0
  172. package/dist/s3/xml-read.js +235 -0
  173. package/dist/s3/xml.d.ts +45 -2
  174. package/dist/s3/xml.js +72 -13
  175. package/dist/s3-gateway.d.ts +11 -5
  176. package/dist/s3-gateway.js +5 -2
  177. package/dist/seal.d.ts +1 -1
  178. package/dist/share.d.ts +5 -0
  179. package/dist/share.js +1 -1
  180. package/dist/shared/lib/api/types-heavy.d.ts +167 -0
  181. package/dist/shared/lib/api/types-heavy.js +60 -0
  182. package/dist/shared/lib/drive/manifest-codec.d.ts +11 -31
  183. package/dist/shared/lib/drive/manifest-codec.js +15 -23
  184. package/dist/shared/lib/drive/manifest-index.d.ts +10 -1
  185. package/dist/shared/lib/drive/manifest-index.js +30 -8
  186. package/dist/shared/lib/drive/manifest-wire-extras.d.ts +50 -0
  187. package/dist/shared/lib/drive/manifest-wire-extras.js +65 -0
  188. package/dist/shared/lib/drive/preview-classify.d.ts +17 -0
  189. package/dist/shared/lib/drive/preview-classify.js +96 -0
  190. package/dist/shared/lib/drive/rebuild-verify.js +1 -0
  191. package/dist/shared/lib/filecoin/providers.d.ts +25 -0
  192. package/dist/shared/lib/filecoin/providers.js +58 -0
  193. package/dist/shared/lib/heavy/download.d.ts +48 -0
  194. package/dist/shared/lib/heavy/download.js +116 -0
  195. package/dist/shared/lib/heavy/order-plan.d.ts +77 -0
  196. package/dist/shared/lib/heavy/order-plan.js +83 -0
  197. package/dist/shared/lib/heavy/order-runner.d.ts +9 -0
  198. package/dist/shared/lib/heavy/order-runner.js +300 -0
  199. package/dist/shared/lib/heavy/order-types.d.ts +90 -0
  200. package/dist/shared/lib/heavy/order-types.js +6 -0
  201. package/dist/shared/lib/heavy/order-wire.d.ts +55 -0
  202. package/dist/shared/lib/heavy/order-wire.js +113 -0
  203. package/dist/shared/lib/heavy/piece-cid.d.ts +24 -0
  204. package/dist/shared/lib/heavy/piece-cid.js +55 -0
  205. package/dist/shared/lib/heavy/sp-upload.d.ts +37 -0
  206. package/dist/shared/lib/heavy/sp-upload.js +112 -0
  207. package/dist/shared/lib/heavy/synapse-piece.d.ts +1 -0
  208. package/dist/shared/lib/heavy/synapse-piece.js +8 -0
  209. package/dist/shared/lib/share/handover-format.d.ts +129 -0
  210. package/dist/shared/lib/share/handover-format.js +323 -0
  211. package/dist/shared/lib/share/shared-file-info.js +1 -0
  212. package/dist/shared/lib/storage-network.d.ts +4 -4
  213. package/dist/shared/lib/storage-network.js +7 -7
  214. package/dist/shared/lib/storage-tier.d.ts +28 -0
  215. package/dist/shared/lib/storage-tier.js +63 -0
  216. package/dist/shared/lib/wallet/send-rules.js +1 -0
  217. package/dist/upload-file.d.ts +8 -0
  218. package/dist/upload-file.js +57 -25
  219. package/dist/upload-price-node.d.ts +3 -0
  220. package/dist/upload-price-node.js +3 -6
  221. package/dist/upload-price.d.ts +10 -0
  222. package/dist/upload-price.js +13 -1
  223. package/dist/upload-run.d.ts +80 -0
  224. package/dist/upload-run.js +173 -0
  225. package/dist/upload-steps.js +15 -4
  226. package/dist/upload-store.d.ts +15 -6
  227. package/dist/upload-store.js +6 -0
  228. package/dist/upload-wallet-put.d.ts +11 -4
  229. package/dist/upload-wallet-put.js +17 -6
  230. package/dist/upload-wallet.js +4 -0
  231. package/dist/upload-wire.d.ts +25 -0
  232. package/dist/upload-wire.js +20 -1
  233. package/dist/upload.js +28 -13
  234. package/dist/wallet-sign.js +2 -2
  235. package/docs/commands/get.md +3 -0
  236. package/docs/commands/handover.md +38 -0
  237. package/docs/commands/heavy.md +35 -0
  238. package/docs/commands/ls.md +5 -0
  239. package/docs/commands/public-code.md +7 -0
  240. package/docs/commands/push.md +4 -1
  241. package/docs/commands/put.md +23 -1
  242. package/docs/commands/share.md +3 -1
  243. package/package.json +5 -2
  244. package/server.json +2 -2
  245. package/vendor/nmts-crypto/nmts_crypto_wasm.d.ts +17 -1
  246. package/vendor/nmts-crypto/nmts_crypto_wasm.js +28 -0
  247. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm +0 -0
  248. package/vendor/nmts-crypto/nmts_crypto_wasm_bg.wasm.d.ts +2 -1
@@ -12,6 +12,9 @@ import { NmtsError } from "./errors.js";
12
12
  * ⛔ IT IS NOT READ HERE. A file large enough to need several parts is a file too large to hold,
13
13
  * and the size is all that is needed to plan the upload and quote its price. The bytes are read
14
14
  * later, a slice at a time, by the part that is being sealed.
15
+ *
16
+ * ⚠ ZERO IS A SIZE. An empty file is sealed and stored like any other (`planFor` in
17
+ * `upload-price.ts`), so it is not refused here.
15
18
  */
16
19
  export function measureLocal(path) {
17
20
  let stat;
@@ -27,11 +30,5 @@ export function measureLocal(path) {
27
30
  nextStep: "This version uploads one file at a time.",
28
31
  });
29
32
  }
30
- if (stat.size === 0) {
31
- throw new NmtsError(`${path} is empty.`, {
32
- exitCode: 4,
33
- nextStep: "The storage network has nothing to store and would refuse the reservation.",
34
- });
35
- }
36
33
  return stat.size;
37
34
  }
@@ -27,6 +27,16 @@ export declare function creditsFor(sealedBytes: number, epochs?: number): number
27
27
  * that rather than doing it, and this is where the number comes from.
28
28
  */
29
29
  export declare function partSizeFor(chosen: string | number | undefined): number;
30
+ /**
31
+ * Where the cuts fall — and for an EMPTY file, one part that carries nothing.
32
+ *
33
+ * ⛔ AN EMPTY FILE IS A FILE, NOT A MISTAKE. S3 clients make them routinely, and NCF-3 seals zero
34
+ * bytes as one empty final chunk: 88 sealed bytes, which the server reserves and commits and every
35
+ * reader opens like any other part. `planParts` is a byte-for-byte copy shared with the browser
36
+ * and refuses a zero length, so the one extra case is said here, in the one place both the price
37
+ * and the sealing read the plan from.
38
+ */
39
+ export declare function planFor(size: number, partSize: number): PartRange[];
30
40
  /**
31
41
  * The plan, and what it will cost — one function so the price and the sealing cannot disagree.
32
42
  *
@@ -67,6 +67,18 @@ function parseSize(text) {
67
67
  return Number.NaN;
68
68
  return Number(match[1]) * factor;
69
69
  }
70
+ /**
71
+ * Where the cuts fall — and for an EMPTY file, one part that carries nothing.
72
+ *
73
+ * ⛔ AN EMPTY FILE IS A FILE, NOT A MISTAKE. S3 clients make them routinely, and NCF-3 seals zero
74
+ * bytes as one empty final chunk: 88 sealed bytes, which the server reserves and commits and every
75
+ * reader opens like any other part. `planParts` is a byte-for-byte copy shared with the browser
76
+ * and refuses a zero length, so the one extra case is said here, in the one place both the price
77
+ * and the sealing read the plan from.
78
+ */
79
+ export function planFor(size, partSize) {
80
+ return size === 0 ? [{ partIndex: 0, offset: 0, length: 0 }] : planParts(size, partSize);
81
+ }
70
82
  /**
71
83
  * The plan, and what it will cost — one function so the price and the sealing cannot disagree.
72
84
  *
@@ -75,7 +87,7 @@ function parseSize(text) {
75
87
  * differently from how it is actually stored.
76
88
  */
77
89
  export function planAndPrice(size, partSize, rule) {
78
- const plan = planParts(size, partSize);
90
+ const plan = planFor(size, partSize);
79
91
  const sealFor = (range) => range.partIndex === plan.length - 1
80
92
  ? paddedPlaintextLen(range.length, rule, { unitBytes: CREDIT_BYTES, shape: NCF3_SHAPE })
81
93
  : range.length;
@@ -0,0 +1,80 @@
1
+ import { type Reservation } from "./upload-store.ts";
2
+ import { type PaidPart } from "./upload-wire.ts";
3
+ /** What a refusal over another run's records is known by, for a program to branch on. */
4
+ export declare const UPLOAD_CONFLICT = "UPLOAD_CONFLICT";
5
+ /** A name for one upload of a file. Random: it says nothing about the file or the account. */
6
+ export declare function newRunId(): string;
7
+ /**
8
+ * The run this file's records belong to, or a new one when none of them names one.
9
+ *
10
+ * ⚠ A record an earlier version wrote names none. Its own key stays the one that version used
11
+ * (`runIdField`); the new id is only for the parts this run is the first to write down.
12
+ */
13
+ export declare function runIdFor(fileKey: string, parts: number): Promise<string>;
14
+ /**
15
+ * The run id a part's record is written with: the one it already has, or this upload's.
16
+ *
17
+ * ⛔ A RECORD KEEPS WHAT IT WAS WRITTEN WITH, including nothing. Its reservation is filed under the
18
+ * key it was made with; giving an earlier version's record a run id now would ask the server
19
+ * under a key it has never seen and buy the storage a second time.
20
+ */
21
+ export declare function runIdField(existing: Reservation | null, runId: string): {
22
+ runId?: string;
23
+ };
24
+ /**
25
+ * Run `body` once every earlier run of the same file in this process has finished.
26
+ *
27
+ * ⚠ WAITING, NOT REFUSING. Inside one process the first run is known to be alive, so the honest
28
+ * answer to a second one is "after it": it then finds a finished upload's records and answers
29
+ * the same file, or finds none and starts an upload of its own.
30
+ */
31
+ export declare function oneUploadAtATime<T>(fileKey: string, body: () => Promise<T>): Promise<T>;
32
+ /**
33
+ * Refuse a part record that another sealing of this file wrote.
34
+ *
35
+ * ⛔ THE WRAPPED FILE KEY SAYS WHICH SEALING A RECORD BELONGS TO. It is sealed afresh by every
36
+ * upload that starts from nothing and carried unchanged by every resume, so a record whose key
37
+ * is not this run's was written by another run — and its bytes open under a key this file's
38
+ * list entry will not hold.
39
+ */
40
+ export declare function refuseOtherSealing(existing: Reservation | null, input: {
41
+ runId: string;
42
+ entry: {
43
+ dekWrapped: string;
44
+ };
45
+ }): void;
46
+ /**
47
+ * The last look before the commit: every part is still written down as THIS run bought it.
48
+ *
49
+ * ⛔ THE READ AT THE START OF A PART IS NOT ENOUGH ACROSS PROCESSES. Another run can write its own
50
+ * record over one of these between that read and this commit; the commit names what this run
51
+ * paid for, so a record that no longer agrees means two sealings are interleaved, and a file
52
+ * made of both would not open.
53
+ */
54
+ export declare function confirmParts(fileKey: string, paid: readonly PaidPart[], entry: {
55
+ dekWrapped: string;
56
+ }): Promise<void>;
57
+ /**
58
+ * Forget a finished upload's records: the parts from the last to the first, then the file's own.
59
+ *
60
+ * ⛔ THE ORDER IS WHAT A RUN THAT STARTS IN THE MIDDLE OF IT CAN READ. A live upload's parts are
61
+ * always written down from the first, so what is left at any moment is a finished upload the
62
+ * next run recognises — a committed file with the first of its parts still named — or a file
63
+ * record alone, which names another run and is passed over. Forgetting the file's record first,
64
+ * or the parts from the front, left the tail of a finished upload looking like the start of a
65
+ * live one, which the next run would resume into keys the server has already settled.
66
+ */
67
+ export declare function forgetUpload(fileKey: string, parts: number): Promise<void>;
68
+ /**
69
+ * Forget records that cannot belong to a live upload: a part written down after one that is not,
70
+ * or a file's record with none of its parts.
71
+ *
72
+ * ⛔ WHY THOSE SHAPES MEAN "LEFT OVER". A live upload writes its parts down from the first, one at a
73
+ * time and each before its money moves; it writes the file's record only once every part is
74
+ * written down; and nothing removes any of them until the file is committed AND listed. So a gap
75
+ * in front of a part, or a file record alone, is a finished upload whose forgetting stopped half
76
+ * way (or ran in the old order). Resuming the first would seal the missing part afresh under a
77
+ * key the server has already settled for other bytes; resuming the second would answer the old
78
+ * file for new storage.
79
+ */
80
+ export declare function dropLeftovers(fileKey: string, parts: number): Promise<void>;
@@ -0,0 +1,173 @@
1
+ // Which UPLOAD a record belongs to, and one upload of one file at a time.
2
+ //
3
+ // ⛔ WHY THIS EXISTS. The records of an unfinished upload are filed under a name that is a pure
4
+ // function of the account, the bytes, the name and the destination (`upload-store.ts`). Two
5
+ // things follow from that, and both were defects:
6
+ //
7
+ // · A LATER upload of the same bytes to the same place — after the first was trashed, erased or
8
+ // replaced — rebuilt the first one's idempotency keys once its records were forgotten. Every
9
+ // reservation was refused as "this key already names another blob" (each sealing is fresh, so
10
+ // the blob differs), and a commit under the old key was answered with the OLD file. A run id,
11
+ // made with an upload's first record and kept with it, is what gives each upload keys of its
12
+ // own while a resume still finds the ones it started with.
13
+ // · Two runs of the same put AT ONCE — a gateway retrying a request its client gave up on, or two
14
+ // programs putting the same file — share those records. Each run seals under a file key of its
15
+ // own, and a run that picked up a part the other wrote would commit a file whose parts open
16
+ // under two different keys: paid for, listed, and impossible to read.
17
+ //
18
+ // ⛔ TWO GUARDS AGAINST THE SECOND, BECAUSE THE RECORD STORE HAS NO LOCK. Inside one process a second
19
+ // run WAITS for the first. Across processes there is nothing to wait on: the store (a directory
20
+ // on a machine, IndexedDB in a page) offers no exclusive create, and a lock made of a read and a
21
+ // write lets both sides believe they hold it. So a run that meets a record another sealing wrote
22
+ // refuses — before it pushes, signs or commits anything of that part — and checks every part
23
+ // once more before the commit.
24
+ import { randomBytes } from "@noble/hashes/utils.js";
25
+ import { toBase64Url } from "./bytes.js";
26
+ import { clearItemRecord, clearReservation, partKey, readReservationRecord, } from "./upload-store.js";
27
+ import { UploadError } from "./upload-wire.js";
28
+ /** What a refusal over another run's records is known by, for a program to branch on. */
29
+ export const UPLOAD_CONFLICT = "UPLOAD_CONFLICT";
30
+ /** A name for one upload of a file. Random: it says nothing about the file or the account. */
31
+ export function newRunId() {
32
+ return toBase64Url(randomBytes(16));
33
+ }
34
+ /**
35
+ * The run this file's records belong to, or a new one when none of them names one.
36
+ *
37
+ * ⚠ A record an earlier version wrote names none. Its own key stays the one that version used
38
+ * (`runIdField`); the new id is only for the parts this run is the first to write down.
39
+ */
40
+ export async function runIdFor(fileKey, parts) {
41
+ for (let index = 0; index < parts; index += 1) {
42
+ const record = await readReservationRecord(partKey(fileKey, index));
43
+ if (record?.runId !== undefined)
44
+ return record.runId;
45
+ }
46
+ return newRunId();
47
+ }
48
+ /**
49
+ * The run id a part's record is written with: the one it already has, or this upload's.
50
+ *
51
+ * ⛔ A RECORD KEEPS WHAT IT WAS WRITTEN WITH, including nothing. Its reservation is filed under the
52
+ * key it was made with; giving an earlier version's record a run id now would ask the server
53
+ * under a key it has never seen and buy the storage a second time.
54
+ */
55
+ export function runIdField(existing, runId) {
56
+ if (existing === null)
57
+ return { runId };
58
+ return existing.runId === undefined ? {} : { runId: existing.runId };
59
+ }
60
+ /** The tail of each file's queue: what the next run of that file waits for. */
61
+ const queues = new Map();
62
+ /**
63
+ * Run `body` once every earlier run of the same file in this process has finished.
64
+ *
65
+ * ⚠ WAITING, NOT REFUSING. Inside one process the first run is known to be alive, so the honest
66
+ * answer to a second one is "after it": it then finds a finished upload's records and answers
67
+ * the same file, or finds none and starts an upload of its own.
68
+ */
69
+ export async function oneUploadAtATime(fileKey, body) {
70
+ const before = queues.get(fileKey) ?? Promise.resolve();
71
+ let release = () => undefined;
72
+ const mine = new Promise((resolve) => {
73
+ release = resolve;
74
+ });
75
+ const tail = before.then(() => mine);
76
+ queues.set(fileKey, tail);
77
+ await before;
78
+ try {
79
+ return await body();
80
+ }
81
+ finally {
82
+ release();
83
+ // The last run out takes the queue with it, so a long-lived process keeps no entry per file.
84
+ if (queues.get(fileKey) === tail)
85
+ queues.delete(fileKey);
86
+ }
87
+ }
88
+ function conflict(paid) {
89
+ return new UploadError({
90
+ phase: "reserve",
91
+ code: UPLOAD_CONFLICT,
92
+ message: "Another run is uploading this same file to the same place.",
93
+ paid,
94
+ nextStep: "This run stopped before committing anything. Let the other run finish, then run this " +
95
+ "again — it finds that upload's records, or starts one of its own.",
96
+ });
97
+ }
98
+ /**
99
+ * Refuse a part record that another sealing of this file wrote.
100
+ *
101
+ * ⛔ THE WRAPPED FILE KEY SAYS WHICH SEALING A RECORD BELONGS TO. It is sealed afresh by every
102
+ * upload that starts from nothing and carried unchanged by every resume, so a record whose key
103
+ * is not this run's was written by another run — and its bytes open under a key this file's
104
+ * list entry will not hold.
105
+ */
106
+ export function refuseOtherSealing(existing, input) {
107
+ if (existing === null)
108
+ return;
109
+ const sameKey = existing.dekWrapped === input.entry.dekWrapped;
110
+ const sameRun = existing.runId === undefined || existing.runId === input.runId;
111
+ if (!sameKey || !sameRun) {
112
+ throw conflict(existing.ledgerId !== undefined || existing.registerTxDigest !== undefined);
113
+ }
114
+ }
115
+ /**
116
+ * The last look before the commit: every part is still written down as THIS run bought it.
117
+ *
118
+ * ⛔ THE READ AT THE START OF A PART IS NOT ENOUGH ACROSS PROCESSES. Another run can write its own
119
+ * record over one of these between that read and this commit; the commit names what this run
120
+ * paid for, so a record that no longer agrees means two sealings are interleaved, and a file
121
+ * made of both would not open.
122
+ */
123
+ export async function confirmParts(fileKey, paid, entry) {
124
+ for (const part of paid) {
125
+ const record = await readReservationRecord(partKey(fileKey, part.partIndex));
126
+ if (record === null || record.dekWrapped !== entry.dekWrapped || record.blobId !== part.blobId) {
127
+ throw conflict(true);
128
+ }
129
+ }
130
+ }
131
+ /**
132
+ * Forget a finished upload's records: the parts from the last to the first, then the file's own.
133
+ *
134
+ * ⛔ THE ORDER IS WHAT A RUN THAT STARTS IN THE MIDDLE OF IT CAN READ. A live upload's parts are
135
+ * always written down from the first, so what is left at any moment is a finished upload the
136
+ * next run recognises — a committed file with the first of its parts still named — or a file
137
+ * record alone, which names another run and is passed over. Forgetting the file's record first,
138
+ * or the parts from the front, left the tail of a finished upload looking like the start of a
139
+ * live one, which the next run would resume into keys the server has already settled.
140
+ */
141
+ export async function forgetUpload(fileKey, parts) {
142
+ for (let index = parts - 1; index >= 0; index -= 1)
143
+ await clearReservation(partKey(fileKey, index));
144
+ await clearItemRecord(fileKey);
145
+ }
146
+ /**
147
+ * Forget records that cannot belong to a live upload: a part written down after one that is not,
148
+ * or a file's record with none of its parts.
149
+ *
150
+ * ⛔ WHY THOSE SHAPES MEAN "LEFT OVER". A live upload writes its parts down from the first, one at a
151
+ * time and each before its money moves; it writes the file's record only once every part is
152
+ * written down; and nothing removes any of them until the file is committed AND listed. So a gap
153
+ * in front of a part, or a file record alone, is a finished upload whose forgetting stopped half
154
+ * way (or ran in the old order). Resuming the first would seal the missing part afresh under a
155
+ * key the server has already settled for other bytes; resuming the second would answer the old
156
+ * file for new storage.
157
+ */
158
+ export async function dropLeftovers(fileKey, parts) {
159
+ let gap = false;
160
+ let any = false;
161
+ for (let index = 0; index < parts; index += 1) {
162
+ const present = (await readReservationRecord(partKey(fileKey, index))) !== null;
163
+ any ||= present;
164
+ if (!present)
165
+ gap = true;
166
+ else if (gap) {
167
+ await forgetUpload(fileKey, parts);
168
+ return;
169
+ }
170
+ }
171
+ if (!any)
172
+ await clearItemRecord(fileKey);
173
+ }
@@ -48,6 +48,7 @@ export async function pushPart(input, step) {
48
48
  phase: "certify",
49
49
  message: why(error),
50
50
  paid: true,
51
+ from: error,
51
52
  nextStep: "The bytes are on the network. Certifying moves no money, so running the same command " +
52
53
  "again finishes the job.",
53
54
  });
@@ -70,14 +71,23 @@ export async function commitItem(input, fileKey, parts) {
70
71
  // Advisory only — the chain is the authority on a blob's life. 0 when this machine could not
71
72
  // read the epoch clock: a number we do not have is not a number to invent.
72
73
  const expiryEpoch = input.currentEpoch === null ? 0 : input.currentEpoch + input.epochs;
73
- const previous = await readItemRecord(fileKey);
74
+ const found = await readItemRecord(fileKey);
75
+ // ⛔ ONLY THIS UPLOAD'S RECORD COUNTS. One carrying another run id was left by an earlier upload
76
+ // of the same bytes to the same place, and answering its item for the parts just bought would
77
+ // name the OLD file for them. A record an earlier version wrote carries none, and is this
78
+ // upload's by the only rule that version had.
79
+ const previous = found !== null && (found.runId === undefined || found.runId === input.runId) ? found : null;
74
80
  // ⛔ ALREADY COMMITTED IS NOT COMMITTED AGAIN. The record outlives the commit precisely so a run
75
81
  // that died before writing the file list does not make a second file out of storage that is
76
82
  // already named.
77
83
  if (previous?.itemId !== undefined)
78
84
  return previous.itemId;
79
85
  const attempt = previous?.attempt ?? 0;
80
- await writeItemRecord(fileKey, { attempt });
86
+ // ⚠ A commit an earlier version attempted keeps the key it was attempted under, because the server
87
+ // may already hold its row; every other commit is this upload's.
88
+ const runId = previous === null ? input.runId : previous.runId;
89
+ const record = runId === undefined ? { attempt } : { attempt, runId };
90
+ await writeItemRecord(fileKey, record);
81
91
  let view;
82
92
  try {
83
93
  view = await input.api.createItem({
@@ -86,13 +96,14 @@ export async function commitItem(input, fileKey, parts) {
86
96
  content_hash_ct: input.entry.contentHashCt,
87
97
  visibility: VISIBILITY_PERSONAL,
88
98
  parts: parts.map((part) => describePart(part, expiryEpoch)),
89
- }, `nmts-cli-commit-${fileKey}-${attempt}`);
99
+ }, runId === undefined ? `nmts-cli-commit-${fileKey}-${attempt}` : `nmts-cli-commit-${fileKey}-${runId}-${attempt}`);
90
100
  }
91
101
  catch (error) {
92
102
  throw new UploadError({
93
103
  phase: "committing",
94
104
  message: `The file is stored but saving it to the drive failed: ${why(error)}`,
95
105
  paid: true,
106
+ from: error,
96
107
  nextStep: "Nothing more will be spent. Running the same command again commits the same stored " +
97
108
  "bytes — the retry is recognised and does not make a second file.",
98
109
  });
@@ -100,7 +111,7 @@ export async function commitItem(input, fileKey, parts) {
100
111
  // ⛔ Written down before returning: from here on the file EXISTS and is paid for, and the only
101
112
  // thing still missing is the account's own list. Losing the record now would make it
102
113
  // unreachable.
103
- await writeItemRecord(fileKey, { attempt, itemId: view.id });
114
+ await writeItemRecord(fileKey, { ...record, itemId: view.id });
104
115
  return view.id;
105
116
  }
106
117
  /**
@@ -95,14 +95,21 @@ export interface Reservation {
95
95
  /**
96
96
  * How many reservations this file has needed. Part of the idempotency key.
97
97
  *
98
- * ⛔ WITHOUT IT, A FAILED RESERVATION BRICKS THIS FILE FOREVER. The idempotency key is derived
99
- * from a key that is a pure function of (account, bytes, destination), and the server replays
100
- * a reservation row under its key WHATEVER STATE IT IS IN — including `failed`, which can
101
- * never become storage. So every later attempt would be handed the same dead row, be told to
102
- * start over, start over into the same dead row, and this account could never upload this
103
- * file again unless a byte of it changed. Counting up is what "start over" actually means.
98
+ * ⛔ WITHOUT IT, A FAILED RESERVATION BRICKS THIS UPLOAD. A resume asks under the key this
99
+ * record names, and the server replays a reservation row under its key WHATEVER STATE IT IS
100
+ * IN — including `failed`, which can never become storage. So every later attempt would be
101
+ * handed the same dead row, be told to start over, and start over into the same dead row.
102
+ * Counting up is what "start over" actually means.
104
103
  */
105
104
  attempt: number;
105
+ /**
106
+ * Which UPLOAD of this file wrote the record — `newRunId` in `upload-run.ts` says why it exists.
107
+ * Part of the idempotency key.
108
+ *
109
+ * ⚠ ABSENT ON A RECORD AN EARLIER VERSION WROTE, and then the key is the one that version used:
110
+ * the reservation it may already have paid for is filed under that key and nowhere else.
111
+ */
112
+ runId?: string;
106
113
  /** Present once the server answered: the reservation row. */
107
114
  ledgerId?: number;
108
115
  /** Present once registered: the transaction the relay checks its tip in. */
@@ -183,6 +190,8 @@ export interface ItemRecord {
183
190
  * storage twice says nothing about how many times the file was committed.
184
191
  */
185
192
  attempt: number;
193
+ /** The upload that attempted the commit. Absent on a record an earlier version wrote. */
194
+ runId?: string;
186
195
  }
187
196
  /** What is known about this file's commit, or `null` when it has not been attempted. */
188
197
  export declare function readItemRecord(fileKey: string): Promise<ItemRecord | null>;
@@ -100,6 +100,9 @@ function isReservation(value) {
100
100
  if (typeof Reflect.get(value, name) !== "number")
101
101
  return false;
102
102
  }
103
+ const runId = Reflect.get(value, "runId");
104
+ if (runId !== undefined && typeof runId !== "string")
105
+ return false;
103
106
  const parent = Reflect.get(value, "parentId");
104
107
  return parent === null || typeof parent === "string";
105
108
  }
@@ -201,6 +204,9 @@ function isItemRecord(value) {
201
204
  return false;
202
205
  if (typeof Reflect.get(value, "attempt") !== "number")
203
206
  return false;
207
+ const runId = Reflect.get(value, "runId");
208
+ if (runId !== undefined && typeof runId !== "string")
209
+ return false;
204
210
  const id = Reflect.get(value, "itemId");
205
211
  return id === undefined || typeof id === "string";
206
212
  }
@@ -1,12 +1,14 @@
1
- import type { OnCollision } from "./collision.ts";
1
+ import type { CollisionAsk } from "./collision.ts";
2
2
  import { type CryptoGlue } from "./crypto.ts";
3
3
  import type { Network } from "./network.ts";
4
4
  import type { PaddingRule } from "./shared/lib/crypto/size-padding.ts";
5
5
  import { type FileUploadStep, type PlaintextSource } from "./upload-file.ts";
6
6
  import { type StorageChoice, type UploadBudget, type WalletUploadReads } from "./upload-wallet-plan.ts";
7
- import type { BlobProtocol, UploadApi } from "./upload-wire.ts";
7
+ import { type BlobProtocol, type UploadApi } from "./upload-wire.ts";
8
8
  import type { Spend } from "./wallet-grant.ts";
9
9
  import type { SignBlobCertify, SignBlobRegister } from "./wallet-sign.ts";
10
+ /** The `code` of the refusal a wallet known to be short of either coin is answered with. */
11
+ export declare const WALLET_SHORT = "WALLET_SHORT";
10
12
  /** The account this upload belongs to, and how it seals. */
11
13
  export interface WalletPutContext {
12
14
  /** ⛔ The NMTS key. It seals the file AND derives the wallet that pays. It is never written down. */
@@ -20,8 +22,11 @@ export interface WalletPutContext {
20
22
  partSize: number;
21
23
  /** The rounding rule from the account's sealed list — it changes the stored size, so the price. */
22
24
  rule: PaddingRule;
23
- /** What to do about a name already in use. Absent = the machine's setting, as `addEntry` reads it. */
24
- onCollision?: OnCollision | undefined;
25
+ /**
26
+ * What to do about a name already in use, for this upload. Absent = the machine's setting, as
27
+ * `addEntry` reads it; a bare word is a command line's and is held to the modes (`collision.ts`).
28
+ */
29
+ onCollision?: CollisionAsk | undefined;
25
30
  /**
26
31
  * Which of this key's wallets pays, by index (0 = the first one).
27
32
  *
@@ -54,6 +59,8 @@ export interface WalletPutFile {
54
59
  parentId: string | null;
55
60
  /** The destination AS TYPED — part of the reservation key, so both runs of a resume agree. */
56
61
  destination: string;
62
+ /** A video's preview picture: the video's item id, written on the entry as `thumbOf`. */
63
+ thumbOf?: string | undefined;
57
64
  }
58
65
  /** The chain, the signatures, the wire and the four things a caller may be told. */
59
66
  export interface WalletPutSeams {
@@ -38,13 +38,16 @@ import { addEntry } from "./manifest-write.js";
38
38
  import { sealedLenFor } from "./seal.js";
39
39
  import { statusOf } from "./shared/lib/storage-control/plan.js";
40
40
  import { createUploadApi } from "./upload-api.js";
41
- import { partKeysOf, uploadFile } from "./upload-file.js";
41
+ import { uploadFile } from "./upload-file.js";
42
42
  import { CREDIT_BYTES, planAndPrice } from "./upload-price.js";
43
- import { clearItemRecord, clearReservation } from "./upload-store.js";
43
+ import { forgetUpload } from "./upload-run.js";
44
44
  import { walletRail } from "./upload-wallet.js";
45
45
  import { chooseUploadEpochs, daysOf, parseStorageAsk, pickResource, uploadBudget, uploadShortfallNextStep, } from "./upload-wallet-plan.js";
46
+ import { UploadError } from "./upload-wire.js";
46
47
  import { walletAddress } from "./wallet.js";
47
48
  import { createBlobProtocol } from "./walrus-write.js";
49
+ /** The `code` of the refusal a wallet known to be short of either coin is answered with. */
50
+ export const WALLET_SHORT = "WALLET_SHORT";
48
51
  /**
49
52
  * Price, agree, sign, upload and record ONE file, paid from the wallet the NMTS key derives.
50
53
  *
@@ -130,8 +133,17 @@ export async function walletPut(ctx, file, seams = {}) {
130
133
  if (seams.dryRun === true)
131
134
  return { kind: "review", review };
132
135
  // ⛔ A WALLET KNOWN TO BE SHORT IS REFUSED BEFORE THE AGREEMENT IS ASKED FOR (`extend-budget.ts`).
136
+ // As the refusal a program branches on: `WALLET_SHORT`, where a credit shortfall carries the
137
+ // server's own code.
133
138
  if (budget.shortfall !== null) {
134
- throw new NmtsError(budget.shortfall, { exitCode: 4, nextStep: uploadShortfallNextStep(budget) });
139
+ throw new UploadError({
140
+ phase: "reserve",
141
+ message: budget.shortfall,
142
+ paid: false,
143
+ nextStep: uploadShortfallNextStep(budget),
144
+ exitCode: 4,
145
+ code: WALLET_SHORT,
146
+ });
135
147
  }
136
148
  seams.agree?.(review);
137
149
  const sign = seams.sign ?? (await signers());
@@ -194,14 +206,13 @@ export async function walletPut(ctx, file, seams = {}) {
194
206
  updatedAt: now,
195
207
  dekWrapped: result.entry.dekWrapped,
196
208
  contentHashCt: result.entry.contentHashCt,
209
+ ...(file.thumbOf !== undefined ? { thumbOf: file.thumbOf } : {}),
197
210
  },
198
211
  });
199
212
  // ⛔ ONLY NOW, AND EVERY PART — the same order the credit rail keeps and for the same reason: a
200
213
  // paid-for file the list does not name is invisible, and the records are what let a second
201
214
  // call finish the job without signing again.
202
- await clearItemRecord(result.fileKey);
203
- for (const record of partKeysOf(result.fileKey, result.parts))
204
- await clearReservation(record);
215
+ await forgetUpload(result.fileKey, result.parts);
205
216
  if (added.replaced)
206
217
  await setTrashed(ctx.server, ctx.apiKey, added.replaced.id, true);
207
218
  return {
@@ -20,6 +20,7 @@
20
20
  // reach them.
21
21
  import { fromBase64Url, toBase64Url } from "./bytes.js";
22
22
  import { NmtsError } from "./errors.js";
23
+ import { refuseOtherSealing, runIdField } from "./upload-run.js";
23
24
  import { readReservationBytes, readReservationRecord, writeReservation } from "./upload-store.js";
24
25
  import { UploadError } from "./upload-wire.js";
25
26
  function why(error) {
@@ -64,6 +65,8 @@ async function buyAndPushPartWithWallet(ctx, input) {
64
65
  "records to start over. Nothing was sent.",
65
66
  });
66
67
  }
68
+ // ⛔ A record another sealing of this file wrote is refused, not resumed (`upload-run.ts`).
69
+ refuseOtherSealing(existing, input);
67
70
  // ── already certified: nothing left to sign or send ──
68
71
  if (existing?.certifyTxDigest !== undefined) {
69
72
  onStep?.({ step: "resuming", ledgerId: 0, state: "certified" });
@@ -95,6 +98,7 @@ async function buyAndPushPartWithWallet(ctx, input) {
95
98
  }
96
99
  const record = {
97
100
  attempt: existing?.attempt ?? 0,
101
+ ...runIdField(existing, input.runId),
98
102
  paidFrom: "wallet",
99
103
  blobId: meta.blobId,
100
104
  nonceB64: toBase64Url(meta.nonce),
@@ -108,15 +108,35 @@ export type UploadStep = {
108
108
  * advice. After it, the credits are gone and the storage exists; the honest advice is that the
109
109
  * same command will FINISH it rather than buy it again, and that saying otherwise would send
110
110
  * somebody to spend twice.
111
+ *
112
+ * ⛔ AND A REFUSAL KEEPS WHAT THE SERVER SAID ABOUT ITSELF. A program deciding whether to top up,
113
+ * wait or give up reads `code`, `status` and `retryAfter`; the sentence is for a person, and a
114
+ * program that matched on it would break the day it was reworded.
111
115
  */
112
116
  export declare class UploadError extends NmtsError {
113
117
  readonly phase: UploadPhase;
114
118
  readonly paid: boolean;
119
+ /**
120
+ * The server's own code when the server refused, exactly as `ServerError.code` carries it — or
121
+ * `WALLET_SHORT` when the paying wallet was known to be short before anything was signed.
122
+ * Absent for every other failure.
123
+ */
124
+ readonly code?: string | undefined;
125
+ /** The HTTP status the server answered with. Absent when no answer came back. */
126
+ readonly status?: number | undefined;
127
+ /** Seconds to wait before asking again, from the server's `Retry-After`; null when it named none. */
128
+ readonly retryAfter?: number | null | undefined;
115
129
  constructor(input: {
116
130
  phase: UploadPhase;
117
131
  message: string;
118
132
  paid: boolean;
119
133
  nextStep?: string | null;
134
+ /** 1 unless this refusal has an exit code of its own. */
135
+ exitCode?: number;
136
+ /** What this refusal is known by, when it is not the server's to name. */
137
+ code?: string;
138
+ /** The failure this one wraps. A server refusal's code, status and wait are carried over. */
139
+ from?: unknown;
120
140
  });
121
141
  }
122
142
  /**
@@ -130,6 +150,11 @@ export declare class UploadError extends NmtsError {
130
150
  */
131
151
  export interface CommitInput {
132
152
  api: UploadApi;
153
+ /**
154
+ * This upload's run id (`newRunId` in `upload-store.ts`): what every NEW record is written with,
155
+ * and what makes this upload's idempotency keys its own rather than the last upload's.
156
+ */
157
+ runId: string;
133
158
  /** Storage term in storage-network epochs. */
134
159
  epochs: number;
135
160
  /** The current storage-network epoch, or null when it could not be read. */
@@ -4,6 +4,7 @@
4
4
  // ⛔ SEPARATE FROM THE MACHINE ON PURPOSE. `upload.ts` is a sequence of decisions about spending;
5
5
  // keeping the vocabulary here means a test can name every seam without importing that sequence,
6
6
  // and means the file that DOES spend stays short enough to read in one sitting.
7
+ import { HttpError, ServerError } from "./api.js";
7
8
  import { NmtsError } from "./errors.js";
8
9
  /**
9
10
  * A failure that names its phase — and, crucially, whether the account has already paid.
@@ -12,14 +13,32 @@ import { NmtsError } from "./errors.js";
12
13
  * advice. After it, the credits are gone and the storage exists; the honest advice is that the
13
14
  * same command will FINISH it rather than buy it again, and that saying otherwise would send
14
15
  * somebody to spend twice.
16
+ *
17
+ * ⛔ AND A REFUSAL KEEPS WHAT THE SERVER SAID ABOUT ITSELF. A program deciding whether to top up,
18
+ * wait or give up reads `code`, `status` and `retryAfter`; the sentence is for a person, and a
19
+ * program that matched on it would break the day it was reworded.
15
20
  */
16
21
  export class UploadError extends NmtsError {
17
22
  phase;
18
23
  paid;
24
+ /**
25
+ * The server's own code when the server refused, exactly as `ServerError.code` carries it — or
26
+ * `WALLET_SHORT` when the paying wallet was known to be short before anything was signed.
27
+ * Absent for every other failure.
28
+ */
29
+ code;
30
+ /** The HTTP status the server answered with. Absent when no answer came back. */
31
+ status;
32
+ /** Seconds to wait before asking again, from the server's `Retry-After`; null when it named none. */
33
+ retryAfter;
19
34
  constructor(input) {
20
- super(input.message, { exitCode: 1, nextStep: input.nextStep ?? null });
35
+ super(input.message, { exitCode: input.exitCode ?? 1, nextStep: input.nextStep ?? null });
21
36
  this.name = "UploadError";
22
37
  this.phase = input.phase;
23
38
  this.paid = input.paid;
39
+ const from = input.from;
40
+ this.code = from instanceof ServerError ? from.code : input.code;
41
+ this.status = from instanceof ServerError || from instanceof HttpError ? from.status : undefined;
42
+ this.retryAfter = from instanceof ServerError ? from.retryAfter : undefined;
24
43
  }
25
44
  }