@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,264 @@
1
+ import { B2ErrorCode, B2ErrorResponse } from '../types/errors.js';
2
+ /**
3
+ * Base error class for all B2 API errors.
4
+ * Contains the HTTP status, B2 error code, and retry metadata from the response.
5
+ */
6
+ export declare class B2Error extends Error {
7
+ /** HTTP status code returned by the B2 API. */
8
+ readonly status: number;
9
+ /** B2 error code identifying the error type (e.g. `expired_auth_token`). */
10
+ readonly code: B2ErrorCode;
11
+ /** B2 request ID from the `X-Bz-Request-Id` response header, if present. */
12
+ readonly requestId?: string;
13
+ /** Retry delay in seconds from the `Retry-After` response header, if present. */
14
+ readonly retryAfter?: number;
15
+ /** Whether this error is transient and the request can be retried. */
16
+ readonly retryable: boolean;
17
+ /**
18
+ * Creates a new B2Error instance.
19
+ * @param response - Parsed B2 error response body.
20
+ * @param options - Optional retry and request metadata from response headers.
21
+ */
22
+ constructor(response: B2ErrorResponse, options?: {
23
+ retryAfter?: number;
24
+ requestId?: string;
25
+ });
26
+ }
27
+ /** Thrown when the auth token has expired. Triggers automatic re-authorization. */
28
+ export declare class ExpiredAuthTokenError extends B2Error {
29
+ /**
30
+ * Creates a new ExpiredAuthTokenError instance.
31
+ * @param response - Parsed B2 error response body.
32
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
33
+ */
34
+ constructor(response: B2ErrorResponse, options?: {
35
+ requestId?: string;
36
+ });
37
+ }
38
+ /** Thrown when the auth token is invalid or unauthorized. */
39
+ export declare class BadAuthTokenError extends B2Error {
40
+ /**
41
+ * Creates a new BadAuthTokenError instance.
42
+ * @param response - Parsed B2 error response body.
43
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
44
+ */
45
+ constructor(response: B2ErrorResponse, options?: {
46
+ requestId?: string;
47
+ });
48
+ }
49
+ /** Thrown when the B2 service is temporarily unavailable (HTTP 503). */
50
+ export declare class ServiceUnavailableError extends B2Error {
51
+ /**
52
+ * Creates a new ServiceUnavailableError instance.
53
+ * @param response - Parsed B2 error response body.
54
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
55
+ */
56
+ constructor(response: B2ErrorResponse, options?: {
57
+ retryAfter?: number;
58
+ requestId?: string;
59
+ });
60
+ }
61
+ /** Thrown when a request times out on the server side (HTTP 408). */
62
+ export declare class RequestTimeoutError extends B2Error {
63
+ /**
64
+ * Creates a new RequestTimeoutError instance.
65
+ * @param response - Parsed B2 error response body.
66
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
67
+ */
68
+ constructor(response: B2ErrorResponse, options?: {
69
+ requestId?: string;
70
+ });
71
+ }
72
+ /** Thrown when the client has sent too many requests (HTTP 429). */
73
+ export declare class TooManyRequestsError extends B2Error {
74
+ /**
75
+ * Creates a new TooManyRequestsError instance.
76
+ * @param response - Parsed B2 error response body.
77
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
78
+ */
79
+ constructor(response: B2ErrorResponse, options?: {
80
+ retryAfter?: number;
81
+ requestId?: string;
82
+ });
83
+ }
84
+ /** Thrown when a storage, transaction, or download cap has been exceeded. */
85
+ export declare class CapExceededError extends B2Error {
86
+ /**
87
+ * Creates a new CapExceededError instance.
88
+ * @param response - Parsed B2 error response body.
89
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
90
+ */
91
+ constructor(response: B2ErrorResponse, options?: {
92
+ requestId?: string;
93
+ });
94
+ }
95
+ /** Thrown when the application key does not have permission for the requested operation. */
96
+ export declare class AccessDeniedError extends B2Error {
97
+ /**
98
+ * Creates a new AccessDeniedError instance.
99
+ * @param response - Parsed B2 error response body.
100
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
101
+ */
102
+ constructor(response: B2ErrorResponse, options?: {
103
+ requestId?: string;
104
+ });
105
+ }
106
+ /** Thrown when the requested file does not exist. */
107
+ export declare class FileNotPresentError extends B2Error {
108
+ /**
109
+ * Creates a new FileNotPresentError instance.
110
+ * @param response - Parsed B2 error response body.
111
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
112
+ */
113
+ constructor(response: B2ErrorResponse, options?: {
114
+ requestId?: string;
115
+ });
116
+ }
117
+ /** Thrown when creating a bucket with a name that already exists in the account. */
118
+ export declare class DuplicateBucketNameError extends B2Error {
119
+ /**
120
+ * Creates a new DuplicateBucketNameError instance.
121
+ * @param response - Parsed B2 error response body.
122
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
123
+ */
124
+ constructor(response: B2ErrorResponse, options?: {
125
+ requestId?: string;
126
+ });
127
+ }
128
+ /** Thrown for general bad request errors (HTTP 400) not covered by a more specific subclass. */
129
+ export declare class BadRequestError extends B2Error {
130
+ /**
131
+ * Creates a new BadRequestError instance.
132
+ * @param response - Parsed B2 error response body.
133
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
134
+ */
135
+ constructor(response: B2ErrorResponse, options?: {
136
+ requestId?: string;
137
+ });
138
+ }
139
+ /**
140
+ * Thrown when an upload URL is no longer valid and must be refreshed.
141
+ *
142
+ * Forward-compat insurance: B2 does not currently surface a distinct
143
+ * error code for this case, so {@link classifyError} never actually
144
+ * instantiates this class today. It's part of the public API so
145
+ * consumers can pre-write `instanceof` checks; when B2 documents a
146
+ * `bad_upload_url` (or similar) error code, the `classifyError`
147
+ * switch gets a matching case and existing consumer code starts
148
+ * catching the typed error without any changes on their side.
149
+ *
150
+ * Until then, expect `BadRequestError` for upload-URL invalidation
151
+ * scenarios — that's what B2 currently returns.
152
+ */
153
+ export declare class BadUploadUrlError extends B2Error {
154
+ /**
155
+ * Creates a new BadUploadUrlError instance.
156
+ * @param response - Parsed B2 error response body.
157
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
158
+ */
159
+ constructor(response: B2ErrorResponse, options?: {
160
+ requestId?: string;
161
+ });
162
+ }
163
+ /**
164
+ * Thrown when the uploaded file's SHA-1 checksum does not match the
165
+ * expected value.
166
+ *
167
+ * Forward-compat insurance: the B2 API currently rejects mismatched
168
+ * uploads with a generic `bad_request` code, so {@link classifyError}
169
+ * never actually instantiates this class today. It's part of the
170
+ * public API so consumers can pre-write `instanceof` checks; when B2
171
+ * documents a dedicated checksum-mismatch code, the `classifyError`
172
+ * switch gets a matching case and existing consumer code starts
173
+ * catching the typed error without any changes on their side.
174
+ *
175
+ * Until then, expect `BadRequestError` for SHA-1 mismatch scenarios.
176
+ */
177
+ export declare class ChecksumMismatchError extends B2Error {
178
+ /**
179
+ * Creates a new ChecksumMismatchError instance.
180
+ * @param response - Parsed B2 error response body.
181
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
182
+ */
183
+ constructor(response: B2ErrorResponse, options?: {
184
+ requestId?: string;
185
+ });
186
+ }
187
+ /**
188
+ * Thrown by client-side capability checks when the application key is missing
189
+ * capabilities required by an operation. Not raised by the server.
190
+ */
191
+ export declare class B2InsufficientCapabilityError extends Error {
192
+ /** Capabilities that were required for the operation. */
193
+ readonly required: readonly string[];
194
+ /** Capabilities that the current key actually has. */
195
+ readonly available: readonly string[];
196
+ /** Capabilities present in `required` but not in `available`. */
197
+ readonly missing: readonly string[];
198
+ /**
199
+ * Creates a new B2InsufficientCapabilityError instance.
200
+ *
201
+ * @param required - Capabilities the operation requires.
202
+ * @param available - Capabilities the current key holds.
203
+ * @param missing - The subset of required that isn't available.
204
+ */
205
+ constructor(required: readonly string[], available: readonly string[], missing: readonly string[]);
206
+ }
207
+ /**
208
+ * Thrown when the SDK is asked to fetch a URL whose host is outside the
209
+ * authorized B2 realm. Defense against SSRF / URL-substitution attacks where
210
+ * a compromised or hostile B2 endpoint returns an upload URL pointing at an
211
+ * internal service (e.g. cloud metadata at `169.254.169.254`).
212
+ *
213
+ * Not retryable.
214
+ */
215
+ export declare class B2SsrfError extends Error {
216
+ /** The full URL that was rejected. */
217
+ readonly url: string;
218
+ /** Always `false` — this is a security failure, not transient. */
219
+ readonly retryable = false;
220
+ /**
221
+ * Creates a new {@link B2SsrfError}.
222
+ *
223
+ * @param message - Human-readable description of which URL was rejected and why.
224
+ * @param url - The full URL that was rejected.
225
+ */
226
+ constructor(message: string,
227
+ /** The full URL that was rejected. */
228
+ url: string);
229
+ }
230
+ /** Thrown when a network-level failure occurs (DNS, TCP, TLS). Always retryable. */
231
+ export declare class NetworkError extends Error {
232
+ readonly cause?: unknown | undefined;
233
+ /** Always `true` since network errors are transient. */
234
+ readonly retryable = true;
235
+ /**
236
+ * Creates a new NetworkError instance.
237
+ * @param message - Human-readable description of the network failure.
238
+ * @param cause - The underlying error that caused this failure, if any.
239
+ */
240
+ constructor(message: string, cause?: unknown | undefined);
241
+ }
242
+ /**
243
+ * Maps a B2 error response to the appropriate {@link B2Error} subclass.
244
+ * Uses the error code for exact matching, then falls back to HTTP status codes.
245
+ *
246
+ * Maintainer note: when B2 documents a new error code, add a `case`
247
+ * branch below pointing at the matching {@link B2Error} subclass. Unknown
248
+ * codes fall through to the HTTP-status-based heuristic and finally to a
249
+ * generic `B2Error` — that's safe but loses semantic specificity (the
250
+ * caller can't `instanceof` against a precise subclass and the retry
251
+ * decision relies on status alone). The `B2ErrorCode` union in
252
+ * `src/types/errors.ts` should also gain the new code at the same time
253
+ * so the switch is exhaustive again.
254
+ *
255
+ * @param response - Parsed B2 error response body.
256
+ * @param options - Optional retry and request metadata from response headers.
257
+ *
258
+ * @returns A typed B2Error subclass instance.
259
+ */
260
+ export declare function classifyError(response: B2ErrorResponse, options?: {
261
+ retryAfter?: number;
262
+ requestId?: string;
263
+ }): B2Error;
264
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEtE;;;GAGG;AACH,qBAAa,OAAQ,SAAQ,KAAK;IAChC,+CAA+C;IAC/C,QAAQ,CAAC,M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;KAAE;CAIxE;AAED;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;IACtD,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;IACrC,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;IAEnC;;;;;;OAMG;gBAED,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,OAAO,EAAE,SAAS,MAAM,EAAE;CAQ7B;AAED;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAYlC,sCAAsC;aACtB,GAAG,EAAE,MAAM;IAZ7B,kEAAkE;IAClE,QAAQ,CAAC,SAAS,SAAQ;IAE1B;;;;;OAKG;gBAED,OAAO,EAAE,MAAM;IACf,sCAAsC;IACtB,GAAG,EAAE,MAAM;CAK9B;AAED,oFAAoF;AACpF,qBAAa,YAAa,SAAQ,KAAK;aAWV,KAAK,CAAC,EAAE,OAAO;IAV1C,wDAAwD;IACxD,QAAQ,CAAC,SAAS,QAAO;IAEzB;;;;OAIG;gBAED,OAAO,EAAE,MAAM,EACU,KAAK,CAAC,EAAE,OAAO,YAAA;CAK3C;AASD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,eAAe,EACzB,OAAO,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACpD,OAAO,CAoCT"}
@@ -0,0 +1,268 @@
1
+ class B2Error extends Error {
2
+ /** HTTP status code returned by the B2 API. */
3
+ status;
4
+ /** B2 error code identifying the error type (e.g. `expired_auth_token`). */
5
+ code;
6
+ /** B2 request ID from the `X-Bz-Request-Id` response header, if present. */
7
+ requestId;
8
+ /** Retry delay in seconds from the `Retry-After` response header, if present. */
9
+ retryAfter;
10
+ /** Whether this error is transient and the request can be retried. */
11
+ retryable;
12
+ /**
13
+ * Creates a new B2Error instance.
14
+ * @param response - Parsed B2 error response body.
15
+ * @param options - Optional retry and request metadata from response headers.
16
+ */
17
+ constructor(response, options) {
18
+ super(response.message);
19
+ this.name = "B2Error";
20
+ this.status = response.status;
21
+ this.code = response.code;
22
+ if (options?.retryAfter !== void 0) this.retryAfter = options.retryAfter;
23
+ if (options?.requestId !== void 0) this.requestId = options.requestId;
24
+ this.retryable = isTransient(response.status, response.code);
25
+ }
26
+ }
27
+ class ExpiredAuthTokenError extends B2Error {
28
+ /**
29
+ * Creates a new ExpiredAuthTokenError instance.
30
+ * @param response - Parsed B2 error response body.
31
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
32
+ */
33
+ constructor(response, options) {
34
+ super(response, options);
35
+ this.name = "ExpiredAuthTokenError";
36
+ }
37
+ }
38
+ class BadAuthTokenError extends B2Error {
39
+ /**
40
+ * Creates a new BadAuthTokenError instance.
41
+ * @param response - Parsed B2 error response body.
42
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
43
+ */
44
+ constructor(response, options) {
45
+ super(response, options);
46
+ this.name = "BadAuthTokenError";
47
+ }
48
+ }
49
+ class ServiceUnavailableError extends B2Error {
50
+ /**
51
+ * Creates a new ServiceUnavailableError instance.
52
+ * @param response - Parsed B2 error response body.
53
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
54
+ */
55
+ constructor(response, options) {
56
+ super(response, options);
57
+ this.name = "ServiceUnavailableError";
58
+ }
59
+ }
60
+ class RequestTimeoutError extends B2Error {
61
+ /**
62
+ * Creates a new RequestTimeoutError instance.
63
+ * @param response - Parsed B2 error response body.
64
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
65
+ */
66
+ constructor(response, options) {
67
+ super(response, options);
68
+ this.name = "RequestTimeoutError";
69
+ }
70
+ }
71
+ class TooManyRequestsError extends B2Error {
72
+ /**
73
+ * Creates a new TooManyRequestsError instance.
74
+ * @param response - Parsed B2 error response body.
75
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
76
+ */
77
+ constructor(response, options) {
78
+ super(response, options);
79
+ this.name = "TooManyRequestsError";
80
+ }
81
+ }
82
+ class CapExceededError extends B2Error {
83
+ /**
84
+ * Creates a new CapExceededError instance.
85
+ * @param response - Parsed B2 error response body.
86
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
87
+ */
88
+ constructor(response, options) {
89
+ super(response, options);
90
+ this.name = "CapExceededError";
91
+ }
92
+ }
93
+ class AccessDeniedError extends B2Error {
94
+ /**
95
+ * Creates a new AccessDeniedError instance.
96
+ * @param response - Parsed B2 error response body.
97
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
98
+ */
99
+ constructor(response, options) {
100
+ super(response, options);
101
+ this.name = "AccessDeniedError";
102
+ }
103
+ }
104
+ class FileNotPresentError extends B2Error {
105
+ /**
106
+ * Creates a new FileNotPresentError instance.
107
+ * @param response - Parsed B2 error response body.
108
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
109
+ */
110
+ constructor(response, options) {
111
+ super(response, options);
112
+ this.name = "FileNotPresentError";
113
+ }
114
+ }
115
+ class DuplicateBucketNameError extends B2Error {
116
+ /**
117
+ * Creates a new DuplicateBucketNameError instance.
118
+ * @param response - Parsed B2 error response body.
119
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
120
+ */
121
+ constructor(response, options) {
122
+ super(response, options);
123
+ this.name = "DuplicateBucketNameError";
124
+ }
125
+ }
126
+ class BadRequestError extends B2Error {
127
+ /**
128
+ * Creates a new BadRequestError instance.
129
+ * @param response - Parsed B2 error response body.
130
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
131
+ */
132
+ constructor(response, options) {
133
+ super(response, options);
134
+ this.name = "BadRequestError";
135
+ }
136
+ }
137
+ class BadUploadUrlError extends B2Error {
138
+ /**
139
+ * Creates a new BadUploadUrlError instance.
140
+ * @param response - Parsed B2 error response body.
141
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
142
+ */
143
+ constructor(response, options) {
144
+ super(response, options);
145
+ this.name = "BadUploadUrlError";
146
+ }
147
+ }
148
+ class ChecksumMismatchError extends B2Error {
149
+ /**
150
+ * Creates a new ChecksumMismatchError instance.
151
+ * @param response - Parsed B2 error response body.
152
+ * @param options - The error details including HTTP status, error code, message, and optional request ID.
153
+ */
154
+ constructor(response, options) {
155
+ super(response, options);
156
+ this.name = "ChecksumMismatchError";
157
+ }
158
+ }
159
+ class B2InsufficientCapabilityError extends Error {
160
+ /** Capabilities that were required for the operation. */
161
+ required;
162
+ /** Capabilities that the current key actually has. */
163
+ available;
164
+ /** Capabilities present in `required` but not in `available`. */
165
+ missing;
166
+ /**
167
+ * Creates a new B2InsufficientCapabilityError instance.
168
+ *
169
+ * @param required - Capabilities the operation requires.
170
+ * @param available - Capabilities the current key holds.
171
+ * @param missing - The subset of required that isn't available.
172
+ */
173
+ constructor(required, available, missing) {
174
+ super(`Application key is missing capabilities: ${missing.join(", ")}`);
175
+ this.name = "B2InsufficientCapabilityError";
176
+ this.required = required;
177
+ this.available = available;
178
+ this.missing = missing;
179
+ }
180
+ }
181
+ class B2SsrfError extends Error {
182
+ /**
183
+ * Creates a new {@link B2SsrfError}.
184
+ *
185
+ * @param message - Human-readable description of which URL was rejected and why.
186
+ * @param url - The full URL that was rejected.
187
+ */
188
+ constructor(message, url) {
189
+ super(message);
190
+ this.url = url;
191
+ this.name = "B2SsrfError";
192
+ }
193
+ /** Always `false` — this is a security failure, not transient. */
194
+ retryable = false;
195
+ }
196
+ class NetworkError extends Error {
197
+ /**
198
+ * Creates a new NetworkError instance.
199
+ * @param message - Human-readable description of the network failure.
200
+ * @param cause - The underlying error that caused this failure, if any.
201
+ */
202
+ constructor(message, cause) {
203
+ super(message);
204
+ this.cause = cause;
205
+ this.name = "NetworkError";
206
+ }
207
+ /** Always `true` since network errors are transient. */
208
+ retryable = true;
209
+ }
210
+ function isTransient(status, code) {
211
+ if (status === 408 || status === 429 || status === 503) return true;
212
+ if (code === "expired_auth_token") return true;
213
+ if (code === "service_unavailable" || code === "request_timeout") return true;
214
+ return false;
215
+ }
216
+ function classifyError(response, options) {
217
+ switch (response.code) {
218
+ case "expired_auth_token":
219
+ return new ExpiredAuthTokenError(response, options);
220
+ case "bad_auth_token":
221
+ case "unauthorized":
222
+ return new BadAuthTokenError(response, options);
223
+ case "service_unavailable":
224
+ return new ServiceUnavailableError(response, options);
225
+ case "request_timeout":
226
+ return new RequestTimeoutError(response, options);
227
+ case "cap_exceeded":
228
+ case "storage_cap_exceeded":
229
+ case "transaction_cap_exceeded":
230
+ case "download_cap_exceeded":
231
+ return new CapExceededError(response, options);
232
+ case "access_denied":
233
+ return new AccessDeniedError(response, options);
234
+ case "file_not_present":
235
+ case "no_such_file":
236
+ return new FileNotPresentError(response, options);
237
+ case "duplicate_bucket_name":
238
+ return new DuplicateBucketNameError(response, options);
239
+ case "bad_sha1_checksum":
240
+ return new ChecksumMismatchError(response, options);
241
+ case "bad_request":
242
+ return new BadRequestError(response, options);
243
+ }
244
+ if (response.status === 429) return new TooManyRequestsError(response, options);
245
+ if (response.status === 503) return new ServiceUnavailableError(response, options);
246
+ if (response.status === 408) return new RequestTimeoutError(response, options);
247
+ return new B2Error(response, options);
248
+ }
249
+ export {
250
+ AccessDeniedError,
251
+ B2Error,
252
+ B2InsufficientCapabilityError,
253
+ B2SsrfError,
254
+ BadAuthTokenError,
255
+ BadRequestError,
256
+ BadUploadUrlError,
257
+ CapExceededError,
258
+ ChecksumMismatchError,
259
+ DuplicateBucketNameError,
260
+ ExpiredAuthTokenError,
261
+ FileNotPresentError,
262
+ NetworkError,
263
+ RequestTimeoutError,
264
+ ServiceUnavailableError,
265
+ TooManyRequestsError,
266
+ classifyError
267
+ };
268
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/errors/index.ts"],"sourcesContent":["/**\n * Typed error hierarchy for B2 API failures.\n *\n * Every B2 error response is mapped to a specific {@link B2Error} subclass\n * (e.g. {@link ExpiredAuthTokenError}, {@link CapExceededError}) with pre-computed\n * {@link B2Error.retryable | retryable} flags. Use {@link classifyError} to convert\n * a raw error response into the appropriate subclass.\n *\n * Convention: `B2Error` and its subclasses represent failures returned by\n * the B2 API. Programming errors and SDK preconditions (e.g. \"not yet\n * authorized\", \"stream consumed twice\", \"called before init\") use the\n * native `Error` constructor instead. Two outliers extend `Error` directly\n * rather than `B2Error` because they originate inside the SDK before any\n * B2 request is made: {@link B2InsufficientCapabilityError} (raised by\n * `B2Client.hasCapabilities`) and {@link B2SsrfError} (raised by the\n * default `UrlGuard` before `fetch`).\n *\n * @packageDocumentation\n */\n\nimport type { B2ErrorCode, B2ErrorResponse } from '../types/errors.ts'\n\n/**\n * Base error class for all B2 API errors.\n * Contains the HTTP status, B2 error code, and retry metadata from the response.\n */\nexport class B2Error extends Error {\n /** HTTP status code returned by the B2 API. */\n readonly status: number\n /** B2 error code identifying the error type (e.g. `expired_auth_token`). */\n readonly code: B2ErrorCode\n /** B2 request ID from the `X-Bz-Request-Id` response header, if present. */\n readonly requestId?: string\n /** Retry delay in seconds from the `Retry-After` response header, if present. */\n readonly retryAfter?: number\n /** Whether this error is transient and the request can be retried. */\n readonly retryable: boolean\n\n /**\n * Creates a new B2Error instance.\n * @param response - Parsed B2 error response body.\n * @param options - Optional retry and request metadata from response headers.\n */\n constructor(response: B2ErrorResponse, options?: { retryAfter?: number; requestId?: string }) {\n super(response.message)\n this.name = 'B2Error'\n this.status = response.status\n this.code = response.code\n if (options?.retryAfter !== undefined) this.retryAfter = options.retryAfter\n if (options?.requestId !== undefined) this.requestId = options.requestId\n this.retryable = isTransient(response.status, response.code)\n }\n}\n\n/** Thrown when the auth token has expired. Triggers automatic re-authorization. */\nexport class ExpiredAuthTokenError extends B2Error {\n /**\n * Creates a new ExpiredAuthTokenError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'ExpiredAuthTokenError'\n }\n}\n\n/** Thrown when the auth token is invalid or unauthorized. */\nexport class BadAuthTokenError extends B2Error {\n /**\n * Creates a new BadAuthTokenError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'BadAuthTokenError'\n }\n}\n\n/** Thrown when the B2 service is temporarily unavailable (HTTP 503). */\nexport class ServiceUnavailableError extends B2Error {\n /**\n * Creates a new ServiceUnavailableError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { retryAfter?: number; requestId?: string }) {\n super(response, options)\n this.name = 'ServiceUnavailableError'\n }\n}\n\n/** Thrown when a request times out on the server side (HTTP 408). */\nexport class RequestTimeoutError extends B2Error {\n /**\n * Creates a new RequestTimeoutError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'RequestTimeoutError'\n }\n}\n\n/** Thrown when the client has sent too many requests (HTTP 429). */\nexport class TooManyRequestsError extends B2Error {\n /**\n * Creates a new TooManyRequestsError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { retryAfter?: number; requestId?: string }) {\n super(response, options)\n this.name = 'TooManyRequestsError'\n }\n}\n\n/** Thrown when a storage, transaction, or download cap has been exceeded. */\nexport class CapExceededError extends B2Error {\n /**\n * Creates a new CapExceededError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'CapExceededError'\n }\n}\n\n/** Thrown when the application key does not have permission for the requested operation. */\nexport class AccessDeniedError extends B2Error {\n /**\n * Creates a new AccessDeniedError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'AccessDeniedError'\n }\n}\n\n/** Thrown when the requested file does not exist. */\nexport class FileNotPresentError extends B2Error {\n /**\n * Creates a new FileNotPresentError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'FileNotPresentError'\n }\n}\n\n/** Thrown when creating a bucket with a name that already exists in the account. */\nexport class DuplicateBucketNameError extends B2Error {\n /**\n * Creates a new DuplicateBucketNameError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'DuplicateBucketNameError'\n }\n}\n\n/** Thrown for general bad request errors (HTTP 400) not covered by a more specific subclass. */\nexport class BadRequestError extends B2Error {\n /**\n * Creates a new BadRequestError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'BadRequestError'\n }\n}\n\n/**\n * Thrown when an upload URL is no longer valid and must be refreshed.\n *\n * Forward-compat insurance: B2 does not currently surface a distinct\n * error code for this case, so {@link classifyError} never actually\n * instantiates this class today. It's part of the public API so\n * consumers can pre-write `instanceof` checks; when B2 documents a\n * `bad_upload_url` (or similar) error code, the `classifyError`\n * switch gets a matching case and existing consumer code starts\n * catching the typed error without any changes on their side.\n *\n * Until then, expect `BadRequestError` for upload-URL invalidation\n * scenarios — that's what B2 currently returns.\n */\nexport class BadUploadUrlError extends B2Error {\n /**\n * Creates a new BadUploadUrlError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'BadUploadUrlError'\n }\n}\n\n/**\n * Thrown when the uploaded file's SHA-1 checksum does not match the\n * expected value.\n *\n * Forward-compat insurance: the B2 API currently rejects mismatched\n * uploads with a generic `bad_request` code, so {@link classifyError}\n * never actually instantiates this class today. It's part of the\n * public API so consumers can pre-write `instanceof` checks; when B2\n * documents a dedicated checksum-mismatch code, the `classifyError`\n * switch gets a matching case and existing consumer code starts\n * catching the typed error without any changes on their side.\n *\n * Until then, expect `BadRequestError` for SHA-1 mismatch scenarios.\n */\nexport class ChecksumMismatchError extends B2Error {\n /**\n * Creates a new ChecksumMismatchError instance.\n * @param response - Parsed B2 error response body.\n * @param options - The error details including HTTP status, error code, message, and optional request ID.\n */\n constructor(response: B2ErrorResponse, options?: { requestId?: string }) {\n super(response, options)\n this.name = 'ChecksumMismatchError'\n }\n}\n\n/**\n * Thrown by client-side capability checks when the application key is missing\n * capabilities required by an operation. Not raised by the server.\n */\nexport class B2InsufficientCapabilityError extends Error {\n /** Capabilities that were required for the operation. */\n readonly required: readonly string[]\n /** Capabilities that the current key actually has. */\n readonly available: readonly string[]\n /** Capabilities present in `required` but not in `available`. */\n readonly missing: readonly string[]\n\n /**\n * Creates a new B2InsufficientCapabilityError instance.\n *\n * @param required - Capabilities the operation requires.\n * @param available - Capabilities the current key holds.\n * @param missing - The subset of required that isn't available.\n */\n constructor(\n required: readonly string[],\n available: readonly string[],\n missing: readonly string[],\n ) {\n super(`Application key is missing capabilities: ${missing.join(', ')}`)\n this.name = 'B2InsufficientCapabilityError'\n this.required = required\n this.available = available\n this.missing = missing\n }\n}\n\n/**\n * Thrown when the SDK is asked to fetch a URL whose host is outside the\n * authorized B2 realm. Defense against SSRF / URL-substitution attacks where\n * a compromised or hostile B2 endpoint returns an upload URL pointing at an\n * internal service (e.g. cloud metadata at `169.254.169.254`).\n *\n * Not retryable.\n */\nexport class B2SsrfError extends Error {\n /** Always `false` — this is a security failure, not transient. */\n readonly retryable = false\n\n /**\n * Creates a new {@link B2SsrfError}.\n *\n * @param message - Human-readable description of which URL was rejected and why.\n * @param url - The full URL that was rejected.\n */\n constructor(\n message: string,\n /** The full URL that was rejected. */\n public readonly url: string,\n ) {\n super(message)\n this.name = 'B2SsrfError'\n }\n}\n\n/** Thrown when a network-level failure occurs (DNS, TCP, TLS). Always retryable. */\nexport class NetworkError extends Error {\n /** Always `true` since network errors are transient. */\n readonly retryable = true\n\n /**\n * Creates a new NetworkError instance.\n * @param message - Human-readable description of the network failure.\n * @param cause - The underlying error that caused this failure, if any.\n */\n constructor(\n message: string,\n public override readonly cause?: unknown,\n ) {\n super(message)\n this.name = 'NetworkError'\n }\n}\n\nfunction isTransient(status: number, code: B2ErrorCode): boolean {\n if (status === 408 || status === 429 || status === 503) return true\n if (code === 'expired_auth_token') return true\n if (code === 'service_unavailable' || code === 'request_timeout') return true\n return false\n}\n\n/**\n * Maps a B2 error response to the appropriate {@link B2Error} subclass.\n * Uses the error code for exact matching, then falls back to HTTP status codes.\n *\n * Maintainer note: when B2 documents a new error code, add a `case`\n * branch below pointing at the matching {@link B2Error} subclass. Unknown\n * codes fall through to the HTTP-status-based heuristic and finally to a\n * generic `B2Error` — that's safe but loses semantic specificity (the\n * caller can't `instanceof` against a precise subclass and the retry\n * decision relies on status alone). The `B2ErrorCode` union in\n * `src/types/errors.ts` should also gain the new code at the same time\n * so the switch is exhaustive again.\n *\n * @param response - Parsed B2 error response body.\n * @param options - Optional retry and request metadata from response headers.\n *\n * @returns A typed B2Error subclass instance.\n */\nexport function classifyError(\n response: B2ErrorResponse,\n options?: { retryAfter?: number; requestId?: string },\n): B2Error {\n switch (response.code) {\n case 'expired_auth_token':\n return new ExpiredAuthTokenError(response, options)\n case 'bad_auth_token':\n case 'unauthorized':\n return new BadAuthTokenError(response, options)\n case 'service_unavailable':\n return new ServiceUnavailableError(response, options)\n case 'request_timeout':\n return new RequestTimeoutError(response, options)\n case 'cap_exceeded':\n case 'storage_cap_exceeded':\n case 'transaction_cap_exceeded':\n case 'download_cap_exceeded':\n return new CapExceededError(response, options)\n case 'access_denied':\n return new AccessDeniedError(response, options)\n case 'file_not_present':\n case 'no_such_file':\n return new FileNotPresentError(response, options)\n case 'duplicate_bucket_name':\n return new DuplicateBucketNameError(response, options)\n case 'bad_sha1_checksum':\n return new ChecksumMismatchError(response, options)\n case 'bad_request':\n return new BadRequestError(response, options)\n default:\n break\n }\n\n if (response.status === 429) return new TooManyRequestsError(response, options)\n if (response.status === 503) return new ServiceUnavailableError(response, options)\n if (response.status === 408) return new RequestTimeoutError(response, options)\n\n return new B2Error(response, options)\n}\n"],"names":[],"mappings":"AA0BO,MAAM,gBAAgB,MAAM;AAAA;AAAA,EAExB;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,YAAY,UAA2B,SAAuD;AAC5F,UAAM,SAAS,OAAO;AACtB,SAAK,OAAO;AACZ,SAAK,SAAS,SAAS;AACvB,SAAK,OAAO,SAAS;AACrB,QAAI,SAAS,eAAe,OAAW,MAAK,aAAa,QAAQ;AACjE,QAAI,SAAS,cAAc,OAAW,MAAK,YAAY,QAAQ;AAC/D,SAAK,YAAY,YAAY,SAAS,QAAQ,SAAS,IAAI;AAAA,EAC7D;AACF;AAGO,MAAM,8BAA8B,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjD,YAAY,UAA2B,SAAkC;AACvE,UAAM,UAAU,OAAO;AACvB,SAAK,OAAO;AAAA,EACd;AACF;AAGO,MAAM,0BAA0B,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM7C,YAAY,UAA2B,SAAkC;AACvE,UAAM,UAAU,OAAO;AACvB,SAAK,OAAO;A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OAAO;AAAA,IACpD,KAAK;AAAA,IACL,KAAK;AACH,aAAO,IAAI,kBAAkB,UAAU,OAAO;AAAA,IAChD,KAAK;AACH,aAAO,IAAI,wBAAwB,UAAU,OAAO;AAAA,IACtD,KAAK;AACH,aAAO,IAAI,oBAAoB,UAAU,OAAO;AAAA,IAClD,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,IAAI,iBAAiB,UAAU,OAAO;AAAA,IAC/C,KAAK;AACH,aAAO,IAAI,kBAAkB,UAAU,OAAO;AAAA,IAChD,KAAK;AAAA,IACL,KAAK;AACH,aAAO,IAAI,oBAAoB,UAAU,OAAO;AAAA,IAClD,KAAK;AACH,aAAO,IAAI,yBAAyB,UAAU,OAAO;AAAA,IACvD,KAAK;AACH,aAAO,IAAI,sBAAsB,UAAU,OAAO;AAAA,IACpD,KAAK;AACH,aAAO,IAAI,gBAAgB,UAAU,OAAO;AAAA,EAE5C;AAGJ,MAAI,SAAS,WAAW,YAAY,IAAI,qBAAqB,UAAU,OAAO;AAC9E,MAAI,SAAS,WAAW,YAAY,IAAI,wBAAwB,UAAU,OAAO;AACjF,MAAI,SAAS,WAAW,YAAY,IAAI,oBAAoB,UAAU,OAAO;AAE7E,SAAO,IAAI,QAAQ,UAAU,OAAO;AACtC;"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const DEFAULT_RETRY_OPTIONS = {
4
+ maxRetries: 5,
5
+ maxRetryDelayMs: 64e3,
6
+ initialRetryDelayMs: 1e3
7
+ };
8
+ function computeBackoff(attempt, options, retryAfter) {
9
+ if (retryAfter !== void 0 && retryAfter > 0) {
10
+ return Math.min(retryAfter * 1e3, options.maxRetryDelayMs);
11
+ }
12
+ const base = options.initialRetryDelayMs * 2 ** attempt;
13
+ const jitter = Math.random() * base * 0.5;
14
+ return Math.min(base + jitter, options.maxRetryDelayMs);
15
+ }
16
+ function sleep(ms, signal) {
17
+ return new Promise((resolve, reject) => {
18
+ if (signal?.aborted) {
19
+ reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
20
+ return;
21
+ }
22
+ const timer = setTimeout(resolve, ms);
23
+ signal?.addEventListener(
24
+ "abort",
25
+ () => {
26
+ clearTimeout(timer);
27
+ reject(signal.reason ?? new DOMException("Aborted", "AbortError"));
28
+ },
29
+ { once: true }
30
+ );
31
+ });
32
+ }
33
+ exports.DEFAULT_RETRY_OPTIONS = DEFAULT_RETRY_OPTIONS;
34
+ exports.computeBackoff = computeBackoff;
35
+ exports.sleep = sleep;
36
+ //# sourceMappingURL=retry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.cjs","sources":["../../src/http/retry.ts"],"sourcesContent":["/** Configuration for retry behavior on transient failures. */\nexport interface RetryOptions {\n /** Maximum number of retry attempts before giving up. */\n readonly maxRetries: number\n /** Upper bound on retry delay in milliseconds, regardless of backoff calculation. */\n readonly maxRetryDelayMs: number\n /** Base delay in milliseconds for the first retry. Doubles on each subsequent attempt. */\n readonly initialRetryDelayMs: number\n}\n\n/** Default retry settings: 5 retries, 1s initial delay, 64s max delay. */\nexport const DEFAULT_RETRY_OPTIONS: RetryOptions = {\n maxRetries: 5,\n maxRetryDelayMs: 64_000,\n initialRetryDelayMs: 1_000,\n}\n\n/**\n * Computes the delay before the next retry using exponential backoff with jitter.\n * If a `Retry-After` value is provided by the server, it takes precedence over\n * the calculated backoff (still capped at {@link RetryOptions.maxRetryDelayMs}).\n *\n * @param attempt - Zero-based retry attempt index.\n * @param options - Retry configuration with delay bounds.\n * @param retryAfter - Server-provided retry delay in seconds, if any.\n *\n * @returns The delay in milliseconds before the next retry attempt.\n */\nexport function computeBackoff(\n attempt: number,\n options: RetryOptions,\n retryAfter?: number,\n): number {\n if (retryAfter !== undefined && retryAfter > 0) {\n return Math.min(retryAfter * 1000, options.maxRetryDelayMs)\n }\n const base = options.initialRetryDelayMs * 2 ** attempt\n const jitter = Math.random() * base * 0.5\n return Math.min(base + jitter, options.maxRetryDelayMs)\n}\n\n/**\n * Returns a promise that resolves after the given delay. Supports cancellation\n * via an optional AbortSignal.\n *\n * @param ms - Delay in milliseconds.\n * @param signal - Optional abort signal to cancel the sleep early.\n *\n * @returns A promise that resolves when the delay elapses or rejects if aborted.\n */\nexport function sleep(ms: number, signal?: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n if (signal?.aborted) {\n reject(signal.reason ?? new DOMException('Aborted', 'AbortError'))\n return\n }\n const timer = setTimeout(resolve, ms)\n signal?.addEventListener(\n 'abort',\n () => {\n clearTimeout(timer)\n reject(signal.reason ?? new DOMException('Aborted', 'AbortError'))\n },\n { once: true },\n )\n })\n}\n"],"names":[],"mappings":";;AAWO,MAAM,wBAAsC;AAAA,EACjD,YAAY;AAAA,EACZ,iBAAiB;AAAA,EACjB,qBAAqB;AACvB;AAaO,SAAS,eACd,SACA,SACA,YACQ;AACR,MAAI,eAAe,UAAa,aAAa,GAAG;AAC9C,WAAO,KAAK,IAAI,aAAa,KAAM,QAAQ,eAAe;AAAA,EAC5D;AACA,QAAM,OAAO,QAAQ,sBAAsB,KAAK;AAChD,QAAM,SAAS,KAAK,OAAA,IAAW,OAAO;AACtC,SAAO,KAAK,IAAI,OAAO,QAAQ,QAAQ,eAAe;AACxD;AAWO,SAAS,MAAM,IAAY,QAAqC;AACrE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI,QAAQ,SAAS;AACnB,aAAO,OAAO,UAAU,IAAI,aAAa,WAAW,YAAY,CAAC;AACjE;AAAA,IACF;AACA,UAAM,QAAQ,WAAW,SAAS,EAAE;AACpC,YAAQ;AAAA,MACN;AAAA,MACA,MAAM;AACJ,qBAAa,KAAK;AAClB,eAAO,OAAO,UAAU,IAAI,aAAa,WAAW,YAAY,CAAC;AAAA,MACnE;AAAA,MACA,EAAE,MAAM,KAAA;AAAA,IAAK;AAAA,EAEjB,CAAC;AACH;;;;"}
@@ -0,0 +1,34 @@
1
+ /** Configuration for retry behavior on transient failures. */
2
+ export interface RetryOptions {
3
+ /** Maximum number of retry attempts before giving up. */
4
+ readonly maxRetries: number;
5
+ /** Upper bound on retry delay in milliseconds, regardless of backoff calculation. */
6
+ readonly maxRetryDelayMs: number;
7
+ /** Base delay in milliseconds for the first retry. Doubles on each subsequent attempt. */
8
+ readonly initialRetryDelayMs: number;
9
+ }
10
+ /** Default retry settings: 5 retries, 1s initial delay, 64s max delay. */
11
+ export declare const DEFAULT_RETRY_OPTIONS: RetryOptions;
12
+ /**
13
+ * Computes the delay before the next retry using exponential backoff with jitter.
14
+ * If a `Retry-After` value is provided by the server, it takes precedence over
15
+ * the calculated backoff (still capped at {@link RetryOptions.maxRetryDelayMs}).
16
+ *
17
+ * @param attempt - Zero-based retry attempt index.
18
+ * @param options - Retry configuration with delay bounds.
19
+ * @param retryAfter - Server-provided retry delay in seconds, if any.
20
+ *
21
+ * @returns The delay in milliseconds before the next retry attempt.
22
+ */
23
+ export declare function computeBackoff(attempt: number, options: RetryOptions, retryAfter?: number): number;
24
+ /**
25
+ * Returns a promise that resolves after the given delay. Supports cancellation
26
+ * via an optional AbortSignal.
27
+ *
28
+ * @param ms - Delay in milliseconds.
29
+ * @param signal - Optional abort signal to cancel the sleep early.
30
+ *
31
+ * @returns A promise that resolves when the delay elapses or rejects if aborted.
32
+ */
33
+ export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
34
+ //# sourceMappingURL=retry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/http/retry.js"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,qFAAqF;IACrF,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,0FAA0F;IAC1F,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAA;CACrC;AAED,0EAA0E;AAC1E,eAAO,MAAM,qBAAqB,EAAE,YAInC,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,YAAY,EACrB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAOR;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBrE"}