magic-hour 0.36.0 → 0.38.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 (327) hide show
  1. package/README.md +202 -10
  2. package/dist/client.d.ts +1 -1
  3. package/dist/client.js +3 -3
  4. package/dist/environment.d.ts +1 -1
  5. package/dist/environment.js +1 -1
  6. package/dist/helpers/download.d.ts +5 -0
  7. package/dist/helpers/download.js +88 -0
  8. package/dist/helpers/generate-type.d.ts +51 -0
  9. package/dist/helpers/generate-type.js +2 -0
  10. package/dist/helpers/sleep.d.ts +4 -0
  11. package/dist/helpers/sleep.js +9 -0
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +5 -5
  14. package/dist/logger.d.ts +48 -0
  15. package/dist/logger.js +97 -0
  16. package/dist/resources/v1/ai-clothes-changer/request-types.js +3 -3
  17. package/dist/resources/v1/ai-clothes-changer/resource-client.d.ts +51 -1
  18. package/dist/resources/v1/ai-clothes-changer/resource-client.js +77 -2
  19. package/dist/resources/v1/ai-face-editor/request-types.js +3 -3
  20. package/dist/resources/v1/ai-face-editor/resource-client.d.ts +56 -1
  21. package/dist/resources/v1/ai-face-editor/resource-client.js +87 -2
  22. package/dist/resources/v1/ai-gif-generator/request-types.js +3 -3
  23. package/dist/resources/v1/ai-gif-generator/resource-client.d.ts +30 -1
  24. package/dist/resources/v1/ai-gif-generator/resource-client.js +62 -2
  25. package/dist/resources/v1/ai-headshot-generator/request-types.js +3 -3
  26. package/dist/resources/v1/ai-headshot-generator/resource-client.d.ts +39 -1
  27. package/dist/resources/v1/ai-headshot-generator/resource-client.js +70 -2
  28. package/dist/resources/v1/ai-image-editor/request-types.js +3 -3
  29. package/dist/resources/v1/ai-image-editor/resource-client.d.ts +40 -1
  30. package/dist/resources/v1/ai-image-editor/resource-client.js +71 -2
  31. package/dist/resources/v1/ai-image-generator/request-types.js +3 -3
  32. package/dist/resources/v1/ai-image-generator/resource-client.d.ts +32 -1
  33. package/dist/resources/v1/ai-image-generator/resource-client.js +64 -2
  34. package/dist/resources/v1/ai-image-upscaler/request-types.js +3 -3
  35. package/dist/resources/v1/ai-image-upscaler/resource-client.d.ts +41 -1
  36. package/dist/resources/v1/ai-image-upscaler/resource-client.js +72 -2
  37. package/dist/resources/v1/ai-meme-generator/request-types.js +3 -3
  38. package/dist/resources/v1/ai-meme-generator/resource-client.d.ts +34 -1
  39. package/dist/resources/v1/ai-meme-generator/resource-client.js +66 -2
  40. package/dist/resources/v1/ai-photo-editor/request-types.js +3 -3
  41. package/dist/resources/v1/ai-photo-editor/resource-client.d.ts +50 -1
  42. package/dist/resources/v1/ai-photo-editor/resource-client.js +81 -2
  43. package/dist/resources/v1/ai-qr-code-generator/request-types.js +3 -3
  44. package/dist/resources/v1/ai-qr-code-generator/resource-client.d.ts +31 -1
  45. package/dist/resources/v1/ai-qr-code-generator/resource-client.js +63 -2
  46. package/dist/resources/v1/ai-talking-photo/request-types.js +3 -3
  47. package/dist/resources/v1/ai-talking-photo/resource-client.d.ts +52 -1
  48. package/dist/resources/v1/ai-talking-photo/resource-client.js +78 -2
  49. package/dist/resources/v1/animation/request-types.js +3 -3
  50. package/dist/resources/v1/animation/resource-client.d.ts +62 -1
  51. package/dist/resources/v1/animation/resource-client.js +100 -2
  52. package/dist/resources/v1/auto-subtitle-generator/request-types.js +3 -3
  53. package/dist/resources/v1/auto-subtitle-generator/resource-client.d.ts +42 -1
  54. package/dist/resources/v1/auto-subtitle-generator/resource-client.js +73 -2
  55. package/dist/resources/v1/face-detection/request-types.js +5 -5
  56. package/dist/resources/v1/face-detection/resource-client.d.ts +31 -1
  57. package/dist/resources/v1/face-detection/resource-client.js +77 -2
  58. package/dist/resources/v1/face-swap/request-types.js +3 -3
  59. package/dist/resources/v1/face-swap/resource-client.d.ts +78 -1
  60. package/dist/resources/v1/face-swap/resource-client.js +127 -2
  61. package/dist/resources/v1/face-swap-photo/request-types.js +3 -3
  62. package/dist/resources/v1/face-swap-photo/resource-client.d.ts +74 -1
  63. package/dist/resources/v1/face-swap-photo/resource-client.js +119 -2
  64. package/dist/resources/v1/files/resource-client.d.ts +41 -1
  65. package/dist/resources/v1/files/resource-client.js +238 -2
  66. package/dist/resources/v1/files/resource-client.test.d.ts +1 -0
  67. package/dist/resources/v1/files/resource-client.test.js +422 -0
  68. package/dist/resources/v1/files/upload-urls/request-types.js +3 -3
  69. package/dist/resources/v1/files/upload-urls/resource-client.d.ts +1 -1
  70. package/dist/resources/v1/files/upload-urls/resource-client.js +2 -2
  71. package/dist/resources/v1/image-background-remover/request-types.js +3 -3
  72. package/dist/resources/v1/image-background-remover/resource-client.d.ts +50 -1
  73. package/dist/resources/v1/image-background-remover/resource-client.js +84 -2
  74. package/dist/resources/v1/image-projects/request-types.js +5 -5
  75. package/dist/resources/v1/image-projects/resource-client.d.ts +23 -1
  76. package/dist/resources/v1/image-projects/resource-client.js +70 -2
  77. package/dist/resources/v1/image-projects/resource-client.test.d.ts +1 -0
  78. package/dist/resources/v1/image-projects/resource-client.test.js +538 -0
  79. package/dist/resources/v1/image-to-video/request-types.js +3 -3
  80. package/dist/resources/v1/image-to-video/resource-client.d.ts +41 -1
  81. package/dist/resources/v1/image-to-video/resource-client.js +72 -2
  82. package/dist/resources/v1/lip-sync/request-types.js +3 -3
  83. package/dist/resources/v1/lip-sync/resource-client.d.ts +54 -1
  84. package/dist/resources/v1/lip-sync/resource-client.js +86 -2
  85. package/dist/resources/v1/photo-colorizer/request-types.js +3 -3
  86. package/dist/resources/v1/photo-colorizer/resource-client.d.ts +39 -1
  87. package/dist/resources/v1/photo-colorizer/resource-client.js +70 -2
  88. package/dist/resources/v1/resource-client.d.ts +1 -1
  89. package/dist/resources/v1/resource-client.js +2 -2
  90. package/dist/resources/v1/text-to-video/request-types.js +3 -3
  91. package/dist/resources/v1/text-to-video/resource-client.d.ts +33 -1
  92. package/dist/resources/v1/text-to-video/resource-client.js +65 -2
  93. package/dist/resources/v1/video-projects/request-types.js +5 -5
  94. package/dist/resources/v1/video-projects/resource-client.d.ts +23 -1
  95. package/dist/resources/v1/video-projects/resource-client.js +70 -2
  96. package/dist/resources/v1/video-projects/resource-client.test.d.ts +1 -0
  97. package/dist/resources/v1/video-projects/resource-client.test.js +713 -0
  98. package/dist/resources/v1/video-to-video/request-types.js +3 -3
  99. package/dist/resources/v1/video-to-video/resource-client.d.ts +49 -1
  100. package/dist/resources/v1/video-to-video/resource-client.js +86 -2
  101. package/dist/types/v1-ai-clothes-changer-create-body-assets.js +3 -3
  102. package/dist/types/v1-ai-clothes-changer-create-body.js +3 -3
  103. package/dist/types/v1-ai-clothes-changer-create-response.js +3 -3
  104. package/dist/types/v1-ai-clothes-changer-create-response400.js +3 -3
  105. package/dist/types/v1-ai-clothes-changer-create-response401.js +3 -3
  106. package/dist/types/v1-ai-clothes-changer-create-response404.js +3 -3
  107. package/dist/types/v1-ai-clothes-changer-create-response422.js +3 -3
  108. package/dist/types/v1-ai-face-editor-create-body-assets.js +3 -3
  109. package/dist/types/v1-ai-face-editor-create-body-style.js +3 -3
  110. package/dist/types/v1-ai-face-editor-create-body.js +3 -3
  111. package/dist/types/v1-ai-face-editor-create-response.js +3 -3
  112. package/dist/types/v1-ai-face-editor-create-response400.js +3 -3
  113. package/dist/types/v1-ai-face-editor-create-response401.js +3 -3
  114. package/dist/types/v1-ai-face-editor-create-response404.js +3 -3
  115. package/dist/types/v1-ai-face-editor-create-response422.js +3 -3
  116. package/dist/types/v1-ai-gif-generator-create-body-style.js +3 -3
  117. package/dist/types/v1-ai-gif-generator-create-body.js +3 -3
  118. package/dist/types/v1-ai-gif-generator-create-response.js +3 -3
  119. package/dist/types/v1-ai-gif-generator-create-response400.js +3 -3
  120. package/dist/types/v1-ai-gif-generator-create-response401.js +3 -3
  121. package/dist/types/v1-ai-gif-generator-create-response404.js +3 -3
  122. package/dist/types/v1-ai-gif-generator-create-response422.js +3 -3
  123. package/dist/types/v1-ai-headshot-generator-create-body-assets.js +3 -3
  124. package/dist/types/v1-ai-headshot-generator-create-body-style.js +3 -3
  125. package/dist/types/v1-ai-headshot-generator-create-body.js +3 -3
  126. package/dist/types/v1-ai-headshot-generator-create-response.js +3 -3
  127. package/dist/types/v1-ai-headshot-generator-create-response400.js +3 -3
  128. package/dist/types/v1-ai-headshot-generator-create-response401.js +3 -3
  129. package/dist/types/v1-ai-headshot-generator-create-response404.js +3 -3
  130. package/dist/types/v1-ai-headshot-generator-create-response422.js +3 -3
  131. package/dist/types/v1-ai-image-editor-create-body-assets.js +3 -3
  132. package/dist/types/v1-ai-image-editor-create-body-style.js +3 -3
  133. package/dist/types/v1-ai-image-editor-create-body.js +3 -3
  134. package/dist/types/v1-ai-image-editor-create-response.js +3 -3
  135. package/dist/types/v1-ai-image-editor-create-response400.js +3 -3
  136. package/dist/types/v1-ai-image-editor-create-response401.js +3 -3
  137. package/dist/types/v1-ai-image-editor-create-response404.js +3 -3
  138. package/dist/types/v1-ai-image-editor-create-response422.js +3 -3
  139. package/dist/types/v1-ai-image-generator-create-body-style.js +3 -3
  140. package/dist/types/v1-ai-image-generator-create-body.js +3 -3
  141. package/dist/types/v1-ai-image-generator-create-response.js +3 -3
  142. package/dist/types/v1-ai-image-generator-create-response400.js +3 -3
  143. package/dist/types/v1-ai-image-generator-create-response401.js +3 -3
  144. package/dist/types/v1-ai-image-generator-create-response404.js +3 -3
  145. package/dist/types/v1-ai-image-generator-create-response422.js +3 -3
  146. package/dist/types/v1-ai-image-upscaler-create-body-assets.js +3 -3
  147. package/dist/types/v1-ai-image-upscaler-create-body-style.js +3 -3
  148. package/dist/types/v1-ai-image-upscaler-create-body.js +3 -3
  149. package/dist/types/v1-ai-image-upscaler-create-response.js +3 -3
  150. package/dist/types/v1-ai-image-upscaler-create-response400.js +3 -3
  151. package/dist/types/v1-ai-image-upscaler-create-response401.js +3 -3
  152. package/dist/types/v1-ai-image-upscaler-create-response404.js +3 -3
  153. package/dist/types/v1-ai-image-upscaler-create-response422.js +3 -3
  154. package/dist/types/v1-ai-meme-generator-create-body-style.js +3 -3
  155. package/dist/types/v1-ai-meme-generator-create-body.js +3 -3
  156. package/dist/types/v1-ai-meme-generator-create-response.js +3 -3
  157. package/dist/types/v1-ai-meme-generator-create-response400.js +3 -3
  158. package/dist/types/v1-ai-meme-generator-create-response401.js +3 -3
  159. package/dist/types/v1-ai-meme-generator-create-response404.js +3 -3
  160. package/dist/types/v1-ai-meme-generator-create-response422.js +3 -3
  161. package/dist/types/v1-ai-photo-editor-create-body-assets.js +3 -3
  162. package/dist/types/v1-ai-photo-editor-create-body-style.js +3 -3
  163. package/dist/types/v1-ai-photo-editor-create-body.js +3 -3
  164. package/dist/types/v1-ai-photo-editor-create-response.js +3 -3
  165. package/dist/types/v1-ai-photo-editor-create-response400.js +3 -3
  166. package/dist/types/v1-ai-photo-editor-create-response401.js +3 -3
  167. package/dist/types/v1-ai-photo-editor-create-response404.js +3 -3
  168. package/dist/types/v1-ai-photo-editor-create-response422.js +3 -3
  169. package/dist/types/v1-ai-qr-code-generator-create-body-style.js +3 -3
  170. package/dist/types/v1-ai-qr-code-generator-create-body.js +3 -3
  171. package/dist/types/v1-ai-qr-code-generator-create-response.js +3 -3
  172. package/dist/types/v1-ai-qr-code-generator-create-response400.js +3 -3
  173. package/dist/types/v1-ai-qr-code-generator-create-response401.js +3 -3
  174. package/dist/types/v1-ai-qr-code-generator-create-response404.js +3 -3
  175. package/dist/types/v1-ai-qr-code-generator-create-response422.js +3 -3
  176. package/dist/types/v1-ai-talking-photo-create-body-assets.js +3 -3
  177. package/dist/types/v1-ai-talking-photo-create-body-style-generation-mode-enum.d.ts +3 -2
  178. package/dist/types/v1-ai-talking-photo-create-body-style.d.ts +4 -3
  179. package/dist/types/v1-ai-talking-photo-create-body-style.js +5 -5
  180. package/dist/types/v1-ai-talking-photo-create-body.js +3 -3
  181. package/dist/types/v1-ai-talking-photo-create-response.js +3 -3
  182. package/dist/types/v1-ai-talking-photo-create-response400.js +3 -3
  183. package/dist/types/v1-ai-talking-photo-create-response401.js +3 -3
  184. package/dist/types/v1-ai-talking-photo-create-response404.js +3 -3
  185. package/dist/types/v1-ai-talking-photo-create-response422.js +3 -3
  186. package/dist/types/v1-animation-create-body-assets.js +3 -3
  187. package/dist/types/v1-animation-create-body-style.js +3 -3
  188. package/dist/types/v1-animation-create-body.js +3 -3
  189. package/dist/types/v1-animation-create-response.js +3 -3
  190. package/dist/types/v1-animation-create-response400.js +3 -3
  191. package/dist/types/v1-animation-create-response401.js +3 -3
  192. package/dist/types/v1-animation-create-response404.js +3 -3
  193. package/dist/types/v1-animation-create-response422.js +3 -3
  194. package/dist/types/v1-auto-subtitle-generator-create-body-assets.js +3 -3
  195. package/dist/types/v1-auto-subtitle-generator-create-body-style-custom-config.js +3 -3
  196. package/dist/types/v1-auto-subtitle-generator-create-body-style.js +3 -3
  197. package/dist/types/v1-auto-subtitle-generator-create-body.js +3 -3
  198. package/dist/types/v1-auto-subtitle-generator-create-response.js +3 -3
  199. package/dist/types/v1-auto-subtitle-generator-create-response400.js +3 -3
  200. package/dist/types/v1-auto-subtitle-generator-create-response401.js +3 -3
  201. package/dist/types/v1-auto-subtitle-generator-create-response404.js +3 -3
  202. package/dist/types/v1-auto-subtitle-generator-create-response422.js +3 -3
  203. package/dist/types/v1-face-detection-create-body-assets.js +3 -3
  204. package/dist/types/v1-face-detection-create-body.js +3 -3
  205. package/dist/types/v1-face-detection-create-response.js +3 -3
  206. package/dist/types/v1-face-detection-create-response400.js +3 -3
  207. package/dist/types/v1-face-detection-create-response401.js +3 -3
  208. package/dist/types/v1-face-detection-create-response404.js +3 -3
  209. package/dist/types/v1-face-detection-create-response422.js +3 -3
  210. package/dist/types/v1-face-detection-get-response-faces-item.js +3 -3
  211. package/dist/types/v1-face-detection-get-response.js +3 -3
  212. package/dist/types/v1-face-detection-get-response400.js +3 -3
  213. package/dist/types/v1-face-detection-get-response401.js +3 -3
  214. package/dist/types/v1-face-detection-get-response404.js +3 -3
  215. package/dist/types/v1-face-detection-get-response422.js +3 -3
  216. package/dist/types/v1-face-swap-create-body-assets-face-mappings-item.js +3 -3
  217. package/dist/types/v1-face-swap-create-body-assets.js +3 -3
  218. package/dist/types/v1-face-swap-create-body-style.js +3 -3
  219. package/dist/types/v1-face-swap-create-body.js +3 -3
  220. package/dist/types/v1-face-swap-create-response.js +3 -3
  221. package/dist/types/v1-face-swap-create-response400.js +3 -3
  222. package/dist/types/v1-face-swap-create-response401.js +3 -3
  223. package/dist/types/v1-face-swap-create-response404.js +3 -3
  224. package/dist/types/v1-face-swap-create-response422.js +3 -3
  225. package/dist/types/v1-face-swap-photo-create-body-assets-face-mappings-item.js +3 -3
  226. package/dist/types/v1-face-swap-photo-create-body-assets.js +3 -3
  227. package/dist/types/v1-face-swap-photo-create-body.js +3 -3
  228. package/dist/types/v1-face-swap-photo-create-response.js +3 -3
  229. package/dist/types/v1-face-swap-photo-create-response400.js +3 -3
  230. package/dist/types/v1-face-swap-photo-create-response401.js +3 -3
  231. package/dist/types/v1-face-swap-photo-create-response404.js +3 -3
  232. package/dist/types/v1-face-swap-photo-create-response422.js +3 -3
  233. package/dist/types/v1-files-upload-urls-create-body-items-item.js +3 -3
  234. package/dist/types/v1-files-upload-urls-create-body.js +3 -3
  235. package/dist/types/v1-files-upload-urls-create-response-items-item.js +3 -3
  236. package/dist/types/v1-files-upload-urls-create-response.js +3 -3
  237. package/dist/types/v1-files-upload-urls-create-response400.js +3 -3
  238. package/dist/types/v1-files-upload-urls-create-response401.js +3 -3
  239. package/dist/types/v1-files-upload-urls-create-response404.js +3 -3
  240. package/dist/types/v1-files-upload-urls-create-response422.js +3 -3
  241. package/dist/types/v1-image-background-remover-create-body-assets.js +3 -3
  242. package/dist/types/v1-image-background-remover-create-body.js +3 -3
  243. package/dist/types/v1-image-background-remover-create-response.js +3 -3
  244. package/dist/types/v1-image-background-remover-create-response400.js +3 -3
  245. package/dist/types/v1-image-background-remover-create-response401.js +3 -3
  246. package/dist/types/v1-image-background-remover-create-response404.js +3 -3
  247. package/dist/types/v1-image-background-remover-create-response422.js +3 -3
  248. package/dist/types/v1-image-projects-delete-response400.js +3 -3
  249. package/dist/types/v1-image-projects-delete-response401.js +3 -3
  250. package/dist/types/v1-image-projects-delete-response404.js +3 -3
  251. package/dist/types/v1-image-projects-get-response-downloads-item.js +3 -3
  252. package/dist/types/v1-image-projects-get-response-error.js +3 -3
  253. package/dist/types/v1-image-projects-get-response.js +3 -3
  254. package/dist/types/v1-image-projects-get-response400.js +3 -3
  255. package/dist/types/v1-image-projects-get-response401.js +3 -3
  256. package/dist/types/v1-image-projects-get-response404.js +3 -3
  257. package/dist/types/v1-image-to-video-create-body-assets.js +3 -3
  258. package/dist/types/v1-image-to-video-create-body-style.js +3 -3
  259. package/dist/types/v1-image-to-video-create-body.js +3 -3
  260. package/dist/types/v1-image-to-video-create-response.js +3 -3
  261. package/dist/types/v1-image-to-video-create-response400.js +3 -3
  262. package/dist/types/v1-image-to-video-create-response401.js +3 -3
  263. package/dist/types/v1-image-to-video-create-response404.js +3 -3
  264. package/dist/types/v1-image-to-video-create-response422.js +3 -3
  265. package/dist/types/v1-lip-sync-create-body-assets.js +3 -3
  266. package/dist/types/v1-lip-sync-create-body.js +3 -3
  267. package/dist/types/v1-lip-sync-create-response.js +3 -3
  268. package/dist/types/v1-lip-sync-create-response400.js +3 -3
  269. package/dist/types/v1-lip-sync-create-response401.js +3 -3
  270. package/dist/types/v1-lip-sync-create-response404.js +3 -3
  271. package/dist/types/v1-lip-sync-create-response422.js +3 -3
  272. package/dist/types/v1-photo-colorizer-create-body-assets.js +3 -3
  273. package/dist/types/v1-photo-colorizer-create-body.js +3 -3
  274. package/dist/types/v1-photo-colorizer-create-response.js +3 -3
  275. package/dist/types/v1-photo-colorizer-create-response400.js +3 -3
  276. package/dist/types/v1-photo-colorizer-create-response401.js +3 -3
  277. package/dist/types/v1-photo-colorizer-create-response404.js +3 -3
  278. package/dist/types/v1-photo-colorizer-create-response422.js +3 -3
  279. package/dist/types/v1-text-to-video-create-body-style.js +3 -3
  280. package/dist/types/v1-text-to-video-create-body.js +3 -3
  281. package/dist/types/v1-text-to-video-create-response.js +3 -3
  282. package/dist/types/v1-text-to-video-create-response400.js +3 -3
  283. package/dist/types/v1-text-to-video-create-response401.js +3 -3
  284. package/dist/types/v1-text-to-video-create-response404.js +3 -3
  285. package/dist/types/v1-text-to-video-create-response422.js +3 -3
  286. package/dist/types/v1-video-projects-delete-response400.js +3 -3
  287. package/dist/types/v1-video-projects-delete-response401.js +3 -3
  288. package/dist/types/v1-video-projects-delete-response404.js +3 -3
  289. package/dist/types/v1-video-projects-delete-response422.js +3 -3
  290. package/dist/types/v1-video-projects-get-response-download.js +3 -3
  291. package/dist/types/v1-video-projects-get-response-downloads-item.js +3 -3
  292. package/dist/types/v1-video-projects-get-response-error.js +3 -3
  293. package/dist/types/v1-video-projects-get-response.js +3 -3
  294. package/dist/types/v1-video-projects-get-response400.js +3 -3
  295. package/dist/types/v1-video-projects-get-response401.js +3 -3
  296. package/dist/types/v1-video-projects-get-response404.js +3 -3
  297. package/dist/types/v1-video-to-video-create-body-assets.js +3 -3
  298. package/dist/types/v1-video-to-video-create-body-style.js +3 -3
  299. package/dist/types/v1-video-to-video-create-body.js +3 -3
  300. package/dist/types/v1-video-to-video-create-response.js +3 -3
  301. package/dist/types/v1-video-to-video-create-response400.js +3 -3
  302. package/dist/types/v1-video-to-video-create-response401.js +3 -3
  303. package/dist/types/v1-video-to-video-create-response404.js +3 -3
  304. package/dist/types/v1-video-to-video-create-response422.js +3 -3
  305. package/package.json +16 -21
  306. package/dist/core/api-error.d.ts +0 -6
  307. package/dist/core/api-error.js +0 -11
  308. package/dist/core/api-promise.d.ts +0 -28
  309. package/dist/core/api-promise.js +0 -252
  310. package/dist/core/auth.d.ts +0 -76
  311. package/dist/core/auth.js +0 -232
  312. package/dist/core/binary-response.d.ts +0 -6
  313. package/dist/core/binary-response.js +0 -10
  314. package/dist/core/content-type.d.ts +0 -4
  315. package/dist/core/content-type.js +0 -12
  316. package/dist/core/core-client.d.ts +0 -58
  317. package/dist/core/core-client.js +0 -168
  318. package/dist/core/form-data.d.ts +0 -26
  319. package/dist/core/form-data.js +0 -83
  320. package/dist/core/index.d.ts +0 -9
  321. package/dist/core/index.js +0 -28
  322. package/dist/core/query.d.ts +0 -8
  323. package/dist/core/query.js +0 -77
  324. package/dist/core/runtime.d.ts +0 -4
  325. package/dist/core/runtime.js +0 -20
  326. package/dist/core/zod.d.ts +0 -13
  327. package/dist/core/zod.js +0 -60
