diff --git a/Common/Server/Services/StatusPageCertificateService.ts b/Common/Server/Services/StatusPageCertificateService.ts index 2a0d04af60..1d7b33fc65 100644 --- a/Common/Server/Services/StatusPageCertificateService.ts +++ b/Common/Server/Services/StatusPageCertificateService.ts @@ -24,7 +24,11 @@ export class StatusPageCertificateService extends BaseService { const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol(); return await API.post({ - url: new URL(httpProtocol, AppApiHostname, new Route("/api/workers/cert")), + url: new URL( + httpProtocol, + AppApiHostname, + new Route("/api/workers/cert"), + ), data: body, }); } @@ -40,7 +44,11 @@ export class StatusPageCertificateService extends BaseService { }; return await API.delete({ - url: new URL(httpProtocol, AppApiHostname, new Route("/api/workers/cert")), + url: new URL( + httpProtocol, + AppApiHostname, + new Route("/api/workers/cert"), + ), data: body, }); } @@ -54,7 +62,11 @@ export class StatusPageCertificateService extends BaseService { const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol(); return await API.get({ - url: new URL(httpProtocol, AppApiHostname, new Route("/api/workers/cert")), + url: new URL( + httpProtocol, + AppApiHostname, + new Route("/api/workers/cert"), + ), data: body, }); } diff --git a/Common/Server/Utils/CodeRepository/GitHub/GitHub.ts b/Common/Server/Utils/CodeRepository/GitHub/GitHub.ts index 811ec1b8b1..e54e8d9d51 100644 --- a/Common/Server/Utils/CodeRepository/GitHub/GitHub.ts +++ b/Common/Server/Utils/CodeRepository/GitHub/GitHub.ts @@ -218,20 +218,22 @@ export default class GitHubUtil extends HostedCodeRepository { `https://api.github.com/repos/${data.organizationName}/${data.repositoryName}/pulls`, ); - const result: HTTPErrorResponse | HTTPResponse = await API.post({ - url: url, - data: { - base: data.baseBranchName, - head: data.headBranchName, - title: data.title, - body: data.body, + const result: HTTPErrorResponse | HTTPResponse = await API.post( + { + url: url, + data: { + base: data.baseBranchName, + head: data.headBranchName, + title: data.title, + body: data.body, + }, + headers: { + Authorization: `Bearer ${gitHubToken}`, + Accept: "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", + }, }, - headers: { - Authorization: `Bearer ${gitHubToken}`, - Accept: "application/vnd.github+json", - "X-GitHub-Api-Version": "2022-11-28", - }, - }); + ); if (result instanceof HTTPErrorResponse) { throw result; diff --git a/Common/Server/Utils/Workspace/Slack/Slack.ts b/Common/Server/Utils/Workspace/Slack/Slack.ts index 79f15d8277..c98c3dbc55 100644 --- a/Common/Server/Utils/Workspace/Slack/Slack.ts +++ b/Common/Server/Utils/Workspace/Slack/Slack.ts @@ -118,21 +118,23 @@ export default class SlackUtil extends WorkspaceBase { logger.debug(JSON.stringify(modalJson, null, 2)); // use view.open API to show modal - const result: HTTPErrorResponse | HTTPResponse = await API.post({ - url: URL.fromString("https://slack.com/api/views.open"), - data: { - trigger_id: data.triggerId, - view: modalJson, + const result: HTTPErrorResponse | HTTPResponse = await API.post( + { + url: URL.fromString("https://slack.com/api/views.open"), + data: { + trigger_id: data.triggerId, + view: modalJson, + }, + headers: { + Authorization: `Bearer ${data.authToken}`, + ["Content-Type"]: "application/json", + }, + options: { + retries: 3, + exponentialBackoff: true, + }, }, - headers: { - Authorization: `Bearer ${data.authToken}`, - ["Content-Type"]: "application/json", - }, - options: { - retries: 3, - exponentialBackoff: true, - }, - }); + ); if (result instanceof HTTPErrorResponse) { logger.error("Error response from Slack API:"); diff --git a/Common/Utils/API.ts b/Common/Utils/API.ts index 98f839e706..605d3a2421 100644 --- a/Common/Utils/API.ts +++ b/Common/Utils/API.ts @@ -85,41 +85,31 @@ export default class API { public async get< T extends JSONObject | JSONArray | BaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse> { + >(options: APIRequestOptions): Promise | HTTPErrorResponse> { return await API.get(options); } public async delete< T extends JSONObject | JSONArray | BaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse> { + >(options: APIRequestOptions): Promise | HTTPErrorResponse> { return await API.delete(options); } public async head< T extends JSONObject | JSONArray | BaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse> { + >(options: APIRequestOptions): Promise | HTTPErrorResponse> { return await API.head(options); } public async put< T extends JSONObject | JSONArray | BaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse> { + >(options: APIRequestOptions): Promise | HTTPErrorResponse> { return await API.put(options); } public async patch< T extends JSONObject | JSONArray | BaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse> { + >(options: APIRequestOptions): Promise | HTTPErrorResponse> { return await API.patch(options); } @@ -180,9 +170,7 @@ export default class API { | Array | AnalyticsBaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse>; + >(options: APIRequestOptions): Promise | HTTPErrorResponse>; public static async get< T extends | JSONObject @@ -207,21 +195,26 @@ export default class API { undefined, options, ); - } else { - // New signature - const { url, data: newData, headers: newHeaders, params, options: newOptions } = urlOrOptions; - if (!url) { - throw new APIException("URL is required for static method"); - } - return await this.fetch( - HTTPMethod.GET, - url, - newData || undefined, - newHeaders, - params, - newOptions, - ); } + // New signature + const { + url, + data: newData, + headers: newHeaders, + params, + options: newOptions, + } = urlOrOptions; + if (!url) { + throw new APIException("URL is required for static method"); + } + return await this.fetch( + HTTPMethod.GET, + url, + newData || undefined, + newHeaders, + params, + newOptions, + ); } public static async delete< @@ -246,9 +239,7 @@ export default class API { | Array | AnalyticsBaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse>; + >(options: APIRequestOptions): Promise | HTTPErrorResponse>; public static async delete< T extends | JSONObject @@ -273,21 +264,26 @@ export default class API { undefined, options, ); - } else { - // New signature - const { url, data: newData, headers: newHeaders, params, options: newOptions } = urlOrOptions; - if (!url) { - throw new APIException("URL is required for static method"); - } - return await this.fetch( - HTTPMethod.DELETE, - url, - newData || undefined, - newHeaders, - params, - newOptions, - ); } + // New signature + const { + url, + data: newData, + headers: newHeaders, + params, + options: newOptions, + } = urlOrOptions; + if (!url) { + throw new APIException("URL is required for static method"); + } + return await this.fetch( + HTTPMethod.DELETE, + url, + newData || undefined, + newHeaders, + params, + newOptions, + ); } public static async head< @@ -312,9 +308,7 @@ export default class API { | Array | AnalyticsBaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse>; + >(options: APIRequestOptions): Promise | HTTPErrorResponse>; public static async head< T extends | JSONObject @@ -339,21 +333,26 @@ export default class API { undefined, options, ); - } else { - // New signature - const { url, data: newData, headers: newHeaders, params, options: newOptions } = urlOrOptions; - if (!url) { - throw new APIException("URL is required for static method"); - } - return await this.fetch( - HTTPMethod.HEAD, - url, - newData || undefined, - newHeaders, - params, - newOptions, - ); } + // New signature + const { + url, + data: newData, + headers: newHeaders, + params, + options: newOptions, + } = urlOrOptions; + if (!url) { + throw new APIException("URL is required for static method"); + } + return await this.fetch( + HTTPMethod.HEAD, + url, + newData || undefined, + newHeaders, + params, + newOptions, + ); } public static async put< @@ -378,9 +377,7 @@ export default class API { | Array | AnalyticsBaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse>; + >(options: APIRequestOptions): Promise | HTTPErrorResponse>; public static async put< T extends | JSONObject @@ -405,21 +402,26 @@ export default class API { undefined, options, ); - } else { - // New signature - const { url, data: newData, headers: newHeaders, params, options: newOptions } = urlOrOptions; - if (!url) { - throw new APIException("URL is required for static method"); - } - return await this.fetch( - HTTPMethod.PUT, - url, - newData || undefined, - newHeaders, - params, - newOptions, - ); } + // New signature + const { + url, + data: newData, + headers: newHeaders, + params, + options: newOptions, + } = urlOrOptions; + if (!url) { + throw new APIException("URL is required for static method"); + } + return await this.fetch( + HTTPMethod.PUT, + url, + newData || undefined, + newHeaders, + params, + newOptions, + ); } public static async patch< @@ -444,9 +446,7 @@ export default class API { | Array | AnalyticsBaseModel | Array, - >( - options: APIRequestOptions, - ): Promise | HTTPErrorResponse>; + >(options: APIRequestOptions): Promise | HTTPErrorResponse>; public static async patch< T extends | JSONObject @@ -471,21 +471,26 @@ export default class API { undefined, options, ); - } else { - // New signature - const { url, data: newData, headers: newHeaders, params, options: newOptions } = urlOrOptions; - if (!url) { - throw new APIException("URL is required for static method"); - } - return await this.fetch( - HTTPMethod.PATCH, - url, - newData || undefined, - newHeaders, - params, - newOptions, - ); } + // New signature + const { + url, + data: newData, + headers: newHeaders, + params, + options: newOptions, + } = urlOrOptions; + if (!url) { + throw new APIException("URL is required for static method"); + } + return await this.fetch( + HTTPMethod.PATCH, + url, + newData || undefined, + newHeaders, + params, + newOptions, + ); } public static async post< @@ -512,21 +517,26 @@ export default class API { undefined, options, ); - } else { - // New signature - const { url, data: newData, headers: newHeaders, params, options: newOptions } = urlOrOptions; - if (!url) { - throw new APIException("URL is required for static method"); - } - return await this.fetch( - HTTPMethod.POST, - url, - newData || undefined, - newHeaders, - params, - newOptions, - ); } + // New signature + const { + url, + data: newData, + headers: newHeaders, + params, + options: newOptions, + } = urlOrOptions; + if (!url) { + throw new APIException("URL is required for static method"); + } + return await this.fetch( + HTTPMethod.POST, + url, + newData || undefined, + newHeaders, + params, + newOptions, + ); } public static async fetch< @@ -555,21 +565,27 @@ export default class API { params, options, ); - } else { - // New signature - const { method, url: newUrl, data: newData, headers: newHeaders, params: newParams, options: newOptions } = methodOrOptions; - if (!newUrl) { - throw new APIException("URL is required for static method"); - } - return await this.fetchInternal( - method, - newUrl, - newData, - newHeaders, - newParams, - newOptions, - ); } + // New signature + const { + method, + url: newUrl, + data: newData, + headers: newHeaders, + params: newParams, + options: newOptions, + } = methodOrOptions; + if (!newUrl) { + throw new APIException("URL is required for static method"); + } + return await this.fetchInternal( + method, + newUrl, + newData, + newHeaders, + newParams, + newOptions, + ); } private static async fetchInternal< diff --git a/Dashboard/src/Components/Slack/SlackChannelCacheModal.tsx b/Dashboard/src/Components/Slack/SlackChannelCacheModal.tsx index 9f4275167d..335ef6c16d 100644 --- a/Dashboard/src/Components/Slack/SlackChannelCacheModal.tsx +++ b/Dashboard/src/Components/Slack/SlackChannelCacheModal.tsx @@ -1,8 +1,4 @@ -import React, { - FunctionComponent, - ReactElement, - useEffect, -} from "react"; +import React, { FunctionComponent, ReactElement, useEffect } from "react"; import Modal from "Common/UI/Components/Modal/Modal"; import { ButtonStyleType } from "Common/UI/Components/Button/Button"; import Dictionary from "Common/UI/Components/Dictionary/Dictionary"; @@ -53,7 +49,7 @@ const SlackChannelCacheModal: FunctionComponent = ( const cacheObj: JSONObject = response.data || {}; const newChannelCache: { [channelName: string]: string } = {}; - + Object.keys(cacheObj).forEach((key: string) => { const value: any = (cacheObj as any)[key]; // value may be either {id, name} or just {id}. Prefer id @@ -61,7 +57,7 @@ const SlackChannelCacheModal: FunctionComponent = ( (value?.id as string) || (value as any)?.toString?.() || ""; newChannelCache[key] = id; }); - + setChannelCache(newChannelCache); } catch (e: unknown) { setError(API.getFriendlyErrorMessage(e as Exception)); diff --git a/Home/Routes.ts b/Home/Routes.ts index f4214dcbe2..b693fe5ab9 100755 --- a/Home/Routes.ts +++ b/Home/Routes.ts @@ -986,7 +986,9 @@ const HomeFeatureSet: FeatureSet = { if (!gitHubBasicInfo) { const basicInfo: HTTPResponse = await API.get({ - url: URL.fromString("https://api.github.com/repos/oneuptime/oneuptime"), + url: URL.fromString( + "https://api.github.com/repos/oneuptime/oneuptime", + ), }); gitHubBasicInfo = basicInfo.data as JSONObject;