diff --git a/src/backend/extension/plasmo.ts b/src/backend/extension/plasmo.ts index 4a7aaad3..14a5481f 100644 --- a/src/backend/extension/plasmo.ts +++ b/src/backend/extension/plasmo.ts @@ -15,25 +15,16 @@ export type ExtensionHelloResponse = ExtensionBaseResponse<{ hasPermission: boolean; }>; -export type ExtensionMakeRequestBody = - | { - bodyType: "string"; - value: string; - } - | { - bodyType: "FormData" | "URLSearchParams" | "object"; - value: Record; - }; - -export type ExtensionMakeRequestBodyType = ExtensionMakeRequestBody["bodyType"]; - export interface ExtensionMakeRequest extends ExtensionBaseRequest { url: string; method: string; headers?: Record; - body?: ExtensionMakeRequestBody; + body?: string | Record; + bodyType?: "string" | "FormData" | "URLSearchParams" | "object"; } +export type ExtensionMakeRequestBodyType = ExtensionMakeRequest["bodyType"]; + export type ExtensionMakeRequestResponse = ExtensionBaseResponse<{ response: { statusCode: number; diff --git a/src/backend/extension/request.ts b/src/backend/extension/request.ts index 3e3f9b8b..96f3b61c 100644 --- a/src/backend/extension/request.ts +++ b/src/backend/extension/request.ts @@ -7,7 +7,7 @@ export function getBodyTypeFromBody( if (body instanceof FormData) return "FormData"; if (body instanceof URLSearchParams) return "URLSearchParams"; if (typeof body === "object") return "object"; - return "string"; + return undefined; } export function convertBodyToObject(body: unknown): any { diff --git a/src/backend/providers/fetchers.ts b/src/backend/providers/fetchers.ts index 0c04013d..5cb6f6ba 100644 --- a/src/backend/providers/fetchers.ts +++ b/src/backend/providers/fetchers.ts @@ -69,14 +69,11 @@ function makeFinalHeaders( export function makeExtensionFetcher() { const fetcher: Fetcher = async (url, ops) => { - const opsWithoutBody = { ...ops, body: undefined }; const result = await sendExtensionRequest({ url, - ...opsWithoutBody, - ...(ops.body && { - body: convertBodyToObject(ops.body), - bodyType: getBodyTypeFromBody(ops.body), - }), + ...ops, + body: convertBodyToObject(ops.body), + bodyType: getBodyTypeFromBody(ops.body), }); if (!result?.success) throw new Error(`extension error: ${result?.error}`); const res = result.response;