@backblaze-labs/b2-sdk 0.3.0 → 0.4.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 (393) hide show
  1. package/CHANGELOG.md +45 -1
  2. package/README.md +18 -5
  3. package/dist/_virtual/_b2-sdk-version-json.cjs +1 -1
  4. package/dist/_virtual/_b2-sdk-version-json.js +1 -1
  5. package/dist/auth/reauth-coalescer.cjs +65 -0
  6. package/dist/auth/reauth-coalescer.cjs.map +1 -0
  7. package/dist/auth/reauth-coalescer.d.cts +34 -0
  8. package/dist/auth/reauth-coalescer.d.cts.map +1 -0
  9. package/dist/auth/reauth-coalescer.d.ts +34 -0
  10. package/dist/auth/reauth-coalescer.d.ts.map +1 -0
  11. package/dist/auth/reauth-coalescer.js +65 -0
  12. package/dist/auth/reauth-coalescer.js.map +1 -0
  13. package/dist/backup/raw.cjs +37 -15
  14. package/dist/backup/raw.cjs.map +1 -1
  15. package/dist/backup/raw.d.cts +2 -2
  16. package/dist/backup/raw.d.cts.map +1 -1
  17. package/dist/backup/raw.d.ts +2 -2
  18. package/dist/backup/raw.d.ts.map +1 -1
  19. package/dist/backup/raw.js +37 -15
  20. package/dist/backup/raw.js.map +1 -1
  21. package/dist/bucket-validation.cjs +111 -0
  22. package/dist/bucket-validation.cjs.map +1 -0
  23. package/dist/bucket-validation.d.cts +27 -0
  24. package/dist/bucket-validation.d.cts.map +1 -0
  25. package/dist/bucket-validation.d.ts +27 -0
  26. package/dist/bucket-validation.d.ts.map +1 -0
  27. package/dist/bucket-validation.js +109 -0
  28. package/dist/bucket-validation.js.map +1 -0
  29. package/dist/bucket.cjs +123 -73
  30. package/dist/bucket.cjs.map +1 -1
  31. package/dist/bucket.d.cts +156 -61
  32. package/dist/bucket.d.cts.map +1 -1
  33. package/dist/bucket.d.ts +156 -61
  34. package/dist/bucket.d.ts.map +1 -1
  35. package/dist/bucket.js +123 -73
  36. package/dist/bucket.js.map +1 -1
  37. package/dist/client.cjs +29 -8
  38. package/dist/client.cjs.map +1 -1
  39. package/dist/client.d.cts +30 -9
  40. package/dist/client.d.cts.map +1 -1
  41. package/dist/client.d.ts +30 -9
  42. package/dist/client.d.ts.map +1 -1
  43. package/dist/client.js +29 -8
  44. package/dist/client.js.map +1 -1
  45. package/dist/download/single.cjs +38 -13
  46. package/dist/download/single.cjs.map +1 -1
  47. package/dist/download/single.d.cts +10 -4
  48. package/dist/download/single.d.cts.map +1 -1
  49. package/dist/download/single.d.ts +10 -4
  50. package/dist/download/single.d.ts.map +1 -1
  51. package/dist/download/single.js +38 -13
  52. package/dist/download/single.js.map +1 -1
  53. package/dist/errors/index.cjs +27 -4
  54. package/dist/errors/index.cjs.map +1 -1
  55. package/dist/errors/index.d.cts +15 -0
  56. package/dist/errors/index.d.cts.map +1 -1
  57. package/dist/errors/index.d.ts +15 -0
  58. package/dist/errors/index.d.ts.map +1 -1
  59. package/dist/errors/index.js +27 -5
  60. package/dist/errors/index.js.map +1 -1
  61. package/dist/http/non-idempotent-mutations.cjs +38 -0
  62. package/dist/http/non-idempotent-mutations.cjs.map +1 -0
  63. package/dist/http/non-idempotent-mutations.d.cts +25 -0
  64. package/dist/http/non-idempotent-mutations.d.cts.map +1 -0
  65. package/dist/http/non-idempotent-mutations.d.ts +25 -0
  66. package/dist/http/non-idempotent-mutations.d.ts.map +1 -0
  67. package/dist/http/non-idempotent-mutations.js +35 -0
  68. package/dist/http/non-idempotent-mutations.js.map +1 -0
  69. package/dist/http/transport.cjs +9 -8
  70. package/dist/http/transport.cjs.map +1 -1
  71. package/dist/http/transport.d.cts +5 -0
  72. package/dist/http/transport.d.cts.map +1 -1
  73. package/dist/http/transport.d.ts +5 -0
  74. package/dist/http/transport.d.ts.map +1 -1
  75. package/dist/http/transport.js +9 -8
  76. package/dist/http/transport.js.map +1 -1
  77. package/dist/http/user-agent.cjs +12 -1
  78. package/dist/http/user-agent.cjs.map +1 -1
  79. package/dist/http/user-agent.d.cts +8 -0
  80. package/dist/http/user-agent.d.cts.map +1 -1
  81. package/dist/http/user-agent.d.ts +8 -0
  82. package/dist/http/user-agent.d.ts.map +1 -1
  83. package/dist/http/user-agent.js +13 -3
  84. package/dist/http/user-agent.js.map +1 -1
  85. package/dist/index.cjs +25 -0
  86. package/dist/index.d.cts +10 -9
  87. package/dist/index.d.cts.map +1 -1
  88. package/dist/index.d.ts +10 -9
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.js +7 -6
  91. package/dist/notifications/index.cjs +3 -0
  92. package/dist/notifications/index.d.cts +2 -0
  93. package/dist/notifications/index.d.cts.map +1 -1
  94. package/dist/notifications/index.d.ts +2 -0
  95. package/dist/notifications/index.d.ts.map +1 -1
  96. package/dist/notifications/index.js +2 -1
  97. package/dist/object.cjs +12 -1
  98. package/dist/object.cjs.map +1 -1
  99. package/dist/object.d.cts +7 -1
  100. package/dist/object.d.cts.map +1 -1
  101. package/dist/object.d.ts +7 -1
  102. package/dist/object.d.ts.map +1 -1
  103. package/dist/object.js +12 -1
  104. package/dist/object.js.map +1 -1
  105. package/dist/partner/auth-core.cjs +4 -23
  106. package/dist/partner/auth-core.cjs.map +1 -1
  107. package/dist/partner/auth-core.d.cts +1 -1
  108. package/dist/partner/auth-core.d.cts.map +1 -1
  109. package/dist/partner/auth-core.d.ts +1 -1
  110. package/dist/partner/auth-core.d.ts.map +1 -1
  111. package/dist/partner/auth-core.js +5 -24
  112. package/dist/partner/auth-core.js.map +1 -1
  113. package/dist/partner/client.cjs +25 -10
  114. package/dist/partner/client.cjs.map +1 -1
  115. package/dist/partner/client.d.cts +32 -10
  116. package/dist/partner/client.d.cts.map +1 -1
  117. package/dist/partner/client.d.ts +32 -10
  118. package/dist/partner/client.d.ts.map +1 -1
  119. package/dist/partner/client.js +25 -10
  120. package/dist/partner/client.js.map +1 -1
  121. package/dist/partner/endpoint-url.cjs +1 -0
  122. package/dist/partner/endpoint-url.cjs.map +1 -1
  123. package/dist/partner/endpoint-url.d.cts +2 -0
  124. package/dist/partner/endpoint-url.d.cts.map +1 -1
  125. package/dist/partner/endpoint-url.d.ts +2 -0
  126. package/dist/partner/endpoint-url.d.ts.map +1 -1
  127. package/dist/partner/endpoint-url.js +1 -0
  128. package/dist/partner/endpoint-url.js.map +1 -1
  129. package/dist/partner/in-memory.cjs.map +1 -1
  130. package/dist/partner/in-memory.js.map +1 -1
  131. package/dist/partner/index.cjs +9 -0
  132. package/dist/partner/index.d.cts +11 -2
  133. package/dist/partner/index.d.cts.map +1 -1
  134. package/dist/partner/index.d.ts +11 -2
  135. package/dist/partner/index.d.ts.map +1 -1
  136. package/dist/partner/index.js +3 -1
  137. package/dist/partner/raw.cjs +52 -44
  138. package/dist/partner/raw.cjs.map +1 -1
  139. package/dist/partner/raw.d.cts +16 -19
  140. package/dist/partner/raw.d.cts.map +1 -1
  141. package/dist/partner/raw.d.ts +16 -19
  142. package/dist/partner/raw.d.ts.map +1 -1
  143. package/dist/partner/raw.js +52 -44
  144. package/dist/partner/raw.js.map +1 -1
  145. package/dist/partner/redaction.cjs +133 -108
  146. package/dist/partner/redaction.cjs.map +1 -1
  147. package/dist/partner/redaction.d.cts +47 -13
  148. package/dist/partner/redaction.d.cts.map +1 -1
  149. package/dist/partner/redaction.d.ts +47 -13
  150. package/dist/partner/redaction.d.ts.map +1 -1
  151. package/dist/partner/redaction.js +133 -109
  152. package/dist/partner/redaction.js.map +1 -1
  153. package/dist/raw/encoding.cjs +29 -10
  154. package/dist/raw/encoding.cjs.map +1 -1
  155. package/dist/raw/encoding.d.cts +3 -2
  156. package/dist/raw/encoding.d.cts.map +1 -1
  157. package/dist/raw/encoding.d.ts +3 -2
  158. package/dist/raw/encoding.d.ts.map +1 -1
  159. package/dist/raw/encoding.js +29 -10
  160. package/dist/raw/encoding.js.map +1 -1
  161. package/dist/raw/index.cjs +64 -39
  162. package/dist/raw/index.cjs.map +1 -1
  163. package/dist/raw/index.d.cts +21 -19
  164. package/dist/raw/index.d.cts.map +1 -1
  165. package/dist/raw/index.d.ts +21 -19
  166. package/dist/raw/index.d.ts.map +1 -1
  167. package/dist/raw/index.js +47 -40
  168. package/dist/raw/index.js.map +1 -1
  169. package/dist/raw/url.cjs.map +1 -1
  170. package/dist/raw/url.d.cts +3 -3
  171. package/dist/raw/url.d.ts +3 -3
  172. package/dist/raw/url.js.map +1 -1
  173. package/dist/simulator/index.cjs +456 -125
  174. package/dist/simulator/index.cjs.map +1 -1
  175. package/dist/simulator/index.d.cts +16 -1
  176. package/dist/simulator/index.d.cts.map +1 -1
  177. package/dist/simulator/index.d.ts +16 -1
  178. package/dist/simulator/index.d.ts.map +1 -1
  179. package/dist/simulator/index.js +449 -130
  180. package/dist/simulator/index.js.map +1 -1
  181. package/dist/simulator/partner-capabilities.cjs +77 -0
  182. package/dist/simulator/partner-capabilities.cjs.map +1 -0
  183. package/dist/simulator/partner-capabilities.d.cts +53 -0
  184. package/dist/simulator/partner-capabilities.d.cts.map +1 -0
  185. package/dist/simulator/partner-capabilities.d.ts +53 -0
  186. package/dist/simulator/partner-capabilities.d.ts.map +1 -0
  187. package/dist/simulator/partner-capabilities.js +73 -0
  188. package/dist/simulator/partner-capabilities.js.map +1 -0
  189. package/dist/simulator/partner.cjs +55 -61
  190. package/dist/simulator/partner.cjs.map +1 -1
  191. package/dist/simulator/partner.d.cts +5 -2
  192. package/dist/simulator/partner.d.cts.map +1 -1
  193. package/dist/simulator/partner.d.ts +5 -2
  194. package/dist/simulator/partner.d.ts.map +1 -1
  195. package/dist/simulator/partner.js +56 -61
  196. package/dist/simulator/partner.js.map +1 -1
  197. package/dist/simulator/validation.cjs +160 -30
  198. package/dist/simulator/validation.cjs.map +1 -1
  199. package/dist/simulator/validation.d.cts +28 -6
  200. package/dist/simulator/validation.d.cts.map +1 -1
  201. package/dist/simulator/validation.d.ts +28 -6
  202. package/dist/simulator/validation.d.ts.map +1 -1
  203. package/dist/simulator/validation.js +148 -31
  204. package/dist/simulator/validation.js.map +1 -1
  205. package/dist/streams/file-source.cjs +1 -1
  206. package/dist/streams/file-source.cjs.map +1 -1
  207. package/dist/streams/file-source.js +1 -1
  208. package/dist/streams/file-source.js.map +1 -1
  209. package/dist/streams/hash.cjs +246 -13
  210. package/dist/streams/hash.cjs.map +1 -1
  211. package/dist/streams/hash.d.cts +37 -12
  212. package/dist/streams/hash.d.cts.map +1 -1
  213. package/dist/streams/hash.d.ts +37 -12
  214. package/dist/streams/hash.d.ts.map +1 -1
  215. package/dist/streams/hash.js +246 -15
  216. package/dist/streams/hash.js.map +1 -1
  217. package/dist/streams/index.cjs +2 -0
  218. package/dist/streams/index.d.cts +1 -1
  219. package/dist/streams/index.d.cts.map +1 -1
  220. package/dist/streams/index.d.ts +1 -1
  221. package/dist/streams/index.d.ts.map +1 -1
  222. package/dist/streams/index.js +2 -2
  223. package/dist/streams/progress.cjs +63 -4
  224. package/dist/streams/progress.cjs.map +1 -1
  225. package/dist/streams/progress.d.cts +28 -2
  226. package/dist/streams/progress.d.cts.map +1 -1
  227. package/dist/streams/progress.d.ts +28 -2
  228. package/dist/streams/progress.d.ts.map +1 -1
  229. package/dist/streams/progress.js +63 -4
  230. package/dist/streams/progress.js.map +1 -1
  231. package/dist/sync/download-staging.cjs +147 -35
  232. package/dist/sync/download-staging.cjs.map +1 -1
  233. package/dist/sync/download-staging.d.cts +25 -2
  234. package/dist/sync/download-staging.d.cts.map +1 -1
  235. package/dist/sync/download-staging.d.ts +25 -2
  236. package/dist/sync/download-staging.d.ts.map +1 -1
  237. package/dist/sync/download-staging.js +146 -36
  238. package/dist/sync/download-staging.js.map +1 -1
  239. package/dist/sync/index.d.cts +1 -1
  240. package/dist/sync/index.d.cts.map +1 -1
  241. package/dist/sync/index.d.ts +1 -1
  242. package/dist/sync/index.d.ts.map +1 -1
  243. package/dist/sync/local-file-io.cjs +5 -1
  244. package/dist/sync/local-file-io.cjs.map +1 -1
  245. package/dist/sync/local-file-io.d.cts +2 -0
  246. package/dist/sync/local-file-io.d.cts.map +1 -1
  247. package/dist/sync/local-file-io.d.ts +2 -0
  248. package/dist/sync/local-file-io.d.ts.map +1 -1
  249. package/dist/sync/local-file-io.js +5 -1
  250. package/dist/sync/local-file-io.js.map +1 -1
  251. package/dist/sync/pairing.cjs +1 -0
  252. package/dist/sync/pairing.cjs.map +1 -1
  253. package/dist/sync/pairing.js +1 -0
  254. package/dist/sync/pairing.js.map +1 -1
  255. package/dist/sync/scanners/b2.cjs +2 -0
  256. package/dist/sync/scanners/b2.cjs.map +1 -1
  257. package/dist/sync/scanners/b2.d.cts.map +1 -1
  258. package/dist/sync/scanners/b2.d.ts.map +1 -1
  259. package/dist/sync/scanners/b2.js +2 -0
  260. package/dist/sync/scanners/b2.js.map +1 -1
  261. package/dist/sync/scanners/local.cjs +150 -33
  262. package/dist/sync/scanners/local.cjs.map +1 -1
  263. package/dist/sync/scanners/local.d.cts +6 -0
  264. package/dist/sync/scanners/local.d.cts.map +1 -1
  265. package/dist/sync/scanners/local.d.ts +6 -0
  266. package/dist/sync/scanners/local.d.ts.map +1 -1
  267. package/dist/sync/scanners/local.js +150 -33
  268. package/dist/sync/scanners/local.js.map +1 -1
  269. package/dist/sync/synchronizer.cjs +76 -29
  270. package/dist/sync/synchronizer.cjs.map +1 -1
  271. package/dist/sync/synchronizer.d.cts +1 -0
  272. package/dist/sync/synchronizer.d.cts.map +1 -1
  273. package/dist/sync/synchronizer.d.ts +1 -0
  274. package/dist/sync/synchronizer.d.ts.map +1 -1
  275. package/dist/sync/synchronizer.js +76 -29
  276. package/dist/sync/synchronizer.js.map +1 -1
  277. package/dist/sync/types.d.cts +19 -3
  278. package/dist/sync/types.d.cts.map +1 -1
  279. package/dist/sync/types.d.ts +19 -3
  280. package/dist/sync/types.d.ts.map +1 -1
  281. package/dist/types/backup.d.cts +6 -1
  282. package/dist/types/backup.d.cts.map +1 -1
  283. package/dist/types/backup.d.ts +6 -1
  284. package/dist/types/backup.d.ts.map +1 -1
  285. package/dist/types/bucket.cjs +81 -11
  286. package/dist/types/bucket.cjs.map +1 -1
  287. package/dist/types/bucket.d.cts +190 -39
  288. package/dist/types/bucket.d.cts.map +1 -1
  289. package/dist/types/bucket.d.ts +190 -39
  290. package/dist/types/bucket.d.ts.map +1 -1
  291. package/dist/types/bucket.js +67 -12
  292. package/dist/types/bucket.js.map +1 -1
  293. package/dist/types/download.cjs.map +1 -1
  294. package/dist/types/download.d.cts +3 -17
  295. package/dist/types/download.d.cts.map +1 -1
  296. package/dist/types/download.d.ts +3 -17
  297. package/dist/types/download.d.ts.map +1 -1
  298. package/dist/types/download.js.map +1 -1
  299. package/dist/types/encryption.cjs +18 -0
  300. package/dist/types/encryption.cjs.map +1 -1
  301. package/dist/types/encryption.d.cts +21 -11
  302. package/dist/types/encryption.d.cts.map +1 -1
  303. package/dist/types/encryption.d.ts +21 -11
  304. package/dist/types/encryption.d.ts.map +1 -1
  305. package/dist/types/encryption.js +18 -0
  306. package/dist/types/encryption.js.map +1 -1
  307. package/dist/types/file.cjs +3 -0
  308. package/dist/types/file.cjs.map +1 -1
  309. package/dist/types/file.d.cts +125 -16
  310. package/dist/types/file.d.cts.map +1 -1
  311. package/dist/types/file.d.ts +125 -16
  312. package/dist/types/file.d.ts.map +1 -1
  313. package/dist/types/file.js +3 -1
  314. package/dist/types/file.js.map +1 -1
  315. package/dist/types/index.d.cts +7 -7
  316. package/dist/types/index.d.cts.map +1 -1
  317. package/dist/types/index.d.ts +7 -7
  318. package/dist/types/index.d.ts.map +1 -1
  319. package/dist/types/key.d.cts +4 -3
  320. package/dist/types/key.d.cts.map +1 -1
  321. package/dist/types/key.d.ts +4 -3
  322. package/dist/types/key.d.ts.map +1 -1
  323. package/dist/types/notifications.cjs +30 -0
  324. package/dist/types/notifications.cjs.map +1 -1
  325. package/dist/types/notifications.d.cts +26 -1
  326. package/dist/types/notifications.d.cts.map +1 -1
  327. package/dist/types/notifications.d.ts +26 -1
  328. package/dist/types/notifications.d.ts.map +1 -1
  329. package/dist/types/notifications.js +29 -1
  330. package/dist/types/notifications.js.map +1 -1
  331. package/dist/types/partner.cjs.map +1 -1
  332. package/dist/types/partner.d.cts +28 -36
  333. package/dist/types/partner.d.cts.map +1 -1
  334. package/dist/types/partner.d.ts +28 -36
  335. package/dist/types/partner.d.ts.map +1 -1
  336. package/dist/types/partner.js.map +1 -1
  337. package/dist/types/upload.d.cts +4 -0
  338. package/dist/types/upload.d.cts.map +1 -1
  339. package/dist/types/upload.d.ts +4 -0
  340. package/dist/types/upload.d.ts.map +1 -1
  341. package/dist/upload/large.cjs +10 -7
  342. package/dist/upload/large.cjs.map +1 -1
  343. package/dist/upload/large.d.cts +15 -6
  344. package/dist/upload/large.d.cts.map +1 -1
  345. package/dist/upload/large.d.ts +15 -6
  346. package/dist/upload/large.d.ts.map +1 -1
  347. package/dist/upload/large.js +10 -7
  348. package/dist/upload/large.js.map +1 -1
  349. package/dist/upload/options.cjs.map +1 -1
  350. package/dist/upload/options.d.cts +12 -0
  351. package/dist/upload/options.d.cts.map +1 -1
  352. package/dist/upload/options.d.ts +12 -0
  353. package/dist/upload/options.d.ts.map +1 -1
  354. package/dist/upload/options.js.map +1 -1
  355. package/dist/upload/resume.cjs +4 -3
  356. package/dist/upload/resume.cjs.map +1 -1
  357. package/dist/upload/resume.d.cts +6 -4
  358. package/dist/upload/resume.d.cts.map +1 -1
  359. package/dist/upload/resume.d.ts +6 -4
  360. package/dist/upload/resume.d.ts.map +1 -1
  361. package/dist/upload/resume.js +4 -3
  362. package/dist/upload/resume.js.map +1 -1
  363. package/dist/upload/retry.cjs +17 -10
  364. package/dist/upload/retry.cjs.map +1 -1
  365. package/dist/upload/retry.d.cts.map +1 -1
  366. package/dist/upload/retry.d.ts.map +1 -1
  367. package/dist/upload/retry.js +17 -10
  368. package/dist/upload/retry.js.map +1 -1
  369. package/dist/upload/single.cjs +35 -31
  370. package/dist/upload/single.cjs.map +1 -1
  371. package/dist/upload/single.d.cts +6 -0
  372. package/dist/upload/single.d.cts.map +1 -1
  373. package/dist/upload/single.d.ts +6 -0
  374. package/dist/upload/single.d.ts.map +1 -1
  375. package/dist/upload/single.js +35 -31
  376. package/dist/upload/single.js.map +1 -1
  377. package/dist/upload/stream.cjs +12 -1
  378. package/dist/upload/stream.cjs.map +1 -1
  379. package/dist/upload/stream.d.cts +6 -0
  380. package/dist/upload/stream.d.cts.map +1 -1
  381. package/dist/upload/stream.d.ts +6 -0
  382. package/dist/upload/stream.d.ts.map +1 -1
  383. package/dist/upload/stream.js +12 -1
  384. package/dist/upload/stream.js.map +1 -1
  385. package/dist/version.cjs +56 -4
  386. package/dist/version.cjs.map +1 -1
  387. package/dist/version.d.cts +53 -4
  388. package/dist/version.d.cts.map +1 -1
  389. package/dist/version.d.ts +53 -4
  390. package/dist/version.d.ts.map +1 -1
  391. package/dist/version.js +52 -5
  392. package/dist/version.js.map +1 -1
  393. package/package.json +11 -4
