@tryfinch/finch-api 1.1.0 → 3.0.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 (501) hide show
  1. package/_shims/agent.d.ts +9 -0
  2. package/_shims/agent.d.ts.map +1 -0
  3. package/_shims/agent.js +14 -0
  4. package/_shims/agent.js.map +1 -0
  5. package/_shims/agent.mjs +10 -0
  6. package/_shims/agent.mjs.map +1 -0
  7. package/_shims/agent.node.d.ts +7 -0
  8. package/_shims/agent.node.d.ts.map +1 -0
  9. package/_shims/agent.node.js +28 -0
  10. package/_shims/agent.node.js.map +1 -0
  11. package/_shims/agent.node.mjs +16 -0
  12. package/_shims/agent.node.mjs.map +1 -0
  13. package/_shims/fetch.d.ts +52 -0
  14. package/_shims/fetch.js +13 -0
  15. package/_shims/fetch.mjs +15 -0
  16. package/_shims/fetch.node.d.ts +53 -0
  17. package/_shims/fetch.node.js +12 -0
  18. package/_shims/fetch.node.mjs +14 -0
  19. package/_shims/fileFromPath.d.ts +22 -0
  20. package/_shims/fileFromPath.d.ts.map +1 -0
  21. package/_shims/fileFromPath.js +16 -0
  22. package/_shims/fileFromPath.js.map +1 -0
  23. package/_shims/fileFromPath.mjs +12 -0
  24. package/_shims/fileFromPath.mjs.map +1 -0
  25. package/_shims/fileFromPath.node.d.ts +17 -0
  26. package/_shims/fileFromPath.node.d.ts.map +1 -0
  27. package/_shims/fileFromPath.node.js +17 -0
  28. package/_shims/fileFromPath.node.js.map +1 -0
  29. package/_shims/fileFromPath.node.mjs +13 -0
  30. package/_shims/fileFromPath.node.mjs.map +1 -0
  31. package/_shims/formdata.d.ts +43 -0
  32. package/_shims/formdata.js +9 -0
  33. package/_shims/formdata.mjs +11 -0
  34. package/_shims/formdata.node.d.ts +44 -0
  35. package/_shims/formdata.node.js +11 -0
  36. package/_shims/formdata.node.mjs +9 -0
  37. package/_shims/getMultipartRequestOptions.d.ts +10 -0
  38. package/_shims/getMultipartRequestOptions.d.ts.map +1 -0
  39. package/_shims/getMultipartRequestOptions.js +12 -0
  40. package/_shims/getMultipartRequestOptions.js.map +1 -0
  41. package/_shims/getMultipartRequestOptions.mjs +8 -0
  42. package/_shims/getMultipartRequestOptions.mjs.map +1 -0
  43. package/_shims/getMultipartRequestOptions.node.d.ts +10 -0
  44. package/_shims/getMultipartRequestOptions.node.d.ts.map +1 -0
  45. package/_shims/getMultipartRequestOptions.node.js +22 -0
  46. package/_shims/getMultipartRequestOptions.node.js.map +1 -0
  47. package/_shims/getMultipartRequestOptions.node.mjs +18 -0
  48. package/_shims/getMultipartRequestOptions.node.mjs.map +1 -0
  49. package/_shims/node-readable.d.ts +23 -0
  50. package/_shims/node-readable.d.ts.map +1 -0
  51. package/_shims/node-readable.js +11 -0
  52. package/_shims/node-readable.js.map +1 -0
  53. package/_shims/node-readable.mjs +7 -0
  54. package/_shims/node-readable.mjs.map +1 -0
  55. package/_shims/node-readable.node.d.ts +8 -0
  56. package/_shims/node-readable.node.d.ts.map +1 -0
  57. package/_shims/node-readable.node.js +9 -0
  58. package/_shims/node-readable.node.js.map +1 -0
  59. package/_shims/node-readable.node.mjs +5 -0
  60. package/_shims/node-readable.node.mjs.map +1 -0
  61. package/{dist/cjs/core.d.ts → core.d.ts} +18 -68
  62. package/core.d.ts.map +1 -0
  63. package/core.js +683 -0
  64. package/core.js.map +1 -0
  65. package/core.mjs +587 -0
  66. package/core.mjs.map +1 -0
  67. package/error.d.ts +48 -0
  68. package/error.d.ts.map +1 -0
  69. package/error.js +126 -0
  70. package/error.js.map +1 -0
  71. package/error.mjs +101 -0
  72. package/error.mjs.map +1 -0
  73. package/index.d.mts +160 -0
  74. package/index.d.ts +160 -0
  75. package/index.d.ts.map +1 -0
  76. package/{dist/cjs/index.js → index.js} +55 -44
  77. package/index.js.map +1 -0
  78. package/index.mjs +157 -0
  79. package/index.mjs.map +1 -0
  80. package/package.json +57 -20
  81. package/{dist/cjs/pagination.d.ts → pagination.d.ts} +6 -4
  82. package/pagination.d.ts.map +1 -0
  83. package/{dist/cjs/pagination.js → pagination.js} +1 -1
  84. package/pagination.js.map +1 -0
  85. package/pagination.mjs +198 -0
  86. package/pagination.mjs.map +1 -0
  87. package/{dist/cjs/resource.d.ts → resource.d.ts} +1 -1
  88. package/resource.d.ts.map +1 -0
  89. package/resource.js.map +1 -0
  90. package/resource.mjs +13 -0
  91. package/resource.mjs.map +1 -0
  92. package/{dist/cjs/resources → resources}/account.d.ts +7 -2
  93. package/resources/account.d.ts.map +1 -0
  94. package/{dist/cjs/resources → resources}/account.js +2 -1
  95. package/resources/account.js.map +1 -0
  96. package/resources/account.mjs +20 -0
  97. package/resources/account.mjs.map +1 -0
  98. package/{dist/cjs/resources → resources}/ats/applications.d.ts +10 -5
  99. package/resources/ats/applications.d.ts.map +1 -0
  100. package/{dist/cjs/resources → resources}/ats/applications.js +5 -8
  101. package/resources/ats/applications.js.map +1 -0
  102. package/resources/ats/applications.mjs +20 -0
  103. package/resources/ats/applications.mjs.map +1 -0
  104. package/resources/ats/ats.d.ts +32 -0
  105. package/resources/ats/ats.d.ts.map +1 -0
  106. package/resources/ats/ats.js +71 -0
  107. package/resources/ats/ats.js.map +1 -0
  108. package/resources/ats/ats.mjs +27 -0
  109. package/resources/ats/ats.mjs.map +1 -0
  110. package/{dist/cjs/resources → resources}/ats/candidates.d.ts +13 -8
  111. package/resources/ats/candidates.d.ts.map +1 -0
  112. package/{dist/cjs/resources → resources}/ats/candidates.js +5 -4
  113. package/resources/ats/candidates.js.map +1 -0
  114. package/resources/ats/candidates.mjs +21 -0
  115. package/resources/ats/candidates.mjs.map +1 -0
  116. package/resources/ats/index.d.ts +7 -0
  117. package/resources/ats/index.d.ts.map +1 -0
  118. package/resources/ats/index.js +60 -0
  119. package/resources/ats/index.js.map +1 -0
  120. package/resources/ats/index.mjs +8 -0
  121. package/resources/ats/index.mjs.map +1 -0
  122. package/{dist/cjs/resources → resources}/ats/jobs.d.ts +13 -8
  123. package/resources/ats/jobs.d.ts.map +1 -0
  124. package/{dist/cjs/resources → resources}/ats/jobs.js +5 -4
  125. package/resources/ats/jobs.js.map +1 -0
  126. package/resources/ats/jobs.mjs +20 -0
  127. package/resources/ats/jobs.mjs.map +1 -0
  128. package/{dist/cjs/resources → resources}/ats/offers.d.ts +9 -4
  129. package/resources/ats/offers.d.ts.map +1 -0
  130. package/{dist/cjs/resources → resources}/ats/offers.js +5 -4
  131. package/resources/ats/offers.js.map +1 -0
  132. package/resources/ats/offers.mjs +20 -0
  133. package/resources/ats/offers.mjs.map +1 -0
  134. package/{dist/cjs/resources → resources}/ats/stages.d.ts +10 -3
  135. package/resources/ats/stages.d.ts.map +1 -0
  136. package/{dist/cjs/resources → resources}/ats/stages.js +3 -2
  137. package/resources/ats/stages.js.map +1 -0
  138. package/resources/ats/stages.mjs +17 -0
  139. package/resources/ats/stages.mjs.map +1 -0
  140. package/{dist/cjs/resources → resources}/hris/benefits/benefits.d.ts +32 -4
  141. package/resources/hris/benefits/benefits.d.ts.map +1 -0
  142. package/resources/hris/benefits/benefits.js +104 -0
  143. package/resources/hris/benefits/benefits.js.map +1 -0
  144. package/resources/hris/benefits/benefits.mjs +58 -0
  145. package/resources/hris/benefits/benefits.mjs.map +1 -0
  146. package/{dist/cjs/resources → resources}/hris/benefits/index.d.ts +4 -2
  147. package/resources/hris/benefits/index.d.ts.map +1 -0
  148. package/{dist/cjs/resources → resources}/hris/benefits/index.js +17 -3
  149. package/resources/hris/benefits/index.js.map +1 -0
  150. package/resources/hris/benefits/index.mjs +9 -0
  151. package/resources/hris/benefits/index.mjs.map +1 -0
  152. package/{dist/cjs/resources → resources}/hris/benefits/individuals.d.ts +21 -4
  153. package/resources/hris/benefits/individuals.d.ts.map +1 -0
  154. package/{dist/cjs/resources → resources}/hris/benefits/individuals.js +18 -18
  155. package/resources/hris/benefits/individuals.js.map +1 -0
  156. package/resources/hris/benefits/individuals.mjs +57 -0
  157. package/resources/hris/benefits/individuals.mjs.map +1 -0
  158. package/{dist/cjs/resources → resources}/hris/company.d.ts +42 -38
  159. package/resources/hris/company.d.ts.map +1 -0
  160. package/{dist/cjs/resources → resources}/hris/company.js +4 -1
  161. package/resources/hris/company.js.map +1 -0
  162. package/resources/hris/company.mjs +12 -0
  163. package/resources/hris/company.mjs.map +1 -0
  164. package/{dist/cjs/resources → resources}/hris/directory.d.ts +20 -15
  165. package/resources/hris/directory.d.ts.map +1 -0
  166. package/{dist/cjs/resources → resources}/hris/directory.js +5 -8
  167. package/resources/hris/directory.js.map +1 -0
  168. package/resources/hris/directory.mjs +14 -0
  169. package/resources/hris/directory.mjs.map +1 -0
  170. package/resources/hris/hris.d.ts +134 -0
  171. package/resources/hris/hris.d.ts.map +1 -0
  172. package/resources/hris/hris.js +78 -0
  173. package/resources/hris/hris.js.map +1 -0
  174. package/resources/hris/hris.mjs +34 -0
  175. package/resources/hris/hris.mjs.map +1 -0
  176. package/{dist/cjs/resources → resources}/hris/index.d.ts +10 -7
  177. package/resources/hris/index.d.ts.map +1 -0
  178. package/resources/hris/index.js +96 -0
  179. package/resources/hris/index.js.map +1 -0
  180. package/resources/hris/index.mjs +9 -0
  181. package/resources/hris/index.mjs.map +1 -0
  182. package/{dist/cjs/resources → resources}/hris/individuals/employment-data.d.ts +28 -19
  183. package/resources/hris/individuals/employment-data.d.ts.map +1 -0
  184. package/resources/hris/individuals/employment-data.js +70 -0
  185. package/resources/hris/individuals/employment-data.js.map +1 -0
  186. package/resources/hris/individuals/employment-data.mjs +25 -0
  187. package/resources/hris/individuals/employment-data.mjs.map +1 -0
  188. package/{dist/cjs/resources → resources}/hris/individuals/index.d.ts +3 -2
  189. package/resources/hris/individuals/index.d.ts.map +1 -0
  190. package/{dist/cjs/resources → resources}/hris/individuals/index.js +10 -3
  191. package/resources/hris/individuals/index.js.map +1 -0
  192. package/resources/hris/individuals/index.mjs +4 -0
  193. package/resources/hris/individuals/index.mjs.map +1 -0
  194. package/{dist/cjs/resources → resources}/hris/individuals/individuals.d.ts +28 -15
  195. package/resources/hris/individuals/individuals.d.ts.map +1 -0
  196. package/resources/hris/individuals/individuals.js +73 -0
  197. package/resources/hris/individuals/individuals.js.map +1 -0
  198. package/resources/hris/individuals/individuals.mjs +28 -0
  199. package/resources/hris/individuals/individuals.mjs.map +1 -0
  200. package/{dist/cjs/resources → resources}/hris/pay-statements.d.ts +45 -35
  201. package/resources/hris/pay-statements.d.ts.map +1 -0
  202. package/{dist/cjs/resources → resources}/hris/pay-statements.js +8 -7
  203. package/resources/hris/pay-statements.js.map +1 -0
  204. package/resources/hris/pay-statements.mjs +21 -0
  205. package/resources/hris/pay-statements.mjs.map +1 -0
  206. package/{dist/cjs/resources → resources}/hris/payments.d.ts +16 -8
  207. package/resources/hris/payments.d.ts.map +1 -0
  208. package/{dist/cjs/resources → resources}/hris/payments.js +4 -3
  209. package/resources/hris/payments.js.map +1 -0
  210. package/resources/hris/payments.mjs +14 -0
  211. package/resources/hris/payments.mjs.map +1 -0
  212. package/{dist/cjs/resources → resources}/index.d.ts +4 -4
  213. package/resources/index.d.ts.map +1 -0
  214. package/{dist/cjs/resources → resources}/index.js +4 -4
  215. package/resources/index.js.map +1 -0
  216. package/resources/index.mjs +6 -0
  217. package/resources/index.mjs.map +1 -0
  218. package/{dist/cjs/resources → resources}/providers.d.ts +14 -7
  219. package/resources/providers.d.ts.map +1 -0
  220. package/{dist/cjs/resources → resources}/providers.js +3 -2
  221. package/resources/providers.js.map +1 -0
  222. package/resources/providers.mjs +14 -0
  223. package/resources/providers.mjs.map +1 -0
  224. package/resources/top-level.d.ts.map +1 -0
  225. package/resources/top-level.js.map +1 -0
  226. package/resources/top-level.mjs +3 -0
  227. package/resources/top-level.mjs.map +1 -0
  228. package/src/_shims/agent.node.ts +22 -0
  229. package/src/_shims/agent.ts +12 -0
  230. package/src/_shims/fetch.d.ts +52 -0
  231. package/src/_shims/fetch.js +13 -0
  232. package/src/_shims/fetch.mjs +15 -0
  233. package/src/_shims/fetch.node.d.ts +53 -0
  234. package/src/_shims/fetch.node.js +12 -0
  235. package/src/_shims/fetch.node.mjs +14 -0
  236. package/src/_shims/fileFromPath.node.ts +29 -0
  237. package/src/_shims/fileFromPath.ts +29 -0
  238. package/src/_shims/formdata.d.ts +43 -0
  239. package/src/_shims/formdata.js +9 -0
  240. package/src/_shims/formdata.mjs +11 -0
  241. package/src/_shims/formdata.node.d.ts +44 -0
  242. package/src/_shims/formdata.node.js +11 -0
  243. package/src/_shims/formdata.node.mjs +9 -0
  244. package/src/_shims/getMultipartRequestOptions.node.ts +25 -0
  245. package/src/_shims/getMultipartRequestOptions.ts +14 -0
  246. package/src/_shims/node-readable.node.ts +10 -0
  247. package/src/_shims/node-readable.ts +30 -0
  248. package/{core.ts → src/core.ts} +69 -177
  249. package/src/error.ts +115 -0
  250. package/{index.ts → src/index.ts} +78 -27
  251. package/{pagination.ts → src/pagination.ts} +4 -1
  252. package/{resources → src/resources}/account.ts +8 -2
  253. package/{resources → src/resources}/ats/applications.ts +13 -7
  254. package/src/resources/ats/ats.ts +39 -0
  255. package/{resources → src/resources}/ats/candidates.ts +16 -10
  256. package/src/resources/ats/index.ts +8 -0
  257. package/{resources → src/resources}/ats/jobs.ts +16 -10
  258. package/{resources → src/resources}/ats/offers.ts +12 -6
  259. package/{resources → src/resources}/ats/stages.ts +11 -3
  260. package/{resources → src/resources}/hris/benefits/benefits.ts +35 -4
  261. package/{resources → src/resources}/hris/benefits/index.ts +2 -0
  262. package/{resources → src/resources}/hris/benefits/individuals.ts +25 -5
  263. package/{resources → src/resources}/hris/company.ts +47 -42
  264. package/{resources → src/resources}/hris/directory.ts +23 -17
  265. package/{resources → src/resources}/hris/hris.ts +47 -1
  266. package/{resources → src/resources}/hris/index.ts +7 -4
  267. package/{resources → src/resources}/hris/individuals/employment-data.ts +31 -21
  268. package/{resources → src/resources}/hris/individuals/index.ts +1 -0
  269. package/{resources → src/resources}/hris/individuals/individuals.ts +31 -16
  270. package/{resources → src/resources}/hris/pay-statements.ts +47 -36
  271. package/{resources → src/resources}/hris/payments.ts +18 -9
  272. package/{resources → src/resources}/providers.ts +16 -8
  273. package/src/streaming.ts +204 -0
  274. package/src/uploads.ts +248 -0
  275. package/src/version.ts +1 -0
  276. package/{dist/cjs/streaming.d.ts → streaming.d.ts} +4 -3
  277. package/streaming.d.ts.map +1 -0
  278. package/streaming.js +155 -0
  279. package/streaming.js.map +1 -0
  280. package/streaming.mjs +151 -0
  281. package/streaming.mjs.map +1 -0
  282. package/uploads.d.ts +90 -0
  283. package/uploads.d.ts.map +1 -0
  284. package/uploads.js +207 -0
  285. package/uploads.js.map +1 -0
  286. package/uploads.mjs +174 -0
  287. package/uploads.mjs.map +1 -0
  288. package/version.d.ts +2 -0
  289. package/version.d.ts.map +1 -0
  290. package/{dist/cjs/version.js → version.js} +1 -1
  291. package/version.js.map +1 -0
  292. package/version.mjs +2 -0
  293. package/version.mjs.map +1 -0
  294. package/.eslintrc.js +0 -10
  295. package/.github/workflows/publish-npm.yml +0 -28
  296. package/.github/workflows/release-doctor.yml +0 -20
  297. package/.github/workflows/release.yml +0 -38
  298. package/.prettierignore +0 -1
  299. package/.prettierrc +0 -6
  300. package/.release-please-manifest.json +0 -3
  301. package/.stats.yml +0 -1
  302. package/CHANGELOG.md +0 -40
  303. package/LICENSE +0 -201
  304. package/README.md +0 -219
  305. package/api.md +0 -186
  306. package/bin/check-release-environment +0 -25
  307. package/bin/check-test-server +0 -50
  308. package/bin/publish-npm +0 -6
  309. package/build +0 -12
  310. package/check-version.ts +0 -18
  311. package/dist/cjs/check-version.d.ts +0 -2
  312. package/dist/cjs/check-version.d.ts.map +0 -1
  313. package/dist/cjs/check-version.js +0 -23
  314. package/dist/cjs/check-version.js.map +0 -1
  315. package/dist/cjs/core.d.ts.map +0 -1
  316. package/dist/cjs/core.js +0 -950
  317. package/dist/cjs/core.js.map +0 -1
  318. package/dist/cjs/fetch-polyfill.d.ts +0 -6
  319. package/dist/cjs/fetch-polyfill.d.ts.map +0 -1
  320. package/dist/cjs/fetch-polyfill.js +0 -57
  321. package/dist/cjs/fetch-polyfill.js.map +0 -1
  322. package/dist/cjs/index.d.ts +0 -118
  323. package/dist/cjs/index.d.ts.map +0 -1
  324. package/dist/cjs/index.js.map +0 -1
  325. package/dist/cjs/pagination.d.ts.map +0 -1
  326. package/dist/cjs/pagination.js.map +0 -1
  327. package/dist/cjs/resource.d.ts.map +0 -1
  328. package/dist/cjs/resource.js.map +0 -1
  329. package/dist/cjs/resources/account.d.ts.map +0 -1
  330. package/dist/cjs/resources/account.js.map +0 -1
  331. package/dist/cjs/resources/ats/applications.d.ts.map +0 -1
  332. package/dist/cjs/resources/ats/applications.js.map +0 -1
  333. package/dist/cjs/resources/ats/ats.d.ts +0 -14
  334. package/dist/cjs/resources/ats/ats.d.ts.map +0 -1
  335. package/dist/cjs/resources/ats/ats.js +0 -22
  336. package/dist/cjs/resources/ats/ats.js.map +0 -1
  337. package/dist/cjs/resources/ats/candidates.d.ts.map +0 -1
  338. package/dist/cjs/resources/ats/candidates.js.map +0 -1
  339. package/dist/cjs/resources/ats/index.d.ts +0 -6
  340. package/dist/cjs/resources/ats/index.d.ts.map +0 -1
  341. package/dist/cjs/resources/ats/index.js +0 -12
  342. package/dist/cjs/resources/ats/index.js.map +0 -1
  343. package/dist/cjs/resources/ats/jobs.d.ts.map +0 -1
  344. package/dist/cjs/resources/ats/jobs.js.map +0 -1
  345. package/dist/cjs/resources/ats/offers.d.ts.map +0 -1
  346. package/dist/cjs/resources/ats/offers.js.map +0 -1
  347. package/dist/cjs/resources/ats/stages.d.ts.map +0 -1
  348. package/dist/cjs/resources/ats/stages.js.map +0 -1
  349. package/dist/cjs/resources/hris/benefits/benefits.d.ts.map +0 -1
  350. package/dist/cjs/resources/hris/benefits/benefits.js +0 -57
  351. package/dist/cjs/resources/hris/benefits/benefits.js.map +0 -1
  352. package/dist/cjs/resources/hris/benefits/index.d.ts.map +0 -1
  353. package/dist/cjs/resources/hris/benefits/index.js.map +0 -1
  354. package/dist/cjs/resources/hris/benefits/individuals.d.ts.map +0 -1
  355. package/dist/cjs/resources/hris/benefits/individuals.js.map +0 -1
  356. package/dist/cjs/resources/hris/company.d.ts.map +0 -1
  357. package/dist/cjs/resources/hris/company.js.map +0 -1
  358. package/dist/cjs/resources/hris/directory.d.ts.map +0 -1
  359. package/dist/cjs/resources/hris/directory.js.map +0 -1
  360. package/dist/cjs/resources/hris/hris.d.ts +0 -95
  361. package/dist/cjs/resources/hris/hris.d.ts.map +0 -1
  362. package/dist/cjs/resources/hris/hris.js +0 -24
  363. package/dist/cjs/resources/hris/hris.js.map +0 -1
  364. package/dist/cjs/resources/hris/index.d.ts.map +0 -1
  365. package/dist/cjs/resources/hris/index.js +0 -44
  366. package/dist/cjs/resources/hris/index.js.map +0 -1
  367. package/dist/cjs/resources/hris/individuals/employment-data.d.ts.map +0 -1
  368. package/dist/cjs/resources/hris/individuals/employment-data.js +0 -26
  369. package/dist/cjs/resources/hris/individuals/employment-data.js.map +0 -1
  370. package/dist/cjs/resources/hris/individuals/index.d.ts.map +0 -1
  371. package/dist/cjs/resources/hris/individuals/index.js.map +0 -1
  372. package/dist/cjs/resources/hris/individuals/individuals.d.ts.map +0 -1
  373. package/dist/cjs/resources/hris/individuals/individuals.js +0 -28
  374. package/dist/cjs/resources/hris/individuals/individuals.js.map +0 -1
  375. package/dist/cjs/resources/hris/pay-statements.d.ts.map +0 -1
  376. package/dist/cjs/resources/hris/pay-statements.js.map +0 -1
  377. package/dist/cjs/resources/hris/payments.d.ts.map +0 -1
  378. package/dist/cjs/resources/hris/payments.js.map +0 -1
  379. package/dist/cjs/resources/index.d.ts.map +0 -1
  380. package/dist/cjs/resources/index.js.map +0 -1
  381. package/dist/cjs/resources/providers.d.ts.map +0 -1
  382. package/dist/cjs/resources/providers.js.map +0 -1
  383. package/dist/cjs/resources/top-level.d.ts.map +0 -1
  384. package/dist/cjs/resources/top-level.js.map +0 -1
  385. package/dist/cjs/streaming.d.ts.map +0 -1
  386. package/dist/cjs/streaming.js +0 -220
  387. package/dist/cjs/streaming.js.map +0 -1
  388. package/dist/cjs/tests/api-resources/account.test.d.ts +0 -2
  389. package/dist/cjs/tests/api-resources/account.test.d.ts.map +0 -1
  390. package/dist/cjs/tests/api-resources/account.test.js +0 -66
  391. package/dist/cjs/tests/api-resources/account.test.js.map +0 -1
  392. package/dist/cjs/tests/api-resources/ats/applications.test.d.ts +0 -2
  393. package/dist/cjs/tests/api-resources/ats/applications.test.d.ts.map +0 -1
  394. package/dist/cjs/tests/api-resources/ats/applications.test.js +0 -73
  395. package/dist/cjs/tests/api-resources/ats/applications.test.js.map +0 -1
  396. package/dist/cjs/tests/api-resources/ats/candidates.test.d.ts +0 -2
  397. package/dist/cjs/tests/api-resources/ats/candidates.test.d.ts.map +0 -1
  398. package/dist/cjs/tests/api-resources/ats/candidates.test.js +0 -73
  399. package/dist/cjs/tests/api-resources/ats/candidates.test.js.map +0 -1
  400. package/dist/cjs/tests/api-resources/ats/jobs.test.d.ts +0 -2
  401. package/dist/cjs/tests/api-resources/ats/jobs.test.d.ts.map +0 -1
  402. package/dist/cjs/tests/api-resources/ats/jobs.test.js +0 -73
  403. package/dist/cjs/tests/api-resources/ats/jobs.test.js.map +0 -1
  404. package/dist/cjs/tests/api-resources/ats/offers.test.d.ts +0 -2
  405. package/dist/cjs/tests/api-resources/ats/offers.test.d.ts.map +0 -1
  406. package/dist/cjs/tests/api-resources/ats/offers.test.js +0 -73
  407. package/dist/cjs/tests/api-resources/ats/offers.test.js.map +0 -1
  408. package/dist/cjs/tests/api-resources/ats/stages.test.d.ts +0 -2
  409. package/dist/cjs/tests/api-resources/ats/stages.test.d.ts.map +0 -1
  410. package/dist/cjs/tests/api-resources/ats/stages.test.js +0 -55
  411. package/dist/cjs/tests/api-resources/ats/stages.test.js.map +0 -1
  412. package/dist/cjs/tests/api-resources/hris/benefits/benefits.test.d.ts +0 -2
  413. package/dist/cjs/tests/api-resources/hris/benefits/benefits.test.d.ts.map +0 -1
  414. package/dist/cjs/tests/api-resources/hris/benefits/benefits.test.js +0 -116
  415. package/dist/cjs/tests/api-resources/hris/benefits/benefits.test.js.map +0 -1
  416. package/dist/cjs/tests/api-resources/hris/benefits/individuals.test.d.ts +0 -2
  417. package/dist/cjs/tests/api-resources/hris/benefits/individuals.test.d.ts.map +0 -1
  418. package/dist/cjs/tests/api-resources/hris/benefits/individuals.test.js +0 -111
  419. package/dist/cjs/tests/api-resources/hris/benefits/individuals.test.js.map +0 -1
  420. package/dist/cjs/tests/api-resources/hris/company.test.d.ts +0 -2
  421. package/dist/cjs/tests/api-resources/hris/company.test.d.ts.map +0 -1
  422. package/dist/cjs/tests/api-resources/hris/company.test.js +0 -55
  423. package/dist/cjs/tests/api-resources/hris/company.test.js.map +0 -1
  424. package/dist/cjs/tests/api-resources/hris/directory.test.d.ts +0 -2
  425. package/dist/cjs/tests/api-resources/hris/directory.test.d.ts.map +0 -1
  426. package/dist/cjs/tests/api-resources/hris/directory.test.js +0 -62
  427. package/dist/cjs/tests/api-resources/hris/directory.test.js.map +0 -1
  428. package/dist/cjs/tests/api-resources/hris/individuals/employment-data.test.d.ts +0 -2
  429. package/dist/cjs/tests/api-resources/hris/individuals/employment-data.test.d.ts.map +0 -1
  430. package/dist/cjs/tests/api-resources/hris/individuals/employment-data.test.js +0 -56
  431. package/dist/cjs/tests/api-resources/hris/individuals/employment-data.test.js.map +0 -1
  432. package/dist/cjs/tests/api-resources/hris/individuals/individuals.test.d.ts +0 -2
  433. package/dist/cjs/tests/api-resources/hris/individuals/individuals.test.d.ts.map +0 -1
  434. package/dist/cjs/tests/api-resources/hris/individuals/individuals.test.js +0 -68
  435. package/dist/cjs/tests/api-resources/hris/individuals/individuals.test.js.map +0 -1
  436. package/dist/cjs/tests/api-resources/hris/pay-statements.test.d.ts +0 -2
  437. package/dist/cjs/tests/api-resources/hris/pay-statements.test.d.ts.map +0 -1
  438. package/dist/cjs/tests/api-resources/hris/pay-statements.test.js +0 -64
  439. package/dist/cjs/tests/api-resources/hris/pay-statements.test.js.map +0 -1
  440. package/dist/cjs/tests/api-resources/hris/payments.test.d.ts +0 -2
  441. package/dist/cjs/tests/api-resources/hris/payments.test.d.ts.map +0 -1
  442. package/dist/cjs/tests/api-resources/hris/payments.test.js +0 -52
  443. package/dist/cjs/tests/api-resources/hris/payments.test.js.map +0 -1
  444. package/dist/cjs/tests/api-resources/providers.test.d.ts +0 -2
  445. package/dist/cjs/tests/api-resources/providers.test.d.ts.map +0 -1
  446. package/dist/cjs/tests/api-resources/providers.test.js +0 -55
  447. package/dist/cjs/tests/api-resources/providers.test.js.map +0 -1
  448. package/dist/cjs/tests/api-resources/top-level.test.d.ts +0 -2
  449. package/dist/cjs/tests/api-resources/top-level.test.d.ts.map +0 -1
  450. package/dist/cjs/tests/api-resources/top-level.test.js +0 -52
  451. package/dist/cjs/tests/api-resources/top-level.test.js.map +0 -1
  452. package/dist/cjs/tests/form.test.d.ts +0 -2
  453. package/dist/cjs/tests/form.test.d.ts.map +0 -1
  454. package/dist/cjs/tests/form.test.js +0 -61
  455. package/dist/cjs/tests/form.test.js.map +0 -1
  456. package/dist/cjs/tests/index.test.d.ts +0 -2
  457. package/dist/cjs/tests/index.test.d.ts.map +0 -1
  458. package/dist/cjs/tests/index.test.js +0 -65
  459. package/dist/cjs/tests/index.test.js.map +0 -1
  460. package/dist/cjs/tests/responses.test.d.ts +0 -2
  461. package/dist/cjs/tests/responses.test.d.ts.map +0 -1
  462. package/dist/cjs/tests/responses.test.js +0 -60
  463. package/dist/cjs/tests/responses.test.js.map +0 -1
  464. package/dist/cjs/version.d.ts +0 -2
  465. package/dist/cjs/version.d.ts.map +0 -1
  466. package/dist/cjs/version.js.map +0 -1
  467. package/fetch-polyfill.ts +0 -69
  468. package/jest.config.js +0 -8
  469. package/release-please-config.json +0 -61
  470. package/resources/ats/ats.ts +0 -16
  471. package/resources/ats/index.ts +0 -7
  472. package/streaming.ts +0 -122
  473. package/tests/api-resources/account.test.ts +0 -29
  474. package/tests/api-resources/ats/applications.test.ts +0 -36
  475. package/tests/api-resources/ats/candidates.test.ts +0 -36
  476. package/tests/api-resources/ats/jobs.test.ts +0 -36
  477. package/tests/api-resources/ats/offers.test.ts +0 -36
  478. package/tests/api-resources/ats/stages.test.ts +0 -18
  479. package/tests/api-resources/hris/benefits/benefits.test.ts +0 -79
  480. package/tests/api-resources/hris/benefits/individuals.test.ts +0 -74
  481. package/tests/api-resources/hris/company.test.ts +0 -18
  482. package/tests/api-resources/hris/directory.test.ts +0 -25
  483. package/tests/api-resources/hris/individuals/employment-data.test.ts +0 -19
  484. package/tests/api-resources/hris/individuals/individuals.test.ts +0 -31
  485. package/tests/api-resources/hris/pay-statements.test.ts +0 -27
  486. package/tests/api-resources/hris/payments.test.ts +0 -15
  487. package/tests/api-resources/providers.test.ts +0 -18
  488. package/tests/api-resources/top-level.test.ts +0 -15
  489. package/tests/form.test.ts +0 -27
  490. package/tests/index.test.ts +0 -72
  491. package/tests/responses.test.ts +0 -25
  492. package/tsconfig.cjs.json +0 -8
  493. package/tsconfig.json +0 -39
  494. package/typings/digest-fetch/index.d.ts +0 -33
  495. package/version.ts +0 -1
  496. /package/{dist/cjs/resource.js → resource.js} +0 -0
  497. /package/{dist/cjs/resources → resources}/top-level.d.ts +0 -0
  498. /package/{dist/cjs/resources → resources}/top-level.js +0 -0
  499. /package/{resource.ts → src/resource.ts} +0 -0
  500. /package/{resources → src/resources}/index.ts +0 -0
  501. /package/{resources → src/resources}/top-level.ts +0 -0
