@eldrajs/vite-plugin-theme 0.1.0 → 0.3.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,40 @@ Release-please writes the generated notes from commit messages and does not repl
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ - **`formSeeds[].actions.subscribe.consentText` (WS-386).** A subscribe action may carry its consent
9
+ sentence per locale (`{ 'en-US': '… {shop} …' }`), validated like Core: locale tags, at most 500
10
+ characters each, plain text (no `<`, `>` or control characters), at least one locale when the key is
11
+ present. Left out, Core fills in its platform default on create, so existing seeds keep working.
12
+
13
+ - **Form seed field types `number` and `url` (WS-386).** `validateFormSeeds` and
14
+ `ManifestFormSeedFieldType` list every type Core accepts: `text`, `email`, `phone`, `textarea`,
15
+ `select`, `checkbox`, `consent`, `number`, `url`. `number` and `url` take `validation` like `text`.
16
+
17
+ - **`formSeeds` cannot reference an email template (WS-386).** Core now refuses a form action that
18
+ would send anything but a form design or the organisation's own custom template. A seed's
19
+ `notify`/`confirm` are flags and `subscribe` takes only `{ list }`, so a seed can only ever use the
20
+ platform form designs; `validateFormSeeds` rejects a `templateRef` (object in place of a flag, or an
21
+ unknown key) as a scan error. No behaviour change for valid seeds; the starter's seeds are unaffected.
22
+ - **`formSeeds`: the forms a site starts with (WS-386).** A new `eldra.formSeeds` option (and
23
+ `ScanOptions.formSeeds`) declares up to eight forms, `{ key, name, fields, actions, success }`, with a
24
+ label per locale on every field. `validateFormSeeds` (exported) refuses what Core refuses — a key
25
+ outside `^[a-z][a-z0-9-]{0,39}$` or the reserved `subscriptions`, duplicate keys or field ids, an
26
+ unknown field type, a `select` with no options, a bad `pattern`, `confirm`/`subscribe` without an
27
+ email field, an unknown key at any level — as scan errors. The manifest carries `formSeeds` only when
28
+ the theme declares some, so a theme that seeds none emits the manifest it always has. New types
29
+ `ManifestFormSeed`, `ManifestFormSeedField`, `ManifestFormSeedFieldType`, `DeclaredFormSeed`.
30
+ Needs a Core whose manifest ingest accepts `formSeeds` (contract 4.4.0).
31
+ - **Breaking:** a theme must declare its id in `package.json` under `eldra.themeId`
32
+ (`^[a-z][a-z0-9-]{1,48}$`, `catalog` reserved). The scanner emits it as `manifest.theme.id` and
33
+ `manifestVersion` is now `2` (`ThemeManifest.manifestVersion: 2`, `theme.id: string`). A missing
34
+ or invalid id is a scan error, so the plugin build, `eldra-theme validate` and
35
+ `eldra-theme deploy` fail naming `package.json: eldra.themeId`; there is no derivation from the
36
+ package name and no v1 manifest is produced. Core stores a theme's block schemas as
37
+ `<themeId>:<blockApiId>`; block ids in `block.json` and the manifest stay bare.
38
+ A v1 `.eldra/manifest.json` left on disk from an earlier build is rejected as the previous
39
+ manifest (`previous manifest: expected manifestVersion 2`): delete it once before the first build
40
+ after upgrading. See `docs/themes.md`'s "Theme id and schema ownership".
41
+
8
42
  - The scanner now reads a theme's own message catalogue: `i18n/<tag>.json`, siblings of
9
43
  `tokens.json`, one file per locale, each a nested JSON object of strings that gets flattened to
10
44
  dotted keys (`header.menu`, `cart.empty.title`). It validates key grammar/length, value
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ThemeManifest, C as ScanOptions, D as TemplateSeedLayoutNode, E as TemplateSeedLayout, O as TemplateSeedReusableNode, S as PageSeedTarget, T as TemplateSeedBlockNode, _ as ManifestPageSeedRegion, a as DeclaredPageSeedBlock, b as ManifestTemplateSeed, c as DeclaredSeed, d as DeclaredThemeCodePage, f as EldraThemeOptions, g as ManifestPageSeedEntry, h as ManifestPageSeedBlock, i as DeclaredPageSeed, j as ThemeMessages, k as TemplateSeedSchemaApiId, l as DeclaredTemplateSeed, m as ManifestPageSeed, n as BlockField, o as DeclaredPageSeedEntry, p as LegacyThemeTokens, r as BlockMigration, s as DeclaredPageSeedRegion, t as BlockDefinition, u as DeclaredTemplateSeedBlock, v as ManifestRoute, w as ScanResult, x as ManifestTemplateSeedBlock, y as ManifestTemplateRoles } from "./types-BRNXfpXW.js";
1
+ import { A as TemplateSeedLayout, C as ManifestTemplateRoles, D as ScanOptions, E as PageSeedTarget, F as ThemeMessages, M as TemplateSeedReusableNode, N as TemplateSeedSchemaApiId, O as ScanResult, P as ThemeManifest, S as ManifestRoute, T as ManifestTemplateSeedBlock, _ as ManifestFormSeedFieldType, a as DeclaredPageSeed, b as ManifestPageSeedEntry, c as DeclaredPageSeedRegion, d as DeclaredTemplateSeedBlock, f as DeclaredThemeCodePage, g as ManifestFormSeedField, h as ManifestFormSeed, i as DeclaredFormSeed, j as TemplateSeedLayoutNode, k as TemplateSeedBlockNode, l as DeclaredSeed, m as LegacyThemeTokens, n as BlockField, o as DeclaredPageSeedBlock, p as EldraThemeOptions, r as BlockMigration, s as DeclaredPageSeedEntry, t as BlockDefinition, u as DeclaredTemplateSeed, v as ManifestPageSeed, w as ManifestTemplateSeed, x as ManifestPageSeedRegion, y as ManifestPageSeedBlock } from "./types-d9173MhL.js";
2
2
  import { Plugin } from "vite";
3
3
  //#region src/plugin.d.ts
4
4
  export default function eldraTheme(options?: EldraThemeOptions): Plugin;
