Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/transloadit: remove deprecated options #5056

Merged
merged 5 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions e2e/clients/dashboard-transloadit/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 6 additions & 34 deletions packages/@uppy/transloadit/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
})
Expand All @@ -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',
},
},
})

Expand Down
92 changes: 11 additions & 81 deletions packages/@uppy/transloadit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -144,67 +145,21 @@ 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
}
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are breaking, can we rename service to endpoint as to be consistent with other integrations?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably support both, and keep service as a deprecated alias

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do it in a separate PR 👍

const defaultOptions = {
service: 'https://api2.transloadit.com',
errorReporting: true,
waitForEncoding: false,
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,
Expand Down Expand Up @@ -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>
Expand All @@ -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()
Expand Down Expand Up @@ -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) => {
Expand Down