@medusajs/medusa-js
Version:
Client for Medusa Commerce Rest API
800 lines (787 loc) • 404 kB
TypeScript
import { AxiosError, AxiosRequestHeaders, AxiosInstance } from 'axios';
import { AdminCreateUserRequest, AdminUpdateUserRequest, AdminPostInvitesReq, StorePostCustomersCustomerAddressesReq, StoreCustomersRes, StorePostCustomersCustomerAddressesAddressReq, StorePostAuthReq, StoreAuthRes, StoreGetAuthEmailRes, StoreBearerAuthRes, StorePostCartsCartLineItemsReq, StoreCartsRes, StorePostCartsCartLineItemsItemReq, StorePostCartsCartShippingMethodReq, StoreCompleteCartRes, StorePostCartReq, StorePostCartsCartPaymentSessionReq, StorePostCartsCartReq, StorePostCartsCartPaymentSessionUpdateReq, StoreCollectionsRes, StoreGetCollectionsParams, StoreCollectionsListRes, StoreCustomersListPaymentMethodsRes, StorePostCustomersReq, StorePostCustomersCustomerReq, StoreGetCustomersCustomerOrdersParams, StoreCustomersListOrdersRes, StorePostCustomersResetPasswordReq, StorePostCustomersCustomerPasswordTokenReq, StoreGiftCardsRes, StoreOrderEditsRes, StorePostOrderEditsOrderEditDecline, StoreOrdersRes, StoreGetOrdersParams, StorePostCustomersCustomerOrderClaimReq, StorePostCustomersCustomerAcceptClaimReq, StoreGetPaymentCollectionsParams, StorePaymentCollectionsRes, StorePostPaymentCollectionsBatchSessionsAuthorizeReq, StorePostPaymentCollectionsBatchSessionsReq, StorePaymentCollectionSessionsReq, StorePaymentCollectionsSessionRes, StoreGetProductCategoriesCategoryParams, StoreGetProductCategoriesCategoryRes, StoreGetProductCategoriesParams, StoreGetProductCategoriesRes, StoreGetProductTagsParams, StoreProductTagsListRes, StoreGetProductTypesParams, StoreProductTypesListRes, StoreVariantsRes, StoreGetVariantsParams, StoreVariantsListRes, StoreProductsRes, StorePostSearchReq, StorePostSearchRes, StoreGetProductsParams, StoreProductsListRes, StoreRegionsListRes, StoreRegionsRes, StoreReturnReasonsRes, StoreReturnReasonsListRes, StorePostReturnsReq, StoreReturnsRes, StoreShippingOptionsListRes, StoreGetShippingOptionsParams, StorePostSwapsReq, StoreSwapsRes, AdminAuthRes, AdminPostAuthReq, AdminBearerAuthRes, AdminPostBatchesReq, AdminBatchJobRes, AdminGetBatchParams, AdminBatchJobListRes, AdminPostCollectionsReq, AdminCollectionsRes, AdminPostCollectionsCollectionReq, AdminCollectionsDeleteRes, AdminGetCollectionsParams, AdminCollectionsListRes, AdminPostProductsToCollectionReq, AdminDeleteProductsFromCollectionReq, AdminDeleteProductsFromCollectionRes, AdminGetCurrenciesParams, AdminCurrenciesListRes, AdminPostCurrenciesCurrencyReq, AdminCurrenciesRes, AdminPostCustomerGroupsReq, AdminCustomerGroupsRes, AdminGetCustomerGroupsGroupParams, AdminPostCustomerGroupsGroupReq, AdminCustomerGroupsDeleteRes, AdminGetCustomerGroupsParams, AdminCustomerGroupsListRes, AdminPostCustomerGroupsGroupCustomersBatchReq, AdminDeleteCustomerGroupsGroupCustomerBatchReq, AdminGetCustomersParams, AdminCustomersListRes, AdminPostCustomersReq, AdminCustomersRes, AdminPostCustomersCustomerReq, AdminDiscountsRes, AdminPostDiscountsReq, AdminPostDiscountsDiscountReq, AdminPostDiscountsDiscountDynamicCodesReq, AdminDiscountsDeleteRes, AdminGetDiscountsParams, AdminDiscountsListRes, AdminPostDiscountsDiscountConditions, AdminPostDiscountsDiscountConditionsParams, AdminPostDiscountsDiscountConditionsCondition, AdminPostDiscountsDiscountConditionsConditionParams, AdminGetDiscountsDiscountConditionsConditionParams, AdminDiscountConditionsRes, AdminPostDiscountsDiscountConditionsConditionBatchReq, AdminPostDiscountsDiscountConditionsConditionBatchParams, AdminDeleteDiscountsDiscountConditionsConditionBatchReq, AdminPostDraftOrdersReq, AdminDraftOrdersRes, AdminPostDraftOrdersDraftOrderLineItemsReq, AdminDraftOrdersDeleteRes, AdminGetDraftOrdersParams, AdminDraftOrdersListRes, AdminPostDraftOrdersDraftOrderRegisterPaymentRes, AdminPostDraftOrdersDraftOrderReq, AdminPostDraftOrdersDraftOrderLineItemsItemReq, AdminPostGiftCardsReq, AdminGiftCardsRes, AdminPostGiftCardsGiftCardReq, AdminGiftCardsDeleteRes, AdminGetGiftCardsParams, AdminGiftCardsListRes, AdminGetInventoryItemsItemParams, AdminInventoryItemsRes, AdminPostInventoryItemsInventoryItemReq, AdminPostInventoryItemsInventoryItemParams, AdminInventoryItemsDeleteRes, AdminPostInventoryItemsReq, AdminPostInventoryItemsParams, AdminGetInventoryItemsParams, AdminInventoryItemsListWithVariantsAndLocationLevelsRes, AdminPostInventoryItemsItemLocationLevelsLevelReq, AdminPostInventoryItemsItemLocationLevelsLevelParams, AdminPostInventoryItemsItemLocationLevelsReq, AdminPostInventoryItemsItemLocationLevelsParams, AdminGetInventoryItemsItemLocationLevelsParams, AdminInventoryItemsLocationLevelsRes, AdminPostInvitesInviteAcceptReq, AdminInviteDeleteRes, AdminListInvitesRes, AdminPostNotesReq, AdminNotesRes, AdminPostNotesNoteReq, AdminNotesDeleteRes, AdminGetNotesParams, AdminNotesListRes, AdminGetNotificationsParams, AdminNotificationsListRes, AdminPostNotificationsNotificationResendReq, AdminNotificationsRes, GetOrderEditsOrderEditParams, AdminOrderEditsRes, GetOrderEditsParams, AdminOrderEditsListRes, AdminPostOrderEditsReq, AdminPostOrderEditsOrderEditReq, AdminOrderEditDeleteRes, AdminPostOrderEditsEditLineItemsReq, AdminOrderEditItemChangeDeleteRes, AdminPostOrderEditsEditLineItemsLineItemReq, AdminPostOrdersOrderReq, AdminOrdersRes, AdminGetOrdersParams, AdminOrdersListRes, AdminPostOrdersOrderRefundsReq, AdminPostOrdersOrderFulfillmentsReq, AdminPostOrdersOrderShipmentReq, AdminPostOrdersOrderReturnsReq, AdminPostOrdersOrderShippingMethodsReq, AdminPostOrdersOrderSwapsReq, AdminPostOrdersOrderSwapsSwapFulfillmentsReq, AdminPostOrdersOrderSwapsSwapShipmentsReq, AdminPostOrdersOrderClaimsReq, AdminPostOrdersOrderClaimsClaimReq, AdminPostOrdersOrderClaimsClaimFulfillmentsReq, AdminPostOrdersOrderClaimsClaimShipmentsReq, AdminGetPaymentCollectionsParams, AdminPaymentCollectionsRes, AdminUpdatePaymentCollectionsReq, AdminPaymentCollectionDeleteRes, GetPaymentsParams, AdminPaymentRes, AdminPostPaymentRefundsReq, AdminRefundRes, AdminPostPriceListsPriceListReq, AdminPriceListRes, AdminPostPriceListsPriceListPriceListReq, AdminPriceListDeleteRes, AdminGetPriceListPaginationParams, AdminPriceListsListRes, AdminGetPriceListsPriceListProductsParams, AdminPriceListsProductsListRes, AdminPostPriceListPricesPricesReq, AdminDeletePriceListPricesPricesReq, AdminPriceListDeleteBatchRes, AdminPriceListDeleteProductPricesRes, AdminPriceListDeleteVariantPricesRes, AdminDeletePriceListsPriceListProductsPricesBatchReq, AdminGetProductCategoryParams, AdminProductCategoriesCategoryRes, AdminPostProductCategoriesReq, AdminPostProductCategoriesCategoryReq, AdminGetProductCategoriesParams, AdminProductCategoriesListRes, AdminProductCategoriesCategoryDeleteRes, AdminDeleteProductCategoriesCategoryProductsBatchReq, AdminPostProductCategoriesCategoryProductsBatchReq, AdminGetProductTagsParams, AdminProductTagsListRes, AdminGetProductTypesParams, AdminProductTypesListRes, AdminPostProductsReq, AdminProductsRes, AdminPostProductsProductReq, AdminProductsDeleteRes, AdminGetProductsParams, AdminProductsListRes, AdminProductsListTypesRes, AdminProductsListTagsRes, AdminPostProductsProductMetadataReq, AdminPostProductsProductVariantsReq, AdminPostProductsProductVariantsVariantReq, AdminProductsDeleteVariantRes, AdminPostProductsProductOptionsReq, AdminPostProductsProductOptionsOption, AdminProductsDeleteOptionRes, AdminPublishableApiKeysRes, GetPublishableApiKeysParams, AdminPublishableApiKeysListRes, AdminPostPublishableApiKeysReq, AdminPostPublishableApiKeysPublishableApiKeyReq, AdminPublishableApiKeyDeleteRes, AdminPostPublishableApiKeySalesChannelsBatchReq, AdminDeletePublishableApiKeySalesChannelsBatchReq, GetPublishableApiKeySalesChannelsParams, AdminPublishableApiKeysListSalesChannelsRes, AdminPostRegionsReq, AdminRegionsRes, AdminPostRegionsRegionReq, AdminRegionsDeleteRes, AdminGetRegionsParams, AdminRegionsListRes, AdminPostRegionsRegionCountriesReq, AdminPostRegionsRegionFulfillmentProvidersReq, AdminGetRegionsRegionFulfillmentOptionsRes, AdminPostRegionsRegionPaymentProvidersReq, AdminReservationsRes, AdminGetReservationsParams, AdminReservationsListRes, AdminPostReservationsReq, AdminPostReservationsReservationReq, AdminReservationsDeleteRes, AdminPostReturnReasonsReq, AdminReturnReasonsRes, AdminPostReturnReasonsReasonReq, AdminReturnReasonsDeleteRes, AdminReturnReasonsListRes, AdminReturnsCancelRes, AdminPostReturnsReturnReceiveReq, AdminReturnsRes, AdminGetReturnsParams, AdminReturnsListRes, AdminSalesChannelsRes, AdminPostSalesChannelsReq, AdminPostSalesChannelsSalesChannelReq, AdminGetSalesChannelsParams, AdminSalesChannelsListRes, AdminSalesChannelsDeleteRes, AdminDeleteSalesChannelsChannelProductsBatchReq, AdminPostSalesChannelsChannelProductsBatchReq, AdminPostSalesChannelsChannelStockLocationsReq, AdminDeleteSalesChannelsChannelStockLocationsReq, AdminPostShippingOptionsReq, AdminShippingOptionsRes, AdminPostShippingOptionsOptionReq, AdminShippingOptionsDeleteRes, AdminGetShippingOptionsParams, AdminShippingOptionsListRes, AdminPostShippingProfilesReq, AdminShippingProfilesRes, AdminPostShippingProfilesProfileReq, AdminDeleteShippingProfileRes, AdminShippingProfilesListRes, AdminPostStockLocationsReq, AdminStockLocationsRes, AdminPostStockLocationsLocationReq, AdminStockLocationsDeleteRes, AdminGetStockLocationsParams, AdminStockLocationsListRes, AdminPostStoreReq, AdminStoresRes, AdminExtendedStoresRes, AdminPaymentProvidersList, AdminTaxProvidersList, AdminSwapsRes, AdminGetSwapsParams, AdminSwapsListRes, AdminGetTaxRatesTaxRateParams, AdminTaxRatesRes, AdminGetTaxRatesParams, AdminTaxRatesListRes, AdminPostTaxRatesReq, AdminPostTaxRatesParams, AdminPostTaxRatesTaxRateReq, AdminPostTaxRatesTaxRateParams, AdminPostTaxRatesTaxRateProductsReq, AdminPostTaxRatesTaxRateProductsParams, AdminPostTaxRatesTaxRateProductTypesReq, AdminPostTaxRatesTaxRateShippingOptionsReq, AdminPostTaxRatesTaxRateShippingOptionsParams, AdminDeleteTaxRatesTaxRateProductsReq, AdminDeleteTaxRatesTaxRateProductsParams, AdminDeleteTaxRatesTaxRateProductTypesReq, AdminDeleteTaxRatesTaxRateProductTypesParams, AdminDeleteTaxRatesTaxRateShippingOptionsReq, AdminDeleteTaxRatesTaxRateShippingOptionsParams, AdminTaxRatesDeleteRes, AdminUploadsRes, AdminDeleteUploadsReq, AdminDeleteUploadsRes, AdminPostUploadsDownloadUrlReq, AdminUploadsDownloadUrlRes, AdminResetPasswordTokenRequest, AdminResetPasswordRequest, AdminUserRes, AdminDeleteUserRes, AdminUsersListRes, AdminGetVariantsParams, AdminVariantsListRes, AdminGetVariantParams, AdminVariantsRes, AdminGetVariantsVariantInventoryRes } from '@medusajs/medusa';
import { FindParams } from '@medusajs/medusa/dist/types/common';
/**
* MedusaError is the base error for every other MedusaError
*/
declare class MedusaError extends Error {
constructor();
static factory(type: ErrorType): MedusaError;
}
declare enum ErrorType {
"INVALID_REQUEST" = 0,
"API" = 1,
"AUTHENTICATION" = 2,
"PERMISSION" = 3,
"CONNECTION" = 4
}
/**
* `KeyManager` holds API keys in state.
*/
declare class KeyManager {
private publishableApiKey;
/**
* Set a publishable api key to be sent with each request.
*/
registerPublishableApiKey(key: string): void;
/**
* Retrieve the publishable api key.
*/
getPublishableApiKey(): string | null;
}
/**
* Export singleton instance.
*/
declare const _default: KeyManager;
interface Config {
baseUrl: string;
maxRetries: number;
apiKey?: string;
publishableApiKey?: string;
customHeaders?: Record<string, any>;
}
/**
* @interface
*
* Options to pass to requests sent to custom API Routes
*
* @prop timeout - The number of milliseconds before the request times out.
* @prop numberOfRetries - The number of times to retry a request before failing.
*/
interface RequestOptions {
timeout?: number;
numberOfRetries?: number;
}
type RequestMethod = "DELETE" | "POST" | "GET";
declare class Client {
private axiosClient;
private config;
constructor(config: Config);
shouldRetryCondition(err: AxiosError, numRetries: number, maxRetries: number): boolean;
normalizeHeaders(obj: object): Record<string, any>;
normalizeHeader(header: string): string;
requiresAuthentication(path: any, method: any): boolean;
/**
* Creates all the initial headers.
* We add the idempotency key, if the request is configured to retry.
* @param {object} userHeaders user supplied headers
* @param {Types.RequestMethod} method request method
* @param {string} path request path
* @param {object} customHeaders user supplied headers
* @return {object}
*/
setHeaders(userHeaders: RequestOptions, method: RequestMethod, path: string, customHeaders?: Record<string, any>): AxiosRequestHeaders;
/**
* Creates the axios client used for requests
* As part of the creation, we configure the retry conditions
* and the exponential backoff approach.
* @param {Config} config user supplied configurations
* @return {AxiosInstance}
*/
createClient(config: Config): AxiosInstance;
/**
* Axios request
* @param method request method
* @param path request path
* @param payload request payload
* @param options axios configuration
* @param customHeaders custom request headers
* @return
*/
request(method: RequestMethod, path: string, payload?: Record<string, any>, options?: RequestOptions, customHeaders?: Record<string, any>): Promise<any>;
}
interface HTTPResponse {
status: number;
statusText: string;
headers: Record<string, string> & {
"set-cookie"?: string[];
};
config: any;
request?: any;
}
type Response<T> = T & {
response: HTTPResponse;
};
type ResponsePromise<T = any> = Promise<Response<T>>;
type NoUndefined<T> = T extends undefined ? never : T;
type CreateUserRolesEnum = NoUndefined<AdminCreateUserRequest["role"]>;
type CreateUserRoles = `${CreateUserRolesEnum}`;
type AdminCreateUserPayload = Omit<AdminCreateUserRequest, "role"> | {
role?: CreateUserRoles;
};
type UpdateUserRolesEnum = NoUndefined<AdminUpdateUserRequest["role"]>;
type UpdateUserRoles = `${UpdateUserRolesEnum}`;
type AdminUpdateUserPayload = Omit<AdminUpdateUserRequest, "role"> & {
role?: UpdateUserRoles;
};
type InviteUserRolesEnum = `${AdminPostInvitesReq["role"]}`;
type AdminPostInvitesPayload = Omit<AdminPostInvitesReq, "role"> & {
role: InviteUserRolesEnum;
};
type AdminCreateUploadPayload = File | File[];
declare class BaseResource {
client: Client;
constructor(client: Client);
}
/**
* This class is used to send requests to Address API Routes part of the [Store Customer API Routes](https://docs.medusajs.com/api/store#customers_postcustomers). All its method
* are available in the JS Client under the `medusa.customers.addresses` property.
*
* All methods in this class require {@link AuthResource.authenticate | customer authentication}.
*/
declare class AddressesResource extends BaseResource {
/**
* Add an address to the logged-in customer's saved addresses.
* @param {StorePostCustomersCustomerAddressesReq} payload - The address to add.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCustomersRes>} Resolves to the customer's details, including the customer's addresses in the `shipping_addresses` attribute.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* // must be previously logged
* medusa.customers.addresses.addAddress({
* address: {
* first_name: "Celia",
* last_name: "Schumm",
* address_1: "225 Bednar Curve",
* city: "Danielville",
* country_code: "US",
* postal_code: "85137",
* phone: "981-596-6748 x90188",
* company: "Wyman LLC",
* province: "Georgia",
* }
* })
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
addAddress(payload: StorePostCustomersCustomerAddressesReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersRes>;
/**
* Delete an address of the logged-in customer.
* @param {string} address_id - The ID of the address to delete.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCustomersRes>} Resolves to the customer's details, including the customer's addresses in the `shipping_addresses` attribute.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* // must be previously logged
* medusa.customers.addresses.deleteAddress(addressId)
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
deleteAddress(address_id: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersRes>;
/**
* Update an address of the logged-in customer.
* @param {string} address_id - The address's ID.
* @param {StorePostCustomersCustomerAddressesAddressReq} payload - The attributes to update in the address.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCustomersRes>} Resolves to the customer's details, including the customer's addresses in the `shipping_addresses` attribute.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* // must be previously logged
* medusa.customers.addresses.updateAddress(addressId, {
* first_name: "Gina"
* })
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
updateAddress(address_id: string, payload: StorePostCustomersCustomerAddressesAddressReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersRes>;
}
/**
* This class is used to send requests to [Store Auth API Routes](https://docs.medusajs.com/api/store#auth). All its method
* are available in the JS Client under the `medusa.auth` property.
*
* The methods in this class allows you to manage a customer's session, such as login or log out.
* You can send authenticated requests for a customer either using the Cookie header or using the JWT Token.
* When you log the customer in using the {@link authenticate} method, the JS client will automatically attach the
* cookie header in all subsequent requests.
*
* Related Guide: [How to implement customer profiles in your storefront](https://docs.medusajs.com/modules/customers/storefront/implement-customer-profiles).
*/
declare class AuthResource extends BaseResource {
/**
* Authenticate a customer using their email and password. If the customer is authenticated successfully, the cookie is automatically attached to subsequent requests sent with the JS Client.
* @param {StorePostAuthReq} payload - The credentials of the customer to authenticate.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreAuthRes>} Resolves to the customer's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.auth.authenticate({
* email: "user@example.com",
* password: "user@example.com"
* })
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
authenticate(payload: StorePostAuthReq, customHeaders?: Record<string, any>): ResponsePromise<StoreAuthRes>;
/**
* Log out the customer and remove their authentication session. This method requires {@link AuthResource.authenticate | customer authentication}.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<void>} Resolves when customer is logged out successfully.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.auth.deleteSession()
* .then(() => {
* // customer logged out successfully
* })
*/
deleteSession(customHeaders?: Record<string, any>): ResponsePromise<void>;
/**
* Retrieve the details of the logged-in customer. Can also be used to check if there is an authenticated customer.
* This method requires {@link AuthResource.authenticate | customer authentication}.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreAuthRes>} Resolves to the customer's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* // must be previously logged
* medusa.auth.getSession()
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
getSession(customHeaders?: Record<string, any>): ResponsePromise<StoreAuthRes>;
/**
* Check if the email is already used by another registered customer. Can be used to validate a new customer's email.
* @param {string} email - The email to check.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreGetAuthEmailRes>} Resolves to the result of the check.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.auth.exists("user@example.com")
*/
exists(email: string, customHeaders?: Record<string, any>): ResponsePromise<StoreGetAuthEmailRes>;
/**
* Authenticate the customer and retrieve a JWT token to use for subsequent authenticated requests.
* @param {AdminPostAuthReq} payload - The credentials of the customer to authenticate.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreBearerAuthRes>} Resolves to the access token of the customer, if they're authenticated successfully.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.auth.getToken({
* email: 'user@example.com',
* password: 'supersecret'
* })
* .then(({ access_token }) => {
* console.log(access_token);
* })
*/
getToken(payload: StorePostAuthReq, customHeaders?: Record<string, any>): ResponsePromise<StoreBearerAuthRes>;
}
/**
* This class is used to send requests to Line Item API Routes part of the [Store Cart API Routes](https://docs.medusajs.com/api/store#carts). All its method
* are available in the JS Client under the `medusa.carts.lineItems` property.
*/
declare class LineItemsResource extends BaseResource {
/**
* Generates a Line Item with a given Product Variant and adds it to the Cart
* @param {string} cart_id - The cart's ID.
* @param {StorePostCartsCartLineItemsReq} payload - The line item to be created.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the associated cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.lineItems.create(cart_id, {
* variant_id,
* quantity: 1
* })
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
create(cart_id: string, payload: StorePostCartsCartLineItemsReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Update a line item's data.
* @param {string} cart_id - The ID of the line item's cart.
* @param {string} line_id - The ID of the line item to update.
* @param {StorePostCartsCartLineItemsItemReq} payload - The data to update in the line item.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the associated cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.lineItems.update(cartId, lineId, {
* quantity: 1
* })
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
update(cart_id: string, line_id: string, payload: StorePostCartsCartLineItemsItemReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Delete a line item from a cart. The payment sessions will be updated and the totals will be recalculated.
* @param {string} cart_id - The ID of the line item's cart.
* @param {string} line_id - The ID of the line item to delete.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the associated cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.lineItems.delete(cartId, lineId)
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
delete(cart_id: string, line_id: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
}
/**
* This class is used to send requests to [Store Cart API Routes](https://docs.medusajs.com/api/store#carts). All its method
* are available in the JS Client under the `medusa.carts` property.
*
* A cart is a virtual shopping bag that customers can use to add items they want to purchase.
* A cart is then used to checkout and place an order.
*
* Related Guide: [How to implement cart functionality in your storefront](https://docs.medusajs.com/modules/carts-and-checkout/storefront/implement-cart).
*/
declare class CartsResource extends BaseResource {
/**
* An instance of {@link LineItemsResource} used to send requests to line-item-related routes part of the [Store Cart API Routes](https://docs.medusajs.com/api/store#carts).
*/
lineItems: LineItemsResource;
/**
* Add a shipping method to the cart. The validation of the `data` field is handled by the fulfillment provider of the chosen shipping option.
* @param {string} cart_id - The ID of the cart to add the shipping method to.
* @param {StorePostCartsCartShippingMethodReq} payload - The shipping method to add.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.addShippingMethod(cartId, {
* option_id
* })
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
addShippingMethod(cart_id: string, payload: StorePostCartsCartShippingMethodReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Complete a cart and place an order or create a swap, based on the cart's type. This includes attempting to authorize the cart's payment.
* If authorizing the payment requires more action, the cart will not be completed and the order will not be placed or the swap will not be created.
* An idempotency key will be generated if none is provided in the header `Idempotency-Key` and added to
* the response. If an error occurs during cart completion or the request is interrupted for any reason, the cart completion can be retried by passing the idempotency
* key in the `Idempotency-Key` header.
* @param {string} cart_id - The ID of the cart to complete.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCompleteCartRes>} Resolves to the completion details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.complete(cartId)
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
complete(cart_id: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCompleteCartRes>;
/**
* Create a Cart. Although optional, specifying the cart's region and sales channel can affect the cart's pricing and
* the products that can be added to the cart respectively. So, make sure to set those early on and change them if necessary, such as when the customer changes their region.
* If a customer is logged in, make sure to pass its ID or email within the cart's details so that the cart is attached to the customer.
* @param {StorePostCartReq} payload - The cart to create.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the created cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.create()
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
create(payload?: StorePostCartReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Create Payment Sessions for each of the available Payment Providers in the Cart's Region. If there's only one payment session created,
* it will be selected by default. The creation of the payment session uses the payment provider and may require sending requests to third-party services.
* @param {string} cart_id - The ID of the cart to create the payment sessions for.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.createPaymentSessions(cartId)
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
createPaymentSessions(cart_id: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Remove a Discount from a Cart. This only removes the application of the discount, and not completely deletes it. The totals will be re-calculated and the payment sessions
* will be refreshed after the removal.
* @param {string} cart_id - the ID of the cart to remove the discount from.
* @param {string} code - The code of the discount to remove from the cart.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.deleteDiscount(cartId, code)
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
deleteDiscount(cart_id: string, code: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Delete a Payment Session in a Cart. May be useful if a payment has failed. The totals will be recalculated.
* @param {string} cart_id - The ID of the cart to delete the payment session from.
* @param {string} provider_id - The ID of the payment provider that the session is associated with.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.deletePaymentSession(cartId, "manual")
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
deletePaymentSession(cart_id: string, provider_id: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Refresh a Payment Session to ensure that it is in sync with the Cart. This is usually not necessary, but is provided for edge cases.
* @param {string} cart_id - The ID of the cart to refresh its payment session.
* @param {string} provider_id - The ID of the payment provider that's associated with the payment session.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.refreshPaymentSession(cartId, "manual")
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
refreshPaymentSession(cart_id: string, provider_id: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Retrieve a Cart's details. This includes recalculating its totals.
* @param {string} cart_id - The cart's ID.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.retrieve(cartId)
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
retrieve(cart_id: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Select the Payment Session that will be used to complete the cart. This is typically used when the customer chooses their preferred payment method during checkout.
* The totals of the cart will be recalculated.
* @param {string} cart_id - The cart's ID.
* @param {StorePostCartsCartPaymentSessionReq} payload - The associated payment provider.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.setPaymentSession(cartId, {
* provider_id: "manual"
* })
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
setPaymentSession(cart_id: string, payload: StorePostCartsCartPaymentSessionReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Update a Cart's details. If the cart has payment sessions and the region was not changed, the payment sessions are updated. The cart's totals are also recalculated.
* @param {string} cart_id - The cart's ID.
* @param {StorePostCartsCartReq} payload - The attributes to update in the cart.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.update(cartId, {
* email: "user@example.com"
* })
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
update(cart_id: string, payload: StorePostCartsCartReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
/**
* Update a Payment Session with additional data. This can be useful depending on the payment provider used.
* All payment sessions are updated and cart totals are recalculated afterwards.
* @param {string} cart_id - The cart's ID.
* @param {string} provider_id - The ID of the payment provider that the payment session is associated with.
* @param {StorePostCartsCartPaymentSessionUpdateReq} payload - The attributes to update in the payment session.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCartsRes>} Resolves to the cart's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.carts.updatePaymentSession(cartId, "manual", {
* data: {
*
* }
* })
* .then(({ cart }) => {
* console.log(cart.id);
* })
*/
updatePaymentSession(cart_id: string, provider_id: string, payload: StorePostCartsCartPaymentSessionUpdateReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCartsRes>;
}
/**
* This class is used to send requests to [Store Product Collection API Routes](https://docs.medusajs.com/api/store#product-collections). All its method
* are available in the JS Client under the `medusa.collections` property.
*
* A product collection is used to organize products for different purposes such as marketing or discount purposes. For example, you can create a Summer Collection.
* Using the methods in this class, you can list or retrieve a collection's details and products.
*/
declare class CollectionsResource extends BaseResource {
/**
* Retrieve a product collection's details.
* @param {string} id - The ID of the product collection.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCollectionsRes>} Resolves to the collection's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.collections.retrieve(collectionId)
* .then(({ collection }) => {
* console.log(collection.id);
* })
*/
retrieve(id: string, customHeaders?: Record<string, any>): ResponsePromise<StoreCollectionsRes>;
/**
* Retrieve a list of product collections. The product collections can be filtered by fields such as `handle` or `created_at` passed in the `query` parameter.
* The product collections can also be paginated.
* @param {StoreGetCollectionsParams} query - Filters and pagination configurations to apply on the retrieved product collections.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCollectionsListRes>} Resolves to the list of product collections with pagination fields.
*
* @example
* To list product collections:
*
* ```ts
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.collections.list()
* .then(({ collections, limit, offset, count }) => {
* console.log(collections.length);
* })
* ```
*
* By default, only the first `10` records are retrieved. You can control pagination by specifying the `limit` and `offset` properties:
*
* ```ts
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.collections.list({
* limit,
* offset
* })
* .then(({ collections, limit, offset, count }) => {
* console.log(collections.length);
* })
* ```
*/
list(query?: StoreGetCollectionsParams, customHeaders?: Record<string, any>): ResponsePromise<StoreCollectionsListRes>;
}
/**
* This class is used to send requests to Payment Method API Routes part of the [Store Customer API Routes](https://docs.medusajs.com/api/store#customers_postcustomers). All its method
* are available in the JS Client under the `medusa.customers.paymentMethods` property.
*
* All methods in this class require {@link AuthResource.authenticate | customer authentication}.
*/
declare class PaymentMethodsResource extends BaseResource {
/**
* Retrieve the logged-in customer's saved payment methods. This method only works with payment providers created with the deprecated Payment Service interface.
* The payment methods are saved using the Payment Service's third-party service, and not on the Medusa backend. So, they're retrieved from the third-party service.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {StoreCustomersListPaymentMethodsRes} Resolves to the customer's payment methods.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* // must be previously logged
* medusa.customers.paymentMethods.list()
* .then(({ payment_methods }) => {
* console.log(payment_methods.length);
* })
*/
list(customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersListPaymentMethodsRes>;
}
/**
* This class is used to send requests to [Store Customer API Routes](https://docs.medusajs.com/api/store#customers_postcustomers). All its method
* are available in the JS Client under the `medusa.customers` property.
*
* A customer can register and manage their information such as addresses, orders, payment methods, and more.
*
* Related Guide: [How to implement customer profiles in your storefront](https://docs.medusajs.com/modules/customers/storefront/implement-customer-profiles).
*/
declare class CustomerResource extends BaseResource {
/**
* An instance of {@link PaymentMethodsResource} used to send requests to payment-related routes part of the [Store Customer API Routes](https://docs.medusajs.com/api/store#customers_postcustomers).
*/
paymentMethods: PaymentMethodsResource;
/**
* An instance of {@link AddressesResource} used to send requests to address-related routes part of the [Store Customer API Routes](https://docs.medusajs.com/api/store#customers_postcustomers).
*/
addresses: AddressesResource;
/**
* Register a new customer. This will also automatically authenticate the customer and set their login session in the response Cookie header.
* Subsequent requests sent with the JS client are sent with the Cookie session automatically.
* @param {StorePostCustomersReq} payload - The details of the customer to be created.
* @param {string} query - Filters and pagination configurations to apply on the retrieved product collections.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns { ResponsePromise<StoreCustomersRes>} Resolves to the created customer's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.customers.create({
* first_name: "Alec",
* last_name: "Reynolds",
* email: "user@example.com",
* password: "supersecret"
* })
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
create(payload: StorePostCustomersReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersRes>;
/**
* Retrieve the logged-in customer's details. This method requires {@link AuthResource.authenticate | customer authentication}.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCustomersRes>} Resolves to the logged-in customer's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* // must be previously logged
* medusa.customers.retrieve()
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
retrieve(customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersRes>;
/**
* Update the logged-in customer's details. This method requires {@link AuthResource.authenticate | customer authentication}.
* @param {StorePostCustomersCustomerReq} payload - The attributes to update in the logged-in customer.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCustomersRes>} Resolves to the logged-in customer's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* // must be previously logged
* medusa.customers.update({
* first_name: "Laury"
* })
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
update(payload: StorePostCustomersCustomerReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersRes>;
/**
* Retrieve a list of the logged-in customer's orders. The orders can be filtered by fields such as `status` or `fulfillment_status`. The orders can also be paginated.
* This method requires {@link AuthResource.authenticate | customer authentication}.
* @param {StoreGetCustomersCustomerOrdersParams} params - Filters and pagination configurations to apply on the retrieved orders.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCustomersListOrdersRes>} Resolves to the list of orders with pagination fields.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* // must be previously logged
* medusa.customers.listOrders()
* .then(({ orders, limit, offset, count }) => {
* console.log(orders);
* })
*/
listOrders(params?: StoreGetCustomersCustomerOrdersParams, customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersListOrdersRes>;
/**
* Reset a customer's password using a password token created by a previous request using the {@link generatePasswordToken} method. If the password token expired,
* you must create a new one.
* @param {StorePostCustomersResetPasswordReq} payload - The necessary details to reset the password.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreCustomersRes>} Resolves to the customer's details.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.customers.resetPassword({
* email: "user@example.com",
* password: "supersecret",
* token: "supersecrettoken"
* })
* .then(({ customer }) => {
* console.log(customer.id);
* })
*/
resetPassword(payload: StorePostCustomersResetPasswordReq, customHeaders?: Record<string, any>): ResponsePromise<StoreCustomersRes>;
/**
* Create a reset password token to be used when sending a request with the {@link resetPassword} method. This emits the event `customer.password_reset`. If a notification provider is
* installed in the Medusa backend and is configured to handle this event, a notification to the customer, such as an email, may be sent with reset instructions.
* @param {StorePostCustomersCustomerPasswordTokenReq} payload - The necessary details to create the reset password token.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise} Resolves when reset password token is created successfully.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
* medusa.customers.generatePasswordToken({
* email: "user@example.com"
* })
* .then(() => {
* // successful
* })
* .catch(() => {
* // failed
* })
*/
generatePasswordToken(payload: StorePostCustomersCustomerPasswordTokenReq, customHeaders?: Record<string, any>): ResponsePromise;
}
/**
* This class is used to send requests to [Store Gift Card API Routes](https://docs.medusajs.com/api/store#gift-cards). All its method
* are available in the JS Client under the `medusa.giftCards` property.
*
* Customers can use gift cards during checkout to deduct the gift card's balance from the checkout total.
* The methods in this class allow retrieving a gift card's details by its code. A gift card can be applied to a cart using {@link CartsResource}.
*
* Related Guide: [How to use gift cards in a storefront](https://docs.medusajs.com/modules/gift-cards/storefront/use-gift-cards).
*/
declare class GiftCardsResource extends BaseResource {
/**
* Retrieve a Gift Card's details by its associated unique code.
* @param {string} code - The code of the gift card.
* @param {Record<string, any>} customHeaders - Custom headers to attach to the request.
* @returns {ResponsePromise<StoreGiftCardsRes>} Resolves to the details of the gift card.
*
* @example
* import Medusa from "@medusajs/medusa-js"
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_