@swishapp/browser
Version:
JS library to integrate Swish into a browser environment.
78 lines (77 loc) • 2 kB
TypeScript
export interface AjaxConfig {
storeDomain: string;
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
}
export interface CartLineItem {
id: number;
properties: Record<string, string> | null;
quantity: number;
variant_id: number;
key: string;
title: string;
price: number;
original_price: number;
discounted_price: number;
line_price: number;
original_line_price: number;
total_discount: number;
discounts: any[];
sku: string;
grams: number;
vendor: string;
taxable: boolean;
product_id: number;
gift_card: boolean;
final_price: number;
final_line_price: number;
url: string;
image: string;
handle: string;
requires_shipping: boolean;
product_type: string;
product_title: string;
product_description: string;
variant_title: string;
variant_options: string[];
line_level_discount_allocations: any[];
}
export interface Cart {
token: string;
note: string | null;
attributes: Record<string, string>;
original_total_price: number;
total_price: number;
total_discount: number;
total_weight: number;
item_count: number;
items: CartLineItem[];
requires_shipping: boolean;
currency: string;
items_subtotal_price: number;
cart_level_discount_applications: any[];
}
export interface AddToCartItem {
id: string;
quantity: number;
}
export interface AddToCartRequest {
items: AddToCartItem[];
}
export interface AddToCartResponse {
items: CartLineItem[];
}
export interface CartError {
message: string;
status: string;
description: string;
}
export declare class AjaxApi {
private config;
private readonly fetchConfig;
constructor(config: Pick<AjaxConfig, "fetch">);
setConfig(config: AjaxConfig): void;
private getBaseUrl;
private request;
fetchCart(): Promise<Cart>;
addToCart(request: AddToCartRequest): Promise<AddToCartResponse>;
}