@@ -6,6 +6,19 @@ export default function eldraTheme(options?: EldraThemeOptions): Plugin;
6
6
  //#region src/blockTypes.d.ts
7
7
  export declare function generateBlockTypes(blocks: BlockDefinition[], messages?: ThemeMessages): string;
8
8
  //#endregion
9
+ //#region src/formSeeds.d.ts
10
+ /**
11
+ * Validates the declared `formSeeds`: the forms a site is created with, ingested by Core's
12
+ * `site_forms` seeding. It rejects an unknown key outright and enforces the wire contract
13
+ * agreed for WS-386 (key and field-id grammar, field types, option and length caps). It mirrors
14
+ * Core's `normalizeFormInput` exactly — anything Core refuses fails the whole manifest sync, so a
15
+ * rule changed on the Core side must be changed here too. A merchant-edited form is never
16
+ * overwritten by a later version of a seed (Core's `editedByMerchant` flag).
17
+ *
18
+ * Absent (`undefined`) and empty both mean "this theme seeds no forms".
19
+ */
20
+ export declare function validateFormSeeds(seeds: ReadonlyArray<DeclaredFormSeed> | undefined, errors: string[]): ManifestFormSeed[];
21
+ //#endregion
9
22
  //#region src/templates.d.ts
10
23
  /**
11
24
  * The layout a seed gets when it declares none: one column of its blocks in
@@ -71,4 +84,4 @@ export declare function validatePageSeeds(seeds: ReadonlyArray<DeclaredSeed>, bl
71
84
  */
72
85
  export declare function validateTemplateRoles(roles: ManifestTemplateRoles | undefined, blocks: ReadonlyArray<Record<string, unknown>>, templates: ReadonlyArray<ManifestTemplateSeed>, errors: string[]): ManifestTemplateRoles | undefined;
73
86
  //#endregion
74
- export type { BlockDefinition, BlockField, BlockMigration, DeclaredPageSeed, DeclaredPageSeedBlock, DeclaredPageSeedEntry, DeclaredPageSeedRegion, DeclaredSeed, DeclaredTemplateSeed, DeclaredTemplateSeedBlock, DeclaredThemeCodePage, EldraThemeOptions, LegacyThemeTokens, ManifestPageSeed, ManifestPageSeedBlock, ManifestPageSeedEntry, ManifestPageSeedRegion, ManifestRoute, ManifestTemplateRoles, ManifestTemplateSeed, ManifestTemplateSeedBlock, PageSeedTarget, ScanOptions, ScanResult, TemplateSeedBlockNode, TemplateSeedLayout, TemplateSeedLayoutNode, TemplateSeedReusableNode, TemplateSeedSchemaApiId, ThemeManifest, ThemeMessages };
87
+ export type { BlockDefinition, BlockField, BlockMigration, DeclaredFormSeed, DeclaredPageSeed, DeclaredPageSeedBlock, DeclaredPageSeedEntry, DeclaredPageSeedRegion, DeclaredSeed, DeclaredTemplateSeed, DeclaredTemplateSeedBlock, DeclaredThemeCodePage, EldraThemeOptions, LegacyThemeTokens, ManifestFormSeed, ManifestFormSeedField, ManifestFormSeedFieldType, ManifestPageSeed, ManifestPageSeedBlock, ManifestPageSeedEntry, ManifestPageSeedRegion, ManifestRoute, ManifestTemplateRoles, ManifestTemplateSeed, ManifestTemplateSeedBlock, PageSeedTarget, ScanOptions, ScanResult, TemplateSeedBlockNode, TemplateSeedLayout, TemplateSeedLayoutNode, TemplateSeedReusableNode, TemplateSeedSchemaApiId, ThemeManifest, ThemeMessages };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as validateTemplateRoles, i as validatePageSeeds, n as scanTheme, o as validateTemplateSeeds, r as seedLayout, t as readPreviousManifest } from "./scan-DjW4f_E8.js";
1
+ import { a as validateTemplateRoles, i as validatePageSeeds, n as scanTheme, o as validateTemplateSeeds, r as seedLayout, s as validateFormSeeds, t as readPreviousManifest } from "./scan-B4nn0SQj.js";
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { dirname, join, relative } from "node:path";
4
4
  import { generateDesignTokenCss, generateTailwindThemeCss, normalizeThemeDesignTokens } from "@eldrajs/theme-core/design-tokens";
@@ -249,6 +249,7 @@ function eldraTheme(options = {}) {
249
249
  customPages: options.customPages,
250
250
  templates: options.templates,
251
251
  templateRoles: options.templateRoles,
252
+ formSeeds: options.formSeeds,
252
253
  breakpoints: options.breakpoints
253
254
  });
254
255
  scan.errors.unshift(...historyErrors);
@@ -449,4 +450,4 @@ function findJsonStringEnd(text, start) {
449
450
  return i;
450
451
  }
451
452
  //#endregion
452
- export { eldraTheme as default, generateBlockTypes, seedLayout, validatePageSeeds, validateTemplateRoles, validateTemplateSeeds };
453
+ export { eldraTheme as default, generateBlockTypes, seedLayout, validateFormSeeds, validatePageSeeds, validateTemplateRoles, validateTemplateSeeds };
@@ -4,11 +4,11 @@ import { dirname, join, relative } from "node:path";
4
4
  import { DesignTokenValidationError, normalizeThemeDesignTokens } from "@eldrajs/theme-core/design-tokens";
5
5
  import { resolveLayoutBreakpoints } from "@eldrajs/theme-core/layout";
6
6
  import Ajv from "ajv";
7
- import { RICH_TEXT_TOOLBAR_CONTROLS, parseDynamicRoutePattern } from "@eldrajs/theme-core";
7
+ import { RESERVED_THEME_IDS, RICH_TEXT_TOOLBAR_CONTROLS, THEME_ID_PATTERN, parseDynamicRoutePattern } from "@eldrajs/theme-core";
8
8
  import { safeLinkHref } from "@eldrajs/theme-core/links";
9
9
  //#region src/blockSchema.ts
10
10
  const API_ID_PATTERN = "^[a-z][a-z0-9-]{1,48}$";
