mirror of
https://github.com/rxliuli/apps.apple.com.git
synced 2025-11-09 17:40:32 +00:00
3 lines
27 KiB
JavaScript
3 lines
27 KiB
JavaScript
import{s as w,n as q,b as X,r as u,k as G,f as Z}from"./mt-metricskit-utils-private.esm~DkzakSThTT.js";import{L as $,l as x}from"./mt-client-logger-core.esm~-rJfHcY8Zf.js";var Q=function(){};Q.prototype.setDelegate=function(e){return u.attachDelegate(this,e)};Q.prototype.localStorageObject=w.localStorageObject;Q.prototype.sessionStorageObject=w.sessionStorageObject;var M=function(){};M.prototype.setDelegate=function(e){return u.attachDelegate(this,e)};M.prototype.makeAjaxRequest=q.makeAjaxRequest;var C="noTopicConfig",B="_",V={configBaseUrl:"https://xp.apple.com/config/1/report",disabled:!0},k,H=function(e,r,n){if(n){e.push(n);var o=n[r];o&&u.hasAnyKeys(o)&&e.push(o)}},v=function(e){this.environment=new Q,this.network=new M,this.logger=new $("mt-client-config"),this._topic=e||C,this._debugSource=null,this._cachedSource=null,this._serviceSource=null,this._initCalled=!1,this._initialized=!1,this._showedDebugWarning=!1,this._showedNoProvidedSourceWarning=!1,this._keyPathsThatSuppressWarning={configBaseUrl:!0},this._configFetchPromise=null,this.DEBUG_SOURCE_KEY="mtClientConfig_debugSource"+B+this._topic,this.CACHED_SOURCE_KEY="mtClientConfig_cachedSource"+B+this._topic};v.defaultConfig=function(){return k||(k=new v(C)),k};v.prototype._defaults=function(){return V};v.prototype._setInitialized=function(e){this._initialized=e};v.prototype._setInitCalled=function(e){this._initCalled=e};v.prototype._setShowedDebugWarning=function(e){this._showedDebugWarning=e};v.prototype._setShowedNoProvidedSourceWarning=function(e){this._showedNoProvidedSourceWarning=e};v.prototype.setDelegate=function(e){return u.attachDelegate(this,e)};v.prototype.resetDelegate=function(){u.detachMethods(this),u.resetDelegates(this)};v.prototype.topic=function(){return this._topic};v.prototype.configHostname=function(){};v.prototype.configUrl=function(){var e=this.configHostname(),r;return e?r=Promise.resolve("https://"+e+"/config/1/report"):r=this.value("configBaseUrl"),r.then((function(n){return this._topic!==C?n+="/"+this.topic():this.logger.error("config.configUrl(): Topic must be provided"),n}).bind(this))};v.prototype.sources=function(){};v.prototype.value=function(e,r){var n=(function(){var i=this.cachedSource(),a=this.serviceSource(),c=this.sources(),f=this.debugSource(),d=i||a||c||f,h;return!c&&!a&&!(e in this._keyPathsThatSuppressWarning)&&(this._showedNoProvidedSourceWarning||(this._showedNoProvidedSourceWarning=!0,this.logger.warn("Metrics config: No config provided via delegate or fetched via init(), using cached config values."))),f&&(this._showedDebugWarning||(this._showedDebugWarning=!0,this.logger.warn('"debugSource" found.\nThis will override any same-named client-supplied configSource fields.\nThis setting "sticks" across session, use "setDebugSource(null)" to clear'))),u.isArray(c)||(c=[c]),e==="disabled"?d?h=[i,a,c,f]:h=[V]:h=[V,i,a,c,f],h=this.configSourcesWithOverrides(h,r||this.topic()),G.valueForKeyPath.apply(null,[e].concat(h))}).bind(this);if(this._configFetchPromise)return this._configFetchPromise.then(n);var o=n();return Promise.resolve(o)};v.prototype.configSourcesWithOverrides=function(e,r){var n=e;if(e&&e.length&&r){n=[];for(var o=0;o<e.length;o++){var i=e[o];if(i)if(u.isArray(i)&&i.length){for(var a=[],c=0;c<i.length;c++)H(a,r,i[c]);n.push(a)}else H(n,r,i)}}return n};v.prototype.setDebugSource=function(e){return this._debugSource=e||null,w.saveObjectToStorage(this.environment.localStorageObject(),this.DEBUG_SOURCE_KEY,this._debugSource)};v.prototype.debugSource=function(){return this._debugSource||(this._debugSource=w.objectFromStorage(this.environment.localStorageObject(),this.DEBUG_SOURCE_KEY)),this._debugSource};v.prototype.setCachedSource=function(e){return this._cachedSource=e||null,w.saveObjectToStorage(this.environment.localStorageObject(),this.CACHED_SOURCE_KEY,this._cachedSource)};v.prototype.cachedSource=function(){return this._cachedSource||(this._cachedSource=w.objectFromStorage(this.environment.localStorageObject(),this.CACHED_SOURCE_KEY)),this._cachedSource};v.prototype.setServiceSource=function(e){return this._serviceSource=e,this._serviceSource};v.prototype.serviceSource=function(){return this._serviceSource};v.prototype.init=function(e){var r=this._topic===C||!u.isFunction(e);if(r&&this.logger.warn("config.init(): Falling back to default config because configSourcesFn or a valid topic was not provided"),this._initCalled||r)return Promise.resolve(this);this._initCalled=!0;var n=this;return this._configFetchPromise=Promise.resolve(e()).then(function(o){return n.setDelegate({sources:function(){return o}}),n._initialized=!0,n}).catch(function(o){throw n._initCalled=!1,n._initialized=!1,o}),this._configFetchPromise};v.prototype.cleanup=function(){this._initCalled=this._initialized=!1,this.setCachedSource(),this.setDebugSource(),this.resetDelegate(),this.environment=null,this.network=null,this.logger=null,this._topic=null,this._debugSource=null,this._cachedSource=null,this._serviceSource=null,this._initCalled=!1,this._initialized=!1,this._showedDebugWarning=!1,this._showedNoProvidedSourceWarning=!1,this._configFetchPromise=null};v.prototype.initialized=function(){return this._initialized};var E=function(e){v.call(this,e)};E.prototype=Object.create(v.prototype);E.prototype.constructor=E;E.prototype.disabled=function(e){return this.value("disabled",e).then(function(r){return!!r})};E.prototype.blacklistedEvents=function(e){return this.denylistedEvents(e)};E.prototype.denylistedEvents=function(e){var r=this.value("blacklistedEvents",e).then(function(o){return o||[]}).catch(function(){return[]}),n=this.value("denylistedEvents",e).then(function(o){return o||[]}).catch(function(){return[]});return Promise.all([r,n]).then(function(o){var i=o[0],a=o[1];return K(i,a)})};function K(t,e){var r={},n=[];if(t)for(var o=0;o<t.length;o++)r[t[o]]=0;if(e)for(var i=0;i<e.length;i++)r[e[i]]=0;return n=Object.keys(r),n}E.prototype.blacklistedFields=function(e){return this.denylistedFields(e)};E.prototype.denylistedFields=function(e){var r=this.value("blacklistedFields",e).then(function(o){return o||[]}).catch(function(){return[]}),n=this.value("denylistedFields",e).then(function(o){return o||[]}).catch(function(){return[]});return Promise.all([r,n]).then(function(o){var i=o[0],a=o[1];return K(i,a)})};E.prototype.removeBlacklistedFields=function(e,r){return this.removeDenylistedFields(e,r)};E.prototype.removeDenylistedFields=function(e,r){return e?this.denylistedFields(r).then(function(n){for(var o=0;o<n.length;o++){var i=n[o];i&&i in e&&delete e[i]}return e}):Promise.resolve(e)};E.prototype.metricsDisabledOrBlacklistedEvent=function(e,r){return this.metricsDisabledOrDenylistedEvent(e,r)};E.prototype.metricsDisabledOrDenylistedEvent=function(e,r){return this.disabled(r).then((function(n){return n||(e?this.denylistedEvents(r).then(function(o){return o.indexOf(e)>-1}):!1)}).bind(this))};E.prototype.deResFields=function(e){return this.value("deResFields",e).then(function(r){return r||[]})};E.prototype.applyDeRes=function(e,r){return e?this.deResFields(r).then(function(n){var o;return n.forEach(function(i){o=i.fieldName,o in e&&(e[o]=X.deResNumber(e[o],i.magnitude,i.significantDigits))}),e}):Promise.resolve(e)};var m=function(e,r){if(!u.isDefinedNonNullNonEmpty(e)||!u.isString(e))throw new Error("No valid topic was provided to Delegates.");this.config=this.getOrCreateConfig(e),u.isDefinedNonNull(r)&&(this.environment=r.environment,this.eventRecorder=r.eventRecorder),this._useOrginalContextForDelegateFunc=!1};m.prototype.init=function(){if(!u.isDefinedNonNull(this.environment))throw new Error("No environment was provided to Delegate options.");if(!u.isDefinedNonNull(this.eventRecorder))throw new Error("No eventRecorder was provided to Delegate options.");this.config.environment.setDelegate(this.environment),this.config.logger.setDelegate(this.logger),this.config.network.setDelegate(this.network);var t=u.isFunction(this.configSources)?this.configSources.bind(this):null;return this.config.init(t)};m.prototype.mergeDelegates=function(t){var e=this;for(var r in t)e[r]||(e[r]=t[r]);this.config.setDelegate(t.config)};m.prototype.cleanup=function(){u.isFunction(this.eventRecorder.cleanup)&&this.eventRecorder.cleanup(),this.config=null,this.eventRecorder=null,this.environment=null};m.prototype.setEventRecorder=function(e){return u.isDefinedNonNull(e)&&(u.isDefinedNonNull(this.eventRecorder)?(u.setDelegates(this.eventRecorder,e),this.eventRecorder.setDelegate(e)):this.eventRecorder=e),this};m.prototype.setEnvironment=function(e){if(!u.isDefinedNonNull(this.environment))this.environment=e;else{var r=Object.create(this.environment);u.extend(r,e),this.environment=r}return this};m.prototype.setConfig=function(e){return this.config.setDelegate(e),this};m.prototype.getOrCreateConfig=function(e){return u.isDefinedNonNull(this.config)||(this.config=new E(e)),this.config};m.prototype.configSources=function(){throw new Error("This method should be implemented by subdelegates.")};function T(){this._operationPromiseChain=Promise.resolve()}T.prototype.setDelegate=function(e){return u.attachDelegate(this,e)};T.prototype.recordEvent=function(e,r){var n=Array.prototype.slice.call(arguments,2),o=this;return this._operationPromiseChain=this._operationPromiseChain.then(function(){return Promise.resolve(r).then(function(i){return o._recordEvent.apply(o,[e,i].concat(n))})}),this._operationPromiseChain};T.prototype.flushUnreportedEvents=function(){var e=Array.prototype.slice.call(arguments),r=this;return this._operationPromiseChain.then(function(){return r._operationPromiseChain=Promise.resolve(),r._flushUnreportedEvents.apply(r,e)})};T.prototype._recordEvent=function(e,r){};T.prototype._flushUnreportedEvents=function(e){};var P={setDelegate:function(e){return u.attachDelegate(this,e)},globalScope:function(){return u.globalScope()}},F={AJAX:"ajax",AJAX_SYNCHRONOUS:"ajaxSynchronous",IMAGE:"image",BEACON:"beacon",BEACON_SYNCHRONOUS:"beaconSynchronous"},ee=["dsId","consumerId"];function te(t,e){var r={_topic:e};return Object.setPrototypeOf(r,t),r}var S=function(e){this._validateConfig(e),this._config=e,this._topicConfigCache={},this._topicPropsCache={},this.logger=x("mt-event-queue")};S.prototype._validateConfig=function(e){var r="please call constructor with a valid Config instance first.";if(e){if(!e.topic||!u.isFunction(e.topic))throw new TypeError("Unable to find config.topic function, "+r);if(!e.metricsDisabledOrDenylistedEvent||!u.isFunction(e.metricsDisabledOrDenylistedEvent))throw new TypeError("Unable to find config.metricsDisabledOrDenylistedEvent function, "+r);if(!e.removeDenylistedFields||!u.isFunction(e.removeDenylistedFields))throw new TypeError("Unable to find config.removeDenylistedFields function, "+r)}else throw new TypeError("Unable to find config, "+r)};S.prototype._removeIdentifiableFieldsForTopic=function(e,r){this._topicPropsCache[e]=this._topicPropsCache[e]||{},this._topicPropsCache[e].anonymous&&ee.forEach(function(n){delete r[n]})};S.prototype._record=function(e){};S.prototype.cleanup=function(){this._config=null,this._topicConfigCache=null,this._topicPropsCache={}};S.prototype.recordEvent=function(e,r){if(!this._config||!r)return Promise.resolve(null);var n=this._config,o=this,i=arguments;return u.isDefinedNonNullNonEmpty(e)&&e!==n.topic()&&(n=this._topicConfigCache[e],n||(n=this._topicConfigCache[e]=te(this._config,e))),n.metricsDisabledOrDenylistedEvent(r.eventType).then(function(a){return a?null:n.removeDenylistedFields(r).then(function(){return o._removeIdentifiableFieldsForTopic(e,r),o._record.apply(o,[n].concat(Array.prototype.slice.call(i,1)))}).then(function(){return r})}).catch(function(a){return o.logger.error(a),null})};S.prototype.sendMethod=function(){return"javascript"};S.prototype.setProperties=function(e,r){this._topicPropsCache[e]=this._topicPropsCache[e]||{},this._topicPropsCache[e]=r};var Y={setDelegate:function(e){return u.attachDelegate(this,e)},makeAjaxRequest:q.makeAjaxRequest};function W(){var t=navigator.userAgent;return/iPad|iPhone|iPod/.test(t)&&t.indexOf("IEMobile")==-1}function re(){return u.isFunction(P.globalScope().fetch)&&!/Firefox/.test(navigator.userAgent)}function b(){return x("mt-event-queue")}var p={DEFAULT_REQUEST_TIMEOUT:1e4,EVENTS_KEY:"events",EVENT_DELIVERY_VERSION:"1.0",MAX_PERSISTENT_QUEUE_SIZE:100,RETRY_EXPONENT_BASE:2,SEND_METHOD:F,URL_DELIVERY_VERSION:2,PROPERTIES_KEY:"properties"},s={eventQueues:{},postIntervalEnabled:!0,enqueueEvent:function(e,r){if(e&&r&&e.topic()){var n=e.topic();return s.eventQueues=s.eventQueues||{},s.eventQueues[n]=s.eventQueues[n]||{},s.eventQueues[n].topicConfig=e,s.eventQueues[n].flushConfig=s.eventQueues[n].flushConfig||{},s.eventQueues[n][p.EVENTS_KEY]=s.eventQueues[n][p.EVENTS_KEY]||[],s.eventQueues[n][p.EVENTS_KEY].push(r),Object.keys(s.eventQueues[n].flushConfig).length===0&&Promise.all([e.value("metricsUrl"),e.value("requestTimeout"),e.value("postFrequency")]).then(function(o){var i=s.eventQueues[n].flushConfig;i.metricsUrl=o[0],i.requestTimeout=o[1],i.postFrequency=o[2]}),e.value("maxPersistentQueueSize").then(function(o){return o=o||p.MAX_PERSISTENT_QUEUE_SIZE,s.trimEventQueues(s.eventQueues,o),r})}else return Promise.resolve(null)},trimEventQueues:function(e,r){var n=Object.keys(e);n.length&&n.forEach(function(o){var i=e[o][p.EVENTS_KEY];i&&i.length&&i.length>r&&(b().warn("eventQueue overflow, deleting LRU events: size is: "+i.length+" which is over max size: "+r),e[o][p.EVENTS_KEY]=i.slice(-r))})},resetTopicQueue:function(e){s.eventQueues[e]&&(s.eventQueues[e][p.EVENTS_KEY]=null)},resetTopicRetryAttempts:function(e){s.eventQueues[e]&&(s.eventQueues[e].retryAttempts=0)},scheduleNextTopicRetryAttempt:function(e){var r=e.topic();return s.eventQueues[r]&&this.postIntervalEnabled?e.value("postFrequency").then(function(n){var o=s.eventQueues[r];o.retryAttempts=o.retryAttempts||0,o.retryAttempts++;var i=Math.pow(p.RETRY_EXPONENT_BASE,o.retryAttempts)*n;s.resetTopicPostInterval(r),s.setTopicPostInterval(e,i)}):Promise.resolve()},sendEvents:function(e,r){var n=[];for(var o in s.eventQueues){var i=s.eventQueues[o].topicConfig,a=s.sendEventsForTopicConfig(i,e,r);n.push(a)}return Promise.all(n)},sendEventsForTopicConfig:function(e,r,n){var o=e.topic(),i=s.eventQueues[o];return Promise.all([e.value("testExponentialBackoff"),e.value("metricsUrl"),e.disabled(),e.value("postFrequency")]).then(function(a){var c=a[0],f=a[1],d=a[2],h=a[3];if(i&&f&&!d&&!c){if(!(i.retryAttempts&&n)){s.resetTopicPostInterval(o),s.setTopicPostInterval(e,h);var y;switch(r){case p.SEND_METHOD.IMAGE:y=s.sendEventsViaImage(e);break;case p.SEND_METHOD.BEACON:y=s.sendEventsViaBeacon(e);break;case p.SEND_METHOD.AJAX_SYNCHRONOUS:y=s.sendEventsViaAjax(e,!1);break;case p.SEND_METHOD.AJAX:default:y=s.sendEventsViaAjax(e,!0);break}return y}}else if(c)return s.scheduleNextTopicRetryAttempt(e)})},sendEventsViaImage:function(e){var r=e.topic(),n=Promise.resolve();return s.eventQueues[r]&&(n=A(e,function(o){var i=o.metricsUrl,a=i.indexOf("?")==-1?"?":"&",c=i+a+"responseType=image",f=s.eventQueues[r][p.EVENTS_KEY];f&&f.length&&f.forEach(function(d){var h=s.createQueryParams(d);if(h){var y=c+"&"+h,O=new Image,N=s.eventQueues[r][p.PROPERTIES_KEY];N&&N.anonymous&&O.setAttribute("crossOrigin","anonymous"),O.src=y}}),s.resetTopicQueue(r)})),n},createQueryParams:function(e){var r,n,o="";return Object.keys(e).forEach(function(i,a,c){r=e[i],n=u.isString(r)?r:JSON.stringify(r),o+=i+"="+encodeURIComponent(n),a<c.length-1&&(o+="&")}),o.length?o:null},sendEventsViaAjax:function(e,r){var n=Promise.resolve(),o=e.topic();if(s.eventQueues[o]&&s.eventQueues[o][p.EVENTS_KEY]){var i=s.eventQueues[o][p.EVENTS_KEY],a=I(i);s.resetTopicQueue(o),a&&(n=A(e,function(c){var f=c.metricsUrl,d=c.requestTimeout,h=function(){s.resetTopicRetryAttempts(o)},y=function(ce,j){if(j>=400&&j<500)h();else{var J=s.eventQueues[o][p.EVENTS_KEY]||[];s.eventQueues[o][p.EVENTS_KEY]=i.concat(J),s.scheduleNextTopicRetryAttempt(e)}},O=s.eventQueues[o][p.PROPERTIES_KEY]||{},N={async:r,timeout:d};O.anonymous&&(N.withCredentials=!1),Y.makeAjaxRequest(f,"POST",a,h,y,N)}))}return n},sendEventsViaBeacon:function(e){var r=Promise.resolve();if(!u.isFunction(navigator.sendBeacon))return b().error("navigator.sendBeacon() is not available in the environment"),r;var n=e.topic(),o=s.eventQueues[n];if(o){var i=o[p.PROPERTIES_KEY];if(i&&i.anonymous)re()?r=s.sendEventsViaFetch(e,{keepalive:!0}):W()?r=s.sendEventsViaAjax(e,!1):r=s.sendEventsViaImage(e);else{var a=I(o[p.EVENTS_KEY]);a&&(s.resetTopicQueue(n),r=A(e,function(c){var f=c.metricsUrl,d=P.globalScope().Blob,h=new d([a],{type:"application/json"}),y=navigator.sendBeacon(f,h);y||b().error("navigator.sendBeacon() was unable to queue the data for transfer")}))}}return r},sendEventsViaFetch:function(e,r){var n=Promise.resolve(),o=e.topic(),i=s.eventQueues[o],a=u.isDefinedNonNull(r)?r.keepalive:null;if(u.isDefinedNonNull(i)){var c=I(i[p.EVENTS_KEY]);if(c){s.resetTopicQueue(o);var f=i[p.PROPERTIES_KEY]||{};n=A(e,function(d){var h=d.metricsUrl;u.globalScope().fetch(h,{method:"POST",headers:{"Content-Type":"application/json"},body:c,credentials:f.anonymous===!0?"omit":"same-origin",keepalive:u.isDefinedNonNull(a)?a:!0})})}}return n},setTopicPostInterval:function(e,r){var n=e.topic();s.eventQueues[n]&&r&&this.postIntervalEnabled&&(this.resetTopicPostInterval(n),s.eventQueues[n].postIntervalToken=P.globalScope().setInterval(function(){b().debug("MetricsKit: triggering postIntervalTimer for "+n+" at "+new Date().toString()),s.sendEventsForTopicConfig(e)},r))},resetTopicPostInterval:function(e){s.eventQueues[e]&&(P.globalScope().clearInterval(s.eventQueues[e].postIntervalToken),s.eventQueues[e].postIntervalToken=null)},resetQueuePostIntervals:function(){for(var e in s.eventQueues)s.resetTopicPostInterval(e)},setQueuePostIntervals:function(){var e=[],r=function(c){return function(f){s.setTopicPostInterval(c,f)}};for(var n in s.eventQueues){var o=s.eventQueues[n][p.EVENTS_KEY],i=s.eventQueues[n].topicConfig;if(o&&o.length){var a=i.value("postFrequency").then(r(i));e.push(a)}}return Promise.all(e)},objectContainsValue:function(e,r){var n=!1;for(var o in e){var i=e[o];if(e.hasOwnProperty(o)&&!u.isFunction(i)&&i===r){n=!0;break}}return n},setProperties:function(e,r){s.eventQueues=s.eventQueues||{},s.eventQueues[e]=s.eventQueues[e]||{},s.eventQueues[e][p.PROPERTIES_KEY]=r}};function U(){return s}function I(t){var e=null;if(t&&t.length){var r={};r.deliveryVersion=p.EVENT_DELIVERY_VERSION,r.postTime=Date.now(),r[p.EVENTS_KEY]=t;try{e=JSON.stringify(r)}catch(n){b().error("Error stringifying events as JSON: "+n)}}return e}function ne(t){return I([t])}function L(t){return t.value("metricsUrl").then(function(e){var r=e+"/"+p.URL_DELIVERY_VERSION+"/";return r+t.topic()})}function A(t,e){if(!u.isFunction(e)){b().warn("No callback function is provided for resolveTopicConfigWithCallback()");return}if(u.isString(t.metricsUrl)&&!u.isFunction(t.value)){var r=u.isFunction(t.topic)?t.topic():t.topic,n=t.metricsUrl+"/"+p.URL_DELIVERY_VERSION+"/"+r,o=t.requestTimeout||p.DEFAULT_REQUEST_TIMEOUT,i=t.postFrequency;return e({requestTimeout:Math.min(o,i),metricsUrl:n})}else return Promise.all([t.value("requestTimeout"),t.value("postFrequency"),L(t)]).then(function(a){var c=a[0]||p.DEFAULT_REQUEST_TIMEOUT,f=a[1],d=a[2];return e({requestTimeout:Math.min(c,f),metricsUrl:d})})}function oe(t){return Promise.all([t.value("requestTimeout"),t.value("postFrequency")]).then(function(e){var r=e[0]||p.DEFAULT_REQUEST_TIMEOUT,n=e[1];return Math.min(r,n)})}function ie(t,e,r){var n=t.topic();return t.disabled().then(function(o){if(!o)return t.value("postFrequency").then(function(i){return i===0&&(r=!0),s.enqueueEvent(t,e).then(function(){return i})}).then(function(i){if(r)return s.sendEvents(p.SEND_METHOD.AJAX,!0);!s.eventQueues[n].postIntervalToken&&s.postIntervalEnabled&&s.setTopicPostInterval(t,i)})})}function se(t,e){return t?e===F.BEACON_SYNCHRONOUS?ue():u.isString(e)&&s.objectContainsValue(F,e)?s.sendEvents(e,!0):u.isFunction(navigator.sendBeacon)?s.sendEvents(p.SEND_METHOD.BEACON,!0):W()?s.sendEvents(p.SEND_METHOD.AJAX_SYNCHRONOUS,!0):s.sendEvents(p.SEND_METHOD.IMAGE,!0):s.sendEvents(p.SEND_METHOD.AJAX,!0)}function ue(){for(var t in s.eventQueues){var e=s.eventQueues[t],r=e.flushConfig,n=u.extend({},r,{_topic:t,topic:function(){return this._topic}});s.sendEventsViaBeacon(n)}}var g=function(e){S.apply(this,arguments)};g.prototype=Object.create(S.prototype);g.prototype.constructor=g;g.prototype._utResetQueue=function(){for(var e in U().eventQueues)U().resetTopicPostInterval(e);U().eventQueues={}};g.prototype._record=function(e,r,n){return ie(e,r,n)};g.prototype.SEND_METHOD=F;g.prototype.setDelegate=function(e){return u.attachDelegate(this,e)};g.prototype.flushUnreportedEvents=function(e,r){return se.apply(null,arguments)};g.prototype.setProperties=function(e,r){Object.getPrototypeOf(g.prototype).setProperties.call(this,e,r),U().setProperties(e,r)};g.prototype.cleanup=function(){Object.getPrototypeOf(g.prototype).cleanup.call(this),this._utResetQueue()};var R=function(e){S.apply(this,arguments)};R.prototype=Object.create(S.prototype);R.prototype.constructor=R;R.prototype._record=function(e,r){var n=ne(r);if(n)return Promise.all([L(e),oe(e)]).then((function(o){var i=o[0],a=o[1],c={timeout:a};this._topicPropsCache[e.topic()]&&this._topicPropsCache[e.topic()].anonymous&&(c.withCredentials=!1),Y.makeAjaxRequest(i,"POST",n,null,null,c)}).bind(this))};var ae=x("mt-event-queue");function l(t){this._config=t}l.prototype._document=function(){if(typeof document<"u")return document;throw"metricskit-delegates-html.environment HTML delegate 'document' object not found"};l.prototype._window=function(){if(typeof window<"u")return window;throw"metricskit-delegates-html.environment HTML delegate 'window' object not found"};l.prototype.browser=function(){var e=this._window().navigator.userAgent;return!u.isDefinedNonNull(this._config)||!u.isDefinedNonNullNonEmpty(e)?null:this._config.value("browserMaps").then(function(r){if(!u.isDefinedNonNull(r))return null;for(var n=r.specifiedBrowsers||[],o=r.browserMap||{},i=null,a=0;a<n.length;a++){var c=n[a];if(e.indexOf(c)>-1){i=c;break}}if(!u.isDefinedNonNull(i)){var f=e.match(/Mozilla\/5.0 \((.*?)\)(\s|$)((.*?)\/(.*?)(\s)\(.*\))?(.*?)\/(.*?)(\s|$)/);u.isDefinedNonNullNonEmpty(f)&&f.length>=8&&(i=f[7])}u.isDefinedNonNull(i)?i=i.trim():i="unknown";var d=o[i]||i;return d})};l.prototype.cookie=function(){return this._window().document.cookie};l.prototype.pageUrl=function(){return this._window().location.href};l.prototype.parentPageUrl=function(){var e=this._window(),r=e.parent,n;if(r!==e)try{n=r.location.href}catch(o){n=this._document().referrer}return n};l.prototype.pixelRatio=function(){return this._window().devicePixelRatio};l.prototype.screenHeight=function(){return this._window().screen.height};l.prototype.screenWidth=function(){return this._window().screen.width};l.prototype.userAgent=function(){return this._window().navigator.userAgent};l.prototype.windowInnerHeight=function(){return this._window().innerHeight};l.prototype.windowInnerWidth=function(){return this._window().innerWidth};l.prototype.windowOuterHeight=function(){return this._window().outerHeight};l.prototype.windowOuterWidth=function(){return this._window().outerWidth};l.prototype.timeOriginOffset=function(){var e=null,r=this._window().performance;return r&&r.timing&&(e=r.timing.navigationStart),e};l.prototype.app=function(){};l.prototype.appVersion=function(){};l.prototype.capacityData=function(){};l.prototype.capacityDataAvailable=function(){};l.prototype.capacityDisk=function(){};l.prototype.capacitySystem=function(){};l.prototype.capacitySystemAvailable=function(){};l.prototype.connectionType=function(){};l.prototype.dsId=function(){};l.prototype.hardwareBrand=function(){};l.prototype.hardwareFamily=function(){};l.prototype.hardwareModel=function(){};l.prototype.hostApp=function(){};l.prototype.hostAppVersion=function(){};l.prototype.os=function(){};l.prototype.osBuildNumber=function(){};l.prototype.osLanguages=function(){};l.prototype.osVersion=function(){};l.prototype.resourceRevNum=function(){};l.prototype.storeFrontCountryCode=function(){};l.prototype.storeFrontHeader=function(){};l.prototype.storeFrontLanguage=function(){};l.prototype.userType=function(){};function _(t){T.call(this),this._proxyEventRecorder=t,this.SEND_METHOD=t.SEND_METHOD}_.prototype=Object.create(T.prototype);_.prototype.constructor=_;_.prototype._recordEvent=function(e,r){return this._proxyEventRecorder.recordEvent.apply(this._proxyEventRecorder,arguments)};_.prototype.flushUnreportedEvents=function(e,r){var n=this,o=Array.prototype.slice.call(arguments);return u.isDefinedNonNull(this._proxyEventRecorder.SEND_METHOD)&&r===this._proxyEventRecorder.SEND_METHOD.BEACON_SYNCHRONOUS?this._proxyEventRecorder.flushUnreportedEvents.apply(this._proxyEventRecorder,arguments):this._operationPromiseChain.then(function(){return n._operationPromiseChain=Promise.resolve(),n._proxyEventRecorder.flushUnreportedEvents.apply(n._proxyEventRecorder,o)})};_.prototype._flushUnreportedEvents=function(){return this._proxyEventRecorder.flushUnreportedEvents.apply(this._proxyEventRecorder,arguments)};_.prototype.sendMethod=function(){return this._proxyEventRecorder.sendMethod.apply(this._proxyEventRecorder,arguments)};_.prototype.setProperties=function(e,r){return this._proxyEventRecorder.setProperties.apply(this._proxyEventRecorder,arguments)};_.prototype.cleanup=function(){return this._proxyEventRecorder.cleanup.apply(this._proxyEventRecorder,arguments)};var D=function(e,r){var n=this.getOrCreateConfig(e);m.call(this,e,{environment:new l(n),eventRecorder:new _(new g(n))}),this.immediateEventRecorder=new _(new R(n)),this.network=null,this.logger=null,r&&(this.mergeDelegates(r),r.environment&&this.setEnvironment(r.environment),r.eventRecorder&&this.setEventRecorder(r.eventRecorder),r.network&&this.setNetwork(r.network),r.logger&&this.setLogger(r.logger),r.config&&(r.config.url&&this.config.setDelegate({configUrl:r.config.url}),this.setConfig(r.config)))};D.prototype=Object.create(m.prototype);D.prototype.constructor=D;D.prototype.setEnvironment=function(t){return P.setDelegate(t),m.prototype.setEnvironment.call(this,t)};D.prototype.setNetwork=function(t){return t&&(this.network=t,Y.setDelegate(t)),this};D.prototype.setLogger=function(t){return t&&(this.logger=t,ae.setDelegate(t)),this};D.prototype.setImmediateEventRecorder=function(t){if(t){var e=Object.create(this.immediateEventRecorder);Object.assign(e,t),this.immediateEventRecorder=e}return this};D.prototype.configSources=function(){var e=this;return new Promise(function(r,n){var o=function(f){try{var d=JSON.parse(f);e.config.setCachedSource(d),e.config.setServiceSource(d),r(d)}catch(h){i(h)}},i=function(f){e.config.setCachedSource(e.config.cachedSource()),n(f)},a=Promise.resolve(e.config.configUrl());a.then(function(c){Z.exponentialBackoff(e.config.network.makeAjaxRequest.bind(e.config.network,c,"GET",null),o,i)}).catch(i)})};export{l as Environment,D as WebDelegates};
|
|
//# sourceMappingURL=mt-metricskit-delegates-web.esm~C4cdYnvnOP.js.map
|