increase 0.11.1 → 0.11.3

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 (532) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +7 -3
  3. package/_shims/MultipartBody.d.ts +9 -0
  4. package/_shims/MultipartBody.d.ts.map +1 -0
  5. package/_shims/MultipartBody.js +16 -0
  6. package/_shims/MultipartBody.js.map +1 -0
  7. package/_shims/MultipartBody.mjs +12 -0
  8. package/_shims/MultipartBody.mjs.map +1 -0
  9. package/_shims/README.md +46 -0
  10. package/{src/_shims/ReadableStream-node.ts → _shims/auto/runtime-bun.d.ts} +2 -3
  11. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  12. package/_shims/auto/runtime-bun.js +21 -0
  13. package/_shims/auto/runtime-bun.js.map +1 -0
  14. package/_shims/auto/runtime-bun.mjs +2 -0
  15. package/_shims/auto/runtime-bun.mjs.map +1 -0
  16. package/_shims/auto/runtime-node.d.ts +5 -0
  17. package/_shims/auto/runtime-node.d.ts.map +1 -0
  18. package/_shims/auto/runtime-node.js +21 -0
  19. package/_shims/auto/runtime-node.js.map +1 -0
  20. package/_shims/auto/runtime-node.mjs +2 -0
  21. package/_shims/auto/runtime-node.mjs.map +1 -0
  22. package/_shims/auto/runtime.d.ts +5 -0
  23. package/_shims/auto/runtime.d.ts.map +1 -0
  24. package/_shims/auto/runtime.js +21 -0
  25. package/_shims/auto/runtime.js.map +1 -0
  26. package/_shims/auto/runtime.mjs +2 -0
  27. package/_shims/auto/runtime.mjs.map +1 -0
  28. package/_shims/auto/types-node.d.ts +5 -0
  29. package/_shims/auto/types-node.d.ts.map +1 -0
  30. package/_shims/auto/types-node.js +21 -0
  31. package/_shims/auto/types-node.js.map +1 -0
  32. package/_shims/auto/types-node.mjs +2 -0
  33. package/_shims/auto/types-node.mjs.map +1 -0
  34. package/_shims/auto/types.d.ts +99 -0
  35. package/_shims/{ReadableStream.js → auto/types.js} +0 -2
  36. package/{src/_shims/ReadableStream.js → _shims/auto/types.mjs} +0 -2
  37. package/_shims/bun-runtime.d.ts +6 -0
  38. package/_shims/bun-runtime.d.ts.map +1 -0
  39. package/_shims/bun-runtime.js +14 -0
  40. package/_shims/bun-runtime.js.map +1 -0
  41. package/_shims/bun-runtime.mjs +10 -0
  42. package/_shims/bun-runtime.mjs.map +1 -0
  43. package/_shims/index.d.ts +79 -0
  44. package/_shims/index.js +13 -0
  45. package/_shims/index.mjs +7 -0
  46. package/_shims/manual-types.d.ts +12 -0
  47. package/_shims/manual-types.js +3 -0
  48. package/_shims/manual-types.mjs +3 -0
  49. package/_shims/node-runtime.d.ts +3 -0
  50. package/_shims/node-runtime.d.ts.map +1 -0
  51. package/_shims/node-runtime.js +87 -0
  52. package/_shims/node-runtime.js.map +1 -0
  53. package/_shims/node-runtime.mjs +54 -0
  54. package/_shims/node-runtime.mjs.map +1 -0
  55. package/_shims/node-types.d.ts +42 -0
  56. package/_shims/node-types.js +3 -0
  57. package/_shims/node-types.mjs +3 -0
  58. package/_shims/registry.d.ts +35 -0
  59. package/_shims/registry.d.ts.map +1 -0
  60. package/_shims/registry.js +39 -0
  61. package/_shims/registry.js.map +1 -0
  62. package/_shims/registry.mjs +35 -0
  63. package/_shims/registry.mjs.map +1 -0
  64. package/_shims/web-runtime.d.ts +5 -0
  65. package/_shims/web-runtime.d.ts.map +1 -0
  66. package/_shims/web-runtime.js +70 -0
  67. package/_shims/web-runtime.js.map +1 -0
  68. package/_shims/web-runtime.mjs +63 -0
  69. package/_shims/web-runtime.mjs.map +1 -0
  70. package/_shims/web-types.d.ts +82 -0
  71. package/_shims/web-types.js +3 -0
  72. package/_shims/web-types.mjs +3 -0
  73. package/core.d.ts +170 -218
  74. package/core.d.ts.map +1 -1
  75. package/core.js +682 -731
  76. package/core.js.map +1 -1
  77. package/core.mjs +676 -682
  78. package/core.mjs.map +1 -1
  79. package/error.d.ts +107 -178
  80. package/error.d.ts.map +1 -1
  81. package/error.js +251 -281
  82. package/error.js.map +1 -1
  83. package/error.mjs +247 -253
  84. package/error.mjs.map +1 -1
  85. package/index.d.mts +333 -356
  86. package/index.d.ts +333 -356
  87. package/index.d.ts.map +1 -1
  88. package/index.js +194 -264
  89. package/index.js.map +1 -1
  90. package/index.mjs +171 -198
  91. package/index.mjs.map +1 -1
  92. package/package.json +31 -58
  93. package/pagination.d.ts +25 -25
  94. package/pagination.js +29 -25
  95. package/pagination.mjs +27 -23
  96. package/resource.d.ts +10 -10
  97. package/resource.js +12 -12
  98. package/resource.mjs +10 -10
  99. package/resources/account-numbers.d.ts +202 -168
  100. package/resources/account-numbers.d.ts.map +1 -1
  101. package/resources/account-numbers.js +33 -31
  102. package/resources/account-numbers.js.map +1 -1
  103. package/resources/account-numbers.mjs +28 -26
  104. package/resources/account-numbers.mjs.map +1 -1
  105. package/resources/account-statements.d.ts +79 -81
  106. package/resources/account-statements.js +21 -21
  107. package/resources/account-statements.mjs +16 -14
  108. package/resources/account-transfers.d.ts +192 -194
  109. package/resources/account-transfers.js +39 -39
  110. package/resources/account-transfers.mjs +34 -32
  111. package/resources/accounts.d.ts +148 -151
  112. package/resources/accounts.js +39 -37
  113. package/resources/accounts.mjs +34 -32
  114. package/resources/ach-prenotifications.d.ts +370 -438
  115. package/resources/ach-prenotifications.d.ts.map +1 -1
  116. package/resources/ach-prenotifications.js +27 -27
  117. package/resources/ach-prenotifications.js.map +1 -1
  118. package/resources/ach-prenotifications.mjs +22 -20
  119. package/resources/ach-prenotifications.mjs.map +1 -1
  120. package/resources/ach-transfers.d.ts +604 -679
  121. package/resources/ach-transfers.d.ts.map +1 -1
  122. package/resources/ach-transfers.js +39 -37
  123. package/resources/ach-transfers.js.map +1 -1
  124. package/resources/ach-transfers.mjs +34 -32
  125. package/resources/ach-transfers.mjs.map +1 -1
  126. package/resources/balance-lookups.d.ts +35 -38
  127. package/resources/balance-lookups.js +12 -11
  128. package/resources/balance-lookups.mjs +9 -8
  129. package/resources/bookkeeping-accounts.d.ts +66 -70
  130. package/resources/bookkeeping-accounts.js +21 -21
  131. package/resources/bookkeeping-accounts.mjs +16 -14
  132. package/resources/bookkeeping-entries.d.ts +36 -37
  133. package/resources/bookkeeping-entries.js +15 -15
  134. package/resources/bookkeeping-entries.mjs +10 -8
  135. package/resources/bookkeeping-entry-sets.d.ts +61 -64
  136. package/resources/bookkeeping-entry-sets.js +12 -13
  137. package/resources/bookkeeping-entry-sets.mjs +9 -8
  138. package/resources/card-disputes.d.ts +127 -129
  139. package/resources/card-disputes.js +27 -25
  140. package/resources/card-disputes.mjs +22 -20
  141. package/resources/card-profiles.d.ts +235 -245
  142. package/resources/card-profiles.js +33 -31
  143. package/resources/card-profiles.mjs +28 -26
  144. package/resources/card-purchase-supplements.d.ts +219 -238
  145. package/resources/card-purchase-supplements.js +21 -21
  146. package/resources/card-purchase-supplements.mjs +16 -14
  147. package/resources/cards.d.ts +288 -279
  148. package/resources/cards.d.ts.map +1 -1
  149. package/resources/cards.js +39 -37
  150. package/resources/cards.js.map +1 -1
  151. package/resources/cards.mjs +34 -32
  152. package/resources/cards.mjs.map +1 -1
  153. package/resources/check-deposits.d.ts +238 -260
  154. package/resources/check-deposits.js +27 -25
  155. package/resources/check-deposits.mjs +22 -20
  156. package/resources/check-transfers.d.ts +487 -503
  157. package/resources/check-transfers.js +45 -43
  158. package/resources/check-transfers.mjs +40 -38
  159. package/resources/declined-transactions.d.ts +811 -926
  160. package/resources/declined-transactions.d.ts.map +1 -1
  161. package/resources/declined-transactions.js +21 -21
  162. package/resources/declined-transactions.js.map +1 -1
  163. package/resources/declined-transactions.mjs +16 -14
  164. package/resources/declined-transactions.mjs.map +1 -1
  165. package/resources/digital-wallet-tokens.d.ts +75 -77
  166. package/resources/digital-wallet-tokens.js +21 -21
  167. package/resources/digital-wallet-tokens.mjs +16 -14
  168. package/resources/documents.d.ts +78 -77
  169. package/resources/documents.js +21 -19
  170. package/resources/documents.mjs +16 -14
  171. package/resources/entities/beneficial-owners.d.ts +233 -244
  172. package/resources/entities/beneficial-owners.js +24 -25
  173. package/resources/entities/beneficial-owners.mjs +21 -20
  174. package/resources/entities/entities.d.ts +1532 -1585
  175. package/resources/entities/entities.d.ts.map +1 -1
  176. package/resources/entities/entities.js +67 -83
  177. package/resources/entities/entities.mjs +43 -42
  178. package/resources/entities/index.d.ts +4 -22
  179. package/resources/entities/index.js +12 -42
  180. package/resources/entities/index.mjs +4 -4
  181. package/resources/entities/supplemental-documents.d.ts +38 -44
  182. package/resources/entities/supplemental-documents.js +24 -24
  183. package/resources/entities/supplemental-documents.mjs +20 -18
  184. package/resources/event-subscriptions.d.ts +246 -355
  185. package/resources/event-subscriptions.d.ts.map +1 -1
  186. package/resources/event-subscriptions.js +33 -33
  187. package/resources/event-subscriptions.js.map +1 -1
  188. package/resources/event-subscriptions.mjs +28 -26
  189. package/resources/event-subscriptions.mjs.map +1 -1
  190. package/resources/events.d.ts +152 -254
  191. package/resources/events.d.ts.map +1 -1
  192. package/resources/events.js +21 -19
  193. package/resources/events.js.map +1 -1
  194. package/resources/events.mjs +16 -14
  195. package/resources/events.mjs.map +1 -1
  196. package/resources/exports.d.ts +210 -158
  197. package/resources/exports.d.ts.map +1 -1
  198. package/resources/exports.js +27 -25
  199. package/resources/exports.js.map +1 -1
  200. package/resources/exports.mjs +22 -20
  201. package/resources/exports.mjs.map +1 -1
  202. package/resources/external-accounts.d.ts +122 -128
  203. package/resources/external-accounts.js +33 -33
  204. package/resources/external-accounts.mjs +28 -26
  205. package/resources/files.d.ts +149 -196
  206. package/resources/files.js +30 -28
  207. package/resources/files.mjs +24 -22
  208. package/resources/groups.d.ts +35 -35
  209. package/resources/groups.js +12 -11
  210. package/resources/groups.mjs +9 -8
  211. package/resources/inbound-ach-transfers.d.ts +270 -305
  212. package/resources/inbound-ach-transfers.d.ts.map +1 -1
  213. package/resources/inbound-ach-transfers.js +42 -42
  214. package/resources/inbound-ach-transfers.js.map +1 -1
  215. package/resources/inbound-ach-transfers.mjs +37 -35
  216. package/resources/inbound-ach-transfers.mjs.map +1 -1
  217. package/resources/inbound-wire-drawdown-requests.d.ts +113 -119
  218. package/resources/inbound-wire-drawdown-requests.js +24 -25
  219. package/resources/inbound-wire-drawdown-requests.mjs +19 -19
  220. package/resources/index.d.ts +39 -205
  221. package/resources/index.js +114 -540
  222. package/resources/index.mjs +39 -42
  223. package/resources/oauth-connections.d.ts +43 -44
  224. package/resources/oauth-connections.js +21 -21
  225. package/resources/oauth-connections.mjs +16 -14
  226. package/resources/pending-transactions.d.ts +560 -601
  227. package/resources/pending-transactions.js +21 -21
  228. package/resources/pending-transactions.mjs +16 -14
  229. package/resources/programs.d.ts +41 -39
  230. package/resources/programs.js +21 -19
  231. package/resources/programs.mjs +16 -14
  232. package/resources/real-time-decisions.d.ts +384 -411
  233. package/resources/real-time-decisions.js +18 -19
  234. package/resources/real-time-decisions.mjs +15 -14
  235. package/resources/real-time-payments-transfers.d.ts +304 -342
  236. package/resources/real-time-payments-transfers.js +30 -30
  237. package/resources/real-time-payments-transfers.mjs +25 -23
  238. package/resources/routing-numbers.d.ts +52 -54
  239. package/resources/routing-numbers.js +18 -16
  240. package/resources/routing-numbers.mjs +14 -12
  241. package/resources/simulations/account-statements.d.ts +12 -15
  242. package/resources/simulations/account-statements.js +13 -14
  243. package/resources/simulations/account-statements.mjs +10 -9
  244. package/resources/simulations/account-transfers.d.ts +8 -11
  245. package/resources/simulations/account-transfers.js +13 -13
  246. package/resources/simulations/account-transfers.mjs +10 -10
  247. package/resources/simulations/ach-transfers.d.ts +3636 -3845
  248. package/resources/simulations/ach-transfers.d.ts.map +1 -1
  249. package/resources/simulations/ach-transfers.js +40 -35
  250. package/resources/simulations/ach-transfers.js.map +1 -1
  251. package/resources/simulations/ach-transfers.mjs +37 -32
  252. package/resources/simulations/ach-transfers.mjs.map +1 -1
  253. package/resources/simulations/card-disputes.d.ts +22 -26
  254. package/resources/simulations/card-disputes.js +15 -14
  255. package/resources/simulations/card-disputes.mjs +12 -11
  256. package/resources/simulations/card-profiles.d.ts +9 -9
  257. package/resources/simulations/card-profiles.js +14 -14
  258. package/resources/simulations/card-profiles.mjs +11 -11
  259. package/resources/simulations/card-refunds.d.ts +13 -16
  260. package/resources/simulations/card-refunds.js +13 -12
  261. package/resources/simulations/card-refunds.mjs +10 -9
  262. package/resources/simulations/cards.d.ts +1311 -1448
  263. package/resources/simulations/cards.d.ts.map +1 -1
  264. package/resources/simulations/cards.js +28 -27
  265. package/resources/simulations/cards.js.map +1 -1
  266. package/resources/simulations/cards.mjs +25 -24
  267. package/resources/simulations/cards.mjs.map +1 -1
  268. package/resources/simulations/check-deposits.d.ts +17 -17
  269. package/resources/simulations/check-deposits.js +26 -26
  270. package/resources/simulations/check-deposits.mjs +23 -23
  271. package/resources/simulations/check-transfers.d.ts +12 -18
  272. package/resources/simulations/check-transfers.js +19 -19
  273. package/resources/simulations/check-transfers.mjs +16 -16
  274. package/resources/simulations/digital-wallet-token-requests.d.ts +35 -43
  275. package/resources/simulations/digital-wallet-token-requests.js +13 -15
  276. package/resources/simulations/digital-wallet-token-requests.mjs +10 -9
  277. package/resources/simulations/documents.d.ts +11 -11
  278. package/resources/simulations/documents.js +12 -11
  279. package/resources/simulations/documents.mjs +9 -8
  280. package/resources/simulations/inbound-funds-holds.d.ts +63 -66
  281. package/resources/simulations/inbound-funds-holds.js +13 -14
  282. package/resources/simulations/inbound-funds-holds.mjs +10 -9
  283. package/resources/simulations/inbound-wire-drawdown-requests.d.ts +94 -97
  284. package/resources/simulations/inbound-wire-drawdown-requests.js +13 -15
  285. package/resources/simulations/inbound-wire-drawdown-requests.mjs +10 -11
  286. package/resources/simulations/index.d.ts +19 -40
  287. package/resources/simulations/index.js +40 -148
  288. package/resources/simulations/index.mjs +19 -19
  289. package/resources/simulations/interest-payments.d.ts +2503 -2752
  290. package/resources/simulations/interest-payments.d.ts.map +1 -1
  291. package/resources/simulations/interest-payments.js +13 -14
  292. package/resources/simulations/interest-payments.js.map +1 -1
  293. package/resources/simulations/interest-payments.mjs +10 -9
  294. package/resources/simulations/interest-payments.mjs.map +1 -1
  295. package/resources/simulations/programs.d.ts +13 -13
  296. package/resources/simulations/programs.js +14 -13
  297. package/resources/simulations/programs.mjs +11 -10
  298. package/resources/simulations/real-time-payments-transfers.d.ts +3368 -3744
  299. package/resources/simulations/real-time-payments-transfers.d.ts.map +1 -1
  300. package/resources/simulations/real-time-payments-transfers.js +24 -25
  301. package/resources/simulations/real-time-payments-transfers.js.map +1 -1
  302. package/resources/simulations/real-time-payments-transfers.mjs +21 -20
  303. package/resources/simulations/real-time-payments-transfers.mjs.map +1 -1
  304. package/resources/simulations/simulations.d.ts +75 -75
  305. package/resources/simulations/simulations.js +78 -101
  306. package/resources/simulations/simulations.mjs +56 -56
  307. package/resources/simulations/wire-transfers.d.ts +2566 -2810
  308. package/resources/simulations/wire-transfers.d.ts.map +1 -1
  309. package/resources/simulations/wire-transfers.js +12 -11
  310. package/resources/simulations/wire-transfers.js.map +1 -1
  311. package/resources/simulations/wire-transfers.mjs +9 -8
  312. package/resources/simulations/wire-transfers.mjs.map +1 -1
  313. package/resources/transactions.d.ts +2559 -2838
  314. package/resources/transactions.d.ts.map +1 -1
  315. package/resources/transactions.js +21 -19
  316. package/resources/transactions.js.map +1 -1
  317. package/resources/transactions.mjs +16 -14
  318. package/resources/transactions.mjs.map +1 -1
  319. package/resources/wire-drawdown-requests.d.ts +140 -147
  320. package/resources/wire-drawdown-requests.js +27 -27
  321. package/resources/wire-drawdown-requests.mjs +22 -20
  322. package/resources/wire-transfers.d.ts +320 -324
  323. package/resources/wire-transfers.d.ts.map +1 -1
  324. package/resources/wire-transfers.js +56 -54
  325. package/resources/wire-transfers.js.map +1 -1
  326. package/resources/wire-transfers.mjs +51 -49
  327. package/resources/wire-transfers.mjs.map +1 -1
  328. package/shims/node.d.ts +29 -0
  329. package/shims/node.d.ts.map +1 -0
  330. package/shims/node.js +31 -0
  331. package/shims/node.js.map +1 -0
  332. package/shims/node.mjs +5 -0
  333. package/shims/node.mjs.map +1 -0
  334. package/shims/web.d.ts +26 -0
  335. package/shims/web.d.ts.map +1 -0
  336. package/shims/web.js +31 -0
  337. package/shims/web.js.map +1 -0
  338. package/shims/web.mjs +5 -0
  339. package/shims/web.mjs.map +1 -0
  340. package/src/_shims/MultipartBody.ts +9 -0
  341. package/src/_shims/README.md +46 -0
  342. package/src/_shims/auto/runtime-bun.ts +4 -0
  343. package/src/_shims/auto/runtime-node.ts +4 -0
  344. package/src/_shims/auto/runtime.ts +4 -0
  345. package/src/_shims/auto/types-node.ts +4 -0
  346. package/src/_shims/auto/types.d.ts +99 -0
  347. package/src/_shims/auto/types.js +3 -0
  348. package/src/_shims/auto/types.mjs +3 -0
  349. package/src/_shims/bun-runtime.ts +14 -0
  350. package/src/_shims/index.d.ts +79 -0
  351. package/src/_shims/index.js +13 -0
  352. package/src/_shims/index.mjs +7 -0
  353. package/src/_shims/manual-types.d.ts +12 -0
  354. package/src/_shims/manual-types.js +3 -0
  355. package/src/_shims/manual-types.mjs +3 -0
  356. package/src/_shims/node-runtime.ts +79 -0
  357. package/src/_shims/node-types.d.ts +42 -0
  358. package/src/_shims/node-types.js +3 -0
  359. package/src/_shims/node-types.mjs +3 -0
  360. package/src/_shims/registry.ts +64 -0
  361. package/src/_shims/web-runtime.ts +91 -0
  362. package/src/_shims/web-types.d.ts +82 -0
  363. package/src/_shims/web-types.js +3 -0
  364. package/src/_shims/web-types.mjs +3 -0
  365. package/src/core.ts +71 -43
  366. package/src/error.ts +4 -2
  367. package/src/index.ts +9 -7
  368. package/src/pagination.ts +1 -1
  369. package/src/resource.ts +1 -1
  370. package/src/resources/account-numbers.ts +49 -5
  371. package/src/resources/account-statements.ts +5 -5
  372. package/src/resources/account-transfers.ts +5 -5
  373. package/src/resources/accounts.ts +5 -5
  374. package/src/resources/ach-prenotifications.ts +45 -16
  375. package/src/resources/ach-transfers.ts +47 -17
  376. package/src/resources/balance-lookups.ts +3 -3
  377. package/src/resources/bookkeeping-accounts.ts +5 -5
  378. package/src/resources/bookkeeping-entries.ts +5 -5
  379. package/src/resources/bookkeeping-entry-sets.ts +3 -3
  380. package/src/resources/card-disputes.ts +5 -5
  381. package/src/resources/card-profiles.ts +5 -5
  382. package/src/resources/card-purchase-supplements.ts +5 -5
  383. package/src/resources/cards.ts +15 -5
  384. package/src/resources/check-deposits.ts +5 -5
  385. package/src/resources/check-transfers.ts +5 -5
  386. package/src/resources/declined-transactions.ts +11 -5
  387. package/src/resources/digital-wallet-tokens.ts +5 -5
  388. package/src/resources/documents.ts +5 -5
  389. package/src/resources/entities/beneficial-owners.ts +5 -5
  390. package/src/resources/entities/entities.ts +18 -18
  391. package/src/resources/entities/index.ts +3 -3
  392. package/src/resources/entities/supplemental-documents.ts +5 -5
  393. package/src/resources/event-subscriptions.ts +13 -5
  394. package/src/resources/events.ts +11 -5
  395. package/src/resources/exports.ts +64 -7
  396. package/src/resources/external-accounts.ts +5 -5
  397. package/src/resources/files.ts +6 -6
  398. package/src/resources/groups.ts +3 -3
  399. package/src/resources/inbound-ach-transfers.ts +11 -5
  400. package/src/resources/inbound-wire-drawdown-requests.ts +5 -5
  401. package/src/resources/index.ts +38 -38
  402. package/src/resources/oauth-connections.ts +5 -5
  403. package/src/resources/pending-transactions.ts +5 -5
  404. package/src/resources/programs.ts +5 -5
  405. package/src/resources/real-time-decisions.ts +3 -3
  406. package/src/resources/real-time-payments-transfers.ts +5 -5
  407. package/src/resources/routing-numbers.ts +4 -4
  408. package/src/resources/simulations/account-statements.ts +4 -4
  409. package/src/resources/simulations/account-transfers.ts +3 -3
  410. package/src/resources/simulations/ach-transfers.ts +333 -29
  411. package/src/resources/simulations/card-disputes.ts +4 -4
  412. package/src/resources/simulations/card-profiles.ts +3 -3
  413. package/src/resources/simulations/card-refunds.ts +4 -4
  414. package/src/resources/simulations/cards.ts +10 -4
  415. package/src/resources/simulations/check-deposits.ts +3 -3
  416. package/src/resources/simulations/check-transfers.ts +3 -3
  417. package/src/resources/simulations/digital-wallet-token-requests.ts +3 -3
  418. package/src/resources/simulations/documents.ts +4 -4
  419. package/src/resources/simulations/inbound-funds-holds.ts +3 -3
  420. package/src/resources/simulations/inbound-wire-drawdown-requests.ts +4 -4
  421. package/src/resources/simulations/index.ts +18 -18
  422. package/src/resources/simulations/interest-payments.ts +42 -14
  423. package/src/resources/simulations/programs.ts +4 -4
  424. package/src/resources/simulations/real-time-payments-transfers.ts +49 -15
  425. package/src/resources/simulations/simulations.ts +19 -19
  426. package/src/resources/simulations/wire-transfers.ts +48 -14
  427. package/src/resources/transactions.ts +44 -16
  428. package/src/resources/wire-drawdown-requests.ts +5 -5
  429. package/src/resources/wire-transfers.ts +11 -5
  430. package/src/shims/node.ts +50 -0
  431. package/src/shims/web.ts +50 -0
  432. package/src/uploads.ts +12 -16
  433. package/src/version.ts +1 -1
  434. package/uploads.d.ts +23 -39
  435. package/uploads.d.ts.map +1 -1
  436. package/uploads.js +115 -157
  437. package/uploads.js.map +1 -1
  438. package/uploads.mjs +111 -133
  439. package/uploads.mjs.map +1 -1
  440. package/version.d.ts +2 -2
  441. package/version.js +4 -4
  442. package/version.mjs +2 -2
  443. package/_shims/ReadableStream-node.d.ts +0 -6
  444. package/_shims/ReadableStream-node.d.ts.map +0 -1
  445. package/_shims/ReadableStream-node.js +0 -14
  446. package/_shims/ReadableStream-node.js.map +0 -1
  447. package/_shims/ReadableStream-node.mjs +0 -3
  448. package/_shims/ReadableStream-node.mjs.map +0 -1
  449. package/_shims/ReadableStream.d.ts +0 -38
  450. package/_shims/ReadableStream.mjs +0 -7
  451. package/_shims/agent-node.d.ts +0 -7
  452. package/_shims/agent-node.d.ts.map +0 -1
  453. package/_shims/agent-node.js +0 -28
  454. package/_shims/agent-node.js.map +0 -1
  455. package/_shims/agent-node.mjs +0 -16
  456. package/_shims/agent-node.mjs.map +0 -1
  457. package/_shims/agent.d.ts +0 -9
  458. package/_shims/agent.d.ts.map +0 -1
  459. package/_shims/agent.js +0 -14
  460. package/_shims/agent.js.map +0 -1
  461. package/_shims/agent.mjs +0 -10
  462. package/_shims/agent.mjs.map +0 -1
  463. package/_shims/fetch-node.d.ts +0 -64
  464. package/_shims/fetch-node.js +0 -12
  465. package/_shims/fetch-node.mjs +0 -14
  466. package/_shims/fetch.d.ts +0 -60
  467. package/_shims/fetch.js +0 -13
  468. package/_shims/fetch.mjs +0 -15
  469. package/_shims/fileFromPath-node.d.ts +0 -17
  470. package/_shims/fileFromPath-node.d.ts.map +0 -1
  471. package/_shims/fileFromPath-node.js +0 -17
  472. package/_shims/fileFromPath-node.js.map +0 -1
  473. package/_shims/fileFromPath-node.mjs +0 -13
  474. package/_shims/fileFromPath-node.mjs.map +0 -1
  475. package/_shims/fileFromPath.d.ts +0 -22
  476. package/_shims/fileFromPath.d.ts.map +0 -1
  477. package/_shims/fileFromPath.js +0 -16
  478. package/_shims/fileFromPath.js.map +0 -1
  479. package/_shims/fileFromPath.mjs +0 -12
  480. package/_shims/fileFromPath.mjs.map +0 -1
  481. package/_shims/form-data-node.d.ts +0 -45
  482. package/_shims/form-data-node.js +0 -11
  483. package/_shims/form-data-node.mjs +0 -9
  484. package/_shims/form-data.d.ts +0 -43
  485. package/_shims/form-data.js +0 -17
  486. package/_shims/form-data.mjs +0 -20
  487. package/_shims/getMultipartRequestOptions-node.d.ts +0 -10
  488. package/_shims/getMultipartRequestOptions-node.d.ts.map +0 -1
  489. package/_shims/getMultipartRequestOptions-node.js +0 -22
  490. package/_shims/getMultipartRequestOptions-node.js.map +0 -1
  491. package/_shims/getMultipartRequestOptions-node.mjs +0 -18
  492. package/_shims/getMultipartRequestOptions-node.mjs.map +0 -1
  493. package/_shims/getMultipartRequestOptions.d.ts +0 -10
  494. package/_shims/getMultipartRequestOptions.d.ts.map +0 -1
  495. package/_shims/getMultipartRequestOptions.js +0 -12
  496. package/_shims/getMultipartRequestOptions.js.map +0 -1
  497. package/_shims/getMultipartRequestOptions.mjs +0 -8
  498. package/_shims/getMultipartRequestOptions.mjs.map +0 -1
  499. package/_shims/node-readable-node.d.ts +0 -8
  500. package/_shims/node-readable-node.d.ts.map +0 -1
  501. package/_shims/node-readable-node.js +0 -9
  502. package/_shims/node-readable-node.js.map +0 -1
  503. package/_shims/node-readable-node.mjs +0 -5
  504. package/_shims/node-readable-node.mjs.map +0 -1
  505. package/_shims/node-readable.d.ts +0 -23
  506. package/_shims/node-readable.d.ts.map +0 -1
  507. package/_shims/node-readable.js +0 -11
  508. package/_shims/node-readable.js.map +0 -1
  509. package/_shims/node-readable.mjs +0 -7
  510. package/_shims/node-readable.mjs.map +0 -1
  511. package/src/_shims/ReadableStream.d.ts +0 -38
  512. package/src/_shims/ReadableStream.mjs +0 -7
  513. package/src/_shims/agent-node.ts +0 -22
  514. package/src/_shims/agent.ts +0 -12
  515. package/src/_shims/fetch-node.d.ts +0 -64
  516. package/src/_shims/fetch-node.js +0 -12
  517. package/src/_shims/fetch-node.mjs +0 -14
  518. package/src/_shims/fetch.d.ts +0 -60
  519. package/src/_shims/fetch.js +0 -13
  520. package/src/_shims/fetch.mjs +0 -15
  521. package/src/_shims/fileFromPath-node.ts +0 -29
  522. package/src/_shims/fileFromPath.ts +0 -29
  523. package/src/_shims/form-data-node.d.ts +0 -45
  524. package/src/_shims/form-data-node.js +0 -11
  525. package/src/_shims/form-data-node.mjs +0 -9
  526. package/src/_shims/form-data.d.ts +0 -43
  527. package/src/_shims/form-data.js +0 -17
  528. package/src/_shims/form-data.mjs +0 -20
  529. package/src/_shims/getMultipartRequestOptions-node.ts +0 -25
  530. package/src/_shims/getMultipartRequestOptions.ts +0 -14
  531. package/src/_shims/node-readable-node.ts +0 -10
  532. package/src/_shims/node-readable.ts +0 -30
