@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.
Files changed (55) hide show
  1. package/README.md +64 -6
  2. package/dist/catalogue.js +12 -3
  3. package/dist/index.d.ts +7 -4
  4. package/dist/index.js +6 -3
  5. package/dist/legacy-schemas.d.ts +9 -0
  6. package/dist/legacy-schemas.js +2446 -0
  7. package/dist/organization-catalogue.js +6 -3
  8. package/dist/organization-schema.d.ts +2 -1
  9. package/dist/organization-schema.js +9 -7
  10. package/dist/product-schema.d.ts +2 -2
  11. package/dist/product-schema.js +54 -22
  12. package/dist/releases.d.ts +36 -0
  13. package/dist/releases.js +41 -0
  14. package/dist/rules/configurator-pricing.d.ts +21 -2
  15. package/dist/rules/configurator-pricing.js +41 -5
  16. package/dist/rules/org-e-002.d.ts +7 -0
  17. package/dist/rules/org-e-002.js +13 -0
  18. package/dist/rules/org-e-003.d.ts +7 -0
  19. package/dist/rules/org-e-003.js +13 -0
  20. package/dist/rules/pdp-e-002.d.ts +3 -9
  21. package/dist/rules/pdp-e-002.js +6 -26
  22. package/dist/rules/pdp-e-008.js +1 -1
  23. package/dist/rules/pdp-e-009.d.ts +1 -1
  24. package/dist/rules/pdp-e-009.js +3 -3
  25. package/dist/rules/pdp-e-013.d.ts +9 -0
  26. package/dist/rules/pdp-e-013.js +26 -0
  27. package/dist/rules/pdp-e-014.d.ts +11 -0
  28. package/dist/rules/pdp-e-014.js +34 -0
  29. package/dist/rules/pdp-e-015.d.ts +2 -0
  30. package/dist/rules/pdp-e-015.js +91 -0
  31. package/dist/rules/pdp-e-016.d.ts +7 -0
  32. package/dist/rules/pdp-e-016.js +13 -0
  33. package/dist/rules/pdp-w-032.d.ts +3 -2
  34. package/dist/rules/pdp-w-032.js +20 -12
  35. package/dist/rules/pdp-w-036.d.ts +2 -0
  36. package/dist/rules/pdp-w-036.js +31 -0
  37. package/dist/rules/pdp-w-037.d.ts +2 -0
  38. package/dist/rules/pdp-w-037.js +37 -0
  39. package/dist/rules/pdp-w-038.d.ts +2 -0
  40. package/dist/rules/pdp-w-038.js +30 -0
  41. package/dist/rules/pdp-w-039.d.ts +10 -0
  42. package/dist/rules/pdp-w-039.js +29 -0
  43. package/dist/rules/release-schema.d.ts +16 -0
  44. package/dist/rules/release-schema.js +77 -0
  45. package/dist/schema-validators.d.ts +2 -0
  46. package/dist/schema-validators.js +10 -4
  47. package/dist/sheet-type.d.ts +17 -0
  48. package/dist/sheet-type.js +25 -0
  49. package/dist/validate-and-lint.d.ts +9 -5
  50. package/dist/validate-and-lint.js +17 -9
  51. package/dist/validate-organization.d.ts +4 -4
  52. package/dist/validate-organization.js +8 -5
  53. package/dist/version.d.ts +1 -1
  54. package/dist/version.js +1 -1
  55. package/package.json +2 -2
@@ -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;
@@ -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
- * The bundled schemas are the current catalogue's format version. A
35
- * document declaring some other `format_version` failing Layer 1 is
36
- * the intended behavior, not a gap: this package lints exactly one
37
- * format version, and there is no separate "unsupported version"
38
- * outcome.
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
- * The bundled schemas are the current catalogue's format version. A
17
- * document declaring some other `format_version` failing Layer 1 is
18
- * the intended behavior, not a gap: this package lints exactly one
19
- * format version, and there is no separate "unsupported version"
20
- * outcome.
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 sheetType = detectSheetType((typeof input === "object" && input !== null ? input : {}));
31
- const validate = sheetType === "organization" ? validateOrganization : validateProduct;
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. The bundled schema is the
23
- * current format version; a document declaring some other
24
- * `format_version` failing Layer 1 is the intended behavior, exactly
25
- * as in the product pipeline.
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 { validateOrganization as validate } from "./schema-validators.js";
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. The bundled schema is the
5
- * current format version; a document declaring some other
6
- * `format_version` failing Layer 1 is the intended behavior, exactly
7
- * as in the product pipeline.
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
@@ -5,4 +5,4 @@
5
5
  * (test/linter-version.test.mjs) fails when they diverge. Regenerate
6
6
  * on version bump.
7
7
  */
8
- export declare const PACKAGE_VERSION = "0.8.0";
8
+ export declare const PACKAGE_VERSION = "0.10.0";
package/dist/version.js CHANGED
@@ -5,4 +5,4 @@
5
5
  * (test/linter-version.test.mjs) fails when they diverge. Regenerate
6
6
  * on version bump.
7
7
  */
8
- export const PACKAGE_VERSION = "0.8.0";
8
+ export const PACKAGE_VERSION = "0.10.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagefront/lint-commerce",
3
- "version": "0.8.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.1.0",
42
+ "@pagefront/lint-core": "^0.2.0",
43
43
  "ajv": "^8.20.0",
44
44
  "ajv-formats": "^3.0.1"
45
45
  },