@backblaze-labs/b2-sdk 0.1.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 (512) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/LICENSE +21 -0
  3. package/README.md +664 -0
  4. package/dist/auth/account-info.d.cts +51 -0
  5. package/dist/auth/account-info.d.cts.map +1 -0
  6. package/dist/auth/account-info.d.ts +51 -0
  7. package/dist/auth/account-info.d.ts.map +1 -0
  8. package/dist/auth/file.cjs +210 -0
  9. package/dist/auth/file.cjs.map +1 -0
  10. package/dist/auth/file.d.cts +157 -0
  11. package/dist/auth/file.d.cts.map +1 -0
  12. package/dist/auth/file.d.ts +157 -0
  13. package/dist/auth/file.d.ts.map +1 -0
  14. package/dist/auth/file.js +210 -0
  15. package/dist/auth/file.js.map +1 -0
  16. package/dist/auth/in-memory.cjs +184 -0
  17. package/dist/auth/in-memory.cjs.map +1 -0
  18. package/dist/auth/in-memory.d.cts +147 -0
  19. package/dist/auth/in-memory.d.cts.map +1 -0
  20. package/dist/auth/in-memory.d.ts +147 -0
  21. package/dist/auth/in-memory.d.ts.map +1 -0
  22. package/dist/auth/in-memory.js +184 -0
  23. package/dist/auth/in-memory.js.map +1 -0
  24. package/dist/auth/index.cjs +10 -0
  25. package/dist/auth/index.cjs.map +1 -0
  26. package/dist/auth/index.d.cts +6 -0
  27. package/dist/auth/index.d.cts.map +1 -0
  28. package/dist/auth/index.d.ts +6 -0
  29. package/dist/auth/index.d.ts.map +1 -0
  30. package/dist/auth/index.js +10 -0
  31. package/dist/auth/index.js.map +1 -0
  32. package/dist/auth/realms.cjs +12 -0
  33. package/dist/auth/realms.cjs.map +1 -0
  34. package/dist/auth/realms.d.cts +12 -0
  35. package/dist/auth/realms.d.cts.map +1 -0
  36. package/dist/auth/realms.d.ts +12 -0
  37. package/dist/auth/realms.d.ts.map +1 -0
  38. package/dist/auth/realms.js +12 -0
  39. package/dist/auth/realms.js.map +1 -0
  40. package/dist/auth/upload-url-pool.cjs +52 -0
  41. package/dist/auth/upload-url-pool.cjs.map +1 -0
  42. package/dist/auth/upload-url-pool.d.cts +35 -0
  43. package/dist/auth/upload-url-pool.d.cts.map +1 -0
  44. package/dist/auth/upload-url-pool.d.ts +35 -0
  45. package/dist/auth/upload-url-pool.d.ts.map +1 -0
  46. package/dist/auth/upload-url-pool.js +52 -0
  47. package/dist/auth/upload-url-pool.js.map +1 -0
  48. package/dist/bucket.cjs +789 -0
  49. package/dist/bucket.cjs.map +1 -0
  50. package/dist/bucket.d.cts +659 -0
  51. package/dist/bucket.d.cts.map +1 -0
  52. package/dist/bucket.d.ts +659 -0
  53. package/dist/bucket.d.ts.map +1 -0
  54. package/dist/bucket.js +789 -0
  55. package/dist/bucket.js.map +1 -0
  56. package/dist/client.cjs +230 -0
  57. package/dist/client.cjs.map +1 -0
  58. package/dist/client.d.cts +222 -0
  59. package/dist/client.d.cts.map +1 -0
  60. package/dist/client.d.ts +222 -0
  61. package/dist/client.d.ts.map +1 -0
  62. package/dist/client.js +230 -0
  63. package/dist/client.js.map +1 -0
  64. package/dist/copy/large.cjs +74 -0
  65. package/dist/copy/large.cjs.map +1 -0
  66. package/dist/copy/large.d.cts +53 -0
  67. package/dist/copy/large.d.cts.map +1 -0
  68. package/dist/copy/large.d.ts +53 -0
  69. package/dist/copy/large.d.ts.map +1 -0
  70. package/dist/copy/large.js +74 -0
  71. package/dist/copy/large.js.map +1 -0
  72. package/dist/download/parallel.cjs +122 -0
  73. package/dist/download/parallel.cjs.map +1 -0
  74. package/dist/download/parallel.d.cts +42 -0
  75. package/dist/download/parallel.d.cts.map +1 -0
  76. package/dist/download/parallel.d.ts +42 -0
  77. package/dist/download/parallel.d.ts.map +1 -0
  78. package/dist/download/parallel.js +122 -0
  79. package/dist/download/parallel.js.map +1 -0
  80. package/dist/download/single.cjs +117 -0
  81. package/dist/download/single.cjs.map +1 -0
  82. package/dist/download/single.d.cts +152 -0
  83. package/dist/download/single.d.cts.map +1 -0
  84. package/dist/download/single.d.ts +152 -0
  85. package/dist/download/single.d.ts.map +1 -0
  86. package/dist/download/single.js +117 -0
  87. package/dist/download/single.js.map +1 -0
  88. package/dist/errors/index.cjs +268 -0
  89. package/dist/errors/index.cjs.map +1 -0
  90. package/dist/errors/index.d.cts +264 -0
  91. package/dist/errors/index.d.cts.map +1 -0
  92. package/dist/errors/index.d.ts +264 -0
  93. package/dist/errors/index.d.ts.map +1 -0
  94. package/dist/errors/index.js +268 -0
  95. package/dist/errors/index.js.map +1 -0
  96. package/dist/http/retry.cjs +36 -0
  97. package/dist/http/retry.cjs.map +1 -0
  98. package/dist/http/retry.d.cts +34 -0
  99. package/dist/http/retry.d.cts.map +1 -0
  100. package/dist/http/retry.d.ts +34 -0
  101. package/dist/http/retry.d.ts.map +1 -0
  102. package/dist/http/retry.js +36 -0
  103. package/dist/http/retry.js.map +1 -0
  104. package/dist/http/transport.cjs +143 -0
  105. package/dist/http/transport.cjs.map +1 -0
  106. package/dist/http/transport.d.cts +122 -0
  107. package/dist/http/transport.d.cts.map +1 -0
  108. package/dist/http/transport.d.ts +122 -0
  109. package/dist/http/transport.d.ts.map +1 -0
  110. package/dist/http/transport.js +143 -0
  111. package/dist/http/transport.js.map +1 -0
  112. package/dist/http/url-guard.cjs +97 -0
  113. package/dist/http/url-guard.cjs.map +1 -0
  114. package/dist/http/url-guard.d.cts +88 -0
  115. package/dist/http/url-guard.d.cts.map +1 -0
  116. package/dist/http/url-guard.d.ts +88 -0
  117. package/dist/http/url-guard.d.ts.map +1 -0
  118. package/dist/http/url-guard.js +97 -0
  119. package/dist/http/url-guard.js.map +1 -0
  120. package/dist/http/user-agent.cjs +51 -0
  121. package/dist/http/user-agent.cjs.map +1 -0
  122. package/dist/http/user-agent.d.cts +28 -0
  123. package/dist/http/user-agent.d.cts.map +1 -0
  124. package/dist/http/user-agent.d.ts +28 -0
  125. package/dist/http/user-agent.d.ts.map +1 -0
  126. package/dist/http/user-agent.js +51 -0
  127. package/dist/http/user-agent.js.map +1 -0
  128. package/dist/index.cjs +78 -0
  129. package/dist/index.cjs.map +1 -0
  130. package/dist/index.d.cts +39 -0
  131. package/dist/index.d.cts.map +1 -0
  132. package/dist/index.d.ts +39 -0
  133. package/dist/index.d.ts.map +1 -0
  134. package/dist/index.js +78 -0
  135. package/dist/index.js.map +1 -0
  136. package/dist/notifications/index.cjs +7 -0
  137. package/dist/notifications/index.cjs.map +1 -0
  138. package/dist/notifications/index.d.cts +3 -0
  139. package/dist/notifications/index.d.cts.map +1 -0
  140. package/dist/notifications/index.d.ts +3 -0
  141. package/dist/notifications/index.d.ts.map +1 -0
  142. package/dist/notifications/index.js +7 -0
  143. package/dist/notifications/index.js.map +1 -0
  144. package/dist/notifications/webhook.cjs +106 -0
  145. package/dist/notifications/webhook.cjs.map +1 -0
  146. package/dist/notifications/webhook.d.cts +146 -0
  147. package/dist/notifications/webhook.d.cts.map +1 -0
  148. package/dist/notifications/webhook.d.ts +146 -0
  149. package/dist/notifications/webhook.d.ts.map +1 -0
  150. package/dist/notifications/webhook.js +106 -0
  151. package/dist/notifications/webhook.js.map +1 -0
  152. package/dist/object.cjs +212 -0
  153. package/dist/object.cjs.map +1 -0
  154. package/dist/object.d.cts +263 -0
  155. package/dist/object.d.cts.map +1 -0
  156. package/dist/object.d.ts +263 -0
  157. package/dist/object.d.ts.map +1 -0
  158. package/dist/object.js +212 -0
  159. package/dist/object.js.map +1 -0
  160. package/dist/package.json.cjs +9 -0
  161. package/dist/package.json.cjs.map +1 -0
  162. package/dist/package.json.js +9 -0
  163. package/dist/package.json.js.map +1 -0
  164. package/dist/raw/encoding.cjs +47 -0
  165. package/dist/raw/encoding.cjs.map +1 -0
  166. package/dist/raw/encoding.d.cts +46 -0
  167. package/dist/raw/encoding.d.cts.map +1 -0
  168. package/dist/raw/encoding.d.ts +46 -0
  169. package/dist/raw/encoding.d.ts.map +1 -0
  170. package/dist/raw/encoding.js +47 -0
  171. package/dist/raw/encoding.js.map +1 -0
  172. package/dist/raw/index.cjs +600 -0
  173. package/dist/raw/index.cjs.map +1 -0
  174. package/dist/raw/index.d.cts +381 -0
  175. package/dist/raw/index.d.cts.map +1 -0
  176. package/dist/raw/index.d.ts +381 -0
  177. package/dist/raw/index.d.ts.map +1 -0
  178. package/dist/raw/index.js +601 -0
  179. package/dist/raw/index.js.map +1 -0
  180. package/dist/s3/index.cjs +23 -0
  181. package/dist/s3/index.cjs.map +1 -0
  182. package/dist/s3/index.d.cts +74 -0
  183. package/dist/s3/index.d.cts.map +1 -0
  184. package/dist/s3/index.d.ts +74 -0
  185. package/dist/s3/index.d.ts.map +1 -0
  186. package/dist/s3/index.js +23 -0
  187. package/dist/s3/index.js.map +1 -0
  188. package/dist/simulator/capabilities.cjs +53 -0
  189. package/dist/simulator/capabilities.cjs.map +1 -0
  190. package/dist/simulator/capabilities.d.cts +15 -0
  191. package/dist/simulator/capabilities.d.cts.map +1 -0
  192. package/dist/simulator/capabilities.d.ts +15 -0
  193. package/dist/simulator/capabilities.d.ts.map +1 -0
  194. package/dist/simulator/capabilities.js +53 -0
  195. package/dist/simulator/capabilities.js.map +1 -0
  196. package/dist/simulator/index.cjs +1559 -0
  197. package/dist/simulator/index.cjs.map +1 -0
  198. package/dist/simulator/index.d.cts +495 -0
  199. package/dist/simulator/index.d.cts.map +1 -0
  200. package/dist/simulator/index.d.ts +495 -0
  201. package/dist/simulator/index.d.ts.map +1 -0
  202. package/dist/simulator/index.js +1560 -0
  203. package/dist/simulator/index.js.map +1 -0
  204. package/dist/simulator/validation.cjs +174 -0
  205. package/dist/simulator/validation.cjs.map +1 -0
  206. package/dist/simulator/validation.d.cts +104 -0
  207. package/dist/simulator/validation.d.cts.map +1 -0
  208. package/dist/simulator/validation.d.ts +104 -0
  209. package/dist/simulator/validation.d.ts.map +1 -0
  210. package/dist/simulator/validation.js +174 -0
  211. package/dist/simulator/validation.js.map +1 -0
  212. package/dist/streams/collect.cjs +26 -0
  213. package/dist/streams/collect.cjs.map +1 -0
  214. package/dist/streams/collect.d.cts +18 -0
  215. package/dist/streams/collect.d.cts.map +1 -0
  216. package/dist/streams/collect.d.ts +18 -0
  217. package/dist/streams/collect.d.ts.map +1 -0
  218. package/dist/streams/collect.js +26 -0
  219. package/dist/streams/collect.js.map +1 -0
  220. package/dist/streams/hash.cjs +123 -0
  221. package/dist/streams/hash.cjs.map +1 -0
  222. package/dist/streams/hash.d.cts +42 -0
  223. package/dist/streams/hash.d.cts.map +1 -0
  224. package/dist/streams/hash.d.ts +42 -0
  225. package/dist/streams/hash.d.ts.map +1 -0
  226. package/dist/streams/hash.js +101 -0
  227. package/dist/streams/hash.js.map +1 -0
  228. package/dist/streams/index.cjs +13 -0
  229. package/dist/streams/index.cjs.map +1 -0
  230. package/dist/streams/index.d.cts +7 -0
  231. package/dist/streams/index.d.cts.map +1 -0
  232. package/dist/streams/index.d.ts +7 -0
  233. package/dist/streams/index.d.ts.map +1 -0
  234. package/dist/streams/index.js +13 -0
  235. package/dist/streams/index.js.map +1 -0
  236. package/dist/streams/progress.cjs +47 -0
  237. package/dist/streams/progress.cjs.map +1 -0
  238. package/dist/streams/progress.d.cts +53 -0
  239. package/dist/streams/progress.d.cts.map +1 -0
  240. package/dist/streams/progress.d.ts +53 -0
  241. package/dist/streams/progress.d.ts.map +1 -0
  242. package/dist/streams/progress.js +47 -0
  243. package/dist/streams/progress.js.map +1 -0
  244. package/dist/streams/source.cjs +155 -0
  245. package/dist/streams/source.cjs.map +1 -0
  246. package/dist/streams/source.d.cts +140 -0
  247. package/dist/streams/source.d.cts.map +1 -0
  248. package/dist/streams/source.d.ts +140 -0
  249. package/dist/streams/source.d.ts.map +1 -0
  250. package/dist/streams/source.js +155 -0
  251. package/dist/streams/source.js.map +1 -0
  252. package/dist/sync/actions/index.cjs +191 -0
  253. package/dist/sync/actions/index.cjs.map +1 -0
  254. package/dist/sync/actions/index.d.cts +167 -0
  255. package/dist/sync/actions/index.d.cts.map +1 -0
  256. package/dist/sync/actions/index.d.ts +167 -0
  257. package/dist/sync/actions/index.d.ts.map +1 -0
  258. package/dist/sync/actions/index.js +191 -0
  259. package/dist/sync/actions/index.js.map +1 -0
  260. package/dist/sync/index.cjs +23 -0
  261. package/dist/sync/index.cjs.map +1 -0
  262. package/dist/sync/index.d.cts +21 -0
  263. package/dist/sync/index.d.cts.map +1 -0
  264. package/dist/sync/index.d.ts +21 -0
  265. package/dist/sync/index.d.ts.map +1 -0
  266. package/dist/sync/index.js +23 -0
  267. package/dist/sync/index.js.map +1 -0
  268. package/dist/sync/pairing.cjs +31 -0
  269. package/dist/sync/pairing.cjs.map +1 -0
  270. package/dist/sync/pairing.d.cts +13 -0
  271. package/dist/sync/pairing.d.cts.map +1 -0
  272. package/dist/sync/pairing.d.ts +13 -0
  273. package/dist/sync/pairing.d.ts.map +1 -0
  274. package/dist/sync/pairing.js +31 -0
  275. package/dist/sync/pairing.js.map +1 -0
  276. package/dist/sync/policies/compare.cjs +14 -0
  277. package/dist/sync/policies/compare.cjs.map +1 -0
  278. package/dist/sync/policies/compare.d.cts +13 -0
  279. package/dist/sync/policies/compare.d.cts.map +1 -0
  280. package/dist/sync/policies/compare.d.ts +13 -0
  281. package/dist/sync/policies/compare.d.ts.map +1 -0
  282. package/dist/sync/policies/compare.js +14 -0
  283. package/dist/sync/policies/compare.js.map +1 -0
  284. package/dist/sync/policies/index.cjs +74 -0
  285. package/dist/sync/policies/index.cjs.map +1 -0
  286. package/dist/sync/policies/index.d.cts +42 -0
  287. package/dist/sync/policies/index.d.cts.map +1 -0
  288. package/dist/sync/policies/index.d.ts +42 -0
  289. package/dist/sync/policies/index.d.ts.map +1 -0
  290. package/dist/sync/policies/index.js +74 -0
  291. package/dist/sync/policies/index.js.map +1 -0
  292. package/dist/sync/scanners/b2.cjs +57 -0
  293. package/dist/sync/scanners/b2.cjs.map +1 -0
  294. package/dist/sync/scanners/b2.d.cts +20 -0
  295. package/dist/sync/scanners/b2.d.cts.map +1 -0
  296. package/dist/sync/scanners/b2.d.ts +20 -0
  297. package/dist/sync/scanners/b2.d.ts.map +1 -0
  298. package/dist/sync/scanners/b2.js +57 -0
  299. package/dist/sync/scanners/b2.js.map +1 -0
  300. package/dist/sync/scanners/local.cjs +58 -0
  301. package/dist/sync/scanners/local.cjs.map +1 -0
  302. package/dist/sync/scanners/local.d.cts +24 -0
  303. package/dist/sync/scanners/local.d.cts.map +1 -0
  304. package/dist/sync/scanners/local.d.ts +24 -0
  305. package/dist/sync/scanners/local.d.ts.map +1 -0
  306. package/dist/sync/scanners/local.js +58 -0
  307. package/dist/sync/scanners/local.js.map +1 -0
  308. package/dist/sync/synchronizer.cjs +203 -0
  309. package/dist/sync/synchronizer.cjs.map +1 -0
  310. package/dist/sync/synchronizer.d.cts +52 -0
  311. package/dist/sync/synchronizer.d.cts.map +1 -0
  312. package/dist/sync/synchronizer.d.ts +52 -0
  313. package/dist/sync/synchronizer.d.ts.map +1 -0
  314. package/dist/sync/synchronizer.js +181 -0
  315. package/dist/sync/synchronizer.js.map +1 -0
  316. package/dist/sync/types.d.cts +121 -0
  317. package/dist/sync/types.d.cts.map +1 -0
  318. package/dist/sync/types.d.ts +121 -0
  319. package/dist/sync/types.d.ts.map +1 -0
  320. package/dist/types/auth.cjs +58 -0
  321. package/dist/types/auth.cjs.map +1 -0
  322. package/dist/types/auth.d.cts +150 -0
  323. package/dist/types/auth.d.cts.map +1 -0
  324. package/dist/types/auth.d.ts +150 -0
  325. package/dist/types/auth.d.ts.map +1 -0
  326. package/dist/types/auth.js +58 -0
  327. package/dist/types/auth.js.map +1 -0
  328. package/dist/types/bucket.cjs +44 -0
  329. package/dist/types/bucket.cjs.map +1 -0
  330. package/dist/types/bucket.d.cts +245 -0
  331. package/dist/types/bucket.d.cts.map +1 -0
  332. package/dist/types/bucket.d.ts +245 -0
  333. package/dist/types/bucket.d.ts.map +1 -0
  334. package/dist/types/bucket.js +44 -0
  335. package/dist/types/bucket.js.map +1 -0
  336. package/dist/types/download.d.cts +110 -0
  337. package/dist/types/download.d.cts.map +1 -0
  338. package/dist/types/download.d.ts +110 -0
  339. package/dist/types/download.d.ts.map +1 -0
  340. package/dist/types/encryption.cjs +343 -0
  341. package/dist/types/encryption.cjs.map +1 -0
  342. package/dist/types/encryption.d.cts +132 -0
  343. package/dist/types/encryption.d.cts.map +1 -0
  344. package/dist/types/encryption.d.ts +132 -0
  345. package/dist/types/encryption.d.ts.map +1 -0
  346. package/dist/types/encryption.js +321 -0
  347. package/dist/types/encryption.js.map +1 -0
  348. package/dist/types/errors.d.cts +16 -0
  349. package/dist/types/errors.d.cts.map +1 -0
  350. package/dist/types/errors.d.ts +16 -0
  351. package/dist/types/errors.d.ts.map +1 -0
  352. package/dist/types/file.cjs +23 -0
  353. package/dist/types/file.cjs.map +1 -0
  354. package/dist/types/file.d.cts +220 -0
  355. package/dist/types/file.d.cts.map +1 -0
  356. package/dist/types/file.d.ts +220 -0
  357. package/dist/types/file.d.ts.map +1 -0
  358. package/dist/types/file.js +23 -0
  359. package/dist/types/file.js.map +1 -0
  360. package/dist/types/ids.cjs +27 -0
  361. package/dist/types/ids.cjs.map +1 -0
  362. package/dist/types/ids.d.cts +84 -0
  363. package/dist/types/ids.d.cts.map +1 -0
  364. package/dist/types/ids.d.ts +84 -0
  365. package/dist/types/ids.d.ts.map +1 -0
  366. package/dist/types/ids.js +27 -0
  367. package/dist/types/ids.js.map +1 -0
  368. package/dist/types/index.d.cts +25 -0
  369. package/dist/types/index.d.cts.map +1 -0
  370. package/dist/types/index.d.ts +25 -0
  371. package/dist/types/index.d.ts.map +1 -0
  372. package/dist/types/key.d.cts +84 -0
  373. package/dist/types/key.d.cts.map +1 -0
  374. package/dist/types/key.d.ts +84 -0
  375. package/dist/types/key.d.ts.map +1 -0
  376. package/dist/types/lock.cjs +17 -0
  377. package/dist/types/lock.cjs.map +1 -0
  378. package/dist/types/lock.d.cts +92 -0
  379. package/dist/types/lock.d.cts.map +1 -0
  380. package/dist/types/lock.d.ts +92 -0
  381. package/dist/types/lock.d.ts.map +1 -0
  382. package/dist/types/lock.js +17 -0
  383. package/dist/types/lock.js.map +1 -0
  384. package/dist/types/notifications.cjs +24 -0
  385. package/dist/types/notifications.cjs.map +1 -0
  386. package/dist/types/notifications.d.cts +97 -0
  387. package/dist/types/notifications.d.cts.map +1 -0
  388. package/dist/types/notifications.d.ts +97 -0
  389. package/dist/types/notifications.d.ts.map +1 -0
  390. package/dist/types/notifications.js +24 -0
  391. package/dist/types/notifications.js.map +1 -0
  392. package/dist/types/replication.d.cts +42 -0
  393. package/dist/types/replication.d.cts.map +1 -0
  394. package/dist/types/replication.d.ts +42 -0
  395. package/dist/types/replication.d.ts.map +1 -0
  396. package/dist/types/upload.d.cts +219 -0
  397. package/dist/types/upload.d.cts.map +1 -0
  398. package/dist/types/upload.d.ts +219 -0
  399. package/dist/types/upload.d.ts.map +1 -0
  400. package/dist/upload/cancel.cjs +10 -0
  401. package/dist/upload/cancel.cjs.map +1 -0
  402. package/dist/upload/cancel.d.cts +23 -0
  403. package/dist/upload/cancel.d.cts.map +1 -0
  404. package/dist/upload/cancel.d.ts +23 -0
  405. package/dist/upload/cancel.d.ts.map +1 -0
  406. package/dist/upload/cancel.js +10 -0
  407. package/dist/upload/cancel.js.map +1 -0
  408. package/dist/upload/concurrency.cjs +54 -0
  409. package/dist/upload/concurrency.cjs.map +1 -0
  410. package/dist/upload/concurrency.d.cts +46 -0
  411. package/dist/upload/concurrency.d.cts.map +1 -0
  412. package/dist/upload/concurrency.d.ts +46 -0
  413. package/dist/upload/concurrency.d.ts.map +1 -0
  414. package/dist/upload/concurrency.js +54 -0
  415. package/dist/upload/concurrency.js.map +1 -0
  416. package/dist/upload/large.cjs +222 -0
  417. package/dist/upload/large.cjs.map +1 -0
  418. package/dist/upload/large.d.cts +71 -0
  419. package/dist/upload/large.d.cts.map +1 -0
  420. package/dist/upload/large.d.ts +71 -0
  421. package/dist/upload/large.d.ts.map +1 -0
  422. package/dist/upload/large.js +222 -0
  423. package/dist/upload/large.js.map +1 -0
  424. package/dist/upload/resume.cjs +34 -0
  425. package/dist/upload/resume.cjs.map +1 -0
  426. package/dist/upload/resume.d.cts +33 -0
  427. package/dist/upload/resume.d.cts.map +1 -0
  428. package/dist/upload/resume.d.ts +33 -0
  429. package/dist/upload/resume.d.ts.map +1 -0
  430. package/dist/upload/resume.js +34 -0
  431. package/dist/upload/resume.js.map +1 -0
  432. package/dist/upload/single.cjs +47 -0
  433. package/dist/upload/single.cjs.map +1 -0
  434. package/dist/upload/single.d.cts +51 -0
  435. package/dist/upload/single.d.cts.map +1 -0
  436. package/dist/upload/single.d.ts +51 -0
  437. package/dist/upload/single.d.ts.map +1 -0
  438. package/dist/upload/single.js +47 -0
  439. package/dist/upload/single.js.map +1 -0
  440. package/dist/upload/stream.cjs +198 -0
  441. package/dist/upload/stream.cjs.map +1 -0
  442. package/dist/upload/stream.d.cts +61 -0
  443. package/dist/upload/stream.d.cts.map +1 -0
  444. package/dist/upload/stream.d.ts +61 -0
  445. package/dist/upload/stream.d.ts.map +1 -0
  446. package/dist/upload/stream.js +198 -0
  447. package/dist/upload/stream.js.map +1 -0
  448. package/dist/util/best-effort.cjs +10 -0
  449. package/dist/util/best-effort.cjs.map +1 -0
  450. package/dist/util/best-effort.d.cts +31 -0
  451. package/dist/util/best-effort.d.cts.map +1 -0
  452. package/dist/util/best-effort.d.ts +31 -0
  453. package/dist/util/best-effort.d.ts.map +1 -0
  454. package/dist/util/best-effort.js +10 -0
  455. package/dist/util/best-effort.js.map +1 -0
  456. package/dist/util/defaults.cjs +11 -0
  457. package/dist/util/defaults.cjs.map +1 -0
  458. package/dist/util/defaults.d.cts +54 -0
  459. package/dist/util/defaults.d.cts.map +1 -0
  460. package/dist/util/defaults.d.ts +54 -0
  461. package/dist/util/defaults.d.ts.map +1 -0
  462. package/dist/util/defaults.js +11 -0
  463. package/dist/util/defaults.js.map +1 -0
  464. package/dist/util/normalize.cjs +16 -0
  465. package/dist/util/normalize.cjs.map +1 -0
  466. package/dist/util/normalize.d.cts +62 -0
  467. package/dist/util/normalize.d.cts.map +1 -0
  468. package/dist/util/normalize.d.ts +62 -0
  469. package/dist/util/normalize.d.ts.map +1 -0
  470. package/dist/util/normalize.js +16 -0
  471. package/dist/util/normalize.js.map +1 -0
  472. package/dist/util/paginator.cjs +20 -0
  473. package/dist/util/paginator.cjs.map +1 -0
  474. package/dist/util/paginator.d.cts +120 -0
  475. package/dist/util/paginator.d.cts.map +1 -0
  476. package/dist/util/paginator.d.ts +120 -0
  477. package/dist/util/paginator.d.ts.map +1 -0
  478. package/dist/util/paginator.js +20 -0
  479. package/dist/util/paginator.js.map +1 -0
  480. package/dist/util/plan-ranges.cjs +28 -0
  481. package/dist/util/plan-ranges.cjs.map +1 -0
  482. package/dist/util/plan-ranges.d.cts +56 -0
  483. package/dist/util/plan-ranges.d.cts.map +1 -0
  484. package/dist/util/plan-ranges.d.ts +56 -0
  485. package/dist/util/plan-ranges.d.ts.map +1 -0
  486. package/dist/util/plan-ranges.js +28 -0
  487. package/dist/util/plan-ranges.js.map +1 -0
  488. package/dist/util/text-codec.cjs +7 -0
  489. package/dist/util/text-codec.cjs.map +1 -0
  490. package/dist/util/text-codec.d.cts +26 -0
  491. package/dist/util/text-codec.d.cts.map +1 -0
  492. package/dist/util/text-codec.d.ts +26 -0
  493. package/dist/util/text-codec.d.ts.map +1 -0
  494. package/dist/util/text-codec.js +7 -0
  495. package/dist/util/text-codec.js.map +1 -0
  496. package/dist/util/to-error.cjs +7 -0
  497. package/dist/util/to-error.cjs.map +1 -0
  498. package/dist/util/to-error.d.cts +15 -0
  499. package/dist/util/to-error.d.cts.map +1 -0
  500. package/dist/util/to-error.d.ts +15 -0
  501. package/dist/util/to-error.d.ts.map +1 -0
  502. package/dist/util/to-error.js +7 -0
  503. package/dist/util/to-error.js.map +1 -0
  504. package/dist/version.cjs +6 -0
  505. package/dist/version.cjs.map +1 -0
  506. package/dist/version.d.cts +14 -0
  507. package/dist/version.d.cts.map +1 -0
  508. package/dist/version.d.ts +14 -0
  509. package/dist/version.d.ts.map +1 -0
  510. package/dist/version.js +6 -0
  511. package/dist/version.js.map +1 -0
  512. package/package.json +198 -0
