@vllnt/convex-consent 0.1.0 → 0.1.1-canary.2f6a182
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/CHANGELOG.md +91 -0
- package/README.md +161 -49
- package/dist/client/index.d.ts +23 -10
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +23 -10
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +4 -3
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/crons.js +1 -1
- package/dist/component/crons.js.map +1 -1
- package/dist/component/mutations.d.ts +16 -10
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +37 -14
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts +6 -4
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +9 -7
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.d.ts +1 -2
- package/dist/component/schema.js +3 -4
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +3 -2
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +3 -2
- package/dist/component/validators.js.map +1 -1
- package/dist/shared.d.ts +5 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +5 -3
- package/dist/shared.js.map +1 -1
- package/docs/API.md +154 -0
- package/llms.txt +34 -0
- package/package.json +36 -19
- package/src/client/index.ts +23 -10
- package/src/client/types.ts +4 -3
- package/src/component/crons.ts +1 -1
- package/src/component/mutations.ts +38 -14
- package/src/component/queries.ts +9 -7
- package/src/component/schema.ts +3 -4
- package/src/component/validators.ts +3 -2
- package/src/shared.ts +5 -3
- package/src/test.ts +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based on
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.1.1] - Unreleased
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Ship `docs/API.md`, `CHANGELOG.md` and `llms.txt` in the npm tarball, so coding agents read
|
|
12
|
+
docs that match the installed version from `node_modules/@vllnt/convex-consent/`. `llms.txt`
|
|
13
|
+
links shipped files by relative path and gains a "For coding agents" note and an ecosystem
|
|
14
|
+
link; the README gains the same note and a "Related packages" section.
|
|
15
|
+
- `docs/API.md` documents the package entry points (`./test`, `./convex.config`,
|
|
16
|
+
`./_generated/component`) and the client options.
|
|
17
|
+
- `pnpm test:package`, which `pnpm build` now runs (so CI and the publish workflow run it), fails
|
|
18
|
+
when a required file is missing from the tarball, when Markdown outside the shipped docs set (such
|
|
19
|
+
as a contributor or internal doc) is packed, or when an `llms.txt` link does not resolve inside the
|
|
20
|
+
tarball.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Drop the `consentState.by_subject` index: it was a prefix of `by_subject_purpose`, which now serves
|
|
25
|
+
`getStatesForSubject` (results ordered by `purpose`). Saves one index entry per state row.
|
|
26
|
+
- `homepage` points at the package page on oss.vllnt.com.
|
|
27
|
+
- Canary publishes on every push to `main` that touches the package or its shipped docs; the
|
|
28
|
+
repository-variable gate is removed. It publishes under the `canary` dist-tag only and never moves
|
|
29
|
+
`latest`.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- `record` rejects an empty `subjectRef`, `purpose` or `version`, and `withdraw` an empty
|
|
34
|
+
`subjectRef` or `purpose`, with `ConvexError({ code: "INVALID_ARGUMENT" })`.
|
|
35
|
+
- `@vllnt/convex-consent/test` now type-checks under `moduleResolution: nodenext`
|
|
36
|
+
(explicit `.js` relative imports, Vite client types referenced).
|
|
37
|
+
- Documentation drift: the shipped `prune` comments now say events are not checked for being
|
|
38
|
+
superseded and that `before` defaults to now minus 365 days; the `proofValidator` comments no
|
|
39
|
+
longer claim `convex/values` validators have a `.parse`; `docs/API.md` states which `ctx` each
|
|
40
|
+
method needs.
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
44
|
+
- Upgrade dev tooling (vitest 5, vite 8.3, convex 1.48, convex-test 0.0.65, prettier 3.9.10) and
|
|
45
|
+
override the vulnerable transitive `handlebars` and `deepmerge-ts` releases.
|
|
46
|
+
- Adopt pnpm 10 with a release-age gate; releases are published only from CI with npm
|
|
47
|
+
trusted publishing and provenance.
|
|
48
|
+
|
|
49
|
+
## [0.1.0] - 2026-09-01
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- First release of `@vllnt/convex-consent` — an append-only consent ledger
|
|
54
|
+
(GDPR Art. 6/7) per `(subjectRef, purpose)`.
|
|
55
|
+
- `record(subjectRef, purpose, decision, { version?, proof? })` appends an
|
|
56
|
+
immutable `consentEvents` row (the legal proof) and updates the O(1)
|
|
57
|
+
`consentState` projection; `decision` is `granted`/`denied`/`withdrawn`.
|
|
58
|
+
- `withdraw(subjectRef, purpose, proof?)` (GDPR Art. 7(3)) revokes a grant by
|
|
59
|
+
appending a `withdrawn` event — only when a grant is currently held, else throws
|
|
60
|
+
`ConvexError({ code: "NO_CONSENT" })` or `ConvexError({ code: "NOT_GRANTED" })`.
|
|
61
|
+
- `check(subjectRef, purpose, requiredVersion?)` is the runtime gate, returning
|
|
62
|
+
`{ granted, stale, decision, version, at }`; a grant for an older policy version
|
|
63
|
+
returns `stale: true` so the host re-prompts.
|
|
64
|
+
- `getState`, `getStatesForSubject`, and paginated `history` read the record;
|
|
65
|
+
`history` pages the immutable ledger newest-first for an audit or data subject
|
|
66
|
+
request.
|
|
67
|
+
- Append-only ledger: a recorded decision is never mutated — withdrawal is a new
|
|
68
|
+
event, not an edit — so the proof trail can't be silently rewritten.
|
|
69
|
+
- Server-sourced time: every event's `at` is stamped from `Date.now()` inside the
|
|
70
|
+
handler — no caller-supplied clock.
|
|
71
|
+
- Typed generics: `Consent<TProof>` with an optional `proofValidator` host parser
|
|
72
|
+
narrowing the opaque stored `proof` at the client boundary on write and read — no
|
|
73
|
+
`v.any()` dump, no unchecked cast — plus a configurable `defaultVersion`.
|
|
74
|
+
- Bounded, self-rescheduling `prune` (`take(batch)` + scheduler) that removes only
|
|
75
|
+
superseded ledger events past the cutoff, plus a built-in daily prune cron
|
|
76
|
+
(`crons.ts`); idempotent. The current-state projection is never pruned. Default
|
|
77
|
+
retention 365 days.
|
|
78
|
+
- Mount-safe: correct under multiple `app.use(component, { name })` mounts — each
|
|
79
|
+
instance is sandboxed, the cron is registered per instance.
|
|
80
|
+
|
|
81
|
+
### Fixed
|
|
82
|
+
|
|
83
|
+
- Apply the documented 365-day default ledger retention and reject invalid prune batches to
|
|
84
|
+
prevent premature proof deletion and scheduler loops.
|
|
85
|
+
|
|
86
|
+
### Changed
|
|
87
|
+
|
|
88
|
+
- Treat Convex `_generated` output as CLI-owned, exclude it from formatting, and expose a
|
|
89
|
+
dedicated codegen script.
|
|
90
|
+
- Refresh all direct dependencies to their latest compatible releases.
|
|
91
|
+
- Require `convex@^1.45.0` and update `convex-test` to `^0.0.56`.
|
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<!-- Badges -->
|
|
2
|
+
|
|
2
3
|
[](https://www.convex.dev/components)
|
|
3
4
|
[](https://www.npmjs.com/package/@vllnt/convex-consent)
|
|
4
5
|
[](https://github.com/vllnt/convex-consent/actions/workflows/ci.yml)
|
|
@@ -15,31 +16,54 @@ const gate = await consent.check(ctx, subjectRef, "analytics"); // { granted, st
|
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
The host records a subject's decision for a purpose (`granted` / `denied` /
|
|
18
|
-
`withdrawn`) — each call appends an immutable ledger event (the
|
|
19
|
-
updates an O(1) current-state projection — then gates processing with
|
|
20
|
-
the policy version changes, a
|
|
21
|
-
Domain-neutral: a cookie gate, a marketing
|
|
19
|
+
`withdrawn`) — each call appends an immutable ledger event (the stored evidence)
|
|
20
|
+
and updates an O(1) current-state projection — then gates processing with
|
|
21
|
+
`check`. When the policy version changes, a grant with a different version goes
|
|
22
|
+
`stale` so the host re-prompts. Domain-neutral: a cookie gate, a marketing
|
|
23
|
+
opt-in, a device-tied consent.
|
|
22
24
|
|
|
23
25
|
## Features
|
|
24
26
|
|
|
25
|
-
- **Record-and-gate** — `record` appends an immutable event and updates the
|
|
26
|
-
|
|
27
|
-
- **
|
|
28
|
-
|
|
29
|
-
- **
|
|
30
|
-
|
|
31
|
-
- **
|
|
32
|
-
|
|
27
|
+
- **Record-and-gate** — `record` appends an immutable event and updates the
|
|
28
|
+
projection; `check` is the O(1) runtime gate before processing.
|
|
29
|
+
- **Append-only ledger** — every decision is a `consentEvents` row, never
|
|
30
|
+
mutated; `history` pages the retained trail for an audit or DSR.
|
|
31
|
+
- **Easy withdrawal** — `withdraw` (Art. 7(3)) revokes a held grant; withdrawing
|
|
32
|
+
something never granted throws a coded error.
|
|
33
|
+
- **Version staleness** — `check` returns `stale: true` when a grant's policy
|
|
34
|
+
version differs from `requiredVersion` (string equality, not version
|
|
35
|
+
ordering).
|
|
36
|
+
- **Server-sourced time** — every event's `at` is stamped from the server clock;
|
|
37
|
+
a caller can never supply a timestamp.
|
|
38
|
+
- **Typed, opaque proof** — `Consent<TProof>` with an optional `proofValidator`
|
|
39
|
+
narrows the stored evidence at the boundary.
|
|
40
|
+
- **Bounded prune + cron** — a daily cron sweeps all ledger events past
|
|
41
|
+
retention, including evidence for the current decision; the live projection is
|
|
42
|
+
never pruned.
|
|
43
|
+
- **Mount-safe** — correct under multiple named `app.use` mounts (web +
|
|
44
|
+
marketing consent on one backend), each an isolated sandbox.
|
|
33
45
|
|
|
34
46
|
## Installation
|
|
35
47
|
|
|
36
48
|
```bash
|
|
37
|
-
pnpm add @vllnt/convex-consent
|
|
49
|
+
pnpm add @vllnt/convex-consent convex@^1.45.0
|
|
38
50
|
```
|
|
39
51
|
|
|
40
|
-
Peer dependency: `convex@^1.
|
|
52
|
+
Peer dependency: `convex@^1.45.0`. The command installs the latest stable
|
|
53
|
+
release; use `@vllnt/convex-consent@canary` for the newest pre-release build
|
|
54
|
+
from `main`, and pin a resolved canary version for reproducible installs.
|
|
55
|
+
|
|
56
|
+
## For coding agents
|
|
57
|
+
|
|
58
|
+
The docs are bundled in this package at
|
|
59
|
+
`node_modules/@vllnt/convex-consent/docs/` and match the installed version. Read
|
|
60
|
+
them, and `llms.txt`, before writing code that uses the package.
|
|
41
61
|
|
|
42
|
-
##
|
|
62
|
+
## Quick start
|
|
63
|
+
|
|
64
|
+
After mounting, run `pnpm exec convex dev` to generate `components.consent`.
|
|
65
|
+
These internal functions are for trusted server callers. Public wrappers must
|
|
66
|
+
derive and authorize the subject rather than trust a caller-supplied identity.
|
|
43
67
|
|
|
44
68
|
```ts
|
|
45
69
|
// convex/convex.config.ts
|
|
@@ -54,36 +78,56 @@ export default app;
|
|
|
54
78
|
```ts
|
|
55
79
|
// convex/consent.ts — host owns auth; pass an opaque subjectRef in.
|
|
56
80
|
import { components } from "./_generated/api";
|
|
57
|
-
import {
|
|
81
|
+
import { internalMutation, internalQuery } from "./_generated/server";
|
|
58
82
|
import { v } from "convex/values";
|
|
59
83
|
import { Consent } from "@vllnt/convex-consent";
|
|
60
84
|
|
|
61
85
|
const consent = new Consent<{ policyHash: string }>(components.consent, {
|
|
62
86
|
defaultVersion: "2024-policy",
|
|
63
|
-
proofValidator:
|
|
87
|
+
proofValidator: (value) => {
|
|
88
|
+
if (
|
|
89
|
+
typeof value !== "object" ||
|
|
90
|
+
value === null ||
|
|
91
|
+
!("policyHash" in value) ||
|
|
92
|
+
typeof value.policyHash !== "string"
|
|
93
|
+
) {
|
|
94
|
+
throw new Error("Expected a policyHash string");
|
|
95
|
+
}
|
|
96
|
+
return { policyHash: value.policyHash };
|
|
97
|
+
},
|
|
64
98
|
});
|
|
65
99
|
|
|
66
100
|
// Record a decision, gate processing on it, and withdraw — host resolves identity → subjectRef.
|
|
67
|
-
export const setConsent =
|
|
68
|
-
args: {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
101
|
+
export const setConsent = internalMutation({
|
|
102
|
+
args: {
|
|
103
|
+
subjectRef: v.string(),
|
|
104
|
+
purpose: v.string(),
|
|
105
|
+
granted: v.boolean(),
|
|
106
|
+
policyHash: v.string(),
|
|
107
|
+
},
|
|
108
|
+
handler: async (ctx, { subjectRef, purpose, granted, policyHash }) => {
|
|
109
|
+
await consent.record(
|
|
110
|
+
ctx,
|
|
111
|
+
subjectRef,
|
|
112
|
+
purpose,
|
|
113
|
+
granted ? "granted" : "denied",
|
|
114
|
+
{ proof: { policyHash } },
|
|
115
|
+
);
|
|
72
116
|
},
|
|
73
117
|
});
|
|
74
118
|
|
|
75
|
-
export const mayProcess =
|
|
76
|
-
args: { purpose: v.string() },
|
|
77
|
-
handler: async (ctx, { purpose }) => {
|
|
78
|
-
const subjectRef = await resolveSubject(ctx);
|
|
119
|
+
export const mayProcess = internalQuery({
|
|
120
|
+
args: { subjectRef: v.string(), purpose: v.string() },
|
|
121
|
+
handler: async (ctx, { subjectRef, purpose }) => {
|
|
79
122
|
const gate = await consent.check(ctx, subjectRef, purpose, "2024-policy");
|
|
80
|
-
return gate.granted; // false (gate.stale === true) if
|
|
123
|
+
return gate.granted; // false (gate.stale === true) if their grant has a different version
|
|
81
124
|
},
|
|
82
125
|
});
|
|
83
126
|
|
|
84
|
-
export const revoke =
|
|
85
|
-
args: { purpose: v.string() },
|
|
86
|
-
handler:
|
|
127
|
+
export const revoke = internalMutation({
|
|
128
|
+
args: { subjectRef: v.string(), purpose: v.string() },
|
|
129
|
+
handler: (ctx, { subjectRef, purpose }) =>
|
|
130
|
+
consent.withdraw(ctx, subjectRef, purpose),
|
|
87
131
|
});
|
|
88
132
|
```
|
|
89
133
|
|
|
@@ -91,29 +135,53 @@ Client options: `new Consent(component, { defaultVersion?, proofValidator? })`.
|
|
|
91
135
|
|
|
92
136
|
## API Reference
|
|
93
137
|
|
|
94
|
-
| Method
|
|
95
|
-
|
|
138
|
+
| Method | Kind | Result |
|
|
139
|
+
| --------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------- |
|
|
96
140
|
| `record(ctx, subjectRef, purpose, decision, opts?)` | mutation | `{ at }` (`decision`: `"granted" \| "denied" \| "withdrawn"`; `opts`: `{ version?; proof? }`) |
|
|
97
|
-
| `withdraw(ctx, subjectRef, purpose, proof?)`
|
|
98
|
-
| `check(ctx, subjectRef, purpose, requiredVersion?)` | query
|
|
99
|
-
| `getState(ctx, subjectRef, purpose)`
|
|
100
|
-
| `getStatesForSubject(ctx, subjectRef)`
|
|
101
|
-
| `history(ctx, subjectRef, purpose, paginationOpts)` | query
|
|
102
|
-
| `prune(ctx, opts?)`
|
|
141
|
+
| `withdraw(ctx, subjectRef, purpose, proof?)` | mutation | `{ at }` |
|
|
142
|
+
| `check(ctx, subjectRef, purpose, requiredVersion?)` | query | `ConsentCheck` (`{ granted; stale; decision; version; at }`) |
|
|
143
|
+
| `getState(ctx, subjectRef, purpose)` | query | `ConsentState \| null` |
|
|
144
|
+
| `getStatesForSubject(ctx, subjectRef)` | query | `ConsentState[]` |
|
|
145
|
+
| `history(ctx, subjectRef, purpose, paginationOpts)` | query | `PaginationResult<ConsentEvent>` |
|
|
146
|
+
| `prune(ctx, opts?)` | mutation | `number` (ledger events removed in the first bounded pass) |
|
|
103
147
|
|
|
104
148
|
Full reference: [docs/API.md](docs/API.md).
|
|
105
149
|
|
|
106
|
-
##
|
|
150
|
+
## Options and limitations
|
|
151
|
+
|
|
152
|
+
- `defaultVersion` defaults to `"1"` and is used for records that omit
|
|
153
|
+
`version`; `check` compares only an explicitly supplied `requiredVersion`.
|
|
154
|
+
- `proofValidator` is a parser `(unknown) => TProof`, not `v.*.parse`.
|
|
155
|
+
- `prune` defaults to 365 days and batch 200 (integer 1–500); non-finite cutoffs
|
|
156
|
+
throw `INVALID_BEFORE`, invalid batches `INVALID_BATCH`.
|
|
157
|
+
- The default daily cron can delete even the latest event's proof. Custom calls
|
|
158
|
+
cannot extend its retention. Export evidence before expiry if your policy
|
|
159
|
+
requires longer storage; this package alone does not establish legal
|
|
160
|
+
compliance.
|
|
161
|
+
- `record` throws `INVALID_ARGUMENT` for an empty `subjectRef`, `purpose` or
|
|
162
|
+
`version`; `withdraw` for an empty `subjectRef` or `purpose`.
|
|
163
|
+
- `withdraw` throws `NO_CONSENT` for an unrecorded pair and `NOT_GRANTED` for a
|
|
164
|
+
non-granted current decision; it is not an idempotent revoke.
|
|
165
|
+
- Mount separately with `app.use(consent, { name: "marketingConsent" })` and
|
|
166
|
+
`new Consent(components.marketingConsent)`.
|
|
167
|
+
|
|
168
|
+
## Integrations
|
|
107
169
|
|
|
108
170
|
Backend-only — no `./react` entry. Consent state is read through an ordinary
|
|
109
|
-
reactive `useQuery` over the host's re-exported `check` / `getState` refs;
|
|
110
|
-
proof is sensitive and gating is server-side, so there is no safe client
|
|
171
|
+
reactive `useQuery` over the host's re-exported `check` / `getState` refs;
|
|
172
|
+
consent proof is sensitive and gating is server-side, so there is no safe client
|
|
173
|
+
surface.
|
|
111
174
|
|
|
112
175
|
## Security
|
|
113
176
|
|
|
114
|
-
- **Auth-agnostic** — the host authenticates the caller, decides who may
|
|
115
|
-
|
|
116
|
-
|
|
177
|
+
- **Auth-agnostic** — the host authenticates the caller, decides who may
|
|
178
|
+
record/read a subject's consent, and passes an opaque `subjectRef`; tables are
|
|
179
|
+
sandboxed.
|
|
180
|
+
- **Append-only** — a recorded decision and its proof can never be silently
|
|
181
|
+
rewritten; withdrawal is a new event, not an edit.
|
|
182
|
+
- **Server-sourced time** — every event's `at` comes from `Date.now()` in the
|
|
183
|
+
handler, never the caller; the `proof` is opaque, narrowed by the host
|
|
184
|
+
validator.
|
|
117
185
|
|
|
118
186
|
See [docs/API.md](docs/API.md).
|
|
119
187
|
|
|
@@ -124,20 +192,64 @@ pnpm test # single run
|
|
|
124
192
|
pnpm test:coverage # enforced 100% on covered files
|
|
125
193
|
```
|
|
126
194
|
|
|
127
|
-
Tests run against the real component runtime via `convex-test`
|
|
195
|
+
Tests run against the real component runtime via `convex-test`
|
|
196
|
+
(`@edge-runtime/vm`), not mocks.
|
|
197
|
+
|
|
198
|
+
### Testing your app
|
|
199
|
+
|
|
200
|
+
`@vllnt/convex-consent/test` exports `register(t, name = "consent")` to mount
|
|
201
|
+
the component in a `convex-test` instance. It needs `convex-test` and `vitest`
|
|
202
|
+
(with Vite's `import.meta.glob`) in the consuming app:
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
/// <reference types="vite/client" />
|
|
206
|
+
import { convexTest } from "convex-test";
|
|
207
|
+
import { register } from "@vllnt/convex-consent/test";
|
|
208
|
+
import schema from "./schema";
|
|
209
|
+
|
|
210
|
+
const t = convexTest(schema, import.meta.glob("./**/*.ts"));
|
|
211
|
+
register(t);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Documentation
|
|
215
|
+
|
|
216
|
+
`llms.txt` is the maintained discovery index. `pnpm generate:llms` checks its
|
|
217
|
+
heading and local links without generating a source bundle.
|
|
218
|
+
|
|
219
|
+
[API reference](docs/API.md) · [LLM index](llms.txt) ·
|
|
220
|
+
[Security policy](https://github.com/vllnt/convex-consent/blob/main/SECURITY.md)
|
|
221
|
+
|
|
222
|
+
## Related packages
|
|
223
|
+
|
|
224
|
+
- [`@vllnt/convex-suppression`](https://oss.vllnt.com/packages/convex-suppression)
|
|
225
|
+
— a do-not-contact suppression list, hash-keyed and channel-aware. Use it to
|
|
226
|
+
stop contacting an address on a channel; use `@vllnt/convex-consent` for
|
|
227
|
+
per-purpose, versioned consent decisions with an append-only history.
|
|
228
|
+
- [`@vllnt/convex-email`](https://oss.vllnt.com/packages/convex-email) — a
|
|
229
|
+
durable outbound transactional email queue. It sends; it does not store
|
|
230
|
+
consent. Call `check` in your own code before enqueueing a message that needs
|
|
231
|
+
consent.
|
|
232
|
+
- [`@vllnt/analytics`](https://oss.vllnt.com/packages/analytics) — privacy-first
|
|
233
|
+
analytics with consent management and React integration. Use it to track usage
|
|
234
|
+
in a React app; use `@vllnt/convex-consent` when you need a durable,
|
|
235
|
+
auditable, server-side record of decisions for any purpose.
|
|
128
236
|
|
|
129
237
|
## Contributing
|
|
130
238
|
|
|
131
|
-
See
|
|
239
|
+
See
|
|
240
|
+
[CONTRIBUTING.md](https://github.com/vllnt/convex-consent/blob/main/CONTRIBUTING.md).
|
|
132
241
|
|
|
133
242
|
## Author
|
|
134
243
|
|
|
135
|
-
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
136
|
-
|
|
137
|
-
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
244
|
+
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
245
|
+
[bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
138
246
|
|
|
139
247
|
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
140
248
|
|
|
141
249
|
## License
|
|
142
250
|
|
|
143
251
|
MIT — see [LICENSE](LICENSE).
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
Part of vllnt oss: https://oss.vllnt.com
|
package/dist/client/index.d.ts
CHANGED
|
@@ -83,7 +83,17 @@ interface RunMutationCtx {
|
|
|
83
83
|
* ```ts
|
|
84
84
|
* const consent = new Consent(components.consent, {
|
|
85
85
|
* defaultVersion: "2024-policy",
|
|
86
|
-
* proofValidator:
|
|
86
|
+
* proofValidator: (value) => {
|
|
87
|
+
* if (
|
|
88
|
+
* typeof value !== "object" ||
|
|
89
|
+
* value === null ||
|
|
90
|
+
* !("policyHash" in value) ||
|
|
91
|
+
* typeof value.policyHash !== "string"
|
|
92
|
+
* ) {
|
|
93
|
+
* throw new Error("Expected a policyHash string");
|
|
94
|
+
* }
|
|
95
|
+
* return { policyHash: value.policyHash };
|
|
96
|
+
* },
|
|
87
97
|
* });
|
|
88
98
|
* await consent.record(ctx, "user_42", "analytics", "granted", {
|
|
89
99
|
* proof: { policyHash },
|
|
@@ -125,8 +135,9 @@ export declare class Consent<TProof = unknown> {
|
|
|
125
135
|
/**
|
|
126
136
|
* The runtime gate: may the host process `purpose` for `subjectRef`? Pass
|
|
127
137
|
* `requiredVersion` to also require the consent be for the current policy
|
|
128
|
-
* version — when the
|
|
129
|
-
* (and not `granted`) so the host
|
|
138
|
+
* version — when the granted `version` differs from it (string inequality, not
|
|
139
|
+
* version ordering) the result is `stale` (and not `granted`) so the host
|
|
140
|
+
* re-prompts.
|
|
130
141
|
*/
|
|
131
142
|
check(ctx: RunQueryCtx, subjectRef: string, purpose: string, requiredVersion?: string): Promise<ConsentCheck>;
|
|
132
143
|
/** The raw current decision for one `(subjectRef, purpose)` pair, or `null`. */
|
|
@@ -136,16 +147,18 @@ export declare class Consent<TProof = unknown> {
|
|
|
136
147
|
/**
|
|
137
148
|
* Page the immutable consent ledger for one `(subjectRef, purpose)` pair,
|
|
138
149
|
* newest-first. Returns the standard Convex pagination envelope with each event
|
|
139
|
-
* narrowed to the typed view — the
|
|
140
|
-
* subject request.
|
|
150
|
+
* narrowed to the typed view — the retained proof trail (events already pruned
|
|
151
|
+
* are gone) for an audit or a data subject request.
|
|
141
152
|
*/
|
|
142
153
|
history(ctx: RunQueryCtx, subjectRef: string, purpose: string, paginationOpts: PaginationOptions): Promise<PaginationResult<ConsentEvent<TProof>>>;
|
|
143
154
|
/**
|
|
144
|
-
* Delete
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
155
|
+
* Delete ledger events whose `at < before` in bounded batches, oldest first.
|
|
156
|
+
* `before` defaults to the server clock minus the 365-day retention window;
|
|
157
|
+
* `batch` (integer 1–500, default 200) caps each pass and the sweep
|
|
158
|
+
* self-reschedules until the tail is clean. Events are not checked for being
|
|
159
|
+
* superseded, so the proof for a pair's current decision can be deleted too.
|
|
160
|
+
* The current-state projection is never pruned. Returns the count removed in
|
|
161
|
+
* the first pass. The built-in daily cron drives this automatically.
|
|
149
162
|
*/
|
|
150
163
|
prune(ctx: RunMutationCtx, opts?: {
|
|
151
164
|
before?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,MAAM,EACN,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB;;;;GAIG;AACH,KAAK,QAAQ,GAAG;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,eAAe,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE;QACT,MAAM,EAAE,iBAAiB,CACvB,UAAU,EACV,UAAU,EACV;YACE,UAAU,EAAE,MAAM,CAAC;YACnB,OAAO,EAAE,MAAM,CAAC;YAChB,QAAQ,EAAE,eAAe,CAAC;YAC1B,OAAO,EAAE,MAAM,CAAC;YAChB,KAAK,CAAC,EAAE,OAAO,CAAC;SACjB,EACD;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CACf,CAAC;QACF,QAAQ,EAAE,iBAAiB,CACzB,UAAU,EACV,UAAU,EACV;YAAE,UAAU,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,OAAO,CAAA;SAAE,EACxD;YAAE,EAAE,EAAE,MAAM,CAAA;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OAAO,CACX,GAAG,EAAE,WAAW,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,iBAAiB,GAChC,OAAO,CAAC,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAOjD;IAED;;;;;;;;OAQG;IACH,KAAK,CACH,GAAG,EAAE,cAAc,EACnB,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAC7C,OAAO,CAAC,MAAM,CAAC,CAKjB;CACF;AAED,YAAY,EACV,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,MAAM,EACN,aAAa,GACd,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -15,7 +15,17 @@ import { DEFAULT_PRUNE_BATCH, DEFAULT_VERSION } from "../shared.js";
|
|
|
15
15
|
* ```ts
|
|
16
16
|
* const consent = new Consent(components.consent, {
|
|
17
17
|
* defaultVersion: "2024-policy",
|
|
18
|
-
* proofValidator:
|
|
18
|
+
* proofValidator: (value) => {
|
|
19
|
+
* if (
|
|
20
|
+
* typeof value !== "object" ||
|
|
21
|
+
* value === null ||
|
|
22
|
+
* !("policyHash" in value) ||
|
|
23
|
+
* typeof value.policyHash !== "string"
|
|
24
|
+
* ) {
|
|
25
|
+
* throw new Error("Expected a policyHash string");
|
|
26
|
+
* }
|
|
27
|
+
* return { policyHash: value.policyHash };
|
|
28
|
+
* },
|
|
19
29
|
* });
|
|
20
30
|
* await consent.record(ctx, "user_42", "analytics", "granted", {
|
|
21
31
|
* proof: { policyHash },
|
|
@@ -88,8 +98,9 @@ export class Consent {
|
|
|
88
98
|
/**
|
|
89
99
|
* The runtime gate: may the host process `purpose` for `subjectRef`? Pass
|
|
90
100
|
* `requiredVersion` to also require the consent be for the current policy
|
|
91
|
-
* version — when the
|
|
92
|
-
* (and not `granted`) so the host
|
|
101
|
+
* version — when the granted `version` differs from it (string inequality, not
|
|
102
|
+
* version ordering) the result is `stale` (and not `granted`) so the host
|
|
103
|
+
* re-prompts.
|
|
93
104
|
*/
|
|
94
105
|
check(ctx, subjectRef, purpose, requiredVersion) {
|
|
95
106
|
return ctx.runQuery(this.component.queries.check, {
|
|
@@ -114,8 +125,8 @@ export class Consent {
|
|
|
114
125
|
/**
|
|
115
126
|
* Page the immutable consent ledger for one `(subjectRef, purpose)` pair,
|
|
116
127
|
* newest-first. Returns the standard Convex pagination envelope with each event
|
|
117
|
-
* narrowed to the typed view — the
|
|
118
|
-
* subject request.
|
|
128
|
+
* narrowed to the typed view — the retained proof trail (events already pruned
|
|
129
|
+
* are gone) for an audit or a data subject request.
|
|
119
130
|
*/
|
|
120
131
|
async history(ctx, subjectRef, purpose, paginationOpts) {
|
|
121
132
|
const result = await ctx.runQuery(this.component.queries.history, {
|
|
@@ -126,11 +137,13 @@ export class Consent {
|
|
|
126
137
|
return { ...result, page: result.page.map((raw) => this.event(raw)) };
|
|
127
138
|
}
|
|
128
139
|
/**
|
|
129
|
-
* Delete
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
140
|
+
* Delete ledger events whose `at < before` in bounded batches, oldest first.
|
|
141
|
+
* `before` defaults to the server clock minus the 365-day retention window;
|
|
142
|
+
* `batch` (integer 1–500, default 200) caps each pass and the sweep
|
|
143
|
+
* self-reschedules until the tail is clean. Events are not checked for being
|
|
144
|
+
* superseded, so the proof for a pair's current decision can be deleted too.
|
|
145
|
+
* The current-state projection is never pruned. Returns the count removed in
|
|
146
|
+
* the first pass. The built-in daily cron drives this automatically.
|
|
134
147
|
*/
|
|
135
148
|
prune(ctx, opts = {}) {
|
|
136
149
|
return ctx.runMutation(this.component.mutations.prune, {
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAgBA,OAA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9D,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO,CACX,GAAgB,EAChB,UAAkB,EAClB,OAAe,EACf,cAAiC;QAEjC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE;YAChE,UAAU;YACV,OAAO;YACP,cAAc;SACf,CAAC,CAAC;QACH,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IACxE,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CACH,GAAmB,EACnB,IAAI,GAAwC,EAAE;QAE9C,OAAO,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE;YACrD,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,mBAAmB;SACzC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/client/types.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ export type ConsentDecision = "granted" | "denied" | "withdrawn";
|
|
|
7
7
|
/**
|
|
8
8
|
* Validates and narrows an opaque stored value to a host type `T` at the client
|
|
9
9
|
* boundary. Receives the raw value the component returned (`unknown`) and MUST
|
|
10
|
-
* return a typed `T` or throw. A
|
|
11
|
-
*
|
|
10
|
+
* return a typed `T` or throw. A hand-written parser or a Zod `.parse` fits;
|
|
11
|
+
* `convex/values` validators have no `.parse`. Omit it to keep the value
|
|
12
|
+
* unvalidated.
|
|
12
13
|
*
|
|
13
14
|
* @typeParam T - The host's stored type (the consent `proof`).
|
|
14
15
|
*/
|
|
@@ -45,7 +46,7 @@ export interface ConsentState {
|
|
|
45
46
|
export interface ConsentCheck {
|
|
46
47
|
/** The gate: `true` only when the latest decision is `granted` and the version matches any requirement. */
|
|
47
48
|
granted: boolean;
|
|
48
|
-
/** `true` when a `granted` decision
|
|
49
|
+
/** `true` when a `granted` decision has a `version` different from `requiredVersion` (string inequality, not version ordering) — re-prompt. */
|
|
49
50
|
stale: boolean;
|
|
50
51
|
/** The current decision, or `null` if none was ever recorded. */
|
|
51
52
|
decision: ConsentDecision | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAExD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEjE
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAExD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC;AAE9C,oFAAoF;AACpF,MAAM,WAAW,YAAY,CAAC,MAAM,GAAG,OAAO;IAC5C,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,QAAQ,EAAE,eAAe,CAAC;IAC1B,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,gGAAgG;IAChG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,iEAAiE;AACjE,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,QAAQ,EAAE,eAAe,CAAC;IAC1B,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,qFAAqF;AACrF,MAAM,WAAW,YAAY;IAC3B,2GAA2G;IAC3G,OAAO,EAAE,OAAO,CAAC;IACjB,+IAA+I;IAC/I,KAAK,EAAE,OAAO,CAAC;IACf,iEAAiE;IACjE,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,gEAAgE;IAChE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,2EAA2E;IAC3E,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACnB;AAED,mDAAmD;AACnD,MAAM,WAAW,aAAa,CAAC,MAAM;IACnC,+FAA+F;IAC/F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,2DAA2D;AAC3D,MAAM,WAAW,cAAc,CAAC,MAAM;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;CACjC"}
|
package/dist/component/crons.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cronJobs } from "convex/server";
|
|
2
|
-
import { api } from "./_generated/api";
|
|
2
|
+
import { api } from "./_generated/api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Default sweep cadence and page size for the built-in prune cron. The cron is
|
|
5
5
|
* the component's own self-healing safety net — a host that wants a different
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,KAAK,EAAE,EAAE,EAAW,CAAC;AAErD,uEAAuE;AACvE,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;AAEzB,KAAK,CAAC,QAAQ,CAAC,eAAe,EAAE,cAAc,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE;IACnE,KAAK,EAAE,WAAW;CACnB,CAAC,CAAC;AAEH,eAAe,KAAK,CAAC"}
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* the client boundary); `proof` is opaque host evidence stored verbatim. The
|
|
12
12
|
* ledger row is the legal record — it is never mutated, only swept by retention
|
|
13
13
|
* `prune`.
|
|
14
|
+
*
|
|
15
|
+
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `subjectRef`, `purpose`
|
|
16
|
+
* or `version` is empty.
|
|
14
17
|
*/
|
|
15
18
|
export declare const record: import("convex/server").RegisteredMutation<"public", {
|
|
16
19
|
decision: "denied" | "granted" | "withdrawn";
|
|
@@ -28,6 +31,8 @@ export declare const record: import("convex/server").RegisteredMutation<"public"
|
|
|
28
31
|
* something never granted is a no-op error rather than a silent ledger entry, so
|
|
29
32
|
* the audit trail stays meaningful.
|
|
30
33
|
*
|
|
34
|
+
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `subjectRef` or `purpose`
|
|
35
|
+
* is empty.
|
|
31
36
|
* @throws `ConvexError({ code: "NO_CONSENT" })` when no consent was ever recorded
|
|
32
37
|
* for the pair.
|
|
33
38
|
* @throws `ConvexError({ code: "NOT_GRANTED" })` when the current decision is not
|
|
@@ -41,17 +46,18 @@ export declare const withdraw: import("convex/server").RegisteredMutation<"publi
|
|
|
41
46
|
at: number;
|
|
42
47
|
}>>;
|
|
43
48
|
/**
|
|
44
|
-
* Delete up to `batch`
|
|
45
|
-
*
|
|
46
|
-
* defaults to the server clock
|
|
47
|
-
* sweeps exactly the events
|
|
48
|
-
* may be more, so the sweep self-reschedules
|
|
49
|
-
* batch signals the tail is clean.
|
|
49
|
+
* Delete up to `batch` ledger events whose `at < before`, oldest first via the
|
|
50
|
+
* `by_at` index, and return the count removed in the first pass. `before`
|
|
51
|
+
* defaults to the server clock minus the 365-day retention window when omitted,
|
|
52
|
+
* so the built-in cron sweeps exactly the events past retention as of the run. If
|
|
53
|
+
* a full batch was removed there may be more, so the sweep self-reschedules
|
|
54
|
+
* through `ctx.scheduler` until a short batch signals the tail is clean.
|
|
50
55
|
*
|
|
51
|
-
* Only the
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
56
|
+
* Only the `consentEvents` ledger is pruned — the `consentState` projection is
|
|
57
|
+
* the live gate and is never swept, so a host that prunes old proof still gets
|
|
58
|
+
* the correct current decision. Events are not checked for being superseded, so
|
|
59
|
+
* the proof for a pair's current decision can be deleted too. Idempotent: only
|
|
60
|
+
* ever removes already-past-retention rows.
|
|
55
61
|
*/
|
|
56
62
|
export declare const prune: import("convex/server").RegisteredMutation<"public", {
|
|
57
63
|
batch: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM;;;;;;;;GA6CjB,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ;;;;;;GAwCnB,CAAC;AAEH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK;;;mBA6BhB,CAAC"}
|