@decocms/blocks 8.0.0 → 8.1.0-next.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 (220) hide show
  1. package/bin/deco.js +13 -0
  2. package/package.json +32 -82
  3. package/src/index.ts +35 -8
  4. package/src/protocol/assets.ts +124 -0
  5. package/src/protocol/canonical.ts +7 -0
  6. package/src/protocol/ciphertext.ts +6 -0
  7. package/src/protocol/client.ts +170 -0
  8. package/src/protocol/conformance/cases/assets.ts +81 -0
  9. package/src/protocol/conformance/cases/guards.ts +314 -0
  10. package/src/protocol/conformance/cases/reads.ts +168 -0
  11. package/src/protocol/conformance/cases/types.ts +9 -0
  12. package/src/protocol/conformance/cases/wire.ts +138 -0
  13. package/src/protocol/conformance/cases/writes.ts +345 -0
  14. package/src/protocol/conformance/contentHashFixtures.ts +79 -0
  15. package/src/protocol/conformance/context.ts +222 -0
  16. package/src/protocol/conformance/index.ts +140 -0
  17. package/src/protocol/errors.ts +142 -0
  18. package/src/protocol/index.ts +39 -0
  19. package/src/protocol/keys.ts +279 -0
  20. package/src/protocol/params.ts +67 -0
  21. package/src/protocol/secrets.ts +231 -0
  22. package/src/protocol/server/assets.ts +119 -0
  23. package/src/protocol/server/auth.ts +49 -0
  24. package/src/protocol/server/bodyCache.ts +84 -0
  25. package/src/protocol/server/content.ts +175 -0
  26. package/src/protocol/server/core.ts +112 -0
  27. package/src/protocol/server/handler.ts +102 -0
  28. package/src/protocol/server/http.ts +139 -0
  29. package/src/protocol/server/index.ts +11 -0
  30. package/src/protocol/server/methods/apply.ts +341 -0
  31. package/src/protocol/server/methods/read.ts +156 -0
  32. package/src/protocol/server/rpc.ts +136 -0
  33. package/src/protocol/storage/fs/hash.ts +21 -0
  34. package/src/protocol/storage/fs/index.ts +338 -0
  35. package/src/protocol/storage/fs/lock.ts +68 -0
  36. package/src/protocol/storage/fs/transaction.ts +183 -0
  37. package/src/protocol/storage/fs/unsupported.ts +15 -0
  38. package/src/protocol/storage/memory.ts +238 -0
  39. package/src/protocol/storage.ts +182 -0
  40. package/src/protocol/types.ts +172 -0
  41. package/src/v8/analytics.ts +50 -0
  42. package/src/v8/background.ts +107 -0
  43. package/src/v8/builtins/data.ts +23 -0
  44. package/src/v8/builtins/index.ts +26 -0
  45. package/src/v8/builtins/lazy.ts +23 -0
  46. package/src/v8/builtins/legacy.ts +65 -0
  47. package/src/v8/builtins/matchers.ts +31 -0
  48. package/src/v8/builtins/multivariate.ts +25 -0
  49. package/src/v8/builtins/secret.ts +82 -0
  50. package/src/v8/canonical.ts +117 -0
  51. package/src/v8/ciphertext.ts +158 -0
  52. package/src/v8/cli/builtins.ts +20 -0
  53. package/src/v8/cli/check/index.ts +774 -0
  54. package/src/v8/cli/check/messages.ts +168 -0
  55. package/src/v8/cli/content.ts +287 -0
  56. package/src/v8/cli/index.ts +17 -0
  57. package/src/v8/cli/log.ts +18 -0
  58. package/src/v8/cli/main.ts +12 -0
  59. package/src/v8/cli/root.ts +66 -0
  60. package/src/v8/cli/run.ts +236 -0
  61. package/src/v8/cli/schema/builtinSchemas.ts +236 -0
  62. package/src/v8/cli/schema/generate.ts +507 -0
  63. package/src/v8/cli/schema/index.ts +63 -0
  64. package/src/v8/cli/schema/tsProgram.ts +497 -0
  65. package/src/v8/cli/schema/typeToSchema.ts +689 -0
  66. package/src/v8/cli/serve/server.ts +303 -0
  67. package/src/v8/cli/watch.ts +86 -0
  68. package/src/v8/client.ts +147 -0
  69. package/src/v8/cms.ts +237 -0
  70. package/src/v8/content.ts +195 -0
  71. package/src/v8/draft.ts +136 -0
  72. package/src/v8/errors.ts +59 -0
  73. package/src/v8/fetch.ts +133 -0
  74. package/src/v8/identity.ts +65 -0
  75. package/src/v8/index.ts +39 -0
  76. package/src/v8/json.ts +74 -0
  77. package/src/v8/matchRoute.ts +204 -0
  78. package/src/v8/remoteLoader.ts +282 -0
  79. package/src/v8/resolver.ts +278 -0
  80. package/src/v8/secrets.ts +17 -0
  81. package/src/v8/telemetry.ts +533 -0
  82. package/src/v8/types.ts +240 -0
  83. package/src/cms/applySectionConventions.ts +0 -124
  84. package/src/cms/blockSource.test.ts +0 -76
  85. package/src/cms/blockSource.ts +0 -191
  86. package/src/cms/client.browserBundle.test.ts +0 -44
  87. package/src/cms/client.ts +0 -80
  88. package/src/cms/draftSource.test.ts +0 -343
  89. package/src/cms/draftSource.ts +0 -362
  90. package/src/cms/index.ts +0 -151
  91. package/src/cms/layoutCacheRace.test.ts +0 -181
  92. package/src/cms/loadDecofileDirectory.test.ts +0 -109
  93. package/src/cms/loadDecofileDirectory.ts +0 -89
  94. package/src/cms/loader.test.ts +0 -200
  95. package/src/cms/loader.ts +0 -304
  96. package/src/cms/registry.test.ts +0 -110
  97. package/src/cms/registry.ts +0 -242
  98. package/src/cms/resolve.test.ts +0 -980
  99. package/src/cms/resolve.ts +0 -2282
  100. package/src/cms/schema.test.ts +0 -356
  101. package/src/cms/schema.ts +0 -1215
  102. package/src/cms/sectionLoaderContext.test.ts +0 -111
  103. package/src/cms/sectionLoaderContext.ts +0 -113
  104. package/src/cms/sectionLoaders.test.ts +0 -533
  105. package/src/cms/sectionLoaders.ts +0 -636
  106. package/src/cms/sectionMixins.test.ts +0 -167
  107. package/src/cms/sectionMixins.ts +0 -153
  108. package/src/cms/stickyFlags.test.ts +0 -117
  109. package/src/flags/audience.ts +0 -56
  110. package/src/flags/everyone.ts +0 -29
  111. package/src/flags/flag.ts +0 -15
  112. package/src/flags/flags.test.ts +0 -148
  113. package/src/flags/multivariate/image.ts +0 -11
  114. package/src/flags/multivariate/message.ts +0 -11
  115. package/src/flags/multivariate/page.ts +0 -16
  116. package/src/flags/multivariate/section.ts +0 -16
  117. package/src/flags/multivariate.ts +0 -1
  118. package/src/flags/types.ts +0 -59
  119. package/src/flags/utils/multivariate.ts +0 -20
  120. package/src/hooks/Image.test.ts +0 -100
  121. package/src/hooks/Image.tsx +0 -250
  122. package/src/hooks/JsonLd.tsx +0 -353
  123. package/src/hooks/LazySection.tsx +0 -121
  124. package/src/hooks/LiveControls.tsx +0 -122
  125. package/src/hooks/Picture.tsx +0 -127
  126. package/src/hooks/RenderSection.test.tsx +0 -81
  127. package/src/hooks/RenderSection.tsx +0 -91
  128. package/src/hooks/SectionErrorFallback.tsx +0 -97
  129. package/src/hooks/index.ts +0 -30
  130. package/src/matchers/builtins.test.ts +0 -318
  131. package/src/matchers/builtins.ts +0 -459
  132. package/src/matchers/countryNames.ts +0 -104
  133. package/src/matchers/override.test.ts +0 -205
  134. package/src/matchers/override.ts +0 -136
  135. package/src/matchers/posthog.ts +0 -154
  136. package/src/middleware/decoState.ts +0 -55
  137. package/src/middleware/healthMetrics.ts +0 -133
  138. package/src/middleware/hydrationContext.test.ts +0 -61
  139. package/src/middleware/hydrationContext.ts +0 -79
  140. package/src/middleware/index.ts +0 -88
  141. package/src/middleware/liveness.ts +0 -21
  142. package/src/middleware/observability.test.ts +0 -242
  143. package/src/middleware/observability.ts +0 -643
  144. package/src/middleware/validateSection.test.ts +0 -147
  145. package/src/middleware/validateSection.ts +0 -100
  146. package/src/sdk/abTesting.test.ts +0 -326
  147. package/src/sdk/abTesting.ts +0 -499
  148. package/src/sdk/analytics.ts +0 -77
  149. package/src/sdk/cacheHeaders.test.ts +0 -115
  150. package/src/sdk/cacheHeaders.ts +0 -433
  151. package/src/sdk/cachedLoader.test.ts +0 -122
  152. package/src/sdk/cachedLoader.ts +0 -503
  153. package/src/sdk/cachedLoaderModule.test.ts +0 -209
  154. package/src/sdk/clx.ts +0 -5
  155. package/src/sdk/cn.test.ts +0 -34
  156. package/src/sdk/cn.ts +0 -28
  157. package/src/sdk/composite.test.ts +0 -121
  158. package/src/sdk/composite.ts +0 -114
  159. package/src/sdk/cookie.test.ts +0 -108
  160. package/src/sdk/cookie.ts +0 -129
  161. package/src/sdk/crypto.ts +0 -185
  162. package/src/sdk/csp.ts +0 -59
  163. package/src/sdk/detectDevice.ts +0 -45
  164. package/src/sdk/djb2.ts +0 -20
  165. package/src/sdk/encoding.test.ts +0 -71
  166. package/src/sdk/encoding.ts +0 -47
  167. package/src/sdk/env.test.ts +0 -33
  168. package/src/sdk/env.ts +0 -54
  169. package/src/sdk/flags.test.ts +0 -91
  170. package/src/sdk/flags.ts +0 -108
  171. package/src/sdk/http.test.ts +0 -71
  172. package/src/sdk/http.ts +0 -124
  173. package/src/sdk/index.ts +0 -90
  174. package/src/sdk/inflightTimeout.test.ts +0 -35
  175. package/src/sdk/inflightTimeout.ts +0 -53
  176. package/src/sdk/instrumentedFetch.test.ts +0 -559
  177. package/src/sdk/instrumentedFetch.ts +0 -339
  178. package/src/sdk/invoke.test.ts +0 -115
  179. package/src/sdk/invoke.ts +0 -298
  180. package/src/sdk/logger.test.ts +0 -432
  181. package/src/sdk/logger.ts +0 -304
  182. package/src/sdk/mergeCacheControl.ts +0 -150
  183. package/src/sdk/normalizeUrls.ts +0 -91
  184. package/src/sdk/observability.ts +0 -109
  185. package/src/sdk/otel.test.ts +0 -526
  186. package/src/sdk/otel.ts +0 -1012
  187. package/src/sdk/otelAdapters/clickhouseCollector.ts +0 -65
  188. package/src/sdk/otelAdapters.test.ts +0 -89
  189. package/src/sdk/otelAdapters.ts +0 -144
  190. package/src/sdk/otelHttpLog.test.ts +0 -457
  191. package/src/sdk/otelHttpLog.ts +0 -419
  192. package/src/sdk/otelHttpMeter.test.ts +0 -292
  193. package/src/sdk/otelHttpMeter.ts +0 -506
  194. package/src/sdk/otelHttpTracer.test.ts +0 -474
  195. package/src/sdk/otelHttpTracer.ts +0 -543
  196. package/src/sdk/redirects.ts +0 -228
  197. package/src/sdk/requestContext.ts +0 -281
  198. package/src/sdk/requestContextStorage.browser.test.ts +0 -29
  199. package/src/sdk/requestContextStorage.browser.ts +0 -43
  200. package/src/sdk/requestContextStorage.ts +0 -35
  201. package/src/sdk/retry.ts +0 -45
  202. package/src/sdk/serverTimings.ts +0 -68
  203. package/src/sdk/signal.ts +0 -42
  204. package/src/sdk/sitemap.ts +0 -160
  205. package/src/sdk/urlRedaction.test.ts +0 -73
  206. package/src/sdk/urlRedaction.ts +0 -82
  207. package/src/sdk/urlUtils.ts +0 -134
  208. package/src/sdk/useDevice.test.ts +0 -130
  209. package/src/sdk/useDevice.ts +0 -89
  210. package/src/sdk/useDeviceContext.tsx +0 -108
  211. package/src/sdk/useId.ts +0 -7
  212. package/src/sdk/useScript.test.ts +0 -128
  213. package/src/sdk/useScript.ts +0 -210
  214. package/src/sdk/useSuggestions.test.ts +0 -230
  215. package/src/sdk/useSuggestions.ts +0 -188
  216. package/src/sdk/wrapCaughtErrors.ts +0 -107
  217. package/src/setup.ts +0 -120
  218. package/src/types/index.ts +0 -53
  219. package/src/types/widgets.ts +0 -14
  220. package/tsconfig.json +0 -7