package/core.js CHANGED
@@ -1,517 +1,457 @@
1
- 'use strict';
2
- var __classPrivateFieldSet =
3
- (this && this.__classPrivateFieldSet) ||
4
- function (receiver, state, value, kind, f) {
5
- if (kind === 'm') throw new TypeError('Private method is not writable');
6
- if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a setter');
7
- if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver))
8
- throw new TypeError('Cannot write private member to an object whose class did not declare it');
9
- return (
10
- kind === 'a' ? f.call(receiver, value)
11
- : f ? (f.value = value)
12
- : state.set(receiver, value),
13
- value
14
- );
15
- };
16
- var __classPrivateFieldGet =
17
- (this && this.__classPrivateFieldGet) ||
18
- function (receiver, state, kind, f) {
19
- if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a getter');
20
- if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver))
21
- throw new TypeError('Cannot read private member from an object whose class did not declare it');
22
- return (
23
- kind === 'm' ? f
24
- : kind === 'a' ? f.call(receiver)
25
- : f ? f.value
26
- : state.get(receiver)
27
- );
28
- };
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
29
13
  var _AbstractPage_client;
30
- Object.defineProperty(exports, '__esModule', { value: true });
31
- exports.toBase64 =
32
- exports.getHeader =
33
- exports.isHeadersProtocol =
34
- exports.isRunningInBrowser =
35
- exports.debug =
36
- exports.hasOwn =
37
- exports.isEmptyObj =
38
- exports.maybeCoerceBoolean =
39
- exports.maybeCoerceFloat =
40
- exports.maybeCoerceInteger =
41
- exports.coerceBoolean =
42
- exports.coerceFloat =
43
- exports.coerceInteger =
44
- exports.readEnv =
45
- exports.ensurePresent =
46
- exports.castToError =
47
- exports.sleep =
48
- exports.safeJSON =
49
- exports.isRequestOptions =
50
- exports.createResponseHeaders =
51
- exports.PagePromise =
52
- exports.AbstractPage =
53
- exports.APIResource =
54
- exports.APIClient =
55
- exports.APIPromise =
56
- exports.createForm =
57
- exports.multipartFormRequestOptions =
58
- exports.maybeMultipartFormRequestOptions =
59
- void 0;
60
- const version_1 = require('./version.js');
61
- const error_1 = require('./error.js');
62
- const agent_1 = require('increase/_shims/agent');
63
- const fetch_1 = require('increase/_shims/fetch');
64
- const uploads_1 = require('./uploads.js');
65
- var uploads_2 = require('./uploads.js');
66
- Object.defineProperty(exports, 'maybeMultipartFormRequestOptions', {
67
- enumerable: true,
68
- get: function () {
69
- return uploads_2.maybeMultipartFormRequestOptions;
70
- },
71
- });
72
- Object.defineProperty(exports, 'multipartFormRequestOptions', {
73
- enumerable: true,
74
- get: function () {
75
- return uploads_2.multipartFormRequestOptions;
76
- },
77
- });
78
- Object.defineProperty(exports, 'createForm', {
79
- enumerable: true,
80
- get: function () {
81
- return uploads_2.createForm;
82
- },
83
- });
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.toBase64 = exports.getHeader = exports.isHeadersProtocol = exports.isRunningInBrowser = exports.debug = exports.hasOwn = exports.isEmptyObj = exports.maybeCoerceBoolean = exports.maybeCoerceFloat = exports.maybeCoerceInteger = exports.coerceBoolean = exports.coerceFloat = exports.coerceInteger = exports.readEnv = exports.ensurePresent = exports.castToError = exports.sleep = exports.safeJSON = exports.isRequestOptions = exports.createResponseHeaders = exports.PagePromise = exports.AbstractPage = exports.APIResource = exports.APIClient = exports.APIPromise = exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = void 0;
16
+ const version_1 = require("./version.js");
17
+ const error_1 = require("./error.js");
18
+ const index_1 = require("./_shims/index.js");
19
+ const uploads_1 = require("./uploads.js");
20
+ var uploads_2 = require("./uploads.js");
21
+ Object.defineProperty(exports, "maybeMultipartFormRequestOptions", { enumerable: true, get: function () { return uploads_2.maybeMultipartFormRequestOptions; } });
22
+ Object.defineProperty(exports, "multipartFormRequestOptions", { enumerable: true, get: function () { return uploads_2.multipartFormRequestOptions; } });
23
+ Object.defineProperty(exports, "createForm", { enumerable: true, get: function () { return uploads_2.createForm; } });
84
24
  const MAX_RETRIES = 2;
