diff --git a/cspell.json b/cspell.json index 2e4895344..658c0a85e 100644 --- a/cspell.json +++ b/cspell.json @@ -60,6 +60,7 @@ "Scroller", "shopt", "signingkey", + "Skema", "skus", "uninject", "uninjector", diff --git a/src/globals.d.ts b/src/globals.d.ts index 300593293..f40d51cf5 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -6,7 +6,6 @@ import type { WebpackChunkGlobal } from "./types/discord"; import * as replugged from "./renderer/replugged"; import type { RepluggedNativeType } from "./preload"; -// eslint-disable-next-line node/no-extraneous-import import type Lodash from "lodash"; declare global { export var appSettings: { diff --git a/src/renderer/coremods/settings/pages/Addons.tsx b/src/renderer/coremods/settings/pages/Addons.tsx index b9d9dd28e..fae26d11f 100644 --- a/src/renderer/coremods/settings/pages/Addons.tsx +++ b/src/renderer/coremods/settings/pages/Addons.tsx @@ -99,7 +99,7 @@ function listAddons(type: AddonType): Map | Map { if (!users.getUser(id)) { try { - const { body } = await api.get({ + const { body } = await api.HTTP.get({ url: `/users/${id}/profile`, query: { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -113,7 +113,7 @@ async function openUserProfile(id: string): Promise { fluxDispatcher.dispatch({ type: "USER_PROFILE_FETCH_SUCCESS", ...body }); } catch { try { - const { body } = await api.get({ + const { body } = await api.HTTP.get({ url: `/users/${id}`, }); fluxDispatcher.dispatch({ type: "USER_UPDATE", user: body }); diff --git a/src/renderer/modules/common/api.ts b/src/renderer/modules/common/api.ts index 0bdacac21..4197fb234 100644 --- a/src/renderer/modules/common/api.ts +++ b/src/renderer/modules/common/api.ts @@ -35,7 +35,7 @@ interface HTTPRequest { interceptResponse?: HTTPRequest["interceptResponse"], ) => void, reject: (reason: Error) => void, - ) => void; + ) => boolean; onRequestCreated?: (request: Request) => void; onRequestProgress?: (progress: ProgressEvent) => void; } @@ -101,16 +101,28 @@ export declare class APIError { public hasFieldErrors: () => boolean; } -export type API = Record< - "get" | "patch" | "post" | "put" | "delete", +type HTTP = Record< + "get" | "post" | "put" | "patch" | "del", >( req: string | HTTPRequest, callback?: (response: HTTPResponse) => void, ) => Promise> -> & { - getAPIBaseURL: (version?: boolean) => string; +>; + +interface RequestPatch { + prepareRequest: (request: Request) => void; + interceptResponse: Required; +} + +export interface API { + INVALID_FORM_BODY_ERROR_CODE: number; + convertSkemaError: (response: Record) => Record; V6OrEarlierAPIError: typeof V6OrEarlierAPIError; V8APIError: typeof APIError; -}; + HTTP: HTTP; + getAPIBaseURL: (version?: boolean) => string; + setAwaitOnline: (callback: (url: string) => Promise) => void; + setRequestPatch: (patch: RequestPatch) => void; +} -export default await waitForProps("getAPIBaseURL", "get", "patch", "post", "put", "delete"); +export default await waitForProps("getAPIBaseURL", "HTTP"); diff --git a/src/renderer/modules/common/lodash.ts b/src/renderer/modules/common/lodash.ts index f73360de7..c12897111 100644 --- a/src/renderer/modules/common/lodash.ts +++ b/src/renderer/modules/common/lodash.ts @@ -1,4 +1,3 @@ -// eslint-disable-next-line node/no-extraneous-import import type Lodash from "lodash"; import { waitForProps } from "../webpack";