@@ -0,0 +1,789 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const large$1 = require("./copy/large.cjs");
4
+ const single$1 = require("./download/single.cjs");
5
+ const object = require("./object.cjs");
6
+ const ids = require("./types/ids.cjs");
7
+ const concurrency = require("./upload/concurrency.cjs");
8
+ const large = require("./upload/large.cjs");
9
+ const single = require("./upload/single.cjs");
10
+ const defaults = require("./util/defaults.cjs");
11
+ const paginator = require("./util/paginator.cjs");
12
+ const toError = require("./util/to-error.cjs");
13
+ class Bucket {
14
+ /** Unique identifier for this bucket. */
15
+ id;
16
+ /** Human-readable bucket name. */
17
+ name;
18
+ /** Full bucket metadata as returned by the B2 API. */
19
+ info;
20
+ client;
21
+ /**
22
+ * @param client - The parent B2Client instance.
23
+ * @param info - The bucket metadata from the API.
24
+ *
25
+ * @internal
26
+ */
27
+ constructor(client, info) {
28
+ this.client = client;
29
+ this.info = info;
30
+ this.id = info.bucketId;
31
+ this.name = info.bucketName;
32
+ }
33
+ /**
34
+ * Returns a {@link B2Object} handle for a specific file name in this bucket.
35
+ * @param fileName - The file path within the bucket.
36
+ *
37
+ * @returns A B2Object handle bound to this bucket and file name.
38
+ */
39
+ file(fileName) {
40
+ return new object.B2Object(this.client, this, fileName);
41
+ }
42
+ /**
43
+ * Uploads a file to this bucket. Automatically uses multipart upload for files
44
+ * larger than the recommended part size.
45
+ * @param options - Upload configuration including file name, source data, and optional settings.
46
+ *
47
+ * @returns Metadata for the uploaded file version.
48
+ */
49
+ async upload(options) {
50
+ const recommendedPartSize = this.client.accountInfo.getRecommendedPartSize();
51
+ const isLarge = options.source.size > recommendedPartSize;
52
+ if (isLarge) {
53
+ return large.uploadLargeFile(this.client.raw, this.client.accountInfo, {
54
+ bucketId: this.id,
55
+ ...options
56
+ });
57
+ }
58
+ const { resume: _resume, resumeFileId: _resumeFileId, ...smallOptions } = options;
59
+ return single.uploadSmallFile(this.client.raw, this.client.accountInfo, {
60
+ bucketId: this.id,
61
+ ...smallOptions
62
+ });
63
+ }
64
+ /**
65
+ * Downloads a file from this bucket by name. Pass `method: 'HEAD'` in
66
+ * `options` to fetch only the response headers (file metadata) without
67
+ * streaming the body.
68
+ * @param fileName - The file name (path) to download.
69
+ * @param options - Optional method, range, SSE-C decryption, response-header overrides, and abort signal.
70
+ *
71
+ * @returns The download result containing response headers and a readable body stream.
72
+ */
73
+ async download(fileName, options) {
74
+ return single$1.downloadByName(this.client.raw, this.client.accountInfo, {
75
+ bucketName: this.name,
76
+ fileName,
77
+ ...options
78
+ });
79
+ }
80
+ /**
81
+ * Fetches the response headers (file metadata) for a file via HTTP
82
+ * HEAD. Returns a body-less result so callers never have to drain
83
+ * the (logically empty) HEAD body themselves.
84
+ *
85
+ * Use this for metadata-only checks like "does this file exist", "what
86
+ * is its current SHA-1", "what is its Content-Length". For full file
87
+ * retrieval use {@link Bucket.download}.
88
+ *
89
+ * @param fileName - The file name (path) to inspect.
90
+ * @param options - Optional range, SSE-C decryption, response-header
91
+ * overrides, and abort signal. Same shape as {@link Bucket.download}'s
92
+ * options minus `method` (always HEAD) and `onProgress` (no body).
93
+ *
94
+ * @returns Parsed download headers (content type, SHA-1, file info, etc.).
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const { headers } = await bucket.head('photos/2026/sunset.jpg')
99
+ * console.log(headers.contentLength, headers.contentSha1)
100
+ * ```
101
+ */
102
+ async head(fileName, options) {
103
+ return single$1.headByName(this.client.raw, this.client.accountInfo, {
104
+ bucketName: this.name,
105
+ fileName,
106
+ ...options
107
+ });
108
+ }
109
+ /**
110
+ * Lists file names in this bucket (most recent versions only).
111
+ * @param options - Optional filtering and pagination settings.
112
+ *
113
+ * @returns A page of file versions with an optional continuation token.
114
+ */
115
+ async listFileNames(options) {
116
+ return this.client.raw.listFileNames(
117
+ this.client.accountInfo.getApiUrl(),
118
+ this.client.accountInfo.getAuthToken(),
119
+ {
120
+ bucketId: this.id,
121
+ ...options?.startFileName !== void 0 ? { startFileName: options.startFileName } : {},
122
+ ...options?.pageSize !== void 0 ? { maxFileCount: options.pageSize } : {},
123
+ ...options?.prefix !== void 0 ? { prefix: options.prefix } : {},
124
+ ...options?.delimiter !== void 0 ? { delimiter: options.delimiter } : {}
125
+ }
126
+ );
127
+ }
128
+ /**
129
+ * Lists all file versions in this bucket, including hidden files.
130
+ * @param options - Optional filtering and pagination settings.
131
+ *
132
+ * @returns A page of file versions with an optional continuation token.
133
+ */
134
+ async listFileVersions(options) {
135
+ return this.client.raw.listFileVersions(
136
+ this.client.accountInfo.getApiUrl(),
137
+ this.client.accountInfo.getAuthToken(),
138
+ {
139
+ bucketId: this.id,
140
+ ...options?.startFileName !== void 0 ? { startFileName: options.startFileName } : {},
141
+ ...options?.startFileId !== void 0 ? { startFileId: options.startFileId } : {},
142
+ ...options?.pageSize !== void 0 ? { maxFileCount: options.pageSize } : {},
143
+ ...options?.prefix !== void 0 ? { prefix: options.prefix } : {},
144
+ ...options?.delimiter !== void 0 ? { delimiter: options.delimiter } : {}
145
+ }
146
+ );
147
+ }
148
+ /**
149
+ * Async iterator that yields the latest visible version of every file in
150
+ * the bucket, automatically handling pagination via `listFileNames`.
151
+ *
152
+ * Hidden files (those whose latest version is a hide marker) are NOT
153
+ * yielded by this iterator. Use {@link paginateFileVersions} when you
154
+ * need full version history.
155
+ *
156
+ * @param options - Filter + pagination + abort options. `pageSize` is
157
+ * forwarded to `b2_list_file_names`'s `maxFileCount` (default 1000,
158
+ * B2-capped at 10000).
159
+ *
160
+ * @returns An async iterable of {@link FileVersion} entries.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * for await (const file of bucket.paginateFileNames({ prefix: 'photos/' })) {
165
+ * console.log(file.fileName, file.contentLength)
166
+ * }
167
+ * ```
168
+ */
169
+ paginateFileNames(options) {
170
+ return paginator.paginateItems(
171
+ async (cursor) => {
172
+ const resp = await this.listFileNames({
173
+ pageSize: options?.pageSize ?? defaults.DEFAULT_PAGE_SIZE,
174
+ ...cursor !== void 0 ? { startFileName: cursor } : {},
175
+ ...options?.prefix !== void 0 ? { prefix: options.prefix } : {},
176
+ ...options?.delimiter !== void 0 ? { delimiter: options.delimiter } : {}
177
+ });
178
+ return { page: resp, nextCursor: resp.nextFileName ?? void 0 };
179
+ },
180
+ // Real B2 surfaces hide markers as rows in `b2_list_file_names`. This
181
+ // iterator's documented contract is "latest VISIBLE version", so we
182
+ // drop hide-action rows here. Callers who need full history should
183
+ // use `paginateFileVersions`.
184
+ (page) => page.files.filter((f) => f.action !== "hide"),
185
+ options?.signal
186
+ );
187
+ }
188
+ /**
189
+ * Async iterator that yields every version of every file in the bucket,
190
+ * including hidden files and historical versions, automatically handling
191
+ * pagination via `listFileVersions`.
192
+ *
193
+ * The two-cursor `(nextFileName, nextFileId)` continuation that the raw
194
+ * endpoint exposes is threaded internally; callers iterate flat.
195
+ *
196
+ * @param options - Filter + pagination + abort options.
197
+ *
198
+ * @returns An async iterable of {@link FileVersion} entries.
199
+ */
200
+ paginateFileVersions(options) {
201
+ return paginator.paginateItems(
202
+ async (cursor) => {
203
+ const resp = await this.listFileVersions({
204
+ pageSize: options?.pageSize ?? defaults.DEFAULT_PAGE_SIZE,
205
+ ...cursor !== void 0 ? { startFileName: cursor.fileName } : {},
206
+ ...cursor?.fileId !== void 0 ? { startFileId: cursor.fileId } : {},
207
+ ...options?.prefix !== void 0 ? { prefix: options.prefix } : {},
208
+ ...options?.delimiter !== void 0 ? { delimiter: options.delimiter } : {}
209
+ });
210
+ const nextCursor = resp.nextFileName !== null ? { fileName: resp.nextFileName, fileId: resp.nextFileId ?? void 0 } : void 0;
211
+ return { page: resp, nextCursor };
212
+ },
213
+ (page) => page.files,
214
+ options?.signal
215
+ );
216
+ }
217
+ /**
218
+ * Async iterator that yields every unfinished large file in the bucket,
219
+ * automatically handling pagination via `listUnfinishedLargeFiles`.
220
+ *
221
+ * Useful for janitorial scripts that want to inspect or cancel abandoned
222
+ * multipart uploads (typically followed by {@link cancelLargeFile} on
223
+ * the underlying raw client).
224
+ *
225
+ * @param options - Filter + pagination + abort options. `pageSize` is
226
+ * B2-capped at 100 for this endpoint.
227
+ *
228
+ * @returns An async iterable of unfinished-large-file metadata entries.
229
+ */
230
+ paginateUnfinishedLargeFiles(options) {
231
+ return paginator.paginateItems(
232
+ async (cursor) => {
233
+ const resp = await this.listUnfinishedLargeFiles({
234
+ pageSize: options?.pageSize ?? 100,
235
+ ...cursor !== void 0 ? { startFileId: cursor } : {},
236
+ ...options?.namePrefix !== void 0 ? { namePrefix: options.namePrefix } : {}
237
+ });
238
+ return { page: resp, nextCursor: resp.nextFileId ?? void 0 };
239
+ },
240
+ (page) => page.files,
241
+ options?.signal
242
+ );
243
+ }
244
+ /**
245
+ * Async iterator that yields every uploaded part for a specific large
246
+ * file, automatically handling pagination via `listParts`.
247
+ *
248
+ * @param largeFileId - The unfinished large file to enumerate parts of.
249
+ * @param options - Pagination + abort options. `pageSize` is B2-capped
250
+ * at 1000 for this endpoint; the default is 1000.
251
+ *
252
+ * @returns An async iterable of {@link PartInfo} entries.
253
+ */
254
+ paginateParts(largeFileId, options) {
255
+ return paginator.paginateItems(
256
+ async (cursor) => {
257
+ const resp = await this.client.raw.listParts(
258
+ this.client.accountInfo.getApiUrl(),
259
+ this.client.accountInfo.getAuthToken(),
260
+ {
261
+ fileId: largeFileId,
262
+ maxPartCount: options?.pageSize ?? defaults.DEFAULT_PAGE_SIZE,
263
+ ...cursor !== void 0 ? { startPartNumber: cursor } : {}
264
+ }
265
+ );
266
+ return { page: resp, nextCursor: resp.nextPartNumber ?? void 0 };
267
+ },
268
+ (page) => page.parts,
269
+ options?.signal
270
+ );
271
+ }
272
+ /**
273
+ * Looks up the latest visible version of a file by name.
274
+ * Uses `listFileNames` under the hood; returns `null` when the file does not
275
+ * exist or its latest version is a hide marker.
276
+ * @param fileName - The exact file path to look up.
277
+ *
278
+ * @returns The latest {@link FileVersion}, or `null` if not found.
279
+ */
280
+ async getFileInfoByName(fileName) {
281
+ const resp = await this.listFileNames({ prefix: fileName, pageSize: 1 });
282
+ const match = resp.files.find((f) => f.fileName === fileName);
283
+ if (!match || match.action === "hide") return null;
284
+ return match;
285
+ }
286
+ /**
287
+ * Removes the latest hide marker for a file, restoring visibility of the
288
+ * previous upload. Returns the deleted hide marker, or `null` if there was
289
+ * no hide marker to remove (file is already visible or does not exist).
290
+ * @param fileName - The file path to unhide.
291
+ *
292
+ * @returns The deleted hide marker version, or `null` if nothing was hidden.
293
+ */
294
+ async unhideFile(fileName) {
295
+ const resp = await this.listFileVersions({ prefix: fileName, pageSize: 100 });
296
+ const versions = resp.files.filter((f) => f.fileName === fileName);
297
+ if (versions.length === 0) return null;
298
+ const latest = versions[0];
299
+ if (!latest || latest.action !== "hide") return null;
300
+ await this.deleteFileVersion(fileName, latest.fileId);
301
+ return latest;
302
+ }
303
+ /**
304
+ * Hides a file by creating a hide marker. The file remains in version history but is no longer visible in `listFileNames`.
305
+ * @param fileName - The file path to hide.
306
+ *
307
+ * @returns Metadata for the newly created hide marker.
308
+ */
309
+ async hideFile(fileName) {
310
+ return this.client.raw.hideFile(
311
+ this.client.accountInfo.getApiUrl(),
312
+ this.client.accountInfo.getAuthToken(),
313
+ { bucketId: this.id, fileName }
314
+ );
315
+ }
316
+ /**
317
+ * Permanently deletes a specific file version. Both file name and file ID are required.
318
+ *
319
+ * If the file is under Object Lock retention, B2 will reject the
320
+ * delete: compliance-mode files cannot be deleted until the retention
321
+ * expires; governance-mode files require `bypassGovernance: true`
322
+ * AND a calling key with the `bypassGovernance` capability. Files on
323
+ * legal hold cannot be deleted by anyone until the hold is removed.
324
+ *
325
+ * @param fileName - The file path of the version to delete.
326
+ * @param fileId - The unique identifier of the file version to delete.
327
+ * @param options - Optional flag for bypassing governance retention.
328
+ */
329
+ async deleteFileVersion(fileName, fileId, options) {
330
+ await this.client.raw.deleteFileVersion(
331
+ this.client.accountInfo.getApiUrl(),
332
+ this.client.accountInfo.getAuthToken(),
333
+ {
334
+ fileName,
335
+ fileId,
336
+ ...options?.bypassGovernance !== void 0 ? { bypassGovernance: options.bypassGovernance } : {}
337
+ }
338
+ );
339
+ }
340
+ /**
341
+ * Cancels an in-progress large file upload so the partial parts are not
342
+ * retained or billed. The most common reason to call this is to clean up
343
+ * abandoned multipart uploads surfaced by {@link listUnfinishedLargeFiles}.
344
+ * @param fileId - The unique identifier of the unfinished large file to cancel.
345
+ *
346
+ * @returns Metadata about the cancelled large file.
347
+ */
348
+ async cancelLargeFile(fileId) {
349
+ return this.client.raw.cancelLargeFile(
350
+ this.client.accountInfo.getApiUrl(),
351
+ this.client.accountInfo.getAuthToken(),
352
+ { fileId }
353
+ );
354
+ }
355
+ /**
356
+ * Lists large files in this bucket that were started but never finished or
357
+ * cancelled. Wraps `b2_list_unfinished_large_files`.
358
+ * @param options - Optional pagination filters.
359
+ *
360
+ * @returns The page of unfinished large files plus a continuation token.
361
+ */
362
+ async listUnfinishedLargeFiles(options) {
363
+ return this.client.raw.listUnfinishedLargeFiles(
364
+ this.client.accountInfo.getApiUrl(),
365
+ this.client.accountInfo.getAuthToken(),
366
+ {
367
+ bucketId: this.id,
368
+ ...options?.namePrefix !== void 0 ? { namePrefix: options.namePrefix } : {},
369
+ ...options?.startFileId !== void 0 ? { startFileId: options.startFileId } : {},
370
+ ...options?.pageSize !== void 0 ? { maxFileCount: options.pageSize } : {}
371
+ }
372
+ );
373
+ }
374
+ /**
375
+ * Deletes many file versions with bounded concurrency. Errors from individual
376
+ * deletes are collected and returned rather than thrown, so partial success
377
+ * does not abort the run.
378
+ *
379
+ * When `options.signal` is supplied and aborted, in-flight deletes
380
+ * complete (they're already on the wire), but no new deletes start
381
+ * after the abort fires. Subsequent targets are short-circuited to an
382
+ * error entry so the result tally reflects what actually happened.
383
+ * @param targets - File versions to delete.
384
+ * @param options - Optional concurrency override and abort signal.
385
+ * Concurrency defaults to the SDK-wide bulk-metadata setting
386
+ * (currently 10, higher than transfer concurrency because each
387
+ * task is a single tiny API round-trip).
388
+ *
389
+ * @returns A summary of successes and per-target errors.
390
+ */
391
+ async deleteMany(targets, options) {
392
+ const concurrency$1 = options?.concurrency ?? defaults.DEFAULT_BULK_CONCURRENCY;
393
+ const sem = new concurrency.Semaphore(concurrency$1);
394
+ const signal = options?.signal;
395
+ let deleted = 0;
396
+ const errors = [];
397
+ await Promise.all(
398
+ targets.map(async (target) => {
399
+ await sem.acquire();
400
+ try {
401
+ if (signal?.aborted) {
402
+ errors.push({
403
+ target,
404
+ error: toError.toError(signal.reason ?? "aborted")
405
+ });
406
+ return;
407
+ }
408
+ await this.deleteFileVersion(target.fileName, target.fileId);
409
+ deleted++;
410
+ } catch (err) {
411
+ errors.push({
412
+ target,
413
+ error: toError.toError(err)
414
+ });
415
+ } finally {
416
+ sem.release();
417
+ }
418
+ })
419
+ );
420
+ return { deleted, errors };
421
+ }
422
+ /**
423
+ * Async generator that streams every file version in the bucket (optionally
424
+ * filtered by prefix) and deletes each one. Yields a {@link DeleteAllEvent}
425
+ * per file version. With `dryRun: true`, no deletes are performed but `skip`
426
+ * events are still emitted.
427
+ * @param options - Optional prefix filter, page size, and dry-run flag.
428
+ *
429
+ * @returns An async generator of per-file events.
430
+ */
431
+ async *deleteAll(options) {
432
+ const dryRun = options?.dryRun ?? false;
433
+ const pageSize = options?.pageSize ?? defaults.DEFAULT_PAGE_SIZE;
434
+ let startFileName;
435
+ let startFileId;
436
+ while (true) {
437
+ const page = await this.listFileVersions({
438
+ pageSize,
439
+ ...options?.prefix !== void 0 ? { prefix: options.prefix } : {},
440
+ ...startFileName !== void 0 ? { startFileName } : {},
441
+ ...startFileId !== void 0 ? { startFileId } : {}
442
+ });
443
+ for (const version of page.files) {
444
+ if (dryRun) {
445
+ yield { type: "skip", fileName: version.fileName, fileId: version.fileId };
446
+ continue;
447
+ }
448
+ try {
449
+ await this.deleteFileVersion(version.fileName, version.fileId);
450
+ yield { type: "delete", fileName: version.fileName, fileId: version.fileId };
451
+ } catch (err) {
452
+ yield {
453
+ type: "error",
454
+ fileName: version.fileName,
455
+ fileId: version.fileId,
456
+ message: toError.toError(err).message
457
+ };
458
+ }
459
+ }
460
+ if (!page.nextFileName) break;
461
+ startFileName = page.nextFileName;
462
+ startFileId = page.nextFileId ?? void 0;
463
+ }
464
+ }
465
+ /**
466
+ * Creates a server-side copy of a file within or across buckets.
467
+ * @param options - Copy configuration including source file ID and destination name.
468
+ *
469
+ * @returns Metadata for the newly created file version.
470
+ */
471
+ async copyFile(options) {
472
+ return this.client.raw.copyFile(
473
+ this.client.accountInfo.getApiUrl(),
474
+ this.client.accountInfo.getAuthToken(),
475
+ options
476
+ );
477
+ }
478
+ /**
479
+ * Copies a file via the server-side multipart protocol. Each part is copied
480
+ * by reference through `b2_copy_part`; data never traverses the client. Falls
481
+ * back to a single `copyFile` call when the source fits within a single part.
482
+ * @param options - Copy parameters including source file ID, destination name, part size, and concurrency.
483
+ *
484
+ * @returns Metadata for the newly created destination file version.
485
+ */
486
+ async copyLargeFile(options) {
487
+ return large$1.copyLargeFile(this.client.raw, this.client.accountInfo, {
488
+ sourceFileId: options.sourceFileId,
489
+ fileName: options.fileName,
490
+ ...options.destinationBucketId !== void 0 ? { destinationBucketId: options.destinationBucketId } : { destinationBucketId: this.id },
491
+ ...options.contentType !== void 0 ? { contentType: options.contentType } : {},
492
+ ...options.fileInfo !== void 0 ? { fileInfo: options.fileInfo } : {},
493
+ ...options.destinationServerSideEncryption !== void 0 ? { destinationServerSideEncryption: options.destinationServerSideEncryption } : {},
494
+ ...options.sourceServerSideEncryption !== void 0 ? { sourceServerSideEncryption: options.sourceServerSideEncryption } : {},
495
+ ...options.partSize !== void 0 ? { partSize: options.partSize } : {},
496
+ ...options.concurrency !== void 0 ? { concurrency: options.concurrency } : {},
497
+ ...options.signal !== void 0 ? { signal: options.signal } : {}
498
+ });
499
+ }
500
+ /**
501
+ * Updates bucket settings such as type, CORS, lifecycle rules, and encryption.
502
+ * @param options - Fields to update. Omitted fields are left unchanged.
503
+ *
504
+ * @returns Updated bucket metadata.
505
+ */
506
+ async update(options) {
507
+ return this.client.raw.updateBucket(
508
+ this.client.accountInfo.getApiUrl(),
509
+ this.client.accountInfo.getAuthToken(),
510
+ {
511
+ accountId: ids.accountId(this.client.accountInfo.getAccountId()),
512
+ bucketId: this.id,
513
+ ...options
514
+ }
515
+ );
516
+ }
517
+ /**
518
+ * Permanently deletes this bucket. The bucket must be empty (no file versions).
519
+ *
520
+ * @returns The deleted bucket metadata.
521
+ */
522
+ async delete() {
523
+ return this.client.deleteBucket(this.id);
524
+ }
525
+ /**
526
+ * Gets a download authorization token scoped to a file name prefix in this bucket.
527
+ * @param fileNamePrefix - Only authorize downloads of files starting with this prefix.
528
+ * @param validDurationInSeconds - How long the authorization is valid (1-604800 seconds).
529
+ *
530
+ * @returns The download authorization response containing a time-limited token.
531
+ */
532
+ async getDownloadAuthorization(fileNamePrefix, validDurationInSeconds) {
533
+ return this.client.raw.getDownloadAuthorization(
534
+ this.client.accountInfo.getApiUrl(),
535
+ this.client.accountInfo.getAuthToken(),
536
+ { bucketId: this.id, fileNamePrefix, validDurationInSeconds }
537
+ );
538
+ }
539
+ /**
540
+ * Gets the event notification rules configured for this bucket.
541
+ *
542
+ * @returns The current notification rules for this bucket.
543
+ */
544
+ async getNotificationRules() {
545
+ return this.client.raw.getBucketNotificationRules(
546
+ this.client.accountInfo.getApiUrl(),
547
+ this.client.accountInfo.getAuthToken(),
548
+ { bucketId: this.id }
549
+ );
550
+ }
551
+ /**
552
+ * Replaces the event notification rules for this bucket.
553
+ * @param rules - The new set of notification rules to apply.
554
+ *
555
+ * @returns The updated notification rules for this bucket.
556
+ */
557
+ async setNotificationRules(rules) {
558
+ return this.client.raw.setBucketNotificationRules(
559
+ this.client.accountInfo.getApiUrl(),
560
+ this.client.accountInfo.getAuthToken(),
561
+ { bucketId: this.id, eventNotificationRules: rules }
562
+ );
563
+ }
564
+ /**
565
+ * Updates the file retention policy for a specific file version. Requires file lock on the bucket.
566
+ * @param fileName - The file path of the version to update.
567
+ * @param fileId - The unique identifier of the file version.
568
+ * @param retention - The new retention policy to apply.
569
+ * @param options - Optional flags. Set `bypassGovernance: true` to shorten governance-mode retention.
570
+ *
571
+ * @returns The updated file retention metadata.
572
+ */
573
+ async updateFileRetention(fileName, fileId, retention, options) {
574
+ return this.client.raw.updateFileRetention(
575
+ this.client.accountInfo.getApiUrl(),
576
+ this.client.accountInfo.getAuthToken(),
577
+ {
578
+ fileName,
579
+ fileId,
580
+ fileRetention: retention,
581
+ ...options?.bypassGovernance !== void 0 ? { bypassGovernance: options.bypassGovernance } : {}
582
+ }
583
+ );
584
+ }
585
+ /**
586
+ * Updates the legal hold status for a specific file version. Requires file lock on the bucket.
587
+ * @param fileName - The file path of the version to update.
588
+ * @param fileId - The unique identifier of the file version.
589
+ * @param legalHold - The new legal hold status to apply.
590
+ *
591
+ * @returns The updated legal hold metadata.
592
+ */
593
+ async updateFileLegalHold(fileName, fileId, legalHold) {
594
+ return this.client.raw.updateFileLegalHold(
595
+ this.client.accountInfo.getApiUrl(),
596
+ this.client.accountInfo.getAuthToken(),
597
+ { fileName, fileId, legalHold }
598
+ );
599
+ }
600
+ /**
601
+ * Refetches this bucket's metadata from B2 so callers operating on
602
+ * replication / lifecycle / retention configuration always start from the
603
+ * server-of-record state.
604
+ *
605
+ * Bucket configuration is monotonically revisioned by B2: B2 increments
606
+ * `revision` on every accepted update. The local {@link info} snapshot
607
+ * captured at construction time goes stale as soon as anyone else (or any
608
+ * prior `update()` call) mutates the bucket, so the ergonomic
609
+ * add/remove helpers below always refresh before composing the next
610
+ * `setX()` call. The result is that each helper is safe to call without
611
+ * the caller having to thread BucketInfo through their code.
612
+ *
613
+ * @returns Fresh {@link BucketInfo} for this bucket.
614
+ *
615
+ * @throws If the bucket no longer exists.
616
+ */
617
+ async refresh() {
618
+ const fresh = await this.client.listBuckets({ bucketId: this.id });
619
+ const found = fresh[0];
620
+ if (!found) throw new Error(`Bucket ${this.id} not found`);
621
+ return found.info;
622
+ }
623
+ /**
624
+ * Returns the current cross-region replication configuration, refetched
625
+ * from B2.
626
+ *
627
+ * Use this when you need to read replication state without composing a
628
+ * write. For add/remove flows the helper methods below handle the
629
+ * refresh-then-set sequence for you.
630
+ *
631
+ * @returns The current {@link ReplicationConfiguration}.
632
+ */
633
+ async getReplication() {
634
+ const fresh = await this.refresh();
635
+ return fresh.replicationConfiguration;
636
+ }
637
+ /**
638
+ * Replaces this bucket's complete replication configuration.
639
+ * @param replication - The new configuration. Pass an empty source/destination
640
+ * pair (`{ asReplicationSource: null, asReplicationDestination: null }`)
641
+ * to clear replication entirely.
642
+ *
643
+ * @returns The updated bucket metadata.
644
+ */
645
+ async setReplication(replication) {
646
+ return this.update({ replicationConfiguration: replication });
647
+ }
648
+ /**
649
+ * Adds (or replaces by `replicationRuleName`) a single replication rule
650
+ * on this bucket while leaving any other rules, the source key, and the
651
+ * destination key mapping untouched.
652
+ *
653
+ * When this is the very first source-side rule, `sourceApplicationKeyId`
654
+ * must be supplied to seed `asReplicationSource.sourceApplicationKeyId`;
655
+ * for subsequent calls the existing source key is reused unless the
656
+ * caller explicitly overrides it.
657
+ *
658
+ * @param rule - The replication rule to add or replace.
659
+ * @param options - Optional source application key ID override (or seed
660
+ * when no source side exists yet).
661
+ *
662
+ * @returns The updated bucket metadata.
663
+ *
664
+ * @throws If no source-side replication exists yet and the caller did
665
+ * not supply `sourceApplicationKeyId`.
666
+ */
667
+ async addReplicationRule(rule, options) {
668
+ const current = (await this.refresh()).replicationConfiguration;
669
+ const existingSource = current.asReplicationSource;
670
+ const sourceKey = options?.sourceApplicationKeyId ?? existingSource?.sourceApplicationKeyId;
671
+ if (!sourceKey) {
672
+ throw new Error(
673
+ "addReplicationRule: no existing source-side replication; pass options.sourceApplicationKeyId"
674
+ );
675
+ }
676
+ const existingRules = existingSource?.replicationRules ?? [];
677
+ const without = existingRules.filter((r) => r.replicationRuleName !== rule.replicationRuleName);
678
+ return this.setReplication({
679
+ asReplicationSource: {
680
+ sourceApplicationKeyId: sourceKey,
681
+ replicationRules: [...without, rule]
682
+ },
683
+ asReplicationDestination: current.asReplicationDestination
684
+ });
685
+ }
686
+ /**
687
+ * Removes a single replication rule by name. No-ops cleanly when the rule
688
+ * is not present (returns the unchanged-but-revision-bumped bucket info).
689
+ *
690
+ * @param replicationRuleName - Name of the rule to remove.
691
+ *
692
+ * @returns The updated bucket metadata.
693
+ */
694
+ async removeReplicationRule(replicationRuleName) {
695
+ const current = (await this.refresh()).replicationConfiguration;
696
+ const existingSource = current.asReplicationSource;
697
+ if (!existingSource) {
698
+ return this.setReplication(current);
699
+ }
700
+ const filtered = existingSource.replicationRules.filter(
701
+ (r) => r.replicationRuleName !== replicationRuleName
702
+ );
703
+ return this.setReplication({
704
+ asReplicationSource: {
705
+ sourceApplicationKeyId: existingSource.sourceApplicationKeyId,
706
+ replicationRules: filtered
707
+ },
708
+ asReplicationDestination: current.asReplicationDestination
709
+ });
710
+ }
711
+ /**
712
+ * Returns the current lifecycle rules for this bucket, refetched from B2.
713
+ *
714
+ * @returns The current array of {@link LifecycleRule}s.
715
+ */
716
+ async getLifecycleRules() {
717
+ const fresh = await this.refresh();
718
+ return fresh.lifecycleRules;
719
+ }
720
+ /**
721
+ * Replaces this bucket's lifecycle rules in their entirety.
722
+ * @param rules - The new rule set. Pass `[]` to remove all lifecycle
723
+ * automation.
724
+ *
725
+ * @returns The updated bucket metadata.
726
+ */
727
+ async setLifecycleRules(rules) {
728
+ return this.update({ lifecycleRules: [...rules] });
729
+ }
730
+ /**
731
+ * Adds (or replaces, matched by `fileNamePrefix`) a single lifecycle rule
732
+ * while leaving any other rules untouched.
733
+ *
734
+ * Matching on prefix mirrors B2's own data model: each unique prefix can
735
+ * have at most one rule, and a `b2_update_bucket` call that contains two
736
+ * rules with the same prefix is rejected. The helper enforces this for
737
+ * the caller.
738
+ *
739
+ * @param rule - The lifecycle rule to add or replace.
740
+ *
741
+ * @returns The updated bucket metadata.
742
+ */
743
+ async addLifecycleRule(rule) {
744
+ const current = await this.getLifecycleRules();
745
+ const without = current.filter((r) => r.fileNamePrefix !== rule.fileNamePrefix);
746
+ return this.setLifecycleRules([...without, rule]);
747
+ }
748
+ /**
749
+ * Removes a single lifecycle rule by prefix. No-ops cleanly when the rule
750
+ * is not present.
751
+ *
752
+ * @param fileNamePrefix - The prefix of the rule to remove.
753
+ *
754
+ * @returns The updated bucket metadata.
755
+ */
756
+ async removeLifecycleRule(fileNamePrefix) {
757
+ const current = await this.getLifecycleRules();
758
+ return this.setLifecycleRules(current.filter((r) => r.fileNamePrefix !== fileNamePrefix));
759
+ }
760
+ /**
761
+ * Returns the current default Object Lock retention policy for new
762
+ * uploads to this bucket, refetched from B2.
763
+ *
764
+ * @returns The default {@link BucketRetentionPolicy} (which may be
765
+ * `{ mode: 'none', period: null }` when Object Lock is enabled on the
766
+ * bucket but no default is set).
767
+ */
768
+ async getDefaultRetention() {
769
+ const fresh = await this.refresh();
770
+ return fresh.defaultRetention;
771
+ }
772
+ /**
773
+ * Sets (or clears, by passing `{ mode: 'none', period: null }`) the
774
+ * default Object Lock retention policy applied to new uploads.
775
+ *
776
+ * Object Lock must already be enabled on the bucket. Buckets created
777
+ * without `fileLockEnabled: true` cannot accept a default retention
778
+ * policy and B2 will reject this call.
779
+ *
780
+ * @param policy - The new default retention policy.
781
+ *
782
+ * @returns The updated bucket metadata.
783
+ */
784
+ async setDefaultRetention(policy) {
785
+ return this.update({ defaultRetention: policy });
786
+ }
787
+ }
788
+ exports.Bucket = Bucket;
789
+ //# sourceMappingURL=bucket.cjs.map