85
25
  async function defaultParseResponse(props) {
86
- const { response } = props;
87
- const contentType = response.headers.get('content-type');
88
- if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) {
89
- const json = await response.json();
90
- debug('response', response.status, response.url, response.headers, json);
91
- return json;
92
- }
93
- // TODO handle blob, arraybuffer, other content types, etc.
94
- const text = await response.text();
95
- debug('response', response.status, response.url, response.headers, text);
96
- return text;
26
+ const { response } = props;
27
+ const contentType = response.headers.get('content-type');
28
+ if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/json')) {
29
+ const json = await response.json();
30
+ debug('response', response.status, response.url, response.headers, json);
31
+ return json;
32
+ }
33
+ // TODO handle blob, arraybuffer, other content types, etc.
34
+ const text = await response.text();
35
+ debug('response', response.status, response.url, response.headers, text);
36
+ return text;
97
37
  }
98
38
  /**
99
39
  * A subclass of `Promise` providing additional helper methods
100
40
  * for interacting with the SDK.
101
41
  */
102
42
  class APIPromise extends Promise {
103
- constructor(responsePromise, parseResponse = defaultParseResponse) {
104
- super((resolve) => {
105
- // this is maybe a bit weird but this has to be a no-op to not implicitly
106
- // parse the response body; instead .then, .catch, .finally are overridden
107
- // to parse the response
108
- resolve(null);
109
- });
110
- this.responsePromise = responsePromise;
111
- this.parseResponse = parseResponse;
112
- }
113
- _thenUnwrap(transform) {
114
- return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
115
- }
116
- /**
117
- * Gets the raw `Response` instance instead of parsing the response
118
- * data.
119
- *
120
- * If you want to parse the response body but still get the `Response`
121
- * instance, you can use {@link withResponse()}.
122
- */
123
- asResponse() {
124
- return this.responsePromise.then((p) => p.response);
125
- }
126
- /**
127
- * Gets the parsed response data and the raw `Response` instance.
128
- *
129
- * If you just want to get the raw `Response` instance without parsing it,
130
- * you can use {@link asResponse()}.
131
- */
132
- async withResponse() {
133
- const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
134
- return { data, response };
135
- }
136
- parse() {
137
- if (!this.parsedPromise) {
138
- this.parsedPromise = this.responsePromise.then(this.parseResponse);
139
- }
140
- return this.parsedPromise;
141
- }
142
- then(onfulfilled, onrejected) {
143
- return this.parse().then(onfulfilled, onrejected);
144
- }
145
- catch(onrejected) {
146
- return this.parse().catch(onrejected);
147
- }
148
- finally(onfinally) {
149
- return this.parse().finally(onfinally);
150
- }
43
+ constructor(responsePromise, parseResponse = defaultParseResponse) {
44
+ super((resolve) => {
45
+ // this is maybe a bit weird but this has to be a no-op to not implicitly
46
+ // parse the response body; instead .then, .catch, .finally are overridden
47
+ // to parse the response
48
+ resolve(null);
49
+ });
50
+ this.responsePromise = responsePromise;
51
+ this.parseResponse = parseResponse;
52
+ }
53
+ _thenUnwrap(transform) {
54
+ return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
55
+ }
56
+ /**
57
+ * Gets the raw `Response` instance instead of parsing the response
58
+ * data.
59
+ *
60
+ * If you want to parse the response body but still get the `Response`
61
+ * instance, you can use {@link withResponse()}.
62
+ *
63
+ * 👋 Getting the wrong TypeScript type for `Response`?
64
+ * Try setting `"moduleResolution": "NodeNext"` if you can,
65
+ * or add one of these imports before your first `import … from 'increase'`:
66
+ * - `import 'increase/shims/node'` (if you're running on Node)
67
+ * - `import 'increase/shims/web'` (otherwise)
68
+ */
69
+ asResponse() {
70
+ return this.responsePromise.then((p) => p.response);
71
+ }
72
+ /**
73
+ * Gets the parsed response data and the raw `Response` instance.
74
+ *
75
+ * If you just want to get the raw `Response` instance without parsing it,
76
+ * you can use {@link asResponse()}.
77
+ *
78
+ *
79
+ * 👋 Getting the wrong TypeScript type for `Response`?
80
+ * Try setting `"moduleResolution": "NodeNext"` if you can,
81
+ * or add one of these imports before your first `import … from 'increase'`:
82
+ * - `import 'increase/shims/node'` (if you're running on Node)
83
+ * - `import 'increase/shims/web'` (otherwise)
84
+ */
85
+ async withResponse() {
86
+ const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
87
+ return { data, response };
88
+ }
89
+ parse() {
90
+ if (!this.parsedPromise) {
91
+ this.parsedPromise = this.responsePromise.then(this.parseResponse);
92
+ }
93
+ return this.parsedPromise;
94
+ }
95
+ then(onfulfilled, onrejected) {
96
+ return this.parse().then(onfulfilled, onrejected);
97
+ }
98
+ catch(onrejected) {
99
+ return this.parse().catch(onrejected);
100
+ }
101
+ finally(onfinally) {
102
+ return this.parse().finally(onfinally);
103
+ }
151
104
  }
