@pagefront/lint-commerce 0.8.0 → 0.10.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 +64 -6
- package/dist/catalogue.js +12 -3
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- package/dist/legacy-schemas.d.ts +9 -0
- package/dist/legacy-schemas.js +2446 -0
- package/dist/organization-catalogue.js +6 -3
- package/dist/organization-schema.d.ts +2 -1
- package/dist/organization-schema.js +9 -7
- package/dist/product-schema.d.ts +2 -2
- package/dist/product-schema.js +54 -22
- package/dist/releases.d.ts +36 -0
- package/dist/releases.js +41 -0
- package/dist/rules/configurator-pricing.d.ts +21 -2
- package/dist/rules/configurator-pricing.js +41 -5
- package/dist/rules/org-e-002.d.ts +7 -0
- package/dist/rules/org-e-002.js +13 -0
- package/dist/rules/org-e-003.d.ts +7 -0
- package/dist/rules/org-e-003.js +13 -0
- package/dist/rules/pdp-e-002.d.ts +3 -9
- package/dist/rules/pdp-e-002.js +6 -26
- package/dist/rules/pdp-e-008.js +1 -1
- package/dist/rules/pdp-e-009.d.ts +1 -1
- package/dist/rules/pdp-e-009.js +3 -3
- package/dist/rules/pdp-e-013.d.ts +9 -0
- package/dist/rules/pdp-e-013.js +26 -0
- package/dist/rules/pdp-e-014.d.ts +11 -0
- package/dist/rules/pdp-e-014.js +34 -0
- package/dist/rules/pdp-e-015.d.ts +2 -0
- package/dist/rules/pdp-e-015.js +91 -0
- package/dist/rules/pdp-e-016.d.ts +7 -0
- package/dist/rules/pdp-e-016.js +13 -0
- package/dist/rules/pdp-w-032.d.ts +3 -2
- package/dist/rules/pdp-w-032.js +20 -12
- package/dist/rules/pdp-w-036.d.ts +2 -0
- package/dist/rules/pdp-w-036.js +31 -0
- package/dist/rules/pdp-w-037.d.ts +2 -0
- package/dist/rules/pdp-w-037.js +37 -0
- package/dist/rules/pdp-w-038.d.ts +2 -0
- package/dist/rules/pdp-w-038.js +30 -0
- package/dist/rules/pdp-w-039.d.ts +10 -0
- package/dist/rules/pdp-w-039.js +29 -0
- package/dist/rules/release-schema.d.ts +16 -0
- package/dist/rules/release-schema.js +77 -0
- package/dist/schema-validators.d.ts +2 -0
- package/dist/schema-validators.js +10 -4
- package/dist/sheet-type.d.ts +17 -0
- package/dist/sheet-type.js +25 -0
- package/dist/validate-and-lint.d.ts +9 -5
- package/dist/validate-and-lint.js +17 -9
- package/dist/validate-organization.d.ts +4 -4
- package/dist/validate-organization.js +8 -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
|
@@ -15,4 +15,21 @@ import type { Sheet } from "@pagefront/lint-core";
|
|
|
15
15
|
* page type the catalogue predates dispatch with.
|
|
16
16
|
*/
|
|
17
17
|
export type SheetType = "product" | "organization";
|
|
18
|
+
/**
|
|
19
|
+
* The two lines a sheet can belong to. A sheet on the *release* line
|
|
20
|
+
* carries `release` and validates against the current sheet-spec
|
|
21
|
+
* schemas; a sheet on the *legacy* draft line carries `format_version`
|
|
22
|
+
* (≤ 0.9) and validates against the frozen legacy schemas.
|
|
23
|
+
*/
|
|
24
|
+
export type SheetLine = "release" | "legacy";
|
|
25
|
+
/**
|
|
26
|
+
* Line detection reads the envelope field first: `release` puts a sheet
|
|
27
|
+
* on the release line (also when `format_version` is present beside it,
|
|
28
|
+
* which the release-line schemas and PDP-E-016 / ORG-E-002 reject), and
|
|
29
|
+
* `format_version` alone puts it on the legacy line. A sheet carrying
|
|
30
|
+
* neither is placed by its `$schema`: a two-part version segment, or
|
|
31
|
+
* the pre-2026-09-08 `/schemas/` path, is legacy; anything else is the
|
|
32
|
+
* release line, whose schema then reports the missing `release`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function detectSheetLine(sheet: Sheet): SheetLine;
|
|
18
35
|
export declare function detectSheetType(sheet: Sheet): SheetType;
|
package/dist/sheet-type.js
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
/** The legacy line's `$schema` version segment: two parts, `v0.9.json`. */
|
|
2
|
+
const LEGACY_SCHEMA_SEGMENT = /\/v\d+\.\d+\.json$/;
|
|
3
|
+
/**
|
|
4
|
+
* Line detection reads the envelope field first: `release` puts a sheet
|
|
5
|
+
* on the release line (also when `format_version` is present beside it,
|
|
6
|
+
* which the release-line schemas and PDP-E-016 / ORG-E-002 reject), and
|
|
7
|
+
* `format_version` alone puts it on the legacy line. A sheet carrying
|
|
8
|
+
* neither is placed by its `$schema`: a two-part version segment, or
|
|
9
|
+
* the pre-2026-09-08 `/schemas/` path, is legacy; anything else is the
|
|
10
|
+
* release line, whose schema then reports the missing `release`.
|
|
11
|
+
*/
|
|
12
|
+
export function detectSheetLine(sheet) {
|
|
13
|
+
if (sheet.release !== undefined)
|
|
14
|
+
return "release";
|
|
15
|
+
if (sheet.format_version !== undefined)
|
|
16
|
+
return "legacy";
|
|
17
|
+
const schema = sheet.$schema;
|
|
18
|
+
if (typeof schema === "string") {
|
|
19
|
+
if (LEGACY_SCHEMA_SEGMENT.test(schema))
|
|
20
|
+
return "legacy";
|
|
21
|
+
if (schema.includes("/schemas/organization/") || schema.includes("/schemas/product/"))
|
|
22
|
+
return "legacy";
|
|
23
|
+
}
|
|
24
|
+
return "release";
|
|
25
|
+
}
|
|
1
26
|
const ORG_DATA_TYPES = new Set(["Organization", "OnlineStore", "OnlineBusiness"]);
|
|
2
27
|
export function detectSheetType(sheet) {
|
|
3
28
|
const schema = sheet.$schema;
|
|
@@ -5,6 +5,9 @@
|
|
|
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 { SheetLine, SheetType } from "./sheet-type.js";
|
|
9
|
+
/** The Layer 1 validator for a sheet type on a line. */
|
|
10
|
+
export declare function validatorFor(sheetType: SheetType, line: SheetLine): import("ajv").ValidateFunction<unknown>;
|
|
8
11
|
/**
|
|
9
12
|
* One Layer 1 (JSON Schema) validation failure, in a shape this
|
|
10
13
|
* package owns. `instancePath` is a JSON Pointer to the offending
|
|
@@ -31,11 +34,12 @@ export type ValidateAndLintResult = {
|
|
|
31
34
|
* catalogue; Layer 1 success is also what makes the internal cast to
|
|
32
35
|
* `Sheet` sound (the schema requires the envelope fields).
|
|
33
36
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* Two lines are validated (see sheet-type.ts): a sheet carrying
|
|
38
|
+
* `release` validates against the current sheet-spec schema for its
|
|
39
|
+
* type, and a legacy sheet carrying `format_version` validates against
|
|
40
|
+
* the frozen legacy schema (format 0.9). A legacy sheet declaring some
|
|
41
|
+
* other `format_version` failing Layer 1 is the intended behavior:
|
|
42
|
+
* there is no separate "unsupported version" outcome.
|
|
39
43
|
*
|
|
40
44
|
* Dispatches by page type (see sheet-type.ts): product sheets validate
|
|
41
45
|
* against the product schema and lint with the product catalogue;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { lintSheet } from "./lint-sheet.js";
|
|
2
|
-
import { detectSheetType } from "./sheet-type.js";
|
|
3
|
-
import { validateProduct, validateOrganization } from "./schema-validators.js";
|
|
2
|
+
import { detectSheetLine, detectSheetType } from "./sheet-type.js";
|
|
3
|
+
import { validateProduct, validateOrganization, validateLegacyProduct, validateLegacyOrganization, } from "./schema-validators.js";
|
|
4
|
+
/** The Layer 1 validator for a sheet type on a line. */
|
|
5
|
+
export function validatorFor(sheetType, line) {
|
|
6
|
+
if (line === "legacy") {
|
|
7
|
+
return sheetType === "organization" ? validateLegacyOrganization : validateLegacyProduct;
|
|
8
|
+
}
|
|
9
|
+
return sheetType === "organization" ? validateOrganization : validateProduct;
|
|
10
|
+
}
|
|
4
11
|
// The validators are compiled ahead of time (see schema-validators.d.ts):
|
|
5
12
|
// nothing here generates code at load time, so the pipeline runs where
|
|
6
13
|
// eval is unavailable, and consumers calling it in a loop pay no
|
|
@@ -13,11 +20,12 @@ import { validateProduct, validateOrganization } from "./schema-validators.js";
|
|
|
13
20
|
* catalogue; Layer 1 success is also what makes the internal cast to
|
|
14
21
|
* `Sheet` sound (the schema requires the envelope fields).
|
|
15
22
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
23
|
+
* Two lines are validated (see sheet-type.ts): a sheet carrying
|
|
24
|
+
* `release` validates against the current sheet-spec schema for its
|
|
25
|
+
* type, and a legacy sheet carrying `format_version` validates against
|
|
26
|
+
* the frozen legacy schema (format 0.9). A legacy sheet declaring some
|
|
27
|
+
* other `format_version` failing Layer 1 is the intended behavior:
|
|
28
|
+
* there is no separate "unsupported version" outcome.
|
|
21
29
|
*
|
|
22
30
|
* Dispatches by page type (see sheet-type.ts): product sheets validate
|
|
23
31
|
* against the product schema and lint with the product catalogue;
|
|
@@ -27,8 +35,8 @@ import { validateProduct, validateOrganization } from "./schema-validators.js";
|
|
|
27
35
|
* document of either type routes to its own schema's errors.
|
|
28
36
|
*/
|
|
29
37
|
export function validateAndLint(input, options) {
|
|
30
|
-
const
|
|
31
|
-
const validate =
|
|
38
|
+
const envelope = (typeof input === "object" && input !== null ? input : {});
|
|
39
|
+
const validate = validatorFor(detectSheetType(envelope), detectSheetLine(envelope));
|
|
32
40
|
if (!validate(input)) {
|
|
33
41
|
const schemaErrors = (validate.errors ?? []).map((error) => ({
|
|
34
42
|
instancePath: error.instancePath,
|
|
@@ -19,9 +19,9 @@ export type ValidateOrganizationResult = {
|
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* Validate a parsed-but-unvalidated document against the bundled
|
|
22
|
-
* Commerce Organization Sheet JSON Schema
|
|
23
|
-
*
|
|
24
|
-
* `format_version
|
|
25
|
-
*
|
|
22
|
+
* Commerce Organization Sheet JSON Schema for its line: the current
|
|
23
|
+
* sheet-spec schema for a sheet carrying `release`, the frozen legacy
|
|
24
|
+
* schema for one carrying `format_version`, exactly as in the product
|
|
25
|
+
* pipeline.
|
|
26
26
|
*/
|
|
27
27
|
export declare function validateOrganizationSheet(input: unknown): ValidateOrganizationResult;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { detectSheetLine } from "./sheet-type.js";
|
|
2
|
+
import { validatorFor } from "./validate-and-lint.js";
|
|
2
3
|
/**
|
|
3
4
|
* Validate a parsed-but-unvalidated document against the bundled
|
|
4
|
-
* Commerce Organization Sheet JSON Schema
|
|
5
|
-
*
|
|
6
|
-
* `format_version
|
|
7
|
-
*
|
|
5
|
+
* Commerce Organization Sheet JSON Schema for its line: the current
|
|
6
|
+
* sheet-spec schema for a sheet carrying `release`, the frozen legacy
|
|
7
|
+
* schema for one carrying `format_version`, exactly as in the product
|
|
8
|
+
* pipeline.
|
|
8
9
|
*/
|
|
9
10
|
export function validateOrganizationSheet(input) {
|
|
11
|
+
const envelope = (typeof input === "object" && input !== null ? input : {});
|
|
12
|
+
const validate = validatorFor("organization", detectSheetLine(envelope));
|
|
10
13
|
if (!validate(input)) {
|
|
11
14
|
const schemaErrors = (validate.errors ?? []).map((error) => ({
|
|
12
15
|
instancePath: error.instancePath,
|
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.10.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.2.0",
|
|
43
43
|
"ajv": "^8.20.0",
|
|
44
44
|
"ajv-formats": "^3.0.1"
|
|
45
45
|
},
|