@@ -0,0 +1,204 @@
1
+ import type { Response } from '@tryfinch/finch-api/_shims/fetch';
2
+ import { APIResponse, Headers, createResponseHeaders } from './core';
3
+
4
+ type ServerSentEvent = {
5
+ event: string | null;
6
+ data: string;
7
+ raw: string[];
8
+ };
9
+
10
+ class SSEDecoder {
11
+ private data: string[];
12
+ private event: string | null;
13
+ private chunks: string[];
14
+
15
+ constructor() {
16
+ this.event = null;
17
+ this.data = [];
18
+ this.chunks = [];
19
+ }
20
+
21
+ decode(line: string) {
22
+ if (line.endsWith('\r')) {
23
+ line = line.substring(0, line.length - 1);
24
+ }
25
+
26
+ if (!line) {
27
+ // empty line and we didn't previously encounter any messages
28
+ if (!this.event && !this.data.length) return null;
29
+
30
+ const sse: ServerSentEvent = {
31
+ event: this.event,
32
+ data: this.data.join('\n'),
33
+ raw: this.chunks,
34
+ };
35
+
36
+ this.event = null;
37
+ this.data = [];
38
+ this.chunks = [];
39
+
40
+ return sse;
41
+ }
42
+
43
+ this.chunks.push(line);
44
+
45
+ if (line.startsWith(':')) {
46
+ return null;
47
+ }
48
+
49
+ let [fieldname, _, value] = partition(line, ':');
50
+
51
+ if (value.startsWith(' ')) {
52
+ value = value.substring(1);
53
+ }
54
+
55
+ if (fieldname === 'event') {
56
+ this.event = value;
57
+ } else if (fieldname === 'data') {
58
+ this.data.push(value);
59
+ }
60
+
61
+ return null;
62
+ }
63
+ }
64
+
65
+ export class Stream<Item> implements AsyncIterable<Item>, APIResponse<Stream<Item>> {
66
+ /** @deprecated - please use the async iterator instead. We plan to add additional helper methods shortly. */
67
+ response: Response;
68
+ /** @deprecated - we plan to add a different way to access raw response information shortly. */
69
+ responseHeaders: Headers;
70
+ controller: AbortController;
71
+
72
+ private decoder: SSEDecoder;
73
+
74
+ constructor(response: Response, controller: AbortController) {
75
+ this.response = response;
76
+ this.controller = controller;
77
+ this.decoder = new SSEDecoder();
78
+ this.responseHeaders = createResponseHeaders(response.headers);
79
+ }
80
+
81
+ private async *iterMessages(): AsyncGenerator<ServerSentEvent, void, unknown> {
82
+ if (!this.response.body) {
83
+ this.controller.abort();
84
+ throw new Error(`Attempted to iterate over a response with no body`);
85
+ }
86
+
87
+ const lineDecoder = new LineDecoder();
88
+
89
+ // @ts-ignore
90
+ for await (const chunk of this.response.body) {
91
+ let text;
92
+ if (chunk instanceof Buffer) {
93
+ text = chunk.toString();
94
+ } else if ((chunk as any) instanceof Uint8Array) {
95
+ text = Buffer.from(chunk).toString();
96
+ } else {
97
+ text = chunk;
98
+ }
99
+
100
+ for (const line of lineDecoder.decode(text)) {
101
+ const sse = this.decoder.decode(line);
102
+ if (sse) yield sse;
103
+ }
104
+ }
105
+
106
+ for (const line of lineDecoder.flush()) {
107
+ const sse = this.decoder.decode(line);
108
+ if (sse) yield sse;
109
+ }
110
+ }
111
+
112
+ async *[Symbol.asyncIterator](): AsyncIterator<Item, any, undefined> {
113
+ try {
114
+ for await (const sse of this.iterMessages()) {
115
+ try {
116
+ yield JSON.parse(sse.data);
117
+ } catch (e) {
118
+ console.error(`Could not parse message into JSON:`, sse.data);
119
+ console.error(`From chunk:`, sse.raw);
120
+ throw e;
121
+ }
122
+ }
123
+ } catch (e) {
124
+ // If the user calls `stream.controller.abort()`, we should exit without throwing.
125
+ if (e instanceof Error && e.name === 'AbortError') return;
126
+ throw e;
127
+ } finally {
128
+ // If the user `break`s, abort the ongoing request.
129
+ this.controller.abort();
130
+ }
131
+ }
132
+ }
133
+
134
+ const NEWLINE_CHARS = '\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029';
135
+
136
+ /**
137
+ * A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
138
+ * reading lines from text.
139
+ *
140
+ * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
141
+ */
142
+ class LineDecoder {
143
+ buffer: string[];
144
+ trailingCR: boolean;
145
+
146
+ constructor() {
147
+ this.buffer = [];
148
+ this.trailingCR = false;
149
+ }
150
+
151
+ decode(text: string): string[] {
152
+ if (this.trailingCR) {
153
+ text = '\r' + text;
154
+ this.trailingCR = false;
155
+ }
156
+ if (text.endsWith('\r')) {
157
+ this.trailingCR = true;
158
+ text = text.slice(0, -1);
159
+ }
160
+
161
+ if (!text) {
162
+ return [];
163
+ }
164
+
165
+ const trailing_newline = NEWLINE_CHARS.includes(text.slice(-1));
166
+ let lines = text.split(/\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g);
167
+
168
+ if (lines.length === 1 && !trailing_newline) {
169
+ this.buffer.push(lines[0]!);
170
+ return [];
171
+ }
172
+
173
+ if (this.buffer.length > 0) {
174
+ lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
175
+ this.buffer = [];
176
+ }
177
+
178
+ if (!trailing_newline) {
179
+ this.buffer = [lines.pop() || ''];
180
+ }
181
+
182
+ return lines;
183
+ }
184
+
185
+ flush(): string[] {
186
+ if (!this.buffer.length && !this.trailingCR) {
187
+ return [];
188
+ }
189
+
190
+ const lines = [this.buffer.join('')];
191
+ this.buffer = [];
192
+ this.trailingCR = false;
193
+ return lines;
194
+ }
195
+ }
196
+
197
+ function partition(str: string, delimiter: string): [string, string, string] {
198
+ const index = str.indexOf(delimiter);
199
+ if (index !== -1) {
200
+ return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
201
+ }
202
+
203
+ return [str, '', ''];
204
+ }
package/src/uploads.ts ADDED
@@ -0,0 +1,248 @@
1
+ import { type RequestOptions } from './core';
2
+ import { type Readable } from '@tryfinch/finch-api/_shims/node-readable';
3
+ import { type BodyInit } from '@tryfinch/finch-api/_shims/fetch';
4
+ import { FormData, File, type FilePropertyBag } from '@tryfinch/finch-api/_shims/formdata';
5
+ import { getMultipartRequestOptions } from '@tryfinch/finch-api/_shims/getMultipartRequestOptions';
6
+ import { fileFromPath } from '@tryfinch/finch-api/_shims/fileFromPath';
7
+ import { type FsReadStream, isFsReadStream } from '@tryfinch/finch-api/_shims/node-readable';
8
+
9
+ export { fileFromPath };
10
+
11
+ export type BlobPart = string | ArrayBuffer | ArrayBufferView | BlobLike | Uint8Array | DataView;
12
+
13
+ /**
14
+ * Typically, this is a native "File" class.
15
+ *
16
+ * We provide the {@link toFile} utility to convert a variety of objects
17
+ * into the File class.
18
+ *
19
+ * For convenience, you can also pass a fetch Response, or in Node,
20
+ * the result of fs.createReadStream().
21
+ */
22
+ export type Uploadable = FileLike | ResponseLike | FsReadStream;
23
+
24
+ /**
25
+ * Intended to match web.Blob, node.Blob, node-fetch.Blob, etc.
26
+ */
27
+ export interface BlobLike {
28
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
29
+ readonly size: number;
30
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
31
+ readonly type: string;
32
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
33
+ text(): Promise<string>;
34
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
35
+ slice(start?: number, end?: number): BlobLike;
36
+ // unfortunately @types/node-fetch@^2.6.4 doesn't type the arrayBuffer method
37
+ }
38
+
39
+ /**
40
+ * Intended to match web.File, node.File, node-fetch.File, etc.
41
+ */
42
+ export interface FileLike extends BlobLike {
43
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
44
+ readonly lastModified: number;
45
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
46
+ readonly name: string;
47
+ }
48
+
49
+ /**
50
+ * Intended to match web.Response, node.Response, node-fetch.Response, etc.
51
+ */
52
+ export interface ResponseLike {
53
+ url: string;
54
+ blob(): Promise<BlobLike>;
55
+ }
56
+
57
+ export const isResponseLike = (value: any): value is ResponseLike =>
58
+ value != null &&
59
+ typeof value === 'object' &&
60
+ typeof value.url === 'string' &&
61
+ typeof value.blob === 'function';
62
+
63
+ export const isFileLike = (value: any): value is FileLike =>
64
+ value != null &&
65
+ typeof value === 'object' &&
66
+ typeof value.name === 'string' &&
67
+ typeof value.lastModified === 'number' &&
68
+ isBlobLike(value);
69
+
70
+ /**
71
+ * The BlobLike type omits arrayBuffer() because @types/node-fetch@^2.6.4 lacks it; but this check
72
+ * adds the arrayBuffer() method type because it is available and used at runtime
73
+ */
74
+ export const isBlobLike = (value: any): value is BlobLike & { arrayBuffer(): Promise<ArrayBuffer> } =>
75
+ value != null &&
76
+ typeof value === 'object' &&
77
+ typeof value.size === 'number' &&
78
+ typeof value.type === 'string' &&
79
+ typeof value.text === 'function' &&
80
+ typeof value.slice === 'function' &&
81
+ typeof value.arrayBuffer === 'function';
82
+
83
+ export const isUploadable = (value: any): value is Uploadable => {
84
+ return isFileLike(value) || isResponseLike(value) || isFsReadStream(value);
85
+ };
86
+
87
+ export type ToFileInput = Uploadable | Exclude<BlobPart, string> | AsyncIterable<BlobPart>;
88
+
89
+ /**
90
+ * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
91
+ * @param bits the raw content of the file. Can be an {@link Uploadable}, {@link BlobPart}, or {@link AsyncIterable} of {@link BlobPart}s
92
+ * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
93
+ * @param {Object=} options additional properties
94
+ * @param {string=} options.type the MIME type of the content
95
+ * @param {number=} options.lastModified the last modified timestamp
96
+ * @returns a {@link File} with the given properties
97
+ */
98
+ export async function toFile(
99
+ value: ToFileInput,
100
+ name?: string | null | undefined,
101
+ options: FilePropertyBag | undefined = {},
102
+ ): Promise<FileLike> {
103
+ if (isResponseLike(value)) {
104
+ const blob = await value.blob();
105
+ name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file';
106
+
107
+ return new File([blob as any], name, options);
108
+ }
109
+
110
+ const bits = await getBytes(value);
111
+
112
+ name ||= getName(value) ?? 'unknown_file';
113
+
114
+ if (!options.type) {
115
+ const type = (bits[0] as any)?.type;
116
+ if (typeof type === 'string') {
117
+ options = { ...options, type };
118
+ }
119
+ }
120
+
121
+ return new File(bits, name, options);
122
+ }
123
+
124
+ async function getBytes(value: ToFileInput): Promise<Array<BlobPart>> {
125
+ if (value instanceof Promise) return getBytes(await (value as any));
126
+
127
+ let parts: Array<BlobPart> = [];
128
+ if (
129
+ typeof value === 'string' ||
130
+ ArrayBuffer.isView(value) || // includes Uint8Array, Buffer, etc.
131
+ value instanceof ArrayBuffer
132
+ ) {
133
+ parts.push(value);
134
+ } else if (isBlobLike(value)) {
135
+ parts.push(await value.arrayBuffer());
136
+ } else if (
137
+ isAsyncIterableIterator(value) // includes Readable, ReadableStream, etc.
138
+ ) {
139
+ for await (const chunk of value) {
140
+ parts.push(chunk as BlobPart); // TODO, consider validating?
141
+ }
142
+ } else {
143
+ throw new Error(
144
+ `Unexpected data type: ${typeof value}; constructor: ${
145
+ value?.constructor?.name
146
+ }; props: ${propsForError(value)}`,
147
+ );
148
+ }
149
+
150
+ return parts;
151
+ }
152
+
153
+ function propsForError(value: any): string {
154
+ const props = Object.getOwnPropertyNames(value);
155
+ return `[${props.map((p) => `"${p}"`).join(', ')}]`;
156
+ }
157
+
158
+ function getName(value: any): string | undefined {
159
+ return (
160
+ getStringFromMaybeBuffer(value.name) ||
161
+ getStringFromMaybeBuffer(value.filename) ||
162
+ // For fs.ReadStream
163
+ getStringFromMaybeBuffer(value.path)?.split(/[\\/]/).pop()
164
+ );
165
+ }
166
+
167
+ const getStringFromMaybeBuffer = (x: string | Buffer | unknown): string | undefined => {
168
+ if (typeof x === 'string') return x;
169
+ if (typeof Buffer !== 'undefined' && x instanceof Buffer) return String(x);
170
+ return undefined;
171
+ };
172
+
173
+ const isAsyncIterableIterator = (value: any): value is AsyncIterableIterator<unknown> =>
174
+ value != null && typeof value === 'object' && typeof value[Symbol.asyncIterator] === 'function';
175
+
176
+ export class MultipartBody {
177
+ constructor(public body: Readable | BodyInit) {}
178
+ get [Symbol.toStringTag](): string {
179
+ return 'MultipartBody';
180
+ }
181
+ }
182
+
183
+ export const isMultipartBody = (body: any): body is MultipartBody =>
184
+ body && typeof body === 'object' && body.body && body[Symbol.toStringTag] === 'MultipartBody';
185
+
186
+ /**
187
+ * Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
188
+ * Otherwise returns the request as is.
189
+ */
190
+ export const maybeMultipartFormRequestOptions = async <T extends {} = Record<string, unknown>>(
191
+ opts: RequestOptions<T>,
192
+ ): Promise<RequestOptions<T | MultipartBody>> => {
193
+ if (!hasUploadableValue(opts.body)) return opts;
194
+
195
+ const form = await createForm(opts.body);
196
+ return getMultipartRequestOptions(form, opts);
197
+ };
198
+
199
+ export const multipartFormRequestOptions = async <T extends {} = Record<string, unknown>>(
200
+ opts: RequestOptions<T>,
201
+ ): Promise<RequestOptions<T | MultipartBody>> => {
202
+ const form = await createForm(opts.body);
203
+ return getMultipartRequestOptions(form, opts);
204
+ };
205
+
206
+ export const createForm = async <T = Record<string, unknown>>(body: T | undefined): Promise<FormData> => {
207
+ const form = new FormData();
208
+ await Promise.all(Object.entries(body || {}).map(([key, value]) => addFormValue(form, key, value)));
209
+ return form;
210
+ };
211
+
212
+ const hasUploadableValue = (value: unknown): boolean => {
213
+ if (isUploadable(value)) return true;
214
+ if (Array.isArray(value)) return value.some(hasUploadableValue);
215
+ if (value && typeof value === 'object') {
216
+ for (const k in value) {
217
+ if (hasUploadableValue((value as any)[k])) return true;
218
+ }
219
+ }
220
+ return false;
221
+ };
222
+
223
+ const addFormValue = async (form: FormData, key: string, value: unknown): Promise<void> => {
224
+ if (value === undefined) return;
225
+ if (value == null) {
226
+ throw new TypeError(
227
+ `Received null for "${key}"; to pass null in FormData, you must use the string 'null'`,
228
+ );
229
+ }
230
+
231
+ // TODO: make nested formats configurable
232
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
233
+ form.append(key, value);
234
+ } else if (isUploadable(value)) {
235
+ const file = await toFile(value);
236
+ form.append(key, file);
237
+ } else if (Array.isArray(value)) {
238
+ await Promise.all(value.map((entry) => addFormValue(form, key + '[]', entry)));
239
+ } else if (typeof value === 'object') {
240
+ await Promise.all(
241
+ Object.entries(value).map(([name, prop]) => addFormValue(form, `${key}[${name}]`, prop)),
242
+ );
243
+ } else {
244
+ throw new TypeError(
245
+ `Invalid value given to form, expected a string, number, boolean, object, Array, File or Blob but got ${value} instead`,
246
+ );
247
+ }
248
+ };
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const VERSION = '3.0.0'; // x-release-please-version
@@ -1,8 +1,9 @@
1
- /// <reference types="node" />
2
- import type { Response } from 'node-fetch';
3
- import { APIResponse, Headers } from './core';
1
+ import type { Response } from '@tryfinch/finch-api/_shims/fetch';
2
+ import { APIResponse, Headers } from './core.js';
4
3
  export declare class Stream<Item> implements AsyncIterable<Item>, APIResponse<Stream<Item>> {
4
+ /** @deprecated - please use the async iterator instead. We plan to add additional helper methods shortly. */
5
5
  response: Response;
6
+ /** @deprecated - we plan to add a different way to access raw response information shortly. */
6
7
  responseHeaders: Headers;
7
8
  controller: AbortController;
8
9
  private decoder;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,OAAO,EAAyB,MAAM,QAAQ,CAAC;AA+DrE,qBAAa,MAAM,CAAC,IAAI,CAAE,YAAW,aAAa,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACjF,6GAA6G;IAC7G,QAAQ,EAAE,QAAQ,CAAC;IACnB,+FAA+F;IAC/F,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,eAAe,CAAC;IAE5B,OAAO,CAAC,OAAO,CAAa;gBAEhB,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe;YAO5C,YAAY;IA+BpB,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,SAAS,CAAC;CAoBrE"}
package/streaming.js ADDED
@@ -0,0 +1,155 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ exports.Stream = void 0;
4
+ const core_1 = require('./core.js');
5
+ class SSEDecoder {
6
+ constructor() {
7
+ this.event = null;
8
+ this.data = [];
9
+ this.chunks = [];
10
+ }
11
+ decode(line) {
12
+ if (line.endsWith('\r')) {
13
+ line = line.substring(0, line.length - 1);
14
+ }
15
+ if (!line) {
16
+ // empty line and we didn't previously encounter any messages
17
+ if (!this.event && !this.data.length) return null;
18
+ const sse = {
19
+ event: this.event,
20
+ data: this.data.join('\n'),
21
+ raw: this.chunks,
22
+ };
23
+ this.event = null;
24
+ this.data = [];
25
+ this.chunks = [];
26
+ return sse;
27
+ }
28
+ this.chunks.push(line);
29
+ if (line.startsWith(':')) {
30
+ return null;
31
+ }
32
+ let [fieldname, _, value] = partition(line, ':');
33
+ if (value.startsWith(' ')) {
34
+ value = value.substring(1);
35
+ }
36
+ if (fieldname === 'event') {
37
+ this.event = value;
38
+ } else if (fieldname === 'data') {
39
+ this.data.push(value);
40
+ }
41
+ return null;
42
+ }
43
+ }
44
+ class Stream {
45
+ constructor(response, controller) {
46
+ this.response = response;
47
+ this.controller = controller;
48
+ this.decoder = new SSEDecoder();
49
+ this.responseHeaders = (0, core_1.createResponseHeaders)(response.headers);
50
+ }
51
+ async *iterMessages() {
52
+ if (!this.response.body) {
53
+ this.controller.abort();
54
+ throw new Error(`Attempted to iterate over a response with no body`);
55
+ }
56
+ const lineDecoder = new LineDecoder();
57
+ // @ts-ignore
58
+ for await (const chunk of this.response.body) {
59
+ let text;
60
+ if (chunk instanceof Buffer) {
61
+ text = chunk.toString();
62
+ } else if (chunk instanceof Uint8Array) {
63
+ text = Buffer.from(chunk).toString();
64
+ } else {
65
+ text = chunk;
66
+ }
67
+ for (const line of lineDecoder.decode(text)) {
68
+ const sse = this.decoder.decode(line);
69
+ if (sse) yield sse;
70
+ }
71
+ }
72
+ for (const line of lineDecoder.flush()) {
73
+ const sse = this.decoder.decode(line);
74
+ if (sse) yield sse;
75
+ }
76
+ }
77
+ async *[Symbol.asyncIterator]() {
78
+ try {
79
+ for await (const sse of this.iterMessages()) {
80
+ try {
81
+ yield JSON.parse(sse.data);
82
+ } catch (e) {
83
+ console.error(`Could not parse message into JSON:`, sse.data);
84
+ console.error(`From chunk:`, sse.raw);
85
+ throw e;
86
+ }
87
+ }
88
+ } catch (e) {
89
+ // If the user calls `stream.controller.abort()`, we should exit without throwing.
90
+ if (e instanceof Error && e.name === 'AbortError') return;
91
+ throw e;
92
+ } finally {
93
+ // If the user `break`s, abort the ongoing request.
94
+ this.controller.abort();
95
+ }
96
+ }
97
+ }
98
+ exports.Stream = Stream;
99
+ const NEWLINE_CHARS = '\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029';
100
+ /**
101
+ * A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
102
+ * reading lines from text.
103
+ *
104
+ * https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
105
+ */
106
+ class LineDecoder {
107
+ constructor() {
108
+ this.buffer = [];
109
+ this.trailingCR = false;
110
+ }
111
+ decode(text) {
112
+ if (this.trailingCR) {
113
+ text = '\r' + text;
114
+ this.trailingCR = false;
115
+ }
116
+ if (text.endsWith('\r')) {
117
+ this.trailingCR = true;
118
+ text = text.slice(0, -1);
119
+ }
120
+ if (!text) {
121
+ return [];
122
+ }
123
+ const trailing_newline = NEWLINE_CHARS.includes(text.slice(-1));
124
+ let lines = text.split(/\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g);
125
+ if (lines.length === 1 && !trailing_newline) {
126
+ this.buffer.push(lines[0]);
127
+ return [];
128
+ }
129
+ if (this.buffer.length > 0) {
130
+ lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
131
+ this.buffer = [];
132
+ }
133
+ if (!trailing_newline) {
134
+ this.buffer = [lines.pop() || ''];
135
+ }
136
+ return lines;
137
+ }
138
+ flush() {
139
+ if (!this.buffer.length && !this.trailingCR) {
140
+ return [];
141
+ }
142
+ const lines = [this.buffer.join('')];
143
+ this.buffer = [];
144
+ this.trailingCR = false;
145
+ return lines;
146
+ }
147
+ }
148
+ function partition(str, delimiter) {
149
+ const index = str.indexOf(delimiter);
150
+ if (index !== -1) {
151
+ return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
152
+ }
153
+ return [str, '', ''];
154
+ }
155
+ //# sourceMappingURL=streaming.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