@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
156 lines (155 loc) • 4.83 kB
TypeScript
import type { Gender, Order, RpcContext, ShopUser, ShopUserAddress } from '../types';
/**
* Represents a paginated API response.
*
* @template EntityType The type of entities in the response.
*/
interface PaginatedResponse<EntityType> {
entities: EntityType[];
pagination: {
current: number;
first: number;
last: number;
next: number;
page: number;
perPage: number;
prev: number;
total: number;
};
}
/**
* Represents contact data for a customer.
*/
interface ContactData {
email: string;
phone: string;
}
/**
* Represents personal data for a customer.
*/
interface PersonalData {
firstName: string;
lastName: string;
birthDate: string;
gender?: Gender;
title?: string;
}
/**
* Data required for updating a password.
*/
interface PasswordUpdate {
password: string;
newPassword: string;
}
/**
* An API client for interacting with the Checkout Customer API.
*
* Should be initialized with the token set acquired from the Auth API.
*
* @see https://scayle.dev/en/api-guides/customer-account-api/
*/
export declare class CustomerAPIClient {
/**
* Base URL for the Checkout API.
*/
baseURL: string;
/**
* RPC context containing authentication and other information.
*/
context: RpcContext;
/**
* Additional headers to include in requests.
*/
additionalHeaders: HeadersInit | undefined;
/**
* Creates a new instance of the CustomerAPIClient.
*
* @param context The RPC context.
*/
constructor(context: RpcContext);
/**
* Gets the headers for API requests, including authorization.
*/
get headers(): HeadersInit;
/**
* Sends an API request and handles potential token refresh.
*
* @param request The request function to execute.
* @param retry Whether to retry the request after a token refresh.
*
* @returns The parsed JSON response.
*
* @template BodyType The expected type of the response body.
*/
sendRequest<BodyType>(request: () => Promise<Response>, retry?: boolean): Promise<BodyType>;
/**
* Get the addresses for the current customer.
*
* @param shopId The ID of the shop.
*
* @returns A paginated response containing the customer's addresses.
*
* @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/address/list-addresses
*/
getAddresses(shopId: number): Promise<PaginatedResponse<ShopUserAddress>>;
/**
* Returns customer data and latest orders.
* When not logged in, it will return `undefined`.
*
* @param shopId The ID of the shop.
* @param accessToken Optional access token to use for the request.
* @returns The customer data.
*
* @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/get-customer
*/
getMe(shopId: number, accessToken?: string): Promise<ShopUser>;
/**
* Retrieve a customer's order.
*
* @param shopId The ID of the shop.
* @param orderId The ID of the order.
*
* @returns The customer's order.
*
* @see https://scayle.dev/en/api-guides/customer-account-api/resources/order/get-order
*/
getOrder(shopId: number, orderId: number): Promise<Order<Record<string, unknown>, Record<string, unknown>>>;
/**
* Update contact details of a customer.
*
* @param shopId The ID of the shop.
* @param data Contact data to update.
* @param data.email Customer's email address.
* @param data.phone Customer's phone number.
*
* @returns The updated customer data.
*
* @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-contact-details
*/
updateContactInfo(shopId: number, { email, phone }: Partial<ContactData>): Promise<ShopUser>;
/**
* Update customer personal data.
*
* @param shopId The ID of the shop.
* @param payload Personal data to update.
*
* @returns The updated customer data.
*
* @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-personal-data
*/
updatePersonalInfo(shopId: number, payload: Partial<PersonalData>): Promise<ShopUser>;
/**
* Update customer password.
*
* @param shopId The ID of the shop.
* @param data Data for updating the password.
* @param data.password Current password.
* @param data.newPassword New password.
*
* @returns The updated customer data.
*
* @see https://scayle.dev/en/api-guides/customer-account-api/resources/customer/update-password
*/
updatePassword(shopId: number, { password, newPassword }: PasswordUpdate): Promise<ShopUser>;
}
export {};