@cookieyes/core 0.4.0 → 0.5.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/README.md +9 -7
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +37 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<a href="#quick-start">Quick start</a> ·
|
|
23
23
|
<a href="#api">API</a> ·
|
|
24
24
|
<a href="#troubleshooting">Troubleshooting</a> ·
|
|
25
|
-
<a href="https://github.com/cookieyes/cookieyes/blob/main/docs/configuration.
|
|
25
|
+
<a href="https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/getting-started/configuration.mdx">Docs</a>
|
|
26
26
|
</p>
|
|
27
27
|
|
|
28
28
|
---
|
|
@@ -64,7 +64,7 @@ bun add @cookieyes/core
|
|
|
64
64
|
**2. Initialise the runtime**
|
|
65
65
|
|
|
66
66
|
> **Which API should I use?** `consentStore.subscribe` is the recommended way to
|
|
67
|
-
> read consent outside React. See the [shared decision tree](
|
|
67
|
+
> read consent outside React. See the [shared decision tree](https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/getting-started/which-api.mdx)
|
|
68
68
|
> if you're not sure which API applies to your situation — core also exposes a
|
|
69
69
|
> handful of lower-level options (see [Low-level / advanced API](#low-level--advanced-api))
|
|
70
70
|
> for specific edge cases.
|
|
@@ -154,9 +154,9 @@ still works today and logs a one-time console warning, and will be removed
|
|
|
154
154
|
Both accept the canonical `CookieYesConfig` and return `{ consentManager, consentStore }` (a
|
|
155
155
|
singleton — call `resetConsentRuntime()` to clear it, mainly for tests). `initCookieYes` is an
|
|
156
156
|
alias provided so one setup name reads across every package. Every option is documented once in
|
|
157
|
-
**[Configuration](https://github.com/cookieyes/cookieyes/blob/main/docs/configuration.
|
|
157
|
+
**[Configuration](https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/getting-started/configuration.mdx)**.
|
|
158
158
|
Migrating off the deprecated `overrides.regulation` / `backendURL` keys? See the
|
|
159
|
-
**[migration guide](https://github.com/cookieyes/cookieyes/blob/main/docs/migration
|
|
159
|
+
**[migration guide](https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/migration.mdx)**.
|
|
160
160
|
|
|
161
161
|
**`config`** (`CookieYesConfig`):
|
|
162
162
|
|
|
@@ -239,7 +239,7 @@ await consentStore.setLanguage("fr"); // switch live; loads via i18n.loadLangu
|
|
|
239
239
|
```
|
|
240
240
|
|
|
241
241
|
Missing text falls back to English; custom categories translate by id (see the
|
|
242
|
-
[configuration guide](https://github.com/cookieyes/cookieyes/blob/main/docs/configuration.
|
|
242
|
+
[configuration guide](https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/getting-started/configuration.mdx)).
|
|
243
243
|
In React, use the `useTranslations()` / `useLanguage()` hooks instead.
|
|
244
244
|
|
|
245
245
|
## Region-based regulation (geo-detection)
|
|
@@ -294,7 +294,9 @@ is lost.
|
|
|
294
294
|
|
|
295
295
|
There are three layers:
|
|
296
296
|
|
|
297
|
-
1. **Network blocking** (`networkBlocker` / `blockNetwork`) —
|
|
297
|
+
1. **Network blocking** (`networkBlocker` / `blockNetwork`) — see
|
|
298
|
+
[Network blocking](https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/network-blocking.mdx) for what it
|
|
299
|
+
can and cannot stop, its measured cost, and starter rules for common vendors. It intercepts
|
|
298
300
|
`fetch`, `XMLHttpRequest`, **and `navigator.sendBeacon`** to blocked domains,
|
|
299
301
|
in real time, for as long as the page is open. `sendBeacon` matters because
|
|
300
302
|
GA4/Meta use it for exit/unload tracking that fetch/XHR interception misses.
|
|
@@ -526,7 +528,7 @@ Still stuck? [Open an issue](https://github.com/cookieyes/cookieyes/issues).
|
|
|
526
528
|
|
|
527
529
|
- [Open an issue](https://github.com/cookieyes/cookieyes/issues) — bug reports and feature requests.
|
|
528
530
|
- Email — [support@cookieyes.com](mailto:support@cookieyes.com).
|
|
529
|
-
- [Full documentation](https://github.com/cookieyes/cookieyes/blob/main/docs/configuration.
|
|
531
|
+
- [Full documentation](https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/getting-started/configuration.mdx).
|
|
530
532
|
|
|
531
533
|
_(A community chat channel is on the roadmap.)_
|
|
532
534
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e="cookieyes-consent",t=new Set(["consentid","consent","action","tax","lastRenewedDate"]);function o(e){const o={categories:{}};for(const n of e.split(",")){const e=n.indexOf(":");if(-1===e)continue;const r=n.slice(0,e).trim(),i=n.slice(e+1).trim();t.has(r)?o[r]=i:r.length>0&&(o.categories[r]=i)}return o}function n(e){const t=[`consentid:${e.consentId}`,"consent:"+(e.hasActed?"yes":"no"),"action:"+(e.hasActed?"yes":"no")];e.taxonomyHash&&t.push(`tax:${e.taxonomyHash}`);for(const[o,n]of Object.entries(e.categories))t.push(`${o}:${n?"yes":"no"}`);return t.push(`lastRenewedDate:${e.lastRenewed??Date.now()}`),t.join(",")}function r(t){for(const n of t.split(";")){const t=n.trim(),r=t.indexOf("=");if(-1===r)continue;if(t.slice(0,r).trim()!==e)continue;const i=t.slice(r+1).trim();try{return o(decodeURIComponent(i))}catch{return null}}return null}function i(t){if("undefined"==typeof document)return;const o=encodeURIComponent(n(t));document.cookie=`${e}=${o}; max-age=31536000; path=/; SameSite=Lax`}function s(){"undefined"!=typeof document&&(document.cookie=`${e}=; max-age=0; path=/`)}function a(){const e=new Uint8Array(32);if("undefined"!=typeof crypto&&crypto.getRandomValues)crypto.getRandomValues(e);else for(let t=0;t<e.length;t++)e[t]=Math.floor(256*Math.random());return btoa(String.fromCharCode(...e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"").slice(0,44)}function c(e,t,o){const n={};for(const t of o.ids)n[t]=!!o.requiredIds.has(t)||"yes"===e.categories[t];return{consentId:e.consentid??a(),hasActed:"yes"===e.action,categories:n,regulation:t,lastRenewed:e.lastRenewedDate?Number(e.lastRenewedDate):void 0,taxonomyHash:e.tax}}function d(e,t,o){const n="CCPA"===t,r={};for(const e of o.ids)r[e]=!!o.requiredIds.has(e)||n;return{consentId:e,hasActed:!1,categories:r,regulation:t,taxonomyHash:o.taxonomyHash}}const l=[{id:"necessary",required:!0},{id:"functional",gcm:["functionality_storage","personalization_storage"]},{id:"analytics",gcm:["analytics_storage"]},{id:"performance"},{id:"advertisement",gcm:["ad_storage","ad_user_data","ad_personalization"]}];function u(e){let t=2166136261;for(let o=0;o<e.length;o++)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function g(e,t){const o=e.map(e=>e.id),n=new Set(e.filter(e=>e.required).map(e=>e.id)),r=e.map(e=>`${e.id}:${e.required?1:0}:${(e.gcm??[]).join("+")}`).join("|");return{list:e,ids:o,requiredIds:n,taxonomyHash:u(r),isDefault:t}}function f(e){if(!e||0===e.length)return g(l,!0);const o=function(e){const o=e.map(e=>e.id);return o.some(e=>"string"!=typeof e||0===e.length)?"every category needs a non-empty string id":o.some(e=>e.includes(",")||e.includes(":"))?"category ids must not contain ',' or ':'":new Set(o).size!==o.length?"category ids must be unique":o.some(e=>t.has(e))?`category ids must not be one of the reserved keys: ${[...t].join(", ")}`:e.some(e=>!0===e.required)?null:"at least one category must be marked { required: true }"}(e);return o?("undefined"!=typeof console&&console.warn(`[cookieyes] Invalid categories config (${o}). Falling back to the default five (necessary, functional, analytics, performance, advertisement).`),g(l,!0)):g(e,!1)}function p(e){"undefined"!=typeof console&&console.warn(e)}function h(e){const t={mode:e.mode},o=e.overrides?.regulation;return void 0!==e.regulation?(t.regulation=e.regulation,void 0!==o&&p("[CookieYes] Received both `regulation` and the deprecated `overrides.regulation`. Using the top-level `regulation` and ignoring `overrides`. Drop the `overrides` object — it is deprecated and will be removed after three release cycles.")):void 0!==o&&(t.regulation=o),void 0!==e.region&&(t.region=e.region),void 0!==e.colorScheme&&(t.colorScheme=e.colorScheme),void 0!==e.theme&&(t.theme=e.theme),void 0!==e.i18n&&(t.i18n=e.i18n),void 0!==e.consentCategories&&(t.consentCategories=e.consentCategories),void 0!==e.categories&&(t.categories=e.categories),void 0!==e.networkBlocker&&(t.networkBlocker=e.networkBlocker),void 0!==e.reloadOnRevoke&&(t.reloadOnRevoke=e.reloadOnRevoke),void 0!==e.googleConsentMatch&&(t.googleConsentMatch=e.googleConsentMatch),void 0!==e.integrations&&(t.integrations=e.integrations),void 0!==e.builtInIntegrations&&(t.builtInIntegrations=e.builtInIntegrations),void 0!==e.customStopHandlers&&(t.customStopHandlers=e.customStopHandlers),void 0!==e.onConsentReady&&(t.onConsentReady=e.onConsentReady),void 0!==e.onConsentUpdate&&(t.onConsentUpdate=e.onConsentUpdate),"self-hosted"===e.mode&&(void 0!==e.apiKey&&(t.apiKey=e.apiKey),void 0!==e.backend&&(t.backend=e.backend),void 0!==e.apiUrl?(t.apiUrl=e.apiUrl,void 0!==e.backendURL&&p("[CookieYes] Received both `apiUrl` and the deprecated `backendURL`. Using `apiUrl` and ignoring `backendURL`. Rename `backendURL` to `apiUrl` — the alias is deprecated and will be removed after three release cycles.")):void 0!==e.backendURL&&(t.apiUrl=e.backendURL)),t}let y=!1;function m(){y||(y=!0,"undefined"!=typeof console&&console.warn('[cookieyes] mode: "offline" has been renamed to "cookie-only". Both do exactly the same thing, but "offline" is deprecated and will be removed in 3 releases. Update to .mode("cookie-only") (or { mode: "cookie-only" }).'))}let v=!1;function w(){v||(v=!0,"undefined"!=typeof console&&console.warn("[cookieyes] `builtInIntegrations` (formerly the `integrations` field) is deprecated and will be removed in a future release. Use the `integrations` field with a preset from `@cookieyes/scripts` instead."))}function k(e){const t={save:new Set,change:new Set};let o={...e()};function n(e,t,o){try{e.listener(o)}catch(e){"undefined"!=typeof console&&console.error(`[cookieyes] a consent "${t}" listener threw; others are unaffected:`,e)}}function r(e,o){for(const r of[...t[e]])r.category&&!o.changedCategories.includes(r.category)||n(r,e,o)}return{on(o,r,i){const s=i?.category?{listener:r,category:i.category}:{listener:r};return t[o].add(s),n(s,o,{categories:{...e()},changedCategories:[],isInitial:!0}),()=>{t[o].delete(s)}},push(e){const t={...e},n=[];for(const e of Object.keys(t))o[e]!==t[e]&&n.push(e);o=t,r("save",{categories:t,changedCategories:n,isInitial:!1}),n.length>0&&r("change",{categories:t,changedCategories:n,isInitial:!1})}}}function b(e){"undefined"!=typeof console&&console.warn(`[cookieyes] ${e}`)}const C=["ad_storage","ad_user_data","ad_personalization","analytics_storage","functionality_storage","personalization_storage","security_storage"];function x(e,t,o="any"){const n={};for(const r of C){if("security_storage"===r){n[r]="granted";continue}const i=e.list.filter(e=>e.gcm?.includes(r));if(0===i.length){n[r]="denied";continue}const s="all"===o?i.every(e=>!0===t[e.id]):i.some(e=>!0===t[e.id]);n[r]=s?"granted":"denied"}return n}function R(e,t,o="any"){if("undefined"==typeof window||!Array.isArray(window.dataLayer))return;const n=x(e,t,o),r=window.dataLayer;if(!r)return;!function(){r.push(arguments)}("consent","update",n)}const S={bannerTitle:"We value your privacy",bannerDescription:"We use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking “Accept All”, you consent to our use of cookies.",acceptAll:"Accept All",rejectAll:"Reject All",managePreferences:"Customise",savePreferences:"Save My Preferences",doNotSell:"Do Not Sell or Share My Personal Information",ccpaDescription:"This website or its third-party tools process personal data. You can opt out of the sale of your personal information by clicking on the “Do Not Sell or Share My Personal Information” link.",accept:"Accept",poweredBy:"Powered by CookieYes",preferencesTitle:"Customise Consent Preferences",preferencesIntro:"We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.",categories:{necessary:{label:"Necessary",description:"Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data."},functional:{label:"Functional",description:"Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features."},analytics:{label:"Analytics",description:"Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc."},performance:{label:"Performance",description:"Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors."},advertisement:{label:"Advertisement",description:"Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns."}},optOut:{title:"Opt-out Preferences",description:'We use third-party cookies that help us analyse how you use this website, store your preferences, and provide the content and advertisements that are relevant to you. However, you can opt out of these cookies by checking "Do Not Sell or Share My Personal Information" and clicking the "Save My Preferences" button. Once you opt out, you can opt in again at any time by unchecking "Do Not Sell or Share My Personal Information" and clicking the "Save My Preferences" button.',cancel:"Cancel",successText:"Your opt-out preference has been honored.",successCountdown:"Banner closes automatically in {seconds} s..."},reloadNotice:{message:"Some tracking on this page can only be fully stopped by reloading. Reload to apply your change, or dismiss to keep browsing.",reloadButton:"Reload page",dismissButton:"Dismiss"}},I=new Set(["ar","he","fa","ur","ps","sd","yi","dv"]);function A(e){return e.split("-")[0]?.toLowerCase()??""}function O(e){return I.has(A(e))?"rtl":"ltr"}function U(e,t){if(!t)return e;const o={...e};for(const[n,r]of Object.entries(t)){if(null==r)continue;const t=e[n],i="object"==typeof r&&!Array.isArray(r)&&"object"==typeof t&&null!=t;o[n]=i?U(t,r):r}return o}function $(e){const t=e?.messages??{},o=[];e?.locale&&o.push(e.locale),(e?.detectBrowserLanguage??1)&&"undefined"!=typeof navigator&&navigator.language&&o.push(navigator.language);for(const e of o){if(t[e])return e;const o=A(e);if(o&&t[o])return o}return"en"}function L(e,t){const o=new Set(e);for(const e of t)o.has(e)&&M(`"${e}" is configured as both a script integration and a built-in integration — remove one to avoid loading it twice (e.g. double-counted events).`)}function H(e,t){const o=new Set(t);for(const t of e){if("afterConsent"!==t.load)continue;const e=t.category,n=Array.isArray(e)?e:[e];if(0!==n.length)for(const e of n)o.has(e)||M(`integration "${t.id}" is gated on category "${e}", which isn't in your configured categories — it will never load. Pass a category that exists (e.g. segment({ category: "…" })), or add it to your taxonomy.`);else M(`integration "${t.id}" has an empty category list — it will never load. Give it at least one category that exists in your taxonomy.`)}}function M(e,t){"undefined"!=typeof console&&(void 0!==t?console.error(`[cookieyes] ${e}`,t):console.warn(`[cookieyes] ${e}`))}function P(e,t){const o=Array.isArray(e.category)?e.category:[e.category];return 0!==o.length&&("any"===e.match?o.some(e=>t.granted(e)):o.every(e=>t.granted(e)))}function B(e,t){const o=[],n=new Set;let r=!1;for(const t of e){const e=t;"string"!=typeof e.vendor||"function"==typeof e.setup?1===t.version?n.has(t.id)?M(`integration "${t.id}" is registered more than once; skipping the duplicate.`):(n.add(t.id),o.push({integration:t,status:"idle",everLoaded:!1,loading:!1,control:void 0,subs:new Set,wasGranted:!1})):M(`integration "${t.id}" uses format version ${t.version}, but this build understands 1. Skipping it.`):M(`an entry in "integrations" looks like the old built-in format ({ vendor: "${e.vendor}" }). That moved to "builtInIntegrations" — move it there, or use a preset from "@cookieyes/scripts" in "integrations". Skipping it.`)}function i(e){for(const t of e.subs)try{t()}catch{}e.subs.clear()}function s(e){i(e),"active"===e.status&&(!function(e){const{integration:t,control:o}=e;try{"remove"===t.onRevoke?o?.():"silence"===t.onRevoke&&o?.silence()}catch(e){M(`integration "${t.id}" threw while being torn down.`,e)}e.control=void 0}(e),"remove"===e.integration.onRevoke?e.status="removed":"silence"===e.integration.onRevoke&&(e.status="silenced"))}function a(e){e.loading=!0,e.status="loading",Promise.resolve().then(()=>e.integration.setup(function(e){return{granted:()=>P(e.integration,t),onConsentChange:o=>{const n=t.subscribe(o);return e.subs.add(n),()=>{e.subs.delete(n)&&n()}},region:t.region}}(e))).then(t=>{e.loading=!1,e.control=t??void 0,e.everLoaded=!0,e.status="active",r?s(e):c(e)}).catch(t=>{e.loading=!1,e.status="error",i(e),M(`integration "${e.integration.id}" failed to load; will retry on the next change.`,t)})}function c(e){const{integration:o}=e,n=P(o,t);if(n&&(e.wasGranted=!0),r||e.loading)return;if("idle"===e.status||"removed"===e.status||"error"===e.status){return void((e.everLoaded?n:"immediately"===o.load||n)&&a(e))}if("keep"===o.onRevoke)return;if("remove"===o.onRevoke){if(!n&&"active"===e.status&&e.wasGranted){i(e);try{e.control?.()}catch(e){M(`integration "${o.id}" cleanup threw on revoke.`,e)}e.control=void 0,e.status="removed"}return}const s=e.control;if(n||"active"!==e.status){if(n&&"silenced"===e.status){try{s?.resume()}catch(e){M(`integration "${o.id}" resume() threw.`,e)}e.status="active"}}else{try{s?.silence()}catch(e){M(`integration "${o.id}" silence() threw.`,e)}e.status="silenced"}}function d(){for(const e of o)c(e)}const l=t.subscribe(d);return d(),{status:()=>{const e={};for(const t of o)e[t.integration.id]=t.status;return e},list:()=>o.map(e=>({id:e.integration.id,category:e.integration.category,load:e.integration.load,onRevoke:e.integration.onRevoke,status:e.status})),stop:()=>{if(!r){r=!0,l();for(const e of o)s(e)}}}}function _(e,t){const o={...e?.messages},n=e?.loadLanguage,r=new Set;let i=$(e),s=l(i),a=u();function c(e){return o[e]??o[A(e)]}function d(e){return"en"===A(e)||void 0!==c(e)}function l(e){return U(S,c(e))}function u(){return{language:i,direction:O(i),languages:Array.from(new Set(["en",...Object.keys(o)]))}}function g(e){i=e,s=l(e),a=u(),t()}function f(e,t){r.has(e)||"undefined"==typeof console||(r.add(e),console.warn(`[cookieyes] no translations for language "${e}"; staying on "${i}". Add it to i18n.messages or provide i18n.loadLanguage.`,t??""))}function p(e){return d(e)?(g(e),Promise.resolve()):n?Promise.resolve().then(()=>n(e)).then(t=>{o[e]=t,g(e)}).catch(t=>f(e,t)):(f(e),Promise.resolve())}return n&&e?.locale&&!d(e.locale)&&"undefined"!=typeof window&&p(e.locale),{getTranslations:()=>s,getLanguageInfo:()=>a,setLanguage:p,getCategoryText:function(e){return c(i)?.categories?.[e]}}}const T=new Map,D=new Map;function q(e,t){if(document.getElementById(e))return;const o=document.createElement("script");o.id=e,o.src=t.src,o.async=!0,t.onLoad&&o.addEventListener("load",t.onLoad,{once:!0}),document.head.appendChild(o),D.set(e,o)}function j(e){return"needsReload"in e&&!0===e.needsReload}function N(e){switch(e.vendor){case"meta":return{id:"meta",category:e.category??"advertisement",stop:()=>window.fbq?.("consent","revoke"),resume:()=>window.fbq?.("consent","grant")};case"tiktok":return{id:"tiktok",category:e.category??"advertisement",needsReload:!0};case"linkedin":return{id:"linkedin",category:e.category??"advertisement",needsReload:!0};case"hotjar":return{id:"hotjar",category:e.category??"analytics",needsReload:!0};case"segment":return{id:"segment",category:e.category??"analytics",needsReload:!0}}}const E=new Map,G=new Set,F=new Set;function X(e){E.set(e.id,e)}function z(e){const t=[];for(const o of E.values()){const n=!0!==e[o.category];if(j(o))n?F.has(o.id)&&(t.push(o.id),F.delete(o.id)):F.add(o.id);else if(n){if(!G.has(o.id))try{o.stop(),G.add(o.id)}catch{t.push(o.id)}}else if(G.has(o.id)){G.delete(o.id);try{o.resume?.()}catch{}}}return{reloadRequiredBy:t}}function K(e,t){const o={consentId:e.consentId,categories:e.categories,regulation:e.regulation,domain:"undefined"!=typeof window?window.location.hostname:"unknown"};return t&&(o.region=t),o}function W(e){const t=new Set,o=f(e.categories),n=e.googleConsentMatch??"any";let l;void 0===e.googleConsentMatch&&function(e){const t=new Map;for(const o of e.list)for(const e of o.gcm??[]){let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(o.id)}for(const[e,o]of t)o.size<=1||b(`categories ${[...o].map(e=>JSON.stringify(e)).join(", ")} all map to the Google signal "${e}", which is a single on/off — this mapping is lossy. Set \`googleConsentMatch: "all"\` to grant it only when all are granted, or "any" (default) to grant it when any is.`)}(o);let u,g,p=!1;function h(e){const t={};for(const n of o.ids)t[n]=!!o.requiredIds.has(n)||e(n);return t}let y=[],m=!1;for(const t of e.integrations??[])X(N(t));for(const t of e.customStopHandlers??[])X(t);const v="undefined"==typeof document?null:r(document.cookie),w=e.regulation??"DEFAULT",k=v?.tax,C=k===o.taxonomyHash,x=null!=v&&(C||void 0===k&&o.isDefault);if(null!=v&&x)l=c(v,w,o);else{const e=v?.consentid??a();l=d(e,w,o),null!=v&&s(),"CCPA"===l.regulation&&i(l)}function S(){const e={consentId:l.consentId,hasActed:l.hasActed,categories:{...l.categories},regulation:l.regulation,lastRenewed:l.lastRenewed,taxonomyHash:l.taxonomyHash};for(const o of t)o(e)}function I(){!function(e){if("undefined"!=typeof document)for(const[t,o]of T)!0===e[o.category]&&(D.has(t)||q(t,o))}(g)}function A(){l={...l,hasActed:!0,lastRenewed:Date.now()},i(l);let t=!1;for(const e of o.ids)if(u[e]&&!l.categories[e]){t=!0;break}if(u={...l.categories},g={...l.categories},S(),e.onConsentUpdate?.(l),e.backend)try{Promise.resolve(e.backend.persist(K(l,e.region))).catch(()=>{})}catch{}else e.apiUrl&&async function(e,t,o,n){const r=K(o,n),i={"Content-Type":"application/json"};t&&(i.Authorization=`Bearer ${t}`);try{await fetch(e,{method:"POST",headers:i,body:JSON.stringify(r),keepalive:!0})}catch{}}(e.apiUrl,e.apiKey,l,e.region);try{I()}catch{}let r=!1;try{const{reloadRequiredBy:e}=z(g);r=function(e){const t=e.length!==y.length||e.some((e,t)=>e!==y[t]);return t&&(y=e,m=!1),t}(e)}catch{}try{R(o,g,n)}catch{}r&&S(),t&&e.reloadOnRevoke&&"undefined"!=typeof window&&window.location.reload()}l={...l,taxonomyHash:o.taxonomyHash},e.gpcOptOut&&!l.hasActed&&(l={...l,categories:h(()=>!1)},i(l)),u={...l.categories},g={...l.categories},Promise.resolve().then(()=>e.onConsentReady?.(l));const O={get consentId(){return l.consentId},get hasActed(){return l.hasActed},get categories(){return{...l.categories}},get committedCategories(){return{...g}},get regulation(){return l.regulation},get lastRenewed(){return l.lastRenewed},get taxonomyHash(){return l.taxonomyHash},get isPreferencesOpen(){return p},acceptAll(){l={...l,categories:h(()=>!0)},p=!1,A()},rejectAll(){l={...l,categories:h(()=>!1)},p=!1,A()},acceptSelected(e){l={...l,categories:h(t=>e.includes(t))},p=!1,A()},updateCategory(e,t){o.requiredIds.has(e)||o.ids.includes(e)&&(l={...l,categories:{...l.categories,[e]:t}},S())},savePreferences(){p=!1,A()},resetConsent(){s();const e=a();l=d(e,l.regulation,o),g={...l.categories},u={...l.categories},p=!1,z(g),R(o,g,n),y=[],m=!1,S()},showPreferences(){p=!0,S()},hidePreferences(){p=!1,S()},subscribe:e=>(t.add(e),()=>t.delete(e)),registerScript(e){!function(e){T.set(e.id,e)}(e),I()},get reloadNotice(){return{required:y.length>0&&!m,reasons:[...y]}},dismissReloadNotice(){m||(m=!0,S())}};I();try{!function(e){for(const t of E.values()){const o=!0!==e[t.category];if(j(t))o?F.delete(t.id):F.add(t.id);else try{o?(t.stop(),G.add(t.id)):(G.delete(t.id),t.resume?.())}catch{}}}(l.categories)}catch{}try{R(o,l.categories,n)}catch{}return O}function Y(e,t,o,n){let r;try{const e="undefined"!=typeof window?window.location.href:"http://localhost";r=new URL(t,e)}catch{return null}const i=r.hostname.toLowerCase(),s=r.pathname+r.search,a=o.toUpperCase();for(const t of e){const e=t.domain.toLowerCase();if((i===e||i.endsWith("."+e))&&((!t.pathIncludes||s.includes(t.pathIncludes))&&(!t.methods||t.methods.map(e=>e.toUpperCase()).includes(a))&&!n(t.category)))return t}return null}let V=null;function J(e,t){if("undefined"==typeof window)return()=>{};if(V)return()=>{};if(!e.rules.length)return()=>{};const o={originalFetch:window.fetch,originalXhrOpen:XMLHttpRequest.prototype.open,originalXhrSend:XMLHttpRequest.prototype.send,originalSendBeacon:"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon?navigator.sendBeacon:void 0};V=o;const n=!1!==e.logBlockedRequests;function r(t){n&&console.warn(`[cookieyes] blocked ${t.method} ${t.url} (rule "${t.rule.id}", category: ${t.rule.category})`),e.onRequestBlocked?.(t)}if(window.fetch=function(n,i){let s="",a=i?.method??"GET";"string"==typeof n?s=n:n instanceof URL?s=n.toString():(s=n.url,a=i?.method??n.method);const c=Y(e.rules,s,a,t);return c?(r({rule:c,url:s,method:a}),Promise.reject(new TypeError(`Blocked by consent (rule: ${c.id}, category: ${c.category})`))):o.originalFetch.call(window,n,i)},XMLHttpRequest.prototype.open=function(e,t,...n){return this._cyUrl=t.toString(),this._cyMethod=e,o.originalXhrOpen.apply(this,[e,t,...n])},XMLHttpRequest.prototype.send=function(n){const i=this._cyUrl??"",s=this._cyMethod??"GET",a=Y(e.rules,i,s,t);return a?(r({rule:a,url:i,method:s}),void this.abort()):o.originalXhrSend.call(this,n)},o.originalSendBeacon){const n=o.originalSendBeacon;navigator.sendBeacon=function(o,i){const s=Y(e.rules,o.toString(),"POST",t);return s?(r({rule:s,url:o.toString(),method:"POST"}),!0):n.call(navigator,o,i)}}return Q}function Q(){V&&("undefined"!=typeof window&&(window.fetch=V.originalFetch,XMLHttpRequest.prototype.open=V.originalXhrOpen,XMLHttpRequest.prototype.send=V.originalXhrSend,V.originalSendBeacon&&(navigator.sendBeacon=V.originalSendBeacon)),V=null)}const Z=[{country:"x-vercel-ip-country",region:"x-vercel-ip-country-region"},{country:"cf-ipcountry"}];function ee(){return"undefined"!=typeof navigator&&!0===navigator.globalPrivacyControl}function te(e,t){const o=e.strictest??"GDPR";if(t)return e.detect&&"undefined"!=typeof console&&console.warn("[cookieyes] `regulation` is set manually, so region detection is ignored. Remove one of them to clear the conflict."),{region:void 0,regulation:t,source:"manual",confidence:"high"};const n=e.detect?.(),r=n?function(e,t){if(e)return e[t]??e[t.split("-")[0]??""]}(e.map,n):void 0;return{region:n,regulation:r??o,source:r?"detected":"strictest",confidence:r?"high":"low"}}function oe(e,t){"undefined"!=typeof console&&console.info("[cookieyes] region detection",{region:e.region,regulation:e.regulation,source:e.source,confidence:e.confidence,gpcOptOut:t})}let ne=null,re=null;function ie(e){if(ne)return ne;"offline"===e.mode&&m();const t=h(e),o=new Set,n=t.onConsentUpdate;let r;const i=t.region?te(t.region,t.regulation):{region:void 0,regulation:t.regulation??"DEFAULT",source:"manual",confidence:"high"},s={};"self-hosted"===t.mode&&(t.backend?s.backend=t.backend:t.apiUrl&&(s.apiUrl=t.apiUrl)),t.apiKey&&(s.apiKey=t.apiKey),s.regulation=i.regulation,i.region&&(s.region=i.region);const a=(c=i.regulation,d=t.region,"CCPA"===c&&(d?.honorGpc??!0)&&ee());var c,d;a&&(s.gpcOptOut=!0),t.region?.debug&&oe(i,a),t.colorScheme&&(s.colorScheme=t.colorScheme),t.theme&&(s.theme=t.theme),t.reloadOnRevoke&&(s.reloadOnRevoke=t.reloadOnRevoke),t.googleConsentMatch&&(s.googleConsentMatch=t.googleConsentMatch),t.builtInIntegrations&&t.builtInIntegrations.length>0&&(w(),s.integrations=t.builtInIntegrations),t.customStopHandlers&&(s.customStopHandlers=t.customStopHandlers),t.categories&&(s.categories=t.categories),t.onConsentReady&&(s.onConsentReady=t.onConsentReady),s.onConsentUpdate=e=>{n?.(e),r.push(e.categories);const t=function(e){const t=[],o=[];for(const n of Object.keys(e))e[n]?t.push(n):o.push(n);return{allowedCategories:t,deniedCategories:o}}(e.categories);for(const e of o)e(t)};const l=W(s);r=k(()=>l.committedCategories);const u=f(t.categories),g=new Set;function p(){const e=v();for(const t of g)t(e)}l.subscribe(p);const y=_(t.i18n,p);function v(){const e=l.categories;return{consentId:l.consentId,hasActed:l.hasActed,categories:e,consents:e,committedConsents:l.committedCategories,regulation:l.regulation,lastRenewed:l.lastRenewed,taxonomyHash:l.taxonomyHash,activeUI:l.isPreferencesOpen?"dialog":l.hasActed?null:"banner",has:e=>!0===l.committedCategories[e],saveConsents:async e=>{"all"===e?l.acceptAll():"necessary"===e?l.rejectAll():l.acceptSelected(e)},setConsent:(e,t)=>l.updateCategory(e,t),subscribeToConsentChanges:e=>(o.add(e),()=>{o.delete(e)})}}const b={subscribe:e=>(g.add(e),()=>{g.delete(e)}),getState:v,on:(e,t,o)=>r.on(e,t,o),get translations(){return y.getTranslations()},getLanguageInfo:y.getLanguageInfo,setLanguage:y.setLanguage,getCategoryText:y.getCategoryText,categories:u,getRegion:()=>i};return t.networkBlocker&&t.networkBlocker.rules.length>0&&J(t.networkBlocker,e=>!0===l.committedCategories[e]),t.integrations&&t.integrations.length>0&&(L(t.integrations.map(e=>e.id),(t.builtInIntegrations??[]).map(e=>e.vendor)),H(t.integrations,u.ids),re=B(t.integrations,{granted:e=>!0===l.committedCategories[e],subscribe:e=>l.subscribe(()=>e()),region:i})),ne={consentManager:l,consentStore:b,getIntegrations:()=>re?.list()??[]},ne}exports.CORE_VERSION="0.4.0",exports.DEFAULT_CATEGORIES=l,exports.INTEGRATION_FORMAT_VERSION=1,exports._clearScriptRegistry=function(){if("undefined"!=typeof document)for(const e of D.values())e.remove();T.clear(),D.clear()},exports._clearStopHandlers=function(){E.clear(),G.clear(),F.clear()},exports._logRegionDecision=oe,exports._normalizeConfig=h,exports._resetBuiltInIntegrationsWarning=function(){v=!1},exports._resetOfflineModeWarning=function(){y=!1},exports._warnBuiltInIntegrationsDeprecated=w,exports._warnOfflineModeDeprecated=m,exports.broadcastGoogleConsent=R,exports.computeGoogleConsent=x,exports.createConsentEmitter=k,exports.createConsentManager=W,exports.createLanguageController=_,exports.defaultTranslations=S,exports.generateConsentId=a,exports.getOrCreateConsentRuntime=ie,exports.getTextDirection=O,exports.initCookieYes=function(e){return ie(e)},exports.installNetworkBlocker=J,exports.mergeTranslations=U,exports.parseCookie=o,exports.parseCookieHeader=r,exports.pickLanguage=$,exports.primaryOf=A,exports.readGpc=ee,exports.readServerConsent=function(e,t={}){if("string"!=typeof e||0===e.length)return null;const o=r(e);if(null==o)return null;const n=f(t.categories),i=o.tax;if(!(i===n.taxonomyHash||void 0===i&&n.isDefault))return null;const s=c(o,t.regulation??"DEFAULT",n);return s.hasActed?{...s,taxonomyHash:n.taxonomyHash}:null},exports.regionFromHeaders=function(e,t){if(t?.header)return e.get(t.header)||void 0;for(const{country:t,region:o}of Z){const n=e.get(t);if(!n)continue;const r=o?e.get(o):void 0;return r?`${n}-${r}`:n}},exports.registerStopHandler=X,exports.resetConsentRuntime=function(){re?.stop(),re=null,ne=null},exports.resolveBuiltInIntegration=N,exports.resolveCategories=f,exports.resolveRegion=te,exports.resolveTranslations=function(e){const t=e?.messages??{},o=$(e);return U(S,t[o]??t[A(o)])},exports.runIntegrations=B,exports.serializeCookie=n,exports.uninstallNetworkBlocker=Q,exports.warnOverlappingVendors=L,exports.warnUnknownCategories=H;
|
|
1
|
+
"use strict";const e="cookieyes-consent",t=new Set(["consentid","consent","action","tax","lastRenewedDate"]);function o(e){const o={categories:{}};for(const n of e.split(",")){const e=n.indexOf(":");if(-1===e)continue;const r=n.slice(0,e).trim(),i=n.slice(e+1).trim();t.has(r)?o[r]=i:r.length>0&&(o.categories[r]=i)}return o}function n(e){const t=[`consentid:${e.consentId}`,"consent:"+(e.hasActed?"yes":"no"),"action:"+(e.hasActed?"yes":"no")];e.taxonomyHash&&t.push(`tax:${e.taxonomyHash}`);for(const[o,n]of Object.entries(e.categories))t.push(`${o}:${n?"yes":"no"}`);return t.push(`lastRenewedDate:${e.lastRenewed??Date.now()}`),t.join(",")}function r(t){for(const n of t.split(";")){const t=n.trim(),r=t.indexOf("=");if(-1===r)continue;if(t.slice(0,r).trim()!==e)continue;const i=t.slice(r+1).trim();try{return o(decodeURIComponent(i))}catch{return null}}return null}function i(t){if("undefined"==typeof document)return;const o=encodeURIComponent(n(t));document.cookie=`${e}=${o}; max-age=31536000; path=/; SameSite=Lax`}function s(){"undefined"!=typeof document&&(document.cookie=`${e}=; max-age=0; path=/`)}function a(){const e=new Uint8Array(32);if("undefined"!=typeof crypto&&crypto.getRandomValues)crypto.getRandomValues(e);else for(let t=0;t<e.length;t++)e[t]=Math.floor(256*Math.random());return btoa(String.fromCharCode(...e)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"").slice(0,44)}function c(e,t,o){const n={};for(const t of o.ids)n[t]=!!o.requiredIds.has(t)||"yes"===e.categories[t];return{consentId:e.consentid??a(),hasActed:"yes"===e.action,categories:n,regulation:t,lastRenewed:e.lastRenewedDate?Number(e.lastRenewedDate):void 0,taxonomyHash:e.tax}}function l(e,t,o){const n="CCPA"===t,r={};for(const e of o.ids)r[e]=!!o.requiredIds.has(e)||n;return{consentId:e,hasActed:!1,categories:r,regulation:t,taxonomyHash:o.taxonomyHash}}const d=[{id:"necessary",required:!0},{id:"functional",gcm:["functionality_storage","personalization_storage"]},{id:"analytics",gcm:["analytics_storage"]},{id:"performance"},{id:"advertisement",gcm:["ad_storage","ad_user_data","ad_personalization"]}];function u(e){let t=2166136261;for(let o=0;o<e.length;o++)t^=e.charCodeAt(o),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function g(e,t){const o=e.map(e=>e.id),n=new Set(e.filter(e=>e.required).map(e=>e.id)),r=e.map(e=>`${e.id}:${e.required?1:0}:${(e.gcm??[]).join("+")}`).join("|");return{list:e,ids:o,requiredIds:n,taxonomyHash:u(r),isDefault:t}}function f(e){if(!e||0===e.length)return g(d,!0);const o=function(e){const o=e.map(e=>e.id);return o.some(e=>"string"!=typeof e||0===e.length)?"every category needs a non-empty string id":o.some(e=>e.includes(",")||e.includes(":"))?"category ids must not contain ',' or ':'":new Set(o).size!==o.length?"category ids must be unique":o.some(e=>t.has(e))?`category ids must not be one of the reserved keys: ${[...t].join(", ")}`:e.some(e=>!0===e.required)?null:"at least one category must be marked { required: true }"}(e);return o?("undefined"!=typeof console&&console.warn(`[cookieyes] Invalid categories config (${o}). Falling back to the default five (necessary, functional, analytics, performance, advertisement).`),g(d,!0)):g(e,!1)}function p(e){"undefined"!=typeof console&&console.warn(e)}function h(e){const t={mode:e.mode},o=e.overrides?.regulation;return void 0!==e.regulation?(t.regulation=e.regulation,void 0!==o&&p("[CookieYes] Received both `regulation` and the deprecated `overrides.regulation`. Using the top-level `regulation` and ignoring `overrides`. Drop the `overrides` object — it is deprecated and will be removed after three release cycles.")):void 0!==o&&(t.regulation=o),void 0!==e.region&&(t.region=e.region),void 0!==e.colorScheme&&(t.colorScheme=e.colorScheme),void 0!==e.theme&&(t.theme=e.theme),void 0!==e.i18n&&(t.i18n=e.i18n),void 0!==e.categories&&(t.categories=e.categories),void 0!==e.networkBlocker&&(t.networkBlocker=e.networkBlocker),void 0!==e.reloadOnRevoke&&(t.reloadOnRevoke=e.reloadOnRevoke),void 0!==e.googleConsentMatch&&(t.googleConsentMatch=e.googleConsentMatch),void 0!==e.integrations&&(t.integrations=e.integrations),void 0!==e.builtInIntegrations&&(t.builtInIntegrations=e.builtInIntegrations),void 0!==e.customStopHandlers&&(t.customStopHandlers=e.customStopHandlers),void 0!==e.onConsentReady&&(t.onConsentReady=e.onConsentReady),void 0!==e.onConsentUpdate&&(t.onConsentUpdate=e.onConsentUpdate),"self-hosted"===e.mode&&(void 0!==e.apiKey&&(t.apiKey=e.apiKey),void 0!==e.backend&&(t.backend=e.backend),void 0!==e.apiUrl?(t.apiUrl=e.apiUrl,void 0!==e.backendURL&&p("[CookieYes] Received both `apiUrl` and the deprecated `backendURL`. Using `apiUrl` and ignoring `backendURL`. Rename `backendURL` to `apiUrl` — the alias is deprecated and will be removed after three release cycles.")):void 0!==e.backendURL&&(t.apiUrl=e.backendURL)),t}let y=!1;function m(){y||(y=!0,"undefined"!=typeof console&&console.warn('[cookieyes] mode: "offline" has been renamed to "cookie-only". Both do exactly the same thing, but "offline" is deprecated and will be removed after three release cycles. See https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/migration.mdx for the full migration guide. Update to .mode("cookie-only") (or { mode: "cookie-only" }).'))}let v=!1;function w(){v||(v=!0,"undefined"!=typeof console&&console.warn("[cookieyes] `builtInIntegrations` (formerly the `integrations` field) is deprecated and will be removed after three release cycles. Use the `integrations` field with a preset from `@cookieyes/scripts` instead. See https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/migration.mdx for the full migration guide."))}function b(e){const t={save:new Set,change:new Set};let o={...e()};function n(e,t,o){try{e.listener(o)}catch(e){"undefined"!=typeof console&&console.error(`[cookieyes] a consent "${t}" listener threw; others are unaffected:`,e)}}function r(e,o){for(const r of[...t[e]])r.category&&!o.changedCategories.includes(r.category)||n(r,e,o)}return{on(o,r,i){const s=i?.category?{listener:r,category:i.category}:{listener:r};return t[o].add(s),n(s,o,{categories:{...e()},changedCategories:[],isInitial:!0}),()=>{t[o].delete(s)}},push(e){const t={...e},n=[];for(const e of Object.keys(t))o[e]!==t[e]&&n.push(e);o=t,r("save",{categories:t,changedCategories:n,isInitial:!1}),n.length>0&&r("change",{categories:t,changedCategories:n,isInitial:!1})}}}function k(e){"undefined"!=typeof console&&console.warn(`[cookieyes] ${e}`)}const C=["ad_storage","ad_user_data","ad_personalization","analytics_storage","functionality_storage","personalization_storage","security_storage"];function x(e,t,o="any"){const n={};for(const r of C){if("security_storage"===r){n[r]="granted";continue}const i=e.list.filter(e=>e.gcm?.includes(r));if(0===i.length){n[r]="denied";continue}const s="all"===o?i.every(e=>!0===t[e.id]):i.some(e=>!0===t[e.id]);n[r]=s?"granted":"denied"}return n}function R(e,t,o="any"){if("undefined"==typeof window||!Array.isArray(window.dataLayer))return;const n=x(e,t,o),r=window.dataLayer;if(!r)return;!function(){r.push(arguments)}("consent","update",n)}const S={bannerTitle:"We value your privacy",bannerDescription:"We use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking “Accept All”, you consent to our use of cookies.",acceptAll:"Accept All",rejectAll:"Reject All",managePreferences:"Customise",savePreferences:"Save My Preferences",doNotSell:"Do Not Sell or Share My Personal Information",ccpaDescription:"This website or its third-party tools process personal data. You can opt out of the sale of your personal information by clicking on the “Do Not Sell or Share My Personal Information” link.",accept:"Accept",poweredBy:"Powered by CookieYes",preferencesTitle:"Customise Consent Preferences",preferencesIntro:"We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.",alwaysActive:"Always Active",preferencesDialogLabel:"Cookie preferences",optOutDialogLabel:"Opt-out preferences",recallButtonLabel:"Consent Preferences",categories:{necessary:{label:"Necessary",description:"Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data."},functional:{label:"Functional",description:"Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features."},analytics:{label:"Analytics",description:"Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc."},performance:{label:"Performance",description:"Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors."},advertisement:{label:"Advertisement",description:"Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns."}},optOut:{title:"Opt-out Preferences",description:'We use third-party cookies that help us analyse how you use this website, store your preferences, and provide the content and advertisements that are relevant to you. However, you can opt out of these cookies by checking "Do Not Sell or Share My Personal Information" and clicking the "Save My Preferences" button. Once you opt out, you can opt in again at any time by unchecking "Do Not Sell or Share My Personal Information" and clicking the "Save My Preferences" button.',cancel:"Cancel",successText:"Your opt-out preference has been honored.",successCountdown:"Banner closes automatically in {seconds} s..."},bannerCloseLabel:"Close",preferencesCloseLabel:"Close preferences",optOutCloseLabel:"Close",gatedFrame:{placeholder:"This content requires {category} cookies to be enabled.",action:"Manage Preferences"},reloadNotice:{message:"Some tracking on this page can only be fully stopped by reloading. Reload to apply your change, or dismiss to keep browsing.",reloadButton:"Reload page",dismissButton:"Dismiss"}},I=new Set(["ar","he","fa","ur","ps","sd","yi","dv"]);function A(e){return e.split("-")[0]?.toLowerCase()??""}function L(e){return I.has(A(e))?"rtl":"ltr"}function O(e,t){if(!t)return e;const o={...e};for(const[n,r]of Object.entries(t)){if(null==r)continue;const t=e[n],i="object"==typeof r&&!Array.isArray(r)&&"object"==typeof t&&null!=t;o[n]=i?O(t,r):r}return o}function U(e){const t=e?.messages??{},o=[];e?.locale&&o.push(e.locale),(e?.detectBrowserLanguage??1)&&"undefined"!=typeof navigator&&navigator.language&&o.push(navigator.language);for(const e of o){if(t[e])return e;const o=A(e);if(o&&t[o])return o}return"en"}function $(e,t){const o=new Set(e);for(const e of t)o.has(e)&&P(`"${e}" is configured as both a script integration and a built-in integration — remove one to avoid loading it twice (e.g. double-counted events).`)}function M(e,t){const o=new Set(t);for(const t of e){if("afterConsent"!==t.load)continue;const e=t.category,n=Array.isArray(e)?e:[e];if(0!==n.length)for(const e of n)o.has(e)||P(`integration "${t.id}" is gated on category "${e}", which isn't in your configured categories — it will never load. Pass a category that exists (e.g. segment({ category: "…" })), or add it to your taxonomy.`);else P(`integration "${t.id}" has an empty category list — it will never load. Give it at least one category that exists in your taxonomy.`)}}function P(e,t){"undefined"!=typeof console&&(void 0!==t?console.error(`[cookieyes] ${e}`,t):console.warn(`[cookieyes] ${e}`))}function H(e,t){const o=Array.isArray(e.category)?e.category:[e.category];return 0!==o.length&&("any"===e.match?o.some(e=>t.granted(e)):o.every(e=>t.granted(e)))}function B(e,t){const o=[],n=new Set;let r=!1;for(const t of e){const e=t;"string"!=typeof e.vendor||"function"==typeof e.setup?1===t.version?n.has(t.id)?P(`integration "${t.id}" is registered more than once; skipping the duplicate.`):(n.add(t.id),o.push({integration:t,status:"idle",everLoaded:!1,loading:!1,control:void 0,subs:new Set,wasGranted:!1})):P(`integration "${t.id}" uses format version ${t.version}, but this build understands 1. Skipping it.`):P(`an entry in "integrations" looks like the old built-in format ({ vendor: "${e.vendor}" }). That moved to "builtInIntegrations" — move it there, or use a preset from "@cookieyes/scripts" in "integrations". Skipping it.`)}function i(e){for(const t of e.subs)try{t()}catch{}e.subs.clear()}function s(e){i(e),"active"===e.status&&(!function(e){const{integration:t,control:o}=e;try{"remove"===t.onRevoke?o?.():"silence"===t.onRevoke&&o?.silence()}catch(e){P(`integration "${t.id}" threw while being torn down.`,e)}e.control=void 0}(e),"remove"===e.integration.onRevoke?e.status="removed":"silence"===e.integration.onRevoke&&(e.status="silenced"))}function a(e){e.loading=!0,e.status="loading",Promise.resolve().then(()=>e.integration.setup(function(e){return{granted:()=>H(e.integration,t),onConsentChange:o=>{const n=t.subscribe(o);return e.subs.add(n),()=>{e.subs.delete(n)&&n()}},region:t.region}}(e))).then(t=>{e.loading=!1,e.control=t??void 0,e.everLoaded=!0,e.status="active",r?s(e):c(e)}).catch(t=>{e.loading=!1,e.status="error",i(e),P(`integration "${e.integration.id}" failed to load; will retry on the next change.`,t)})}function c(e){const{integration:o}=e,n=H(o,t);if(n&&(e.wasGranted=!0),r||e.loading)return;if("idle"===e.status||"removed"===e.status||"error"===e.status){return void((e.everLoaded?n:"immediately"===o.load||n)&&a(e))}if("keep"===o.onRevoke)return;if("remove"===o.onRevoke){if(!n&&"active"===e.status&&e.wasGranted){i(e);try{e.control?.()}catch(e){P(`integration "${o.id}" cleanup threw on revoke.`,e)}e.control=void 0,e.status="removed"}return}const s=e.control;if(n||"active"!==e.status){if(n&&"silenced"===e.status){try{s?.resume()}catch(e){P(`integration "${o.id}" resume() threw.`,e)}e.status="active"}}else{try{s?.silence()}catch(e){P(`integration "${o.id}" silence() threw.`,e)}e.status="silenced"}}function l(){for(const e of o)c(e)}const d=t.subscribe(l);return l(),{status:()=>{const e={};for(const t of o)e[t.integration.id]=t.status;return e},list:()=>o.map(e=>({id:e.integration.id,category:e.integration.category,load:e.integration.load,onRevoke:e.integration.onRevoke,status:e.status})),stop:()=>{if(!r){r=!0,d();for(const e of o)s(e)}}}}function T(e,t){const o={...e?.messages},n=e?.loadLanguage,r=new Set;let i=U(e),s=d(i),a=u();function c(e){return o[e]??o[A(e)]}function l(e){return"en"===A(e)||void 0!==c(e)}function d(e){return O(S,c(e))}function u(){return{language:i,direction:L(i),languages:Array.from(new Set(["en",...Object.keys(o)]))}}function g(e){i=e,s=d(e),a=u(),t()}function f(e,t){r.has(e)||"undefined"==typeof console||(r.add(e),console.warn(`[cookieyes] no translations for language "${e}"; staying on "${i}". Add it to i18n.messages or provide i18n.loadLanguage.`,t??""))}function p(e){return l(e)?(g(e),Promise.resolve()):n?Promise.resolve().then(()=>n(e)).then(t=>{o[e]=t,g(e)}).catch(t=>f(e,t)):(f(e),Promise.resolve())}return n&&e?.locale&&!l(e.locale)&&"undefined"!=typeof window&&p(e.locale),{getTranslations:()=>s,getLanguageInfo:()=>a,setLanguage:p,getCategoryText:function(e){return c(i)?.categories?.[e]}}}const _=new Map,D=new Map;function q(e,t){if(document.getElementById(e))return;const o=document.createElement("script");o.id=e,o.src=t.src,o.async=!0,t.onLoad&&o.addEventListener("load",t.onLoad,{once:!0}),document.head.appendChild(o),D.set(e,o)}function j(e){return"needsReload"in e&&!0===e.needsReload}function N(e){switch(e.vendor){case"meta":return{id:"meta",category:e.category??"advertisement",stop:()=>window.fbq?.("consent","revoke"),resume:()=>window.fbq?.("consent","grant")};case"tiktok":return{id:"tiktok",category:e.category??"advertisement",needsReload:!0};case"linkedin":return{id:"linkedin",category:e.category??"advertisement",needsReload:!0};case"hotjar":return{id:"hotjar",category:e.category??"analytics",needsReload:!0};case"segment":return{id:"segment",category:e.category??"analytics",needsReload:!0}}}const E=new Map,G=new Set,F=new Set;function X(e){E.set(e.id,e)}function z(e){const t=[];for(const o of E.values()){const n=!0!==e[o.category];if(j(o))n?F.has(o.id)&&(t.push(o.id),F.delete(o.id)):F.add(o.id);else if(n){if(!G.has(o.id))try{o.stop(),G.add(o.id)}catch{t.push(o.id)}}else if(G.has(o.id)){G.delete(o.id);try{o.resume?.()}catch{}}}return{reloadRequiredBy:t}}function K(e,t){const o={consentId:e.consentId,categories:e.categories,regulation:e.regulation,domain:"undefined"!=typeof window?window.location.hostname:"unknown"};return t&&(o.region=t),o}function W(e){const t=new Set,o=f(e.categories),n=e.googleConsentMatch??"any";let d;void 0===e.googleConsentMatch&&function(e){const t=new Map;for(const o of e.list)for(const e of o.gcm??[]){let n=t.get(e);n||(n=new Set,t.set(e,n)),n.add(o.id)}for(const[e,o]of t)o.size<=1||k(`categories ${[...o].map(e=>JSON.stringify(e)).join(", ")} all map to the Google signal "${e}", which is a single on/off — this mapping is lossy. Set \`googleConsentMatch: "all"\` to grant it only when all are granted, or "any" (default) to grant it when any is.`)}(o);let u,g,p=!1;function h(e){const t={};for(const n of o.ids)t[n]=!!o.requiredIds.has(n)||e(n);return t}let y=[],m=!1;for(const t of e.integrations??[])X(N(t));for(const t of e.customStopHandlers??[])X(t);const v="undefined"==typeof document?null:r(document.cookie),w=e.regulation??"DEFAULT",b=v?.tax,C=b===o.taxonomyHash,x=null!=v&&(C||void 0===b&&o.isDefault);if(null!=v&&x)d=c(v,w,o);else{const e=v?.consentid??a();d=l(e,w,o),null!=v&&s(),"CCPA"===d.regulation&&i(d)}function S(){const e={consentId:d.consentId,hasActed:d.hasActed,categories:{...d.categories},regulation:d.regulation,lastRenewed:d.lastRenewed,taxonomyHash:d.taxonomyHash};for(const o of t)o(e)}function I(){!function(e){if("undefined"!=typeof document)for(const[t,o]of _)!0===e[o.category]&&(D.has(t)||q(t,o))}(g)}function A(){d={...d,hasActed:!0,lastRenewed:Date.now()},i(d);let t=!1;for(const e of o.ids)if(u[e]&&!d.categories[e]){t=!0;break}if(u={...d.categories},g={...d.categories},S(),e.onConsentUpdate?.(d),e.backend)try{Promise.resolve(e.backend.persist(K(d,e.region))).catch(()=>{})}catch{}else e.apiUrl&&async function(e,t,o,n){const r=K(o,n),i={"Content-Type":"application/json"};t&&(i.Authorization=`Bearer ${t}`);try{await fetch(e,{method:"POST",headers:i,body:JSON.stringify(r),keepalive:!0})}catch{}}(e.apiUrl,e.apiKey,d,e.region);try{I()}catch{}let r=!1;try{const{reloadRequiredBy:e}=z(g);r=function(e){const t=e.length!==y.length||e.some((e,t)=>e!==y[t]);return t&&(y=e,m=!1),t}(e)}catch{}try{R(o,g,n)}catch{}r&&S(),t&&e.reloadOnRevoke&&"undefined"!=typeof window&&window.location.reload()}d={...d,taxonomyHash:o.taxonomyHash},e.gpcOptOut&&!d.hasActed&&(d={...d,categories:h(()=>!1)},i(d)),u={...d.categories},g={...d.categories},Promise.resolve().then(()=>e.onConsentReady?.(d));const L={get consentId(){return d.consentId},get hasActed(){return d.hasActed},get categories(){return{...d.categories}},get committedCategories(){return{...g}},get regulation(){return d.regulation},get lastRenewed(){return d.lastRenewed},get taxonomyHash(){return d.taxonomyHash},get isPreferencesOpen(){return p},acceptAll(){d={...d,categories:h(()=>!0)},p=!1,A()},rejectAll(){d={...d,categories:h(()=>!1)},p=!1,A()},acceptSelected(e){d={...d,categories:h(t=>e.includes(t))},p=!1,A()},updateCategory(e,t){o.requiredIds.has(e)||o.ids.includes(e)&&(d={...d,categories:{...d.categories,[e]:t}},S())},savePreferences(){p=!1,A()},resetConsent(){s();const e=a();d=l(e,d.regulation,o),g={...d.categories},u={...d.categories},p=!1,z(g),R(o,g,n),y=[],m=!1,S()},showPreferences(){p=!0,S()},hidePreferences(){p=!1,S()},subscribe:e=>(t.add(e),()=>t.delete(e)),registerScript(e){!function(e){_.set(e.id,e)}(e),I()},get reloadNotice(){return{required:y.length>0&&!m,reasons:[...y]}},dismissReloadNotice(){m||(m=!0,S())}};I();try{!function(e){for(const t of E.values()){const o=!0!==e[t.category];if(j(t))o?F.delete(t.id):F.add(t.id);else try{o?(t.stop(),G.add(t.id)):(G.delete(t.id),t.resume?.())}catch{}}}(d.categories)}catch{}try{R(o,d.categories,n)}catch{}return L}function Y(e,t,o,n){let r;try{const e="undefined"!=typeof window?window.location.href:"http://localhost";r=new URL(t,e)}catch{return null}const i=r.hostname.toLowerCase(),s=r.pathname+r.search,a=o.toUpperCase();for(const t of e){const e=t.domain.toLowerCase();if((i===e||i.endsWith("."+e))&&((!t.pathIncludes||s.includes(t.pathIncludes))&&(!t.methods||t.methods.map(e=>e.toUpperCase()).includes(a))&&!n(t.category)))return t}return null}let V=null;function J(e,t){if("undefined"==typeof window)return()=>{};if(V)return()=>{};if(!e.rules.length)return()=>{};const o={originalFetch:window.fetch,originalXhrOpen:XMLHttpRequest.prototype.open,originalXhrSend:XMLHttpRequest.prototype.send,originalSendBeacon:"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon?navigator.sendBeacon:void 0};V=o;const n=!1!==e.logBlockedRequests;function r(t){n&&console.warn(`[cookieyes] blocked ${t.method} ${t.url} (rule "${t.rule.id}", category: ${t.rule.category})`),e.onRequestBlocked?.(t)}if(window.fetch=function(n,i){let s="",a=i?.method??"GET";"string"==typeof n?s=n:n instanceof URL?s=n.toString():(s=n.url,a=i?.method??n.method);const c=Y(e.rules,s,a,t);return c?(r({rule:c,url:s,method:a}),Promise.reject(new TypeError(`Blocked by consent (rule: ${c.id}, category: ${c.category})`))):o.originalFetch.call(window,n,i)},XMLHttpRequest.prototype.open=function(e,t,...n){return this._cyUrl=t.toString(),this._cyMethod=e,o.originalXhrOpen.apply(this,[e,t,...n])},XMLHttpRequest.prototype.send=function(n){const i=this._cyUrl??"",s=this._cyMethod??"GET",a=Y(e.rules,i,s,t);return a?(r({rule:a,url:i,method:s}),void this.abort()):o.originalXhrSend.call(this,n)},o.originalSendBeacon){const n=o.originalSendBeacon;navigator.sendBeacon=function(o,i){const s=Y(e.rules,o.toString(),"POST",t);return s?(r({rule:s,url:o.toString(),method:"POST"}),!0):n.call(navigator,o,i)}}return Q}function Q(){V&&("undefined"!=typeof window&&(window.fetch=V.originalFetch,XMLHttpRequest.prototype.open=V.originalXhrOpen,XMLHttpRequest.prototype.send=V.originalXhrSend,V.originalSendBeacon&&(navigator.sendBeacon=V.originalSendBeacon)),V=null)}const Z=[{country:"x-vercel-ip-country",region:"x-vercel-ip-country-region"},{country:"cf-ipcountry"}];function ee(){return"undefined"!=typeof navigator&&!0===navigator.globalPrivacyControl}function te(e,t){const o=e.strictest??"GDPR";if(t)return e.detect&&"undefined"!=typeof console&&console.warn("[cookieyes] `regulation` is set manually, so region detection is ignored. Remove one of them to clear the conflict."),{region:void 0,regulation:t,source:"manual",confidence:"high"};const n=e.detect?.(),r=n?function(e,t){if(e)return e[t]??e[t.split("-")[0]??""]}(e.map,n):void 0;return{region:n,regulation:r??o,source:r?"detected":"strictest",confidence:r?"high":"low"}}function oe(e,t){"undefined"!=typeof console&&console.info("[cookieyes] region detection",{region:e.region,regulation:e.regulation,source:e.source,confidence:e.confidence,gpcOptOut:t})}let ne=null,re=null;function ie(e){if(ne)return ne;"offline"===e.mode&&m();const t=h(e),o=new Set,n=t.onConsentUpdate;let r;const i=t.region?te(t.region,t.regulation):{region:void 0,regulation:t.regulation??"DEFAULT",source:"manual",confidence:"high"},s={};"self-hosted"===t.mode&&(t.backend?s.backend=t.backend:t.apiUrl&&(s.apiUrl=t.apiUrl)),t.apiKey&&(s.apiKey=t.apiKey),s.regulation=i.regulation,i.region&&(s.region=i.region);const a=(c=i.regulation,l=t.region,"CCPA"===c&&(l?.honorGpc??!0)&&ee());var c,l;a&&(s.gpcOptOut=!0),t.region?.debug&&oe(i,a),t.colorScheme&&(s.colorScheme=t.colorScheme),t.theme&&(s.theme=t.theme),t.reloadOnRevoke&&(s.reloadOnRevoke=t.reloadOnRevoke),t.googleConsentMatch&&(s.googleConsentMatch=t.googleConsentMatch),t.builtInIntegrations&&t.builtInIntegrations.length>0&&(w(),s.integrations=t.builtInIntegrations),t.customStopHandlers&&(s.customStopHandlers=t.customStopHandlers),t.categories&&(s.categories=t.categories),t.onConsentReady&&(s.onConsentReady=t.onConsentReady),s.onConsentUpdate=e=>{n?.(e),r.push(e.categories);const t=function(e){const t=[],o=[];for(const n of Object.keys(e))e[n]?t.push(n):o.push(n);return{allowedCategories:t,deniedCategories:o}}(e.categories);for(const e of o)e(t)};const d=W(s);r=b(()=>d.committedCategories);const u=f(t.categories),g=new Set;function p(){const e=v();for(const t of g)t(e)}d.subscribe(p);const y=T(t.i18n,p);function v(){const e=d.categories;return{consentId:d.consentId,hasActed:d.hasActed,categories:e,consents:e,committedConsents:d.committedCategories,regulation:d.regulation,lastRenewed:d.lastRenewed,taxonomyHash:d.taxonomyHash,activeUI:d.isPreferencesOpen?"dialog":d.hasActed?null:"banner",has:e=>!0===d.committedCategories[e],saveConsents:async e=>{"all"===e?d.acceptAll():"necessary"===e?d.rejectAll():d.acceptSelected(e)},setConsent:(e,t)=>d.updateCategory(e,t),subscribeToConsentChanges:e=>(o.add(e),()=>{o.delete(e)})}}const k={subscribe:e=>(g.add(e),()=>{g.delete(e)}),getState:v,on:(e,t,o)=>r.on(e,t,o),get translations(){return y.getTranslations()},getLanguageInfo:y.getLanguageInfo,setLanguage:y.setLanguage,getCategoryText:y.getCategoryText,categories:u,getRegion:()=>i};return t.networkBlocker&&t.networkBlocker.rules.length>0&&J(t.networkBlocker,e=>!0===d.committedCategories[e]),t.integrations&&t.integrations.length>0&&($(t.integrations.map(e=>e.id),(t.builtInIntegrations??[]).map(e=>e.vendor)),M(t.integrations,u.ids),re=B(t.integrations,{granted:e=>!0===d.committedCategories[e],subscribe:e=>d.subscribe(()=>e()),region:i})),ne={consentManager:d,consentStore:k,getIntegrations:()=>re?.list()??[]},ne}exports.CORE_VERSION="0.5.0",exports.DEFAULT_CATEGORIES=d,exports.INTEGRATION_FORMAT_VERSION=1,exports._clearScriptRegistry=function(){if("undefined"!=typeof document)for(const e of D.values())e.remove();_.clear(),D.clear()},exports._clearStopHandlers=function(){E.clear(),G.clear(),F.clear()},exports._logRegionDecision=oe,exports._normalizeConfig=h,exports._resetBuiltInIntegrationsWarning=function(){v=!1},exports._resetOfflineModeWarning=function(){y=!1},exports._warnBuiltInIntegrationsDeprecated=w,exports._warnOfflineModeDeprecated=m,exports.broadcastGoogleConsent=R,exports.computeGoogleConsent=x,exports.createConsentEmitter=b,exports.createConsentManager=W,exports.createLanguageController=T,exports.defaultTranslations=S,exports.generateConsentId=a,exports.getOrCreateConsentRuntime=ie,exports.getTextDirection=L,exports.initCookieYes=function(e){return ie(e)},exports.installNetworkBlocker=J,exports.mergeTranslations=O,exports.parseCookie=o,exports.parseCookieHeader=r,exports.pickLanguage=U,exports.primaryOf=A,exports.readGpc=ee,exports.readServerConsent=function(e,t={}){if("string"!=typeof e||0===e.length)return null;const o=r(e);if(null==o)return null;const n=f(t.categories),i=o.tax;if(!(i===n.taxonomyHash||void 0===i&&n.isDefault))return null;const s=c(o,t.regulation??"DEFAULT",n);return s.hasActed?{...s,taxonomyHash:n.taxonomyHash}:null},exports.regionFromHeaders=function(e,t){if(t?.header)return e.get(t.header)||void 0;for(const{country:t,region:o}of Z){const n=e.get(t);if(!n)continue;const r=o?e.get(o):void 0;return r?`${n}-${r}`:n}},exports.registerStopHandler=X,exports.resetConsentRuntime=function(){Q(),re?.stop(),re=null,ne=null},exports.resolveBuiltInIntegration=N,exports.resolveCategories=f,exports.resolveRegion=te,exports.resolveTranslations=function(e){const t=e?.messages??{},o=U(e);return O(S,t[o]??t[A(o)])},exports.runIntegrations=B,exports.serializeCookie=n,exports.uninstallNetworkBlocker=Q,exports.warnOverlappingVendors=$,exports.warnUnknownCategories=M;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|