spitch 1.16.1 → 1.19.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 (430) hide show
  1. package/CHANGELOG.md +35 -4
  2. package/README.md +116 -54
  3. package/api-promise.d.mts +2 -0
  4. package/api-promise.d.mts.map +1 -0
  5. package/api-promise.d.ts +2 -0
  6. package/api-promise.d.ts.map +1 -0
  7. package/api-promise.js +6 -0
  8. package/api-promise.js.map +1 -0
  9. package/api-promise.mjs +2 -0
  10. package/api-promise.mjs.map +1 -0
  11. package/client.d.mts +183 -0
  12. package/client.d.mts.map +1 -0
  13. package/client.d.ts +183 -0
  14. package/client.d.ts.map +1 -0
  15. package/client.js +464 -0
  16. package/client.js.map +1 -0
  17. package/client.mjs +460 -0
  18. package/client.mjs.map +1 -0
  19. package/core/api-promise.d.mts +46 -0
  20. package/core/api-promise.d.mts.map +1 -0
  21. package/core/api-promise.d.ts +46 -0
  22. package/core/api-promise.d.ts.map +1 -0
  23. package/core/api-promise.js +74 -0
  24. package/core/api-promise.js.map +1 -0
  25. package/core/api-promise.mjs +70 -0
  26. package/core/api-promise.mjs.map +1 -0
  27. package/core/error.d.mts +46 -0
  28. package/core/error.d.mts.map +1 -0
  29. package/core/error.d.ts +46 -0
  30. package/core/error.d.ts.map +1 -0
  31. package/core/error.js +113 -0
  32. package/core/error.js.map +1 -0
  33. package/core/error.mjs +97 -0
  34. package/core/error.mjs.map +1 -0
  35. package/core/resource.d.mts +6 -0
  36. package/core/resource.d.mts.map +1 -0
  37. package/core/resource.d.ts +6 -0
  38. package/core/resource.d.ts.map +1 -0
  39. package/core/resource.js +11 -0
  40. package/core/resource.js.map +1 -0
  41. package/core/resource.mjs +7 -0
  42. package/core/resource.mjs.map +1 -0
  43. package/core/uploads.d.mts +3 -0
  44. package/core/uploads.d.mts.map +1 -0
  45. package/core/uploads.d.ts +3 -0
  46. package/core/uploads.d.ts.map +1 -0
  47. package/core/uploads.js +6 -0
  48. package/core/uploads.js.map +1 -0
  49. package/core/uploads.mjs +2 -0
  50. package/core/uploads.mjs.map +1 -0
  51. package/error.d.mts +2 -0
  52. package/error.d.mts.map +1 -0
  53. package/error.d.ts +1 -46
  54. package/error.d.ts.map +1 -1
  55. package/error.js +3 -110
  56. package/error.js.map +1 -1
  57. package/error.mjs +1 -96
  58. package/error.mjs.map +1 -1
  59. package/index.d.mts +6 -114
  60. package/index.d.mts.map +1 -0
  61. package/index.d.ts +5 -113
  62. package/index.d.ts.map +1 -1
  63. package/index.js +12 -111
  64. package/index.js.map +1 -1
  65. package/index.mjs +5 -84
  66. package/index.mjs.map +1 -1
  67. package/internal/builtin-types.d.mts +73 -0
  68. package/internal/builtin-types.d.mts.map +1 -0
  69. package/internal/builtin-types.d.ts +73 -0
  70. package/internal/builtin-types.d.ts.map +1 -0
  71. package/internal/builtin-types.js +4 -0
  72. package/internal/builtin-types.js.map +1 -0
  73. package/internal/builtin-types.mjs +3 -0
  74. package/internal/builtin-types.mjs.map +1 -0
  75. package/internal/detect-platform.d.mts +15 -0
  76. package/internal/detect-platform.d.mts.map +1 -0
  77. package/internal/detect-platform.d.ts +15 -0
  78. package/internal/detect-platform.d.ts.map +1 -0
  79. package/internal/detect-platform.js +162 -0
  80. package/internal/detect-platform.js.map +1 -0
  81. package/internal/detect-platform.mjs +157 -0
  82. package/internal/detect-platform.mjs.map +1 -0
  83. package/internal/errors.d.mts +3 -0
  84. package/internal/errors.d.mts.map +1 -0
  85. package/internal/errors.d.ts +3 -0
  86. package/internal/errors.d.ts.map +1 -0
  87. package/internal/errors.js +41 -0
  88. package/internal/errors.js.map +1 -0
  89. package/internal/errors.mjs +36 -0
  90. package/internal/errors.mjs.map +1 -0
  91. package/internal/headers.d.mts +20 -0
  92. package/internal/headers.d.mts.map +1 -0
  93. package/internal/headers.d.ts +20 -0
  94. package/internal/headers.d.ts.map +1 -0
  95. package/internal/headers.js +79 -0
  96. package/internal/headers.js.map +1 -0
  97. package/internal/headers.mjs +74 -0
  98. package/internal/headers.mjs.map +1 -0
  99. package/internal/parse.d.mts +12 -0
  100. package/internal/parse.d.mts.map +1 -0
  101. package/internal/parse.d.ts +12 -0
  102. package/internal/parse.d.ts.map +1 -0
  103. package/internal/parse.js +35 -0
  104. package/internal/parse.js.map +1 -0
  105. package/internal/parse.mjs +32 -0
  106. package/internal/parse.mjs.map +1 -0
  107. package/internal/request-options.d.mts +75 -0
  108. package/internal/request-options.d.mts.map +1 -0
  109. package/internal/request-options.d.ts +75 -0
  110. package/internal/request-options.d.ts.map +1 -0
  111. package/internal/request-options.js +14 -0
  112. package/internal/request-options.js.map +1 -0
  113. package/internal/request-options.mjs +10 -0
  114. package/internal/request-options.mjs.map +1 -0
  115. package/internal/shim-types.d.mts +17 -0
  116. package/internal/shim-types.d.mts.map +1 -0
  117. package/internal/shim-types.d.ts +17 -0
  118. package/internal/shim-types.d.ts.map +1 -0
  119. package/internal/shim-types.js +4 -0
  120. package/internal/shim-types.js.map +1 -0
  121. package/internal/shim-types.mjs +3 -0
  122. package/internal/shim-types.mjs.map +1 -0
  123. package/internal/shims.d.mts +20 -0
  124. package/internal/shims.d.mts.map +1 -0
  125. package/internal/shims.d.ts +20 -0
  126. package/internal/shims.d.ts.map +1 -0
  127. package/internal/shims.js +92 -0
  128. package/internal/shims.js.map +1 -0
  129. package/internal/shims.mjs +85 -0
  130. package/internal/shims.mjs.map +1 -0
  131. package/internal/to-file.d.mts +45 -0
  132. package/internal/to-file.d.mts.map +1 -0
  133. package/internal/to-file.d.ts +45 -0
  134. package/internal/to-file.d.ts.map +1 -0
  135. package/internal/to-file.js +91 -0
  136. package/internal/to-file.js.map +1 -0
  137. package/internal/to-file.mjs +88 -0
  138. package/internal/to-file.mjs.map +1 -0
  139. package/internal/tslib.js +81 -0
  140. package/internal/tslib.mjs +17 -0
  141. package/internal/types.d.mts +69 -0
  142. package/internal/types.d.mts.map +1 -0
  143. package/internal/types.d.ts +69 -0
  144. package/internal/types.d.ts.map +1 -0
  145. package/internal/types.js +4 -0
  146. package/internal/types.js.map +1 -0
  147. package/internal/types.mjs +3 -0
  148. package/internal/types.mjs.map +1 -0
  149. package/internal/uploads.d.mts +42 -0
  150. package/internal/uploads.d.mts.map +1 -0
  151. package/internal/uploads.d.ts +42 -0
  152. package/internal/uploads.d.ts.map +1 -0
  153. package/internal/uploads.js +141 -0
  154. package/internal/uploads.js.map +1 -0
  155. package/internal/uploads.mjs +131 -0
  156. package/internal/uploads.mjs.map +1 -0
  157. package/internal/utils/base64.d.mts +3 -0
  158. package/internal/utils/base64.d.mts.map +1 -0
  159. package/internal/utils/base64.d.ts +3 -0
  160. package/internal/utils/base64.d.ts.map +1 -0
  161. package/internal/utils/base64.js +38 -0
  162. package/internal/utils/base64.js.map +1 -0
  163. package/internal/utils/base64.mjs +33 -0
  164. package/internal/utils/base64.mjs.map +1 -0
  165. package/internal/utils/bytes.d.mts +4 -0
  166. package/internal/utils/bytes.d.mts.map +1 -0
  167. package/internal/utils/bytes.d.ts +4 -0
  168. package/internal/utils/bytes.d.ts.map +1 -0
  169. package/internal/utils/bytes.js +31 -0
  170. package/internal/utils/bytes.js.map +1 -0
  171. package/internal/utils/bytes.mjs +26 -0
  172. package/internal/utils/bytes.mjs.map +1 -0
  173. package/internal/utils/env.d.mts +9 -0
  174. package/internal/utils/env.d.mts.map +1 -0
  175. package/internal/utils/env.d.ts +9 -0
  176. package/internal/utils/env.d.ts.map +1 -0
  177. package/internal/utils/env.js +22 -0
  178. package/internal/utils/env.js.map +1 -0
  179. package/internal/utils/env.mjs +18 -0
  180. package/internal/utils/env.mjs.map +1 -0
  181. package/internal/utils/log.d.mts +37 -0
  182. package/internal/utils/log.d.mts.map +1 -0
  183. package/internal/utils/log.d.ts +37 -0
  184. package/internal/utils/log.d.ts.map +1 -0
  185. package/internal/utils/log.js +85 -0
  186. package/internal/utils/log.js.map +1 -0
  187. package/internal/utils/log.mjs +79 -0
  188. package/internal/utils/log.mjs.map +1 -0
  189. package/internal/utils/path.d.mts +15 -0
  190. package/internal/utils/path.d.mts.map +1 -0
  191. package/internal/utils/path.d.ts +15 -0
  192. package/internal/utils/path.d.ts.map +1 -0
  193. package/internal/utils/path.js +79 -0
  194. package/internal/utils/path.js.map +1 -0
  195. package/internal/utils/path.mjs +74 -0
  196. package/internal/utils/path.mjs.map +1 -0
  197. package/internal/utils/sleep.d.mts +2 -0
  198. package/internal/utils/sleep.d.mts.map +1 -0
  199. package/internal/utils/sleep.d.ts +2 -0
  200. package/internal/utils/sleep.d.ts.map +1 -0
  201. package/internal/utils/sleep.js +7 -0
  202. package/internal/utils/sleep.js.map +1 -0
  203. package/internal/utils/sleep.mjs +3 -0
  204. package/internal/utils/sleep.mjs.map +1 -0
  205. package/internal/utils/uuid.d.mts +5 -0
  206. package/internal/utils/uuid.d.mts.map +1 -0
  207. package/internal/utils/uuid.d.ts +5 -0
  208. package/internal/utils/uuid.d.ts.map +1 -0
  209. package/internal/utils/uuid.js +19 -0
  210. package/internal/utils/uuid.js.map +1 -0
  211. package/internal/utils/uuid.mjs +15 -0
  212. package/internal/utils/uuid.mjs.map +1 -0
  213. package/internal/utils/values.d.mts +18 -0
  214. package/internal/utils/values.d.mts.map +1 -0
  215. package/internal/utils/values.d.ts +18 -0
  216. package/internal/utils/values.d.ts.map +1 -0
  217. package/internal/utils/values.js +112 -0
  218. package/internal/utils/values.js.map +1 -0
  219. package/internal/utils/values.mjs +94 -0
  220. package/internal/utils/values.mjs.map +1 -0
  221. package/internal/utils.d.mts +7 -0
  222. package/internal/utils.d.mts.map +1 -0
  223. package/internal/utils.d.ts +7 -0
  224. package/internal/utils.d.ts.map +1 -0
  225. package/internal/utils.js +11 -0
  226. package/internal/utils.js.map +1 -0
  227. package/internal/utils.mjs +8 -0
  228. package/internal/utils.mjs.map +1 -0
  229. package/package.json +102 -70
  230. package/resource.d.mts +2 -0
  231. package/resource.d.mts.map +1 -0
  232. package/resource.d.ts +1 -5
  233. package/resource.d.ts.map +1 -1
  234. package/resource.js +3 -8
  235. package/resource.js.map +1 -1
  236. package/resource.mjs +1 -6
  237. package/resource.mjs.map +1 -1
  238. package/resources/index.d.mts +3 -0
  239. package/resources/index.d.mts.map +1 -0
  240. package/resources/index.d.ts +1 -1
  241. package/resources/index.d.ts.map +1 -1
  242. package/resources/index.js.map +1 -1
  243. package/resources/index.mjs.map +1 -1
  244. package/resources/speech.d.mts +45 -0
  245. package/resources/speech.d.mts.map +1 -0
  246. package/resources/speech.d.ts +20 -30
  247. package/resources/speech.d.ts.map +1 -1
  248. package/resources/speech.js +5 -35
  249. package/resources/speech.js.map +1 -1
  250. package/resources/speech.mjs +5 -12
  251. package/resources/speech.mjs.map +1 -1
  252. package/resources/text.d.mts +34 -0
  253. package/resources/text.d.mts.map +1 -0
  254. package/resources/text.d.ts +7 -6
  255. package/resources/text.d.ts.map +1 -1
  256. package/resources/text.js +1 -1
  257. package/resources/text.js.map +1 -1
  258. package/resources/text.mjs +1 -1
  259. package/resources/text.mjs.map +1 -1
  260. package/resources.d.mts +2 -0
  261. package/resources.d.mts.map +1 -0
  262. package/resources.d.ts.map +1 -1
  263. package/resources.js +2 -15
  264. package/resources.js.map +1 -1
  265. package/src/api-promise.ts +2 -0
  266. package/src/client.ts +753 -0
  267. package/src/core/README.md +3 -0
  268. package/src/core/api-promise.ts +92 -0
  269. package/src/core/error.ts +130 -0
  270. package/src/core/resource.ts +11 -0
  271. package/src/core/uploads.ts +2 -0
  272. package/src/error.ts +2 -130
  273. package/src/index.ts +5 -203
  274. package/src/internal/README.md +3 -0
  275. package/src/internal/builtin-types.ts +93 -0
  276. package/src/internal/detect-platform.ts +196 -0
  277. package/src/internal/errors.ts +33 -0
  278. package/src/internal/headers.ts +97 -0
  279. package/src/internal/parse.ts +50 -0
  280. package/src/internal/request-options.ts +91 -0
  281. package/src/internal/shim-types.ts +26 -0
  282. package/src/internal/shims.ts +107 -0
  283. package/src/internal/to-file.ts +154 -0
  284. package/src/internal/types.ts +95 -0
  285. package/src/internal/uploads.ts +187 -0
  286. package/src/internal/utils/base64.ts +40 -0
  287. package/src/internal/utils/bytes.ts +32 -0
  288. package/src/internal/utils/env.ts +18 -0
  289. package/src/internal/utils/log.ts +126 -0
  290. package/src/internal/utils/path.ts +88 -0
  291. package/src/internal/utils/sleep.ts +3 -0
  292. package/src/internal/utils/uuid.ts +17 -0
  293. package/src/internal/utils/values.ts +105 -0
  294. package/src/internal/utils.ts +8 -0
  295. package/src/resource.ts +2 -11
  296. package/src/resources/index.ts +1 -0
  297. package/src/resources/speech.ts +33 -47
  298. package/src/resources/text.ts +7 -9
  299. package/src/tsconfig.json +2 -2
  300. package/src/uploads.ts +2 -255
  301. package/src/version.ts +1 -1
  302. package/uploads.d.mts +2 -0
  303. package/uploads.d.mts.map +1 -0
  304. package/uploads.d.ts +1 -74
  305. package/uploads.d.ts.map +1 -1
  306. package/uploads.js +3 -168
  307. package/uploads.js.map +1 -1
  308. package/uploads.mjs +1 -157
  309. package/uploads.mjs.map +1 -1
  310. package/version.d.mts +2 -0
  311. package/version.d.mts.map +1 -0
  312. package/version.d.ts +1 -1
  313. package/version.js +1 -1
  314. package/version.mjs +1 -1
  315. package/_shims/MultipartBody.d.ts +0 -9
  316. package/_shims/MultipartBody.d.ts.map +0 -1
  317. package/_shims/MultipartBody.js +0 -16
  318. package/_shims/MultipartBody.js.map +0 -1
  319. package/_shims/MultipartBody.mjs +0 -12
  320. package/_shims/MultipartBody.mjs.map +0 -1
  321. package/_shims/README.md +0 -46
  322. package/_shims/auto/runtime-bun.d.ts +0 -5
  323. package/_shims/auto/runtime-bun.d.ts.map +0 -1
  324. package/_shims/auto/runtime-bun.js +0 -21
  325. package/_shims/auto/runtime-bun.js.map +0 -1
  326. package/_shims/auto/runtime-bun.mjs +0 -2
  327. package/_shims/auto/runtime-bun.mjs.map +0 -1
  328. package/_shims/auto/runtime-node.d.ts +0 -5
  329. package/_shims/auto/runtime-node.d.ts.map +0 -1
  330. package/_shims/auto/runtime-node.js +0 -21
  331. package/_shims/auto/runtime-node.js.map +0 -1
  332. package/_shims/auto/runtime-node.mjs +0 -2
  333. package/_shims/auto/runtime-node.mjs.map +0 -1
  334. package/_shims/auto/runtime.d.ts +0 -5
  335. package/_shims/auto/runtime.d.ts.map +0 -1
  336. package/_shims/auto/runtime.js +0 -21
  337. package/_shims/auto/runtime.js.map +0 -1
  338. package/_shims/auto/runtime.mjs +0 -2
  339. package/_shims/auto/runtime.mjs.map +0 -1
  340. package/_shims/auto/types-node.d.ts +0 -5
  341. package/_shims/auto/types-node.d.ts.map +0 -1
  342. package/_shims/auto/types-node.js +0 -21
  343. package/_shims/auto/types-node.js.map +0 -1
  344. package/_shims/auto/types-node.mjs +0 -2
  345. package/_shims/auto/types-node.mjs.map +0 -1
  346. package/_shims/auto/types.d.ts +0 -101
  347. package/_shims/auto/types.js +0 -3
  348. package/_shims/auto/types.mjs +0 -3
  349. package/_shims/bun-runtime.d.ts +0 -6
  350. package/_shims/bun-runtime.d.ts.map +0 -1
  351. package/_shims/bun-runtime.js +0 -14
  352. package/_shims/bun-runtime.js.map +0 -1
  353. package/_shims/bun-runtime.mjs +0 -10
  354. package/_shims/bun-runtime.mjs.map +0 -1
  355. package/_shims/index.d.ts +0 -83
  356. package/_shims/index.js +0 -17
  357. package/_shims/index.mjs +0 -11
  358. package/_shims/manual-types.d.ts +0 -12
  359. package/_shims/manual-types.js +0 -3
  360. package/_shims/manual-types.mjs +0 -3
  361. package/_shims/node-runtime.d.ts +0 -3
  362. package/_shims/node-runtime.d.ts.map +0 -1
  363. package/_shims/node-runtime.js +0 -89
  364. package/_shims/node-runtime.js.map +0 -1
  365. package/_shims/node-runtime.mjs +0 -56
  366. package/_shims/node-runtime.mjs.map +0 -1
  367. package/_shims/node-types.d.ts +0 -42
  368. package/_shims/node-types.js +0 -3
  369. package/_shims/node-types.mjs +0 -3
  370. package/_shims/registry.d.ts +0 -37
  371. package/_shims/registry.d.ts.map +0 -1
  372. package/_shims/registry.js +0 -41
  373. package/_shims/registry.js.map +0 -1
  374. package/_shims/registry.mjs +0 -37
  375. package/_shims/registry.mjs.map +0 -1
  376. package/_shims/web-runtime.d.ts +0 -5
  377. package/_shims/web-runtime.d.ts.map +0 -1
  378. package/_shims/web-runtime.js +0 -78
  379. package/_shims/web-runtime.js.map +0 -1
  380. package/_shims/web-runtime.mjs +0 -71
  381. package/_shims/web-runtime.mjs.map +0 -1
  382. package/_shims/web-types.d.ts +0 -83
  383. package/_shims/web-types.js +0 -3
  384. package/_shims/web-types.mjs +0 -3
  385. package/core.d.ts +0 -255
  386. package/core.d.ts.map +0 -1
  387. package/core.js +0 -922
  388. package/core.js.map +0 -1
  389. package/core.mjs +0 -890
  390. package/core.mjs.map +0 -1
  391. package/shims/node.d.ts +0 -30
  392. package/shims/node.d.ts.map +0 -1
  393. package/shims/node.js +0 -31
  394. package/shims/node.js.map +0 -1
  395. package/shims/node.mjs +0 -5
  396. package/shims/node.mjs.map +0 -1
  397. package/shims/web.d.ts +0 -26
  398. package/shims/web.d.ts.map +0 -1
  399. package/shims/web.js +0 -31
  400. package/shims/web.js.map +0 -1
  401. package/shims/web.mjs +0 -5
  402. package/shims/web.mjs.map +0 -1
  403. package/src/_shims/MultipartBody.ts +0 -9
  404. package/src/_shims/README.md +0 -46
  405. package/src/_shims/auto/runtime-bun.ts +0 -4
  406. package/src/_shims/auto/runtime-node.ts +0 -4
  407. package/src/_shims/auto/runtime.ts +0 -4
  408. package/src/_shims/auto/types-node.ts +0 -4
  409. package/src/_shims/auto/types.d.ts +0 -101
  410. package/src/_shims/auto/types.js +0 -3
  411. package/src/_shims/auto/types.mjs +0 -3
  412. package/src/_shims/bun-runtime.ts +0 -14
  413. package/src/_shims/index.d.ts +0 -83
  414. package/src/_shims/index.js +0 -17
  415. package/src/_shims/index.mjs +0 -11
  416. package/src/_shims/manual-types.d.ts +0 -12
  417. package/src/_shims/manual-types.js +0 -3
  418. package/src/_shims/manual-types.mjs +0 -3
  419. package/src/_shims/node-runtime.ts +0 -81
  420. package/src/_shims/node-types.d.ts +0 -42
  421. package/src/_shims/node-types.js +0 -3
  422. package/src/_shims/node-types.mjs +0 -3
  423. package/src/_shims/registry.ts +0 -65
  424. package/src/_shims/web-runtime.ts +0 -103
  425. package/src/_shims/web-types.d.ts +0 -83
  426. package/src/_shims/web-types.js +0 -3
  427. package/src/_shims/web-types.mjs +0 -3
  428. package/src/core.ts +0 -1234
  429. package/src/shims/node.ts +0 -50
  430. package/src/shims/web.ts +0 -50
