@consent-kit/server 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ -- consent-kit: consent receipts, the proof of each decision a visitor makes in the banner.
2
+ -- Apply with `wrangler d1 migrations apply <DATABASE>`; @consent-kit/server writes rows here.
3
+ --
4
+ -- One row per receipt. A row holds no personal data beyond subject_hash, which is
5
+ -- HMAC-SHA-256(key, consentId) in lowercase hex: the consentId itself, the IP address, the user
6
+ -- agent, the request headers, the URL and the raw body are never stored.
7
+ --
8
+ -- Append-only: rows are inserted and never changed (the trigger below refuses every UPDATE).
9
+ -- Deleting is reserved for retention (old rows, by received_at) and for erasure requests (one
10
+ -- subject, by subject_hash); each has an index.
11
+ CREATE TABLE consent_receipts (
12
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
13
+ -- HMAC-SHA-256 of the browser's consentId with the server's key, lowercase hex.
14
+ subject_hash TEXT NOT NULL CHECK (length(subject_hash) = 64 AND subject_hash NOT GLOB '*[^0-9a-f]*'),
15
+ -- 'first': the visitor's first decision; 'change': a later one (including a withdrawal).
16
+ event TEXT NOT NULL CHECK (event IN ('first', 'change')),
17
+ -- JSON arrays of {"purpose": id, "version": n}, sorted by purpose. Together they hold every
18
+ -- consent purpose of the policy exactly once.
19
+ accepted TEXT NOT NULL CHECK (json_valid(accepted) AND json_type(accepted) = 'array'),
20
+ rejected TEXT NOT NULL CHECK (json_valid(rejected) AND json_type(rejected) = 'array'),
21
+ -- The policy the visitor decided on: policySnapshot(registry).hash, lowercase hex SHA-256.
22
+ policy_hash TEXT NOT NULL CHECK (length(policy_hash) = 64 AND policy_hash NOT GLOB '*[^0-9a-f]*'),
23
+ -- CookieConsent's revision of that policy.
24
+ revision INTEGER NOT NULL CHECK (revision >= 0),
25
+ -- When the browser says the decision was made: ISO 8601 UTC from the visitor's clock. A claim.
26
+ client_timestamp TEXT NOT NULL,
27
+ -- When the server received it: ISO 8601 UTC from the server's clock. The time of record.
28
+ received_at TEXT NOT NULL
29
+ ) STRICT;
30
+
31
+ CREATE INDEX consent_receipts_subject_hash ON consent_receipts (subject_hash);
32
+ CREATE INDEX consent_receipts_received_at ON consent_receipts (received_at);
33
+
34
+ CREATE TRIGGER consent_receipts_append_only
35
+ BEFORE UPDATE ON consent_receipts
36
+ BEGIN
37
+ SELECT RAISE(ABORT, 'consent_receipts is append-only');
38
+ END;
@@ -0,0 +1,91 @@
1
+ -- consent-kit: data subject requests (access, Art. 15, and erasure, Art. 17 GDPR) received
2
+ -- through the site's request form. Apply with `wrangler d1 migrations apply <DATABASE>`;
3
+ -- @consent-kit/server writes rows here.
4
+ --
5
+ -- One row per request. It holds what is needed to answer and to show that the request was
6
+ -- answered: the type, the requester's email address (in plain text, to reply to), its keyed
7
+ -- hash, the keyed hash of the browser's consent id (the same hash consent_receipts.subject_hash
8
+ -- holds, so the two join), the details the requester gave, and the dates. No IP address, user
9
+ -- agent or request header is stored.
10
+ --
11
+ -- The content of a request is fixed once inserted; only its progress may change (confirmation,
12
+ -- notification, extension, closing), and a closed request not at all. Both are enforced by the
13
+ -- triggers below. Rows are deleted only by retention: closed requests, by closed_at.
14
+ CREATE TABLE subject_requests (
15
+ -- 128 random bits, lowercase hex.
16
+ id TEXT PRIMARY KEY CHECK (length(id) = 32 AND id NOT GLOB '*[^0-9a-f]*'),
17
+ type TEXT NOT NULL CHECK (type IN ('access', 'erasure')),
18
+ email TEXT NOT NULL CHECK (length(email) BETWEEN 3 AND 254 AND instr(email, '@') > 1),
19
+ -- HMAC-SHA-256 of the lowercased email address, with the receipts' key, lowercase hex.
20
+ email_hash TEXT NOT NULL CHECK (length(email_hash) = 64 AND email_hash NOT GLOB '*[^0-9a-f]*'),
21
+ -- HMAC-SHA-256 of the consentId in the browser's consent cookie, or NULL when it sent none.
22
+ subject_hash TEXT CHECK (subject_hash IS NULL OR (length(subject_hash) = 64 AND subject_hash NOT GLOB '*[^0-9a-f]*')),
23
+ details TEXT CHECK (details IS NULL OR length(details) <= 2000),
24
+ locale TEXT NOT NULL CHECK (length(locale) BETWEEN 2 AND 35),
25
+ -- policySnapshot(registry).hash of the build that received the request.
26
+ policy_hash TEXT NOT NULL CHECK (length(policy_hash) = 64 AND policy_hash NOT GLOB '*[^0-9a-f]*'),
27
+ -- ISO 8601 UTC from the server's clock.
28
+ received_at TEXT NOT NULL,
29
+ -- One calendar month after received_at (Art. 12(3) GDPR).
30
+ due_at TEXT NOT NULL,
31
+ -- Up to two further months, with the reason the requester was given.
32
+ extended_due_at TEXT,
33
+ extension_reason TEXT,
34
+ status TEXT NOT NULL CHECK (status IN ('received', 'confirmed', 'closed')),
35
+ confirmed_at TEXT,
36
+ closed_at TEXT,
37
+ outcome TEXT,
38
+ -- When the email to the controller's mailbox went out; NULL while it has not.
39
+ notified_at TEXT,
40
+ -- When the confirmation email of this request went out, if it did.
41
+ confirmation_sent_at TEXT,
42
+ CHECK ((extended_due_at IS NULL) = (extension_reason IS NULL)),
43
+ CHECK ((status = 'closed') = (closed_at IS NOT NULL)),
44
+ CHECK (status <> 'closed' OR outcome IS NOT NULL)
45
+ ) STRICT;
46
+
47
+ CREATE INDEX subject_requests_open ON subject_requests (status, due_at);
48
+ CREATE INDEX subject_requests_email_hash ON subject_requests (email_hash);
49
+ CREATE INDEX subject_requests_closed_at ON subject_requests (closed_at);
50
+
51
+ CREATE TRIGGER subject_requests_content_fixed
52
+ BEFORE UPDATE ON subject_requests
53
+ WHEN NEW.id IS NOT OLD.id
54
+ OR NEW.type IS NOT OLD.type
55
+ OR NEW.email IS NOT OLD.email
56
+ OR NEW.email_hash IS NOT OLD.email_hash
57
+ OR NEW.subject_hash IS NOT OLD.subject_hash
58
+ OR NEW.details IS NOT OLD.details
59
+ OR NEW.locale IS NOT OLD.locale
60
+ OR NEW.policy_hash IS NOT OLD.policy_hash
61
+ OR NEW.received_at IS NOT OLD.received_at
62
+ OR NEW.due_at IS NOT OLD.due_at
63
+ BEGIN
64
+ SELECT RAISE(ABORT, 'subject_requests: the content of a request cannot be changed');
65
+ END;
66
+
67
+ CREATE TRIGGER subject_requests_closed_fixed
68
+ BEFORE UPDATE ON subject_requests
69
+ WHEN OLD.status = 'closed'
70
+ BEGIN
71
+ SELECT RAISE(ABORT, 'subject_requests: a closed request cannot be changed');
72
+ END;
73
+
74
+ CREATE TRIGGER subject_requests_confirmation_once
75
+ BEFORE UPDATE ON subject_requests
76
+ WHEN OLD.confirmed_at IS NOT NULL AND NEW.confirmed_at IS NOT OLD.confirmed_at
77
+ BEGIN
78
+ SELECT RAISE(ABORT, 'subject_requests: a confirmation cannot be changed');
79
+ END;
80
+
81
+ -- Rate limits of the confirmation emails to requesters: one row per normalised address (keyed
82
+ -- hash) and one row "*" for all of them. A send is allowed only when the handler's conditional
83
+ -- upsert changes the row (a new window, or room left under the cap), which only one of several
84
+ -- concurrent requests can do; the others send nothing.
85
+ CREATE TABLE subject_request_confirmation_slots (
86
+ rate_key TEXT PRIMARY KEY CHECK (rate_key = '*' OR (length(rate_key) = 64 AND rate_key NOT GLOB '*[^0-9a-f]*')),
87
+ -- When the current window started, ISO 8601 UTC.
88
+ window_start TEXT NOT NULL,
89
+ -- Emails sent in the current window.
90
+ count INTEGER NOT NULL CHECK (count >= 1)
91
+ ) STRICT;
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@consent-kit/server",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "The receiving end of consent-kit: consent receipts and data subject requests, as Fetch API handlers with Cloudflare D1 adapters and email adapters.",
5
+ "keywords": [
6
+ "consent-kit",
7
+ "consent",
8
+ "privacy",
9
+ "gdpr",
10
+ "eprivacy",
11
+ "cookie-consent",
12
+ "consent-receipts",
13
+ "data-subject-requests",
14
+ "cloudflare-workers",
15
+ "d1",
16
+ "fetch-api"
17
+ ],
18
+ "homepage": "https://consent-kit.com",
19
+ "bugs": {
20
+ "url": "https://github.com/pavelpascari/consent-kit/issues"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/pavelpascari/consent-kit.git",
25
+ "directory": "packages/server"
26
+ },
27
+ "license": "MIT",
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "engines": {
31
+ "node": ">=22"
32
+ },
33
+ "files": [
34
+ "dist",
35
+ "migrations",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "exports": {
40
+ ".": {
41
+ "types": "./dist/index.d.ts",
42
+ "import": "./dist/index.js"
43
+ },
44
+ "./migrations/0001_consent_receipts.sql": "./migrations/0001_consent_receipts.sql",
45
+ "./migrations/0002_subject_requests.sql": "./migrations/0002_subject_requests.sql",
46
+ "./package.json": "./package.json"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "devDependencies": {
52
+ "playwright": "^1.65.0",
53
+ "wrangler": "^4.169.0",
54
+ "@consent-kit/compiler": "0.1.0",
55
+ "@consent-kit/storage": "0.1.0"
56
+ },
57
+ "scripts": {
58
+ "build": "tsup"
59
+ },
60
+ "main": "./dist/index.js",
61
+ "types": "./dist/index.d.ts"
6
62
  }