@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.
- package/LICENSE +21 -0
- package/README.md +701 -0
- package/dist/ApiError.d.ts +22 -0
- package/dist/ApiError.d.ts.map +1 -0
- package/dist/ApiError.js +33 -0
- package/dist/ApiError.js.map +1 -0
- package/dist/InconsistentResponseError.d.ts +4 -0
- package/dist/InconsistentResponseError.d.ts.map +1 -0
- package/dist/InconsistentResponseError.js +4 -0
- package/dist/InconsistentResponseError.js.map +1 -0
- package/dist/PaginationStream.d.ts +14 -0
- package/dist/PaginationStream.d.ts.map +1 -0
- package/dist/PaginationStream.js +36 -0
- package/dist/PaginationStream.js.map +1 -0
- package/dist/PollingTimeoutError.d.ts +5 -0
- package/dist/PollingTimeoutError.d.ts.map +1 -0
- package/dist/PollingTimeoutError.js +5 -0
- package/dist/PollingTimeoutError.js.map +1 -0
- package/dist/Transloadit.d.ts +250 -0
- package/dist/Transloadit.d.ts.map +1 -0
- package/dist/Transloadit.js +661 -0
- package/dist/Transloadit.js.map +1 -0
- package/dist/alphalib/lib/nativeGlobby.d.ts +14 -0
- package/dist/alphalib/lib/nativeGlobby.d.ts.map +1 -0
- package/dist/alphalib/lib/nativeGlobby.js +181 -0
- package/dist/alphalib/lib/nativeGlobby.js.map +1 -0
- package/dist/alphalib/mcache.d.ts +65 -0
- package/dist/alphalib/mcache.d.ts.map +1 -0
- package/dist/alphalib/mcache.js +135 -0
- package/dist/alphalib/mcache.js.map +1 -0
- package/dist/alphalib/tryCatch.d.ts +21 -0
- package/dist/alphalib/tryCatch.d.ts.map +1 -0
- package/dist/alphalib/tryCatch.js +17 -0
- package/dist/alphalib/tryCatch.js.map +1 -0
- package/dist/alphalib/types/assembliesGet.d.ts +62 -0
- package/dist/alphalib/types/assembliesGet.d.ts.map +1 -0
- package/dist/alphalib/types/assembliesGet.js +33 -0
- package/dist/alphalib/types/assembliesGet.js.map +1 -0
- package/dist/alphalib/types/assemblyReplay.d.ts +7858 -0
- package/dist/alphalib/types/assemblyReplay.d.ts.map +1 -0
- package/dist/alphalib/types/assemblyReplay.js +15 -0
- package/dist/alphalib/types/assemblyReplay.js.map +1 -0
- package/dist/alphalib/types/assemblyReplayNotification.d.ts +7849 -0
- package/dist/alphalib/types/assemblyReplayNotification.d.ts.map +1 -0
- package/dist/alphalib/types/assemblyReplayNotification.js +13 -0
- package/dist/alphalib/types/assemblyReplayNotification.js.map +1 -0
- package/dist/alphalib/types/assemblyStatus.d.ts +71084 -0
- package/dist/alphalib/types/assemblyStatus.d.ts.map +1 -0
- package/dist/alphalib/types/assemblyStatus.js +710 -0
- package/dist/alphalib/types/assemblyStatus.js.map +1 -0
- package/dist/alphalib/types/bill.d.ts +44 -0
- package/dist/alphalib/types/bill.d.ts.map +1 -0
- package/dist/alphalib/types/bill.js +8 -0
- package/dist/alphalib/types/bill.js.map +1 -0
- package/dist/alphalib/types/robots/_index.d.ts +76306 -0
- package/dist/alphalib/types/robots/_index.d.ts.map +1 -0
- package/dist/alphalib/types/robots/_index.js +354 -0
- package/dist/alphalib/types/robots/_index.js.map +1 -0
- package/dist/alphalib/types/robots/_instructions-primitives.d.ts +3533 -0
- package/dist/alphalib/types/robots/_instructions-primitives.d.ts.map +1 -0
- package/dist/alphalib/types/robots/_instructions-primitives.js +1491 -0
- package/dist/alphalib/types/robots/_instructions-primitives.js.map +1 -0
- package/dist/alphalib/types/robots/ai-chat.d.ts +2096 -0
- package/dist/alphalib/types/robots/ai-chat.d.ts.map +1 -0
- package/dist/alphalib/types/robots/ai-chat.js +223 -0
- package/dist/alphalib/types/robots/ai-chat.js.map +1 -0
- package/dist/alphalib/types/robots/assembly-savejson.d.ts +52 -0
- package/dist/alphalib/types/robots/assembly-savejson.d.ts.map +1 -0
- package/dist/alphalib/types/robots/assembly-savejson.js +22 -0
- package/dist/alphalib/types/robots/assembly-savejson.js.map +1 -0
- package/dist/alphalib/types/robots/audio-artwork.d.ts +2867 -0
- package/dist/alphalib/types/robots/audio-artwork.d.ts.map +1 -0
- package/dist/alphalib/types/robots/audio-artwork.js +73 -0
- package/dist/alphalib/types/robots/audio-artwork.js.map +1 -0
- package/dist/alphalib/types/robots/audio-concat.d.ts +2916 -0
- package/dist/alphalib/types/robots/audio-concat.d.ts.map +1 -0
- package/dist/alphalib/types/robots/audio-concat.js +106 -0
- package/dist/alphalib/types/robots/audio-concat.js.map +1 -0
- package/dist/alphalib/types/robots/audio-encode.d.ts +2864 -0
- package/dist/alphalib/types/robots/audio-encode.d.ts.map +1 -0
- package/dist/alphalib/types/robots/audio-encode.js +67 -0
- package/dist/alphalib/types/robots/audio-encode.js.map +1 -0
- package/dist/alphalib/types/robots/audio-loop.d.ts +2879 -0
- package/dist/alphalib/types/robots/audio-loop.d.ts.map +1 -0
- package/dist/alphalib/types/robots/audio-loop.js +67 -0
- package/dist/alphalib/types/robots/audio-loop.js.map +1 -0
- package/dist/alphalib/types/robots/audio-merge.d.ts +2931 -0
- package/dist/alphalib/types/robots/audio-merge.d.ts.map +1 -0
- package/dist/alphalib/types/robots/audio-merge.js +101 -0
- package/dist/alphalib/types/robots/audio-merge.js.map +1 -0
- package/dist/alphalib/types/robots/audio-waveform.d.ts +3131 -0
- package/dist/alphalib/types/robots/audio-waveform.d.ts.map +1 -0
- package/dist/alphalib/types/robots/audio-waveform.js +238 -0
- package/dist/alphalib/types/robots/audio-waveform.js.map +1 -0
- package/dist/alphalib/types/robots/azure-import.d.ts +210 -0
- package/dist/alphalib/types/robots/azure-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/azure-import.js +73 -0
- package/dist/alphalib/types/robots/azure-import.js.map +1 -0
- package/dist/alphalib/types/robots/azure-store.d.ts +562 -0
- package/dist/alphalib/types/robots/azure-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/azure-store.js +115 -0
- package/dist/alphalib/types/robots/azure-store.js.map +1 -0
- package/dist/alphalib/types/robots/backblaze-import.d.ts +210 -0
- package/dist/alphalib/types/robots/backblaze-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/backblaze-import.js +81 -0
- package/dist/alphalib/types/robots/backblaze-import.js.map +1 -0
- package/dist/alphalib/types/robots/backblaze-store.d.ts +478 -0
- package/dist/alphalib/types/robots/backblaze-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/backblaze-store.js +76 -0
- package/dist/alphalib/types/robots/backblaze-store.js.map +1 -0
- package/dist/alphalib/types/robots/cloudfiles-import.d.ts +234 -0
- package/dist/alphalib/types/robots/cloudfiles-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/cloudfiles-import.js +80 -0
- package/dist/alphalib/types/robots/cloudfiles-import.js.map +1 -0
- package/dist/alphalib/types/robots/cloudfiles-store.d.ts +490 -0
- package/dist/alphalib/types/robots/cloudfiles-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/cloudfiles-store.js +70 -0
- package/dist/alphalib/types/robots/cloudfiles-store.js.map +1 -0
- package/dist/alphalib/types/robots/cloudflare-import.d.ts +234 -0
- package/dist/alphalib/types/robots/cloudflare-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/cloudflare-import.js +81 -0
- package/dist/alphalib/types/robots/cloudflare-import.js.map +1 -0
- package/dist/alphalib/types/robots/cloudflare-store.d.ts +514 -0
- package/dist/alphalib/types/robots/cloudflare-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/cloudflare-store.js +86 -0
- package/dist/alphalib/types/robots/cloudflare-store.js.map +1 -0
- package/dist/alphalib/types/robots/digitalocean-import.d.ts +234 -0
- package/dist/alphalib/types/robots/digitalocean-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/digitalocean-import.js +78 -0
- package/dist/alphalib/types/robots/digitalocean-import.js.map +1 -0
- package/dist/alphalib/types/robots/digitalocean-store.d.ts +526 -0
- package/dist/alphalib/types/robots/digitalocean-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/digitalocean-store.js +91 -0
- package/dist/alphalib/types/robots/digitalocean-store.js.map +1 -0
- package/dist/alphalib/types/robots/document-autorotate.d.ts +405 -0
- package/dist/alphalib/types/robots/document-autorotate.d.ts.map +1 -0
- package/dist/alphalib/types/robots/document-autorotate.js +44 -0
- package/dist/alphalib/types/robots/document-autorotate.js.map +1 -0
- package/dist/alphalib/types/robots/document-convert.d.ts +513 -0
- package/dist/alphalib/types/robots/document-convert.d.ts.map +1 -0
- package/dist/alphalib/types/robots/document-convert.js +273 -0
- package/dist/alphalib/types/robots/document-convert.js.map +1 -0
- package/dist/alphalib/types/robots/document-merge.d.ts +429 -0
- package/dist/alphalib/types/robots/document-merge.d.ts.map +1 -0
- package/dist/alphalib/types/robots/document-merge.js +86 -0
- package/dist/alphalib/types/robots/document-merge.js.map +1 -0
- package/dist/alphalib/types/robots/document-ocr.d.ts +441 -0
- package/dist/alphalib/types/robots/document-ocr.d.ts.map +1 -0
- package/dist/alphalib/types/robots/document-ocr.js +86 -0
- package/dist/alphalib/types/robots/document-ocr.js.map +1 -0
- package/dist/alphalib/types/robots/document-split.d.ts +417 -0
- package/dist/alphalib/types/robots/document-split.d.ts.map +1 -0
- package/dist/alphalib/types/robots/document-split.js +48 -0
- package/dist/alphalib/types/robots/document-split.js.map +1 -0
- package/dist/alphalib/types/robots/document-thumbs.d.ts +592 -0
- package/dist/alphalib/types/robots/document-thumbs.d.ts.map +1 -0
- package/dist/alphalib/types/robots/document-thumbs.js +196 -0
- package/dist/alphalib/types/robots/document-thumbs.js.map +1 -0
- package/dist/alphalib/types/robots/dropbox-import.d.ts +144 -0
- package/dist/alphalib/types/robots/dropbox-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/dropbox-import.js +65 -0
- package/dist/alphalib/types/robots/dropbox-import.js.map +1 -0
- package/dist/alphalib/types/robots/dropbox-store.d.ts +449 -0
- package/dist/alphalib/types/robots/dropbox-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/dropbox-store.js +68 -0
- package/dist/alphalib/types/robots/dropbox-store.js.map +1 -0
- package/dist/alphalib/types/robots/edgly-deliver.d.ts +100 -0
- package/dist/alphalib/types/robots/edgly-deliver.d.ts.map +1 -0
- package/dist/alphalib/types/robots/edgly-deliver.js +46 -0
- package/dist/alphalib/types/robots/edgly-deliver.js.map +1 -0
- package/dist/alphalib/types/robots/file-compress.d.ts +477 -0
- package/dist/alphalib/types/robots/file-compress.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-compress.js +139 -0
- package/dist/alphalib/types/robots/file-compress.js.map +1 -0
- package/dist/alphalib/types/robots/file-decompress.d.ts +404 -0
- package/dist/alphalib/types/robots/file-decompress.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-decompress.js +94 -0
- package/dist/alphalib/types/robots/file-decompress.js.map +1 -0
- package/dist/alphalib/types/robots/file-filter.d.ts +465 -0
- package/dist/alphalib/types/robots/file-filter.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-filter.js +136 -0
- package/dist/alphalib/types/robots/file-filter.js.map +1 -0
- package/dist/alphalib/types/robots/file-hash.d.ts +417 -0
- package/dist/alphalib/types/robots/file-hash.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-hash.js +59 -0
- package/dist/alphalib/types/robots/file-hash.js.map +1 -0
- package/dist/alphalib/types/robots/file-preview.d.ts +854 -0
- package/dist/alphalib/types/robots/file-preview.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-preview.js +221 -0
- package/dist/alphalib/types/robots/file-preview.js.map +1 -0
- package/dist/alphalib/types/robots/file-read.d.ts +405 -0
- package/dist/alphalib/types/robots/file-read.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-read.js +44 -0
- package/dist/alphalib/types/robots/file-read.js.map +1 -0
- package/dist/alphalib/types/robots/file-serve.d.ts +418 -0
- package/dist/alphalib/types/robots/file-serve.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-serve.js +99 -0
- package/dist/alphalib/types/robots/file-serve.js.map +1 -0
- package/dist/alphalib/types/robots/file-verify.d.ts +441 -0
- package/dist/alphalib/types/robots/file-verify.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-verify.js +73 -0
- package/dist/alphalib/types/robots/file-verify.js.map +1 -0
- package/dist/alphalib/types/robots/file-virusscan.d.ts +435 -0
- package/dist/alphalib/types/robots/file-virusscan.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-virusscan.js +82 -0
- package/dist/alphalib/types/robots/file-virusscan.js.map +1 -0
- package/dist/alphalib/types/robots/file-watermark.d.ts +417 -0
- package/dist/alphalib/types/robots/file-watermark.d.ts.map +1 -0
- package/dist/alphalib/types/robots/file-watermark.js +28 -0
- package/dist/alphalib/types/robots/file-watermark.js.map +1 -0
- package/dist/alphalib/types/robots/ftp-import.d.ts +198 -0
- package/dist/alphalib/types/robots/ftp-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/ftp-import.js +60 -0
- package/dist/alphalib/types/robots/ftp-import.js.map +1 -0
- package/dist/alphalib/types/robots/ftp-store.d.ts +532 -0
- package/dist/alphalib/types/robots/ftp-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/ftp-store.js +91 -0
- package/dist/alphalib/types/robots/ftp-store.js.map +1 -0
- package/dist/alphalib/types/robots/google-import.d.ts +174 -0
- package/dist/alphalib/types/robots/google-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/google-import.js +77 -0
- package/dist/alphalib/types/robots/google-import.js.map +1 -0
- package/dist/alphalib/types/robots/google-store.d.ts +476 -0
- package/dist/alphalib/types/robots/google-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/google-store.js +111 -0
- package/dist/alphalib/types/robots/google-store.js.map +1 -0
- package/dist/alphalib/types/robots/html-convert.d.ts +531 -0
- package/dist/alphalib/types/robots/html-convert.d.ts.map +1 -0
- package/dist/alphalib/types/robots/html-convert.js +137 -0
- package/dist/alphalib/types/robots/html-convert.js.map +1 -0
- package/dist/alphalib/types/robots/http-import.d.ts +215 -0
- package/dist/alphalib/types/robots/http-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/http-import.js +135 -0
- package/dist/alphalib/types/robots/http-import.js.map +1 -0
- package/dist/alphalib/types/robots/image-bgremove.d.ts +453 -0
- package/dist/alphalib/types/robots/image-bgremove.d.ts.map +1 -0
- package/dist/alphalib/types/robots/image-bgremove.js +65 -0
- package/dist/alphalib/types/robots/image-bgremove.js.map +1 -0
- package/dist/alphalib/types/robots/image-describe.d.ts +453 -0
- package/dist/alphalib/types/robots/image-describe.d.ts.map +1 -0
- package/dist/alphalib/types/robots/image-describe.js +86 -0
- package/dist/alphalib/types/robots/image-describe.js.map +1 -0
- package/dist/alphalib/types/robots/image-facedetect.d.ts +477 -0
- package/dist/alphalib/types/robots/image-facedetect.d.ts.map +1 -0
- package/dist/alphalib/types/robots/image-facedetect.js +151 -0
- package/dist/alphalib/types/robots/image-facedetect.js.map +1 -0
- package/dist/alphalib/types/robots/image-generate.d.ts +522 -0
- package/dist/alphalib/types/robots/image-generate.d.ts.map +1 -0
- package/dist/alphalib/types/robots/image-generate.js +64 -0
- package/dist/alphalib/types/robots/image-generate.js.map +1 -0
- package/dist/alphalib/types/robots/image-merge.d.ts +477 -0
- package/dist/alphalib/types/robots/image-merge.d.ts.map +1 -0
- package/dist/alphalib/types/robots/image-merge.js +92 -0
- package/dist/alphalib/types/robots/image-merge.js.map +1 -0
- package/dist/alphalib/types/robots/image-ocr.d.ts +441 -0
- package/dist/alphalib/types/robots/image-ocr.d.ts.map +1 -0
- package/dist/alphalib/types/robots/image-ocr.js +79 -0
- package/dist/alphalib/types/robots/image-ocr.js.map +1 -0
- package/dist/alphalib/types/robots/image-optimize.d.ts +453 -0
- package/dist/alphalib/types/robots/image-optimize.d.ts.map +1 -0
- package/dist/alphalib/types/robots/image-optimize.js +81 -0
- package/dist/alphalib/types/robots/image-optimize.js.map +1 -0
- package/dist/alphalib/types/robots/image-resize.d.ts +1758 -0
- package/dist/alphalib/types/robots/image-resize.d.ts.map +1 -0
- package/dist/alphalib/types/robots/image-resize.js +602 -0
- package/dist/alphalib/types/robots/image-resize.js.map +1 -0
- package/dist/alphalib/types/robots/meta-read.d.ts +98 -0
- package/dist/alphalib/types/robots/meta-read.d.ts.map +1 -0
- package/dist/alphalib/types/robots/meta-read.js +24 -0
- package/dist/alphalib/types/robots/meta-read.js.map +1 -0
- package/dist/alphalib/types/robots/meta-write.d.ts +2842 -0
- package/dist/alphalib/types/robots/meta-write.d.ts.map +1 -0
- package/dist/alphalib/types/robots/meta-write.js +66 -0
- package/dist/alphalib/types/robots/meta-write.js.map +1 -0
- package/dist/alphalib/types/robots/minio-import.d.ts +234 -0
- package/dist/alphalib/types/robots/minio-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/minio-import.js +81 -0
- package/dist/alphalib/types/robots/minio-import.js.map +1 -0
- package/dist/alphalib/types/robots/minio-store.d.ts +514 -0
- package/dist/alphalib/types/robots/minio-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/minio-store.js +87 -0
- package/dist/alphalib/types/robots/minio-store.js.map +1 -0
- package/dist/alphalib/types/robots/progress-simulate.d.ts +229 -0
- package/dist/alphalib/types/robots/progress-simulate.d.ts.map +1 -0
- package/dist/alphalib/types/robots/progress-simulate.js +25 -0
- package/dist/alphalib/types/robots/progress-simulate.js.map +1 -0
- package/dist/alphalib/types/robots/s3-import.d.ts +246 -0
- package/dist/alphalib/types/robots/s3-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/s3-import.js +137 -0
- package/dist/alphalib/types/robots/s3-import.js.map +1 -0
- package/dist/alphalib/types/robots/s3-store.d.ts +593 -0
- package/dist/alphalib/types/robots/s3-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/s3-store.js +169 -0
- package/dist/alphalib/types/robots/s3-store.js.map +1 -0
- package/dist/alphalib/types/robots/script-run.d.ts +423 -0
- package/dist/alphalib/types/robots/script-run.d.ts.map +1 -0
- package/dist/alphalib/types/robots/script-run.js +95 -0
- package/dist/alphalib/types/robots/script-run.js.map +1 -0
- package/dist/alphalib/types/robots/sftp-import.d.ts +192 -0
- package/dist/alphalib/types/robots/sftp-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/sftp-import.js +62 -0
- package/dist/alphalib/types/robots/sftp-import.js.map +1 -0
- package/dist/alphalib/types/robots/sftp-store.d.ts +520 -0
- package/dist/alphalib/types/robots/sftp-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/sftp-store.js +83 -0
- package/dist/alphalib/types/robots/sftp-store.js.map +1 -0
- package/dist/alphalib/types/robots/speech-transcribe.d.ts +465 -0
- package/dist/alphalib/types/robots/speech-transcribe.d.ts.map +1 -0
- package/dist/alphalib/types/robots/speech-transcribe.js +103 -0
- package/dist/alphalib/types/robots/speech-transcribe.js.map +1 -0
- package/dist/alphalib/types/robots/supabase-import.d.ts +246 -0
- package/dist/alphalib/types/robots/supabase-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/supabase-import.js +83 -0
- package/dist/alphalib/types/robots/supabase-import.js.map +1 -0
- package/dist/alphalib/types/robots/supabase-store.d.ts +514 -0
- package/dist/alphalib/types/robots/supabase-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/supabase-store.js +77 -0
- package/dist/alphalib/types/robots/supabase-store.js.map +1 -0
- package/dist/alphalib/types/robots/swift-import.d.ts +246 -0
- package/dist/alphalib/types/robots/swift-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/swift-import.js +81 -0
- package/dist/alphalib/types/robots/swift-import.js.map +1 -0
- package/dist/alphalib/types/robots/swift-store.d.ts +526 -0
- package/dist/alphalib/types/robots/swift-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/swift-store.js +84 -0
- package/dist/alphalib/types/robots/swift-store.js.map +1 -0
- package/dist/alphalib/types/robots/text-speak.d.ts +465 -0
- package/dist/alphalib/types/robots/text-speak.d.ts.map +1 -0
- package/dist/alphalib/types/robots/text-speak.js +119 -0
- package/dist/alphalib/types/robots/text-speak.js.map +1 -0
- package/dist/alphalib/types/robots/text-translate.d.ts +441 -0
- package/dist/alphalib/types/robots/text-translate.d.ts.map +1 -0
- package/dist/alphalib/types/robots/text-translate.js +211 -0
- package/dist/alphalib/types/robots/text-translate.js.map +1 -0
- package/dist/alphalib/types/robots/tigris-import.d.ts +244 -0
- package/dist/alphalib/types/robots/tigris-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/tigris-import.js +85 -0
- package/dist/alphalib/types/robots/tigris-import.js.map +1 -0
- package/dist/alphalib/types/robots/tigris-store.d.ts +524 -0
- package/dist/alphalib/types/robots/tigris-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/tigris-store.js +91 -0
- package/dist/alphalib/types/robots/tigris-store.js.map +1 -0
- package/dist/alphalib/types/robots/tlcdn-deliver.d.ts +100 -0
- package/dist/alphalib/types/robots/tlcdn-deliver.d.ts.map +1 -0
- package/dist/alphalib/types/robots/tlcdn-deliver.js +46 -0
- package/dist/alphalib/types/robots/tlcdn-deliver.js.map +1 -0
- package/dist/alphalib/types/robots/tus-store.d.ts +477 -0
- package/dist/alphalib/types/robots/tus-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/tus-store.js +102 -0
- package/dist/alphalib/types/robots/tus-store.js.map +1 -0
- package/dist/alphalib/types/robots/upload-handle.d.ts +100 -0
- package/dist/alphalib/types/robots/upload-handle.d.ts.map +1 -0
- package/dist/alphalib/types/robots/upload-handle.js +66 -0
- package/dist/alphalib/types/robots/upload-handle.js.map +1 -0
- package/dist/alphalib/types/robots/video-adaptive.d.ts +2915 -0
- package/dist/alphalib/types/robots/video-adaptive.d.ts.map +1 -0
- package/dist/alphalib/types/robots/video-adaptive.js +144 -0
- package/dist/alphalib/types/robots/video-adaptive.js.map +1 -0
- package/dist/alphalib/types/robots/video-concat.d.ts +2891 -0
- package/dist/alphalib/types/robots/video-concat.d.ts.map +1 -0
- package/dist/alphalib/types/robots/video-concat.js +96 -0
- package/dist/alphalib/types/robots/video-concat.js.map +1 -0
- package/dist/alphalib/types/robots/video-encode.d.ts +3280 -0
- package/dist/alphalib/types/robots/video-encode.d.ts.map +1 -0
- package/dist/alphalib/types/robots/video-encode.js +107 -0
- package/dist/alphalib/types/robots/video-encode.js.map +1 -0
- package/dist/alphalib/types/robots/video-merge.d.ts +2987 -0
- package/dist/alphalib/types/robots/video-merge.d.ts.map +1 -0
- package/dist/alphalib/types/robots/video-merge.js +102 -0
- package/dist/alphalib/types/robots/video-merge.js.map +1 -0
- package/dist/alphalib/types/robots/video-ondemand.d.ts +4553 -0
- package/dist/alphalib/types/robots/video-ondemand.d.ts.map +1 -0
- package/dist/alphalib/types/robots/video-ondemand.js +112 -0
- package/dist/alphalib/types/robots/video-ondemand.js.map +1 -0
- package/dist/alphalib/types/robots/video-subtitle.d.ts +2975 -0
- package/dist/alphalib/types/robots/video-subtitle.d.ts.map +1 -0
- package/dist/alphalib/types/robots/video-subtitle.js +122 -0
- package/dist/alphalib/types/robots/video-subtitle.js.map +1 -0
- package/dist/alphalib/types/robots/video-thumbs.d.ts +2938 -0
- package/dist/alphalib/types/robots/video-thumbs.d.ts.map +1 -0
- package/dist/alphalib/types/robots/video-thumbs.js +122 -0
- package/dist/alphalib/types/robots/video-thumbs.js.map +1 -0
- package/dist/alphalib/types/robots/vimeo-import.d.ts +189 -0
- package/dist/alphalib/types/robots/vimeo-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/vimeo-import.js +92 -0
- package/dist/alphalib/types/robots/vimeo-import.js.map +1 -0
- package/dist/alphalib/types/robots/vimeo-store.d.ts +520 -0
- package/dist/alphalib/types/robots/vimeo-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/vimeo-store.js +115 -0
- package/dist/alphalib/types/robots/vimeo-store.js.map +1 -0
- package/dist/alphalib/types/robots/wasabi-import.d.ts +244 -0
- package/dist/alphalib/types/robots/wasabi-import.d.ts.map +1 -0
- package/dist/alphalib/types/robots/wasabi-import.js +85 -0
- package/dist/alphalib/types/robots/wasabi-import.js.map +1 -0
- package/dist/alphalib/types/robots/wasabi-store.d.ts +526 -0
- package/dist/alphalib/types/robots/wasabi-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/wasabi-store.js +85 -0
- package/dist/alphalib/types/robots/wasabi-store.js.map +1 -0
- package/dist/alphalib/types/robots/youtube-store.d.ts +477 -0
- package/dist/alphalib/types/robots/youtube-store.d.ts.map +1 -0
- package/dist/alphalib/types/robots/youtube-store.js +122 -0
- package/dist/alphalib/types/robots/youtube-store.js.map +1 -0
- package/dist/alphalib/types/stackVersions.d.ts +13 -0
- package/dist/alphalib/types/stackVersions.d.ts.map +1 -0
- package/dist/alphalib/types/stackVersions.js +13 -0
- package/dist/alphalib/types/stackVersions.js.map +1 -0
- package/dist/alphalib/types/template.d.ts +131710 -0
- package/dist/alphalib/types/template.d.ts.map +1 -0
- package/dist/alphalib/types/template.js +218 -0
- package/dist/alphalib/types/template.js.map +1 -0
- package/dist/alphalib/types/templateCredential.d.ts +95 -0
- package/dist/alphalib/types/templateCredential.d.ts.map +1 -0
- package/dist/alphalib/types/templateCredential.js +57 -0
- package/dist/alphalib/types/templateCredential.js.map +1 -0
- package/dist/alphalib/zodParseWithContext.d.ts +17 -0
- package/dist/alphalib/zodParseWithContext.d.ts.map +1 -0
- package/dist/alphalib/zodParseWithContext.js +248 -0
- package/dist/alphalib/zodParseWithContext.js.map +1 -0
- package/dist/apiTypes.d.ts +112 -0
- package/dist/apiTypes.d.ts.map +1 -0
- package/dist/apiTypes.js +3 -0
- package/dist/apiTypes.js.map +1 -0
- package/dist/cli/OutputCtl.d.ts +47 -0
- package/dist/cli/OutputCtl.d.ts.map +1 -0
- package/dist/cli/OutputCtl.js +85 -0
- package/dist/cli/OutputCtl.js.map +1 -0
- package/dist/cli/commands/BaseCommand.d.ts +24 -0
- package/dist/cli/commands/BaseCommand.d.ts.map +1 -0
- package/dist/cli/commands/BaseCommand.js +52 -0
- package/dist/cli/commands/BaseCommand.js.map +1 -0
- package/dist/cli/commands/assemblies.d.ts +93 -0
- package/dist/cli/commands/assemblies.d.ts.map +1 -0
- package/dist/cli/commands/assemblies.js +1021 -0
- package/dist/cli/commands/assemblies.js.map +1 -0
- package/dist/cli/commands/auth.d.ts +28 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/auth.js +280 -0
- package/dist/cli/commands/auth.js.map +1 -0
- package/dist/cli/commands/bills.d.ts +14 -0
- package/dist/cli/commands/bills.d.ts.map +1 -0
- package/dist/cli/commands/bills.js +69 -0
- package/dist/cli/commands/bills.js.map +1 -0
- package/dist/cli/commands/index.d.ts +3 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +39 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/notifications.d.ts +9 -0
- package/dist/cli/commands/notifications.d.ts.map +1 -0
- package/dist/cli/commands/notifications.js +44 -0
- package/dist/cli/commands/notifications.js.map +1 -0
- package/dist/cli/commands/templates.d.ts +73 -0
- package/dist/cli/commands/templates.d.ts.map +1 -0
- package/dist/cli/commands/templates.js +428 -0
- package/dist/cli/commands/templates.js.map +1 -0
- package/dist/cli/helpers.d.ts +13 -0
- package/dist/cli/helpers.d.ts.map +1 -0
- package/dist/cli/helpers.js +39 -0
- package/dist/cli/helpers.js.map +1 -0
- package/dist/cli/template-last-modified.d.ts +10 -0
- package/dist/cli/template-last-modified.d.ts.map +1 -0
- package/dist/cli/template-last-modified.js +134 -0
- package/dist/cli/template-last-modified.js.map +1 -0
- package/dist/cli/types.d.ts +78 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +49 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +41 -0
- package/dist/cli.js.map +1 -0
- package/dist/tus.d.ts +18 -0
- package/dist/tus.d.ts.map +1 -0
- package/dist/tus.js +122 -0
- package/dist/tus.js.map +1 -0
- package/package.json +92 -0
- package/src/ApiError.ts +49 -0
- package/src/InconsistentResponseError.ts +3 -0
- package/src/PaginationStream.ts +54 -0
- package/src/PollingTimeoutError.ts +5 -0
- package/src/Transloadit.ts +980 -0
- package/src/alphalib/lib/nativeGlobby.ts +244 -0
- package/src/alphalib/mcache.ts +184 -0
- package/src/alphalib/tryCatch.ts +30 -0
- package/src/alphalib/types/assembliesGet.ts +42 -0
- package/src/alphalib/types/assemblyReplay.ts +24 -0
- package/src/alphalib/types/assemblyReplayNotification.ts +16 -0
- package/src/alphalib/types/assemblyStatus.ts +794 -0
- package/src/alphalib/types/bill.ts +9 -0
- package/src/alphalib/types/robots/_index.ts +1201 -0
- package/src/alphalib/types/robots/_instructions-primitives.ts +1770 -0
- package/src/alphalib/types/robots/ai-chat.ts +278 -0
- package/src/alphalib/types/robots/assembly-savejson.ts +37 -0
- package/src/alphalib/types/robots/audio-artwork.ts +107 -0
- package/src/alphalib/types/robots/audio-concat.ts +142 -0
- package/src/alphalib/types/robots/audio-encode.ts +103 -0
- package/src/alphalib/types/robots/audio-loop.ts +102 -0
- package/src/alphalib/types/robots/audio-merge.ts +137 -0
- package/src/alphalib/types/robots/audio-waveform.ts +280 -0
- package/src/alphalib/types/robots/azure-import.ts +111 -0
- package/src/alphalib/types/robots/azure-store.ts +143 -0
- package/src/alphalib/types/robots/backblaze-import.ts +119 -0
- package/src/alphalib/types/robots/backblaze-store.ts +104 -0
- package/src/alphalib/types/robots/cloudfiles-import.ts +118 -0
- package/src/alphalib/types/robots/cloudfiles-store.ts +104 -0
- package/src/alphalib/types/robots/cloudflare-import.ts +121 -0
- package/src/alphalib/types/robots/cloudflare-store.ts +120 -0
- package/src/alphalib/types/robots/digitalocean-import.ts +118 -0
- package/src/alphalib/types/robots/digitalocean-store.ts +125 -0
- package/src/alphalib/types/robots/document-autorotate.ts +74 -0
- package/src/alphalib/types/robots/document-convert.ts +302 -0
- package/src/alphalib/types/robots/document-merge.ts +114 -0
- package/src/alphalib/types/robots/document-ocr.ts +120 -0
- package/src/alphalib/types/robots/document-split.ts +78 -0
- package/src/alphalib/types/robots/document-thumbs.ts +231 -0
- package/src/alphalib/types/robots/dropbox-import.ts +100 -0
- package/src/alphalib/types/robots/dropbox-store.ts +97 -0
- package/src/alphalib/types/robots/edgly-deliver.ts +73 -0
- package/src/alphalib/types/robots/file-compress.ts +167 -0
- package/src/alphalib/types/robots/file-decompress.ts +125 -0
- package/src/alphalib/types/robots/file-filter.ts +173 -0
- package/src/alphalib/types/robots/file-hash.ts +86 -0
- package/src/alphalib/types/robots/file-preview.ts +260 -0
- package/src/alphalib/types/robots/file-read.ts +71 -0
- package/src/alphalib/types/robots/file-serve.ts +128 -0
- package/src/alphalib/types/robots/file-verify.ts +102 -0
- package/src/alphalib/types/robots/file-virusscan.ts +113 -0
- package/src/alphalib/types/robots/file-watermark.ts +56 -0
- package/src/alphalib/types/robots/ftp-import.ts +95 -0
- package/src/alphalib/types/robots/ftp-store.ts +119 -0
- package/src/alphalib/types/robots/google-import.ts +115 -0
- package/src/alphalib/types/robots/google-store.ts +139 -0
- package/src/alphalib/types/robots/html-convert.ts +165 -0
- package/src/alphalib/types/robots/http-import.ts +168 -0
- package/src/alphalib/types/robots/image-bgremove.ts +95 -0
- package/src/alphalib/types/robots/image-describe.ts +121 -0
- package/src/alphalib/types/robots/image-facedetect.ts +187 -0
- package/src/alphalib/types/robots/image-generate.ts +92 -0
- package/src/alphalib/types/robots/image-merge.ts +127 -0
- package/src/alphalib/types/robots/image-ocr.ts +112 -0
- package/src/alphalib/types/robots/image-optimize.ts +114 -0
- package/src/alphalib/types/robots/image-resize.ts +653 -0
- package/src/alphalib/types/robots/meta-read.ts +44 -0
- package/src/alphalib/types/robots/meta-write.ts +93 -0
- package/src/alphalib/types/robots/minio-import.ts +120 -0
- package/src/alphalib/types/robots/minio-store.ts +115 -0
- package/src/alphalib/types/robots/progress-simulate.ts +40 -0
- package/src/alphalib/types/robots/s3-import.ts +175 -0
- package/src/alphalib/types/robots/s3-store.ts +198 -0
- package/src/alphalib/types/robots/script-run.ts +122 -0
- package/src/alphalib/types/robots/sftp-import.ts +92 -0
- package/src/alphalib/types/robots/sftp-store.ts +110 -0
- package/src/alphalib/types/robots/speech-transcribe.ts +139 -0
- package/src/alphalib/types/robots/supabase-import.ts +122 -0
- package/src/alphalib/types/robots/supabase-store.ts +105 -0
- package/src/alphalib/types/robots/swift-import.ts +120 -0
- package/src/alphalib/types/robots/swift-store.ts +112 -0
- package/src/alphalib/types/robots/text-speak.ts +152 -0
- package/src/alphalib/types/robots/text-translate.ts +245 -0
- package/src/alphalib/types/robots/tigris-import.ts +124 -0
- package/src/alphalib/types/robots/tigris-store.ts +119 -0
- package/src/alphalib/types/robots/tlcdn-deliver.ts +73 -0
- package/src/alphalib/types/robots/tus-store.ts +129 -0
- package/src/alphalib/types/robots/upload-handle.ts +95 -0
- package/src/alphalib/types/robots/video-adaptive.ts +179 -0
- package/src/alphalib/types/robots/video-concat.ts +130 -0
- package/src/alphalib/types/robots/video-encode.ts +141 -0
- package/src/alphalib/types/robots/video-merge.ts +138 -0
- package/src/alphalib/types/robots/video-ondemand.ts +161 -0
- package/src/alphalib/types/robots/video-subtitle.ts +159 -0
- package/src/alphalib/types/robots/video-thumbs.ts +158 -0
- package/src/alphalib/types/robots/vimeo-import.ts +126 -0
- package/src/alphalib/types/robots/vimeo-store.ts +143 -0
- package/src/alphalib/types/robots/wasabi-import.ts +124 -0
- package/src/alphalib/types/robots/wasabi-store.ts +113 -0
- package/src/alphalib/types/robots/youtube-store.ts +153 -0
- package/src/alphalib/types/stackVersions.ts +12 -0
- package/src/alphalib/types/template.ts +277 -0
- package/src/alphalib/types/templateCredential.ts +61 -0
- package/src/alphalib/zodParseWithContext.ts +306 -0
- package/src/apiTypes.ts +154 -0
- package/src/cli/OutputCtl.ts +115 -0
- package/src/cli/commands/BaseCommand.ts +71 -0
- package/src/cli/commands/assemblies.ts +1373 -0
- package/src/cli/commands/auth.ts +354 -0
- package/src/cli/commands/bills.ts +91 -0
- package/src/cli/commands/index.ts +65 -0
- package/src/cli/commands/notifications.ts +63 -0
- package/src/cli/commands/templates.ts +556 -0
- package/src/cli/helpers.ts +50 -0
- package/src/cli/template-last-modified.ts +156 -0
- package/src/cli/types.ts +70 -0
- package/src/cli.ts +44 -0
- 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}¶ms=${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
|
+
}
|