package/dist/index.d.ts CHANGED
@@ -9,31 +9,32 @@
9
9
  */
10
10
  export type { AccountInfo, AuthContextAwareAccountInfo, UploadUrlEntry, } from './auth/account-info.js';
11
11
  export { InMemoryAccountInfo } from './auth/in-memory.js';
12
- export { Bucket, type DeleteAllDeleteEvent, type DeleteAllErrorEvent, type DeleteAllEvent, type DeleteAllSkipEvent, type DeleteError, type DeleteManyResult, type DeleteTarget, } from './bucket.js';
13
- export { B2Client, type B2ClientOptions, type CapabilityCheckResult } from './client.js';
12
+ export { Bucket, type BucketListFileNamesBaseOptions, type BucketListFileNamesMaybeDelimiterOptions, type BucketListFileNamesOptions, type BucketListFileNamesWithDelimiterOptions, type BucketListFileVersionsBaseOptions, type BucketListFileVersionsMaybeDelimiterOptions, type BucketListFileVersionsOptions, type BucketListFileVersionsWithDelimiterOptions, type BucketPaginateFileNamesMaybeDelimiterOptions, type BucketPaginateFileNamesOptions, type BucketPaginateFileNamesWithDelimiterOptions, type BucketPaginateFileVersionsMaybeDelimiterOptions, type BucketPaginateFileVersionsOptions, type BucketPaginateFileVersionsWithDelimiterOptions, type DeleteAllDeleteEvent, type DeleteAllErrorEvent, type DeleteAllEvent, type DeleteAllSkipEvent, type DeleteError, type DeleteManyResult, type DeleteTarget, } from './bucket.js';
13
+ export { assertValidBucketConfiguration, assertValidBucketInfo, assertValidCorsRules, } from './bucket-validation.js';
14
+ export { B2Client, type B2ClientAuthorizeOptions, type B2ClientOptions, type CapabilityCheckResult, } from './client.js';
14
15
  export type { DownloadResult, HeadResult } from './download/single.js';
15
- export type { B2ErrorOptions } from './errors/index.js';
16
- export { AccessDeniedError, B2Error, B2InsufficientCapabilityError, B2PartnerAuthorizationError, B2RealmConfigurationError, B2RedirectError, B2SsrfError, BadAuthTokenError, BadBucketIdError, BadJsonError, BadRequestError, BadUploadUrlError, CapExceededError, ChecksumMismatchError, ConflictError, classifyError, DuplicateBucketNameError, ExpiredAuthTokenError, FileNotPresentError, FinishLargeFileResponseBodyError, GroupMemberCreationFailedError, InternalError, InvalidAccountIdError, InvalidBucketIdError, InvalidBucketInfoError, InvalidBucketNameError, InvalidComputerIdError, InvalidEmailError, InvalidFileIdError, InvalidFileInfoError, InvalidFileNameError, InvalidGroupIdError, InvalidMemberAccountIdError, InvalidPartNumberError, InvalidRegionError, InvalidSmsPhoneError, MethodFailureError, MethodNotAllowedError, MissingSmsPhoneError, NetworkError, NotFoundError, OutOfRangeError, RangeNotSatisfiableError, RequestTimeoutError, ResumeFileIdMismatchError, ServiceUnavailableError, TooManyBucketsError, TooManyFilesError, TooManyGroupMembersError, TooManyMembersError, TooManyRequestsError, UploadResponseBodyError, } from './errors/index.js';
16
+ export type { B2BucketConfigurationErrorField, B2ErrorOptions } from './errors/index.js';
17
+ export { AccessDeniedError, B2BucketConfigurationError, B2Error, B2InsufficientCapabilityError, B2PartnerAuthorizationError, B2RealmConfigurationError, B2RedirectError, B2SsrfError, BadAuthTokenError, BadBucketIdError, BadJsonError, BadRequestError, BadUploadUrlError, CapExceededError, ChecksumMismatchError, ConflictError, classifyError, DuplicateBucketNameError, ExpiredAuthTokenError, FileNotPresentError, FinishLargeFileResponseBodyError, GroupMemberCreationFailedError, InternalError, InvalidAccountIdError, InvalidBucketIdError, InvalidBucketInfoError, InvalidBucketNameError, InvalidComputerIdError, InvalidEmailError, InvalidFileIdError, InvalidFileInfoError, InvalidFileNameError, InvalidGroupIdError, InvalidMemberAccountIdError, InvalidPartNumberError, InvalidRegionError, InvalidSmsPhoneError, MethodFailureError, MethodNotAllowedError, MissingSmsPhoneError, NetworkError, NotFoundError, OutOfRangeError, RangeNotSatisfiableError, RequestTimeoutError, ResumeFileIdMismatchError, ServiceUnavailableError, TooManyBucketsError, TooManyFilesError, TooManyGroupMembersError, TooManyMembersError, TooManyRequestsError, UploadResponseBodyError, } from './errors/index.js';
17
18
  export type { RetryOptions } from './http/retry.js';
18
19
  export type { HttpRequest, HttpResponse, HttpTransport, RetryTransportOptions, UrlGuardedTransport, } from './http/transport.js';
19
20
  export { FetchTransport, getTransportUrlGuard, RetryTransport } from './http/transport.js';
20
21
  export { deriveAllowedSuffixes, UrlGuard } from './http/url-guard.js';
21
22
  export { B2Object, type DownloadCallOptions, type HeadCallOptions } from './object.js';
22
- export { type DownloadFileOptions, RawClient, type RawClientOptions, type RawRequestOptions, type SseCDownloadKey, } from './raw/index.js';
23
- export { IncrementalSha1, sha1Hex } from './streams/hash.js';
23
+ export { type AuthorizeAccountOptions, type DownloadFileOptions, RawClient, type RawClientOptions, type RawRequestOptions, type SseCDownloadKey, } from './raw/index.js';
24
+ export { IncrementalSha1, IncrementalSha256, sha1Hex, sha256Hex } from './streams/hash.js';
24
25
  export type { ProgressEvent, ProgressListener } from './streams/progress.js';
25
26
  export type { ContentSource, FileSourcePath } from './streams/source.js';
26
27
  export { BlobSource, BufferSource, FileSource, StreamSource, toContentSource, } from './streams/source.js';
27
28
  export { Capability } from './types/auth.js';
28
- export { BucketRetentionMode, BucketType, CorsOperation } from './types/bucket.js';
29
+ export { BUCKET_INFO_KEY_MAX_BYTES, BUCKET_INFO_KEY_MIN_BYTES, BUCKET_INFO_KEY_PATTERN, BUCKET_INFO_RESERVED_PREFIX, BUCKET_INFO_VALUES_MAX_BYTES, BucketKeyOption, BucketRetentionMode, BucketType, CORS_ALLOWED_OPERATIONS, CORS_MAX_AGE_SECONDS_MAX, CORS_RULE_MAX_BYTES, CORS_RULE_NAME_MAX_LENGTH, CORS_RULE_NAME_MIN_LENGTH, CORS_RULE_NAME_PATTERN, CORS_RULE_NAME_RESERVED_PREFIX, CORS_RULES_MAX_COUNT, CorsOperation, KnownBucketResponseType, } from './types/bucket.js';
29
30
  export { DownloadClientUnauthorizedToReadMarker, DownloadHeaderName, } from './types/download.js';
30
31
  export { EncryptionAlgorithm, EncryptionKey, EncryptionMode, SSE_B2, SSE_NONE, sseCustomer, } from './types/encryption.js';
31
32
  export { KNOWN_B2_ERROR_CODES } from './types/errors.js';
32
- export { FileAction, MetadataDirective } from './types/file.js';
33
+ export { FileAction, HIDE_MARKER_CONTENT_TYPE, MetadataDirective } from './types/file.js';
33
34
  export { accountId, applicationKeyId, bucketId, computerId, fileId, groupId, keyId, largeFileId, partnerToken, } from './types/ids.js';
34
35
  export type * from './types/index.js';
35
36
  export { LegalHoldValue, RetentionMode } from './types/lock.js';
36
- export { EventType } from './types/notifications.js';
37
+ export { EventType, notificationCustomHeadersToRecord, recordToNotificationCustomHeaders, } from './types/notifications.js';
37
38
  export { PartnerCapability, Region } from './types/partner.js';
38
39
  export type { AmbiguousFinishCleanupFailureEvent, CancelLargeFileCleanupFailureEvent, CleanupFailureEvent, CleanupFailureListener, CleanupFailureOptions, } from './upload/cancel.js';
39
40
  export type { ResumePartReusedEvent, ResumePartReusedListener, } from './upload/large.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,YAAY,EACV,WAAW,EACX,2BAA2B,EAC3B,cAAc,GACf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzD,OA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9B,MAAM,oBAAoB,CAAA;AAC3B,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAClG,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAIxE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -1,24 +1,25 @@
1
1
  import { InMemoryAccountInfo } from "./auth/in-memory.js";
2
- import { FileAction, MetadataDirective } from "./types/file.js";
2
+ import { FileAction, HIDE_MARKER_CONTENT_TYPE, MetadataDirective } from "./types/file.js";
3
3
  import { accountId, applicationKeyId, bucketId, computerId, fileId, groupId, keyId, largeFileId, partnerToken } from "./types/ids.js";
4
4
  import { KNOWN_B2_ERROR_CODES } from "./types/errors.js";
5
- import { AccessDeniedError, B2Error, B2InsufficientCapabilityError, B2PartnerAuthorizationError, B2RealmConfigurationError, B2RedirectError, B2SsrfError, BadAuthTokenError, BadBucketIdError, BadJsonError, BadRequestError, BadUploadUrlError, CapExceededError, ChecksumMismatchError, ConflictError, DuplicateBucketNameError, ExpiredAuthTokenError, FileNotPresentError, FinishLargeFileResponseBodyError, GroupMemberCreationFailedError, InternalError, InvalidAccountIdError, InvalidBucketIdError, InvalidBucketInfoError, InvalidBucketNameError, InvalidComputerIdError, InvalidEmailError, InvalidFileIdError, InvalidFileInfoError, InvalidFileNameError, InvalidGroupIdError, InvalidMemberAccountIdError, InvalidPartNumberError, InvalidRegionError, InvalidSmsPhoneError, MethodFailureError, MethodNotAllowedError, MissingSmsPhoneError, NetworkError, NotFoundError, OutOfRangeError, RangeNotSatisfiableError, RequestTimeoutError, ResumeFileIdMismatchError, ServiceUnavailableError, TooManyBucketsError, TooManyFilesError, TooManyGroupMembersError, TooManyMembersError, TooManyRequestsError, UploadResponseBodyError, classifyError } from "./errors/index.js";
5
+ import { AccessDeniedError, B2BucketConfigurationError, B2Error, B2InsufficientCapabilityError, B2PartnerAuthorizationError, B2RealmConfigurationError, B2RedirectError, B2SsrfError, BadAuthTokenError, BadBucketIdError, BadJsonError, BadRequestError, BadUploadUrlError, CapExceededError, ChecksumMismatchError, ConflictError, DuplicateBucketNameError, ExpiredAuthTokenError, FileNotPresentError, FinishLargeFileResponseBodyError, GroupMemberCreationFailedError, InternalError, InvalidAccountIdError, InvalidBucketIdError, InvalidBucketInfoError, InvalidBucketNameError, InvalidComputerIdError, InvalidEmailError, InvalidFileIdError, InvalidFileInfoError, InvalidFileNameError, InvalidGroupIdError, InvalidMemberAccountIdError, InvalidPartNumberError, InvalidRegionError, InvalidSmsPhoneError, MethodFailureError, MethodNotAllowedError, MissingSmsPhoneError, NetworkError, NotFoundError, OutOfRangeError, RangeNotSatisfiableError, RequestTimeoutError, ResumeFileIdMismatchError, ServiceUnavailableError, TooManyBucketsError, TooManyFilesError, TooManyGroupMembersError, TooManyMembersError, TooManyRequestsError, UploadResponseBodyError, classifyError } from "./errors/index.js";
6
6
  import { DownloadClientUnauthorizedToReadMarker, DownloadHeaderName } from "./types/download.js";
7
7
  import { EncryptionAlgorithm, EncryptionKey, EncryptionMode, SSE_B2, SSE_NONE, sseCustomer } from "./types/encryption.js";
8
8
  import { LegalHoldValue, RetentionMode } from "./types/lock.js";
9
- import { IncrementalSha1, sha1Hex } from "./streams/hash.js";
9
+ import { IncrementalSha1, IncrementalSha256, sha1Hex, sha256Hex } from "./streams/hash.js";
10
10
  import { FileSource } from "./streams/file-source.js";
