Kaynağa Gözat

@uppy/companion-client: fix tests and linter (#4890)

Antoine du Hamel 1 yıl önce
ebeveyn
işleme
c0baaef17b

+ 6 - 4
packages/@uppy/companion-client/src/Provider.ts

@@ -54,8 +54,9 @@ function isOriginAllowed(
   origin: string,
   allowedOrigin: string | RegExp | Array<string | RegExp> | undefined,
 ) {
-  const patterns = Array.isArray(allowedOrigin)
-    ? allowedOrigin.map(getRegex)
+  const patterns =
+    Array.isArray(allowedOrigin) ?
+      allowedOrigin.map(getRegex)
     : [getRegex(allowedOrigin)]
   return patterns.some(
     (pattern) => pattern?.test(origin) || pattern?.test(`${origin}/`),
@@ -118,8 +119,9 @@ export default class Provider<
     super.onReceiveResponse(response)
     const plugin = this.#getPlugin()
     const oldAuthenticated = plugin.getPluginState().authenticated
-    const authenticated = oldAuthenticated
-      ? response.status !== authErrorStatusCode
+    const authenticated =
+      oldAuthenticated ?
+        response.status !== authErrorStatusCode
       : response.status < 400
     plugin.setPluginState({ authenticated })
     return response

+ 8 - 7
packages/@uppy/companion-client/src/RequestClient.ts

@@ -110,7 +110,8 @@ export default class RequestClient<M extends Meta, B extends Body> {
     this.uppy = uppy
     this.opts = opts
     this.onReceiveResponse = this.onReceiveResponse.bind(this)
-    this.#companionHeaders = opts.companionHeaders
+    // TODO: Remove optional chaining
+    this.#companionHeaders = opts?.companionHeaders
   }
 
   setCompanionHeaders(headers: Record<string, string>): void {
@@ -130,12 +131,12 @@ export default class RequestClient<M extends Meta, B extends Body> {
   async headers(emptyBody = false): Promise<Record<string, string>> {
     const defaultHeaders = {
       Accept: 'application/json',
-      ...(emptyBody
-        ? undefined
-        : {
-            // Passing those headers on requests with no data forces browsers to first make a preflight request.
-            'Content-Type': 'application/json',
-          }),
+      ...(emptyBody ? undefined : (
+        {
+          // Passing those headers on requests with no data forces browsers to first make a preflight request.
+          'Content-Type': 'application/json',
+        }
+      )),
     }
 
     return {

+ 6 - 6
packages/@uppy/companion-client/tsconfig.json

@@ -6,16 +6,16 @@
     "paths": {
       "@uppy/utils/lib/*": ["../utils/src/*"],
       "@uppy/core": ["../core/src/index.js"],
-      "@uppy/core/lib/*": ["../core/src/*"]
-    }
+      "@uppy/core/lib/*": ["../core/src/*"],
+    },
   },
   "include": ["./package.json", "./src/**/*.*"],
   "references": [
     {
-      "path": "../utils/tsconfig.build.json"
+      "path": "../utils/tsconfig.build.json",
     },
     {
-      "path": "../core/tsconfig.build.json"
-    }
-  ]
+      "path": "../core/tsconfig.build.json",
+    },
+  ],
 }