transloadit 3.0.2 → 4.0.0-4

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 (477) hide show
  1. package/CHANGELOG.md +9 -12
  2. package/README.md +175 -129
  3. package/dist/ApiError.d.ts +20 -0
  4. package/dist/ApiError.d.ts.map +1 -0
  5. package/dist/ApiError.js +35 -0
  6. package/dist/ApiError.js.map +1 -0
  7. package/dist/InconsistentResponseError.d.ts +4 -0
  8. package/dist/InconsistentResponseError.d.ts.map +1 -0
  9. package/dist/InconsistentResponseError.js +7 -0
  10. package/dist/InconsistentResponseError.js.map +1 -0
  11. package/dist/PaginationStream.d.ts +14 -0
  12. package/dist/PaginationStream.d.ts.map +1 -0
  13. package/dist/PaginationStream.js +39 -0
  14. package/dist/PaginationStream.js.map +1 -0
  15. package/dist/PollingTimeoutError.d.ts +5 -0
  16. package/dist/PollingTimeoutError.d.ts.map +1 -0
  17. package/dist/PollingTimeoutError.js +8 -0
  18. package/dist/PollingTimeoutError.js.map +1 -0
  19. package/dist/Transloadit.d.ts +227 -0
  20. package/dist/Transloadit.d.ts.map +1 -0
  21. package/dist/Transloadit.js +628 -0
  22. package/dist/Transloadit.js.map +1 -0
  23. package/dist/alphalib/types/assemblyStatus.d.ts +6208 -0
  24. package/dist/alphalib/types/assemblyStatus.d.ts.map +1 -0
  25. package/dist/alphalib/types/assemblyStatus.js +285 -0
  26. package/dist/alphalib/types/assemblyStatus.js.map +1 -0
  27. package/dist/alphalib/types/robots/_index.d.ts +56966 -0
  28. package/dist/alphalib/types/robots/_index.d.ts.map +1 -0
  29. package/dist/alphalib/types/robots/_index.js +347 -0
  30. package/dist/alphalib/types/robots/_index.js.map +1 -0
  31. package/dist/alphalib/types/robots/_instructions-primitives.d.ts +2157 -0
  32. package/dist/alphalib/types/robots/_instructions-primitives.d.ts.map +1 -0
  33. package/dist/alphalib/types/robots/_instructions-primitives.js +655 -0
  34. package/dist/alphalib/types/robots/_instructions-primitives.js.map +1 -0
  35. package/dist/alphalib/types/robots/audio-artwork.d.ts +628 -0
  36. package/dist/alphalib/types/robots/audio-artwork.d.ts.map +1 -0
  37. package/dist/alphalib/types/robots/audio-artwork.js +55 -0
  38. package/dist/alphalib/types/robots/audio-artwork.js.map +1 -0
  39. package/dist/alphalib/types/robots/audio-concat.d.ts +632 -0
  40. package/dist/alphalib/types/robots/audio-concat.d.ts.map +1 -0
  41. package/dist/alphalib/types/robots/audio-concat.js +66 -0
  42. package/dist/alphalib/types/robots/audio-concat.js.map +1 -0
  43. package/dist/alphalib/types/robots/audio-encode.d.ts +629 -0
  44. package/dist/alphalib/types/robots/audio-encode.d.ts.map +1 -0
  45. package/dist/alphalib/types/robots/audio-encode.js +55 -0
  46. package/dist/alphalib/types/robots/audio-encode.js.map +1 -0
  47. package/dist/alphalib/types/robots/audio-loop.d.ts +631 -0
  48. package/dist/alphalib/types/robots/audio-loop.d.ts.map +1 -0
  49. package/dist/alphalib/types/robots/audio-loop.js +54 -0
  50. package/dist/alphalib/types/robots/audio-loop.js.map +1 -0
  51. package/dist/alphalib/types/robots/audio-merge.d.ts +637 -0
  52. package/dist/alphalib/types/robots/audio-merge.d.ts.map +1 -0
  53. package/dist/alphalib/types/robots/audio-merge.js +65 -0
  54. package/dist/alphalib/types/robots/audio-merge.js.map +1 -0
  55. package/dist/alphalib/types/robots/audio-waveform.d.ts +642 -0
  56. package/dist/alphalib/types/robots/audio-waveform.d.ts.map +1 -0
  57. package/dist/alphalib/types/robots/audio-waveform.js +80 -0
  58. package/dist/alphalib/types/robots/audio-waveform.js.map +1 -0
  59. package/dist/alphalib/types/robots/azure-import.d.ts +46 -0
  60. package/dist/alphalib/types/robots/azure-import.d.ts.map +1 -0
  61. package/dist/alphalib/types/robots/azure-import.js +58 -0
  62. package/dist/alphalib/types/robots/azure-import.js.map +1 -0
  63. package/dist/alphalib/types/robots/azure-store.d.ts +129 -0
  64. package/dist/alphalib/types/robots/azure-store.d.ts.map +1 -0
  65. package/dist/alphalib/types/robots/azure-store.js +73 -0
  66. package/dist/alphalib/types/robots/azure-store.js.map +1 -0
  67. package/dist/alphalib/types/robots/backblaze-import.d.ts +49 -0
  68. package/dist/alphalib/types/robots/backblaze-import.d.ts.map +1 -0
  69. package/dist/alphalib/types/robots/backblaze-import.js +66 -0
  70. package/dist/alphalib/types/robots/backblaze-import.js.map +1 -0
  71. package/dist/alphalib/types/robots/backblaze-store.d.ts +111 -0
  72. package/dist/alphalib/types/robots/backblaze-store.d.ts.map +1 -0
  73. package/dist/alphalib/types/robots/backblaze-store.js +58 -0
  74. package/dist/alphalib/types/robots/backblaze-store.js.map +1 -0
  75. package/dist/alphalib/types/robots/cloudfiles-import.d.ts +55 -0
  76. package/dist/alphalib/types/robots/cloudfiles-import.d.ts.map +1 -0
  77. package/dist/alphalib/types/robots/cloudfiles-import.js +65 -0
  78. package/dist/alphalib/types/robots/cloudfiles-import.js.map +1 -0
  79. package/dist/alphalib/types/robots/cloudfiles-store.d.ts +114 -0
  80. package/dist/alphalib/types/robots/cloudfiles-store.d.ts.map +1 -0
  81. package/dist/alphalib/types/robots/cloudfiles-store.js +56 -0
  82. package/dist/alphalib/types/robots/cloudfiles-store.js.map +1 -0
  83. package/dist/alphalib/types/robots/cloudflare-import.d.ts +52 -0
  84. package/dist/alphalib/types/robots/cloudflare-import.d.ts.map +1 -0
  85. package/dist/alphalib/types/robots/cloudflare-import.js +68 -0
  86. package/dist/alphalib/types/robots/cloudflare-import.js.map +1 -0
  87. package/dist/alphalib/types/robots/cloudflare-store.d.ts +117 -0
  88. package/dist/alphalib/types/robots/cloudflare-store.d.ts.map +1 -0
  89. package/dist/alphalib/types/robots/cloudflare-store.js +57 -0
  90. package/dist/alphalib/types/robots/cloudflare-store.js.map +1 -0
  91. package/dist/alphalib/types/robots/digitalocean-import.d.ts +52 -0
  92. package/dist/alphalib/types/robots/digitalocean-import.d.ts.map +1 -0
  93. package/dist/alphalib/types/robots/digitalocean-import.js +65 -0
  94. package/dist/alphalib/types/robots/digitalocean-import.js.map +1 -0
  95. package/dist/alphalib/types/robots/digitalocean-store.d.ts +123 -0
  96. package/dist/alphalib/types/robots/digitalocean-store.d.ts.map +1 -0
  97. package/dist/alphalib/types/robots/digitalocean-store.js +62 -0
  98. package/dist/alphalib/types/robots/digitalocean-store.js.map +1 -0
  99. package/dist/alphalib/types/robots/document-autorotate.d.ts +91 -0
  100. package/dist/alphalib/types/robots/document-autorotate.d.ts.map +1 -0
  101. package/dist/alphalib/types/robots/document-autorotate.js +31 -0
  102. package/dist/alphalib/types/robots/document-autorotate.js.map +1 -0
  103. package/dist/alphalib/types/robots/document-convert.d.ts +118 -0
  104. package/dist/alphalib/types/robots/document-convert.d.ts.map +1 -0
  105. package/dist/alphalib/types/robots/document-convert.js +182 -0
  106. package/dist/alphalib/types/robots/document-convert.js.map +1 -0
  107. package/dist/alphalib/types/robots/document-merge.d.ts +97 -0
  108. package/dist/alphalib/types/robots/document-merge.d.ts.map +1 -0
  109. package/dist/alphalib/types/robots/document-merge.js +66 -0
  110. package/dist/alphalib/types/robots/document-merge.js.map +1 -0
  111. package/dist/alphalib/types/robots/document-ocr.d.ts +100 -0
  112. package/dist/alphalib/types/robots/document-ocr.d.ts.map +1 -0
  113. package/dist/alphalib/types/robots/document-ocr.js +65 -0
  114. package/dist/alphalib/types/robots/document-ocr.js.map +1 -0
  115. package/dist/alphalib/types/robots/document-split.d.ts +94 -0
  116. package/dist/alphalib/types/robots/document-split.d.ts.map +1 -0
  117. package/dist/alphalib/types/robots/document-split.js +34 -0
  118. package/dist/alphalib/types/robots/document-split.js.map +1 -0
  119. package/dist/alphalib/types/robots/document-thumbs.d.ts +134 -0
  120. package/dist/alphalib/types/robots/document-thumbs.d.ts.map +1 -0
  121. package/dist/alphalib/types/robots/document-thumbs.js +111 -0
  122. package/dist/alphalib/types/robots/document-thumbs.js.map +1 -0
  123. package/dist/alphalib/types/robots/dropbox-import.d.ts +43 -0
  124. package/dist/alphalib/types/robots/dropbox-import.d.ts.map +1 -0
  125. package/dist/alphalib/types/robots/dropbox-import.js +52 -0
  126. package/dist/alphalib/types/robots/dropbox-import.js.map +1 -0
  127. package/dist/alphalib/types/robots/dropbox-store.d.ts +114 -0
  128. package/dist/alphalib/types/robots/dropbox-store.d.ts.map +1 -0
  129. package/dist/alphalib/types/robots/dropbox-store.js +49 -0
  130. package/dist/alphalib/types/robots/dropbox-store.js.map +1 -0
  131. package/dist/alphalib/types/robots/edgly-deliver.d.ts +19 -0
  132. package/dist/alphalib/types/robots/edgly-deliver.d.ts.map +1 -0
  133. package/dist/alphalib/types/robots/edgly-deliver.js +31 -0
  134. package/dist/alphalib/types/robots/edgly-deliver.js.map +1 -0
  135. package/dist/alphalib/types/robots/file-compress.d.ts +106 -0
  136. package/dist/alphalib/types/robots/file-compress.d.ts.map +1 -0
  137. package/dist/alphalib/types/robots/file-compress.js +102 -0
  138. package/dist/alphalib/types/robots/file-compress.js.map +1 -0
  139. package/dist/alphalib/types/robots/file-decompress.d.ts +94 -0
  140. package/dist/alphalib/types/robots/file-decompress.d.ts.map +1 -0
  141. package/dist/alphalib/types/robots/file-decompress.js +81 -0
  142. package/dist/alphalib/types/robots/file-decompress.js.map +1 -0
  143. package/dist/alphalib/types/robots/file-filter.d.ts +107 -0
  144. package/dist/alphalib/types/robots/file-filter.d.ts.map +1 -0
  145. package/dist/alphalib/types/robots/file-filter.js +108 -0
  146. package/dist/alphalib/types/robots/file-filter.js.map +1 -0
  147. package/dist/alphalib/types/robots/file-hash.d.ts +94 -0
  148. package/dist/alphalib/types/robots/file-hash.d.ts.map +1 -0
  149. package/dist/alphalib/types/robots/file-hash.js +49 -0
  150. package/dist/alphalib/types/robots/file-hash.js.map +1 -0
  151. package/dist/alphalib/types/robots/file-preview.d.ts +393 -0
  152. package/dist/alphalib/types/robots/file-preview.d.ts.map +1 -0
  153. package/dist/alphalib/types/robots/file-preview.js +155 -0
  154. package/dist/alphalib/types/robots/file-preview.js.map +1 -0
  155. package/dist/alphalib/types/robots/file-read.d.ts +91 -0
  156. package/dist/alphalib/types/robots/file-read.d.ts.map +1 -0
  157. package/dist/alphalib/types/robots/file-read.js +34 -0
  158. package/dist/alphalib/types/robots/file-read.js.map +1 -0
  159. package/dist/alphalib/types/robots/file-serve.d.ts +95 -0
  160. package/dist/alphalib/types/robots/file-serve.d.ts.map +1 -0
  161. package/dist/alphalib/types/robots/file-serve.js +56 -0
  162. package/dist/alphalib/types/robots/file-serve.js.map +1 -0
  163. package/dist/alphalib/types/robots/file-verify.d.ts +100 -0
  164. package/dist/alphalib/types/robots/file-verify.d.ts.map +1 -0
  165. package/dist/alphalib/types/robots/file-verify.js +52 -0
  166. package/dist/alphalib/types/robots/file-verify.js.map +1 -0
  167. package/dist/alphalib/types/robots/file-virusscan.d.ts +97 -0
  168. package/dist/alphalib/types/robots/file-virusscan.d.ts.map +1 -0
  169. package/dist/alphalib/types/robots/file-virusscan.js +55 -0
  170. package/dist/alphalib/types/robots/file-virusscan.js.map +1 -0
  171. package/dist/alphalib/types/robots/file-watermark.d.ts +92 -0
  172. package/dist/alphalib/types/robots/file-watermark.d.ts.map +1 -0
  173. package/dist/alphalib/types/robots/file-watermark.js +13 -0
  174. package/dist/alphalib/types/robots/file-watermark.js.map +1 -0
  175. package/dist/alphalib/types/robots/ftp-import.d.ts +46 -0
  176. package/dist/alphalib/types/robots/ftp-import.d.ts.map +1 -0
  177. package/dist/alphalib/types/robots/ftp-import.js +47 -0
  178. package/dist/alphalib/types/robots/ftp-import.js.map +1 -0
  179. package/dist/alphalib/types/robots/ftp-store.d.ts +120 -0
  180. package/dist/alphalib/types/robots/ftp-store.d.ts.map +1 -0
  181. package/dist/alphalib/types/robots/ftp-store.js +57 -0
  182. package/dist/alphalib/types/robots/ftp-store.js.map +1 -0
  183. package/dist/alphalib/types/robots/google-import.d.ts +40 -0
  184. package/dist/alphalib/types/robots/google-import.d.ts.map +1 -0
  185. package/dist/alphalib/types/robots/google-import.js +65 -0
  186. package/dist/alphalib/types/robots/google-import.js.map +1 -0
  187. package/dist/alphalib/types/robots/google-store.d.ts +113 -0
  188. package/dist/alphalib/types/robots/google-store.d.ts.map +1 -0
  189. package/dist/alphalib/types/robots/google-store.js +86 -0
  190. package/dist/alphalib/types/robots/google-store.js.map +1 -0
  191. package/dist/alphalib/types/robots/html-convert.d.ts +115 -0
  192. package/dist/alphalib/types/robots/html-convert.d.ts.map +1 -0
  193. package/dist/alphalib/types/robots/html-convert.js +81 -0
  194. package/dist/alphalib/types/robots/html-convert.js.map +1 -0
  195. package/dist/alphalib/types/robots/http-import.d.ts +42 -0
  196. package/dist/alphalib/types/robots/http-import.d.ts.map +1 -0
  197. package/dist/alphalib/types/robots/http-import.js +76 -0
  198. package/dist/alphalib/types/robots/http-import.js.map +1 -0
  199. package/dist/alphalib/types/robots/image-describe.d.ts +103 -0
  200. package/dist/alphalib/types/robots/image-describe.d.ts.map +1 -0
  201. package/dist/alphalib/types/robots/image-describe.js +66 -0
  202. package/dist/alphalib/types/robots/image-describe.js.map +1 -0
  203. package/dist/alphalib/types/robots/image-facedetect.d.ts +109 -0
  204. package/dist/alphalib/types/robots/image-facedetect.d.ts.map +1 -0
  205. package/dist/alphalib/types/robots/image-facedetect.js +125 -0
  206. package/dist/alphalib/types/robots/image-facedetect.js.map +1 -0
  207. package/dist/alphalib/types/robots/image-generate.d.ts +229 -0
  208. package/dist/alphalib/types/robots/image-generate.d.ts.map +1 -0
  209. package/dist/alphalib/types/robots/image-generate.js +27 -0
  210. package/dist/alphalib/types/robots/image-generate.js.map +1 -0
  211. package/dist/alphalib/types/robots/image-merge.d.ts +109 -0
  212. package/dist/alphalib/types/robots/image-merge.d.ts.map +1 -0
  213. package/dist/alphalib/types/robots/image-merge.js +74 -0
  214. package/dist/alphalib/types/robots/image-merge.js.map +1 -0
  215. package/dist/alphalib/types/robots/image-ocr.d.ts +100 -0
  216. package/dist/alphalib/types/robots/image-ocr.d.ts.map +1 -0
  217. package/dist/alphalib/types/robots/image-ocr.js +64 -0
  218. package/dist/alphalib/types/robots/image-ocr.js.map +1 -0
  219. package/dist/alphalib/types/robots/image-optimize.d.ts +103 -0
  220. package/dist/alphalib/types/robots/image-optimize.d.ts.map +1 -0
  221. package/dist/alphalib/types/robots/image-optimize.js +60 -0
  222. package/dist/alphalib/types/robots/image-optimize.js.map +1 -0
  223. package/dist/alphalib/types/robots/image-remove-background.d.ts +98 -0
  224. package/dist/alphalib/types/robots/image-remove-background.d.ts.map +1 -0
  225. package/dist/alphalib/types/robots/image-remove-background.js +21 -0
  226. package/dist/alphalib/types/robots/image-remove-background.js.map +1 -0
  227. package/dist/alphalib/types/robots/image-resize.d.ts +696 -0
  228. package/dist/alphalib/types/robots/image-resize.d.ts.map +1 -0
  229. package/dist/alphalib/types/robots/image-resize.js +364 -0
  230. package/dist/alphalib/types/robots/image-resize.js.map +1 -0
  231. package/dist/alphalib/types/robots/media-playlist.d.ts +115 -0
  232. package/dist/alphalib/types/robots/media-playlist.d.ts.map +1 -0
  233. package/dist/alphalib/types/robots/media-playlist.js +56 -0
  234. package/dist/alphalib/types/robots/media-playlist.js.map +1 -0
  235. package/dist/alphalib/types/robots/meta-write.d.ts +623 -0
  236. package/dist/alphalib/types/robots/meta-write.d.ts.map +1 -0
  237. package/dist/alphalib/types/robots/meta-write.js +53 -0
  238. package/dist/alphalib/types/robots/meta-write.js.map +1 -0
  239. package/dist/alphalib/types/robots/minio-import.d.ts +52 -0
  240. package/dist/alphalib/types/robots/minio-import.d.ts.map +1 -0
  241. package/dist/alphalib/types/robots/minio-import.js +68 -0
  242. package/dist/alphalib/types/robots/minio-import.js.map +1 -0
  243. package/dist/alphalib/types/robots/minio-store.d.ts +120 -0
  244. package/dist/alphalib/types/robots/minio-store.d.ts.map +1 -0
  245. package/dist/alphalib/types/robots/minio-store.js +61 -0
  246. package/dist/alphalib/types/robots/minio-store.js.map +1 -0
  247. package/dist/alphalib/types/robots/progress-simulate.d.ts +29 -0
  248. package/dist/alphalib/types/robots/progress-simulate.d.ts.map +1 -0
  249. package/dist/alphalib/types/robots/progress-simulate.js +15 -0
  250. package/dist/alphalib/types/robots/progress-simulate.js.map +1 -0
  251. package/dist/alphalib/types/robots/s3-import.d.ts +52 -0
  252. package/dist/alphalib/types/robots/s3-import.d.ts.map +1 -0
  253. package/dist/alphalib/types/robots/s3-import.js +104 -0
  254. package/dist/alphalib/types/robots/s3-import.js.map +1 -0
  255. package/dist/alphalib/types/robots/s3-store.d.ts +135 -0
  256. package/dist/alphalib/types/robots/s3-store.d.ts.map +1 -0
  257. package/dist/alphalib/types/robots/s3-store.js +118 -0
  258. package/dist/alphalib/types/robots/s3-store.js.map +1 -0
  259. package/dist/alphalib/types/robots/script-run.d.ts +94 -0
  260. package/dist/alphalib/types/robots/script-run.d.ts.map +1 -0
  261. package/dist/alphalib/types/robots/script-run.js +79 -0
  262. package/dist/alphalib/types/robots/script-run.js.map +1 -0
  263. package/dist/alphalib/types/robots/sftp-import.d.ts +43 -0
  264. package/dist/alphalib/types/robots/sftp-import.d.ts.map +1 -0
  265. package/dist/alphalib/types/robots/sftp-import.js +45 -0
  266. package/dist/alphalib/types/robots/sftp-import.js.map +1 -0
  267. package/dist/alphalib/types/robots/sftp-store.d.ts +120 -0
  268. package/dist/alphalib/types/robots/sftp-store.d.ts.map +1 -0
  269. package/dist/alphalib/types/robots/sftp-store.js +58 -0
  270. package/dist/alphalib/types/robots/sftp-store.js.map +1 -0
  271. package/dist/alphalib/types/robots/speech-transcribe.d.ts +210 -0
  272. package/dist/alphalib/types/robots/speech-transcribe.d.ts.map +1 -0
  273. package/dist/alphalib/types/robots/speech-transcribe.js +80 -0
  274. package/dist/alphalib/types/robots/speech-transcribe.js.map +1 -0
  275. package/dist/alphalib/types/robots/supabase-import.d.ts +52 -0
  276. package/dist/alphalib/types/robots/supabase-import.d.ts.map +1 -0
  277. package/dist/alphalib/types/robots/supabase-import.js +70 -0
  278. package/dist/alphalib/types/robots/supabase-import.js.map +1 -0
  279. package/dist/alphalib/types/robots/supabase-store.d.ts +117 -0
  280. package/dist/alphalib/types/robots/supabase-store.d.ts.map +1 -0
  281. package/dist/alphalib/types/robots/supabase-store.js +54 -0
  282. package/dist/alphalib/types/robots/supabase-store.js.map +1 -0
  283. package/dist/alphalib/types/robots/swift-import.d.ts +52 -0
  284. package/dist/alphalib/types/robots/swift-import.d.ts.map +1 -0
  285. package/dist/alphalib/types/robots/swift-import.js +68 -0
  286. package/dist/alphalib/types/robots/swift-import.js.map +1 -0
  287. package/dist/alphalib/types/robots/swift-store.d.ts +120 -0
  288. package/dist/alphalib/types/robots/swift-store.d.ts.map +1 -0
  289. package/dist/alphalib/types/robots/swift-store.js +58 -0
  290. package/dist/alphalib/types/robots/swift-store.js.map +1 -0
  291. package/dist/alphalib/types/robots/text-speak.d.ts +106 -0
  292. package/dist/alphalib/types/robots/text-speak.d.ts.map +1 -0
  293. package/dist/alphalib/types/robots/text-speak.js +97 -0
  294. package/dist/alphalib/types/robots/text-speak.js.map +1 -0
  295. package/dist/alphalib/types/robots/text-translate.d.ts +100 -0
  296. package/dist/alphalib/types/robots/text-translate.d.ts.map +1 -0
  297. package/dist/alphalib/types/robots/text-translate.js +196 -0
  298. package/dist/alphalib/types/robots/text-translate.js.map +1 -0
  299. package/dist/alphalib/types/robots/tigris-import.d.ts +52 -0
  300. package/dist/alphalib/types/robots/tigris-import.d.ts.map +1 -0
  301. package/dist/alphalib/types/robots/tigris-import.js +68 -0
  302. package/dist/alphalib/types/robots/tigris-import.js.map +1 -0
  303. package/dist/alphalib/types/robots/tigris-store.d.ts +120 -0
  304. package/dist/alphalib/types/robots/tigris-store.d.ts.map +1 -0
  305. package/dist/alphalib/types/robots/tigris-store.js +61 -0
  306. package/dist/alphalib/types/robots/tigris-store.js.map +1 -0
  307. package/dist/alphalib/types/robots/tlcdn-deliver.d.ts +19 -0
  308. package/dist/alphalib/types/robots/tlcdn-deliver.d.ts.map +1 -0
  309. package/dist/alphalib/types/robots/tlcdn-deliver.js +31 -0
  310. package/dist/alphalib/types/robots/tlcdn-deliver.js.map +1 -0
  311. package/dist/alphalib/types/robots/tus-store.d.ts +110 -0
  312. package/dist/alphalib/types/robots/tus-store.d.ts.map +1 -0
  313. package/dist/alphalib/types/robots/tus-store.js +74 -0
  314. package/dist/alphalib/types/robots/tus-store.js.map +1 -0
  315. package/dist/alphalib/types/robots/upload-handle.d.ts +92 -0
  316. package/dist/alphalib/types/robots/upload-handle.d.ts.map +1 -0
  317. package/dist/alphalib/types/robots/upload-handle.js +54 -0
  318. package/dist/alphalib/types/robots/upload-handle.js.map +1 -0
  319. package/dist/alphalib/types/robots/video-adaptive.d.ts +640 -0
  320. package/dist/alphalib/types/robots/video-adaptive.d.ts.map +1 -0
  321. package/dist/alphalib/types/robots/video-adaptive.js +119 -0
  322. package/dist/alphalib/types/robots/video-adaptive.js.map +1 -0
  323. package/dist/alphalib/types/robots/video-concat.d.ts +634 -0
  324. package/dist/alphalib/types/robots/video-concat.d.ts.map +1 -0
  325. package/dist/alphalib/types/robots/video-concat.js +65 -0
  326. package/dist/alphalib/types/robots/video-concat.js.map +1 -0
  327. package/dist/alphalib/types/robots/video-encode.d.ts +1439 -0
  328. package/dist/alphalib/types/robots/video-encode.d.ts.map +1 -0
  329. package/dist/alphalib/types/robots/video-encode.js +157 -0
  330. package/dist/alphalib/types/robots/video-encode.js.map +1 -0
  331. package/dist/alphalib/types/robots/video-merge.d.ts +655 -0
  332. package/dist/alphalib/types/robots/video-merge.d.ts.map +1 -0
  333. package/dist/alphalib/types/robots/video-merge.js +64 -0
  334. package/dist/alphalib/types/robots/video-merge.js.map +1 -0
  335. package/dist/alphalib/types/robots/video-subtitle.d.ts +649 -0
  336. package/dist/alphalib/types/robots/video-subtitle.d.ts.map +1 -0
  337. package/dist/alphalib/types/robots/video-subtitle.js +77 -0
  338. package/dist/alphalib/types/robots/video-subtitle.js.map +1 -0
  339. package/dist/alphalib/types/robots/video-thumbs.d.ts +642 -0
  340. package/dist/alphalib/types/robots/video-thumbs.d.ts.map +1 -0
  341. package/dist/alphalib/types/robots/video-thumbs.js +79 -0
  342. package/dist/alphalib/types/robots/video-thumbs.js.map +1 -0
  343. package/dist/alphalib/types/robots/vimeo-store.d.ts +116 -0
  344. package/dist/alphalib/types/robots/vimeo-store.d.ts.map +1 -0
  345. package/dist/alphalib/types/robots/vimeo-store.js +81 -0
  346. package/dist/alphalib/types/robots/vimeo-store.js.map +1 -0
  347. package/dist/alphalib/types/robots/wasabi-import.d.ts +53 -0
  348. package/dist/alphalib/types/robots/wasabi-import.d.ts.map +1 -0
  349. package/dist/alphalib/types/robots/wasabi-import.js +72 -0
  350. package/dist/alphalib/types/robots/wasabi-import.js.map +1 -0
  351. package/dist/alphalib/types/robots/wasabi-store.d.ts +120 -0
  352. package/dist/alphalib/types/robots/wasabi-store.d.ts.map +1 -0
  353. package/dist/alphalib/types/robots/wasabi-store.js +59 -0
  354. package/dist/alphalib/types/robots/wasabi-store.js.map +1 -0
  355. package/dist/alphalib/types/robots/youtube-store.d.ts +110 -0
  356. package/dist/alphalib/types/robots/youtube-store.d.ts.map +1 -0
  357. package/dist/alphalib/types/robots/youtube-store.js +105 -0
  358. package/dist/alphalib/types/robots/youtube-store.js.map +1 -0
  359. package/dist/alphalib/types/stackVersions.d.ts +13 -0
  360. package/dist/alphalib/types/stackVersions.d.ts.map +1 -0
  361. package/dist/alphalib/types/stackVersions.js +16 -0
  362. package/dist/alphalib/types/stackVersions.js.map +1 -0
  363. package/dist/alphalib/types/template.d.ts +77150 -0
  364. package/dist/alphalib/types/template.d.ts.map +1 -0
  365. package/dist/alphalib/types/template.js +49 -0
  366. package/dist/alphalib/types/template.js.map +1 -0
  367. package/dist/alphalib/zodParseWithContext.d.ts +18 -0
  368. package/dist/alphalib/zodParseWithContext.d.ts.map +1 -0
  369. package/dist/alphalib/zodParseWithContext.js +123 -0
  370. package/dist/alphalib/zodParseWithContext.js.map +1 -0
  371. package/dist/apiTypes.d.ts +127 -0
  372. package/dist/apiTypes.d.ts.map +1 -0
  373. package/dist/apiTypes.js +3 -0
  374. package/dist/apiTypes.js.map +1 -0
  375. package/dist/tus.d.ts +17 -0
  376. package/dist/tus.d.ts.map +1 -0
  377. package/dist/tus.js +88 -0
  378. package/dist/tus.js.map +1 -0
  379. package/package.json +58 -39
  380. package/src/ApiError.ts +44 -0
  381. package/src/InconsistentResponseError.ts +3 -0
  382. package/src/PaginationStream.ts +55 -0
  383. package/src/PollingTimeoutError.ts +5 -0
  384. package/src/Transloadit.ts +826 -0
  385. package/src/alphalib/types/assemblyStatus.ts +300 -0
  386. package/src/alphalib/types/robots/_index.ts +437 -0
  387. package/src/alphalib/types/robots/_instructions-primitives.ts +835 -0
  388. package/src/alphalib/types/robots/audio-artwork.ts +57 -0
  389. package/src/alphalib/types/robots/audio-concat.ts +74 -0
  390. package/src/alphalib/types/robots/audio-encode.ts +63 -0
  391. package/src/alphalib/types/robots/audio-loop.ts +62 -0
  392. package/src/alphalib/types/robots/audio-merge.ts +73 -0
  393. package/src/alphalib/types/robots/audio-waveform.ts +83 -0
  394. package/src/alphalib/types/robots/azure-import.ts +69 -0
  395. package/src/alphalib/types/robots/azure-store.ts +76 -0
  396. package/src/alphalib/types/robots/backblaze-import.ts +81 -0
  397. package/src/alphalib/types/robots/backblaze-store.ts +63 -0
  398. package/src/alphalib/types/robots/cloudfiles-import.ts +80 -0
  399. package/src/alphalib/types/robots/cloudfiles-store.ts +63 -0
  400. package/src/alphalib/types/robots/cloudflare-import.ts +84 -0
  401. package/src/alphalib/types/robots/cloudflare-store.ts +64 -0
  402. package/src/alphalib/types/robots/digitalocean-import.ts +81 -0
  403. package/src/alphalib/types/robots/digitalocean-store.ts +69 -0
  404. package/src/alphalib/types/robots/document-autorotate.ts +36 -0
  405. package/src/alphalib/types/robots/document-convert.ts +186 -0
  406. package/src/alphalib/types/robots/document-merge.ts +68 -0
  407. package/src/alphalib/types/robots/document-ocr.ts +72 -0
  408. package/src/alphalib/types/robots/document-split.ts +38 -0
  409. package/src/alphalib/types/robots/document-thumbs.ts +119 -0
  410. package/src/alphalib/types/robots/dropbox-import.ts +58 -0
  411. package/src/alphalib/types/robots/dropbox-store.ts +52 -0
  412. package/src/alphalib/types/robots/edgly-deliver.ts +32 -0
  413. package/src/alphalib/types/robots/file-compress.ts +104 -0
  414. package/src/alphalib/types/robots/file-decompress.ts +86 -0
  415. package/src/alphalib/types/robots/file-filter.ts +115 -0
  416. package/src/alphalib/types/robots/file-hash.ts +51 -0
  417. package/src/alphalib/types/robots/file-preview.ts +174 -0
  418. package/src/alphalib/types/robots/file-read.ts +36 -0
  419. package/src/alphalib/types/robots/file-serve.ts +60 -0
  420. package/src/alphalib/types/robots/file-verify.ts +55 -0
  421. package/src/alphalib/types/robots/file-virusscan.ts +60 -0
  422. package/src/alphalib/types/robots/file-watermark.ts +13 -0
  423. package/src/alphalib/types/robots/ftp-import.ts +52 -0
  424. package/src/alphalib/types/robots/ftp-store.ts +61 -0
  425. package/src/alphalib/types/robots/google-import.ts +77 -0
  426. package/src/alphalib/types/robots/google-store.ts +89 -0
  427. package/src/alphalib/types/robots/html-convert.ts +83 -0
  428. package/src/alphalib/types/robots/http-import.ts +79 -0
  429. package/src/alphalib/types/robots/image-describe.ts +74 -0
  430. package/src/alphalib/types/robots/image-facedetect.ts +131 -0
  431. package/src/alphalib/types/robots/image-generate.ts +32 -0
  432. package/src/alphalib/types/robots/image-merge.ts +81 -0
  433. package/src/alphalib/types/robots/image-ocr.ts +71 -0
  434. package/src/alphalib/types/robots/image-optimize.ts +61 -0
  435. package/src/alphalib/types/robots/image-remove-background.ts +23 -0
  436. package/src/alphalib/types/robots/image-resize.ts +401 -0
  437. package/src/alphalib/types/robots/media-playlist.ts +58 -0
  438. package/src/alphalib/types/robots/meta-write.ts +55 -0
  439. package/src/alphalib/types/robots/minio-import.ts +80 -0
  440. package/src/alphalib/types/robots/minio-store.ts +64 -0
  441. package/src/alphalib/types/robots/progress-simulate.ts +16 -0
  442. package/src/alphalib/types/robots/s3-import.ts +116 -0
  443. package/src/alphalib/types/robots/s3-store.ts +121 -0
  444. package/src/alphalib/types/robots/script-run.ts +81 -0
  445. package/src/alphalib/types/robots/sftp-import.ts +50 -0
  446. package/src/alphalib/types/robots/sftp-store.ts +61 -0
  447. package/src/alphalib/types/robots/speech-transcribe.ts +96 -0
  448. package/src/alphalib/types/robots/supabase-import.ts +84 -0
  449. package/src/alphalib/types/robots/supabase-store.ts +59 -0
  450. package/src/alphalib/types/robots/swift-import.ts +80 -0
  451. package/src/alphalib/types/robots/swift-store.ts +61 -0
  452. package/src/alphalib/types/robots/text-speak.ts +100 -0
  453. package/src/alphalib/types/robots/text-translate.ts +199 -0
  454. package/src/alphalib/types/robots/tigris-import.ts +80 -0
  455. package/src/alphalib/types/robots/tigris-store.ts +64 -0
  456. package/src/alphalib/types/robots/tlcdn-deliver.ts +32 -0
  457. package/src/alphalib/types/robots/tus-store.ts +77 -0
  458. package/src/alphalib/types/robots/upload-handle.ts +58 -0
  459. package/src/alphalib/types/robots/video-adaptive.ts +123 -0
  460. package/src/alphalib/types/robots/video-concat.ts +68 -0
  461. package/src/alphalib/types/robots/video-encode.ts +182 -0
  462. package/src/alphalib/types/robots/video-merge.ts +72 -0
  463. package/src/alphalib/types/robots/video-subtitle.ts +86 -0
  464. package/src/alphalib/types/robots/video-thumbs.ts +88 -0
  465. package/src/alphalib/types/robots/vimeo-store.ts +84 -0
  466. package/src/alphalib/types/robots/wasabi-import.ts +84 -0
  467. package/src/alphalib/types/robots/wasabi-store.ts +62 -0
  468. package/src/alphalib/types/robots/youtube-store.ts +108 -0
  469. package/src/alphalib/types/stackVersions.ts +12 -0
  470. package/src/alphalib/types/template.ts +71 -0
  471. package/src/alphalib/zodParseWithContext.ts +151 -0
  472. package/src/apiTypes.ts +165 -0
  473. package/src/tus.ts +123 -0
  474. package/index.js +0 -1
  475. package/src/PaginationStream.js +0 -39
  476. package/src/Transloadit.js +0 -701
  477. package/types/index.d.ts +0 -217
