@thorprovider/storefront 0.15.0 → 0.15.2
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/README.md +9 -4
- package/assets/templates/app/app/[[...slug]]/page.tsx +22 -4
- package/assets/templates/app/app/layout.tsx +2 -2
- package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +11 -4
- package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +7 -4
- package/assets/templates/app/lib/__STOREFRONT__/header-universal.ts +363 -0
- package/assets/templates/app/lib/__STOREFRONT__/registry.tsx +49 -1
- package/assets/templates/app/lib/__STOREFRONT__/schema.ts +52 -0
- package/assets/templates/app/lib/__STOREFRONT__/shell/content.ts +43 -0
- package/assets/templates/app/lib/__STOREFRONT__/shell/props.ts +4 -0
- package/assets/templates/app/lib/__STOREFRONT__/spec/index.ts +16 -43
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +8 -0
- package/assets/templates/app/lib/__STOREFRONT__/store-context.ts +84 -18
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/header-universal.client.tsx +33 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/header-universal.tsx +16 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/index.ts +2 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.header-universal.ts +360 -0
- package/assets/templates/views/cart/registry.tsx +9 -0
- package/assets/templates/views/checkout/checkout-commerce-hosted.tsx +5 -1
- package/package.json +1 -1
- package/recipes/sections.json +18 -0
- package/scripts/candidate.mjs +2 -2
- package/scripts/env-file.mjs +5 -0
- package/scripts/file-classes.mjs +7 -2
- package/skills/sf-view-gen/assets/recipes/sections.json +18 -0
- package/skills/sf-view-gen/assets/templates/views/sections/header-universal.client.tsx +33 -0
- package/skills/sf-view-gen/assets/templates/views/sections/header-universal.tsx +16 -0
- package/skills/sf-view-gen/assets/templates/views/sections/schema.header-universal.ts +360 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// Optional section fragment: header-universal (mirrors recipes/sections.json) — shared contract.
|
|
2
|
+
// Zod mirror of the HeaderUniversal block contract (delivery header-universal),
|
|
3
|
+
// shared by the server catalog (header-universal.tsx) and the client registry
|
|
4
|
+
// (header-universal.client.tsx). The React-only callback (`onAction`) is
|
|
5
|
+
// intentionally excluded; the runtime commerce data (`context.cart`,
|
|
6
|
+
// `context.account`, …) is carried through `context` exactly as the host feeds
|
|
7
|
+
// it, so the section serializes the same shape the block renders.
|
|
8
|
+
|
|
9
|
+
import { z } from 'zod'
|
|
10
|
+
import { universalMainMenuDataSchema } from './schema.universal-main-menu'
|
|
11
|
+
|
|
12
|
+
const surfaceToken = z.enum(['transparent', 'background', 'card', 'muted', 'primary', 'accent'])
|
|
13
|
+
const accentToken = z.enum(['none', 'primary', 'accent', 'success'])
|
|
14
|
+
const densityToken = z.enum(['compact', 'comfortable'])
|
|
15
|
+
const radiusToken = z.enum(['none', 'sm', 'md', 'lg', 'xl'])
|
|
16
|
+
const spaceToken = z.enum(['none', 'xs', 'sm', 'md', 'lg', 'xl'])
|
|
17
|
+
const heightToken = z.enum(['xs', 'sm', 'md', 'lg', 'xl'])
|
|
18
|
+
const borderToken = z.enum(['none', 'bottom', 'top', 'all'])
|
|
19
|
+
const shadowToken = z.enum(['none', 'sm', 'md'])
|
|
20
|
+
const positionToken = z.enum(['static', 'sticky', 'fixed'])
|
|
21
|
+
const breakpointToken = z.enum(['base', 'md', '2xl'])
|
|
22
|
+
const zoneName = z.enum(['start', 'center', 'end'])
|
|
23
|
+
const presetId = z.enum(['commerce', 'minimal', 'marketplace', 'b2b', 'checkout', 'landing'])
|
|
24
|
+
const contextKind = z.enum(['guest', 'authenticated', 'b2b', 'checkout', 'landing'])
|
|
25
|
+
const pageKind = z.enum(['home', 'category', 'product', 'checkout', 'account', 'landing'])
|
|
26
|
+
|
|
27
|
+
const moduleType = z.enum([
|
|
28
|
+
'logo',
|
|
29
|
+
'navigation',
|
|
30
|
+
'search',
|
|
31
|
+
'cart',
|
|
32
|
+
'account',
|
|
33
|
+
'wishlist',
|
|
34
|
+
'region',
|
|
35
|
+
'language',
|
|
36
|
+
'location',
|
|
37
|
+
'organization',
|
|
38
|
+
'announcement',
|
|
39
|
+
'promotion-progress',
|
|
40
|
+
'support',
|
|
41
|
+
'notifications',
|
|
42
|
+
'spacer',
|
|
43
|
+
'divider',
|
|
44
|
+
'text-label',
|
|
45
|
+
'custom-link',
|
|
46
|
+
'custom-button',
|
|
47
|
+
'icon-action',
|
|
48
|
+
'main-menu',
|
|
49
|
+
])
|
|
50
|
+
|
|
51
|
+
const capabilityId = z.enum([
|
|
52
|
+
'catalog',
|
|
53
|
+
'catalog-search',
|
|
54
|
+
'checkout',
|
|
55
|
+
'customer-account',
|
|
56
|
+
'saved-items',
|
|
57
|
+
'reviews',
|
|
58
|
+
'recommendations',
|
|
59
|
+
'newsletter',
|
|
60
|
+
'b2b',
|
|
61
|
+
'notifications',
|
|
62
|
+
'promotions',
|
|
63
|
+
'locations',
|
|
64
|
+
])
|
|
65
|
+
|
|
66
|
+
const headerActionName = z.enum([
|
|
67
|
+
'navigate',
|
|
68
|
+
'openCart',
|
|
69
|
+
'closeCart',
|
|
70
|
+
'goToCart',
|
|
71
|
+
'goToCheckout',
|
|
72
|
+
'openSearch',
|
|
73
|
+
'closeSearch',
|
|
74
|
+
'openAccount',
|
|
75
|
+
'closeAccount',
|
|
76
|
+
'openNotifications',
|
|
77
|
+
'login',
|
|
78
|
+
'register',
|
|
79
|
+
'logout',
|
|
80
|
+
'selectRegion',
|
|
81
|
+
'selectLanguage',
|
|
82
|
+
'selectLocation',
|
|
83
|
+
'selectOrganization',
|
|
84
|
+
'openComponent',
|
|
85
|
+
'closeComponent',
|
|
86
|
+
'changeCartQuantity',
|
|
87
|
+
'removeCartLine',
|
|
88
|
+
'selectNotification',
|
|
89
|
+
'dismissAnnouncement',
|
|
90
|
+
])
|
|
91
|
+
|
|
92
|
+
const modulePropsSchema = z.record(z.union([z.string(), z.number(), z.boolean()]))
|
|
93
|
+
|
|
94
|
+
const themeSchema = z.object({
|
|
95
|
+
surface: surfaceToken,
|
|
96
|
+
accent: accentToken,
|
|
97
|
+
density: densityToken,
|
|
98
|
+
radius: radiusToken,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const behaviorSchema = z.object({
|
|
102
|
+
position: positionToken,
|
|
103
|
+
transparent: z.boolean(),
|
|
104
|
+
overHero: z.boolean(),
|
|
105
|
+
scrolledSurface: z.boolean(),
|
|
106
|
+
compactOnScroll: z.boolean(),
|
|
107
|
+
hideOnScrollDown: z.boolean(),
|
|
108
|
+
showOnScrollUp: z.boolean(),
|
|
109
|
+
threshold: z.number(),
|
|
110
|
+
zIndex: z.number(),
|
|
111
|
+
reducedMotion: z.boolean(),
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const rowStyleSchema = z.object({
|
|
115
|
+
minHeight: heightToken,
|
|
116
|
+
maxHeight: z.union([heightToken, z.literal('none')]),
|
|
117
|
+
paddingX: spaceToken,
|
|
118
|
+
paddingY: spaceToken,
|
|
119
|
+
gap: spaceToken,
|
|
120
|
+
align: z.enum(['start', 'center', 'end']),
|
|
121
|
+
justify: z.enum(['start', 'center', 'between', 'end']),
|
|
122
|
+
maxWidth: z.enum(['full', 'sm', 'md', 'lg', 'xl']),
|
|
123
|
+
surface: surfaceToken,
|
|
124
|
+
border: borderToken,
|
|
125
|
+
shadow: shadowToken,
|
|
126
|
+
separator: z.boolean(),
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const headerActionSchema = z.object({
|
|
130
|
+
name: headerActionName,
|
|
131
|
+
payload: modulePropsSchema.optional(),
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
const moduleSchema = z.object({
|
|
135
|
+
id: z.string(),
|
|
136
|
+
type: moduleType,
|
|
137
|
+
enabled: z.boolean(),
|
|
138
|
+
requires: capabilityId.optional(),
|
|
139
|
+
props: modulePropsSchema,
|
|
140
|
+
style: z
|
|
141
|
+
.object({
|
|
142
|
+
surface: surfaceToken.optional(),
|
|
143
|
+
size: z.enum(['sm', 'md', 'lg']).optional(),
|
|
144
|
+
emphasis: z.enum(['none', 'accent']).optional(),
|
|
145
|
+
})
|
|
146
|
+
.optional(),
|
|
147
|
+
visibility: z
|
|
148
|
+
.object({
|
|
149
|
+
breakpoints: z.array(breakpointToken).optional(),
|
|
150
|
+
contexts: z.array(contextKind).optional(),
|
|
151
|
+
})
|
|
152
|
+
.optional(),
|
|
153
|
+
responsive: z
|
|
154
|
+
.record(
|
|
155
|
+
breakpointToken,
|
|
156
|
+
z.object({
|
|
157
|
+
row: z.string().optional(),
|
|
158
|
+
zone: zoneName.optional(),
|
|
159
|
+
order: z.number().optional(),
|
|
160
|
+
hidden: z.boolean().optional(),
|
|
161
|
+
props: modulePropsSchema.optional(),
|
|
162
|
+
}),
|
|
163
|
+
)
|
|
164
|
+
.optional(),
|
|
165
|
+
bindings: z.record(z.string(), z.string()).optional(),
|
|
166
|
+
actions: z.record(z.string(), headerActionSchema).optional(),
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const rowSchema = rowStyleSchema.extend({
|
|
170
|
+
id: z.string(),
|
|
171
|
+
enabled: z.boolean(),
|
|
172
|
+
zones: z.record(zoneName, z.array(z.string())),
|
|
173
|
+
responsive: z
|
|
174
|
+
.record(
|
|
175
|
+
breakpointToken,
|
|
176
|
+
rowStyleSchema
|
|
177
|
+
.partial()
|
|
178
|
+
.extend({
|
|
179
|
+
zones: z.record(zoneName, z.array(z.string()).optional()).optional(),
|
|
180
|
+
hidden: z.boolean().optional(),
|
|
181
|
+
}),
|
|
182
|
+
)
|
|
183
|
+
.optional(),
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const visibilityRuleSchema = z.object({
|
|
187
|
+
id: z.string(),
|
|
188
|
+
target: z.object({
|
|
189
|
+
rows: z.array(z.string()).optional(),
|
|
190
|
+
modules: z.array(z.string()).optional(),
|
|
191
|
+
}),
|
|
192
|
+
when: z.object({
|
|
193
|
+
capability: capabilityId.optional(),
|
|
194
|
+
context: contextKind.optional(),
|
|
195
|
+
page: pageKind.optional(),
|
|
196
|
+
from: z.string().optional(),
|
|
197
|
+
to: z.string().optional(),
|
|
198
|
+
}),
|
|
199
|
+
mode: z.literal('hide'),
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
export const headerConfigSchema = z.object({
|
|
203
|
+
schemaVersion: z.number(),
|
|
204
|
+
id: z.string(),
|
|
205
|
+
name: z.string(),
|
|
206
|
+
preset: presetId,
|
|
207
|
+
theme: themeSchema,
|
|
208
|
+
behavior: behaviorSchema,
|
|
209
|
+
layout: z.array(rowSchema),
|
|
210
|
+
modules: z.array(moduleSchema),
|
|
211
|
+
capabilities: z.record(capabilityId, z.boolean().optional()),
|
|
212
|
+
visibilityRules: z.array(visibilityRuleSchema),
|
|
213
|
+
fallbacks: z.object({
|
|
214
|
+
missingCapability: z.enum(['hide', 'placeholder']),
|
|
215
|
+
missingImage: z.enum(['fallback', 'label']),
|
|
216
|
+
missingAction: z.enum(['disable', 'hide']),
|
|
217
|
+
}),
|
|
218
|
+
analytics: z.object({ events: z.array(z.string()) }).optional(),
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
const moneySchema = z.object({ amount: z.string(), currencyCode: z.string() })
|
|
222
|
+
|
|
223
|
+
const brandSchema = z.object({
|
|
224
|
+
name: z.string(),
|
|
225
|
+
href: z.string(),
|
|
226
|
+
logo: z.string().optional(),
|
|
227
|
+
logoLight: z.string().optional(),
|
|
228
|
+
logoDark: z.string().optional(),
|
|
229
|
+
accent: z.string().optional(),
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
const cartStateKind = z.enum(['ready', 'empty', 'loading', 'error'])
|
|
233
|
+
const accountStateKind = z.enum(['guest', 'authenticated', 'loading', 'expired', 'error'])
|
|
234
|
+
|
|
235
|
+
const cartLineSchema = z.object({
|
|
236
|
+
id: z.string(),
|
|
237
|
+
name: z.string(),
|
|
238
|
+
price: z.number(),
|
|
239
|
+
quantity: z.number(),
|
|
240
|
+
variant: z.string().optional(),
|
|
241
|
+
image: z.string().optional(),
|
|
242
|
+
unitPrice: moneySchema.optional(),
|
|
243
|
+
lineTotal: moneySchema.optional(),
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
const headerCartSchema = z.object({
|
|
247
|
+
state: cartStateKind,
|
|
248
|
+
lines: z.array(cartLineSchema),
|
|
249
|
+
totals: z
|
|
250
|
+
.object({
|
|
251
|
+
subtotal: moneySchema,
|
|
252
|
+
total: moneySchema,
|
|
253
|
+
discount: moneySchema.optional(),
|
|
254
|
+
tax: moneySchema.optional(),
|
|
255
|
+
shipping: moneySchema.optional(),
|
|
256
|
+
})
|
|
257
|
+
.optional(),
|
|
258
|
+
quantity: z.number(),
|
|
259
|
+
lineCount: z.number(),
|
|
260
|
+
currency: z.string(),
|
|
261
|
+
shippingGroups: z.number(),
|
|
262
|
+
shippingNote: z.string().optional(),
|
|
263
|
+
subtotalUnavailableLabel: z.string(),
|
|
264
|
+
promotions: z.array(z.string()),
|
|
265
|
+
error: z.string().optional(),
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
const accountUserSchema = z.object({
|
|
269
|
+
email: z.string(),
|
|
270
|
+
name: z.string(),
|
|
271
|
+
initials: z.string(),
|
|
272
|
+
avatar: z.string().optional(),
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
const accountMenuItemSchema = z.object({
|
|
276
|
+
label: z.string(),
|
|
277
|
+
href: z.string(),
|
|
278
|
+
icon: z.enum(['orders', 'wishlist', 'addresses', 'settings']).optional(),
|
|
279
|
+
description: z.string().optional(),
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
const headerAccountSchema = z.object({
|
|
283
|
+
state: accountStateKind,
|
|
284
|
+
user: accountUserSchema.optional(),
|
|
285
|
+
menu: z.array(accountMenuItemSchema),
|
|
286
|
+
error: z.string().optional(),
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
const headerContextSchema = z.object({
|
|
290
|
+
brand: brandSchema,
|
|
291
|
+
menu: universalMainMenuDataSchema.optional(),
|
|
292
|
+
cart: headerCartSchema,
|
|
293
|
+
account: headerAccountSchema,
|
|
294
|
+
wishlist: z.object({ count: z.number(), lists: z.number() }),
|
|
295
|
+
regions: z.object({
|
|
296
|
+
activeId: z.string(),
|
|
297
|
+
options: z.array(z.object({ id: z.string(), label: z.string(), currencyCode: z.string() })),
|
|
298
|
+
}),
|
|
299
|
+
languages: z.object({
|
|
300
|
+
activeCode: z.string(),
|
|
301
|
+
options: z.array(z.object({ code: z.string(), label: z.string() })),
|
|
302
|
+
}),
|
|
303
|
+
locations: z.object({
|
|
304
|
+
activeId: z.string().optional(),
|
|
305
|
+
enabled: z.boolean(),
|
|
306
|
+
options: z.array(z.object({ id: z.string(), label: z.string(), detail: z.string().optional() })),
|
|
307
|
+
}),
|
|
308
|
+
organization: z
|
|
309
|
+
.object({
|
|
310
|
+
activeId: z.string(),
|
|
311
|
+
options: z.array(
|
|
312
|
+
z.object({
|
|
313
|
+
id: z.string(),
|
|
314
|
+
name: z.string(),
|
|
315
|
+
role: z.string(),
|
|
316
|
+
permissions: z.array(z.string()),
|
|
317
|
+
}),
|
|
318
|
+
),
|
|
319
|
+
})
|
|
320
|
+
.optional(),
|
|
321
|
+
announcements: z.array(
|
|
322
|
+
z.object({
|
|
323
|
+
id: z.string(),
|
|
324
|
+
message: z.string(),
|
|
325
|
+
href: z.string().optional(),
|
|
326
|
+
linkLabel: z.string().optional(),
|
|
327
|
+
tone: z.enum(['info', 'accent', 'muted']),
|
|
328
|
+
from: z.string().optional(),
|
|
329
|
+
to: z.string().optional(),
|
|
330
|
+
dismissible: z.boolean(),
|
|
331
|
+
}),
|
|
332
|
+
),
|
|
333
|
+
promotion: z
|
|
334
|
+
.object({
|
|
335
|
+
state: z.enum(['not-eligible', 'in-progress', 'complete']),
|
|
336
|
+
threshold: z.string().optional(),
|
|
337
|
+
current: z.string().optional(),
|
|
338
|
+
remaining: z.string().optional(),
|
|
339
|
+
message: z.string().optional(),
|
|
340
|
+
})
|
|
341
|
+
.optional(),
|
|
342
|
+
notifications: z.object({
|
|
343
|
+
available: z.boolean(),
|
|
344
|
+
unread: z.number(),
|
|
345
|
+
items: z.array(z.object({ id: z.string(), title: z.string(), href: z.string(), read: z.boolean() })),
|
|
346
|
+
}),
|
|
347
|
+
openComponents: z.array(z.string()),
|
|
348
|
+
now: z.string(),
|
|
349
|
+
capabilities: z.record(capabilityId, z.boolean().optional()),
|
|
350
|
+
context: contextKind,
|
|
351
|
+
page: pageKind,
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
export const universalHeaderPropsSchema = z.object({
|
|
355
|
+
config: headerConfigSchema,
|
|
356
|
+
context: headerContextSchema,
|
|
357
|
+
labels: z.record(z.string(), z.record(z.string(), z.string())).optional(),
|
|
358
|
+
breakpoint: breakpointToken.optional(),
|
|
359
|
+
className: z.string().optional(),
|
|
360
|
+
})
|