From 5bc29156555fb3f0ec3ad80c6a25ccc2d0bb4ec0 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 18 Mar 2024 09:10:07 -0400 Subject: [PATCH] style: prettier --- src/utils/options.ts | 93 ++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/src/utils/options.ts b/src/utils/options.ts index fc2c8e9..70ff074 100644 --- a/src/utils/options.ts +++ b/src/utils/options.ts @@ -1,5 +1,5 @@ -import {AxiosHeaders, AxiosProgressEvent, AxiosRequestConfig} from "axios"; -import {S5Client} from "../client.js"; +import { AxiosHeaders, AxiosProgressEvent, AxiosRequestConfig } from "axios"; +import { S5Client } from "../client.js"; /** * Custom client options. @@ -12,64 +12,63 @@ import {S5Client} from "../client.js"; */ export type CustomClientOptions = { - apiKey?: string; - customUserAgent?: string; - customCookie?: string; - onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void; - onUploadProgress?: (progressEvent: AxiosProgressEvent) => void; + apiKey?: string; + customUserAgent?: string; + customCookie?: string; + onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void; + onUploadProgress?: (progressEvent: AxiosProgressEvent) => void; }; export function optionsToConfig( - client: S5Client, - def: CustomClientOptions, - ...options: CustomClientOptions[] + client: S5Client, + def: CustomClientOptions, + ...options: CustomClientOptions[] ): AxiosRequestConfig { - const config: AxiosRequestConfig = {}; + const config: AxiosRequestConfig = {}; - config.baseURL = client.portalUrl; + config.baseURL = client.portalUrl; - const extraOptions = options.reduce((acc, val) => { - return { - ...acc, - ...val, - }; - }, options); + const extraOptions = options.reduce((acc, val) => { + return { + ...acc, + ...val, + }; + }, options); - const finalOptions = { - ...def, - ...client.customOptions, - ...extraOptions, - } as CustomClientOptions; + const finalOptions = { + ...def, + ...client.customOptions, + ...extraOptions, + } as CustomClientOptions; - if (finalOptions?.onDownloadProgress) { - config.onDownloadProgress = finalOptions?.onDownloadProgress; - } + if (finalOptions?.onDownloadProgress) { + config.onDownloadProgress = finalOptions?.onDownloadProgress; + } - if (finalOptions?.onUploadProgress) { - config.onUploadProgress = finalOptions?.onUploadProgress; - } + if (finalOptions?.onUploadProgress) { + config.onUploadProgress = finalOptions?.onUploadProgress; + } - const headers = new AxiosHeaders(config.headers as AxiosHeaders) + const headers = new AxiosHeaders(config.headers as AxiosHeaders); - if (finalOptions?.customCookie) { - headers.set("Cookie", finalOptions.customCookie); + if (finalOptions?.customCookie) { + headers.set("Cookie", finalOptions.customCookie); + } + if (finalOptions?.customUserAgent) { + headers.set("User-Agent", finalOptions.customUserAgent); + } - } - if (finalOptions?.customUserAgent) { - headers.set("User-Agent", finalOptions.customUserAgent); - } + if (finalOptions?.apiKey) { + headers.set("Authorization", `Bearer ${finalOptions.apiKey}`); + config.withCredentials = true; - if (finalOptions?.apiKey) { - headers.set("Authorization", `Bearer ${finalOptions.apiKey}`); - config.withCredentials = true; + config.params = { + ...config.params, + auth_token: finalOptions?.apiKey, + }; + } - config.params = { - ...config.params, - auth_token: finalOptions?.apiKey, - }; - } + config.headers = headers; - config.headers = headers; - - return config; + return config; }