@transloadit/node 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (593) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +701 -0
  3. package/dist/ApiError.d.ts +22 -0
  4. package/dist/ApiError.d.ts.map +1 -0
  5. package/dist/ApiError.js +33 -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 +4 -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 +36 -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 +5 -0
  18. package/dist/PollingTimeoutError.js.map +1 -0
  19. package/dist/Transloadit.d.ts +250 -0
  20. package/dist/Transloadit.d.ts.map +1 -0
  21. package/dist/Transloadit.js +661 -0
  22. package/dist/Transloadit.js.map +1 -0
  23. package/dist/alphalib/lib/nativeGlobby.d.ts +14 -0
  24. package/dist/alphalib/lib/nativeGlobby.d.ts.map +1 -0
  25. package/dist/alphalib/lib/nativeGlobby.js +181 -0
  26. package/dist/alphalib/lib/nativeGlobby.js.map +1 -0
  27. package/dist/alphalib/mcache.d.ts +65 -0
  28. package/dist/alphalib/mcache.d.ts.map +1 -0
  29. package/dist/alphalib/mcache.js +135 -0
  30. package/dist/alphalib/mcache.js.map +1 -0
  31. package/dist/alphalib/tryCatch.d.ts +21 -0
  32. package/dist/alphalib/tryCatch.d.ts.map +1 -0
  33. package/dist/alphalib/tryCatch.js +17 -0
  34. package/dist/alphalib/tryCatch.js.map +1 -0
  35. package/dist/alphalib/types/assembliesGet.d.ts +62 -0
  36. package/dist/alphalib/types/assembliesGet.d.ts.map +1 -0
  37. package/dist/alphalib/types/assembliesGet.js +33 -0
  38. package/dist/alphalib/types/assembliesGet.js.map +1 -0
  39. package/dist/alphalib/types/assemblyReplay.d.ts +7858 -0
  40. package/dist/alphalib/types/assemblyReplay.d.ts.map +1 -0
  41. package/dist/alphalib/types/assemblyReplay.js +15 -0
  42. package/dist/alphalib/types/assemblyReplay.js.map +1 -0
  43. package/dist/alphalib/types/assemblyReplayNotification.d.ts +7849 -0
  44. package/dist/alphalib/types/assemblyReplayNotification.d.ts.map +1 -0
  45. package/dist/alphalib/types/assemblyReplayNotification.js +13 -0
  46. package/dist/alphalib/types/assemblyReplayNotification.js.map +1 -0
  47. package/dist/alphalib/types/assemblyStatus.d.ts +71084 -0
  48. package/dist/alphalib/types/assemblyStatus.d.ts.map +1 -0
  49. package/dist/alphalib/types/assemblyStatus.js +710 -0
  50. package/dist/alphalib/types/assemblyStatus.js.map +1 -0
  51. package/dist/alphalib/types/bill.d.ts +44 -0
  52. package/dist/alphalib/types/bill.d.ts.map +1 -0
  53. package/dist/alphalib/types/bill.js +8 -0
  54. package/dist/alphalib/types/bill.js.map +1 -0
  55. package/dist/alphalib/types/robots/_index.d.ts +76306 -0
  56. package/dist/alphalib/types/robots/_index.d.ts.map +1 -0
  57. package/dist/alphalib/types/robots/_index.js +354 -0
  58. package/dist/alphalib/types/robots/_index.js.map +1 -0
  59. package/dist/alphalib/types/robots/_instructions-primitives.d.ts +3533 -0
  60. package/dist/alphalib/types/robots/_instructions-primitives.d.ts.map +1 -0
  61. package/dist/alphalib/types/robots/_instructions-primitives.js +1491 -0
  62. package/dist/alphalib/types/robots/_instructions-primitives.js.map +1 -0
  63. package/dist/alphalib/types/robots/ai-chat.d.ts +2096 -0
  64. package/dist/alphalib/types/robots/ai-chat.d.ts.map +1 -0
  65. package/dist/alphalib/types/robots/ai-chat.js +223 -0
  66. package/dist/alphalib/types/robots/ai-chat.js.map +1 -0
  67. package/dist/alphalib/types/robots/assembly-savejson.d.ts +52 -0
  68. package/dist/alphalib/types/robots/assembly-savejson.d.ts.map +1 -0
  69. package/dist/alphalib/types/robots/assembly-savejson.js +22 -0
  70. package/dist/alphalib/types/robots/assembly-savejson.js.map +1 -0
  71. package/dist/alphalib/types/robots/audio-artwork.d.ts +2867 -0
  72. package/dist/alphalib/types/robots/audio-artwork.d.ts.map +1 -0
  73. package/dist/alphalib/types/robots/audio-artwork.js +73 -0
  74. package/dist/alphalib/types/robots/audio-artwork.js.map +1 -0
  75. package/dist/alphalib/types/robots/audio-concat.d.ts +2916 -0
  76. package/dist/alphalib/types/robots/audio-concat.d.ts.map +1 -0
  77. package/dist/alphalib/types/robots/audio-concat.js +106 -0
  78. package/dist/alphalib/types/robots/audio-concat.js.map +1 -0
  79. package/dist/alphalib/types/robots/audio-encode.d.ts +2864 -0
  80. package/dist/alphalib/types/robots/audio-encode.d.ts.map +1 -0
  81. package/dist/alphalib/types/robots/audio-encode.js +67 -0
  82. package/dist/alphalib/types/robots/audio-encode.js.map +1 -0
  83. package/dist/alphalib/types/robots/audio-loop.d.ts +2879 -0
  84. package/dist/alphalib/types/robots/audio-loop.d.ts.map +1 -0
  85. package/dist/alphalib/types/robots/audio-loop.js +67 -0
  86. package/dist/alphalib/types/robots/audio-loop.js.map +1 -0
  87. package/dist/alphalib/types/robots/audio-merge.d.ts +2931 -0
  88. package/dist/alphalib/types/robots/audio-merge.d.ts.map +1 -0
  89. package/dist/alphalib/types/robots/audio-merge.js +101 -0
  90. package/dist/alphalib/types/robots/audio-merge.js.map +1 -0
  91. package/dist/alphalib/types/robots/audio-waveform.d.ts +3131 -0
  92. package/dist/alphalib/types/robots/audio-waveform.d.ts.map +1 -0
  93. package/dist/alphalib/types/robots/audio-waveform.js +238 -0
  94. package/dist/alphalib/types/robots/audio-waveform.js.map +1 -0
  95. package/dist/alphalib/types/robots/azure-import.d.ts +210 -0
  96. package/dist/alphalib/types/robots/azure-import.d.ts.map +1 -0
  97. package/dist/alphalib/types/robots/azure-import.js +73 -0
  98. package/dist/alphalib/types/robots/azure-import.js.map +1 -0
  99. package/dist/alphalib/types/robots/azure-store.d.ts +562 -0
  100. package/dist/alphalib/types/robots/azure-store.d.ts.map +1 -0
  101. package/dist/alphalib/types/robots/azure-store.js +115 -0
  102. package/dist/alphalib/types/robots/azure-store.js.map +1 -0
  103. package/dist/alphalib/types/robots/backblaze-import.d.ts +210 -0
  104. package/dist/alphalib/types/robots/backblaze-import.d.ts.map +1 -0
  105. package/dist/alphalib/types/robots/backblaze-import.js +81 -0
  106. package/dist/alphalib/types/robots/backblaze-import.js.map +1 -0
  107. package/dist/alphalib/types/robots/backblaze-store.d.ts +478 -0
  108. package/dist/alphalib/types/robots/backblaze-store.d.ts.map +1 -0
  109. package/dist/alphalib/types/robots/backblaze-store.js +76 -0
  110. package/dist/alphalib/types/robots/backblaze-store.js.map +1 -0
  111. package/dist/alphalib/types/robots/cloudfiles-import.d.ts +234 -0
  112. package/dist/alphalib/types/robots/cloudfiles-import.d.ts.map +1 -0
  113. package/dist/alphalib/types/robots/cloudfiles-import.js +80 -0
  114. package/dist/alphalib/types/robots/cloudfiles-import.js.map +1 -0
  115. package/dist/alphalib/types/robots/cloudfiles-store.d.ts +490 -0
  116. package/dist/alphalib/types/robots/cloudfiles-store.d.ts.map +1 -0
  117. package/dist/alphalib/types/robots/cloudfiles-store.js +70 -0
  118. package/dist/alphalib/types/robots/cloudfiles-store.js.map +1 -0
  119. package/dist/alphalib/types/robots/cloudflare-import.d.ts +234 -0
  120. package/dist/alphalib/types/robots/cloudflare-import.d.ts.map +1 -0
  121. package/dist/alphalib/types/robots/cloudflare-import.js +81 -0
  122. package/dist/alphalib/types/robots/cloudflare-import.js.map +1 -0
  123. package/dist/alphalib/types/robots/cloudflare-store.d.ts +514 -0
  124. package/dist/alphalib/types/robots/cloudflare-store.d.ts.map +1 -0
  125. package/dist/alphalib/types/robots/cloudflare-store.js +86 -0
  126. package/dist/alphalib/types/robots/cloudflare-store.js.map +1 -0
  127. package/dist/alphalib/types/robots/digitalocean-import.d.ts +234 -0
  128. package/dist/alphalib/types/robots/digitalocean-import.d.ts.map +1 -0
  129. package/dist/alphalib/types/robots/digitalocean-import.js +78 -0
  130. package/dist/alphalib/types/robots/digitalocean-import.js.map +1 -0
  131. package/dist/alphalib/types/robots/digitalocean-store.d.ts +526 -0
  132. package/dist/alphalib/types/robots/digitalocean-store.d.ts.map +1 -0
  133. package/dist/alphalib/types/robots/digitalocean-store.js +91 -0
  134. package/dist/alphalib/types/robots/digitalocean-store.js.map +1 -0
  135. package/dist/alphalib/types/robots/document-autorotate.d.ts +405 -0
  136. package/dist/alphalib/types/robots/document-autorotate.d.ts.map +1 -0
  137. package/dist/alphalib/types/robots/document-autorotate.js +44 -0
  138. package/dist/alphalib/types/robots/document-autorotate.js.map +1 -0
  139. package/dist/alphalib/types/robots/document-convert.d.ts +513 -0
  140. package/dist/alphalib/types/robots/document-convert.d.ts.map +1 -0
  141. package/dist/alphalib/types/robots/document-convert.js +273 -0
  142. package/dist/alphalib/types/robots/document-convert.js.map +1 -0
  143. package/dist/alphalib/types/robots/document-merge.d.ts +429 -0
  144. package/dist/alphalib/types/robots/document-merge.d.ts.map +1 -0
  145. package/dist/alphalib/types/robots/document-merge.js +86 -0
  146. package/dist/alphalib/types/robots/document-merge.js.map +1 -0
  147. package/dist/alphalib/types/robots/document-ocr.d.ts +441 -0
  148. package/dist/alphalib/types/robots/document-ocr.d.ts.map +1 -0
  149. package/dist/alphalib/types/robots/document-ocr.js +86 -0
  150. package/dist/alphalib/types/robots/document-ocr.js.map +1 -0
  151. package/dist/alphalib/types/robots/document-split.d.ts +417 -0
  152. package/dist/alphalib/types/robots/document-split.d.ts.map +1 -0
  153. package/dist/alphalib/types/robots/document-split.js +48 -0
  154. package/dist/alphalib/types/robots/document-split.js.map +1 -0
  155. package/dist/alphalib/types/robots/document-thumbs.d.ts +592 -0
  156. package/dist/alphalib/types/robots/document-thumbs.d.ts.map +1 -0
  157. package/dist/alphalib/types/robots/document-thumbs.js +196 -0
  158. package/dist/alphalib/types/robots/document-thumbs.js.map +1 -0
  159. package/dist/alphalib/types/robots/dropbox-import.d.ts +144 -0
  160. package/dist/alphalib/types/robots/dropbox-import.d.ts.map +1 -0
  161. package/dist/alphalib/types/robots/dropbox-import.js +65 -0
  162. package/dist/alphalib/types/robots/dropbox-import.js.map +1 -0
  163. package/dist/alphalib/types/robots/dropbox-store.d.ts +449 -0
  164. package/dist/alphalib/types/robots/dropbox-store.d.ts.map +1 -0
  165. package/dist/alphalib/types/robots/dropbox-store.js +68 -0
  166. package/dist/alphalib/types/robots/dropbox-store.js.map +1 -0
  167. package/dist/alphalib/types/robots/edgly-deliver.d.ts +100 -0
  168. package/dist/alphalib/types/robots/edgly-deliver.d.ts.map +1 -0
  169. package/dist/alphalib/types/robots/edgly-deliver.js +46 -0
  170. package/dist/alphalib/types/robots/edgly-deliver.js.map +1 -0
  171. package/dist/alphalib/types/robots/file-compress.d.ts +477 -0
  172. package/dist/alphalib/types/robots/file-compress.d.ts.map +1 -0
  173. package/dist/alphalib/types/robots/file-compress.js +139 -0
  174. package/dist/alphalib/types/robots/file-compress.js.map +1 -0
  175. package/dist/alphalib/types/robots/file-decompress.d.ts +404 -0
  176. package/dist/alphalib/types/robots/file-decompress.d.ts.map +1 -0
  177. package/dist/alphalib/types/robots/file-decompress.js +94 -0
  178. package/dist/alphalib/types/robots/file-decompress.js.map +1 -0
  179. package/dist/alphalib/types/robots/file-filter.d.ts +465 -0
  180. package/dist/alphalib/types/robots/file-filter.d.ts.map +1 -0
  181. package/dist/alphalib/types/robots/file-filter.js +136 -0
  182. package/dist/alphalib/types/robots/file-filter.js.map +1 -0
  183. package/dist/alphalib/types/robots/file-hash.d.ts +417 -0
  184. package/dist/alphalib/types/robots/file-hash.d.ts.map +1 -0
  185. package/dist/alphalib/types/robots/file-hash.js +59 -0
  186. package/dist/alphalib/types/robots/file-hash.js.map +1 -0
  187. package/dist/alphalib/types/robots/file-preview.d.ts +854 -0
  188. package/dist/alphalib/types/robots/file-preview.d.ts.map +1 -0
  189. package/dist/alphalib/types/robots/file-preview.js +221 -0
  190. package/dist/alphalib/types/robots/file-preview.js.map +1 -0
  191. package/dist/alphalib/types/robots/file-read.d.ts +405 -0
  192. package/dist/alphalib/types/robots/file-read.d.ts.map +1 -0
  193. package/dist/alphalib/types/robots/file-read.js +44 -0
  194. package/dist/alphalib/types/robots/file-read.js.map +1 -0
  195. package/dist/alphalib/types/robots/file-serve.d.ts +418 -0
  196. package/dist/alphalib/types/robots/file-serve.d.ts.map +1 -0
  197. package/dist/alphalib/types/robots/file-serve.js +99 -0
  198. package/dist/alphalib/types/robots/file-serve.js.map +1 -0
  199. package/dist/alphalib/types/robots/file-verify.d.ts +441 -0
  200. package/dist/alphalib/types/robots/file-verify.d.ts.map +1 -0
  201. package/dist/alphalib/types/robots/file-verify.js +73 -0
  202. package/dist/alphalib/types/robots/file-verify.js.map +1 -0
  203. package/dist/alphalib/types/robots/file-virusscan.d.ts +435 -0
  204. package/dist/alphalib/types/robots/file-virusscan.d.ts.map +1 -0
  205. package/dist/alphalib/types/robots/file-virusscan.js +82 -0
  206. package/dist/alphalib/types/robots/file-virusscan.js.map +1 -0
  207. package/dist/alphalib/types/robots/file-watermark.d.ts +417 -0
  208. package/dist/alphalib/types/robots/file-watermark.d.ts.map +1 -0
  209. package/dist/alphalib/types/robots/file-watermark.js +28 -0
  210. package/dist/alphalib/types/robots/file-watermark.js.map +1 -0
  211. package/dist/alphalib/types/robots/ftp-import.d.ts +198 -0
  212. package/dist/alphalib/types/robots/ftp-import.d.ts.map +1 -0
  213. package/dist/alphalib/types/robots/ftp-import.js +60 -0
  214. package/dist/alphalib/types/robots/ftp-import.js.map +1 -0
  215. package/dist/alphalib/types/robots/ftp-store.d.ts +532 -0
  216. package/dist/alphalib/types/robots/ftp-store.d.ts.map +1 -0
  217. package/dist/alphalib/types/robots/ftp-store.js +91 -0
  218. package/dist/alphalib/types/robots/ftp-store.js.map +1 -0
  219. package/dist/alphalib/types/robots/google-import.d.ts +174 -0
  220. package/dist/alphalib/types/robots/google-import.d.ts.map +1 -0
  221. package/dist/alphalib/types/robots/google-import.js +77 -0
  222. package/dist/alphalib/types/robots/google-import.js.map +1 -0
  223. package/dist/alphalib/types/robots/google-store.d.ts +476 -0
  224. package/dist/alphalib/types/robots/google-store.d.ts.map +1 -0
  225. package/dist/alphalib/types/robots/google-store.js +111 -0
  226. package/dist/alphalib/types/robots/google-store.js.map +1 -0
  227. package/dist/alphalib/types/robots/html-convert.d.ts +531 -0
  228. package/dist/alphalib/types/robots/html-convert.d.ts.map +1 -0
  229. package/dist/alphalib/types/robots/html-convert.js +137 -0
  230. package/dist/alphalib/types/robots/html-convert.js.map +1 -0
  231. package/dist/alphalib/types/robots/http-import.d.ts +215 -0
  232. package/dist/alphalib/types/robots/http-import.d.ts.map +1 -0
  233. package/dist/alphalib/types/robots/http-import.js +135 -0
  234. package/dist/alphalib/types/robots/http-import.js.map +1 -0
  235. package/dist/alphalib/types/robots/image-bgremove.d.ts +453 -0
  236. package/dist/alphalib/types/robots/image-bgremove.d.ts.map +1 -0
  237. package/dist/alphalib/types/robots/image-bgremove.js +65 -0
  238. package/dist/alphalib/types/robots/image-bgremove.js.map +1 -0
  239. package/dist/alphalib/types/robots/image-describe.d.ts +453 -0
  240. package/dist/alphalib/types/robots/image-describe.d.ts.map +1 -0
  241. package/dist/alphalib/types/robots/image-describe.js +86 -0
  242. package/dist/alphalib/types/robots/image-describe.js.map +1 -0
  243. package/dist/alphalib/types/robots/image-facedetect.d.ts +477 -0
  244. package/dist/alphalib/types/robots/image-facedetect.d.ts.map +1 -0
  245. package/dist/alphalib/types/robots/image-facedetect.js +151 -0
  246. package/dist/alphalib/types/robots/image-facedetect.js.map +1 -0
  247. package/dist/alphalib/types/robots/image-generate.d.ts +522 -0
  248. package/dist/alphalib/types/robots/image-generate.d.ts.map +1 -0
  249. package/dist/alphalib/types/robots/image-generate.js +64 -0
  250. package/dist/alphalib/types/robots/image-generate.js.map +1 -0
  251. package/dist/alphalib/types/robots/image-merge.d.ts +477 -0
  252. package/dist/alphalib/types/robots/image-merge.d.ts.map +1 -0
  253. package/dist/alphalib/types/robots/image-merge.js +92 -0
  254. package/dist/alphalib/types/robots/image-merge.js.map +1 -0
  255. package/dist/alphalib/types/robots/image-ocr.d.ts +441 -0
  256. package/dist/alphalib/types/robots/image-ocr.d.ts.map +1 -0
  257. package/dist/alphalib/types/robots/image-ocr.js +79 -0
  258. package/dist/alphalib/types/robots/image-ocr.js.map +1 -0
  259. package/dist/alphalib/types/robots/image-optimize.d.ts +453 -0
  260. package/dist/alphalib/types/robots/image-optimize.d.ts.map +1 -0
  261. package/dist/alphalib/types/robots/image-optimize.js +81 -0
  262. package/dist/alphalib/types/robots/image-optimize.js.map +1 -0
  263. package/dist/alphalib/types/robots/image-resize.d.ts +1758 -0
  264. package/dist/alphalib/types/robots/image-resize.d.ts.map +1 -0
  265. package/dist/alphalib/types/robots/image-resize.js +602 -0
  266. package/dist/alphalib/types/robots/image-resize.js.map +1 -0
  267. package/dist/alphalib/types/robots/meta-read.d.ts +98 -0
  268. package/dist/alphalib/types/robots/meta-read.d.ts.map +1 -0
  269. package/dist/alphalib/types/robots/meta-read.js +24 -0
  270. package/dist/alphalib/types/robots/meta-read.js.map +1 -0
  271. package/dist/alphalib/types/robots/meta-write.d.ts +2842 -0
  272. package/dist/alphalib/types/robots/meta-write.d.ts.map +1 -0
  273. package/dist/alphalib/types/robots/meta-write.js +66 -0
  274. package/dist/alphalib/types/robots/meta-write.js.map +1 -0
  275. package/dist/alphalib/types/robots/minio-import.d.ts +234 -0
  276. package/dist/alphalib/types/robots/minio-import.d.ts.map +1 -0
  277. package/dist/alphalib/types/robots/minio-import.js +81 -0
  278. package/dist/alphalib/types/robots/minio-import.js.map +1 -0
  279. package/dist/alphalib/types/robots/minio-store.d.ts +514 -0
  280. package/dist/alphalib/types/robots/minio-store.d.ts.map +1 -0
  281. package/dist/alphalib/types/robots/minio-store.js +87 -0
  282. package/dist/alphalib/types/robots/minio-store.js.map +1 -0
  283. package/dist/alphalib/types/robots/progress-simulate.d.ts +229 -0
  284. package/dist/alphalib/types/robots/progress-simulate.d.ts.map +1 -0
  285. package/dist/alphalib/types/robots/progress-simulate.js +25 -0
  286. package/dist/alphalib/types/robots/progress-simulate.js.map +1 -0
  287. package/dist/alphalib/types/robots/s3-import.d.ts +246 -0
  288. package/dist/alphalib/types/robots/s3-import.d.ts.map +1 -0
  289. package/dist/alphalib/types/robots/s3-import.js +137 -0
  290. package/dist/alphalib/types/robots/s3-import.js.map +1 -0
  291. package/dist/alphalib/types/robots/s3-store.d.ts +593 -0
  292. package/dist/alphalib/types/robots/s3-store.d.ts.map +1 -0
  293. package/dist/alphalib/types/robots/s3-store.js +169 -0
  294. package/dist/alphalib/types/robots/s3-store.js.map +1 -0
  295. package/dist/alphalib/types/robots/script-run.d.ts +423 -0
  296. package/dist/alphalib/types/robots/script-run.d.ts.map +1 -0
  297. package/dist/alphalib/types/robots/script-run.js +95 -0
  298. package/dist/alphalib/types/robots/script-run.js.map +1 -0
  299. package/dist/alphalib/types/robots/sftp-import.d.ts +192 -0
  300. package/dist/alphalib/types/robots/sftp-import.d.ts.map +1 -0
  301. package/dist/alphalib/types/robots/sftp-import.js +62 -0
  302. package/dist/alphalib/types/robots/sftp-import.js.map +1 -0
  303. package/dist/alphalib/types/robots/sftp-store.d.ts +520 -0
  304. package/dist/alphalib/types/robots/sftp-store.d.ts.map +1 -0
  305. package/dist/alphalib/types/robots/sftp-store.js +83 -0
  306. package/dist/alphalib/types/robots/sftp-store.js.map +1 -0
  307. package/dist/alphalib/types/robots/speech-transcribe.d.ts +465 -0
  308. package/dist/alphalib/types/robots/speech-transcribe.d.ts.map +1 -0
  309. package/dist/alphalib/types/robots/speech-transcribe.js +103 -0
  310. package/dist/alphalib/types/robots/speech-transcribe.js.map +1 -0
  311. package/dist/alphalib/types/robots/supabase-import.d.ts +246 -0
  312. package/dist/alphalib/types/robots/supabase-import.d.ts.map +1 -0
  313. package/dist/alphalib/types/robots/supabase-import.js +83 -0
  314. package/dist/alphalib/types/robots/supabase-import.js.map +1 -0
  315. package/dist/alphalib/types/robots/supabase-store.d.ts +514 -0
  316. package/dist/alphalib/types/robots/supabase-store.d.ts.map +1 -0
  317. package/dist/alphalib/types/robots/supabase-store.js +77 -0
  318. package/dist/alphalib/types/robots/supabase-store.js.map +1 -0
  319. package/dist/alphalib/types/robots/swift-import.d.ts +246 -0
  320. package/dist/alphalib/types/robots/swift-import.d.ts.map +1 -0
  321. package/dist/alphalib/types/robots/swift-import.js +81 -0
  322. package/dist/alphalib/types/robots/swift-import.js.map +1 -0
  323. package/dist/alphalib/types/robots/swift-store.d.ts +526 -0
  324. package/dist/alphalib/types/robots/swift-store.d.ts.map +1 -0
  325. package/dist/alphalib/types/robots/swift-store.js +84 -0
  326. package/dist/alphalib/types/robots/swift-store.js.map +1 -0
  327. package/dist/alphalib/types/robots/text-speak.d.ts +465 -0
  328. package/dist/alphalib/types/robots/text-speak.d.ts.map +1 -0
  329. package/dist/alphalib/types/robots/text-speak.js +119 -0
  330. package/dist/alphalib/types/robots/text-speak.js.map +1 -0
  331. package/dist/alphalib/types/robots/text-translate.d.ts +441 -0
  332. package/dist/alphalib/types/robots/text-translate.d.ts.map +1 -0
  333. package/dist/alphalib/types/robots/text-translate.js +211 -0
  334. package/dist/alphalib/types/robots/text-translate.js.map +1 -0
  335. package/dist/alphalib/types/robots/tigris-import.d.ts +244 -0
  336. package/dist/alphalib/types/robots/tigris-import.d.ts.map +1 -0
  337. package/dist/alphalib/types/robots/tigris-import.js +85 -0
  338. package/dist/alphalib/types/robots/tigris-import.js.map +1 -0
  339. package/dist/alphalib/types/robots/tigris-store.d.ts +524 -0
  340. package/dist/alphalib/types/robots/tigris-store.d.ts.map +1 -0
  341. package/dist/alphalib/types/robots/tigris-store.js +91 -0
  342. package/dist/alphalib/types/robots/tigris-store.js.map +1 -0
  343. package/dist/alphalib/types/robots/tlcdn-deliver.d.ts +100 -0
  344. package/dist/alphalib/types/robots/tlcdn-deliver.d.ts.map +1 -0
  345. package/dist/alphalib/types/robots/tlcdn-deliver.js +46 -0
  346. package/dist/alphalib/types/robots/tlcdn-deliver.js.map +1 -0
  347. package/dist/alphalib/types/robots/tus-store.d.ts +477 -0
  348. package/dist/alphalib/types/robots/tus-store.d.ts.map +1 -0
  349. package/dist/alphalib/types/robots/tus-store.js +102 -0
  350. package/dist/alphalib/types/robots/tus-store.js.map +1 -0
  351. package/dist/alphalib/types/robots/upload-handle.d.ts +100 -0
  352. package/dist/alphalib/types/robots/upload-handle.d.ts.map +1 -0
  353. package/dist/alphalib/types/robots/upload-handle.js +66 -0
  354. package/dist/alphalib/types/robots/upload-handle.js.map +1 -0
  355. package/dist/alphalib/types/robots/video-adaptive.d.ts +2915 -0
  356. package/dist/alphalib/types/robots/video-adaptive.d.ts.map +1 -0
  357. package/dist/alphalib/types/robots/video-adaptive.js +144 -0
  358. package/dist/alphalib/types/robots/video-adaptive.js.map +1 -0
  359. package/dist/alphalib/types/robots/video-concat.d.ts +2891 -0
  360. package/dist/alphalib/types/robots/video-concat.d.ts.map +1 -0
  361. package/dist/alphalib/types/robots/video-concat.js +96 -0
  362. package/dist/alphalib/types/robots/video-concat.js.map +1 -0
  363. package/dist/alphalib/types/robots/video-encode.d.ts +3280 -0
  364. package/dist/alphalib/types/robots/video-encode.d.ts.map +1 -0
  365. package/dist/alphalib/types/robots/video-encode.js +107 -0
  366. package/dist/alphalib/types/robots/video-encode.js.map +1 -0
  367. package/dist/alphalib/types/robots/video-merge.d.ts +2987 -0
  368. package/dist/alphalib/types/robots/video-merge.d.ts.map +1 -0
  369. package/dist/alphalib/types/robots/video-merge.js +102 -0
  370. package/dist/alphalib/types/robots/video-merge.js.map +1 -0
  371. package/dist/alphalib/types/robots/video-ondemand.d.ts +4553 -0
  372. package/dist/alphalib/types/robots/video-ondemand.d.ts.map +1 -0
  373. package/dist/alphalib/types/robots/video-ondemand.js +112 -0
  374. package/dist/alphalib/types/robots/video-ondemand.js.map +1 -0
  375. package/dist/alphalib/types/robots/video-subtitle.d.ts +2975 -0
  376. package/dist/alphalib/types/robots/video-subtitle.d.ts.map +1 -0
  377. package/dist/alphalib/types/robots/video-subtitle.js +122 -0
  378. package/dist/alphalib/types/robots/video-subtitle.js.map +1 -0
  379. package/dist/alphalib/types/robots/video-thumbs.d.ts +2938 -0
  380. package/dist/alphalib/types/robots/video-thumbs.d.ts.map +1 -0
  381. package/dist/alphalib/types/robots/video-thumbs.js +122 -0
  382. package/dist/alphalib/types/robots/video-thumbs.js.map +1 -0
  383. package/dist/alphalib/types/robots/vimeo-import.d.ts +189 -0
  384. package/dist/alphalib/types/robots/vimeo-import.d.ts.map +1 -0
  385. package/dist/alphalib/types/robots/vimeo-import.js +92 -0
  386. package/dist/alphalib/types/robots/vimeo-import.js.map +1 -0
  387. package/dist/alphalib/types/robots/vimeo-store.d.ts +520 -0
  388. package/dist/alphalib/types/robots/vimeo-store.d.ts.map +1 -0
  389. package/dist/alphalib/types/robots/vimeo-store.js +115 -0
  390. package/dist/alphalib/types/robots/vimeo-store.js.map +1 -0
  391. package/dist/alphalib/types/robots/wasabi-import.d.ts +244 -0
  392. package/dist/alphalib/types/robots/wasabi-import.d.ts.map +1 -0
  393. package/dist/alphalib/types/robots/wasabi-import.js +85 -0
  394. package/dist/alphalib/types/robots/wasabi-import.js.map +1 -0
  395. package/dist/alphalib/types/robots/wasabi-store.d.ts +526 -0
  396. package/dist/alphalib/types/robots/wasabi-store.d.ts.map +1 -0
  397. package/dist/alphalib/types/robots/wasabi-store.js +85 -0
  398. package/dist/alphalib/types/robots/wasabi-store.js.map +1 -0
  399. package/dist/alphalib/types/robots/youtube-store.d.ts +477 -0
  400. package/dist/alphalib/types/robots/youtube-store.d.ts.map +1 -0
  401. package/dist/alphalib/types/robots/youtube-store.js +122 -0
  402. package/dist/alphalib/types/robots/youtube-store.js.map +1 -0
  403. package/dist/alphalib/types/stackVersions.d.ts +13 -0
  404. package/dist/alphalib/types/stackVersions.d.ts.map +1 -0
  405. package/dist/alphalib/types/stackVersions.js +13 -0
  406. package/dist/alphalib/types/stackVersions.js.map +1 -0
  407. package/dist/alphalib/types/template.d.ts +131710 -0
  408. package/dist/alphalib/types/template.d.ts.map +1 -0
  409. package/dist/alphalib/types/template.js +218 -0
  410. package/dist/alphalib/types/template.js.map +1 -0
  411. package/dist/alphalib/types/templateCredential.d.ts +95 -0
  412. package/dist/alphalib/types/templateCredential.d.ts.map +1 -0
  413. package/dist/alphalib/types/templateCredential.js +57 -0
  414. package/dist/alphalib/types/templateCredential.js.map +1 -0
  415. package/dist/alphalib/zodParseWithContext.d.ts +17 -0
  416. package/dist/alphalib/zodParseWithContext.d.ts.map +1 -0
  417. package/dist/alphalib/zodParseWithContext.js +248 -0
  418. package/dist/alphalib/zodParseWithContext.js.map +1 -0
  419. package/dist/apiTypes.d.ts +112 -0
  420. package/dist/apiTypes.d.ts.map +1 -0
  421. package/dist/apiTypes.js +3 -0
  422. package/dist/apiTypes.js.map +1 -0
  423. package/dist/cli/OutputCtl.d.ts +47 -0
  424. package/dist/cli/OutputCtl.d.ts.map +1 -0
  425. package/dist/cli/OutputCtl.js +85 -0
  426. package/dist/cli/OutputCtl.js.map +1 -0
  427. package/dist/cli/commands/BaseCommand.d.ts +24 -0
  428. package/dist/cli/commands/BaseCommand.d.ts.map +1 -0
  429. package/dist/cli/commands/BaseCommand.js +52 -0
  430. package/dist/cli/commands/BaseCommand.js.map +1 -0
  431. package/dist/cli/commands/assemblies.d.ts +93 -0
  432. package/dist/cli/commands/assemblies.d.ts.map +1 -0
  433. package/dist/cli/commands/assemblies.js +1021 -0
  434. package/dist/cli/commands/assemblies.js.map +1 -0
  435. package/dist/cli/commands/auth.d.ts +28 -0
  436. package/dist/cli/commands/auth.d.ts.map +1 -0
  437. package/dist/cli/commands/auth.js +280 -0
  438. package/dist/cli/commands/auth.js.map +1 -0
  439. package/dist/cli/commands/bills.d.ts +14 -0
  440. package/dist/cli/commands/bills.d.ts.map +1 -0
  441. package/dist/cli/commands/bills.js +69 -0
  442. package/dist/cli/commands/bills.js.map +1 -0
  443. package/dist/cli/commands/index.d.ts +3 -0
  444. package/dist/cli/commands/index.d.ts.map +1 -0
  445. package/dist/cli/commands/index.js +39 -0
  446. package/dist/cli/commands/index.js.map +1 -0
  447. package/dist/cli/commands/notifications.d.ts +9 -0
  448. package/dist/cli/commands/notifications.d.ts.map +1 -0
  449. package/dist/cli/commands/notifications.js +44 -0
  450. package/dist/cli/commands/notifications.js.map +1 -0
  451. package/dist/cli/commands/templates.d.ts +73 -0
  452. package/dist/cli/commands/templates.d.ts.map +1 -0
  453. package/dist/cli/commands/templates.js +428 -0
  454. package/dist/cli/commands/templates.js.map +1 -0
  455. package/dist/cli/helpers.d.ts +13 -0
  456. package/dist/cli/helpers.d.ts.map +1 -0
  457. package/dist/cli/helpers.js +39 -0
  458. package/dist/cli/helpers.js.map +1 -0
  459. package/dist/cli/template-last-modified.d.ts +10 -0
  460. package/dist/cli/template-last-modified.d.ts.map +1 -0
  461. package/dist/cli/template-last-modified.js +134 -0
  462. package/dist/cli/template-last-modified.js.map +1 -0
  463. package/dist/cli/types.d.ts +78 -0
  464. package/dist/cli/types.d.ts.map +1 -0
  465. package/dist/cli/types.js +49 -0
  466. package/dist/cli/types.js.map +1 -0
  467. package/dist/cli.d.ts +6 -0
  468. package/dist/cli.d.ts.map +1 -0
  469. package/dist/cli.js +41 -0
  470. package/dist/cli.js.map +1 -0
  471. package/dist/tus.d.ts +18 -0
  472. package/dist/tus.d.ts.map +1 -0
  473. package/dist/tus.js +122 -0
  474. package/dist/tus.js.map +1 -0
  475. package/package.json +92 -0
  476. package/src/ApiError.ts +49 -0
  477. package/src/InconsistentResponseError.ts +3 -0
  478. package/src/PaginationStream.ts +54 -0
  479. package/src/PollingTimeoutError.ts +5 -0
  480. package/src/Transloadit.ts +980 -0
  481. package/src/alphalib/lib/nativeGlobby.ts +244 -0
  482. package/src/alphalib/mcache.ts +184 -0
  483. package/src/alphalib/tryCatch.ts +30 -0
  484. package/src/alphalib/types/assembliesGet.ts +42 -0
  485. package/src/alphalib/types/assemblyReplay.ts +24 -0
  486. package/src/alphalib/types/assemblyReplayNotification.ts +16 -0
  487. package/src/alphalib/types/assemblyStatus.ts +794 -0
  488. package/src/alphalib/types/bill.ts +9 -0
  489. package/src/alphalib/types/robots/_index.ts +1201 -0
  490. package/src/alphalib/types/robots/_instructions-primitives.ts +1770 -0
  491. package/src/alphalib/types/robots/ai-chat.ts +278 -0
  492. package/src/alphalib/types/robots/assembly-savejson.ts +37 -0
  493. package/src/alphalib/types/robots/audio-artwork.ts +107 -0
  494. package/src/alphalib/types/robots/audio-concat.ts +142 -0
  495. package/src/alphalib/types/robots/audio-encode.ts +103 -0
  496. package/src/alphalib/types/robots/audio-loop.ts +102 -0
  497. package/src/alphalib/types/robots/audio-merge.ts +137 -0
  498. package/src/alphalib/types/robots/audio-waveform.ts +280 -0
  499. package/src/alphalib/types/robots/azure-import.ts +111 -0
  500. package/src/alphalib/types/robots/azure-store.ts +143 -0
  501. package/src/alphalib/types/robots/backblaze-import.ts +119 -0
  502. package/src/alphalib/types/robots/backblaze-store.ts +104 -0
  503. package/src/alphalib/types/robots/cloudfiles-import.ts +118 -0
  504. package/src/alphalib/types/robots/cloudfiles-store.ts +104 -0
  505. package/src/alphalib/types/robots/cloudflare-import.ts +121 -0
  506. package/src/alphalib/types/robots/cloudflare-store.ts +120 -0
  507. package/src/alphalib/types/robots/digitalocean-import.ts +118 -0
  508. package/src/alphalib/types/robots/digitalocean-store.ts +125 -0
  509. package/src/alphalib/types/robots/document-autorotate.ts +74 -0
  510. package/src/alphalib/types/robots/document-convert.ts +302 -0
  511. package/src/alphalib/types/robots/document-merge.ts +114 -0
  512. package/src/alphalib/types/robots/document-ocr.ts +120 -0
  513. package/src/alphalib/types/robots/document-split.ts +78 -0
  514. package/src/alphalib/types/robots/document-thumbs.ts +231 -0
  515. package/src/alphalib/types/robots/dropbox-import.ts +100 -0
  516. package/src/alphalib/types/robots/dropbox-store.ts +97 -0
  517. package/src/alphalib/types/robots/edgly-deliver.ts +73 -0
  518. package/src/alphalib/types/robots/file-compress.ts +167 -0
  519. package/src/alphalib/types/robots/file-decompress.ts +125 -0
  520. package/src/alphalib/types/robots/file-filter.ts +173 -0
  521. package/src/alphalib/types/robots/file-hash.ts +86 -0
  522. package/src/alphalib/types/robots/file-preview.ts +260 -0
  523. package/src/alphalib/types/robots/file-read.ts +71 -0
  524. package/src/alphalib/types/robots/file-serve.ts +128 -0
  525. package/src/alphalib/types/robots/file-verify.ts +102 -0
  526. package/src/alphalib/types/robots/file-virusscan.ts +113 -0
  527. package/src/alphalib/types/robots/file-watermark.ts +56 -0
  528. package/src/alphalib/types/robots/ftp-import.ts +95 -0
  529. package/src/alphalib/types/robots/ftp-store.ts +119 -0
  530. package/src/alphalib/types/robots/google-import.ts +115 -0
  531. package/src/alphalib/types/robots/google-store.ts +139 -0
  532. package/src/alphalib/types/robots/html-convert.ts +165 -0
  533. package/src/alphalib/types/robots/http-import.ts +168 -0
  534. package/src/alphalib/types/robots/image-bgremove.ts +95 -0
  535. package/src/alphalib/types/robots/image-describe.ts +121 -0
  536. package/src/alphalib/types/robots/image-facedetect.ts +187 -0
  537. package/src/alphalib/types/robots/image-generate.ts +92 -0
  538. package/src/alphalib/types/robots/image-merge.ts +127 -0
  539. package/src/alphalib/types/robots/image-ocr.ts +112 -0
  540. package/src/alphalib/types/robots/image-optimize.ts +114 -0
  541. package/src/alphalib/types/robots/image-resize.ts +653 -0
  542. package/src/alphalib/types/robots/meta-read.ts +44 -0
  543. package/src/alphalib/types/robots/meta-write.ts +93 -0
  544. package/src/alphalib/types/robots/minio-import.ts +120 -0
  545. package/src/alphalib/types/robots/minio-store.ts +115 -0
  546. package/src/alphalib/types/robots/progress-simulate.ts +40 -0
  547. package/src/alphalib/types/robots/s3-import.ts +175 -0
  548. package/src/alphalib/types/robots/s3-store.ts +198 -0
  549. package/src/alphalib/types/robots/script-run.ts +122 -0
  550. package/src/alphalib/types/robots/sftp-import.ts +92 -0
  551. package/src/alphalib/types/robots/sftp-store.ts +110 -0
  552. package/src/alphalib/types/robots/speech-transcribe.ts +139 -0
  553. package/src/alphalib/types/robots/supabase-import.ts +122 -0
  554. package/src/alphalib/types/robots/supabase-store.ts +105 -0
  555. package/src/alphalib/types/robots/swift-import.ts +120 -0
  556. package/src/alphalib/types/robots/swift-store.ts +112 -0
  557. package/src/alphalib/types/robots/text-speak.ts +152 -0
  558. package/src/alphalib/types/robots/text-translate.ts +245 -0
  559. package/src/alphalib/types/robots/tigris-import.ts +124 -0
  560. package/src/alphalib/types/robots/tigris-store.ts +119 -0
  561. package/src/alphalib/types/robots/tlcdn-deliver.ts +73 -0
  562. package/src/alphalib/types/robots/tus-store.ts +129 -0
  563. package/src/alphalib/types/robots/upload-handle.ts +95 -0
  564. package/src/alphalib/types/robots/video-adaptive.ts +179 -0
  565. package/src/alphalib/types/robots/video-concat.ts +130 -0
  566. package/src/alphalib/types/robots/video-encode.ts +141 -0
  567. package/src/alphalib/types/robots/video-merge.ts +138 -0
  568. package/src/alphalib/types/robots/video-ondemand.ts +161 -0
  569. package/src/alphalib/types/robots/video-subtitle.ts +159 -0
  570. package/src/alphalib/types/robots/video-thumbs.ts +158 -0
  571. package/src/alphalib/types/robots/vimeo-import.ts +126 -0
  572. package/src/alphalib/types/robots/vimeo-store.ts +143 -0
  573. package/src/alphalib/types/robots/wasabi-import.ts +124 -0
  574. package/src/alphalib/types/robots/wasabi-store.ts +113 -0
  575. package/src/alphalib/types/robots/youtube-store.ts +153 -0
  576. package/src/alphalib/types/stackVersions.ts +12 -0
  577. package/src/alphalib/types/template.ts +277 -0
  578. package/src/alphalib/types/templateCredential.ts +61 -0
  579. package/src/alphalib/zodParseWithContext.ts +306 -0
  580. package/src/apiTypes.ts +154 -0
  581. package/src/cli/OutputCtl.ts +115 -0
  582. package/src/cli/commands/BaseCommand.ts +71 -0
  583. package/src/cli/commands/assemblies.ts +1373 -0
  584. package/src/cli/commands/auth.ts +354 -0
  585. package/src/cli/commands/bills.ts +91 -0
  586. package/src/cli/commands/index.ts +65 -0
  587. package/src/cli/commands/notifications.ts +63 -0
  588. package/src/cli/commands/templates.ts +556 -0
  589. package/src/cli/helpers.ts +50 -0
  590. package/src/cli/template-last-modified.ts +156 -0
  591. package/src/cli/types.ts +70 -0
  592. package/src/cli.ts +44 -0
  593. package/src/tus.ts +168 -0
