@roarkanalytics/sdk 2.20.0 → 2.21.1

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 (419) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +83 -45
  3. package/api-promise.d.mts +47 -0
  4. package/api-promise.d.mts.map +1 -0
  5. package/api-promise.d.ts +47 -0
  6. package/api-promise.d.ts.map +1 -0
  7. package/api-promise.js +84 -0
  8. package/api-promise.js.map +1 -0
  9. package/api-promise.mjs +80 -0
  10. package/api-promise.mjs.map +1 -0
  11. package/client.d.mts +201 -0
  12. package/client.d.mts.map +1 -0
  13. package/client.d.ts +201 -0
  14. package/client.d.ts.map +1 -0
  15. package/client.js +454 -0
  16. package/client.js.map +1 -0
  17. package/client.mjs +427 -0
  18. package/client.mjs.map +1 -0
  19. package/error.d.mts +47 -0
  20. package/error.d.mts.map +1 -0
  21. package/error.d.ts +1 -1
  22. package/error.d.ts.map +1 -1
  23. package/error.js +2 -2
  24. package/error.js.map +1 -1
  25. package/error.mjs +1 -1
  26. package/error.mjs.map +1 -1
  27. package/index.d.mts +4 -130
  28. package/index.d.mts.map +1 -0
  29. package/index.d.ts +4 -130
  30. package/index.d.ts.map +1 -1
  31. package/index.js +10 -128
  32. package/index.js.map +1 -1
  33. package/index.mjs +4 -102
  34. package/index.mjs.map +1 -1
  35. package/internal/builtin-types.d.mts +65 -0
  36. package/internal/builtin-types.d.mts.map +1 -0
  37. package/internal/builtin-types.d.ts +65 -0
  38. package/internal/builtin-types.d.ts.map +1 -0
  39. package/internal/builtin-types.js +4 -0
  40. package/internal/builtin-types.js.map +1 -0
  41. package/internal/builtin-types.mjs +3 -0
  42. package/internal/builtin-types.mjs.map +1 -0
  43. package/internal/detect-platform.d.mts +15 -0
  44. package/internal/detect-platform.d.mts.map +1 -0
  45. package/internal/detect-platform.d.ts +15 -0
  46. package/internal/detect-platform.d.ts.map +1 -0
  47. package/internal/detect-platform.js +162 -0
  48. package/internal/detect-platform.js.map +1 -0
  49. package/internal/detect-platform.mjs +157 -0
  50. package/internal/detect-platform.mjs.map +1 -0
  51. package/internal/errors.d.mts +3 -0
  52. package/internal/errors.d.mts.map +1 -0
  53. package/internal/errors.d.ts +3 -0
  54. package/internal/errors.d.ts.map +1 -0
  55. package/internal/errors.js +26 -0
  56. package/internal/errors.js.map +1 -0
  57. package/internal/errors.mjs +21 -0
  58. package/internal/errors.mjs.map +1 -0
  59. package/internal/headers.d.mts +21 -0
  60. package/internal/headers.d.mts.map +1 -0
  61. package/internal/headers.d.ts +21 -0
  62. package/internal/headers.d.ts.map +1 -0
  63. package/internal/headers.js +77 -0
  64. package/internal/headers.js.map +1 -0
  65. package/internal/headers.mjs +72 -0
  66. package/internal/headers.mjs.map +1 -0
  67. package/internal/parse.d.mts +10 -0
  68. package/internal/parse.d.mts.map +1 -0
  69. package/internal/parse.d.ts +10 -0
  70. package/internal/parse.d.ts.map +1 -0
  71. package/internal/parse.js +28 -0
  72. package/internal/parse.js.map +1 -0
  73. package/internal/parse.mjs +24 -0
  74. package/internal/parse.mjs.map +1 -0
  75. package/internal/polyfill/crypto.node.d.ts +10 -0
  76. package/internal/polyfill/crypto.node.js +11 -0
  77. package/internal/polyfill/crypto.node.mjs +2 -0
  78. package/internal/polyfill/file.node.d.ts +9 -0
  79. package/internal/polyfill/file.node.js +17 -0
  80. package/internal/polyfill/file.node.mjs +9 -0
  81. package/internal/qs/formats.d.mts +6 -0
  82. package/internal/qs/formats.d.mts.map +1 -0
  83. package/internal/qs/formats.d.ts.map +1 -1
  84. package/internal/qs/index.d.mts +10 -0
  85. package/internal/qs/index.d.mts.map +1 -0
  86. package/internal/qs/index.d.ts.map +1 -1
  87. package/internal/qs/stringify.d.mts +3 -0
  88. package/internal/qs/stringify.d.mts.map +1 -0
  89. package/internal/qs/stringify.d.ts.map +1 -1
  90. package/internal/qs/types.d.mts +57 -0
  91. package/internal/qs/types.d.mts.map +1 -0
  92. package/internal/qs/utils.d.mts +14 -0
  93. package/internal/qs/utils.d.mts.map +1 -0
  94. package/internal/qs/utils.d.ts.map +1 -1
  95. package/internal/request-options.d.mts +34 -0
  96. package/internal/request-options.d.mts.map +1 -0
  97. package/internal/request-options.d.ts +34 -0
  98. package/internal/request-options.d.ts.map +1 -0
  99. package/internal/request-options.js +39 -0
  100. package/internal/request-options.js.map +1 -0
  101. package/internal/request-options.mjs +34 -0
  102. package/internal/request-options.mjs.map +1 -0
  103. package/internal/shim-types.d.mts +28 -0
  104. package/internal/shim-types.d.ts +28 -0
  105. package/internal/shims.d.mts +61 -0
  106. package/internal/shims.d.mts.map +1 -0
  107. package/internal/shims.d.ts +61 -0
  108. package/internal/shims.d.ts.map +1 -0
  109. package/internal/shims.js +101 -0
  110. package/internal/shims.js.map +1 -0
  111. package/internal/shims.mjs +92 -0
  112. package/internal/shims.mjs.map +1 -0
  113. package/internal/types.d.mts +68 -0
  114. package/internal/types.d.mts.map +1 -0
  115. package/internal/types.d.ts +68 -0
  116. package/internal/types.d.ts.map +1 -0
  117. package/internal/types.js +4 -0
  118. package/internal/types.js.map +1 -0
  119. package/internal/types.mjs +3 -0
  120. package/internal/types.mjs.map +1 -0
  121. package/internal/uploads.d.mts +73 -0
  122. package/internal/uploads.d.mts.map +1 -0
  123. package/internal/uploads.d.ts +73 -0
  124. package/internal/uploads.d.ts.map +1 -0
  125. package/internal/uploads.js +208 -0
  126. package/internal/uploads.js.map +1 -0
  127. package/internal/uploads.mjs +200 -0
  128. package/internal/uploads.mjs.map +1 -0
  129. package/internal/utils/base64.d.mts +3 -0
  130. package/internal/utils/base64.d.mts.map +1 -0
  131. package/internal/utils/base64.d.ts +3 -0
  132. package/internal/utils/base64.d.ts.map +1 -0
  133. package/internal/utils/base64.js +33 -0
  134. package/internal/utils/base64.js.map +1 -0
  135. package/internal/utils/base64.mjs +28 -0
  136. package/internal/utils/base64.mjs.map +1 -0
  137. package/internal/utils/env.d.mts +9 -0
  138. package/internal/utils/env.d.mts.map +1 -0
  139. package/internal/utils/env.d.ts +9 -0
  140. package/internal/utils/env.d.ts.map +1 -0
  141. package/internal/utils/env.js +22 -0
  142. package/internal/utils/env.js.map +1 -0
  143. package/internal/utils/env.mjs +18 -0
  144. package/internal/utils/env.mjs.map +1 -0
  145. package/internal/utils/log.d.mts +4 -0
  146. package/internal/utils/log.d.mts.map +1 -0
  147. package/internal/utils/log.d.ts +4 -0
  148. package/internal/utils/log.d.ts.map +1 -0
  149. package/internal/utils/log.js +47 -0
  150. package/internal/utils/log.js.map +1 -0
  151. package/internal/utils/log.mjs +43 -0
  152. package/internal/utils/log.mjs.map +1 -0
  153. package/internal/utils/sleep.d.mts +2 -0
  154. package/internal/utils/sleep.d.mts.map +1 -0
  155. package/internal/utils/sleep.d.ts +2 -0
  156. package/internal/utils/sleep.d.ts.map +1 -0
  157. package/internal/utils/sleep.js +7 -0
  158. package/internal/utils/sleep.js.map +1 -0
  159. package/internal/utils/sleep.mjs +3 -0
  160. package/internal/utils/sleep.mjs.map +1 -0
  161. package/internal/utils/uuid.d.mts +5 -0
  162. package/internal/utils/uuid.d.mts.map +1 -0
  163. package/internal/utils/uuid.d.ts +5 -0
  164. package/internal/utils/uuid.d.ts.map +1 -0
  165. package/internal/utils/uuid.js +15 -0
  166. package/internal/utils/uuid.js.map +1 -0
  167. package/internal/utils/uuid.mjs +11 -0
  168. package/internal/utils/uuid.mjs.map +1 -0
  169. package/internal/utils/values.d.mts +15 -0
  170. package/internal/utils/values.d.mts.map +1 -0
  171. package/internal/utils/values.d.ts +15 -0
  172. package/internal/utils/values.d.ts.map +1 -0
  173. package/internal/utils/values.js +100 -0
  174. package/internal/utils/values.js.map +1 -0
  175. package/internal/utils/values.mjs +84 -0
  176. package/internal/utils/values.mjs.map +1 -0
  177. package/internal/utils.d.mts +7 -0
  178. package/internal/utils.d.mts.map +1 -0
  179. package/internal/utils.d.ts +7 -0
  180. package/internal/utils.d.ts.map +1 -0
  181. package/{_shims/auto/runtime-bun.js → internal/utils.js} +8 -5
  182. package/internal/utils.js.map +1 -0
  183. package/internal/utils.mjs +8 -0
  184. package/internal/utils.mjs.map +1 -0
  185. package/package.json +83 -66
  186. package/resource.d.mts +6 -0
  187. package/resource.d.mts.map +1 -0
  188. package/resource.d.ts +2 -2
  189. package/resource.d.ts.map +1 -1
  190. package/resource.js.map +1 -1
  191. package/resource.mjs.map +1 -1
  192. package/resources/call.d.mts +1197 -0
  193. package/resources/call.d.mts.map +1 -0
  194. package/resources/call.d.ts +13 -24
  195. package/resources/call.d.ts.map +1 -1
  196. package/resources/call.js +15 -15
  197. package/resources/call.js.map +1 -1
  198. package/resources/call.mjs +15 -15
  199. package/resources/call.mjs.map +1 -1
  200. package/resources/evaluation.d.mts +1295 -0
  201. package/resources/evaluation.d.mts.map +1 -0
  202. package/resources/evaluation.d.ts +13 -26
  203. package/resources/evaluation.d.ts.map +1 -1
  204. package/resources/evaluation.js +13 -13
  205. package/resources/evaluation.js.map +1 -1
  206. package/resources/evaluation.mjs +13 -13
  207. package/resources/evaluation.mjs.map +1 -1
  208. package/resources/health.d.mts +29 -0
  209. package/resources/health.d.mts.map +1 -0
  210. package/resources/health.d.ts +3 -2
  211. package/resources/health.d.ts.map +1 -1
  212. package/resources/health.js.map +1 -1
  213. package/resources/health.mjs.map +1 -1
  214. package/resources/index.d.mts +8 -0
  215. package/resources/index.d.mts.map +1 -0
  216. package/resources/index.d.ts.map +1 -1
  217. package/resources/integrations.d.mts +81 -0
  218. package/resources/integrations.d.mts.map +1 -0
  219. package/resources/integrations.d.ts +8 -40
  220. package/resources/integrations.d.ts.map +1 -1
  221. package/resources/integrations.js +0 -25
  222. package/resources/integrations.js.map +1 -1
  223. package/resources/integrations.mjs +0 -25
  224. package/resources/integrations.mjs.map +1 -1
  225. package/resources/metric.d.mts +75 -0
  226. package/resources/metric.d.mts.map +1 -0
  227. package/resources/metric.d.ts +3 -2
  228. package/resources/metric.d.ts.map +1 -1
  229. package/resources/metric.js.map +1 -1
  230. package/resources/metric.mjs.map +1 -1
  231. package/resources/persona.d.mts +491 -0
  232. package/resources/persona.d.mts.map +1 -0
  233. package/resources/persona.d.ts +13 -51
  234. package/resources/persona.d.ts.map +1 -1
  235. package/resources/persona.js +10 -26
  236. package/resources/persona.js.map +1 -1
  237. package/resources/persona.mjs +10 -26
  238. package/resources/persona.mjs.map +1 -1
  239. package/resources/simulation.d.mts +756 -0
  240. package/resources/simulation.d.mts.map +1 -0
  241. package/resources/simulation.d.ts +11 -58
  242. package/resources/simulation.d.ts.map +1 -1
  243. package/resources/simulation.js +13 -43
  244. package/resources/simulation.js.map +1 -1
  245. package/resources/simulation.mjs +13 -43
  246. package/resources/simulation.mjs.map +1 -1
  247. package/src/api-promise.ts +92 -0
  248. package/src/client.ts +751 -0
  249. package/src/error.ts +1 -1
  250. package/src/index.ts +4 -307
  251. package/src/internal/builtin-types.ts +79 -0
  252. package/src/internal/detect-platform.ts +196 -0
  253. package/src/internal/errors.ts +22 -0
  254. package/src/internal/headers.ts +96 -0
  255. package/src/internal/parse.ts +41 -0
  256. package/src/internal/polyfill/crypto.node.d.ts +10 -0
  257. package/src/internal/polyfill/crypto.node.js +11 -0
  258. package/src/internal/polyfill/crypto.node.mjs +2 -0
  259. package/src/internal/polyfill/file.node.d.ts +9 -0
  260. package/src/internal/polyfill/file.node.js +17 -0
  261. package/src/internal/polyfill/file.node.mjs +9 -0
  262. package/src/internal/request-options.ts +67 -0
  263. package/src/internal/shim-types.d.ts +28 -0
  264. package/src/internal/shims.ts +145 -0
  265. package/src/internal/types.ts +98 -0
  266. package/src/internal/uploads.ts +307 -0
  267. package/src/internal/utils/base64.ts +37 -0
  268. package/src/internal/utils/env.ts +18 -0
  269. package/src/internal/utils/log.ts +49 -0
  270. package/src/internal/utils/sleep.ts +3 -0
  271. package/src/internal/utils/uuid.ts +13 -0
  272. package/src/internal/utils/values.ts +94 -0
  273. package/src/internal/utils.ts +8 -0
  274. package/src/resource.ts +2 -2
  275. package/src/resources/call.ts +22 -42
  276. package/src/resources/evaluation.ts +25 -42
  277. package/src/resources/health.ts +3 -2
  278. package/src/resources/integrations.ts +10 -34
  279. package/src/resources/metric.ts +3 -2
  280. package/src/resources/persona.ts +22 -61
  281. package/src/resources/simulation.ts +22 -84
  282. package/src/tsconfig.json +2 -2
  283. package/src/uploads.ts +1 -255
  284. package/src/version.ts +1 -1
  285. package/uploads.d.mts +2 -0
  286. package/uploads.d.mts.map +1 -0
  287. package/uploads.d.ts +1 -74
  288. package/uploads.d.ts.map +1 -1
  289. package/uploads.js +3 -168
  290. package/uploads.js.map +1 -1
  291. package/uploads.mjs +1 -157
  292. package/uploads.mjs.map +1 -1
  293. package/version.d.mts +2 -0
  294. package/version.d.mts.map +1 -0
  295. package/version.d.ts +1 -1
  296. package/version.js +1 -1
  297. package/version.mjs +1 -1
  298. package/_shims/MultipartBody.d.ts +0 -9
  299. package/_shims/MultipartBody.d.ts.map +0 -1
  300. package/_shims/MultipartBody.js +0 -16
  301. package/_shims/MultipartBody.js.map +0 -1
  302. package/_shims/MultipartBody.mjs +0 -12
  303. package/_shims/MultipartBody.mjs.map +0 -1
  304. package/_shims/README.md +0 -46
  305. package/_shims/auto/runtime-bun.d.ts +0 -5
  306. package/_shims/auto/runtime-bun.d.ts.map +0 -1
  307. package/_shims/auto/runtime-bun.js.map +0 -1
  308. package/_shims/auto/runtime-bun.mjs +0 -2
  309. package/_shims/auto/runtime-bun.mjs.map +0 -1
  310. package/_shims/auto/runtime-node.d.ts +0 -5
  311. package/_shims/auto/runtime-node.d.ts.map +0 -1
  312. package/_shims/auto/runtime-node.js +0 -21
  313. package/_shims/auto/runtime-node.js.map +0 -1
  314. package/_shims/auto/runtime-node.mjs +0 -2
  315. package/_shims/auto/runtime-node.mjs.map +0 -1
  316. package/_shims/auto/runtime.d.ts +0 -5
  317. package/_shims/auto/runtime.d.ts.map +0 -1
  318. package/_shims/auto/runtime.js +0 -21
  319. package/_shims/auto/runtime.js.map +0 -1
  320. package/_shims/auto/runtime.mjs +0 -2
  321. package/_shims/auto/runtime.mjs.map +0 -1
  322. package/_shims/auto/types-node.d.ts +0 -5
  323. package/_shims/auto/types-node.d.ts.map +0 -1
  324. package/_shims/auto/types-node.js +0 -21
  325. package/_shims/auto/types-node.js.map +0 -1
  326. package/_shims/auto/types-node.mjs +0 -2
  327. package/_shims/auto/types-node.mjs.map +0 -1
  328. package/_shims/auto/types.d.ts +0 -101
  329. package/_shims/auto/types.js +0 -3
  330. package/_shims/auto/types.mjs +0 -3
  331. package/_shims/bun-runtime.d.ts +0 -6
  332. package/_shims/bun-runtime.d.ts.map +0 -1
  333. package/_shims/bun-runtime.js +0 -14
  334. package/_shims/bun-runtime.js.map +0 -1
  335. package/_shims/bun-runtime.mjs +0 -10
  336. package/_shims/bun-runtime.mjs.map +0 -1
  337. package/_shims/index.d.ts +0 -83
  338. package/_shims/index.js +0 -17
  339. package/_shims/index.mjs +0 -11
  340. package/_shims/manual-types.d.ts +0 -12
  341. package/_shims/manual-types.js +0 -3
  342. package/_shims/manual-types.mjs +0 -3
  343. package/_shims/node-runtime.d.ts +0 -3
  344. package/_shims/node-runtime.d.ts.map +0 -1
  345. package/_shims/node-runtime.js +0 -89
  346. package/_shims/node-runtime.js.map +0 -1
  347. package/_shims/node-runtime.mjs +0 -56
  348. package/_shims/node-runtime.mjs.map +0 -1
  349. package/_shims/node-types.d.ts +0 -42
  350. package/_shims/node-types.js +0 -3
  351. package/_shims/node-types.mjs +0 -3
  352. package/_shims/registry.d.ts +0 -37
  353. package/_shims/registry.d.ts.map +0 -1
  354. package/_shims/registry.js +0 -41
  355. package/_shims/registry.js.map +0 -1
  356. package/_shims/registry.mjs +0 -37
  357. package/_shims/registry.mjs.map +0 -1
  358. package/_shims/web-runtime.d.ts +0 -5
  359. package/_shims/web-runtime.d.ts.map +0 -1
  360. package/_shims/web-runtime.js +0 -78
  361. package/_shims/web-runtime.js.map +0 -1
  362. package/_shims/web-runtime.mjs +0 -71
  363. package/_shims/web-runtime.mjs.map +0 -1
  364. package/_shims/web-types.d.ts +0 -83
  365. package/_shims/web-types.js +0 -3
  366. package/_shims/web-types.mjs +0 -3
  367. package/core.d.ts +0 -255
  368. package/core.d.ts.map +0 -1
  369. package/core.js +0 -929
  370. package/core.js.map +0 -1
  371. package/core.mjs +0 -897
  372. package/core.mjs.map +0 -1
  373. package/resources.d.ts +0 -2
  374. package/resources.d.ts.map +0 -1
  375. package/resources.js +0 -18
  376. package/resources.js.map +0 -1
  377. package/resources.mjs +0 -2
  378. package/resources.mjs.map +0 -1
  379. package/shims/node.d.ts +0 -30
  380. package/shims/node.d.ts.map +0 -1
  381. package/shims/node.js +0 -31
  382. package/shims/node.js.map +0 -1
  383. package/shims/node.mjs +0 -5
  384. package/shims/node.mjs.map +0 -1
  385. package/shims/web.d.ts +0 -26
  386. package/shims/web.d.ts.map +0 -1
  387. package/shims/web.js +0 -31
  388. package/shims/web.js.map +0 -1
  389. package/shims/web.mjs +0 -5
  390. package/shims/web.mjs.map +0 -1
  391. package/src/_shims/MultipartBody.ts +0 -9
  392. package/src/_shims/README.md +0 -46
  393. package/src/_shims/auto/runtime-bun.ts +0 -4
  394. package/src/_shims/auto/runtime-node.ts +0 -4
  395. package/src/_shims/auto/runtime.ts +0 -4
  396. package/src/_shims/auto/types-node.ts +0 -4
  397. package/src/_shims/auto/types.d.ts +0 -101
  398. package/src/_shims/auto/types.js +0 -3
  399. package/src/_shims/auto/types.mjs +0 -3
  400. package/src/_shims/bun-runtime.ts +0 -14
  401. package/src/_shims/index.d.ts +0 -83
  402. package/src/_shims/index.js +0 -17
  403. package/src/_shims/index.mjs +0 -11
  404. package/src/_shims/manual-types.d.ts +0 -12
  405. package/src/_shims/manual-types.js +0 -3
  406. package/src/_shims/manual-types.mjs +0 -3
  407. package/src/_shims/node-runtime.ts +0 -81
  408. package/src/_shims/node-types.d.ts +0 -42
  409. package/src/_shims/node-types.js +0 -3
  410. package/src/_shims/node-types.mjs +0 -3
  411. package/src/_shims/registry.ts +0 -67
  412. package/src/_shims/web-runtime.ts +0 -103
  413. package/src/_shims/web-types.d.ts +0 -83
  414. package/src/_shims/web-types.js +0 -3
  415. package/src/_shims/web-types.mjs +0 -3
  416. package/src/core.ts +0 -1242
  417. package/src/resources.ts +0 -1
  418. package/src/shims/node.ts +0 -50
  419. package/src/shims/web.ts +0 -50
