@dargmuesli/nuxt-cookie-control 2.0.0-beta.6 → 2.0.0-beta.7
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.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
|
11
11
|
const __dirname = __cjs_path__.dirname(__filename);
|
|
12
12
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
13
13
|
const name = "@dargmuesli/nuxt-cookie-control";
|
|
14
|
-
const version = "2.0.0-beta.
|
|
14
|
+
const version = "2.0.0-beta.7";
|
|
15
15
|
|
|
16
16
|
const en = {
|
|
17
17
|
acceptAll: "Accept all",
|
|
@@ -85,8 +85,7 @@
|
|
|
85
85
|
type="checkbox"
|
|
86
86
|
:checked="
|
|
87
87
|
cookiesEnabledIds.includes(getCookieId(cookie)) ||
|
|
88
|
-
(
|
|
89
|
-
0 &&
|
|
88
|
+
(getCookieControlConsent()?.length === 0 &&
|
|
90
89
|
typeof moduleOptions.isIframeBlocked === 'object' &&
|
|
91
90
|
moduleOptions.isIframeBlocked.initialState)
|
|
92
91
|
"
|
|
@@ -127,7 +126,9 @@
|
|
|
127
126
|
v-text="localeStrings?.acceptAll"
|
|
128
127
|
/>
|
|
129
128
|
<button
|
|
130
|
-
@click="
|
|
129
|
+
@click="
|
|
130
|
+
setConsent({ declineAll: true, isConsentGiven: false })
|
|
131
|
+
"
|
|
131
132
|
v-text="localeStrings?.declineAll"
|
|
132
133
|
/>
|
|
133
134
|
</div>
|
|
@@ -140,15 +141,16 @@
|
|
|
140
141
|
</template>
|
|
141
142
|
|
|
142
143
|
<script setup lang="ts">
|
|
143
|
-
import Cookies from 'js-cookie'
|
|
144
144
|
import { ref, computed, onBeforeMount } from 'vue'
|
|
145
145
|
|
|
146
146
|
import { Cookie, CookieType, Locale, Translatable } from '../types'
|
|
147
147
|
import {
|
|
148
|
+
getCookieControlConsent,
|
|
148
149
|
getCookieId,
|
|
149
150
|
useAcceptNecessary,
|
|
150
151
|
useSetConsent,
|
|
151
152
|
useResolveTranslatable,
|
|
153
|
+
setCookies,
|
|
152
154
|
} from '../methods'
|
|
153
155
|
|
|
154
156
|
import { useCookieControl } from '#imports'
|
|
@@ -187,34 +189,31 @@ const toogleCookie = (cookie: Cookie) => {
|
|
|
187
189
|
}
|
|
188
190
|
const setConsent = ({
|
|
189
191
|
type = undefined,
|
|
190
|
-
|
|
192
|
+
isConsentGiven = true,
|
|
191
193
|
reload = true,
|
|
192
194
|
declineAll = false,
|
|
193
195
|
}: {
|
|
194
196
|
type?: 'partial'
|
|
195
|
-
|
|
197
|
+
isConsentGiven?: boolean
|
|
196
198
|
reload?: boolean
|
|
197
199
|
declineAll?: boolean
|
|
198
200
|
}) => {
|
|
199
|
-
const
|
|
201
|
+
const cookieIds = declineAll
|
|
200
202
|
? []
|
|
201
|
-
: type === 'partial' &&
|
|
203
|
+
: type === 'partial' && isConsentGiven
|
|
202
204
|
? cookiesEnabledIds.value
|
|
203
|
-
: moduleOptions.cookies.optional.map((cookie) =>
|
|
205
|
+
: moduleOptions.cookies.optional.map((cookie: Cookie) =>
|
|
206
|
+
getCookieId(cookie)
|
|
207
|
+
)
|
|
204
208
|
|
|
205
209
|
const expirationDate = new Date()
|
|
206
210
|
expirationDate.setFullYear(expirationDate.getFullYear() + 1)
|
|
207
211
|
|
|
208
|
-
|
|
212
|
+
setCookies({
|
|
213
|
+
isConsentGiven,
|
|
214
|
+
cookieIds,
|
|
209
215
|
expires: expirationDate,
|
|
210
216
|
})
|
|
211
|
-
Cookies.set(
|
|
212
|
-
'cookie_control_enabled_cookies',
|
|
213
|
-
consent ? enabledCookies.join(',') : '',
|
|
214
|
-
{
|
|
215
|
-
expires: expirationDate,
|
|
216
|
-
}
|
|
217
|
-
)
|
|
218
217
|
|
|
219
218
|
if (reload) {
|
|
220
219
|
window.location.reload()
|
|
@@ -258,7 +257,7 @@ onBeforeMount(async () => {
|
|
|
258
257
|
}
|
|
259
258
|
}
|
|
260
259
|
|
|
261
|
-
const cookieControlConsent =
|
|
260
|
+
const cookieControlConsent = getCookieControlConsent()
|
|
262
261
|
|
|
263
262
|
if (!cookieControlConsent || !cookieControlConsent.length) {
|
|
264
263
|
for (const cookieOptional of moduleOptions.cookies.optional) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
{{ localeStrings?.blockedIframe }}
|
|
7
7
|
<a
|
|
8
8
|
href="#"
|
|
9
|
-
@click.prevent="
|
|
9
|
+
@click.prevent="isModalActive = true"
|
|
10
10
|
v-text="localeStrings?.here"
|
|
11
11
|
/>
|
|
12
12
|
</p>
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { computed } from 'vue'
|
|
19
19
|
|
|
20
20
|
import { LOCALE_DEFAULT } from '../constants'
|
|
21
|
-
import { Locale } from '../types'
|
|
21
|
+
import { Cookie, Locale } from '../types'
|
|
22
22
|
|
|
23
23
|
import { useCookieControl } from '#imports'
|
|
24
24
|
|
|
@@ -29,15 +29,14 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
29
29
|
locale: LOCALE_DEFAULT,
|
|
30
30
|
})
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const { cookiesEnabled, isModalActive, moduleOptions } = useCookieControl()
|
|
33
33
|
|
|
34
34
|
// computations
|
|
35
35
|
const isCookieFunctionalEnabled = computed(
|
|
36
36
|
() =>
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
)
|
|
40
|
-
const localeStrings = computed(
|
|
41
|
-
() => cookieControl.moduleOptions.localeTexts[props.locale]
|
|
37
|
+
cookiesEnabled.value.filter(
|
|
38
|
+
(cookieEnabled: Cookie) => cookieEnabled.name === 'functional'
|
|
39
|
+
).length > 0
|
|
42
40
|
)
|
|
41
|
+
const localeStrings = computed(() => moduleOptions.localeTexts[props.locale])
|
|
43
42
|
</script>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Ref } from 'vue';
|
|
2
2
|
import { Cookie, ModuleOptions, Translatable } from './types';
|
|
3
3
|
export declare const useAcceptNecessary: () => () => void;
|
|
4
|
-
export declare const acceptNecessary: (
|
|
4
|
+
export declare const acceptNecessary: (cookiesEnabledRef: Ref<Cookie[]>, isConsentGivenRef: Ref<boolean>, cookiesNecessary?: Cookie[]) => void;
|
|
5
5
|
export declare const useResolveTranslatable: (locale?: import("./types").Locale) => (translatable: Translatable) => string;
|
|
6
6
|
export declare const useSetConsent: () => () => void;
|
|
7
7
|
export declare const setConsent: ({ isInit, isConsentGiven, moduleOptions, cookiesEnabled, cookiesEnabledIds, }: {
|
|
@@ -11,6 +11,12 @@ export declare const setConsent: ({ isInit, isConsentGiven, moduleOptions, cooki
|
|
|
11
11
|
cookiesEnabled: Ref<Cookie[]>;
|
|
12
12
|
cookiesEnabledIds: Ref<string[]>;
|
|
13
13
|
}) => void;
|
|
14
|
+
export declare const getCookieControlConsent: () => any;
|
|
14
15
|
export declare const getCookieId: (cookie: Cookie) => string;
|
|
15
16
|
export declare const clearCookies: (cookiesEnabledIds: string[], cookiesOptional: Cookie[]) => void;
|
|
16
17
|
export declare const setHead: (enabledCookies: Cookie[]) => void;
|
|
18
|
+
export declare const setCookies: ({ isConsentGiven, cookieIds, expires, }: {
|
|
19
|
+
isConsentGiven: boolean;
|
|
20
|
+
cookieIds: string[];
|
|
21
|
+
expires: Date;
|
|
22
|
+
}) => void;
|
package/dist/runtime/methods.mjs
CHANGED
|
@@ -10,19 +10,20 @@ export const useAcceptNecessary = () => {
|
|
|
10
10
|
moduleOptions.cookies?.necessary
|
|
11
11
|
);
|
|
12
12
|
};
|
|
13
|
-
export const acceptNecessary = (
|
|
13
|
+
export const acceptNecessary = (cookiesEnabledRef, isConsentGivenRef, cookiesNecessary = []) => {
|
|
14
14
|
const expires = new Date();
|
|
15
15
|
expires.setFullYear(expires.getFullYear() + 1);
|
|
16
|
-
const necessaryCookieIds =
|
|
16
|
+
const necessaryCookieIds = cookiesNecessary.map(
|
|
17
17
|
(necessaryCookie) => getCookieId(necessaryCookie)
|
|
18
18
|
);
|
|
19
|
-
|
|
19
|
+
setCookies({
|
|
20
|
+
isConsentGiven: isConsentGivenRef.value,
|
|
21
|
+
cookieIds: necessaryCookieIds,
|
|
20
22
|
expires
|
|
21
23
|
});
|
|
22
|
-
|
|
23
|
-
consent.value = true;
|
|
24
|
+
isConsentGivenRef.value = true;
|
|
24
25
|
if (process.client) {
|
|
25
|
-
setHead(
|
|
26
|
+
setHead(cookiesEnabledRef.value);
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
export const useResolveTranslatable = (locale = LOCALE_DEFAULT) => {
|
|
@@ -68,8 +69,8 @@ export const setConsent = ({
|
|
|
68
69
|
}
|
|
69
70
|
if (moduleOptions.cookies?.necessary)
|
|
70
71
|
cookiesEnabled.value.push(
|
|
71
|
-
...moduleOptions.cookies.necessary.filter((
|
|
72
|
-
return
|
|
72
|
+
...moduleOptions.cookies.necessary.filter((cookieNecessary) => {
|
|
73
|
+
return cookieNecessary.src;
|
|
73
74
|
})
|
|
74
75
|
);
|
|
75
76
|
cookiesEnabledIds.value = cookiesEnabled.value.map(
|
|
@@ -83,6 +84,7 @@ export const setConsent = ({
|
|
|
83
84
|
);
|
|
84
85
|
}
|
|
85
86
|
};
|
|
87
|
+
export const getCookieControlConsent = () => Cookies.get("cookie_control_consent");
|
|
86
88
|
export const getCookieId = (cookie) => cookie.id || slugify(resolveTranslatable(cookie.name));
|
|
87
89
|
export const clearCookies = (cookiesEnabledIds, cookiesOptional) => {
|
|
88
90
|
const cookiesDisabled = cookiesOptional.filter(
|
|
@@ -115,3 +117,19 @@ export const setHead = (enabledCookies) => {
|
|
|
115
117
|
head.appendChild(script);
|
|
116
118
|
}
|
|
117
119
|
};
|
|
120
|
+
export const setCookies = ({
|
|
121
|
+
isConsentGiven,
|
|
122
|
+
cookieIds,
|
|
123
|
+
expires
|
|
124
|
+
}) => {
|
|
125
|
+
Cookies.set(
|
|
126
|
+
"cookie_control_enabled_cookies",
|
|
127
|
+
isConsentGiven ? cookieIds.join(",") : "",
|
|
128
|
+
{
|
|
129
|
+
expires
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
Cookies.set("cookie_control_consent", isConsentGiven.toString(), {
|
|
133
|
+
expires
|
|
134
|
+
});
|
|
135
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dargmuesli/nuxt-cookie-control",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.7",
|
|
4
4
|
"description": "Nuxt Cookies Control Module",
|
|
5
5
|
"author": "Dario Ferderber <dario.ferderber@broj42.com>",
|
|
6
6
|
"maintainers": [
|
|
@@ -52,25 +52,12 @@
|
|
|
52
52
|
"husky": "8.0.2",
|
|
53
53
|
"lint-staged": "13.1.0",
|
|
54
54
|
"nuxt": "3.0.0",
|
|
55
|
-
"prettier": "2.8.
|
|
56
|
-
"typescript": "4.9.
|
|
57
|
-
"vite": "3.2.5",
|
|
55
|
+
"prettier": "2.8.1",
|
|
56
|
+
"typescript": "4.9.4",
|
|
58
57
|
"vue": "3.2.45",
|
|
59
|
-
"vue-tsc": "1.0.
|
|
58
|
+
"vue-tsc": "1.0.12",
|
|
60
59
|
"webpack": "5.75.0"
|
|
61
60
|
},
|
|
62
|
-
"peerDependencies": {
|
|
63
|
-
"vite": "^3",
|
|
64
|
-
"webpack": "^5"
|
|
65
|
-
},
|
|
66
|
-
"peerDependenciesMeta": {
|
|
67
|
-
"vite": {
|
|
68
|
-
"optional": true
|
|
69
|
-
},
|
|
70
|
-
"webpack": {
|
|
71
|
-
"optional": true
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
61
|
"resolutions": {
|
|
75
62
|
"@dargmuesli/nuxt-cookie-control": "link:./"
|
|
76
63
|
},
|