@commercetools-frontend/cookie-consent 1.4.2 → 1.5.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 +11 -30
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.d.ts +1 -0
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.d.ts.map +1 -0
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.dev.js +16 -3
- package/core/dist/commercetools-frontend-cookie-consent-core.cjs.prod.js +16 -3
- package/core/dist/commercetools-frontend-cookie-consent-core.esm.js +16 -3
- package/dist/declarations/src/core/index.d.ts +5 -0
- package/package.json +14 -14
- package/react/dist/commercetools-frontend-cookie-consent-react.cjs.d.ts +1 -0
- package/react/dist/commercetools-frontend-cookie-consent-react.cjs.d.ts.map +1 -0
package/README.md
CHANGED
|
@@ -99,7 +99,17 @@ import { setConsentCookie } from '@commercetools-frontend/cookie-consent/core';
|
|
|
99
99
|
setConsentCookie({ performanceCookieConsent: true });
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
|
|
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.
|
|
103
113
|
|
|
104
114
|
```js
|
|
105
115
|
import { useCookieConsent } from '@commercetools-frontend/cookie-consent/react';
|
|
@@ -131,32 +141,3 @@ import { CookieConsentModal } from '@commercetools-frontend/cookie-consent/react
|
|
|
131
141
|
|
|
132
142
|
<CookieConsentModal />;
|
|
133
143
|
```
|
|
134
|
-
|
|
135
|
-
## Local development strategies
|
|
136
|
-
|
|
137
|
-
Cookies are bound to a domain. In order to test this functionality when developing locally, it's important to spoof a cookie, and also ensure that the domain is localhost when using `cookie-consent` module functionality.
|
|
138
|
-
|
|
139
|
-
To spoof a cookie in your browser, open Chrome, and enter the following into the console:
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
document.cookie="OptanonConsent=isGpcEnabled=0&datestamp=Wed+Mar+01+2023+11%3A38%3A38+GMT-0500+(Eastern+Standard+Time)&version=202301.2.0&isIABGlobal=false&hosts=&consentId=1623165b-6d62-4e4a-beae-71598c0756c6&interactionCount=1&landingPath=NotLandingPage&groups=C0001%3A1%2CC0002%3A0%2CC0003%3A1%2CC0004%3A1%2CC0005%3A1&geolocation=US%3BNC&AwaitingReconsent=false; domain=localhost; path=/"
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
This will create a cookie with all consent values set to false, bound to localhost.
|
|
146
|
-
|
|
147
|
-
In order to set the domain to localhost when using `cookie-consent`, pass the domain in where appropriate. For example:
|
|
148
|
-
|
|
149
|
-
```js
|
|
150
|
-
setConsent(
|
|
151
|
-
{
|
|
152
|
-
essentialCookies: true,
|
|
153
|
-
performanceCookies: true,
|
|
154
|
-
functionalCookies: false,
|
|
155
|
-
socialMediaCookies: false,
|
|
156
|
-
targetingCookies: false,
|
|
157
|
-
},
|
|
158
|
-
'localhost' // <- the important part
|
|
159
|
-
);
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
Remember to remove this argument before making a PR.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commercetools-frontend-cookie-consent-core.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/core/index.d.ts"],"names":[],"mappings":"AAAA"}
|
|
@@ -127,12 +127,25 @@ function generateConsentCookie(consentGroups) {
|
|
|
127
127
|
const consentCookieValue = new _URLSearchParams__default["default"](consentValues);
|
|
128
128
|
return consentCookieValue.toString();
|
|
129
129
|
}
|
|
130
|
-
function setConsentCookie(consentGroups) {
|
|
130
|
+
function setConsentCookie(consentGroups, domain) {
|
|
131
131
|
var _context8, _context9;
|
|
132
|
-
let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.commercetools.com';
|
|
133
132
|
const expiresAt = new Date();
|
|
134
133
|
expiresAt.setFullYear(expiresAt.getFullYear() + 11);
|
|
135
|
-
|
|
134
|
+
let consentCookieDomain;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The `domain` argument takes precedence if passed.
|
|
138
|
+
* The `window.app.cookieConsentDomain` can be passed but can not be an empty string.
|
|
139
|
+
* By default `.commercetools.com` is used.
|
|
140
|
+
*/
|
|
141
|
+
if (domain && domain.length > 0) {
|
|
142
|
+
consentCookieDomain = domain;
|
|
143
|
+
} else if (window.app && window.app.cookieConsentDomain && window.app.cookieConsentDomain.length > 0) {
|
|
144
|
+
consentCookieDomain = window.app.cookieConsentDomain;
|
|
145
|
+
} else {
|
|
146
|
+
consentCookieDomain = '.commercetools.com';
|
|
147
|
+
}
|
|
148
|
+
document.cookie = _concatInstanceProperty__default["default"](_context8 = _concatInstanceProperty__default["default"](_context9 = "".concat(CONSENT_COOKIE_NAME, "=").concat(generateConsentCookie(consentGroups), "; domain=")).call(_context9, consentCookieDomain, "; expires=")).call(_context8, expiresAt.toUTCString(), "; SameSite=Lax; path=/; ");
|
|
136
149
|
}
|
|
137
150
|
|
|
138
151
|
exports.CONSENT_COOKIE_NAME = CONSENT_COOKIE_NAME;
|
|
@@ -127,12 +127,25 @@ function generateConsentCookie(consentGroups) {
|
|
|
127
127
|
const consentCookieValue = new _URLSearchParams__default["default"](consentValues);
|
|
128
128
|
return consentCookieValue.toString();
|
|
129
129
|
}
|
|
130
|
-
function setConsentCookie(consentGroups) {
|
|
130
|
+
function setConsentCookie(consentGroups, domain) {
|
|
131
131
|
var _context8, _context9;
|
|
132
|
-
let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.commercetools.com';
|
|
133
132
|
const expiresAt = new Date();
|
|
134
133
|
expiresAt.setFullYear(expiresAt.getFullYear() + 11);
|
|
135
|
-
|
|
134
|
+
let consentCookieDomain;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The `domain` argument takes precedence if passed.
|
|
138
|
+
* The `window.app.cookieConsentDomain` can be passed but can not be an empty string.
|
|
139
|
+
* By default `.commercetools.com` is used.
|
|
140
|
+
*/
|
|
141
|
+
if (domain && domain.length > 0) {
|
|
142
|
+
consentCookieDomain = domain;
|
|
143
|
+
} else if (window.app && window.app.cookieConsentDomain && window.app.cookieConsentDomain.length > 0) {
|
|
144
|
+
consentCookieDomain = window.app.cookieConsentDomain;
|
|
145
|
+
} else {
|
|
146
|
+
consentCookieDomain = '.commercetools.com';
|
|
147
|
+
}
|
|
148
|
+
document.cookie = _concatInstanceProperty__default["default"](_context8 = _concatInstanceProperty__default["default"](_context9 = "".concat(CONSENT_COOKIE_NAME, "=").concat(generateConsentCookie(consentGroups), "; domain=")).call(_context9, consentCookieDomain, "; expires=")).call(_context8, expiresAt.toUTCString(), "; SameSite=Lax; path=/; ");
|
|
136
149
|
}
|
|
137
150
|
|
|
138
151
|
exports.CONSENT_COOKIE_NAME = CONSENT_COOKIE_NAME;
|
|
@@ -106,12 +106,25 @@ function generateConsentCookie(consentGroups) {
|
|
|
106
106
|
const consentCookieValue = new _URLSearchParams(consentValues);
|
|
107
107
|
return consentCookieValue.toString();
|
|
108
108
|
}
|
|
109
|
-
function setConsentCookie(consentGroups) {
|
|
109
|
+
function setConsentCookie(consentGroups, domain) {
|
|
110
110
|
var _context8, _context9;
|
|
111
|
-
let domain = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.commercetools.com';
|
|
112
111
|
const expiresAt = new Date();
|
|
113
112
|
expiresAt.setFullYear(expiresAt.getFullYear() + 11);
|
|
114
|
-
|
|
113
|
+
let consentCookieDomain;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The `domain` argument takes precedence if passed.
|
|
117
|
+
* The `window.app.cookieConsentDomain` can be passed but can not be an empty string.
|
|
118
|
+
* By default `.commercetools.com` is used.
|
|
119
|
+
*/
|
|
120
|
+
if (domain && domain.length > 0) {
|
|
121
|
+
consentCookieDomain = domain;
|
|
122
|
+
} else if (window.app && window.app.cookieConsentDomain && window.app.cookieConsentDomain.length > 0) {
|
|
123
|
+
consentCookieDomain = window.app.cookieConsentDomain;
|
|
124
|
+
} else {
|
|
125
|
+
consentCookieDomain = '.commercetools.com';
|
|
126
|
+
}
|
|
127
|
+
document.cookie = _concatInstanceProperty(_context8 = _concatInstanceProperty(_context9 = "".concat(CONSENT_COOKIE_NAME, "=").concat(generateConsentCookie(consentGroups), "; domain=")).call(_context9, consentCookieDomain, "; expires=")).call(_context8, expiresAt.toUTCString(), "; SameSite=Lax; path=/; ");
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
export { CONSENT_COOKIE_NAME, COOKIE_CONSENT_GROUPS, generateConsentCookie, getParsedConsentCookieGroups, getRawConsentCookie, setConsentCookie };
|
|
@@ -5,6 +5,11 @@ declare const COOKIE_CONSENT_GROUPS: {
|
|
|
5
5
|
readonly targetingCookies: "C0004";
|
|
6
6
|
readonly socialMediaCookies: "C0005";
|
|
7
7
|
};
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window {
|
|
10
|
+
app: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
8
13
|
type TConsentGroupNames = keyof typeof COOKIE_CONSENT_GROUPS;
|
|
9
14
|
type TConsentGroups = Record<TConsentGroupNames, boolean>;
|
|
10
15
|
declare const CONSENT_COOKIE_NAME = "OptanonConsent";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/cookie-consent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A package integrating with OneTrust cookie consent",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/commercetools-frontend-cookie-consent.cjs.js",
|
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
"@babel/core": "^7.21.0",
|
|
18
18
|
"@babel/runtime": "^7.21.0",
|
|
19
19
|
"@babel/runtime-corejs3": "^7.21.0",
|
|
20
|
-
"@commercetools-frontend/application-components": "^21.
|
|
21
|
-
"@commercetools-uikit/collapsible-panel": "^15.
|
|
22
|
-
"@commercetools-uikit/design-system": "^15.
|
|
23
|
-
"@commercetools-uikit/grid": "^15.
|
|
24
|
-
"@commercetools-uikit/link": "^15.
|
|
25
|
-
"@commercetools-uikit/primary-button": "^15.
|
|
26
|
-
"@commercetools-uikit/spacings": "^15.
|
|
27
|
-
"@commercetools-uikit/text": "^15.
|
|
28
|
-
"@commercetools-uikit/toggle-input": "^15.
|
|
20
|
+
"@commercetools-frontend/application-components": "^21.25.2",
|
|
21
|
+
"@commercetools-uikit/collapsible-panel": "^15.15.0",
|
|
22
|
+
"@commercetools-uikit/design-system": "^15.15.0",
|
|
23
|
+
"@commercetools-uikit/grid": "^15.15.0",
|
|
24
|
+
"@commercetools-uikit/link": "^15.15.0",
|
|
25
|
+
"@commercetools-uikit/primary-button": "^15.15.0",
|
|
26
|
+
"@commercetools-uikit/spacings": "^15.15.0",
|
|
27
|
+
"@commercetools-uikit/text": "^15.15.0",
|
|
28
|
+
"@commercetools-uikit/toggle-input": "^15.15.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@commercetools-frontend/application-shell": "21.
|
|
32
|
-
"@commercetools-frontend/application-shell-connectors": "21.
|
|
33
|
-
"@types/node": "18.15.
|
|
34
|
-
"@types/react": "17.0.
|
|
31
|
+
"@commercetools-frontend/application-shell": "21.25.2",
|
|
32
|
+
"@commercetools-frontend/application-shell-connectors": "21.25.2",
|
|
33
|
+
"@types/node": "18.15.12",
|
|
34
|
+
"@types/react": "17.0.58",
|
|
35
35
|
"@emotion/react": "11.10.6",
|
|
36
36
|
"react": "17.0.2",
|
|
37
37
|
"react-intl": "5.25.1",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commercetools-frontend-cookie-consent-react.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/react/index.d.ts"],"names":[],"mappings":"AAAA"}
|