@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.
- package/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/client/index.d.ts +156 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +142 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +79 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +3 -0
- package/dist/client/types.js.map +1 -0
- package/dist/component/_generated/api.d.ts +40 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +102 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +46 -0
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +7 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/crons.d.ts +16 -0
- package/dist/component/crons.d.ts.map +1 -0
- package/dist/component/crons.js +19 -0
- package/dist/component/crons.js.map +1 -0
- package/dist/component/mutations.d.ts +60 -0
- package/dist/component/mutations.d.ts.map +1 -0
- package/dist/component/mutations.js +142 -0
- package/dist/component/mutations.js.map +1 -0
- package/dist/component/queries.d.ts +78 -0
- package/dist/component/queries.d.ts.map +1 -0
- package/dist/component/queries.js +119 -0
- package/dist/component/queries.js.map +1 -0
- package/dist/component/schema.d.ts +53 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +40 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/component/validators.d.ts +80 -0
- package/dist/component/validators.d.ts.map +1 -0
- package/dist/component/validators.js +62 -0
- package/dist/component/validators.js.map +1 -0
- package/dist/shared.d.ts +30 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +28 -0
- package/dist/shared.js.map +1 -0
- package/package.json +98 -0
- package/src/client/index.ts +298 -0
- package/src/client/types.ts +85 -0
- package/src/component/_generated/api.ts +56 -0
- package/src/component/_generated/component.ts +127 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +156 -0
- package/src/component/convex.config.ts +9 -0
- package/src/component/crons.ts +23 -0
- package/src/component/mutations.ts +151 -0
- package/src/component/queries.ts +142 -0
- package/src/component/schema.ts +41 -0
- package/src/component/validators.ts +70 -0
- package/src/shared.ts +35 -0
- package/src/test.ts +15 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { ConvexError, v } from "convex/values";
|
|
2
|
+
import { api } from "./_generated/api";
|
|
3
|
+
import { mutation } from "./_generated/server";
|
|
4
|
+
import { consentDecision, jsonValue } from "./validators";
|
|
5
|
+
/**
|
|
6
|
+
* Record a consent decision for a `(subjectRef, purpose)` pair. Appends one
|
|
7
|
+
* immutable row to the `consentEvents` ledger — the GDPR proof — and overwrites
|
|
8
|
+
* the `consentState` projection so the next {@link check}/{@link getState} reads
|
|
9
|
+
* the new decision. `at` is stamped from the server clock (`Date.now()` inside
|
|
10
|
+
* the handler — never caller-supplied), so the ledger order cannot be skewed by a
|
|
11
|
+
* client clock.
|
|
12
|
+
*
|
|
13
|
+
* `subjectRef` and `purpose` are opaque host strings; `version` is the policy
|
|
14
|
+
* version the subject consented to (defaults to the host's `defaultVersion` at
|
|
15
|
+
* the client boundary); `proof` is opaque host evidence stored verbatim. The
|
|
16
|
+
* ledger row is the legal record — it is never mutated, only swept by retention
|
|
17
|
+
* `prune`.
|
|
18
|
+
*/
|
|
19
|
+
export const record = mutation({
|
|
20
|
+
args: {
|
|
21
|
+
subjectRef: v.string(),
|
|
22
|
+
purpose: v.string(),
|
|
23
|
+
decision: consentDecision,
|
|
24
|
+
version: v.string(),
|
|
25
|
+
proof: v.optional(jsonValue),
|
|
26
|
+
},
|
|
27
|
+
returns: v.object({ at: v.number() }),
|
|
28
|
+
handler: async (ctx, args) => {
|
|
29
|
+
const at = Date.now();
|
|
30
|
+
await ctx.db.insert("consentEvents", {
|
|
31
|
+
subjectRef: args.subjectRef,
|
|
32
|
+
purpose: args.purpose,
|
|
33
|
+
decision: args.decision,
|
|
34
|
+
version: args.version,
|
|
35
|
+
proof: args.proof,
|
|
36
|
+
at,
|
|
37
|
+
});
|
|
38
|
+
const existing = await ctx.db
|
|
39
|
+
.query("consentState")
|
|
40
|
+
.withIndex("by_subject_purpose", (q) => q.eq("subjectRef", args.subjectRef).eq("purpose", args.purpose))
|
|
41
|
+
.unique();
|
|
42
|
+
const projection = {
|
|
43
|
+
subjectRef: args.subjectRef,
|
|
44
|
+
purpose: args.purpose,
|
|
45
|
+
decision: args.decision,
|
|
46
|
+
version: args.version,
|
|
47
|
+
at,
|
|
48
|
+
};
|
|
49
|
+
if (existing === null) {
|
|
50
|
+
await ctx.db.insert("consentState", projection);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await ctx.db.patch(existing._id, projection);
|
|
54
|
+
}
|
|
55
|
+
return { at };
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
/**
|
|
59
|
+
* Withdraw a previously-granted consent — the GDPR Art. 7(3) "as easy to withdraw
|
|
60
|
+
* as to give" path. Appends a `withdrawn` event and projects it, but ONLY when the
|
|
61
|
+
* subject currently holds a `granted` decision for the purpose; withdrawing
|
|
62
|
+
* something never granted is a no-op error rather than a silent ledger entry, so
|
|
63
|
+
* the audit trail stays meaningful.
|
|
64
|
+
*
|
|
65
|
+
* @throws `ConvexError({ code: "NO_CONSENT" })` when no consent was ever recorded
|
|
66
|
+
* for the pair.
|
|
67
|
+
* @throws `ConvexError({ code: "NOT_GRANTED" })` when the current decision is not
|
|
68
|
+
* `granted` (already `denied`/`withdrawn`) — there is nothing to withdraw.
|
|
69
|
+
*/
|
|
70
|
+
export const withdraw = mutation({
|
|
71
|
+
args: {
|
|
72
|
+
subjectRef: v.string(),
|
|
73
|
+
purpose: v.string(),
|
|
74
|
+
proof: v.optional(jsonValue),
|
|
75
|
+
},
|
|
76
|
+
returns: v.object({ at: v.number() }),
|
|
77
|
+
handler: async (ctx, args) => {
|
|
78
|
+
const state = await ctx.db
|
|
79
|
+
.query("consentState")
|
|
80
|
+
.withIndex("by_subject_purpose", (q) => q.eq("subjectRef", args.subjectRef).eq("purpose", args.purpose))
|
|
81
|
+
.unique();
|
|
82
|
+
if (state === null) {
|
|
83
|
+
throw new ConvexError({
|
|
84
|
+
code: "NO_CONSENT",
|
|
85
|
+
message: `no consent recorded for "${args.subjectRef}" / "${args.purpose}"`,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (state.decision !== "granted") {
|
|
89
|
+
throw new ConvexError({
|
|
90
|
+
code: "NOT_GRANTED",
|
|
91
|
+
message: `consent for "${args.subjectRef}" / "${args.purpose}" is "${state.decision}", not "granted" — nothing to withdraw`,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
const at = Date.now();
|
|
95
|
+
await ctx.db.insert("consentEvents", {
|
|
96
|
+
subjectRef: args.subjectRef,
|
|
97
|
+
purpose: args.purpose,
|
|
98
|
+
decision: "withdrawn",
|
|
99
|
+
version: state.version,
|
|
100
|
+
proof: args.proof,
|
|
101
|
+
at,
|
|
102
|
+
});
|
|
103
|
+
await ctx.db.patch(state._id, { decision: "withdrawn", at });
|
|
104
|
+
return { at };
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* Delete up to `batch` superseded ledger events whose `at < before`, oldest first
|
|
109
|
+
* via the `by_at` index, and return the count removed in the first pass. `before`
|
|
110
|
+
* defaults to the server clock (`Date.now()`) when omitted, so the built-in cron
|
|
111
|
+
* sweeps exactly the events stale as of the run. If a full batch was removed there
|
|
112
|
+
* may be more, so the sweep self-reschedules through `ctx.scheduler` until a short
|
|
113
|
+
* batch signals the tail is clean.
|
|
114
|
+
*
|
|
115
|
+
* Only the historical `consentEvents` ledger is pruned — the `consentState`
|
|
116
|
+
* projection is the live gate and is never swept, so a host that prunes old proof
|
|
117
|
+
* still gets the correct current decision. Idempotent: only ever removes
|
|
118
|
+
* already-past-retention rows.
|
|
119
|
+
*/
|
|
120
|
+
export const prune = mutation({
|
|
121
|
+
args: { before: v.optional(v.number()), batch: v.number() },
|
|
122
|
+
returns: v.number(),
|
|
123
|
+
handler: async (ctx, args) => {
|
|
124
|
+
const before = args.before ?? Date.now();
|
|
125
|
+
const stale = await ctx.db
|
|
126
|
+
.query("consentEvents")
|
|
127
|
+
.withIndex("by_at", (q) => q.lt("at", before))
|
|
128
|
+
.take(args.batch);
|
|
129
|
+
for (const row of stale) {
|
|
130
|
+
await ctx.db.delete(row._id);
|
|
131
|
+
}
|
|
132
|
+
const removed = stale.length;
|
|
133
|
+
if (removed === args.batch) {
|
|
134
|
+
await ctx.scheduler.runAfter(0, api.mutations.prune, {
|
|
135
|
+
before,
|
|
136
|
+
batch: args.batch,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return removed;
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
//# 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,eAA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,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,GAAG,CAAC,GAAG,CAAC,CAAC;QAC/B,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
|
+
requiredVersion?: string | undefined;
|
|
11
|
+
subjectRef: string;
|
|
12
|
+
purpose: 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: "granted" | "denied" | "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
|
+
subjectRef: string;
|
|
29
|
+
purpose: string;
|
|
30
|
+
}, Promise<{
|
|
31
|
+
subjectRef: string;
|
|
32
|
+
purpose: string;
|
|
33
|
+
decision: "granted" | "denied" | "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: "granted" | "denied" | "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
|
+
subjectRef: string;
|
|
55
|
+
purpose: string;
|
|
56
|
+
paginationOpts: {
|
|
57
|
+
id?: number;
|
|
58
|
+
endCursor?: string | null;
|
|
59
|
+
maximumRowsRead?: number;
|
|
60
|
+
maximumBytesRead?: number;
|
|
61
|
+
numItems: number;
|
|
62
|
+
cursor: string | null;
|
|
63
|
+
};
|
|
64
|
+
}, Promise<{
|
|
65
|
+
page: {
|
|
66
|
+
subjectRef: string;
|
|
67
|
+
purpose: string;
|
|
68
|
+
decision: "granted" | "denied" | "withdrawn";
|
|
69
|
+
version: string;
|
|
70
|
+
proof: any;
|
|
71
|
+
at: number;
|
|
72
|
+
}[];
|
|
73
|
+
isDone: boolean;
|
|
74
|
+
continueCursor: import("convex/server").Cursor;
|
|
75
|
+
splitCursor?: import("convex/server").Cursor | null;
|
|
76
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
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;KAC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IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;IACzD,CAAC;CACF,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
|
+
proof?: any;
|
|
19
|
+
subjectRef: string;
|
|
20
|
+
purpose: string;
|
|
21
|
+
decision: "granted" | "denied" | "withdrawn";
|
|
22
|
+
version: string;
|
|
23
|
+
at: number;
|
|
24
|
+
}, {
|
|
25
|
+
subjectRef: import("convex/values").VString<string, "required">;
|
|
26
|
+
purpose: import("convex/values").VString<string, "required">;
|
|
27
|
+
decision: import("convex/values").VUnion<"granted" | "denied" | "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", "subjectRef" | "purpose" | "decision" | "version" | "proof" | "at" | `proof.${string}`>, {
|
|
32
|
+
by_subject_purpose_at: ["subjectRef", "purpose", "at", "_creationTime"];
|
|
33
|
+
by_at: ["at", "_creationTime"];
|
|
34
|
+
}, {}, {}>;
|
|
35
|
+
consentState: import("convex/server").TableDefinition<import("convex/values").VObject<{
|
|
36
|
+
subjectRef: string;
|
|
37
|
+
purpose: string;
|
|
38
|
+
decision: "granted" | "denied" | "withdrawn";
|
|
39
|
+
version: string;
|
|
40
|
+
at: number;
|
|
41
|
+
}, {
|
|
42
|
+
subjectRef: import("convex/values").VString<string, "required">;
|
|
43
|
+
purpose: import("convex/values").VString<string, "required">;
|
|
44
|
+
decision: import("convex/values").VUnion<"granted" | "denied" | "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", "subjectRef" | "purpose" | "decision" | "version" | "at">, {
|
|
48
|
+
by_subject_purpose: ["subjectRef", "purpose", "_creationTime"];
|
|
49
|
+
by_subject: ["subjectRef", "_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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACH,wBAqBG"}
|
|
@@ -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<"granted" | "denied" | "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
|
+
proof?: any;
|
|
28
|
+
subjectRef: string;
|
|
29
|
+
purpose: string;
|
|
30
|
+
decision: "granted" | "denied" | "withdrawn";
|
|
31
|
+
version: string;
|
|
32
|
+
at: number;
|
|
33
|
+
}, {
|
|
34
|
+
subjectRef: import("convex/values").VString<string, "required">;
|
|
35
|
+
purpose: import("convex/values").VString<string, "required">;
|
|
36
|
+
decision: import("convex/values").VUnion<"granted" | "denied" | "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", "subjectRef" | "purpose" | "decision" | "version" | "proof" | "at" | `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
|
+
subjectRef: string;
|
|
48
|
+
purpose: string;
|
|
49
|
+
decision: "granted" | "denied" | "withdrawn";
|
|
50
|
+
version: string;
|
|
51
|
+
at: number;
|
|
52
|
+
}, {
|
|
53
|
+
subjectRef: import("convex/values").VString<string, "required">;
|
|
54
|
+
purpose: import("convex/values").VString<string, "required">;
|
|
55
|
+
decision: import("convex/values").VUnion<"granted" | "denied" | "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", "subjectRef" | "purpose" | "decision" | "version" | "at">;
|
|
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
|
+
granted: boolean;
|
|
69
|
+
decision: "granted" | "denied" | "withdrawn" | null;
|
|
70
|
+
version: string | null;
|
|
71
|
+
at: number | null;
|
|
72
|
+
stale: boolean;
|
|
73
|
+
}, {
|
|
74
|
+
granted: import("convex/values").VBoolean<boolean, "required">;
|
|
75
|
+
stale: import("convex/values").VBoolean<boolean, "required">;
|
|
76
|
+
decision: import("convex/values").VUnion<"granted" | "denied" | "withdrawn" | null, [import("convex/values").VUnion<"granted" | "denied" | "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", "granted" | "decision" | "version" | "at" | "stale">;
|
|
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":"","sources":["../../src/component/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAElC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CACpC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,EACpB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EACnB,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CACvB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,QAAQ,EAAE,eAAe;IACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;IAC5B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;IACtB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,QAAQ,EAAE,eAAe;IACzB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE;IACpB,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE;IAClB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5C,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACtC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;CAClC,CAAC,CAAC"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Shared constants used by both `client/` and `component/`. */
|
|
2
|
+
export declare 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 declare const CONSENT_DECISIONS: readonly ["granted", "denied", "withdrawn"];
|
|
10
|
+
/** A single consent decision. */
|
|
11
|
+
export type ConsentDecision = (typeof CONSENT_DECISIONS)[number];
|
|
12
|
+
/**
|
|
13
|
+
* The default policy version stamped on a decision when the host supplies none.
|
|
14
|
+
* Consent is always versioned so a later policy change can invalidate a stale
|
|
15
|
+
* grant; `"1"` is the sensible zero-config default for a host that hasn't started
|
|
16
|
+
* versioning its policy yet.
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_VERSION = "1";
|
|
19
|
+
/**
|
|
20
|
+
* Default retention (ms) for ledger events before the prune cron sweeps them:
|
|
21
|
+
* 365 days. Consent proof must survive long enough to answer an audit or a data
|
|
22
|
+
* subject request, so the default window is deliberately long. The current-state
|
|
23
|
+
* projection is NEVER pruned — only superseded historical ledger events past the
|
|
24
|
+
* cutoff are removed. A host with a stricter or looser legal window drives
|
|
25
|
+
* `prune` from its own scheduler with an explicit `before` cutoff.
|
|
26
|
+
*/
|
|
27
|
+
export declare const DEFAULT_RETENTION_MS = 31536000000;
|
|
28
|
+
/** Default page size for a `prune` pass before the sweep self-reschedules. */
|
|
29
|
+
export declare const DEFAULT_PRUNE_BATCH = 200;
|
|
30
|
+
//# sourceMappingURL=shared.d.ts.map
|