@backblaze-labs/b2-sdk 0.2.0 → 0.3.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 (460) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +20 -2
  3. package/dist/_virtual/_b2-sdk-version-json.cjs +1 -1
  4. package/dist/_virtual/_b2-sdk-version-json.js +1 -1
  5. package/dist/auth/file.cjs.map +1 -1
  6. package/dist/backup/client.cjs +206 -0
  7. package/dist/backup/client.cjs.map +1 -0
  8. package/dist/backup/client.d.cts +238 -0
  9. package/dist/backup/client.d.cts.map +1 -0
  10. package/dist/backup/client.d.ts +238 -0
  11. package/dist/backup/client.d.ts.map +1 -0
  12. package/dist/backup/client.js +206 -0
  13. package/dist/backup/client.js.map +1 -0
  14. package/dist/backup/index.cjs +15 -0
  15. package/dist/backup/index.d.cts +22 -0
  16. package/dist/backup/index.d.cts.map +1 -0
  17. package/dist/backup/index.d.ts +22 -0
  18. package/dist/backup/index.d.ts.map +1 -0
  19. package/dist/backup/index.js +7 -0
  20. package/dist/backup/raw.cjs +146 -0
  21. package/dist/backup/raw.cjs.map +1 -0
  22. package/dist/backup/raw.d.cts +122 -0
  23. package/dist/backup/raw.d.cts.map +1 -0
  24. package/dist/backup/raw.d.ts +122 -0
  25. package/dist/backup/raw.d.ts.map +1 -0
  26. package/dist/backup/raw.js +146 -0
  27. package/dist/backup/raw.js.map +1 -0
  28. package/dist/bucket.cjs +2 -1
  29. package/dist/bucket.cjs.map +1 -1
  30. package/dist/bucket.js +2 -1
  31. package/dist/bucket.js.map +1 -1
  32. package/dist/copy/large.cjs +5 -3
  33. package/dist/copy/large.cjs.map +1 -1
  34. package/dist/copy/large.d.cts.map +1 -1
  35. package/dist/copy/large.d.ts.map +1 -1
  36. package/dist/copy/large.js +5 -3
  37. package/dist/copy/large.js.map +1 -1
  38. package/dist/download/checksum.cjs +6 -2
  39. package/dist/download/checksum.cjs.map +1 -1
  40. package/dist/download/checksum.js +6 -2
  41. package/dist/download/checksum.js.map +1 -1
  42. package/dist/download/parallel.cjs +52 -15
  43. package/dist/download/parallel.cjs.map +1 -1
  44. package/dist/download/parallel.d.cts +8 -1
  45. package/dist/download/parallel.d.cts.map +1 -1
  46. package/dist/download/parallel.d.ts +8 -1
  47. package/dist/download/parallel.d.ts.map +1 -1
  48. package/dist/download/parallel.js +52 -15
  49. package/dist/download/parallel.js.map +1 -1
  50. package/dist/download/single.cjs +141 -6
  51. package/dist/download/single.cjs.map +1 -1
  52. package/dist/download/single.d.cts.map +1 -1
  53. package/dist/download/single.d.ts.map +1 -1
  54. package/dist/download/single.js +141 -6
  55. package/dist/download/single.js.map +1 -1
  56. package/dist/errors/index.cjs +173 -3
  57. package/dist/errors/index.cjs.map +1 -1
  58. package/dist/errors/index.d.cts +119 -0
  59. package/dist/errors/index.d.cts.map +1 -1
  60. package/dist/errors/index.d.ts +119 -0
  61. package/dist/errors/index.d.ts.map +1 -1
  62. package/dist/errors/index.js +161 -4
  63. package/dist/errors/index.js.map +1 -1
  64. package/dist/http/retry.cjs +1 -1
  65. package/dist/http/retry.cjs.map +1 -1
  66. package/dist/http/retry.js +1 -1
  67. package/dist/http/retry.js.map +1 -1
  68. package/dist/http/transport.cjs +61 -23
  69. package/dist/http/transport.cjs.map +1 -1
  70. package/dist/http/transport.d.cts +25 -3
  71. package/dist/http/transport.d.cts.map +1 -1
  72. package/dist/http/transport.d.ts +25 -3
  73. package/dist/http/transport.d.ts.map +1 -1
  74. package/dist/http/transport.js +59 -22
  75. package/dist/http/transport.js.map +1 -1
  76. package/dist/index.cjs +25 -2
  77. package/dist/index.d.cts +6 -4
  78. package/dist/index.d.cts.map +1 -1
  79. package/dist/index.d.ts +6 -4
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +8 -6
  82. package/dist/object.cjs +1 -1
  83. package/dist/object.cjs.map +1 -1
  84. package/dist/object.d.cts +4 -2
  85. package/dist/object.d.cts.map +1 -1
  86. package/dist/object.d.ts +4 -2
  87. package/dist/object.d.ts.map +1 -1
  88. package/dist/object.js +1 -1
  89. package/dist/object.js.map +1 -1
  90. package/dist/partner/account-info.d.cts +43 -0
  91. package/dist/partner/account-info.d.cts.map +1 -0
  92. package/dist/partner/account-info.d.ts +43 -0
  93. package/dist/partner/account-info.d.ts.map +1 -0
  94. package/dist/partner/auth-clone.cjs +64 -0
  95. package/dist/partner/auth-clone.cjs.map +1 -0
  96. package/dist/partner/auth-clone.d.cts +27 -0
  97. package/dist/partner/auth-clone.d.cts.map +1 -0
  98. package/dist/partner/auth-clone.d.ts +27 -0
  99. package/dist/partner/auth-clone.d.ts.map +1 -0
  100. package/dist/partner/auth-clone.js +63 -0
  101. package/dist/partner/auth-clone.js.map +1 -0
  102. package/dist/partner/auth-core.cjs +175 -0
  103. package/dist/partner/auth-core.cjs.map +1 -0
  104. package/dist/partner/auth-core.d.cts +111 -0
  105. package/dist/partner/auth-core.d.cts.map +1 -0
  106. package/dist/partner/auth-core.d.ts +111 -0
  107. package/dist/partner/auth-core.d.ts.map +1 -0
  108. package/dist/partner/auth-core.js +175 -0
  109. package/dist/partner/auth-core.js.map +1 -0
  110. package/dist/partner/auth-shape.cjs +36 -0
  111. package/dist/partner/auth-shape.cjs.map +1 -0
  112. package/dist/partner/auth-shape.d.cts +12 -0
  113. package/dist/partner/auth-shape.d.cts.map +1 -0
  114. package/dist/partner/auth-shape.d.ts +12 -0
  115. package/dist/partner/auth-shape.d.ts.map +1 -0
  116. package/dist/partner/auth-shape.js +36 -0
  117. package/dist/partner/auth-shape.js.map +1 -0
  118. package/dist/partner/client.cjs +255 -0
  119. package/dist/partner/client.cjs.map +1 -0
  120. package/dist/partner/client.d.cts +335 -0
  121. package/dist/partner/client.d.cts.map +1 -0
  122. package/dist/partner/client.d.ts +335 -0
  123. package/dist/partner/client.d.ts.map +1 -0
  124. package/dist/partner/client.js +255 -0
  125. package/dist/partner/client.js.map +1 -0
  126. package/dist/partner/endpoint-url.cjs +108 -0
  127. package/dist/partner/endpoint-url.cjs.map +1 -0
  128. package/dist/partner/endpoint-url.d.cts +72 -0
  129. package/dist/partner/endpoint-url.d.cts.map +1 -0
  130. package/dist/partner/endpoint-url.d.ts +72 -0
  131. package/dist/partner/endpoint-url.d.ts.map +1 -0
  132. package/dist/partner/endpoint-url.js +105 -0
  133. package/dist/partner/endpoint-url.js.map +1 -0
  134. package/dist/partner/in-memory.cjs +135 -0
  135. package/dist/partner/in-memory.cjs.map +1 -0
  136. package/dist/partner/in-memory.d.cts +99 -0
  137. package/dist/partner/in-memory.d.cts.map +1 -0
  138. package/dist/partner/in-memory.d.ts +99 -0
  139. package/dist/partner/in-memory.d.ts.map +1 -0
  140. package/dist/partner/in-memory.js +135 -0
  141. package/dist/partner/in-memory.js.map +1 -0
  142. package/dist/partner/index.cjs +18 -0
  143. package/dist/partner/index.d.cts +23 -0
  144. package/dist/partner/index.d.cts.map +1 -0
  145. package/dist/partner/index.d.ts +23 -0
  146. package/dist/partner/index.d.ts.map +1 -0
  147. package/dist/partner/index.js +7 -0
  148. package/dist/partner/raw.cjs +392 -0
  149. package/dist/partner/raw.cjs.map +1 -0
  150. package/dist/partner/raw.d.cts +223 -0
  151. package/dist/partner/raw.d.cts.map +1 -0
  152. package/dist/partner/raw.d.ts +223 -0
  153. package/dist/partner/raw.d.ts.map +1 -0
  154. package/dist/partner/raw.js +390 -0
  155. package/dist/partner/raw.js.map +1 -0
  156. package/dist/partner/redaction-placeholders.cjs +10 -0
  157. package/dist/partner/redaction-placeholders.cjs.map +1 -0
  158. package/dist/partner/redaction-placeholders.d.cts +5 -0
  159. package/dist/partner/redaction-placeholders.d.cts.map +1 -0
  160. package/dist/partner/redaction-placeholders.d.ts +5 -0
  161. package/dist/partner/redaction-placeholders.d.ts.map +1 -0
  162. package/dist/partner/redaction-placeholders.js +9 -0
  163. package/dist/partner/redaction-placeholders.js.map +1 -0
  164. package/dist/partner/redaction.cjs +267 -0
  165. package/dist/partner/redaction.cjs.map +1 -0
  166. package/dist/partner/redaction.d.cts +124 -0
  167. package/dist/partner/redaction.d.cts.map +1 -0
  168. package/dist/partner/redaction.d.ts +124 -0
  169. package/dist/partner/redaction.d.ts.map +1 -0
  170. package/dist/partner/redaction.js +257 -0
  171. package/dist/partner/redaction.js.map +1 -0
  172. package/dist/raw/index.cjs +81 -19
  173. package/dist/raw/index.cjs.map +1 -1
  174. package/dist/raw/index.d.cts +6 -2
  175. package/dist/raw/index.d.cts.map +1 -1
  176. package/dist/raw/index.d.ts +6 -2
  177. package/dist/raw/index.d.ts.map +1 -1
  178. package/dist/raw/index.js +81 -19
  179. package/dist/raw/index.js.map +1 -1
  180. package/dist/raw/url.cjs +111 -0
  181. package/dist/raw/url.cjs.map +1 -0
  182. package/dist/raw/url.d.cts +41 -0
  183. package/dist/raw/url.d.cts.map +1 -0
  184. package/dist/raw/url.d.ts +41 -0
  185. package/dist/raw/url.d.ts.map +1 -0
  186. package/dist/raw/url.js +110 -0
  187. package/dist/raw/url.js.map +1 -0
  188. package/dist/s3/sigv4.cjs +15 -10
  189. package/dist/s3/sigv4.cjs.map +1 -1
  190. package/dist/s3/sigv4.js +15 -10
  191. package/dist/s3/sigv4.js.map +1 -1
  192. package/dist/simulator/index.cjs +1197 -206
  193. package/dist/simulator/index.cjs.map +1 -1
  194. package/dist/simulator/index.d.cts +109 -11
  195. package/dist/simulator/index.d.cts.map +1 -1
  196. package/dist/simulator/index.d.ts +109 -11
  197. package/dist/simulator/index.d.ts.map +1 -1
  198. package/dist/simulator/index.js +1196 -209
  199. package/dist/simulator/index.js.map +1 -1
  200. package/dist/simulator/partner.cjs +719 -0
  201. package/dist/simulator/partner.cjs.map +1 -0
  202. package/dist/simulator/partner.d.cts +183 -0
  203. package/dist/simulator/partner.d.cts.map +1 -0
  204. package/dist/simulator/partner.d.ts +183 -0
  205. package/dist/simulator/partner.d.ts.map +1 -0
  206. package/dist/simulator/partner.js +718 -0
  207. package/dist/simulator/partner.js.map +1 -0
  208. package/dist/simulator/validation.cjs +577 -0
  209. package/dist/simulator/validation.cjs.map +1 -1
  210. package/dist/simulator/validation.d.cts +117 -0
  211. package/dist/simulator/validation.d.cts.map +1 -1
  212. package/dist/simulator/validation.d.ts +117 -0
  213. package/dist/simulator/validation.d.ts.map +1 -1
  214. package/dist/simulator/validation.js +563 -1
  215. package/dist/simulator/validation.js.map +1 -1
  216. package/dist/streams/file-source.cjs +1 -1
  217. package/dist/streams/file-source.cjs.map +1 -1
  218. package/dist/streams/file-source.js +1 -1
  219. package/dist/streams/file-source.js.map +1 -1
  220. package/dist/streams/index.cjs +1 -1
  221. package/dist/streams/index.js +1 -1
  222. package/dist/streams/source.cjs +2 -1
  223. package/dist/streams/source.cjs.map +1 -1
  224. package/dist/streams/source.js +2 -1
  225. package/dist/streams/source.js.map +1 -1
  226. package/dist/sync/b2-sha1-reader.cjs +6 -2
  227. package/dist/sync/b2-sha1-reader.cjs.map +1 -1
  228. package/dist/sync/b2-sha1-reader.d.cts.map +1 -1
  229. package/dist/sync/b2-sha1-reader.d.ts.map +1 -1
  230. package/dist/sync/b2-sha1-reader.js +6 -2
  231. package/dist/sync/b2-sha1-reader.js.map +1 -1
  232. package/dist/sync/download-staging.cjs +11 -10
  233. package/dist/sync/download-staging.cjs.map +1 -1
  234. package/dist/sync/download-staging.d.cts +2 -1
  235. package/dist/sync/download-staging.d.cts.map +1 -1
  236. package/dist/sync/download-staging.d.ts +2 -1
  237. package/dist/sync/download-staging.d.ts.map +1 -1
  238. package/dist/sync/download-staging.js +11 -10
  239. package/dist/sync/download-staging.js.map +1 -1
  240. package/dist/sync/filters.cjs.map +1 -1
  241. package/dist/sync/filters.js.map +1 -1
  242. package/dist/sync/local-file-io.cjs +11 -6
  243. package/dist/sync/local-file-io.cjs.map +1 -1
  244. package/dist/sync/local-file-io.d.cts +1 -0
  245. package/dist/sync/local-file-io.d.cts.map +1 -1
  246. package/dist/sync/local-file-io.d.ts +1 -0
  247. package/dist/sync/local-file-io.d.ts.map +1 -1
  248. package/dist/sync/local-file-io.js +11 -6
  249. package/dist/sync/local-file-io.js.map +1 -1
  250. package/dist/sync/local-sha1.cjs +6 -15
  251. package/dist/sync/local-sha1.cjs.map +1 -1
  252. package/dist/sync/local-sha1.d.cts +0 -8
  253. package/dist/sync/local-sha1.d.cts.map +1 -1
  254. package/dist/sync/local-sha1.d.ts +0 -8
  255. package/dist/sync/local-sha1.d.ts.map +1 -1
  256. package/dist/sync/local-sha1.js +7 -15
  257. package/dist/sync/local-sha1.js.map +1 -1
  258. package/dist/sync/policies/compare.cjs +5 -3
  259. package/dist/sync/policies/compare.cjs.map +1 -1
  260. package/dist/sync/policies/compare.d.cts.map +1 -1
  261. package/dist/sync/policies/compare.d.ts.map +1 -1
  262. package/dist/sync/policies/compare.js +6 -4
  263. package/dist/sync/policies/compare.js.map +1 -1
  264. package/dist/sync/policies/index.cjs +4 -10
  265. package/dist/sync/policies/index.cjs.map +1 -1
  266. package/dist/sync/policies/index.js +4 -10
  267. package/dist/sync/policies/index.js.map +1 -1
  268. package/dist/sync/scanners/b2.cjs +2 -2
  269. package/dist/sync/scanners/b2.cjs.map +1 -1
  270. package/dist/sync/scanners/b2.js +2 -2
  271. package/dist/sync/scanners/b2.js.map +1 -1
  272. package/dist/sync/scanners/local.cjs.map +1 -1
  273. package/dist/sync/scanners/local.js.map +1 -1
  274. package/dist/sync/synchronizer.cjs +3 -2
  275. package/dist/sync/synchronizer.cjs.map +1 -1
  276. package/dist/sync/synchronizer.js +3 -2
  277. package/dist/sync/synchronizer.js.map +1 -1
  278. package/dist/types/auth.cjs +4 -0
  279. package/dist/types/auth.cjs.map +1 -1
  280. package/dist/types/auth.d.cts +4 -0
  281. package/dist/types/auth.d.cts.map +1 -1
  282. package/dist/types/auth.d.ts +4 -0
  283. package/dist/types/auth.d.ts.map +1 -1
  284. package/dist/types/auth.js +4 -0
  285. package/dist/types/auth.js.map +1 -1
  286. package/dist/types/backup.d.cts +80 -0
  287. package/dist/types/backup.d.cts.map +1 -0
  288. package/dist/types/backup.d.ts +80 -0
  289. package/dist/types/backup.d.ts.map +1 -0
  290. package/dist/types/bucket.cjs.map +1 -1
  291. package/dist/types/bucket.d.cts +4 -2
  292. package/dist/types/bucket.d.cts.map +1 -1
  293. package/dist/types/bucket.d.ts +4 -2
  294. package/dist/types/bucket.d.ts.map +1 -1
  295. package/dist/types/bucket.js.map +1 -1
  296. package/dist/types/download.cjs +62 -0
  297. package/dist/types/download.cjs.map +1 -0
  298. package/dist/types/download.d.cts +98 -0
  299. package/dist/types/download.d.cts.map +1 -1
  300. package/dist/types/download.d.ts +98 -0
  301. package/dist/types/download.d.ts.map +1 -1
  302. package/dist/types/download.js +61 -0
  303. package/dist/types/download.js.map +1 -0
  304. package/dist/types/encryption.cjs +58 -229
  305. package/dist/types/encryption.cjs.map +1 -1
  306. package/dist/types/encryption.d.cts +32 -0
  307. package/dist/types/encryption.d.cts.map +1 -1
  308. package/dist/types/encryption.d.ts +32 -0
  309. package/dist/types/encryption.d.ts.map +1 -1
  310. package/dist/types/encryption.js +56 -229
  311. package/dist/types/encryption.js.map +1 -1
  312. package/dist/types/errors.cjs +9 -0
  313. package/dist/types/errors.cjs.map +1 -1
  314. package/dist/types/errors.d.cts +1 -1
  315. package/dist/types/errors.d.cts.map +1 -1
  316. package/dist/types/errors.d.ts +1 -1
  317. package/dist/types/errors.d.ts.map +1 -1
  318. package/dist/types/errors.js +9 -0
  319. package/dist/types/errors.js.map +1 -1
  320. package/dist/types/file.cjs.map +1 -1
  321. package/dist/types/file.d.cts +15 -2
  322. package/dist/types/file.d.cts.map +1 -1
  323. package/dist/types/file.d.ts +15 -2
  324. package/dist/types/file.d.ts.map +1 -1
  325. package/dist/types/file.js.map +1 -1
  326. package/dist/types/ids.cjs +30 -0
  327. package/dist/types/ids.cjs.map +1 -1
  328. package/dist/types/ids.d.cts +32 -0
  329. package/dist/types/ids.d.cts.map +1 -1
  330. package/dist/types/ids.d.ts +32 -0
  331. package/dist/types/ids.d.ts.map +1 -1
  332. package/dist/types/ids.js +28 -1
  333. package/dist/types/ids.js.map +1 -1
  334. package/dist/types/index.d.cts +10 -6
  335. package/dist/types/index.d.cts.map +1 -1
  336. package/dist/types/index.d.ts +10 -6
  337. package/dist/types/index.d.ts.map +1 -1
  338. package/dist/types/lock.cjs.map +1 -1
  339. package/dist/types/lock.d.cts +14 -0
  340. package/dist/types/lock.d.cts.map +1 -1
  341. package/dist/types/lock.d.ts +14 -0
  342. package/dist/types/lock.d.ts.map +1 -1
  343. package/dist/types/lock.js.map +1 -1
  344. package/dist/types/notifications.cjs +1 -1
  345. package/dist/types/notifications.cjs.map +1 -1
  346. package/dist/types/notifications.d.cts +5 -3
  347. package/dist/types/notifications.d.cts.map +1 -1
  348. package/dist/types/notifications.d.ts +5 -3
  349. package/dist/types/notifications.d.ts.map +1 -1
  350. package/dist/types/notifications.js +1 -1
  351. package/dist/types/notifications.js.map +1 -1
  352. package/dist/types/partner.cjs +32 -0
  353. package/dist/types/partner.cjs.map +1 -0
  354. package/dist/types/partner.d.cts +394 -0
  355. package/dist/types/partner.d.cts.map +1 -0
  356. package/dist/types/partner.d.ts +394 -0
  357. package/dist/types/partner.d.ts.map +1 -0
  358. package/dist/types/partner.js +29 -0
  359. package/dist/types/partner.js.map +1 -0
  360. package/dist/types/upload.d.cts +31 -18
  361. package/dist/types/upload.d.cts.map +1 -1
  362. package/dist/types/upload.d.ts +31 -18
  363. package/dist/types/upload.d.ts.map +1 -1
  364. package/dist/upload/abort-scope.cjs +0 -45
  365. package/dist/upload/abort-scope.cjs.map +1 -1
  366. package/dist/upload/abort-scope.d.cts +0 -22
  367. package/dist/upload/abort-scope.d.cts.map +1 -1
  368. package/dist/upload/abort-scope.d.ts +0 -22
  369. package/dist/upload/abort-scope.d.ts.map +1 -1
  370. package/dist/upload/abort-scope.js +1 -44
  371. package/dist/upload/abort-scope.js.map +1 -1
  372. package/dist/upload/finish.cjs +3 -8
  373. package/dist/upload/finish.cjs.map +1 -1
  374. package/dist/upload/finish.d.cts.map +1 -1
  375. package/dist/upload/finish.d.ts.map +1 -1
  376. package/dist/upload/finish.js +1 -6
  377. package/dist/upload/finish.js.map +1 -1
  378. package/dist/upload/large.cjs +5 -1
  379. package/dist/upload/large.cjs.map +1 -1
  380. package/dist/upload/large.d.cts +16 -2
  381. package/dist/upload/large.d.cts.map +1 -1
  382. package/dist/upload/large.d.ts +16 -2
  383. package/dist/upload/large.d.ts.map +1 -1
  384. package/dist/upload/large.js +5 -1
  385. package/dist/upload/large.js.map +1 -1
  386. package/dist/upload/options.cjs.map +1 -1
  387. package/dist/upload/options.d.cts +12 -0
  388. package/dist/upload/options.d.cts.map +1 -1
  389. package/dist/upload/options.d.ts +12 -0
  390. package/dist/upload/options.d.ts.map +1 -1
  391. package/dist/upload/options.js.map +1 -1
  392. package/dist/upload/resume.cjs +2 -1
  393. package/dist/upload/resume.cjs.map +1 -1
  394. package/dist/upload/resume.d.cts +3 -1
  395. package/dist/upload/resume.d.cts.map +1 -1
  396. package/dist/upload/resume.d.ts +3 -1
  397. package/dist/upload/resume.d.ts.map +1 -1
  398. package/dist/upload/resume.js +2 -1
  399. package/dist/upload/resume.js.map +1 -1
  400. package/dist/upload/retry.cjs +8 -3
  401. package/dist/upload/retry.cjs.map +1 -1
  402. package/dist/upload/retry.js +8 -3
  403. package/dist/upload/retry.js.map +1 -1
  404. package/dist/upload/single.cjs +2 -1
  405. package/dist/upload/single.cjs.map +1 -1
  406. package/dist/upload/single.d.cts +6 -0
  407. package/dist/upload/single.d.cts.map +1 -1
  408. package/dist/upload/single.d.ts +6 -0
  409. package/dist/upload/single.d.ts.map +1 -1
  410. package/dist/upload/single.js +2 -1
  411. package/dist/upload/single.js.map +1 -1
  412. package/dist/upload/stream.cjs +6 -4
  413. package/dist/upload/stream.cjs.map +1 -1
  414. package/dist/upload/stream.d.cts +6 -0
  415. package/dist/upload/stream.d.cts.map +1 -1
  416. package/dist/upload/stream.d.ts +6 -0
  417. package/dist/upload/stream.d.ts.map +1 -1
  418. package/dist/upload/stream.js +3 -1
  419. package/dist/upload/stream.js.map +1 -1
  420. package/dist/util/abort.cjs +114 -0
  421. package/dist/util/abort.cjs.map +1 -0
  422. package/dist/util/abort.d.cts +65 -0
  423. package/dist/util/abort.d.cts.map +1 -0
  424. package/dist/util/abort.d.ts +65 -0
  425. package/dist/util/abort.d.ts.map +1 -0
  426. package/dist/util/abort.js +109 -0
  427. package/dist/util/abort.js.map +1 -0
  428. package/dist/util/defaults.cjs +3 -0
  429. package/dist/util/defaults.cjs.map +1 -1
  430. package/dist/util/defaults.d.cts +2 -0
  431. package/dist/util/defaults.d.cts.map +1 -1
  432. package/dist/util/defaults.d.ts +2 -0
  433. package/dist/util/defaults.d.ts.map +1 -1
  434. package/dist/util/defaults.js +3 -1
  435. package/dist/util/defaults.js.map +1 -1
  436. package/dist/util/md5.cjs +211 -0
  437. package/dist/util/md5.cjs.map +1 -0
  438. package/dist/util/md5.d.cts +43 -0
  439. package/dist/util/md5.d.cts.map +1 -0
  440. package/dist/util/md5.d.ts +43 -0
  441. package/dist/util/md5.d.ts.map +1 -0
  442. package/dist/util/md5.js +209 -0
  443. package/dist/util/md5.js.map +1 -0
  444. package/dist/util/normalize.cjs +5 -5
  445. package/dist/util/normalize.cjs.map +1 -1
  446. package/dist/util/normalize.d.cts +7 -7
  447. package/dist/util/normalize.d.cts.map +1 -1
  448. package/dist/util/normalize.d.ts +7 -7
  449. package/dist/util/normalize.d.ts.map +1 -1
  450. package/dist/util/normalize.js +5 -5
  451. package/dist/util/normalize.js.map +1 -1
  452. package/dist/util/paginator.cjs +7 -1
  453. package/dist/util/paginator.cjs.map +1 -1
  454. package/dist/util/paginator.d.cts +3 -1
  455. package/dist/util/paginator.d.cts.map +1 -1
  456. package/dist/util/paginator.d.ts +3 -1
  457. package/dist/util/paginator.d.ts.map +1 -1
  458. package/dist/util/paginator.js +7 -1
  459. package/dist/util/paginator.js.map +1 -1
  460. package/package.json +38 -16