@@ -0,0 +1,3 @@
1
+ # `core`
2
+
3
+ This directory holds public modules implementing non-resource-specific SDK functionality.
@@ -0,0 +1,92 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { type Spitch } from '../client';
4
+
5
+ import { type PromiseOrValue } from '../internal/types';
6
+ import { APIResponseProps, defaultParseResponse } from '../internal/parse';
7
+
8
+ /**
9
+ * A subclass of `Promise` providing additional helper methods
10
+ * for interacting with the SDK.
11
+ */
12
+ export class APIPromise<T> extends Promise<T> {
13
+ private parsedPromise: Promise<T> | undefined;
14
+ #client: Spitch;
15
+
16
+ constructor(
17
+ client: Spitch,
18
+ private responsePromise: Promise<APIResponseProps>,
19
+ private parseResponse: (
20
+ client: Spitch,
21
+ props: APIResponseProps,
22
+ ) => PromiseOrValue<T> = defaultParseResponse,
23
+ ) {
24
+ super((resolve) => {
25
+ // this is maybe a bit weird but this has to be a no-op to not implicitly
26
+ // parse the response body; instead .then, .catch, .finally are overridden
27
+ // to parse the response
28
+ resolve(null as any);
29
+ });
30
+ this.#client = client;
31
+ }
32
+
33
+ _thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {
34
+ return new APIPromise(this.#client, this.responsePromise, async (client, props) =>
35
+ transform(await this.parseResponse(client, props), props),
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Gets the raw `Response` instance instead of parsing the response
41
+ * data.
42
+ *
43
+ * If you want to parse the response body but still get the `Response`
44
+ * instance, you can use {@link withResponse()}.
45
+ *
46
+ * 👋 Getting the wrong TypeScript type for `Response`?
47
+ * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
48
+ * to your `tsconfig.json`.
49
+ */
50
+ asResponse(): Promise<Response> {
51
+ return this.responsePromise.then((p) => p.response);
52
+ }
53
+
54
+ /**
55
+ * Gets the parsed response data and the raw `Response` instance.
56
+ *
57
+ * If you just want to get the raw `Response` instance without parsing it,
58
+ * you can use {@link asResponse()}.
59
+ *
60
+ * 👋 Getting the wrong TypeScript type for `Response`?
61
+ * Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
62
+ * to your `tsconfig.json`.
63
+ */
64
+ async withResponse(): Promise<{ data: T; response: Response }> {
65
+ const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
66
+ return { data, response };
67
+ }
68
+
69
+ private parse(): Promise<T> {
70
+ if (!this.parsedPromise) {
71
+ this.parsedPromise = this.responsePromise.then((data) => this.parseResponse(this.#client, data));
72
+ }
73
+ return this.parsedPromise;
74
+ }
75
+
76
+ override then<TResult1 = T, TResult2 = never>(
77
+ onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
78
+ onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null,
79
+ ): Promise<TResult1 | TResult2> {
80
+ return this.parse().then(onfulfilled, onrejected);
81
+ }
82
+
83
+ override catch<TResult = never>(
84
+ onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null,
85
+ ): Promise<T | TResult> {
86
+ return this.parse().catch(onrejected);
87
+ }
88
+
89
+ override finally(onfinally?: (() => void) | undefined | null): Promise<T> {
90
+ return this.parse().finally(onfinally);
91
+ }
92
+ }
@@ -0,0 +1,130 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { castToError } from '../internal/errors';
4
+
5
+ export class SpitchError extends Error {}
6
+
7
+ export class APIError<
8
+ TStatus extends number | undefined = number | undefined,
9
+ THeaders extends Headers | undefined = Headers | undefined,
10
+ TError extends Object | undefined = Object | undefined,
11
+ > extends SpitchError {
12
+ /** HTTP status for the response that caused the error */
13
+ readonly status: TStatus;
14
+ /** HTTP headers for the response that caused the error */
15
+ readonly headers: THeaders;
16
+ /** JSON body of the response that caused the error */
17
+ readonly error: TError;
18
+
19
+ constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
20
+ super(`${APIError.makeMessage(status, error, message)}`);
21
+ this.status = status;
22
+ this.headers = headers;
23
+ this.error = error;
24
+ }
25
+
26
+ private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
27
+ const msg =
28
+ error?.message ?
29
+ typeof error.message === 'string' ?
30
+ error.message
31
+ : JSON.stringify(error.message)
32
+ : error ? JSON.stringify(error)
33
+ : message;
34
+
35
+ if (status && msg) {
36
+ return `${status} ${msg}`;
37
+ }
38
+ if (status) {
39
+ return `${status} status code (no body)`;
40
+ }
41
+ if (msg) {
42
+ return msg;
43
+ }
44
+ return '(no status code or body)';
45
+ }
46
+
47
+ static generate(
48
+ status: number | undefined,
49
+ errorResponse: Object | undefined,
50
+ message: string | undefined,
51
+ headers: Headers | undefined,
52
+ ): APIError {
53
+ if (!status || !headers) {
54
+ return new APIConnectionError({ message, cause: castToError(errorResponse) });
55
+ }
56
+
57
+ const error = errorResponse as Record<string, any>;
58
+
59
+ if (status === 400) {
60
+ return new BadRequestError(status, error, message, headers);
61
+ }
62
+
63
+ if (status === 401) {
64
+ return new AuthenticationError(status, error, message, headers);
65
+ }
66
+
67
+ if (status === 403) {
68
+ return new PermissionDeniedError(status, error, message, headers);
69
+ }
70
+
71
+ if (status === 404) {
72
+ return new NotFoundError(status, error, message, headers);
73
+ }
74
+
75
+ if (status === 409) {
76
+ return new ConflictError(status, error, message, headers);
77
+ }
78
+
79
+ if (status === 422) {
80
+ return new UnprocessableEntityError(status, error, message, headers);
81
+ }
82
+
83
+ if (status === 429) {
84
+ return new RateLimitError(status, error, message, headers);
85
+ }
86
+
87
+ if (status >= 500) {
88
+ return new InternalServerError(status, error, message, headers);
89
+ }
90
+
91
+ return new APIError(status, error, message, headers);
92
+ }
93
+ }
94
+
95
+ export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
96
+ constructor({ message }: { message?: string } = {}) {
97
+ super(undefined, undefined, message || 'Request was aborted.', undefined);
98
+ }
99
+ }
100
+
101
+ export class APIConnectionError extends APIError<undefined, undefined, undefined> {
102
+ constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
103
+ super(undefined, undefined, message || 'Connection error.', undefined);
104
+ // in some environments the 'cause' property is already declared
105
+ // @ts-ignore
106
+ if (cause) this.cause = cause;
107
+ }
108
+ }
109
+
110
+ export class APIConnectionTimeoutError extends APIConnectionError {
111
+ constructor({ message }: { message?: string } = {}) {
112
+ super({ message: message ?? 'Request timed out.' });
113
+ }
114
+ }
115
+
116
+ export class BadRequestError extends APIError<400, Headers> {}
117
+
118
+ export class AuthenticationError extends APIError<401, Headers> {}
119
+
120
+ export class PermissionDeniedError extends APIError<403, Headers> {}
121
+
122
+ export class NotFoundError extends APIError<404, Headers> {}
123
+
124
+ export class ConflictError extends APIError<409, Headers> {}
125
+
126
+ export class UnprocessableEntityError extends APIError<422, Headers> {}
127
+
128
+ export class RateLimitError extends APIError<429, Headers> {}
129
+
130
+ export class InternalServerError extends APIError<number, Headers> {}
@@ -0,0 +1,11 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import type { Spitch } from '../client';
4
+
5
+ export abstract class APIResource {
6
+ protected _client: Spitch;
7
+
8
+ constructor(client: Spitch) {
9
+ this._client = client;
10
+ }
11
+ }
@@ -0,0 +1,2 @@
1
+ export { type Uploadable } from '../internal/uploads';
2
+ export { toFile, type ToFileInput } from '../internal/to-file';
package/src/error.ts CHANGED
@@ -1,130 +1,2 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- import { castToError, Headers } from './core';
4
-
5
- export class SpitchError extends Error {}
6
-
7
- export class APIError<
8
- TStatus extends number | undefined = number | undefined,
9
- THeaders extends Headers | undefined = Headers | undefined,
10
- TError extends Object | undefined = Object | undefined,
11
- > extends SpitchError {
12
- /** HTTP status for the response that caused the error */
13
- readonly status: TStatus;
14
- /** HTTP headers for the response that caused the error */
15
- readonly headers: THeaders;
16
- /** JSON body of the response that caused the error */
17
- readonly error: TError;
18
-
19
- constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
20
- super(`${APIError.makeMessage(status, error, message)}`);
21
- this.status = status;
22
- this.headers = headers;
23
- this.error = error;
24
- }
25
-
26
- private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
27
- const msg =
28
- error?.message ?
29
- typeof error.message === 'string' ?
30
- error.message
31
- : JSON.stringify(error.message)
32
- : error ? JSON.stringify(error)
33
- : message;
34
-
35
- if (status && msg) {
36
- return `${status} ${msg}`;
37
- }
38
- if (status) {
39
- return `${status} status code (no body)`;
40
- }
41
- if (msg) {
42
- return msg;
43
- }
44
- return '(no status code or body)';
45
- }
46
-
47
- static generate(
48
- status: number | undefined,
49
- errorResponse: Object | undefined,
50
- message: string | undefined,
51
- headers: Headers | undefined,
52
- ): APIError {
53
- if (!status || !headers) {
54
- return new APIConnectionError({ message, cause: castToError(errorResponse) });
55
- }
56
-
57
- const error = errorResponse as Record<string, any>;
58
-
59
- if (status === 400) {
60
- return new BadRequestError(status, error, message, headers);
61
- }
62
-
63
- if (status === 401) {
64
- return new AuthenticationError(status, error, message, headers);
65
- }
66
-
67
- if (status === 403) {
68
- return new PermissionDeniedError(status, error, message, headers);
69
- }
70
-
71
- if (status === 404) {
72
- return new NotFoundError(status, error, message, headers);
73
- }
74
-
75
- if (status === 409) {
76
- return new ConflictError(status, error, message, headers);
77
- }
78
-
79
- if (status === 422) {
80
- return new UnprocessableEntityError(status, error, message, headers);
81
- }
82
-
83
- if (status === 429) {
84
- return new RateLimitError(status, error, message, headers);
85
- }
86
-
87
- if (status >= 500) {
88
- return new InternalServerError(status, error, message, headers);
89
- }
90
-
91
- return new APIError(status, error, message, headers);
92
- }
93
- }
94
-
95
- export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
96
- constructor({ message }: { message?: string } = {}) {
97
- super(undefined, undefined, message || 'Request was aborted.', undefined);
98
- }
99
- }
100
-
101
- export class APIConnectionError extends APIError<undefined, undefined, undefined> {
102
- constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
103
- super(undefined, undefined, message || 'Connection error.', undefined);
104
- // in some environments the 'cause' property is already declared
105
- // @ts-ignore
106
- if (cause) this.cause = cause;
107
- }
108
- }
109
-
110
- export class APIConnectionTimeoutError extends APIConnectionError {
111
- constructor({ message }: { message?: string } = {}) {
112
- super({ message: message ?? 'Request timed out.' });
113
- }
114
- }
115
-
116
- export class BadRequestError extends APIError<400, Headers> {}
117
-
118
- export class AuthenticationError extends APIError<401, Headers> {}
119
-
120
- export class PermissionDeniedError extends APIError<403, Headers> {}
121
-
122
- export class NotFoundError extends APIError<404, Headers> {}
123
-
124
- export class ConflictError extends APIError<409, Headers> {}
125
-
126
- export class UnprocessableEntityError extends APIError<422, Headers> {}
127
-
128
- export class RateLimitError extends APIError<429, Headers> {}
129
-
130
- export class InternalServerError extends APIError<number, Headers> {}
1
+ /** @deprecated Import from ./core/error instead */
2
+ export * from './core/error';
package/src/index.ts CHANGED
@@ -1,206 +1,10 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { type Agent } from './_shims/index';
4
- import * as Core from './core';
5
- import * as Errors from './error';
6
- import * as Uploads from './uploads';
7
- import * as API from './resources/index';
8
- import {
9
- Speech,
10
- SpeechGenerateParams,
11
- SpeechTranscribeParams,
12
- SpeechTranscribeResponse,
13
- } from './resources/speech';
14
- import {
15
- Text,
16
- TextToneMarkParams,
17
- TextToneMarkResponse,
18
- TextTranslateParams,
19
- TextTranslateResponse,
20
- } from './resources/text';
3
+ export { Spitch as default } from './client';
21
4
 
