@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.
Files changed (25) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -0
  3. package/core/dist/commercetools-frontend-cookie-consent-core.cjs.d.ts +2 -0
  4. package/core/dist/commercetools-frontend-cookie-consent-core.cjs.dev.js +190 -0
  5. package/core/dist/commercetools-frontend-cookie-consent-core.cjs.js +7 -0
  6. package/core/dist/commercetools-frontend-cookie-consent-core.cjs.prod.js +190 -0
  7. package/core/dist/commercetools-frontend-cookie-consent-core.esm.js +164 -0
  8. package/core/package.json +4 -0
  9. package/dist/declarations/src/core/index.d.ts +35 -0
  10. package/dist/declarations/src/react/cookie-consent-banner/cookie-consent-banner.d.ts +8 -0
  11. package/dist/declarations/src/react/cookie-consent-banner/index.d.ts +1 -0
  12. package/dist/declarations/src/react/cookie-consent-modal/cookie-consent-modal.d.ts +7 -0
  13. package/dist/declarations/src/react/cookie-consent-modal/index.d.ts +1 -0
  14. package/dist/declarations/src/react/index.d.ts +4 -0
  15. package/dist/declarations/src/react/use-cookie-consent/index.d.ts +1 -0
  16. package/dist/declarations/src/react/use-cookie-consent/use-cookie-consent.d.ts +10 -0
  17. package/dist/declarations/src/react/use-skip-cookie-consent/index.d.ts +1 -0
  18. package/dist/declarations/src/react/use-skip-cookie-consent/use-skip-cookie-consent.d.ts +2 -0
  19. package/package.json +67 -0
  20. package/react/dist/commercetools-frontend-cookie-consent-react.cjs.d.ts +2 -0
  21. package/react/dist/commercetools-frontend-cookie-consent-react.cjs.dev.js +818 -0
  22. package/react/dist/commercetools-frontend-cookie-consent-react.cjs.js +7 -0
  23. package/react/dist/commercetools-frontend-cookie-consent-react.cjs.prod.js +796 -0
  24. package/react/dist/commercetools-frontend-cookie-consent-react.esm.js +791 -0
  25. package/react/package.json +4 -0
