diff --git a/.changeset/five-pets-move.md b/.changeset/five-pets-move.md new file mode 100644 index 0000000000..4ba92fc56e --- /dev/null +++ b/.changeset/five-pets-move.md @@ -0,0 +1,6 @@ +--- +"@medusajs/medusa-js": patch +"@medusajs/medusa": patch +--- + +Only include payload on POST and DELETE requests diff --git a/packages/medusa-js/src/request.ts b/packages/medusa-js/src/request.ts index 0534e53b0e..dd230b32f8 100644 --- a/packages/medusa-js/src/request.ts +++ b/packages/medusa-js/src/request.ts @@ -173,33 +173,32 @@ class Client { /** * Axios request - * @param {Types.RequestMethod} method request method - * @param {string} path request path - * @param {object} payload request payload - * @param {RequestOptions} options axios configuration - * @param {object} customHeaders custom request headers - * @return {object} + * @param method request method + * @param path request path + * @param payload request payload + * @param options axios configuration + * @param customHeaders custom request headers + * @return */ async request( method: RequestMethod, path: string, - payload: Record | null = null, + payload: Record = {}, options: RequestOptions = {}, customHeaders: Record = {} ): Promise { - if (method === "POST" && !payload) { - payload = {} - } - const reqOpts = { method, withCredentials: true, url: path, - data: payload, json: true, headers: this.setHeaders(options, method, path, customHeaders), } + if (["POST", "DELETE"].includes(method)) { + reqOpts["data"] = payload + } + // e.g. data = { cart: { ... } }, response = { status, headers, ... } const { data, ...response } = await this.axiosClient(reqOpts) diff --git a/packages/medusa-react/test/hooks/admin/uploads/mutations.test.ts b/packages/medusa-react/test/hooks/admin/uploads/mutations.test.ts index 2393217b02..2a6db3b886 100644 --- a/packages/medusa-react/test/hooks/admin/uploads/mutations.test.ts +++ b/packages/medusa-react/test/hooks/admin/uploads/mutations.test.ts @@ -7,7 +7,7 @@ import { import { createWrapper } from "../../../utils" describe("useAdminDeleteFile hook", () => { - test("Removes file with key and returns deleteresult", async () => { + test("Removes file with key and returns delete result", async () => { const file_key = "test" const { result, waitFor } = renderHook(() => useAdminDeleteFile(), {