(this["webpackJsonpgonzo-test-client"]=this["webpackJsonpgonzo-test-client"]||[]).push([[35],{tNNC:function(e,t,n){"use strict";var i=n("GOuw"),r=n("cc0a"),s=n("gr/K"),o=n("EcEN"),a=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{u(i.next(e))}catch(t){s(t)}}function a(e){try{u(i.throw(e))}catch(t){s(t)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}u((i=i.apply(e,t||[])).next())}))},u=function(e,t){var n,i,r,s,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"===typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(r=(r=o.trys).length>0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]this._config.bufferSize)return c.debug("Exceeded analytics events buffer size"),e.handlers.reject(new Error("Exceeded the size of analytics events buffer"));var n=((t={})[e.params.event.eventId]=e,t);this._buffer.push(n)},e.prototype.pause=function(){this._pause=!0},e.prototype.resume=function(){this._pause=!1},e.prototype.updateClient=function(e){this._client=e},e.prototype.flush=function(){this._flush=!0},e.prototype._startLoop=function(){this._interval&&clearInterval(this._interval);var e=this._config.flushInterval;this._interval=setInterval(this._sendBatch,e)},e.prototype._sendBatch=function(){var e=this._buffer.length;if(this._flush&&!e&&clearInterval(this._interval),!this._pause&&e){var t=this._config.flushSize,n=Math.min(t,e),i=this._buffer.splice(0,n);this._putEvents(i)}},e.prototype._putEvents=function(e){return a(this,void 0,void 0,(function(){var t,n,i,r;return u(this,(function(s){switch(s.label){case 0:t=this._bufferToMap(e),n=this._generateBatchEventParams(t),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this._client.putEvents(n).promise()];case 2:return i=s.sent(),this._processPutEventsSuccessResponse(i,t),[3,4];case 3:return r=s.sent(),[2,this._handlePutEventsFailure(r,t)];case 4:return[2]}}))}))},e.prototype._generateBatchEventParams=function(e){var t={ApplicationId:"",EventsRequest:{BatchItem:{}}};return Object.values(e).forEach((function(e){var n=e.params,i=n.event,r=n.timestamp,s=n.config,o=i.name,a=i.attributes,u=i.metrics,c=i.eventId,f=i.session,d=s.appId,p=s.endpointId,l=t.EventsRequest.BatchItem;t.ApplicationId=t.ApplicationId||d,l[p]||(l[p]={Endpoint:{},Events:{}}),l[p].Events[c]={EventType:o,Timestamp:new Date(r).toISOString(),Attributes:a,Metrics:u,Session:f}})),t},e.prototype._handlePutEventsFailure=function(e,t){c.debug("_putEvents Failed:",e);var n=e.statusCode;if(f.includes(n)){var i=Object.values(t);this._retry(i)}else;},e.prototype._processPutEventsSuccessResponse=function(e,t){var n=e.EventsResponse.Results,i=[];Object.entries(n).forEach((function(e){var n=e[0],r=e[1].EventsItemResponse;Object.entries(r).forEach((function(e){var r,s,o=e[0],a=e[1],u=a.StatusCode,p=a.Message,l=t[o],h={EventsResponse:{Results:(r={},r[n]={EventsItemResponse:(s={},s[o]={StatusCode:u,Message:p},s)},r)}};if(d.includes(u))l.handlers.resolve(h);else{if(!f.includes(u)){var g=l.params.event.name;return c.error("event "+o+" : "+g+" failed with error: "+p),l.handlers.reject(h)}i.push(l)}}))})),i.length&&this._retry(i)},e.prototype._retry=function(e){var t,n=[];e.forEach((function(e){var t,i=e.params,r=i.event,s=r.eventId,o=r.name;if(i.resendLimit-- >0)return c.debug("resending event "+s+" : "+o+" with "+i.resendLimit+" retry attempts remaining"),void n.push((t={},t[s]=e,t));c.debug("no retry attempts remaining for event "+s+" : "+o)})),(t=this._buffer).unshift.apply(t,n)},e.prototype._bufferToMap=function(e){return e.reduce((function(e,t){var n=Object.entries(t)[0],i=n[0],r=n[1];return e[i]=r,e}),{})},e}(),l=function(){return(l=Object.assign||function(e){for(var t,n=1,i=arguments.length;n0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]0?(y.debug("resending event "+e.eventName+" with "+e.resendLimit+" retry times left"),this._pinpointPutEvents(e,t)):y.debug("retry times used up for event "+e.eventName)},e.prototype._updateEndpoint=function(e){return h(this,void 0,void 0,(function(){var t,n,r,s,o,a,u,c,f,d,p;return g(this,(function(l){switch(l.label){case 0:t=e.params,n=e.handlers,r=t.config,s=t.event,o=r.appId,a=r.endpointId,u=this._endpointRequest(r,i.i.transferKeyToLowerCase(s,[],["attributes","userAttributes","Attributes","UserAttributes"])),c={ApplicationId:o,EndpointId:a,EndpointRequest:u},l.label=1;case 1:return l.trys.push([1,3,,4]),[4,this.pinpointClient.updateEndpoint(c).promise()];case 2:return f=l.sent(),y.debug("updateEndpoint success",f),this._endpointGenerating=!1,this._resumeBuffer(),n.resolve(f),[2];case 3:return d=l.sent(),p={err:d,update_params:c,endpointObject:e},[2,this._handleEndpointUpdateFailure(p)];case 4:return[2]}}))}))},e.prototype._handleEndpointUpdateFailure=function(e){return h(this,void 0,void 0,(function(){var t,n,i;return g(this,(function(r){switch(t=e.err,n=e.endpointObject,i=t.statusCode,y.debug("updateEndpoint failed",t),i){case 400:return[2,this._handleEndpointUpdateBadRequest(e)];case 403:return[2,this._handleEndpointUpdateForbidden(e)];default:if(m.includes(i))return!0,[2,this._retryEndpointUpdate(n,!0)];n.handlers.reject(t)}return[2]}))}))},e.prototype._handleEndpointUpdateBadRequest=function(e){return h(this,void 0,void 0,(function(){var t,n,i,r,s,o,a;return g(this,(function(u){switch(u.label){case 0:if(t=e.err,n=e.update_params,i=e.endpointObject,r=t.message,s=n.ApplicationId,o=n.EndpointRequest,!String(r).startsWith("Exceeded maximum endpoint per user count"))return[2,i.handlers.reject(t)];u.label=1;case 1:return u.trys.push([1,3,,4]),[4,this._removeUnusedEndpoints(s,o.User.UserId)];case 2:return u.sent(),y.debug("Removed unused endpoints successfully"),this._retryEndpointUpdate(i),[3,4];case 3:return a=u.sent(),y.warn("Failed to remove unused endpoints with error: "+a),y.warn('Please ensure you have updated your Pinpoint IAM Policy with the Action: "mobiletargeting:GetUserEndpoints" in order to get endpoints info of the user'),[2,i.handlers.reject(a)];case 4:return[2]}}))}))},e.prototype._handleEndpointUpdateForbidden=function(e){var t=e.err,n=e.endpointObject,i=t.code,r=t.retryable;if("ExpiredTokenException"!==i&&!r)return n.handlers.reject(t);this._retryEndpointUpdate(n)},e.prototype._retryEndpointUpdate=function(e,t){void 0===t&&(t=!1),y.debug("_retryEndpointUpdate",e);var n=e.params,i=n.config.resendLimit;if(n.resendLimit="number"===typeof n.resendLimit?n.resendLimit:i,n.resendLimit-- >0)return y.debug("resending endpoint update "+n.event.eventId+" with "+n.resendLimit+" retry attempts remaining"),void(this._endpointBuffer.length?this._endpointBuffer.unshift(e):this._updateEndpoint(e));y.warn("resending endpoint update "+n.event.eventId+" failed after "+n.config.resendLimit+" attempts"),this._endpointGenerating&&y.error("Initial endpoint update failed. ")},e.prototype._removeUnusedEndpoints=function(e,t){return h(this,void 0,void 0,(function(){var n=this;return g(this,(function(i){return[2,new Promise((function(i,r){n.pinpointClient.getUserEndpoints({ApplicationId:e,UserId:t},(function(s,o){if(s)return y.debug("Failed to get endpoints associated with the userId: "+t+" with error",s),r(s);var a=o.EndpointsResponse.Item;y.debug("get endpoints associated with the userId: "+t+" with data",a);for(var u=a[0],c=1;c0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]0},e}(),oe=n("I5gj"),ae=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{u(i.next(e))}catch(t){s(t)}}function a(e){try{u(i.throw(e))}catch(t){s(t)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}u((i=i.apply(e,t||[])).next())}))},ue=function(e,t){var n,i,r,s,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"===typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,i&&(r=2&s[0]?i.return:s[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,s[1])).done)return r;switch(i=0,r&&(s=[2&s[0],r.value]),s[0]){case 0:case 1:r=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,i=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(r=(r=o.trys).length>0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]0&&this._config.flushSize<=10?this._config.flushSize:5,this._config.flushInterval=this._config.flushInterval||5e3,this._sessionManager=new ve,Object(ge.isEmpty)(this._config.trackingId)||(this._sessionInfo=this._sessionManager.retrieveSessionInfo(this._config.trackingId)),this._isBrowser=i.i.browserOrNode().isBrowser,this._setupTimer()}e.prototype._setupTimer=function(){this._timer&&clearInterval(this._timer);var e=this._config,t=(e.flushSize,e.flushInterval),n=this;this._timer=setInterval((function(){n._sendFromBuffer()}),t)},e.prototype.record=function(e){return be(this,void 0,void 0,(function(){var t,n,i,r,s;return ye(this,(function(o){switch(o.label){case 0:return[4,this._getCredentials()];case 1:return(t=o.sent())?(Object.assign(e,{config:this._config,credentials:t,sentAt:(new Date).getTime()/1e3}),n=e.event,i=n.eventType,r=n.properties,"Identify"===i?(this._sessionManager.updateSessionInfo(r&&r.userId?r.userId:"",this._sessionInfo),[2]):(Object(ge.isEmpty)(e.event.userId)||this._sessionManager.updateSessionInfo(e.event.userId,this._sessionInfo),s=this.generateRequestParams(e,this._sessionInfo),"MediaAutoTrack"!==i?[3,7]:this._isBrowser?Object(ge.isEmpty)(Object(ge.get)(s,"eventData.properties.domElementId",null))?[3,3]:[4,this.isElementFullyLoaded(this.loadElement,s.eventData.properties.domElementId,500,5)]:[3,5])):[2,Promise.resolve(!1)];case 2:return o.sent()?new _e(s,this):me.debug("Cannot find the media element."),[3,4];case 3:me.debug("Missing domElementId field in 'properties' for MediaAutoTrack event type."),o.label=4;case 4:return[3,6];case 5:me.debug("MediaAutoTrack only for browser"),o.label=6;case 6:return[2];case 7:return[2,this.putToBuffer(s)]}}))}))},e.prototype.loadElement=function(e){return new Promise((function(t,n){return document.getElementById(e)&&document.getElementById(e).clientHeight?t(!0):n(!0)}))},e.prototype.isElementFullyLoaded=function(e,t,n,i){var r=this;return new Promise((function(s,o){return e(t).then(s).catch((function(a){return i-1>0?(u=n,new Promise((function(e){return setTimeout(e,u)}))).then(r.isElementFullyLoaded.bind(null,e,t,n,i-1)).then(s).catch(o):o(a);var u}))}))},e.prototype.getCategory=function(){return"Analytics"},e.prototype.getProviderName=function(){return"AmazonPersonalize"},e.prototype.configure=function(e){me.debug("configure Analytics",e);var t=e||{};return this._config=Object.assign({},this._config,t),Object(ge.isEmpty)(this._config.trackingId)||(this._sessionInfo=this._sessionManager.retrieveSessionInfo(this._config.trackingId)),this._setupTimer(),this._config},e.prototype.generateRequestParams=function(e,t){var n={},i=e.event,r=i.eventType,s=i.properties;return n.eventData={eventType:r,properties:s},n.sessionInfo=t,n.sentAt=e.sentAt,n.credentials=e.credentials,n.config=e.config,n},e.prototype._sendEvents=function(e){var t=e.length;if(0!==t){var n=e[0],i=n.config,r=n.credentials,s=n.sessionInfo;if(!this._init(i,r))return!1;if(t>0){for(var o=[],a=0;a0&&r[r.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!r||s[1]>r[0]&&s[1]