@shop-on/theme-server 0.10.0 → 0.11.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.
Files changed (168) hide show
  1. package/dist/account-state.js +1 -2
  2. package/dist/account.d.ts +1 -3
  3. package/dist/account.js +1 -3
  4. package/dist/activity.d.ts +1 -3
  5. package/dist/activity.js +1 -2
  6. package/dist/analytics-proxy.d.ts +8 -14
  7. package/dist/analytics-proxy.js +111 -28
  8. package/dist/analytics-script-proxy.d.ts +1 -5
  9. package/dist/analytics-script-proxy.js +4 -14
  10. package/dist/api-contract/src/addresses.js +32 -0
  11. package/dist/api-contract/src/areas.js +49 -0
  12. package/dist/api-contract/src/custom-data.d.ts +31 -0
  13. package/dist/api-contract/src/custom-data.js +303 -0
  14. package/dist/api-contract/src/ids.js +110 -0
  15. package/dist/api-contract/src/image.js +65 -0
  16. package/dist/api-contract/src/limits.js +44 -0
  17. package/dist/api-contract/src/media.js +13 -0
  18. package/dist/api-contract/src/pickup.js +11 -0
  19. package/dist/api-contract/src/recommendations.js +4 -0
  20. package/dist/api-contract/src/shops.js +27 -0
  21. package/dist/api-contract/src/storefront/analytics.d.ts +100 -0
  22. package/dist/api-contract/src/storefront/analytics.js +138 -0
  23. package/dist/api-contract/src/storefront/areas.d.ts +2 -0
  24. package/dist/api-contract/src/storefront/cart.d.ts +132 -0
  25. package/dist/api-contract/src/storefront/cart.js +248 -0
  26. package/dist/api-contract/src/storefront/catalog.d.ts +3 -0
  27. package/dist/api-contract/src/storefront/checkout-analytics.d.ts +2 -0
  28. package/dist/api-contract/src/storefront/checkout.d.ts +2 -0
  29. package/dist/api-contract/src/storefront/checkout.js +624 -0
  30. package/dist/api-contract/src/storefront/client.d.ts +3 -0
  31. package/dist/api-contract/src/storefront/client.js +6 -0
  32. package/dist/api-contract/src/storefront/content.d.ts +3 -0
  33. package/dist/api-contract/src/storefront/custom-data.d.ts +2 -0
  34. package/dist/api-contract/src/storefront/custom-data.js +27 -0
  35. package/dist/api-contract/src/storefront/customer.d.ts +2 -0
  36. package/dist/api-contract/src/storefront/customer.js +261 -0
  37. package/dist/api-contract/src/storefront/downloads.d.ts +2 -0
  38. package/dist/api-contract/src/storefront/draft-order-invoice.d.ts +2 -0
  39. package/dist/api-contract/src/storefront/forms.d.ts +2 -0
  40. package/dist/api-contract/src/storefront/forms.js +82 -0
  41. package/dist/api-contract/src/storefront/index.d.ts +20956 -0
  42. package/dist/api-contract/src/storefront/orders.d.ts +2 -0
  43. package/dist/api-contract/src/storefront/policies.d.ts +2 -0
  44. package/dist/api-contract/src/storefront/procedure.d.ts +2 -0
  45. package/dist/api-contract/src/storefront/procedure.js +29 -0
  46. package/dist/api-contract/src/storefront/reviews.d.ts +20 -0
  47. package/dist/api-contract/src/storefront/search.d.ts +3 -0
  48. package/dist/api-contract/src/storefront/seo.d.ts +2 -0
  49. package/dist/api-contract/src/storefront/seo.js +132 -0
  50. package/dist/api-contract/src/storefront/shop.d.ts +2 -0
  51. package/dist/api-contract/src/storefront/shop.js +101 -0
  52. package/dist/api-contract/src/taxonomy.js +5 -0
  53. package/dist/api-contract/src/text.js +15 -0
  54. package/dist/api-contract/src/theme-documents.js +13 -0
  55. package/dist/api-contract/src/theme-translations.d.ts +14 -0
  56. package/dist/api-contract/src/theme-translations.js +30 -0
  57. package/dist/api-contract/src/video.js +19 -0
  58. package/dist/availability.d.ts +6 -3
  59. package/dist/availability.js +11 -5
  60. package/dist/blog.d.ts +53 -59
  61. package/dist/blog.js +197 -497
  62. package/dist/cache.d.ts +5 -6
  63. package/dist/cache.js +1 -2
  64. package/dist/canonical-host.d.ts +4 -6
  65. package/dist/canonical-host.js +5 -6
  66. package/dist/card.js +159 -0
  67. package/dist/cart-customer.d.ts +1 -3
  68. package/dist/cart-customer.js +64 -105
  69. package/dist/cart-mutations.d.ts +43 -77
  70. package/dist/cart-mutations.js +106 -232
  71. package/dist/cart-recommendations.d.ts +1 -3
  72. package/dist/cart-recommendations.js +1 -2
  73. package/dist/cart-session.d.ts +1 -3
  74. package/dist/cart-session.js +1 -2
  75. package/dist/cart.d.ts +63 -224
  76. package/dist/cart.js +70 -197
  77. package/dist/checkout.d.ts +13 -17
  78. package/dist/checkout.js +75 -101
  79. package/dist/coalesce.js +57 -0
  80. package/dist/collection.d.ts +89 -298
  81. package/dist/collection.js +210 -656
  82. package/dist/contact.d.ts +20 -10
  83. package/dist/contact.js +36 -30
  84. package/dist/content-version.d.ts +37 -21
  85. package/dist/content-version.js +64 -42
  86. package/dist/contract-kit/src/client.d.ts +12 -0
  87. package/dist/contract-kit/src/client.js +156 -0
  88. package/dist/contract-kit/src/errors.d.ts +1 -0
  89. package/dist/contract-kit/src/errors.js +81 -0
  90. package/dist/contract-kit/src/ids.d.ts +1 -0
  91. package/dist/contract-kit/src/ids.js +118 -0
  92. package/dist/contract-kit/src/index.d.ts +7 -0
  93. package/dist/contract-kit/src/money.d.ts +1 -0
  94. package/dist/contract-kit/src/money.js +10 -0
  95. package/dist/contract-kit/src/pagination.d.ts +1 -0
  96. package/dist/contract-kit/src/procedure.d.ts +69 -0
  97. package/dist/contract-kit/src/procedure.js +16 -0
  98. package/dist/contract-kit/src/realtime.d.ts +1 -0
  99. package/dist/cookie-secret.js +1 -2
  100. package/dist/csrf.js +1 -2
  101. package/dist/customer-handoff.d.ts +1 -3
  102. package/dist/customer-handoff.js +10 -25
  103. package/dist/customer-session.d.ts +1 -3
  104. package/dist/customer-session.js +1 -2
  105. package/dist/customer.d.ts +2 -3
  106. package/dist/customer.js +27 -44
  107. package/dist/files.d.ts +49 -10
  108. package/dist/files.js +106 -89
  109. package/dist/fonts.d.ts +3 -5
  110. package/dist/fonts.js +16 -35
  111. package/dist/html.d.ts +1 -3
  112. package/dist/html.js +1 -2
  113. package/dist/liquid.d.ts +4 -10
  114. package/dist/liquid.js +25 -32
  115. package/dist/listing.js +79 -0
  116. package/dist/marketing-cookies.d.ts +1 -3
  117. package/dist/marketing-cookies.js +1 -2
  118. package/dist/menu.d.ts +46 -155
  119. package/dist/menu.js +51 -61
  120. package/dist/metafields.d.ts +9 -5
  121. package/dist/metafields.js +10 -38
  122. package/dist/metaobject.d.ts +10 -5
  123. package/dist/metaobject.js +43 -66
  124. package/dist/money.d.ts +7 -0
  125. package/dist/money.js +18 -0
  126. package/dist/newsletter.d.ts +19 -10
  127. package/dist/newsletter.js +31 -25
  128. package/dist/page.d.ts +13 -17
  129. package/dist/page.js +49 -105
  130. package/dist/password-session.d.ts +1 -3
  131. package/dist/password-session.js +1 -2
  132. package/dist/password.d.ts +25 -18
  133. package/dist/password.js +41 -59
  134. package/dist/policy.d.ts +7 -7
  135. package/dist/policy.js +19 -55
  136. package/dist/product.d.ts +42 -67
  137. package/dist/product.js +144 -644
  138. package/dist/read-ahead.d.ts +18 -0
  139. package/dist/read-ahead.js +32 -0
  140. package/dist/recommendations.d.ts +6 -12
  141. package/dist/recommendations.js +36 -60
  142. package/dist/review.d.ts +134 -94
  143. package/dist/review.js +257 -469
  144. package/dist/search.d.ts +59 -64
  145. package/dist/search.js +170 -469
  146. package/dist/seo-context.d.ts +1 -3
  147. package/dist/seo-context.js +4 -5
  148. package/dist/seo-documents.d.ts +50 -0
  149. package/dist/seo-documents.js +149 -0
  150. package/dist/shop-seo.d.ts +3 -5
  151. package/dist/shop-seo.js +7 -26
  152. package/dist/shop.d.ts +38 -42
  153. package/dist/shop.js +37 -51
  154. package/dist/store-availability.d.ts +12 -14
  155. package/dist/store-availability.js +18 -56
  156. package/dist/storefront.js +199 -0
  157. package/dist/structured-data.d.ts +3 -28
  158. package/dist/structured-data.js +19 -49
  159. package/dist/trace.js +1 -2
  160. package/dist/translations.d.ts +26 -31
  161. package/dist/translations.js +55 -28
  162. package/package.json +16 -14
  163. package/dist/graphql-env.d.ts +0 -22778
  164. package/dist/graphql.d.ts +0 -64
  165. package/dist/graphql.js +0 -344
  166. package/dist/schema.storefront.graphql +0 -10483
  167. package/dist/seo-proxy.d.ts +0 -11
  168. package/dist/seo-proxy.js +0 -26
