@pagefront/lint-commerce 0.10.0 → 0.11.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 +24 -11
- package/dist/generated/release-manifest.d.ts +22 -0
- package/dist/generated/release-manifest.js +27 -0
- package/dist/generated/schema-ids.d.ts +1 -0
- package/dist/generated/schema-ids.js +7 -0
- package/dist/generated/schema-properties.d.ts +1 -0
- package/dist/{schema-properties.js → generated/schema-properties.js} +2 -10
- package/dist/generated/schemas.d.ts +1 -0
- package/dist/generated/schemas.js +4883 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -5
- package/dist/releases.d.ts +12 -26
- package/dist/releases.js +16 -30
- package/dist/rules/pdp-i-001.js +3 -2
- package/dist/schema-registry.d.ts +29 -0
- package/dist/schema-registry.js +35 -0
- package/dist/schema-validators.d.ts +7 -8
- package/dist/schema-validators.js +10 -4
- package/dist/validate-and-lint.d.ts +24 -21
- package/dist/validate-and-lint.js +47 -36
- package/dist/validate-organization.d.ts +5 -5
- package/dist/validate-organization.js +8 -18
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/dist/legacy-schemas.d.ts +0 -9
- package/dist/legacy-schemas.js +0 -2446
- package/dist/organization-schema.d.ts +0 -10
- package/dist/organization-schema.js +0 -443
- package/dist/product-schema.d.ts +0 -9
- package/dist/product-schema.js +0 -2015
- package/dist/schema-properties.d.ts +0 -10
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
* `validateOrganizationSheet` (Layer 1 for the Commerce Organization
|
|
8
8
|
* Sheet; no organization catalogue exists yet), the commerce
|
|
9
9
|
* catalogue object, and the types those signatures mention.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* (`RELEASE_MANIFEST`, `sheetSpecVersionFor`)
|
|
13
|
-
*
|
|
10
|
+
* The bundled schemas (`generated/`), the compiled validators and the
|
|
11
|
+
* individual rule modules are internal. The release manifest
|
|
12
|
+
* (`RELEASE_MANIFEST`, `sheetSpecVersionFor`, `schemaUrlFor`) and the
|
|
13
|
+
* list of bundled schema ids (`BUNDLED_SCHEMA_IDS`) are exported so
|
|
14
|
+
* callers can resolve a release to its sheet-spec versions and tell
|
|
15
|
+
* which `$schema` values this package validates.
|
|
14
16
|
*/
|
|
15
17
|
export { lintSheet } from "./lint-sheet.js";
|
|
16
18
|
export { validateAndLint } from "./validate-and-lint.js";
|
|
@@ -21,5 +23,6 @@ export { commerceCatalogue } from "./catalogue.js";
|
|
|
21
23
|
export { organizationCatalogue } from "./organization-catalogue.js";
|
|
22
24
|
export { detectSheetType, detectSheetLine } from "./sheet-type.js";
|
|
23
25
|
export type { SheetType, SheetLine } from "./sheet-type.js";
|
|
24
|
-
export { RELEASE_MANIFEST, KNOWN_RELEASES, sheetSpecVersionFor } from "./releases.js";
|
|
26
|
+
export { RELEASE_MANIFEST, KNOWN_RELEASES, CURRENT_RELEASE, sheetSpecVersionFor, schemaUrlFor, } from "./releases.js";
|
|
27
|
+
export { SCHEMA_IDS as BUNDLED_SCHEMA_IDS } from "./generated/schema-ids.js";
|
|
25
28
|
export type { Report, Finding, Summary, Severity, LintOptions, Sheet, } from "@pagefront/lint-core";
|
package/dist/index.js
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
* `validateOrganizationSheet` (Layer 1 for the Commerce Organization
|
|
8
8
|
* Sheet; no organization catalogue exists yet), the commerce
|
|
9
9
|
* catalogue object, and the types those signatures mention.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* (`RELEASE_MANIFEST`, `sheetSpecVersionFor`)
|
|
13
|
-
*
|
|
10
|
+
* The bundled schemas (`generated/`), the compiled validators and the
|
|
11
|
+
* individual rule modules are internal. The release manifest
|
|
12
|
+
* (`RELEASE_MANIFEST`, `sheetSpecVersionFor`, `schemaUrlFor`) and the
|
|
13
|
+
* list of bundled schema ids (`BUNDLED_SCHEMA_IDS`) are exported so
|
|
14
|
+
* callers can resolve a release to its sheet-spec versions and tell
|
|
15
|
+
* which `$schema` values this package validates.
|
|
14
16
|
*/
|
|
15
17
|
export { lintSheet } from "./lint-sheet.js";
|
|
16
18
|
export { validateAndLint } from "./validate-and-lint.js";
|
|
@@ -18,4 +20,5 @@ export { validateOrganizationSheet } from "./validate-organization.js";
|
|
|
18
20
|
export { commerceCatalogue } from "./catalogue.js";
|
|
19
21
|
export { organizationCatalogue } from "./organization-catalogue.js";
|
|
20
22
|
export { detectSheetType, detectSheetLine } from "./sheet-type.js";
|
|
21
|
-
export { RELEASE_MANIFEST, KNOWN_RELEASES, sheetSpecVersionFor } from "./releases.js";
|
|
23
|
+
export { RELEASE_MANIFEST, KNOWN_RELEASES, CURRENT_RELEASE, sheetSpecVersionFor, schemaUrlFor, } from "./releases.js";
|
|
24
|
+
export { SCHEMA_IDS as BUNDLED_SCHEMA_IDS } from "./generated/schema-ids.js";
|
package/dist/releases.d.ts
CHANGED
|
@@ -1,36 +1,22 @@
|
|
|
1
|
+
import { RELEASE_MANIFEST } from "./generated/release-manifest.js";
|
|
1
2
|
import type { SheetType } from "./sheet-type.js";
|
|
2
3
|
/**
|
|
3
|
-
* The commerce release manifest (commerce/spec/releases.json)
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* The commerce release manifest (commerce/spec/releases.json): each
|
|
5
|
+
* release and the member versions it bundles. Bundled at build time by
|
|
6
|
+
* scripts/bundle-schemas.mjs, so the package always carries the
|
|
7
|
+
* manifest it was built from.
|
|
7
8
|
*/
|
|
8
|
-
export
|
|
9
|
-
readonly $comment: "The commerce release manifest: each release and the member versions it bundles. Consumed by the linter; the human-readable form is releases.md.";
|
|
10
|
-
readonly vertical: "commerce";
|
|
11
|
-
readonly schema_url_template: "https://themachineweb.org/pagefront/spec/commerce/{sheet}/v{version}.json";
|
|
12
|
-
readonly releases: readonly [{
|
|
13
|
-
readonly release: "0.3.0";
|
|
14
|
-
readonly date: "2026-10-01";
|
|
15
|
-
readonly vocabulary: "0.3.0";
|
|
16
|
-
readonly sheets: {
|
|
17
|
-
readonly product: "0.9.0";
|
|
18
|
-
readonly organization: "0.3.0";
|
|
19
|
-
};
|
|
20
|
-
}];
|
|
21
|
-
readonly legacy: {
|
|
22
|
-
readonly envelope_field: "format_version";
|
|
23
|
-
readonly format_versions: readonly ["0.9"];
|
|
24
|
-
readonly schemas: {
|
|
25
|
-
readonly product: "https://themachineweb.org/pagefront/spec/commerce/product/v0.9.json";
|
|
26
|
-
readonly organization: "https://themachineweb.org/pagefront/spec/commerce/organization/v0.9.json";
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
};
|
|
9
|
+
export { RELEASE_MANIFEST };
|
|
30
10
|
/** Every release the manifest lists, in manifest order. */
|
|
31
11
|
export declare const KNOWN_RELEASES: readonly string[];
|
|
12
|
+
/** The latest release the manifest lists. */
|
|
13
|
+
export declare const CURRENT_RELEASE: string;
|
|
32
14
|
/**
|
|
33
15
|
* The sheet-spec version a release bundles for a sheet type, or
|
|
34
16
|
* undefined when the manifest does not list the release.
|
|
35
17
|
*/
|
|
36
18
|
export declare function sheetSpecVersionFor(release: string, sheetType: SheetType): string | undefined;
|
|
19
|
+
/** The published URL of a sheet spec's JSON Schema, which is also its `$id`. */
|
|
20
|
+
export declare function schemaUrlFor(sheetType: SheetType, version: string): string;
|
|
21
|
+
/** The legacy draft line's schema URL for a sheet type. */
|
|
22
|
+
export declare function legacySchemaUrl(sheetType: SheetType): string;
|
package/dist/releases.js
CHANGED
|
@@ -1,37 +1,15 @@
|
|
|
1
|
+
import { RELEASE_MANIFEST } from "./generated/release-manifest.js";
|
|
1
2
|
/**
|
|
2
|
-
* The commerce release manifest (commerce/spec/releases.json)
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* The commerce release manifest (commerce/spec/releases.json): each
|
|
4
|
+
* release and the member versions it bundles. Bundled at build time by
|
|
5
|
+
* scripts/bundle-schemas.mjs, so the package always carries the
|
|
6
|
+
* manifest it was built from.
|
|
6
7
|
*/
|
|
7
|
-
export
|
|
8
|
-
"$comment": "The commerce release manifest: each release and the member versions it bundles. Consumed by the linter; the human-readable form is releases.md.",
|
|
9
|
-
"vertical": "commerce",
|
|
10
|
-
"schema_url_template": "https://themachineweb.org/pagefront/spec/commerce/{sheet}/v{version}.json",
|
|
11
|
-
"releases": [
|
|
12
|
-
{
|
|
13
|
-
"release": "0.3.0",
|
|
14
|
-
"date": "2026-10-01",
|
|
15
|
-
"vocabulary": "0.3.0",
|
|
16
|
-
"sheets": {
|
|
17
|
-
"product": "0.9.0",
|
|
18
|
-
"organization": "0.3.0"
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
],
|
|
22
|
-
"legacy": {
|
|
23
|
-
"envelope_field": "format_version",
|
|
24
|
-
"format_versions": [
|
|
25
|
-
"0.9"
|
|
26
|
-
],
|
|
27
|
-
"schemas": {
|
|
28
|
-
"product": "https://themachineweb.org/pagefront/spec/commerce/product/v0.9.json",
|
|
29
|
-
"organization": "https://themachineweb.org/pagefront/spec/commerce/organization/v0.9.json"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
8
|
+
export { RELEASE_MANIFEST };
|
|
33
9
|
/** Every release the manifest lists, in manifest order. */
|
|
34
10
|
export const KNOWN_RELEASES = RELEASE_MANIFEST.releases.map((r) => r.release);
|
|
11
|
+
/** The latest release the manifest lists. */
|
|
12
|
+
export const CURRENT_RELEASE = KNOWN_RELEASES[KNOWN_RELEASES.length - 1];
|
|
35
13
|
/**
|
|
36
14
|
* The sheet-spec version a release bundles for a sheet type, or
|
|
37
15
|
* undefined when the manifest does not list the release.
|
|
@@ -39,3 +17,11 @@ export const KNOWN_RELEASES = RELEASE_MANIFEST.releases.map((r) => r.release);
|
|
|
39
17
|
export function sheetSpecVersionFor(release, sheetType) {
|
|
40
18
|
return RELEASE_MANIFEST.releases.find((r) => r.release === release)?.sheets[sheetType];
|
|
41
19
|
}
|
|
20
|
+
/** The published URL of a sheet spec's JSON Schema, which is also its `$id`. */
|
|
21
|
+
export function schemaUrlFor(sheetType, version) {
|
|
22
|
+
return RELEASE_MANIFEST.schema_url_template.replace("{sheet}", sheetType).replace("{version}", version);
|
|
23
|
+
}
|
|
24
|
+
/** The legacy draft line's schema URL for a sheet type. */
|
|
25
|
+
export function legacySchemaUrl(sheetType) {
|
|
26
|
+
return RELEASE_MANIFEST.legacy.schemas[sheetType];
|
|
27
|
+
}
|
package/dist/rules/pdp-i-001.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { DATA_BLOCK_PROPERTIES } from "../schema-properties.js";
|
|
1
|
+
import { DATA_BLOCK_PROPERTIES } from "../generated/schema-properties.js";
|
|
2
2
|
/**
|
|
3
3
|
* PDP-I-001 — Property outside Pagefront's modeled set.
|
|
4
4
|
* Transcribed from commerce/spec/rules.md (normative).
|
|
5
5
|
*
|
|
6
6
|
* The modeled set is the JSON Schema's dataBlock property inventory
|
|
7
|
-
*
|
|
7
|
+
* of the latest released Product Sheet schema (generated at build
|
|
8
|
+
* time, see scripts/bundle-schemas.mjs). The
|
|
8
9
|
* target `$.data.*` selects top-level data properties by design; any
|
|
9
10
|
* property outside the inventory fires, including unmodeled
|
|
10
11
|
* `pagefront:`-prefixed ones.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Sheet } from "@pagefront/lint-core";
|
|
2
|
+
import type { SheetType } from "./sheet-type.js";
|
|
3
|
+
/**
|
|
4
|
+
* Which frozen schema a sheet is validated against. The package bundles
|
|
5
|
+
* every schema ever published (commerce/schemas/), keyed by `$id`, and a
|
|
6
|
+
* sheet is validated against the one its `$schema` names, on either
|
|
7
|
+
* line. Nothing is substituted: a `$schema` that names no bundled schema
|
|
8
|
+
* is reported as such, and the sheet is not validated against a
|
|
9
|
+
* neighbouring version.
|
|
10
|
+
*/
|
|
11
|
+
export type SchemaResolution = {
|
|
12
|
+
kind: "schema";
|
|
13
|
+
id: string;
|
|
14
|
+
}
|
|
15
|
+
/** `$schema` is a string that names no schema this package bundles. */
|
|
16
|
+
| {
|
|
17
|
+
kind: "unknown";
|
|
18
|
+
declared: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Resolve the schema for a document. A declared `$schema` is taken at
|
|
22
|
+
* its word. Without one, the schema is the one the sheet's own
|
|
23
|
+
* statements lead to: the legacy schema for a sheet on the legacy line,
|
|
24
|
+
* and for a sheet on the release line the sheet-spec version its
|
|
25
|
+
* `release` bundles (the current release's when the release is not in
|
|
26
|
+
* the manifest). `sheetType` forces the type for callers that validate
|
|
27
|
+
* one type only.
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveSchema(sheet: Sheet, sheetType?: SheetType): SchemaResolution;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SCHEMA_IDS } from "./generated/schema-ids.js";
|
|
2
|
+
import { CURRENT_RELEASE, legacySchemaUrl, schemaUrlFor, sheetSpecVersionFor, } from "./releases.js";
|
|
3
|
+
import { detectSheetLine, detectSheetType } from "./sheet-type.js";
|
|
4
|
+
/**
|
|
5
|
+
* The identifiers the legacy schemas carried before 2026-09-08
|
|
6
|
+
* (`…/pagefront/commerce/schemas/<type>/v0.9.json`); sheets declaring
|
|
7
|
+
* them validate against the legacy schema they became.
|
|
8
|
+
*/
|
|
9
|
+
const FORMER_LEGACY_ID = /^https:\/\/themachineweb\.org\/pagefront\/commerce\/schemas\/(product|organization)\/v0\.9\.json$/;
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the schema for a document. A declared `$schema` is taken at
|
|
12
|
+
* its word. Without one, the schema is the one the sheet's own
|
|
13
|
+
* statements lead to: the legacy schema for a sheet on the legacy line,
|
|
14
|
+
* and for a sheet on the release line the sheet-spec version its
|
|
15
|
+
* `release` bundles (the current release's when the release is not in
|
|
16
|
+
* the manifest). `sheetType` forces the type for callers that validate
|
|
17
|
+
* one type only.
|
|
18
|
+
*/
|
|
19
|
+
export function resolveSchema(sheet, sheetType) {
|
|
20
|
+
const declared = sheet.$schema;
|
|
21
|
+
if (typeof declared === "string") {
|
|
22
|
+
if (SCHEMA_IDS.includes(declared))
|
|
23
|
+
return { kind: "schema", id: declared };
|
|
24
|
+
const former = FORMER_LEGACY_ID.exec(declared);
|
|
25
|
+
if (former !== null)
|
|
26
|
+
return { kind: "schema", id: legacySchemaUrl(former[1]) };
|
|
27
|
+
return { kind: "unknown", declared };
|
|
28
|
+
}
|
|
29
|
+
const type = sheetType ?? detectSheetType(sheet);
|
|
30
|
+
if (detectSheetLine(sheet) === "legacy")
|
|
31
|
+
return { kind: "schema", id: legacySchemaUrl(type) };
|
|
32
|
+
const release = typeof sheet.release === "string" ? sheet.release : CURRENT_RELEASE;
|
|
33
|
+
const version = sheetSpecVersionFor(release, type) ?? sheetSpecVersionFor(CURRENT_RELEASE, type);
|
|
34
|
+
return { kind: "schema", id: schemaUrlFor(type, version) };
|
|
35
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Layer 1 validators, compiled ahead of time from
|
|
3
|
-
* schemas by scripts/compile-validators.mjs into
|
|
4
|
-
* (the
|
|
5
|
-
* type; the script copies it beside the
|
|
2
|
+
* The Layer 1 validators, compiled ahead of time from every bundled
|
|
3
|
+
* schema (commerce/schemas/) by scripts/compile-validators.mjs into
|
|
4
|
+
* dist/schema-validators.js (the last step of `npm run build`). This
|
|
5
|
+
* declaration is the module's type; the script copies it beside the
|
|
6
|
+
* generated file.
|
|
6
7
|
*/
|
|
7
8
|
import type { ValidateFunction } from "ajv";
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
export const
|
|
11
|
-
export const validateLegacyProduct: ValidateFunction;
|
|
12
|
-
export const validateLegacyOrganization: ValidateFunction;
|
|
10
|
+
/** One validator per bundled schema, keyed by the schema's `$id`. */
|
|
11
|
+
export const VALIDATORS: Readonly<Record<string, ValidateFunction>>;
|