@nortic/citronkaka-service 0.0.2-beta.32 → 0.1.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/dist/index.es.js +30 -30
- package/dist/index.iife.js +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const f = { BASE_URL: "/", DEV: !1, DOMAIN: "
|
|
1
|
+
const f = { BASE_URL: "/", DEV: !1, DOMAIN: ".nortic.io", MODE: "production", NODE_ENV: "production", PROD: !0, SSR: !1 }, { DOMAIN: m } = f, k = {
|
|
2
2
|
domain: m,
|
|
3
3
|
defaultModel: {
|
|
4
4
|
useraction: !1,
|
|
@@ -14,8 +14,8 @@ const f = { BASE_URL: "/", DEV: !1, DOMAIN: "localhost", MODE: "development", NO
|
|
|
14
14
|
};
|
|
15
15
|
class p {
|
|
16
16
|
static createCookieString(e, t, o = {}) {
|
|
17
|
-
const { expires:
|
|
18
|
-
return `${e}=${c}${u}; path=${r}; SameSite=${
|
|
17
|
+
const { expires: s, path: r = "/", sameSite: i = "Strict", domain: n } = o, c = encodeURIComponent(t), u = s ? `; expires=${s.toUTCString()}` : "", d = n ? `; domain=${n}` : "";
|
|
18
|
+
return `${e}=${c}${u}; path=${r}; SameSite=${i}${d}`;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Sets a cookie with the specified options.
|
|
@@ -24,9 +24,9 @@ class p {
|
|
|
24
24
|
* @param days Number of days until the cookie expires.
|
|
25
25
|
* @param domain Optional domain for the cookie.
|
|
26
26
|
*/
|
|
27
|
-
static set(e, t, o,
|
|
28
|
-
const r = typeof t == "string" ? t : JSON.stringify(t),
|
|
29
|
-
document.cookie = this.createCookieString(e, r, { expires:
|
|
27
|
+
static set(e, t, o, s) {
|
|
28
|
+
const r = typeof t == "string" ? t : JSON.stringify(t), i = new Date(Date.now() + o * 24 * 60 * 60 * 1e3);
|
|
29
|
+
document.cookie = this.createCookieString(e, r, { expires: i, domain: s });
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Retrieves the value of a cookie by name.
|
|
@@ -62,14 +62,14 @@ class h {
|
|
|
62
62
|
* @param blacklist An array of RegExp patterns for cookies to delete.
|
|
63
63
|
*/
|
|
64
64
|
static run(e, t = p) {
|
|
65
|
-
function o(
|
|
65
|
+
function o(s) {
|
|
66
66
|
document.cookie.split(";").forEach((r) => {
|
|
67
|
-
const
|
|
68
|
-
|
|
67
|
+
const i = r.split("=")[0].trim();
|
|
68
|
+
s.test(i) && (t.delete(i), console.warn(`Removed cookie: ${i}`));
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
|
-
e.forEach((
|
|
72
|
-
o(
|
|
71
|
+
e.forEach((s) => {
|
|
72
|
+
o(s);
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -101,8 +101,8 @@ class y {
|
|
|
101
101
|
*/
|
|
102
102
|
set(o) {
|
|
103
103
|
var n;
|
|
104
|
-
const
|
|
105
|
-
(r ? new Date(r[1]).getTime() < Date.now() : !1) || !e.some((c) => c.test(
|
|
104
|
+
const s = o.split("=")[0].trim(), r = o.match(/expires=([^;]+)/i);
|
|
105
|
+
(r ? new Date(r[1]).getTime() < Date.now() : !1) || !e.some((c) => c.test(s)) ? (n = t.set) == null || n.call(document, o) : console.warn(`Blocked cookie: ${s}`);
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
108
|
}
|
|
@@ -132,18 +132,18 @@ class l {
|
|
|
132
132
|
static interceptScriptCreation(e) {
|
|
133
133
|
const t = document.createElement.bind(document);
|
|
134
134
|
document.createElement = function(o) {
|
|
135
|
-
const
|
|
135
|
+
const s = t(o);
|
|
136
136
|
if (o.toLowerCase() === "script") {
|
|
137
|
-
const r =
|
|
137
|
+
const r = s, i = Object.getOwnPropertyDescriptor(
|
|
138
138
|
HTMLScriptElement.prototype,
|
|
139
139
|
"src"
|
|
140
140
|
);
|
|
141
|
-
|
|
141
|
+
i && Object.defineProperty(r, "src", {
|
|
142
142
|
configurable: !0,
|
|
143
143
|
enumerable: !0,
|
|
144
144
|
get() {
|
|
145
145
|
var n;
|
|
146
|
-
return (n =
|
|
146
|
+
return (n = i.get) == null ? void 0 : n.call(r);
|
|
147
147
|
},
|
|
148
148
|
set(n) {
|
|
149
149
|
var c;
|
|
@@ -151,11 +151,11 @@ class l {
|
|
|
151
151
|
console.warn(`Blocked script: ${n}`), r.type = "javascript/blocked";
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
|
-
(c =
|
|
154
|
+
(c = i.set) == null || c.call(r, n);
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
|
-
return
|
|
158
|
+
return s;
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
161
|
/**
|
|
@@ -165,16 +165,16 @@ class l {
|
|
|
165
165
|
*/
|
|
166
166
|
static observeDynamicScripts(e) {
|
|
167
167
|
new MutationObserver((o) => {
|
|
168
|
-
o.forEach(({ addedNodes:
|
|
169
|
-
|
|
168
|
+
o.forEach(({ addedNodes: s }) => {
|
|
169
|
+
s.forEach((r) => {
|
|
170
170
|
if (r.nodeType === Node.ELEMENT_NODE && r.tagName === "SCRIPT") {
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
console.warn(`Blocked dynamically added script: ${
|
|
171
|
+
const i = r;
|
|
172
|
+
if (i.src && this.shouldBlockScript(e, i.src)) {
|
|
173
|
+
console.warn(`Blocked dynamically added script: ${i.src}`), i.type = "javascript/blocked";
|
|
174
174
|
const n = (c) => {
|
|
175
|
-
|
|
175
|
+
i.getAttribute("type") === "javascript/blocked" && (c.preventDefault(), console.warn(`Prevented execution of blocked script: ${i.src}`)), i.removeEventListener("beforescriptexecute", n);
|
|
176
176
|
};
|
|
177
|
-
|
|
177
|
+
i.addEventListener("beforescriptexecute", n);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
});
|
|
@@ -186,8 +186,8 @@ class l {
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
class g {
|
|
189
|
-
constructor(e = k, t = { update: [] }, o = p,
|
|
190
|
-
this.config = e, this.listeners = t, this.persistentService = o, this.cookieCleaner =
|
|
189
|
+
constructor(e = k, t = { update: [] }, o = p, s = h, r = y, i = l) {
|
|
190
|
+
this.config = e, this.listeners = t, this.persistentService = o, this.cookieCleaner = s, this.cookieInterceptor = r, this.scriptInterceptor = i, s.run(this.blacklist.cookies), r.run(this.blacklist.cookies), i.run(this.blacklist.scripts);
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* Retrieves the current cookie consent model from persistent storage.
|
|
@@ -241,8 +241,8 @@ class g {
|
|
|
241
241
|
get blacklist() {
|
|
242
242
|
return this.config.services.reduce((e, t) => {
|
|
243
243
|
if (this.model.value[t.category] === !1) {
|
|
244
|
-
const { cookies: o, scripts:
|
|
245
|
-
e.cookies = e.cookies.concat(o), e.scripts = e.scripts.concat(
|
|
244
|
+
const { cookies: o, scripts: s } = t;
|
|
245
|
+
e.cookies = e.cookies.concat(o), e.scripts = e.scripts.concat(s);
|
|
246
246
|
}
|
|
247
247
|
return e;
|
|
248
248
|
}, { cookies: [], scripts: [] });
|
package/dist/index.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Citronkaka=function(){"use strict";const u={BASE_URL:"/",DEV:!1,DOMAIN:"
|
|
1
|
+
var Citronkaka=function(){"use strict";const u={BASE_URL:"/",DEV:!1,DOMAIN:".nortic.io",MODE:"production",NODE_ENV:"production",PROD:!0,SSR:!1},{DOMAIN:d}=u,f={domain:d,defaultModel:{useraction:!1,value:{necessary:!0,functional:!1,analytics:!1,marketing:!1}},persistentKey:"nortic_cookie_consent",persistentExpirationDays:365,categories:["necessary","functional","analytics","marketing"],services:[{name:"Translations",category:"functional",scripts:[],cookies:[/^i18n_redirected/]},{name:"Color mode",category:"functional",scripts:[],cookies:[/^color-mode/]}]};class p{static createCookieString(e,t,o={}){const{expires:s,path:r="/",sameSite:i="Strict",domain:n}=o,c=encodeURIComponent(t),y=s?`; expires=${s.toUTCString()}`:"",g=n?`; domain=${n}`:"";return`${e}=${c}${y}; path=${r}; SameSite=${i}${g}`}static set(e,t,o,s){const r=typeof t=="string"?t:JSON.stringify(t),i=new Date(Date.now()+o*24*60*60*1e3);document.cookie=this.createCookieString(e,r,{expires:i,domain:s})}static get(e){const t=document.cookie.match(new RegExp(`(^| )${e}=([^;]+)`));if(!t)return null;const o=decodeURIComponent(t[2]);try{return JSON.parse(o)}catch{return o}}static delete(e,t){document.cookie=this.createCookieString(e,"",{expires:new Date(0),domain:t})}}class m{static run(e,t=p){function o(s){document.cookie.split(";").forEach(r=>{const i=r.split("=")[0].trim();s.test(i)&&(t.delete(i),console.warn(`Removed cookie: ${i}`))})}e.forEach(s=>{o(s)})}}class k{static run(e){const t=Object.getOwnPropertyDescriptor(Document.prototype,"cookie");if(!t){console.error("Failed to retrieve the cookie property descriptor.");return}Object.defineProperty(document,"cookie",{configurable:!0,enumerable:!0,get(){var o;return((o=t.get)==null?void 0:o.call(document))||""},set(o){var n;const s=o.split("=")[0].trim(),r=o.match(/expires=([^;]+)/i);(r?new Date(r[1]).getTime()<Date.now():!1)||!e.some(c=>c.test(s))?(n=t.set)==null||n.call(document,o):console.warn(`Blocked cookie: ${s}`)}})}}class a{static run(e){this.interceptScriptCreation(e),this.observeDynamicScripts(e)}static shouldBlockScript(e,t){return e.some(o=>o.test(t))}static interceptScriptCreation(e){const t=document.createElement.bind(document);document.createElement=function(o){const s=t(o);if(o.toLowerCase()==="script"){const r=s,i=Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype,"src");i&&Object.defineProperty(r,"src",{configurable:!0,enumerable:!0,get(){var n;return(n=i.get)==null?void 0:n.call(r)},set(n){var c;if(a.shouldBlockScript(e,n)){console.warn(`Blocked script: ${n}`),r.type="javascript/blocked";return}(c=i.set)==null||c.call(r,n)}})}return s}}static observeDynamicScripts(e){new MutationObserver(o=>{o.forEach(({addedNodes:s})=>{s.forEach(r=>{if(r.nodeType===Node.ELEMENT_NODE&&r.tagName==="SCRIPT"){const i=r;if(i.src&&this.shouldBlockScript(e,i.src)){console.warn(`Blocked dynamically added script: ${i.src}`),i.type="javascript/blocked";const n=c=>{i.getAttribute("type")==="javascript/blocked"&&(c.preventDefault(),console.warn(`Prevented execution of blocked script: ${i.src}`)),i.removeEventListener("beforescriptexecute",n)};i.addEventListener("beforescriptexecute",n)}}})})}).observe(document.documentElement,{childList:!0,subtree:!0})}}class h{constructor(e=f,t={update:[]},o=p,s=m,r=k,i=a){this.config=e,this.listeners=t,this.persistentService=o,this.cookieCleaner=s,this.cookieInterceptor=r,this.scriptInterceptor=i,s.run(this.blacklist.cookies),r.run(this.blacklist.cookies),i.run(this.blacklist.scripts)}get model(){const e=this.persistentService.get(this.config.persistentKey);return this.isCookieConsentModel(e)?e:this.config.defaultModel}set model(e){if(!this.isCookieConsentModel(e))throw new Error("Invalid model: The provided value is not a valid CookieConsentModel.");this.persistentService.set(this.config.persistentKey,e,this.config.persistentExpirationDays,this.config.domain)}update(e){this.model={useraction:!0,value:e},this.notifyListeners("update")}on(e,t){this.listeners[e].push(t)}notifyListeners(e){this.listeners[e].forEach(t=>t(this.model))}get blacklist(){return this.config.services.reduce((e,t)=>{if(this.model.value[t.category]===!1){const{cookies:o,scripts:s}=t;e.cookies=e.cookies.concat(o),e.scripts=e.scripts.concat(s)}return e},{cookies:[],scripts:[]})}isCookieConsentModel(e){if(typeof e!="object"||e===null)return!1;const t=e;if(typeof t.useraction!="boolean"||typeof t.value!="object"||t.value===null)return!1;const o=t.value;return o.necessary===!0&&typeof o.functional=="boolean"&&typeof o.analytics=="boolean"&&typeof o.marketing=="boolean"}}return window.Citronkaka=window.Citronkaka||new h,window.Citronkaka}();
|