@consent-kit/cli 0.0.0-stage → 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 +21 -0
- package/README.md +32 -2
- package/dist/bin.js +21392 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.js +877 -0
- package/package.json +68 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
export { parseRegistry } from '@consent-kit/presets';
|
|
2
|
+
import { ValidationError, Change, VersionIssue, RejectedOverride, PresetReport, Receipts, Registry, RegistryDiff, ValidationResult, Overrides } from '@consent-kit/schema';
|
|
3
|
+
export { Registry } from '@consent-kit/schema';
|
|
4
|
+
import { CspDeviation, ReleasedPolicy, ReceiptManifestOptions, ContentSecurityPolicy } from '@consent-kit/compiler';
|
|
5
|
+
export { ConsentEmbedOptions, ContentSecurityPolicy, ContentSecurityPolicyOptions, CspDeviation, consentEmbed, consentScriptTag, contentSecurityPolicy, describeCspDeviations, guardManifest } from '@consent-kit/compiler';
|
|
6
|
+
import { GuardMode } from '@consent-kit/guard';
|
|
7
|
+
export { GuardMode, InlineGuardOptions, renderInlineGuard } from '@consent-kit/guard';
|
|
8
|
+
import { PhraseOverrides } from '@consent-kit/documents';
|
|
9
|
+
|
|
10
|
+
declare const EXIT_OK = 0;
|
|
11
|
+
/** The check failed, or generated files are stale. */
|
|
12
|
+
declare const EXIT_FAILED = 1;
|
|
13
|
+
/** Bad command line, or an input file that cannot be read. */
|
|
14
|
+
declare const EXIT_USAGE = 2;
|
|
15
|
+
interface Output {
|
|
16
|
+
write(text: string): unknown;
|
|
17
|
+
isTTY?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface RunOptions {
|
|
20
|
+
/** Relative paths resolve against this. Default `process.cwd()`. */
|
|
21
|
+
cwd?: string;
|
|
22
|
+
stdout?: Output;
|
|
23
|
+
stderr?: Output;
|
|
24
|
+
/** The clock `release` stamps the lock with. */
|
|
25
|
+
now?: () => Date;
|
|
26
|
+
/** Only `NO_COLOR` is read. Default `process.env`. */
|
|
27
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
28
|
+
/** How the `audit` command loads the optional `@consent-kit/audit` package. Injected in tests. */
|
|
29
|
+
loadAudit?: () => Promise<AuditModule>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The part of `@consent-kit/audit` the `audit` command uses. Declared here
|
|
33
|
+
* structurally: the package is an optional peer and is never imported statically,
|
|
34
|
+
* so that it and Playwright stay out of this CLI's install and its bundled bin.
|
|
35
|
+
*/
|
|
36
|
+
interface AuditModule {
|
|
37
|
+
run(argv: readonly string[], io?: {
|
|
38
|
+
cwd?: string;
|
|
39
|
+
stdout?: {
|
|
40
|
+
write(text: string): unknown;
|
|
41
|
+
};
|
|
42
|
+
stderr?: {
|
|
43
|
+
write(text: string): unknown;
|
|
44
|
+
};
|
|
45
|
+
programName?: string;
|
|
46
|
+
defaultRegistry?: string;
|
|
47
|
+
}): Promise<number>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Runs the CLI and returns its exit code. Never calls `process.exit`.
|
|
51
|
+
*
|
|
52
|
+
* Every command is synchronous and returns a number, except `audit`, which
|
|
53
|
+
* drives a browser and returns a promise of one. `await run(...)` covers both.
|
|
54
|
+
*/
|
|
55
|
+
declare function run(argv: readonly ['audit', ...string[]], options?: RunOptions): Promise<number>;
|
|
56
|
+
declare function run(argv: readonly string[], options?: RunOptions): number | Promise<number>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* `privacy.lock.json`: the last released state, and the history of every release.
|
|
60
|
+
* `lockVersion` 1 had no history; it is read as a history of its one release.
|
|
61
|
+
*/
|
|
62
|
+
interface LockFile {
|
|
63
|
+
lockVersion: 2;
|
|
64
|
+
/** CookieConsent's single global re-consent counter as of this release. */
|
|
65
|
+
revision: number;
|
|
66
|
+
/** `policySnapshot(registry).hash` at release time. */
|
|
67
|
+
policyHash: string;
|
|
68
|
+
/** ISO 8601 timestamp of the release. */
|
|
69
|
+
releasedAt: string;
|
|
70
|
+
/**
|
|
71
|
+
* Every release, oldest first; the last entry is this one. A release appends to it and
|
|
72
|
+
* never rewrites an entry, so a diff of the lock shows one new entry per release. Receipt
|
|
73
|
+
* endpoints keep accepting receipts for each of these policies (`receipts.manifest.gen.json`).
|
|
74
|
+
*/
|
|
75
|
+
history: ReleasedPolicy[];
|
|
76
|
+
/** The released registry in canonical form (`policySnapshot(registry).policy`). */
|
|
77
|
+
registry: Registry;
|
|
78
|
+
}
|
|
79
|
+
/** `privacy.review.json`: what a person decided about the pending changes. */
|
|
80
|
+
interface ReviewFile {
|
|
81
|
+
/** Change key to classification. Passed to `diffRegistry`, which only honours escalations. */
|
|
82
|
+
overrides: Overrides;
|
|
83
|
+
/** Change keys a person has reviewed. Unblocks `needs_review`, confirms `needs_confirmation`. */
|
|
84
|
+
acknowledged: readonly string[];
|
|
85
|
+
}
|
|
86
|
+
/** The revision a project without a lock file starts from; its first release produces 1. */
|
|
87
|
+
declare const INITIAL_REVISION = 0;
|
|
88
|
+
type Acknowledgement = 'not_required' | 'acknowledged' | 'missing';
|
|
89
|
+
interface ReportedChange extends Change {
|
|
90
|
+
acknowledgement: Acknowledgement;
|
|
91
|
+
}
|
|
92
|
+
interface Finding {
|
|
93
|
+
/** Stable code, e.g. `version/missing_bump`, `review/unacknowledged`, `override/downgrade`. */
|
|
94
|
+
code: string;
|
|
95
|
+
message: string;
|
|
96
|
+
/** The change key the finding is about, when there is one. */
|
|
97
|
+
key?: string;
|
|
98
|
+
/** The purpose the finding is about, when there is one. */
|
|
99
|
+
purposeId?: string;
|
|
100
|
+
}
|
|
101
|
+
/** The `--json` output of `check` and `diff`. Additive changes only within one `reportVersion`. */
|
|
102
|
+
interface CheckReport {
|
|
103
|
+
reportVersion: 1;
|
|
104
|
+
/** False when there is a validation error or any entry in `errors`. */
|
|
105
|
+
ok: boolean;
|
|
106
|
+
registry: string;
|
|
107
|
+
lock: {
|
|
108
|
+
path: string;
|
|
109
|
+
exists: boolean;
|
|
110
|
+
revision: number | null;
|
|
111
|
+
policyHash: string | null;
|
|
112
|
+
releasedAt: string | null;
|
|
113
|
+
};
|
|
114
|
+
/** No lock file: nothing to diff against, everything is new. */
|
|
115
|
+
firstRelease: boolean;
|
|
116
|
+
/** Hash of the current registry. Null when it does not validate. */
|
|
117
|
+
policyHash: string | null;
|
|
118
|
+
/** True when the registry differs from the lock (or there is no lock). */
|
|
119
|
+
unreleasedChanges: boolean;
|
|
120
|
+
/** `pending` is the revision the next release will carry. Null when the registry does not validate. */
|
|
121
|
+
revision: {
|
|
122
|
+
released: number | null;
|
|
123
|
+
pending: number | null;
|
|
124
|
+
};
|
|
125
|
+
reconsentRequired: boolean;
|
|
126
|
+
validationErrors: ValidationError[];
|
|
127
|
+
changes: ReportedChange[];
|
|
128
|
+
purposesNeedingBump: string[];
|
|
129
|
+
missingVersionBumps: string[];
|
|
130
|
+
unnecessaryBumps: string[];
|
|
131
|
+
versionIssues: VersionIssue[];
|
|
132
|
+
rejectedOverrides: RejectedOverride[];
|
|
133
|
+
/** Everything that fails the check, apart from `validationErrors`. */
|
|
134
|
+
errors: Finding[];
|
|
135
|
+
warnings: Finding[];
|
|
136
|
+
/**
|
|
137
|
+
* The presets the registry adopts and every local override of a preset default.
|
|
138
|
+
* Informational: overrides never fail the check. Empty lists when no preset is used.
|
|
139
|
+
*/
|
|
140
|
+
presets: Pick<PresetReport, 'applied' | 'overrides'>;
|
|
141
|
+
/**
|
|
142
|
+
* How the generated Content-Security-Policy compares with the strict default: every
|
|
143
|
+
* loosening the registry's `csp` section asks for, and every one the compiler had to
|
|
144
|
+
* make, each with its reason. Informational: a deviation never fails the check (a new
|
|
145
|
+
* one shows up in `changes` and needs a confirmation). Null when the registry does not validate.
|
|
146
|
+
*/
|
|
147
|
+
csp: {
|
|
148
|
+
level: 'strict' | 'loosened';
|
|
149
|
+
deviations: CspDeviation[];
|
|
150
|
+
} | null;
|
|
151
|
+
/**
|
|
152
|
+
* The registry's `receipts` section: where proof of each consent decision goes, or the
|
|
153
|
+
* opt-out with its reason (which is also a `receipts/opted-out` warning). Null when the
|
|
154
|
+
* registry does not validate or has no section (it then has no consent purpose).
|
|
155
|
+
*/
|
|
156
|
+
receipts: Receipts | null;
|
|
157
|
+
/** Ids of the purposes whose lawful basis is consent. Empty: the site has no banner and nobody is asked. */
|
|
158
|
+
consentPurposes: string[];
|
|
159
|
+
}
|
|
160
|
+
interface AnalysisInput {
|
|
161
|
+
/** Registry path as it should be shown to the user. */
|
|
162
|
+
registryPath: string;
|
|
163
|
+
lockPath: string;
|
|
164
|
+
parsed: ValidationResult;
|
|
165
|
+
lock: LockFile | null;
|
|
166
|
+
review: ReviewFile;
|
|
167
|
+
}
|
|
168
|
+
interface Analysis {
|
|
169
|
+
report: CheckReport;
|
|
170
|
+
/** Present when the registry validates. */
|
|
171
|
+
registry?: Registry;
|
|
172
|
+
/** The registry in canonical form: what a release stores in the lock. */
|
|
173
|
+
policy?: Registry;
|
|
174
|
+
/** Null on a first release. Absent when the registry does not validate. */
|
|
175
|
+
diff?: RegistryDiff | null;
|
|
176
|
+
}
|
|
177
|
+
/** Everything `check` knows, from already-loaded inputs. Pure. */
|
|
178
|
+
declare function analyse(input: AnalysisInput): Analysis;
|
|
179
|
+
/** The lock a release of `policy` writes: `previous` (the lock it replaces) with this release appended to its history. */
|
|
180
|
+
declare function makeLock(policy: Registry, policyHash: string, revision: number, releasedAt: Date, previous?: LockFile | null): LockFile;
|
|
181
|
+
|
|
182
|
+
declare const GUARD_MODES: readonly GuardMode[];
|
|
183
|
+
declare const DEFAULT_GUARD_MODE: GuardMode;
|
|
184
|
+
declare const DEFAULT_OUT_DIR = "src/consent.gen";
|
|
185
|
+
/** What a receipt endpoint (@consent-kit/server) checks receipts against. Only with `receipts.endpoint`. */
|
|
186
|
+
declare const RECEIPTS_MANIFEST_FILE = "receipts.manifest.gen.json";
|
|
187
|
+
interface BuildOptions {
|
|
188
|
+
/** The pending revision: what CookieConsent compares a visitor's stored consent against. */
|
|
189
|
+
revision: number;
|
|
190
|
+
guardMode: GuardMode;
|
|
191
|
+
reportUrl?: string;
|
|
192
|
+
/** Every release so far (the lock's history): the receipt manifest keeps accepting their receipts. */
|
|
193
|
+
history?: ReceiptManifestOptions['history'];
|
|
194
|
+
/** The project's wording for library phrases (`phrases` of privacy.documents.json), for the request form and emails. */
|
|
195
|
+
phraseOverrides?: PhraseOverrides;
|
|
196
|
+
}
|
|
197
|
+
/** Every generated file as filename → contents, in a stable order. Performs no I/O. */
|
|
198
|
+
declare function buildOutputs(registry: Registry, options: BuildOptions): Record<string, string>;
|
|
199
|
+
/**
|
|
200
|
+
* A `_headers` fragment (Netlify / Cloudflare Pages format) that sets the policy on every
|
|
201
|
+
* path: under `Content-Security-Policy`, or `Content-Security-Policy-Report-Only` when the
|
|
202
|
+
* registry asks for report-only, plus `Reporting-Endpoints` when a `report-to` group has a URL.
|
|
203
|
+
* A plain string is taken as the value of an enforcing `Content-Security-Policy` header.
|
|
204
|
+
*/
|
|
205
|
+
declare function headersFile(csp: Pick<ContentSecurityPolicy, 'headerName' | 'header' | 'reportingEndpoints'> | string): string;
|
|
206
|
+
type FileStatus = 'created' | 'updated' | 'unchanged';
|
|
207
|
+
/** Compares generated contents with what is on disk (`null` = file missing). */
|
|
208
|
+
declare function planWrites(outputs: Readonly<Record<string, string>>, existing: (name: string) => string | null): {
|
|
209
|
+
name: string;
|
|
210
|
+
status: FileStatus;
|
|
211
|
+
}[];
|
|
212
|
+
|
|
213
|
+
declare const DEFAULT_REGISTRY_FILE = "privacy.registry.yaml";
|
|
214
|
+
declare const LOCK_FILE = "privacy.lock.json";
|
|
215
|
+
declare const REVIEW_FILE = "privacy.review.json";
|
|
216
|
+
|
|
217
|
+
/** Text styling. `plain` is used whenever stdout is not a TTY or `NO_COLOR` is set. */
|
|
218
|
+
interface Painter {
|
|
219
|
+
bold(text: string): string;
|
|
220
|
+
dim(text: string): string;
|
|
221
|
+
red(text: string): string;
|
|
222
|
+
yellow(text: string): string;
|
|
223
|
+
green(text: string): string;
|
|
224
|
+
}
|
|
225
|
+
/** One line per validation error: `file:line:col rule message`. */
|
|
226
|
+
declare function renderValidationErrors(report: CheckReport, paint?: Painter): string[];
|
|
227
|
+
/** The diff against the lock, grouped by classification. Expects a report of a valid registry. */
|
|
228
|
+
declare function renderDiff(report: CheckReport, paint?: Painter): string[];
|
|
229
|
+
/** Full `check` output: validation errors, or the diff followed by findings and a verdict. */
|
|
230
|
+
declare function renderCheck(report: CheckReport, paint?: Painter): string[];
|
|
231
|
+
/** What `release` prints: a changelog entry for the release it just wrote. */
|
|
232
|
+
declare function renderChangelogEntry(report: CheckReport, releasedAt: string, paint?: Painter): string[];
|
|
233
|
+
|
|
234
|
+
export { DEFAULT_GUARD_MODE, DEFAULT_OUT_DIR, DEFAULT_REGISTRY_FILE, EXIT_FAILED, EXIT_OK, EXIT_USAGE, GUARD_MODES, INITIAL_REVISION, LOCK_FILE, RECEIPTS_MANIFEST_FILE, REVIEW_FILE, analyse, buildOutputs, headersFile, makeLock, planWrites, renderChangelogEntry, renderCheck, renderDiff, renderValidationErrors, run };
|
|
235
|
+
export type { Acknowledgement, Analysis, AnalysisInput, AuditModule, BuildOptions, CheckReport, FileStatus, Finding, LockFile, Output, ReportedChange, ReviewFile, RunOptions };
|