11
11
  import { BlobSource, BufferSource, StreamSource, toContentSource } from "./streams/source.js";
12
- import { BucketRetentionMode, BucketType, CorsOperation } from "./types/bucket.js";
12
+ import { BUCKET_INFO_KEY_MAX_BYTES, BUCKET_INFO_KEY_MIN_BYTES, BUCKET_INFO_KEY_PATTERN, BUCKET_INFO_RESERVED_PREFIX, BUCKET_INFO_VALUES_MAX_BYTES, BucketKeyOption, BucketRetentionMode, BucketType, CORS_ALLOWED_OPERATIONS, CORS_MAX_AGE_SECONDS_MAX, CORS_RULES_MAX_COUNT, CORS_RULE_MAX_BYTES, CORS_RULE_NAME_MAX_LENGTH, CORS_RULE_NAME_MIN_LENGTH, CORS_RULE_NAME_PATTERN, CORS_RULE_NAME_RESERVED_PREFIX, CorsOperation, KnownBucketResponseType } from "./types/bucket.js";
13
13
  import { B2Object } from "./object.js";
14
14
  import { paginateItems, paginatePages } from "./util/paginator.js";
15
15
  import { Bucket } from "./bucket.js";
16
+ import { assertValidBucketConfiguration, assertValidBucketInfo, assertValidCorsRules } from "./bucket-validation.js";
16
17
  import { UrlGuard, deriveAllowedSuffixes } from "./http/url-guard.js";
17
18
  import { VERSION } from "./version.js";
18
19
  import { FetchTransport, RetryTransport, getTransportUrlGuard } from "./http/transport.js";
19
20
  import { RawClient } from "./raw/index.js";
20
21
  import { B2Client } from "./client.js";
21
22
  import { Capability } from "./types/auth.js";
22
- import { EventType } from "./types/notifications.js";
23
+ import { EventType, notificationCustomHeadersToRecord, recordToNotificationCustomHeaders } from "./types/notifications.js";
23
24
  import { PartnerCapability, Region } from "./types/partner.js";
24
- export { AccessDeniedError, B2Client, B2Error, B2InsufficientCapabilityError, B2Object, B2PartnerAuthorizationError, B2RealmConfigurationError, B2RedirectError, B2SsrfError, BadAuthTokenError, BadBucketIdError, BadJsonError, BadRequestError, BadUploadUrlError, BlobSource, Bucket, BucketRetentionMode, BucketType, BufferSource, CapExceededError, Capability, ChecksumMismatchError, ConflictError, CorsOperation, DownloadClientUnauthorizedToReadMarker, DownloadHeaderName, DuplicateBucketNameError, EncryptionAlgorithm, EncryptionKey, EncryptionMode, EventType, ExpiredAuthTokenError, FetchTransport, FileAction, FileNotPresentError, FileSource, FinishLargeFileResponseBodyError, GroupMemberCreationFailedError, InMemoryAccountInfo, IncrementalSha1, InternalError, InvalidAccountIdError, InvalidBucketIdError, InvalidBucketInfoError, InvalidBucketNameError, InvalidComputerIdError, InvalidEmailError, InvalidFileIdError, InvalidFileInfoError, InvalidFileNameError, InvalidGroupIdError, InvalidMemberAccountIdError, InvalidPartNumberError, InvalidRegionError, InvalidSmsPhoneError, KNOWN_B2_ERROR_CODES, LegalHoldValue, MetadataDirective, MethodFailureError, MethodNotAllowedError, MissingSmsPhoneError, NetworkError, NotFoundError, OutOfRangeError, PartnerCapability, RangeNotSatisfiableError, RawClient, Region, RequestTimeoutError, ResumeFileIdMismatchError, RetentionMode, RetryTransport, SSE_B2, SSE_NONE, ServiceUnavailableError, StreamSource, TooManyBucketsError, TooManyFilesError, TooManyGroupMembersError, TooManyMembersError, TooManyRequestsError, UploadResponseBodyError, UrlGuard, VERSION, accountId, applicationKeyId, bucketId, classifyError, computerId, deriveAllowedSuffixes, fileId, getTransportUrlGuard, groupId, keyId, largeFileId, paginateItems, paginatePages, partnerToken, sha1Hex, sseCustomer, toContentSource };
25
+ export { AccessDeniedError, B2BucketConfigurationError, B2Client, B2Error, B2InsufficientCapabilityError, B2Object, B2PartnerAuthorizationError, B2RealmConfigurationError, B2RedirectError, B2SsrfError, BUCKET_INFO_KEY_MAX_BYTES, BUCKET_INFO_KEY_MIN_BYTES, BUCKET_INFO_KEY_PATTERN, BUCKET_INFO_RESERVED_PREFIX, BUCKET_INFO_VALUES_MAX_BYTES, BadAuthTokenError, BadBucketIdError, BadJsonError, BadRequestError, BadUploadUrlError, BlobSource, Bucket, BucketKeyOption, BucketRetentionMode, BucketType, BufferSource, CORS_ALLOWED_OPERATIONS, CORS_MAX_AGE_SECONDS_MAX, CORS_RULES_MAX_COUNT, CORS_RULE_MAX_BYTES, CORS_RULE_NAME_MAX_LENGTH, CORS_RULE_NAME_MIN_LENGTH, CORS_RULE_NAME_PATTERN, CORS_RULE_NAME_RESERVED_PREFIX, CapExceededError, Capability, ChecksumMismatchError, ConflictError, CorsOperation, DownloadClientUnauthorizedToReadMarker, DownloadHeaderName, DuplicateBucketNameError, EncryptionAlgorithm, EncryptionKey, EncryptionMode, EventType, ExpiredAuthTokenError, FetchTransport, FileAction, FileNotPresentError, FileSource, FinishLargeFileResponseBodyError, GroupMemberCreationFailedError, HIDE_MARKER_CONTENT_TYPE, InMemoryAccountInfo, IncrementalSha1, IncrementalSha256, InternalError, InvalidAccountIdError, InvalidBucketIdError, InvalidBucketInfoError, InvalidBucketNameError, InvalidComputerIdError, InvalidEmailError, InvalidFileIdError, InvalidFileInfoError, InvalidFileNameError, InvalidGroupIdError, InvalidMemberAccountIdError, InvalidPartNumberError, InvalidRegionError, InvalidSmsPhoneError, KNOWN_B2_ERROR_CODES, KnownBucketResponseType, LegalHoldValue, MetadataDirective, MethodFailureError, MethodNotAllowedError, MissingSmsPhoneError, NetworkError, NotFoundError, OutOfRangeError, PartnerCapability, RangeNotSatisfiableError, RawClient, Region, RequestTimeoutError, ResumeFileIdMismatchError, RetentionMode, RetryTransport, SSE_B2, SSE_NONE, ServiceUnavailableError, StreamSource, TooManyBucketsError, TooManyFilesError, TooManyGroupMembersError, TooManyMembersError, TooManyRequestsError, UploadResponseBodyError, UrlGuard, VERSION, accountId, applicationKeyId, assertValidBucketConfiguration, assertValidBucketInfo, assertValidCorsRules, bucketId, classifyError, computerId, deriveAllowedSuffixes, fileId, getTransportUrlGuard, groupId, keyId, largeFileId, notificationCustomHeadersToRecord, paginateItems, paginatePages, partnerToken, recordToNotificationCustomHeaders, sha1Hex, sha256Hex, sseCustomer, toContentSource };
@@ -1,5 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_notifications = require("../types/notifications.cjs");
2
3
  const require_webhook = require("./webhook.cjs");
3
4
  exports.B2_WEBHOOK_SIGNATURE_HEADER = require_webhook.B2_WEBHOOK_SIGNATURE_HEADER;
5
+ exports.notificationCustomHeadersToRecord = require_notifications.notificationCustomHeadersToRecord;
6
+ exports.recordToNotificationCustomHeaders = require_notifications.recordToNotificationCustomHeaders;
4
7
  exports.requireValidWebhook = require_webhook.requireValidWebhook;
5
8
  exports.verifyWebhookSignature = require_webhook.verifyWebhookSignature;
@@ -1,3 +1,5 @@
1
+ export type { EventNotificationCustomHeader, EventNotificationRule, } from '../types/notifications.js';
2
+ export { notificationCustomHeadersToRecord, recordToNotificationCustomHeaders, } from '../types/notifications.js';
1
3
  export type { VerifyWebhookOptions, VerifyWebhookResult, WebhookEvent, WebhookPayload, } from './webhook.js';
2
4
  export { B2_WEBHOOK_SIGNATURE_HEADER, requireValidWebhook, verifyWebhookSignature, } from './webhook.js';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notifications/index.js"],"names":[],"mappings":"AAAA,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACZ,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notifications/index.js"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,iCAAiC,EACjC,iCAAiC,GAClC,MAAM,2BAA2B,CAAA;AAClC,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACZ,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,cAAc,CAAA"}
@@ -1,3 +1,5 @@
1
+ export type { EventNotificationCustomHeader, EventNotificationRule, } from '../types/notifications.js';
2
+ export { notificationCustomHeadersToRecord, recordToNotificationCustomHeaders, } from '../types/notifications.js';
1
3
  export type { VerifyWebhookOptions, VerifyWebhookResult, WebhookEvent, WebhookPayload, } from './webhook.js';
2
4
  export { B2_WEBHOOK_SIGNATURE_HEADER, requireValidWebhook, verifyWebhookSignature, } from './webhook.js';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notifications/index.js"],"names":[],"mappings":"AAAA,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACZ,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/notifications/index.js"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,iCAAiC,EACjC,iCAAiC,GAClC,MAAM,2BAA2B,CAAA;AAClC,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACZ,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,cAAc,CAAA"}
@@ -1,2 +1,3 @@
1
+ import { notificationCustomHeadersToRecord, recordToNotificationCustomHeaders } from "../types/notifications.js";
1
2
  import { B2_WEBHOOK_SIGNATURE_HEADER, requireValidWebhook, verifyWebhookSignature } from "./webhook.js";
2
- export { B2_WEBHOOK_SIGNATURE_HEADER, requireValidWebhook, verifyWebhookSignature };
3
+ export { B2_WEBHOOK_SIGNATURE_HEADER, notificationCustomHeadersToRecord, recordToNotificationCustomHeaders, requireValidWebhook, verifyWebhookSignature };
package/dist/object.cjs CHANGED
@@ -15,6 +15,15 @@ function bucketDefaultRetentionSnapshot(info) {
15
15
  unreadable: false
16
16
  };
17
17
  }
18
+ function bucketDefaultServerSideEncryptionSnapshot(info) {
19
+ const encryption = info.defaultServerSideEncryption;
20
+ if (!encryption.isClientAuthorizedToRead) return { unreadable: true };
21
+ if (encryption.value === null) return { unreadable: false };
22
+ return {
23
+ encryption: encryption.value,
24
+ unreadable: false
25
+ };
26
+ }
18
27
  function resumeNeedsFreshBucketDefaults(options) {
19
28
  return (options.resume === true || options.resumeFileId !== void 0) && (options.serverSideEncryption === void 0 || options.fileRetention === void 0);
20
29
  }
