authentikate/node_modules/search-insights/dist/search-insights.iife.min.js
2025-08-04 18:41:00 -04:00

2 lines
12 KiB
JavaScript

var AlgoliaAnalytics=function(e){"use strict";var t="2.17.3";function s(e){return e.reduce(function(e,t){var n=e.events,e=e.additionalParams;return"index"in t?{additionalParams:e,events:n.concat([t])}:{events:n,additionalParams:t}},{events:[],additionalParams:void 0})}function n(){try{return Boolean(navigator.cookieEnabled)}catch(e){return}}function i(){}i.get=function(e){var t=null==(t=this.store)?void 0:t.getItem(e);if(!t)return null;try{return JSON.parse(t)}catch(e){return null}},i.set=function(t,e){var n;try{null!=(n=this.store)&&n.setItem(t,JSON.stringify(e))}catch(e){console.error("Unable to set "+t+" in localStorage, storage may be full.")}},i.remove=function(e){var t;null!=(t=this.store)&&t.removeItem(e)},i.store=function(){try{var e="__test_localStorage__";return globalThis.localStorage.setItem(e,e),globalThis.localStorage.removeItem(e),globalThis.localStorage}catch(e){}}();var r="AlgoliaObjectQueryCache",o=5e3,a=1e3;function v(){var e;return null!=(e=i.get(r))?e:{}}function g(e){i.set(r,(e=e,Object.keys(e).length>o?function(e){e=Object.entries(e).sort(function(e,t){e=e[1][1];return t[1][1]-e});return e.slice(0,e.length-a-1).reduce(function(e,t){var n=t[0],t=t[1];return Object.assign(Object.assign({},e),((e={})[n]=t,e))},{})}(e):e))}function p(e,t){return e+"_"+t}function u(e,t,n){var i=v();i[p(e,t)]=[n,Date.now()],g(i)}function b(e){return void 0===e}function c(e){return"number"==typeof e}function h(e){return"function"==typeof e}function k(e){return"function"==typeof(null==e?void 0:e.then)}function l(e){var n,i,t=e.AlgoliaAnalyticsObject;t&&(i=this,n=function(e){for(var t=[],n=arguments.length-1;0<n--;)t[n]=arguments[n+1];if(e&&h(i[e]))return i[e].apply(i,t);console.warn("The method `"+e+"` doesn't exist.")},(e=e[t]).queue=e.queue||[],(t=e.queue).forEach(function(e){var e=[].slice.call(e),t=e[0],e=e.slice(1);n.apply(void 0,[t].concat(e))}),t.push=function(e){var e=[].slice.call(e),t=e[0],e=e.slice(1);n.apply(void 0,[t].concat(e))})}var d=["insights-js ("+t+")","insights-js-browser-iife ("+t+")"];function y(e,t){var n={};for(r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function T(e){return e.map(function(r){var o,e;return(e=r).queryID||"conversion"!==e.eventType||(o=[],e=null==(e=r.objectIDs)?void 0:e.map(function(e,t){var n,i=null==(i=r.objectData)?void 0:i[t];return null!=i&&i.queryID?i:((n=(null!==(t=r.index,n=e,t=v()[p(t,n)])&&void 0!==t?t:[])[0])&&o.push(e),Object.assign(Object.assign({},i),{queryID:n}))}),0===o.length)?r:Object.assign(Object.assign({},r),{objectData:e,objectIDsWithInferredQueryID:o})})}function f(f){return function(e,t){var i=this;if(this._userHasOptedOut)return Promise.resolve(!1);if(!(!b(this._apiKey)&&!b(this._appId)||(null==(d=null==t?void 0:t.headers)?void 0:d["X-Algolia-Application-Id"])&&(null==(d=null==t?void 0:t.headers)?void 0:d["X-Algolia-API-Key"])))throw new Error("Before calling any methods on the analytics, you first need to call the 'init' function with appId and apiKey parameters or provide custom credentials in additional parameters.");!this._userToken&&this._anonymousUserToken&&this.setAnonymousUserToken(!0);var n,r,o,s,a,u,c,h,l,d=(null!=t&&t.inferQueryID?T(e):e).map(function(e){var t=e.filters,n=y(e,["filters"]),e=Object.assign(Object.assign({},n),{userToken:null!=(n=null==e?void 0:e.userToken)?n:i._userToken,authenticatedUserToken:null!=(n=null==e?void 0:e.authenticatedUserToken)?n:i._authenticatedUserToken});return b(t)||(e.filters=t.map(encodeURIComponent)),e});return 0===d.length?Promise.resolve(!1):(e=f,n=this._ua,r=this._endpointOrigin,o=d,s=this._appId,a=this._apiKey,t=null==t?void 0:t.headers,u=(t=void 0===t?{}:t)["X-Algolia-Application-Id"],c=t["X-Algolia-API-Key"],t=y(t,["X-Algolia-Application-Id","X-Algolia-API-Key"]),h=Object.assign({"X-Algolia-Application-Id":null!=u?u:s,"X-Algolia-API-Key":null!=c?c:a,"X-Algolia-Agent":encodeURIComponent(n.join("; "))},t),u=Object.keys(h).map(function(e){return e+"="+h[e]}).join("&"),s=e(r+"/1/events?"+u,{events:o}),k(s)?s.then((l=d,function(e){return e&&l.filter(function(e){var t=e.eventType,n=e.eventSubtype,e=e.objectIDs;return"conversion"===t&&"purchase"===n&&(null==e?void 0:e.length)}).forEach(function(e){var t,n,i=e.index,e=e.objectIDs;return t=i,i=e,n=v(),i.forEach(function(e){delete n[p(t,e)]}),void g(n)}),e})):s)}}function _(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function O(e,t,n){var i=new Date,n=(i.setTime(i.getTime()+n),"expires="+i.toUTCString());document.cookie=e+"="+t+";"+n+";path=/"}function m(e){for(var t=e+"=",n=document.cookie.split(";"),i=0;i<n.length;i++){for(var r=n[i];" "===r.charAt(0);)r=r.substring(1);if(0===r.indexOf(t))return r.substring(t.length,r.length)}return""}var j="_ALGOLIA",x=2592e6;function I(t,e){return e.map(function(e){return Object.assign({eventType:t},e)})}function A(t,n,e){return e.map(function(e){return Object.assign({eventType:t,eventSubtype:n},e)})}var U=["de","us"];function D(e){if(!b((e=void 0===e?{}:e).region)&&-1===U.indexOf(e.region))throw new Error("optional region is incorrect, please provide either one of: "+U.join(", ")+".");if(!(b(e.cookieDuration)||c(e.cookieDuration)&&isFinite(e.cookieDuration)&&Math.floor(e.cookieDuration)===e.cookieDuration))throw new Error("optional cookieDuration is incorrect, expected an integer.");var t=this,n=e,i={_userHasOptedOut:Boolean(e.userHasOptedOut),_region:e.region,_host:e.host,_anonymousUserToken:null==(i=e.anonymousUserToken)||i,_useCookie:null!=(i=e.useCookie)&&i,_cookieDuration:e.cookieDuration||6*x},r=n.partial,o=y(n,["partial"]);r||Object.assign(t,i),Object.assign(t,Object.keys(o).reduce(function(e,t){return Object.assign(Object.assign({},e),((e={})["_"+t]=o[t],e))},{})),this._endpointOrigin=this._host||(this._region?"https://insights."+this._region+".algolia.io":"https://insights.algolia.io"),this._ua=[].concat(d),e.authenticatedUserToken&&this.setAuthenticatedUserToken(e.authenticatedUserToken),e.userToken?this.setUserToken(e.userToken):this._userToken||this._userHasOptedOut||!this._useCookie?void 0!==(n=this)._userToken&&function(e){return"number"!=typeof e&&0===e.indexOf("anonymous-")}(n._userToken)&&n._useCookie&&!n._userHasOptedOut&&this.saveTokenAsCookie():this.setAnonymousUserToken()}function C(e){e=e.requestFn,this._endpointOrigin="https://insights.algolia.io",this._anonymousUserToken=!0,this._userHasOptedOut=!1,this._useCookie=!1,this._cookieDuration=6*x,this._ua=[],this.version=t,this.sendEvents=f(e).bind(this),this.init=D.bind(this),this.addAlgoliaAgent=function(e){-1===this._ua.indexOf(e)&&this._ua.push(e)}.bind(this),this.saveTokenAsCookie=function(){var e=m(j);!this._userToken||e&&""!==e&&0===e.indexOf("anonymous-")||O(j,this._userToken,this._cookieDuration)}.bind(this),this.setUserToken=function(e){return this._userToken=e,h(this._onUserTokenChangeCallback)&&this._onUserTokenChangeCallback(this._userToken),this._userToken}.bind(this),this.setAnonymousUserToken=function(e){(e=void 0!==e&&e)?this.setUserToken("anonymous-"+_()):n()&&((e=m(j))&&""!==e&&0===e.indexOf("anonymous-")?this.setUserToken(e):(e=this.setUserToken("anonymous-"+_()),O(j,e,this._cookieDuration)))}.bind(this),this.getUserToken=function(e,t){return h(t)&&t(null,this._userToken),this._userToken}.bind(this),this.onUserTokenChange=function(e,t){this._onUserTokenChangeCallback=e,t&&t.immediate&&h(this._onUserTokenChangeCallback)&&this._onUserTokenChangeCallback(this._userToken)}.bind(this),this.setAuthenticatedUserToken=function(e){return this._authenticatedUserToken=e,h(this._onAuthenticatedUserTokenChangeCallback)&&this._onAuthenticatedUserTokenChangeCallback(this._authenticatedUserToken),this._authenticatedUserToken}.bind(this),this.getAuthenticatedUserToken=function(e,t){return h(t)&&t(null,this._authenticatedUserToken),this._authenticatedUserToken}.bind(this),this.onAuthenticatedUserTokenChange=function(e,t){this._onAuthenticatedUserTokenChangeCallback=e,t&&t.immediate&&h(this._onAuthenticatedUserTokenChangeCallback)&&this._onAuthenticatedUserTokenChangeCallback(this._authenticatedUserToken)}.bind(this),this.clickedObjectIDsAfterSearch=function(){for(var i=this,e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(r=s(e)).events,r=r.additionalParams;return n.forEach(function(e){var t=e.index,n=e.queryID;return e.objectIDs.forEach(function(e){return!i._userHasOptedOut&&u(t,e,n)})}),this.sendEvents(I("click",n),r)}.bind(this),this.clickedObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(I("click",n),i)}.bind(this),this.clickedFilters=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(I("click",n),i)}.bind(this),this.convertedObjectIDsAfterSearch=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(I("conversion",n),i)}.bind(this),this.purchasedObjectIDsAfterSearch=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(A("conversion","purchase",n),i)}.bind(this),this.addedToCartObjectIDsAfterSearch=function(){for(var o=this,e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return n.forEach(function(e){var n=e.index,i=e.queryID,t=e.objectIDs,r=e.objectData;return t.forEach(function(e,t){t=null!=(t=null==(t=null==r?void 0:r[t])?void 0:t.queryID)?t:i;!o._userHasOptedOut&&t&&u(n,e,t)})}),this.sendEvents(A("conversion","addToCart",n),i)}.bind(this),this.convertedObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(I("conversion",n),i)}.bind(this),this.addedToCartObjectIDs=function(){for(var r=this,e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return n.forEach(function(e){var n=e.index,t=e.objectIDs,i=e.objectData;return t.forEach(function(e,t){t=null==(t=null==i?void 0:i[t])?void 0:t.queryID;!r._userHasOptedOut&&t&&u(n,e,t)})}),this.sendEvents(A("conversion","addToCart",n),i)}.bind(this),this.purchasedObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(A("conversion","purchase",n),i)}.bind(this),this.convertedFilters=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(I("conversion",n),i)}.bind(this),this.viewedObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(I("view",n),i)}.bind(this),this.viewedFilters=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=s(e)).events,i=i.additionalParams;return this.sendEvents(I("view",n),i)}.bind(this),this.getVersion=function(e){return h(e)&&e(this.version),this.version}.bind(this)}function P(e,t){var n=JSON.stringify(t),n=navigator.sendBeacon(e,n);return Promise.resolve(!!n||w(e,t))}function E(e,i){return new Promise(function(t,n){fetch(e,{method:"POST",body:JSON.stringify(i),headers:{"Content-Type":"application/json"}}).then(function(e){t(200===e.status)}).catch(function(e){n(e)})})}var w=function(r,o){return new Promise(function(e,t){var n=JSON.stringify(o),i=new XMLHttpRequest;i.addEventListener("readystatechange",function(){4===i.readyState&&200===i.status?e(!0):4===i.readyState&&e(!1)}),i.addEventListener("error",function(){return t()}),i.addEventListener("timeout",function(){return e(!1)}),i.open("POST",r),i.setRequestHeader("Content-Type","application/json"),i.send(n)})};function S(e){e=new C({requestFn:e});return"object"==typeof window&&l.call(e,window),e.version=t,e}var q=S(function(){if(function(){try{return Boolean(navigator.sendBeacon)}catch(e){return!1}}())return P;if(function(){try{return Boolean(XMLHttpRequest)}catch(e){return!1}}())return w;if(function(){try{return void 0!==fetch}catch(e){return!1}}())return E;throw new Error("Could not find a supported HTTP request client in this environment.")}());return e.createInsightsClient=S,e.default=q,Object.defineProperty(e,"__esModule",{value:!0}),e}({});