@jini-ai/cookie-consent 0.6.15-rc.1 → 0.6.15-rc.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/client/dom.d.ts +3 -1
- package/dist/client/dom.js +1 -1
- package/dist/client/index.js +7 -4
- package/dist/client.min.js +1 -1
- package/package.json +1 -1
package/dist/client/dom.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @file DOM helpers for the browser client: cookies, storage purge, inert tags and the Jini banner binding.
|
|
2
2
|
* The Jini banner is a client of the public API, exactly like an owner's own ("My own") banner. */
|
|
3
|
-
import { type Choices, type JiniConsentApi, type Optional, type StoragePrefixes } from '../contract.js';
|
|
3
|
+
import { type Choices, type ConsentState, type JiniConsentApi, type Optional, type StoragePrefixes } from '../contract.js';
|
|
4
4
|
/** @complexity O(cookie header). Malformed escapes read as "no value", never throw. */
|
|
5
5
|
export declare function readCookie(doc: Document, name: string): string | null;
|
|
6
6
|
export declare function writeCookie(doc: Document, { name, value, maxAgeS }: {
|
|
@@ -23,6 +23,8 @@ export declare function installOpeners({ api, doc }: {
|
|
|
23
23
|
api: JiniConsentApi;
|
|
24
24
|
doc: Document;
|
|
25
25
|
}): void;
|
|
26
|
+
/** A durable grant that is still waiting for its receipt keeps the banner open with its alert. */
|
|
27
|
+
export declare const waiting: (s: ConsentState) => boolean;
|
|
26
28
|
/** Wire #jini-consent (renderBanner's markup) to the public API. @complexity O(1) per click. */
|
|
27
29
|
export declare function bindBanner({ api, doc }: {
|
|
28
30
|
api: JiniConsentApi;
|
package/dist/client/dom.js
CHANGED
|
@@ -105,7 +105,7 @@ function syncInputs(root, s) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
/** A durable grant that is still waiting for its receipt keeps the banner open with its alert. */
|
|
108
|
-
const waiting = (s) => OPTIONAL.some(c => s.choices[c] && !s.allowed[c]);
|
|
108
|
+
export const waiting = (s) => OPTIONAL.some(c => s.choices[c] && !s.allowed[c]);
|
|
109
109
|
/** Wire #jini-consent (renderBanner's markup) to the public API. @complexity O(1) per click. */
|
|
110
110
|
export function bindBanner({ api, doc }) {
|
|
111
111
|
const root = doc.getElementById('jini-consent');
|
package/dist/client/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { ADAPTER_KIND, CONFIG_ID, CONSENT_COOKIE, OPEN_EVENT, OPTIONAL, READY_EVENT, REGION_COOKIE, STATE_EVENT } from '../contract.js';
|
|
6
6
|
import { choicesFor, DAY_MS, effective, parseStored, RECEIPT_ID, regionFrom } from '../policy.js';
|
|
7
7
|
import { ADAPTER_SLOT, createPluginRegistry } from '../plugins.js';
|
|
8
|
-
import { activateInert, installOpeners, purge, readCookie, writeCookie } from './dom.js';
|
|
8
|
+
import { activateInert, installOpeners, purge, readCookie, waiting, writeCookie } from './dom.js';
|
|
9
9
|
const within = (p, ms) => Promise.race([p, new Promise(r => setTimeout(r, ms))]);
|
|
10
10
|
const quiet = (fn) => { try {
|
|
11
11
|
fn();
|
|
@@ -45,7 +45,7 @@ export function createCookieConsent({ config, ports }, options = {}) {
|
|
|
45
45
|
if (ctl.signal.aborted || anonymous && state.analyticsLevel === 'none')
|
|
46
46
|
return null; // withdrawn first: nothing ran
|
|
47
47
|
return Promise.resolve().then(() => adapter.grant({ config: slot.entry.config ?? adapter.config, state, signal: ctl.signal }))
|
|
48
|
-
.then(r
|
|
48
|
+
.then((r = {}) => r, () => ({})); // a grant that threw may have run code
|
|
49
49
|
}, () => null); // import failed: nothing ran
|
|
50
50
|
slot.run = { ctl, result };
|
|
51
51
|
}
|
|
@@ -118,7 +118,7 @@ export function createCookieConsent({ config, ports }, options = {}) {
|
|
|
118
118
|
persist();
|
|
119
119
|
const now = apply(); // denial is live here, before any network
|
|
120
120
|
const sent = confirm(stored, previousId);
|
|
121
|
-
if (durable &&
|
|
121
|
+
if (durable && waiting(now))
|
|
122
122
|
await within(sent, durable.waitMs ?? 1500);
|
|
123
123
|
return state;
|
|
124
124
|
}
|
|
@@ -154,7 +154,7 @@ export function createCookieConsent({ config, ports }, options = {}) {
|
|
|
154
154
|
// A refused cookie write leaves only this tab's choice; absence cannot supersede it.
|
|
155
155
|
if (!latest && !cookiePersisted)
|
|
156
156
|
return false;
|
|
157
|
-
if (
|
|
157
|
+
if (sameStoredChoice({ latest, stored }))
|
|
158
158
|
return false;
|
|
159
159
|
stored = latest;
|
|
160
160
|
apply();
|
|
@@ -178,6 +178,9 @@ export function createCookieConsent({ config, ports }, options = {}) {
|
|
|
178
178
|
void confirm(stored); // durable retry of an earlier failed receipt
|
|
179
179
|
return api;
|
|
180
180
|
}
|
|
181
|
+
function sameStoredChoice({ latest, stored }) {
|
|
182
|
+
return latest?.t === stored?.t && latest?.a === stored?.a && latest?.r === stored?.r;
|
|
183
|
+
}
|
|
181
184
|
function durableEvidence({ evidence }, _optional = {}) {
|
|
182
185
|
return evidence?.mode === 'durable' ? evidence : null;
|
|
183
186
|
}
|
package/dist/client.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";(()=>{var R="jini_choices",J="jini_region",$="jini:consent",B="jini:consent-ready",O="jini:consent-open",G="jini-consent-config",S=["functional","analytics","marketing"],Te=["necessary",...S],V=["accept","reject","save","do-not-sell","withdraw"];var k="consent-adapter";var le='script[type="text/plain"][data-consent-category],iframe[data-consent-category][data-src]',ue=new Set(["type","data-src","data-type","data-consent-category"]),de=':not(html)[data-consent-open],a[href="#privacy-choices"]';function T(e,t){let n=e.cookie.split(/;\s*/).find(o=>o.startsWith(t+"="));try{return n?decodeURIComponent(n.slice(t.length+1)):null}catch{return null}}function W(e,{name:t,value:n,maxAgeS:o},{domain:r}={}){let p=e.defaultView?.location.protocol==="https:"?"; Secure":"";e.cookie=`${t}=${encodeURIComponent(n)}; Path=/; Max-Age=${Math.floor(o)}; SameSite=Lax${p}${r?`; Domain=${r}`:""}`}function pe(e,t){let n=(e.defaultView?.location.hostname??"").split(".");e.cookie=`${t}=; Path=/; Max-Age=0`;for(let o=0;o<n.length-1;o++)e.cookie=`${t}=; Path=/; Max-Age=0; Domain=.${n.slice(o).join(".")}`}function _(e,t){if(t){for(let n of e.cookie.split(/;\s*/)){let o=n.split("=")[0];t.cookies?.some(r=>o.startsWith(r))&&pe(e,o)}try{let n=e.defaultView.localStorage;for(let o of Object.keys(n))t.local?.some(r=>o.startsWith(r))&&n.removeItem(o)}catch{}}}function z(e,{allowed:t,ran:n}){e.querySelectorAll(le).forEach(o=>{let r=o.dataset.consentCategory;if(!(!S.includes(r)||!t[r])){if(n.add(r),o.tagName==="IFRAME"){o.setAttribute("src",o.dataset.src),o.removeAttribute("data-src");return}o.replaceWith(fe(e,o))}})}function fe(e,t){let n=e.createElement("script");for(let{name:o,value:r}of Array.from(t.attributes))ue.has(o)||n.setAttribute(o,r);return t.nonce&&(n.nonce=t.nonce),t.dataset.type&&(n.type=t.dataset.type),t.dataset.src?n.src=t.dataset.src:n.text=t.text,n.async=!1,n}function Q({api:e,doc:t}){t.addEventListener("click",n=>{n.target.closest?.(de)&&(n.preventDefault(),e.open())})}function ge(e){let t={};for(let n of S){let o=e.querySelector(`input[name="${n}"]`);o&&(t[n]=o.checked)}return t}function N(e,t){for(let n of S){let o=e.querySelector(`input[name="${n}"]`);o&&(o.checked=t.choices[n],o.disabled=t.gpc&&n!=="functional")}}var D=e=>S.some(t=>e.choices[t]&&!e.allowed[t]);function Y({api:e,doc:t}){let n=t.getElementById("jini-consent");if(!n)return;let o=n.querySelector("[data-consent-error]"),r=s=>{n.hidden=!s,e.setOpen({open:s})},p=s=>{o&&(o.hidden=!D(s)),D(s)||r(!1)};n.addEventListener("click",s=>{let m=s.target.closest?.("[data-consent-action]")?.getAttribute("data-consent-action");m&&(s.preventDefault(),e.set({action:m},{choices:ge(n)}).then(p))}),n.addEventListener("keydown",s=>{s.key==="Escape"&&e.get().status==="set"&&r(!1)}),t.addEventListener(O,()=>{N(n,e.get()),r(!0),n.querySelector("button")?.focus()}),e.subscribe({listener:s=>{N(n,s),o&&!o.hidden&&!D(s)&&p(s)}}),N(n,e.get()),r(e.get().status==="pending")}var M=864e5,ye=180*M,me=6e4,L=/^[\w-]{16,128}$/,U=Object.freeze({necessary:!0,functional:!1,analytics:!1,marketing:!1});function X({configured:e,hint:t},n={}){return e!=="auto"?e:t==="us"?"opt-out":"opt-in"}var E=(e,t=e,n=t)=>({functional:e,analytics:t,marketing:n});function Z({action:e,picked:t={}},n={}){return e==="accept"?E(!0):e==="save"?E(t.functional===!0,t.analytics===!0,t.marketing===!0):e==="do-not-sell"?E(t.functional!==!1,!1):E(!1)}function Ce({flags:e,gpc:t},n={}){return{necessary:!0,functional:e.functional,analytics:e.analytics&&!t,marketing:e.marketing&&!t}}function ee({stored:e,policy:t,region:n,gpc:o,nowMs:r},{maxAgeMs:p=ye,durable:s=!1,anonymous:m=!1}={}){let C=be({stored:e,policy:t,nowMs:r,maxAgeMs:p,anonymous:m}),f=Ce({flags:m?U:C?.c??E(n==="opt-out"),gpc:o}),v={contract:1,policy:t,region:n,gpc:o,choices:f,...Se({choices:f,live:C,durable:s,anonymous:m,gpc:o})};return C?{...v,status:"set",action:C.a,at:C.t,receipt:he(C)}:{...v,status:"pending",action:null,at:null,receipt:"none"}}function be({stored:e,policy:t,nowMs:n,maxAgeMs:o,anonymous:r}){return!r&&e&&e.p===t&&e.t<=n+me&&n-e.t<=o?e:null}function Se({choices:e,live:t,durable:n,anonymous:o,gpc:r},p={}){let s=o||t&&n&&!t.r?U:e;return{allowed:s,analyticsLevel:o&&!r?"anonymous":s.analytics?"full":"none"}}function he(e){return e.r?"stored":e.q?"pending":"local"}function te({raw:e},t={}){if(!e||e.length>1024)return null;let n;try{n=JSON.parse(e)}catch{return null}if(!ve(n))return null;let o={v:1,p:n.p,c:E(n.c.functional,n.c.analytics,n.c.marketing),t:n.t,a:n.a};return typeof n.r=="string"&&L.test(n.r)&&(o.r=n.r),n.q===1&&(o.q=1),o}function ve(e){return!e||e.v!==1||typeof e.p!="string"||!Number.isFinite(e.t)?!1:V.includes(e.a)&&Ae(e.c)}function Ae(e){let t=e;return!!t&&typeof t=="object"&&typeof t.functional=="boolean"&&typeof t.analytics=="boolean"&&typeof t.marketing=="boolean"}var Ee=/^[a-z0-9][a-z0-9._:-]{0,63}$/;function ne(e={},{slots:t=[],onProblem:n=()=>{}}={}){let o=new Map,r=[],p=new Set,s=new Set,m=a=>r.filter(l=>l.kind===a).sort((l,c)=>c.priority-l.priority).map(l=>l.value),C=a=>s.forEach(l=>{if(l.kind===a)try{l.fn(m(a))}catch{}});function f(a,l){let c=h=>(n({id:String(a.id),kind:a.kind,reason:h,...l.source?{source:l.source}:{}}),()=>{});if(!Ee.test(String(a.id)))return c("short lowercase id");let A=o.get(a.kind).accept({contribution:a});if(typeof A=="string")return c(A);if(r.some(h=>h.kind===a.kind&&h.id===a.id))return c("duplicate id");let b={kind:a.kind,id:a.id,value:A,priority:l.priority??0};return r.push(b),C(a.kind),()=>{let h=r.indexOf(b);h>=0&&(r.splice(h,1),C(a.kind))}}let v={defineSlot({slot:a}){if(!o.has(a.kind)){o.set(a.kind,a);for(let l of p)l.raw.kind===a.kind&&(p.delete(l),l.dispose=f(l.raw,l.options))}},registerPlugin(a,l={}){if(o.has(a.kind))return f(a,l);let c={raw:a,options:l,dispose:()=>{p.delete(c)}};return p.add(c),()=>c.dispose()},list:({kind:a})=>m(a),subscribe({kind:a,listener:l}){let c={kind:a,fn:l};return s.add(c),()=>{s.delete(c)}}};for(let a of t)v.defineSlot({slot:a});return v}var oe={kind:k,accept({contribution:e}){return S.includes(e.category)?typeof e.grant=="function"||typeof e.src=="string"?e:"grant() or src needed":"category must be functional, analytics or marketing"}};var xe=(e,t)=>Promise.race([e,new Promise(n=>setTimeout(n,t))]),w=e=>{try{e()}catch{}};function Pe({config:e,ports:t},n={}){let{doc:o}=t,r=n.plugins??ne({},{slots:[oe]}),p=ke(n),s=new Map,m=new Set,C=new Set,f=e.banner==="off",v=(e.maxAgeDays??180)*M,a=X({configured:e.regionMode,hint:f?null:T(o,J)}),l=()=>f?null:te({raw:T(o,R)}),c=l(),A=!0,b=h();function h(){return ee({stored:c,policy:e.policy,region:a,gpc:t.gpc(),nowMs:t.now()},{maxAgeMs:v,durable:!!p,anonymous:f})}function j(){let i=JSON.stringify(c);W(o,{name:R,value:i,maxAgeS:v/1e3},{domain:e.cookieDomain}),A=T(o,R)===i}function q(i){i.generation++;let d=new AbortController,u=Promise.resolve(i.adapter??t.importModule(i.entry.src).then(y=>i.adapter=y.default)).then(y=>(w(()=>y.onState?.({state:b})),d.signal.aborted||f&&b.analyticsLevel==="none"?null:Promise.resolve().then(()=>y.grant({config:i.entry.config??y.config,state:b,signal:d.signal})).then(P=>P===void 0?{}:P,()=>({}))),()=>null);i.run={ctl:d,result:u}}async function F(i){let d=i.run,g=i.generation;i.run=void 0,d.ctl.abort();let u=await d.result;if(!u)return!1;let y=await Promise.resolve().then(()=>u.revoke?.()).catch(()=>!1);return!f&&i.generation===g&&_(o,i.adapter?.storage??i.entry.storage),!y}function re(i){let d=[];for(let u of s.values())(f?i.analyticsLevel==="anonymous":i.allowed[u.entry.category])?u.run||q(u):u.run&&d.push(F(u)),w(()=>u.adapter?.onState?.({state:i}));f||z(o,{allowed:i.allowed,ran:C});let g=S.some(u=>C.has(u)&&!i.allowed[u]);Promise.all(d).then(u=>{(g||u.includes(!0))&&t.reload()})}function x(){let i=b=h(),d=o.documentElement;return d.dataset.consent=i.status,d.dataset.consentRegion=i.region,d.toggleAttribute("data-consent-gpc",i.gpc),re(i),m.forEach(g=>w(()=>g(i))),o.dispatchEvent(new CustomEvent($,{detail:i})),i}async function K(i,d){if(!p)return;let g=JSON.stringify({policy:i.p,choices:i.c,action:i.a,gpc:t.gpc(),previousId:d}),u=await t.fetch(p.endpoint,{method:"POST",credentials:"same-origin",keepalive:!0,headers:{"content-type":"application/json"},body:g}).catch(()=>null),y=u?.ok?await u.json().catch(()=>null):null;c!==i||I()||typeof y?.id!="string"||!L.test(y.id)||(c={v:1,p:i.p,c:i.c,t:i.t,a:i.a,r:y.id},j(),x())}async function se({action:i},{choices:d={}}={}){if(f)return x();let g=c?.r;c={v:1,p:e.policy,c:Z({action:i,picked:d}),t:t.now(),a:i,...p?{q:1}:{}},j();let u=x(),y=K(c,g);return p&&S.some(P=>u.choices[P]&&!u.allowed[P])&&await xe(y,p.waitMs??1500),b}function ae(i){if(f&&(!i.supportsAnonymous||i.category!=="analytics"))return;let d={entry:i,generation:0,adapter:typeof i.grant=="function"?i:void 0};s.set(i.id,d),f||b.allowed[i.category]?q(d):_(o,i.storage),w(()=>d.adapter?.onState?.({state:b}))}function H(i){let d=new Set(i.map(g=>g.id));for(let[g,u]of s)d.has(g)||(s.delete(g),u.run&&F(u).then(y=>{y&&t.reload()}));for(let g of i)s.has(g.id)||ae(g)}function I(){let i=l();return!i&&!A||i?.t===c?.t&&i?.a===c?.a&&i?.r===c?.r?!1:(c=i,x(),!0)}let ce={contract:1,plugins:r,set:se,get:()=>b,subscribe:({listener:i})=>(m.add(i),()=>{m.delete(i)}),open:()=>{o.dispatchEvent(new CustomEvent(O))},setOpen:({open:i})=>{o.documentElement.toggleAttribute("data-consent-open",i)}};return r.subscribe({kind:k,listener:H}),H(r.list({kind:k})),e.plugins?.forEach(i=>r.registerPlugin(i,{source:"page"})),x(),o.addEventListener("visibilitychange",()=>{o.visibilityState==="visible"&&I()}),o.defaultView?.addEventListener("pageshow",()=>I()),c?.q&&c.p===e.policy&&K(c),ce}function ke({evidence:e},t={}){return e?.mode==="durable"?e:null}function Re(e){return{doc:e.document,fetch:e.fetch.bind(e),now:Date.now,reload:()=>e.location.reload(),gpc:()=>e.navigator.globalPrivacyControl===!0||e.navigator.doNotTrack==="1",importModule:t=>import(t)}}function Oe(e){try{return JSON.parse(e.getElementById(G)?.textContent??"")}catch{return null}}function ie(e=window,{ports:t=Re(e),bindBanner:n}={}){if(e.jiniConsent)return e.jiniConsent;let o=Oe(e.document);if(!o)return;let{evidence:r,...p}=o,s=Pe({config:p,ports:t},{evidence:r}),m=Array.isArray(e.jiniConsentQueue)?e.jiniConsentQueue:[];return e.jiniConsent=s,e.jiniConsentQueue={push:(...C)=>C.forEach(f=>s.plugins.registerPlugin(f,{source:"queue"}))},e.jiniConsentQueue.push(...m),Q({api:s,doc:e.document}),p.banner==="jini"&&n?.({api:s,doc:e.document}),e.document.dispatchEvent(new CustomEvent(B,{detail:s})),s}ie(window,{bindBanner:Y});})();
|
|
1
|
+
"use strict";(()=>{var R="jini_choices",H="jini_region",J="jini:consent",$="jini:consent-ready",O="jini:consent-open",B="jini-consent-config",h=["functional","analytics","marketing"],we=["necessary",...h],G=["accept","reject","save","do-not-sell","withdraw"];var P="consent-adapter";var le='script[type="text/plain"][data-consent-category],iframe[data-consent-category][data-src]',ue=new Set(["type","data-src","data-type","data-consent-category"]),de=':not(html)[data-consent-open],a[href="#privacy-choices"]';function T(e,t){let n=e.cookie.split(/;\s*/).find(o=>o.startsWith(t+"="));try{return n?decodeURIComponent(n.slice(t.length+1)):null}catch{return null}}function V(e,{name:t,value:n,maxAgeS:o},{domain:r}={}){let p=e.defaultView?.location.protocol==="https:"?"; Secure":"";e.cookie=`${t}=${encodeURIComponent(n)}; Path=/; Max-Age=${Math.floor(o)}; SameSite=Lax${p}${r?`; Domain=${r}`:""}`}function pe(e,t){let n=(e.defaultView?.location.hostname??"").split(".");e.cookie=`${t}=; Path=/; Max-Age=0`;for(let o=0;o<n.length-1;o++)e.cookie=`${t}=; Path=/; Max-Age=0; Domain=.${n.slice(o).join(".")}`}function D(e,t){if(t){for(let n of e.cookie.split(/;\s*/)){let o=n.split("=")[0];t.cookies?.some(r=>o.startsWith(r))&&pe(e,o)}try{let n=e.defaultView.localStorage;for(let o of Object.keys(n))t.local?.some(r=>o.startsWith(r))&&n.removeItem(o)}catch{}}}function W(e,{allowed:t,ran:n}){e.querySelectorAll(le).forEach(o=>{let r=o.dataset.consentCategory;if(!(!h.includes(r)||!t[r])){if(n.add(r),o.tagName==="IFRAME"){o.setAttribute("src",o.dataset.src),o.removeAttribute("data-src");return}o.replaceWith(fe(e,o))}})}function fe(e,t){let n=e.createElement("script");for(let{name:o,value:r}of Array.from(t.attributes))ue.has(o)||n.setAttribute(o,r);return t.nonce&&(n.nonce=t.nonce),t.dataset.type&&(n.type=t.dataset.type),t.dataset.src?n.src=t.dataset.src:n.text=t.text,n.async=!1,n}function z({api:e,doc:t}){t.addEventListener("click",n=>{n.target.closest?.(de)&&(n.preventDefault(),e.open())})}function ge(e){let t={};for(let n of h){let o=e.querySelector(`input[name="${n}"]`);o&&(t[n]=o.checked)}return t}function N(e,t){for(let n of h){let o=e.querySelector(`input[name="${n}"]`);o&&(o.checked=t.choices[n],o.disabled=t.gpc&&n!=="functional")}}var k=e=>h.some(t=>e.choices[t]&&!e.allowed[t]);function Q({api:e,doc:t}){let n=t.getElementById("jini-consent");if(!n)return;let o=n.querySelector("[data-consent-error]"),r=s=>{n.hidden=!s,e.setOpen({open:s})},p=s=>{o&&(o.hidden=!k(s)),k(s)||r(!1)};n.addEventListener("click",s=>{let m=s.target.closest?.("[data-consent-action]")?.getAttribute("data-consent-action");m&&(s.preventDefault(),e.set({action:m},{choices:ge(n)}).then(p))}),n.addEventListener("keydown",s=>{s.key==="Escape"&&e.get().status==="set"&&r(!1)}),t.addEventListener(O,()=>{N(n,e.get()),r(!0),n.querySelector("button")?.focus()}),e.subscribe({listener:s=>{N(n,s),o&&!o.hidden&&!k(s)&&p(s)}}),N(n,e.get()),r(e.get().status==="pending")}var _=864e5,ye=180*_,me=6e4,M=/^[\w-]{16,128}$/,Y=Object.freeze({necessary:!0,functional:!1,analytics:!1,marketing:!1});function U({configured:e,hint:t},n={}){return e!=="auto"?e:t==="us"?"opt-out":"opt-in"}var x=(e,t=e,n=t)=>({functional:e,analytics:t,marketing:n});function X({action:e,picked:t={}},n={}){return e==="accept"?x(!0):e==="save"?x(t.functional===!0,t.analytics===!0,t.marketing===!0):e==="do-not-sell"?x(t.functional!==!1,!1):x(!1)}function Ce({flags:e,gpc:t},n={}){return{necessary:!0,functional:e.functional,analytics:e.analytics&&!t,marketing:e.marketing&&!t}}function Z({stored:e,policy:t,region:n,gpc:o,nowMs:r},{maxAgeMs:p=ye,durable:s=!1,anonymous:m=!1}={}){let C=be({stored:e,policy:t,nowMs:r,maxAgeMs:p,anonymous:m}),f=Ce({flags:m?Y:C?.c??x(n==="opt-out"),gpc:o}),v={contract:1,policy:t,region:n,gpc:o,choices:f,...Se({choices:f,live:C,durable:s,anonymous:m,gpc:o})};return C?{...v,status:"set",action:C.a,at:C.t,receipt:he(C)}:{...v,status:"pending",action:null,at:null,receipt:"none"}}function be({stored:e,policy:t,nowMs:n,maxAgeMs:o,anonymous:r}){return!r&&e&&e.p===t&&e.t<=n+me&&n-e.t<=o?e:null}function Se({choices:e,live:t,durable:n,anonymous:o,gpc:r},p={}){let s=o||t&&n&&!t.r?Y:e;return{allowed:s,analyticsLevel:o&&!r?"anonymous":s.analytics?"full":"none"}}function he(e){return e.r?"stored":e.q?"pending":"local"}function ee({raw:e},t={}){if(!e||e.length>1024)return null;let n;try{n=JSON.parse(e)}catch{return null}if(!ve(n))return null;let o={v:1,p:n.p,c:x(n.c.functional,n.c.analytics,n.c.marketing),t:n.t,a:n.a};return typeof n.r=="string"&&M.test(n.r)&&(o.r=n.r),n.q===1&&(o.q=1),o}function ve(e){return!e||e.v!==1||typeof e.p!="string"||!Number.isFinite(e.t)?!1:G.includes(e.a)&&Ae(e.c)}function Ae(e){let t=e;return!!t&&typeof t=="object"&&typeof t.functional=="boolean"&&typeof t.analytics=="boolean"&&typeof t.marketing=="boolean"}var xe=/^[a-z0-9][a-z0-9._:-]{0,63}$/;function te(e={},{slots:t=[],onProblem:n=()=>{}}={}){let o=new Map,r=[],p=new Set,s=new Set,m=a=>r.filter(c=>c.kind===a).sort((c,l)=>l.priority-c.priority).map(c=>c.value),C=a=>s.forEach(c=>{if(c.kind===a)try{c.fn(m(a))}catch{}});function f(a,c){let l=S=>(n({id:String(a.id),kind:a.kind,reason:S,...c.source?{source:c.source}:{}}),()=>{});if(!xe.test(String(a.id)))return l("short lowercase id");let A=o.get(a.kind).accept({contribution:a});if(typeof A=="string")return l(A);if(r.some(S=>S.kind===a.kind&&S.id===a.id))return l("duplicate id");let b={kind:a.kind,id:a.id,value:A,priority:c.priority??0};return r.push(b),C(a.kind),()=>{let S=r.indexOf(b);S>=0&&(r.splice(S,1),C(a.kind))}}let v={defineSlot({slot:a}){if(!o.has(a.kind)){o.set(a.kind,a);for(let c of p)c.raw.kind===a.kind&&(p.delete(c),c.dispose=f(c.raw,c.options))}},registerPlugin(a,c={}){if(o.has(a.kind))return f(a,c);let l={raw:a,options:c,dispose:()=>{p.delete(l)}};return p.add(l),()=>l.dispose()},list:({kind:a})=>m(a),subscribe({kind:a,listener:c}){let l={kind:a,fn:c};return s.add(l),()=>{s.delete(l)}}};for(let a of t)v.defineSlot({slot:a});return v}var ne={kind:P,accept({contribution:e}){return h.includes(e.category)?typeof e.grant=="function"||typeof e.src=="string"?e:"grant() or src needed":"category must be functional, analytics or marketing"}};var Ee=(e,t)=>Promise.race([e,new Promise(n=>setTimeout(n,t))]),w=e=>{try{e()}catch{}};function Pe({config:e,ports:t},n={}){let{doc:o}=t,r=n.plugins??te({},{slots:[ne]}),p=Re(n),s=new Map,m=new Set,C=new Set,f=e.banner==="off",v=(e.maxAgeDays??180)*_,a=U({configured:e.regionMode,hint:f?null:T(o,H)}),c=()=>f?null:ee({raw:T(o,R)}),l=c(),A=!0,b=S();function S(){return Z({stored:l,policy:e.policy,region:a,gpc:t.gpc(),nowMs:t.now()},{maxAgeMs:v,durable:!!p,anonymous:f})}function L(){let i=JSON.stringify(l);V(o,{name:R,value:i,maxAgeS:v/1e3},{domain:e.cookieDomain}),A=T(o,R)===i}function j(i){i.generation++;let d=new AbortController,u=Promise.resolve(i.adapter??t.importModule(i.entry.src).then(y=>i.adapter=y.default)).then(y=>(w(()=>y.onState?.({state:b})),d.signal.aborted||f&&b.analyticsLevel==="none"?null:Promise.resolve().then(()=>y.grant({config:i.entry.config??y.config,state:b,signal:d.signal})).then((ce={})=>ce,()=>({}))),()=>null);i.run={ctl:d,result:u}}async function q(i){let d=i.run,g=i.generation;i.run=void 0,d.ctl.abort();let u=await d.result;if(!u)return!1;let y=await Promise.resolve().then(()=>u.revoke?.()).catch(()=>!1);return!f&&i.generation===g&&D(o,i.adapter?.storage??i.entry.storage),!y}function ie(i){let d=[];for(let u of s.values())(f?i.analyticsLevel==="anonymous":i.allowed[u.entry.category])?u.run||j(u):u.run&&d.push(q(u)),w(()=>u.adapter?.onState?.({state:i}));f||W(o,{allowed:i.allowed,ran:C});let g=h.some(u=>C.has(u)&&!i.allowed[u]);Promise.all(d).then(u=>{(g||u.includes(!0))&&t.reload()})}function E(){let i=b=S(),d=o.documentElement;return d.dataset.consent=i.status,d.dataset.consentRegion=i.region,d.toggleAttribute("data-consent-gpc",i.gpc),ie(i),m.forEach(g=>w(()=>g(i))),o.dispatchEvent(new CustomEvent(J,{detail:i})),i}async function F(i,d){if(!p)return;let g=JSON.stringify({policy:i.p,choices:i.c,action:i.a,gpc:t.gpc(),previousId:d}),u=await t.fetch(p.endpoint,{method:"POST",credentials:"same-origin",keepalive:!0,headers:{"content-type":"application/json"},body:g}).catch(()=>null),y=u?.ok?await u.json().catch(()=>null):null;l!==i||I()||typeof y?.id!="string"||!M.test(y.id)||(l={v:1,p:i.p,c:i.c,t:i.t,a:i.a,r:y.id},L(),E())}async function re({action:i},{choices:d={}}={}){if(f)return E();let g=l?.r;l={v:1,p:e.policy,c:X({action:i,picked:d}),t:t.now(),a:i,...p?{q:1}:{}},L();let u=E(),y=F(l,g);return p&&k(u)&&await Ee(y,p.waitMs??1500),b}function se(i){if(f&&(!i.supportsAnonymous||i.category!=="analytics"))return;let d={entry:i,generation:0,adapter:typeof i.grant=="function"?i:void 0};s.set(i.id,d),f||b.allowed[i.category]?j(d):D(o,i.storage),w(()=>d.adapter?.onState?.({state:b}))}function K(i){let d=new Set(i.map(g=>g.id));for(let[g,u]of s)d.has(g)||(s.delete(g),u.run&&q(u).then(y=>{y&&t.reload()}));for(let g of i)s.has(g.id)||se(g)}function I(){let i=c();return!i&&!A||ke({latest:i,stored:l})?!1:(l=i,E(),!0)}let ae={contract:1,plugins:r,set:re,get:()=>b,subscribe:({listener:i})=>(m.add(i),()=>{m.delete(i)}),open:()=>{o.dispatchEvent(new CustomEvent(O))},setOpen:({open:i})=>{o.documentElement.toggleAttribute("data-consent-open",i)}};return r.subscribe({kind:P,listener:K}),K(r.list({kind:P})),e.plugins?.forEach(i=>r.registerPlugin(i,{source:"page"})),E(),o.addEventListener("visibilitychange",()=>{o.visibilityState==="visible"&&I()}),o.defaultView?.addEventListener("pageshow",()=>I()),l?.q&&l.p===e.policy&&F(l),ae}function ke({latest:e,stored:t}){return e?.t===t?.t&&e?.a===t?.a&&e?.r===t?.r}function Re({evidence:e},t={}){return e?.mode==="durable"?e:null}function Oe(e){return{doc:e.document,fetch:e.fetch.bind(e),now:Date.now,reload:()=>e.location.reload(),gpc:()=>e.navigator.globalPrivacyControl===!0||e.navigator.doNotTrack==="1",importModule:t=>import(t)}}function Te(e){try{return JSON.parse(e.getElementById(B)?.textContent??"")}catch{return null}}function oe(e=window,{ports:t=Oe(e),bindBanner:n}={}){if(e.jiniConsent)return e.jiniConsent;let o=Te(e.document);if(!o)return;let{evidence:r,...p}=o,s=Pe({config:p,ports:t},{evidence:r}),m=Array.isArray(e.jiniConsentQueue)?e.jiniConsentQueue:[];return e.jiniConsent=s,e.jiniConsentQueue={push:(...C)=>C.forEach(f=>s.plugins.registerPlugin(f,{source:"queue"}))},e.jiniConsentQueue.push(...m),z({api:s,doc:e.document}),p.banner==="jini"&&n?.({api:s,doc:e.document}),e.document.dispatchEvent(new CustomEvent($,{detail:s})),s}oe(window,{bindBanner:Q});})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/cookie-consent",
|
|
3
|
-
"version": "0.6.15-rc.
|
|
3
|
+
"version": "0.6.15-rc.2",
|
|
4
4
|
"description": "Standalone, vendor-free cookie consent: a consent-state contract any banner can drive, a ~3 KB browser client, a pure-string banner renderer with owner CSS, web-standard receipts and open plugin slots.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|