@@ -0,0 +1,303 @@
1
+ import { mnt } from "../../contract-kit/src/money.js";
2
+ import { liteId } from "./ids.js";
3
+ import { categoryCode } from "./taxonomy.js";
4
+ import { z } from "zod";
5
+ /** The kinds of file a file field may be held to (legacy `FILE_KIND_TO_CLASS`). */
6
+ const FILE_TYPE_OPTIONS = ["image", "video"];
7
+ const RICH_TEXT_DEPTH_MAX = 40;
8
+ const URL_SCHEMES = /^(https?:|mailto:|tel:)/i;
9
+ /** A rich-text document: legacy's node tree (root → paragraph, heading, list → text, link, image). */
10
+ const richTextNode = z.lazy(() => z.union([
11
+ z.object({
12
+ type: z.literal("text"),
13
+ value: z.string().max(1e5),
14
+ bold: z.boolean().optional(),
15
+ italic: z.boolean().optional()
16
+ }),
17
+ z.object({
18
+ type: z.literal("link"),
19
+ url: z.string().max(2048).regex(URL_SCHEMES),
20
+ title: z.string().max(255).optional(),
21
+ target: z.enum(["_blank", "_self"]).optional(),
22
+ children: z.array(richTextNode).max(1e3)
23
+ }),
24
+ z.object({
25
+ type: z.literal("image"),
26
+ url: z.string().max(2048).regex(/^https?:/i),
27
+ alt: z.string().max(512).optional()
28
+ }),
29
+ z.object({
30
+ type: z.literal("paragraph"),
31
+ children: z.array(richTextNode).max(1e3)
32
+ }),
33
+ z.object({
34
+ type: z.literal("heading"),
35
+ level: z.int().min(1).max(6),
36
+ children: z.array(richTextNode).max(1e3)
37
+ }),
38
+ z.object({
39
+ type: z.literal("list"),
40
+ listType: z.enum(["ordered", "unordered"]),
41
+ children: z.array(richTextNode).max(1e3)
42
+ }),
43
+ z.object({
44
+ type: z.literal("list-item"),
45
+ children: z.array(richTextNode).max(1e3)
46
+ })
47
+ ]));
48
+ const depthOf = (node) => 1 + Math.max(0, ...(node.children ?? []).map((child) => depthOf(child)));
49
+ const richTextRoot = z.object({
50
+ type: z.literal("root"),
51
+ children: z.array(richTextNode).max(1e3)
52
+ }).refine((root) => depthOf(root) <= RICH_TEXT_DEPTH_MAX, "Nested too deep").refine((root) => JSON.stringify(root).length <= 1e5, "Too long");
53
+ /** One line of text: what `single_line_text` holds, and a choice of one. */
54
+ const oneLine = z.string().min(1).max(5e3).regex(/^[^\r\n]*$/, "One line");
55
+ /** A value of each type, as the wire carries one item. */
56
+ const items = {
57
+ single_line_text: oneLine,
58
+ multi_line_text: z.string().min(1).max(1e5),
59
+ rich_text: richTextRoot,
60
+ integer: z.int().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER),
61
+ /** An exact decimal, as a string so no digit is lost. */
62
+ decimal: z.string().regex(/^-?\d{1,20}(\.\d{1,9})?$/),
63
+ money: mnt,
64
+ boolean: z.boolean(),
65
+ date: z.iso.date(),
66
+ date_time: z.iso.datetime({ offset: true }),
67
+ /** http(s) with a host, or a path on the shop (`/pages/about`). */
68
+ url: z.string().max(2048).refine((url) => {
69
+ if (url.startsWith("/")) return !url.startsWith("//");
70
+ try {
71
+ const parsed = new URL(url);
72
+ return /^https?:$/.test(parsed.protocol) && parsed.host !== "" && !parsed.username;
73
+ } catch {
74
+ return false;
75
+ }
76
+ }, "An http(s) URL or a path"),
77
+ color: z.string().regex(/^#([0-9a-f]{3}|[0-9a-f]{6})$/, "#rgb or #rrggbb, lowercase"),
78
+ json: z.json().refine((json) => JSON.stringify(json).length <= 1e5, "Too long"),
79
+ file_reference: liteId("file"),
80
+ page_reference: liteId("page"),
81
+ product_reference: liteId("prod"),
82
+ variant_reference: liteId("variant"),
83
+ collection_reference: liteId("collection"),
84
+ metaobject_reference: liteId("metaobject"),
85
+ taxonomy_category_reference: categoryCode,
86
+ /** A taxonomy value's friendly id (`color__red`). */
87
+ taxonomy_value_reference: z.string().regex(/^[a-z0-9_/]{1,100}__[^\s]{1,200}$/)
88
+ };
89
+ /** Every value type: legacy's list, and money. */
90
+ const VALUE_TYPES = {
91
+ single_line_text: {
92
+ list: true,
93
+ validations: [
94
+ "length",
95
+ "pattern",
96
+ "choices"
97
+ ]
98
+ },
99
+ multi_line_text: {
100
+ list: true,
101
+ validations: ["length"]
102
+ },
103
+ rich_text: {
104
+ list: false,
105
+ validations: []
106
+ },
107
+ integer: {
108
+ list: true,
109
+ validations: ["number"]
110
+ },
111
+ decimal: {
112
+ list: true,
113
+ validations: ["number", "decimalPlaces"]
114
+ },
115
+ money: {
116
+ list: false,
117
+ validations: ["number"]
118
+ },
119
+ boolean: {
120
+ list: true,
121
+ validations: []
122
+ },
123
+ date: {
124
+ list: true,
125
+ validations: ["date"]
126
+ },
127
+ date_time: {
128
+ list: true,
129
+ validations: ["dateTime"]
130
+ },
131
+ url: {
132
+ list: true,
133
+ validations: []
134
+ },
135
+ color: {
136
+ list: true,
137
+ validations: []
138
+ },
139
+ json: {
140
+ list: false,
141
+ validations: []
142
+ },
143
+ file_reference: {
144
+ list: false,
145
+ validations: ["fileTypeOptions"],
146
+ reference: "file"
147
+ },
148
+ page_reference: {
149
+ list: false,
150
+ validations: [],
151
+ reference: "page"
152
+ },
153
+ product_reference: {
154
+ list: true,
155
+ validations: [],
156
+ reference: "product"
157
+ },
158
+ variant_reference: {
159
+ list: true,
160
+ validations: [],
161
+ reference: "variant"
162
+ },
163
+ collection_reference: {
164
+ list: true,
165
+ validations: [],
166
+ reference: "collection"
167
+ },
168
+ metaobject_reference: {
169
+ list: true,
170
+ validations: [],
171
+ reference: "metaobject"
172
+ },
173
+ taxonomy_category_reference: {
174
+ list: false,
175
+ validations: [],
176
+ reference: "taxonomyCategory"
177
+ },
178
+ taxonomy_value_reference: {
179
+ list: true,
180
+ validations: [],
181
+ reference: "taxonomyValue"
182
+ }
183
+ };
184
+ const valueTypes = Object.keys(VALUE_TYPES);
185
+ const bound = (item) => z.object({
186
+ min: item.optional(),
187
+ max: item.optional()
188
+ }).refine((range) => range.min !== void 0 || range.max !== void 0, "A bound");
189
+ /** The rules a definition puts on its values; each key only on the types that allow it. */
190
+ const metafieldValidations = z.strictObject({
191
+ /** Text length in characters, inclusive. */
192
+ length: bound(z.int().min(0).max(1e5)).optional(),
193
+ /** A regular expression every value matches (Postgres syntax; checked by the database). */
194
+ pattern: z.string().min(1).max(200).optional(),
195
+ /** The only values allowed. */
196
+ choices: z.array(oneLine).min(1).max(128).optional(),
197
+ /** Inclusive bounds of an integer, decimal or money (möngö) value. */
198
+ number: bound(z.number()).optional(),
199
+ /** Most digits after a decimal's point. */
200
+ decimalPlaces: z.int().min(0).max(9).optional(),
201
+ date: bound(z.iso.date()).optional(),
202
+ dateTime: bound(z.iso.datetime({ offset: true })).optional(),
203
+ /** How many items a list holds, inclusive. */
204
+ listItems: bound(z.int().min(0).max(250)).optional(),
205
+ /**
206
+ * A file's kinds allowed (legacy `file_type_options`, a metaobject field's
207
+ * rule only); none: any file. Checked by the api against the file.
208
+ */
209
+ fileTypeOptions: z.array(z.enum(FILE_TYPE_OPTIONS)).min(1).max(FILE_TYPE_OPTIONS.length).refine((kinds) => new Set(kinds).size === kinds.length, "Kinds repeat").optional()
210
+ });
211
+ z.object({
212
+ type: z.enum(valueTypes),
213
+ /** A list of the type's items. */
214
+ list: z.boolean(),
215
+ validations: metafieldValidations
216
+ });
217
+ /** A value of one type on the wire: an item, or an array of them for a list. */
218
+ const valueOfType = (type) => z.object({
219
+ type: z.literal(type),
220
+ list: z.boolean(),
221
+ value: z.union([items[type], z.array(items[type])])
222
+ });
223
+ const typedValue = z.discriminatedUnion("type", valueTypes.map((type) => valueOfType(type)));
224
+ /** A key a definition goes by on its owner kind: `custom.material`. */
225
+ const metafieldNamespace = z.string().regex(/^[a-z][a-z0-9_-]*$/).max(64);
226
+ const metafieldKey = z.string().regex(/^[a-z][a-z0-9_-]*$/).max(64);
227
+ /** One value as a save sends it: null clears it. */
228
+ const metafieldValueInput = z.object({
229
+ namespace: metafieldNamespace.describe("The definition's namespace (custom)."),
230
+ key: metafieldKey.describe("The definition's key."),
231
+ /** The type's wire value (an array for a list); checked against the definition. Null clears it. */
232
+ value: z.json().nullable().describe("The value in its definition's type (an array for a list); null clears it.")
233
+ });
234
+ z.array(metafieldValueInput).max(256).refine((values) => new Set(values.map((value) => `${value.namespace}.${value.key}`)).size === values.length, "One value per key");
235
+ /** One stored value, with its definition's key and type. */
236
+ const metafieldValue = typedValue.and(z.object({
237
+ definitionId: liteId("metafield_definition"),
238
+ namespace: z.string(),
239
+ key: z.string()
240
+ }));
241
+ /** A metaobject entry's field value: as a metafield, keyed by the field. */
242
+ const metaobjectFieldValue = typedValue.and(z.object({
243
+ fieldId: liteId("metafield_definition"),
244
+ key: z.string()
245
+ }));
246
+ /**
247
+ * What the values reference, each target once, so a form draws a picker's
248
+ * chip without a call per value. A target gone (deleted, or not the
249
+ * caller's to read) is absent: its value shows as broken.
250
+ */
251
+ const metafieldReferences = z.object({
252
+ products: z.array(z.object({
253
+ id: liteId("prod"),
254
+ title: z.string(),
255
+ handle: z.string(),
256
+ imageUrl: z.string().nullable()
257
+ })),
258
+ variants: z.array(z.object({
259
+ id: liteId("variant"),
260
+ productId: liteId("prod"),
261
+ productTitle: z.string(),
262
+ /** Its option values, joined: `Small / Red`; empty for a product without options. */
263
+ title: z.string(),
264
+ sku: z.string().nullable()
265
+ })),
266
+ collections: z.array(z.object({
267
+ id: liteId("collection"),
268
+ title: z.string(),
269
+ handle: z.string()
270
+ })),
271
+ files: z.array(z.object({
272
+ id: liteId("file"),
273
+ filename: z.string(),
274
+ kind: z.string(),
275
+ url: z.string().nullable()
276
+ })),
277
+ pages: z.array(z.object({
278
+ id: liteId("page"),
279
+ title: z.string(),
280
+ handle: z.string()
281
+ })),
282
+ metaobjects: z.array(z.object({
283
+ id: liteId("metaobject"),
284
+ definitionId: liteId("metaobject_definition"),
285
+ handle: z.string(),
286
+ displayName: z.string()
287
+ })),
288
+ taxonomyCategories: z.array(z.object({
289
+ code: z.string(),
290
+ name: z.object({
291
+ en: z.string(),
292
+ mn: z.string().nullable()
293
+ })
294
+ })),
295
+ taxonomyValues: z.array(z.object({
296
+ friendlyId: z.string(),
297
+ name: z.object({
298
+ en: z.string(),
299
+ mn: z.string().nullable()
300
+ })
301
+ }))
302
+ });
303
+ export { FILE_TYPE_OPTIONS, VALUE_TYPES, metafieldKey, metafieldNamespace, metafieldReferences, metafieldValidations, metafieldValue, metafieldValueInput, metaobjectFieldValue, richTextRoot, valueTypes };
@@ -0,0 +1,110 @@
1
+ import { ID_PREFIXES, defineIds } from "../../contract-kit/src/ids.js";
2
+ // ../api-contract/src/ids.ts
3
+ const LITE_ID_PREFIXES = {
4
+ ...ID_PREFIXES,
5
+ user: "staff account",
6
+ staff: "staff member",
7
+ role: "role",
8
+ invite: "staff invitation",
9
+ domain: "storefront domain",
10
+ event: "activity event",
11
+ notification: "staff notification",
12
+ area: "administrative area",
13
+ customer: "customer",
14
+ customer_address: "customer address",
15
+ discount: "discount",
16
+ discount_code: "discount code",
17
+ shipping_profile: "shipping profile",
18
+ location_group: "shipping location group",
19
+ shipping_zone: "shipping zone",
20
+ shipping_rate: "shipping rate",
21
+ shipping_package: "shipping package",
22
+ driver: "delivery driver",
23
+ delivery_rule: "delivery customization rule",
24
+ register: "register",
25
+ register_role: "register role",
26
+ cashier: "cashier",
27
+ register_session: "cashier session",
28
+ shift: "cash drawer shift",
29
+ cash_movement: "cash movement",
30
+ file: "file",
31
+ font_family: "font family",
32
+ font_face: "font face",
33
+ option: "product option",
34
+ option_value: "product option value",
35
+ variant: "product variant",
36
+ location: "location",
37
+ channel: "sales channel",
38
+ collection: "collection",
39
+ collection_source: "collection source",
40
+ inventory_entry: "inventory ledger entry",
41
+ inventory_bulk: "inventory bulk operation",
42
+ product_import: "product import",
43
+ product_export: "product export",
44
+ digital_file: "digital file",
45
+ download_grant: "download grant",
46
+ metafield_definition: "metafield definition",
47
+ metaobject_definition: "metaobject definition",
48
+ metaobject: "metaobject entry",
49
+ page: "page",
50
+ blog: "blog",
51
+ article: "article",
52
+ menu: "menu",
53
+ menu_item: "menu item",
54
+ synonym: "search synonym group",
55
+ search_boost: "search boost",
56
+ search_filter: "search filter",
57
+ review: "product review",
58
+ review_attribute: "review question",
59
+ sfc: "storefront credential",
60
+ oauth_client: "OAuth client",
61
+ theme: "theme",
62
+ theme_version: "theme version",
63
+ theme_preset: "theme preset",
64
+ theme_install: "theme install",
65
+ theme_revision: "theme revision",
66
+ developer: "theme developer",
67
+ theme_submission: "theme submission",
68
+ theme_highlight: "theme preset highlight",
69
+ industry: "theme industry",
70
+ basket: "basket",
71
+ basket_line: "basket line",
72
+ draft_order: "draft order",
73
+ order: "order",
74
+ order_line: "order line",
75
+ order_line_group: "order line group",
76
+ fiscal_receipt: "fiscal receipt",
77
+ refund: "refund",
78
+ refund_line: "refund line",
79
+ refund_transaction: "refund transaction",
80
+ return: "return",
81
+ return_line: "return line",
82
+ fulfilment_order: "fulfilment order",
83
+ fulfilment_order_line: "fulfilment order line",
84
+ fulfilment: "fulfilment",
85
+ fulfilment_line: "fulfilment line",
86
+ delivery: "delivery",
87
+ delivery_event: "delivery event",
88
+ payment: "payment",
89
+ gift_card: "gift card",
90
+ gift_card_movement: "gift card movement",
91
+ store_credit_lot: "store credit grant",
92
+ store_credit_revocation: "store credit revocation",
93
+ store_credit_movement: "store credit movement",
94
+ webhook_subscription: "webhook subscription",
95
+ webhook_delivery: "webhook delivery",
96
+ invoice: "billing invoice",
97
+ plan_license: "plan license",
98
+ feedback: "feedback",
99
+ app: "app",
100
+ app_install: "app install"
101
+ };
102
+ /**
103
+ * `liteId("role")` accepts `role_…` UUIDv7s only; `toLiteId` gives a row's
104
+ * wire id; `fromLiteId` its UUID, throwing on another kind; `newLiteId`
105
+ * mints one on the caller's side, for a row a client names before it saves
106
+ * it (a product's options, values and variants), so a retried save is the
107
+ * same save.
108
+ */
109
+ const { idSchema: liteId, toId: toLiteId, toUuid: fromLiteId, newId: newLiteId } = defineIds(LITE_ID_PREFIXES);
110
+ export { LITE_ID_PREFIXES, liteId };
@@ -0,0 +1,65 @@
1
+ import { liteId } from "./ids.js";
2
+ import { z } from "zod";
3
+ // ../api-contract/src/image.ts
4
+ const imageSchema = z.object({
5
+ id: liteId("file"),
6
+ /** The original, as stored. */
7
+ url: z.string(),
8
+ /** `url` resized: `{width}`, `{height}` and `{fit}` to fill in; null when it cannot be resized. */
9
+ sized: z.string().nullable(),
10
+ /** Pixels as displayed (EXIF orientation applied); an SVG's viewBox, rounded up. */
11
+ width: z.int().positive(),
12
+ height: z.int().positive(),
13
+ alt: z.string().nullable(),
14
+ /** ThumbHash placeholder, base64; null for an SVG. */
15
+ thumbhash: z.string().nullable(),
16
+ /** Where a crop should keep, in percent from the left and the top; null for the centre. */
17
+ focalPoint: z.object({
18
+ x: z.number().min(0).max(100),
19
+ y: z.number().min(0).max(100)
20
+ }).nullable()
21
+ });
22
+ /**
23
+ * The widths a sized URL is ever asked for. Legacy's `ImageTransformInput`
24
+ * took any width to 5,760 at a scale of 1 to 3; one variant per ladder step
25
+ * keeps the CDN's cache small and hot.
26
+ */
27
+ const IMAGE_WIDTHS = [
28
+ 16,
29
+ 32,
30
+ 48,
31
+ 64,
32
+ 96,
33
+ 128,
34
+ 160,
35
+ 240,
36
+ 320,
37
+ 480,
38
+ 640,
39
+ 800,
40
+ 960,
41
+ 1080,
42
+ 1280,
43
+ 1600,
44
+ 1920,
45
+ 2400,
46
+ 2880,
47
+ 3840,
48
+ 4800,
49
+ 5760
50
+ ];
51
+ const IMAGE_MAX_DIMENSION = 5760;
52
+ /**
53
+ * The image's URL at `size`: the width times the scale snapped up the
54
+ * ladder (at most 5,760), the height from the asked aspect or the image's
55
+ * own, or `url` when the image cannot be resized.
56
+ */
57
+ function imageUrl(image, { width, height, fit = "cover", scale = 1 }) {
58
+ if (image.sized === null) return image.url;
59
+ const wanted = Math.min(Math.ceil(width * Math.min(Math.max(scale, 1), 3)), IMAGE_MAX_DIMENSION);
60
+ const snapped = IMAGE_WIDTHS.find((step) => step >= wanted);
61
+ const aspect = height !== void 0 && width > 0 ? height / width : image.height / image.width;
62
+ const sizedHeight = Math.min(Math.max(Math.round(snapped * aspect), 1), IMAGE_MAX_DIMENSION);
63
+ return image.sized.replace("{width}", String(snapped)).replace("{height}", String(sizedHeight)).replace("{fit}", fit);
64
+ }
65
+ export { IMAGE_MAX_DIMENSION, IMAGE_WIDTHS, imageSchema, imageUrl };
@@ -0,0 +1,44 @@
1
+ // ../api-contract/src/limits.ts
2
+ /** How far into a listing, a search tab or a blog a page may start. */
3
+ const LISTING_OFFSET_MAX = 1e4;
4
+ /** The longest Turnstile token a storefront form may send (Cloudflare refuses one over 2048). */
5
+ const TURNSTILE_TOKEN_MAX = 2048;
6
+ /** The largest photo a buyer may upload with a review (legacy Review::Media::MAX_UPLOAD_SIZE, 5 MiB). */
7
+ const REVIEW_PHOTO_BYTES_MAX = 5242880;
8
+ /** What a review's photo may be uploaded as (legacy Review::Media::CONTENT_TYPES); it is stored as WebP. */
9
+ const REVIEW_PHOTO_TYPES = [
10
+ "image/jpeg",
11
+ "image/png",
12
+ "image/webp"
13
+ ];
14
+ /** The contact form's message, its rows and their labels (legacy Mutations::ShopContactForm's BODY_MAX, FIELDS_MAX, FIELD_LABEL_MAX, FIELDS_TOTAL_MAX), counted once blank rows are dropped. */
15
+ const CONTACT_BODY_MAX = 5e3;
16
+ const CONTACT_FIELDS_TOTAL_MAX = 5e3;
17
+ /**
18
+ * The sitemap's files, in the index's order (legacy Shop::Seo::SitemapQuery::KINDS):
19
+ * `static` (the home page, the catalogue, each blog, each written policy)
20
+ * first, the one that is never empty.
21
+ */
22
+ const SITEMAP_KINDS = [
23
+ "static",
24
+ "products",
25
+ "collections",
26
+ "pages",
27
+ "articles"
28
+ ];
29
+ /** The highest sitemap file a kind is asked for: 50 million entries, far past any catalogue; the point is a finite set. */
30
+ const SITEMAP_PAGE_MAX = 1e4;
31
+ /** The longest landing or referrer URL a visit may send: past the kept bound it is dropped, not refused. */
32
+ const ANALYTICS_URL_SENT_MAX = 8192;
33
+ /** The largest count, place or quantity an event carries (the log's integer columns). */
34
+ const ANALYTICS_NUMBER_MAX = 2147483647;
35
+ /** The most units one cart line holds. */
36
+ const CART_LINE_QUANTITY_MAX = 1e4;
37
+ /** The longest buyer note a cart keeps (legacy BuyerNotable's). */
38
+ const CART_NOTE_MAX = 1e3;
39
+ /** The longest custom attribute value. */
40
+ const LINE_ATTRIBUTE_VALUE_MAX = 1e3;
41
+ const DISCOUNT_CODE_PATTERN = /^[A-Za-z0-9_-]+$/;
42
+ /** A gift card's code: 8 to 20 letters and digits, kept upper-cased (legacy's). */
43
+ const GIFT_CARD_CODE_PATTERN = /^[A-Z0-9]{8,20}$/;
44
+ export { ANALYTICS_NUMBER_MAX, ANALYTICS_URL_SENT_MAX, CART_LINE_QUANTITY_MAX, CART_NOTE_MAX, CONTACT_BODY_MAX, CONTACT_FIELDS_TOTAL_MAX, DISCOUNT_CODE_PATTERN, GIFT_CARD_CODE_PATTERN, LINE_ATTRIBUTE_VALUE_MAX, LISTING_OFFSET_MAX, REVIEW_PHOTO_BYTES_MAX, REVIEW_PHOTO_TYPES, SITEMAP_KINDS, SITEMAP_PAGE_MAX, TURNSTILE_TOKEN_MAX };
@@ -0,0 +1,13 @@
1
+ import { liteId } from "./ids.js";
2
+ import { imageSchema } from "./image.js";
3
+ import { videoSchema } from "./video.js";
4
+ import { z } from "zod";
5
+ // ../api-contract/src/media.ts
6
+ const productMedia = z.object({
7
+ fileId: liteId("file"),
8
+ /** An image's, once it is processed; null for a video. */
9
+ image: imageSchema.nullable(),
10
+ /** A video's, once it is transcoded; null for an image. */
11
+ video: videoSchema.nullable()
12
+ });
13
+ export { productMedia };
@@ -0,0 +1,11 @@
1
+ // ../api-contract/src/pickup.ts
2
+ /** How soon an order is usually ready for collection, as the buyer is told. */
3
+ const PICKUP_LEAD_TIMES = [
4
+ "oneHour",
5
+ "twoHours",
6
+ "fourHours",
7
+ "twentyFourHours",
8
+ "twoToFourDays",
9
+ "fiveOrMoreDays"
10
+ ];
11
+ export { PICKUP_LEAD_TIMES };
@@ -0,0 +1,4 @@
1
+ // ../api-contract/src/recommendations.ts
2
+ /** related: alternatives to the product; complementary: things bought with it. */
3
+ const RECOMMENDATION_INTENTS = ["related", "complementary"];
4
+ export { RECOMMENDATION_INTENTS };
@@ -0,0 +1,27 @@
1
+ import { z } from "zod";
2
+ z.string().regex(/^[a-z0-9][a-z0-9-]{0,62}$/);
3
+ const SHOP_STATUSES = [
4
+ "active",
5
+ "closed",
6
+ "suspended"
7
+ ];
8
+ z.string().max(64).regex(/^[A-Za-z][A-Za-z0-9_+-]*(?:\/[A-Za-z0-9_+-]+)*$/).refine((zone) => {
9
+ try {
10
+ new Intl.DateTimeFormat("en-US", { timeZone: zone });
11
+ return true;
12
+ } catch {
13
+ return false;
14
+ }
15
+ }, "Not a time zone");
16
+ const STOREFRONT_LOCALES = [
17
+ "mn",
18
+ "en",
19
+ "zh",
20
+ "ru",
21
+ "ko",
22
+ "ja",
23
+ "de",
24
+ "fr",
25
+ "es"
26
+ ];
27
+ export { SHOP_STATUSES, STOREFRONT_LOCALES };
@@ -0,0 +1,100 @@
1
+ import "../../../contract-kit/src/index.js";
2
+ import { z } from "zod";
3
+ /**
4
+ * The events a storefront records, by `name`: GA4's ecommerce events. The
5
+ * checkout's (`checkout_*_submitted`, `payment_initiated`,
6
+ * `checkout_completed`) are the checkout app's, not a storefront's:
7
+ * `analytics.checkout.events.record` (checkout-analytics.ts).
8
+ */
9
+ export declare const storefrontEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
+ id: z.ZodUUID;
11
+ name: z.ZodLiteral<"search_submitted">;
12
+ query: z.ZodString;
13
+ resultCount: z.ZodOptional<z.ZodInt>;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ id: z.ZodUUID;
16
+ name: z.ZodLiteral<"collection_viewed">;
17
+ collectionId: z.core.$ZodBranded<z.ZodTemplateLiteral<`collection_${string}`>, "id:collection", "inout">;
18
+ collectionHandle: z.ZodOptional<z.ZodString>;
19
+ }, z.core.$strip>, z.ZodObject<{
20
+ id: z.ZodUUID;
21
+ name: z.ZodLiteral<"product_list_viewed">;
22
+ list: z.ZodObject<{
23
+ kind: z.ZodEnum<{
24
+ collection: "collection";
25
+ search: "search";
26
+ }>;
27
+ collectionId: z.ZodOptional<z.core.$ZodBranded<z.ZodTemplateLiteral<`collection_${string}`>, "id:collection", "inout">>;
28
+ }, z.core.$strip>;
29
+ resultCount: z.ZodOptional<z.ZodInt>;
30
+ items: z.ZodArray<z.ZodObject<{
31
+ productId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
32
+ index: z.ZodInt;
33
+ }, z.core.$strip>>;
34
+ }, z.core.$strip>, z.ZodObject<{
35
+ id: z.ZodUUID;
36
+ name: z.ZodLiteral<"product_clicked">;
37
+ productId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
38
+ productHandle: z.ZodOptional<z.ZodString>;
39
+ list: z.ZodOptional<z.ZodObject<{
40
+ kind: z.ZodEnum<{
41
+ collection: "collection";
42
+ search: "search";
43
+ }>;
44
+ collectionId: z.ZodOptional<z.core.$ZodBranded<z.ZodTemplateLiteral<`collection_${string}`>, "id:collection", "inout">>;
45
+ }, z.core.$strip>>;
46
+ index: z.ZodOptional<z.ZodInt>;
47
+ }, z.core.$strip>, z.ZodObject<{
48
+ id: z.ZodUUID;
49
+ name: z.ZodLiteral<"product_viewed">;
50
+ productId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
51
+ productHandle: z.ZodOptional<z.ZodString>;
52
+ }, z.core.$strip>, z.ZodObject<{
53
+ id: z.ZodUUID;
54
+ name: z.ZodLiteral<"recommendation_shown">;
55
+ productId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
56
+ productHandle: z.ZodOptional<z.ZodString>;
57
+ referenceProductId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
58
+ referenceProductHandle: z.ZodOptional<z.ZodString>;
59
+ intent: z.ZodEnum<{
60
+ complementary: "complementary";
61
+ related: "related";
62
+ }>;
63
+ index: z.ZodOptional<z.ZodInt>;
64
+ }, z.core.$strip>, z.ZodObject<{
65
+ id: z.ZodUUID;
66
+ name: z.ZodLiteral<"recommendation_clicked">;
67
+ productId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
68
+ productHandle: z.ZodOptional<z.ZodString>;
69
+ referenceProductId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
70
+ referenceProductHandle: z.ZodOptional<z.ZodString>;
71
+ intent: z.ZodEnum<{
72
+ complementary: "complementary";
73
+ related: "related";
74
+ }>;
75
+ index: z.ZodOptional<z.ZodInt>;
76
+ }, z.core.$strip>, z.ZodObject<{
77
+ id: z.ZodUUID;
78
+ name: z.ZodLiteral<"product_added_to_cart">;
79
+ productId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
80
+ variantId: z.core.$ZodBranded<z.ZodTemplateLiteral<`variant_${string}`>, "id:variant", "inout">;
81
+ quantity: z.ZodInt;
82
+ }, z.core.$strip>, z.ZodObject<{
83
+ id: z.ZodUUID;
84
+ name: z.ZodLiteral<"product_removed_from_cart">;
85
+ productId: z.core.$ZodBranded<z.ZodTemplateLiteral<`prod_${string}`>, "id:prod", "inout">;
86
+ variantId: z.core.$ZodBranded<z.ZodTemplateLiteral<`variant_${string}`>, "id:variant", "inout">;
87
+ quantity: z.ZodInt;
88
+ }, z.core.$strip>, z.ZodObject<{
89
+ id: z.ZodUUID;
90
+ name: z.ZodLiteral<"cart_viewed">;
91
+ lineCount: z.ZodInt;
92
+ totalQuantity: z.ZodInt;
93
+ subtotal: z.ZodInt;
94
+ }, z.core.$strip>, z.ZodObject<{
95
+ id: z.ZodUUID;
96
+ name: z.ZodLiteral<"checkout_started">;
97
+ totalQuantity: z.ZodInt;
98
+ subtotal: z.ZodInt;
99
+ }, z.core.$strip>], "name">;
100
+ export type StorefrontEvent = z.output<typeof storefrontEvent>;