@@ -0,0 +1,164 @@
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
+
17
+ var _context2;
18
+ function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context7, _context8; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context7 = ownKeys(Object(t), !0)).call(_context7, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context8 = ownKeys(Object(t))).call(_context8, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
20
+ const COOKIE_CONSENT_GROUPS = {
21
+ essentialCookies: 'C0001',
22
+ performanceCookies: 'C0002',
23
+ functionalCookies: 'C0003',
24
+ targetingCookies: 'C0004',
25
+ socialMediaCookies: 'C0005'
26
+ };
27
+ const CONSENT_COOKIE_NAME = 'OptanonConsent';
28
+ function getRawConsentCookie() {
29
+ var _context;
30
+ let name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CONSENT_COOKIE_NAME;
31
+ const escapedCookies = decodeURIComponent(document.cookie);
32
+ const consentCookie = _findInstanceProperty(_context = escapedCookies.split('; ')).call(_context, rawCookie => {
33
+ const _rawCookie$split = rawCookie.split('='),
34
+ _rawCookie$split2 = _slicedToArray(_rawCookie$split, 1),
35
+ cookieName = _rawCookie$split2[0];
36
+ return cookieName === name;
37
+ });
38
+ return consentCookie;
39
+ }
40
+ const defaultConsentGroups = _Object$fromEntries(_mapInstanceProperty(_context2 = _Object$keys(COOKIE_CONSENT_GROUPS)).call(_context2, consentGroup => [consentGroup, false]));
41
+ function getParsedConsentCookieGroups() {
42
+ var _context3;
43
+ let cookieValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getRawConsentCookie();
44
+ let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
45
+ skipConsent = _ref.skipConsent;
46
+ let parsedConsentCookieGroups = {};
47
+ const encodedConsentGroupToConsentGroup = _Object$fromEntries(_mapInstanceProperty(_context3 = _Object$entries(COOKIE_CONSENT_GROUPS)).call(_context3, _ref2 => {
48
+ let _ref3 = _slicedToArray(_ref2, 2),
49
+ encodedConsentGroupName = _ref3[0],
50
+ decodedConsentGroupName = _ref3[1];
51
+ return [decodedConsentGroupName, encodedConsentGroupName];
52
+ }));
53
+ try {
54
+ var _context4;
55
+ const parsedConsentCookieValue = new _URLSearchParams(cookieValue);
56
+ const rawConsentCookieGroups = parsedConsentCookieValue.get('groups');
57
+ const parsedConsentCookieGroupEntries = rawConsentCookieGroups && _mapInstanceProperty(_context4 = rawConsentCookieGroups.split(',')).call(_context4, consentGroup => {
58
+ const _consentGroup$split = consentGroup.split(':'),
59
+ _consentGroup$split2 = _slicedToArray(_consentGroup$split, 2),
60
+ encodedConsentGroupName = _consentGroup$split2[0],
61
+ consentGroupValue = _consentGroup$split2[1];
62
+ return [encodedConsentGroupName && encodedConsentGroupToConsentGroup[encodedConsentGroupName], skipConsent === true ? true : consentGroupValue === '1'];
63
+ });
64
+ parsedConsentCookieGroups = parsedConsentCookieGroupEntries ? _Object$fromEntries(parsedConsentCookieGroupEntries) : null;
65
+ } catch (error) {}
66
+ return _objectSpread(_objectSpread({}, defaultConsentGroups), parsedConsentCookieGroups);
67
+ }
68
+
69
+ /**
70
+ * Copied from GitHub to make this library not have a UUID library dependency.
71
+ * This implementation is good enough for the purposes here.
72
+ */
73
+ function generateUuid(prefix) {
74
+ return prefix ? ((Number(prefix) ^ Math.random() * 16) >> Number(prefix) / 4).toString(16) : `${1e7}-${1e3}-${4e3}-${8e3}-${1e11}`.replace(/[018]/g, generateUuid);
75
+ }
76
+ function generateEncodedConsentGroups(consentGroups) {
77
+ var _context5, _context6;
78
+ return _filterInstanceProperty(_context5 = _mapInstanceProperty(_context6 = _Object$entries(consentGroups)).call(_context6, _ref4 => {
79
+ let _ref5 = _slicedToArray(_ref4, 2),
80
+ consentGroupName = _ref5[0],
81
+ consentGroupValue = _ref5[1];
82
+ const encodedConsentGroup = COOKIE_CONSENT_GROUPS[consentGroupName];
83
+ if (!encodedConsentGroup) {
84
+ return null;
85
+ }
86
+ return `${encodedConsentGroup}:${consentGroupValue && '1' || '0'}`;
87
+ })).call(_context5, Boolean).join(',');
88
+ }
89
+ function generateConsentCookie(consentGroups) {
90
+ const existingConsentGroups = getParsedConsentCookieGroups();
91
+ const encodedConsentGroups = generateEncodedConsentGroups(_objectSpread(_objectSpread({}, existingConsentGroups), consentGroups));
92
+ const consentValues = {
93
+ isGpcEnabled: '0',
94
+ datestamp: new Date().toString(),
95
+ version: '202209.1.0',
96
+ isIABGlobal: 'false',
97
+ hosts: '',
98
+ consentId: generateUuid(),
99
+ interactionCount: '1',
100
+ landingPath: 'NotLandingPage',
101
+ groups: encodedConsentGroups,
102
+ AwaitingReconsent: 'false'
103
+ };
104
+ const consentCookieValue = new _URLSearchParams(consentValues);
105
+ return consentCookieValue.toString();
106
+ }
107
+
108
+ /**
109
+ * The `window.app.cookieConsentDomain` can be passed but cannot be an empty string.
110
+ *
111
+ * By default `.commercetools.com` is used.
112
+ */
113
+ function getConsentCookieDomain() {
114
+ let consentCookieDomain;
115
+ if (window.app && window.app.cookieConsentDomain && window.app.cookieConsentDomain.length > 0) {
116
+ consentCookieDomain = window.app.cookieConsentDomain;
117
+ } else {
118
+ consentCookieDomain = '.commercetools.com';
119
+ }
120
+ return consentCookieDomain;
121
+ }
122
+ function setConsentCookie(consentGroups, domain) {
123
+ const expiresAt = new Date();
124
+ expiresAt.setFullYear(expiresAt.getFullYear() + 11);
125
+ let consentCookieDomain;
126
+
127
+ /**
128
+ * The `domain` argument takes precedence if passed.
129
+ */
130
+ if (domain && domain.length > 0) {
131
+ consentCookieDomain = domain;
132
+ } else {
133
+ consentCookieDomain = getConsentCookieDomain();
134
+ }
135
+ document.cookie = `${CONSENT_COOKIE_NAME}=${generateConsentCookie(consentGroups)}; domain=${consentCookieDomain}; expires=${expiresAt.toUTCString()}; SameSite=Lax; path=/; `;
136
+ }
137
+
138
+ /**
139
+ * Deletes the consent cookie from the browser by setting the cookie's expiration date to a past date.
140
+ */
141
+ function deleteConsentCookie() {
142
+ const beginningOfTime = 'Thu, 01 Jan 1970 00:00:00 GMT';
143
+ const cookieConsentDomain = getConsentCookieDomain();
144
+ document.cookie = `${CONSENT_COOKIE_NAME}=; expires=${beginningOfTime}; path=/; domain=${cookieConsentDomain}`;
145
+ }
146
+
147
+ /**
148
+ * Checks and potentially revokes the consent cookie based on its date stamp.
149
+ *
150
+ * If the cookie's date stamp is older than the revocation date, it deletes the cookie.
151
+ */
152
+ function unsetConsentCookie(revocationDate) {
153
+ const rawConsentCookie = getRawConsentCookie();
154
+ const parsedConsentCookieValue = new _URLSearchParams(rawConsentCookie);
155
+ const cookieDateStamp = parsedConsentCookieValue.get('datestamp');
156
+ if (cookieDateStamp) {
157
+ const cookieDate = new Date(cookieDateStamp);
158
+ if (cookieDate < revocationDate) {
159
+ deleteConsentCookie();
160
+ }
161
+ }
162
+ }
163
+
164
+ export { CONSENT_COOKIE_NAME, COOKIE_CONSENT_GROUPS, generateConsentCookie, getParsedConsentCookieGroups, getRawConsentCookie, setConsentCookie, unsetConsentCookie };
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "dist/commercetools-frontend-cookie-consent-core.cjs.js",
3
+ "module": "dist/commercetools-frontend-cookie-consent-core.esm.js"
4
+ }
@@ -0,0 +1,35 @@
1
+ declare const COOKIE_CONSENT_GROUPS: {
2
+ readonly essentialCookies: "C0001";
3
+ readonly performanceCookies: "C0002";
4
+ readonly functionalCookies: "C0003";
5
+ readonly targetingCookies: "C0004";
6
+ readonly socialMediaCookies: "C0005";
7
+ };
8
+ declare global {
9
+ interface Window {
10
+ app: Record<string, unknown>;
11
+ }
12
+ }
13
+ type TConsentGroupNames = keyof typeof COOKIE_CONSENT_GROUPS;
14
+ type TConsentGroups = Record<TConsentGroupNames, boolean>;
15
+ declare const CONSENT_COOKIE_NAME = "OptanonConsent";
16
+ declare function getRawConsentCookie(name?: string): string | undefined;
17
+ type TGetParsedConsentCookieGroupsOptions = {
18
+ skipConsent?: boolean;
19
+ };
20
+ declare function getParsedConsentCookieGroups(cookieValue?: string | undefined, { skipConsent }?: TGetParsedConsentCookieGroupsOptions): {
21
+ essentialCookies: boolean;
22
+ performanceCookies: boolean;
23
+ functionalCookies: boolean;
24
+ targetingCookies: boolean;
25
+ socialMediaCookies: boolean;
26
+ };
27
+ declare function generateConsentCookie(consentGroups: Partial<TConsentGroups>): string;
28
+ declare function setConsentCookie(consentGroups: Partial<TConsentGroups>, domain?: string): void;
29
+ /**
30
+ * Checks and potentially revokes the consent cookie based on its date stamp.
31
+ *
32
+ * If the cookie's date stamp is older than the revocation date, it deletes the cookie.
33
+ */
34
+ declare function unsetConsentCookie(revocationDate: Date): void;
35
+ export { type TConsentGroups, CONSENT_COOKIE_NAME, getRawConsentCookie, getParsedConsentCookieGroups, setConsentCookie, unsetConsentCookie, generateConsentCookie, COOKIE_CONSENT_GROUPS, };
@@ -0,0 +1,8 @@
1
+ type ConsentBannerProps = {
2
+ skipConsent: boolean;
3
+ };
4
+ declare const CookieConsentBanner: {
5
+ (bannerProps: ConsentBannerProps): import("@emotion/react/types/jsx-namespace").EmotionJSX.Element | null;
6
+ displayName: string;
7
+ };
8
+ export { CookieConsentBanner };
@@ -0,0 +1 @@
1
+ export { CookieConsentBanner } from "./cookie-consent-banner.js";
@@ -0,0 +1,7 @@
1
+ type ModalStateProps = {
2
+ isModalOpen: boolean;
3
+ closeModal: () => void;
4
+ setBannerClosed: (boolean: boolean) => void;
5
+ };
6
+ declare const CookieConsentModal: (modalProps: ModalStateProps) => import("@emotion/react/types/jsx-namespace").EmotionJSX.Element;
7
+ export default CookieConsentModal;
@@ -0,0 +1 @@
1
+ export { default as CookieConsentModal } from "./cookie-consent-modal.js";
@@ -0,0 +1,4 @@
1
+ export { useCookieConsent } from "./use-cookie-consent/index.js";
2
+ export { useSkipCookieConsent } from "./use-skip-cookie-consent/index.js";
3
+ export { CookieConsentModal } from "./cookie-consent-modal/index.js";
4
+ export { CookieConsentBanner } from "./cookie-consent-banner/index.js";
@@ -0,0 +1 @@
1
+ export { useCookieConsent } from "./use-cookie-consent.js";
@@ -0,0 +1,10 @@
1
+ import { setConsentCookie, COOKIE_CONSENT_GROUPS } from "../../core/index.js";
2
+ type TConsentOptions = {
3
+ skipConsent?: boolean;
4
+ cookieName?: string;
5
+ };
6
+ declare function useCookieConsent(consentGroup: keyof typeof COOKIE_CONSENT_GROUPS, { skipConsent, cookieName }?: TConsentOptions): {
7
+ givenConsent: boolean;
8
+ setConsent: typeof setConsentCookie;
9
+ };
10
+ export { useCookieConsent };
@@ -0,0 +1 @@
1
+ export { useSkipCookieConsent } from "./use-skip-cookie-consent.js";
@@ -0,0 +1,2 @@
1
+ declare function useSkipCookieConsent(): boolean;
2
+ export { useSkipCookieConsent };
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@commercetools-frontend/cookie-consent",
3
+ "version": "0.0.0-FEC-212-react19-20250122084835",
4
+ "description": "A package integrating with OneTrust cookie consent",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/commercetools/merchant-center-frontend.git",
8
+ "directory": "packages-shared/cookie-consent"
9
+ },
10
+ "license": "MIT",
11
+ "main": "dist/commercetools-frontend-cookie-consent.cjs.js",
12
+ "module": "dist/commercetools-frontend-cookie-consent.esm.js",
13
+ "files": [
14
+ "dist",
15
+ "core",
16
+ "react",
17
+ "package.json",
18
+ "LICENSE",
19
+ "README.md"
20
+ ],
21
+ "dependencies": {
22
+ "@babel/core": "^7.22.11",
23
+ "@babel/runtime-corejs3": "^7.21.0",
24
+ "@commercetools-frontend/application-components": "0.0.0-fec-156-react19-20250117164550",
25
+ "@commercetools-uikit/collapsible-panel": "0.0.0-fec-155-react-19-20250117211328",
26
+ "@commercetools-uikit/design-system": "0.0.0-fec-155-react-19-20250117211328",
27
+ "@commercetools-uikit/grid": "0.0.0-fec-155-react-19-20250117211328",
28
+ "@commercetools-uikit/link": "0.0.0-fec-155-react-19-20250117211328",
29
+ "@commercetools-uikit/primary-button": "0.0.0-fec-155-react-19-20250117211328",
30
+ "@commercetools-uikit/spacings": "0.0.0-fec-155-react-19-20250117211328",
31
+ "@commercetools-uikit/text": "0.0.0-fec-155-react-19-20250117211328",
32
+ "@commercetools-uikit/toggle-input": "0.0.0-fec-155-react-19-20250117211328"
33
+ },
34
+ "devDependencies": {
35
+ "@apollo/client": "3.7.10",
36
+ "@commercetools-frontend/application-shell": "0.0.0-fec-156-react19-20250117164550",
37
+ "@commercetools-frontend/application-shell-connectors": "0.0.0-fec-156-react19-20250117164550",
38
+ "@emotion/react": "11.13.3",
39
+ "@testing-library/react": "16.1.0",
40
+ "@types/jest": "^29.5.2",
41
+ "@types/node": "20.17.13",
42
+ "@types/react": "19.0.0",
43
+ "@types/testing-library__jest-dom": "^5.14.6",
44
+ "react": "19.0.0",
45
+ "react-intl": "6.6.8",
46
+ "typescript": "5.2.2"
47
+ },
48
+ "peerDependencies": {
49
+ "@commercetools-frontend/application-shell": "0.0.0-fec-156-react19-20250117164550",
50
+ "@commercetools-frontend/application-shell-connectors": "0.0.0-fec-156-react19-20250117164550",
51
+ "@emotion/react": "11.x",
52
+ "react": "19.x",
53
+ "react-intl": "6.x"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "preconstruct": {
59
+ "entrypoints": [
60
+ "./core/index.ts",
61
+ "./react/index.ts"
62
+ ]
63
+ },
64
+ "scripts": {
65
+ "typecheck": "tsc --noEmit"
66
+ }
67
+ }
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/react/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy1mcm9udGVuZC1jb29raWUtY29uc2VudC1yZWFjdC5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL2Rpc3QvZGVjbGFyYXRpb25zL3NyYy9yZWFjdC9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=