@@ -0,0 +1,980 @@
1
+ import * as assert from 'node:assert'
2
+ import { createHmac, randomUUID } from 'node:crypto'
3
+ import { constants, createReadStream } from 'node:fs'
4
+ import { access } from 'node:fs/promises'
5
+ import type { Readable } from 'node:stream'
6
+ import { setTimeout as delay } from 'node:timers/promises'
7
+ import debug from 'debug'
8
+ import FormData from 'form-data'
9
+ import type { Delays, Headers, OptionsOfJSONResponseBody, RetryOptions } from 'got'
10
+ import got, { HTTPError, RequestError } from 'got'
11
+ import intoStream, { type Input as IntoStreamInput } from 'into-stream'
12
+ import { isReadableStream, isStream } from 'is-stream'
13
+ import pMap from 'p-map'
14
+ import packageJson from '../package.json' with { type: 'json' }
15
+ import type { TransloaditErrorResponseBody } from './ApiError.ts'
16
+ import { ApiError } from './ApiError.ts'
17
+ import type {
18
+ AssemblyIndex,
19
+ AssemblyIndexItem,
20
+ AssemblyStatus,
21
+ } from './alphalib/types/assemblyStatus.ts'
22
+ import { assemblyIndexSchema, assemblyStatusSchema } from './alphalib/types/assemblyStatus.ts'
23
+ import { zodParseWithContext } from './alphalib/zodParseWithContext.ts'
24
+ import type {
25
+ BaseResponse,
26
+ BillResponse,
27
+ CreateAssemblyParams,
28
+ CreateTemplateCredentialParams,
29
+ CreateTemplateParams,
30
+ EditTemplateParams,
31
+ ListAssembliesParams,
32
+ ListedTemplate,
33
+ ListTemplateCredentialsParams,
34
+ ListTemplatesParams,
35
+ OptionalAuthParams,
36
+ PaginationListWithCount,
37
+ ReplayAssemblyNotificationParams,
38
+ ReplayAssemblyNotificationResponse,
39
+ ReplayAssemblyParams,
40
+ ReplayAssemblyResponse,
41
+ TemplateCredentialResponse,
42
+ TemplateCredentialsResponse,
43
+ TemplateResponse,
44
+ } from './apiTypes.ts'
45
+ import InconsistentResponseError from './InconsistentResponseError.ts'
46
+ import PaginationStream from './PaginationStream.ts'
47
+ import PollingTimeoutError from './PollingTimeoutError.ts'
48
+ import type { Stream } from './tus.ts'
49
+ import { sendTusRequest } from './tus.ts'
50
+
51
+ // See https://github.com/sindresorhus/got/tree/v11.8.6?tab=readme-ov-file#errors
52
+ // Expose relevant errors
53
+ export {
54
+ HTTPError,
55
+ MaxRedirectsError,
56
+ ParseError,
57
+ ReadError,
58
+ RequestError,
59
+ TimeoutError,
60
+ UploadError,
61
+ } from 'got'
62
+
63
+ export type { AssemblyStatus } from './alphalib/types/assemblyStatus.ts'
64
+ export * from './apiTypes.ts'
65
+ export { InconsistentResponseError, ApiError }
66
+
67
+ const log = debug('transloadit')
68
+ const logWarn = debug('transloadit:warn')
69
+
70
+ export interface UploadProgress {
71
+ uploadedBytes?: number | undefined
72
+ totalBytes?: number | undefined
73
+ }
74
+
75
+ const { version } = packageJson
76
+
77
+ export type AssemblyProgress = (assembly: AssemblyStatus) => void
78
+
79
+ export interface CreateAssemblyOptions {
80
+ params?: CreateAssemblyParams
81
+ files?: {
82
+ [name: string]: string
83
+ }
84
+ uploads?: {
85
+ [name: string]: Readable | IntoStreamInput
86
+ }
87
+ waitForCompletion?: boolean
88
+ chunkSize?: number
89
+ uploadConcurrency?: number
90
+ timeout?: number
91
+ onUploadProgress?: (uploadProgress: UploadProgress) => void
92
+ onAssemblyProgress?: AssemblyProgress
93
+ assemblyId?: string
94
+ /**
95
+ * Optional AbortSignal to cancel the assembly creation and upload.
96
+ * When aborted, any in-flight HTTP requests and TUS uploads will be cancelled.
97
+ */
98
+ signal?: AbortSignal
99
+ }
100
+
101
+ export interface AwaitAssemblyCompletionOptions {
102
+ onAssemblyProgress?: AssemblyProgress
103
+ timeout?: number
104
+ interval?: number
105
+ startTimeMs?: number
106
+ /**
107
+ * Optional AbortSignal to cancel polling.
108
+ * When aborted, the polling loop will stop and throw an AbortError.
109
+ */
110
+ signal?: AbortSignal
111
+ /**
112
+ * Optional callback invoked before each poll iteration.
113
+ * Return `false` to stop polling early and return the current assembly status.
114
+ * Useful for watch mode where a newer job may supersede the current one.
115
+ */
116
+ onPoll?: () => boolean | undefined
117
+ }
118
+
119
+ export interface SmartCDNUrlOptions {
120
+ /**
121
+ * Workspace slug
122
+ */
123
+ workspace: string
124
+ /**
125
+ * Template slug or template ID
126
+ */
127
+ template: string
128
+ /**
129
+ * Input value that is provided as `${fields.input}` in the template
130
+ */
131
+ input: string
132
+ /**
133
+ * Additional parameters for the URL query string
134
+ */
135
+ urlParams?: Record<string, boolean | number | string | (boolean | number | string)[]>
136
+ /**
137
+ * Expiration timestamp of the signature in milliseconds since UNIX epoch.
138
+ * Defaults to 1 hour from now.
139
+ */
140
+ expiresAt?: number
141
+ }
142
+
143
+ export type Fields = Record<string, string | number>
144
+
145
+ // A special promise that lets the user immediately get the assembly ID (synchronously before the request is sent)
146
+ interface CreateAssemblyPromise extends Promise<AssemblyStatus> {
147
+ assemblyId: string
148
+ }
149
+
150
+ // Not sure if this is still a problem with the API, but throw a special error type so the user can retry if needed
151
+ function checkAssemblyUrls(result: AssemblyStatus) {
152
+ if (result.assembly_url == null || result.assembly_ssl_url == null) {
153
+ throw new InconsistentResponseError('Server returned an incomplete assembly response (no URL)')
154
+ }
155
+ }
156
+
157
+ function getHrTimeMs(): number {
158
+ return Number(process.hrtime.bigint() / 1000000n)
159
+ }
160
+
161
+ function checkResult<T>(result: T | { error: string }): asserts result is T {
162
+ // In case server returned a successful HTTP status code, but an `error` in the JSON object
163
+ // This happens sometimes, for example when createAssembly with an invalid file (IMPORT_FILE_ERROR)
164
+ if (
165
+ typeof result === 'object' &&
166
+ result !== null &&
167
+ 'error' in result &&
168
+ typeof result.error === 'string'
169
+ ) {
170
+ throw new ApiError({ body: result }) // in this case there is no `cause` because we don't have an HTTPError
171
+ }
172
+ }
173
+
174
+ export interface Options {
175
+ authKey: string
176
+ authSecret: string
177
+ endpoint?: string
178
+ maxRetries?: number
179
+ timeout?: number
180
+ gotRetry?: Partial<RetryOptions>
181
+ validateResponses?: boolean
182
+ }
183
+
184
+ export class Transloadit {
185
+ private _authKey: string
186
+
187
+ private _authSecret: string
188
+
189
+ private _endpoint: string
190
+
191
+ private _maxRetries: number
192
+
193
+ private _defaultTimeout: number
194
+
195
+ private _gotRetry: Partial<RetryOptions>
196
+
197
+ private _lastUsedAssemblyUrl = ''
198
+
199
+ private _validateResponses = false
200
+
201
+ constructor(opts: Options) {
202
+ if (opts?.authKey == null) {
203
+ throw new Error('Please provide an authKey')
204
+ }
205
+
206
+ if (opts.authSecret == null) {
207
+ throw new Error('Please provide an authSecret')
208
+ }
209
+
210
+ if (opts.endpoint?.endsWith('/')) {
211
+ throw new Error('Trailing slash in endpoint is not allowed')
212
+ }
213
+
214
+ this._authKey = opts.authKey
215
+ this._authSecret = opts.authSecret
216
+ this._endpoint = opts.endpoint || 'https://api2.transloadit.com'
217
+ this._maxRetries = opts.maxRetries != null ? opts.maxRetries : 5
218
+ this._defaultTimeout = opts.timeout != null ? opts.timeout : 60000
219
+
220
+ // Passed on to got https://github.com/sindresorhus/got/blob/main/documentation/7-retry.md
221
+ this._gotRetry = opts.gotRetry != null ? opts.gotRetry : { limit: 0 }
222
+
223
+ if (opts.validateResponses != null) this._validateResponses = opts.validateResponses
224
+ }
225
+
226
+ getLastUsedAssemblyUrl(): string {
227
+ return this._lastUsedAssemblyUrl
228
+ }
229
+
230
+ setDefaultTimeout(timeout: number): void {
231
+ this._defaultTimeout = timeout
232
+ }
233
+
234
+ /**
235
+ * Create an Assembly
236
+ *
237
+ * @param opts assembly options
238
+ */
239
+ createAssembly(opts: CreateAssemblyOptions = {}): CreateAssemblyPromise {
240
+ const {
241
+ params = {},
242
+ waitForCompletion = false,
243
+ chunkSize: requestedChunkSize = Number.POSITIVE_INFINITY,
244
+ uploadConcurrency = 10,
245
+ timeout = 24 * 60 * 60 * 1000, // 1 day
246
+ onUploadProgress = () => {},
247
+ onAssemblyProgress = () => {},
248
+ files = {},
249
+ uploads = {},
250
+ assemblyId,
251
+ signal,
252
+ } = opts
253
+
254
+ // Keep track of how long the request took
255
+ const startTimeMs = getHrTimeMs()
256
+
257
+ // Undocumented feature to allow specifying a custom assembly id from the client
258
+ // Not recommended for general use due to security. E.g if the user doesn't provide a cryptographically
259
+ // secure ID, then anyone could access the assembly.
260
+ let effectiveAssemblyId: string
261
+ if (assemblyId != null) {
262
+ effectiveAssemblyId = assemblyId
263
+ } else {
264
+ effectiveAssemblyId = randomUUID().replace(/-/g, '')
265
+ }
266
+ const urlSuffix = `/assemblies/${effectiveAssemblyId}`
267
+
268
+ // We want to be able to return the promise immediately with custom data
269
+ const promise = (async () => {
270
+ this._lastUsedAssemblyUrl = `${this._endpoint}${urlSuffix}`
271
+
272
+ await pMap(
273
+ Object.entries(files),
274
+ async ([, path]) => access(path, constants.F_OK | constants.R_OK),
275
+ { concurrency: 5 },
276
+ )
277
+
278
+ // Convert uploads to streams
279
+ const streamsMap = Object.fromEntries(
280
+ Object.entries(uploads).map(([label, value]) => {
281
+ const isReadable = isReadableStream(value)
282
+ if (!isReadable && isStream(value)) {
283
+ // https://github.com/transloadit/node-sdk/issues/92
284
+ throw new Error(`Upload named "${label}" is not a Readable stream`)
285
+ }
286
+
287
+ return [label, isReadableStream(value) ? value : intoStream(value)]
288
+ }),
289
+ )
290
+
291
+ // Wrap in object structure (so we can store whether it's a pathless stream or not)
292
+ const allStreamsMap = Object.fromEntries<Stream>(
293
+ Object.entries(streamsMap).map(([label, stream]) => [label, { stream }]),
294
+ )
295
+
296
+ // Create streams from files too
297
+ for (const [label, path] of Object.entries(files)) {
298
+ const stream = createReadStream(path)
299
+ allStreamsMap[label] = { stream, path } // File streams have path
300
+ }
301
+
302
+ const allStreams = Object.values(allStreamsMap)
303
+
304
+ // Pause all streams
305
+ for (const { stream } of allStreams) {
306
+ stream.pause()
307
+ }
308
+
309
+ // If any stream emits error, we want to handle this and exit with error.
310
+ // This promise races against createAssemblyAndUpload() below via Promise.race().
311
+ // When createAssemblyAndUpload wins the race, this promise becomes "orphaned" -
312
+ // it's no longer awaited, but stream error handlers remain attached.
313
+ // The no-op catch prevents Node's unhandled rejection warning if a stream
314
+ // errors after the race is already won.
315
+ const streamErrorPromise = new Promise<AssemblyStatus>((_resolve, reject) => {
316
+ for (const { stream } of allStreams) {
317
+ stream.on('error', reject)
318
+ }
319
+ })
320
+ streamErrorPromise.catch(() => {})
321
+
322
+ const createAssemblyAndUpload = async () => {
323
+ const result: AssemblyStatus = await this._remoteJson({
324
+ urlSuffix,
325
+ method: 'post',
326
+ timeout: { request: timeout },
327
+ params,
328
+ fields: {
329
+ tus_num_expected_upload_files: allStreams.length,
330
+ },
331
+ signal,
332
+ })
333
+ checkResult(result)
334
+
335
+ if (Object.keys(allStreamsMap).length > 0) {
336
+ await sendTusRequest({
337
+ streamsMap: allStreamsMap,
338
+ assembly: result,
339
+ onProgress: onUploadProgress,
340
+ requestedChunkSize,
341
+ uploadConcurrency,
342
+ signal,
343
+ })
344
+ }
345
+
346
+ if (!waitForCompletion) return result
347
+
348
+ if (result.assembly_id == null) {
349
+ throw new InconsistentResponseError(
350
+ 'Server returned an assembly response without an assembly_id after creation',
351
+ )
352
+ }
353
+ const awaitResult = await this.awaitAssemblyCompletion(result.assembly_id, {
354
+ timeout,
355
+ onAssemblyProgress,
356
+ startTimeMs,
357
+ signal,
358
+ })
359
+ checkResult(awaitResult)
360
+ return awaitResult
361
+ }
362
+
363
+ return Promise.race([createAssemblyAndUpload(), streamErrorPromise])
364
+ })()
365
+
366
+ // This allows the user to use or log the assemblyId even before it has been created for easier debugging
367
+ return Object.assign(promise, { assemblyId: effectiveAssemblyId })
368
+ }
369
+
370
+ async awaitAssemblyCompletion(
371
+ assemblyId: string,
372
+ {
373
+ onAssemblyProgress = () => {},
374
+ timeout,
375
+ startTimeMs = getHrTimeMs(),
376
+ interval = 1000,
377
+ signal,
378
+ onPoll,
379
+ }: AwaitAssemblyCompletionOptions = {},
380
+ ): Promise<AssemblyStatus> {
381
+ assert.ok(assemblyId)
382
+
383
+ let lastResult: AssemblyStatus | undefined
384
+
385
+ while (true) {
386
+ // Check if caller wants to stop polling early
387
+ if (onPoll?.() === false && lastResult) {
388
+ return lastResult
389
+ }
390
+
391
+ // Check if aborted before making the request
392
+ if (signal?.aborted) {
393
+ throw signal.reason ?? new DOMException('Aborted', 'AbortError')
394
+ }
395
+
396
+ const result = await this.getAssembly(assemblyId, { signal })
397
+ lastResult = result
398
+
399
+ // If 'ok' is not in result, it implies a terminal state (e.g., error, completed, canceled).
400
+ // If 'ok' is present, then we check if it's one of the non-terminal polling states.
401
+ if (
402
+ !('ok' in result) ||
403
+ (result.ok !== 'ASSEMBLY_UPLOADING' &&
404
+ result.ok !== 'ASSEMBLY_EXECUTING' &&
405
+ // ASSEMBLY_REPLAYING is not a valid 'ok' status for polling, it means it's done replaying.
406
+ // The API does not seem to have an ASSEMBLY_REPLAYING status in the typical polling loop.
407
+ // It's usually a final status from the replay endpoint.
408
+ // For polling, we only care about UPLOADING and EXECUTING.
409
+ // If a replay operation puts it into a pollable state, that state would be EXECUTING.
410
+ result.ok !== 'ASSEMBLY_REPLAYING') // This line might need review based on actual API behavior for replayed assembly polling
411
+ ) {
412
+ return result // Done!
413
+ }
414
+
415
+ try {
416
+ onAssemblyProgress(result)
417
+ } catch (err) {
418
+ log('Caught onAssemblyProgress error', err)
419
+ }
420
+
421
+ const nowMs = getHrTimeMs()
422
+ if (timeout != null && nowMs - startTimeMs >= timeout) {
423
+ throw new PollingTimeoutError('Polling timed out')
424
+ }
425
+
426
+ // Make the sleep abortable, ensuring listener cleanup to prevent memory leaks
427
+ await new Promise<void>((resolve, reject) => {
428
+ const timeoutId = setTimeout(() => {
429
+ signal?.removeEventListener('abort', onAbort)
430
+ resolve()
431
+ }, interval)
432
+
433
+ function onAbort() {
434
+ clearTimeout(timeoutId)
435
+ reject(signal?.reason ?? new DOMException('Aborted', 'AbortError'))
436
+ }
437
+
438
+ signal?.addEventListener('abort', onAbort, { once: true })
439
+ })
440
+ }
441
+ }
442
+
443
+ maybeThrowInconsistentResponseError(message: string) {
444
+ const err = new InconsistentResponseError(message)
445
+
446
+ // @TODO, once our schemas have matured, we should remove the option and always throw the error here.
447
+ // But as it stands, schemas are new, and we can't easily update all customer's node-sdks,
448
+ // so there will be a long tail of throws if we enable this now.
449
+ if (this._validateResponses) {
450
+ throw err
451
+ }
452
+
453
+ console.error(
454
+ `---\nPlease report this error to Transloadit (support@transloadit.com). We are working on better schemas for our API and this looks like something we do not cover yet: \n\n${err}\nThank you in advance!\n---\n`,
455
+ )
456
+ }
457
+
458
+ /**
459
+ * Cancel the assembly
460
+ *
461
+ * @param assemblyId assembly ID
462
+ * @returns after the assembly is deleted
463
+ */
464
+ async cancelAssembly(assemblyId: string): Promise<AssemblyStatus> {
465
+ const { assembly_ssl_url: url } = await this.getAssembly(assemblyId)
466
+ const rawResult = await this._remoteJson<Record<string, unknown>, OptionalAuthParams>({
467
+ url,
468
+ method: 'delete',
469
+ })
470
+
471
+ const parsedResult = zodParseWithContext(assemblyStatusSchema, rawResult)
472
+
473
+ if (!parsedResult.success) {
474
+ this.maybeThrowInconsistentResponseError(
475
+ `The API responded with data that does not match the expected schema while cancelling Assembly: ${assemblyId}.\n${parsedResult.humanReadable}`,
476
+ )
477
+ }
478
+
479
+ checkAssemblyUrls(rawResult as AssemblyStatus)
480
+ return rawResult as AssemblyStatus
481
+ }
482
+
483
+ /**
484
+ * Replay an Assembly
485
+ *
486
+ * @param assemblyId of the assembly to replay
487
+ * @param optional params
488
+ * @returns after the replay is started
489
+ */
490
+ async replayAssembly(
491
+ assemblyId: string,
492
+ params: ReplayAssemblyParams = {},
493
+ ): Promise<ReplayAssemblyResponse> {
494
+ const result: ReplayAssemblyResponse = await this._remoteJson({
495
+ urlSuffix: `/assemblies/${assemblyId}/replay`,
496
+ method: 'post',
497
+ ...(Object.keys(params).length > 0 && { params }),
498
+ })
499
+ checkResult(result)
500
+ return result
501
+ }
502
+
503
+ /**
504
+ * Replay an Assembly notification
505
+ *
506
+ * @param assemblyId of the assembly whose notification to replay
507
+ * @param optional params
508
+ * @returns after the replay is started
509
+ */
510
+ async replayAssemblyNotification(
511
+ assemblyId: string,
512
+ params: ReplayAssemblyNotificationParams = {},
513
+ ): Promise<ReplayAssemblyNotificationResponse> {
514
+ return await this._remoteJson({
515
+ urlSuffix: `/assembly_notifications/${assemblyId}/replay`,
516
+ method: 'post',
517
+ ...(Object.keys(params).length > 0 && { params }),
518
+ })
519
+ }
520
+
521
+ /**
522
+ * List all assemblies
523
+ *
524
+ * @param params optional request options
525
+ * @returns list of Assemblies
526
+ */
527
+ async listAssemblies(
528
+ params?: ListAssembliesParams,
529
+ ): Promise<PaginationListWithCount<AssemblyIndexItem>> {
530
+ const rawResponse = await this._remoteJson<
531
+ PaginationListWithCount<Record<string, unknown>>,
532
+ ListAssembliesParams
533
+ >({
534
+ urlSuffix: '/assemblies',
535
+ method: 'get',
536
+ params: params || {},
537
+ })
538
+
539
+ if (
540
+ rawResponse == null ||
541
+ typeof rawResponse !== 'object' ||
542
+ !Array.isArray(rawResponse.items)
543
+ ) {
544
+ throw new InconsistentResponseError(
545
+ 'API response for listAssemblies is malformed or missing items array',
546
+ )
547
+ }
548
+
549
+ const parsedResult = zodParseWithContext(assemblyIndexSchema, rawResponse.items)
550
+
551
+ if (!parsedResult.success) {
552
+ this.maybeThrowInconsistentResponseError(
553
+ `API response for listAssemblies contained items that do not match the expected schema.\n${parsedResult.humanReadable}`,
554
+ )
555
+ }
556
+
557
+ return {
558
+ items: rawResponse.items as AssemblyIndex,
559
+ count: rawResponse.count,
560
+ }
561
+ }
562
+
563
+ streamAssemblies(params: ListAssembliesParams): Readable {
564
+ return new PaginationStream(async (page) => this.listAssemblies({ ...params, page }))
565
+ }
566
+
567
+ /**
568
+ * Get an Assembly
569
+ *
570
+ * @param assemblyId the Assembly Id
571
+ * @param options optional request options
572
+ * @returns the retrieved Assembly
573
+ */
574
+ async getAssembly(
575
+ assemblyId: string,
576
+ options?: { signal?: AbortSignal },
577
+ ): Promise<AssemblyStatus> {
578
+ const rawResult = await this._remoteJson<Record<string, unknown>, OptionalAuthParams>({
579
+ urlSuffix: `/assemblies/${assemblyId}`,
580
+ signal: options?.signal,
581
+ })
582
+
583
+ const parsedResult = zodParseWithContext(assemblyStatusSchema, rawResult)
584
+
585
+ if (!parsedResult.success) {
586
+ this.maybeThrowInconsistentResponseError(
587
+ `The API responded with data that does not match the expected schema while getting Assembly: ${assemblyId}.\n${parsedResult.humanReadable}`,
588
+ )
589
+ }
590
+
591
+ checkAssemblyUrls(rawResult as AssemblyStatus)
592
+ return rawResult as AssemblyStatus
593
+ }
594
+
595
+ /**
596
+ * Create a Credential
597
+ *
598
+ * @param params optional request options
599
+ * @returns when the Credential is created
600
+ */
601
+ async createTemplateCredential(
602
+ params: CreateTemplateCredentialParams,
603
+ ): Promise<TemplateCredentialResponse> {
604
+ return await this._remoteJson({
605
+ urlSuffix: '/template_credentials',
606
+ method: 'post',
607
+ params: params || {},
608
+ })
609
+ }
610
+
611
+ /**
612
+ * Edit a Credential
613
+ *
614
+ * @param credentialId the Credential ID
615
+ * @param params optional request options
616
+ * @returns when the Credential is edited
617
+ */
618
+ async editTemplateCredential(
619
+ credentialId: string,
620
+ params: CreateTemplateCredentialParams,
621
+ ): Promise<TemplateCredentialResponse> {
622
+ return await this._remoteJson({
623
+ urlSuffix: `/template_credentials/${credentialId}`,
624
+ method: 'put',
625
+ params: params || {},
626
+ })
627
+ }
628
+
629
+ /**
630
+ * Delete a Credential
631
+ *
632
+ * @param credentialId the Credential ID
633
+ * @returns when the Credential is deleted
634
+ */
635
+ async deleteTemplateCredential(credentialId: string): Promise<BaseResponse> {
636
+ return await this._remoteJson({
637
+ urlSuffix: `/template_credentials/${credentialId}`,
638
+ method: 'delete',
639
+ })
640
+ }
641
+
642
+ /**
643
+ * Get a Credential
644
+ *
645
+ * @param credentialId the Credential ID
646
+ * @returns when the Credential is retrieved
647
+ */
648
+ async getTemplateCredential(credentialId: string): Promise<TemplateCredentialResponse> {
649
+ return await this._remoteJson({
650
+ urlSuffix: `/template_credentials/${credentialId}`,
651
+ method: 'get',
652
+ })
653
+ }
654
+
655
+ /**
656
+ * List all TemplateCredentials
657
+ *
658
+ * @param params optional request options
659
+ * @returns the list of templates
660
+ */
661
+ async listTemplateCredentials(
662
+ params?: ListTemplateCredentialsParams,
663
+ ): Promise<TemplateCredentialsResponse> {
664
+ return await this._remoteJson({
665
+ urlSuffix: '/template_credentials',
666
+ method: 'get',
667
+ params: params || {},
668
+ })
669
+ }
670
+
671
+ streamTemplateCredentials(params: ListTemplateCredentialsParams) {
672
+ return new PaginationStream(async (page) => ({
673
+ items: (await this.listTemplateCredentials({ ...params, page })).credentials,
674
+ }))
675
+ }
676
+
677
+ /**
678
+ * Create an Assembly Template
679
+ *
680
+ * @param params optional request options
681
+ * @returns when the template is created
682
+ */
683
+ async createTemplate(params: CreateTemplateParams): Promise<TemplateResponse> {
684
+ return await this._remoteJson({
685
+ urlSuffix: '/templates',
686
+ method: 'post',
687
+ params: params || {},
688
+ })
689
+ }
690
+
691
+ /**
692
+ * Edit an Assembly Template
693
+ *
694
+ * @param templateId the template ID
695
+ * @param params optional request options
696
+ * @returns when the template is edited
697
+ */
698
+ async editTemplate(templateId: string, params: EditTemplateParams): Promise<TemplateResponse> {
699
+ return await this._remoteJson({
700
+ urlSuffix: `/templates/${templateId}`,
701
+ method: 'put',
702
+ params: params || {},
703
+ })
704
+ }
705
+
706
+ /**
707
+ * Delete an Assembly Template
708
+ *
709
+ * @param templateId the template ID
710
+ * @returns when the template is deleted
711
+ */
712
+ async deleteTemplate(templateId: string): Promise<BaseResponse> {
713
+ return await this._remoteJson({
714
+ urlSuffix: `/templates/${templateId}`,
715
+ method: 'delete',
716
+ })
717
+ }
718
+
719
+ /**
720
+ * Get an Assembly Template
721
+ *
722
+ * @param templateId the template ID
723
+ * @returns when the template is retrieved
724
+ */
725
+ async getTemplate(templateId: string): Promise<TemplateResponse> {
726
+ return await this._remoteJson({
727
+ urlSuffix: `/templates/${templateId}`,
728
+ method: 'get',
729
+ })
730
+ }
731
+
732
+ /**
733
+ * List all Assembly Templates
734
+ *
735
+ * @param params optional request options
736
+ * @returns the list of templates
737
+ */
738
+ async listTemplates(
739
+ params?: ListTemplatesParams,
740
+ ): Promise<PaginationListWithCount<ListedTemplate>> {
741
+ return await this._remoteJson({
742
+ urlSuffix: '/templates',
743
+ method: 'get',
744
+ params: params || {},
745
+ })
746
+ }
747
+
748
+ streamTemplates(params?: ListTemplatesParams): PaginationStream<ListedTemplate> {
749
+ return new PaginationStream(async (page) => this.listTemplates({ ...params, page }))
750
+ }
751
+
752
+ /**
753
+ * Get account Billing details for a specific month
754
+ *
755
+ * @param month the date for the required billing in the format yyyy-mm
756
+ * @returns with billing data
757
+ * @see https://transloadit.com/docs/api/bill-date-get/
758
+ */
759
+ async getBill(month: string): Promise<BillResponse> {
760
+ assert.ok(month, 'month is required')
761
+ return await this._remoteJson({
762
+ urlSuffix: `/bill/${month}`,
763
+ method: 'get',
764
+ })
765
+ }
766
+
767
+ calcSignature(
768
+ params: OptionalAuthParams,
769
+ algorithm?: string,
770
+ ): { signature: string; params: string } {
771
+ const jsonParams = this._prepareParams(params)
772
+ const signature = this._calcSignature(jsonParams, algorithm)
773
+
774
+ return { signature, params: jsonParams }
775
+ }
776
+
777
+ /**
778
+ * Construct a signed Smart CDN URL. See https://transloadit.com/docs/topics/signature-authentication/#smart-cdn.
779
+ */
780
+ getSignedSmartCDNUrl(opts: SmartCDNUrlOptions): string {
781
+ if (opts.workspace == null || opts.workspace === '')
782
+ throw new TypeError('workspace is required')
783
+ if (opts.template == null || opts.template === '') throw new TypeError('template is required')
784
+ if (opts.input == null) throw new TypeError('input is required') // `input` can be an empty string.
785
+
786
+ const workspaceSlug = encodeURIComponent(opts.workspace)
787
+ const templateSlug = encodeURIComponent(opts.template)
788
+ const inputField = encodeURIComponent(opts.input)
789
+ const expiresAt = opts.expiresAt || Date.now() + 60 * 60 * 1000 // 1 hour
790
+
791
+ const queryParams = new URLSearchParams()
792
+ for (const [key, value] of Object.entries(opts.urlParams || {})) {
793
+ if (Array.isArray(value)) {
794
+ for (const val of value) {
795
+ queryParams.append(key, `${val}`)
796
+ }
797
+ } else {
798
+ queryParams.append(key, `${value}`)
799
+ }
800
+ }
801
+
802
+ queryParams.set('auth_key', this._authKey)
803
+ queryParams.set('exp', `${expiresAt}`)
804
+ // The signature changes depending on the order of the query parameters. We therefore sort them on the client-
805
+ // and server-side to ensure that we do not get mismatching signatures if a proxy changes the order of query
806
+ // parameters or implementations handle query parameters ordering differently.
807
+ queryParams.sort()
808
+
809
+ const stringToSign = `${workspaceSlug}/${templateSlug}/${inputField}?${queryParams}`
810
+ const algorithm = 'sha256'
811
+ const signature = createHmac(algorithm, this._authSecret).update(stringToSign).digest('hex')
812
+
813
+ queryParams.set('sig', `sha256:${signature}`)
814
+ const signedUrl = `https://${workspaceSlug}.tlcdn.com/${templateSlug}/${inputField}?${queryParams}`
815
+ return signedUrl
816
+ }
817
+
818
+ private _calcSignature(toSign: string, algorithm = 'sha384'): string {
819
+ return `${algorithm}:${createHmac(algorithm, this._authSecret)
820
+ .update(Buffer.from(toSign, 'utf-8'))
821
+ .digest('hex')}`
822
+ }
823
+
824
+ // Sets the multipart/form-data for POST, PUT and DELETE requests, including
825
+ // the streams, the signed params, and any additional fields.
826
+ private _appendForm(form: FormData, params: OptionalAuthParams, fields?: Fields): void {
827
+ const sigData = this.calcSignature(params)
828
+ const jsonParams = sigData.params
829
+ const { signature } = sigData
830
+
831
+ form.append('params', jsonParams)
832
+
833
+ if (fields != null) {
834
+ for (const [key, val] of Object.entries(fields)) {
835
+ form.append(key, val)
836
+ }
837
+ }
838
+
839
+ form.append('signature', signature)
840
+ }
841
+
842
+ // Implements HTTP GET query params, handling the case where the url already
843
+ // has params.
844
+ private _appendParamsToUrl(url: string, params: OptionalAuthParams): string {
845
+ const { signature, params: jsonParams } = this.calcSignature(params)
846
+
847
+ const prefix = url.indexOf('?') === -1 ? '?' : '&'
848
+
849
+ return `${url}${prefix}signature=${signature}&params=${encodeURIComponent(jsonParams)}`
850
+ }
851
+
852
+ // Responsible for including auth parameters in all requests
853
+ private _prepareParams(paramsIn?: OptionalAuthParams): string {
854
+ let params = paramsIn
855
+ if (params == null) {
856
+ params = {}
857
+ }
858
+ if (params.auth == null) {
859
+ params.auth = {}
860
+ }
861
+ if (params.auth.key == null) {
862
+ params.auth.key = this._authKey
863
+ }
864
+ if (params.auth.expires == null) {
865
+ params.auth.expires = this._getExpiresDate()
866
+ }
867
+
868
+ return JSON.stringify(params)
869
+ }
870
+
871
+ // We want to mock this method
872
+ private _getExpiresDate(): string {
873
+ const expiresDate = new Date()
874
+ expiresDate.setDate(expiresDate.getDate() + 1)
875
+ return expiresDate.toISOString()
876
+ }
877
+
878
+ // Responsible for making API calls. Automatically sends streams with any POST,
879
+ // PUT or DELETE requests. Automatically adds signature parameters to all
880
+ // requests. Also automatically parses the JSON response.
881
+ private async _remoteJson<TRet, TParams extends OptionalAuthParams>(opts: {
882
+ urlSuffix?: string
883
+ url?: string
884
+ timeout?: Delays
885
+ method?: 'delete' | 'get' | 'post' | 'put'
886
+ params?: TParams
887
+ fields?: Fields
888
+ headers?: Headers
889
+ signal?: AbortSignal
890
+ }): Promise<TRet> {
891
+ const {
892
+ urlSuffix,
893
+ url: urlInput,
894
+ timeout = { request: this._defaultTimeout },
895
+ method = 'get',
896
+ params = {},
897
+ fields,
898
+ headers,
899
+ signal,
900
+ } = opts
901
+
902
+ // Allow providing either a `urlSuffix` or a full `url`
903
+ if (!urlSuffix && !urlInput) throw new Error('No URL provided')
904
+ let url = urlInput || `${this._endpoint}${urlSuffix}`
905
+
906
+ if (method === 'get') {
907
+ url = this._appendParamsToUrl(url, params)
908
+ }
909
+
910
+ log('Sending request', method, url)
911
+
912
+ // todo use got.retry instead because we are no longer using FormData (which is a stream and can only be used once)
913
+ // https://github.com/sindresorhus/got/issues/1282
914
+ for (let retryCount = 0; ; retryCount++) {
915
+ let form: FormData | undefined
916
+
917
+ if (method === 'post' || method === 'put' || method === 'delete') {
918
+ form = new FormData()
919
+ this._appendForm(form, params, fields)
920
+ }
921
+
922
+ const requestOpts: OptionsOfJSONResponseBody = {
923
+ retry: this._gotRetry,
924
+ body: form,
925
+ timeout,
926
+ headers: {
927
+ 'Transloadit-Client': `node-sdk:${version}`,
928
+ 'User-Agent': undefined, // Remove got's user-agent
929
+ ...headers,
930
+ },
931
+ responseType: 'json',
932
+ signal,
933
+ }
934
+
935
+ try {
936
+ const request = got[method]<TRet>(url, requestOpts)
937
+ const { body } = await request
938
+ // console.log(body)
939
+ return body
940
+ } catch (err) {
941
+ if (!(err instanceof RequestError)) throw err
942
+
943
+ if (err instanceof HTTPError) {
944
+ const { statusCode, body } = err.response
945
+ logWarn('HTTP error', statusCode, body)
946
+
947
+ // check whether we should retry
948
+ // https://transloadit.com/blog/2012/04/introducing-rate-limiting/
949
+ if (
950
+ typeof body === 'object' &&
951
+ body != null &&
952
+ 'error' in body &&
953
+ 'info' in body &&
954
+ typeof body.info === 'object' &&
955
+ body.info != null &&
956
+ 'retryIn' in body.info &&
957
+ typeof body.info.retryIn === 'number' &&
958
+ Boolean(body.info.retryIn) &&
959
+ retryCount < this._maxRetries && // 413 taken from https://transloadit.com/blog/2012/04/introducing-rate-limiting/
960
+ // todo can 413 be removed?
961
+ ((statusCode === 413 && body.error === 'RATE_LIMIT_REACHED') || statusCode === 429)
962
+ ) {
963
+ const { retryIn: retryInSec } = body.info
964
+ logWarn(`Rate limit reached, retrying request in approximately ${retryInSec} seconds.`)
965
+ const retryInMs = 1000 * (retryInSec * (1 + 0.1 * Math.random()))
966
+ await delay(retryInMs)
967
+ // Retry
968
+ } else {
969
+ throw new ApiError({
970
+ cause: err,
971
+ body: err.response?.body as TransloaditErrorResponseBody | undefined,
972
+ }) // todo don't assert type
973
+ }
974
+ } else {
975
+ throw err
976
+ }
977
+ }
978
+ }
979
+ }
980
+ }