@cookieyes/core 0.2.0 → 0.3.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 +53 -3
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +134 -24
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -192,16 +192,66 @@ methods (`acceptAll()`, `rejectAll()`, `acceptSelected(cats)`, `updateCategory(c
|
|
|
192
192
|
> `overrides.regulation` alias still works) and defaults to `"DEFAULT"`. The core engine does not
|
|
193
193
|
> perform IP-based geo-detection.
|
|
194
194
|
|
|
195
|
+
## Reacting to consent changes
|
|
196
|
+
|
|
197
|
+
To run your own code when a visitor grants or withdraws consent, use
|
|
198
|
+
`consentStore.on(type, listener, options?)`:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
const { consentStore } = initCookieYes({ mode: "cookie-only" });
|
|
202
|
+
|
|
203
|
+
// "change" fires only when a category actually differs — the right place to
|
|
204
|
+
// (re)load a script, so a re-confirm of the same choices doesn't run it again.
|
|
205
|
+
const off = consentStore.on("change", ({ changedCategories }) => {
|
|
206
|
+
if (changedCategories.includes("analytics")) loadAnalytics();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// "save" fires on every save, even an unchanged re-confirm.
|
|
210
|
+
consentStore.on("save", () => toast("Preferences saved"));
|
|
211
|
+
|
|
212
|
+
off(); // stop listening when you're done
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
- The listener fires **once immediately** with the current state
|
|
216
|
+
(`isInitial: true`), so a late listener isn't blind to earlier choices.
|
|
217
|
+
- Pass `{ category: "analytics" }` to only hear about one category.
|
|
218
|
+
- Payload: `{ categories, changedCategories, isInitial }`.
|
|
219
|
+
|
|
220
|
+
This is the recommended way to react to consent. The paths below still work but
|
|
221
|
+
aren't the primary one.
|
|
222
|
+
|
|
223
|
+
## Translations & language
|
|
224
|
+
|
|
225
|
+
For a framework-less custom UI, `consentStore` carries the active language and
|
|
226
|
+
lets you switch it live (no reload):
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
const { consentStore } = initCookieYes({
|
|
230
|
+
mode: "cookie-only",
|
|
231
|
+
i18n: { messages: { fr } }, // languages you support; each may be partial
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
consentStore.translations.acceptAll; // text for the active language
|
|
235
|
+
consentStore.getLanguageInfo(); // { language, direction, languages }
|
|
236
|
+
|
|
237
|
+
consentStore.subscribe(() => render()); // re-render on consent OR language change
|
|
238
|
+
await consentStore.setLanguage("fr"); // switch live; loads via i18n.loadLanguage if needed
|
|
239
|
+
```
|
|
240
|
+
|
|
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.md)).
|
|
243
|
+
In React, use the `useTranslations()` / `useLanguage()` hooks instead.
|
|
244
|
+
|
|
195
245
|
## Low-level / advanced API
|
|
196
246
|
|
|
197
247
|
You shouldn't need these for a typical integration — each exists for a
|
|
198
|
-
specific narrower situation than `consentStore.subscribe`:
|
|
248
|
+
specific narrower situation than `consentStore.on` / `consentStore.subscribe`:
|
|
199
249
|
|
|
200
250
|
| API | Use when |
|
|
201
251
|
|---|---|
|
|
202
|
-
| `subscribeToConsentChanges(listener)` (on `consentStore.getState()`) |
|
|
252
|
+
| `subscribeToConsentChanges(listener)` (on `consentStore.getState()`) | Predates `consentStore.on`; fires on saved changes but without the `change`/`save` split, the `isInitial` flag, or per-category filtering. Prefer `on`. |
|
|
203
253
|
| `onConsentReady` (config option) | You need a one-time callback right after the initial state is known — e.g. conditionally loading analytics on first load — rather than an ongoing subscription. |
|
|
204
|
-
| `onConsentUpdate` (config option) |
|
|
254
|
+
| `onConsentUpdate` (config option) | A saved-changes callback registered once at config time instead of dynamically after mount. Prefer `consentStore.on` unless you specifically need a config-time callback. |
|
|
205
255
|
| `createConsentManager(config)` | Bypasses `consentStore` entirely for direct access to the manager: `acceptAll()`, `rejectAll()`, `acceptSelected(cats)`, `updateCategory(cat, val)`, `savePreferences()`, `resetConsent()`, `showPreferences()`, `hidePreferences()`, `subscribe(fn)`, `registerScript(entry)`. `config` (`ConsentConfig`) accepts `regulation`, `colorScheme`, `theme`, `apiUrl`, `apiKey`, `backend`, `reloadOnRevoke`, `onConsentReady`, `onConsentUpdate`. |
|
|
206
256
|
| `parseCookie` / `serializeCookie` | Reading or writing the raw `cookieyes-consent` cookie directly — e.g. in a Next.js Server Component or route handler, where no live runtime or React hooks are available. |
|
|
207
257
|
|
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 f(e){"undefined"!=typeof console&&console.warn(e)}function g(e){const t={mode:e.mode},o=e.overrides?.regulation;return void 0!==e.regulation?(t.regulation=e.regulation,void 0!==o&&f("[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&&f("[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" }).'))}const y=["ad_storage","ad_user_data","ad_personalization","analytics_storage","functionality_storage","personalization_storage","security_storage"];function m(e,t){const o={};for(const e of y)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 w(e,t){if("undefined"==typeof window||!Array.isArray(window.dataLayer))return;const o=m(e,t),n=window.dataLayer;if(!n)return;!function(){n.push(arguments)}("consent","update",o)}const v={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"}};const k=new Map,b=new Map;function C(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),b.set(e,o)}function R(e){return"needsReload"in e&&!0===e.needsReload}function S(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 x=new Map,U=new Set,A=new Set;function B(e){x.set(e.id,e)}function I(e){const t=[];for(const o of x.values()){const n=!0!==e[o.category];if(R(o))n?A.has(o.id)&&(t.push(o.id),A.delete(o.id)):A.add(o.id);else if(n){if(!U.has(o.id))try{o.stop(),U.add(o.id)}catch{t.push(o.id)}}else if(U.has(o.id)){U.delete(o.id);try{o.resume?.()}catch{}}}return{reloadRequiredBy:t}}function H(e){return{consentId:e.consentId,categories:e.categories,regulation:e.regulation,domain:"undefined"!=typeof window?window.location.hostname:"unknown"}}function O(t){const n=new Set,c=u(t.categories);let d,l,f,g=!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??[])B(S(e));for(const e of t.customStopHandlers??[])B(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}(),v=t.regulation??"DEFAULT",O=m?.tax,P=O===c.taxonomyHash,L=null!=m&&(P||void 0===O&&c.isDefault);if(null!=m&&L)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,v,c);else{const e=m?.consentid??a();d=i(e,v,c),null!=m&&s(),"CCPA"===d.regulation&&r(d)}function _(){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 q(){!function(e){if("undefined"!=typeof document)for(const[t,o]of k)!0===e[o.category]&&(b.has(t)||C(t,o))}(f)}function M(){if(d={...d,hasActed:!0,lastRenewed:Date.now()},r(d),t.backend)try{Promise.resolve(t.backend.persist(H(d))).catch(()=>{})}catch{}else t.apiUrl&&async function(e,t,o){const n=H(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},f={...d.categories},q();const{reloadRequiredBy:o}=I(f);var n;((n=o).length!==h.length||n.some((e,t)=>e!==h[t]))&&(h=n,y=!1),w(c,f),_(),t.onConsentUpdate?.(d),e&&t.reloadOnRevoke&&"undefined"!=typeof window&&window.location.reload()}d={...d,taxonomyHash:c.taxonomyHash},l={...d.categories},f={...d.categories},Promise.resolve().then(()=>t.onConsentReady?.(d));const $={get consentId(){return d.consentId},get hasActed(){return d.hasActed},get categories(){return{...d.categories}},get committedCategories(){return{...f}},get regulation(){return d.regulation},get lastRenewed(){return d.lastRenewed},get taxonomyHash(){return d.taxonomyHash},get isPreferencesOpen(){return g},acceptAll(){d={...d,categories:p(()=>!0)},g=!1,M()},rejectAll(){d={...d,categories:p(()=>!1)},g=!1,M()},acceptSelected(e){d={...d,categories:p(t=>e.includes(t))},g=!1,M()},updateCategory(e,t){c.requiredIds.has(e)||c.ids.includes(e)&&(d={...d,categories:{...d.categories,[e]:t}},_())},savePreferences(){g=!1,M()},resetConsent(){s();const e=a();d=i(e,d.regulation,c),f={...d.categories},l={...d.categories},g=!1,I(f),w(c,f),h=[],y=!1,_()},showPreferences(){g=!0,_()},hidePreferences(){g=!1,_()},subscribe:e=>(n.add(e),()=>n.delete(e)),registerScript(e){!function(e){k.set(e.id,e)}(e),q()},get reloadNotice(){return{required:h.length>0&&!y,reasons:[...h]}},dismissReloadNotice(){y||(y=!0,_())}};return q(),function(e){for(const t of x.values()){const o=!0!==e[t.category];if(R(t))o?A.delete(t.id):A.add(t.id);else try{o?(t.stop(),U.add(t.id)):(U.delete(t.id),t.resume?.())}catch{}}}(d.categories),w(c,d.categories),$}function P(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 L=null;function _(e,t){if("undefined"==typeof window)return()=>{};if(L)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};L=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=P(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=P(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=P(e.rules,o.toString(),"POST",t);return a?(r({rule:a,url:o.toString(),method:"POST"}),!0):n.call(navigator,o,s)}}return q}function q(){L&&("undefined"!=typeof window&&(window.fetch=L.originalFetch,XMLHttpRequest.prototype.open=L.originalXhrOpen,XMLHttpRequest.prototype.send=L.originalXhrSend,L.originalSendBeacon&&(navigator.sendBeacon=L.originalSendBeacon)),L=null)}let M=null;function $(e){if(M)return M;"offline"===e.mode&&h();const t=g(e),o=new Set,n=t.onConsentUpdate,r={};"self-hosted"===t.mode&&(t.backend?r.backend=t.backend:t.apiUrl&&(r.apiUrl=t.apiUrl)),t.apiKey&&(r.apiKey=t.apiKey),t.regulation&&(r.regulation=t.regulation),t.colorScheme&&(r.colorScheme=t.colorScheme),t.theme&&(r.theme=t.theme),t.reloadOnRevoke&&(r.reloadOnRevoke=t.reloadOnRevoke),t.integrations&&(r.integrations=t.integrations),t.customStopHandlers&&(r.customStopHandlers=t.customStopHandlers),t.categories&&(r.categories=t.categories),t.onConsentReady&&(r.onConsentReady=t.onConsentReady),r.onConsentUpdate=e=>{n?.(e);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 s=O(r);function a(){const e=s.categories;return{consentId:s.consentId,hasActed:s.hasActed,categories:e,consents:e,committedConsents:s.committedCategories,regulation:s.regulation,lastRenewed:s.lastRenewed,taxonomyHash:s.taxonomyHash,activeUI:s.isPreferencesOpen?"dialog":s.hasActed?null:"banner",has:e=>!0===s.committedCategories[e],saveConsents:async e=>{"all"===e?s.acceptAll():"necessary"===e?s.rejectAll():s.acceptSelected(e)},setConsent:(e,t)=>s.updateCategory(e,t),subscribeToConsentChanges:e=>(o.add(e),()=>{o.delete(e)})}}const i={subscribe:e=>s.subscribe(()=>e(a())),getState:a};return t.networkBlocker&&t.networkBlocker.rules.length>0&&_(t.networkBlocker,e=>!0===s.committedCategories[e]),M={consentManager:s,consentStore:i},M}exports.DEFAULT_CATEGORIES=c,exports._clearStopHandlers=function(){x.clear(),U.clear(),A.clear()},exports._normalizeConfig=g,exports._resetOfflineModeWarning=function(){p=!1},exports._warnOfflineModeDeprecated=h,exports.broadcastGoogleConsent=w,exports.computeGoogleConsent=m,exports.createConsentManager=O,exports.defaultTranslations=v,exports.generateConsentId=a,exports.getOrCreateConsentRuntime=$,exports.initCookieYes=function(e){return $(e)},exports.installNetworkBlocker=_,exports.parseCookie=o,exports.registerStopHandler=B,exports.resetConsentRuntime=function(){M=null},exports.resolveBuiltInIntegration=S,exports.resolveCategories=u,exports.resolveTranslations=function(e){const t=e?.messages??{},o=e?.detectBrowserLanguage??!0,n=[];e?.locale&&n.push(e.locale),o&&"undefined"!=typeof navigator&&navigator.language&&n.push(navigator.language);for(const e of n){const o=e.split("-")[0]?.toLowerCase()??"",n=t[e]??(o?t[o]:void 0);if(n)return n}return t.en??v},exports.serializeCookie=n,exports.uninstallNetworkBlocker=q;
|
|
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;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|