@cookieyes/core 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -7
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +37 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -239,6 +239,20 @@ type TranslationMap = {
|
|
|
239
239
|
poweredBy: string;
|
|
240
240
|
preferencesTitle: string;
|
|
241
241
|
preferencesIntro: string;
|
|
242
|
+
/** Shown in place of a toggle on a category marked `required: true`. */
|
|
243
|
+
alwaysActive: string;
|
|
244
|
+
/** Accessible name of the preferences dialog. */
|
|
245
|
+
preferencesDialogLabel: string;
|
|
246
|
+
/** Accessible name of the opt-out dialog. */
|
|
247
|
+
optOutDialogLabel: string;
|
|
248
|
+
/** Accessible name of the floating recall button. */
|
|
249
|
+
recallButtonLabel: string;
|
|
250
|
+
/** Accessible name of the banner's close button (rendered under CCPA only). */
|
|
251
|
+
bannerCloseLabel: string;
|
|
252
|
+
/** Accessible name of the preferences dialog's close button. */
|
|
253
|
+
preferencesCloseLabel: string;
|
|
254
|
+
/** Accessible name of the opt-out dialog's close button. */
|
|
255
|
+
optOutCloseLabel: string;
|
|
242
256
|
categories: {
|
|
243
257
|
necessary: CategoryText;
|
|
244
258
|
functional: CategoryText;
|
|
@@ -253,6 +267,12 @@ type TranslationMap = {
|
|
|
253
267
|
successText: string;
|
|
254
268
|
successCountdown: string;
|
|
255
269
|
};
|
|
270
|
+
gatedFrame: {
|
|
271
|
+
/** Placeholder shown in place of blocked embedded content. `{category}` is substituted. */
|
|
272
|
+
placeholder: string;
|
|
273
|
+
/** Label of the placeholder's button, which opens the preferences dialog. */
|
|
274
|
+
action: string;
|
|
275
|
+
};
|
|
256
276
|
reloadNotice: {
|
|
257
277
|
message: string;
|
|
258
278
|
reloadButton: string;
|
|
@@ -304,14 +324,25 @@ type ThemeConfig = {
|
|
|
304
324
|
borderColor?: string | undefined;
|
|
305
325
|
borderRadius?: string | undefined;
|
|
306
326
|
fontFamily?: string | undefined;
|
|
307
|
-
|
|
308
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Focus-ring color for interactive elements. Falls back to
|
|
329
|
+
* `var(--cy-primary)` — the ring matches your brand color exactly like it
|
|
330
|
+
* did before this field existed.
|
|
331
|
+
*/
|
|
332
|
+
focusColor?: string | undefined;
|
|
333
|
+
/**
|
|
334
|
+
* Background color of the floating recall widget (the small circular
|
|
335
|
+
* re-open button). Falls back to `"#0056a7"` in light mode. In dark mode,
|
|
336
|
+
* this value is still respected if you set it; only when you don't set it
|
|
337
|
+
* does a dark-mode default apply, the same way
|
|
338
|
+
* backgroundColor/textColor/mutedTextColor/borderColor already work.
|
|
339
|
+
*/
|
|
340
|
+
widgetBackgroundColor?: string | undefined;
|
|
309
341
|
};
|
|
310
342
|
type ScriptEntry = {
|
|
311
343
|
id: string;
|
|
312
344
|
src: string;
|
|
313
345
|
category: ConsentCategory;
|
|
314
|
-
strategy?: "afterConsent" | "lazyOnce" | undefined;
|
|
315
346
|
onLoad?: (() => void) | undefined;
|
|
316
347
|
};
|
|
317
348
|
type I18nConfig = {
|
|
@@ -447,7 +478,7 @@ interface ConsentBackend {
|
|
|
447
478
|
}
|
|
448
479
|
/**
|
|
449
480
|
* @deprecated Use `"cookie-only"` instead — identical behavior, clearer name.
|
|
450
|
-
* `"offline"` still works but will be removed
|
|
481
|
+
* `"offline"` still works but will be removed after three release cycles.
|
|
451
482
|
*/
|
|
452
483
|
type DeprecatedOfflineMode = "offline";
|
|
453
484
|
type ConsentRuntimeMode = "self-hosted" | "cookie-only" | DeprecatedOfflineMode;
|
|
@@ -474,7 +505,6 @@ type CookieYesConfigCommon = {
|
|
|
474
505
|
colorScheme?: ColorScheme | undefined;
|
|
475
506
|
theme?: ThemeConfig | undefined;
|
|
476
507
|
i18n?: I18nConfig | undefined;
|
|
477
|
-
consentCategories?: ConsentCategory[] | undefined;
|
|
478
508
|
/**
|
|
479
509
|
* Define your own category taxonomy. Omit to get the built-in five
|
|
480
510
|
* (necessary, functional, analytics, performance, advertisement) unchanged.
|
|
@@ -504,8 +534,8 @@ type CookieYesConfigCommon = {
|
|
|
504
534
|
* @deprecated Renamed from `integrations`. Built-in stop-handlers for a few
|
|
505
535
|
* first-party vendors — e.g. `{ vendor: "meta" }` — stopped cleanly (no
|
|
506
536
|
* reload) when their category is revoked. Prefer the new `integrations` field
|
|
507
|
-
* with a preset from `@cookieyes/scripts`; this will be removed
|
|
508
|
-
* release.
|
|
537
|
+
* with a preset from `@cookieyes/scripts`; this will be removed after three
|
|
538
|
+
* release cycles.
|
|
509
539
|
*/
|
|
510
540
|
builtInIntegrations?: BuiltInIntegration[] | undefined;
|
|
511
541
|
/**
|
|
@@ -721,7 +751,6 @@ type _NormalizedConfig = {
|
|
|
721
751
|
colorScheme?: ColorScheme | undefined;
|
|
722
752
|
theme?: ThemeConfig | undefined;
|
|
723
753
|
i18n?: I18nConfig | undefined;
|
|
724
|
-
consentCategories?: ConsentCategory[] | undefined;
|
|
725
754
|
categories?: CategoryDef[] | undefined;
|
|
726
755
|
networkBlocker?: NetworkBlockerConfig | undefined;
|
|
727
756
|
reloadOnRevoke?: boolean | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e="cookieyes-consent",t=new Set(["consentid","consent","action","tax","lastRenewedDate"]);function n(e){const n={categories:{}};for(const o of e.split(",")){const e=o.indexOf(":");if(-1===e)continue;const i=o.slice(0,e).trim(),r=o.slice(e+1).trim();t.has(i)?n[i]=r:i.length>0&&(n.categories[i]=r)}return n}function o(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[n,o]of Object.entries(e.categories))t.push(`${n}:${o?"yes":"no"}`);return t.push(`lastRenewedDate:${e.lastRenewed??Date.now()}`),t.join(",")}function i(t){for(const o of t.split(";")){const t=o.trim(),i=t.indexOf("=");if(-1===i)continue;if(t.slice(0,i).trim()!==e)continue;const r=t.slice(i+1).trim();try{return n(decodeURIComponent(r))}catch{return null}}return null}function r(t){if("undefined"==typeof document)return;const n=encodeURIComponent(o(t));document.cookie=`${e}=${n}; max-age=31536000; path=/; SameSite=Lax`}function a(){"undefined"!=typeof document&&(document.cookie=`${e}=; max-age=0; path=/`)}function s(){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,n){const o={};for(const t of n.ids)o[t]=!!n.requiredIds.has(t)||"yes"===e.categories[t];return{consentId:e.consentid??s(),hasActed:"yes"===e.action,categories:o,regulation:t,lastRenewed:e.lastRenewedDate?Number(e.lastRenewedDate):void 0,taxonomyHash:e.tax}}function d(e,t,n){const o="CCPA"===t,i={};for(const e of n.ids)i[e]=!!n.requiredIds.has(e)||o;return{consentId:e,hasActed:!1,categories:i,regulation:t,taxonomyHash:n.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 n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function g(e,t){const n=e.map(e=>e.id),o=new Set(e.filter(e=>e.required).map(e=>e.id)),i=e.map(e=>`${e.id}:${e.required?1:0}:${(e.gcm??[]).join("+")}`).join("|");return{list:e,ids:n,requiredIds:o,taxonomyHash:u(i),isDefault:t}}function f(e){if(!e||0===e.length)return g(l,!0);const n=function(e){const n=e.map(e=>e.id);return n.some(e=>"string"!=typeof e||0===e.length)?"every category needs a non-empty string id":n.some(e=>e.includes(",")||e.includes(":"))?"category ids must not contain ',' or ':'":new Set(n).size!==n.length?"category ids must be unique":n.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 n?("undefined"!=typeof console&&console.warn(`[cookieyes] Invalid categories config (${n}). Falling back to the default five (necessary, functional, analytics, performance, advertisement).`),g(l,!0)):g(e,!1)}function h(e){"undefined"!=typeof console&&console.warn(e)}function y(e){const t={mode:e.mode},n=e.overrides?.regulation;return void 0!==e.regulation?(t.regulation=e.regulation,void 0!==n&&h("[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!==n&&(t.regulation=n),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&&h("[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 m(){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 v(){p=!1}let w=!1;function b(){w||(w=!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(){w=!1}function C(e){const t={save:new Set,change:new Set};let n={...e()};function o(e,t,n){try{e.listener(n)}catch(e){"undefined"!=typeof console&&console.error(`[cookieyes] a consent "${t}" listener threw; others are unaffected:`,e)}}function i(e,n){for(const i of[...t[e]])i.category&&!n.changedCategories.includes(i.category)||o(i,e,n)}return{on(n,i,r){const a=r?.category?{listener:i,category:r.category}:{listener:i};return t[n].add(a),o(a,n,{categories:{...e()},changedCategories:[],isInitial:!0}),()=>{t[n].delete(a)}},push(e){const t={...e},o=[];for(const e of Object.keys(t))n[e]!==t[e]&&o.push(e);n=t,i("save",{categories:t,changedCategories:o,isInitial:!1}),o.length>0&&i("change",{categories:t,changedCategories:o,isInitial:!1})}}}function R(e){"undefined"!=typeof console&&console.warn(`[cookieyes] ${e}`)}const S=["ad_storage","ad_user_data","ad_personalization","analytics_storage","functionality_storage","personalization_storage","security_storage"];function I(e,t,n="any"){const o={};for(const i of S){if("security_storage"===i){o[i]="granted";continue}const r=e.list.filter(e=>e.gcm?.includes(i));if(0===r.length){o[i]="denied";continue}const a="all"===n?r.every(e=>!0===t[e.id]):r.some(e=>!0===t[e.id]);o[i]=a?"granted":"denied"}return o}function A(e,t,n="any"){if("undefined"==typeof window||!Array.isArray(window.dataLayer))return;const o=I(e,t,n),i=window.dataLayer;if(!i)return;!function(){i.push(arguments)}("consent","update",o)}const x={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"}},$=new Set(["ar","he","fa","ur","ps","sd","yi","dv"]);function U(e){return e.split("-")[0]?.toLowerCase()??""}function L(e){return $.has(U(e))?"rtl":"ltr"}function P(e,t){if(!t)return e;const n={...e};for(const[o,i]of Object.entries(t)){if(null==i)continue;const t=e[o],r="object"==typeof i&&!Array.isArray(i)&&"object"==typeof t&&null!=t;n[o]=r?P(t,i):i}return n}function O(e){const t=e?.messages??{},n=[];e?.locale&&n.push(e.locale),(e?.detectBrowserLanguage??1)&&"undefined"!=typeof navigator&&navigator.language&&n.push(navigator.language);for(const e of n){if(t[e])return e;const n=U(e);if(n&&t[n])return n}return"en"}function H(e){const t=e?.messages??{},n=O(e);return P(x,t[n]??t[U(n)])}const M=1;function B(e,t){const n=new Set(e);for(const e of t)n.has(e)&&T(`"${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 q(e,t){const n=new Set(t);for(const t of e){if("afterConsent"!==t.load)continue;const e=t.category,o=Array.isArray(e)?e:[e];if(0!==o.length)for(const e of o)n.has(e)||T(`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 T(`integration "${t.id}" has an empty category list — it will never load. Give it at least one category that exists in your taxonomy.`)}}function T(e,t){"undefined"!=typeof console&&(void 0!==t?console.error(`[cookieyes] ${e}`,t):console.warn(`[cookieyes] ${e}`))}function j(e,t){const n=Array.isArray(e.category)?e.category:[e.category];return 0!==n.length&&("any"===e.match?n.some(e=>t.granted(e)):n.every(e=>t.granted(e)))}function D(e,t){const n=[],o=new Set;let i=!1;for(const t of e){const e=t;"string"!=typeof e.vendor||"function"==typeof e.setup?1===t.version?o.has(t.id)?T(`integration "${t.id}" is registered more than once; skipping the duplicate.`):(o.add(t.id),n.push({integration:t,status:"idle",everLoaded:!1,loading:!1,control:void 0,subs:new Set,wasGranted:!1})):T(`integration "${t.id}" uses format version ${t.version}, but this build understands 1. Skipping it.`):T(`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 r(e){for(const t of e.subs)try{t()}catch{}e.subs.clear()}function a(e){r(e),"active"===e.status&&(!function(e){const{integration:t,control:n}=e;try{"remove"===t.onRevoke?n?.():"silence"===t.onRevoke&&n?.silence()}catch(e){T(`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 s(e){e.loading=!0,e.status="loading",Promise.resolve().then(()=>e.integration.setup(function(e){return{granted:()=>j(e.integration,t),onConsentChange:n=>{const o=t.subscribe(n);return e.subs.add(o),()=>{e.subs.delete(o)&&o()}},region:t.region}}(e))).then(t=>{e.loading=!1,e.control=t??void 0,e.everLoaded=!0,e.status="active",i?a(e):c(e)}).catch(t=>{e.loading=!1,e.status="error",r(e),T(`integration "${e.integration.id}" failed to load; will retry on the next change.`,t)})}function c(e){const{integration:n}=e,o=j(n,t);if(o&&(e.wasGranted=!0),i||e.loading)return;if("idle"===e.status||"removed"===e.status||"error"===e.status){return void((e.everLoaded?o:"immediately"===n.load||o)&&s(e))}if("keep"===n.onRevoke)return;if("remove"===n.onRevoke){if(!o&&"active"===e.status&&e.wasGranted){r(e);try{e.control?.()}catch(e){T(`integration "${n.id}" cleanup threw on revoke.`,e)}e.control=void 0,e.status="removed"}return}const a=e.control;if(o||"active"!==e.status){if(o&&"silenced"===e.status){try{a?.resume()}catch(e){T(`integration "${n.id}" resume() threw.`,e)}e.status="active"}}else{try{a?.silence()}catch(e){T(`integration "${n.id}" silence() threw.`,e)}e.status="silenced"}}function d(){for(const e of n)c(e)}const l=t.subscribe(d);return d(),{status:()=>{const e={};for(const t of n)e[t.integration.id]=t.status;return e},list:()=>n.map(e=>({id:e.integration.id,category:e.integration.category,load:e.integration.load,onRevoke:e.integration.onRevoke,status:e.status})),stop:()=>{if(!i){i=!0,l();for(const e of n)a(e)}}}}function _(e,t){const n={...e?.messages},o=e?.loadLanguage,i=new Set;let r=O(e),a=l(r),s=u();function c(e){return n[e]??n[U(e)]}function d(e){return"en"===U(e)||void 0!==c(e)}function l(e){return P(x,c(e))}function u(){return{language:r,direction:L(r),languages:Array.from(new Set(["en",...Object.keys(n)]))}}function g(e){r=e,a=l(e),s=u(),t()}function f(e,t){i.has(e)||"undefined"==typeof console||(i.add(e),console.warn(`[cookieyes] no translations for language "${e}"; staying on "${r}". Add it to i18n.messages or provide i18n.loadLanguage.`,t??""))}function h(e){return d(e)?(g(e),Promise.resolve()):o?Promise.resolve().then(()=>o(e)).then(t=>{n[e]=t,g(e)}).catch(t=>f(e,t)):(f(e),Promise.resolve())}return o&&e?.locale&&!d(e.locale)&&"undefined"!=typeof window&&h(e.locale),{getTranslations:()=>a,getLanguageInfo:()=>s,setLanguage:h,getCategoryText:function(e){return c(r)?.categories?.[e]}}}const N=new Map,X=new Map;function E(){if("undefined"!=typeof document)for(const e of X.values())e.remove();N.clear(),X.clear()}function F(e,t){if(document.getElementById(e))return;const n=document.createElement("script");n.id=e,n.src=t.src,n.async=!0,t.onLoad&&n.addEventListener("load",t.onLoad,{once:!0}),document.head.appendChild(n),X.set(e,n)}function G(e){return"needsReload"in e&&!0===e.needsReload}function z(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 K=new Map,Y=new Set,W=new Set;function J(e){K.set(e.id,e)}function V(){K.clear(),Y.clear(),W.clear()}function Q(e){const t=[];for(const n of K.values()){const o=!0!==e[n.category];if(G(n))o?W.has(n.id)&&(t.push(n.id),W.delete(n.id)):W.add(n.id);else if(o){if(!Y.has(n.id))try{n.stop(),Y.add(n.id)}catch{t.push(n.id)}}else if(Y.has(n.id)){Y.delete(n.id);try{n.resume?.()}catch{}}}return{reloadRequiredBy:t}}function Z(e,t){const n={consentId:e.consentId,categories:e.categories,regulation:e.regulation,domain:"undefined"!=typeof window?window.location.hostname:"unknown"};return t&&(n.region=t),n}function ee(e){const t=new Set,n=f(e.categories),o=e.googleConsentMatch??"any";let l;void 0===e.googleConsentMatch&&function(e){const t=new Map;for(const n of e.list)for(const e of n.gcm??[]){let o=t.get(e);o||(o=new Set,t.set(e,o)),o.add(n.id)}for(const[e,n]of t)n.size<=1||R(`categories ${[...n].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.`)}(n);let u,g,h=!1;function y(e){const t={};for(const o of n.ids)t[o]=!!n.requiredIds.has(o)||e(o);return t}let p=[],m=!1;for(const t of e.integrations??[])J(z(t));for(const t of e.customStopHandlers??[])J(t);const v="undefined"==typeof document?null:i(document.cookie),w=e.regulation??"DEFAULT",b=v?.tax,k=b===n.taxonomyHash,C=null!=v&&(k||void 0===b&&n.isDefault);if(null!=v&&C)l=c(v,w,n);else{const e=v?.consentid??s();l=d(e,w,n),null!=v&&a(),"CCPA"===l.regulation&&r(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 n of t)n(e)}function I(){!function(e){if("undefined"!=typeof document)for(const[t,n]of N)!0===e[n.category]&&(X.has(t)||F(t,n))}(g)}function x(){l={...l,hasActed:!0,lastRenewed:Date.now()},r(l);let t=!1;for(const e of n.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(Z(l,e.region))).catch(()=>{})}catch{}else e.apiUrl&&async function(e,t,n,o){const i=Z(n,o),r={"Content-Type":"application/json"};t&&(r.Authorization=`Bearer ${t}`);try{await fetch(e,{method:"POST",headers:r,body:JSON.stringify(i),keepalive:!0})}catch{}}(e.apiUrl,e.apiKey,l,e.region);try{I()}catch{}let i=!1;try{const{reloadRequiredBy:e}=Q(g);i=function(e){const t=e.length!==p.length||e.some((e,t)=>e!==p[t]);return t&&(p=e,m=!1),t}(e)}catch{}try{A(n,g,o)}catch{}i&&S(),t&&e.reloadOnRevoke&&"undefined"!=typeof window&&window.location.reload()}l={...l,taxonomyHash:n.taxonomyHash},e.gpcOptOut&&!l.hasActed&&(l={...l,categories:y(()=>!1)},r(l)),u={...l.categories},g={...l.categories},Promise.resolve().then(()=>e.onConsentReady?.(l));const $={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 h},acceptAll(){l={...l,categories:y(()=>!0)},h=!1,x()},rejectAll(){l={...l,categories:y(()=>!1)},h=!1,x()},acceptSelected(e){l={...l,categories:y(t=>e.includes(t))},h=!1,x()},updateCategory(e,t){n.requiredIds.has(e)||n.ids.includes(e)&&(l={...l,categories:{...l.categories,[e]:t}},S())},savePreferences(){h=!1,x()},resetConsent(){a();const e=s();l=d(e,l.regulation,n),g={...l.categories},u={...l.categories},h=!1,Q(g),A(n,g,o),p=[],m=!1,S()},showPreferences(){h=!0,S()},hidePreferences(){h=!1,S()},subscribe:e=>(t.add(e),()=>t.delete(e)),registerScript(e){!function(e){N.set(e.id,e)}(e),I()},get reloadNotice(){return{required:p.length>0&&!m,reasons:[...p]}},dismissReloadNotice(){m||(m=!0,S())}};I();try{!function(e){for(const t of K.values()){const n=!0!==e[t.category];if(G(t))n?W.delete(t.id):W.add(t.id);else try{n?(t.stop(),Y.add(t.id)):(Y.delete(t.id),t.resume?.())}catch{}}}(l.categories)}catch{}try{A(n,l.categories,o)}catch{}return $}function te(e,t,n,o){let i;try{const e="undefined"!=typeof window?window.location.href:"http://localhost";i=new URL(t,e)}catch{return null}const r=i.hostname.toLowerCase(),a=i.pathname+i.search,s=n.toUpperCase();for(const t of e){const e=t.domain.toLowerCase();if((r===e||r.endsWith("."+e))&&((!t.pathIncludes||a.includes(t.pathIncludes))&&(!t.methods||t.methods.map(e=>e.toUpperCase()).includes(s))&&!o(t.category)))return t}return null}let ne=null;function oe(e,t){if("undefined"==typeof window)return()=>{};if(ne)return()=>{};if(!e.rules.length)return()=>{};const n={originalFetch:window.fetch,originalXhrOpen:XMLHttpRequest.prototype.open,originalXhrSend:XMLHttpRequest.prototype.send,originalSendBeacon:"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon?navigator.sendBeacon:void 0};ne=n;const o=!1!==e.logBlockedRequests;function i(t){o&&console.warn(`[cookieyes] blocked ${t.method} ${t.url} (rule "${t.rule.id}", category: ${t.rule.category})`),e.onRequestBlocked?.(t)}if(window.fetch=function(o,r){let a="",s=r?.method??"GET";"string"==typeof o?a=o:o instanceof URL?a=o.toString():(a=o.url,s=r?.method??o.method);const c=te(e.rules,a,s,t);return c?(i({rule:c,url:a,method:s}),Promise.reject(new TypeError(`Blocked by consent (rule: ${c.id}, category: ${c.category})`))):n.originalFetch.call(window,o,r)},XMLHttpRequest.prototype.open=function(e,t,...o){return this._cyUrl=t.toString(),this._cyMethod=e,n.originalXhrOpen.apply(this,[e,t,...o])},XMLHttpRequest.prototype.send=function(o){const r=this._cyUrl??"",a=this._cyMethod??"GET",s=te(e.rules,r,a,t);return s?(i({rule:s,url:r,method:a}),void this.abort()):n.originalXhrSend.call(this,o)},n.originalSendBeacon){const o=n.originalSendBeacon;navigator.sendBeacon=function(n,r){const a=te(e.rules,n.toString(),"POST",t);return a?(i({rule:a,url:n.toString(),method:"POST"}),!0):o.call(navigator,n,r)}}return ie}function ie(){ne&&("undefined"!=typeof window&&(window.fetch=ne.originalFetch,XMLHttpRequest.prototype.open=ne.originalXhrOpen,XMLHttpRequest.prototype.send=ne.originalXhrSend,ne.originalSendBeacon&&(navigator.sendBeacon=ne.originalSendBeacon)),ne=null)}const re=[{country:"x-vercel-ip-country",region:"x-vercel-ip-country-region"},{country:"cf-ipcountry"}];function ae(e,t){if(t?.header)return e.get(t.header)||void 0;for(const{country:t,region:n}of re){const o=e.get(t);if(!o)continue;const i=n?e.get(n):void 0;return i?`${o}-${i}`:o}}function se(){return"undefined"!=typeof navigator&&!0===navigator.globalPrivacyControl}function ce(e,t){const n=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 o=e.detect?.(),i=o?function(e,t){if(e)return e[t]??e[t.split("-")[0]??""]}(e.map,o):void 0;return{region:o,regulation:i??n,source:i?"detected":"strictest",confidence:i?"high":"low"}}function de(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 le=null,ue=null;function ge(e){if(le)return le;"offline"===e.mode&&m();const t=y(e),n=new Set,o=t.onConsentUpdate;let i;const r=t.region?ce(t.region,t.regulation):{region:void 0,regulation:t.regulation??"DEFAULT",source:"manual",confidence:"high"},a={};"self-hosted"===t.mode&&(t.backend?a.backend=t.backend:t.apiUrl&&(a.apiUrl=t.apiUrl)),t.apiKey&&(a.apiKey=t.apiKey),a.regulation=r.regulation,r.region&&(a.region=r.region);const s=(c=r.regulation,d=t.region,"CCPA"===c&&(d?.honorGpc??!0)&&se());var c,d;s&&(a.gpcOptOut=!0),t.region?.debug&&de(r,s),t.colorScheme&&(a.colorScheme=t.colorScheme),t.theme&&(a.theme=t.theme),t.reloadOnRevoke&&(a.reloadOnRevoke=t.reloadOnRevoke),t.googleConsentMatch&&(a.googleConsentMatch=t.googleConsentMatch),t.builtInIntegrations&&t.builtInIntegrations.length>0&&(b(),a.integrations=t.builtInIntegrations),t.customStopHandlers&&(a.customStopHandlers=t.customStopHandlers),t.categories&&(a.categories=t.categories),t.onConsentReady&&(a.onConsentReady=t.onConsentReady),a.onConsentUpdate=e=>{o?.(e),i.push(e.categories);const t=function(e){const t=[],n=[];for(const o of Object.keys(e))e[o]?t.push(o):n.push(o);return{allowedCategories:t,deniedCategories:n}}(e.categories);for(const e of n)e(t)};const l=ee(a);i=C(()=>l.committedCategories);const u=f(t.categories),g=new Set;function h(){const e=v();for(const t of g)t(e)}l.subscribe(h);const p=_(t.i18n,h);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=>(n.add(e),()=>{n.delete(e)})}}const w={subscribe:e=>(g.add(e),()=>{g.delete(e)}),getState:v,on:(e,t,n)=>i.on(e,t,n),get translations(){return p.getTranslations()},getLanguageInfo:p.getLanguageInfo,setLanguage:p.setLanguage,getCategoryText:p.getCategoryText,categories:u,getRegion:()=>r};return t.networkBlocker&&t.networkBlocker.rules.length>0&&oe(t.networkBlocker,e=>!0===l.committedCategories[e]),t.integrations&&t.integrations.length>0&&(B(t.integrations.map(e=>e.id),(t.builtInIntegrations??[]).map(e=>e.vendor)),q(t.integrations,u.ids),ue=D(t.integrations,{granted:e=>!0===l.committedCategories[e],subscribe:e=>l.subscribe(()=>e()),region:r})),le={consentManager:l,consentStore:w,getIntegrations:()=>ue?.list()??[]},le}function fe(e){return ge(e)}function he(){ue?.stop(),ue=null,le=null}function ye(e,t={}){if("string"!=typeof e||0===e.length)return null;const n=i(e);if(null==n)return null;const o=f(t.categories),r=n.tax;if(!(r===o.taxonomyHash||void 0===r&&o.isDefault))return null;const a=c(n,t.regulation??"DEFAULT",o);return a.hasActed?{...a,taxonomyHash:o.taxonomyHash}:null}const pe="0.4.0";export{pe as CORE_VERSION,l as DEFAULT_CATEGORIES,M as INTEGRATION_FORMAT_VERSION,E as _clearScriptRegistry,V as _clearStopHandlers,de as _logRegionDecision,y as _normalizeConfig,k as _resetBuiltInIntegrationsWarning,v as _resetOfflineModeWarning,b as _warnBuiltInIntegrationsDeprecated,m as _warnOfflineModeDeprecated,A as broadcastGoogleConsent,I as computeGoogleConsent,C as createConsentEmitter,ee as createConsentManager,_ as createLanguageController,x as defaultTranslations,s as generateConsentId,ge as getOrCreateConsentRuntime,L as getTextDirection,fe as initCookieYes,oe as installNetworkBlocker,P as mergeTranslations,n as parseCookie,i as parseCookieHeader,O as pickLanguage,U as primaryOf,se as readGpc,ye as readServerConsent,ae as regionFromHeaders,J as registerStopHandler,he as resetConsentRuntime,z as resolveBuiltInIntegration,f as resolveCategories,ce as resolveRegion,H as resolveTranslations,D as runIntegrations,o as serializeCookie,ie as uninstallNetworkBlocker,B as warnOverlappingVendors,q as warnUnknownCategories};
|
|
1
|
+
const e="cookieyes-consent",t=new Set(["consentid","consent","action","tax","lastRenewedDate"]);function n(e){const n={categories:{}};for(const o of e.split(",")){const e=o.indexOf(":");if(-1===e)continue;const i=o.slice(0,e).trim(),r=o.slice(e+1).trim();t.has(i)?n[i]=r:i.length>0&&(n.categories[i]=r)}return n}function o(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[n,o]of Object.entries(e.categories))t.push(`${n}:${o?"yes":"no"}`);return t.push(`lastRenewedDate:${e.lastRenewed??Date.now()}`),t.join(",")}function i(t){for(const o of t.split(";")){const t=o.trim(),i=t.indexOf("=");if(-1===i)continue;if(t.slice(0,i).trim()!==e)continue;const r=t.slice(i+1).trim();try{return n(decodeURIComponent(r))}catch{return null}}return null}function r(t){if("undefined"==typeof document)return;const n=encodeURIComponent(o(t));document.cookie=`${e}=${n}; max-age=31536000; path=/; SameSite=Lax`}function a(){"undefined"!=typeof document&&(document.cookie=`${e}=; max-age=0; path=/`)}function s(){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,n){const o={};for(const t of n.ids)o[t]=!!n.requiredIds.has(t)||"yes"===e.categories[t];return{consentId:e.consentid??s(),hasActed:"yes"===e.action,categories:o,regulation:t,lastRenewed:e.lastRenewedDate?Number(e.lastRenewedDate):void 0,taxonomyHash:e.tax}}function d(e,t,n){const o="CCPA"===t,i={};for(const e of n.ids)i[e]=!!n.requiredIds.has(e)||o;return{consentId:e,hasActed:!1,categories:i,regulation:t,taxonomyHash:n.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 n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function g(e,t){const n=e.map(e=>e.id),o=new Set(e.filter(e=>e.required).map(e=>e.id)),i=e.map(e=>`${e.id}:${e.required?1:0}:${(e.gcm??[]).join("+")}`).join("|");return{list:e,ids:n,requiredIds:o,taxonomyHash:u(i),isDefault:t}}function f(e){if(!e||0===e.length)return g(l,!0);const n=function(e){const n=e.map(e=>e.id);return n.some(e=>"string"!=typeof e||0===e.length)?"every category needs a non-empty string id":n.some(e=>e.includes(",")||e.includes(":"))?"category ids must not contain ',' or ':'":new Set(n).size!==n.length?"category ids must be unique":n.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 n?("undefined"!=typeof console&&console.warn(`[cookieyes] Invalid categories config (${n}). Falling back to the default five (necessary, functional, analytics, performance, advertisement).`),g(l,!0)):g(e,!1)}function h(e){"undefined"!=typeof console&&console.warn(e)}function y(e){const t={mode:e.mode},n=e.overrides?.regulation;return void 0!==e.regulation?(t.regulation=e.regulation,void 0!==n&&h("[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!==n&&(t.regulation=n),void 0!==e.region&&(t.region=e.region),void 0!==e.colorScheme&&(t.colorScheme=e.colorScheme),void 0!==e.theme&&(t.theme=e.theme),void 0!==e.i18n&&(t.i18n=e.i18n),void 0!==e.categories&&(t.categories=e.categories),void 0!==e.networkBlocker&&(t.networkBlocker=e.networkBlocker),void 0!==e.reloadOnRevoke&&(t.reloadOnRevoke=e.reloadOnRevoke),void 0!==e.googleConsentMatch&&(t.googleConsentMatch=e.googleConsentMatch),void 0!==e.integrations&&(t.integrations=e.integrations),void 0!==e.builtInIntegrations&&(t.builtInIntegrations=e.builtInIntegrations),void 0!==e.customStopHandlers&&(t.customStopHandlers=e.customStopHandlers),void 0!==e.onConsentReady&&(t.onConsentReady=e.onConsentReady),void 0!==e.onConsentUpdate&&(t.onConsentUpdate=e.onConsentUpdate),"self-hosted"===e.mode&&(void 0!==e.apiKey&&(t.apiKey=e.apiKey),void 0!==e.backend&&(t.backend=e.backend),void 0!==e.apiUrl?(t.apiUrl=e.apiUrl,void 0!==e.backendURL&&h("[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 m(){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 after three release cycles. See https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/migration.mdx for the full migration guide. Update to .mode("cookie-only") (or { mode: "cookie-only" }).'))}function v(){p=!1}let w=!1;function b(){w||(w=!0,"undefined"!=typeof console&&console.warn("[cookieyes] `builtInIntegrations` (formerly the `integrations` field) is deprecated and will be removed after three release cycles. Use the `integrations` field with a preset from `@cookieyes/scripts` instead. See https://github.com/cookieyes/cookieyes/blob/main/apps/web/content/docs/migration.mdx for the full migration guide."))}function k(){w=!1}function C(e){const t={save:new Set,change:new Set};let n={...e()};function o(e,t,n){try{e.listener(n)}catch(e){"undefined"!=typeof console&&console.error(`[cookieyes] a consent "${t}" listener threw; others are unaffected:`,e)}}function i(e,n){for(const i of[...t[e]])i.category&&!n.changedCategories.includes(i.category)||o(i,e,n)}return{on(n,i,r){const a=r?.category?{listener:i,category:r.category}:{listener:i};return t[n].add(a),o(a,n,{categories:{...e()},changedCategories:[],isInitial:!0}),()=>{t[n].delete(a)}},push(e){const t={...e},o=[];for(const e of Object.keys(t))n[e]!==t[e]&&o.push(e);n=t,i("save",{categories:t,changedCategories:o,isInitial:!1}),o.length>0&&i("change",{categories:t,changedCategories:o,isInitial:!1})}}}function S(e){"undefined"!=typeof console&&console.warn(`[cookieyes] ${e}`)}const R=["ad_storage","ad_user_data","ad_personalization","analytics_storage","functionality_storage","personalization_storage","security_storage"];function I(e,t,n="any"){const o={};for(const i of R){if("security_storage"===i){o[i]="granted";continue}const r=e.list.filter(e=>e.gcm?.includes(i));if(0===r.length){o[i]="denied";continue}const a="all"===n?r.every(e=>!0===t[e.id]):r.some(e=>!0===t[e.id]);o[i]=a?"granted":"denied"}return o}function A(e,t,n="any"){if("undefined"==typeof window||!Array.isArray(window.dataLayer))return;const o=I(e,t,n),i=window.dataLayer;if(!i)return;!function(){i.push(arguments)}("consent","update",o)}const x={bannerTitle:"We value your privacy",bannerDescription:"We use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking “Accept All”, you consent to our use of cookies.",acceptAll:"Accept All",rejectAll:"Reject All",managePreferences:"Customise",savePreferences:"Save My Preferences",doNotSell:"Do Not Sell or Share My Personal Information",ccpaDescription:"This website or its third-party tools process personal data. You can opt out of the sale of your personal information by clicking on the “Do Not Sell or Share My Personal Information” link.",accept:"Accept",poweredBy:"Powered by CookieYes",preferencesTitle:"Customise Consent Preferences",preferencesIntro:"We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.",alwaysActive:"Always Active",preferencesDialogLabel:"Cookie preferences",optOutDialogLabel:"Opt-out preferences",recallButtonLabel:"Consent Preferences",categories:{necessary:{label:"Necessary",description:"Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data."},functional:{label:"Functional",description:"Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features."},analytics:{label:"Analytics",description:"Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc."},performance:{label:"Performance",description:"Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors."},advertisement:{label:"Advertisement",description:"Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns."}},optOut:{title:"Opt-out Preferences",description:'We use third-party cookies that help us analyse how you use this website, store your preferences, and provide the content and advertisements that are relevant to you. However, you can opt out of these cookies by checking "Do Not Sell or Share My Personal Information" and clicking the "Save My Preferences" button. Once you opt out, you can opt in again at any time by unchecking "Do Not Sell or Share My Personal Information" and clicking the "Save My Preferences" button.',cancel:"Cancel",successText:"Your opt-out preference has been honored.",successCountdown:"Banner closes automatically in {seconds} s..."},bannerCloseLabel:"Close",preferencesCloseLabel:"Close preferences",optOutCloseLabel:"Close",gatedFrame:{placeholder:"This content requires {category} cookies to be enabled.",action:"Manage Preferences"},reloadNotice:{message:"Some tracking on this page can only be fully stopped by reloading. Reload to apply your change, or dismiss to keep browsing.",reloadButton:"Reload page",dismissButton:"Dismiss"}},L=new Set(["ar","he","fa","ur","ps","sd","yi","dv"]);function $(e){return e.split("-")[0]?.toLowerCase()??""}function U(e){return L.has($(e))?"rtl":"ltr"}function P(e,t){if(!t)return e;const n={...e};for(const[o,i]of Object.entries(t)){if(null==i)continue;const t=e[o],r="object"==typeof i&&!Array.isArray(i)&&"object"==typeof t&&null!=t;n[o]=r?P(t,i):i}return n}function O(e){const t=e?.messages??{},n=[];e?.locale&&n.push(e.locale),(e?.detectBrowserLanguage??1)&&"undefined"!=typeof navigator&&navigator.language&&n.push(navigator.language);for(const e of n){if(t[e])return e;const n=$(e);if(n&&t[n])return n}return"en"}function M(e){const t=e?.messages??{},n=O(e);return P(x,t[n]??t[$(n)])}const H=1;function B(e,t){const n=new Set(e);for(const e of t)n.has(e)&&T(`"${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 q(e,t){const n=new Set(t);for(const t of e){if("afterConsent"!==t.load)continue;const e=t.category,o=Array.isArray(e)?e:[e];if(0!==o.length)for(const e of o)n.has(e)||T(`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 T(`integration "${t.id}" has an empty category list — it will never load. Give it at least one category that exists in your taxonomy.`)}}function T(e,t){"undefined"!=typeof console&&(void 0!==t?console.error(`[cookieyes] ${e}`,t):console.warn(`[cookieyes] ${e}`))}function D(e,t){const n=Array.isArray(e.category)?e.category:[e.category];return 0!==n.length&&("any"===e.match?n.some(e=>t.granted(e)):n.every(e=>t.granted(e)))}function j(e,t){const n=[],o=new Set;let i=!1;for(const t of e){const e=t;"string"!=typeof e.vendor||"function"==typeof e.setup?1===t.version?o.has(t.id)?T(`integration "${t.id}" is registered more than once; skipping the duplicate.`):(o.add(t.id),n.push({integration:t,status:"idle",everLoaded:!1,loading:!1,control:void 0,subs:new Set,wasGranted:!1})):T(`integration "${t.id}" uses format version ${t.version}, but this build understands 1. Skipping it.`):T(`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 r(e){for(const t of e.subs)try{t()}catch{}e.subs.clear()}function a(e){r(e),"active"===e.status&&(!function(e){const{integration:t,control:n}=e;try{"remove"===t.onRevoke?n?.():"silence"===t.onRevoke&&n?.silence()}catch(e){T(`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 s(e){e.loading=!0,e.status="loading",Promise.resolve().then(()=>e.integration.setup(function(e){return{granted:()=>D(e.integration,t),onConsentChange:n=>{const o=t.subscribe(n);return e.subs.add(o),()=>{e.subs.delete(o)&&o()}},region:t.region}}(e))).then(t=>{e.loading=!1,e.control=t??void 0,e.everLoaded=!0,e.status="active",i?a(e):c(e)}).catch(t=>{e.loading=!1,e.status="error",r(e),T(`integration "${e.integration.id}" failed to load; will retry on the next change.`,t)})}function c(e){const{integration:n}=e,o=D(n,t);if(o&&(e.wasGranted=!0),i||e.loading)return;if("idle"===e.status||"removed"===e.status||"error"===e.status){return void((e.everLoaded?o:"immediately"===n.load||o)&&s(e))}if("keep"===n.onRevoke)return;if("remove"===n.onRevoke){if(!o&&"active"===e.status&&e.wasGranted){r(e);try{e.control?.()}catch(e){T(`integration "${n.id}" cleanup threw on revoke.`,e)}e.control=void 0,e.status="removed"}return}const a=e.control;if(o||"active"!==e.status){if(o&&"silenced"===e.status){try{a?.resume()}catch(e){T(`integration "${n.id}" resume() threw.`,e)}e.status="active"}}else{try{a?.silence()}catch(e){T(`integration "${n.id}" silence() threw.`,e)}e.status="silenced"}}function d(){for(const e of n)c(e)}const l=t.subscribe(d);return d(),{status:()=>{const e={};for(const t of n)e[t.integration.id]=t.status;return e},list:()=>n.map(e=>({id:e.integration.id,category:e.integration.category,load:e.integration.load,onRevoke:e.integration.onRevoke,status:e.status})),stop:()=>{if(!i){i=!0,l();for(const e of n)a(e)}}}}function _(e,t){const n={...e?.messages},o=e?.loadLanguage,i=new Set;let r=O(e),a=l(r),s=u();function c(e){return n[e]??n[$(e)]}function d(e){return"en"===$(e)||void 0!==c(e)}function l(e){return P(x,c(e))}function u(){return{language:r,direction:U(r),languages:Array.from(new Set(["en",...Object.keys(n)]))}}function g(e){r=e,a=l(e),s=u(),t()}function f(e,t){i.has(e)||"undefined"==typeof console||(i.add(e),console.warn(`[cookieyes] no translations for language "${e}"; staying on "${r}". Add it to i18n.messages or provide i18n.loadLanguage.`,t??""))}function h(e){return d(e)?(g(e),Promise.resolve()):o?Promise.resolve().then(()=>o(e)).then(t=>{n[e]=t,g(e)}).catch(t=>f(e,t)):(f(e),Promise.resolve())}return o&&e?.locale&&!d(e.locale)&&"undefined"!=typeof window&&h(e.locale),{getTranslations:()=>a,getLanguageInfo:()=>s,setLanguage:h,getCategoryText:function(e){return c(r)?.categories?.[e]}}}const N=new Map,X=new Map;function F(){if("undefined"!=typeof document)for(const e of X.values())e.remove();N.clear(),X.clear()}function E(e,t){if(document.getElementById(e))return;const n=document.createElement("script");n.id=e,n.src=t.src,n.async=!0,t.onLoad&&n.addEventListener("load",t.onLoad,{once:!0}),document.head.appendChild(n),X.set(e,n)}function G(e){return"needsReload"in e&&!0===e.needsReload}function z(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 K=new Map,Y=new Set,W=new Set;function J(e){K.set(e.id,e)}function V(){K.clear(),Y.clear(),W.clear()}function Q(e){const t=[];for(const n of K.values()){const o=!0!==e[n.category];if(G(n))o?W.has(n.id)&&(t.push(n.id),W.delete(n.id)):W.add(n.id);else if(o){if(!Y.has(n.id))try{n.stop(),Y.add(n.id)}catch{t.push(n.id)}}else if(Y.has(n.id)){Y.delete(n.id);try{n.resume?.()}catch{}}}return{reloadRequiredBy:t}}function Z(e,t){const n={consentId:e.consentId,categories:e.categories,regulation:e.regulation,domain:"undefined"!=typeof window?window.location.hostname:"unknown"};return t&&(n.region=t),n}function ee(e){const t=new Set,n=f(e.categories),o=e.googleConsentMatch??"any";let l;void 0===e.googleConsentMatch&&function(e){const t=new Map;for(const n of e.list)for(const e of n.gcm??[]){let o=t.get(e);o||(o=new Set,t.set(e,o)),o.add(n.id)}for(const[e,n]of t)n.size<=1||S(`categories ${[...n].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.`)}(n);let u,g,h=!1;function y(e){const t={};for(const o of n.ids)t[o]=!!n.requiredIds.has(o)||e(o);return t}let p=[],m=!1;for(const t of e.integrations??[])J(z(t));for(const t of e.customStopHandlers??[])J(t);const v="undefined"==typeof document?null:i(document.cookie),w=e.regulation??"DEFAULT",b=v?.tax,k=b===n.taxonomyHash,C=null!=v&&(k||void 0===b&&n.isDefault);if(null!=v&&C)l=c(v,w,n);else{const e=v?.consentid??s();l=d(e,w,n),null!=v&&a(),"CCPA"===l.regulation&&r(l)}function R(){const e={consentId:l.consentId,hasActed:l.hasActed,categories:{...l.categories},regulation:l.regulation,lastRenewed:l.lastRenewed,taxonomyHash:l.taxonomyHash};for(const n of t)n(e)}function I(){!function(e){if("undefined"!=typeof document)for(const[t,n]of N)!0===e[n.category]&&(X.has(t)||E(t,n))}(g)}function x(){l={...l,hasActed:!0,lastRenewed:Date.now()},r(l);let t=!1;for(const e of n.ids)if(u[e]&&!l.categories[e]){t=!0;break}if(u={...l.categories},g={...l.categories},R(),e.onConsentUpdate?.(l),e.backend)try{Promise.resolve(e.backend.persist(Z(l,e.region))).catch(()=>{})}catch{}else e.apiUrl&&async function(e,t,n,o){const i=Z(n,o),r={"Content-Type":"application/json"};t&&(r.Authorization=`Bearer ${t}`);try{await fetch(e,{method:"POST",headers:r,body:JSON.stringify(i),keepalive:!0})}catch{}}(e.apiUrl,e.apiKey,l,e.region);try{I()}catch{}let i=!1;try{const{reloadRequiredBy:e}=Q(g);i=function(e){const t=e.length!==p.length||e.some((e,t)=>e!==p[t]);return t&&(p=e,m=!1),t}(e)}catch{}try{A(n,g,o)}catch{}i&&R(),t&&e.reloadOnRevoke&&"undefined"!=typeof window&&window.location.reload()}l={...l,taxonomyHash:n.taxonomyHash},e.gpcOptOut&&!l.hasActed&&(l={...l,categories:y(()=>!1)},r(l)),u={...l.categories},g={...l.categories},Promise.resolve().then(()=>e.onConsentReady?.(l));const L={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 h},acceptAll(){l={...l,categories:y(()=>!0)},h=!1,x()},rejectAll(){l={...l,categories:y(()=>!1)},h=!1,x()},acceptSelected(e){l={...l,categories:y(t=>e.includes(t))},h=!1,x()},updateCategory(e,t){n.requiredIds.has(e)||n.ids.includes(e)&&(l={...l,categories:{...l.categories,[e]:t}},R())},savePreferences(){h=!1,x()},resetConsent(){a();const e=s();l=d(e,l.regulation,n),g={...l.categories},u={...l.categories},h=!1,Q(g),A(n,g,o),p=[],m=!1,R()},showPreferences(){h=!0,R()},hidePreferences(){h=!1,R()},subscribe:e=>(t.add(e),()=>t.delete(e)),registerScript(e){!function(e){N.set(e.id,e)}(e),I()},get reloadNotice(){return{required:p.length>0&&!m,reasons:[...p]}},dismissReloadNotice(){m||(m=!0,R())}};I();try{!function(e){for(const t of K.values()){const n=!0!==e[t.category];if(G(t))n?W.delete(t.id):W.add(t.id);else try{n?(t.stop(),Y.add(t.id)):(Y.delete(t.id),t.resume?.())}catch{}}}(l.categories)}catch{}try{A(n,l.categories,o)}catch{}return L}function te(e,t,n,o){let i;try{const e="undefined"!=typeof window?window.location.href:"http://localhost";i=new URL(t,e)}catch{return null}const r=i.hostname.toLowerCase(),a=i.pathname+i.search,s=n.toUpperCase();for(const t of e){const e=t.domain.toLowerCase();if((r===e||r.endsWith("."+e))&&((!t.pathIncludes||a.includes(t.pathIncludes))&&(!t.methods||t.methods.map(e=>e.toUpperCase()).includes(s))&&!o(t.category)))return t}return null}let ne=null;function oe(e,t){if("undefined"==typeof window)return()=>{};if(ne)return()=>{};if(!e.rules.length)return()=>{};const n={originalFetch:window.fetch,originalXhrOpen:XMLHttpRequest.prototype.open,originalXhrSend:XMLHttpRequest.prototype.send,originalSendBeacon:"undefined"!=typeof navigator&&"function"==typeof navigator.sendBeacon?navigator.sendBeacon:void 0};ne=n;const o=!1!==e.logBlockedRequests;function i(t){o&&console.warn(`[cookieyes] blocked ${t.method} ${t.url} (rule "${t.rule.id}", category: ${t.rule.category})`),e.onRequestBlocked?.(t)}if(window.fetch=function(o,r){let a="",s=r?.method??"GET";"string"==typeof o?a=o:o instanceof URL?a=o.toString():(a=o.url,s=r?.method??o.method);const c=te(e.rules,a,s,t);return c?(i({rule:c,url:a,method:s}),Promise.reject(new TypeError(`Blocked by consent (rule: ${c.id}, category: ${c.category})`))):n.originalFetch.call(window,o,r)},XMLHttpRequest.prototype.open=function(e,t,...o){return this._cyUrl=t.toString(),this._cyMethod=e,n.originalXhrOpen.apply(this,[e,t,...o])},XMLHttpRequest.prototype.send=function(o){const r=this._cyUrl??"",a=this._cyMethod??"GET",s=te(e.rules,r,a,t);return s?(i({rule:s,url:r,method:a}),void this.abort()):n.originalXhrSend.call(this,o)},n.originalSendBeacon){const o=n.originalSendBeacon;navigator.sendBeacon=function(n,r){const a=te(e.rules,n.toString(),"POST",t);return a?(i({rule:a,url:n.toString(),method:"POST"}),!0):o.call(navigator,n,r)}}return ie}function ie(){ne&&("undefined"!=typeof window&&(window.fetch=ne.originalFetch,XMLHttpRequest.prototype.open=ne.originalXhrOpen,XMLHttpRequest.prototype.send=ne.originalXhrSend,ne.originalSendBeacon&&(navigator.sendBeacon=ne.originalSendBeacon)),ne=null)}const re=[{country:"x-vercel-ip-country",region:"x-vercel-ip-country-region"},{country:"cf-ipcountry"}];function ae(e,t){if(t?.header)return e.get(t.header)||void 0;for(const{country:t,region:n}of re){const o=e.get(t);if(!o)continue;const i=n?e.get(n):void 0;return i?`${o}-${i}`:o}}function se(){return"undefined"!=typeof navigator&&!0===navigator.globalPrivacyControl}function ce(e,t){const n=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 o=e.detect?.(),i=o?function(e,t){if(e)return e[t]??e[t.split("-")[0]??""]}(e.map,o):void 0;return{region:o,regulation:i??n,source:i?"detected":"strictest",confidence:i?"high":"low"}}function de(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 le=null,ue=null;function ge(e){if(le)return le;"offline"===e.mode&&m();const t=y(e),n=new Set,o=t.onConsentUpdate;let i;const r=t.region?ce(t.region,t.regulation):{region:void 0,regulation:t.regulation??"DEFAULT",source:"manual",confidence:"high"},a={};"self-hosted"===t.mode&&(t.backend?a.backend=t.backend:t.apiUrl&&(a.apiUrl=t.apiUrl)),t.apiKey&&(a.apiKey=t.apiKey),a.regulation=r.regulation,r.region&&(a.region=r.region);const s=(c=r.regulation,d=t.region,"CCPA"===c&&(d?.honorGpc??!0)&&se());var c,d;s&&(a.gpcOptOut=!0),t.region?.debug&&de(r,s),t.colorScheme&&(a.colorScheme=t.colorScheme),t.theme&&(a.theme=t.theme),t.reloadOnRevoke&&(a.reloadOnRevoke=t.reloadOnRevoke),t.googleConsentMatch&&(a.googleConsentMatch=t.googleConsentMatch),t.builtInIntegrations&&t.builtInIntegrations.length>0&&(b(),a.integrations=t.builtInIntegrations),t.customStopHandlers&&(a.customStopHandlers=t.customStopHandlers),t.categories&&(a.categories=t.categories),t.onConsentReady&&(a.onConsentReady=t.onConsentReady),a.onConsentUpdate=e=>{o?.(e),i.push(e.categories);const t=function(e){const t=[],n=[];for(const o of Object.keys(e))e[o]?t.push(o):n.push(o);return{allowedCategories:t,deniedCategories:n}}(e.categories);for(const e of n)e(t)};const l=ee(a);i=C(()=>l.committedCategories);const u=f(t.categories),g=new Set;function h(){const e=v();for(const t of g)t(e)}l.subscribe(h);const p=_(t.i18n,h);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=>(n.add(e),()=>{n.delete(e)})}}const w={subscribe:e=>(g.add(e),()=>{g.delete(e)}),getState:v,on:(e,t,n)=>i.on(e,t,n),get translations(){return p.getTranslations()},getLanguageInfo:p.getLanguageInfo,setLanguage:p.setLanguage,getCategoryText:p.getCategoryText,categories:u,getRegion:()=>r};return t.networkBlocker&&t.networkBlocker.rules.length>0&&oe(t.networkBlocker,e=>!0===l.committedCategories[e]),t.integrations&&t.integrations.length>0&&(B(t.integrations.map(e=>e.id),(t.builtInIntegrations??[]).map(e=>e.vendor)),q(t.integrations,u.ids),ue=j(t.integrations,{granted:e=>!0===l.committedCategories[e],subscribe:e=>l.subscribe(()=>e()),region:r})),le={consentManager:l,consentStore:w,getIntegrations:()=>ue?.list()??[]},le}function fe(e){return ge(e)}function he(){ie(),ue?.stop(),ue=null,le=null}function ye(e,t={}){if("string"!=typeof e||0===e.length)return null;const n=i(e);if(null==n)return null;const o=f(t.categories),r=n.tax;if(!(r===o.taxonomyHash||void 0===r&&o.isDefault))return null;const a=c(n,t.regulation??"DEFAULT",o);return a.hasActed?{...a,taxonomyHash:o.taxonomyHash}:null}const pe="0.5.0";export{pe as CORE_VERSION,l as DEFAULT_CATEGORIES,H as INTEGRATION_FORMAT_VERSION,F as _clearScriptRegistry,V as _clearStopHandlers,de as _logRegionDecision,y as _normalizeConfig,k as _resetBuiltInIntegrationsWarning,v as _resetOfflineModeWarning,b as _warnBuiltInIntegrationsDeprecated,m as _warnOfflineModeDeprecated,A as broadcastGoogleConsent,I as computeGoogleConsent,C as createConsentEmitter,ee as createConsentManager,_ as createLanguageController,x as defaultTranslations,s as generateConsentId,ge as getOrCreateConsentRuntime,U as getTextDirection,fe as initCookieYes,oe as installNetworkBlocker,P as mergeTranslations,n as parseCookie,i as parseCookieHeader,O as pickLanguage,$ as primaryOf,se as readGpc,ye as readServerConsent,ae as regionFromHeaders,J as registerStopHandler,he as resetConsentRuntime,z as resolveBuiltInIntegration,f as resolveCategories,ce as resolveRegion,M as resolveTranslations,j as runIntegrations,o as serializeCookie,ie as uninstallNetworkBlocker,B as warnOverlappingVendors,q as warnUnknownCategories};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|