@schemasentry/cli 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Schema Sentry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/index.js ADDED
@@ -0,0 +1,241 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { Command } from "commander";
5
+ import { readFile } from "fs/promises";
6
+ import path from "path";
7
+ import { stableStringify as stableStringify2 } from "@schemasentry/core";
8
+
9
+ // src/report.ts
10
+ import {
11
+ stableStringify,
12
+ validateSchema
13
+ } from "@schemasentry/core";
14
+ var buildReport = (manifest, data) => {
15
+ const manifestRoutes = manifest.routes ?? {};
16
+ const dataRoutes = data.routes ?? {};
17
+ const allRoutes = /* @__PURE__ */ new Set([
18
+ ...Object.keys(manifestRoutes),
19
+ ...Object.keys(dataRoutes)
20
+ ]);
21
+ const routes = Array.from(allRoutes).sort().map((route) => {
22
+ const expectedTypes = manifestRoutes[route] ?? [];
23
+ const nodes = dataRoutes[route] ?? [];
24
+ const foundTypes = nodes.map((node) => node["@type"]).filter((type) => typeof type === "string");
25
+ const validation = validateSchema(nodes);
26
+ const issues = [...validation.issues];
27
+ if (expectedTypes.length > 0) {
28
+ if (nodes.length === 0) {
29
+ issues.push({
30
+ path: `routes["${route}"]`,
31
+ message: "No schema blocks found for route",
32
+ severity: "error",
33
+ ruleId: "coverage.missing_route"
34
+ });
35
+ }
36
+ for (const expectedType of expectedTypes) {
37
+ if (!foundTypes.includes(expectedType)) {
38
+ issues.push({
39
+ path: `routes["${route}"].types`,
40
+ message: `Missing expected schema type '${expectedType}'`,
41
+ severity: "error",
42
+ ruleId: "coverage.missing_type"
43
+ });
44
+ }
45
+ }
46
+ }
47
+ if (!manifestRoutes[route] && nodes.length > 0) {
48
+ issues.push({
49
+ path: `routes["${route}"]`,
50
+ message: "Route has schema but is missing from manifest",
51
+ severity: "warn",
52
+ ruleId: "coverage.unlisted_route"
53
+ });
54
+ }
55
+ const errorCount = issues.filter((issue) => issue.severity === "error").length;
56
+ const warnCount = issues.filter((issue) => issue.severity === "warn").length;
57
+ const score = Math.max(0, validation.score - errorCount * 5 - warnCount * 2);
58
+ return {
59
+ route,
60
+ ok: errorCount === 0,
61
+ score,
62
+ issues,
63
+ expectedTypes,
64
+ foundTypes
65
+ };
66
+ });
67
+ const summaryErrors = routes.reduce(
68
+ (count, route) => count + route.issues.filter((i) => i.severity === "error").length,
69
+ 0
70
+ );
71
+ const summaryWarnings = routes.reduce(
72
+ (count, route) => count + route.issues.filter((i) => i.severity === "warn").length,
73
+ 0
74
+ );
75
+ const summaryScore = routes.length === 0 ? 0 : Math.round(
76
+ routes.reduce((total, route) => total + route.score, 0) / routes.length
77
+ );
78
+ return {
79
+ ok: summaryErrors === 0,
80
+ summary: {
81
+ routes: routes.length,
82
+ errors: summaryErrors,
83
+ warnings: summaryWarnings,
84
+ score: summaryScore
85
+ },
86
+ routes
87
+ };
88
+ };
89
+
90
+ // src/index.ts
91
+ var program = new Command();
92
+ program.name("schemasentry").description("Schema Sentry CLI").version("0.1.0");
93
+ program.command("validate").description("Validate schema coverage and rules").option(
94
+ "-m, --manifest <path>",
95
+ "Path to manifest JSON",
96
+ "schema-sentry.manifest.json"
97
+ ).option(
98
+ "-d, --data <path>",
99
+ "Path to schema data JSON",
100
+ "schema-sentry.data.json"
101
+ ).action(async (options) => {
102
+ const manifestPath = path.resolve(process.cwd(), options.manifest);
103
+ const dataPath = path.resolve(process.cwd(), options.data);
104
+ let raw;
105
+ try {
106
+ raw = await readFile(manifestPath, "utf8");
107
+ } catch (error) {
108
+ console.error(
109
+ stableStringify2({
110
+ ok: false,
111
+ errors: [
112
+ {
113
+ code: "manifest.not_found",
114
+ message: `Manifest not found at ${manifestPath}`
115
+ }
116
+ ]
117
+ })
118
+ );
119
+ process.exit(1);
120
+ return;
121
+ }
122
+ let manifest;
123
+ try {
124
+ manifest = JSON.parse(raw);
125
+ } catch (error) {
126
+ console.error(
127
+ stableStringify2({
128
+ ok: false,
129
+ errors: [
130
+ {
131
+ code: "manifest.invalid_json",
132
+ message: "Manifest is not valid JSON"
133
+ }
134
+ ]
135
+ })
136
+ );
137
+ process.exit(1);
138
+ return;
139
+ }
140
+ if (!isManifest(manifest)) {
141
+ console.error(
142
+ stableStringify2({
143
+ ok: false,
144
+ errors: [
145
+ {
146
+ code: "manifest.invalid_shape",
147
+ message: "Manifest must contain a 'routes' object with string array values"
148
+ }
149
+ ]
150
+ })
151
+ );
152
+ process.exit(1);
153
+ return;
154
+ }
155
+ let dataRaw;
156
+ try {
157
+ dataRaw = await readFile(dataPath, "utf8");
158
+ } catch (error) {
159
+ console.error(
160
+ stableStringify2({
161
+ ok: false,
162
+ errors: [
163
+ {
164
+ code: "data.not_found",
165
+ message: `Schema data not found at ${dataPath}`
166
+ }
167
+ ]
168
+ })
169
+ );
170
+ process.exit(1);
171
+ return;
172
+ }
173
+ let data;
174
+ try {
175
+ data = JSON.parse(dataRaw);
176
+ } catch (error) {
177
+ console.error(
178
+ stableStringify2({
179
+ ok: false,
180
+ errors: [
181
+ {
182
+ code: "data.invalid_json",
183
+ message: "Schema data is not valid JSON"
184
+ }
185
+ ]
186
+ })
187
+ );
188
+ process.exit(1);
189
+ return;
190
+ }
191
+ if (!isSchemaData(data)) {
192
+ console.error(
193
+ stableStringify2({
194
+ ok: false,
195
+ errors: [
196
+ {
197
+ code: "data.invalid_shape",
198
+ message: "Schema data must contain a 'routes' object with array values"
199
+ }
200
+ ]
201
+ })
202
+ );
203
+ process.exit(1);
204
+ return;
205
+ }
206
+ const report = buildReport(manifest, data);
207
+ console.log(formatReportOutput(report));
208
+ process.exit(report.ok ? 0 : 1);
209
+ });
210
+ program.parse();
211
+ var isManifest = (value) => {
212
+ if (!value || typeof value !== "object") {
213
+ return false;
214
+ }
215
+ const manifest = value;
216
+ if (!manifest.routes || typeof manifest.routes !== "object") {
217
+ return false;
218
+ }
219
+ for (const entry of Object.values(manifest.routes)) {
220
+ if (!Array.isArray(entry) || entry.some((item) => typeof item !== "string")) {
221
+ return false;
222
+ }
223
+ }
224
+ return true;
225
+ };
226
+ var isSchemaData = (value) => {
227
+ if (!value || typeof value !== "object") {
228
+ return false;
229
+ }
230
+ const data = value;
231
+ if (!data.routes || typeof data.routes !== "object") {
232
+ return false;
233
+ }
234
+ for (const entry of Object.values(data.routes)) {
235
+ if (!Array.isArray(entry)) {
236
+ return false;
237
+ }
238
+ }
239
+ return true;
240
+ };
241
+ var formatReportOutput = (report) => stableStringify2(report);
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@schemasentry/cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI for Schema Sentry validation and reporting.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "bin": {
9
+ "schemasentry": "./dist/index.js"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/arindamdawn/schema-sentry.git",
17
+ "directory": "packages/cli"
18
+ },
19
+ "homepage": "https://github.com/arindamdawn/schema-sentry#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/arindamdawn/schema-sentry/issues"
22
+ },
23
+ "keywords": [
24
+ "schema",
25
+ "json-ld",
26
+ "structured-data",
27
+ "seo",
28
+ "cli",
29
+ "nextjs"
30
+ ],
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "dependencies": {
35
+ "commander": "^12.0.0",
36
+ "@schemasentry/core": "0.1.0"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup src/index.ts --format esm --dts --clean --tsconfig tsconfig.build.json",
40
+ "lint": "echo \"lint not configured\" && exit 0",
41
+ "test": "vitest run"
42
+ }
43
+ }