@dargmuesli/nuxt-cookie-control 5.10.4 → 6.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.
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
- ✅ 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
7
+ ✅ Translated for: ar, az, bg, cs, da, de, en, es, fi, fr, hr, hu, it, ja, ko, lt, nl, no, oc, pt, pl, ro, 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,6 +1,7 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { CookieOptions } from 'nuxt/app';
2
3
 
3
- 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
+ type Locale = 'ar' | 'az' | 'bg' | 'cs' | 'da' | 'de' | 'en' | 'es' | 'fi' | 'fr' | 'hr' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'nl' | 'no' | 'oc' | 'pt' | 'pl' | 'ro' | 'rs' | 'ru' | 'sk' | 'sv' | 'tr' | 'uk';
4
5
  type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
5
6
  type Translatable = string | PartialRecord<Locale, string>;
6
7
  interface Cookie {
@@ -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.4",
3
+ "version": "6.1.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.4";
6
+ const version = "6.1.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) {
@@ -95,11 +95,7 @@
95
95
  :checked="
96
96
  getCookieIds(localCookiesEnabled).includes(
97
97
  getCookieId(cookie),
98
- ) ||
99
- (cookieIsConsentGiven !== allCookieIdsString &&
100
- typeof moduleOptions.isIframeBlocked ===
101
- 'object' &&
102
- moduleOptions.isIframeBlocked.initialState)
98
+ )
103
99
  "
104
100
  @change="toogleCookie(cookie)"
105
101
  />
@@ -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
226
  moduleOptions.cookieNameCookiesEnabledIds,
227
+ {
228
+ expires,
229
+ ...moduleOptions.cookieOptions,
230
+ },
228
231
  )
229
232
 
230
233
  // computations
@@ -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
@@ -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
@@ -406,13 +396,7 @@ 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>
@@ -19,6 +19,7 @@ import no from "./no.mjs";
19
19
  import oc from "./oc.mjs";
20
20
  import pt from "./pt.mjs";
21
21
  import pl from "./pl.mjs";
22
+ import ro from "./ro.mjs";
22
23
  import rs from "./rs.mjs";
23
24
  import ru from "./ru.mjs";
24
25
  import sk from "./sk.mjs";
@@ -47,6 +48,7 @@ export const locales = [
47
48
  oc,
48
49
  pt,
49
50
  pl,
51
+ ro,
50
52
  rs,
51
53
  ru,
52
54
  sk,
@@ -0,0 +1,3 @@
1
+ import { LocaleStrings } from '../types';
2
+ declare const _default: LocaleStrings;
3
+ export default _default;
@@ -0,0 +1,17 @@
1
+ export default {
2
+ accept: "Accept\u0103",
3
+ acceptAll: "Accept\u0103 toate",
4
+ bannerDescription: "Utiliz\u0103m propriile noastre cookie-uri \u0219i cookie-uri ale ter\u021Bilor pentru a afi\u0219a corect acest site web \u0219i pentru a \xEEn\u021Belege mai bine modul \xEEn care este utilizat acest site web, cu scopul de a \xEEmbun\u0103t\u0103\u021Bi serviciile pe care le oferim. Decizia cu privire la permisiunile de utilizare a cookie-urilor poate fi modificat\u0103 \xEEn orice moment folosind butonul de cookie-uri care va ap\u0103rea dup\u0103 ce a\u021Bi f\u0103cut o selec\u021Bie pe aceast\u0103 banner.",
5
+ bannerTitle: "Cookie-uri",
6
+ close: "\xCEnchide",
7
+ cookiesFunctional: "Cookie-uri func\u021Bionale",
8
+ cookiesNecessary: "Cookie-uri necesare",
9
+ cookiesOptional: "Cookie-uri op\u021Bionale",
10
+ decline: "Declin\u0103",
11
+ declineAll: "Declin\u0103 toate",
12
+ here: "aici",
13
+ iframeBlocked: "Pentru a vedea aceasta, activeaz\u0103 cookie-urile func\u021Bionale",
14
+ manageCookies: "Afl\u0103 mai multe \u0219i configureaz\u0103",
15
+ save: "Salveaz\u0103",
16
+ settingsUnsaved: "Ai set\u0103ri nesalvate"
17
+ };
@@ -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,5 +1,6 @@
1
1
  import { Ref } from 'vue';
2
- 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';
2
+ import { CookieOptions } from 'nuxt/app';
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' | 'ro' | '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>;
5
6
  export declare enum CookieType {
@@ -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.4",
4
- "description": "Nuxt Cookies Control Module",
3
+ "version": "6.1.0",
4
+ "description": "Nuxt Cookie Control Module",
5
5
  "author": "Dario Ferderber <dario.ferderber@broj42.com>",
6
6
  "maintainers": [
7
7
  "Jonas Thelemann"