transloadit 4.0.7 → 4.1.2

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 (80) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +200 -21
  3. package/dist/ApiError.d.ts +1 -1
  4. package/dist/ApiError.d.ts.map +1 -1
  5. package/dist/ApiError.js.map +1 -1
  6. package/dist/Transloadit.d.ts +23 -4
  7. package/dist/Transloadit.d.ts.map +1 -1
  8. package/dist/Transloadit.js +62 -28
  9. package/dist/Transloadit.js.map +1 -1
  10. package/dist/apiTypes.d.ts +1 -1
  11. package/dist/apiTypes.d.ts.map +1 -1
  12. package/dist/cli/OutputCtl.d.ts +46 -0
  13. package/dist/cli/OutputCtl.d.ts.map +1 -0
  14. package/dist/cli/OutputCtl.js +85 -0
  15. package/dist/cli/OutputCtl.js.map +1 -0
  16. package/dist/cli/commands/BaseCommand.d.ts +23 -0
  17. package/dist/cli/commands/BaseCommand.d.ts.map +1 -0
  18. package/dist/cli/commands/BaseCommand.js +52 -0
  19. package/dist/cli/commands/BaseCommand.js.map +1 -0
  20. package/dist/cli/commands/assemblies.d.ts +93 -0
  21. package/dist/cli/commands/assemblies.d.ts.map +1 -0
  22. package/dist/cli/commands/assemblies.js +1021 -0
  23. package/dist/cli/commands/assemblies.js.map +1 -0
  24. package/dist/cli/commands/auth.d.ts +28 -0
  25. package/dist/cli/commands/auth.d.ts.map +1 -0
  26. package/dist/cli/commands/auth.js +280 -0
  27. package/dist/cli/commands/auth.js.map +1 -0
  28. package/dist/cli/commands/bills.d.ts +14 -0
  29. package/dist/cli/commands/bills.d.ts.map +1 -0
  30. package/dist/cli/commands/bills.js +69 -0
  31. package/dist/cli/commands/bills.js.map +1 -0
  32. package/dist/cli/commands/index.d.ts +3 -0
  33. package/dist/cli/commands/index.d.ts.map +1 -0
  34. package/dist/cli/commands/index.js +39 -0
  35. package/dist/cli/commands/index.js.map +1 -0
  36. package/dist/cli/commands/notifications.d.ts +16 -0
  37. package/dist/cli/commands/notifications.d.ts.map +1 -0
  38. package/dist/cli/commands/notifications.js +44 -0
  39. package/dist/cli/commands/notifications.js.map +1 -0
  40. package/dist/cli/commands/templates.d.ts +81 -0
  41. package/dist/cli/commands/templates.d.ts.map +1 -0
  42. package/dist/cli/commands/templates.js +428 -0
  43. package/dist/cli/commands/templates.js.map +1 -0
  44. package/dist/cli/helpers.d.ts +13 -0
  45. package/dist/cli/helpers.d.ts.map +1 -0
  46. package/dist/cli/helpers.js +39 -0
  47. package/dist/cli/helpers.js.map +1 -0
  48. package/dist/cli/template-last-modified.d.ts +10 -0
  49. package/dist/cli/template-last-modified.d.ts.map +1 -0
  50. package/dist/cli/template-last-modified.js +134 -0
  51. package/dist/cli/template-last-modified.js.map +1 -0
  52. package/dist/cli/types.d.ts +152 -0
  53. package/dist/cli/types.d.ts.map +1 -0
  54. package/dist/cli/types.js +64 -0
  55. package/dist/cli/types.js.map +1 -0
  56. package/dist/cli.d.ts +2 -12
  57. package/dist/cli.d.ts.map +1 -1
  58. package/dist/cli.js +11 -256
  59. package/dist/cli.js.map +1 -1
  60. package/dist/tus.d.ts +2 -1
  61. package/dist/tus.d.ts.map +1 -1
  62. package/dist/tus.js +33 -5
  63. package/dist/tus.js.map +1 -1
  64. package/package.json +12 -7
  65. package/src/ApiError.ts +2 -1
  66. package/src/Transloadit.ts +98 -39
  67. package/src/apiTypes.ts +1 -1
  68. package/src/cli/OutputCtl.ts +115 -0
  69. package/src/cli/commands/BaseCommand.ts +71 -0
  70. package/src/cli/commands/assemblies.ts +1373 -0
  71. package/src/cli/commands/auth.ts +354 -0
  72. package/src/cli/commands/bills.ts +91 -0
  73. package/src/cli/commands/index.ts +65 -0
  74. package/src/cli/commands/notifications.ts +63 -0
  75. package/src/cli/commands/templates.ts +556 -0
  76. package/src/cli/helpers.ts +50 -0
  77. package/src/cli/template-last-modified.ts +156 -0
  78. package/src/cli/types.ts +183 -0
  79. package/src/cli.ts +12 -305
  80. package/src/tus.ts +37 -5
