@cookieyes/core 0.3.0 → 0.4.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 CHANGED
@@ -242,6 +242,30 @@ Missing text falls back to English; custom categories translate by id (see the
242
242
  [configuration guide](https://github.com/cookieyes/cookieyes/blob/main/docs/configuration.md)).
243
243
  In React, use the `useTranslations()` / `useLanguage()` hooks instead.
244
244
 
245
+ ## Region-based regulation (geo-detection)
246
+
247
+ Optionally pick the regulation from the visitor's region. Fully optional; a manual
248
+ `regulation` always wins.
249
+
250
+ ```ts
251
+ const { consentStore } = initCookieYes({
252
+ mode: "cookie-only",
253
+ region: {
254
+ // `detect` is YOUR function — return the visitor's region, however you get it (sync).
255
+ detect: () => myRegion, // "US-CA" | "DE" | undefined
256
+ map: { "US-CA": "CCPA", DE: "GDPR" }, // you own the mapping
257
+ honorGpc: true, // default; browser "do not sell" signal → CCPA
258
+ },
259
+ });
260
+
261
+ consentStore.getRegion(); // { region, regulation, source, confidence }
262
+ ```
263
+
264
+ `detect` runs synchronously — you return a region you already have (server-injected value, your
265
+ own lookup done beforehand, etc.). Unknown/failed detection → the strictest regulation
266
+ (default `GDPR`), never a skipped banner. In self-hosted mode the detected region is included on
267
+ the consent-log payload.
268
+
245
269
  ## Low-level / advanced API
246
270
 
247
271
  You shouldn't need these for a typical integration — each exists for a
@@ -259,24 +283,36 @@ specific narrower situation than `consentStore.on` / `consentStore.subscribe`:
259
283
 
260
284
  When a visitor revokes consent, the SDK stops tracking **without reloading the
261
285
  page** — nothing they were doing (form input, scroll position, an open dialog)
262
- is lost. There are three layers:
286
+ is lost.
287
+
288
+ > **Gating vs. stopping.** The cleanest way to handle a third-party script is to
289
+ > **gate** it — never load it until its category is granted — with the
290
+ > `integrations` option and a preset from
291
+ > [`@cookieyes/scripts`](https://github.com/cookieyes/cookieyes/tree/main/sdk/scripts).
292
+ > The layers below are for scripts that are *already loaded* (first-party
293
+ > vendors, your own tags) and need to be stopped when consent is withdrawn.
294
+
295
+ There are three layers:
263
296
 
264
297
  1. **Network blocking** (`networkBlocker` / `blockNetwork`) — intercepts
265
298
  `fetch`, `XMLHttpRequest`, **and `navigator.sendBeacon`** to blocked domains,
266
299
  in real time, for as long as the page is open. `sendBeacon` matters because
267
300
  GA4/Meta use it for exit/unload tracking that fetch/XHR interception misses.
268
- 2. **Integration stop-handlers** (`integrations`) — call a vendor's own
301
+ 2. **Built-in stop-handlers** (`builtInIntegrations`) — call a vendor's own
269
302
  documented "stop" API on revoke, and resume it on re-accept:
270
303
 
271
304
  ```ts
272
305
  getOrCreateConsentRuntime({
273
306
  mode: "cookie-only",
274
- integrations: [
307
+ builtInIntegrations: [
275
308
  { vendor: "meta" }, // fbq('consent','revoke'|'grant')
276
309
  ],
277
310
  });
278
311
  ```
279
312
 
313
+ > `builtInIntegrations` was previously called `integrations`; that name now
314
+ > refers to the gated presets from `@cookieyes/scripts` (see the note above).
315
+
280
316
  > **Google Analytics & Tag Manager are handled automatically** — you don't
281
317
  > list them here. The SDK broadcasts Google Consent Mode v2 whenever a
282
318
  > `dataLayer` is present (see [Google Consent Mode](#google-consent-mode-v2)
@@ -297,7 +333,7 @@ is lost. There are three layers:
297
333
 
298
334
  | Vendor | Runtime stop | How |
299
335
  |--------|-------------|-----|
300
- | **Google Analytics 4 / Tag Manager** | ✅ automatic | Consent Mode v2 broadcast — no `integrations` entry needed (see [below](#google-consent-mode-v2)). |
336
+ | **Google Analytics 4 / Tag Manager** | ✅ automatic | Consent Mode v2 broadcast — no `builtInIntegrations` entry needed (see [below](#google-consent-mode-v2)). |
301
337
  | **Meta Pixel** | ✅ clean | `fbq('consent', 'revoke')` / `'grant'` |
302
338
  | TikTok Pixel | ⚠️ reload | No runtime stop we could confidently verify; modelled as reload-only. |
303
339
  | LinkedIn Insight Tag | ⚠️ reload | No documented runtime opt-out after load. |
@@ -308,6 +344,11 @@ is lost. There are three layers:
308
344
  never continues tracking them silently. Any of them can be upgraded to a clean
309
345
  stop later (in `resolveBuiltInIntegration`) once a real runtime API is confirmed.
310
346
 
347
+ > Better still, **gate** the vendor instead of stopping it after the fact:
348
+ > [`@cookieyes/scripts`](https://github.com/cookieyes/cookieyes/tree/main/sdk/scripts)
349
+ > ships a Segment preset (`segment()`) that never loads until consent and is
350
+ > removed on revoke — so there's nothing to reload.
351
+
311
352
  ### Reload notice
312
353
 
313
354
  If a revoked tool has no clean runtime stop, the manager computes
@@ -398,7 +439,7 @@ visitor actually agreed to.
398
439
  If a Google `dataLayer` is present on the page, the SDK **broadcasts** all seven
399
440
  Consent Mode v2 signals — on load and on every consent change — for every
400
441
  visitor. This is what governs Google Analytics 4 and Tag Manager; you do **not**
401
- register them under `integrations`.
442
+ register them under `builtInIntegrations`.
402
443
 
403
444
  Each signal is `granted` when any granted category maps to it (via its `gcm`
404
445
  field), otherwise `denied`. `security_storage` is always `granted`. The built-in
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(),s=n.slice(e+1).trim();t.has(r)?o[r]=s:r.length>0&&(o.categories[r]=s)}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){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 i(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 c=[{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 d(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 l(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:d(r),isDefault:t}}function u(e){if(!e||0===e.length)return l(c,!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).`),l(c,!0)):l(e,!1)}function g(e){"undefined"!=typeof console&&console.warn(e)}function f(e){const t={mode:e.mode},o=e.overrides?.regulation;return void 0!==e.regulation?(t.regulation=e.regulation,void 0!==o&&g("[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.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.integrations&&(t.integrations=e.integrations),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&&g("[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 p=!1;function h(){p||(p=!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" }).'))}function y(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,s){const a=s?.category?{listener:r,category:s.category}:{listener:r};return t[o].add(a),n(a,o,{categories:{...e()},changedCategories:[],isInitial:!0}),()=>{t[o].delete(a)}},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})}}}const m=["ad_storage","ad_user_data","ad_personalization","analytics_storage","functionality_storage","personalization_storage","security_storage"];function w(e,t){const o={};for(const e of m)o[e]="denied";o.security_storage="granted";for(const n of e.list)if(n.gcm&&0!==n.gcm.length&&t[n.id])for(const e of n.gcm)o[e]="granted";return o}function v(e,t){if("undefined"==typeof window||!Array.isArray(window.dataLayer))return;const o=w(e,t),n=window.dataLayer;if(!n)return;!function(){n.push(arguments)}("consent","update",o)}const k={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"}},b=new Set(["ar","he","fa","ur","ps","sd","yi","dv"]);function C(e){return e.split("-")[0]?.toLowerCase()??""}function S(e){return b.has(C(e))?"rtl":"ltr"}function R(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],s="object"==typeof r&&!Array.isArray(r)&&"object"==typeof t&&null!=t;o[n]=s?R(t,r):r}return o}function x(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=C(e);if(o&&t[o])return o}return"en"}function A(e,t){const o={...e?.messages},n=e?.loadLanguage,r=new Set;let s=x(e),a=l(s),i=u();function c(e){return o[e]??o[C(e)]}function d(e){return"en"===C(e)||void 0!==c(e)}function l(e){return R(k,c(e))}function u(){return{language:s,direction:S(s),languages:Array.from(new Set(["en",...Object.keys(o)]))}}function g(e){s=e,a=l(e),i=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 "${s}". 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:()=>a,getLanguageInfo:()=>i,setLanguage:p,getCategoryText:function(e){return c(s)?.categories?.[e]}}}const U=new Map,I=new Map;function L(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),I.set(e,o)}function B(e){return"needsReload"in e&&!0===e.needsReload}function H(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 O=new Map,P=new Set,T=new Set;function _(e){O.set(e.id,e)}function q(e){const t=[];for(const o of O.values()){const n=!0!==e[o.category];if(B(o))n?T.has(o.id)&&(t.push(o.id),T.delete(o.id)):T.add(o.id);else if(n){if(!P.has(o.id))try{o.stop(),P.add(o.id)}catch{t.push(o.id)}}else if(P.has(o.id)){P.delete(o.id);try{o.resume?.()}catch{}}}return{reloadRequiredBy:t}}function M(e){return{consentId:e.consentId,categories:e.categories,regulation:e.regulation,domain:"undefined"!=typeof window?window.location.hostname:"unknown"}}function $(t){const n=new Set,c=u(t.categories);let d,l,g,f=!1;function p(e){const t={};for(const o of c.ids)t[o]=!!c.requiredIds.has(o)||e(o);return t}let h=[],y=!1;for(const e of t.integrations??[])_(H(e));for(const e of t.customStopHandlers??[])_(e);const m=function(){if("undefined"==typeof document)return null;const t=document.cookie.split(";");for(const n of t){const t=n.trim(),r=t.indexOf("=");if(-1!==r&&t.slice(0,r).trim()===e){const e=t.slice(r+1).trim();return o(decodeURIComponent(e))}}return null}(),w=t.regulation??"DEFAULT",k=m?.tax,b=k===c.taxonomyHash,C=null!=m&&(b||void 0===k&&c.isDefault);if(null!=m&&C)d=function(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}}(m,w,c);else{const e=m?.consentid??a();d=i(e,w,c),null!=m&&s(),"CCPA"===d.regulation&&r(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 t of n)t(e)}function R(){!function(e){if("undefined"!=typeof document)for(const[t,o]of U)!0===e[o.category]&&(I.has(t)||L(t,o))}(g)}function x(){if(d={...d,hasActed:!0,lastRenewed:Date.now()},r(d),t.backend)try{Promise.resolve(t.backend.persist(M(d))).catch(()=>{})}catch{}else t.apiUrl&&async function(e,t,o){const n=M(o),r={"Content-Type":"application/json"};t&&(r.Authorization=`Bearer ${t}`);try{await fetch(e,{method:"POST",headers:r,body:JSON.stringify(n),keepalive:!0})}catch{}}(t.apiUrl,t.apiKey,d);let e=!1;for(const t of c.ids)if(l[t]&&!d.categories[t]){e=!0;break}l={...d.categories},g={...d.categories},R();const{reloadRequiredBy:o}=q(g);var n;((n=o).length!==h.length||n.some((e,t)=>e!==h[t]))&&(h=n,y=!1),v(c,g),S(),t.onConsentUpdate?.(d),e&&t.reloadOnRevoke&&"undefined"!=typeof window&&window.location.reload()}d={...d,taxonomyHash:c.taxonomyHash},l={...d.categories},g={...d.categories},Promise.resolve().then(()=>t.onConsentReady?.(d));const A={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 f},acceptAll(){d={...d,categories:p(()=>!0)},f=!1,x()},rejectAll(){d={...d,categories:p(()=>!1)},f=!1,x()},acceptSelected(e){d={...d,categories:p(t=>e.includes(t))},f=!1,x()},updateCategory(e,t){c.requiredIds.has(e)||c.ids.includes(e)&&(d={...d,categories:{...d.categories,[e]:t}},S())},savePreferences(){f=!1,x()},resetConsent(){s();const e=a();d=i(e,d.regulation,c),g={...d.categories},l={...d.categories},f=!1,q(g),v(c,g),h=[],y=!1,S()},showPreferences(){f=!0,S()},hidePreferences(){f=!1,S()},subscribe:e=>(n.add(e),()=>n.delete(e)),registerScript(e){!function(e){U.set(e.id,e)}(e),R()},get reloadNotice(){return{required:h.length>0&&!y,reasons:[...h]}},dismissReloadNotice(){y||(y=!0,S())}};return R(),function(e){for(const t of O.values()){const o=!0!==e[t.category];if(B(t))o?T.delete(t.id):T.add(t.id);else try{o?(t.stop(),P.add(t.id)):(P.delete(t.id),t.resume?.())}catch{}}}(d.categories),v(c,d.categories),A}function j(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 s=r.hostname.toLowerCase(),a=r.pathname+r.search,i=o.toUpperCase();for(const t of e){const e=t.domain.toLowerCase();if((s===e||s.endsWith("."+e))&&((!t.pathIncludes||a.includes(t.pathIncludes))&&(!t.methods||t.methods.map(e=>e.toUpperCase()).includes(i))&&!n(t.category)))return t}return null}let D=null;function N(e,t){if("undefined"==typeof window)return()=>{};if(D)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};D=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,s){let a="",i=s?.method??"GET";"string"==typeof n?a=n:n instanceof URL?a=n.toString():(a=n.url,i=s?.method??n.method);const c=j(e.rules,a,i,t);return c?(r({rule:c,url:a,method:i}),Promise.reject(new TypeError(`Blocked by consent (rule: ${c.id}, category: ${c.category})`))):o.originalFetch.call(window,n,s)},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 s=this._cyUrl??"",a=this._cyMethod??"GET",i=j(e.rules,s,a,t);return i?(r({rule:i,url:s,method:a}),void this.abort()):o.originalXhrSend.call(this,n)},o.originalSendBeacon){const n=o.originalSendBeacon;navigator.sendBeacon=function(o,s){const a=j(e.rules,o.toString(),"POST",t);return a?(r({rule:a,url:o.toString(),method:"POST"}),!0):n.call(navigator,o,s)}}return X}function X(){D&&("undefined"!=typeof window&&(window.fetch=D.originalFetch,XMLHttpRequest.prototype.open=D.originalXhrOpen,XMLHttpRequest.prototype.send=D.originalXhrSend,D.originalSendBeacon&&(navigator.sendBeacon=D.originalSendBeacon)),D=null)}let E=null;function z(e){if(E)return E;"offline"===e.mode&&h();const t=f(e),o=new Set,n=t.onConsentUpdate;let r;const s={};"self-hosted"===t.mode&&(t.backend?s.backend=t.backend:t.apiUrl&&(s.apiUrl=t.apiUrl)),t.apiKey&&(s.apiKey=t.apiKey),t.regulation&&(s.regulation=t.regulation),t.colorScheme&&(s.colorScheme=t.colorScheme),t.theme&&(s.theme=t.theme),t.reloadOnRevoke&&(s.reloadOnRevoke=t.reloadOnRevoke),t.integrations&&(s.integrations=t.integrations),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 a=$(s);r=y(()=>a.committedCategories);const i=u(t.categories),c=new Set;function d(){const e=g();for(const t of c)t(e)}a.subscribe(d);const l=A(t.i18n,d);function g(){const e=a.categories;return{consentId:a.consentId,hasActed:a.hasActed,categories:e,consents:e,committedConsents:a.committedCategories,regulation:a.regulation,lastRenewed:a.lastRenewed,taxonomyHash:a.taxonomyHash,activeUI:a.isPreferencesOpen?"dialog":a.hasActed?null:"banner",has:e=>!0===a.committedCategories[e],saveConsents:async e=>{"all"===e?a.acceptAll():"necessary"===e?a.rejectAll():a.acceptSelected(e)},setConsent:(e,t)=>a.updateCategory(e,t),subscribeToConsentChanges:e=>(o.add(e),()=>{o.delete(e)})}}const p={subscribe:e=>(c.add(e),()=>{c.delete(e)}),getState:g,on:(e,t,o)=>r.on(e,t,o),get translations(){return l.getTranslations()},getLanguageInfo:l.getLanguageInfo,setLanguage:l.setLanguage,getCategoryText:l.getCategoryText,categories:i};return t.networkBlocker&&t.networkBlocker.rules.length>0&&N(t.networkBlocker,e=>!0===a.committedCategories[e]),E={consentManager:a,consentStore:p},E}exports.DEFAULT_CATEGORIES=c,exports._clearStopHandlers=function(){O.clear(),P.clear(),T.clear()},exports._normalizeConfig=f,exports._resetOfflineModeWarning=function(){p=!1},exports._warnOfflineModeDeprecated=h,exports.broadcastGoogleConsent=v,exports.computeGoogleConsent=w,exports.createConsentEmitter=y,exports.createConsentManager=$,exports.createLanguageController=A,exports.defaultTranslations=k,exports.generateConsentId=a,exports.getOrCreateConsentRuntime=z,exports.getTextDirection=S,exports.initCookieYes=function(e){return z(e)},exports.installNetworkBlocker=N,exports.mergeTranslations=R,exports.parseCookie=o,exports.pickLanguage=x,exports.primaryOf=C,exports.registerStopHandler=_,exports.resetConsentRuntime=function(){E=null},exports.resolveBuiltInIntegration=H,exports.resolveCategories=u,exports.resolveTranslations=function(e){const t=e?.messages??{},o=x(e);return R(k,t[o]??t[C(o)])},exports.serializeCookie=n,exports.uninstallNetworkBlocker=X;
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;
2
2
  //# sourceMappingURL=index.cjs.map