package/src/cms/schema.ts DELETED
@@ -1,1215 +0,0 @@
1
- /**
2
- * Framework-level schema definitions and runtime meta composition.
3
- *
4
- * The schema generator (scripts/generate-schema.ts) produces section and app
5
- * schemas from site TypeScript files. Framework-managed block types -- pages,
6
- * loaders, matchers, flags -- have their schemas defined here and injected
7
- * at runtime via composeMeta().
8
- *
9
- * This keeps the generator focused on site-specific concerns while the
10
- * framework owns the schemas for its own block types.
11
- */
12
-
13
- export interface MetaResponse {
14
- major: number;
15
- version: string;
16
- namespace: string;
17
- site: string;
18
- manifest: {
19
- blocks: Record<string, Record<string, { $ref: string; namespace?: string }>>;
20
- };
21
- schema: {
22
- definitions: Record<string, any>;
23
- root: Record<string, any>;
24
- };
25
- platform?: string;
26
- cloudProvider?: string;
27
- framework?: string;
28
- etag?: string;
29
- }
30
-
31
- /**
32
- * Standard base64 encoding that matches the browser's btoa().
33
- * The admin uses btoa(resolveType) in some code paths to construct
34
- * definition refs, so our keys MUST include the = padding.
35
- */
36
- function toBase64(str: string): string {
37
- if (typeof btoa === "function") return btoa(str);
38
- return Buffer.from(str).toString("base64");
39
- }
40
-
41
- // The admin's deRefUntil and ArrayFieldTemplate look for the LITERAL
42
- // string "Resolvable" (not base64-encoded). Both keys are needed:
43
- // - literal for admin detection
44
- // - base64 for backward compat with any code that does btoa("Resolvable")
45
- const RESOLVABLE_LITERAL_KEY = "Resolvable";
46
- const RESOLVABLE_B64_KEY = toBase64("Resolvable");
47
-
48
- function buildResolvableDefinition() {
49
- return {
50
- title: "Select from saved",
51
- type: "object",
52
- required: ["__resolveType"],
53
- additionalProperties: true,
54
- properties: { __resolveType: { type: "string" } },
55
- };
56
- }
57
-
58
- // ---------------------------------------------------------------------------
59
- // Loader definitions — dynamic registry
60
- // ---------------------------------------------------------------------------
61
-
62
- export interface LoaderConfig {
63
- key: string;
64
- title: string;
65
- namespace: string;
66
- description?: string;
67
- icon?: string;
68
- propsSchema: Record<string, any>;
69
- /** Tags for property matching (e.g., "product-list" enables injection into Product[] props). */
70
- tags?: string[];
71
- /**
72
- * Auto-registered placeholder with no real props (see registerCommerceLoaders).
73
- * A stub never overwrites a real schema for the same key, regardless of
74
- * registration order.
75
- */
76
- isStub?: boolean;
77
- }
78
-
79
- const loaderRegistry: LoaderConfig[] = [];
80
-
81
- /** Register a single loader schema for the admin. */
82
- export function registerLoaderSchema(config: LoaderConfig) {
83
- const idx = loaderRegistry.findIndex((l) => l.key === config.key);
84
- if (idx >= 0) {
85
- if (config.isStub && !loaderRegistry[idx].isStub) return;
86
- loaderRegistry[idx] = config;
87
- } else {
88
- loaderRegistry.push(config);
89
- }
90
- }
91
-
92
- /** Register multiple loader schemas at once. */
93
- export function registerLoaderSchemas(configs: LoaderConfig[]) {
94
- for (const config of configs) registerLoaderSchema(config);
95
- }
96
-
97
- /** Get all registered loader schemas. */
98
- export function getRegisteredLoaders(): LoaderConfig[] {
99
- return [...loaderRegistry];
100
- }
101
-
102
- function getProductListLoaderKeys(): string[] {
103
- return loaderRegistry.filter((l) => l.tags?.includes("product-list")).map((l) => l.key);
104
- }
105
-
106
- // ---------------------------------------------------------------------------
107
- // Action definitions — dynamic registry
108
- // ---------------------------------------------------------------------------
109
-
110
- export interface ActionConfig {
111
- key: string;
112
- title: string;
113
- namespace: string;
114
- description?: string;
115
- icon?: string;
116
- propsSchema: Record<string, any>;
117
- /** Auto-registered placeholder — never overwrites a real schema. See LoaderConfig.isStub. */
118
- isStub?: boolean;
119
- }
120
-
121
- const actionRegistry: ActionConfig[] = [];
122
-
123
- /** Register a single action schema for the admin. */
124
- export function registerActionSchema(config: ActionConfig) {
125
- const idx = actionRegistry.findIndex((a) => a.key === config.key);
126
- if (idx >= 0) {
127
- if (config.isStub && !actionRegistry[idx].isStub) return;
128
- actionRegistry[idx] = config;
129
- } else {
130
- actionRegistry.push(config);
131
- }
132
- }
133
-
134
- /** Register multiple action schemas at once. */
135
- export function registerActionSchemas(configs: ActionConfig[]) {
136
- for (const config of configs) registerActionSchema(config);
137
- }
138
-
139
- // ---------------------------------------------------------------------------
140
- // App block schemas — real props generated at app build time
141
- // ---------------------------------------------------------------------------
142
-
143
- /**
144
- * Loader keys matching these substrings return product lists — the admin uses
145
- * the "product-list" tag to offer them as loader pickers on Product[] props.
146
- */
147
- export function inferLoaderTags(key: string): string[] {
148
- if (
149
- key.includes("productList") ||
150
- key.includes("ProductList") ||
151
- key.includes("ProductShelf") ||
152
- key.includes("SearchResult")
153
- ) {
154
- return ["product-list"];
155
- }
156
- return [];
157
- }
158
-
159
- /**
160
- * Props schema of a single loader/action as emitted by blocks-cli's
161
- * generate-app-schemas.ts into an app package's src/schemas.gen.ts.
162
- * Same shape generate-schema.ts produces for site loaders.
163
- */
164
- export interface BlockPropsSchema {
165
- type?: "object";
166
- title?: string;
167
- description?: string;
168
- properties?: Record<string, any>;
169
- required?: string[];
170
- additionalProperties?: boolean;
171
- /** Any other JSON Schema keyword or JSDoc passthrough tag (nullable, …). */
172
- [keyword: string]: any;
173
- }
174
-
175
- export interface AppSchemas {
176
- namespace: string;
177
- loaders?: Record<string, BlockPropsSchema>;
178
- actions?: Record<string, BlockPropsSchema>;
179
- }
180
-
181
- /**
182
- * Register the real loader/action props schemas an app package generated at
183
- * build time (src/schemas.gen.ts). These take precedence over the
184
- * `__resolveType`-only stubs auto-registered by registerCommerceLoaders(),
185
- * regardless of which side registers first.
186
- */
187
- export function registerAppSchemas(app: AppSchemas): void {
188
- const loaderConfigs: LoaderConfig[] = Object.entries(app.loaders ?? {}).map(([key, schema]) => ({
189
- key,
190
- title: schema.title || key,
191
- namespace: app.namespace,
192
- ...(schema.description ? { description: schema.description } : {}),
193
- propsSchema: schema,
194
- tags: inferLoaderTags(key),
195
- }));
196
- const actionConfigs: ActionConfig[] = Object.entries(app.actions ?? {}).map(([key, schema]) => ({
197
- key,
198
- title: schema.title || key,
199
- namespace: app.namespace,
200
- ...(schema.description ? { description: schema.description } : {}),
201
- propsSchema: schema,
202
- }));
203
- registerLoaderSchemas(loaderConfigs);
204
- registerActionSchemas(actionConfigs);
205
- }
206
-
207
- function buildActionDefinitions() {
208
- const definitions: Record<string, any> = {};
209
- const manifestBlocks: Record<string, any> = {};
210
-
211
- for (const action of actionRegistry) {
212
- const defKey = toBase64(action.key);
213
-
214
- definitions[defKey] = {
215
- title: action.title || action.key,
216
- ...(action.description ? { description: action.description } : {}),
217
- ...(action.icon ? { icon: action.icon } : {}),
218
- type: "object",
219
- required: ["__resolveType", ...(action.propsSchema?.required || [])],
220
- properties: {
221
- __resolveType: {
222
- type: "string",
223
- enum: [action.key],
224
- default: action.key,
225
- },
226
- ...(action.propsSchema?.properties || {}),
227
- },
228
- // Preserved so the admin can tell "props unknown — edit as JSON" (stub)
229
- // apart from "takes no input" (real schema without the flag).
230
- ...(action.propsSchema?.additionalProperties === true ? { additionalProperties: true } : {}),
231
- };
232
-
233
- manifestBlocks[action.key] = {
234
- $ref: `#/definitions/${defKey}`,
235
- namespace: action.namespace,
236
- };
237
- }
238
-
239
- return { definitions, manifestBlocks };
240
- }
241
-
242
- // ---------------------------------------------------------------------------
243
- // Matcher definitions — dynamic registry
244
- // ---------------------------------------------------------------------------
245
-
246
- export interface MatcherConfig {
247
- key: string;
248
- title: string;
249
- namespace: string;
250
- description?: string;
251
- icon?: string;
252
- propsSchema?: Record<string, any>;
253
- }
254
-
255
- const matcherRegistry: MatcherConfig[] = [];
256
-
257
- /** Register a single matcher schema for the admin. */
258
- export function registerMatcherSchema(config: MatcherConfig) {
259
- const idx = matcherRegistry.findIndex((m) => m.key === config.key);
260
- if (idx >= 0) {
261
- matcherRegistry[idx] = config;
262
- } else {
263
- matcherRegistry.push(config);
264
- }
265
- }
266
-
267
- /** Register multiple matcher schemas at once. */
268
- export function registerMatcherSchemas(configs: MatcherConfig[]) {
269
- for (const config of configs) registerMatcherSchema(config);
270
- }
271
-
272
- /** Get all registered matcher schemas. */
273
- export function getRegisteredMatchers(): MatcherConfig[] {
274
- return matcherRegistry;
275
- }
276
-
277
- // Register built-in matchers that are always available
278
- registerMatcherSchemas([
279
- {
280
- key: "website/matchers/always.ts",
281
- title: "Always",
282
- description: "Target all users",
283
- icon: "eye",
284
- namespace: "website",
285
- },
286
- {
287
- key: "website/matchers/never.ts",
288
- title: "Never",
289
- description: "Hide from all users",
290
- icon: "eye-off",
291
- namespace: "website",
292
- },
293
- {
294
- key: "website/matchers/device.ts",
295
- title: "Device",
296
- description: "Target users based on their device type, such as desktop, tablet, or mobile",
297
- icon: "device-mobile",
298
- namespace: "website",
299
- propsSchema: {
300
- type: "object",
301
- properties: {
302
- mobile: { type: "boolean", title: "Mobile" },
303
- desktop: { type: "boolean", title: "Desktop" },
304
- },
305
- },
306
- },
307
- {
308
- key: "website/matchers/date.ts",
309
- title: "Date and Time",
310
- description: "Target users based on specific dates or date ranges, including specific times",
311
- icon: "calendar-event",
312
- namespace: "website",
313
- propsSchema: {
314
- type: "object",
315
- properties: {
316
- start: { type: "string", title: "Start Date", format: "date-time" },
317
- end: { type: "string", title: "End Date", format: "date-time" },
318
- },
319
- },
320
- },
321
- {
322
- key: "website/matchers/cron.ts",
323
- title: "Cron",
324
- description: "Target users with precision using recurring schedules",
325
- icon: "refresh",
326
- namespace: "website",
327
- propsSchema: {
328
- type: "object",
329
- properties: {
330
- start: { type: "string", title: "Start", format: "date-time" },
331
- end: { type: "string", title: "End", format: "date-time" },
332
- },
333
- },
334
- },
335
- {
336
- key: "website/matchers/cookie.ts",
337
- title: "Cookie",
338
- description: "Target users that have a specific cookie",
339
- icon: "cookie",
340
- namespace: "website",
341
- propsSchema: {
342
- type: "object",
343
- properties: {
344
- name: { type: "string", title: "Cookie Name" },
345
- value: { type: "string", title: "Cookie Value" },
346
- },
347
- },
348
- },
349
- {
350
- key: "website/matchers/host.ts",
351
- title: "Host",
352
- description: "Target users based on the domain or subdomain they are accessing your site from",
353
- icon: "world-www",
354
- namespace: "website",
355
- propsSchema: {
356
- type: "object",
357
- properties: {
358
- host: { type: "string", title: "Hostname" },
359
- },
360
- },
361
- },
362
- {
363
- key: "website/matchers/pathname.ts",
364
- title: "Pathname",
365
- description: "Target users based on the pathname",
366
- icon: "world-www",
367
- namespace: "website",
368
- propsSchema: {
369
- type: "object",
370
- properties: {
371
- pattern: { type: "string", title: "Regex Pattern" },
372
- includes: {
373
- type: "array",
374
- title: "Includes",
375
- items: { type: "string" },
376
- },
377
- excludes: {
378
- type: "array",
379
- title: "Excludes",
380
- items: { type: "string" },
381
- },
382
- },
383
- },
384
- },
385
- {
386
- key: "website/matchers/queryString.ts",
387
- title: "Query String",
388
- description: "Match with a specific querystring",
389
- icon: "question-mark",
390
- namespace: "website",
391
- propsSchema: {
392
- type: "object",
393
- properties: {
394
- key: { type: "string", title: "Parameter Name" },
395
- value: { type: "string", title: "Parameter Value" },
396
- },
397
- },
398
- },
399
- {
400
- key: "website/matchers/random.ts",
401
- title: "Random",
402
- description: "Target a percentage of the total traffic to do an A/B test",
403
- icon: "arrow-split",
404
- namespace: "website",
405
- propsSchema: {
406
- type: "object",
407
- properties: {
408
- traffic: {
409
- type: "number",
410
- title: "Traffic Percentage (0\u20131)",
411
- minimum: 0,
412
- maximum: 1,
413
- },
414
- },
415
- },
416
- },
417
- {
418
- key: "website/matchers/location.ts",
419
- title: "Location",
420
- description:
421
- "Target users based on their geographical location, such as country, city, or region",
422
- icon: "map-2",
423
- namespace: "website",
424
- propsSchema: (() => {
425
- // `includeLocations`/`excludeLocations` are `(Location | Map)[]` in the
426
- // matcher source. Emit the union as an `anyOf` of two branches so the CMS
427
- // renders a Location/Map choice instead of merging every field into one
428
- // form. The Location branch is exactly {city, regionCode, country}; the
429
- // Map branch carries the `@format: map` coordinate picker.
430
- const locationBranch = {
431
- type: "object" as const,
432
- title: "Location",
433
- properties: {
434
- city: {
435
- type: "string",
436
- title: "City",
437
- examples: ["São Paulo"],
438
- description:
439
- "Exact city name (case-insensitive) as returned by Cloudflare's cf-ipcity header.",
440
- },
441
- regionCode: {
442
- type: "string",
443
- title: "Region Code",
444
- examples: ["SP", "RJ", "MG", "47"],
445
- description:
446
- 'Matches Cloudflare\'s cf-region-code header. Usually the ISO 3166-2 subdivision code (SP, RJ, MG, …); for some regions Cloudflare returns numeric codes (e.g. 47). Use the same value cf-region-code returns for your audience — full region names like "São Paulo" are NOT matched.',
447
- },
448
- country: {
449
- type: "string",
450
- title: "Country",
451
- examples: ["BR", "Brasil", "US"],
452
- description:
453
- "ISO 3166-1 alpha-2 code (BR, US, AR, …) or a full country name (Brasil, United States) — the matcher resolves common aliases.",
454
- },
455
- },
456
- };
457
- const mapBranch = {
458
- type: "object" as const,
459
- title: "Map",
460
- properties: {
461
- coordinates: {
462
- type: "string",
463
- title: "Area selection",
464
- format: "map",
465
- examples: ["-23.5505,-46.6333,5000"],
466
- description:
467
- '"latitude,longitude,radius_in_meters" for haversine-radius matching. Set this for the Map mode.',
468
- },
469
- },
470
- };
471
- // Mustache title so array items summarise their content instead of
472
- // "Item 1". Absent fields render empty; the label is trimmed. Covers both
473
- // branches — Location fields and the Map coordinates.
474
- const locationOrMapItem = {
475
- title: "{{{city}}} {{{regionCode}}} {{{country}}} {{{coordinates}}}",
476
- anyOf: [locationBranch, mapBranch],
477
- };
478
- return {
479
- type: "object" as const,
480
- properties: {
481
- includeLocations: {
482
- type: "array",
483
- title: "Include Locations",
484
- items: locationOrMapItem,
485
- },
486
- excludeLocations: {
487
- type: "array",
488
- title: "Exclude Locations",
489
- items: locationOrMapItem,
490
- },
491
- },
492
- };
493
- })(),
494
- },
495
- {
496
- key: "website/matchers/userAgent.ts",
497
- title: "User Agent",
498
- description: "Target users based on their web browser or operational system",
499
- icon: "world",
500
- namespace: "website",
501
- propsSchema: {
502
- type: "object",
503
- properties: {
504
- includes: { type: "string", title: "Includes (substring)" },
505
- match: { type: "string", title: "Match (regex)" },
506
- },
507
- },
508
- },
509
- {
510
- key: "website/matchers/environment.ts",
511
- title: "Environment",
512
- description:
513
- "Target users based from where they are accessing your site (development, testing, or production)",
514
- icon: "code",
515
- namespace: "website",
516
- propsSchema: {
517
- type: "object",
518
- properties: {
519
- environment: {
520
- type: "string",
521
- title: "Environment",
522
- enum: ["production", "development"],
523
- },
524
- },
525
- },
526
- },
527
- {
528
- key: "website/matchers/multi.ts",
529
- title: "Multi",
530
- description: "Create more complex conditions by combining multiple matchers",
531
- icon: "plus",
532
- namespace: "website",
533
- propsSchema: {
534
- type: "object",
535
- properties: {
536
- op: {
537
- type: "string",
538
- title: "Operator",
539
- enum: ["and", "or"],
540
- default: "and",
541
- },
542
- matchers: {
543
- type: "array",
544
- title: "Matchers",
545
- items: { $ref: "#/root/matchers" },
546
- },
547
- },
548
- },
549
- },
550
- {
551
- key: "website/matchers/negate.ts",
552
- title: "Negates",
553
- description: "Create conditions that target users who do not meet certain criteria",
554
- icon: "minus",
555
- namespace: "website",
556
- propsSchema: {
557
- type: "object",
558
- properties: {
559
- matcher: {
560
- $ref: "#/root/matchers",
561
- title: "Matcher",
562
- },
563
- },
564
- },
565
- },
566
- ]);
567
-
568
- function buildLoaderDefinitions() {
569
- const definitions: Record<string, any> = {};
570
- const manifestBlocks: Record<string, any> = {};
571
- const loaderAnyOf: any[] = [{ $ref: `#/definitions/${RESOLVABLE_LITERAL_KEY}` }];
572
-
573
- for (const loader of loaderRegistry) {
574
- const defKey = toBase64(loader.key);
575
-
576
- definitions[defKey] = {
577
- title: loader.title || loader.key,
578
- ...(loader.description ? { description: loader.description } : {}),
579
- ...(loader.icon ? { icon: loader.icon } : {}),
580
- type: "object",
581
- required: ["__resolveType", ...(loader.propsSchema?.required || [])],
582
- properties: {
583
- __resolveType: {
584
- type: "string",
585
- enum: [loader.key],
586
- default: loader.key,
587
- },
588
- ...(loader.propsSchema?.properties || {}),
589
- },
590
- // Preserved so the admin can tell "props unknown — edit as JSON" (stub)
591
- // apart from "takes no input" (real schema without the flag).
592
- ...(loader.propsSchema?.additionalProperties === true ? { additionalProperties: true } : {}),
593
- };
594
-
595
- manifestBlocks[loader.key] = {
596
- $ref: `#/definitions/${defKey}`,
597
- namespace: loader.namespace,
598
- };
599
-
600
- loaderAnyOf.push({ $ref: `#/definitions/${defKey}` });
601
- }
602
-
603
- return { definitions, manifestBlocks, loaderAnyOf };
604
- }
605
-
606
- // ---------------------------------------------------------------------------
607
- // Matcher definitions
608
- // ---------------------------------------------------------------------------
609
-
610
- function buildMatcherDefinitions() {
611
- const definitions: Record<string, any> = {};
612
- const manifestBlocks: Record<string, any> = {};
613
- const matcherAnyOf: any[] = [{ $ref: `#/definitions/${RESOLVABLE_LITERAL_KEY}` }];
614
-
615
- for (const matcher of matcherRegistry) {
616
- const defKey = toBase64(matcher.key);
617
- definitions[defKey] = {
618
- title: matcher.title,
619
- ...(matcher.description ? { description: matcher.description } : {}),
620
- ...(matcher.icon ? { icon: matcher.icon } : {}),
621
- type: "object",
622
- required: ["__resolveType"],
623
- properties: {
624
- __resolveType: {
625
- type: "string",
626
- enum: [matcher.key],
627
- default: matcher.key,
628
- },
629
- ...(matcher.propsSchema?.properties || {}),
630
- },
631
- ...(matcher.propsSchema?.additionalProperties === true ? { additionalProperties: true } : {}),
632
- };
633
- manifestBlocks[matcher.key] = {
634
- $ref: `#/definitions/${defKey}`,
635
- namespace: matcher.namespace,
636
- };
637
- matcherAnyOf.push({ $ref: `#/definitions/${defKey}` });
638
- }
639
-
640
- return { definitions, manifestBlocks, matcherAnyOf };
641
- }
642
-
643
- // ---------------------------------------------------------------------------
644
- // Multivariate flag schema
645
- // ---------------------------------------------------------------------------
646
-
647
- function buildMultivariateFlagSchema(innerSchema: any) {
648
- return {
649
- type: "object",
650
- required: ["__resolveType"],
651
- properties: {
652
- __resolveType: {
653
- type: "string",
654
- enum: ["website/flags/multivariate.ts", "website/flags/multivariate/section.ts"],
655
- },
656
- variants: {
657
- type: "array",
658
- title: "Variants",
659
- items: {
660
- type: "object",
661
- properties: {
662
- rule: {
663
- title: "Rule",
664
- type: "object",
665
- required: ["__resolveType"],
666
- properties: {
667
- __resolveType: { type: "string" },
668
- },
669
- additionalProperties: true,
670
- },
671
- value: innerSchema,
672
- },
673
- },
674
- },
675
- },
676
- };
677
- }
678
-
679
- // ---------------------------------------------------------------------------
680
- // Page schema
681
- // ---------------------------------------------------------------------------
682
-
683
- function buildPageSchema(sectionAnyOf: any[]) {
684
- const PAGE_TYPE = "website/pages/Page.tsx";
685
- const defKey = toBase64(PAGE_TYPE);
686
-
687
- const sectionsArraySchema = {
688
- type: "array",
689
- title: "Sections",
690
- items: { anyOf: sectionAnyOf },
691
- };
692
-
693
- const sectionsMultivariateSchema = buildMultivariateFlagSchema(sectionsArraySchema);
694
-
695
- const definition = {
696
- title: PAGE_TYPE,
697
- type: "object",
698
- required: ["__resolveType"],
699
- properties: {
700
- __resolveType: {
701
- type: "string",
702
- enum: [PAGE_TYPE],
703
- default: PAGE_TYPE,
704
- },
705
- name: { type: "string", title: "Name" },
706
- path: { type: "string", title: "Path" },
707
- seo: { title: "SEO", anyOf: sectionAnyOf },
708
- sections: {
709
- title: "Sections",
710
- anyOf: [sectionsArraySchema, sectionsMultivariateSchema],
711
- },
712
- },
713
- };
714
-
715
- return {
716
- definitions: { [defKey]: definition },
717
- manifestBlocks: {
718
- [PAGE_TYPE]: {
719
- $ref: `#/definitions/${defKey}`,
720
- namespace: "website",
721
- },
722
- },
723
- rootAnyOf: [
724
- { $ref: `#/definitions/${RESOLVABLE_LITERAL_KEY}` },
725
- { $ref: `#/definitions/${defKey}` },
726
- ],
727
- };
728
- }
729
-
730
- // ---------------------------------------------------------------------------
731
- // Framework sections
732
- // ---------------------------------------------------------------------------
733
-
734
- // Merchant-facing help for the per-section `ignoreStructuredData` toggle, shared
735
- // by the PLP (`configJsonLD`) and PDP (top-level) SEO sections. The fetch-skip is
736
- // deliberately scoped to "the page's SEO source" — it only fires when this block
737
- // is wired as the page's SEO (`page.seo`), not when the section is dropped inline
738
- // in the sections array (there the commerce loader still runs; only the JSON-LD
739
- // output is omitted for visitors).
740
- const IGNORE_STRUCTURED_DATA_DESCRIPTION =
741
- "By default, Structured Data (JSON-LD) is sent to everyone. Turn this on to omit it for regular visitors while crawlers and bots still receive the full Structured Data. When this block is the page's SEO source, the product fetch is also skipped for visitors, so the page loads faster. Some integrations may rely on Structured Data being present for all users.";
742
-
743
- function buildFrameworkSections(sectionAnyOf: any[], loaderUnion: any[]) {
744
- const definitions: Record<string, any> = {};
745
- const manifestBlocks: Record<string, any> = {};
746
- const extraAnyOf: any[] = [];
747
-
748
- // --- website/sections/Rendering/Lazy.tsx ---
749
- const LAZY_TYPE = "website/sections/Rendering/Lazy.tsx";
750
- const lazyKey = toBase64(LAZY_TYPE);
751
- definitions[lazyKey] = {
752
- title: LAZY_TYPE,
753
- type: "object",
754
- required: ["__resolveType"],
755
- properties: {
756
- __resolveType: {
757
- type: "string",
758
- enum: [LAZY_TYPE],
759
- default: LAZY_TYPE,
760
- },
761
- section: {
762
- title: "Section",
763
- anyOf: sectionAnyOf,
764
- },
765
- },
766
- };
767
- manifestBlocks[LAZY_TYPE] = {
768
- $ref: `#/definitions/${lazyKey}`,
769
- namespace: "website",
770
- };
771
- extraAnyOf.push({ $ref: `#/definitions/${lazyKey}` });
772
-
773
- // --- website/sections/Seo/Seo.tsx ---
774
- const SEO_TYPE = "website/sections/Seo/Seo.tsx";
775
- const seoKey = toBase64(SEO_TYPE);
776
- definitions[seoKey] = {
777
- title: SEO_TYPE,
778
- type: "object",
779
- required: ["__resolveType"],
780
- properties: {
781
- __resolveType: {
782
- type: "string",
783
- enum: [SEO_TYPE],
784
- default: SEO_TYPE,
785
- },
786
- title: { type: "string", title: "Title" },
787
- description: { type: "string", title: "Description" },
788
- canonical: { type: "string", title: "Canonical URL" },
789
- favicon: { type: "string", title: "Favicon", format: "image-uri" },
790
- noIndexing: { type: "boolean", title: "No Indexing" },
791
- titleTemplate: { type: "string", title: "Title Template" },
792
- descriptionTemplate: { type: "string", title: "Description Template" },
793
- type: { type: "string", title: "Page Type" },
794
- image: { type: "string", title: "OG Image", format: "image-uri" },
795
- themeColor: { type: "string", title: "Theme Color", format: "color" },
796
- jsonLDs: {
797
- type: "array",
798
- title: "JSON-LD Structured Data",
799
- items: { type: "object", additionalProperties: true },
800
- },
801
- },
802
- };
803
- manifestBlocks[SEO_TYPE] = {
804
- $ref: `#/definitions/${seoKey}`,
805
- namespace: "website",
806
- };
807
- extraAnyOf.push({ $ref: `#/definitions/${seoKey}` });
808
-
809
- // --- website/sections/Seo/SeoV2.tsx ---
810
- const SEOV2_TYPE = "website/sections/Seo/SeoV2.tsx";
811
- const seoV2Key = toBase64(SEOV2_TYPE);
812
- definitions[seoV2Key] = {
813
- title: SEOV2_TYPE,
814
- type: "object",
815
- required: ["__resolveType"],
816
- properties: {
817
- __resolveType: {
818
- type: "string",
819
- enum: [SEOV2_TYPE],
820
- default: SEOV2_TYPE,
821
- },
822
- title: { type: "string", title: "Title" },
823
- description: { type: "string", title: "Description" },
824
- canonical: { type: "string", title: "Canonical URL" },
825
- favicon: { type: "string", title: "Favicon", format: "image-uri" },
826
- noIndexing: { type: "boolean", title: "No Indexing" },
827
- titleTemplate: { type: "string", title: "Title Template" },
828
- descriptionTemplate: { type: "string", title: "Description Template" },
829
- type: { type: "string", title: "Page Type" },
830
- image: { type: "string", title: "OG Image", format: "image-uri" },
831
- themeColor: { type: "string", title: "Theme Color", format: "color" },
832
- jsonLDs: {
833
- type: "array",
834
- title: "JSON-LD Structured Data",
835
- items: { type: "object", additionalProperties: true },
836
- },
837
- },
838
- };
839
- manifestBlocks[SEOV2_TYPE] = {
840
- $ref: `#/definitions/${seoV2Key}`,
841
- namespace: "website",
842
- };
843
- extraAnyOf.push({ $ref: `#/definitions/${seoV2Key}` });
844
-
845
- // --- commerce/sections/Seo/SeoPLPV2.tsx ---
846
- // Product-listing SEO. Its schema is synthesized here (like the website Seo
847
- // sections) because the commerce apps ship loaders/types, not sections — so
848
- // there is no manifest to emit these props from. The Studio's SEO editor
849
- // already knows this type as its "plp" mode (see seo-form-mode.ts); it just
850
- // needs the props schema to render the override fields. `jsonLD` is the
851
- // data-source loader picker (mirrors deco-cx's `@title Data Source`) — an
852
- // inline anyOf over the loader union so the editor lets you pick the PLP/PDP
853
- // loader that feeds the structured data. Inlined (a fresh copy) rather than a
854
- // `$ref: "#/root/loaders"` because the Studio drops the prop-level title when
855
- // resolving a `$ref` union, which would lose the "Data Source" label; the
856
- // copy also avoids sharing one array instance across the two defs + root.
857
- //
858
- // Added to `extraAnyOf` (offered as a selectable page.seo type) unconditionally,
859
- // like the website Seo sections above. Gating this on "is a commerce site" via
860
- // the loader registry does NOT work: meta.gen.json is baked at generation time
861
- // (blocks-cli), when the registry is empty, and the runtime serves that baked,
862
- // already-composed meta as-is (composeMeta is idempotent on it) — so a gate
863
- // would drop the options at bake and never re-add them. Non-commerce sites
864
- // seeing these two extra options is a minor, acceptable cost.
865
- const SEO_PLP_V2_TYPE = "commerce/sections/Seo/SeoPLPV2.tsx";
866
- const seoPlpV2Key = toBase64(SEO_PLP_V2_TYPE);
867
- definitions[seoPlpV2Key] = {
868
- title: SEO_PLP_V2_TYPE,
869
- type: "object",
870
- required: ["__resolveType"],
871
- properties: {
872
- __resolveType: {
873
- type: "string",
874
- enum: [SEO_PLP_V2_TYPE],
875
- default: SEO_PLP_V2_TYPE,
876
- },
877
- jsonLD: { title: "Data Source", anyOf: [...loaderUnion] },
878
- title: { type: "string", title: "Title Override" },
879
- description: { type: "string", title: "Description Override" },
880
- noIndexing: { type: "boolean", title: "Disable indexing" },
881
- configJsonLD: {
882
- type: "object",
883
- title: "Structured Data",
884
- properties: {
885
- removeVideos: { type: "boolean", title: "Remove videos" },
886
- ignoreStructuredData: {
887
- type: "boolean",
888
- title: "Ignore Structured Data",
889
- description: IGNORE_STRUCTURED_DATA_DESCRIPTION,
890
- },
891
- },
892
- },
893
- },
894
- };
895
- manifestBlocks[SEO_PLP_V2_TYPE] = {
896
- $ref: `#/definitions/${seoPlpV2Key}`,
897
- namespace: "commerce",
898
- };
899
- extraAnyOf.push({ $ref: `#/definitions/${seoPlpV2Key}` });
900
-
901
- // --- commerce/sections/Seo/SeoPDPV2.tsx ---
902
- // Product-details SEO. Studio "pdp" mode counterpart of the PLP section above.
903
- const SEO_PDP_V2_TYPE = "commerce/sections/Seo/SeoPDPV2.tsx";
904
- const seoPdpV2Key = toBase64(SEO_PDP_V2_TYPE);
905
- definitions[seoPdpV2Key] = {
906
- title: SEO_PDP_V2_TYPE,
907
- type: "object",
908
- required: ["__resolveType"],
909
- properties: {
910
- __resolveType: {
911
- type: "string",
912
- enum: [SEO_PDP_V2_TYPE],
913
- default: SEO_PDP_V2_TYPE,
914
- },
915
- jsonLD: { title: "Data Source", anyOf: [...loaderUnion] },
916
- omitVariants: { type: "boolean", title: "Omit variants" },
917
- title: { type: "string", title: "Title Override" },
918
- description: { type: "string", title: "Description Override" },
919
- noIndexing: { type: "boolean", title: "Disable indexing" },
920
- ignoreStructuredData: {
921
- type: "boolean",
922
- title: "Ignore Structured Data",
923
- description: IGNORE_STRUCTURED_DATA_DESCRIPTION,
924
- },
925
- },
926
- };
927
- manifestBlocks[SEO_PDP_V2_TYPE] = {
928
- $ref: `#/definitions/${seoPdpV2Key}`,
929
- namespace: "commerce",
930
- };
931
- extraAnyOf.push({ $ref: `#/definitions/${seoPdpV2Key}` });
932
-
933
- // --- website/flags/multivariate/section.ts ---
934
- const MV_SECTION_TYPE = "website/flags/multivariate/section.ts";
935
- const mvSectionKey = toBase64(MV_SECTION_TYPE);
936
- definitions[mvSectionKey] = {
937
- title: MV_SECTION_TYPE,
938
- type: "object",
939
- required: ["__resolveType"],
940
- properties: {
941
- __resolveType: {
942
- type: "string",
943
- enum: [MV_SECTION_TYPE],
944
- default: MV_SECTION_TYPE,
945
- },
946
- variants: {
947
- type: "array",
948
- title: "Variants",
949
- items: {
950
- type: "object",
951
- properties: {
952
- rule: {
953
- title: "Rule",
954
- type: "object",
955
- required: ["__resolveType"],
956
- properties: { __resolveType: { type: "string" } },
957
- additionalProperties: true,
958
- },
959
- value: {
960
- title: "Section",
961
- anyOf: sectionAnyOf,
962
- },
963
- },
964
- },
965
- },
966
- },
967
- };
968
- manifestBlocks[MV_SECTION_TYPE] = {
969
- $ref: `#/definitions/${mvSectionKey}`,
970
- namespace: "website",
971
- };
972
- extraAnyOf.push({ $ref: `#/definitions/${mvSectionKey}` });
973
-
974
- return { definitions, manifestBlocks, extraAnyOf };
975
- }
976
-
977
- // ---------------------------------------------------------------------------
978
- // Post-processing: wrap complex properties with Resolvable anyOf
979
- // ---------------------------------------------------------------------------
980
-
981
- /**
982
- * Walk all @Props definitions and wrap complex array/object properties
983
- * with anyOf [Resolvable, original, ...matchingLoaders].
984
- *
985
- * In the deco CMS, ANY complex property can be replaced by a loader
986
- * reference ({ __resolveType: "some/loader.ts", props: {...} }).
987
- * This function ensures the schema accepts both inline data and
988
- * loader references for all such properties.
989
- */
990
- function wrapResolvableProperties(
991
- definitions: Record<string, any>,
992
- _loaderDefinitions: Record<string, any>,
993
- ) {
994
- const resolvableRef = { $ref: `#/definitions/${RESOLVABLE_LITERAL_KEY}` };
995
-
996
- const productLoaderRefs = getProductListLoaderKeys().map((key) => ({
997
- $ref: `#/definitions/${toBase64(key)}`,
998
- }));
999
-
1000
- for (const [defKey, def] of Object.entries(definitions)) {
1001
- if (!defKey.endsWith("@Props")) continue;
1002
- if (!def || !def.properties) continue;
1003
-
1004
- for (const [propName, propSchema] of Object.entries(def.properties as Record<string, any>)) {
1005
- if (!propSchema || typeof propSchema !== "object") continue;
1006
- if (propSchema.anyOf || propSchema.$ref) continue;
1007
-
1008
- const shouldWrap = isLoaderCompatibleProperty(propSchema);
1009
- if (!shouldWrap) continue;
1010
-
1011
- const { nullable, title, hide, ...rest } = propSchema;
1012
-
1013
- // Determine which loader refs to include based on property type
1014
- const loaderRefs = isProductArrayProperty(propSchema) ? productLoaderRefs : [];
1015
-
1016
- const wrapped: any = {
1017
- anyOf: [resolvableRef, { ...rest, title: title || "Inline data" }, ...loaderRefs],
1018
- };
1019
- if (nullable) wrapped.nullable = true;
1020
- if (title) wrapped.title = title;
1021
- if (hide) wrapped.hide = hide;
1022
-
1023
- def.properties[propName] = wrapped;
1024
- }
1025
-
1026
- // Also walk nested object properties (e.g., Tab.products inside tabs array items)
1027
- wrapNestedProperties(def, resolvableRef, productLoaderRefs);
1028
- }
1029
- }
1030
-
1031
- function isLoaderCompatibleProperty(schema: any): boolean {
1032
- if (schema.type === "array" && schema.items?.type === "object") {
1033
- const propCount = Object.keys(schema.items.properties || {}).length;
1034
- return propCount > 3;
1035
- }
1036
- return false;
1037
- }
1038
-
1039
- function isProductArrayProperty(schema: any): boolean {
1040
- if (schema.type !== "array" || !schema.items?.properties) return false;
1041
- const itemProps = schema.items.properties;
1042
- return !!(itemProps.productID || itemProps.name || itemProps.offers || itemProps.brand);
1043
- }
1044
-
1045
- /**
1046
- * Recursively walk nested object/array schemas to wrap deeply nested
1047
- * loader-compatible properties. Handles cases like Tab.products where
1048
- * the products field is inside an array item's object schema.
1049
- */
1050
- function wrapNestedProperties(
1051
- schema: any,
1052
- resolvableRef: any,
1053
- productLoaderRefs: any[],
1054
- depth = 0,
1055
- ) {
1056
- if (depth > 5 || !schema || typeof schema !== "object") return;
1057
-
1058
- if (schema.type === "array" && schema.items?.type === "object" && schema.items.properties) {
1059
- for (const [propName, propSchema] of Object.entries(
1060
- schema.items.properties as Record<string, any>,
1061
- )) {
1062
- if (!propSchema || typeof propSchema !== "object") continue;
1063
- if (propSchema.anyOf || propSchema.$ref) continue;
1064
-
1065
- if (isLoaderCompatibleProperty(propSchema)) {
1066
- const { nullable, title, hide, ...rest } = propSchema;
1067
- const loaderRefs = isProductArrayProperty(propSchema) ? productLoaderRefs : [];
1068
- const wrapped: any = {
1069
- anyOf: [resolvableRef, { ...rest, title: title || "Inline data" }, ...loaderRefs],
1070
- };
1071
- if (nullable) wrapped.nullable = true;
1072
- if (title) wrapped.title = title;
1073
- if (hide) wrapped.hide = hide;
1074
- schema.items.properties[propName] = wrapped;
1075
- }
1076
-
1077
- wrapNestedProperties(propSchema, resolvableRef, productLoaderRefs, depth + 1);
1078
- }
1079
- }
1080
-
1081
- if (schema.properties) {
1082
- for (const propSchema of Object.values(schema.properties)) {
1083
- wrapNestedProperties(propSchema as any, resolvableRef, productLoaderRefs, depth + 1);
1084
- }
1085
- }
1086
- }
1087
-
1088
- // ---------------------------------------------------------------------------
1089
- // composeMeta
1090
- // ---------------------------------------------------------------------------
1091
-
1092
- const SECTION_REF_DEF_KEY = "__SECTION_REF__";
1093
-
1094
- export interface ComposeMetaOptions {
1095
- /**
1096
- * Value written to the returned `framework` field. Defaults to
1097
- * "tanstack-start" for backward compatibility. Non-React stacks that compose
1098
- * a self-contained meta at generation time (e.g. Eitri) pass their own name.
1099
- */
1100
- framework?: string;
1101
- }
1102
-
1103
- export function composeMeta(siteMeta: MetaResponse, options?: ComposeMetaOptions): MetaResponse {
1104
- // Idempotency guard. composeMeta is NOT structurally idempotent — it appends
1105
- // the framework section refs to `root.sections.anyOf` (and `__SECTION_REF__`),
1106
- // so composing an already-composed meta a second time duplicates those refs.
1107
- // Since self-contained meta.gen.json is now baked at generation time (via the
1108
- // CLI's --compose), the tanstack runtime re-runs composeMeta on the file it
1109
- // loads from disk. A composed meta always carries a top-level `framework`
1110
- // field, which raw generateMeta() output never sets — use it as the sentinel
1111
- // and return the already-composed meta unchanged. Raw metas (framework unset,
1112
- // e.g. sites generated by an older CLI) still compose normally, so this stays
1113
- // backward compatible.
1114
- if (siteMeta.framework) {
1115
- return siteMeta;
1116
- }
1117
-
1118
- const siteAnyOf = siteMeta.schema?.root?.sections?.anyOf || [];
1119
-
1120
- // Build all framework components. Loaders first: the commerce SEO sections'
1121
- // `jsonLD` data-source picker references the loader union, and that union must
1122
- // include the site's OWN loaders. The runtime registry (loaderRegistry) is
1123
- // empty at generation time, so `buildLoaderDefinitions` alone yields just
1124
- // `Resolvable` — merge in the site's own loaders so loader-backed pickers have
1125
- // real options in the baked meta, not only at runtime.
1126
- //
1127
- // Seed from the site's loader UNION (`schema.root.loaders.anyOf`), NOT
1128
- // `manifest.blocks.loaders`: the generator keeps `@ignore`d loaders in the
1129
- // manifest (they still need a def) while withholding them from the union so
1130
- // they can't be picked — reading the manifest would resurrect them. This
1131
- // source is also already `{ $ref }`-shaped and only points at defs that exist
1132
- // (no dangling refs).
1133
- //
1134
- // TODO: `root.matchers`/`root.actions` have the same empty-union-at-gen-time
1135
- // gap; only loaders are merged here (commerce SEO scope). Generalize if a
1136
- // matcher/action picker ever needs baked options.
1137
- const loaders = buildLoaderDefinitions();
1138
- const siteLoaderRefs = (siteMeta.schema?.root?.loaders?.anyOf ?? []).filter(
1139
- (ref: any): ref is { $ref: string } => Boolean(ref) && typeof ref.$ref === "string",
1140
- );
1141
- const seenLoaderRefs = new Set<string>(loaders.loaderAnyOf.map((r: any) => r.$ref));
1142
- const loaderUnion = [
1143
- ...loaders.loaderAnyOf,
1144
- ...siteLoaderRefs.filter((r) => !seenLoaderRefs.has(r.$ref)),
1145
- ];
1146
-
1147
- const fwSections = buildFrameworkSections(siteAnyOf, loaderUnion);
1148
- const fullSectionAnyOf = [...siteAnyOf, ...fwSections.extraAnyOf];
1149
- const page = buildPageSchema(fullSectionAnyOf);
1150
- const actions = buildActionDefinitions();
1151
- const matchers = buildMatcherDefinitions();
1152
-
1153
- const sectionRefDef = { title: "Section", anyOf: fullSectionAnyOf };
1154
-
1155
- const resolvableDef = buildResolvableDefinition();
1156
-
1157
- // Merge all definitions.
1158
- // Priority (last wins): auto-registered empty schemas → framework sections/pages →
1159
- // site-generated schemas (meta.gen.json, with full loader props) → framework-critical keys.
1160
- // This ensures detailed site-generated schemas always win over auto-registered stubs.
1161
- const allDefinitions: Record<string, any> = {
1162
- ...loaders.definitions,
1163
- ...actions.definitions,
1164
- ...matchers.definitions,
1165
- ...fwSections.definitions,
1166
- ...page.definitions,
1167
- ...(siteMeta.schema?.definitions || {}),
1168
- [SECTION_REF_DEF_KEY]: sectionRefDef,
1169
- [RESOLVABLE_LITERAL_KEY]: resolvableDef,
1170
- [RESOLVABLE_B64_KEY]: resolvableDef,
1171
- };
1172
-
1173
- // Post-process: wrap complex section properties with Resolvable anyOf
1174
- wrapResolvableProperties(allDefinitions, loaders.definitions);
1175
-
1176
- return {
1177
- ...siteMeta,
1178
- framework: options?.framework ?? "tanstack-start",
1179
- manifest: {
1180
- blocks: {
1181
- ...(siteMeta.manifest?.blocks || {}),
1182
- sections: {
1183
- ...(siteMeta.manifest?.blocks?.sections || {}),
1184
- ...fwSections.manifestBlocks,
1185
- },
1186
- pages: {
1187
- ...(siteMeta.manifest?.blocks?.pages || {}),
1188
- ...page.manifestBlocks,
1189
- },
1190
- loaders: {
1191
- ...(siteMeta.manifest?.blocks?.loaders || {}),
1192
- ...loaders.manifestBlocks,
1193
- },
1194
- actions: {
1195
- ...(siteMeta.manifest?.blocks?.actions || {}),
1196
- ...actions.manifestBlocks,
1197
- },
1198
- matchers: {
1199
- ...(siteMeta.manifest?.blocks?.matchers || {}),
1200
- ...matchers.manifestBlocks,
1201
- },
1202
- },
1203
- },
1204
- schema: {
1205
- definitions: allDefinitions,
1206
- root: {
1207
- ...(siteMeta.schema?.root || {}),
1208
- sections: { anyOf: fullSectionAnyOf },
1209
- pages: { anyOf: page.rootAnyOf },
1210
- loaders: { anyOf: loaderUnion },
1211
- matchers: { anyOf: matchers.matcherAnyOf },
1212
- },
1213
- },
1214
- };
1215
- }