@commercetools-frontend/cookie-consent 1.2.2 → 1.3.1
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/core/dist/commercetools-frontend-cookie-consent-core.cjs.dev.js +6 -3
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.prod.js +6 -3
- package/core/dist/commercetools-frontend-cookie-consent-core.esm.js +119 -0
- package/core/package.json +2 -1
- package/dist/declarations/src/core/index.d.ts +5 -2
- package/package.json +1 -1
- package/react/dist/commercetools-frontend-cookie-consent-react.cjs.dev.js +70 -52
- package/react/dist/commercetools-frontend-cookie-consent-react.cjs.prod.js +56 -44
- package/react/dist/commercetools-frontend-cookie-consent-react.esm.js +833 -0
- package/react/package.json +2 -1
|
@@ -46,9 +46,10 @@ var COOKIE_CONSENT_GROUPS = {
|
|
|
46
46
|
targetingCookies: 'C0004',
|
|
47
47
|
socialMediaCookies: 'C0005'
|
|
48
48
|
};
|
|
49
|
+
var CONSENT_COOKIE_NAME = 'OptanonConsent';
|
|
49
50
|
function getRawConsentCookie() {
|
|
50
51
|
var _context;
|
|
51
|
-
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
52
|
+
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CONSENT_COOKIE_NAME;
|
|
52
53
|
var escapedCookies = decodeURIComponent(document.cookie);
|
|
53
54
|
var consentCookie = _findInstanceProperty__default["default"](_context = escapedCookies.split('; ')).call(_context, function (rawCookie) {
|
|
54
55
|
var _rawCookie$split = rawCookie.split('='),
|
|
@@ -77,7 +78,7 @@ function getParsedConsentCookieGroups() {
|
|
|
77
78
|
var _context4;
|
|
78
79
|
var parsedConsentCookieValue = new _URLSearchParams__default["default"](cookieValue);
|
|
79
80
|
var rawConsentCookieGroups = parsedConsentCookieValue.get('groups');
|
|
80
|
-
var parsedConsentCookieGroupEntries = rawConsentCookieGroups
|
|
81
|
+
var parsedConsentCookieGroupEntries = rawConsentCookieGroups && _mapInstanceProperty__default["default"](_context4 = rawConsentCookieGroups.split(',')).call(_context4, function (consentGroup) {
|
|
81
82
|
var _consentGroup$split = consentGroup.split(':'),
|
|
82
83
|
_consentGroup$split2 = _slicedToArray(_consentGroup$split, 2),
|
|
83
84
|
encodedConsentGroupName = _consentGroup$split2[0],
|
|
@@ -133,10 +134,12 @@ function setConsentCookie(consentGroups) {
|
|
|
133
134
|
var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.commercetools.com';
|
|
134
135
|
var expiresAt = new Date();
|
|
135
136
|
expiresAt.setFullYear(expiresAt.getFullYear() + 11);
|
|
136
|
-
document.cookie = _concatInstanceProperty__default["default"](_context8 = _concatInstanceProperty__default["default"](_context9 = "
|
|
137
|
+
document.cookie = _concatInstanceProperty__default["default"](_context8 = _concatInstanceProperty__default["default"](_context9 = "".concat(CONSENT_COOKIE_NAME, "=").concat(generateConsentCookie(consentGroups), "; domain=")).call(_context9, domain, "; expires=")).call(_context8, expiresAt.toUTCString(), "; SameSite=Lax; path=/; ");
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
exports.CONSENT_COOKIE_NAME = CONSENT_COOKIE_NAME;
|
|
139
141
|
exports.COOKIE_CONSENT_GROUPS = COOKIE_CONSENT_GROUPS;
|
|
142
|
+
exports.generateConsentCookie = generateConsentCookie;
|
|
140
143
|
exports.getParsedConsentCookieGroups = getParsedConsentCookieGroups;
|
|
141
144
|
exports.getRawConsentCookie = getRawConsentCookie;
|
|
142
145
|
exports.setConsentCookie = setConsentCookie;
|
|
@@ -46,9 +46,10 @@ var COOKIE_CONSENT_GROUPS = {
|
|
|
46
46
|
targetingCookies: 'C0004',
|
|
47
47
|
socialMediaCookies: 'C0005'
|
|
48
48
|
};
|
|
49
|
+
var CONSENT_COOKIE_NAME = 'OptanonConsent';
|
|
49
50
|
function getRawConsentCookie() {
|
|
50
51
|
var _context;
|
|
51
|
-
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
52
|
+
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CONSENT_COOKIE_NAME;
|
|
52
53
|
var escapedCookies = decodeURIComponent(document.cookie);
|
|
53
54
|
var consentCookie = _findInstanceProperty__default["default"](_context = escapedCookies.split('; ')).call(_context, function (rawCookie) {
|
|
54
55
|
var _rawCookie$split = rawCookie.split('='),
|
|
@@ -77,7 +78,7 @@ function getParsedConsentCookieGroups() {
|
|
|
77
78
|
var _context4;
|
|
78
79
|
var parsedConsentCookieValue = new _URLSearchParams__default["default"](cookieValue);
|
|
79
80
|
var rawConsentCookieGroups = parsedConsentCookieValue.get('groups');
|
|
80
|
-
var parsedConsentCookieGroupEntries = rawConsentCookieGroups
|
|
81
|
+
var parsedConsentCookieGroupEntries = rawConsentCookieGroups && _mapInstanceProperty__default["default"](_context4 = rawConsentCookieGroups.split(',')).call(_context4, function (consentGroup) {
|
|
81
82
|
var _consentGroup$split = consentGroup.split(':'),
|
|
82
83
|
_consentGroup$split2 = _slicedToArray(_consentGroup$split, 2),
|
|
83
84
|
encodedConsentGroupName = _consentGroup$split2[0],
|
|
@@ -133,10 +134,12 @@ function setConsentCookie(consentGroups) {
|
|
|
133
134
|
var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.commercetools.com';
|
|
134
135
|
var expiresAt = new Date();
|
|
135
136
|
expiresAt.setFullYear(expiresAt.getFullYear() + 11);
|
|
136
|
-
document.cookie = _concatInstanceProperty__default["default"](_context8 = _concatInstanceProperty__default["default"](_context9 = "
|
|
137
|
+
document.cookie = _concatInstanceProperty__default["default"](_context8 = _concatInstanceProperty__default["default"](_context9 = "".concat(CONSENT_COOKIE_NAME, "=").concat(generateConsentCookie(consentGroups), "; domain=")).call(_context9, domain, "; expires=")).call(_context8, expiresAt.toUTCString(), "; SameSite=Lax; path=/; ");
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
exports.CONSENT_COOKIE_NAME = CONSENT_COOKIE_NAME;
|
|
139
141
|
exports.COOKIE_CONSENT_GROUPS = COOKIE_CONSENT_GROUPS;
|
|
142
|
+
exports.generateConsentCookie = generateConsentCookie;
|
|
140
143
|
exports.getParsedConsentCookieGroups = getParsedConsentCookieGroups;
|
|
141
144
|
exports.getRawConsentCookie = getRawConsentCookie;
|
|
142
145
|
exports.setConsentCookie = setConsentCookie;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
2
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
3
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
4
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
5
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
6
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
7
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
8
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
9
|
+
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
10
|
+
import _Object$fromEntries from '@babel/runtime-corejs3/core-js-stable/object/from-entries';
|
|
11
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
12
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
13
|
+
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
14
|
+
import _URLSearchParams from '@babel/runtime-corejs3/core-js-stable/url-search-params';
|
|
15
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
16
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
17
|
+
|
|
18
|
+
var _context2;
|
|
19
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context10, _context11; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context10 = ownKeys(Object(source), !0)).call(_context10, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context11 = ownKeys(Object(source))).call(_context11, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
var COOKIE_CONSENT_GROUPS = {
|
|
22
|
+
essentialCookies: 'C0001',
|
|
23
|
+
performanceCookies: 'C0002',
|
|
24
|
+
functionalCookies: 'C0003',
|
|
25
|
+
targetingCookies: 'C0004',
|
|
26
|
+
socialMediaCookies: 'C0005'
|
|
27
|
+
};
|
|
28
|
+
var CONSENT_COOKIE_NAME = 'OptanonConsent';
|
|
29
|
+
function getRawConsentCookie() {
|
|
30
|
+
var _context;
|
|
31
|
+
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CONSENT_COOKIE_NAME;
|
|
32
|
+
var escapedCookies = decodeURIComponent(document.cookie);
|
|
33
|
+
var consentCookie = _findInstanceProperty(_context = escapedCookies.split('; ')).call(_context, function (rawCookie) {
|
|
34
|
+
var _rawCookie$split = rawCookie.split('='),
|
|
35
|
+
_rawCookie$split2 = _slicedToArray(_rawCookie$split, 1),
|
|
36
|
+
cookieName = _rawCookie$split2[0];
|
|
37
|
+
return cookieName === name;
|
|
38
|
+
});
|
|
39
|
+
return consentCookie;
|
|
40
|
+
}
|
|
41
|
+
var defaultConsentGroups = _Object$fromEntries(_mapInstanceProperty(_context2 = _Object$keys(COOKIE_CONSENT_GROUPS)).call(_context2, function (consentGroup) {
|
|
42
|
+
return [consentGroup, false];
|
|
43
|
+
}));
|
|
44
|
+
function getParsedConsentCookieGroups() {
|
|
45
|
+
var _context3;
|
|
46
|
+
var cookieValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getRawConsentCookie();
|
|
47
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
48
|
+
skipConsent = _ref.skipConsent;
|
|
49
|
+
var parsedConsentCookieGroups = {};
|
|
50
|
+
var encodedConsentGroupToConsentGroup = _Object$fromEntries(_mapInstanceProperty(_context3 = _Object$entries(COOKIE_CONSENT_GROUPS)).call(_context3, function (_ref2) {
|
|
51
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
52
|
+
encodedConsentGroupName = _ref3[0],
|
|
53
|
+
decodedConsentGroupName = _ref3[1];
|
|
54
|
+
return [decodedConsentGroupName, encodedConsentGroupName];
|
|
55
|
+
}));
|
|
56
|
+
try {
|
|
57
|
+
var _context4;
|
|
58
|
+
var parsedConsentCookieValue = new _URLSearchParams(cookieValue);
|
|
59
|
+
var rawConsentCookieGroups = parsedConsentCookieValue.get('groups');
|
|
60
|
+
var parsedConsentCookieGroupEntries = rawConsentCookieGroups && _mapInstanceProperty(_context4 = rawConsentCookieGroups.split(',')).call(_context4, function (consentGroup) {
|
|
61
|
+
var _consentGroup$split = consentGroup.split(':'),
|
|
62
|
+
_consentGroup$split2 = _slicedToArray(_consentGroup$split, 2),
|
|
63
|
+
encodedConsentGroupName = _consentGroup$split2[0],
|
|
64
|
+
consentGroupValue = _consentGroup$split2[1];
|
|
65
|
+
return [encodedConsentGroupToConsentGroup[encodedConsentGroupName], skipConsent === true ? true : consentGroupValue === '1'];
|
|
66
|
+
});
|
|
67
|
+
parsedConsentCookieGroups = parsedConsentCookieGroupEntries ? _Object$fromEntries(parsedConsentCookieGroupEntries) : null;
|
|
68
|
+
} catch (error) {}
|
|
69
|
+
return _objectSpread(_objectSpread({}, defaultConsentGroups), parsedConsentCookieGroups);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Copied from GitHub to make this library not have a UUID library dependency.
|
|
74
|
+
* This implementation is good enough for the purposes here.
|
|
75
|
+
*/
|
|
76
|
+
function generateUuid(prefix) {
|
|
77
|
+
return prefix ? ((Number(prefix) ^ Math.random() * 16) >> Number(prefix) / 4).toString(16) : "".concat(1e7, "-", 1e3, "-", 4e3, "-", 8e3, "-", 1e11).replace(/[018]/g, generateUuid);
|
|
78
|
+
}
|
|
79
|
+
function generateEncodedConsentGroups(consentGroups) {
|
|
80
|
+
var _context5, _context6;
|
|
81
|
+
return _filterInstanceProperty(_context5 = _mapInstanceProperty(_context6 = _Object$entries(consentGroups)).call(_context6, function (_ref4) {
|
|
82
|
+
var _context7;
|
|
83
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
84
|
+
consentGroupName = _ref5[0],
|
|
85
|
+
consentGroupValue = _ref5[1];
|
|
86
|
+
var encodedConsentGroup = COOKIE_CONSENT_GROUPS[consentGroupName];
|
|
87
|
+
if (!encodedConsentGroup) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return _concatInstanceProperty(_context7 = "".concat(encodedConsentGroup, ":")).call(_context7, consentGroupValue && '1' || '0');
|
|
91
|
+
})).call(_context5, Boolean).join(',');
|
|
92
|
+
}
|
|
93
|
+
function generateConsentCookie(consentGroups) {
|
|
94
|
+
var existingConsentGroups = getParsedConsentCookieGroups();
|
|
95
|
+
var encodedConsentGroups = generateEncodedConsentGroups(_objectSpread(_objectSpread({}, existingConsentGroups), consentGroups));
|
|
96
|
+
var consentValues = {
|
|
97
|
+
isGpcEnabled: '0',
|
|
98
|
+
datestamp: new Date().toString(),
|
|
99
|
+
version: '202209.1.0',
|
|
100
|
+
isIABGlobal: 'false',
|
|
101
|
+
hosts: '',
|
|
102
|
+
consentId: generateUuid(),
|
|
103
|
+
interactionCount: '1',
|
|
104
|
+
landingPath: 'NotLandingPage',
|
|
105
|
+
groups: encodedConsentGroups,
|
|
106
|
+
AwaitingReconsent: 'false'
|
|
107
|
+
};
|
|
108
|
+
var consentCookieValue = new _URLSearchParams(consentValues);
|
|
109
|
+
return consentCookieValue.toString();
|
|
110
|
+
}
|
|
111
|
+
function setConsentCookie(consentGroups) {
|
|
112
|
+
var _context8, _context9;
|
|
113
|
+
var domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.commercetools.com';
|
|
114
|
+
var expiresAt = new Date();
|
|
115
|
+
expiresAt.setFullYear(expiresAt.getFullYear() + 11);
|
|
116
|
+
document.cookie = _concatInstanceProperty(_context8 = _concatInstanceProperty(_context9 = "".concat(CONSENT_COOKIE_NAME, "=").concat(generateConsentCookie(consentGroups), "; domain=")).call(_context9, domain, "; expires=")).call(_context8, expiresAt.toUTCString(), "; SameSite=Lax; path=/; ");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { CONSENT_COOKIE_NAME, COOKIE_CONSENT_GROUPS, generateConsentCookie, getParsedConsentCookieGroups, getRawConsentCookie, setConsentCookie };
|
package/core/package.json
CHANGED
|
@@ -6,6 +6,8 @@ declare const COOKIE_CONSENT_GROUPS: {
|
|
|
6
6
|
readonly socialMediaCookies: "C0005";
|
|
7
7
|
};
|
|
8
8
|
type TConsentGroupNames = keyof typeof COOKIE_CONSENT_GROUPS;
|
|
9
|
+
type TConsentGroups = Record<TConsentGroupNames, boolean>;
|
|
10
|
+
declare const CONSENT_COOKIE_NAME = "OptanonConsent";
|
|
9
11
|
declare function getRawConsentCookie(name?: string): string | undefined;
|
|
10
12
|
type TGetParsedConsentCookieGroupsOptions = {
|
|
11
13
|
skipConsent?: boolean;
|
|
@@ -17,5 +19,6 @@ declare function getParsedConsentCookieGroups(cookieValue?: string | undefined,
|
|
|
17
19
|
targetingCookies: boolean;
|
|
18
20
|
socialMediaCookies: boolean;
|
|
19
21
|
};
|
|
20
|
-
declare function
|
|
21
|
-
|
|
22
|
+
declare function generateConsentCookie(consentGroups: Partial<TConsentGroups>): string;
|
|
23
|
+
declare function setConsentCookie(consentGroups: Partial<TConsentGroups>, domain?: string): void;
|
|
24
|
+
export { type TConsentGroups, CONSENT_COOKIE_NAME, getRawConsentCookie, getParsedConsentCookieGroups, setConsentCookie, generateConsentCookie, COOKIE_CONSENT_GROUPS, };
|
package/package.json
CHANGED