@decocms/blocks-cli 7.79.1 → 7.79.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks-cli",
3
- "version": "7.79.1",
3
+ "version": "7.79.3",
4
4
  "type": "module",
5
5
  "description": "Deco codegen (generate-blocks, generate-schema, generate-invoke) and Fresh-to-TanStack migration tooling",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "lint:unused": "knip"
34
34
  },
35
35
  "dependencies": {
36
- "@decocms/blocks": "7.79.1",
36
+ "@decocms/blocks": "7.79.3",
37
37
  "ts-morph": "^27.0.0",
38
38
  "tsx": "^4.22.5"
39
39
  },
@@ -0,0 +1,216 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
6
+
7
+ interface Schema {
8
+ type?: string;
9
+ title?: string;
10
+ description?: string;
11
+ nullable?: boolean;
12
+ $ref?: string;
13
+ allOf?: Schema[];
14
+ anyOf?: Schema[];
15
+ enum?: string[];
16
+ properties?: Record<string, Schema>;
17
+ items?: Schema;
18
+ required?: string[];
19
+ }
20
+
21
+ // Regression: site multivariate flags (`src/flags/**`, e.g. a
22
+ // `MultivariateFlag<BannerContent>`) were never scanned, so `root.flags`
23
+ // was empty and a prop holding `{ __resolveType: "site/flags/…", variants }`
24
+ // had no schema branch for it. The admin then drew the bare object form over
25
+ // the flag: no variants, every field empty. Driven through the real CLI so the
26
+ // flag pass runs before the loader/section passes that consume it.
27
+ describe("generate-schema site multivariate flags", () => {
28
+ let fixture: string;
29
+ let meta: any;
30
+
31
+ const FLAG = "site/flags/multivariate/content.ts";
32
+ const LIST_FLAG = "site/flags/multivariate/products.ts";
33
+
34
+ beforeAll(() => {
35
+ fixture = mkdtempSync(path.join(tmpdir(), "schema-flags-"));
36
+ const write = (relative: string, contents: string) => {
37
+ const file = path.join(fixture, relative);
38
+ mkdirSync(path.dirname(file), { recursive: true });
39
+ writeFileSync(file, contents);
40
+ };
41
+ write(
42
+ "tsconfig.json",
43
+ JSON.stringify({
44
+ compilerOptions: {
45
+ target: "ES2022",
46
+ module: "ESNext",
47
+ moduleResolution: "Bundler",
48
+ strict: true,
49
+ },
50
+ }),
51
+ );
52
+ // Same shape as @decocms/apps-website's types, declared locally so the
53
+ // fixture has no package to resolve.
54
+ write(
55
+ "src/flags/types.ts",
56
+ `export interface Variant<T> { rule: unknown; value: T; }
57
+ export interface MultivariateProps<T> { variants: Variant<T>[]; }
58
+ export interface MultivariateFlag<T> { variants: Variant<T>[]; }`,
59
+ );
60
+ write(
61
+ "src/types.ts",
62
+ `export interface Content { matcher?: string[]; label: string; }
63
+ export interface Kit { name: string; content: Content; }
64
+ export interface Product { productID: string; }`,
65
+ );
66
+ write(
67
+ "src/flags/multivariate/content.ts",
68
+ `import type { MultivariateFlag, MultivariateProps } from "../types";
69
+ import type { Content } from "../../types";
70
+ /** @title Content Variants */
71
+ export default function content(p: MultivariateProps<Content>): MultivariateFlag<Content> { return p; }`,
72
+ );
73
+ write(
74
+ "src/flags/multivariate/products.ts",
75
+ `import type { MultivariateFlag, MultivariateProps } from "../types";
76
+ import type { Product } from "../../types";
77
+ export default function products(
78
+ p: MultivariateProps<Product[] | null>,
79
+ ): MultivariateFlag<Product[] | null> { return p; }`,
80
+ );
81
+ write("src/flags/helpers.ts", "export const notAFlag = 1;");
82
+ write(
83
+ "src/loaders/kits.ts",
84
+ `import type { Kit } from "../types";
85
+ interface Props { kits: Kit[]; }
86
+ export default function kits({ kits }: Props): Kit[] { return kits; }`,
87
+ );
88
+ write(
89
+ "src/loaders/products.ts",
90
+ `import type { Product } from "../types";
91
+ export default function load(): Product[] { throw new Error("fixture only"); }`,
92
+ );
93
+ write(
94
+ "src/sections/Example.tsx",
95
+ `import type { Content, Product } from "../types";
96
+ export interface Props {
97
+ /**
98
+ * @title Main content
99
+ * @description Shown on top
100
+ */
101
+ content: Content;
102
+ optional?: Content | null;
103
+ products: Product[] | null;
104
+ /** @hide */
105
+ hidden?: Content;
106
+ }
107
+ export default function Example(_props: Props) { return null; }`,
108
+ );
109
+
110
+ const run = spawnSync(
111
+ process.execPath,
112
+ [
113
+ "--import",
114
+ import.meta.resolve("tsx"),
115
+ path.resolve(__dirname, "generate-schema.ts"),
116
+ "--skip-apps",
117
+ ],
118
+ { cwd: fixture, encoding: "utf8", timeout: 30_000 },
119
+ );
120
+ expect(run.status, run.error?.message ?? run.stderr).toBe(0);
121
+ meta = JSON.parse(readFileSync(path.join(fixture, ".deco/meta.gen.json"), "utf8"));
122
+ }, 30_000);
123
+
124
+ afterAll(() => {
125
+ if (fixture) rmSync(fixture, { recursive: true, force: true });
126
+ });
127
+
128
+ const def = (key: string): Schema => meta.schema.definitions[key];
129
+
130
+ function sectionProps(): Record<string, Schema> {
131
+ const section = def(btoa("site/sections/Example.tsx"));
132
+ const ref = section.allOf!.find((part) => part.$ref)!.$ref!;
133
+ return def(ref.replace("#/definitions/", "")).properties!;
134
+ }
135
+
136
+ function expectFlagged(schema: Schema, flagKey: string, title: string) {
137
+ expect(schema.anyOf).toHaveLength(2);
138
+ const [inline, flag] = schema.anyOf!;
139
+ expect(inline.type).toBe("object");
140
+ expect(inline.properties?.label.type).toBe("string");
141
+ // Inline, with its own __resolveType: how the admin tells a block option
142
+ // from the plain branch and renders the field with variants.
143
+ expect(flag).toEqual({
144
+ title,
145
+ type: "object",
146
+ allOf: [{ $ref: `#/definitions/${btoa(flagKey)}@Props` }],
147
+ required: ["__resolveType"],
148
+ properties: { __resolveType: { type: "string", enum: [flagKey], default: flagKey } },
149
+ });
150
+ }
151
+
152
+ it("registers each flag in the manifest and in root.flags", () => {
153
+ expect(meta.manifest.blocks.flags).toEqual({
154
+ [FLAG]: { $ref: `#/definitions/${btoa(FLAG)}`, namespace: "site" },
155
+ [LIST_FLAG]: { $ref: `#/definitions/${btoa(LIST_FLAG)}`, namespace: "site" },
156
+ });
157
+ expect(meta.schema.root.flags.anyOf).toContainEqual({
158
+ $ref: `#/definitions/${btoa(FLAG)}`,
159
+ inputSchema: `#/definitions/${btoa(FLAG)}@Props`,
160
+ });
161
+ expect(def(btoa(FLAG)).title).toBe("Content Variants");
162
+ // No @title → the key, as for loaders.
163
+ expect(def(btoa(LIST_FLAG)).title).toBe(LIST_FLAG);
164
+ });
165
+
166
+ it("emits the variants schema over the flag's value type", () => {
167
+ const variant = def(`${btoa(FLAG)}@Props`).properties!.variants.items!;
168
+ expect(variant.required).toEqual(["rule", "value"]);
169
+ expect(variant.properties!.rule.required).toEqual(["__resolveType"]);
170
+ expect(variant.properties!.value.properties!.label.type).toBe("string");
171
+ });
172
+
173
+ it("skips files under src/flags that are not multivariate flags", () => {
174
+ expect(Object.keys(meta.manifest.blocks.flags)).not.toContain("site/flags/helpers.ts");
175
+ expect(Object.keys(meta.manifest.blocks.flags)).not.toContain("site/flags/types.ts");
176
+ });
177
+
178
+ it("offers the flag on a section prop of the flag's type, keeping its annotations", () => {
179
+ const content = sectionProps().content;
180
+ expectFlagged(content, FLAG, "Content Variants");
181
+ expect(content.title).toBe("Main content");
182
+ expect(content.description).toBe("Shown on top");
183
+ expect(sectionProps().optional.nullable).toBe(true);
184
+ expectFlagged(sectionProps().optional, FLAG, "Content Variants");
185
+ });
186
+
187
+ it("offers the flag on a nested prop of a loader's props (a list of items with flagged content)", () => {
188
+ const loader = def(btoa("site/loaders/kits.ts"));
189
+ // A list prop of a type a loader returns also offers that loader (here,
190
+ // the loader itself); its inline branch is the list.
191
+ const kits = loader.properties!.kits;
192
+ const kit = (kits.anyOf?.[0] ?? kits).items!;
193
+ expect(kit.properties!.name.type).toBe("string");
194
+ expectFlagged(kit.properties!.content, FLAG, "Content Variants");
195
+ });
196
+
197
+ it("adds the flag to a loader block-ref picker over the same type", () => {
198
+ const loaderPicker = [
199
+ { $ref: "#/definitions/Resolvable" },
200
+ { $ref: `#/definitions/${btoa("site/loaders/products.ts")}` },
201
+ ];
202
+ expect(sectionProps().products.anyOf).toEqual([
203
+ ...loaderPicker,
204
+ { $ref: `#/definitions/${btoa(LIST_FLAG)}` },
205
+ ]);
206
+ // Each variant is itself a loader pick, not the whole inlined Product type.
207
+ const variant = def(`${btoa(LIST_FLAG)}@Props`).properties!.variants.items!;
208
+ expect(variant.properties!.value.anyOf).toEqual(loaderPicker);
209
+ });
210
+
211
+ it("leaves a hidden prop alone", () => {
212
+ const hidden = sectionProps().hidden;
213
+ expect(hidden.anyOf).toBeUndefined();
214
+ expect(hidden.type).toBe("object");
215
+ });
216
+ });
@@ -0,0 +1,190 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
6
+
7
+ interface Schema {
8
+ type?: string;
9
+ title?: string;
10
+ $ref?: string;
11
+ allOf?: Schema[];
12
+ anyOf?: Schema[];
13
+ enum?: string[];
14
+ properties?: Record<string, Schema>;
15
+ items?: Schema;
16
+ }
17
+
18
+ // Regressions, compared with deco-cx/deco's admin:
19
+ // - A section's `page: ProductListingPage` never offered the commerce
20
+ // `listingPage.ts` extension wrapper (every PLP's stored value), because the
21
+ // wrapper was emitted but not registered as returning what it wraps.
22
+ // - The wrapper's `extensions` list offered nothing: the site's extension
23
+ // loaders (`ExtensionOf<ProductListingPage>`) were never collected.
24
+ // - A loader's own props never got loader pickers: loader input schemas were
25
+ // built before the loader output map existed, so an extension's
26
+ // `products: Product[]` was a bare array with no way to pick a product loader.
27
+ describe("generate-schema loader props and commerce extension wrappers", () => {
28
+ let fixture: string;
29
+ let meta: any;
30
+
31
+ const WRAPPER = "commerce/loaders/product/extensions/listingPage.ts";
32
+ const EXTENSION = "site/loaders/extensions/injectProducts.ts";
33
+
34
+ beforeAll(() => {
35
+ fixture = mkdtempSync(path.join(tmpdir(), "schema-loader-props-"));
36
+ const write = (relative: string, contents: string) => {
37
+ const file = path.join(fixture, relative);
38
+ mkdirSync(path.dirname(file), { recursive: true });
39
+ writeFileSync(file, contents);
40
+ };
41
+ write(
42
+ "tsconfig.json",
43
+ JSON.stringify({
44
+ compilerOptions: {
45
+ target: "ES2022",
46
+ module: "ESNext",
47
+ moduleResolution: "Bundler",
48
+ strict: true,
49
+ },
50
+ }),
51
+ );
52
+ write(
53
+ "src/types.ts",
54
+ `export interface Product { productID: string; name: string; }
55
+ export interface ProductListingPage { products: Product[]; }
56
+ export type ExtensionOf<T> = (data: T) => T | Promise<T>;
57
+ export interface Settings { ids: string[]; }`,
58
+ );
59
+ write(
60
+ "src/loaders/plp.ts",
61
+ `import type { ProductListingPage } from "../types";
62
+ export interface Props { query: string; }
63
+ export default async function plp(_p: Props): Promise<ProductListingPage | null> { return null; }`,
64
+ );
65
+ write(
66
+ "src/loaders/productList.ts",
67
+ `import type { Product } from "../types";
68
+ /** @title Product list */
69
+ export default function productList(): Product[] { return []; }`,
70
+ );
71
+ write(
72
+ "src/loaders/settings.ts",
73
+ `import type { Settings } from "../types";
74
+ export interface Props { fallback?: Settings; }
75
+ /** @title Global settings */
76
+ export default function settings(_p: Props): Settings { return { ids: [] }; }`,
77
+ );
78
+ write(
79
+ "src/loaders/kits.ts",
80
+ `import type { Product } from "../types";
81
+ export interface Props { kits: Product[]; }
82
+ /** @title Kits */
83
+ export default function kits({ kits }: Props): Product[] { return kits; }`,
84
+ );
85
+ write(
86
+ "src/loaders/extensions/injectProducts.ts",
87
+ `import type { ExtensionOf, Product, ProductListingPage, Settings } from "../../types";
88
+ export interface Props {
89
+ products: Product[] | null;
90
+ settings?: Settings | null;
91
+ /** @title Add to the end */
92
+ append?: boolean;
93
+ }
94
+ /** @title Inject products */
95
+ export default async function injectProducts(
96
+ _p: Props,
97
+ ): Promise<ExtensionOf<ProductListingPage | null>> { return (page) => page; }`,
98
+ );
99
+ write(
100
+ "src/sections/Search.tsx",
101
+ `import type { ProductListingPage } from "../types";
102
+ export interface Props { page: ProductListingPage | null; }
103
+ export default function Search(_props: Props) { return null; }`,
104
+ );
105
+
106
+ const run = spawnSync(
107
+ process.execPath,
108
+ [
109
+ "--import",
110
+ import.meta.resolve("tsx"),
111
+ path.resolve(__dirname, "generate-schema.ts"),
112
+ "--skip-apps",
113
+ ],
114
+ { cwd: fixture, encoding: "utf8", timeout: 30_000 },
115
+ );
116
+ expect(run.status, run.error?.message ?? run.stderr).toBe(0);
117
+ meta = JSON.parse(readFileSync(path.join(fixture, ".deco/meta.gen.json"), "utf8"));
118
+ }, 30_000);
119
+
120
+ afterAll(() => {
121
+ if (fixture) rmSync(fixture, { recursive: true, force: true });
122
+ });
123
+
124
+ const def = (key: string): Schema => meta.schema.definitions[key];
125
+ const ref = (key: string) => ({ $ref: `#/definitions/${btoa(key)}` });
126
+ const loaderBranch = (key: string, title: string) => ({
127
+ title,
128
+ type: "object",
129
+ allOf: [ref(key)],
130
+ required: ["__resolveType"],
131
+ properties: { __resolveType: { type: "string", enum: [key], default: key } },
132
+ });
133
+
134
+ it("offers the listingPage wrapper on a section's ProductListingPage prop", () => {
135
+ const section = def(btoa("site/sections/Search.tsx"));
136
+ const propsRef = section.allOf!.find((part) => part.$ref)!.$ref!;
137
+ const page = def(propsRef.replace("#/definitions/", "")).properties!.page;
138
+ expect(page.anyOf).toEqual([
139
+ { $ref: "#/definitions/Resolvable" },
140
+ ref("site/loaders/plp.ts"),
141
+ ref(WRAPPER),
142
+ ]);
143
+ });
144
+
145
+ it("lists the site's extension loaders in the wrapper's extensions", () => {
146
+ const wrapper = def(btoa(WRAPPER));
147
+ expect(wrapper.properties!.extensions.items!.anyOf).toEqual([
148
+ { $ref: "#/definitions/Resolvable" },
149
+ ref(EXTENSION),
150
+ ]);
151
+ // `data` still offers only the base loaders, never the wrapper itself.
152
+ expect(wrapper.properties!.data.anyOf).toEqual([
153
+ { $ref: "#/definitions/Resolvable" },
154
+ ref("site/loaders/plp.ts"),
155
+ ]);
156
+ });
157
+
158
+ it("titles a site loader by its @title", () => {
159
+ expect(def(btoa(EXTENSION)).title).toBe("Inject products");
160
+ expect(def(btoa("site/loaders/plp.ts")).title).toBe("site/loaders/plp.ts");
161
+ });
162
+
163
+ it("keeps a loader's list prop inline and offers the loaders of its type beside it", () => {
164
+ const props = def(btoa(EXTENSION)).properties!;
165
+ const [inline, ...loaders] = props.products.anyOf!;
166
+ expect(inline.type).toBe("array");
167
+ expect(inline.items?.properties?.productID.type).toBe("string");
168
+ expect(loaders).toEqual([
169
+ loaderBranch("site/loaders/kits.ts", "Kits"),
170
+ loaderBranch("site/loaders/productList.ts", "Product list"),
171
+ ]);
172
+ expect(props.append).toMatchObject({ type: "boolean", title: "Add to the end" });
173
+ });
174
+
175
+ it("offers a list loader in its own list prop (content nests it, as deco-cx/deco allowed)", () => {
176
+ const kits = def(btoa("site/loaders/kits.ts")).properties!.kits;
177
+ expect(kits.anyOf?.[0].type).toBe("array");
178
+ expect(kits.anyOf).toContainEqual(loaderBranch("site/loaders/kits.ts", "Kits"));
179
+ });
180
+
181
+ it("keeps a loader's object prop inline only", () => {
182
+ // The admin can't keep an object editable in place beside block options:
183
+ // it would edit a stored plain value through the picked loader's form.
184
+ const { settings } = def(btoa(EXTENSION)).properties!;
185
+ expect(settings.anyOf).toBeUndefined();
186
+ expect(settings.properties?.ids.type).toBe("array");
187
+ const { fallback } = def(btoa("site/loaders/settings.ts")).properties!;
188
+ expect(fallback.anyOf).toBeUndefined();
189
+ });
190
+ });
@@ -23,6 +23,7 @@ import { fileURLToPath } from "node:url";
23
23
  * --version Framework version (default: "1.0.0")