package/src/tus.ts CHANGED
@@ -3,7 +3,8 @@ import { basename } from 'node:path'
3
3
  import type { Readable } from 'node:stream'
4
4
  import debug from 'debug'
5
5
  import pMap from 'p-map'
6
- import { type OnSuccessPayload, Upload, type UploadOptions } from 'tus-js-client'
6
+ import type { OnSuccessPayload, UploadOptions } from 'tus-js-client'
7
+ import { Upload } from 'tus-js-client'
7
8
  import type { AssemblyStatus } from './alphalib/types/assemblyStatus.ts'
8
9
  import type { UploadProgress } from './Transloadit.ts'
9
10
 
@@ -20,6 +21,7 @@ interface SendTusRequestOptions {
20
21
  requestedChunkSize: number
21
22
  uploadConcurrency: number
22
23
  onProgress: (options: UploadProgress) => void
24
+ signal?: AbortSignal
23
25
  }
24
26
 
25
27
  export async function sendTusRequest({
@@ -28,6 +30,7 @@ export async function sendTusRequest({
28
30
  requestedChunkSize,
29
31
  uploadConcurrency,
30
32
  onProgress,
33
+ signal,
31
34
  }: SendTusRequestOptions) {
32
35
  const streamLabels = Object.keys(streamsMap)
33
36
 
@@ -42,6 +45,9 @@ export async function sendTusRequest({
42
45
  await pMap(
43
46
  streamLabels,
44
47
  async (label) => {
48
+ // Check if aborted before each operation
49
+ if (signal?.aborted) throw new Error('Upload aborted')
50
+
45
51
  const streamInfo = streamsMap[label]
46
52
  if (!streamInfo) {
47
53
  throw new Error(`Stream info not found for label: ${label}`)
@@ -54,7 +60,7 @@ export async function sendTusRequest({
54
60
  totalBytes += size
55
61
  }
56
62
  },
57
- { concurrency: 5 },
63
+ { concurrency: 5, signal },
58
64
  )
59
65
 
60
66
  const uploadProgresses: Record<string, number> = {}
@@ -102,12 +108,29 @@ export async function sendTusRequest({
102
108
 
103
109
  const filename = path ? basename(path) : label
104
110
 
105
- await new Promise<OnSuccessPayload>((resolve, reject) => {
111
+ await new Promise<OnSuccessPayload>((resolvePromise, rejectPromise) => {
106
112
  if (!assembly.assembly_ssl_url) {
107
- reject(new Error('assembly_ssl_url is not present in the assembly status'))
113
+ rejectPromise(new Error('assembly_ssl_url is not present in the assembly status'))
108
114
  return
109
115
  }
110
116
 
117
+ // Check if already aborted before starting
118
+ if (signal?.aborted) {
119
+ rejectPromise(new Error('Upload aborted'))
120
+ return
121
+ }
122
+
123
+ // Wrap resolve/reject to clean up abort listener
124
+ let abortHandler: (() => void) | undefined
125
+ const resolve = (payload: OnSuccessPayload) => {
126
+ if (abortHandler) signal?.removeEventListener('abort', abortHandler)
127
+ resolvePromise(payload)
128
+ }
129
+ const reject = (err: unknown) => {
130
+ if (abortHandler) signal?.removeEventListener('abort', abortHandler)
131
+ rejectPromise(err)
132
+ }
133
+
111
134
  const tusOptions: UploadOptions = {
112
135
  endpoint: assembly.tus_url,
113
136
  metadata: {
@@ -126,11 +149,20 @@ export async function sendTusRequest({
126
149
 
127
150
  const tusUpload = new Upload(stream, tusOptions)
128
151
 
152
+ // Handle abort signal
153
+ if (signal) {
154
+ abortHandler = () => {
155
+ tusUpload.abort()
156
+ reject(new Error('Upload aborted'))
157
+ }
158
+ signal.addEventListener('abort', abortHandler, { once: true })
159
+ }
160
+
129
161
  tusUpload.start()
130
162
  })
131
163
 
132
164
  log(label, 'upload done')
133
165
  }
134
166
 
135
- await pMap(streamLabels, uploadSingleStream, { concurrency: uploadConcurrency })
167
+ await pMap(streamLabels, uploadSingleStream, { concurrency: uploadConcurrency, signal })
136
168
  }