@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.19
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/LICENSE +21 -0
- package/README.md +128 -10
- package/dist/abi/canvas-live.d.ts +72 -0
- package/dist/abi/canvas-live.js +159 -0
- package/dist/abi/cart.d.ts +60 -0
- package/dist/abi/cart.js +396 -0
- package/dist/abi/convert.d.ts +360 -0
- package/dist/abi/convert.js +1330 -0
- package/dist/abi/data-api.d.ts +15 -0
- package/dist/abi/data-api.js +213 -0
- package/dist/abi/jcs.d.ts +6 -0
- package/dist/abi/jcs.js +28 -0
- package/dist/abi/labels.d.ts +3 -0
- package/dist/abi/labels.js +34 -0
- package/dist/abi/page-data.d.ts +264 -0
- package/dist/abi/page-data.js +746 -0
- package/dist/abi/page.d.ts +28 -0
- package/dist/abi/page.js +57 -0
- package/dist/abi/referrals.d.ts +23 -0
- package/dist/abi/referrals.js +89 -0
- package/dist/abi/rewards.d.ts +27 -0
- package/dist/abi/rewards.js +82 -0
- package/dist/abi/seo.d.ts +47 -0
- package/dist/abi/seo.js +68 -0
- package/dist/abi/shell.d.ts +23 -0
- package/dist/abi/shell.js +10 -0
- package/dist/abi/state-pack.d.ts +17 -0
- package/dist/abi/state-pack.js +43 -0
- package/dist/abi/wire.d.ts +46 -0
- package/dist/abi/wire.js +114 -0
- package/dist/build.d.ts +121 -0
- package/dist/build.js +401 -0
- package/dist/chunks.d.ts +23 -0
- package/dist/chunks.js +41 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.js +101 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +6 -0
- package/dist/headless/ai.d.ts +132 -0
- package/dist/headless/ai.js +99 -0
- package/dist/headless/hooks.d.ts +276 -0
- package/dist/headless/hooks.js +544 -0
- package/dist/headless/i18n.d.ts +13 -0
- package/dist/headless/i18n.js +45 -0
- package/dist/headless/index.d.ts +44 -0
- package/dist/headless/index.js +48 -0
- package/dist/headless/lazy-component.d.ts +72 -0
- package/dist/headless/lazy-component.js +225 -0
- package/dist/headless/lazy-section.d.ts +38 -0
- package/dist/headless/lazy-section.js +97 -0
- package/dist/headless/model.d.ts +73 -0
- package/dist/headless/model.js +115 -0
- package/dist/headless/money.d.ts +17 -0
- package/dist/headless/money.js +63 -0
- package/dist/headless/page.d.ts +45 -0
- package/dist/headless/page.js +53 -0
- package/dist/headless/platform.d.ts +55 -0
- package/dist/headless/platform.js +77 -0
- package/dist/headless/primitives/cart.d.ts +90 -0
- package/dist/headless/primitives/cart.js +153 -0
- package/dist/headless/primitives/collection.d.ts +68 -0
- package/dist/headless/primitives/collection.js +80 -0
- package/dist/headless/primitives/product.d.ts +101 -0
- package/dist/headless/primitives/product.js +117 -0
- package/dist/headless/primitives/storefront.d.ts +106 -0
- package/dist/headless/primitives/storefront.js +187 -0
- package/dist/headless/primitives/util.d.ts +19 -0
- package/dist/headless/primitives/util.js +42 -0
- package/dist/headless/strings.d.ts +9 -0
- package/dist/headless/strings.js +198 -0
- package/dist/headless/structured-data.d.ts +31 -0
- package/dist/headless/structured-data.js +57 -0
- package/dist/headless/tanqory-money.generated.d.ts +493 -0
- package/dist/headless/tanqory-money.generated.js +507 -0
- package/dist/headless/theme.d.ts +109 -0
- package/dist/headless/theme.js +62 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -553
- package/dist/runtime/data/StoreProvider.d.ts +84 -0
- package/dist/runtime/data/StoreProvider.js +380 -0
- package/dist/runtime/data/handle.d.ts +14 -0
- package/dist/runtime/data/handle.js +16 -0
- package/dist/runtime/data/routes.d.ts +87 -0
- package/dist/runtime/data/routes.js +158 -0
- package/dist/runtime/data/to-ui.d.ts +286 -0
- package/dist/runtime/data/to-ui.js +1009 -0
- package/dist/runtime/entries/register.d.ts +9 -0
- package/dist/runtime/entries/register.js +9 -0
- package/dist/runtime/entries/sections.d.ts +16 -0
- package/dist/runtime/entries/sections.js +19 -0
- package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
- package/dist/runtime/kit/SectionTree.js +100 -0
- package/dist/runtime/kit/analytics.d.ts +63 -0
- package/dist/runtime/kit/analytics.js +250 -0
- package/dist/runtime/kit/cart.d.ts +222 -0
- package/dist/runtime/kit/cart.js +545 -0
- package/dist/{types → runtime/kit}/composition.d.ts +1 -1
- package/dist/runtime/kit/composition.js +3 -0
- package/dist/{types → runtime/kit}/config.d.ts +2 -2
- package/dist/runtime/kit/config.js +6 -0
- package/dist/runtime/kit/consent.d.ts +29 -0
- package/dist/runtime/kit/consent.js +159 -0
- package/dist/runtime/kit/contract/content.d.ts +213 -0
- package/dist/runtime/kit/contract/content.js +119 -0
- package/dist/runtime/kit/contract/field-types.d.ts +360 -0
- package/dist/runtime/kit/contract/field-types.js +216 -0
- package/dist/runtime/kit/contract/groups.d.ts +230 -0
- package/dist/runtime/kit/contract/groups.js +402 -0
- package/dist/runtime/kit/contract/index.d.ts +33 -0
- package/dist/runtime/kit/contract/index.js +33 -0
- package/dist/runtime/kit/contract/transform.d.ts +82 -0
- package/dist/runtime/kit/contract/transform.js +133 -0
- package/dist/runtime/kit/contract/validate.d.ts +77 -0
- package/dist/runtime/kit/contract/validate.js +520 -0
- package/dist/runtime/kit/data.d.ts +732 -0
- package/dist/runtime/kit/data.js +1131 -0
- package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
- package/dist/runtime/kit/defineSection.js +10 -0
- package/dist/runtime/kit/dynamic-source.d.ts +118 -0
- package/dist/runtime/kit/dynamic-source.js +311 -0
- package/dist/runtime/kit/index.d.ts +24 -0
- package/dist/runtime/kit/index.js +24 -0
- package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
- package/dist/runtime/kit/jsx-to-json.js +28 -0
- package/dist/{types → runtime/kit}/mount.d.ts +25 -4
- package/dist/runtime/kit/mount.js +124 -0
- package/dist/{types → runtime/kit}/registry.d.ts +1 -1
- package/dist/runtime/kit/registry.js +12 -0
- package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
- package/dist/runtime/kit/ssg.js +56 -0
- package/dist/runtime/kit/storefront.d.ts +652 -0
- package/dist/runtime/kit/storefront.js +723 -0
- package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
- package/dist/runtime/kit/theme-context.js +25 -0
- package/dist/runtime/kit/types.d.ts +155 -0
- package/dist/runtime/kit/types.js +1 -0
- package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
- package/dist/runtime/platform/TrackingPixels.js +63 -0
- package/dist/runtime/platform/environment.d.ts +68 -0
- package/dist/runtime/platform/environment.js +85 -0
- package/dist/runtime/platform/locale.d.ts +27 -0
- package/dist/runtime/platform/locale.js +42 -0
- package/dist/runtime/platform/route-analytics.d.ts +15 -0
- package/dist/runtime/platform/route-analytics.js +72 -0
- package/dist/runtime/platform/safe-href.d.ts +25 -0
- package/dist/runtime/platform/safe-href.js +69 -0
- package/dist/runtime/platform/safe-values.d.ts +37 -0
- package/dist/runtime/platform/safe-values.js +140 -0
- package/dist/runtime/render/SectionRenderer.d.ts +4 -0
- package/dist/runtime/render/SectionRenderer.js +199 -0
- package/dist/runtime/render/listing-query.d.ts +52 -0
- package/dist/runtime/render/listing-query.js +122 -0
- package/dist/runtime/render/localized-copy.d.ts +86 -0
- package/dist/runtime/render/localized-copy.js +129 -0
- package/dist/runtime/render/product-listing.d.ts +11 -0
- package/dist/runtime/render/product-listing.js +243 -0
- package/dist/runtime/render/resolved.d.ts +47 -0
- package/dist/runtime/render/resolved.js +80 -0
- package/dist/runtime/render/section-actions.d.ts +67 -0
- package/dist/runtime/render/section-actions.js +205 -0
- package/dist/runtime/render/starter.d.ts +11 -0
- package/dist/runtime/render/starter.js +96 -0
- package/dist/runtime/seo/head.d.ts +115 -0
- package/dist/runtime/seo/head.js +281 -0
- package/dist/runtime/seo/structured-data.d.ts +83 -0
- package/dist/runtime/seo/structured-data.js +252 -0
- package/dist/runtime/shell/PageShell.d.ts +18 -0
- package/dist/runtime/shell/PageShell.js +118 -0
- package/dist/runtime/shell/RuntimeBridge.d.ts +18 -0
- package/dist/runtime/shell/RuntimeBridge.js +124 -0
- package/dist/runtime/shell/overlay-state.d.ts +31 -0
- package/dist/runtime/shell/overlay-state.js +59 -0
- package/dist/runtime/shell/preview-mode.d.ts +2 -0
- package/dist/runtime/shell/preview-mode.js +11 -0
- package/dist/runtime/shell/spa-router.d.ts +14 -0
- package/dist/runtime/shell/spa-router.js +76 -0
- package/dist/runtime/shell/url-redirects.d.ts +6 -0
- package/dist/runtime/shell/url-redirects.js +37 -0
- package/dist/runtime/slots.d.ts +74 -0
- package/dist/runtime/slots.js +16 -0
- package/dist/runtime.d.ts +34 -0
- package/dist/runtime.js +40 -0
- package/dist/sdk/app-block.d.ts +29 -0
- package/dist/sdk/app-block.js +22 -0
- package/dist/sdk/font-hooks.d.ts +7 -0
- package/dist/sdk/font-hooks.js +21 -0
- package/dist/sdk/fonts.d.ts +144 -0
- package/dist/sdk/fonts.js +241 -0
- package/dist/sdk/index.d.ts +32 -0
- package/dist/sdk/index.js +36 -0
- package/dist/sdk/motion-hooks.d.ts +23 -0
- package/dist/sdk/motion-hooks.js +46 -0
- package/dist/sdk/motion.d.ts +78 -0
- package/dist/sdk/motion.js +292 -0
- package/dist/sdk/referrals.d.ts +62 -0
- package/dist/sdk/referrals.js +20 -0
- package/dist/sdk/rewards.d.ts +85 -0
- package/dist/sdk/rewards.js +29 -0
- package/dist/sdk/runtime-context.d.ts +230 -0
- package/dist/sdk/runtime-context.js +73 -0
- package/dist/sdk/schema.d.ts +249 -0
- package/dist/sdk/schema.js +168 -0
- package/dist/sdk/server-render.d.ts +8 -0
- package/dist/sdk/server-render.js +12 -0
- package/dist/sdk/store-lookup.d.ts +32 -0
- package/dist/sdk/store-lookup.js +48 -0
- package/dist/sdk/store.d.ts +164 -0
- package/dist/sdk/store.js +5 -0
- package/dist/sdk/sx.d.ts +45 -0
- package/dist/sdk/sx.js +117 -0
- package/dist/sdk/theme.d.ts +212 -0
- package/dist/sdk/theme.js +27 -0
- package/dist/sdk/types.d.ts +789 -0
- package/dist/sdk/types.js +7 -0
- package/dist/server.d.ts +112 -0
- package/dist/server.js +589 -0
- package/dist/vite-chunks.d.ts +10 -0
- package/dist/vite-chunks.js +44 -0
- package/docs/headless-api.md +250 -0
- package/package.json +72 -26
- package/dist/index.js.map +0 -1
- package/dist/ssg-BZ5FYTw7.js +0 -1802
- package/dist/ssg-BZ5FYTw7.js.map +0 -1
- package/dist/ssg.js +0 -8
- package/dist/ssg.js.map +0 -1
- package/dist/types/cart.d.ts +0 -86
- package/dist/types/data.d.ts +0 -357
- package/dist/types/dynamic-source.d.ts +0 -84
- package/dist/types/editor.d.ts +0 -5
- package/dist/types/index.d.ts +0 -20
- package/dist/types/preview-bridge.d.ts +0 -9
- package/dist/types/storefront.d.ts +0 -333
- package/dist/types/types.d.ts +0 -44
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tanqory Theme Contract v1 — the shared agreement between the theme (kit),
|
|
3
|
+
* the CMS (studio-api + code-store), the Editor (studio-app), the storefront
|
|
4
|
+
* runtime, and any AI authoring against them.
|
|
5
|
+
*
|
|
6
|
+
* Owner: `@tanqory/theme-kit`. It already owns `AttrSpec` / `SectionDef` /
|
|
7
|
+
* `ContentNode` / `PageDoc`, so the contract derives from the code rather than
|
|
8
|
+
* restating it — and `tsc` proves the derivation.
|
|
9
|
+
*
|
|
10
|
+
* This entry is dependency-free (no React), so it builds to a single portable
|
|
11
|
+
* `dist/contract.js` that studio-api can vendor without breaking its
|
|
12
|
+
* zero-npm-dependency image.
|
|
13
|
+
*/
|
|
14
|
+
export const CONTRACT_VERSION = '1.0.0';
|
|
15
|
+
/**
|
|
16
|
+
* Which theme-kit releases this contract describes.
|
|
17
|
+
*
|
|
18
|
+
* Nothing on the platform declared runtime compatibility before, so a theme
|
|
19
|
+
* built against one kit and rendered by another failed at runtime with no
|
|
20
|
+
* signal. A consumer compares its installed kit version against this range and
|
|
21
|
+
* says so up front.
|
|
22
|
+
*/
|
|
23
|
+
export const KIT_COMPATIBILITY = {
|
|
24
|
+
/** Lowest kit release whose runtime honours everything in this contract. */
|
|
25
|
+
min: '0.1.3',
|
|
26
|
+
/** Highest kit release verified against it. */
|
|
27
|
+
maxVerified: '0.2.0',
|
|
28
|
+
};
|
|
29
|
+
export * from './field-types.js';
|
|
30
|
+
export * from './content.js';
|
|
31
|
+
export * from './groups.js';
|
|
32
|
+
export * from './transform.js';
|
|
33
|
+
export * from './validate.js';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical Editor <-> runtime transform.
|
|
3
|
+
*
|
|
4
|
+
* Two shapes exist and both are load-bearing:
|
|
5
|
+
* runtime / disk : `{ sections: [ { type, id, settings, blocks? } ] }` — an
|
|
6
|
+
* ARRAY, because `SectionTree` does `node.blocks?.map`.
|
|
7
|
+
* editor UI : `{ order: [id], sections: { id: {...} } }` — an object map
|
|
8
|
+
* keyed by id, because the panel addresses nodes by id.
|
|
9
|
+
*
|
|
10
|
+
* studio-api converts between them today (`editor-routes.mjs:77-108`). That
|
|
11
|
+
* implementation is lossy in three ways this one is not:
|
|
12
|
+
*
|
|
13
|
+
* 1. **It rebuilds a fixed shape**, so any key it does not enumerate is
|
|
14
|
+
* destroyed on the first autosave. `area` — used 43× in Nova's templates,
|
|
15
|
+
* and written by the AI theme assembler — is dropped on read and never
|
|
16
|
+
* restored on write. Anything this contract adds later would go the same
|
|
17
|
+
* way. Here, unknown keys are carried through.
|
|
18
|
+
* 2. **A block with no id gets `` `${type}-${index}` ``** — a POSITIONAL
|
|
19
|
+
* identity. Reorder and `faq-item-0` silently means a different question,
|
|
20
|
+
* which breaks "edit one answer without touching the others".
|
|
21
|
+
* 3. **A section with no id falls back to its `type`**, so two sections of the
|
|
22
|
+
* same type collide in the map and the second overwrites the first.
|
|
23
|
+
*
|
|
24
|
+
* Ids are minted once, here, when genuinely absent — and reported, so the
|
|
25
|
+
* caller can persist them instead of re-minting on every read.
|
|
26
|
+
*/
|
|
27
|
+
import { type ContractPageDoc } from './content.js';
|
|
28
|
+
/** The editor's object-map shape for one node. */
|
|
29
|
+
export interface EditorNode {
|
|
30
|
+
type: string;
|
|
31
|
+
settings: Record<string, unknown>;
|
|
32
|
+
blocks?: Record<string, EditorNode>;
|
|
33
|
+
order?: string[];
|
|
34
|
+
/** Keys the contract does not model, preserved verbatim across the round trip. */
|
|
35
|
+
[extra: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
export interface EditorDoc {
|
|
38
|
+
order: string[];
|
|
39
|
+
sections: Record<string, EditorNode>;
|
|
40
|
+
contentVersion?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Top-level keys the transform does not model — `groups` (the shared
|
|
43
|
+
* header/footer bindings) above all — preserved verbatim, so a document that
|
|
44
|
+
* binds a group still binds it after an Editor round trip.
|
|
45
|
+
*/
|
|
46
|
+
[extra: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
export interface TransformReport {
|
|
49
|
+
/** Ids minted because a node had none. Persist these or they change next read. */
|
|
50
|
+
mintedIds: Array<{
|
|
51
|
+
path: string;
|
|
52
|
+
type: string;
|
|
53
|
+
id: string;
|
|
54
|
+
}>;
|
|
55
|
+
/** Ids that collided and had to be disambiguated. */
|
|
56
|
+
renamedIds: Array<{
|
|
57
|
+
path: string;
|
|
58
|
+
from: string;
|
|
59
|
+
to: string;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* runtime/disk → editor. Non-destructive: unmodelled keys survive in the node
|
|
64
|
+
* and are restored by `toRuntimeShape`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function toEditorShape(doc: ContractPageDoc, mint?: (type: string) => string): {
|
|
67
|
+
doc: EditorDoc;
|
|
68
|
+
report: TransformReport;
|
|
69
|
+
};
|
|
70
|
+
/** editor → runtime/disk. The exact inverse, including unmodelled keys. */
|
|
71
|
+
export declare function toRuntimeShape(doc: EditorDoc): ContractPageDoc;
|
|
72
|
+
/**
|
|
73
|
+
* Give every node an explicit id, in place of the positional fallback.
|
|
74
|
+
*
|
|
75
|
+
* Run once over a template authored before this contract (or by a producer that
|
|
76
|
+
* omitted ids) and persist the result: after that, ids are stable and a
|
|
77
|
+
* targeted edit addresses the node the author meant.
|
|
78
|
+
*/
|
|
79
|
+
export declare function ensureNodeIds(doc: ContractPageDoc, mint?: (type: string) => string): {
|
|
80
|
+
doc: ContractPageDoc;
|
|
81
|
+
report: TransformReport;
|
|
82
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical Editor <-> runtime transform.
|
|
3
|
+
*
|
|
4
|
+
* Two shapes exist and both are load-bearing:
|
|
5
|
+
* runtime / disk : `{ sections: [ { type, id, settings, blocks? } ] }` — an
|
|
6
|
+
* ARRAY, because `SectionTree` does `node.blocks?.map`.
|
|
7
|
+
* editor UI : `{ order: [id], sections: { id: {...} } }` — an object map
|
|
8
|
+
* keyed by id, because the panel addresses nodes by id.
|
|
9
|
+
*
|
|
10
|
+
* studio-api converts between them today (`editor-routes.mjs:77-108`). That
|
|
11
|
+
* implementation is lossy in three ways this one is not:
|
|
12
|
+
*
|
|
13
|
+
* 1. **It rebuilds a fixed shape**, so any key it does not enumerate is
|
|
14
|
+
* destroyed on the first autosave. `area` — used 43× in Nova's templates,
|
|
15
|
+
* and written by the AI theme assembler — is dropped on read and never
|
|
16
|
+
* restored on write. Anything this contract adds later would go the same
|
|
17
|
+
* way. Here, unknown keys are carried through.
|
|
18
|
+
* 2. **A block with no id gets `` `${type}-${index}` ``** — a POSITIONAL
|
|
19
|
+
* identity. Reorder and `faq-item-0` silently means a different question,
|
|
20
|
+
* which breaks "edit one answer without touching the others".
|
|
21
|
+
* 3. **A section with no id falls back to its `type`**, so two sections of the
|
|
22
|
+
* same type collide in the map and the second overwrites the first.
|
|
23
|
+
*
|
|
24
|
+
* Ids are minted once, here, when genuinely absent — and reported, so the
|
|
25
|
+
* caller can persist them instead of re-minting on every read.
|
|
26
|
+
*/
|
|
27
|
+
import { mintNodeId } from './content.js';
|
|
28
|
+
/** Top-level keys the transform manages; everything else rides through. */
|
|
29
|
+
const MANAGED_DOC_KEYS = new Set(['sections', 'order', 'contentVersion']);
|
|
30
|
+
/** Keys the transform manages explicitly; everything else rides in `extra`. */
|
|
31
|
+
const MANAGED = new Set(['type', 'id', 'settings', 'blocks']);
|
|
32
|
+
/**
|
|
33
|
+
* runtime/disk → editor. Non-destructive: unmodelled keys survive in the node
|
|
34
|
+
* and are restored by `toRuntimeShape`.
|
|
35
|
+
*/
|
|
36
|
+
export function toEditorShape(doc, mint = mintNodeId) {
|
|
37
|
+
const report = { mintedIds: [], renamedIds: [] };
|
|
38
|
+
const sections = Array.isArray(doc?.sections) ? doc.sections : [];
|
|
39
|
+
const { map, order } = levelToEditor(sections, 'sections', report, mint);
|
|
40
|
+
const extra = {};
|
|
41
|
+
for (const [k, v] of Object.entries(doc ?? {}))
|
|
42
|
+
if (!MANAGED_DOC_KEYS.has(k))
|
|
43
|
+
extra[k] = v;
|
|
44
|
+
return {
|
|
45
|
+
doc: {
|
|
46
|
+
order,
|
|
47
|
+
sections: map,
|
|
48
|
+
contentVersion: doc?.contentVersion ?? undefined,
|
|
49
|
+
...extra,
|
|
50
|
+
},
|
|
51
|
+
report,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function levelToEditor(nodes, basePath, report, mint) {
|
|
55
|
+
const map = {};
|
|
56
|
+
const order = [];
|
|
57
|
+
nodes.forEach((node, i) => {
|
|
58
|
+
const path = `${basePath}[${i}]`;
|
|
59
|
+
let id = typeof node?.id === 'string' && node.id !== '' ? node.id : '';
|
|
60
|
+
if (!id) {
|
|
61
|
+
id = mint(node?.type ?? 'node');
|
|
62
|
+
report.mintedIds.push({ path, type: node?.type ?? 'node', id });
|
|
63
|
+
}
|
|
64
|
+
if (map[id]) {
|
|
65
|
+
const to = mint(node?.type ?? 'node');
|
|
66
|
+
report.renamedIds.push({ path, from: id, to });
|
|
67
|
+
id = to;
|
|
68
|
+
}
|
|
69
|
+
const extra = {};
|
|
70
|
+
for (const [k, v] of Object.entries(node ?? {})) {
|
|
71
|
+
if (!MANAGED.has(k))
|
|
72
|
+
extra[k] = v;
|
|
73
|
+
}
|
|
74
|
+
const child = Array.isArray(node?.blocks)
|
|
75
|
+
? levelToEditor(node.blocks, `${path}.blocks`, report, mint)
|
|
76
|
+
: null;
|
|
77
|
+
map[id] = {
|
|
78
|
+
type: node?.type,
|
|
79
|
+
settings: node?.settings ?? {},
|
|
80
|
+
...extra,
|
|
81
|
+
...(child ? { blocks: child.map, order: child.order } : {}),
|
|
82
|
+
};
|
|
83
|
+
order.push(id);
|
|
84
|
+
});
|
|
85
|
+
return { map, order };
|
|
86
|
+
}
|
|
87
|
+
/** editor → runtime/disk. The exact inverse, including unmodelled keys. */
|
|
88
|
+
export function toRuntimeShape(doc) {
|
|
89
|
+
const order = Array.isArray(doc?.order) ? doc.order : Object.keys(doc?.sections ?? {});
|
|
90
|
+
const extra = {};
|
|
91
|
+
for (const [k, v] of Object.entries(doc ?? {}))
|
|
92
|
+
if (!MANAGED_DOC_KEYS.has(k))
|
|
93
|
+
extra[k] = v;
|
|
94
|
+
return {
|
|
95
|
+
...(doc?.contentVersion !== undefined ? { contentVersion: doc.contentVersion } : {}),
|
|
96
|
+
sections: levelToRuntime(doc?.sections ?? {}, order),
|
|
97
|
+
...extra,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function levelToRuntime(map, order) {
|
|
101
|
+
return order
|
|
102
|
+
.filter((id) => map[id])
|
|
103
|
+
.map((id) => {
|
|
104
|
+
const node = map[id];
|
|
105
|
+
const extra = {};
|
|
106
|
+
for (const [k, v] of Object.entries(node)) {
|
|
107
|
+
if (k === 'type' || k === 'settings' || k === 'blocks' || k === 'order')
|
|
108
|
+
continue;
|
|
109
|
+
extra[k] = v;
|
|
110
|
+
}
|
|
111
|
+
const blocks = node.blocks && typeof node.blocks === 'object'
|
|
112
|
+
? levelToRuntime(node.blocks, Array.isArray(node.order) ? node.order : Object.keys(node.blocks))
|
|
113
|
+
: null;
|
|
114
|
+
return {
|
|
115
|
+
type: node.type,
|
|
116
|
+
id,
|
|
117
|
+
settings: node.settings ?? {},
|
|
118
|
+
...extra,
|
|
119
|
+
...(blocks && blocks.length ? { blocks } : {}),
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Give every node an explicit id, in place of the positional fallback.
|
|
125
|
+
*
|
|
126
|
+
* Run once over a template authored before this contract (or by a producer that
|
|
127
|
+
* omitted ids) and persist the result: after that, ids are stable and a
|
|
128
|
+
* targeted edit addresses the node the author meant.
|
|
129
|
+
*/
|
|
130
|
+
export function ensureNodeIds(doc, mint = mintNodeId) {
|
|
131
|
+
const { doc: editor, report } = toEditorShape(doc, mint);
|
|
132
|
+
return { doc: toRuntimeShape(editor), report };
|
|
133
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type AppBlockContract, type ContractPageDoc, type SectionContract } from './content.js';
|
|
2
|
+
import { type GroupMap, type GroupedPageDoc } from './groups.js';
|
|
3
|
+
export type Severity = 'error' | 'warning';
|
|
4
|
+
export interface ValidationIssue {
|
|
5
|
+
severity: Severity;
|
|
6
|
+
/** Stable machine identifier. Callers branch on this, never on `message`. */
|
|
7
|
+
code: ValidationCode;
|
|
8
|
+
/** The node this is about, when there is one. */
|
|
9
|
+
nodeId?: string;
|
|
10
|
+
/** JSON path into the document, e.g. `sections[2].blocks[0].settings.answer`. */
|
|
11
|
+
path: string;
|
|
12
|
+
message: string;
|
|
13
|
+
/** The corrected value, when the validator knows it (aliases, casing). */
|
|
14
|
+
suggestion?: string;
|
|
15
|
+
}
|
|
16
|
+
export type ValidationCode = 'unknown_component' | 'unknown_setting' | 'unknown_field_type' | 'alias_field_type' | 'editor_only_field_type' | 'missing_node_id' | 'invalid_node_id' | 'invalid_node_name' | 'duplicate_node_id' | 'disallowed_nesting' | 'leaf_cannot_nest' | 'invalid_area' | 'invalid_value' | 'missing_required_constraint' | 'invalid_binding' | 'missing_context' | 'invalid_placement' | 'unknown_group' | 'invalid_group' | 'app_block_unavailable' | 'invalid_app_block';
|
|
17
|
+
export interface ValidationResult {
|
|
18
|
+
ok: boolean;
|
|
19
|
+
issues: ValidationIssue[];
|
|
20
|
+
}
|
|
21
|
+
/** The section catalogue a document is validated against. */
|
|
22
|
+
export type SectionCatalog = Record<string, SectionContract>;
|
|
23
|
+
export interface ValidateOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Route context available where this document renders, for `requiresContext`.
|
|
26
|
+
* When supplied, a section placed outside its required context is an ERROR —
|
|
27
|
+
* the caller has said where this renders, and it would show a not-found
|
|
28
|
+
* state on every visit. Omitted → the same finding is a warning.
|
|
29
|
+
*/
|
|
30
|
+
context?: readonly string[];
|
|
31
|
+
/**
|
|
32
|
+
* Treat unknown settings as warnings rather than errors. Off by default: an
|
|
33
|
+
* unknown setting is silently dropped at render, so the template claims to
|
|
34
|
+
* configure something it does not.
|
|
35
|
+
*/
|
|
36
|
+
lenientSettings?: boolean;
|
|
37
|
+
/** Base template slug this document is, for `placement.templates`. */
|
|
38
|
+
template?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The app blocks the store can use (theme-abi §7.2), by type: the blocks of the newest released version of each
|
|
41
|
+
* installed app. Given, an `app:` node whose type is not here is reported `app_block_unavailable` (a WARNING: the
|
|
42
|
+
* node stays in the document and is left out of the render, so a save never fails because an app was removed) and
|
|
43
|
+
* a known one has its settings checked against the block's own definition. Omitted, app nodes are checked for
|
|
44
|
+
* placement only.
|
|
45
|
+
*/
|
|
46
|
+
appBlocks?: Readonly<Record<string, AppBlockContract>>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validate a section's own declaration — the shape a theme author or an AI
|
|
50
|
+
* writes in `defineSection({...})`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function validateSectionContract(def: SectionContract): ValidationResult;
|
|
53
|
+
/** What to write instead of an editor-only type that has a declarable form, or undefined (MCP limits item 7). */
|
|
54
|
+
export declare function editorOnlyReplacement(type: unknown): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Validate a template document against a section catalogue.
|
|
57
|
+
*
|
|
58
|
+
* This is the check that makes the FAQ round trip provable: unknown component,
|
|
59
|
+
* unknown setting, disallowed nesting, duplicate id and missing id are each a
|
|
60
|
+
* distinct, addressable failure instead of a silent drop at render time.
|
|
61
|
+
*/
|
|
62
|
+
export declare function validateDocument(doc: ContractPageDoc, catalog: SectionCatalog, opts?: ValidateOptions): ValidationResult;
|
|
63
|
+
/** Validate one `groups/<name>.json` document against the catalogue. */
|
|
64
|
+
export declare function validateGroup(name: string, group: unknown, catalog: SectionCatalog, opts?: ValidateOptions): ValidationResult;
|
|
65
|
+
/**
|
|
66
|
+
* Validate a template TOGETHER with the groups it binds — the check the editor,
|
|
67
|
+
* studio-api and the AI tools run before a save.
|
|
68
|
+
*
|
|
69
|
+
* - the template's own body validates as before;
|
|
70
|
+
* - each `ref` must name a supplied group (`unknown_group` otherwise);
|
|
71
|
+
* - each `override` validates as that slot's nodes;
|
|
72
|
+
* - the RESOLVED page is checked for duplicate ids across slots, so a group
|
|
73
|
+
* node and a body node cannot share an id.
|
|
74
|
+
*/
|
|
75
|
+
export declare function validatePage(template: GroupedPageDoc, groups: GroupMap, catalog: SectionCatalog, opts?: ValidateOptions): ValidationResult;
|
|
76
|
+
/** Render issues as human lines — shared by the CLI and error responses. */
|
|
77
|
+
export declare function formatIssues(issues: ValidationIssue[]): string;
|