-
Notifications
You must be signed in to change notification settings - Fork 2k
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/companion-client: migrate to TS #4864
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aduh95
reviewed
Jan 16, 2024
aduh95
reviewed
Jan 16, 2024
aduh95
reviewed
Jan 16, 2024
aduh95
reviewed
Jan 16, 2024
aduh95
reviewed
Jan 16, 2024
aduh95
reviewed
Jan 16, 2024
Title is wrong, right? It should be |
aduh95
changed the title
@uppy/provider-views: migrate to TS
@uppy/companion-client: migrate to TS
Jan 17, 2024
Merged
mifi
reviewed
Jan 18, 2024
Diff output filesdiff --git a/packages/@uppy/companion-client/lib/Provider.js b/packages/@uppy/companion-client/lib/Provider.js
index 720d03b..0a71eb2 100644
--- a/packages/@uppy/companion-client/lib/Provider.js
+++ b/packages/@uppy/companion-client/lib/Provider.js
@@ -1,5 +1,3 @@
-"use strict";
-
function _classPrivateFieldLooseBase(receiver, privateKey) {
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
throw new TypeError("attempted to use private field on non-instance");
@@ -35,10 +33,14 @@ function isOriginAllowed(origin, allowedOrigin) {
}
var _refreshingTokenPromise = _classPrivateFieldLooseKey("refreshingTokenPromise");
var _getAuthToken = _classPrivateFieldLooseKey("getAuthToken");
+var _getPlugin = _classPrivateFieldLooseKey("getPlugin");
export default class Provider extends RequestClient {
constructor(uppy, opts) {
var _opts$supportsRefresh;
super(uppy, opts);
+ Object.defineProperty(this, _getPlugin, {
+ value: _getPlugin2,
+ });
Object.defineProperty(this, _getAuthToken, {
value: _getAuthToken2,
});
@@ -78,7 +80,7 @@ export default class Provider extends RequestClient {
}
onReceiveResponse(response) {
super.onReceiveResponse(response);
- const plugin = this.uppy.getPlugin(this.pluginId);
+ const plugin = _classPrivateFieldLooseBase(this, _getPlugin)[_getPlugin]();
const oldAuthenticated = plugin.getPluginState().authenticated;
const authenticated = oldAuthenticated ? response.status !== authErrorStatusCode : response.status < 400;
plugin.setPluginState({
@@ -87,10 +89,10 @@ export default class Provider extends RequestClient {
return response;
}
async setAuthToken(token) {
- return this.uppy.getPlugin(this.pluginId).storage.setItem(this.tokenKey, token);
+ return _classPrivateFieldLooseBase(this, _getPlugin)[_getPlugin]().storage.setItem(this.tokenKey, token);
}
async removeAuthToken() {
- return this.uppy.getPlugin(this.pluginId).storage.removeItem(this.tokenKey);
+ return _classPrivateFieldLooseBase(this, _getPlugin)[_getPlugin]().storage.removeItem(this.tokenKey);
}
async ensurePreAuth() {
if (this.companionKeysParams && !this.preAuthToken) {
@@ -100,14 +102,14 @@ export default class Provider extends RequestClient {
}
}
}
- authQuery() {
+ authQuery(data) {
return {};
}
- authUrl(_temp) {
+ authUrl(_ref) {
let {
authFormData,
query,
- } = _temp === void 0 ? {} : _temp;
+ } = _ref;
const params = new URLSearchParams({
...query,
state: btoa(JSON.stringify({
@@ -122,12 +124,12 @@ export default class Provider extends RequestClient {
}
return `${this.hostname}/${this.id}/connect?${params}`;
}
- async loginSimpleAuth(_ref) {
+ async loginSimpleAuth(_ref2) {
let {
uppyVersions,
authFormData,
signal,
- } = _ref;
+ } = _ref2;
const response = await this.post(`${this.id}/simple-auth`, {
form: authFormData,
}, {
@@ -138,12 +140,12 @@ export default class Provider extends RequestClient {
});
this.setAuthToken(response.uppyAuthToken);
}
- async loginOAuth(_ref2) {
+ async loginOAuth(_ref3) {
let {
uppyVersions,
authFormData,
signal,
- } = _ref2;
+ } = _ref3;
await this.ensurePreAuth();
signal.throwIfAborted();
return new Promise((resolve, reject) => {
@@ -166,7 +168,7 @@ export default class Provider extends RequestClient {
}
const {
companionAllowedHosts,
- } = this.uppy.getPlugin(this.pluginId).opts;
+ } = _classPrivateFieldLooseBase(this, _getPlugin)[_getPlugin]().opts;
if (!isOriginAllowed(e.origin, companionAllowedHosts)) {
reject(new Error(`rejecting event from ${e.origin} vs allowed pattern ${companionAllowedHosts}`));
return;
@@ -195,7 +197,7 @@ export default class Provider extends RequestClient {
resolve(this.setAuthToken(data.token));
};
cleanup = () => {
- authWindow.close();
+ authWindow == null || authWindow.close();
window.removeEventListener("message", handleToken);
signal.removeEventListener("abort", cleanup);
};
@@ -203,12 +205,12 @@ export default class Provider extends RequestClient {
window.addEventListener("message", handleToken);
});
}
- async login(_ref3) {
+ async login(_ref4) {
let {
uppyVersions,
authFormData,
signal,
- } = _ref3;
+ } = _ref4;
return this.loginOAuth({
uppyVersions,
authFormData,
@@ -305,5 +307,10 @@ export default class Provider extends RequestClient {
}
}
async function _getAuthToken2() {
- return this.uppy.getPlugin(this.pluginId).storage.getItem(this.tokenKey);
+ return _classPrivateFieldLooseBase(this, _getPlugin)[_getPlugin]().storage.getItem(this.tokenKey);
+}
+function _getPlugin2() {
+ const plugin = this.uppy.getPlugin(this.pluginId);
+ if (plugin == null) throw new Error("Plugin was nullish");
+ return plugin;
}
diff --git a/packages/@uppy/companion-client/lib/RequestClient.js b/packages/@uppy/companion-client/lib/RequestClient.js
index 4edc0fa..010fcaf 100644
--- a/packages/@uppy/companion-client/lib/RequestClient.js
+++ b/packages/@uppy/companion-client/lib/RequestClient.js
@@ -34,7 +34,6 @@ class HttpError extends Error {
message,
} = _ref;
super(message);
- this.statusCode = void 0;
this.name = "HttpError";
this.statusCode = statusCode;
}
@@ -85,18 +84,21 @@ export default class RequestClient {
Object.defineProperty(this, _requestSocketToken, {
writable: true,
value: async _ref2 => {
+ var _file$remote;
let {
file,
postBody,
signal,
} = _ref2;
- if (file.remote.url == null) {
+ if (((_file$remote = file.remote) == null ? void 0 : _file$remote.url) == null) {
throw new Error("Cannot connect to an undefined URL");
}
const res = await this.post(file.remote.url, {
...file.remote.body,
...postBody,
- }, signal);
+ }, {
+ signal,
+ });
return res.token;
},
});
@@ -135,10 +137,10 @@ export default class RequestClient {
..._classPrivateFieldLooseBase(this, _companionHeaders)[_companionHeaders],
};
}
- onReceiveResponse(_ref3) {
- let {
+ onReceiveResponse(res) {
+ const {
headers,
- } = _ref3;
+ } = res;
const state = this.uppy.getState();
const companion = state.companion || {};
const host = this.opts.companionUrl;
@@ -151,14 +153,14 @@ export default class RequestClient {
});
}
}
- async request(_ref4) {
+ async request(_ref3) {
let {
path,
method = "GET",
data,
skipPostResponse,
signal,
- } = _ref4;
+ } = _ref3;
try {
const headers = await this.headers(!data);
const response = await fetchWithNetworkError(_classPrivateFieldLooseBase(this, _getUrl)[_getUrl](path), {
@@ -178,9 +180,6 @@ export default class RequestClient {
}
}
async get(path, options) {
- if (options === void 0) {
- options = undefined;
- }
if (typeof options === "boolean") {
options = {
skipPostResponse: options,
@@ -192,9 +191,6 @@ export default class RequestClient {
});
}
async post(path, data, options) {
- if (options === void 0) {
- options = undefined;
- }
if (typeof options === "boolean") {
options = {
skipPostResponse: options,
@@ -208,9 +204,6 @@ export default class RequestClient {
});
}
async delete(path, data, options) {
- if (data === void 0) {
- data = undefined;
- }
if (typeof options === "boolean") {
options = {
skipPostResponse: options,
@@ -225,14 +218,11 @@ export default class RequestClient {
}
async uploadRemoteFile(file, reqBody, options) {
var _this = this;
- if (options === void 0) {
- options = {};
- }
try {
const {
signal,
getQueue,
- } = options;
+ } = options || {};
return await pRetry(async () => {
var _this$uppy$getFile;
const existingServerToken = (_this$uppy$getFile = this.uppy.getFile(file.id)) == null
@@ -296,12 +286,12 @@ function _getUrl2(url) {
}
return `${this.hostname}/${url}`;
}
-async function _awaitRemoteFileUpload2(_ref5) {
+async function _awaitRemoteFileUpload2(_ref4) {
let {
file,
queue,
signal,
- } = _ref5;
+ } = _ref4;
let removeEventHandlers;
const {
capabilities,
@@ -360,7 +350,7 @@ async function _awaitRemoteFileUpload2(_ref5) {
try {
await queue.wrapPromiseFunction(async () => {
const reconnectWebsocket = async () =>
- new Promise((resolveSocket, rejectSocket) => {
+ new Promise((_, rejectSocket) => {
socket = new WebSocket(`${host}/api/${token}`);
resetActivityTimeout();
socket.addEventListener("close", () => {
@@ -368,8 +358,9 @@ async function _awaitRemoteFileUpload2(_ref5) {
rejectSocket(new Error("Socket closed unexpectedly"));
});
socket.addEventListener("error", error => {
+ var _socket2;
this.uppy.log(`Companion socket error ${JSON.stringify(error)}, closing socket`, "warning");
- socket.close();
+ (_socket2 = socket) == null || _socket2.close();
});
socket.addEventListener("open", () => {
sendState();
@@ -457,11 +448,11 @@ async function _awaitRemoteFileUpload2(_ref5) {
this.uppy.log(`upload ${file.id} was removed`, "info");
resolve();
};
- const onCancelAll = _ref6 => {
+ const onCancelAll = _ref5 => {
var _socketAbortControlle5;
let {
reason,
- } = _ref6;
+ } = _ref5;
if (reason === "user") {
socketSend("cancel");
} |
Murderlon
force-pushed
the
ts-provider-views
branch
from
January 18, 2024 15:07
e93ef8e
to
48dac69
Compare
aduh95
reviewed
Jan 18, 2024
aduh95
reviewed
Jan 18, 2024
aduh95
reviewed
Jan 18, 2024
aduh95
reviewed
Jan 18, 2024
aduh95
reviewed
Jan 19, 2024
aduh95
reviewed
Jan 19, 2024
aduh95
reviewed
Jan 22, 2024
aduh95
reviewed
Jan 22, 2024
aduh95
approved these changes
Jan 22, 2024
aduh95
reviewed
Jan 23, 2024
aduh95
reviewed
Jan 23, 2024
aduh95
reviewed
Jan 23, 2024
aduh95
reviewed
Jan 23, 2024
Co-authored-by: Antoine du Hamel <antoine@transloadit.com>
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
Co-authored-by: Antoine du Hamel <antoine@transloadit.com>
Murderlon
force-pushed
the
ts-provider-views
branch
from
January 24, 2024 10:12
dd1460e
to
1880908
Compare
aduh95
reviewed
Jan 24, 2024
aduh95
approved these changes
Jan 24, 2024
Co-authored-by: Antoine du Hamel <antoine@transloadit.com>
Merged
github-actions bot
added a commit
that referenced
this pull request
Feb 19, 2024
| Package | Version | Package | Version | | ------------------------- | ------- | ------------------------- | ------- | | @uppy/audio | 1.1.5 | @uppy/remote-sources | 1.1.1 | | @uppy/aws-s3 | 3.6.1 | @uppy/status-bar | 3.2.6 | | @uppy/aws-s3-multipart | 3.10.1 | @uppy/store-default | 3.2.1 | | @uppy/companion | 4.12.1 | @uppy/store-redux | 3.0.6 | | @uppy/companion-client | 3.7.1 | @uppy/svelte | 3.1.2 | | @uppy/compressor | 1.1.0 | @uppy/thumbnail-generator | 3.0.7 | | @uppy/core | 3.9.0 | @uppy/transloadit | 3.5.0 | | @uppy/dashboard | 3.7.2 | @uppy/tus | 3.5.1 | | @uppy/drop-target | 2.0.3 | @uppy/utils | 5.7.1 | | @uppy/form | 3.1.0 | @uppy/vue | 1.1.1 | | @uppy/golden-retriever | 3.1.2 | @uppy/webcam | 3.3.5 | | @uppy/image-editor | 2.4.1 | @uppy/xhr-upload | 3.6.1 | | @uppy/locales | 3.5.1 | uppy | 3.22.0 | | @uppy/provider-views | 3.9.0 | | | - @uppy/aws-s3-multipart,@uppy/aws-s3,@uppy/companion-client,@uppy/tus,@uppy/xhr-upload: update `uppyfile` objects before emitting events (antoine du hamel / #4928) - @uppy/transloadit: add `clientname` option (marius / #4920) - @uppy/thumbnail-generator: fix broken previews after cropping (evgenia karunus / #4926) - @uppy/compressor: upgrade compressorjs (merlijn vos / #4924) - @uppy/companion: fix companion dns and allow redirects from http->https again (mikael finstad / #4895) - @uppy/dashboard: autoopenfileeditor - rename "edit file" to "edit image" (evgenia karunus / #4925) - meta: resolve jsx to preact in shared tsconfig (merlijn vos / #4923) - @uppy/image-editor: image editor: make compressor work after the image editor, too (evgenia karunus / #4918) - meta: exclude `tsconfig` files from npm bundles (antoine du hamel / #4916) - @uppy/compressor: migrate to ts (mikael finstad / #4907) - @uppy/provider-views: update uppy-providerbrowser-viewtype--list.scss (aditya patadia / #4913) - @uppy/tus: migrate to ts (merlijn vos / #4899) - meta: bump yarn version (antoine du hamel / #4906) - meta: validate `defaultoptions` for stricter option types (antoine du hamel / #4901) - @uppy/dashboard: Uncouple native camera and video buttons from the `disableLocalFiles` option (jake mcallister / #4894) - meta: put experimental ternaries in .prettierrc.js (merlijn vos / #4900) - @uppy/xhr-upload: migrate to ts (merlijn vos / #4892) - @uppy/drop-target: refactor to typescript (artur paikin / #4863) - meta: fix missing line return in js2ts script (antoine du hamel) - meta: disable `@typescript-eslint/no-empty-function` lint rule (antoine du hamel / #4891) - @uppy/companion-client: fix tests and linter (antoine du hamel / #4890) - @uppy/companion-client: migrate to ts (merlijn vos / #4864) - meta: prettier 3.0.3 -> 3.2.4 (antoine du hamel / #4889) - @uppy/image-editor: migrate to ts (merlijn vos / #4880) - meta: fix race condition in `e2e.yml` (antoine du hamel) - @uppy/core: add utility type to help define plugin option types (antoine du hamel / #4885) - meta: merge `output-watcher` and `e2e` workflows (antoine du hamel / #4886) - @uppy/status-bar: fix `statusbaroptions` type (antoine du hamel / #4883) - @uppy/core: improve types of .use() (merlijn vos / #4882) - @uppy/audio: fix `audiooptions` (antoine du hamel / #4884) - meta: upgrade vite and vitest (antoine du hamel / #4881) - meta: fix `yarn build:clean` (antoine du hamel) - @uppy/audio: refactor to typescript (antoine du hamel / #4860) - @uppy/status-bar: refactor to typescript (antoine du hamel / #4839) - @uppy/core: add `plugintarget` type and mark options as optional (antoine du hamel / #4874) - meta: improve output watcher diff (antoine du hamel / #4876) - meta: minify the output watcher diff further (antoine du hamel) - meta: remove comments from output watcher (mikael finstad / #4875) - @uppy/utils: improve types for `finddomelement` (antoine du hamel / #4873) - @uppy/code: allow plugins to type `pluginstate` (antoine du hamel / #4872) - meta: build(deps): bump follow-redirects from 1.15.1 to 1.15.4 (dependabot[bot] / #4862) - meta: add `output-watcher` gha to help check output diff (antoine du hamel / #4868) - meta: generate locale pack from output file (antoine du hamel / #4867) - meta: comment on what we want to do about close, resetprogress, clearuploadedfiles, etc in the next major (artur paikin / #4865) - meta: fix `yarn build:clean` (antoine du hamel / #4866) - meta: use `explicit-module-boundary-types` lint rule (antoine du hamel / #4858) - @uppy/form: use requestsubmit (merlijn vos / #4852) - @uppy/provider-views: add referrerpolicy to images (merlijn vos / #4853) - @uppy/core: add `debuglogger` as export in manual types (antoine du hamel / #4831) - meta: fix `js2ts` script (antoine du hamel / #4846) - @uppy/xhr-upload: show remove button (merlijn vos / #4851) - meta: upgrade `@transloadit/prettier-bytes` (antoine du hamel / #4850) - @uppy/core: add missing requiredmetafields key in restrictions (darthf1 / #4819) - @uppy/companion,@uppy/tus: bump `tus-js-client` version range (merlijn vos / #4848) - meta: build(deps): bump aws/aws-sdk-php from 3.272.1 to 3.288.1 in /examples/aws-php (dependabot[bot] / #4838) - @uppy/dashboard: fix `typeerror` when `file.remote` is nullish (antoine du hamel / #4825) - meta: fix `js2ts` script (antoine du hamel / #4844) - @uppy/locales: fix "save" button translation in hr_hr.ts (žan žlender / #4830) - meta: fix linting of `.tsx` files (antoine du hamel / #4843) - @uppy/core: fix types (antoine du hamel / #4842) - @uppy/utils: improve `preprocess` and `postprocess` types (antoine du hamel / #4841) - meta: fix `yarn build:clean` (mikael finstad / #4840) - meta: dev: remove extensions from vite aliases (antoine du hamel) - meta: fix `"e2e"` script (antoine du hamel) - @uppy/core: refactor to ts (murderlon) - meta: fix typescript ci (antoine du hamel) - meta: fix clean script (mikael finstad / #4820) - @uppy/companion-client: fix `typeerror` (antoine du hamel)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.