/*! For license information please see track.js.LICENSE.txt */ !function(){var e={213:function(e,t,r){var n=r(924).default;function i(){"use strict";e.exports=i=function(){return t},e.exports.__esModule=!0,e.exports.default=e.exports;var t={},r=Object.prototype,o=r.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function p(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{p({},"")}catch(e){p=function(e,t,r){return e[t]=r}}function d(e,t,r,n){var i=t&&t.prototype instanceof y?t:y,o=Object.create(i.prototype),c=new O(n||[]);return a(o,"_invoke",{value:k(e,r,c)}),o}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=d;var h={};function y(){}function v(){}function g(){}var b={};p(b,s,(function(){return this}));var m=Object.getPrototypeOf,w=m&&m(m(C([])));w&&w!==r&&o.call(w,s)&&(b=w);var _=g.prototype=y.prototype=Object.create(b);function S(e){["next","throw","return"].forEach((function(t){p(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){function r(i,a,c,s){var u=f(e[i],e,a);if("throw"!==u.type){var l=u.arg,p=l.value;return p&&"object"==n(p)&&o.call(p,"__await")?t.resolve(p.__await).then((function(e){r("next",e,c,s)}),(function(e){r("throw",e,c,s)})):t.resolve(p).then((function(e){l.value=e,c(l)}),(function(e){return r("throw",e,c,s)}))}s(u.arg)}var i;a(this,"_invoke",{value:function(e,n){function o(){return new t((function(t,i){r(e,n,t,i)}))}return i=i?i.then(o,o):o()}})}function k(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var c=E(a,r);if(c){if(c===h)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=f(e,t,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===h)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}function E(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,E(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var i=f(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,h;var o=i.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,h):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,h)}function P(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function O(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(P,this),this.reset(!0)}function C(e){if(e){var t=e[s];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r=0;--n){var i=this.tryEntries[n],a=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=o.call(i,"catchLoc"),s=o.call(i,"finallyLoc");if(c&&s){if(this.prev=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),h}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;I(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}e.exports=i,e.exports.__esModule=!0,e.exports.default=e.exports},924:function(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},264:function(e,t,r){var n=r(213)();e.exports=n;try{regeneratorRuntime=n}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n](o,o.exports,r),o.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(t){var r=function(t,r){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r);if("object"!==e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"===e(r)?r:String(r)}function n(e,r,n){return(r=t(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function i(e,t,r,n,i,o,a){try{var c=e[o](a),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,i)}function o(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function c(e){i(a,n,o,c,s,"next",e)}function s(e){i(a,n,o,c,s,"throw",e)}c(void 0)}))}}var a=r(264),c=r.n(a);function s(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}var u={API_BASE:"https://webhooks.myperfit.net/track",API_REGISTER_DOMAIN:"https://webhooks.myperfit.net/events/domains/generic/all/3a2e8954/3e2a1161",API_PUSH_SUBSCRIPTION:"https://webhooks.myperfit.net/events/push/generic/subscription/4rt3tmrgre/f5518f90",OPTIN_RULES_API:"https://optinrules.myperfit.net/optinrules/public",app:"",source:"",trackCartUpdates:!1,loadOptinRules:!0},l="PerfitDebugMode",p=!1;function d(e){if(p){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),i=1;ie.length)&&(t=e.length);for(var r=0,n=new Array(t);r1&&(u.privateKey=s[1]),e.abrupt("return",u);case 21:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function k(e,t){return E.apply(this,arguments)}function E(){return(E=o(c().mark((function e(t,r){var n,i,o,a,s,u,l,p;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=[],e.next=3,crypto.subtle.exportKey("jwk",t);case 3:if(i=e.sent,o=w(i.x),a=w(i.y),(s=new Uint8Array(65)).set([4],0),s.set(o,1),s.set(a,33),n.push(s),!r){e.next=16;break}return e.next=14,crypto.subtle.exportKey("jwk",r);case 14:u=e.sent,n.push(w(u.d));case 16:return e.next=18,Promise.all(n);case 18:return l=e.sent,p={publicKey:l[0]},l.length>1&&(p.privateKey=l[1]),e.abrupt("return",p);case 22:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function P(){return crypto.getRandomValues(new Uint8Array(16))}var I={publicKey:"BDd3_hVL9fZi9Ybo2UUzA284WG5FZR30_95YeZJsiApwXKpNcF1rRPF3foIiBHXRdJI2Qhumhf6_LFTeZaNndIo",privateKey:"xKZKYRNdFFn8iQIF2MH54KTfUHwH105zBdzMR7SI3xI"},O=(new URLSearchParams(window.location.search).get("backend"),function(){function e(){v(this,e)}var t;return b(e,null,[{key:"createVapidAuthHeader",value:(t=o(c().mark((function e(t,r,n,i){var o,a,s,u,l,p,d,f,h,y,v;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}return e.abrupt("return",Promise.reject(new Error("Audience must be the origin of the server")));case 2:if(n){e.next=4;break}return e.abrupt("return",Promise.reject(new Error("Subject must be either a mailto or http link")));case 4:return"number"!=typeof i&&(i=Math.floor(Date.now()/1e3+43200)),o=w(t.publicKey),a=w(t.privateKey),r=new URL(r).origin,s={typ:"JWT",alg:"ES256"},u={aud:r,exp:i,sub:n},l=new TextEncoder("utf-8"),p=m(l.encode(JSON.stringify(s)))+"."+m(l.encode(JSON.stringify(u))),d={kty:"EC",crv:"P-256",x:m(o.subarray(1,33)),y:m(o.subarray(33,65)),d:m(a)},e.next=15,crypto.subtle.importKey("jwk",d,{name:"ECDSA",namedCurve:"P-256"},!0,["sign"]);case 15:return f=e.sent,e.next=18,crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},f,l.encode(p));case 18:return h=e.sent,y=p+"."+m(new Uint8Array(h)),v=m(o),e.abrupt("return",{Authorization:"WebPush ".concat(y),"Crypto-Key":"p256ecdsa=".concat(v)});case 22:case"end":return e.stop()}}),e)}))),function(e,r,n,i){return t.apply(this,arguments)})}]),e}()),C=function(){function e(t){v(this,e),this._ikm=t}var t;return b(e,[{key:"sign",value:(t=o(c().mark((function e(t){var r;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,crypto.subtle.importKey("raw",this._ikm,{name:"HMAC",hash:"SHA-256"},!1,["sign"]);case 2:return r=e.sent,e.abrupt("return",crypto.subtle.sign("HMAC",r,t));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})}]),e}(),K=function(){function e(t,r){v(this,e),this._ikm=t,this._salt=r,this._hmac=new C(r)}var t;return b(e,[{key:"generate",value:(t=o(c().mark((function e(t,r){var n,i,o,a;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(n=new Uint8Array(t.byteLength+1)).set(t,0),n.set(new Uint8Array(1).fill(1),t.byteLength),e.next=5,this._hmac.sign(this._ikm);case 5:return i=e.sent,o=new C(i),e.next=9,o.sign(n);case 9:return a=e.sent,e.abrupt("return",a.slice(0,r));case 11:case"end":return e.stop()}}),e,this)}))),function(e,r){return t.apply(this,arguments)})}]),e}(),L=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};v(this,e),this._b64ServerKeys=t.serverKeys,this._b64Salt=t.salt,this._b4VapidKeys=t.vapidKeys}var t,r,n,i,a,s,u,l;return b(e,[{key:"getServerKeys",value:function(){return this._b64ServerKeys?S(w(this._b64ServerKeys.publicKey),w(this._b64ServerKeys.privateKey)):e.generateServerKeys()}},{key:"getSalt",value:function(){return this._b64Salt?w(this._b64Salt):P()}},{key:"getVapidKeys",value:function(){return this._b4VapidKeys?this._b4VapidKeys:I}},{key:"getRequestDetails",value:(l=o(c().mark((function e(t,r){var n,i,o,a,s;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,O.createVapidAuthHeader(this.getVapidKeys(),t.endpoint,"mailto:simple-push-demo@gauntface.co.uk");case 2:return n=e.sent,e.next=5,this.encryptPayload(t,r);case 5:return i=e.sent,o=null,(a={}).TTL=60,i?(o=i.cipherText,a.Encryption="salt=".concat(i.salt),a["Crypto-Key"]="dh=".concat(i.publicServerKey),a["Content-Encoding"]="aesgcm"):a["Content-Length"]=0,n&&Object.keys(n).forEach((function(e){a[e]?a[e]="".concat(a[e],"; ").concat(n[e]):a[e]=n[e]})),s={headers:a,endpoint:t.endpoint},o&&(s.body=o),e.abrupt("return",s);case 14:case"end":return e.stop()}}),e,this)}))),function(e,t){return l.apply(this,arguments)})},{key:"encryptPayload",value:(u=o(c().mark((function e(t,r){var n,i,o,a,s,u,l,p,d,f,h;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r&&0!==r.trim().length){e.next=2;break}return e.abrupt("return",Promise.resolve(null));case 2:return n=this.getSalt(),e.next=5,this.getServerKeys();case 5:return i=e.sent,e.next=8,k(i.publicKey);case 8:return o=e.sent,e.next=11,this._generateEncryptionKeys(t,n,i);case 11:return a=e.sent,e.next=14,crypto.subtle.importKey("raw",a.contentEncryptionKey,"AES-GCM",!0,["decrypt","encrypt"]);case 14:return s=e.sent,a.contentEncryptionCryptoKey=s,u=new Uint8Array(2),l=new TextEncoder("utf-8"),p=l.encode(r),(d=new Uint8Array(u.byteLength+p.byteLength)).set(u,0),d.set(p,u.byteLength),f={name:"AES-GCM",tagLength:128,iv:a.nonce},e.next=26,crypto.subtle.encrypt(f,a.contentEncryptionCryptoKey,d);case 26:return h=e.sent,e.abrupt("return",{cipherText:h,salt:m(n),publicServerKey:m(o.publicKey)});case 28:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"_generateEncryptionKeys",value:(s=o(c().mark((function e(t,r,n){var i,o,a,s,u,l,p;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Promise.all([this._generatePRK(t,n),this._generateCEKInfo(t,n),this._generateNonceInfo(t,n)]);case 2:return i=e.sent,o=i[0],a=i[1],s=i[2],u=new K(o,r),l=new K(o,r),e.next=10,Promise.all([u.generate(a,16),l.generate(s,12)]);case 10:return p=e.sent,e.abrupt("return",{contentEncryptionKey:p[0],nonce:p[1]});case 12:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return s.apply(this,arguments)})},{key:"_generateContext",value:(a=o(c().mark((function e(t,r){var n,i,o,a,s,u,l,p,d;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,S(t.getKey("p256dh"));case 2:return n=e.sent,i={clientPublicKey:n.publicKey,serverPublicKey:r.publicKey},e.next=6,Promise.all([k(i.clientPublicKey),k(i.serverPublicKey)]);case 6:return o=e.sent,a={clientPublicKey:o[0].publicKey,serverPublicKey:o[1].publicKey},s=new TextEncoder("utf-8"),u=s.encode("P-256"),l=new Uint8Array(1).fill(0),(p=new Uint8Array(2))[0]=0,p[1]=a.clientPublicKey.byteLength,(d=new Uint8Array(2))[0]=0,d[1]=a.serverPublicKey.byteLength,e.abrupt("return",_([u,l,p,a.clientPublicKey,d,a.serverPublicKey]));case 18:case"end":return e.stop()}}),e)}))),function(e,t){return a.apply(this,arguments)})},{key:"_generateCEKInfo",value:(i=o(c().mark((function e(t,r){var n,i,o,a;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new TextEncoder("utf-8"),i=n.encode("Content-Encoding: aesgcm"),o=new Uint8Array(1).fill(0),e.next=5,this._generateContext(t,r);case 5:return a=e.sent,e.abrupt("return",_([i,o,a]));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return i.apply(this,arguments)})},{key:"_generateNonceInfo",value:(n=o(c().mark((function e(t,r){var n,i,o,a;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new TextEncoder("utf-8"),i=n.encode("Content-Encoding: nonce"),o=new Uint8Array(1).fill(0),e.next=5,this._generateContext(t,r);case 5:return a=e.sent,e.abrupt("return",_([i,o,a]));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"_generatePRK",value:(r=o(c().mark((function e(t,r){var n,i,o,a;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getSharedSecret(t,r);case 2:return n=e.sent,i=new TextEncoder("utf-8"),o=i.encode("Content-Encoding: auth\0"),a=new K(n,t.getKey("auth")),e.abrupt("return",a.generate(o,32));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"_getSharedSecret",value:(t=o(c().mark((function e(t,r){var n,i;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,S(t.getKey("p256dh"));case 2:if((n=e.sent).publicKey instanceof CryptoKey){e.next=5;break}throw new Error("The publicKey must be a CryptoKey.");case 5:return i={name:"ECDH",namedCurve:"P-256",public:n.publicKey},e.abrupt("return",crypto.subtle.deriveBits(i,r.privateKey,256));case 7:case"end":return e.stop()}}),e)}))),function(e,r){return t.apply(this,arguments)})}],[{key:"generateServerKeys",value:function(){return crypto.subtle.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveBits"])}}]),e}(),U=function(){function e(){v(this,e)}var t;return b(e,null,[{key:"createVapidAuthHeader",value:(t=o(c().mark((function e(t,r,n,i){var o,a,s,u,l,p,d,f,h,y,v;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r){e.next=2;break}return e.abrupt("return",Promise.reject(new Error("Audience must be the origin of the server")));case 2:if(n){e.next=4;break}return e.abrupt("return",Promise.reject(new Error("Subject must be either a mailto or http link")));case 4:return"number"!=typeof i&&(i=Math.floor(Date.now()/1e3+43200)),o=w(t.publicKey),a=w(t.privateKey),r=new URL(r).origin,s={typ:"JWT",alg:"ES256"},u={aud:r,exp:i,sub:n},l=new TextEncoder("utf-8"),p=m(l.encode(JSON.stringify(s)))+"."+m(l.encode(JSON.stringify(u))),d={kty:"EC",crv:"P-256",x:m(o.subarray(1,33)),y:m(o.subarray(33,65)),d:m(a)},e.next=15,crypto.subtle.importKey("jwk",d,{name:"ECDSA",namedCurve:"P-256"},!0,["sign"]);case 15:return f=e.sent,e.next=18,crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},f,l.encode(p));case 18:return h=e.sent,y=p+"."+m(new Uint8Array(h)),v=m(o),e.abrupt("return",{Authorization:"vapid t=".concat(y,", k=").concat(v)});case 22:case"end":return e.stop()}}),e)}))),function(e,r,n,i){return t.apply(this,arguments)})}]),e}(),A=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};v(this,e),this._b64ServerKeys=t.serverKeys,this._b64Salt=t.salt,this._b4VapidKeys=t.vapidKeys}var t,r,n,i,a,s,u;return b(e,[{key:"getServerKeys",value:function(){return this._b64ServerKeys?S(w(this._b64ServerKeys.publicKey),w(this._b64ServerKeys.privateKey)):e.generateServerKeys()}},{key:"getSalt",value:function(){return this._b64Salt?w(this._b64Salt):P()}},{key:"getVapidKeys",value:function(){return this._b4VapidKeys?this._b4VapidKeys:I}},{key:"getRequestDetails",value:(u=o(c().mark((function e(t,r){var n,i,o,a,s,u,l;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=U,i=t.endpoint,e.next=4,n.createVapidAuthHeader(this.getVapidKeys(),t.endpoint,"mailto:simple-push-demo@gauntface.co.uk");case 4:return o=e.sent,e.next=7,this.encryptPayload(t,r);case 7:return a=e.sent,s=null,(u={}).TTL=60,a?(s=a.cipherText,u["Content-Encoding"]="aes128gcm"):u["Content-Length"]=0,o&&Object.keys(o).forEach((function(e){u[e]=o[e]})),l={headers:u,endpoint:i},s&&(l.body=s),e.abrupt("return",l);case 16:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"encryptPayload",value:(s=o(c().mark((function e(t,r){var n,i,o,a,s,u,l,p,d,f,h,y;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r&&0!==r.trim().length){e.next=2;break}return e.abrupt("return",Promise.resolve(null));case 2:return n=this.getSalt(),e.next=5,this.getServerKeys();case 5:return i=e.sent,e.next=8,k(i.publicKey);case 8:return o=e.sent,e.next=11,this._generateEncryptionKeys(t,n,i);case 11:return a=e.sent,e.next=14,crypto.subtle.importKey("raw",a.contentEncryptionKey,"AES-GCM",!0,["decrypt","encrypt"]);case 14:return s=e.sent,a.contentEncryptionCryptoKey=s,u=new TextEncoder("utf-8"),l=u.encode(r),(p=new Uint8Array(1)).fill(0),p[0]=2,d=_([l,p]),f={name:"AES-GCM",tagLength:128,iv:a.nonce},e.next=26,crypto.subtle.encrypt(f,a.contentEncryptionCryptoKey,d);case 26:return h=e.sent,e.next=29,this._addEncryptionContentCodingHeader(h,i,n);case 29:return y=e.sent,e.abrupt("return",{cipherText:y,salt:m(n),publicServerKey:m(o.publicKey)});case 31:case"end":return e.stop()}}),e,this)}))),function(e,t){return s.apply(this,arguments)})},{key:"_addEncryptionContentCodingHeader",value:(a=o(c().mark((function e(t,r,n){var i,o,a,s,u;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,k(r.publicKey);case 2:return i=e.sent,o=new Uint8Array([0,0,16,0]),(a=new Uint8Array(1))[0]=i.publicKey.byteLength,s=[n,o,a,i.publicKey,new Uint8Array(t)],u=_(s),e.abrupt("return",u.buffer);case 9:case"end":return e.stop()}}),e)}))),function(e,t,r){return a.apply(this,arguments)})},{key:"_generateEncryptionKeys",value:(i=o(c().mark((function e(t,r,n){var i,o,a,s,u,l,p;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Promise.all([this._generatePRK(t,n),this._generateCEKInfo(t,n),this._generateNonceInfo(t,n)]);case 2:return i=e.sent,o=i[0],a=i[1],s=i[2],u=new K(o,r),l=new K(o,r),e.next=10,Promise.all([u.generate(a,16),l.generate(s,12)]);case 10:return p=e.sent,e.abrupt("return",{contentEncryptionKey:p[0],nonce:p[1]});case 12:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return i.apply(this,arguments)})},{key:"_generateCEKInfo",value:function(){return _([new TextEncoder("utf-8").encode("Content-Encoding: aes128gcm"),new Uint8Array(1).fill(0)])}},{key:"_generateNonceInfo",value:function(){return _([new TextEncoder("utf-8").encode("Content-Encoding: nonce"),new Uint8Array(1).fill(0)])}},{key:"_generatePRK",value:(n=o(c().mark((function e(t,r){var n,i,o;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._getSharedSecret(t,r);case 2:return n=e.sent,e.next=5,this._getKeyInfo(t,r);case 5:return i=e.sent,o=new K(n,t.getKey("auth")),e.abrupt("return",o.generate(i,32));case 8:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"_getSharedSecret",value:(r=o(c().mark((function e(t,r){var n,i;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,S(t.getKey("p256dh"));case 2:if((n=e.sent).publicKey instanceof CryptoKey){e.next=5;break}throw new Error("The publicKey must be a CryptoKey.");case 5:return i={name:"ECDH",namedCurve:"P-256",public:n.publicKey},e.abrupt("return",crypto.subtle.deriveBits(i,r.privateKey,256));case 7:case"end":return e.stop()}}),e)}))),function(e,t){return r.apply(this,arguments)})},{key:"_getKeyInfo",value:(t=o(c().mark((function e(t,r){var n,i;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=new TextEncoder("utf-8"),e.next=3,k(r.publicKey);case 3:return i=e.sent,e.abrupt("return",_([n.encode("WebPush: info"),new Uint8Array(1).fill(0),new Uint8Array(t.getKey("p256dh")),i.publicKey]));case 5:case"end":return e.stop()}}),e)}))),function(e,r){return t.apply(this,arguments)})}],[{key:"generateServerKeys",value:function(){return crypto.subtle.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveBits"])}}]),e}();function T(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw o}}}}(t);try{for(r.s();!(e=r.n()).done;){var n=e.value;switch(n){case"aes128gcm":return new A;case"aesgcm":return new L;default:console.warn("Unknown content encoding: ".concat(n))}}}catch(e){r.e(e)}finally{r.f()}throw console.error("Failed to find a known encoding: ",t),new Error("Unable to find a known encoding")}}]),e}(),M=function(){function e(t,r,n){v(this,e),this._stateChangeCb=t,this._subscriptionUpdate=r,this._publicApplicationKey=w(n),this._state={UNSUPPORTED:{id:"UNSUPPORTED",interactive:!1,pushEnabled:!1},INITIALISING:{id:"INITIALISING",interactive:!1,pushEnabled:!1},PERMISSION_DENIED:{id:"PERMISSION_DENIED",interactive:!1,pushEnabled:!1},PERMISSION_GRANTED:{id:"PERMISSION_GRANTED",interactive:!0},PERMISSION_PROMPT:{id:"PERMISSION_PROMPT",interactive:!0,pushEnabled:!1},ERROR:{id:"ERROR",interactive:!1,pushEnabled:!1},STARTING_SUBSCRIBE:{id:"STARTING_SUBSCRIBE",interactive:!1,pushEnabled:!0},SUBSCRIBED:{id:"SUBSCRIBED",interactive:!0,pushEnabled:!0},STARTING_UNSUBSCRIBE:{id:"STARTING_UNSUBSCRIBE",interactive:!1,pushEnabled:!1},UNSUBSCRIBED:{id:"UNSUBSCRIBED",interactive:!0,pushEnabled:!1}},"serviceWorker"in navigator?"PushManager"in window?"showNotification"in ServiceWorkerRegistration.prototype?this.init():this._stateChangeCb(this._state.UNSUPPORTED,"Showing Notifications from a service worker is not available on this browser"):this._stateChangeCb(this._state.UNSUPPORTED,"PushManager not available on this browser"):this._stateChangeCb(this._state.UNSUPPORTED,"Service worker not available on this browser")}var t,r,n,i;return b(e,[{key:"init",value:(i=o(c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.serviceWorker.ready;case 2:this._stateChangeCb(this._state.INITIALISING),this.setUpPushPermission();case 4:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"_permissionStateChange",value:function(e){switch(e){case"denied":this._stateChangeCb(this._state.PERMISSION_DENIED);break;case"granted":this._stateChangeCb(this._state.PERMISSION_GRANTED);break;case"default":this._stateChangeCb(this._state.PERMISSION_PROMPT);break;default:console.error("Unexpected permission state: ",e)}}},{key:"setUpPushPermission",value:(n=o(c().mark((function e(){var t,r;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,this._permissionStateChange(Notification.permission),e.next=4,navigator.serviceWorker.ready;case 4:return t=e.sent,e.next=7,t.pushManager.getSubscription();case 7:if(r=e.sent,this._subscriptionUpdate(r),r){e.next=11;break}return e.abrupt("return");case 11:this._stateChangeCb(this._state.SUBSCRIBED),e.next=18;break;case 14:e.prev=14,e.t0=e.catch(0),console.error("setUpPushPermission() ",e.t0),this._stateChangeCb(this._state.ERROR,e.t0);case 18:case"end":return e.stop()}}),e,this,[[0,14]])}))),function(){return n.apply(this,arguments)})},{key:"subscribeDevice",value:(r=o(c().mark((function e(){var t,r;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this._stateChangeCb(this._state.STARTING_SUBSCRIBE),e.prev=1,e.t0=Notification.permission,e.next="denied"===e.t0?5:"granted"===e.t0?6:7;break;case 5:throw new Error("Push messages are blocked.");case 6:return e.abrupt("break",9);case 7:return e.next=9,new Promise((function(e,t){Notification.requestPermission((function(r){"granted"!==r&&t(new Error("Bad permission result")),e()}))}));case 9:return e.prev=9,e.next=12,navigator.serviceWorker.ready;case 12:return t=e.sent,e.next=15,t.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:this._publicApplicationKey});case 15:r=e.sent,this._stateChangeCb(this._state.SUBSCRIBED),this._subscriptionUpdate(r),e.next=24;break;case 20:e.prev=20,e.t1=e.catch(9),console.error("subscribeDevice() ",e.t1),this._stateChangeCb(this._state.ERROR,e.t1);case 24:e.next=30;break;case 26:e.prev=26,e.t2=e.catch(1),console.error("subscribeDevice() ",e.t2),this._permissionStateChange(Notification.permission);case 30:case"end":return e.stop()}}),e,this,[[1,26],[9,20]])}))),function(){return r.apply(this,arguments)})},{key:"unsubscribeDevice",value:(t=o(c().mark((function e(){var t,r;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._stateChangeCb(this._state.STARTING_UNSUBSCRIBE),e.prev=1,e.next=4,navigator.serviceWorker.ready;case 4:return t=e.sent,e.next=7,t.pushManager.getSubscription();case 7:if(r=e.sent){e.next=12;break}return this._stateChangeCb(this._state.UNSUBSCRIBED),this._subscriptionUpdate(null),e.abrupt("return");case 12:return e.next=14,r.unsubscribe();case 14:e.sent||console.warn("We were unable to unregister from push"),this._stateChangeCb(this._state.UNSUBSCRIBED),this._subscriptionUpdate(null),e.next=23;break;case 20:e.prev=20,e.t0=e.catch(1),console.error("Error thrown while revoking push notifications. Most likely because push was never registered",e.t0);case 23:case"end":return e.stop()}}),e,this,[[1,20]])}))),function(){return t.apply(this,arguments)})}]),e}();function B(e,t){var r,n=t;return window.location.href.indexOf(e)>-1&&(n=(r={},window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,(function(e,t,n){return r[t]=n,n})),r)[e]),n}function J(e){for(var t=e+"=",r=document.cookie.split(";"),n=0;n0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];"vtex"===u.source&&(e.product_id=e.product_id||z.getPageProductId(),e.category_id=e.category_id||z.getPageCategoryId()),(e.product_id||e.category_id)&&(t&&(N=!1),N&&e.product_id===N.product_id&&e.category_id===N.category_id||F(e))}function F(e){j&&clearInterval(j),N={product_id:e.product_id||void 0,category_id:e.category_id||void 0},R=0,V(),X()&&(j=setInterval(V,5e3))}function V(){Q("visit",G(G({},N),{},{customer_id:Y.customerId||void 0,contact_id:Y.contactId||void 0,email:Y.email||void 0,visitor_id:Y.visitorId,secs_lapsed:5*R,timestamp:(new Date).toISOString()})),++R>5&&(clearInterval(j),N=null)}var z={getPageProductId:function(){var e,t,r,n;if(dataLayer)return(null===(e=dataLayer.find((function(e){return"Product"===e.pageCategory})))||void 0===e?void 0:e.productId)||(null===(t=dataLayer.find((function(e){return"productDetail"==e.event})))||void 0===t||null===(r=t.ecommerce.detail)||void 0===r||null===(n=r.products[0])||void 0===n?void 0:n.id)},getPageCategoryId:function(){var e,t;if(dataLayer)return(null===(e=dataLayer.find((function(e){return"Product"===e.pageCategory})))||void 0===e?void 0:e.productCategoryId)||(null===(t=dataLayer.find((function(e){return"categoryView"==e.event})))||void 0===t?void 0:t.categoryId)},getUserEmail:function(){var e,t,r;if(dataLayer)return(null===(e=dataLayer.find((function(e){return e.visitorLoginState})))||void 0===e||null===(t=e.visitorContactInfo)||void 0===t?void 0:t[0])||(null===(r=dataLayer.find((function(e){return"userData"==e.event})))||void 0===r?void 0:r.userId)},listenUrlChanges:function(){try{var e=function(){setTimeout((function(){Z(),q({},!1)}),2e3)};window.addEventListener("pushstate",e),window.addEventListener("popstate",e)}catch(e){console.error("Perfit: could not attach to listen url changes")}}},Y={contactId:null,customerId:null,email:null,visitorId:null};function Z(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"vtex"===u.source&&(e.email=e.email||z.getUserEmail()),e.customer_id&&(Y.customerId=e.customer_id),e.email&&(Y.email=e.email),$()}function X(){return Y.contactId||Y.customerId||Y.email}function $(){localStorage.setItem("perfit-session",JSON.stringify(Y))}function Q(e,t){var r="".concat(u.API_BASE,"/").concat(u.source,"/").concat(u.app,"/").concat(e);fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({topic:e,data:t})})}function ee(){fetch(u.API_REGISTER_DOMAIN,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:u.app,domain:window.location.origin})})}var te=function(){function e(){v(this,e),this._encryptionHelper=D.generateHelper(),this._stateChangeListener=this._stateChangeListener.bind(this),this._subscriptionUpdate=this._subscriptionUpdate.bind(this),this._pushClient=new M(this._stateChangeListener,this._subscriptionUpdate,I.publicKey)}var t;return b(e,[{key:"subscribe",value:(t=o(c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._pushClient.subscribeDevice();case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"registerServiceWorker",value:function(){var e=this;"serviceWorker"in navigator?navigator.serviceWorker.register("/sw.js").then((function(e){console.debug("serviceWorker registered")})).catch((function(t){console.error(t),e.showErrorMessage("Unable to Register SW","Sorry this demo requires a service worker to work and it failed to install - sorry :(")})):this.showErrorMessage("Service Worker Not Supported","Sorry this demo requires service worker support in your browser. Please try this demo in Chrome or Firefox Nightly.")}},{key:"_stateChangeListener",value:function(e,t){switch(console.log("_stateChangeListener",e),e.id){case"UNSUPPORTED":this.showErrorMessage("Push Not Supported",t);break;case"ERROR":this.showErrorMessage("Ooops a Problem Occurred",t)}}},{key:"_subscriptionUpdate",value:function(e){if(this._currentSubscription=e,e){var t=JSON.parse(JSON.stringify(e));console.log("subscriptionUpdate",t),function(e){fetch(u.API_PUSH_SUBSCRIPTION,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:u.app,subscription:e,contact:{email:Y.email||void 0,contact_id:Y.contactId||void 0},topic:"transactional",device:"desktop"})})}({endpoint:t.endpoint,p256dh:t.keys.p256dh,auth:t.keys.auth})}}},{key:"toHex",value:function(e){return(t=new Uint8Array(e),function(e){if(Array.isArray(e))return h(e)}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||y(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){return e.toString(16).padStart(2,"0")})).join(" ");var t}},{key:"showErrorMessage",value:function(e,t){console.error(e,t)}}]),e}();function re(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function ne(e){for(var t=1;t0&&n.trigger_count>=e.trigger_options.max_displays||n.last_triggered&&e.trigger_options.interval_days>0&&(new Date).getTime()=e.trigger_mode_options.scroll&&(xe(e),ve(e.id,"triggered"),document.removeEventListener("scroll",t,!1))}),!1)}(e)}}function he(e){e.trigger_mode_options.delay>0&&me(e.optin_id).then((function(){Se(e)})),setTimeout((function(){ae?he(e):(xe(e),ve(e.id,"triggered"))}),1e3*e.trigger_mode_options.delay)}function ye(){try{ce=JSON.parse(localStorage.getItem(ie)||"{}")}catch(e){ce={}}}function ve(e,t){ye(),ce[e]||(ce[e]=ne({},se)),"triggered"===t?(ce[e].trigger_count++,ce[e].last_triggered=(new Date).getTime()):"submitted"===t&&(ce[e].success=!0),localStorage.setItem(ie,JSON.stringify(ce))}function ge(){return be.apply(this,arguments)}function be(){return(be=o(c().mark((function e(){var t,r;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.next=2;break;case 2:return e.prev=2,t="".concat(u.OPTIN_RULES_API,"?account=").concat(u.app),f()&&(t+="&ts=".concat((new Date).getTime())),e.next=7,fetch(t,{method:"GET",headers:{"Content-Type":"application/json","X-Account":u.app}});case 7:if((r=e.sent).ok){e.next=10;break}throw new Error("fetch error: "+t);case 10:return e.next=12,r.json();case 12:return e.abrupt("return",e.sent.data);case 15:return e.prev=15,e.t0=e.catch(2),console.error("Perfit: could not load optin configuration",e.t0),e.abrupt("return",[]);case 19:case"end":return e.stop()}}),e,null,[[2,15]])})))).apply(this,arguments)}function me(e){return we.apply(this,arguments)}function we(){return(we=o(c().mark((function e(t){var r,n,i,o;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!window.PerfitOptIn||!window.PerfitOptIn[t]){e.next=2;break}return e.abrupt("return");case 2:if(!t.startsWith("push")){e.next=5;break}return ke(t),e.abrupt("return");case 5:return r=window.document,(n=r.createElement("div")).id="optin-".concat(t),n.dataset.type="popup",n.dataset.mode="manual",r.body.appendChild(n),i=new Promise((function(e){var n=r.createElement("link");n.rel="stylesheet",n.type="text/css",n.href="https://optin.myperfit.com/res/css/".concat(u.app,"/").concat(t,".css"),n.onload=e,r.body.appendChild(n)})),o=new Promise((function(e){var n=r.createElement("script");n.type="text/javascript",n.charset="utf-8",n.src="https://optin.myperfit.com/res/js/".concat(u.app,"/").concat(t,".js"),n.onload=e,r.body.appendChild(n)})),e.abrupt("return",Promise.all([i,o]));case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _e(e){ae||window.PerfitOptIn[e].open()}function Se(e){window.PerfitOptIn[e.optin_id].setCallbacks({submitted:function(){d("submitted "+e.optin_id),ve(e.id,"submitted")},closed:function(){d("closed "+e.optin_id),ae=!1},opened:function(){d("opened "+e.optin_id),ae=!0}})}function xe(e){window.PerfitOptIn&&window.PerfitOptIn[e.optin_id]?_e(e.optin_id):me(e.optin_id).then((function(){Se(e),_e(e.optin_id)}))}function ke(e){window.PerfitOptIn||(window.PerfitOptIn=[]),window.PerfitOptIn[e]={open:function(){if(X()){var e=function(){if(console.debug("Setting up push."),navigator.serviceWorker){if("PushManager"in window){var e=new te;return e.registerServiceWorker(),e}console.warn("Push is not supported in this browser.")}else console.warn("Service workers are not supported in this browser.")}();e&&setTimeout((function(){e.subscribe()}),1e3)}},close:function(){},setCallbacks:function(){},form:void 0,config:void 0}}var Ee="perfit-cart";function Pe(){H(Ee,"",-1)}var Ie=function(){var e=o(c().mark((function e(t){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t.account,e.abrupt("return",[{onsite_id:"onsite_cldvoehor00060d24ziwulk3y",account:"test20220128",name:"Multiple steps",enabled:!0,priority:1,trigger_options:{url:".*",interval_days:1,max_displays:3,stop_on_success:!1},trigger_mode:"delayed",trigger_mode_options:{delay:1},created:"2024-03-13T00:00:00Z"},{onsite_id:"onsite_cldvoehor00060d24ziwul123",account:"test20220128",name:"Modal Fijo",enabled:!0,priority:1,trigger_options:{element_id:"montar-aqui",url:".*",interval_days:1,max_displays:3,stop_on_success:!1},trigger_mode:"delayed",trigger_mode_options:{delay:1},created:"2024-03-13T00:00:00Z"}]);case 2:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),Oe={},Ce=function(e){var t=document.createElement("iframe");t.src="https://onsite.myperfit.net?perfitOnsiteId=".concat(e.onsite_id),t.id=e.onsite_id,t.style.height="0px",t.style.width="0px",t.style.display="none",Oe[e.onsite_id]={reference:t,rule:e},document.body.appendChild(t)},Ke={identify:Z,visit:q,cart:function(){var e,t,r,n,i,o,a,c=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],s=arguments.length>1?arguments[1]:void 0;if(c&&c.length){var l=J(Ee),p={cart:[]};try{l&&(p=JSON.parse(l))}catch(e){console.error("Perfit: invalid cart cookie"),Pe()}s&&(null===(e=p)||void 0===e?void 0:e.cartId)!=s&&(Pe(),p={cart:[]}),H(Ee,JSON.stringify({cart:c,cartId:s}),7),(null===(t=p)||void 0===t||null===(r=t.cart)||void 0===r||!r.length)&&c.length>0?X()&&Q("cart-init",{cart:c,cart_id:s,customer_id:Y.customerId||void 0,contact_id:Y.contactId||void 0,email:Y.email||void 0,visitor_id:Y.visitorId,timestamp:(new Date).toISOString()}):null!==(n=p)&&void 0!==n&&null!==(i=n.cart)&&void 0!==i&&i.length&&(null===(o=p)||void 0===o||null===(a=o.cart)||void 0===a?void 0:a.length)!=c.length&&u.trackCartUpdates&&X()&&Q("cart-update",{cart:c,cart_id:s,customer_id:Y.customerId||void 0,contact_id:Y.contactId||void 0,email:Y.email||void 0,visitor_id:Y.visitorId,timestamp:(new Date).toISOString()})}else Pe()},showPopup:function(e){var t,r=e.id;if(r){var n=(null===(t=e.options)||void 0===t?void 0:t.timeout)||0;me(r).then((function(){var t,i;null!==(t=e.options)&&void 0!==t&&t.callbacks&&window.PerfitOptIn[r].setCallbacks(null===(i=e.options)||void 0===i?void 0:i.callbacks),setTimeout((function(){_e(r)}),n)}))}},initRules:function(e){e&&ue(e)},setDebug:function(e){p=e,localStorage.setItem(l,JSON.stringify(p)),d("Debug mode enabled")},registerOrigin:ee,loadOnsites:function(){var e=o(c().mark((function e(){var t;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=function(e){for(var t=1;t=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){c=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw o}}}}function Ae(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r-1){for(var r=e[t].src.split("?").pop().split("&"),n={},i=0;i-1&&(_=(w={},window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,(function(e,t,r){w[t]=r.split("#")[0]})),w).pc),(x=_)?K(c,r=x,365):r=!!S&&S.split("#")[0],t&&Z({customer_id:t}),n&&Z({email:n}),function(){var e,t=Ue(document.getElementsByTagName("form"));try{for(t.s();!(e=t.n()).done;){var r=e.value;r.action.includes("winnie-pooh")&&r.addEventListener("submit",(function(e){var t,r,n,i=Ue(e.target);try{for(i.s();!(n=i.n()).done;){var o=n.value;"email"===o.name?t=o.value:"name"===o.name&&(r=o.value)}}catch(e){i.e(e)}finally{i.f()}t&&Z({email:t}),I({event_type:"newsletter.subscribed",email:t,name:"Sin nombre"!==r?r:void 0},!1)}))}}catch(e){t.e(e)}finally{t.f()}}(),LS&&LS.on&&LS.on("productAddedToCart",P),window.location.pathname.startsWith("/checkout")||P(),window.location.pathname.startsWith("/checkout/start")||window.location.pathname.startsWith("/checkout/v3/start"))if(r||n||t)v="checkout_start",P();else{var k=new MutationObserver((function(){d("[checkout start] - observer started");var e=document.querySelector('form input[name="shippingAddress.first_name"]'),t=document.querySelector("div.shipping-options-ship");if(d("[checkout start] - shippingAddressFirstNameInput element: ",e),d("[checkout start] - shippingSection element: ",t),e||t){var r,i=document.querySelector('form input[type="email"][name="contact.email"]');(n=i?i.value:"")&&LS&&!LS.order&&(v="checkout_start",d("[checkout start] - LS.order: ",null===(r=LS)||void 0===r?void 0:r.order),d("[checkout start] - email detected: ",n),Z({email:n}),k.disconnect(),P())}})),E=document.querySelector("form");d("[checkout start] - formElement element: ",E),E?k.observe(E,{childList:!0,subtree:!0}):d("[checkout start] - Form not found")}(t||r||n)&&(window.location.pathname.startsWith("/checkout/next")||window.location.pathname.startsWith("/checkout/v3/next"))&&LS&&!LS.order&&(d("[checkout next] - executed"),v="checkout_next",P()),d("[init] customer",t),d("[init] contact",r),d("[init] email",n),LS&&(LS.product||LS.category)&&(i=setInterval((function(){y++>=5&&clearInterval(i),O()}),5e3),O())}else d("no url params");function P(e){var i,o,a,c,u,l,p,f,h,y,g,b,m,w,_=!1,S=!1,x=null===(i=LS)||void 0===i||null===(o=i.cart)||void 0===o?void 0:o.id,k=null===(a=LS)||void 0===a||null===(c=a.cart)||void 0===c?void 0:c.subtotal;d("[CheckCartUpdated] - LS.cart.id",x),d("[CheckCartUpdated] - LS.cart.subtotal",k),e&&e.detail&&(S=!0,x=null!==(p=e.detail)&&void 0!==p&&null!==(f=p.cart_item)&&void 0!==f&&f.cart_id?e.detail.cart_item.cart_id:null===(h=LS)||void 0===h||null===(y=h.cart)||void 0===y?void 0:y.id,k=null!==(g=e.detail)&&void 0!==g&&null!==(b=g.cart_item)&&void 0!==b&&b.subtotal?e.detail.cart_item.cart_id:null===(m=LS)||void 0===m||null===(w=m.cart)||void 0===w?void 0:w.subtotal,v="product_added_to_cart",d("[CheckCartUpdated] - addedToCartEvent",e),d("[CheckCartUpdated] - cartId updated: ",x),d("[CheckCartUpdated] - cartSubtotal updated: ",k)),(u=C(s))&&(_=JSON.parse(u),d("[CheckCartUpdated] - last cart cookie: "+JSON.stringify(_))),"undefined"!=typeof LS&&x&&(t||r||n)&&(S||k>0)&&(_&&_.id==x?_.subtotal!=k&&(l={id:x,subtotal:k},d("[CheckCartUpdated] - cart subtotal updated: "+JSON.stringify(l)),K(s,JSON.stringify(l),7)):("not_detected"===v&&(v="store_load"),l={id:x,subtotal:k,stage:v},d("[CheckCartUpdated] - new cart cookie: "+JSON.stringify(l)),K(s,JSON.stringify(l),7),I({event_type:"cart.created",cart_id:l.id,customer_id:t||void 0,contact_id:r||void 0,email:n||void 0,stage:v}),v="not_detected"))}function I(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=new XMLHttpRequest,i=h+"/"+e.a+"/js/"+e.r+"/"+e.h;n.open("POST",i,r),n.send(JSON.stringify(t))}function O(){var a=new XMLHttpRequest,c="https://webhooks.myperfit.net/events/tiendanube-trk/"+e.a+"/js/"+e.r+"/"+e.h,s={store_id:e.store,account:e.a,category_id:LS.category?LS.category.id:void 0,product_id:LS.product?LS.product.id:void 0,customer_id:t||void 0,contact_id:r||void 0,email:n||void 0,secs_lapsed:5*y,visitor_id:o,timestamp:(new Date).toISOString()};t||r||n?(a.open("POST",c,!0),a.send(JSON.stringify(s))):C(f)||(a.open("POST",c,!0),a.send(JSON.stringify(s)),clearInterval(i),K(f,"1",1))}function C(e){for(var t=e+"=",r=document.cookie.split(";"),n=0;n