@cyguin/banner 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.
Files changed (47) hide show
  1. package/.github/workflows/publish.yml +27 -0
  2. package/LICENSE +7 -0
  3. package/README.md +113 -0
  4. package/dist/adapters/postgres.d.mts +8 -0
  5. package/dist/adapters/postgres.d.ts +8 -0
  6. package/dist/adapters/postgres.js +8 -0
  7. package/dist/adapters/postgres.mjs +8 -0
  8. package/dist/adapters/sqlite.d.mts +8 -0
  9. package/dist/adapters/sqlite.d.ts +8 -0
  10. package/dist/adapters/sqlite.js +8 -0
  11. package/dist/adapters/sqlite.mjs +8 -0
  12. package/dist/chunk-3R4HB5JY.mjs +175 -0
  13. package/dist/chunk-ATHBJQGY.js +73 -0
  14. package/dist/chunk-EBO3CZXG.mjs +15 -0
  15. package/dist/chunk-GW7T5T6B.mjs +69 -0
  16. package/dist/chunk-LI5BSLUA.js +175 -0
  17. package/dist/chunk-MCKGQKYU.js +15 -0
  18. package/dist/chunk-PCYDRYYV.js +69 -0
  19. package/dist/chunk-Q3CIRMT7.js +37 -0
  20. package/dist/chunk-SQPUEELE.mjs +73 -0
  21. package/dist/chunk-UF2PO4UG.mjs +81 -0
  22. package/dist/chunk-UG6SXPV3.js +81 -0
  23. package/dist/chunk-YH77VFY5.mjs +37 -0
  24. package/dist/index.d.mts +7 -0
  25. package/dist/index.d.ts +7 -0
  26. package/dist/index.js +20 -0
  27. package/dist/index.mjs +20 -0
  28. package/dist/next.d.mts +13 -0
  29. package/dist/next.d.ts +13 -0
  30. package/dist/next.js +7 -0
  31. package/dist/next.mjs +7 -0
  32. package/dist/react.d.mts +14 -0
  33. package/dist/react.d.ts +14 -0
  34. package/dist/react.js +7 -0
  35. package/dist/react.mjs +7 -0
  36. package/dist/types-pufIZ_FB.d.mts +14 -0
  37. package/dist/types-pufIZ_FB.d.ts +14 -0
  38. package/package.json +39 -0
  39. package/src/adapters/postgres.ts +77 -0
  40. package/src/adapters/sqlite.ts +84 -0
  41. package/src/components/ConsentBanner.tsx +186 -0
  42. package/src/components/index.ts +3 -0
  43. package/src/handlers/route.ts +51 -0
  44. package/src/index.ts +17 -0
  45. package/src/types.ts +18 -0
  46. package/tsconfig.json +18 -0
  47. package/tsup.config.ts +14 -0
