@asteby/storefront 0.0.0-stage → 0.2.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.
@@ -0,0 +1,465 @@
1
+ /**
2
+ * Storefront API v1 contract types.
3
+ *
4
+ * Field names match the wire format exactly (snake_case). Money amounts are
5
+ * decimal strings ("1899.00") so no precision is lost in transit.
6
+ */
7
+ type Money = {
8
+ amount: string;
9
+ currency_code: string;
10
+ };
11
+ type Image = {
12
+ url: string;
13
+ alt: string | null;
14
+ width?: number;
15
+ height?: number;
16
+ };
17
+ type SEO = {
18
+ title: string | null;
19
+ description: string | null;
20
+ };
21
+ type PageInfo = {
22
+ has_next_page: boolean;
23
+ end_cursor: string | null;
24
+ };
25
+ type Connection<T> = {
26
+ nodes: T[];
27
+ page_info: PageInfo;
28
+ total_count?: number;
29
+ };
30
+ type ProductOption = {
31
+ name: string;
32
+ values: string[];
33
+ };
34
+ type SelectedOption = {
35
+ name: string;
36
+ value: string;
37
+ };
38
+ type ProductVariant = {
39
+ id: string;
40
+ sku: string;
41
+ title: string;
42
+ selected_options: SelectedOption[];
43
+ price: Money;
44
+ compare_at_price: Money | null;
45
+ available_for_sale: boolean;
46
+ quantity_available: number | null;
47
+ image: Image | null;
48
+ barcode: string | null;
49
+ };
50
+ type ProductAttributeValue = string | number | boolean;
51
+ type ProductCategory = {
52
+ id: string;
53
+ handle: string;
54
+ title: string;
55
+ };
56
+ type MoneyRange = {
57
+ min: Money;
58
+ max: Money;
59
+ };
60
+ type Product = {
61
+ id: string;
62
+ handle: string;
63
+ title: string;
64
+ description: string;
65
+ /** HTML sanitized server-side. */
66
+ description_html: string;
67
+ /** Brand. */
68
+ vendor: string | null;
69
+ product_type: string | null;
70
+ category: ProductCategory | null;
71
+ tags: string[];
72
+ /** Free-form typed attributes, e.g. tire specs: width, aspect, rim, size_key. */
73
+ attributes: Record<string, ProductAttributeValue>;
74
+ featured_image: Image | null;
75
+ images: Image[];
76
+ options: ProductOption[];
77
+ variants: ProductVariant[];
78
+ price_range: MoneyRange;
79
+ compare_at_price_range: MoneyRange | null;
80
+ available_for_sale: boolean;
81
+ seo: SEO;
82
+ /** RFC 3339. */
83
+ updated_at: string;
84
+ };
85
+ type Collection = {
86
+ id: string;
87
+ handle: string;
88
+ title: string;
89
+ description: string;
90
+ image: Image | null;
91
+ seo: SEO;
92
+ parent_handle: string | null;
93
+ };
94
+ type FacetValue = {
95
+ value: string;
96
+ label: string;
97
+ count: number;
98
+ };
99
+ type Facet = {
100
+ key: string;
101
+ label: string;
102
+ type: 'list' | 'price_range';
103
+ values: FacetValue[];
104
+ };
105
+ type ProductSort = 'relevance' | 'price_asc' | 'price_desc' | 'newest' | 'title_asc';
106
+ type ProductConnection = Connection<Product> & {
107
+ facets: Facet[];
108
+ };
109
+ /** `quantity_available` is `null` when the variant's stock is not tracked (always sellable). */
110
+ type StockLevel = {
111
+ sku: string;
112
+ quantity_available: number | null;
113
+ };
114
+ type ShopContact = {
115
+ email: string | null;
116
+ phone: string | null;
117
+ whatsapp: string | null;
118
+ };
119
+ type ShopBranch = {
120
+ id: string;
121
+ name: string;
122
+ address: string;
123
+ city: string;
124
+ phone: string | null;
125
+ lat: number | null;
126
+ lng: number | null;
127
+ hours: string | null;
128
+ };
129
+ type ShopPolicies = {
130
+ free_shipping_min: Money | null;
131
+ returns_days: number | null;
132
+ };
133
+ type Shop = {
134
+ name: string;
135
+ description: string | null;
136
+ domain: string | null;
137
+ currency_code: string;
138
+ locale: string;
139
+ locales: string[];
140
+ country_code: string;
141
+ logo: Image | null;
142
+ contact: ShopContact;
143
+ branches: ShopBranch[];
144
+ policies: ShopPolicies;
145
+ };
146
+ /**
147
+ * Postal address. The contract references `Address` without spelling it out;
148
+ * this is the shape the client sends and the mock returns.
149
+ */
150
+ type Address = {
151
+ /** Present on saved customer addresses. */
152
+ id?: string;
153
+ first_name: string | null;
154
+ last_name: string | null;
155
+ company: string | null;
156
+ address1: string;
157
+ address2: string | null;
158
+ city: string;
159
+ province: string | null;
160
+ zip: string;
161
+ country_code: string;
162
+ phone: string | null;
163
+ /** Colonia. Sent and echoed by the cart API. */
164
+ neighborhood?: string | null;
165
+ province_code?: string | null;
166
+ /** Delivery reference ("between streets", gate code...). */
167
+ reference?: string | null;
168
+ };
169
+ type AddressInput = Partial<Omit<Address, 'id' | 'address1' | 'city' | 'zip' | 'country_code'>> & Pick<Address, 'address1' | 'city' | 'zip' | 'country_code'>;
170
+ type CartLineMerchandise = ProductVariant & {
171
+ product: Pick<Product, 'handle' | 'title' | 'featured_image'>;
172
+ };
173
+ type CartLine = {
174
+ id: string;
175
+ quantity: number;
176
+ merchandise: CartLineMerchandise;
177
+ cost: {
178
+ total: Money;
179
+ unit: Money;
180
+ compare_at_unit: Money | null;
181
+ discount?: Money;
182
+ };
183
+ };
184
+ type CartDiscountCode = {
185
+ code: string;
186
+ applicable: boolean;
187
+ /** Why an inapplicable code was not applied. */
188
+ reason?: string;
189
+ };
190
+ type CartBuyer = {
191
+ email: string | null;
192
+ phone: string | null;
193
+ customer_id: string | null;
194
+ };
195
+ type DeliveryMethod = 'shipping' | 'pickup';
196
+ type CartDelivery = {
197
+ method: DeliveryMethod | null;
198
+ rate_id: string | null;
199
+ branch_id: string | null;
200
+ /** Present when the chosen option is no longer valid (e.g. the quote expired). */
201
+ problem?: string;
202
+ /** Description of the chosen carrier rate (carrier addons only). */
203
+ title?: string | null;
204
+ carrier?: string | null;
205
+ eta?: string | null;
206
+ };
207
+ type CartCost = {
208
+ subtotal: Money;
209
+ discount: Money;
210
+ shipping: Money | null;
211
+ tax: Money | null;
212
+ total: Money;
213
+ tax_included: boolean;
214
+ };
215
+ type Cart = {
216
+ id: string;
217
+ /** `active` while it can be edited; anything else is a cart already turned into an order. */
218
+ status?: string;
219
+ currency_code?: string;
220
+ lines: CartLine[];
221
+ total_quantity: number;
222
+ discount_codes: CartDiscountCode[];
223
+ buyer: CartBuyer;
224
+ shipping_address: Address | null;
225
+ delivery: CartDelivery;
226
+ cost: CartCost;
227
+ note?: string | null;
228
+ updated_at: string;
229
+ };
230
+ type CartLineInput = {
231
+ variant_id: string;
232
+ quantity: number;
233
+ };
234
+ type CartLineUpdateInput = {
235
+ id: string;
236
+ quantity: number;
237
+ };
238
+ type CartBuyerInput = {
239
+ email?: string | null;
240
+ phone?: string | null;
241
+ };
242
+ /**
243
+ * A delivery rate. `id`, `title`, `cost` and `eta` are always present. The rest only
244
+ * comes from carrier addons (`commerce.shipping.rates`); `cost` already reflects a
245
+ * free-shipping code. Show it as is; never recompute.
246
+ */
247
+ type ShippingRate = {
248
+ id: string;
249
+ title: string;
250
+ cost: Money;
251
+ eta: string | null;
252
+ /** Addon key of the rate provider. */
253
+ provider?: string;
254
+ carrier?: string | null;
255
+ service_code?: string | null;
256
+ eta_days_min?: number;
257
+ eta_days_max?: number;
258
+ /** e.g. `home`, `pickup_point`. */
259
+ delivery_type?: string | null;
260
+ pickup?: boolean;
261
+ taxes_included?: boolean | null;
262
+ /** RFC 3339: the quote is valid until then. */
263
+ expires_at?: string | null;
264
+ };
265
+ type PickupOption = {
266
+ branch_id: string;
267
+ name: string;
268
+ address?: string | null;
269
+ city?: string | null;
270
+ };
271
+ /** A rate provider that did not answer in time. */
272
+ type UnavailableRateProvider = {
273
+ provider: string;
274
+ code: string;
275
+ };
276
+ type DeliveryOptions = {
277
+ /** Empty until the cart has a shipping address. Cheapest first. */
278
+ rates: ShippingRate[];
279
+ pickup: PickupOption[];
280
+ /** `true` when some provider failed: `rates` holds only what arrived. */
281
+ partial?: boolean;
282
+ unavailable?: UnavailableRateProvider[];
283
+ };
284
+ /** One way to pay (`GET /storefront/carts/:id/payment-methods`). `key` is sent as `payment_method` at checkout. */
285
+ type PaymentMethod = {
286
+ key: string;
287
+ /** `builtin` (manual transfer/cash) or `provider` (a payment addon). */
288
+ kind: 'builtin' | 'provider';
289
+ default: boolean;
290
+ };
291
+ type PaymentMethods = {
292
+ methods: PaymentMethod[];
293
+ /** Market the request acted in; `null` when none. */
294
+ market: string | null;
295
+ };
296
+ type DeliveryInput = {
297
+ method: DeliveryMethod;
298
+ rate_id?: string;
299
+ branch_id?: string;
300
+ };
301
+ type InvoiceRequest = {
302
+ requested?: boolean;
303
+ tax_id?: string;
304
+ legal_name?: string;
305
+ tax_regime?: string;
306
+ /** CFDI use. */
307
+ use?: string;
308
+ postal_code?: string;
309
+ /** Spanish aliases the API also accepts. */
310
+ rfc?: string;
311
+ razon_social?: string;
312
+ regimen?: string;
313
+ uso_cfdi?: string;
314
+ cp?: string;
315
+ [key: string]: unknown;
316
+ };
317
+ type CheckoutInput = {
318
+ /** `manual` or the `key` of a method from `carts.paymentMethods`. */
319
+ payment_method: string;
320
+ invoice?: InvoiceRequest;
321
+ /** Absolute URL; the API appends `?checkout=<id>` to it. */
322
+ return_url: string;
323
+ note?: string;
324
+ };
325
+ type CheckoutPayment = {
326
+ provider: string;
327
+ status: string;
328
+ redirect_url?: string | null;
329
+ client_secret?: string | null;
330
+ /** What to do next (provider addons): `redirect`, `embed`, `voucher` or `none`. */
331
+ action_type?: string | null;
332
+ /** Isolated iframe URL of an embedded payment widget. */
333
+ embed_url?: string | null;
334
+ /** Offline instructions as data (OXXO reference, SPEI CLABE, deadline...). */
335
+ instructions_data?: Record<string, unknown>;
336
+ /** Offline payment instructions (OXXO reference, SPEI CLABE, manual transfer data) as text; `null` when none. */
337
+ instructions?: string | null;
338
+ };
339
+ type CheckoutInfo = {
340
+ /** Checkout session id; use it with `payment.instructions`. */
341
+ id: string;
342
+ /** e.g. `pending`, `paid`, `failed`, `cancelled`, `converted`. */
343
+ status: string;
344
+ external_order_id: string;
345
+ /** Amount to charge, computed by OPS (includes shipping and taxes). */
346
+ total: Money;
347
+ /** RFC 3339. Stock is held until then; `null` when nothing is held. */
348
+ stock_hold_expires_at: string | null;
349
+ };
350
+ type CheckoutResult = {
351
+ /** `number` is `null` until the order exists in OPS (it is created asynchronously after checkout). */
352
+ order: {
353
+ id: string;
354
+ number: string | null;
355
+ };
356
+ payment: CheckoutPayment;
357
+ checkout: CheckoutInfo;
358
+ };
359
+ type Customer = {
360
+ id: string;
361
+ email: string | null;
362
+ phone: string | null;
363
+ first_name: string | null;
364
+ last_name: string | null;
365
+ default_address_id: string | null;
366
+ created_at: string;
367
+ };
368
+ type CustomerIdentifier = {
369
+ email: string;
370
+ phone?: never;
371
+ } | {
372
+ phone: string;
373
+ email?: never;
374
+ };
375
+ type CustomerSessionInput = CustomerIdentifier & {
376
+ code: string;
377
+ };
378
+ type CustomerSession = {
379
+ token: string;
380
+ expires_at: string;
381
+ customer: Customer;
382
+ };
383
+ type OrderLine = {
384
+ title: string;
385
+ variant_title: string | null;
386
+ sku: string | null;
387
+ quantity: number;
388
+ unit: Money;
389
+ total: Money;
390
+ image: Image | null;
391
+ };
392
+ type Order = {
393
+ id: string;
394
+ number: string;
395
+ status: string;
396
+ created_at: string;
397
+ total: Money;
398
+ lines: OrderLine[];
399
+ };
400
+ type ReturnRequestInput = {
401
+ lines: {
402
+ sku: string;
403
+ quantity: number;
404
+ }[];
405
+ reason?: string;
406
+ };
407
+ type ReturnRequest = {
408
+ id: string;
409
+ order_id: string;
410
+ status: string;
411
+ };
412
+ type InvoiceResult = {
413
+ status: string;
414
+ url?: string | null;
415
+ };
416
+ type Theme = {
417
+ /** Design tokens, e.g. `{ primary: '#0f766e', 'primary-foreground': '#ffffff' }`. */
418
+ tokens: Record<string, string>;
419
+ /** Font roles, e.g. `{ heading: 'Inter', body: 'Inter' }`. */
420
+ fonts: Record<string, string>;
421
+ /** Base radius as a CSS length, e.g. `0.5rem`. */
422
+ radius: string;
423
+ };
424
+ type Section<P extends Record<string, unknown> = Record<string, unknown>> = {
425
+ id: string;
426
+ type: string;
427
+ props: P;
428
+ };
429
+ type Page = {
430
+ handle: string;
431
+ title: string;
432
+ seo: SEO;
433
+ sections: Section[];
434
+ };
435
+ type MenuItem = {
436
+ title: string;
437
+ url: string;
438
+ items?: MenuItem[];
439
+ };
440
+ type Menu = {
441
+ handle?: string;
442
+ items: MenuItem[];
443
+ };
444
+ type Article = {
445
+ id: string;
446
+ handle: string;
447
+ title: string;
448
+ excerpt: string | null;
449
+ content_html: string;
450
+ image: Image | null;
451
+ author: string | null;
452
+ tags: string[];
453
+ published_at: string;
454
+ seo: SEO;
455
+ };
456
+ type StorefrontErrorCode = 'validation' | 'unauthorized' | 'forbidden' | 'not_found' | 'conflict' | 'insufficient_stock' | 'price_mismatch' | 'invalid_state' | 'rate_limited' | 'not_modified' | 'server_error' | 'network' | 'timeout' | 'aborted' | 'invalid_response' | (string & {});
457
+ type StorefrontErrorBody = {
458
+ error: {
459
+ code: StorefrontErrorCode;
460
+ message: string;
461
+ field?: string;
462
+ };
463
+ };
464
+
465
+ export type { SelectedOption as $, Address as A, MenuItem as B, Cart as C, DeliveryInput as D, Money as E, Facet as F, MoneyRange as G, OrderLine as H, Image as I, PageInfo as J, PaymentMethod as K, PaymentMethods as L, Menu as M, PickupOption as N, Order as O, Page as P, Product as Q, ProductAttributeValue as R, ProductCategory as S, ProductConnection as T, ProductOption as U, ProductSort as V, ProductVariant as W, ReturnRequest as X, ReturnRequestInput as Y, SEO as Z, Section as _, AddressInput as a, ShippingRate as a0, Shop as a1, ShopBranch as a2, ShopContact as a3, ShopPolicies as a4, StockLevel as a5, StorefrontErrorBody as a6, StorefrontErrorCode as a7, Theme as a8, UnavailableRateProvider as a9, Article as b, CartBuyer as c, CartBuyerInput as d, CartCost as e, CartDelivery as f, CartDiscountCode as g, CartLine as h, CartLineInput as i, CartLineMerchandise as j, CartLineUpdateInput as k, CheckoutInfo as l, CheckoutInput as m, CheckoutPayment as n, CheckoutResult as o, Collection as p, Connection as q, Customer as r, CustomerIdentifier as s, CustomerSession as t, CustomerSessionInput as u, DeliveryMethod as v, DeliveryOptions as w, FacetValue as x, InvoiceRequest as y, InvoiceResult as z };