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

Companion 4x breaking changes #5198

Merged
merged 15 commits into from
May 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions docs/companion.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,10 @@ using many instances. See [How to scale Companion](#how-to-scale-companion).
#### `COMPANION_REDIS_EXPRESS_SESSION_PREFIX`

Set a custom prefix for redis keys created by
[connect-redis](https://github.com/tj/connect-redis). Defaults to `sess:`.
Sessions are used for storing authentication state and for allowing thumbnails
to be loaded by the browser via Companion. You might want to change this because
if you run a redis with many different apps in the same redis server, it’s hard
to know where `sess:` comes from and it might collide with other apps. **Note:**
in the future, we plan and changing the default to `companion:` and possibly
remove this option. This is a standalone-only option. See also
`COMPANION_REDIS_PUBSUB_SCOPE`.
[connect-redis](https://github.com/tj/connect-redis). Defaults to
`companion-session:`. Sessions are used for storing authentication state and for
allowing thumbnails to be loaded by the browser via Companion and for OAuth2.
See also `COMPANION_REDIS_PUBSUB_SCOPE`.

#### `redisOptions` `COMPANION_REDIS_OPTIONS`

Expand Down Expand Up @@ -655,8 +651,8 @@ as well as

#### `enableUrlEndpoint` `COMPANION_ENABLE_URL_ENDPOINT`

Set this to `false` to disable the
[URL functionalily](https://uppy.io/docs/url/). Default: `true`.
Set this to `true` to enable the [URL functionalily](https://uppy.io/docs/url/).
Default: `false`.

### Events

Expand Down
43 changes: 43 additions & 0 deletions docs/guides/migration-guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@

These cover all the major Uppy versions and how to migrate to them.

## Migrate from Uppy 3.x to 4.x

### Companion

- `COMPANION_REDIS_EXPRESS_SESSION_PREFIX` now defaults to `companion-session:`
(before `sess:`). To revert keep backwards compatibility, set the environment
variable `COMPANION_REDIS_EXPRESS_SESSION_PREFIX=sess:`.
- The URL endpoint (used by the `Url`/`Link` plugin) is now turned off by
default and must be explicitly enabled with
`COMPANION_ENABLE_URL_ENDPOINT=true` or `enableUrlEndpoint: true`.
- Custom provider breaking changes. If you have not implemented a custom
provider, you should not be affected.
- The static `getExtraConfig` property has been renamed to
`getExtraGrantConfig`.
- The static `authProvider` property has been renamed to `oauthProvider`.
- Endpoint `GET /s3/params` now returns `{ method: "POST" }` instead of
`{ method: "post" }`. This will not affect most people.
- The Companion [`error` event](https://uppy.io/docs/companion/#events) now no
longer includes `extraData` inside the `payload.error` property. `extraData`
is (and was also before) included in the `payload`.
- `access-control-allow-headers` is no longer included in
`Access-Control-Expose-Headers`, and `uppy-versions` is no longer an allowed
header. We are not aware of any issues this might cause.
- Internal refactoring (probably won’t affect you)
- `getProtectedGot` parameter `blockLocalIPs` changed to `allowLocalIPs`
(inverted boolean).
- `getURLMeta` 2nd (boolean) argument inverted.
- `getProtectedHttpAgent` parameter `blockLocalIPs` changed to `allowLocalIPs`
(inverted boolean).
- `downloadURL` 2nd (boolean) argument inverted.

### `@uppy/companion-client`

- `supportsRefreshToken` now defaults to `false` instead of `true`. If you have
implemented a custom provider, this might affect you.
- `Socket` class is no longer in use and has been removed. Unless you used this
class you don’t need to do anything.
- Remove deprecated options `serverUrl` and `serverPattern` (they were merely
defined in Typescript, not in use).
- `RequestClient` methods `get`, `post`, `delete` no longer accepts a boolean as
the third argument. Instead, pass `{ skipPostResponse: true | false }`. This
won’t affect you unless you’ve been using `RequestClient`.

## Migrate from Robodog to Uppy plugins

Uppy is flexible and extensible through plugins. But the integration code could
Expand Down
4 changes: 2 additions & 2 deletions docs/sources/companion-plugins/url.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ new Uppy()

### Use in Companion

Companion supports this plugin out-of-the-box so integration is required on this
side.
Companion supports this plugin out-of-the-box, however it must be enabled in
Companion with the `enableUrlEndpoint` / `COMPANION_ENABLE_URL_ENDPOINT` option.

## API

Expand Down
1 change: 1 addition & 0 deletions e2e/start-companion-with-load-balancer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const startCompanion = ({ name, port }) => {
COMPANION_SECRET: 'development', // multi instance will not work without secret set
COMPANION_PREAUTH_SECRET: 'development', // multi instance will not work without secret set
COMPANION_ALLOW_LOCAL_URLS: 'true',
COMPANION_ENABLE_URL_ENDPOINT: 'true',
COMPANION_LOGGER_PROCESS_NAME: name,
},
})
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-provider/server/CustomProvider.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function adaptData (res) {
class MyCustomProvider {
static version = 2

static get authProvider () {
static get oauthProvider () {
return 'myunsplash'
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ export default class AwsS3Multipart<
this.type = 'uploader'
this.id = this.opts.id || 'AwsS3Multipart'
// TODO: only initiate `RequestClient` is `companionUrl` is defined.
this.#client = new RequestClient(uppy, opts as any)
this.#client = new RequestClient(uppy, (opts as any) ?? {})

const dynamicDefaultOptions = {
createMultipartUpload: this.createMultipartUpload,
Expand Down
7 changes: 1 addition & 6 deletions packages/@uppy/companion-client/src/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import type { UnknownProviderPlugin } from '@uppy/core/lib/Uppy'
import RequestClient, { authErrorStatusCode } from './RequestClient.ts'
import type { CompanionPluginOptions } from './index.js'

// TODO: remove deprecated options in next major release
export interface Opts extends PluginOpts, CompanionPluginOptions {
/** @deprecated */
serverUrl?: string
/** @deprecated */
serverPattern?: string
pluginId: string
name?: string
supportsRefreshToken?: boolean
Expand Down Expand Up @@ -87,7 +82,7 @@ export default class Provider<M extends Meta, B extends Body>
this.tokenKey = `companion-${this.pluginId}-auth-token`
this.companionKeysParams = this.opts.companionKeysParams
this.preAuthToken = null
this.supportsRefreshToken = opts.supportsRefreshToken ?? true // todo false in next major
this.supportsRefreshToken = !!opts.supportsRefreshToken
}

async headers(): Promise<Record<string, string>> {
Expand Down
22 changes: 4 additions & 18 deletions packages/@uppy/companion-client/src/RequestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export type Opts = {
companionKeysParams?: Record<string, string>
}

type _RequestOptions =
| boolean // TODO: remove this on the next major
| RequestOptions

// Remove the trailing slash so we can always safely append /xyz.
function stripSlash(url: string) {
return url.replace(/\/$/, '')
Expand Down Expand Up @@ -98,8 +94,7 @@ export default class RequestClient<M extends Meta, B extends Body> {
this.uppy = uppy
this.opts = opts
this.onReceiveResponse = this.onReceiveResponse.bind(this)
// TODO: Remove optional chaining
this.#companionHeaders = opts?.companionHeaders
this.#companionHeaders = opts.companionHeaders
}

setCompanionHeaders(headers: Record<string, string>): void {
Expand Down Expand Up @@ -196,33 +191,24 @@ export default class RequestClient<M extends Meta, B extends Body> {

async get<PostBody>(
path: string,
options?: _RequestOptions,
options?: RequestOptions,
): Promise<PostBody> {
// TODO: remove boolean support for options that was added for backward compatibility.
// eslint-disable-next-line no-param-reassign
if (typeof options === 'boolean') options = { skipPostResponse: options }
return this.request({ ...options, path })
}

async post<PostBody>(
path: string,
data: Record<string, unknown>,
options?: _RequestOptions,
options?: RequestOptions,
): Promise<PostBody> {
// TODO: remove boolean support for options that was added for backward compatibility.
// eslint-disable-next-line no-param-reassign
if (typeof options === 'boolean') options = { skipPostResponse: options }
return this.request<PostBody>({ ...options, path, method: 'POST', data })
}

async delete<T>(
path: string,
data?: Record<string, unknown>,
options?: _RequestOptions,
options?: RequestOptions,
): Promise<T> {
// TODO: remove boolean support for options that was added for backward compatibility.
// eslint-disable-next-line no-param-reassign
if (typeof options === 'boolean') options = { skipPostResponse: options }
return this.request({ ...options, path, method: 'DELETE', data })
}

Expand Down
202 changes: 0 additions & 202 deletions packages/@uppy/companion-client/src/Socket.test.ts

This file was deleted.

Loading
Loading