11
- const FIELD_ID_PATTERN = "^[a-z][a-zA-Z0-9]{0,48}$";
11
+ const FIELD_ID_PATTERN$1 = "^[a-z][a-zA-Z0-9]{0,48}$";
12
12
  const blockJsonSchema = {
13
13
  $schema: "http://json-schema.org/draft-07/schema#",
14
14
  type: "object",
@@ -60,7 +60,7 @@ const blockJsonSchema = {
60
60
  properties: {
61
61
  groupId: {
62
62
  type: "string",
63
- pattern: FIELD_ID_PATTERN
63
+ pattern: FIELD_ID_PATTERN$1
64
64
  },
65
65
  name: {
66
66
  type: "string",
@@ -101,11 +101,11 @@ const blockJsonSchema = {
101
101
  properties: {
102
102
  from: {
103
103
  type: "string",
104
- pattern: FIELD_ID_PATTERN
104
+ pattern: FIELD_ID_PATTERN$1
105
105
  },
106
106
  to: {
107
107
  type: "string",
108
- pattern: FIELD_ID_PATTERN
108
+ pattern: FIELD_ID_PATTERN$1
109
109
  }
110
110
  }
111
111
  }
@@ -124,11 +124,11 @@ const blockJsonSchema = {
124
124
  properties: {
125
125
  from: {
126
126
  type: "string",
127
- pattern: FIELD_ID_PATTERN
127
+ pattern: FIELD_ID_PATTERN$1
128
128
  },
129
129
  to: {
130
130
  type: "string",
131
- pattern: FIELD_ID_PATTERN
131
+ pattern: FIELD_ID_PATTERN$1
132
132
  },
133
133
  shape: {
134
134
  type: "string",
@@ -136,15 +136,15 @@ const blockJsonSchema = {
136
136
  },
137
137
  label: {
138
138
  type: "string",
139
- pattern: FIELD_ID_PATTERN
139
+ pattern: FIELD_ID_PATTERN$1
140
140
  },
141
141
  url: {
142
142
  type: "string",
143
- pattern: FIELD_ID_PATTERN
143
+ pattern: FIELD_ID_PATTERN$1
144
144
  },
145
145
  group: {
146
146
  type: "string",
147
- pattern: FIELD_ID_PATTERN
147
+ pattern: FIELD_ID_PATTERN$1
148
148
  },
149
149
  children: {
150
150
  type: "object",
@@ -153,19 +153,19 @@ const blockJsonSchema = {
153
153
  properties: {
154
154
  from: {
155
155
  type: "string",
156
- pattern: FIELD_ID_PATTERN
156
+ pattern: FIELD_ID_PATTERN$1
157
157
  },
158
158
  label: {
159
159
  type: "string",
160
- pattern: FIELD_ID_PATTERN
160
+ pattern: FIELD_ID_PATTERN$1
161
161
  },
162
162
  url: {
163
163
  type: "string",
164
- pattern: FIELD_ID_PATTERN
164
+ pattern: FIELD_ID_PATTERN$1
165
165
  },
166
166
  group: {
167
167
  type: "string",
168
- pattern: FIELD_ID_PATTERN
168
+ pattern: FIELD_ID_PATTERN$1
169
169
  }
170
170
  }
171
171
  }
@@ -185,7 +185,7 @@ const blockJsonSchema = {
185
185
  properties: {
186
186
  fieldId: {
187
187
  type: "string",
188
- pattern: FIELD_ID_PATTERN
188
+ pattern: FIELD_ID_PATTERN$1
189
189
  },
190
190
  name: {
191
191
  type: "string",
@@ -210,7 +210,7 @@ const blockJsonSchema = {
210
210
  properties: {
211
211
  field: {
212
212
  type: "string",
213
- pattern: FIELD_ID_PATTERN
213
+ pattern: FIELD_ID_PATTERN$1
214
214
  },
215
215
  in: {
216
216
  type: "array",
@@ -831,6 +831,332 @@ function validLinkTarget(target, kind) {
831
831
  return keys.every((key) => LINK_SLUG_KEYS.has(key)) && LINK_SLUG_TYPES.has(kind) && typeof target.slug === "string" && target.slug.trim() !== "";
832
832
  }
833
833
  //#endregion
834
+ //#region src/formSeeds.ts
835
+ const MAX_FORM_SEEDS = 8;
836
+ const MAX_FIELDS = 30;
837
+ const MAX_OPTIONS = 50;
838
+ const MAX_NAME_LENGTH = 80;
839
+ const MAX_TEXT_LENGTH = 200;
840
+ const MAX_MESSAGE_LENGTH = 1e3;
841
+ /** Core's cap on a subscribe action's consent sentence, per locale. */
842
+ const MAX_CONSENT_TEXT_LENGTH = 500;
843
+ /** Core's form key rule: a URL segment, and never the reserved `subscriptions` route. */
844
+ const FORM_KEY_PATTERN = /^[a-z][a-z0-9-]{0,39}$/;
845
+ const RESERVED_FORM_KEY = "subscriptions";
846
+ /** A field id is the key of a submission value, so it stays a plain identifier. */
847
+ const FIELD_ID_PATTERN = /^[a-zA-Z][a-zA-Z0-9_]{0,39}$/;
848
+ const OPTION_VALUE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
849
+ const LOCALE_TAG_PATTERN$1 = /^[a-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/;
850
+ const LIST_KEY_PATTERN = /^[a-z][a-z0-9-]{0,39}$/;
851
+ /** A field id Core reserves (it names the whole submission in its own routes). */
852
+ const RESERVED_FIELD_ID = "all";
853
+ /** Core's cap on `minLength` / `maxLength`. */
854
+ const MAX_VALIDATION_LENGTH = 8e3;
855
+ /** The field types that take a `validation` block; Core refuses it on the rest. */
856
+ const VALIDATION_TYPES = /* @__PURE__ */ new Set([
857
+ "text",
858
+ "email",
859
+ "phone",
860
+ "textarea",
861
+ "number",
862
+ "url"
863
+ ]);
864
+ const FIELD_TYPES = /* @__PURE__ */ new Set([
865
+ "text",
866
+ "email",
867
+ "phone",
868
+ "textarea",
869
+ "select",
870
+ "checkbox",
871
+ "consent",
872
+ "number",
873
+ "url"
874
+ ]);
875
+ const SEED_KEYS = /* @__PURE__ */ new Set([
876
+ "key",
877
+ "name",
878
+ "fields",
879
+ "actions",
880
+ "success"
881
+ ]);
882
+ const FIELD_KEYS = /* @__PURE__ */ new Set([
883
+ "id",
884
+ "type",
885
+ "required",
886
+ "label",
887
+ "placeholder",
888
+ "options",
889
+ "validation"
890
+ ]);
891
+ const ACTION_KEYS = /* @__PURE__ */ new Set([
892
+ "notify",
893
+ "confirm",
894
+ "subscribe"
895
+ ]);
896
+ const SUCCESS_KEYS = /* @__PURE__ */ new Set(["message", "redirect"]);
897
+ const VALIDATION_KEYS = /* @__PURE__ */ new Set([
898
+ "minLength",
899
+ "maxLength",
900
+ "pattern"
901
+ ]);
902
+ function unknownKeys(at, value, allowed, errors) {
903
+ for (const key of Object.keys(value)) if (!allowed.has(key)) errors.push(`${at}.${key} — unknown key`);
904
+ }
905
+ /** A `{ <locale>: text }` map: at least one locale, every tag well-formed, every text non-empty. */
906
+ function localizedText(at, value, maxLength, errors) {
907
+ if (!isRecord(value) || Object.keys(value).length === 0) {
908
+ errors.push(`${at} — must map at least one locale tag to text`);
909
+ return null;
910
+ }
911
+ const out = {};
912
+ for (const [locale, text] of Object.entries(value)) {
913
+ if (!LOCALE_TAG_PATTERN$1.test(locale)) {
914
+ errors.push(`${at}.${locale} — not a locale tag (expected something like "en-US")`);
915
+ continue;
916
+ }
917
+ const clean = stripPlainTextControls(text).trim();
918
+ if (clean === "" || codePointLength(clean) > maxLength) {
919
+ errors.push(`${at}.${locale} — must contain 1..${maxLength} characters`);
920
+ continue;
921
+ }
922
+ out[locale] = clean;
923
+ }
924
+ return out;
925
+ }
926
+ /**
927
+ * Core compiles `pattern` as RE2 (`^(?:pattern)$`), which has no lookaround and no
928
+ * backreferences; a JS `RegExp` accepts both, so they are refused here by scanning for them
929
+ * outside character classes and escapes. Returns what was found, or `null`.
930
+ */
931
+ function nonRe2Construct(pattern) {
932
+ let inClass = false;
933
+ for (let i = 0; i < pattern.length; i += 1) {
934
+ const char = pattern[i];
935
+ if (char === "\\") {
936
+ const next = pattern[i + 1] ?? "";
937
+ if (!inClass && (/[1-9]/.test(next) || next === "k")) return "a backreference";
938
+ i += 1;
939
+ } else if (inClass) {
940
+ if (char === "]") inClass = false;
941
+ } else if (char === "[") {
942
+ inClass = true;
943
+ if (pattern[i + 1] === "^") i += 1;
944
+ if (pattern[i + 1] === "]") i += 1;
945
+ } else if (char === "(" && pattern[i + 1] === "?") {
946
+ const rest = pattern.slice(i + 2, i + 4);
947
+ if (rest.startsWith("=") || rest.startsWith("!") || rest === "<=" || rest === "<!") return "a lookaround";
948
+ if (rest.startsWith(">")) return "an atomic group";
949
+ }
950
+ }
951
+ return null;
952
+ }
953
+ function validateField(at, entry, errors) {
954
+ if (!isRecord(entry)) {
955
+ errors.push(`${at} — must be a field object`);
956
+ return null;
957
+ }
958
+ unknownKeys(at, entry, FIELD_KEYS, errors);
959
+ const id = typeof entry.id === "string" ? entry.id : "";
960
+ if (id.toLowerCase() === RESERVED_FIELD_ID) errors.push(`${at}.id — "${RESERVED_FIELD_ID}" is reserved`);
961
+ else if (!FIELD_ID_PATTERN.test(id)) errors.push(`${at}.id — invalid id ${JSON.stringify(entry.id)} (expected ${FIELD_ID_PATTERN.source})`);
962
+ const type = typeof entry.type === "string" ? entry.type : "";
963
+ if (!FIELD_TYPES.has(type)) errors.push(`${at}.type — must be one of ${[...FIELD_TYPES].join(", ")}`);
964
+ if (typeof entry.required !== "boolean") errors.push(`${at}.required — must be true or false`);
965
+ const label = localizedText(`${at}.label`, entry.label, MAX_TEXT_LENGTH, errors);
966
+ const field = {
967
+ id,
968
+ type,
969
+ required: entry.required === true,
970
+ label: label ?? {}
971
+ };
972
+ if (entry.placeholder !== void 0) {
973
+ const placeholder = localizedText(`${at}.placeholder`, entry.placeholder, MAX_TEXT_LENGTH, errors);
974
+ if (placeholder !== null) field.placeholder = placeholder;
975
+ }
976
+ if (type === "select") {
977
+ const options = Array.isArray(entry.options) ? entry.options : [];
978
+ if (options.length < 1 || options.length > MAX_OPTIONS) errors.push(`${at}.options — a select declares 1..${MAX_OPTIONS} options`);
979
+ const seen = /* @__PURE__ */ new Set();
980
+ field.options = [];
981
+ for (const [index, option] of options.slice(0, MAX_OPTIONS).entries()) {
982
+ const optionAt = `${at}.options[${index}]`;
983
+ if (!isRecord(option)) {
984
+ errors.push(`${optionAt} — must be { value, label }`);
985
+ continue;
986
+ }
987
+ unknownKeys(optionAt, option, /* @__PURE__ */ new Set(["value", "label"]), errors);
988
+ const value = typeof option.value === "string" ? option.value : "";
989
+ if (!OPTION_VALUE_PATTERN.test(value)) errors.push(`${optionAt}.value — invalid value ${JSON.stringify(option.value)}`);
990
+ else if (seen.has(value)) errors.push(`${optionAt}.value — duplicate value ${JSON.stringify(value)}`);
991
+ seen.add(value);
992
+ const optionLabel = localizedText(`${optionAt}.label`, option.label, MAX_TEXT_LENGTH, errors);
993
+ field.options.push({
994
+ value,
995
+ label: optionLabel ?? {}
996
+ });
997
+ }
998
+ } else if (entry.options !== void 0) errors.push(`${at}.options — only a select field takes options`);
999
+ if (entry.validation !== void 0) {
1000
+ if (!VALIDATION_TYPES.has(type)) errors.push(`${at}.validation — a ${type || "this"} field takes no validation`);
1001
+ else if (!isRecord(entry.validation)) errors.push(`${at}.validation — must be an object`);
1002
+ else {
1003
+ const rules = entry.validation;
1004
+ unknownKeys(`${at}.validation`, rules, VALIDATION_KEYS, errors);
1005
+ const validation = {};
1006
+ for (const key of ["minLength", "maxLength"]) {
1007
+ const value = rules[key];
1008
+ if (value === void 0) continue;
1009
+ if (typeof value !== "number" || !Number.isInteger(value) || value < 0 || value > MAX_VALIDATION_LENGTH) errors.push(`${at}.validation.${key} — must be an integer 0..${MAX_VALIDATION_LENGTH}`);
1010
+ else validation[key] = value;
1011
+ }
1012
+ if (validation.minLength !== void 0 && validation.maxLength !== void 0 && validation.minLength > validation.maxLength) errors.push(`${at}.validation — minLength exceeds maxLength`);
1013
+ if (rules.pattern !== void 0) {
1014
+ if (typeof rules.pattern !== "string" || rules.pattern.length > 200) errors.push(`${at}.validation.pattern — must be a regular expression of at most 200 characters`);
1015
+ else try {
1016
+ new RegExp(rules.pattern);
1017
+ const unsupported = nonRe2Construct(rules.pattern);
1018
+ if (unsupported === null) validation.pattern = rules.pattern;
1019
+ else errors.push(`${at}.validation.pattern — ${unsupported} is not supported (the platform matches with RE2)`);
1020
+ } catch {
1021
+ errors.push(`${at}.validation.pattern — not a valid regular expression`);
1022
+ }
1023
+ }
1024
+ field.validation = validation;
1025
+ }
1026
+ }
1027
+ return field;
1028
+ }
1029
+ /**
1030
+ * Validates the declared `formSeeds`: the forms a site is created with, ingested by Core's
1031
+ * `site_forms` seeding. It rejects an unknown key outright and enforces the wire contract
1032
+ * agreed for WS-386 (key and field-id grammar, field types, option and length caps). It mirrors
1033
+ * Core's `normalizeFormInput` exactly — anything Core refuses fails the whole manifest sync, so a
1034
+ * rule changed on the Core side must be changed here too. A merchant-edited form is never
1035
+ * overwritten by a later version of a seed (Core's `editedByMerchant` flag).
1036
+ *
1037
+ * Absent (`undefined`) and empty both mean "this theme seeds no forms".
1038
+ */
1039
+ function validateFormSeeds(seeds, errors) {
1040
+ if (seeds === void 0) return [];
1041
+ if (!Array.isArray(seeds)) {
1042
+ errors.push("formSeeds — must be an array");
1043
+ return [];
1044
+ }
1045
+ if (seeds.length > MAX_FORM_SEEDS) errors.push(`formSeeds: contains ${seeds.length} seeds — exceeds ${MAX_FORM_SEEDS}`);
1046
+ const normalized = [];
1047
+ const keys = /* @__PURE__ */ new Set();
1048
+ for (const [index, entry] of seeds.slice(0, MAX_FORM_SEEDS).entries()) {
1049
+ const at = `formSeeds[${index}]`;
1050
+ if (!isRecord(entry)) {
1051
+ errors.push(`${at} — must be a form seed object`);
1052
+ continue;
1053
+ }
1054
+ unknownKeys(at, entry, SEED_KEYS, errors);
1055
+ const key = typeof entry.key === "string" ? entry.key : "";
1056
+ if (!FORM_KEY_PATTERN.test(key) || key === RESERVED_FORM_KEY) errors.push(`${at}.key — invalid key ${JSON.stringify(entry.key)} (expected ${FORM_KEY_PATTERN.source}, and "${RESERVED_FORM_KEY}" is reserved)`);
1057
+ else if (keys.has(key)) errors.push(`${at}.key — duplicate key ${JSON.stringify(key)}`);
1058
+ else keys.add(key);
1059
+ const name = stripPlainTextControls(entry.name).trim();
1060
+ if (codePointLength(name) < 1 || codePointLength(name) > MAX_NAME_LENGTH) errors.push(`${at}.name — must contain 1..${MAX_NAME_LENGTH} characters`);
1061
+ const rawFields = Array.isArray(entry.fields) ? entry.fields : [];
1062
+ if (rawFields.length < 1 || rawFields.length > MAX_FIELDS) errors.push(`${at}.fields — must declare 1..${MAX_FIELDS} fields`);
1063
+ const fields = [];
1064
+ const ids = /* @__PURE__ */ new Set();
1065
+ for (const [fieldIndex, rawField] of rawFields.slice(0, MAX_FIELDS).entries()) {
1066
+ const field = validateField(`${at}.fields[${fieldIndex}]`, rawField, errors);
1067
+ if (field === null) continue;
1068
+ if (ids.has(field.id.toLowerCase())) errors.push(`${at}.fields[${fieldIndex}].id — duplicate id ${JSON.stringify(field.id)} (ids are compared ignoring case)`);
1069
+ ids.add(field.id.toLowerCase());
1070
+ fields.push(field);
1071
+ }
1072
+ const actions = validateActions(at, entry.actions, fields, errors);
1073
+ const success = validateSuccess(at, entry.success, errors);
1074
+ normalized.push({
1075
+ key,
1076
+ name,
1077
+ fields,
1078
+ actions,
1079
+ success
1080
+ });
1081
+ }
1082
+ return normalized;
1083
+ }
1084
+ function validateActions(at, value, fields, errors) {
1085
+ const actions = {
1086
+ notify: false,
1087
+ confirm: false
1088
+ };
1089
+ if (!isRecord(value)) {
1090
+ errors.push(`${at}.actions — must be an object`);
1091
+ return actions;
1092
+ }
1093
+ unknownKeys(`${at}.actions`, value, ACTION_KEYS, errors);
1094
+ const hasEmailField = fields.some((field) => field.type === "email");
1095
+ for (const key of ["notify", "confirm"]) {
1096
+ const flag = value[key];
1097
+ if (flag === void 0) continue;
1098
+ if (typeof flag !== "boolean") errors.push(`${at}.actions.${key} — must be true or false`);
1099
+ else actions[key] = flag;
1100
+ }
1101
+ if (actions.confirm && !hasEmailField) errors.push(`${at}.actions.confirm — needs an email field to send the confirmation to`);
1102
+ if (value.subscribe !== void 0) {
1103
+ const subscribe = value.subscribe;
1104
+ if (!isRecord(subscribe)) errors.push(`${at}.actions.subscribe — must be { list, consentText? }`);
1105
+ else {
1106
+ unknownKeys(`${at}.actions.subscribe`, subscribe, /* @__PURE__ */ new Set(["list", "consentText"]), errors);
1107
+ const list = typeof subscribe.list === "string" ? subscribe.list : "";
1108
+ if (!LIST_KEY_PATTERN.test(list)) errors.push(`${at}.actions.subscribe.list — invalid list ${JSON.stringify(subscribe.list)}`);
1109
+ else actions.subscribe = { list };
1110
+ if (subscribe.consentText !== void 0) {
1111
+ const consentText = consentSentence(`${at}.actions.subscribe.consentText`, subscribe.consentText, errors);
1112
+ if (consentText !== null && actions.subscribe !== void 0) actions.subscribe.consentText = consentText;
1113
+ }
1114
+ if (!hasEmailField) errors.push(`${at}.actions.subscribe — needs an email field to subscribe`);
1115
+ }
1116
+ }
1117
+ return actions;
1118
+ }
1119
+ /**
1120
+ * A subscribe action's consent sentence: a locale map like any label, but plain text only (Core
1121
+ * refuses `<`, `>` and control characters rather than strip them, since the sentence is the proof of consent and must
1122
+ * be stored exactly as the visitor saw it) and up to 500 characters per locale.
1123
+ */
1124
+ function consentSentence(at, value, errors) {
1125
+ if (isRecord(value)) {
1126
+ for (const [locale, text] of Object.entries(value)) if (typeof text === "string" && /[<>\u0000-\u001f\u007f]/.test(text.trim())) {
1127
+ errors.push(`${at}.${locale} — must be plain text (no < or > or control characters)`);
1128
+ return null;
1129
+ }
1130
+ }
1131
+ return localizedText(at, value, MAX_CONSENT_TEXT_LENGTH, errors);
1132
+ }
1133
+ /** Core's `checkFormRedirect`: a site path, or an absolute http(s) URL. */
1134
+ function isFormRedirect(target) {
1135
+ if (target.startsWith("/")) return true;
1136
+ try {
1137
+ const url = new URL(target);
1138
+ return url.protocol === "http:" || url.protocol === "https:";
1139
+ } catch {
1140
+ return false;
1141
+ }
1142
+ }
1143
+ function validateSuccess(at, value, errors) {
1144
+ if (!isRecord(value)) {
1145
+ errors.push(`${at}.success — must be { message }`);
1146
+ return { message: {} };
1147
+ }
1148
+ unknownKeys(`${at}.success`, value, SUCCESS_KEYS, errors);
1149
+ const success = { message: localizedText(`${at}.success.message`, value.message, MAX_MESSAGE_LENGTH, errors) ?? {} };
1150
+ if (value.redirect !== void 0) {
1151
+ const redirect = localizedText(`${at}.success.redirect`, value.redirect, 500, errors);
1152
+ if (redirect !== null) {
1153
+ for (const [locale, target] of Object.entries(redirect)) if (!isFormRedirect(target)) errors.push(`${at}.success.redirect.${locale} — must be a path starting with "/" or an http(s) URL`);
1154
+ success.redirect = redirect;
1155
+ }
1156
+ }
1157
+ return success;
1158
+ }
1159
+ //#endregion
834
1160
  //#region src/templates.ts
835
1161
  const MAX_TEMPLATES = 8;
836
1162
  const MAX_PAGE_SEEDS = 16;
@@ -1529,10 +1855,12 @@ function scanTheme(opts) {
1529
1855
  const templates = validateTemplateSeeds(opts.templates ?? [], blocks, errors);
1530
1856
  const templateRoles = validateTemplateRoles(opts.templateRoles, blocks, templates, errors);
1531
1857
  const pageSeeds = validatePageSeeds(opts.templates ?? [], blocks, templates, templateRoles, errors);
1858
+ const formSeeds = validateFormSeeds(opts.formSeeds, errors);
1532
1859
  const messages = readMessages(themeDir, packageJson, errors);
1533
1860
  const manifest = {
1534
- manifestVersion: 1,
1861
+ manifestVersion: 2,
1535
1862
  theme: {
1863
+ id: readThemeId(packageJson, errors),
1536
1864
  name: sanitizeThemeName(typeof packageJson?.name === "string" ? packageJson.name : ""),
1537
1865
  version: typeof packageJson?.version === "string" ? packageJson.version : "0.0.0",
1538
1866
  framework: opts.framework ?? "vite",
@@ -1547,6 +1875,7 @@ function scanTheme(opts) {
1547
1875
  ...templates.length === 0 ? {} : { templates },
1548
1876
  ...templateRoles === void 0 ? {} : { templateRoles },
1549
1877
  ...pageSeeds.length === 0 ? {} : { pageSeeds },
1878
+ ...formSeeds.length === 0 ? {} : { formSeeds },
1550
1879
  tokens: readTokens(themeDir, errors),
1551
1880
  ...messages === void 0 ? {} : { messages }
1552
1881
  };
@@ -2104,6 +2433,27 @@ function resolvePackageVersion(themeDir, packageName) {
2104
2433
  return "0.0.0";
2105
2434
  }
2106
2435
  }
2436
+ /** The theme's declared `eldra.themeId`: the stable identity Core stores the
2437
+ * theme's block schemas and entries under (`<themeId>:<apiId>`), independent of
2438
+ * the npm package name. Required; there is no derivation from `name`. Returns
2439
+ * an empty string after reporting an error, so the caller still builds the
2440
+ * rest of the manifest and every problem is reported in one pass. */
2441
+ function readThemeId(packageJson, errors) {
2442
+ const declared = isRecord(packageJson?.eldra) ? packageJson.eldra.themeId : void 0;
2443
+ if (declared === void 0) {
2444
+ errors.push("package.json: eldra.themeId — required; set \"eldra\": { \"themeId\": \"<id>\" } (lower-case letters, digits and hyphens, 2 to 49 characters, starting with a letter)");
2445
+ return "";
2446
+ }
2447
+ if (typeof declared !== "string" || !THEME_ID_PATTERN.test(declared)) {
2448
+ errors.push(`package.json: eldra.themeId — must match ${THEME_ID_PATTERN} (lower-case letters, digits and hyphens, 2 to 49 characters, starting with a letter; got ${JSON.stringify(declared)})`);
2449
+ return "";
2450
+ }
2451
+ if (RESERVED_THEME_IDS.includes(declared)) {
2452
+ errors.push(`package.json: eldra.themeId — "${declared}" is reserved`);
2453
+ return "";
2454
+ }
2455
+ return declared;
2456
+ }
2107
2457
  function sanitizeThemeName(name) {
2108
2458
  return (name.split("/").pop() ?? "").toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 49);
2109
2459
  }
@@ -2121,8 +2471,8 @@ function toRelative(themeDir, path) {
2121
2471
  function previousBlocks(manifest, errors) {
2122
2472
  const result = /* @__PURE__ */ new Map();
2123
2473
  if (manifest === void 0) return result;
2124
- if (!isRecord(manifest) || manifest.manifestVersion !== 1 || !Array.isArray(manifest.blocks)) {
2125
- errors.push("previous manifest: expected manifestVersion 1 and a blocks array");
2474
+ if (!isRecord(manifest) || manifest.manifestVersion !== 2 || !Array.isArray(manifest.blocks)) {
2475
+ errors.push("previous manifest: expected manifestVersion 2 and a blocks array");
2126
2476
  return result;
2127
2477
  }
2128
2478
  for (const [index, value] of manifest.blocks.entries()) {
@@ -2159,4 +2509,4 @@ function readPreviousManifest(themeDir, errors) {
2159
2509
  return parsed === null ? void 0 : parsed;
2160
2510
  }
2161
2511
  //#endregion
2162
- export { validateTemplateRoles as a, validatePageSeeds as i, scanTheme as n, validateTemplateSeeds as o, seedLayout as r, readPreviousManifest as t };
2512
+ export { validateTemplateRoles as a, validatePageSeeds as i, scanTheme as n, validateTemplateSeeds as o, seedLayout as r, validateFormSeeds as s, readPreviousManifest as t };
package/dist/scan.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as ThemeManifest, C as ScanOptions, b as ManifestTemplateSeed, l as DeclaredTemplateSeed, v as ManifestRoute, w as ScanResult } from "./types-BRNXfpXW.js";
1
+ import { D as ScanOptions, O as ScanResult, P as ThemeManifest, S as ManifestRoute, u as DeclaredTemplateSeed, w as ManifestTemplateSeed } from "./types-d9173MhL.js";
2
2
  //#region src/scan.d.ts
3
3
  export declare function scanTheme(opts: ScanOptions): ScanResult;
4
4
  export declare function readPreviousManifest(themeDir: string, errors: string[]): ThemeManifest | undefined;
package/dist/scan.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as scanTheme, t as readPreviousManifest } from "./scan-DjW4f_E8.js";
1
+ import { n as scanTheme, t as readPreviousManifest } from "./scan-B4nn0SQj.js";
2
2
  export { readPreviousManifest, scanTheme };
@@ -286,8 +286,12 @@ interface BlockDefinition {
286
286
  migrations?: BlockMigration[];
287
287
  }
288
288
  interface ThemeManifest {
289
- manifestVersion: 1;
289
+ /** 2: `theme.id` is required. There is no v1 reader. */
290
+ manifestVersion: 2;
290
291
  theme: {
292
+ /** The theme's stable id (`package.json` `eldra.themeId`); Core stores the theme's
293
+ * block schemas as `<id>:<blockApiId>`. Block apiIds in this manifest stay bare. */
294
+ id: string;
291
295
  name: string;
292
296
  version: string;
293
297
  framework: string;
@@ -316,6 +320,9 @@ interface ThemeManifest {
316
320
  * byte-identical to the one themes have always emitted. Absent rather than
317
321
  * empty when the theme seeds no pages, for the same reason `templates` is. */
318
322
  pageSeeds?: ManifestPageSeed[];
323
+ /** The forms the site is created with (`/site/v1/forms/{key}` serves them). Absent rather than
324
+ * empty when the theme seeds none, for the same reason `templates` is. */
325
+ formSeeds?: ManifestFormSeed[];
319
326
  tokens: ThemeDesignTokens | LegacyThemeTokens;
320
327
  /** The theme's own message catalogue, read from `i18n/<tag>.json` and
321
328
  * flattened to dotted keys. Absent rather than empty when the theme ships
@@ -348,6 +355,62 @@ interface ScanResult {
348
355
  * `.eldra/manifest.json`. Always resolved, independent of `errors`. */
349
356
  breakpoints: LayoutBreakpoints;
350
357
  }
358
+ /**
359
+ * The field types a seeded form field may take: the WS-386 set (`text`, `email`, `phone`,
360
+ * `textarea`, `select`, `checkbox`, `consent`, `number`, `url`), exactly what Core accepts. `consent` is a checkbox
361
+ * whose value is a boolean and whose `required` means it must be checked.
362
+ */
363
+ type ManifestFormSeedFieldType = 'text' | 'email' | 'phone' | 'textarea' | 'select' | 'checkbox' | 'consent' | 'number' | 'url';
364
+ interface ManifestFormSeedField {
365
+ id: string;
366
+ type: ManifestFormSeedFieldType;
367
+ required: boolean;
368
+ /** One entry per locale tag, e.g. `{ 'en-US': 'Email', 'is-IS': 'Netfang' }`. */
369
+ label: Record<string, string>;
370
+ placeholder?: Record<string, string>;
371
+ /** A `select` field's options; absent on every other type. */
372
+ options?: Array<{
373
+ value: string;
374
+ label: Record<string, string>;
375
+ }>;
376
+ validation?: {
377
+ minLength?: number;
378
+ maxLength?: number;
379
+ pattern?: string;
380
+ };
381
+ }
382
+ /**
383
+ * A form the site is created with (`formSeeds` in the manifest). Core creates it only when the
384
+ * key is absent; a seeded form the merchant never edited is refreshed on a theme version bump.
385
+ */
386
+ interface ManifestFormSeed {
387
+ key: string;
388
+ name: string;
389
+ fields: ManifestFormSeedField[];
390
+ actions: {
391
+ /** Email the merchant's notification recipients on every submission. */
392
+ notify: boolean;
393
+ /** Email the visitor a copy (needs an email field). */
394
+ confirm: boolean;
395
+ /** Subscribe the visitor's email to a list, double opt-in (needs an email field). */
396
+ subscribe?: {
397
+ list: string;
398
+ /**
399
+ * The consent sentence shown beside the submit button, per locale, with a `{shop}`
400
+ * placeholder Core replaces with the shop name. It is sent to marketing as the proof of
401
+ * consent. Plain text, at most 500 characters per locale. Left out, Core fills in its
402
+ * platform default on create, so a seed without it keeps working.
403
+ */
404
+ consentText?: Record<string, string>;
405
+ };
406
+ };
407
+ success: {
408
+ message: Record<string, string>;
409
+ redirect?: Record<string, string>;
410
+ };
411
+ }
412
+ /** What a theme declares; the same shape, validated by `validateFormSeeds` into `ManifestFormSeed`. */
413
+ type DeclaredFormSeed = ManifestFormSeed;
351
414
  interface ScanOptions {
352
415
  /** Last validated local manifest, advisory only; Core owns installed history. */
353
416
  previousManifest?: ThemeManifest;
@@ -362,6 +425,8 @@ interface ScanOptions {
362
425
  * `templates` layouts may reference. Required for a role once any template
363
426
  * seed's layout places it. */
364
427
  templateRoles?: ManifestTemplateRoles;
428
+ /** The forms a site is created with; see `ManifestFormSeed`. */
429
+ formSeeds?: DeclaredFormSeed[];
365
430
  /** The theme's raw, as-configured breakpoints — validated and defaulted
366
431
  * into the manifest's `breakpoints` by resolveLayoutBreakpoints (Core),
367
432
  * not here. */
@@ -383,6 +448,10 @@ interface EldraThemeOptions {
383
448
  * `templates` layouts may reference. Required for a role once any template
384
449
  * seed's layout places it. */
385
450
  templateRoles?: ManifestTemplateRoles;
451
+ /** The forms a site is created with on its first deploy (at most 8): fields with a label per
452
+ * locale, and which of notify/confirm/subscribe a submission triggers. Never overwrites a
453
+ * form the merchant has edited. */
454
+ formSeeds?: DeclaredFormSeed[];
386
455
  /** Theme source root. Nuxt 4 sets Vite's root to app/, so adapters pass rootDir explicitly. */
387
456
  themeDir?: string;
388
457
  /** Opt in to the Tailwind v4 virtual theme module; false keeps Tailwind entirely optional. */
@@ -427,4 +496,4 @@ interface EldraThemeOptions {
427
496
  resolveTokens?: (manifestTokens: ThemeDesignTokens | LegacyThemeTokens) => ThemeDesignTokens;
428
497
  }
429
498
  //#endregion
430
- export { ThemeManifest as A, ScanOptions as C, TemplateSeedLayoutNode as D, TemplateSeedLayout as E, TemplateSeedReusableNode as O, PageSeedTarget as S, TemplateSeedBlockNode as T, ManifestPageSeedRegion as _, DeclaredPageSeedBlock as a, ManifestTemplateSeed as b, DeclaredSeed as c, DeclaredThemeCodePage as d, EldraThemeOptions as f, ManifestPageSeedEntry as g, ManifestPageSeedBlock as h, DeclaredPageSeed as i, ThemeMessages as j, TemplateSeedSchemaApiId as k, DeclaredTemplateSeed as l, ManifestPageSeed as m, BlockField as n, DeclaredPageSeedEntry as o, LegacyThemeTokens as p, BlockMigration as r, DeclaredPageSeedRegion as s, BlockDefinition as t, DeclaredTemplateSeedBlock as u, ManifestRoute as v, ScanResult as w, ManifestTemplateSeedBlock as x, ManifestTemplateRoles as y };
499
+ export { TemplateSeedLayout as A, ManifestTemplateRoles as C, ScanOptions as D, PageSeedTarget as E, ThemeMessages as F, TemplateSeedReusableNode as M, TemplateSeedSchemaApiId as N, ScanResult as O, ThemeManifest as P, ManifestRoute as S, ManifestTemplateSeedBlock as T, ManifestFormSeedFieldType as _, DeclaredPageSeed as a, ManifestPageSeedEntry as b, DeclaredPageSeedRegion as c, DeclaredTemplateSeedBlock as d, DeclaredThemeCodePage as f, ManifestFormSeedField as g, ManifestFormSeed as h, DeclaredFormSeed as i, TemplateSeedLayoutNode as j, TemplateSeedBlockNode as k, DeclaredSeed as l, LegacyThemeTokens as m, BlockField as n, DeclaredPageSeedBlock as o, EldraThemeOptions as p, BlockMigration as r, DeclaredPageSeedEntry as s, BlockDefinition as t, DeclaredTemplateSeed as u, ManifestPageSeed as v, ManifestTemplateSeed as w, ManifestPageSeedRegion as x, ManifestPageSeedBlock as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/vite-plugin-theme",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Vite plugin for Eldra themes: scans blocks/*/block.json, validates them, emits the theme manifest and the virtual modules the runtime reads (blocks, manifest, block fields, breakpoints, tokens CSS).",
5
5
  "keywords": [
6
6
  "cms",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "ajv": "^8.17.1",
44
- "@eldrajs/theme-core": "^0.1.0"
44
+ "@eldrajs/theme-core": "^0.3.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@tailwindcss/vite": "^4.1.14",