fix(medusa-js): Allow payload in DELETE and POST (#1985)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa-js": patch
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Only include payload on POST and DELETE requests
|
||||||
@@ -173,33 +173,32 @@ class Client {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Axios request
|
* Axios request
|
||||||
* @param {Types.RequestMethod} method request method
|
* @param method request method
|
||||||
* @param {string} path request path
|
* @param path request path
|
||||||
* @param {object} payload request payload
|
* @param payload request payload
|
||||||
* @param {RequestOptions} options axios configuration
|
* @param options axios configuration
|
||||||
* @param {object} customHeaders custom request headers
|
* @param customHeaders custom request headers
|
||||||
* @return {object}
|
* @return
|
||||||
*/
|
*/
|
||||||
async request(
|
async request(
|
||||||
method: RequestMethod,
|
method: RequestMethod,
|
||||||
path: string,
|
path: string,
|
||||||
payload: Record<string, any> | null = null,
|
payload: Record<string, any> = {},
|
||||||
options: RequestOptions = {},
|
options: RequestOptions = {},
|
||||||
customHeaders: Record<string, any> = {}
|
customHeaders: Record<string, any> = {}
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
if (method === "POST" && !payload) {
|
|
||||||
payload = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
const reqOpts = {
|
const reqOpts = {
|
||||||
method,
|
method,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
url: path,
|
url: path,
|
||||||
data: payload,
|
|
||||||
json: true,
|
json: true,
|
||||||
headers: this.setHeaders(options, method, path, customHeaders),
|
headers: this.setHeaders(options, method, path, customHeaders),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (["POST", "DELETE"].includes(method)) {
|
||||||
|
reqOpts["data"] = payload
|
||||||
|
}
|
||||||
|
|
||||||
// e.g. data = { cart: { ... } }, response = { status, headers, ... }
|
// e.g. data = { cart: { ... } }, response = { status, headers, ... }
|
||||||
const { data, ...response } = await this.axiosClient(reqOpts)
|
const { data, ...response } = await this.axiosClient(reqOpts)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
import { createWrapper } from "../../../utils"
|
import { createWrapper } from "../../../utils"
|
||||||
|
|
||||||
describe("useAdminDeleteFile hook", () => {
|
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 file_key = "test"
|
||||||
|
|
||||||
const { result, waitFor } = renderHook(() => useAdminDeleteFile(), {
|
const { result, waitFor } = renderHook(() => useAdminDeleteFile(), {
|
||||||
|
|||||||
Reference in New Issue
Block a user