@eldrajs/theme-cli 0.2.2 → 0.2.4

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 (44) hide show
  1. package/dist/cli.js +2 -3
  2. package/dist/index.d.ts +0 -12
  3. package/dist/index.js +1 -1
  4. package/dist/{validate-DprFpjV7.js → validate-FjQ-5_ne.js} +9 -18
  5. package/package.json +3 -3
  6. package/template/.eldra/previews.json +35 -35
  7. package/template/app/plugins/chunk-reload.client.ts +29 -0
  8. package/template/app/plugins/eldra-storefront.ts +5 -0
  9. package/template/app/storefront/gateway.ts +34 -14
  10. package/template/app/storefront/sharedRead.ts +34 -0
  11. package/template/app/storefront/structuredData.ts +19 -2
  12. package/template/app/storefront/types.ts +0 -5
  13. package/template/app/utils/chunkReload.ts +11 -0
  14. package/template/app/utils/seoInput.ts +0 -1
  15. package/template/blocks/article-list/preview.png +0 -0
  16. package/template/blocks/breadcrumbs/preview.png +0 -0
  17. package/template/blocks/cart/preview.png +0 -0
  18. package/template/blocks/collection-grid/Block.vue +146 -94
  19. package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
  20. package/template/blocks/collection-grid/preview.png +0 -0
  21. package/template/blocks/collection-header/preview.png +0 -0
  22. package/template/blocks/navigation/Block.vue +125 -541
  23. package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
  24. package/template/blocks/navigation/parts/MenuLink.vue +15 -0
  25. package/template/blocks/product-detail/preview.png +0 -0
  26. package/template/blocks/search/preview.png +0 -0
  27. package/template/blocks/team/preview.png +0 -0
  28. package/template/blocks/video-embed/preview.png +0 -0
  29. package/template/package.json +1 -1
  30. package/template/test/chunkReload.spec.ts +20 -0
  31. package/template/test/imageFraming.browser.spec.ts +125 -0
  32. package/template/test/pages/article.spec.ts +1 -1
  33. package/template/test/pages/collection.spec.ts +1 -1
  34. package/template/test/pages/home.spec.ts +1 -1
  35. package/template/test/pages/product.spec.ts +1 -1
  36. package/template/test/prerenderRefresh.browser.spec.ts +58 -13
  37. package/template/test/seoInput.spec.ts +5 -4
  38. package/template/test/storefront/gateway.spec.ts +6 -0
  39. package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
  40. package/template/test/storefront/sharedRead.spec.ts +43 -0
  41. package/template/test/storefront/structuredData.spec.ts +34 -6
  42. package/template/test/structuredData.generate.spec.ts +1 -1
  43. package/template/test/support/mockGateway.ts +8 -3
  44. package/template/blocks/navigation/useMegaMenuKeys.ts +0 -276
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { a as initTheme, i as scaffoldBlock, n as generateBlockTypesFile, o as DeployError, r as generateTypes, s as deployTheme, t as validateTheme } from "./validate-DprFpjV7.js";
2
+ import { a as initTheme, i as scaffoldBlock, n as generateBlockTypesFile, o as DeployError, r as generateTypes, s as deployTheme, t as validateTheme } from "./validate-FjQ-5_ne.js";
3
3
  import { resolve } from "node:path";
4
4
  import { defineCommand, runMain } from "citty";
