@leancodepl/cookie-consent 9.7.2 → 9.7.4
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/CHANGELOG.md +18 -0
- package/LICENSE +201 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +971 -0
- package/dist/index.umd.cjs +1 -0
- package/{src → dist}/lib/config.d.ts +1 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/{src → dist}/lib/getDefaultConsentConfig.d.ts +2 -1
- package/dist/lib/getDefaultConsentConfig.d.ts.map +1 -0
- package/{src → dist}/lib/getGoogleConsent.d.ts +1 -0
- package/dist/lib/getGoogleConsent.d.ts.map +1 -0
- package/{src → dist}/lib/runCookieConsent.d.ts +2 -1
- package/dist/lib/runCookieConsent.d.ts.map +1 -0
- package/package.json +19 -6
- package/src/index.d.ts +0 -2
- package/src/index.js +0 -3
- package/src/index.js.map +0 -1
- package/src/lib/config.js +0 -218
- package/src/lib/config.js.map +0 -1
- package/src/lib/getDefaultConsentConfig.js +0 -70
- package/src/lib/getDefaultConsentConfig.js.map +0 -1
- package/src/lib/getGoogleConsent.js +0 -43
- package/src/lib/getGoogleConsent.js.map +0 -1
- package/src/lib/runCookieConsent.js +0 -169
- package/src/lib/runCookieConsent.js.map +0 -1
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import * as CookieConsent from "vanilla-cookieconsent";
|
|
2
|
-
import { catAnalytics, catNecessary, getGoogleConsent, } from "./getGoogleConsent";
|
|
3
|
-
function getCookieConsentConfig(config) {
|
|
4
|
-
const { categories, onFirstConsent, onChange, onConsent, ...rest } = config;
|
|
5
|
-
const supportedServices = Object.values(categories).flatMap(category => Object.keys(category.services ?? {}));
|
|
6
|
-
const { setDefaultConsent, updateConsent } = getGoogleConsent();
|
|
7
|
-
setDefaultConsent(supportedServices);
|
|
8
|
-
const cookieConsentConfig = {
|
|
9
|
-
onFirstConsent: params => {
|
|
10
|
-
updateConsent(supportedServices);
|
|
11
|
-
onFirstConsent?.(params);
|
|
12
|
-
},
|
|
13
|
-
onConsent: params => {
|
|
14
|
-
updateConsent(supportedServices);
|
|
15
|
-
onConsent?.(params);
|
|
16
|
-
},
|
|
17
|
-
onChange: params => {
|
|
18
|
-
updateConsent(supportedServices);
|
|
19
|
-
onChange?.(params);
|
|
20
|
-
},
|
|
21
|
-
categories: {
|
|
22
|
-
[catNecessary]: {
|
|
23
|
-
enabled: true,
|
|
24
|
-
readOnly: true,
|
|
25
|
-
...(categories[catNecessary] ?? {}),
|
|
26
|
-
},
|
|
27
|
-
[catAnalytics]: {
|
|
28
|
-
autoClear: {
|
|
29
|
-
cookies: [{ name: /^_ga/ }, { name: "_gid" }],
|
|
30
|
-
},
|
|
31
|
-
...(categories[catAnalytics] ?? {}),
|
|
32
|
-
},
|
|
33
|
-
...categories,
|
|
34
|
-
},
|
|
35
|
-
...rest,
|
|
36
|
-
};
|
|
37
|
-
return cookieConsentConfig;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Runs cookie consent and synchronizes consent state with Google via `"@leancodepl/gtag"`.
|
|
41
|
-
*
|
|
42
|
-
* This function derives supported Google consent services from the provided `categories.services`
|
|
43
|
-
* and automatically calls Google consent APIs on first consent, consent, and change events while
|
|
44
|
-
* preserving any user-provided handlers.
|
|
45
|
-
*
|
|
46
|
-
* @param config - Cookie consent configuration that mirrors `vanilla-cookieconsent` options, with a strongly-typed
|
|
47
|
-
* `categories` shape. All non-`categories` fields pass through to `vanilla-cookieconsent` unchanged.
|
|
48
|
-
* For complete configuration details, see the vanilla-cookieconsent documentation: https://cookieconsent.orestbida.com/
|
|
49
|
-
* @returns The `vanilla-cookieconsent` module instance after initialization
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
runCookieConsent({
|
|
53
|
-
categories: {
|
|
54
|
-
analytics: {
|
|
55
|
-
services: {
|
|
56
|
-
analytics_storage: {
|
|
57
|
-
label:
|
|
58
|
-
'Enables storage (such as cookies) related to analytics e.g. visit duration.'
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
guiOptions: {
|
|
64
|
-
consentModal: {
|
|
65
|
-
layout: 'box wide',
|
|
66
|
-
position: 'bottom right'
|
|
67
|
-
},
|
|
68
|
-
preferencesModal: {
|
|
69
|
-
layout: 'box'
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
language: {
|
|
73
|
-
default: 'en',
|
|
74
|
-
translations: {
|
|
75
|
-
en: {
|
|
76
|
-
consentModal: {
|
|
77
|
-
title: 'We use cookies',
|
|
78
|
-
description:
|
|
79
|
-
'This website uses essential cookies to ensure its proper operation and tracking cookies to understand how you interact with it. The latter will be set only after consent.',
|
|
80
|
-
acceptAllBtn: 'Accept all',
|
|
81
|
-
acceptNecessaryBtn: 'Reject all',
|
|
82
|
-
showPreferencesBtn: 'Manage Individual preferences'
|
|
83
|
-
},
|
|
84
|
-
preferencesModal: {
|
|
85
|
-
title: 'Manage cookie preferences',
|
|
86
|
-
acceptAllBtn: 'Accept all',
|
|
87
|
-
acceptNecessaryBtn: 'Reject all',
|
|
88
|
-
savePreferencesBtn: 'Accept current selection',
|
|
89
|
-
closeIconLabel: 'Close modal',
|
|
90
|
-
sections: [
|
|
91
|
-
{
|
|
92
|
-
title: 'Cookie usage',
|
|
93
|
-
description:
|
|
94
|
-
'We use cookies to ensure the basic functionalities of the website and to enhance your online experience.'
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
title: 'Strictly necessary cookies',
|
|
98
|
-
description:
|
|
99
|
-
'These cookies are essential for the proper functioning of the website, for example for user authentication.',
|
|
100
|
-
linkedCategory: 'necessary'
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
title: 'Analytics',
|
|
104
|
-
description:
|
|
105
|
-
'Cookies used for analytics help collect data that allows services to understand how users interact with a particular service. These insights allow services both to improve content and to build better features that improve the user’s experience.',
|
|
106
|
-
linkedCategory: 'analytics',
|
|
107
|
-
cookieTable: {
|
|
108
|
-
headers: {
|
|
109
|
-
name: 'Name',
|
|
110
|
-
domain: 'Service',
|
|
111
|
-
description: 'Description',
|
|
112
|
-
expiration: 'Expiration'
|
|
113
|
-
},
|
|
114
|
-
body: [
|
|
115
|
-
{
|
|
116
|
-
name: '_ga',
|
|
117
|
-
domain: 'Google Analytics',
|
|
118
|
-
description:
|
|
119
|
-
'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
|
|
120
|
-
expiration: 'Expires after 12 days'
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
name: '_gid',
|
|
124
|
-
domain: 'Google Analytics',
|
|
125
|
-
description:
|
|
126
|
-
'Cookie set by <a href="https://business.safety.google/adscookies/">Google Analytics</a>',
|
|
127
|
-
expiration: 'Session'
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
title: 'Advertising',
|
|
134
|
-
description:
|
|
135
|
-
'Google uses cookies for advertising, including serving and rendering ads, personalizing ads (depending on your ad settings at <a href=\"https://g.co/adsettings\">g.co/adsettings</a>), limiting the number of times an ad is shown to a user, muting ads you have chosen to stop seeing, and measuring the effectiveness of ads.',
|
|
136
|
-
linkedCategory: 'advertising'
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
title: 'Functionality',
|
|
140
|
-
description:
|
|
141
|
-
'Cookies used for functionality allow users to interact with a service or site to access features that are fundamental to that service. Things considered fundamental to the service include preferences like the user’s choice of language, product optimizations that help maintain and improve a service, and maintaining information relating to a user’s session, such as the content of a shopping cart.',
|
|
142
|
-
linkedCategory: 'functionality'
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
title: 'Security',
|
|
146
|
-
description:
|
|
147
|
-
'Cookies used for security authenticate users, prevent fraud, and protect users as they interact with a service.',
|
|
148
|
-
linkedCategory: 'security'
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
title: 'More information',
|
|
152
|
-
description:
|
|
153
|
-
'For any queries in relation to the policy on cookies and your choices, please <a href="https://www.example.com/contacts">contact us</a>.'
|
|
154
|
-
}
|
|
155
|
-
]
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
})
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
export async function runCookieConsent(config) {
|
|
164
|
-
const cookieConsent = CookieConsent;
|
|
165
|
-
const cookieConsentConfig = getCookieConsentConfig(config);
|
|
166
|
-
await cookieConsent.run(cookieConsentConfig);
|
|
167
|
-
return cookieConsent;
|
|
168
|
-
}
|
|
169
|
-
//# sourceMappingURL=runCookieConsent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runCookieConsent.js","sourceRoot":"","sources":["../../../../../packages/cookie-consent/src/lib/runCookieConsent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,uBAAuB,CAAA;AACtD,OAAO,EACL,YAAY,EAEZ,YAAY,EACZ,gBAAgB,GAGjB,MAAM,oBAAoB,CAAA;AAqB3B,SAAS,sBAAsB,CAAC,MAA2B;IACzD,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAA;IAC3E,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CACrE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,EAAE,CAAC,CACrB,CAAA;IAEjB,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,GAAG,gBAAgB,EAAE,CAAA;IAC/D,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;IAEpC,MAAM,mBAAmB,GAAsC;QAC7D,cAAc,EAAE,MAAM,CAAC,EAAE;YACvB,aAAa,CAAC,iBAAi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