@zappie/sdk 0.1.13 → 0.1.15
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 +12 -0
- package/dist/config/index.d.ts +18 -1
- package/dist/debug.js +1 -1
- package/dist/index.js +1 -1
- package/dist/server/index.d.ts +16 -0
- package/dist/site-config/sections.js +13 -6
- package/dist/site-config/sections.js.map +2 -2
- package/dist/site-config/types.js +2 -1
- package/dist/site-config/types.js.map +2 -2
- package/dist/site-config/validate.js +28 -24
- package/dist/site-config/validate.js.map +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @zappie/sdk
|
|
2
2
|
|
|
3
|
+
## 0.1.15
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b0b2a59: Let a site raise V15's first-card tappable limit to 5000 ms with an explained site budget, and record the applied limit in the verify report. A site that adds `budgets.tappableMs` must upgrade `@zappie/check` and `@zappie/sdk` in the same change.
|
|
8
|
+
|
|
9
|
+
## 0.1.14
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5a2bce9: Verify can start somewhere other than `/`, for a site whose root is a directory of its menus. Set `verify.startPath` in `zappie.config.ts`, or pass `startPath` to `verify()` or `verifyProject()`. Every check that opened `/` as the menu opens that route instead. Set `verify.cataloguePath`, such as `/menu?menu={menu}`, when each menu has its own page: V03 then needs 95% of each menu's available items on that menu's page, instead of 95% of the branch's items on one page, and the checks that use an item open the page of a menu that holds it. A route must start with one `/` and contain no backslash. A site that sets neither runs as before. The report's `environment` records `startPath`, and `cataloguePath` when it is set. When `--store` is passed and `zappie.config.ts` exists but can't be read, the report's `warnings` says its verify settings were ignored. The `@zappie/sdk` site config and `zappie check` accept the `verify` settings, so a site that adds them needs `@zappie/sdk` 0.1.14 and `@zappie/check` 0.2.4 in the same change. This is a minor release, so a regression comparison doesn't compare these reports with reports from 0.2.
|
|
14
|
+
|
|
3
15
|
## 0.1.13
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Default site budgets: 200 KB gzipped JavaScript, 50 KB gzipped CSS and
|
|
2
|
+
* Default site budgets: 200 KB gzipped JavaScript, 50 KB gzipped CSS, 2500 ms LCP and 3000 ms until the first product card is tappable.
|
|
3
3
|
*/
|
|
4
4
|
declare const DEFAULT_BUDGETS: {
|
|
5
5
|
readonly jsKbGz: 200;
|
|
6
6
|
readonly cssKbGz: 50;
|
|
7
7
|
readonly lcpMs: 2500;
|
|
8
|
+
readonly tappableMs: 3000;
|
|
8
9
|
};
|
|
9
10
|
/**
|
|
10
11
|
* Package names and patterns allowed globally without a site-specific allowlist entry.
|
|
@@ -50,6 +51,8 @@ type ZappieSiteConfig = {
|
|
|
50
51
|
jsKbGz?: number;
|
|
51
52
|
cssKbGz?: number;
|
|
52
53
|
lcpMs?: number;
|
|
54
|
+
/** V15's limit for the first product card to become tappable. Values below 3000 use 3000. */
|
|
55
|
+
tappableMs?: number;
|
|
53
56
|
override?: {
|
|
54
57
|
reason: string;
|
|
55
58
|
};
|
|
@@ -71,6 +74,20 @@ type ZappieSiteConfig = {
|
|
|
71
74
|
metaPixel?: string;
|
|
72
75
|
};
|
|
73
76
|
};
|
|
77
|
+
/** Where `zappie verify` opens the storefront and finds each catalogue. */
|
|
78
|
+
verify?: {
|
|
79
|
+
/**
|
|
80
|
+
* The route verify opens as the menu, such as /menu. It must list items. Defaults to /.
|
|
81
|
+
* `{menu}` stands for the first menu that holds items and `{branch}` for the default branch,
|
|
82
|
+
* such as `/menu?menu={menu}`.
|
|
83
|
+
*/
|
|
84
|
+
startPath?: string;
|
|
85
|
+
/**
|
|
86
|
+
* The page for each menu, with `{menu}` where its id goes and, optionally, `{branch}` for the
|
|
87
|
+
* branch id, such as `/menu?menu={menu}`. Verify then judges each menu on its own page.
|
|
88
|
+
*/
|
|
89
|
+
cataloguePath?: string;
|
|
90
|
+
};
|
|
74
91
|
};
|
|
75
92
|
/**
|
|
76
93
|
* A configuration diagnostic with its field path, stable code, message and severity.
|
package/dist/debug.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { ZappieError, isZappieError } from "./errors.js";
|
|
|
10
10
|
export * from "./models.js";
|
|
11
11
|
import { format, money } from "./money.js";
|
|
12
12
|
import { RestTransport } from "./transport/rest.js";
|
|
13
|
-
var VERSION = true ? "0.1.
|
|
13
|
+
var VERSION = true ? "0.1.15" : "0.0.0-development";
|
|
14
14
|
export {
|
|
15
15
|
API_VERSION,
|
|
16
16
|
RestTransport,
|
package/dist/server/index.d.ts
CHANGED
|
@@ -202,6 +202,8 @@ type ZappieSiteConfig = {
|
|
|
202
202
|
jsKbGz?: number;
|
|
203
203
|
cssKbGz?: number;
|
|
204
204
|
lcpMs?: number;
|
|
205
|
+
/** V15's limit for the first product card to become tappable. Values below 3000 use 3000. */
|
|
206
|
+
tappableMs?: number;
|
|
205
207
|
override?: {
|
|
206
208
|
reason: string;
|
|
207
209
|
};
|
|
@@ -223,6 +225,20 @@ type ZappieSiteConfig = {
|
|
|
223
225
|
metaPixel?: string;
|
|
224
226
|
};
|
|
225
227
|
};
|
|
228
|
+
/** Where `zappie verify` opens the storefront and finds each catalogue. */
|
|
229
|
+
verify?: {
|
|
230
|
+
/**
|
|
231
|
+
* The route verify opens as the menu, such as /menu. It must list items. Defaults to /.
|
|
232
|
+
* `{menu}` stands for the first menu that holds items and `{branch}` for the default branch,
|
|
233
|
+
* such as `/menu?menu={menu}`.
|
|
234
|
+
*/
|
|
235
|
+
startPath?: string;
|
|
236
|
+
/**
|
|
237
|
+
* The page for each menu, with `{menu}` where its id goes and, optionally, `{branch}` for the
|
|
238
|
+
* branch id, such as `/menu?menu={menu}`. Verify then judges each menu on its own page.
|
|
239
|
+
*/
|
|
240
|
+
cataloguePath?: string;
|
|
241
|
+
};
|
|
226
242
|
};
|
|
227
243
|
|
|
228
244
|
/** Inputs for a storefront document's report-only security headers. */
|
|
@@ -21,7 +21,7 @@ function budgets(value, issue, error) {
|
|
|
21
21
|
nested(
|
|
22
22
|
value,
|
|
23
23
|
"budgets",
|
|
24
|
-
[
|
|
24
|
+
[...Object.keys(DEFAULT_BUDGETS), "override"],
|
|
25
25
|
issue,
|
|
26
26
|
(budget) => {
|
|
27
27
|
nested(
|
|
@@ -39,28 +39,35 @@ function budgets(value, issue, error) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
);
|
|
42
|
-
for (const key of
|
|
42
|
+
for (const key of Object.keys(DEFAULT_BUDGETS)) {
|
|
43
43
|
const amount = budget[key];
|
|
44
|
+
const path = `budgets.${key}`;
|
|
44
45
|
if (amount === void 0) {
|
|
45
46
|
continue;
|
|
46
47
|
}
|
|
47
48
|
if (typeof amount !== "number" || !Number.isFinite(amount) || amount <= 0) {
|
|
48
49
|
error(
|
|
49
|
-
|
|
50
|
+
path,
|
|
50
51
|
"invalid_type",
|
|
51
|
-
`Expected a positive finite number. Set
|
|
52
|
+
`Expected a positive finite number. Set ${path} to a number greater than zero.`
|
|
53
|
+
);
|
|
54
|
+
} else if (key === "tappableMs" && amount > 5e3) {
|
|
55
|
+
error(
|
|
56
|
+
path,
|
|
57
|
+
"invalid_format",
|
|
58
|
+
"The tappableMs budget cannot exceed 5000. Set budgets.tappableMs to 5000 or less."
|
|
52
59
|
);
|
|
53
60
|
} else if (amount > DEFAULT_BUDGETS[key]) {
|
|
54
61
|
const message = `The ${key} budget exceeds the ${DEFAULT_BUDGETS[key]} default.`;
|
|
55
62
|
if (budget.override === void 0) {
|
|
56
63
|
error(
|
|
57
|
-
|
|
64
|
+
path,
|
|
58
65
|
"budget_override",
|
|
59
66
|
`${message} Add budgets.override.reason to explain the increase.`
|
|
60
67
|
);
|
|
61
68
|
} else {
|
|
62
69
|
issue({
|
|
63
|
-
path
|
|
70
|
+
path,
|
|
64
71
|
code: "budget_override",
|
|
65
72
|
message: `${message} Lower it to the default when the exception is no longer needed.`,
|
|
66
73
|
severity: "warning"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/site-config/sections.ts"],
|
|
4
|
-
"sourcesContent": ["import { record, unknownKeys } from \"./helpers\";\nimport { DEFAULT_BUDGETS, type ConfigIssue } from \"./types\";\n\ntype AddIssue = (value: ConfigIssue) => void;\ntype AddError = (\n path: string,\n code: ConfigIssue[\"code\"],\n message: string,\n) => void;\n\nexport function nested(\n value: unknown,\n path: string,\n keys: readonly string[],\n issue: AddIssue,\n validate: (value: Record<string, unknown>) => void,\n) {\n if (value === undefined) {\n return;\n }\n if (!record(value)) {\n issue({\n path,\n code: \"invalid_type\",\n message: `Expected an object. Set ${path} to an object or remove it.`,\n severity: \"error\",\n });\n return;\n }\n unknownKeys(value, keys, path, issue);\n validate(value);\n}\n\nexport function budgets(value: unknown, issue: AddIssue, error: AddError) {\n nested(\n value,\n \"budgets\",\n [
|
|
5
|
-
"mappings": ";AAAA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,uBAAyC;AAS3C,SAAS,OACd,OACA,MACA,MACA,OACA,UACA;AACA,MAAI,UAAU,QAAW;AACvB;AAAA,EACF;AACA,MAAI,CAAC,OAAO,KAAK,GAAG;AAClB,UAAM;AAAA,MACJ;AAAA,MACA,MAAM;AAAA,MACN,SAAS,2BAA2B,IAAI;AAAA,MACxC,UAAU;AAAA,IACZ,CAAC;AACD;AAAA,EACF;AACA,cAAY,OAAO,MAAM,MAAM,KAAK;AACpC,WAAS,KAAK;AAChB;AAEO,SAAS,QAAQ,OAAgB,OAAiB,OAAiB;AACxE;AAAA,IACE;AAAA,IACA;AAAA,IACA,CAAC,
|
|
4
|
+
"sourcesContent": ["import { record, unknownKeys } from \"./helpers\";\nimport { DEFAULT_BUDGETS, type ConfigIssue } from \"./types\";\n\ntype AddIssue = (value: ConfigIssue) => void;\ntype AddError = (\n path: string,\n code: ConfigIssue[\"code\"],\n message: string,\n) => void;\n\nexport function nested(\n value: unknown,\n path: string,\n keys: readonly string[],\n issue: AddIssue,\n validate: (value: Record<string, unknown>) => void,\n) {\n if (value === undefined) {\n return;\n }\n if (!record(value)) {\n issue({\n path,\n code: \"invalid_type\",\n message: `Expected an object. Set ${path} to an object or remove it.`,\n severity: \"error\",\n });\n return;\n }\n unknownKeys(value, keys, path, issue);\n validate(value);\n}\n\nexport function budgets(value: unknown, issue: AddIssue, error: AddError) {\n nested(\n value,\n \"budgets\",\n [...Object.keys(DEFAULT_BUDGETS), \"override\"],\n issue,\n (budget) => {\n nested(\n budget.override,\n \"budgets.override\",\n [\"reason\"],\n issue,\n (override) => {\n if (typeof override.reason !== \"string\" || !override.reason.trim()) {\n error(\n \"budgets.override.reason\",\n \"invalid_format\",\n \"Expected a non-blank reason. Explain why the default budget must be raised.\",\n );\n }\n },\n );\n for (const key of Object.keys(DEFAULT_BUDGETS) as Array<\n keyof typeof DEFAULT_BUDGETS\n >) {\n const amount = budget[key];\n const path = `budgets.${key}`;\n if (amount === undefined) {\n continue;\n }\n if (\n typeof amount !== \"number\" ||\n !Number.isFinite(amount) ||\n amount <= 0\n ) {\n error(\n path,\n \"invalid_type\",\n `Expected a positive finite number. Set ${path} to a number greater than zero.`,\n );\n } else if (key === \"tappableMs\" && amount > 5_000) {\n error(\n path,\n \"invalid_format\",\n \"The tappableMs budget cannot exceed 5000. Set budgets.tappableMs to 5000 or less.\",\n );\n } else if (amount > DEFAULT_BUDGETS[key]) {\n const message = `The ${key} budget exceeds the ${DEFAULT_BUDGETS[key]} default.`;\n if (budget.override === undefined) {\n error(\n path,\n \"budget_override\",\n `${message} Add budgets.override.reason to explain the increase.`,\n );\n } else {\n issue({\n path,\n code: \"budget_override\",\n message: `${message} Lower it to the default when the exception is no longer needed.`,\n severity: \"warning\",\n });\n }\n }\n }\n },\n );\n}\n\nexport function analytics(value: unknown, issue: AddIssue, error: AddError) {\n nested(value, \"analytics\", [\"forward\"], issue, (analyticsValue) => {\n nested(\n analyticsValue.forward,\n \"analytics.forward\",\n [\"ga4\", \"metaPixel\"],\n issue,\n (forward) => {\n if (\n forward.ga4 !== undefined &&\n (typeof forward.ga4 !== \"string\" ||\n !/^G-[A-Z0-9]+$/.test(forward.ga4))\n ) {\n error(\n \"analytics.forward.ga4\",\n \"invalid_format\",\n \"Expected a GA4 measurement id beginning with G-. Use a value such as G-XXXXXXXXXX.\",\n );\n }\n if (\n forward.metaPixel !== undefined &&\n (typeof forward.metaPixel !== \"string\" ||\n !/^\\d+$/.test(forward.metaPixel))\n ) {\n error(\n \"analytics.forward.metaPixel\",\n \"invalid_format\",\n \"Expected a numeric Meta Pixel id. Use digits only.\",\n );\n }\n },\n );\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,uBAAyC;AAS3C,SAAS,OACd,OACA,MACA,MACA,OACA,UACA;AACA,MAAI,UAAU,QAAW;AACvB;AAAA,EACF;AACA,MAAI,CAAC,OAAO,KAAK,GAAG;AAClB,UAAM;AAAA,MACJ;AAAA,MACA,MAAM;AAAA,MACN,SAAS,2BAA2B,IAAI;AAAA,MACxC,UAAU;AAAA,IACZ,CAAC;AACD;AAAA,EACF;AACA,cAAY,OAAO,MAAM,MAAM,KAAK;AACpC,WAAS,KAAK;AAChB;AAEO,SAAS,QAAQ,OAAgB,OAAiB,OAAiB;AACxE;AAAA,IACE;AAAA,IACA;AAAA,IACA,CAAC,GAAG,OAAO,KAAK,eAAe,GAAG,UAAU;AAAA,IAC5C;AAAA,IACA,CAAC,WAAW;AACV;AAAA,QACE,OAAO;AAAA,QACP;AAAA,QACA,CAAC,QAAQ;AAAA,QACT;AAAA,QACA,CAAC,aAAa;AACZ,cAAI,OAAO,SAAS,WAAW,YAAY,CAAC,SAAS,OAAO,KAAK,GAAG;AAClE;AAAA,cACE;AAAA,cACA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,QAAQ,SAAS,IACjC;AACA;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/site-config/types.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Default site budgets: 200 KB gzipped JavaScript, 50 KB gzipped CSS and
|
|
5
|
-
"mappings": ";AAGO,IAAM,kBAAkB;AAAA,EAC7B,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,OAAO;
|
|
4
|
+
"sourcesContent": ["/**\n * Default site budgets: 200 KB gzipped JavaScript, 50 KB gzipped CSS, 2500 ms LCP and 3000 ms until the first product card is tappable.\n */\nexport const DEFAULT_BUDGETS = {\n jsKbGz: 200,\n cssKbGz: 50,\n lcpMs: 2500,\n tappableMs: 3000,\n} as const;\n\n/**\n * Package names and patterns allowed globally without a site-specific allowlist entry.\n */\nexport const GLOBAL_PACKAGE_ALLOWLIST = [\n \"react\",\n \"react-dom\",\n \"react-router\",\n \"@react-router/*\",\n \"@zappie/*\",\n \"tailwindcss\",\n \"@tailwindcss/*\",\n \"clsx\",\n \"tailwind-merge\",\n \"class-variance-authority\",\n \"lucide-react\",\n \"date-fns\",\n \"embla-carousel-react\",\n \"framer-motion/motion\",\n \"zod\",\n \"@radix-ui/*\",\n \"sonner\",\n \"vaul\",\n] as const;\n\n/**\n * The store, theme and optional build policies you export from zappie.config.ts.\n */\nexport type ZappieSiteConfig = {\n store: string;\n branches?: string[];\n theme: string;\n prerender?: string[];\n menu?: { hiddenCategories?: string[] };\n packages?: { allow?: string[] };\n /** Time-bounded acknowledgements for advisories that have no fixed version. */\n audit?: {\n ignore?: { id: string; reason: string; until: string }[];\n };\n outbound?: { allow?: string[] };\n /** Add sources to the fixed storefront Content Security Policy. */\n security?: {\n csp?: {\n imgSrc?: string[];\n connectSrc?: string[];\n fontSrc?: string[];\n styleSrc?: string[];\n frameSrc?: string[];\n };\n };\n /** Each budget left out uses DEFAULT_BUDGETS. */\n budgets?: {\n jsKbGz?: number;\n cssKbGz?: number;\n lcpMs?: number;\n /** V15's limit for the first product card to become tappable. Values below 3000 use 3000. */\n tappableMs?: number;\n override?: { reason: string };\n };\n /** Records explained exceptions to storefront readiness checks. */\n readiness?: {\n /** Lets this site skip the initial route discovery requirement. */\n routeDiscovery?: {\n /** Explains why this site does not use initial route discovery. */\n optOut: {\n /** States the constraint that prevents initial route discovery. */\n reason: string;\n };\n };\n };\n analytics?: { forward?: { ga4?: string; metaPixel?: string } };\n /** Where `zappie verify` opens the storefront and finds each catalogue. */\n verify?: {\n /**\n * The route verify opens as the menu, such as /menu. It must list items. Defaults to /.\n * `{menu}` stands for the first menu that holds items and `{branch}` for the default branch,\n * such as `/menu?menu={menu}`.\n */\n startPath?: string;\n /**\n * The page for each menu, with `{menu}` where its id goes and, optionally, `{branch}` for the\n * branch id, such as `/menu?menu={menu}`. Verify then judges each menu on its own page.\n */\n cataloguePath?: string;\n };\n};\n\n/**\n * A configuration diagnostic with its field path, stable code, message and severity.\n */\nexport type ConfigIssue = {\n path: string;\n code:\n | \"invalid_type\"\n | \"missing_required\"\n | \"unknown_key\"\n | \"invalid_format\"\n | \"duplicate\"\n | \"redundant_allowlist\"\n | \"budget_override\";\n message: string;\n severity: \"error\" | \"warning\";\n};\n\n/**\n * Configuration validation results. Warnings alone do not make valid false.\n */\nexport type ConfigValidation = { valid: boolean; issues: ConfigIssue[] };\n"],
|
|
5
|
+
"mappings": ";AAGO,IAAM,kBAAkB;AAAA,EAC7B,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,OAAO;AAAA,EACP,YAAY;AACd;AAKO,IAAM,2BAA2B;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -20,7 +20,8 @@ var rootKeys = [
|
|
|
20
20
|
"security",
|
|
21
21
|
"budgets",
|
|
22
22
|
"readiness",
|
|
23
|
-
"analytics"
|
|
23
|
+
"analytics",
|
|
24
|
+
"verify"
|
|
24
25
|
];
|
|
25
26
|
function validateConfig(input) {
|
|
26
27
|
const issues = [];
|
|
@@ -40,14 +41,30 @@ function validateConfig(input) {
|
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
unknownKeys(input, rootKeys, "", issue);
|
|
43
|
-
|
|
44
|
+
if (!nonblank(input.store)) {
|
|
45
|
+
error(
|
|
46
|
+
"store",
|
|
47
|
+
input.store === void 0 ? "missing_required" : "invalid_type",
|
|
48
|
+
"Expected a non-empty storefront slug. Set store to the slug used by createZappie()."
|
|
49
|
+
);
|
|
50
|
+
}
|
|
44
51
|
theme(input.theme, error);
|
|
45
52
|
stringList(input.branches, "branches", error, {
|
|
46
53
|
nonempty: true,
|
|
47
54
|
unique: true,
|
|
48
55
|
slug: true
|
|
49
56
|
});
|
|
50
|
-
|
|
57
|
+
stringList(input.prerender, "prerender", error, { unique: true })?.forEach(
|
|
58
|
+
(path, index) => {
|
|
59
|
+
if (!path.startsWith("/")) {
|
|
60
|
+
error(
|
|
61
|
+
`prerender[${index}]`,
|
|
62
|
+
"invalid_format",
|
|
63
|
+
"Expected a route starting with /. Prefix the route with /."
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
);
|
|
51
68
|
nested(input.menu, "menu", ["hiddenCategories"], issue, (value) => {
|
|
52
69
|
stringList(value.hiddenCategories, "menu.hiddenCategories", error);
|
|
53
70
|
});
|
|
@@ -119,20 +136,19 @@ function validateConfig(input) {
|
|
|
119
136
|
}
|
|
120
137
|
);
|
|
121
138
|
analytics(input.analytics, issue, error);
|
|
139
|
+
nested(
|
|
140
|
+
input.verify,
|
|
141
|
+
"verify",
|
|
142
|
+
["startPath", "cataloguePath"],
|
|
143
|
+
issue,
|
|
144
|
+
() => {
|
|
145
|
+
}
|
|
146
|
+
);
|
|
122
147
|
return {
|
|
123
148
|
valid: !issues.some((entry) => entry.severity === "error"),
|
|
124
149
|
issues
|
|
125
150
|
};
|
|
126
151
|
}
|
|
127
|
-
function requiredSlug(value, path, error) {
|
|
128
|
-
if (!nonblank(value)) {
|
|
129
|
-
error(
|
|
130
|
-
path,
|
|
131
|
-
value === void 0 ? "missing_required" : "invalid_type",
|
|
132
|
-
`Expected a non-empty storefront slug. Set ${path} to the slug used by createZappie().`
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
152
|
function theme(value, error) {
|
|
137
153
|
if (typeof value !== "string") {
|
|
138
154
|
error(
|
|
@@ -196,18 +212,6 @@ function hostList(value, path, error) {
|
|
|
196
212
|
}
|
|
197
213
|
});
|
|
198
214
|
}
|
|
199
|
-
function paths(value, error) {
|
|
200
|
-
const values = stringList(value, "prerender", error, { unique: true });
|
|
201
|
-
values?.forEach((path, index) => {
|
|
202
|
-
if (!path.startsWith("/")) {
|
|
203
|
-
error(
|
|
204
|
-
`prerender[${index}]`,
|
|
205
|
-
"invalid_format",
|
|
206
|
-
"Expected a route starting with /. Prefix the route with /."
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
215
|
export {
|
|
212
216
|
validateConfig
|
|
213
217
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/site-config/validate.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n globallyAllowed,\n hostname,\n nonblank,\n packageName,\n record,\n unknownKeys,\n} from \"./helpers\";\nimport { analytics, budgets, nested } from \"./sections\";\nimport type { ConfigIssue, ConfigValidation } from \"./types\";\n\nconst rootKeys = [\n \"store\",\n \"branches\",\n \"theme\",\n \"prerender\",\n \"menu\",\n \"packages\",\n \"audit\",\n \"outbound\",\n \"security\",\n \"budgets\",\n \"readiness\",\n \"analytics\",\n] as const;\n\n/**\n * Validate a site configuration and collect errors and warnings without changing it.\n * Checks required fields, unknown keys, allowlists, budgets and analytics settings.\n *\n * @param input - The configuration value to inspect.\n * @returns Diagnostics and a valid flag that is true when there are no errors.\n */\nexport function validateConfig(input: unknown): ConfigValidation {\n const issues: ConfigIssue[] = [];\n const issue = (value: ConfigIssue) => issues.push(value);\n const error = (path: string, code: ConfigIssue[\"code\"], message: string) =>\n issue({ path, code, message, severity: \"error\" });\n if (!record(input)) {\n return {\n valid: false,\n issues: [\n {\n path: \"$\",\n code: \"invalid_type\",\n message:\n \"Expected a configuration object. Export an object from zappie.config.ts.\",\n severity: \"error\",\n },\n ],\n };\n }\n unknownKeys(input, rootKeys, \"\", issue);\n
|
|
5
|
-
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,SAAS,cAAc;AAG3C,IAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AASO,SAAS,eAAe,OAAkC;AAC/D,QAAM,SAAwB,CAAC;AAC/B,QAAM,QAAQ,CAAC,UAAuB,OAAO,KAAK,KAAK;AACvD,QAAM,QAAQ,CAAC,MAAc,MAA2B,YACtD,MAAM,EAAE,MAAM,MAAM,SAAS,UAAU,QAAQ,CAAC;AAClD,MAAI,CAAC,OAAO,KAAK,GAAG;AAClB,WAAO;AAAA,MACL,OAAO;AAAA,MACP,QAAQ;AAAA,QACN;AAAA,UACE,MAAM;AAAA,UACN,MAAM;AAAA,UACN,SACE;AAAA,UACF,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,cAAY,OAAO,UAAU,IAAI,KAAK;AACtC,
|
|
4
|
+
"sourcesContent": ["import {\n globallyAllowed,\n hostname,\n nonblank,\n packageName,\n record,\n unknownKeys,\n} from \"./helpers\";\nimport { analytics, budgets, nested } from \"./sections\";\nimport type { ConfigIssue, ConfigValidation } from \"./types\";\n\nconst rootKeys = [\n \"store\",\n \"branches\",\n \"theme\",\n \"prerender\",\n \"menu\",\n \"packages\",\n \"audit\",\n \"outbound\",\n \"security\",\n \"budgets\",\n \"readiness\",\n \"analytics\",\n \"verify\",\n] as const;\n\n/**\n * Validate a site configuration and collect errors and warnings without changing it.\n * Checks required fields, unknown keys, allowlists, budgets and analytics settings.\n *\n * @param input - The configuration value to inspect.\n * @returns Diagnostics and a valid flag that is true when there are no errors.\n */\nexport function validateConfig(input: unknown): ConfigValidation {\n const issues: ConfigIssue[] = [];\n const issue = (value: ConfigIssue) => issues.push(value);\n const error = (path: string, code: ConfigIssue[\"code\"], message: string) =>\n issue({ path, code, message, severity: \"error\" });\n if (!record(input)) {\n return {\n valid: false,\n issues: [\n {\n path: \"$\",\n code: \"invalid_type\",\n message:\n \"Expected a configuration object. Export an object from zappie.config.ts.\",\n severity: \"error\",\n },\n ],\n };\n }\n unknownKeys(input, rootKeys, \"\", issue);\n if (!nonblank(input.store)) {\n error(\n \"store\",\n input.store === undefined ? \"missing_required\" : \"invalid_type\",\n \"Expected a non-empty storefront slug. Set store to the slug used by createZappie().\",\n );\n }\n theme(input.theme, error);\n stringList(input.branches, \"branches\", error, {\n nonempty: true,\n unique: true,\n slug: true,\n });\n stringList(input.prerender, \"prerender\", error, { unique: true })?.forEach(\n (path, index) => {\n if (!path.startsWith(\"/\")) {\n error(\n `prerender[${index}]`,\n \"invalid_format\",\n \"Expected a route starting with /. Prefix the route with /.\",\n );\n }\n },\n );\n nested(input.menu, \"menu\", [\"hiddenCategories\"], issue, (value) => {\n stringList(value.hiddenCategories, \"menu.hiddenCategories\", error);\n });\n nested(input.packages, \"packages\", [\"allow\"], issue, (value) => {\n const allow = stringList(value.allow, \"packages.allow\", error);\n allow?.forEach((name, index) => {\n if (globallyAllowed(name)) {\n issue({\n path: `packages.allow[${index}]`,\n code: \"redundant_allowlist\",\n message: `${name} is already globally allowed. Remove it from packages.allow.`,\n severity: \"warning\",\n });\n } else if (!packageName(name)) {\n error(\n `packages.allow[${index}]`,\n \"invalid_format\",\n \"Expected a lowercase npm package name. Use a package name such as lucide-react or @scope/name.\",\n );\n }\n });\n });\n nested(input.outbound, \"outbound\", [\"allow\"], issue, (value) => {\n hostList(value.allow, \"outbound.allow\", error);\n });\n nested(input.security, \"security\", [\"csp\"], issue, (security) => {\n nested(\n security.csp,\n \"security.csp\",\n [\"imgSrc\", \"connectSrc\", \"fontSrc\", \"styleSrc\", \"frameSrc\"],\n issue,\n (csp) => {\n for (const [name, value] of Object.entries(csp)) {\n hostList(value, `security.csp.${name}`, error);\n }\n },\n );\n });\n budgets(input.budgets, issue, error);\n nested(\n input.readiness,\n \"readiness\",\n [\"routeDiscovery\"],\n issue,\n (readiness) => {\n nested(\n readiness.routeDiscovery,\n \"readiness.routeDiscovery\",\n [\"optOut\"],\n issue,\n (routeDiscovery) => {\n nested(\n routeDiscovery.optOut,\n \"readiness.routeDiscovery.optOut\",\n [\"reason\"],\n issue,\n (optOut) => {\n if (typeof optOut.reason !== \"string\" || !optOut.reason.trim()) {\n error(\n \"readiness.routeDiscovery.optOut.reason\",\n \"invalid_format\",\n \"Expected a non-blank reason. Explain why the site disables initial route discovery.\",\n );\n }\n },\n );\n },\n );\n },\n );\n analytics(input.analytics, issue, error);\n // Verify checks the routes themselves when it runs.\n nested(\n input.verify,\n \"verify\",\n [\"startPath\", \"cataloguePath\"],\n issue,\n () => {},\n );\n return {\n valid: !issues.some((entry) => entry.severity === \"error\"),\n issues,\n };\n}\n\ntype AddError = (\n path: string,\n code: ConfigIssue[\"code\"],\n message: string,\n) => void;\n\nfunction theme(value: unknown, error: AddError) {\n if (typeof value !== \"string\") {\n error(\n \"theme\",\n value === undefined ? \"missing_required\" : \"invalid_type\",\n \"Expected a relative .json path. Set theme to a value such as ./theme.json.\",\n );\n } else if (\n !/\\.json$/.test(value) ||\n /^(?:[a-z][a-z\\d+.-]*:|\\/|\\\\)/i.test(value) ||\n value.includes(\"\\\\\")\n ) {\n error(\n \"theme\",\n \"invalid_format\",\n \"Expected a relative .json path. Use a value such as ./theme.json.\",\n );\n }\n}\n\nfunction stringList(\n value: unknown,\n path: string,\n error: AddError,\n options: { nonempty?: boolean; unique?: boolean; slug?: boolean } = {},\n) {\n if (value === undefined) {\n return undefined;\n }\n if (\n !Array.isArray(value) ||\n value.some((entry) => typeof entry !== \"string\")\n ) {\n error(\n path,\n \"invalid_type\",\n `Expected an array of strings. Set ${path} to string values.`,\n );\n return undefined;\n }\n if (options.nonempty && value.length === 0) {\n error(\n path,\n \"invalid_format\",\n `Expected at least one value. Add a value to ${path} or remove the field.`,\n );\n }\n value.forEach((entry, index) => {\n if (options.slug && !nonblank(entry)) {\n error(\n `${path}[${index}]`,\n \"invalid_format\",\n \"Expected a non-empty branch slug. Remove the empty value or use a branch slug.\",\n );\n }\n });\n if (options.unique && new Set(value).size !== value.length) {\n error(\n path,\n \"duplicate\",\n `Expected unique values. Remove duplicates from ${path}.`,\n );\n }\n return value;\n}\n\nfunction hostList(value: unknown, path: string, error: AddError) {\n stringList(value, path, error)?.forEach((host, index) => {\n if (!hostname(host)) {\n error(\n `${path}[${index}]`,\n \"invalid_format\",\n \"Expected a hostname or leading *. subdomain pattern without a scheme, path, port or IP. Use a value such as api.example.com.\",\n );\n }\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,WAAW,SAAS,cAAc;AAG3C,IAAM,WAAW;AAAA,EACf;AAAA,EACA;AAAA,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