@vllnt/convex-consent 0.1.0-canary.799596f

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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -0
  3. package/dist/client/index.d.ts +156 -0
  4. package/dist/client/index.d.ts.map +1 -0
  5. package/dist/client/index.js +142 -0
  6. package/dist/client/index.js.map +1 -0
  7. package/dist/client/types.d.ts +79 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +3 -0
  10. package/dist/client/types.js.map +1 -0
  11. package/dist/component/_generated/api.d.ts +40 -0
  12. package/dist/component/_generated/api.d.ts.map +1 -0
  13. package/dist/component/_generated/api.js +31 -0
  14. package/dist/component/_generated/api.js.map +1 -0
  15. package/dist/component/_generated/component.d.ts +102 -0
  16. package/dist/component/_generated/component.d.ts.map +1 -0
  17. package/dist/component/_generated/component.js +11 -0
  18. package/dist/component/_generated/component.js.map +1 -0
  19. package/dist/component/_generated/dataModel.d.ts +46 -0
  20. package/dist/component/_generated/dataModel.d.ts.map +1 -0
  21. package/dist/component/_generated/dataModel.js +11 -0
  22. package/dist/component/_generated/dataModel.js.map +1 -0
  23. package/dist/component/_generated/server.d.ts +121 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +78 -0
  26. package/dist/component/_generated/server.js.map +1 -0
  27. package/dist/component/convex.config.d.ts +3 -0
  28. package/dist/component/convex.config.d.ts.map +1 -0
  29. package/dist/component/convex.config.js +7 -0
  30. package/dist/component/convex.config.js.map +1 -0
  31. package/dist/component/crons.d.ts +16 -0
  32. package/dist/component/crons.d.ts.map +1 -0
  33. package/dist/component/crons.js +19 -0
  34. package/dist/component/crons.js.map +1 -0
  35. package/dist/component/mutations.d.ts +60 -0
  36. package/dist/component/mutations.d.ts.map +1 -0
  37. package/dist/component/mutations.js +142 -0
  38. package/dist/component/mutations.js.map +1 -0
  39. package/dist/component/queries.d.ts +78 -0
  40. package/dist/component/queries.d.ts.map +1 -0
  41. package/dist/component/queries.js +119 -0
  42. package/dist/component/queries.js.map +1 -0
  43. package/dist/component/schema.d.ts +53 -0
  44. package/dist/component/schema.d.ts.map +1 -0
  45. package/dist/component/schema.js +40 -0
  46. package/dist/component/schema.js.map +1 -0
  47. package/dist/component/validators.d.ts +80 -0
  48. package/dist/component/validators.d.ts.map +1 -0
  49. package/dist/component/validators.js +62 -0
  50. package/dist/component/validators.js.map +1 -0
  51. package/dist/shared.d.ts +30 -0
  52. package/dist/shared.d.ts.map +1 -0
  53. package/dist/shared.js +28 -0
  54. package/dist/shared.js.map +1 -0
  55. package/package.json +98 -0
  56. package/src/client/index.ts +298 -0
  57. package/src/client/types.ts +85 -0
  58. package/src/component/_generated/api.ts +56 -0
  59. package/src/component/_generated/component.ts +127 -0
  60. package/src/component/_generated/dataModel.ts +60 -0
  61. package/src/component/_generated/server.ts +156 -0
  62. package/src/component/convex.config.ts +9 -0
  63. package/src/component/crons.ts +23 -0
  64. package/src/component/mutations.ts +151 -0
  65. package/src/component/queries.ts +142 -0
  66. package/src/component/schema.ts +41 -0
  67. package/src/component/validators.ts +70 -0
  68. package/src/shared.ts +35 -0
  69. package/src/test.ts +15 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,6CAA8C,CAAC;AAE7E,iCAAiC;AACjC,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;;GAKG;AACH,eAAO,MAAM,eAAe,MAAM,CAAC;AAEnC;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,cAAiB,CAAC;AAEnD,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,MAAM,CAAC"}
