chefcookie 2.5.4 → 2.5.7
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 +4 -0
- package/_build/_helper.js +6 -43
- package/_build/script.js +60 -39
- package/chefcookie.min.js +8 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -82,6 +82,7 @@ const cc = new chefcookie({
|
|
|
82
82
|
expiration: 7, // in days
|
|
83
83
|
cookie_prefix: 'cc_', // switch cookie prefix (e.g. for different pages on the same top level domain)
|
|
84
84
|
exclude_ua_regex: /(Speed Insights|Chrome-Lighthouse|PSTS[\d\.]+)/,
|
|
85
|
+
//domain: undefined,
|
|
85
86
|
style: {
|
|
86
87
|
layout: 'overlay', // overlay|bottombar|topbar
|
|
87
88
|
size: 3, // 1|2|3|4|5
|
|
@@ -415,6 +416,9 @@ this only gets executed when you call `resolve()` inside your custom tracking fu
|
|
|
415
416
|
the cookie banner is shown always, if no consent is saved.\
|
|
416
417
|
if done so, it is shown again, after the cookie expired (see the `expiration`-setting).
|
|
417
418
|
|
|
419
|
+
cookies are valid by default for the 2nd level domain of the site. e.g if the banner is on www.foo.bar, the cookie domain will be foo.bar, so the user's choices will be valid for www.foo.bar, xxx.foo.bar, ...\
|
|
420
|
+
there is an option to customize the domain using the `domain`-settings. setting the domain to `undefined` means using cookies only for the current site.
|
|
421
|
+
|
|
418
422
|
it is recommended to include a (re)opening link in the privacy policy, for example.\
|
|
419
423
|
here you can also use the following code:
|
|
420
424
|
|
package/_build/_helper.js
CHANGED
|
@@ -17,48 +17,6 @@ var helper = /*#__PURE__*/function () {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
(0, _createClass2.default)(helper, null, [{
|
|
20
|
-
key: "cookieExists",
|
|
21
|
-
value: function cookieExists(cookie_name) {
|
|
22
|
-
if (document.cookie !== undefined && this.cookieGet(cookie_name) !== null) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}, {
|
|
29
|
-
key: "cookieGet",
|
|
30
|
-
value: function cookieGet(cookie_name) {
|
|
31
|
-
var cookie_match = document.cookie.match(new RegExp(cookie_name + '=([^;]+)'));
|
|
32
|
-
|
|
33
|
-
if (cookie_match) {
|
|
34
|
-
return cookie_match[1];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
}, {
|
|
40
|
-
key: "cookieSet",
|
|
41
|
-
value: function cookieSet(cookie_name, cookie_value, days) {
|
|
42
|
-
var samesite = '';
|
|
43
|
-
|
|
44
|
-
if (window.location.protocol.indexOf('https') > -1) {
|
|
45
|
-
samesite = '; SameSite=None; Secure';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
document.cookie = cookie_name + '=' + cookie_value + '; ' + 'expires=' + new Date(new Date().getTime() + days * 24 * 60 * 60 * 1000).toUTCString() + '; path=/' + samesite + '; domain=' + this.urlHostTopLevel();
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: "cookieDelete",
|
|
52
|
-
value: function cookieDelete(cookie_name) {
|
|
53
|
-
var samesite = '';
|
|
54
|
-
|
|
55
|
-
if (window.location.protocol.indexOf('https') > -1) {
|
|
56
|
-
samesite = '; SameSite=None; Secure';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
document.cookie = cookie_name + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/' + samesite + '; domain=' + this.urlHostTopLevel();
|
|
60
|
-
}
|
|
61
|
-
}, {
|
|
62
20
|
key: "getParam",
|
|
63
21
|
value: function getParam(variable) {
|
|
64
22
|
var url = window.location.search;
|
|
@@ -83,7 +41,12 @@ var helper = /*#__PURE__*/function () {
|
|
|
83
41
|
}, {
|
|
84
42
|
key: "urlHostTopLevel",
|
|
85
43
|
value: function urlHostTopLevel() {
|
|
86
|
-
var host = window.location.hostname;
|
|
44
|
+
var host = window.location.hostname; // ipv4
|
|
45
|
+
|
|
46
|
+
if (host.match(/^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/)) {
|
|
47
|
+
return host;
|
|
48
|
+
}
|
|
49
|
+
|
|
87
50
|
host = host.split('.');
|
|
88
51
|
|
|
89
52
|
while (host.length > 2) {
|
package/_build/script.js
CHANGED
|
@@ -31,6 +31,8 @@ require("@babel/polyfill/noConflict");
|
|
|
31
31
|
|
|
32
32
|
var _helper = _interopRequireDefault(require("./_helper"));
|
|
33
33
|
|
|
34
|
+
var _cookie = _interopRequireDefault(require("cookie"));
|
|
35
|
+
|
|
34
36
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
35
37
|
|
|
36
38
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -40,10 +42,10 @@ var chefcookie = /*#__PURE__*/function () {
|
|
|
40
42
|
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
41
43
|
(0, _classCallCheck2.default)(this, chefcookie);
|
|
42
44
|
var defaults = {
|
|
43
|
-
exclude_ua_regex: /(Speed Insights|Chrome-Lighthouse|PSTS[\d\.]+)
|
|
45
|
+
exclude_ua_regex: /(Speed Insights|Chrome-Lighthouse|PSTS[\d\.]+)/,
|
|
46
|
+
domain: _helper.default.urlHostTopLevel()
|
|
44
47
|
};
|
|
45
|
-
this.config = _objectSpread(_objectSpread({}, defaults), config);
|
|
46
|
-
console.log(this.config); // add dummy entries for empty groups
|
|
48
|
+
this.config = _objectSpread(_objectSpread({}, defaults), config); // add dummy entries for empty groups
|
|
47
49
|
|
|
48
50
|
this.config.settings.forEach(function (group, i) {
|
|
49
51
|
if (!('scripts' in group) || Object.keys(group.scripts).length === 0) {
|
|
@@ -634,6 +636,44 @@ var chefcookie = /*#__PURE__*/function () {
|
|
|
634
636
|
el.checked = false;
|
|
635
637
|
});
|
|
636
638
|
}
|
|
639
|
+
}, {
|
|
640
|
+
key: "getCookieExpiration",
|
|
641
|
+
value: function getCookieExpiration() {
|
|
642
|
+
var expiration = 30;
|
|
643
|
+
|
|
644
|
+
if ('expiration' in this.config && Number.isInteger(this.config.expiration)) {
|
|
645
|
+
expiration = this.config.expiration;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return expiration;
|
|
649
|
+
}
|
|
650
|
+
}, {
|
|
651
|
+
key: "getCookieName",
|
|
652
|
+
value: function getCookieName(cookieName) {
|
|
653
|
+
return (this.config.cookie_prefix || 'cc_') + cookieName;
|
|
654
|
+
}
|
|
655
|
+
}, {
|
|
656
|
+
key: "setCookie",
|
|
657
|
+
value: function setCookie(name, value) {
|
|
658
|
+
var cookie_name = this.getCookieName(name);
|
|
659
|
+
var days = this.getCookieExpiration();
|
|
660
|
+
var cookie_domain = this.config.domain;
|
|
661
|
+
var options = window.location.protocol.indexOf('https') > -1 ? {
|
|
662
|
+
secure: true,
|
|
663
|
+
samesite: 'None'
|
|
664
|
+
} : {};
|
|
665
|
+
document.cookie = _cookie.default.serialize(cookie_name, value, _objectSpread({
|
|
666
|
+
httpOnly: false,
|
|
667
|
+
maxAge: 60 * 60 * 24 * days,
|
|
668
|
+
domain: cookie_domain && window.location.hostname.endsWith(cookie_domain) ? cookie_domain : undefined
|
|
669
|
+
}, options));
|
|
670
|
+
}
|
|
671
|
+
}, {
|
|
672
|
+
key: "getCookie",
|
|
673
|
+
value: function getCookie(name) {
|
|
674
|
+
var cookie_name = this.getCookieName(name);
|
|
675
|
+
return _cookie.default.parse(document.cookie)[cookie_name];
|
|
676
|
+
}
|
|
637
677
|
}, {
|
|
638
678
|
key: "isCheckboxActiveForGroup",
|
|
639
679
|
value: function isCheckboxActiveForGroup(group_index) {
|
|
@@ -696,12 +736,12 @@ var chefcookie = /*#__PURE__*/function () {
|
|
|
696
736
|
}, {
|
|
697
737
|
key: "setCookieToHideOverlay",
|
|
698
738
|
value: function setCookieToHideOverlay() {
|
|
699
|
-
|
|
739
|
+
this.setCookie('hide_prompt', '1');
|
|
700
740
|
}
|
|
701
741
|
}, {
|
|
702
742
|
key: "isCookieSetToHideOverlay",
|
|
703
743
|
value: function isCookieSetToHideOverlay() {
|
|
704
|
-
return
|
|
744
|
+
return this.getCookie('hide_prompt') !== undefined;
|
|
705
745
|
}
|
|
706
746
|
}, {
|
|
707
747
|
key: "saveInCookie",
|
|
@@ -737,34 +777,32 @@ var chefcookie = /*#__PURE__*/function () {
|
|
|
737
777
|
providers.push('null');
|
|
738
778
|
}
|
|
739
779
|
|
|
740
|
-
|
|
780
|
+
this.setCookie('accepted_providers', providers.join(','));
|
|
741
781
|
}
|
|
742
782
|
}, {
|
|
743
783
|
key: "addToCookie",
|
|
744
784
|
value: function addToCookie(provider) {
|
|
745
785
|
var providers;
|
|
746
786
|
|
|
747
|
-
if (
|
|
787
|
+
if (this.getCookie('accepted_providers') === undefined || this.getCookie('accepted_providers') === 'null') {
|
|
748
788
|
providers = [];
|
|
749
789
|
} else {
|
|
750
|
-
providers =
|
|
790
|
+
providers = this.getCookie('accepted_providers').split(',');
|
|
751
791
|
}
|
|
752
792
|
|
|
753
793
|
if (providers.indexOf(provider) === -1) {
|
|
754
794
|
providers.push(provider);
|
|
755
|
-
|
|
756
|
-
_helper.default.cookieSet(this.getCookieName('accepted_providers'), providers.join(','), this.getCookieExpiration());
|
|
795
|
+
this.setCookie('accepted_providers', providers.join(','));
|
|
757
796
|
}
|
|
758
797
|
}
|
|
759
798
|
}, {
|
|
760
799
|
key: "deleteFromCookie",
|
|
761
800
|
value: function deleteFromCookie(provider) {
|
|
762
|
-
if (
|
|
801
|
+
if (this.getCookie('accepted_providers') === undefined) {
|
|
763
802
|
return;
|
|
764
803
|
}
|
|
765
804
|
|
|
766
|
-
var providers =
|
|
767
|
-
|
|
805
|
+
var providers = this.getCookie('accepted_providers').split(',');
|
|
768
806
|
var index = providers.indexOf(provider);
|
|
769
807
|
|
|
770
808
|
if (index !== -1) {
|
|
@@ -772,26 +810,10 @@ var chefcookie = /*#__PURE__*/function () {
|
|
|
772
810
|
}
|
|
773
811
|
|
|
774
812
|
if (providers.length > 0) {
|
|
775
|
-
|
|
813
|
+
this.setCookie('accepted_providers', providers.join(','));
|
|
776
814
|
} else {
|
|
777
|
-
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
}, {
|
|
781
|
-
key: "getCookieExpiration",
|
|
782
|
-
value: function getCookieExpiration() {
|
|
783
|
-
var expiration = 30;
|
|
784
|
-
|
|
785
|
-
if ('expiration' in this.config && Number.isInteger(this.config.expiration)) {
|
|
786
|
-
expiration = this.config.expiration;
|
|
815
|
+
this.setCookie('accepted_providers', 'null');
|
|
787
816
|
}
|
|
788
|
-
|
|
789
|
-
return expiration;
|
|
790
|
-
}
|
|
791
|
-
}, {
|
|
792
|
-
key: "getCookieName",
|
|
793
|
-
value: function getCookieName(cookieName) {
|
|
794
|
-
return (this.config.cookie_prefix || 'cc_') + cookieName;
|
|
795
817
|
}
|
|
796
818
|
}, {
|
|
797
819
|
key: "addEnabledScripts",
|
|
@@ -800,11 +822,11 @@ var chefcookie = /*#__PURE__*/function () {
|
|
|
800
822
|
|
|
801
823
|
var isInit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
802
824
|
|
|
803
|
-
if (
|
|
825
|
+
if (this.getCookie('accepted_providers') === undefined) {
|
|
804
826
|
return;
|
|
805
827
|
}
|
|
806
828
|
|
|
807
|
-
var settings =
|
|
829
|
+
var settings = this.getCookie('accepted_providers');
|
|
808
830
|
|
|
809
831
|
if (settings == 'null') {
|
|
810
832
|
return;
|
|
@@ -839,17 +861,16 @@ var chefcookie = /*#__PURE__*/function () {
|
|
|
839
861
|
|
|
840
862
|
var isInit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
841
863
|
|
|
842
|
-
if (
|
|
864
|
+
if (this.getCookie('accepted_providers') === undefined) {
|
|
843
865
|
return;
|
|
844
866
|
}
|
|
845
867
|
|
|
846
|
-
var settings =
|
|
868
|
+
var settings = this.getCookie('accepted_providers').split(',');
|
|
847
869
|
|
|
848
|
-
if (settings
|
|
870
|
+
if (settings === ['null']) {
|
|
849
871
|
return;
|
|
850
872
|
}
|
|
851
873
|
|
|
852
|
-
settings = settings.split(',');
|
|
853
874
|
this.config.settings.forEach(function (settings__value) {
|
|
854
875
|
if (settings__value.scripts !== undefined) {
|
|
855
876
|
Object.entries(settings__value.scripts).forEach(function (_ref6) {
|
|
@@ -1092,11 +1113,11 @@ var chefcookie = /*#__PURE__*/function () {
|
|
|
1092
1113
|
}, {
|
|
1093
1114
|
key: "isAccepted",
|
|
1094
1115
|
value: function isAccepted(provider) {
|
|
1095
|
-
if (
|
|
1116
|
+
if (this.getCookie('accepted_providers') === undefined) {
|
|
1096
1117
|
return false;
|
|
1097
1118
|
}
|
|
1098
1119
|
|
|
1099
|
-
return
|
|
1120
|
+
return this.getCookie('accepted_providers').split(',').indexOf(provider) > -1;
|
|
1100
1121
|
}
|
|
1101
1122
|
}, {
|
|
1102
1123
|
key: "isLoaded",
|