@@ -0,0 +1,73 @@
1
+
2
+
3
+ import { type RequestOptions } from "./request-options.mjs";
4
+ import type { FilePropertyBag, Fetch } from "./builtin-types.mjs";
5
+ import { type FsReadStreamLike } from "./shims.mjs";
6
+ import type { Roark } from "../client.mjs";
7
+ import "./polyfill/file.node.mjs";
8
+ type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
9
+ type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
10
+ /**
11
+ * Typically, this is a native "File" class.
12
+ *
13
+ * We provide the {@link toFile} utility to convert a variety of objects
14
+ * into the File class.
15
+ *
16
+ * For convenience, you can also pass a fetch Response, or in Node,
17
+ * the result of fs.createReadStream().
18
+ */
19
+ export type Uploadable = FileLike | ResponseLike | FsReadStreamLike;
20
+ /**
21
+ * Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
22
+ * Don't add arrayBuffer here, node-fetch doesn't have it
23
+ */
24
+ interface BlobLike {
25
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
26
+ readonly size: number;
27
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
28
+ readonly type: string;
29
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
30
+ text(): Promise<string>;
31
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
32
+ slice(start?: number, end?: number): BlobLike;
33
+ }
34
+ /**
35
+ * Intended to match DOM File, node:buffer File, undici File, etc.
36
+ */
37
+ interface FileLike extends BlobLike {
38
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
39
+ readonly lastModified: number;
40
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
41
+ readonly name: string;
42
+ }
43
+ /**
44
+ * Intended to match DOM Response, node-fetch Response, undici Response, etc.
45
+ */
46
+ export interface ResponseLike {
47
+ url: string;
48
+ blob(): Promise<BlobLike>;
49
+ }
50
+ type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
51
+ /**
52
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
53
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
54
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
55
+ * @param {Object=} options additional properties
56
+ * @param {string=} options.type the MIME type of the content
57
+ * @param {number=} options.lastModified the last modified timestamp
58
+ * @returns a {@link File} with the given properties
59
+ */
60
+ export declare function toFile(value: ToFileInput | PromiseLike<ToFileInput>, name?: string | null | undefined, options?: FilePropertyBag | undefined): Promise<FileLike>;
61
+ export declare function getBytes(value: Uploadable | BlobLikePart | AsyncIterable<BlobLikePart>): Promise<Array<BlobPart>>;
62
+ /**
63
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
64
+ * Otherwise returns the request as is.
65
+ */
66
+ export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: Roark | Fetch) => Promise<RequestOptions>;
67
+ type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & {
68
+ body: unknown;
69
+ };
70
+ export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: Roark | Fetch) => Promise<RequestOptions>;
71
+ export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: Roark | Fetch) => Promise<FormData>;
72
+ export {};
73
+ //# sourceMappingURL=uploads.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploads.d.mts","sourceRoot":"","sources":["../src/internal/uploads.ts"],"names":[],"mappings":";;OAAO,EAAE,KAAK,cAAc,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E,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,GACpC,OAAO,CAAC,QAAQ,CAAC,CAgCnB;AAED,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,UAAU,GAAG,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC,GAC7D,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CA0B1B;AAsBD;;;GAGG;AACH,eAAO,MAAM,gCAAgC,SACrC,cAAc,SACb,KAAK,GAAG,KAAK,KACnB,QAAQ,cAAc,CAIxB,CAAC;AAEF,KAAK,2BAA2B,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,eAAO,MAAM,2BAA2B,SAChC,2BAA2B,SAC1B,KAAK,GAAG,KAAK,KACnB,QAAQ,cAAc,CAExB,CAAC;AAkCF,eAAO,MAAM,UAAU,4DAEd,KAAK,GAAG,KAAK,KACnB,QAAQ,QAAQ,CASlB,CAAC"}
@@ -0,0 +1,73 @@
1
+
2
+
3
+ import { type RequestOptions } from "./request-options.js";
4
+ import type { FilePropertyBag, Fetch } from "./builtin-types.js";
5
+ import { type FsReadStreamLike } from "./shims.js";
6
+ import type { Roark } from "../client.js";
7
+ import "./polyfill/file.node.js";
8
+ type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
9
+ type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
10
+ /**
11
+ * Typically, this is a native "File" class.
12
+ *
13
+ * We provide the {@link toFile} utility to convert a variety of objects
14
+ * into the File class.
15
+ *
16
+ * For convenience, you can also pass a fetch Response, or in Node,
17
+ * the result of fs.createReadStream().
18
+ */
19
+ export type Uploadable = FileLike | ResponseLike | FsReadStreamLike;
20
+ /**
21
+ * Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
22
+ * Don't add arrayBuffer here, node-fetch doesn't have it
23
+ */
24
+ interface BlobLike {
25
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
26
+ readonly size: number;
27
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
28
+ readonly type: string;
29
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
30
+ text(): Promise<string>;
31
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
32
+ slice(start?: number, end?: number): BlobLike;
33
+ }
34
+ /**
35
+ * Intended to match DOM File, node:buffer File, undici File, etc.
36
+ */
37
+ interface FileLike extends BlobLike {
38
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
39
+ readonly lastModified: number;
40
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
41
+ readonly name: string;
42
+ }
43
+ /**
44
+ * Intended to match DOM Response, node-fetch Response, undici Response, etc.
45
+ */
46
+ export interface ResponseLike {
47
+ url: string;
48
+ blob(): Promise<BlobLike>;
49
+ }
50
+ type ToFileInput = Uploadable | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
51
+ /**
52
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
53
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
54
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
55
+ * @param {Object=} options additional properties
56
+ * @param {string=} options.type the MIME type of the content
57
+ * @param {number=} options.lastModified the last modified timestamp
58
+ * @returns a {@link File} with the given properties
59
+ */
60
+ export declare function toFile(value: ToFileInput | PromiseLike<ToFileInput>, name?: string | null | undefined, options?: FilePropertyBag | undefined): Promise<FileLike>;
61
+ export declare function getBytes(value: Uploadable | BlobLikePart | AsyncIterable<BlobLikePart>): Promise<Array<BlobPart>>;
62
+ /**
63
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
64
+ * Otherwise returns the request as is.
65
+ */
66
+ export declare const maybeMultipartFormRequestOptions: (opts: RequestOptions, fetch: Roark | Fetch) => Promise<RequestOptions>;
67
+ type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & {
68
+ body: unknown;
69
+ };
70
+ export declare const multipartFormRequestOptions: (opts: MultipartFormRequestOptions, fetch: Roark | Fetch) => Promise<RequestOptions>;
71
+ export declare const createForm: <T = Record<string, unknown>>(body: T | undefined, fetch: Roark | Fetch) => Promise<FormData>;
72
+ export {};
73
+ //# sourceMappingURL=uploads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploads.d.ts","sourceRoot":"","sources":["../src/internal/uploads.ts"],"names":[],"mappings":";;OAAO,EAAE,KAAK,cAAc,EAAE;OACvB,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;OAC/B,EAAsB,KAAK,gBAAgB,EAAE;OAC7C,KAAK,EAAE,KAAK,EAAE;;AAGrB,KAAK,YAAY,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,QAAQ,GAAG,QAAQ,CAAC;AACjF,KAAK,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,GAAG,IAAI,GAAG,QAAQ,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,gBAAgB,CAAC;AAEpE;;;GAGG;AACH,UAAU,QAAQ;IAChB,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,6EAA6E;IAC7E,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC/C;AAcD;;GAEG;AACH,UAAU,QAAS,SAAQ,QAAQ;IACjC,oFAAoF;IACpF,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAgBD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC3B;AAYD,KAAK,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;AAgB5F;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,KAAK,EAAE,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,EAC7C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,GACpC,OAAO,CAAC,QAAQ,CAAC,CAgCnB;AAED,wBAAsB,QAAQ,CAC5B,KAAK,EAAE,UAAU,GAAG,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC,GAC7D,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CA0B1B;AAsBD;;;GAGG;AACH,eAAO,MAAM,gCAAgC,SACrC,cAAc,SACb,KAAK,GAAG,KAAK,KACnB,QAAQ,cAAc,CAIxB,CAAC;AAEF,KAAK,2BAA2B,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEpF,eAAO,MAAM,2BAA2B,SAChC,2BAA2B,SAC1B,KAAK,GAAG,KAAK,KACnB,QAAQ,cAAc,CAExB,CAAC;AAkCF,eAAO,MAAM,UAAU,4DAEd,KAAK,GAAG,KAAK,KACnB,QAAQ,QAAQ,CASlB,CAAC"}
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = exports.getBytes = exports.toFile = void 0;
4
+ const shims_1 = require("./shims.js");
5
+ require("./polyfill/file.node.js");
6
+ /**
7
+ * This check adds the arrayBuffer() method type because it is available and used at runtime
8
+ */
9
+ const isBlobLike = (value) => value != null &&
10
+ typeof value === 'object' &&
11
+ typeof value.size === 'number' &&
12
+ typeof value.type === 'string' &&
13
+ typeof value.text === 'function' &&
14
+ typeof value.slice === 'function' &&
15
+ typeof value.arrayBuffer === 'function';
16
+ /**
17
+ * This check adds the arrayBuffer() method type because it is available and used at runtime
18
+ */
19
+ const isFileLike = (value) => value != null &&
20
+ typeof value === 'object' &&
21
+ typeof value.name === 'string' &&
22
+ typeof value.lastModified === 'number' &&
23
+ isBlobLike(value);
24
+ const isResponseLike = (value) => value != null &&
25
+ typeof value === 'object' &&
26
+ typeof value.url === 'string' &&
27
+ typeof value.blob === 'function';
28
+ const isUploadable = (value) => {
29
+ return isFileLike(value) || isResponseLike(value) || (0, shims_1.isFsReadStreamLike)(value);
30
+ };
31
+ /**
32
+ * Construct a `File` instance. This is used to ensure a helpful error is thrown
33
+ * for environments that don't define a global `File` yet and so that we don't
34
+ * accidentally rely on a global `File` type in our annotations.
35
+ */
36
+ function makeFile(fileBits, fileName, options) {
37
+ const File = globalThis.File;
38
+ if (typeof File === 'undefined') {
39
+ throw new Error('`File` is not defined as a global which is required for file uploads');
40
+ }
41
+ return new File(fileBits, fileName, options);
42
+ }
43
+ /**
44
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
45
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
46
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
47
+ * @param {Object=} options additional properties
48
+ * @param {string=} options.type the MIME type of the content
49
+ * @param {number=} options.lastModified the last modified timestamp
50
+ * @returns a {@link File} with the given properties
51
+ */
52
+ async function toFile(value, name, options) {
53
+ // If it's a promise, resolve it.
54
+ value = await value;
55
+ // If we've been given a `File` we don't need to do anything
56
+ if (isFileLike(value)) {
57
+ const File = globalThis.File;
58
+ if (File && value instanceof File) {
59
+ return value;
60
+ }
61
+ return makeFile([await value.arrayBuffer()], value.name);
62
+ }
63
+ if (isResponseLike(value)) {
64
+ const blob = await value.blob();
65
+ name || (name = new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file');
66
+ return makeFile(await getBytes(blob), name, options);
67
+ }
68
+ const parts = await getBytes(value);
69
+ name || (name = getName(value) ?? 'unknown_file');
70
+ if (!options?.type) {
71
+ const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
72
+ if (typeof type === 'string') {
73
+ options = { ...options, type };
74
+ }
75
+ }
76
+ return makeFile(parts, name, options);
77
+ }
78
+ exports.toFile = toFile;
79
+ async function getBytes(value) {
80
+ let parts = [];
81
+ if (typeof value === 'string' ||
82
+ ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
83
+ value instanceof ArrayBuffer) {
84
+ parts.push(value);
85
+ }
86
+ else if (isBlobLike(value)) {
87
+ parts.push(value instanceof Blob ? value : await value.arrayBuffer());
88
+ }
89
+ else if (isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
90
+ ) {
91
+ for await (const chunk of value) {
92
+ parts.push(...(await getBytes(chunk))); // TODO, consider validating?
93
+ }
94
+ }
95
+ else {
96
+ const constructor = value?.constructor?.name;
97
+ throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ''}${propsForError(value)}`);
98
+ }
99
+ return parts;
100
+ }
101
+ exports.getBytes = getBytes;
102
+ function propsForError(value) {
103
+ if (typeof value !== 'object' || value === null)
104
+ return '';
105
+ const props = Object.getOwnPropertyNames(value);
106
+ return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
107
+ }
108
+ function getName(value) {
109
+ return ((typeof value === 'object' &&
110
+ value !== null &&
111
+ (('name' in value && String(value.name)) ||
112
+ ('filename' in value && String(value.filename)) ||
113
+ ('path' in value && String(value.path).split(/[\\/]/).pop()))) ||
114
+ undefined);
115
+ }
116
+ const isAsyncIterableIterator = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
117
+ /**
118
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
119
+ * Otherwise returns the request as is.
120
+ */
121
+ const maybeMultipartFormRequestOptions = async (opts, fetch) => {
122
+ if (!hasUploadableValue(opts.body))
123
+ return opts;
124
+ return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
125
+ };
126
+ exports.maybeMultipartFormRequestOptions = maybeMultipartFormRequestOptions;
127
+ const multipartFormRequestOptions = async (opts, fetch) => {
128
+ return { ...opts, body: await (0, exports.createForm)(opts.body, fetch) };
129
+ };
130
+ exports.multipartFormRequestOptions = multipartFormRequestOptions;
131
+ const supportsFormDataMap = new WeakMap();
132
+ /**
133
+ * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
134
+ * properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
135
+ * This function detects if the fetch function provided supports the global FormData object to avoid
136
+ * confusing error messages later on.
137
+ */
138
+ function supportsFormData(fetchObject) {
139
+ const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
140
+ const cached = supportsFormDataMap.get(fetch);
141
+ if (cached)
142
+ return cached;
143
+ const promise = (async () => {
144
+ try {
145
+ const FetchResponse = ('Response' in fetch ?
146
+ fetch.Response
147
+ : (await fetch('data:,')).constructor);
148
+ const data = new FormData();
149
+ if (data.toString() === (await new FetchResponse(data).text())) {
150
+ return false;
151
+ }
152
+ return true;
153
+ }
154
+ catch {
155
+ // avoid false negatives
156
+ return true;
157
+ }
158
+ })();
159
+ supportsFormDataMap.set(fetch, promise);
160
+ return promise;
161
+ }
162
+ const createForm = async (body, fetch) => {
163
+ if (!(await supportsFormData(fetch))) {
164
+ throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
165
+ }
166
+ const form = new FormData();
167
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
168
+ return form;
169
+ };
170
+ exports.createForm = createForm;
171
+ const hasUploadableValue = (value) => {
172
+ if (isUploadable(value))
173
+ return true;
174
+ if (Array.isArray(value))
175
+ return value.some(hasUploadableValue);
176
+ if (value && typeof value === 'object') {
177
+ for (const k in value) {
178
+ if (hasUploadableValue(value[k]))
179
+ return true;
180
+ }
181
+ }
182
+ return false;
183
+ };
184
+ const addFormValue = async (form, key, value) => {
185
+ if (value === undefined)
186
+ return;
187
+ if (value == null) {
188
+ throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
189
+ }
190
+ // TODO: make nested formats configurable
191
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
192
+ form.append(key, String(value));
193
+ }
194
+ else if (isUploadable(value)) {
195
+ const file = await toFile(value);
196
+ form.append(key, file);
197
+ }
198
+ else if (Array.isArray(value)) {
199
+ await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
200
+ }
201
+ else if (typeof value === 'object') {
202
+ await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
203
+ }
204
+ else {
205
+ throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
206
+ }
207
+ };
208
+ //# sourceMappingURL=uploads.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uploads.js","sourceRoot":"","sources":["../src/internal/uploads.ts"],"names":[],"mappings":";;;AAEA,sCAAoE;AAEpE,mCAAiC;AA+BjC;;GAEG;AACH,MAAM,UAAU,GAAG,CAAC,KAAU,EAA+D,EAAE,CAC7F,KAAK,IAAI,IAAI;IACb,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;IAC9B,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;IAChC,OAAO,KAAK,CAAC,KAAK,KAAK,U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,CAAC,EAAE;QAC/B,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;KAChF;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,CACzF,CAAC;KACH;SAAM;QACL,MAAM,IAAI,SAAS,CACjB,wGAAwG,KAAK,UAAU,CACxH,CAAC;KACH;AACH,CAAC,CAAC"}
@@ -0,0 +1,200 @@
1
+ import { isFsReadStreamLike } from "./shims.mjs";
2
+ import "./polyfill/file.node.mjs";
3
+ /**
4
+ * This check adds the arrayBuffer() method type because it is available and used at runtime
5
+ */
6
+ const isBlobLike = (value) => value != null &&
7
+ typeof value === 'object' &&
8
+ typeof value.size === 'number' &&
9
+ typeof value.type === 'string' &&
10
+ typeof value.text === 'function' &&
11
+ typeof value.slice === 'function' &&
12
+ typeof value.arrayBuffer === 'function';
13
+ /**
14
+ * This check adds the arrayBuffer() method type because it is available and used at runtime
15
+ */
16
+ const isFileLike = (value) => value != null &&
17
+ typeof value === 'object' &&
18
+ typeof value.name === 'string' &&
19
+ typeof value.lastModified === 'number' &&
20
+ isBlobLike(value);
21
+ const isResponseLike = (value) => value != null &&
22
+ typeof value === 'object' &&
23
+ typeof value.url === 'string' &&
24
+ typeof value.blob === 'function';
25
+ const isUploadable = (value) => {
26
+ return isFileLike(value) || isResponseLike(value) || isFsReadStreamLike(value);
27
+ };
28
+ /**
29
+ * Construct a `File` instance. This is used to ensure a helpful error is thrown
30
+ * for environments that don't define a global `File` yet and so that we don't
31
+ * accidentally rely on a global `File` type in our annotations.
32
+ */
33
+ function makeFile(fileBits, fileName, options) {
34
+ const File = globalThis.File;
35
+ if (typeof File === 'undefined') {
36
+ throw new Error('`File` is not defined as a global which is required for file uploads');
37
+ }
38
+ return new File(fileBits, fileName, options);
39
+ }
40
+ /**
41
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
42
+ * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
43
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
44
+ * @param {Object=} options additional properties
45
+ * @param {string=} options.type the MIME type of the content
46
+ * @param {number=} options.lastModified the last modified timestamp
47
+ * @returns a {@link File} with the given properties
48
+ */
49
+ export async function toFile(value, name, options) {
50
+ // If it's a promise, resolve it.
51
+ value = await value;
52
+ // If we've been given a `File` we don't need to do anything
53
+ if (isFileLike(value)) {
54
+ const File = globalThis.File;
55
+ if (File && value instanceof File) {
56
+ return value;
57
+ }
58
+ return makeFile([await value.arrayBuffer()], value.name);
59
+ }
60
+ if (isResponseLike(value)) {
61
+ const blob = await value.blob();
62
+ name || (name = new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file');
63
+ return makeFile(await getBytes(blob), name, options);
64
+ }
65
+ const parts = await getBytes(value);
66
+ name || (name = getName(value) ?? 'unknown_file');
67
+ if (!options?.type) {
68
+ const type = parts.find((part) => typeof part === 'object' && 'type' in part && part.type);
69
+ if (typeof type === 'string') {
70
+ options = { ...options, type };
71
+ }
72
+ }
73
+ return makeFile(parts, name, options);
74
+ }
75
+ export async function getBytes(value) {
76
+ let parts = [];
77
+ if (typeof value === 'string' ||
78
+ ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
79
+ value instanceof ArrayBuffer) {
80
+ parts.push(value);
81
+ }
82
+ else if (isBlobLike(value)) {
83
+ parts.push(value instanceof Blob ? value : await value.arrayBuffer());
84
+ }
85
+ else if (isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
86
+ ) {
87
+ for await (const chunk of value) {
88
+ parts.push(...(await getBytes(chunk))); // TODO, consider validating?
89
+ }
90
+ }
91
+ else {
92
+ const constructor = value?.constructor?.name;
93
+ throw new Error(`Unexpected data type: ${typeof value}${constructor ? `; constructor: ${constructor}` : ''}${propsForError(value)}`);
94
+ }
95
+ return parts;
96
+ }
97
+ function propsForError(value) {
98
+ if (typeof value !== 'object' || value === null)
99
+ return '';
100
+ const props = Object.getOwnPropertyNames(value);
101
+ return `; props: [${props.map((p) => `"${p}"`).join(', ')}]`;
102
+ }
103
+ function getName(value) {
104
+ return ((typeof value === 'object' &&
105
+ value !== null &&
106
+ (('name' in value && String(value.name)) ||
107
+ ('filename' in value && String(value.filename)) ||
108
+ ('path' in value && String(value.path).split(/[\\/]/).pop()))) ||
109
+ undefined);
110
+ }
111
+ const isAsyncIterableIterator = (value) => value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
112
+ /**
113
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
114
+ * Otherwise returns the request as is.
115
+ */
116
+ export const maybeMultipartFormRequestOptions = async (opts, fetch) => {
117
+ if (!hasUploadableValue(opts.body))
118
+ return opts;
119
+ return { ...opts, body: await createForm(opts.body, fetch) };
120
+ };
121
+ export const multipartFormRequestOptions = async (opts, fetch) => {
122
+ return { ...opts, body: await createForm(opts.body, fetch) };
123
+ };
124
+ const supportsFormDataMap = new WeakMap();
125
+ /**
126
+ * node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
127
+ * properly-encoded form data, it just stringifies the object, resulting in a request body of "[object FormData]".
128
+ * This function detects if the fetch function provided supports the global FormData object to avoid
129
+ * confusing error messages later on.
130
+ */
131
+ function supportsFormData(fetchObject) {
132
+ const fetch = typeof fetchObject === 'function' ? fetchObject : fetchObject.fetch;
133
+ const cached = supportsFormDataMap.get(fetch);
134
+ if (cached)
135
+ return cached;
136
+ const promise = (async () => {
137
+ try {
138
+ const FetchResponse = ('Response' in fetch ?
139
+ fetch.Response
140
+ : (await fetch('data:,')).constructor);
141
+ const data = new FormData();
142
+ if (data.toString() === (await new FetchResponse(data).text())) {
143
+ return false;
144
+ }
145
+ return true;
146
+ }
147
+ catch {
148
+ // avoid false negatives
149
+ return true;
150
+ }
151
+ })();
152
+ supportsFormDataMap.set(fetch, promise);
153
+ return promise;
154
+ }
155
+ export const createForm = async (body, fetch) => {
156
+ if (!(await supportsFormData(fetch))) {
157
+ throw new TypeError('The provided fetch function does not support file uploads with the current global FormData class.');
158
+ }
159
+ const form = new FormData();
160
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
161
+ return form;
162
+ };
163
+ const hasUploadableValue = (value) => {
164
+ if (isUploadable(value))
165
+ return true;
166
+ if (Array.isArray(value))
167
+ return value.some(hasUploadableValue);
168
+ if (value && typeof value === 'object') {
169
+ for (const k in value) {
170
+ if (hasUploadableValue(value[k]))
171
+ return true;
172
+ }
173
+ }
174
+ return false;
175
+ };
176
+ const addFormValue = async (form, key, value) => {
177
+ if (value === undefined)
178
+ return;
179
+ if (value == null) {
180
+ throw new TypeError(`Received null for "${key}"; to pass null in FormData, you must use the string 'null'`);
181
+ }
182
+ // TODO: make nested formats configurable
183
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
184
+ form.append(key, String(value));
185
+ }
186
+ else if (isUploadable(value)) {
187
+ const file = await toFile(value);
188
+ form.append(key, file);
189
+ }
190
+ else if (Array.isArray(value)) {
191
+ await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
192
+ }
193
+ else if (typeof value === 'object') {
194
+ await Promise.all(Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)));
195
+ }
196
+ else {
197
+ throw new TypeError(`Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`);
198
+ }
199
+ };
200
+ //# sourceMappingURL=uploads.mjs.map
@@ -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OAAO,KAAK,KAAK,SAAS,EAAE;QACxF,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;KACjC;SAAM,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;QAC9B,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,IAAW,CAAC,CAAC;KAC/B;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC/B,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;KAChF;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,CACzF,CAAC;KACH;SAAM;QACL,MAAM,IAAI,SAAS,CACjB,wGAAwG,KAAK,UAAU,CACxH,CAAC;KACH;AACH,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const toBase64: (data: string | Uint8Array | null | undefined) => string;
2
+ export declare const fromBase64: (str: string) => Uint8Array;
3
+ //# sourceMappingURL=base64.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.mts","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,SAAU,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,KAAG,MAgBvE,CAAC;AAEF,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,UAcxC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const toBase64: (data: string | Uint8Array | null | undefined) => string;
2
+ export declare const fromBase64: (str: string) => Uint8Array;
3
+ //# sourceMappingURL=base64.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/internal/utils/base64.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,SAAU,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,SAAS,KAAG,MAgBvE,CAAC;AAEF,eAAO,MAAM,UAAU,QAAS,MAAM,KAAG,UAcxC,CAAC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.fromBase64 = exports.toBase64 = void 0;
5
+ const error_1 = require("../../error.js");
6
+ const toBase64 = (data) => {
7
+ if (!data)
8
+ return '';
9
+ if (typeof data === 'string') {
10
+ data = new globalThis.TextEncoder().encode(data);
11
+ }
12
+ if (typeof globalThis.Buffer !== 'undefined') {
13
+ return globalThis.Buffer.from(data).toString('base64');
14
+ }
15
+ if (typeof btoa !== 'undefined') {
16
+ return btoa(String.fromCharCode.apply(null, data));
17
+ }
18
+ throw new error_1.RoarkError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
19
+ };
20
+ exports.toBase64 = toBase64;
21
+ const fromBase64 = (str) => {
22
+ if (typeof globalThis.Buffer !== 'undefined') {
23
+ return new Uint8Array(globalThis.Buffer.from(str, 'base64'));
24
+ }
25
+ if (typeof atob !== 'undefined') {
26
+ return new Uint8Array(atob(str)
27
+ .split('')
28
+ .map((c) => c.charCodeAt(0)));
29
+ }
30
+ throw new error_1.RoarkError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
31
+ };
32
+ exports.fromBase64 = fromBase64;
33
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1 @@
1
+ {"version":3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