@pagefront/lint-commerce 0.1.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/LICENSE +202 -0
- package/README.md +118 -0
- package/dist/catalogue.d.ts +9 -0
- package/dist/catalogue.js +43 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +144 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +18 -0
- package/dist/lint-sheet.d.ts +13 -0
- package/dist/lint-sheet.js +25 -0
- package/dist/organization-catalogue.d.ts +11 -0
- package/dist/organization-catalogue.js +21 -0
- package/dist/organization-schema.d.ts +9 -0
- package/dist/organization-schema.js +441 -0
- package/dist/product-schema.d.ts +9 -0
- package/dist/product-schema.js +1853 -0
- package/dist/rules/org-shared.d.ts +21 -0
- package/dist/rules/org-shared.js +44 -0
- package/dist/rules/org-w-001.d.ts +12 -0
- package/dist/rules/org-w-001.js +31 -0
- package/dist/rules/org-w-002.d.ts +12 -0
- package/dist/rules/org-w-002.js +32 -0
- package/dist/rules/org-w-003.d.ts +11 -0
- package/dist/rules/org-w-003.js +30 -0
- package/dist/rules/org-w-004.d.ts +12 -0
- package/dist/rules/org-w-004.js +32 -0
- package/dist/rules/org-w-005.d.ts +2 -0
- package/dist/rules/org-w-005.js +54 -0
- package/dist/rules/org-w-006.d.ts +13 -0
- package/dist/rules/org-w-006.js +32 -0
- package/dist/rules/pdp-e-001.d.ts +2 -0
- package/dist/rules/pdp-e-001.js +42 -0
- package/dist/rules/pdp-e-002.d.ts +13 -0
- package/dist/rules/pdp-e-002.js +33 -0
- package/dist/rules/pdp-i-001.d.ts +2 -0
- package/dist/rules/pdp-i-001.js +28 -0
- package/dist/rules/pdp-w-001.d.ts +12 -0
- package/dist/rules/pdp-w-001.js +22 -0
- package/dist/rules/pdp-w-002.d.ts +13 -0
- package/dist/rules/pdp-w-002.js +23 -0
- package/dist/rules/pdp-w-003.d.ts +12 -0
- package/dist/rules/pdp-w-003.js +22 -0
- package/dist/rules/pdp-w-004.d.ts +11 -0
- package/dist/rules/pdp-w-004.js +30 -0
- package/dist/rules/pdp-w-005.d.ts +18 -0
- package/dist/rules/pdp-w-005.js +44 -0
- package/dist/rules/pdp-w-006.d.ts +10 -0
- package/dist/rules/pdp-w-006.js +31 -0
- package/dist/rules/pdp-w-007.d.ts +9 -0
- package/dist/rules/pdp-w-007.js +29 -0
- package/dist/rules/pdp-w-008.d.ts +19 -0
- package/dist/rules/pdp-w-008.js +43 -0
- package/dist/rules/pdp-w-009.d.ts +9 -0
- package/dist/rules/pdp-w-009.js +29 -0
- package/dist/rules/pdp-w-010.d.ts +24 -0
- package/dist/rules/pdp-w-010.js +85 -0
- package/dist/rules/pdp-w-011.d.ts +2 -0
- package/dist/rules/pdp-w-011.js +44 -0
- package/dist/rules/pdp-w-012.d.ts +18 -0
- package/dist/rules/pdp-w-012.js +51 -0
- package/dist/rules/pdp-w-013.d.ts +13 -0
- package/dist/rules/pdp-w-013.js +25 -0
- package/dist/rules/pdp-w-014.d.ts +26 -0
- package/dist/rules/pdp-w-014.js +69 -0
- package/dist/rules/pdp-w-015.d.ts +10 -0
- package/dist/rules/pdp-w-015.js +33 -0
- package/dist/rules/pdp-w-016.d.ts +9 -0
- package/dist/rules/pdp-w-016.js +30 -0
- package/dist/rules/pdp-w-017.d.ts +2 -0
- package/dist/rules/pdp-w-017.js +55 -0
- package/dist/rules/pdp-w-018.d.ts +2 -0
- package/dist/rules/pdp-w-018.js +32 -0
- package/dist/rules/pdp-w-019.d.ts +14 -0
- package/dist/rules/pdp-w-019.js +49 -0
- package/dist/rules/pdp-w-020.d.ts +2 -0
- package/dist/rules/pdp-w-020.js +64 -0
- package/dist/rules/pdp-w-021.d.ts +2 -0
- package/dist/rules/pdp-w-021.js +53 -0
- package/dist/rules/pdp-w-022.d.ts +11 -0
- package/dist/rules/pdp-w-022.js +25 -0
- package/dist/rules/pdp-w-023.d.ts +2 -0
- package/dist/rules/pdp-w-023.js +39 -0
- package/dist/rules/pdp-w-024.d.ts +24 -0
- package/dist/rules/pdp-w-024.js +58 -0
- package/dist/rules/pdp-w-025.d.ts +2 -0
- package/dist/rules/pdp-w-025.js +35 -0
- package/dist/rules/pdp-w-026.d.ts +10 -0
- package/dist/rules/pdp-w-026.js +31 -0
- package/dist/rules/pdp-w-027.d.ts +14 -0
- package/dist/rules/pdp-w-027.js +47 -0
- package/dist/schema-properties.d.ts +10 -0
- package/dist/schema-properties.js +67 -0
- package/dist/sheet-type.d.ts +16 -0
- package/dist/sheet-type.js +20 -0
- package/dist/validate-and-lint.d.ts +47 -0
- package/dist/validate-and-lint.js +53 -0
- package/dist/validate-organization.d.ts +27 -0
- package/dist/validate-organization.js +30 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.js +8 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @pagefront/lint-commerce
|
|
2
|
+
|
|
3
|
+
The Pagefront commerce linter: the commerce rule catalogue
|
|
4
|
+
([`commerce/spec/rules.md`](https://github.com/themachineweb/pagefront/blob/main/commerce/spec/rules.md), normative) and the
|
|
5
|
+
`pagefront-lint-commerce` CLI, on the
|
|
6
|
+
[`@pagefront/lint-core`](https://www.npmjs.com/package/@pagefront/lint-core) engine. This is the
|
|
7
|
+
reference implementation of Layer 2 of the validation stack defined in
|
|
8
|
+
[`core/spec/linter.md`](https://github.com/themachineweb/pagefront/blob/main/core/spec/linter.md).
|
|
9
|
+
|
|
10
|
+
## CLI
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
pagefront-lint-commerce <sheet-url-or-path> [options]
|
|
14
|
+
|
|
15
|
+
--format <json|text|html|github> output format (default: json)
|
|
16
|
+
--fail-on <error|warning> lowest severity that fails the exit code
|
|
17
|
+
--checked-at <iso8601> inject the report timestamp (reproducible output)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The CLI validates Layer 1 (JSON Schema) first; a failing Sheet gets its
|
|
21
|
+
schema errors on stderr and no report. Exit codes: `0` nothing
|
|
22
|
+
blocking, `1` Layer 1 failure or blocking findings, `2` operational
|
|
23
|
+
failure. Both commerce page types are handled: product sheets and
|
|
24
|
+
Commerce Organization Sheets each validate against their own schema and
|
|
25
|
+
lint with their own catalogue, dispatched by sheet type.
|
|
26
|
+
|
|
27
|
+
## API
|
|
28
|
+
|
|
29
|
+
The public surface — everything importable from the package root, and
|
|
30
|
+
nothing else (the bundled schema and the individual rule modules are
|
|
31
|
+
internal):
|
|
32
|
+
|
|
33
|
+
- `validateAndLint(input: unknown, options?: LintOptions)` — the CLI's
|
|
34
|
+
own pipeline as a function: Layer 1 against the bundled schema for
|
|
35
|
+
the document's page type, then Layer 2 against that page type's
|
|
36
|
+
catalogue. Product sheets route to the product schema and catalogue,
|
|
37
|
+
Commerce Organization Sheets to the organization ones (see
|
|
38
|
+
`detectSheetType`). Returns
|
|
39
|
+
`{ layer: 1, schemaErrors: SchemaError[] }` or
|
|
40
|
+
`{ layer: 2, report: Report }`. The bundled schemas are the current
|
|
41
|
+
format version; a document declaring another `format_version` fails
|
|
42
|
+
Layer 1 by design.
|
|
43
|
+
- `lintSheet(sheet: Sheet, options?: LintOptions): Report` — Layer 2
|
|
44
|
+
only, for input you have already schema-validated. Dispatches to the
|
|
45
|
+
page type's catalogue the same way.
|
|
46
|
+
- `validateOrganizationSheet(input: unknown)` — Layer 1 only, against
|
|
47
|
+
the bundled Commerce Organization Sheet schema. Returns
|
|
48
|
+
`{ valid: true }` or `{ valid: false, schemaErrors: SchemaError[] }`.
|
|
49
|
+
- `detectSheetType(sheet: Sheet): SheetType` — the page-type dispatch:
|
|
50
|
+
`"organization"` when the envelope `$schema` path contains
|
|
51
|
+
`/schemas/organization/` (a `/schemas/product/` path likewise wins
|
|
52
|
+
for `"product"`), falling back to a data block whose `@type` is
|
|
53
|
+
`Organization`/`OnlineStore`/`OnlineBusiness` with
|
|
54
|
+
`pagefront:commerceRole` present; `"product"` otherwise.
|
|
55
|
+
- `commerceCatalogue`, `organizationCatalogue` — the per-page-type
|
|
56
|
+
catalogue objects (read-only), for direct engine use or
|
|
57
|
+
introspection. Product rules never run on organization sheets and
|
|
58
|
+
vice versa.
|
|
59
|
+
- Types: `SchemaError`, `ValidateAndLintResult`,
|
|
60
|
+
`ValidateOrganizationResult`, `SheetType`, and the core types the
|
|
61
|
+
signatures mention — `Report`, `Finding`, `Summary`, `Severity`,
|
|
62
|
+
`LintOptions`, `Sheet`.
|
|
63
|
+
|
|
64
|
+
### CI script
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import { readFile } from "node:fs/promises";
|
|
68
|
+
import { validateAndLint } from "@pagefront/lint-commerce";
|
|
69
|
+
|
|
70
|
+
const document = JSON.parse(await readFile(process.argv[2], "utf8"));
|
|
71
|
+
const result = validateAndLint(document);
|
|
72
|
+
if (result.layer === 1) {
|
|
73
|
+
for (const e of result.schemaErrors) {
|
|
74
|
+
console.error(`${e.instancePath === "" ? "(root)" : e.instancePath}: ${e.message}`);
|
|
75
|
+
}
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
process.exit(result.report.summary.errors > 0 ? 1 : 0);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Pipeline embed
|
|
82
|
+
|
|
83
|
+
A production pipeline with its own validation layer calls the same
|
|
84
|
+
function and folds the union into its own result
|
|
85
|
+
shape — the schema compiles once at module load, so per-document calls
|
|
86
|
+
are cheap:
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
import { validateAndLint } from "@pagefront/lint-commerce";
|
|
90
|
+
|
|
91
|
+
export function validateSheet(document) {
|
|
92
|
+
const result = validateAndLint(document);
|
|
93
|
+
return result.layer === 1
|
|
94
|
+
? { ok: false, schemaErrors: result.schemaErrors }
|
|
95
|
+
: { ok: result.report.summary.errors === 0, report: result.report };
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Rendering stored reports
|
|
100
|
+
|
|
101
|
+
The renderers are pure functions over the canonical Report JSON — they
|
|
102
|
+
live in `@pagefront/lint-core` and work on any report, including one
|
|
103
|
+
you stored earlier:
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
import { readFile } from "node:fs/promises";
|
|
107
|
+
import { renderHtml } from "@pagefront/lint-core";
|
|
108
|
+
|
|
109
|
+
const report = JSON.parse(await readFile("report.json", "utf8"));
|
|
110
|
+
await writeFile("report.html", renderHtml(report));
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Versioning
|
|
114
|
+
|
|
115
|
+
Pre-1.0: minor versions may break the API. The surface listed above is
|
|
116
|
+
what versioning tracks — imports that reach past it (`dist/` paths,
|
|
117
|
+
rule modules) are internal and may change without notice in any
|
|
118
|
+
release.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Catalogue } from "@pagefront/lint-core";
|
|
2
|
+
/**
|
|
3
|
+
* The commerce product-sheet rule catalogue — the executable form of
|
|
4
|
+
* the product rules in commerce/spec/rules.md (normative). Every
|
|
5
|
+
* subsequent rule file gets imported and appended to `rules` here, in
|
|
6
|
+
* ID order. Organization-sheet rules live in organization-catalogue.ts;
|
|
7
|
+
* lintSheet dispatches between the two by sheet type.
|
|
8
|
+
*/
|
|
9
|
+
export declare const commerceCatalogue: Catalogue;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { pdpE001 } from "./rules/pdp-e-001.js";
|
|
2
|
+
import { pdpE002 } from "./rules/pdp-e-002.js";
|
|
3
|
+
import { pdpW001 } from "./rules/pdp-w-001.js";
|
|
4
|
+
import { pdpW002 } from "./rules/pdp-w-002.js";
|
|
5
|
+
import { pdpW003 } from "./rules/pdp-w-003.js";
|
|
6
|
+
import { pdpW004 } from "./rules/pdp-w-004.js";
|
|
7
|
+
import { pdpW005 } from "./rules/pdp-w-005.js";
|
|
8
|
+
import { pdpW006 } from "./rules/pdp-w-006.js";
|
|
9
|
+
import { pdpW007 } from "./rules/pdp-w-007.js";
|
|
10
|
+
import { pdpW008 } from "./rules/pdp-w-008.js";
|
|
11
|
+
import { pdpW009 } from "./rules/pdp-w-009.js";
|
|
12
|
+
import { pdpW010 } from "./rules/pdp-w-010.js";
|
|
13
|
+
import { pdpW011 } from "./rules/pdp-w-011.js";
|
|
14
|
+
import { pdpW012 } from "./rules/pdp-w-012.js";
|
|
15
|
+
import { pdpW013 } from "./rules/pdp-w-013.js";
|
|
16
|
+
import { pdpW014 } from "./rules/pdp-w-014.js";
|
|
17
|
+
import { pdpW015 } from "./rules/pdp-w-015.js";
|
|
18
|
+
import { pdpW016 } from "./rules/pdp-w-016.js";
|
|
19
|
+
import { pdpW017 } from "./rules/pdp-w-017.js";
|
|
20
|
+
import { pdpW018 } from "./rules/pdp-w-018.js";
|
|
21
|
+
import { pdpW019 } from "./rules/pdp-w-019.js";
|
|
22
|
+
import { pdpW020 } from "./rules/pdp-w-020.js";
|
|
23
|
+
import { pdpW021 } from "./rules/pdp-w-021.js";
|
|
24
|
+
import { pdpW022 } from "./rules/pdp-w-022.js";
|
|
25
|
+
import { pdpW023 } from "./rules/pdp-w-023.js";
|
|
26
|
+
import { pdpW024 } from "./rules/pdp-w-024.js";
|
|
27
|
+
import { pdpW025 } from "./rules/pdp-w-025.js";
|
|
28
|
+
import { pdpW026 } from "./rules/pdp-w-026.js";
|
|
29
|
+
import { pdpW027 } from "./rules/pdp-w-027.js";
|
|
30
|
+
import { pdpI001 } from "./rules/pdp-i-001.js";
|
|
31
|
+
/**
|
|
32
|
+
* The commerce product-sheet rule catalogue — the executable form of
|
|
33
|
+
* the product rules in commerce/spec/rules.md (normative). Every
|
|
34
|
+
* subsequent rule file gets imported and appended to `rules` here, in
|
|
35
|
+
* ID order. Organization-sheet rules live in organization-catalogue.ts;
|
|
36
|
+
* lintSheet dispatches between the two by sheet type.
|
|
37
|
+
*/
|
|
38
|
+
export const commerceCatalogue = {
|
|
39
|
+
vertical: "commerce",
|
|
40
|
+
formatVersion: "0.9",
|
|
41
|
+
catalogueVersion: "0.5.0",
|
|
42
|
+
rules: [pdpE001, pdpE002, pdpW001, pdpW002, pdpW003, pdpW004, pdpW005, pdpW006, pdpW007, pdpW008, pdpW009, pdpW010, pdpW011, pdpW012, pdpW013, pdpW014, pdpW015, pdpW016, pdpW017, pdpW018, pdpW019, pdpW020, pdpW021, pdpW022, pdpW023, pdpW024, pdpW025, pdpW026, pdpW027, pdpI001],
|
|
43
|
+
};
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* CLI entry point for `pagefront-lint-commerce` — the reference
|
|
4
|
+
* implementation described in core/spec/linter.md ("Implementations").
|
|
5
|
+
* Accepts a Sheet URL or local file path, runs Layer 1 (JSON Schema —
|
|
6
|
+
* the bundled product schema) and then Layer 2 (the commerce rule
|
|
7
|
+
* catalogue), and emits the canonical JSON report to stdout;
|
|
8
|
+
* `--format=text` emits the terminal rendering instead. Only the
|
|
9
|
+
* report ever goes to stdout — usage and Layer 1 diagnostics go to
|
|
10
|
+
* stderr.
|
|
11
|
+
*
|
|
12
|
+
* Exit codes: 0 — lint ran, nothing blocking; 1 — Layer 1 failed, or
|
|
13
|
+
* findings at or above --fail-on (default: error); 2 — operational
|
|
14
|
+
* failure (bad usage, unreadable input, fetch failure, invalid JSON).
|
|
15
|
+
*/
|
|
16
|
+
import { readFile } from "node:fs/promises";
|
|
17
|
+
import { createRequire } from "node:module";
|
|
18
|
+
import { parseArgs } from "node:util";
|
|
19
|
+
import { renderGithub, renderHtml, renderText } from "@pagefront/lint-core";
|
|
20
|
+
import { validateAndLint } from "./index.js";
|
|
21
|
+
const require = createRequire(import.meta.url);
|
|
22
|
+
const PACKAGE_VERSION = require("../package.json").version;
|
|
23
|
+
const USAGE = `usage: pagefront-lint-commerce <sheet-url-or-path> [options]
|
|
24
|
+
|
|
25
|
+
Lint a Pagefront commerce Sheet: Layer 1 (JSON Schema) validation,
|
|
26
|
+
then the Layer 2 rule catalogue. The canonical JSON report goes to
|
|
27
|
+
stdout.
|
|
28
|
+
|
|
29
|
+
options:
|
|
30
|
+
--format <json|text|html|github>
|
|
31
|
+
output format (default: json); github emits
|
|
32
|
+
GitHub Actions annotations
|
|
33
|
+
--fail-on <error|warning> lowest severity that fails the exit code
|
|
34
|
+
(default: error)
|
|
35
|
+
--checked-at <iso8601> override the report's checked_at timestamp,
|
|
36
|
+
for reproducible output
|
|
37
|
+
--version print the linter version
|
|
38
|
+
--help print this usage
|
|
39
|
+
`;
|
|
40
|
+
/** Operational failure (exit 2): usage, IO, fetch, JSON parse. */
|
|
41
|
+
function fail(message) {
|
|
42
|
+
process.stderr.write(`pagefront-lint-commerce: ${message}\n`);
|
|
43
|
+
process.exit(2);
|
|
44
|
+
}
|
|
45
|
+
async function loadSheetText(target) {
|
|
46
|
+
if (/^https?:\/\//i.test(target)) {
|
|
47
|
+
let response;
|
|
48
|
+
try {
|
|
49
|
+
response = await fetch(target, {
|
|
50
|
+
headers: { accept: "application/json" },
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
fail(`fetch failed for ${target}: ${error.message}`);
|
|
55
|
+
}
|
|
56
|
+
if (!response.ok) {
|
|
57
|
+
fail(`fetch failed for ${target}: HTTP ${response.status}`);
|
|
58
|
+
}
|
|
59
|
+
return response.text();
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
return await readFile(target, "utf8");
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
fail(`cannot read ${target}: ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const { values, positionals } = (() => {
|
|
69
|
+
try {
|
|
70
|
+
return parseArgs({
|
|
71
|
+
allowPositionals: true,
|
|
72
|
+
options: {
|
|
73
|
+
format: { type: "string", default: "json" },
|
|
74
|
+
"fail-on": { type: "string", default: "error" },
|
|
75
|
+
"checked-at": { type: "string" },
|
|
76
|
+
version: { type: "boolean", default: false },
|
|
77
|
+
help: { type: "boolean", default: false },
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
fail(`${error.message}\n\n${USAGE}`);
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
if (values.help) {
|
|
86
|
+
process.stdout.write(USAGE);
|
|
87
|
+
process.exit(0);
|
|
88
|
+
}
|
|
89
|
+
if (values.version) {
|
|
90
|
+
process.stdout.write(`${PACKAGE_VERSION}\n`);
|
|
91
|
+
process.exit(0);
|
|
92
|
+
}
|
|
93
|
+
if (positionals.length !== 1) {
|
|
94
|
+
fail(`expected exactly one Sheet URL or file path\n\n${USAGE}`);
|
|
95
|
+
}
|
|
96
|
+
const FORMATS = ["json", "text", "html", "github"];
|
|
97
|
+
if (!FORMATS.includes(values.format)) {
|
|
98
|
+
fail(`--format must be one of ${FORMATS.join(", ")}, got "${values.format}"`);
|
|
99
|
+
}
|
|
100
|
+
if (values["fail-on"] !== "error" && values["fail-on"] !== "warning") {
|
|
101
|
+
fail(`--fail-on must be error or warning, got "${values["fail-on"]}"`);
|
|
102
|
+
}
|
|
103
|
+
const checkedAt = values["checked-at"];
|
|
104
|
+
if (checkedAt !== undefined && Number.isNaN(Date.parse(checkedAt))) {
|
|
105
|
+
fail(`--checked-at must be an ISO 8601 timestamp, got "${checkedAt}"`);
|
|
106
|
+
}
|
|
107
|
+
const target = positionals[0];
|
|
108
|
+
const text = await loadSheetText(target);
|
|
109
|
+
let parsed;
|
|
110
|
+
try {
|
|
111
|
+
parsed = JSON.parse(text);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
fail(`${target} is not valid JSON: ${error.message}`);
|
|
115
|
+
}
|
|
116
|
+
// Layer 1 → Layer 2 — the library owns the sequencing; the CLI only
|
|
117
|
+
// maps the result union onto streams and exit codes.
|
|
118
|
+
const result = validateAndLint(parsed, { checkedAt });
|
|
119
|
+
if (result.layer === 1) {
|
|
120
|
+
const errors = result.schemaErrors;
|
|
121
|
+
process.stderr.write(`Layer 1 (JSON Schema) validation failed for ${target}: ` +
|
|
122
|
+
`${errors.length} error${errors.length === 1 ? "" : "s"}\n`);
|
|
123
|
+
for (const error of errors) {
|
|
124
|
+
process.stderr.write(` ${error.instancePath === "" ? "(root)" : error.instancePath}: ${error.message}\n`);
|
|
125
|
+
}
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
const report = result.report;
|
|
129
|
+
if (values.format === "json") {
|
|
130
|
+
process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
131
|
+
}
|
|
132
|
+
else if (values.format === "html") {
|
|
133
|
+
process.stdout.write(renderHtml(report));
|
|
134
|
+
}
|
|
135
|
+
else if (values.format === "github") {
|
|
136
|
+
process.stdout.write(renderGithub(report));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
const color = process.stdout.isTTY === true && process.env.NO_COLOR === undefined;
|
|
140
|
+
process.stdout.write(renderText(report, { color }));
|
|
141
|
+
}
|
|
142
|
+
const blocking = report.summary.errors > 0 ||
|
|
143
|
+
(values["fail-on"] === "warning" && report.summary.warnings > 0);
|
|
144
|
+
process.exit(blocking ? 1 : 0);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pagefront/lint-commerce — public surface.
|
|
3
|
+
*
|
|
4
|
+
* Everything a consumer may rely on is exported here, and nothing
|
|
5
|
+
* else: `lintSheet` (Layer 2 only, for already-validated Sheets),
|
|
6
|
+
* `validateAndLint` (Layer 1 → Layer 2, the CLI's own pipeline),
|
|
7
|
+
* `validateOrganizationSheet` (Layer 1 for the Commerce Organization
|
|
8
|
+
* Sheet; no organization catalogue exists yet), the commerce
|
|
9
|
+
* catalogue object, and the types those signatures mention.
|
|
10
|
+
* `product-schema.ts`, `organization-schema.ts`, and the individual
|
|
11
|
+
* rule modules are internal.
|
|
12
|
+
*/
|
|
13
|
+
export { lintSheet } from "./lint-sheet.js";
|
|
14
|
+
export { validateAndLint } from "./validate-and-lint.js";
|
|
15
|
+
export type { SchemaError, ValidateAndLintResult } from "./validate-and-lint.js";
|
|
16
|
+
export { validateOrganizationSheet } from "./validate-organization.js";
|
|
17
|
+
export type { ValidateOrganizationResult } from "./validate-organization.js";
|
|
18
|
+
export { commerceCatalogue } from "./catalogue.js";
|
|
19
|
+
export { organizationCatalogue } from "./organization-catalogue.js";
|
|
20
|
+
export { detectSheetType } from "./sheet-type.js";
|
|
21
|
+
export type { SheetType } from "./sheet-type.js";
|
|
22
|
+
export type { Report, Finding, Summary, Severity, LintOptions, Sheet, } from "@pagefront/lint-core";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pagefront/lint-commerce — public surface.
|
|
3
|
+
*
|
|
4
|
+
* Everything a consumer may rely on is exported here, and nothing
|
|
5
|
+
* else: `lintSheet` (Layer 2 only, for already-validated Sheets),
|
|
6
|
+
* `validateAndLint` (Layer 1 → Layer 2, the CLI's own pipeline),
|
|
7
|
+
* `validateOrganizationSheet` (Layer 1 for the Commerce Organization
|
|
8
|
+
* Sheet; no organization catalogue exists yet), the commerce
|
|
9
|
+
* catalogue object, and the types those signatures mention.
|
|
10
|
+
* `product-schema.ts`, `organization-schema.ts`, and the individual
|
|
11
|
+
* rule modules are internal.
|
|
12
|
+
*/
|
|
13
|
+
export { lintSheet } from "./lint-sheet.js";
|
|
14
|
+
export { validateAndLint } from "./validate-and-lint.js";
|
|
15
|
+
export { validateOrganizationSheet } from "./validate-organization.js";
|
|
16
|
+
export { commerceCatalogue } from "./catalogue.js";
|
|
17
|
+
export { organizationCatalogue } from "./organization-catalogue.js";
|
|
18
|
+
export { detectSheetType } from "./sheet-type.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LintOptions, Report, Sheet } from "@pagefront/lint-core";
|
|
2
|
+
/**
|
|
3
|
+
* Lint a Sheet against the commerce rule catalogue for its page type:
|
|
4
|
+
* the product catalogue for product sheets, the organization catalogue
|
|
5
|
+
* for Commerce Organization Sheets, dispatched by sheet-type detection
|
|
6
|
+
* (see sheet-type.ts). Product rules never run on organization sheets
|
|
7
|
+
* and vice versa.
|
|
8
|
+
*
|
|
9
|
+
* `Report.linter_version` identifies the invoking implementation, so the
|
|
10
|
+
* default here is this package's version — lint-core's own fallback (its
|
|
11
|
+
* engine version) applies only to direct engine use.
|
|
12
|
+
*/
|
|
13
|
+
export declare function lintSheet(sheet: Sheet, options?: LintOptions): Report;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { lint } from "@pagefront/lint-core";
|
|
2
|
+
import { commerceCatalogue } from "./catalogue.js";
|
|
3
|
+
import { organizationCatalogue } from "./organization-catalogue.js";
|
|
4
|
+
import { detectSheetType } from "./sheet-type.js";
|
|
5
|
+
import { PACKAGE_VERSION } from "./version.js";
|
|
6
|
+
/**
|
|
7
|
+
* Lint a Sheet against the commerce rule catalogue for its page type:
|
|
8
|
+
* the product catalogue for product sheets, the organization catalogue
|
|
9
|
+
* for Commerce Organization Sheets, dispatched by sheet-type detection
|
|
10
|
+
* (see sheet-type.ts). Product rules never run on organization sheets
|
|
11
|
+
* and vice versa.
|
|
12
|
+
*
|
|
13
|
+
* `Report.linter_version` identifies the invoking implementation, so the
|
|
14
|
+
* default here is this package's version — lint-core's own fallback (its
|
|
15
|
+
* engine version) applies only to direct engine use.
|
|
16
|
+
*/
|
|
17
|
+
export function lintSheet(sheet, options) {
|
|
18
|
+
const opts = { ...options };
|
|
19
|
+
if (opts.linterVersion === undefined)
|
|
20
|
+
opts.linterVersion = PACKAGE_VERSION;
|
|
21
|
+
const catalogue = detectSheetType(sheet) === "organization"
|
|
22
|
+
? organizationCatalogue
|
|
23
|
+
: commerceCatalogue;
|
|
24
|
+
return lint(sheet, catalogue, opts);
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Catalogue } from "@pagefront/lint-core";
|
|
2
|
+
/**
|
|
3
|
+
* The Commerce Organization Sheet rule catalogue — the executable form
|
|
4
|
+
* of the "Commerce Organization Sheet rules" section of
|
|
5
|
+
* commerce/spec/rules.md (normative). It shares rules.md's catalogue
|
|
6
|
+
* version with the product catalogue: one normative document, one
|
|
7
|
+
* version, two page-type rule sets dispatched by sheet type (see
|
|
8
|
+
* sheet-type.ts). Product rules never run on organization sheets and
|
|
9
|
+
* vice versa.
|
|
10
|
+
*/
|
|
11
|
+
export declare const organizationCatalogue: Catalogue;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { orgW001 } from "./rules/org-w-001.js";
|
|
2
|
+
import { orgW002 } from "./rules/org-w-002.js";
|
|
3
|
+
import { orgW003 } from "./rules/org-w-003.js";
|
|
4
|
+
import { orgW004 } from "./rules/org-w-004.js";
|
|
5
|
+
import { orgW005 } from "./rules/org-w-005.js";
|
|
6
|
+
import { orgW006 } from "./rules/org-w-006.js";
|
|
7
|
+
/**
|
|
8
|
+
* The Commerce Organization Sheet rule catalogue — the executable form
|
|
9
|
+
* of the "Commerce Organization Sheet rules" section of
|
|
10
|
+
* commerce/spec/rules.md (normative). It shares rules.md's catalogue
|
|
11
|
+
* version with the product catalogue: one normative document, one
|
|
12
|
+
* version, two page-type rule sets dispatched by sheet type (see
|
|
13
|
+
* sheet-type.ts). Product rules never run on organization sheets and
|
|
14
|
+
* vice versa.
|
|
15
|
+
*/
|
|
16
|
+
export const organizationCatalogue = {
|
|
17
|
+
vertical: "commerce",
|
|
18
|
+
formatVersion: "0.9",
|
|
19
|
+
catalogueVersion: "0.5.0",
|
|
20
|
+
rules: [orgW001, orgW002, orgW003, orgW004, orgW005, orgW006],
|
|
21
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Pagefront Commerce Organization Sheet JSON Schema
|
|
3
|
+
* (commerce/spec/organization.json, format 0.9), bundled verbatim so
|
|
4
|
+
* the published package can run Layer 1 validation without the
|
|
5
|
+
* monorepo checkout. Generated from the spec file; the schema drift
|
|
6
|
+
* test (test/schema.test.mjs) fails when the two diverge. Regenerate
|
|
7
|
+
* on any schema change, in the same change that motivates it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ORGANIZATION_SCHEMA: Record<string, unknown>;
|