Forráskód Böngészése

@uppy/transloadit: remove deprecated options (#5056)

Merlijn Vos 1 éve
szülő
commit
c4455ebba7

+ 5 - 4
e2e/clients/dashboard-transloadit/app.js

@@ -14,10 +14,11 @@ const uppy = new Uppy()
   .use(Transloadit, {
     service: process.env.VITE_TRANSLOADIT_SERVICE_URL,
     waitForEncoding: true,
-    getAssemblyOptions: () => generateSignatureIfSecret(process.env.VITE_TRANSLOADIT_SECRET, {
-      auth: { key: process.env.VITE_TRANSLOADIT_KEY },
-      template_id: process.env.VITE_TRANSLOADIT_TEMPLATE,
-    }),
+    assemblyOptions: () =>
+      generateSignatureIfSecret(process.env.VITE_TRANSLOADIT_SECRET, {
+        auth: { key: process.env.VITE_TRANSLOADIT_KEY },
+        template_id: process.env.VITE_TRANSLOADIT_TEMPLATE,
+      }),
   })
 
 // Keep this here to access uppy in tests

+ 6 - 34
packages/@uppy/transloadit/src/index.test.js

@@ -6,41 +6,11 @@ import Transloadit from './index.ts'
 import 'whatwg-fetch'
 
 describe('Transloadit', () => {
-  it('Throws errors if options are missing', () => {
-    const uppy = new Core()
-
-    expect(() => {
-      uppy.use(Transloadit, { params: {} })
-    }).toThrowError(/The `params\.auth\.key` option is required/)
-  })
-
-  it('Accepts a JSON string as `params` for signature authentication', () => {
-    const uppy = new Core()
-
-    expect(() => {
-      uppy.use(Transloadit, {
-        params: 'not json',
-      })
-    }).toThrowError(/The `params` option is a malformed JSON string/)
-
-    expect(() => {
-      uppy.use(Transloadit, {
-        params: '{"template_id":"some template id string"}',
-      })
-    }).toThrowError(/The `params\.auth\.key` option is required/)
-    expect(() => {
-      uppy.use(Transloadit, {
-        params:
-          '{"auth":{"key":"some auth key string"},"template_id":"some template id string"}',
-      })
-    }).not.toThrowError(/The `params\.auth\.key` option is required/)
-  })
-
   it('Does not leave lingering progress if getAssemblyOptions fails', () => {
     const error = new Error('expected failure')
     const uppy = new Core()
     uppy.use(Transloadit, {
-      getAssemblyOptions() {
+      assemblyOptions() {
         return Promise.reject(error)
       },
     })
@@ -67,9 +37,11 @@ describe('Transloadit', () => {
   it('Does not leave lingering progress if creating assembly fails', () => {
     const uppy = new Core()
     uppy.use(Transloadit, {
-      params: {
-        auth: { key: 'some auth key string' },
-        template_id: 'some template id string',
+      assemblyOptions: {
+        params: {
+          auth: { key: 'some auth key string' },
+          template_id: 'some template id string',
+        },
       },
     })
 

+ 11 - 81
packages/@uppy/transloadit/src/index.ts

@@ -9,7 +9,6 @@ import type { Uppy } from '@uppy/core'
 import Assembly from './Assembly.ts'
 import Client, { AssemblyError } from './Client.ts'
 import AssemblyOptionsBuilder, {
-  validateParams,
   type OptionsWithRestructuredFields,
 } from './AssemblyOptions.ts'
 import AssemblyWatcher from './AssemblyWatcher.ts'
@@ -134,7 +133,9 @@ export interface AssemblyOptions {
   signature?: string | null
 }
 
-interface BaseOptions extends PluginOpts {
+// eslint-disable-next-line @typescript-eslint/no-unused-vars
+export interface TransloaditOptions<M extends Meta, B extends Body>
+  extends PluginOpts {
   service?: string
   errorReporting?: boolean
   waitForEncoding?: boolean
@@ -144,52 +145,14 @@ interface BaseOptions extends PluginOpts {
   limit?: number
   clientName?: string | null
   retryDelays?: number[]
+  assemblyOptions?:
+    | AssemblyOptions
+    | ((
+        file?: UppyFile<M, B> | null,
+        options?: TransloaditOptions<M, B>,
+      ) => Promise<AssemblyOptions> | AssemblyOptions)
 }
 
-export type TransloaditOptions<M extends Meta, B extends Body> = BaseOptions &
-  (
-    | {
-        assemblyOptions?:
-          | AssemblyOptions
-          | ((
-              file?: UppyFile<M, B> | null,
-              options?: AssemblyOptions,
-            ) => Promise<AssemblyOptions> | AssemblyOptions)
-        /** @deprecated use `assemblyOptions` instead */
-        getAssemblyOptions?: never | null
-        /** @deprecated use `assemblyOptions` instead */
-        params?: never | null
-        /** @deprecated use `assemblyOptions` instead */
-        fields?: never | null
-        /** @deprecated use `assemblyOptions` instead */
-        signature?: never | null
-      }
-    | {
-        /** @deprecated use `assemblyOptions` instead */
-        getAssemblyOptions?: (
-          file?: UppyFile<M, B> | null,
-        ) => AssemblyOptions | Promise<AssemblyOptions>
-        assemblyOptions?: never
-        /** @deprecated use `assemblyOptions` instead */
-        params?: never | null
-        /** @deprecated use `assemblyOptions` instead */
-        fields?: never | null
-        /** @deprecated use `assemblyOptions` instead */
-        signature?: never | null
-      }
-    | {
-        /** @deprecated use `assemblyOptions` instead */
-        params?: AssemblyParameters | null
-        /** @deprecated use `assemblyOptions` instead */
-        fields?: { [name: string]: number | string } | string[] | null
-        /** @deprecated use `assemblyOptions` instead */
-        signature?: string | null
-        /** @deprecated use `assemblyOptions` instead */
-        getAssemblyOptions?: never | null
-        assemblyOptions?: never
-      }
-  )
-
 const defaultOptions = {
   service: 'https://api2.transloadit.com',
   errorReporting: true,
@@ -197,14 +160,6 @@ const defaultOptions = {
   waitForMetadata: false,
   alwaysRunAssembly: false,
   importFromUploadURLs: false,
-  /** @deprecated use `assemblyOptions` instead */
-  signature: null,
-  /** @deprecated use `assemblyOptions` instead */
-  params: null,
-  /** @deprecated use `assemblyOptions` instead */
-  fields: null,
-  /** @deprecated use `assemblyOptions` instead */
-  getAssemblyOptions: null,
   limit: 20,
   retryDelays: [7_000, 10_000, 15_000, 20_000],
   clientName: null,
@@ -292,12 +247,6 @@ export default class Transloadit<
 > extends BasePlugin<Opts<M, B>, M, B, TransloaditState> {
   static VERSION = packageJson.version
 
-  /** @deprecated use `import { COMPANION_URL } from '@uppy/transloadit'` instead. */
-  static COMPANION = COMPANION_URL
-
-  /** @deprecated use `import { COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit'` instead. */
-  static COMPANION_PATTERN = COMPANION_ALLOWED_HOSTS
-
   #rateLimitedQueue: RateLimitedQueue
 
   client: Client<M, B>
@@ -317,22 +266,6 @@ export default class Transloadit<
 
     this.defaultLocale = locale
 
-    // TODO: remove this fallback in the next major
-    this.opts.assemblyOptions ??= this.opts.getAssemblyOptions ?? {
-      params: this.opts.params,
-      signature: this.opts.signature,
-      fields: this.opts.fields,
-    }
-
-    // TODO: remove this check in the next major (validating params when creating the assembly should be enough)
-    if (
-      opts?.params != null &&
-      opts.getAssemblyOptions == null &&
-      opts.assemblyOptions == null
-    ) {
-      validateParams((this.opts.assemblyOptions as AssemblyOptions).params)
-    }
-
     this.#rateLimitedQueue = new RateLimitedQueue(this.opts.limit)
 
     this.i18nInit()
@@ -1013,12 +946,9 @@ export default class Transloadit<
       },
     })
 
-    const assemblyOptions = new AssemblyOptionsBuilder(
-      filesWithoutErrors,
-      this.opts,
-    )
+    const builder = new AssemblyOptionsBuilder(filesWithoutErrors, this.opts)
 
-    await assemblyOptions
+    await builder
       .build()
       .then((assemblies) => Promise.all(assemblies.map(createAssembly)))
       .then((maybeCreatedAssemblies) => {