@@ -0,0 +1,175 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/components/ConsentBanner.tsx
2
+ var _react = require('react');
3
+ var _jsxruntime = require('react/jsx-runtime');
4
+ function ConsentBanner({
5
+ apiBase = "/api/banner",
6
+ userId,
7
+ theme = "light",
8
+ className = "",
9
+ onAccept,
10
+ onReject
11
+ }) {
12
+ const [visible, setVisible] = _react.useState.call(void 0, false);
13
+ const [loading, setLoading] = _react.useState.call(void 0, true);
14
+ _react.useEffect.call(void 0, () => {
15
+ const checkConsent = async () => {
16
+ try {
17
+ const url = new URL(`${apiBase}/[...cyguin]`);
18
+ url.searchParams.set("cyguin", "");
19
+ if (userId) url.searchParams.set("userId", userId);
20
+ const res = await fetch(`${apiBase}/[...cyguin]${url.search}`);
21
+ if (res.ok) {
22
+ const data = await res.json();
23
+ if (data) {
24
+ setLoading(false);
25
+ return;
26
+ }
27
+ }
28
+ } catch (e) {
29
+ }
30
+ setVisible(true);
31
+ setLoading(false);
32
+ };
33
+ checkConsent();
34
+ }, [apiBase, userId]);
35
+ const handleDecision = async (decision) => {
36
+ try {
37
+ await fetch(`${apiBase}/[...cyguin]`, {
38
+ method: "POST",
39
+ headers: { "Content-Type": "application/json" },
40
+ body: JSON.stringify({ userId, decision, categories: [] })
41
+ });
42
+ } catch (e2) {
43
+ }
44
+ setVisible(false);
45
+ if (decision === "accept") {
46
+ _optionalChain([onAccept, 'optionalCall', _ => _()]);
47
+ } else {
48
+ _optionalChain([onReject, 'optionalCall', _2 => _2()]);
49
+ }
50
+ };
51
+ if (loading || !visible) return null;
52
+ return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
53
+ "div",
54
+ {
55
+ className: `cyguin-banner ${className}`,
56
+ "data-theme": theme,
57
+ role: "region",
58
+ "aria-label": "Cookie consent",
59
+ children: [
60
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "style", { children: `
61
+ .cyguin-banner {
62
+ --cyguin-bg: #ffffff;
63
+ --cyguin-bg-subtle: #f5f5f5;
64
+ --cyguin-border: #e5e5e5;
65
+ --cyguin-border-focus: #f5a800;
66
+ --cyguin-fg: #0a0a0a;
67
+ --cyguin-fg-muted: #888888;
68
+ --cyguin-accent: #f5a800;
69
+ --cyguin-accent-dark: #c47f00;
70
+ --cyguin-accent-fg: #0a0a0a;
71
+ --cyguin-radius: 6px;
72
+ --cyguin-shadow: 0 1px 4px rgba(0,0,0,0.08);
73
+ position: fixed;
74
+ bottom: 0;
75
+ left: 0;
76
+ right: 0;
77
+ z-index: 99999;
78
+ background: var(--cyguin-bg);
79
+ border-top: 1px solid var(--cyguin-border);
80
+ box-shadow: var(--cyguin-shadow);
81
+ padding: 16px 24px;
82
+ font-family: system-ui, -apple-system, sans-serif;
83
+ display: flex;
84
+ align-items: center;
85
+ justify-content: space-between;
86
+ gap: 16px;
87
+ flex-wrap: wrap;
88
+ }
89
+ .cyguin-banner[data-theme="dark"] {
90
+ --cyguin-bg: #0a0a0a;
91
+ --cyguin-bg-subtle: #1a1a1a;
92
+ --cyguin-border: #2a2a2a;
93
+ --cyguin-border-focus: #f5a800;
94
+ --cyguin-fg: #f5f5f5;
95
+ --cyguin-fg-muted: #888888;
96
+ --cyguin-accent: #f5a800;
97
+ --cyguin-accent-dark: #c47f00;
98
+ --cyguin-accent-fg: #0a0a0a;
99
+ --cyguin-radius: 6px;
100
+ --cyguin-shadow: 0 1px 4px rgba(0,0,0,0.4);
101
+ }
102
+ .cyguin-banner__text {
103
+ color: var(--cyguin-fg);
104
+ font-size: 14px;
105
+ line-height: 1.5;
106
+ margin: 0;
107
+ flex: 1;
108
+ min-width: 200px;
109
+ }
110
+ .cyguin-banner__text a {
111
+ color: var(--cyguin-accent);
112
+ text-decoration: underline;
113
+ }
114
+ .cyguin-banner__actions {
115
+ display: flex;
116
+ gap: 8px;
117
+ flex-shrink: 0;
118
+ }
119
+ .cyguin-banner__btn {
120
+ padding: 8px 16px;
121
+ border-radius: var(--cyguin-radius);
122
+ font-size: 14px;
123
+ font-weight: 500;
124
+ cursor: pointer;
125
+ border: 1px solid transparent;
126
+ transition: background 0.15s, border-color 0.15s;
127
+ }
128
+ .cyguin-banner__btn--accept {
129
+ background: var(--cyguin-accent);
130
+ color: var(--cyguin-accent-fg);
131
+ border-color: var(--cyguin-accent);
132
+ }
133
+ .cyguin-banner__btn--accept:hover {
134
+ background: var(--cyguin-accent-dark);
135
+ border-color: var(--cyguin-accent-dark);
136
+ }
137
+ .cyguin-banner__btn--reject {
138
+ background: transparent;
139
+ color: var(--cyguin-fg-muted);
140
+ border-color: var(--cyguin-border);
141
+ }
142
+ .cyguin-banner__btn--reject:hover {
143
+ border-color: var(--cyguin-fg-muted);
144
+ color: var(--cyguin-fg);
145
+ }
146
+ ` }),
147
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "cyguin-banner__text", children: "We use cookies to improve your experience. By continuing to browse you agree to our cookie policy." }),
148
+ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "cyguin-banner__actions", children: [
149
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
150
+ "button",
151
+ {
152
+ className: "cyguin-banner__btn cyguin-banner__btn--reject",
153
+ onClick: () => handleDecision("reject"),
154
+ type: "button",
155
+ children: "Reject"
156
+ }
157
+ ),
158
+ /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
159
+ "button",
160
+ {
161
+ className: "cyguin-banner__btn cyguin-banner__btn--accept",
162
+ onClick: () => handleDecision("accept"),
163
+ type: "button",
164
+ children: "Accept"
165
+ }
166
+ )
167
+ ] })
168
+ ]
169
+ }
170
+ );
171
+ }
172
+
173
+
174
+
175
+ exports.ConsentBanner = ConsentBanner;
@@ -0,0 +1,15 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+ var __commonJS = (cb, mod) => function __require2() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+
12
+
13
+
14
+
15
+ exports.__require = __require; exports.__commonJS = __commonJS;
@@ -0,0 +1,69 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkMCKGQKYUjs = require('./chunk-MCKGQKYU.js');
5
+
6
+ // node_modules/nanoid/url-alphabet/index.cjs
7
+ var require_url_alphabet = _chunkMCKGQKYUjs.__commonJS.call(void 0, {
8
+ "node_modules/nanoid/url-alphabet/index.cjs"(exports, module) {
9
+ "use strict";
10
+ var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
11
+ module.exports = { urlAlphabet };
12
+ }
13
+ });
14
+
15
+ // node_modules/nanoid/index.cjs
16
+ var require_nanoid = _chunkMCKGQKYUjs.__commonJS.call(void 0, {
17
+ "node_modules/nanoid/index.cjs"(exports, module) {
18
+ "use strict";
19
+ var crypto = _chunkMCKGQKYUjs.__require.call(void 0, "crypto");
20
+ var { urlAlphabet } = require_url_alphabet();
21
+ var POOL_SIZE_MULTIPLIER = 128;
22
+ var pool;
23
+ var poolOffset;
24
+ var fillPool = (bytes) => {
25
+ if (!pool || pool.length < bytes) {
26
+ pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
27
+ crypto.randomFillSync(pool);
28
+ poolOffset = 0;
29
+ } else if (poolOffset + bytes > pool.length) {
30
+ crypto.randomFillSync(pool);
31
+ poolOffset = 0;
32
+ }
33
+ poolOffset += bytes;
34
+ };
35
+ var random = (bytes) => {
36
+ fillPool(bytes |= 0);
37
+ return pool.subarray(poolOffset - bytes, poolOffset);
38
+ };
39
+ var customRandom = (alphabet, defaultSize, getRandom) => {
40
+ let mask = (2 << 31 - Math.clz32(alphabet.length - 1 | 1)) - 1;
41
+ let step = Math.ceil(1.6 * mask * defaultSize / alphabet.length);
42
+ return (size = defaultSize) => {
43
+ let id = "";
44
+ while (true) {
45
+ let bytes = getRandom(step);
46
+ let i = step;
47
+ while (i--) {
48
+ id += alphabet[bytes[i] & mask] || "";
49
+ if (id.length === size) return id;
50
+ }
51
+ }
52
+ };
53
+ };
54
+ var customAlphabet = (alphabet, size = 21) => customRandom(alphabet, size, random);
55
+ var nanoid = (size = 21) => {
56
+ fillPool(size |= 0);
57
+ let id = "";
58
+ for (let i = poolOffset - size; i < poolOffset; i++) {
59
+ id += urlAlphabet[pool[i] & 63];
60
+ }
61
+ return id;
62
+ };
63
+ module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random };
64
+ }
65
+ });
66
+
67
+
68
+
69
+ exports.require_nanoid = require_nanoid;
@@ -0,0 +1,37 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/handlers/route.ts
2
+ var _server = require('next/server');
3
+ function createBannerHandler(options) {
4
+ const { adapter } = options;
5
+ return async function handler(request, { params }) {
6
+ const method = request.method;
7
+ if (method === "GET") {
8
+ const userId = _nullishCoalesce(request.nextUrl.searchParams.get("userId"), () => ( void 0));
9
+ const record = await adapter.getConsent(userId);
10
+ if (!record) {
11
+ return _server.NextResponse.json(null, { status: 200 });
12
+ }
13
+ return _server.NextResponse.json(record, { status: 200 });
14
+ }
15
+ if (method === "POST") {
16
+ const body = await request.json();
17
+ const { userId, decision, categories } = body;
18
+ if (!decision || !["accept", "reject"].includes(decision)) {
19
+ return _server.NextResponse.json(
20
+ { error: 'Invalid decision. Must be "accept" or "reject".' },
21
+ { status: 400 }
22
+ );
23
+ }
24
+ const record = await adapter.recordConsent(
25
+ userId,
26
+ decision,
27
+ _nullishCoalesce(categories, () => ( []))
28
+ );
29
+ return _server.NextResponse.json(record, { status: 201 });
30
+ }
31
+ return _server.NextResponse.json({ error: "Method not allowed" }, { status: 405 });
32
+ };
33
+ }
34
+
35
+
36
+
37
+ exports.createBannerHandler = createBannerHandler;
@@ -0,0 +1,73 @@
1
+ import {
2
+ require_nanoid
3
+ } from "./chunk-GW7T5T6B.mjs";
4
+ import {
5
+ __require
6
+ } from "./chunk-EBO3CZXG.mjs";
7
+
8
+ // src/adapters/postgres.ts
9
+ function PostgresAdapter(options) {
10
+ let db;
11
+ try {
12
+ const postgres = __require("porsager/postgres");
13
+ db = postgres(options.connectionString);
14
+ } catch {
15
+ throw new Error("porsager/postgres is required. Install with: npm install porsager/postgres");
16
+ }
17
+ return {
18
+ async getConsent(userId) {
19
+ let result;
20
+ if (userId) {
21
+ result = await db`
22
+ SELECT * FROM consent_records
23
+ WHERE user_id = ${userId}
24
+ ORDER BY created_at DESC
25
+ LIMIT 1
26
+ `;
27
+ } else {
28
+ result = await db`
29
+ SELECT * FROM consent_records
30
+ ORDER BY created_at DESC
31
+ LIMIT 1
32
+ `;
33
+ }
34
+ const row = result[0];
35
+ if (!row) return null;
36
+ return {
37
+ id: row.id,
38
+ userId: row.user_id,
39
+ decision: row.decision,
40
+ categories: row.categories,
41
+ createdAt: row.created_at
42
+ };
43
+ },
44
+ async recordConsent(userId, decision, categories) {
45
+ const { nanoid } = require_nanoid();
46
+ const id = nanoid();
47
+ const createdAt = Date.now();
48
+ const result = await db`
49
+ INSERT INTO consent_records (id, user_id, decision, categories, created_at)
50
+ VALUES (
51
+ ${id},
52
+ ${userId ?? null},
53
+ ${decision},
54
+ ${categories},
55
+ ${createdAt}
56
+ )
57
+ RETURNING *
58
+ `;
59
+ const row = result[0];
60
+ return {
61
+ id: row.id,
62
+ userId: row.user_id,
63
+ decision: row.decision,
64
+ categories: row.categories,
65
+ createdAt: row.created_at
66
+ };
67
+ }
68
+ };
69
+ }
70
+
71
+ export {
72
+ PostgresAdapter
73
+ };
@@ -0,0 +1,81 @@
1
+ import {
2
+ require_nanoid
3
+ } from "./chunk-GW7T5T6B.mjs";
4
+ import {
5
+ __require
6
+ } from "./chunk-EBO3CZXG.mjs";
7
+
8
+ // src/adapters/sqlite.ts
9
+ function SQLiteAdapter(options = {}) {
10
+ let db;
11
+ try {
12
+ const Database = __require("better-sqlite3");
13
+ const dbPath = options.path ?? "./data/banner.db";
14
+ db = new Database(dbPath);
15
+ db.pragma("journal_mode = WAL");
16
+ } catch {
17
+ throw new Error("better-sqlite3 is required. Install with: npm install better-sqlite3");
18
+ }
19
+ db.exec(`
20
+ CREATE TABLE IF NOT EXISTS consent_records (
21
+ id TEXT PRIMARY KEY,
22
+ user_id TEXT,
23
+ decision TEXT NOT NULL,
24
+ categories TEXT NOT NULL DEFAULT '[]',
25
+ created_at INTEGER NOT NULL
26
+ )
27
+ `);
28
+ return {
29
+ async getConsent(userId) {
30
+ let stmt;
31
+ if (userId) {
32
+ stmt = db.prepare(
33
+ "SELECT * FROM consent_records WHERE user_id = ? ORDER BY created_at DESC LIMIT 1"
34
+ );
35
+ const row = stmt.get(userId);
36
+ if (!row) return null;
37
+ return {
38
+ id: row.id,
39
+ userId: row.user_id,
40
+ decision: row.decision,
41
+ categories: JSON.parse(row.categories),
42
+ createdAt: row.created_at
43
+ };
44
+ } else {
45
+ stmt = db.prepare(
46
+ "SELECT * FROM consent_records ORDER BY created_at DESC LIMIT 1"
47
+ );
48
+ const row = stmt.get();
49
+ if (!row) return null;
50
+ return {
51
+ id: row.id,
52
+ userId: row.user_id,
53
+ decision: row.decision,
54
+ categories: JSON.parse(row.categories),
55
+ createdAt: row.created_at
56
+ };
57
+ }
58
+ },
59
+ async recordConsent(userId, decision, categories) {
60
+ const { nanoid } = require_nanoid();
61
+ const id = nanoid();
62
+ const createdAt = Date.now();
63
+ const stmt = db.prepare(`
64
+ INSERT INTO consent_records (id, user_id, decision, categories, created_at)
65
+ VALUES (?, ?, ?, ?, ?)
66
+ `);
67
+ stmt.run(id, userId ?? null, decision, JSON.stringify(categories), createdAt);
68
+ return {
69
+ id,
70
+ userId: userId ?? null,
71
+ decision,
72
+ categories,
73
+ createdAt
74
+ };
75
+ }
76
+ };
77
+ }
78
+
79
+ export {
80
+ SQLiteAdapter
81
+ };
@@ -0,0 +1,81 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkPCYDRYYVjs = require('./chunk-PCYDRYYV.js');
4
+
5
+
6
+ var _chunkMCKGQKYUjs = require('./chunk-MCKGQKYU.js');
7
+
8
+ // src/adapters/sqlite.ts
9
+ function SQLiteAdapter(options = {}) {
10
+ let db;
11
+ try {
12
+ const Database = _chunkMCKGQKYUjs.__require.call(void 0, "better-sqlite3");
13
+ const dbPath = _nullishCoalesce(options.path, () => ( "./data/banner.db"));
14
+ db = new Database(dbPath);
15
+ db.pragma("journal_mode = WAL");
16
+ } catch (e) {
17
+ throw new Error("better-sqlite3 is required. Install with: npm install better-sqlite3");
18
+ }
19
+ db.exec(`
20
+ CREATE TABLE IF NOT EXISTS consent_records (
21
+ id TEXT PRIMARY KEY,
22
+ user_id TEXT,
23
+ decision TEXT NOT NULL,
24
+ categories TEXT NOT NULL DEFAULT '[]',
25
+ created_at INTEGER NOT NULL
26
+ )
27
+ `);
28
+ return {
29
+ async getConsent(userId) {
30
+ let stmt;
31
+ if (userId) {
32
+ stmt = db.prepare(
33
+ "SELECT * FROM consent_records WHERE user_id = ? ORDER BY created_at DESC LIMIT 1"
34
+ );
35
+ const row = stmt.get(userId);
36
+ if (!row) return null;
37
+ return {
38
+ id: row.id,
39
+ userId: row.user_id,
40
+ decision: row.decision,
41
+ categories: JSON.parse(row.categories),
42
+ createdAt: row.created_at
43
+ };
44
+ } else {
45
+ stmt = db.prepare(
46
+ "SELECT * FROM consent_records ORDER BY created_at DESC LIMIT 1"
47
+ );
48
+ const row = stmt.get();
49
+ if (!row) return null;
50
+ return {
51
+ id: row.id,
52
+ userId: row.user_id,
53
+ decision: row.decision,
54
+ categories: JSON.parse(row.categories),
55
+ createdAt: row.created_at
56
+ };
57
+ }
58
+ },
59
+ async recordConsent(userId, decision, categories) {
60
+ const { nanoid } = _chunkPCYDRYYVjs.require_nanoid.call(void 0, );
61
+ const id = nanoid();
62
+ const createdAt = Date.now();
63
+ const stmt = db.prepare(`
64
+ INSERT INTO consent_records (id, user_id, decision, categories, created_at)
65
+ VALUES (?, ?, ?, ?, ?)
66
+ `);
67
+ stmt.run(id, _nullishCoalesce(userId, () => ( null)), decision, JSON.stringify(categories), createdAt);
68
+ return {
69
+ id,
70
+ userId: _nullishCoalesce(userId, () => ( null)),
71
+ decision,
72
+ categories,
73
+ createdAt
74
+ };
75
+ }
76
+ };
77
+ }
78
+
79
+
80
+
81
+ exports.SQLiteAdapter = SQLiteAdapter;
@@ -0,0 +1,37 @@
1
+ // src/handlers/route.ts
2
+ import { NextResponse } from "next/server";
3
+ function createBannerHandler(options) {
4
+ const { adapter } = options;
5
+ return async function handler(request, { params }) {
6
+ const method = request.method;
7
+ if (method === "GET") {
8
+ const userId = request.nextUrl.searchParams.get("userId") ?? void 0;
9
+ const record = await adapter.getConsent(userId);
10
+ if (!record) {
11
+ return NextResponse.json(null, { status: 200 });
12
+ }
13
+ return NextResponse.json(record, { status: 200 });
14
+ }
15
+ if (method === "POST") {
16
+ const body = await request.json();
17
+ const { userId, decision, categories } = body;
18
+ if (!decision || !["accept", "reject"].includes(decision)) {
19
+ return NextResponse.json(
20
+ { error: 'Invalid decision. Must be "accept" or "reject".' },
21
+ { status: 400 }
22
+ );
23
+ }
24
+ const record = await adapter.recordConsent(
25
+ userId,
26
+ decision,
27
+ categories ?? []
28
+ );
29
+ return NextResponse.json(record, { status: 201 });
30
+ }
31
+ return NextResponse.json({ error: "Method not allowed" }, { status: 405 });
32
+ };
33
+ }
34
+
35
+ export {
36
+ createBannerHandler
37
+ };
@@ -0,0 +1,7 @@
1
+ export { B as BannerAdapter, C as ConsentDecision, a as ConsentRecordData } from './types-pufIZ_FB.mjs';
2
+ export { ConsentBanner, ConsentBannerProps } from './react.mjs';
3
+ export { SQLiteAdapter, SQLiteAdapterOptions } from './adapters/sqlite.mjs';
4
+ export { PostgresAdapter, PostgresAdapterOptions } from './adapters/postgres.mjs';
5
+ export { BannerHandlerOptions, createBannerHandler } from './next.mjs';
6
+ import 'react/jsx-runtime';
7
+ import 'next/server';
@@ -0,0 +1,7 @@
1
+ export { B as BannerAdapter, C as ConsentDecision, a as ConsentRecordData } from './types-pufIZ_FB.js';
2
+ export { ConsentBanner, ConsentBannerProps } from './react.js';
3
+ export { SQLiteAdapter, SQLiteAdapterOptions } from './adapters/sqlite.js';
4
+ export { PostgresAdapter, PostgresAdapterOptions } from './adapters/postgres.js';
5
+ export { BannerHandlerOptions, createBannerHandler } from './next.js';
6
+ import 'react/jsx-runtime';
7
+ import 'next/server';
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkQ3CIRMT7js = require('./chunk-Q3CIRMT7.js');
4
+
5
+
6
+ var _chunkLI5BSLUAjs = require('./chunk-LI5BSLUA.js');
7
+
8
+
9
+ var _chunkUG6SXPV3js = require('./chunk-UG6SXPV3.js');
10
+
11
+
12
+ var _chunkATHBJQGYjs = require('./chunk-ATHBJQGY.js');
13
+ require('./chunk-PCYDRYYV.js');
14
+ require('./chunk-MCKGQKYU.js');
15
+
16
+
17
+
18
+
19
+
20
+ exports.ConsentBanner = _chunkLI5BSLUAjs.ConsentBanner; exports.PostgresAdapter = _chunkATHBJQGYjs.PostgresAdapter; exports.SQLiteAdapter = _chunkUG6SXPV3js.SQLiteAdapter; exports.createBannerHandler = _chunkQ3CIRMT7js.createBannerHandler;
package/dist/index.mjs ADDED
@@ -0,0 +1,20 @@
1
+ import {
2
+ createBannerHandler
3
+ } from "./chunk-YH77VFY5.mjs";
4
+ import {
5
+ ConsentBanner
6
+ } from "./chunk-3R4HB5JY.mjs";
7
+ import {
8
+ SQLiteAdapter
9
+ } from "./chunk-UF2PO4UG.mjs";
10
+ import {
11
+ PostgresAdapter
12
+ } from "./chunk-SQPUEELE.mjs";
13
+ import "./chunk-GW7T5T6B.mjs";
14
+ import "./chunk-EBO3CZXG.mjs";
15
+ export {
16
+ ConsentBanner,
17
+ PostgresAdapter,
18
+ SQLiteAdapter,
19
+ createBannerHandler
20
+ };
@@ -0,0 +1,13 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import { B as BannerAdapter } from './types-pufIZ_FB.mjs';
3
+
4
+ interface BannerHandlerOptions {
5
+ adapter: BannerAdapter;
6
+ }
7
+ declare function createBannerHandler(options: BannerHandlerOptions): (request: NextRequest, { params }: {
8
+ params: {
9
+ cyguin: string[];
10
+ };
11
+ }) => Promise<NextResponse>;
12
+
13
+ export { type BannerHandlerOptions, createBannerHandler };
package/dist/next.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { NextRequest, NextResponse } from 'next/server';
2
+ import { B as BannerAdapter } from './types-pufIZ_FB.js';
3
+
4
+ interface BannerHandlerOptions {
5
+ adapter: BannerAdapter;
6
+ }
7
+ declare function createBannerHandler(options: BannerHandlerOptions): (request: NextRequest, { params }: {
8
+ params: {
9
+ cyguin: string[];
10
+ };
11
+ }) => Promise<NextResponse>;
12
+
13
+ export { type BannerHandlerOptions, createBannerHandler };
package/dist/next.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkQ3CIRMT7js = require('./chunk-Q3CIRMT7.js');
4
+ require('./chunk-MCKGQKYU.js');
5
+
6
+
7
+ exports.createBannerHandler = _chunkQ3CIRMT7js.createBannerHandler;
package/dist/next.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import {
2
+ createBannerHandler
3
+ } from "./chunk-YH77VFY5.mjs";
4
+ import "./chunk-EBO3CZXG.mjs";
5
+ export {
6
+ createBannerHandler
7
+ };