@uppy/companion-client
Advanced tools
Comparing version 3.7.2 to 3.7.3
# @uppy/companion-client | ||
## 3.7.3 | ||
Released: 2024-02-22 | ||
Included in: Uppy v3.22.2 | ||
- @uppy/companion-client: fix body/url on upload-success (Merlijn Vos / #4922) | ||
- @uppy/companion-client: remove unnecessary `'use strict'` directives (Antoine du Hamel / #4943) | ||
- @uppy/companion-client: type changes for provider-views (Antoine du Hamel / #4938) | ||
- @uppy/companion-client: update types (Antoine du Hamel / #4927) | ||
## 3.7.1 | ||
@@ -4,0 +14,0 @@ |
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
let _Symbol$for; | ||
@@ -18,3 +16,3 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
const packageJson = { | ||
"version": "3.7.2" | ||
"version": "3.7.3" | ||
}; | ||
@@ -325,3 +323,2 @@ // Remove the trailing slash so we can always safely append /xyz. | ||
const token = file.serverToken; | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const host = getSocketHost(file.remote.companionUrl); | ||
@@ -402,8 +399,9 @@ let socket; | ||
{ | ||
var _socketAbortControlle2; | ||
this.uppy.emit('upload-success', this.uppy.getFile(file.id), | ||
// @ts-expect-error event expects a lot more data. | ||
// TODO: add missing data? | ||
{ | ||
uploadURL: payload.url | ||
var _payload$response, _payload$response$sta, _payload$response2, _socketAbortControlle2; | ||
// payload.response exists for xhr-upload but not for tus/transloadit | ||
const text = (_payload$response = payload.response) == null ? void 0 : _payload$response.responseText; | ||
this.uppy.emit('upload-success', this.uppy.getFile(file.id), { | ||
uploadURL: payload.url, | ||
status: (_payload$response$sta = (_payload$response2 = payload.response) == null ? void 0 : _payload$response2.status) != null ? _payload$response$sta : 200, | ||
body: text ? JSON.parse(text) : undefined | ||
}); | ||
@@ -410,0 +408,0 @@ (_socketAbortControlle2 = socketAbortController) == null || _socketAbortControlle2.abort == null || _socketAbortControlle2.abort(); |
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
import RequestClient from "./RequestClient.js"; | ||
@@ -4,0 +2,0 @@ const getName = id => { |
@@ -66,3 +66,2 @@ let _Symbol$for, _Symbol$for2; | ||
const first = _classPrivateFieldLooseBase(this, _queued)[_queued].shift(); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
this.send(first.action, first.payload); | ||
@@ -69,0 +68,0 @@ } |
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
/** | ||
@@ -4,0 +2,0 @@ * This module serves as an Async wrapper for LocalStorage |
{ | ||
"name": "@uppy/companion-client", | ||
"description": "Client library for communication with Companion. Intended for use in Uppy plugins.", | ||
"version": "3.7.2", | ||
"version": "3.7.3", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/utils": "^5.7.2", | ||
"@uppy/utils": "^5.7.3", | ||
"namespace-emitter": "^2.0.1", | ||
@@ -34,4 +34,4 @@ "p-retry": "^6.1.0" | ||
"peerDependencies": { | ||
"@uppy/core": "^3.9.1" | ||
"@uppy/core": "^3.9.2" | ||
} | ||
} |
@@ -1,8 +0,10 @@ | ||
import type { Uppy, BasePlugin } from '@uppy/core' | ||
import type { Body, Meta, UppyFile } from '@uppy/utils/lib/UppyFile' | ||
import type { Uppy } from '@uppy/core' | ||
import type { Body, Meta } from '@uppy/utils/lib/UppyFile' | ||
import type { PluginOpts } from '@uppy/core/lib/BasePlugin.ts' | ||
import RequestClient, { | ||
authErrorStatusCode, | ||
type RequestOptions, | ||
} from './RequestClient.ts' | ||
import type { | ||
RequestOptions, | ||
CompanionClientProvider, | ||
} from '@uppy/utils/lib/CompanionClientProvider' | ||
import type { UnknownProviderPlugin } from '@uppy/core/lib/Uppy.ts' | ||
import RequestClient, { authErrorStatusCode } from './RequestClient.ts' | ||
import * as tokenStorage from './tokenStorage.ts' | ||
@@ -25,9 +27,2 @@ | ||
interface ProviderPlugin<M extends Meta, B extends Body> | ||
extends BasePlugin<Opts, M, B> { | ||
files: UppyFile<M, B>[] | ||
storage: typeof tokenStorage | ||
} | ||
const getName = (id: string) => { | ||
@@ -68,6 +63,6 @@ return id | ||
export default class Provider< | ||
M extends Meta, | ||
B extends Body, | ||
> extends RequestClient<M, B> { | ||
export default class Provider<M extends Meta, B extends Body> | ||
extends RequestClient<M, B> | ||
implements CompanionClientProvider | ||
{ | ||
#refreshingTokenPromise: Promise<void> | undefined | ||
@@ -146,3 +141,6 @@ | ||
#getPlugin() { | ||
const plugin = this.uppy.getPlugin(this.pluginId) as ProviderPlugin<M, B> | ||
const plugin = this.uppy.getPlugin(this.pluginId) as UnknownProviderPlugin< | ||
M, | ||
B | ||
> | ||
if (plugin == null) throw new Error('Plugin was nullish') | ||
@@ -311,3 +309,3 @@ return plugin | ||
protected async request<ResBody extends Record<string, unknown>>( | ||
protected async request<ResBody>( | ||
...args: Parameters<RequestClient<M, B>['request']> | ||
@@ -382,3 +380,3 @@ ): Promise<ResBody> { | ||
list<ResBody extends Record<string, unknown>>( | ||
list<ResBody>( | ||
directory: string | undefined, | ||
@@ -390,5 +388,3 @@ options: RequestOptions, | ||
async logout<ResBody extends Record<string, unknown>>( | ||
options: RequestOptions, | ||
): Promise<ResBody> { | ||
async logout<ResBody>(options?: RequestOptions): Promise<ResBody> { | ||
const response = await this.get<ResBody>(`${this.id}/logout`, options) | ||
@@ -400,3 +396,3 @@ await this.removeAuthToken() | ||
static initPlugin( | ||
plugin: ProviderPlugin<any, any>, // any because static methods cannot use class generics | ||
plugin: UnknownProviderPlugin<any, any>, // any because static methods cannot use class generics | ||
opts: Opts, | ||
@@ -403,0 +399,0 @@ defaultOpts: Record<string, unknown>, |
@@ -1,3 +0,1 @@ | ||
'use strict' | ||
import UserFacingApiError from '@uppy/utils/lib/UserFacingApiError' | ||
@@ -14,2 +12,3 @@ // eslint-disable-next-line import/no-extraneous-dependencies | ||
import type { UppyFile, Meta, Body } from '@uppy/utils/lib/UppyFile' | ||
import type { RequestOptions } from '@uppy/utils/lib/CompanionClientProvider.ts' | ||
import AuthError from './AuthError.ts' | ||
@@ -32,11 +31,5 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
export type RequestOptions = | ||
type _RequestOptions = | ||
| boolean // TODO: remove this on the next major | ||
| { | ||
method?: string | ||
data?: Record<string, unknown> | ||
skipPostResponse?: boolean | ||
signal?: AbortSignal | ||
qs?: Record<string, string> | ||
} | ||
| RequestOptions | ||
@@ -69,5 +62,3 @@ // Remove the trailing slash so we can always safely append /xyz. | ||
async function handleJSONResponse<ResJson extends Record<string, unknown>>( | ||
res: Response, | ||
): Promise<ResJson> { | ||
async function handleJSONResponse<ResJson>(res: Response): Promise<ResJson> { | ||
if (res.status === authErrorStatusCode) { | ||
@@ -169,3 +160,3 @@ throw new AuthError() | ||
protected async request<ResBody extends Record<string, unknown>>({ | ||
protected async request<ResBody>({ | ||
path, | ||
@@ -210,5 +201,5 @@ method = 'GET', | ||
async get<PostBody extends Record<string, unknown>>( | ||
async get<PostBody>( | ||
path: string, | ||
options?: RequestOptions, | ||
options?: _RequestOptions, | ||
): Promise<PostBody> { | ||
@@ -221,6 +212,6 @@ // TODO: remove boolean support for options that was added for backward compatibility. | ||
async post<PostBody extends Record<string, unknown>>( | ||
async post<PostBody>( | ||
path: string, | ||
data: Record<string, unknown>, | ||
options?: RequestOptions, | ||
options?: _RequestOptions, | ||
): Promise<PostBody> { | ||
@@ -233,7 +224,7 @@ // TODO: remove boolean support for options that was added for backward compatibility. | ||
async delete( | ||
async delete<T>( | ||
path: string, | ||
data: Record<string, unknown>, | ||
options?: RequestOptions, | ||
): Promise<unknown> { | ||
data?: Record<string, unknown>, | ||
options?: _RequestOptions, | ||
): Promise<T> { | ||
// TODO: remove boolean support for options that was added for backward compatibility. | ||
@@ -360,3 +351,3 @@ // eslint-disable-next-line no-param-reassign | ||
const res = await this.post( | ||
const res = await this.post<{ token: string }>( | ||
file.remote.url, | ||
@@ -370,3 +361,3 @@ { | ||
return res.token as string | ||
return res.token | ||
} | ||
@@ -395,3 +386,2 @@ | ||
const token = file.serverToken | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const host = getSocketHost(file.remote!.companionUrl) | ||
@@ -502,9 +492,12 @@ | ||
case 'success': { | ||
// payload.response exists for xhr-upload but not for tus/transloadit | ||
const text = payload.response?.responseText | ||
this.uppy.emit( | ||
'upload-success', | ||
this.uppy.getFile(file.id), | ||
// @ts-expect-error event expects a lot more data. | ||
// TODO: add missing data? | ||
{ | ||
uploadURL: payload.url, | ||
status: payload.response?.status ?? 200, | ||
body: text ? JSON.parse(text) : undefined, | ||
}, | ||
@@ -511,0 +504,0 @@ ) |
@@ -1,5 +0,4 @@ | ||
'use strict' | ||
import type { Body, Meta } from '@uppy/utils/lib/UppyFile.ts' | ||
import type { Uppy } from '@uppy/core' | ||
import type { CompanionClientSearchProvider } from '@uppy/utils/lib/CompanionClientProvider' | ||
import RequestClient, { type Opts } from './RequestClient.ts' | ||
@@ -14,6 +13,6 @@ | ||
export default class SearchProvider< | ||
M extends Meta, | ||
B extends Body, | ||
> extends RequestClient<M, B> { | ||
export default class SearchProvider<M extends Meta, B extends Body> | ||
extends RequestClient<M, B> | ||
implements CompanionClientSearchProvider | ||
{ | ||
provider: string | ||
@@ -39,6 +38,3 @@ | ||
search<ResBody extends Record<string, unknown>>( | ||
text: string, | ||
queries?: string, | ||
): Promise<ResBody> { | ||
search<ResBody>(text: string, queries?: string): Promise<ResBody> { | ||
return this.get<ResBody>( | ||
@@ -45,0 +41,0 @@ `search/${this.id}/list?q=${encodeURIComponent(text)}${ |
@@ -53,5 +53,4 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
while (this.#queued.length > 0 && this.#isOpen) { | ||
const first = this.#queued.shift() | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
this.send(first!.action, first!.payload) | ||
const first = this.#queued.shift()! | ||
this.send(first.action, first.payload) | ||
} | ||
@@ -58,0 +57,0 @@ } |
@@ -1,3 +0,1 @@ | ||
'use strict' | ||
/** | ||
@@ -4,0 +2,0 @@ * This module serves as an Async wrapper for LocalStorage |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167186
2336
Updated@uppy/utils@^5.7.3