22
- export interface ClientOptions {
23
- /**
24
- * Defaults to process.env['SPITCH_API_KEY'].
25
- */
26
- apiKey?: string | undefined;
27
-
28
- /**
29
- * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
30
- *
31
- * Defaults to process.env['SPITCH_BASE_URL'].
32
- */
33
- baseURL?: string | null | undefined;
34
-
35
- /**
36
- * The maximum amount of time (in milliseconds) that the client should wait for a response
37
- * from the server before timing out a single request.
38
- *
39
- * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
40
- * much longer than this timeout before the promise succeeds or fails.
41
- */
42
- timeout?: number | undefined;
43
-
44
- /**
45
- * An HTTP agent used to manage HTTP(S) connections.
46
- *
47
- * If not provided, an agent will be constructed by default in the Node.js environment,
48
- * otherwise no agent is used.
49
- */
50
- httpAgent?: Agent | undefined;
51
-
52
- /**
53
- * Specify a custom `fetch` function implementation.
54
- *
55
- * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
56
- * defined globally.
57
- */
58
- fetch?: Core.Fetch | undefined;
59
-
60
- /**
61
- * The maximum number of times that the client will retry a request in case of a
62
- * temporary failure, like a network error or a 5XX error from the server.
63
- *
64
- * @default 2
65
- */
66
- maxRetries?: number | undefined;
67
-
68
- /**
69
- * Default headers to include with every request to the API.
70
- *
71
- * These can be removed in individual requests by explicitly setting the
72
- * header to `undefined` or `null` in request options.
73
- */
74
- defaultHeaders?: Core.Headers | undefined;
75
-
76
- /**
77
- * Default query parameters to include with every request to the API.
78
- *
79
- * These can be removed in individual requests by explicitly setting the
80
- * param to `undefined` in request options.
81
- */
82
- defaultQuery?: Core.DefaultQuery | undefined;
83
- }
84
-
85
- /**
86
- * API Client for interfacing with the Spitch API.
87
- */
88
- export class Spitch extends Core.APIClient {
89
- apiKey: string;
90
-
91
- private _options: ClientOptions;
92
-
93
- /**
94
- * API Client for interfacing with the Spitch API.
95
- *
96
- * @param {string | undefined} [opts.apiKey=process.env['SPITCH_API_KEY'] ?? undefined]
97
- * @param {string} [opts.baseURL=process.env['SPITCH_BASE_URL'] ?? https://api.spi-tch.com] - Override the default base URL for the API.
98
- * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
99
- * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
100
- * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
101
- * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
102
- * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
103
- * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
104
- */
105
- constructor({
106
- baseURL = Core.readEnv('SPITCH_BASE_URL'),
107
- apiKey = Core.readEnv('SPITCH_API_KEY'),
108
- ...opts
109
- }: ClientOptions = {}) {
110
- if (apiKey === undefined) {
111
- throw new Errors.SpitchError(
112
- "The SPITCH_API_KEY environment variable is missing or empty; either provide it, or instantiate the Spitch client with an apiKey option, like new Spitch({ apiKey: 'My API Key' }).",
113
- );
114
- }
115
-
116
- const options: ClientOptions = {
117
- apiKey,
118
- ...opts,
119
- baseURL: baseURL || `https://api.spi-tch.com`,
120
- };
121
-
122
- super({
123
- baseURL: options.baseURL!,
124
- baseURLOverridden: baseURL ? baseURL !== 'https://api.spi-tch.com' : false,
125
- timeout: options.timeout ?? 60000 /* 1 minute */,
126
- httpAgent: options.httpAgent,
127
- maxRetries: options.maxRetries,
128
- fetch: options.fetch,
129
- });
130
-
131
- this._options = options;
132
-
133
- this.apiKey = apiKey;
134
- }
135
-
136
- speech: API.Speech = new API.Speech(this);
137
- text: API.Text = new API.Text(this);
138
-
139
- /**
140
- * Check whether the base URL is set to its default.
141
- */
142
- #baseURLOverridden(): boolean {
143
- return this.baseURL !== 'https://api.spi-tch.com';
144
- }
145
-
146
- protected override defaultQuery(): Core.DefaultQuery | undefined {
147
- return this._options.defaultQuery;
148
- }
149
-
150
- protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
151
- return {
152
- ...super.defaultHeaders(opts),
153
- ...this._options.defaultHeaders,
154
- };
155
- }
156
-
157
- protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
158
- return { Authorization: `Bearer ${this.apiKey}` };
159
- }
160
-
161
- static Spitch = this;
162
- static DEFAULT_TIMEOUT = 60000; // 1 minute
163
-
164
- static SpitchError = Errors.SpitchError;
165
- static APIError = Errors.APIError;
166
- static APIConnectionError = Errors.APIConnectionError;
167
- static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
168
- static APIUserAbortError = Errors.APIUserAbortError;
169
- static NotFoundError = Errors.NotFoundError;
170
- static ConflictError = Errors.ConflictError;
171
- static RateLimitError = Errors.RateLimitError;
172
- static BadRequestError = Errors.BadRequestError;
173
- static AuthenticationError = Errors.AuthenticationError;
174
- static InternalServerError = Errors.InternalServerError;
175
- static PermissionDeniedError = Errors.PermissionDeniedError;
176
- static UnprocessableEntityError = Errors.UnprocessableEntityError;
177
-
178
- static toFile = Uploads.toFile;
179
- static fileFromPath = Uploads.fileFromPath;
180
- }
181
-
182
- Spitch.Speech = Speech;
183
- Spitch.Text = Text;
184
- export declare namespace Spitch {
185
- export type RequestOptions = Core.RequestOptions;
186
-
187
- export {
188
- Speech as Speech,
189
- type SpeechTranscribeResponse as SpeechTranscribeResponse,
190
- type SpeechGenerateParams as SpeechGenerateParams,
191
- type SpeechTranscribeParams as SpeechTranscribeParams,
192
- };
193
-
194
- export {
195
- Text as Text,
196
- type TextToneMarkResponse as TextToneMarkResponse,
197
- type TextTranslateResponse as TextTranslateResponse,
198
- type TextToneMarkParams as TextToneMarkParams,
199
- type TextTranslateParams as TextTranslateParams,
200
- };
201
- }
202
-
203
- export { toFile, fileFromPath } from './uploads';
5
+ export { type Uploadable, toFile } from './core/uploads';
6
+ export { APIPromise } from './core/api-promise';
7
+ export { Spitch, type ClientOptions } from './client';
204
8
  export {
205
9
  SpitchError,
206
10
  APIError,
@@ -215,6 +19,4 @@ export {
215
19
  InternalServerError,
216
20
  PermissionDeniedError,
217
21
  UnprocessableEntityError,
218
- } from './error';
219
-
220
- export default Spitch;
22
+ } from './core/error';
@@ -0,0 +1,3 @@
1
+ # `internal`
2
+
3
+ The modules in this directory are not importable outside this package and will change between releases.
@@ -0,0 +1,93 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export type Fetch = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
4
+
5
+ /**
6
+ * An alias to the builtin `RequestInit` type so we can
7
+ * easily alias it in import statements if there are name clashes.
8
+ *
9
+ * https://developer.mozilla.org/docs/Web/API/RequestInit
10
+ */
11
+ type _RequestInit = RequestInit;
12
+
13
+ /**
14
+ * An alias to the builtin `Response` type so we can
15
+ * easily alias it in import statements if there are name clashes.
16
+ *
17
+ * https://developer.mozilla.org/docs/Web/API/Response
18
+ */
19
+ type _Response = Response;
20
+
21
+ /**
22
+ * The type for the first argument to `fetch`.
23
+ *
24
+ * https://developer.mozilla.org/docs/Web/API/Window/fetch#resource
25
+ */
26
+ type _RequestInfo = Request | URL | string;
27
+
28
+ /**
29
+ * The type for constructing `RequestInit` Headers.
30
+ *
31
+ * https://developer.mozilla.org/docs/Web/API/RequestInit#setting_headers
32
+ */
33
+ type _HeadersInit = RequestInit['headers'];
34
+
35
+ /**
36
+ * The type for constructing `RequestInit` body.
37
+ *
38
+ * https://developer.mozilla.org/docs/Web/API/RequestInit#body
39
+ */
40
+ type _BodyInit = RequestInit['body'];
41
+
42
+ /**
43
+ * An alias to the builtin `Array<T>` type so we can
44
+ * easily alias it in import statements if there are name clashes.
45
+ */
46
+ type _Array<T> = Array<T>;
47
+
48
+ /**
49
+ * An alias to the builtin `Record<K, T>` type so we can
50
+ * easily alias it in import statements if there are name clashes.
51
+ */
52
+ type _Record<K extends keyof any, T> = Record<K, T>;
53
+
54
+ export type {
55
+ _Array as Array,
56
+ _BodyInit as BodyInit,
57
+ _HeadersInit as HeadersInit,
58
+ _Record as Record,
59
+ _RequestInfo as RequestInfo,
60
+ _RequestInit as RequestInit,
61
+ _Response as Response,
62
+ };
63
+
64
+ /**
65
+ * A copy of the builtin `EndingType` type as it isn't fully supported in certain
66
+ * environments and attempting to reference the global version will error.
67
+ *
68
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L27941
69
+ */
70
+ type EndingType = 'native' | 'transparent';
71
+
72
+ /**
73
+ * A copy of the builtin `BlobPropertyBag` type as it isn't fully supported in certain
74
+ * environments and attempting to reference the global version will error.
75
+ *
76
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L154
77
+ * https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#options
78
+ */
79
+ export interface BlobPropertyBag {
80
+ endings?: EndingType;
81
+ type?: string;
82
+ }
83
+
84
+ /**
85
+ * A copy of the builtin `FilePropertyBag` type as it isn't fully supported in certain
86
+ * environments and attempting to reference the global version will error.
87
+ *
88
+ * https://github.com/microsoft/TypeScript/blob/49ad1a3917a0ea57f5ff248159256e12bb1cb705/src/lib/dom.generated.d.ts#L503
89
+ * https://developer.mozilla.org/en-US/docs/Web/API/File/File#options
90
+ */
91
+ export interface FilePropertyBag extends BlobPropertyBag {
92
+ lastModified?: number;
93
+ }