@nortic/citronkaka-service 0.1.0 → 0.1.1
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 +12 -9
- package/dist/index.iife.js +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function f() {
|
|
2
|
+
return location.hostname.split(".").slice(-2).join(".");
|
|
3
|
+
}
|
|
4
|
+
const m = {
|
|
5
|
+
domain: f(),
|
|
3
6
|
defaultModel: {
|
|
4
7
|
useraction: !1,
|
|
5
8
|
value: { necessary: !0, functional: !1, analytics: !1, marketing: !1 }
|
|
@@ -56,7 +59,7 @@ class p {
|
|
|
56
59
|
});
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
|
-
class
|
|
62
|
+
class k {
|
|
60
63
|
/**
|
|
61
64
|
* Cleans up cookies based on a list of blacklist patterns.
|
|
62
65
|
* @param blacklist An array of RegExp patterns for cookies to delete.
|
|
@@ -73,7 +76,7 @@ class h {
|
|
|
73
76
|
});
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
|
-
class
|
|
79
|
+
class h {
|
|
77
80
|
/**
|
|
78
81
|
* Starts the cookie interception process to block cookies based on a blacklist.
|
|
79
82
|
* @param blacklist An array of RegExp patterns for cookie names to block.
|
|
@@ -185,8 +188,8 @@ class l {
|
|
|
185
188
|
});
|
|
186
189
|
}
|
|
187
190
|
}
|
|
188
|
-
class
|
|
189
|
-
constructor(e =
|
|
191
|
+
class y {
|
|
192
|
+
constructor(e = m, t = { update: [] }, o = p, s = k, r = h, i = l) {
|
|
190
193
|
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
194
|
}
|
|
192
195
|
/**
|
|
@@ -262,8 +265,8 @@ class g {
|
|
|
262
265
|
return o.necessary === !0 && typeof o.functional == "boolean" && typeof o.analytics == "boolean" && typeof o.marketing == "boolean";
|
|
263
266
|
}
|
|
264
267
|
}
|
|
265
|
-
window.Citronkaka = window.Citronkaka || new
|
|
266
|
-
const
|
|
268
|
+
window.Citronkaka = window.Citronkaka || new y();
|
|
269
|
+
const g = window.Citronkaka;
|
|
267
270
|
export {
|
|
268
|
-
|
|
271
|
+
g as default
|
|
269
272
|
};
|
package/dist/index.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Citronkaka=function(){"use strict";
|
|
1
|
+
var Citronkaka=function(){"use strict";function u(){return location.hostname.split(".").slice(-2).join(".")}const d={domain:u(),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),h=s?`; expires=${s.toUTCString()}`:"",y=n?`; domain=${n}`:"";return`${e}=${c}${h}; path=${r}; SameSite=${i}${y}`}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 f{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 m{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 l{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(l.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 k{constructor(e=d,t={update:[]},o=p,s=f,r=m,i=l){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 k,window.Citronkaka}();
|