@@ -64,12 +73,14 @@ var B2Object = class {
64
73
  if (isLarge) {
65
74
  const bucketInfo = resumeNeedsFreshBucketDefaults(options) ? await this.fetchFreshBucketInfo() : this.bucket.info;
66
75
  const bucketDefaultRetention = bucketDefaultRetentionSnapshot(bucketInfo);
76
+ const bucketDefaultSse = bucketDefaultServerSideEncryptionSnapshot(bucketInfo);
67
77
  return require_large.uploadLargeFile(this.client.raw, this.client.accountInfo, {
68
78
  ...options,
69
79
  bucketId: this.bucket.id,
70
80
  fileName: this.fileName,
71
81
  retry: uploadRetryOptions,
72
- bucketDefaultServerSideEncryption: bucketInfo.defaultServerSideEncryption,
82
+ ...bucketDefaultSse.encryption !== void 0 ? { bucketDefaultServerSideEncryption: bucketDefaultSse.encryption } : {},
83
+ ...bucketDefaultSse.unreadable ? { bucketDefaultServerSideEncryptionUnreadable: true } : {},
73
84
  ...bucketDefaultRetention.retention !== void 0 ? { bucketDefaultRetention: bucketDefaultRetention.retention } : {},
74
85
  ...bucketDefaultRetention.unreadable ? { bucketDefaultRetentionUnreadable: true } : {}
75
86
  });
@@ -1 +1 @@
1
- {"version":3,"file":"object.cjs","names":[],"sources":["../src/object.ts"],"sourcesContent":["import type { Bucket } from './bucket.ts'\nimport type { B2Client } from './client.ts'\nimport { createParallelDownloadStream } from './download/parallel.ts'\nimport {\n type DownloadResult,\n downloadById,\n downloadByName,\n type HeadResult,\n headById,\n headByName,\n} from './download/single.ts'\nimport type { RetryOptions } from './http/retry.ts'\nimport { mergeUploadRetryOptions } from './internal/upload-retry-options.ts'\nimport type { SseCDownloadKey } from './raw/index.ts'\nimport type { ProgressListener } from './streams/progress.ts'\nimport type { BucketRetentionPolicy } from './types/bucket.ts'\nimport type { FileVersion } from './types/file.ts'\nimport type { FileId } from './types/ids.ts'\nimport type { FileRetentionValue, LegalHoldValue } from './types/lock.ts'\nimport { uploadLargeFile } from './upload/large.ts'\nimport {\n type B2ObjectUploadOptions,\n type B2ObjectWriteStreamOptions,\n rejectSmallResumeFileId,\n stripResumeOnlyOptions,\n} from './upload/options.ts'\nimport { uploadSmallFile } from './upload/single.ts'\nimport { createWriteStream, type UploadWriteHandle } from './upload/stream.ts'\n\ninterface BucketDefaultRetentionSnapshot {\n readonly retention?: BucketRetentionPolicy\n readonly unreadable: boolean\n}\n\nfunction bucketDefaultRetentionSnapshot(info: Bucket['info']): BucketDefaultRetentionSnapshot {\n const fileLock = info.fileLockConfiguration\n if (!fileLock.isClientAuthorizedToRead) return { unreadable: true }\n if (fileLock.value === null) return { unreadable: false }\n return { retention: fileLock.value.defaultRetention, unreadable: false }\n}\n\nfunction resumeNeedsFreshBucketDefaults(options: B2ObjectUploadOptions): boolean {\n const resumeRequested = options.resume === true || options.resumeFileId !== undefined\n return (\n resumeRequested &&\n (options.serverSideEncryption === undefined || options.fileRetention === undefined)\n )\n}\n\n/** Options accepted by {@link B2Object.download} and {@link B2Object.downloadById}. */\nexport interface DownloadCallOptions {\n /**\n * HTTP method. Defaults to `'GET'`. Use `'HEAD'` to fetch only\n * response headers. Prefer the dedicated {@link B2Object.head} /\n * {@link Bucket.head} method over this option — those return a\n * body-less result so callers never have to remember to drain the\n * empty body of a HEAD response.\n */\n readonly method?: 'GET' | 'HEAD'\n /** HTTP Range header value (e.g., `\"bytes=0-999\"`). */\n readonly range?: string\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n readonly serverSideEncryption?: SseCDownloadKey\n /** Override the response `Content-Disposition` header. */\n readonly b2ContentDisposition?: string\n /** Override the response `Content-Language` header. */\n readonly b2ContentLanguage?: string\n /** Override the response `Content-Encoding` header. */\n readonly b2ContentEncoding?: string\n /** Override the response `Content-Type` header. */\n readonly b2ContentType?: string\n /** Override the response `Cache-Control` header. */\n readonly b2CacheControl?: string\n /** Override the response `Expires` header. */\n readonly b2Expires?: string\n /** Abort signal for cancelling the download. */\n readonly signal?: AbortSignal\n /**\n * Callback invoked as the response body is consumed.\n *\n * Progress is byte-driven, not request-driven: the callback fires per\n * chunk as the caller reads the returned `body` stream, and the final\n * `partsCompleted: 1` event only fires once the stream is read to\n * completion. Downloads that are dropped or aborted partway through\n * will NOT emit a `completePart()` event.\n */\n readonly onProgress?: ProgressListener\n}\n\n/**\n * Options accepted by {@link B2Object.head} / {@link Bucket.head}.\n * Same shape as {@link DownloadCallOptions} minus `method` (always\n * HEAD) and `onProgress` (no body to track).\n */\nexport type HeadCallOptions = Omit<DownloadCallOptions, 'method' | 'onProgress'>\n\n/**\n * Handle to a specific file (by name) within a B2 bucket.\n *\n * Provides file-scoped upload, download, and management operations.\n * Obtained via {@link Bucket.file}.\n *\n * @example\n * ```ts\n * const obj = bucket.file('photos/2026/sunset.jpg')\n * await obj.upload({ source: new BufferSource(data) })\n * const result = await obj.download()\n * ```\n */\nexport class B2Object {\n /** The file name (path) within the bucket. */\n readonly fileName: string\n private readonly client: B2Client\n private readonly bucket: Bucket\n private readonly uploadRetryOptions: RetryOptions\n\n /**\n * @param client - The parent B2Client instance.\n * @param bucket - The parent Bucket this object belongs to.\n * @param fileName - The file path within the bucket.\n * @param uploadRetryOptions - Resolved client upload retry defaults.\n *\n * @internal\n */\n constructor(\n client: B2Client,\n bucket: Bucket,\n fileName: string,\n uploadRetryOptions: RetryOptions,\n ) {\n this.client = client\n this.bucket = bucket\n this.fileName = fileName\n this.uploadRetryOptions = uploadRetryOptions\n }\n\n /**\n * Uploads data to this file name. Automatically uses multipart upload for large files.\n * @param options - Upload configuration including data source and optional settings.\n *\n * @returns Metadata for the uploaded file version.\n */\n async upload(options: B2ObjectUploadOptions): Promise<FileVersion> {\n const recommendedPartSize = this.client.accountInfo.getRecommendedPartSize()\n const isLarge = options.source.size > recommendedPartSize\n const uploadRetryOptions = mergeUploadRetryOptions(this.uploadRetryOptions, options.retry)\n\n if (isLarge) {\n const bucketInfo = resumeNeedsFreshBucketDefaults(options)\n ? await this.fetchFreshBucketInfo()\n : this.bucket.info\n const bucketDefaultRetention = bucketDefaultRetentionSnapshot(bucketInfo)\n return uploadLargeFile(this.client.raw, this.client.accountInfo, {\n ...options,\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n bucketDefaultServerSideEncryption: bucketInfo.defaultServerSideEncryption,\n ...(bucketDefaultRetention.retention !== undefined\n ? { bucketDefaultRetention: bucketDefaultRetention.retention }\n : {}),\n ...(bucketDefaultRetention.unreadable ? { bucketDefaultRetentionUnreadable: true } : {}),\n })\n }\n rejectSmallResumeFileId(options, 'B2Object.upload')\n const smallOptions = stripResumeOnlyOptions(options)\n return uploadSmallFile(this.client.raw, this.client.accountInfo, {\n ...smallOptions,\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n })\n }\n\n private async fetchFreshBucketInfo(): Promise<Bucket['info']> {\n const fresh = await this.client.listBuckets({ bucketId: this.bucket.id })\n const found = fresh[0]\n if (!found) throw new Error(`Bucket ${this.bucket.id} not found`)\n return found.info\n }\n\n /**\n * Downloads this file by name. Pass `method: 'HEAD'` to fetch only the\n * response headers (file metadata) without streaming the body.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async download(options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for this file via HTTP HEAD. Returns a\n * body-less result so callers never have to drain the (logically\n * empty) HEAD body themselves.\n *\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal. Same shape as {@link B2Object.download}'s\n * options minus `method` (always HEAD) and `onProgress` (no body).\n *\n * @returns Parsed download headers (content type, SHA-1, file info, etc.).\n */\n async head(options?: HeadCallOptions): Promise<HeadResult> {\n return headByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Downloads a specific version of this file by ID. Pass `method: 'HEAD'`\n * to fetch only the response headers (file metadata) without streaming the body.\n * @param fileId - The file version ID to download.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async downloadById(fileId: FileId, options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for a specific version of this file by ID\n * via HTTP HEAD. Returns a body-less result so callers never have to\n * drain the (logically empty) HEAD body themselves.\n *\n * @param fileId - The file version ID to inspect.\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal.\n *\n * @returns Parsed download headers.\n */\n async headById(fileId: FileId, options?: HeadCallOptions): Promise<HeadResult> {\n return headById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Creates a parallel-download ReadableStream that fetches the file in concurrent ranged chunks.\n * @param fileId - The file version ID to download.\n * @param totalSize - Total file size in bytes (needed to compute range boundaries).\n * @param options - Concurrency, range size, SSE-C decryption, and abort signal.\n *\n * @returns A Web ReadableStream of file data in sequential order.\n */\n createReadStream(\n fileId: FileId,\n totalSize: number,\n options?: {\n /** Size of each ranged GET request in bytes. Defaults to 10 MB. */\n rangeSize?: number\n /** Number of concurrent range requests. Defaults to 4. */\n concurrency?: number\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n serverSideEncryption?: SseCDownloadKey\n /** Abort signal for cancelling the download. */\n signal?: AbortSignal\n },\n ): ReadableStream<Uint8Array> {\n return createParallelDownloadStream(this.client.raw, this.client.accountInfo, {\n fileId,\n totalSize,\n ...options,\n })\n }\n\n /**\n * Creates a Web `WritableStream` that uploads streamed data into this file\n * using the multipart protocol. Pipe a `ReadableStream<Uint8Array>` into the\n * returned `writable` and await `done` to get the final {@link FileVersion}.\n *\n * Note: streaming uploads do not support resume because the size and per-part\n * hashes are not known in advance. Use {@link upload} with a buffered source\n * when resume is required.\n *\n * @param options - Streaming upload parameters (part size, concurrency, encryption).\n *\n * @returns A handle with the writable sink and a completion promise.\n */\n createWriteStream(options?: B2ObjectWriteStreamOptions): UploadWriteHandle {\n const uploadRetryOptions = mergeUploadRetryOptions(this.uploadRetryOptions, options?.retry)\n return createWriteStream(this.client.raw, this.client.accountInfo, {\n ...(options ?? {}),\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n })\n }\n\n /**\n * Retrieves metadata for a specific file version.\n * @param fileId - The file version ID to look up.\n *\n * @returns The file version metadata.\n */\n async getFileInfo(fileId: FileId): Promise<FileVersion> {\n return this.client.raw.getFileInfo(\n this.client.accountInfo.getApiUrl(),\n this.client.accountInfo.getAuthToken(),\n { fileId },\n )\n }\n\n /**\n * Hides this file by creating a hide marker at this file name.\n *\n * @returns Metadata for the newly created hide marker.\n */\n async hide(): Promise<FileVersion> {\n return this.bucket.hideFile(this.fileName)\n }\n\n /**\n * Permanently deletes a specific version of this file.\n * @param fileId - The unique identifier of the file version to delete.\n */\n async deleteVersion(fileId: FileId): Promise<void> {\n await this.bucket.deleteFileVersion(this.fileName, fileId)\n }\n\n /**\n * Sets or updates the Object Lock retention policy on a specific file\n * version of this file.\n *\n * The bucket must have Object Lock enabled (`fileLockEnabled: true` at\n * creation time). Governance-mode retention can be shortened or removed\n * by passing `bypassGovernance: true` together with an application key\n * that carries the `bypassGovernance` capability; compliance-mode\n * retention cannot be shortened by anyone until the\n * `retainUntilTimestamp` elapses.\n *\n * @param fileId - The file version to apply the policy to.\n * @param retention - The retention policy to apply.\n * @param options - Optional flag for shortening governance-mode retention.\n *\n * @returns Metadata for the updated file version.\n */\n async setRetention(\n fileId: FileId,\n retention: FileRetentionValue,\n options?: { bypassGovernance?: boolean },\n ) {\n return this.bucket.updateFileRetention(this.fileName, fileId, retention, options)\n }\n\n /**\n * Toggles the legal hold flag on a specific file version of this file.\n *\n * Legal hold is independent of retention: a file can be on legal hold\n * without any retention policy, and vice versa. The bucket must have\n * Object Lock enabled, and any caller must hold the `writeFileLegalHolds`\n * capability.\n *\n * @param fileId - The file version to apply the flag to.\n * @param legalHold - `'on'` to apply the hold, `'off'` to remove it.\n *\n * @returns Metadata for the updated file version.\n */\n async setLegalHold(fileId: FileId, legalHold: LegalHoldValue) {\n return this.bucket.updateFileLegalHold(this.fileName, fileId, legalHold)\n }\n}\n"],"mappings":";;;;;;;;AAkCA,SAAS,+BAA+B,MAAsD;CAC5F,MAAM,WAAW,KAAK;CACtB,IAAI,CAAC,SAAS,0BAA0B,OAAO,EAAE,YAAY,KAAK;CAClE,IAAI,SAAS,UAAU,MAAM,OAAO,EAAE,YAAY,MAAM;CACxD,OAAO;EAAE,WAAW,SAAS,MAAM;EAAkB,YAAY;CAAM;AACzE;AAEA,SAAS,+BAA+B,SAAyC;CAE/E,QADwB,QAAQ,WAAW,QAAQ,QAAQ,iBAAiB,KAAA,OAGzE,QAAQ,yBAAyB,KAAA,KAAa,QAAQ,kBAAkB,KAAA;AAE7E;;;;;;;;;;;;;;AA8DA,IAAa,WAAb,MAAsB;;CAEpB;CACA;CACA;CACA;;;;;;;;;CAUA,YACE,QACA,QACA,UACA,oBACA;EACA,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,WAAW;EAChB,KAAK,qBAAqB;CAC5B;;;;;;;CAQA,MAAM,OAAO,SAAsD;EACjE,MAAM,sBAAsB,KAAK,OAAO,YAAY,uBAAuB;EAC3E,MAAM,UAAU,QAAQ,OAAO,OAAO;EACtC,MAAM,qBAAqB,6BAAA,wBAAwB,KAAK,oBAAoB,QAAQ,KAAK;EAEzF,IAAI,SAAS;GACX,MAAM,aAAa,+BAA+B,OAAO,IACrD,MAAM,KAAK,qBAAqB,IAChC,KAAK,OAAO;GAChB,MAAM,yBAAyB,+BAA+B,UAAU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gB,SAAgD;EAC7E,OAAO,eAAA,SAAS,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GACxD;GACA,GAAG;EACL,CAAC;CACH;;;;;;;;;CAUA,iBACE,QACA,WACA,SAU4B;EAC5B,OAAO,iBAAA,6BAA6B,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GAC5E;GACA;GACA,GAAG;EACL,CAAC;CACH;;;;;;;;;;;;;;CAeA,kBAAkB,SAAyD;EACzE,MAAM,qBAAqB,6BAAA,wBAAwB,KAAK,oBAAoB,SAAS,KAAK;EAC1F,OAAO,eAAA,kBAAkB,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GACjE,GAAI,WAAW,CAAC;GAChB,UAAU,KAAK,OAAO;GACtB,UAAU,KAAK;GACf,OAAO;EACT,CAAC;CACH;;;;;;;CAQA,MAAM,YAAY,QAAsC;EACtD,OAAO,KAAK,OAAO,IAAI,YACrB,KAAK,OAAO,YAAY,UAAU,GAClC,KAAK,OAAO,YAAY,aAAa,GACrC,EAAE,OAAO,CACX;CACF;;;;;;CAOA,MAAM,OAA6B;EACjC,OAAO,KAAK,OAAO,SAAS,KAAK,QAAQ;CAC3C;;;;;CAMA,MAAM,cAAc,QAA+B;EACjD,MAAM,KAAK,OAAO,kBAAkB,KAAK,UAAU,MAAM;CAC3D;;;;;;;;;;;;;;;;;;CAmBA,MAAM,aACJ,QACA,WACA,SACA;EACA,OAAO,KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,WAAW,OAAO;CAClF;;;;;;;;;;;;;;CAeA,MAAM,aAAa,QAAgB,WAA2B;EAC5D,OAAO,KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,SAAS;CACzE;AACF"}
1
+ {"version":3,"file":"object.cjs","names":[],"sources":["../src/object.ts"],"sourcesContent":["import type { Bucket } from './bucket.ts'\nimport type { B2Client } from './client.ts'\nimport { createParallelDownloadStream } from './download/parallel.ts'\nimport {\n type DownloadResult,\n downloadById,\n downloadByName,\n type HeadResult,\n headById,\n headByName,\n} from './download/single.ts'\nimport type { RetryOptions } from './http/retry.ts'\nimport { mergeUploadRetryOptions } from './internal/upload-retry-options.ts'\nimport type { SseCDownloadKey } from './raw/index.ts'\nimport type { ProgressListener } from './streams/progress.ts'\nimport type { BucketDefaultRetention, BucketDefaultServerSideEncryption } from './types/bucket.ts'\nimport type { FileVersion } from './types/file.ts'\nimport type { FileId } from './types/ids.ts'\nimport type { FileRetentionValue, LegalHoldValue } from './types/lock.ts'\nimport { uploadLargeFile } from './upload/large.ts'\nimport {\n type B2ObjectUploadOptions,\n type B2ObjectWriteStreamOptions,\n rejectSmallResumeFileId,\n stripResumeOnlyOptions,\n} from './upload/options.ts'\nimport { uploadSmallFile } from './upload/single.ts'\nimport { createWriteStream, type UploadWriteHandle } from './upload/stream.ts'\n\ninterface BucketDefaultRetentionSnapshot {\n readonly retention?: BucketDefaultRetention\n readonly unreadable: boolean\n}\n\ninterface BucketDefaultServerSideEncryptionSnapshot {\n readonly encryption?: BucketDefaultServerSideEncryption\n readonly unreadable: boolean\n}\n\nfunction bucketDefaultRetentionSnapshot(info: Bucket['info']): BucketDefaultRetentionSnapshot {\n const fileLock = info.fileLockConfiguration\n if (!fileLock.isClientAuthorizedToRead) return { unreadable: true }\n if (fileLock.value === null) return { unreadable: false }\n return { retention: fileLock.value.defaultRetention, unreadable: false }\n}\n\nfunction bucketDefaultServerSideEncryptionSnapshot(\n info: Bucket['info'],\n): BucketDefaultServerSideEncryptionSnapshot {\n const encryption = info.defaultServerSideEncryption\n if (!encryption.isClientAuthorizedToRead) return { unreadable: true }\n if (encryption.value === null) return { unreadable: false }\n return { encryption: encryption.value, unreadable: false }\n}\n\nfunction resumeNeedsFreshBucketDefaults(options: B2ObjectUploadOptions): boolean {\n const resumeRequested = options.resume === true || options.resumeFileId !== undefined\n return (\n resumeRequested &&\n (options.serverSideEncryption === undefined || options.fileRetention === undefined)\n )\n}\n\n/** Options accepted by {@link B2Object.download} and {@link B2Object.downloadById}. */\nexport interface DownloadCallOptions {\n /**\n * HTTP method. Defaults to `'GET'`. Use `'HEAD'` to fetch only\n * response headers. Prefer the dedicated {@link B2Object.head} /\n * {@link Bucket.head} method over this option — those return a\n * body-less result so callers never have to remember to drain the\n * empty body of a HEAD response.\n */\n readonly method?: 'GET' | 'HEAD'\n /** HTTP Range header value (e.g., `\"bytes=0-999\"`). */\n readonly range?: string\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n readonly serverSideEncryption?: SseCDownloadKey\n /** Override the response `Content-Disposition` header. */\n readonly b2ContentDisposition?: string\n /** Override the response `Content-Language` header. */\n readonly b2ContentLanguage?: string\n /** Override the response `Content-Encoding` header. */\n readonly b2ContentEncoding?: string\n /** Override the response `Content-Type` header. */\n readonly b2ContentType?: string\n /** Override the response `Cache-Control` header. */\n readonly b2CacheControl?: string\n /** Override the response `Expires` header. */\n readonly b2Expires?: string\n /** Abort signal for cancelling the download. */\n readonly signal?: AbortSignal\n /**\n * Callback invoked as the response body is consumed.\n *\n * Progress is byte-driven, not request-driven: the callback fires per\n * chunk as the caller reads the returned `body` stream, and the final\n * `partsCompleted: 1` event only fires once the stream is read to\n * completion. Downloads that are dropped or aborted partway through\n * will NOT emit a `completePart()` event.\n */\n readonly onProgress?: ProgressListener\n /**\n * Minimum milliseconds between byte-only progress callbacks. Defaults to\n * the SDK's 100 ms progress interval; set to 0 for per-chunk callbacks.\n * The final completion callback is always emitted immediately.\n */\n readonly progressIntervalMillis?: number\n}\n\n/**\n * Options accepted by {@link B2Object.head} / {@link Bucket.head}.\n * Same shape as {@link DownloadCallOptions} minus `method` (always\n * HEAD) and `onProgress` (no body to track).\n */\nexport type HeadCallOptions = Omit<\n DownloadCallOptions,\n 'method' | 'onProgress' | 'progressIntervalMillis'\n>\n\n/**\n * Handle to a specific file (by name) within a B2 bucket.\n *\n * Provides file-scoped upload, download, and management operations.\n * Obtained via {@link Bucket.file}.\n *\n * @example\n * ```ts\n * const obj = bucket.file('photos/2026/sunset.jpg')\n * await obj.upload({ source: new BufferSource(data) })\n * const result = await obj.download()\n * ```\n */\nexport class B2Object {\n /** The file name (path) within the bucket. */\n readonly fileName: string\n private readonly client: B2Client\n private readonly bucket: Bucket\n private readonly uploadRetryOptions: RetryOptions\n\n /**\n * @param client - The parent B2Client instance.\n * @param bucket - The parent Bucket this object belongs to.\n * @param fileName - The file path within the bucket.\n * @param uploadRetryOptions - Resolved client upload retry defaults.\n *\n * @internal\n */\n constructor(\n client: B2Client,\n bucket: Bucket,\n fileName: string,\n uploadRetryOptions: RetryOptions,\n ) {\n this.client = client\n this.bucket = bucket\n this.fileName = fileName\n this.uploadRetryOptions = uploadRetryOptions\n }\n\n /**\n * Uploads data to this file name. Automatically uses multipart upload for large files.\n * @param options - Upload configuration including data source and optional settings.\n *\n * @returns Metadata for the uploaded file version.\n */\n async upload(options: B2ObjectUploadOptions): Promise<FileVersion> {\n const recommendedPartSize = this.client.accountInfo.getRecommendedPartSize()\n const isLarge = options.source.size > recommendedPartSize\n const uploadRetryOptions = mergeUploadRetryOptions(this.uploadRetryOptions, options.retry)\n\n if (isLarge) {\n const bucketInfo = resumeNeedsFreshBucketDefaults(options)\n ? await this.fetchFreshBucketInfo()\n : this.bucket.info\n const bucketDefaultRetention = bucketDefaultRetentionSnapshot(bucketInfo)\n const bucketDefaultSse = bucketDefaultServerSideEncryptionSnapshot(bucketInfo)\n return uploadLargeFile(this.client.raw, this.client.accountInfo, {\n ...options,\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n ...(bucketDefaultSse.encryption !== undefined\n ? { bucketDefaultServerSideEncryption: bucketDefaultSse.encryption }\n : {}),\n ...(bucketDefaultSse.unreadable\n ? { bucketDefaultServerSideEncryptionUnreadable: true }\n : {}),\n ...(bucketDefaultRetention.retention !== undefined\n ? { bucketDefaultRetention: bucketDefaultRetention.retention }\n : {}),\n ...(bucketDefaultRetention.unreadable ? { bucketDefaultRetentionUnreadable: true } : {}),\n })\n }\n rejectSmallResumeFileId(options, 'B2Object.upload')\n const smallOptions = stripResumeOnlyOptions(options)\n return uploadSmallFile(this.client.raw, this.client.accountInfo, {\n ...smallOptions,\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n })\n }\n\n private async fetchFreshBucketInfo(): Promise<Bucket['info']> {\n const fresh = await this.client.listBuckets({ bucketId: this.bucket.id })\n const found = fresh[0]\n if (!found) throw new Error(`Bucket ${this.bucket.id} not found`)\n return found.info\n }\n\n /**\n * Downloads this file by name. Pass `method: 'HEAD'` to fetch only the\n * response headers (file metadata) without streaming the body.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async download(options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for this file via HTTP HEAD. Returns a\n * body-less result so callers never have to drain the (logically\n * empty) HEAD body themselves.\n *\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal. Same shape as {@link B2Object.download}'s\n * options minus `method` (always HEAD) and `onProgress` (no body).\n *\n * @returns Parsed download headers (content type, SHA-1, file info, etc.).\n */\n async head(options?: HeadCallOptions): Promise<HeadResult> {\n return headByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Downloads a specific version of this file by ID. Pass `method: 'HEAD'`\n * to fetch only the response headers (file metadata) without streaming the body.\n * @param fileId - The file version ID to download.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async downloadById(fileId: FileId, options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for a specific version of this file by ID\n * via HTTP HEAD. Returns a body-less result so callers never have to\n * drain the (logically empty) HEAD body themselves.\n *\n * @param fileId - The file version ID to inspect.\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal.\n *\n * @returns Parsed download headers.\n */\n async headById(fileId: FileId, options?: HeadCallOptions): Promise<HeadResult> {\n return headById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Creates a parallel-download ReadableStream that fetches the file in concurrent ranged chunks.\n * @param fileId - The file version ID to download.\n * @param totalSize - Total file size in bytes (needed to compute range boundaries).\n * @param options - Concurrency, range size, SSE-C decryption, and abort signal.\n *\n * @returns A Web ReadableStream of file data in sequential order.\n */\n createReadStream(\n fileId: FileId,\n totalSize: number,\n options?: {\n /** Size of each ranged GET request in bytes. Defaults to 10 MB. */\n rangeSize?: number\n /** Number of concurrent range requests. Defaults to 4. */\n concurrency?: number\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n serverSideEncryption?: SseCDownloadKey\n /** Abort signal for cancelling the download. */\n signal?: AbortSignal\n },\n ): ReadableStream<Uint8Array> {\n return createParallelDownloadStream(this.client.raw, this.client.accountInfo, {\n fileId,\n totalSize,\n ...options,\n })\n }\n\n /**\n * Creates a Web `WritableStream` that uploads streamed data into this file\n * using the multipart protocol. Pipe a `ReadableStream<Uint8Array>` into the\n * returned `writable` and await `done` to get the final {@link FileVersion}.\n *\n * Note: streaming uploads do not support resume because the size and per-part\n * hashes are not known in advance. Use {@link upload} with a buffered source\n * when resume is required.\n *\n * @param options - Streaming upload parameters (part size, concurrency, encryption).\n *\n * @returns A handle with the writable sink and a completion promise.\n */\n createWriteStream(options?: B2ObjectWriteStreamOptions): UploadWriteHandle {\n const uploadRetryOptions = mergeUploadRetryOptions(this.uploadRetryOptions, options?.retry)\n return createWriteStream(this.client.raw, this.client.accountInfo, {\n ...(options ?? {}),\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n })\n }\n\n /**\n * Retrieves metadata for a specific file version.\n * @param fileId - The file version ID to look up.\n *\n * @returns The file version metadata.\n */\n async getFileInfo(fileId: FileId): Promise<FileVersion> {\n return this.client.raw.getFileInfo(\n this.client.accountInfo.getApiUrl(),\n this.client.accountInfo.getAuthToken(),\n { fileId },\n )\n }\n\n /**\n * Hides this file by creating a hide marker at this file name.\n *\n * @returns Metadata for the newly created hide marker.\n */\n async hide(): Promise<FileVersion> {\n return this.bucket.hideFile(this.fileName)\n }\n\n /**\n * Permanently deletes a specific version of this file.\n * @param fileId - The unique identifier of the file version to delete.\n */\n async deleteVersion(fileId: FileId): Promise<void> {\n await this.bucket.deleteFileVersion(this.fileName, fileId)\n }\n\n /**\n * Sets or updates the Object Lock retention policy on a specific file\n * version of this file.\n *\n * The bucket must have Object Lock enabled (`fileLockEnabled: true` at\n * creation time). Governance-mode retention can be shortened or removed\n * by passing `bypassGovernance: true` together with an application key\n * that carries the `bypassGovernance` capability; compliance-mode\n * retention cannot be shortened by anyone until the\n * `retainUntilTimestamp` elapses.\n *\n * @param fileId - The file version to apply the policy to.\n * @param retention - The retention policy to apply.\n * @param options - Optional flag for shortening governance-mode retention.\n *\n * @returns Metadata for the updated file version.\n */\n async setRetention(\n fileId: FileId,\n retention: FileRetentionValue,\n options?: { bypassGovernance?: boolean },\n ) {\n return this.bucket.updateFileRetention(this.fileName, fileId, retention, options)\n }\n\n /**\n * Toggles the legal hold flag on a specific file version of this file.\n *\n * Legal hold is independent of retention: a file can be on legal hold\n * without any retention policy, and vice versa. The bucket must have\n * Object Lock enabled, and any caller must hold the `writeFileLegalHolds`\n * capability.\n *\n * @param fileId - The file version to apply the flag to.\n * @param legalHold - `'on'` to apply the hold, `'off'` to remove it.\n *\n * @returns Metadata for the updated file version.\n */\n async setLegalHold(fileId: FileId, legalHold: LegalHoldValue) {\n return this.bucket.updateFileLegalHold(this.fileName, fileId, legalHold)\n }\n}\n"],"mappings":";;;;;;;;AAuCA,SAAS,+BAA+B,MAAsD;CAC5F,MAAM,WAAW,KAAK;CACtB,IAAI,CAA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aAAa;GACxD;GACA,GAAG;EACL,CAAC;CACH;;;;;;;;;CAUA,iBACE,QACA,WACA,SAU4B;EAC5B,OAAO,iBAAA,6BAA6B,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GAC5E;GACA;GACA,GAAG;EACL,CAAC;CACH;;;;;;;;;;;;;;CAeA,kBAAkB,SAAyD;EACzE,MAAM,qBAAqB,6BAAA,wBAAwB,KAAK,oBAAoB,SAAS,KAAK;EAC1F,OAAO,eAAA,kBAAkB,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GACjE,GAAI,WAAW,CAAC;GAChB,UAAU,KAAK,OAAO;GACtB,UAAU,KAAK;GACf,OAAO;EACT,CAAC;CACH;;;;;;;CAQA,MAAM,YAAY,QAAsC;EACtD,OAAO,KAAK,OAAO,IAAI,YACrB,KAAK,OAAO,YAAY,UAAU,GAClC,KAAK,OAAO,YAAY,aAAa,GACrC,EAAE,OAAO,CACX;CACF;;;;;;CAOA,MAAM,OAA6B;EACjC,OAAO,KAAK,OAAO,SAAS,KAAK,QAAQ;CAC3C;;;;;CAMA,MAAM,cAAc,QAA+B;EACjD,MAAM,KAAK,OAAO,kBAAkB,KAAK,UAAU,MAAM;CAC3D;;;;;;;;;;;;;;;;;;CAmBA,MAAM,aACJ,QACA,WACA,SACA;EACA,OAAO,KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,WAAW,OAAO;CAClF;;;;;;;;;;;;;;CAeA,MAAM,aAAa,QAAgB,WAA2B;EAC5D,OAAO,KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,SAAS;CACzE;AACF"}
package/dist/object.d.cts CHANGED
@@ -47,13 +47,19 @@ export interface DownloadCallOptions {
47
47
  * will NOT emit a `completePart()` event.
48
48
  */
49
49
  readonly onProgress?: ProgressListener;
50
+ /**
51
+ * Minimum milliseconds between byte-only progress callbacks. Defaults to
52
+ * the SDK's 100 ms progress interval; set to 0 for per-chunk callbacks.
53
+ * The final completion callback is always emitted immediately.
54
+ */
55
+ readonly progressIntervalMillis?: number;
50
56
  }
51
57
  /**
52
58
  * Options accepted by {@link B2Object.head} / {@link Bucket.head}.
53
59
  * Same shape as {@link DownloadCallOptions} minus `method` (always
54
60
  * HEAD) and `onProgress` (no body to track).
55
61
  */
56
- export type HeadCallOptions = Omit<DownloadCallOptions, 'method' | 'onProgress'>;
62
+ export type HeadCallOptions = Omit<DownloadCallOptions, 'method' | 'onProgress' | 'progressIntervalMillis'>;
57
63
  /**
58
64
  * Handle to a specific file (by name) within a B2 bucket.
59
65
  *
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEzE,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAGhC,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAsB9E,uFAAuF;AACvF,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IAChC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a `completePart()` event.
48
48
  */
49
49
  readonly onProgress?: ProgressListener;
50
+ /**
51
+ * Minimum milliseconds between byte-only progress callbacks. Defaults to
52
+ * the SDK's 100 ms progress interval; set to 0 for per-chunk callbacks.
53
+ * The final completion callback is always emitted immediately.
54
+ */
55
+ readonly progressIntervalMillis?: number;
50
56
  }
51
57
  /**
52
58
  * Options accepted by {@link B2Object.head} / {@link Bucket.head}.
53
59
  * Same shape as {@link DownloadCallOptions} minus `method` (always
54
60
  * HEAD) and `onProgress` (no body to track).
55
61
  */
56
- export type HeadCallOptions = Omit<DownloadCallOptions, 'method' | 'onProgress'>;
62
+ export type HeadCallOptions = Omit<DownloadCallOptions, 'method' | 'onProgress' | 'progressIntervalMillis'>;
57
63
  /**
58
64
  * Handle to a specific file (by name) within a B2 bucket.
59
65
  *
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,EACL,KAAK,cAAc,EAGnB,KAAK,UAAU,EAGhB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEzE,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAGhC,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAqB,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;IAK1C;;;;;;;;;;;;OAYG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc;CAG7D"}
package/dist/object.js CHANGED
@@ -15,6 +15,15 @@ function bucketDefaultRetentionSnapshot(info) {
15
15
  unreadable: false
16
16
  };
17
17
  }
18
+ function bucketDefaultServerSideEncryptionSnapshot(info) {
19
+ const encryption = info.defaultServerSideEncryption;
20
+ if (!encryption.isClientAuthorizedToRead) return { unreadable: true };
21
+ if (encryption.value === null) return { unreadable: false };
22
+ return {
23
+ encryption: encryption.value,
24
+ unreadable: false
25
+ };
26
+ }
18
27
  function resumeNeedsFreshBucketDefaults(options) {
19
28
  return (options.resume === true || options.resumeFileId !== void 0) && (options.serverSideEncryption === void 0 || options.fileRetention === void 0);
20
29
  }
@@ -64,12 +73,14 @@ var B2Object = class {
64
73
  if (isLarge) {
65
74
  const bucketInfo = resumeNeedsFreshBucketDefaults(options) ? await this.fetchFreshBucketInfo() : this.bucket.info;
66
75
  const bucketDefaultRetention = bucketDefaultRetentionSnapshot(bucketInfo);
76
+ const bucketDefaultSse = bucketDefaultServerSideEncryptionSnapshot(bucketInfo);
67
77
  return uploadLargeFile(this.client.raw, this.client.accountInfo, {
68
78
  ...options,
69
79
  bucketId: this.bucket.id,
70
80
  fileName: this.fileName,
71
81
  retry: uploadRetryOptions,
72
- bucketDefaultServerSideEncryption: bucketInfo.defaultServerSideEncryption,
82
+ ...bucketDefaultSse.encryption !== void 0 ? { bucketDefaultServerSideEncryption: bucketDefaultSse.encryption } : {},
83
+ ...bucketDefaultSse.unreadable ? { bucketDefaultServerSideEncryptionUnreadable: true } : {},
73
84
  ...bucketDefaultRetention.retention !== void 0 ? { bucketDefaultRetention: bucketDefaultRetention.retention } : {},
74
85
  ...bucketDefaultRetention.unreadable ? { bucketDefaultRetentionUnreadable: true } : {}
75
86
  });
@@ -1 +1 @@
1
- {"version":3,"file":"object.js","names":[],"sources":["../src/object.ts"],"sourcesContent":["import type { Bucket } from './bucket.ts'\nimport type { B2Client } from './client.ts'\nimport { createParallelDownloadStream } from './download/parallel.ts'\nimport {\n type DownloadResult,\n downloadById,\n downloadByName,\n type HeadResult,\n headById,\n headByName,\n} from './download/single.ts'\nimport type { RetryOptions } from './http/retry.ts'\nimport { mergeUploadRetryOptions } from './internal/upload-retry-options.ts'\nimport type { SseCDownloadKey } from './raw/index.ts'\nimport type { ProgressListener } from './streams/progress.ts'\nimport type { BucketRetentionPolicy } from './types/bucket.ts'\nimport type { FileVersion } from './types/file.ts'\nimport type { FileId } from './types/ids.ts'\nimport type { FileRetentionValue, LegalHoldValue } from './types/lock.ts'\nimport { uploadLargeFile } from './upload/large.ts'\nimport {\n type B2ObjectUploadOptions,\n type B2ObjectWriteStreamOptions,\n rejectSmallResumeFileId,\n stripResumeOnlyOptions,\n} from './upload/options.ts'\nimport { uploadSmallFile } from './upload/single.ts'\nimport { createWriteStream, type UploadWriteHandle } from './upload/stream.ts'\n\ninterface BucketDefaultRetentionSnapshot {\n readonly retention?: BucketRetentionPolicy\n readonly unreadable: boolean\n}\n\nfunction bucketDefaultRetentionSnapshot(info: Bucket['info']): BucketDefaultRetentionSnapshot {\n const fileLock = info.fileLockConfiguration\n if (!fileLock.isClientAuthorizedToRead) return { unreadable: true }\n if (fileLock.value === null) return { unreadable: false }\n return { retention: fileLock.value.defaultRetention, unreadable: false }\n}\n\nfunction resumeNeedsFreshBucketDefaults(options: B2ObjectUploadOptions): boolean {\n const resumeRequested = options.resume === true || options.resumeFileId !== undefined\n return (\n resumeRequested &&\n (options.serverSideEncryption === undefined || options.fileRetention === undefined)\n )\n}\n\n/** Options accepted by {@link B2Object.download} and {@link B2Object.downloadById}. */\nexport interface DownloadCallOptions {\n /**\n * HTTP method. Defaults to `'GET'`. Use `'HEAD'` to fetch only\n * response headers. Prefer the dedicated {@link B2Object.head} /\n * {@link Bucket.head} method over this option — those return a\n * body-less result so callers never have to remember to drain the\n * empty body of a HEAD response.\n */\n readonly method?: 'GET' | 'HEAD'\n /** HTTP Range header value (e.g., `\"bytes=0-999\"`). */\n readonly range?: string\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n readonly serverSideEncryption?: SseCDownloadKey\n /** Override the response `Content-Disposition` header. */\n readonly b2ContentDisposition?: string\n /** Override the response `Content-Language` header. */\n readonly b2ContentLanguage?: string\n /** Override the response `Content-Encoding` header. */\n readonly b2ContentEncoding?: string\n /** Override the response `Content-Type` header. */\n readonly b2ContentType?: string\n /** Override the response `Cache-Control` header. */\n readonly b2CacheControl?: string\n /** Override the response `Expires` header. */\n readonly b2Expires?: string\n /** Abort signal for cancelling the download. */\n readonly signal?: AbortSignal\n /**\n * Callback invoked as the response body is consumed.\n *\n * Progress is byte-driven, not request-driven: the callback fires per\n * chunk as the caller reads the returned `body` stream, and the final\n * `partsCompleted: 1` event only fires once the stream is read to\n * completion. Downloads that are dropped or aborted partway through\n * will NOT emit a `completePart()` event.\n */\n readonly onProgress?: ProgressListener\n}\n\n/**\n * Options accepted by {@link B2Object.head} / {@link Bucket.head}.\n * Same shape as {@link DownloadCallOptions} minus `method` (always\n * HEAD) and `onProgress` (no body to track).\n */\nexport type HeadCallOptions = Omit<DownloadCallOptions, 'method' | 'onProgress'>\n\n/**\n * Handle to a specific file (by name) within a B2 bucket.\n *\n * Provides file-scoped upload, download, and management operations.\n * Obtained via {@link Bucket.file}.\n *\n * @example\n * ```ts\n * const obj = bucket.file('photos/2026/sunset.jpg')\n * await obj.upload({ source: new BufferSource(data) })\n * const result = await obj.download()\n * ```\n */\nexport class B2Object {\n /** The file name (path) within the bucket. */\n readonly fileName: string\n private readonly client: B2Client\n private readonly bucket: Bucket\n private readonly uploadRetryOptions: RetryOptions\n\n /**\n * @param client - The parent B2Client instance.\n * @param bucket - The parent Bucket this object belongs to.\n * @param fileName - The file path within the bucket.\n * @param uploadRetryOptions - Resolved client upload retry defaults.\n *\n * @internal\n */\n constructor(\n client: B2Client,\n bucket: Bucket,\n fileName: string,\n uploadRetryOptions: RetryOptions,\n ) {\n this.client = client\n this.bucket = bucket\n this.fileName = fileName\n this.uploadRetryOptions = uploadRetryOptions\n }\n\n /**\n * Uploads data to this file name. Automatically uses multipart upload for large files.\n * @param options - Upload configuration including data source and optional settings.\n *\n * @returns Metadata for the uploaded file version.\n */\n async upload(options: B2ObjectUploadOptions): Promise<FileVersion> {\n const recommendedPartSize = this.client.accountInfo.getRecommendedPartSize()\n const isLarge = options.source.size > recommendedPartSize\n const uploadRetryOptions = mergeUploadRetryOptions(this.uploadRetryOptions, options.retry)\n\n if (isLarge) {\n const bucketInfo = resumeNeedsFreshBucketDefaults(options)\n ? await this.fetchFreshBucketInfo()\n : this.bucket.info\n const bucketDefaultRetention = bucketDefaultRetentionSnapshot(bucketInfo)\n return uploadLargeFile(this.client.raw, this.client.accountInfo, {\n ...options,\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n bucketDefaultServerSideEncryption: bucketInfo.defaultServerSideEncryption,\n ...(bucketDefaultRetention.retention !== undefined\n ? { bucketDefaultRetention: bucketDefaultRetention.retention }\n : {}),\n ...(bucketDefaultRetention.unreadable ? { bucketDefaultRetentionUnreadable: true } : {}),\n })\n }\n rejectSmallResumeFileId(options, 'B2Object.upload')\n const smallOptions = stripResumeOnlyOptions(options)\n return uploadSmallFile(this.client.raw, this.client.accountInfo, {\n ...smallOptions,\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n })\n }\n\n private async fetchFreshBucketInfo(): Promise<Bucket['info']> {\n const fresh = await this.client.listBuckets({ bucketId: this.bucket.id })\n const found = fresh[0]\n if (!found) throw new Error(`Bucket ${this.bucket.id} not found`)\n return found.info\n }\n\n /**\n * Downloads this file by name. Pass `method: 'HEAD'` to fetch only the\n * response headers (file metadata) without streaming the body.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async download(options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for this file via HTTP HEAD. Returns a\n * body-less result so callers never have to drain the (logically\n * empty) HEAD body themselves.\n *\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal. Same shape as {@link B2Object.download}'s\n * options minus `method` (always HEAD) and `onProgress` (no body).\n *\n * @returns Parsed download headers (content type, SHA-1, file info, etc.).\n */\n async head(options?: HeadCallOptions): Promise<HeadResult> {\n return headByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Downloads a specific version of this file by ID. Pass `method: 'HEAD'`\n * to fetch only the response headers (file metadata) without streaming the body.\n * @param fileId - The file version ID to download.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async downloadById(fileId: FileId, options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for a specific version of this file by ID\n * via HTTP HEAD. Returns a body-less result so callers never have to\n * drain the (logically empty) HEAD body themselves.\n *\n * @param fileId - The file version ID to inspect.\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal.\n *\n * @returns Parsed download headers.\n */\n async headById(fileId: FileId, options?: HeadCallOptions): Promise<HeadResult> {\n return headById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Creates a parallel-download ReadableStream that fetches the file in concurrent ranged chunks.\n * @param fileId - The file version ID to download.\n * @param totalSize - Total file size in bytes (needed to compute range boundaries).\n * @param options - Concurrency, range size, SSE-C decryption, and abort signal.\n *\n * @returns A Web ReadableStream of file data in sequential order.\n */\n createReadStream(\n fileId: FileId,\n totalSize: number,\n options?: {\n /** Size of each ranged GET request in bytes. Defaults to 10 MB. */\n rangeSize?: number\n /** Number of concurrent range requests. Defaults to 4. */\n concurrency?: number\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n serverSideEncryption?: SseCDownloadKey\n /** Abort signal for cancelling the download. */\n signal?: AbortSignal\n },\n ): ReadableStream<Uint8Array> {\n return createParallelDownloadStream(this.client.raw, this.client.accountInfo, {\n fileId,\n totalSize,\n ...options,\n })\n }\n\n /**\n * Creates a Web `WritableStream` that uploads streamed data into this file\n * using the multipart protocol. Pipe a `ReadableStream<Uint8Array>` into the\n * returned `writable` and await `done` to get the final {@link FileVersion}.\n *\n * Note: streaming uploads do not support resume because the size and per-part\n * hashes are not known in advance. Use {@link upload} with a buffered source\n * when resume is required.\n *\n * @param options - Streaming upload parameters (part size, concurrency, encryption).\n *\n * @returns A handle with the writable sink and a completion promise.\n */\n createWriteStream(options?: B2ObjectWriteStreamOptions): UploadWriteHandle {\n const uploadRetryOptions = mergeUploadRetryOptions(this.uploadRetryOptions, options?.retry)\n return createWriteStream(this.client.raw, this.client.accountInfo, {\n ...(options ?? {}),\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n })\n }\n\n /**\n * Retrieves metadata for a specific file version.\n * @param fileId - The file version ID to look up.\n *\n * @returns The file version metadata.\n */\n async getFileInfo(fileId: FileId): Promise<FileVersion> {\n return this.client.raw.getFileInfo(\n this.client.accountInfo.getApiUrl(),\n this.client.accountInfo.getAuthToken(),\n { fileId },\n )\n }\n\n /**\n * Hides this file by creating a hide marker at this file name.\n *\n * @returns Metadata for the newly created hide marker.\n */\n async hide(): Promise<FileVersion> {\n return this.bucket.hideFile(this.fileName)\n }\n\n /**\n * Permanently deletes a specific version of this file.\n * @param fileId - The unique identifier of the file version to delete.\n */\n async deleteVersion(fileId: FileId): Promise<void> {\n await this.bucket.deleteFileVersion(this.fileName, fileId)\n }\n\n /**\n * Sets or updates the Object Lock retention policy on a specific file\n * version of this file.\n *\n * The bucket must have Object Lock enabled (`fileLockEnabled: true` at\n * creation time). Governance-mode retention can be shortened or removed\n * by passing `bypassGovernance: true` together with an application key\n * that carries the `bypassGovernance` capability; compliance-mode\n * retention cannot be shortened by anyone until the\n * `retainUntilTimestamp` elapses.\n *\n * @param fileId - The file version to apply the policy to.\n * @param retention - The retention policy to apply.\n * @param options - Optional flag for shortening governance-mode retention.\n *\n * @returns Metadata for the updated file version.\n */\n async setRetention(\n fileId: FileId,\n retention: FileRetentionValue,\n options?: { bypassGovernance?: boolean },\n ) {\n return this.bucket.updateFileRetention(this.fileName, fileId, retention, options)\n }\n\n /**\n * Toggles the legal hold flag on a specific file version of this file.\n *\n * Legal hold is independent of retention: a file can be on legal hold\n * without any retention policy, and vice versa. The bucket must have\n * Object Lock enabled, and any caller must hold the `writeFileLegalHolds`\n * capability.\n *\n * @param fileId - The file version to apply the flag to.\n * @param legalHold - `'on'` to apply the hold, `'off'` to remove it.\n *\n * @returns Metadata for the updated file version.\n */\n async setLegalHold(fileId: FileId, legalHold: LegalHoldValue) {\n return this.bucket.updateFileLegalHold(this.fileName, fileId, legalHold)\n }\n}\n"],"mappings":";;;;;;;;AAkCA,SAAS,+BAA+B,MAAsD;CAC5F,MAAM,WAAW,KAAK;CACtB,IAAI,CAAC,SAAS,0BAA0B,OAAO,EAAE,YAAY,KAAK;CAClE,IAAI,SAAS,UAAU,MAAM,OAAO,EAAE,YAAY,MAAM;CACxD,OAAO;EAAE,WAAW,SAAS,MAAM;EAAkB,YAAY;CAAM;AACzE;AAEA,SAAS,+BAA+B,SAAyC;CAE/E,QADwB,QAAQ,WAAW,QAAQ,QAAQ,iBAAiB,KAAA,OAGzE,QAAQ,yBAAyB,KAAA,KAAa,QAAQ,kBAAkB,KAAA;AAE7E;;;;;;;;;;;;;;AA8DA,IAAa,WAAb,MAAsB;;CAEpB;CACA;CACA;CACA;;;;;;;;;CAUA,YACE,QACA,QACA,UACA,oBACA;EACA,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,WAAW;EAChB,KAAK,qBAAqB;CAC5B;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KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,SAAS;CACzE;AACF"}
1
+ {"version":3,"file":"object.js","names":[],"sources":["../src/object.ts"],"sourcesContent":["import type { Bucket } from './bucket.ts'\nimport type { B2Client } from './client.ts'\nimport { createParallelDownloadStream } from './download/parallel.ts'\nimport {\n type DownloadResult,\n downloadById,\n downloadByName,\n type HeadResult,\n headById,\n headByName,\n} from './download/single.ts'\nimport type { RetryOptions } from './http/retry.ts'\nimport { mergeUploadRetryOptions } from './internal/upload-retry-options.ts'\nimport type { SseCDownloadKey } from './raw/index.ts'\nimport type { ProgressListener } from './streams/progress.ts'\nimport type { BucketDefaultRetention, BucketDefaultServerSideEncryption } from './types/bucket.ts'\nimport type { FileVersion } from './types/file.ts'\nimport type { FileId } from './types/ids.ts'\nimport type { FileRetentionValue, LegalHoldValue } from './types/lock.ts'\nimport { uploadLargeFile } from './upload/large.ts'\nimport {\n type B2ObjectUploadOptions,\n type B2ObjectWriteStreamOptions,\n rejectSmallResumeFileId,\n stripResumeOnlyOptions,\n} from './upload/options.ts'\nimport { uploadSmallFile } from './upload/single.ts'\nimport { createWriteStream, type UploadWriteHandle } from './upload/stream.ts'\n\ninterface BucketDefaultRetentionSnapshot {\n readonly retention?: BucketDefaultRetention\n readonly unreadable: boolean\n}\n\ninterface BucketDefaultServerSideEncryptionSnapshot {\n readonly encryption?: BucketDefaultServerSideEncryption\n readonly unreadable: boolean\n}\n\nfunction bucketDefaultRetentionSnapshot(info: Bucket['info']): BucketDefaultRetentionSnapshot {\n const fileLock = info.fileLockConfiguration\n if (!fileLock.isClientAuthorizedToRead) return { unreadable: true }\n if (fileLock.value === null) return { unreadable: false }\n return { retention: fileLock.value.defaultRetention, unreadable: false }\n}\n\nfunction bucketDefaultServerSideEncryptionSnapshot(\n info: Bucket['info'],\n): BucketDefaultServerSideEncryptionSnapshot {\n const encryption = info.defaultServerSideEncryption\n if (!encryption.isClientAuthorizedToRead) return { unreadable: true }\n if (encryption.value === null) return { unreadable: false }\n return { encryption: encryption.value, unreadable: false }\n}\n\nfunction resumeNeedsFreshBucketDefaults(options: B2ObjectUploadOptions): boolean {\n const resumeRequested = options.resume === true || options.resumeFileId !== undefined\n return (\n resumeRequested &&\n (options.serverSideEncryption === undefined || options.fileRetention === undefined)\n )\n}\n\n/** Options accepted by {@link B2Object.download} and {@link B2Object.downloadById}. */\nexport interface DownloadCallOptions {\n /**\n * HTTP method. Defaults to `'GET'`. Use `'HEAD'` to fetch only\n * response headers. Prefer the dedicated {@link B2Object.head} /\n * {@link Bucket.head} method over this option — those return a\n * body-less result so callers never have to remember to drain the\n * empty body of a HEAD response.\n */\n readonly method?: 'GET' | 'HEAD'\n /** HTTP Range header value (e.g., `\"bytes=0-999\"`). */\n readonly range?: string\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n readonly serverSideEncryption?: SseCDownloadKey\n /** Override the response `Content-Disposition` header. */\n readonly b2ContentDisposition?: string\n /** Override the response `Content-Language` header. */\n readonly b2ContentLanguage?: string\n /** Override the response `Content-Encoding` header. */\n readonly b2ContentEncoding?: string\n /** Override the response `Content-Type` header. */\n readonly b2ContentType?: string\n /** Override the response `Cache-Control` header. */\n readonly b2CacheControl?: string\n /** Override the response `Expires` header. */\n readonly b2Expires?: string\n /** Abort signal for cancelling the download. */\n readonly signal?: AbortSignal\n /**\n * Callback invoked as the response body is consumed.\n *\n * Progress is byte-driven, not request-driven: the callback fires per\n * chunk as the caller reads the returned `body` stream, and the final\n * `partsCompleted: 1` event only fires once the stream is read to\n * completion. Downloads that are dropped or aborted partway through\n * will NOT emit a `completePart()` event.\n */\n readonly onProgress?: ProgressListener\n /**\n * Minimum milliseconds between byte-only progress callbacks. Defaults to\n * the SDK's 100 ms progress interval; set to 0 for per-chunk callbacks.\n * The final completion callback is always emitted immediately.\n */\n readonly progressIntervalMillis?: number\n}\n\n/**\n * Options accepted by {@link B2Object.head} / {@link Bucket.head}.\n * Same shape as {@link DownloadCallOptions} minus `method` (always\n * HEAD) and `onProgress` (no body to track).\n */\nexport type HeadCallOptions = Omit<\n DownloadCallOptions,\n 'method' | 'onProgress' | 'progressIntervalMillis'\n>\n\n/**\n * Handle to a specific file (by name) within a B2 bucket.\n *\n * Provides file-scoped upload, download, and management operations.\n * Obtained via {@link Bucket.file}.\n *\n * @example\n * ```ts\n * const obj = bucket.file('photos/2026/sunset.jpg')\n * await obj.upload({ source: new BufferSource(data) })\n * const result = await obj.download()\n * ```\n */\nexport class B2Object {\n /** The file name (path) within the bucket. */\n readonly fileName: string\n private readonly client: B2Client\n private readonly bucket: Bucket\n private readonly uploadRetryOptions: RetryOptions\n\n /**\n * @param client - The parent B2Client instance.\n * @param bucket - The parent Bucket this object belongs to.\n * @param fileName - The file path within the bucket.\n * @param uploadRetryOptions - Resolved client upload retry defaults.\n *\n * @internal\n */\n constructor(\n client: B2Client,\n bucket: Bucket,\n fileName: string,\n uploadRetryOptions: RetryOptions,\n ) {\n this.client = client\n this.bucket = bucket\n this.fileName = fileName\n this.uploadRetryOptions = uploadRetryOptions\n }\n\n /**\n * Uploads data to this file name. Automatically uses multipart upload for large files.\n * @param options - Upload configuration including data source and optional settings.\n *\n * @returns Metadata for the uploaded file version.\n */\n async upload(options: B2ObjectUploadOptions): Promise<FileVersion> {\n const recommendedPartSize = this.client.accountInfo.getRecommendedPartSize()\n const isLarge = options.source.size > recommendedPartSize\n const uploadRetryOptions = mergeUploadRetryOptions(this.uploadRetryOptions, options.retry)\n\n if (isLarge) {\n const bucketInfo = resumeNeedsFreshBucketDefaults(options)\n ? await this.fetchFreshBucketInfo()\n : this.bucket.info\n const bucketDefaultRetention = bucketDefaultRetentionSnapshot(bucketInfo)\n const bucketDefaultSse = bucketDefaultServerSideEncryptionSnapshot(bucketInfo)\n return uploadLargeFile(this.client.raw, this.client.accountInfo, {\n ...options,\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n ...(bucketDefaultSse.encryption !== undefined\n ? { bucketDefaultServerSideEncryption: bucketDefaultSse.encryption }\n : {}),\n ...(bucketDefaultSse.unreadable\n ? { bucketDefaultServerSideEncryptionUnreadable: true }\n : {}),\n ...(bucketDefaultRetention.retention !== undefined\n ? { bucketDefaultRetention: bucketDefaultRetention.retention }\n : {}),\n ...(bucketDefaultRetention.unreadable ? { bucketDefaultRetentionUnreadable: true } : {}),\n })\n }\n rejectSmallResumeFileId(options, 'B2Object.upload')\n const smallOptions = stripResumeOnlyOptions(options)\n return uploadSmallFile(this.client.raw, this.client.accountInfo, {\n ...smallOptions,\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n })\n }\n\n private async fetchFreshBucketInfo(): Promise<Bucket['info']> {\n const fresh = await this.client.listBuckets({ bucketId: this.bucket.id })\n const found = fresh[0]\n if (!found) throw new Error(`Bucket ${this.bucket.id} not found`)\n return found.info\n }\n\n /**\n * Downloads this file by name. Pass `method: 'HEAD'` to fetch only the\n * response headers (file metadata) without streaming the body.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async download(options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for this file via HTTP HEAD. Returns a\n * body-less result so callers never have to drain the (logically\n * empty) HEAD body themselves.\n *\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal. Same shape as {@link B2Object.download}'s\n * options minus `method` (always HEAD) and `onProgress` (no body).\n *\n * @returns Parsed download headers (content type, SHA-1, file info, etc.).\n */\n async head(options?: HeadCallOptions): Promise<HeadResult> {\n return headByName(this.client.raw, this.client.accountInfo, {\n bucketName: this.bucket.name,\n fileName: this.fileName,\n ...options,\n })\n }\n\n /**\n * Downloads a specific version of this file by ID. Pass `method: 'HEAD'`\n * to fetch only the response headers (file metadata) without streaming the body.\n * @param fileId - The file version ID to download.\n * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.\n *\n * @returns The download result with response headers and body stream.\n */\n async downloadById(fileId: FileId, options?: DownloadCallOptions): Promise<DownloadResult> {\n return downloadById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Fetches response headers for a specific version of this file by ID\n * via HTTP HEAD. Returns a body-less result so callers never have to\n * drain the (logically empty) HEAD body themselves.\n *\n * @param fileId - The file version ID to inspect.\n * @param options - Optional range, SSE-C decryption, response-header\n * overrides, and abort signal.\n *\n * @returns Parsed download headers.\n */\n async headById(fileId: FileId, options?: HeadCallOptions): Promise<HeadResult> {\n return headById(this.client.raw, this.client.accountInfo, {\n fileId,\n ...options,\n })\n }\n\n /**\n * Creates a parallel-download ReadableStream that fetches the file in concurrent ranged chunks.\n * @param fileId - The file version ID to download.\n * @param totalSize - Total file size in bytes (needed to compute range boundaries).\n * @param options - Concurrency, range size, SSE-C decryption, and abort signal.\n *\n * @returns A Web ReadableStream of file data in sequential order.\n */\n createReadStream(\n fileId: FileId,\n totalSize: number,\n options?: {\n /** Size of each ranged GET request in bytes. Defaults to 10 MB. */\n rangeSize?: number\n /** Number of concurrent range requests. Defaults to 4. */\n concurrency?: number\n /** SSE-C decryption parameters, required if the file was uploaded with SSE-C. */\n serverSideEncryption?: SseCDownloadKey\n /** Abort signal for cancelling the download. */\n signal?: AbortSignal\n },\n ): ReadableStream<Uint8Array> {\n return createParallelDownloadStream(this.client.raw, this.client.accountInfo, {\n fileId,\n totalSize,\n ...options,\n })\n }\n\n /**\n * Creates a Web `WritableStream` that uploads streamed data into this file\n * using the multipart protocol. Pipe a `ReadableStream<Uint8Array>` into the\n * returned `writable` and await `done` to get the final {@link FileVersion}.\n *\n * Note: streaming uploads do not support resume because the size and per-part\n * hashes are not known in advance. Use {@link upload} with a buffered source\n * when resume is required.\n *\n * @param options - Streaming upload parameters (part size, concurrency, encryption).\n *\n * @returns A handle with the writable sink and a completion promise.\n */\n createWriteStream(options?: B2ObjectWriteStreamOptions): UploadWriteHandle {\n const uploadRetryOptions = mergeUploadRetryOptions(this.uploadRetryOptions, options?.retry)\n return createWriteStream(this.client.raw, this.client.accountInfo, {\n ...(options ?? {}),\n bucketId: this.bucket.id,\n fileName: this.fileName,\n retry: uploadRetryOptions,\n })\n }\n\n /**\n * Retrieves metadata for a specific file version.\n * @param fileId - The file version ID to look up.\n *\n * @returns The file version metadata.\n */\n async getFileInfo(fileId: FileId): Promise<FileVersion> {\n return this.client.raw.getFileInfo(\n this.client.accountInfo.getApiUrl(),\n this.client.accountInfo.getAuthToken(),\n { fileId },\n )\n }\n\n /**\n * Hides this file by creating a hide marker at this file name.\n *\n * @returns Metadata for the newly created hide marker.\n */\n async hide(): Promise<FileVersion> {\n return this.bucket.hideFile(this.fileName)\n }\n\n /**\n * Permanently deletes a specific version of this file.\n * @param fileId - The unique identifier of the file version to delete.\n */\n async deleteVersion(fileId: FileId): Promise<void> {\n await this.bucket.deleteFileVersion(this.fileName, fileId)\n }\n\n /**\n * Sets or updates the Object Lock retention policy on a specific file\n * version of this file.\n *\n * The bucket must have Object Lock enabled (`fileLockEnabled: true` at\n * creation time). Governance-mode retention can be shortened or removed\n * by passing `bypassGovernance: true` together with an application key\n * that carries the `bypassGovernance` capability; compliance-mode\n * retention cannot be shortened by anyone until the\n * `retainUntilTimestamp` elapses.\n *\n * @param fileId - The file version to apply the policy to.\n * @param retention - The retention policy to apply.\n * @param options - Optional flag for shortening governance-mode retention.\n *\n * @returns Metadata for the updated file version.\n */\n async setRetention(\n fileId: FileId,\n retention: FileRetentionValue,\n options?: { bypassGovernance?: boolean },\n ) {\n return this.bucket.updateFileRetention(this.fileName, fileId, retention, options)\n }\n\n /**\n * Toggles the legal hold flag on a specific file version of this file.\n *\n * Legal hold is independent of retention: a file can be on legal hold\n * without any retention policy, and vice versa. The bucket must have\n * Object Lock enabled, and any caller must hold the `writeFileLegalHolds`\n * capability.\n *\n * @param fileId - The file version to apply the flag to.\n * @param legalHold - `'on'` to apply the hold, `'off'` to remove it.\n *\n * @returns Metadata for the updated file version.\n */\n async setLegalHold(fileId: FileId, legalHold: LegalHoldValue) {\n return this.bucket.updateFileLegalHold(this.fileName, fileId, legalHold)\n }\n}\n"],"mappings":";;;;;;;;AAuCA,SAAS,+BAA+B,MAAsD;CAC5F,MAAM,WAAW,KAAK;CACtB,IAAI,CAAC,SAAS,0BAA0B,OAAO,EAAE,YAAY,KAAK;CAClE,IAAI,SAAS,UAAU,MAAM,OAAO,EAAE,YAAY,MAAM;CACxD,OAAO;EAAE,WAAW,SAAS,MAAM;EAAkB,YAAY;CAAM;AACzE;AAEA,SAAS,0CACP,MAC2C;CAC3C,MAAM,aAAa,KAAK;CACxB,IAAI,CAAC,WAAW,0BAA0B,OAAO,EAAE,YAAY,KAAK;CACpE,IAAI,WAAW,UAAU,MAAM,OAAO,EAAE,YAAY,MAAM;CAC1D,OAAO;EAAE,YAAY,WAAW;EAAO,YAAY;CAAM;AAC3D;AAEA,SAAS,+BAA+B,SAAyC;CAE/E,QADwB,QAAQ,WAAW,QAAQ,QAAQ,iBAAiB,KAAA,OAGzE,QAAQ,yBAAyB,KAAA,KAAa,QAAQ,kBAAkB,KAAA;AAE7E;;;;;;;;;;;;;;AAuEA,IAAa,WAAb,MAAsB;;CAEpB;CACA;CACA;CACA;;;;;;;;;CAUA,YACE,QACA,QACA,UACA,oBACA;EACA,KAAK,SAAS;EACd,KAAK,SAAS;EACd,KAAK,WAAW;EAChB,KAAK,qBAAqB;CAC5B;;;;;;;CAQA,MAAM,OAAO,SAAsD;EACjE,MAAM,sBAAsB,KAAK,OAAO,YAAY,uBAAuB;EAC3E,MAAM,UAAU,QAAQ,OAAO,OAAO;EACtC,MAAM,qBAAqB,wBAAwB,KAAK,oBAAoB,QAAQ,KAAK;EAEzF,IAAI,SAAS;GACX,MAAM,aAAa,+BAA+B,OAAO,IACrD,MAAM,KAAK,qBAAqB,IAChC,KAAK,OAAO;GAChB,MAAM,yBAAyB,+BAA+B,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AAa,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GAC5D;GACA,GAAG;EACL,CAAC;CACH;;;;;;;;;;;;CAaA,MAAM,SAAS,QAAgB,SAAgD;EAC7E,OAAO,SAAS,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GACxD;GACA,GAAG;EACL,CAAC;CACH;;;;;;;;;CAUA,iBACE,QACA,WACA,SAU4B;EAC5B,OAAO,6BAA6B,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GAC5E;GACA;GACA,GAAG;EACL,CAAC;CACH;;;;;;;;;;;;;;CAeA,kBAAkB,SAAyD;EACzE,MAAM,qBAAqB,wBAAwB,KAAK,oBAAoB,SAAS,KAAK;EAC1F,OAAO,kBAAkB,KAAK,OAAO,KAAK,KAAK,OAAO,aAAa;GACjE,GAAI,WAAW,CAAC;GAChB,UAAU,KAAK,OAAO;GACtB,UAAU,KAAK;GACf,OAAO;EACT,CAAC;CACH;;;;;;;CAQA,MAAM,YAAY,QAAsC;EACtD,OAAO,KAAK,OAAO,IAAI,YACrB,KAAK,OAAO,YAAY,UAAU,GAClC,KAAK,OAAO,YAAY,aAAa,GACrC,EAAE,OAAO,CACX;CACF;;;;;;CAOA,MAAM,OAA6B;EACjC,OAAO,KAAK,OAAO,SAAS,KAAK,QAAQ;CAC3C;;;;;CAMA,MAAM,cAAc,QAA+B;EACjD,MAAM,KAAK,OAAO,kBAAkB,KAAK,UAAU,MAAM;CAC3D;;;;;;;;;;;;;;;;;;CAmBA,MAAM,aACJ,QACA,WACA,SACA;EACA,OAAO,KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,WAAW,OAAO;CAClF;;;;;;;;;;;;;;CAeA,MAAM,aAAa,QAAgB,WAA2B;EAC5D,OAAO,KAAK,OAAO,oBAAoB,KAAK,UAAU,QAAQ,SAAS;CACzE;AACF"}
@@ -1,6 +1,7 @@
1
1
  const require_abort = require("../util/abort.cjs");
2
2
  const require_retry = require("../http/retry.cjs");
3
3
  const require_realms = require("../auth/realms.cjs");
4
+ const require_reauth_coalescer = require("../auth/reauth-coalescer.cjs");
4
5
  const require_url_guard = require("../http/url-guard.cjs");
5
6
  const require_transport = require("../http/transport.cjs");
6
7
  const require_in_memory = require("./in-memory.cjs");
@@ -30,7 +31,7 @@ var PartnerAuthCore = class {
30
31
  #masterKey;
31
32
  additionalAllowedSuffixes;
32
33
  disableSsrfGuard;
33
- #inflightReauth = null;
34
+ reauthCoalescer;
34
35
  /**
35
36
  * Creates a shared Partner authorization core.
36
37
  *
@@ -44,6 +45,7 @@ var PartnerAuthCore = class {
44
45
  this.additionalAllowedSuffixes = options.additionalAllowedHostSuffixes;
45
46
  this.disableSsrfGuard = options.disableSsrfGuard ?? false;
46
47
  this.allowCustomAuthorizeRealm = options.allowCustomAuthorizeRealm ?? false;
48
+ this.reauthCoalescer = new require_reauth_coalescer.ReauthCoalescer((signal) => this.doReauthorize(signal));
47
49
  let baseTransport;
48
50
  if (options.transport !== void 0) {
49
51
  baseTransport = options.transport;
@@ -142,28 +144,7 @@ var PartnerAuthCore = class {
142
144
  }
143
145
  }
144
146
  reauthorize(signal) {
145
- require_abort.throwIfSignalAborted(signal);
146
- const inflight = this.#inflightReauth ?? this.startReauthorize();
147
- inflight.waiters += 1;
148
- return require_abort.raceWithAbort(inflight.promise, signal).finally(() => {
149
- inflight.waiters -= 1;
150
- if (inflight.waiters === 0 && !inflight.settled && !inflight.controller.signal.aborted) inflight.controller.abort(signal?.aborted === true ? require_abort.abortReason(signal) : void 0);
151
- });
152
- }
153
- startReauthorize() {
154
- const controller = new AbortController();
155
- const inflight = {
156
- controller,
157
- promise: require_abort.raceWithAbort(this.doReauthorize(controller.signal), controller.signal).finally(() => {
158
- if (this.#inflightReauth?.controller !== controller) return;
159
- this.#inflightReauth.settled = true;
160
- this.#inflightReauth = null;
161
- }),
162
- waiters: 0,
163
- settled: false
164
- };
165
- this.#inflightReauth = inflight;
166
- return inflight;
147
+ return this.reauthCoalescer.run(signal);
167
148
  }
168
149
  async doReauthorize(signal) {
169
150
  return (await this.authorize({ signal })).authorizationToken;
@@ -1 +1 @@
1
- {"version":3,"file":"auth-core.cjs","names":["#masterKeyId","#masterKey","#inflightReauth"],"sources":["../../src/partner/auth-core.ts"],"sourcesContent":["import { getRealmUrl } from '../auth/realms.ts'\nimport { DEFAULT_RETRY_OPTIONS, type RetryOptions } from '../http/retry.ts'\nimport type { HttpTransport } from '../http/transport.ts'\nimport { FetchTransport, RetryTransport } from '../http/transport.ts'\nimport { UrlGuard } from '../http/url-guard.ts'\nimport type { PartnerAuthorizeResponse } from '../types/partner.ts'\nimport { abortReason, raceWithAbort, throwIfSignalAborted } from '../util/abort.ts'\nimport type { PartnerAccountInfo } from './account-info.ts'\nimport { InMemoryPartnerAccountInfo } from './in-memory.ts'\nimport {\n derivePartnerAllowedSuffixes,\n PartnerRawClient,\n validatePartnerAuthorizeResponseEndpoints,\n} from './raw.ts'\n\n/** Shared Partner authorization options used by Partner and Backup facades. */\nexport interface PartnerAuthCoreOptions {\n /** The Master Application Key ID for the partner administrator account. */\n readonly masterKeyId: string\n /** The Master Application Key secret. */\n readonly masterKey: string\n /** B2 realm alias or direct trusted realm URL. Defaults to `\"production\"`. */\n readonly realm?: string\n /** Storage backend for Partner authorization state. */\n readonly partnerAccountInfo?: PartnerAccountInfo\n /** Custom HTTP transport. Defaults to {@link FetchTransport}. */\n readonly transport?: HttpTransport\n /** Override retry behavior for retryable requests. */\n readonly retry?: Partial<RetryOptions>\n /** Custom user-agent string prepended to the SDK default. */\n readonly userAgent?: string\n /** Extra trusted host suffixes to merge into the default SSRF guard. */\n readonly additionalAllowedHostSuffixes?: readonly string[]\n /** Explicitly disable default SSRF guard suffix locking. */\n readonly disableSsrfGuard?: boolean\n /** Whether the default fetch transport may follow same-origin GET/HEAD redirects. */\n readonly followSameOriginRedirects?: boolean\n /** Allow direct custom authorize realms for tests or private proxies. */\n readonly allowCustomAuthorizeRealm?: boolean\n}\n\n/** Options for Partner authorization through {@link PartnerAuthCore}. */\nexport interface PartnerAuthCoreAuthorizeOptions {\n /** Abort signal for cancelling the authorize request. */\n readonly signal?: AbortSignal\n}\n\ninterface InflightPartnerReauth {\n readonly controller: AbortController\n readonly promise: Promise<string>\n waiters: number\n settled: boolean\n}\n\n/**\n * Internal Partner authorization state machine shared by public facades.\n *\n * @internal\n */\nexport class PartnerAuthCore {\n /** Low-level Partner raw client used for authorization and Partner endpoints. */\n readonly raw: PartnerRawClient\n /** Partner authorization state storage. */\n readonly partnerAccountInfo: PartnerAccountInfo\n /** Default transport URL guard, or null when a custom transport owns guarding. */\n readonly urlGuard: UrlGuard | null\n /** Retry-wrapped transport shared by facade-specific raw clients. */\n readonly transport: HttpTransport\n /** Endpoint suffixes validated from cached authorization during construction. */\n readonly cachedEndpointSuffixes: readonly string[] | undefined\n /** Resolved Partner authorize realm URL. */\n private readonly realmUrl: string\n /** Whether custom authorize realms are trusted. */\n private readonly allowCustomAuthorizeRealm: boolean\n readonly #masterKeyId: string\n readonly #masterKey: string\n private readonly additionalAllowedSuffixes: readonly string[] | undefined\n private readonly disableSsrfGuard: boolean\n #inflightReauth: InflightPartnerReauth | null = null\n\n /**\n * Creates a shared Partner authorization core.\n *\n * @param options - Credentials, state storage, transport, retry, and guard settings.\n */\n constructor(options: PartnerAuthCoreOptions) {\n this.#masterKeyId = options.masterKeyId\n this.#masterKey = options.masterKey\n this.realmUrl = getRealmUrl(options.realm ?? 'production')\n this.partnerAccountInfo = options.partnerAccountInfo ?? new InMemoryPartnerAccountInfo()\n this.additionalAllowedSuffixes = options.additionalAllowedHostSuffixes\n this.disableSsrfGuard = options.disableSsrfGuard ?? false\n this.allowCustomAuthorizeRealm = options.allowCustomAuthorizeRealm ?? false\n\n let baseTransport: HttpTransport\n if (options.transport !== undefined) {\n baseTransport = options.transport\n this.urlGuard = null\n } else {\n const urlGuard = new UrlGuard()\n baseTransport = new FetchTransport({\n urlGuard,\n ...(options.userAgent !== undefined ? { userAgent: options.userAgent } : {}),\n ...(options.followSameOriginRedirects !== undefined\n ? { followSameOriginRedirects: options.followSameOriginRedirects }\n : {}),\n })\n this.urlGuard = urlGuard\n }\n\n this.transport = new RetryTransport({\n transport: baseTransport,\n retry: { ...DEFAULT_RETRY_OPTIONS, ...options.retry },\n onReauth: (signal) => this.reauthorize(signal),\n })\n\n this.cachedEndpointSuffixes = this.validateCachedAuth()\n if (this.cachedEndpointSuffixes !== undefined) {\n this.lockUrlGuardFromSuffixes(this.cachedEndpointSuffixes)\n }\n\n this.raw = new PartnerRawClient({\n transport: this.transport,\n ...(this.cachedEndpointSuffixes !== undefined\n ? { authorizedPartnerEndpointSuffixes: this.cachedEndpointSuffixes }\n : {}),\n ...(options.allowCustomAuthorizeRealm !== undefined\n ? { allowCustomAuthorizeRealm: options.allowCustomAuthorizeRealm }\n : {}),\n })\n }\n\n /**\n * Authenticates with B2 Partner authorization and stores the authorization state.\n *\n * @param options - Optional abort signal.\n *\n * @returns The normalized Partner authorization response.\n */\n async authorize(options?: PartnerAuthCoreAuthorizeOptions): Promise<PartnerAuthorizeResponse> {\n throwIfSignalAborted(options?.signal)\n const auth = await this.raw.authorizePartner(\n this.#masterKeyId,\n this.#masterKey,\n this.realmUrl,\n options?.signal !== undefined ? { signal: options.signal } : undefined,\n )\n throwIfSignalAborted(options?.signal)\n this.partnerAccountInfo.setAuth(auth)\n this.lockUrlGuard(auth)\n return auth\n }\n\n /**\n * Locks the default transport URL guard to suffixes from a validated auth response.\n *\n * @param auth - Partner authorization response to derive suffixes from.\n */\n lockUrlGuard(auth: PartnerAuthorizeResponse): void {\n this.lockUrlGuardFromSuffixes(derivePartnerAllowedSuffixes(auth, this.realmUrl))\n }\n\n /**\n * Locks the default transport URL guard to previously validated endpoint suffixes.\n *\n * @param derived - Validated endpoint suffixes.\n */\n private lockUrlGuardFromSuffixes(derived: readonly string[]): void {\n if (this.urlGuard === null) return\n const merged =\n this.disableSsrfGuard === true\n ? []\n : this.additionalAllowedSuffixes !== undefined\n ? Array.from(new Set([...derived, ...this.additionalAllowedSuffixes]))\n : derived\n this.urlGuard.setAllowedSuffixes(merged)\n }\n\n /**\n * Validates a Partner authorization snapshot and returns endpoint suffixes.\n *\n * @param auth - Partner authorization response to validate.\n *\n * @returns Host suffixes safe for Partner-token endpoint requests.\n *\n * @internal\n */\n private validateEndpointSuffixes(auth: PartnerAuthorizeResponse): readonly string[] {\n return validatePartnerAuthorizeResponseEndpoints(\n auth,\n this.realmUrl,\n this.allowCustomAuthorizeRealm,\n )\n }\n\n /**\n * Validates an auth snapshot, locks the default URL guard, and returns endpoint suffixes.\n *\n * @param auth - Partner authorization response to validate and activate.\n *\n * @returns Host suffixes safe for Partner-token endpoint requests.\n *\n * @internal\n */\n activateEndpointSuffixes(auth: PartnerAuthorizeResponse): readonly string[] {\n const suffixes = this.validateEndpointSuffixes(auth)\n this.lockUrlGuardFromSuffixes(suffixes)\n return suffixes\n }\n\n private validateCachedAuth(): readonly string[] | undefined {\n const cachedAuth = this.partnerAccountInfo.getAuth()\n if (cachedAuth === null) return undefined\n try {\n return this.validateEndpointSuffixes(cachedAuth)\n } catch {\n // Do not mutate a shared PartnerAccountInfo during construction. The\n // facade will ignore this auth locally until authorize() replaces it.\n return undefined\n }\n }\n\n private reauthorize(signal: AbortSignal | undefined): Promise<string> {\n throwIfSignalAborted(signal)\n const inflight = this.#inflightReauth ?? this.startReauthorize()\n inflight.waiters += 1\n return raceWithAbort(inflight.promise, signal).finally(() => {\n inflight.waiters -= 1\n if (inflight.waiters === 0 && !inflight.settled && !inflight.controller.signal.aborted) {\n inflight.controller.abort(signal?.aborted === true ? abortReason(signal) : undefined)\n }\n })\n }\n\n private startReauthorize(): InflightPartnerReauth {\n const controller = new AbortController()\n const promise = raceWithAbort(this.doReauthorize(controller.signal), controller.signal).finally(\n () => {\n if (this.#inflightReauth?.controller !== controller) return\n this.#inflightReauth.settled = true\n this.#inflightReauth = null\n },\n )\n const inflight: InflightPartnerReauth = {\n controller,\n promise,\n waiters: 0,\n settled: false,\n }\n this.#inflightReauth = inflight\n return inflight\n }\n\n private async doReauthorize(signal: AbortSignal): Promise<string> {\n const auth = await this.authorize({ signal })\n return auth.authorizationToken\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA2DA,IAAa,kBAAb,MAA6B;;CAE3B;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;CACA;CACA;CACA;CACA;CACA,kBAAgD;;;;;;CAOhD,YAAY,SAAiC;EAC3C,KAAKA,eAAe,QAAQ;EAC5B,KAAKC,aAAa,QAAQ;EAC1B,KAAK,WAAW,eAAA,YAAY,QAAQ,SAAS,YAAY;EACzD,KAAK,qBAAqB,QAAQ,sBAAsB,IAAI,kBAAA,2BAA2B;EACvF,KAAK,4BAA4B,QAAQ;EACzC,KAAK,mBAAmB,QAAQ,oBAAoB;EACpD,KAAK,4BAA4B,QAAQ,6BAA6B;EAEtE,IAAI;EACJ,IAAI,QAAQ,cAAc,KAAA,GAAW;GACnC,gBAAgB,QAAQ;GACxB,KAAK,WAAW;EAClB,OAAO;GACL,MAAM,WAAW,IAAI,kBAAA,SAAS;GAC9B,gBAAgB,IAAI,kBAAA,eAAe;IACjC;IACA,GAAI,QAAQ,cAAc,KAAA,IAAY,EAAE,WAAW,QAAQ,UAAU,IAAI,CAAC;IAC1E,GAAI,QAAQ,8BAA8B,KAAA,IACtC,EAAE,2BAA2B,QAAQ,0BAA0B,IAC/D,CAAC;GACP,CAAC;GACD,KAAK,WAAW;EAClB;EAEA,KAAK,YAAY,IAAI,kBAAA,eAAe;GAClC,WAAW;GACX,OAAO;IAAE,GAAG,cAAA;IAAuB,GAAG,QAAQ;GAAM;GACpD,WAAW,WAAW,KAAK,YAAY,MAAM;EAC/C,CAAC;EAED,KAAK,yBAAyB,KAAK,mBAAmB;EACtD,IAAI,KAAK,2BAA2B,KAAA,GAClC,KAAK,yBAAyB,KAAK,sBAAsB;EAG3D,KAAK,MAAM,IAAI,YAAA,iBAAiB;GAC9B,WAAW,KAAK;GA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ACpE,cAAA,qBAAqB,MAAM;EAC3B,MAAM,WAAW,KAAKC,mBAAmB,KAAK,iBAAiB;EAC/D,SAAS,WAAW;EACpB,OAAO,cAAA,cAAc,SAAS,SAAS,MAAM,CAAC,CAAC,cAAc;GAC3D,SAAS,WAAW;GACpB,IAAI,SAAS,YAAY,KAAK,CAAC,SAAS,WAAW,CAAC,SAAS,WAAW,OAAO,SAC7E,SAAS,WAAW,MAAM,QAAQ,YAAY,OAAO,cAAA,YAAY,MAAM,IAAI,KAAA,CAAS;EAExF,CAAC;CACH;CAEA,mBAAkD;EAChD,MAAM,aAAa,IAAI,gBAAgB;EAQvC,MAAM,WAAkC;GACtC;GACA,SATc,cAAA,cAAc,KAAK,cAAc,WAAW,MAAM,GAAG,WAAW,MAAM,CAAC,CAAC,cAChF;IACJ,IAAI,KAAKA,iBAAiB,eAAe,YAAY;IACrD,KAAKA,gBAAgB,UAAU;IAC/B,KAAKA,kBAAkB;GACzB,CAIA;GACA,SAAS;GACT,SAAS;EACX;EACA,KAAKA,kBAAkB;EACvB,OAAO;CACT;CAEA,MAAc,cAAc,QAAsC;EAEhE,QAAO,MADY,KAAK,UAAU,EAAE,OAAO,CAAC,EAAA,CAChC;CACd;AACF"}
1
+ {"version":3,"file":"auth-core.cjs","names":[],"sources":["../../src/partner/auth-core.ts"],"sourcesContent":["import { getRealmUrl } from '../auth/realms.ts'\nimport { ReauthCoalescer } from '../auth/reauth-coalescer.ts'\nimport { DEFAULT_RETRY_OPTIONS, type RetryOptions } from '../http/retry.ts'\nimport type { HttpTransport } from '../http/transport.ts'\nimport { FetchTransport, RetryTransport } from '../http/transport.ts'\nimport { UrlGuard } from '../http/url-guard.ts'\nimport type { PartnerAuthorizeResponse } from '../types/partner.ts'\nimport { throwIfSignalAborted } from '../util/abort.ts'\nimport type { PartnerAccountInfo } from './account-info.ts'\nimport { InMemoryPartnerAccountInfo } from './in-memory.ts'\nimport {\n derivePartnerAllowedSuffixes,\n PartnerRawClient,\n validatePartnerAuthorizeResponseEndpoints,\n} from './raw.ts'\n\n/** Shared Partner authorization options used by Partner and Backup facades. */\nexport interface PartnerAuthCoreOptions {\n /** The Master Application Key ID for the partner administrator account. */\n readonly masterKeyId: string\n /** The Master Application Key secret. */\n readonly masterKey: string\n /** B2 realm alias or direct trusted realm URL. Defaults to `\"production\"`. */\n readonly realm?: string\n /** Storage backend for Partner authorization state. */\n readonly partnerAccountInfo?: PartnerAccountInfo\n /** Custom HTTP transport. Defaults to {@link FetchTransport}. */\n readonly transport?: HttpTransport\n /** Override retry behavior for retryable requests. */\n readonly retry?: Partial<RetryOptions>\n /** Custom user-agent string prepended to the SDK default. */\n readonly userAgent?: string\n /** Extra trusted host suffixes to merge into the default SSRF guard. */\n readonly additionalAllowedHostSuffixes?: readonly string[]\n /** Explicitly disable default SSRF guard suffix locking. */\n readonly disableSsrfGuard?: boolean\n /** Whether the default fetch transport may follow same-origin GET/HEAD redirects. */\n readonly followSameOriginRedirects?: boolean\n /** Allow direct custom authorize realms for tests or private proxies. */\n readonly allowCustomAuthorizeRealm?: boolean\n}\n\n/** Options for Partner authorization through {@link PartnerAuthCore}. */\nexport interface PartnerAuthCoreAuthorizeOptions {\n /** Abort signal for cancelling the authorize request. */\n readonly signal?: AbortSignal\n}\n\n/**\n * Internal Partner authorization state machine shared by public facades.\n *\n * @internal\n */\nexport class PartnerAuthCore {\n /** Low-level Partner raw client used for authorization and Partner endpoints. */\n readonly raw: PartnerRawClient\n /** Partner authorization state storage. */\n readonly partnerAccountInfo: PartnerAccountInfo\n /** Default transport URL guard, or null when a custom transport owns guarding. */\n readonly urlGuard: UrlGuard | null\n /** Retry-wrapped transport shared by facade-specific raw clients. */\n readonly transport: HttpTransport\n /** Endpoint suffixes validated from cached authorization during construction. */\n readonly cachedEndpointSuffixes: readonly string[] | undefined\n /** Resolved Partner authorize realm URL. */\n private readonly realmUrl: string\n /** Whether custom authorize realms are trusted. */\n private readonly allowCustomAuthorizeRealm: boolean\n readonly #masterKeyId: string\n readonly #masterKey: string\n private readonly additionalAllowedSuffixes: readonly string[] | undefined\n private readonly disableSsrfGuard: boolean\n private readonly reauthCoalescer: ReauthCoalescer<string>\n\n /**\n * Creates a shared Partner authorization core.\n *\n * @param options - Credentials, state storage, transport, retry, and guard settings.\n */\n constructor(options: PartnerAuthCoreOptions) {\n this.#masterKeyId = options.masterKeyId\n this.#masterKey = options.masterKey\n this.realmUrl = getRealmUrl(options.realm ?? 'production')\n this.partnerAccountInfo = options.partnerAccountInfo ?? new InMemoryPartnerAccountInfo()\n this.additionalAllowedSuffixes = options.additionalAllowedHostSuffixes\n this.disableSsrfGuard = options.disableSsrfGuard ?? false\n this.allowCustomAuthorizeRealm = options.allowCustomAuthorizeRealm ?? false\n this.reauthCoalescer = new ReauthCoalescer((signal) => this.doReauthorize(signal))\n\n let baseTransport: HttpTransport\n if (options.transport !== undefined) {\n baseTransport = options.transport\n this.urlGuard = null\n } else {\n const urlGuard = new UrlGuard()\n baseTransport = new FetchTransport({\n urlGuard,\n ...(options.userAgent !== undefined ? { userAgent: options.userAgent } : {}),\n ...(options.followSameOriginRedirects !== undefined\n ? { followSameOriginRedirects: options.followSameOriginRedirects }\n : {}),\n })\n this.urlGuard = urlGuard\n }\n\n this.transport = new RetryTransport({\n transport: baseTransport,\n retry: { ...DEFAULT_RETRY_OPTIONS, ...options.retry },\n onReauth: (signal) => this.reauthorize(signal),\n })\n\n this.cachedEndpointSuffixes = this.validateCachedAuth()\n if (this.cachedEndpointSuffixes !== undefined) {\n this.lockUrlGuardFromSuffixes(this.cachedEndpointSuffixes)\n }\n\n this.raw = new PartnerRawClient({\n transport: this.transport,\n ...(this.cachedEndpointSuffixes !== undefined\n ? { authorizedPartnerEndpointSuffixes: this.cachedEndpointSuffixes }\n : {}),\n ...(options.allowCustomAuthorizeRealm !== undefined\n ? { allowCustomAuthorizeRealm: options.allowCustomAuthorizeRealm }\n : {}),\n })\n }\n\n /**\n * Authenticates with B2 Partner authorization and stores the authorization state.\n *\n * @param options - Optional abort signal.\n *\n * @returns The normalized Partner authorization response.\n */\n async authorize(options?: PartnerAuthCoreAuthorizeOptions): Promise<PartnerAuthorizeResponse> {\n throwIfSignalAborted(options?.signal)\n const auth = await this.raw.authorizePartner(\n this.#masterKeyId,\n this.#masterKey,\n this.realmUrl,\n options?.signal !== undefined ? { signal: options.signal } : undefined,\n )\n throwIfSignalAborted(options?.signal)\n this.partnerAccountInfo.setAuth(auth)\n this.lockUrlGuard(auth)\n return auth\n }\n\n /**\n * Locks the default transport URL guard to suffixes from a validated auth response.\n *\n * @param auth - Partner authorization response to derive suffixes from.\n */\n lockUrlGuard(auth: PartnerAuthorizeResponse): void {\n this.lockUrlGuardFromSuffixes(derivePartnerAllowedSuffixes(auth, this.realmUrl))\n }\n\n /**\n * Locks the default transport URL guard to previously validated endpoint suffixes.\n *\n * @param derived - Validated endpoint suffixes.\n */\n private lockUrlGuardFromSuffixes(derived: readonly string[]): void {\n if (this.urlGuard === null) return\n const merged =\n this.disableSsrfGuard === true\n ? []\n : this.additionalAllowedSuffixes !== undefined\n ? Array.from(new Set([...derived, ...this.additionalAllowedSuffixes]))\n : derived\n this.urlGuard.setAllowedSuffixes(merged)\n }\n\n /**\n * Validates a Partner authorization snapshot and returns endpoint suffixes.\n *\n * @param auth - Partner authorization response to validate.\n *\n * @returns Host suffixes safe for Partner-token endpoint requests.\n *\n * @internal\n */\n private validateEndpointSuffixes(auth: PartnerAuthorizeResponse): readonly string[] {\n return validatePartnerAuthorizeResponseEndpoints(\n auth,\n this.realmUrl,\n this.allowCustomAuthorizeRealm,\n )\n }\n\n /**\n * Validates an auth snapshot, locks the default URL guard, and returns endpoint suffixes.\n *\n * @param auth - Partner authorization response to validate and activate.\n *\n * @returns Host suffixes safe for Partner-token endpoint requests.\n *\n * @internal\n */\n activateEndpointSuffixes(auth: PartnerAuthorizeResponse): readonly string[] {\n const suffixes = this.validateEndpointSuffixes(auth)\n this.lockUrlGuardFromSuffixes(suffixes)\n return suffixes\n }\n\n private validateCachedAuth(): readonly string[] | undefined {\n const cachedAuth = this.partnerAccountInfo.getAuth()\n if (cachedAuth === null) return undefined\n try {\n return this.validateEndpointSuffixes(cachedAuth)\n } catch {\n // Do not mutate a shared PartnerAccountInfo during construction. The\n // facade will ignore this auth locally until authorize() replaces it.\n return undefined\n }\n }\n\n private reauthorize(signal: AbortSignal | undefined): Promise<string> {\n return this.reauthCoalescer.run(signal)\n }\n\n private async doReauthorize(signal: AbortSignal): Promise<string> {\n const auth = await this.authorize({ signal })\n return auth.authorizationToken\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAqDA,IAAa,kBAAb,MAA6B;;CAE3B;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;;CAEA;CACA;CACA;CACA;CACA;CACA;;;;;;CAOA,YAAY,SAAiC;EAC3C,KAAK,eAAe,QAAQ;EAC5B,KAAK,aAAa,QAAQ;EAC1B,KAAK,WAAW,eAAA,YAAY,QAAQ,SAAS,YAAY;EACzD,KAAK,qBAAqB,QAAQ,sBAAsB,IAAI,kBAAA,2BAA2B;EACvF,KAAK,4BAA4B,QAAQ;EACzC,KAAK,mBAAmB,QAAQ,oBAAoB;EACpD,KAAK,4BAA4B,QAAQ,6BAA6B;EACtE,KAAK,kBAAkB,IAAI,yBAAA,iBAAiB,WAAW,KAAK,cAAc,MAAM,CAAC;EAEjF,IAAI;EACJ,IAAI,QAAQ,cAAc,KAAA,GAAW;GACnC,gBAAgB,QAAQ;GACxB,KAAK,WAAW;EAClB,OAAO;GACL,MAAM,WAAW,IAAI,kBAAA,SAAS;GAC9B,gBAAgB,IAAI,kBAAA,eAAe;IACjC;IACA,GAAI,QAAQ,cAAc,KAAA,IAAY,EAAE,WAAW,QAAQ,UAAU,IAAI,CAAC;IAC1E,GAAI,QAAQ,8BAA8B,KAAA,IACtC,EAAE,2BAA2B,QAAQ,0BAA0B,IAC/D,CAAC;GACP,CAAC;GACD,KAAK,WAAW;EAClB;EAEA,KAAK,YAAY,IAAI,kBAA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