@nortic/citronkaka-service 0.2.0 → 0.2.2
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 +11 -15
- package/dist/index.iife.js +1 -1
- package/package.json +11 -11
package/dist/index.es.js
CHANGED
|
@@ -14,8 +14,8 @@ const h = {
|
|
|
14
14
|
};
|
|
15
15
|
class p {
|
|
16
16
|
static createCookieString(e, t, o = {}) {
|
|
17
|
-
const { expires: s, path: r = "/", sameSite: i = "Strict", domain: n } = o,
|
|
18
|
-
return `${e}=${
|
|
17
|
+
const { expires: s, path: r = "/", sameSite: i = "Strict", domain: n } = o, a = encodeURIComponent(t), u = s ? `; expires=${s.toUTCString()}` : "", d = n ? `; domain=${n}` : "";
|
|
18
|
+
return `${e}=${a}${u}; path=${r}; SameSite=${i}${d}`;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Sets a cookie with the specified options.
|
|
@@ -37,7 +37,7 @@ class p {
|
|
|
37
37
|
const t = document.cookie.match(new RegExp(`(^| )${e}=([^;]+)`));
|
|
38
38
|
if (!t)
|
|
39
39
|
return null;
|
|
40
|
-
const o = decodeURIComponent(t[2]);
|
|
40
|
+
const o = decodeURIComponent(t[2] ?? "");
|
|
41
41
|
try {
|
|
42
42
|
return JSON.parse(o);
|
|
43
43
|
} catch {
|
|
@@ -64,7 +64,7 @@ class k {
|
|
|
64
64
|
static run(e, t = p) {
|
|
65
65
|
function o(s) {
|
|
66
66
|
document.cookie.split(";").forEach((r) => {
|
|
67
|
-
const i = r.split("=")[0].trim();
|
|
67
|
+
const i = (r.split("=")[0] ?? "").trim();
|
|
68
68
|
s.test(i) && (t.delete(i), console.warn(`Removed cookie: ${i}`));
|
|
69
69
|
});
|
|
70
70
|
}
|
|
@@ -92,17 +92,15 @@ class m {
|
|
|
92
92
|
* @returns The current cookies as a string.
|
|
93
93
|
*/
|
|
94
94
|
get() {
|
|
95
|
-
|
|
96
|
-
return ((o = t.get) == null ? void 0 : o.call(document)) || "";
|
|
95
|
+
return t.get?.call(document) || "";
|
|
97
96
|
},
|
|
98
97
|
/**
|
|
99
98
|
* Setter for `document.cookie`. Intercepts and blocks cookies based on the blacklist.
|
|
100
99
|
* @param cookieString The cookie string to be set.
|
|
101
100
|
*/
|
|
102
101
|
set(o) {
|
|
103
|
-
|
|
104
|
-
|
|
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}`);
|
|
102
|
+
const s = (o?.split("=")[0] ?? "").trim(), r = o.match(/expires=([^;]+)/i);
|
|
103
|
+
(r && typeof r[1] == "string" ? new Date(r[1]).getTime() < Date.now() : !1) || !e.some((n) => n.test(s)) ? t.set?.call(document, o) : console.warn(`Blocked cookie: ${s}`);
|
|
106
104
|
}
|
|
107
105
|
});
|
|
108
106
|
}
|
|
@@ -142,16 +140,14 @@ class l {
|
|
|
142
140
|
configurable: !0,
|
|
143
141
|
enumerable: !0,
|
|
144
142
|
get() {
|
|
145
|
-
|
|
146
|
-
return (n = i.get) == null ? void 0 : n.call(r);
|
|
143
|
+
return i.get?.call(r);
|
|
147
144
|
},
|
|
148
145
|
set(n) {
|
|
149
|
-
var c;
|
|
150
146
|
if (l.shouldBlockScript(e, n)) {
|
|
151
147
|
console.warn(`Blocked script: ${n}`), r.type = "javascript/blocked";
|
|
152
148
|
return;
|
|
153
149
|
}
|
|
154
|
-
|
|
150
|
+
i.set?.call(r, n);
|
|
155
151
|
}
|
|
156
152
|
});
|
|
157
153
|
}
|
|
@@ -171,8 +167,8 @@ class l {
|
|
|
171
167
|
const i = r;
|
|
172
168
|
if (i.src && this.shouldBlockScript(e, i.src)) {
|
|
173
169
|
console.warn(`Blocked dynamically added script: ${i.src}`), i.type = "javascript/blocked";
|
|
174
|
-
const n = (
|
|
175
|
-
i.getAttribute("type") === "javascript/blocked" && (
|
|
170
|
+
const n = (a) => {
|
|
171
|
+
i.getAttribute("type") === "javascript/blocked" && (a.preventDefault(), console.warn(`Prevented execution of blocked script: ${i.src}`)), i.removeEventListener("beforescriptexecute", n);
|
|
176
172
|
};
|
|
177
173
|
i.addEventListener("beforescriptexecute", n);
|
|
178
174
|
}
|
package/dist/index.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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:[]};class p{static createCookieString(e,t,o={}){const{expires:s,path:r="/",sameSite:i="Strict",domain:n}=o,
|
|
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:[]};class p{static createCookieString(e,t,o={}){const{expires:s,path:r="/",sameSite:i="Strict",domain:n}=o,l=encodeURIComponent(t),m=s?`; expires=${s.toUTCString()}`:"",g=n?`; domain=${n}`:"";return`${e}=${l}${m}; 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 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 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(){return t.get?.call(document)||""},set(o){const s=(o?.split("=")[0]??"").trim(),r=o.match(/expires=([^;]+)/i);(r&&typeof r[1]=="string"?new Date(r[1]).getTime()<Date.now():!1)||!e.some(n=>n.test(s))?t.set?.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(){return i.get?.call(r)},set(n){if(a.shouldBlockScript(e,n)){console.warn(`Blocked script: ${n}`),r.type="javascript/blocked";return}i.set?.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=l=>{i.getAttribute("type")==="javascript/blocked"&&(l.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=d,t={update:[]},o=p,s=f,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)}init(e={}){this.config={...this.config,...e},this.cookieCleaner.run(this.blacklist.cookies),this.cookieInterceptor.run(this.blacklist.cookies),this.scriptInterceptor.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})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nortic/citronkaka-service",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@tsconfig/node20": "^20.1.
|
|
25
|
-
"@types/jsdom": "^
|
|
26
|
-
"@types/node": "^
|
|
27
|
-
"@vue/tsconfig": "^0.
|
|
28
|
-
"jsdom": "^
|
|
29
|
-
"npm-run-all2": "^
|
|
30
|
-
"typescript": "~5.
|
|
31
|
-
"vite": "^
|
|
32
|
-
"vite-plugin-dts": "^4.5.
|
|
33
|
-
"vitest": "^
|
|
24
|
+
"@tsconfig/node20": "^20.1.8",
|
|
25
|
+
"@types/jsdom": "^27.0.0",
|
|
26
|
+
"@types/node": "^24.10.1",
|
|
27
|
+
"@vue/tsconfig": "^0.8.1",
|
|
28
|
+
"jsdom": "^27.2.0",
|
|
29
|
+
"npm-run-all2": "^8.0.4",
|
|
30
|
+
"typescript": "~5.9.3",
|
|
31
|
+
"vite": "^7.2.6",
|
|
32
|
+
"vite-plugin-dts": "^4.5.4",
|
|
33
|
+
"vitest": "^4.0.15"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"dev": "vite build --watch",
|