@vllnt/convex-consent 0.1.0-canary.591da41

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 +133 -0
  24. package/dist/component/_generated/server.d.ts.map +1 -0
  25. package/dist/component/_generated/server.js +80 -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 +149 -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 +31 -0
  52. package/dist/shared.d.ts.map +1 -0
  53. package/dist/shared.js +29 -0
  54. package/dist/shared.js.map +1 -0
  55. package/package.json +101 -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 +169 -0
  62. package/src/component/convex.config.ts +9 -0
  63. package/src/component/crons.ts +23 -0
  64. package/src/component/mutations.ts +158 -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 +36 -0
  69. package/src/test.ts +15 -0
@@ -0,0 +1,149 @@
1
+ import { ConvexError, v } from "convex/values";
2
+ import { api } from "./_generated/api";
3
+ import { mutation } from "./_generated/server";
4
+ import { DEFAULT_RETENTION_MS, MAX_PRUNE_BATCH } from "../shared";
5
+ import { consentDecision, jsonValue } from "./validators";
6
+ /**
7
+ * Record a consent decision for a `(subjectRef, purpose)` pair. Appends one
8
+ * immutable row to the `consentEvents` ledger — the GDPR proof — and overwrites
9
+ * the `consentState` projection so the next {@link check}/{@link getState} reads
10
+ * the new decision. `at` is stamped from the server clock (`Date.now()` inside
11
+ * the handler — never caller-supplied), so the ledger order cannot be skewed by a
12
+ * client clock.
13
+ *
14
+ * `subjectRef` and `purpose` are opaque host strings; `version` is the policy
15
+ * version the subject consented to (defaults to the host's `defaultVersion` at
16
+ * the client boundary); `proof` is opaque host evidence stored verbatim. The
17
+ * ledger row is the legal record — it is never mutated, only swept by retention
18
+ * `prune`.
19
+ */
20
+ export const record = mutation({
21
+ args: {
22
+ subjectRef: v.string(),
23
+ purpose: v.string(),
24
+ decision: consentDecision,
25
+ version: v.string(),
26
+ proof: v.optional(jsonValue),
27
+ },
28
+ returns: v.object({ at: v.number() }),
29
+ handler: async (ctx, args) => {
30
+ const at = Date.now();
31
+ await ctx.db.insert("consentEvents", {
32
+ subjectRef: args.subjectRef,
33
+ purpose: args.purpose,
34
+ decision: args.decision,
35
+ version: args.version,
36
+ proof: args.proof,
37
+ at,
38
+ });
39
+ const existing = await ctx.db
40
+ .query("consentState")
41
+ .withIndex("by_subject_purpose", (q) => q.eq("subjectRef", args.subjectRef).eq("purpose", args.purpose))
42
+ .unique();
43
+ const projection = {
44
+ subjectRef: args.subjectRef,
45
+ purpose: args.purpose,
46
+ decision: args.decision,
47
+ version: args.version,
48
+ at,
49
+ };
50
+ if (existing === null) {
51
+ await ctx.db.insert("consentState", projection);
52
+ }
53
+ else {
54
+ await ctx.db.patch("consentState", existing._id, projection);
55
+ }
56
+ return { at };
57
+ },
58
+ });
59
+ /**
60
+ * Withdraw a previously-granted consent — the GDPR Art. 7(3) "as easy to withdraw
61
+ * as to give" path. Appends a `withdrawn` event and projects it, but ONLY when the
62
+ * subject currently holds a `granted` decision for the purpose; withdrawing
63
+ * something never granted is a no-op error rather than a silent ledger entry, so
64
+ * the audit trail stays meaningful.
65
+ *
66
+ * @throws `ConvexError({ code: "NO_CONSENT" })` when no consent was ever recorded
67
+ * for the pair.
68
+ * @throws `ConvexError({ code: "NOT_GRANTED" })` when the current decision is not
69
+ * `granted` (already `denied`/`withdrawn`) — there is nothing to withdraw.
70
+ */
71
+ export const withdraw = mutation({
72
+ args: {
73
+ subjectRef: v.string(),
74
+ purpose: v.string(),
75
+ proof: v.optional(jsonValue),
76
+ },
77
+ returns: v.object({ at: v.number() }),
78
+ handler: async (ctx, args) => {
79
+ const state = await ctx.db
80
+ .query("consentState")
81
+ .withIndex("by_subject_purpose", (q) => q.eq("subjectRef", args.subjectRef).eq("purpose", args.purpose))
82
+ .unique();
83
+ if (state === null) {
84
+ throw new ConvexError({
85
+ code: "NO_CONSENT",
86
+ message: `no consent recorded for "${args.subjectRef}" / "${args.purpose}"`,
87
+ });
88
+ }
89
+ if (state.decision !== "granted") {
90
+ throw new ConvexError({
91
+ code: "NOT_GRANTED",
92
+ message: `consent for "${args.subjectRef}" / "${args.purpose}" is "${state.decision}", not "granted" — nothing to withdraw`,
93
+ });
94
+ }
95
+ const at = Date.now();
96
+ await ctx.db.insert("consentEvents", {
97
+ subjectRef: args.subjectRef,
98
+ purpose: args.purpose,
99
+ decision: "withdrawn",
100
+ version: state.version,
101
+ proof: args.proof,
102
+ at,
103
+ });
104
+ await ctx.db.patch("consentState", state._id, { decision: "withdrawn", at });
105
+ return { at };
106
+ },
107
+ });
108
+ /**
109
+ * Delete up to `batch` superseded ledger events whose `at < before`, oldest first
110
+ * via the `by_at` index, and return the count removed in the first pass. `before`
111
+ * defaults to the server clock (`Date.now()`) when omitted, so the built-in cron
112
+ * sweeps exactly the events stale as of the run. If a full batch was removed there
113
+ * may be more, so the sweep self-reschedules through `ctx.scheduler` until a short
114
+ * batch signals the tail is clean.
115
+ *
116
+ * Only the historical `consentEvents` ledger is pruned — the `consentState`
117
+ * projection is the live gate and is never swept, so a host that prunes old proof
118
+ * still gets the correct current decision. Idempotent: only ever removes
119
+ * already-past-retention rows.
120
+ */
121
+ export const prune = mutation({
122
+ args: { before: v.optional(v.number()), batch: v.number() },
123
+ returns: v.number(),
124
+ handler: async (ctx, args) => {
125
+ if (!Number.isFinite(args.batch) || !Number.isInteger(args.batch) || args.batch < 1 || args.batch > MAX_PRUNE_BATCH) {
126
+ throw new ConvexError({ code: "INVALID_BATCH", message: `batch must be an integer between 1 and ${MAX_PRUNE_BATCH}` });
127
+ }
128
+ if (args.before !== undefined && !Number.isFinite(args.before)) {
129
+ throw new ConvexError({ code: "INVALID_BEFORE", message: "before must be finite" });
130
+ }
131
+ const before = args.before ?? Date.now() - DEFAULT_RETENTION_MS;
132
+ const stale = await ctx.db
133
+ .query("consentEvents")
134
+ .withIndex("by_at", (q) => q.lt("at", before))
135
+ .take(args.batch);
136
+ for (const row of stale) {
137
+ await ctx.db.delete("consentEvents", row._id);
138
+ }
139
+ const removed = stale.length;
140
+ if (removed === args.batch) {
141
+ await ctx.scheduler.runAfter(0, api.mutations.prune, {
142
+ before,
143
+ batch: args.batch,
144
+ });
145
+ }
146
+ return removed;
147
+ },
148
+ });
149
+ //# sourceMappingURL=mutations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;IAC7B,IAAI,EAAE;QACJ,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;KAC7B;IACD,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACrC,OAAO,EAAE,K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CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,oBAAoB,CAAC;QAChE,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE;aACvB,KAAK,CAAC,eAAe,CAAC;aACtB,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;aAC7C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEpB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;YACxB,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,eAAe,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAChD,CAAC;QACD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC;QAE7B,IAAI,OAAO,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3B,MAAM,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE;gBACnD,MAAM;gBACN,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * The runtime gate: may the host process `purpose` for `subjectRef`? Reads the
3
+ * O(1) current-state projection. `granted` is `true` only when the latest
4
+ * decision is `granted` AND — if a `requiredVersion` is supplied — the consented
5
+ * `version` matches it. When the subject granted an older version than required,
6
+ * `stale` is `true` (and `granted` is `false`) so the host re-prompts. With no
7
+ * recorded consent every field is `null`/`false`.
8
+ */
9
+ export declare const check: import("convex/server").RegisteredQuery<"public", {
10
+ purpose: string;
11
+ requiredVersion?: string | undefined;
12
+ subjectRef: string;
13
+ }, Promise<{
14
+ granted: boolean;
15
+ stale: boolean;
16
+ decision: null;
17
+ version: null;
18
+ at: null;
19
+ } | {
20
+ granted: boolean;
21
+ stale: boolean;
22
+ decision: "denied" | "granted" | "withdrawn";
23
+ version: string;
24
+ at: number;
25
+ }>>;
26
+ /** The raw current decision for one `(subjectRef, purpose)` pair, or `null`. */
27
+ export declare const getState: import("convex/server").RegisteredQuery<"public", {
28
+ purpose: string;
29
+ subjectRef: string;
30
+ }, Promise<{
31
+ subjectRef: string;
32
+ purpose: string;
33
+ decision: "denied" | "granted" | "withdrawn";
34
+ version: string;
35
+ at: number;
36
+ } | null>>;
37
+ /** Every current decision held by one subject, across all purposes. */
38
+ export declare const getStatesForSubject: import("convex/server").RegisteredQuery<"public", {
39
+ subjectRef: string;
40
+ }, Promise<{
41
+ subjectRef: string;
42
+ purpose: string;
43
+ decision: "denied" | "granted" | "withdrawn";
44
+ version: string;
45
+ at: number;
46
+ }[]>>;
47
+ /**
48
+ * Page the immutable consent ledger for one `(subjectRef, purpose)` pair,
49
+ * newest-first via the `by_subject_purpose_at` index. Takes the standard Convex
50
+ * `paginationOpts` and returns the standard paginated envelope (`page`, `isDone`,
51
+ * `continueCursor`) — the full proof trail for an audit or a data subject request.
52
+ */
53
+ export declare const history: import("convex/server").RegisteredQuery<"public", {
54
+ paginationOpts: {
55
+ id?: number;
56
+ endCursor?: string | null;
57
+ maximumRowsRead?: number;
58
+ maximumBytesRead?: number;
59
+ numItems: number;
60
+ cursor: string | null;
61
+ };
62
+ purpose: string;
63
+ subjectRef: string;
64
+ }, Promise<{
65
+ isDone: boolean;
66
+ continueCursor: import("convex/server").Cursor;
67
+ splitCursor?: import("convex/server").Cursor | null;
68
+ pageStatus?: "SplitRecommended" | "SplitRequired" | null;
69
+ page: {
70
+ subjectRef: string;
71
+ purpose: string;
72
+ decision: "denied" | "granted" | "withdrawn";
73
+ version: string;
74
+ proof: any;
75
+ at: number;
76
+ }[];
77
+ }>>;
78
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAiCA;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;GAmChB,CAAC;AAEH,gFAAgF;AAChF,eAAO,MAAM,QAAQ;;;;;;;;;UAYnB,CAAC;AAEH,uEAAuE;AACvE,eAAO,MAAM,mBAAmB;;;;;;;;KAU9B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;GA6BlB,CAAC"}
@@ -0,0 +1,119 @@
1
+ import { v } from "convex/values";
2
+ import { paginationOptsValidator } from "convex/server";
3
+ import { query } from "./_generated/server";
4
+ import { consentCheckView, consentEventView, consentStateView, } from "./validators";
5
+ /** Project a stored ledger row to its public event view (drops internal fields). */
6
+ function eventView(e) {
7
+ return {
8
+ subjectRef: e.subjectRef,
9
+ purpose: e.purpose,
10
+ decision: e.decision,
11
+ version: e.version,
12
+ proof: e.proof,
13
+ at: e.at,
14
+ };
15
+ }
16
+ /** Project a stored projection row to its public state view. */
17
+ function stateView(s) {
18
+ return {
19
+ subjectRef: s.subjectRef,
20
+ purpose: s.purpose,
21
+ decision: s.decision,
22
+ version: s.version,
23
+ at: s.at,
24
+ };
25
+ }
26
+ /**
27
+ * The runtime gate: may the host process `purpose` for `subjectRef`? Reads the
28
+ * O(1) current-state projection. `granted` is `true` only when the latest
29
+ * decision is `granted` AND — if a `requiredVersion` is supplied — the consented
30
+ * `version` matches it. When the subject granted an older version than required,
31
+ * `stale` is `true` (and `granted` is `false`) so the host re-prompts. With no
32
+ * recorded consent every field is `null`/`false`.
33
+ */
34
+ export const check = query({
35
+ args: {
36
+ subjectRef: v.string(),
37
+ purpose: v.string(),
38
+ requiredVersion: v.optional(v.string()),
39
+ },
40
+ returns: consentCheckView,
41
+ handler: async (ctx, args) => {
42
+ const state = await ctx.db
43
+ .query("consentState")
44
+ .withIndex("by_subject_purpose", (q) => q.eq("subjectRef", args.subjectRef).eq("purpose", args.purpose))
45
+ .unique();
46
+ if (state === null) {
47
+ return {
48
+ granted: false,
49
+ stale: false,
50
+ decision: null,
51
+ version: null,
52
+ at: null,
53
+ };
54
+ }
55
+ const versionMatches = args.requiredVersion === undefined ||
56
+ state.version === args.requiredVersion;
57
+ const isGranted = state.decision === "granted";
58
+ return {
59
+ granted: isGranted && versionMatches,
60
+ stale: isGranted && !versionMatches,
61
+ decision: state.decision,
62
+ version: state.version,
63
+ at: state.at,
64
+ };
65
+ },
66
+ });
67
+ /** The raw current decision for one `(subjectRef, purpose)` pair, or `null`. */
68
+ export const getState = query({
69
+ args: { subjectRef: v.string(), purpose: v.string() },
70
+ returns: v.union(v.null(), consentStateView),
71
+ handler: async (ctx, args) => {
72
+ const state = await ctx.db
73
+ .query("consentState")
74
+ .withIndex("by_subject_purpose", (q) => q.eq("subjectRef", args.subjectRef).eq("purpose", args.purpose))
75
+ .unique();
76
+ return state === null ? null : stateView(state);
77
+ },
78
+ });
79
+ /** Every current decision held by one subject, across all purposes. */
80
+ export const getStatesForSubject = query({
81
+ args: { subjectRef: v.string() },
82
+ returns: v.array(consentStateView),
83
+ handler: async (ctx, args) => {
84
+ const states = await ctx.db
85
+ .query("consentState")
86
+ .withIndex("by_subject", (q) => q.eq("subjectRef", args.subjectRef))
87
+ .collect();
88
+ return states.map(stateView);
89
+ },
90
+ });
91
+ /**
92
+ * Page the immutable consent ledger for one `(subjectRef, purpose)` pair,
93
+ * newest-first via the `by_subject_purpose_at` index. Takes the standard Convex
94
+ * `paginationOpts` and returns the standard paginated envelope (`page`, `isDone`,
95
+ * `continueCursor`) — the full proof trail for an audit or a data subject request.
96
+ */
97
+ export const history = query({
98
+ args: {
99
+ subjectRef: v.string(),
100
+ purpose: v.string(),
101
+ paginationOpts: paginationOptsValidator,
102
+ },
103
+ returns: v.object({
104
+ page: v.array(consentEventView),
105
+ isDone: v.boolean(),
106
+ continueCursor: v.string(),
107
+ splitCursor: v.optional(v.union(v.string(), v.null())),
108
+ pageStatus: v.optional(v.union(v.literal("SplitRecommended"), v.literal("SplitRequired"), v.null())),
109
+ }),
110
+ handler: async (ctx, args) => {
111
+ const result = await ctx.db
112
+ .query("consentEvents")
113
+ .withIndex("by_subject_purpose_at", (q) => q.eq("subjectRef", args.subjectRef).eq("purpose", args.purpose))
114
+ .order("desc")
115
+ .paginate(args.paginationOpts);
116
+ return { ...result, page: result.page.map(eventView) };
117
+ },
118
+ });
119
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAGtB,oFAAoF;AACpF,SAAS,SAAS,CAAC,CAAuB;IACxC,OAAO;QACL,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,EAAE,EAAE,CAAC,CAAC,EAAE;KACT,CAAC;AACJ,CAAC;AAED,gEAAgE;AAChE,SAAS,SAAS,CAAC,CAAsB;IACvC,OAAO;QACL,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,EAAE,EAAE,CAAC,CAAC,EAAE;KACT,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC;IACz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CAAC,CAAC"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Two sandboxed tables — the consent ledger's own concern.
3
+ *
4
+ * `consentEvents` is the **append-only** legal record (GDPR Art. 7(1) proof): a
5
+ * row is inserted on every grant/deny/withdraw and is NEVER mutated, only ever
6
+ * deleted by the retention prune. `subjectRef` and `purpose` are opaque host
7
+ * strings; `proof` is opaque host evidence (policy hash, IP, UA). The
8
+ * `by_subject_purpose_at` index reads one pair's history newest-first; the
9
+ * `by_at` index drives the oldest-first retention sweep.
10
+ *
11
+ * `consentState` is the derived **current-decision projection** — exactly one
12
+ * row per `(subjectRef, purpose)`, overwritten on each new event. It is the O(1)
13
+ * runtime gate the host queries before processing; `by_subject_purpose` resolves
14
+ * a single pair, `by_subject` lists every purpose for one subject.
15
+ */
16
+ declare const _default: import("convex/server").SchemaDefinition<{
17
+ consentEvents: import("convex/server").TableDefinition<import("convex/values").VObject<{
18
+ at: number;
19
+ decision: "denied" | "granted" | "withdrawn";
20
+ proof?: any;
21
+ purpose: string;
22
+ subjectRef: string;
23
+ version: string;
24
+ }, {
25
+ subjectRef: import("convex/values").VString<string, "required">;
26
+ purpose: import("convex/values").VString<string, "required">;
27
+ decision: import("convex/values").VUnion<"denied" | "granted" | "withdrawn", [import("convex/values").VLiteral<"granted", "required">, import("convex/values").VLiteral<"denied", "required">, import("convex/values").VLiteral<"withdrawn", "required">], "required", never>;
28
+ version: import("convex/values").VString<string, "required">;
29
+ proof: import("convex/values").VAny<any, "optional", string>;
30
+ at: import("convex/values").VFloat64<number, "required">;
31
+ }, "required", "at" | "decision" | "proof" | "purpose" | "subjectRef" | "version" | `proof.${string}`>, {
32
+ by_at: ["at", "_creationTime"];
33
+ by_subject_purpose_at: ["subjectRef", "purpose", "at", "_creationTime"];
34
+ }, {}, {}>;
35
+ consentState: import("convex/server").TableDefinition<import("convex/values").VObject<{
36
+ at: number;
37
+ decision: "denied" | "granted" | "withdrawn";
38
+ purpose: string;
39
+ subjectRef: string;
40
+ version: string;
41
+ }, {
42
+ subjectRef: import("convex/values").VString<string, "required">;
43
+ purpose: import("convex/values").VString<string, "required">;
44
+ decision: import("convex/values").VUnion<"denied" | "granted" | "withdrawn", [import("convex/values").VLiteral<"granted", "required">, import("convex/values").VLiteral<"denied", "required">, import("convex/values").VLiteral<"withdrawn", "required">], "required", never>;
45
+ version: import("convex/values").VString<string, "required">;
46
+ at: import("convex/values").VFloat64<number, "required">;
47
+ }, "required", "at" | "decision" | "purpose" | "subjectRef" | "version">, {
48
+ by_subject: ["subjectRef", "_creationTime"];
49
+ by_subject_purpose: ["subjectRef", "purpose", "_creationTime"];
50
+ }, {}, {}>;
51
+ }, true>;
52
+ export default _default;
53
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG"}
@@ -0,0 +1,40 @@
1
+ import { defineSchema, defineTable } from "convex/server";
2
+ import { v } from "convex/values";
3
+ import { consentDecision, jsonValue } from "./validators";
4
+ /**
5
+ * Two sandboxed tables — the consent ledger's own concern.
6
+ *
7
+ * `consentEvents` is the **append-only** legal record (GDPR Art. 7(1) proof): a
8
+ * row is inserted on every grant/deny/withdraw and is NEVER mutated, only ever
9
+ * deleted by the retention prune. `subjectRef` and `purpose` are opaque host
10
+ * strings; `proof` is opaque host evidence (policy hash, IP, UA). The
11
+ * `by_subject_purpose_at` index reads one pair's history newest-first; the
12
+ * `by_at` index drives the oldest-first retention sweep.
13
+ *
14
+ * `consentState` is the derived **current-decision projection** — exactly one
15
+ * row per `(subjectRef, purpose)`, overwritten on each new event. It is the O(1)
16
+ * runtime gate the host queries before processing; `by_subject_purpose` resolves
17
+ * a single pair, `by_subject` lists every purpose for one subject.
18
+ */
19
+ export default defineSchema({
20
+ consentEvents: defineTable({
21
+ subjectRef: v.string(),
22
+ purpose: v.string(),
23
+ decision: consentDecision,
24
+ version: v.string(),
25
+ proof: v.optional(jsonValue),
26
+ at: v.number(),
27
+ })
28
+ .index("by_subject_purpose_at", ["subjectRef", "purpose", "at"])
29
+ .index("by_at", ["at"]),
30
+ consentState: defineTable({
31
+ subjectRef: v.string(),
32
+ purpose: v.string(),
33
+ decision: consentDecision,
34
+ version: v.string(),
35
+ at: v.number(),
36
+ })
37
+ .index("by_subject_purpose", ["subjectRef", "purpose"])
38
+ .index("by_subject", ["subjectRef"]),
39
+ });
40
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D;;;;;;;;;;;;;;GAcG;AACH,eAAe,YAAY,CAAC;IAC1B,aAAa,EAAE,WAAW,CAAC;QACzB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;QAC5B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;KACf,CAAC;SACC,KAAK,CAAC,uBAAuB,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;SAC/D,KAAK,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IAEzB,YAAY,EAAE,WAAW,CAAC;QACxB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;QACnB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;KACf,CAAC;SACC,KAAK,CAAC,oBAAoB,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;SACtD,KAAK,CAAC,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC;CACvC,CAAC,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Opaque host-owned proof recorded alongside a consent decision — the evidence
3
+ * that the subject made the choice (a policy hash, an IP, a user agent, a signed
4
+ * token). The component never inspects it; it is last-resort arbitrary data,
5
+ * aliased here rather than left bare in function signatures. The host narrows it
6
+ * at the {@link Consent} client boundary via an optional `proofValidator` parser.
7
+ *
8
+ * This is the single documented `v.any()` escape hatch in the component; the lint
9
+ * rule `convex-rules/no-bare-v-any` is satisfied by routing every arbitrary host
10
+ * proof through this alias instead of a bare `v.any()`.
11
+ */
12
+ export declare const jsonValue: import("convex/values").VAny<any, "required", string>;
13
+ /**
14
+ * The three consent decisions a subject can hold for a purpose. `granted` and
15
+ * `denied` are explicit answers to the consent prompt; `withdrawn` revokes a
16
+ * prior grant. Every decision is appended to the immutable ledger — the GDPR
17
+ * proof — and projected onto the current-state row.
18
+ */
19
+ export declare const consentDecision: import("convex/values").VUnion<"denied" | "granted" | "withdrawn", [import("convex/values").VLiteral<"granted", "required">, import("convex/values").VLiteral<"denied", "required">, import("convex/values").VLiteral<"withdrawn", "required">], "required", never>;
20
+ /**
21
+ * One immutable row in the consent ledger. `subjectRef` and `purpose` are opaque
22
+ * host strings; `decision` is the recorded answer; `version` is the policy
23
+ * version the subject consented to; `proof` is the opaque host evidence; `at` is
24
+ * the server timestamp. The ledger is append-only — a row is never mutated.
25
+ */
26
+ export declare const consentEventView: import("convex/values").VObject<{
27
+ at: number;
28
+ decision: "denied" | "granted" | "withdrawn";
29
+ proof?: any;
30
+ purpose: string;
31
+ subjectRef: string;
32
+ version: string;
33
+ }, {
34
+ subjectRef: import("convex/values").VString<string, "required">;
35
+ purpose: import("convex/values").VString<string, "required">;
36
+ decision: import("convex/values").VUnion<"denied" | "granted" | "withdrawn", [import("convex/values").VLiteral<"granted", "required">, import("convex/values").VLiteral<"denied", "required">, import("convex/values").VLiteral<"withdrawn", "required">], "required", never>;
37
+ version: import("convex/values").VString<string, "required">;
38
+ proof: import("convex/values").VAny<any, "optional", string>;
39
+ at: import("convex/values").VFloat64<number, "required">;
40
+ }, "required", "at" | "decision" | "proof" | "purpose" | "subjectRef" | "version" | `proof.${string}`>;
41
+ /**
42
+ * The current decision for one `(subjectRef, purpose)` pair — the O(1) runtime
43
+ * gate, projected from the latest ledger event. `null` is returned by
44
+ * {@link check}/{@link getState} when no event was ever recorded.
45
+ */
46
+ export declare const consentStateView: import("convex/values").VObject<{
47
+ at: number;
48
+ decision: "denied" | "granted" | "withdrawn";
49
+ purpose: string;
50
+ subjectRef: string;
51
+ version: string;
52
+ }, {
53
+ subjectRef: import("convex/values").VString<string, "required">;
54
+ purpose: import("convex/values").VString<string, "required">;
55
+ decision: import("convex/values").VUnion<"denied" | "granted" | "withdrawn", [import("convex/values").VLiteral<"granted", "required">, import("convex/values").VLiteral<"denied", "required">, import("convex/values").VLiteral<"withdrawn", "required">], "required", never>;
56
+ version: import("convex/values").VString<string, "required">;
57
+ at: import("convex/values").VFloat64<number, "required">;
58
+ }, "required", "at" | "decision" | "purpose" | "subjectRef" | "version">;
59
+ /**
60
+ * The answer to "may I process `<purpose>` for `<subject>`?". `granted` is the
61
+ * gate: `true` only when the latest decision is `granted` AND its `version`
62
+ * matches the host-supplied `requiredVersion` (or no version was required).
63
+ * `stale` is `true` when the subject granted an older policy version than the one
64
+ * now required — the host re-prompts. `decision`/`version`/`at` mirror the
65
+ * current state (all `null` when no event was ever recorded).
66
+ */
67
+ export declare const consentCheckView: import("convex/values").VObject<{
68
+ at: number | null;
69
+ decision: "denied" | "granted" | "withdrawn" | null;
70
+ granted: boolean;
71
+ stale: boolean;
72
+ version: string | null;
73
+ }, {
74
+ granted: import("convex/values").VBoolean<boolean, "required">;
75
+ stale: import("convex/values").VBoolean<boolean, "required">;
76
+ decision: import("convex/values").VUnion<"denied" | "granted" | "withdrawn" | null, [import("convex/values").VUnion<"denied" | "granted" | "withdrawn", [import("convex/values").VLiteral<"granted", "required">, import("convex/values").VLiteral<"denied", "required">, import("convex/values").VLiteral<"withdrawn", "required">], "required", never>, import("convex/values").VNull<null, "required">], "required", never>;
77
+ version: import("convex/values").VUnion<string | null, [import("convex/values").VString<string, "required">, import("convex/values").VNull<null, "required">], "required", never>;
78
+ at: import("convex/values").VUnion<number | null, [import("convex/values").VFloat64<number, "required">, import("convex/values").VNull<null, "required">], "required", never>;
79
+ }, "required", "at" | "decision" | "granted" | "stale" | "version">;
80
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,uDAAU,CAAC;AAEjC;;;;;GAKG;AACH,eAAO,MAAM,eAAe,qQAI3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;sGAO3B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;wEAM3B,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;mEAM3B,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { v } from "convex/values";
2
+ /**
3
+ * Opaque host-owned proof recorded alongside a consent decision — the evidence
4
+ * that the subject made the choice (a policy hash, an IP, a user agent, a signed
5
+ * token). The component never inspects it; it is last-resort arbitrary data,
6
+ * aliased here rather than left bare in function signatures. The host narrows it
7
+ * at the {@link Consent} client boundary via an optional `proofValidator` parser.
8
+ *
9
+ * This is the single documented `v.any()` escape hatch in the component; the lint
10
+ * rule `convex-rules/no-bare-v-any` is satisfied by routing every arbitrary host
11
+ * proof through this alias instead of a bare `v.any()`.
12
+ */
13
+ export const jsonValue = v.any();
14
+ /**
15
+ * The three consent decisions a subject can hold for a purpose. `granted` and
16
+ * `denied` are explicit answers to the consent prompt; `withdrawn` revokes a
17
+ * prior grant. Every decision is appended to the immutable ledger — the GDPR
18
+ * proof — and projected onto the current-state row.
19
+ */
20
+ export const consentDecision = v.union(v.literal("granted"), v.literal("denied"), v.literal("withdrawn"));
21
+ /**
22
+ * One immutable row in the consent ledger. `subjectRef` and `purpose` are opaque
23
+ * host strings; `decision` is the recorded answer; `version` is the policy
24
+ * version the subject consented to; `proof` is the opaque host evidence; `at` is
25
+ * the server timestamp. The ledger is append-only — a row is never mutated.
26
+ */
27
+ export const consentEventView = v.object({
28
+ subjectRef: v.string(),
29
+ purpose: v.string(),
30
+ decision: consentDecision,
31
+ version: v.string(),
32
+ proof: v.optional(jsonValue),
33
+ at: v.number(),
34
+ });
35
+ /**
36
+ * The current decision for one `(subjectRef, purpose)` pair — the O(1) runtime
37
+ * gate, projected from the latest ledger event. `null` is returned by
38
+ * {@link check}/{@link getState} when no event was ever recorded.
39
+ */
40
+ export const consentStateView = v.object({
41
+ subjectRef: v.string(),
42
+ purpose: v.string(),
43
+ decision: consentDecision,
44
+ version: v.string(),
45
+ at: v.number(),
46
+ });
47
+ /**
48
+ * The answer to "may I process `<purpose>` for `<subject>`?". `granted` is the
49
+ * gate: `true` only when the latest decision is `granted` AND its `version`
50
+ * matches the host-supplied `requiredVersion` (or no version was required).
51
+ * `stale` is `true` when the subject granted an older policy version than the one
52
+ * now required — the host re-prompts. `decision`/`version`/`at` mirror the
53
+ * current state (all `null` when no event was ever recorded).
54
+ */
55
+ export const consentCheckView = v.object({
56
+ granted: v.boolean(),
57
+ stale: v.boolean(),
58
+ decision: v.union(consentDecision, v.null()),
59
+ version: v.union(v.string(), v.null()),
60
+ at: v.union(v.number(), v.null()),
61
+ });
62
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot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