@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.
- package/dist/cli.js +2 -3
- package/dist/index.d.ts +0 -12
- package/dist/index.js +1 -1
- package/dist/{validate-DprFpjV7.js → validate-FjQ-5_ne.js} +9 -18
- package/package.json +3 -3
- package/template/.eldra/previews.json +35 -35
- package/template/app/plugins/chunk-reload.client.ts +29 -0
- package/template/app/plugins/eldra-storefront.ts +5 -0
- package/template/app/storefront/gateway.ts +34 -14
- package/template/app/storefront/sharedRead.ts +34 -0
- package/template/app/storefront/structuredData.ts +19 -2
- package/template/app/storefront/types.ts +0 -5
- package/template/app/utils/chunkReload.ts +11 -0
- package/template/app/utils/seoInput.ts +0 -1
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +146 -94
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +125 -541
- package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
- package/template/blocks/navigation/parts/MenuLink.vue +15 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/package.json +1 -1
- package/template/test/chunkReload.spec.ts +20 -0
- package/template/test/imageFraming.browser.spec.ts +125 -0
- package/template/test/pages/article.spec.ts +1 -1
- package/template/test/pages/collection.spec.ts +1 -1
- package/template/test/pages/home.spec.ts +1 -1
- package/template/test/pages/product.spec.ts +1 -1
- package/template/test/prerenderRefresh.browser.spec.ts +58 -13
- package/template/test/seoInput.spec.ts +5 -4
- package/template/test/storefront/gateway.spec.ts +6 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
- package/template/test/storefront/sharedRead.spec.ts +43 -0
- package/template/test/storefront/structuredData.spec.ts +34 -6
- package/template/test/structuredData.generate.spec.ts +1 -1
- package/template/test/support/mockGateway.ts +8 -3
- 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-
|
|
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
|
-
|
|
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-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
46
|
-
"@eldrajs/vite-plugin-theme": "^0.3.
|
|
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": "
|
|
3
|
-
"article": "
|
|
4
|
-
"article-list": "
|
|
5
|
-
"breadcrumbs": "
|
|
6
|
-
"cart": "
|
|
7
|
-
"collection-grid": "
|
|
8
|
-
"collection-header": "
|
|
9
|
-
"contact": "
|
|
10
|
-
"cta": "
|
|
11
|
-
"faq": "
|
|
12
|
-
"feature-grid": "
|
|
13
|
-
"footer": "
|
|
14
|
-
"form": "
|
|
15
|
-
"gallery": "
|
|
16
|
-
"hero": "
|
|
17
|
-
"image": "
|
|
18
|
-
"logo-cloud": "
|
|
19
|
-
"navigation": "
|
|
20
|
-
"newsletter": "
|
|
21
|
-
"order-status": "
|
|
22
|
-
"pricing-table": "
|
|
23
|
-
"product-carousel": "
|
|
24
|
-
"product-detail": "
|
|
25
|
-
"quote": "
|
|
26
|
-
"rich-text": "
|
|
27
|
-
"search": "
|
|
28
|
-
"split-content": "
|
|
29
|
-
"stats": "
|
|
30
|
-
"tabs": "
|
|
31
|
-
"team": "
|
|
32
|
-
"testimonials": "
|
|
33
|
-
"timeline": "
|
|
34
|
-
"trust-strip": "
|
|
35
|
-
"video-embed": "
|
|
36
|
-
"wishlist": "
|
|
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
|
-
* `
|
|
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
|
|
1400
|
-
|
|
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 (`
|
|
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 `
|
|
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
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
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 (`
|
|
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
|
-
//
|
|
146
|
-
brand:
|
|
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
|
|
Binary file
|
|
Binary file
|