24
24
  * --sections Sections directory (default: "src/sections")
25
25
  * --loaders Loaders directory (default: "src/loaders")
26
+ * --flags Flags directory (default: "src/flags")
26
27
  * --apps Apps directory (default: "src/apps")
27
28
  * --skip-apps Skip app schema generation
28
29
  * --out Output file (default: ".deco/meta.gen.json")
@@ -71,6 +72,7 @@ let SITE_NAME = "storefront";
71
72
  let FRAMEWORK_VERSION = "1.0.0";
72
73
  let SECTIONS_REL = "src/sections";
73
74
  let LOADERS_REL = "src/loaders";
75
+ let FLAGS_REL = "src/flags";
74
76
  let APPS_REL = "src/apps";
75
77
  let SKIP_APPS = false;
76
78
  let OUT_REL = NEW_DEFAULT_OUT_REL;
@@ -89,6 +91,7 @@ if (isMainModule()) {
89
91
  FRAMEWORK_VERSION = arg("version", FRAMEWORK_VERSION);
90
92
  SECTIONS_REL = arg("sections", SECTIONS_REL);
91
93
  LOADERS_REL = arg("loaders", LOADERS_REL);
94
+ FLAGS_REL = arg("flags", FLAGS_REL);
92
95
  APPS_REL = arg("apps", APPS_REL);
93
96
  SKIP_APPS = argv.includes("--skip-apps");
94
97
  OUT_REL = arg("out", NEW_DEFAULT_OUT_REL);
@@ -373,6 +376,23 @@ const RUNTIME_INJECTED_TYPES = new Set([
373
376
  interface GenerationContext {
374
377
  /** Loader output type name → loader keys, for block-ref pickers. Sections only. */
375
378
  outputTypeToLoaderKeys?: Map<string, string[]>;
379
+ /**
380
+ * Flag value type name → the site's flag blocks over that type (see
381
+ * flagBranch). A prop of that type also accepts the flag, which is what
382
+ * makes the admin offer — and recognize — variants on that field.
383
+ */
384
+ outputTypeToFlags?: Map<string, FlagBlock[]>;
385
+ /**
386
+ * Loader input schemas: a list prop (`T[]`) of a type loaders return keeps its
387
+ * inline form and offers those loaders beside it — `anyOf [inline T[],
388
+ * ...loaders]`, deco-cx/deco's shape, which the admin renders as an editable
389
+ * list that can also hold a loader (`array` + `loaderRef`). Object props stay
390
+ * inline only: for an object the admin draws a block picker and edits a
391
+ * stored plain value through the picked loader's form, not in place.
392
+ */
393
+ loaderPicksInline?: boolean;
394
+ /** Loader key → picker label (its @title), for inline loader branches. */
395
+ loaderTitles?: Map<string, string>;
376
396
  /**
377
397
  * Shared definitions sink. When present, a recursive named type (e.g.
378
398
  * `interface Link { submenu?: Link[] }`) is emitted once as a definition and
@@ -477,6 +497,117 @@ function extractLoaderOutputTypeName(sourceFile: SourceFile): string | null {
477
497
  return loaderTypeName(ret);
478
498
  }
479
499
 
500
+ /**
501
+ * For an extension loader — default export returning `ExtensionOf<T>` (or a
502
+ * Promise of it), e.g. `ExtensionOf<ProductListingPage | null>` — the name of
503
+ * `T`, so the commerce extension wrapper over `T` can offer it in its
504
+ * `extensions` list. Null for any other loader.
505
+ */
506
+ export function extractExtensionTargetTypeName(sourceFile: SourceFile): string | null {
507
+ const sym = sourceFile.getDefaultExportSymbol();
508
+ if (!sym) return null;
509
+ const callSigs = sym.getTypeAtLocation(sourceFile).getCallSignatures();
510
+ if (!callSigs.length) return null;
511
+ let ret = callSigs[0].getReturnType();
512
+ if (ret.getSymbol()?.getName() === "Promise") {
513
+ const args = ret.getTypeArguments();
514
+ if (args.length) ret = args[0];
515
+ }
516
+ if (ret.getAliasSymbol()?.getName() !== "ExtensionOf") return null;
517
+ const [target] = ret.getAliasTypeArguments();
518
+ return target ? loaderTypeName(target) : null;
519
+ }
520
+
521
+ /** A site flag block (`src/flags/**`): its key, picker title and definition id. */
522
+ export interface FlagBlock {
523
+ key: string;
524
+ title: string;
525
+ defKey: string;
526
+ }
527
+
528
+ /**
529
+ * The value type a multivariate flag chooses between: `T` in
530
+ * `export default function (props: MultivariateProps<T>): MultivariateFlag<T>`,
531
+ * read from the props' `variants[].value` so it does not depend on what the
532
+ * helper types are called or where they are imported from.
533
+ */
534
+ export function extractFlagValueType(sourceFile: SourceFile): Type | null {
535
+ const propsType = extractDefaultExportPropsType(sourceFile);
536
+ const variants = propsType?.getProperty("variants");
537
+ if (!variants) return null;
538
+ let variantsType = variants.getTypeAtLocation(sourceFile);
539
+ if (variantsType.isUnion()) {
540
+ const nonNull = variantsType.getUnionTypes().filter((t) => !t.isNull() && !t.isUndefined());
541
+ if (nonNull.length !== 1) return null;
542
+ variantsType = nonNull[0];
543
+ }
544
+ const value = variantsType.getArrayElementType()?.getProperty("value");
545
+ return value ? value.getTypeAtLocation(sourceFile) : null;
546
+ }
547
+
548
+ /**
549
+ * A flag block as an `anyOf` branch of a prop it can fill, in deco-cx/deco's
550
+ * shape: inline, carrying its own `__resolveType`, with the variants schema
551
+ * behind the `allOf`. The admin recognizes a block option by the
552
+ * `__resolveType` on the branch itself, and treats a field whose only block
553
+ * option is a flag with `variants` as a field with variants — a `$ref` branch
554
+ * would make it a plain block picker instead.
555
+ */
556
+ export function flagBranch(flag: FlagBlock): any {
557
+ return blockBranch(flag.key, flag.title, `${flag.defKey}@Props`);
558
+ }
559
+
560
+ /** A loader as an inline `anyOf` branch (same shape as flagBranch). */
561
+ export function loaderBranch(key: string, title: string): any {
562
+ return blockBranch(key, title, toBase64(key));
563
+ }
564
+
565
+ function blockBranch(key: string, title: string, inputDefKey: string): any {
566
+ return {
567
+ title,
568
+ type: "object",
569
+ allOf: [{ $ref: `#/definitions/${inputDefKey}` }],
570
+ required: ["__resolveType"],
571
+ properties: {
572
+ __resolveType: { type: "string", enum: [key], default: key },
573
+ },
574
+ };
575
+ }
576
+
577
+ /**
578
+ * Input schema of a multivariate flag over a value schema. `rule` is any
579
+ * matcher; the admin edits it with its own matcher picker, so it only needs to
580
+ * be a block reference (same shape composeMeta gives the section flag).
581
+ */
582
+ export function multivariatePropsSchema(valueSchema: any): any {
583
+ return {
584
+ title: "Multivariate",
585
+ type: "object",
586
+ required: ["variants"],
587
+ properties: {
588
+ variants: {
589
+ type: "array",
590
+ title: "Variants",
591
+ minItems: 1,
592
+ items: {
593
+ type: "object",
594
+ required: ["rule", "value"],
595
+ properties: {
596
+ rule: {
597
+ title: "Rule",
598
+ type: "object",
599
+ required: ["__resolveType"],
600
+ properties: { __resolveType: { type: "string" } },
601
+ additionalProperties: true,
602
+ },
603
+ value: { ...valueSchema, title: "Content" },
604
+ },
605
+ },
606
+ },
607
+ },
608
+ };
609
+ }
610
+
480
611
  export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?: GenerationContext): any {
481
612
  const typeText = type.getText();
482
613
  if (visited.has(typeText)) return recursiveTypeRef(type, ctx) ?? { type: "object" };
@@ -713,18 +844,26 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
713
844
  continue;
714
845
  }
715
846
 
847
+ const outputTypeName = loaderTypeName(propType);
848
+ const matchingFlags =
849
+ (outputTypeName ? ctx?.outputTypeToFlags?.get(outputTypeName) : undefined) ?? [];
850
+
716
851
  // Loader output type → block-ref: emit anyOf [Resolvable, ...matchingLoaders]
717
852
  // baseHint strips "| null | undefined" so "ProductListingPage | null" → "ProductListingPage"
853
+ let inlineLoaders: string[] = [];
718
854
  if (ctx?.outputTypeToLoaderKeys) {
719
- const outputTypeName = loaderTypeName(propType);
720
855
  const matchingLoaders =
721
856
  (outputTypeName ? ctx.outputTypeToLoaderKeys.get(outputTypeName) : undefined) ??
722
- (outputTypeName !== baseHint ? ctx.outputTypeToLoaderKeys.get(baseHint) : undefined);
723
- if (matchingLoaders?.length) {
857
+ (outputTypeName !== baseHint ? ctx.outputTypeToLoaderKeys.get(baseHint) : undefined) ??
858
+ [];
859
+ if (ctx.loaderPicksInline) {
860
+ if (outputTypeName?.endsWith("[]")) inlineLoaders = matchingLoaders;
861
+ } else if (matchingLoaders.length) {
724
862
  const blockRefSchema: any = {
725
863
  anyOf: [
726
864
  { $ref: `#/definitions/${RESOLVABLE_KEY}` },
727
865
  ...matchingLoaders.map((k) => ({ $ref: `#/definitions/${toBase64(k)}` })),
866
+ ...matchingFlags.map((f) => ({ $ref: `#/definitions/${f.defKey}` })),
728
867
  ],
729
868
  title: name.charAt(0).toUpperCase() + name.slice(1),
730
869
  };
@@ -749,6 +888,27 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
749
888
 
750
889
  if (!schema.title) schema.title = name.charAt(0).toUpperCase() + name.slice(1);
751
890
 
891
+ // A site flag over this prop's type → the value may also be that flag
892
+ // (`{ __resolveType: "site/flags/…", variants }`). Without the branch the
893
+ // admin can't read a stored flag and shows the bare, empty object form.
894
+ // Same for loaders of this type in a loader's props (loaderPicksInline).
895
+ const blockBranches = [
896
+ ...inlineLoaders.map((k) => loaderBranch(k, ctx?.loaderTitles?.get(k) ?? k)),
897
+ ...matchingFlags.map(flagBranch),
898
+ ];
899
+ if (blockBranches.length > 0 && schema.hide !== "true") {
900
+ const { title, description, nullable, ...inline } = schema;
901
+ const flagged: any = {
902
+ anyOf: [{ ...inline, title }, ...blockBranches],
903
+ title,
904
+ };
905
+ if (description) flagged.description = description;
906
+ if (nullable) flagged.nullable = true;
907
+ properties[name] = flagged;
908
+ if (!prop.isOptional()) required.push(name);
909
+ continue;
910
+ }
911
+
752
912
  properties[name] = schema;
753
913
  // A hidden prop (runtime-injected type, ReactNode, @hide) can never be
754
914
  // filled in by the CMS user — requiring it would deadlock the form.
@@ -1053,6 +1213,7 @@ function generateMeta(): MetaResponse {
1053
1213
  const root = process.cwd();
1054
1214
  const sectionsDir = path.resolve(root, SECTIONS_REL);
1055
1215
  const loadersDir = path.resolve(root, LOADERS_REL);
1216
+ const flagsDir = path.resolve(root, FLAGS_REL);
1056
1217
  const srcDir = path.join(root, "src");
1057
1218
 
1058
1219
  const project = new Project({
@@ -1065,12 +1226,20 @@ function generateMeta(): MetaResponse {
1065
1226
  const loaderBlocks: Record<string, any> = {};
1066
1227
  const sectionRootAnyOf: any[] = [];
1067
1228
  const loaderRootAnyOf: any[] = [{ $ref: `#/definitions/${RESOLVABLE_KEY}` }];
1229
+ const flagBlocks: Record<string, any> = {};
1230
+ const flagRootAnyOf: any[] = [{ $ref: `#/definitions/${RESOLVABLE_KEY}` }];
1068
1231
  const outputTypeToLoaderKeys = new Map<string, string[]>();
1232
+ const outputTypeToFlags = new Map<string, FlagBlock[]>();
1069
1233
  const sourceFileCache: SourceFileCache = new Map();
1070
1234
  const moduleResolutionCache: ModuleResolutionCache = new Map();
1071
1235
  const propsSchemaCache: PropsSchemaCache = new Map();
1072
1236
  // Shared by every pass so each recursive type is emitted as one definition.
1073
- const schemaRefs: GenerationContext = { definitions, rootDir: root, recursiveRefs: new Set() };
1237
+ const schemaRefs: GenerationContext = {
1238
+ definitions,
1239
+ rootDir: root,
1240
+ recursiveRefs: new Set(),
1241
+ outputTypeToFlags,
1242
+ };
1074
1243
 
1075
1244
  // Resolvable: the admin's deRefUntil expects the LITERAL key "Resolvable",
1076
1245
  // not a base64-encoded version. We store both for compatibility.
@@ -1087,8 +1256,64 @@ function generateMeta(): MetaResponse {
1087
1256
  sectionRootAnyOf.push({ $ref: `#/definitions/${RESOLVABLE_KEY}` });
1088
1257
 
1089
1258
  // ---------------------------------------------------------------------------
1090
- // First pass: scan loaders — build input schemas + outputTypeToLoaderKeys map
1259
+ // Flags pass: the site's multivariate flags (src/flags/**, e.g.
1260
+ // `MultivariateFlag<BannerContent>`). Only registers each flag's value type
1261
+ // here, before every props pass: a prop of that type gets the flag as an
1262
+ // extra branch (see flagBranch), wherever the prop is — section, loader or
1263
+ // app. The flags' own schemas are built after the loader passes (below), so
1264
+ // a `Product[]` inside a flag's value is a loader picker, not the whole
1265
+ // inlined Product type.
1266
+ // ---------------------------------------------------------------------------
1267
+ const flagFiles = fs.existsSync(flagsDir) ? findTsxFiles(flagsDir) : [];
1268
+ const siteFlags: Array<{ flag: FlagBlock; valueType: Type; valueTypeName: string | null }> = [];
1269
+ for (const filePath of flagFiles) {
1270
+ const relativePath = path.relative(srcDir, filePath).replaceAll("\\", "/");
1271
+ const flagKey = `${SITE_NAMESPACE}/${relativePath}`;
1272
+ try {
1273
+ const sourceFile = getSourceFile(project, filePath, sourceFileCache);
1274
+ const defaultSym = sourceFile.getDefaultExportSymbol();
1275
+ const valueType = extractFlagValueType(sourceFile);
1276
+ if (!defaultSym || !valueType) {
1277
+ console.log(` · flag ${flagKey} (not a multivariate flag, skipped)`);
1278
+ continue;
1279
+ }
1280
+ const titleTag = getJsDocTags(defaultSym).title;
1281
+ const flag: FlagBlock = {
1282
+ key: flagKey,
1283
+ title: titleTag && !titleTag.includes("/") ? titleTag : flagKey,
1284
+ defKey: toBase64(flagKey),
1285
+ };
1286
+ const valueTypeName = loaderTypeName(valueType);
1287
+ siteFlags.push({ flag, valueType, valueTypeName });
1288
+ if (valueTypeName) {
1289
+ const existing = outputTypeToFlags.get(valueTypeName) ?? [];
1290
+ existing.push(flag);
1291
+ outputTypeToFlags.set(valueTypeName, existing);
1292
+ }
1293
+ } catch (e) {
1294
+ console.warn(` ✗ flag ${flagKey}: ${(e as Error).message}`);
1295
+ }
1296
+ }
1297
+
1091
1298
  // ---------------------------------------------------------------------------
1299
+ // First pass: scan loaders — register each loader and its output type. The
1300
+ // input schemas are built later (pendingLoaderDefs), once every loader's
1301
+ // output type is known (site, app and extension wrappers): a loader prop of a
1302
+ // type other loaders return gets the same block-ref picker a section prop
1303
+ // gets, e.g. an extension loader's `products: Product[]` → product loaders.
1304
+ // ---------------------------------------------------------------------------
1305
+ const pendingLoaderDefs: Array<() => void> = [];
1306
+ const loaderTitles = new Map<string, string>();
1307
+ const loaderCtx = (): GenerationContext => ({ ...ctx, loaderPicksInline: true, loaderTitles });
1308
+ /** Extended type name → extension loader keys (see extractExtensionTargetTypeName). */
1309
+ const extensionTargetToLoaderKeys = new Map<string, string[]>();
1310
+ const registerExtension = (sourceFile: SourceFile, loaderKey: string) => {
1311
+ const target = extractExtensionTargetTypeName(sourceFile);
1312
+ if (!target) return;
1313
+ const existing = extensionTargetToLoaderKeys.get(target) ?? [];
1314
+ existing.push(loaderKey);
1315
+ extensionTargetToLoaderKeys.set(target, existing);
1316
+ };
1092
1317
  const loaderFiles = fs.existsSync(loadersDir) ? findTsxFiles(loadersDir) : [];
1093
1318
  console.log(`Found ${loaderFiles.length} loader files`);
1094
1319
  for (const filePath of loaderFiles) {
@@ -1101,35 +1326,7 @@ function generateMeta(): MetaResponse {
1101
1326
 
1102
1327
  try {
1103
1328
  const sourceFile = getSourceFile(project, filePath, sourceFileCache);
1104
-
1105
- // Extract Props (input schema)
1106
- let propsSchema: any = null;
1107
- const propsInterface = sourceFile.getInterface("Props");
1108
- if (propsInterface)
1109
- propsSchema = typeToJsonSchema(propsInterface.getType(), undefined, schemaRefs);
1110
-
1111
- const propsTypeAlias = sourceFile.getTypeAlias("Props");
1112
- if (!propsSchema && propsTypeAlias)
1113
- propsSchema = typeToJsonSchema(propsTypeAlias.getType(), undefined, schemaRefs);
1114
-
1115
- if (!propsSchema) {
1116
- const localPropsType = extractDefaultExportPropsType(sourceFile);
1117
- if (localPropsType) propsSchema = typeToJsonSchema(localPropsType, undefined, schemaRefs);
1118
- }
1119
-
1120
- if (!propsSchema) propsSchema = { type: "object", properties: {} };
1121
-
1122
- // Register flat loader definition (Bug #2: spread props, not nested under "props:")
1123
1329
  const loaderDefKey = toBase64(loaderKey);
1124
- definitions[loaderDefKey] = {
1125
- title: loaderKey,
1126
- type: "object",
1127
- required: ["__resolveType", ...(propsSchema?.required || [])],
1128
- properties: {
1129
- __resolveType: { type: "string", enum: [loaderKey], default: loaderKey },
1130
- ...(propsSchema?.properties || {}),
1131
- },
1132
- };
1133
1330
 
1134
1331
  loaderBlocks[loaderKey] = {
1135
1332
  $ref: `#/definitions/${loaderDefKey}`,
@@ -1137,18 +1334,61 @@ function generateMeta(): MetaResponse {
1137
1334
  };
1138
1335
  loaderRootAnyOf.push({ $ref: `#/definitions/${loaderDefKey}` });
1139
1336
 
1140
- // Extract return type name for block-ref detection in sections (Bug #3)
1337
+ // Extract return type name for block-ref detection (Bug #3)
1141
1338
  const outputTypeName = extractLoaderOutputTypeName(sourceFile);
1142
1339
  if (outputTypeName) {
1143
1340
  const existing = outputTypeToLoaderKeys.get(outputTypeName) ?? [];
1144
1341
  existing.push(loaderKey);
1145
1342
  outputTypeToLoaderKeys.set(outputTypeName, existing);
1146
1343
  }
1344
+ registerExtension(sourceFile, loaderKey);
1147
1345
 
1148
- const propCount = Object.keys(propsSchema.properties || {}).length;
1149
- console.log(
1150
- ` ✓ loader ${loaderKey} (${propCount} props${outputTypeName ? ` → ${outputTypeName}` : ""})`,
1151
- );
1346
+ // The picker label, as for app loaders: a slash-free JSDoc @title on the
1347
+ // default export, else the key.
1348
+ const defaultSym = sourceFile.getDefaultExportSymbol();
1349
+ const titleTag = defaultSym ? getJsDocTags(defaultSym).title : undefined;
1350
+ const title = titleTag && !titleTag.includes("/") ? titleTag : loaderKey;
1351
+ loaderTitles.set(loaderKey, title);
1352
+
1353
+ pendingLoaderDefs.push(() => {
1354
+ try {
1355
+ // Extract Props (input schema)
1356
+ const lctx = loaderCtx();
1357
+ let propsSchema: any = null;
1358
+ const propsInterface = sourceFile.getInterface("Props");
1359
+ if (propsInterface)
1360
+ propsSchema = typeToJsonSchema(propsInterface.getType(), undefined, lctx);
1361
+
1362
+ const propsTypeAlias = sourceFile.getTypeAlias("Props");
1363
+ if (!propsSchema && propsTypeAlias)
1364
+ propsSchema = typeToJsonSchema(propsTypeAlias.getType(), undefined, lctx);
1365
+
1366
+ if (!propsSchema) {
1367
+ const localPropsType = extractDefaultExportPropsType(sourceFile);
1368
+ if (localPropsType) propsSchema = typeToJsonSchema(localPropsType, undefined, lctx);
1369
+ }
1370
+
1371
+ if (!propsSchema) propsSchema = { type: "object", properties: {} };
1372
+
1373
+ // Register flat loader definition (Bug #2: spread props, not nested under "props:")
1374
+ definitions[loaderDefKey] = {
1375
+ title,
1376
+ type: "object",
1377
+ required: ["__resolveType", ...(propsSchema?.required || [])],
1378
+ properties: {
1379
+ __resolveType: { type: "string", enum: [loaderKey], default: loaderKey },
1380
+ ...(propsSchema?.properties || {}),
1381
+ },
1382
+ };
1383
+
1384
+ const propCount = Object.keys(propsSchema.properties || {}).length;
1385
+ console.log(
1386
+ ` ✓ loader ${loaderKey} (${propCount} props${outputTypeName ? ` → ${outputTypeName}` : ""})`,
1387
+ );
1388
+ } catch (e) {
1389
+ console.warn(` ✗ loader ${loaderKey}: ${(e as Error).message}`);
1390
+ }
1391
+ });
1152
1392
  } catch (e) {
1153
1393
  console.warn(` ✗ loader ${loaderKey}: ${(e as Error).message}`);
1154
1394
  }
@@ -1227,7 +1467,9 @@ function generateMeta(): MetaResponse {
1227
1467
 
1228
1468
  // De-duplicate: when re-export files point to the same source, parse once
1229
1469
  const appLoaderCache = new Map<string, {
1230
- propsSchema: any;
1470
+ sourceFile: SourceFile;
1471
+ /** Built on first use, in the deferred pass (see pendingLoaderDefs). */
1472
+ propsSchema?: any;
1231
1473
  outputTypeName: string | null;
1232
1474
  title: string | null;
1233
1475
  hidden: boolean;
@@ -1264,40 +1506,60 @@ function generateMeta(): MetaResponse {
1264
1506
  const title = titleTag && !titleTag.includes("/") ? titleTag : null;
1265
1507
  const hidden = !!loaderTags.ignore;
1266
1508
 
1267
- // Extract Props (input schema)
1268
- let propsSchema: any = null;
1269
- const propsInterface = sourceFile.getInterface("Props");
1270
- if (propsInterface)
1271
- propsSchema = typeToJsonSchema(propsInterface.getType(), undefined, schemaRefs);
1272
-
1273
- const propsTypeAlias = sourceFile.getTypeAlias("Props");
1274
- if (!propsSchema && propsTypeAlias)
1275
- propsSchema = typeToJsonSchema(propsTypeAlias.getType(), undefined, schemaRefs);
1276
-
1277
- if (!propsSchema) {
1278
- const localPropsType = extractDefaultExportPropsType(sourceFile);
1279
- if (localPropsType) propsSchema = typeToJsonSchema(localPropsType, undefined, schemaRefs);
1280
- }
1281
-
1282
- if (!propsSchema) propsSchema = { type: "object", properties: {} };
1283
-
1284
1509
  const outputTypeName = extractLoaderOutputTypeName(sourceFile);
1285
- cached = { propsSchema, outputTypeName, title, hidden };
1510
+ cached = { sourceFile, outputTypeName, title, hidden };
1286
1511
  appLoaderCache.set(realPath, cached);
1287
1512
  }
1288
1513
 
1289
- const { propsSchema, outputTypeName, title, hidden } = cached;
1514
+ const entry = cached;
1515
+ if (!entry.hidden) registerExtension(entry.sourceFile, appLoader.cmsKey);
1516
+ loaderTitles.set(appLoader.cmsKey, entry.title ?? appLoader.cmsKey);
1517
+ const { outputTypeName, title, hidden } = entry;
1290
1518
  const loaderDefKey = toBase64(appLoader.cmsKey);
1519
+ const cmsKey = appLoader.cmsKey;
1291
1520
 
1292
- definitions[loaderDefKey] = {
1293
- title: title ?? appLoader.cmsKey,
1294
- type: "object",
1295
- required: ["__resolveType", ...(propsSchema?.required || [])],
1296
- properties: {
1297
- __resolveType: { type: "string", enum: [appLoader.cmsKey], default: appLoader.cmsKey },
1298
- ...(propsSchema?.properties || {}),
1299
- },
1300
- };
1521
+ pendingLoaderDefs.push(() => {
1522
+ try {
1523
+ if (!entry.propsSchema) {
1524
+ const { sourceFile } = entry;
1525
+ const lctx = loaderCtx();
1526
+ // Extract Props (input schema)
1527
+ let propsSchema: any = null;
1528
+ const propsInterface = sourceFile.getInterface("Props");
1529
+ if (propsInterface)
1530
+ propsSchema = typeToJsonSchema(propsInterface.getType(), undefined, lctx);
1531
+
1532
+ const propsTypeAlias = sourceFile.getTypeAlias("Props");
1533
+ if (!propsSchema && propsTypeAlias)
1534
+ propsSchema = typeToJsonSchema(propsTypeAlias.getType(), undefined, lctx);
1535
+
1536
+ if (!propsSchema) {
1537
+ const localPropsType = extractDefaultExportPropsType(sourceFile);
1538
+ if (localPropsType) propsSchema = typeToJsonSchema(localPropsType, undefined, lctx);
1539
+ }
1540
+
1541
+ entry.propsSchema = propsSchema ?? { type: "object", properties: {} };
1542
+ }
1543
+ const { propsSchema } = entry;
1544
+
1545
+ definitions[loaderDefKey] = {
1546
+ title: title ?? cmsKey,
1547
+ type: "object",
1548
+ required: ["__resolveType", ...(propsSchema?.required || [])],
1549
+ properties: {
1550
+ __resolveType: { type: "string", enum: [cmsKey], default: cmsKey },
1551
+ ...(propsSchema?.properties || {}),
1552
+ },
1553
+ };
1554
+
1555
+ const propCount = Object.keys(propsSchema.properties || {}).length;
1556
+ console.log(
1557
+ ` ${hidden ? "·" : "✓"} app loader ${cmsKey} (${propCount} props${outputTypeName ? ` → ${outputTypeName}` : ""}${hidden ? ", hidden" : ""})`,
1558
+ );
1559
+ } catch (e) {
1560
+ console.warn(` ✗ app loader ${cmsKey}: ${(e as Error).message}`);
1561
+ }
1562
+ });
1301
1563
 
1302
1564
  loaderBlocks[appLoader.cmsKey] = {
1303
1565
  $ref: `#/definitions/${loaderDefKey}`,
@@ -1317,11 +1579,6 @@ function generateMeta(): MetaResponse {
1317
1579
  outputTypeToLoaderKeys.set(outputTypeName, existing);
1318
1580
  }
1319
1581
  }
1320
-
1321
- const propCount = Object.keys(propsSchema.properties || {}).length;
1322
- console.log(
1323
- ` ${hidden ? "·" : "✓"} app loader ${appLoader.cmsKey} (${propCount} props${outputTypeName ? ` → ${outputTypeName}` : ""}${hidden ? ", hidden" : ""})`,
1324
- );
1325
1582
  } catch (e) {
1326
1583
  console.warn(` ✗ app loader ${appLoader.cmsKey}: ${(e as Error).message}`);
1327
1584
  }
@@ -1329,6 +1586,33 @@ function generateMeta(): MetaResponse {
1329
1586
 
1330
1587
  const ctx: GenerationContext = { ...schemaRefs, outputTypeToLoaderKeys };
1331
1588
 
1589
+ // The flags' own schemas (registered in the flags pass above). A value type
1590
+ // loaders return (`Product[] | null`) is a loader picker, as for a prop.
1591
+ for (const { flag, valueType, valueTypeName } of siteFlags) {
1592
+ try {
1593
+ const matchingLoaders = valueTypeName ? outputTypeToLoaderKeys.get(valueTypeName) : undefined;
1594
+ const valueSchema = matchingLoaders?.length
1595
+ ? {
1596
+ anyOf: [
1597
+ { $ref: `#/definitions/${RESOLVABLE_KEY}` },
1598
+ ...matchingLoaders.map((k) => ({ $ref: `#/definitions/${toBase64(k)}` })),
1599
+ ],
1600
+ }
1601
+ : typeToJsonSchema(valueType, undefined, ctx);
1602
+ definitions[`${flag.defKey}@Props`] = multivariatePropsSchema(valueSchema);
1603
+ const { allOf, required, properties } = flagBranch(flag);
1604
+ definitions[flag.defKey] = { title: flag.title, type: "object", allOf, required, properties };
1605
+ flagBlocks[flag.key] = { $ref: `#/definitions/${flag.defKey}`, namespace: SITE_NAMESPACE };
1606
+ flagRootAnyOf.push({
1607
+ $ref: `#/definitions/${flag.defKey}`,
1608
+ inputSchema: `#/definitions/${flag.defKey}@Props`,
1609
+ });
1610
+ console.log(` ✓ flag ${flag.key}${valueTypeName ? ` → ${valueTypeName}` : ""}`);
1611
+ } catch (e) {
1612
+ console.warn(` ✗ flag ${flag.key}: ${(e as Error).message}`);
1613
+ }
1614
+ }
1615
+
1332
1616
  // ---------------------------------------------------------------------------
1333
1617
  // Commerce "extension wrapper" loaders (deco-cx parity).
1334
1618
  //
@@ -1351,7 +1635,8 @@ function generateMeta(): MetaResponse {
1351
1635
  },
1352
1636
  ];
1353
1637
  for (const wrapper of COMMERCE_EXTENSION_WRAPPERS) {
1354
- const matchingLoaders = outputTypeToLoaderKeys.get(wrapper.outputType) ?? [];
1638
+ const matchingLoaders = [...(outputTypeToLoaderKeys.get(wrapper.outputType) ?? [])];
1639
+ const extensionLoaders = extensionTargetToLoaderKeys.get(wrapper.outputType) ?? [];
1355
1640
  // A wrapper whose base loader type has no matching loaders in the site is
1356
1641
  // useless (its `data` picker would only offer Resolvable). Non-commerce
1357
1642
  // sites (e.g. Eitri) have none, so skip it instead of injecting a phantom
@@ -1375,7 +1660,12 @@ function generateMeta(): MetaResponse {
1375
1660
  extensions: {
1376
1661
  type: "array",
1377
1662
  title: "The data Extensions",
1378
- items: { anyOf: [{ $ref: `#/definitions/${RESOLVABLE_KEY}` }] },
1663
+ items: {
1664
+ anyOf: [
1665
+ { $ref: `#/definitions/${RESOLVABLE_KEY}` },
1666
+ ...extensionLoaders.map((k) => ({ $ref: `#/definitions/${toBase64(k)}` })),
1667
+ ],
1668
+ },
1379
1669
  },
1380
1670
  },
1381
1671
  };
@@ -1384,11 +1674,17 @@ function generateMeta(): MetaResponse {
1384
1674
  namespace: "commerce",
1385
1675
  };
1386
1676
  loaderRootAnyOf.push({ $ref: `#/definitions/${wrapperDefKey}` });
1677
+ // The wrapper returns what it wraps, so a prop of that type offers it too
1678
+ // (a PLP section's `page` → "listingPage.ts" with its extensions).
1679
+ outputTypeToLoaderKeys.set(wrapper.outputType, [...matchingLoaders, wrapper.key]);
1387
1680
  console.log(
1388
- ` ✓ commerce extension wrapper ${wrapper.key} (data → ${matchingLoaders.length} loader(s))`,
1681
+ ` ✓ commerce extension wrapper ${wrapper.key} (data → ${matchingLoaders.length} loader(s), ${extensionLoaders.length} extension(s))`,
1389
1682
  );
1390
1683
  }
1391
1684
 
1685
+ // Loader input schemas, now that every loader output type is registered.
1686
+ for (const buildLoaderDef of pendingLoaderDefs) buildLoaderDef();
1687
+
1392
1688
  // ---------------------------------------------------------------------------
1393
1689
  // Second pass: scan sections
1394
1690
  // ---------------------------------------------------------------------------
@@ -1600,7 +1896,14 @@ function generateMeta(): MetaResponse {
1600
1896
  version: FRAMEWORK_VERSION,
1601
1897
  namespace: SITE_NAMESPACE,
1602
1898
  site: SITE_NAME,
1603
- manifest: { blocks: { sections: sectionBlocks, loaders: loaderBlocks, apps: appBlocks } },
1899
+ manifest: {
1900
+ blocks: {
1901
+ sections: sectionBlocks,
1902
+ loaders: loaderBlocks,
1903
+ flags: flagBlocks,
1904
+ apps: appBlocks,
1905
+ },
1906
+ },
1604
1907
  schema: {
1605
1908
  definitions,
1606
1909
  root: {
@@ -1610,7 +1913,7 @@ function generateMeta(): MetaResponse {
1610
1913
  pages: emptyAnyOf,
1611
1914
  handlers: emptyAnyOf,
1612
1915
  matchers: emptyAnyOf,
1613
- flags: emptyAnyOf,
1916
+ flags: { anyOf: flagRootAnyOf },
1614
1917
  functions: emptyAnyOf,
1615
1918
  apps: { anyOf: appRootAnyOf },
1616
1919
  },