@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 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/raw/index.ts"],"sourcesContent":["/**\n * Low-level 1:1 bindings for every B2 native API endpoint.\n *\n * Each method on {@link RawClient} maps directly to a single `b2_*` HTTP call\n * with fully typed request and response objects. No retry logic, no URL pooling,\n * no automatic reauthorization. Use this when you need precise control over\n * individual API calls; for most use cases prefer the high-level `B2Client`.\n *\n * @packageDocumentation\n */\n\nimport type { HttpTransport } from '../http/transport.ts'\nimport type {\n ApplicationKey,\n AuthorizeAccountResponse,\n BucketInfo,\n CancelLargeFileRequest,\n CancelLargeFileResponse,\n CopyFileRequest,\n CopyPartRequest,\n CopyPartResponse,\n CreateBucketRequest,\n CreateKeyRequest,\n DeleteBucketRequest,\n DeleteFileVersionRequest,\n DeleteFileVersionResponse,\n DeleteKeyRequest,\n DownloadAuthorizationRequest,\n DownloadAuthorizationResponse,\n FileVersion,\n FinishLargeFileRequest,\n FullApplicationKey,\n GetBucketNotificationRulesRequest,\n GetBucketNotificationRulesResponse,\n GetFileInfoRequest,\n GetUploadPartUrlRequest,\n GetUploadPartUrlResponse,\n GetUploadUrlRequest,\n GetUploadUrlResponse,\n HideFileRequest,\n ListBucketsRequest,\n ListBucketsResponse,\n ListFileNamesRequest,\n ListFileNamesResponse,\n ListFileVersionsRequest,\n ListFileVersionsResponse,\n ListKeysRequest,\n ListKeysResponse,\n ListPartsRequest,\n ListPartsResponse,\n ListUnfinishedLargeFilesRequest,\n ListUnfinishedLargeFilesResponse,\n SetBucketNotificationRulesRequest,\n SetBucketNotificationRulesResponse,\n StartLargeFileRequest,\n StartLargeFileResponse,\n UpdateBucketRequest,\n UpdateFileLegalHoldRequest,\n UpdateFileLegalHoldResponse,\n UpdateFileRetentionRequest,\n UpdateFileRetentionResponse,\n} from '../types/index.ts'\nimport type { UploadFileHeaders, UploadPartHeaders, UploadPartResponse } from '../types/upload.ts'\nimport { normalizeFileVersionListSha1, normalizeFileVersionSha1 } from '../util/normalize.ts'\nimport { buildFileInfoHeaders, encodeFileName } from './encoding.ts'\n\n/** Configuration for constructing a {@link RawClient}. */\nexport interface RawClientOptions {\n /** The HTTP transport used to send requests (e.g., FetchTransport or RetryTransport). */\n readonly transport: HttpTransport\n}\n\n/**\n * Low-level client providing 1:1 bindings to all B2 native API endpoints.\n *\n * Each method maps directly to a single B2 API call. Most methods accept\n * `(apiUrl, authToken, request)` and return the JSON response. Upload and\n * download methods accept endpoint-specific parameters instead.\n */\nexport class RawClient {\n /** @internal */\n private readonly transport: HttpTransport\n\n /**\n * Creates a new RawClient with the given transport.\n * @param options - The constructor configuration.\n */\n constructor(options: RawClientOptions) {\n this.transport = options.transport\n }\n\n // --- Auth ---\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-authorize-account | b2_authorize_account}.\n * @param applicationKeyId - The application key ID for authentication.\n * @param applicationKey - The application key secret.\n * @param realmUrl - The B2 realm URL to authenticate against.\n *\n * @returns The authorization response with API URLs and credentials.\n */\n async authorizeAccount(\n applicationKeyId: string,\n applicationKey: string,\n realmUrl = 'https://api.backblazeb2.com',\n ): Promise<AuthorizeAccountResponse> {\n const response = await this.transport.send({\n url: `${realmUrl}/b2api/v3/b2_authorize_account`,\n method: 'GET',\n headers: {\n Authorization: `Basic ${btoa(`${applicationKeyId}:${applicationKey}`)}`,\n },\n })\n return response.json<AuthorizeAccountResponse>()\n }\n\n // --- Buckets ---\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-create-bucket | b2_create_bucket}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The created bucket metadata.\n */\n async createBucket(\n apiUrl: string,\n authToken: string,\n request: CreateBucketRequest,\n ): Promise<BucketInfo> {\n return this.postJson<BucketInfo>(apiUrl, authToken, 'b2_create_bucket', request)\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-delete-bucket | b2_delete_bucket}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The deleted bucket metadata.\n */\n async deleteBucket(\n apiUrl: string,\n authToken: string,\n request: DeleteBucketRequest,\n ): Promise<BucketInfo> {\n return this.postJson<BucketInfo>(apiUrl, authToken, 'b2_delete_bucket', request)\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-list-buckets | b2_list_buckets}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The list of matching buckets.\n */\n async listBuckets(\n apiUrl: string,\n authToken: string,\n request: ListBucketsRequest,\n ): Promise<ListBucketsResponse> {\n return this.postJson<ListBucketsResponse>(apiUrl, authToken, 'b2_list_buckets', request)\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-update-bucket | b2_update_bucket}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The updated bucket metadata.\n */\n async updateBucket(\n apiUrl: string,\n authToken: string,\n request: UpdateBucketRequest,\n ): Promise<BucketInfo> {\n return this.postJson<BucketInfo>(apiUrl, authToken, 'b2_update_bucket', request)\n }\n\n // --- Files ---\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-get-upload-url | b2_get_upload_url}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The upload URL and authorization token.\n */\n async getUploadUrl(\n apiUrl: string,\n authToken: string,\n request: GetUploadUrlRequest,\n ): Promise<GetUploadUrlResponse> {\n return this.postJson<GetUploadUrlResponse>(apiUrl, authToken, 'b2_get_upload_url', request)\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-upload-file | b2_upload_file}.\n *\n * Unlike most methods, this posts directly to the `uploadUrl` obtained\n * from {@link getUploadUrl} rather than the API URL.\n * @param uploadUrl - The upload endpoint URL.\n * @param headers - The request headers including authorization and content metadata.\n * @param body - The file data to upload.\n * @param signal - An optional abort signal for cancellation.\n *\n * @returns The uploaded file version metadata.\n */\n async uploadFile(\n uploadUrl: string,\n headers: UploadFileHeaders,\n body: BodyInit,\n signal?: AbortSignal,\n ): Promise<FileVersion> {\n const reqHeaders: Record<string, string> = {\n Authorization: headers.authorization,\n 'X-Bz-File-Name': encodeFileName(headers.fileName),\n 'Content-Type': headers.contentType,\n 'Content-Length': String(headers.contentLength),\n 'X-Bz-Content-Sha1': headers.contentSha1,\n ...buildFileInfoHeaders(headers.fileInfo),\n }\n\n if (headers.lastModifiedMillis !== undefined) {\n reqHeaders['X-Bz-Info-src_last_modified_millis'] = String(headers.lastModifiedMillis)\n }\n if (headers.contentDisposition) {\n reqHeaders['X-Bz-Info-b2-content-disposition'] = headers.contentDisposition\n }\n if (headers.contentLanguage) {\n reqHeaders['X-Bz-Info-b2-content-language'] = headers.contentLanguage\n }\n if (headers.expires) {\n reqHeaders['X-Bz-Info-b2-expires'] = headers.expires\n }\n if (headers.cacheControl) {\n reqHeaders['X-Bz-Info-b2-cache-control'] = headers.cacheControl\n }\n if (headers.contentEncoding) {\n reqHeaders['X-Bz-Info-b2-content-encoding'] = headers.contentEncoding\n }\n\n applyEncryptionHeaders(reqHeaders, headers.serverSideEncryption)\n applyRetentionHeaders(reqHeaders, headers.fileRetention)\n applyLegalHoldHeader(reqHeaders, headers.legalHold)\n\n const response = await this.transport.send({\n url: uploadUrl,\n method: 'POST',\n headers: reqHeaders,\n body,\n ...(signal !== undefined ? { signal } : {}),\n })\n return normalizeFileVersionSha1(await response.json<FileVersion>())\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-list-file-names | b2_list_file_names}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The list of file names and optional continuation token.\n */\n async listFileNames(\n apiUrl: string,\n authToken: string,\n request: ListFileNamesRequest,\n ): Promise<ListFileNamesResponse> {\n return normalizeFileVersionListSha1(\n await this.postJson<ListFileNamesResponse>(apiUrl, authToken, 'b2_list_file_names', request),\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-list-file-versions | b2_list_file_versions}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The list of file versions and optional continuation token.\n */\n async listFileVersions(\n apiUrl: string,\n authToken: string,\n request: ListFileVersionsRequest,\n ): Promise<ListFileVersionsResponse> {\n return normalizeFileVersionListSha1(\n await this.postJson<ListFileVersionsResponse>(\n apiUrl,\n authToken,\n 'b2_list_file_versions',\n request,\n ),\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-get-file-info | b2_get_file_info}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The file version metadata.\n */\n async getFileInfo(\n apiUrl: string,\n authToken: string,\n request: GetFileInfoRequest,\n ): Promise<FileVersion> {\n return normalizeFileVersionSha1(\n await this.postJson<FileVersion>(apiUrl, authToken, 'b2_get_file_info', request),\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-hide-file | b2_hide_file}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The hidden file version metadata.\n */\n async hideFile(\n apiUrl: string,\n authToken: string,\n request: HideFileRequest,\n ): Promise<FileVersion> {\n return normalizeFileVersionSha1(\n await this.postJson<FileVersion>(apiUrl, authToken, 'b2_hide_file', request),\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-delete-file-version | b2_delete_file_version}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The deleted file version identifier.\n */\n async deleteFileVersion(\n apiUrl: string,\n authToken: string,\n request: DeleteFileVersionRequest,\n ): Promise<DeleteFileVersionResponse> {\n return this.postJson<DeleteFileVersionResponse>(\n apiUrl,\n authToken,\n 'b2_delete_file_version',\n request,\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-copy-file | b2_copy_file}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The copied file version metadata.\n */\n async copyFile(\n apiUrl: string,\n authToken: string,\n request: CopyFileRequest,\n ): Promise<FileVersion> {\n return normalizeFileVersionSha1(\n await this.postJson<FileVersion>(apiUrl, authToken, 'b2_copy_file', request),\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-copy-part | b2_copy_part}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The copied part metadata.\n */\n async copyPart(\n apiUrl: string,\n authToken: string,\n request: CopyPartRequest,\n ): Promise<CopyPartResponse> {\n return this.postJson<CopyPartResponse>(apiUrl, authToken, 'b2_copy_part', request)\n }\n\n // --- Large Files ---\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-start-large-file | b2_start_large_file}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The started large file metadata with file ID.\n */\n async startLargeFile(\n apiUrl: string,\n authToken: string,\n request: StartLargeFileRequest,\n ): Promise<StartLargeFileResponse> {\n return this.postJson<StartLargeFileResponse>(apiUrl, authToken, 'b2_start_large_file', request)\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-get-upload-part-url | b2_get_upload_part_url}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The upload part URL and authorization token.\n */\n async getUploadPartUrl(\n apiUrl: string,\n authToken: string,\n request: GetUploadPartUrlRequest,\n ): Promise<GetUploadPartUrlResponse> {\n return this.postJson<GetUploadPartUrlResponse>(\n apiUrl,\n authToken,\n 'b2_get_upload_part_url',\n request,\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-upload-part | b2_upload_part}.\n *\n * Posts directly to the `uploadUrl` obtained from {@link getUploadPartUrl}\n * rather than the API URL.\n * @param uploadUrl - The upload endpoint URL.\n * @param headers - The request headers including authorization and content metadata.\n * @param body - The file data to upload.\n * @param signal - An optional abort signal for cancellation.\n *\n * @returns The uploaded part metadata.\n */\n async uploadPart(\n uploadUrl: string,\n headers: UploadPartHeaders,\n body: BodyInit,\n signal?: AbortSignal,\n ): Promise<UploadPartResponse> {\n const reqHeaders: Record<string, string> = {\n Authorization: headers.authorization,\n 'X-Bz-Part-Number': String(headers.partNumber),\n 'Content-Length': String(headers.contentLength),\n 'X-Bz-Content-Sha1': headers.contentSha1,\n }\n\n applyEncryptionHeaders(reqHeaders, headers.serverSideEncryption)\n\n const response = await this.transport.send({\n url: uploadUrl,\n method: 'POST',\n headers: reqHeaders,\n body,\n ...(signal !== undefined ? { signal } : {}),\n })\n return response.json<UploadPartResponse>()\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-finish-large-file | b2_finish_large_file}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The completed file version metadata.\n */\n async finishLargeFile(\n apiUrl: string,\n authToken: string,\n request: FinishLargeFileRequest,\n ): Promise<FileVersion> {\n return normalizeFileVersionSha1(\n await this.postJson<FileVersion>(apiUrl, authToken, 'b2_finish_large_file', request),\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-cancel-large-file | b2_cancel_large_file}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The cancelled large file metadata.\n */\n async cancelLargeFile(\n apiUrl: string,\n authToken: string,\n request: CancelLargeFileRequest,\n ): Promise<CancelLargeFileResponse> {\n return this.postJson<CancelLargeFileResponse>(\n apiUrl,\n authToken,\n 'b2_cancel_large_file',\n request,\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-list-unfinished-large-files | b2_list_unfinished_large_files}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The list of unfinished large files and optional continuation token.\n */\n async listUnfinishedLargeFiles(\n apiUrl: string,\n authToken: string,\n request: ListUnfinishedLargeFilesRequest,\n ): Promise<ListUnfinishedLargeFilesResponse> {\n return this.postJson<ListUnfinishedLargeFilesResponse>(\n apiUrl,\n authToken,\n 'b2_list_unfinished_large_files',\n request,\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-list-parts | b2_list_parts}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The list of uploaded parts and optional continuation token.\n */\n async listParts(\n apiUrl: string,\n authToken: string,\n request: ListPartsRequest,\n ): Promise<ListPartsResponse> {\n return this.postJson<ListPartsResponse>(apiUrl, authToken, 'b2_list_parts', request)\n }\n\n // --- Downloads ---\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-download-file-by-id | b2_download_file_by_id}.\n * @param downloadUrl - The B2 download base URL.\n * @param authToken - The authorization token.\n * @param fileId - The unique identifier of the file to download.\n * @param options - Optional download parameters for range requests and cancellation.\n *\n * @returns The response headers, streaming body, and HTTP status code.\n */\n async downloadFileById(\n downloadUrl: string,\n authToken: string,\n fileId: string,\n options?: DownloadFileOptions,\n ): Promise<{\n /** Response headers containing file metadata and B2 info headers. */\n headers: Headers\n /** Streaming response body, or `null` for HEAD-like responses. */\n body: ReadableStream<Uint8Array> | null\n /** HTTP status code (200 for full content, 206 for partial content). */\n status: number\n }> {\n const headers = buildDownloadRequestHeaders(authToken, options)\n const url = appendDownloadOverrides(\n `${downloadUrl}/b2api/v3/b2_download_file_by_id?fileId=${encodeURIComponent(fileId)}`,\n options,\n )\n\n const response = await this.transport.send({\n url,\n method: options?.method ?? 'GET',\n headers,\n ...(options?.signal !== undefined ? { signal: options.signal } : {}),\n })\n\n return { headers: response.headers, body: response.body, status: response.status }\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-download-file-by-name | b2_download_file_by_name}.\n * @param downloadUrl - The B2 download base URL.\n * @param authToken - The authorization token.\n * @param bucketName - The name of the bucket containing the file.\n * @param fileName - The name of the file to download.\n * @param options - Optional download parameters for range requests and cancellation.\n *\n * @returns The response headers, streaming body, and HTTP status code.\n */\n async downloadFileByName(\n downloadUrl: string,\n authToken: string,\n bucketName: string,\n fileName: string,\n options?: DownloadFileOptions,\n ): Promise<{\n /** Response headers containing file metadata and B2 info headers. */\n headers: Headers\n /** Streaming response body, or `null` for HEAD-like responses. */\n body: ReadableStream<Uint8Array> | null\n /** HTTP status code (200 for full content, 206 for partial content). */\n status: number\n }> {\n const headers = buildDownloadRequestHeaders(authToken, options)\n const url = appendDownloadOverrides(\n `${downloadUrl}/file/${encodeURIComponent(bucketName)}/${encodeFileName(fileName)}`,\n options,\n )\n\n const response = await this.transport.send({\n url,\n method: options?.method ?? 'GET',\n headers,\n ...(options?.signal !== undefined ? { signal: options.signal } : {}),\n })\n\n return { headers: response.headers, body: response.body, status: response.status }\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-get-download-authorization | b2_get_download_authorization}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The current session authorization token.\n * @param request - The API request parameters.\n *\n * @returns The download authorization token for the specified file prefix.\n */\n async getDownloadAuthorization(\n apiUrl: string,\n authToken: string,\n request: DownloadAuthorizationRequest,\n ): Promise<DownloadAuthorizationResponse> {\n return this.postJson<DownloadAuthorizationResponse>(\n apiUrl,\n authToken,\n 'b2_get_download_authorization',\n request,\n )\n }\n\n // --- Keys ---\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-create-key | b2_create_key}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The newly created application key with secret.\n */\n async createKey(\n apiUrl: string,\n authToken: string,\n request: CreateKeyRequest,\n ): Promise<FullApplicationKey> {\n return this.postJson<FullApplicationKey>(apiUrl, authToken, 'b2_create_key', request)\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-list-keys | b2_list_keys}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The list of application keys and optional continuation token.\n */\n async listKeys(\n apiUrl: string,\n authToken: string,\n request: ListKeysRequest,\n ): Promise<ListKeysResponse> {\n return this.postJson<ListKeysResponse>(apiUrl, authToken, 'b2_list_keys', request)\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-delete-key | b2_delete_key}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The deleted application key metadata.\n */\n async deleteKey(\n apiUrl: string,\n authToken: string,\n request: DeleteKeyRequest,\n ): Promise<ApplicationKey> {\n return this.postJson<ApplicationKey>(apiUrl, authToken, 'b2_delete_key', request)\n }\n\n // --- Retention / Legal Hold ---\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-update-file-retention | b2_update_file_retention}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The updated file retention settings.\n */\n async updateFileRetention(\n apiUrl: string,\n authToken: string,\n request: UpdateFileRetentionRequest,\n ): Promise<UpdateFileRetentionResponse> {\n return this.postJson<UpdateFileRetentionResponse>(\n apiUrl,\n authToken,\n 'b2_update_file_retention',\n request,\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-update-file-legal-hold | b2_update_file_legal_hold}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The updated file legal hold status.\n */\n async updateFileLegalHold(\n apiUrl: string,\n authToken: string,\n request: UpdateFileLegalHoldRequest,\n ): Promise<UpdateFileLegalHoldResponse> {\n return this.postJson<UpdateFileLegalHoldResponse>(\n apiUrl,\n authToken,\n 'b2_update_file_legal_hold',\n request,\n )\n }\n\n // --- Notifications ---\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-get-bucket-notification-rules | b2_get_bucket_notification_rules}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The configured event notification rules for the specified bucket.\n */\n async getBucketNotificationRules(\n apiUrl: string,\n authToken: string,\n request: GetBucketNotificationRulesRequest,\n ): Promise<GetBucketNotificationRulesResponse> {\n return this.postJson<GetBucketNotificationRulesResponse>(\n apiUrl,\n authToken,\n 'b2_get_bucket_notification_rules',\n request,\n )\n }\n\n /**\n * Calls {@link https://www.backblaze.com/apidocs/b2-set-bucket-notification-rules | b2_set_bucket_notification_rules}.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param request - The API request parameters.\n *\n * @returns The updated bucket notification rules.\n */\n async setBucketNotificationRules(\n apiUrl: string,\n authToken: string,\n request: SetBucketNotificationRulesRequest,\n ): Promise<SetBucketNotificationRulesResponse> {\n return this.postJson<SetBucketNotificationRulesResponse>(\n apiUrl,\n authToken,\n 'b2_set_bucket_notification_rules',\n request,\n )\n }\n\n // --- Internal ---\n\n /**\n * Sends a JSON POST request to the specified B2 API endpoint.\n * @param apiUrl - The B2 API base URL.\n * @param authToken - The authorization token.\n * @param endpoint - The B2 API endpoint name.\n * @param body - The JSON request body.\n *\n * @returns The parsed JSON response.\n */\n private async postJson<T>(\n apiUrl: string,\n authToken: string,\n endpoint: string,\n body: unknown,\n ): Promise<T> {\n const response = await this.transport.send({\n url: `${apiUrl}/b2api/v3/${endpoint}`,\n method: 'POST',\n headers: {\n Authorization: authToken,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n })\n return response.json<T>()\n }\n}\n\n// --- Header helpers ---\n\nimport { EncryptionAlgorithm, EncryptionMode, type EncryptionSetting } from '../types/encryption.ts'\nimport type { FileRetentionValue, LegalHoldValue } from '../types/lock.ts'\n\n/**\n * Applies server-side encryption headers to the request.\n * @param headers - The mutable headers object to populate.\n * @param encryption - The encryption settings, or undefined to skip.\n */\nfunction applyEncryptionHeaders(\n headers: Record<string, string>,\n encryption: EncryptionSetting | undefined,\n): void {\n if (!encryption || encryption.mode === EncryptionMode.None) return\n if (encryption.mode === EncryptionMode.SseB2) {\n headers['X-Bz-Server-Side-Encryption'] = EncryptionAlgorithm.Aes256\n } else if (encryption.mode === EncryptionMode.SseC) {\n headers['X-Bz-Server-Side-Encryption-Customer-Algorithm'] = EncryptionAlgorithm.Aes256\n headers['X-Bz-Server-Side-Encryption-Customer-Key'] = encryption.customerKey\n headers['X-Bz-Server-Side-Encryption-Customer-Key-Md5'] = encryption.customerKeyMd5\n }\n}\n\n/**\n * SSE-C decryption parameters supplied to downloads of files that were\n * uploaded with customer-managed keys.\n */\nexport interface SseCDownloadKey {\n /** Encryption algorithm. Always `EncryptionAlgorithm.Aes256` (`'AES256'`). */\n readonly algorithm: EncryptionAlgorithm\n /** Base64-encoded customer-provided decryption key. */\n readonly customerKey: string\n /** Base64-encoded MD5 digest of the decryption key. */\n readonly customerKeyMd5: string\n}\n\n/**\n * Options accepted by {@link RawClient.downloadFileById} and\n * {@link RawClient.downloadFileByName}. Mirrors the B2 native API: range +\n * SSE-C decryption headers + the documented `b2Content*` response-header\n * overrides (query-string parameters on the request URL).\n */\nexport interface DownloadFileOptions {\n /** HTTP method. Defaults to `'GET'`. Use `'HEAD'` to fetch headers without the body. */\n readonly method?: 'GET' | 'HEAD'\n /** HTTP Range header value for partial content requests. */\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 `Content-Disposition` header in the download response. */\n readonly b2ContentDisposition?: string\n /** Override the `Content-Language` header in the download response. */\n readonly b2ContentLanguage?: string\n /** Override the `Content-Encoding` header in the download response. */\n readonly b2ContentEncoding?: string\n /** Override the `Content-Type` header in the download response. */\n readonly b2ContentType?: string\n /** Override the `Cache-Control` header in the download response. */\n readonly b2CacheControl?: string\n /** Override the `Expires` header in the download response. */\n readonly b2Expires?: string\n /** Signal to abort the download. */\n readonly signal?: AbortSignal\n}\n\nconst DOWNLOAD_OVERRIDE_PARAMS = [\n 'b2ContentDisposition',\n 'b2ContentLanguage',\n 'b2ContentEncoding',\n 'b2ContentType',\n 'b2CacheControl',\n 'b2Expires',\n] as const\n\n/**\n * Builds the HTTP request headers for a download: Authorization, optional\n * Range, and optional SSE-C decryption headers.\n *\n * @param authToken - The B2 session authorization token.\n * @param options - Caller-supplied download options.\n *\n * @returns The header map to send with the request.\n */\nfunction buildDownloadRequestHeaders(\n authToken: string,\n options: DownloadFileOptions | undefined,\n): Record<string, string> {\n const headers: Record<string, string> = { Authorization: authToken }\n if (options?.range) headers['Range'] = options.range\n if (options?.serverSideEncryption) {\n applyEncryptionHeaders(headers, {\n mode: EncryptionMode.SseC,\n ...options.serverSideEncryption,\n })\n }\n return headers\n}\n\n/**\n * Appends the documented `b2Content*` response-header overrides to a download\n * URL as query-string parameters. B2 echoes the values into the response\n * headers so callers can control content type, disposition, and caching.\n *\n * @param url - The base download URL.\n * @param options - Caller-supplied download options.\n *\n * @returns The URL with any override parameters appended.\n */\nfunction appendDownloadOverrides(url: string, options: DownloadFileOptions | undefined): string {\n if (!options) return url\n const params: string[] = []\n for (const key of DOWNLOAD_OVERRIDE_PARAMS) {\n const value = options[key]\n if (value !== undefined) {\n params.push(`${key}=${encodeURIComponent(value)}`)\n }\n }\n if (params.length === 0) return url\n const separator = url.includes('?') ? '&' : '?'\n return `${url}${separator}${params.join('&')}`\n}\n\n/**\n * Applies file retention headers to the request.\n * @param headers - The mutable headers object to populate.\n * @param retention - The retention settings, or undefined to skip.\n */\nfunction applyRetentionHeaders(\n headers: Record<string, string>,\n retention: FileRetentionValue | undefined,\n): void {\n if (!retention) return\n if (retention.mode) {\n headers['X-Bz-File-Retention-Mode'] = retention.mode\n }\n if (retention.retainUntilTimestamp) {\n headers['X-Bz-File-Retention-Retain-Until-Timestamp'] = String(retention.retainUntilTimestamp)\n }\n}\n\n/**\n * Applies the legal hold header to the request.\n * @param headers - The mutable headers object to populate.\n * @param legalHold - The legal hold value, or undefined to skip.\n */\nfunction applyLegalHoldHeader(\n headers: Record<string, string>,\n legalHold: LegalHoldValue | undefined,\n): void {\n if (!legalHold) return\n headers['X-Bz-File-Legal-Hold'] = legalHold\n}\n\nexport {\n encodeFileName,\n decodeFileName,\n buildFileInfoHeaders,\n parseFileInfoHeaders,\n} from './encoding.ts'\n"],"names":[],"mappings":";;;;AA+EO,MAAM,UAAU;AAAA;AAAA,EAEJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjB,YAAY,SAA2B;AACrC,SAAK,YAAY,QAAQ;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,iBACJ,kBACA,gBACA,WAAW,+BACwB;AACnC,UAAM,WAAW,MAAM,KAAK,UAAU,KAAK;AAAA,MACzC,KAAK,GAAG,QAAQ;AAAA,MAChB,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,eAAe,SAAS,KAAK,GAAG,gBAAgB,IAAI,cAAc,EAAE,CAAC;AAAA,MAAA;AAAA,IACvE,CACD;AACD,WAAO,SAAS,KAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,aACJ,QACA,WACA,SACqB;AACrB,WAAO,KAAK,SAAqB,QAAQ,WAAW,oBAAoB,OAAO;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,aACJ,QACA,WACA,SACqB;AACrB,WAAO,KAAK,SAAqB,QAAQ,WAAW,oBAAoB,OAAO;AAAA,EACjF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,YACJ,QACA,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WAAW;AACjE,YAAQ,8CAA8C,IAAI,WAAW;AAAA,EACvE;AACF;AA4CA,MAAM,2BAA2B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAWA,SAAS,4BACP,WACA,SACwB;AACxB,QAAM,UAAkC,EAAE,eAAe,UAAA;AACzD,MAAI,SAAS,MAAO,SAAQ,OAAO,IAAI,QAAQ;AAC/C,MAAI,SAAS,sBAAsB;AACjC,2BAAuB,SAAS;AAAA,MAC9B,MAAM,eAAe;AAAA,MACrB,GAAG,QAAQ;AAAA,IAAA,CACZ;AAAA,EACH;AACA,SAAO;AACT;AAYA,SAAS,wBAAwB,KAAa,SAAkD;AAC9F,MAAI,CAAC,QAAS,QAAO;AACrB,QAAM,SAAmB,CAAA;AACzB,aAAW,OAAO,0BAA0B;AAC1C,UAAM,QAAQ,QAAQ,GAAG;AACzB,QAAI,UAAU,QAAW;AACvB,aAAO,KAAK,GAAG,GAAG,IAAI,mBAAmB,KAAK,CAAC,EAAE;AAAA,IACnD;AAAA,EACF;AACA,MAAI,OAAO,WAAW,EAAG,QAAO;AAChC,QAAM,YAAY,IAAI,SAAS,GAAG,IAAI,MAAM;AAC5C,SAAO,GAAG,GAAG,GAAG,SAAS,GAAG,OAAO,KAAK,GAAG,CAAC;AAC9C;AAOA,SAAS,sBACP,SACA,WACM;AACN,MAAI,CAAC,UAAW;AAChB,MAAI,UAAU,MAAM;AAClB,YAAQ,0BAA0B,IAAI,UAAU;AAAA,EAClD;AACA,MAAI,UAAU,sBAAsB;AAClC,YAAQ,4CAA4C,IAAI,OAAO,UAAU,oBAAoB;AAAA,EAC/F;AACF;AAOA,SAAS,qBACP,SACA,WACM;AACN,MAAI,CAAC,UAAW;AAChB,UAAQ,sBAAsB,IAAI;AACpC;"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function createS3ClientConfig(config) {
4
+ const s3Url = config.accountInfo.getS3ApiUrl();
5
+ const regionMatch = s3Url.match(/s3\.([^.]+)\.backblazeb2\.com/);
6
+ const region = config.region ?? regionMatch?.[1] ?? "us-west-004";
7
+ return {
8
+ endpoint: s3Url,
9
+ region,
10
+ credentials: {
11
+ accessKeyId: config.applicationKeyId,
12
+ secretAccessKey: config.applicationKey
13
+ },
14
+ forcePathStyle: true
15
+ };
16
+ }
17
+ function presignGetObjectUrl(downloadUrl, bucketName, fileName, authorizationToken, validDurationInSeconds = 3600) {
18
+ const expires = Math.floor(Date.now() / 1e3) + validDurationInSeconds;
19
+ return `${downloadUrl}/file/${encodeURIComponent(bucketName)}/${encodeURIComponent(fileName)}?Authorization=${encodeURIComponent(authorizationToken)}&expires=${expires}`;
20
+ }
21
+ exports.createS3ClientConfig = createS3ClientConfig;
22
+ exports.presignGetObjectUrl = presignGetObjectUrl;
23
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/s3/index.ts"],"sourcesContent":["/**\n * S3-compatible helpers for using B2 with the AWS SDK.\n *\n * Provides {@link createS3ClientConfig} to derive endpoint, region, and\n * credentials from B2 authorization state, plus {@link presignGetObjectUrl}\n * for generating download URLs using B2 native download authorization.\n *\n * @packageDocumentation\n */\n\nimport type { AccountInfo } from '../auth/account-info.ts'\n\n/**\n * Configuration for deriving S3-compatible client settings from B2 auth state.\n *\n * Per B2's S3-compatible API contract, the S3 `accessKeyId` is the\n * `applicationKeyId` and the S3 `secretAccessKey` is the\n * `applicationKey`. These are NOT the native `accountId` /\n * `authorizationToken` returned by `b2_authorize_account` — those won't\n * authenticate against the S3 endpoint. Both must be supplied here\n * because `AccountInfo` doesn't retain the application key after\n * authorization for security reasons.\n *\n * @see https://www.backblaze.com/apidocs/s3-compatible-api\n */\nexport interface B2S3Config {\n /** The authorized AccountInfo containing the S3 endpoint URL. */\n readonly accountInfo: AccountInfo\n /** B2 application key ID. Used as the S3 `accessKeyId`. */\n readonly applicationKeyId: string\n /** B2 application key (secret). Used as the S3 `secretAccessKey`. */\n readonly applicationKey: string\n /** Override the S3 region. If omitted, extracted from the S3 API URL. */\n readonly region?: string\n}\n\n/** Configuration object compatible with `@aws-sdk/client-s3`'s S3Client constructor. */\nexport interface S3ClientConfig {\n /** The S3-compatible endpoint URL (e.g., `https://s3.us-west-004.backblazeb2.com`). */\n readonly endpoint: string\n /** The S3 region identifier (e.g., `us-west-004`). */\n readonly region: string\n /** AWS-style credentials — the B2 application key pair. */\n readonly credentials: {\n /** The B2 application key ID, used as the S3 access key ID. */\n readonly accessKeyId: string\n /** The B2 application key (secret), used as the S3 secret access key. */\n readonly secretAccessKey: string\n }\n /** Always `true` for B2, which requires path-style bucket addressing. */\n readonly forcePathStyle: boolean\n}\n\n/**\n * Derives an S3-compatible client configuration from B2 authorization state.\n * Pass the result to `new S3Client(config)` from `@aws-sdk/client-s3`.\n *\n * @param config - B2 auth state, application key credentials, and optional region override.\n *\n * @returns Configuration ready for the AWS S3 SDK.\n *\n * @example\n * ```ts\n * const { B2_APPLICATION_KEY_ID, B2_APPLICATION_KEY } = process.env\n * if (!B2_APPLICATION_KEY_ID || !B2_APPLICATION_KEY) throw new Error('Missing B2 credentials')\n * const s3 = new S3Client(createS3ClientConfig({\n * accountInfo: client.accountInfo,\n * applicationKeyId: B2_APPLICATION_KEY_ID,\n * applicationKey: B2_APPLICATION_KEY,\n * }))\n * ```\n */\nexport function createS3ClientConfig(config: B2S3Config): S3ClientConfig {\n const s3Url = config.accountInfo.getS3ApiUrl()\n const regionMatch = s3Url.match(/s3\\.([^.]+)\\.backblazeb2\\.com/)\n const region = config.region ?? regionMatch?.[1] ?? 'us-west-004'\n\n return {\n endpoint: s3Url,\n region,\n credentials: {\n accessKeyId: config.applicationKeyId,\n secretAccessKey: config.applicationKey,\n },\n forcePathStyle: true,\n }\n}\n\n/**\n * Constructs a presigned download URL using B2's native download authorization.\n * This is not a standard S3 presigned URL but works for B2 download endpoints.\n *\n * @param downloadUrl - The B2 download URL from authorization (e.g., `https://f004.backblazeb2.com`).\n * @param bucketName - The bucket containing the file.\n * @param fileName - The file name (path) to download.\n * @param authorizationToken - A download authorization token from `b2_get_download_authorization`.\n * @param validDurationInSeconds - URL validity duration in seconds. Defaults to 3600 (1 hour).\n *\n * @returns The presigned download URL string.\n */\nexport function presignGetObjectUrl(\n downloadUrl: string,\n bucketName: string,\n fileName: string,\n authorizationToken: string,\n validDurationInSeconds = 3600,\n): string {\n const expires = Math.floor(Date.now() / 1000) + validDurationInSeconds\n return `${downloadUrl}/file/${encodeURIComponent(bucketName)}/${encodeURIComponent(fileName)}?Authorization=${encodeURIComponent(authorizationToken)}&expires=${expires}`\n}\n"],"names":[],"mappings":";;AAwEO,SAAS,qBAAqB,QAAoC;AACvE,QAAM,QAAQ,OAAO,YAAY,YAAA;AACjC,QAAM,cAAc,MAAM,MAAM,+BAA+B;AAC/D,QAAM,SAAS,OAAO,UAAU,cAAc,CAAC,KAAK;AAEpD,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,IACA,aAAa;AAAA,MACX,aAAa,OAAO;AAAA,MACpB,iBAAiB,OAAO;AAAA,IAAA;AAAA,IAE1B,gBAAgB;AAAA,EAAA;AAEpB;AAcO,SAAS,oBACd,aACA,YACA,UACA,oBACA,yBAAyB,MACjB;AACR,QAAM,UAAU,KAAK,MAAM,KAAK,IAAA,IAAQ,GAAI,IAAI;AAChD,SAAO,GAAG,WAAW,SAAS,mBAAmB,UAAU,CAAC,IAAI,mBAAmB,QAAQ,CAAC,kBAAkB,mBAAmB,kBAAkB,CAAC,YAAY,OAAO;AACzK;;;"}
@@ -0,0 +1,74 @@
1
+ import { AccountInfo } from '../auth/account-info.js';
2
+ /**
3
+ * Configuration for deriving S3-compatible client settings from B2 auth state.
4
+ *
5
+ * Per B2's S3-compatible API contract, the S3 `accessKeyId` is the
6
+ * `applicationKeyId` and the S3 `secretAccessKey` is the
7
+ * `applicationKey`. These are NOT the native `accountId` /
8
+ * `authorizationToken` returned by `b2_authorize_account` — those won't
9
+ * authenticate against the S3 endpoint. Both must be supplied here
10
+ * because `AccountInfo` doesn't retain the application key after
11
+ * authorization for security reasons.
12
+ *
13
+ * @see https://www.backblaze.com/apidocs/s3-compatible-api
14
+ */
15
+ export interface B2S3Config {
16
+ /** The authorized AccountInfo containing the S3 endpoint URL. */
17
+ readonly accountInfo: AccountInfo;
18
+ /** B2 application key ID. Used as the S3 `accessKeyId`. */
19
+ readonly applicationKeyId: string;
20
+ /** B2 application key (secret). Used as the S3 `secretAccessKey`. */
21
+ readonly applicationKey: string;
22
+ /** Override the S3 region. If omitted, extracted from the S3 API URL. */
23
+ readonly region?: string;
24
+ }
25
+ /** Configuration object compatible with `@aws-sdk/client-s3`'s S3Client constructor. */
26
+ export interface S3ClientConfig {
27
+ /** The S3-compatible endpoint URL (e.g., `https://s3.us-west-004.backblazeb2.com`). */
28
+ readonly endpoint: string;
29
+ /** The S3 region identifier (e.g., `us-west-004`). */
30
+ readonly region: string;
31
+ /** AWS-style credentials — the B2 application key pair. */
32
+ readonly credentials: {
33
+ /** The B2 application key ID, used as the S3 access key ID. */
34
+ readonly accessKeyId: string;
35
+ /** The B2 application key (secret), used as the S3 secret access key. */
36
+ readonly secretAccessKey: string;
37
+ };
38
+ /** Always `true` for B2, which requires path-style bucket addressing. */
39
+ readonly forcePathStyle: boolean;
40
+ }
41
+ /**
42
+ * Derives an S3-compatible client configuration from B2 authorization state.
43
+ * Pass the result to `new S3Client(config)` from `@aws-sdk/client-s3`.
44
+ *
45
+ * @param config - B2 auth state, application key credentials, and optional region override.
46
+ *
47
+ * @returns Configuration ready for the AWS S3 SDK.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const { B2_APPLICATION_KEY_ID, B2_APPLICATION_KEY } = process.env
52
+ * if (!B2_APPLICATION_KEY_ID || !B2_APPLICATION_KEY) throw new Error('Missing B2 credentials')
53
+ * const s3 = new S3Client(createS3ClientConfig({
54
+ * accountInfo: client.accountInfo,
55
+ * applicationKeyId: B2_APPLICATION_KEY_ID,
56
+ * applicationKey: B2_APPLICATION_KEY,
57
+ * }))
58
+ * ```
59
+ */
60
+ export declare function createS3ClientConfig(config: B2S3Config): S3ClientConfig;
61
+ /**
62
+ * Constructs a presigned download URL using B2's native download authorization.
63
+ * This is not a standard S3 presigned URL but works for B2 download endpoints.
64
+ *
65
+ * @param downloadUrl - The B2 download URL from authorization (e.g., `https://f004.backblazeb2.com`).
66
+ * @param bucketName - The bucket containing the file.
67
+ * @param fileName - The file name (path) to download.
68
+ * @param authorizationToken - A download authorization token from `b2_get_download_authorization`.
69
+ * @param validDurationInSeconds - URL validity duration in seconds. Defaults to 3600 (1 hour).
70
+ *
71
+ * @returns The presigned download URL string.
72
+ */
73
+ export declare function presignGetObjectUrl(downloadUrl: string, bucketName: string, fileName: string, authorizationToken: string, validDurationInSeconds?: number): string;
74
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/s3/index.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACzB,iEAAiE;IACjE,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,EAAE;QACpB,+DAA+D;QAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;QAC5B,yEAAyE;QACzE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;KACjC,CAAA;IACD,yEAAyE;IACzE,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;CACjC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,CAcvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,MAAM,EAC1B,sBAAsB,SAAO,GAC5B,MAAM,CAGR"}
@@ -0,0 +1,74 @@
1
+ import { AccountInfo } from '../auth/account-info.js';
2
+ /**
3
+ * Configuration for deriving S3-compatible client settings from B2 auth state.
4
+ *
5
+ * Per B2's S3-compatible API contract, the S3 `accessKeyId` is the
6
+ * `applicationKeyId` and the S3 `secretAccessKey` is the
7
+ * `applicationKey`. These are NOT the native `accountId` /
8
+ * `authorizationToken` returned by `b2_authorize_account` — those won't
9
+ * authenticate against the S3 endpoint. Both must be supplied here
10
+ * because `AccountInfo` doesn't retain the application key after
11
+ * authorization for security reasons.
12
+ *
13
+ * @see https://www.backblaze.com/apidocs/s3-compatible-api
14
+ */
15
+ export interface B2S3Config {
16
+ /** The authorized AccountInfo containing the S3 endpoint URL. */
17
+ readonly accountInfo: AccountInfo;
18
+ /** B2 application key ID. Used as the S3 `accessKeyId`. */
19
+ readonly applicationKeyId: string;
20
+ /** B2 application key (secret). Used as the S3 `secretAccessKey`. */
21
+ readonly applicationKey: string;
22
+ /** Override the S3 region. If omitted, extracted from the S3 API URL. */
23
+ readonly region?: string;
24
+ }
25
+ /** Configuration object compatible with `@aws-sdk/client-s3`'s S3Client constructor. */
26
+ export interface S3ClientConfig {
27
+ /** The S3-compatible endpoint URL (e.g., `https://s3.us-west-004.backblazeb2.com`). */
28
+ readonly endpoint: string;
29
+ /** The S3 region identifier (e.g., `us-west-004`). */
30
+ readonly region: string;
31
+ /** AWS-style credentials — the B2 application key pair. */
32
+ readonly credentials: {
33
+ /** The B2 application key ID, used as the S3 access key ID. */
34
+ readonly accessKeyId: string;
35
+ /** The B2 application key (secret), used as the S3 secret access key. */
36
+ readonly secretAccessKey: string;
37
+ };
38
+ /** Always `true` for B2, which requires path-style bucket addressing. */
39
+ readonly forcePathStyle: boolean;
40
+ }
41
+ /**
42
+ * Derives an S3-compatible client configuration from B2 authorization state.
43
+ * Pass the result to `new S3Client(config)` from `@aws-sdk/client-s3`.
44
+ *
45
+ * @param config - B2 auth state, application key credentials, and optional region override.
46
+ *
47
+ * @returns Configuration ready for the AWS S3 SDK.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const { B2_APPLICATION_KEY_ID, B2_APPLICATION_KEY } = process.env
52
+ * if (!B2_APPLICATION_KEY_ID || !B2_APPLICATION_KEY) throw new Error('Missing B2 credentials')
53
+ * const s3 = new S3Client(createS3ClientConfig({
54
+ * accountInfo: client.accountInfo,
55
+ * applicationKeyId: B2_APPLICATION_KEY_ID,
56
+ * applicationKey: B2_APPLICATION_KEY,
57
+ * }))
58
+ * ```
59
+ */
60
+ export declare function createS3ClientConfig(config: B2S3Config): S3ClientConfig;
61
+ /**
62
+ * Constructs a presigned download URL using B2's native download authorization.
63
+ * This is not a standard S3 presigned URL but works for B2 download endpoints.
64
+ *
65
+ * @param downloadUrl - The B2 download URL from authorization (e.g., `https://f004.backblazeb2.com`).
66
+ * @param bucketName - The bucket containing the file.
67
+ * @param fileName - The file name (path) to download.
68
+ * @param authorizationToken - A download authorization token from `b2_get_download_authorization`.
69
+ * @param validDurationInSeconds - URL validity duration in seconds. Defaults to 3600 (1 hour).
70
+ *
71
+ * @returns The presigned download URL string.
72
+ */
73
+ export declare function presignGetObjectUrl(downloadUrl: string, bucketName: string, fileName: string, authorizationToken: string, validDurationInSeconds?: number): string;
74
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/s3/index.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAE1D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACzB,iEAAiE;IACjE,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;IACjC,2DAA2D;IAC3D,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,2DAA2D;IAC3D,QAAQ,CAAC,WAAW,EAAE;QACpB,+DAA+D;QAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;QAC5B,yEAAyE;QACzE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;KACjC,CAAA;IACD,yEAAyE;IACzE,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;CACjC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,CAcvE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,kBAAkB,EAAE,MAAM,EAC1B,sBAAsB,SAAO,GAC5B,MAAM,CAGR"}
@@ -0,0 +1,23 @@
1
+ function createS3ClientConfig(config) {
2
+ const s3Url = config.accountInfo.getS3ApiUrl();
3
+ const regionMatch = s3Url.match(/s3\.([^.]+)\.backblazeb2\.com/);
4
+ const region = config.region ?? regionMatch?.[1] ?? "us-west-004";
5
+ return {
6
+ endpoint: s3Url,
7
+ region,
8
+ credentials: {
9
+ accessKeyId: config.applicationKeyId,
10
+ secretAccessKey: config.applicationKey
11
+ },
12
+ forcePathStyle: true
13
+ };
14
+ }
15
+ function presignGetObjectUrl(downloadUrl, bucketName, fileName, authorizationToken, validDurationInSeconds = 3600) {
16
+ const expires = Math.floor(Date.now() / 1e3) + validDurationInSeconds;
17
+ return `${downloadUrl}/file/${encodeURIComponent(bucketName)}/${encodeURIComponent(fileName)}?Authorization=${encodeURIComponent(authorizationToken)}&expires=${expires}`;
18
+ }
19
+ export {
20
+ createS3ClientConfig,
21
+ presignGetObjectUrl
22
+ };
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/s3/index.ts"],"sourcesContent":["/**\n * S3-compatible helpers for using B2 with the AWS SDK.\n *\n * Provides {@link createS3ClientConfig} to derive endpoint, region, and\n * credentials from B2 authorization state, plus {@link presignGetObjectUrl}\n * for generating download URLs using B2 native download authorization.\n *\n * @packageDocumentation\n */\n\nimport type { AccountInfo } from '../auth/account-info.ts'\n\n/**\n * Configuration for deriving S3-compatible client settings from B2 auth state.\n *\n * Per B2's S3-compatible API contract, the S3 `accessKeyId` is the\n * `applicationKeyId` and the S3 `secretAccessKey` is the\n * `applicationKey`. These are NOT the native `accountId` /\n * `authorizationToken` returned by `b2_authorize_account` — those won't\n * authenticate against the S3 endpoint. Both must be supplied here\n * because `AccountInfo` doesn't retain the application key after\n * authorization for security reasons.\n *\n * @see https://www.backblaze.com/apidocs/s3-compatible-api\n */\nexport interface B2S3Config {\n /** The authorized AccountInfo containing the S3 endpoint URL. */\n readonly accountInfo: AccountInfo\n /** B2 application key ID. Used as the S3 `accessKeyId`. */\n readonly applicationKeyId: string\n /** B2 application key (secret). Used as the S3 `secretAccessKey`. */\n readonly applicationKey: string\n /** Override the S3 region. If omitted, extracted from the S3 API URL. */\n readonly region?: string\n}\n\n/** Configuration object compatible with `@aws-sdk/client-s3`'s S3Client constructor. */\nexport interface S3ClientConfig {\n /** The S3-compatible endpoint URL (e.g., `https://s3.us-west-004.backblazeb2.com`). */\n readonly endpoint: string\n /** The S3 region identifier (e.g., `us-west-004`). */\n readonly region: string\n /** AWS-style credentials — the B2 application key pair. */\n readonly credentials: {\n /** The B2 application key ID, used as the S3 access key ID. */\n readonly accessKeyId: string\n /** The B2 application key (secret), used as the S3 secret access key. */\n readonly secretAccessKey: string\n }\n /** Always `true` for B2, which requires path-style bucket addressing. */\n readonly forcePathStyle: boolean\n}\n\n/**\n * Derives an S3-compatible client configuration from B2 authorization state.\n * Pass the result to `new S3Client(config)` from `@aws-sdk/client-s3`.\n *\n * @param config - B2 auth state, application key credentials, and optional region override.\n *\n * @returns Configuration ready for the AWS S3 SDK.\n *\n * @example\n * ```ts\n * const { B2_APPLICATION_KEY_ID, B2_APPLICATION_KEY } = process.env\n * if (!B2_APPLICATION_KEY_ID || !B2_APPLICATION_KEY) throw new Error('Missing B2 credentials')\n * const s3 = new S3Client(createS3ClientConfig({\n * accountInfo: client.accountInfo,\n * applicationKeyId: B2_APPLICATION_KEY_ID,\n * applicationKey: B2_APPLICATION_KEY,\n * }))\n * ```\n */\nexport function createS3ClientConfig(config: B2S3Config): S3ClientConfig {\n const s3Url = config.accountInfo.getS3ApiUrl()\n const regionMatch = s3Url.match(/s3\\.([^.]+)\\.backblazeb2\\.com/)\n const region = config.region ?? regionMatch?.[1] ?? 'us-west-004'\n\n return {\n endpoint: s3Url,\n region,\n credentials: {\n accessKeyId: config.applicationKeyId,\n secretAccessKey: config.applicationKey,\n },\n forcePathStyle: true,\n }\n}\n\n/**\n * Constructs a presigned download URL using B2's native download authorization.\n * This is not a standard S3 presigned URL but works for B2 download endpoints.\n *\n * @param downloadUrl - The B2 download URL from authorization (e.g., `https://f004.backblazeb2.com`).\n * @param bucketName - The bucket containing the file.\n * @param fileName - The file name (path) to download.\n * @param authorizationToken - A download authorization token from `b2_get_download_authorization`.\n * @param validDurationInSeconds - URL validity duration in seconds. Defaults to 3600 (1 hour).\n *\n * @returns The presigned download URL string.\n */\nexport function presignGetObjectUrl(\n downloadUrl: string,\n bucketName: string,\n fileName: string,\n authorizationToken: string,\n validDurationInSeconds = 3600,\n): string {\n const expires = Math.floor(Date.now() / 1000) + validDurationInSeconds\n return `${downloadUrl}/file/${encodeURIComponent(bucketName)}/${encodeURIComponent(fileName)}?Authorization=${encodeURIComponent(authorizationToken)}&expires=${expires}`\n}\n"],"names":[],"mappings":"AAwEO,SAAS,qBAAqB,QAAoC;AACvE,QAAM,QAAQ,OAAO,YAAY,YAAA;AACjC,QAAM,cAAc,MAAM,MAAM,+BAA+B;AAC/D,QAAM,SAAS,OAAO,UAAU,cAAc,CAAC,KAAK;AAEpD,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,IACA,aAAa;AAAA,MACX,aAAa,OAAO;AAAA,MACpB,iBAAiB,OAAO;AAAA,IAAA;AAAA,IAE1B,gBAAgB;AAAA,EAAA;AAEpB;AAcO,SAAS,oBACd,aACA,YACA,UACA,oBACA,yBAAyB,MACjB;AACR,QAAM,UAAU,KAAK,MAAM,KAAK,IAAA,IAAQ,GAAI,IAAI;AAChD,SAAO,GAAG,WAAW,SAAS,mBAAmB,UAAU,CAAC,IAAI,mBAAmB,QAAQ,CAAC,kBAAkB,mBAAmB,kBAAkB,CAAC,YAAY,OAAO;AACzK;"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const auth = require("../types/auth.cjs");
4
+ const ENDPOINT_CAPABILITIES = {
5
+ // Auth endpoint takes credentials, not an auth token — no cap check.
6
+ b2_authorize_account: [],
7
+ // Bucket management.
8
+ b2_create_bucket: [auth.Capability.WriteBuckets],
9
+ b2_delete_bucket: [auth.Capability.DeleteBuckets],
10
+ b2_update_bucket: [auth.Capability.WriteBuckets],
11
+ b2_list_buckets: [auth.Capability.ListBuckets],
12
+ // File upload + URL acquisition.
13
+ b2_get_upload_url: [auth.Capability.WriteFiles],
14
+ b2_get_upload_part_url: [auth.Capability.WriteFiles],
15
+ b2_upload_file: [auth.Capability.WriteFiles],
16
+ b2_upload_part: [auth.Capability.WriteFiles],
17
+ b2_start_large_file: [auth.Capability.WriteFiles],
18
+ b2_finish_large_file: [auth.Capability.WriteFiles],
19
+ b2_cancel_large_file: [auth.Capability.WriteFiles],
20
+ b2_copy_file: [auth.Capability.WriteFiles],
21
+ b2_copy_part: [auth.Capability.WriteFiles],
22
+ // File listing + reading.
23
+ b2_list_file_names: [auth.Capability.ListFiles],
24
+ b2_list_file_versions: [auth.Capability.ListFiles],
25
+ b2_list_unfinished_large_files: [auth.Capability.ListFiles],
26
+ b2_list_parts: [auth.Capability.ListFiles],
27
+ b2_get_file_info: [auth.Capability.ReadFiles],
28
+ b2_download_file_by_id: [auth.Capability.ReadFiles],
29
+ b2_download_file_by_name: [auth.Capability.ReadFiles],
30
+ // File mutations.
31
+ b2_hide_file: [auth.Capability.WriteFiles],
32
+ b2_delete_file_version: [auth.Capability.DeleteFiles],
33
+ // Object lock + legal hold.
34
+ b2_update_file_retention: [auth.Capability.WriteFileRetentions],
35
+ b2_update_file_legal_hold: [auth.Capability.WriteFileLegalHolds],
36
+ // Application keys.
37
+ b2_create_key: [auth.Capability.WriteKeys],
38
+ b2_list_keys: [auth.Capability.ListKeys],
39
+ b2_delete_key: [auth.Capability.DeleteKeys],
40
+ // Download authorisation.
41
+ b2_get_download_authorization: [auth.Capability.ShareFiles],
42
+ // Notification rules.
43
+ b2_get_bucket_notification_rules: [auth.Capability.ReadBucketNotifications],
44
+ b2_set_bucket_notification_rules: [auth.Capability.WriteBucketNotifications]
45
+ };
46
+ function missingCapabilitiesFor(endpoint, granted) {
47
+ const required = ENDPOINT_CAPABILITIES[endpoint] ?? [];
48
+ const grantedSet = new Set(granted);
49
+ return required.filter((cap) => !grantedSet.has(cap));
50
+ }
51
+ exports.ENDPOINT_CAPABILITIES = ENDPOINT_CAPABILITIES;
52
+ exports.missingCapabilitiesFor = missingCapabilitiesFor;
53
+ //# sourceMappingURL=capabilities.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.cjs","sources":["../../src/simulator/capabilities.ts"],"sourcesContent":["/**\n * Capability requirement table mapping each B2 native API endpoint to\n * the capability (or capabilities — usually one) the caller's\n * application key must hold to invoke it. Used by `B2Simulator` when\n * `strictAuth: true` is set, so test code that exercises a restricted\n * key sees the same `403 unauthorized` response real B2 would return.\n *\n * Source: https://www.backblaze.com/apidocs (each endpoint page lists\n * the required capability in its description).\n *\n * @packageDocumentation\n */\n\nimport { Capability } from '../types/auth.ts'\n\n/** Endpoint → required capability(s). An empty array means \"no capability check\". */\nexport const ENDPOINT_CAPABILITIES: Record<string, readonly Capability[]> = {\n // Auth endpoint takes credentials, not an auth token — no cap check.\n b2_authorize_account: [],\n // Bucket management.\n b2_create_bucket: [Capability.WriteBuckets],\n b2_delete_bucket: [Capability.DeleteBuckets],\n b2_update_bucket: [Capability.WriteBuckets],\n b2_list_buckets: [Capability.ListBuckets],\n // File upload + URL acquisition.\n b2_get_upload_url: [Capability.WriteFiles],\n b2_get_upload_part_url: [Capability.WriteFiles],\n b2_upload_file: [Capability.WriteFiles],\n b2_upload_part: [Capability.WriteFiles],\n b2_start_large_file: [Capability.WriteFiles],\n b2_finish_large_file: [Capability.WriteFiles],\n b2_cancel_large_file: [Capability.WriteFiles],\n b2_copy_file: [Capability.WriteFiles],\n b2_copy_part: [Capability.WriteFiles],\n // File listing + reading.\n b2_list_file_names: [Capability.ListFiles],\n b2_list_file_versions: [Capability.ListFiles],\n b2_list_unfinished_large_files: [Capability.ListFiles],\n b2_list_parts: [Capability.ListFiles],\n b2_get_file_info: [Capability.ReadFiles],\n b2_download_file_by_id: [Capability.ReadFiles],\n b2_download_file_by_name: [Capability.ReadFiles],\n // File mutations.\n b2_hide_file: [Capability.WriteFiles],\n b2_delete_file_version: [Capability.DeleteFiles],\n // Object lock + legal hold.\n b2_update_file_retention: [Capability.WriteFileRetentions],\n b2_update_file_legal_hold: [Capability.WriteFileLegalHolds],\n // Application keys.\n b2_create_key: [Capability.WriteKeys],\n b2_list_keys: [Capability.ListKeys],\n b2_delete_key: [Capability.DeleteKeys],\n // Download authorisation.\n b2_get_download_authorization: [Capability.ShareFiles],\n // Notification rules.\n b2_get_bucket_notification_rules: [Capability.ReadBucketNotifications],\n b2_set_bucket_notification_rules: [Capability.WriteBucketNotifications],\n}\n\n/**\n * Find which capabilities are missing from the caller's grant set\n * relative to the endpoint requirement.\n *\n * @param endpoint - B2 endpoint name (e.g. `'b2_upload_file'`).\n * @param granted - Capabilities the caller's key has.\n *\n * @returns The subset of required capabilities that the caller is\n * missing. Empty array means \"request authorized\".\n */\nexport function missingCapabilitiesFor(\n endpoint: string,\n granted: readonly Capability[],\n): readonly Capability[] {\n const required = ENDPOINT_CAPABILITIES[endpoint] ?? []\n const grantedSet = new Set(granted)\n return required.filter((cap) => !grantedSet.has(cap))\n}\n"],"names":["Capability"],"mappings":";;;AAgBO,MAAM,wBAA+D;AAAA;AAAA,EAE1E,sBAAsB,CAAA;AAAA;AAAA,EAEtB,kBAAkB,CAACA,KAAAA,WAAW,YAAY;AAAA,EAC1C,kBAAkB,CAACA,KAAAA,WAAW,aAAa;AAAA,EAC3C,kBAAkB,CAACA,KAAAA,WAAW,YAAY;AAAA,EAC1C,iBAAiB,CAACA,KAAAA,WAAW,WAAW;AAAA;AAAA,EAExC,mBAAmB,CAACA,KAAAA,WAAW,UAAU;AAAA,EACzC,wBAAwB,CAACA,KAAAA,WAAW,UAAU;AAAA,EAC9C,gBAAgB,CAACA,KAAAA,WAAW,UAAU;AAAA,EACtC,gBAAgB,CAACA,KAAAA,WAAW,UAAU;AAAA,EACtC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@@ -0,0 +1,15 @@
1
+ import { Capability } from '../types/auth.js';
2
+ /** Endpoint → required capability(s). An empty array means "no capability check". */
3
+ export declare const ENDPOINT_CAPABILITIES: Record<string, readonly Capability[]>;
4
+ /**
5
+ * Find which capabilities are missing from the caller's grant set
6
+ * relative to the endpoint requirement.
7
+ *
8
+ * @param endpoint - B2 endpoint name (e.g. `'b2_upload_file'`).
9
+ * @param granted - Capabilities the caller's key has.
10
+ *
11
+ * @returns The subset of required capabilities that the caller is
12
+ * missing. Empty array means "request authorized".
13
+ */
14
+ export declare function missingCapabilitiesFor(endpoint: string, granted: readonly Capability[]): readonly Capability[];
15
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/simulator/capabilities.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,qFAAqF;AACrF,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAyCvE,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,UAAU,EAAE,GAC7B,SAAS,UAAU,EAAE,CAIvB"}
@@ -0,0 +1,15 @@
1
+ import { Capability } from '../types/auth.js';
2
+ /** Endpoint → required capability(s). An empty array means "no capability check". */
3
+ export declare const ENDPOINT_CAPABILITIES: Record<string, readonly Capability[]>;
4
+ /**
5
+ * Find which capabilities are missing from the caller's grant set
6
+ * relative to the endpoint requirement.
7
+ *
8
+ * @param endpoint - B2 endpoint name (e.g. `'b2_upload_file'`).
9
+ * @param granted - Capabilities the caller's key has.
10
+ *
11
+ * @returns The subset of required capabilities that the caller is
12
+ * missing. Empty array means "request authorized".
13
+ */
14
+ export declare function missingCapabilitiesFor(endpoint: string, granted: readonly Capability[]): readonly Capability[];
15
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/simulator/capabilities.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,qFAAqF;AACrF,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,CAyCvE,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,SAAS,UAAU,EAAE,GAC7B,SAAS,UAAU,EAAE,CAIvB"}
@@ -0,0 +1,53 @@
1
+ import { Capability } from "../types/auth.js";
2
+ const ENDPOINT_CAPABILITIES = {
3
+ // Auth endpoint takes credentials, not an auth token — no cap check.
4
+ b2_authorize_account: [],
5
+ // Bucket management.
6
+ b2_create_bucket: [Capability.WriteBuckets],
7
+ b2_delete_bucket: [Capability.DeleteBuckets],
8
+ b2_update_bucket: [Capability.WriteBuckets],
9
+ b2_list_buckets: [Capability.ListBuckets],
10
+ // File upload + URL acquisition.
11
+ b2_get_upload_url: [Capability.WriteFiles],
12
+ b2_get_upload_part_url: [Capability.WriteFiles],
13
+ b2_upload_file: [Capability.WriteFiles],
14
+ b2_upload_part: [Capability.WriteFiles],
15
+ b2_start_large_file: [Capability.WriteFiles],
16
+ b2_finish_large_file: [Capability.WriteFiles],
17
+ b2_cancel_large_file: [Capability.WriteFiles],
18
+ b2_copy_file: [Capability.WriteFiles],
19
+ b2_copy_part: [Capability.WriteFiles],
20
+ // File listing + reading.
21
+ b2_list_file_names: [Capability.ListFiles],
22
+ b2_list_file_versions: [Capability.ListFiles],
23
+ b2_list_unfinished_large_files: [Capability.ListFiles],
24
+ b2_list_parts: [Capability.ListFiles],
25
+ b2_get_file_info: [Capability.ReadFiles],
26
+ b2_download_file_by_id: [Capability.ReadFiles],
27
+ b2_download_file_by_name: [Capability.ReadFiles],
28
+ // File mutations.
29
+ b2_hide_file: [Capability.WriteFiles],
30
+ b2_delete_file_version: [Capability.DeleteFiles],
31
+ // Object lock + legal hold.
32
+ b2_update_file_retention: [Capability.WriteFileRetentions],
33
+ b2_update_file_legal_hold: [Capability.WriteFileLegalHolds],
34
+ // Application keys.
35
+ b2_create_key: [Capability.WriteKeys],
36
+ b2_list_keys: [Capability.ListKeys],
37
+ b2_delete_key: [Capability.DeleteKeys],
38
+ // Download authorisation.
39
+ b2_get_download_authorization: [Capability.ShareFiles],
40
+ // Notification rules.
41
+ b2_get_bucket_notification_rules: [Capability.ReadBucketNotifications],
42
+ b2_set_bucket_notification_rules: [Capability.WriteBucketNotifications]
43
+ };
44
+ function missingCapabilitiesFor(endpoint, granted) {
45
+ const required = ENDPOINT_CAPABILITIES[endpoint] ?? [];
46
+ const grantedSet = new Set(granted);
47
+ return required.filter((cap) => !grantedSet.has(cap));
48
+ }
49
+ export {
50
+ ENDPOINT_CAPABILITIES,
51
+ missingCapabilitiesFor
52
+ };
53
+ //# sourceMappingURL=capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.js","sources":["../../src/simulator/capabilities.ts"],"sourcesContent":["/**\n * Capability requirement table mapping each B2 native API endpoint to\n * the capability (or capabilities — usually one) the caller's\n * application key must hold to invoke it. Used by `B2Simulator` when\n * `strictAuth: true` is set, so test code that exercises a restricted\n * key sees the same `403 unauthorized` response real B2 would return.\n *\n * Source: https://www.backblaze.com/apidocs (each endpoint page lists\n * the required capability in its description).\n *\n * @packageDocumentation\n */\n\nimport { Capability } from '../types/auth.ts'\n\n/** Endpoint → required capability(s). An empty array means \"no capability check\". */\nexport const ENDPOINT_CAPABILITIES: Record<string, readonly Capability[]> = {\n // Auth endpoint takes credentials, not an auth token — no cap check.\n b2_authorize_account: [],\n // Bucket management.\n b2_create_bucket: [Capability.WriteBuckets],\n b2_delete_bucket: [Capability.DeleteBuckets],\n b2_update_bucket: [Capability.WriteBuckets],\n b2_list_buckets: [Capability.ListBuckets],\n // File upload + URL acquisition.\n b2_get_upload_url: [Capability.WriteFiles],\n b2_get_upload_part_url: [Capability.WriteFiles],\n b2_upload_file: [Capability.WriteFiles],\n b2_upload_part: [Capability.WriteFiles],\n b2_start_large_file: [Capability.WriteFiles],\n b2_finish_large_file: [Capability.WriteFiles],\n b2_cancel_large_file: [Capability.WriteFiles],\n b2_copy_file: [Capability.WriteFiles],\n b2_copy_part: [Capability.WriteFiles],\n // File listing + reading.\n b2_list_file_names: [Capability.ListFiles],\n b2_list_file_versions: [Capability.ListFiles],\n b2_list_unfinished_large_files: [Capability.ListFiles],\n b2_list_parts: [Capability.ListFiles],\n b2_get_file_info: [Capability.ReadFiles],\n b2_download_file_by_id: [Capability.ReadFiles],\n b2_download_file_by_name: [Capability.ReadFiles],\n // File mutations.\n b2_hide_file: [Capability.WriteFiles],\n b2_delete_file_version: [Capability.DeleteFiles],\n // Object lock + legal hold.\n b2_update_file_retention: [Capability.WriteFileRetentions],\n b2_update_file_legal_hold: [Capability.WriteFileLegalHolds],\n // Application keys.\n b2_create_key: [Capability.WriteKeys],\n b2_list_keys: [Capability.ListKeys],\n b2_delete_key: [Capability.DeleteKeys],\n // Download authorisation.\n b2_get_download_authorization: [Capability.ShareFiles],\n // Notification rules.\n b2_get_bucket_notification_rules: [Capability.ReadBucketNotifications],\n b2_set_bucket_notification_rules: [Capability.WriteBucketNotifications],\n}\n\n/**\n * Find which capabilities are missing from the caller's grant set\n * relative to the endpoint requirement.\n *\n * @param endpoint - B2 endpoint name (e.g. `'b2_upload_file'`).\n * @param granted - Capabilities the caller's key has.\n *\n * @returns The subset of required capabilities that the caller is\n * missing. Empty array means \"request authorized\".\n */\nexport function missingCapabilitiesFor(\n endpoint: string,\n granted: readonly Capability[],\n): readonly Capability[] {\n const required = ENDPOINT_CAPABILITIES[endpoint] ?? []\n const grantedSet = new Set(granted)\n return required.filter((cap) => !grantedSet.has(cap))\n}\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