package/dist/shared.js ADDED
@@ -0,0 +1,28 @@
1
+ /** Shared constants used by both `client/` and `component/`. */
2
+ export const COMPONENT_NAME = "consent";
3
+ /**
4
+ * The consent decisions a subject can hold for a purpose. `granted` and `denied`
5
+ * are explicit answers to the consent prompt; `withdrawn` revokes a prior grant.
6
+ * Every decision is appended to the immutable ledger and projected onto the
7
+ * current-state row.
8
+ */
9
+ export const CONSENT_DECISIONS = ["granted", "denied", "withdrawn"];
10
+ /**
11
+ * The default policy version stamped on a decision when the host supplies none.
12
+ * Consent is always versioned so a later policy change can invalidate a stale
13
+ * grant; `"1"` is the sensible zero-config default for a host that hasn't started
14
+ * versioning its policy yet.
15
+ */
16
+ export const DEFAULT_VERSION = "1";
17
+ /**
18
+ * Default retention (ms) for ledger events before the prune cron sweeps them:
19
+ * 365 days. Consent proof must survive long enough to answer an audit or a data
20
+ * subject request, so the default window is deliberately long. The current-state
21
+ * projection is NEVER pruned — only superseded historical ledger events past the
22
+ * cutoff are removed. A host with a stricter or looser legal window drives
23
+ * `prune` from its own scheduler with an explicit `before` cutoff.
24
+ */
25
+ export const DEFAULT_RETENTION_MS = 31_536_000_000;
26
+ /** Default page size for a `prune` pass before the sweep self-reschedules. */
27
+ export const DEFAULT_PRUNE_BATCH = 200;
28
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAEhE,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAC;AAExC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,CAAU,CAAC;AAK7E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAEnD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC"}
package/package.json ADDED
@@ -0,0 +1,98 @@
1
+ {
2
+ "name": "@vllnt/convex-consent",
3
+ "version": "0.1.0-canary.799596f",
4
+ "description": "Append-only consent ledger (GDPR Art. 6/7) — record, withdraw, and gate consent per subject + purpose as a Convex component",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "packageManager": "pnpm@9.15.4",
8
+ "files": [
9
+ "dist",
10
+ "src"
11
+ ],
12
+ "exports": {
13
+ "./package.json": "./package.json",
14
+ ".": {
15
+ "types": "./dist/client/index.d.ts",
16
+ "default": "./dist/client/index.js"
17
+ },
18
+ "./test": "./src/test.ts",
19
+ "./_generated/component.js": {
20
+ "types": "./dist/component/_generated/component.d.ts"
21
+ },
22
+ "./_generated/component": {
23
+ "types": "./dist/component/_generated/component.d.ts"
24
+ },
25
+ "./convex.config": {
26
+ "types": "./dist/component/convex.config.d.ts",
27
+ "default": "./dist/component/convex.config.js"
28
+ },
29
+ "./convex.config.js": {
30
+ "types": "./dist/component/convex.config.d.ts",
31
+ "default": "./dist/component/convex.config.js"
32
+ }
33
+ },
34
+ "types": "./dist/client/index.d.ts",
35
+ "module": "./dist/client/index.js",
36
+ "scripts": {
37
+ "build": "tsc --project ./tsconfig.build.json",
38
+ "build:codegen": "pnpm convex codegen --component-dir ./src/component && pnpm build",
39
+ "build:clean": "rm -rf dist *.tsbuildinfo && pnpm build:codegen",
40
+ "typecheck": "tsc --noEmit",
41
+ "typecheck:ci": "tsc --noEmit --project tsconfig.ci.json",
42
+ "lint": "eslint .",
43
+ "test": "vitest run --passWithNoTests",
44
+ "test:watch": "vitest --typecheck --clearScreen false",
45
+ "test:coverage": "vitest run --coverage --coverage.reporter=text",
46
+ "generate:llms": "node scripts/generate-llms.mjs",
47
+ "preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck && pnpm generate:llms",
48
+ "prepublishOnly": "npm whoami || npm login",
49
+ "alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
50
+ "release": "npm version patch && npm publish && git push --follow-tags"
51
+ },
52
+ "dependencies": {},
53
+ "peerDependencies": {
54
+ "convex": "^1.41.0"
55
+ },
56
+ "devDependencies": {
57
+ "@edge-runtime/vm": "^5.0.0",
58
+ "@vitest/coverage-v8": "^4.1.8",
59
+ "@vllnt/eslint-config": "^1.0.0",
60
+ "@vllnt/typescript": "^1.0.0",
61
+ "convex": "^1.41.0",
62
+ "convex-test": "^0.0.53",
63
+ "eslint": "^9.0.0",
64
+ "prettier": "^3.4.0",
65
+ "typescript": "^5.7.0",
66
+ "vitest": "^4.1.8"
67
+ },
68
+ "homepage": "https://github.com/vllnt/convex-consent#readme",
69
+ "bugs": {
70
+ "url": "https://github.com/vllnt/convex-consent/issues"
71
+ },
72
+ "author": {
73
+ "name": "bntvllnt",
74
+ "url": "https://bntvllnt.com"
75
+ },
76
+ "funding": {
77
+ "type": "github",
78
+ "url": "https://github.com/sponsors/bntvllnt"
79
+ },
80
+ "repository": {
81
+ "type": "git",
82
+ "url": "https://github.com/vllnt/convex-consent"
83
+ },
84
+ "engines": {
85
+ "node": ">=18"
86
+ },
87
+ "publishConfig": {
88
+ "access": "public"
89
+ },
90
+ "sideEffects": false,
91
+ "keywords": [
92
+ "convex",
93
+ "convex-component",
94
+ "consent",
95
+ "gdpr",
96
+ "privacy"
97
+ ]
98
+ }
@@ -0,0 +1,298 @@
1
+ import type {
2
+ FunctionArgs,
3
+ FunctionReference,
4
+ FunctionReturnType,
5
+ PaginationOptions,
6
+ PaginationResult,
7
+ } from "convex/server";
8
+ import type {
9
+ ConsentCheck,
10
+ ConsentDecision,
11
+ ConsentEvent,
12
+ ConsentOptions,
13
+ ConsentState,
14
+ Parser,
15
+ RecordOptions,
16
+ } from "./types.js";
17
+ import { DEFAULT_PRUNE_BATCH, DEFAULT_VERSION } from "../shared.js";
18
+
19
+ /**
20
+ * The component's raw ledger event, before the client narrows opaque host proof.
21
+ * `proof` is `unknown` here; the {@link Consent} client runs the host validator
22
+ * over it at its typed boundary.
23
+ */
24
+ type RawEvent = {
25
+ subjectRef: string;
26
+ purpose: string;
27
+ decision: ConsentDecision;
28
+ version: string;
29
+ proof?: unknown;
30
+ at: number;
31
+ };
32
+
33
+ /**
34
+ * The consent component's function references, as exposed on the host via
35
+ * `components.consent`. The host's stored `proof` is opaque here (`unknown`); the
36
+ * {@link Consent} client narrows it at its own typed boundary.
37
+ */
38
+ export interface ConsentComponent {
39
+ mutations: {
40
+ record: FunctionReference<
41
+ "mutation",
42
+ "internal",
43
+ {
44
+ subjectRef: string;
45
+ purpose: string;
46
+ decision: ConsentDecision;
47
+ version: string;
48
+ proof?: unknown;
49
+ },
50
+ { at: number }
51
+ >;
52
+ withdraw: FunctionReference<
53
+ "mutation",
54
+ "internal",
55
+ { subjectRef: string; purpose: string; proof?: unknown },
56
+ { at: number }
57
+ >;
58
+ prune: FunctionReference<
59
+ "mutation",
60
+ "internal",
61
+ { before?: number; batch: number },
62
+ number
63
+ >;
64
+ };
65
+ queries: {
66
+ check: FunctionReference<
67
+ "query",
68
+ "internal",
69
+ { subjectRef: string; purpose: string; requiredVersion?: string },
70
+ ConsentCheck
71
+ >;
72
+ getState: FunctionReference<
73
+ "query",
74
+ "internal",
75
+ { subjectRef: string; purpose: string },
76
+ ConsentState | null
77
+ >;
78
+ getStatesForSubject: FunctionReference<
79
+ "query",
80
+ "internal",
81
+ { subjectRef: string },
82
+ ConsentState[]
83
+ >;
84
+ history: FunctionReference<
85
+ "query",
86
+ "internal",
87
+ { subjectRef: string; purpose: string; paginationOpts: PaginationOptions },
88
+ PaginationResult<RawEvent>
89
+ >;
90
+ };
91
+ }
92
+
93
+ interface RunQueryCtx {
94
+ runQuery<Q extends FunctionReference<"query", "internal">>(
95
+ reference: Q,
96
+ args: FunctionArgs<Q>,
97
+ ): Promise<FunctionReturnType<Q>>;
98
+ }
99
+
100
+ interface RunMutationCtx {
101
+ runMutation<M extends FunctionReference<"mutation", "internal">>(
102
+ reference: M,
103
+ args: FunctionArgs<M>,
104
+ ): Promise<FunctionReturnType<M>>;
105
+ }
106
+
107
+ /**
108
+ * Consumer-facing client for the consent ledger (GDPR Art. 6/7). The host records
109
+ * a subject's decision for a purpose with `record` (or revokes one with
110
+ * `withdraw`) — each call appends an immutable ledger event (the legal proof) and
111
+ * updates the O(1) current-state projection. Before processing, the host calls
112
+ * `check` to gate: "may I process `<purpose>` for `<subject>`?". `subjectRef` and
113
+ * `purpose` are opaque host strings; the host owns meaning and auth. Pass
114
+ * `proofValidator` to narrow the opaque stored `proof` to `TProof` at the
115
+ * boundary — there is no unchecked cast.
116
+ *
117
+ * @typeParam TProof - The host's consent-proof type (defaults to `unknown`).
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * const consent = new Consent(components.consent, {
122
+ * defaultVersion: "2024-policy",
123
+ * proofValidator: v.object({ policyHash: v.string() }).parse,
124
+ * });
125
+ * await consent.record(ctx, "user_42", "analytics", "granted", {
126
+ * proof: { policyHash },
127
+ * });
128
+ * const gate = await consent.check(ctx, "user_42", "analytics", "2024-policy");
129
+ * if (gate.granted) {
130
+ * // process the personal data
131
+ * }
132
+ * ```
133
+ */
134
+ export class Consent<TProof = unknown> {
135
+ private readonly defaultVersion: string;
136
+ private readonly proofValidator: Parser<TProof> | undefined;
137
+
138
+ constructor(
139
+ private readonly component: ConsentComponent,
140
+ options: ConsentOptions<TProof> = {},
141
+ ) {
142
+ this.defaultVersion = options.defaultVersion ?? DEFAULT_VERSION;
143
+ this.proofValidator = options.proofValidator;
144
+ }
145
+
146
+ /** Narrow an opaque value through the host proof parser; pass `undefined` and an unset parser through. */
147
+ private parseProof(value: unknown): TProof | undefined {
148
+ if (value === undefined) {
149
+ return undefined;
150
+ }
151
+ if (this.proofValidator === undefined) {
152
+ return value as TProof;
153
+ }
154
+ return this.proofValidator(value);
155
+ }
156
+
157
+ /** Project a raw component event into the typed, validated client event. */
158
+ private event(raw: RawEvent): ConsentEvent<TProof> {
159
+ return {
160
+ subjectRef: raw.subjectRef,
161
+ purpose: raw.purpose,
162
+ decision: raw.decision,
163
+ version: raw.version,
164
+ proof: this.parseProof(raw.proof),
165
+ at: raw.at,
166
+ };
167
+ }
168
+
169
+ /**
170
+ * Record a consent decision for `(subjectRef, purpose)`. Appends an immutable
171
+ * ledger event and updates the current-state projection. `opts.version` defaults
172
+ * to the client's `defaultVersion`; `opts.proof` is opaque host evidence
173
+ * validated against `proofValidator` before storage. Returns the server
174
+ * timestamp stamped on the event.
175
+ */
176
+ record(
177
+ ctx: RunMutationCtx,
178
+ subjectRef: string,
179
+ purpose: string,
180
+ decision: ConsentDecision,
181
+ opts: RecordOptions<TProof> = {},
182
+ ): Promise<{ at: number }> {
183
+ return ctx.runMutation(this.component.mutations.record, {
184
+ subjectRef,
185
+ purpose,
186
+ decision,
187
+ version: opts.version ?? this.defaultVersion,
188
+ proof: opts.proof === undefined ? undefined : this.parseProof(opts.proof),
189
+ });
190
+ }
191
+
192
+ /**
193
+ * Withdraw a previously-granted consent (GDPR Art. 7(3)). Appends a `withdrawn`
194
+ * event and updates the projection, but only when the subject currently holds a
195
+ * `granted` decision — the component throws a coded `ConvexError` (`NO_CONSENT`
196
+ * / `NOT_GRANTED`) otherwise so the audit trail stays meaningful.
197
+ */
198
+ withdraw(
199
+ ctx: RunMutationCtx,
200
+ subjectRef: string,
201
+ purpose: string,
202
+ proof?: TProof,
203
+ ): Promise<{ at: number }> {
204
+ return ctx.runMutation(this.component.mutations.withdraw, {
205
+ subjectRef,
206
+ purpose,
207
+ proof: proof === undefined ? undefined : this.parseProof(proof),
208
+ });
209
+ }
210
+
211
+ /**
212
+ * The runtime gate: may the host process `purpose` for `subjectRef`? Pass
213
+ * `requiredVersion` to also require the consent be for the current policy
214
+ * version — when the subject granted an older version the result is `stale`
215
+ * (and not `granted`) so the host re-prompts.
216
+ */
217
+ check(
218
+ ctx: RunQueryCtx,
219
+ subjectRef: string,
220
+ purpose: string,
221
+ requiredVersion?: string,
222
+ ): Promise<ConsentCheck> {
223
+ return ctx.runQuery(this.component.queries.check, {
224
+ subjectRef,
225
+ purpose,
226
+ requiredVersion,
227
+ });
228
+ }
229
+
230
+ /** The raw current decision for one `(subjectRef, purpose)` pair, or `null`. */
231
+ getState(
232
+ ctx: RunQueryCtx,
233
+ subjectRef: string,
234
+ purpose: string,
235
+ ): Promise<ConsentState | null> {
236
+ return ctx.runQuery(this.component.queries.getState, {
237
+ subjectRef,
238
+ purpose,
239
+ });
240
+ }
241
+
242
+ /** Every current decision held by one subject, across all purposes. */
243
+ getStatesForSubject(
244
+ ctx: RunQueryCtx,
245
+ subjectRef: string,
246
+ ): Promise<ConsentState[]> {
247
+ return ctx.runQuery(this.component.queries.getStatesForSubject, {
248
+ subjectRef,
249
+ });
250
+ }
251
+
252
+ /**
253
+ * Page the immutable consent ledger for one `(subjectRef, purpose)` pair,
254
+ * newest-first. Returns the standard Convex pagination envelope with each event
255
+ * narrowed to the typed view — the full proof trail for an audit or a data
256
+ * subject request.
257
+ */
258
+ async history(
259
+ ctx: RunQueryCtx,
260
+ subjectRef: string,
261
+ purpose: string,
262
+ paginationOpts: PaginationOptions,
263
+ ): Promise<PaginationResult<ConsentEvent<TProof>>> {
264
+ const result = await ctx.runQuery(this.component.queries.history, {
265
+ subjectRef,
266
+ purpose,
267
+ paginationOpts,
268
+ });
269
+ return { ...result, page: result.page.map((raw) => this.event(raw)) };
270
+ }
271
+
272
+ /**
273
+ * Delete superseded ledger events whose `at < before` in bounded batches,
274
+ * oldest first. `before` defaults to the server clock; `batch` caps each pass
275
+ * and the sweep self-reschedules until the tail is clean. The current-state
276
+ * projection is never pruned. Returns the count removed in the first pass. The
277
+ * built-in daily cron drives this automatically.
278
+ */
279
+ prune(
280
+ ctx: RunMutationCtx,
281
+ opts: { before?: number; batch?: number } = {},
282
+ ): Promise<number> {
283
+ return ctx.runMutation(this.component.mutations.prune, {
284
+ before: opts.before,
285
+ batch: opts.batch ?? DEFAULT_PRUNE_BATCH,
286
+ });
287
+ }
288
+ }
289
+
290
+ export type {
291
+ ConsentCheck,
292
+ ConsentDecision,
293
+ ConsentEvent,
294
+ ConsentOptions,
295
+ ConsentState,
296
+ Parser,
297
+ RecordOptions,
298
+ };
@@ -0,0 +1,85 @@
1
+ /** Public TypeScript surface for the consent client. */
2
+
3
+ /**
4
+ * The three consent decisions a subject can hold for a purpose. `granted` and
5
+ * `denied` are explicit answers to the prompt; `withdrawn` revokes a prior grant.
6
+ */
7
+ export type ConsentDecision = "granted" | "denied" | "withdrawn";
8
+
9
+ /**
10
+ * Validates and narrows an opaque stored value to a host type `T` at the client
11
+ * boundary. Receives the raw value the component returned (`unknown`) and MUST
12
+ * return a typed `T` or throw. A `convex/values` validator's `.parse` (or a Zod
13
+ * `.parse`) fits directly; omit it to keep the value unvalidated.
14
+ *
15
+ * @typeParam T - The host's stored type (the consent `proof`).
16
+ */
17
+ export type Parser<T> = (value: unknown) => T;
18
+
19
+ /** One immutable row in the consent ledger — a recorded decision plus its proof. */
20
+ export interface ConsentEvent<TProof = unknown> {
21
+ /** The opaque host-supplied subject identifier. */
22
+ subjectRef: string;
23
+ /** The opaque host-supplied purpose key. */
24
+ purpose: string;
25
+ /** The recorded decision. */
26
+ decision: ConsentDecision;
27
+ /** The policy version the subject consented to. */
28
+ version: string;
29
+ /** The opaque host proof recorded with the decision (narrowed if a `proofValidator` is set). */
30
+ proof?: TProof;
31
+ /** Absolute ms timestamp the decision was recorded (server clock). */
32
+ at: number;
33
+ }
34
+
35
+ /** The current decision for one `(subjectRef, purpose)` pair. */
36
+ export interface ConsentState {
37
+ /** The opaque host-supplied subject identifier. */
38
+ subjectRef: string;
39
+ /** The opaque host-supplied purpose key. */
40
+ purpose: string;
41
+ /** The latest decision. */
42
+ decision: ConsentDecision;
43
+ /** The policy version of the latest decision. */
44
+ version: string;
45
+ /** Absolute ms timestamp of the latest decision (server clock). */
46
+ at: number;
47
+ }
48
+
49
+ /** The answer to "may I process `purpose` for `subjectRef`?" returned by `check`. */
50
+ export interface ConsentCheck {
51
+ /** The gate: `true` only when the latest decision is `granted` and the version matches any requirement. */
52
+ granted: boolean;
53
+ /** `true` when a `granted` decision is for an older version than the one now required — re-prompt. */
54
+ stale: boolean;
55
+ /** The current decision, or `null` if none was ever recorded. */
56
+ decision: ConsentDecision | null;
57
+ /** The current version, or `null` if none was ever recorded. */
58
+ version: string | null;
59
+ /** The current decision timestamp, or `null` if none was ever recorded. */
60
+ at: number | null;
61
+ }
62
+
63
+ /** Per-call options for {@link Consent.record}. */
64
+ export interface RecordOptions<TProof> {
65
+ /** The policy version the subject consented to (defaults to the client's `defaultVersion`). */
66
+ version?: string;
67
+ /** The opaque host proof to store (validated against `proofValidator`). */
68
+ proof?: TProof;
69
+ }
70
+
71
+ /** Construction options for the {@link Consent} client. */
72
+ export interface ConsentOptions<TProof> {
73
+ /**
74
+ * The policy version stamped on a decision when `record` is called without an
75
+ * explicit `version`. Lets a host bump its policy version in one place. Defaults
76
+ * to `"1"`.
77
+ */
78
+ defaultVersion?: string;
79
+ /**
80
+ * Validates/narrows a stored `proof` to `TProof` at the boundary — applied to
81
+ * the `proof` passed into `record`/`withdraw` (before storage) and the `proof`
82
+ * returned by `history`. Throws on a mismatch. Omit to leave proof unvalidated.
83
+ */
84
+ proofValidator?: Parser<TProof>;
85
+ }
@@ -0,0 +1,56 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type * as crons from "../crons.js";
12
+ import type * as mutations from "../mutations.js";
13
+ import type * as queries from "../queries.js";
14
+ import type * as validators from "../validators.js";
15
+
16
+ import type {
17
+ ApiFromModules,
18
+ FilterApi,
19
+ FunctionReference,
20
+ } from "convex/server";
21
+ import { anyApi, componentsGeneric } from "convex/server";
22
+
23
+ const fullApi: ApiFromModules<{
24
+ crons: typeof crons;
25
+ mutations: typeof mutations;
26
+ queries: typeof queries;
27
+ validators: typeof validators;
28
+ }> = anyApi as any;
29
+
30
+ /**
31
+ * A utility for referencing Convex functions in your app's public API.
32
+ *
33
+ * Usage:
34
+ * ```js
35
+ * const myFunctionReference = api.myModule.myFunction;
36
+ * ```
37
+ */
38
+ export const api: FilterApi<
39
+ typeof fullApi,
40
+ FunctionReference<any, "public">
41
+ > = anyApi as any;
42
+
43
+ /**
44
+ * A utility for referencing Convex functions in your app's internal API.
45
+ *
46
+ * Usage:
47
+ * ```js
48
+ * const myFunctionReference = internal.myModule.myFunction;
49
+ * ```
50
+ */
51
+ export const internal: FilterApi<
52
+ typeof fullApi,
53
+ FunctionReference<any, "internal">
54
+ > = anyApi as any;
55
+
56
+ export const components = componentsGeneric() as unknown as {};
@@ -0,0 +1,127 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `ComponentApi` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type { FunctionReference } from "convex/server";
12
+
13
+ /**
14
+ * A utility for referencing a Convex component's exposed API.
15
+ *
16
+ * Useful when expecting a parameter like `components.myComponent`.
17
+ * Usage:
18
+ * ```ts
19
+ * async function myFunction(ctx: QueryCtx, component: ComponentApi) {
20
+ * return ctx.runQuery(component.someFile.someQuery, { ...args });
21
+ * }
22
+ * ```
23
+ */
24
+ export type ComponentApi<Name extends string | undefined = string | undefined> =
25
+ {
26
+ mutations: {
27
+ record: FunctionReference<
28
+ "mutation",
29
+ "internal",
30
+ {
31
+ decision: "granted" | "denied" | "withdrawn";
32
+ proof?: any;
33
+ purpose: string;
34
+ subjectRef: string;
35
+ version: string;
36
+ },
37
+ { at: number },
38
+ Name
39
+ >;
40
+ withdraw: FunctionReference<
41
+ "mutation",
42
+ "internal",
43
+ { proof?: any; purpose: string; subjectRef: string },
44
+ { at: number },
45
+ Name
46
+ >;
47
+ prune: FunctionReference<
48
+ "mutation",
49
+ "internal",
50
+ { batch: number; before?: number },
51
+ number,
52
+ Name
53
+ >;
54
+ };
55
+ queries: {
56
+ check: FunctionReference<
57
+ "query",
58
+ "internal",
59
+ { purpose: string; requiredVersion?: string; subjectRef: string },
60
+ {
61
+ at: number | null;
62
+ decision: "granted" | "denied" | "withdrawn" | null;
63
+ granted: boolean;
64
+ stale: boolean;
65
+ version: string | null;
66
+ },
67
+ Name
68
+ >;
69
+ getState: FunctionReference<
70
+ "query",
71
+ "internal",
72
+ { purpose: string; subjectRef: string },
73
+ null | {
74
+ at: number;
75
+ decision: "granted" | "denied" | "withdrawn";
76
+ purpose: string;
77
+ subjectRef: string;
78
+ version: string;
79
+ },
80
+ Name
81
+ >;
82
+ getStatesForSubject: FunctionReference<
83
+ "query",
84
+ "internal",
85
+ { subjectRef: string },
86
+ Array<{
87
+ at: number;
88
+ decision: "granted" | "denied" | "withdrawn";
89
+ purpose: string;
90
+ subjectRef: string;
91
+ version: string;
92
+ }>,
93
+ Name
94
+ >;
95
+ history: FunctionReference<
96
+ "query",
97
+ "internal",
98
+ {
99
+ paginationOpts: {
100
+ cursor: string | null;
101
+ endCursor?: string | null;
102
+ id?: number;
103
+ maximumBytesRead?: number;
104
+ maximumRowsRead?: number;
105
+ numItems: number;
106
+ };
107
+ purpose: string;
108
+ subjectRef: string;
109
+ },
110
+ {
111
+ continueCursor: string;
112
+ isDone: boolean;
113
+ page: Array<{
114
+ at: number;
115
+ decision: "granted" | "denied" | "withdrawn";
116
+ proof?: any;
117
+ purpose: string;
118
+ subjectRef: string;
119
+ version: string;
120
+ }>;
121
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
122
+ splitCursor?: string | null;
123
+ },
124
+ Name
125
+ >;
126
+ };
127
+ };