@openpolicy/cli 0.0.12 → 0.0.13
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 +2 -2
- package/dist/cli.js +1 -291
- package/package.json +8 -2
- package/src/cli.ts +5 -0
- package/dist/_cli-BVVbyDQ9.js +0 -49
- package/dist/_cli-BjVuFgXe.js +0 -33
- package/dist/_cli-C-Vx-Nop.js +0 -58
- package/dist/_cli-DrypJgn2.js +0 -247
- package/dist/_lib-9AbI1LBo.js +0 -35
- package/dist/_lib-9AbI1LBo.js.map +0 -1
- package/dist/_lib-D2I-M4OU.js +0 -51
- package/dist/_lib-D2I-M4OU.js.map +0 -1
- package/dist/_lib-D2LkleUQ.js +0 -60
- package/dist/_lib-D2LkleUQ.js.map +0 -1
- package/dist/_lib-MI0GKJMR.js +0 -249
- package/dist/_lib-MI0GKJMR.js.map +0 -1
- package/dist/cli +0 -0
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/commands/generate.d.ts +0 -18
- package/dist/commands/generate.d.ts.map +0 -1
- package/dist/commands/generate.test.d.ts +0 -2
- package/dist/commands/generate.test.d.ts.map +0 -1
- package/dist/commands/init.d.ts +0 -13
- package/dist/commands/init.d.ts.map +0 -1
- package/dist/commands/init.test.d.ts +0 -2
- package/dist/commands/init.test.d.ts.map +0 -1
- package/dist/commands/validate.d.ts +0 -13
- package/dist/commands/validate.d.ts.map +0 -1
- package/dist/commands/validate.test.d.ts +0 -2
- package/dist/commands/validate.test.d.ts.map +0 -1
- package/dist/generate-ItFTJ-jj.js +0 -60
- package/dist/generate-ItFTJ-jj.js.map +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/init-37NxG-6N.js +0 -249
- package/dist/init-37NxG-6N.js.map +0 -1
- package/dist/load-config-Bw8yiDkb.js +0 -35
- package/dist/load-config-Bw8yiDkb.js.map +0 -1
- package/dist/utils/load-config.d.ts +0 -2
- package/dist/utils/load-config.d.ts.map +0 -1
- package/dist/validate-DPge58Uv.js +0 -51
- package/dist/validate-DPge58Uv.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> CLI for generating and validating [OpenPolicy](https://openpolicy.sh) policy documents.
|
|
4
4
|
|
|
5
|
-
Compile privacy policies and terms of service to Markdown or
|
|
5
|
+
Compile privacy policies and terms of service to Markdown, HTML, or PDF from the command line — no Vite or Astro required.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -38,7 +38,7 @@ openpolicy generate ./terms.config.ts --format markdown --out ./public/po
|
|
|
38
38
|
|
|
39
39
|
| Flag | Default | Description |
|
|
40
40
|
|---|---|---|
|
|
41
|
-
| `--format` | `markdown` | Comma-separated output formats: `markdown`, `html` |
|
|
41
|
+
| `--format` | `markdown` | Comma-separated output formats: `markdown`, `html`, `pdf` |
|
|
42
42
|
| `--out` | `./public/policies` | Output directory |
|
|
43
43
|
| `--type` | auto-detected | Override policy type: `privacy` or `terms` |
|
|
44
44
|
| `--watch` | `false` | Watch config files and regenerate on changes |
|
package/dist/cli.js
CHANGED
|
@@ -1,291 +1 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
import { defineCommand, runMain } from "citty";
|
|
3
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
4
|
-
import { join, resolve } from "node:path";
|
|
5
|
-
import consola from "consola";
|
|
6
|
-
import { existsSync, watch } from "node:fs";
|
|
7
|
-
import { compilePolicy, expandOpenPolicyConfig, isOpenPolicyConfig, validateCookiePolicy, validatePrivacyPolicy, validateTermsOfService } from "@openpolicy/core";
|
|
8
|
-
//#region \0rolldown/runtime.js
|
|
9
|
-
var __defProp = Object.defineProperty;
|
|
10
|
-
var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
11
|
-
var __exportAll = (all, no_symbols) => {
|
|
12
|
-
let target = {};
|
|
13
|
-
for (var name in all) __defProp(target, name, {
|
|
14
|
-
get: all[name],
|
|
15
|
-
enumerable: true
|
|
16
|
-
});
|
|
17
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
-
return target;
|
|
19
|
-
};
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region package.json
|
|
22
|
-
var version = "0.0.12";
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/commands/init.ts
|
|
25
|
-
var init_exports = /* @__PURE__ */ __exportAll({
|
|
26
|
-
getOpenPolicyTemplate: () => getOpenPolicyTemplate,
|
|
27
|
-
initCommand: () => initCommand
|
|
28
|
-
});
|
|
29
|
-
function getOpenPolicyTemplate(companyName, contactEmail, policies) {
|
|
30
|
-
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
31
|
-
return `import { defineConfig } from "@openpolicy/sdk";
|
|
32
|
-
|
|
33
|
-
export default defineConfig({
|
|
34
|
-
company: {
|
|
35
|
-
name: "${companyName}",
|
|
36
|
-
legalName: "${companyName}",
|
|
37
|
-
address: "",
|
|
38
|
-
contact: "${contactEmail}",
|
|
39
|
-
},${policies.includes("privacy") ? `
|
|
40
|
-
privacy: {
|
|
41
|
-
effectiveDate: "${today}",
|
|
42
|
-
dataCollected: {
|
|
43
|
-
"Personal Information": ["Email address"],
|
|
44
|
-
},
|
|
45
|
-
legalBasis: "Legitimate interests",
|
|
46
|
-
retention: {
|
|
47
|
-
"All personal data": "As long as necessary for the purposes described in this policy",
|
|
48
|
-
},
|
|
49
|
-
cookies: { essential: true, analytics: false, marketing: false },
|
|
50
|
-
thirdParties: [],
|
|
51
|
-
userRights: ["access", "erasure"],
|
|
52
|
-
jurisdictions: ["us"],
|
|
53
|
-
},` : ""}${policies.includes("terms") ? `
|
|
54
|
-
terms: {
|
|
55
|
-
effectiveDate: "${today}",
|
|
56
|
-
acceptance: { methods: ["using the service", "creating an account"] },
|
|
57
|
-
eligibility: { minimumAge: 13 },
|
|
58
|
-
accounts: {
|
|
59
|
-
registrationRequired: false,
|
|
60
|
-
userResponsibleForCredentials: true,
|
|
61
|
-
companyCanTerminate: true,
|
|
62
|
-
},
|
|
63
|
-
prohibitedUses: [
|
|
64
|
-
"Violating any applicable laws or regulations",
|
|
65
|
-
"Infringing on intellectual property rights",
|
|
66
|
-
"Transmitting harmful or malicious content",
|
|
67
|
-
],
|
|
68
|
-
intellectualProperty: { companyOwnsService: true, usersMayNotCopy: true },
|
|
69
|
-
termination: { companyCanTerminate: true, userCanTerminate: true },
|
|
70
|
-
disclaimers: { serviceProvidedAsIs: true, noWarranties: true },
|
|
71
|
-
limitationOfLiability: { excludesIndirectDamages: true },
|
|
72
|
-
governingLaw: { jurisdiction: "Delaware, USA" },
|
|
73
|
-
changesPolicy: {
|
|
74
|
-
noticeMethod: "email or prominent notice on our website",
|
|
75
|
-
noticePeriodDays: 30,
|
|
76
|
-
},
|
|
77
|
-
},` : ""}${policies.includes("cookie") ? `
|
|
78
|
-
cookie: {
|
|
79
|
-
effectiveDate: "${today}",
|
|
80
|
-
cookies: { essential: true, analytics: false, functional: false, marketing: false },
|
|
81
|
-
jurisdictions: ["us"],
|
|
82
|
-
},` : ""}
|
|
83
|
-
});
|
|
84
|
-
`;
|
|
85
|
-
}
|
|
86
|
-
var initCommand;
|
|
87
|
-
var init_init = __esmMin((() => {
|
|
88
|
-
initCommand = defineCommand({
|
|
89
|
-
meta: {
|
|
90
|
-
name: "init",
|
|
91
|
-
description: "Interactively create a policy config file"
|
|
92
|
-
},
|
|
93
|
-
args: { out: {
|
|
94
|
-
type: "string",
|
|
95
|
-
description: "Output path for generated config",
|
|
96
|
-
default: "openpolicy.ts"
|
|
97
|
-
} },
|
|
98
|
-
async run({ args }) {
|
|
99
|
-
consola.box("Welcome to OpenPolicy\nGenerate privacy policies, terms of service, and cookie policies from a single config file.");
|
|
100
|
-
consola.start("Let's get you set up.");
|
|
101
|
-
const source = getOpenPolicyTemplate(String(await consola.prompt("Company name?", {
|
|
102
|
-
type: "text",
|
|
103
|
-
cancel: "reject"
|
|
104
|
-
})), String(await consola.prompt("Contact email?", {
|
|
105
|
-
type: "text",
|
|
106
|
-
cancel: "reject"
|
|
107
|
-
})), await consola.prompt("Which policies do you need?", {
|
|
108
|
-
type: "multiselect",
|
|
109
|
-
cancel: "reject",
|
|
110
|
-
options: [
|
|
111
|
-
"privacy",
|
|
112
|
-
"terms",
|
|
113
|
-
"cookie"
|
|
114
|
-
]
|
|
115
|
-
}));
|
|
116
|
-
const outPath = resolve(args.out);
|
|
117
|
-
await writeFile(outPath, source);
|
|
118
|
-
consola.success(`Config written to ${outPath}`);
|
|
119
|
-
consola.info(`Open ${outPath} and fill in your company's details — address, legal name, and any policy-specific fields.`);
|
|
120
|
-
consola.info(`When you're ready, run:\n\n openpolicy generate ${args.out}\n\nto compile your policies to HTML or Markdown.`);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}));
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/utils/load-config.ts
|
|
126
|
-
async function loadConfig(configPath, bustCache = false) {
|
|
127
|
-
const absPath = resolve(configPath);
|
|
128
|
-
if (!existsSync(absPath)) {
|
|
129
|
-
consola.error(`Config file not found: ${absPath}`);
|
|
130
|
-
process.exit(1);
|
|
131
|
-
}
|
|
132
|
-
const importPath = bustCache ? `${absPath}?t=${Date.now()}` : absPath;
|
|
133
|
-
let mod;
|
|
134
|
-
try {
|
|
135
|
-
mod = await import(importPath);
|
|
136
|
-
} catch (err) {
|
|
137
|
-
consola.error(`Failed to load config: ${absPath}`);
|
|
138
|
-
consola.error(err);
|
|
139
|
-
process.exit(1);
|
|
140
|
-
}
|
|
141
|
-
const config = mod["default"] ?? mod["module.exports"] ?? mod;
|
|
142
|
-
if (config === null || config === void 0 || typeof config !== "object") {
|
|
143
|
-
consola.error(`Config must export a non-null object: ${absPath}`);
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}
|
|
146
|
-
return config;
|
|
147
|
-
}
|
|
148
|
-
var init_load_config = __esmMin((() => {}));
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region src/commands/generate.ts
|
|
151
|
-
var generate_exports = /* @__PURE__ */ __exportAll({ generateCommand: () => generateCommand });
|
|
152
|
-
async function generateFromConfig(configPath, formats, outDir, bustCache = false) {
|
|
153
|
-
const config = await loadConfig(configPath, bustCache);
|
|
154
|
-
if (isOpenPolicyConfig(config)) {
|
|
155
|
-
const inputs = expandOpenPolicyConfig(config);
|
|
156
|
-
if (inputs.length === 0) {
|
|
157
|
-
consola.warn(`Unified config has no privacy or terms sections: ${configPath}`);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
await mkdir(outDir, { recursive: true });
|
|
161
|
-
for (const input of inputs) {
|
|
162
|
-
const outputFilename = input.type === "terms" ? "terms-of-service" : input.type === "cookie" ? "cookie-policy" : "privacy-policy";
|
|
163
|
-
consola.start(`Generating ${input.type} policy from ${configPath} → formats: ${formats.join(", ")}`);
|
|
164
|
-
const results = compilePolicy(input, { formats });
|
|
165
|
-
for (const result of results) {
|
|
166
|
-
const outPath = join(outDir, `${outputFilename}.${result.format === "markdown" ? "md" : result.format}`);
|
|
167
|
-
await writeFile(outPath, result.content, "utf-8");
|
|
168
|
-
consola.success(`Written: ${outPath}`);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
throw new Error(`[openpolicy] Config must use defineConfig() (OpenPolicyConfig): ${configPath}`);
|
|
174
|
-
}
|
|
175
|
-
var generateCommand;
|
|
176
|
-
var init_generate = __esmMin((() => {
|
|
177
|
-
init_load_config();
|
|
178
|
-
generateCommand = defineCommand({
|
|
179
|
-
meta: {
|
|
180
|
-
name: "generate",
|
|
181
|
-
description: "Compile a policy config to one or more output formats"
|
|
182
|
-
},
|
|
183
|
-
args: {
|
|
184
|
-
config: {
|
|
185
|
-
type: "positional",
|
|
186
|
-
description: "Path to policy config file",
|
|
187
|
-
default: "./openpolicy.ts"
|
|
188
|
-
},
|
|
189
|
-
format: {
|
|
190
|
-
type: "string",
|
|
191
|
-
description: "Comma-separated output formats: markdown,pdf,jsx",
|
|
192
|
-
default: "markdown"
|
|
193
|
-
},
|
|
194
|
-
out: {
|
|
195
|
-
type: "string",
|
|
196
|
-
description: "Output directory",
|
|
197
|
-
default: "./output"
|
|
198
|
-
},
|
|
199
|
-
watch: {
|
|
200
|
-
type: "boolean",
|
|
201
|
-
description: "Watch config file and regenerate on changes",
|
|
202
|
-
default: false
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
async run({ args }) {
|
|
206
|
-
const formats = args.format.split(",").map((f) => f.trim()).filter(Boolean);
|
|
207
|
-
const outDir = args.out;
|
|
208
|
-
const configPath = args.config;
|
|
209
|
-
if (!existsSync(configPath)) throw new Error(`Config not found: ${configPath}`);
|
|
210
|
-
await generateFromConfig(configPath, formats, outDir);
|
|
211
|
-
consola.success(`Policy generation complete → ${outDir}`);
|
|
212
|
-
if (args.watch) {
|
|
213
|
-
consola.info("Watching for changes...");
|
|
214
|
-
let debounceTimer = null;
|
|
215
|
-
watch(configPath, () => {
|
|
216
|
-
if (debounceTimer) clearTimeout(debounceTimer);
|
|
217
|
-
debounceTimer = setTimeout(async () => {
|
|
218
|
-
try {
|
|
219
|
-
await generateFromConfig(configPath, formats, outDir, true);
|
|
220
|
-
} catch (err) {
|
|
221
|
-
consola.error(`Error regenerating ${configPath}:`, err);
|
|
222
|
-
}
|
|
223
|
-
}, 100);
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}));
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/commands/validate.ts
|
|
231
|
-
var validate_exports = /* @__PURE__ */ __exportAll({ validateCommand: () => validateCommand });
|
|
232
|
-
var validateCommand;
|
|
233
|
-
var init_validate = __esmMin((() => {
|
|
234
|
-
init_load_config();
|
|
235
|
-
validateCommand = defineCommand({
|
|
236
|
-
meta: {
|
|
237
|
-
name: "validate",
|
|
238
|
-
description: "Validate a policy config for compliance"
|
|
239
|
-
},
|
|
240
|
-
args: {
|
|
241
|
-
config: {
|
|
242
|
-
type: "positional",
|
|
243
|
-
description: "Path to policy config file",
|
|
244
|
-
default: "./policy.config.ts"
|
|
245
|
-
},
|
|
246
|
-
jurisdiction: {
|
|
247
|
-
type: "string",
|
|
248
|
-
description: "Jurisdiction to validate against: gdpr, ccpa, or all",
|
|
249
|
-
default: "all"
|
|
250
|
-
}
|
|
251
|
-
},
|
|
252
|
-
async run({ args }) {
|
|
253
|
-
const configPath = args.config ?? "./policy.config.ts";
|
|
254
|
-
const config = await loadConfig(configPath);
|
|
255
|
-
if (!isOpenPolicyConfig(config)) throw new Error(`[openpolicy] Config must use defineConfig() (OpenPolicyConfig): ${configPath}`);
|
|
256
|
-
const inputs = expandOpenPolicyConfig(config);
|
|
257
|
-
let totalErrors = 0;
|
|
258
|
-
for (const input of inputs) {
|
|
259
|
-
consola.start(`Validating ${input.type} policy: ${configPath}`);
|
|
260
|
-
const issues = input.type === "terms" ? validateTermsOfService(input) : input.type === "cookie" ? validateCookiePolicy(input) : validatePrivacyPolicy(input);
|
|
261
|
-
if (issues.length === 0) {
|
|
262
|
-
consola.success(`${input.type}: no issues found.`);
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
265
|
-
for (const issue of issues) if (issue.level === "error") consola.error(issue.message);
|
|
266
|
-
else consola.warn(issue.message);
|
|
267
|
-
const errors = issues.filter((i) => i.level === "error");
|
|
268
|
-
totalErrors += errors.length;
|
|
269
|
-
if (errors.length > 0) consola.fail(`${input.type}: validation failed with ${errors.length} error(s).`);
|
|
270
|
-
else consola.success(`${input.type}: validation passed with warnings.`);
|
|
271
|
-
}
|
|
272
|
-
if (totalErrors > 0) process.exit(1);
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}));
|
|
276
|
-
//#endregion
|
|
277
|
-
//#region src/cli.ts
|
|
278
|
-
runMain(defineCommand({
|
|
279
|
-
meta: {
|
|
280
|
-
name: "openpolicy",
|
|
281
|
-
version,
|
|
282
|
-
description: "Generate and validate privacy policy documents"
|
|
283
|
-
},
|
|
284
|
-
subCommands: {
|
|
285
|
-
init: () => Promise.resolve().then(() => (init_init(), init_exports)).then((m) => m.initCommand),
|
|
286
|
-
generate: () => Promise.resolve().then(() => (init_generate(), generate_exports)).then((m) => m.generateCommand),
|
|
287
|
-
validate: () => Promise.resolve().then(() => (init_validate(), validate_exports)).then((m) => m.validateCommand)
|
|
288
|
-
}
|
|
289
|
-
}));
|
|
290
|
-
//#endregion
|
|
291
|
-
export {};
|
|
1
|
+
#!/usr/bin/env bun
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpolicy/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "CLI for generating and validating OpenPolicy privacy policy documents",
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
@@ -14,7 +14,12 @@
|
|
|
14
14
|
"README.md"
|
|
15
15
|
],
|
|
16
16
|
"bin": {
|
|
17
|
-
"openpolicy": "./
|
|
17
|
+
"openpolicy": "./src/cli.ts"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"bin": {
|
|
21
|
+
"openpolicy": "./dist/cli.js"
|
|
22
|
+
}
|
|
18
23
|
},
|
|
19
24
|
"scripts": {
|
|
20
25
|
"dev": "rolldown -c --watch",
|
|
@@ -28,6 +33,7 @@
|
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
35
|
"@openpolicy/core": "workspace:*",
|
|
36
|
+
"@openpolicy/renderers": "workspace:*",
|
|
31
37
|
"@openpolicy/tooling": "workspace:*"
|
|
32
38
|
}
|
|
33
39
|
}
|
package/src/cli.ts
ADDED
package/dist/_cli-BVVbyDQ9.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { n as detectType, t as loadConfig } from "./_cli-BjVuFgXe.js";
|
|
2
|
-
import { defineCommand } from "citty";
|
|
3
|
-
import { validatePrivacyPolicy, validateTermsOfService } from "@openpolicy/core";
|
|
4
|
-
import consola from "consola";
|
|
5
|
-
//#region src/commands/validate.ts
|
|
6
|
-
const validateCommand = defineCommand({
|
|
7
|
-
meta: {
|
|
8
|
-
name: "validate",
|
|
9
|
-
description: "Validate a policy config for compliance"
|
|
10
|
-
},
|
|
11
|
-
args: {
|
|
12
|
-
config: {
|
|
13
|
-
type: "positional",
|
|
14
|
-
description: "Path to policy config file",
|
|
15
|
-
default: "./policy.config.ts"
|
|
16
|
-
},
|
|
17
|
-
jurisdiction: {
|
|
18
|
-
type: "string",
|
|
19
|
-
description: "Jurisdiction to validate against: gdpr, ccpa, or all",
|
|
20
|
-
default: "all"
|
|
21
|
-
},
|
|
22
|
-
type: {
|
|
23
|
-
type: "string",
|
|
24
|
-
description: "Policy type: \"privacy\" or \"terms\" (auto-detected from filename if omitted)",
|
|
25
|
-
default: ""
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
async run({ args }) {
|
|
29
|
-
const configPath = args.config ?? "./policy.config.ts";
|
|
30
|
-
const policyType = detectType(args.type || void 0, configPath);
|
|
31
|
-
consola.start(`Validating ${policyType} policy: ${configPath}`);
|
|
32
|
-
const config = await loadConfig(configPath);
|
|
33
|
-
const issues = policyType === "terms" ? validateTermsOfService(config) : validatePrivacyPolicy(config);
|
|
34
|
-
if (issues.length === 0) {
|
|
35
|
-
consola.success("Config is valid — no issues found.");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
for (const issue of issues) if (issue.level === "error") consola.error(issue.message);
|
|
39
|
-
else consola.warn(issue.message);
|
|
40
|
-
const errors = issues.filter((i) => i.level === "error");
|
|
41
|
-
if (errors.length > 0) {
|
|
42
|
-
consola.fail(`Validation failed with ${errors.length} error(s).`);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
consola.success("Validation passed with warnings.");
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
//#endregion
|
|
49
|
-
export { validateCommand };
|
package/dist/_cli-BjVuFgXe.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import consola from "consola";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
//#region src/utils/detect-type.ts
|
|
5
|
-
function detectType(explicitType, configPath) {
|
|
6
|
-
if (explicitType === "privacy" || explicitType === "terms") return explicitType;
|
|
7
|
-
return configPath.toLowerCase().includes("terms") ? "terms" : "privacy";
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/utils/load-config.ts
|
|
11
|
-
async function loadConfig(configPath) {
|
|
12
|
-
const absPath = resolve(configPath);
|
|
13
|
-
if (!existsSync(absPath)) {
|
|
14
|
-
consola.error(`Config file not found: ${absPath}`);
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
let mod;
|
|
18
|
-
try {
|
|
19
|
-
mod = await import(absPath);
|
|
20
|
-
} catch (err) {
|
|
21
|
-
consola.error(`Failed to load config: ${absPath}`);
|
|
22
|
-
consola.error(err);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
const config = mod["default"] ?? mod["module.exports"] ?? mod;
|
|
26
|
-
if (config === null || config === void 0 || typeof config !== "object") {
|
|
27
|
-
consola.error(`Config must export a non-null object: ${absPath}`);
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
return config;
|
|
31
|
-
}
|
|
32
|
-
//#endregion
|
|
33
|
-
export { detectType as n, loadConfig as t };
|
package/dist/_cli-C-Vx-Nop.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { n as detectType, t as loadConfig } from "./_cli-BjVuFgXe.js";
|
|
2
|
-
import { defineCommand } from "citty";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { compilePolicy } from "@openpolicy/core";
|
|
5
|
-
import consola from "consola";
|
|
6
|
-
//#region src/commands/generate.ts
|
|
7
|
-
const generateCommand = defineCommand({
|
|
8
|
-
meta: {
|
|
9
|
-
name: "generate",
|
|
10
|
-
description: "Compile a policy config to one or more output formats"
|
|
11
|
-
},
|
|
12
|
-
args: {
|
|
13
|
-
config: {
|
|
14
|
-
type: "positional",
|
|
15
|
-
description: "Path to policy config file",
|
|
16
|
-
default: "./policy.config.ts"
|
|
17
|
-
},
|
|
18
|
-
format: {
|
|
19
|
-
type: "string",
|
|
20
|
-
description: "Comma-separated output formats: markdown,pdf,jsx",
|
|
21
|
-
default: "markdown"
|
|
22
|
-
},
|
|
23
|
-
out: {
|
|
24
|
-
type: "string",
|
|
25
|
-
description: "Output directory",
|
|
26
|
-
default: "./output"
|
|
27
|
-
},
|
|
28
|
-
type: {
|
|
29
|
-
type: "string",
|
|
30
|
-
description: "Policy type: \"privacy\" or \"terms\" (auto-detected from filename if omitted)",
|
|
31
|
-
default: ""
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
async run({ args }) {
|
|
35
|
-
const formats = (args.format ?? "markdown").split(",").map((f) => f.trim()).filter(Boolean);
|
|
36
|
-
const outDir = args.out ?? "./output";
|
|
37
|
-
const configPath = args.config ?? "./policy.config.ts";
|
|
38
|
-
const policyType = detectType(args.type || void 0, configPath);
|
|
39
|
-
consola.start(`Generating ${policyType} policy from ${configPath} → formats: ${formats.join(", ")}`);
|
|
40
|
-
const config = await loadConfig(configPath);
|
|
41
|
-
const outputFilename = policyType === "terms" ? "terms-of-service" : "privacy-policy";
|
|
42
|
-
const results = compilePolicy(policyType === "terms" ? {
|
|
43
|
-
type: "terms",
|
|
44
|
-
...config
|
|
45
|
-
} : {
|
|
46
|
-
type: "privacy",
|
|
47
|
-
...config
|
|
48
|
-
}, { formats });
|
|
49
|
-
for (const result of results) {
|
|
50
|
-
const outPath = join(outDir, `${outputFilename}.${result.format === "markdown" ? "md" : result.format}`);
|
|
51
|
-
await Bun.write(outPath, result.content);
|
|
52
|
-
consola.success(`Written: ${outPath}`);
|
|
53
|
-
}
|
|
54
|
-
consola.success(`Policy generation complete → ${outDir}`);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
//#endregion
|
|
58
|
-
export { generateCommand };
|