package/dist/core/auth.js DELETED
@@ -1,232 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.OAuth2 = exports.AuthKey = exports.AuthBearer = exports.AuthBasic = void 0;
49
- const qs_1 = __importDefault(require("qs"));
50
- const form_urlencoded_1 = __importDefault(require("form-urlencoded"));
51
- const js_base64_1 = require("js-base64");
52
- const jsonpointer = __importStar(require("jsonpointer"));
53
- const runtime_1 = require("./runtime");
54
- const api_error_1 = require("./api-error");
55
- const AUTHORIZATION = "Authorization";
56
- const COOKIE = "Cookie";
57
- class AuthBasic {
58
- constructor(username, password) {
59
- this.username = username !== null && username !== void 0 ? username : null;
60
- this.password = password !== null && password !== void 0 ? password : null;
61
- }
62
- applyAuth(cfg) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- var _a;
65
- const headers = (_a = cfg.headers) !== null && _a !== void 0 ? _a : {};
66
- if (this.username !== null && this.password !== null) {
67
- const encoded = (0, js_base64_1.toBase64)(`${this.username}:${this.password}`);
68
- cfg.headers = headers;
69
- headers[AUTHORIZATION] = `Basic ${encoded}`;
70
- }
71
- return cfg;
72
- });
73
- }
74
- setValue(val) {
75
- this.username = val !== null && val !== void 0 ? val : null;
76
- }
77
- }
78
- exports.AuthBasic = AuthBasic;
79
- class AuthBearer {
80
- constructor(token) {
81
- this.token = token !== null && token !== void 0 ? token : null;
82
- }
83
- applyAuth(cfg) {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- var _a;
86
- const headers = (_a = cfg.headers) !== null && _a !== void 0 ? _a : {};
87
- if (this.token !== null) {
88
- cfg.headers = headers;
89
- headers[AUTHORIZATION] = `Bearer ${this.token}`;
90
- }
91
- return cfg;
92
- });
93
- }
94
- setValue(val) {
95
- this.token = val !== null && val !== void 0 ? val : null;
96
- }
97
- }
98
- exports.AuthBearer = AuthBearer;
99
- class AuthKey {
100
- constructor(name, location, key) {
101
- this.name = name;
102
- this.location = location;
103
- this.key = key !== null && key !== void 0 ? key : null;
104
- }
105
- applyAuth(cfg) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- var _a, _b, _c, _d;
108
- if (this.key === null) {
109
- return cfg;
110
- }
111
- if (this.location === "query") {
112
- const query = (_a = cfg.query) !== null && _a !== void 0 ? _a : [];
113
- cfg.query = query;
114
- query.push(qs_1.default.stringify({ [this.name]: this.key }));
115
- }
116
- else if (this.location === "header") {
117
- const headers = (_b = cfg.headers) !== null && _b !== void 0 ? _b : {};
118
- cfg.headers = headers;
119
- headers[this.name] = this.key;
120
- }
121
- else if (this.location === "cookie" && runtime_1.RUNTIME.type === "browser") {
122
- cfg.withCredentials = true;
123
- }
124
- else if (this.location === "cookie") {
125
- const headers = (_c = cfg.headers) !== null && _c !== void 0 ? _c : {};
126
- const cookies = (_d = headers[COOKIE]) !== null && _d !== void 0 ? _d : "";
127
- headers[COOKIE] = `${cookies.length > 0 ? ";" : ""}${this.name}=${this.key}`;
128
- cfg.headers = headers;
129
- }
130
- return cfg;
131
- });
132
- }
133
- setValue(val) {
134
- this.key = val !== null && val !== void 0 ? val : null;
135
- }
136
- }
137
- exports.AuthKey = AuthKey;
138
- function isOAuth2Password(val) {
139
- return typeof val.username === "string" && typeof val.password === "string";
140
- }
141
- function isOAuth2ClientCredentials(val) {
142
- return (typeof val.clientId === "string" && typeof val.clientSecret === "string");
143
- }
144
- class OAuth2 {
145
- constructor(props) {
146
- this.props = props;
147
- }
148
- refresh(form) {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- var _a, _b;
151
- const { baseUrl, defaultTokenUrl, credentialsLocation, bodyContent, accessTokenPointer, expiresInPointer, } = this.props;
152
- // build token url
153
- let tokenUrl = (_a = form === null || form === void 0 ? void 0 : form.tokenUrl) !== null && _a !== void 0 ? _a : defaultTokenUrl;
154
- if (tokenUrl.startsWith("/")) {
155
- // relative token url
156
- const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
157
- tokenUrl = `${base}${tokenUrl}`;
158
- }
159
- let defaultGrantType = isOAuth2Password(form)
160
- ? "password"
161
- : "client_credentials";
162
- const reqHeaders = {};
163
- const reqData = {
164
- grant_type: (_b = form.grantType) !== null && _b !== void 0 ? _b : defaultGrantType,
165
- };
166
- // Add client credentials
167
- if (isOAuth2ClientCredentials(form)) {
168
- if (credentialsLocation === "basic_authorization_header") {
169
- const encoded = (0, js_base64_1.toBase64)(`${form.clientId}:${form.clientSecret}`);
170
- reqHeaders[AUTHORIZATION] = `Basic ${encoded}`;
171
- }
172
- else {
173
- reqData["client_id"] = form.clientId;
174
- reqData["client_secret"] = form.clientSecret;
175
- }
176
- }
177
- if (isOAuth2Password(form)) {
178
- reqData["username"] = form.username;
179
- reqData["password"] = form.password;
180
- }
181
- if (typeof form.scope !== "undefined") {
182
- reqData["scope"] = form.scope.join(" ");
183
- }
184
- const reqInit = { method: "POST" };
185
- if (bodyContent === "form") {
186
- reqInit.body = (0, form_urlencoded_1.default)(reqData);
187
- reqHeaders["content-type"] = "application/x-www-form-urlencoded";
188
- }
189
- else {
190
- reqInit.body = JSON.stringify(reqData);
191
- reqHeaders["content-type"] = "application/json";
192
- }
193
- reqInit.headers = reqHeaders;
194
- const fetcherFn = runtime_1.RUNTIME.type === "node" || typeof fetch !== "function"
195
- ? require("node-fetch").default
196
- : fetch;
197
- const tokenRes = yield fetcherFn(tokenUrl, reqInit);
198
- if (!tokenRes.ok) {
199
- throw new api_error_1.ApiError({
200
- method: "post",
201
- path: tokenUrl,
202
- headers: reqHeaders,
203
- body: reqData,
204
- contentType: reqHeaders["content-type"],
205
- }, tokenRes);
206
- }
207
- const tokenResJson = yield tokenRes.json();
208
- const accessTokenRaw = jsonpointer.get(tokenResJson, accessTokenPointer);
209
- const accessToken = typeof accessTokenRaw === "string" ? accessTokenRaw : "";
210
- const expiresInRaw = jsonpointer.get(tokenResJson, expiresInPointer);
211
- const expiresInSecs = typeof expiresInRaw === "number" ? expiresInRaw : 600;
212
- const now = new Date();
213
- const expiresAt = new Date(now.getTime() + expiresInSecs * 1000);
214
- return { accessToken, expiresAt };
215
- });
216
- }
217
- applyAuth(cfg) {
218
- return __awaiter(this, void 0, void 0, function* () {
219
- if (this.props.form && !this.accessToken) {
220
- const { accessToken, expiresAt } = yield this.refresh(this.props.form);
221
- this.accessToken = accessToken;
222
- this.expiresAt = expiresAt;
223
- }
224
- this.props.requestMutator.setValue(this.accessToken);
225
- return yield this.props.requestMutator.applyAuth(cfg);
226
- });
227
- }
228
- setValue(val) {
229
- throw "an OAuth2 auth provider can not a requestMutator";
230
- }
231
- }
232
- exports.OAuth2 = OAuth2;
@@ -1,6 +0,0 @@
1
- import type { Blob as NodeBlob } from "node-fetch";
2
- export declare class BinaryResponse {
3
- content: Blob | NodeBlob;
4
- contentType: string | null;
5
- constructor(content: Blob | NodeBlob, contentType: string | null);
6
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BinaryResponse = void 0;
4
- class BinaryResponse {
5
- constructor(content, contentType) {
6
- this.content = content;
7
- this.contentType = contentType;
8
- }
9
- }
10
- exports.BinaryResponse = BinaryResponse;
@@ -1,4 +0,0 @@
1
- export declare const JSON_PATTERN: RegExp;
2
- export declare const TEXT_PATTERN: RegExp;
3
- export declare const MULTIPART_FORM = "multipart/form-data";
4
- export declare const URL_FORM = "application/x-www-form-urlencoded";
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.URL_FORM = exports.MULTIPART_FORM = exports.TEXT_PATTERN = exports.JSON_PATTERN = void 0;
4
- // use a pattern to match json content type to handle
5
- // base case of application/json as well as vendor specific
6
- // headers e.g. application/vnd.github+json
7
- exports.JSON_PATTERN = /^application\/(.+\+)?json/;
8
- // use a pattern to match text types to handle base case
9
- // of text/plain as well as more specific cases e.g. text/html
10
- exports.TEXT_PATTERN = /^text\/(.+)/;
11
- exports.MULTIPART_FORM = "multipart/form-data";
12
- exports.URL_FORM = "application/x-www-form-urlencoded";
@@ -1,58 +0,0 @@
1
- import type * as z from "zod";
2
- import type { Response as NodeResponse } from "node-fetch";
3
- import type { AuthProvider } from "./auth";
4
- import { ApiPromise } from "./api-promise";
5
- import { type QueryStyle } from "./query";
6
- export interface CoreClientProps {
7
- baseUrl: string | Record<string, string | undefined>;
8
- timeout?: number | undefined;
9
- auths?: Record<string, AuthProvider>;
10
- }
11
- export type ApiResponse = Response | NodeResponse;
12
- export type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
13
- export type RequestConfig = {
14
- method: HttpMethod;
15
- path: string;
16
- serviceName?: string | undefined;
17
- responseSchema?: z.Schema;
18
- responseStream?: boolean;
19
- responseRaw?: boolean;
20
- auth?: string[];
21
- query?: string[];
22
- body?: any;
23
- bodyEncoding?: {
24
- style?: Record<string, QueryStyle>;
25
- explode?: Record<string, boolean>;
26
- };
27
- contentType?: string;
28
- headers?: Record<string, string>;
29
- opts?: RequestOptions | undefined;
30
- withCredentials?: boolean;
31
- };
32
- export interface RequestOptions {
33
- timeout?: number;
34
- additionalHeaders?: Record<string, string>;
35
- additionalQuery?: Record<string, string>;
36
- }
37
- export declare class CoreClient {
38
- private baseUrl;
39
- private auths;
40
- private timeout;
41
- constructor(props: CoreClientProps);
42
- private applyAuths;
43
- buildUrl(path: string, serviceName?: string): string;
44
- private buildUrlFromCfg;
45
- private applyHeaders;
46
- private encodeBodyByContentType;
47
- private buildRequestInit;
48
- private request;
49
- makeRequest<R>(cfg: RequestConfig): ApiPromise<R>;
50
- }
51
- export interface ResourceClientOptions {
52
- lazyLoad?: boolean | undefined;
53
- }
54
- export declare class CoreResourceClient {
55
- protected _client: CoreClient;
56
- protected _opts: ResourceClientOptions;
57
- constructor(client: CoreClient, opts: ResourceClientOptions);
58
- }
@@ -1,168 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CoreResourceClient = exports.CoreClient = void 0;
13
- const runtime_1 = require("./runtime");
14
- const api_promise_1 = require("./api-promise");
15
- const api_error_1 = require("./api-error");
16
- const form_data_1 = require("./form-data");
17
- const query_1 = require("./query");
18
- const content_type_1 = require("./content-type");
19
- const _DEFAULT_SERVICE_NAME = "__default_service__";
20
- class CoreClient {
21
- constructor(props) {
22
- var _a;
23
- this.baseUrl =
24
- typeof props.baseUrl === "string"
25
- ? { [_DEFAULT_SERVICE_NAME]: props.baseUrl }
26
- : props.baseUrl;
27
- this.auths = (_a = props.auths) !== null && _a !== void 0 ? _a : {};
28
- this.timeout = props.timeout;
29
- }
30
- applyAuths(cfg) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- var _a;
33
- for (const name of (_a = cfg.auth) !== null && _a !== void 0 ? _a : []) {
34
- const provider = this.auths[name];
35
- if (provider) {
36
- cfg = yield provider.applyAuth(cfg);
37
- }
38
- }
39
- return cfg;
40
- });
41
- }
42
- buildUrl(path, serviceName = _DEFAULT_SERVICE_NAME) {
43
- var _a;
44
- const baseUrl = (_a = this.baseUrl[serviceName !== null && serviceName !== void 0 ? serviceName : _DEFAULT_SERVICE_NAME]) !== null && _a !== void 0 ? _a : "";
45
- const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
46
- const cleanPath = path.startsWith("/") ? path.slice(1) : path;
47
- return `${base}/${cleanPath}`;
48
- }
49
- buildUrlFromCfg(cfg) {
50
- var _a, _b, _c;
51
- let url = this.buildUrl(cfg.path, cfg.serviceName);
52
- const searchParams = new URLSearchParams(((_a = cfg.query) !== null && _a !== void 0 ? _a : []).join("&"));
53
- for (const [key, val] of Object.entries((_c = (_b = cfg.opts) === null || _b === void 0 ? void 0 : _b.additionalQuery) !== null && _c !== void 0 ? _c : {})) {
54
- searchParams.append(key, val);
55
- }
56
- if (searchParams.toString().length > 0) {
57
- url += `?${searchParams.toString()}`;
58
- }
59
- return url;
60
- }
61
- applyHeaders(cfg, reqInit) {
62
- var _a, _b, _c;
63
- const finalHeaders = Object.assign(Object.assign(Object.assign(Object.assign({ "x-sideko-sdk-language": "Javascript", "x-sideko-runtime": runtime_1.RUNTIME.type }, ((_a = reqInit.headers) !== null && _a !== void 0 ? _a : {})), ((_b = cfg.headers) !== null && _b !== void 0 ? _b : {})), (cfg.contentType ? { "content-type": cfg.contentType } : {})), (_c = cfg.opts) === null || _c === void 0 ? void 0 : _c.additionalHeaders);
64
- reqInit.headers = finalHeaders;
65
- return reqInit;
66
- }
67
- encodeBodyByContentType(cfg, reqInit) {
68
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
69
- const contentTypeOverride = (_c = (_b = (_a = cfg.opts) === null || _a === void 0 ? void 0 : _a.additionalHeaders) === null || _b === void 0 ? void 0 : _b["content-type"]) !== null && _c !== void 0 ? _c : (_e = (_d = cfg.opts) === null || _d === void 0 ? void 0 : _d.additionalHeaders) === null || _e === void 0 ? void 0 : _e["Content-Type"];
70
- const contentType = (_f = contentTypeOverride !== null && contentTypeOverride !== void 0 ? contentTypeOverride : cfg.contentType) !== null && _f !== void 0 ? _f : "";
71
- if (typeof cfg.body === "undefined") {
72
- return reqInit;
73
- }
74
- else if (contentType.match(content_type_1.JSON_PATTERN)) {
75
- reqInit.body = JSON.stringify(cfg.body);
76
- }
77
- else if (contentType.match(content_type_1.TEXT_PATTERN)) {
78
- reqInit.body = String(cfg.body);
79
- }
80
- else if (contentType === content_type_1.MULTIPART_FORM) {
81
- // encode form
82
- const form = (0, form_data_1.createForm)(cfg.body);
83
- const headers = (_g = reqInit.headers) !== null && _g !== void 0 ? _g : {};
84
- if (runtime_1.RUNTIME.type === "node") {
85
- // explicitly set boundary
86
- headers["content-type"] = `${content_type_1.MULTIPART_FORM}; boundary=${form.getBoundary()}`;
87
- }
88
- else {
89
- // the browser should automatically set the content type
90
- delete headers["content-type"];
91
- }
92
- reqInit.headers = headers;
93
- reqInit.body = form;
94
- }
95
- else if (contentType === content_type_1.URL_FORM) {
96
- if (typeof cfg.body !== "object") {
97
- throw new TypeError("x-www-form-urlencoded data must be an object at the top level");
98
- }
99
- // encode form data
100
- const styleMap = (_j = (_h = cfg.bodyEncoding) === null || _h === void 0 ? void 0 : _h.style) !== null && _j !== void 0 ? _j : {};
101
- const explodeMap = (_l = (_k = cfg.bodyEncoding) === null || _k === void 0 ? void 0 : _k.explode) !== null && _l !== void 0 ? _l : {};
102
- const formData = Object.entries(cfg.body).map(([name, value]) => {
103
- var _a, _b;
104
- const style = (_a = styleMap[name]) !== null && _a !== void 0 ? _a : "form";
105
- const explode = (_b = explodeMap[name]) !== null && _b !== void 0 ? _b : style === "form";
106
- return (0, query_1.encodeQueryParam)({ name, value, style, explode });
107
- });
108
- reqInit.body = formData.join("&");
109
- }
110
- else {
111
- // we expect body to already be encoded in the correct fashion
112
- reqInit.body = cfg.body;
113
- }
114
- return reqInit;
115
- }
116
- buildRequestInit(cfg) {
117
- let reqInit = { method: cfg.method.toUpperCase() };
118
- reqInit = this.applyHeaders(cfg, reqInit);
119
- reqInit = this.encodeBodyByContentType(cfg, reqInit);
120
- if (cfg.withCredentials) {
121
- reqInit.credentials = "include";
122
- }
123
- return reqInit;
124
- }
125
- request(cfg) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- var _a, _b;
128
- const fetcherFn = runtime_1.RUNTIME.type === "node" || typeof fetch !== "function"
129
- ? require("node-fetch").default
130
- : fetch;
131
- cfg = yield this.applyAuths(cfg);
132
- const reqInit = this.buildRequestInit(cfg);
133
- const url = this.buildUrlFromCfg(cfg);
134
- const timeout = (_b = (_a = cfg.opts) === null || _a === void 0 ? void 0 : _a.timeout) !== null && _b !== void 0 ? _b : this.timeout;
135
- const controller = new AbortController();
136
- let timeoutId;
137
- if (typeof timeout !== "undefined") {
138
- timeoutId = setTimeout(() => controller.abort(), timeout);
139
- }
140
- reqInit.signal = controller.signal;
141
- const response = yield fetcherFn(url, reqInit);
142
- if (timeoutId) {
143
- clearTimeout(timeoutId);
144
- }
145
- if (!response.ok) {
146
- throw new api_error_1.ApiError(cfg, response);
147
- }
148
- return response;
149
- });
150
- }
151
- makeRequest(cfg) {
152
- var _a, _b;
153
- return new api_promise_1.ApiPromise({
154
- responsePromise: this.request(cfg),
155
- responseRaw: (_a = cfg.responseRaw) !== null && _a !== void 0 ? _a : false,
156
- responseStream: (_b = cfg.responseStream) !== null && _b !== void 0 ? _b : false,
157
- responseSchema: cfg.responseSchema,
158
- });
159
- }
160
- }
161
- exports.CoreClient = CoreClient;
162
- class CoreResourceClient {
163
- constructor(client, opts) {
164
- this._client = client;
165
- this._opts = opts;
166
- }
167
- }
168
- exports.CoreResourceClient = CoreResourceClient;
@@ -1,26 +0,0 @@
1
- import type { ReadStream as NodeReadStream } from "node:fs";
2
- export type UploadFile = FileLike | NodeReadStream;
3
- export declare function isUploadFile(val: any): val is UploadFile;
4
- export declare function isNodeReadStream(val: any): val is NodeReadStream;
5
- /**
6
- * Defines common File spec compatible with modern browser File, node-fetch, etc.
7
- */
8
- export interface FileLike extends BlobLike {
9
- lastModified: number;
10
- name: string;
11
- }
12
- export declare function isFileLike(val: any): val is FileLike;
13
- /**
14
- * Defines common Blob spec compatible with modern browser Blob, fetch-blob, etc.
15
- */
16
- export interface BlobLike {
17
- type: string;
18
- size: number;
19
- slice(start?: number, end?: number, type?: string): BlobLike;
20
- text(): Promise<string>;
21
- arrayBuffer(): Promise<ArrayBuffer>;
22
- }
23
- export declare function isBlobLike(val: any): val is BlobLike;
24
- export declare function createForm(data: {
25
- [key: string]: unknown;
26
- }): any;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUploadFile = isUploadFile;
4
- exports.isNodeReadStream = isNodeReadStream;
5
- exports.isFileLike = isFileLike;
6
- exports.isBlobLike = isBlobLike;
7
- exports.createForm = createForm;
8
- const runtime_1 = require("./runtime");
9
- function isUploadFile(val) {
10
- return isFileLike(val) || isNodeReadStream(val);
11
- }
12
- function isNodeReadStream(val) {
13
- // node read stream duck-typing check
14
- return (runtime_1.RUNTIME.type === "node" &&
15
- typeof val === "object" &&
16
- typeof val.bytesRead === "number" &&
17
- (typeof val.path === "string" || val.path instanceof Buffer) &&
18
- typeof val.pending === "boolean" &&
19
- typeof val.readable === "boolean" &&
20
- typeof val.read === "function" &&
21
- typeof val.setEncoding === "function" &&
22
- typeof val.pause === "function" &&
23
- typeof val.resume === "function" &&
24
- typeof val.isPaused === "function" &&
25
- typeof val.pipe === "function" &&
26
- typeof val.unpipe === "function" &&
27
- typeof val.unshift === "function" &&
28
- typeof val.wrap === "function");
29
- }
30
- function isFileLike(val) {
31
- // https://developer.mozilla.org/docs/Web/API/File
32
- // https://github.com/node-fetch/fetch-blob/blob/main/file.js
33
- return (typeof (val === null || val === void 0 ? void 0 : val.lastModified) === "number" &&
34
- typeof (val === null || val === void 0 ? void 0 : val.name) === "string" &&
35
- isBlobLike(val));
36
- }
37
- function isBlobLike(val) {
38
- // https://developer.mozilla.org/docs/Web/API/Blob
39
- // https://github.com/node-fetch/fetch-blob/blob/main/index.js
40
- return (typeof (val === null || val === void 0 ? void 0 : val.size) === "number" &&
41
- typeof (val === null || val === void 0 ? void 0 : val.type) === "string" &&
42
- typeof (val === null || val === void 0 ? void 0 : val.slice) === "function" &&
43
- typeof (val === null || val === void 0 ? void 0 : val.text) === "function" &&
44
- typeof (val === null || val === void 0 ? void 0 : val.arrayBuffer) === "function");
45
- }
46
- function appendFormData(form, key, val) {
47
- if (val === null || typeof val === "undefined") {
48
- return;
49
- }
50
- else if (["string", "boolean", "number"].includes(typeof val)) {
51
- form.append(key, val.toString());
52
- }
53
- else if (Array.isArray(val)) {
54
- for (const arrVal of val) {
55
- appendFormData(form, key, arrVal);
56
- }
57
- }
58
- else if (isUploadFile(val)) {
59
- form.append(key, val);
60
- }
61
- else if (typeof val === "object") {
62
- for (const [objKey, objVal] of Object.entries(val)) {
63
- appendFormData(form, `${key}[${objKey}]`, objVal);
64
- }
65
- }
66
- else {
67
- throw new TypeError(`Invalid value given to form: ${val}`);
68
- }
69
- }
70
- function createForm(data) {
71
- let form;
72
- if (runtime_1.RUNTIME.type === "node") {
73
- const NodeFormData = require("form-data");
74
- form = new NodeFormData();
75
- }
76
- else {
77
- form = new FormData();
78
- }
79
- for (const [key, val] of Object.entries(data)) {
80
- appendFormData(form, key, val);
81
- }
82
- return form;
83
- }
@@ -1,9 +0,0 @@
1
- export { ApiError } from "./api-error";
2
- export { ApiPromise, EventSourceResponse } from "./api-promise";
3
- export { AuthBasic, AuthBearer, AuthKey, AuthProvider, OAuth2, OAuth2ClientCredentials, OAuth2Password, } from "./auth";
4
- export { BinaryResponse } from "./binary-response";
5
- export { ApiResponse, CoreClient, CoreClientProps, ResourceClientOptions, CoreResourceClient, RequestOptions, } from "./core-client";
6
- export { createForm, isUploadFile, UploadFile } from "./form-data";
7
- export { encodeQueryParam } from "./query";
8
- export { RUNTIME } from "./runtime";
9
- export { zodRequiredAny, zodTransform, zodUploadFile } from "./zod";
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.zodUploadFile = exports.zodTransform = exports.zodRequiredAny = exports.RUNTIME = exports.encodeQueryParam = exports.isUploadFile = exports.createForm = exports.CoreResourceClient = exports.CoreClient = exports.BinaryResponse = exports.OAuth2 = exports.AuthKey = exports.AuthBearer = exports.AuthBasic = exports.ApiPromise = exports.ApiError = void 0;
4
- var api_error_1 = require("./api-error");
5
- Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return api_error_1.ApiError; } });
6
- var api_promise_1 = require("./api-promise");
7
- Object.defineProperty(exports, "ApiPromise", { enumerable: true, get: function () { return api_promise_1.ApiPromise; } });
8
- var auth_1 = require("./auth");
9
- Object.defineProperty(exports, "AuthBasic", { enumerable: true, get: function () { return auth_1.AuthBasic; } });
10
- Object.defineProperty(exports, "AuthBearer", { enumerable: true, get: function () { return auth_1.AuthBearer; } });
11
- Object.defineProperty(exports, "AuthKey", { enumerable: true, get: function () { return auth_1.AuthKey; } });
12
- Object.defineProperty(exports, "OAuth2", { enumerable: true, get: function () { return auth_1.OAuth2; } });
13
- var binary_response_1 = require("./binary-response");
14
- Object.defineProperty(exports, "BinaryResponse", { enumerable: true, get: function () { return binary_response_1.BinaryResponse; } });
15
- var core_client_1 = require("./core-client");
16
- Object.defineProperty(exports, "CoreClient", { enumerable: true, get: function () { return core_client_1.CoreClient; } });
17
- Object.defineProperty(exports, "CoreResourceClient", { enumerable: true, get: function () { return core_client_1.CoreResourceClient; } });
18
- var form_data_1 = require("./form-data");
19
- Object.defineProperty(exports, "createForm", { enumerable: true, get: function () { return form_data_1.createForm; } });
20
- Object.defineProperty(exports, "isUploadFile", { enumerable: true, get: function () { return form_data_1.isUploadFile; } });
21
- var query_1 = require("./query");
22
- Object.defineProperty(exports, "encodeQueryParam", { enumerable: true, get: function () { return query_1.encodeQueryParam; } });
23
- var runtime_1 = require("./runtime");
24
- Object.defineProperty(exports, "RUNTIME", { enumerable: true, get: function () { return runtime_1.RUNTIME; } });
25
- var zod_1 = require("./zod");
26
- Object.defineProperty(exports, "zodRequiredAny", { enumerable: true, get: function () { return zod_1.zodRequiredAny; } });
27
- Object.defineProperty(exports, "zodTransform", { enumerable: true, get: function () { return zod_1.zodTransform; } });
28
- Object.defineProperty(exports, "zodUploadFile", { enumerable: true, get: function () { return zod_1.zodUploadFile; } });
@@ -1,8 +0,0 @@
1
- export type QueryStyle = "form" | "spaceDelimited" | "pipeDelimited" | "deepObject";
2
- export interface EncodeQueryParamProps {
3
- name: string;
4
- value: any;
5
- style: QueryStyle;
6
- explode: boolean;
7
- }
8
- export declare function encodeQueryParam({ name, value, style, explode, }: EncodeQueryParamProps): string;