UNPKG

@spree/storefront-api-v2-sdk

Version:

Node module to easily integrate your JavaScript or TypeScript application with Spree Storefront API V2. You can create an entirely custom Storefront in JS/TS with this package including one page checkout, Single Page Apps, PWAs and so on.

1,582 lines (1,521 loc) 118 kB
type HttpMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'; /** * @deprecated Automatic parsing will be removed in the future to ensure the same behavior of different Fetchers. */ type AutomaticResponseParsing = 'automatic'; type ResponseParsing = AutomaticResponseParsing | 'text' | 'json' | 'stream'; type FetchConfig = { url: string; params: { [key: string]: any; }; method: HttpMethod; headers: { [key: string]: string; }; responseParsing: ResponseParsing; }; type Fetcher = { fetch: (options: FetchConfig) => Promise<{ data: any; }>; }; type CreateFetcher = (options: CreateFetcherConfig) => Fetcher; type CreateFetcherConfig = { host: string; }; type FetcherConfig = { createFetcher: CreateFetcher; }; type IClientConfig = CreateFetcherConfig & FetcherConfig; interface IEndpoints { [key: string]: any; } declare class Client$1 { protected host: string; protected fetcher: Fetcher; constructor(customOptions: IClientConfig, endpoints: IEndpoints); } // TypeScript Version: 3.0 type AxiosRequestHeaders = Record<string, string | number | boolean>; type AxiosResponseHeaders = Record<string, string> & { "set-cookie"?: string[] }; interface AxiosRequestTransformer { (data: any, headers?: AxiosRequestHeaders): any; } interface AxiosResponseTransformer { (data: any, headers?: AxiosResponseHeaders): any; } interface AxiosAdapter { (config: AxiosRequestConfig): AxiosPromise; } interface AxiosBasicCredentials { username: string; password: string; } interface AxiosProxyConfig { host: string; port: number; auth?: { username: string; password: string; }; protocol?: string; } type Method = | 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'; type ResponseType = | 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'; type responseEncoding = | 'ascii' | 'ASCII' | 'ansi' | 'ANSI' | 'binary' | 'BINARY' | 'base64' | 'BASE64' | 'base64url' | 'BASE64URL' | 'hex' | 'HEX' | 'latin1' | 'LATIN1' | 'ucs-2' | 'UCS-2' | 'ucs2' | 'UCS2' | 'utf-8' | 'UTF-8' | 'utf8' | 'UTF8' | 'utf16le' | 'UTF16LE'; interface TransitionalOptions { silentJSONParsing?: boolean; forcedJSONParsing?: boolean; clarifyTimeoutError?: boolean; } interface AxiosRequestConfig<D = any> { url?: string; method?: Method; baseURL?: string; transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[]; transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[]; headers?: AxiosRequestHeaders; params?: any; paramsSerializer?: (params: any) => string; data?: D; timeout?: number; timeoutErrorMessage?: string; withCredentials?: boolean; adapter?: AxiosAdapter; auth?: AxiosBasicCredentials; responseType?: ResponseType; responseEncoding?: responseEncoding | string; xsrfCookieName?: string; xsrfHeaderName?: string; onUploadProgress?: (progressEvent: any) => void; onDownloadProgress?: (progressEvent: any) => void; maxContentLength?: number; validateStatus?: ((status: number) => boolean) | null; maxBodyLength?: number; maxRedirects?: number; socketPath?: string | null; httpAgent?: any; httpsAgent?: any; proxy?: AxiosProxyConfig | false; cancelToken?: CancelToken; decompress?: boolean; transitional?: TransitionalOptions; signal?: AbortSignal; insecureHTTPParser?: boolean; } interface AxiosResponse<T = any, D = any> { data: T; status: number; statusText: string; headers: AxiosResponseHeaders; config: AxiosRequestConfig<D>; request?: any; } interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> { } interface Cancel { message: string | undefined; } interface CancelToken { promise: Promise<Cancel>; reason?: Cancel; throwIfRequested(): void; } type RawFetchResponse = AxiosResponse | Response | any; declare class SpreeSDKError extends Error { constructor(message: string); } declare class SpreeError extends SpreeSDKError { serverResponse: RawFetchResponse; constructor(serverResponse: RawFetchResponse); } declare class BasicSpreeError extends SpreeError { summary: string; constructor(serverResponse: RawFetchResponse, errorsSummary: string); } type FieldErrors = unknown[]; interface Errors { [key: string]: Errors | FieldErrors; } declare class ExpandedSpreeError extends BasicSpreeError { errors: Errors; constructor(serverResponse: RawFetchResponse, errorsSummary: string, errors: { [fieldPath: string]: FieldErrors; }); /** * @deprecated This method will be removed in future versions. * Use optional chaining, lodash/get, Final Form's getIn or another * 3rd party library to recreate the behavior of this method. */ getErrors(path: string[]): Errors | FieldErrors | null; } declare class MisconfigurationError extends SpreeSDKError { constructor(message: string); } declare class NoResponseError extends SpreeSDKError { constructor(); } type RawFetchRequest = Request | any; declare class FetchError extends SpreeSDKError { response?: RawFetchResponse; request?: RawFetchRequest; data?: any; constructor(response?: RawFetchResponse, request?: unknown, data?: unknown, message?: string); } declare class DocumentRelationshipError extends SpreeSDKError { constructor(message: string); } type ErrorType = 'basic' | 'full' | 'limited'; interface JsonApiDocument { id: string; type: string; attributes: any; relationships: any; } interface JsonApiResponse { data: JsonApiDocument | JsonApiDocument[]; included?: JsonApiDocument[]; } interface JsonApiListResponse extends JsonApiResponse { data: JsonApiDocument[]; meta?: { total_pages: number; total_count: number; count: number; }; } interface JsonApiSingleResponse extends JsonApiResponse { data: JsonApiDocument; } interface Result<F extends Error, S> { isSuccess(): boolean; isFail(): boolean; success(): S; fail(): F; } interface ResultResponse<SuccessType> extends Result<SpreeSDKError, SuccessType> { } /** * @deprecated Use * {@link RequiredAnyToken}, * {@link OptionalAnyToken}, * {@link RequiredAccountToken}, * {@link OptionalAccountToken} or * {@link WithCommonOptions} specific to the endpoint you're attempting to call * instead. */ interface IToken { orderToken?: string; bearerToken?: string; } type RequiredAnyToken = { order_token: string; bearer_token?: never; } | { order_token?: never; bearer_token: string; }; type OptionalAnyToken = { order_token?: string; bearer_token?: never; } | { order_token?: never; bearer_token?: string; }; type RequiredAccountToken = { bearer_token: string; }; type OptionalAccountToken = { bearer_token?: string; }; interface IOAuthToken { access_token: string; token_type: 'Bearer'; expires_in: number; refresh_token: string; created_at: number; } interface IPlatformToken { access_token: string; token_type: 'Bearer'; expires_in: number; scope: string; created_at: number; } interface IPlatformUserToken extends IPlatformToken { refresh_token: string; } interface IOAuthTokenResult extends ResultResponse<IOAuthToken> { } interface IPlatformTokenResult extends ResultResponse<IPlatformToken> { } interface IPlatformUserTokenResult extends ResultResponse<IPlatformUserToken> { } type EndpointOptions = { fetcher: Fetcher; }; declare class Http { fetcher: Fetcher; constructor({ fetcher }: EndpointOptions); protected spreeResponse<ResponseType = JsonApiResponse>(method: HttpMethod, url: string, tokens?: IToken, params?: any, responseParsing?: ResponseParsing): Promise<ResultResponse<ResponseType>>; /** * The HTTP error code returned by Spree is not indicative of its response shape. * This function determines the information provided by Spree and uses everything available. */ protected classifySpreeError(error: FetchError): ErrorType; protected processError(error: Error): SpreeSDKError; protected processSpreeError(error: FetchError): SpreeError; protected spreeOrderHeaders(tokens: IToken): { [headerName: string]: string; }; } interface RelationType { id: string; type: string; } interface IRelationships { [key: string]: { data: RelationType | RelationType[]; }; } declare const findDocument: <DocumentType_1 extends JsonApiDocument>(spreeSuccessResponse: JsonApiResponse, relationType: RelationType) => DocumentType_1; declare const findRelationshipDocuments: <DocumentType_1 extends JsonApiDocument>(spreeSuccessResponse: JsonApiResponse, sourceDocument: JsonApiDocument, relationshipName: string) => DocumentType_1[]; declare const findSingleRelationshipDocument: <DocumentType_1 extends JsonApiDocument>(spreeSuccessResponse: JsonApiResponse, sourceDocument: JsonApiDocument, relationshipName: string) => DocumentType_1; /** * Serializes object into a query string understood by Spree. * Spree uses the "brackets" format for serializing arrays which * is a different format than used by URLSearchParams. */ declare const objectToQuerystring: (source: Record<string, any>) => string; declare const makeSuccess: <F extends Error, S>(value: S) => Result<F, S>; declare const makeFail: <F extends Error, S>(value: F) => Result<F, S>; /** * Converts a Result instance into its JSON representation. * Not all information is preserved from the Result instance. * Most notably, non-enumerable properties are skipped. */ declare const toJson: <F extends Error, S>(result: Result<F, S>) => { type: string; subtype: string; value?: any; }; /** * Converts JSON to a Result instance. * If the JSON represents a fail, converts the error into an instance of SpreeSDKError its subtype. */ declare const fromJson: (json: { [key: string]: any; }) => Result<SpreeSDKError, any>; /** * If Spree returns a success response, extracts and returns its data. * Otherwise, throws the response's SpreeSDKError. Useful for handling * SpreeSDKErrors inside try..catch blocks. */ declare const extractSuccess: <ResponseType_1, T extends ResponseType_1>(spreeRequest: Promise<ResultResponse<T>>) => Promise<T>; declare const split: (source: Record<string, any>, specialKeys: string[]) => [Record<string, any>, Record<string, any>]; /** * @deprecated This function is used only to support the old method signatures * and will be removed in the future. */ declare const squashAndPreparePositionalArguments: (positionalArguments: Record<string, any>[], specialKeys: string[]) => Record<string, any> & { token: IToken; } & { params: Record<string, any>; }; type CreateFetchFetcherConfig = CreateFetcherConfig & { fetch: typeof globalThis.fetch | any; requestConstructor: typeof globalThis.Request | any; }; type CreateCustomizedFetchFetcher = (options: CreateFetchFetcherConfig) => Fetcher; type DeepAnyObject<T> = T extends (...args: any[]) => any ? T : T extends Array<infer U> ? _DeepAnyObjectArray<U> : T extends object ? _DeepAnyObjectObject<T> : T | undefined; interface _DeepAnyObjectArray<T> extends Array<DeepAnyObject<T>> { } type _DeepAnyObjectObject<T> = { [P in keyof T]: DeepAnyObject<T[P]>; } & Record<string, any>; type EmptyObjectResponse = Record<string, never>; interface EmptyObjectResult extends ResultResponse<EmptyObjectResponse> { } type ImageTransformation = { size?: string; quality?: number; }; interface LocalizedSlugs { [key: string]: string; } type NoContentResponse = ''; interface NoContentResult extends ResultResponse<NoContentResponse> { } interface IQuery { currency?: string; locale?: string; include?: string; fields?: { [key: string]: string; }; filter?: { [key: string]: number | string; }; page?: number; per_page?: number; sort?: string; [customSpreeExtensionKey: string]: any; } /** * @deprecated Use {@link ListOptions} instead. */ interface IProductsQuery extends IQuery { image_transformation?: { size?: string; quality?: number; }; } type AllowedCustomizations = { suggestToken: boolean; suggestQuery: boolean; optionalToken: boolean; onlyAccountToken: boolean; }; type DefaultCustomizations = AllowedCustomizations & { suggestToken: false; suggestQuery: false; optionalToken: false; onlyAccountToken: false; }; type WithCommonOptions<CustomizationsOrNull extends Partial<AllowedCustomizations> | null = Partial<AllowedCustomizations> | null, CustomOptions extends Record<string, any> = Record<string, any>, Customizations extends CustomizationsOrNull extends null ? Record<string, unknown> : CustomizationsOrNull = CustomizationsOrNull extends null ? Record<string, unknown> : CustomizationsOrNull, IntersectedCustomizations extends Customizations & DefaultCustomizations = Customizations & DefaultCustomizations, FinalCustomizations extends { [P in keyof AllowedCustomizations]: IntersectedCustomizations[P] extends never ? Customizations[P] : DefaultCustomizations[P]; } = { [P in keyof AllowedCustomizations]: IntersectedCustomizations[P] extends never ? Customizations[P] : DefaultCustomizations[P]; }> = DeepAnyObject<((FinalCustomizations['suggestToken'] extends true ? FinalCustomizations['onlyAccountToken'] extends true ? FinalCustomizations['optionalToken'] extends true ? OptionalAccountToken : RequiredAccountToken : FinalCustomizations['optionalToken'] extends true ? OptionalAnyToken : RequiredAnyToken : Record<string, unknown>) & (FinalCustomizations['suggestQuery'] extends true ? IQuery : Record<string, unknown>)) & CustomOptions>; declare const storefrontPath = "api/v2/storefront"; declare const endpoints$1: { productsPath: () => string; productPath: (id: string) => string; taxonsPath: () => string; taxonPath: (id: string) => string; countriesPath: () => string; countryPath: (iso: string) => string; cartPath: () => string; cartAddItemPath: () => string; cartRemoveItemPath: (id: string) => string; cartEmptyPath: () => string; cartSetItemQuantity: () => string; cartApplyCodePath: () => string; cartRemoveCodePath: (code?: string) => string; cartRemoveAllCoupons: () => string; /** * @deprecated Use {@link cartEstimateShippingRatesPath} instead. */ cartEstimateShippingMethodsPath: () => string; cartEstimateShippingRatesPath: () => string; cartAssociatePath: () => string; cartChangeCurrencyPath: () => string; checkoutPath: () => string; checkoutNextPath: () => string; checkoutAdvancePath: () => string; checkoutCompletePath: () => string; checkoutAddStoreCreditsPath: () => string; checkoutRemoveStoreCreditsPath: () => string; checkoutPaymentMethodsPath: () => string; /** * @deprecated Use {@link checkoutShippingRatesPath} instead. */ checkoutShippingMethodsPath: () => string; checkoutShippingRatesPath: () => string; checkoutSelectShippingMethodPath: () => string; checkoutAddPaymentPath: () => string; checkoutCreateStripeSessionPath: () => string; oauthTokenPath: () => string; oauthRevokePath: () => string; accountPath: () => string; accountAddressPath: (id: string) => string; accountAddressesPath: () => string; accountAddressRemovePath: (id: string) => string; accountConfirmPath: (confirmationToken: string) => string; accountCreditCardsPath: () => string; accountDefaultCreditCardPath: () => string; accountCreditCardRemovePath: (id: string) => string; accountCompletedOrdersPath: () => string; accountCompletedOrderPath: (orderNumber: string) => string; forgotPasswordPath: () => string; resetPasswordPath: (resetPasswordToken: string) => string; orderStatusPath: (orderNumber: string) => string; pagesPath: () => string; pagePath: (id: string) => string; defaultCountryPath: () => string; digitalAssetsDownloadPath: (token: string) => string; menusPath: () => string; menuPath: (id: string) => string; wishlistsPath: () => string; wishlistPath: (token: string) => string; defaultWishlistPath: () => string; wishlistsAddWishedItemPath: (token: string) => string; wishlistsUpdateWishedItemQuantityPath: (token: string, id: string) => string; wishlistsRemoveWishedItemPath: (token: string, id: string) => string; vendorsPath: () => string; vendorPath: (id: string) => string; }; interface IAddress { firstname: string; lastname: string; address1: string; address2?: string; city: string; zipcode: string; state_name: string; country_iso: string; phone?: string; company?: string; } interface AccountAttr extends JsonApiDocument { data: { id: string; type: string; attributes: { email: string; store_credits: number; completed_orders: number; }; relationships: IRelationships; }; } interface IAccount extends JsonApiSingleResponse { data: AccountAttr; } interface IAccountResult extends ResultResponse<IAccount> { } interface IAccountConfirmation { data: { state: string; }; } interface IAccountConfirmationResult extends ResultResponse<IAccountConfirmation> { } /** * @deprecated Use {@link ForgotPasswordOptions} instead. */ interface ForgotPasswordParams extends IQuery { user: { email: string; }; } /** * @deprecated Use {@link ResetPasswordOptions} instead. */ interface ResetPasswordParams extends IQuery { user: { password: string; password_confirmation: string; }; } /** * @deprecated Use {@link CreateAddressOptions} instead. */ interface AccountAddressParams extends IQuery { address: IAddress; } interface AccountAddressAttr extends JsonApiDocument { attributes: IAddress; } interface AccountAddressResponse extends JsonApiSingleResponse { data: AccountAddressAttr; } interface AccountAddressesResponse extends JsonApiListResponse { data: AccountAddressAttr[]; } interface AccountAddressResult extends ResultResponse<AccountAddressResponse> { } interface AccountAddressesResult extends ResultResponse<AccountAddressesResponse> { } type AccountInfoOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }>; type CreditCardsListOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; suggestQuery: true; }>; type DefaultCreditCardOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; suggestQuery: true; }>; type RemoveCreditCardOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; suggestQuery: true; }, { id: string; }>; type CompletedOrdersListOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; suggestQuery: true; }>; type CompletedOrderOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; suggestQuery: true; }, { order_number: string; }>; type CreateOptions$2 = WithCommonOptions<null, { user: { email: string; password: string; password_confirmation: string; first_name?: string; last_name?: string; public_metadata?: { [key: string]: string; }; private_metadata?: { [key: string]: string; }; }; }>; type ConfirmOptions = WithCommonOptions<null, { confirmation_token: string; }>; type ForgotPasswordOptions = WithCommonOptions<null, ForgotPasswordParams>; type ResetPasswordOptions = WithCommonOptions<null, ResetPasswordParams & { reset_password_token: string; }>; type UpdateOptions$1 = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; }, { user: { email: string; password?: string; password_confirmation?: string; first_name?: string; last_name?: string; bill_address_id?: string; ship_address_id?: string; public_metadata?: { [key: string]: string; }; private_metadata?: { [key: string]: string; }; }; }>; type AddressesListOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; }>; type ShowAddressOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; suggestQuery: true; }, { id: string; }>; type CreateAddressOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; suggestQuery: true; }, AccountAddressParams>; type RemoveAddressOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; }, { id: string; }>; type UpdateAddressOptions = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; }, AccountAddressParams & { id: string; }>; interface CreditCardAttr extends JsonApiDocument { type: string; id: string; attributes: { cc_type: string; last_digits: string; month: number; year: number; name: string; default: boolean; }; relationships: IRelationships; } interface ICreditCard extends JsonApiSingleResponse { data: CreditCardAttr; } interface ICreditCards extends JsonApiListResponse { data: CreditCardAttr[]; } interface ICreditCardResult extends ResultResponse<ICreditCard> { } interface ICreditCardsResult extends ResultResponse<ICreditCards> { } interface OrderAttr extends JsonApiDocument { type: string; id: string; attributes: { number: string; item_total: string; total: string; ship_total: string; adjustment_total: string; included_tax_total: string; additional_tax_total: string; display_additional_tax_total: string; display_included_tax_total: string; tax_total: string; currency: string; state: string; token: string; email: string; display_item_total: string; display_ship_total: string; display_adjustment_total: string; display_tax_total: string; promo_total: string; display_promo_total: string; item_count: number; special_instructions: string; display_total: string; created_at: Date; updated_at: Date; completed_at: Date; }; relationships: IRelationships; } interface IOrder extends JsonApiSingleResponse { data: OrderAttr; } interface IOrders extends JsonApiListResponse { data: OrderAttr[]; } interface IOrderResult extends ResultResponse<IOrder> { } interface IOrdersResult extends ResultResponse<IOrders> { } type StatusOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, { order_number: string; }>; declare class Account extends Http { /** * Creates new account and returns its attributes. See [api docs](https://api.spreecommerce.org/docs/api-v2/534a12ece987f-create-an-account). * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.create({ * user: { * email: 'john@snow.org', * password: 'spree123', * password_confirmation: 'spree123' * } * }) * ``` */ create(options: CreateOptions$2): Promise<IAccountResult>; /** * @hidden * @deprecated Use the combined options signature instead. * Creates new account and returns its attributes. */ create(params: IQuery): Promise<IAccountResult>; /** * Confirms new account e-mail and returns account registration status. See [reference](https://github.com/spree/spree_auth_devise/blob/db4ccf202f42cdb713931e9915b213ab9c9b2062/config/routes.rb). * * **Success response schema:** * ```ts * { * data: { * state: string * } * } * ``` * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.confirm({ confirmation_token: '2xssfC9Hzf8DJXyRZGmB' }) * ``` */ confirm(option: ConfirmOptions): Promise<IAccountConfirmationResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ confirm(confirmationToken: string): Promise<IAccountConfirmationResult>; /** * Sends an account recovery link to the provided email address. The link allows resetting the password for the account. * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.forgotPassword({ * user: { * email: 'spree@example.com' * } * }) * ``` */ forgotPassword(options: ForgotPasswordOptions): Promise<NoContentResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ forgotPassword(params: ForgotPasswordParams): Promise<NoContentResult>; /** * Changes the password associated with the account using an account recovery token. * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.resetPassword({ * reset_password_token: '7381273269536713689562374856', * user: { * password: '123!@#asdASD', * password_confirmation: '123!@#asdASD' * } * }) * ``` */ resetPassword(options: ResetPasswordOptions): Promise<NoContentResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ resetPassword(resetPasswordToken: string, params: ResetPasswordParams): Promise<NoContentResult>; /** * Updates account and returns its attributes. See [api docs](https://api.spreecommerce.org/docs/api-v2/9f8e112bbb91f-update-an-account). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.update({ * bearer_token: '7381273269536713689562374856', * user: { * email: 'john@snow.org', * password: 'new_spree123', * password_confirmation: 'new_spree123' * } * }) * ``` */ update(options: UpdateOptions$1): Promise<IAccountResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ update(token: IToken, params: IQuery): Promise<IAccountResult>; /** * Returns current user information. See [api docs](https://api.spreecommerce.org/docs/api-v2/a531029531471-retrieve-an-account). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.accountInfo({ bearer_token: '7381273269536713689562374856' }) * ``` */ accountInfo(options: AccountInfoOptions): Promise<IAccountResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ accountInfo(token: IToken, params?: IQuery): Promise<IAccountResult>; /** * Returns a list of Credit Cards for the signed in User. See [api docs](https://api.spreecommerce.org/docs/api-v2/eae76f03a90db-list-all-credit-cards). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.creditCardsList({ bearer_token: '7381273269536713689562374856' }) * ``` */ creditCardsList(options: CreditCardsListOptions): Promise<ICreditCardsResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ creditCardsList(token: IToken, params?: IQuery): Promise<ICreditCardsResult>; /** * Return the User's default Credit Card. See [api docs](https://api.spreecommerce.org/docs/api-v2/1054d9230daf4-retrieve-the-default-credit-card). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.defaultCreditCard({ bearer_token: '7381273269536713689562374856' }) * ``` */ defaultCreditCard(options: DefaultCreditCardOptions): Promise<ICreditCardResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ defaultCreditCard(token: IToken, params?: IQuery): Promise<ICreditCardResult>; /** * Remove a User's Credit Card. See [api docs](https://api.spreecommerce.org/docs/api-v2/b3A6MTc1NjU3NDM-remove-a-credit-card). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.removeCreditCard({ * bearer_token: '7381273269536713689562374856', * id: '14' * }) * ``` */ removeCreditCard(options: RemoveCreditCardOptions): Promise<NoContentResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ removeCreditCard(token: IToken, id: string, params?: IQuery): Promise<NoContentResult>; /** * Returns Orders placed by the User. Only completed ones. See [api docs](https://api.spreecommerce.org/docs/api-v2/94d319dfe8909-list-all-orders). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.completedOrdersList({ * bearer_token: '7381273269536713689562374856' * }) * ``` */ completedOrdersList(options: CompletedOrdersListOptions): Promise<IOrdersResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ completedOrdersList(token: IToken, params?: IQuery): Promise<IOrdersResult>; /** * Return the User's completed Order. See [api docs](https://api.spreecommerce.org/docs/api-v2/ab4c5da10fbba-retrieve-an-order). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.completedOrder({ * bearer_token: '7381273269536713689562374856', * order_number: 'R653163382' * }) * ``` */ completedOrder(options: CompletedOrderOptions): Promise<IOrderResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ completedOrder(token: IToken, orderNumber: string, params?: IQuery): Promise<IOrderResult>; /** * Returns a list of Addresses for the signed in User. See [api docs](https://api.spreecommerce.org/docs/api-v2/c8ebb212f75bf-list-all-addresses). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.addressesList({ * bearer_token: '7381273269536713689562374856' * }) * ``` */ addressesList(options: AddressesListOptions): Promise<AccountAddressesResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ addressesList(token: IToken): Promise<AccountAddressesResult>; /** * Returns a single address for the signed in User. * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.showAddress({ * bearer_token: '7381273269536713689562374856', * id: '1' * }) * ``` */ showAddress(options: ShowAddressOptions): Promise<AccountAddressResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ showAddress(token: IToken, addressId: string, params?: IQuery): Promise<AccountAddressResult>; /** * Create a new Address for the signed in User. See [api docs](https://api.spreecommerce.org/docs/api-v2/daacab4666dfc-create-an-address). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Options schema:** * ```ts * interface options { * address: { * firstname: string * lastname: string * address1: string * address2?: string * city: string * phone?: string * zipcode: string * state_name: string // State Abbreviations * country_iso: string // Country ISO (2-chars) or ISO3 (3-chars) * company?: string * } * } * ``` * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.createAddress({ * bearer_token: '7381273269536713689562374856', * address: { * firstname: 'John', * lastname: 'Snow', * address1: '7735 Old Georgetown Road', * address2: '2nd Floor', * city: 'Bethesda', * phone: '3014445002', * zipcode: '20814', * state_name: 'MD', * country_iso: 'US', * company: 'Spark' * } * }) * ``` */ createAddress(options: CreateAddressOptions): Promise<AccountAddressResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ createAddress(token: IToken, params: AccountAddressParams): Promise<AccountAddressResult>; /** * Removes selected Address for the signed in User. See [api docs](https://api.spreecommerce.org/docs/api-v2/b3A6MTAwNjA3Njg-remove-an-address). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.removeAddress({ * bearer_token: '7381273269536713689562374856', * id: '1' * }) * ``` */ removeAddress(options: RemoveAddressOptions): Promise<NoContentResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ removeAddress(token: IToken, id: string, params?: IQuery): Promise<NoContentResult>; /** * Update selected Address for the signed in User. See [api docs](https://api.spreecommerce.org/docs/api-v2/fbae19a10190d-update-an-address). * * Required token: Bearer token * * **Options schema:** * ```ts * interface options { * id: string * address: { * firstname: string * lastname: string * address1: string * address2?: string * city: string * phone?: string * zipcode: string * state_name: string // State Abbreviations * country_iso: string // Country ISO (2-chars) or ISO3 (3-chars) * company?: string * } * } * ``` * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.account.updateAddress({ * bearer_token: '7381273269536713689562374856', * id: '1', * address: { * firstname: 'John', * lastname: 'Snow', * address1: '7735 Old Georgetown Road', * address2: '2nd Floor', * city: 'Bethesda', * phone: '3014445002', * zipcode: '20814', * state_name: 'MD', * country_iso: 'US', * company: 'Spark' * } * }) * ``` */ updateAddress(options: UpdateAddressOptions): Promise<AccountAddressResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ updateAddress(token: IToken, addressId: string, params: AccountAddressParams): Promise<AccountAddressResult>; } interface AuthTokenAttr { username: string; password: string; } interface RefreshTokenAttr { refresh_token: string; } interface RevokeTokenAttr { token: string; } interface AuthTokenParams { username: string; password: string; grant_type: 'password'; } interface RefreshTokenParams { refresh_token: string; grant_type: 'refresh_token'; } interface RevokeTokenParams { token: string; } type GetTokenOptions = WithCommonOptions<null, AuthTokenAttr>; type RefreshTokenOptions = WithCommonOptions<null, RefreshTokenAttr>; type RevokeTokenOptions = WithCommonOptions<null, RevokeTokenAttr>; declare class Authentication extends Http { /** * Creates a [Bearer token](../pages/tokens.html#bearer-token) required to authorize OAuth API calls. * * **Success response schema:** * ```ts * interface res { * access_token: string * token_type: string = 'Bearer' * expires_in: number * refresh_token: string * created_at: number * } * ``` * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const token = await client.authentication.getToken({ * username: 'spree@example.com', * password: 'spree123' * }) * ``` */ getToken(options: GetTokenOptions): Promise<IOAuthTokenResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ getToken(params: AuthTokenAttr): Promise<IOAuthTokenResult>; /** * Refreshes the [Bearer token](../pages/tokens.html#bearer-token) required to authorize OAuth API calls. * * **Success response schema:** * ```ts * interface res { * access_token: string * token_type: string = 'Bearer' * expires_in: number * refresh_token: string * created_at: number * } * ``` * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const token = await client.authentication.refreshToken({ * refresh_token: 'aebe2886d7dbba6f769e20043e40cfa3447e23ad9d8e82c632f60ed63a2f0df1' * }) * ``` */ refreshToken(options: RefreshTokenOptions): Promise<IOAuthTokenResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ refreshToken(params: RefreshTokenAttr): Promise<IOAuthTokenResult>; /** * Revokes a [Bearer token (access token)](../pages/tokens.html#bearer-token) or a refresh token. * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * const response = await client.authentication.revokeToken({ * token: 'aebe2886d7dbba6f769e20043e40cfa3447e23ad9d8e82c632f60ed63a2f0df1' * }) * ``` */ revokeToken(optons: RevokeTokenOptions): Promise<EmptyObjectResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ revokeToken(params: RevokeTokenAttr): Promise<EmptyObjectResult>; } /** * @deprecated Use {@link AddItemOptions} instead. */ interface AddItem extends IQuery { variant_id: string; quantity: number; options?: { [key: string]: string; }; } /** * @deprecated Use {@link SetQuantityOptions} instead. */ interface SetQuantity extends IQuery { line_item_id: string; quantity: number; } /** * @deprecated Use {@link ApplyCouponCodeOptions} instead. */ interface CouponCode extends IQuery { coupon_code: string; } /** * @deprecated Use {@link EstimateShippingRates} instead. */ interface EstimateShippingMethods extends IQuery { country_iso: string; } /** * @deprecated Use {@link EstimateShippingRatesOptions} instead. */ interface EstimateShippingRates extends IQuery { country_iso: string; } /** * @deprecated Use {@link AssociateGuestCartOptions} instead. */ interface AssociateCart extends IQuery { guest_order_token: string; } /** * @deprecated Use {@link ChangeCurrencyOptions} instead. */ interface ChangeCurrency extends IQuery { new_currency: string; } interface EstimatedShippingMethodAttr extends JsonApiDocument { type: 'shipping_rate'; id: string; attributes: { name: string; selected: boolean; cost: string; tax_amount: string; shipping_method_id: number; final_price: string; display_cost: string; display_final_price: string; display_tax_amount: string; free: boolean; }; } /** * @deprecated Use {@link EstimatedShippingRates} instead. */ interface IEstimatedShippingMethods extends JsonApiListResponse { data: EstimatedShippingMethodAttr[]; } /** * @deprecated Use {@link EstimatedShippingRatesResult} instead. */ interface IEstimatedShippingMethodsResult extends ResultResponse<IEstimatedShippingMethods> { } interface EstimatedShippingRates extends JsonApiListResponse { data: EstimatedShippingMethodAttr[]; } interface EstimatedShippingRatesResult extends ResultResponse<EstimatedShippingRates> { } type ShowOptions$7 = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }>; type CreateOptions$1 = WithCommonOptions<{ suggestToken: true; onlyAccountToken: true; optionalToken: true; suggestQuery: true; }>; type AddItemOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, AddItem>; type RemoveItemOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, { id: string; }>; type EmptyCartOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }>; type RemoveOptions$1 = WithCommonOptions<{ suggestToken: true; }>; type SetQuantityOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, SetQuantity>; type ApplyCouponCodeOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, CouponCode>; type RemoveCouponCodeOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, { code?: string; }>; type RemoveAllCouponsOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }>; type EstimateShippingRatesOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, EstimateShippingRates>; type AssociateGuestCartOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, AssociateCart>; type ChangeCurrencyOptions = WithCommonOptions<{ suggestToken: true; suggestQuery: true; }, ChangeCurrency>; declare class Cart extends Http { /** * Creates a new Cart and returns its attributes. See [api docs](https://api.spreecommerce.org/docs/api-v2/6a57a5a49594f-create-a-cart). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) - if logged in user * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * // Logged in user * const response = await client.cart.create({ * bearer_token: '7381273269536713689562374856' * }) * * // or guest user * const response = await client.cart.create() * ``` */ create(options?: CreateOptions$1): Promise<IOrderResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ create(token?: IToken, params?: IQuery): Promise<IOrderResult>; /** * Returns contents of the cart. See [api docs](https://api.spreecommerce.org/docs/api-v2/b3A6MzE0Mjc0Ng-retrieve-a-cart). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) or [Order token](../pages/tokens.html#order-token) * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * // Logged in user * const response = await client.cart.show({ * bearer_token: '7381273269536713689562374856' * }) * * // or guest user * const response = await client.cart.show({ * order_token: '7381273269536713689562374856' * }) * ``` */ show(options: ShowOptions$7): Promise<IOrderResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ show(token: IToken, params?: IQuery): Promise<IOrderResult>; /** * Adds a Product Variant to the Cart. See [api docs](https://api.spreecommerce.org/docs/api-v2/b3A6MzE0Mjc0Nw-add-an-item-to-cart). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) or [Order token](../pages/tokens.html#order-token) * * **Options schema:** * ```ts * interface options { * variant_id: string * quantity: number * options?: { * [key: string]: string * } * } * ``` * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * // Logged in user * const response = await client.cart.addItem({ * bearer_token: '7381273269536713689562374856', * variant_id: '1', * quantity: 1 * }) * * // or guest user * const response = await client.cart.addItem({ * order_token: '7381273269536713689562374856', * variant_id: '1', * quantity: 1 * }) * ``` */ addItem(options: AddItemOptions): Promise<IOrderResult>; /** * @hidden * @deprecated Use the combined options signature instead. */ addItem(token: IToken, params: AddItem): Promise<IOrderResult>; /** * Sets the quantity of a given line item. It has to be a positive integer greater than 0. See [api docs](https://api.spreecommerce.org/docs/api-v2/b3A6MzE0Mjc0OA-set-line-item-quantity). * * **Required token:** [Bearer token](../pages/tokens.html#bearer-token) or [Order token](../pages/tokens.html#order-token) * * **Options schema:** * ```ts * interface options { * line_item_id: string * quantity: number * } * ``` * * **Success response schema:** [Success schema](../pages/response-schema.html#success-schema) * * **Failure response schema:** [Error schema](../pages/response-schema.html#error-schema) * * **Example:** * ```ts * // Logged in u