@dargmuesli/nuxt-cookie-control 5.10.3 → 6.0.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.
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Nuxt Cookie Control
2
- [![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href]
3
2
 
4
- ![Nuxt Cookie Control](https://drive.google.com/a/broj42.com/uc?id=1FGQVyj2s0OT-gpTYxH_FuQhe6oU9iejW)
3
+ [![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
4
 
5
+ ![nuxt-cookie-control](https://drive.google.com/a/broj42.com/uc?id=19sFguJo7SKUvmH4xu9DhK9ZXzR6oWLX8)
6
6
 
7
7
  ✅ Translated for: ar, az, bg, cs, da, de, en, es, fi, fr, hr, hu, it, ja, ko, lt, nl, no, oc, pt, pl, rs, ru, sk, sv, tr and uk
8
8
 
9
9
  ✅ Vue 3 support
10
10
 
11
- Components and composables are [auto-imported](https://nuxt.com/docs/guide/concepts/auto-imports)
11
+ ⚠️ For Nuxt 2, please use nuxt-cookie-control < 3.0.0
12
12
 
13
13
  🚩 API changes since continuing Dario Ferderber's work on [gitlab.com/broj42/nuxt-cookie-control](https://gitlab.com/broj42/nuxt-cookie-control), make sure to read the README!
14
14
 
@@ -17,14 +17,18 @@
17
17
 
18
18
  [![Stackblitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/dargmuesli/nuxt-cookie-control?file=playground%2Fapp.vue)
19
19
 
20
+
20
21
  ### Installation
22
+
21
23
  ```bash
22
24
  npm i -D @dargmuesli/nuxt-cookie-control
23
25
  yarn add -D @dargmuesli/nuxt-cookie-control
24
26
  pnpm i -D @dargmuesli/nuxt-cookie-control
25
27
  ```
26
28
 
29
+
27
30
  ### Configuration
31
+
28
32
  ```javascript
29
33
  // nuxt.config.js
30
34
 
@@ -44,7 +48,9 @@ modules: [
44
48
  ]
45
49
  ```
46
50
 
51
+
47
52
  ### Usage
53
+
48
54
  ```html
49
55
  <!-- app.vue -->
50
56
 
@@ -147,6 +153,11 @@ cookieExpiryOffsetMs: 1000 * 60 * 60 * 24 * 365, // one year
147
153
  cookieNameIsConsentGiven: 'ncc_c',
148
154
  cookieNameCookiesEnabledIds: 'ncc_e',
149
155
 
156
+ // Options to pass to nuxt's useCookie
157
+ cookieOptions: {
158
+ path: '/',
159
+ }
160
+
150
161
  // Switch to toggle the "accept necessary" button.
151
162
  isAcceptNecessaryButtonEnabled: true
152
163
 
@@ -169,18 +180,10 @@ isDashInDescriptionEnabled: true,
169
180
  // Switch to toggle the blocking of iframes.
170
181
  // This can be used to prevent iframes from adding additional cookies.
171
182
  isIframeBlocked: false,
172
- // or:
173
- // isIframeBlocked: {
174
- // initialState: false
175
- // },
176
183
 
177
184
  // Switch to toggle the modal being shown right away, requiring a user's decision.
178
185
  isModalForced: false,
179
186
 
180
- // The domain to set cookies on.
181
- // This is useful in case you have subdomains (shop.yourdomain.com)
182
- domain: 'yourdomain.com',
183
-
184
187
  // The locales to include.
185
188
  locales: ['en'],
186
189
 
@@ -214,6 +217,7 @@ Every property the includes a `{ en: ... }` value is a translatable property tha
214
217
  ### Component Slots
215
218
 
216
219
  #### Bar
220
+
217
221
  ```html
218
222
  <CookieControl>
219
223
  <template #bar>
@@ -225,6 +229,7 @@ Every property the includes a `{ en: ... }` value is a translatable property tha
225
229
  ```
226
230
 
227
231
  #### Modal
232
+
228
233
  ```html
229
234
  <template #modal>
230
235
  <h3>Modal title</h3>
@@ -233,6 +238,7 @@ Every property the includes a `{ en: ... }` value is a translatable property tha
233
238
  ```
234
239
 
235
240
  #### Cookie
241
+
236
242
  ```html
237
243
  <template #cookie="{config}">
238
244
  <span v-for="c in config" :key="c.id" v-text="c.cookies"/>
@@ -240,6 +246,7 @@ Every property the includes a `{ en: ... }` value is a translatable property tha
240
246
  ```
241
247
 
242
248
  ### Props
249
+
243
250
  - locale: `['en']`
244
251
  ```html
245
252
  <CookieControl locale="de"/>
package/dist/module.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { CookieOptions } from 'nuxt/app';
2
3
 
3
4
  type Locale = 'ar' | 'az' | 'bg' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hr' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'nl' | 'no' | 'oc' | 'pt' | 'pl' | 'rs' | 'ru' | 'sk' | 'sv' | 'tr' | 'uk';
4
5
  type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
@@ -39,16 +40,14 @@ interface ModuleOptions {
39
40
  necessary: Cookie[];
40
41
  optional: Cookie[];
41
42
  };
42
- domain: string;
43
+ cookieOptions: CookieOptions;
43
44
  isAcceptNecessaryButtonEnabled: boolean;
44
45
  isControlButtonEnabled: boolean;
45
46
  isCookieIdVisible: boolean;
46
47
  isCssEnabled: boolean;
47
48
  isCssPonyfillEnabled: boolean;
48
49
  isDashInDescriptionEnabled: boolean;
49
- isIframeBlocked: boolean | {
50
- initialState: boolean;
51
- };
50
+ isIframeBlocked: boolean;
52
51
  isModalForced: boolean;
53
52
  locales: Locale[];
54
53
  localeTexts: PartialRecord<Locale, Partial<LocaleStrings>>;
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "5.10.3",
3
+ "version": "6.0.0",
4
4
  "configKey": "cookieControl",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.0.0"
package/dist/module.mjs CHANGED
@@ -3,7 +3,7 @@ import { pathToFileURL } from 'node:url';
3
3
  import { createResolver, defineNuxtModule, addPlugin, addImports, addTemplate, extendWebpackConfig, resolvePath } from '@nuxt/kit';
4
4
 
5
5
  const name = "@dargmuesli/nuxt-cookie-control";
6
- const version = "5.10.3";
6
+ const version = "6.0.0";
7
7
 
8
8
  const en = {
9
9
  accept: "Accept",
@@ -62,6 +62,9 @@ const DEFAULTS = {
62
62
  // one year
63
63
  cookieNameIsConsentGiven: "ncc_c",
64
64
  cookieNameCookiesEnabledIds: "ncc_e",
65
+ cookieOptions: {
66
+ path: "/"
67
+ },
65
68
  isAcceptNecessaryButtonEnabled: true,
66
69
  isControlButtonEnabled: true,
67
70
  isCookieIdVisible: false,
@@ -70,7 +73,6 @@ const DEFAULTS = {
70
73
  isDashInDescriptionEnabled: true,
71
74
  isIframeBlocked: false,
72
75
  isModalForced: false,
73
- domain: "",
74
76
  locales: ["en"],
75
77
  localeTexts: { en }
76
78
  };
@@ -122,8 +124,7 @@ export default ${JSON.stringify(
122
124
  const blockIframes = (moduleOptions) => {
123
125
  if (moduleOptions.isIframeBlocked) {
124
126
  const isIframeBlocked = {
125
- name: "functional",
126
- initialState: typeof moduleOptions.isIframeBlocked !== "boolean" && moduleOptions.isIframeBlocked.initialState !== void 0 ? moduleOptions.isIframeBlocked.initialState : true
127
+ name: "functional"
127
128
  };
128
129
  if (moduleOptions.cookies) {
129
130
  if (moduleOptions.cookies.optional) {
@@ -94,12 +94,8 @@
94
94
  type="checkbox"
95
95
  :checked="
96
96
  getCookieIds(localCookiesEnabled).includes(
97
- getCookieId(cookie)
98
- ) ||
99
- (cookieIsConsentGiven !== allCookieIdsString &&
100
- typeof moduleOptions.isIframeBlocked ===
101
- 'object' &&
102
- moduleOptions.isIframeBlocked.initialState)
97
+ getCookieId(cookie),
98
+ )
103
99
  "
104
100
  @change="toogleCookie(cookie)"
105
101
  />
@@ -135,7 +131,7 @@
135
131
  >
136
132
  <span
137
133
  v-for="entry in Object.entries(
138
- cookie.links || {}
134
+ cookie.links || {},
139
135
  )"
140
136
  :key="entry[0]"
141
137
  >
@@ -196,7 +192,6 @@ import {
196
192
  getCookieId,
197
193
  getCookieIds,
198
194
  removeCookie,
199
- setCookie,
200
195
  resolveTranslatable,
201
196
  } from '../methods'
202
197
  import setCssVariables from '#cookie-control/set-vars'
@@ -219,12 +214,20 @@ const {
219
214
  } = useCookieControl()
220
215
 
221
216
  // data
222
- const expires = new Date()
217
+ const expires = new Date(Date.now() + moduleOptions.cookieExpiryOffsetMs)
223
218
  const localCookiesEnabled = ref([...(cookiesEnabled.value || [])])
224
219
  const allCookieIdsString = getAllCookieIdsString(moduleOptions)
225
- const cookieIsConsentGiven = useCookie(moduleOptions.cookieNameIsConsentGiven)
220
+ const cookieIsConsentGiven = useCookie(moduleOptions.cookieNameIsConsentGiven, {
221
+ expires,
222
+ ...moduleOptions.cookieOptions,
223
+ })
224
+
226
225
  const cookieCookiesEnabledIds = useCookie(
227
- moduleOptions.cookieNameCookiesEnabledIds
226
+ moduleOptions.cookieNameCookiesEnabledIds,
227
+ {
228
+ expires,
229
+ ...moduleOptions.cookieOptions,
230
+ },
228
231
  )
229
232
 
230
233
  // computations
@@ -232,7 +235,7 @@ const isSaved = computed(
232
235
  () =>
233
236
  getCookieIds(cookiesEnabled.value || [])
234
237
  .sort()
235
- .join('|') !== getCookieIds(localCookiesEnabled.value).sort().join('|')
238
+ .join('|') !== getCookieIds(localCookiesEnabled.value).sort().join('|'),
236
239
  )
237
240
  const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
238
241
 
@@ -275,9 +278,6 @@ const getName = (name: Translatable) => {
275
278
  ? localeStrings.value?.cookiesFunctional
276
279
  : resolveTranslatable(name, props.locale)
277
280
  }
278
- const init = () => {
279
- expires.setTime(expires.getTime() + moduleOptions.cookieExpiryOffsetMs)
280
- }
281
281
  const onModalClick = () => {
282
282
  if (moduleOptions.closeModalOnClickOutside) {
283
283
  isModalActive.value = false
@@ -295,7 +295,7 @@ const setCookies = ({
295
295
  ? [
296
296
  ...moduleOptions.cookies.necessary,
297
297
  ...moduleOptions.cookies.optional.filter((cookieOptional: Cookie) =>
298
- cookiesOptionalEnabledNew.includes(cookieOptional)
298
+ cookiesOptionalEnabledNew.includes(cookieOptional),
299
299
  ),
300
300
  ]
301
301
  : []
@@ -311,7 +311,7 @@ const toggleButton = ($event: MouseEvent) => {
311
311
  }
312
312
  const toogleCookie = (cookie: Cookie) => {
313
313
  const cookieIndex = getCookieIds(localCookiesEnabled.value).indexOf(
314
- getCookieId(cookie)
314
+ getCookieId(cookie),
315
315
  )
316
316
 
317
317
  if (cookieIndex < 0) {
@@ -338,11 +338,7 @@ onBeforeMount(() => {
338
338
 
339
339
  if (cookieIsConsentGiven.value === allCookieIdsString) {
340
340
  for (const cookieOptional of moduleOptions.cookies.optional) {
341
- if (
342
- typeof moduleOptions.isIframeBlocked === 'boolean'
343
- ? moduleOptions.isIframeBlocked === true
344
- : moduleOptions.isIframeBlocked.initialState === true
345
- ) {
341
+ if (moduleOptions.isIframeBlocked) {
346
342
  localCookiesEnabled.value.push(cookieOptional)
347
343
  }
348
344
  }
@@ -358,13 +354,7 @@ watch(
358
354
  localCookiesEnabled.value = [...(current || [])]
359
355
 
360
356
  if (isConsentGiven.value) {
361
- setCookie(
362
- moduleOptions.cookieNameCookiesEnabledIds,
363
- getCookieIds(current || []).join('|'),
364
- {
365
- expires,
366
- }
367
- )
357
+ cookieCookiesEnabledIds.value = getCookieIds(current || []).join('|')
368
358
 
369
359
  for (const cookieEnabled of current || []) {
370
360
  if (!cookieEnabled.src) continue
@@ -379,7 +369,7 @@ watch(
379
369
 
380
370
  // delete formerly enabled cookies that are now disabled
381
371
  const cookiesOptionalDisabled = moduleOptions.cookies.optional.filter(
382
- (cookieOptional) => !(current || []).includes(cookieOptional)
372
+ (cookieOptional) => !(current || []).includes(cookieOptional),
383
373
  )
384
374
 
385
375
  for (const cookieOptionalDisabled of cookiesOptionalDisabled) {
@@ -392,7 +382,7 @@ watch(
392
382
  if (cookieOptionalDisabled.src) {
393
383
  for (const script of [
394
384
  ...document.head.querySelectorAll(
395
- `script[src="${cookieOptionalDisabled.src}"]`
385
+ `script[src="${cookieOptionalDisabled.src}"]`,
396
386
  ),
397
387
  ]) {
398
388
  script.parentNode?.removeChild(script)
@@ -400,19 +390,13 @@ watch(
400
390
  }
401
391
  }
402
392
  },
403
- { deep: true }
393
+ { deep: true },
404
394
  )
405
395
  watch(isConsentGiven, (current, _previous) => {
406
396
  if (current === undefined) {
407
397
  cookieIsConsentGiven.value = undefined
408
398
  } else {
409
- setCookie(
410
- moduleOptions.cookieNameIsConsentGiven,
411
- current ? allCookieIdsString : '0',
412
- {
413
- expires,
414
- }
415
- )
399
+ cookieIsConsentGiven.value = current ? allCookieIdsString : '0'
416
400
  }
417
401
  })
418
402
 
@@ -421,7 +405,4 @@ defineExpose({
421
405
  acceptPartial,
422
406
  decline,
423
407
  })
424
-
425
- // initialization
426
- init()
427
408
  </script>
@@ -35,8 +35,8 @@ const { cookiesEnabled, isModalActive, moduleOptions } = useCookieControl()
35
35
  const isCookieFunctionalEnabled = computed(
36
36
  () =>
37
37
  (cookiesEnabled.value || []).filter(
38
- (cookieEnabled: Cookie) => cookieEnabled.name === 'functional'
39
- ).length > 0
38
+ (cookieEnabled: Cookie) => cookieEnabled.name === 'functional',
39
+ ).length > 0,
40
40
  )
41
41
  const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
42
42
  </script>
@@ -1,9 +1,7 @@
1
- import { type CookieSerializeOptions } from 'cookie-es';
2
1
  import { Cookie, ModuleOptions, Translatable } from './types';
3
2
  export declare const getAllCookieIdsString: (moduleOptions: ModuleOptions) => string;
4
3
  export declare const getCookieId: (cookie: Cookie) => string;
5
4
  export declare const getCookieIds: (cookies: Cookie[]) => string[];
6
5
  export declare const removeCookie: (name: string) => string;
7
6
  export declare const resolveTranslatable: (translatable: Translatable, locale?: import("./types").Locale) => string;
8
- export declare const setCookie: (name: string, value: string, options: CookieSerializeOptions) => string;
9
7
  export declare const useResolveTranslatable: (locale?: import("./types").Locale) => (translatable: Translatable) => string;
@@ -18,10 +18,6 @@ export const resolveTranslatable = (translatable, locale = LOCALE_DEFAULT) => {
18
18
  throw new Error(`Could not get translation for locale ${locale}.`);
19
19
  return result;
20
20
  };
21
- export const setCookie = (name, value, options) => document.cookie = serialize(name, value, {
22
- sameSite: "strict",
23
- ...options
24
- });
25
21
  export const useResolveTranslatable = (locale = LOCALE_DEFAULT) => {
26
22
  return (translatable) => resolveTranslatable(translatable, locale);
27
23
  };
@@ -3,9 +3,13 @@ import { getAllCookieIdsString, getCookieId } from "./methods.mjs";
3
3
  import { defineNuxtPlugin, useCookie } from "#imports";
4
4
  import moduleOptions from "#build/cookie-control-options";
5
5
  export default defineNuxtPlugin((_nuxtApp) => {
6
- const cookieIsConsentGiven = useCookie(moduleOptions.cookieNameIsConsentGiven);
6
+ const cookieIsConsentGiven = useCookie(
7
+ moduleOptions.cookieNameIsConsentGiven,
8
+ moduleOptions.cookieOptions
9
+ );
7
10
  const cookieCookiesEnabledIds = useCookie(
8
- moduleOptions.cookieNameCookiesEnabledIds
11
+ moduleOptions.cookieNameCookiesEnabledIds,
12
+ moduleOptions.cookieOptions
9
13
  ).value?.split("|");
10
14
  const isConsentGiven = ref(
11
15
  cookieIsConsentGiven === void 0 ? void 0 : cookieIsConsentGiven.value === getAllCookieIdsString(moduleOptions)
@@ -1,4 +1,5 @@
1
1
  import { Ref } from 'vue';
2
+ import { CookieOptions } from 'nuxt/app';
2
3
  export type Locale = 'ar' | 'az' | 'bg' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hr' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'nl' | 'no' | 'oc' | 'pt' | 'pl' | 'rs' | 'ru' | 'sk' | 'sv' | 'tr' | 'uk';
3
4
  export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
4
5
  export type Translatable = string | PartialRecord<Locale, string>;
@@ -42,16 +43,14 @@ export interface ModuleOptions {
42
43
  necessary: Cookie[];
43
44
  optional: Cookie[];
44
45
  };
45
- domain: string;
46
+ cookieOptions: CookieOptions;
46
47
  isAcceptNecessaryButtonEnabled: boolean;
47
48
  isControlButtonEnabled: boolean;
48
49
  isCookieIdVisible: boolean;
49
50
  isCssEnabled: boolean;
50
51
  isCssPonyfillEnabled: boolean;
51
52
  isDashInDescriptionEnabled: boolean;
52
- isIframeBlocked: boolean | {
53
- initialState: boolean;
54
- };
53
+ isIframeBlocked: boolean;
55
54
  isModalForced: boolean;
56
55
  locales: Locale[];
57
56
  localeTexts: PartialRecord<Locale, Partial<LocaleStrings>>;
@@ -43,6 +43,9 @@ export const DEFAULTS = {
43
43
  // one year
44
44
  cookieNameIsConsentGiven: "ncc_c",
45
45
  cookieNameCookiesEnabledIds: "ncc_e",
46
+ cookieOptions: {
47
+ path: "/"
48
+ },
46
49
  isAcceptNecessaryButtonEnabled: true,
47
50
  isControlButtonEnabled: true,
48
51
  isCookieIdVisible: false,
@@ -51,7 +54,6 @@ export const DEFAULTS = {
51
54
  isDashInDescriptionEnabled: true,
52
55
  isIframeBlocked: false,
53
56
  isModalForced: false,
54
- domain: "",
55
57
  locales: ["en"],
56
58
  localeTexts: { en }
57
59
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dargmuesli/nuxt-cookie-control",
3
- "version": "5.10.3",
4
- "description": "Nuxt Cookies Control Module",
3
+ "version": "6.0.0",
4
+ "description": "Nuxt Cookie Control Module",
5
5
  "author": "Dario Ferderber <dario.ferderber@broj42.com>",
6
6
  "maintainers": [
7
7
  "Jonas Thelemann"
@@ -18,7 +18,7 @@
18
18
  "engines": {
19
19
  "node": ">=16"
20
20
  },
21
- "packageManager": "pnpm@8.6.5",
21
+ "packageManager": "pnpm@8.6.7",
22
22
  "exports": {
23
23
  ".": {
24
24
  "import": "./dist/module.mjs",
@@ -35,11 +35,12 @@
35
35
  "scripts": {
36
36
  "build": "nuxt-module-build",
37
37
  "lint": "eslint --ext .js,.ts,.vue . && nuxt typecheck",
38
+ "lint:fix": "eslint --ext .js,.ts,.vue --fix . && nuxt typecheck --fix",
38
39
  "prepack": "pnpm build",
39
40
  "prepare": "husky install"
40
41
  },
41
42
  "dependencies": {
42
- "@nuxt/kit": "3.6.1",
43
+ "@nuxt/kit": "3.6.2",
43
44
  "@sindresorhus/slugify": "2.2.1",
44
45
  "css-vars-ponyfill": "2.4.8",
45
46
  "string-replace-loader": "3.1.0"
@@ -50,17 +51,17 @@
50
51
  "@dargmuesli/nuxt-cookie-control": "link:.",
51
52
  "@nuxt/module-builder": "0.4.0",
52
53
  "@nuxtjs/eslint-config-typescript": "12.0.0",
53
- "eslint": "8.43.0",
54
+ "eslint": "8.44.0",
54
55
  "eslint-config-prettier": "8.8.0",
55
- "eslint-plugin-prettier": "4.2.1",
56
+ "eslint-plugin-prettier": "5.0.0",
56
57
  "husky": "8.0.3",
57
- "lint-staged": "13.2.2",
58
- "nuxt": "3.6.1",
59
- "prettier": "2.8.8",
60
- "typescript": "5.1.3",
58
+ "lint-staged": "13.2.3",
59
+ "nuxt": "3.6.2",
60
+ "prettier": "3.0.0",
61
+ "typescript": "5.1.6",
61
62
  "vue": "3.3.4",
62
- "vue-tsc": "1.8.2",
63
- "webpack": "5.88.0"
63
+ "vue-tsc": "1.8.4",
64
+ "webpack": "5.88.1"
64
65
  },
65
66
  "publishConfig": {
66
67
  "access": "public"