@@ -0,0 +1,826 @@
1
+ import { createHmac, randomUUID } from 'crypto'
2
+ import got, { RequiredRetryOptions, Headers, OptionsOfJSONResponseBody } from 'got'
3
+ import FormData from 'form-data'
4
+ import { constants, createReadStream } from 'fs'
5
+ import { access } from 'fs/promises'
6
+ import debug from 'debug'
7
+ import intoStream from 'into-stream'
8
+ import isStream from 'is-stream'
9
+ import * as assert from 'assert'
10
+ import pMap from 'p-map'
11
+ import type { Readable } from 'stream'
12
+ import InconsistentResponseError from './InconsistentResponseError'
13
+ import PaginationStream from './PaginationStream'
14
+ import PollingTimeoutError from './PollingTimeoutError'
15
+ import { TransloaditErrorResponseBody, ApiError } from './ApiError'
16
+ import { version } from '../package.json'
17
+ import { sendTusRequest, Stream } from './tus'
18
+ import { AssemblyStatus } from './alphalib/types/assemblyStatus'
19
+ import type {
20
+ BaseResponse,
21
+ BillResponse,
22
+ CreateAssemblyParams,
23
+ CreateTemplateCredentialParams,
24
+ CreateTemplateParams,
25
+ EditTemplateParams,
26
+ ListAssembliesParams,
27
+ ListedAssembly,
28
+ ListedTemplate,
29
+ ListTemplateCredentialsParams,
30
+ ListTemplatesParams,
31
+ OptionalAuthParams,
32
+ PaginationListWithCount,
33
+ ReplayAssemblyNotificationParams,
34
+ ReplayAssemblyNotificationResponse,
35
+ ReplayAssemblyParams,
36
+ ReplayAssemblyResponse,
37
+ TemplateCredentialResponse,
38
+ TemplateCredentialsResponse,
39
+ TemplateResponse,
40
+ } from './apiTypes'
41
+
42
+ export type * from './apiTypes'
43
+
44
+ // See https://github.com/sindresorhus/got/tree/v11.8.6?tab=readme-ov-file#errors
45
+ // Expose relevant errors
46
+ export {
47
+ RequestError,
48
+ ReadError,
49
+ ParseError,
50
+ UploadError,
51
+ HTTPError,
52
+ MaxRedirectsError,
53
+ TimeoutError,
54
+ } from 'got'
55
+ export { InconsistentResponseError, ApiError }
56
+
57
+ const log = debug('transloadit')
58
+ const logWarn = debug('transloadit:warn')
59
+
60
+ export interface UploadProgress {
61
+ uploadedBytes?: number | undefined
62
+ totalBytes?: number | undefined
63
+ }
64
+
65
+ export type AssemblyProgress = (assembly: AssemblyStatus) => void
66
+
67
+ export interface CreateAssemblyOptions {
68
+ params?: CreateAssemblyParams
69
+ files?: {
70
+ [name: string]: string
71
+ }
72
+ uploads?: {
73
+ [name: string]: Readable | intoStream.Input
74
+ }
75
+ waitForCompletion?: boolean
76
+ chunkSize?: number
77
+ uploadConcurrency?: number
78
+ timeout?: number
79
+ onUploadProgress?: (uploadProgress: UploadProgress) => void
80
+ onAssemblyProgress?: AssemblyProgress
81
+ assemblyId?: string
82
+ }
83
+
84
+ export interface AwaitAssemblyCompletionOptions {
85
+ onAssemblyProgress?: AssemblyProgress
86
+ timeout?: number
87
+ interval?: number
88
+ startTimeMs?: number
89
+ }
90
+
91
+ export interface SmartCDNUrlOptions {
92
+ /**
93
+ * Workspace slug
94
+ */
95
+ workspace: string
96
+ /**
97
+ * Template slug or template ID
98
+ */
99
+ template: string
100
+ /**
101
+ * Input value that is provided as `${fields.input}` in the template
102
+ */
103
+ input: string
104
+ /**
105
+ * Additional parameters for the URL query string
106
+ */
107
+ urlParams?: Record<string, boolean | number | string | (boolean | number | string)[]>
108
+ /**
109
+ * Expiration timestamp of the signature in milliseconds since UNIX epoch.
110
+ * Defaults to 1 hour from now.
111
+ */
112
+ expiresAt?: number
113
+ }
114
+
115
+ export type Fields = Record<string, string | number>
116
+
117
+ // A special promise that lets the user immediately get the assembly ID (synchronously before the request is sent)
118
+ interface CreateAssemblyPromise extends Promise<AssemblyStatus> {
119
+ assemblyId: string
120
+ }
121
+
122
+ // Not sure if this is still a problem with the API, but throw a special error type so the user can retry if needed
123
+ function checkAssemblyUrls(result: AssemblyStatus) {
124
+ if (result.assembly_url == null || result.assembly_ssl_url == null) {
125
+ throw new InconsistentResponseError('Server returned an incomplete assembly response (no URL)')
126
+ }
127
+ }
128
+
129
+ function getHrTimeMs(): number {
130
+ return Number(process.hrtime.bigint() / 1000000n)
131
+ }
132
+
133
+ function checkResult<T>(result: T | { error: string }): asserts result is T {
134
+ // In case server returned a successful HTTP status code, but an `error` in the JSON object
135
+ // This happens sometimes, for example when createAssembly with an invalid file (IMPORT_FILE_ERROR)
136
+ if (
137
+ typeof result === 'object' &&
138
+ result !== null &&
139
+ 'error' in result &&
140
+ typeof result.error === 'string'
141
+ ) {
142
+ throw new ApiError({ body: result }) // in this case there is no `cause` because we don't have an HTTPError
143
+ }
144
+ }
145
+
146
+ export interface Options {
147
+ authKey: string
148
+ authSecret: string
149
+ endpoint?: string
150
+ maxRetries?: number
151
+ timeout?: number
152
+ gotRetry?: RequiredRetryOptions
153
+ }
154
+
155
+ export class Transloadit {
156
+ private _authKey: string
157
+
158
+ private _authSecret: string
159
+
160
+ private _endpoint: string
161
+
162
+ private _maxRetries: number
163
+
164
+ private _defaultTimeout: number
165
+
166
+ private _gotRetry: RequiredRetryOptions | number
167
+
168
+ private _lastUsedAssemblyUrl = ''
169
+
170
+ constructor(opts: Options) {
171
+ if (opts?.authKey == null) {
172
+ throw new Error('Please provide an authKey')
173
+ }
174
+
175
+ if (opts.authSecret == null) {
176
+ throw new Error('Please provide an authSecret')
177
+ }
178
+
179
+ if (opts.endpoint && opts.endpoint.endsWith('/')) {
180
+ throw new Error('Trailing slash in endpoint is not allowed')
181
+ }
182
+
183
+ this._authKey = opts.authKey
184
+ this._authSecret = opts.authSecret
185
+ this._endpoint = opts.endpoint || 'https://api2.transloadit.com'
186
+ this._maxRetries = opts.maxRetries != null ? opts.maxRetries : 5
187
+ this._defaultTimeout = opts.timeout != null ? opts.timeout : 60000
188
+
189
+ // Passed on to got https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md
190
+ this._gotRetry = opts.gotRetry != null ? opts.gotRetry : 0
191
+ }
192
+
193
+ getLastUsedAssemblyUrl(): string {
194
+ return this._lastUsedAssemblyUrl
195
+ }
196
+
197
+ setDefaultTimeout(timeout: number): void {
198
+ this._defaultTimeout = timeout
199
+ }
200
+
201
+ /**
202
+ * Create an Assembly
203
+ *
204
+ * @param opts assembly options
205
+ */
206
+ createAssembly(opts: CreateAssemblyOptions = {}): CreateAssemblyPromise {
207
+ const {
208
+ params = {},
209
+ waitForCompletion = false,
210
+ chunkSize: requestedChunkSize = Infinity,
211
+ uploadConcurrency = 10,
212
+ timeout = 24 * 60 * 60 * 1000, // 1 day
213
+ onUploadProgress = () => {},
214
+ onAssemblyProgress = () => {},
215
+ files = {},
216
+ uploads = {},
217
+ assemblyId,
218
+ } = opts
219
+
220
+ // Keep track of how long the request took
221
+ const startTimeMs = getHrTimeMs()
222
+
223
+ // Undocumented feature to allow specifying a custom assembly id from the client
224
+ // Not recommended for general use due to security. E.g if the user doesn't provide a cryptographically
225
+ // secure ID, then anyone could access the assembly.
226
+ let effectiveAssemblyId
227
+ if (assemblyId != null) {
228
+ effectiveAssemblyId = assemblyId
229
+ } else {
230
+ effectiveAssemblyId = randomUUID().replace(/-/g, '')
231
+ }
232
+ const urlSuffix = `/assemblies/${effectiveAssemblyId}`
233
+
234
+ // We want to be able to return the promise immediately with custom data
235
+ const promise = (async () => {
236
+ this._lastUsedAssemblyUrl = `${this._endpoint}${urlSuffix}`
237
+
238
+ await pMap(
239
+ Object.entries(files),
240
+ // eslint-disable-next-line no-bitwise
241
+ async ([, path]) => access(path, constants.F_OK | constants.R_OK),
242
+ { concurrency: 5 }
243
+ )
244
+
245
+ // Convert uploads to streams
246
+ const streamsMap = Object.fromEntries(
247
+ Object.entries(uploads).map(([label, value]) => {
248
+ const isReadable = isStream.readable(value)
249
+ if (!isReadable && isStream(value)) {
250
+ // https://github.com/transloadit/node-sdk/issues/92
251
+ throw new Error(`Upload named "${label}" is not a Readable stream`)
252
+ }
253
+
254
+ return [label, isStream.readable(value) ? value : intoStream(value)]
255
+ })
256
+ )
257
+
258
+ // Wrap in object structure (so we can store whether it's a pathless stream or not)
259
+ const allStreamsMap = Object.fromEntries<Stream>(
260
+ Object.entries(streamsMap).map(([label, stream]) => [label, { stream }])
261
+ )
262
+
263
+ // Create streams from files too
264
+ for (const [label, path] of Object.entries(files)) {
265
+ const stream = createReadStream(path)
266
+ allStreamsMap[label] = { stream, path } // File streams have path
267
+ }
268
+
269
+ const allStreams = Object.values(allStreamsMap)
270
+
271
+ // Pause all streams
272
+ allStreams.forEach(({ stream }) => stream.pause())
273
+
274
+ // If any stream emits error, we want to handle this and exit with error
275
+ const streamErrorPromise = new Promise<AssemblyStatus>((resolve, reject) => {
276
+ allStreams.forEach(({ stream }) => stream.on('error', reject))
277
+ })
278
+
279
+ const createAssemblyAndUpload = async () => {
280
+ const result: AssemblyStatus = await this._remoteJson({
281
+ urlSuffix,
282
+ method: 'post',
283
+ timeout,
284
+ params,
285
+ fields: {
286
+ tus_num_expected_upload_files: allStreams.length,
287
+ },
288
+ })
289
+ checkResult(result)
290
+
291
+ if (Object.keys(allStreamsMap).length > 0) {
292
+ await sendTusRequest({
293
+ streamsMap: allStreamsMap,
294
+ assembly: result,
295
+ onProgress: onUploadProgress,
296
+ requestedChunkSize,
297
+ uploadConcurrency,
298
+ })
299
+ }
300
+
301
+ if (!waitForCompletion) return result
302
+ const awaitResult = await this.awaitAssemblyCompletion(result.assembly_id, {
303
+ timeout,
304
+ onAssemblyProgress,
305
+ startTimeMs,
306
+ })
307
+ checkResult(awaitResult)
308
+ return awaitResult
309
+ }
310
+
311
+ return Promise.race([createAssemblyAndUpload(), streamErrorPromise])
312
+ })()
313
+
314
+ // This allows the user to use or log the assemblyId even before it has been created for easier debugging
315
+ return Object.assign(promise, { assemblyId: effectiveAssemblyId })
316
+ }
317
+
318
+ async awaitAssemblyCompletion(
319
+ assemblyId: string,
320
+ {
321
+ onAssemblyProgress = () => {},
322
+ timeout,
323
+ startTimeMs = getHrTimeMs(),
324
+ interval = 1000,
325
+ }: AwaitAssemblyCompletionOptions = {}
326
+ ): Promise<AssemblyStatus> {
327
+ assert.ok(assemblyId)
328
+
329
+ // eslint-disable-next-line no-constant-condition
330
+ while (true) {
331
+ const result = await this.getAssembly(assemblyId)
332
+
333
+ if (
334
+ result.ok !== 'ASSEMBLY_UPLOADING' &&
335
+ result.ok !== 'ASSEMBLY_EXECUTING' &&
336
+ result.ok !== 'ASSEMBLY_REPLAYING'
337
+ ) {
338
+ return result // Done!
339
+ }
340
+
341
+ try {
342
+ onAssemblyProgress(result)
343
+ } catch (err) {
344
+ log('Caught onAssemblyProgress error', err)
345
+ }
346
+
347
+ const nowMs = getHrTimeMs()
348
+ if (timeout != null && nowMs - startTimeMs >= timeout) {
349
+ throw new PollingTimeoutError('Polling timed out')
350
+ }
351
+ await new Promise((resolve) => setTimeout(resolve, interval))
352
+ }
353
+ }
354
+
355
+ /**
356
+ * Cancel the assembly
357
+ *
358
+ * @param assemblyId assembly ID
359
+ * @returns after the assembly is deleted
360
+ */
361
+ async cancelAssembly(assemblyId: string): Promise<AssemblyStatus> {
362
+ // You may wonder why do we need to call getAssembly first:
363
+ // If we use the default base URL (instead of the one returned in assembly_url_ssl),
364
+ // the delete call will hang in certain cases
365
+ // See test "should stop the assembly from reaching completion"
366
+ const { assembly_ssl_url: url } = await this.getAssembly(assemblyId)
367
+ return this._remoteJson({
368
+ url,
369
+ // urlSuffix: `/assemblies/${assemblyId}`, // Cannot simply do this, see above
370
+ method: 'delete',
371
+ })
372
+ }
373
+
374
+ /**
375
+ * Replay an Assembly
376
+ *
377
+ * @param assemblyId of the assembly to replay
378
+ * @param optional params
379
+ * @returns after the replay is started
380
+ */
381
+ async replayAssembly(
382
+ assemblyId: string,
383
+ params: ReplayAssemblyParams = {}
384
+ ): Promise<ReplayAssemblyResponse> {
385
+ const result: ReplayAssemblyResponse = await this._remoteJson({
386
+ urlSuffix: `/assemblies/${assemblyId}/replay`,
387
+ method: 'post',
388
+ ...(Object.keys(params).length > 0 && { params }),
389
+ })
390
+ checkResult(result)
391
+ return result
392
+ }
393
+
394
+ /**
395
+ * Replay an Assembly notification
396
+ *
397
+ * @param assemblyId of the assembly whose notification to replay
398
+ * @param optional params
399
+ * @returns after the replay is started
400
+ */
401
+ async replayAssemblyNotification(
402
+ assemblyId: string,
403
+ params: ReplayAssemblyNotificationParams = {}
404
+ ): Promise<ReplayAssemblyNotificationResponse> {
405
+ return this._remoteJson({
406
+ urlSuffix: `/assembly_notifications/${assemblyId}/replay`,
407
+ method: 'post',
408
+ ...(Object.keys(params).length > 0 && { params }),
409
+ })
410
+ }
411
+
412
+ /**
413
+ * List all assemblies
414
+ *
415
+ * @param params optional request options
416
+ * @returns list of Assemblies
417
+ */
418
+ async listAssemblies(
419
+ params?: ListAssembliesParams
420
+ ): Promise<PaginationListWithCount<ListedAssembly>> {
421
+ return this._remoteJson({
422
+ urlSuffix: '/assemblies',
423
+ method: 'get',
424
+ params: params || {},
425
+ })
426
+ }
427
+
428
+ streamAssemblies(params: ListAssembliesParams): Readable {
429
+ return new PaginationStream(async (page) => this.listAssemblies({ ...params, page }))
430
+ }
431
+
432
+ /**
433
+ * Get an Assembly
434
+ *
435
+ * @param assemblyId the Assembly Id
436
+ * @returns the retrieved Assembly
437
+ */
438
+ async getAssembly(assemblyId: string): Promise<AssemblyStatus> {
439
+ const result: AssemblyStatus = await this._remoteJson({
440
+ urlSuffix: `/assemblies/${assemblyId}`,
441
+ })
442
+ checkAssemblyUrls(result)
443
+ return result
444
+ }
445
+
446
+ /**
447
+ * Create a Credential
448
+ *
449
+ * @param params optional request options
450
+ * @returns when the Credential is created
451
+ */
452
+ async createTemplateCredential(
453
+ params: CreateTemplateCredentialParams
454
+ ): Promise<TemplateCredentialResponse> {
455
+ return this._remoteJson({
456
+ urlSuffix: '/template_credentials',
457
+ method: 'post',
458
+ params: params || {},
459
+ })
460
+ }
461
+
462
+ /**
463
+ * Edit a Credential
464
+ *
465
+ * @param credentialId the Credential ID
466
+ * @param params optional request options
467
+ * @returns when the Credential is edited
468
+ */
469
+ async editTemplateCredential(
470
+ credentialId: string,
471
+ params: CreateTemplateCredentialParams
472
+ ): Promise<TemplateCredentialResponse> {
473
+ return this._remoteJson({
474
+ urlSuffix: `/template_credentials/${credentialId}`,
475
+ method: 'put',
476
+ params: params || {},
477
+ })
478
+ }
479
+
480
+ /**
481
+ * Delete a Credential
482
+ *
483
+ * @param credentialId the Credential ID
484
+ * @returns when the Credential is deleted
485
+ */
486
+ async deleteTemplateCredential(credentialId: string): Promise<BaseResponse> {
487
+ return this._remoteJson({
488
+ urlSuffix: `/template_credentials/${credentialId}`,
489
+ method: 'delete',
490
+ })
491
+ }
492
+
493
+ /**
494
+ * Get a Credential
495
+ *
496
+ * @param credentialId the Credential ID
497
+ * @returns when the Credential is retrieved
498
+ */
499
+ async getTemplateCredential(credentialId: string): Promise<TemplateCredentialResponse> {
500
+ return this._remoteJson({
501
+ urlSuffix: `/template_credentials/${credentialId}`,
502
+ method: 'get',
503
+ })
504
+ }
505
+
506
+ /**
507
+ * List all TemplateCredentials
508
+ *
509
+ * @param params optional request options
510
+ * @returns the list of templates
511
+ */
512
+ async listTemplateCredentials(
513
+ params?: ListTemplateCredentialsParams
514
+ ): Promise<TemplateCredentialsResponse> {
515
+ return this._remoteJson({
516
+ urlSuffix: '/template_credentials',
517
+ method: 'get',
518
+ params: params || {},
519
+ })
520
+ }
521
+
522
+ streamTemplateCredentials(params: ListTemplateCredentialsParams) {
523
+ return new PaginationStream(async (page) => ({
524
+ items: (await this.listTemplateCredentials({ ...params, page })).credentials,
525
+ }))
526
+ }
527
+
528
+ /**
529
+ * Create an Assembly Template
530
+ *
531
+ * @param params optional request options
532
+ * @returns when the template is created
533
+ */
534
+ async createTemplate(params: CreateTemplateParams): Promise<TemplateResponse> {
535
+ return this._remoteJson({
536
+ urlSuffix: '/templates',
537
+ method: 'post',
538
+ params: params || {},
539
+ })
540
+ }
541
+
542
+ /**
543
+ * Edit an Assembly Template
544
+ *
545
+ * @param templateId the template ID
546
+ * @param params optional request options
547
+ * @returns when the template is edited
548
+ */
549
+ async editTemplate(templateId: string, params: EditTemplateParams): Promise<TemplateResponse> {
550
+ return this._remoteJson({
551
+ urlSuffix: `/templates/${templateId}`,
552
+ method: 'put',
553
+ params: params || {},
554
+ })
555
+ }
556
+
557
+ /**
558
+ * Delete an Assembly Template
559
+ *
560
+ * @param templateId the template ID
561
+ * @returns when the template is deleted
562
+ */
563
+ async deleteTemplate(templateId: string): Promise<BaseResponse> {
564
+ return this._remoteJson({
565
+ urlSuffix: `/templates/${templateId}`,
566
+ method: 'delete',
567
+ })
568
+ }
569
+
570
+ /**
571
+ * Get an Assembly Template
572
+ *
573
+ * @param templateId the template ID
574
+ * @returns when the template is retrieved
575
+ */
576
+ async getTemplate(templateId: string): Promise<TemplateResponse> {
577
+ return this._remoteJson({
578
+ urlSuffix: `/templates/${templateId}`,
579
+ method: 'get',
580
+ })
581
+ }
582
+
583
+ /**
584
+ * List all Assembly Templates
585
+ *
586
+ * @param params optional request options
587
+ * @returns the list of templates
588
+ */
589
+ async listTemplates(
590
+ params?: ListTemplatesParams
591
+ ): Promise<PaginationListWithCount<ListedTemplate>> {
592
+ return this._remoteJson({
593
+ urlSuffix: '/templates',
594
+ method: 'get',
595
+ params: params || {},
596
+ })
597
+ }
598
+
599
+ streamTemplates(params?: ListTemplatesParams): PaginationStream<ListedTemplate> {
600
+ return new PaginationStream(async (page) => this.listTemplates({ ...params, page }))
601
+ }
602
+
603
+ /**
604
+ * Get account Billing details for a specific month
605
+ *
606
+ * @param month the date for the required billing in the format yyyy-mm
607
+ * @returns with billing data
608
+ * @see https://transloadit.com/docs/api/bill-date-get/
609
+ */
610
+ async getBill(month: string): Promise<BillResponse> {
611
+ assert.ok(month, 'month is required')
612
+ return this._remoteJson({
613
+ urlSuffix: `/bill/${month}`,
614
+ method: 'get',
615
+ })
616
+ }
617
+
618
+ calcSignature(params: OptionalAuthParams): { signature: string; params: string } {
619
+ const jsonParams = this._prepareParams(params)
620
+ const signature = this._calcSignature(jsonParams)
621
+
622
+ return { signature, params: jsonParams }
623
+ }
624
+
625
+ /**
626
+ * Construct a signed Smart CDN URL. See https://transloadit.com/docs/topics/signature-authentication/#smart-cdn.
627
+ */
628
+ getSignedSmartCDNUrl(opts: SmartCDNUrlOptions): string {
629
+ if (opts.workspace == null || opts.workspace === '')
630
+ throw new TypeError('workspace is required')
631
+ if (opts.template == null || opts.template === '') throw new TypeError('template is required')
632
+ if (opts.input == null) throw new TypeError('input is required') // `input` can be an empty string.
633
+
634
+ const workspaceSlug = encodeURIComponent(opts.workspace)
635
+ const templateSlug = encodeURIComponent(opts.template)
636
+ const inputField = encodeURIComponent(opts.input)
637
+ const expiresAt = opts.expiresAt || Date.now() + 60 * 60 * 1000 // 1 hour
638
+
639
+ const queryParams = new URLSearchParams()
640
+ for (const [key, value] of Object.entries(opts.urlParams || {})) {
641
+ if (Array.isArray(value)) {
642
+ for (const val of value) {
643
+ queryParams.append(key, `${val}`)
644
+ }
645
+ } else {
646
+ queryParams.append(key, `${value}`)
647
+ }
648
+ }
649
+
650
+ queryParams.set('auth_key', this._authKey)
651
+ queryParams.set('exp', `${expiresAt}`)
652
+ // The signature changes depending on the order of the query parameters. We therefore sort them on the client-
653
+ // and server-side to ensure that we do not get mismatching signatures if a proxy changes the order of query
654
+ // parameters or implementations handle query parameters ordering differently.
655
+ queryParams.sort()
656
+
657
+ const stringToSign = `${workspaceSlug}/${templateSlug}/${inputField}?${queryParams}`
658
+ const algorithm = 'sha256'
659
+ const signature = createHmac(algorithm, this._authSecret).update(stringToSign).digest('hex')
660
+
661
+ queryParams.set('sig', `sha256:${signature}`)
662
+ const signedUrl = `https://${workspaceSlug}.tlcdn.com/${templateSlug}/${inputField}?${queryParams}`
663
+ return signedUrl
664
+ }
665
+
666
+ private _calcSignature(toSign: string, algorithm = 'sha384'): string {
667
+ return `${algorithm}:${createHmac(algorithm, this._authSecret)
668
+ .update(Buffer.from(toSign, 'utf-8'))
669
+ .digest('hex')}`
670
+ }
671
+
672
+ // Sets the multipart/form-data for POST, PUT and DELETE requests, including
673
+ // the streams, the signed params, and any additional fields.
674
+ private _appendForm(form: FormData, params: OptionalAuthParams, fields?: Fields): void {
675
+ const sigData = this.calcSignature(params)
676
+ const jsonParams = sigData.params
677
+ const { signature } = sigData
678
+
679
+ form.append('params', jsonParams)
680
+
681
+ if (fields != null) {
682
+ for (const [key, val] of Object.entries(fields)) {
683
+ form.append(key, val)
684
+ }
685
+ }
686
+
687
+ form.append('signature', signature)
688
+ }
689
+
690
+ // Implements HTTP GET query params, handling the case where the url already
691
+ // has params.
692
+ private _appendParamsToUrl(url: string, params: OptionalAuthParams): string {
693
+ const { signature, params: jsonParams } = this.calcSignature(params)
694
+
695
+ const prefix = url.indexOf('?') === -1 ? '?' : '&'
696
+
697
+ return `${url}${prefix}signature=${signature}&params=${encodeURIComponent(jsonParams)}`
698
+ }
699
+
700
+ // Responsible for including auth parameters in all requests
701
+ private _prepareParams(paramsIn?: OptionalAuthParams): string {
702
+ let params = paramsIn
703
+ if (params == null) {
704
+ params = {}
705
+ }
706
+ if (params['auth'] == null) {
707
+ params['auth'] = {}
708
+ }
709
+ if (params['auth'].key == null) {
710
+ params['auth'].key = this._authKey
711
+ }
712
+ if (params['auth'].expires == null) {
713
+ params['auth'].expires = this._getExpiresDate()
714
+ }
715
+
716
+ return JSON.stringify(params)
717
+ }
718
+
719
+ // We want to mock this method
720
+ // eslint-disable-next-line class-methods-use-this
721
+ private _getExpiresDate(): string {
722
+ const expiresDate = new Date()
723
+ expiresDate.setDate(expiresDate.getDate() + 1)
724
+ return expiresDate.toISOString()
725
+ }
726
+
727
+ // Responsible for making API calls. Automatically sends streams with any POST,
728
+ // PUT or DELETE requests. Automatically adds signature parameters to all
729
+ // requests. Also automatically parses the JSON response.
730
+ private async _remoteJson<TRet, TParams extends OptionalAuthParams>(opts: {
731
+ urlSuffix?: string
732
+ url?: string
733
+ timeout?: number
734
+ method?: 'delete' | 'get' | 'post' | 'put'
735
+ params?: TParams
736
+ fields?: Fields
737
+ headers?: Headers
738
+ }): Promise<TRet> {
739
+ const {
740
+ urlSuffix,
741
+ url: urlInput,
742
+ timeout = this._defaultTimeout,
743
+ method = 'get',
744
+ params = {},
745
+ fields,
746
+ headers,
747
+ } = opts
748
+
749
+ // Allow providing either a `urlSuffix` or a full `url`
750
+ if (!urlSuffix && !urlInput) throw new Error('No URL provided')
751
+ let url = urlInput || `${this._endpoint}${urlSuffix}`
752
+
753
+ if (method === 'get') {
754
+ url = this._appendParamsToUrl(url, params)
755
+ }
756
+
757
+ log('Sending request', method, url)
758
+
759
+ // todo use got.retry instead because we are no longer using FormData (which is a stream and can only be used once)
760
+ // https://github.com/sindresorhus/got/issues/1282
761
+ for (let retryCount = 0; ; retryCount++) {
762
+ let form: FormData | undefined
763
+
764
+ if (method === 'post' || method === 'put' || method === 'delete') {
765
+ form = new FormData()
766
+ this._appendForm(form, params, fields)
767
+ }
768
+
769
+ const requestOpts: OptionsOfJSONResponseBody = {
770
+ retry: this._gotRetry,
771
+ body: form,
772
+ timeout,
773
+ headers: {
774
+ 'Transloadit-Client': `node-sdk:${version}`,
775
+ 'User-Agent': undefined, // Remove got's user-agent
776
+ ...headers,
777
+ },
778
+ responseType: 'json',
779
+ }
780
+
781
+ try {
782
+ const request = got[method]<TRet>(url, requestOpts)
783
+ const { body } = await request
784
+ // console.log(body)
785
+ return body
786
+ } catch (err) {
787
+ if (!(err instanceof got.RequestError)) throw err
788
+
789
+ if (err instanceof got.HTTPError) {
790
+ const { statusCode, body } = err.response
791
+ logWarn('HTTP error', statusCode, body)
792
+
793
+ // check whether we should retry
794
+ // https://transloadit.com/blog/2012/04/introducing-rate-limiting/
795
+ if (
796
+ typeof body === 'object' &&
797
+ body != null &&
798
+ 'error' in body &&
799
+ 'info' in body &&
800
+ typeof body.info === 'object' &&
801
+ body.info != null &&
802
+ 'retryIn' in body.info &&
803
+ typeof body.info.retryIn === 'number' &&
804
+ Boolean(body.info.retryIn) &&
805
+ retryCount < this._maxRetries && // 413 taken from https://transloadit.com/blog/2012/04/introducing-rate-limiting/
806
+ // todo can 413 be removed?
807
+ ((statusCode === 413 && body.error === 'RATE_LIMIT_REACHED') || statusCode === 429)
808
+ ) {
809
+ const { retryIn: retryInSec } = body.info
810
+ logWarn(`Rate limit reached, retrying request in approximately ${retryInSec} seconds.`)
811
+ const retryInMs = 1000 * (retryInSec * (1 + 0.1 * Math.random()))
812
+ await new Promise((resolve) => setTimeout(resolve, retryInMs))
813
+ // Retry
814
+ } else {
815
+ throw new ApiError({
816
+ cause: err,
817
+ body: err.response?.body as TransloaditErrorResponseBody | undefined,
818
+ }) // todo don't assert type
819
+ }
820
+ } else {
821
+ throw err
822
+ }
823
+ }
824
+ }
825
+ }
826
+ }