Skip to content

Commit

Permalink
fix: api module not found
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeIlLeone committed Apr 2, 2024
1 parent bd4e5a8 commit ef208fa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"Scroller",
"shopt",
"signingkey",
"Skema",
"skus",
"uninject",
"uninjector",
Expand Down
1 change: 0 additions & 1 deletion src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/coremods/settings/pages/Addons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function listAddons(type: AddonType): Map<string, RepluggedPlugin> | Map<string,
async function openUserProfile(id: string): Promise<void> {
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
Expand All @@ -113,7 +113,7 @@ async function openUserProfile(id: string): Promise<void> {
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 });
Expand Down
26 changes: 19 additions & 7 deletions src/renderer/modules/common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ interface HTTPRequest {
interceptResponse?: HTTPRequest["interceptResponse"],
) => void,
reject: (reason: Error) => void,
) => void;
) => boolean;
onRequestCreated?: (request: Request) => void;
onRequestProgress?: (progress: ProgressEvent) => void;
}
Expand Down Expand Up @@ -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",
<T = Record<string, unknown>>(
req: string | HTTPRequest,
callback?: (response: HTTPResponse) => void,
) => Promise<HTTPResponse<T>>
> & {
getAPIBaseURL: (version?: boolean) => string;
>;

interface RequestPatch {
prepareRequest: (request: Request) => void;
interceptResponse: Required<HTTPRequest["interceptResponse"]>;
}

export interface API {
INVALID_FORM_BODY_ERROR_CODE: number;
convertSkemaError: (response: Record<string, unknown>) => Record<string, unknown>;
V6OrEarlierAPIError: typeof V6OrEarlierAPIError;
V8APIError: typeof APIError;
};
HTTP: HTTP;
getAPIBaseURL: (version?: boolean) => string;
setAwaitOnline: (callback: (url: string) => Promise<void>) => void;
setRequestPatch: (patch: RequestPatch) => void;
}

export default await waitForProps<API>("getAPIBaseURL", "get", "patch", "post", "put", "delete");
export default await waitForProps<API>("getAPIBaseURL", "HTTP");
1 change: 0 additions & 1 deletion src/renderer/modules/common/lodash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line node/no-extraneous-import
import type Lodash from "lodash";
import { waitForProps } from "../webpack";

Expand Down

0 comments on commit ef208fa

Please sign in to comment.