@@ -1 +1 @@
1
- {"version":3,"file":"validation.cjs","names":[],"sources":["../../src/simulator/validation.ts"],"sourcesContent":["/**\n * B2 spec-compliance validation helpers for the simulator.\n *\n * Each function mirrors a documented B2 input limit (file name length,\n * bucket name regex, file-info byte budget, etc.). Validators return\n * `null` for valid input or a `{ code, message }` pair that the handler\n * converts into a synthetic `400`/`403` response with the right B2\n * error code.\n *\n * Keeping validation in one module makes the simulator's \"what does B2\n * reject?\" surface auditable in a single file. Doc references inline at\n * each rule so the spec source is immediate.\n *\n * @packageDocumentation\n */\n\nimport {\n BUCKET_NAME_MAX,\n BUCKET_NAME_MIN,\n BUCKET_NAME_RESERVED_PREFIX,\n FILE_NAME_MAX_BYTES,\n getB2FileNameByteLength,\n hasB2FileNameControlCharacter,\n hasValidB2BucketNameShape,\n isB2BucketNameIpv4Address,\n} from '../internal/b2-naming.ts'\nimport { utf8Encoder } from '../util/text-codec.ts'\n\n/** Shape returned by validation functions when input is rejected. */\nexport interface ValidationError {\n readonly code: string\n readonly message: string\n}\n\n// ---------------------------------------------------------------------------\n// Bucket name (`b2_create_bucket`, `b2_update_bucket`)\n// ---------------------------------------------------------------------------\n\nexport { BUCKET_NAME_MAX, BUCKET_NAME_MIN }\n\n/**\n * Validates a bucket name against B2's documented rules.\n *\n * @param name - Caller-supplied bucket name.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-bucket\n */\nexport function validateBucketName(name: string): ValidationError | null {\n if (typeof name !== 'string' || name.length < BUCKET_NAME_MIN || name.length > BUCKET_NAME_MAX) {\n return {\n code: 'invalid_bucket_name',\n message: `bucketName must be ${BUCKET_NAME_MIN}-${BUCKET_NAME_MAX} characters`,\n }\n }\n if (isB2BucketNameIpv4Address(name)) {\n return {\n code: 'invalid_bucket_name',\n message: 'bucketName must not be formatted as an IPv4 address',\n }\n }\n if (!hasValidB2BucketNameShape(name)) {\n return {\n code: 'invalid_bucket_name',\n message:\n 'bucketName must contain only letters, digits, hyphens, and periods; cannot start or end with punctuation or contain consecutive periods',\n }\n }\n if (name.startsWith(BUCKET_NAME_RESERVED_PREFIX)) {\n return {\n code: 'invalid_bucket_name',\n message: `bucketName cannot start with the reserved prefix \"${BUCKET_NAME_RESERVED_PREFIX}\"`,\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// File name (every upload / hide / copy entry point)\n// ---------------------------------------------------------------------------\n\nexport { FILE_NAME_MAX_BYTES }\n\n/**\n * Validates a file name against B2's documented rules. Mirrors the\n * server-side checks B2 runs on `b2_upload_file` / `b2_hide_file` /\n * `b2_start_large_file` / `b2_copy_file` filename inputs.\n *\n * @param name - Caller-supplied file name (raw, unencoded).\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-upload-file\n */\nexport function validateFileName(name: string): ValidationError | null {\n if (typeof name !== 'string' || name.length === 0) {\n return { code: 'invalid_file_name', message: 'fileName must be a non-empty string' }\n }\n const byteLength = getB2FileNameByteLength(name)\n if (byteLength === null) {\n return {\n code: 'invalid_file_name',\n message: 'fileName exceeds the 1024-byte UTF-8 limit',\n }\n }\n if (hasB2FileNameControlCharacter(name)) {\n return {\n code: 'invalid_file_name',\n message: 'fileName must not contain control characters (U+0000-U+001F or U+007F)',\n }\n }\n // Path segments equal to `.` or `..` alone are illegal per B2 docs.\n // Embedded `..` within a segment (e.g. `a..b`) is fine, and a path\n // like `../foo` is fine because the SDK doesn't interpret it; only\n // bare `.` or `..` as a complete name is rejected.\n if (name === '.' || name === '..') {\n return {\n code: 'invalid_file_name',\n message: 'fileName cannot be exactly \".\" or \"..\"',\n }\n }\n // No leading or trailing slash, no `//`.\n if (name.startsWith('/') || name.endsWith('/') || name.includes('//')) {\n return {\n code: 'invalid_file_name',\n message: 'fileName cannot start with \"/\", end with \"/\", or contain \"//\"',\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// File-info / Bucket-info byte budget\n// ---------------------------------------------------------------------------\n\n/** Per-file fileInfo total size cap (sum of key+value bytes). */\nexport const FILE_INFO_TOTAL_MAX = 2048\n/** Per-key fileInfo value byte cap. */\nexport const FILE_INFO_VALUE_MAX = 2048\n/** Allowed key character set (case-insensitive). */\nconst FILE_INFO_KEY_REGEX = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Validates a `fileInfo` record against B2's byte-budget and\n * key-shape rules.\n *\n * @param info - Caller-supplied fileInfo record.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-upload-file\n */\nexport function validateFileInfo(info: Record<string, string>): ValidationError | null {\n let total = 0\n for (const [key, value] of Object.entries(info)) {\n if (!FILE_INFO_KEY_REGEX.test(key)) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo key \"${key}\" must match ^[a-zA-Z0-9_-]+$`,\n }\n }\n if (typeof value !== 'string') {\n return { code: 'invalid_file_info', message: `fileInfo value for \"${key}\" must be a string` }\n }\n const keyBytes = utf8Encoder.encode(key).byteLength\n const valueBytes = utf8Encoder.encode(value).byteLength\n if (valueBytes > FILE_INFO_VALUE_MAX) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo value for \"${key}\" exceeds ${FILE_INFO_VALUE_MAX} bytes`,\n }\n }\n total += keyBytes + valueBytes\n }\n if (total > FILE_INFO_TOTAL_MAX) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo total size ${total} bytes exceeds the ${FILE_INFO_TOTAL_MAX}-byte limit`,\n }\n }\n return null\n}\n\n/** Per-bucket bucketInfo total max keys. */\nexport const BUCKET_INFO_MAX_KEYS = 10\n/** Per-key bucketInfo value byte cap. */\nexport const BUCKET_INFO_VALUE_MAX = 2048\n/** Allowed key character set for bucketInfo. */\nconst BUCKET_INFO_KEY_REGEX = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Validates a `bucketInfo` record against B2's per-bucket metadata rules.\n *\n * @param info - Caller-supplied bucketInfo record.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-bucket\n */\nexport function validateBucketInfo(info: Record<string, string>): ValidationError | null {\n const entries = Object.entries(info)\n if (entries.length > BUCKET_INFO_MAX_KEYS) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo cannot have more than ${BUCKET_INFO_MAX_KEYS} keys (got ${entries.length})`,\n }\n }\n for (const [key, value] of entries) {\n if (!BUCKET_INFO_KEY_REGEX.test(key)) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo key \"${key}\" must match ^[a-zA-Z0-9_-]+$`,\n }\n }\n if (typeof value !== 'string') {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo value for \"${key}\" must be a string`,\n }\n }\n const valueBytes = utf8Encoder.encode(value).byteLength\n if (valueBytes > BUCKET_INFO_VALUE_MAX) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo value for \"${key}\" exceeds ${BUCKET_INFO_VALUE_MAX} bytes`,\n }\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// maxFileCount caps per endpoint\n// ---------------------------------------------------------------------------\n\n/**\n * Per-endpoint upper bound on the `maxFileCount` (or `maxKeyCount` /\n * `maxPartCount`) request field. Sourced from the B2 endpoint docs.\n */\nexport const LIST_ENDPOINT_CAPS = {\n /** `b2_list_file_names.maxFileCount` cap. */\n b2_list_file_names: 10_000,\n /** `b2_list_file_versions.maxFileCount` cap. */\n b2_list_file_versions: 10_000,\n /** `b2_list_unfinished_large_files.maxFileCount` cap. */\n b2_list_unfinished_large_files: 100,\n /** `b2_list_keys.maxKeyCount` cap. */\n b2_list_keys: 10_000,\n /** `b2_list_parts.maxPartCount` cap. */\n b2_list_parts: 10_000,\n} as const\n\n/**\n * Validates a `maxFileCount` (or `maxKeyCount` / `maxPartCount`) value\n * against the per-endpoint cap documented by B2.\n *\n * @param requested - Caller-supplied count.\n * @param endpoint - Which list endpoint this applies to.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n */\nexport function validateMaxCount(\n requested: number | undefined,\n endpoint: keyof typeof LIST_ENDPOINT_CAPS,\n): ValidationError | null {\n if (requested === undefined) return null\n if (!Number.isInteger(requested) || requested < 1) {\n return {\n code: 'bad_request',\n message: `maxFileCount must be a positive integer (got ${requested})`,\n }\n }\n const cap = LIST_ENDPOINT_CAPS[endpoint]\n if (requested > cap) {\n return {\n code: 'bad_request',\n message: `maxFileCount ${requested} exceeds the ${endpoint} cap of ${cap}`,\n }\n }\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,SAAgB,mBAAmB,MAAsC;CACvE,IAAI,OAAO,SAAS,YAAY,KAAK,SAAA,KAA4B,KAAK,SAAA,IACpE,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,IAAI,kBAAA,0BAA0B,IAAI,GAChC,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,IAAI,CAAC,kBAAA,0BAA0B,IAAI,GACjC,OAAO;EACL,MAAM;EACN,SACE;CACJ;CAEF,IAAI,KAAK,WAAA,KAAsC,GAC7C,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,OAAO;AACT;;;;;;;;;;;;AAmBA,SAAgB,iBAAiB,MAAsC;CACrE,IAAI,OAAO,SAAS,YAAY,KAAK,WAAW,GAC9C,OAAO;EAAE,MAAM;EAAqB,SAAS;CAAsC;CAGrF,IADmB,kBAAA,wBAAwB,IACvC,MAAe,MACjB,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,IAAI,kBAAA,8BAA8B,IAAI,GACpC,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAMF,IAAI,SAAS,OAAO,SAAS,MAC3B,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAGF,IAAI,KAAK,WAAW,GAAG,KAAK,KAAK,SAAS,GAAG,KAAK,KAAK,SAAS,IAAI,GAClE,OAAO;EACL,MAAM;EACN,SAAS;CACX;CAEF,OAAO;AACT;;AAOA,IAAa,sBAAsB;;AAEnC,IAAa,sBA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ACA,OAAO;AACT;;;;;AAUA,IAAa,qBAAqB;;CAEhC,oBAAoB;;CAEpB,uBAAuB;;CAEvB,gCAAgC;;CAEhC,cAAc;;CAEd,eAAe;AACjB;;;;;;;;;;AAWA,SAAgB,iBACd,WACA,UACwB;CACxB,IAAI,cAAc,KAAA,GAAW,OAAO;CACpC,IAAI,CAAC,OAAO,UAAU,SAAS,KAAK,YAAY,GAC9C,OAAO;EACL,MAAM;EACN,SAAS,gDAAgD,UAAU;CACrE;CAEF,MAAM,MAAM,mBAAmB;CAC/B,IAAI,YAAY,KACd,OAAO;EACL,MAAM;EACN,SAAS,gBAAgB,UAAU,eAAe,SAAS,UAAU;CACvE;CAEF,OAAO;AACT"}
1
+ {"version":3,"file":"validation.cjs","names":[],"sources":["../../src/simulator/validation.ts"],"sourcesContent":["/**\n * B2 spec-compliance validation helpers for the simulator.\n *\n * Each function mirrors a documented B2 input limit (file name length,\n * bucket name regex, file-info byte budget, etc.). Validators return\n * `null` for valid input or a `{ code, message }` pair that the handler\n * converts into a synthetic `400`/`403` response with the right B2\n * error code.\n *\n * Keeping validation in one module makes the simulator's \"what does B2\n * reject?\" surface auditable in a single file. Doc references inline at\n * each rule so the spec source is immediate.\n *\n * @packageDocumentation\n */\n\nimport {\n BUCKET_NAME_MAX,\n BUCKET_NAME_MIN,\n BUCKET_NAME_RESERVED_PREFIX,\n FILE_NAME_MAX_BYTES,\n getB2FileNameByteLength,\n hasB2FileNameControlCharacter,\n hasValidB2BucketNameShape,\n isB2BucketNameIpv4Address,\n} from '../internal/b2-naming.ts'\nimport { Capability } from '../types/auth.ts'\nimport { BucketRetentionMode, BucketType, CorsOperation } from '../types/bucket.ts'\nimport { EventType } from '../types/notifications.ts'\nimport { utf8Encoder } from '../util/text-codec.ts'\n\n/** Shape returned by validation functions when input is rejected. */\nexport interface ValidationError {\n readonly code: string\n readonly message: string\n}\n\n// ---------------------------------------------------------------------------\n// Application keys (`b2_create_key`)\n// ---------------------------------------------------------------------------\n\n/** Minimum length for application key names. */\nexport const KEY_NAME_MIN = 1\n/** Maximum length for application key names. */\nexport const KEY_NAME_MAX = 100\n\nconst VALID_CAPABILITIES = new Set<string>(Object.values(Capability))\n\n/**\n * Validates application-key capabilities against B2's supported capability set.\n *\n * @param capabilities - Caller-supplied capabilities array.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-key\n */\nexport function validateCreateKeyCapabilities(capabilities: unknown): ValidationError | null {\n if (!Array.isArray(capabilities)) {\n return { code: 'bad_request', message: 'capabilities must be an array' }\n }\n if (capabilities.length === 0) {\n return { code: 'bad_request', message: 'capabilities must not be empty' }\n }\n const unknownCapabilities = capabilities.filter(\n (capability) => typeof capability !== 'string' || !VALID_CAPABILITIES.has(capability),\n )\n if (unknownCapabilities.length > 0) {\n return {\n code: 'bad_request',\n message: `unknown capabilities: ${unknownCapabilities.map(String).join(', ')}`,\n }\n }\n return null\n}\n\n/**\n * Returns a frozen copy of a previously validated application-key capability list.\n *\n * @param capabilities - Validated caller-supplied capabilities.\n *\n * @returns An immutable capability list safe to store internally.\n */\nexport function normalizeCreateKeyCapabilities(\n capabilities: readonly Capability[],\n): readonly Capability[] {\n return Object.freeze([...capabilities])\n}\n\n/**\n * Validates application-key names against B2's documented length limits.\n *\n * @param keyName - Caller-supplied keyName.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-key\n */\nexport function validateCreateKeyName(keyName: unknown): ValidationError | null {\n if (typeof keyName !== 'string') {\n return { code: 'bad_request', message: 'keyName must be a string' }\n }\n if (keyName.length < KEY_NAME_MIN || keyName.length > KEY_NAME_MAX) {\n return {\n code: 'bad_request',\n message: `keyName must be ${KEY_NAME_MIN}-${KEY_NAME_MAX} characters`,\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Bucket name (`b2_create_bucket`, `b2_update_bucket`)\n// ---------------------------------------------------------------------------\n\nexport { BUCKET_NAME_MAX, BUCKET_NAME_MIN }\n\n/**\n * Validates a bucket name against B2's documented rules.\n *\n * @param name - Caller-supplied bucket name.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-bucket\n */\nexport function validateBucketName(name: string): ValidationError | null {\n if (typeof name !== 'string' || name.length < BUCKET_NAME_MIN || name.length > BUCKET_NAME_MAX) {\n return {\n code: 'invalid_bucket_name',\n message: `bucketName must be ${BUCKET_NAME_MIN}-${BUCKET_NAME_MAX} characters`,\n }\n }\n if (isB2BucketNameIpv4Address(name)) {\n return {\n code: 'invalid_bucket_name',\n message: 'bucketName must not be formatted as an IPv4 address',\n }\n }\n if (!hasValidB2BucketNameShape(name)) {\n return {\n code: 'invalid_bucket_name',\n message:\n 'bucketName must contain only letters, digits, hyphens, and periods; cannot start or end with punctuation or contain consecutive periods',\n }\n }\n if (name.startsWith(BUCKET_NAME_RESERVED_PREFIX)) {\n return {\n code: 'invalid_bucket_name',\n message: `bucketName cannot start with the reserved prefix \"${BUCKET_NAME_RESERVED_PREFIX}\"`,\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// File name (every upload / hide / copy entry point)\n// ---------------------------------------------------------------------------\n\nexport { FILE_NAME_MAX_BYTES }\n\n/**\n * Validates a file name against B2's documented rules. Mirrors the\n * server-side checks B2 runs on `b2_upload_file` / `b2_hide_file` /\n * `b2_start_large_file` / `b2_copy_file` filename inputs.\n *\n * @param name - Caller-supplied file name (raw, unencoded).\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-upload-file\n */\nexport function validateFileName(name: string): ValidationError | null {\n if (typeof name !== 'string' || name.length === 0) {\n return { code: 'invalid_file_name', message: 'fileName must be a non-empty string' }\n }\n const byteLength = getB2FileNameByteLength(name)\n if (byteLength === null) {\n return {\n code: 'invalid_file_name',\n message: 'fileName exceeds the 1024-byte UTF-8 limit',\n }\n }\n if (hasB2FileNameControlCharacter(name)) {\n return {\n code: 'invalid_file_name',\n message: 'fileName must not contain control characters (U+0000-U+001F or U+007F)',\n }\n }\n // Path segments equal to `.` or `..` alone are illegal per B2 docs.\n // Embedded `..` within a segment (e.g. `a..b`) is fine, and a path\n // like `../foo` is fine because the SDK doesn't interpret it; only\n // bare `.` or `..` as a complete name is rejected.\n if (name === '.' || name === '..') {\n return {\n code: 'invalid_file_name',\n message: 'fileName cannot be exactly \".\" or \"..\"',\n }\n }\n // No leading or trailing slash, no `//`.\n if (name.startsWith('/') || name.endsWith('/') || name.includes('//')) {\n return {\n code: 'invalid_file_name',\n message: 'fileName cannot start with \"/\", end with \"/\", or contain \"//\"',\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// File-info / Bucket-info byte budget\n// ---------------------------------------------------------------------------\n\n/** Per-file fileInfo total size cap (sum of key+value bytes). */\nexport const FILE_INFO_TOTAL_MAX = 2048\n/** Per-key fileInfo value byte cap. */\nexport const FILE_INFO_VALUE_MAX = 2048\n/** Allowed key character set (case-insensitive). */\nconst FILE_INFO_KEY_REGEX = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Validates a `fileInfo` record against B2's byte-budget and\n * key-shape rules.\n *\n * @param info - Caller-supplied fileInfo record.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-upload-file\n */\nexport function validateFileInfo(info: Record<string, string>): ValidationError | null {\n let total = 0\n for (const [key, value] of Object.entries(info)) {\n if (!FILE_INFO_KEY_REGEX.test(key)) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo key \"${key}\" must match ^[a-zA-Z0-9_-]+$`,\n }\n }\n if (typeof value !== 'string') {\n return { code: 'invalid_file_info', message: `fileInfo value for \"${key}\" must be a string` }\n }\n const keyBytes = utf8Encoder.encode(key).byteLength\n const valueBytes = utf8Encoder.encode(value).byteLength\n if (valueBytes > FILE_INFO_VALUE_MAX) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo value for \"${key}\" exceeds ${FILE_INFO_VALUE_MAX} bytes`,\n }\n }\n total += keyBytes + valueBytes\n }\n if (total > FILE_INFO_TOTAL_MAX) {\n return {\n code: 'invalid_file_info',\n message: `fileInfo total size ${total} bytes exceeds the ${FILE_INFO_TOTAL_MAX}-byte limit`,\n }\n }\n return null\n}\n\n/** Per-bucket bucketInfo total max keys. */\nexport const BUCKET_INFO_MAX_KEYS = 10\n/** Per-key bucketInfo value byte cap. */\nexport const BUCKET_INFO_VALUE_MAX = 2048\n/** Allowed key character set for bucketInfo. */\nconst BUCKET_INFO_KEY_REGEX = /^[a-zA-Z0-9_-]+$/\n\n/**\n * Validates a `bucketInfo` record against B2's per-bucket metadata rules.\n *\n * @param info - Caller-supplied bucketInfo record.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-create-bucket\n */\nexport function validateBucketInfo(info: Record<string, string>): ValidationError | null {\n const entries = Object.entries(info)\n if (entries.length > BUCKET_INFO_MAX_KEYS) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo cannot have more than ${BUCKET_INFO_MAX_KEYS} keys (got ${entries.length})`,\n }\n }\n for (const [key, value] of entries) {\n if (!BUCKET_INFO_KEY_REGEX.test(key)) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo key \"${key}\" must match ^[a-zA-Z0-9_-]+$`,\n }\n }\n if (typeof value !== 'string') {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo value for \"${key}\" must be a string`,\n }\n }\n const valueBytes = utf8Encoder.encode(value).byteLength\n if (valueBytes > BUCKET_INFO_VALUE_MAX) {\n return {\n code: 'invalid_bucket_info',\n message: `bucketInfo value for \"${key}\" exceeds ${BUCKET_INFO_VALUE_MAX} bytes`,\n }\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// maxFileCount caps per endpoint\n// ---------------------------------------------------------------------------\n\n/**\n * Per-endpoint upper bound on the `maxFileCount` (or `maxKeyCount` /\n * `maxPartCount`) request field. Sourced from the B2 endpoint docs.\n */\nexport const LIST_ENDPOINT_CAPS = {\n /** `b2_list_file_names.maxFileCount` cap. */\n b2_list_file_names: 10_000,\n /** `b2_list_file_versions.maxFileCount` cap. */\n b2_list_file_versions: 10_000,\n /** `b2_list_unfinished_large_files.maxFileCount` cap. */\n b2_list_unfinished_large_files: 100,\n /** `b2_list_keys.maxKeyCount` cap. */\n b2_list_keys: 10_000,\n /** `b2_list_parts.maxPartCount` cap. */\n b2_list_parts: 10_000,\n} as const\n\n/**\n * Validates a `maxFileCount` (or `maxKeyCount` / `maxPartCount`) value\n * against the per-endpoint cap documented by B2.\n *\n * @param requested - Caller-supplied count.\n * @param endpoint - Which list endpoint this applies to.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n */\nexport function validateMaxCount(\n requested: number | undefined,\n endpoint: keyof typeof LIST_ENDPOINT_CAPS,\n): ValidationError | null {\n if (requested === undefined) return null\n if (!Number.isInteger(requested) || requested < 1) {\n return {\n code: 'bad_request',\n message: `maxFileCount must be a positive integer (got ${requested})`,\n }\n }\n const cap = LIST_ENDPOINT_CAPS[endpoint]\n if (requested > cap) {\n return {\n code: 'bad_request',\n message: `maxFileCount ${requested} exceeds the ${endpoint} cap of ${cap}`,\n }\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Download authorization duration\n// ---------------------------------------------------------------------------\n\n/** Minimum `b2_get_download_authorization.validDurationInSeconds`. */\nexport const DOWNLOAD_AUTH_DURATION_MIN_SECONDS = 1\n/** Maximum `b2_get_download_authorization.validDurationInSeconds`. */\nexport const DOWNLOAD_AUTH_DURATION_MAX_SECONDS = 604_800\n\n/**\n * Validates a `b2_get_download_authorization` duration against B2's\n * documented inclusive 1-second to 7-day range.\n *\n * @param requested - Caller-supplied duration in seconds.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n */\nexport function validateDownloadAuthorizationDuration(requested: unknown): ValidationError | null {\n if (\n typeof requested !== 'number' ||\n !Number.isInteger(requested) ||\n requested < DOWNLOAD_AUTH_DURATION_MIN_SECONDS ||\n requested > DOWNLOAD_AUTH_DURATION_MAX_SECONDS\n ) {\n return {\n code: 'bad_request',\n message: `validDurationInSeconds must be an integer from ${DOWNLOAD_AUTH_DURATION_MIN_SECONDS} through ${DOWNLOAD_AUTH_DURATION_MAX_SECONDS}`,\n }\n }\n return null\n}\n\n/**\n * Validates a `b2_get_download_authorization` file name prefix.\n *\n * B2 allows an empty prefix, but the field must still be present as a\n * string so later prefix checks cannot crash on malformed request bodies.\n *\n * @param requested - Caller-supplied file name prefix.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n */\nexport function validateDownloadAuthorizationPrefix(requested: unknown): ValidationError | null {\n if (typeof requested !== 'string') {\n return { code: 'bad_request', message: 'fileNamePrefix must be a string' }\n }\n return null\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction validateKnownFields(\n value: Record<string, unknown>,\n allowedFields: ReadonlySet<string>,\n path: string,\n): ValidationError | null {\n for (const field of Object.keys(value)) {\n if (!allowedFields.has(field)) {\n return {\n code: 'bad_request',\n message: `${path}.${field} is not a supported field`,\n }\n }\n }\n return null\n}\n\nfunction validateStringArray(\n value: unknown,\n path: string,\n options: { readonly allowNull?: boolean; readonly requireNonEmpty?: boolean } = {},\n): ValidationError | null {\n if (value === null && options.allowNull === true) return null\n if (!Array.isArray(value)) {\n return { code: 'bad_request', message: `${path} must be an array of strings` }\n }\n if (options.requireNonEmpty === true && value.length === 0) {\n return { code: 'bad_request', message: `${path} must be a non-empty array` }\n }\n for (const [index, item] of value.entries()) {\n if (typeof item !== 'string') {\n return { code: 'bad_request', message: `${path}[${index}] must be a string` }\n }\n }\n return null\n}\n\nfunction validateNonEmptyString(value: unknown, path: string): ValidationError | null {\n if (typeof value !== 'string' || value.length === 0) {\n return { code: 'bad_request', message: `${path} must be a non-empty string` }\n }\n return null\n}\n\nfunction validateNonNegativeInteger(value: unknown, path: string): ValidationError | null {\n if (typeof value !== 'number' || !Number.isInteger(value) || value < 0) {\n return { code: 'bad_request', message: `${path} must be a non-negative integer` }\n }\n return null\n}\n\nfunction validateIntegerAtMost(value: number, max: number, path: string): ValidationError | null {\n if (value > max) {\n return { code: 'bad_request', message: `${path} must not exceed ${max}` }\n }\n return null\n}\n\nfunction validatePositiveInteger(value: unknown, path: string): ValidationError | null {\n if (typeof value !== 'number' || !Number.isInteger(value) || value < 1) {\n return { code: 'bad_request', message: `${path} must be a positive integer` }\n }\n return null\n}\n\nfunction validateNullablePositiveInteger(value: unknown, path: string): ValidationError | null {\n if (value === undefined || value === null) return null\n return validatePositiveInteger(value, path)\n}\n\nfunction validateUniqueName(\n names: Set<string>,\n name: string,\n path: string,\n): ValidationError | null {\n if (names.has(name)) {\n return { code: 'bad_request', message: `${path} must be unique` }\n }\n names.add(name)\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Bucket configuration (`b2_create_bucket`, `b2_update_bucket`)\n// ---------------------------------------------------------------------------\n\nconst KNOWN_BUCKET_TYPES = new Set<string>(Object.values(BucketType))\n\n/**\n * Validates a `b2_list_buckets.bucketTypes` filter.\n *\n * @param bucketTypes - Caller-supplied bucket type filter.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-list-buckets\n */\nexport function validateBucketTypes(bucketTypes: unknown): ValidationError | null {\n if (bucketTypes === undefined) return null\n if (!Array.isArray(bucketTypes)) {\n return { code: 'bad_request', message: 'bucketTypes must be an array' }\n }\n for (const [index, bucketType] of bucketTypes.entries()) {\n if (typeof bucketType !== 'string' || !KNOWN_BUCKET_TYPES.has(bucketType)) {\n return {\n code: 'bad_request',\n message: `bucketTypes[${index}] must be a known bucket type`,\n }\n }\n }\n return null\n}\n\nconst CORS_RULE_FIELDS = new Set([\n 'allowedHeaders',\n 'allowedOperations',\n 'allowedOrigins',\n 'corsRuleName',\n 'exposeHeaders',\n 'maxAgeSeconds',\n])\n\nconst CORS_MAX_AGE_SECONDS_MAX = 86_400\nconst KNOWN_CORS_OPERATIONS = new Set<string>(Object.values(CorsOperation))\n\n/**\n * Validates B2 CORS rule structure for bucket create/update requests.\n *\n * @param rules - Caller-supplied CORS rules.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/docs/cloud-storage-cross-origin-resource-sharing-rules\n */\nexport function validateCorsRules(rules: unknown): ValidationError | null {\n if (!Array.isArray(rules)) {\n return { code: 'bad_request', message: 'corsRules must be an array' }\n }\n\n const names = new Set<string>()\n for (const [index, rule] of rules.entries()) {\n const rulePath = `corsRules[${index}]`\n if (!isRecord(rule)) {\n return { code: 'bad_request', message: `${rulePath} must be an object` }\n }\n\n const fieldError = validateKnownFields(rule, CORS_RULE_FIELDS, rulePath)\n if (fieldError) return fieldError\n\n const nameError = validateNonEmptyString(rule['corsRuleName'], `${rulePath}.corsRuleName`)\n if (nameError) return nameError\n const ruleName = rule['corsRuleName'] as string\n const uniqueNameError = validateUniqueName(names, ruleName, `${rulePath}.corsRuleName`)\n if (uniqueNameError) return uniqueNameError\n\n const originsError = validateStringArray(rule['allowedOrigins'], `${rulePath}.allowedOrigins`, {\n requireNonEmpty: true,\n })\n if (originsError) return originsError\n\n const operationsError = validateStringArray(\n rule['allowedOperations'],\n `${rulePath}.allowedOperations`,\n { requireNonEmpty: true },\n )\n if (operationsError) return operationsError\n for (const operation of rule['allowedOperations'] as readonly string[]) {\n if (!KNOWN_CORS_OPERATIONS.has(operation)) {\n return {\n code: 'bad_request',\n message: `${rulePath}.allowedOperations contains an unknown operation`,\n }\n }\n }\n\n const headersError = validateStringArray(rule['allowedHeaders'], `${rulePath}.allowedHeaders`, {\n allowNull: true,\n })\n if (headersError) return headersError\n\n const exposeError = validateStringArray(rule['exposeHeaders'], `${rulePath}.exposeHeaders`, {\n allowNull: true,\n })\n if (exposeError) return exposeError\n\n const ageError = validateNonNegativeInteger(rule['maxAgeSeconds'], `${rulePath}.maxAgeSeconds`)\n if (ageError) return ageError\n const maxAgeError = validateIntegerAtMost(\n rule['maxAgeSeconds'] as number,\n CORS_MAX_AGE_SECONDS_MAX,\n `${rulePath}.maxAgeSeconds`,\n )\n if (maxAgeError) return maxAgeError\n }\n\n return null\n}\n\nconst LIFECYCLE_RULE_FIELDS = new Set([\n 'daysFromHidingToDeleting',\n 'daysFromStartingToCancelingUnfinishedLargeFiles',\n 'daysFromUploadingToHiding',\n 'fileNamePrefix',\n])\n\n/**\n * Validates B2 lifecycle rule structure for bucket create/update requests.\n *\n * @param rules - Caller-supplied lifecycle rules.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/docs/cloud-storage-lifecycle-rules\n */\nexport function validateLifecycleRules(rules: unknown): ValidationError | null {\n if (!Array.isArray(rules)) {\n return { code: 'bad_request', message: 'lifecycleRules must be an array' }\n }\n\n for (const [index, rule] of rules.entries()) {\n const rulePath = `lifecycleRules[${index}]`\n if (!isRecord(rule)) {\n return { code: 'bad_request', message: `${rulePath} must be an object` }\n }\n\n const fieldError = validateKnownFields(rule, LIFECYCLE_RULE_FIELDS, rulePath)\n if (fieldError) return fieldError\n\n const deletingError = validateNullablePositiveInteger(\n rule['daysFromHidingToDeleting'],\n `${rulePath}.daysFromHidingToDeleting`,\n )\n if (deletingError) return deletingError\n\n const hidingError = validateNullablePositiveInteger(\n rule['daysFromUploadingToHiding'],\n `${rulePath}.daysFromUploadingToHiding`,\n )\n if (hidingError) return hidingError\n\n const cancelError = validateNullablePositiveInteger(\n rule['daysFromStartingToCancelingUnfinishedLargeFiles'],\n `${rulePath}.daysFromStartingToCancelingUnfinishedLargeFiles`,\n )\n if (cancelError) return cancelError\n\n if (\n rule['daysFromHidingToDeleting'] == null &&\n rule['daysFromUploadingToHiding'] == null &&\n rule['daysFromStartingToCancelingUnfinishedLargeFiles'] == null\n ) {\n return {\n code: 'bad_request',\n message: `${rulePath} must set at least one lifecycle action`,\n }\n }\n\n if (typeof rule['fileNamePrefix'] !== 'string') {\n return { code: 'bad_request', message: `${rulePath}.fileNamePrefix must be a string` }\n }\n }\n\n return null\n}\n\nconst DEFAULT_RETENTION_FIELDS = new Set(['mode', 'period'])\nconst RETENTION_PERIOD_FIELDS = new Set(['duration', 'unit'])\nconst DEFAULT_RETENTION_MODES = new Set<string>(Object.values(BucketRetentionMode))\nconst OBJECT_LOCK_RETENTION_MAX_DAYS = 3000\n\n/**\n * Validates default Object Lock retention policy structure for bucket requests.\n *\n * @param policy - Caller-supplied default retention policy.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/docs/cloud-storage-object-lock\n */\nexport function validateDefaultRetention(policy: unknown): ValidationError | null {\n if (!isRecord(policy)) {\n return { code: 'bad_request', message: 'defaultRetention must be an object' }\n }\n\n const fieldError = validateKnownFields(policy, DEFAULT_RETENTION_FIELDS, 'defaultRetention')\n if (fieldError) return fieldError\n\n const mode = policy['mode']\n if (typeof mode !== 'string' || !DEFAULT_RETENTION_MODES.has(mode)) {\n return {\n code: 'bad_request',\n message: 'defaultRetention.mode must be \"compliance\", \"governance\", or \"none\"',\n }\n }\n\n const period = policy['period']\n if (mode === BucketRetentionMode.None) {\n if (period !== null) {\n return {\n code: 'bad_request',\n message: 'defaultRetention.period must be null when mode is \"none\"',\n }\n }\n return null\n }\n\n if (!isRecord(period)) {\n return {\n code: 'bad_request',\n message: 'defaultRetention.period must be an object for retention modes',\n }\n }\n\n const periodFieldError = validateKnownFields(\n period,\n RETENTION_PERIOD_FIELDS,\n 'defaultRetention.period',\n )\n if (periodFieldError) return periodFieldError\n\n const durationError = validatePositiveInteger(\n period['duration'],\n 'defaultRetention.period.duration',\n )\n if (durationError) return durationError\n if (!Number.isSafeInteger(period['duration'])) {\n return {\n code: 'bad_request',\n message: 'defaultRetention.period.duration must be a safe integer',\n }\n }\n\n if (period['unit'] !== 'days' && period['unit'] !== 'years') {\n return {\n code: 'bad_request',\n message: 'defaultRetention.period.unit must be \"days\" or \"years\"',\n }\n }\n const durationDays =\n period['unit'] === 'days'\n ? (period['duration'] as number)\n : (period['duration'] as number) * 365\n if (!Number.isFinite(durationDays) || durationDays > OBJECT_LOCK_RETENTION_MAX_DAYS) {\n return {\n code: 'bad_request',\n message: `defaultRetention.period must not exceed ${OBJECT_LOCK_RETENTION_MAX_DAYS} days`,\n }\n }\n\n return null\n}\n\nconst REPLICATION_CONFIG_FIELDS = new Set(['asReplicationSource', 'asReplicationDestination'])\nconst REPLICATION_SOURCE_FIELDS = new Set(['replicationRules', 'sourceApplicationKeyId'])\nconst REPLICATION_DESTINATION_FIELDS = new Set(['sourceToDestinationKeyMapping'])\nconst REPLICATION_RULE_FIELDS = new Set([\n 'destinationBucketId',\n 'fileNamePrefix',\n 'includeExistingFiles',\n 'isEnabled',\n 'priority',\n 'replicationRuleName',\n])\n\nfunction validateReplicationRule(rule: unknown, rulePath: string): ValidationError | null {\n if (!isRecord(rule)) {\n return { code: 'bad_request', message: `${rulePath} must be an object` }\n }\n\n const fieldError = validateKnownFields(rule, REPLICATION_RULE_FIELDS, rulePath)\n if (fieldError) return fieldError\n\n const destinationError = validateNonEmptyString(\n rule['destinationBucketId'],\n `${rulePath}.destinationBucketId`,\n )\n if (destinationError) return destinationError\n\n if (typeof rule['fileNamePrefix'] !== 'string') {\n return { code: 'bad_request', message: `${rulePath}.fileNamePrefix must be a string` }\n }\n\n if (typeof rule['includeExistingFiles'] !== 'boolean') {\n return { code: 'bad_request', message: `${rulePath}.includeExistingFiles must be a boolean` }\n }\n\n if (typeof rule['isEnabled'] !== 'boolean') {\n return { code: 'bad_request', message: `${rulePath}.isEnabled must be a boolean` }\n }\n\n const priorityError = validatePositiveInteger(rule['priority'], `${rulePath}.priority`)\n if (priorityError) return priorityError\n\n const nameError = validateNonEmptyString(\n rule['replicationRuleName'],\n `${rulePath}.replicationRuleName`,\n )\n if (nameError) return nameError\n\n return null\n}\n\nfunction validateReplicationSource(source: unknown): ValidationError | null {\n if (!isRecord(source)) {\n return {\n code: 'bad_request',\n message: 'replicationConfiguration.asReplicationSource must be an object',\n }\n }\n\n const fieldError = validateKnownFields(\n source,\n REPLICATION_SOURCE_FIELDS,\n 'replicationConfiguration.asReplicationSource',\n )\n if (fieldError) return fieldError\n\n const sourceKeyError = validateNonEmptyString(\n source['sourceApplicationKeyId'],\n 'replicationConfiguration.asReplicationSource.sourceApplicationKeyId',\n )\n if (sourceKeyError) return sourceKeyError\n\n const rules = source['replicationRules']\n if (!Array.isArray(rules)) {\n return {\n code: 'bad_request',\n message: 'replicationConfiguration.asReplicationSource.replicationRules must be an array',\n }\n }\n\n const names = new Set<string>()\n for (const [index, rule] of rules.entries()) {\n const rulePath = `replicationConfiguration.asReplicationSource.replicationRules[${index}]`\n const ruleError = validateReplicationRule(rule, rulePath)\n if (ruleError) return ruleError\n const ruleName = (rule as Record<string, unknown>)['replicationRuleName'] as string\n const uniqueNameError = validateUniqueName(names, ruleName, `${rulePath}.replicationRuleName`)\n if (uniqueNameError) return uniqueNameError\n }\n\n return null\n}\n\nfunction validateReplicationDestination(destination: unknown): ValidationError | null {\n if (!isRecord(destination)) {\n return {\n code: 'bad_request',\n message: 'replicationConfiguration.asReplicationDestination must be an object',\n }\n }\n\n const fieldError = validateKnownFields(\n destination,\n REPLICATION_DESTINATION_FIELDS,\n 'replicationConfiguration.asReplicationDestination',\n )\n if (fieldError) return fieldError\n\n const mapping = destination['sourceToDestinationKeyMapping']\n if (!isRecord(mapping)) {\n return {\n code: 'bad_request',\n message:\n 'replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping must be an object',\n }\n }\n\n for (const [sourceKey, destinationKey] of Object.entries(mapping)) {\n if (sourceKey.length === 0) {\n return {\n code: 'bad_request',\n message:\n 'replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping keys must be non-empty',\n }\n }\n if (typeof destinationKey !== 'string' || destinationKey.length === 0) {\n return {\n code: 'bad_request',\n message:\n 'replicationConfiguration.asReplicationDestination.sourceToDestinationKeyMapping values must be non-empty strings',\n }\n }\n }\n\n return null\n}\n\n/**\n * Validates B2 replication configuration structure for bucket requests.\n *\n * @param config - Caller-supplied replication configuration.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-update-bucket\n */\nexport function validateReplicationConfiguration(config: unknown): ValidationError | null {\n if (!isRecord(config)) {\n return { code: 'bad_request', message: 'replicationConfiguration must be an object' }\n }\n\n const fieldError = validateKnownFields(\n config,\n REPLICATION_CONFIG_FIELDS,\n 'replicationConfiguration',\n )\n if (fieldError) return fieldError\n\n if (!('asReplicationSource' in config) && !('asReplicationDestination' in config)) {\n return {\n code: 'bad_request',\n message:\n 'replicationConfiguration must include asReplicationSource or asReplicationDestination',\n }\n }\n\n const source = config['asReplicationSource']\n if (source !== undefined && source !== null) {\n const sourceError = validateReplicationSource(source)\n if (sourceError) return sourceError\n }\n\n const destination = config['asReplicationDestination']\n if (destination !== undefined && destination !== null) {\n const destinationError = validateReplicationDestination(destination)\n if (destinationError) return destinationError\n }\n\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Event notification rules (`b2_set_bucket_notification_rules`)\n// ---------------------------------------------------------------------------\n\nconst NOTIFICATION_RULE_FIELDS = new Set([\n 'eventTypes',\n 'isEnabled',\n 'isSuspended',\n 'maxEventsPerBatch',\n 'name',\n 'objectNamePrefix',\n 'suspensionReason',\n 'targetConfiguration',\n])\n\nconst NOTIFICATION_TARGET_FIELDS = new Set([\n 'customHeaders',\n 'hmacSha256SigningSecret',\n 'targetType',\n 'url',\n])\n\nconst KNOWN_NOTIFICATION_EVENT_TYPES = new Set<string>(Object.values(EventType))\n\n/**\n * Validates event notification rules for `b2_set_bucket_notification_rules`.\n *\n * @param rules - Caller-supplied event notification rules.\n *\n * @returns A `{ code, message }` pair on failure, or `null` when valid.\n *\n * @see https://www.backblaze.com/apidocs/b2-set-bucket-notification-rules\n */\nexport function validateNotificationRules(rules: unknown): ValidationError | null {\n if (!Array.isArray(rules)) {\n return {\n code: 'bad_request',\n message: 'eventNotificationRules must be an array',\n }\n }\n\n const names = new Set<string>()\n for (const [index, ruleValue] of rules.entries()) {\n const rulePath = `eventNotificationRules[${index}]`\n if (!isRecord(ruleValue)) {\n return { code: 'bad_request', message: `${rulePath} must be an object` }\n }\n\n const fieldError = validateKnownFields(ruleValue, NOTIFICATION_RULE_FIELDS, rulePath)\n if (fieldError) return fieldError\n\n if (typeof ruleValue['isEnabled'] !== 'boolean') {\n return {\n code: 'bad_request',\n message: `${rulePath}.isEnabled must be a boolean`,\n }\n }\n\n const maxEventsPerBatch = ruleValue['maxEventsPerBatch']\n if (\n maxEventsPerBatch !== undefined &&\n (typeof maxEventsPerBatch !== 'number' ||\n !Number.isInteger(maxEventsPerBatch) ||\n maxEventsPerBatch < 1)\n ) {\n return {\n code: 'bad_request',\n message: `${rulePath}.maxEventsPerBatch must be a positive integer`,\n }\n }\n\n const name = ruleValue['name']\n if (typeof name !== 'string' || name.length === 0) {\n return {\n code: 'bad_request',\n message: `${rulePath}.name must be a non-empty string`,\n }\n }\n if (names.has(name)) {\n return {\n code: 'bad_request',\n message: `${rulePath}.name must be unique within eventNotificationRules`,\n }\n }\n names.add(name)\n\n const eventTypes = ruleValue['eventTypes']\n if (!Array.isArray(eventTypes) || eventTypes.length === 0) {\n return {\n code: 'bad_request',\n message: `${rulePath}.eventTypes must be a non-empty array`,\n }\n }\n for (const eventType of eventTypes) {\n if (typeof eventType !== 'string' || !KNOWN_NOTIFICATION_EVENT_TYPES.has(eventType)) {\n return {\n code: 'bad_request',\n message: `${rulePath}.eventTypes contains an unknown event type`,\n }\n }\n }\n\n const targetConfiguration = ruleValue['targetConfiguration']\n if (!isRecord(targetConfiguration)) {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration must be an object`,\n }\n }\n\n const targetFieldError = validateKnownFields(\n targetConfiguration,\n NOTIFICATION_TARGET_FIELDS,\n `${rulePath}.targetConfiguration`,\n )\n if (targetFieldError) return targetFieldError\n\n if (targetConfiguration['targetType'] !== 'webhook') {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration.targetType must be \"webhook\"`,\n }\n }\n\n const url = targetConfiguration['url']\n if (typeof url !== 'string') {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration.url must be a valid https URL`,\n }\n }\n try {\n if (new URL(url).protocol !== 'https:') {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration.url must be a valid https URL`,\n }\n }\n } catch {\n return {\n code: 'bad_request',\n message: `${rulePath}.targetConfiguration.url must be a valid https URL`,\n }\n }\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,eAAe;;AAE5B,IAAa,eAAe;AAE5B,IAAM,qBAAqB,IAAI,IAAY,OAAO,OAAO,aAAA,UAAU,CAAC;;;;;;;;;;AAWpE,SAAgB,8BAA8B,cAA+C;CAC3F,IAAI,CAAC,MAAM,QAAQ,YAAY,GAC7B,OAAO;EAAE,MAAM;EAAe,SAAS;CAAgC;CAEzE,IAAI,aAAa,WAAW,GAC1B,OAAO;EAAE,MAAM;EAAe,SAAS;CAAiC;CAE1E,MAAM,sBAAsB,aAAa,QACtC,eAAe,OAAO,eAAe,YAAY,CAAC,mBAAmB,IAAI,UAAU,CACtF;CACA,IAAI,oBAAoB,SAAS,GAC/B,OAAO;EACL,MAAM;EACN,SAAS,yBAAyB,oBAAoB,IAAI,MAAM,CAAC,CAAC,KAAK,IAAI;CAC7E;CAEF,OAAO;AACT;;;;;;;;AASA,SAAgB,+BACd,cACuB;CACvB,OAAO,OAAO,OAAO,CAAC,GAAG,YAAY,CAAC;AACxC;;;;;;;;;;AAWA,SAAgB,sBAAsB,SAA0C;CAC9E,IAAI,OAAO,YAAY,UACrB,OAAO;EAAE,MAAM;EAAe,SAAS;CAA2B;CAEpE,IAAI,QAAQ,SAAA,KAAyB,QAAQ,SAAA,K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,SAAS,GAAG,SAAS;EACvB;EAEF,IAAI,MAAM,IAAI,IAAI,GAChB,OAAO;GACL,MAAM;GACN,SAAS,GAAG,SAAS;EACvB;EAEF,MAAM,IAAI,IAAI;EAEd,MAAM,aAAa,UAAU;EAC7B,IAAI,CAAC,MAAM,QAAQ,UAAU,KAAK,WAAW,WAAW,GACtD,OAAO;GACL,MAAM;GACN,SAAS,GAAG,SAAS;EACvB;EAEF,KAAK,MAAM,aAAa,YACtB,IAAI,OAAO,cAAc,YAAY,CAAC,+BAA+B,IAAI,SAAS,GAChF,OAAO;GACL,MAAM;GACN,SAAS,GAAG,SAAS;EACvB;EAIJ,MAAM,sBAAsB,UAAU;EACtC,IAAI,CAAC,SAAS,mBAAmB,GAC/B,OAAO;GACL,MAAM;GACN,SAAS,GAAG,SAAS;EACvB;EAGF,MAAM,mBAAmB,oBACvB,qBACA,4BACA,GAAG,SAAS,qBACd;EACA,IAAI,kBAAkB,OAAO;EAE7B,IAAI,oBAAoB,kBAAkB,WACxC,OAAO;GACL,MAAM;GACN,SAAS,GAAG,SAAS;EACvB;EAGF,MAAM,MAAM,oBAAoB;EAChC,IAAI,OAAO,QAAQ,UACjB,OAAO;GACL,MAAM;GACN,SAAS,GAAG,SAAS;EACvB;EAEF,IAAI;GACF,IAAI,IAAI,IAAI,GAAG,CAAC,CAAC,aAAa,UAC5B,OAAO;IACL,MAAM;IACN,SAAS,GAAG,SAAS;GACvB;EAEJ,QAAQ;GACN,OAAO;IACL,MAAM;IACN,SAAS,GAAG,SAAS;GACvB;EACF;CACF;CAEA,OAAO;AACT"}
@@ -1,9 +1,42 @@
1
1
  import { BUCKET_NAME_MAX, BUCKET_NAME_MIN, FILE_NAME_MAX_BYTES } from '../internal/b2-naming.js';
2
+ import { Capability } from '../types/auth.js';
2
3
  /** Shape returned by validation functions when input is rejected. */
3
4
  export interface ValidationError {
4
5
  readonly code: string;
5
6
  readonly message: string;
6
7
  }
8
+ /** Minimum length for application key names. */
9
+ export declare const KEY_NAME_MIN = 1;
10
+ /** Maximum length for application key names. */
11
+ export declare const KEY_NAME_MAX = 100;
12
+ /**
13
+ * Validates application-key capabilities against B2's supported capability set.
14
+ *
15
+ * @param capabilities - Caller-supplied capabilities array.
16
+ *
17
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
18
+ *
19
+ * @see https://www.backblaze.com/apidocs/b2-create-key
20
+ */
21
+ export declare function validateCreateKeyCapabilities(capabilities: unknown): ValidationError | null;
22
+ /**
23
+ * Returns a frozen copy of a previously validated application-key capability list.
24
+ *
25
+ * @param capabilities - Validated caller-supplied capabilities.
26
+ *
27
+ * @returns An immutable capability list safe to store internally.
28
+ */
29
+ export declare function normalizeCreateKeyCapabilities(capabilities: readonly Capability[]): readonly Capability[];
30
+ /**
31
+ * Validates application-key names against B2's documented length limits.
32
+ *
33
+ * @param keyName - Caller-supplied keyName.
34
+ *
35
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
36
+ *
37
+ * @see https://www.backblaze.com/apidocs/b2-create-key
38
+ */
39
+ export declare function validateCreateKeyName(keyName: unknown): ValidationError | null;
7
40
  export { BUCKET_NAME_MAX, BUCKET_NAME_MIN };
8
41
  /**
9
42
  * Validates a bucket name against B2's documented rules.
@@ -83,4 +116,88 @@ export declare const LIST_ENDPOINT_CAPS: {
83
116
  * @returns A `{ code, message }` pair on failure, or `null` when valid.
84
117
  */
85
118
  export declare function validateMaxCount(requested: number | undefined, endpoint: keyof typeof LIST_ENDPOINT_CAPS): ValidationError | null;
119
+ /** Minimum `b2_get_download_authorization.validDurationInSeconds`. */
120
+ export declare const DOWNLOAD_AUTH_DURATION_MIN_SECONDS = 1;
121
+ /** Maximum `b2_get_download_authorization.validDurationInSeconds`. */
122
+ export declare const DOWNLOAD_AUTH_DURATION_MAX_SECONDS = 604800;
123
+ /**
124
+ * Validates a `b2_get_download_authorization` duration against B2's
125
+ * documented inclusive 1-second to 7-day range.
126
+ *
127
+ * @param requested - Caller-supplied duration in seconds.
128
+ *
129
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
130
+ */
131
+ export declare function validateDownloadAuthorizationDuration(requested: unknown): ValidationError | null;
132
+ /**
133
+ * Validates a `b2_get_download_authorization` file name prefix.
134
+ *
135
+ * B2 allows an empty prefix, but the field must still be present as a
136
+ * string so later prefix checks cannot crash on malformed request bodies.
137
+ *
138
+ * @param requested - Caller-supplied file name prefix.
139
+ *
140
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
141
+ */
142
+ export declare function validateDownloadAuthorizationPrefix(requested: unknown): ValidationError | null;
143
+ /**
144
+ * Validates a `b2_list_buckets.bucketTypes` filter.
145
+ *
146
+ * @param bucketTypes - Caller-supplied bucket type filter.
147
+ *
148
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
149
+ *
150
+ * @see https://www.backblaze.com/apidocs/b2-list-buckets
151
+ */
152
+ export declare function validateBucketTypes(bucketTypes: unknown): ValidationError | null;
153
+ /**
154
+ * Validates B2 CORS rule structure for bucket create/update requests.
155
+ *
156
+ * @param rules - Caller-supplied CORS rules.
157
+ *
158
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
159
+ *
160
+ * @see https://www.backblaze.com/docs/cloud-storage-cross-origin-resource-sharing-rules
161
+ */
162
+ export declare function validateCorsRules(rules: unknown): ValidationError | null;
163
+ /**
164
+ * Validates B2 lifecycle rule structure for bucket create/update requests.
165
+ *
166
+ * @param rules - Caller-supplied lifecycle rules.
167
+ *
168
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
169
+ *
170
+ * @see https://www.backblaze.com/docs/cloud-storage-lifecycle-rules
171
+ */
172
+ export declare function validateLifecycleRules(rules: unknown): ValidationError | null;
173
+ /**
174
+ * Validates default Object Lock retention policy structure for bucket requests.
175
+ *
176
+ * @param policy - Caller-supplied default retention policy.
177
+ *
178
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
179
+ *
180
+ * @see https://www.backblaze.com/docs/cloud-storage-object-lock
181
+ */
182
+ export declare function validateDefaultRetention(policy: unknown): ValidationError | null;
183
+ /**
184
+ * Validates B2 replication configuration structure for bucket requests.
185
+ *
186
+ * @param config - Caller-supplied replication configuration.
187
+ *
188
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
189
+ *
190
+ * @see https://www.backblaze.com/apidocs/b2-update-bucket
191
+ */
192
+ export declare function validateReplicationConfiguration(config: unknown): ValidationError | null;
193
+ /**
194
+ * Validates event notification rules for `b2_set_bucket_notification_rules`.
195
+ *
196
+ * @param rules - Caller-supplied event notification rules.
197
+ *
198
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
199
+ *
200
+ * @see https://www.backblaze.com/apidocs/b2-set-bucket-notification-rules
201
+ */
202
+ export declare function validateNotificationRules(rules: unknown): ValidationError | null;
86
203
  //# sourceMappingURL=validation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/simulator/validation.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,eAAe,EACf,eAAe,EAEf,mBAAmB,EAKpB,MAAM,0BAA0B,CAAA;AAGjC,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAMD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,CAAA;AAE3C;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA2BvE;AAMD,OAAO,EAAE,mBAAmB,EAAE,CAAA;AAE9B;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAmCrE;AAMD,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,OAAO,CAAA;AACvC,uCAAuC;AACvC,eAAO,MAAM,mBAAmB,OAAO,CAAA;AAIvC;;;;;;;;;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EAAsE;AACtE,eAAO,MAAM,kCAAkC,IAAI,CAAA;AACnD,sEAAsE;AACtE,eAAO,MAAM,kCAAkC,SAAU,CAAA;AAEzD;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CAAC,SAAS,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAahG;AAED;;;;;;;;;GASG;AACH,wBAAgB,mCAAmC,CAAC,SAAS,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAK9F;AA6FD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAchF;AAcD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CA8DxE;AASD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAiD7E;AAOD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAuEhF;AA0ID;;;;;;;;GAQG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAiCxF;AA0BD;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAkHhF"}
@@ -1,9 +1,42 @@
1
1
  import { BUCKET_NAME_MAX, BUCKET_NAME_MIN, FILE_NAME_MAX_BYTES } from '../internal/b2-naming.js';
2
+ import { Capability } from '../types/auth.js';
2
3
  /** Shape returned by validation functions when input is rejected. */
3
4
  export interface ValidationError {
4
5
  readonly code: string;
5
6
  readonly message: string;
6
7
  }
8
+ /** Minimum length for application key names. */
9
+ export declare const KEY_NAME_MIN = 1;
10
+ /** Maximum length for application key names. */
11
+ export declare const KEY_NAME_MAX = 100;
12
+ /**
13
+ * Validates application-key capabilities against B2's supported capability set.
14
+ *
15
+ * @param capabilities - Caller-supplied capabilities array.
16
+ *
17
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
18
+ *
19
+ * @see https://www.backblaze.com/apidocs/b2-create-key
20
+ */
21
+ export declare function validateCreateKeyCapabilities(capabilities: unknown): ValidationError | null;
22
+ /**
23
+ * Returns a frozen copy of a previously validated application-key capability list.
24
+ *
25
+ * @param capabilities - Validated caller-supplied capabilities.
26
+ *
27
+ * @returns An immutable capability list safe to store internally.
28
+ */
29
+ export declare function normalizeCreateKeyCapabilities(capabilities: readonly Capability[]): readonly Capability[];
30
+ /**
31
+ * Validates application-key names against B2's documented length limits.
32
+ *
33
+ * @param keyName - Caller-supplied keyName.
34
+ *
35
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
36
+ *
37
+ * @see https://www.backblaze.com/apidocs/b2-create-key
38
+ */
39
+ export declare function validateCreateKeyName(keyName: unknown): ValidationError | null;
7
40
  export { BUCKET_NAME_MAX, BUCKET_NAME_MIN };
8
41
  /**
9
42
  * Validates a bucket name against B2's documented rules.
@@ -83,4 +116,88 @@ export declare const LIST_ENDPOINT_CAPS: {
83
116
  * @returns A `{ code, message }` pair on failure, or `null` when valid.
84
117
  */
85
118
  export declare function validateMaxCount(requested: number | undefined, endpoint: keyof typeof LIST_ENDPOINT_CAPS): ValidationError | null;
119
+ /** Minimum `b2_get_download_authorization.validDurationInSeconds`. */
120
+ export declare const DOWNLOAD_AUTH_DURATION_MIN_SECONDS = 1;
121
+ /** Maximum `b2_get_download_authorization.validDurationInSeconds`. */
122
+ export declare const DOWNLOAD_AUTH_DURATION_MAX_SECONDS = 604800;
123
+ /**
124
+ * Validates a `b2_get_download_authorization` duration against B2's
125
+ * documented inclusive 1-second to 7-day range.
126
+ *
127
+ * @param requested - Caller-supplied duration in seconds.
128
+ *
129
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
130
+ */
131
+ export declare function validateDownloadAuthorizationDuration(requested: unknown): ValidationError | null;
132
+ /**
133
+ * Validates a `b2_get_download_authorization` file name prefix.
134
+ *
135
+ * B2 allows an empty prefix, but the field must still be present as a
136
+ * string so later prefix checks cannot crash on malformed request bodies.
137
+ *
138
+ * @param requested - Caller-supplied file name prefix.
139
+ *
140
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
141
+ */
142
+ export declare function validateDownloadAuthorizationPrefix(requested: unknown): ValidationError | null;
143
+ /**
144
+ * Validates a `b2_list_buckets.bucketTypes` filter.
145
+ *
146
+ * @param bucketTypes - Caller-supplied bucket type filter.
147
+ *
148
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
149
+ *
150
+ * @see https://www.backblaze.com/apidocs/b2-list-buckets
151
+ */
152
+ export declare function validateBucketTypes(bucketTypes: unknown): ValidationError | null;
153
+ /**
154
+ * Validates B2 CORS rule structure for bucket create/update requests.
155
+ *
156
+ * @param rules - Caller-supplied CORS rules.
157
+ *
158
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
159
+ *
160
+ * @see https://www.backblaze.com/docs/cloud-storage-cross-origin-resource-sharing-rules
161
+ */
162
+ export declare function validateCorsRules(rules: unknown): ValidationError | null;
163
+ /**
164
+ * Validates B2 lifecycle rule structure for bucket create/update requests.
165
+ *
166
+ * @param rules - Caller-supplied lifecycle rules.
167
+ *
168
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
169
+ *
170
+ * @see https://www.backblaze.com/docs/cloud-storage-lifecycle-rules
171
+ */
172
+ export declare function validateLifecycleRules(rules: unknown): ValidationError | null;
173
+ /**
174
+ * Validates default Object Lock retention policy structure for bucket requests.
175
+ *
176
+ * @param policy - Caller-supplied default retention policy.
177
+ *
178
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
179
+ *
180
+ * @see https://www.backblaze.com/docs/cloud-storage-object-lock
181
+ */
182
+ export declare function validateDefaultRetention(policy: unknown): ValidationError | null;
183
+ /**
184
+ * Validates B2 replication configuration structure for bucket requests.
185
+ *
186
+ * @param config - Caller-supplied replication configuration.
187
+ *
188
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
189
+ *
190
+ * @see https://www.backblaze.com/apidocs/b2-update-bucket
191
+ */
192
+ export declare function validateReplicationConfiguration(config: unknown): ValidationError | null;
193
+ /**
194
+ * Validates event notification rules for `b2_set_bucket_notification_rules`.
195
+ *
196
+ * @param rules - Caller-supplied event notification rules.
197
+ *
198
+ * @returns A `{ code, message }` pair on failure, or `null` when valid.
199
+ *
200
+ * @see https://www.backblaze.com/apidocs/b2-set-bucket-notification-rules
201
+ */
202
+ export declare function validateNotificationRules(rules: unknown): ValidationError | null;
86
203
  //# sourceMappingURL=validation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/simulator/validation.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,eAAe,EACf,eAAe,EAEf,mBAAmB,EAKpB,MAAM,0BAA0B,CAAA;AAGjC,qEAAqE;AACrE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAMD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,CAAA;AAE3C;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA2BvE;AAMD,OAAO,EAAE,mBAAmB,EAAE,CAAA;AAE9B;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAmCrE;AAMD,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,OAAO,CAAA;AACvC,uCAAuC;AACvC,eAAO,MAAM,mBAAmB,OAAO,CAAA;AAIvC;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,eAAe,GAAG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