@frigear-nu/cookie-consent 0.1.2 → 0.1.3
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/dist/module.d.mts +6 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +6 -4
- package/dist/runtime/app/composables/useCookieConsent.js +3 -2
- package/dist/runtime/server/routes/cookie-consent/index.post.js +4 -3
- package/dist/runtime/utils/api.d.ts +8 -0
- package/dist/runtime/utils/api.js +7 -0
- package/dist/runtime/utils/index.d.ts +2 -1
- package/dist/runtime/utils/index.js +1 -0
- package/dist/types.d.mts +1 -1
- package/package.json +10 -5
package/dist/module.d.mts
CHANGED
|
@@ -87,6 +87,11 @@ interface ConsentState {
|
|
|
87
87
|
ts: number;
|
|
88
88
|
categories: Record<string, boolean>;
|
|
89
89
|
}
|
|
90
|
+
/** The response of `GET` and `POST /api/cookie-consent`: the signed-in user's stored choice. */
|
|
91
|
+
interface ConsentDto {
|
|
92
|
+
/** `null` while the user has not answered. */
|
|
93
|
+
consent: ConsentState | null;
|
|
94
|
+
}
|
|
90
95
|
|
|
91
96
|
declare module '@nuxt/schema' {
|
|
92
97
|
interface NuxtConfig {
|
|
@@ -137,4 +142,4 @@ declare module 'nitropack' {
|
|
|
137
142
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
138
143
|
|
|
139
144
|
export { _default as default };
|
|
140
|
-
export type { ConsentCategory, ConsentCookie, ConsentMessages, ConsentState, ModuleOptions, PublicModuleOptions };
|
|
145
|
+
export type { ConsentCategory, ConsentCookie, ConsentDto, ConsentMessages, ConsentState, ModuleOptions, PublicModuleOptions };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, hasNuxtModule, addImports, addServerImports, addComponentsDir
|
|
2
|
-
import { registerModule, registerTailwindSource, registerLocales, extendDatabaseTable } from '@frigear-nu/module-kit/utils';
|
|
1
|
+
import { defineNuxtModule, createResolver, hasNuxtModule, addImports, addServerImports, addComponentsDir } from '@nuxt/kit';
|
|
2
|
+
import { registerModule, registerTailwindSource, registerLocales, addModuleRoutes, extendDatabaseTable } from '@frigear-nu/module-kit/utils';
|
|
3
3
|
import { mergeCategories, DEFAULT_CATEGORIES, computeVersion } from '../dist/runtime/utils/consent.js';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_MAX_AGE = 60 * 60 * 24 * 180;
|
|
@@ -37,8 +37,10 @@ const module$1 = defineNuxtModule({
|
|
|
37
37
|
]);
|
|
38
38
|
addComponentsDir({ path: resolver.resolve("./runtime/app/components"), priority: -1 });
|
|
39
39
|
if (persistToUser) {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
addModuleRoutes(resolver, [
|
|
41
|
+
{ method: "get", path: "", file: "cookie-consent/index.get" },
|
|
42
|
+
{ method: "post", path: "", file: "cookie-consent/index.post" }
|
|
43
|
+
], { base: "/api/cookie-consent" });
|
|
42
44
|
extendDatabaseTable(nuxt, {
|
|
43
45
|
resolver,
|
|
44
46
|
file: (dialect) => `./runtime/server/db/schema.${dialect}`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cookieConsentApi } from "../../utils/api.js";
|
|
1
2
|
import { acceptAllChoices, buildConsent, normalizeConsent, rejectAllChoices } from "../../utils/consent.js";
|
|
2
3
|
const createCookieConsent = (nuxtApp) => {
|
|
3
4
|
const config = useRuntimeConfig().public.cookieConsent;
|
|
@@ -18,7 +19,7 @@ const createCookieConsent = (nuxtApp) => {
|
|
|
18
19
|
const { loggedIn } = useUserSession();
|
|
19
20
|
if (!loggedIn.value) return;
|
|
20
21
|
try {
|
|
21
|
-
await $fetch(
|
|
22
|
+
await $fetch(cookieConsentApi.root, { method: "POST", body: { categories: state.categories, version: state.v } });
|
|
22
23
|
} catch (error) {
|
|
23
24
|
console.warn("[cookie-consent] Failed to store consent on the user.", error);
|
|
24
25
|
}
|
|
@@ -46,7 +47,7 @@ const createCookieConsent = (nuxtApp) => {
|
|
|
46
47
|
const { loggedIn } = useUserSession();
|
|
47
48
|
if (!loggedIn.value) return;
|
|
48
49
|
try {
|
|
49
|
-
const { consent: stored } = await $fetch(
|
|
50
|
+
const { consent: stored } = await $fetch(cookieConsentApi.root);
|
|
50
51
|
const state = normalizeConsent(stored, config.categories, config.version, stored?.ts);
|
|
51
52
|
if (state) {
|
|
52
53
|
cookie.value = state;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { db, schema } from "@nuxthub/db";
|
|
2
2
|
import { eq } from "drizzle-orm";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import { apiError } from "@frigear-nu/module-kit/server";
|
|
4
5
|
import { buildConsent } from "../../../utils/consent.js";
|
|
5
6
|
import { getCookieConsentConfig } from "../../utils/consent.js";
|
|
6
7
|
const bodySchema = z.object({
|
|
@@ -12,12 +13,12 @@ export default defineEventHandler(async (event) => {
|
|
|
12
13
|
const config = getCookieConsentConfig(event);
|
|
13
14
|
const body = await readValidatedBody(event, bodySchema.parse);
|
|
14
15
|
if (body.version !== config.version) {
|
|
15
|
-
throw
|
|
16
|
+
throw apiError(409, "outdated_version", "Outdated cookie consent version.");
|
|
16
17
|
}
|
|
17
18
|
const known = new Set(config.categories.map((category) => category.key));
|
|
18
19
|
const unknown = Object.keys(body.categories).filter((key) => !known.has(key));
|
|
19
20
|
if (unknown.length) {
|
|
20
|
-
throw
|
|
21
|
+
throw apiError(400, "unknown_categories", `Unknown categories: ${unknown.join(", ")}`, { categories: unknown });
|
|
21
22
|
}
|
|
22
23
|
const state = buildConsent(config.categories, config.version, body.categories);
|
|
23
24
|
await db.update(schema.users).set({
|
|
@@ -26,5 +27,5 @@ export default defineEventHandler(async (event) => {
|
|
|
26
27
|
cookieConsentCategories: JSON.stringify(state.categories)
|
|
27
28
|
}).where(eq(schema.users.id, user.id));
|
|
28
29
|
await useNitroApp().hooks.callHook("cookie-consent:saved", { userId: user.id, state, acceptedAt: state.ts });
|
|
29
|
-
return state;
|
|
30
|
+
return { consent: state };
|
|
30
31
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The cookie-consent API (registered only while consent is persisted on the user). */
|
|
2
|
+
export declare const cookieConsentApi: {
|
|
3
|
+
/**
|
|
4
|
+
* Session only. `GET`: `{ consent }`, the signed-in user's stored choice (`null` before they answered).
|
|
5
|
+
* `POST { categories, version }`: stores the choice and answers the same `{ consent }` shape (200).
|
|
6
|
+
*/
|
|
7
|
+
readonly root: "/api/cookie-consent";
|
|
8
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const cookieConsentApi = {
|
|
2
|
+
/**
|
|
3
|
+
* Session only. `GET`: `{ consent }`, the signed-in user's stored choice (`null` before they answered).
|
|
4
|
+
* `POST { categories, version }`: stores the choice and answers the same `{ consent }` shape (200).
|
|
5
|
+
*/
|
|
6
|
+
root: "/api/cookie-consent"
|
|
7
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { extendCookieConsent, defineConsentCategory } from './extend.js';
|
|
2
2
|
export { DEFAULT_CATEGORIES, mergeCategories, computeVersion, buildConsent, normalizeConsent, acceptAllChoices, rejectAllChoices, localize, } from './consent.js';
|
|
3
|
-
export
|
|
3
|
+
export { cookieConsentApi } from './api.js';
|
|
4
|
+
export type { ConsentCategory, ConsentCookie, ConsentDto, ConsentState, Translated } from '../../types.js';
|
package/dist/types.d.mts
CHANGED
|
@@ -2,4 +2,4 @@ export { type Translated } from '@frigear-nu/ui/translated'
|
|
|
2
2
|
|
|
3
3
|
export { default } from './module.mjs'
|
|
4
4
|
|
|
5
|
-
export { type ConsentCategory, type ConsentCookie, type ConsentMessages, type ConsentState, type ModuleOptions, type PublicModuleOptions } from './module.mjs'
|
|
5
|
+
export { type ConsentCategory, type ConsentCookie, type ConsentDto, type ConsentMessages, type ConsentState, type ModuleOptions, type PublicModuleOptions } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/cookie-consent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "GDPR cookie consent banner with categories - modules contribute categories (extendCookieConsent), apps gate scripts on consent, and the choice is stored as proof on the user.",
|
|
5
5
|
"homepage": "https://docs.frigear.dev/modules/cookie-consent",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"types": "./dist/runtime/utils/index.d.ts",
|
|
22
22
|
"import": "./dist/runtime/utils/index.js",
|
|
23
23
|
"default": "./dist/runtime/utils/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./api": {
|
|
26
|
+
"types": "./dist/runtime/utils/api.d.ts",
|
|
27
|
+
"import": "./dist/runtime/utils/api.js",
|
|
28
|
+
"default": "./dist/runtime/utils/api.js"
|
|
24
29
|
}
|
|
25
30
|
},
|
|
26
31
|
"files": [
|
|
@@ -30,8 +35,8 @@
|
|
|
30
35
|
"playground"
|
|
31
36
|
],
|
|
32
37
|
"dependencies": {
|
|
33
|
-
"@frigear-nu/module-kit": "1.1.
|
|
34
|
-
"@frigear-nu/ui": "0.1.
|
|
38
|
+
"@frigear-nu/module-kit": "1.1.3",
|
|
39
|
+
"@frigear-nu/ui": "0.1.3",
|
|
35
40
|
"@libsql/client": "^0.18.0",
|
|
36
41
|
"@nuxt/kit": "^4.6.1",
|
|
37
42
|
"@vueuse/core": "^15.0.0",
|
|
@@ -60,8 +65,8 @@
|
|
|
60
65
|
}
|
|
61
66
|
},
|
|
62
67
|
"devDependencies": {
|
|
63
|
-
"@frigear-nu/auth": "0.1.
|
|
64
|
-
"@frigear-nu/users": "1.1.
|
|
68
|
+
"@frigear-nu/auth": "0.1.4",
|
|
69
|
+
"@frigear-nu/users": "1.1.4",
|
|
65
70
|
"@nuxt/devtools": "^3.4.2",
|
|
66
71
|
"@nuxt/eslint-config": "^1.17.0",
|
|
67
72
|
"@nuxt/module-builder": "^1.0.3",
|