@tanqory/theme-kit 0.1.0 → 2.0.0-alpha.17

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 (210) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -10
  3. package/dist/abi/canvas-live.d.ts +67 -0
  4. package/dist/abi/canvas-live.js +154 -0
  5. package/dist/abi/cart.d.ts +59 -0
  6. package/dist/abi/cart.js +387 -0
  7. package/dist/abi/convert.d.ts +344 -0
  8. package/dist/abi/convert.js +1278 -0
  9. package/dist/abi/data-api.d.ts +15 -0
  10. package/dist/abi/data-api.js +209 -0
  11. package/dist/abi/jcs.d.ts +6 -0
  12. package/dist/abi/jcs.js +28 -0
  13. package/dist/abi/labels.d.ts +3 -0
  14. package/dist/abi/labels.js +34 -0
  15. package/dist/abi/page-data.d.ts +256 -0
  16. package/dist/abi/page-data.js +678 -0
  17. package/dist/abi/page.d.ts +28 -0
  18. package/dist/abi/page.js +57 -0
  19. package/dist/abi/referrals.d.ts +23 -0
  20. package/dist/abi/referrals.js +89 -0
  21. package/dist/abi/rewards.d.ts +27 -0
  22. package/dist/abi/rewards.js +82 -0
  23. package/dist/abi/seo.d.ts +47 -0
  24. package/dist/abi/seo.js +68 -0
  25. package/dist/abi/shell.d.ts +23 -0
  26. package/dist/abi/shell.js +10 -0
  27. package/dist/abi/state-pack.d.ts +17 -0
  28. package/dist/abi/state-pack.js +43 -0
  29. package/dist/abi/wire.d.ts +38 -0
  30. package/dist/abi/wire.js +84 -0
  31. package/dist/build.d.ts +116 -0
  32. package/dist/build.js +310 -0
  33. package/dist/client.d.ts +19 -0
  34. package/dist/client.js +87 -0
  35. package/dist/contract.d.ts +6 -0
  36. package/dist/contract.js +6 -0
  37. package/dist/headless/ai.d.ts +132 -0
  38. package/dist/headless/ai.js +99 -0
  39. package/dist/headless/hooks.d.ts +276 -0
  40. package/dist/headless/hooks.js +540 -0
  41. package/dist/headless/i18n.d.ts +13 -0
  42. package/dist/headless/i18n.js +45 -0
  43. package/dist/headless/index.d.ts +37 -0
  44. package/dist/headless/index.js +38 -0
  45. package/dist/headless/money.d.ts +25 -0
  46. package/dist/headless/money.js +61 -0
  47. package/dist/headless/page.d.ts +43 -0
  48. package/dist/headless/page.js +53 -0
  49. package/dist/headless/platform.d.ts +55 -0
  50. package/dist/headless/platform.js +77 -0
  51. package/dist/headless/primitives/cart.d.ts +90 -0
  52. package/dist/headless/primitives/cart.js +153 -0
  53. package/dist/headless/primitives/collection.d.ts +68 -0
  54. package/dist/headless/primitives/collection.js +80 -0
  55. package/dist/headless/primitives/product.d.ts +101 -0
  56. package/dist/headless/primitives/product.js +117 -0
  57. package/dist/headless/primitives/storefront.d.ts +106 -0
  58. package/dist/headless/primitives/storefront.js +186 -0
  59. package/dist/headless/primitives/util.d.ts +19 -0
  60. package/dist/headless/primitives/util.js +42 -0
  61. package/dist/headless/strings.d.ts +9 -0
  62. package/dist/headless/strings.js +190 -0
  63. package/dist/headless/structured-data.d.ts +31 -0
  64. package/dist/headless/structured-data.js +57 -0
  65. package/dist/headless/theme.d.ts +99 -0
  66. package/dist/headless/theme.js +54 -0
  67. package/dist/index.d.ts +20 -0
  68. package/dist/index.js +18 -553
  69. package/dist/runtime/data/StoreProvider.d.ts +84 -0
  70. package/dist/runtime/data/StoreProvider.js +373 -0
  71. package/dist/runtime/data/handle.d.ts +14 -0
  72. package/dist/runtime/data/handle.js +16 -0
  73. package/dist/runtime/data/routes.d.ts +87 -0
  74. package/dist/runtime/data/routes.js +158 -0
  75. package/dist/runtime/data/to-ui.d.ts +281 -0
  76. package/dist/runtime/data/to-ui.js +977 -0
  77. package/dist/runtime/entries/register.d.ts +9 -0
  78. package/dist/runtime/entries/register.js +9 -0
  79. package/dist/runtime/entries/sections.d.ts +16 -0
  80. package/dist/runtime/entries/sections.js +19 -0
  81. package/dist/{types → runtime/kit}/SectionTree.d.ts +2 -1
  82. package/dist/runtime/kit/SectionTree.js +100 -0
  83. package/dist/runtime/kit/analytics.d.ts +63 -0
  84. package/dist/runtime/kit/analytics.js +250 -0
  85. package/dist/runtime/kit/cart.d.ts +215 -0
  86. package/dist/runtime/kit/cart.js +545 -0
  87. package/dist/{types → runtime/kit}/composition.d.ts +1 -1
  88. package/dist/runtime/kit/composition.js +3 -0
  89. package/dist/{types → runtime/kit}/config.d.ts +2 -2
  90. package/dist/runtime/kit/config.js +6 -0
  91. package/dist/runtime/kit/consent.d.ts +29 -0
  92. package/dist/runtime/kit/consent.js +159 -0
  93. package/dist/runtime/kit/contract/content.d.ts +199 -0
  94. package/dist/runtime/kit/contract/content.js +106 -0
  95. package/dist/runtime/kit/contract/field-types.d.ts +337 -0
  96. package/dist/runtime/kit/contract/field-types.js +206 -0
  97. package/dist/runtime/kit/contract/groups.d.ts +230 -0
  98. package/dist/runtime/kit/contract/groups.js +402 -0
  99. package/dist/runtime/kit/contract/index.d.ts +33 -0
  100. package/dist/runtime/kit/contract/index.js +33 -0
  101. package/dist/runtime/kit/contract/transform.d.ts +82 -0
  102. package/dist/runtime/kit/contract/transform.js +133 -0
  103. package/dist/runtime/kit/contract/validate.d.ts +75 -0
  104. package/dist/runtime/kit/contract/validate.js +480 -0
  105. package/dist/runtime/kit/data.d.ts +720 -0
  106. package/dist/runtime/kit/data.js +1117 -0
  107. package/dist/{types → runtime/kit}/defineSection.d.ts +1 -1
  108. package/dist/runtime/kit/defineSection.js +10 -0
  109. package/dist/{types → runtime/kit}/dynamic-source.d.ts +40 -18
  110. package/dist/runtime/kit/dynamic-source.js +294 -0
  111. package/dist/runtime/kit/index.d.ts +24 -0
  112. package/dist/runtime/kit/index.js +24 -0
  113. package/dist/{types → runtime/kit}/jsx-to-json.d.ts +1 -1
  114. package/dist/runtime/kit/jsx-to-json.js +28 -0
  115. package/dist/{types → runtime/kit}/mount.d.ts +25 -4
  116. package/dist/runtime/kit/mount.js +124 -0
  117. package/dist/{types → runtime/kit}/registry.d.ts +1 -1
  118. package/dist/runtime/kit/registry.js +12 -0
  119. package/dist/{types → runtime/kit}/ssg.d.ts +9 -3
  120. package/dist/runtime/kit/ssg.js +56 -0
  121. package/dist/runtime/kit/storefront.d.ts +639 -0
  122. package/dist/runtime/kit/storefront.js +723 -0
  123. package/dist/{types → runtime/kit}/theme-context.d.ts +8 -2
  124. package/dist/runtime/kit/theme-context.js +25 -0
  125. package/dist/runtime/kit/types.d.ts +147 -0
  126. package/dist/runtime/kit/types.js +1 -0
  127. package/dist/runtime/platform/TrackingPixels.d.ts +14 -0
  128. package/dist/runtime/platform/TrackingPixels.js +63 -0
  129. package/dist/runtime/platform/environment.d.ts +68 -0
  130. package/dist/runtime/platform/environment.js +85 -0
  131. package/dist/runtime/platform/locale.d.ts +27 -0
  132. package/dist/runtime/platform/locale.js +42 -0
  133. package/dist/runtime/platform/route-analytics.d.ts +15 -0
  134. package/dist/runtime/platform/route-analytics.js +72 -0
  135. package/dist/runtime/platform/safe-href.d.ts +25 -0
  136. package/dist/runtime/platform/safe-href.js +69 -0
  137. package/dist/runtime/platform/safe-values.d.ts +37 -0
  138. package/dist/runtime/platform/safe-values.js +140 -0
  139. package/dist/runtime/render/SectionRenderer.d.ts +4 -0
  140. package/dist/runtime/render/SectionRenderer.js +166 -0
  141. package/dist/runtime/render/listing-query.d.ts +52 -0
  142. package/dist/runtime/render/listing-query.js +122 -0
  143. package/dist/runtime/render/localized-copy.d.ts +86 -0
  144. package/dist/runtime/render/localized-copy.js +129 -0
  145. package/dist/runtime/render/product-listing.d.ts +11 -0
  146. package/dist/runtime/render/product-listing.js +243 -0
  147. package/dist/runtime/render/section-actions.d.ts +66 -0
  148. package/dist/runtime/render/section-actions.js +202 -0
  149. package/dist/runtime/render/starter.d.ts +11 -0
  150. package/dist/runtime/render/starter.js +81 -0
  151. package/dist/runtime/seo/head.d.ts +115 -0
  152. package/dist/runtime/seo/head.js +281 -0
  153. package/dist/runtime/seo/structured-data.d.ts +83 -0
  154. package/dist/runtime/seo/structured-data.js +252 -0
  155. package/dist/runtime/shell/PageShell.d.ts +18 -0
  156. package/dist/runtime/shell/PageShell.js +113 -0
  157. package/dist/runtime/shell/RuntimeBridge.d.ts +14 -0
  158. package/dist/runtime/shell/RuntimeBridge.js +93 -0
  159. package/dist/runtime/shell/overlay-state.d.ts +31 -0
  160. package/dist/runtime/shell/overlay-state.js +59 -0
  161. package/dist/runtime/shell/preview-mode.d.ts +2 -0
  162. package/dist/runtime/shell/preview-mode.js +11 -0
  163. package/dist/runtime/shell/spa-router.d.ts +14 -0
  164. package/dist/runtime/shell/spa-router.js +76 -0
  165. package/dist/runtime/shell/url-redirects.d.ts +6 -0
  166. package/dist/runtime/shell/url-redirects.js +37 -0
  167. package/dist/runtime/slots.d.ts +74 -0
  168. package/dist/runtime/slots.js +16 -0
  169. package/dist/runtime.d.ts +34 -0
  170. package/dist/runtime.js +40 -0
  171. package/dist/sdk/app-block.d.ts +29 -0
  172. package/dist/sdk/app-block.js +22 -0
  173. package/dist/sdk/index.d.ts +26 -0
  174. package/dist/sdk/index.js +26 -0
  175. package/dist/sdk/referrals.d.ts +62 -0
  176. package/dist/sdk/referrals.js +20 -0
  177. package/dist/sdk/rewards.d.ts +85 -0
  178. package/dist/sdk/rewards.js +29 -0
  179. package/dist/sdk/runtime-context.d.ts +202 -0
  180. package/dist/sdk/runtime-context.js +73 -0
  181. package/dist/sdk/schema.d.ts +206 -0
  182. package/dist/sdk/schema.js +121 -0
  183. package/dist/sdk/server-render.d.ts +8 -0
  184. package/dist/sdk/server-render.js +12 -0
  185. package/dist/sdk/store-lookup.d.ts +27 -0
  186. package/dist/sdk/store-lookup.js +29 -0
  187. package/dist/sdk/store.d.ts +149 -0
  188. package/dist/sdk/store.js +5 -0
  189. package/dist/sdk/sx.d.ts +40 -0
  190. package/dist/sdk/sx.js +112 -0
  191. package/dist/sdk/theme.d.ts +191 -0
  192. package/dist/sdk/theme.js +10 -0
  193. package/dist/sdk/types.d.ts +757 -0
  194. package/dist/sdk/types.js +7 -0
  195. package/dist/server.d.ts +111 -0
  196. package/dist/server.js +533 -0
  197. package/docs/headless-api.md +220 -0
  198. package/package.json +76 -22
  199. package/dist/index.js.map +0 -1
  200. package/dist/ssg-BZ5FYTw7.js +0 -1802
  201. package/dist/ssg-BZ5FYTw7.js.map +0 -1
  202. package/dist/ssg.js +0 -8
  203. package/dist/ssg.js.map +0 -1
  204. package/dist/types/cart.d.ts +0 -86
  205. package/dist/types/data.d.ts +0 -357
  206. package/dist/types/editor.d.ts +0 -5
  207. package/dist/types/index.d.ts +0 -20
  208. package/dist/types/preview-bridge.d.ts +0 -9
  209. package/dist/types/storefront.d.ts +0 -333
  210. package/dist/types/types.d.ts +0 -44
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Cookie-consent state — the single source of truth the storefront consults
3
+ * before running any tracking (analytics beacon, marketing pixels), so the
4
+ * shopper's choice is actually ENFORCED.
5
+ *
6
+ * Model: two purposes, `analytics` + `marketing`. The decision persists in
7
+ * localStorage (`tq-cookie-consent`) and a `tq-consent-change` event lets
8
+ * subscribers (pixels, analytics) react live to Accept/Decline/Manage.
9
+ *
10
+ * DENY-UNTIL-DECIDED IS THE DEFAULT (journey-matrix 0.5). This gate used to start
11
+ * "no banner required → everything allowed", set from the MERCHANT's toggle, so an EU
12
+ * shopper in a shop whose owner never enabled the banner was tracked with no consent,
13
+ * and so was everyone before shop data arrived. The mode is now decided by the SERVER
14
+ * from the shopper's jurisdiction (`shop.cookieBanner.mode`) and the merchant's toggle
15
+ * can only add protection. Until that verdict arrives the mode is OPT_IN.
16
+ *
17
+ * Gate semantics (`hasConsent`):
18
+ * - GPC signalled → MARKETING is denied in every mode, even after an accept-all (analytics unaffected).
19
+ * - mode NONE (no consent statute applies to this shopper) → allowed.
20
+ * - mode OPT_IN + undecided → denied (GDPR/ePrivacy/UK/CH/LGPD/PDPA/Quebec, and unknown location).
21
+ * - mode OPT_OUT + undecided → allowed, except MARKETING when the shopper sends
22
+ * Global Privacy Control (a decline without a click). US opt-out states.
23
+ * - decided → the stored purpose flag, in every mode.
24
+ */
25
+ const KEY = 'tq-cookie-consent';
26
+ const EVENT = 'tq-consent-change';
27
+ // Fail closed until the theme has the shop's verdict.
28
+ let mode = 'OPT_IN';
29
+ /**
30
+ * True once an AUTHORITATIVE verdict for THIS shopper has set the mode (the LIVE per-request answer). A snapshot or a
31
+ * default never arms it. The banner is shown only when armed — so a not-yet-armed gate is closed AND silent.
32
+ */
33
+ let armed = false;
34
+ const MODE_EVENT = 'tq-consent-mode';
35
+ const announce = () => {
36
+ try {
37
+ window.dispatchEvent(new CustomEvent(MODE_EVENT));
38
+ }
39
+ catch {
40
+ /* SSR / no window */
41
+ }
42
+ };
43
+ /** Set the mode from an authoritative (live) verdict. The ONLY way the gate opens — components must not call it. */
44
+ export function setConsentMode(m) {
45
+ mode = m;
46
+ armed = true;
47
+ announce();
48
+ }
49
+ /** Force the gate closed (OPT_IN) and un-armed — the SSG boot, until the live answer arrives. */
50
+ export function holdConsentClosed() {
51
+ mode = 'OPT_IN';
52
+ armed = false;
53
+ announce();
54
+ }
55
+ export function getConsentMode() {
56
+ return mode;
57
+ }
58
+ export function isConsentArmed() {
59
+ return armed;
60
+ }
61
+ /** Subscribe to mode/armed changes (banner display); returns an unsubscribe fn. */
62
+ export function onConsentModeChange(cb) {
63
+ try {
64
+ window.addEventListener(MODE_EVENT, cb);
65
+ return () => window.removeEventListener(MODE_EVENT, cb);
66
+ }
67
+ catch {
68
+ return () => { };
69
+ }
70
+ }
71
+ /** Back-compat for callers that only know a boolean: true → OPT_IN, false → NONE. */
72
+ export function setBannerRequired(v) {
73
+ setConsentMode(v ? 'OPT_IN' : 'NONE');
74
+ }
75
+ export function isBannerRequired() {
76
+ return mode !== 'NONE';
77
+ }
78
+ /**
79
+ * The mode for a loaded shop. The server's `cookieBanner.mode` is authoritative; an older API that only sends `enabled`
80
+ * is read as before (enabled → OPT_IN); anything missing or unrecognised is OPT_IN, never permissive.
81
+ */
82
+ export function consentModeFromShop(shop) {
83
+ const cb = shop
84
+ ?.cookieBanner;
85
+ if (!cb || typeof cb !== 'object')
86
+ return 'OPT_IN';
87
+ if (cb.mode === 'OPT_IN' || cb.mode === 'OPT_OUT' || cb.mode === 'NONE')
88
+ return cb.mode;
89
+ if (cb.mode !== undefined && cb.mode !== null)
90
+ return 'OPT_IN';
91
+ return cb.enabled ? 'OPT_IN' : 'NONE';
92
+ }
93
+ function gpcSignalled() {
94
+ try {
95
+ return navigator.globalPrivacyControl === true;
96
+ }
97
+ catch {
98
+ return false;
99
+ }
100
+ }
101
+ /** The stored decision, or null when the shopper hasn't chosen yet. */
102
+ export function getConsent() {
103
+ try {
104
+ const raw = localStorage.getItem(KEY);
105
+ if (!raw)
106
+ return null;
107
+ if (raw === 'accepted')
108
+ return { analytics: true, marketing: true };
109
+ if (raw === 'declined')
110
+ return { analytics: false, marketing: false };
111
+ const p = JSON.parse(raw);
112
+ return { analytics: !!p.analytics, marketing: !!p.marketing };
113
+ }
114
+ catch {
115
+ return null;
116
+ }
117
+ }
118
+ export function hasDecided() {
119
+ return getConsent() !== null;
120
+ }
121
+ export function setConsent(c) {
122
+ try {
123
+ localStorage.setItem(KEY, JSON.stringify(c));
124
+ }
125
+ catch {
126
+ /* private mode — the choice just won't persist across reloads */
127
+ }
128
+ try {
129
+ window.dispatchEvent(new CustomEvent(EVENT, { detail: c }));
130
+ }
131
+ catch {
132
+ /* SSR / no window */
133
+ }
134
+ }
135
+ /** True when `purpose` may run right now (see gate semantics above). */
136
+ export function hasConsent(purpose) {
137
+ // Global Privacy Control is honoured EVERYWHERE and beats even a stored "accept all": marketing is never allowed while
138
+ // the browser signals GPC (conservative reading, matches admin-api's "GPC always wins"; analytics is unaffected).
139
+ if (purpose === 'marketing' && gpcSignalled())
140
+ return false;
141
+ const c = getConsent();
142
+ // An explicit decision on this site beats every default.
143
+ if (c)
144
+ return c[purpose];
145
+ if (mode === 'NONE' || mode === 'OPT_OUT')
146
+ return true;
147
+ return false;
148
+ }
149
+ /** Subscribe to consent changes; returns an unsubscribe fn. */
150
+ export function onConsentChange(cb) {
151
+ const handler = (e) => cb(e.detail);
152
+ try {
153
+ window.addEventListener(EVENT, handler);
154
+ return () => window.removeEventListener(EVENT, handler);
155
+ }
156
+ catch {
157
+ return () => { };
158
+ }
159
+ }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * The content-tree contract: what a `templates/<slug>.json` may contain, and
3
+ * the node-identity rules every producer (Editor, AI, theme author) must follow.
4
+ *
5
+ * Node identity is the part that was never written down, and it is the part the
6
+ * round trip depends on. Today:
7
+ *
8
+ * - The Editor mints `${type}_${uuid8}` (`tanqory-template-context.tsx:379`)
9
+ * — stable and unique. Correct.
10
+ * - `blocksToStudio` (`editor-routes.mjs:49-62`) falls back to
11
+ * `` `${b.type}-${i}` `` for a block with no id — a POSITIONAL identity.
12
+ * Reorder the array on disk and `faq-item-0` now means a different question.
13
+ * - `themekitToStudio` falls back to `s.id ?? s.type` for a section — so two
14
+ * sections of the same type with no id COLLIDE in the `sections` map and the
15
+ * second silently overwrites the first.
16
+ *
17
+ * Both fallbacks are silent. Neither is safe for "AI edits one answer without
18
+ * clobbering the others", which is exactly what this contract has to make true.
19
+ * The rule below is therefore: **every node carries an explicit, stable id.**
20
+ */
21
+ /** A node in the content tree — a section instance or a child block. */
22
+ export interface ContractNode {
23
+ /** The section/block definition name this instantiates. */
24
+ type: string;
25
+ /** Stable identity. Required by this contract; see `mintNodeId`. */
26
+ id: string;
27
+ /**
28
+ * The merchant's own name for this node in the editor's outline ("Summer sale banner"), set with Rename. Editor
29
+ * metadata only: trimmed, 1 to {@link NODE_NAME_MAX_LENGTH} characters, absent when the node shows its type's name.
30
+ * It is never part of what a theme renders: the storefront's node (`SavedSection` / `SavedBlock`, the
31
+ * ContentRevision a publish exports) carries no name.
32
+ */
33
+ name?: string;
34
+ settings?: Record<string, unknown>;
35
+ blocks?: ContractNode[];
36
+ /**
37
+ * Layout slot. Nova's templates use this 43 times; nothing in the kit or the
38
+ * theme reads it, and the Editor's save round-trip currently DROPS it
39
+ * (neither `themekitToStudio` nor `studioToThemekit` mentions it).
40
+ * Declared here so it is a known key with known values — a converter that
41
+ * preserves the contract's keys preserves this one.
42
+ */
43
+ area?: TemplateArea;
44
+ }
45
+ export type TemplateArea = 'header' | 'template' | 'footer';
46
+ export declare const TEMPLATE_AREAS: readonly TemplateArea[];
47
+ /** A template document as stored at `templates/<slug>.json`. */
48
+ export interface ContractPageDoc {
49
+ sections: ContractNode[];
50
+ /**
51
+ * Content-format version.
52
+ * absent / 1 — inline header + footer sections in every template (legacy;
53
+ * still fully supported, resolved as an implicit per-page copy)
54
+ * 2 — `groups` bindings: header/footer come from a shared
55
+ * `groups/<name>.json` unless the page overrides them.
56
+ * A future shape change bumps this and gets a migration, instead of silently
57
+ * orphaning a merchant's customisation the way a path-prefix merge does.
58
+ */
59
+ contentVersion?: number;
60
+ /**
61
+ * Shared-slot bindings (content version 2). See `groups.ts` for the shape.
62
+ * Declared here as `unknown` so the base document type stays independent of
63
+ * the group module; `GroupedPageDoc` narrows it.
64
+ */
65
+ groups?: unknown;
66
+ }
67
+ export declare const CURRENT_CONTENT_VERSION = 2;
68
+ /**
69
+ * App blocks (theme-abi-v2.md §7.2 "App blocks (`@app`)"). A section or block that lists {@link APP_BLOCKS} in its
70
+ * `allowedBlocks` (manifest `component.children`) accepts the blocks of the apps installed on the store. Such a node's
71
+ * type is `app:<appHandle>/<blockHandle>` and it is a leaf: it is never looked up in the theme's catalogue, and its
72
+ * settings are checked against the app block's own settings definition. A layout section cannot list it.
73
+ */
74
+ export declare const APP_BLOCKS = "@app";
75
+ /** `app:<appHandle>/<blockHandle>`: each part 1-64 lower-case letters, digits or hyphens. */
76
+ export declare const APP_BLOCK_TYPE_PATTERN: RegExp;
77
+ /** Whether a node type names an app block. */
78
+ export declare function isAppBlockType(type: unknown): boolean;
79
+ /** Whether a list of accepted block types (`allowedBlocks`, `schema.blocks`) accepts app blocks. */
80
+ export declare function acceptsAppBlocks(allowed: readonly string[] | undefined | null): boolean;
81
+ /**
82
+ * What the validator knows about one app block the store can use (the editor reads it from the installed apps): its
83
+ * settings definition, in the same field-type registry as a theme's attributes.
84
+ */
85
+ export interface AppBlockContract {
86
+ /** `app:<appHandle>/<blockHandle>`. */
87
+ type: string;
88
+ /** The name the editor shows. */
89
+ name?: string;
90
+ settings: Record<string, AttrContract>;
91
+ }
92
+ /**
93
+ * Node ids must be URL-safe, stable across saves, and unique within their
94
+ * parent. Readable prefixes are deliberate: `faq-item_a1b2c3d4` is greppable in
95
+ * a diff, which matters when the thing being diffed is a merchant's content.
96
+ */
97
+ export declare const NODE_ID_PATTERN: RegExp;
98
+ /** Longest custom node name the editor stores (`ContractNode.name`). */
99
+ export declare const NODE_NAME_MAX_LENGTH = 100;
100
+ /** Whether `name` is a storable node name: a string, trimmed, 1 to NODE_NAME_MAX_LENGTH characters. */
101
+ export declare function isValidNodeName(name: unknown): name is string;
102
+ /**
103
+ * Mint a stable node id. Matches the Editor's own scheme
104
+ * (`tanqory-template-context.tsx:379`) so a node authored by AI and a node
105
+ * authored by a human are indistinguishable downstream.
106
+ */
107
+ export declare function mintNodeId(type: string, rand?: () => string): string;
108
+ /**
109
+ * What a section definition promises. This is `SectionDef` minus `component` —
110
+ * the serialisable half — plus the two things the platform needs and no
111
+ * existing artifact carries: the context a section requires, and which runtimes
112
+ * it works against.
113
+ */
114
+ export interface SectionContract {
115
+ name: string;
116
+ title: string;
117
+ /** One line for the inserter; see `SectionDef.description`. */
118
+ description?: string;
119
+ category?: string;
120
+ icon?: string;
121
+ attributes: Record<string, AttrContract>;
122
+ /** Block types that may nest inside. Empty/absent = a leaf section. */
123
+ allowedBlocks?: string[];
124
+ /** Starting compositions. `presets[0]` is what the inserter should seed. */
125
+ presets?: SectionPresetContract[];
126
+ /**
127
+ * Route context the section needs to render meaningfully — e.g. a PDP section
128
+ * needs `product`. When the validator is told which context the template
129
+ * provides, placing a section outside its context is an ERROR (the section
130
+ * would render a not-found state on every visit); with no context supplied
131
+ * it degrades to a warning, since the caller has not said where this is.
132
+ */
133
+ requiresContext?: readonly ContextKind[];
134
+ /**
135
+ * What kind of unit this is. Explicit, because `category` is a DISPLAY
136
+ * grouping for the inserter and was being read as a placement rule
137
+ * (`category === 'block'` decided which picker offered it).
138
+ * section — a top-level page unit
139
+ * block — only nests inside a parent that lists it in `allowedBlocks`
140
+ * layout — chrome: header/footer/announcement; lives in a shared group
141
+ * Absent = derived: `category: 'block'` → block; `area` declared → layout;
142
+ * otherwise section.
143
+ */
144
+ role?: SectionRole;
145
+ /**
146
+ * Default slot for a layout section — where the editor files it when added
147
+ * without one, and where the AI should place it. Also the only slot it may
148
+ * be placed in unless `placement.areas` widens that.
149
+ */
150
+ area?: TemplateArea;
151
+ /** Where this unit may be placed. Every list is an allowlist; absent = anywhere of its role. */
152
+ placement?: PlacementContract;
153
+ }
154
+ export type SectionRole = 'section' | 'block' | 'layout';
155
+ export declare const SECTION_ROLES: readonly SectionRole[];
156
+ export interface PlacementContract {
157
+ /** Slots this unit may occupy. A block ignores this (its parent decides). */
158
+ areas?: readonly TemplateArea[];
159
+ /** Base template slugs (`product`, `collection`, …) it may appear on. */
160
+ templates?: readonly string[];
161
+ /** For a block: the parent types that may host it (mirrors the parents' `allowedBlocks`). */
162
+ parents?: readonly string[];
163
+ }
164
+ /** The effective role, applying the documented fallbacks for definitions that predate `role`. */
165
+ export declare function roleOf(def: Pick<SectionContract, 'role' | 'category' | 'area' | 'name'>): SectionRole;
166
+ /**
167
+ * The route context a template provides, from its base slug. `product.bundle`
168
+ * is still a product page. Used as the validator's default `context` when a
169
+ * caller names the template rather than listing kinds by hand.
170
+ */
171
+ export declare function templateContext(slug: string): ContextKind[];
172
+ export type ContextKind = 'product' | 'collection' | 'page' | 'blog' | 'article' | 'cart' | 'search' | 'customer' | 'policy';
173
+ export declare const CONTEXT_KINDS: readonly ContextKind[];
174
+ export interface SectionPresetContract {
175
+ name?: string;
176
+ settings?: Record<string, unknown>;
177
+ blocks?: Array<Omit<ContractNode, 'id'> & {
178
+ id?: string;
179
+ }>;
180
+ }
181
+ /** One editor-facing setting. Mirrors `AttrSpec`, stated structurally. */
182
+ export interface AttrContract {
183
+ type: string;
184
+ default?: unknown;
185
+ label?: string;
186
+ info?: string;
187
+ placeholder?: string;
188
+ group?: string;
189
+ dynamic?: boolean;
190
+ visible_if?: string | Record<string, unknown>;
191
+ min?: number;
192
+ max?: number;
193
+ step?: number;
194
+ unit?: string;
195
+ options?: Array<{
196
+ value: string;
197
+ label: string;
198
+ }>;
199
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The content-tree contract: what a `templates/<slug>.json` may contain, and
3
+ * the node-identity rules every producer (Editor, AI, theme author) must follow.
4
+ *
5
+ * Node identity is the part that was never written down, and it is the part the
6
+ * round trip depends on. Today:
7
+ *
8
+ * - The Editor mints `${type}_${uuid8}` (`tanqory-template-context.tsx:379`)
9
+ * — stable and unique. Correct.
10
+ * - `blocksToStudio` (`editor-routes.mjs:49-62`) falls back to
11
+ * `` `${b.type}-${i}` `` for a block with no id — a POSITIONAL identity.
12
+ * Reorder the array on disk and `faq-item-0` now means a different question.
13
+ * - `themekitToStudio` falls back to `s.id ?? s.type` for a section — so two
14
+ * sections of the same type with no id COLLIDE in the `sections` map and the
15
+ * second silently overwrites the first.
16
+ *
17
+ * Both fallbacks are silent. Neither is safe for "AI edits one answer without
18
+ * clobbering the others", which is exactly what this contract has to make true.
19
+ * The rule below is therefore: **every node carries an explicit, stable id.**
20
+ */
21
+ export const TEMPLATE_AREAS = ['header', 'template', 'footer'];
22
+ export const CURRENT_CONTENT_VERSION = 2;
23
+ /**
24
+ * App blocks (theme-abi-v2.md §7.2 "App blocks (`@app`)"). A section or block that lists {@link APP_BLOCKS} in its
25
+ * `allowedBlocks` (manifest `component.children`) accepts the blocks of the apps installed on the store. Such a node's
26
+ * type is `app:<appHandle>/<blockHandle>` and it is a leaf: it is never looked up in the theme's catalogue, and its
27
+ * settings are checked against the app block's own settings definition. A layout section cannot list it.
28
+ */
29
+ export const APP_BLOCKS = '@app';
30
+ /** `app:<appHandle>/<blockHandle>`: each part 1-64 lower-case letters, digits or hyphens. */
31
+ export const APP_BLOCK_TYPE_PATTERN = /^app:([a-z0-9][a-z0-9-]{0,63})\/([a-z0-9][a-z0-9-]{0,63})$/;
32
+ /** Whether a node type names an app block. */
33
+ export function isAppBlockType(type) {
34
+ return typeof type === 'string' && APP_BLOCK_TYPE_PATTERN.test(type);
35
+ }
36
+ /** Whether a list of accepted block types (`allowedBlocks`, `schema.blocks`) accepts app blocks. */
37
+ export function acceptsAppBlocks(allowed) {
38
+ return Array.isArray(allowed) && allowed.includes(APP_BLOCKS);
39
+ }
40
+ /**
41
+ * Node ids must be URL-safe, stable across saves, and unique within their
42
+ * parent. Readable prefixes are deliberate: `faq-item_a1b2c3d4` is greppable in
43
+ * a diff, which matters when the thing being diffed is a merchant's content.
44
+ */
45
+ export const NODE_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
46
+ /** Longest custom node name the editor stores (`ContractNode.name`). */
47
+ export const NODE_NAME_MAX_LENGTH = 100;
48
+ /** Whether `name` is a storable node name: a string, trimmed, 1 to NODE_NAME_MAX_LENGTH characters. */
49
+ export function isValidNodeName(name) {
50
+ return typeof name === 'string' && name.length > 0 && name.length <= NODE_NAME_MAX_LENGTH && name === name.trim();
51
+ }
52
+ /**
53
+ * Mint a stable node id. Matches the Editor's own scheme
54
+ * (`tanqory-template-context.tsx:379`) so a node authored by AI and a node
55
+ * authored by a human are indistinguishable downstream.
56
+ */
57
+ export function mintNodeId(type, rand = defaultRand) {
58
+ const base = String(type).replace(/[^a-z0-9]/gi, '-').replace(/^-+|-+$/g, '') || 'node';
59
+ return `${base}_${rand()}`;
60
+ }
61
+ function defaultRand() {
62
+ const c = globalThis.crypto;
63
+ if (c?.randomUUID)
64
+ return c.randomUUID().slice(0, 8);
65
+ return Math.random().toString(36).slice(2, 10).padEnd(8, '0');
66
+ }
67
+ export const SECTION_ROLES = ['section', 'block', 'layout'];
68
+ /** The effective role, applying the documented fallbacks for definitions that predate `role`. */
69
+ export function roleOf(def) {
70
+ if (def.role)
71
+ return def.role;
72
+ if (def.category === 'block')
73
+ return 'block';
74
+ if (def.area === 'header' || def.area === 'footer')
75
+ return 'layout';
76
+ if (def.name === 'header' || def.name === 'footer')
77
+ return 'layout';
78
+ return 'section';
79
+ }
80
+ /**
81
+ * The route context a template provides, from its base slug. `product.bundle`
82
+ * is still a product page. Used as the validator's default `context` when a
83
+ * caller names the template rather than listing kinds by hand.
84
+ */
85
+ export function templateContext(slug) {
86
+ const base = String(slug ?? '').split('.')[0] ?? '';
87
+ switch (base) {
88
+ case 'product': return ['product'];
89
+ case 'collection': return ['collection'];
90
+ case 'page': return ['page'];
91
+ case 'blog': return ['blog'];
92
+ case 'article': return ['article', 'blog'];
93
+ case 'cart': return ['cart'];
94
+ case 'search': return ['search'];
95
+ // A signed-in customer exists only on the account template; a policy body
96
+ // only under /policies/*. Sections that read them (AccountPage, PolicyPage)
97
+ // declared nothing, so the editor offered them everywhere and previewed
98
+ // them as "Loading your account…" forever — there was nothing to load.
99
+ case 'account': return ['customer'];
100
+ case 'policy': return ['policy'];
101
+ default: return [];
102
+ }
103
+ }
104
+ export const CONTEXT_KINDS = [
105
+ 'product', 'collection', 'page', 'blog', 'article', 'cart', 'search', 'customer', 'policy',
106
+ ];