@webround/commerce 0.0.0-stage → 0.3.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.
Files changed (138) hide show
  1. package/README.md +192 -2
  2. package/dist/account/account.d.ts +54 -0
  3. package/dist/account/account.js +40 -0
  4. package/dist/account/index.d.ts +3 -0
  5. package/dist/account/index.js +2 -0
  6. package/dist/addresses/api.d.ts +16 -0
  7. package/dist/addresses/api.js +13 -0
  8. package/dist/addresses/book.d.ts +40 -0
  9. package/dist/addresses/book.js +144 -0
  10. package/dist/addresses/index.d.ts +8 -0
  11. package/dist/addresses/index.js +5 -0
  12. package/dist/addresses/rules.d.ts +4 -0
  13. package/dist/addresses/rules.js +9 -0
  14. package/dist/addresses/types.d.ts +48 -0
  15. package/dist/addresses/types.js +6 -0
  16. package/dist/auth/api.d.ts +43 -0
  17. package/dist/auth/api.js +22 -0
  18. package/dist/auth/auth.d.ts +32 -0
  19. package/dist/auth/auth.js +23 -0
  20. package/dist/auth/cookies.d.ts +46 -0
  21. package/dist/auth/cookies.js +156 -0
  22. package/dist/auth/index.d.ts +14 -0
  23. package/dist/auth/index.js +8 -0
  24. package/dist/auth/renewal.d.ts +4 -0
  25. package/dist/auth/renewal.js +37 -0
  26. package/dist/auth/store.d.ts +70 -0
  27. package/dist/auth/store.js +284 -0
  28. package/dist/auth/types.d.ts +105 -0
  29. package/dist/auth/types.js +5 -0
  30. package/dist/auth/wake.d.ts +18 -0
  31. package/dist/auth/wake.js +23 -0
  32. package/dist/cache.d.ts +49 -0
  33. package/dist/cache.js +144 -0
  34. package/dist/canonical.d.ts +7 -0
  35. package/dist/canonical.js +32 -0
  36. package/dist/cart/api.d.ts +25 -0
  37. package/dist/cart/api.js +16 -0
  38. package/dist/cart/index.d.ts +10 -0
  39. package/dist/cart/index.js +6 -0
  40. package/dist/cart/lines.d.ts +15 -0
  41. package/dist/cart/lines.js +23 -0
  42. package/dist/cart/storage.d.ts +30 -0
  43. package/dist/cart/storage.js +82 -0
  44. package/dist/cart/store.d.ts +58 -0
  45. package/dist/cart/store.js +218 -0
  46. package/dist/cart/types.d.ts +194 -0
  47. package/dist/cart/types.js +11 -0
  48. package/dist/catalog/cached.d.ts +47 -0
  49. package/dist/catalog/cached.js +52 -0
  50. package/dist/catalog/catalog.d.ts +10 -0
  51. package/dist/catalog/catalog.js +7 -0
  52. package/dist/catalog/named.d.ts +3 -0
  53. package/dist/catalog/named.js +7 -0
  54. package/dist/catalog/products.d.ts +28 -0
  55. package/dist/catalog/products.js +12 -0
  56. package/dist/catalog/store-data.d.ts +13 -0
  57. package/dist/catalog/store-data.js +6 -0
  58. package/dist/catalog/types.d.ts +430 -0
  59. package/dist/catalog/types.js +4 -0
  60. package/dist/checkout/api.d.ts +14 -0
  61. package/dist/checkout/api.js +7 -0
  62. package/dist/checkout/errors.d.ts +23 -0
  63. package/dist/checkout/errors.js +18 -0
  64. package/dist/checkout/index.d.ts +10 -0
  65. package/dist/checkout/index.js +6 -0
  66. package/dist/checkout/return-urls.d.ts +7 -0
  67. package/dist/checkout/return-urls.js +11 -0
  68. package/dist/checkout/store.d.ts +98 -0
  69. package/dist/checkout/store.js +179 -0
  70. package/dist/checkout/types.d.ts +225 -0
  71. package/dist/checkout/types.js +28 -0
  72. package/dist/commerce.d.ts +55 -0
  73. package/dist/commerce.js +55 -0
  74. package/dist/customer-resources.d.ts +18 -0
  75. package/dist/customer-resources.js +40 -0
  76. package/dist/errors.d.ts +65 -0
  77. package/dist/errors.js +96 -0
  78. package/dist/http.d.ts +49 -0
  79. package/dist/http.js +94 -0
  80. package/dist/index.d.ts +32 -0
  81. package/dist/index.js +22 -0
  82. package/dist/orders/api.d.ts +16 -0
  83. package/dist/orders/api.js +13 -0
  84. package/dist/orders/index.d.ts +6 -0
  85. package/dist/orders/index.js +3 -0
  86. package/dist/orders/orders.d.ts +19 -0
  87. package/dist/orders/orders.js +18 -0
  88. package/dist/orders/types.d.ts +88 -0
  89. package/dist/orders/types.js +4 -0
  90. package/dist/resource.d.ts +19 -0
  91. package/dist/resource.js +15 -0
  92. package/dist/returns/api.d.ts +27 -0
  93. package/dist/returns/api.js +19 -0
  94. package/dist/returns/index.d.ts +6 -0
  95. package/dist/returns/index.js +3 -0
  96. package/dist/returns/returns.d.ts +30 -0
  97. package/dist/returns/returns.js +31 -0
  98. package/dist/returns/types.d.ts +99 -0
  99. package/dist/returns/types.js +2 -0
  100. package/dist/reviews/api.d.ts +19 -0
  101. package/dist/reviews/api.js +15 -0
  102. package/dist/reviews/index.d.ts +9 -0
  103. package/dist/reviews/index.js +5 -0
  104. package/dist/reviews/reviews.d.ts +23 -0
  105. package/dist/reviews/reviews.js +37 -0
  106. package/dist/reviews/rules.d.ts +8 -0
  107. package/dist/reviews/rules.js +7 -0
  108. package/dist/reviews/types.d.ts +54 -0
  109. package/dist/reviews/types.js +10 -0
  110. package/dist/shop/address-store.d.ts +14 -0
  111. package/dist/shop/address-store.js +28 -0
  112. package/dist/shop/address.d.ts +12 -0
  113. package/dist/shop/address.js +95 -0
  114. package/dist/shop/index.d.ts +16 -0
  115. package/dist/shop/index.js +9 -0
  116. package/dist/shop/question.d.ts +15 -0
  117. package/dist/shop/question.js +12 -0
  118. package/dist/shop/range.d.ts +7 -0
  119. package/dist/shop/range.js +38 -0
  120. package/dist/shop/sort.d.ts +19 -0
  121. package/dist/shop/sort.js +18 -0
  122. package/dist/shop/state.d.ts +47 -0
  123. package/dist/shop/state.js +51 -0
  124. package/dist/shop/store.d.ts +26 -0
  125. package/dist/shop/store.js +47 -0
  126. package/dist/shop/to-search.d.ts +14 -0
  127. package/dist/shop/to-search.js +53 -0
  128. package/dist/store-kit.d.ts +39 -0
  129. package/dist/store-kit.js +81 -0
  130. package/dist/wishlist/api.d.ts +12 -0
  131. package/dist/wishlist/api.js +10 -0
  132. package/dist/wishlist/index.d.ts +7 -0
  133. package/dist/wishlist/index.js +4 -0
  134. package/dist/wishlist/types.d.ts +30 -0
  135. package/dist/wishlist/types.js +4 -0
  136. package/dist/wishlist/wishlist.d.ts +45 -0
  137. package/dist/wishlist/wishlist.js +84 -0
  138. package/package.json +39 -5