152
105
  exports.APIPromise = APIPromise;
153
106
  class APIClient {
154
- constructor({
155
- baseURL,
156
- maxRetries,
157
- timeout = 60000, // 1 minute
158
- httpAgent,
159
- fetch: overridenFetch,
160
- }) {
161
- this.baseURL = baseURL;
162
- this.maxRetries = validatePositiveInteger(
163
- 'maxRetries',
164
- maxRetries !== null && maxRetries !== void 0 ? maxRetries : MAX_RETRIES,
165
- );
166
- this.timeout = validatePositiveInteger('timeout', timeout);
167
- this.httpAgent = httpAgent;
168
- this.fetch = overridenFetch !== null && overridenFetch !== void 0 ? overridenFetch : fetch_1.fetch;
169
- }
170
- authHeaders(opts) {
171
- return {};
172
- }
173
- /**
174
- * Override this to add your own default headers, for example:
175
- *
176
- * {
177
- * ...super.defaultHeaders(),
178
- * Authorization: 'Bearer 123',
179
- * }
180
- */
181
- defaultHeaders(opts) {
182
- return {
183
- Accept: 'application/json',
184
- 'Content-Type': 'application/json',
185
- 'User-Agent': this.getUserAgent(),
186
- ...getPlatformHeaders(),
187
- ...this.authHeaders(opts),
188
- };
189
- }
190
- /**
191
- * Override this to add your own headers validation:
192
- */
193
- validateHeaders(headers, customHeaders) {}
194
- defaultIdempotencyKey() {
195
- return `stainless-node-retry-${uuid4()}`;
196
- }
197
- get(path, opts) {
198
- return this.methodRequest('get', path, opts);
199
- }
200
- post(path, opts) {
201
- return this.methodRequest('post', path, opts);
202
- }
203
- patch(path, opts) {
204
- return this.methodRequest('patch', path, opts);
205
- }
206
- put(path, opts) {
207
- return this.methodRequest('put', path, opts);
208
- }
209
- delete(path, opts) {
210
- return this.methodRequest('delete', path, opts);
211
- }
212
- methodRequest(method, path, opts) {
213
- return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
214
- }
215
- getAPIList(path, Page, opts) {
216
- return this.requestAPIList(Page, { method: 'get', path, ...opts });
217
- }
218
- calculateContentLength(body) {
219
- if (typeof body === 'string') {
220
- if (typeof Buffer !== 'undefined') {
221
- return Buffer.byteLength(body, 'utf8').toString();
222
- }
223
- if (typeof TextEncoder !== 'undefined') {
224
- const encoder = new TextEncoder();
225
- const encoded = encoder.encode(body);
226
- return encoded.length.toString();
227
- }
107
+ constructor({ baseURL, maxRetries, timeout = 60000, // 1 minute
108
+ httpAgent, fetch: overridenFetch, }) {
109
+ this.baseURL = baseURL;
110
+ this.maxRetries = validatePositiveInteger('maxRetries', maxRetries !== null && maxRetries !== void 0 ? maxRetries : MAX_RETRIES);
111
+ this.timeout = validatePositiveInteger('timeout', timeout);
112
+ this.httpAgent = httpAgent;
113
+ this.fetch = overridenFetch !== null && overridenFetch !== void 0 ? overridenFetch : index_1.fetch;
228
114
  }
229
- return null;
230
- }
231
- buildRequest(options) {
232
- var _a, _b, _c, _d, _e, _f;
233
- const { method, path, query, headers: headers = {} } = options;
234
- const body =
235
- (0, uploads_1.isMultipartBody)(options.body) ? options.body.body
236
- : options.body ? JSON.stringify(options.body, null, 2)
237
- : null;
238
- const contentLength = this.calculateContentLength(body);
239
- const url = this.buildURL(path, query);
240
- if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
241
- const timeout = (_a = options.timeout) !== null && _a !== void 0 ? _a : this.timeout;
242
- const httpAgent =
243
- (
244
- (_c = (_b = options.httpAgent) !== null && _b !== void 0 ? _b : this.httpAgent) !== null &&
245
- _c !== void 0
246
- ) ?
247
- _c
248
- : (0, agent_1.getDefaultAgent)(url);
249
- const minAgentTimeout = timeout + 1000;
250
- if (
251
- typeof ((
252
- (_d = httpAgent === null || httpAgent === void 0 ? void 0 : httpAgent.options) === null ||
253
- _d === void 0
254
- ) ?
255
- void 0
256
- : _d.timeout) === 'number' &&
257
- minAgentTimeout > ((_e = httpAgent.options.timeout) !== null && _e !== void 0 ? _e : 0)
258
- ) {
259
- // Allow any given request to bump our agent active socket timeout.
260
- // This may seem strange, but leaking active sockets should be rare and not particularly problematic,
261
- // and without mutating agent we would need to create more of them.
262
- // This tradeoff optimizes for performance.
263
- httpAgent.options.timeout = minAgentTimeout;
264
- }
265
- if (this.idempotencyHeader && method !== 'get') {
266
- if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
267
- headers[this.idempotencyHeader] = options.idempotencyKey;
268
- }
269
- const reqHeaders = {
270
- ...(contentLength && { 'Content-Length': contentLength }),
271
- ...this.defaultHeaders(options),
272
- ...headers,
273
- };
274
- // let builtin fetch set the Content-Type for multipart bodies
275
- if ((0, uploads_1.isMultipartBody)(options.body) && !fetch_1.isPolyfilled) {
276
- delete reqHeaders['Content-Type'];
277
- }
278
- // Strip any headers being explicitly omitted with null
279
- Object.keys(reqHeaders).forEach((key) => reqHeaders[key] === null && delete reqHeaders[key]);
280
- const req = {
281
- method,
282
- ...(body && { body: body }),
283
- headers: reqHeaders,
284
- ...(httpAgent && { agent: httpAgent }),
285
- // @ts-ignore node-fetch uses a custom AbortSignal type that is
286
- // not compatible with standard web types
287
- signal: (_f = options.signal) !== null && _f !== void 0 ? _f : null,
288
- };
289
- this.validateHeaders(reqHeaders, headers);
290
- return { req, url, timeout };
291
- }
292
- /**
293
- * Used as a callback for mutating the given `RequestInit` object.
294
- *
295
- * This is useful for cases where you want to add certain headers based off of
296
- * the request properties, e.g. `method` or `url`.
297
- */
298
- async prepareRequest(request, { url, options }) {}
299
- parseHeaders(headers) {
300
- return (
301
- !headers ? {}
302
- : Symbol.iterator in headers ? Object.fromEntries(Array.from(headers).map((header) => [...header]))
303
- : { ...headers }
304
- );
305
- }
306
- makeStatusError(status, error, message, headers) {
307
- return error_1.APIError.generate(status, error, message, headers);
308
- }
309
- request(options, remainingRetries = null) {
310
- return new APIPromise(this.makeRequest(options, remainingRetries));
311
- }
312
- async makeRequest(optionsInput, retriesRemaining) {
313
- var _a, _b, _c;
314
- const options = await optionsInput;
315
- if (retriesRemaining == null) {
316
- retriesRemaining = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
317
- }
318
- const { req, url, timeout } = this.buildRequest(options);
319
- await this.prepareRequest(req, { url, options });
320
- debug('request', url, options, req.headers);
321
- if ((_b = options.signal) === null || _b === void 0 ? void 0 : _b.aborted) {
322
- throw new error_1.APIUserAbortError();
323
- }
324
- const controller = new AbortController();
325
- const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(exports.castToError);
326
- if (response instanceof Error) {
327
- if ((_c = options.signal) === null || _c === void 0 ? void 0 : _c.aborted) {
328
- throw new error_1.APIUserAbortError();
329
- }
330
- if (retriesRemaining) {
331
- return this.retryRequest(options, retriesRemaining);
332
- }
333
- if (response.name === 'AbortError') {
334
- throw new error_1.APIConnectionTimeoutError();
335
- }
336
- throw new error_1.APIConnectionError({ cause: response });
337
- }
338
- const responseHeaders = (0, exports.createResponseHeaders)(response.headers);
339
- if (!response.ok) {
340
- if (retriesRemaining && this.shouldRetry(response)) {
341
- return this.retryRequest(options, retriesRemaining, responseHeaders);
342
- }
343
- const errText = await response.text().catch((e) => (0, exports.castToError)(e).message);
344
- const errJSON = (0, exports.safeJSON)(errText);
345
- const errMessage = errJSON ? undefined : errText;
346
- debug('response', response.status, url, responseHeaders, errMessage);
347
- const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders);
348
- throw err;
349
- }
350
- return { response, options, controller };
351
- }
352
- requestAPIList(Page, options) {
353
- const request = this.makeRequest(options, null);
354
- return new PagePromise(this, request, Page);
355
- }
356
- buildURL(path, query) {
357
- const url =
358
- isAbsoluteURL(path) ?
359
- new URL(path)
360
- : new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
361
- const defaultQuery = this.defaultQuery();
362
- if (!isEmptyObj(defaultQuery)) {
363
- query = { ...defaultQuery, ...query };
364
- }
365
- if (query) {
366
- url.search = this.stringifyQuery(query);
367
- }
368
- return url.toString();
369
- }
370
- stringifyQuery(query) {
371
- return Object.entries(query)
372
- .filter(([_, value]) => typeof value !== 'undefined')
373
- .map(([key, value]) => {
374
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
375
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
115
+ authHeaders(opts) {
116
+ return {};
117
+ }
118
+ /**
119
+ * Override this to add your own default headers, for example:
120
+ *
121
+ * {
122
+ * ...super.defaultHeaders(),
123
+ * Authorization: 'Bearer 123',
124
+ * }
125
+ */
126
+ defaultHeaders(opts) {
127
+ return {
128
+ Accept: 'application/json',
129
+ 'Content-Type': 'application/json',
130
+ 'User-Agent': this.getUserAgent(),
131
+ ...getPlatformHeaders(),
132
+ ...this.authHeaders(opts),
133
+ };
134
+ }
135
+ /**
136
+ * Override this to add your own headers validation:
137
+ */
138
+ validateHeaders(headers, customHeaders) { }
139
+ defaultIdempotencyKey() {
140
+ return `stainless-node-retry-${uuid4()}`;
141
+ }
142
+ get(path, opts) {
143
+ return this.methodRequest('get', path, opts);
144
+ }
145
+ post(path, opts) {
146
+ return this.methodRequest('post', path, opts);
147
+ }
148
+ patch(path, opts) {
149
+ return this.methodRequest('patch', path, opts);
150
+ }
151
+ put(path, opts) {
152
+ return this.methodRequest('put', path, opts);
153
+ }
154
+ delete(path, opts) {
155
+ return this.methodRequest('delete', path, opts);
156
+ }
157
+ methodRequest(method, path, opts) {
158
+ return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts })));
159
+ }
160
+ getAPIList(path, Page, opts) {
161
+ return this.requestAPIList(Page, { method: 'get', path, ...opts });
162
+ }
163
+ calculateContentLength(body) {
164
+ if (typeof body === 'string') {
165
+ if (typeof Buffer !== 'undefined') {
166
+ return Buffer.byteLength(body, 'utf8').toString();
167
+ }
168
+ if (typeof TextEncoder !== 'undefined') {
169
+ const encoder = new TextEncoder();
170
+ const encoded = encoder.encode(body);
171
+ return encoded.length.toString();
172
+ }
173
+ }
174
+ return null;
175
+ }
176
+ buildRequest(options) {
177
+ var _a, _b, _c, _d, _e, _f;
178
+ const { method, path, query, headers: headers = {} } = options;
179
+ const body = (0, uploads_1.isMultipartBody)(options.body) ? options.body.body
180
+ : options.body ? JSON.stringify(options.body, null, 2)
181
+ : null;
182
+ const contentLength = this.calculateContentLength(body);
183
+ const url = this.buildURL(path, query);
184
+ if ('timeout' in options)
185
+ validatePositiveInteger('timeout', options.timeout);
186
+ const timeout = (_a = options.timeout) !== null && _a !== void 0 ? _a : this.timeout;
187
+ const httpAgent = (_c = (_b = options.httpAgent) !== null && _b !== void 0 ? _b : this.httpAgent) !== null && _c !== void 0 ? _c : (0, index_1.getDefaultAgent)(url);
188
+ const minAgentTimeout = timeout + 1000;
189
+ if (typeof ((_d = httpAgent === null || httpAgent === void 0 ? void 0 : httpAgent.options) === null || _d === void 0 ? void 0 : _d.timeout) === 'number' &&
190
+ minAgentTimeout > ((_e = httpAgent.options.timeout) !== null && _e !== void 0 ? _e : 0)) {
191
+ // Allow any given request to bump our agent active socket timeout.
192
+ // This may seem strange, but leaking active sockets should be rare and not particularly problematic,
193
+ // and without mutating agent we would need to create more of them.
194
+ // This tradeoff optimizes for performance.
195
+ httpAgent.options.timeout = minAgentTimeout;
196
+ }
197
+ if (this.idempotencyHeader && method !== 'get') {
198
+ if (!options.idempotencyKey)
199
+ options.idempotencyKey = this.defaultIdempotencyKey();
200
+ headers[this.idempotencyHeader] = options.idempotencyKey;
201
+ }
202
+ const reqHeaders = {
203
+ ...(contentLength && { 'Content-Length': contentLength }),
204
+ ...this.defaultHeaders(options),
205
+ ...headers,
206
+ };
207
+ // let builtin fetch set the Content-Type for multipart bodies
208
+ if ((0, uploads_1.isMultipartBody)(options.body) && index_1.kind !== 'node') {
209
+ delete reqHeaders['Content-Type'];
210
+ }
211
+ // Strip any headers being explicitly omitted with null
212
+ Object.keys(reqHeaders).forEach((key) => reqHeaders[key] === null && delete reqHeaders[key]);
213
+ const req = {
214
+ method,
215
+ ...(body && { body: body }),
216
+ headers: reqHeaders,
217
+ ...(httpAgent && { agent: httpAgent }),
218
+ // @ts-ignore node-fetch uses a custom AbortSignal type that is
219
+ // not compatible with standard web types
220
+ signal: (_f = options.signal) !== null && _f !== void 0 ? _f : null,
221
+ };
222
+ this.validateHeaders(reqHeaders, headers);
223
+ return { req, url, timeout };
224
+ }
225
+ /**
226
+ * Used as a callback for mutating the given `RequestInit` object.
227
+ *
228
+ * This is useful for cases where you want to add certain headers based off of
229
+ * the request properties, e.g. `method` or `url`.
230
+ */
231
+ async prepareRequest(request, { url, options }) { }
232
+ parseHeaders(headers) {
233
+ return (!headers ? {}
234
+ : Symbol.iterator in headers ?
235
+ Object.fromEntries(Array.from(headers).map((header) => [...header]))
236
+ : { ...headers });
237
+ }
238
+ makeStatusError(status, error, message, headers) {
239
+ return error_1.APIError.generate(status, error, message, headers);
240
+ }
241
+ request(options, remainingRetries = null) {
242
+ return new APIPromise(this.makeRequest(options, remainingRetries));
243
+ }
244
+ async makeRequest(optionsInput, retriesRemaining) {
245
+ var _a, _b, _c;
246
+ const options = await optionsInput;
247
+ if (retriesRemaining == null) {
248
+ retriesRemaining = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
249
+ }
250
+ const { req, url, timeout } = this.buildRequest(options);
251
+ await this.prepareRequest(req, { url, options });
252
+ debug('request', url, options, req.headers);
253
+ if ((_b = options.signal) === null || _b === void 0 ? void 0 : _b.aborted) {
254
+ throw new error_1.APIUserAbortError();
376
255
  }
377
- if (value === null) {
378
- return `${encodeURIComponent(key)}=`;
256
+ const controller = new AbortController();
257
+ const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(exports.castToError);
258
+ if (response instanceof Error) {
259
+ if ((_c = options.signal) === null || _c === void 0 ? void 0 : _c.aborted) {
260
+ throw new error_1.APIUserAbortError();
261
+ }
262
+ if (retriesRemaining) {
263
+ return this.retryRequest(options, retriesRemaining);
264
+ }
265
+ if (response.name === 'AbortError') {
266
+ throw new error_1.APIConnectionTimeoutError();
267
+ }
268
+ throw new error_1.APIConnectionError({ cause: response });
379
269
  }
380
- throw new Error(
381
- `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
382
- );
383
- })
384
- .join('&');
385
- }
386
- async fetchWithTimeout(url, init, ms, controller) {
387
- const { signal, ...options } = init || {};
388
- if (signal) signal.addEventListener('abort', () => controller.abort());
389
- const timeout = setTimeout(() => controller.abort(), ms);
390
- return this.getRequestClient()
391
- .fetch(url, { signal: controller.signal, ...options })
392
- .finally(() => {
393
- clearTimeout(timeout);
394
- });
395
- }
396
- getRequestClient() {
397
- return { fetch: this.fetch };
398
- }
399
- shouldRetry(response) {
400
- // Note this is not a standard header.
401
- const shouldRetryHeader = response.headers.get('x-should-retry');
402
- // If the server explicitly says whether or not to retry, obey.
403
- if (shouldRetryHeader === 'true') return true;
404
- if (shouldRetryHeader === 'false') return false;
405
- // Retry on request timeouts.
406
- if (response.status === 408) return true;
407
- // Retry on lock timeouts.
408
- if (response.status === 409) return true;
409
- // Retry on rate limits.
410
- if (response.status === 429) return true;
411
- // Retry internal errors.
412
- if (response.status >= 500) return true;
413
- return false;
414
- }
415
- async retryRequest(options, retriesRemaining, responseHeaders) {
416
- var _a;
417
- retriesRemaining -= 1;
418
- // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
419
- //
420
- // TODO: we may want to handle the case where the header is using the http-date syntax: "Retry-After: <http-date>".
421
- // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After#syntax for details.
422
- const retryAfter = parseInt(
423
- (responseHeaders === null || responseHeaders === void 0 ? void 0 : responseHeaders['retry-after']) ||
424
- '',
425
- );
426
- const maxRetries = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
427
- const timeout = this.calculateRetryTimeoutSeconds(retriesRemaining, retryAfter, maxRetries) * 1000;
428
- await (0, exports.sleep)(timeout);
429
- return this.makeRequest(options, retriesRemaining);
430
- }
431
- calculateRetryTimeoutSeconds(retriesRemaining, retryAfter, maxRetries) {
432
- const initialRetryDelay = 0.5;
433
- const maxRetryDelay = 2;
434
- // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
435
- // just do what it says.
436
- if (Number.isInteger(retryAfter) && retryAfter <= 60) {
437
- return retryAfter;
438
- }
439
- const numRetries = maxRetries - retriesRemaining;
440
- // Apply exponential backoff, but not more than the max.
441
- const sleepSeconds = Math.min(initialRetryDelay * Math.pow(numRetries - 1, 2), maxRetryDelay);
442
- // Apply some jitter, plus-or-minus half a second.
443
- const jitter = Math.random() - 0.5;
444
- return sleepSeconds + jitter;
445
- }
446
- getUserAgent() {
447
- return `${this.constructor.name}/JS ${version_1.VERSION}`;
448
- }
270
+ const responseHeaders = (0, exports.createResponseHeaders)(response.headers);
271
+ if (!response.ok) {
272
+ if (retriesRemaining && this.shouldRetry(response)) {
273
+ return this.retryRequest(options, retriesRemaining, responseHeaders);
274
+ }
275
+ const errText = await response.text().catch((e) => (0, exports.castToError)(e).message);
276
+ const errJSON = (0, exports.safeJSON)(errText);
277
+ const errMessage = errJSON ? undefined : errText;
278
+ debug('response', response.status, url, responseHeaders, errMessage);
279
+ const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders);
280
+ throw err;
281
+ }
282
+ return { response, options, controller };
283
+ }
284
+ requestAPIList(Page, options) {
285
+ const request = this.makeRequest(options, null);
286
+ return new PagePromise(this, request, Page);
287
+ }
288
+ buildURL(path, query) {
289
+ const url = isAbsoluteURL(path) ?
290
+ new URL(path)
291
+ : new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
292
+ const defaultQuery = this.defaultQuery();
293
+ if (!isEmptyObj(defaultQuery)) {
294
+ query = { ...defaultQuery, ...query };
295
+ }
296
+ if (query) {
297
+ url.search = this.stringifyQuery(query);
298
+ }
299
+ return url.toString();
300
+ }
301
+ stringifyQuery(query) {
302
+ return Object.entries(query)
303
+ .filter(([_, value]) => typeof value !== 'undefined')
304
+ .map(([key, value]) => {
305
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
306
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
307
+ }
308
+ if (value === null) {
309
+ return `${encodeURIComponent(key)}=`;
310
+ }
311
+ throw new error_1.IncreaseError(`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`);
312
+ })
313
+ .join('&');
314
+ }
315
+ async fetchWithTimeout(url, init, ms, controller) {
316
+ const { signal, ...options } = init || {};
317
+ if (signal)
318
+ signal.addEventListener('abort', () => controller.abort());
319
+ const timeout = setTimeout(() => controller.abort(), ms);
320
+ return (this.getRequestClient()
321
+ // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
322
+ .fetch.call(undefined, url, { signal: controller.signal, ...options })
323
+ .finally(() => {
324
+ clearTimeout(timeout);
325
+ }));
326
+ }
327
+ getRequestClient() {
328
+ return { fetch: this.fetch };
329
+ }
330
+ shouldRetry(response) {
331
+ // Note this is not a standard header.
332
+ const shouldRetryHeader = response.headers.get('x-should-retry');
333
+ // If the server explicitly says whether or not to retry, obey.
334
+ if (shouldRetryHeader === 'true')
335
+ return true;
336
+ if (shouldRetryHeader === 'false')
337
+ return false;
338
+ // Retry on request timeouts.
339
+ if (response.status === 408)
340
+ return true;
341
+ // Retry on lock timeouts.
342
+ if (response.status === 409)
343
+ return true;
344
+ // Retry on rate limits.
345
+ if (response.status === 429)
346
+ return true;
347
+ // Retry internal errors.
348
+ if (response.status >= 500)
349
+ return true;
350
+ return false;
351
+ }
352
+ async retryRequest(options, retriesRemaining, responseHeaders) {
353
+ var _a;
354
+ retriesRemaining -= 1;
355
+ // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
356
+ let timeoutMillis;
357
+ const retryAfterHeader = responseHeaders === null || responseHeaders === void 0 ? void 0 : responseHeaders['retry-after'];
358
+ if (retryAfterHeader) {
359
+ const timeoutSeconds = parseInt(retryAfterHeader);
360
+ if (!Number.isNaN(timeoutSeconds)) {
361
+ timeoutMillis = timeoutSeconds * 1000;
362
+ }
363
+ else {
364
+ timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
365
+ }
366
+ }
367
+ // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
368
+ // just do what it says, but otherwise calculate a default
369
+ if (!timeoutMillis ||
370
+ !Number.isInteger(timeoutMillis) ||
371
+ timeoutMillis <= 0 ||
372
+ timeoutMillis > 60 * 1000) {
373
+ const maxRetries = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : this.maxRetries;
374
+ timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
375
+ }
376
+ await (0, exports.sleep)(timeoutMillis);
377
+ return this.makeRequest(options, retriesRemaining);
378
+ }
379
+ calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
380
+ const initialRetryDelay = 0.5;
381
+ const maxRetryDelay = 2;
382
+ const numRetries = maxRetries - retriesRemaining;
383
+ // Apply exponential backoff, but not more than the max.
384
+ const sleepSeconds = Math.min(initialRetryDelay * Math.pow(numRetries - 1, 2), maxRetryDelay);
385
+ // Apply some jitter, plus-or-minus half a second.
386
+ const jitter = Math.random() - 0.5;
387
+ return (sleepSeconds + jitter) * 1000;
388
+ }
389
+ getUserAgent() {
390
+ return `${this.constructor.name}/JS ${version_1.VERSION}`;
391
+ }
449
392
  }
450
393
  exports.APIClient = APIClient;
451
394
  class APIResource {
452
- constructor(client) {
453
- this.client = client;
454
- this.get = client.get.bind(client);
455
- this.post = client.post.bind(client);
456
- this.patch = client.patch.bind(client);
457
- this.put = client.put.bind(client);
458
- this.delete = client.delete.bind(client);
459
- this.getAPIList = client.getAPIList.bind(client);
460
- }
395
+ constructor(client) {
396
+ this.client = client;
397
+ this.get = client.get.bind(client);
398
+ this.post = client.post.bind(client);
399
+ this.patch = client.patch.bind(client);
400
+ this.put = client.put.bind(client);
401
+ this.delete = client.delete.bind(client);
402
+ this.getAPIList = client.getAPIList.bind(client);
403
+ }
461
404
  }
462
405
  exports.APIResource = APIResource;
463
406
  class AbstractPage {
464
- constructor(client, response, body, options) {
465
- _AbstractPage_client.set(this, void 0);
466
- __classPrivateFieldSet(this, _AbstractPage_client, client, 'f');
467
- this.options = options;
468
- this.response = response;
469
- this.body = body;
470
- }
471
- hasNextPage() {
472
- const items = this.getPaginatedItems();
473
- if (!items.length) return false;
474
- return this.nextPageInfo() != null;
475
- }
476
- async getNextPage() {
477
- const nextInfo = this.nextPageInfo();
478
- if (!nextInfo) {
479
- throw new Error(
480
- 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
481
- );
482
- }
483
- const nextOptions = { ...this.options };
484
- if ('params' in nextInfo) {
485
- nextOptions.query = { ...nextOptions.query, ...nextInfo.params };
486
- } else if ('url' in nextInfo) {
487
- const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()];
488
- for (const [key, value] of params) {
489
- nextInfo.url.searchParams.set(key, value);
490
- }
491
- nextOptions.query = undefined;
492
- nextOptions.path = nextInfo.url.toString();
493
- }
494
- return await __classPrivateFieldGet(this, _AbstractPage_client, 'f').requestAPIList(
495
- this.constructor,
496
- nextOptions,
497
- );
498
- }
499
- async *iterPages() {
500
- // eslint-disable-next-line @typescript-eslint/no-this-alias
501
- let page = this;
502
- yield page;
503
- while (page.hasNextPage()) {
504
- page = await page.getNextPage();
505
- yield page;
506
- }
507
- }
508
- async *[((_AbstractPage_client = new WeakMap()), Symbol.asyncIterator)]() {
509
- for await (const page of this.iterPages()) {
510
- for (const item of page.getPaginatedItems()) {
511
- yield item;
512
- }
513
- }
514
- }
407
+ constructor(client, response, body, options) {
408
+ _AbstractPage_client.set(this, void 0);
409
+ __classPrivateFieldSet(this, _AbstractPage_client, client, "f");
410
+ this.options = options;
411
+ this.response = response;
412
+ this.body = body;
413
+ }
414
+ hasNextPage() {
415
+ const items = this.getPaginatedItems();
416
+ if (!items.length)
417
+ return false;
418
+ return this.nextPageInfo() != null;
419
+ }
420
+ async getNextPage() {
421
+ const nextInfo = this.nextPageInfo();
422
+ if (!nextInfo) {
423
+ throw new error_1.IncreaseError('No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.');
424
+ }
425
+ const nextOptions = { ...this.options };
426
+ if ('params' in nextInfo) {
427
+ nextOptions.query = { ...nextOptions.query, ...nextInfo.params };
428
+ }
429
+ else if ('url' in nextInfo) {
430
+ const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()];
431
+ for (const [key, value] of params) {
432
+ nextInfo.url.searchParams.set(key, value);
433
+ }
434
+ nextOptions.query = undefined;
435
+ nextOptions.path = nextInfo.url.toString();
436
+ }
437
+ return await __classPrivateFieldGet(this, _AbstractPage_client, "f").requestAPIList(this.constructor, nextOptions);
438
+ }
439
+ async *iterPages() {
440
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
441
+ let page = this;
442
+ yield page;
443
+ while (page.hasNextPage()) {
444
+ page = await page.getNextPage();
445
+ yield page;
446
+ }
447
+ }
448
+ async *[(_AbstractPage_client = new WeakMap(), Symbol.asyncIterator)]() {
449
+ for await (const page of this.iterPages()) {
450
+ for (const item of page.getPaginatedItems()) {
451
+ yield item;
452
+ }
453
+ }
454
+ }
515
455
  }
516
456
  exports.AbstractPage = AbstractPage;
517
457
  /**
@@ -524,217 +464,222 @@ exports.AbstractPage = AbstractPage;
524
464
  * }
525
465
  */
526
466
  class PagePromise extends APIPromise {
527
- constructor(client, request, Page) {
528
- super(
529
- request,
530
- async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options),
531
- );
532
- }
533
- /**
534
- * Allow auto-paginating iteration on an unawaited list call, eg:
535
- *
536
- * for await (const item of client.items.list()) {
537
- * console.log(item)
538
- * }
539
- */
540
- async *[Symbol.asyncIterator]() {
541
- const page = await this;
542
- for await (const item of page) {
543
- yield item;
544
- }
545
- }
467
+ constructor(client, request, Page) {
468
+ super(request, async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options));
469
+ }
470
+ /**
471
+ * Allow auto-paginating iteration on an unawaited list call, eg:
472
+ *
473
+ * for await (const item of client.items.list()) {
474
+ * console.log(item)
475
+ * }
476
+ */
477
+ async *[Symbol.asyncIterator]() {
478
+ const page = await this;
479
+ for await (const item of page) {
480
+ yield item;
481
+ }
482
+ }
546
483
  }
547
484
  exports.PagePromise = PagePromise;
548
485
  const createResponseHeaders = (headers) => {
549
- return new Proxy(
550
- Object.fromEntries(
551
- // @ts-ignore
552
- headers.entries(),
553
- ),
554
- {
555
- get(target, name) {
556
- const key = name.toString();
557
- return target[key.toLowerCase()] || target[key];
558
- },
559
- },
560
- );
486
+ return new Proxy(Object.fromEntries(
487
+ // @ts-ignore
488
+ headers.entries()), {
489
+ get(target, name) {
490
+ const key = name.toString();
491
+ return target[key.toLowerCase()] || target[key];
492
+ },
493
+ });
561
494
  };
562
495
  exports.createResponseHeaders = createResponseHeaders;
563
496
  // This is required so that we can determine if a given object matches the RequestOptions
564
497
  // type at runtime. While this requires duplication, it is enforced by the TypeScript
565
498
  // compiler such that any missing / extraneous keys will cause an error.
566
499
  const requestOptionsKeys = {
567
- method: true,
568
- path: true,
569
- query: true,
570
- body: true,
571
- headers: true,
572
- maxRetries: true,
573
- stream: true,
574
- timeout: true,
575
- httpAgent: true,
576
- signal: true,
577
- idempotencyKey: true,
500
+ method: true,
501
+ path: true,
502
+ query: true,
503
+ body: true,
504
+ headers: true,
505
+ maxRetries: true,
506
+ stream: true,
507
+ timeout: true,
508
+ httpAgent: true,
509
+ signal: true,
510
+ idempotencyKey: true,
578
511
  };
579
512
  const isRequestOptions = (obj) => {
580
- return (
581
- typeof obj === 'object' &&
582
- obj !== null &&
583
- !isEmptyObj(obj) &&
584
- Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k))
585
- );
513
+ return (typeof obj === 'object' &&
514
+ obj !== null &&
515
+ !isEmptyObj(obj) &&
516
+ Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k)));
586
517
  };
587
518
  exports.isRequestOptions = isRequestOptions;
588
519
  const getPlatformProperties = () => {
589
- if (typeof Deno !== 'undefined' && Deno.build != null) {
590
- return {
591
- 'X-Stainless-Lang': 'js',
592
- 'X-Stainless-Package-Version': version_1.VERSION,
593
- 'X-Stainless-OS': normalizePlatform(Deno.build.os),
594
- 'X-Stainless-Arch': normalizeArch(Deno.build.arch),
595
- 'X-Stainless-Runtime': 'deno',
596
- 'X-Stainless-Runtime-Version': Deno.version,
597
- };
598
- }
599
- if (typeof EdgeRuntime !== 'undefined') {
600
- return {
601
- 'X-Stainless-Lang': 'js',
602
- 'X-Stainless-Package-Version': version_1.VERSION,
603
- 'X-Stainless-OS': 'Unknown',
604
- 'X-Stainless-Arch': `other:${EdgeRuntime}`,
605
- 'X-Stainless-Runtime': 'edge',
606
- 'X-Stainless-Runtime-Version': process.version,
607
- };
608
- }
609
- // Check if Node.js
610
- if (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') {
611
- return {
612
- 'X-Stainless-Lang': 'js',
613
- 'X-Stainless-Package-Version': version_1.VERSION,
614
- 'X-Stainless-OS': normalizePlatform(process.platform),
615
- 'X-Stainless-Arch': normalizeArch(process.arch),
616
- 'X-Stainless-Runtime': 'node',
617
- 'X-Stainless-Runtime-Version': process.version,
618
- };
619
- }
620
- const browserInfo = getBrowserInfo();
621
- if (browserInfo) {
520
+ if (typeof Deno !== 'undefined' && Deno.build != null) {
521
+ return {
522
+ 'X-Stainless-Lang': 'js',
523
+ 'X-Stainless-Package-Version': version_1.VERSION,
524
+ 'X-Stainless-OS': normalizePlatform(Deno.build.os),
525
+ 'X-Stainless-Arch': normalizeArch(Deno.build.arch),
526
+ 'X-Stainless-Runtime': 'deno',
527
+ 'X-Stainless-Runtime-Version': Deno.version,
528
+ };
529
+ }
530
+ if (typeof EdgeRuntime !== 'undefined') {
531
+ return {
532
+ 'X-Stainless-Lang': 'js',
533
+ 'X-Stainless-Package-Version': version_1.VERSION,
534
+ 'X-Stainless-OS': 'Unknown',
535
+ 'X-Stainless-Arch': `other:${EdgeRuntime}`,
536
+ 'X-Stainless-Runtime': 'edge',
537
+ 'X-Stainless-Runtime-Version': process.version,
538
+ };
539
+ }
540
+ // Check if Node.js
541
+ if (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') {
542
+ return {
543
+ 'X-Stainless-Lang': 'js',
544
+ 'X-Stainless-Package-Version': version_1.VERSION,
545
+ 'X-Stainless-OS': normalizePlatform(process.platform),
546
+ 'X-Stainless-Arch': normalizeArch(process.arch),
547
+ 'X-Stainless-Runtime': 'node',
548
+ 'X-Stainless-Runtime-Version': process.version,
549
+ };
550
+ }
551
+ const browserInfo = getBrowserInfo();
552
+ if (browserInfo) {
553
+ return {
554
+ 'X-Stainless-Lang': 'js',
555
+ 'X-Stainless-Package-Version': version_1.VERSION,
556
+ 'X-Stainless-OS': 'Unknown',
557
+ 'X-Stainless-Arch': 'unknown',
558
+ 'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
559
+ 'X-Stainless-Runtime-Version': browserInfo.version,
560
+ };
561
+ }
562
+ // TODO add support for Cloudflare workers, etc.
622
563
  return {
623
- 'X-Stainless-Lang': 'js',
624
- 'X-Stainless-Package-Version': version_1.VERSION,
625
- 'X-Stainless-OS': 'Unknown',
626
- 'X-Stainless-Arch': 'unknown',
627
- 'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
628
- 'X-Stainless-Runtime-Version': browserInfo.version,
564
+ 'X-Stainless-Lang': 'js',
565
+ 'X-Stainless-Package-Version': version_1.VERSION,
566
+ 'X-Stainless-OS': 'Unknown',
567
+ 'X-Stainless-Arch': 'unknown',
568
+ 'X-Stainless-Runtime': 'unknown',
569
+ 'X-Stainless-Runtime-Version': 'unknown',
629
570
  };
630
- }
631
- // TODO add support for Cloudflare workers, etc.
632
- return {
633
- 'X-Stainless-Lang': 'js',
634
- 'X-Stainless-Package-Version': version_1.VERSION,
635
- 'X-Stainless-OS': 'Unknown',
636
- 'X-Stainless-Arch': 'unknown',
637
- 'X-Stainless-Runtime': 'unknown',
638
- 'X-Stainless-Runtime-Version': 'unknown',
639
- };
640
571
  };
641
572
  // Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
642
573
  function getBrowserInfo() {
643
- if (typeof navigator === 'undefined' || !navigator) {
574
+ if (typeof navigator === 'undefined' || !navigator) {
575
+ return null;
576
+ }
577
+ // NOTE: The order matters here!
578
+ const browserPatterns = [
579
+ { key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
580
+ { key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
581
+ { key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
582
+ { key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
583
+ { key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
584
+ { key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
585
+ ];
586
+ // Find the FIRST matching browser
587
+ for (const { key, pattern } of browserPatterns) {
588
+ const match = pattern.exec(navigator.userAgent);
589
+ if (match) {
590
+ const major = match[1] || 0;
591
+ const minor = match[2] || 0;
592
+ const patch = match[3] || 0;
593
+ return { browser: key, version: `${major}.${minor}.${patch}` };
594
+ }
595
+ }
644
596
  return null;
645
- }
646
- // NOTE: The order matters here!
647
- const browserPatterns = [
648
- { key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
649
- { key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
650
- { key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
651
- { key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
652
- { key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
653
- { key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
654
- ];
655
- // Find the FIRST matching browser
656
- for (const { key, pattern } of browserPatterns) {
657
- const match = pattern.exec(navigator.userAgent);
658
- if (match) {
659
- const major = match[1] || 0;
660
- const minor = match[2] || 0;
661
- const patch = match[3] || 0;
662
- return { browser: key, version: `${major}.${minor}.${patch}` };
663
- }
664
- }
665
- return null;
666
597
  }
667
598
  const normalizeArch = (arch) => {
668
- // Node docs:
669
- // - https://nodejs.org/api/process.html#processarch
670
- // Deno docs:
671
- // - https://doc.deno.land/deno/stable/~/Deno.build
672
- if (arch === 'x32') return 'x32';
673
- if (arch === 'x86_64' || arch === 'x64') return 'x64';
674
- if (arch === 'arm') return 'arm';
675
- if (arch === 'aarch64' || arch === 'arm64') return 'arm64';
676
- if (arch) return `other:${arch}`;
677
- return 'unknown';
599
+ // Node docs:
600
+ // - https://nodejs.org/api/process.html#processarch
601
+ // Deno docs:
602
+ // - https://doc.deno.land/deno/stable/~/Deno.build
603
+ if (arch === 'x32')
604
+ return 'x32';
605
+ if (arch === 'x86_64' || arch === 'x64')
606
+ return 'x64';
607
+ if (arch === 'arm')
608
+ return 'arm';
609
+ if (arch === 'aarch64' || arch === 'arm64')
610
+ return 'arm64';
611
+ if (arch)
612
+ return `other:${arch}`;
613
+ return 'unknown';
678
614
  };
679
615
  const normalizePlatform = (platform) => {
680
- // Node platforms:
681
- // - https://nodejs.org/api/process.html#processplatform
682
- // Deno platforms:
683
- // - https://doc.deno.land/deno/stable/~/Deno.build
684
- // - https://github.com/denoland/deno/issues/14799
685
- platform = platform.toLowerCase();
686
- // NOTE: this iOS check is untested and may not work
687
- // Node does not work natively on IOS, there is a fork at
688
- // https://github.com/nodejs-mobile/nodejs-mobile
689
- // however it is unknown at the time of writing how to detect if it is running
690
- if (platform.includes('ios')) return 'iOS';
691
- if (platform === 'android') return 'Android';
692
- if (platform === 'darwin') return 'MacOS';
693
- if (platform === 'win32') return 'Windows';
694
- if (platform === 'freebsd') return 'FreeBSD';
695
- if (platform === 'openbsd') return 'OpenBSD';
696
- if (platform === 'linux') return 'Linux';
697
- if (platform) return `Other:${platform}`;
698
- return 'Unknown';
616
+ // Node platforms:
617
+ // - https://nodejs.org/api/process.html#processplatform
618
+ // Deno platforms:
619
+ // - https://doc.deno.land/deno/stable/~/Deno.build
620
+ // - https://github.com/denoland/deno/issues/14799
621
+ platform = platform.toLowerCase();
622
+ // NOTE: this iOS check is untested and may not work
623
+ // Node does not work natively on IOS, there is a fork at
624
+ // https://github.com/nodejs-mobile/nodejs-mobile
625
+ // however it is unknown at the time of writing how to detect if it is running
626
+ if (platform.includes('ios'))
627
+ return 'iOS';
628
+ if (platform === 'android')
629
+ return 'Android';
630
+ if (platform === 'darwin')
631
+ return 'MacOS';
632
+ if (platform === 'win32')
633
+ return 'Windows';
634
+ if (platform === 'freebsd')
635
+ return 'FreeBSD';
636
+ if (platform === 'openbsd')
637
+ return 'OpenBSD';
638
+ if (platform === 'linux')
639
+ return 'Linux';
640
+ if (platform)
641
+ return `Other:${platform}`;
642
+ return 'Unknown';
699
643
  };
700
644
  let _platformHeaders;
701
645
  const getPlatformHeaders = () => {
702
- return _platformHeaders !== null && _platformHeaders !== void 0 ?
703
- _platformHeaders
704
- : (_platformHeaders = getPlatformProperties());
646
+ return (_platformHeaders !== null && _platformHeaders !== void 0 ? _platformHeaders : (_platformHeaders = getPlatformProperties()));
705
647
  };
706
648
  const safeJSON = (text) => {
707
- try {
708
- return JSON.parse(text);
709
- } catch (err) {
710
- return undefined;
711
- }
649
+ try {
650
+ return JSON.parse(text);
651
+ }
652
+ catch (err) {
653
+ return undefined;
654
+ }
712
655
  };
713
656
  exports.safeJSON = safeJSON;
714
657
  // https://stackoverflow.com/a/19709846
715
658
  const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
716
659
  const isAbsoluteURL = (url) => {
717
- return startsWithSchemeRegexp.test(url);
660
+ return startsWithSchemeRegexp.test(url);
718
661
  };
719
662
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
720
663
  exports.sleep = sleep;
721
664
  const validatePositiveInteger = (name, n) => {
722
- if (typeof n !== 'number' || !Number.isInteger(n)) {
723
- throw new Error(`${name} must be an integer`);
724
- }
725
- if (n < 0) {
726
- throw new Error(`${name} must be a positive integer`);
727
- }
728
- return n;
665
+ if (typeof n !== 'number' || !Number.isInteger(n)) {
666
+ throw new error_1.IncreaseError(`${name} must be an integer`);
667
+ }
668
+ if (n < 0) {
669
+ throw new error_1.IncreaseError(`${name} must be a positive integer`);
670
+ }
671
+ return n;
729
672
  };
730
673
  const castToError = (err) => {
731
- if (err instanceof Error) return err;
732
- return new Error(err);
674
+ if (err instanceof Error)
675
+ return err;
676
+ return new Error(err);
733
677
  };
734
678
  exports.castToError = castToError;
735
679
  const ensurePresent = (value) => {
736
- if (value == null) throw new Error(`Expected a value to be given but received ${value} instead.`);
737
- return value;
680
+ if (value == null)
681
+ throw new error_1.IncreaseError(`Expected a value to be given but received ${value} instead.`);
682
+ return value;
738
683
  };
739
684
  exports.ensurePresent = ensurePresent;
740
685
  /**
@@ -743,126 +688,132 @@ exports.ensurePresent = ensurePresent;
743
688
  * Will return undefined if the environment variable doesn't exist or cannot be accessed.
744
689
  */
745
690
  const readEnv = (env) => {
746
- var _a, _b, _c, _d;
747
- if (typeof process !== 'undefined') {
748
- return (_b = (_a = process.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ?
749
- _b
750
- : undefined;
751
- }
752
- if (typeof Deno !== 'undefined') {
753
- return (_d = (_c = Deno.env) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ?
754
- void 0
755
- : _d.call(_c, env);
756
- }
757
- return undefined;
691
+ var _a, _b, _c, _d;
692
+ if (typeof process !== 'undefined') {
693
+ return (_b = (_a = process.env) === null || _a === void 0 ? void 0 : _a[env]) !== null && _b !== void 0 ? _b : undefined;
694
+ }
695
+ if (typeof Deno !== 'undefined') {
696
+ return (_d = (_c = Deno.env) === null || _c === void 0 ? void 0 : _c.get) === null || _d === void 0 ? void 0 : _d.call(_c, env);
697
+ }
698
+ return undefined;
758
699
  };
759
700
  exports.readEnv = readEnv;
760
701
  const coerceInteger = (value) => {
761
- if (typeof value === 'number') return Math.round(value);
762
- if (typeof value === 'string') return parseInt(value, 10);
763
- throw new Error(`Could not coerce ${value} (type: ${typeof value}) into a number`);
702
+ if (typeof value === 'number')
703
+ return Math.round(value);
704
+ if (typeof value === 'string')
705
+ return parseInt(value, 10);
706
+ throw new error_1.IncreaseError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
764
707
  };
765
708
  exports.coerceInteger = coerceInteger;
766
709
  const coerceFloat = (value) => {
767
- if (typeof value === 'number') return value;
768
- if (typeof value === 'string') return parseFloat(value);
769
- throw new Error(`Could not coerce ${value} (type: ${typeof value}) into a number`);
710
+ if (typeof value === 'number')
711
+ return value;
712
+ if (typeof value === 'string')
713
+ return parseFloat(value);
714
+ throw new error_1.IncreaseError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
770
715
  };
771
716
  exports.coerceFloat = coerceFloat;
772
717
  const coerceBoolean = (value) => {
773
- if (typeof value === 'boolean') return value;
774
- if (typeof value === 'string') return value === 'true';
775
- return Boolean(value);
718
+ if (typeof value === 'boolean')
719
+ return value;
720
+ if (typeof value === 'string')
721
+ return value === 'true';
722
+ return Boolean(value);
776
723
  };
777
724
  exports.coerceBoolean = coerceBoolean;
778
725
  const maybeCoerceInteger = (value) => {
779
- if (value === undefined) {
780
- return undefined;
781
- }
782
- return (0, exports.coerceInteger)(value);
726
+ if (value === undefined) {
727
+ return undefined;
728
+ }
729
+ return (0, exports.coerceInteger)(value);
783
730
  };
784
731
  exports.maybeCoerceInteger = maybeCoerceInteger;
785
732
  const maybeCoerceFloat = (value) => {
786
- if (value === undefined) {
787
- return undefined;
788
- }
789
- return (0, exports.coerceFloat)(value);
733
+ if (value === undefined) {
734
+ return undefined;
735
+ }
736
+ return (0, exports.coerceFloat)(value);
790
737
  };
791
738
  exports.maybeCoerceFloat = maybeCoerceFloat;
792
739
  const maybeCoerceBoolean = (value) => {
793
- if (value === undefined) {
794
- return undefined;
795
- }
796
- return (0, exports.coerceBoolean)(value);
740
+ if (value === undefined) {
741
+ return undefined;
742
+ }
743
+ return (0, exports.coerceBoolean)(value);
797
744
  };
798
745
  exports.maybeCoerceBoolean = maybeCoerceBoolean;
799
746
  // https://stackoverflow.com/a/34491287
800
747
  function isEmptyObj(obj) {
801
- if (!obj) return true;
802
- for (const _k in obj) return false;
803
- return true;
748
+ if (!obj)
749
+ return true;
750
+ for (const _k in obj)
751
+ return false;
752
+ return true;
804
753
  }
805
754
  exports.isEmptyObj = isEmptyObj;
806
755
  // https://eslint.org/docs/latest/rules/no-prototype-builtins
807
756
  function hasOwn(obj, key) {
808
- return Object.prototype.hasOwnProperty.call(obj, key);
757
+ return Object.prototype.hasOwnProperty.call(obj, key);
809
758
  }
810
759
  exports.hasOwn = hasOwn;
811
760
  function debug(action, ...args) {
812
- if (typeof process !== 'undefined' && process.env['DEBUG'] === 'true') {
813
- console.log(`Increase:DEBUG:${action}`, ...args);
814
- }
761
+ if (typeof process !== 'undefined' && process.env['DEBUG'] === 'true') {
762
+ console.log(`Increase:DEBUG:${action}`, ...args);
763
+ }
815
764
  }
816
765
  exports.debug = debug;
817
766
  /**
818
767
  * https://stackoverflow.com/a/2117523
819
768
  */
820
769
  const uuid4 = () => {
821
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
822
- const r = (Math.random() * 16) | 0;
823
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
824
- return v.toString(16);
825
- });
770
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
771
+ const r = (Math.random() * 16) | 0;
772
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
773
+ return v.toString(16);
774
+ });
826
775
  };
827
776
  const isRunningInBrowser = () => {
828
- return (
777
+ return (
829
778
  // @ts-ignore
830
779
  typeof window !== 'undefined' &&
831
- // @ts-ignore
832
- typeof window.document !== 'undefined' &&
833
- // @ts-ignore
834
- typeof navigator !== 'undefined'
835
- );
780
+ // @ts-ignore
781
+ typeof window.document !== 'undefined' &&
782
+ // @ts-ignore
783
+ typeof navigator !== 'undefined');
836
784
  };
837
785
  exports.isRunningInBrowser = isRunningInBrowser;
838
786
  const isHeadersProtocol = (headers) => {
839
- return typeof (headers === null || headers === void 0 ? void 0 : headers.get) === 'function';
787
+ return typeof (headers === null || headers === void 0 ? void 0 : headers.get) === 'function';
840
788
  };
841
789
  exports.isHeadersProtocol = isHeadersProtocol;
842
790
  const getHeader = (headers, key) => {
843
- const lowerKey = key.toLowerCase();
844
- if ((0, exports.isHeadersProtocol)(headers)) return headers.get(key) || headers.get(lowerKey);
845
- const value = headers[key] || headers[lowerKey];
846
- if (Array.isArray(value)) {
847
- if (value.length <= 1) return value[0];
848
- console.warn(`Received ${value.length} entries for the ${key} header, using the first entry.`);
849
- return value[0];
850
- }
851
- return value;
791
+ const lowerKey = key.toLowerCase();
792
+ if ((0, exports.isHeadersProtocol)(headers))
793
+ return headers.get(key) || headers.get(lowerKey);
794
+ const value = headers[key] || headers[lowerKey];
795
+ if (Array.isArray(value)) {
796
+ if (value.length <= 1)
797
+ return value[0];
798
+ console.warn(`Received ${value.length} entries for the ${key} header, using the first entry.`);
799
+ return value[0];
800
+ }
801
+ return value;
852
802
  };
853
803
  exports.getHeader = getHeader;
854
804
  /**
855
805
  * Encodes a string to Base64 format.
856
806
  */
857
807
  const toBase64 = (str) => {
858
- if (!str) return '';
859
- if (typeof Buffer !== 'undefined') {
860
- return Buffer.from(str).toString('base64');
861
- }
862
- if (typeof btoa !== 'undefined') {
863
- return btoa(str);
864
- }
865
- throw new Error('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
808
+ if (!str)
809
+ return '';
810
+ if (typeof Buffer !== 'undefined') {
811
+ return Buffer.from(str).toString('base64');
812
+ }
813
+ if (typeof btoa !== 'undefined') {
814
+ return btoa(str);
815
+ }
816
+ throw new error_1.IncreaseError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
866
817
  };
867
818
  exports.toBase64 = toBase64;
868
- //# sourceMappingURL=core.js.map
819
+ //# sourceMappingURL=core.js.map