@commercetools-frontend/cookie-consent 0.0.0-FEC-212-react19-20250122084835
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/LICENSE +21 -0
- package/README.md +143 -0
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.d.ts +2 -0
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.dev.js +190 -0
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.js +7 -0
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.prod.js +190 -0
- package/core/dist/commercetools-frontend-cookie-consent-core.esm.js +164 -0
- package/core/package.json +4 -0
- package/dist/declarations/src/core/index.d.ts +35 -0
- package/dist/declarations/src/react/cookie-consent-banner/cookie-consent-banner.d.ts +8 -0
- package/dist/declarations/src/react/cookie-consent-banner/index.d.ts +1 -0
- package/dist/declarations/src/react/cookie-consent-modal/cookie-consent-modal.d.ts +7 -0
- package/dist/declarations/src/react/cookie-consent-modal/index.d.ts +1 -0
- package/dist/declarations/src/react/index.d.ts +4 -0
- package/dist/declarations/src/react/use-cookie-consent/index.d.ts +1 -0
- package/dist/declarations/src/react/use-cookie-consent/use-cookie-consent.d.ts +10 -0
- package/dist/declarations/src/react/use-skip-cookie-consent/index.d.ts +1 -0
- package/dist/declarations/src/react/use-skip-cookie-consent/use-skip-cookie-consent.d.ts +2 -0
- package/package.json +67 -0
- package/react/dist/commercetools-frontend-cookie-consent-react.cjs.d.ts +2 -0
- package/react/dist/commercetools-frontend-cookie-consent-react.cjs.dev.js +818 -0
- package/react/dist/commercetools-frontend-cookie-consent-react.cjs.js +7 -0
- package/react/dist/commercetools-frontend-cookie-consent-react.cjs.prod.js +796 -0
- package/react/dist/commercetools-frontend-cookie-consent-react.esm.js +791 -0
- package/react/package.json +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) commercetools GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @commercetools-frontend/cookie-consent
|
|
2
|
+
|
|
3
|
+
> This is a package used internally for Merchant Center applications. We do not provide any guarantees or support for the functionality.
|
|
4
|
+
|
|
5
|
+
This package provides an easy to use integration with OneTrust cookie consent.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ npm install --save @commercetools-frontend/cookie-consent
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Background
|
|
14
|
+
|
|
15
|
+
Cookie consent is given from a user towards a company as the legal entity for all of its products not for every single product. Consent via OneTrust is can be given on a marketing website for instance commercetools.com. The OneTrust cookie banner supports opting out of certain categories of cookies or revoking consent entirely.
|
|
16
|
+
|
|
17
|
+
The resulting cookie stored in a user's browser is called `OptanonConsent`. The contents of those cookie can be of the following:
|
|
18
|
+
|
|
19
|
+
```txt
|
|
20
|
+
isGpcEnabled=0&datestamp=Wed+Feb+01+2023+12%3A35%3A32+GMT%2B0100+(Central+European+Standard+Time)&version=202209.1.0&isIABGlobal=false&hosts=&consentId=7f3cf16d-b3e1-4781-8db1-61482d0a9dff&interactionCount=1&landingPath=NotLandingPage&groups=C0001%3A1%2CC0002%3A0%2CC0003%3A1%2CC0004%3A1%2CC0005%3A1&geolocation=AT%3B9&AwaitingReconsent=false
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The cookie will be removed after 365 days yielding repeated consent to be requested by the user on our marketing website. The cookie itself is URL encoded and can be parsed using `URLSearchParams`. The field of interest is `groups`. These are the groups for which consent was granted or not:
|
|
24
|
+
|
|
25
|
+
1. EssentialCookies: 'C0001'
|
|
26
|
+
2. PerformanceCookies: 'C0002'
|
|
27
|
+
3. FunctionalCookies: 'C0003'
|
|
28
|
+
4. TargetingCookies: 'C0004'
|
|
29
|
+
5. SocialMediaCookies: 'C0005'
|
|
30
|
+
|
|
31
|
+
This package parses the cookie if present and returns consent for groups given or revoked.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Retrieving consent values
|
|
36
|
+
|
|
37
|
+
This package does not make assumptions what framework you use. To integrate without any assumptions about the framework use the `/core` entry point:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { getParsedConsentCookieGroups } from '@commercetools-frontend/cookie-consent/core';
|
|
41
|
+
|
|
42
|
+
const consentGroups = getParsedConsentCookieGroups();
|
|
43
|
+
// { essentialCookies: true, performanceCookies: false }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If there is ever a need to use the raw consent cookie's value itself you can retrieve it too:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { getRawConsentCookie } from '@commercetools-frontend/cookie-consent/core';
|
|
50
|
+
|
|
51
|
+
const rawConsentCookie = getRawConsentCookie();
|
|
52
|
+
// The value of the `OptanonConsent` cookie
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Knowing the consent groups you can use a constant to easily map them onto something easier to understand:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import { getParsedConsentCookieGroups } from '@commercetools-frontend/cookie-consent/core';
|
|
59
|
+
|
|
60
|
+
const consentGroups = getParsedConsentCookieGroups();
|
|
61
|
+
const hasGivenPerformanceCookieConsent = Boolean(
|
|
62
|
+
consentGroups.performanceCookies
|
|
63
|
+
);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
You can also use the `useCookieConsent` from the `/react` entry point of the package.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import { useCookieConsent } from '@commercetools-frontend/cookie-consent/react';
|
|
70
|
+
|
|
71
|
+
const { givenConsent } = useCookieConsent('performanceCookies');
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Note also that in certain cases (e.g. a staging environment) you may want to skip cookie consent entirely. To do so you can use the `skipConsent` option:
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
const { givenConsent } = useCookieConsent('performanceCookies', {
|
|
78
|
+
skipConsent: true,
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The preferred value of `skipConsent` can be determined for instance by an environment variable and read using the `useSkipCookieConsent` hook.
|
|
83
|
+
|
|
84
|
+
The resulting `givenConsent` value is a boolean which can be passed to any software needing consent for instance FullStory. A combination of `@commercetools-frontend/cookie-consent` and `@commercetools-frontend/fullstory` could look like this:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const { givenConsent } = useCookieConsent('performanceCookies');
|
|
88
|
+
|
|
89
|
+
useFullStoryTrackingEffect({ disable: !givenConsent });
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Setting consent values
|
|
93
|
+
|
|
94
|
+
To integrate without any assumptions about the framework again, use the `/core` entry point:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
import { setConsentCookie } from '@commercetools-frontend/cookie-consent/core';
|
|
98
|
+
|
|
99
|
+
setConsentCookie({ performanceCookieConsent: true });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Setting a cookie also accepts a `domain` as a second argument. This value defaults to `.commercetools.com` but can also be influenced using the `additionalEnv` when building a Custom Application:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
additionalEnv: {
|
|
106
|
+
cookieConsentDomain: '${env:COOKIE_CONSENT_DOMAIN}',
|
|
107
|
+
},
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Whenever you are not building a Custom Application you can define the `window.app.cookieConsentDomain` instead.
|
|
111
|
+
|
|
112
|
+
When needing to set a cookie you can use the `useCookieConsent` from the `/react` entry point of the package.
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import { useCookieConsent } from '@commercetools-frontend/cookie-consent/react';
|
|
116
|
+
|
|
117
|
+
const { setConsent } = useCookieConsent('performanceCookies');
|
|
118
|
+
|
|
119
|
+
// For instance in an `onClick` hander you can
|
|
120
|
+
<button onClick={() => setConsent({ performanceCookieConsent: true })}>
|
|
121
|
+
Update cookie consent
|
|
122
|
+
</button>;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Showing a consent banner
|
|
126
|
+
|
|
127
|
+
You can render the `CookieConsentBanner` to show a consent banner.
|
|
128
|
+
|
|
129
|
+
```jsx
|
|
130
|
+
import { CookieConsentBanner } from '@commercetools-frontend/cookie-consent/react';
|
|
131
|
+
|
|
132
|
+
<CookieConsentBanner />;
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Showing a consent modal
|
|
136
|
+
|
|
137
|
+
You can render the `CookieConsentModal` to open a consent modal. Upon interaction with the modal a cookie will be written in accordance with the consent groups selected.
|
|
138
|
+
|
|
139
|
+
```jsx
|
|
140
|
+
import { CookieConsentModal } from '@commercetools-frontend/cookie-consent/react';
|
|
141
|
+
|
|
142
|
+
<CookieConsentModal />;
|
|
143
|
+
```
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/core/index.js";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy1mcm9udGVuZC1jb29raWUtY29uc2VudC1jb3JlLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vZGlzdC9kZWNsYXJhdGlvbnMvc3JjL2NvcmUvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
6
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
7
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
8
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
9
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
10
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
11
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
12
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
13
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
14
|
+
var _Object$fromEntries = require('@babel/runtime-corejs3/core-js-stable/object/from-entries');
|
|
15
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
16
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
17
|
+
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
18
|
+
var _URLSearchParams = require('@babel/runtime-corejs3/core-js-stable/url-search-params');
|
|
19
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
20
|
+
|
|
21
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
22
|
+
|
|
23
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
24
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
25
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
26
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
27
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
28
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
29
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
30
|
+
var _Object$fromEntries__default = /*#__PURE__*/_interopDefault(_Object$fromEntries);
|
|
31
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
32
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
33
|
+
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
34
|
+
var _URLSearchParams__default = /*#__PURE__*/_interopDefault(_URLSearchParams);
|
|
35
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
36
|
+
|
|
37
|
+
var _context2;
|
|
38
|
+
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
39
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context7, _context8; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context7 = ownKeys(Object(t), !0)).call(_context7, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context8 = ownKeys(Object(t))).call(_context8, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
40
|
+
const COOKIE_CONSENT_GROUPS = {
|
|
41
|
+
essentialCookies: 'C0001',
|
|
42
|
+
performanceCookies: 'C0002',
|
|
43
|
+
functionalCookies: 'C0003',
|
|
44
|
+
targetingCookies: 'C0004',
|
|
45
|
+
socialMediaCookies: 'C0005'
|
|
46
|
+
};
|
|
47
|
+
const CONSENT_COOKIE_NAME = 'OptanonConsent';
|
|
48
|
+
function getRawConsentCookie() {
|
|
49
|
+
var _context;
|
|
50
|
+
let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CONSENT_COOKIE_NAME;
|
|
51
|
+
const escapedCookies = decodeURIComponent(document.cookie);
|
|
52
|
+
const consentCookie = _findInstanceProperty__default["default"](_context = escapedCookies.split('; ')).call(_context, rawCookie => {
|
|
53
|
+
const _rawCookie$split = rawCookie.split('='),
|
|
54
|
+
_rawCookie$split2 = _slicedToArray(_rawCookie$split, 1),
|
|
55
|
+
cookieName = _rawCookie$split2[0];
|
|
56
|
+
return cookieName === name;
|
|
57
|
+
});
|
|
58
|
+
return consentCookie;
|
|
59
|
+
}
|
|
60
|
+
const defaultConsentGroups = _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context2 = _Object$keys__default["default"](COOKIE_CONSENT_GROUPS)).call(_context2, consentGroup => [consentGroup, false]));
|
|
61
|
+
function getParsedConsentCookieGroups() {
|
|
62
|
+
var _context3;
|
|
63
|
+
let cookieValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getRawConsentCookie();
|
|
64
|
+
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
65
|
+
skipConsent = _ref.skipConsent;
|
|
66
|
+
let parsedConsentCookieGroups = {};
|
|
67
|
+
const encodedConsentGroupToConsentGroup = _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context3 = _Object$entries__default["default"](COOKIE_CONSENT_GROUPS)).call(_context3, _ref2 => {
|
|
68
|
+
let _ref3 = _slicedToArray(_ref2, 2),
|
|
69
|
+
encodedConsentGroupName = _ref3[0],
|
|
70
|
+
decodedConsentGroupName = _ref3[1];
|
|
71
|
+
return [decodedConsentGroupName, encodedConsentGroupName];
|
|
72
|
+
}));
|
|
73
|
+
try {
|
|
74
|
+
var _context4;
|
|
75
|
+
const parsedConsentCookieValue = new _URLSearchParams__default["default"](cookieValue);
|
|
76
|
+
const rawConsentCookieGroups = parsedConsentCookieValue.get('groups');
|
|
77
|
+
const parsedConsentCookieGroupEntries = rawConsentCookieGroups && _mapInstanceProperty__default["default"](_context4 = rawConsentCookieGroups.split(',')).call(_context4, consentGroup => {
|
|
78
|
+
const _consentGroup$split = consentGroup.split(':'),
|
|
79
|
+
_consentGroup$split2 = _slicedToArray(_consentGroup$split, 2),
|
|
80
|
+
encodedConsentGroupName = _consentGroup$split2[0],
|
|
81
|
+
consentGroupValue = _consentGroup$split2[1];
|
|
82
|
+
return [encodedConsentGroupName && encodedConsentGroupToConsentGroup[encodedConsentGroupName], skipConsent === true ? true : consentGroupValue === '1'];
|
|
83
|
+
});
|
|
84
|
+
parsedConsentCookieGroups = parsedConsentCookieGroupEntries ? _Object$fromEntries__default["default"](parsedConsentCookieGroupEntries) : null;
|
|
85
|
+
} catch (error) {}
|
|
86
|
+
return _objectSpread(_objectSpread({}, defaultConsentGroups), parsedConsentCookieGroups);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Copied from GitHub to make this library not have a UUID library dependency.
|
|
91
|
+
* This implementation is good enough for the purposes here.
|
|
92
|
+
*/
|
|
93
|
+
function generateUuid(prefix) {
|
|
94
|
+
return prefix ? ((Number(prefix) ^ Math.random() * 16) >> Number(prefix) / 4).toString(16) : `${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(/[018]/g, generateUuid);
|
|
95
|
+
}
|
|
96
|
+
function generateEncodedConsentGroups(consentGroups) {
|
|
97
|
+
var _context5, _context6;
|
|
98
|
+
return _filterInstanceProperty__default["default"](_context5 = _mapInstanceProperty__default["default"](_context6 = _Object$entries__default["default"](consentGroups)).call(_context6, _ref4 => {
|
|
99
|
+
let _ref5 = _slicedToArray(_ref4, 2),
|
|
100
|
+
consentGroupName = _ref5[0],
|
|
101
|
+
consentGroupValue = _ref5[1];
|
|
102
|
+
const encodedConsentGroup = COOKIE_CONSENT_GROUPS[consentGroupName];
|
|
103
|
+
if (!encodedConsentGroup) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return `${encodedConsentGroup}:${consentGroupValue && '1' || '0'}`;
|
|
107
|
+
})).call(_context5, Boolean).join(',');
|
|
108
|
+
}
|
|
109
|
+
function generateConsentCookie(consentGroups) {
|
|
110
|
+
const existingConsentGroups = getParsedConsentCookieGroups();
|
|
111
|
+
const encodedConsentGroups = generateEncodedConsentGroups(_objectSpread(_objectSpread({}, existingConsentGroups), consentGroups));
|
|
112
|
+
const consentValues = {
|
|
113
|
+
isGpcEnabled: '0',
|
|
114
|
+
datestamp: new Date().toString(),
|
|
115
|
+
version: '202209.1.0',
|
|
116
|
+
isIABGlobal: 'false',
|
|
117
|
+
hosts: '',
|
|
118
|
+
consentId: generateUuid(),
|
|
119
|
+
interactionCount: '1',
|
|
120
|
+
landingPath: 'NotLandingPage',
|
|
121
|
+
groups: encodedConsentGroups,
|
|
122
|
+
AwaitingReconsent: 'false'
|
|
123
|
+
};
|
|
124
|
+
const consentCookieValue = new _URLSearchParams__default["default"](consentValues);
|
|
125
|
+
return consentCookieValue.toString();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The `window.app.cookieConsentDomain` can be passed but cannot be an empty string.
|
|
130
|
+
*
|
|
131
|
+
* By default `.commercetools.com` is used.
|
|
132
|
+
*/
|
|
133
|
+
function getConsentCookieDomain() {
|
|
134
|
+
let consentCookieDomain;
|
|
135
|
+
if (window.app && window.app.cookieConsentDomain && window.app.cookieConsentDomain.length > 0) {
|
|
136
|
+
consentCookieDomain = window.app.cookieConsentDomain;
|
|
137
|
+
} else {
|
|
138
|
+
consentCookieDomain = '.commercetools.com';
|
|
139
|
+
}
|
|
140
|
+
return consentCookieDomain;
|
|
141
|
+
}
|
|
142
|
+
function setConsentCookie(consentGroups, domain) {
|
|
143
|
+
const expiresAt = new Date();
|
|
144
|
+
expiresAt.setFullYear(expiresAt.getFullYear() + 11);
|
|
145
|
+
let consentCookieDomain;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The `domain` argument takes precedence if passed.
|
|
149
|
+
*/
|
|
150
|
+
if (domain && domain.length > 0) {
|
|
151
|
+
consentCookieDomain = domain;
|
|
152
|
+
} else {
|
|
153
|
+
consentCookieDomain = getConsentCookieDomain();
|
|
154
|
+
}
|
|
155
|
+
document.cookie = `${CONSENT_COOKIE_NAME}=${generateConsentCookie(consentGroups)}; domain=${consentCookieDomain}; expires=${expiresAt.toUTCString()}; SameSite=Lax; path=/; `;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Deletes the consent cookie from the browser by setting the cookie's expiration date to a past date.
|
|
160
|
+
*/
|
|
161
|
+
function deleteConsentCookie() {
|
|
162
|
+
const beginningOfTime = 'Thu, 01 Jan 1970 00:00:00 GMT';
|
|
163
|
+
const cookieConsentDomain = getConsentCookieDomain();
|
|
164
|
+
document.cookie = `${CONSENT_COOKIE_NAME}=; expires=${beginningOfTime}; path=/; domain=${cookieConsentDomain}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Checks and potentially revokes the consent cookie based on its date stamp.
|
|
169
|
+
*
|
|
170
|
+
* If the cookie's date stamp is older than the revocation date, it deletes the cookie.
|
|
171
|
+
*/
|
|
172
|
+
function unsetConsentCookie(revocationDate) {
|
|
173
|
+
const rawConsentCookie = getRawConsentCookie();
|
|
174
|
+
const parsedConsentCookieValue = new _URLSearchParams__default["default"](rawConsentCookie);
|
|
175
|
+
const cookieDateStamp = parsedConsentCookieValue.get('datestamp');
|
|
176
|
+
if (cookieDateStamp) {
|
|
177
|
+
const cookieDate = new Date(cookieDateStamp);
|
|
178
|
+
if (cookieDate < revocationDate) {
|
|
179
|
+
deleteConsentCookie();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
exports.CONSENT_COOKIE_NAME = CONSENT_COOKIE_NAME;
|
|
185
|
+
exports.COOKIE_CONSENT_GROUPS = COOKIE_CONSENT_GROUPS;
|
|
186
|
+
exports.generateConsentCookie = generateConsentCookie;
|
|
187
|
+
exports.getParsedConsentCookieGroups = getParsedConsentCookieGroups;
|
|
188
|
+
exports.getRawConsentCookie = getRawConsentCookie;
|
|
189
|
+
exports.setConsentCookie = setConsentCookie;
|
|
190
|
+
exports.unsetConsentCookie = unsetConsentCookie;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
6
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
7
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
8
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
9
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
10
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
11
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
12
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
13
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
14
|
+
var _Object$fromEntries = require('@babel/runtime-corejs3/core-js-stable/object/from-entries');
|
|
15
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
16
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
17
|
+
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
18
|
+
var _URLSearchParams = require('@babel/runtime-corejs3/core-js-stable/url-search-params');
|
|
19
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
20
|
+
|
|
21
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
22
|
+
|
|
23
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
24
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
25
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
26
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
27
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
28
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
29
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
30
|
+
var _Object$fromEntries__default = /*#__PURE__*/_interopDefault(_Object$fromEntries);
|
|
31
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
32
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
33
|
+
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
34
|
+
var _URLSearchParams__default = /*#__PURE__*/_interopDefault(_URLSearchParams);
|
|
35
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
36
|
+
|
|
37
|
+
var _context2;
|
|
38
|
+
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
39
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context7, _context8; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context7 = ownKeys(Object(t), !0)).call(_context7, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context8 = ownKeys(Object(t))).call(_context8, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
40
|
+
const COOKIE_CONSENT_GROUPS = {
|
|
41
|
+
essentialCookies: 'C0001',
|
|
42
|
+
performanceCookies: 'C0002',
|
|
43
|
+
functionalCookies: 'C0003',
|
|
44
|
+
targetingCookies: 'C0004',
|
|
45
|
+
socialMediaCookies: 'C0005'
|
|
46
|
+
};
|
|
47
|
+
const CONSENT_COOKIE_NAME = 'OptanonConsent';
|
|
48
|
+
function getRawConsentCookie() {
|
|
49
|
+
var _context;
|
|
50
|
+
let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CONSENT_COOKIE_NAME;
|
|
51
|
+
const escapedCookies = decodeURIComponent(document.cookie);
|
|
52
|
+
const consentCookie = _findInstanceProperty__default["default"](_context = escapedCookies.split('; ')).call(_context, rawCookie => {
|
|
53
|
+
const _rawCookie$split = rawCookie.split('='),
|
|
54
|
+
_rawCookie$split2 = _slicedToArray(_rawCookie$split, 1),
|
|
55
|
+
cookieName = _rawCookie$split2[0];
|
|
56
|
+
return cookieName === name;
|
|
57
|
+
});
|
|
58
|
+
return consentCookie;
|
|
59
|
+
}
|
|
60
|
+
const defaultConsentGroups = _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context2 = _Object$keys__default["default"](COOKIE_CONSENT_GROUPS)).call(_context2, consentGroup => [consentGroup, false]));
|
|
61
|
+
function getParsedConsentCookieGroups() {
|
|
62
|
+
var _context3;
|
|
63
|
+
let cookieValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getRawConsentCookie();
|
|
64
|
+
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
65
|
+
skipConsent = _ref.skipConsent;
|
|
66
|
+
let parsedConsentCookieGroups = {};
|
|
67
|
+
const encodedConsentGroupToConsentGroup = _Object$fromEntries__default["default"](_mapInstanceProperty__default["default"](_context3 = _Object$entries__default["default"](COOKIE_CONSENT_GROUPS)).call(_context3, _ref2 => {
|
|
68
|
+
let _ref3 = _slicedToArray(_ref2, 2),
|
|
69
|
+
encodedConsentGroupName = _ref3[0],
|
|
70
|
+
decodedConsentGroupName = _ref3[1];
|
|
71
|
+
return [decodedConsentGroupName, encodedConsentGroupName];
|
|
72
|
+
}));
|
|
73
|
+
try {
|
|
74
|
+
var _context4;
|
|
75
|
+
const parsedConsentCookieValue = new _URLSearchParams__default["default"](cookieValue);
|
|
76
|
+
const rawConsentCookieGroups = parsedConsentCookieValue.get('groups');
|
|
77
|
+
const parsedConsentCookieGroupEntries = rawConsentCookieGroups && _mapInstanceProperty__default["default"](_context4 = rawConsentCookieGroups.split(',')).call(_context4, consentGroup => {
|
|
78
|
+
const _consentGroup$split = consentGroup.split(':'),
|
|
79
|
+
_consentGroup$split2 = _slicedToArray(_consentGroup$split, 2),
|
|
80
|
+
encodedConsentGroupName = _consentGroup$split2[0],
|
|
81
|
+
consentGroupValue = _consentGroup$split2[1];
|
|
82
|
+
return [encodedConsentGroupName && encodedConsentGroupToConsentGroup[encodedConsentGroupName], skipConsent === true ? true : consentGroupValue === '1'];
|
|
83
|
+
});
|
|
84
|
+
parsedConsentCookieGroups = parsedConsentCookieGroupEntries ? _Object$fromEntries__default["default"](parsedConsentCookieGroupEntries) : null;
|
|
85
|
+
} catch (error) {}
|
|
86
|
+
return _objectSpread(_objectSpread({}, defaultConsentGroups), parsedConsentCookieGroups);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Copied from GitHub to make this library not have a UUID library dependency.
|
|
91
|
+
* This implementation is good enough for the purposes here.
|
|
92
|
+
*/
|
|
93
|
+
function generateUuid(prefix) {
|
|
94
|
+
return prefix ? ((Number(prefix) ^ Math.random() * 16) >> Number(prefix) / 4).toString(16) : `${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(/[018]/g, generateUuid);
|
|
95
|
+
}
|
|
96
|
+
function generateEncodedConsentGroups(consentGroups) {
|
|
97
|
+
var _context5, _context6;
|
|
98
|
+
return _filterInstanceProperty__default["default"](_context5 = _mapInstanceProperty__default["default"](_context6 = _Object$entries__default["default"](consentGroups)).call(_context6, _ref4 => {
|
|
99
|
+
let _ref5 = _slicedToArray(_ref4, 2),
|
|
100
|
+
consentGroupName = _ref5[0],
|
|
101
|
+
consentGroupValue = _ref5[1];
|
|
102
|
+
const encodedConsentGroup = COOKIE_CONSENT_GROUPS[consentGroupName];
|
|
103
|
+
if (!encodedConsentGroup) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return `${encodedConsentGroup}:${consentGroupValue && '1' || '0'}`;
|
|
107
|
+
})).call(_context5, Boolean).join(',');
|
|
108
|
+
}
|
|
109
|
+
function generateConsentCookie(consentGroups) {
|
|
110
|
+
const existingConsentGroups = getParsedConsentCookieGroups();
|
|
111
|
+
const encodedConsentGroups = generateEncodedConsentGroups(_objectSpread(_objectSpread({}, existingConsentGroups), consentGroups));
|
|
112
|
+
const consentValues = {
|
|
113
|
+
isGpcEnabled: '0',
|
|
114
|
+
datestamp: new Date().toString(),
|
|
115
|
+
version: '202209.1.0',
|
|
116
|
+
isIABGlobal: 'false',
|
|
117
|
+
hosts: '',
|
|
118
|
+
consentId: generateUuid(),
|
|
119
|
+
interactionCount: '1',
|
|
120
|
+
landingPath: 'NotLandingPage',
|
|
121
|
+
groups: encodedConsentGroups,
|
|
122
|
+
AwaitingReconsent: 'false'
|
|
123
|
+
};
|
|
124
|
+
const consentCookieValue = new _URLSearchParams__default["default"](consentValues);
|
|
125
|
+
return consentCookieValue.toString();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The `window.app.cookieConsentDomain` can be passed but cannot be an empty string.
|
|
130
|
+
*
|
|
131
|
+
* By default `.commercetools.com` is used.
|
|
132
|
+
*/
|
|
133
|
+
function getConsentCookieDomain() {
|
|
134
|
+
let consentCookieDomain;
|
|
135
|
+
if (window.app && window.app.cookieConsentDomain && window.app.cookieConsentDomain.length > 0) {
|
|
136
|
+
consentCookieDomain = window.app.cookieConsentDomain;
|
|
137
|
+
} else {
|
|
138
|
+
consentCookieDomain = '.commercetools.com';
|
|
139
|
+
}
|
|
140
|
+
return consentCookieDomain;
|
|
141
|
+
}
|
|
142
|
+
function setConsentCookie(consentGroups, domain) {
|
|
143
|
+
const expiresAt = new Date();
|
|
144
|
+
expiresAt.setFullYear(expiresAt.getFullYear() + 11);
|
|
145
|
+
let consentCookieDomain;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The `domain` argument takes precedence if passed.
|
|
149
|
+
*/
|
|
150
|
+
if (domain && domain.length > 0) {
|
|
151
|
+
consentCookieDomain = domain;
|
|
152
|
+
} else {
|
|
153
|
+
consentCookieDomain = getConsentCookieDomain();
|
|
154
|
+
}
|
|
155
|
+
document.cookie = `${CONSENT_COOKIE_NAME}=${generateConsentCookie(consentGroups)}; domain=${consentCookieDomain}; expires=${expiresAt.toUTCString()}; SameSite=Lax; path=/; `;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Deletes the consent cookie from the browser by setting the cookie's expiration date to a past date.
|
|
160
|
+
*/
|
|
161
|
+
function deleteConsentCookie() {
|
|
162
|
+
const beginningOfTime = 'Thu, 01 Jan 1970 00:00:00 GMT';
|
|
163
|
+
const cookieConsentDomain = getConsentCookieDomain();
|
|
164
|
+
document.cookie = `${CONSENT_COOKIE_NAME}=; expires=${beginningOfTime}; path=/; domain=${cookieConsentDomain}`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Checks and potentially revokes the consent cookie based on its date stamp.
|
|
169
|
+
*
|
|
170
|
+
* If the cookie's date stamp is older than the revocation date, it deletes the cookie.
|
|
171
|
+
*/
|
|
172
|
+
function unsetConsentCookie(revocationDate) {
|
|
173
|
+
const rawConsentCookie = getRawConsentCookie();
|
|
174
|
+
const parsedConsentCookieValue = new _URLSearchParams__default["default"](rawConsentCookie);
|
|
175
|
+
const cookieDateStamp = parsedConsentCookieValue.get('datestamp');
|
|
176
|
+
if (cookieDateStamp) {
|
|
177
|
+
const cookieDate = new Date(cookieDateStamp);
|
|
178
|
+
if (cookieDate < revocationDate) {
|
|
179
|
+
deleteConsentCookie();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
exports.CONSENT_COOKIE_NAME = CONSENT_COOKIE_NAME;
|
|
185
|
+
exports.COOKIE_CONSENT_GROUPS = COOKIE_CONSENT_GROUPS;
|
|
186
|
+
exports.generateConsentCookie = generateConsentCookie;
|
|
187
|
+
exports.getParsedConsentCookieGroups = getParsedConsentCookieGroups;
|
|
188
|
+
exports.getRawConsentCookie = getRawConsentCookie;
|
|
189
|
+
exports.setConsentCookie = setConsentCookie;
|
|
190
|
+
exports.unsetConsentCookie = unsetConsentCookie;
|