fix: medusa-js fine-tuning (#836)
This commit is contained in:
@@ -12,6 +12,7 @@ import ReturnReasonsResource from "./resources/return-reasons"
|
||||
import ReturnsResource from "./resources/returns"
|
||||
import ShippingOptionsResource from "./resources/shipping-options"
|
||||
import SwapsResource from "./resources/swaps"
|
||||
import PaymentMethodsResource from "./resources/payment-methods"
|
||||
|
||||
class Medusa {
|
||||
private client: Client
|
||||
@@ -28,6 +29,7 @@ class Medusa {
|
||||
public swaps: SwapsResource
|
||||
public collections: CollectionsResource
|
||||
public giftCards: GiftCardsResource
|
||||
public paymentMethods: PaymentMethodsResource
|
||||
|
||||
constructor(config: Config) {
|
||||
this.client = new Client(config)
|
||||
@@ -45,7 +47,10 @@ class Medusa {
|
||||
this.swaps = new SwapsResource(this.client)
|
||||
this.collections = new CollectionsResource(this.client)
|
||||
this.giftCards = new GiftCardsResource(this.client)
|
||||
this.paymentMethods = new PaymentMethodsResource(this.client)
|
||||
}
|
||||
}
|
||||
|
||||
export default Medusa
|
||||
|
||||
export * from "./typings"
|
||||
|
||||
@@ -151,22 +151,6 @@ class Client {
|
||||
return client
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the response data as:
|
||||
* { cart: { id: "some_cart", ... } }
|
||||
* @param {object} data Axios response data
|
||||
* @param {number} status Axios response status code
|
||||
* @return {object}
|
||||
*/
|
||||
createRawResponse(data: object, status: number): object {
|
||||
const res = { status }
|
||||
Object.entries(data).map(([key, value]) => {
|
||||
res[key] = value
|
||||
})
|
||||
|
||||
return res as any // eslint-disable-line
|
||||
}
|
||||
|
||||
/**
|
||||
* Axios request
|
||||
* @param {Types.RequestMethod} method request method
|
||||
@@ -190,9 +174,11 @@ class Client {
|
||||
headers: this.setHeaders(options, method, path),
|
||||
}
|
||||
|
||||
const { data, status } = await this.axiosClient(reqOpts)
|
||||
// e.g. data = { cart: { ... } }, response = { status, headers, ... }
|
||||
const { data, ...response } = await this.axiosClient(reqOpts)
|
||||
|
||||
return this.createRawResponse(data, status)
|
||||
// e.g. would return an object like of this shape { cart, response }
|
||||
return { ...data, response }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,18 +3,18 @@ import {
|
||||
StorePostCustomersCustomerAddressesAddressReq,
|
||||
StorePostCustomersCustomerAddressesReq,
|
||||
} from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class AddressesResource extends BaseResource {
|
||||
/**
|
||||
* Adds an address to a customers saved addresses
|
||||
* @param {StorePostCustomersCustomerAddressesReq} payload contains information to create an address
|
||||
* @return {AxiosPromise<StoreCustomerResponse>}
|
||||
* @return {ResponsePromise<StoreCustomerResponse>}
|
||||
*/
|
||||
addAddress(
|
||||
payload: StorePostCustomersCustomerAddressesReq
|
||||
): AxiosPromise<StoreCustomersRes> {
|
||||
): ResponsePromise<StoreCustomersRes> {
|
||||
const path = `/store/customers/me/addresses`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -22,9 +22,9 @@ class AddressesResource extends BaseResource {
|
||||
/**
|
||||
* Deletes an address of a customer
|
||||
* @param {string} address_id id of the address to delete
|
||||
* @return {AxiosPromise<StoreCustomersResponse>}
|
||||
* @return {ResponsePromise<StoreCustomersResponse>}
|
||||
*/
|
||||
deleteAddress(address_id: string): AxiosPromise<StoreCustomersRes> {
|
||||
deleteAddress(address_id: string): ResponsePromise<StoreCustomersRes> {
|
||||
const path = `/store/customers/me/addresses/${address_id}`
|
||||
return this.client.request("DELETE", path)
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class AddressesResource extends BaseResource {
|
||||
updateAddress(
|
||||
address_id: string,
|
||||
payload: StorePostCustomersCustomerAddressesAddressReq
|
||||
): AxiosPromise<StoreCustomersRes> {
|
||||
): ResponsePromise<StoreCustomersRes> {
|
||||
const path = `/store/customers/me/addresses/${address_id}`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { AxiosPromise } from "axios"
|
||||
import {
|
||||
StoreGetAuthEmailRes,
|
||||
StorePostAuthReq,
|
||||
StoreAuthRes,
|
||||
} from "@medusajs/medusa"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class AuthResource extends BaseResource {
|
||||
/**
|
||||
* @description Authenticates a customer using email and password combination
|
||||
* @param {StorePostAuthReq} payload authentication payload
|
||||
* @return {AxiosPromise<StoreAuthRes>}
|
||||
* @return {ResponsePromise<StoreAuthRes>}
|
||||
*/
|
||||
authenticate(payload: StorePostAuthReq): AxiosPromise<StoreAuthRes> {
|
||||
authenticate(payload: StorePostAuthReq): ResponsePromise<StoreAuthRes> {
|
||||
const path = `/store/auth`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -20,9 +20,9 @@ class AuthResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves an authenticated session
|
||||
* Usually used to check if authenticated session is alive.
|
||||
* @return {AxiosPromise<StoreAuthRes>}
|
||||
* @return {ResponsePromise<StoreAuthRes>}
|
||||
*/
|
||||
getSession(): AxiosPromise<StoreAuthRes> {
|
||||
getSession(): ResponsePromise<StoreAuthRes> {
|
||||
const path = `/store/auth`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -30,9 +30,9 @@ class AuthResource extends BaseResource {
|
||||
/**
|
||||
* @description Check if email exists
|
||||
* @param {string} email is required
|
||||
* @return {AxiosPromise<StoreGetAuthEmailRes>}
|
||||
* @return {ResponsePromise<StoreGetAuthEmailRes>}
|
||||
*/
|
||||
exists(email: string): AxiosPromise<StoreGetAuthEmailRes> {
|
||||
exists(email: string): ResponsePromise<StoreGetAuthEmailRes> {
|
||||
const path = `/store/auth/${email}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
StorePostCartsCartReq,
|
||||
StorePostCartsCartShippingMethodReq,
|
||||
} from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
import LineItemsResource from "./line-items"
|
||||
|
||||
@@ -17,12 +17,12 @@ 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
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
addShippingMethod(
|
||||
cart_id: string,
|
||||
payload: StorePostCartsCartShippingMethodReq
|
||||
): AxiosPromise<StoreCartsRes> {
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/shipping-methods`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -34,9 +34,9 @@ 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
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
complete(cart_id: string): AxiosPromise<StoreCartsRes> {
|
||||
complete(cart_id: string): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/complete`
|
||||
return this.client.request("POST", path)
|
||||
}
|
||||
@@ -45,9 +45,9 @@ class CartsResource extends BaseResource {
|
||||
* 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
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
create(payload?: StorePostCartReq): AxiosPromise<StoreCartsRes> {
|
||||
create(payload?: StorePostCartReq): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -57,9 +57,9 @@ 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
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
createPaymentSessions(cart_id: string): AxiosPromise<StoreCartsRes> {
|
||||
createPaymentSessions(cart_id: string): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/payment-sessions`
|
||||
return this.client.request("POST", path)
|
||||
}
|
||||
@@ -68,9 +68,12 @@ class CartsResource extends BaseResource {
|
||||
* Removes a discount from cart.
|
||||
* @param {string} cart_id is required
|
||||
* @param {string} code discount code to remove
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
deleteDiscount(cart_id: string, code: string): AxiosPromise<StoreCartsRes> {
|
||||
deleteDiscount(
|
||||
cart_id: string,
|
||||
code: string
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/discounts/${code}`
|
||||
return this.client.request("DELETE", path)
|
||||
}
|
||||
@@ -80,12 +83,12 @@ 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"
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
deletePaymentSession(
|
||||
cart_id: string,
|
||||
provider_id: string
|
||||
): AxiosPromise<StoreCartsRes> {
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}`
|
||||
return this.client.request("DELETE", path)
|
||||
}
|
||||
@@ -94,12 +97,12 @@ class CartsResource extends BaseResource {
|
||||
* Refreshes a payment session.
|
||||
* @param {string} cart_id is required
|
||||
* @param {string} provider_id the provider id of the session e.g. "stripe"
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
refreshPaymentSession(
|
||||
cart_id: string,
|
||||
provider_id: string
|
||||
): AxiosPromise<StoreCartsRes> {
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/payment-sessions/${provider_id}/refresh`
|
||||
return this.client.request("POST", path)
|
||||
}
|
||||
@@ -107,9 +110,9 @@ class CartsResource extends BaseResource {
|
||||
/**
|
||||
* Retrieves a cart
|
||||
* @param {string} cart_id is required
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
retrieve(cart_id: string): AxiosPromise<StoreCartsRes> {
|
||||
retrieve(cart_id: string): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -118,12 +121,12 @@ class CartsResource extends BaseResource {
|
||||
* Refreshes a payment session.
|
||||
* @param {string} cart_id is required
|
||||
* @param {StorePostCartsCartPaymentSessionReq} payload the provider id of the session e.g. "stripe"
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
setPaymentSession(
|
||||
cart_id: string,
|
||||
payload: StorePostCartsCartPaymentSessionReq
|
||||
): AxiosPromise<StoreCartsRes> {
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/payment-session`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -132,12 +135,12 @@ class CartsResource extends BaseResource {
|
||||
* Updates a cart
|
||||
* @param {string} cart_id is required
|
||||
* @param {StorePostCartsCartReq} payload is required and can contain region_id, email, billing and shipping address
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
update(
|
||||
cart_id: string,
|
||||
payload: StorePostCartsCartReq
|
||||
): AxiosPromise<StoreCartsRes> {
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -146,12 +149,12 @@ class CartsResource extends BaseResource {
|
||||
* Updates the payment method
|
||||
* @param {string} cart_id is required
|
||||
* @param {StorePostCartsCartPaymentSessionUpdateReq} payload is required
|
||||
* @return {AxiosPromise<StoreCartsRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
updatePaymentSession(
|
||||
cart_id: string,
|
||||
payload: StorePostCartsCartPaymentSessionUpdateReq
|
||||
): AxiosPromise<StoreCartsRes> {
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/payment-session/update`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { AxiosPromise } from "axios"
|
||||
import {
|
||||
StoreCollectionsRes,
|
||||
StoreCollectionsListRes,
|
||||
StoreGetCollectionsParams,
|
||||
} from "@medusajs/medusa"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class CollectionsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a single collection
|
||||
* @param {string} id id of the collection
|
||||
* @return {AxiosPromise<StoreCollectionsRes>}
|
||||
* @return {ResponsePromise<StoreCollectionsRes>}
|
||||
*/
|
||||
retrieve(id: string): AxiosPromise<StoreCollectionsRes> {
|
||||
retrieve(id: string): ResponsePromise<StoreCollectionsRes> {
|
||||
const path = `/store/collections/${id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -20,11 +20,11 @@ class CollectionsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a list of collections
|
||||
* @param {string} query is optional. Can contain a limit and offset for the returned list
|
||||
* @return {AxiosPromise<StoreCollectionsListRes>}
|
||||
* @return {ResponsePromise<StoreCollectionsListRes>}
|
||||
*/
|
||||
list(
|
||||
query?: StoreGetCollectionsParams
|
||||
): AxiosPromise<StoreCollectionsListRes> {
|
||||
): ResponsePromise<StoreCollectionsListRes> {
|
||||
let path = `/store/collections`
|
||||
|
||||
if (query) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
StorePostCustomersCustomerReq,
|
||||
StorePostCustomersReq,
|
||||
} from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import AddressesResource from "./addresses"
|
||||
import BaseResource from "./base"
|
||||
import PaymentMethodsResource from "./payment-methods"
|
||||
@@ -18,18 +18,18 @@ class CustomerResource extends BaseResource {
|
||||
/**
|
||||
* Creates a customer
|
||||
* @param {StorePostCustomersReq} payload information of customer
|
||||
* @return { AxiosPromise<StoreCustomersRes>}
|
||||
* @return { ResponsePromise<StoreCustomersRes>}
|
||||
*/
|
||||
create(payload: StorePostCustomersReq): AxiosPromise<StoreCustomersRes> {
|
||||
create(payload: StorePostCustomersReq): ResponsePromise<StoreCustomersRes> {
|
||||
const path = `/store/customers`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the customer that is currently logged
|
||||
* @return {AxiosPromise<StoreCustomersRes>}
|
||||
* @return {ResponsePromise<StoreCustomersRes>}
|
||||
*/
|
||||
retrieve(): AxiosPromise<StoreCustomersRes> {
|
||||
retrieve(): ResponsePromise<StoreCustomersRes> {
|
||||
const path = `/store/customers/me`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -37,11 +37,11 @@ class CustomerResource extends BaseResource {
|
||||
/**
|
||||
* Updates a customer
|
||||
* @param {StorePostCustomersCustomerReq} payload information to update customer with
|
||||
* @return {AxiosPromise<StoreCustomersRes>}
|
||||
* @return {ResponsePromise<StoreCustomersRes>}
|
||||
*/
|
||||
update(
|
||||
payload: StorePostCustomersCustomerReq
|
||||
): AxiosPromise<StoreCustomersRes> {
|
||||
): ResponsePromise<StoreCustomersRes> {
|
||||
const path = `/store/customers/me`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -49,11 +49,11 @@ class CustomerResource extends BaseResource {
|
||||
/**
|
||||
* Retrieve customer orders
|
||||
* @param {StoreGetCustomersCustomerOrdersParams} params optional params to retrieve orders
|
||||
* @return {AxiosPromise<StoreCustomersListOrdersRes>}
|
||||
* @return {ResponsePromise<StoreCustomersListOrdersRes>}
|
||||
*/
|
||||
listOrders(
|
||||
params?: StoreGetCustomersCustomerOrdersParams
|
||||
): AxiosPromise<StoreCustomersListOrdersRes> {
|
||||
): ResponsePromise<StoreCustomersListOrdersRes> {
|
||||
let path = `/store/customers/me/orders`
|
||||
if (params) {
|
||||
let query: string | undefined
|
||||
@@ -76,11 +76,11 @@ class CustomerResource extends BaseResource {
|
||||
/**
|
||||
* Resets customer password
|
||||
* @param {StorePostCustomersCustomerPasswordTokenReq} payload info used to reset customer password
|
||||
* @return {AxiosPromise<StoreCustomersRes>}
|
||||
* @return {ResponsePromise<StoreCustomersRes>}
|
||||
*/
|
||||
resetPassword(
|
||||
payload: StorePostCustomersCustomerPasswordTokenReq
|
||||
): AxiosPromise<StoreCustomersRes> {
|
||||
): ResponsePromise<StoreCustomersRes> {
|
||||
const path = `/store/customers/password-reset`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -89,11 +89,11 @@ class CustomerResource extends BaseResource {
|
||||
* 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
|
||||
* @return {AxiosPromise}
|
||||
* @return {ResponsePromise}
|
||||
*/
|
||||
generatePasswordToken(
|
||||
payload: StorePostCustomersCustomerPasswordTokenReq
|
||||
): AxiosPromise {
|
||||
): ResponsePromise {
|
||||
const path = `/store/customers/password-token`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { StoreGiftCardsRes } from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class GiftCardsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a single GiftCard
|
||||
* @param {string} code code of the gift card
|
||||
* @return {AxiosPromise<StoreGiftCardsRes>}
|
||||
* @return {ResponsePromise<StoreGiftCardsRes>}
|
||||
*/
|
||||
retrieve(code: string): AxiosPromise<StoreGiftCardsRes> {
|
||||
retrieve(code: string): ResponsePromise<StoreGiftCardsRes> {
|
||||
const path = `/store/gift-cards/${code}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import {
|
||||
StoreCartsRes,
|
||||
StoreCartsDeleteRes,
|
||||
StorePostCartsCartLineItemsItemReq,
|
||||
StorePostCartsCartLineItemsReq,
|
||||
} from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class LineItemsResource extends BaseResource {
|
||||
@@ -12,12 +11,12 @@ 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
|
||||
* @return {AxiosPromise<StoreCartsCartRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
create(
|
||||
cart_id: string,
|
||||
payload: StorePostCartsCartLineItemsReq
|
||||
): AxiosPromise<StoreCartsRes> {
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/line-items`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -28,13 +27,13 @@ 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
|
||||
* @return {AxiosPromise<StoreCartsCartRes>}
|
||||
* @return {ResponsePromise<StoreCartsRes>}
|
||||
*/
|
||||
update(
|
||||
cart_id: string,
|
||||
line_id: string,
|
||||
payload: StorePostCartsCartLineItemsItemReq
|
||||
): AxiosPromise<StoreCartsRes> {
|
||||
): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/line-items/${line_id}`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -43,9 +42,9 @@ class LineItemsResource extends BaseResource {
|
||||
* Remove a line-item from a cart
|
||||
* @param {string} cart_id id of cart
|
||||
* @param {string} line_id id of item to remove
|
||||
* @return {AxiosPromise<StoreCartsDeleteRes>}
|
||||
* @return {ResponsePromise<StoreCartsDeleteRes>}
|
||||
*/
|
||||
delete(cart_id: string, line_id: string): AxiosPromise<StoreCartsDeleteRes> {
|
||||
delete(cart_id: string, line_id: string): ResponsePromise<StoreCartsRes> {
|
||||
const path = `/store/carts/${cart_id}/line-items/${line_id}`
|
||||
return this.client.request("DELETE", path)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { StoreGetOrdersParams, StoreOrdersRes } from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class OrdersResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves an order
|
||||
* @param {string} id is required
|
||||
* @return {AxiosPromise<StoreOrdersRes>}
|
||||
* @return {ResponsePromise<StoreOrdersRes>}
|
||||
*/
|
||||
retrieve(id: string): AxiosPromise<StoreOrdersRes> {
|
||||
retrieve(id: string): ResponsePromise<StoreOrdersRes> {
|
||||
const path = `/store/orders/${id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -16,9 +16,9 @@ class OrdersResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves an order by cart id
|
||||
* @param {string} cart_id is required
|
||||
* @return {AxiosPromise<StoreOrdersRes>}
|
||||
* @return {ResponsePromise<StoreOrdersRes>}
|
||||
*/
|
||||
retrieveByCartId(cart_id: string): AxiosPromise<StoreOrdersRes> {
|
||||
retrieveByCartId(cart_id: string): ResponsePromise<StoreOrdersRes> {
|
||||
const path = `/store/orders/cart/${cart_id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -26,18 +26,18 @@ class OrdersResource extends BaseResource {
|
||||
/**
|
||||
* @description Look up an order using order details
|
||||
* @param {StoreGetOrdersParams} payload details used to look up the order
|
||||
* @return {AxiosPromise<StoreOrdersRes>}
|
||||
* @return {ResponsePromise<StoreOrdersRes>}
|
||||
*/
|
||||
lookupOrder(payload: StoreGetOrdersParams): AxiosPromise<StoreOrdersRes> {
|
||||
lookupOrder(payload: StoreGetOrdersParams): ResponsePromise<StoreOrdersRes> {
|
||||
let path = `/store/orders?`
|
||||
|
||||
const queryString = Object.entries(payload).map(([key, value]) => {
|
||||
let val = value
|
||||
let val = value as string
|
||||
if (Array.isArray(value)) {
|
||||
val = value.join(",")
|
||||
}
|
||||
|
||||
return `${key}=${encodeURIComponent(val as string)}`
|
||||
return `${key}=${encodeURIComponent(val)}`
|
||||
})
|
||||
path = `/store/orders?${queryString.join("&")}`
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { StoreCustomersListPaymentMethodsRes } from '@medusajs/medusa'
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
import { AxiosPromise } from "axios"
|
||||
|
||||
class PaymentMethodsResource extends BaseResource {
|
||||
/**
|
||||
* Lists customer payment methods
|
||||
* @param {string} id id of cart
|
||||
* @return {AxiosPromise<{ payment_methods: object[] }>}
|
||||
* @return {StoreCustomersListPaymentMethodsRes}
|
||||
*/
|
||||
list(id: string): AxiosPromise<{ payment_methods: object[] }> {
|
||||
list(id: string): ResponsePromise<StoreCustomersListPaymentMethodsRes> {
|
||||
const path = `/store/carts/${id}/payment-methods`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ import {
|
||||
StoreVariantsListRes,
|
||||
StoreVariantsRes,
|
||||
} from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class ProductVariantsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a single product variant
|
||||
* @param {string} id is required
|
||||
* @return {AxiosPromise<StoreVariantsRes>}
|
||||
* @return {ResponsePromise<StoreVariantsRes>}
|
||||
*/
|
||||
retrieve(id: string): AxiosPromise<StoreVariantsRes> {
|
||||
retrieve(id: string): ResponsePromise<StoreVariantsRes> {
|
||||
const path = `/store/variants/${id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -20,9 +20,9 @@ class ProductVariantsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a list of of Product Variants
|
||||
* @param {StoreVariantsListParamsObject} query
|
||||
* @return {AxiosPromise<StoreVariantsListRes>}
|
||||
* @return {ResponsePromise<StoreVariantsListRes>}
|
||||
*/
|
||||
list(query?: StoreGetVariantsParams): AxiosPromise<StoreVariantsListRes> {
|
||||
list(query?: StoreGetVariantsParams): ResponsePromise<StoreVariantsListRes> {
|
||||
const path = `/store/variants`
|
||||
|
||||
const search = Object.entries(query || {}).map(([key, value]) => {
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
StoreProductsListRes,
|
||||
StoreProductsRes,
|
||||
} from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
import ProductVariantsResource from "./product-variants"
|
||||
|
||||
@@ -15,9 +15,9 @@ class ProductsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a single Product
|
||||
* @param {string} id is required
|
||||
* @return {AxiosPromise<StoreProductsRes>}
|
||||
* @return {ResponsePromise<StoreProductsRes>}
|
||||
*/
|
||||
retrieve(id: string): AxiosPromise<StoreProductsRes> {
|
||||
retrieve(id: string): ResponsePromise<StoreProductsRes> {
|
||||
const path = `/store/products/${id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -25,9 +25,11 @@ class ProductsResource extends BaseResource {
|
||||
/**
|
||||
* @description Searches for products
|
||||
* @param {StorePostSearchReq} searchOptions is required
|
||||
* @return {AxiosPromise<StorePostSearchRes>}
|
||||
* @return {ResponsePromise<StorePostSearchRes>}
|
||||
*/
|
||||
search(searchOptions: StorePostSearchReq): AxiosPromise<StorePostSearchRes> {
|
||||
search(
|
||||
searchOptions: StorePostSearchReq
|
||||
): ResponsePromise<StorePostSearchRes> {
|
||||
const path = `/store/products/search`
|
||||
return this.client.request("POST", path, searchOptions)
|
||||
}
|
||||
@@ -35,9 +37,9 @@ class ProductsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a list of products
|
||||
* @param {StoreGetProductsParams} query is optional. Can contain a limit and offset for the returned list
|
||||
* @return {AxiosPromise<StoreProductsListRes>}
|
||||
* @return {ResponsePromise<StoreProductsListRes>}
|
||||
*/
|
||||
list(query?: StoreGetProductsParams): AxiosPromise<StoreProductsListRes> {
|
||||
list(query?: StoreGetProductsParams): ResponsePromise<StoreProductsListRes> {
|
||||
let path = `/store/products`
|
||||
|
||||
if (query) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import { StoreRegionsListRes, StoreRegionsRes } from "@medusajs/medusa"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class RegionsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a list of regions
|
||||
* @return {AxiosPromise<StoreRegionsListRes>}
|
||||
* @return {ResponsePromise<StoreRegionsListRes>}
|
||||
*/
|
||||
list(): AxiosPromise<StoreRegionsListRes> {
|
||||
list(): ResponsePromise<StoreRegionsListRes> {
|
||||
const path = `/store/regions`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -15,9 +15,9 @@ class RegionsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a region
|
||||
* @param {string} id is required
|
||||
* @return {AxiosPromise<StoreRegionsRes>}
|
||||
* @return {ResponsePromise<StoreRegionsRes>}
|
||||
*/
|
||||
retrieve(id: string): AxiosPromise<StoreRegionsRes> {
|
||||
retrieve(id: string): ResponsePromise<StoreRegionsRes> {
|
||||
const path = `/store/regions/${id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
|
||||
@@ -3,24 +3,24 @@ import {
|
||||
StoreReturnReasonsListRes,
|
||||
StoreReturnReasonsRes,
|
||||
} from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
|
||||
class ReturnReasonsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a single Return Reason
|
||||
* @param {string} id is required
|
||||
* @return {AxiosPromise<StoreReturnReasonsRes>}
|
||||
* @return {ResponsePromise<StoreReturnReasonsRes>}
|
||||
*/
|
||||
retrieve(id: string): AxiosPromise<StoreReturnReasonsRes> {
|
||||
retrieve(id: string): ResponsePromise<StoreReturnReasonsRes> {
|
||||
const path = `/store/return-reasons/${id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists return reasons defined in Medusa Admin
|
||||
* @return {AxiosPromise<StoreReturnReasonsListRes>}
|
||||
* @return {ResponsePromise<StoreReturnReasonsListRes>}
|
||||
*/
|
||||
list(): AxiosPromise<StoreReturnReasonsListRes> {
|
||||
list(): ResponsePromise<StoreReturnReasonsListRes> {
|
||||
const path = `/store/return-reasons`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import BaseResource from "./base"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import { StoreReturnsRes, StorePostReturnsReq } from "@medusajs/medusa"
|
||||
|
||||
class ReturnsResource extends BaseResource {
|
||||
/**
|
||||
* Creates a return request
|
||||
* @param {StorePostReturnsReq} payload details needed to create a return
|
||||
* @return {AxiosPromise<StoreReturnsRes>}
|
||||
* @return {ResponsePromise<StoreReturnsRes>}
|
||||
*/
|
||||
create(payload: StorePostReturnsReq): AxiosPromise<StoreReturnsRes> {
|
||||
create(payload: StorePostReturnsReq): ResponsePromise<StoreReturnsRes> {
|
||||
const path = `/store/returns`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@ import {
|
||||
StoreGetShippingOptionsParams,
|
||||
StoreShippingOptionsListRes,
|
||||
} from "@medusajs/medusa"
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class ShippingOptionsResource extends BaseResource {
|
||||
/**
|
||||
* @description Lists shiping options available for a cart
|
||||
* @param {string} cart_id
|
||||
* @return {AxiosPromise<StoreShippingOptionsListRes>}
|
||||
* @return {ResponsePromise<StoreShippingOptionsListRes>}
|
||||
*/
|
||||
listCartOptions(cart_id: string): AxiosPromise<StoreShippingOptionsListRes> {
|
||||
listCartOptions(cart_id: string): ResponsePromise<StoreShippingOptionsListRes> {
|
||||
const path = `/store/shipping-options/${cart_id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
@@ -19,11 +19,11 @@ class ShippingOptionsResource extends BaseResource {
|
||||
/**
|
||||
* @description Lists shiping options available
|
||||
* @param {StoreGetShippingOptionsParamsObject} query
|
||||
* @return {AxiosPromise<StoreShippingOptionsListRes>}
|
||||
* @return {ResponsePromise<StoreShippingOptionsListRes>}
|
||||
*/
|
||||
list(
|
||||
query?: StoreGetShippingOptionsParams
|
||||
): AxiosPromise<StoreShippingOptionsListRes> {
|
||||
): ResponsePromise<StoreShippingOptionsListRes> {
|
||||
let path = `/store/shipping-options`
|
||||
|
||||
const queryString = Object.entries(query || {}).map(([key, value]) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AxiosPromise } from "axios"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import { StoreSwapsRes, StorePostSwapsReq } from "@medusajs/medusa"
|
||||
import BaseResource from "./base"
|
||||
|
||||
@@ -6,9 +6,9 @@ class SwapsResource extends BaseResource {
|
||||
/**
|
||||
* @description Creates a swap from a cart
|
||||
* @param {StorePostSwapsReq} payload
|
||||
* @return {AxiosPromise<StoreSwapsRes>}
|
||||
* @return {ResponsePromise<StoreSwapsRes>}
|
||||
*/
|
||||
create(payload: StorePostSwapsReq): AxiosPromise<StoreSwapsRes> {
|
||||
create(payload: StorePostSwapsReq): ResponsePromise<StoreSwapsRes> {
|
||||
const path = `/store/swaps`
|
||||
return this.client.request("POST", path, payload)
|
||||
}
|
||||
@@ -16,9 +16,9 @@ class SwapsResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a swap by cart id
|
||||
* @param {string} cart_id id of cart
|
||||
* @return {AxiosPromise<StoreSwapsRes>}
|
||||
* @return {ResponsePromise<StoreSwapsRes>}
|
||||
*/
|
||||
retrieveByCartId(cart_id: string): AxiosPromise<StoreSwapsRes> {
|
||||
retrieveByCartId(cart_id: string): ResponsePromise<StoreSwapsRes> {
|
||||
const path = `/store/swaps/${cart_id}`
|
||||
return this.client.request("GET", path)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { AxiosResponse } from "axios"
|
||||
|
||||
export type Response<T> = T & {
|
||||
response: Omit<AxiosResponse<T>, "data">
|
||||
}
|
||||
|
||||
export type ResponsePromise<T = any> = Promise<Response<T>>
|
||||
Reference in New Issue
Block a user