/** * @id5io/id5-api.js * @version v1.0.76 * @link https://id5.io/ * @license Apache-2.0 */ !function(){"use strict";function r(t,e){var i,r=Object.keys(t);return Object.getOwnPropertySymbols&&(i=Object.getOwnPropertySymbols(t),e&&(i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,i)),r}function h(t){for(var e=1;ee.length)&&(t=e.length);for(var i=0,r=new Array(t);i=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:t}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,n=!0,o=!1;return{s:function(){i=i.call(e)},n:function(){var e=i.next();return n=e.done,e},e:function(e){o=!0,s=e},f:function(){try{n||null==i.return||i.return()}finally{if(o)throw s}}}}function i(e,t,i){return function(e,t){if(e!==t)throw new TypeError("Private static access of wrong provenance")}(e,t),i}class e{debug(){}info(){}warn(){}error(){}}const g=new e;class p extends e{constructor(e,t){super(),this._prefix=e,this._delegate=t}debug(){for(var e=arguments.length,t=new Array(e),i=0;i{let r=i.data;if(void 0!==i.data&&i.data._isId5Message&&i.data.src!==s._id&&(void 0===i.data.dst||i.data.dst===s._id))try{[o,r.type].forEach(e=>{let t=s._handlers[e];t&&t.forEach(e=>e(r,i.source))})}catch(e){s._log.error("Error while handling message",r,e)}},{capture:!1,signal:e})}unregister(){this._abortController&&this._abortController.abort()}onAnyMessage(e){return this.onMessage(o,e)}onMessage(e,t){const i=this._handlers[e];return i?i.push(t):this._handlers[e]=[t],this}broadcastMessage(e,t){this._log.debug("Broadcasting message",t,e),this._postMessage(this._messageFactory.createBroadcastMessage(e,t))}sendResponseMessage(e,t){var i=2void 0===e.dst?(this._countInvalidMessage(e,"no-destination-proxy"),void this._log.error("Received invalid RemoteMethodCallMessage message",JSON.stringify(e),"Ignoring it....")):void t._handle(u(new w,e.payload)))}_countInvalidMessage(e,t){var i,r=e=>null!=e;void 0!==(null===(i=this._metrics)||void 0===i?void 0:i.instanceInvalidMsgCounter)&&this._metrics.instanceInvalidMsgCounter({reason:t,hasDestination:r(e.dst),hasSource:r(e.src),hasPayload:r(e.payload),hasRequest:r(e.request),hasTimestamp:r(e.timestamp)}).inc()}}function b(e,t){var i="^\\d+(\\.\\d+(\\.\\d+){0,1}){0,1}$";if(e.match(i)&&t.match(i)){var r=e.split("."),s=t.split("."),i=e=>parseInt(e)||0,e=(e,t)=>{t=e-t;return 0==t?0:t<0?-1:1},t=e(i(r[0]),i(s[0]));if(0!==t)return t;t=e(i(r[1]),i(s[1]));return 0===t?e(i(r[2]),i(s[2])):t}}const D="Array",E="String",T="Function",A=Object.prototype.toString;function P(e,t){return A.call(e)==="[object "+t+"]"}function O(e){return P(e,T)}function R(e){return P(e,E)}function x(e){return P(e,D)}function N(e){return P(e,"Number")}function L(e){return P(e,"Object")}function F(e){return void 0!==e}function U(t,i){if(!function(e){if(!e)return 1;if(x(e)||R(e))return!(0{let i=t.split("="),r=l(i,2),s=r[0],n=r[1];return/\[\]$/.test(s)?(s=s.replace("[]",""),e[s]=e[s]||[],e[s].push(n)):e[s]=n||"",e},{}):{},hash:(i.hash||"").replace(/^#/,""),host:i.host||window.location.host}}function V(e){return(e.protocol||"http")+"://"+(e.host||e.hostname+(e.port?":".concat(e.port):""))+(e.pathname||"")+(e.search?"?".concat((i=e.search||"",Object.keys(i).map(t=>Array.isArray(i[t])?i[t].map(e=>"".concat(t,"[]=").concat(e)).join("&"):"".concat(t,"=").concat(i[t])).join("&"))):"")+(e.hash?"#".concat(e.hash):"");var i}function G(i,e){function r(e,t){if(O(Math.imul))return Math.imul(e,t);var i=(4194303&e)*(t|=0);return 4290772992&e&&(i+=(4290772992&e)*t|0),0|i}e=1>>16,2246822507)^r(n^n>>>13,3266489909),n=r(n^n>>>16,2246822507)^r(s^s>>>13,3266489909),(4294967296*(2097151&n)+(s>>>0)).toString()}const M=Object.freeze({cmp:"cmp",partner:"partner",prebid:"prebid"}),j=["localStoragePurposeConsent","ccpaString"],W=Object.freeze({NONE:"none",TCF_V1:"TCFv1",TCF_V2:"TCFv2",USP_V1:"USPv1",ID5_ALLOWED_VENDORS:"ID5",PREBID:"PBJS",GPP_V1_0:"GPPv1.0",GPP_V1_1:"GPPv1.1"});class q{constructor(){var e=0t[e]).reduce((e,t)=>e&&t,!0);return new B(r,J.CONSENT_API,t,i)}_addToDebugInfo(e,t,i){return void 0!==t.localStoragePurposeConsent&&(i[e+"-localStoragePurposeConsent"]=t.localStoragePurposeConsent),void 0!==t.vendorsConsentForId5Granted&&(i[e+"-vendorsConsentForId5Granted"]=t.vendorsConsentForId5Granted),i}_isGranted(){return!1===this.gdprApplies||!0===this.localStoragePurposeConsent&&!1!==this.vendorsConsentForId5Granted}hashCode(){this.localStoragePurposeConsent,this.ccpaString;var e=t(this,j);return G(JSON.stringify(e))}static createFrom(e){const t=u(new H,e);return F(t.api)&&(t.apiTypes=function(e){var t=e.api;if(t===W.NONE)return[];if(t!==W.PREBID)return[t];{const i=[];return(F(e.gdprApplies)||F(e.consentString))&&i.push(W.TCF_V2),F(e.ccpaString)&&i.push(W.USP_V1),F(e.gppData)&&F(e.gppData.version)&&i.push(e.gppData.version),i}}(e),t.api=void 0),L(t.gppData)&&(t.gppData=u(new q,t.gppData)),t}getApiTypeData(e){if(this.apiTypes.includes(e)){if(e===W.USP_V1)return{ccpaString:this.ccpaString};if(e===W.TCF_V2)return{consentString:this.consentString,gdprApplies:this.gdprApplies,localStoragePurposeConsent:this.localStoragePurposeConsent};if(e===W.GPP_V1_1||e===W.GPP_V1_0)return this.gppData;if(e===W.ID5_ALLOWED_VENDORS)return{allowedVendors:this.allowedVendors}}}}const J=Object.freeze({FORCE_ALLOWED_BY_CONFIG:"force_allowed_by_config",ID5_CONSENT:"id5_consent",PROVISIONAL:"provisional",JURISDICTION:"jurisdiction",CONSENT_API:"consent_api"});class B{constructor(e,t){var i=2{var t=e.cacheId;r.has(t)||(e=i.getResponseFor(e.integrationId))&&(this._clientStore.storeResponseV2(t,e,i.timestamp),r.add(t))}),this._trueLinkAdapter.setPrivacy(null===(e=i.getGenericResponse())||void 0===e?void 0:e.privacy)}clearAll(e){this._clientStore.clearResponse(),this._clientStore.clearDateTime(),e.forEach(e=>{e=e.cacheId;this._clientStore.clearResponseV2(e)}),this._clientStore.clearHashedConsentData(),this._trueLinkAdapter.clearPrivacy(),this._clientStore.clearExtensions()}getCachedResponse(e){e=this._clientStore.getStoredResponseV2(e);if(e)return new Q(e.response,e.responseTimestamp,e.nb)}getCachedExtensions(){return this._clientStore.getExtensions()}storeExtensions(e){var t=N(e.ttl)?e.ttl/86400:Y.DEFAULT.EXTENSIONS.expiresDays,t=new K(Y.DEFAULT.EXTENSIONS.name,t);return this._clientStore.storeExtensions(e,t)}}class Q{constructor(e,t){var i=2e}isStale(){return!this.timestamp||this._isOlderThanSec(1209600)}isResponseComplete(){return L(this.response)&&R(this.response.universal_uid)&&R(this.response.signature)}isValid(){return this.isResponseComplete()&&!this.isStale()}getMaxAge(){var e,t;return null===(e=this.response)||void 0===e||null===(t=e.cache_control)||void 0===t?void 0:t.max_age_sec}getAgeSec(){return(Date.now()-this.timestamp)/1e3|0}}const $="_exp";class Z{constructor(e){var t=1{e.removeItem(t)};this._replicas.forEach(e),this._lastKeyOperation[t]=e}setItem(t,i){this._primaryStorage.setItem(t,i);var e=e=>{e.setItem(t,i)};this._replicas.forEach(e),this._lastKeyOperation[t]=e}addReplica(t){Object.values(this._lastKeyOperation).forEach(e=>e(t)),this._replicas.push(t)}getKeysWithPrefix(e){return this._primaryStorage.getKeysWithPrefix(e)}}const se="undefined"!=typeof Promise&&"undefined"!=typeof fetch;class ne{constructor(e){var t=1function(i){Object.keys(i).forEach(function(e){var t=i[e];t&&(t instanceof Object?i[e]=JSON.stringify(t):i[e]="".concat(t))})}(e.tags)),fetch(this.url,{method:"POST",headers:{"Content-Type":"text/plain"},mode:"no-cors",body:JSON.stringify({metadata:h(h({},this._metadata),t),measurements:e})})):Promise.resolve()}}const oe=Object.freeze({});var ae,ce={EMPTY:oe,from:function(e){return e?e instanceof Map?Object.fromEntries(e):e:oe},toString:function(e){return Array.from(Object.entries(e),e=>{var t=l(e,2),e=t[0],t=t[1];return"".concat(e,"=").concat(t)}).sort().toString()}};const le=Object.freeze({TIMER:"TIMER",SUMMARY:"SUMMARY",COUNTER:"COUNTER"});class de{constructor(e,t,i){d(this,"name",void 0),d(this,"tags",void 0),d(this,"values",void 0),this.name=e,this.tags=ce.from(t),this.type=i,this.values=[]}reset(){this.values=[]}}class he extends de{constructor(e){super(e,1{return l(e,2)[1]})}}function ve(){return new ue}function fe(e){return{partner:e}}class me extends class{constructor(){var e=0({name:e.name,type:e.type,tags:e.tags,values:e.values})).filter(function(e){return e.values&&0e.reset())}addCommonTags(e){this.commonTags=h(h({},this.commonTags),ce.from(e))}timer(e){return this.getOrCreate(e,1new he(e,t))}counter(e){return this.getOrCreate(e,1new ge(e,t))}summary(e){return this.getOrCreate(e,1new pe(e,t))}publish(){let t=0e,i=1t(e,i)).then(()=>this.reset())}schedulePublishAfterMsec(t,i){if(!this._scheduled){let e=this;setTimeout(()=>(e._scheduled=!1,e.publish(i,{trigger:"fixed-time",fixed_time_msec:t})),t),this._scheduled=!0}return this}schedulePublishBeforeUnload(e){const t=this,i="undefined"!=typeof AbortController?new AbortController:void 0;return i&&(i.publisher=e,addEventListener("beforeunload",()=>t.publish(e,{trigger:"beforeunload"}),{capture:!1,signal:i.signal}),this._onUnloadPublishAbortController=i),this}unregister(){const e=this._onUnloadPublishAbortController;if(e)return e.abort(),this.publish(e.publisher,{trigger:"unregister"})}}{constructor(e,t){var i=2{const s=e.map(e=>{const t=e.cacheData;var i=null===t||void 0===t||null===(s=t.response)||void 0===s?void 0:s.signature,r=null===t||void 0===t?void 0:t.nb,s=null===t||void 0===t?void 0:t.getMaxAge();return this._createRequest(l,e,i,r,s,n,d)}),o=this._log,a=this._metrics,c=this;return new Promise((t,i)=>{const r=ve();var e="".concat("https://id5-sync.com").concat("/gm/v3");o.info("Fetching ID5 ID from:",e,s),function(r,s,n,o,e){o=3{i.setRequestHeader(t,e)}),o.preflight&&i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.setRequestHeader("Content-Type",o.contentType||"text/plain"),"POST"===l&&n?i.send(n):i.send()}catch(e){a.error("ajax","xhr construction",e)}}(e,{success:function(e){o.info("Success at fetch call:",e),r.record(null===a||void 0===a?void 0:a.fetchSuccessfulCallTimer());try{t(new Ie(c._validateResponse(e)))}catch(e){i(e)}},error:function(e){r.record(null===a||void 0===a?void 0:a.fetchFailureCallTimer()),i(e)}},JSON.stringify({requests:s}),{method:"POST",withCredentials:!0},o)})})}_validateResponse(e){if(!e||!R(e)||e.length<1)throw new Error('Empty fetch response from ID5 servers: "'.concat(e,'"'));var t=JSON.parse(e);if(!L(t.generic))throw new Error("Server response failed to validate: ".concat(e));return this._log.info("Valid json response from ID5 received",t),t}_createRequest(e,i,t,r,s,n,o){this._log.info("Create request data for",{fetchIdData:i,consentData:e,signature:t,nbValue:r,refreshInSecondUsed:s,extensions:n});var a=i.partnerId;const c={requestId:i.integrationId,requestCount:i.requestCount,role:i.role,cacheId:i.cacheId,refresh:i.refresh,source:i.source,sourceVersion:i.sourceVersion,partner:a,v:i.originVersion,o:i.origin,tml:null===(a=i.refererInfo)||void 0===a?void 0:a.topmostLocation,ref:null===(a=i.refererInfo)||void 0===a?void 0:a.ref,cu:null===(a=i.refererInfo)||void 0===a?void 0:a.canonicalUrl,u:(null===(a=i.refererInfo)||void 0===a?void 0:a.stack[0])||window.location.href,top:null!==(a=i.refererInfo)&&void 0!==a&&a.reachedTop?1:0,localStorage:!0===o?1:0,nbPage:r,id5cdn:i.isUsingCdn,ua:window.navigator.userAgent,att:i.att};r=e.gdprApplies;F(r)&&(c.gdpr=r?1:0);r=e.consentString;F(r)&&(c.gdpr_consent=r),F(i.allowedVendors)?c.allowed_vendors=i.allowedVendors:F(e.allowedVendors)&&(c.allowed_vendors=e.allowedVendors),F(e.gppData)&&(c.gpp_string=e.gppData.gppString,c.gpp_sid=e.gppData.applicableSections.join(",")),F(t)&&(c.s=t);t=i.uaHints;F(t)&&(c.ua_hints=t),F(e.ccpaString)&&""!==e.ccpaString&&(c.us_privacy=e.ccpaString),function(e){var t=Object.keys(e);let i=t.length,r=new Array(i);for(;i--;)r[i]=[t[i],e[t[i]]];return r}({pd:"pd",partnerUserId:"puid",provider:"provider",segments:"segments",trueLink:"true_link"}).forEach(e=>{var t=l(e,2),e=t[0],t=t[1];F(i[e])&&(c[t]=i[e])});e=i.abTesting;e&&!0===e.enabled&&(c.ab_testing={enabled:!0,control_group_pct:e.controlGroupPct});e=i.invalidSegmentsCount;return e&&0void 0!==e.find(e=>t.getId()===e)&&t.canDoCascade()).sort((e,t)=>{function i(e){var t;return(null===(e=e.getFetchIdData().refererInfo)||void 0===e||null===(t=e.stack)||void 0===t?void 0:t.length)||Number.MAX_SAFE_INTEGER}return i(e)-i(t)});if(0{const e=this._consentManager.localStorageGrant("fetch-before-request");if(o.info("Local storage grant",e),e.allowed){var i=this._store.hasConsentChanged(t);e.isDefinitivelyAllowed()&&this._store.storeConsent(t);var r=ie.checkIfAccessible();const c=new Map;let a=n;const s=this._followers.map(e=>{var t=e.getId(),i=(this._followersRequests[t]||0)+1,r=this._properties.id,s=!0===this._refreshRequired[e.getId()];a=a||s;var n,o=e.getCacheId();return c.has(o)||(n=this._store.getCachedResponse(o))&&c.set(o,n),h(h({},e.getFetchIdData()),{},{integrationId:t,requestCount:i,refresh:s,role:r===e.getId()?"leader":"follower",cacheId:o,cacheData:c.get(o),sourceVersion:e.getSourceVersion(),source:e.getSource()})});i||a?(o.info("Decided to fetch a fresh ID5 ID",{consentHasChanged:i,shouldRefresh:a}),o.info("Fetching ID5 ID (forceFetch:".concat(n,")")),this._inProgressFetch=!0,this._firstFetchTriggered=!0,this._fetcher.fetchId(s,t,r).then(e=>{this._handleRefreshResult(s,c,t,e),this._handleFetchCompleted()}).catch(e=>{this._handleFailed(e),this._handleFetchCompleted()})):(o.info("Not decided to refresh ID5 ID",{consentHasChanged:i,shouldRefresh:a}),this._handleFetchCompleted())}else o.info("No legal basis to use ID5",t),this._store.clearAll(this._followers.map(e=>({cacheId:e.getCacheId()}))),this._handleCancel("No legal basis to use ID5")})}_waitForConsent(){const t=this._log,e=this._consentManager,i=this._metrics;t.info("Waiting for consent");const r=i.timer("fetch.consent.wait.time");return e.getConsentData().then(e=>(t.info("Consent received",e),r&&r.recordNow(),e))}start(){!0!==this._started&&(this._getId(!1),this._started=!0)}refreshUid(){var e=0e.getId()===t))&&this._provisionFromCache(i)),this._metrics.refreshCallCounter("leader",{overwrites:void 0===this._queuedRefreshArgs}).inc(),this._callRefresh(e,t)}_callRefresh(){var e=0e.getDeclaredConsentSource()));var i=e.source||M.cmp,r=1===s.size&&s.has(M.partner);this._awaitedConsentFrom?this._awaitedConsentFrom===t?(this._consentManager.setConsentData(e),this._awaitedConsentFrom=void 0):this._handleIgnoredConsent(e,"awaited"):i!==M.partner||r?this._consentManager.setConsentData(e):this._handleIgnoredConsent(e,"partner")}}_handleIgnoredConsentUpdate(e){try{const r=this._consentManager._consentDataHolder.getValue();if(r){const s={},n=H.createFrom(e);Object.values(W).forEach(e=>{var t,i;n.apiTypes.includes(e)&&r.apiTypes.includes(e)?(t=JSON.stringify(r.getApiTypeData(e)),i=JSON.stringify(n.getApiTypeData(e)),s[e]=t===i?"same":"different"):n.apiTypes.includes(e)?s[e]="added":r.apiTypes.includes(e)&&(s[e]="missed")}),this._metrics.consentChangeCounter(s).inc()}}catch(e){this._log.error(e)}}_handleIgnoredConsent(e,t){try{const i={reason:t,source:e.source};e.apiTypes.forEach(e=>i[e]=!0),this._metrics.consentIgnoreCounter(i)}catch(e){this._log.error(e)}}updateFetchIdData(t,e){const i=this._followers.find(e=>e.getId()===t);var r=i.getCacheId();i.updateFetchIdData(e);e=i.getCacheId();e!==r&&(this._log.info("Follower",i.getId(),"cacheId changed from",r," to",e,"required refresh"),this._refreshRequired[i.getId()]=!0)}addFollower(t){const e=this._log;var i=void 0===this._followers.find(e=>e.getCacheId()===t.getCacheId());this._followers.push(t),e.info("Added follower",t.getId(),"cacheId",t.getCacheId()),this._window!==t.getWindow()&&(r=t.getStorage(),e.info("Adding follower's",t.getId(),"storage as replica"),this._leaderStorage.addReplica(r));var r=this._provisionFromCache(t);let s=new Re;return!0===this._firstFetchTriggered&&(s.lateJoiner=!0,s.uniqueLateJoiner=i,r&&this._callRefresh({forceFetch:!0})),s}_provisionFromCache(e){var t=this._cachedIdProvider.provisionFromCache(e);return this._refreshRequired[e.getId()]=t.refreshRequired,t.provisioned&&this._store.incNb(t.cacheId),t.refreshRequired}getProperties(){return this._properties}_handleFetchCompleted(){this._inProgressFetch=void 0,this._queuedRefreshArgs&&(this._callRefresh(...this._queuedRefreshArgs),this._queuedRefreshArgs=void 0)}_handleFailed(e){this._log.error("Fetch id failed",e);var t,i=f(this._followers);try{for(i.s();!(t=i.n()).done;){const r=t.value;r.notifyFetchUidCanceled({reason:"error"})}}catch(e){i.e(e)}finally{i.f()}}}class Le extends xe{constructor(e,t){super(),d(this,"_messenger",void 0),d(this,"_leaderInstanceProperties",void 0),this._messenger=e,this._leaderInstanceProperties=t}_sendToLeader(e,t){this._messenger.callProxyMethod(this._leaderInstanceProperties.id,C.LEADER,e,t)}updateConsent(e,t){this._sendToLeader("updateConsent",[e,t])}refreshUid(e,t){this._sendToLeader("refreshUid",[e,t])}updateFetchIdData(e,t){this._sendToLeader("updateFetchIdData",[e,t])}getProperties(){return this._leaderInstanceProperties}}class Fe extends xe{constructor(){super(...arguments),d(this,"_callsQueue",[]),d(this,"_assignedLeader",void 0)}updateConsent(e,t){this._callOrBuffer("updateConsent",[e,t])}updateFetchIdData(e,t){this._callOrBuffer("updateFetchIdData",[e,t])}refreshUid(e,t){this._callOrBuffer("refreshUid",[e,t])}addFollower(e){return this._callOrBuffer("addFollower",[e])}getProperties(){if(this._assignedLeader)return this._assignedLeader.getProperties()}assignLeader(e){this._assignedLeader=e;var t,i=f(this._callsQueue);try{for(i.s();!(t=i.n()).done;){var r=t.value;this._callAssignedLeader(r.name,r.args)}}catch(e){i.e(e)}finally{i.f()}this._callsQueue=[]}_callOrBuffer(e,t){if(this._assignedLeader)return this._callAssignedLeader(e,t);this._callsQueue.push({name:e,args:t})}_callAssignedLeader(e,t){return this._assignedLeader[e](...t)}}class Ue{constructor(){d(this,"_valuePromise",void 0),d(this,"_value",void 0),d(this,"_resolve",void 0),d(this,"_hasValue",void 0),this.reset()}reset(){this._value=void 0,this._hasValue=!1,this._valuePromise=new Promise(e=>{this._resolve=e})}set(e){this._hasValue?this._valuePromise=Promise.resolve(e):(this._hasValue=!0,this._resolve(e)),this._value=e}getValuePromise(){return this._valuePromise}hasValue(){return this._hasValue}getValue(){return this._value}}class ke extends class{getConsentData(){}localStorageGrant(){}setStoredPrivacy(){}}{constructor(e,t,i,r,s){super(),d(this,"_consentDataHolder",void 0),d(this,"storedPrivacyData",void 0),d(this,"localStorage",void 0),d(this,"_forceAllowLocalStorageGrant",void 0),this._log=r,this.localStorage=e,this.storageConfig=t,this._consentDataHolder=new Ue,this._forceAllowLocalStorageGrant=i,this._metrics=s}isForceAllowLocalStorageGrant(){return this._forceAllowLocalStorageGrant}resetConsentData(e){this._consentDataHolder.reset(),this.storedPrivacyData=void 0,this._forceAllowLocalStorageGrant=e}localStorageGrant(){var e,t=0h(h({},e),{},{response:t,responseTimestamp:i}))}getStoredResponseV2(e){return this._getObject(this.storageConfig.ID5_V2.withNameSuffixed(e))}incNbV2(e){let i=1{var t=Math.max(0,N(null==e?void 0:e.nb)?Math.round(e.nb)+i:i);return h(h({},e),{},{nb:t})})}static storedDataMatchesCurrentData(e,t){return null==e||e===t}storedConsentDataMatchesConsentData(e){return Ve.storedDataMatchesCurrentData(this.getHashedConsentData(),e.hashCode())}getExtensions(){return this._getObject(this.storageConfig.EXTENSIONS)}storeExtensions(e,t){return this._updateObject(t,()=>e)}clearExtensions(){return this.clear(this.storageConfig.EXTENSIONS)}}class Ge{constructor(e,t,i){d(this,"_metrics",void 0),d(this,"_log",void 0),d(this,"_store",void 0),this._metrics=e,this._log=t,this._store=i}static getChunkUrl(e,t){return"https://d".concat(e,".eu-").concat(t,"-id5-sync.com")}submitExtensionCall(t,i){var e=2{if(e.ok)return r.record(this._metrics.extensionsCallTimer(i,!0)),e.json();r.record(this._metrics.extensionsCallTimer(i,!1));e="The call to get extensions at ".concat(t," was not ok, status: ").concat(e.status,", statusText: ").concat(e.statusText);return this._log.warn(e),Promise.reject(new Error(e))}).catch(e=>(r.record(this._metrics.extensionsCallTimer(i,!1)),this._log.warn("Got error from ".concat(t," endpoint"),e),{}))}gatherChunks(e,i){if(e){let t=ve();return Promise.all(Array.from({length:i.length},(e,t)=>{t=Ge.getChunkUrl(t,i.urlVersion);return fetch(t).then(e=>{if(e.ok)return e.text();throw new Error("The call to get ".concat(i.name," was not ok, status: ").concat(e.status,", statusText: ").concat(e.statusText))})})).then(e=>(t.record(this._metrics.extensionsCallTimer(i.name,!0)),{[i.name]:e,[i.name+"Version"]:"".concat(i.version)})).catch(e=>(t.record(this._metrics.extensionsCallTimer(i.name,!1)),this._log.warn("Got error when getting ".concat(i.name),e),{}))}return Promise.resolve({})}gather(e){var t=this._store.getCachedExtensions();if(void 0!==t)return Promise.resolve(t);let i=ve(),r=this._submitBounce(e);return this.submitExtensionCall("https://lb.eu-1-id5-sync.com/lb/v1","lb").then(e=>{var t=this.getChunksEnabled(e);return Promise.allSettled([Promise.resolve(e),this.gatherChunks(t,Ge.CHUNKS_CONFIGS.devChunks),this.gatherChunks(t,Ge.CHUNKS_CONFIGS.groupChunks),r])}).then(e=>{i.record(this._metrics.extensionsCallTimer("all",!0));let t=Ge.DEFAULT_RESPONSE;return e.forEach(e=>{e.value&&(t=h(h({},t),e.value))}),this._store.storeExtensions(t),t}).catch(e=>(i.record(this._metrics.extensionsCallTimer("all",!1)),this._log.error("Got error ".concat(e," when gathering extensions data")),Ge.DEFAULT_RESPONSE))}_submitBounce(e){return e.some(e=>{return F(null===(e=e.cacheData)||void 0===e?void 0:e.signature)})?Promise.resolve({}):this.submitExtensionCall("https://id5-sync.com/bounce","bounce",{credentials:"include"})}getChunksEnabled(e){e=null==e?void 0:e.chunks;return 0!==e&&e}}d(Ge,"CHUNKS_CONFIGS",Object.freeze({devChunks:{name:"devChunks",urlVersion:3,length:8,version:4},groupChunks:{name:"groupChunks",urlVersion:4,length:8,version:4}})),d(Ge,"DEFAULT_RESPONSE",{lbCDN:"%%LB_CDN%%"});const Me={createExtensions:function(e,t,i){return new Ge(e,t,i)}},je=Object.freeze({UNKNOWN:"unknown",LEADER:"leader",FOLLOWER:"follower"}),We=Object.freeze({MULTIPLEXING:"multiplexing",SINGLETON:"singleton"}),qe=Object.freeze({AWAITING_SCHEDULE:"awaiting_schedule",SKIPPED:"skipped",SCHEDULED:"scheduled",COMPLETED:"completed",CANCELED:"canceled"});class He{constructor(e,t,i){d(this,"properties",void 0),d(this,"knownState",void 0),d(this,"_joinTime",void 0),d(this,"_window",void 0),this.properties=e,this.knownState=t,this._window=i,this._joinTime=performance.now()}getId(){return this.properties.id}isMultiplexingPartyAllowed(){var e;return(null===(e=this.knownState)||void 0===e?void 0:e.operatingMode)===We.MULTIPLEXING}getInstanceMultiplexingLeader(){var e,t;if((null===(e=this.knownState)||void 0===e?void 0:e.operatingMode)===We.MULTIPLEXING)return null===(e=this.knownState)||void 0===e||null===(t=e.multiplexing)||void 0===t?void 0:t.leader}getWindow(){return this._window}}class Je{constructor(e){d(this,"_knownValues",[]),d(this,"_counter",void 0),this._counter=e}add(e){e&&-1===this._knownValues.indexOf(e)&&(this._counter.inc(),this._knownValues.push(e))}}class Be{constructor(e,t){d(this,"_instancesCounter",void 0),d(this,"_domainsCounter",void 0),d(this,"_windowsCounter",void 0),d(this,"_partnersCounter",void 0);var i=t.id;this._instancesCounter=e.instanceCounter(t.id),this._windowsCounter=new Je(e.instanceUniqWindowsCounter(i)),this._partnersCounter=new Je(e.instanceUniqPartnersCounter(i)),this._domainsCounter=new Je(e.instanceUniqueDomainsCounter(i))}addInstance(e){var t,i,r;this._instancesCounter.inc(),this._partnersCounter.add((null==e||null===(t=e.fetchIdData)||void 0===t?void 0:t.partnerId)|(null==e||null===(i=e.sourceConfiguration)||void 0===i||null===(r=i.options)||void 0===r?void 0:r.partnerId)),this._domainsCounter.add(null==e?void 0:e.domain),this._windowsCounter.add(null==e?void 0:e.href)}}class ze{constructor(e){d(this,"_scheduleTime",void 0),d(this,"_closeTime",void 0),d(this,"_timeoutId",void 0),d(this,"_state",qe.AWAITING_SCHEDULE),d(this,"_delayMs",void 0),d(this,"_instance",void 0),this._instance=e}schedule(e){const t=this;t._delayMs=e,this._timeoutId=setTimeout(()=>{t._timeoutId&&(t._timeoutId=void 0,t._instance._doElection(),t._closeWithState(qe.COMPLETED))},t._delayMs),t._state=qe.SCHEDULED,t._scheduleTime=performance.now()}skip(){this._closeWithState(qe.SKIPPED)}cancel(){this._timeoutId&&(clearTimeout(this._timeoutId),this._timeoutId=void 0),this._closeWithState(qe.CANCELED)}_closeWithState(e){this._state=e,this._closeTime=performance.now()}}class Ke{constructor(e,t,i,r,s,n,o){d(this,"properties",void 0),d(this,"_messenger",void 0),d(this,"_knownInstances",new Map),d(this,"_lastJoinedInstance",void 0),d(this,"role",void 0),d(this,"_leader",void 0),d(this,"_mode",void 0),d(this,"_metrics",void 0),d(this,"_logger",void 0),d(this,"_instanceCounters",void 0),d(this,"_election",void 0),d(this,"_window",void 0),d(this,"_storage",void 0),d(this,"_trueLinkAdapter",void 0),d(this,"_cachedIdProvider",void 0);var a=F(globalThis)&&F(globalThis.crypto)&&O(globalThis.crypto.randomUUID)?globalThis.crypto.randomUUID():"".concat(1e6*Math.random()|0);this.properties=u({id:a,version:"1.0.33",href:null===(a=e.location)||void 0===a?void 0:a.href,domain:null===(a=e.location)||void 0===a?void 0:a.hostname},t),this.role=je.UNKNOWN,this._metrics=r,this._instanceCounters=new Be(r,this.properties),this._loadTime=performance.now(),this._logger=new Ye(s,this),this._window=e,this._dispatcher=new be(this._logger),this._leader=new Fe,this._followerRole=new Te(this._window,this.properties,this._dispatcher,this._logger,this._metrics),this._election=new ze(this),this._storage=i,this._trueLinkAdapter=n,this._cachedIdProvider=new Oe("self",new X(o,n),this._logger,this._metrics)}updateConfig(e){u(this.properties,e)}init(){var e=0{setTimeout(()=>{var e=((null===(e=i._knownInstances)||void 0===e?void 0:e.size)||0)+1;r.summary("instance.partySize",{after:t,electionState:i._election._state}).record(e)},t)})}(r),r._messenger=new S(r.properties.id,s,r._logger,r._metrics),r._messenger.onAnyMessage((e,t)=>{var i=Date.now()-e.timestamp|0;r._metrics.instanceMsgDeliveryTimer({messageType:e.type,sameWindow:s===t}).record(i),r._logger.debug("Message received",e),r._doFireEvent(ye.ID5_MESSAGE_RECEIVED,e)}).onMessage(I.TYPE,(e,t)=>{let i=u(new I,e.payload);void 0===i.isResponse&&(i.isResponse=e.dst!==_),r._handleHelloMessage(i,e,t)}).onProxyMethodCall(new y(this._logger).registerTarget(C.LEADER,r._leader).registerTarget(C.FOLLOWER,r._followerRole).registerTarget(C.STORAGE,r._storage)),r._mode===We.SINGLETON?(r._election.skip(),r._onLeaderElected(r.properties)):r._mode===We.MULTIPLEXING&&r._election.schedule(e),r._messenger.broadcastMessage(r._createHelloMessage(!1),I.TYPE)}register(e){try{this.updateConfig(e),this.init()}catch(e){this._logger.error("Failed to register integration instance",e)}return this}_handleHelloMessage(e,t,i){this._joinInstance(e,t,i)}unregister(){this._logger.info("Unregistering"),this._messenger&&this._messenger.unregister()}on(e,t){return this._dispatcher.on(e,t),this}_joinInstance(e,t,i){var r=e.isResponse;const s=new He(e.instance,e.instanceState,i);this._knownInstances.get(s.getId())?this._logger.debug("Instance already known",s.getId()):(this._knownInstances.set(s.getId(),s),this._lastJoinedInstance=s,this._instanceCounters.addInstance(s.properties),this._metrics.instanceJoinDelayTimer({election:this._election._state}).record(performance.now()-this._loadTime|0),r?(r=s.getInstanceMultiplexingLeader(),this._mode===We.MULTIPLEXING&&this.role===je.UNKNOWN&&void 0!==r&&(this._logger.info("Joined late, elected leader is",r),this._election.cancel(),this._onLeaderElected(r))):(this._messenger.sendResponseMessage(t,this._createHelloMessage(!0),I.TYPE),this._mode===We.MULTIPLEXING&&this.role!==je.UNKNOWN&&this._handleLateJoiner(s)),this._logger.debug("Instance joined",s.getId()),this._doFireEvent(ye.ID5_INSTANCE_JOINED,s.properties))}_createHelloMessage(){var e,t=0e.properties)};return this._mode===We.MULTIPLEXING&&(i.multiplexing={role:this.role,electionState:null===(e=this._election)||void 0===e?void 0:e._state,leader:this._leader.getProperties()}),new I(this.properties,t,i)}_handleLateJoiner(e){this._logger.info("Late joiner detected",e.properties);var t=this._metrics.instanceLateJoinCounter(this.properties.id,{scope:"party"}).inc();this._metrics.instanceLateJoinDelayTimer({election:this._election._state,isFirst:1===t}).record(performance.now()-this._election._closeTime),!e.isMultiplexingPartyAllowed()||this.role!==je.LEADER||!0===(null==(e=this._leader.addFollower(new Pe(e,this._messenger,this._logger)))?void 0:e.lateJoiner)&&this._metrics.instanceLateJoinCounter(this.properties.id,{scope:"leader",unique:!0===(null==e?void 0:e.uniqueLateJoiner)}).inc()}_doFireEvent(e){for(var t=arguments.length,i=new Array(1o.localStorageGrant("client-store"),s,n,t),this._trueLinkAdapter),n=new Ce(i,t,Me.createExtensions(i,t,s));const a=new Ne(this._window,e,r,s,o,i,t,n);a.addFollower(this._followerRole),this._leader.assignLeader(a),this._mode===We.MULTIPLEXING&&Array.from(this._knownInstances.values()).filter(e=>e.isMultiplexingPartyAllowed()).map(e=>a.addFollower(new Pe(e,this._messenger,t))),a.start()}_followRemoteLeader(e){this._leader.assignLeader(new Le(this._messenger,e)),this._logger.info("Following remote leader ",e)}updateConsent(e){this._leader.updateConsent(e,this.properties.id)}updateFetchIdData(e){this._leader.updateFetchIdData(this.properties.id,e),u(this.properties.fetchIdData,e)}refreshUid(e){this._leader.refreshUid(e,this.properties.id)}_doElection(){var e=this._election;const t=this._knownInstances;let i=Array.from(t.values()).filter(e=>e.isMultiplexingPartyAllowed()).map(e=>e.properties);i.push(this.properties),this._onLeaderElected(function(e){if(!e||0===e.length)return;e=e.sort((e,t)=>{let i=-(0|b(e.version,t.version));var r,s,n;return 0===i&&(i=e.source.localeCompare(t.source),0===i&&(i=-(0|b(e.sourceVersion,t.sourceVersion))),0===i&&(s=(null===(s=e.fetchIdData)||void 0===s||null===(r=s.refererInfo)||void 0===r?void 0:r.numIframes)||Number.MAX_SAFE_INTEGER,n=(null===(r=t.fetchIdData)||void 0===r||null===(n=r.refererInfo)||void 0===n?void 0:n.numIframes)||Number.MAX_SAFE_INTEGER,i=s-n),0===i&&(i=e.id.localeCompare(t.id))),i});return e[0]}(i));var r=this._lastJoinedInstance;r&&this._metrics.instanceLastJoinDelayTimer().record(Math.max(r._joinTime-e._scheduleTime,0))}_onLeaderElected(e){var t=this;t.role=e.id===t.properties.id?je.LEADER:je.FOLLOWER,t.role===je.LEADER?t._actAsLeader():t.role===je.FOLLOWER&&t._followRemoteLeader(e),t._logger.debug("Leader elected",e.id,"my role",t.role),t._doFireEvent(ye.ID5_LEADER_ELECTED,t.role,t._leader.getProperties())}getId(){return this.properties.id}lookupForCachedId(){return this._logger.info("Self lookup for cachedId triggered"),this._cachedIdProvider.provisionFromCache(this._followerRole)}}class Ye extends e{constructor(e,t){super(),d(this,"_instance",void 0),this._delegate=e||g,this._instance=t}_prefix(){return"Instance(id=".concat(this._instance.getId(),", role=").concat(this._instance.role,")")}debug(){for(var e=arguments.length,t=new Array(e),i=0;inull!=e&&"object"==typeof e;const vt=(ae=window,function(){try{var i=ft(),r=i.length-1,s=null!==i[r].location||0{var e=i("ping",function(e){t(e)});e&&t(e)});switch(s.gppVersion){case St.version:return new St(s,i,r);case Dt.version:return new Dt(s,i,r);default:var n="Unsupported version of gpp: ".concat(s.gppVersion);return a.warn(n),Promise.reject(n)}})()}static tcfDataHasLocalStorageGrant(e){e=i(wt,wt,yt).call(wt,e,"PurposeConsent","PurposeConsents");return ct(e)&&!0===e[0]}static tcfDataHasID5VendorConsented(e){let t=i(wt,wt,yt).call(wt,e,"VendorConsent","VendorConsents");return void 0!==(null===t||void 0===t?void 0:t.find(e=>"131"==e))}static getTcfData(e){e=null==e?void 0:e.tcfeuv2;let t=void 0;return ct(e)&&dt(e[0])?t=e[0]:dt(e)&&(t=e),t}}function yt(e,t,i){return t in e?e[t]:e[i]}class St extends wt{constructor(e,t,i){super(i,St.version),d(this,"gppFn",void 0),d(this,"ready",void 0),this.gppFn=t,this.ready=this.isReady(e)}isReady(e){return"loaded"===e.cmpStatus&&"visible"!==e.cmpDisplayStatus}getClientConsentData(){var r=this;return s(function*(){r.ready||(r.ready=yield new Promise(t=>{r.gppFn("addEventListener",e=>!!r.isReady(e.pingData)&&void t(!0))}));var e=new Promise(t=>{r.gppFn("getGPPData",e=>{t(e)})}),t=new Promise(t=>{r.gppFn("getSection",e=>{t(e)},"tcfeuv2")}),e=l(yield Promise.all([e,t]),2),t=e[0],e=e[1];const i=new q;return i.version=W.GPP_V1_0,i.gppString=t.gppString,i.applicableSections=t.applicableSections,e&&(i.localStoragePurposeConsent=wt.tcfDataHasLocalStorageGrant(e),i.vendorsConsentForId5Granted=wt.tcfDataHasID5VendorConsented(e)),i})()}}function bt(e,t,i){i&&(e.apiTypes.push(t),u(e,i))}d(St,"version","1.0");class Dt extends wt{constructor(e,t,i){super(i,Dt.version),d(this,"gppFn",void 0),d(this,"readyPingData",void 0),this.gppFn=t,"ready"===e.signalStatus&&(this.readyPingData=e)}getClientConsentData(){var i=this;return s(function*(){return new Promise(t=>{i.readyPingData?t(i.parsePingData(i.readyPingData)):i.gppFn("addEventListener",e=>"ready"===e.pingData.signalStatus&&void t(i.parsePingData(e.pingData)))})})()}parsePingData(e){const t=new q;t.gppString=e.gppString,t.version=W.GPP_V1_1,t.applicableSections=e.applicableSections;e=wt.getTcfData(e.parsedSections);return e&&(t.localStoragePurposeConsent=wt.tcfDataHasLocalStorageGrant(e),t.vendorsConsentForId5Granted=wt.tcfDataHasID5VendorConsented(e)),t}}d(Dt,"version","1.1");class Et{constructor(e){var t=1{r._lookupInProgress=!1})),this._consentDataPromise}_lookupConsentData(e,t,i){if(e){this._log.warn("cmpApi: ID5 is operating in forced consent mode and will not retrieve any consent signals from the CMP");let e=new H;return e.forcedGrantByConfig=!0,e.source=M.partner,Promise.resolve(e)}switch(t){case"static":return new Promise(e=>{this._parseStaticConsentData(i,e)});case"iab":return new Promise(e=>{this._lookupIabConsent(e)});default:return this._log.error("cmpApi: Unknown consent API: ".concat(t)),Promise.reject(new Error("Unknown consent API: ".concat(t)))}}_parseStaticConsentData(e,t){e=e||{};let i=new H;if(i.source=M.partner,dt(e.getTCData)){const r=this._parseTcfData(e.getTCData);bt(i,W.TCF_V2,r);try{const s=this._metrics;this._lookupTcf(e=>{s.consentDiscrepancyCounter({apiType:W.TCF_V2,sameString:(null==e?void 0:e.consentString)===(null===r||void 0===r?void 0:r.consentString),sameLSPC:(null==e?void 0:e.localStoragePurposeConsent)===(null===r||void 0===r?void 0:r.localStoragePurposeConsent),sameVendorsConsentForId5Granted:(null==e?void 0:e.vendorsConsentForId5Granted)===(null===r||void 0===r?void 0:r.vendorsConsentForId5Granted),sameGdpr:(null==e?void 0:e.gdprApplies)===(null===r||void 0===r?void 0:r.gdprApplies)}).inc()})}catch(e){}}if(ct(e.allowedVendors)&&bt(i,W.ID5_ALLOWED_VENDORS,{allowedVendors:e.allowedVendors.map(e=>e.toString()),gdprApplies:!0}),dt(e.getUSPData)){const n=this._parseUspData(e.getUSPData);bt(i,W.USP_V1,n);try{const o=this._metrics;this._lookupUsp(e=>{o.consentDiscrepancyCounter({apiType:W.USP_V1,sameString:(null==e?void 0:e.ccpaString)===(null===n||void 0===n?void 0:n.ccpaString)}).inc()})}catch(e){}}0===i.apiTypes.length&&this._log.warn("cmpApi: No static consent data detected! Using defaults."),this._log.info("cmpApi: Detected APIs '".concat(i.apiTypes,"' from static consent data"),e),t(i)}_lookupIabConsent(r){const s=[];let n=new H;n.source=M.cmp;var e=i=>(s[i]=0,(e,t)=>{s[i]||(s[i]=Date.now(),e&&bt(n,t,e),s.every(e=>0{t?i(this._parseUspData(e),W.USP_V1):(this._log.error("cmpApi: USP callback not successful. Using defaults for CCPA."),i())})}_lookupGpp(n){var o=this;return s(function*(){var t=Date.now();try{let e=yield wt.create(o._log);if(e){var i={gppVersion:e.version,directCmp:e.direct};try{var r=yield e.getConsentData();n({gppData:r},r.version);var s=Date.now();o._metrics.timer("gpp.delay",i).record(s-t)}catch(e){o._metrics.counter("gpp.failure",u({type:"CONSENT"},i)).inc(),o._log.error("cmpApi: getting GPP consent not successful. Using defaults for Gpp."),n()}}else n()}catch(e){o._metrics.counter("gpp.failure",{type:"CLIENT"}).inc(),o._log.error("cmpApi: creating GPP client not successful. Using defaults for Gpp."),n()}})()}static _buildCmpSurrogate(a,c){return(e,t,i)=>{const r=Math.random()+"",s={},n={};n[a.objKeys[0]]=e,n[a.objKeys[1]]=t,n.callId=r,s[a.objName]=n;const o=e=>{e=pt(e,"data.".concat(a.returnObjName));e&&e.callId===r&&(void 0!==(e=i(e.returnValue,e.success))&&!0!==e||window.removeEventListener("message",o))};window.addEventListener("message",o,!1),c.postMessage(s,"*")}}_lookupTcf(e){var t=Et._findTCF(),i=t.cmpFrame,t=t.cmpFunction;if(!i)return this._log.warn("cmpApi: TCF not found! Using defaults for GDPR."),void e();ot(t)?this._lookupDirectTcf(t,e):(this._log.info("cmpApi: Detected TCF is outside the current iframe. Using message passing."),this._lookupMessageTcf(i,e))}_lookupMessageTcf(e,t){e=Et._buildCmpSurrogate(It.tcfv2,e);this._lookupDirectTcf(e,t)}_lookupDirectTcf(e,s){const n=this._log;e("addEventListener",2,(e,t)=>{var i,r;return i="event",r=e,n.info("cmpApi: TCFv2 - Received a call back: ".concat(i),r),t?!(!e||!1!==e.gdprApplies&&"tcloaded"!==e.eventStatus&&"useractioncomplete"!==e.eventStatus)&&void s(this._parseTcfData(e),W.TCF_V2):(n.error("cmpApi: TCFv2 - Received insuccess: ".concat("addEventListener",". Please check your CMP setup. Using defaults for GDPR.")),void s())})}_parseUspData(e){if(dt(e)&&at(e.uspString))return{ccpaString:e.uspString};this._log.error("cmpApi: No or malformed USP data. Using defaults for CCPA.")}_parseTcfData(e){let t=this._log,i,r;if(i=Et._isValidV2ConsentObject,r=Et._normalizeV2Data,i(e))return r(e);t.error("cmpApi: Invalid CMP data. Using defaults for GDPR.",e)}static _isValidV2ConsentObject(e){var t=e&&e.gdprApplies,e=e&&e.tcString;return!1===t||at(e)}static _tcfDataHasID5VendorConsented(e){var t,i;return!0===(null==e||null===(t=e.vendor)||void 0===t||null===(i=t.consents)||void 0===i?void 0:i[131])}static _normalizeV2Data(e){let t=pt(e,"purpose.consents.1");ht(t)||(t=function(e,t){var i=152+t-1,t=~~(i/6);if(e&&"C"===e.charAt(0)&&!(e.length<=t)){t=e.charAt(t),t=mt[t];if(void 0!==t)return 0!=(t&1<<6-i%6-1)}}(e.tcString,1));var i=Et._tcfDataHasID5VendorConsented(e);return{consentString:e.tcString,localStoragePurposeConsent:t,gdprApplies:e.gdprApplies,vendorsConsentForId5Granted:i}}static _findTCF(){let e=window,t,i;for(;!t;){try{if("function"==typeof e.__tcfapi){i=e.__tcfapi,t=e;break}}catch(e){}try{if(e.frames.__tcfapiLocator){t=e;break}}catch(e){}if(e===window.top)break;e=e.parent}return{cmpFrame:t,cmpFunction:i}}static _findCmpApi(e){let t=window,i,r;for(;!i;){try{if("function"==typeof t[e]){r=t[e],i=t;break}}catch(e){}try{if(t.frames["".concat(e,"Locator")]){i=t;break}}catch(e){}if(t===window.top)break;t=t.parent}return{cmpApiFrame:i,cmpApiFunction:r}}}const Tt="1.0.76";class At{static gatherUaHints(e,t){return s(function*(){if(F(window.navigator.userAgentData)&&!e){let e;try{e=yield window.navigator.userAgentData.getHighEntropyValues(["architecture","fullVersionList","model","platformVersion"])}catch(e){return void t.error("Error while calling navigator.userAgentData.getHighEntropyValues()",e)}return At.filterUaHints(e)}})()}static filterUaHints(e){if(F(e)){const t=/[()-.:;=?_/]/g;return x(e.brands)&&(e.brands=e.brands.filter(e=>R(e.brand)&&e.brand.search(t)<0)),x(e.fullVersionList)&&(e.fullVersionList=e.fullVersionList.filter(e=>R(e.brand)&&e.brand.search(t)<0)),e}}}const Pt=Object.freeze({NEVER:"never",AFTER_UID_SET:"after-uid-set",ASAP:"asap"}),Ot=Object.freeze({allowGCReclaim:Object.values(Pt)});class Rt{constructor(e){var t=1{this.options[e]=t,this.providedOptions[e]=t};Object.keys(a).forEach(e=>{if("segments"===e){const r=a[e],s=[];F(r)&&(ct(r)?(r.forEach((e,t)=>{t="segments[".concat(t,"]");return ct(e.ids)&&function(e,t){let i=!0;return U(e,e=>i=i&&t(e)),i}(e.ids,at)?e.ids.length<1?(l.error("Config option ".concat(t,".ids should contain at least one segment ID")),void(c.invalidSegments+=1)):at(e.destination)?void s.push(e):(xt(l,"".concat(t,".destination"),"String",e.destination),void(c.invalidSegments+=1)):(xt(l,"".concat(t,".ids"),"Array of String",e.ids),void(c.invalidSegments+=1))}),d(e,s)):xt(l,e,"Array",r))}else if("diagnostics"===e){const n=this.options.diagnostics,o=a.diagnostics;if(nt(o,Rt.configTypes.diagnostics)){let t=h({},n);Object.keys(o).forEach(e=>{void 0!==n[e]&&typeof n[e]==typeof o[e]&&(t[e]=o[e])}),this.options[e]=t}this.providedOptions[e]=a[e]}else{var t,i;void 0!==Ot[e]?(i=a[e])&&Ot[e].includes(i)&&d(e,i):"partnerId"!==e&&(t=Rt.configTypes[e],F(i=a[e])&&(nt(i,t)?d(e,i):xt(l,e,t,i)))}})}else l.error("Config options must be an object")}setPartnerId(e){let t;if(at(e)){if(t=parseInt(e),isNaN(t)||t<0)throw new Error("partnerId is required and must parse to a positive integer")}else lt(e)&&(t=e);if(lt(t)){if(lt(this.options.partnerId)&&t!==this.options.partnerId)throw new Error("Cannot update config with a different partnerId");this.options.partnerId=t,this.providedOptions.partnerId=e}}}function xt(e,t,i,r){e.error("Config option ".concat(t," must be of type ").concat(i," but was ").concat(toString.call(r),". Ignoring..."))}d(Rt,"configTypes",{debugBypassConsent:"Boolean",allowLocalStorageWithoutConsentApi:"Boolean",cmpApi:"String",consentData:"Object",refreshInSeconds:"Number",partnerUserId:"String",callbackOnAvailable:"Function",callbackOnUpdates:"Function",callbackTimeoutInMs:"Number",pd:"String",abTesting:"Object",provider:"String",maxCascades:"Number",applyCreativeRestrictions:"Boolean",acr:"Boolean",disableUaHints:"Boolean",storageExpirationDays:"Number",att:"Number",diagnostics:"Object",multiplexing:"Object",dynamicConfig:"Object",allowGCReclaim:"String"});class Nt{constructor(e,t,i,r,s,n,o){d(this,"_called",void 0),d(this,"_callbackFn",void 0),d(this,"_callbackArgs",void 0),d(this,"_beforeTrigger",void 0),d(this,"_watchdog",void 0),d(this,"_log",void 0),d(this,"_metrics",void 0),d(this,"_callbackName",void 0),this._callbackName=e,this._log=t,this._metrics=i,this._callbackFn=r;for(var a=arguments.length,c=new Array(7this._trigger("immediate"),0):0this._trigger("timeout"),s))}_trigger(){let e=0{this._log.debug("Firing ".concat(this._callbackName," callback after ").concat(t,"ms. Triggered by ").concat(e,", configured timeoutMs=").concat(this._timeout)),this._beforeTrigger(),this._callbackFn.call(globalThis,...this._callbackArgs)},0))}triggerNow(){var e=0{try{ut(e)&&ot(e.unregister)&&e.unregister()}catch(e){}})}}globalThis.__id5_finalization_registry||(globalThis.__id5_finalization_registry=new class{constructor(){d(this,"_finalizationRegistry",void 0),d(this,"_instancesHolder",void 0),this._instancesHolder=new Set;try{this._finalizationRegistry=new FinalizationRegistry(e=>{try{ut(e)&&ot(e.unregister)&&e.unregister("gc-reclaim")}catch(e){}})}catch(e){}}register(e){try{e.getOptions().allowGCReclaim!==Pt.ASAP&&this._instancesHolder.add(e),this._finalizationRegistry.register(e,e._unregisterTargets,e)}catch(e){}}unregister(e){try{this.releaseInstance(e,!0),this._finalizationRegistry.unregister(e)}catch(e){}}releaseInstance(e){var t=1{},this),this}onUpdate(e){if(!ot(e))throw new Error("onUpdate expects a function");return this._updateCallback=e,this._userIdAvailable&&this._fireOnUpdate(),this}onRefresh(e,t){if(!ot(e))throw new Error("onRefresh expects a function");this._refreshCallback&&this._refreshCallback.disableWatchdog();var i=!0===this._isRefreshing&&!1===this._isRefreshingWithFetch&&this._userIdAvailable;return this._refreshCallback=new Nt("onRefresh",this._log,this._metrics,e,t,i,()=>{this._isRefreshing=!1,this._isRefreshingWithFetch=!1},this),this}unregister(){try{this._unregisterTargets.unregister("api-call"),Ut.unregister(this)}catch(e){}}collectEvent(t,i){const r=e=>{e=new Request("https://id5-sync.com/event",{method:"POST",mode:"no-cors",body:JSON.stringify({partnerId:this.config.getOptions().partnerId,id5id:e,eventType:t,metadata:i})});return this._log.info("Sending event",e),fetch(e).catch(e=>this._log.error("Error while sending event to ID5 of type "+t,e))};return this._userIdAvailable?r(this._userId):this._userIdAvailablePromise.then(e=>r(e))}constructor(e,t,i,r,s,n,o,a,c,l){d(this,"_availableCallback",void 0),d(this,"_updateCallback",void 0),d(this,"_refreshCallback",void 0),d(this,"_isExposed",void 0),d(this,"_fromCache",void 0),d(this,"_isRefreshing",!1),d(this,"_isRefreshingWithFetch",!1),d(this,"_userId",void 0),d(this,"_ext",void 0),d(this,"_userIdAvailable",!1),d(this,"_userIdAvailablePromise",void 0),d(this,"_userIdAvailablePromiseResolver",void 0),d(this,"invocationId",void 0),d(this,"config",void 0),d(this,"clientStore",void 0),d(this,"consentManagement",void 0),d(this,"_consentDataProvider",void 0),d(this,"_metrics",void 0),d(this,"_log",void 0),d(this,"_multiplexingInstance",void 0),d(this,"_pageLevelInfo",void 0),d(this,"_trueLinkAdapter",void 0),d(this,"_publisherTrueLinkId",void 0),d(this,"_gpId",void 0),d(this,"_origin",void 0),this.config=e,this.clientStore=t,this.consentManagement=i,this._metrics=r,this._consentDataProvider=s,this._log=new p("Id5Instance:",n),this._multiplexingInstance=o,this._userIdAvailablePromise=new Promise(e=>{this._userIdAvailablePromiseResolver=e}),this._pageLevelInfo=a,this._unregisterTargets=new Ft(this._multiplexingInstance,this._metrics),this._trueLinkAdapter=c,this._origin=l||"api",Ut.register(this)}bootstrap(){const n=ve();var e=this.config.getOptions();const o=this._ref();this._multiplexingInstance.on(we.CASCADE_NEEDED,e=>{const t=o.deref();t&&t._doCascade(e)}).on(we.USER_ID_READY,(e,t)=>{const i=o.deref();if(i){try{var r=null!=t&&t.tags?h({},t.tags):{};const s=i._metrics;null!=t&&t.timestamp&&s.userIdNotificationDeliveryDelayTimer(r).record(Date.now()-t.timestamp),n.record(s.userIdProvisioningDelayTimer(e.isFromCache,h(h({},r),{},{isUpdate:i._userIdAvailable,hasOnAvailable:void 0!==i._availableCallback,hasOnRefresh:void 0!==i._refreshCallback,hasOnUpdate:void 0!==i._updateCallback,provisioner:(null==t?void 0:t.provisioner)||"leader",hasChanged:i._userId!==e.responseObj.universal_uid})))}catch(e){i._log.error("Failed to measure provisioning metrics",e)}i._setUserId(e.responseObj,e.isFromCache,e.willBeRefreshed)}}).on(we.USER_ID_FETCH_CANCELED,e=>{const t=o.deref();t&&t._log.info("ID5 User ID fetch canceled:",e.reason)}),this._log.info("bootstrapped for partner ".concat(e.partnerId," with referer ").concat(this._refererInfo," and options"),this.getProvidedOptions())}firstFetch(){const i=this.config.getOptions(),e=this._gatherFetchIdData().then(e=>{var t;this._multiplexingInstance.register({source:this._origin,sourceVersion:Tt,sourceConfiguration:{options:i},fetchIdData:e,singletonMode:!0===(null===i||void 0===i||null===(t=i.multiplexing)||void 0===t?void 0:t._disabled),canDoCascade:!this.config.hasCreativeRestrictions(),forceAllowLocalStorageGrant:this.consentManagement.isForceAllowLocalStorageGrant(),storageExpirationDays:i.storageExpirationDays})}),t=this._submitRefreshConsent().then(e=>{e&&this.consentManagement.setConsentData(e)});return e.then(()=>{this._multiplexingInstance.lookupForCachedId().provisioned||(this._log.info("Couldn't find cached userId. Will try again when consent is resolved"),t.then(()=>{this._log.info("Consent resolved. Looking for cached id again"),this._multiplexingInstance.lookupForCachedId()}))}),Promise.allSettled([e,t])}refreshId(t,e){let i,r;this._log.info("ID refresh requested (force=".concat(t,") with additional options "),e);try{this._isRefreshing=!0,this._isRefreshingWithFetch=t,this.config.updOptions(e);var s=this.config.getOptions();const n=s.allowLocalStorageWithoutConsentApi||s.debugBypassConsent;i=this._gatherFetchIdData().then(e=>{this._multiplexingInstance.updateFetchIdData(e),this._multiplexingInstance.refreshUid({resetConsent:!0,forceAllowLocalStorageGrant:n,forceFetch:t}),r=this._submitRefreshConsent()}),this._metrics.refreshCallCounter("public-api").inc()}catch(e){return this._log.error("Exception caught from refreshId()",e),Promise.reject(e)}return Promise.allSettled([i,r])}_doCascade(e){var t,i=this.config.getOptions();if(e.partnerId===i.partnerId&&0<=i.maxCascades&&!this.config.hasCreativeRestrictions()){var r=i.partnerUserId&&0s[e]=!0),t.record(n._metrics.consentRequestTimer(i,h({success:!0},s))),n._multiplexingInstance.updateConsent(r)}catch(e){n._log.error("Couldn't get consent data",e),t.record(n._metrics.consentRequestTimer(i,{success:!1,error:e.message}))}return r})()}_setUserId(e,t){var i=2= 0 and <= 1");break;case"control":this._isExposed=!1,this._log.info("User is in control group!")}var s=this._userId!==r||!1===function e(t,i){if(!_t(t)||!_t(i))return t===i;var r=Object.keys(t),s=Object.keys(i);if(r.length!==s.length)return!1;for(var n=0,o=r;n{ot(this._updateCallback)&&(this._log.debug("Firing onUpdate"),this._updateCallback(this))},0)}localStorageGrant(){return this.clientStore.localStorageGrant()}}class Gt{isBooted(){return L(window.id5Bootstrap)}getTrueLink(){return this.isBooted()?window.id5Bootstrap.getTrueLinkInfo():{booted:!1}}setPrivacy(e){this.isBooted()&&window.id5Bootstrap.setPrivacy&&window.id5Bootstrap.setPrivacy(e)}clearPrivacy(){this.setPrivacy(void 0)}}class Mt{set debug(e){e=e,et=!!e}get debug(){return it()}constructor(){var e=0u.localStorageGrant(),s,d.storageConfig,t);var o=new Gt,a=Xe.createInstance(window,t,h,r,o,g),c=new Et(h,t),l=new Lt(this._referer,this._version,this._isUsingCdn);const p=new Vt(d,g,u,h,c,t,a,l,o,this.origin);return p.bootstrap(),p.firstFetch(),g.scheduleGC(h),p}catch(e){t.error("Exception caught during init()",e)}}refreshId(e){var t=1new ne(o,{sampling:n}).publish(e,t):e=>e,null!=s&&s.publishAfterLoadInMsec&&0