@@ -0,0 +1,430 @@
1
+ /** What every call of the catalog can be given besides what it asks. */
2
+ export interface CallOptions {
3
+ /** To give up on the call. */
4
+ signal?: AbortSignal;
5
+ }
6
+ export type ProductSortField = 'createdAt' | 'updatedAt' | 'alphabetical' | 'price' | 'match' | 'availability' | `attribute:${string}` | `tag:${string}`;
7
+ export type SortDirection = 'asc' | 'desc';
8
+ /** What a product is loaded with: the shape of the answer does not change (the lists are always there), only what is in them. */
9
+ export interface ProductLoad {
10
+ includeAssets?: boolean;
11
+ includeTagValues?: boolean;
12
+ includeAttributes?: boolean;
13
+ includeOptions?: boolean;
14
+ includeVariantAssets?: boolean;
15
+ includeVariantTagValues?: boolean;
16
+ includeVariantAttributes?: boolean;
17
+ }
18
+ /** The body of `POST /public/products`. The server refuses a key it does not know (400), so there is no other. */
19
+ export interface ProductSearch extends ProductLoad {
20
+ /** Prices come in this currency (three letters: `EUR`). The one thing the server always asks for. */
21
+ currencyCode: string;
22
+ page?: number;
23
+ /** 1 to 100. */
24
+ limit?: number;
25
+ sortBy?: ProductSortField;
26
+ sortDirection?: SortDirection;
27
+ /** `once`, `daily`, `weekly`, `monthly`, `quarterly`, `semiannual` or `yearly` (another is refused). What prices are read and sorted in; sorting by price with none is sorting by `once`. */
28
+ cadence?: string;
29
+ /**
30
+ * The language the texts come in. `default` is the code of the store's DEFAULT language, whatever it is called (`it`, for a store whose default is Italian): it is always accepted. A language that is
31
+ * left out, or that the store does not use, is answered in the default one.
32
+ */
33
+ langCode?: string;
34
+ /**
35
+ * The filters to apply: a filter's id, or `<id>[<min>;<max>]` for a range of a range filter (either bound may be left empty: `[;100]`, `[10;]`; only `;` separates). Filters are combined with AND.
36
+ * Ids are matched as the store wrote them (in capitals they match nothing); one the store does not have is ignored, one that is not a UUID is refused. More than one range of the SAME filter is not
37
+ * something to send: the catalog keeps one of them.
38
+ */
39
+ filterIds?: readonly string[];
40
+ /** Tag values to filter by: values of the SAME tag are OR (either), values of different tags are AND (both). Ids as in `filterIds`. */
41
+ tagValueIds?: readonly string[];
42
+ /** A text to search for (1 to 255 characters). */
43
+ search?: string;
44
+ /** With a search, the filters are not applied. */
45
+ searchIgnoresFilters?: boolean;
46
+ includeNestedVariants?: boolean;
47
+ }
48
+ /** What the two ways of asking for ONE product have in common. A product is found by an id that is its own (a variant's slug, or the product's id): no page, no limit, no sorting. */
49
+ export interface ProductDetailInput extends ProductLoad {
50
+ currencyCode: string;
51
+ cadence?: string;
52
+ /** The language the texts come in: `default` is the store's default language (see `ProductSearch.langCode`); one the store does not use is answered in the default one. */
53
+ langCode?: string;
54
+ }
55
+ /** By a variant's slug the answer is the variant's product; this route reads `includeNestedVariants` (and not `includeAllVariants`). */
56
+ export interface ProductBySlugInput extends ProductDetailInput {
57
+ includeNestedVariants?: boolean;
58
+ }
59
+ /** By the product's id; this route reads `includeAllVariants` (and not `includeNestedVariants`). */
60
+ export interface ProductByIdInput extends ProductDetailInput {
61
+ includeAllVariants?: boolean;
62
+ }
63
+ /**
64
+ * The body of `POST /public/products/{id}/related`: which of the product's related ones, and what they are loaded with. The catalog checks it against the same schema as a product's
65
+ * detail (so a page, a limit or a sorting are accepted), but reads only what is here: the related ones are always the first ten, in order of relevance, and a product has no `includeOptions` here.
66
+ */
67
+ export interface ProductRelatedInput extends Omit<ProductLoad, 'includeOptions'> {
68
+ currencyCode: string;
69
+ cadence?: string;
70
+ /** The language the texts come in: `default` is the store's default language (see `ProductSearch.langCode`); one the store does not use is answered in the default one. */
71
+ langCode?: string;
72
+ includeNestedVariants?: boolean;
73
+ }
74
+ /** The body of `POST /public/products/{id}/reviews`: which reviews of a product, in which order. Everything is optional; what is left out is the server's to decide. */
75
+ export interface ProductReviewsInput {
76
+ page?: number;
77
+ /** 1 to 100. */
78
+ limit?: number;
79
+ sortBy?: 'createdAt' | 'rating';
80
+ sortDirection?: SortDirection;
81
+ /** Only the reviews with this grade. */
82
+ rating?: 1 | 2 | 3 | 4 | 5;
83
+ }
84
+ export type AssetType = 'image' | 'video' | 'document';
85
+ export type TagType = 'string' | 'number' | 'date';
86
+ export type ValueFormat = 'year' | 'month-year' | 'date' | 'datetime' | 'datetime+tz';
87
+ /**
88
+ * What an attribute or a tag says about how its value is written. The catalog documents `ValueFormat`, but a real one also sends `"number"` and `"string"` here (the type of the value, in the place of
89
+ * its format), so any text can come: the known ones are what an editor suggests.
90
+ */
91
+ export type Format = ValueFormat | (string & Record<never, never>);
92
+ export type Availability = 'not_available' | 'low_availability' | 'available';
93
+ export interface AssetSummary {
94
+ url: string;
95
+ type: AssetType;
96
+ position: number;
97
+ /** A video's picture. */
98
+ thumbnail?: string;
99
+ }
100
+ export interface TagValueSummary {
101
+ value: string;
102
+ alias?: string;
103
+ }
104
+ /** In a list there are only the tags that are marked relevant. */
105
+ export interface TagSummary {
106
+ name: string;
107
+ label?: string | null;
108
+ type: TagType;
109
+ format?: Format | null;
110
+ icon?: string | null;
111
+ relevant: boolean;
112
+ values: TagValueSummary[];
113
+ }
114
+ /** In a list there are only the attributes that are marked relevant. */
115
+ export interface AttributeSummary {
116
+ name: string;
117
+ label?: string | null;
118
+ relevant: boolean;
119
+ type: TagType;
120
+ format?: Format | null;
121
+ icon?: string | null;
122
+ value: string;
123
+ }
124
+ /** What something costs, for one currency and cadence: net, gross (with the tax rate of the visitor's country) and the price before a discount. */
125
+ export interface PriceRange {
126
+ cadence?: string;
127
+ currencyCode?: string;
128
+ netMin?: number;
129
+ netMax?: number;
130
+ grossMin?: number;
131
+ grossMax?: number;
132
+ compareNetMin?: number;
133
+ compareNetMax?: number;
134
+ compareGrossMin?: number;
135
+ compareGrossMax?: number;
136
+ rate?: number;
137
+ }
138
+ export interface VariantSummary {
139
+ id: string;
140
+ name: string;
141
+ slug: string;
142
+ /** The variant that is shown first. */
143
+ isFavourite: boolean;
144
+ productId: string;
145
+ availability: Availability;
146
+ /** At most 3. */
147
+ assets: AssetSummary[];
148
+ tags: TagSummary[];
149
+ attributes: AttributeSummary[];
150
+ quantity: number;
151
+ allowBackorder: boolean;
152
+ priceRanges: PriceRange[];
153
+ sku?: string;
154
+ }
155
+ export interface ReviewStats {
156
+ /** The average, 1 to 5 (0 with no reviews). */
157
+ rating: number;
158
+ count: number;
159
+ }
160
+ export interface ProductSummary {
161
+ id: string;
162
+ name?: string;
163
+ metadata: Record<string, unknown>;
164
+ /** At most 3. */
165
+ assets: AssetSummary[];
166
+ tags: TagSummary[];
167
+ attributes: AttributeSummary[];
168
+ reviews: ReviewStats;
169
+ /** One for each currency and cadence, over all the visible variants. */
170
+ priceRanges: PriceRange[];
171
+ /** At most 5, with different covers, the favourite ones first. */
172
+ variants: VariantSummary[];
173
+ /** How many visible variants are not in `variants`. */
174
+ remainingVariantsCount: number;
175
+ }
176
+ export interface Pagination {
177
+ page: number;
178
+ limit: number;
179
+ total: number;
180
+ totalPages: number;
181
+ }
182
+ /** The answer of `POST /public/products`. */
183
+ export interface ProductPage {
184
+ data: ProductSummary[];
185
+ pagination: Pagination;
186
+ }
187
+ export interface Review {
188
+ id: string;
189
+ /** The name of the customer who wrote it. */
190
+ customerName: string;
191
+ /** 1 to 5. */
192
+ rating: number;
193
+ title: string;
194
+ comment: string;
195
+ /** True when the customer had an order before they wrote it. */
196
+ verifiedPurchase: boolean;
197
+ createdAt: string | null;
198
+ updatedAt: string | null;
199
+ }
200
+ /** The answer of `POST /public/products/{id}/reviews`, as the catalog sends it. */
201
+ export interface ReviewPage {
202
+ data: Review[];
203
+ pagination: Pagination;
204
+ /** How many reviews there are for each grade, over all of the product's reviews that match `rating` (a grade nobody gave is not there). */
205
+ breakdown: Partial<Record<'1' | '2' | '3' | '4' | '5', number>>;
206
+ }
207
+ export interface AssetDetail {
208
+ id: string;
209
+ url: string;
210
+ type: AssetType;
211
+ position: number;
212
+ thumbnail?: string;
213
+ inherited: boolean;
214
+ }
215
+ export interface TagValueDetail {
216
+ id: string;
217
+ value: string;
218
+ alias?: string;
219
+ }
220
+ export interface TagDetail {
221
+ id: string;
222
+ name: string;
223
+ label?: string | null;
224
+ relevant: boolean;
225
+ sortable: boolean;
226
+ filterable: boolean;
227
+ type: TagType;
228
+ format?: Format | null;
229
+ icon?: string | null;
230
+ values: TagValueDetail[];
231
+ }
232
+ export interface AttributeDetail {
233
+ id: string;
234
+ name: string;
235
+ label?: string | null;
236
+ relevant: boolean;
237
+ sortable: boolean;
238
+ type: TagType;
239
+ format?: Format | null;
240
+ icon?: string | null;
241
+ value: string;
242
+ }
243
+ export interface OptionValueDetail {
244
+ optionId: string;
245
+ /** What a variant's `options` holds for this option when it has this value. */
246
+ optionValueId: string;
247
+ tagValueId: string;
248
+ /** The text of the value, in the language asked. */
249
+ tagValue: string;
250
+ position: number;
251
+ }
252
+ /** What a variant is chosen by (a colour, a size), with the values it can have. */
253
+ export interface OptionDetail {
254
+ id: string;
255
+ name: string;
256
+ type: 'tagValue';
257
+ position: number;
258
+ values: OptionValueDetail[];
259
+ }
260
+ /**
261
+ * A discount by quantity: from `min` to `max` (`null`: with no end) of a variant bought, the price has `discountValue` (a percentage, for `discountType: "percentage"`) off. The catalog declares
262
+ * `quantityTable` as `any`; this shape is the one seen on a real catalog (`rounding` was `"00"` and `"99"`) and the one the v1 template uses. Only `percentage` has been seen as a `discountType`.
263
+ */
264
+ export interface QuantityTier {
265
+ min: number;
266
+ max: number | null;
267
+ rounding: string;
268
+ discountType: string;
269
+ discountValue: number;
270
+ }
271
+ /** A price of a variant: the list price (`amount` is the net one) and what it is gross, with the tax rate of the visitor's country. */
272
+ export interface PriceDetail {
273
+ id: string;
274
+ currencyCode: string;
275
+ cadence: string;
276
+ amount: number;
277
+ comparePrice: number;
278
+ isDefault?: boolean;
279
+ /** `null` when the price has no discounts by quantity (seen on a real catalog). */
280
+ quantityTable?: QuantityTier[] | null;
281
+ netAmount: number;
282
+ grossAmount: number;
283
+ rate: number;
284
+ netCompare: number;
285
+ grossCompare: number;
286
+ }
287
+ export interface VariantDetail {
288
+ id: string;
289
+ name: string;
290
+ slug: string;
291
+ isFavourite: boolean;
292
+ productId: string;
293
+ availability: Availability;
294
+ assets: AssetDetail[];
295
+ tags: TagDetail[];
296
+ attributes: AttributeDetail[];
297
+ quantity: number;
298
+ allowBackorder: boolean;
299
+ /** One for each currency and cadence (the lists have `priceRanges` instead). */
300
+ prices: PriceDetail[];
301
+ metadata: Record<string, unknown>;
302
+ inheritAssets: boolean;
303
+ inheritAttributes: boolean;
304
+ inheritTagValues: boolean;
305
+ sku?: string;
306
+ ean?: string;
307
+ mpn?: string;
308
+ upc?: string;
309
+ gtin?: string;
310
+ isbn?: string;
311
+ asin?: string;
312
+ hsCode?: string;
313
+ supplierCode?: string;
314
+ /** The value this variant has for each option of the product: the option's id → the value's `optionValueId`. */
315
+ options: Record<string, string>;
316
+ }
317
+ export interface ProductDetail {
318
+ id: string;
319
+ name?: string;
320
+ /** HTML. */
321
+ description?: string;
322
+ metadata: Record<string, unknown>;
323
+ assets: AssetDetail[];
324
+ tags: TagDetail[];
325
+ options: OptionDetail[];
326
+ attributes: AttributeDetail[];
327
+ reviews: ReviewStats;
328
+ /** All the visible variants. */
329
+ variants: VariantDetail[];
330
+ }
331
+ /** The answer of `POST /public/products/by-slug/{slug}` and `POST /public/products/{id}`, as the catalog sends it. */
332
+ export interface ProductDetailResponse {
333
+ data: ProductDetail;
334
+ }
335
+ /** The store's own settings. What the server has not got comes with its default (`EUR`, `once`, `IT`, `default`, a list with the default one). */
336
+ export interface StoreSettings {
337
+ defaultCurrencyCode: string;
338
+ defaultCadence: string;
339
+ defaultCountryCode: string;
340
+ /** What the store's default language is (`it`). To ask for it, a query says `default`, not this: see `ProductSearch.langCode`. `languages` are the OTHER languages the store has. */
341
+ defaultLangCode: string;
342
+ languages: string[];
343
+ currencies: string[];
344
+ cadences: string[];
345
+ /** The link to Stripe's customer portal, to manage a subscription: an empty text when the store has none. */
346
+ stripeCustomerPortalUrl: string;
347
+ }
348
+ export interface StoreTagValue {
349
+ id: string;
350
+ value: string;
351
+ alias: string | null;
352
+ position: number;
353
+ /** How many visible products have it. */
354
+ count: number;
355
+ }
356
+ /** The tags a customer can filter by (the visible and filterable ones), with their values in the language asked. */
357
+ export interface StoreTag {
358
+ id: string;
359
+ name: string;
360
+ label: string | null;
361
+ type: TagType;
362
+ format: Format | null;
363
+ sortable: boolean;
364
+ relevant: boolean;
365
+ icon: string | null;
366
+ position: number;
367
+ values: StoreTagValue[];
368
+ }
369
+ /** The attributes products can be sorted by (the visible and sortable ones). */
370
+ export interface StoreAttribute {
371
+ id: string;
372
+ name: string;
373
+ label: string | null;
374
+ type: TagType;
375
+ format: Format | null;
376
+ relevant: boolean;
377
+ sortable: boolean;
378
+ icon: string | null;
379
+ position: number | null;
380
+ }
381
+ /** A visible collection, with the visible ones inside it: a tree. `filterIds` are what the products of the collection are filtered by (they go in a search's `filterIds`). */
382
+ export interface StoreCollection {
383
+ id: string;
384
+ name: string;
385
+ slug: string;
386
+ parentId?: string | null;
387
+ position: number | null;
388
+ visible: boolean;
389
+ filterIds: string[];
390
+ children: StoreCollection[];
391
+ }
392
+ export interface StoreFilterCondition {
393
+ id: string;
394
+ /** `range`, … */
395
+ operator: string;
396
+ min: number | null;
397
+ max: number | null;
398
+ /** `price`, `number`, `date`, or another. */
399
+ type: string | null;
400
+ attributeId: string | null;
401
+ attribute: {
402
+ id: string;
403
+ type: TagType;
404
+ name: string;
405
+ format: Format | null;
406
+ } | null;
407
+ }
408
+ /** The filters a customer can set: the visible ones that have a range condition (a price, a number, a date). */
409
+ export interface StoreFilter {
410
+ id: string;
411
+ name: string;
412
+ operator: 'AND' | 'OR';
413
+ position: number | null;
414
+ visible: boolean;
415
+ conditionIds: string[];
416
+ type: 'price' | 'date' | 'number';
417
+ conditions: StoreFilterCondition[];
418
+ }
419
+ export interface StoreData {
420
+ store: StoreSettings;
421
+ tags: StoreTag[];
422
+ attributes: StoreAttribute[];
423
+ collections: StoreCollection[];
424
+ filters: StoreFilter[];
425
+ }
426
+ /** The answer of `GET /public/store_data`, as the catalog sends it. */
427
+ export interface StoreDataResponse {
428
+ data: StoreData;
429
+ }
430
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,4 @@
1
+ // What the catalog (`wr-commerce-catalog`) takes and answers, written from what its code does (ProductMapper), not from its OpenAPI document. Nothing here is a default of the server's:
2
+ // what is not said is for the server to decide.
3
+ export {};
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,14 @@
1
+ import type { HttpClient } from '../http.js';
2
+ import type { CallOptions } from '../catalog/types.js';
3
+ import type { PayAnswer, PayInput, Quote, QuoteInput } from './types.js';
4
+ export interface CheckoutApi {
5
+ /**
6
+ * `POST /v2/checkout/quote`: what the customer would pay for this cart, with the store's rules and hooks applied. It changes nothing in the store, so it can be asked as often as needed, and it is always asked
7
+ * again (availability and prices change). A refusal says why: `CHECKOUT_BLOCKED`, `CHECKOUT_HOOK_FAILED`, `SHIPPING_METHOD_UNAVAILABLE`, or an HTTP 400 for the cart itself (stock, quantities, delivery, the address).
8
+ */
9
+ quote(input: QuoteInput, options?: CallOptions): Promise<Quote>;
10
+ /** `POST /v2/checkout/stripe`: starts the payment. It reserves the stock and makes the order, so it is asked once; the answer is the payment page to send the customer to. Refuses what `quote` refuses. */
11
+ pay(input: PayInput, options?: CallOptions): Promise<PayAnswer>;
12
+ }
13
+ export declare function createCheckoutApi(http: HttpClient): CheckoutApi;
14
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1,7 @@
1
+ export function createCheckoutApi(http) {
2
+ return {
3
+ quote: (input, options) => http.request({ method: 'POST', path: '/v2/checkout/quote', body: input, signal: options?.signal }),
4
+ pay: (input, options) => http.request({ method: 'POST', path: '/v2/checkout/stripe', body: input, signal: options?.signal }),
5
+ };
6
+ }
7
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1,23 @@
1
+ import { CHECKOUT_ERROR_CODES, type CheckoutBlockTarget } from './types.js';
2
+ export type CheckoutRefusal = {
3
+ code: typeof CHECKOUT_ERROR_CODES.blocked;
4
+ meta: {
5
+ hookId: string;
6
+ code: string;
7
+ target: CheckoutBlockTarget;
8
+ };
9
+ } | {
10
+ code: typeof CHECKOUT_ERROR_CODES.hookFailed;
11
+ meta: {
12
+ hookId: string;
13
+ reason: string;
14
+ };
15
+ } | {
16
+ code: typeof CHECKOUT_ERROR_CODES.shippingMethodUnavailable;
17
+ meta: {
18
+ shippingMethodId: string;
19
+ };
20
+ };
21
+ /** What the checkout refused with a code of its own (a hook stopped it, a hook failed, the shipping method is not available), or `null` for any other error. */
22
+ export declare function checkoutRefusalOf(error: unknown): CheckoutRefusal | null;
23
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { isCommerceError } from '../errors.js';
2
+ import { CHECKOUT_ERROR_CODES } from './types.js';
3
+ /** What the checkout refused with a code of its own (a hook stopped it, a hook failed, the shipping method is not available), or `null` for any other error. */
4
+ export function checkoutRefusalOf(error) {
5
+ if (!isCommerceError(error))
6
+ return null;
7
+ switch (error.code) {
8
+ case CHECKOUT_ERROR_CODES.blocked:
9
+ return { code: CHECKOUT_ERROR_CODES.blocked, meta: error.meta };
10
+ case CHECKOUT_ERROR_CODES.hookFailed:
11
+ return { code: CHECKOUT_ERROR_CODES.hookFailed, meta: error.meta };
12
+ case CHECKOUT_ERROR_CODES.shippingMethodUnavailable:
13
+ return { code: CHECKOUT_ERROR_CODES.shippingMethodUnavailable, meta: error.meta };
14
+ default:
15
+ return null;
16
+ }
17
+ }
18
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,10 @@
1
+ export { createCheckoutApi } from './api.js';
2
+ export type { CheckoutApi } from './api.js';
3
+ export { checkoutRefusalOf } from './errors.js';
4
+ export type { CheckoutRefusal } from './errors.js';
5
+ export { browserReturnUrls } from './return-urls.js';
6
+ export { createCheckoutStore } from './store.js';
7
+ export type { CheckoutState, CheckoutStore, CheckoutStoreOptions } from './store.js';
8
+ export { CHECKOUT_ERROR_CODES, DELIVERY_METHODS, PROMOTION_REJECTION_REASONS } from './types.js';
9
+ export type { CheckoutAddress, CheckoutBlockTarget, DeliveryMethod, InvoiceInput, PayAnswer, PayInput, PromotionRejectionReason, Quote, QuoteDiscount, QuoteDiscountSource, QuoteDiscountTarget, QuoteInput, QuoteLine, QuoteLinePresentation, QuoteUnavailableLine, QuotePromotions, QuoteShippingOption, QuoteTotals, ReturnUrls, } from './types.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,6 @@
1
+ export { createCheckoutApi } from './api.js';
2
+ export { checkoutRefusalOf } from './errors.js';
3
+ export { browserReturnUrls } from './return-urls.js';
4
+ export { createCheckoutStore } from './store.js';
5
+ export { CHECKOUT_ERROR_CODES, DELIVERY_METHODS, PROMOTION_REJECTION_REASONS } from './types.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ import type { ReturnUrls } from './types.js';
2
+ /**
3
+ * Where the customer comes back to when the site says nothing else: this page's own origin, the success page (`/checkout/success`, which empties the cart when it finds `clean_cart=true`) and the home page for giving
4
+ * up. The same the site's checkout has always sent. Without a page (a server) it says nothing, and the store's own pages are used. A site that wants others gives them to `pay` or to `createCommerce`.
5
+ */
6
+ export declare function browserReturnUrls(): ReturnUrls;
7
+ //# sourceMappingURL=return-urls.d.ts.map
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Where the customer comes back to when the site says nothing else: this page's own origin, the success page (`/checkout/success`, which empties the cart when it finds `clean_cart=true`) and the home page for giving
3
+ * up. The same the site's checkout has always sent. Without a page (a server) it says nothing, and the store's own pages are used. A site that wants others gives them to `pay` or to `createCommerce`.
4
+ */
5
+ export function browserReturnUrls() {
6
+ const origin = globalThis.location?.origin;
7
+ if (!origin || origin === 'null')
8
+ return {};
9
+ return { successUrl: `${origin}/checkout/success?clean_cart=true`, cancelUrl: `${origin}/` };
10
+ }
11
+ //# sourceMappingURL=return-urls.js.map
@@ -0,0 +1,98 @@
1
+ import { CommerceError } from '../errors.js';
2
+ import type { CartLineInput } from '../cart/types.js';
3
+ import type { CheckoutApi } from './api.js';
4
+ import { type CheckoutAddress, type DeliveryMethod, type PayAnswer, type Quote, type ReturnUrls } from './types.js';
5
+ export interface CheckoutState {
6
+ /** How each variant of the cart reaches the customer, by variant id. A variant with no choice here is asked to the store without one (and the store says so). */
7
+ deliveryMethods: Record<string, DeliveryMethod>;
8
+ shippingAddress: CheckoutAddress | null;
9
+ billingAddress: CheckoutAddress | null;
10
+ /** The shipping method chosen from the preview's options, or null. */
11
+ shippingMethodId: string | null;
12
+ promotionCodes: string[];
13
+ additionalData: Record<string, unknown> | null;
14
+ /** Who pays: for a guest, who the order is for. Not part of the preview. */
15
+ email: string;
16
+ requestsInvoice: boolean;
17
+ invoiceVatCode: string | null;
18
+ invoiceRecipientCode: string | null;
19
+ /** What the store said it costs, or null until it said. While `isStale`, it is the answer to something the customer has since changed. */
20
+ quote: Quote | null;
21
+ /** What the preview would ask NOW (the cart and the choices that matter to it): a change that leaves it as it was (the email, the invoice) does not make the preview out of date. */
22
+ requestKey: string;
23
+ /** What the preview on show was asked, or null. */
24
+ quotedKey: string | null;
25
+ /** `quote` is not the answer to what would be asked now. */
26
+ isStale: boolean;
27
+ /** How many lines the cart has (the preview asks nothing of an empty one). */
28
+ lineCount: number;
29
+ quoting: boolean;
30
+ paying: boolean;
31
+ /** Why the last preview failed (it goes when one works); an action's own failure is thrown, not kept. */
32
+ error: CommerceError | null;
33
+ }
34
+ export interface CheckoutStore {
35
+ getState(): CheckoutState;
36
+ subscribe(listener: () => void): () => void;
37
+ /** Starts following the cart: a change of its lines or of whose it is makes the preview out of date. Once. */
38
+ start(): void;
39
+ /** How this variant reaches the customer. */
40
+ setDeliveryMethod(variantId: string, method: DeliveryMethod): void;
41
+ setShippingAddress(address: CheckoutAddress | null): void;
42
+ setBillingAddress(address: CheckoutAddress | null): void;
43
+ /** The shipping method the customer chose (one of the preview's options), or null for none. */
44
+ selectShippingMethod(id: string | null): void;
45
+ setPromotionCodes(codes: readonly string[]): void;
46
+ setAdditionalData(data: Record<string, unknown> | null): void;
47
+ setEmail(email: string): void;
48
+ /** An invoice asked for or not, with the codes it needs. */
49
+ setInvoice(invoice: {
50
+ requested: boolean;
51
+ vatCode?: string | null;
52
+ recipientCode?: string | null;
53
+ }): void;
54
+ /**
55
+ * Asks the store what the cart costs with these choices, and keeps the answer in `state.quote`. Asked again while one is on its way, the first is cancelled (and throws `aborted`). Throws what the store refuses
56
+ * (see `checkoutRefusalOf`); the same refusal is left in `state.error`, and the last good preview stays on show as stale.
57
+ */
58
+ quote(options?: {
59
+ signal?: AbortSignal;
60
+ }): Promise<Quote>;
61
+ /**
62
+ * What a page does by itself when the cart or the choices change: asks the preview, unless the cart is empty or this very question was already asked (by anyone: a refusal is not asked again by itself, and
63
+ * any number of components can call this). Resolves `null` when it asked nothing; otherwise what `quote` does.
64
+ */
65
+ ensureQuote(): Promise<Quote | null>;
66
+ /**
67
+ * Starts the payment: the store reserves the stock, makes the order and gives the page to send the customer to (`url`). `returnUrls` says where they come back to (both or neither; the checkout's `returnUrls` option
68
+ * when not given). Asked once per order: it is not asked again by this store. Throws what the store refuses.
69
+ */
70
+ pay(returnUrls?: ReturnUrls): Promise<PayAnswer>;
71
+ /** Everything chosen and the preview, forgotten: the customer starts again. */
72
+ reset(): void;
73
+ /** The payment is done (the success page): the cart is emptied (a guest's here; a customer's was emptied by the store, and is read again) and the checkout is forgotten. */
74
+ complete(): Promise<void>;
75
+ /** Stops following the cart. */
76
+ dispose(): void;
77
+ }
78
+ export interface CheckoutStoreOptions {
79
+ api: CheckoutApi;
80
+ /** The cart the checkout is for: only what is needed to follow it. */
81
+ cart: {
82
+ getState(): {
83
+ owner: string;
84
+ lines: CartLineInput[];
85
+ };
86
+ subscribe(listener: () => void): () => void;
87
+ };
88
+ /** Webround Commerce's id of this cart: the same for a guest and for the customer they become. */
89
+ trackingId: () => string;
90
+ /** The language the store answers in: read at each call (`default` when there is none). */
91
+ langCode?: () => string | undefined;
92
+ /** Where the customer comes back to after paying: read when `pay` is not given any. Nothing = the store's own pages. */
93
+ returnUrls?: () => ReturnUrls | undefined;
94
+ /** Empties the cart (`complete`). */
95
+ clearCart: () => Promise<void>;
96
+ }
97
+ export declare function createCheckoutStore(options: CheckoutStoreOptions): CheckoutStore;
98
+ //# sourceMappingURL=store.d.ts.map