UNPKG

@knapsack/app

Version:

Build Design Systems on top of knapsack, by Basalt

2 lines 53.3 kB
(window.webpackJsonp=window.webpackJsonp||[]).push([["vendors~App-7KZ9F~cd57acee"],{"../node_modules/@aws-amplify/analytics/lib-esm/index.js":function(e,t,n){var i=n("../node_modules/@aws-amplify/core/lib-esm/index.js"),r=n("../node_modules/aws-sdk/clients/mobileanalytics.js"),s=n("../node_modules/aws-sdk/clients/pinpoint.js"),o=n("../node_modules/@aws-amplify/cache/lib-esm/index.js"),a=n("../node_modules/uuid/index.js"),__assign=function(){return(__assign=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},__awaiter=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},__generator=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:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(s){return function(a){return function step(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]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},__rest=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n},c="undefined"!=typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("amplify_default"):"@@amplify_default",dispatchAnalyticsEvent=function(e,t){i.f.dispatch("analytics",{event:e,data:t},"Analytics",c)},u=new i.c("AWSPinpointProvider"),d=[429,500],l=[202],f=navigator&&"function"==typeof navigator.sendBeacon,p=1e3,h=100,g=5e3,v=5,b=function(){function AWSPinpointProvider(e){this._endpointGenerating=!0,this._buffer=[],this._config=e||{},this._config.bufferSize=this._config.bufferSize||p,this._config.flushSize=this._config.flushSize||h,this._config.flushInterval=this._config.flushInterval||g,this._config.resendLimit=this._config.resendLimit||v,this._clientInfo=i.b.clientInfo()}return AWSPinpointProvider.prototype._setupTimer=function(){var e=this;this._timer&&clearInterval(this._timer);var t=this._config,n=t.flushSize,i=t.flushInterval,r=this;this._timer=setInterval((function(){for(var t=e._buffer.length<n?e._buffer.length:n,i=0;i<t;i+=1){var s=e._buffer.shift(),o=s.params,a=s.handlers;if(r._send(o,a),e._endpointGenerating)break}}),i)},AWSPinpointProvider.prototype._putToBuffer=function(e,t){var n=this._config.bufferSize;if(!(this._buffer.length<n))return u.debug("exceed analytics events buffer size"),t.reject(new Error("Exceed the size of analytics events buffer"));this._buffer.push({params:e,handlers:t})},AWSPinpointProvider.prototype.getCategory=function(){return AWSPinpointProvider.category},AWSPinpointProvider.prototype.getProviderName=function(){return AWSPinpointProvider.providerName},AWSPinpointProvider.prototype.configure=function(e){var t=this;u.debug("configure Analytics",e);var n=e||{};if(this._config=Object.assign({},this._config,n),this._config.appId&&!this._config.disabled){if(this._config.endpointId)dispatchAnalyticsEvent("pinpointProvider_configured",null);else{var i=this.getProviderName()+"_"+this._config.appId;this._getEndpointId(i).then((function(e){u.debug("setting endpoint id from the cache",e),t._config.endpointId=e,dispatchAnalyticsEvent("pinpointProvider_configured",null)})).catch((function(e){u.debug("Failed to generate endpointId",e)}))}this._setupTimer()}else this._timer&&clearInterval(this._timer);return this._config},AWSPinpointProvider.prototype.record=function(e,t){return __awaiter(this,void 0,void 0,(function(){var n,i;return __generator(this,(function(r){switch(r.label){case 0:return[4,this._getCredentials()];case 1:return(n=r.sent())&&this._config.appId&&this._config.region?(i=(new Date).getTime(),this._generateSession(e),e.event.eventId=Object(a.v1)(),Object.assign(e,{timestamp:i,config:this._config,credentials:n}),e.event.immediate?[2,this._send(e,t)]:(this._putToBuffer(e,t),[2])):(u.debug("cannot send events without credentials, applicationId or region"),[2,t.reject(new Error("No credentials, applicationId or region"))])}}))}))},AWSPinpointProvider.prototype._generateSession=function(e){this._sessionId=this._sessionId||Object(a.v1)();var t=e.event;switch(t.name){case"_session.start":this._sessionStartTimestamp=(new Date).getTime(),this._sessionId=Object(a.v1)(),t.session={Id:this._sessionId,StartTimestamp:new Date(this._sessionStartTimestamp).toISOString()};break;case"_session.stop":var n=(new Date).getTime();this._sessionStartTimestamp=this._sessionStartTimestamp||(new Date).getTime(),this._sessionId=this._sessionId||Object(a.v1)(),t.session={Id:this._sessionId,Duration:n-this._sessionStartTimestamp,StartTimestamp:new Date(this._sessionStartTimestamp).toISOString(),StopTimestamp:new Date(n).toISOString()},this._sessionId=void 0,this._sessionStartTimestamp=void 0;break;default:this._sessionStartTimestamp=this._sessionStartTimestamp||(new Date).getTime(),this._sessionId=this._sessionId||Object(a.v1)(),t.session={Id:this._sessionId,StartTimestamp:new Date(this._sessionStartTimestamp).toISOString()}}},AWSPinpointProvider.prototype._send=function(e,t){return __awaiter(this,void 0,void 0,(function(){var n;return __generator(this,(function(i){switch(n=e.event,e.config,n.name){case"_update_endpoint":return[2,this._updateEndpoint(e,t)];case"_session.stop":return[2,this._pinpointSendStopSession(e,t)];default:return[2,this._record(e,t)]}return[2]}))}))},AWSPinpointProvider.prototype._generateBatchItemContext=function(e){var t=e.event,n=e.timestamp,i=e.config,r=(e.credentials,t.name),s=t.attributes,o=t.metrics,a=t.eventId,c=t.session,u=i.appId,d=i.endpointId,l={ApplicationId:u,EventsRequest:{BatchItem:{}}};l.EventsRequest.BatchItem[d]={};var f=l.EventsRequest.BatchItem[d];return f.Endpoint={},f.Events={},f.Events[a]={EventType:r,Timestamp:new Date(n).toISOString(),Attributes:s,Metrics:o,Session:c},l},AWSPinpointProvider.prototype._pinpointPutEvents=function(e,t){return __awaiter(this,void 0,void 0,(function(){var n,i,r,s,o=this;return __generator(this,(function(a){return n=e.event.eventId,i=e.config.endpointId,r=this._generateBatchItemContext(e),(s=this.pinpointClient.putEvents(r)).on("build",(function(){s.httpRequest.path=s.httpRequest.path+"/legacy"})),s.send((function(r,s){if(r)return u.error("record event failed. ",r),u.warn('If you have not updated your Pinpoint IAM Policy with the Action: "mobiletargeting:PutEvents" yet, please do it. This action is not necessary for now but in order to avoid breaking changes in the future, please update it as soon as possible.'),t.reject(r);var a=i,c=n,f=s.EventsResponse.Results[a].EventsItemResponse[c],p=f.StatusCode,h=f.Message;return l.includes(p)?(o._endpointGenerating=!1,u.debug("record event success. ",s),t.resolve(s)):d.includes(p)?void o._retry(e,t):(u.error("Event "+n+" is not accepted, the error is "+h),t.reject(s))})),[2]}))}))},AWSPinpointProvider.prototype._pinpointSendStopSession=function(e,t){if(f){var n=this._generateBatchItemContext(e),r=this._config.region,s=n.ApplicationId,o=n.EventsRequest,a={secret_key:this._config.credentials.secretAccessKey,access_key:this._config.credentials.accessKeyId,session_token:this._config.credentials.sessionToken},c="https://pinpoint."+r+".amazonaws.com/v1/apps/"+s+"/events",u=JSON.stringify(o),d={url:c,body:u,method:"POST"},l={region:r,service:"mobiletargeting"},p=i.m.signUrl(d,a,l,null);return navigator.sendBeacon(p,u)?t.resolve("sendBeacon success"):t.reject("sendBeacon failure")}this._record(e,t)},AWSPinpointProvider.prototype._retry=function(e,t){var n=e.config.resendLimit;e.resendLimit="number"==typeof e.resendLimit?e.resendLimit:n,e.resendLimit-- >0?(u.debug("resending event "+e.eventName+" with "+e.resendLimit+" retry times left"),this._putToBuffer(e,t)):u.debug("retry times used up for event "+e.eventName)},AWSPinpointProvider.prototype._record=function(e,t){return __awaiter(this,void 0,void 0,(function(){var n,i;return __generator(this,(function(r){return e.event,e.timestamp,n=e.config,i=e.credentials,this._initClients(n,i),[2,this._pinpointPutEvents(e,t)]}))}))},AWSPinpointProvider.prototype._updateEndpoint=function(e,t){return __awaiter(this,void 0,void 0,(function(){var n,r,s,o,a,c,d,l,f=this;return __generator(this,(function(p){return e.timestamp,n=e.config,r=e.credentials,s=e.event,o=n.appId,n.region,a=n.endpointId,this._initClients(n,r),c=this._endpointRequest(n,i.h.transferKeyToLowerCase(s,[],["attributes","userAttributes","Attributes","UserAttributes"])),d={ApplicationId:o,EndpointId:a,EndpointRequest:c},l=this,u.debug("updateEndpoint with params: ",d),l.pinpointClient.updateEndpoint(d,(function(n,i){return n?(u.debug("updateEndpoint failed",n),n.message.startsWith("Exceeded maximum endpoint per user count")?void f._removeUnusedEndpoints(o,c.User.UserId).then((function(){u.debug("Remove the unused endpoints successfully"),f._retry(e,t)})).catch((function(e){return u.warn("Failed to remove unused endpoints with error: "+e),u.warn('Please ensure you have updated your Pinpoint IAM Policy with the Action: "mobiletargeting:GetUserEndpoints" in order to get endpoints info of the user'),t.reject(n)})):t.reject(n)):(u.debug("updateEndpoint success",i),f._endpointGenerating=!1,t.resolve(i))})),[2]}))}))},AWSPinpointProvider.prototype._removeUnusedEndpoints=function(e,t){return __awaiter(this,void 0,void 0,(function(){var n=this;return __generator(this,(function(i){return[2,new Promise((function(i,r){n.pinpointClient.getUserEndpoints({ApplicationId:e,UserId:t},(function(s,o){if(s)return u.debug("Failed to get endpoints associated with the userId: "+t+" with error",s),r(s);var a=o.EndpointsResponse.Item;u.debug("get endpoints associated with the userId: "+t+" with data",a);for(var c=a[0],d=1;d<a.length;d++){var l=Date.parse(c.EffectiveDate),f=Date.parse(a[d].EffectiveDate);if(isNaN(l))break;if(isNaN(f)){c=a[d];break}f<l&&(c=a[d])}var p={ApplicationId:e,EndpointId:c.Id,EndpointRequest:{User:{UserId:""}}};n.pinpointClient.updateEndpoint(p,(function(e,t){return e?(u.debug("Failed to update the endpoint",e),r(e)):(u.debug("The old endpoint is updated with an empty string for user id"),i(t))}))}))}))]}))}))},AWSPinpointProvider.prototype._initClients=function(e,t){return __awaiter(this,void 0,void 0,(function(){var n;return __generator(this,(function(o){return u.debug("init clients"),this.mobileAnalytics&&this.pinpointClient&&this._config.credentials&&this._config.credentials.sessionToken===t.sessionToken&&this._config.credentials.identityId===t.identityId?(u.debug("no change for aws credentials, directly return from init"),[2]):(this._config.credentials=t,n=e.region,u.debug("init clients with credentials",t),this.mobileAnalytics=new r({credentials:t,region:n}),this.pinpointClient=new s({region:n,credentials:t}),i.k.isReactNative&&this.pinpointClient.customizeRequests((function(e){e.on("build",(function(e){e.httpRequest.headers["user-agent"]=i.k.userAgent}))})),[2])}))}))},AWSPinpointProvider.prototype._getEndpointId=function(e){return __awaiter(this,void 0,void 0,(function(){var t;return __generator(this,(function(n){switch(n.label){case 0:return[4,o.a.getItem(e)];case 1:return t=n.sent(),u.debug("endpointId from cache",t,"type",typeof t),t||(t=Object(a.v1)(),o.a.setItem(e,t)),[2,t]}}))}))},AWSPinpointProvider.prototype._endpointRequest=function(e,t){var n=e.credentials,r=this._clientInfo||{},s=e.clientContext||{},o=e.endpoint||{},c={appVersion:r.appVersion,make:r.make,model:r.model,modelVersion:r.version,platform:r.platform},u=(s.clientId,s.appTitle,s.appVersionName,s.appVersionCode,s.appPackageName,__rest(s,["clientId","appTitle","appVersionName","appVersionCode","appPackageName"])),d=t.address?"android"===r.platform?"GCM":"APNS":void 0,l=__assign(__assign(__assign({channelType:d,requestId:Object(a.v1)(),effectiveDate:(new Date).toISOString()},o),t),{attributes:__assign(__assign({},o.attributes),t.attributes),demographic:__assign(__assign(__assign(__assign({},c),u),o.demographic),t.demographic),location:__assign(__assign({},o.location),t.location),metrics:__assign(__assign({},o.metrics),t.metrics),user:{userId:t.userId||o.userId||n.identityId,userAttributes:__assign(__assign({},o.userAttributes),t.userAttributes)}}),f=(l.userId,l.userAttributes,l.name,l.session,l.eventId,l.immediate,__rest(l,["userId","userAttributes","name","session","eventId","immediate"]));return i.h.transferKeyToUpperCase(f,[],["metrics","userAttributes","attributes"])},AWSPinpointProvider.prototype._getCredentials=function(){return i.e.get().then((function(e){return e?(u.debug("set credentials for analytics",e),i.e.shear(e)):null})).catch((function(e){return u.debug("ensure credentials error",e),null}))},AWSPinpointProvider.category="Analytics",AWSPinpointProvider.providerName="AWSPinpoint",AWSPinpointProvider}(),_=[],m=function(){function MethodEmbed(e,t){this.context=e,this.methodName=t,this._originalMethod=e[t].bind(e)}return MethodEmbed.add=function(e,t,n){getInstance(e,t).set(n)},MethodEmbed.remove=function(e,t){getInstance(e,t).remove()},MethodEmbed.prototype.set=function(e){var t=this;this.context[this.methodName]=function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];return e(t._originalMethod.apply(t,n))}},MethodEmbed.prototype.remove=function(){this.context[this.methodName]=this._originalMethod},MethodEmbed}(),y=m;function getInstance(e,t){var n=_.filter((function(n){return n.context===e&&n.methodName===t}))[0];return n||(n=new m(e,t),_.push(n)),n}var PageViewTracker_awaiter=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},PageViewTracker_generator=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:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(s){return function(a){return function step(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]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},w=new i.c("PageViewTracker"),P="aws-amplify-analytics-prevUrl",I={enable:!1,provider:"AWSPinpoint",getUrl:function(){return i.h.browserOrNode().isBrowser?window.location.origin+window.location.pathname:""}},S=function(){function PageViewTracker(e,t){w.debug("initialize pageview tracker with opts",t),this._config=Object.assign({},I,t),this._tracker=e,this._hasEnabled=!1,this._trackFunc=this._trackFunc.bind(this),"SPA"===this._config.type?this._pageViewTrackSPA():this._pageViewTrackDefault()}return PageViewTracker.prototype.configure=function(e){return Object.assign(this._config,e),"SPA"===this._config.type&&this._pageViewTrackSPA(),this._config},PageViewTracker.prototype._isSameUrl=function(){return sessionStorage.getItem(P)===this._config.getUrl()&&(w.debug("the url is same"),!0)},PageViewTracker.prototype._pageViewTrackDefault=function(){return PageViewTracker_awaiter(this,void 0,void 0,(function(){var e,t,n,r;return PageViewTracker_generator(this,(function(s){switch(s.label){case 0:return i.h.browserOrNode().isBrowser&&window.addEventListener&&window.sessionStorage?(e=this._config.getUrl(),"function"!=typeof this._config.attributes?[3,2]:[4,this._config.attributes()]):(w.debug("not in the supported web enviroment"),[2]);case 1:return n=s.sent(),[3,3];case 2:n=this._config.attributes,s.label=3;case 3:return t=n,r=Object.assign({url:e},t),this._config.enable&&!this._isSameUrl()&&(this._tracker({name:this._config.eventName||"pageView",attributes:r},this._config.provider).catch((function(e){w.debug("Failed to record the page view event",e)})),sessionStorage.setItem(P,e)),[2]}}))}))},PageViewTracker.prototype._trackFunc=function(){return PageViewTracker_awaiter(this,void 0,void 0,(function(){var e,t,n,r;return PageViewTracker_generator(this,(function(s){switch(s.label){case 0:return i.h.browserOrNode().isBrowser&&window.addEventListener&&history.pushState&&window.sessionStorage?(e=this._config.getUrl(),"function"!=typeof this._config.attributes?[3,2]:[4,this._config.attributes()]):(w.debug("not in the supported web enviroment"),[2]);case 1:return n=s.sent(),[3,3];case 2:n=this._config.attributes,s.label=3;case 3:return t=n,r=Object.assign({url:e},t),this._isSameUrl()||(this._tracker({name:this._config.eventName||"pageView",attributes:r},this._config.provider).catch((function(e){w.debug("Failed to record the page view event",e)})),sessionStorage.setItem(P,e)),[2]}}))}))},PageViewTracker.prototype._pageViewTrackSPA=function(){i.h.browserOrNode().isBrowser&&window.addEventListener&&history.pushState?this._config.enable&&!this._hasEnabled?(y.add(history,"pushState",this._trackFunc),y.add(history,"replaceState",this._trackFunc),window.addEventListener("popstate",this._trackFunc),this._trackFunc(),this._hasEnabled=!0):(y.remove(history,"pushState"),y.remove(history,"replaceState"),window.removeEventListener("popstate",this._trackFunc),this._hasEnabled=!1):w.debug("not in the supported web enviroment")},PageViewTracker}(),E=i.h.browserOrNode().isBrowser&&window.Element?window.Element.prototype:null,A=E?E.matches||E.matchesSelector||E.webkitMatchesSelector||E.mozMatchesSelector||E.msMatchesSelector||E.oMatchesSelector:null;function matches(e,t){if(e&&1===e.nodeType&&t){if("string"==typeof t||1===t.nodeType)return e===t||matchesSelector(e,t);if("length"in t)for(var n=0,i=void 0;i=t[n];n++)if(e===i||matchesSelector(e,i))return!0}return!1}function matchesSelector(e,t){if("string"!=typeof t)return!1;if(A)return A.call(e,t);for(var n=e.parentNode.querySelectorAll(t),i=0,r=void 0;r=n[i];i++)if(r===e)return!0;return!1}function delegate(e,t,n,i,r){void 0===r&&(r={});var listener=function(e){var t;if(r.composed&&"function"==typeof e.composedPath)for(var s=e.composedPath(),o=0,a=void 0;a=s[o];o++)1===a.nodeType&&matches(a,n)&&(t=a);else t=function closest(e,t,n){if(void 0===n&&(n=!1),e&&1===e.nodeType&&t)for(var i,r=(n?[e]:[]).concat(function parents(e){for(var t=[],n=e;n&&n.parentNode&&1===n.parentNode.nodeType;)n=n.parentNode,t.push(n);return t}(e)),s=0;i=r[s];s++)if(matches(i,t))return i}(e.target,n,!0);t&&i.call(t,e,t)};return e.addEventListener(t,listener,r.useCapture),{destroy:function(){e.removeEventListener(t,listener,r.useCapture)}}}var k="80",T="443";RegExp(":("+k+"|"+T+")$"),i.h.browserOrNode().isBrowser&&document.createElement("a");var O,j,C,EventTracker_awaiter=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},EventTracker_generator=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:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(s){return function(a){return function step(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]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},z=new i.c("EventTracker"),M={enable:!1,events:["click"],selectorPrefix:"data-amplify-analytics-",provider:"AWSPinpoint"},x=function(){function EventTracker(e,t){i.h.browserOrNode().isBrowser&&window.addEventListener?(this._config=Object.assign({},M,t),this._tracker=e,this._delegates={},this._trackFunc=this._trackFunc.bind(this),z.debug("initialize pageview tracker with opts",this._config),this.configure(this._config)):z.debug("not in the supported web environment")}return EventTracker.prototype.configure=function(e){var t=this;if(Object.assign(this._config,e),this._config.enable){if(this._config.enable&&0===Object.keys(this._delegates).length){var n="["+this._config.selectorPrefix+"on]";this._config.events.forEach((function(e){t._delegates[e]=delegate(document,e,n,t._trackFunc,{composed:!0,useCapture:!0})}))}}else Object.keys(this._delegates).forEach((function(e){"function"==typeof t._delegates[e].destroy&&t._delegates[e].destroy()})),this._delegates={};return this._config},EventTracker.prototype._trackFunc=function(e,t){return EventTracker_awaiter(this,void 0,void 0,(function(){var n,i,r,s,o,a,c;return EventTracker_generator(this,(function(u){switch(u.label){case 0:return n={},i=t.getAttribute(this._config.selectorPrefix+"on").split(/\s*,\s*/),r=t.getAttribute(this._config.selectorPrefix+"name"),(s=t.getAttribute(this._config.selectorPrefix+"attrs"))&&s.split(/\s*,\s*/).forEach((function(e){var t=e.trim().split(/\s*:\s*/);n[t[0]]=t[1]})),"function"!=typeof this._config.attributes?[3,2]:[4,this._config.attributes()];case 1:return a=u.sent(),[3,3];case 2:a=this._config.attributes,u.label=3;case 3:return o=a,c=Object.assign({type:e.type,target:e.target.localName+" with id "+e.target.id},o,n),z.debug("events needed to be recorded",i),z.debug("attributes needed to be attached",n),i.indexOf(e.type)<0?(z.debug("event "+e.type+" is not selected to be recorded"),[2]):(this._tracker({name:r||"event",attributes:c},this._config.provider).catch((function(t){z.debug("Failed to record the "+e.type+" event', "+t)})),[2])}}))}))},EventTracker}(),SessionTracker_awaiter=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},SessionTracker_generator=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:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(s){return function(a){return function step(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]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},N=new i.c("SessionTracker"),D={enable:!1,provider:"AWSPinpoint"},W=!1,F=function(){function SessionTracker(e,t){this._config=Object.assign({},D,t),this._tracker=e,this._hasEnabled=!1,this._trackFunc=this._trackFunc.bind(this),this._trackBeforeUnload=this._trackBeforeUnload.bind(this),this.configure(this._config)}return SessionTracker.prototype._envCheck=function(){if(!i.h.browserOrNode().isBrowser)return!1;if(!document||!document.addEventListener)return N.debug("not in the supported web environment"),!1;if(void 0!==document.hidden)this._hidden="hidden",this._visibilityChange="visibilitychange";else if(void 0!==document.msHidden)this._hidden="msHidden",this._visibilityChange="msvisibilitychange";else{if(void 0===document.webkitHidden)return N.debug("not in the supported web environment"),!1;this._hidden="webkitHidden",this._visibilityChange="webkitvisibilitychange"}return!0},SessionTracker.prototype._trackFunc=function(){return SessionTracker_awaiter(this,void 0,void 0,(function(){var e,t,n;return SessionTracker_generator(this,(function(i){switch(i.label){case 0:return"function"!=typeof this._config.attributes?[3,2]:[4,this._config.attributes()];case 1:return t=i.sent(),[3,3];case 2:t=this._config.attributes,i.label=3;case 3:return e=t,n=Object.assign({},e),document.visibilityState===this._hidden?this._tracker({name:"_session.stop",attributes:n},this._config.provider).catch((function(e){N.debug("record session stop event failed.",e)})):this._tracker({name:"_session.start",attributes:n},this._config.provider).catch((function(e){N.debug("record session start event failed.",e)})),[2]}}))}))},SessionTracker.prototype._trackBeforeUnload=function(e){var t=this;("function"==typeof this._config.attributes?Promise.resolve(this._config.attributes()):Promise.resolve(this._config.attributes)).then((function(e){var n=Object.assign({},e);t._tracker({name:"_session.stop",attributes:n,immediate:!0},t._config.provider).catch((function(e){N.debug("record session stop event failed.",e)}))}))},SessionTracker.prototype._sendInitialEvent=function(){return SessionTracker_awaiter(this,void 0,void 0,(function(){var e,t,n;return SessionTracker_generator(this,(function(i){switch(i.label){case 0:return W?(N.debug("the start session has been sent when the page is loaded"),[2]):(W=!0,"function"!=typeof this._config.attributes?[3,2]:[4,this._config.attributes()]);case 1:return t=i.sent(),[3,3];case 2:t=this._config.attributes,i.label=3;case 3:return e=t,n=Object.assign({},e),this._tracker({name:"_session.start",attributes:n},this._config.provider).catch((function(e){N.debug("record session start event failed.",e)})),[2]}}))}))},SessionTracker.prototype.configure=function(e){return this._envCheck()?(Object.assign(this._config,e),this._config.enable&&!this._hasEnabled?(this._sendInitialEvent(),document.addEventListener(this._visibilityChange,this._trackFunc,!1),window.addEventListener("beforeunload",this._trackBeforeUnload,!1),this._hasEnabled=!0):!this._config.enable&&this._hasEnabled&&(document.removeEventListener(this._visibilityChange,this._trackFunc,!1),window.removeEventListener("beforeunload",this._trackBeforeUnload,!1),this._hasEnabled=!1),this._config):this._config},SessionTracker}(),Analytics_assign=function(){return(Analytics_assign=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},Analytics_awaiter=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},Analytics_generator=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:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(s){return function(a){return function step(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]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},B=new i.c("AnalyticsClass"),V="undefined"!=typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("amplify_default"):"@@amplify_default",R={pageView:S,event:x,session:F},L=function(){function AnalyticsClass(){this._config={},this._pluggables=[],this._disabled=!1,this._trackers={},this.record=this.record.bind(this)}return AnalyticsClass.prototype.getModuleName=function(){return"Analytics"},AnalyticsClass.prototype.configure=function(e){var t=this;if(!e)return this._config;B.debug("configure Analytics",e);var n,r,s,o=i.j.parseMobilehubConfig(e);return this._config=Object.assign({},this._config,o.Analytics,e),this._config.disabled&&(this._disabled=!0),this._pluggables.forEach((function(e){var n="AWSPinpoint"!==e.getProviderName()||t._config.AWSPinpoint?t._config[e.getProviderName()]:t._config;e.configure(Analytics_assign({disabled:t._config.disabled},n))})),0===this._pluggables.length&&this.addPluggable(new b),void 0===this._config.autoSessionRecord&&(this._config.autoSessionRecord=!0),n="configured",r=null,s="The Analytics category has been configured successfully",i.f.dispatch("analytics",{event:n,data:r,message:s},"Analytics",V),B.debug("current configuration",this._config),this._config},AnalyticsClass.prototype.addPluggable=function(e){if(e&&"Analytics"===e.getCategory()){this._pluggables.push(e);var t="AWSPinpoint"!==e.getProviderName()||this._config.AWSPinpoint?this._config[e.getProviderName()]:this._config,n=Analytics_assign({disabled:this._config.disabled},t);return e.configure(n),n}},AnalyticsClass.prototype.getPluggable=function(e){for(var t=0;t<this._pluggables.length;t+=1){var n=this._pluggables[t];if(n.getProviderName()===e)return n}return B.debug("No plugin found with providerName",e),null},AnalyticsClass.prototype.removePluggable=function(e){for(var t=0;t<this._pluggables.length&&this._pluggables[t].getProviderName()!==e;)t+=1;return t===this._pluggables.length?void B.debug("No plugin found with providerName",e):void this._pluggables.splice(t,t+1)},AnalyticsClass.prototype.disable=function(){this._disabled=!0},AnalyticsClass.prototype.enable=function(){this._disabled=!1},AnalyticsClass.prototype.startSession=function(e){return Analytics_awaiter(this,void 0,void 0,(function(){var t;return Analytics_generator(this,(function(n){return t={event:{name:"_session.start"},provider:e},[2,this._sendEvent(t)]}))}))},AnalyticsClass.prototype.stopSession=function(e){return Analytics_awaiter(this,void 0,void 0,(function(){var t;return Analytics_generator(this,(function(n){return t={event:{name:"_session.stop"},provider:e},[2,this._sendEvent(t)]}))}))},AnalyticsClass.prototype.record=function(e,t,n){return Analytics_awaiter(this,void 0,void 0,(function(){var i,r;return Analytics_generator(this,(function(s){return this.isAnalyticsConfigured()?(r=null,r="string"==typeof e?{event:{name:e,attributes:t,metrics:n},provider:"AWSPinpoint"}:{event:e,provider:t},[2,this._sendEvent(r)]):(i="Analytics has not been configured",B.debug(i),[2,Promise.reject(new Error(i))])}))}))},AnalyticsClass.prototype.updateEndpoint=function(e,t){return Analytics_awaiter(this,void 0,void 0,(function(){var n;return Analytics_generator(this,(function(i){return n=Object.assign({name:"_update_endpoint"},e),[2,this.record(n,t)]}))}))},AnalyticsClass.prototype._sendEvent=function(e){var t=this;if(!this.isAnalyticsConfigured()){var n="Analytics has not been configured";return B.debug(n),Promise.reject(new Error(n))}if(this._disabled)return B.debug("Analytics has been disabled"),Promise.resolve();var i=e.provider?e.provider:"AWSPinpoint";return new Promise((function(n,r){t._pluggables.forEach((function(t){t.getProviderName()===i&&t.record(e,{resolve:n,reject:r})}))}))},AnalyticsClass.prototype.autoTrack=function(e,t){if(R[e]){"session"===e&&(this._config.autoSessionRecord=t.enable);var n=this._trackers[e];n?n.configure(t):this._trackers[e]=new R[e](this.record,t)}else B.debug("invalid tracker type")},AnalyticsClass.prototype.isAnalyticsConfigured=function(){return this._config&&Object.entries(this._config).length>0},AnalyticsClass}(),U=n("../node_modules/aws-sdk/clients/kinesis.js"),AWSKinesisProvider_awaiter=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},AWSKinesisProvider_generator=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:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(s){return function(a){return function step(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]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},K=new i.c("AWSKineisProvider"),q=1e3,G=100,Y=5e3,H=5,J=(function(){function AWSKinesisProvider(e){this._buffer=[],this._config=e||{},this._config.bufferSize=this._config.bufferSize||q,this._config.flushSize=this._config.flushSize||G,this._config.flushInterval=this._config.flushInterval||Y,this._config.resendLimit=this._config.resendLimit||H;this._setupTimer()}AWSKinesisProvider.prototype._setupTimer=function(){var e=this;this._timer&&clearInterval(this._timer);var t=this._config,n=t.flushSize,i=t.flushInterval,r=this;this._timer=setInterval((function(){for(var t=e._buffer.length<n?e._buffer.length:n,i=[],s=0;s<t;s+=1){var o=e._buffer.shift();i.push(o)}r._sendFromBuffer(i)}),i)},AWSKinesisProvider.prototype.getCategory=function(){return"Analytics"},AWSKinesisProvider.prototype.getProviderName=function(){return"AWSKinesis"},AWSKinesisProvider.prototype.configure=function(e){K.debug("configure Analytics",e);var t=e||{};return this._config=Object.assign({},this._config,t),this._setupTimer(),this._config},AWSKinesisProvider.prototype.record=function(e){return AWSKinesisProvider_awaiter(this,void 0,void 0,(function(){var t;return AWSKinesisProvider_generator(this,(function(n){switch(n.label){case 0:return[4,this._getCredentials()];case 1:return(t=n.sent())?(Object.assign(e,{config:this._config,credentials:t}),[2,this._putToBuffer(e)]):[2,Promise.resolve(!1)]}}))}))},AWSKinesisProvider.prototype.updateEndpoint=function(e){return K.debug("updateEndpoint is not implemented in Kinesis provider"),Promise.resolve(!0)},AWSKinesisProvider.prototype._putToBuffer=function(e){return this._buffer.length<q?(this._buffer.push(e),Promise.resolve(!0)):(K.debug("exceed analytics events buffer size"),Promise.reject(!1))},AWSKinesisProvider.prototype._sendFromBuffer=function(e){for(var t=this,n=[],i=null,r=[],s=0;s<e.length;s+=1){var o=e[s].credentials;0===s?(r.push(e[s]),i=o):o.sessionToken===i.sessionToken&&o.identityId===i.identityId?(K.debug("no change for cred, put event in the same group"),r.push(e[s])):(n.push(r),(r=[]).push(e[s]),i=o)}n.push(r),n.map((function(e){t._sendEvents(e)}))},AWSKinesisProvider.prototype._sendEvents=function(e){var t=this;if(0!==e.length){var n=e[0],i=n.config,r=n.credentials;if(!this._init(i,r))return!1;var s={};e.map((function(e){var t=e.event,n=t.streamName;void 0===s[n]&&(s[n]=[]);var i={Data:JSON.stringify(t.data),PartitionKey:t.partitionKey||"partition-"+r.identityId};s[n].push(i)})),Object.keys(s).map((function(e){K.debug("putting records to kinesis with records",s[e]),t._kinesis.putRecords({Records:s[e],StreamName:e},(function(t,n){t?K.debug("Failed to upload records to Kinesis",t):K.debug("Upload records to stream",e)}))}))}},AWSKinesisProvider.prototype._init=function(e,t){if(K.debug("init clients"),this._kinesis&&this._config.credentials&&this._config.credentials.sessionToken===t.sessionToken&&this._config.credentials.identityId===t.identityId)return K.debug("no change for analytics config, directly return from init"),!0;this._config.credentials=t;var n=e.region;return K.debug("initialize kinesis with credentials",t),this._kinesis=new U({apiVersion:"2013-12-02",region:n,credentials:t}),!0},AWSKinesisProvider.prototype._getCredentials=function(){var e=this;return i.e.get().then((function(t){return t?(K.debug("set credentials for analytics",e._config.credentials),i.e.shear(t)):null})).catch((function(e){return K.debug("ensure credentials error",e),null}))}}(),n("../node_modules/aws-sdk/clients/personalizeevents.js")),Z=n("../node_modules/lodash/lodash.js"),$=(new i.c("AmazonPersonalizeProvider"),function(){function SessionInfoManager(e){void 0===e&&(e=""),this._isBrowser=i.h.browserOrNode().isBrowser,this._timerKey=Object(a.v1)().substr(0,15),this._refreshTimer()}return SessionInfoManager.prototype._refreshTimer=function(){this._timer&&clearInterval(this._timer);var e=this;this._timer=setInterval((function(){e._timerKey=Object(a.v1)().substr(0,15)}),3e4)},SessionInfoManager.prototype.storeValue=function(e,t){var n=new Date,i=new Date;i.setTime(n.getTime()+6048e5),o.a.setItem(this._getCachePrefix(e),t,{expires:i.getTime()})},SessionInfoManager.prototype.retrieveValue=function(e){return o.a.getItem(this._getCachePrefix(e))},SessionInfoManager.prototype._getCachePrefix=function(e){return this._isBrowser?e+"."+window.location.host:"peronslize"},SessionInfoManager.prototype.getTimerKey=function(){return this._timerKey},SessionInfoManager.prototype.updateSessionInfo=function(e,t){var n=t.userId,i=t.sessionId;if(this._isRequireNewSession(e,n,i)){var r=Object(a.v1)();this.storeValue("_awsct_uid",e),this.storeValue("_awsct_sid",r),t.sessionId=r}else this._isRequireUpdateSessionInfo(e,n,i)&&this.storeValue("_awsct_uid",e);t.userId=e},SessionInfoManager.prototype._isRequireUpdateSessionInfo=function(e,t,n){return!Object(Z.isEmpty)(n)&&Object(Z.isEmpty)(t)&&!Object(Z.isEmpty)(e)},SessionInfoManager.prototype.retrieveSessionInfo=function(e){var t={};return t.trackingId=e,t.sessionId=this.retrieveValue("_awsct_sid"),t.userId=this.retrieveValue("_awsct_uid"),Object(Z.isEmpty)(t.sessionId)&&(t.sessionId=Object(a.v1)(),this.storeValue("_awsct_sid",t.sessionId)),this.storeValue("_awsct",e),t},SessionInfoManager.prototype._isRequireNewSession=function(e,t,n){var i=Object(Z.isEmpty)(n),r=Object(Z.isEmpty)(e)&&!Object(Z.isEmpty)(t),s=!Object(Z.isEmpty)(e)&&!Object(Z.isEmpty)(t)&&!Object(Z.isEqual)(e,t);return i||r||s},SessionInfoManager}());!function(e){e.PLAY="play",e.PAUSE="pause",e.ENDED="Ended"}(O||(O={})),function(e){e.IFRAME="IFRAME",e.VIDEO="VIDEO",e.AUDIO="AUDIO"}(j||(j={})),function(e){e.PLAY="Play",e.ENDED="Ended",e.PAUSE="Pause",e.TIME_WATCHED="TimeWatched"}(C||(C={}));var Q=function(){function MediaAutoTrack(e,t){var n;this.eventActionMapping=((n={})[C.ENDED]=this.endedEventAction.bind(this),n[C.PLAY]=this.playEventAction.bind(this),n[C.PAUSE]=this.pauseEventAction.bind(this),n);var i=e.eventData;this._params=e,this._mediaElement=document.getElementById(i.properties.domElementId),this._started=!1,this._provider=t,{IFRAME:this._iframeMediaTracker,VIDEO:this._html5MediaTracker,AUDIO:this._html5MediaTracker}[this._mediaElement.tagName].bind(this)(),this._initYoutubeFrame()}return MediaAutoTrack.prototype._initYoutubeFrame=function(){this._youTubeIframeLoader={src:"https://www.youtube.com/iframe_api",loading:!1,loaded:!1,listeners:[],load:function(e){var t=this;if(this.listeners.push(e),this.loaded)setTimeout((function(){t.done()}));else if(!this.loading){this.loading=!0,window.onYouTubeIframeAPIReady=function(){t.loaded=!0,t.done()};var n=document.createElement("script");n.type="text/javascript",n.src=this.src,document.body.appendChild(n)}},done:function(){for(delete window.onYouTubeIframeAPIReady;this.listeners.length;)this.listeners.pop()(window.YT)}}},MediaAutoTrack.prototype._iframeMediaTracker=function(){var e=this;setInterval((function(){e._started&&e.recordEvent(j.IFRAME,C.TIME_WATCHED)}),3e3),this._youTubeIframeLoader.load((function(t){e._iframePlayer=new t.Player(e._mediaElement.id,{events:{onStateChange:e._onPlayerStateChange.bind(e)}})}))},MediaAutoTrack.prototype._onPlayerStateChange=function(e){var t={0:C.ENDED,1:C.PLAY,2:C.PAUSE}[e.data];t&&this.eventActionMapping[t](j.IFRAME)},MediaAutoTrack.prototype._html5MediaTracker=function(){var e=this;setInterval((function(){e._started&&e.recordEvent(j.VIDEO,C.TIME_WATCHED)}),3e3),this._mediaElement.addEventListener(O.PLAY,(function(){e.eventActionMapping[C.PLAY](j.VIDEO)}),!1),this._mediaElement.addEventListener(O.PAUSE,(function(){e.eventActionMapping[C.PAUSE](j.VIDEO)}),!1),this._mediaElement.addEventListener(O.ENDED,(function(){e.eventActionMapping[C.ENDED](j.VIDEO)}),!1)},MediaAutoTrack.prototype.playEventAction=function(e){this._started=!0,this.recordEvent(e,C.PLAY)},MediaAutoTrack.prototype.pauseEventAction=function(e){this._started=!1,this.recordEvent(e,C.PAUSE)},MediaAutoTrack.prototype.endedEventAction=function(e){this._started=!1,this.recordEvent(e,C.ENDED)},MediaAutoTrack.prototype.recordEvent=function(e,t){var n=Object.assign({},this._params),i=n.eventData;i.eventType=t,e===j.VIDEO?(i.properties.timestamp=this._mediaElement.currentTime,i.properties.duration=this._mediaElement.duration):(i.properties.timestamp=this._financial(this._iframePlayer.getCurrentTime()),i.properties.duration=this._financial(this._iframePlayer.getDuration()));var r=parseFloat(i.properties.timestamp)/parseFloat(i.properties.duration);i.properties.eventValue=Number(r.toFixed(4)),delete i.properties.domElementId,this._provider.putToBuffer(n)},MediaAutoTrack.prototype._financial=function(e){return Number.parseFloat(e).toFixed(4)},MediaAutoTrack}(),AmazonPersonalizeProvider_awaiter=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function fulfilled(e){try{step(i.next(e))}catch(e){s(e)}}function rejected(e){try{step(i.throw(e))}catch(e){s(e)}}function step(e){e.done?r(e.value):function adopt(e){return e instanceof n?e:new n((function(t){t(e)}))}(e.value).then(fulfilled,rejected)}step((i=i.apply(e,t||[])).next())}))},AmazonPersonalizeProvider_generator=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:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function verb(s){return function(a){return function step(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]<r[3])){o.label=s[1];break}if(6===s[0]&&o.label<r[1]){o.label=r[1],r=s;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(s);break}r[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],i=0}finally{n=r=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}},X=new i.c("AmazonPersonalizeProvider"),ee=5,te=10,ne=5e3,ie=(function(){function AmazonPersonalizeProvider(e){this._buffer=[],this._config=e||{},this._config.flushSize=this._config.flushSize>0&&this._config.flushSize<=te?this._config.flushSize:ee,this._config.flushInterval=this._config.flushInterval||ne,this._sessionManager=new $,Object(Z.isEmpty)(this._config.trackingId)||(this._sessionInfo=this._sessionManager.retrieveSessionInfo(this._config.trackingId)),this._isBrowser=i.h.browserOrNode().isBrowser,this._setupTimer()}AmazonPersonalizeProvider.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)},AmazonPersonalizeProvider.prototype.record=function(e){return AmazonPersonalizeProvider_awaiter(this,void 0,void 0,(function(){var t,n,i,r,s;return AmazonPersonalizeProvider_generator(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(Z.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(Z.isEmpty)(Object(Z.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 Q(s,this):X.debug("Cannot find the media element."),[3,4];case 3:X.debug("Missing domElementId field in 'properties' for MediaAutoTrack event type."),o.label=4;case 4:return[3,6];case 5:X.debug("MediaAutoTrack only for browser"),o.label=6;case 6:return[2];case 7:return[2,this.putToBuffer(s)]}}))}))},AmazonPersonalizeProvider.prototype.loadElement=function(e){return new Promise((function(t,n){return document.getElementById(e)&&document.getElementById(e).clientHeight?t(!0):n(!0)}))},AmazonPersonalizeProvider.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?(c=n,new Promise((function(e){return setTimeout(e,c)}))).then(r.isElementFullyLoaded.bind(null,e,t,n,i-1)).then(s).catch(o):o(a);var c}))}))},AmazonPersonalizeProvider.prototype.getCategory=function(){return"Analytics"},AmazonPersonalizeProvider.prototype.getProviderName=function(){return"AmazonPersonalize"},AmazonPersonalizeProvider.prototype.configure=function(e){X.debug("configure Analytics",e);var t=e||{};return this._config=Object.assign({},this._config,t),Object(Z.isEmpty)(this._config.trackingId)||(this._sessionInfo=this._sessionManager.retrieveSessionInfo(this._config.trackingId)),this._setupTimer(),this._config},AmazonPersonalizeProvider.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},AmazonPersonalizeProvider.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;a<t;a+=1){var c=e.shift(),u=this._generateSingleRecordPayload(c,s);o.push(u)}var d={};d.trackingId=s.trackingId,d.sessionId=s.sessionId,d.userId=s.userId,d.eventList=o,this._personalize.putEvents(d,(function(e,t){e?X.debug("Failed to call putEvents in Personalize",e):X.debug("Put events")}))}}else X.debug("events array is empty, directly return")},AmazonPersonalizeProvider.prototype.putToBuffer=function(e){return this._buffer.length<this._config.flushSize?this._buffer.push(e):(this._buffer.push(e),this._sendFromBuffer()),Promise.resolve(!0)},AmazonPersonalizeProvider.prototype._sendFromBuffer=function(){var e=this,t=this._buffer.length;if(!(t<=0)){for(var n=[],i=null,r=[],s=0;s<t;s+=1){var o=this._buffer.shift(),a=o.credentials,c=o.sessionInfo;0===s?(r.push(o),i=a):Object(Z.isEqual)(c,this._sessionInfo)&&a.sessionToken===i.sessionToken&&a.identityId===i.identityId?(X.debug("no change for cred, put event in the same group"),r.push(o)):(n.push(r),(r=[]).push(o),i=a,this._sessionInfo=c)}n.push(r),n.map((function(t){e._sendEvents(t)}))}},AmazonPersonalizeProvider.prototype._generateSingleRecordPayload=function(e,t){var n=e.eventData,i=e.sentAt,r={};return r.sentAt=i,r.properties=n.properties,r.eventId=this._sessionManager.getTimerKey()+t.sessionId,r.eventType=n.eventType,r},AmazonPersonalizeProvider.prototype._init=function(e,t){if(X.debug("init clients"),this._personalize&&this._config.credentials&&this._config.credentials.sessionToken===t.sessionToken&&this._config.credentials.identityId===t.identityId)return X.debug("no change for analytics config, directly return from init"),!0;this._config.credentials=t;var n=e.region;return X.debug("initialize personalize with credentials",t),this._personalize=new J({apiVersion:"2018-03-22",region:n,credentials:t}),!0},AmazonPersonalizeProvider.prototype._getCredentials=function(){var e=this;return i.e.get().then((function(t){return t?(X.debug("set credentials for analytics",e._config.credentials),i.e.shear(t)):null})).catch((function(e){return X.debug("ensure credentials error",e),null}))}}(),new i.c("Analytics")),re=!1,se=!1,oe=!1,ae=null;ae||(ie.debug("Create Analytics Instance"),ae=new L);var ce=ae;i.o.register(ce);t.a=ce;var lib_esm_listener=function(e){var t=e.channel,n=e.payload;e.source;switch(ie.debug("on hub capsule "+t,n),t){case"auth":authEvent(n);break;case"storage":storageEvent(n);break;case"analytics":analyticsEvent(n)}},storageEvent=function(e){var t=e.data,n=t.attrs,i=t.metrics;n&&oe&&ce.record({name:"Storage",attributes:n,metrics:i}).catch((function(e){ie.debug("Failed to send the storage event automatically",e)}))},authEvent=function(e){var t=e.event;if(t)switch(t){case"signIn":se&&oe&&ce.record({name:"_userauth.sign_in"}).catch((function(e){ie.debug("Failed to send the sign in event automatically",e)}));break;case"signUp":se&&oe&&ce.record({name:"_userauth.sign_up"}).catch((function(e){ie.debug("Failed to send the sign up event automatically",e)}));break;case"signOut":break;case"signIn_failure":se&&oe&&ce.record({name:"_userauth.auth_fail"}).catch((function(e){ie.debug("Failed to send the sign in failure event automatically",e)}));break;case"configured":(se=!0)&&oe&&sendEvents()}},analyticsEvent=function(e){var t=e.event;if(t)switch(t){case"pinpointProvider_configured":oe=!0,se&&oe&&sendEvents()}},sendEvents=function(){var e=ce.configure();!re&&e.autoSessionRecord&&(ce.updateEndpoint({immediate:!0}).catch((function(e){ie.debug("Failed to update the endpoint",e)})),re=!0),ce.autoTrack("session",{enable:e.autoSessionRecord})};i.f.listen("auth",lib_esm_listener),i.f.listen("storage",lib_esm_listener),i.f.listen("analytics",lib_esm_listener)}}]);
//# sourceMappingURL=vendors~App-7KZ9F~cd57acee.chunk.eaa5497fb7f7db0479e3.js.map