fix: default POST request payloads to an empty object (#1141)

* defaulted carts.create payload to an empty object

* fix linting

* requested changes
This commit is contained in:
Kasper Fabricius Kristensen
2022-03-09 17:19:38 +01:00
committed by GitHub
parent 5f5a2af30b
commit 4e7435e4d7
2 changed files with 34 additions and 11 deletions
+4
View File
@@ -187,6 +187,10 @@ class Client {
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,
+30 -11
View File
@@ -24,7 +24,8 @@ class CartsResource extends BaseResource {
addShippingMethod( addShippingMethod(
cart_id: string, cart_id: string,
payload: StorePostCartsCartShippingMethodReq, payload: StorePostCartsCartShippingMethodReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/shipping-methods` const path = `/store/carts/${cart_id}/shipping-methods`
return this.client.request("POST", path, payload, {}, customHeaders) return this.client.request("POST", path, payload, {}, customHeaders)
} }
@@ -39,7 +40,10 @@ class CartsResource extends BaseResource {
* @param customHeaders * @param customHeaders
* @return {ResponsePromise<StoreCompleteCartRes>} * @return {ResponsePromise<StoreCompleteCartRes>}
*/ */
complete(cart_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCompleteCartRes> { complete(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCompleteCartRes> {
const path = `/store/carts/${cart_id}/complete` const path = `/store/carts/${cart_id}/complete`
return this.client.request("POST", path, {}, {}, customHeaders) return this.client.request("POST", path, {}, {}, customHeaders)
} }
@@ -51,7 +55,10 @@ class CartsResource extends BaseResource {
* @param customHeaders * @param customHeaders
* @return {ResponsePromise<StoreCartsRes>} * @return {ResponsePromise<StoreCartsRes>}
*/ */
create(payload?: StorePostCartReq, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { create(
payload?: StorePostCartReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts` const path = `/store/carts`
return this.client.request("POST", path, payload, {}, customHeaders) return this.client.request("POST", path, payload, {}, customHeaders)
} }
@@ -64,7 +71,10 @@ class CartsResource extends BaseResource {
* @param customHeaders * @param customHeaders
* @return {ResponsePromise<StoreCartsRes>} * @return {ResponsePromise<StoreCartsRes>}
*/ */
createPaymentSessions(cart_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { createPaymentSessions(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-sessions` const path = `/store/carts/${cart_id}/payment-sessions`
return this.client.request("POST", path, {}, {}, customHeaders) return this.client.request("POST", path, {}, {}, customHeaders)
} }
@@ -79,7 +89,8 @@ class CartsResource extends BaseResource {
deleteDiscount( deleteDiscount(
cart_id: string, cart_id: string,
code: string, code: string,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/discounts/${code}` const path = `/store/carts/${cart_id}/discounts/${code}`
return this.client.request("DELETE", path, {}, {}, customHeaders) return this.client.request("DELETE", path, {}, {}, customHeaders)
} }
@@ -95,7 +106,8 @@ class CartsResource extends BaseResource {
deletePaymentSession( deletePaymentSession(
cart_id: string, cart_id: string,
provider_id: string, provider_id: string,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}` const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}`
return this.client.request("DELETE", path, {}, {}, customHeaders) return this.client.request("DELETE", path, {}, {}, customHeaders)
} }
@@ -110,7 +122,8 @@ class CartsResource extends BaseResource {
refreshPaymentSession( refreshPaymentSession(
cart_id: string, cart_id: string,
provider_id: string, provider_id: string,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}/refresh` const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}/refresh`
return this.client.request("POST", path, {}, {}, customHeaders) return this.client.request("POST", path, {}, {}, customHeaders)
} }
@@ -121,7 +134,10 @@ class CartsResource extends BaseResource {
* @param customHeaders * @param customHeaders
* @return {ResponsePromise<StoreCartsRes>} * @return {ResponsePromise<StoreCartsRes>}
*/ */
retrieve(cart_id: string, customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { retrieve(
cart_id: string,
customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}` const path = `/store/carts/${cart_id}`
return this.client.request("GET", path, {}, {}, customHeaders) return this.client.request("GET", path, {}, {}, customHeaders)
} }
@@ -136,7 +152,8 @@ class CartsResource extends BaseResource {
setPaymentSession( setPaymentSession(
cart_id: string, cart_id: string,
payload: StorePostCartsCartPaymentSessionReq, payload: StorePostCartsCartPaymentSessionReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-session` const path = `/store/carts/${cart_id}/payment-session`
return this.client.request("POST", path, payload, {}, customHeaders) return this.client.request("POST", path, payload, {}, customHeaders)
} }
@@ -151,7 +168,8 @@ class CartsResource extends BaseResource {
update( update(
cart_id: string, cart_id: string,
payload: StorePostCartsCartReq, payload: StorePostCartsCartReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}` const path = `/store/carts/${cart_id}`
return this.client.request("POST", path, payload, {}, customHeaders) return this.client.request("POST", path, payload, {}, customHeaders)
} }
@@ -168,7 +186,8 @@ class CartsResource extends BaseResource {
cart_id: string, cart_id: string,
provider_id: string, provider_id: string,
payload: StorePostCartsCartPaymentSessionUpdateReq, payload: StorePostCartsCartPaymentSessionUpdateReq,
customHeaders: Record<string, any> = {}): ResponsePromise<StoreCartsRes> { customHeaders: Record<string, any> = {}
): ResponsePromise<StoreCartsRes> {
const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}` const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}`
return this.client.request("POST", path, payload, {}, customHeaders) return this.client.request("POST", path, payload, {}, customHeaders)
} }