@easy-cms/plugin-ecommerce 0.0.0-stage → 0.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/admin.js +62 -0
- package/dist/chunk-KON3VWC6.js +302 -0
- package/dist/chunk-RRF3IDUV.js +1937 -0
- package/dist/client.d.ts +250 -0
- package/dist/client.js +18 -0
- package/dist/index.d.ts +530 -0
- package/dist/index.js +44 -0
- package/dist/payments-tPD3bTTW.d.ts +213 -0
- package/dist/react.d.ts +95 -0
- package/dist/react.js +170 -0
- package/dist/stripe.d.ts +58 -0
- package/dist/stripe.js +90 -0
- package/dist/vue.d.ts +119 -0
- package/dist/vue.js +179 -0
- package/package.json +84 -4
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
type ID$1 = string | number;
|
|
2
|
+
/** A currency prices are given in. Amounts are whole numbers of its smallest unit (satang, cents). */
|
|
3
|
+
interface Currency {
|
|
4
|
+
/** ISO 4217, e.g. `THB`. */
|
|
5
|
+
readonly code: string;
|
|
6
|
+
/** e.g. `฿`. */
|
|
7
|
+
readonly symbol: string;
|
|
8
|
+
readonly label: string;
|
|
9
|
+
/** Digits after the point: 2 for THB (1 baht = 100 satang), 0 for JPY. */
|
|
10
|
+
readonly decimals: number;
|
|
11
|
+
}
|
|
12
|
+
/** Currencies to choose from by code; others are given in full. */
|
|
13
|
+
declare const CURRENCIES: Readonly<Record<string, Currency>>;
|
|
14
|
+
/** The field holding a product's or variant's price in a currency, e.g. `priceInTHB`. */
|
|
15
|
+
declare const priceField: (code: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* An amount in a currency's smallest unit, for people: `formatPrice(123450, THB)` →
|
|
18
|
+
* `฿1,234.50`. `locale` picks the digits and separators (default `en`).
|
|
19
|
+
*/
|
|
20
|
+
declare function formatPrice(amount: number, currency: Currency, locale?: string): string;
|
|
21
|
+
/** Where an order is in its life. */
|
|
22
|
+
declare const ORDER_STATUSES: readonly ["pending", "paid", "fulfilled", "cancelled", "refunded"];
|
|
23
|
+
/**
|
|
24
|
+
* - `pending`: waiting for payment (bank transfer).
|
|
25
|
+
* - `paid`: paid, to be sent.
|
|
26
|
+
* - `fulfilled`: sent or handed over.
|
|
27
|
+
* - `cancelled`: called off before payment.
|
|
28
|
+
* - `refunded`: the money went back.
|
|
29
|
+
*/
|
|
30
|
+
type OrderStatus = (typeof ORDER_STATUSES)[number];
|
|
31
|
+
/** Where a payment is. */
|
|
32
|
+
declare const TRANSACTION_STATUSES: readonly ["pending", "processing", "succeeded", "failed", "refunded"];
|
|
33
|
+
type TransactionStatus = (typeof TRANSACTION_STATUSES)[number];
|
|
34
|
+
/** An addition to or deduction from a cart's total (a negative amount), e.g. shipping or a discount. */
|
|
35
|
+
interface Adjustment {
|
|
36
|
+
readonly label: string;
|
|
37
|
+
readonly amount: number;
|
|
38
|
+
}
|
|
39
|
+
/** A line of a cart, as pages see it. */
|
|
40
|
+
interface CartLine {
|
|
41
|
+
/** The line's id, for changing or removing it. */
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly product: {
|
|
44
|
+
readonly id: ID$1;
|
|
45
|
+
readonly title: string;
|
|
46
|
+
readonly slug: string | null;
|
|
47
|
+
/** The first image's URL. */
|
|
48
|
+
readonly image: string | null;
|
|
49
|
+
};
|
|
50
|
+
readonly variant: {
|
|
51
|
+
readonly id: ID$1;
|
|
52
|
+
readonly title: string;
|
|
53
|
+
} | null;
|
|
54
|
+
readonly quantity: number;
|
|
55
|
+
/** Price of one, in the cart's currency; `null` when it has no price there. */
|
|
56
|
+
readonly unitPrice: number | null;
|
|
57
|
+
readonly total: number;
|
|
58
|
+
/** Whether it can be bought as it is: priced, in stock, still for sale. */
|
|
59
|
+
readonly available: boolean;
|
|
60
|
+
/** How many are left, when stock is kept; `null` otherwise. */
|
|
61
|
+
readonly stock: number | null;
|
|
62
|
+
}
|
|
63
|
+
/** A cart, as pages see it. */
|
|
64
|
+
interface CartView {
|
|
65
|
+
readonly id: ID$1;
|
|
66
|
+
readonly currency: string;
|
|
67
|
+
readonly lines: readonly CartLine[];
|
|
68
|
+
/** How many items, counting quantities. */
|
|
69
|
+
readonly count: number;
|
|
70
|
+
readonly subtotal: number;
|
|
71
|
+
/** From the shop's `totals` (shipping, tax, discounts), without an address yet. */
|
|
72
|
+
readonly adjustments: readonly Adjustment[];
|
|
73
|
+
readonly total: number;
|
|
74
|
+
}
|
|
75
|
+
/** What `GET <api>/shop/config` tells pages. */
|
|
76
|
+
interface ShopSettings {
|
|
77
|
+
readonly currencies: readonly Currency[];
|
|
78
|
+
readonly defaultCurrency: string;
|
|
79
|
+
readonly paymentMethods: readonly {
|
|
80
|
+
readonly name: string;
|
|
81
|
+
readonly label: string;
|
|
82
|
+
}[];
|
|
83
|
+
readonly guests: boolean;
|
|
84
|
+
readonly countries: readonly string[];
|
|
85
|
+
}
|
|
86
|
+
/** A postal address, as stored on addresses and orders. */
|
|
87
|
+
interface Address {
|
|
88
|
+
readonly name?: string | null;
|
|
89
|
+
readonly phone?: string | null;
|
|
90
|
+
readonly line1?: string | null;
|
|
91
|
+
readonly line2?: string | null;
|
|
92
|
+
/** Sub-district (แขวง / ตำบล). */
|
|
93
|
+
readonly subdistrict?: string | null;
|
|
94
|
+
/** District (เขต / อำเภอ). */
|
|
95
|
+
readonly district?: string | null;
|
|
96
|
+
readonly province?: string | null;
|
|
97
|
+
readonly postalCode?: string | null;
|
|
98
|
+
/** ISO 3166-1 alpha-2, e.g. `TH`. */
|
|
99
|
+
readonly country?: string | null;
|
|
100
|
+
readonly [field: string]: unknown;
|
|
101
|
+
}
|
|
102
|
+
/** What starting a checkout returns to the page. */
|
|
103
|
+
interface CheckoutResult {
|
|
104
|
+
readonly transaction: ID$1;
|
|
105
|
+
/** What the payment method needs on the page, e.g. Stripe's client secret. */
|
|
106
|
+
readonly payment: Readonly<Record<string, unknown>>;
|
|
107
|
+
/** Set when the order exists already, e.g. paid later by bank transfer. */
|
|
108
|
+
readonly order: {
|
|
109
|
+
readonly id: ID$1;
|
|
110
|
+
readonly orderNumber: string;
|
|
111
|
+
readonly status: OrderStatus;
|
|
112
|
+
} | null;
|
|
113
|
+
}
|
|
114
|
+
/** What confirming a payment returns. */
|
|
115
|
+
interface ConfirmResult {
|
|
116
|
+
readonly status: TransactionStatus;
|
|
117
|
+
readonly order: {
|
|
118
|
+
readonly id: ID$1;
|
|
119
|
+
readonly orderNumber: string;
|
|
120
|
+
readonly status: OrderStatus;
|
|
121
|
+
} | null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The shop for pages, without a framework: cart, customer, checkout, addresses and orders over
|
|
126
|
+
* the REST API, with a guest's cart kept in `localStorage`. `/react` and `/vue` wrap it.
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
type ID = string | number;
|
|
130
|
+
interface ShopClientOptions {
|
|
131
|
+
/** Where the CMS's REST API is. Default `/api/cms`. */
|
|
132
|
+
readonly api?: string;
|
|
133
|
+
/** Where a guest's cart is remembered. Default `localStorage` in a browser; `null` for none. */
|
|
134
|
+
readonly storage?: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'> | null;
|
|
135
|
+
/** The key under which it is remembered. Default `easy-cms-cart`. */
|
|
136
|
+
readonly storageKey?: string;
|
|
137
|
+
/** `en` or `th`: the language of emails and messages. Default `en`. */
|
|
138
|
+
readonly locale?: string;
|
|
139
|
+
readonly fetch?: typeof fetch;
|
|
140
|
+
}
|
|
141
|
+
/** The signed-in customer (or staff member). */
|
|
142
|
+
interface ShopUser {
|
|
143
|
+
readonly id: ID;
|
|
144
|
+
readonly email: string;
|
|
145
|
+
readonly name?: string | null;
|
|
146
|
+
readonly role: string;
|
|
147
|
+
readonly [field: string]: unknown;
|
|
148
|
+
}
|
|
149
|
+
interface ShopState {
|
|
150
|
+
readonly settings: ShopSettings | null;
|
|
151
|
+
readonly user: ShopUser | null;
|
|
152
|
+
readonly cart: CartView | null;
|
|
153
|
+
/** True until `load()` finishes the first time. */
|
|
154
|
+
readonly loading: boolean;
|
|
155
|
+
/** Waiting for the server, e.g. while adding to the cart. */
|
|
156
|
+
readonly busy: boolean;
|
|
157
|
+
}
|
|
158
|
+
/** An error from the API: its message and, for invalid input, which fields and why. */
|
|
159
|
+
declare class ShopError extends Error {
|
|
160
|
+
readonly status: number;
|
|
161
|
+
readonly errors: readonly {
|
|
162
|
+
field: string;
|
|
163
|
+
message: string;
|
|
164
|
+
}[];
|
|
165
|
+
constructor(message: string, status: number, errors?: readonly {
|
|
166
|
+
field: string;
|
|
167
|
+
message: string;
|
|
168
|
+
}[]);
|
|
169
|
+
}
|
|
170
|
+
interface ShopClient {
|
|
171
|
+
getState(): ShopState;
|
|
172
|
+
/** Calls `listener` after every change; returns the way to stop. */
|
|
173
|
+
subscribe(listener: (state: ShopState) => void): () => void;
|
|
174
|
+
/** Loads the shop's settings, the customer and the cart. Call once on start. */
|
|
175
|
+
load(): Promise<void>;
|
|
176
|
+
/** The cart again from the server. */
|
|
177
|
+
refreshCart(): Promise<CartView | null>;
|
|
178
|
+
addItem(product: ID, options?: {
|
|
179
|
+
variant?: ID | null;
|
|
180
|
+
quantity?: number;
|
|
181
|
+
}): Promise<CartView>;
|
|
182
|
+
/** Sets a line's quantity; 0 removes it. */
|
|
183
|
+
updateItem(line: string, quantity: number): Promise<CartView>;
|
|
184
|
+
incrementItem(line: string): Promise<CartView>;
|
|
185
|
+
decrementItem(line: string): Promise<CartView>;
|
|
186
|
+
removeItem(line: string): Promise<CartView>;
|
|
187
|
+
clearCart(): Promise<CartView | null>;
|
|
188
|
+
setCurrency(code: string): Promise<CartView>;
|
|
189
|
+
/** The cart's currency, or the shop's default. */
|
|
190
|
+
currency(): Currency | null;
|
|
191
|
+
/** An amount for people, in the cart's currency or `code`'s. */
|
|
192
|
+
formatPrice(amount: number, code?: string): string;
|
|
193
|
+
/** Signs in; a guest's cart joins the customer's. */
|
|
194
|
+
login(email: string, password: string): Promise<ShopUser>;
|
|
195
|
+
logout(): Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Creates an account. With email confirmation (the default) resolves `{ verify: true }`: a link
|
|
198
|
+
* is on its way; otherwise signs in.
|
|
199
|
+
*/
|
|
200
|
+
signup(data: {
|
|
201
|
+
email: string;
|
|
202
|
+
password: string;
|
|
203
|
+
name?: string;
|
|
204
|
+
turnstile?: string;
|
|
205
|
+
}): Promise<{
|
|
206
|
+
verify: boolean;
|
|
207
|
+
}>;
|
|
208
|
+
/** Confirms the email from the link's `token`, and signs in. */
|
|
209
|
+
verifyEmail(token: string): Promise<ShopUser>;
|
|
210
|
+
forgotPassword(email: string): Promise<void>;
|
|
211
|
+
/** Sets a new password from the link's `token`, and signs in. */
|
|
212
|
+
resetPassword(token: string, password: string): Promise<ShopUser>;
|
|
213
|
+
/**
|
|
214
|
+
* Starts paying for the cart with a payment method: its `payment` holds what the method needs
|
|
215
|
+
* on the page (Stripe's `clientSecret`; a bank transfer's `instructions`).
|
|
216
|
+
*/
|
|
217
|
+
checkout(input: {
|
|
218
|
+
method: string;
|
|
219
|
+
/** Guests give theirs; signed-in customers use their account's. */
|
|
220
|
+
email?: string;
|
|
221
|
+
shippingAddress?: Address;
|
|
222
|
+
/** A saved address of the customer instead. */
|
|
223
|
+
address?: ID;
|
|
224
|
+
}): Promise<CheckoutResult>;
|
|
225
|
+
/** After the payment on the page (e.g. Stripe's `confirmPayment`): makes the order. */
|
|
226
|
+
confirm(transaction: ID, input?: Record<string, unknown>): Promise<ConfirmResult>;
|
|
227
|
+
addresses(): Promise<(Address & {
|
|
228
|
+
id: ID;
|
|
229
|
+
})[]>;
|
|
230
|
+
createAddress(address: Address): Promise<Address & {
|
|
231
|
+
id: ID;
|
|
232
|
+
}>;
|
|
233
|
+
updateAddress(id: ID, address: Partial<Address>): Promise<Address & {
|
|
234
|
+
id: ID;
|
|
235
|
+
}>;
|
|
236
|
+
deleteAddress(id: ID): Promise<void>;
|
|
237
|
+
/** The customer's orders, newest first. */
|
|
238
|
+
orders(options?: {
|
|
239
|
+
page?: number;
|
|
240
|
+
limit?: number;
|
|
241
|
+
}): Promise<{
|
|
242
|
+
docs: Record<string, unknown>[];
|
|
243
|
+
totalDocs: number;
|
|
244
|
+
totalPages: number;
|
|
245
|
+
page: number;
|
|
246
|
+
}>;
|
|
247
|
+
}
|
|
248
|
+
declare function createShopClient(options?: ShopClientOptions): ShopClient;
|
|
249
|
+
|
|
250
|
+
export { type Address, type Adjustment, CURRENCIES, type CartLine, type CartView, type CheckoutResult, type ConfirmResult, type Currency, ORDER_STATUSES, type OrderStatus, type ShopClient, type ShopClientOptions, ShopError, type ShopSettings, type ShopState, type ShopUser, TRANSACTION_STATUSES, type TransactionStatus, createShopClient, formatPrice, priceField };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CURRENCIES,
|
|
3
|
+
ORDER_STATUSES,
|
|
4
|
+
ShopError,
|
|
5
|
+
TRANSACTION_STATUSES,
|
|
6
|
+
createShopClient,
|
|
7
|
+
formatPrice,
|
|
8
|
+
priceField
|
|
9
|
+
} from "./chunk-KON3VWC6.js";
|
|
10
|
+
export {
|
|
11
|
+
CURRENCIES,
|
|
12
|
+
ORDER_STATUSES,
|
|
13
|
+
ShopError,
|
|
14
|
+
TRANSACTION_STATUSES,
|
|
15
|
+
createShopClient,
|
|
16
|
+
formatPrice,
|
|
17
|
+
priceField
|
|
18
|
+
};
|