@shoplix-ai/sdui-schema 1.3.0 → 1.5.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/dist/binding.d.ts +26 -4
- package/dist/binding.d.ts.map +1 -1
- package/dist/binding.js +23 -3
- package/dist/binding.js.map +1 -1
- package/dist/block-definition.d.ts +85 -13
- package/dist/block-definition.d.ts.map +1 -1
- package/dist/block-definition.js +29 -5
- package/dist/block-definition.js.map +1 -1
- package/dist/blocks.d.ts +277 -6
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +33 -0
- package/dist/blocks.js.map +1 -1
- package/dist/definition-validator.d.ts +2 -0
- package/dist/definition-validator.d.ts.map +1 -1
- package/dist/definition-validator.js +30 -0
- package/dist/definition-validator.js.map +1 -1
- package/dist/display.d.ts +163 -7
- package/dist/display.d.ts.map +1 -1
- package/dist/display.js +69 -8
- package/dist/display.js.map +1 -1
- package/dist/envelope.d.ts +148 -22
- package/dist/envelope.d.ts.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/manifest.d.ts +2 -0
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js.map +1 -1
- package/dist/parse.d.ts +2 -1
- package/dist/parse.d.ts.map +1 -1
- package/dist/parse.js +4 -1
- package/dist/parse.js.map +1 -1
- package/dist/screen.d.ts +27 -5
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +39 -1
- package/dist/screen.js.map +1 -1
- package/dist/theme.d.ts +1 -1
- package/package.json +1 -1
package/dist/display.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
/**
|
|
3
|
-
* Display
|
|
4
|
-
*
|
|
5
|
-
* the charged price
|
|
3
|
+
* Display money: a ready-to-render string, its currency code, and the decimal
|
|
4
|
+
* amount it was formatted from. A block may derive a display-only figure from
|
|
5
|
+
* amounts in one currency; the charged price and the total a buyer sees are
|
|
6
|
+
* always Shopify's, never a device-side sum.
|
|
6
7
|
*/
|
|
7
8
|
export declare const displayMoneySchema: z.ZodObject<{
|
|
8
9
|
formatted: z.ZodString;
|
|
9
10
|
currencyCode: z.ZodString;
|
|
11
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
10
12
|
}, z.core.$strict>;
|
|
11
13
|
export declare const displayImageSchema: z.ZodObject<{
|
|
12
14
|
url: z.ZodURL;
|
|
@@ -36,10 +38,12 @@ export declare const productVariantSchema: z.ZodObject<{
|
|
|
36
38
|
price: z.ZodOptional<z.ZodObject<{
|
|
37
39
|
formatted: z.ZodString;
|
|
38
40
|
currencyCode: z.ZodString;
|
|
41
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
39
42
|
}, z.core.$strict>>;
|
|
40
43
|
compareAtPrice: z.ZodOptional<z.ZodObject<{
|
|
41
44
|
formatted: z.ZodString;
|
|
42
45
|
currencyCode: z.ZodString;
|
|
46
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
43
47
|
}, z.core.$strict>>;
|
|
44
48
|
}, z.core.$strict>;
|
|
45
49
|
/**
|
|
@@ -61,10 +65,12 @@ export declare const productDisplaySchema: z.ZodObject<{
|
|
|
61
65
|
price: z.ZodObject<{
|
|
62
66
|
formatted: z.ZodString;
|
|
63
67
|
currencyCode: z.ZodString;
|
|
68
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
64
69
|
}, z.core.$strict>;
|
|
65
70
|
compareAtPrice: z.ZodOptional<z.ZodObject<{
|
|
66
71
|
formatted: z.ZodString;
|
|
67
72
|
currencyCode: z.ZodString;
|
|
73
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
68
74
|
}, z.core.$strict>>;
|
|
69
75
|
available: z.ZodBoolean;
|
|
70
76
|
images: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
@@ -91,10 +97,12 @@ export declare const productDisplaySchema: z.ZodObject<{
|
|
|
91
97
|
price: z.ZodOptional<z.ZodObject<{
|
|
92
98
|
formatted: z.ZodString;
|
|
93
99
|
currencyCode: z.ZodString;
|
|
100
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
94
101
|
}, z.core.$strict>>;
|
|
95
102
|
compareAtPrice: z.ZodOptional<z.ZodObject<{
|
|
96
103
|
formatted: z.ZodString;
|
|
97
104
|
currencyCode: z.ZodString;
|
|
105
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
98
106
|
}, z.core.$strict>>;
|
|
99
107
|
}, z.core.$strict>>>;
|
|
100
108
|
}, z.core.$strict>;
|
|
@@ -109,12 +117,150 @@ export declare const collectionDisplaySchema: z.ZodObject<{
|
|
|
109
117
|
height: z.ZodOptional<z.ZodNumber>;
|
|
110
118
|
}, z.core.$strict>>;
|
|
111
119
|
}, z.core.$strict>;
|
|
120
|
+
/** One custom attribute a buyer or a block put on a line or the cart: a key and a value. */
|
|
121
|
+
export declare const cartAttributeSchema: z.ZodObject<{
|
|
122
|
+
key: z.ZodString;
|
|
123
|
+
value: z.ZodString;
|
|
124
|
+
}, z.core.$strict>;
|
|
125
|
+
/**
|
|
126
|
+
* One line of the held cart as Shopify answered it and the Provider formatted
|
|
127
|
+
* it: what the buyer holds, of which product and variant, at what price. The
|
|
128
|
+
* compare-at total and the discount amount are present only where Shopify
|
|
129
|
+
* gave one.
|
|
130
|
+
*/
|
|
131
|
+
export declare const cartLineDisplaySchema: z.ZodObject<{
|
|
132
|
+
id: z.ZodString;
|
|
133
|
+
variantId: z.ZodString;
|
|
134
|
+
productId: z.ZodString;
|
|
135
|
+
productTitle: z.ZodString;
|
|
136
|
+
variantTitle: z.ZodString;
|
|
137
|
+
vendor: z.ZodOptional<z.ZodString>;
|
|
138
|
+
selectedOptions: z.ZodArray<z.ZodObject<{
|
|
139
|
+
name: z.ZodString;
|
|
140
|
+
value: z.ZodString;
|
|
141
|
+
}, z.core.$strict>>;
|
|
142
|
+
image: z.ZodOptional<z.ZodObject<{
|
|
143
|
+
url: z.ZodURL;
|
|
144
|
+
altText: z.ZodOptional<z.ZodString>;
|
|
145
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
146
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
147
|
+
}, z.core.$strict>>;
|
|
148
|
+
quantity: z.ZodInt;
|
|
149
|
+
unitPrice: z.ZodObject<{
|
|
150
|
+
formatted: z.ZodString;
|
|
151
|
+
currencyCode: z.ZodString;
|
|
152
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
153
|
+
}, z.core.$strict>;
|
|
154
|
+
lineTotal: z.ZodObject<{
|
|
155
|
+
formatted: z.ZodString;
|
|
156
|
+
currencyCode: z.ZodString;
|
|
157
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
158
|
+
}, z.core.$strict>;
|
|
159
|
+
compareAtTotal: z.ZodOptional<z.ZodObject<{
|
|
160
|
+
formatted: z.ZodString;
|
|
161
|
+
currencyCode: z.ZodString;
|
|
162
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
163
|
+
}, z.core.$strict>>;
|
|
164
|
+
discountAmount: z.ZodOptional<z.ZodObject<{
|
|
165
|
+
formatted: z.ZodString;
|
|
166
|
+
currencyCode: z.ZodString;
|
|
167
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
168
|
+
}, z.core.$strict>>;
|
|
169
|
+
attributes: z.ZodArray<z.ZodObject<{
|
|
170
|
+
key: z.ZodString;
|
|
171
|
+
value: z.ZodString;
|
|
172
|
+
}, z.core.$strict>>;
|
|
173
|
+
}, z.core.$strict>;
|
|
174
|
+
export declare const cartDiscountCodeSchema: z.ZodObject<{
|
|
175
|
+
code: z.ZodString;
|
|
176
|
+
applicable: z.ZodBoolean;
|
|
177
|
+
}, z.core.$strict>;
|
|
178
|
+
/**
|
|
179
|
+
* The held cart. The id and the checkout url are absent until Shopify holds
|
|
180
|
+
* the cart, which the first add brings about; a buyer who holds nothing sees
|
|
181
|
+
* zero lines and zero money in the market's currency. The total is Shopify's,
|
|
182
|
+
* with its estimated flag; a code Shopify does not honour stays listed with
|
|
183
|
+
* applicable false.
|
|
184
|
+
*/
|
|
185
|
+
export declare const cartDisplaySchema: z.ZodObject<{
|
|
186
|
+
id: z.ZodOptional<z.ZodString>;
|
|
187
|
+
checkoutUrl: z.ZodOptional<z.ZodURL>;
|
|
188
|
+
totalQuantity: z.ZodInt;
|
|
189
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
190
|
+
id: z.ZodString;
|
|
191
|
+
variantId: z.ZodString;
|
|
192
|
+
productId: z.ZodString;
|
|
193
|
+
productTitle: z.ZodString;
|
|
194
|
+
variantTitle: z.ZodString;
|
|
195
|
+
vendor: z.ZodOptional<z.ZodString>;
|
|
196
|
+
selectedOptions: z.ZodArray<z.ZodObject<{
|
|
197
|
+
name: z.ZodString;
|
|
198
|
+
value: z.ZodString;
|
|
199
|
+
}, z.core.$strict>>;
|
|
200
|
+
image: z.ZodOptional<z.ZodObject<{
|
|
201
|
+
url: z.ZodURL;
|
|
202
|
+
altText: z.ZodOptional<z.ZodString>;
|
|
203
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
204
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
205
|
+
}, z.core.$strict>>;
|
|
206
|
+
quantity: z.ZodInt;
|
|
207
|
+
unitPrice: z.ZodObject<{
|
|
208
|
+
formatted: z.ZodString;
|
|
209
|
+
currencyCode: z.ZodString;
|
|
210
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
211
|
+
}, z.core.$strict>;
|
|
212
|
+
lineTotal: z.ZodObject<{
|
|
213
|
+
formatted: z.ZodString;
|
|
214
|
+
currencyCode: z.ZodString;
|
|
215
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
216
|
+
}, z.core.$strict>;
|
|
217
|
+
compareAtTotal: z.ZodOptional<z.ZodObject<{
|
|
218
|
+
formatted: z.ZodString;
|
|
219
|
+
currencyCode: z.ZodString;
|
|
220
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
221
|
+
}, z.core.$strict>>;
|
|
222
|
+
discountAmount: z.ZodOptional<z.ZodObject<{
|
|
223
|
+
formatted: z.ZodString;
|
|
224
|
+
currencyCode: z.ZodString;
|
|
225
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
226
|
+
}, z.core.$strict>>;
|
|
227
|
+
attributes: z.ZodArray<z.ZodObject<{
|
|
228
|
+
key: z.ZodString;
|
|
229
|
+
value: z.ZodString;
|
|
230
|
+
}, z.core.$strict>>;
|
|
231
|
+
}, z.core.$strict>>;
|
|
232
|
+
subtotal: z.ZodObject<{
|
|
233
|
+
formatted: z.ZodString;
|
|
234
|
+
currencyCode: z.ZodString;
|
|
235
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
236
|
+
}, z.core.$strict>;
|
|
237
|
+
totalDiscountAmount: z.ZodObject<{
|
|
238
|
+
formatted: z.ZodString;
|
|
239
|
+
currencyCode: z.ZodString;
|
|
240
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
241
|
+
}, z.core.$strict>;
|
|
242
|
+
total: z.ZodObject<{
|
|
243
|
+
formatted: z.ZodString;
|
|
244
|
+
currencyCode: z.ZodString;
|
|
245
|
+
amount: z.ZodOptional<z.ZodString>;
|
|
246
|
+
}, z.core.$strict>;
|
|
247
|
+
totalEstimated: z.ZodBoolean;
|
|
248
|
+
discountCodes: z.ZodArray<z.ZodObject<{
|
|
249
|
+
code: z.ZodString;
|
|
250
|
+
applicable: z.ZodBoolean;
|
|
251
|
+
}, z.core.$strict>>;
|
|
252
|
+
note: z.ZodOptional<z.ZodString>;
|
|
253
|
+
}, z.core.$strict>;
|
|
112
254
|
export type DisplayMoney = z.infer<typeof displayMoneySchema>;
|
|
113
255
|
export type DisplayImage = z.infer<typeof displayImageSchema>;
|
|
114
256
|
export type ProductOption = z.infer<typeof productOptionSchema>;
|
|
115
257
|
export type ProductVariantDisplay = z.infer<typeof productVariantSchema>;
|
|
116
258
|
export type ProductDisplay = z.infer<typeof productDisplaySchema>;
|
|
117
259
|
export type CollectionDisplay = z.infer<typeof collectionDisplaySchema>;
|
|
260
|
+
export type CartAttribute = z.infer<typeof cartAttributeSchema>;
|
|
261
|
+
export type CartLineDisplay = z.infer<typeof cartLineDisplaySchema>;
|
|
262
|
+
export type CartDiscountCode = z.infer<typeof cartDiscountCodeSchema>;
|
|
263
|
+
export type CartDisplay = z.infer<typeof cartDisplaySchema>;
|
|
118
264
|
/**
|
|
119
265
|
* What a products Binding resolved to: the page in hand, the collection it
|
|
120
266
|
* came from, and the cursor that reaches the page after it.
|
|
@@ -133,6 +279,8 @@ export type ProductsBindingData = {
|
|
|
133
279
|
/**
|
|
134
280
|
* What one Binding resolves to, by kind. A missing entity is an empty shape,
|
|
135
281
|
* null or an empty list, so a renderer collapses the block instead of erroring.
|
|
282
|
+
* The cart always resolves: a buyer who holds nothing holds a cart of zero
|
|
283
|
+
* lines, and the blocks decide what an empty cart shows.
|
|
136
284
|
*/
|
|
137
285
|
export type BindingData = {
|
|
138
286
|
readonly kind: 'product';
|
|
@@ -143,9 +291,17 @@ export type BindingData = {
|
|
|
143
291
|
} | {
|
|
144
292
|
readonly kind: 'collections';
|
|
145
293
|
readonly collections: readonly CollectionDisplay[];
|
|
294
|
+
} | {
|
|
295
|
+
readonly kind: 'cart';
|
|
296
|
+
readonly cart: CartDisplay;
|
|
146
297
|
};
|
|
147
|
-
/**
|
|
148
|
-
|
|
298
|
+
/**
|
|
299
|
+
* One entry of what a Binding resolved to: what a repeater draws once per
|
|
300
|
+
* item, and what a row's cell receives. A cart line is one so the cart lines
|
|
301
|
+
* block can hand its rows to the host; the Composed vocabulary reads nothing
|
|
302
|
+
* off it.
|
|
303
|
+
*/
|
|
304
|
+
export type BoundItem = ProductDisplay | CollectionDisplay | CartLineDisplay;
|
|
149
305
|
/**
|
|
150
306
|
* The Binding's items in order, whatever its kind. A single-entity Binding
|
|
151
307
|
* that resolved to nothing is an empty list, the same as an empty one, so a
|
|
@@ -154,8 +310,8 @@ export type BoundItem = ProductDisplay | CollectionDisplay;
|
|
|
154
310
|
export declare function bindingItems(data: BindingData | null | undefined): readonly BoundItem[];
|
|
155
311
|
/**
|
|
156
312
|
* One text field off the current item, already in the buyer's language. A
|
|
157
|
-
* field the item does not carry
|
|
158
|
-
* nothing, and the node that asked for it draws nothing.
|
|
313
|
+
* field the item does not carry (a collection has no vendor, a cart line none
|
|
314
|
+
* of these) reads as nothing, and the node that asked for it draws nothing.
|
|
159
315
|
*/
|
|
160
316
|
export declare function itemText(item: BoundItem, field: string): string | undefined;
|
|
161
317
|
export declare function itemImage(item: BoundItem): DisplayImage | undefined;
|
package/dist/display.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../src/display.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB
|
|
1
|
+
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../src/display.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;kBAO7B,CAAC;AAIH,eAAO,MAAM,kBAAkB;;;;;kBAK7B,CAAC;AAEH,iEAAiE;AACjE,eAAO,MAAM,mBAAmB;;;kBAG9B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;kBAO/B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAc/B,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;kBAKlC,CAAC;AAEH,4FAA4F;AAC5F,eAAO,MAAM,mBAAmB;;;kBAAgE,CAAC;AAEjG;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAehC,CA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 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
/**
|
|
3
|
-
* Display
|
|
4
|
-
*
|
|
5
|
-
* the charged price
|
|
3
|
+
* Display money: a ready-to-render string, its currency code, and the decimal
|
|
4
|
+
* amount it was formatted from. A block may derive a display-only figure from
|
|
5
|
+
* amounts in one currency; the charged price and the total a buyer sees are
|
|
6
|
+
* always Shopify's, never a device-side sum.
|
|
6
7
|
*/
|
|
7
8
|
export const displayMoneySchema = z.strictObject({
|
|
8
9
|
formatted: z.string().min(1),
|
|
9
10
|
currencyCode: z.string().regex(/^[A-Z]{3}$/, 'expected an ISO 4217 currency code'),
|
|
11
|
+
amount: z
|
|
12
|
+
.string()
|
|
13
|
+
.regex(/^\d+(\.\d+)?$/, 'expected a decimal amount string')
|
|
14
|
+
.optional(),
|
|
10
15
|
});
|
|
16
|
+
const selectedOptionSchema = z.strictObject({ name: z.string().min(1), value: z.string().min(1) });
|
|
11
17
|
export const displayImageSchema = z.strictObject({
|
|
12
18
|
url: z.url(),
|
|
13
19
|
altText: z.string().optional(),
|
|
@@ -28,7 +34,7 @@ export const productOptionSchema = z.strictObject({
|
|
|
28
34
|
export const productVariantSchema = z.strictObject({
|
|
29
35
|
id: z.string().min(1),
|
|
30
36
|
title: z.string(),
|
|
31
|
-
selectedOptions: z.array(
|
|
37
|
+
selectedOptions: z.array(selectedOptionSchema),
|
|
32
38
|
available: z.boolean(),
|
|
33
39
|
price: displayMoneySchema.optional(),
|
|
34
40
|
compareAtPrice: displayMoneySchema.optional(),
|
|
@@ -60,6 +66,53 @@ export const collectionDisplaySchema = z.strictObject({
|
|
|
60
66
|
handle: z.string().min(1),
|
|
61
67
|
image: displayImageSchema.optional(),
|
|
62
68
|
});
|
|
69
|
+
/** One custom attribute a buyer or a block put on a line or the cart: a key and a value. */
|
|
70
|
+
export const cartAttributeSchema = z.strictObject({ key: z.string().min(1), value: z.string() });
|
|
71
|
+
/**
|
|
72
|
+
* One line of the held cart as Shopify answered it and the Provider formatted
|
|
73
|
+
* it: what the buyer holds, of which product and variant, at what price. The
|
|
74
|
+
* compare-at total and the discount amount are present only where Shopify
|
|
75
|
+
* gave one.
|
|
76
|
+
*/
|
|
77
|
+
export const cartLineDisplaySchema = z.strictObject({
|
|
78
|
+
id: z.string().min(1),
|
|
79
|
+
variantId: z.string().min(1),
|
|
80
|
+
productId: z.string().min(1),
|
|
81
|
+
productTitle: z.string(),
|
|
82
|
+
variantTitle: z.string(),
|
|
83
|
+
vendor: z.string().optional(),
|
|
84
|
+
selectedOptions: z.array(selectedOptionSchema),
|
|
85
|
+
image: displayImageSchema.optional(),
|
|
86
|
+
quantity: z.int().positive(),
|
|
87
|
+
unitPrice: displayMoneySchema,
|
|
88
|
+
lineTotal: displayMoneySchema,
|
|
89
|
+
compareAtTotal: displayMoneySchema.optional(),
|
|
90
|
+
discountAmount: displayMoneySchema.optional(),
|
|
91
|
+
attributes: z.array(cartAttributeSchema),
|
|
92
|
+
});
|
|
93
|
+
export const cartDiscountCodeSchema = z.strictObject({
|
|
94
|
+
code: z.string().min(1),
|
|
95
|
+
applicable: z.boolean(),
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* The held cart. The id and the checkout url are absent until Shopify holds
|
|
99
|
+
* the cart, which the first add brings about; a buyer who holds nothing sees
|
|
100
|
+
* zero lines and zero money in the market's currency. The total is Shopify's,
|
|
101
|
+
* with its estimated flag; a code Shopify does not honour stays listed with
|
|
102
|
+
* applicable false.
|
|
103
|
+
*/
|
|
104
|
+
export const cartDisplaySchema = z.strictObject({
|
|
105
|
+
id: z.string().min(1).optional(),
|
|
106
|
+
checkoutUrl: z.url().optional(),
|
|
107
|
+
totalQuantity: z.int().min(0),
|
|
108
|
+
lines: z.array(cartLineDisplaySchema),
|
|
109
|
+
subtotal: displayMoneySchema,
|
|
110
|
+
totalDiscountAmount: displayMoneySchema,
|
|
111
|
+
total: displayMoneySchema,
|
|
112
|
+
totalEstimated: z.boolean(),
|
|
113
|
+
discountCodes: z.array(cartDiscountCodeSchema),
|
|
114
|
+
note: z.string().optional(),
|
|
115
|
+
});
|
|
63
116
|
/**
|
|
64
117
|
* The Binding's items in order, whatever its kind. A single-entity Binding
|
|
65
118
|
* that resolved to nothing is an empty list, the same as an empty one, so a
|
|
@@ -77,22 +130,30 @@ export function bindingItems(data) {
|
|
|
77
130
|
return data.collection === null ? [] : [data.collection];
|
|
78
131
|
case 'collections':
|
|
79
132
|
return data.collections;
|
|
133
|
+
case 'cart':
|
|
134
|
+
return data.cart.lines;
|
|
80
135
|
}
|
|
81
136
|
}
|
|
82
137
|
function asProduct(item) {
|
|
83
138
|
return 'price' in item ? item : undefined;
|
|
84
139
|
}
|
|
140
|
+
function asCatalogItem(item) {
|
|
141
|
+
return 'handle' in item ? item : undefined;
|
|
142
|
+
}
|
|
85
143
|
/**
|
|
86
144
|
* One text field off the current item, already in the buyer's language. A
|
|
87
|
-
* field the item does not carry
|
|
88
|
-
* nothing, and the node that asked for it draws nothing.
|
|
145
|
+
* field the item does not carry (a collection has no vendor, a cart line none
|
|
146
|
+
* of these) reads as nothing, and the node that asked for it draws nothing.
|
|
89
147
|
*/
|
|
90
148
|
export function itemText(item, field) {
|
|
149
|
+
const listed = asCatalogItem(item);
|
|
150
|
+
if (listed === undefined)
|
|
151
|
+
return undefined;
|
|
91
152
|
switch (field) {
|
|
92
153
|
case 'title':
|
|
93
|
-
return
|
|
154
|
+
return listed.title;
|
|
94
155
|
case 'handle':
|
|
95
|
-
return
|
|
156
|
+
return listed.handle;
|
|
96
157
|
case 'vendor':
|
|
97
158
|
return asProduct(item)?.vendor;
|
|
98
159
|
case 'product_type':
|
package/dist/display.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"display.js","sourceRoot":"","sources":["../src/display.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB
|
|
1
|
+
{"version":3,"file":"display.js","sourceRoot":"","sources":["../src/display.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