@hand-off/storefront 0.0.0-stage → 0.1.1
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 +464 -2
- package/index.cjs +736 -0
- package/index.mjs +713 -0
- package/package.json +44 -4
- package/skill/SKILL.md +207 -0
- package/types/core/cart.d.ts +47 -0
- package/types/core/collections.d.ts +7 -0
- package/types/core/content.d.ts +8 -0
- package/types/core/discount.d.ts +15 -0
- package/types/core/errors.d.ts +34 -0
- package/types/core/menus.d.ts +7 -0
- package/types/core/products.d.ts +34 -0
- package/types/core/store.d.ts +15 -0
- package/types/core/transport.d.ts +47 -0
- package/types/entry/format.d.ts +5 -0
- package/types/entry/index.d.ts +30 -0
- package/types/sdk/checkout.d.ts +51 -0
- package/types/sdk/session.d.ts +29 -0
- package/types/sdk/shopper.d.ts +64 -0
- package/types/sdk/storefront.d.ts +86 -0
- package/types/transport/key.d.ts +77 -0
- package/types/transport/session.d.ts +21 -0
- package/types/types/api.d.ts +658 -0
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shapes the storefront API answers (`/storefront/api/v1/…`), written out by hand so this
|
|
3
|
+
* library imports nothing. They mirror `libs/contract/src/lib/storefront/storefront-api-v1.ts`
|
|
4
|
+
* name for name (without the `StorefrontApi` prefix); a spec in the API app
|
|
5
|
+
* (`storefront-library-types.spec.ts`) stops compiling when the two drift.
|
|
6
|
+
*
|
|
7
|
+
* Money is an integer in minor units (cents) beside its `currency`. These names are a public
|
|
8
|
+
* contract: add fields, never rename or remove one.
|
|
9
|
+
*/
|
|
10
|
+
/** The API's error codes. A newer API may answer a code this list does not have yet. */
|
|
11
|
+
export type ApiErrorCode = 'NOT_FOUND' | 'PROTECTED' | 'AUTH_REQUIRED' | 'REGISTRATION_REQUIRED' | 'PENDING_APPROVAL' | 'VERIFICATION_REQUIRED' | 'FORBIDDEN' | 'INVALID_REQUEST' | 'RATE_LIMITED' | 'INTERNAL_ERROR' | 'TOKEN_REQUIRED' | 'TOKEN_INVALID' | 'TOKEN_EXPIRED' | 'SCOPE_REFUSED' | 'SIGN_IN_REQUIRED' | 'OUT_OF_STOCK' | 'DISCOUNT_REFUSED' | 'CONFLICT' | 'CLOSED' | 'UNAVAILABLE' | 'STATE_TOO_LARGE' | 'STATE_INVALID' | 'KEY_REQUIRED' | 'KEY_INVALID' | 'ORIGIN_REFUSED';
|
|
12
|
+
export type ApiPageInfo = {
|
|
13
|
+
nextCursor: string | null;
|
|
14
|
+
};
|
|
15
|
+
export type ApiSuccess<T> = {
|
|
16
|
+
data: T;
|
|
17
|
+
page?: ApiPageInfo;
|
|
18
|
+
};
|
|
19
|
+
export type ApiFailure = {
|
|
20
|
+
error: {
|
|
21
|
+
code: ApiErrorCode;
|
|
22
|
+
message: string;
|
|
23
|
+
/** A more exact reason where one exists (a form's own code, such as `FORM_TOKEN_EXPIRED`). */
|
|
24
|
+
reason?: string;
|
|
25
|
+
/** Per-field error codes of a form submission. */
|
|
26
|
+
fields?: Record<string, string>;
|
|
27
|
+
retryAfterMs?: number;
|
|
28
|
+
/** A fresh form render token, to send the same answers again. */
|
|
29
|
+
formToken?: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export type ApiResponse<T> = ApiSuccess<T> | ApiFailure;
|
|
33
|
+
/** An amount in minor units with its ISO 4217 currency. */
|
|
34
|
+
export type Money = {
|
|
35
|
+
amount: number;
|
|
36
|
+
currency: string;
|
|
37
|
+
};
|
|
38
|
+
export type Image = {
|
|
39
|
+
url: string;
|
|
40
|
+
/** Empty when the image has no other sizes. */
|
|
41
|
+
srcset: string;
|
|
42
|
+
width: number | null;
|
|
43
|
+
height: number | null;
|
|
44
|
+
alt: string;
|
|
45
|
+
};
|
|
46
|
+
export type Media = {
|
|
47
|
+
id: string;
|
|
48
|
+
url: string;
|
|
49
|
+
mimeType: string;
|
|
50
|
+
alt: string;
|
|
51
|
+
image: Image | null;
|
|
52
|
+
/** A video's still frame. */
|
|
53
|
+
posterUrl: string | null;
|
|
54
|
+
};
|
|
55
|
+
export type Address = {
|
|
56
|
+
street: string;
|
|
57
|
+
city: string;
|
|
58
|
+
state: string;
|
|
59
|
+
zip: string;
|
|
60
|
+
country: string | null;
|
|
61
|
+
};
|
|
62
|
+
/** `openTime` and `closeTime` are `HH:mm` in the store's `timezone`. */
|
|
63
|
+
export type Hours = {
|
|
64
|
+
day: string;
|
|
65
|
+
isOpen: boolean;
|
|
66
|
+
openTime: string | null;
|
|
67
|
+
closeTime: string | null;
|
|
68
|
+
};
|
|
69
|
+
/** Dates are `YYYY-MM-DD` in the store's `timezone`, both inclusive. */
|
|
70
|
+
export type Closure = {
|
|
71
|
+
startDate: string;
|
|
72
|
+
endDate: string;
|
|
73
|
+
label: string | null;
|
|
74
|
+
};
|
|
75
|
+
export type OrderingState = {
|
|
76
|
+
isOpenNow: boolean;
|
|
77
|
+
nextOpenAt: string | null;
|
|
78
|
+
closesAt: string | null;
|
|
79
|
+
/** Until when an active closure lasts, when one applies now. */
|
|
80
|
+
closureUntil: string | null;
|
|
81
|
+
};
|
|
82
|
+
export type FulfillmentOption = {
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
hours: Hours[];
|
|
85
|
+
closures: Closure[];
|
|
86
|
+
/** Whether orders are taken right now for this method. Null when the method has no hours to go by. */
|
|
87
|
+
ordering: OrderingState | null;
|
|
88
|
+
/** The smallest order this method takes, in minor units of the store's currency. Null: none. */
|
|
89
|
+
orderMinimum: number | null;
|
|
90
|
+
};
|
|
91
|
+
export type Store = {
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
/** The store's slug: the address prefix in an organization with more than one store. */
|
|
95
|
+
slug: string;
|
|
96
|
+
description: string | null;
|
|
97
|
+
tagline: string | null;
|
|
98
|
+
/** The store's own address (scheme and host, plus the store slug where the organization has several stores). */
|
|
99
|
+
url: string;
|
|
100
|
+
currency: string;
|
|
101
|
+
timezone: string;
|
|
102
|
+
/** The answer's language, and the languages this store's pages exist in. */
|
|
103
|
+
language: string;
|
|
104
|
+
languages: string[];
|
|
105
|
+
visibility: 'public' | 'private';
|
|
106
|
+
logoUrl: string | null;
|
|
107
|
+
branding: {
|
|
108
|
+
colors: Record<string, string>;
|
|
109
|
+
fonts: {
|
|
110
|
+
heading: string | null;
|
|
111
|
+
body: string | null;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
contact: {
|
|
115
|
+
email: string | null;
|
|
116
|
+
phone: string | null;
|
|
117
|
+
address: Address | null;
|
|
118
|
+
};
|
|
119
|
+
hours: Hours[];
|
|
120
|
+
ordering: OrderingState & {
|
|
121
|
+
timezone: string;
|
|
122
|
+
};
|
|
123
|
+
fulfillment: {
|
|
124
|
+
pickup: FulfillmentOption & {
|
|
125
|
+
address: Address | null;
|
|
126
|
+
};
|
|
127
|
+
delivery: FulfillmentOption;
|
|
128
|
+
shipping: FulfillmentOption & {
|
|
129
|
+
/** Minor units of the store's currency. Null: not a flat rate. */
|
|
130
|
+
flatRate: number | null;
|
|
131
|
+
freeShippingThreshold: number | null;
|
|
132
|
+
/** Where the store does not ship: a country, or only the listed states of it. */
|
|
133
|
+
restrictions: Array<{
|
|
134
|
+
country: string;
|
|
135
|
+
states: string[];
|
|
136
|
+
}>;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
registration: {
|
|
140
|
+
automaticApproval: boolean;
|
|
141
|
+
requiresEmailVerification: boolean;
|
|
142
|
+
requiresReferralCode: boolean;
|
|
143
|
+
requiresIdVerification: boolean;
|
|
144
|
+
collectsDateOfBirth: boolean;
|
|
145
|
+
minimumAge: number | null;
|
|
146
|
+
};
|
|
147
|
+
ageGate: {
|
|
148
|
+
enabled: boolean;
|
|
149
|
+
minimumAge: number | null;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
export type StockState = 'in_stock' | 'out_of_stock' | 'not_tracked';
|
|
153
|
+
export type Stock = {
|
|
154
|
+
state: StockState;
|
|
155
|
+
/** How many can be bought now. Null when the product is not tracked or the store hides its counts. */
|
|
156
|
+
quantity: number | null;
|
|
157
|
+
};
|
|
158
|
+
export type ProductOption = {
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
values: Array<{
|
|
162
|
+
id: string;
|
|
163
|
+
name: string;
|
|
164
|
+
}>;
|
|
165
|
+
};
|
|
166
|
+
export type Variant = {
|
|
167
|
+
/** The id a cart line and an order line carry (`productVariantCombinationId`). */
|
|
168
|
+
id: string;
|
|
169
|
+
productId: string;
|
|
170
|
+
/** The key the cart routes take (`combinationKey`). */
|
|
171
|
+
key: string;
|
|
172
|
+
/** The chosen values' names joined with " / "; the product's name for a product without options. */
|
|
173
|
+
title: string;
|
|
174
|
+
sku: string | null;
|
|
175
|
+
/** The price a shopper pays now, in minor units. */
|
|
176
|
+
price: number;
|
|
177
|
+
/** The list price before the store's automatic discount, when one lowers it. */
|
|
178
|
+
compareAtPrice: number | null;
|
|
179
|
+
currency: string;
|
|
180
|
+
stock: Stock;
|
|
181
|
+
/** Option id to chosen value. */
|
|
182
|
+
options: Array<{
|
|
183
|
+
optionId: string;
|
|
184
|
+
optionName: string;
|
|
185
|
+
valueId: string;
|
|
186
|
+
valueName: string;
|
|
187
|
+
}>;
|
|
188
|
+
media: Media[];
|
|
189
|
+
};
|
|
190
|
+
export type ProductSummary = {
|
|
191
|
+
id: string;
|
|
192
|
+
/** The product's address part: `/products/{slug}`. */
|
|
193
|
+
slug: string;
|
|
194
|
+
url: string;
|
|
195
|
+
name: string;
|
|
196
|
+
subtitle: string | null;
|
|
197
|
+
brand: string | null;
|
|
198
|
+
/** The lowest price shown on its card, in minor units; `maxPrice` when its variants differ. */
|
|
199
|
+
price: number;
|
|
200
|
+
maxPrice: number | null;
|
|
201
|
+
compareAtPrice: number | null;
|
|
202
|
+
currency: string;
|
|
203
|
+
stock: Stock;
|
|
204
|
+
hasVariants: boolean;
|
|
205
|
+
purchaseOptions: string;
|
|
206
|
+
badges: string[];
|
|
207
|
+
image: Image | null;
|
|
208
|
+
};
|
|
209
|
+
export type Product = Omit<ProductSummary, 'image' | 'hasVariants'> & {
|
|
210
|
+
/** Sanitised HTML. */
|
|
211
|
+
descriptionHtml: string | null;
|
|
212
|
+
productType: string;
|
|
213
|
+
categories: Array<{
|
|
214
|
+
id: string;
|
|
215
|
+
name: string;
|
|
216
|
+
}>;
|
|
217
|
+
seo: {
|
|
218
|
+
title: string | null;
|
|
219
|
+
description: string | null;
|
|
220
|
+
};
|
|
221
|
+
media: Media[];
|
|
222
|
+
options: ProductOption[];
|
|
223
|
+
variants: Variant[];
|
|
224
|
+
/** The variant its page opens on, when the store set one. */
|
|
225
|
+
defaultVariantId: string | null;
|
|
226
|
+
customFields: Array<{
|
|
227
|
+
label: string;
|
|
228
|
+
value: unknown;
|
|
229
|
+
prefix: string | null;
|
|
230
|
+
suffix: string | null;
|
|
231
|
+
}>;
|
|
232
|
+
};
|
|
233
|
+
export type VariantLookup = {
|
|
234
|
+
variant: Variant;
|
|
235
|
+
product: ProductSummary;
|
|
236
|
+
};
|
|
237
|
+
export type Collection = {
|
|
238
|
+
id: string;
|
|
239
|
+
slug: string;
|
|
240
|
+
url: string;
|
|
241
|
+
name: string;
|
|
242
|
+
/** Sanitised HTML or plain text, as the collection page prints it. */
|
|
243
|
+
description: string | null;
|
|
244
|
+
image: Image | null;
|
|
245
|
+
seo: {
|
|
246
|
+
title: string | null;
|
|
247
|
+
description: string | null;
|
|
248
|
+
};
|
|
249
|
+
/** Present where the store shows it. */
|
|
250
|
+
productCount: number | null;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* A product category (what a product is: Tees, Mugs), as `GET categories` lists it: the store's
|
|
254
|
+
* top-level categories first, then their subcategories (`parentId`). `url` is the category's own
|
|
255
|
+
* page on the shop; `products?categoryId=` lists its products.
|
|
256
|
+
*/
|
|
257
|
+
export type Category = {
|
|
258
|
+
id: string;
|
|
259
|
+
/** The address part of its page: `/categories/{slug}`. */
|
|
260
|
+
slug: string;
|
|
261
|
+
url: string;
|
|
262
|
+
name: string;
|
|
263
|
+
/** Null for a top-level category. */
|
|
264
|
+
parentId: string | null;
|
|
265
|
+
/** How many products the shop lists in it now. */
|
|
266
|
+
productCount: number;
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* The storefront's built-in pages a store's own pages stand beside: home (`/`), `/about`,
|
|
270
|
+
* `/contact` and `/faq`. Their addresses are fixed; a store cannot rename, remove or password
|
|
271
|
+
* protect one, only switch its blocks on and off.
|
|
272
|
+
*/
|
|
273
|
+
export type BuiltinPageKey = 'home' | 'about' | 'contact' | 'faq';
|
|
274
|
+
export type PageSummary = {
|
|
275
|
+
/** A custom page's id; `builtin:<key>` for a built-in page. */
|
|
276
|
+
id: string | null;
|
|
277
|
+
path: string;
|
|
278
|
+
url: string;
|
|
279
|
+
title: string | null;
|
|
280
|
+
publishedAt: string | null;
|
|
281
|
+
/** Present on a built-in page only (home, about, contact, FAQ); absent on a store's custom page. */
|
|
282
|
+
builtin?: BuiltinPageKey;
|
|
283
|
+
};
|
|
284
|
+
export type PageSection = {
|
|
285
|
+
/** On a built-in page's own block (`type` is `builtin`): the block's name on that page, such as `hero` or `contactForm`. */
|
|
286
|
+
id: string;
|
|
287
|
+
/** A section type of the section library, or `builtin` for a built-in page's own block. */
|
|
288
|
+
type: string;
|
|
289
|
+
variant: string | null;
|
|
290
|
+
/**
|
|
291
|
+
* The section's shopper-facing settings. Only settings reviewed as public for this section type
|
|
292
|
+
* are present; a section type that has not been reviewed carries none (`audited: false`).
|
|
293
|
+
* A setting the page does not print as things stand is null (a list is empty): a link text and
|
|
294
|
+
* link while their switch (`showViewAll`) is off, a button's link without its words, a subtitle
|
|
295
|
+
* under an empty title, every word of a sale band whose discount is not live. The switch itself
|
|
296
|
+
* is answered as it is.
|
|
297
|
+
*/
|
|
298
|
+
settings: Record<string, unknown>;
|
|
299
|
+
audited: boolean;
|
|
300
|
+
};
|
|
301
|
+
export type Page = {
|
|
302
|
+
kind: 'page';
|
|
303
|
+
/** A custom page's id; `builtin:<key>` for a built-in page. */
|
|
304
|
+
id: string;
|
|
305
|
+
/** Present on a built-in page only (home, about, contact, FAQ); absent on a store's custom page. */
|
|
306
|
+
builtin?: BuiltinPageKey;
|
|
307
|
+
path: string;
|
|
308
|
+
url: string;
|
|
309
|
+
title: string;
|
|
310
|
+
seo: {
|
|
311
|
+
title: string | null;
|
|
312
|
+
description: string | null;
|
|
313
|
+
noindex: boolean;
|
|
314
|
+
};
|
|
315
|
+
sections: PageSection[];
|
|
316
|
+
};
|
|
317
|
+
export type ContentField = {
|
|
318
|
+
id: string;
|
|
319
|
+
name: string;
|
|
320
|
+
type: string;
|
|
321
|
+
value: unknown;
|
|
322
|
+
};
|
|
323
|
+
export type ContentEntry = {
|
|
324
|
+
id: string;
|
|
325
|
+
slug: string;
|
|
326
|
+
/** Null when the collection has entry pages off. */
|
|
327
|
+
url: string | null;
|
|
328
|
+
title: string;
|
|
329
|
+
description: string | null;
|
|
330
|
+
/** Sanitised HTML. Present on a single entry; null in a list. */
|
|
331
|
+
contentHtml: string | null;
|
|
332
|
+
publishedDate: string | null;
|
|
333
|
+
author: string | null;
|
|
334
|
+
link: string | null;
|
|
335
|
+
image: Image | null;
|
|
336
|
+
gallery: Image[];
|
|
337
|
+
tags: Array<{
|
|
338
|
+
id: string;
|
|
339
|
+
name: string;
|
|
340
|
+
}>;
|
|
341
|
+
fields: ContentField[];
|
|
342
|
+
};
|
|
343
|
+
export type ContentCollection = {
|
|
344
|
+
id: string;
|
|
345
|
+
slug: string;
|
|
346
|
+
url: string;
|
|
347
|
+
title: string;
|
|
348
|
+
entryPages: boolean;
|
|
349
|
+
tags: Array<{
|
|
350
|
+
id: string;
|
|
351
|
+
name: string;
|
|
352
|
+
}>;
|
|
353
|
+
};
|
|
354
|
+
export type ContentList = {
|
|
355
|
+
collection: ContentCollection;
|
|
356
|
+
entries: ContentEntry[];
|
|
357
|
+
};
|
|
358
|
+
export type ContentItem = {
|
|
359
|
+
collection: ContentCollection;
|
|
360
|
+
entry: ContentEntry;
|
|
361
|
+
};
|
|
362
|
+
/** What `pages/by-path` answers: a custom or built-in page, a content collection's list, one entry, or where the address moved to. */
|
|
363
|
+
export type PathContent = Page | ({
|
|
364
|
+
kind: 'content-collection';
|
|
365
|
+
} & ContentList) | ({
|
|
366
|
+
kind: 'content-entry';
|
|
367
|
+
} & ContentItem) | {
|
|
368
|
+
kind: 'redirect';
|
|
369
|
+
toPath: string;
|
|
370
|
+
};
|
|
371
|
+
export type MenuLink = {
|
|
372
|
+
label: string;
|
|
373
|
+
href: string;
|
|
374
|
+
external: boolean;
|
|
375
|
+
children: Array<{
|
|
376
|
+
label: string;
|
|
377
|
+
href: string;
|
|
378
|
+
external: boolean;
|
|
379
|
+
}>;
|
|
380
|
+
};
|
|
381
|
+
export type Menus = {
|
|
382
|
+
/** Null: the store has no header menu of its own. */
|
|
383
|
+
header: MenuLink[] | null;
|
|
384
|
+
/** Null: the store has no footer menu of its own. */
|
|
385
|
+
footer: Array<{
|
|
386
|
+
heading: string;
|
|
387
|
+
links: Array<{
|
|
388
|
+
label: string;
|
|
389
|
+
href: string;
|
|
390
|
+
external: boolean;
|
|
391
|
+
}>;
|
|
392
|
+
}> | null;
|
|
393
|
+
};
|
|
394
|
+
export type Policy = {
|
|
395
|
+
key: 'privacy' | 'terms' | 'shipping' | 'refund';
|
|
396
|
+
/** Absolute address of the policy page. Null when the store has no such page. */
|
|
397
|
+
url: string | null;
|
|
398
|
+
hasContent: boolean;
|
|
399
|
+
title: string | null;
|
|
400
|
+
/** Sanitised HTML. Null when the page has no text of its own. */
|
|
401
|
+
bodyHtml: string | null;
|
|
402
|
+
};
|
|
403
|
+
export type Policies = {
|
|
404
|
+
policies: Policy[];
|
|
405
|
+
};
|
|
406
|
+
export type FormField = {
|
|
407
|
+
id: string;
|
|
408
|
+
type: string;
|
|
409
|
+
label: string;
|
|
410
|
+
required: boolean;
|
|
411
|
+
placeholder: string | null;
|
|
412
|
+
helpText: string | null;
|
|
413
|
+
options: Array<{
|
|
414
|
+
id: string;
|
|
415
|
+
label: string;
|
|
416
|
+
}>;
|
|
417
|
+
maxLength: number | null;
|
|
418
|
+
};
|
|
419
|
+
export type Form = {
|
|
420
|
+
id: string;
|
|
421
|
+
closed: boolean;
|
|
422
|
+
closedMessage: string | null;
|
|
423
|
+
fields: FormField[];
|
|
424
|
+
submitLabel: string;
|
|
425
|
+
successMessage: string;
|
|
426
|
+
footnote: string | null;
|
|
427
|
+
/** Sent back with a submission. Empty for a closed form. Valid for a day, on this store only. */
|
|
428
|
+
renderToken: string;
|
|
429
|
+
};
|
|
430
|
+
export type PageToken = {
|
|
431
|
+
token: string;
|
|
432
|
+
expiresAt: string;
|
|
433
|
+
};
|
|
434
|
+
export type CartLineAddOn = {
|
|
435
|
+
addOnId: string;
|
|
436
|
+
optionId: string;
|
|
437
|
+
name: string;
|
|
438
|
+
optionName: string;
|
|
439
|
+
quantity: number;
|
|
440
|
+
unitPrice: number;
|
|
441
|
+
subtotal: number;
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* A cart line as a page sees it: the product, the choice, the quantity and list prices. No
|
|
445
|
+
* discount, gift or reward is in a page's cart view (they show on `/cart`).
|
|
446
|
+
*/
|
|
447
|
+
export type CartLine = {
|
|
448
|
+
id: string;
|
|
449
|
+
productId: string;
|
|
450
|
+
productSlug: string | null;
|
|
451
|
+
combinationKey: string;
|
|
452
|
+
name: string;
|
|
453
|
+
variant: string | null;
|
|
454
|
+
image: string | null;
|
|
455
|
+
quantity: number;
|
|
456
|
+
maxQuantity: number;
|
|
457
|
+
/** Unit price before discounts, minor units. */
|
|
458
|
+
unitPrice: number;
|
|
459
|
+
addOns: CartLineAddOn[];
|
|
460
|
+
/** Quantity times unit price, plus add-ons, before discounts. */
|
|
461
|
+
lineSubtotal: number;
|
|
462
|
+
needsAttention: boolean;
|
|
463
|
+
attentionReason: string | null;
|
|
464
|
+
personalization: {
|
|
465
|
+
label: string;
|
|
466
|
+
value: string;
|
|
467
|
+
required: boolean;
|
|
468
|
+
maxLength: number;
|
|
469
|
+
} | null;
|
|
470
|
+
};
|
|
471
|
+
/** A cart-level add-on the shopper chose (gift wrap, a fee). Its amount shows on `/cart`: a percentage add-on is priced on the discounted cart. */
|
|
472
|
+
export type CartAddOn = {
|
|
473
|
+
id: string;
|
|
474
|
+
name: string;
|
|
475
|
+
};
|
|
476
|
+
export type Cart = {
|
|
477
|
+
currency: string;
|
|
478
|
+
lines: CartLine[];
|
|
479
|
+
itemCount: number;
|
|
480
|
+
/** The lines' subtotals before discounts. */
|
|
481
|
+
linesSubtotal: number;
|
|
482
|
+
cartAddOns: CartAddOn[];
|
|
483
|
+
/** Codes the shopper entered that are on the cart. Amounts show on `/cart`. */
|
|
484
|
+
discountCodes: string[];
|
|
485
|
+
needsAttention: boolean;
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* A sealed page's own small state for one visitor at one store (`GET` and `PUT page/state`, token
|
|
489
|
+
* scope `state`): the same visitor the page's cart belongs to. Kept 30 days from the last write.
|
|
490
|
+
* Values are plain: strings, numbers, booleans or null (nest anything else as a JSON string).
|
|
491
|
+
*/
|
|
492
|
+
export type VisitorStateValue = string | number | boolean | null;
|
|
493
|
+
export type VisitorState = Record<string, VisitorStateValue>;
|
|
494
|
+
/** The body of both state routes: `PUT` sends it, both answer it in `data`. A `PUT` replaces the whole object. */
|
|
495
|
+
export type VisitorStateBody = {
|
|
496
|
+
state: VisitorState;
|
|
497
|
+
};
|
|
498
|
+
/** A guest's cart token (`POST session/cart-token`): `hoct1.…`, 30 days. */
|
|
499
|
+
export type CartToken = {
|
|
500
|
+
token: string;
|
|
501
|
+
expiresAt: string;
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* A signed-in shopper's tokens. The access token (`hosa1.…`, 15 minutes) goes in
|
|
505
|
+
* `Authorization: Bearer`; the refresh token (`hosr1.…`) goes in the body of `POST session/shopper/refresh`
|
|
506
|
+
* and is replaced on every use.
|
|
507
|
+
*/
|
|
508
|
+
export type ShopperTokens = {
|
|
509
|
+
accessToken: string;
|
|
510
|
+
accessTokenExpiresAt: string;
|
|
511
|
+
refreshToken: string;
|
|
512
|
+
refreshTokenExpiresAt: string;
|
|
513
|
+
};
|
|
514
|
+
/** A shopper sign-in or join that finished (`POST session/shopper/verify`, `…/register`). */
|
|
515
|
+
export type ShopperSignIn = ShopperTokens & {
|
|
516
|
+
shopper: Shopper;
|
|
517
|
+
/** The guest cart token sent with the sign-in was merged into the shopper's cart and no longer works. */
|
|
518
|
+
cartMerged: boolean;
|
|
519
|
+
};
|
|
520
|
+
/** The signed-in shopper as the token's frontend sees them (`GET session/shopper`). */
|
|
521
|
+
export type Shopper = {
|
|
522
|
+
customerId: string;
|
|
523
|
+
firstName: string | null;
|
|
524
|
+
lastName: string | null;
|
|
525
|
+
/** `ACTIVE`, `PENDING` (waiting for the store's approval) or another customer status. */
|
|
526
|
+
status: string;
|
|
527
|
+
/** False while the store still needs the shopper to finish verification (email or ID). */
|
|
528
|
+
verificationComplete: boolean;
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* A code check for a shopper new to the store, on the progressive flow (`POST session/shopper/verify`
|
|
532
|
+
* with `progressive: true`): ask for these fields, then finish with `POST session/shopper/register`.
|
|
533
|
+
*/
|
|
534
|
+
export type ShopperNeedsProfile = {
|
|
535
|
+
needsProfile: true;
|
|
536
|
+
registrationToken: string;
|
|
537
|
+
requirements: {
|
|
538
|
+
name: boolean;
|
|
539
|
+
email: boolean;
|
|
540
|
+
referral: boolean;
|
|
541
|
+
dateOfBirth?: boolean;
|
|
542
|
+
collectDateOfBirth?: boolean;
|
|
543
|
+
};
|
|
544
|
+
};
|
|
545
|
+
/**
|
|
546
|
+
* A line of the cart on token sessions: the storefront's own cart view (what `/cart` draws), so
|
|
547
|
+
* with totals and discounts, unlike a sealed page's `CartLine`. Minor units throughout. More
|
|
548
|
+
* members may be present; these are the ones to build on.
|
|
549
|
+
*/
|
|
550
|
+
export type SessionCartItem = {
|
|
551
|
+
id: string;
|
|
552
|
+
productId: string;
|
|
553
|
+
combinationKey: string;
|
|
554
|
+
name: string;
|
|
555
|
+
variant: string | null;
|
|
556
|
+
image: string | null;
|
|
557
|
+
productSlug: string | null;
|
|
558
|
+
/** Unit price, minor units. */
|
|
559
|
+
price: number;
|
|
560
|
+
quantity: number;
|
|
561
|
+
maxQuantity: number;
|
|
562
|
+
addOns: Array<{
|
|
563
|
+
addOnId: string;
|
|
564
|
+
name: string;
|
|
565
|
+
quantity: number;
|
|
566
|
+
[member: string]: unknown;
|
|
567
|
+
}>;
|
|
568
|
+
addOnsTotal: number;
|
|
569
|
+
personalization: {
|
|
570
|
+
label: string;
|
|
571
|
+
value: string;
|
|
572
|
+
required: boolean;
|
|
573
|
+
maxLength: number;
|
|
574
|
+
[member: string]: unknown;
|
|
575
|
+
} | null;
|
|
576
|
+
lineSubtotal: number;
|
|
577
|
+
needsAttention: boolean;
|
|
578
|
+
attentionReason: string | null;
|
|
579
|
+
/** A free gift a discount added. */
|
|
580
|
+
isGift?: boolean;
|
|
581
|
+
giftLabel?: string | null;
|
|
582
|
+
[member: string]: unknown;
|
|
583
|
+
};
|
|
584
|
+
/** The cart on token sessions (`session/cart` and every cart write): the storefront cart view, its currency and, once it has a line, its id. */
|
|
585
|
+
export type SessionCart = {
|
|
586
|
+
currency: string;
|
|
587
|
+
cartId?: string;
|
|
588
|
+
items: SessionCartItem[];
|
|
589
|
+
productsTotal: number;
|
|
590
|
+
/** Products total minus product-level discounts. */
|
|
591
|
+
cartSubtotal: number;
|
|
592
|
+
/** Cart minus cart-level discounts, plus cart add-ons. */
|
|
593
|
+
subtotal: number;
|
|
594
|
+
discount: number;
|
|
595
|
+
cartAddOns: Array<{
|
|
596
|
+
addOnId: string;
|
|
597
|
+
name: string;
|
|
598
|
+
amount: number;
|
|
599
|
+
[member: string]: unknown;
|
|
600
|
+
}>;
|
|
601
|
+
cartAddOnsTotal: number;
|
|
602
|
+
shippingDiscount: number;
|
|
603
|
+
shipping: number;
|
|
604
|
+
paymentFee: number;
|
|
605
|
+
total: number;
|
|
606
|
+
itemCount: number;
|
|
607
|
+
needsAttention: boolean;
|
|
608
|
+
attentionReason: string | null;
|
|
609
|
+
appliedDiscounts: Array<{
|
|
610
|
+
discountId: string;
|
|
611
|
+
code: string | null;
|
|
612
|
+
description: string;
|
|
613
|
+
amount: number;
|
|
614
|
+
isAutomatic: boolean;
|
|
615
|
+
[member: string]: unknown;
|
|
616
|
+
}>;
|
|
617
|
+
rejectedCodes: Array<{
|
|
618
|
+
code: string;
|
|
619
|
+
reason: string;
|
|
620
|
+
}>;
|
|
621
|
+
appliedCodes: string[];
|
|
622
|
+
[member: string]: unknown;
|
|
623
|
+
};
|
|
624
|
+
export type CheckoutLinkStatus = 'OPEN' | 'COMPLETED' | 'EXPIRED';
|
|
625
|
+
/** A line the checkout link is made of: what an add to the cart takes. */
|
|
626
|
+
export type CheckoutLinkLine = {
|
|
627
|
+
productId: string;
|
|
628
|
+
combinationKey?: string;
|
|
629
|
+
/** 1 to 100. */
|
|
630
|
+
quantity: number;
|
|
631
|
+
selectedAddOns?: Array<{
|
|
632
|
+
addOnId: string;
|
|
633
|
+
selectedOptionId: string;
|
|
634
|
+
quantity: number;
|
|
635
|
+
}>;
|
|
636
|
+
personalizationText?: string;
|
|
637
|
+
};
|
|
638
|
+
/** `POST checkout-links`: send the shopper to `url`; it works once, until `expiresAt`. */
|
|
639
|
+
export type CheckoutLink = {
|
|
640
|
+
checkoutLinkId: string;
|
|
641
|
+
status: CheckoutLinkStatus;
|
|
642
|
+
url: string;
|
|
643
|
+
expiresAt: string;
|
|
644
|
+
orderNumber: string | null;
|
|
645
|
+
cart: {
|
|
646
|
+
currency: string;
|
|
647
|
+
itemCount: number;
|
|
648
|
+
subtotal: number;
|
|
649
|
+
items: unknown[];
|
|
650
|
+
} | null;
|
|
651
|
+
};
|
|
652
|
+
/** `GET checkout-links/:checkoutLinkId`: whether the shopper paid, and the order. */
|
|
653
|
+
export type CheckoutLinkState = {
|
|
654
|
+
checkoutLinkId: string;
|
|
655
|
+
status: CheckoutLinkStatus;
|
|
656
|
+
orderNumber: string | null;
|
|
657
|
+
expiresAt: string;
|
|
658
|
+
};
|