@pagefront/lint-commerce 0.12.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -13
- package/dist/catalogue.js +8 -2
- package/dist/collection-catalogue.d.ts +15 -0
- package/dist/collection-catalogue.js +31 -0
- package/dist/generated/release-manifest.d.ts +9 -0
- package/dist/generated/release-manifest.js +10 -0
- package/dist/generated/schema-ids.js +3 -0
- package/dist/generated/schemas.js +2744 -23
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/lint-sheet.d.ts +4 -3
- package/dist/lint-sheet.js +9 -6
- package/dist/organization-catalogue.d.ts +4 -4
- package/dist/organization-catalogue.js +8 -6
- package/dist/overrides.d.ts +36 -0
- package/dist/overrides.js +5 -0
- package/dist/releases.d.ts +21 -6
- package/dist/releases.js +30 -8
- package/dist/rules/checkout-template.d.ts +69 -0
- package/dist/rules/checkout-template.js +165 -0
- package/dist/rules/col-e-001.d.ts +11 -0
- package/dist/rules/col-e-001.js +31 -0
- package/dist/rules/col-e-002.d.ts +2 -0
- package/dist/rules/col-e-002.js +37 -0
- package/dist/rules/col-e-003.d.ts +11 -0
- package/dist/rules/col-e-003.js +18 -0
- package/dist/rules/col-e-004.d.ts +12 -0
- package/dist/rules/col-e-004.js +19 -0
- package/dist/rules/col-e-005.d.ts +16 -0
- package/dist/rules/col-e-005.js +64 -0
- package/dist/rules/col-shared.d.ts +25 -0
- package/dist/rules/col-shared.js +43 -0
- package/dist/rules/col-w-001.d.ts +11 -0
- package/dist/rules/col-w-001.js +21 -0
- package/dist/rules/col-w-002.d.ts +12 -0
- package/dist/rules/col-w-002.js +31 -0
- package/dist/rules/col-w-004.d.ts +12 -0
- package/dist/rules/col-w-004.js +37 -0
- package/dist/rules/col-w-005.d.ts +12 -0
- package/dist/rules/col-w-005.js +41 -0
- package/dist/rules/col-w-006.d.ts +11 -0
- package/dist/rules/col-w-006.js +37 -0
- package/dist/rules/col-w-007.d.ts +13 -0
- package/dist/rules/col-w-007.js +32 -0
- package/dist/rules/org-w-007.d.ts +15 -0
- package/dist/rules/org-w-007.js +47 -0
- package/dist/rules/org-w-008.d.ts +15 -0
- package/dist/rules/org-w-008.js +59 -0
- package/dist/rules/pdp-e-005.d.ts +3 -1
- package/dist/rules/pdp-e-005.js +7 -5
- package/dist/rules/pdp-e-019.d.ts +2 -0
- package/dist/rules/pdp-e-019.js +50 -0
- package/dist/rules/pdp-e-020.d.ts +13 -0
- package/dist/rules/pdp-e-020.js +31 -0
- package/dist/rules/pdp-e-021.d.ts +11 -0
- package/dist/rules/pdp-e-021.js +32 -0
- package/dist/rules/pdp-e-022.d.ts +13 -0
- package/dist/rules/pdp-e-022.js +33 -0
- package/dist/rules/pdp-w-016.d.ts +4 -0
- package/dist/rules/pdp-w-016.js +7 -0
- package/dist/rules/pdp-w-021.js +1 -1
- package/dist/rules/pdp-w-031.d.ts +4 -4
- package/dist/rules/pdp-w-031.js +9 -7
- package/dist/rules/pdp-w-040.d.ts +12 -0
- package/dist/rules/pdp-w-040.js +37 -0
- package/dist/rules/pdp-w-041.d.ts +15 -0
- package/dist/rules/pdp-w-041.js +53 -0
- package/dist/rules/release-schema.d.ts +3 -2
- package/dist/rules/release-schema.js +11 -11
- package/dist/rules/unavailable-offer.d.ts +2 -0
- package/dist/rules/unavailable-offer.js +13 -0
- package/dist/schema-registry.d.ts +11 -0
- package/dist/schema-registry.js +24 -9
- package/dist/schema-validators.js +14 -5
- package/dist/sheet-type.d.ts +17 -12
- package/dist/sheet-type.js +11 -0
- package/dist/test-hooks.d.ts +15 -0
- package/dist/test-hooks.js +28 -0
- package/dist/validate-and-lint.d.ts +9 -5
- package/dist/validate-and-lint.js +33 -5
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/sheet-type.d.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import type { Sheet } from "@pagefront/lint-core";
|
|
2
2
|
/**
|
|
3
|
-
* Sheet-type detection for page-type dispatch:
|
|
4
|
-
*
|
|
5
|
-
* rules must never run on
|
|
3
|
+
* Sheet-type detection for page-type dispatch: product sheets,
|
|
4
|
+
* organization sheets and collection sheets are three page types, and
|
|
5
|
+
* each page type's rules must never run on another's sheets.
|
|
6
6
|
*
|
|
7
7
|
* The envelope `$schema` is authoritative when it names a page type:
|
|
8
|
-
* `/spec/commerce/organization
|
|
9
|
-
* path, or the
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
8
|
+
* `/spec/commerce/organization/`, `/spec/commerce/product/` or
|
|
9
|
+
* `/spec/commerce/collection/` in its path, or the
|
|
10
|
+
* `/schemas/organization/` and `/schemas/product/` paths the schemas
|
|
11
|
+
* were identified by before 2026-09-08 (the collection schema never
|
|
12
|
+
* had such a path). The data-block fallbacks — `@type` of
|
|
13
|
+
* `Organization` / `OnlineStore` / `OnlineBusiness` with
|
|
14
|
+
* `pagefront:commerceRole` present, and `@type` of `Collection` with
|
|
15
|
+
* `pagefront:collectionKind` present — apply only when `$schema` is
|
|
16
|
+
* absent or names no type, so a declared schema always wins over shape
|
|
17
|
+
* heuristics. The default is `product`, the page type the catalogue
|
|
18
|
+
* predates dispatch with.
|
|
16
19
|
*/
|
|
17
|
-
export type SheetType = "product" | "organization";
|
|
20
|
+
export type SheetType = "product" | "organization" | "collection";
|
|
21
|
+
/** The sheet types as the rule messages name them. */
|
|
22
|
+
export declare const SHEET_LABEL: Record<SheetType, string>;
|
|
18
23
|
/**
|
|
19
24
|
* The two lines a sheet can belong to. A sheet on the *release* line
|
|
20
25
|
* carries `release` and validates against the current sheet-spec
|
package/dist/sheet-type.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/** The sheet types as the rule messages name them. */
|
|
2
|
+
export const SHEET_LABEL = {
|
|
3
|
+
product: "Product Sheet",
|
|
4
|
+
organization: "Organization Sheet",
|
|
5
|
+
collection: "Collection Sheet",
|
|
6
|
+
};
|
|
1
7
|
/** The legacy line's `$schema` version segment: two parts, `v0.9.json`. */
|
|
2
8
|
const LEGACY_SCHEMA_SEGMENT = /\/v\d+\.\d+\.json$/;
|
|
3
9
|
/**
|
|
@@ -31,6 +37,8 @@ export function detectSheetType(sheet) {
|
|
|
31
37
|
return "organization";
|
|
32
38
|
if (schema.includes("/spec/commerce/product/"))
|
|
33
39
|
return "product";
|
|
40
|
+
if (schema.includes("/spec/commerce/collection/"))
|
|
41
|
+
return "collection";
|
|
34
42
|
if (schema.includes("/schemas/organization/"))
|
|
35
43
|
return "organization";
|
|
36
44
|
if (schema.includes("/schemas/product/"))
|
|
@@ -44,6 +52,9 @@ export function detectSheetType(sheet) {
|
|
|
44
52
|
d["pagefront:commerceRole"] !== undefined) {
|
|
45
53
|
return "organization";
|
|
46
54
|
}
|
|
55
|
+
if (d["@type"] === "Collection" && d["pagefront:collectionKind"] !== undefined) {
|
|
56
|
+
return "collection";
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
59
|
return "product";
|
|
49
60
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReleaseManifestShape } from "./overrides.js";
|
|
2
|
+
export interface TestManifestOptions {
|
|
3
|
+
/** The manifest to read in place of the bundled one. */
|
|
4
|
+
manifest: ReleaseManifestShape;
|
|
5
|
+
/**
|
|
6
|
+
* Schemas to validate against at Layer 1 for ids the package does not
|
|
7
|
+
* bundle, keyed by `$id`; compiled here with the options the build
|
|
8
|
+
* uses for the frozen schemas.
|
|
9
|
+
*/
|
|
10
|
+
schemas?: Record<string, object>;
|
|
11
|
+
}
|
|
12
|
+
/** Install a test manifest (and optional schemas) until `clearTestManifest`. */
|
|
13
|
+
export declare function installTestManifest(options: TestManifestOptions): void;
|
|
14
|
+
/** Back to the bundled manifest and the compiled validators. */
|
|
15
|
+
export declare function clearTestManifest(): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only hooks. Not part of the public surface (index.ts does not
|
|
3
|
+
* export this module): the conformance suite and the collection tests
|
|
4
|
+
* import it from dist/ to run the linter against a release manifest
|
|
5
|
+
* other than the bundled commerce/spec/releases.json, and to validate
|
|
6
|
+
* at Layer 1 against an editable schema head the frozen store does not
|
|
7
|
+
* carry yet. Production callers never reach this code, and nothing here
|
|
8
|
+
* imports a Node built-in, so the library stays browser-pure.
|
|
9
|
+
*/
|
|
10
|
+
import Ajv2020Module from "ajv/dist/2020.js";
|
|
11
|
+
import addFormatsModule from "ajv-formats";
|
|
12
|
+
import { setOverrides } from "./overrides.js";
|
|
13
|
+
const Ajv2020 = (Ajv2020Module.default ?? Ajv2020Module);
|
|
14
|
+
const addFormats = (addFormatsModule.default ?? addFormatsModule);
|
|
15
|
+
/** Install a test manifest (and optional schemas) until `clearTestManifest`. */
|
|
16
|
+
export function installTestManifest(options) {
|
|
17
|
+
const ajv = new Ajv2020({ allErrors: true, allowUnionTypes: true });
|
|
18
|
+
addFormats(ajv);
|
|
19
|
+
const validators = {};
|
|
20
|
+
for (const [id, schema] of Object.entries(options.schemas ?? {})) {
|
|
21
|
+
validators[id] = ajv.compile(schema);
|
|
22
|
+
}
|
|
23
|
+
setOverrides({ manifest: options.manifest, validators });
|
|
24
|
+
}
|
|
25
|
+
/** Back to the bundled manifest and the compiled validators. */
|
|
26
|
+
export function clearTestManifest() {
|
|
27
|
+
setOverrides({});
|
|
28
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* boundary: callers see `SchemaError`, never Ajv's own error type.
|
|
6
6
|
*/
|
|
7
7
|
import type { LintOptions, Report } from "@pagefront/lint-core";
|
|
8
|
-
import type
|
|
8
|
+
import { type SheetType } from "./sheet-type.js";
|
|
9
9
|
/**
|
|
10
10
|
* One Layer 1 (JSON Schema) validation failure, in a shape this
|
|
11
11
|
* package owns. `instancePath` is a JSON Pointer to the offending
|
|
@@ -30,9 +30,12 @@ export type ValidateAndLintResult = {
|
|
|
30
30
|
* sheet is validated against the schema its `$schema` names. Returns
|
|
31
31
|
* the errors, empty when the document is valid. A `release` the
|
|
32
32
|
* manifest does not list is a Layer 1 failure of its own, reported at
|
|
33
|
-
* `/release` with the keyword `release
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* `/release` with the keyword `release`, and so is a release that
|
|
34
|
+
* bundles no schema for the sheet's type (a type that joined the line
|
|
35
|
+
* later); a legacy `$schema` naming no bundled schema is reported at
|
|
36
|
+
* `/$schema`, and a legacy sheet of a type that was never on that line
|
|
37
|
+
* at `/format_version`. In no case is the document validated against
|
|
38
|
+
* some other version.
|
|
36
39
|
*/
|
|
37
40
|
export declare function schemaErrorsFor(input: unknown, sheetType?: SheetType): SchemaError[];
|
|
38
41
|
/**
|
|
@@ -53,6 +56,7 @@ export declare function schemaErrorsFor(input: unknown, sheetType?: SheetType):
|
|
|
53
56
|
*
|
|
54
57
|
* Layer 2 dispatches by page type (see sheet-type.ts): product sheets
|
|
55
58
|
* lint with the product catalogue, Commerce Organization Sheets with
|
|
56
|
-
* the organization catalogue
|
|
59
|
+
* the organization catalogue, Commerce Collection Sheets with the
|
|
60
|
+
* collection catalogue.
|
|
57
61
|
*/
|
|
58
62
|
export declare function validateAndLint(input: unknown, options?: LintOptions): ValidateAndLintResult;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { lintSheet } from "./lint-sheet.js";
|
|
2
|
+
import { overrides } from "./overrides.js";
|
|
2
3
|
import { resolveSchema } from "./schema-registry.js";
|
|
4
|
+
import { SHEET_LABEL } from "./sheet-type.js";
|
|
3
5
|
import { VALIDATORS } from "./schema-validators.js";
|
|
4
6
|
// The validators are compiled ahead of time (see schema-validators.d.ts):
|
|
5
7
|
// nothing here generates code at load time, so the pipeline runs where
|
|
@@ -11,9 +13,12 @@ import { VALIDATORS } from "./schema-validators.js";
|
|
|
11
13
|
* sheet is validated against the schema its `$schema` names. Returns
|
|
12
14
|
* the errors, empty when the document is valid. A `release` the
|
|
13
15
|
* manifest does not list is a Layer 1 failure of its own, reported at
|
|
14
|
-
* `/release` with the keyword `release
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* `/release` with the keyword `release`, and so is a release that
|
|
17
|
+
* bundles no schema for the sheet's type (a type that joined the line
|
|
18
|
+
* later); a legacy `$schema` naming no bundled schema is reported at
|
|
19
|
+
* `/$schema`, and a legacy sheet of a type that was never on that line
|
|
20
|
+
* at `/format_version`. In no case is the document validated against
|
|
21
|
+
* some other version.
|
|
17
22
|
*/
|
|
18
23
|
export function schemaErrorsFor(input, sheetType) {
|
|
19
24
|
const envelope = (typeof input === "object" && input !== null ? input : {});
|
|
@@ -36,7 +41,29 @@ export function schemaErrorsFor(input, sheetType) {
|
|
|
36
41
|
},
|
|
37
42
|
];
|
|
38
43
|
}
|
|
39
|
-
|
|
44
|
+
if (resolution.kind === "unbundled-type") {
|
|
45
|
+
const label = SHEET_LABEL[resolution.sheetType];
|
|
46
|
+
return [
|
|
47
|
+
resolution.release === null
|
|
48
|
+
? {
|
|
49
|
+
instancePath: "/format_version",
|
|
50
|
+
message: `the legacy draft line has no ${label} schema`,
|
|
51
|
+
keyword: "format_version",
|
|
52
|
+
}
|
|
53
|
+
: {
|
|
54
|
+
instancePath: "/release",
|
|
55
|
+
message: `release ${resolution.release} bundles no ${label} schema`,
|
|
56
|
+
keyword: "release",
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
// A test may install a validator for a schema the store does not
|
|
61
|
+
// carry yet (test-hooks.ts); the compiled validators are the rule.
|
|
62
|
+
const validate = overrides().validators?.[resolution.id] ?? VALIDATORS[resolution.id];
|
|
63
|
+
if (validate === undefined) {
|
|
64
|
+
// Unreachable when the store and the manifest agree, which CI checks.
|
|
65
|
+
return [{ instancePath: "/release", message: `no schema bundled for ${resolution.id}`, keyword: "release" }];
|
|
66
|
+
}
|
|
40
67
|
if (validate(input))
|
|
41
68
|
return [];
|
|
42
69
|
return (validate.errors ?? []).map((error) => ({
|
|
@@ -63,7 +90,8 @@ export function schemaErrorsFor(input, sheetType) {
|
|
|
63
90
|
*
|
|
64
91
|
* Layer 2 dispatches by page type (see sheet-type.ts): product sheets
|
|
65
92
|
* lint with the product catalogue, Commerce Organization Sheets with
|
|
66
|
-
* the organization catalogue
|
|
93
|
+
* the organization catalogue, Commerce Collection Sheets with the
|
|
94
|
+
* collection catalogue.
|
|
67
95
|
*/
|
|
68
96
|
export function validateAndLint(input, options) {
|
|
69
97
|
const schemaErrors = schemaErrorsFor(input);
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagefront/lint-commerce",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Pagefront commerce linter: the commerce rule catalogue and CLI, on the @pagefront/lint-core engine.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"prepublishOnly": "npm test"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@pagefront/lint-core": "^0.
|
|
42
|
+
"@pagefront/lint-core": "^0.4.0",
|
|
43
43
|
"ajv": "^8.20.0",
|
|
44
44
|
"ajv-formats": "^3.0.1"
|
|
45
45
|
},
|