ApiClient
Source: client.ts:40
The one implementation of IApiClient (@/api/client.types).
Owns everything shared by every call — the base URL, the Authorization header, rate-limit handling, error enrichment, and telling an aborted request apart from a failed one — so no endpoint method repeats it and no feature touches fetch.
Do not construct one. src/client.ts builds the single instance this page uses; ask it with getApiClient(). Twelve places used to run new ApiClient(…) themselves, which produced a dozen identical clients.
Depend on IApiClient, not on this class, wherever you only need to call the API: it is what lets a test supply a compiler-checked fake instead of mocking the module by path. The interface is intentionally not re-exported from src/index.ts — that is the frozen public surface — so import it from @/api/client.types.
Because the instance is shared, every field here must stay per-page, not per-caller. A cache, an in-flight map or an abort controller added to this class would silently be shared by every holder — that state belongs in the caller.
Constructors
new ApiClient(apiKey: string): ApiClient
Parameters
apiKey(string)
Returns
ApiClient
Implements
IApiClient
Methods
getCampaigns(currency?: string): Promise<Campaign>
Implementation of getCampaigns
The campaign, its packages and prices, optionally in a specific currency.
Parameters
currency(string, optional)
Returns
Promise<Campaign>
createCart(
data: CartBase & { currency?: string },
): Promise<Cart>
Implementation of createCart
Creates a server-side cart. Used for prospect carts and express checkout.
Parameters
data(CartBase & { currency?: string })
Returns
Promise<Cart>
calculateSummary(
data: CartCalculateSummary,
signal?: AbortSignal,
options?: { upsell?: boolean },
): Promise<CartSummary>
Implementation of calculateSummary
Prices a set of lines without creating a cart — the totals shown before checkout.
Parameters
data(CartCalculateSummary)signal(AbortSignal, optional) — Aborts a request the shopper has already superseded; the client logs an aborted request atdebugrather thanerror.options({ upsell?: boolean }, optional) —upsell: trueprices the lines as a post-purchase offer.
Properties
upsell(boolean, optional)
Returns
Promise<CartSummary>
createOrder(
data: CreateOrder & { currency?: string },
): Promise<Order>
Implementation of createOrder
Submits the order. The money path — see the checkout feature's guide.
Parameters
data(CreateOrder & { currency?: string })
Returns
Promise<Order>
getOrder(refId: string): Promise<Order>
Implementation of getOrder
Re-reads an order by its ref_id, e.g. on an upsell or confirmation page.
Parameters
refId(string)
Returns
Promise<Order>
addUpsell(refId: string, data: AddUpsellLine): Promise<Order>
Implementation of addUpsell
Adds an accepted post-purchase offer to an existing order.
Parameters
refId(string)data(AddUpsellLine)
Returns
Promise<Order>
createProspectCart(data: any): Promise<any>
Implementation of createProspectCart
Records a cart for a shopper who has given an email but not yet ordered.
Parameters
data(any)
Returns
Promise<any>
updateProspectCart(cartId: string, data: any): Promise<any>
Implementation of updateProspectCart
Parameters
cartId(string)data(any)
Returns
Promise<any>
getProspectCart(cartId: string): Promise<any>
Implementation of getProspectCart
Parameters
cartId(string)
Returns
Promise<any>
abandonProspectCart(cartId: string): Promise<any>
Implementation of abandonProspectCart
Marks the prospect cart abandoned — the signal a recovery campaign acts on.
Parameters
cartId(string)
Returns
Promise<any>
convertProspectCart(cartId: string): Promise<any>
Implementation of convertProspectCart
Marks it converted, so recovery does not chase a shopper who already bought.
Parameters
cartId(string)
Returns
Promise<any>
getAddressesAutocomplete(
query_text: string,
country?: string,
language?: string,
signal?: AbortSignal,
): Promise<any>
Implementation of getAddressesAutocomplete
Address suggestions for the checkout form, from the SDK's own provider.
Parameters
query_text(string)country(string, optional)language(string, optional)signal(AbortSignal, optional) — Aborts the previous suggestion request as the shopper keeps typing.
Returns
Promise<any>
setApiKey(apiKey: string): void
Re-keys this client in place.
Not part of IApiClient, and not for feature code. There is one client per page, so this changes the credentials of every holder at once — including holders that cached the instance and will never ask for it again. Use getApiClient(newKey) from @/client, which builds a client for that key; it reads the key back off the instance, so calling this behind its back gets the shared client replaced on the next call rather than silently reused.
Parameters
apiKey(string)
Returns
void
getApiKey(): string
Implementation of getApiKey
The key this client authenticates with.
Returns
string