5
- //#region src/cli.ts
5
+ // src/cli.ts
6
6
  const gatewayArgs = {
7
7
  "gateway-url": {
8
8
  type: "string",
@@ -199,5 +199,4 @@ const main = defineCommand({
199
199
  }
200
200
  });
201
201
  await runMain(main);
202
- //#endregion
203
202
  export {};
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { DeclaredThemeCodePage } from "@eldrajs/vite-plugin-theme";
2
2
  import { scanTheme } from "@eldrajs/vite-plugin-theme/scan";
3
- //#region src/deployReport.d.ts
4
3
  /**
5
4
  * What a deploy did to existing content, in the words an author needs.
6
5
  *
@@ -78,8 +77,6 @@ interface FieldMigrationReport {
78
77
  * deploy command only forwards these to its logger.
79
78
  */
80
79
  export declare function fieldMigrationLines(report: FieldMigrationReport | undefined | null): string[];
81
- //#endregion
82
- //#region src/commands/deploy.d.ts
83
80
  export declare class DeployError extends Error {
84
81
  readonly code: string | null;
85
82
  constructor(message: string, code?: string | null);
@@ -119,11 +116,7 @@ export declare function detectCommitSha(env: {
119
116
  BITBUCKET_COMMIT?: string;
120
117
  }): string | null;
121
118
  export declare function deployTheme(opts: DeployOptions): Promise<DeployResult>;
122
- //#endregion
123
- //#region src/commands/init.d.ts
124
119
  export declare function initTheme(targetDir: string): void;
125
- //#endregion
126
- //#region src/commands/scaffold.d.ts
127
120
  interface ScaffoldBlockOptions {
128
121
  themeDir: string;
129
122
  apiId: string;
@@ -134,8 +127,6 @@ interface ScaffoldBlockOptions {
134
127
  export declare function scaffoldBlock(opts: ScaffoldBlockOptions): {
135
128
  created: string[];
136
129
  };
137
- //#endregion
138
- //#region src/commands/types.d.ts
139
130
  export declare function generateTypes(opts: {
140
131
  themeDir: string;
141
132
  gatewayUrl: string;
@@ -154,8 +145,6 @@ export declare function generateTypes(opts: {
154
145
  export declare function generateBlockTypesFile(opts: {
155
146
  themeDir: string;
156
147
  }): string;
157
- //#endregion
158
- //#region src/commands/validate.d.ts
159
148
  interface ValidateOptions {
160
149
  themeDir: string;
161
150
  remote: boolean;
@@ -170,5 +159,4 @@ interface ValidateResult {
170
159
  blockCount: number;
171
160
  }
172
161
  export declare function validateTheme(opts: ValidateOptions): Promise<ValidateResult>;
173
- //#endregion
174
162
  export { type ConvertedFieldMigration, type DeployOptions, type DeployResult, type DeploySyncResult, type DroppedLinkRows, type FieldMigrationReport, type RetiredFieldMigration, type ScaffoldBlockOptions, type ValidateOptions, type ValidateResult, scanTheme };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import { a as initTheme, c as detectCommitSha, i as scaffoldBlock, l as fieldMigrationLines, n as generateBlockTypesFile, o as DeployError, r as generateTypes, s as deployTheme, t as validateTheme } from "./validate-DprFpjV7.js";
1
+ import { a as initTheme, c as detectCommitSha, i as scaffoldBlock, l as fieldMigrationLines, n as generateBlockTypesFile, o as DeployError, r as generateTypes, s as deployTheme, t as validateTheme } from "./validate-FjQ-5_ne.js";
2
2
  import { scanTheme } from "@eldrajs/vite-plugin-theme/scan";
3
3
  export { DeployError, deployTheme, detectCommitSha, fieldMigrationLines, generateBlockTypesFile, generateTypes, initTheme, scaffoldBlock, scanTheme, validateTheme };
@@ -7,7 +7,7 @@ import * as tar from "tar";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { generateBlockTypes } from "@eldrajs/vite-plugin-theme";
9
9
  import { readPreviousManifest, scanTheme } from "@eldrajs/vite-plugin-theme/scan";
10
- //#region src/deployReport.ts
10
+ // src/deployReport.ts
11
11
  /** The drop reasons this version can say in words. Anything else prints as the
12
12
  * code the gateway sent, so a reason added later is still reported. */
13
13
  const DROP_REASONS = { "kind-not-offered": "the field does not offer that kind" };
@@ -88,8 +88,7 @@ function nameOf(value) {
88
88
  function asArray(value) {
89
89
  return Array.isArray(value) ? value : [];
90
90
  }
91
- //#endregion
92
- //#region src/urls.ts
91
+ // src/urls.ts
93
92
  /**
94
93
  * Strips every trailing `/` from a URL (`https://x///` → `https://x`). A
95
94
  * regex equivalent (`/\/+$/`) backtracks polynomially on a long run of
@@ -105,8 +104,7 @@ function stripTrailingSlashes(value) {
105
104
  while (end > 0 && value.charCodeAt(end - 1) === 47) end--;
106
105
  return value.slice(0, end);
107
106
  }
108
- //#endregion
109
- //#region src/commands/deploy.ts
107
+ // src/commands/deploy.ts
110
108
  const MAX_FILES = 2e4;
111
109
  const MAX_FILE_BYTES = 26214400;
112
110
  const MAX_DESIGN_TOKEN_MAPPING_BYTES = 16384;
@@ -286,8 +284,7 @@ async function toDeployError(res) {
286
284
  if (res.status === 413 && bodyUnparseable) return new DeployError("deploy: gateway responded 413 (payload too large) with no error body — a proxy/CDN in front of it may have a smaller limit than the app's own (≤ 20,000 files, ≤ 25 MiB/file, ≤ 500 MiB unpacked, ≤ 200 MiB compressed), or the request exceeds one of those; check the artifact size, and if it is within them ask infra about the proxy limit");
287
285
  return new DeployError(`deploy: ${messages[detail ?? ""] ?? `gateway responded ${res.status}${detail ? ` (${detail})` : ""}`}`, detail);
288
286
  }
289
- //#endregion
290
- //#region src/templateExclude.mjs
287
+ // src/templateExclude.mjs
291
288
  /** A directory with this name, at any depth, is never copied. */
292
289
  const EXCLUDE_DIR_NAMES = [
293
290
  "node_modules",
@@ -321,8 +318,7 @@ function shouldCopyTemplatePath(path) {
321
318
  if (parts.some((part) => EXCLUDE_DIR_NAMES.includes(part))) return false;
322
319
  return !parts.some((part, index) => EXCLUDE_NESTED_DIRS.some((nested) => part === nested.parent && parts[index + 1] === nested.name));
323
320
  }
324
- //#endregion
325
- //#region src/commands/init.ts
321
+ // src/commands/init.ts
326
322
  function initTheme(targetDir) {
327
323
  if (existsSync(targetDir) && readdirSync(targetDir).length > 0) throw new Error(`init: target directory ${targetDir} is not empty`);
328
324
  const source = templateSource();
@@ -350,8 +346,7 @@ function templateSource() {
350
346
  if (source === void 0) throw new Error("starter template not found (package built without template/)");
351
347
  return source;
352
348
  }
353
- //#endregion
354
- //#region src/commands/scaffold.ts
349
+ // src/commands/scaffold.ts
355
350
  const API_ID_RE = /^[a-z][a-z0-9-]{1,48}$/;
356
351
  function scaffoldBlock(opts) {
357
352
  if (!API_ID_RE.test(opts.apiId)) throw new Error(`scaffoldBlock: apiId "${opts.apiId}" must match ${API_ID_RE.source}`);
@@ -404,8 +399,7 @@ function scaffoldBlock(opts) {
404
399
  function titleCase(apiId) {
405
400
  return apiId.split("-").map((word) => `${word[0].toUpperCase()}${word.slice(1)}`).join(" ");
406
401
  }
407
- //#endregion
408
- //#region src/commands/types.ts
402
+ // src/commands/types.ts
409
403
  async function generateTypes(opts) {
410
404
  const definitions = await createEldraClient({
411
405
  gatewayUrl: opts.gatewayUrl,
@@ -436,8 +430,7 @@ function generateBlockTypesFile(opts) {
436
430
  writeFileSync(target, content);
437
431
  return target;
438
432
  }
439
- //#endregion
440
- //#region src/knownFieldTypes.ts
433
+ // src/knownFieldTypes.ts
441
434
  const KNOWN_FIELD_TYPES = [
442
435
  "bool",
443
436
  "color",
@@ -463,8 +456,7 @@ const KNOWN_FIELD_TYPES = [
463
456
  "text",
464
457
  "uuid"
465
458
  ];
466
- //#endregion
467
- //#region src/commands/validate.ts
459
+ // src/commands/validate.ts
468
460
  const DEFAULT_CAPABLE_FIELD_TYPES = /* @__PURE__ */ new Set([
469
461
  "string",
470
462
  "text",
@@ -531,5 +523,4 @@ function validateFields(apiId, fields, validTypes, errors, path) {
531
523
  if (typeof nested.item === "object" && nested.item !== null) validateFields(apiId, [nested.item], validTypes, errors, `${fieldPath}.metadata.item`);
532
524
  });
533
525
  }
534
- //#endregion
535
526
  export { initTheme as a, detectCommitSha as c, scaffoldBlock as i, fieldMigrationLines as l, generateBlockTypesFile as n, DeployError as o, generateTypes as r, deployTheme as s, validateTheme as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/theme-cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "CLI for Eldra themes: init from the starter, scaffold blocks, validate, generate types, deploy a static build to Eldra.",
5
5
  "keywords": [
6
6
  "cli",
@@ -42,8 +42,8 @@
42
42
  "dependencies": {
43
43
  "citty": "^0.1.6",
44
44
  "tar": "^7.4.3",
45
- "@eldrajs/theme-core": "^0.3.1",
46
- "@eldrajs/vite-plugin-theme": "^0.3.1"
45
+ "@eldrajs/theme-core": "^0.3.3",
46
+ "@eldrajs/vite-plugin-theme": "^0.3.3"
47
47
  },
48
48
  "devDependencies": {
49
49
  "execa": "^9.5.2"
@@ -1,37 +1,37 @@
1
1
  {
2
- "announcement-bar": "68ba9861a4fcecb582e18aa7f44a51ff3f6465c9fbb47e88cddd8890420337be",
3
- "article": "5a5254d7ee0f76eec3ac8c1a66b34eefe9356e087bd36d825e4574bbe968e4a6",
4
- "article-list": "1d661f6f33521324f89524b53095a09d5ded680618bfcb96fc909e9ed67c6b49",
5
- "breadcrumbs": "80f7223888fe94df391ef9eb14e7d21db29783865e96e501efb545681633d35f",
6
- "cart": "cd4c0b36d1096fb01371ee10e3ca96ea6c79c5c3adfc708861a2a66dbc295070",
7
- "collection-grid": "54346552f7c6485b93fff6b97f19896c25f4995c1a6a20548a0303751733c757",
8
- "collection-header": "20b09301eb4f776e7d8af810bcb3c68c163a9d0f57640464542ab475837bf26d",
9
- "contact": "fe8f7c5ac315c08303b4f60a428037389205498689f86bf9d298c4ae2743a0d5",
10
- "cta": "c77c1ad7ee168c9b9a21ba3829fbf7d49ce553eb44e55e24048054440ff1b9b9",
11
- "faq": "4f6545197383c27ffa047f127f66689a579f471a813abb8077ee02acdc5042c3",
12
- "feature-grid": "42a3e8c3ed8ba59c47808072e7bd75134f0dd5cd6601890aaefe4d9d680a758d",
13
- "footer": "b8abd478dea9527a12eb16df8bbc77c0138f72c3b9ccd187a42e35519aca8d2e",
14
- "form": "215c423696dc865cc11b65680dd4bea7d015fe934605843338aa6a90a49fc491",
15
- "gallery": "66757de8c7f8450ac115826353352010a31883260dae2f963cb17d186f64843b",
16
- "hero": "cd9f9ae50828278eedd8e8a71c5b2955ad4d1fc5d6d0373ab3ba6f30df1bc293",
17
- "image": "1a384a1981e8fbdf3e6815d339158eff339e547c53487be26f247ed88dc3ac82",
18
- "logo-cloud": "406912fe0300486b7cd485411bd34bdcf4d93c82340f27d63e6713543949b6de",
19
- "navigation": "93b181878989575035cf454218148aea9cb049f17eb3b25e9da2db15fc7d7c4a",
20
- "newsletter": "f676177b2fca8a09cf59f4ecc4e84fc60aa525f2539252577e0e9b26c8e331ed",
21
- "order-status": "d8b65673592446379e561d3d48597668a3106c07840f744332c8fca3ae52369d",
22
- "pricing-table": "68d1a9d389f4042268ae0fd79b84c587ec01eb8893f7ada06c54245b5956b94a",
23
- "product-carousel": "024c67324ffd1d6247698472432b4e834ca81af55eab2234c4328503216aaaa3",
24
- "product-detail": "299507d04f82e14a40e6e3ce918eca8b2a859b979f5ec05a887a1e40d266858c",
25
- "quote": "ffdc3c965ee0a91a7182cec18ce97d9f62f55d46546b4b0be043cf6b88910e04",
26
- "rich-text": "a0cd489b4d00771c8da71fe3a4bc93b92e50bf34278d5c517b10cc6b6c35b039",
27
- "search": "c5c2b96738215219dcdc097a35579b0d38780e47b944d1d70edc8d8616c20ce4",
28
- "split-content": "99f9e1259086fef5e9edc03afa6c28eebc92d05b2ec9ef8c4651130da798db60",
29
- "stats": "708d400b93646a28b80a60893d0a8faa74a718258626998f0060126cde0b69ea",
30
- "tabs": "f689ffce96742598f115e4275fecd27759a97bb137d55e3acbd8e2fb118e10ce",
31
- "team": "e36e1af3528e799000c4ba8464c3785ac07a47aac4eac2a98dfc82ae0f409924",
32
- "testimonials": "25a01fd4e5399eac5d01c25a5010ef07ffacbba47c8daa3e36d3737d11e1fb40",
33
- "timeline": "2f8944c3df228ab1c7e268abbae8e8ca935ac0a070c1a088504a7566f74a109f",
34
- "trust-strip": "ed8c3652aa09ff76983d7dc217490a1c8ecf9e87ff4539eeb4ab7b18619648ea",
35
- "video-embed": "22e334618a755bceecef473bb8e027efd829f457756482088043232143237659",
36
- "wishlist": "273cbad2f658ccb87354266890a078f5951294bd8066fd4a236e0a2b5456796c"
2
+ "announcement-bar": "2b057546d7d017f6481e5c89e7af3ee67c1f03fc503ba29ef3485a8b3b72ca3e",
3
+ "article": "0f1d1229dc640ef3580442855b1eb4be83bbad43e6d828b71edd218018581b7e",
4
+ "article-list": "4132ded9bc945513dbdf0d6138c85a081aaeae65cb66f101e091acbd302c3274",
5
+ "breadcrumbs": "637c19cb81ba8e5a979df0e5f7bf6444ce85feb618c8168ac76df91434e00aad",
6
+ "cart": "7163dc4cdb18e2ea39b573e0e33c70c04202261266616671f06fd0837c141c70",
7
+ "collection-grid": "2062ade27f90aac810114c3d9a4bbd5efddd5b74c869a2b891dc3589c149eda6",
8
+ "collection-header": "cbcfacb1d8ab6638fb8094a8517baec3ff3911f9df744007babeee402e75715f",
9
+ "contact": "0af119acf554c453d8f545f3cd7a37ed4f3afa9a2472e105978e4f48f7d51616",
10
+ "cta": "0e3fc7d629f34d451b9f785d57fdd88c7853f737dab55136ec2e07b282cc4d81",
11
+ "faq": "90baa9a0832632aa47cd9ce1fe29682c16e045ea9739464e67d7287c6b0b94c8",
12
+ "feature-grid": "9bb14686453ba8ec7758442a6a55ffec797208ad02aed05d465ab384b42ff6c1",
13
+ "footer": "cbf8e902d28cc54eed9b57c75f1de122bbdbbda9845097a5f751e4864f3b3b9e",
14
+ "form": "55c897592a0048fb4465485d66c240084173479dad56e692608111c20f9d1a1d",
15
+ "gallery": "aaaae7b8b72f8a54c96bdac673317ba260e946c52fc7a62dbc439aab87f1f5a3",
16
+ "hero": "17309fd9ed6ca109725906c064c07d24187a7888175db2a1fb900966999a69f9",
17
+ "image": "7e2eaff913b3daf5eb96013e4e1762400b0c1eb06ccfb51cdb4eaee39e54c4aa",
18
+ "logo-cloud": "281e3cd1b8a4d3f3983623b22cfad7072aed6ab467a0d06eafcf3d884655a25a",
19
+ "navigation": "6377021a405f0ced6ad0f4013a19e20f42b2f1ea0d2a35f0646d9584b0a75088",
20
+ "newsletter": "fed26701771229ce4573d01ee79383ed482683bc904e225b30549d28f5b25697",
21
+ "order-status": "260384a10709343107828059b42a3e1238083aae94b9bc812c6feaa999adf522",
22
+ "pricing-table": "99890127509926177dc6a55b74a355577c8c8179a053290a3e866846e875be80",
23
+ "product-carousel": "4f2d1269f8432e1e7ba39abc57f4bc2330efbf7db1cd473004731c066fc23cd3",
24
+ "product-detail": "8e4cd802a3b0e9f7514edb4978b7dfff2fc1bd32d5fd0f7da9c041b1259b7222",
25
+ "quote": "e173b6e75861006d6c9a7397f9cf7d11834a2116bff27029e8df58799143bdf4",
26
+ "rich-text": "3239b3aa81b99b807409bbc5e1def629db64c8ee73140c7f6382d535c7a2ae48",
27
+ "search": "d6501ae66f353842724b2dd90413d01ead20ab75f2c17722a9cd87527ccf6418",
28
+ "split-content": "41b84b530d65d37777c3df6f55cf12a62a090edf938f784491641c5967b6d602",
29
+ "stats": "e7bf6d2134a6f404d9e3cce87892c36838e9b4ed247f7b3e34882eca61412ad1",
30
+ "tabs": "352eaed3dea3c54d7bcb7665feafb770a9977f0fa0029abf9e3fb83c23960936",
31
+ "team": "52ca9e5827f11c68344593aa44508cb41f3322576a6aac3cb9454df2c381827a",
32
+ "testimonials": "a4477a2a42c2634ea7180ba2801412580962661651baee2697703b1ca854dd45",
33
+ "timeline": "c5ab8481388681dec370959c815f835130da75f37cbaa0745dbc39f1afc825b6",
34
+ "trust-strip": "babe3d988c88a93a8452881a0d8ecc6d1872004c604d550471edcae52d565066",
35
+ "video-embed": "4cd7b65b4ee6c7cc86b0dc5ef27e29c2e144afcdc9736bf6b2ac5b750ada4ce0",
36
+ "wishlist": "6051e425cb5b40a638c08b86d452bbeed4cba590582ed7092f29697ea2fd1636"
37
37
  }
@@ -0,0 +1,29 @@
1
+ import { defineNuxtPlugin } from 'nuxt/app';
2
+ import { isChunkError, shouldReload } from '../utils/chunkReload';
3
+
4
+ const KEY = 'eldra:chunk-reload-at';
5
+
6
+ // A deploy renames every `_nuxt` chunk, so a tab or cached page from the old build asks for files that are gone and its lazy blocks never render.
7
+ export default defineNuxtPlugin((nuxtApp) => {
8
+ function reloadOnce(): void {
9
+ let last: number | null = null;
10
+ try {
11
+ const stored = window.sessionStorage.getItem(KEY);
12
+ last = stored === null ? null : Number(stored);
13
+ if (!shouldReload(Date.now(), last)) return;
14
+ window.sessionStorage.setItem(KEY, String(Date.now()));
15
+ } catch {
16
+ return;
17
+ }
18
+ window.location.reload();
19
+ }
20
+
21
+ window.addEventListener('vite:preloadError', (event) => {
22
+ event.preventDefault();
23
+ reloadOnce();
24
+ });
25
+ nuxtApp.hook('app:chunkError', reloadOnce);
26
+ nuxtApp.hook('vue:error', (error) => {
27
+ if (isChunkError(error)) reloadOnce();
28
+ });
29
+ });
@@ -13,6 +13,7 @@ import {
13
13
  type StorefrontPrerenderHandle,
14
14
  type StorefrontRuntime,
15
15
  } from '../storefront/gateway';
16
+ import { createSharedRead } from '../storefront/sharedRead';
16
17
  import { withAnalytics } from '../storefront/analytics';
17
18
  import { createVolatileRefresher } from '../storefront/refresh';
18
19
  import {
@@ -178,6 +179,8 @@ export default defineNuxtPlugin({
178
179
  formsEndpoint?: string;
179
180
  };
180
181
 
182
+ // Build-wide reads (the category tree) are shared across the routes of a prerender (WS-406).
183
+ const shared = createSharedRead(publicConfig.eldra);
181
184
  const client = createEldraClient({
182
185
  apiBaseUrl: publicConfig.eldra?.gatewayUrl || undefined,
183
186
  orgId: publicConfig.eldra?.orgId || undefined,
@@ -265,6 +268,8 @@ export default defineNuxtPlugin({
265
268
 
266
269
  source = createGatewayStorefront(client, {
267
270
  route,
271
+ // Build-wide reads (the category tree) are made once per prerender, not once per route.
272
+ shared,
268
273
  // What the store sells in, as the platform published it — the module read it once during the
269
274
  // build (`@eldrajs/theme-nuxt`), so a prerendered page already has it. `app/plugins/
270
275
  // eldra-ui-messages.ts` provides the currency half to `@eldrajs/ui`; this puts the whole
@@ -17,6 +17,8 @@ import {
17
17
  import { fromMinorUnits, roundMoney, toMinorUnits } from './money';
18
18
  import { chunkIds, collectVolatileTargets } from './volatile';
19
19
  import { canonicalAvailabilityValues, OPTION_SOURCE_PREFIX } from './facets';
20
+
21
+ const TOGGLE_SOURCE_PREFIX = 'toggle:';
20
22
  import { optionDisplayType, storefrontOptionKind } from './options';
21
23
  import {
22
24
  buildCategoryIndex,
@@ -237,8 +239,6 @@ interface RawProductDetails {
237
239
  * knows the response carries it rather than inferring the catalogue only ever assigns one.
238
240
  */
239
241
  categoryIds?: string[] | null;
240
- /** Per-product brand, for `Product.brand` in the structured data. */
241
- brand?: string | null;
242
242
  description?: Record<string, unknown>;
243
243
  mediaLinks?: RawMediaItem[] | null;
244
244
  options?: RawProductOption[] | null;
@@ -600,7 +600,6 @@ function mapProductDetails(
600
600
  ? (stock?.get(countableVariant.id)?.availableQuantity ?? null)
601
601
  : null,
602
602
  stock: variantStock(firstAvailable, stock),
603
- brand: raw.brand?.trim() || null,
604
603
  // Each variant's own price and stock state, for the page's structured data: the same
605
604
  // `variantStock` rule the buy box's line uses, so the markup and the page cannot disagree.
606
605
  variants: variants.map((variant) => ({
@@ -1297,7 +1296,7 @@ const GATEWAY_UNSORTABLE: readonly string[] = ['best-selling'];
1297
1296
  * - **`category` is a slug in the URL and a uuid in the request.** The block's values are the facet
1298
1297
  * terms' slugs (a filtered view has to stay linkable and readable), while `categoryId` takes
1299
1298
  * catalog ids, so the slugs are resolved through the store's own category list — see
1300
- * `readCategories`.
1299
+ * `readCategoryRows`.
1301
1300
  * - **`availability` is one value, not a set.** Both boxes ticked is every product, which is no
1302
1301
  * filter at all, so nothing is sent; one box is sent as the platform's own
1303
1302
  * `in_stock`/`out_of_stock` spelling, which `canonicalAvailabilityValues` also folds the retired
@@ -1319,6 +1318,8 @@ interface CatalogFilterQuery {
1319
1318
  collectionId?: string[];
1320
1319
  availability?: string;
1321
1320
  option?: string[];
1321
+ /** `onSale=true`, the one boolean parameter the platform has today (`facets.toggles[]`'s `on_sale`). */
1322
+ onSale?: true;
1322
1323
  }
1323
1324
 
1324
1325
  /**
@@ -1396,9 +1397,8 @@ function priceParam(raw: string | undefined, currency: string | undefined): numb
1396
1397
  * URL and the active-filter row all say is applied is a lie, so that one fails the collection read,
1397
1398
  * which the block already draws as an error over the last good page.
1398
1399
  */
1399
- async function readCategories(client: EldraClient): Promise<CategoryIndex> {
1400
- const rows = (await client.catalog.listCategories({})) as unknown as RawCategory[] | null;
1401
- return buildCategoryIndex(rows);
1400
+ async function readCategoryRows(client: EldraClient): Promise<RawCategory[] | null> {
1401
+ return (await client.catalog.listCategories({})) as unknown as RawCategory[] | null;
1402
1402
  }
1403
1403
 
1404
1404
  /**
@@ -1466,6 +1466,11 @@ async function catalogFilterQuery(
1466
1466
  if (known.length === 1) query.availability = known[0];
1467
1467
  continue;
1468
1468
  }
1469
+ if (source.startsWith(TOGGLE_SOURCE_PREFIX)) {
1470
+ // A toggle is a yes/no switch; only the one the platform has a parameter for (onSale) is sent.
1471
+ if (source.slice(TOGGLE_SOURCE_PREFIX.length) === 'on_sale') query.onSale = true;
1472
+ continue;
1473
+ }
1469
1474
  if (source === 'category') {
1470
1475
  const { idBySlug } = await categoriesOnce();
1471
1476
  const matched = selected
@@ -1895,6 +1900,14 @@ async function detailSnapshots(
1895
1900
 
1896
1901
  export interface GatewayStorefrontOptions {
1897
1902
  route: StorefrontRoute;
1903
+ /**
1904
+ * Shares a build-wide read between the storefronts of a prerender (WS-406): `nuxi generate`
1905
+ * creates one storefront per route, so a read that never changes during a build (the category
1906
+ * tree) would otherwise go out once per route. The app layer binds it to the site and passes
1907
+ * `@eldrajs/theme-nuxt/prerender`'s `memoizeForPrerender`, which runs `load` every time outside a
1908
+ * prerender. Omitted — Storybook, a spec — every storefront reads for itself.
1909
+ */
1910
+ shared?: <T>(name: string, load: () => Promise<T>, locale: string | undefined) => Promise<T>;
1898
1911
  /**
1899
1912
  * Overrides where form submissions go (`forms.submit`); see `postToFormsEndpoint`. Form
1900
1913
  * definitions still come from the platform. Also the endpoint `catalog.notifyBackInStock` posts to.
@@ -1992,11 +2005,11 @@ export function createGatewayStorefront(
1992
2005
  /**
1993
2006
  * The store's category tree, read at most once for the life of this storefront and only when
1994
2007
  * something actually needs it: a category filter to resolve, a product page's breadcrumb trail, or
1995
- * a category facet the platform could not place its own terms in (`readCategories`).
2008
+ * a category facet the platform could not place its own terms in (`readCategoryRows`).
1996
2009
  *
1997
2010
  * The in-flight read is what is cached, so a product page and a grid asking at once share one
1998
2011
  * request; a failure drops the cache so the next read tries again rather than inheriting the first
1999
- * one's error. Which callers swallow that failure and which let it through is on `readCategories`.
2012
+ * one's error. Which callers swallow that failure and which let it through is on `readCategoryRows`.
2000
2013
  *
2001
2014
  * It is read on the **server** during a prerender, inside the same `useAsyncData` the product or
2002
2015
  * collection read runs under, so a generated product page carries its trail in the page payload
@@ -2004,10 +2017,17 @@ export function createGatewayStorefront(
2004
2017
  */
2005
2018
  let categories: Promise<CategoryIndex> | null = null;
2006
2019
  const categoriesOnce = (): Promise<CategoryIndex> => {
2007
- categories ??= readCategories(client).catch((caught: unknown) => {
2008
- categories = null;
2009
- throw caught;
2010
- });
2020
+ // The rows, not the index, are what a build shares: the same list `@eldrajs/theme-nuxt` reads
2021
+ // for link targets, under the same memo name and key, so a build reads it once per locale.
2022
+ const read = (): Promise<RawCategory[] | null> => readCategoryRows(client);
2023
+ categories ??= (
2024
+ options.shared === undefined ? read() : options.shared('categories', read, locale?.())
2025
+ )
2026
+ .then((rows) => buildCategoryIndex(rows))
2027
+ .catch((caught: unknown) => {
2028
+ categories = null;
2029
+ throw caught;
2030
+ });
2011
2031
  return categories;
2012
2032
  };
2013
2033
 
@@ -2139,7 +2159,7 @@ export function createGatewayStorefront(
2139
2159
  // add a serial round trip to every product page. The tree's failure is swallowed here — a
2140
2160
  // product page without a category crumb is a product page, while a product page that 500s
2141
2161
  // because the category list was unreachable is not — which is the opposite of what the
2142
- // `category` *filter* does with the same read (`readCategories`).
2162
+ // `category` *filter* does with the same read (`readCategoryRows`).
2143
2163
  const [stock, tree] = await Promise.all([
2144
2164
  readStock(client, raw, signal),
2145
2165
  categoriesOnce().catch(() => null),
@@ -0,0 +1,34 @@
1
+ import {
2
+ CATEGORIES_MEMO_NAME,
3
+ memoizeForPrerender,
4
+ prerenderMemoScope,
5
+ } from '@eldrajs/theme-nuxt/prerender';
6
+
7
+ /**
8
+ * How the storefront shares build-wide reads (WS-406). No Nuxt global is touched: the plugin passes
9
+ * the public runtime config.
10
+ *
11
+ * Reads are keyed gateway + organisation + locale, the same key `@eldrajs/theme-nuxt` uses for its
12
+ * own reads, so a list both ask for (the categories) is read once per build.
13
+ */
14
+ export interface StorefrontSharedConfig {
15
+ gatewayUrl?: string;
16
+ orgId?: string;
17
+ }
18
+
19
+ export type SharedRead = <T>(
20
+ name: string,
21
+ load: () => Promise<T>,
22
+ locale: string | undefined
23
+ ) => Promise<T>;
24
+
25
+ export { CATEGORIES_MEMO_NAME };
26
+
27
+ export function createSharedRead(
28
+ config: StorefrontSharedConfig | undefined,
29
+ memoize: typeof memoizeForPrerender = memoizeForPrerender
30
+ ): SharedRead {
31
+ const gatewayUrl = config?.gatewayUrl ?? '';
32
+ return (name, load, locale) =>
33
+ memoize(prerenderMemoScope(gatewayUrl, config?.orgId, locale), name, load);
34
+ }
@@ -58,6 +58,15 @@ export interface PageLdParts {
58
58
  logoUrl: string | null;
59
59
  sameAs: readonly string[];
60
60
  contact: { email: string | null; telephone: string | null };
61
+ /** The registered company (`useSiteProfile().legal`), or `null`. */
62
+ legal: {
63
+ name: string | null;
64
+ kennitala: string;
65
+ streetAddress: string | null;
66
+ postalCode: string | null;
67
+ city: string | null;
68
+ countryCode: string | null;
69
+ } | null;
61
70
  };
62
71
  /** The site's search page path (`/search`, unprefixed: it follows the home URL), or `null` when
63
72
  * the site has none. */
@@ -109,6 +118,14 @@ export function pageStructuredData(parts: PageLdParts): StructuredDataEntry[] {
109
118
  logo: parts.profile.logoUrl,
110
119
  sameAs: parts.profile.sameAs,
111
120
  contact: parts.profile.contact,
121
+ legalName: parts.profile.legal?.name,
122
+ taxID: parts.profile.legal?.kennitala,
123
+ address: parts.profile.legal && {
124
+ streetAddress: parts.profile.legal.streetAddress,
125
+ postalCode: parts.profile.legal.postalCode,
126
+ addressLocality: parts.profile.legal.city,
127
+ addressCountry: parts.profile.legal.countryCode,
128
+ },
112
129
  }),
113
130
  },
114
131
  {
@@ -142,8 +159,8 @@ export function pageStructuredData(parts: PageLdParts): StructuredDataEntry[] {
142
159
  name: product.title,
143
160
  description: ldPlainText(product.description),
144
161
  images: product.images.map((image) => image.src),
145
- // A product with no brand of its own is sold under the shop's name (the site profile's).
146
- brand: product.brand ?? parts.profile.name,
162
+ // Products carry no brand of their own: they are sold under the shop's name.
163
+ brand: parts.profile.name,
147
164
  variants: variantsOf(product, parts.currentUrl),
148
165
  currency: parts.currency,
149
166
  ratings: product.rating,
@@ -179,11 +179,6 @@ export interface StorefrontProduct extends StorefrontProductListItem {
179
179
  */
180
180
  inventory: number | null;
181
181
  shipsBy?: string | null;
182
- /**
183
- * The product's brand, when the platform carries one (`brand` on the public product read). Read
184
- * by the page's structured data only; the page itself does not show it.
185
- */
186
- brand?: string | null;
187
182
  /**
188
183
  * **Every variant, with the price and stock the page's own variant resolves from** — what the
189
184
  * page's structured data writes one offer per. Absent from a source that has no variants to
@@ -0,0 +1,11 @@
1
+ const CHUNK_ERROR =
2
+ /dynamically imported module|importing a module script failed|error loading dynamically imported module/i;
3
+
4
+ export function isChunkError(error: unknown): boolean {
5
+ return CHUNK_ERROR.test(error instanceof Error ? error.message : String(error));
6
+ }
7
+
8
+ /** One reload per window of `windowMs`, so a chunk that stays missing cannot reload the page forever. */
9
+ export function shouldReload(now: number, lastReloadAt: number | null, windowMs = 30_000): boolean {
10
+ return lastReloadAt === null || now - lastReloadAt > windowMs;
11
+ }
@@ -72,7 +72,6 @@ export function seoInput(parts: SeoInputParts): SeoInput {
72
72
  data['product.sku'] = text(variants[0]?.sku) ?? '';
73
73
  data['product.price'] = prices.length === 0 ? '' : parts.formatPrice(Math.min(...prices));
74
74
  data['product.shortDescription'] = shortDescription(entryData.description);
75
- data['product.brand'] = text(entryData.brand) ?? '';
76
75
  data['product.category'] = text(parts.productCategory) ?? '';
77
76
  contentImage = shareImage(list(entryData.images)[0]);
78
77
  } else if (catalogKind !== null) {
Binary file