diff --git a/integration-tests/api/__tests__/store/cart.js b/integration-tests/api/__tests__/store/cart.js index b5232bb196..ab9fb24d3b 100644 --- a/integration-tests/api/__tests__/store/cart.js +++ b/integration-tests/api/__tests__/store/cart.js @@ -150,7 +150,7 @@ describe("/store/carts", () => { const cart = getRes.data.cart expect(cart.context).toEqual({ ip: "::ffff:127.0.0.1", - user_agent: "axios/0.21.1", + user_agent: expect.stringContaining("axios/0.21."), test_id: "test", }) }) diff --git a/packages/medusa-js/src/request.ts b/packages/medusa-js/src/request.ts index 302ef247ab..0faf43b7a0 100644 --- a/packages/medusa-js/src/request.ts +++ b/packages/medusa-js/src/request.ts @@ -68,7 +68,7 @@ class Client { } // Stolen from https://github.com/stripe/stripe-node/blob/fd0a597064289b8c82f374f4747d634050739043/lib/utils.js#L282 - normalizeHeaders(obj: object): object { + normalizeHeaders(obj: object): Record { if (!(obj && typeof obj === "object")) { return obj } @@ -109,9 +109,9 @@ class Client { userHeaders: RequestOptions, method: RequestMethod, path: string, - customHeaders: object = {} + customHeaders: Record = {} ): AxiosRequestHeaders { - let defaultHeaders: object = { + let defaultHeaders: Record = { Accept: "application/json", "Content-Type": "application/json", } @@ -183,9 +183,9 @@ class Client { async request( method: RequestMethod, path: string, - payload: object = {}, + payload: Record = {}, options: RequestOptions = {}, - customHeaders: object = {} + customHeaders: Record = {} ): Promise { const reqOpts = { method, diff --git a/packages/medusa-js/src/resources/addresses.ts b/packages/medusa-js/src/resources/addresses.ts index ab88a82a20..a04a0c5845 100644 --- a/packages/medusa-js/src/resources/addresses.ts +++ b/packages/medusa-js/src/resources/addresses.ts @@ -10,37 +10,40 @@ class AddressesResource extends BaseResource { /** * Adds an address to a customers saved addresses * @param {StorePostCustomersCustomerAddressesReq} payload contains information to create an address - * @return {ResponsePromise} + * @param customHeaders + * @return {ResponsePromise} */ addAddress( - payload: StorePostCustomersCustomerAddressesReq - ): ResponsePromise { + payload: StorePostCustomersCustomerAddressesReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/customers/me/addresses` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Deletes an address of a customer * @param {string} address_id id of the address to delete - * @return {ResponsePromise} + * @param customHeaders + * @return {ResponsePromise} */ - deleteAddress(address_id: string): ResponsePromise { + deleteAddress(address_id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/customers/me/addresses/${address_id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * Update an address of a customer * @param {string} address_id id of customer * @param {StorePostCustomersCustomerAddressesAddressReq} payload address update - * @return {StoreCustomersResponse} + * @param customHeaders + * @return {StoreCustomersRes} */ updateAddress( address_id: string, - payload: StorePostCustomersCustomerAddressesAddressReq - ): ResponsePromise { + payload: StorePostCustomersCustomerAddressesAddressReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/customers/me/addresses/${address_id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/auth.ts b/packages/medusa-js/src/resources/admin/auth.ts index ae45b86e7b..0873979b29 100644 --- a/packages/medusa-js/src/resources/admin/auth.ts +++ b/packages/medusa-js/src/resources/admin/auth.ts @@ -6,30 +6,33 @@ class AdminAuthResource extends BaseResource { /** * @description Retrieves an authenticated session * Usually used to check if authenticated session is alive. + * @param customHeaders * @return {ResponsePromise} */ - getSession(): ResponsePromise { + getSession(customHeaders: Record = {}): ResponsePromise { const path = `/admin/auth` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description destroys an authenticated session + * @param customHeaders * @return {ResponsePromise} */ - deleteSession(): ResponsePromise { + deleteSession(customHeaders: Record = {}): ResponsePromise { const path = `/admin/auth` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description Creates an authenticated session * @param {AdminPostAuthReq} payload + * @param customHeaders * @return {ResponsePromise} */ - createSession(payload: AdminPostAuthReq): ResponsePromise { + createSession(payload: AdminPostAuthReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/auth` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/collections.ts b/packages/medusa-js/src/resources/admin/collections.ts index 8439d07d85..4ce8225b01 100644 --- a/packages/medusa-js/src/resources/admin/collections.ts +++ b/packages/medusa-js/src/resources/admin/collections.ts @@ -14,56 +14,64 @@ class AdminCollectionsResource extends BaseResource { /** * @description Creates a collection. * @param payload + * @param customHeaders * @returns Created collection. */ create( - payload: AdminPostCollectionsReq + payload: AdminPostCollectionsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/collections` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description Updates a collection * @param id id of the collection to update. * @param payload update to apply to collection. + * @param customHeaders * @returns the updated collection. */ update( id: string, - payload: AdminPostCollectionsCollectionReq + payload: AdminPostCollectionsCollectionReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/collections/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description deletes a collection * @param id id of collection to delete. + * @param customHeaders * @returns Deleted response */ - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/collections/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description get a collection * @param id id of the collection to retrieve. + * @param customHeaders * @returns the collection with the given id */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/collections/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Lists collections matching a query * @param query Query for searching collections + * @param customHeaders * @returns a list of collections matching the query. */ list( - query?: AdminGetCollectionsParams + query?: AdminGetCollectionsParams, + customHeaders: Record = {} ): ResponsePromise { let path = `/admin/collections` @@ -72,7 +80,7 @@ class AdminCollectionsResource extends BaseResource { path = `/admin/collections?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/customers.ts b/packages/medusa-js/src/resources/admin/customers.ts index b5e63ee732..6607d3f373 100644 --- a/packages/medusa-js/src/resources/admin/customers.ts +++ b/packages/medusa-js/src/resources/admin/customers.ts @@ -13,40 +13,46 @@ class AdminCustomersResource extends BaseResource { /** * Creates a customer * @param payload information of customer + * @param customHeaders */ - create(payload: AdminPostCustomersReq): ResponsePromise { + create(payload: AdminPostCustomersReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/customers` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Updates a customer * @param id customer id * @param payload data to update customer with + * @param customHeaders */ update( id: string, - payload: AdminPostCustomersCustomerReq + payload: AdminPostCustomersCustomerReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/customers/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Retrieves a customer * @param id customer id + * @param customHeaders */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/customers/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * Lists customers * @param query optional + * @param customHeaders */ list( - query?: AdminGetCustomersParams + query?: AdminGetCustomersParams, + customHeaders: Record = {} ): ResponsePromise { let path = `/admin/customers` @@ -55,7 +61,7 @@ class AdminCustomersResource extends BaseResource { path = `/admin/customers?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/discounts.ts b/packages/medusa-js/src/resources/admin/discounts.ts index 25c75b385f..bbcfd66e90 100644 --- a/packages/medusa-js/src/resources/admin/discounts.ts +++ b/packages/medusa-js/src/resources/admin/discounts.ts @@ -15,9 +15,9 @@ class AdminDiscountsResource extends BaseResource { /** * @description Adds region to discount */ - addRegion(id: string, regionId: string): ResponsePromise { + addRegion(id: string, regionId: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}/regions/${regionId}` - return this.client.request("POST", path, {}) + return this.client.request("POST", path, {}, {}, customHeaders) } /** @@ -25,8 +25,8 @@ class AdminDiscountsResource extends BaseResource { */ addValidProduct( id: string, - productId: string - ): ResponsePromise { + productId: string, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}/products/${productId}` return this.client.request("POST", path, {}) } @@ -34,9 +34,9 @@ class AdminDiscountsResource extends BaseResource { /** * @description Creates discounts */ - create(payload: AdminPostDiscountsReq): ResponsePromise { + create(payload: AdminPostDiscountsReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -44,10 +44,10 @@ class AdminDiscountsResource extends BaseResource { */ update( id: string, - payload: AdminPostDiscountsDiscountReq - ): ResponsePromise { + payload: AdminPostDiscountsDiscountReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -55,18 +55,18 @@ class AdminDiscountsResource extends BaseResource { */ createDynamicCode( id: string, - payload: AdminPostDiscountsDiscountDynamicCodesReq - ): ResponsePromise { + payload: AdminPostDiscountsDiscountDynamicCodesReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}/dynamic-codes` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description Deletes a discount */ - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** @@ -74,34 +74,34 @@ class AdminDiscountsResource extends BaseResource { */ deleteDynamicCode( id: string, - code: string - ): ResponsePromise { + code: string, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}/dynamic-codes/${code}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description Retrieves a discount */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Retrieves a discount by code */ - retrieveByCode(code: string): ResponsePromise { + retrieveByCode(code: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/code/${code}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Lists discounts */ list( - query?: AdminGetDiscountsParams - ): ResponsePromise { + query?: AdminGetDiscountsParams, + customHeaders: Record = {}): ResponsePromise { let path = `/admin/discounts` if (query) { @@ -109,7 +109,7 @@ class AdminDiscountsResource extends BaseResource { path = `/admin/discounts?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** @@ -117,10 +117,10 @@ class AdminDiscountsResource extends BaseResource { */ removeRegion( id: string, - regionId: string - ): ResponsePromise { + regionId: string, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}/regions/${regionId}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** @@ -128,10 +128,10 @@ class AdminDiscountsResource extends BaseResource { */ removeValidProduct( id: string, - productId: string - ): ResponsePromise { + productId: string, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/discounts/${id}/products/${productId}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/draft-orders.ts b/packages/medusa-js/src/resources/admin/draft-orders.ts index 6c37558c03..f36b078829 100644 --- a/packages/medusa-js/src/resources/admin/draft-orders.ts +++ b/packages/medusa-js/src/resources/admin/draft-orders.ts @@ -17,10 +17,10 @@ class AdminDraftOrdersResource extends BaseResource { * @description Creates a draft order */ create( - payload: AdminPostDraftOrdersDraftOrderReq - ): ResponsePromise { + payload: AdminPostDraftOrdersDraftOrderReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/draft-orders` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -28,18 +28,18 @@ class AdminDraftOrdersResource extends BaseResource { */ addLineItem( id: string, - payload: AdminPostDraftOrdersDraftOrderLineItemsReq - ): ResponsePromise { + payload: AdminPostDraftOrdersDraftOrderLineItemsReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/draft-orders/${id}/line-items` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description Delete draft order */ - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/draft-orders/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** @@ -47,26 +47,26 @@ class AdminDraftOrdersResource extends BaseResource { */ removeLineItem( id: string, - itemId: string - ): ResponsePromise { + itemId: string, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/draft-orders/${id}/line-items/${itemId}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description Retrieves a draft order */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/draft-orders/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Lists draft orders */ list( - query?: AdminGetDraftOrdersParams - ): ResponsePromise { + query?: AdminGetDraftOrdersParams, + customHeaders: Record = {}): ResponsePromise { let path = `/admin/draft-orders` if (query) { @@ -74,14 +74,15 @@ class AdminDraftOrdersResource extends BaseResource { path = `/admin/draft-orders?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Mark a draft order as paid */ markPaid( - id: string + id: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/draft-orders/${id}/pay` return this.client.request("POST", path, {}) @@ -92,10 +93,10 @@ class AdminDraftOrdersResource extends BaseResource { */ update( id: string, - payload: AdminPostDraftOrdersDraftOrderReq - ): ResponsePromise { + payload: AdminPostDraftOrdersDraftOrderReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/draft-orders/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -104,10 +105,10 @@ class AdminDraftOrdersResource extends BaseResource { updateLineItem( id: string, itemId: string, - payload: AdminPostDraftOrdersDraftOrderLineItemsItemReq - ): ResponsePromise { + payload: AdminPostDraftOrdersDraftOrderLineItemsItemReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/draft-orders/${id}/line-items/${itemId}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/gift-cards.ts b/packages/medusa-js/src/resources/admin/gift-cards.ts index a0db39b939..42a0b13450 100644 --- a/packages/medusa-js/src/resources/admin/gift-cards.ts +++ b/packages/medusa-js/src/resources/admin/gift-cards.ts @@ -14,9 +14,9 @@ class AdminGiftCardsResource extends BaseResource { /** * @description Creates a gift card */ - create(payload: AdminPostGiftCardsReq): ResponsePromise { + create(payload: AdminPostGiftCardsReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/gift-cards` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -24,34 +24,34 @@ class AdminGiftCardsResource extends BaseResource { */ update( id: string, - payload: AdminPostGiftCardsGiftCardReq - ): ResponsePromise { + payload: AdminPostGiftCardsGiftCardReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/gift-cards/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description Deletes a gift card */ - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/gift-cards/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description Deletes a gift card */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/gift-cards/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Lists gift cards */ list( - query?: AdminGetGiftCardsParams - ): ResponsePromise { + query?: AdminGetGiftCardsParams, + customHeaders: Record = {}): ResponsePromise { let path = `/admin/gift-cards/` if (query) { @@ -59,7 +59,7 @@ class AdminGiftCardsResource extends BaseResource { path = `/admin/gift-cards?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/invites.ts b/packages/medusa-js/src/resources/admin/invites.ts index ceee73191a..834190dbcd 100644 --- a/packages/medusa-js/src/resources/admin/invites.ts +++ b/packages/medusa-js/src/resources/admin/invites.ts @@ -7,29 +7,29 @@ import { AdminPostInvitesPayload, ResponsePromise } from "../.." import BaseResource from "../base" class AdminInvitesResource extends BaseResource { - accept(payload: AdminPostInvitesInviteAcceptReq): ResponsePromise { + accept(payload: AdminPostInvitesInviteAcceptReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/invites/accept` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - create(payload: AdminPostInvitesPayload): ResponsePromise { + create(payload: AdminPostInvitesPayload, customHeaders: Record = {}): ResponsePromise { const path = `/admin/invites` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/invites/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } - list(): ResponsePromise { + list(customHeaders: Record = {}): ResponsePromise { const path = `/admin/invites` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } - resend(id: string): ResponsePromise { + resend(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/invites/${id}` - return this.client.request("POST", path, {}) + return this.client.request("POST", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/notes.ts b/packages/medusa-js/src/resources/admin/notes.ts index b1c5f4243a..d991ecda44 100644 --- a/packages/medusa-js/src/resources/admin/notes.ts +++ b/packages/medusa-js/src/resources/admin/notes.ts @@ -11,30 +11,30 @@ import { ResponsePromise } from "../../typings" import BaseResource from "../base" class AdminNotesResource extends BaseResource { - create(payload: AdminPostNotesReq): ResponsePromise { + create(payload: AdminPostNotesReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/notes` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } update( id: string, - payload: AdminPostNotesNoteReq - ): ResponsePromise { + payload: AdminPostNotesNoteReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/notes/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/notes/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/notes/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } - list(query?: AdminGetNotesParams): ResponsePromise { + list(query?: AdminGetNotesParams, customHeaders: Record = {}): ResponsePromise { let path = `/admin/notes/` if (query) { @@ -42,7 +42,7 @@ class AdminNotesResource extends BaseResource { path = `/admin/notes?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/notifications.ts b/packages/medusa-js/src/resources/admin/notifications.ts index 481d69e411..2b2b6d56a6 100644 --- a/packages/medusa-js/src/resources/admin/notifications.ts +++ b/packages/medusa-js/src/resources/admin/notifications.ts @@ -10,8 +10,8 @@ import BaseResource from "../base" class AdminNotificationsResource extends BaseResource { list( - query?: AdminGetNotificationsParams - ): ResponsePromise { + query?: AdminGetNotificationsParams, + customHeaders: Record = {}): ResponsePromise { let path = `/admin/notifications` if (query) { @@ -19,15 +19,15 @@ class AdminNotificationsResource extends BaseResource { path = `/admin/notifications?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } resend( id: string, - payload: AdminPostNotificationsNotificationResendReq - ): ResponsePromise { + payload: AdminPostNotificationsNotificationResendReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/notifications/${id}/resend` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/orders.ts b/packages/medusa-js/src/resources/admin/orders.ts index 0df0cc86ba..660cf455ee 100644 --- a/packages/medusa-js/src/resources/admin/orders.ts +++ b/packages/medusa-js/src/resources/admin/orders.ts @@ -22,25 +22,25 @@ import { ResponsePromise } from "../../typings" import BaseResource from "../base" class AdminOrdersResource extends BaseResource { - create(payload: AdminPostOrdersReq): ResponsePromise { + create(payload: AdminPostOrdersReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } update( id: string, - payload: AdminPostOrdersOrderReq - ): ResponsePromise { + payload: AdminPostOrdersOrderReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } - list(query?: AdminGetOrdersParams): ResponsePromise { + list(query?: AdminGetOrdersParams, customHeaders: Record = {}): ResponsePromise { let path = `/admin/orders` if (query) { @@ -48,177 +48,191 @@ class AdminOrdersResource extends BaseResource { path = `/admin/orders?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } - complete(id: string): ResponsePromise { + complete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/complete` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } - capturePayment(id: string): ResponsePromise { + capturePayment(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/capture` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } refundPayment( id: string, - payload: AdminPostOrdersOrderRefundsReq - ): ResponsePromise { + payload: AdminPostOrdersOrderRefundsReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/refund` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } createFulfillment( id: string, - payload: AdminPostOrdersOrderFulfillmentsReq - ): ResponsePromise { + payload: AdminPostOrdersOrderFulfillmentsReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/fulfillment` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } cancelFulfillment( id: string, - fulfillmentId: string + fulfillmentId: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/fulfillments/${fulfillmentId}/cancel` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } cancelSwapFulfillment( id: string, swapId: string, - fulfillmentId: string + fulfillmentId: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/swaps/${swapId}/fulfillments/${fulfillmentId}/cancel` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } cancelClaimFulfillment( id: string, claimId: string, - fulfillmentId: string + fulfillmentId: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/claims/${claimId}/fulfillments/${fulfillmentId}/cancel` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } createShipment( id: string, - payload: AdminPostOrdersOrderShipmentReq + payload: AdminPostOrdersOrderShipmentReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/shipment` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } requestReturn( id: string, - payload: AdminPostOrdersOrderReturnsReq + payload: AdminPostOrdersOrderReturnsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/return` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - cancel(id: string): ResponsePromise { + cancel(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/cancel` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } addShippingMethod( id: string, - payload: AdminPostOrdersOrderShippingMethodsReq + payload: AdminPostOrdersOrderShippingMethodsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/shipping-methods` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - archive(id: string): ResponsePromise { + archive(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/archive` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } createSwap( id: string, - payload: AdminPostOrdersOrderSwapsReq + payload: AdminPostOrdersOrderSwapsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/swaps` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - cancelSwap(id: string, swapId: string): ResponsePromise { + cancelSwap(id: string, swapId: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/swaps/${swapId}/cancel` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } fulfillSwap( id: string, swapId: string, - payload: AdminPostOrdersOrderSwapsSwapFulfillmentsReq + payload: AdminPostOrdersOrderSwapsSwapFulfillmentsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/swaps/${swapId}/fulfillments` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } createSwapShipment( id: string, swapId: string, - payload: AdminPostOrdersOrderSwapsSwapShipmentsReq + payload: AdminPostOrdersOrderSwapsSwapShipmentsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/swaps/${swapId}/shipments` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } processSwapPayment( id: string, - swapId: string + swapId: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/swaps/${swapId}/process-payment` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } createClaim( id: string, - payload: AdminPostOrdersOrderClaimsReq + payload: AdminPostOrdersOrderClaimsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/claims` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - cancelClaim(id: string, claimId: string): ResponsePromise { + cancelClaim(id: string, claimId: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/claims/${claimId}/cancel` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } updateClaim( id: string, claimId: string, - payload: AdminPostOrdersOrderClaimsClaimReq + payload: AdminPostOrdersOrderClaimsClaimReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/claims/${claimId}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } fulfillClaim( id: string, claimId: string, - payload: AdminPostOrdersOrderClaimsClaimFulfillmentsReq + payload: AdminPostOrdersOrderClaimsClaimFulfillmentsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/claims/${claimId}/fulfillments` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } createClaimShipment( id: string, claimId: string, - payload: AdminPostOrdersOrderClaimsClaimShipmentsReq + payload: AdminPostOrdersOrderClaimsClaimShipmentsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/orders/${id}/claims/${claimId}/shipments` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - deleteMetadata(id: string, key: string): ResponsePromise { + deleteMetadata(id: string, key: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/orders/${id}/metadata/${key}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/products.ts b/packages/medusa-js/src/resources/admin/products.ts index 2864cd1fa7..9f767284ab 100644 --- a/packages/medusa-js/src/resources/admin/products.ts +++ b/packages/medusa-js/src/resources/admin/products.ts @@ -20,30 +20,30 @@ import { ResponsePromise } from "../../typings" import BaseResource from "../base" class AdminProductsResource extends BaseResource { - create(payload: AdminPostProductsReq): ResponsePromise { + create(payload: AdminPostProductsReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/products/` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/products/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } update( id: string, - payload: AdminPostProductsProductReq - ): ResponsePromise { + payload: AdminPostProductsProductReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/products/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/products/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } - list(query?: AdminGetProductsParams): ResponsePromise { + list(query?: AdminGetProductsParams, customHeaders: Record = {}): ResponsePromise { let path = `/admin/products` if (query) { @@ -51,75 +51,82 @@ class AdminProductsResource extends BaseResource { path = `/admin/products?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } - listTypes(): ResponsePromise { + listTypes(customHeaders: Record = {}): ResponsePromise { const path = `/admin/products/types` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } - listTags(): ResponsePromise { + listTags(customHeaders: Record = {}): ResponsePromise { const path = `/admin/products/tag-usage` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } setMetadata( id: string, - payload: AdminPostProductsProductMetadataReq + payload: AdminPostProductsProductMetadataReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/products/${id}/metadata` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } createVariant( id: string, - payload: AdminPostProductsProductVariantsReq + payload: AdminPostProductsProductVariantsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/products/${id}/variants` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } updateVariant( id: string, variantId: string, - payload: AdminPostProductsProductVariantsVariantReq + payload: AdminPostProductsProductVariantsVariantReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/products/${id}/variants/${variantId}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } deleteVariant( id: string, - variantId: string + variantId: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/products/${id}/variants/${variantId}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } addOption( id: string, - payload: AdminPostProductsProductOptionsReq + payload: AdminPostProductsProductOptionsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/products/${id}/options` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } updateOption( id: string, optionId: string, - payload: AdminPostProductsProductOptionsOption + payload: AdminPostProductsProductOptionsOption, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/products/${id}/options/${optionId}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } deleteOption( id: string, - optionId: string + optionId: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/products/${id}/options/${optionId}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/regions.ts b/packages/medusa-js/src/resources/admin/regions.ts index 446277b76b..73d8882138 100644 --- a/packages/medusa-js/src/resources/admin/regions.ts +++ b/packages/medusa-js/src/resources/admin/regions.ts @@ -19,53 +19,59 @@ class AdminRegionsResource extends BaseResource { /** * @description creates a region. * @param payload + * @param customHeaders * @returns created region. */ - create(payload: AdminPostRegionsReq): ResponsePromise { + create(payload: AdminPostRegionsReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/regions` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description updates a region * @param id id of the region to update. * @param payload update to apply to region. + * @param customHeaders * @returns the updated region. */ update( id: string, - payload: AdminPostRegionsRegionReq + payload: AdminPostRegionsRegionReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description deletes a region * @param id id of region to delete. + * @param customHeaders * @returns Deleted response */ - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/regions/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description get a region * @param id id of the region to retrieve. + * @param customHeaders * @returns the region with the given id */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/regions/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description lists regions matching a query * @param query query for searching regions + * @param customHeaders * @returns a list of regions matching the query. */ - list(query?: AdminGetRegionsParams): ResponsePromise { + list(query?: AdminGetRegionsParams, customHeaders: Record = {}): ResponsePromise { let path = `/admin/regions` if (query) { @@ -73,128 +79,145 @@ class AdminRegionsResource extends BaseResource { path = `/admin/regions?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description adds metadata to a region * @param id region id * @param payload metadata + * @param customHeaders * @returns updated region */ setMetadata( id: string, - payload: AdminPostRegionsRegionMetadata + payload: AdminPostRegionsRegionMetadata, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}/metadata` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description delete a region's metadata key value pair * @param id region id * @param key metadata key + * @param customHeaders * @returns updated region */ - deleteMetadata(id: string, key: string): ResponsePromise { + deleteMetadata(id: string, key: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/regions/${id}/metadata/${key}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description adds a country to the list of countries in a region * @param id region id * @param payload country data + * @param customHeaders * @returns updated region */ addCountry( id: string, - payload: AdminPostRegionsRegionCountriesReq + payload: AdminPostRegionsRegionCountriesReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}/countries` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description remove a country from a region's list of coutnries * @param id region id * @param country_code the 2 character ISO code for the Country. + * @param customHeaders * @returns updated region */ deleteCountry( id: string, - country_code: string + country_code: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}/countries/${country_code}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description adds a fulfillment provider to a region * @param id region id * @param payload fulfillment provider data + * @param customHeaders * @returns updated region */ addFulfillmentProvider( id: string, - payload: AdminPostRegionsRegionFulfillmentProvidersReq + payload: AdminPostRegionsRegionFulfillmentProvidersReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}/fulfillment-providers` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description remove a fulfillment provider from a region * @param id region id * @param provider_id the if of the fulfillment provider + * @param customHeaders * @returns updated region */ deleteFulfillmentProvider( id: string, - provider_id: string + provider_id: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}/fulfillment-providers/${provider_id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description retrieves the list of fulfillment options available in a region * @param id region id + * @param customHeaders * @returns list of fulfillment options */ retrieveFulfillmentOptions( - id: string + id: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}/fulfillment-options` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description adds a payment provider to a region * @param id region id * @param payload payment provider data + * @param customHeaders * @returns updated region */ addPaymentProvider( id: string, - payload: AdminPostRegionsRegionPaymentProvidersReq + payload: AdminPostRegionsRegionPaymentProvidersReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}/payment-providers` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description removes a payment provider from a region * @param id region id * @param provider_id the id of the payment provider + * @param customHeaders * @returns updated region */ deletePaymentProvider( id: string, - provider_id: string + provider_id: string, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/regions/${id}/payment-providers/${provider_id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/return-reasons.ts b/packages/medusa-js/src/resources/admin/return-reasons.ts index 15155cabe6..83f4a42313 100644 --- a/packages/medusa-js/src/resources/admin/return-reasons.ts +++ b/packages/medusa-js/src/resources/admin/return-reasons.ts @@ -12,58 +12,64 @@ class AdminReturnReasonsResource extends BaseResource { /** * @description Creates a return reason. * @param payload + * @param customHeaders * @returns Created return reason. */ create( - payload: AdminPostReturnReasonsReq + payload: AdminPostReturnReasonsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/return-reasons` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description Updates a return reason * @param id id of the return reason to update. * @param payload update to apply to return reason. + * @param customHeaders * @returns the updated return reason. */ update( id: string, - payload: AdminPostReturnReasonsReasonReq + payload: AdminPostReturnReasonsReasonReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/return-reasons/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description deletes a return reason * @param id id of return reason to delete. + * @param customHeaders * @returns Deleted response */ - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/return-reasons/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description retrieves a return reason * @param id id of the return reason to retrieve. + * @param customHeaders * @returns the return reason with the given id */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/return-reasons/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Lists return reasons matching a query - * @param query Query for searching return reasons * @returns a list of return reasons matching the query. + * @param customHeaders */ - list(): ResponsePromise { + list(customHeaders: Record = {}): ResponsePromise { const path = `/admin/return-reasons` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/returns.ts b/packages/medusa-js/src/resources/admin/returns.ts index 48c66e91b4..b61a826c6d 100644 --- a/packages/medusa-js/src/resources/admin/returns.ts +++ b/packages/medusa-js/src/resources/admin/returns.ts @@ -13,33 +13,37 @@ class AdminReturnsResource extends BaseResource { /** * @description cancels a return * @param id id of return to cancel + * @param customHeaders * @returns the order for which the return was canceled */ - cancel(id: string): ResponsePromise { + cancel(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/returns/${id}/cancel` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } /** * @description receive a return * @param id id of the return to receive. * @param payload items to receive and an optional refund amount + * @param customHeaders * @returns the return */ receive( id: string, - payload: AdminPostReturnsReturnReceiveReq + payload: AdminPostReturnsReturnReceiveReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/returns/${id}/receive` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description lists returns matching a query * @param query query for searching returns + * @param customHeaders * @returns a list of returns matching the query */ - list(query?: AdminGetReturnsParams): ResponsePromise { + list(query?: AdminGetReturnsParams, customHeaders: Record = {}): ResponsePromise { let path = `/admin/returns/` if (query) { @@ -47,7 +51,7 @@ class AdminReturnsResource extends BaseResource { path = `/admin/returns?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/shipping-options.ts b/packages/medusa-js/src/resources/admin/shipping-options.ts index 444fcf0cbf..a2e9d080d9 100644 --- a/packages/medusa-js/src/resources/admin/shipping-options.ts +++ b/packages/medusa-js/src/resources/admin/shipping-options.ts @@ -14,56 +14,64 @@ class AdminShippingOptionsResource extends BaseResource { /** * @description creates a shipping option. * @param payload + * @param customHeaders * @returns created shipping option. */ create( - payload: AdminPostShippingOptionsReq + payload: AdminPostShippingOptionsReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/shipping-options` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description updates a shipping option * @param id id of the shipping option to update. * @param payload update to apply to shipping option. + * @param customHeaders * @returns the updated shipping option. */ update( id: string, - payload: AdminPostShippingOptionsOptionReq + payload: AdminPostShippingOptionsOptionReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/shipping-options/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description deletes a shipping option * @param id id of shipping option to delete. + * @param customHeaders * @returns deleted response */ - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/shipping-options/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description get a shipping option * @param id id of the shipping option to retrieve. + * @param customHeaders * @returns the shipping option with the given id */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/shipping-options/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description lists shipping options matching a query * @param query query for searching shipping options + * @param customHeaders * @returns a list of shipping options matching the query. */ list( - query?: AdminGetShippingOptionsParams + query?: AdminGetShippingOptionsParams, + customHeaders: Record = {} ): ResponsePromise { let path = `/admin/shipping-options` @@ -72,7 +80,7 @@ class AdminShippingOptionsResource extends BaseResource { path = `/admin/shipping-options?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/shipping-profiles.ts b/packages/medusa-js/src/resources/admin/shipping-profiles.ts index 13d1c6c75d..348d33d388 100644 --- a/packages/medusa-js/src/resources/admin/shipping-profiles.ts +++ b/packages/medusa-js/src/resources/admin/shipping-profiles.ts @@ -10,33 +10,33 @@ import BaseResource from "../base" class AdminShippingProfilesResource extends BaseResource { create( - payload: AdminPostShippingProfilesReq - ): ResponsePromise { + payload: AdminPostShippingProfilesReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/shipping-profiles/` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } update( id: string, - payload: AdminPostShippingProfilesProfileReq - ): ResponsePromise { + payload: AdminPostShippingProfilesProfileReq, + customHeaders: Record = {}): ResponsePromise { const path = `/admin/shipping-profiles/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/shipping-profiles/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/shipping-profiles/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } - list(): ResponsePromise { + list(customHeaders: Record = {}): ResponsePromise { const path = `/admin/shipping-profiles/` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/store.ts b/packages/medusa-js/src/resources/admin/store.ts index 98642309f8..b5f37cb52e 100644 --- a/packages/medusa-js/src/resources/admin/store.ts +++ b/packages/medusa-js/src/resources/admin/store.ts @@ -10,49 +10,52 @@ class AdminStoresResource extends BaseResource { /** * @description Updates the store * @param payload update to apply to the store. + * @param customHeaders * @returns the updated store. */ - update(payload: AdminPostStoreReq): ResponsePromise { + update(payload: AdminPostStoreReq, customHeaders: Record = {}): ResponsePromise { const path = `/admin/store/` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description adds a currency to the store. * @param currency_code code of the currency to add + * @param customHeaders * @returns updated store. */ - addCurrency(currency_code: string): ResponsePromise { + addCurrency(currency_code: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/store/${currency_code}` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } /** * @description deletes a currency from the available store currencies * @param currency_code currency code of the currency to delete from the store. + * @param customHeaders * @returns updated store */ - deleteCurrency(currency_code: string): ResponsePromise { + deleteCurrency(currency_code: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/store/currencies/${currency_code}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description gets a medusa store * @returns a medusa store */ - retrieve(): ResponsePromise { + retrieve(customHeaders: Record = {}): ResponsePromise { const path = `/admin/store/` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Lists the store's payment providers * @returns a list of payment providers configured on the store */ - listPaymentProviders(): ResponsePromise { + listPaymentProviders(customHeaders: Record = {}): ResponsePromise { const path = `/admin/store/payment-providers` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/swaps.ts b/packages/medusa-js/src/resources/admin/swaps.ts index ab5e75ec33..689c4a356e 100644 --- a/packages/medusa-js/src/resources/admin/swaps.ts +++ b/packages/medusa-js/src/resources/admin/swaps.ts @@ -8,12 +8,12 @@ import { ResponsePromise } from "../../typings" import BaseResource from "../base" class AdminSwapsResource extends BaseResource { - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/swaps/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } - list(query?: AdminGetSwapsParams): ResponsePromise { + list(query?: AdminGetSwapsParams, customHeaders: Record = {}): ResponsePromise { let path = `/admin/swaps/` if (query) { @@ -21,7 +21,7 @@ class AdminSwapsResource extends BaseResource { path = `/admin/swaps?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/users.ts b/packages/medusa-js/src/resources/admin/users.ts index 07a5b78dbd..062a93355e 100644 --- a/packages/medusa-js/src/resources/admin/users.ts +++ b/packages/medusa-js/src/resources/admin/users.ts @@ -16,78 +16,87 @@ class AdminUsersResource extends BaseResource { /** * @description resets password by re-sending password token. * @param payload payload for generating reset-password token. + * @param customHeaders * @returns */ sendResetPasswordToken( - payload: AdminResetPasswordTokenRequest + payload: AdminResetPasswordTokenRequest, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/users/password-token` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description resets the users password given the correct token. * @param payload reset password information. + * @param customHeaders * @returns */ resetPassword( - payload: AdminResetPasswordRequest + payload: AdminResetPasswordRequest, + customHeaders: Record = {} ): ResponsePromise { const path = `admin/users/reset-password` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Retrieves a given user * @param id id of the user + * @param customHeaders * @returns the user */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/users/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description creates a user with the provided information * @param payload user creation request body + * @param customHeaders * @returns created user */ - create(payload: AdminCreateUserPayload): ResponsePromise { + create(payload: AdminCreateUserPayload, customHeaders: Record = {}): ResponsePromise { const path = `/admin/users` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description updates a given user * @param id id of the user to update * @param payload user update request body + * @param customHeaders * @returns the updated user */ update( id: string, - payload: AdminUpdateUserPayload + payload: AdminUpdateUserPayload, + customHeaders: Record = {} ): ResponsePromise { const path = `/admin/users/${id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description deletes a user * @param id id of the user to be deleted + * @param customHeaders * @returns delete response */ - delete(id: string): ResponsePromise { + delete(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/admin/users/${id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * @description lists all users * @returns a list of all users */ - list(): ResponsePromise { + list(customHeaders: Record = {}): ResponsePromise { const path = `/admin/users` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/admin/variants.ts b/packages/medusa-js/src/resources/admin/variants.ts index 62a9d2f4e4..5a19e5c7e8 100644 --- a/packages/medusa-js/src/resources/admin/variants.ts +++ b/packages/medusa-js/src/resources/admin/variants.ts @@ -4,7 +4,7 @@ import { ResponsePromise } from "../.." import BaseResource from "../base" class AdminVariantsResource extends BaseResource { - list(query?: AdminGetVariantsParams): ResponsePromise { + list(query?: AdminGetVariantsParams, customHeaders: Record = {}): ResponsePromise { let path = `/admin/variants` if (query) { @@ -12,7 +12,7 @@ class AdminVariantsResource extends BaseResource { path = `/admin/variants?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/auth.ts b/packages/medusa-js/src/resources/auth.ts index 37df601d65..6dfa507304 100644 --- a/packages/medusa-js/src/resources/auth.ts +++ b/packages/medusa-js/src/resources/auth.ts @@ -10,31 +10,34 @@ class AuthResource extends BaseResource { /** * @description Authenticates a customer using email and password combination * @param {StorePostAuthReq} payload authentication payload + * @param customHeaders * @return {ResponsePromise} */ - authenticate(payload: StorePostAuthReq): ResponsePromise { + authenticate(payload: StorePostAuthReq, customHeaders: Record = {}): ResponsePromise { const path = `/store/auth` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description Retrieves an authenticated session * Usually used to check if authenticated session is alive. + * @param customHeaders * @return {ResponsePromise} */ - getSession(): ResponsePromise { + getSession(customHeaders: Record = {}): ResponsePromise { const path = `/store/auth` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Check if email exists * @param {string} email is required + * @param customHeaders * @return {ResponsePromise} */ - exists(email: string): ResponsePromise { + exists(email: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/auth/${email}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/carts.ts b/packages/medusa-js/src/resources/carts.ts index 977633ea8f..8f6a26fd04 100644 --- a/packages/medusa-js/src/resources/carts.ts +++ b/packages/medusa-js/src/resources/carts.ts @@ -18,14 +18,15 @@ class CartsResource extends BaseResource { * Adds a shipping method to cart * @param {string} cart_id Id of cart * @param {StorePostCartsCartShippingMethodReq} payload Containg id of shipping option and optional data + * @param customHeaders * @return {ResponsePromise} */ addShippingMethod( cart_id: string, - payload: StorePostCartsCartShippingMethodReq - ): ResponsePromise { + payload: StorePostCartsCartShippingMethodReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/shipping-methods` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -35,22 +36,24 @@ class CartsResource extends BaseResource { * The completion of a cart can be performed idempotently with a provided header Idempotency-Key. * If not provuided, we will generate one for the request. * @param {string} cart_id is required + * @param customHeaders * @return {ResponsePromise} */ - complete(cart_id: string): ResponsePromise { + complete(cart_id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/complete` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } /** * Creates a cart * @param {StorePostCartReq} payload is optional and can contain a region_id and items. * The cart will contain the payload, if provided. Otherwise it will be empty + * @param customHeaders * @return {ResponsePromise} */ - create(payload?: StorePostCartReq): ResponsePromise { + create(payload?: StorePostCartReq, customHeaders: Record = {}): ResponsePromise { const path = `/store/carts` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -58,25 +61,27 @@ class CartsResource extends BaseResource { * Initializes the payment sessions that can be used to pay for the items of the cart. * This is usually called when a customer proceeds to checkout. * @param {string} cart_id is required + * @param customHeaders * @return {ResponsePromise} */ - createPaymentSessions(cart_id: string): ResponsePromise { + createPaymentSessions(cart_id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/payment-sessions` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } /** * Removes a discount from cart. * @param {string} cart_id is required * @param {string} code discount code to remove + * @param customHeaders * @return {ResponsePromise} */ deleteDiscount( cart_id: string, - code: string - ): ResponsePromise { + code: string, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/discounts/${code}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** @@ -84,66 +89,71 @@ class CartsResource extends BaseResource { * Can be useful in case a payment has failed * @param {string} cart_id is required * @param {string} provider_id the provider id of the session e.g. "stripe" + * @param customHeaders * @return {ResponsePromise} */ deletePaymentSession( cart_id: string, - provider_id: string - ): ResponsePromise { + provider_id: string, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } /** * Refreshes a payment session. * @param {string} cart_id is required * @param {string} provider_id the provider id of the session e.g. "stripe" + * @param customHeaders * @return {ResponsePromise} */ refreshPaymentSession( cart_id: string, - provider_id: string - ): ResponsePromise { + provider_id: string, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}/refresh` - return this.client.request("POST", path) + return this.client.request("POST", path, {}, {}, customHeaders) } /** * Retrieves a cart * @param {string} cart_id is required + * @param customHeaders * @return {ResponsePromise} */ - retrieve(cart_id: string): ResponsePromise { + retrieve(cart_id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * Refreshes a payment session. * @param {string} cart_id is required * @param {StorePostCartsCartPaymentSessionReq} payload the provider id of the session e.g. "stripe" + * @param customHeaders * @return {ResponsePromise} */ setPaymentSession( cart_id: string, - payload: StorePostCartsCartPaymentSessionReq - ): ResponsePromise { + payload: StorePostCartsCartPaymentSessionReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/payment-session` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Updates a cart * @param {string} cart_id is required * @param {StorePostCartsCartReq} payload is required and can contain region_id, email, billing and shipping address + * @param customHeaders * @return {ResponsePromise} */ update( cart_id: string, - payload: StorePostCartsCartReq - ): ResponsePromise { + payload: StorePostCartsCartReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -151,15 +161,16 @@ class CartsResource extends BaseResource { * @param {string} cart_id is required * @param {string} provider_id is required * @param {StorePostCartsCartPaymentSessionUpdateReq} payload is required + * @param customHeaders * @return {ResponsePromise} */ updatePaymentSession( cart_id: string, provider_id: string, - payload: StorePostCartsCartPaymentSessionUpdateReq - ): ResponsePromise { + payload: StorePostCartsCartPaymentSessionUpdateReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/collections.ts b/packages/medusa-js/src/resources/collections.ts index 6278b05862..6cb8e03a5f 100644 --- a/packages/medusa-js/src/resources/collections.ts +++ b/packages/medusa-js/src/resources/collections.ts @@ -11,21 +11,23 @@ class CollectionsResource extends BaseResource { /** * @description Retrieves a single collection * @param {string} id id of the collection + * @param customHeaders * @return {ResponsePromise} */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/collections/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Retrieves a list of collections * @param {string} query is optional. Can contain a limit and offset for the returned list + * @param customHeaders * @return {ResponsePromise} */ list( - query?: StoreGetCollectionsParams - ): ResponsePromise { + query?: StoreGetCollectionsParams, + customHeaders: Record = {}): ResponsePromise { let path = `/store/collections` if (query) { @@ -33,7 +35,7 @@ class CollectionsResource extends BaseResource { path = `/store/collections?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/customers.ts b/packages/medusa-js/src/resources/customers.ts index 81408f4b2f..47e1a7b268 100644 --- a/packages/medusa-js/src/resources/customers.ts +++ b/packages/medusa-js/src/resources/customers.ts @@ -19,42 +19,46 @@ class CustomerResource extends BaseResource { /** * Creates a customer * @param {StorePostCustomersReq} payload information of customer + * @param customHeaders * @return { ResponsePromise} */ - create(payload: StorePostCustomersReq): ResponsePromise { + create(payload: StorePostCustomersReq, customHeaders: Record = {}): ResponsePromise { const path = `/store/customers` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Retrieves the customer that is currently logged + * @param customHeaders * @return {ResponsePromise} */ - retrieve(): ResponsePromise { + retrieve(customHeaders: Record = {}): ResponsePromise { const path = `/store/customers/me` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * Updates a customer * @param {StorePostCustomersCustomerReq} payload information to update customer with + * @param customHeaders * @return {ResponsePromise} */ update( - payload: StorePostCustomersCustomerReq - ): ResponsePromise { + payload: StorePostCustomersCustomerReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/customers/me` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Retrieve customer orders * @param {StoreGetCustomersCustomerOrdersParams} params optional params to retrieve orders + * @param customHeaders * @return {ResponsePromise} */ listOrders( - params?: StoreGetCustomersCustomerOrdersParams - ): ResponsePromise { + params?: StoreGetCustomersCustomerOrdersParams, + customHeaders: Record = {}): ResponsePromise { let path = `/store/customers/me/orders` if (params) { const query = qs.stringify(params) @@ -62,32 +66,35 @@ class CustomerResource extends BaseResource { path += `?${query}` } } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * Resets customer password * @param {StorePostCustomersCustomerPasswordTokenReq} payload info used to reset customer password + * @param customHeaders * @return {ResponsePromise} */ resetPassword( - payload: StorePostCustomersCustomerPasswordTokenReq - ): ResponsePromise { + payload: StorePostCustomersCustomerPasswordTokenReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/customers/password-reset` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Generates a reset password token, which can be used to reset the password. * The token is not returned but should be sent out to the customer in an email. * @param {StorePostCustomersCustomerPasswordTokenReq} payload info used to generate token + * @param customHeaders * @return {ResponsePromise} */ generatePasswordToken( - payload: StorePostCustomersCustomerPasswordTokenReq + payload: StorePostCustomersCustomerPasswordTokenReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/store/customers/password-token` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/gift-cards.ts b/packages/medusa-js/src/resources/gift-cards.ts index bf6dd9a7ab..0e458b5bef 100644 --- a/packages/medusa-js/src/resources/gift-cards.ts +++ b/packages/medusa-js/src/resources/gift-cards.ts @@ -6,11 +6,12 @@ class GiftCardsResource extends BaseResource { /** * @description Retrieves a single GiftCard * @param {string} code code of the gift card + * @param customHeaders * @return {ResponsePromise} */ - retrieve(code: string): ResponsePromise { + retrieve(code: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/gift-cards/${code}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/line-items.ts b/packages/medusa-js/src/resources/line-items.ts index 4a096fc741..6443301110 100644 --- a/packages/medusa-js/src/resources/line-items.ts +++ b/packages/medusa-js/src/resources/line-items.ts @@ -11,14 +11,15 @@ class LineItemsResource extends BaseResource { * Creates a line-item for a cart * @param {string} cart_id id of cart * @param {StorePostCartsCartLineItemsReq} payload details needed to create a line-item + * @param customHeaders * @return {ResponsePromise} */ create( cart_id: string, - payload: StorePostCartsCartLineItemsReq - ): ResponsePromise { + payload: StorePostCartsCartLineItemsReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/line-items` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** @@ -27,26 +28,28 @@ class LineItemsResource extends BaseResource { * @param {string} cart_id id of cart * @param {string} line_id id of item to update * @param {StorePostCartsCartLineItemsItemReq} payload details needed to update a line-item + * @param customHeaders * @return {ResponsePromise} */ update( cart_id: string, line_id: string, - payload: StorePostCartsCartLineItemsItemReq - ): ResponsePromise { + payload: StorePostCartsCartLineItemsItemReq, + customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/line-items/${line_id}` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * Remove a line-item from a cart * @param {string} cart_id id of cart * @param {string} line_id id of item to remove - * @return {ResponsePromise} + * @param customHeaders + * @return {ResponsePromise} */ - delete(cart_id: string, line_id: string): ResponsePromise { + delete(cart_id: string, line_id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${cart_id}/line-items/${line_id}` - return this.client.request("DELETE", path) + return this.client.request("DELETE", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/orders.ts b/packages/medusa-js/src/resources/orders.ts index ff55e898aa..921646e724 100644 --- a/packages/medusa-js/src/resources/orders.ts +++ b/packages/medusa-js/src/resources/orders.ts @@ -7,35 +7,38 @@ class OrdersResource extends BaseResource { /** * @description Retrieves an order * @param {string} id is required + * @param customHeaders * @return {ResponsePromise} */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/orders/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Retrieves an order by cart id * @param {string} cart_id is required + * @param customHeaders * @return {ResponsePromise} */ - retrieveByCartId(cart_id: string): ResponsePromise { + retrieveByCartId(cart_id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/orders/cart/${cart_id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Look up an order using order details * @param {StoreGetOrdersParams} payload details used to look up the order + * @param customHeaders * @return {ResponsePromise} */ - lookupOrder(payload: StoreGetOrdersParams): ResponsePromise { + lookupOrder(payload: StoreGetOrdersParams, customHeaders: Record = {}): ResponsePromise { let path = `/store/orders?` const queryString = qs.stringify(payload) path = `/store/orders?${queryString}` - return this.client.request("GET", path, payload) + return this.client.request("GET", path, payload, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/payment-methods.ts b/packages/medusa-js/src/resources/payment-methods.ts index d2f2cbaf4b..b367f8ee9f 100644 --- a/packages/medusa-js/src/resources/payment-methods.ts +++ b/packages/medusa-js/src/resources/payment-methods.ts @@ -6,11 +6,12 @@ class PaymentMethodsResource extends BaseResource { /** * Lists customer payment methods * @param {string} id id of cart + * @param customHeaders * @return {StoreCustomersListPaymentMethodsRes} */ - list(id: string): ResponsePromise { + list(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/carts/${id}/payment-methods` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/product-variants.ts b/packages/medusa-js/src/resources/product-variants.ts index 13448d1bbd..39350ebfb8 100644 --- a/packages/medusa-js/src/resources/product-variants.ts +++ b/packages/medusa-js/src/resources/product-variants.ts @@ -11,26 +11,28 @@ class ProductVariantsResource extends BaseResource { /** * @description Retrieves a single product variant * @param {string} id is required + * @param customHeaders * @return {ResponsePromise} */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/variants/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Retrieves a list of of Product Variants - * @param {StoreVariantsListParamsObject} query + * @param {StoreGetVariantsParams} query + * @param customHeaders * @return {ResponsePromise} */ - list(query?: StoreGetVariantsParams): ResponsePromise { + list(query?: StoreGetVariantsParams, customHeaders: Record = {}): ResponsePromise { let path = `/store/variants` if (query) { const queryString = qs.stringify(query) path += `?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, undefined, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/products.ts b/packages/medusa-js/src/resources/products.ts index ac32be9d36..306b4c2247 100644 --- a/packages/medusa-js/src/resources/products.ts +++ b/packages/medusa-js/src/resources/products.ts @@ -16,31 +16,35 @@ class ProductsResource extends BaseResource { /** * @description Retrieves a single Product * @param {string} id is required + * @param customHeaders * @return {ResponsePromise} */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/products/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Searches for products * @param {StorePostSearchReq} searchOptions is required + * @param customHeaders * @return {ResponsePromise} */ search( - searchOptions: StorePostSearchReq + searchOptions: StorePostSearchReq, + customHeaders: Record = {} ): ResponsePromise { const path = `/store/products/search` - return this.client.request("POST", path, searchOptions) + return this.client.request("POST", path, searchOptions, {}, customHeaders) } /** * @description Retrieves a list of products * @param {StoreGetProductsParams} query is optional. Can contain a limit and offset for the returned list + * @param customHeaders * @return {ResponsePromise} */ - list(query?: StoreGetProductsParams): ResponsePromise { + list(query?: StoreGetProductsParams, customHeaders: Record = {}): ResponsePromise { let path = `/store/products` if (query) { @@ -48,7 +52,7 @@ class ProductsResource extends BaseResource { path = `/store/products?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/regions.ts b/packages/medusa-js/src/resources/regions.ts index 551d7881d5..bbf19cefa0 100644 --- a/packages/medusa-js/src/resources/regions.ts +++ b/packages/medusa-js/src/resources/regions.ts @@ -5,21 +5,23 @@ import BaseResource from "./base" class RegionsResource extends BaseResource { /** * @description Retrieves a list of regions + * @param customHeaders * @return {ResponsePromise} */ - list(): ResponsePromise { + list(customHeaders: Record = {}): ResponsePromise { const path = `/store/regions` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Retrieves a region * @param {string} id is required + * @param customHeaders * @return {ResponsePromise} */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/regions/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/return-reasons.ts b/packages/medusa-js/src/resources/return-reasons.ts index a06e14b62d..ff03044205 100644 --- a/packages/medusa-js/src/resources/return-reasons.ts +++ b/packages/medusa-js/src/resources/return-reasons.ts @@ -9,20 +9,22 @@ class ReturnReasonsResource extends BaseResource { /** * @description Retrieves a single Return Reason * @param {string} id is required + * @param customHeaders * @return {ResponsePromise} */ - retrieve(id: string): ResponsePromise { + retrieve(id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/return-reasons/${id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * Lists return reasons defined in Medusa Admin + * @param customHeaders * @return {ResponsePromise} */ - list(): ResponsePromise { + list(customHeaders: Record = {}): ResponsePromise { const path = `/store/return-reasons` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/returns.ts b/packages/medusa-js/src/resources/returns.ts index c3a71c75eb..17b6358191 100644 --- a/packages/medusa-js/src/resources/returns.ts +++ b/packages/medusa-js/src/resources/returns.ts @@ -6,11 +6,12 @@ class ReturnsResource extends BaseResource { /** * Creates a return request * @param {StorePostReturnsReq} payload details needed to create a return + * @param customHeaders * @return {ResponsePromise} */ - create(payload: StorePostReturnsReq): ResponsePromise { + create(payload: StorePostReturnsReq, customHeaders: Record = {}): ResponsePromise { const path = `/store/returns` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/shipping-options.ts b/packages/medusa-js/src/resources/shipping-options.ts index 03f97395a9..74564a82cf 100644 --- a/packages/medusa-js/src/resources/shipping-options.ts +++ b/packages/medusa-js/src/resources/shipping-options.ts @@ -10,23 +10,23 @@ class ShippingOptionsResource extends BaseResource { /** * @description Lists shiping options available for a cart * @param {string} cart_id + * @param customHeaders * @return {ResponsePromise} */ - listCartOptions( - cart_id: string - ): ResponsePromise { + listCartOptions(cart_id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/shipping-options/${cart_id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } /** * @description Lists shiping options available - * @param {StoreGetShippingOptionsParamsObject} query + * @param {StoreGetShippingOptionsParams} query + * @param customHeaders * @return {ResponsePromise} */ list( - query?: StoreGetShippingOptionsParams - ): ResponsePromise { + query?: StoreGetShippingOptionsParams, + customHeaders: Record = {}): ResponsePromise { let path = `/store/shipping-options` if (query) { @@ -34,7 +34,7 @@ class ShippingOptionsResource extends BaseResource { path = `/store/shipping-options?${queryString}` } - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa-js/src/resources/swaps.ts b/packages/medusa-js/src/resources/swaps.ts index dd3803a3e2..266ac9afca 100644 --- a/packages/medusa-js/src/resources/swaps.ts +++ b/packages/medusa-js/src/resources/swaps.ts @@ -6,21 +6,23 @@ class SwapsResource extends BaseResource { /** * @description Creates a swap from a cart * @param {StorePostSwapsReq} payload + * @param customHeaders * @return {ResponsePromise} */ - create(payload: StorePostSwapsReq): ResponsePromise { + create(payload: StorePostSwapsReq, customHeaders: Record = {}): ResponsePromise { const path = `/store/swaps` - return this.client.request("POST", path, payload) + return this.client.request("POST", path, payload, {}, customHeaders) } /** * @description Retrieves a swap by cart id * @param {string} cart_id id of cart + * @param customHeaders * @return {ResponsePromise} */ - retrieveByCartId(cart_id: string): ResponsePromise { + retrieveByCartId(cart_id: string, customHeaders: Record = {}): ResponsePromise { const path = `/store/swaps/${cart_id}` - return this.client.request("GET", path) + return this.client.request("GET", path, {}, {}, customHeaders) } } diff --git a/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts b/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts index 699c916d17..a5bab9b3c4 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/create-draft-order.ts @@ -189,7 +189,7 @@ export class AdminPostDraftOrdersReq { @IsObject() @IsOptional() - metadata?: object = {} + metadata?: Record = {} } class ShippingMethod { @@ -198,7 +198,7 @@ class ShippingMethod { @IsObject() @IsOptional() - data?: object = {} + data?: Record = {} @IsNumber() @IsOptional() @@ -228,5 +228,5 @@ class Item { @IsObject() @IsOptional() - metadata?: object = {} + metadata?: Record = {} } diff --git a/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.ts b/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.ts index e4945cd90c..06ffeff0e7 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/create-line-item.ts @@ -134,5 +134,5 @@ export class AdminPostDraftOrdersDraftOrderLineItemsReq { @IsObject() @IsOptional() - metadata?: object = {} + metadata?: Record = {} } diff --git a/packages/medusa/src/api/routes/admin/draft-orders/update-line-item.ts b/packages/medusa/src/api/routes/admin/draft-orders/update-line-item.ts index 5ff8f9a29e..ff4a66f895 100644 --- a/packages/medusa/src/api/routes/admin/draft-orders/update-line-item.ts +++ b/packages/medusa/src/api/routes/admin/draft-orders/update-line-item.ts @@ -128,5 +128,5 @@ export class AdminPostDraftOrdersDraftOrderLineItemsItemReq { @IsObject() @IsOptional() - metadata?: object = {} + metadata?: Record = {} } diff --git a/packages/medusa/src/api/routes/admin/orders/add-shipping-method.ts b/packages/medusa/src/api/routes/admin/orders/add-shipping-method.ts index 4258962927..47de55b040 100644 --- a/packages/medusa/src/api/routes/admin/orders/add-shipping-method.ts +++ b/packages/medusa/src/api/routes/admin/orders/add-shipping-method.ts @@ -70,5 +70,5 @@ export class AdminPostOrdersOrderShippingMethodsReq { @IsObject() @IsOptional() - data?: object = {} + data?: Record = {} } diff --git a/packages/medusa/src/api/routes/store/carts/add-shipping-method.ts b/packages/medusa/src/api/routes/store/carts/add-shipping-method.ts index ae56e660ed..7a73dd1ab4 100644 --- a/packages/medusa/src/api/routes/store/carts/add-shipping-method.ts +++ b/packages/medusa/src/api/routes/store/carts/add-shipping-method.ts @@ -67,5 +67,5 @@ export class StorePostCartsCartShippingMethodReq { option_id: string @IsOptional() - data?: object = {} + data?: Record = {} } diff --git a/packages/medusa/src/services/cart.ts b/packages/medusa/src/services/cart.ts index 0636b9e9e5..7b7fe1c67d 100644 --- a/packages/medusa/src/services/cart.ts +++ b/packages/medusa/src/services/cart.ts @@ -1215,7 +1215,7 @@ class CartService extends BaseService { * this could be IP address or similar for fraud handling. * @return {Promise} the resulting cart */ - async authorizePayment(cartId: string, context: object = {}): Promise { + async authorizePayment(cartId: string, context: Record = {}): Promise { return this.atomicPhase_(async (manager: EntityManager) => { const cartRepository = manager.getCustomRepository(this.cartRepository_) @@ -1520,7 +1520,7 @@ class CartService extends BaseService { async addShippingMethod( cartId: string, optionId: string, - data: object = {} + data: Record = {} ): Promise { return this.atomicPhase_(async (manager: EntityManager) => { const cart = await this.retrieve(cartId, { diff --git a/packages/medusa/src/services/product-variant.ts b/packages/medusa/src/services/product-variant.ts index 7bb4be7466..3ced10225f 100644 --- a/packages/medusa/src/services/product-variant.ts +++ b/packages/medusa/src/services/product-variant.ts @@ -666,7 +666,7 @@ class ProductVariantService extends BaseService { * @param {Object} metadata - the metadata to set * @return {Object} updated metadata object */ - setMetadata_(variant: ProductVariant, metadata: object): object { + setMetadata_(variant: ProductVariant, metadata: object): Record { const existing = variant.metadata || {} const newData = {} for (const [key, value] of Object.entries(metadata)) {