@pagefront/lint-commerce 0.1.0 → 0.2.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 +5 -2
- package/dist/organization-schema.js +2 -2
- package/dist/product-schema.js +1 -1
- package/dist/schema-validators.d.ts +10 -0
- package/dist/schema-validators.js +7 -0
- package/dist/sheet-type.d.ts +4 -2
- package/dist/sheet-type.js +4 -0
- package/dist/validate-and-lint.js +5 -17
- package/dist/validate-organization.js +1 -12
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -3
package/dist/sheet-type.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ import type { Sheet } from "@pagefront/lint-core";
|
|
|
4
4
|
* a different page type from product sheets, and each page type's
|
|
5
5
|
* rules must never run on the other's sheets.
|
|
6
6
|
*
|
|
7
|
-
* The envelope `$schema` is authoritative when it names a page type
|
|
8
|
-
*
|
|
7
|
+
* The envelope `$schema` is authoritative when it names a page type:
|
|
8
|
+
* `/spec/commerce/organization/` or `/spec/commerce/product/` in its
|
|
9
|
+
* path, or the `/schemas/organization/` and `/schemas/product/` paths
|
|
10
|
+
* the schemas were identified by before 2026-09-08. The
|
|
9
11
|
* data-block fallback — `@type` of `Organization` / `OnlineStore` /
|
|
10
12
|
* `OnlineBusiness` with `pagefront:commerceRole` present — applies
|
|
11
13
|
* only when `$schema` is absent or names neither, so a declared schema
|
package/dist/sheet-type.js
CHANGED
|
@@ -2,6 +2,10 @@ const ORG_DATA_TYPES = new Set(["Organization", "OnlineStore", "OnlineBusiness"]
|
|
|
2
2
|
export function detectSheetType(sheet) {
|
|
3
3
|
const schema = sheet.$schema;
|
|
4
4
|
if (typeof schema === "string") {
|
|
5
|
+
if (schema.includes("/spec/commerce/organization/"))
|
|
6
|
+
return "organization";
|
|
7
|
+
if (schema.includes("/spec/commerce/product/"))
|
|
8
|
+
return "product";
|
|
5
9
|
if (schema.includes("/schemas/organization/"))
|
|
6
10
|
return "organization";
|
|
7
11
|
if (schema.includes("/schemas/product/"))
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import { lintSheet } from "./lint-sheet.js";
|
|
2
|
-
import { PRODUCT_SCHEMA } from "./product-schema.js";
|
|
3
|
-
import { ORGANIZATION_SCHEMA } from "./organization-schema.js";
|
|
4
2
|
import { detectSheetType } from "./sheet-type.js";
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const Ajv2020 = Ajv2020Module.default;
|
|
11
|
-
const addFormats = addFormatsModule.default;
|
|
12
|
-
// Compiled once at module scope: pipeline consumers call
|
|
13
|
-
// validateAndLint in a loop, and schema compilation is the expensive
|
|
14
|
-
// step. `allowUnionTypes` because the product schema legitimately
|
|
15
|
-
// uses union `type` keywords.
|
|
16
|
-
const ajv = new Ajv2020({ allErrors: true, allowUnionTypes: true });
|
|
17
|
-
addFormats(ajv);
|
|
18
|
-
const validateProduct = ajv.compile(PRODUCT_SCHEMA);
|
|
19
|
-
const validateOrganization = ajv.compile(ORGANIZATION_SCHEMA);
|
|
3
|
+
import { validateProduct, validateOrganization } from "./schema-validators.js";
|
|
4
|
+
// The validators are compiled ahead of time (see schema-validators.d.ts):
|
|
5
|
+
// nothing here generates code at load time, so the pipeline runs where
|
|
6
|
+
// eval is unavailable, and consumers calling it in a loop pay no
|
|
7
|
+
// compilation cost.
|
|
20
8
|
/**
|
|
21
9
|
* Validate a parsed-but-unvalidated document against the bundled
|
|
22
10
|
* product JSON Schema (Layer 1), and — only if it passes — lint it
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// ajv ships CJS with `module.exports === exports.default`; under
|
|
3
|
-
// NodeNext the default import binding is the CJS namespace, so the
|
|
4
|
-
// class/function is reached via `.default` (identical at runtime).
|
|
5
|
-
import Ajv2020Module from "ajv/dist/2020.js";
|
|
6
|
-
import addFormatsModule from "ajv-formats";
|
|
7
|
-
const Ajv2020 = Ajv2020Module.default;
|
|
8
|
-
const addFormats = addFormatsModule.default;
|
|
9
|
-
// Compiled once at module scope, mirroring validate-and-lint.
|
|
10
|
-
const ajv = new Ajv2020({ allErrors: true, allowUnionTypes: true });
|
|
11
|
-
addFormats(ajv);
|
|
12
|
-
const validate = ajv.compile(ORGANIZATION_SCHEMA);
|
|
1
|
+
import { validateOrganization as validate } from "./schema-validators.js";
|
|
13
2
|
/**
|
|
14
3
|
* Validate a parsed-but-unvalidated document against the bundled
|
|
15
4
|
* Commerce Organization Sheet JSON Schema. The bundled schema is the
|
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.2.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": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
|
-
"build": "tsc",
|
|
38
|
-
"test": "
|
|
37
|
+
"build": "tsc && node scripts/compile-validators.mjs",
|
|
38
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
39
39
|
"prepublishOnly": "npm test"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|