@standardnotes/filesafe-bar 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see EncryptionWorker.js.LICENSE.txt */
|
|
2
|
-
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}([function(e,t,r){(function(t){e.exports=function e(t,r,n){function i(o,s){if(!r[o]){if(!t[o]){if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[o]={exports:{}};t[o][0].call(c.exports,(function(e){return i(t[o][1][e]||e)}),c,c.exports,e,t,r,n)}return r[o].exports}for(var a=!1,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,r,n){(function(e){var t,r,i,a,o,s,u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math);function c(e,t){return!t||"object"!==d(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&h(e,t)}function h(e,t){return(h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!t||r.length!==t);n=!0);}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function d(e){return(d="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)}function y(e,t,r,n,i,a,o){try{var s=e[a](o),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,i)}function v(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var a=e.apply(t,r);function o(e){y(a,n,i,o,s,"next",e)}function s(e){y(a,n,i,o,s,"throw",e)}o(void 0)}))}}function g(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function m(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function k(e,t,r){return t&&m(e.prototype,t),r&&m(e,r),e}r=(t=u).lib.WordArray,t.enc.Base64={stringify:function(e){var t=e.words,r=e.sigBytes,n=this._map;e.clamp(),e=[];for(var i=0;i<r;i+=3)for(var a=(t[i>>>2]>>>24-i%4*8&255)<<16|(t[i+1>>>2]>>>24-(i+1)%4*8&255)<<8|t[i+2>>>2]>>>24-(i+2)%4*8&255,o=0;4>o&&i+.75*o<r;o++)e.push(n.charAt(a>>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(i=n.charAt(64))&&-1!=(i=e.indexOf(i))&&(t=i);for(var i=[],a=0,o=0;o<t;o++)if(o%4){var s=n.indexOf(e.charAt(o-1))<<o%4*2,u=n.indexOf(e.charAt(o))>>>6-o%4*2;i[a>>>2]|=(s|u)<<24-a%4*8,a++}return r.create(i,a)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,r,n,i,a,o){return((e=e+(t&r|~t&n)+i+o)<<a|e>>>32-a)+t}function r(e,t,r,n,i,a,o){return((e=e+(t&n|r&~n)+i+o)<<a|e>>>32-a)+t}function n(e,t,r,n,i,a,o){return((e=e+(t^r^n)+i+o)<<a|e>>>32-a)+t}function i(e,t,r,n,i,a,o){return((e=e+(r^(t|~n))+i+o)<<a|e>>>32-a)+t}for(var a=u,o=(c=a.lib).WordArray,s=c.Hasher,c=a.algo,l=[],f=0;64>f;f++)l[f]=4294967296*e.abs(e.sin(f+1))|0;c=c.MD5=s.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,a){for(var o=0;16>o;o++){var s=e[u=a+o];e[u]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}o=this._hash.words;var u=e[a+0],c=(s=e[a+1],e[a+2]),f=e[a+3],h=e[a+4],p=e[a+5],d=e[a+6],y=e[a+7],v=e[a+8],g=e[a+9],m=e[a+10],k=e[a+11],b=e[a+12],w=e[a+13],x=e[a+14],S=e[a+15],_=t(_=o[0],A=o[1],I=o[2],R=o[3],u,7,l[0]),R=t(R,_,A,I,s,12,l[1]),I=t(I,R,_,A,c,17,l[2]),A=t(A,I,R,_,f,22,l[3]);_=t(_,A,I,R,h,7,l[4]),R=t(R,_,A,I,p,12,l[5]),I=t(I,R,_,A,d,17,l[6]),A=t(A,I,R,_,y,22,l[7]),_=t(_,A,I,R,v,7,l[8]),R=t(R,_,A,I,g,12,l[9]),I=t(I,R,_,A,m,17,l[10]),A=t(A,I,R,_,k,22,l[11]),_=t(_,A,I,R,b,7,l[12]),R=t(R,_,A,I,w,12,l[13]),I=t(I,R,_,A,x,17,l[14]),_=r(_,A=t(A,I,R,_,S,22,l[15]),I,R,s,5,l[16]),R=r(R,_,A,I,d,9,l[17]),I=r(I,R,_,A,k,14,l[18]),A=r(A,I,R,_,u,20,l[19]),_=r(_,A,I,R,p,5,l[20]),R=r(R,_,A,I,m,9,l[21]),I=r(I,R,_,A,S,14,l[22]),A=r(A,I,R,_,h,20,l[23]),_=r(_,A,I,R,g,5,l[24]),R=r(R,_,A,I,x,9,l[25]),I=r(I,R,_,A,f,14,l[26]),A=r(A,I,R,_,v,20,l[27]),_=r(_,A,I,R,w,5,l[28]),R=r(R,_,A,I,c,9,l[29]),I=r(I,R,_,A,y,14,l[30]),_=n(_,A=r(A,I,R,_,b,20,l[31]),I,R,p,4,l[32]),R=n(R,_,A,I,v,11,l[33]),I=n(I,R,_,A,k,16,l[34]),A=n(A,I,R,_,x,23,l[35]),_=n(_,A,I,R,s,4,l[36]),R=n(R,_,A,I,h,11,l[37]),I=n(I,R,_,A,y,16,l[38]),A=n(A,I,R,_,m,23,l[39]),_=n(_,A,I,R,w,4,l[40]),R=n(R,_,A,I,u,11,l[41]),I=n(I,R,_,A,f,16,l[42]),A=n(A,I,R,_,d,23,l[43]),_=n(_,A,I,R,g,4,l[44]),R=n(R,_,A,I,b,11,l[45]),I=n(I,R,_,A,S,16,l[46]),_=i(_,A=n(A,I,R,_,c,23,l[47]),I,R,u,6,l[48]),R=i(R,_,A,I,y,10,l[49]),I=i(I,R,_,A,x,15,l[50]),A=i(A,I,R,_,p,21,l[51]),_=i(_,A,I,R,b,6,l[52]),R=i(R,_,A,I,f,10,l[53]),I=i(I,R,_,A,m,15,l[54]),A=i(A,I,R,_,s,21,l[55]),_=i(_,A,I,R,v,6,l[56]),R=i(R,_,A,I,S,10,l[57]),I=i(I,R,_,A,d,15,l[58]),A=i(A,I,R,_,w,21,l[59]),_=i(_,A,I,R,h,6,l[60]),R=i(R,_,A,I,k,10,l[61]),I=i(I,R,_,A,c,15,l[62]),A=i(A,I,R,_,g,21,l[63]),o[0]=o[0]+_|0,o[1]=o[1]+A|0,o[2]=o[2]+I|0,o[3]=o[3]+R|0},_doFinalize:function(){var t=this._data,r=t.words,n=8*this._nDataBytes,i=8*t.sigBytes;r[i>>>5]|=128<<24-i%32;var a=e.floor(n/4294967296);for(r[15+(i+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),r[14+(i+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(r.length+1),this._process(),r=(t=this._hash).words,n=0;4>n;n++)i=r[n],r[n]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8);return t},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}}),a.MD5=s._createHelper(c),a.HmacMD5=s._createHmacHelper(c)}(Math),function(){var e,t=u,r=(e=t.lib).Base,n=e.WordArray,i=(e=t.algo).EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var r=(s=this.cfg).hasher.create(),i=n.create(),a=i.words,o=s.keySize,s=s.iterations;a.length<o;){u&&r.update(u);var u=r.update(e).finalize(t);r.reset();for(var c=1;c<s;c++)u=r.finalize(u),r.reset();i.concat(u)}return i.sigBytes=4*o,i}});t.EvpKDF=function(e,t,r){return i.create(r).compute(e,t)}}(),u.lib.Cipher||function(e){var t=(d=u).lib,r=t.Base,n=t.WordArray,i=t.BufferedBlockAlgorithm,a=d.enc.Base64,o=d.algo.EvpKDF,s=t.Cipher=i.extend({cfg:r.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,r){this.cfg=this.cfg.extend(r),this._xformMode=e,this._key=t,this.reset()},reset:function(){i.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(e){return{encrypt:function(t,r,n){return("string"==typeof r?y:p).encrypt(e,t,r,n)},decrypt:function(t,r,n){return("string"==typeof r?y:p).decrypt(e,t,r,n)}}}});t.StreamCipher=s.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var c=d.mode={},l=function(e,t,r){var n=this._iv;n?this._iv=void 0:n=this._prevBlock;for(var i=0;i<r;i++)e[t+i]^=n[i]},f=(t.BlockCipherMode=r.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}})).extend();f.Encryptor=f.extend({processBlock:function(e,t){var r=this._cipher,n=r.blockSize;l.call(this,e,t,n),r.encryptBlock(e,t),this._prevBlock=e.slice(t,t+n)}}),f.Decryptor=f.extend({processBlock:function(e,t){var r=this._cipher,n=r.blockSize,i=e.slice(t,t+n);r.decryptBlock(e,t),l.call(this,e,t,n),this._prevBlock=i}}),c=c.CBC=f,f=(d.pad={}).Pkcs7={pad:function(e,t){for(var r,i=(r=(r=4*t)-e.sigBytes%r)<<24|r<<16|r<<8|r,a=[],o=0;o<r;o+=4)a.push(i);r=n.create(a,r),e.concat(r)},unpad:function(e){e.sigBytes-=255&e.words[e.sigBytes-1>>>2]}},t.BlockCipher=s.extend({cfg:s.cfg.extend({mode:c,padding:f}),reset:function(){s.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var r=t.createEncryptor;else r=t.createDecryptor,this._minBufferSize=1;this._mode=r.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=r.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),p=(c=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(a)},parse:function(e){var t=(e=a.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var r=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:r})}},t.SerializableCipher=r.extend({cfg:r.extend({format:c}),encrypt:function(e,t,r,n){n=this.cfg.extend(n);var i=e.createEncryptor(r,n);return t=i.finalize(t),i=i.cfg,h.create({ciphertext:t,key:r,iv:i.iv,algorithm:e,mode:i.mode,padding:i.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,r,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(r,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,r,i){return i||(i=n.random(8)),e=o.create({keySize:t+r}).compute(e,i),r=n.create(e.words.slice(t),4*r),e.sigBytes=4*t,h.create({key:e,iv:r,salt:i})}},y=t.PasswordBasedCipher=p.extend({cfg:p.cfg.extend({kdf:d}),encrypt:function(e,t,r,n){return r=(n=this.cfg.extend(n)).kdf.execute(r,e.keySize,e.ivSize),n.iv=r.iv,(e=p.encrypt.call(this,e,t,r.key,n)).mixIn(r),e},decrypt:function(e,t,r,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),r=n.kdf.execute(r,e.keySize,e.ivSize,t.salt),n.iv=r.iv,p.decrypt.call(this,e,t,r.key,n)}})}(),function(){for(var e=u,t=e.lib.BlockCipher,r=e.algo,n=[],i=[],a=[],o=[],s=[],c=[],l=[],f=[],h=[],p=[],d=[],y=0;256>y;y++)d[y]=128>y?y<<1:y<<1^283;var v=0,g=0;for(y=0;256>y;y++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;n[v]=m,i[m]=v;var k=d[v],b=d[k],w=d[b],x=257*d[m]^16843008*m;a[v]=x<<24|x>>>8,o[v]=x<<16|x>>>16,s[v]=x<<8|x>>>24,c[v]=x,x=16843009*w^65537*b^257*k^16843008*v,l[m]=x<<24|x>>>8,f[m]=x<<16|x>>>16,h[m]=x<<8|x>>>24,p[m]=x,v?(v=k^d[d[d[w^k]]],g^=d[d[g]]):v=g=1}var S=[0,1,2,4,8,16,32,64,128,27,54];r=r.AES=t.extend({_doReset:function(){for(var e=(r=this._key).words,t=r.sigBytes/4,r=4*((this._nRounds=t+6)+1),i=this._keySchedule=[],a=0;a<r;a++)if(a<t)i[a]=e[a];else{var o=i[a-1];a%t?6<t&&4==a%t&&(o=n[o>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=S[a/t|0]<<24),i[a]=i[a-t]^o}for(e=this._invKeySchedule=[],t=0;t<r;t++)a=r-t,o=t%4?i[a]:i[a-4],e[t]=4>t||4>=a?o:l[n[o>>>24]]^f[n[o>>>16&255]]^h[n[o>>>8&255]]^p[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,o,s,c,n)},decryptBlock:function(e,t){var r=e[t+1];e[t+1]=e[t+3],e[t+3]=r,this._doCryptBlock(e,t,this._invKeySchedule,l,f,h,p,i),r=e[t+1],e[t+1]=e[t+3],e[t+3]=r},_doCryptBlock:function(e,t,r,n,i,a,o,s){for(var u=this._nRounds,c=e[t]^r[0],l=e[t+1]^r[1],f=e[t+2]^r[2],h=e[t+3]^r[3],p=4,d=1;d<u;d++){var y=n[c>>>24]^i[l>>>16&255]^a[f>>>8&255]^o[255&h]^r[p++],v=n[l>>>24]^i[f>>>16&255]^a[h>>>8&255]^o[255&c]^r[p++],g=n[f>>>24]^i[h>>>16&255]^a[c>>>8&255]^o[255&l]^r[p++];h=n[h>>>24]^i[c>>>16&255]^a[l>>>8&255]^o[255&f]^r[p++],c=y,l=v,f=g}y=(s[c>>>24]<<24|s[l>>>16&255]<<16|s[f>>>8&255]<<8|s[255&h])^r[p++],v=(s[l>>>24]<<24|s[f>>>16&255]<<16|s[h>>>8&255]<<8|s[255&c])^r[p++],g=(s[f>>>24]<<24|s[h>>>16&255]<<16|s[c>>>8&255]<<8|s[255&l])^r[p++],h=(s[h>>>24]<<24|s[c>>>16&255]<<16|s[l>>>8&255]<<8|s[255&f])^r[p++],e[t]=y,e[t+1]=v,e[t+2]=g,e[t+3]=h},keySize:8}),e.AES=t._createHelper(r)}(),u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math),function(e){for(var t=u,r=(i=t.lib).WordArray,n=i.Hasher,i=t.algo,a=[],o=[],s=function(e){return 4294967296*(e-(0|e))|0},c=2,l=0;64>l;){var f;e:{f=c;for(var h=e.sqrt(f),p=2;p<=h;p++)if(!(f%p)){f=!1;break e}f=!0}f&&(8>l&&(a[l]=s(e.pow(c,.5))),o[l]=s(e.pow(c,1/3)),l++),c++}var d=[];i=i.SHA256=n.extend({_doReset:function(){this._hash=new r.init(a.slice(0))},_doProcessBlock:function(e,t){for(var r=this._hash.words,n=r[0],i=r[1],a=r[2],s=r[3],u=r[4],c=r[5],l=r[6],f=r[7],h=0;64>h;h++){if(16>h)d[h]=0|e[t+h];else{var p=d[h-15],y=d[h-2];d[h]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+d[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+d[h-16]}p=f+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+o[h]+d[h],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&i^n&a^i&a),f=l,l=c,c=u,u=s+p|0,s=a,a=i,i=n,n=p+y|0}r[0]=r[0]+n|0,r[1]=r[1]+i|0,r[2]=r[2]+a|0,r[3]=r[3]+s|0,r[4]=r[4]+u|0,r[5]=r[5]+c|0,r[6]=r[6]+l|0,r[7]=r[7]+f|0},_doFinalize:function(){var t=this._data,r=t.words,n=8*this._nDataBytes,i=8*t.sigBytes;return r[i>>>5]|=128<<24-i%32,r[14+(i+64>>>9<<4)]=e.floor(n/4294967296),r[15+(i+64>>>9<<4)]=n,t.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}}),t.SHA256=n._createHelper(i),t.HmacSHA256=n._createHmacHelper(i)}(Math),a=(i=u).enc.Utf8,i.algo.HMAC=i.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var r=e.blockSize,n=4*r;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var i=this._oKey=t.clone(),o=this._iKey=t.clone(),s=i.words,u=o.words,c=0;c<r;c++)s[c]^=1549556828,u[c]^=909522486;i.sigBytes=o.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}}),u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math),function(e){var t,r=(t=u).lib,n=r.Base,i=r.WordArray;(t=t.x64={}).Word=n.extend({init:function(e,t){this.high=e,this.low=t}}),t.WordArray=n.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,r=[],n=0;n<t;n++){var a=e[n];r.push(a.high),r.push(a.low)}return i.create(r,this.sigBytes)},clone:function(){for(var e=n.clone.call(this),t=e.words=this.words.slice(0),r=t.length,i=0;i<r;i++)t[i]=t[i].clone();return e}})}(),function(){function e(){return n.create.apply(n,arguments)}for(var t=u,r=t.lib.Hasher,n=(a=t.x64).Word,i=a.WordArray,a=t.algo,o=[e(1116352408,3609767458),e(1899447441,602891725),e(3049323471,3964484399),e(3921009573,2173295548),e(961987163,4081628472),e(1508970993,3053834265),e(2453635748,2937671579),e(2870763221,3664609560),e(3624381080,2734883394),e(310598401,1164996542),e(607225278,1323610764),e(1426881987,3590304994),e(1925078388,4068182383),e(2162078206,991336113),e(2614888103,633803317),e(3248222580,3479774868),e(3835390401,2666613458),e(4022224774,944711139),e(264347078,2341262773),e(604807628,2007800933),e(770255983,1495990901),e(1249150122,1856431235),e(1555081692,3175218132),e(1996064986,2198950837),e(2554220882,3999719339),e(2821834349,766784016),e(2952996808,2566594879),e(3210313671,3203337956),e(3336571891,1034457026),e(3584528711,2466948901),e(113926993,3758326383),e(338241895,168717936),e(666307205,1188179964),e(773529912,1546045734),e(1294757372,1522805485),e(1396182291,2643833823),e(1695183700,2343527390),e(1986661051,1014477480),e(2177026350,1206759142),e(2456956037,344077627),e(2730485921,1290863460),e(2820302411,3158454273),e(3259730800,3505952657),e(3345764771,106217008),e(3516065817,3606008344),e(3600352804,1432725776),e(4094571909,1467031594),e(275423344,851169720),e(430227734,3100823752),e(506948616,1363258195),e(659060556,3750685593),e(883997877,3785050280),e(958139571,3318307427),e(1322822218,3812723403),e(1537002063,2003034995),e(1747873779,3602036899),e(1955562222,1575990012),e(2024104815,1125592928),e(2227730452,2716904306),e(2361852424,442776044),e(2428436474,593698344),e(2756734187,3733110249),e(3204031479,2999351573),e(3329325298,3815920427),e(3391569614,3928383900),e(3515267271,566280711),e(3940187606,3454069534),e(4118630271,4000239992),e(116418474,1914138554),e(174292421,2731055270),e(289380356,3203993006),e(460393269,320620315),e(685471733,587496836),e(852142971,1086792851),e(1017036298,365543100),e(1126000580,2618297676),e(1288033470,3409855158),e(1501505948,4234509866),e(1607167915,987167468),e(1816402316,1246189591)],s=[],c=0;80>c;c++)s[c]=e();a=a.SHA512=r.extend({_doReset:function(){this._hash=new i.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var r=(f=this._hash.words)[0],n=f[1],i=f[2],a=f[3],u=f[4],c=f[5],l=f[6],f=f[7],h=r.high,p=r.low,d=n.high,y=n.low,v=i.high,g=i.low,m=a.high,k=a.low,b=u.high,w=u.low,x=c.high,S=c.low,_=l.high,R=l.low,I=f.high,A=f.low,D=h,M=p,C=d,O=y,F=v,P=g,j=m,B=k,E=b,T=w,L=x,H=S,z=_,U=R,N=I,K=A,W=0;80>W;W++){var J=s[W];if(16>W)var q=J.high=0|e[t+2*W],V=J.low=0|e[t+2*W+1];else{q=((V=(q=s[W-15]).high)>>>1|($=q.low)<<31)^(V>>>8|$<<24)^V>>>7;var $=($>>>1|V<<31)^($>>>8|V<<24)^($>>>7|V<<25),G=((V=(G=s[W-2]).high)>>>19|(X=G.low)<<13)^(V<<3|X>>>29)^V>>>6,X=(X>>>19|V<<13)^(X<<3|V>>>29)^(X>>>6|V<<26),Y=(V=s[W-7]).high,Q=(Z=s[W-16]).high,Z=Z.low;q=(q=(q=q+Y+((V=$+V.low)>>>0<$>>>0?1:0))+G+((V+=X)>>>0<X>>>0?1:0))+Q+((V+=Z)>>>0<Z>>>0?1:0),J.high=q,J.low=V}Y=E&L^~E&z,Z=T&H^~T&U,J=D&C^D&F^C&F;var ee=M&O^M&P^O&P,te=($=(D>>>28|M<<4)^(D<<30|M>>>2)^(D<<25|M>>>7),G=(M>>>28|D<<4)^(M<<30|D>>>2)^(M<<25|D>>>7),(X=o[W]).high),re=X.low;Q=N+((E>>>14|T<<18)^(E>>>18|T<<14)^(E<<23|T>>>9))+((X=K+((T>>>14|E<<18)^(T>>>18|E<<14)^(T<<23|E>>>9)))>>>0<K>>>0?1:0),N=z,K=U,z=L,U=H,L=E,H=T,E=j+(Q=(Q=(Q=Q+Y+((X+=Z)>>>0<Z>>>0?1:0))+te+((X+=re)>>>0<re>>>0?1:0))+q+((X+=V)>>>0<V>>>0?1:0))+((T=B+X|0)>>>0<B>>>0?1:0)|0,j=F,B=P,F=C,P=O,C=D,O=M,D=Q+(J=$+J+((V=G+ee)>>>0<G>>>0?1:0))+((M=X+V|0)>>>0<X>>>0?1:0)|0}p=r.low=p+M,r.high=h+D+(p>>>0<M>>>0?1:0),y=n.low=y+O,n.high=d+C+(y>>>0<O>>>0?1:0),g=i.low=g+P,i.high=v+F+(g>>>0<P>>>0?1:0),k=a.low=k+B,a.high=m+j+(k>>>0<B>>>0?1:0),w=u.low=w+T,u.high=b+E+(w>>>0<T>>>0?1:0),S=c.low=S+H,c.high=x+L+(S>>>0<H>>>0?1:0),R=l.low=R+U,l.high=_+z+(R>>>0<U>>>0?1:0),A=f.low=A+K,f.high=I+N+(A>>>0<K>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,r=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[30+(n+128>>>10<<5)]=Math.floor(r/4294967296),t[31+(n+128>>>10<<5)]=r,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32}),t.SHA512=r._createHelper(a),t.HmacSHA512=r._createHmacHelper(a)}(),s=(o=u).enc.Utf8,o.algo.HMAC=o.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var r=e.blockSize,n=4*r;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var i=this._oKey=t.clone(),a=this._iKey=t.clone(),o=i.words,u=a.words,c=0;c<r;c++)o[c]^=1549556828,u[c]^=909522486;i.sigBytes=a.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}}),u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math),function(){var e=u,t=(i=e.lib).WordArray,r=i.Hasher,n=[],i=e.algo.SHA1=r.extend({_doReset:function(){this._hash=new t.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var r=this._hash.words,i=r[0],a=r[1],o=r[2],s=r[3],u=r[4],c=0;80>c;c++){if(16>c)n[c]=0|e[t+c];else{var l=n[c-3]^n[c-8]^n[c-14]^n[c-16];n[c]=l<<1|l>>>31}l=(i<<5|i>>>27)+u+n[c],l=20>c?l+(1518500249+(a&o|~a&s)):40>c?l+(1859775393+(a^o^s)):60>c?l+((a&o|a&s|o&s)-1894007588):l+((a^o^s)-899497514),u=s,s=o,o=a<<30|a>>>2,a=i,i=l}r[0]=r[0]+i|0,r[1]=r[1]+a|0,r[2]=r[2]+o|0,r[3]=r[3]+s|0,r[4]=r[4]+u|0},_doFinalize:function(){var e=this._data,t=e.words,r=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=Math.floor(r/4294967296),t[15+(n+64>>>9<<4)]=r,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});e.SHA1=r._createHelper(i),e.HmacSHA1=r._createHmacHelper(i)}(),function(){var e=u,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,r){e=this._hasher=new e.init,"string"==typeof r&&(r=t.parse(r));var n=e.blockSize,i=4*n;r.sigBytes>i&&(r=e.finalize(r)),r.clamp();for(var a=this._oKey=r.clone(),o=this._iKey=r.clone(),s=a.words,u=o.words,c=0;c<n;c++)s[c]^=1549556828,u[c]^=909522486;a.sigBytes=o.sigBytes=i,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}(),function(){var e,t=u,r=(e=t.lib).Base,n=e.WordArray,i=(e=t.algo).HMAC,a=e.PBKDF2=r.extend({cfg:r.extend({keySize:4,hasher:e.SHA1,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){var r=this.cfg,a=i.create(r.hasher,e),o=n.create(),s=n.create([1]),u=o.words,c=s.words,l=r.keySize;for(r=r.iterations;u.length<l;){var f=a.update(t).finalize(s);a.reset();for(var h=f.words,p=h.length,d=f,y=1;y<r;y++){d=a.finalize(d),a.reset();for(var v=d.words,g=0;g<p;g++)h[g]^=v[g]}o.concat(f),c[0]++}return o.sigBytes=4*l,o}});t.PBKDF2=function(e,t,r){return a.create(r).compute(e,t)}}(),u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math),function(){var e=u,t=(i=e.lib).WordArray,r=i.Hasher,n=[],i=e.algo.SHA1=r.extend({_doReset:function(){this._hash=new t.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var r=this._hash.words,i=r[0],a=r[1],o=r[2],s=r[3],u=r[4],c=0;80>c;c++){if(16>c)n[c]=0|e[t+c];else{var l=n[c-3]^n[c-8]^n[c-14]^n[c-16];n[c]=l<<1|l>>>31}l=(i<<5|i>>>27)+u+n[c],l=20>c?l+(1518500249+(a&o|~a&s)):40>c?l+(1859775393+(a^o^s)):60>c?l+((a&o|a&s|o&s)-1894007588):l+((a^o^s)-899497514),u=s,s=o,o=a<<30|a>>>2,a=i,i=l}r[0]=r[0]+i|0,r[1]=r[1]+a|0,r[2]=r[2]+o|0,r[3]=r[3]+s|0,r[4]=r[4]+u|0},_doFinalize:function(){var e=this._data,t=e.words,r=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=Math.floor(r/4294967296),t[15+(n+64>>>9<<4)]=r,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});e.SHA1=r._createHelper(i),e.HmacSHA1=r._createHmacHelper(i)}(),Object.defineProperty(n,"__esModule",{value:!0}),n.StandardFile=n.SFItemTransformer=n.SFCryptoWeb=n.SFCryptoJS=n.SFAbstractCrypto=n.SFItemHistoryEntry=n.SFItemHistory=n.SFHistorySession=n.SFPrivileges=n.SFPredicate=n.SFItemParams=n.SFItem=n.SFSyncManager=n.SFStorageManager=n.SFSingletonManager=n.SFSessionHistoryManager=n.SFPrivilegesManager=n.SFModelManager=n.SFMigrationManager=n.SFHttpManager=n.SFAuthManager=n.SFAlertManager=void 0;var b=function(){function e(){g(this,e)}var t,r;return k(e,[{key:"alert",value:(r=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){window.alert(t.text),e()})));case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})},{key:"confirm",value:(t=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){window.confirm(t.text)?e():r()})));case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();n.SFAlertManager=b;var w=function(){function e(t,r,n,i){g(this,e),e.DidSignOutEvent="DidSignOutEvent",e.WillSignInEvent="WillSignInEvent",e.DidSignInEvent="DidSignInEvent",this.httpManager=r,this.storageManager=t,this.alertManager=n||new b,this.$timeout=i||setTimeout.bind(window),this.eventHandlers=[]}var t,r,n,i,a,o,s,u,c,l;return k(e,[{key:"addEventHandler",value:function(e){return this.eventHandlers.push(e),e}},{key:"removeEventHandler",value:function(e){_.pull(this.eventHandlers,e)}},{key:"notifyEvent",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,o=this.eventHandlers[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)(0,a.value)(e,t||{})}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}},{key:"saveKeys",value:(l=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._keys=t,e.next=3,this.storageManager.setItem("mk",t.mk);case 3:return e.next=5,this.storageManager.setItem("ak",t.ak);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"signout",value:(c=v(regeneratorRuntime.mark((function t(r){var n=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._keys=null,this._authParams=null,!r){t.next=6;break}return t.abrupt("return",this.storageManager.clearAllData().then((function(){n.notifyEvent(e.DidSignOutEvent)})));case 6:this.notifyEvent(e.DidSignOutEvent);case 7:case"end":return t.stop()}}),t,this)}))),function(e){return c.apply(this,arguments)})},{key:"keys",value:(u=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._keys){e.next=11;break}return e.next=3,this.storageManager.getItem("mk");case 3:if(t=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.t0=t,e.next=9,this.storageManager.getItem("ak");case 9:e.t1=e.sent,this._keys={mk:e.t0,ak:e.t1};case 11:return e.abrupt("return",this._keys);case 12:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"getAuthParams",value:(s=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._authParams){e.next=5;break}return e.next=3,this.storageManager.getItem("auth_params");case 3:t=e.sent,this._authParams=JSON.parse(t);case 5:if(!this._authParams||this._authParams.version){e.next=9;break}return e.next=8,this.defaultProtocolVersion();case 8:this._authParams.version=e.sent;case 9:return e.abrupt("return",this._authParams);case 10:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"defaultProtocolVersion",value:(o=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.keys();case 2:if(!(t=e.sent)||!t.ak){e.next=7;break}return e.abrupt("return","002");case 7:return e.abrupt("return","001");case 8:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"protocolVersion",value:(a=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getAuthParams();case 2:if(!(t=e.sent)||!t.version){e.next=5;break}return e.abrupt("return",t.version);case 5:return e.abrupt("return",this.defaultProtocolVersion());case 6:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getAuthParamsForEmail",value:(i=v(regeneratorRuntime.mark((function e(t,r,n){var i,a=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(i=_.merge({email:r},n)).api=S.getApiVersion(),e.abrupt("return",new Promise((function(e,r){var n=t+"/auth/params";a.httpManager.getAbsolute(n,i,(function(t){e(t)}),(function(t){console.error("Error getting auth params",t),"object"!==d(t)&&(t={error:{message:"A server error occurred while trying to sign in. Please try again."}}),e(t)}))})));case 3:case"end":return e.stop()}}),e)}))),function(e,t,r){return i.apply(this,arguments)})},{key:"lock",value:function(){this.locked=!0}},{key:"unlock",value:function(){this.locked=!1}},{key:"isLocked",value:function(){return 1==this.locked}},{key:"unlockAndResolve",value:function(e,t){this.unlock(),e(t)}},{key:"login",value:(n=v(regeneratorRuntime.mark((function t(r,n,i,a,o){var s=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(){var t=v(regeneratorRuntime.mark((function t(u,c){var l,f,h,p,y,g,m,k,b,w;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.keys();case 2:if(null==t.sent){t.next=6;break}return u({error:{message:"Cannot log in because already signed in."}}),t.abrupt("return");case 6:if(!s.isLocked()){t.next=9;break}return u({error:{message:"Login already in progress."}}),t.abrupt("return");case 9:return s.lock(),s.notifyEvent(e.WillSignInEvent),t.next=13,s.getAuthParamsForEmail(r,n,o);case 13:if((l=t.sent).identifier=n,!l.error){t.next=18;break}return s.unlockAndResolve(u,l),t.abrupt("return");case 18:if(l&&l.pw_cost){t.next=21;break}return s.unlockAndResolve(u,{error:{message:"Invalid email or password."}}),t.abrupt("return");case 21:if(SFJS.supportedVersions().includes(l.version)){t.next=25;break}return f=SFJS.isVersionNewerThanLibraryVersion(l.version)?"This version of the application does not support your newer account type. Please upgrade to the latest version of Standard Notes to sign in.":"The protocol version associated with your account is outdated and no longer supported by this application. Please visit standardnotes.org/help/security for more information.",s.unlockAndResolve(u,{error:{message:f}}),t.abrupt("return");case 25:if(!SFJS.isProtocolVersionOutdated(l.version)){t.next=32;break}return h="The encryption version for your account, ".concat(l.version,", is outdated and requires upgrade. You may proceed with login, but are advised to perform a security update using the web or desktop application. Please visit standardnotes.org/help/security for more information."),p=!1,t.next=30,s.alertManager.confirm({title:"Update Needed",text:h,confirmButtonText:"Sign In"}).catch((function(){s.unlockAndResolve(u,{error:{}}),p=!0}));case 30:if(!p){t.next=32;break}return t.abrupt("return");case 32:if(SFJS.supportsPasswordDerivationCost(l.pw_cost)){t.next=36;break}return s.unlockAndResolve(u,{error:{message:"Your account was created on a platform with higher security capabilities than this browser supports. If we attempted to generate your login keys here, it would take hours. Please use a browser with more up to date security capabilities, like Google Chrome or Firefox, to log in."}}),t.abrupt("return");case 36:if(y=SFJS.costMinimumForVersion(l.version),!(l.pw_cost<y)){t.next=41;break}return s.unlockAndResolve(u,{error:{message:"Unable to login due to insecure password parameters. Please visit standardnotes.org/help/security for more information."}}),t.abrupt("return");case 41:if(!a){t.next=47;break}if(g=SFJS.version(),l.version===g){t.next=47;break}return m="Strict sign in refused server sign in parameters. The latest security version is ".concat(g,", but your account is reported to have version ").concat(l.version,". If you'd like to proceed with sign in anyway, please disable strict sign in and try again."),s.unlockAndResolve(u,{error:{message:m}}),t.abrupt("return");case 47:return t.next=49,SFJS.crypto.computeEncryptionKeysForUser(i,l);case 49:k=t.sent,b=r+"/auth/sign_in",(w=_.merge({password:k.pw,email:n},o)).api=S.getApiVersion(),s.httpManager.postAbsolute(b,w,function(){var t=v(regeneratorRuntime.mark((function t(i){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.handleAuthResponse(i,n,r,l,k);case 2:s.notifyEvent(e.DidSignInEvent),s.$timeout((function(){return s.unlockAndResolve(u,i)}));case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),(function(e){console.error("Error logging in",e),"object"!==d(e)&&(e={error:{message:"A server error occurred while trying to sign in. Please try again."}}),s.$timeout((function(){return s.unlockAndResolve(u,e)}))}));case 54:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}()));case 1:case"end":return t.stop()}}),t)}))),function(e,t,r,i,a){return n.apply(this,arguments)})},{key:"register",value:function(e,t,r){var n=this;return new Promise(function(){var i=v(regeneratorRuntime.mark((function i(a,o){var s,u,c,l,f,h;return regeneratorRuntime.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(!n.isLocked()){i.next=3;break}return a({error:{message:"Register already in progress."}}),i.abrupt("return");case 3:if(!(r.length<8)){i.next=8;break}return s="Your password must be at least ".concat(8," characters in length. For your security, please choose a longer password or, ideally, a passphrase, and try again."),a({error:{message:s}}),i.abrupt("return");case 8:return n.lock(),i.next=11,SFJS.crypto.generateInitialKeysAndAuthParamsForUser(t,r);case 11:u=i.sent,c=u.keys,l=u.authParams,f=e+"/auth",(h=_.merge({password:c.pw,email:t},l)).api=S.getApiVersion(),n.httpManager.postAbsolute(f,h,function(){var r=v(regeneratorRuntime.mark((function r(i){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,n.handleAuthResponse(i,t,e,l,c);case 2:n.unlockAndResolve(a,i);case 3:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),(function(e){console.error("Registration error",e),"object"!==d(e)&&(e={error:{message:"A server error occurred while trying to register. Please try again."}}),n.unlockAndResolve(a,e)}));case 18:case"end":return i.stop()}}),i)})));return function(e,t){return i.apply(this,arguments)}}())}},{key:"changePassword",value:(r=v(regeneratorRuntime.mark((function e(t,r,n,i,a){var o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise(function(){var e=v(regeneratorRuntime.mark((function e(s,u){var c,l,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!o.isLocked()){e.next=3;break}return s({error:{message:"Change password already in progress."}}),e.abrupt("return");case 3:o.lock(),c=i.pw,l=t+"/auth/change_pw",(f=_.merge({new_password:c,current_password:n},a)).api=S.getApiVersion(),o.httpManager.postAuthenticatedAbsolute(l,f,function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.handleAuthResponse(t,r,null,a,i);case 2:o.unlockAndResolve(s,t);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),(function(e){"object"!==d(e)&&(e={error:{message:"Something went wrong while changing your password. Your password was not changed. Please try again."}}),o.unlockAndResolve(s,e)}));case 9:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()));case 1:case"end":return e.stop()}}),e)}))),function(e,t,n,i,a){return r.apply(this,arguments)})},{key:"handleAuthResponse",value:(t=v(regeneratorRuntime.mark((function e(t,r,n,i,a){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n){e.next=3;break}return e.next=3,this.storageManager.setItem("server",n);case 3:return this._authParams=i,e.next=6,this.storageManager.setItem("auth_params",JSON.stringify(i));case 6:return e.next=8,this.storageManager.setItem("jwt",t.token);case 8:return e.abrupt("return",this.saveKeys(a));case 9:case"end":return e.stop()}}),e,this)}))),function(e,r,n,i,a){return t.apply(this,arguments)})}]),e}();n.SFAuthManager=w;var x="undefined"!=typeof window?window:void 0!==e?e:null,S=function(){function e(t,r){g(this,e),this.$timeout=t||setTimeout.bind(x)}var t,r,n,i,a,o;return k(e,null,[{key:"getApiVersion",value:function(){return"20190520"}}]),k(e,[{key:"setJWTRequestHandler",value:function(e){this.jwtRequestHandler=e}},{key:"setAuthHeadersForRequest",value:(o=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.jwtRequestHandler();case 2:(r=e.sent)&&t.setRequestHeader("Authorization","Bearer "+r);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"postAbsolute",value:(a=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.httpRequest("post",t,r,n,i));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return a.apply(this,arguments)})},{key:"postAuthenticatedAbsolute",value:(i=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.httpRequest("post",t,r,n,i,!0));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return i.apply(this,arguments)})},{key:"patchAbsolute",value:(n=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.httpRequest("patch",t,r,n,i));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"getAbsolute",value:(r=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.httpRequest("get",t,r,n,i));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"httpRequest",value:(t=v(regeneratorRuntime.mark((function e(t,r,n,i,a){var o,s=this,u=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=u.length>5&&void 0!==u[5]&&u[5],e.abrupt("return",new Promise(function(){var e=v(regeneratorRuntime.mark((function e(u,c){var l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((l=new XMLHttpRequest).onreadystatechange=function(){if(4==l.readyState){var e=l.responseText;if(e)try{e=JSON.parse(e)}catch(e){}l.status>=200&&l.status<=299?s.$timeout((function(){i(e),u(e)})):(console.error("Request error:",e),s.$timeout((function(){a(e,l.status),c(e)})))}},"get"==t&&Object.keys(n).length>0&&(r=s.urlForUrlAndParams(r,n)),l.open(t,r,!0),l.setRequestHeader("Content-type","application/json"),!o){e.next=8;break}return e.next=8,s.setAuthHeadersForRequest(l);case 8:"post"==t||"patch"==t?l.send(JSON.stringify(n)):l.send();case 9:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()));case 2:case"end":return e.stop()}}),e)}))),function(e,r,n,i,a){return t.apply(this,arguments)})},{key:"urlForUrlAndParams",value:function(e,t){var r=Object.keys(t).map((function(e){return e+"="+encodeURIComponent(t[e])})).join("&");return e.includes("?")?e+"&"+r:e+"?"+r}}]),e}();n.SFHttpManager=S;var R=function(){function e(t,r,n,i){var a=this;g(this,e),this.modelManager=t,this.syncManager=r,this.storageManager=n,this.completionHandlers=[],this.loadMigrations();var o=!1,s=i.addEventHandler((function(e){e==w.DidSignInEvent&&(o=!0)}));this.receivedLocalDataEvent=r.initialDataLoaded(),this.syncManager.addEventHandler(function(){var e=v(regeneratorRuntime.mark((function e(t,r){var n,u,c,l,f,h,p,d,y;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u="sync:completed"==t,!(n="local-data-loaded"==t)&&!u){e.next=40;break}if(n?a.receivedLocalDataEvent=!0:u&&(a.receivedSyncCompletedEvent=!0),!a.receivedLocalDataEvent||!a.receivedSyncCompletedEvent){e.next=40;break}if(!o){e.next=39;break}return o=!1,i.removeEventHandler(s),e.next=10,a.getCompletedMigrations();case 10:c=e.sent.slice(),l=!0,f=!1,h=void 0,e.prev=14,p=c[Symbol.iterator]();case 16:if(l=(d=p.next()).done){e.next=25;break}return y=d.value,e.next=20,a.migrationForEncodedName(y);case 20:e.sent.runOnlyOnce||_.pull(a._completed,y);case 22:l=!0,e.next=16;break;case 25:e.next=31;break;case 27:e.prev=27,e.t0=e.catch(14),f=!0,h=e.t0;case 31:e.prev=31,e.prev=32,l||null==p.return||p.return();case 34:if(e.prev=34,!f){e.next=37;break}throw h;case 37:return e.finish(34);case 38:return e.finish(31);case 39:a.runPendingMigrations();case 40:case"end":return e.stop()}}),e,null,[[14,27,31,39],[32,,34,38]])})));return function(t,r){return e.apply(this,arguments)}}())}var t,r,n,i,a,o,s,u;return k(e,[{key:"addCompletionHandler",value:function(e){this.completionHandlers.push(e)}},{key:"removeCompletionHandler",value:function(e){_.pull(this.completionHandlers,e)}},{key:"migrationForEncodedName",value:(u=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.decode(t);case 2:return r=e.sent,e.abrupt("return",this.migrations.find((function(e){return e.name==r})));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"loadMigrations",value:function(){this.migrations=this.registeredMigrations()}},{key:"registeredMigrations",value:function(){}},{key:"runPendingMigrations",value:(s=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,u,c,l,f,h,p,d,y,v,g,m,k,b,w,x,S,_,R,I,A,D;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getPendingMigrations();case 2:for(t=e.sent,r=!0,n=!1,i=void 0,e.prev=6,a=t[Symbol.iterator]();!(r=(o=a.next()).done);r=!0)(s=o.value).items=[];e.next=14;break;case 10:e.prev=10,e.t0=e.catch(6),n=!0,i=e.t0;case 14:e.prev=14,e.prev=15,r||null==a.return||a.return();case 17:if(e.prev=17,!n){e.next=20;break}throw i;case 20:return e.finish(17);case 21:return e.finish(14);case 22:u=!0,c=!1,l=void 0,e.prev=25,f=this.modelManager.allNondummyItems[Symbol.iterator]();case 27:if(u=(h=f.next()).done){e.next=51;break}for(p=h.value,d=!0,y=!1,v=void 0,e.prev=32,g=t[Symbol.iterator]();!(d=(m=g.next()).done);d=!0)s=m.value,p.content_type==s.content_type&&s.items.push(p);e.next=40;break;case 36:e.prev=36,e.t1=e.catch(32),y=!0,v=e.t1;case 40:e.prev=40,e.prev=41,d||null==g.return||g.return();case 43:if(e.prev=43,!y){e.next=46;break}throw v;case 46:return e.finish(43);case 47:return e.finish(40);case 48:u=!0,e.next=27;break;case 51:e.next=57;break;case 53:e.prev=53,e.t2=e.catch(25),c=!0,l=e.t2;case 57:e.prev=57,e.prev=58,u||null==f.return||f.return();case 60:if(e.prev=60,!c){e.next=63;break}throw l;case 63:return e.finish(60);case 64:return e.finish(57);case 65:k=!0,b=!1,w=void 0,e.prev=68,x=t[Symbol.iterator]();case 70:if(k=(S=x.next()).done){e.next=81;break}if(!((s=S.value).items&&s.items.length>0||s.customHandler)){e.next=77;break}return e.next=75,this.runMigration(s,s.items);case 75:e.next=78;break;case 77:this.markMigrationCompleted(s);case 78:k=!0,e.next=70;break;case 81:e.next=87;break;case 83:e.prev=83,e.t3=e.catch(68),b=!0,w=e.t3;case 87:e.prev=87,e.prev=88,k||null==x.return||x.return();case 90:if(e.prev=90,!b){e.next=93;break}throw w;case 93:return e.finish(90);case 94:return e.finish(87);case 95:for(_=!0,R=!1,I=void 0,e.prev=98,A=this.completionHandlers[Symbol.iterator]();!(_=(D=A.next()).done);_=!0)(0,D.value)();e.next=106;break;case 102:e.prev=102,e.t4=e.catch(98),R=!0,I=e.t4;case 106:e.prev=106,e.prev=107,_||null==A.return||A.return();case 109:if(e.prev=109,!R){e.next=112;break}throw I;case 112:return e.finish(109);case 113:return e.finish(106);case 114:case"end":return e.stop()}}),e,this,[[6,10,14,22],[15,,17,21],[25,53,57,65],[32,36,40,48],[41,,43,47],[58,,60,64],[68,83,87,95],[88,,90,94],[98,102,106,114],[107,,109,113]])}))),function(){return s.apply(this,arguments)})},{key:"encode",value:(o=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",window.btoa(t));case 1:case"end":return e.stop()}}),e)}))),function(e){return o.apply(this,arguments)})},{key:"decode",value:(a=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",window.atob(t));case 1:case"end":return e.stop()}}),e)}))),function(e){return a.apply(this,arguments)})},{key:"getCompletedMigrations",value:(i=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._completed){e.next=5;break}return e.next=3,this.storageManager.getItem("migrations");case 3:t=e.sent,this._completed=t?JSON.parse(t):[];case 5:return e.abrupt("return",this._completed);case 6:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getPendingMigrations",value:(n=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getCompletedMigrations();case 2:t=e.sent,r=[],n=!0,i=!1,a=void 0,e.prev=7,o=this.migrations[Symbol.iterator]();case 9:if(n=(s=o.next()).done){e.next=22;break}return u=s.value,e.t0=t,e.next=14,this.encode(u.name);case 14:if(e.t1=e.sent,e.t2=e.t0.indexOf.call(e.t0,e.t1),e.t3=-1,e.t2!=e.t3){e.next=19;break}r.push(u);case 19:n=!0,e.next=9;break;case 22:e.next=28;break;case 24:e.prev=24,e.t4=e.catch(7),i=!0,a=e.t4;case 28:e.prev=28,e.prev=29,n||null==o.return||o.return();case 31:if(e.prev=31,!i){e.next=34;break}throw a;case 34:return e.finish(31);case 35:return e.finish(28);case 36:return e.abrupt("return",r);case 37:case"end":return e.stop()}}),e,this,[[7,24,28,36],[29,,31,35]])}))),function(){return n.apply(this,arguments)})},{key:"markMigrationCompleted",value:(r=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getCompletedMigrations();case 2:return r=e.sent,e.t0=r,e.next=6,this.encode(t.name);case 6:e.t1=e.sent,e.t0.push.call(e.t0,e.t1),this.storageManager.setItem("migrations",JSON.stringify(r)),t.running=!1;case 10:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"runMigration",value:(t=v(regeneratorRuntime.mark((function e(t,r){var n=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.running){e.next=2;break}return e.abrupt("return");case 2:if(console.log("Running migration:",t.name),t.running=!0,!t.customHandler){e.next=8;break}return e.abrupt("return",t.customHandler().then((function(){n.markMigrationCompleted(t)})));case 8:return e.abrupt("return",t.handler(r).then((function(){n.markMigrationCompleted(t)})));case 9:case"end":return e.stop()}}),e)}))),function(e,r){return t.apply(this,arguments)})}]),e}();n.SFMigrationManager=R;var I=function(){function e(t){g(this,e),e.MappingSourceRemoteRetrieved="MappingSourceRemoteRetrieved",e.MappingSourceRemoteSaved="MappingSourceRemoteSaved",e.MappingSourceLocalSaved="MappingSourceLocalSaved",e.MappingSourceLocalRetrieved="MappingSourceLocalRetrieved",e.MappingSourceLocalDirtied="MappingSourceLocalDirtied",e.MappingSourceComponentRetrieved="MappingSourceComponentRetrieved",e.MappingSourceDesktopInstalled="MappingSourceDesktopInstalled",e.MappingSourceRemoteActionRetrieved="MappingSourceRemoteActionRetrieved",e.MappingSourceFileImport="MappingSourceFileImport",e.isMappingSourceRetrieved=function(t){return[e.MappingSourceRemoteRetrieved,e.MappingSourceComponentRetrieved,e.MappingSourceRemoteActionRetrieved].includes(t)},this.$timeout=t||setTimeout.bind(window),this.itemSyncObservers=[],this.items=[],this.itemsHash={},this.missedReferences={},this.uuidChangeObservers=[]}var t,r,n,i,a,o,s,u,c,l,f,h;return k(e,[{key:"handleSignout",value:function(){this.items.length=0,this.itemsHash={},this.missedReferences={}}},{key:"addModelUuidChangeObserver",value:function(e,t){this.uuidChangeObservers.push({id:e,callback:t})}},{key:"notifyObserversOfUuidChange",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,o=this.uuidChangeObservers[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value;try{s.callback(e,t)}catch(e){console.error("Notify observers of uuid change exception:",e)}}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}},{key:"alternateUUIDForItem",value:(h=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.createItem(r),t.next=3,SFJS.crypto.generateUUID();case 3:for(n.uuid=t.sent,n.informReferencesOfUUIDChange(r.uuid,n.uuid),this.informModelsOfUUIDChangeForItem(n,r.uuid,n.uuid),i=!0,a=!1,o=void 0,t.prev=9,s=r.referencingObjects[Symbol.iterator]();!(i=(u=s.next()).done);i=!0)(c=u.value).setIsNoLongerBeingReferencedBy(r),r.setIsNoLongerBeingReferencedBy(c),c.addItemAsRelationship(n);t.next=17;break;case 13:t.prev=13,t.t0=t.catch(9),a=!0,o=t.t0;case 17:t.prev=17,t.prev=18,i||null==s.return||s.return();case 20:if(t.prev=20,!a){t.next=23;break}throw o;case 23:return t.finish(20);case 24:return t.finish(17);case 25:return this.setItemsDirty(r.referencingObjects,!0),this.resolveReferencesForItem(n),this.loggingEnabled&&console.log(r.uuid,"--\x3e",n.uuid),r.deleted=!0,r.content.references=[],this.setItemDirty(r,!1,!1,e.MappingSourceLocalSaved),t.next=33,this.mapResponseItemsToLocalModels([r],e.MappingSourceLocalSaved);case 33:return this.addItem(n),this.setItemDirty(n,!0,!0,e.MappingSourceLocalSaved),this.notifyObserversOfUuidChange(r,n),t.abrupt("return",n);case 37:case"end":return t.stop()}}),t,this,[[9,13,17,25],[18,,20,24]])}))),function(e){return h.apply(this,arguments)})},{key:"informModelsOfUUIDChangeForItem",value:function(e,t,r){var n=!0,i=!1,a=void 0;try{for(var o,s=this.items[Symbol.iterator]();!(n=(o=s.next()).done);n=!0)o.value.potentialItemOfInterestHasChangedItsUUID(e,t,r)}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}}},{key:"didSyncModelsOffline",value:function(t){this.notifySyncObserversOfModels(t,e.MappingSourceLocalSaved)}},{key:"mapResponseItemsToLocalModels",value:(f=v(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mapResponseItemsToLocalModelsWithOptions({items:t,source:r,sourceKey:n}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return f.apply(this,arguments)})},{key:"mapResponseItemsToLocalModelsOmittingFields",value:(l=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mapResponseItemsToLocalModelsWithOptions({items:t,omitFields:r,source:n,sourceKey:i}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return l.apply(this,arguments)})},{key:"mapResponseItemsToLocalModelsWithOptions",value:(c=v(regeneratorRuntime.mark((function e(t){var r,n,i,a,o,s,u,c,l,f,h,d,y,v,g,m,k,b,w,x,S,_,R,I,A,D,M,C,O,F,P,j,B,E,T,L,H,z,U;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.items,n=t.omitFields,i=t.source,a=t.sourceKey,t.options,o=[],s=[],u=[],c=!0,l=!1,f=void 0,e.prev=5,h=r[Symbol.iterator]();case 7:if(c=(d=h.next()).done){e.next=58;break}if(y=d.value){e.next=11;break}return e.abrupt("continue",55);case 11:if(v=!y.content&&!y.errorDecrypting,y.content_type&&y.uuid&&!v||y.deleted){e.next=16;break}return console.error("Server response item is corrupt:",y),e.abrupt("continue",55);case 16:if(!Array.isArray(n)){e.next=36;break}for(g=!0,m=!1,k=void 0,e.prev=20,b=n[Symbol.iterator]();!(g=(w=b.next()).done);g=!0)x=w.value,delete y[x];e.next=28;break;case 24:e.prev=24,e.t0=e.catch(20),m=!0,k=e.t0;case 28:e.prev=28,e.prev=29,g||null==b.return||b.return();case 31:if(e.prev=31,!m){e.next=34;break}throw k;case 34:return e.finish(31);case 35:return e.finish(28);case 36:if((S=this.findItem(y.uuid))&&(S.updateFromJSON(y),S.dummy=!1),_=y.content_type||S&&S.content_type,!this.acceptableContentTypes||this.acceptableContentTypes.includes(_)){e.next=42;break}return e.abrupt("continue",55);case 42:if(R=!1,1!=y.deleted){e.next=50;break}if(!y.dirty){e.next=48;break}R=!0,e.next=50;break;case 48:return S&&(o.push(S),u.push(S),this.removeItemLocally(S)),e.abrupt("continue",55);case 50:S||(S=this.createItem(y)),this.addItem(S,R),S.errorDecrypting||u.push(S),o.push(S),s.push(y);case 55:c=!0,e.next=7;break;case 58:e.next=64;break;case 60:e.prev=60,e.t1=e.catch(5),l=!0,f=e.t1;case 64:e.prev=64,e.prev=65,c||null==h.return||h.return();case 67:if(e.prev=67,!l){e.next=70;break}throw f;case 70:return e.finish(67);case 71:return e.finish(64);case 72:for(I=!0,A=!1,D=void 0,e.prev=75,M=s.entries()[Symbol.iterator]();!(I=(C=M.next()).done);I=!0)O=p(C.value,2),F=O[0],P=O[1],j=o[F],P.content&&this.resolveReferencesForItem(j),j.didFinishSyncing();e.next=83;break;case 79:e.prev=79,e.t2=e.catch(75),A=!0,D=e.t2;case 83:e.prev=83,e.prev=84,I||null==M.return||M.return();case 86:if(e.prev=86,!A){e.next=89;break}throw D;case 89:return e.finish(86);case 90:return e.finish(83);case 91:for(B=this.popMissedReferenceStructsForObjects(s),E=!0,T=!1,L=void 0,e.prev=95,H=function(){var e=U.value,t=o.find((function(t){return t.uuid==e.reference_uuid}));t&&e.for_item.addItemAsRelationship(t)},z=B[Symbol.iterator]();!(E=(U=z.next()).done);E=!0)H();e.next=104;break;case 100:e.prev=100,e.t3=e.catch(95),T=!0,L=e.t3;case 104:e.prev=104,e.prev=105,E||null==z.return||z.return();case 107:if(e.prev=107,!T){e.next=110;break}throw L;case 110:return e.finish(107);case 111:return e.finish(104);case 112:return e.next=114,this.notifySyncObserversOfModels(u,i,a);case 114:return e.abrupt("return",o);case 115:case"end":return e.stop()}}),e,this,[[5,60,64,72],[20,24,28,36],[29,,31,35],[65,,67,71],[75,79,83,91],[84,,86,90],[95,100,104,112],[105,,107,111]])}))),function(e){return c.apply(this,arguments)})},{key:"missedReferenceBuildKey",value:function(e,t){return"".concat(e,":").concat(t)}},{key:"popMissedReferenceStructsForObjects",value:function(e){if(!e||0==e.length)return[];for(var t=[],r=[],n=e.map((function(e){return e.uuid})),i=n[0].length,a=0,o=Object.keys(this.missedReferences);a<o.length;a++){var s=o[a];n.includes(s.substring(0,i))&&(t.push(this.missedReferences[s]),r.push(s))}for(var u=0,c=r;u<c.length;u++){var l=c[u];delete this.missedReferences[l]}return t}},{key:"resolveReferencesForItem",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e.errorDecrypting){var r=e.contentObject;if(e.updateLocalRelationships(),r.references){var n=r.references.slice().map((function(e){return e.uuid})),i=this.findItems(n,!0),a=!0,o=!1,s=void 0;try{for(var u,c=i.entries()[Symbol.iterator]();!(a=(u=c.next()).done);a=!0){var l=p(u.value,2),f=l[0],h=l[1];if(h)e.addItemAsRelationship(h),t&&this.setItemDirty(h,!0);else{var d=n[f],y=this.missedReferenceBuildKey(d,e.uuid);if(!this.missedReferences[y]){var v={reference_uuid:d,for_item:e};this.missedReferences[y]=v}}}}catch(e){o=!0,s=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw s}}}}}},{key:"notifySyncObserversOfModels",value:(u=v(regeneratorRuntime.mark((function e(t,r,n){var i,a,o,s,u,c,l,f=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=this.itemSyncObservers.sort((function(e,t){return e.priority<t.priority?-1:1})),a=!0,o=!1,s=void 0,e.prev=4,u=regeneratorRuntime.mark((function e(){var i,a,o,s,u,c,h,p,d,y;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=l.value,a=i.types.includes("*")?t:t.filter((function(e){return i.types.includes(e.content_type)})),o=[],s=[],u=!0,c=!1,h=void 0,e.prev=6,p=a[Symbol.iterator]();!(u=(d=p.next()).done);u=!0)(y=d.value).deleted?s.push(y):o.push(y);e.next=14;break;case 10:e.prev=10,e.t0=e.catch(6),c=!0,h=e.t0;case 14:e.prev=14,e.prev=15,u||null==p.return||p.return();case 17:if(e.prev=17,!c){e.next=20;break}throw h;case 20:return e.finish(17);case 21:return e.finish(14);case 22:if(!(a.length>0)){e.next=25;break}return e.next=25,f._callSyncObserverCallbackWithTimeout(i,a,o,s,r,n);case 25:case"end":return e.stop()}}),e,null,[[6,10,14,22],[15,,17,21]])})),c=i[Symbol.iterator]();case 7:if(a=(l=c.next()).done){e.next=12;break}return e.delegateYield(u(),"t0",9);case 9:a=!0,e.next=7;break;case 12:e.next=18;break;case 14:e.prev=14,e.t1=e.catch(4),o=!0,s=e.t1;case 18:e.prev=18,e.prev=19,a||null==c.return||c.return();case 21:if(e.prev=21,!o){e.next=24;break}throw s;case 24:return e.finish(21);case 25:return e.finish(18);case 26:case"end":return e.stop()}}),e,this,[[4,14,18,26],[19,,21,25]])}))),function(e,t,r){return u.apply(this,arguments)})},{key:"_callSyncObserverCallbackWithTimeout",value:(s=v(regeneratorRuntime.mark((function e(t,r,n,i,a,o){var s=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,u){s.$timeout((function(){try{t.callback(r,n,i,a,o)}catch(e){console.error("Sync observer exception",e)}finally{e()}}))})));case 1:case"end":return e.stop()}}),e)}))),function(e,t,r,n,i,a){return s.apply(this,arguments)})},{key:"setItemDirty",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;this.setItemsDirty([e],t,r,n,i)}},{key:"setItemsDirty",value:function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0,o=!0,s=!1,u=void 0;try{for(var c,l=t[Symbol.iterator]();!(o=(c=l.next()).done);o=!0)c.value.setDirty(r,n)}catch(e){s=!0,u=e}finally{try{o||null==l.return||l.return()}finally{if(s)throw u}}this.notifySyncObserversOfModels(t,i||e.MappingSourceLocalDirtied,a)}},{key:"createItem",value:function(t){var r=e.ContentTypeClassMapping&&e.ContentTypeClassMapping[t.content_type];return r||(r=P),new r(t)}},{key:"createDuplicateItemFromResponseItem",value:(o=v(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("function"!=typeof t.setDirty){e.next=3;break}return console.error("Attempting to create conflicted copy of non-response item."),e.abrupt("return",null);case 3:return r=JSON.parse(JSON.stringify(t)),e.next=6,SFJS.crypto.generateUUID();case 6:return r.uuid=e.sent,n=this.createItem(r),e.abrupt("return",n);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"duplicateItemAndAddAsConflict",value:function(e){return this.duplicateItemWithCustomContentAndAddAsConflict({content:e.content,duplicateOf:e})}},{key:"duplicateItemWithCustomContentAndAddAsConflict",value:function(e){var t=e.content,r=e.duplicateOf,n=this.duplicateItemWithCustomContent({content:t,duplicateOf:r});return this.addDuplicatedItemAsConflict({duplicate:n,duplicateOf:r}),n}},{key:"addDuplicatedItemAsConflict",value:function(e){var t=e.duplicate,r=e.duplicateOf;this.addDuplicatedItem(t,r),t.content.conflict_of=r.uuid}},{key:"duplicateItemWithCustomContent",value:function(e){var t=e.content,r=e.duplicateOf,n=new r.constructor({content:t});return n.created_at=r.created_at,n.content_type||(n.content_type=r.content_type),n}},{key:"duplicateItemAndAdd",value:function(e){var t=this.duplicateItemWithoutAdding(e);return this.addDuplicatedItem(t,e),t}},{key:"duplicateItemWithoutAdding",value:function(e){var t=new e.constructor({content:e.content});return t.created_at=e.created_at,t.content_type||(t.content_type=e.content_type),t}},{key:"addDuplicatedItem",value:function(e,t){this.addItem(e);var r=!0,n=!1,i=void 0;try{for(var a,o=t.referencingObjects[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value;s.addItemAsRelationship(e),this.setItemDirty(s,!0)}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}this.resolveReferencesForItem(e),this.setItemDirty(e,!0)}},{key:"addItem",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.addItems([e],t)}},{key:"addItems",value:function(e){var t=this;e.forEach((function(e){t.itemsHash[e.uuid]||(t.itemsHash[e.uuid]=e,t.items.push(e))}))}},{key:"addItemSyncObserver",value:function(e,t,r){this.addItemSyncObserverWithPriority({id:e,types:t,callback:r,priority:1})}},{key:"addItemSyncObserverWithPriority",value:function(e){var t=e.id,r=e.priority,n=e.types,i=e.callback;Array.isArray(n)||(n=[n]),this.itemSyncObservers.push({id:t,types:n,priority:r,callback:i})}},{key:"removeItemSyncObserver",value:function(e){_.remove(this.itemSyncObservers,_.find(this.itemSyncObservers,{id:e}))}},{key:"getDirtyItems",value:function(){return this.items.filter((function(e){return 1==e.dirty&&!e.dummy&&(!e.errorDecrypting||e.deleted)}))}},{key:"clearDirtyItems",value:function(e){var t=!0,r=!1,n=void 0;try{for(var i,a=e[Symbol.iterator]();!(t=(i=a.next()).done);t=!0)i.value.setDirty(!1)}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}},{key:"removeAndDirtyAllRelationshipsForItem",value:function(e){if(!e.errorDecrypting){var t=!0,r=!1,n=void 0;try{for(var i,a=e.content.references[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value,s=this.findItem(o.uuid);s&&(e.removeItemAsRelationship(s),s.hasRelationshipWithItem(e)&&(s.removeItemAsRelationship(e),this.setItemDirty(s,!0)))}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}var u=!0,c=!1,l=void 0;try{for(var f,h=e.referencingObjects[Symbol.iterator]();!(u=(f=h.next()).done);u=!0){var p=f.value;p.removeItemAsRelationship(e),this.setItemDirty(p,!0)}}catch(e){c=!0,l=e}finally{try{u||null==h.return||h.return()}finally{if(c)throw l}}e.referencingObjects=[]}},{key:"setAllItemsDirty",value:function(){var e=this.allItems;this.setItemsDirty(e,!0)}},{key:"setItemToBeDeleted",value:function(e){e.deleted=!0,e.dummy||this.setItemDirty(e,!0),this.removeAndDirtyAllRelationshipsForItem(e)}},{key:"removeItemLocally",value:(a=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:_.remove(this.items,{uuid:t.uuid}),delete this.itemsHash[t.uuid],t.isBeingRemovedLocally();case 3:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"allItemsMatchingTypes",value:function(e){return this.allItems.filter((function(t){return(_.includes(e,t.content_type)||_.includes(e,"*"))&&!t.dummy}))}},{key:"invalidItems",value:function(){return this.allItems.filter((function(e){return e.errorDecrypting}))}},{key:"validItemsForContentType",value:function(e){return this.allItems.filter((function(t){return t.content_type==e&&!t.errorDecrypting}))}},{key:"findItem",value:function(e){return this.itemsHash[e]}},{key:"findItems",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=[],n=!0,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var u=o.value,c=this.itemsHash[u];(c||t)&&r.push(c)}}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}},{key:"itemsMatchingPredicate",value:function(e){return this.itemsMatchingPredicates([e])}},{key:"itemsMatchingPredicates",value:function(e){return this.filterItemsWithPredicates(this.allItems,e)}},{key:"filterItemsWithPredicates",value:function(e,t){return e.filter((function(e){var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value;if(!e.satisfiesPredicate(s))return!1}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return!0}))}},{key:"importItems",value:(i=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c,l,f,h,p,d,y,v,g,m,k,b,w,x,S,_,R,I,A,D,M;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n=[],i={},a=!0,o=!1,s=void 0,t.prev=5,u=r[Symbol.iterator]();case 7:if(a=(c=u.next()).done){t.next=18;break}if(l=c.value,f=this.findItem(l.uuid)){t.next=13;break}return i[l.uuid]={},t.abrupt("continue",15);case 13:h=this.duplicateItemWithoutAdding(f),i[l.uuid]={frozenValue:h,itemRef:f};case 15:a=!0,t.next=7;break;case 18:t.next=24;break;case 20:t.prev=20,t.t0=t.catch(5),o=!0,s=t.t0;case 24:t.prev=24,t.prev=25,a||null==u.return||u.return();case 27:if(t.prev=27,!o){t.next=30;break}throw s;case 30:return t.finish(27);case 31:return t.finish(24);case 32:p=!0,d=!1,y=void 0,t.prev=35,v=r[Symbol.iterator]();case 37:if(p=(g=v.next()).done){t.next=52;break}if(m=g.value,k=i[m.uuid],b=k.frozenValue,w=k.itemRef,!b||w.errorDecrypting){t.next=47;break}return t.next=43,this.createDuplicateItemFromResponseItem(m);case 43:x=t.sent,m.deleted||b.isItemContentEqualWith(x)||(this.addDuplicatedItemAsConflict({duplicate:x,duplicateOf:w}),n.push(x)),t.next=49;break;case 47:n.push(m),w&&w.errorDecrypting&&(w.errorDecrypting=!1);case 49:p=!0,t.next=37;break;case 52:t.next=58;break;case 54:t.prev=54,t.t1=t.catch(35),d=!0,y=t.t1;case 58:t.prev=58,t.prev=59,p||null==v.return||v.return();case 61:if(t.prev=61,!d){t.next=64;break}throw y;case 64:return t.finish(61);case 65:return t.finish(58);case 66:return t.next=68,this.mapResponseItemsToLocalModels(n,e.MappingSourceFileImport);case 68:for(S=t.sent,_=!0,R=!1,I=void 0,t.prev=72,A=S[Symbol.iterator]();!(_=(D=A.next()).done);_=!0)M=D.value,this.setItemDirty(M,!0,!1),M.deleted=!1;t.next=80;break;case 76:t.prev=76,t.t2=t.catch(72),R=!0,I=t.t2;case 80:t.prev=80,t.prev=81,_||null==A.return||A.return();case 83:if(t.prev=83,!R){t.next=86;break}throw I;case 86:return t.finish(83);case 87:return t.finish(80);case 88:return t.abrupt("return",S);case 89:case"end":return t.stop()}}),t,this,[[5,20,24,32],[25,,27,31],[35,54,58,66],[59,,61,65],[72,76,80,88],[81,,83,87]])}))),function(e){return i.apply(this,arguments)})},{key:"getAllItemsJSONData",value:(n=v(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.getJSONDataForItems(this.allItems,t,r,n));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"getJSONDataForItems",value:(r=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Promise.all(t.map((function(e){return new j(e,r,n).paramsForExportFile()}))).then((function(e){if(i&&0==e.length)return null;var t={items:e};return r&&(t.auth_params=n),JSON.stringify(t,null,2)})));case 1:case"end":return e.stop()}}),e)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"computeDataIntegrityHash",value:(t=v(regeneratorRuntime.mark((function e(){var t,r,n,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t=this.allNondummyItems.sort((function(e,t){return t.updated_at-e.updated_at})),r=t.map((function(e){return e.updatedAtTimestamp()})),n=r.join(","),e.next=6,SFJS.crypto.sha256(n);case 6:return i=e.sent,e.abrupt("return",i);case 10:return e.prev=10,e.t0=e.catch(0),console.error("Error computing data integrity hash",e.t0),e.abrupt("return",null);case 14:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return t.apply(this,arguments)})},{key:"allItems",get:function(){return this.items.slice()}},{key:"allNondummyItems",get:function(){return this.items.filter((function(e){return!e.dummy}))}}]),e}();n.SFModelManager=I;var A=function(){function e(t,r,n){g(this,e),this.modelManager=t,this.syncManager=r,this.singletonManager=n,this.loadPrivileges(),e.CredentialAccountPassword="CredentialAccountPassword",e.CredentialLocalPasscode="CredentialLocalPasscode",e.ActionManageExtensions="ActionManageExtensions",e.ActionManageBackups="ActionManageBackups",e.ActionViewProtectedNotes="ActionViewProtectedNotes",e.ActionManagePrivileges="ActionManagePrivileges",e.ActionManagePasscode="ActionManagePasscode",e.ActionDeleteNote="ActionDeleteNote",e.SessionExpiresAtKey="SessionExpiresAtKey",e.SessionLengthKey="SessionLengthKey",e.SessionLengthNone=0,e.SessionLengthFiveMinutes=300,e.SessionLengthOneHour=3600,e.SessionLengthOneWeek=604800,this.availableActions=[e.ActionViewProtectedNotes,e.ActionDeleteNote,e.ActionManagePasscode,e.ActionManageBackups,e.ActionManageExtensions,e.ActionManagePrivileges],this.availableCredentials=[e.CredentialAccountPassword,e.CredentialLocalPasscode],this.sessionLengths=[e.SessionLengthNone,e.SessionLengthFiveMinutes,e.SessionLengthOneHour,e.SessionLengthOneWeek,e.SessionLengthIndefinite]}var t,r,n,i,a,o,s,u,c,l,f,h;return k(e,[{key:"setDelegate",value:function(e){this.delegate=e}},{key:"getAvailableActions",value:function(){return this.availableActions}},{key:"getAvailableCredentials",value:function(){return this.availableCredentials}},{key:"netCredentialsForAction",value:(h=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c,l;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPrivileges();case 2:t.t0=r,n=t.sent.getCredentialsForAction(t.t0),i=[],a=!0,o=!1,s=void 0,t.prev=8,u=n[Symbol.iterator]();case 10:if(a=(c=u.next()).done){t.next=27;break}if((l=c.value)!=e.CredentialAccountPassword){t.next=19;break}return t.next=15,this.delegate.isOffline();case 15:t.sent||i.push(l),t.next=24;break;case 19:if(l!=e.CredentialLocalPasscode){t.next=24;break}return t.next=22,this.delegate.hasLocalPasscode();case 22:t.sent&&i.push(l);case 24:a=!0,t.next=10;break;case 27:t.next=33;break;case 29:t.prev=29,t.t1=t.catch(8),o=!0,s=t.t1;case 33:t.prev=33,t.prev=34,a||null==u.return||u.return();case 36:if(t.prev=36,!o){t.next=39;break}throw s;case 39:return t.finish(36);case 40:return t.finish(33);case 41:return t.abrupt("return",i);case 42:case"end":return t.stop()}}),t,this,[[8,29,33,41],[34,,36,40]])}))),function(e){return h.apply(this,arguments)})},{key:"loadPrivileges",value:(f=v(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.loadPromise){e.next=2;break}return e.abrupt("return",this.loadPromise);case 2:return this.loadPromise=new Promise((function(e,r){var n=E.contentType(),i=new B("content_type","=",n);t.singletonManager.registerSingleton([i],(function(r){t.privileges=r,e(r)}),function(){var r=v(regeneratorRuntime.mark((function r(i){var a;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(a=new E({content_type:n}),SFJS.crypto.generateUUIDSync){r.next=4;break}return r.next=4,a.initUUID();case 4:t.modelManager.addItem(a),t.modelManager.setItemDirty(a,!0),t.syncManager.sync(),i(a),e(a);case 9:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}())})),e.abrupt("return",this.loadPromise);case 4:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"getPrivileges",value:(l=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.privileges){e.next=4;break}return e.abrupt("return",this.privileges);case 4:return e.abrupt("return",this.loadPrivileges());case 5:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"displayInfoForCredential",value:function(t){var r={};return r[e.CredentialAccountPassword]={label:"Account Password",prompt:"Please enter your account password."},r[e.CredentialLocalPasscode]={label:"Local Passcode",prompt:"Please enter your local passcode."},r[t]}},{key:"displayInfoForAction",value:function(t){var r={};return r[e.ActionManageExtensions]={label:"Manage Extensions"},r[e.ActionManageBackups]={label:"Download/Import Backups"},r[e.ActionViewProtectedNotes]={label:"View Protected Notes"},r[e.ActionManagePrivileges]={label:"Manage Privileges"},r[e.ActionManagePasscode]={label:"Manage Passcode"},r[e.ActionDeleteNote]={label:"Delete Notes"},r[t]}},{key:"getSessionLengthOptions",value:function(){return[{value:e.SessionLengthNone,label:"Don't Remember"},{value:e.SessionLengthFiveMinutes,label:"5 Minutes"},{value:e.SessionLengthOneHour,label:"1 Hour"},{value:e.SessionLengthOneWeek,label:"1 Week"}]}},{key:"setSessionLength",value:(c=v(regeneratorRuntime.mark((function t(r){var n;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=r,a=void 0,(a=new Date).setSeconds(a.getSeconds()+i),n=a,t.abrupt("return",Promise.all([this.delegate.saveToStorage(e.SessionExpiresAtKey,JSON.stringify(n)),this.delegate.saveToStorage(e.SessionLengthKey,JSON.stringify(r))]));case 3:case"end":return t.stop()}var i,a}),t,this)}))),function(e){return c.apply(this,arguments)})},{key:"clearSession",value:(u=v(regeneratorRuntime.mark((function t(){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.setSessionLength(e.SessionLengthNone));case 1:case"end":return t.stop()}}),t,this)}))),function(){return u.apply(this,arguments)})},{key:"getSelectedSessionLength",value:(s=v(regeneratorRuntime.mark((function t(){var r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.delegate.getFromStorage(e.SessionLengthKey);case 2:if(!(r=t.sent)){t.next=7;break}return t.abrupt("return",JSON.parse(r));case 7:return t.abrupt("return",e.SessionLengthNone);case 8:case"end":return t.stop()}}),t,this)}))),function(){return s.apply(this,arguments)})},{key:"getSessionExpirey",value:(o=v(regeneratorRuntime.mark((function t(){var r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.delegate.getFromStorage(e.SessionExpiresAtKey);case 2:if(!(r=t.sent)){t.next=7;break}return t.abrupt("return",new Date(JSON.parse(r)));case 7:return t.abrupt("return",new Date);case 8:case"end":return t.stop()}}),t,this)}))),function(){return o.apply(this,arguments)})},{key:"actionHasPrivilegesConfigured",value:(a=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.netCredentialsForAction(t);case 2:return e.t0=e.sent.length,e.abrupt("return",e.t0>0);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"actionRequiresPrivilege",value:(i=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSessionExpirey();case 2:if(!(e.sent>new Date)){e.next=5;break}return e.abrupt("return",!1);case 5:return e.next=7,this.netCredentialsForAction(t);case 7:return r=e.sent,e.abrupt("return",r.length>0);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"savePrivileges",value:(n=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getPrivileges();case 2:t=e.sent,this.modelManager.setItemDirty(t,!0),this.syncManager.sync();case 5:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"authenticateAction",value:(r=v(regeneratorRuntime.mark((function e(t,r){var n,i,a,o,s,u,c,l,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.netCredentialsForAction(t);case 2:n=e.sent,i=[],a=[],o=!0,s=!1,u=void 0,e.prev=7,c=n[Symbol.iterator]();case 9:if(o=(l=c.next()).done){e.next=18;break}return f=l.value,e.next=13,this._verifyAuthenticationParameters(f,r[f]);case 13:e.sent?i.push(f):a.push(f);case 15:o=!0,e.next=9;break;case 18:e.next=24;break;case 20:e.prev=20,e.t0=e.catch(7),s=!0,u=e.t0;case 24:e.prev=24,e.prev=25,o||null==c.return||c.return();case 27:if(e.prev=27,!s){e.next=30;break}throw u;case 30:return e.finish(27);case 31:return e.finish(24);case 32:return e.abrupt("return",{success:0==a.length,successfulCredentials:i,failedCredentials:a});case 33:case"end":return e.stop()}}),e,this,[[7,20,24,32],[25,,27,31]])}))),function(e,t){return r.apply(this,arguments)})},{key:"_verifyAuthenticationParameters",value:(t=v(regeneratorRuntime.mark((function t(r,n){var i,a,o=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(i=function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",o.delegate.verifyAccountPassword(t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),a=function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",o.delegate.verifyLocalPasscode(t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),r!=e.CredentialAccountPassword){t.next=6;break}return t.abrupt("return",i(n));case 6:if(r!=e.CredentialLocalPasscode){t.next=8;break}return t.abrupt("return",a(n));case 8:case"end":return t.stop()}}),t)}))),function(e,r){return t.apply(this,arguments)})}]),e}();n.SFPrivilegesManager=A;var D=function(){function e(t,r,n,i,a){var o=this;g(this,e),this.modelManager=t,this.storageManager=r,this.$timeout=a||setTimeout.bind(window),this.keyRequestHandler=n,this.loadFromDisk().then((function(){o.modelManager.addItemSyncObserver("session-history",i,(function(e,t,r,n,i){if(n!==I.MappingSourceLocalDirtied){var a=!0,s=!1,u=void 0;try{for(var c,l=e[Symbol.iterator]();!(a=(c=l.next()).done);a=!0){var f=c.value;try{o.addHistoryEntryForItem(f)}catch(e){console.log("Caught exception while trying to add item history entry",e)}}}catch(e){s=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(s)throw u}}}}))}))}var t,r,n,i,a,o,s;return k(e,[{key:"encryptionParams",value:(s=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.keyRequestHandler());case 1:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"addHistoryEntryForItem",value:function(e){var t=this,r={uuid:e.uuid,content_type:e.content_type,updated_at:e.updated_at,content:e.getContentCopy()},n=this.historySession.addEntryForItem(r);this.autoOptimize&&this.historySession.optimizeHistoryForItem(e),n&&this.diskEnabled&&(this.diskTimeout&&(this.$timeout.hasOwnProperty("cancel")?this.$timeout.cancel(this.diskTimeout):clearTimeout(this.diskTimeout)),this.diskTimeout=this.$timeout((function(){t.saveToDisk()}),2e3))}},{key:"historyForItem",value:function(e){return this.historySession.historyForItem(e)}},{key:"clearHistoryForItem",value:(o=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.historySession.clearItemHistory(t),e.abrupt("return",this.saveToDisk());case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"clearAllHistory",value:(a=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.historySession.clearAllHistory(),e.abrupt("return",this.storageManager.removeItem("sessionHistory_revisions"));case 2:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"toggleDiskSaving",value:(i=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.diskEnabled=!this.diskEnabled,!this.diskEnabled){e.next=6;break}this.storageManager.setItem("sessionHistory_persist",JSON.stringify(!0)),this.saveToDisk(),e.next=8;break;case 6:return this.storageManager.setItem("sessionHistory_persist",JSON.stringify(!1)),e.abrupt("return",this.storageManager.removeItem("sessionHistory_revisions"));case 8:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"saveToDisk",value:(n=v(regeneratorRuntime.mark((function e(){var t,r=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.diskEnabled){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.encryptionParams();case 4:t=e.sent,new j(this.historySession,t.keys,t.auth_params).paramsForSync().then((function(e){r.storageManager.setItem("sessionHistory_revisions",JSON.stringify(e))}));case 7:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"loadFromDisk",value:(r=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.storageManager.getItem("sessionHistory_persist");case 2:return(t=e.sent)&&(this.diskEnabled=JSON.parse(t)),e.next=6,this.storageManager.getItem("sessionHistory_revisions");case 6:if(!(r=e.sent)){e.next=18;break}return r=JSON.parse(r),e.next=11,this.encryptionParams();case 11:return n=e.sent,e.next=14,SFJS.itemTransformer.decryptItem(r,n.keys);case 14:i=new T(r),this.historySession=i,e.next=19;break;case 18:this.historySession=new T;case 19:return e.next=21,this.storageManager.getItem("sessionHistory_autoOptimize");case 21:a=e.sent,this.autoOptimize=!a||JSON.parse(a);case 23:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"toggleAutoOptimize",value:(t=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.autoOptimize=!this.autoOptimize,this.autoOptimize?this.storageManager.setItem("sessionHistory_autoOptimize",JSON.stringify(!0)):this.storageManager.setItem("sessionHistory_autoOptimize",JSON.stringify(!1));case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();n.SFSessionHistoryManager=D;var M=function(){function e(t,r){var n=this;g(this,e),this.syncManager=r,this.modelManager=t,this.singletonHandlers=[],t.addItemSyncObserverWithPriority({id:"sf-singleton-manager",types:"*",priority:-1,callback:function(e,r,i,a,o){a!==I.MappingSourceLocalDirtied&&n.resolveSingletons(t.allNondummyItems,null,!0)}}),r.addEventHandler((function(e,r){if("local-data-loaded"==e)n.resolveSingletons(t.allNondummyItems,null,!0),n.initialDataLoaded=!0;else if("sync:completed"==e){if(!n.initialDataLoaded)return;n.resolveSingletons(r.retrievedItems,r.savedItems)}})),t.addModelUuidChangeObserver("singleton-manager",(function(e,t){var r=!0,i=!1,a=void 0;try{for(var o,s=n.singletonHandlers[Symbol.iterator]();!(r=(o=s.next()).done);r=!0){var u=o.value;u.singleton&&B.ItemSatisfiesPredicates(t,u.predicates)&&(u.singleton=null,n.resolveSingletons([t]))}}catch(e){i=!0,a=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw a}}}))}return k(e,[{key:"registerSingleton",value:function(e,t,r){this.singletonHandlers.push({predicates:e,resolutionCallback:t,createBlock:r})}},{key:"resolveSingletons",value:function(e,t,r){var n=this;e=e||[],t=t||[];var i=!0,a=!1,o=void 0;try{for(var s,u=function(){var i=s.value,a=i.predicates.slice(),o=n.modelManager.filterItemsWithPredicates(e,a),u=function(){i.createBlock&&(i.pendingCreateBlockCallback=!0,i.createBlock((function(e){i.singleton=e,i.pendingCreateBlockCallback=!1,i.resolutionCallback&&i.resolutionCallback(e)})))},c=n.modelManager.filterItemsWithPredicates(t,a).length;if(o.length>0||c>0){var l=n.modelManager.itemsMatchingPredicates(a);if(l.length>=2){var f=l.sort((function(e,t){return e.errorDecrypting?1:t.errorDecrypting||e.created_at<t.created_at?-1:1})),h=f[0],p=f.slice(1,f.length),d=!0,y=!1,v=void 0;try{for(var g,m=p[Symbol.iterator]();!(d=(g=m.next()).done);d=!0){var k=g.value;n.modelManager.setItemToBeDeleted(k)}}catch(e){y=!0,v=e}finally{try{d||null==m.return||m.return()}finally{if(y)throw v}}n.syncManager.sync(),i.singleton=h,i.resolutionCallback&&i.resolutionCallback(h)}else if(1==l.length){var b=l[0];b.errorDecrypting?(n.modelManager.setItemToBeDeleted(b),u()):i.singleton&&i.singleton===b||(i.singleton=b,i.resolutionCallback&&i.resolutionCallback(b))}}else i.singleton||r||i.pendingCreateBlockCallback||u()},c=this.singletonHandlers[Symbol.iterator]();!(i=(s=c.next()).done);i=!0)u()}catch(e){a=!0,o=e}finally{try{i||null==c.return||c.return()}finally{if(a)throw o}}}}]),e}();n.SFSingletonManager=M;var C=function(){function e(){g(this,e)}var t,r,n,i,a,o,s,u,c,l;return k(e,[{key:"setItem",value:(l=v(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e,t){return l.apply(this,arguments)})},{key:"getItem",value:(c=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"removeItem",value:(u=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return u.apply(this,arguments)})},{key:"clear",value:(s=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(){return s.apply(this,arguments)})},{key:"getAllModels",value:(o=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(){return o.apply(this,arguments)})},{key:"saveModel",value:(a=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.saveModels([t]));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"saveModels",value:(i=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return i.apply(this,arguments)})},{key:"deleteModel",value:(n=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})},{key:"clearAllModels",value:(r=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(){return r.apply(this,arguments)})},{key:"clearAllData",value:(t=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Promise.all([this.clear(),this.clearAllModels()]));case 1:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();n.SFStorageManager=C;var O,F=function(){function e(t,r,n,i,a){g(this,e),e.KeyRequestLoadLocal="KeyRequestLoadLocal",e.KeyRequestSaveLocal="KeyRequestSaveLocal",e.KeyRequestLoadSaveAccount="KeyRequestLoadSaveAccount",this.httpManager=n,this.modelManager=t,this.storageManager=r,this.$interval=a||setInterval.bind(window),this.$timeout=i||setTimeout.bind(window),this.syncStatus={},this.syncStatusObservers=[],this.eventHandlers=[],this.PerSyncItemUploadLimit=150,this.ServerItemDownloadLimit=150,this.MajorDataChangeThreshold=15,this.MaxDiscordanceBeforeOutOfSync=5,this.syncDiscordance=0,this.outOfSync=!1}var t,r,n,i,a,o,s,u,c,l,f,h,p,d,y,m,b,w,x,R,A,D,M;return k(e,[{key:"handleServerIntegrityHash",value:(M=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&0!=t.length){e.next=2;break}return e.abrupt("return",!0);case 2:return e.next=4,this.modelManager.computeDataIntegrityHash();case 4:if(r=e.sent){e.next=7;break}return e.abrupt("return",!0);case 7:if(r===t){e.next=13;break}return this.syncDiscordance++,this.syncDiscordance>=this.MaxDiscordanceBeforeOutOfSync&&(this.outOfSync||(this.outOfSync=!0,this.notifyEvent("enter-out-of-sync"))),e.abrupt("return",!1);case 13:return this.outOfSync&&(this.outOfSync=!1,this.notifyEvent("exit-out-of-sync")),this.syncDiscordance=0,e.abrupt("return",!0);case 16:case"end":return e.stop()}}),e,this)}))),function(e){return M.apply(this,arguments)})},{key:"isOutOfSync",value:function(){return this.outOfSync}},{key:"getServerURL",value:(D=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.storageManager.getItem("server");case 2:if(e.t0=e.sent,e.t0){e.next=5;break}e.t0=window._default_sf_server;case 5:return e.abrupt("return",e.t0);case 6:case"end":return e.stop()}}),e,this)}))),function(){return D.apply(this,arguments)})},{key:"getSyncURL",value:(A=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getServerURL();case 2:return e.t0=e.sent,e.abrupt("return",e.t0+"/items/sync");case 4:case"end":return e.stop()}}),e,this)}))),function(){return A.apply(this,arguments)})},{key:"registerSyncStatusObserver",value:function(e){var t={key:new Date,callback:e};return this.syncStatusObservers.push(t),t}},{key:"removeSyncStatusObserver",value:function(e){_.pull(this.syncStatusObservers,e)}},{key:"syncStatusDidChange",value:function(){var e=this;this.syncStatusObservers.forEach((function(t){t.callback(e.syncStatus)}))}},{key:"addEventHandler",value:function(e){return this.eventHandlers.push(e),e}},{key:"removeEventHandler",value:function(e){_.pull(this.eventHandlers,e)}},{key:"notifyEvent",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,o=this.eventHandlers[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)(0,a.value)(e,t||{})}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}},{key:"setKeyRequestHandler",value:function(e){this.keyRequestHandler=e}},{key:"getActiveKeyInfo",value:(R=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.keyRequestHandler(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return R.apply(this,arguments)})},{key:"initialDataLoaded",value:function(){return!0===this._initialDataLoaded}},{key:"_sortLocalItems",value:function(e){var t=this;return e.sort((function(e,r){var n=new Date(r.updated_at)-new Date(e.updated_at),i=t.contentTypeLoadPriority,a=0,o=0;return i&&(a=i.indexOf(e.content_type),o=i.indexOf(r.content_type),-1==a&&(a=i.length),-1==o&&(o=i.length)),a==o?n:a<o?-1:1}))}},{key:"loadLocalItems",value:(x=v(regeneratorRuntime.mark((function t(){var r,n,i,a,o,s=this,u=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=(r=u.length>0&&void 0!==u[0]?u[0]:{}).incrementalCallback,i=r.batchSize,!(a=r.options)||!a.simulateHighLatency){t.next=5;break}return o=a.simulatedLatency||1e3,t.next=5,this._awaitSleep(o);case 5:if(!this.loadLocalDataPromise){t.next=7;break}return t.abrupt("return",this.loadLocalDataPromise);case 7:return i||(i=100),this.loadLocalDataPromise=this.storageManager.getAllModels().then((function(t){var r=(t=(t=s._sortLocalItems(t)).filter((function(e){var t=s.modelManager.findItem(e.uuid);return!t||new Date(e.dirtiedDate)>t.dirtiedDate}))).length,a=0,o=[],u=function(){var c=v(regeneratorRuntime.mark((function c(){var l,f;return regeneratorRuntime.wrap((function(c){for(;;)switch(c.prev=c.next){case 0:return l=t.slice(a,a+i),c.next=3,s.handleItemsResponse(l,null,I.MappingSourceLocalRetrieved,e.KeyRequestLoadLocal);case 3:if(f=c.sent,o.push(f),!((a+=l.length)<r)){c.next=10;break}return c.abrupt("return",new Promise((function(e,t){s.$timeout((function(){s.notifyEvent("local-data-incremental-load"),n&&n(a,r),u().then(e)}))})));case 10:s._initialDataLoaded=!0,s.notifyEvent("local-data-loaded");case 12:case"end":return c.stop()}}),c)})));return function(){return c.apply(this,arguments)}}();return u()})),t.abrupt("return",this.loadLocalDataPromise);case 10:case"end":return t.stop()}}),t,this)}))),function(){return x.apply(this,arguments)})},{key:"writeItemsToLocalStorage",value:(w=v(regeneratorRuntime.mark((function t(r,n){var i=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(0!=r.length){t.next=2;break}return t.abrupt("return");case 2:return t.abrupt("return",new Promise(function(){var t=v(regeneratorRuntime.mark((function t(a,o){var s,u,c,l,f,h,p,d,y,g;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(s=[],u=[],c=!0,l=!1,f=void 0,t.prev=4,h=r[Symbol.iterator]();!(c=(p=h.next()).done);c=!0)!0!==(d=p.value).deleted||d.dirty?s.push(d):u.push(d);t.next=12;break;case 8:t.prev=8,t.t0=t.catch(4),l=!0,f=t.t0;case 12:t.prev=12,t.prev=13,c||null==h.return||h.return();case 15:if(t.prev=15,!l){t.next=18;break}throw f;case 18:return t.finish(15);case 19:return t.finish(12);case 20:if(!(u.length>0)){t.next=23;break}return t.next=23,Promise.all(u.map(function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",i.storageManager.deleteModel(t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 23:return t.next=25,i.getActiveKeyInfo(e.KeyRequestSaveLocal);case 25:if(y=t.sent,!(s.length>0)){t.next=33;break}return t.next=29,Promise.all(s.map(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new j(t,y.keys,y.auth_params),e.next=3,r.paramsForLocalStorage();case 3:return r=e.sent,n&&delete r.dirty,e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}())).catch((function(e){return o(e)}));case 29:return g=t.sent,t.next=32,i.storageManager.saveModels(g).catch((function(e){console.error("Error writing items",e),i.syncStatus.localError=e,i.syncStatusDidChange(),o()}));case 32:i.syncStatus.localError&&(i.syncStatus.localError=null,i.syncStatusDidChange());case 33:a();case 34:case"end":return t.stop()}}),t,null,[[4,8,12,20],[13,,15,19]])})));return function(e,r){return t.apply(this,arguments)}}()));case 3:case"end":return t.stop()}}),t)}))),function(e,t){return w.apply(this,arguments)})},{key:"syncOffline",value:(b=v(regeneratorRuntime.mark((function e(t){var r,n,i,a,o,s=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=!0,n=!1,i=void 0,e.prev=3,a=t[Symbol.iterator]();!(r=(o=a.next()).done);r=!0)o.value.updated_at=new Date;e.next=11;break;case 7:e.prev=7,e.t0=e.catch(3),n=!0,i=e.t0;case 11:e.prev=11,e.prev=12,r||null==a.return||a.return();case 14:if(e.prev=14,!n){e.next=17;break}throw i;case 17:return e.finish(14);case 18:return e.finish(11);case 19:return e.abrupt("return",this.writeItemsToLocalStorage(t,!0).then((function(e){var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value;u.deleted&&s.modelManager.removeItemLocally(u)}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return s.modelManager.clearDirtyItems(t),s.modelManager.didSyncModelsOffline(t),s.notifyEvent("sync:completed",{savedItems:t}),{saved_items:t}})));case 20:case"end":return e.stop()}}),e,this,[[3,7,11,19],[12,,14,18]])}))),function(e){return b.apply(this,arguments)})},{key:"markAllItemsDirtyAndSaveOffline",value:(m=v(regeneratorRuntime.mark((function e(t){var r,n,i,a,o,s,u,c,l,f,h,p,d;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t){e.next=28;break}r=this.modelManager.allNondummyItems.filter((function(e){return!e.errorDecrypting})).slice(),n=!0,i=!1,a=void 0,e.prev=5,o=r[Symbol.iterator]();case 7:if(n=(s=o.next()).done){e.next=14;break}return u=s.value,e.next=11,this.modelManager.alternateUUIDForItem(u);case 11:n=!0,e.next=7;break;case 14:e.next=20;break;case 16:e.prev=16,e.t0=e.catch(5),i=!0,a=e.t0;case 20:e.prev=20,e.prev=21,n||null==o.return||o.return();case 23:if(e.prev=23,!i){e.next=26;break}throw a;case 26:return e.finish(23);case 27:return e.finish(20);case 28:for(c=this.modelManager.allNondummyItems,l=!0,f=!1,h=void 0,e.prev=32,p=c[Symbol.iterator]();!(l=(d=p.next()).done);l=!0)d.value.setDirty(!0);e.next=40;break;case 36:e.prev=36,e.t1=e.catch(32),f=!0,h=e.t1;case 40:e.prev=40,e.prev=41,l||null==p.return||p.return();case 43:if(e.prev=43,!f){e.next=46;break}throw h;case 46:return e.finish(43);case 47:return e.finish(40);case 48:return e.abrupt("return",this.writeItemsToLocalStorage(c,!1));case 49:case"end":return e.stop()}}),e,this,[[5,16,20,28],[21,,23,27],[32,36,40,48],[41,,43,47]])}))),function(e){return m.apply(this,arguments)})},{key:"setSyncToken",value:(y=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._syncToken=t,e.next=3,this.storageManager.setItem("syncToken",t);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return y.apply(this,arguments)})},{key:"getSyncToken",value:(d=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._syncToken){e.next=4;break}return e.next=3,this.storageManager.getItem("syncToken");case 3:this._syncToken=e.sent;case 4:return e.abrupt("return",this._syncToken);case 5:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"setCursorToken",value:(p=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._cursorToken=t,!t){e.next=6;break}return e.next=4,this.storageManager.setItem("cursorToken",t);case 4:e.next=8;break;case 6:return e.next=8,this.storageManager.removeItem("cursorToken");case 8:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"getCursorToken",value:(h=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._cursorToken){e.next=4;break}return e.next=3,this.storageManager.getItem("cursorToken");case 3:this._cursorToken=e.sent;case 4:return e.abrupt("return",this._cursorToken);case 5:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"clearQueuedCallbacks",value:function(){this._queuedCallbacks=[]}},{key:"callQueuedCallbacks",value:function(e){var t=this.queuedCallbacks;if(t.length){var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)(0,a.value)(e)}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}this.clearQueuedCallbacks()}}},{key:"beginCheckingIfSyncIsTakingTooLong",value:function(){this.syncStatus.checker&&this.stopCheckingIfSyncIsTakingTooLong(),this.syncStatus.checker=this.$interval(function(){(new Date-this.syncStatus.syncStart)/1e3>5&&(this.notifyEvent("sync:taking-too-long"),this.stopCheckingIfSyncIsTakingTooLong())}.bind(this),500)}},{key:"stopCheckingIfSyncIsTakingTooLong",value:function(){this.$interval.hasOwnProperty("cancel")?this.$interval.cancel(this.syncStatus.checker):clearInterval(this.syncStatus.checker),this.syncStatus.checker=null}},{key:"lockSyncing",value:function(){this.syncLocked=!0}},{key:"unlockSyncing",value:function(){this.syncLocked=!1}},{key:"sync",value:(f=v(regeneratorRuntime.mark((function t(){var r,n=this,i=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=i.length>0&&void 0!==i[0]?i[0]:{},!this.syncLocked){t.next=4;break}return console.log("Sync Locked, Returning;"),t.abrupt("return");case 4:return t.abrupt("return",new Promise(function(){var t=v(regeneratorRuntime.mark((function t(i,a){var o,s,u,c,l,f,h,p,d,y,v,g,m,k;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r||(r={}),o=n.modelManager.getDirtyItems(),s=o.filter((function(e){return!n.lastDirtyItemsSave||e.dirtiedDate>n.lastDirtyItemsSave})),t.next=5,n.getActiveKeyInfo(e.KeyRequestLoadSaveAccount);case 5:if(u=t.sent,c=n.syncStatus.syncOpInProgress,l=n.initialDataLoaded(),!c&&l){t.next=16;break}return n.performSyncAgainOnCompletion=!0,n.lastDirtyItemsSave=new Date,t.next=13,n.writeItemsToLocalStorage(s,!1);case 13:return c&&(n.queuedCallbacks.push(i),n.loggingEnabled&&console.warn("Attempting to sync while existing sync is in progress.")),l||(n.loggingEnabled&&console.warn("(1) Attempting to perform online sync before local data has loaded"),i()),t.abrupt("return");case 16:if(n.syncStatus.syncOpInProgress=!0,!u.offline){t.next=19;break}return t.abrupt("return",n.syncOffline(o).then((function(e){n.syncStatus.syncOpInProgress=!1,i(e)})).catch((function(e){n.notifyEvent("sync-exception",e)})));case 19:if(n.initialDataLoaded()){t.next=22;break}return console.error("Attempting to perform online sync before local data has loaded"),t.abrupt("return");case 22:return n.loggingEnabled&&console.log("Syncing online user."),f=n.syncStatus.needsMoreSync,n.syncStatus.syncStart=new Date,n.beginCheckingIfSyncIsTakingTooLong(),h=n.PerSyncItemUploadLimit,(p=o.slice(0,h)).length<o.length?n.syncStatus.needsMoreSync=!0:n.syncStatus.needsMoreSync=!1,f||(n.syncStatus.total=o.length,n.syncStatus.current=0),n.syncStatus.current>n.syncStatus.total&&(n.syncStatus.total=n.syncStatus.current),n.syncStatusDidChange(),t.next=34,n.writeItemsToLocalStorage(s,!1);case 34:return n.lastDirtyItemsSave=new Date,r.onPreSyncSave&&r.onPreSyncSave(),n.allRetreivedItems||(n.allRetreivedItems=[]),n.allSavedItems||(n.allSavedItems=[]),(d={}).limit=n.ServerItemDownloadLimit,r.performIntegrityCheck&&(d.compute_integrity=!0),t.prev=41,t.next=44,Promise.all(p.map((function(e){var t=new j(e,u.keys,u.auth_params);return t.additionalFields=r.additionalFields,t.paramsForSync()}))).then((function(e){d.items=e}));case 44:t.next=49;break;case 46:t.prev=46,t.t0=t.catch(41),n.notifyEvent("sync-exception",t.t0);case 49:for(y=!0,v=!1,g=void 0,t.prev=52,m=p[Symbol.iterator]();!(y=(k=m.next()).done);y=!0)k.value.dirtyCount=0;t.next=60;break;case 56:t.prev=56,t.t1=t.catch(52),v=!0,g=t.t1;case 60:t.prev=60,t.prev=61,y||null==m.return||m.return();case 63:if(t.prev=63,!v){t.next=66;break}throw g;case 66:return t.finish(63);case 67:return t.finish(60);case 68:return t.next=70,n.getSyncToken();case 70:return d.sync_token=t.sent,t.next=73,n.getCursorToken();case 73:return d.cursor_token=t.sent,d.api=S.getApiVersion(),n.loggingEnabled&&console.log("Syncing with params",d),t.prev=76,t.t2=n.httpManager,t.next=80,n.getSyncURL();case 80:t.t3=t.sent,t.t4=d,t.t5=function(e){n.handleSyncSuccess(p,e,r).then((function(){i(e)})).catch((function(e){console.log("Caught sync success exception:",e),n.handleSyncError(e,null,o).then((function(t){n.notifyEvent("sync-exception",e),i(t)}))}))},t.t6=function(e,t){n.handleSyncError(e,t,o).then((function(e){i(e)}))},t.t2.postAuthenticatedAbsolute.call(t.t2,t.t3,t.t4,t.t5,t.t6),t.next=90;break;case 87:t.prev=87,t.t7=t.catch(76),console.log("Sync exception caught:",t.t7);case 90:case"end":return t.stop()}}),t,null,[[41,46],[52,56,60,68],[61,,63,67],[76,87]])})));return function(e,r){return t.apply(this,arguments)}}()));case 5:case"end":return t.stop()}}),t,this)}))),function(){return f.apply(this,arguments)})},{key:"_awaitSleep",value:(l=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.warn("Simulating high latency sync request",t),e.abrupt("return",new Promise((function(e,r){setTimeout((function(){e()}),t)})));case 2:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"handleSyncSuccess",value:(c=v(regeneratorRuntime.mark((function t(r,n,i){var a,o,s,u,c,l,f,h,p,d,y,v,g,m,k,b,w=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!i.simulateHighLatency){t.next=4;break}return a=i.simulatedLatency||1e3,t.next=4,this._awaitSleep(a);case 4:for(this.syncStatus.error=null,this.loggingEnabled&&console.log("Sync response",n),o=this.allSavedItems.map((function(e){return e.uuid})),s=n.saved_items.map((function(e){return e.uuid})),n.retrieved_items=n.retrieved_items.filter((function(e){var t=o.includes(e.uuid),r=s.includes(e.uuid);if(t||r)return!1;var n=w.modelManager.findItem(e.uuid);return!n||!n.dirty})),u=[],c=!0,l=!1,f=void 0,t.prev=13,h=r[Symbol.iterator]();!(c=(p=h.next()).done);c=!0)0==(d=p.value).dirtyCount&&u.push(d);t.next=21;break;case 17:t.prev=17,t.t0=t.catch(13),l=!0,f=t.t0;case 21:t.prev=21,t.prev=22,c||null==h.return||h.return();case 24:if(t.prev=24,!l){t.next=27;break}throw f;case 27:return t.finish(24);case 28:return t.finish(21);case 29:return this.modelManager.clearDirtyItems(u),t.next=32,this.handleItemsResponse(n.retrieved_items,null,I.MappingSourceRemoteRetrieved,e.KeyRequestLoadSaveAccount);case 32:return y=t.sent,this.allRetreivedItems=this.allRetreivedItems.concat(y),this.syncStatus.retrievedCount=this.allRetreivedItems.length,v=["content","auth_hash"],t.next=38,this.handleItemsResponse(n.saved_items,v,I.MappingSourceRemoteSaved,e.KeyRequestLoadSaveAccount);case 38:return g=t.sent,this.allSavedItems=this.allSavedItems.concat(g),m=n.unsaved,t.next=43,this.deprecated_handleUnsavedItemsResponse(m);case 43:return t.next=45,this.handleConflictsResponse(n.conflicts);case 45:if(k=t.sent,b=k&&k.length>0,!k){t.next=50;break}return t.next=50,this.writeItemsToLocalStorage(k,!1);case 50:return t.next=52,this.writeItemsToLocalStorage(g,!1);case 52:return t.next=54,this.writeItemsToLocalStorage(y,!1);case 54:if(!n.integrity_hash||n.cursor_token){t.next=59;break}return t.next=57,this.handleServerIntegrityHash(n.integrity_hash);case 57:t.sent||this.syncDiscordance<this.MaxDiscordanceBeforeOutOfSync&&(this.performSyncAgainOnCompletion=!0);case 59:return this.syncStatus.syncOpInProgress=!1,this.syncStatus.current+=r.length,this.syncStatusDidChange(),this.setSyncToken(n.sync_token),this.setCursorToken(n.cursor_token),this.stopCheckingIfSyncIsTakingTooLong(),t.next=67,this.getCursorToken();case 67:if(!t.sent&&!this.syncStatus.needsMoreSync){t.next=72;break}return t.abrupt("return",new Promise((function(e,t){setTimeout(function(){this.sync(i).then(e)}.bind(w),10)})));case 72:if(!b){t.next=77;break}return this.performSyncAgainOnCompletion=!1,t.abrupt("return",new Promise((function(e,t){setTimeout((function(){w.sync(i).then(e)}),10)})));case 77:return this.syncStatus.retrievedCount=0,this.syncStatus.current=0,this.syncStatus.total=0,this.syncStatusDidChange(),(this.allRetreivedItems.length>=this.majorDataChangeThreshold||g.length>=this.majorDataChangeThreshold||m&&m.length>=this.majorDataChangeThreshold||k&&k.length>=this.majorDataChangeThreshold)&&this.notifyEvent("major-data-change"),this.callQueuedCallbacks(n),this.notifyEvent("sync:completed",{retrievedItems:this.allRetreivedItems,savedItems:this.allSavedItems}),this.allRetreivedItems=[],this.allSavedItems=[],this.performSyncAgainOnCompletion&&(this.performSyncAgainOnCompletion=!1,setTimeout((function(){w.sync(i)}),10)),t.abrupt("return",n);case 88:case"end":return t.stop()}}),t,this,[[13,17,21,29],[22,,24,28]])}))),function(e,t,r){return c.apply(this,arguments)})},{key:"handleSyncError",value:(u=v(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("Sync error: ",t),401==r&&this.notifyEvent("sync-session-invalid"),t?"string"==typeof t&&(t={error:{message:t}}):t={error:{message:"Could not connect to server."}},this.syncStatus.syncOpInProgress=!1,this.syncStatus.error=t.error,this.syncStatusDidChange(),this.writeItemsToLocalStorage(n,!1),this.modelManager.didSyncModelsOffline(n),this.stopCheckingIfSyncIsTakingTooLong(),this.notifyEvent("sync:error",t.error),this.callQueuedCallbacks({error:"Sync error"}),e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return u.apply(this,arguments)})},{key:"handleItemsResponse",value:(s=v(regeneratorRuntime.mark((function e(t,r,n,i){var a,o,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getActiveKeyInfo(i);case 2:return a=e.sent.keys,e.next=5,SFJS.itemTransformer.decryptMultipleItems(t,a);case 5:return e.next=7,this.modelManager.mapResponseItemsToLocalModelsOmittingFields(t,r,n);case 7:return o=e.sent,(s=o.filter((function(e){var t=e.errorDecryptingValueChanged;return e.errorDecryptingValueChanged=!1,t}))).length>0&&this.writeItemsToLocalStorage(s,!1),e.abrupt("return",o);case 11:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return s.apply(this,arguments)})},{key:"refreshErroredItems",value:(o=v(regeneratorRuntime.mark((function t(){var r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!((r=this.modelManager.allNondummyItems.filter((function(e){return 1==e.errorDecrypting}))).length>0)){t.next=3;break}return t.abrupt("return",this.handleItemsResponse(r,null,I.MappingSourceLocalRetrieved,e.KeyRequestLoadSaveAccount));case 3:case"end":return t.stop()}}),t,this)}))),function(){return o.apply(this,arguments)})},{key:"handleConflictsResponse",value:(a=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c,l,f,h,p,d,y,v,g,m,k,b,w,x,S,_,R,A,D,M,C,O,F,j,B;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r&&0!=r.length){t.next=2;break}return t.abrupt("return");case 2:this.loggingEnabled&&console.log("Handle Conflicted Items:",r),n={},i=!0,a=!1,o=void 0,t.prev=7,s=r[Symbol.iterator]();case 9:if(i=(u=s.next()).done){t.next=21;break}if(c=u.value,l=c.server_item||c.unsaved_item,f=this.modelManager.findItem(l.uuid)){t.next=16;break}return n[l.uuid]={},t.abrupt("continue",18);case 16:h=f.getContentCopy(),n[l.uuid]={frozenContent:h,itemRef:f};case 18:i=!0,t.next=9;break;case 21:t.next=27;break;case 23:t.prev=23,t.t0=t.catch(7),a=!0,o=t.t0;case 27:t.prev=27,t.prev=28,i||null==s.return||s.return();case 30:if(t.prev=30,!a){t.next=33;break}throw o;case 33:return t.finish(30);case 34:return t.finish(27);case 35:p=[],d=!0,y=!1,v=void 0,t.prev=39,g=r[Symbol.iterator]();case 41:if(d=(m=g.next()).done){t.next=91;break}return k=m.value,b=k.server_item||k.unsaved_item,t.t1=SFJS.itemTransformer,t.t2=[b],t.next=48,this.getActiveKeyInfo(e.KeyRequestLoadSaveAccount);case 48:return t.t3=t.sent.keys,t.next=51,t.t1.decryptMultipleItems.call(t.t1,t.t2,t.t3);case 51:if(w=n[b.uuid],x=w.frozenContent,S=w.itemRef){t.next=54;break}return t.abrupt("continue",88);case 54:if(p.push(S),"uuid_conflict"!==k.type){t.next=62;break}return t.next=58,this.modelManager.alternateUUIDForItem(S);case 58:_=t.sent,p.push(_),t.next=88;break;case 62:if("sync_conflict"!==k.type){t.next=86;break}return t.next=65,this.modelManager.createDuplicateItemFromResponseItem(b);case 65:if(R=t.sent,A=this.modelManager.duplicateItemWithCustomContent({content:x,duplicateOf:S}),D=!A.isItemContentEqualWith(R),M=!S.isItemContentEqualWith(R),C=!1,O=!1,F=!1,j=!1,b.deleted||S.deleted?j=!0:D?(new Date-S.client_updated_at)/1e3<20?(F=!0,O=!0):(C=!0,j=!0):M?P.AreItemContentsEqual({leftContent:S.content,rightContent:R.content,keysToIgnore:S.keysToIgnoreWhenCheckingContentEquality().concat(["references"]),appDataKeysToIgnore:S.appDataKeysToIgnoreWhenCheckingContentEquality()})?F=!0:(C=!0,j=!0):j=!0,!C){t.next=79;break}return t.next=77,this.modelManager.duplicateItemWithCustomContentAndAddAsConflict({content:x,duplicateOf:S});case 77:B=t.sent,p.push(B);case 79:if(O&&(this.modelManager.addDuplicatedItemAsConflict({duplicate:R,duplicateOf:S}),p.push(R)),!j){t.next=83;break}return t.next=83,this.modelManager.mapResponseItemsToLocalModelsOmittingFields([b],null,I.MappingSourceRemoteRetrieved);case 83:F&&(S.updated_at=R.updated_at,S.setDirty(!0)),t.next=88;break;case 86:return console.error("Unsupported conflict type",k.type),t.abrupt("continue",88);case 88:d=!0,t.next=41;break;case 91:t.next=97;break;case 93:t.prev=93,t.t4=t.catch(39),y=!0,v=t.t4;case 97:t.prev=97,t.prev=98,d||null==g.return||g.return();case 100:if(t.prev=100,!y){t.next=103;break}throw v;case 103:return t.finish(100);case 104:return t.finish(97);case 105:return t.abrupt("return",p);case 106:case"end":return t.stop()}}),t,this,[[7,23,27,35],[28,,30,34],[39,93,97,105],[98,,100,104]])}))),function(e){return a.apply(this,arguments)})},{key:"deprecated_handleUnsavedItemsResponse",value:(i=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c,l,f,h;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r&&0!=r.length){t.next=2;break}return t.abrupt("return");case 2:this.loggingEnabled&&console.log("Handle Unsaved Items:",r),n=!0,i=!1,a=void 0,t.prev=6,o=r[Symbol.iterator]();case 8:if(n=(s=o.next()).done){t.next=35;break}return u=s.value,c=u.item,t.t0=SFJS.itemTransformer,t.t1=[c],t.next=15,this.getActiveKeyInfo(e.KeyRequestLoadSaveAccount);case 15:return t.t2=t.sent.keys,t.next=18,t.t0.decryptMultipleItems.call(t.t0,t.t1,t.t2);case 18:if(l=this.modelManager.findItem(c.uuid)){t.next=21;break}return t.abrupt("continue",32);case 21:if("uuid_conflict"!==(f=u.error).tag){t.next=27;break}return t.next=25,this.modelManager.alternateUUIDForItem(l);case 25:t.next=32;break;case 27:if("sync_conflict"!==f.tag){t.next=32;break}return t.next=30,this.modelManager.createDuplicateItemFromResponseItem(c);case 30:h=t.sent,c.deleted||l.isItemContentEqualWith(h)||this.modelManager.addDuplicatedItemAsConflict({duplicate:h,duplicateOf:l});case 32:n=!0,t.next=8;break;case 35:t.next=41;break;case 37:t.prev=37,t.t3=t.catch(6),i=!0,a=t.t3;case 41:t.prev=41,t.prev=42,n||null==o.return||o.return();case 44:if(t.prev=44,!i){t.next=47;break}throw a;case 47:return t.finish(44);case 48:return t.finish(41);case 49:case"end":return t.stop()}}),t,this,[[6,37,41,49],[42,,44,48]])}))),function(e){return i.apply(this,arguments)})},{key:"stateless_downloadAllItems",value:function(){var t=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new Promise(function(){var n=v(regeneratorRuntime.mark((function n(i,a){var o;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o={limit:r.limit||500,sync_token:r.syncToken,cursor_token:r.cursorToken,content_type:r.contentType,event:r.event,api:S.getApiVersion()},n.prev=1,n.t0=t.httpManager,n.next=5,t.getSyncURL();case 5:n.t1=n.sent,n.t2=o,n.t3=function(){var n=v(regeneratorRuntime.mark((function n(a){var o,s;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r.retrievedItems||(r.retrievedItems=[]),o=a.retrieved_items,n.next=4,t.getActiveKeyInfo(e.KeyRequestLoadSaveAccount);case 4:return s=n.sent.keys,n.next=7,SFJS.itemTransformer.decryptMultipleItems(o,s);case 7:r.retrievedItems=r.retrievedItems.concat(o.map((function(e){return t.modelManager.createItem(e)}))),r.syncToken=a.sync_token,r.cursorToken=a.cursor_token,r.cursorToken?t.stateless_downloadAllItems(r).then(i):i(r.retrievedItems);case 11:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),n.t4=function(e,t){a(e)},n.t0.postAuthenticatedAbsolute.call(n.t0,n.t1,n.t2,n.t3,n.t4),n.next=16;break;case 12:n.prev=12,n.t5=n.catch(1),console.log("Download all items exception caught:",n.t5),a(n.t5);case 16:case"end":return n.stop()}}),n,null,[[1,12]])})));return function(e,t){return n.apply(this,arguments)}}())}},{key:"resolveOutOfSync",value:(n=v(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.stateless_downloadAllItems({event:"resolve-out-of-sync"}).then(function(){var e=v(regeneratorRuntime.mark((function e(r){var n,i,a,o,s,u,c,l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=[],i=!0,a=!1,o=void 0,e.prev=4,s=r[Symbol.iterator]();case 6:if(i=(u=s.next()).done){e.next=18;break}if(c=u.value,!(l=t.modelManager.findItem(c.uuid))){e.next=14;break}if(c.isItemContentEqualWith(l)){e.next=14;break}return e.next=14,t.modelManager.duplicateItemAndAddAsConflict(l);case 14:n.push(c);case 15:i=!0,e.next=6;break;case 18:e.next=24;break;case 20:e.prev=20,e.t0=e.catch(4),a=!0,o=e.t0;case 24:e.prev=24,e.prev=25,i||null==s.return||s.return();case 27:if(e.prev=27,!a){e.next=30;break}throw o;case 30:return e.finish(27);case 31:return e.finish(24);case 32:return e.next=34,t.modelManager.mapResponseItemsToLocalModelsWithOptions({items:n,source:I.MappingSourceRemoteRetrieved});case 34:return e.next=36,t.writeItemsToLocalStorage(t.modelManager.allNondummyItems);case 36:return e.abrupt("return",t.sync({performIntegrityCheck:!0}));case 37:case"end":return e.stop()}}),e,null,[[4,20,24,32],[25,,27,31]])})));return function(t){return e.apply(this,arguments)}}()));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"handleSignout",value:(r=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.outOfSync=!1,this.loadLocalDataPromise=null,this.performSyncAgainOnCompletion=!1,this.syncStatus.syncOpInProgress=!1,this._queuedCallbacks=[],this.syncStatus={},e.abrupt("return",this.clearSyncToken());case 7:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"clearSyncToken",value:(t=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._syncToken=null,this._cursorToken=null,e.abrupt("return",this.storageManager.removeItem("syncToken"));case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"__setLocalDataNotLoaded",value:function(){this.loadLocalDataPromise=null,this._initialDataLoaded=!1}},{key:"queuedCallbacks",get:function(){return this._queuedCallbacks||(this._queuedCallbacks=[]),this._queuedCallbacks}}]),e}();n.SFSyncManager=F;var P=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};g(this,e),this.content={},this.referencingObjects=[],this.updateFromJSON(t),this.uuid||"undefined"!=typeof SFJS&&SFJS.crypto.generateUUIDSync&&(this.uuid=SFJS.crypto.generateUUIDSync()),"object"!==d(this.content)||this.content.references||(this.content.references=[])}var t;return k(e,[{key:"initUUID",value:(t=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.uuid){e.next=4;break}return e.next=3,SFJS.crypto.generateUUID();case 3:this.uuid=e.sent;case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"updateFromJSON",value:function(t){if(t){this.deleted=t.deleted,this.uuid=t.uuid,this.enc_item_key=t.enc_item_key,this.auth_hash=t.auth_hash,this.auth_params=t.auth_params;for(var r=0,n=["errorDecrypting","dirty","dirtyCount","dirtiedDate","dummy"];r<n.length;r++){var i=n[r];void 0!==t[i]&&(this[i]=t[i])}if(this.dirtiedDate&&"string"==typeof this.dirtiedDate&&(this.dirtiedDate=new Date(this.dirtiedDate)),this.content_type||(this.content_type=t.content_type),t.errorDecrypting)this.content=t.content;else try{var a="string"==typeof t.content?JSON.parse(t.content):t.content;e.deepMerge(this.contentObject,a)}catch(e){console.log("Error while updating item from json",e)}t.created_at&&(this.created_at=t.created_at),t.updated_at&&(this.updated_at=t.updated_at),this.created_at?this.created_at=new Date(this.created_at):this.created_at=new Date,this.updated_at?this.updated_at=new Date(this.updated_at):this.updated_at=new Date(0),this._client_updated_at=null,t.content?this.mapContentToLocalProperties(this.contentObject):1==t.deleted&&this.handleDeletedContent()}}},{key:"mapContentToLocalProperties",value:function(e){}},{key:"createContentJSONFromProperties",value:function(){var t=this.structureParams();return e.deepMerge(this.contentObject,t),t}},{key:"structureParams",value:function(){return this.getContentCopy()}},{key:"handleDeletedContent",value:function(){}},{key:"setDirty",value:function(e,t){this.dirty=e,this.dirtyCount||(this.dirtyCount=0),e?this.dirtyCount++:this.dirtyCount=0,this.dirtiedDate=new Date,e&&t?this.client_updated_at=new Date:this.hasRawClientUpdatedAtValue()||(this.client_updated_at=new Date(this.updated_at))}},{key:"updateLocalRelationships",value:function(){}},{key:"addItemAsRelationship",value:function(e){if(e.setIsBeingReferencedBy(this),!this.hasRelationshipWithItem(e)){var t=this.content.references||[];t.push({uuid:e.uuid,content_type:e.content_type}),this.content.references=t}}},{key:"removeItemAsRelationship",value:function(e){e.setIsNoLongerBeingReferencedBy(this),this.removeReferenceWithUuid(e.uuid)}},{key:"setIsBeingReferencedBy",value:function(e){_.find(this.referencingObjects,{uuid:e.uuid})||this.referencingObjects.push(e)}},{key:"setIsNoLongerBeingReferencedBy",value:function(e){_.remove(this.referencingObjects,{uuid:e.uuid}),this.hasRelationshipWithItem(e)&&(this.removeReferenceWithUuid(e.uuid),this.setDirty(!0))}},{key:"removeReferenceWithUuid",value:function(e){var t=this.content.references||[];t=t.filter((function(t){return t.uuid!=e})),this.content.references=t}},{key:"hasRelationshipWithItem",value:function(e){return null!=this.content.references.find((function(t){return t.uuid==e.uuid}))}},{key:"isBeingRemovedLocally",value:function(){}},{key:"didFinishSyncing",value:function(){}},{key:"informReferencesOfUUIDChange",value:function(e,t){}},{key:"potentialItemOfInterestHasChangedItsUUID",value:function(e,t,r){if(!this.errorDecrypting){var n=!0,i=!1,a=void 0;try{for(var o,s=this.content.references[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var u=o.value;u.uuid==t&&(u.uuid=r,this.setDirty(!0))}}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}}}},{key:"doNotEncrypt",value:function(){return!1}},{key:"setDomainDataItem",value:function(e,t,r){if(r){if(!this.errorDecrypting){this.content.appData||(this.content.appData={});var n=this.content.appData[r];n||(n={}),n[e]=t,this.content.appData[r]=n}}else console.error("SFItem.AppDomain needs to be set.")}},{key:"getDomainDataItem",value:function(e,t){if(t){if(!this.errorDecrypting){this.content.appData||(this.content.appData={});var r=this.content.appData[t];return r?r[e]:null}}else console.error("SFItem.AppDomain needs to be set.")}},{key:"setAppDataItem",value:function(t,r){this.setDomainDataItem(t,r,e.AppDomain)}},{key:"getAppDataItem",value:function(t){return this.getDomainDataItem(t,e.AppDomain)}},{key:"hasRawClientUpdatedAtValue",value:function(){return null!=this.getAppDataItem("client_updated_at")}},{key:"keysToIgnoreWhenCheckingContentEquality",value:function(){return[]}},{key:"appDataKeysToIgnoreWhenCheckingContentEquality",value:function(){return["client_updated_at"]}},{key:"getContentCopy",value:function(){return JSON.parse(JSON.stringify(this.content))}},{key:"isItemContentEqualWith",value:function(t){return e.AreItemContentsEqual({leftContent:this.content,rightContent:t.content,keysToIgnore:this.keysToIgnoreWhenCheckingContentEquality(),appDataKeysToIgnore:this.appDataKeysToIgnoreWhenCheckingContentEquality()})}},{key:"satisfiesPredicate",value:function(e){return B.ItemSatisfiesPredicate(this,e)}},{key:"createdAtString",value:function(){return this.dateToLocalizedString(this.created_at)}},{key:"updatedAtString",value:function(){return this.dateToLocalizedString(this.client_updated_at)}},{key:"updatedAtTimestamp",value:function(){return this.updated_at.getTime()}},{key:"dateToLocalizedString",value:function(e){if("undefined"!=typeof Intl&&Intl.DateTimeFormat){if(!O){var t=navigator.languages&&navigator.languages.length?navigator.languages[0]:navigator.language;O=new Intl.DateTimeFormat(t,{year:"numeric",month:"short",day:"2-digit",weekday:"long",hour:"2-digit",minute:"2-digit"})}return O.format(e)}return e.toDateString()+" "+e.toLocaleTimeString()}},{key:"contentObject",get:function(){if(this.errorDecrypting)return this.content;if(!this.content)return this.content={},this.content;if(null!==this.content&&"object"===d(this.content))return this.content;try{var e=JSON.parse(this.content);return this.content=e,this.content}catch(e){return console.log("Error parsing json",e,this),this.content={},this.content}}},{key:"pinned",get:function(){return this.getAppDataItem("pinned")}},{key:"archived",get:function(){return this.getAppDataItem("archived")}},{key:"locked",get:function(){return this.getAppDataItem("locked")}},{key:"displayName",get:function(){return"Item"}},{key:"client_updated_at",get:function(){if(!this._client_updated_at){var e=this.getAppDataItem("client_updated_at");this._client_updated_at=e?new Date(e):new Date(this.updated_at)}return this._client_updated_at},set:function(e){this._client_updated_at=e,this.setAppDataItem("client_updated_at",e)}}],[{key:"deepMerge",value:function(e,t){return _.mergeWith(e,t,(function(e,t){if(_.isArray(e))return t})),e}},{key:"AreItemContentsEqual",value:function(t){var r=t.leftContent,n=t.rightContent,i=t.keysToIgnore,a=t.appDataKeysToIgnore,o=function(e,t){if(!e)return e;var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)delete e[a.value]}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return e};return(r=JSON.parse(JSON.stringify(r))).appData&&o(r.appData[e.AppDomain],a),r=o(r,i),(n=JSON.parse(JSON.stringify(n))).appData&&o(n.appData[e.AppDomain],a),n=o(n,i),JSON.stringify(r)===JSON.stringify(n)}}]),e}();n.SFItem=P;var j=function(){function e(t,r,n){if(g(this,e),this.item=t,this.keys=r,this.auth_params=n,this.keys&&!this.auth_params)throw"SFItemParams.auth_params must be supplied if supplying keys.";if(this.auth_params&&!this.auth_params.version)throw"SFItemParams.auth_params is missing version"}var t,r,n,i,a;return k(e,[{key:"paramsForExportFile",value:(a=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.forExportFile=!0,!t){e.next=5;break}return e.abrupt("return",this.__params());case 5:return e.next=7,this.__params();case 7:return r=e.sent,e.abrupt("return",_.omit(r,["deleted"]));case 9:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"paramsForExtension",value:(i=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.paramsForExportFile());case 1:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"paramsForLocalStorage",value:(n=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.additionalFields=["dirty","dirtiedDate","errorDecrypting"],this.forExportFile=!0,e.abrupt("return",this.__params());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"paramsForSync",value:(r=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.__params());case 1:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"__params",value:(t=v(regeneratorRuntime.mark((function e(){var t,r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t={uuid:this.item.uuid,content_type:this.item.content_type,deleted:this.item.deleted,created_at:this.item.created_at,updated_at:this.item.updated_at},this.item.errorDecrypting){e.next=23;break}if(r=this.item.doNotEncrypt()&&!this.forExportFile,!this.keys||r){e.next=11;break}return e.next=6,SFJS.itemTransformer.encryptItem(this.item,this.keys,this.auth_params);case 6:n=e.sent,_.merge(t,n),"001"!==this.auth_params.version&&(t.auth_hash=null),e.next=21;break;case 11:if(!this.forExportFile){e.next=15;break}e.t0=this.item.createContentJSONFromProperties(),e.next=19;break;case 15:return e.next=17,SFJS.crypto.base64(JSON.stringify(this.item.createContentJSONFromProperties()));case 17:e.t1=e.sent,e.t0="000"+e.t1;case 19:t.content=e.t0,this.forExportFile||(t.enc_item_key=null,t.auth_hash=null);case 21:e.next=26;break;case 23:t.content=this.item.content,t.enc_item_key=this.item.enc_item_key,t.auth_hash=this.item.auth_hash;case 26:return this.additionalFields&&_.merge(t,_.pick(this.item,this.additionalFields)),e.abrupt("return",t);case 28:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();n.SFItemParams=j;var B=function(){function e(t,r,n){g(this,e),this.keypath=t,this.operator=r,this.value=n,e.IsRecursiveOperator(this.operator)&&(this.value=this.value.map(e.fromArray))}return k(e,null,[{key:"fromArray",value:function(t){return new e(t[0],t[1],t[2])}},{key:"ObjectSatisfiesPredicate",value:function(t,r){if(Array.isArray(r)&&(r=this.fromArray(r)),e.IsRecursiveOperator(r.operator)){if("and"===r.operator){var n=!0,i=!1,a=void 0;try{for(var o,s=r.value[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var u=o.value;if(!this.ObjectSatisfiesPredicate(t,u))return!1}}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return!0}if("or"===r.operator){var c=!0,l=!1,f=void 0;try{for(var h,p=r.value[Symbol.iterator]();!(c=(h=p.next()).done);c=!0)if(u=h.value,this.ObjectSatisfiesPredicate(t,u))return!0}catch(e){l=!0,f=e}finally{try{c||null==p.return||p.return()}finally{if(l)throw f}}return!1}}var d=r.value;"string"==typeof d&&d.includes(".ago")&&(d=this.DateFromString(d));var y=r.keypath.split(".").reduce((function(e,t){return e&&e[t]}),t),v=[!1,"",null,void 0,NaN];return null==y?"!="==r.operator?!v.includes(r.value):v.includes(r.value):"="==r.operator?Array.isArray(y)?JSON.stringify(y)==JSON.stringify(d):y==d:"!="==r.operator?Array.isArray(y)?JSON.stringify(y)!=JSON.stringify(d):y!==d:"<"==r.operator?y<d:">"==r.operator?y>d:"<="==r.operator?y<=d:">="==r.operator?y>=d:"startsWith"==r.operator?y.startsWith(d):"in"==r.operator?-1!=d.indexOf(y):"includes"==r.operator?this.resolveIncludesPredicate(y,d):"matches"==r.operator&&new RegExp(d).test(y)}},{key:"resolveIncludesPredicate",value:function(t,r){if("string"==typeof r)return t.includes(r);var n;n=Array.isArray(r)?e.fromArray(r):r;var i=!0,a=!1,o=void 0;try{for(var s,u=t[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var c=s.value;if(this.ObjectSatisfiesPredicate(c,n))return!0}}catch(e){a=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(a)throw o}}return!1}},{key:"ItemSatisfiesPredicate",value:function(t,r){return Array.isArray(r)&&(r=e.fromArray(r)),this.ObjectSatisfiesPredicate(t,r)}},{key:"ItemSatisfiesPredicates",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value;if(!this.ItemSatisfiesPredicate(e,s))return!1}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return!0}},{key:"DateFromString",value:function(e){var t=e.split("."),r=t[1],n=new Date,i=parseInt(t[0]);return"days"==r?n.setDate(n.getDate()-i):"hours"==r&&n.setHours(n.getHours()-i),n}},{key:"IsRecursiveOperator",value:function(e){return["and","or"].includes(e)}}]),e}();n.SFPredicate=B;var E=function(e){function t(e){var r;return g(this,t),(r=c(this,l(t).call(this,e))).content.desktopPrivileges||(r.content.desktopPrivileges={}),r}return f(t,e),k(t,null,[{key:"contentType",value:function(){return"SN|Privileges"}}]),k(t,[{key:"setCredentialsForAction",value:function(e,t){this.content.desktopPrivileges[e]=t}},{key:"getCredentialsForAction",value:function(e){return this.content.desktopPrivileges[e]||[]}},{key:"toggleCredentialForAction",value:function(e,t){this.isCredentialRequiredForAction(e,t)?this.removeCredentialForAction(e,t):this.addCredentialForAction(e,t)}},{key:"removeCredentialForAction",value:function(e,t){_.pull(this.content.desktopPrivileges[e],t)}},{key:"addCredentialForAction",value:function(e,t){var r=this.getCredentialsForAction(e);r.push(t),this.setCredentialsForAction(e,r)}},{key:"isCredentialRequiredForAction",value:function(e,t){return this.getCredentialsForAction(e).includes(t)}}]),t}(P);n.SFPrivileges=E;var T=function(e){function t(e){var r;return g(this,t),(r=c(this,l(t).call(this,e))).content.itemUUIDToItemHistoryMapping||(r.content.itemUUIDToItemHistoryMapping={}),Object.keys(r.content.itemUUIDToItemHistoryMapping).forEach((function(e){var t=r.content.itemUUIDToItemHistoryMapping[e];r.content.itemUUIDToItemHistoryMapping[e]=new L(t)})),r}return f(t,e),k(t,[{key:"addEntryForItem",value:function(e){return this.historyForItem(e).addHistoryEntryForItem(e)}},{key:"historyForItem",value:function(e){var t=this.content.itemUUIDToItemHistoryMapping[e.uuid];return t||(t=this.content.itemUUIDToItemHistoryMapping[e.uuid]=new L),t}},{key:"clearItemHistory",value:function(e){this.historyForItem(e).clear()}},{key:"clearAllHistory",value:function(){this.content.itemUUIDToItemHistoryMapping={}}},{key:"optimizeHistoryForItem",value:function(e){var r=this.historyForItem(e);r.entries.length>t.LargeItemEntryAmountThreshold&&r.optimize()}}]),t}(P);n.SFHistorySession=T,T.LargeItemEntryAmountThreshold=60;var L=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(g(this,e),this.entries||(this.entries=[]),t.entries){var r=!0,n=!1,i=void 0;try{for(var a,o=t.entries[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value,u=this.createEntryForItem(s.item);u.setPreviousEntry(this.getLastEntry()),this.entries.push(u)}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}}return k(e,[{key:"createEntryForItem",value:function(t){var r=e.HistoryEntryClassMapping&&e.HistoryEntryClassMapping[t.content_type];return r||(r=H),new r(t)}},{key:"getLastEntry",value:function(){return this.entries[this.entries.length-1]}},{key:"addHistoryEntryForItem",value:function(e){var t=this.createEntryForItem(e),r=this.getLastEntry();if(t.setPreviousEntry(r),!t.isSameAsEntry(r))return this.entries.push(t),t}},{key:"clear",value:function(){this.entries.length=0}},{key:"optimize",value:function(){var t=this,r=[],n=function(t){return t.deltaSize()>e.LargeEntryDeltaThreshold},i=function(e,i,a){if(a?r.push(e):-1!==(i=r.indexOf(e))&&r.splice(i,1),a&&n(e)&&-1==e.operationVector()){var o=t.entries[i-1];o&&r.push(o)}};this.entries.forEach((function(e,r){if(0==r||r==t.entries.length-1)i(e,r,!0);else{var a=n(e);i(e,r,a)}})),this.entries=this.entries.filter((function(e,t){return-1!==r.indexOf(e)}))}}]),e}();n.SFItemHistory=L,L.LargeEntryDeltaThreshold=15;var H=function(){function e(t){g(this,e),this.item=P.deepMerge({},t),this.defaultContentKeyToDiffOn="text",this.textCharDiffLength=0,"string"==typeof this.item.updated_at&&(this.item.updated_at=new Date(this.item.updated_at))}return k(e,[{key:"setPreviousEntry",value:function(e){this.hasPreviousEntry=null!=e,this.item.content[this.defaultContentKeyToDiffOn]&&(this.textCharDiffLength=e?this.item.content[this.defaultContentKeyToDiffOn].length-e.item.content[this.defaultContentKeyToDiffOn].length:this.item.content[this.defaultContentKeyToDiffOn].length)}},{key:"operationVector",value:function(){return null!=this.textCharDiffLength?this.hasPreviousEntry&&0!=this.textCharDiffLength?this.textCharDiffLength<0?-1:1:0:1}},{key:"deltaSize",value:function(){return null!=this.textCharDiffLength?Math.abs(this.textCharDiffLength):1}},{key:"isSameAsEntry",value:function(e){if(!e)return!1;var t=new P(this.item),r=new P(e.item);return t.isItemContentEqualWith(r)}}]),e}();n.SFItemHistoryEntry=H,x="undefined"!=typeof window?window:void 0!==e?e:null;var z=function(){function e(){g(this,e),this.DefaultPBKDF2Length=768}var t,r,n,i,a,o,s,c,l,f,h,p,d,y,m;return k(e,[{key:"generateUUIDSync",value:function(){var e=x.crypto||x.msCrypto;if(e){var t=new Uint32Array(4);e.getRandomValues(t);var r=-1;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){r++;var n=t[r>>3]>>r%8*4&15;return("x"==e?n:3&n|8).toString(16)}))}var n=(new Date).getTime();return x.performance&&"function"==typeof x.performance.now&&(n+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"==e?t:3&t|8).toString(16)}))}},{key:"generateUUID",value:(m=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.generateUUIDSync());case 1:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"timingSafeEqual",value:function(e,t){var r=String(e),n=String(t),i=r.length,a=0;i!==n.length&&(n=r,a=1);for(var o=0;o<i;o++)a|=r.charCodeAt(o)^n.charCodeAt(o);return 0===a}},{key:"decryptText",value:(y=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,c,l,f,h,p=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=(t=p.length>0&&void 0!==p[0]?p[0]:{}).ciphertextToAuth,n=t.contentCiphertext,i=t.encryptionKey,a=t.iv,o=t.authHash,s=t.authKey,!(p.length>1?p[1]:void 0)||o){e.next=5;break}return console.error("Auth hash is required."),e.abrupt("return");case 5:if(!o){e.next=12;break}return e.next=8,this.hmac256(r,s);case 8:if(c=e.sent,!1!==this.timingSafeEqual(o,c)){e.next=12;break}return console.error("Auth hash does not match, returning null."),e.abrupt("return",null);case 12:return l=u.enc.Hex.parse(i),f=u.enc.Hex.parse(a||""),h=u.AES.decrypt(n,l,{iv:f,mode:u.mode.CBC,padding:u.pad.Pkcs7}),e.abrupt("return",h.toString(u.enc.Utf8));case 16:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"encryptText",value:(d=v(regeneratorRuntime.mark((function e(t,r,n){var i,a,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=u.enc.Hex.parse(r),a=u.enc.Hex.parse(n||""),o=u.AES.encrypt(t,i,{iv:a,mode:u.mode.CBC,padding:u.pad.Pkcs7}),e.abrupt("return",o.toString());case 4:case"end":return e.stop()}}),e)}))),function(e,t,r){return d.apply(this,arguments)})},{key:"generateRandomKey",value:(p=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u.lib.WordArray.random(t/8).toString());case 1:case"end":return e.stop()}}),e)}))),function(e){return p.apply(this,arguments)})},{key:"generateItemEncryptionKey",value:(h=v(regeneratorRuntime.mark((function e(){var t,r,n,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=512,r=1,e.next=4,this.generateRandomKey(t);case 4:return n=e.sent,e.next=7,this.generateRandomKey(t);case 7:return i=e.sent,e.abrupt("return",this.pbkdf2(i,n,r,t));case 9:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"firstHalfOfKey",value:(f=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.substring(0,t.length/2));case 1:case"end":return e.stop()}}),e)}))),function(e){return f.apply(this,arguments)})},{key:"secondHalfOfKey",value:(l=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.substring(t.length/2,t.length));case 1:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"base64",value:(c=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",x.btoa(encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)}))));case 1:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"base64Decode",value:(s=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",x.atob(t));case 1:case"end":return e.stop()}}),e)}))),function(e){return s.apply(this,arguments)})},{key:"sha256",value:(o=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u.SHA256(t).toString());case 1:case"end":return e.stop()}}),e)}))),function(e){return o.apply(this,arguments)})},{key:"hmac256",value:(a=v(regeneratorRuntime.mark((function e(t,r){var n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=u.enc.Hex.parse(r),i=u.enc.Utf8.parse(t),a=u.HmacSHA256(i,n).toString(),e.abrupt("return",a);case 4:case"end":return e.stop()}}),e)}))),function(e,t){return a.apply(this,arguments)})},{key:"generateSalt",value:(i=v(regeneratorRuntime.mark((function e(t,r,n,i){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sha256([t,"SF",r,n,i].join(":"));case 2:return a=e.sent,e.abrupt("return",a);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return i.apply(this,arguments)})},{key:"generateSymmetricKeyPair",value:(n=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,u,c,l,f=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=(t=f.length>0&&void 0!==f[0]?f[0]:{}).password,n=t.pw_salt,i=t.pw_cost,e.next=3,this.pbkdf2(r,n,i,this.DefaultPBKDF2Length);case 3:return a=e.sent,o=a.length,s=o/3,u=a.slice(0,s),c=a.slice(s,2*s),l=a.slice(2*s,3*s),e.abrupt("return",[u,c,l]);case 10:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"computeEncryptionKeysForUser",value:(r=v(regeneratorRuntime.mark((function e(t,r){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("003"!=r.version){e.next=9;break}if(r.identifier){e.next=4;break}return console.error("authParams is missing identifier."),e.abrupt("return");case 4:return e.next=6,this.generateSalt(r.identifier,r.version,r.pw_cost,r.pw_nonce);case 6:n=e.sent,e.next=10;break;case 9:n=r.pw_salt;case 10:return e.abrupt("return",this.generateSymmetricKeyPair({password:t,pw_salt:n,pw_cost:r.pw_cost}).then((function(e){return{pw:e[0],mk:e[1],ak:e[2]}})));case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"generateInitialKeysAndAuthParamsForUser",value:(t=v(regeneratorRuntime.mark((function e(t,r){var n,i,a,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.SFJS.version,i=this.SFJS.defaultPasswordGenerationCost,e.next=4,this.generateRandomKey(256);case 4:return a=e.sent,e.next=7,this.generateSalt(t,n,i,a);case 7:return o=e.sent,e.abrupt("return",this.generateSymmetricKeyPair({password:r,pw_salt:o,pw_cost:i}).then((function(e){var r={pw_nonce:a,pw_cost:i,identifier:t,version:n};return{keys:{pw:e[0],mk:e[1],ak:e[2]},authParams:r}})));case 9:case"end":return e.stop()}}),e,this)}))),function(e,r){return t.apply(this,arguments)})}]),e}();n.SFAbstractCrypto=z;var U=function(e){function t(){return g(this,t),c(this,l(t).apply(this,arguments))}var r;return f(t,e),k(t,[{key:"pbkdf2",value:(r=v(regeneratorRuntime.mark((function e(t,r,n,i){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a={keySize:i/32,hasher:u.algo.SHA512,iterations:n},e.abrupt("return",u.PBKDF2(t,r,a).toString());case 2:case"end":return e.stop()}}),e)}))),function(e,t,n,i){return r.apply(this,arguments)})}]),t}(z);n.SFCryptoJS=U;var N=(x="undefined"!=typeof window?window:void 0!==e?e:null).crypto?x.crypto.subtle:null,K=function(e){function t(){return g(this,t),c(this,l(t).apply(this,arguments))}var r,n,i,a,o,s,u,h,p,d,y,m,b,w;return f(t,e),k(t,[{key:"pbkdf2",value:(w=v(regeneratorRuntime.mark((function e(t,r,n,i){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.webCryptoImportKey(t,"PBKDF2",["deriveBits"]);case 2:if(a=e.sent){e.next=6;break}return console.log("Key is null, unable to continue"),e.abrupt("return",null);case 6:return e.abrupt("return",this.webCryptoDeriveBits(a,r,n,i));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return w.apply(this,arguments)})},{key:"generateRandomKey",value:(b=v(regeneratorRuntime.mark((function e(t){var r=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",N.generateKey({name:"AES-CBC",length:t},!0,["encrypt","decrypt"]).then((function(e){return N.exportKey("raw",e).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.arrayBufferToHexString(new Uint8Array(t));case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){console.error("Error exporting key",e)}))})).catch((function(e){console.error("Error generating key",e)})));case 2:case"end":return e.stop()}}),e)}))),function(e){return b.apply(this,arguments)})},{key:"generateItemEncryptionKey",value:(m=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Promise.all([this.generateRandomKey(256),this.generateRandomKey(256)]).then((function(e){return e.join("")})));case 2:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"encryptText",value:(y=v(regeneratorRuntime.mark((function e(t,r,n){var i,a,o,s,u,c=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n){e.next=6;break}return e.next=3,this.hexStringToArrayBuffer(n);case 3:e.t0=e.sent,e.next=7;break;case 6:e.t0=new ArrayBuffer(16);case 7:return i=e.t0,a={name:"AES-CBC",iv:i},e.next=11,this.hexStringToArrayBuffer(r);case 11:return o=e.sent,e.next=14,this.webCryptoImportKey(o,a.name,["encrypt"]);case 14:return s=e.sent,e.next=17,this.stringToArrayBuffer(t);case 17:return u=e.sent,e.abrupt("return",crypto.subtle.encrypt(a,s,u).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c.arrayBufferToBase64(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 19:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return y.apply(this,arguments)})},{key:"decryptText",value:(d=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,u,c,l,f,h,p,d=this,y=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=(t=y.length>0&&void 0!==y[0]?y[0]:{}).ciphertextToAuth,n=t.contentCiphertext,i=t.encryptionKey,a=t.iv,o=t.authHash,s=t.authKey,!(y.length>1?y[1]:void 0)||o){e.next=5;break}return console.error("Auth hash is required."),e.abrupt("return");case 5:if(!o){e.next=12;break}return e.next=8,this.hmac256(r,s);case 8:if(u=e.sent,!1!==this.timingSafeEqual(o,u)){e.next=12;break}return console.error("Auth hash does not match, returning null. ".concat(o," != ").concat(u)),e.abrupt("return",null);case 12:if(!a){e.next=18;break}return e.next=15,this.hexStringToArrayBuffer(a);case 15:e.t0=e.sent,e.next=19;break;case 18:e.t0=new ArrayBuffer(16);case 19:return c=e.t0,l={name:"AES-CBC",iv:c},e.next=23,this.hexStringToArrayBuffer(i);case 23:return f=e.sent,e.next=26,this.webCryptoImportKey(f,l.name,["decrypt"]);case 26:return h=e.sent,e.next=29,this.base64ToArrayBuffer(n);case 29:return p=e.sent,e.abrupt("return",crypto.subtle.decrypt(l,h,p).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,d.arrayBufferToString(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){console.error("Error decrypting:",e)})));case 31:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"hmac256",value:(p=v(regeneratorRuntime.mark((function e(t,r){var n,i,a,o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.hexStringToArrayBuffer(r);case 2:return n=e.sent,e.next=5,this.webCryptoImportKey(n,"HMAC",["sign"],{name:"SHA-256"});case 5:return i=e.sent,e.next=8,this.stringToArrayBuffer(t);case 8:return a=e.sent,e.abrupt("return",crypto.subtle.sign({name:"HMAC"},i,a).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.arrayBufferToHexString(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){console.error("Error computing hmac",e)})));case 10:case"end":return e.stop()}}),e,this)}))),function(e,t){return p.apply(this,arguments)})},{key:"webCryptoImportKey",value:(h=v(regeneratorRuntime.mark((function e(t,r,n,i){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t){e.next=6;break}return e.next=3,this.stringToArrayBuffer(t);case 3:e.t0=e.sent,e.next=7;break;case 6:e.t0=t;case 7:return a=e.t0,e.abrupt("return",N.importKey("raw",a,{name:r,hash:i},!1,n).then((function(e){return e})).catch((function(e){return console.error(e),null})));case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return h.apply(this,arguments)})},{key:"webCryptoDeriveBits",value:(u=v(regeneratorRuntime.mark((function e(t,r,n,i){var a,o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.stringToArrayBuffer(r);case 2:return e.t0=e.sent,e.t1=n,e.t2={name:"SHA-512"},a={name:"PBKDF2",salt:e.t0,iterations:e.t1,hash:e.t2},e.abrupt("return",N.deriveBits(a,t,i).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.arrayBufferToHexString(new Uint8Array(t));case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return console.error(e),null})));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return u.apply(this,arguments)})},{key:"stringToArrayBuffer",value:(s=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){var n=new Blob([t]),i=new FileReader;i.onload=function(t){e(t.target.result)},i.readAsArrayBuffer(n)})));case 1:case"end":return e.stop()}}),e)}))),function(e){return s.apply(this,arguments)})},{key:"arrayBufferToString",value:(o=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){var n=new Blob([t]),i=new FileReader;i.onload=function(t){e(t.target.result)},i.readAsText(n)})));case 1:case"end":return e.stop()}}),e)}))),function(e){return o.apply(this,arguments)})},{key:"arrayBufferToHexString",value:(a=v(regeneratorRuntime.mark((function e(t){var r,n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=new Uint8Array(t),n="",a=0;a<r.byteLength;a++)(i=r[a].toString(16)).length<2&&(i="0"+i),n+=i;return e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)}))),function(e){return a.apply(this,arguments)})},{key:"hexStringToArrayBuffer",value:(i=v(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=[],n=0;n<t.length;n+=2)r.push(parseInt(t.substr(n,2),16));return e.abrupt("return",new Uint8Array(r));case 2:case"end":return e.stop()}}),e)}))),function(e){return i.apply(this,arguments)})},{key:"base64ToArrayBuffer",value:(n=v(regeneratorRuntime.mark((function e(t){var r,n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.base64Decode(t);case 2:for(r=e.sent,n=r.length,i=new Uint8Array(n),a=0;a<n;a++)i[a]=r.charCodeAt(a);return e.abrupt("return",i.buffer);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"arrayBufferToBase64",value:(r=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){var n=new Blob([t],{type:"application/octet-binary"}),i=new FileReader;i.onload=function(t){var r=t.target.result;e(r.substr(r.indexOf(",")+1))},i.readAsDataURL(n)})));case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})}]),t}(z);n.SFCryptoWeb=K;var W=function(){function e(t){g(this,e),this.crypto=t}var t,r,n,i;return k(e,[{key:"_private_encryptString",value:(i=v(regeneratorRuntime.mark((function e(t,r,n,i,a){var o,s,u,c,l,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("001"!==a.version){e.next=7;break}return e.next=3,this.crypto.encryptText(t,r,null);case 3:s=e.sent,o=a.version+s,e.next=21;break;case 7:return e.next=9,this.crypto.generateRandomKey(128);case 9:return u=e.sent,e.next=12,this.crypto.encryptText(t,r,u);case 12:return s=e.sent,c=[a.version,i,u,s].join(":"),e.next=16,this.crypto.hmac256(c,n);case 16:return l=e.sent,e.next=19,this.crypto.base64(JSON.stringify(a));case 19:f=e.sent,o=[a.version,l,i,u,s,f].join(":");case 21:return e.abrupt("return",o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return i.apply(this,arguments)})},{key:"encryptItem",value:(n=v(regeneratorRuntime.mark((function e(t,r,n){var i,a,o,s,u,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={},e.next=3,this.crypto.generateItemEncryptionKey();case 3:if(a=e.sent,"001"!==n.version){e.next=10;break}return e.next=7,this.crypto.encryptText(a,r.mk,null);case 7:i.enc_item_key=e.sent,e.next=13;break;case 10:return e.next=12,this._private_encryptString(a,r.mk,r.ak,t.uuid,n);case 12:i.enc_item_key=e.sent;case 13:return e.next=15,this.crypto.firstHalfOfKey(a);case 15:return o=e.sent,e.next=18,this.crypto.secondHalfOfKey(a);case 18:return s=e.sent,e.next=21,this._private_encryptString(JSON.stringify(t.createContentJSONFromProperties()),o,s,t.uuid,n);case 21:if(u=e.sent,"001"!==n.version){e.next=27;break}return e.next=25,this.crypto.hmac256(u,s);case 25:c=e.sent,i.auth_hash=c;case 27:return i.content=u,e.abrupt("return",i);case 29:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"encryptionComponentsFromString",value:function(e,t,r){var n=e.substring(0,3);if("001"===n)return{contentCiphertext:e.substring(3,e.length),encryptionVersion:n,ciphertextToAuth:e,iv:null,authHash:null,encryptionKey:t,authKey:r};var i=e.split(":");return{encryptionVersion:i[0],authHash:i[1],uuid:i[2],iv:i[3],contentCiphertext:i[4],authParams:i[5],ciphertextToAuth:[i[0],i[2],i[3],i[4]].join(":"),encryptionKey:t,authKey:r}}},{key:"decryptItem",value:(r=v(regeneratorRuntime.mark((function e(t,r){var n,i,a,o,s,u,c,l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"==typeof t.content){e.next=2;break}return e.abrupt("return");case 2:if(!t.content.startsWith("000")){e.next=14;break}return e.prev=3,e.t0=JSON,e.next=7,this.crypto.base64Decode(t.content.substring(3,t.content.length));case 7:e.t1=e.sent,t.content=e.t0.parse.call(e.t0,e.t1),e.next=13;break;case 11:e.prev=11,e.t2=e.catch(3);case 13:return e.abrupt("return");case 14:if(t.enc_item_key){e.next=17;break}return console.log("Missing item encryption key, skipping decryption."),e.abrupt("return");case 17:if(n=t.enc_item_key,i=!0,n.startsWith("002")||n.startsWith("003")||(n="001"+n,i=!1),!(a=this.encryptionComponentsFromString(n,r.mk,r.ak)).uuid||a.uuid===t.uuid){e.next=26;break}return console.error("Item key params UUID does not match item UUID"),t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0,e.abrupt("return");case 26:return e.next=28,this.crypto.decryptText(a,i);case 28:if(o=e.sent){e.next=34;break}return console.log("Error decrypting item",t),t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0,e.abrupt("return");case 34:return e.next=36,this.crypto.firstHalfOfKey(o);case 36:return s=e.sent,e.next=39,this.crypto.secondHalfOfKey(o);case 39:return u=e.sent,c=this.encryptionComponentsFromString(t.content,s,u),e.prev=41,e.t3=JSON,e.next=45,this.crypto.base64Decode(c.authParams);case 45:e.t4=e.sent,t.auth_params=e.t3.parse.call(e.t3,e.t4),e.next=51;break;case 49:e.prev=49,e.t5=e.catch(41);case 51:if(!c.uuid||c.uuid===t.uuid){e.next=55;break}return t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0,e.abrupt("return");case 55:return c.authHash||(c.authHash=t.auth_hash),e.next=58,this.crypto.decryptText(c,!0);case 58:(l=e.sent)?(1==t.errorDecrypting&&(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!1,t.content=l):(t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0);case 60:case"end":return e.stop()}}),e,this,[[3,11],[41,49]])}))),function(e,t){return r.apply(this,arguments)})},{key:"decryptMultipleItems",value:(t=v(regeneratorRuntime.mark((function e(t,r,n){var i,a=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return");case 2:if(1!=t.deleted||null!=t.content){e.next=4;break}return e.abrupt("return");case 4:if(!("string"==typeof t.content||t.content instanceof String)){e.next=19;break}return e.prev=6,e.next=9,a.decryptItem(t,r);case 9:e.next=19;break;case 11:if(e.prev=11,e.t0=e.catch(6),t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0,!n){e.next=17;break}throw e.t0;case 17:return console.error("Error decrypting item",t,e.t0),e.abrupt("return");case 19:case"end":return e.stop()}}),e,null,[[6,11]])})));return function(t){return e.apply(this,arguments)}}(),e.abrupt("return",Promise.all(t.map((function(e){return i(e)}))));case 2:case"end":return e.stop()}}),e)}))),function(e,r,n){return t.apply(this,arguments)})}]),e}();n.SFItemTransformer=W,x="undefined"!=typeof window?window:void 0!==e?e:null;var J=function(){function e(t){g(this,e),x&&("undefined"!=typeof document&&document.documentMode||/Edge/.test(navigator.userAgent)||!x.crypto||!x.crypto.subtle?this.crypto=new U:this.crypto=new K),t&&(this.crypto=t),this.itemTransformer=new W(this.crypto),this.crypto.SFJS={version:this.version(),defaultPasswordGenerationCost:this.defaultPasswordGenerationCost()}}return k(e,[{key:"version",value:function(){return"003"}},{key:"supportsPasswordDerivationCost",value:function(e){return!(e>5e3)||this.crypto instanceof K}},{key:"supportedVersions",value:function(){return["001","002","003"]}},{key:"isVersionNewerThanLibraryVersion",value:function(e){var t=this.version();return parseInt(e)>parseInt(t)}},{key:"isProtocolVersionOutdated",value:function(e){var t={"001":Date.parse("2018-01-01"),"002":Date.parse("2020-01-01")}[e];return!!t&&new Date>t}},{key:"costMinimumForVersion",value:function(e){return{"001":3e3,"002":3e3,"003":11e4}[e]}},{key:"defaultPasswordGenerationCost",value:function(){return this.costMinimumForVersion(this.version())}}]),e}();if(n.StandardFile=J,x)try{x.StandardFile=J,x.SFJS=new J,x.SFCryptoWeb=K,x.SFCryptoJS=U,x.SFItemTransformer=W,x.SFModelManager=I,x.SFItem=P,x.SFItemParams=j,x.SFHttpManager=S,x.SFStorageManager=C,x.SFSyncManager=F,x.SFAuthManager=w,x.SFMigrationManager=R,x.SFAlertManager=b,x.SFPredicate=B,x.SFHistorySession=T,x.SFSessionHistoryManager=D,x.SFItemHistory=L,x.SFItemHistoryEntry=H,x.SFPrivilegesManager=A,x.SFPrivileges=E,x.SFSingletonManager=M}catch(e){console.log("Exception while exporting window variables",e)}}).call(this,void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1])(1)}).call(this,r(2))},function(e,t){!function(t){"use strict";var r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",o=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag",u="object"==typeof e,c=t.regeneratorRuntime;if(c)u&&(e.exports=c);else{(c=t.regeneratorRuntime=u?e.exports:{}).wrap=y;var l={},f={};f[a]=function(){return this};var h=Object.getPrototypeOf,p=h&&h(h(I([])));p&&p!==r&&n.call(p,a)&&(f=p);var d=k.prototype=g.prototype=Object.create(f);m.prototype=d.constructor=k,k.constructor=m,k[s]=m.displayName="GeneratorFunction",c.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},c.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,k):(e.__proto__=k,s in e||(e[s]="GeneratorFunction")),e.prototype=Object.create(d),e},c.awrap=function(e){return{__await:e}},b(w.prototype),w.prototype[o]=function(){return this},c.AsyncIterator=w,c.async=function(e,t,r,n){var i=new w(y(e,t,r,n));return c.isGeneratorFunction(t)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},b(d),d[s]="Generator",d[a]=function(){return this},d.toString=function(){return"[object Generator]"},c.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},c.values=I,R.prototype={constructor:R,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return o.type="throw",o.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),_(r),l}},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;_(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:I(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}}}function y(e,t,r,n){var i=t&&t.prototype instanceof g?t:g,a=Object.create(i.prototype),o=new R(n||[]);return a._invoke=function(e,t,r){var n="suspendedStart";return function(i,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw a;return{value:void 0,done:!0}}for(r.method=i,r.arg=a;;){var o=r.delegate;if(o){var s=x(o,r);if(s){if(s===l)continue;return s}}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 u=v(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,o),a}function v(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}function g(){}function m(){}function k(){}function b(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function w(e){var t;this._invoke=function(r,i){function a(){return new Promise((function(t,a){!function t(r,i,a,o){var s=v(e[r],e,i);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"==typeof c&&n.call(c,"__await")?Promise.resolve(c.__await).then((function(e){t("next",e,a,o)}),(function(e){t("throw",e,a,o)})):Promise.resolve(c).then((function(e){u.value=e,a(u)}),o)}o(s.arg)}(r,i,t,a)}))}return t=t?t.then(a,a):a()}}function x(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=v(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function S(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 _(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function I(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:A}}function A(){return{value:void 0,done:!0}}}(function(){return this}()||Function("return this")())},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){(function(e,n){var i;(function(){function a(e,t){return e.set(t[0],t[1]),e}function o(e,t){return e.add(t),e}function s(e,t){for(var r=-1,n=null==e?0:e.length,i=0,a=[];++r<n;){var o=e[r];t(o,r,e)&&(a[i++]=o)}return a}function u(e,t){return!(null==e||!e.length)&&-1<d(e,t,0)}function c(e,t){for(var r=-1,n=null==e?0:e.length,i=Array(n);++r<n;)i[r]=t(e[r],r,e);return i}function l(e,t){for(var r=-1,n=t.length,i=e.length;++r<n;)e[i+r]=t[r];return e}function f(e,t,r){for(var n=-1,i=null==e?0:e.length;++n<i;)r=t(r,e[n],n,e);return r}function h(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1}function p(e,t,r){var n=e.length;for(r+=-1;++r<n;)if(t(e[r],r,e))return r;return-1}function d(e,t,r){if(t==t)e:{--r;for(var n=e.length;++r<n;)if(e[r]===t){e=r;break e}e=-1}else e=p(e,y,r);return e}function y(e){return e!=e}function v(e,t){return e.has(t)}function g(e){var t=-1,r=Array(e.size);return e.forEach((function(e,n){r[++t]=[n,e]})),r}function m(e){var t=Object;return function(r){return e(t(r))}}function k(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r}function b(){}function w(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function x(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function S(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function _(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new S;++t<r;)this.add(e[t])}function R(e){this.size=(this.__data__=new x(e)).size}function I(e,t){var r,n=br(e),i=!n&&kr(e),a=!n&&!i&&wr(e),o=!n&&!i&&!a&&xr(e);if(n=n||i||a||o){i=e.length;for(var s=String,u=-1,c=Array(i);++u<i;)c[u]=s(u);i=c}else i=[];for(r in s=i.length,e)!t&&!_t.call(e,r)||n&&("length"==r||a&&("offset"==r||"parent"==r)||o&&("buffer"==r||"byteLength"==r||"byteOffset"==r)||ue(r,s))||i.push(r);return i}function A(e,t,r){(r===Ve||be(e[t],r))&&(r!==Ve||t in e)||C(e,t,r)}function D(e,t,r){var n=e[t];_t.call(e,t)&&be(n,r)&&(r!==Ve||t in e)||C(e,t,r)}function M(e,t){for(var r=e.length;r--;)if(be(e[r][0],t))return r;return-1}function C(e,t,r){"__proto__"==t&&Ht?Ht(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}function O(e,t,r,n,i,a){var o,s=1&t,u=2&t,c=4&t;if(r&&(o=i?r(e,n,i,a):r(e)),o!==Ve)return o;if(!Re(e))return e;if(n=br(e)){if(o=function(e){var t=e.length,r=e.constructor(t);return t&&"string"==typeof e[0]&&_t.call(e,"index")&&(r.index=e.index,r.input=e.input),r}(e),!s)return $(e,o)}else{var l=dr(e),f="[object Function]"==l||"[object GeneratorFunction]"==l;if(wr(e))return J(e,s);if("[object Object]"==l||"[object Arguments]"==l||f&&!i){if(o=u||f?{}:ae(e),!s)return u?function(e,t){return G(e,pr(e),t)}(e,function(e,t){return e&&G(t,Le(t),e)}(o,e)):function(e,t){return G(e,hr(e),t)}(e,function(e,t){return e&&G(t,Te(t),e)}(o,e))}else{if(!ct[l])return i?e:{};o=oe(e,l,O,s)}}if(a||(a=new R),i=a.get(e))return i;a.set(e,o),u=c?u?te:ee:u?Le:Te;var h=n?Ve:u(e);return function(e,t){for(var r=-1,n=null==e?0:e.length;++r<n&&!1!==t(e[r],r););}(h||e,(function(n,i){h&&(n=e[i=n]),D(o,i,O(n,t,r,i,e,a))})),o}function F(e,t){var r=[];return ur(e,(function(e,n,i){t(e,n,i)&&r.push(e)})),r}function P(e,t){for(var r=0,n=(t=W(t,e)).length;null!=e&&r<n;)e=e[pe(t[r++])];return r&&r==n?e:Ve}function j(e,t,r){return t=t(e),br(e)?t:l(t,r(e))}function B(e){if(null==e)e=e===Ve?"[object Undefined]":"[object Null]";else if(Lt&&Lt in Object(e)){var t=_t.call(e,Lt),r=e[Lt];try{e[Lt]=Ve;var n=!0}catch(e){}var i=It.call(e);n&&(t?e[Lt]=r:delete e[Lt]),e=i}else e=It.call(e);return e}function E(e){return Ie(e)&&"[object Arguments]"==B(e)}function T(e,t,r,n,i){if(e===t)t=!0;else if(null==e||null==t||!Ie(e)&&!Ie(t))t=e!=e&&t!=t;else e:{var a,o,s=br(e),u=br(t),c="[object Object]"==(a="[object Arguments]"==(a=s?"[object Array]":dr(e))?"[object Object]":a);if(u="[object Object]"==(o="[object Arguments]"==(o=u?"[object Array]":dr(t))?"[object Object]":o),(o=a==o)&&wr(e)){if(!wr(t)){t=!1;break e}s=!0,c=!1}if(o&&!c)i||(i=new R),t=s||xr(e)?Q(e,t,r,n,T,i):function(e,t,r,n,i,a,o){switch(r){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)break;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":if(e.byteLength!=t.byteLength||!a(new Ot(e),new Ot(t)))break;return!0;case"[object Boolean]":case"[object Date]":case"[object Number]":return be(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var s=g;case"[object Set]":if(s||(s=k),e.size!=t.size&&!(1&n))break;return(r=o.get(e))?r==t:(n|=2,o.set(e,t),t=Q(s(e),s(t),n,i,a,o),o.delete(e),t);case"[object Symbol]":if(ar)return ar.call(e)==ar.call(t)}return!1}(e,t,a,r,n,T,i);else{if(!(1&r)&&(s=c&&_t.call(e,"__wrapped__"),a=u&&_t.call(t,"__wrapped__"),s||a)){e=s?e.value():e,t=a?t.value():t,i||(i=new R),t=T(e,t,r,n,i);break e}if(o)t:if(i||(i=new R),s=1&r,a=ee(e),u=a.length,o=ee(t).length,u==o||s){for(c=u;c--;){var l=a[c];if(!(s?l in t:_t.call(t,l))){t=!1;break t}}if((o=i.get(e))&&i.get(t))t=o==t;else{o=!0,i.set(e,t),i.set(t,e);for(var f=s;++c<u;){var h=e[l=a[c]],p=t[l];if(n)var d=s?n(p,h,l,t,e,i):n(h,p,l,e,t,i);if(d===Ve?h!==p&&!T(h,p,r,n,i):!d){o=!1;break}f||(f="constructor"==l)}o&&!f&&(r=e.constructor)!=(n=t.constructor)&&"constructor"in e&&"constructor"in t&&!("function"==typeof r&&r instanceof r&&"function"==typeof n&&n instanceof n)&&(o=!1),i.delete(e),i.delete(t),t=o}}else t=!1;else t=!1}}return t}function L(e){return"function"==typeof e?e:null==e?Ue:"object"==typeof e?br(e)?function(e,t){return ce(e)&&t==t&&!Re(t)?fe(pe(e),t):function(r){var n=Be(r,e);return n===Ve&&n===t?Ee(r,e):T(t,n,3)}}(e[0],e[1]):function(e){var t=function(e){for(var t=Te(e),r=t.length;r--;){var n=t[r],i=e[n];t[r]=[n,i,i==i&&!Re(i)]}return t}(e);return 1==t.length&&t[0][2]?fe(t[0][0],t[0][1]):function(r){return r===e||function(e,t){var r=t.length,n=r;if(null==e)return!n;for(e=Object(e);r--;)if((i=t[r])[2]?i[1]!==e[i[0]]:!(i[0]in e))return!1;for(;++r<n;){var i,a=(i=t[r])[0],o=e[a],s=i[1];if(i[2]){if(o===Ve&&!(a in e))return!1}else if(!T(s,o,3,void 0,i=new R))return!1}return!0}(r,t)}}(e):We(e)}function H(e,t){var r=-1,n=we(e)?Array(e.length):[];return ur(e,(function(e,i,a){n[++r]=t(e,i,a)})),n}function z(e,t,r,n,i){e!==t&&cr(t,(function(a,o){if(Re(a)){i||(i=new R);var s=i,u=e[o],c=t[o];if(d=s.get(c))A(e,o,d);else{var l=(d=n?n(u,c,o+"",e,t,s):Ve)===Ve;if(l){var f=br(c),h=!f&&wr(c),p=!f&&!h&&xr(c),d=c;f||h||p?br(u)?d=u:xe(u)?d=$(u):h?(l=!1,d=J(c,!0)):p?(l=!1,d=V(c,!0)):d=[]:Ae(c)||kr(c)?(d=u,kr(u)?d=Pe(u):(!Re(u)||r&&Se(u))&&(d=ae(c))):l=!1}l&&(s.set(c,d),z(d,c,r,n,s),s.delete(c)),A(e,o,d)}}else(s=n?n(e[o],a,o+"",e,t,i):Ve)===Ve&&(s=a),A(e,o,s)}),Le)}function U(e){return yr(he(e,void 0,Ue),e+"")}function N(e){if("string"==typeof e)return e;if(br(e))return c(e,N)+"";if(Me(e))return or?or.call(e):"";var t=e+"";return"0"==t&&1/e==-$e?"-0":t}function K(e,t){var r;if(2>(t=W(t,e)).length)r=e;else{var n=0,i=-1,a=-1,o=(r=t).length;for(0>n&&(n=-n>o?0:o+n),0>(i=i>o?o:i)&&(i+=o),o=n>i?0:i-n>>>0,n>>>=0,i=Array(o);++a<o;)i[a]=r[a+n];r=P(e,i)}null==(e=r)||delete e[pe(ge(t))]}function W(e,t){return br(e)?e:ce(e,t)?[e]:vr(je(e))}function J(e,t){if(t)return e.slice();var r=e.length;return r=Ft?Ft(r):new e.constructor(r),e.copy(r),r}function q(e){var t=new e.constructor(e.byteLength);return new Ot(t).set(new Ot(e)),t}function V(e,t){return new e.constructor(t?q(e.buffer):e.buffer,e.byteOffset,e.length)}function $(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t}function G(e,t,r){var n=!r;r||(r={});for(var i=-1,a=t.length;++i<a;){var o=t[i],s=Ve;s===Ve&&(s=e[o]),n?C(r,o,s):D(r,o,s)}return r}function X(e){return U((function(t,r){var n,i=-1,a=r.length,o=1<a?r[a-1]:Ve,s=2<a?r[2]:Ve;if(o=3<e.length&&"function"==typeof o?(a--,o):Ve,n=s){n=r[0];var u=r[1];if(Re(s)){var c=typeof u;n=!!("number"==c?we(s)&&ue(u,s.length):"string"==c&&u in s)&&be(s[u],n)}else n=!1}for(n&&(o=3>a?Ve:o,a=1),t=Object(t);++i<a;)(s=r[i])&&e(t,s,i,o);return t}))}function Y(e){return Ae(e)?Ve:e}function Q(e,t,r,n,i,a){var o=1&r,s=e.length;if(s!=(u=t.length)&&!(o&&u>s))return!1;if((u=a.get(e))&&a.get(t))return u==t;var u=-1,c=!0,l=2&r?new _:Ve;for(a.set(e,t),a.set(t,e);++u<s;){var f=e[u],p=t[u];if(n)var d=o?n(p,f,u,t,e,a):n(f,p,u,e,t,a);if(d!==Ve){if(d)continue;c=!1;break}if(l){if(!h(t,(function(e,t){if(!v(l,t)&&(f===e||i(f,e,r,n,a)))return l.push(t)}))){c=!1;break}}else if(f!==p&&!i(f,p,r,n,a)){c=!1;break}}return a.delete(e),a.delete(t),c}function Z(e){return yr(he(e,Ve,ve),e+"")}function ee(e){return j(e,Te,hr)}function te(e){return j(e,Le,pr)}function re(){var e=(e=b.iteratee||Ne)===Ne?L:e;return arguments.length?e(arguments[0],arguments[1]):e}function ne(e,t){var r=e.__data__,n=typeof t;return("string"==n||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==t:null===t)?r["string"==typeof t?"string":"hash"]:r.map}function ie(e,t){var r=null==e?Ve:e[t];return!Re(r)||Rt&&Rt in r||!(Se(r)?Dt:at).test(de(r))?Ve:r}function ae(e){return"function"!=typeof e.constructor||le(e)?{}:sr(Pt(e))}function oe(e,t,r,n){var i=e.constructor;switch(t){case"[object ArrayBuffer]":return q(e);case"[object Boolean]":case"[object Date]":return new i(+e);case"[object DataView]":return t=n?q(e.buffer):e.buffer,new e.constructor(t,e.byteOffset,e.byteLength);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return V(e,n);case"[object Map]":return f(t=n?r(g(e),1):g(e),a,new e.constructor);case"[object Number]":case"[object String]":return new i(e);case"[object RegExp]":return(t=new e.constructor(e.source,rt.exec(e))).lastIndex=e.lastIndex,t;case"[object Set]":return f(t=n?r(k(e),1):k(e),o,new e.constructor);case"[object Symbol]":return ar?Object(ar.call(e)):{}}}function se(e){return br(e)||kr(e)||!!(Tt&&e&&e[Tt])}function ue(e,t){return!!(t=null==t?9007199254740991:t)&&("number"==typeof e||st.test(e))&&-1<e&&0==e%1&&e<t}function ce(e,t){if(br(e))return!1;var r=typeof e;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!Me(e))||Ye.test(e)||!Xe.test(e)||null!=t&&e in Object(t)}function le(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||wt)}function fe(e,t){return function(r){return null!=r&&r[e]===t&&(t!==Ve||e in Object(r))}}function he(e,t,r){return t=Wt(t===Ve?e.length-1:t,0),function(){for(var n=arguments,i=-1,a=Wt(n.length-t,0),o=Array(a);++i<a;)o[i]=n[t+i];for(i=-1,a=Array(t+1);++i<t;)a[i]=n[i];return a[t]=r(o),function(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}(e,this,a)}}function pe(e){if("string"==typeof e||Me(e))return e;var t=e+"";return"0"==t&&1/e==-$e?"-0":t}function de(e){if(null!=e){try{return St.call(e)}catch(e){}return e+""}return""}function ye(e,t,r){var n=null==e?0:e.length;return n?(0>(r=null==r?0:Oe(r))&&(r=Wt(n+r,0)),p(e,re(t,3),r)):-1}function ve(e){return null!=e&&e.length?function e(t,r,n,i,a){var o=-1,s=t.length;for(n||(n=se),a||(a=[]);++o<s;){var u=t[o];0<r&&n(u)?1<r?e(u,r-1,n,i,a):l(a,u):i||(a[a.length]=u)}return a}(e,1):[]}function ge(e){var t=null==e?0:e.length;return t?e[t-1]:Ve}function me(e,t){var r;if(e&&e.length&&t&&t.length){var n=d,i=-1,a=(r=t).length;for(e===r&&(r=$(r));++i<a;)for(var o=0,s=r[i];-1<(o=n(e,s,o,void 0));)e!=e&&Et.call(e,o,1),Et.call(e,o,1);r=e}else r=e;return r}function ke(e,t){function r(){var n=arguments,i=t?t.apply(this,n):n[0],a=r.cache;return a.has(i)?a.get(i):(n=e.apply(this,n),r.cache=a.set(i,n)||a,n)}if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");return r.cache=new(ke.Cache||S),r}function be(e,t){return e===t||e!=e&&t!=t}function we(e){return null!=e&&_e(e.length)&&!Se(e)}function xe(e){return Ie(e)&&we(e)}function Se(e){return!!Re(e)&&("[object Function]"==(e=B(e))||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e)}function _e(e){return"number"==typeof e&&-1<e&&0==e%1&&9007199254740991>=e}function Re(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function Ie(e){return null!=e&&"object"==typeof e}function Ae(e){return!(!Ie(e)||"[object Object]"!=B(e))&&(null===(e=Pt(e))||"function"==typeof(e=_t.call(e,"constructor")&&e.constructor)&&e instanceof e&&St.call(e)==At)}function De(e){return"string"==typeof e||!br(e)&&Ie(e)&&"[object String]"==B(e)}function Me(e){return"symbol"==typeof e||Ie(e)&&"[object Symbol]"==B(e)}function Ce(e){return e?(e=Fe(e))===$e||e===-$e?17976931348623157e292*(0>e?-1:1):e==e?e:0:0===e?e:0}function Oe(e){var t=(e=Ce(e))%1;return e==e?t?e-t:e:0}function Fe(e){if("number"==typeof e)return e;if(Me(e))return Ge;if(Re(e)&&(e=Re(e="function"==typeof e.valueOf?e.valueOf():e)?e+"":e),"string"!=typeof e)return 0===e?e:+e;e=e.replace(et,"");var t=it.test(e);return t||ot.test(e)?ft(e.slice(2),t?2:8):nt.test(e)?Ge:+e}function Pe(e){return G(e,Le(e))}function je(e){return null==e?"":N(e)}function Be(e,t,r){return(e=null==e?Ve:P(e,t))===Ve?r:e}function Ee(e,t){var r;if(r=null!=e){for(var n,i=-1,a=(n=W(t,r=e)).length,o=!1;++i<a;){var s=pe(n[i]);if(!(o=null!=r&&null!=r&&s in Object(r)))break;r=r[s]}r=o||++i!=a?o:!!(a=null==r?0:r.length)&&_e(a)&&ue(s,a)&&(br(r)||kr(r))}return r}function Te(e){if(we(e))e=I(e);else if(le(e)){var t,r=[];for(t in Object(e))_t.call(e,t)&&"constructor"!=t&&r.push(t);e=r}else e=Kt(e);return e}function Le(e){if(we(e))e=I(e,!0);else if(Re(e)){var t,r=le(e),n=[];for(t in e)("constructor"!=t||!r&&_t.call(e,t))&&n.push(t);e=n}else{if(t=[],null!=e)for(r in Object(e))t.push(r);e=t}return e}function He(e){return null==e?[]:function(e,t){return c(t,(function(t){return e[t]}))}(e,Te(e))}function ze(e){return function(){return e}}function Ue(e){return e}function Ne(e){return L("function"==typeof e?e:O(e,1))}function Ke(){}function We(e){return ce(e)?function(e){return function(t){return null==t?Ve:t[e]}}(pe(e)):function(e){return function(t){return P(t,e)}}(e)}function Je(){return[]}function qe(){return!1}var Ve,$e=1/0,Ge=NaN,Xe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ye=/^\w*$/,Qe=/^\./,Ze=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,et=/^\s+|\s+$/g,tt=/\\(\\)?/g,rt=/\w*$/,nt=/^[-+]0x[0-9a-f]+$/i,it=/^0b[01]+$/i,at=/^\[object .+?Constructor\]$/,ot=/^0o[0-7]+$/i,st=/^(?:0|[1-9]\d*)$/,ut={};ut["[object Float32Array]"]=ut["[object Float64Array]"]=ut["[object Int8Array]"]=ut["[object Int16Array]"]=ut["[object Int32Array]"]=ut["[object Uint8Array]"]=ut["[object Uint8ClampedArray]"]=ut["[object Uint16Array]"]=ut["[object Uint32Array]"]=!0,ut["[object Arguments]"]=ut["[object Array]"]=ut["[object ArrayBuffer]"]=ut["[object Boolean]"]=ut["[object DataView]"]=ut["[object Date]"]=ut["[object Error]"]=ut["[object Function]"]=ut["[object Map]"]=ut["[object Number]"]=ut["[object Object]"]=ut["[object RegExp]"]=ut["[object Set]"]=ut["[object String]"]=ut["[object WeakMap]"]=!1;var ct={};ct["[object Arguments]"]=ct["[object Array]"]=ct["[object ArrayBuffer]"]=ct["[object DataView]"]=ct["[object Boolean]"]=ct["[object Date]"]=ct["[object Float32Array]"]=ct["[object Float64Array]"]=ct["[object Int8Array]"]=ct["[object Int16Array]"]=ct["[object Int32Array]"]=ct["[object Map]"]=ct["[object Number]"]=ct["[object Object]"]=ct["[object RegExp]"]=ct["[object Set]"]=ct["[object String]"]=ct["[object Symbol]"]=ct["[object Uint8Array]"]=ct["[object Uint8ClampedArray]"]=ct["[object Uint16Array]"]=ct["[object Uint32Array]"]=!0,ct["[object Error]"]=ct["[object Function]"]=ct["[object WeakMap]"]=!1;var lt,ft=parseInt,ht="object"==typeof e&&e&&e.Object===Object&&e,pt="object"==typeof self&&self&&self.Object===Object&&self,dt=ht||pt||Function("return this")(),yt=t&&!t.nodeType&&t,vt=yt&&"object"==typeof n&&n&&!n.nodeType&&n,gt=vt&&vt.exports===yt,mt=gt&&ht.process;e:{try{lt=mt&&mt.binding&&mt.binding("util");break e}catch(a){}lt=void 0}var kt=lt&<.isTypedArray,bt=Array.prototype,wt=Object.prototype,xt=dt["__core-js_shared__"],St=Function.prototype.toString,_t=wt.hasOwnProperty,Rt=function(){var e=/[^.]+$/.exec(xt&&xt.keys&&xt.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),It=wt.toString,At=St.call(Object),Dt=RegExp("^"+St.call(_t).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Mt=gt?dt.Buffer:Ve,Ct=dt.Symbol,Ot=dt.Uint8Array,Ft=Mt?Mt.a:Ve,Pt=m(Object.getPrototypeOf),jt=Object.create,Bt=wt.propertyIsEnumerable,Et=bt.splice,Tt=Ct?Ct.isConcatSpreadable:Ve,Lt=Ct?Ct.toStringTag:Ve,Ht=function(){try{var e=ie(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),zt=Math.floor,Ut=Object.getOwnPropertySymbols,Nt=Mt?Mt.isBuffer:Ve,Kt=m(Object.keys),Wt=Math.max,Jt=Math.min,qt=Date.now,Vt=ie(dt,"DataView"),$t=ie(dt,"Map"),Gt=ie(dt,"Promise"),Xt=ie(dt,"Set"),Yt=ie(dt,"WeakMap"),Qt=ie(Object,"create"),Zt=de(Vt),er=de($t),tr=de(Gt),rr=de(Xt),nr=de(Yt),ir=Ct?Ct.prototype:Ve,ar=ir?ir.valueOf:Ve,or=ir?ir.toString:Ve,sr=function(){function e(){}return function(t){return Re(t)?jt?jt(t):(e.prototype=t,t=new e,e.prototype=Ve,t):{}}}();w.prototype.clear=function(){this.__data__=Qt?Qt(null):{},this.size=0},w.prototype.delete=function(e){return e=this.has(e)&&delete this.__data__[e],this.size-=e?1:0,e},w.prototype.get=function(e){var t=this.__data__;return Qt?"__lodash_hash_undefined__"===(e=t[e])?Ve:e:_t.call(t,e)?t[e]:Ve},w.prototype.has=function(e){var t=this.__data__;return Qt?t[e]!==Ve:_t.call(t,e)},w.prototype.set=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Qt&&t===Ve?"__lodash_hash_undefined__":t,this},x.prototype.clear=function(){this.__data__=[],this.size=0},x.prototype.delete=function(e){var t=this.__data__;return!(0>(e=M(t,e))||(e==t.length-1?t.pop():Et.call(t,e,1),--this.size,0))},x.prototype.get=function(e){var t=this.__data__;return 0>(e=M(t,e))?Ve:t[e][1]},x.prototype.has=function(e){return-1<M(this.__data__,e)},x.prototype.set=function(e,t){var r=this.__data__,n=M(r,e);return 0>n?(++this.size,r.push([e,t])):r[n][1]=t,this},S.prototype.clear=function(){this.size=0,this.__data__={hash:new w,map:new($t||x),string:new w}},S.prototype.delete=function(e){return e=ne(this,e).delete(e),this.size-=e?1:0,e},S.prototype.get=function(e){return ne(this,e).get(e)},S.prototype.has=function(e){return ne(this,e).has(e)},S.prototype.set=function(e,t){var r=ne(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this},_.prototype.add=_.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},_.prototype.has=function(e){return this.__data__.has(e)},R.prototype.clear=function(){this.__data__=new x,this.size=0},R.prototype.delete=function(e){var t=this.__data__;return e=t.delete(e),this.size=t.size,e},R.prototype.get=function(e){return this.__data__.get(e)},R.prototype.has=function(e){return this.__data__.has(e)},R.prototype.set=function(e,t){var r=this.__data__;if(r instanceof x){var n=r.__data__;if(!$t||199>n.length)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new S(n)}return r.set(e,t),this.size=r.size,this};var ur=function(e,t){if(null==e)return e;if(!we(e))return function(e,t){return e&&cr(e,t,Te)}(e,t);for(var r=e.length,n=-1,i=Object(e);++n<r&&!1!==t(i[n],n,i););return e},cr=function(e,t,r){for(var n=-1,i=Object(e),a=(r=r(e)).length;a--;){var o=r[++n];if(!1===t(i[o],o,i))break}return e},lr=Ht?function(e,t){return Ht(e,"toString",{configurable:!0,enumerable:!1,value:ze(t),writable:!0})}:Ue,fr=Xt&&1/k(new Xt([,-0]))[1]==$e?function(e){return new Xt(e)}:Ke,hr=Ut?function(e){return null==e?[]:(e=Object(e),s(Ut(e),(function(t){return Bt.call(e,t)})))}:Je,pr=Ut?function(e){for(var t=[];e;)l(t,hr(e)),e=Pt(e);return t}:Je,dr=B;(Vt&&"[object DataView]"!=dr(new Vt(new ArrayBuffer(1)))||$t&&"[object Map]"!=dr(new $t)||Gt&&"[object Promise]"!=dr(Gt.resolve())||Xt&&"[object Set]"!=dr(new Xt)||Yt&&"[object WeakMap]"!=dr(new Yt))&&(dr=function(e){var t=B(e);if(e=(e="[object Object]"==t?e.constructor:Ve)?de(e):"")switch(e){case Zt:return"[object DataView]";case er:return"[object Map]";case tr:return"[object Promise]";case rr:return"[object Set]";case nr:return"[object WeakMap]"}return t});var yr=function(e){var t=0,r=0;return function(){var n=qt(),i=16-(n-r);if(r=n,0<i){if(800<=++t)return arguments[0]}else t=0;return e.apply(Ve,arguments)}}(lr),vr=function(e){var t=(e=ke(e,(function(e){return 500===t.size&&t.clear(),e}))).cache;return e}((function(e){var t=[];return Qe.test(e)&&t.push(""),e.replace(Ze,(function(e,r,n,i){t.push(n?i.replace(tt,"$1"):r||e)})),t})),gr=U(me),mr=function(e){return function(t,r,n){var i=Object(t);if(!we(t)){var a=re(r,3);t=Te(t),r=function(e){return a(i[e],e,i)}}return-1<(r=e(t,r,n))?i[a?t[r]:r]:Ve}}(ye);ke.Cache=S;var kr=E(function(){return arguments}())?E:function(e){return Ie(e)&&_t.call(e,"callee")&&!Bt.call(e,"callee")},br=Array.isArray,wr=Nt||qe,xr=kt?function(e){return function(t){return e(t)}}(kt):function(e){return Ie(e)&&_e(e.length)&&!!ut[B(e)]},Sr=X((function(e,t,r){z(e,t,r)})),_r=X((function(e,t,r,n){z(e,t,r,n)})),Rr=Z((function(e,t){var r={};if(null==e)return r;var n=!1;t=c(t,(function(t){return t=W(t,e),n||(n=1<t.length),t})),G(e,te(e),r),n&&(r=O(r,7,Y));for(var i=t.length;i--;)K(r,t[i]);return r})),Ir=Z((function(e,t){return null==e?{}:function(e,t){return function(e,t,r){for(var n=-1,i=t.length,a={};++n<i;){var o=t[n],s=P(e,o);if(r(0,o)){var u=a;if(o=W(o,e),Re(u))for(var c=-1,l=(o=W(o,u)).length,f=l-1;null!=u&&++c<l;){var h=pe(o[c]),p=s;if(c!=f){var d=u[h];(p=Ve)===Ve&&(p=Re(d)?d:ue(o[c+1])?[]:{})}D(u,h,p),u=u[h]}}}return a}(e,t,(function(t,r){return Ee(e,r)}))}(e,t)}));b.constant=ze,b.filter=function(e,t){return(br(e)?s:F)(e,re(t,3))},b.flatten=ve,b.iteratee=Ne,b.keys=Te,b.keysIn=Le,b.map=function(e,t){return(br(e)?c:H)(e,re(t,3))},b.memoize=ke,b.merge=Sr,b.mergeWith=_r,b.omit=Rr,b.pick=Ir,b.property=We,b.pull=gr,b.pullAll=me,b.remove=function(e,t){var r=[];if(!e||!e.length)return r;var n=-1,i=[],a=e.length;for(t=re(t,3);++n<a;){var o=e[n];t(o,n,e)&&(r.push(o),i.push(n))}for(a=(n=e?i.length:0)-1;n--;)if(o=i[n],n==a||o!==s){var s=o;ue(o)?Et.call(e,o,1):K(e,o)}return r},b.toPlainObject=Pe,b.uniq=function(e){if(e&&e.length)e:{var t=-1,r=u,n=e.length,i=!0,a=[],o=a;if(200<=n){if(r=fr(e)){e=k(r);break e}i=!1,r=v,o=new _}else o=a;t:for(;++t<n;){var s=c=e[t],c=0!==c?c:0;if(i&&s==s){for(var l=o.length;l--;)if(o[l]===s)continue t;a.push(c)}else r(o,s,void 0)||(o!==a&&o.push(s),a.push(c))}e=a}else e=[];return e},b.values=He,b.cloneDeep=function(e){return O(e,5)},b.eq=be,b.find=mr,b.findIndex=ye,b.get=Be,b.hasIn=Ee,b.identity=Ue,b.includes=function(e,t,r,n){return e=we(e)?e:He(e),r=r&&!n?Oe(r):0,n=e.length,0>r&&(r=Wt(n+r,0)),De(e)?r<=n&&-1<e.indexOf(t,r):!!n&&-1<d(e,t,r)},b.isArguments=kr,b.isArray=br,b.isArrayLike=we,b.isArrayLikeObject=xe,b.isBuffer=wr,b.isFunction=Se,b.isLength=_e,b.isObject=Re,b.isObjectLike=Ie,b.isPlainObject=Ae,b.isString=De,b.isSymbol=Me,b.isTypedArray=xr,b.last=ge,b.stubArray=Je,b.stubFalse=qe,b.noop=Ke,b.sortedIndexBy=function(e,t,r){t=(r=re(r,2))(t);for(var n=0,i=null==e?0:e.length,a=t!=t,o=null===t,s=Me(t),u=t===Ve;n<i;){var c=zt((n+i)/2),l=r(e[c]),f=l!==Ve,h=null===l,p=l==l,d=Me(l);(a?p:u?p&&f:o?p&&f&&!h:s?p&&f&&!h&&!d:!h&&!d&&l<t)?n=c+1:i=c}return Jt(i,4294967294)},b.toFinite=Ce,b.toInteger=Oe,b.toNumber=Fe,b.toString=je,b.VERSION="4.17.4",dt._=b,void 0===(i=function(){return b}.call(t,r,t,n))||(n.exports=i)}).call(this)}).call(this,r(2),r(4)(e))},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,r){"use strict";r.r(t),r(1),r(3);var n=r(0);function i(e,t,r,n,i,a,o){try{var s=e[a](o),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,i)}function a(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var o=e.apply(t,r);function s(e){i(o,n,a,s,u,"next",e)}function u(e){i(o,n,a,s,u,"throw",e)}s(void 0)}))}}var o=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.httpManger=new n.SFHttpManager,this.httpManger.setJWTRequestHandler((function(){}))}var t,r,i,o,s;return t=e,(r=[{key:"setCredentials",value:function(e){this.credentials=e}},{key:"uploadFile",value:(s=a(regeneratorRuntime.mark((function e(t,r,n){var i,a,o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i="".concat(n.content.relayUrl,"/integrations/save-item"),a={file:{name:t,item:r},source:n.content.source,authorization:n.content.authorization},e.abrupt("return",new Promise((function(e,t){o.httpManger.postAbsolute(i,a,(function(t){e(t.metadata)}),(function(e){var r=e.error;r||(r={message:"File upload failed."}),console.log("Upload error response",r),t(r)}))})));case 3:case"end":return e.stop()}}),e)}))),function(e,t,r){return s.apply(this,arguments)})},{key:"downloadFile",value:(o=a(regeneratorRuntime.mark((function e(t,r){var n,i,a=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n="".concat(r.content.relayUrl,"/integrations/download-item"),i={metadata:t.content.serverMetadata,authorization:r.content.authorization},e.abrupt("return",new Promise((function(e,t){a.httpManger.postAbsolute(n,i,(function(t){e(t)}),(function(e){var r=e.error;console.log("Download error response",e),t(r)}))})));case 3:case"end":return e.stop()}}),e)}))),function(e,t){return o.apply(this,arguments)})},{key:"deleteFile",value:(i=a(regeneratorRuntime.mark((function e(t,r){var n,i,a=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n="".concat(r.content.relayUrl,"/integrations/delete-item"),i={metadata:t.content.serverMetadata,authorization:r.content.authorization},e.abrupt("return",new Promise((function(e,t){a.httpManger.postAbsolute(n,i,(function(t){e(t)}),(function(e){var r=e.error;console.log("Download error response",e),t(r)}))})));case 3:case"end":return e.stop()}}),e)}))),function(e,t){return i.apply(this,arguments)})}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(t.prototype,r),e}();self.addEventListener("message",(async function(e){const t=e.data;if("encrypt"==t.operation){const e=new n.SFItem({content_type:t.contentType,content:{rawData:t.fileData,fileName:t.fileName,fileType:t.fileType}});new n.SFItemParams(e,t.keys,t.authParams).paramsForSync().then((e=>{self.postMessage({fileItem:e})}))}else if("decrypt"==t.operation)SFJS.itemTransformer.decryptItem(t.item,t.keys).then((()=>{const e=new n.SFItem(t.item),r=e.content.rawData;e.errorDecrypting?self.postMessage({error:{message:"Error decrypting."}}):self.postMessage({decryptedData:r,decryptedItem:e})})).catch((e=>{console.log("Decryption error:",e),self.postMessage({error:e})}));else if("upload"==t.operation){const e=new o;e.setCredentials(t.credentials),e.uploadFile(t.outputFileName,t.fileItem,t.integration).then((e=>{self.postMessage({metadata:e})})).catch((e=>{self.postMessage({error:e}),console.log("Upload exception",e)}))}}),!1)}]);
|
|
2
|
+
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=5)}([function(e,t,r){(function(t){e.exports=function e(t,r,n){function i(o,s){if(!r[o]){if(!t[o]){if(a)return a(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[o]={exports:{}};t[o][0].call(c.exports,(function(e){return i(t[o][1][e]||e)}),c,c.exports,e,t,r,n)}return r[o].exports}for(var a=!1,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,r,n){(function(e){var t,r,i,a,o,s,u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math);function c(e,t){return!t||"object"!==d(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&h(e,t)}function h(e,t){return(h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!t||r.length!==t);n=!0);}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function d(e){return(d="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)}function y(e,t,r,n,i,a,o){try{var s=e[a](o),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,i)}function v(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var a=e.apply(t,r);function o(e){y(a,n,i,o,s,"next",e)}function s(e){y(a,n,i,o,s,"throw",e)}o(void 0)}))}}function g(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function m(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function b(e,t,r){return t&&m(e.prototype,t),r&&m(e,r),e}r=(t=u).lib.WordArray,t.enc.Base64={stringify:function(e){var t=e.words,r=e.sigBytes,n=this._map;e.clamp(),e=[];for(var i=0;i<r;i+=3)for(var a=(t[i>>>2]>>>24-i%4*8&255)<<16|(t[i+1>>>2]>>>24-(i+1)%4*8&255)<<8|t[i+2>>>2]>>>24-(i+2)%4*8&255,o=0;4>o&&i+.75*o<r;o++)e.push(n.charAt(a>>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(i=n.charAt(64))&&-1!=(i=e.indexOf(i))&&(t=i);for(var i=[],a=0,o=0;o<t;o++)if(o%4){var s=n.indexOf(e.charAt(o-1))<<o%4*2,u=n.indexOf(e.charAt(o))>>>6-o%4*2;i[a>>>2]|=(s|u)<<24-a%4*8,a++}return r.create(i,a)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,r,n,i,a,o){return((e=e+(t&r|~t&n)+i+o)<<a|e>>>32-a)+t}function r(e,t,r,n,i,a,o){return((e=e+(t&n|r&~n)+i+o)<<a|e>>>32-a)+t}function n(e,t,r,n,i,a,o){return((e=e+(t^r^n)+i+o)<<a|e>>>32-a)+t}function i(e,t,r,n,i,a,o){return((e=e+(r^(t|~n))+i+o)<<a|e>>>32-a)+t}for(var a=u,o=(c=a.lib).WordArray,s=c.Hasher,c=a.algo,l=[],f=0;64>f;f++)l[f]=4294967296*e.abs(e.sin(f+1))|0;c=c.MD5=s.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,a){for(var o=0;16>o;o++){var s=e[u=a+o];e[u]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}o=this._hash.words;var u=e[a+0],c=(s=e[a+1],e[a+2]),f=e[a+3],h=e[a+4],p=e[a+5],d=e[a+6],y=e[a+7],v=e[a+8],g=e[a+9],m=e[a+10],b=e[a+11],k=e[a+12],w=e[a+13],x=e[a+14],S=e[a+15],_=t(_=o[0],A=o[1],I=o[2],R=o[3],u,7,l[0]),R=t(R,_,A,I,s,12,l[1]),I=t(I,R,_,A,c,17,l[2]),A=t(A,I,R,_,f,22,l[3]);_=t(_,A,I,R,h,7,l[4]),R=t(R,_,A,I,p,12,l[5]),I=t(I,R,_,A,d,17,l[6]),A=t(A,I,R,_,y,22,l[7]),_=t(_,A,I,R,v,7,l[8]),R=t(R,_,A,I,g,12,l[9]),I=t(I,R,_,A,m,17,l[10]),A=t(A,I,R,_,b,22,l[11]),_=t(_,A,I,R,k,7,l[12]),R=t(R,_,A,I,w,12,l[13]),I=t(I,R,_,A,x,17,l[14]),_=r(_,A=t(A,I,R,_,S,22,l[15]),I,R,s,5,l[16]),R=r(R,_,A,I,d,9,l[17]),I=r(I,R,_,A,b,14,l[18]),A=r(A,I,R,_,u,20,l[19]),_=r(_,A,I,R,p,5,l[20]),R=r(R,_,A,I,m,9,l[21]),I=r(I,R,_,A,S,14,l[22]),A=r(A,I,R,_,h,20,l[23]),_=r(_,A,I,R,g,5,l[24]),R=r(R,_,A,I,x,9,l[25]),I=r(I,R,_,A,f,14,l[26]),A=r(A,I,R,_,v,20,l[27]),_=r(_,A,I,R,w,5,l[28]),R=r(R,_,A,I,c,9,l[29]),I=r(I,R,_,A,y,14,l[30]),_=n(_,A=r(A,I,R,_,k,20,l[31]),I,R,p,4,l[32]),R=n(R,_,A,I,v,11,l[33]),I=n(I,R,_,A,b,16,l[34]),A=n(A,I,R,_,x,23,l[35]),_=n(_,A,I,R,s,4,l[36]),R=n(R,_,A,I,h,11,l[37]),I=n(I,R,_,A,y,16,l[38]),A=n(A,I,R,_,m,23,l[39]),_=n(_,A,I,R,w,4,l[40]),R=n(R,_,A,I,u,11,l[41]),I=n(I,R,_,A,f,16,l[42]),A=n(A,I,R,_,d,23,l[43]),_=n(_,A,I,R,g,4,l[44]),R=n(R,_,A,I,k,11,l[45]),I=n(I,R,_,A,S,16,l[46]),_=i(_,A=n(A,I,R,_,c,23,l[47]),I,R,u,6,l[48]),R=i(R,_,A,I,y,10,l[49]),I=i(I,R,_,A,x,15,l[50]),A=i(A,I,R,_,p,21,l[51]),_=i(_,A,I,R,k,6,l[52]),R=i(R,_,A,I,f,10,l[53]),I=i(I,R,_,A,m,15,l[54]),A=i(A,I,R,_,s,21,l[55]),_=i(_,A,I,R,v,6,l[56]),R=i(R,_,A,I,S,10,l[57]),I=i(I,R,_,A,d,15,l[58]),A=i(A,I,R,_,w,21,l[59]),_=i(_,A,I,R,h,6,l[60]),R=i(R,_,A,I,b,10,l[61]),I=i(I,R,_,A,c,15,l[62]),A=i(A,I,R,_,g,21,l[63]),o[0]=o[0]+_|0,o[1]=o[1]+A|0,o[2]=o[2]+I|0,o[3]=o[3]+R|0},_doFinalize:function(){var t=this._data,r=t.words,n=8*this._nDataBytes,i=8*t.sigBytes;r[i>>>5]|=128<<24-i%32;var a=e.floor(n/4294967296);for(r[15+(i+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),r[14+(i+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(r.length+1),this._process(),r=(t=this._hash).words,n=0;4>n;n++)i=r[n],r[n]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8);return t},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}}),a.MD5=s._createHelper(c),a.HmacMD5=s._createHmacHelper(c)}(Math),function(){var e,t=u,r=(e=t.lib).Base,n=e.WordArray,i=(e=t.algo).EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var r=(s=this.cfg).hasher.create(),i=n.create(),a=i.words,o=s.keySize,s=s.iterations;a.length<o;){u&&r.update(u);var u=r.update(e).finalize(t);r.reset();for(var c=1;c<s;c++)u=r.finalize(u),r.reset();i.concat(u)}return i.sigBytes=4*o,i}});t.EvpKDF=function(e,t,r){return i.create(r).compute(e,t)}}(),u.lib.Cipher||function(e){var t=(d=u).lib,r=t.Base,n=t.WordArray,i=t.BufferedBlockAlgorithm,a=d.enc.Base64,o=d.algo.EvpKDF,s=t.Cipher=i.extend({cfg:r.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,r){this.cfg=this.cfg.extend(r),this._xformMode=e,this._key=t,this.reset()},reset:function(){i.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(e){return{encrypt:function(t,r,n){return("string"==typeof r?y:p).encrypt(e,t,r,n)},decrypt:function(t,r,n){return("string"==typeof r?y:p).decrypt(e,t,r,n)}}}});t.StreamCipher=s.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var c=d.mode={},l=function(e,t,r){var n=this._iv;n?this._iv=void 0:n=this._prevBlock;for(var i=0;i<r;i++)e[t+i]^=n[i]},f=(t.BlockCipherMode=r.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}})).extend();f.Encryptor=f.extend({processBlock:function(e,t){var r=this._cipher,n=r.blockSize;l.call(this,e,t,n),r.encryptBlock(e,t),this._prevBlock=e.slice(t,t+n)}}),f.Decryptor=f.extend({processBlock:function(e,t){var r=this._cipher,n=r.blockSize,i=e.slice(t,t+n);r.decryptBlock(e,t),l.call(this,e,t,n),this._prevBlock=i}}),c=c.CBC=f,f=(d.pad={}).Pkcs7={pad:function(e,t){for(var r,i=(r=(r=4*t)-e.sigBytes%r)<<24|r<<16|r<<8|r,a=[],o=0;o<r;o+=4)a.push(i);r=n.create(a,r),e.concat(r)},unpad:function(e){e.sigBytes-=255&e.words[e.sigBytes-1>>>2]}},t.BlockCipher=s.extend({cfg:s.cfg.extend({mode:c,padding:f}),reset:function(){s.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var r=t.createEncryptor;else r=t.createDecryptor,this._minBufferSize=1;this._mode=r.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=r.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),p=(c=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(a)},parse:function(e){var t=(e=a.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var r=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:r})}},t.SerializableCipher=r.extend({cfg:r.extend({format:c}),encrypt:function(e,t,r,n){n=this.cfg.extend(n);var i=e.createEncryptor(r,n);return t=i.finalize(t),i=i.cfg,h.create({ciphertext:t,key:r,iv:i.iv,algorithm:e,mode:i.mode,padding:i.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,r,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(r,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,r,i){return i||(i=n.random(8)),e=o.create({keySize:t+r}).compute(e,i),r=n.create(e.words.slice(t),4*r),e.sigBytes=4*t,h.create({key:e,iv:r,salt:i})}},y=t.PasswordBasedCipher=p.extend({cfg:p.cfg.extend({kdf:d}),encrypt:function(e,t,r,n){return r=(n=this.cfg.extend(n)).kdf.execute(r,e.keySize,e.ivSize),n.iv=r.iv,(e=p.encrypt.call(this,e,t,r.key,n)).mixIn(r),e},decrypt:function(e,t,r,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),r=n.kdf.execute(r,e.keySize,e.ivSize,t.salt),n.iv=r.iv,p.decrypt.call(this,e,t,r.key,n)}})}(),function(){for(var e=u,t=e.lib.BlockCipher,r=e.algo,n=[],i=[],a=[],o=[],s=[],c=[],l=[],f=[],h=[],p=[],d=[],y=0;256>y;y++)d[y]=128>y?y<<1:y<<1^283;var v=0,g=0;for(y=0;256>y;y++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;n[v]=m,i[m]=v;var b=d[v],k=d[b],w=d[k],x=257*d[m]^16843008*m;a[v]=x<<24|x>>>8,o[v]=x<<16|x>>>16,s[v]=x<<8|x>>>24,c[v]=x,x=16843009*w^65537*k^257*b^16843008*v,l[m]=x<<24|x>>>8,f[m]=x<<16|x>>>16,h[m]=x<<8|x>>>24,p[m]=x,v?(v=b^d[d[d[w^b]]],g^=d[d[g]]):v=g=1}var S=[0,1,2,4,8,16,32,64,128,27,54];r=r.AES=t.extend({_doReset:function(){for(var e=(r=this._key).words,t=r.sigBytes/4,r=4*((this._nRounds=t+6)+1),i=this._keySchedule=[],a=0;a<r;a++)if(a<t)i[a]=e[a];else{var o=i[a-1];a%t?6<t&&4==a%t&&(o=n[o>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=S[a/t|0]<<24),i[a]=i[a-t]^o}for(e=this._invKeySchedule=[],t=0;t<r;t++)a=r-t,o=t%4?i[a]:i[a-4],e[t]=4>t||4>=a?o:l[n[o>>>24]]^f[n[o>>>16&255]]^h[n[o>>>8&255]]^p[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,a,o,s,c,n)},decryptBlock:function(e,t){var r=e[t+1];e[t+1]=e[t+3],e[t+3]=r,this._doCryptBlock(e,t,this._invKeySchedule,l,f,h,p,i),r=e[t+1],e[t+1]=e[t+3],e[t+3]=r},_doCryptBlock:function(e,t,r,n,i,a,o,s){for(var u=this._nRounds,c=e[t]^r[0],l=e[t+1]^r[1],f=e[t+2]^r[2],h=e[t+3]^r[3],p=4,d=1;d<u;d++){var y=n[c>>>24]^i[l>>>16&255]^a[f>>>8&255]^o[255&h]^r[p++],v=n[l>>>24]^i[f>>>16&255]^a[h>>>8&255]^o[255&c]^r[p++],g=n[f>>>24]^i[h>>>16&255]^a[c>>>8&255]^o[255&l]^r[p++];h=n[h>>>24]^i[c>>>16&255]^a[l>>>8&255]^o[255&f]^r[p++],c=y,l=v,f=g}y=(s[c>>>24]<<24|s[l>>>16&255]<<16|s[f>>>8&255]<<8|s[255&h])^r[p++],v=(s[l>>>24]<<24|s[f>>>16&255]<<16|s[h>>>8&255]<<8|s[255&c])^r[p++],g=(s[f>>>24]<<24|s[h>>>16&255]<<16|s[c>>>8&255]<<8|s[255&l])^r[p++],h=(s[h>>>24]<<24|s[c>>>16&255]<<16|s[l>>>8&255]<<8|s[255&f])^r[p++],e[t]=y,e[t+1]=v,e[t+2]=g,e[t+3]=h},keySize:8}),e.AES=t._createHelper(r)}(),u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math),function(e){for(var t=u,r=(i=t.lib).WordArray,n=i.Hasher,i=t.algo,a=[],o=[],s=function(e){return 4294967296*(e-(0|e))|0},c=2,l=0;64>l;){var f;e:{f=c;for(var h=e.sqrt(f),p=2;p<=h;p++)if(!(f%p)){f=!1;break e}f=!0}f&&(8>l&&(a[l]=s(e.pow(c,.5))),o[l]=s(e.pow(c,1/3)),l++),c++}var d=[];i=i.SHA256=n.extend({_doReset:function(){this._hash=new r.init(a.slice(0))},_doProcessBlock:function(e,t){for(var r=this._hash.words,n=r[0],i=r[1],a=r[2],s=r[3],u=r[4],c=r[5],l=r[6],f=r[7],h=0;64>h;h++){if(16>h)d[h]=0|e[t+h];else{var p=d[h-15],y=d[h-2];d[h]=((p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3)+d[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+d[h-16]}p=f+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+o[h]+d[h],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&i^n&a^i&a),f=l,l=c,c=u,u=s+p|0,s=a,a=i,i=n,n=p+y|0}r[0]=r[0]+n|0,r[1]=r[1]+i|0,r[2]=r[2]+a|0,r[3]=r[3]+s|0,r[4]=r[4]+u|0,r[5]=r[5]+c|0,r[6]=r[6]+l|0,r[7]=r[7]+f|0},_doFinalize:function(){var t=this._data,r=t.words,n=8*this._nDataBytes,i=8*t.sigBytes;return r[i>>>5]|=128<<24-i%32,r[14+(i+64>>>9<<4)]=e.floor(n/4294967296),r[15+(i+64>>>9<<4)]=n,t.sigBytes=4*r.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}}),t.SHA256=n._createHelper(i),t.HmacSHA256=n._createHmacHelper(i)}(Math),a=(i=u).enc.Utf8,i.algo.HMAC=i.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var r=e.blockSize,n=4*r;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var i=this._oKey=t.clone(),o=this._iKey=t.clone(),s=i.words,u=o.words,c=0;c<r;c++)s[c]^=1549556828,u[c]^=909522486;i.sigBytes=o.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}}),u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math),function(e){var t,r=(t=u).lib,n=r.Base,i=r.WordArray;(t=t.x64={}).Word=n.extend({init:function(e,t){this.high=e,this.low=t}}),t.WordArray=n.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,r=[],n=0;n<t;n++){var a=e[n];r.push(a.high),r.push(a.low)}return i.create(r,this.sigBytes)},clone:function(){for(var e=n.clone.call(this),t=e.words=this.words.slice(0),r=t.length,i=0;i<r;i++)t[i]=t[i].clone();return e}})}(),function(){function e(){return n.create.apply(n,arguments)}for(var t=u,r=t.lib.Hasher,n=(a=t.x64).Word,i=a.WordArray,a=t.algo,o=[e(1116352408,3609767458),e(1899447441,602891725),e(3049323471,3964484399),e(3921009573,2173295548),e(961987163,4081628472),e(1508970993,3053834265),e(2453635748,2937671579),e(2870763221,3664609560),e(3624381080,2734883394),e(310598401,1164996542),e(607225278,1323610764),e(1426881987,3590304994),e(1925078388,4068182383),e(2162078206,991336113),e(2614888103,633803317),e(3248222580,3479774868),e(3835390401,2666613458),e(4022224774,944711139),e(264347078,2341262773),e(604807628,2007800933),e(770255983,1495990901),e(1249150122,1856431235),e(1555081692,3175218132),e(1996064986,2198950837),e(2554220882,3999719339),e(2821834349,766784016),e(2952996808,2566594879),e(3210313671,3203337956),e(3336571891,1034457026),e(3584528711,2466948901),e(113926993,3758326383),e(338241895,168717936),e(666307205,1188179964),e(773529912,1546045734),e(1294757372,1522805485),e(1396182291,2643833823),e(1695183700,2343527390),e(1986661051,1014477480),e(2177026350,1206759142),e(2456956037,344077627),e(2730485921,1290863460),e(2820302411,3158454273),e(3259730800,3505952657),e(3345764771,106217008),e(3516065817,3606008344),e(3600352804,1432725776),e(4094571909,1467031594),e(275423344,851169720),e(430227734,3100823752),e(506948616,1363258195),e(659060556,3750685593),e(883997877,3785050280),e(958139571,3318307427),e(1322822218,3812723403),e(1537002063,2003034995),e(1747873779,3602036899),e(1955562222,1575990012),e(2024104815,1125592928),e(2227730452,2716904306),e(2361852424,442776044),e(2428436474,593698344),e(2756734187,3733110249),e(3204031479,2999351573),e(3329325298,3815920427),e(3391569614,3928383900),e(3515267271,566280711),e(3940187606,3454069534),e(4118630271,4000239992),e(116418474,1914138554),e(174292421,2731055270),e(289380356,3203993006),e(460393269,320620315),e(685471733,587496836),e(852142971,1086792851),e(1017036298,365543100),e(1126000580,2618297676),e(1288033470,3409855158),e(1501505948,4234509866),e(1607167915,987167468),e(1816402316,1246189591)],s=[],c=0;80>c;c++)s[c]=e();a=a.SHA512=r.extend({_doReset:function(){this._hash=new i.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var r=(f=this._hash.words)[0],n=f[1],i=f[2],a=f[3],u=f[4],c=f[5],l=f[6],f=f[7],h=r.high,p=r.low,d=n.high,y=n.low,v=i.high,g=i.low,m=a.high,b=a.low,k=u.high,w=u.low,x=c.high,S=c.low,_=l.high,R=l.low,I=f.high,A=f.low,D=h,M=p,O=d,C=y,F=v,P=g,j=m,E=b,L=k,B=w,T=x,H=S,z=_,U=R,N=I,K=A,W=0;80>W;W++){var J=s[W];if(16>W)var q=J.high=0|e[t+2*W],V=J.low=0|e[t+2*W+1];else{q=((V=(q=s[W-15]).high)>>>1|($=q.low)<<31)^(V>>>8|$<<24)^V>>>7;var $=($>>>1|V<<31)^($>>>8|V<<24)^($>>>7|V<<25),G=((V=(G=s[W-2]).high)>>>19|(X=G.low)<<13)^(V<<3|X>>>29)^V>>>6,X=(X>>>19|V<<13)^(X<<3|V>>>29)^(X>>>6|V<<26),Y=(V=s[W-7]).high,Q=(Z=s[W-16]).high,Z=Z.low;q=(q=(q=q+Y+((V=$+V.low)>>>0<$>>>0?1:0))+G+((V+=X)>>>0<X>>>0?1:0))+Q+((V+=Z)>>>0<Z>>>0?1:0),J.high=q,J.low=V}Y=L&T^~L&z,Z=B&H^~B&U,J=D&O^D&F^O&F;var ee=M&C^M&P^C&P,te=($=(D>>>28|M<<4)^(D<<30|M>>>2)^(D<<25|M>>>7),G=(M>>>28|D<<4)^(M<<30|D>>>2)^(M<<25|D>>>7),(X=o[W]).high),re=X.low;Q=N+((L>>>14|B<<18)^(L>>>18|B<<14)^(L<<23|B>>>9))+((X=K+((B>>>14|L<<18)^(B>>>18|L<<14)^(B<<23|L>>>9)))>>>0<K>>>0?1:0),N=z,K=U,z=T,U=H,T=L,H=B,L=j+(Q=(Q=(Q=Q+Y+((X+=Z)>>>0<Z>>>0?1:0))+te+((X+=re)>>>0<re>>>0?1:0))+q+((X+=V)>>>0<V>>>0?1:0))+((B=E+X|0)>>>0<E>>>0?1:0)|0,j=F,E=P,F=O,P=C,O=D,C=M,D=Q+(J=$+J+((V=G+ee)>>>0<G>>>0?1:0))+((M=X+V|0)>>>0<X>>>0?1:0)|0}p=r.low=p+M,r.high=h+D+(p>>>0<M>>>0?1:0),y=n.low=y+C,n.high=d+O+(y>>>0<C>>>0?1:0),g=i.low=g+P,i.high=v+F+(g>>>0<P>>>0?1:0),b=a.low=b+E,a.high=m+j+(b>>>0<E>>>0?1:0),w=u.low=w+B,u.high=k+L+(w>>>0<B>>>0?1:0),S=c.low=S+H,c.high=x+T+(S>>>0<H>>>0?1:0),R=l.low=R+U,l.high=_+z+(R>>>0<U>>>0?1:0),A=f.low=A+K,f.high=I+N+(A>>>0<K>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,r=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[30+(n+128>>>10<<5)]=Math.floor(r/4294967296),t[31+(n+128>>>10<<5)]=r,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32}),t.SHA512=r._createHelper(a),t.HmacSHA512=r._createHmacHelper(a)}(),s=(o=u).enc.Utf8,o.algo.HMAC=o.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var r=e.blockSize,n=4*r;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var i=this._oKey=t.clone(),a=this._iKey=t.clone(),o=i.words,u=a.words,c=0;c<r;c++)o[c]^=1549556828,u[c]^=909522486;i.sigBytes=a.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}}),u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math),function(){var e=u,t=(i=e.lib).WordArray,r=i.Hasher,n=[],i=e.algo.SHA1=r.extend({_doReset:function(){this._hash=new t.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var r=this._hash.words,i=r[0],a=r[1],o=r[2],s=r[3],u=r[4],c=0;80>c;c++){if(16>c)n[c]=0|e[t+c];else{var l=n[c-3]^n[c-8]^n[c-14]^n[c-16];n[c]=l<<1|l>>>31}l=(i<<5|i>>>27)+u+n[c],l=20>c?l+(1518500249+(a&o|~a&s)):40>c?l+(1859775393+(a^o^s)):60>c?l+((a&o|a&s|o&s)-1894007588):l+((a^o^s)-899497514),u=s,s=o,o=a<<30|a>>>2,a=i,i=l}r[0]=r[0]+i|0,r[1]=r[1]+a|0,r[2]=r[2]+o|0,r[3]=r[3]+s|0,r[4]=r[4]+u|0},_doFinalize:function(){var e=this._data,t=e.words,r=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=Math.floor(r/4294967296),t[15+(n+64>>>9<<4)]=r,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});e.SHA1=r._createHelper(i),e.HmacSHA1=r._createHmacHelper(i)}(),function(){var e=u,t=e.enc.Utf8;e.algo.HMAC=e.lib.Base.extend({init:function(e,r){e=this._hasher=new e.init,"string"==typeof r&&(r=t.parse(r));var n=e.blockSize,i=4*n;r.sigBytes>i&&(r=e.finalize(r)),r.clamp();for(var a=this._oKey=r.clone(),o=this._iKey=r.clone(),s=a.words,u=o.words,c=0;c<n;c++)s[c]^=1549556828,u[c]^=909522486;a.sigBytes=o.sigBytes=i,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher;return e=t.finalize(e),t.reset(),t.finalize(this._oKey.clone().concat(e))}})}(),function(){var e,t=u,r=(e=t.lib).Base,n=e.WordArray,i=(e=t.algo).HMAC,a=e.PBKDF2=r.extend({cfg:r.extend({keySize:4,hasher:e.SHA1,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){var r=this.cfg,a=i.create(r.hasher,e),o=n.create(),s=n.create([1]),u=o.words,c=s.words,l=r.keySize;for(r=r.iterations;u.length<l;){var f=a.update(t).finalize(s);a.reset();for(var h=f.words,p=h.length,d=f,y=1;y<r;y++){d=a.finalize(d),a.reset();for(var v=d.words,g=0;g<p;g++)h[g]^=v[g]}o.concat(f),c[0]++}return o.sigBytes=4*l,o}});t.PBKDF2=function(e,t,r){return a.create(r).compute(e,t)}}(),u=u||function(e,t){var r={},n=r.lib={},i=function(){},a=n.Base={extend:function(e){i.prototype=this;var t=new i;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=a.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,r=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var i=0;i<e;i++)t[n+i>>>2]|=(r[i>>>2]>>>24-i%4*8&255)<<24-(n+i)%4*8;else if(65535<r.length)for(i=0;i<e;i+=4)t[n+i>>>2]=r[i>>>2];else t.push.apply(t,r);return this.sigBytes+=e,this},clamp:function(){var t=this.words,r=this.sigBytes;t[r>>>2]&=4294967295<<32-r%4*8,t.length=e.ceil(r/4)},clone:function(){var e=a.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var r=[],n=0;n<t;n+=4)r.push(4294967296*e.random()|0);return new o.init(r,t)}}),s=r.enc={},u=s.Hex={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++){var i=t[n>>>2]>>>24-n%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n+=2)r[n>>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(r,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var r=[],n=0;n<e;n++)r.push(String.fromCharCode(t[n>>>2]>>>24-n%4*8&255));return r.join("")},parse:function(e){for(var t=e.length,r=[],n=0;n<t;n++)r[n>>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(r,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},f=n.BufferedBlockAlgorithm=a.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var r=this._data,n=r.words,i=r.sigBytes,a=this.blockSize,s=i/(4*a);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*a,i=e.min(4*t,i),t){for(var u=0;u<t;u+=a)this._doProcessBlock(n,u);u=n.splice(0,t),r.sigBytes-=i}return new o.init(u,i)},clone:function(){var e=a.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});n.Hasher=f.extend({cfg:a.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,r){return new e.init(r).finalize(t)}},_createHmacHelper:function(e){return function(t,r){return new h.HMAC.init(e,r).finalize(t)}}});var h=r.algo={};return r}(Math),function(){var e=u,t=(i=e.lib).WordArray,r=i.Hasher,n=[],i=e.algo.SHA1=r.extend({_doReset:function(){this._hash=new t.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var r=this._hash.words,i=r[0],a=r[1],o=r[2],s=r[3],u=r[4],c=0;80>c;c++){if(16>c)n[c]=0|e[t+c];else{var l=n[c-3]^n[c-8]^n[c-14]^n[c-16];n[c]=l<<1|l>>>31}l=(i<<5|i>>>27)+u+n[c],l=20>c?l+(1518500249+(a&o|~a&s)):40>c?l+(1859775393+(a^o^s)):60>c?l+((a&o|a&s|o&s)-1894007588):l+((a^o^s)-899497514),u=s,s=o,o=a<<30|a>>>2,a=i,i=l}r[0]=r[0]+i|0,r[1]=r[1]+a|0,r[2]=r[2]+o|0,r[3]=r[3]+s|0,r[4]=r[4]+u|0},_doFinalize:function(){var e=this._data,t=e.words,r=8*this._nDataBytes,n=8*e.sigBytes;return t[n>>>5]|=128<<24-n%32,t[14+(n+64>>>9<<4)]=Math.floor(r/4294967296),t[15+(n+64>>>9<<4)]=r,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});e.SHA1=r._createHelper(i),e.HmacSHA1=r._createHmacHelper(i)}(),Object.defineProperty(n,"__esModule",{value:!0}),n.StandardFile=n.SFItemTransformer=n.SFCryptoWeb=n.SFCryptoJS=n.SFAbstractCrypto=n.SFItemHistoryEntry=n.SFItemHistory=n.SFHistorySession=n.SFPrivileges=n.SFPredicate=n.SFItemParams=n.SFItem=n.SFSyncManager=n.SFStorageManager=n.SFSingletonManager=n.SFSessionHistoryManager=n.SFPrivilegesManager=n.SFModelManager=n.SFMigrationManager=n.SFHttpManager=n.SFAuthManager=n.SFAlertManager=void 0;var k=function(){function e(){g(this,e)}var t,r;return b(e,[{key:"alert",value:(r=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){window.alert(t.text),e()})));case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})},{key:"confirm",value:(t=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){window.confirm(t.text)?e():r()})));case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})}]),e}();n.SFAlertManager=k;var w=function(){function e(t,r,n,i){g(this,e),e.DidSignOutEvent="DidSignOutEvent",e.WillSignInEvent="WillSignInEvent",e.DidSignInEvent="DidSignInEvent",this.httpManager=r,this.storageManager=t,this.alertManager=n||new k,this.$timeout=i||setTimeout.bind(window),this.eventHandlers=[]}var t,r,n,i,a,o,s,u,c,l;return b(e,[{key:"addEventHandler",value:function(e){return this.eventHandlers.push(e),e}},{key:"removeEventHandler",value:function(e){_.pull(this.eventHandlers,e)}},{key:"notifyEvent",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,o=this.eventHandlers[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)(0,a.value)(e,t||{})}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}},{key:"saveKeys",value:(l=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._keys=t,e.next=3,this.storageManager.setItem("mk",t.mk);case 3:return e.next=5,this.storageManager.setItem("ak",t.ak);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"signout",value:(c=v(regeneratorRuntime.mark((function t(r){var n=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this._keys=null,this._authParams=null,!r){t.next=6;break}return t.abrupt("return",this.storageManager.clearAllData().then((function(){n.notifyEvent(e.DidSignOutEvent)})));case 6:this.notifyEvent(e.DidSignOutEvent);case 7:case"end":return t.stop()}}),t,this)}))),function(e){return c.apply(this,arguments)})},{key:"keys",value:(u=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._keys){e.next=11;break}return e.next=3,this.storageManager.getItem("mk");case 3:if(t=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.t0=t,e.next=9,this.storageManager.getItem("ak");case 9:e.t1=e.sent,this._keys={mk:e.t0,ak:e.t1};case 11:return e.abrupt("return",this._keys);case 12:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"getAuthParams",value:(s=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._authParams){e.next=5;break}return e.next=3,this.storageManager.getItem("auth_params");case 3:t=e.sent,this._authParams=JSON.parse(t);case 5:if(!this._authParams||this._authParams.version){e.next=9;break}return e.next=8,this.defaultProtocolVersion();case 8:this._authParams.version=e.sent;case 9:return e.abrupt("return",this._authParams);case 10:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"defaultProtocolVersion",value:(o=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.keys();case 2:if(!(t=e.sent)||!t.ak){e.next=7;break}return e.abrupt("return","002");case 7:return e.abrupt("return","001");case 8:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"protocolVersion",value:(a=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getAuthParams();case 2:if(!(t=e.sent)||!t.version){e.next=5;break}return e.abrupt("return",t.version);case 5:return e.abrupt("return",this.defaultProtocolVersion());case 6:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"getAuthParamsForEmail",value:(i=v(regeneratorRuntime.mark((function e(t,r,n){var i,a=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(i=_.merge({email:r},n)).api=S.getApiVersion(),e.abrupt("return",new Promise((function(e,r){var n=t+"/auth/params";a.httpManager.getAbsolute(n,i,(function(t){e(t)}),(function(t){console.error("Error getting auth params",t),"object"!==d(t)&&(t={error:{message:"A server error occurred while trying to sign in. Please try again."}}),e(t)}))})));case 3:case"end":return e.stop()}}),e)}))),function(e,t,r){return i.apply(this,arguments)})},{key:"lock",value:function(){this.locked=!0}},{key:"unlock",value:function(){this.locked=!1}},{key:"isLocked",value:function(){return 1==this.locked}},{key:"unlockAndResolve",value:function(e,t){this.unlock(),e(t)}},{key:"login",value:(n=v(regeneratorRuntime.mark((function t(r,n,i,a,o){var s=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(){var t=v(regeneratorRuntime.mark((function t(u,c){var l,f,h,p,y,g,m,b,k,w;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.keys();case 2:if(null==t.sent){t.next=6;break}return u({error:{message:"Cannot log in because already signed in."}}),t.abrupt("return");case 6:if(!s.isLocked()){t.next=9;break}return u({error:{message:"Login already in progress."}}),t.abrupt("return");case 9:return s.lock(),s.notifyEvent(e.WillSignInEvent),t.next=13,s.getAuthParamsForEmail(r,n,o);case 13:if((l=t.sent).identifier=n,!l.error){t.next=18;break}return s.unlockAndResolve(u,l),t.abrupt("return");case 18:if(l&&l.pw_cost){t.next=21;break}return s.unlockAndResolve(u,{error:{message:"Invalid email or password."}}),t.abrupt("return");case 21:if(SFJS.supportedVersions().includes(l.version)){t.next=25;break}return f=SFJS.isVersionNewerThanLibraryVersion(l.version)?"This version of the application does not support your newer account type. Please upgrade to the latest version of Standard Notes to sign in.":"The protocol version associated with your account is outdated and no longer supported by this application. Please visit standardnotes.org/help/security for more information.",s.unlockAndResolve(u,{error:{message:f}}),t.abrupt("return");case 25:if(!SFJS.isProtocolVersionOutdated(l.version)){t.next=32;break}return h="The encryption version for your account, ".concat(l.version,", is outdated and requires upgrade. You may proceed with login, but are advised to perform a security update using the web or desktop application. Please visit standardnotes.org/help/security for more information."),p=!1,t.next=30,s.alertManager.confirm({title:"Update Needed",text:h,confirmButtonText:"Sign In"}).catch((function(){s.unlockAndResolve(u,{error:{}}),p=!0}));case 30:if(!p){t.next=32;break}return t.abrupt("return");case 32:if(SFJS.supportsPasswordDerivationCost(l.pw_cost)){t.next=36;break}return s.unlockAndResolve(u,{error:{message:"Your account was created on a platform with higher security capabilities than this browser supports. If we attempted to generate your login keys here, it would take hours. Please use a browser with more up to date security capabilities, like Google Chrome or Firefox, to log in."}}),t.abrupt("return");case 36:if(y=SFJS.costMinimumForVersion(l.version),!(l.pw_cost<y)){t.next=41;break}return s.unlockAndResolve(u,{error:{message:"Unable to login due to insecure password parameters. Please visit standardnotes.org/help/security for more information."}}),t.abrupt("return");case 41:if(!a){t.next=47;break}if(g=SFJS.version(),l.version===g){t.next=47;break}return m="Strict sign in refused server sign in parameters. The latest security version is ".concat(g,", but your account is reported to have version ").concat(l.version,". If you'd like to proceed with sign in anyway, please disable strict sign in and try again."),s.unlockAndResolve(u,{error:{message:m}}),t.abrupt("return");case 47:return t.next=49,SFJS.crypto.computeEncryptionKeysForUser(i,l);case 49:b=t.sent,k=r+"/auth/sign_in",(w=_.merge({password:b.pw,email:n},o)).api=S.getApiVersion(),s.httpManager.postAbsolute(k,w,function(){var t=v(regeneratorRuntime.mark((function t(i){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.handleAuthResponse(i,n,r,l,b);case 2:s.notifyEvent(e.DidSignInEvent),s.$timeout((function(){return s.unlockAndResolve(u,i)}));case 4:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),(function(e){console.error("Error logging in",e),"object"!==d(e)&&(e={error:{message:"A server error occurred while trying to sign in. Please try again."}}),s.$timeout((function(){return s.unlockAndResolve(u,e)}))}));case 54:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}()));case 1:case"end":return t.stop()}}),t)}))),function(e,t,r,i,a){return n.apply(this,arguments)})},{key:"register",value:function(e,t,r){var n=this;return new Promise(function(){var i=v(regeneratorRuntime.mark((function i(a,o){var s,u,c,l,f,h;return regeneratorRuntime.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(!n.isLocked()){i.next=3;break}return a({error:{message:"Register already in progress."}}),i.abrupt("return");case 3:if(!(r.length<8)){i.next=8;break}return s="Your password must be at least ".concat(8," characters in length. For your security, please choose a longer password or, ideally, a passphrase, and try again."),a({error:{message:s}}),i.abrupt("return");case 8:return n.lock(),i.next=11,SFJS.crypto.generateInitialKeysAndAuthParamsForUser(t,r);case 11:u=i.sent,c=u.keys,l=u.authParams,f=e+"/auth",(h=_.merge({password:c.pw,email:t},l)).api=S.getApiVersion(),n.httpManager.postAbsolute(f,h,function(){var r=v(regeneratorRuntime.mark((function r(i){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,n.handleAuthResponse(i,t,e,l,c);case 2:n.unlockAndResolve(a,i);case 3:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}(),(function(e){console.error("Registration error",e),"object"!==d(e)&&(e={error:{message:"A server error occurred while trying to register. Please try again."}}),n.unlockAndResolve(a,e)}));case 18:case"end":return i.stop()}}),i)})));return function(e,t){return i.apply(this,arguments)}}())}},{key:"changePassword",value:(r=v(regeneratorRuntime.mark((function e(t,r,n,i,a){var o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise(function(){var e=v(regeneratorRuntime.mark((function e(s,u){var c,l,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!o.isLocked()){e.next=3;break}return s({error:{message:"Change password already in progress."}}),e.abrupt("return");case 3:o.lock(),c=i.pw,l=t+"/auth/change_pw",(f=_.merge({new_password:c,current_password:n},a)).api=S.getApiVersion(),o.httpManager.postAuthenticatedAbsolute(l,f,function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.handleAuthResponse(t,r,null,a,i);case 2:o.unlockAndResolve(s,t);case 3:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),(function(e){"object"!==d(e)&&(e={error:{message:"Something went wrong while changing your password. Your password was not changed. Please try again."}}),o.unlockAndResolve(s,e)}));case 9:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()));case 1:case"end":return e.stop()}}),e)}))),function(e,t,n,i,a){return r.apply(this,arguments)})},{key:"handleAuthResponse",value:(t=v(regeneratorRuntime.mark((function e(t,r,n,i,a){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n){e.next=3;break}return e.next=3,this.storageManager.setItem("server",n);case 3:return this._authParams=i,e.next=6,this.storageManager.setItem("auth_params",JSON.stringify(i));case 6:return e.next=8,this.storageManager.setItem("jwt",t.token);case 8:return e.abrupt("return",this.saveKeys(a));case 9:case"end":return e.stop()}}),e,this)}))),function(e,r,n,i,a){return t.apply(this,arguments)})}]),e}();n.SFAuthManager=w;var x="undefined"!=typeof window?window:void 0!==e?e:null,S=function(){function e(t,r){g(this,e),this.$timeout=t||setTimeout.bind(x)}var t,r,n,i,a,o;return b(e,null,[{key:"getApiVersion",value:function(){return"20190520"}}]),b(e,[{key:"setJWTRequestHandler",value:function(e){this.jwtRequestHandler=e}},{key:"setAuthHeadersForRequest",value:(o=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.jwtRequestHandler();case 2:(r=e.sent)&&t.setRequestHeader("Authorization","Bearer "+r);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"postAbsolute",value:(a=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.httpRequest("post",t,r,n,i));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return a.apply(this,arguments)})},{key:"postAuthenticatedAbsolute",value:(i=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.httpRequest("post",t,r,n,i,!0));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return i.apply(this,arguments)})},{key:"patchAbsolute",value:(n=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.httpRequest("patch",t,r,n,i));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r,i){return n.apply(this,arguments)})},{key:"getAbsolute",value:(r=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.httpRequest("get",t,r,n,i));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"httpRequest",value:(t=v(regeneratorRuntime.mark((function e(t,r,n,i,a){var o,s=this,u=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=u.length>5&&void 0!==u[5]&&u[5],e.abrupt("return",new Promise(function(){var e=v(regeneratorRuntime.mark((function e(u,c){var l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((l=new XMLHttpRequest).onreadystatechange=function(){if(4==l.readyState){var e=l.responseText;if(e)try{e=JSON.parse(e)}catch(e){}l.status>=200&&l.status<=299?s.$timeout((function(){i(e),u(e)})):(console.error("Request error:",e),s.$timeout((function(){a(e,l.status),c(e)})))}},"get"==t&&Object.keys(n).length>0&&(r=s.urlForUrlAndParams(r,n)),l.open(t,r,!0),l.setRequestHeader("Content-type","application/json"),!o){e.next=8;break}return e.next=8,s.setAuthHeadersForRequest(l);case 8:"post"==t||"patch"==t?l.send(JSON.stringify(n)):l.send();case 9:case"end":return e.stop()}}),e)})));return function(t,r){return e.apply(this,arguments)}}()));case 2:case"end":return e.stop()}}),e)}))),function(e,r,n,i,a){return t.apply(this,arguments)})},{key:"urlForUrlAndParams",value:function(e,t){var r=Object.keys(t).map((function(e){return e+"="+encodeURIComponent(t[e])})).join("&");return e.includes("?")?e+"&"+r:e+"?"+r}}]),e}();n.SFHttpManager=S;var R=function(){function e(t,r,n,i){var a=this;g(this,e),this.modelManager=t,this.syncManager=r,this.storageManager=n,this.completionHandlers=[],this.loadMigrations();var o=!1,s=i.addEventHandler((function(e){e==w.DidSignInEvent&&(o=!0)}));this.receivedLocalDataEvent=r.initialDataLoaded(),this.syncManager.addEventHandler(function(){var e=v(regeneratorRuntime.mark((function e(t,r){var n,u,c,l,f,h,p,d,y;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u="sync:completed"==t,!(n="local-data-loaded"==t)&&!u){e.next=40;break}if(n?a.receivedLocalDataEvent=!0:u&&(a.receivedSyncCompletedEvent=!0),!a.receivedLocalDataEvent||!a.receivedSyncCompletedEvent){e.next=40;break}if(!o){e.next=39;break}return o=!1,i.removeEventHandler(s),e.next=10,a.getCompletedMigrations();case 10:c=e.sent.slice(),l=!0,f=!1,h=void 0,e.prev=14,p=c[Symbol.iterator]();case 16:if(l=(d=p.next()).done){e.next=25;break}return y=d.value,e.next=20,a.migrationForEncodedName(y);case 20:e.sent.runOnlyOnce||_.pull(a._completed,y);case 22:l=!0,e.next=16;break;case 25:e.next=31;break;case 27:e.prev=27,e.t0=e.catch(14),f=!0,h=e.t0;case 31:e.prev=31,e.prev=32,l||null==p.return||p.return();case 34:if(e.prev=34,!f){e.next=37;break}throw h;case 37:return e.finish(34);case 38:return e.finish(31);case 39:a.runPendingMigrations();case 40:case"end":return e.stop()}}),e,null,[[14,27,31,39],[32,,34,38]])})));return function(t,r){return e.apply(this,arguments)}}())}var t,r,n,i,a,o,s,u;return b(e,[{key:"addCompletionHandler",value:function(e){this.completionHandlers.push(e)}},{key:"removeCompletionHandler",value:function(e){_.pull(this.completionHandlers,e)}},{key:"migrationForEncodedName",value:(u=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.decode(t);case 2:return r=e.sent,e.abrupt("return",this.migrations.find((function(e){return e.name==r})));case 4:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})},{key:"loadMigrations",value:function(){this.migrations=this.registeredMigrations()}},{key:"registeredMigrations",value:function(){}},{key:"runPendingMigrations",value:(s=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,u,c,l,f,h,p,d,y,v,g,m,b,k,w,x,S,_,R,I,A,D;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getPendingMigrations();case 2:for(t=e.sent,r=!0,n=!1,i=void 0,e.prev=6,a=t[Symbol.iterator]();!(r=(o=a.next()).done);r=!0)(s=o.value).items=[];e.next=14;break;case 10:e.prev=10,e.t0=e.catch(6),n=!0,i=e.t0;case 14:e.prev=14,e.prev=15,r||null==a.return||a.return();case 17:if(e.prev=17,!n){e.next=20;break}throw i;case 20:return e.finish(17);case 21:return e.finish(14);case 22:u=!0,c=!1,l=void 0,e.prev=25,f=this.modelManager.allNondummyItems[Symbol.iterator]();case 27:if(u=(h=f.next()).done){e.next=51;break}for(p=h.value,d=!0,y=!1,v=void 0,e.prev=32,g=t[Symbol.iterator]();!(d=(m=g.next()).done);d=!0)s=m.value,p.content_type==s.content_type&&s.items.push(p);e.next=40;break;case 36:e.prev=36,e.t1=e.catch(32),y=!0,v=e.t1;case 40:e.prev=40,e.prev=41,d||null==g.return||g.return();case 43:if(e.prev=43,!y){e.next=46;break}throw v;case 46:return e.finish(43);case 47:return e.finish(40);case 48:u=!0,e.next=27;break;case 51:e.next=57;break;case 53:e.prev=53,e.t2=e.catch(25),c=!0,l=e.t2;case 57:e.prev=57,e.prev=58,u||null==f.return||f.return();case 60:if(e.prev=60,!c){e.next=63;break}throw l;case 63:return e.finish(60);case 64:return e.finish(57);case 65:b=!0,k=!1,w=void 0,e.prev=68,x=t[Symbol.iterator]();case 70:if(b=(S=x.next()).done){e.next=81;break}if(!((s=S.value).items&&s.items.length>0||s.customHandler)){e.next=77;break}return e.next=75,this.runMigration(s,s.items);case 75:e.next=78;break;case 77:this.markMigrationCompleted(s);case 78:b=!0,e.next=70;break;case 81:e.next=87;break;case 83:e.prev=83,e.t3=e.catch(68),k=!0,w=e.t3;case 87:e.prev=87,e.prev=88,b||null==x.return||x.return();case 90:if(e.prev=90,!k){e.next=93;break}throw w;case 93:return e.finish(90);case 94:return e.finish(87);case 95:for(_=!0,R=!1,I=void 0,e.prev=98,A=this.completionHandlers[Symbol.iterator]();!(_=(D=A.next()).done);_=!0)(0,D.value)();e.next=106;break;case 102:e.prev=102,e.t4=e.catch(98),R=!0,I=e.t4;case 106:e.prev=106,e.prev=107,_||null==A.return||A.return();case 109:if(e.prev=109,!R){e.next=112;break}throw I;case 112:return e.finish(109);case 113:return e.finish(106);case 114:case"end":return e.stop()}}),e,this,[[6,10,14,22],[15,,17,21],[25,53,57,65],[32,36,40,48],[41,,43,47],[58,,60,64],[68,83,87,95],[88,,90,94],[98,102,106,114],[107,,109,113]])}))),function(){return s.apply(this,arguments)})},{key:"encode",value:(o=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",window.btoa(t));case 1:case"end":return e.stop()}}),e)}))),function(e){return o.apply(this,arguments)})},{key:"decode",value:(a=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",window.atob(t));case 1:case"end":return e.stop()}}),e)}))),function(e){return a.apply(this,arguments)})},{key:"getCompletedMigrations",value:(i=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._completed){e.next=5;break}return e.next=3,this.storageManager.getItem("migrations");case 3:t=e.sent,this._completed=t?JSON.parse(t):[];case 5:return e.abrupt("return",this._completed);case 6:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"getPendingMigrations",value:(n=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getCompletedMigrations();case 2:t=e.sent,r=[],n=!0,i=!1,a=void 0,e.prev=7,o=this.migrations[Symbol.iterator]();case 9:if(n=(s=o.next()).done){e.next=22;break}return u=s.value,e.t0=t,e.next=14,this.encode(u.name);case 14:if(e.t1=e.sent,e.t2=e.t0.indexOf.call(e.t0,e.t1),e.t3=-1,e.t2!=e.t3){e.next=19;break}r.push(u);case 19:n=!0,e.next=9;break;case 22:e.next=28;break;case 24:e.prev=24,e.t4=e.catch(7),i=!0,a=e.t4;case 28:e.prev=28,e.prev=29,n||null==o.return||o.return();case 31:if(e.prev=31,!i){e.next=34;break}throw a;case 34:return e.finish(31);case 35:return e.finish(28);case 36:return e.abrupt("return",r);case 37:case"end":return e.stop()}}),e,this,[[7,24,28,36],[29,,31,35]])}))),function(){return n.apply(this,arguments)})},{key:"markMigrationCompleted",value:(r=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getCompletedMigrations();case 2:return r=e.sent,e.t0=r,e.next=6,this.encode(t.name);case 6:e.t1=e.sent,e.t0.push.call(e.t0,e.t1),this.storageManager.setItem("migrations",JSON.stringify(r)),t.running=!1;case 10:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"runMigration",value:(t=v(regeneratorRuntime.mark((function e(t,r){var n=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.running){e.next=2;break}return e.abrupt("return");case 2:if(console.log("Running migration:",t.name),t.running=!0,!t.customHandler){e.next=8;break}return e.abrupt("return",t.customHandler().then((function(){n.markMigrationCompleted(t)})));case 8:return e.abrupt("return",t.handler(r).then((function(){n.markMigrationCompleted(t)})));case 9:case"end":return e.stop()}}),e)}))),function(e,r){return t.apply(this,arguments)})}]),e}();n.SFMigrationManager=R;var I=function(){function e(t){g(this,e),e.MappingSourceRemoteRetrieved="MappingSourceRemoteRetrieved",e.MappingSourceRemoteSaved="MappingSourceRemoteSaved",e.MappingSourceLocalSaved="MappingSourceLocalSaved",e.MappingSourceLocalRetrieved="MappingSourceLocalRetrieved",e.MappingSourceLocalDirtied="MappingSourceLocalDirtied",e.MappingSourceComponentRetrieved="MappingSourceComponentRetrieved",e.MappingSourceDesktopInstalled="MappingSourceDesktopInstalled",e.MappingSourceRemoteActionRetrieved="MappingSourceRemoteActionRetrieved",e.MappingSourceFileImport="MappingSourceFileImport",e.isMappingSourceRetrieved=function(t){return[e.MappingSourceRemoteRetrieved,e.MappingSourceComponentRetrieved,e.MappingSourceRemoteActionRetrieved].includes(t)},this.$timeout=t||setTimeout.bind(window),this.itemSyncObservers=[],this.items=[],this.itemsHash={},this.missedReferences={},this.uuidChangeObservers=[]}var t,r,n,i,a,o,s,u,c,l,f,h;return b(e,[{key:"handleSignout",value:function(){this.items.length=0,this.itemsHash={},this.missedReferences={}}},{key:"addModelUuidChangeObserver",value:function(e,t){this.uuidChangeObservers.push({id:e,callback:t})}},{key:"notifyObserversOfUuidChange",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,o=this.uuidChangeObservers[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value;try{s.callback(e,t)}catch(e){console.error("Notify observers of uuid change exception:",e)}}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}},{key:"alternateUUIDForItem",value:(h=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.createItem(r),t.next=3,SFJS.crypto.generateUUID();case 3:for(n.uuid=t.sent,n.informReferencesOfUUIDChange(r.uuid,n.uuid),this.informModelsOfUUIDChangeForItem(n,r.uuid,n.uuid),i=!0,a=!1,o=void 0,t.prev=9,s=r.referencingObjects[Symbol.iterator]();!(i=(u=s.next()).done);i=!0)(c=u.value).setIsNoLongerBeingReferencedBy(r),r.setIsNoLongerBeingReferencedBy(c),c.addItemAsRelationship(n);t.next=17;break;case 13:t.prev=13,t.t0=t.catch(9),a=!0,o=t.t0;case 17:t.prev=17,t.prev=18,i||null==s.return||s.return();case 20:if(t.prev=20,!a){t.next=23;break}throw o;case 23:return t.finish(20);case 24:return t.finish(17);case 25:return this.setItemsDirty(r.referencingObjects,!0),this.resolveReferencesForItem(n),this.loggingEnabled&&console.log(r.uuid,"--\x3e",n.uuid),r.deleted=!0,r.content.references=[],this.setItemDirty(r,!1,!1,e.MappingSourceLocalSaved),t.next=33,this.mapResponseItemsToLocalModels([r],e.MappingSourceLocalSaved);case 33:return this.addItem(n),this.setItemDirty(n,!0,!0,e.MappingSourceLocalSaved),this.notifyObserversOfUuidChange(r,n),t.abrupt("return",n);case 37:case"end":return t.stop()}}),t,this,[[9,13,17,25],[18,,20,24]])}))),function(e){return h.apply(this,arguments)})},{key:"informModelsOfUUIDChangeForItem",value:function(e,t,r){var n=!0,i=!1,a=void 0;try{for(var o,s=this.items[Symbol.iterator]();!(n=(o=s.next()).done);n=!0)o.value.potentialItemOfInterestHasChangedItsUUID(e,t,r)}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}}},{key:"didSyncModelsOffline",value:function(t){this.notifySyncObserversOfModels(t,e.MappingSourceLocalSaved)}},{key:"mapResponseItemsToLocalModels",value:(f=v(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mapResponseItemsToLocalModelsWithOptions({items:t,source:r,sourceKey:n}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return f.apply(this,arguments)})},{key:"mapResponseItemsToLocalModelsOmittingFields",value:(l=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.mapResponseItemsToLocalModelsWithOptions({items:t,omitFields:r,source:n,sourceKey:i}));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return l.apply(this,arguments)})},{key:"mapResponseItemsToLocalModelsWithOptions",value:(c=v(regeneratorRuntime.mark((function e(t){var r,n,i,a,o,s,u,c,l,f,h,d,y,v,g,m,b,k,w,x,S,_,R,I,A,D,M,O,C,F,P,j,E,L,B,T,H,z,U;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=t.items,n=t.omitFields,i=t.source,a=t.sourceKey,t.options,o=[],s=[],u=[],c=!0,l=!1,f=void 0,e.prev=5,h=r[Symbol.iterator]();case 7:if(c=(d=h.next()).done){e.next=58;break}if(y=d.value){e.next=11;break}return e.abrupt("continue",55);case 11:if(v=!y.content&&!y.errorDecrypting,y.content_type&&y.uuid&&!v||y.deleted){e.next=16;break}return console.error("Server response item is corrupt:",y),e.abrupt("continue",55);case 16:if(!Array.isArray(n)){e.next=36;break}for(g=!0,m=!1,b=void 0,e.prev=20,k=n[Symbol.iterator]();!(g=(w=k.next()).done);g=!0)x=w.value,delete y[x];e.next=28;break;case 24:e.prev=24,e.t0=e.catch(20),m=!0,b=e.t0;case 28:e.prev=28,e.prev=29,g||null==k.return||k.return();case 31:if(e.prev=31,!m){e.next=34;break}throw b;case 34:return e.finish(31);case 35:return e.finish(28);case 36:if((S=this.findItem(y.uuid))&&(S.updateFromJSON(y),S.dummy=!1),_=y.content_type||S&&S.content_type,!this.acceptableContentTypes||this.acceptableContentTypes.includes(_)){e.next=42;break}return e.abrupt("continue",55);case 42:if(R=!1,1!=y.deleted){e.next=50;break}if(!y.dirty){e.next=48;break}R=!0,e.next=50;break;case 48:return S&&(o.push(S),u.push(S),this.removeItemLocally(S)),e.abrupt("continue",55);case 50:S||(S=this.createItem(y)),this.addItem(S,R),S.errorDecrypting||u.push(S),o.push(S),s.push(y);case 55:c=!0,e.next=7;break;case 58:e.next=64;break;case 60:e.prev=60,e.t1=e.catch(5),l=!0,f=e.t1;case 64:e.prev=64,e.prev=65,c||null==h.return||h.return();case 67:if(e.prev=67,!l){e.next=70;break}throw f;case 70:return e.finish(67);case 71:return e.finish(64);case 72:for(I=!0,A=!1,D=void 0,e.prev=75,M=s.entries()[Symbol.iterator]();!(I=(O=M.next()).done);I=!0)C=p(O.value,2),F=C[0],P=C[1],j=o[F],P.content&&this.resolveReferencesForItem(j),j.didFinishSyncing();e.next=83;break;case 79:e.prev=79,e.t2=e.catch(75),A=!0,D=e.t2;case 83:e.prev=83,e.prev=84,I||null==M.return||M.return();case 86:if(e.prev=86,!A){e.next=89;break}throw D;case 89:return e.finish(86);case 90:return e.finish(83);case 91:for(E=this.popMissedReferenceStructsForObjects(s),L=!0,B=!1,T=void 0,e.prev=95,H=function(){var e=U.value,t=o.find((function(t){return t.uuid==e.reference_uuid}));t&&e.for_item.addItemAsRelationship(t)},z=E[Symbol.iterator]();!(L=(U=z.next()).done);L=!0)H();e.next=104;break;case 100:e.prev=100,e.t3=e.catch(95),B=!0,T=e.t3;case 104:e.prev=104,e.prev=105,L||null==z.return||z.return();case 107:if(e.prev=107,!B){e.next=110;break}throw T;case 110:return e.finish(107);case 111:return e.finish(104);case 112:return e.next=114,this.notifySyncObserversOfModels(u,i,a);case 114:return e.abrupt("return",o);case 115:case"end":return e.stop()}}),e,this,[[5,60,64,72],[20,24,28,36],[29,,31,35],[65,,67,71],[75,79,83,91],[84,,86,90],[95,100,104,112],[105,,107,111]])}))),function(e){return c.apply(this,arguments)})},{key:"missedReferenceBuildKey",value:function(e,t){return"".concat(e,":").concat(t)}},{key:"popMissedReferenceStructsForObjects",value:function(e){if(!e||0==e.length)return[];for(var t=[],r=[],n=e.map((function(e){return e.uuid})),i=n[0].length,a=0,o=Object.keys(this.missedReferences);a<o.length;a++){var s=o[a];n.includes(s.substring(0,i))&&(t.push(this.missedReferences[s]),r.push(s))}for(var u=0,c=r;u<c.length;u++){var l=c[u];delete this.missedReferences[l]}return t}},{key:"resolveReferencesForItem",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e.errorDecrypting){var r=e.contentObject;if(e.updateLocalRelationships(),r.references){var n=r.references.slice().map((function(e){return e.uuid})),i=this.findItems(n,!0),a=!0,o=!1,s=void 0;try{for(var u,c=i.entries()[Symbol.iterator]();!(a=(u=c.next()).done);a=!0){var l=p(u.value,2),f=l[0],h=l[1];if(h)e.addItemAsRelationship(h),t&&this.setItemDirty(h,!0);else{var d=n[f],y=this.missedReferenceBuildKey(d,e.uuid);if(!this.missedReferences[y]){var v={reference_uuid:d,for_item:e};this.missedReferences[y]=v}}}}catch(e){o=!0,s=e}finally{try{a||null==c.return||c.return()}finally{if(o)throw s}}}}}},{key:"notifySyncObserversOfModels",value:(u=v(regeneratorRuntime.mark((function e(t,r,n){var i,a,o,s,u,c,l,f=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=this.itemSyncObservers.sort((function(e,t){return e.priority<t.priority?-1:1})),a=!0,o=!1,s=void 0,e.prev=4,u=regeneratorRuntime.mark((function e(){var i,a,o,s,u,c,h,p,d,y;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=l.value,a=i.types.includes("*")?t:t.filter((function(e){return i.types.includes(e.content_type)})),o=[],s=[],u=!0,c=!1,h=void 0,e.prev=6,p=a[Symbol.iterator]();!(u=(d=p.next()).done);u=!0)(y=d.value).deleted?s.push(y):o.push(y);e.next=14;break;case 10:e.prev=10,e.t0=e.catch(6),c=!0,h=e.t0;case 14:e.prev=14,e.prev=15,u||null==p.return||p.return();case 17:if(e.prev=17,!c){e.next=20;break}throw h;case 20:return e.finish(17);case 21:return e.finish(14);case 22:if(!(a.length>0)){e.next=25;break}return e.next=25,f._callSyncObserverCallbackWithTimeout(i,a,o,s,r,n);case 25:case"end":return e.stop()}}),e,null,[[6,10,14,22],[15,,17,21]])})),c=i[Symbol.iterator]();case 7:if(a=(l=c.next()).done){e.next=12;break}return e.delegateYield(u(),"t0",9);case 9:a=!0,e.next=7;break;case 12:e.next=18;break;case 14:e.prev=14,e.t1=e.catch(4),o=!0,s=e.t1;case 18:e.prev=18,e.prev=19,a||null==c.return||c.return();case 21:if(e.prev=21,!o){e.next=24;break}throw s;case 24:return e.finish(21);case 25:return e.finish(18);case 26:case"end":return e.stop()}}),e,this,[[4,14,18,26],[19,,21,25]])}))),function(e,t,r){return u.apply(this,arguments)})},{key:"_callSyncObserverCallbackWithTimeout",value:(s=v(regeneratorRuntime.mark((function e(t,r,n,i,a,o){var s=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,u){s.$timeout((function(){try{t.callback(r,n,i,a,o)}catch(e){console.error("Sync observer exception",e)}finally{e()}}))})));case 1:case"end":return e.stop()}}),e)}))),function(e,t,r,n,i,a){return s.apply(this,arguments)})},{key:"setItemDirty",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2?arguments[2]:void 0,n=arguments.length>3?arguments[3]:void 0,i=arguments.length>4?arguments[4]:void 0;this.setItemsDirty([e],t,r,n,i)}},{key:"setItemsDirty",value:function(t){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=arguments.length>2?arguments[2]:void 0,i=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0,o=!0,s=!1,u=void 0;try{for(var c,l=t[Symbol.iterator]();!(o=(c=l.next()).done);o=!0)c.value.setDirty(r,n)}catch(e){s=!0,u=e}finally{try{o||null==l.return||l.return()}finally{if(s)throw u}}this.notifySyncObserversOfModels(t,i||e.MappingSourceLocalDirtied,a)}},{key:"createItem",value:function(t){var r=e.ContentTypeClassMapping&&e.ContentTypeClassMapping[t.content_type];return r||(r=P),new r(t)}},{key:"createDuplicateItemFromResponseItem",value:(o=v(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("function"!=typeof t.setDirty){e.next=3;break}return console.error("Attempting to create conflicted copy of non-response item."),e.abrupt("return",null);case 3:return r=JSON.parse(JSON.stringify(t)),e.next=6,SFJS.crypto.generateUUID();case 6:return r.uuid=e.sent,n=this.createItem(r),e.abrupt("return",n);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"duplicateItemAndAddAsConflict",value:function(e){return this.duplicateItemWithCustomContentAndAddAsConflict({content:e.content,duplicateOf:e})}},{key:"duplicateItemWithCustomContentAndAddAsConflict",value:function(e){var t=e.content,r=e.duplicateOf,n=this.duplicateItemWithCustomContent({content:t,duplicateOf:r});return this.addDuplicatedItemAsConflict({duplicate:n,duplicateOf:r}),n}},{key:"addDuplicatedItemAsConflict",value:function(e){var t=e.duplicate,r=e.duplicateOf;this.addDuplicatedItem(t,r),t.content.conflict_of=r.uuid}},{key:"duplicateItemWithCustomContent",value:function(e){var t=e.content,r=e.duplicateOf,n=new r.constructor({content:t});return n.created_at=r.created_at,n.content_type||(n.content_type=r.content_type),n}},{key:"duplicateItemAndAdd",value:function(e){var t=this.duplicateItemWithoutAdding(e);return this.addDuplicatedItem(t,e),t}},{key:"duplicateItemWithoutAdding",value:function(e){var t=new e.constructor({content:e.content});return t.created_at=e.created_at,t.content_type||(t.content_type=e.content_type),t}},{key:"addDuplicatedItem",value:function(e,t){this.addItem(e);var r=!0,n=!1,i=void 0;try{for(var a,o=t.referencingObjects[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value;s.addItemAsRelationship(e),this.setItemDirty(s,!0)}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}this.resolveReferencesForItem(e),this.setItemDirty(e,!0)}},{key:"addItem",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.addItems([e],t)}},{key:"addItems",value:function(e){var t=this;e.forEach((function(e){t.itemsHash[e.uuid]||(t.itemsHash[e.uuid]=e,t.items.push(e))}))}},{key:"addItemSyncObserver",value:function(e,t,r){this.addItemSyncObserverWithPriority({id:e,types:t,callback:r,priority:1})}},{key:"addItemSyncObserverWithPriority",value:function(e){var t=e.id,r=e.priority,n=e.types,i=e.callback;Array.isArray(n)||(n=[n]),this.itemSyncObservers.push({id:t,types:n,priority:r,callback:i})}},{key:"removeItemSyncObserver",value:function(e){_.remove(this.itemSyncObservers,_.find(this.itemSyncObservers,{id:e}))}},{key:"getDirtyItems",value:function(){return this.items.filter((function(e){return 1==e.dirty&&!e.dummy&&(!e.errorDecrypting||e.deleted)}))}},{key:"clearDirtyItems",value:function(e){var t=!0,r=!1,n=void 0;try{for(var i,a=e[Symbol.iterator]();!(t=(i=a.next()).done);t=!0)i.value.setDirty(!1)}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}},{key:"removeAndDirtyAllRelationshipsForItem",value:function(e){if(!e.errorDecrypting){var t=!0,r=!1,n=void 0;try{for(var i,a=e.content.references[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var o=i.value,s=this.findItem(o.uuid);s&&(e.removeItemAsRelationship(s),s.hasRelationshipWithItem(e)&&(s.removeItemAsRelationship(e),this.setItemDirty(s,!0)))}}catch(e){r=!0,n=e}finally{try{t||null==a.return||a.return()}finally{if(r)throw n}}}var u=!0,c=!1,l=void 0;try{for(var f,h=e.referencingObjects[Symbol.iterator]();!(u=(f=h.next()).done);u=!0){var p=f.value;p.removeItemAsRelationship(e),this.setItemDirty(p,!0)}}catch(e){c=!0,l=e}finally{try{u||null==h.return||h.return()}finally{if(c)throw l}}e.referencingObjects=[]}},{key:"setAllItemsDirty",value:function(){var e=this.allItems;this.setItemsDirty(e,!0)}},{key:"setItemToBeDeleted",value:function(e){e.deleted=!0,e.dummy||this.setItemDirty(e,!0),this.removeAndDirtyAllRelationshipsForItem(e)}},{key:"removeItemLocally",value:(a=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:_.remove(this.items,{uuid:t.uuid}),delete this.itemsHash[t.uuid],t.isBeingRemovedLocally();case 3:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"allItemsMatchingTypes",value:function(e){return this.allItems.filter((function(t){return(_.includes(e,t.content_type)||_.includes(e,"*"))&&!t.dummy}))}},{key:"invalidItems",value:function(){return this.allItems.filter((function(e){return e.errorDecrypting}))}},{key:"validItemsForContentType",value:function(e){return this.allItems.filter((function(t){return t.content_type==e&&!t.errorDecrypting}))}},{key:"findItem",value:function(e){return this.itemsHash[e]}},{key:"findItems",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=[],n=!0,i=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var u=o.value,c=this.itemsHash[u];(c||t)&&r.push(c)}}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return r}},{key:"itemsMatchingPredicate",value:function(e){return this.itemsMatchingPredicates([e])}},{key:"itemsMatchingPredicates",value:function(e){return this.filterItemsWithPredicates(this.allItems,e)}},{key:"filterItemsWithPredicates",value:function(e,t){return e.filter((function(e){var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value;if(!e.satisfiesPredicate(s))return!1}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return!0}))}},{key:"importItems",value:(i=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c,l,f,h,p,d,y,v,g,m,b,k,w,x,S,_,R,I,A,D,M;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n=[],i={},a=!0,o=!1,s=void 0,t.prev=5,u=r[Symbol.iterator]();case 7:if(a=(c=u.next()).done){t.next=18;break}if(l=c.value,f=this.findItem(l.uuid)){t.next=13;break}return i[l.uuid]={},t.abrupt("continue",15);case 13:h=this.duplicateItemWithoutAdding(f),i[l.uuid]={frozenValue:h,itemRef:f};case 15:a=!0,t.next=7;break;case 18:t.next=24;break;case 20:t.prev=20,t.t0=t.catch(5),o=!0,s=t.t0;case 24:t.prev=24,t.prev=25,a||null==u.return||u.return();case 27:if(t.prev=27,!o){t.next=30;break}throw s;case 30:return t.finish(27);case 31:return t.finish(24);case 32:p=!0,d=!1,y=void 0,t.prev=35,v=r[Symbol.iterator]();case 37:if(p=(g=v.next()).done){t.next=52;break}if(m=g.value,b=i[m.uuid],k=b.frozenValue,w=b.itemRef,!k||w.errorDecrypting){t.next=47;break}return t.next=43,this.createDuplicateItemFromResponseItem(m);case 43:x=t.sent,m.deleted||k.isItemContentEqualWith(x)||(this.addDuplicatedItemAsConflict({duplicate:x,duplicateOf:w}),n.push(x)),t.next=49;break;case 47:n.push(m),w&&w.errorDecrypting&&(w.errorDecrypting=!1);case 49:p=!0,t.next=37;break;case 52:t.next=58;break;case 54:t.prev=54,t.t1=t.catch(35),d=!0,y=t.t1;case 58:t.prev=58,t.prev=59,p||null==v.return||v.return();case 61:if(t.prev=61,!d){t.next=64;break}throw y;case 64:return t.finish(61);case 65:return t.finish(58);case 66:return t.next=68,this.mapResponseItemsToLocalModels(n,e.MappingSourceFileImport);case 68:for(S=t.sent,_=!0,R=!1,I=void 0,t.prev=72,A=S[Symbol.iterator]();!(_=(D=A.next()).done);_=!0)M=D.value,this.setItemDirty(M,!0,!1),M.deleted=!1;t.next=80;break;case 76:t.prev=76,t.t2=t.catch(72),R=!0,I=t.t2;case 80:t.prev=80,t.prev=81,_||null==A.return||A.return();case 83:if(t.prev=83,!R){t.next=86;break}throw I;case 86:return t.finish(83);case 87:return t.finish(80);case 88:return t.abrupt("return",S);case 89:case"end":return t.stop()}}),t,this,[[5,20,24,32],[25,,27,31],[35,54,58,66],[59,,61,65],[72,76,80,88],[81,,83,87]])}))),function(e){return i.apply(this,arguments)})},{key:"getAllItemsJSONData",value:(n=v(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.getJSONDataForItems(this.allItems,t,r,n));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"getJSONDataForItems",value:(r=v(regeneratorRuntime.mark((function e(t,r,n,i){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Promise.all(t.map((function(e){return new j(e,r,n).paramsForExportFile()}))).then((function(e){if(i&&0==e.length)return null;var t={items:e};return r&&(t.auth_params=n),JSON.stringify(t,null,2)})));case 1:case"end":return e.stop()}}),e)}))),function(e,t,n,i){return r.apply(this,arguments)})},{key:"computeDataIntegrityHash",value:(t=v(regeneratorRuntime.mark((function e(){var t,r,n,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t=this.allNondummyItems.sort((function(e,t){return t.updated_at-e.updated_at})),r=t.map((function(e){return e.updatedAtTimestamp()})),n=r.join(","),e.next=6,SFJS.crypto.sha256(n);case 6:return i=e.sent,e.abrupt("return",i);case 10:return e.prev=10,e.t0=e.catch(0),console.error("Error computing data integrity hash",e.t0),e.abrupt("return",null);case 14:case"end":return e.stop()}}),e,this,[[0,10]])}))),function(){return t.apply(this,arguments)})},{key:"allItems",get:function(){return this.items.slice()}},{key:"allNondummyItems",get:function(){return this.items.filter((function(e){return!e.dummy}))}}]),e}();n.SFModelManager=I;var A=function(){function e(t,r,n){g(this,e),this.modelManager=t,this.syncManager=r,this.singletonManager=n,this.loadPrivileges(),e.CredentialAccountPassword="CredentialAccountPassword",e.CredentialLocalPasscode="CredentialLocalPasscode",e.ActionManageExtensions="ActionManageExtensions",e.ActionManageBackups="ActionManageBackups",e.ActionViewProtectedNotes="ActionViewProtectedNotes",e.ActionManagePrivileges="ActionManagePrivileges",e.ActionManagePasscode="ActionManagePasscode",e.ActionDeleteNote="ActionDeleteNote",e.SessionExpiresAtKey="SessionExpiresAtKey",e.SessionLengthKey="SessionLengthKey",e.SessionLengthNone=0,e.SessionLengthFiveMinutes=300,e.SessionLengthOneHour=3600,e.SessionLengthOneWeek=604800,this.availableActions=[e.ActionViewProtectedNotes,e.ActionDeleteNote,e.ActionManagePasscode,e.ActionManageBackups,e.ActionManageExtensions,e.ActionManagePrivileges],this.availableCredentials=[e.CredentialAccountPassword,e.CredentialLocalPasscode],this.sessionLengths=[e.SessionLengthNone,e.SessionLengthFiveMinutes,e.SessionLengthOneHour,e.SessionLengthOneWeek,e.SessionLengthIndefinite]}var t,r,n,i,a,o,s,u,c,l,f,h;return b(e,[{key:"setDelegate",value:function(e){this.delegate=e}},{key:"getAvailableActions",value:function(){return this.availableActions}},{key:"getAvailableCredentials",value:function(){return this.availableCredentials}},{key:"netCredentialsForAction",value:(h=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c,l;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPrivileges();case 2:t.t0=r,n=t.sent.getCredentialsForAction(t.t0),i=[],a=!0,o=!1,s=void 0,t.prev=8,u=n[Symbol.iterator]();case 10:if(a=(c=u.next()).done){t.next=27;break}if((l=c.value)!=e.CredentialAccountPassword){t.next=19;break}return t.next=15,this.delegate.isOffline();case 15:t.sent||i.push(l),t.next=24;break;case 19:if(l!=e.CredentialLocalPasscode){t.next=24;break}return t.next=22,this.delegate.hasLocalPasscode();case 22:t.sent&&i.push(l);case 24:a=!0,t.next=10;break;case 27:t.next=33;break;case 29:t.prev=29,t.t1=t.catch(8),o=!0,s=t.t1;case 33:t.prev=33,t.prev=34,a||null==u.return||u.return();case 36:if(t.prev=36,!o){t.next=39;break}throw s;case 39:return t.finish(36);case 40:return t.finish(33);case 41:return t.abrupt("return",i);case 42:case"end":return t.stop()}}),t,this,[[8,29,33,41],[34,,36,40]])}))),function(e){return h.apply(this,arguments)})},{key:"loadPrivileges",value:(f=v(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.loadPromise){e.next=2;break}return e.abrupt("return",this.loadPromise);case 2:return this.loadPromise=new Promise((function(e,r){var n=L.contentType(),i=new E("content_type","=",n);t.singletonManager.registerSingleton([i],(function(r){t.privileges=r,e(r)}),function(){var r=v(regeneratorRuntime.mark((function r(i){var a;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(a=new L({content_type:n}),SFJS.crypto.generateUUIDSync){r.next=4;break}return r.next=4,a.initUUID();case 4:t.modelManager.addItem(a),t.modelManager.setItemDirty(a,!0),t.syncManager.sync(),i(a),e(a);case 9:case"end":return r.stop()}}),r)})));return function(e){return r.apply(this,arguments)}}())})),e.abrupt("return",this.loadPromise);case 4:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"getPrivileges",value:(l=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.privileges){e.next=4;break}return e.abrupt("return",this.privileges);case 4:return e.abrupt("return",this.loadPrivileges());case 5:case"end":return e.stop()}}),e,this)}))),function(){return l.apply(this,arguments)})},{key:"displayInfoForCredential",value:function(t){var r={};return r[e.CredentialAccountPassword]={label:"Account Password",prompt:"Please enter your account password."},r[e.CredentialLocalPasscode]={label:"Local Passcode",prompt:"Please enter your local passcode."},r[t]}},{key:"displayInfoForAction",value:function(t){var r={};return r[e.ActionManageExtensions]={label:"Manage Extensions"},r[e.ActionManageBackups]={label:"Download/Import Backups"},r[e.ActionViewProtectedNotes]={label:"View Protected Notes"},r[e.ActionManagePrivileges]={label:"Manage Privileges"},r[e.ActionManagePasscode]={label:"Manage Passcode"},r[e.ActionDeleteNote]={label:"Delete Notes"},r[t]}},{key:"getSessionLengthOptions",value:function(){return[{value:e.SessionLengthNone,label:"Don't Remember"},{value:e.SessionLengthFiveMinutes,label:"5 Minutes"},{value:e.SessionLengthOneHour,label:"1 Hour"},{value:e.SessionLengthOneWeek,label:"1 Week"}]}},{key:"setSessionLength",value:(c=v(regeneratorRuntime.mark((function t(r){var n;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=r,a=void 0,(a=new Date).setSeconds(a.getSeconds()+i),n=a,t.abrupt("return",Promise.all([this.delegate.saveToStorage(e.SessionExpiresAtKey,JSON.stringify(n)),this.delegate.saveToStorage(e.SessionLengthKey,JSON.stringify(r))]));case 3:case"end":return t.stop()}var i,a}),t,this)}))),function(e){return c.apply(this,arguments)})},{key:"clearSession",value:(u=v(regeneratorRuntime.mark((function t(){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.setSessionLength(e.SessionLengthNone));case 1:case"end":return t.stop()}}),t,this)}))),function(){return u.apply(this,arguments)})},{key:"getSelectedSessionLength",value:(s=v(regeneratorRuntime.mark((function t(){var r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.delegate.getFromStorage(e.SessionLengthKey);case 2:if(!(r=t.sent)){t.next=7;break}return t.abrupt("return",JSON.parse(r));case 7:return t.abrupt("return",e.SessionLengthNone);case 8:case"end":return t.stop()}}),t,this)}))),function(){return s.apply(this,arguments)})},{key:"getSessionExpirey",value:(o=v(regeneratorRuntime.mark((function t(){var r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.delegate.getFromStorage(e.SessionExpiresAtKey);case 2:if(!(r=t.sent)){t.next=7;break}return t.abrupt("return",new Date(JSON.parse(r)));case 7:return t.abrupt("return",new Date);case 8:case"end":return t.stop()}}),t,this)}))),function(){return o.apply(this,arguments)})},{key:"actionHasPrivilegesConfigured",value:(a=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.netCredentialsForAction(t);case 2:return e.t0=e.sent.length,e.abrupt("return",e.t0>0);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"actionRequiresPrivilege",value:(i=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSessionExpirey();case 2:if(!(e.sent>new Date)){e.next=5;break}return e.abrupt("return",!1);case 5:return e.next=7,this.netCredentialsForAction(t);case 7:return r=e.sent,e.abrupt("return",r.length>0);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"savePrivileges",value:(n=v(regeneratorRuntime.mark((function e(){var t;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getPrivileges();case 2:t=e.sent,this.modelManager.setItemDirty(t,!0),this.syncManager.sync();case 5:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"authenticateAction",value:(r=v(regeneratorRuntime.mark((function e(t,r){var n,i,a,o,s,u,c,l,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.netCredentialsForAction(t);case 2:n=e.sent,i=[],a=[],o=!0,s=!1,u=void 0,e.prev=7,c=n[Symbol.iterator]();case 9:if(o=(l=c.next()).done){e.next=18;break}return f=l.value,e.next=13,this._verifyAuthenticationParameters(f,r[f]);case 13:e.sent?i.push(f):a.push(f);case 15:o=!0,e.next=9;break;case 18:e.next=24;break;case 20:e.prev=20,e.t0=e.catch(7),s=!0,u=e.t0;case 24:e.prev=24,e.prev=25,o||null==c.return||c.return();case 27:if(e.prev=27,!s){e.next=30;break}throw u;case 30:return e.finish(27);case 31:return e.finish(24);case 32:return e.abrupt("return",{success:0==a.length,successfulCredentials:i,failedCredentials:a});case 33:case"end":return e.stop()}}),e,this,[[7,20,24,32],[25,,27,31]])}))),function(e,t){return r.apply(this,arguments)})},{key:"_verifyAuthenticationParameters",value:(t=v(regeneratorRuntime.mark((function t(r,n){var i,a,o=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(i=function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",o.delegate.verifyAccountPassword(t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),a=function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",o.delegate.verifyLocalPasscode(t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),r!=e.CredentialAccountPassword){t.next=6;break}return t.abrupt("return",i(n));case 6:if(r!=e.CredentialLocalPasscode){t.next=8;break}return t.abrupt("return",a(n));case 8:case"end":return t.stop()}}),t)}))),function(e,r){return t.apply(this,arguments)})}]),e}();n.SFPrivilegesManager=A;var D=function(){function e(t,r,n,i,a){var o=this;g(this,e),this.modelManager=t,this.storageManager=r,this.$timeout=a||setTimeout.bind(window),this.keyRequestHandler=n,this.loadFromDisk().then((function(){o.modelManager.addItemSyncObserver("session-history",i,(function(e,t,r,n,i){if(n!==I.MappingSourceLocalDirtied){var a=!0,s=!1,u=void 0;try{for(var c,l=e[Symbol.iterator]();!(a=(c=l.next()).done);a=!0){var f=c.value;try{o.addHistoryEntryForItem(f)}catch(e){console.log("Caught exception while trying to add item history entry",e)}}}catch(e){s=!0,u=e}finally{try{a||null==l.return||l.return()}finally{if(s)throw u}}}}))}))}var t,r,n,i,a,o,s;return b(e,[{key:"encryptionParams",value:(s=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.keyRequestHandler());case 1:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"addHistoryEntryForItem",value:function(e){var t=this,r={uuid:e.uuid,content_type:e.content_type,updated_at:e.updated_at,content:e.getContentCopy()},n=this.historySession.addEntryForItem(r);this.autoOptimize&&this.historySession.optimizeHistoryForItem(e),n&&this.diskEnabled&&(this.diskTimeout&&(this.$timeout.hasOwnProperty("cancel")?this.$timeout.cancel(this.diskTimeout):clearTimeout(this.diskTimeout)),this.diskTimeout=this.$timeout((function(){t.saveToDisk()}),2e3))}},{key:"historyForItem",value:function(e){return this.historySession.historyForItem(e)}},{key:"clearHistoryForItem",value:(o=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.historySession.clearItemHistory(t),e.abrupt("return",this.saveToDisk());case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"clearAllHistory",value:(a=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.historySession.clearAllHistory(),e.abrupt("return",this.storageManager.removeItem("sessionHistory_revisions"));case 2:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"toggleDiskSaving",value:(i=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.diskEnabled=!this.diskEnabled,!this.diskEnabled){e.next=6;break}this.storageManager.setItem("sessionHistory_persist",JSON.stringify(!0)),this.saveToDisk(),e.next=8;break;case 6:return this.storageManager.setItem("sessionHistory_persist",JSON.stringify(!1)),e.abrupt("return",this.storageManager.removeItem("sessionHistory_revisions"));case 8:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"saveToDisk",value:(n=v(regeneratorRuntime.mark((function e(){var t,r=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.diskEnabled){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,this.encryptionParams();case 4:t=e.sent,new j(this.historySession,t.keys,t.auth_params).paramsForSync().then((function(e){r.storageManager.setItem("sessionHistory_revisions",JSON.stringify(e))}));case 7:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"loadFromDisk",value:(r=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.storageManager.getItem("sessionHistory_persist");case 2:return(t=e.sent)&&(this.diskEnabled=JSON.parse(t)),e.next=6,this.storageManager.getItem("sessionHistory_revisions");case 6:if(!(r=e.sent)){e.next=18;break}return r=JSON.parse(r),e.next=11,this.encryptionParams();case 11:return n=e.sent,e.next=14,SFJS.itemTransformer.decryptItem(r,n.keys);case 14:i=new B(r),this.historySession=i,e.next=19;break;case 18:this.historySession=new B;case 19:return e.next=21,this.storageManager.getItem("sessionHistory_autoOptimize");case 21:a=e.sent,this.autoOptimize=!a||JSON.parse(a);case 23:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"toggleAutoOptimize",value:(t=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this.autoOptimize=!this.autoOptimize,this.autoOptimize?this.storageManager.setItem("sessionHistory_autoOptimize",JSON.stringify(!0)):this.storageManager.setItem("sessionHistory_autoOptimize",JSON.stringify(!1));case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();n.SFSessionHistoryManager=D;var M=function(){function e(t,r){var n=this;g(this,e),this.syncManager=r,this.modelManager=t,this.singletonHandlers=[],t.addItemSyncObserverWithPriority({id:"sf-singleton-manager",types:"*",priority:-1,callback:function(e,r,i,a,o){a!==I.MappingSourceLocalDirtied&&n.resolveSingletons(t.allNondummyItems,null,!0)}}),r.addEventHandler((function(e,r){if("local-data-loaded"==e)n.resolveSingletons(t.allNondummyItems,null,!0),n.initialDataLoaded=!0;else if("sync:completed"==e){if(!n.initialDataLoaded)return;n.resolveSingletons(r.retrievedItems,r.savedItems)}})),t.addModelUuidChangeObserver("singleton-manager",(function(e,t){var r=!0,i=!1,a=void 0;try{for(var o,s=n.singletonHandlers[Symbol.iterator]();!(r=(o=s.next()).done);r=!0){var u=o.value;u.singleton&&E.ItemSatisfiesPredicates(t,u.predicates)&&(u.singleton=null,n.resolveSingletons([t]))}}catch(e){i=!0,a=e}finally{try{r||null==s.return||s.return()}finally{if(i)throw a}}}))}return b(e,[{key:"registerSingleton",value:function(e,t,r){this.singletonHandlers.push({predicates:e,resolutionCallback:t,createBlock:r})}},{key:"resolveSingletons",value:function(e,t,r){var n=this;e=e||[],t=t||[];var i=!0,a=!1,o=void 0;try{for(var s,u=function(){var i=s.value,a=i.predicates.slice(),o=n.modelManager.filterItemsWithPredicates(e,a),u=function(){i.createBlock&&(i.pendingCreateBlockCallback=!0,i.createBlock((function(e){i.singleton=e,i.pendingCreateBlockCallback=!1,i.resolutionCallback&&i.resolutionCallback(e)})))},c=n.modelManager.filterItemsWithPredicates(t,a).length;if(o.length>0||c>0){var l=n.modelManager.itemsMatchingPredicates(a);if(l.length>=2){var f=l.sort((function(e,t){return e.errorDecrypting?1:t.errorDecrypting||e.created_at<t.created_at?-1:1})),h=f[0],p=f.slice(1,f.length),d=!0,y=!1,v=void 0;try{for(var g,m=p[Symbol.iterator]();!(d=(g=m.next()).done);d=!0){var b=g.value;n.modelManager.setItemToBeDeleted(b)}}catch(e){y=!0,v=e}finally{try{d||null==m.return||m.return()}finally{if(y)throw v}}n.syncManager.sync(),i.singleton=h,i.resolutionCallback&&i.resolutionCallback(h)}else if(1==l.length){var k=l[0];k.errorDecrypting?(n.modelManager.setItemToBeDeleted(k),u()):i.singleton&&i.singleton===k||(i.singleton=k,i.resolutionCallback&&i.resolutionCallback(k))}}else i.singleton||r||i.pendingCreateBlockCallback||u()},c=this.singletonHandlers[Symbol.iterator]();!(i=(s=c.next()).done);i=!0)u()}catch(e){a=!0,o=e}finally{try{i||null==c.return||c.return()}finally{if(a)throw o}}}}]),e}();n.SFSingletonManager=M;var O=function(){function e(){g(this,e)}var t,r,n,i,a,o,s,u,c,l;return b(e,[{key:"setItem",value:(l=v(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e,t){return l.apply(this,arguments)})},{key:"getItem",value:(c=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"removeItem",value:(u=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return u.apply(this,arguments)})},{key:"clear",value:(s=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(){return s.apply(this,arguments)})},{key:"getAllModels",value:(o=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(){return o.apply(this,arguments)})},{key:"saveModel",value:(a=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.saveModels([t]));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"saveModels",value:(i=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return i.apply(this,arguments)})},{key:"deleteModel",value:(n=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(e){return n.apply(this,arguments)})},{key:"clearAllModels",value:(r=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}}),e)}))),function(){return r.apply(this,arguments)})},{key:"clearAllData",value:(t=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Promise.all([this.clear(),this.clearAllModels()]));case 1:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();n.SFStorageManager=O;var C,F=function(){function e(t,r,n,i,a){g(this,e),e.KeyRequestLoadLocal="KeyRequestLoadLocal",e.KeyRequestSaveLocal="KeyRequestSaveLocal",e.KeyRequestLoadSaveAccount="KeyRequestLoadSaveAccount",this.httpManager=n,this.modelManager=t,this.storageManager=r,this.$interval=a||setInterval.bind(window),this.$timeout=i||setTimeout.bind(window),this.syncStatus={},this.syncStatusObservers=[],this.eventHandlers=[],this.PerSyncItemUploadLimit=150,this.ServerItemDownloadLimit=150,this.MajorDataChangeThreshold=15,this.MaxDiscordanceBeforeOutOfSync=5,this.syncDiscordance=0,this.outOfSync=!1}var t,r,n,i,a,o,s,u,c,l,f,h,p,d,y,m,k,w,x,R,A,D,M;return b(e,[{key:"handleServerIntegrityHash",value:(M=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t&&0!=t.length){e.next=2;break}return e.abrupt("return",!0);case 2:return e.next=4,this.modelManager.computeDataIntegrityHash();case 4:if(r=e.sent){e.next=7;break}return e.abrupt("return",!0);case 7:if(r===t){e.next=13;break}return this.syncDiscordance++,this.syncDiscordance>=this.MaxDiscordanceBeforeOutOfSync&&(this.outOfSync||(this.outOfSync=!0,this.notifyEvent("enter-out-of-sync"))),e.abrupt("return",!1);case 13:return this.outOfSync&&(this.outOfSync=!1,this.notifyEvent("exit-out-of-sync")),this.syncDiscordance=0,e.abrupt("return",!0);case 16:case"end":return e.stop()}}),e,this)}))),function(e){return M.apply(this,arguments)})},{key:"isOutOfSync",value:function(){return this.outOfSync}},{key:"getServerURL",value:(D=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.storageManager.getItem("server");case 2:if(e.t0=e.sent,e.t0){e.next=5;break}e.t0=window._default_sf_server;case 5:return e.abrupt("return",e.t0);case 6:case"end":return e.stop()}}),e,this)}))),function(){return D.apply(this,arguments)})},{key:"getSyncURL",value:(A=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getServerURL();case 2:return e.t0=e.sent,e.abrupt("return",e.t0+"/items/sync");case 4:case"end":return e.stop()}}),e,this)}))),function(){return A.apply(this,arguments)})},{key:"registerSyncStatusObserver",value:function(e){var t={key:new Date,callback:e};return this.syncStatusObservers.push(t),t}},{key:"removeSyncStatusObserver",value:function(e){_.pull(this.syncStatusObservers,e)}},{key:"syncStatusDidChange",value:function(){var e=this;this.syncStatusObservers.forEach((function(t){t.callback(e.syncStatus)}))}},{key:"addEventHandler",value:function(e){return this.eventHandlers.push(e),e}},{key:"removeEventHandler",value:function(e){_.pull(this.eventHandlers,e)}},{key:"notifyEvent",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,o=this.eventHandlers[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)(0,a.value)(e,t||{})}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}},{key:"setKeyRequestHandler",value:function(e){this.keyRequestHandler=e}},{key:"getActiveKeyInfo",value:(R=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.keyRequestHandler(t));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return R.apply(this,arguments)})},{key:"initialDataLoaded",value:function(){return!0===this._initialDataLoaded}},{key:"_sortLocalItems",value:function(e){var t=this;return e.sort((function(e,r){var n=new Date(r.updated_at)-new Date(e.updated_at),i=t.contentTypeLoadPriority,a=0,o=0;return i&&(a=i.indexOf(e.content_type),o=i.indexOf(r.content_type),-1==a&&(a=i.length),-1==o&&(o=i.length)),a==o?n:a<o?-1:1}))}},{key:"loadLocalItems",value:(x=v(regeneratorRuntime.mark((function t(){var r,n,i,a,o,s=this,u=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=(r=u.length>0&&void 0!==u[0]?u[0]:{}).incrementalCallback,i=r.batchSize,!(a=r.options)||!a.simulateHighLatency){t.next=5;break}return o=a.simulatedLatency||1e3,t.next=5,this._awaitSleep(o);case 5:if(!this.loadLocalDataPromise){t.next=7;break}return t.abrupt("return",this.loadLocalDataPromise);case 7:return i||(i=100),this.loadLocalDataPromise=this.storageManager.getAllModels().then((function(t){var r=(t=(t=s._sortLocalItems(t)).filter((function(e){var t=s.modelManager.findItem(e.uuid);return!t||new Date(e.dirtiedDate)>t.dirtiedDate}))).length,a=0,o=[],u=function(){var c=v(regeneratorRuntime.mark((function c(){var l,f;return regeneratorRuntime.wrap((function(c){for(;;)switch(c.prev=c.next){case 0:return l=t.slice(a,a+i),c.next=3,s.handleItemsResponse(l,null,I.MappingSourceLocalRetrieved,e.KeyRequestLoadLocal);case 3:if(f=c.sent,o.push(f),!((a+=l.length)<r)){c.next=10;break}return c.abrupt("return",new Promise((function(e,t){s.$timeout((function(){s.notifyEvent("local-data-incremental-load"),n&&n(a,r),u().then(e)}))})));case 10:s._initialDataLoaded=!0,s.notifyEvent("local-data-loaded");case 12:case"end":return c.stop()}}),c)})));return function(){return c.apply(this,arguments)}}();return u()})),t.abrupt("return",this.loadLocalDataPromise);case 10:case"end":return t.stop()}}),t,this)}))),function(){return x.apply(this,arguments)})},{key:"writeItemsToLocalStorage",value:(w=v(regeneratorRuntime.mark((function t(r,n){var i=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(0!=r.length){t.next=2;break}return t.abrupt("return");case 2:return t.abrupt("return",new Promise(function(){var t=v(regeneratorRuntime.mark((function t(a,o){var s,u,c,l,f,h,p,d,y,g;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(s=[],u=[],c=!0,l=!1,f=void 0,t.prev=4,h=r[Symbol.iterator]();!(c=(p=h.next()).done);c=!0)!0!==(d=p.value).deleted||d.dirty?s.push(d):u.push(d);t.next=12;break;case 8:t.prev=8,t.t0=t.catch(4),l=!0,f=t.t0;case 12:t.prev=12,t.prev=13,c||null==h.return||h.return();case 15:if(t.prev=15,!l){t.next=18;break}throw f;case 18:return t.finish(15);case 19:return t.finish(12);case 20:if(!(u.length>0)){t.next=23;break}return t.next=23,Promise.all(u.map(function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",i.storageManager.deleteModel(t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 23:return t.next=25,i.getActiveKeyInfo(e.KeyRequestSaveLocal);case 25:if(y=t.sent,!(s.length>0)){t.next=33;break}return t.next=29,Promise.all(s.map(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new j(t,y.keys,y.auth_params),e.next=3,r.paramsForLocalStorage();case 3:return r=e.sent,n&&delete r.dirty,e.abrupt("return",r);case 6:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}())).catch((function(e){return o(e)}));case 29:return g=t.sent,t.next=32,i.storageManager.saveModels(g).catch((function(e){console.error("Error writing items",e),i.syncStatus.localError=e,i.syncStatusDidChange(),o()}));case 32:i.syncStatus.localError&&(i.syncStatus.localError=null,i.syncStatusDidChange());case 33:a();case 34:case"end":return t.stop()}}),t,null,[[4,8,12,20],[13,,15,19]])})));return function(e,r){return t.apply(this,arguments)}}()));case 3:case"end":return t.stop()}}),t)}))),function(e,t){return w.apply(this,arguments)})},{key:"syncOffline",value:(k=v(regeneratorRuntime.mark((function e(t){var r,n,i,a,o,s=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=!0,n=!1,i=void 0,e.prev=3,a=t[Symbol.iterator]();!(r=(o=a.next()).done);r=!0)o.value.updated_at=new Date;e.next=11;break;case 7:e.prev=7,e.t0=e.catch(3),n=!0,i=e.t0;case 11:e.prev=11,e.prev=12,r||null==a.return||a.return();case 14:if(e.prev=14,!n){e.next=17;break}throw i;case 17:return e.finish(14);case 18:return e.finish(11);case 19:return e.abrupt("return",this.writeItemsToLocalStorage(t,!0).then((function(e){var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var u=a.value;u.deleted&&s.modelManager.removeItemLocally(u)}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return s.modelManager.clearDirtyItems(t),s.modelManager.didSyncModelsOffline(t),s.notifyEvent("sync:completed",{savedItems:t}),{saved_items:t}})));case 20:case"end":return e.stop()}}),e,this,[[3,7,11,19],[12,,14,18]])}))),function(e){return k.apply(this,arguments)})},{key:"markAllItemsDirtyAndSaveOffline",value:(m=v(regeneratorRuntime.mark((function e(t){var r,n,i,a,o,s,u,c,l,f,h,p,d;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t){e.next=28;break}r=this.modelManager.allNondummyItems.filter((function(e){return!e.errorDecrypting})).slice(),n=!0,i=!1,a=void 0,e.prev=5,o=r[Symbol.iterator]();case 7:if(n=(s=o.next()).done){e.next=14;break}return u=s.value,e.next=11,this.modelManager.alternateUUIDForItem(u);case 11:n=!0,e.next=7;break;case 14:e.next=20;break;case 16:e.prev=16,e.t0=e.catch(5),i=!0,a=e.t0;case 20:e.prev=20,e.prev=21,n||null==o.return||o.return();case 23:if(e.prev=23,!i){e.next=26;break}throw a;case 26:return e.finish(23);case 27:return e.finish(20);case 28:for(c=this.modelManager.allNondummyItems,l=!0,f=!1,h=void 0,e.prev=32,p=c[Symbol.iterator]();!(l=(d=p.next()).done);l=!0)d.value.setDirty(!0);e.next=40;break;case 36:e.prev=36,e.t1=e.catch(32),f=!0,h=e.t1;case 40:e.prev=40,e.prev=41,l||null==p.return||p.return();case 43:if(e.prev=43,!f){e.next=46;break}throw h;case 46:return e.finish(43);case 47:return e.finish(40);case 48:return e.abrupt("return",this.writeItemsToLocalStorage(c,!1));case 49:case"end":return e.stop()}}),e,this,[[5,16,20,28],[21,,23,27],[32,36,40,48],[41,,43,47]])}))),function(e){return m.apply(this,arguments)})},{key:"setSyncToken",value:(y=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._syncToken=t,e.next=3,this.storageManager.setItem("syncToken",t);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return y.apply(this,arguments)})},{key:"getSyncToken",value:(d=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._syncToken){e.next=4;break}return e.next=3,this.storageManager.getItem("syncToken");case 3:this._syncToken=e.sent;case 4:return e.abrupt("return",this._syncToken);case 5:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"setCursorToken",value:(p=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._cursorToken=t,!t){e.next=6;break}return e.next=4,this.storageManager.setItem("cursorToken",t);case 4:e.next=8;break;case 6:return e.next=8,this.storageManager.removeItem("cursorToken");case 8:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"getCursorToken",value:(h=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._cursorToken){e.next=4;break}return e.next=3,this.storageManager.getItem("cursorToken");case 3:this._cursorToken=e.sent;case 4:return e.abrupt("return",this._cursorToken);case 5:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"clearQueuedCallbacks",value:function(){this._queuedCallbacks=[]}},{key:"callQueuedCallbacks",value:function(e){var t=this.queuedCallbacks;if(t.length){var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)(0,a.value)(e)}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}this.clearQueuedCallbacks()}}},{key:"beginCheckingIfSyncIsTakingTooLong",value:function(){this.syncStatus.checker&&this.stopCheckingIfSyncIsTakingTooLong(),this.syncStatus.checker=this.$interval(function(){(new Date-this.syncStatus.syncStart)/1e3>5&&(this.notifyEvent("sync:taking-too-long"),this.stopCheckingIfSyncIsTakingTooLong())}.bind(this),500)}},{key:"stopCheckingIfSyncIsTakingTooLong",value:function(){this.$interval.hasOwnProperty("cancel")?this.$interval.cancel(this.syncStatus.checker):clearInterval(this.syncStatus.checker),this.syncStatus.checker=null}},{key:"lockSyncing",value:function(){this.syncLocked=!0}},{key:"unlockSyncing",value:function(){this.syncLocked=!1}},{key:"sync",value:(f=v(regeneratorRuntime.mark((function t(){var r,n=this,i=arguments;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=i.length>0&&void 0!==i[0]?i[0]:{},!this.syncLocked){t.next=4;break}return console.log("Sync Locked, Returning;"),t.abrupt("return");case 4:return t.abrupt("return",new Promise(function(){var t=v(regeneratorRuntime.mark((function t(i,a){var o,s,u,c,l,f,h,p,d,y,v,g,m,b;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r||(r={}),o=n.modelManager.getDirtyItems(),s=o.filter((function(e){return!n.lastDirtyItemsSave||e.dirtiedDate>n.lastDirtyItemsSave})),t.next=5,n.getActiveKeyInfo(e.KeyRequestLoadSaveAccount);case 5:if(u=t.sent,c=n.syncStatus.syncOpInProgress,l=n.initialDataLoaded(),!c&&l){t.next=16;break}return n.performSyncAgainOnCompletion=!0,n.lastDirtyItemsSave=new Date,t.next=13,n.writeItemsToLocalStorage(s,!1);case 13:return c&&(n.queuedCallbacks.push(i),n.loggingEnabled&&console.warn("Attempting to sync while existing sync is in progress.")),l||(n.loggingEnabled&&console.warn("(1) Attempting to perform online sync before local data has loaded"),i()),t.abrupt("return");case 16:if(n.syncStatus.syncOpInProgress=!0,!u.offline){t.next=19;break}return t.abrupt("return",n.syncOffline(o).then((function(e){n.syncStatus.syncOpInProgress=!1,i(e)})).catch((function(e){n.notifyEvent("sync-exception",e)})));case 19:if(n.initialDataLoaded()){t.next=22;break}return console.error("Attempting to perform online sync before local data has loaded"),t.abrupt("return");case 22:return n.loggingEnabled&&console.log("Syncing online user."),f=n.syncStatus.needsMoreSync,n.syncStatus.syncStart=new Date,n.beginCheckingIfSyncIsTakingTooLong(),h=n.PerSyncItemUploadLimit,(p=o.slice(0,h)).length<o.length?n.syncStatus.needsMoreSync=!0:n.syncStatus.needsMoreSync=!1,f||(n.syncStatus.total=o.length,n.syncStatus.current=0),n.syncStatus.current>n.syncStatus.total&&(n.syncStatus.total=n.syncStatus.current),n.syncStatusDidChange(),t.next=34,n.writeItemsToLocalStorage(s,!1);case 34:return n.lastDirtyItemsSave=new Date,r.onPreSyncSave&&r.onPreSyncSave(),n.allRetreivedItems||(n.allRetreivedItems=[]),n.allSavedItems||(n.allSavedItems=[]),(d={}).limit=n.ServerItemDownloadLimit,r.performIntegrityCheck&&(d.compute_integrity=!0),t.prev=41,t.next=44,Promise.all(p.map((function(e){var t=new j(e,u.keys,u.auth_params);return t.additionalFields=r.additionalFields,t.paramsForSync()}))).then((function(e){d.items=e}));case 44:t.next=49;break;case 46:t.prev=46,t.t0=t.catch(41),n.notifyEvent("sync-exception",t.t0);case 49:for(y=!0,v=!1,g=void 0,t.prev=52,m=p[Symbol.iterator]();!(y=(b=m.next()).done);y=!0)b.value.dirtyCount=0;t.next=60;break;case 56:t.prev=56,t.t1=t.catch(52),v=!0,g=t.t1;case 60:t.prev=60,t.prev=61,y||null==m.return||m.return();case 63:if(t.prev=63,!v){t.next=66;break}throw g;case 66:return t.finish(63);case 67:return t.finish(60);case 68:return t.next=70,n.getSyncToken();case 70:return d.sync_token=t.sent,t.next=73,n.getCursorToken();case 73:return d.cursor_token=t.sent,d.api=S.getApiVersion(),n.loggingEnabled&&console.log("Syncing with params",d),t.prev=76,t.t2=n.httpManager,t.next=80,n.getSyncURL();case 80:t.t3=t.sent,t.t4=d,t.t5=function(e){n.handleSyncSuccess(p,e,r).then((function(){i(e)})).catch((function(e){console.log("Caught sync success exception:",e),n.handleSyncError(e,null,o).then((function(t){n.notifyEvent("sync-exception",e),i(t)}))}))},t.t6=function(e,t){n.handleSyncError(e,t,o).then((function(e){i(e)}))},t.t2.postAuthenticatedAbsolute.call(t.t2,t.t3,t.t4,t.t5,t.t6),t.next=90;break;case 87:t.prev=87,t.t7=t.catch(76),console.log("Sync exception caught:",t.t7);case 90:case"end":return t.stop()}}),t,null,[[41,46],[52,56,60,68],[61,,63,67],[76,87]])})));return function(e,r){return t.apply(this,arguments)}}()));case 5:case"end":return t.stop()}}),t,this)}))),function(){return f.apply(this,arguments)})},{key:"_awaitSleep",value:(l=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.warn("Simulating high latency sync request",t),e.abrupt("return",new Promise((function(e,r){setTimeout((function(){e()}),t)})));case 2:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"handleSyncSuccess",value:(c=v(regeneratorRuntime.mark((function t(r,n,i){var a,o,s,u,c,l,f,h,p,d,y,v,g,m,b,k,w=this;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!i.simulateHighLatency){t.next=4;break}return a=i.simulatedLatency||1e3,t.next=4,this._awaitSleep(a);case 4:for(this.syncStatus.error=null,this.loggingEnabled&&console.log("Sync response",n),o=this.allSavedItems.map((function(e){return e.uuid})),s=n.saved_items.map((function(e){return e.uuid})),n.retrieved_items=n.retrieved_items.filter((function(e){var t=o.includes(e.uuid),r=s.includes(e.uuid);if(t||r)return!1;var n=w.modelManager.findItem(e.uuid);return!n||!n.dirty})),u=[],c=!0,l=!1,f=void 0,t.prev=13,h=r[Symbol.iterator]();!(c=(p=h.next()).done);c=!0)0==(d=p.value).dirtyCount&&u.push(d);t.next=21;break;case 17:t.prev=17,t.t0=t.catch(13),l=!0,f=t.t0;case 21:t.prev=21,t.prev=22,c||null==h.return||h.return();case 24:if(t.prev=24,!l){t.next=27;break}throw f;case 27:return t.finish(24);case 28:return t.finish(21);case 29:return this.modelManager.clearDirtyItems(u),t.next=32,this.handleItemsResponse(n.retrieved_items,null,I.MappingSourceRemoteRetrieved,e.KeyRequestLoadSaveAccount);case 32:return y=t.sent,this.allRetreivedItems=this.allRetreivedItems.concat(y),this.syncStatus.retrievedCount=this.allRetreivedItems.length,v=["content","auth_hash"],t.next=38,this.handleItemsResponse(n.saved_items,v,I.MappingSourceRemoteSaved,e.KeyRequestLoadSaveAccount);case 38:return g=t.sent,this.allSavedItems=this.allSavedItems.concat(g),m=n.unsaved,t.next=43,this.deprecated_handleUnsavedItemsResponse(m);case 43:return t.next=45,this.handleConflictsResponse(n.conflicts);case 45:if(b=t.sent,k=b&&b.length>0,!b){t.next=50;break}return t.next=50,this.writeItemsToLocalStorage(b,!1);case 50:return t.next=52,this.writeItemsToLocalStorage(g,!1);case 52:return t.next=54,this.writeItemsToLocalStorage(y,!1);case 54:if(!n.integrity_hash||n.cursor_token){t.next=59;break}return t.next=57,this.handleServerIntegrityHash(n.integrity_hash);case 57:t.sent||this.syncDiscordance<this.MaxDiscordanceBeforeOutOfSync&&(this.performSyncAgainOnCompletion=!0);case 59:return this.syncStatus.syncOpInProgress=!1,this.syncStatus.current+=r.length,this.syncStatusDidChange(),this.setSyncToken(n.sync_token),this.setCursorToken(n.cursor_token),this.stopCheckingIfSyncIsTakingTooLong(),t.next=67,this.getCursorToken();case 67:if(!t.sent&&!this.syncStatus.needsMoreSync){t.next=72;break}return t.abrupt("return",new Promise((function(e,t){setTimeout(function(){this.sync(i).then(e)}.bind(w),10)})));case 72:if(!k){t.next=77;break}return this.performSyncAgainOnCompletion=!1,t.abrupt("return",new Promise((function(e,t){setTimeout((function(){w.sync(i).then(e)}),10)})));case 77:return this.syncStatus.retrievedCount=0,this.syncStatus.current=0,this.syncStatus.total=0,this.syncStatusDidChange(),(this.allRetreivedItems.length>=this.majorDataChangeThreshold||g.length>=this.majorDataChangeThreshold||m&&m.length>=this.majorDataChangeThreshold||b&&b.length>=this.majorDataChangeThreshold)&&this.notifyEvent("major-data-change"),this.callQueuedCallbacks(n),this.notifyEvent("sync:completed",{retrievedItems:this.allRetreivedItems,savedItems:this.allSavedItems}),this.allRetreivedItems=[],this.allSavedItems=[],this.performSyncAgainOnCompletion&&(this.performSyncAgainOnCompletion=!1,setTimeout((function(){w.sync(i)}),10)),t.abrupt("return",n);case 88:case"end":return t.stop()}}),t,this,[[13,17,21,29],[22,,24,28]])}))),function(e,t,r){return c.apply(this,arguments)})},{key:"handleSyncError",value:(u=v(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return console.log("Sync error: ",t),401==r&&this.notifyEvent("sync-session-invalid"),t?"string"==typeof t&&(t={error:{message:t}}):t={error:{message:"Could not connect to server."}},this.syncStatus.syncOpInProgress=!1,this.syncStatus.error=t.error,this.syncStatusDidChange(),this.writeItemsToLocalStorage(n,!1),this.modelManager.didSyncModelsOffline(n),this.stopCheckingIfSyncIsTakingTooLong(),this.notifyEvent("sync:error",t.error),this.callQueuedCallbacks({error:"Sync error"}),e.abrupt("return",t);case 12:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return u.apply(this,arguments)})},{key:"handleItemsResponse",value:(s=v(regeneratorRuntime.mark((function e(t,r,n,i){var a,o,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getActiveKeyInfo(i);case 2:return a=e.sent.keys,e.next=5,SFJS.itemTransformer.decryptMultipleItems(t,a);case 5:return e.next=7,this.modelManager.mapResponseItemsToLocalModelsOmittingFields(t,r,n);case 7:return o=e.sent,(s=o.filter((function(e){var t=e.errorDecryptingValueChanged;return e.errorDecryptingValueChanged=!1,t}))).length>0&&this.writeItemsToLocalStorage(s,!1),e.abrupt("return",o);case 11:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return s.apply(this,arguments)})},{key:"refreshErroredItems",value:(o=v(regeneratorRuntime.mark((function t(){var r;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!((r=this.modelManager.allNondummyItems.filter((function(e){return 1==e.errorDecrypting}))).length>0)){t.next=3;break}return t.abrupt("return",this.handleItemsResponse(r,null,I.MappingSourceLocalRetrieved,e.KeyRequestLoadSaveAccount));case 3:case"end":return t.stop()}}),t,this)}))),function(){return o.apply(this,arguments)})},{key:"handleConflictsResponse",value:(a=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c,l,f,h,p,d,y,v,g,m,b,k,w,x,S,_,R,A,D,M,O,C,F,j,E;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r&&0!=r.length){t.next=2;break}return t.abrupt("return");case 2:this.loggingEnabled&&console.log("Handle Conflicted Items:",r),n={},i=!0,a=!1,o=void 0,t.prev=7,s=r[Symbol.iterator]();case 9:if(i=(u=s.next()).done){t.next=21;break}if(c=u.value,l=c.server_item||c.unsaved_item,f=this.modelManager.findItem(l.uuid)){t.next=16;break}return n[l.uuid]={},t.abrupt("continue",18);case 16:h=f.getContentCopy(),n[l.uuid]={frozenContent:h,itemRef:f};case 18:i=!0,t.next=9;break;case 21:t.next=27;break;case 23:t.prev=23,t.t0=t.catch(7),a=!0,o=t.t0;case 27:t.prev=27,t.prev=28,i||null==s.return||s.return();case 30:if(t.prev=30,!a){t.next=33;break}throw o;case 33:return t.finish(30);case 34:return t.finish(27);case 35:p=[],d=!0,y=!1,v=void 0,t.prev=39,g=r[Symbol.iterator]();case 41:if(d=(m=g.next()).done){t.next=91;break}return b=m.value,k=b.server_item||b.unsaved_item,t.t1=SFJS.itemTransformer,t.t2=[k],t.next=48,this.getActiveKeyInfo(e.KeyRequestLoadSaveAccount);case 48:return t.t3=t.sent.keys,t.next=51,t.t1.decryptMultipleItems.call(t.t1,t.t2,t.t3);case 51:if(w=n[k.uuid],x=w.frozenContent,S=w.itemRef){t.next=54;break}return t.abrupt("continue",88);case 54:if(p.push(S),"uuid_conflict"!==b.type){t.next=62;break}return t.next=58,this.modelManager.alternateUUIDForItem(S);case 58:_=t.sent,p.push(_),t.next=88;break;case 62:if("sync_conflict"!==b.type){t.next=86;break}return t.next=65,this.modelManager.createDuplicateItemFromResponseItem(k);case 65:if(R=t.sent,A=this.modelManager.duplicateItemWithCustomContent({content:x,duplicateOf:S}),D=!A.isItemContentEqualWith(R),M=!S.isItemContentEqualWith(R),O=!1,C=!1,F=!1,j=!1,k.deleted||S.deleted?j=!0:D?(new Date-S.client_updated_at)/1e3<20?(F=!0,C=!0):(O=!0,j=!0):M?P.AreItemContentsEqual({leftContent:S.content,rightContent:R.content,keysToIgnore:S.keysToIgnoreWhenCheckingContentEquality().concat(["references"]),appDataKeysToIgnore:S.appDataKeysToIgnoreWhenCheckingContentEquality()})?F=!0:(O=!0,j=!0):j=!0,!O){t.next=79;break}return t.next=77,this.modelManager.duplicateItemWithCustomContentAndAddAsConflict({content:x,duplicateOf:S});case 77:E=t.sent,p.push(E);case 79:if(C&&(this.modelManager.addDuplicatedItemAsConflict({duplicate:R,duplicateOf:S}),p.push(R)),!j){t.next=83;break}return t.next=83,this.modelManager.mapResponseItemsToLocalModelsOmittingFields([k],null,I.MappingSourceRemoteRetrieved);case 83:F&&(S.updated_at=R.updated_at,S.setDirty(!0)),t.next=88;break;case 86:return console.error("Unsupported conflict type",b.type),t.abrupt("continue",88);case 88:d=!0,t.next=41;break;case 91:t.next=97;break;case 93:t.prev=93,t.t4=t.catch(39),y=!0,v=t.t4;case 97:t.prev=97,t.prev=98,d||null==g.return||g.return();case 100:if(t.prev=100,!y){t.next=103;break}throw v;case 103:return t.finish(100);case 104:return t.finish(97);case 105:return t.abrupt("return",p);case 106:case"end":return t.stop()}}),t,this,[[7,23,27,35],[28,,30,34],[39,93,97,105],[98,,100,104]])}))),function(e){return a.apply(this,arguments)})},{key:"deprecated_handleUnsavedItemsResponse",value:(i=v(regeneratorRuntime.mark((function t(r){var n,i,a,o,s,u,c,l,f,h;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r&&0!=r.length){t.next=2;break}return t.abrupt("return");case 2:this.loggingEnabled&&console.log("Handle Unsaved Items:",r),n=!0,i=!1,a=void 0,t.prev=6,o=r[Symbol.iterator]();case 8:if(n=(s=o.next()).done){t.next=35;break}return u=s.value,c=u.item,t.t0=SFJS.itemTransformer,t.t1=[c],t.next=15,this.getActiveKeyInfo(e.KeyRequestLoadSaveAccount);case 15:return t.t2=t.sent.keys,t.next=18,t.t0.decryptMultipleItems.call(t.t0,t.t1,t.t2);case 18:if(l=this.modelManager.findItem(c.uuid)){t.next=21;break}return t.abrupt("continue",32);case 21:if("uuid_conflict"!==(f=u.error).tag){t.next=27;break}return t.next=25,this.modelManager.alternateUUIDForItem(l);case 25:t.next=32;break;case 27:if("sync_conflict"!==f.tag){t.next=32;break}return t.next=30,this.modelManager.createDuplicateItemFromResponseItem(c);case 30:h=t.sent,c.deleted||l.isItemContentEqualWith(h)||this.modelManager.addDuplicatedItemAsConflict({duplicate:h,duplicateOf:l});case 32:n=!0,t.next=8;break;case 35:t.next=41;break;case 37:t.prev=37,t.t3=t.catch(6),i=!0,a=t.t3;case 41:t.prev=41,t.prev=42,n||null==o.return||o.return();case 44:if(t.prev=44,!i){t.next=47;break}throw a;case 47:return t.finish(44);case 48:return t.finish(41);case 49:case"end":return t.stop()}}),t,this,[[6,37,41,49],[42,,44,48]])}))),function(e){return i.apply(this,arguments)})},{key:"stateless_downloadAllItems",value:function(){var t=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new Promise(function(){var n=v(regeneratorRuntime.mark((function n(i,a){var o;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o={limit:r.limit||500,sync_token:r.syncToken,cursor_token:r.cursorToken,content_type:r.contentType,event:r.event,api:S.getApiVersion()},n.prev=1,n.t0=t.httpManager,n.next=5,t.getSyncURL();case 5:n.t1=n.sent,n.t2=o,n.t3=function(){var n=v(regeneratorRuntime.mark((function n(a){var o,s;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return r.retrievedItems||(r.retrievedItems=[]),o=a.retrieved_items,n.next=4,t.getActiveKeyInfo(e.KeyRequestLoadSaveAccount);case 4:return s=n.sent.keys,n.next=7,SFJS.itemTransformer.decryptMultipleItems(o,s);case 7:r.retrievedItems=r.retrievedItems.concat(o.map((function(e){return t.modelManager.createItem(e)}))),r.syncToken=a.sync_token,r.cursorToken=a.cursor_token,r.cursorToken?t.stateless_downloadAllItems(r).then(i):i(r.retrievedItems);case 11:case"end":return n.stop()}}),n)})));return function(e){return n.apply(this,arguments)}}(),n.t4=function(e,t){a(e)},n.t0.postAuthenticatedAbsolute.call(n.t0,n.t1,n.t2,n.t3,n.t4),n.next=16;break;case 12:n.prev=12,n.t5=n.catch(1),console.log("Download all items exception caught:",n.t5),a(n.t5);case 16:case"end":return n.stop()}}),n,null,[[1,12]])})));return function(e,t){return n.apply(this,arguments)}}())}},{key:"resolveOutOfSync",value:(n=v(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.stateless_downloadAllItems({event:"resolve-out-of-sync"}).then(function(){var e=v(regeneratorRuntime.mark((function e(r){var n,i,a,o,s,u,c,l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:n=[],i=!0,a=!1,o=void 0,e.prev=4,s=r[Symbol.iterator]();case 6:if(i=(u=s.next()).done){e.next=18;break}if(c=u.value,!(l=t.modelManager.findItem(c.uuid))){e.next=14;break}if(c.isItemContentEqualWith(l)){e.next=14;break}return e.next=14,t.modelManager.duplicateItemAndAddAsConflict(l);case 14:n.push(c);case 15:i=!0,e.next=6;break;case 18:e.next=24;break;case 20:e.prev=20,e.t0=e.catch(4),a=!0,o=e.t0;case 24:e.prev=24,e.prev=25,i||null==s.return||s.return();case 27:if(e.prev=27,!a){e.next=30;break}throw o;case 30:return e.finish(27);case 31:return e.finish(24);case 32:return e.next=34,t.modelManager.mapResponseItemsToLocalModelsWithOptions({items:n,source:I.MappingSourceRemoteRetrieved});case 34:return e.next=36,t.writeItemsToLocalStorage(t.modelManager.allNondummyItems);case 36:return e.abrupt("return",t.sync({performIntegrityCheck:!0}));case 37:case"end":return e.stop()}}),e,null,[[4,20,24,32],[25,,27,31]])})));return function(t){return e.apply(this,arguments)}}()));case 1:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"handleSignout",value:(r=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.outOfSync=!1,this.loadLocalDataPromise=null,this.performSyncAgainOnCompletion=!1,this.syncStatus.syncOpInProgress=!1,this._queuedCallbacks=[],this.syncStatus={},e.abrupt("return",this.clearSyncToken());case 7:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"clearSyncToken",value:(t=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._syncToken=null,this._cursorToken=null,e.abrupt("return",this.storageManager.removeItem("syncToken"));case 3:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"__setLocalDataNotLoaded",value:function(){this.loadLocalDataPromise=null,this._initialDataLoaded=!1}},{key:"queuedCallbacks",get:function(){return this._queuedCallbacks||(this._queuedCallbacks=[]),this._queuedCallbacks}}]),e}();n.SFSyncManager=F;var P=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};g(this,e),this.content={},this.referencingObjects=[],this.updateFromJSON(t),this.uuid||"undefined"!=typeof SFJS&&SFJS.crypto.generateUUIDSync&&(this.uuid=SFJS.crypto.generateUUIDSync()),"object"!==d(this.content)||this.content.references||(this.content.references=[])}var t;return b(e,[{key:"initUUID",value:(t=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.uuid){e.next=4;break}return e.next=3,SFJS.crypto.generateUUID();case 3:this.uuid=e.sent;case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"updateFromJSON",value:function(t){if(t){this.deleted=t.deleted,this.uuid=t.uuid,this.enc_item_key=t.enc_item_key,this.auth_hash=t.auth_hash,this.auth_params=t.auth_params;for(var r=0,n=["errorDecrypting","dirty","dirtyCount","dirtiedDate","dummy"];r<n.length;r++){var i=n[r];void 0!==t[i]&&(this[i]=t[i])}if(this.dirtiedDate&&"string"==typeof this.dirtiedDate&&(this.dirtiedDate=new Date(this.dirtiedDate)),this.content_type||(this.content_type=t.content_type),t.errorDecrypting)this.content=t.content;else try{var a="string"==typeof t.content?JSON.parse(t.content):t.content;e.deepMerge(this.contentObject,a)}catch(e){console.log("Error while updating item from json",e)}t.created_at&&(this.created_at=t.created_at),t.updated_at&&(this.updated_at=t.updated_at),this.created_at?this.created_at=new Date(this.created_at):this.created_at=new Date,this.updated_at?this.updated_at=new Date(this.updated_at):this.updated_at=new Date(0),this._client_updated_at=null,t.content?this.mapContentToLocalProperties(this.contentObject):1==t.deleted&&this.handleDeletedContent()}}},{key:"mapContentToLocalProperties",value:function(e){}},{key:"createContentJSONFromProperties",value:function(){var t=this.structureParams();return e.deepMerge(this.contentObject,t),t}},{key:"structureParams",value:function(){return this.getContentCopy()}},{key:"handleDeletedContent",value:function(){}},{key:"setDirty",value:function(e,t){this.dirty=e,this.dirtyCount||(this.dirtyCount=0),e?this.dirtyCount++:this.dirtyCount=0,this.dirtiedDate=new Date,e&&t?this.client_updated_at=new Date:this.hasRawClientUpdatedAtValue()||(this.client_updated_at=new Date(this.updated_at))}},{key:"updateLocalRelationships",value:function(){}},{key:"addItemAsRelationship",value:function(e){if(e.setIsBeingReferencedBy(this),!this.hasRelationshipWithItem(e)){var t=this.content.references||[];t.push({uuid:e.uuid,content_type:e.content_type}),this.content.references=t}}},{key:"removeItemAsRelationship",value:function(e){e.setIsNoLongerBeingReferencedBy(this),this.removeReferenceWithUuid(e.uuid)}},{key:"setIsBeingReferencedBy",value:function(e){_.find(this.referencingObjects,{uuid:e.uuid})||this.referencingObjects.push(e)}},{key:"setIsNoLongerBeingReferencedBy",value:function(e){_.remove(this.referencingObjects,{uuid:e.uuid}),this.hasRelationshipWithItem(e)&&(this.removeReferenceWithUuid(e.uuid),this.setDirty(!0))}},{key:"removeReferenceWithUuid",value:function(e){var t=this.content.references||[];t=t.filter((function(t){return t.uuid!=e})),this.content.references=t}},{key:"hasRelationshipWithItem",value:function(e){return null!=this.content.references.find((function(t){return t.uuid==e.uuid}))}},{key:"isBeingRemovedLocally",value:function(){}},{key:"didFinishSyncing",value:function(){}},{key:"informReferencesOfUUIDChange",value:function(e,t){}},{key:"potentialItemOfInterestHasChangedItsUUID",value:function(e,t,r){if(!this.errorDecrypting){var n=!0,i=!1,a=void 0;try{for(var o,s=this.content.references[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var u=o.value;u.uuid==t&&(u.uuid=r,this.setDirty(!0))}}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}}}},{key:"doNotEncrypt",value:function(){return!1}},{key:"setDomainDataItem",value:function(e,t,r){if(r){if(!this.errorDecrypting){this.content.appData||(this.content.appData={});var n=this.content.appData[r];n||(n={}),n[e]=t,this.content.appData[r]=n}}else console.error("SFItem.AppDomain needs to be set.")}},{key:"getDomainDataItem",value:function(e,t){if(t){if(!this.errorDecrypting){this.content.appData||(this.content.appData={});var r=this.content.appData[t];return r?r[e]:null}}else console.error("SFItem.AppDomain needs to be set.")}},{key:"setAppDataItem",value:function(t,r){this.setDomainDataItem(t,r,e.AppDomain)}},{key:"getAppDataItem",value:function(t){return this.getDomainDataItem(t,e.AppDomain)}},{key:"hasRawClientUpdatedAtValue",value:function(){return null!=this.getAppDataItem("client_updated_at")}},{key:"keysToIgnoreWhenCheckingContentEquality",value:function(){return[]}},{key:"appDataKeysToIgnoreWhenCheckingContentEquality",value:function(){return["client_updated_at"]}},{key:"getContentCopy",value:function(){return JSON.parse(JSON.stringify(this.content))}},{key:"isItemContentEqualWith",value:function(t){return e.AreItemContentsEqual({leftContent:this.content,rightContent:t.content,keysToIgnore:this.keysToIgnoreWhenCheckingContentEquality(),appDataKeysToIgnore:this.appDataKeysToIgnoreWhenCheckingContentEquality()})}},{key:"satisfiesPredicate",value:function(e){return E.ItemSatisfiesPredicate(this,e)}},{key:"createdAtString",value:function(){return this.dateToLocalizedString(this.created_at)}},{key:"updatedAtString",value:function(){return this.dateToLocalizedString(this.client_updated_at)}},{key:"updatedAtTimestamp",value:function(){return this.updated_at.getTime()}},{key:"dateToLocalizedString",value:function(e){if("undefined"!=typeof Intl&&Intl.DateTimeFormat){if(!C){var t=navigator.languages&&navigator.languages.length?navigator.languages[0]:navigator.language;C=new Intl.DateTimeFormat(t,{year:"numeric",month:"short",day:"2-digit",weekday:"long",hour:"2-digit",minute:"2-digit"})}return C.format(e)}return e.toDateString()+" "+e.toLocaleTimeString()}},{key:"contentObject",get:function(){if(this.errorDecrypting)return this.content;if(!this.content)return this.content={},this.content;if(null!==this.content&&"object"===d(this.content))return this.content;try{var e=JSON.parse(this.content);return this.content=e,this.content}catch(e){return console.log("Error parsing json",e,this),this.content={},this.content}}},{key:"pinned",get:function(){return this.getAppDataItem("pinned")}},{key:"archived",get:function(){return this.getAppDataItem("archived")}},{key:"locked",get:function(){return this.getAppDataItem("locked")}},{key:"displayName",get:function(){return"Item"}},{key:"client_updated_at",get:function(){if(!this._client_updated_at){var e=this.getAppDataItem("client_updated_at");this._client_updated_at=e?new Date(e):new Date(this.updated_at)}return this._client_updated_at},set:function(e){this._client_updated_at=e,this.setAppDataItem("client_updated_at",e)}}],[{key:"deepMerge",value:function(e,t){return _.mergeWith(e,t,(function(e,t){if(_.isArray(e))return t})),e}},{key:"AreItemContentsEqual",value:function(t){var r=t.leftContent,n=t.rightContent,i=t.keysToIgnore,a=t.appDataKeysToIgnore,o=function(e,t){if(!e)return e;var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0)delete e[a.value]}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return e};return(r=JSON.parse(JSON.stringify(r))).appData&&o(r.appData[e.AppDomain],a),r=o(r,i),(n=JSON.parse(JSON.stringify(n))).appData&&o(n.appData[e.AppDomain],a),n=o(n,i),JSON.stringify(r)===JSON.stringify(n)}}]),e}();n.SFItem=P;var j=function(){function e(t,r,n){if(g(this,e),this.item=t,this.keys=r,this.auth_params=n,this.keys&&!this.auth_params)throw"SFItemParams.auth_params must be supplied if supplying keys.";if(this.auth_params&&!this.auth_params.version)throw"SFItemParams.auth_params is missing version"}var t,r,n,i,a;return b(e,[{key:"paramsForExportFile",value:(a=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.forExportFile=!0,!t){e.next=5;break}return e.abrupt("return",this.__params());case 5:return e.next=7,this.__params();case 7:return r=e.sent,e.abrupt("return",_.omit(r,["deleted"]));case 9:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"paramsForExtension",value:(i=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.paramsForExportFile());case 1:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"paramsForLocalStorage",value:(n=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.additionalFields=["dirty","dirtiedDate","errorDecrypting"],this.forExportFile=!0,e.abrupt("return",this.__params());case 3:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"paramsForSync",value:(r=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.__params());case 1:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"__params",value:(t=v(regeneratorRuntime.mark((function e(){var t,r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t={uuid:this.item.uuid,content_type:this.item.content_type,deleted:this.item.deleted,created_at:this.item.created_at,updated_at:this.item.updated_at},this.item.errorDecrypting){e.next=23;break}if(r=this.item.doNotEncrypt()&&!this.forExportFile,!this.keys||r){e.next=11;break}return e.next=6,SFJS.itemTransformer.encryptItem(this.item,this.keys,this.auth_params);case 6:n=e.sent,_.merge(t,n),"001"!==this.auth_params.version&&(t.auth_hash=null),e.next=21;break;case 11:if(!this.forExportFile){e.next=15;break}e.t0=this.item.createContentJSONFromProperties(),e.next=19;break;case 15:return e.next=17,SFJS.crypto.base64(JSON.stringify(this.item.createContentJSONFromProperties()));case 17:e.t1=e.sent,e.t0="000"+e.t1;case 19:t.content=e.t0,this.forExportFile||(t.enc_item_key=null,t.auth_hash=null);case 21:e.next=26;break;case 23:t.content=this.item.content,t.enc_item_key=this.item.enc_item_key,t.auth_hash=this.item.auth_hash;case 26:return this.additionalFields&&_.merge(t,_.pick(this.item,this.additionalFields)),e.abrupt("return",t);case 28:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}();n.SFItemParams=j;var E=function(){function e(t,r,n){g(this,e),this.keypath=t,this.operator=r,this.value=n,e.IsRecursiveOperator(this.operator)&&(this.value=this.value.map(e.fromArray))}return b(e,null,[{key:"fromArray",value:function(t){return new e(t[0],t[1],t[2])}},{key:"ObjectSatisfiesPredicate",value:function(t,r){if(Array.isArray(r)&&(r=this.fromArray(r)),e.IsRecursiveOperator(r.operator)){if("and"===r.operator){var n=!0,i=!1,a=void 0;try{for(var o,s=r.value[Symbol.iterator]();!(n=(o=s.next()).done);n=!0){var u=o.value;if(!this.ObjectSatisfiesPredicate(t,u))return!1}}catch(e){i=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(i)throw a}}return!0}if("or"===r.operator){var c=!0,l=!1,f=void 0;try{for(var h,p=r.value[Symbol.iterator]();!(c=(h=p.next()).done);c=!0)if(u=h.value,this.ObjectSatisfiesPredicate(t,u))return!0}catch(e){l=!0,f=e}finally{try{c||null==p.return||p.return()}finally{if(l)throw f}}return!1}}var d=r.value;"string"==typeof d&&d.includes(".ago")&&(d=this.DateFromString(d));var y=r.keypath.split(".").reduce((function(e,t){return e&&e[t]}),t),v=[!1,"",null,void 0,NaN];return null==y?"!="==r.operator?!v.includes(r.value):v.includes(r.value):"="==r.operator?Array.isArray(y)?JSON.stringify(y)==JSON.stringify(d):y==d:"!="==r.operator?Array.isArray(y)?JSON.stringify(y)!=JSON.stringify(d):y!==d:"<"==r.operator?y<d:">"==r.operator?y>d:"<="==r.operator?y<=d:">="==r.operator?y>=d:"startsWith"==r.operator?y.startsWith(d):"in"==r.operator?-1!=d.indexOf(y):"includes"==r.operator?this.resolveIncludesPredicate(y,d):"matches"==r.operator&&new RegExp(d).test(y)}},{key:"resolveIncludesPredicate",value:function(t,r){if("string"==typeof r)return t.includes(r);var n;n=Array.isArray(r)?e.fromArray(r):r;var i=!0,a=!1,o=void 0;try{for(var s,u=t[Symbol.iterator]();!(i=(s=u.next()).done);i=!0){var c=s.value;if(this.ObjectSatisfiesPredicate(c,n))return!0}}catch(e){a=!0,o=e}finally{try{i||null==u.return||u.return()}finally{if(a)throw o}}return!1}},{key:"ItemSatisfiesPredicate",value:function(t,r){return Array.isArray(r)&&(r=e.fromArray(r)),this.ObjectSatisfiesPredicate(t,r)}},{key:"ItemSatisfiesPredicates",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,o=t[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value;if(!this.ItemSatisfiesPredicate(e,s))return!1}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}return!0}},{key:"DateFromString",value:function(e){var t=e.split("."),r=t[1],n=new Date,i=parseInt(t[0]);return"days"==r?n.setDate(n.getDate()-i):"hours"==r&&n.setHours(n.getHours()-i),n}},{key:"IsRecursiveOperator",value:function(e){return["and","or"].includes(e)}}]),e}();n.SFPredicate=E;var L=function(e){function t(e){var r;return g(this,t),(r=c(this,l(t).call(this,e))).content.desktopPrivileges||(r.content.desktopPrivileges={}),r}return f(t,e),b(t,null,[{key:"contentType",value:function(){return"SN|Privileges"}}]),b(t,[{key:"setCredentialsForAction",value:function(e,t){this.content.desktopPrivileges[e]=t}},{key:"getCredentialsForAction",value:function(e){return this.content.desktopPrivileges[e]||[]}},{key:"toggleCredentialForAction",value:function(e,t){this.isCredentialRequiredForAction(e,t)?this.removeCredentialForAction(e,t):this.addCredentialForAction(e,t)}},{key:"removeCredentialForAction",value:function(e,t){_.pull(this.content.desktopPrivileges[e],t)}},{key:"addCredentialForAction",value:function(e,t){var r=this.getCredentialsForAction(e);r.push(t),this.setCredentialsForAction(e,r)}},{key:"isCredentialRequiredForAction",value:function(e,t){return this.getCredentialsForAction(e).includes(t)}}]),t}(P);n.SFPrivileges=L;var B=function(e){function t(e){var r;return g(this,t),(r=c(this,l(t).call(this,e))).content.itemUUIDToItemHistoryMapping||(r.content.itemUUIDToItemHistoryMapping={}),Object.keys(r.content.itemUUIDToItemHistoryMapping).forEach((function(e){var t=r.content.itemUUIDToItemHistoryMapping[e];r.content.itemUUIDToItemHistoryMapping[e]=new T(t)})),r}return f(t,e),b(t,[{key:"addEntryForItem",value:function(e){return this.historyForItem(e).addHistoryEntryForItem(e)}},{key:"historyForItem",value:function(e){var t=this.content.itemUUIDToItemHistoryMapping[e.uuid];return t||(t=this.content.itemUUIDToItemHistoryMapping[e.uuid]=new T),t}},{key:"clearItemHistory",value:function(e){this.historyForItem(e).clear()}},{key:"clearAllHistory",value:function(){this.content.itemUUIDToItemHistoryMapping={}}},{key:"optimizeHistoryForItem",value:function(e){var r=this.historyForItem(e);r.entries.length>t.LargeItemEntryAmountThreshold&&r.optimize()}}]),t}(P);n.SFHistorySession=B,B.LargeItemEntryAmountThreshold=60;var T=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(g(this,e),this.entries||(this.entries=[]),t.entries){var r=!0,n=!1,i=void 0;try{for(var a,o=t.entries[Symbol.iterator]();!(r=(a=o.next()).done);r=!0){var s=a.value,u=this.createEntryForItem(s.item);u.setPreviousEntry(this.getLastEntry()),this.entries.push(u)}}catch(e){n=!0,i=e}finally{try{r||null==o.return||o.return()}finally{if(n)throw i}}}}return b(e,[{key:"createEntryForItem",value:function(t){var r=e.HistoryEntryClassMapping&&e.HistoryEntryClassMapping[t.content_type];return r||(r=H),new r(t)}},{key:"getLastEntry",value:function(){return this.entries[this.entries.length-1]}},{key:"addHistoryEntryForItem",value:function(e){var t=this.createEntryForItem(e),r=this.getLastEntry();if(t.setPreviousEntry(r),!t.isSameAsEntry(r))return this.entries.push(t),t}},{key:"clear",value:function(){this.entries.length=0}},{key:"optimize",value:function(){var t=this,r=[],n=function(t){return t.deltaSize()>e.LargeEntryDeltaThreshold},i=function(e,i,a){if(a?r.push(e):-1!==(i=r.indexOf(e))&&r.splice(i,1),a&&n(e)&&-1==e.operationVector()){var o=t.entries[i-1];o&&r.push(o)}};this.entries.forEach((function(e,r){if(0==r||r==t.entries.length-1)i(e,r,!0);else{var a=n(e);i(e,r,a)}})),this.entries=this.entries.filter((function(e,t){return-1!==r.indexOf(e)}))}}]),e}();n.SFItemHistory=T,T.LargeEntryDeltaThreshold=15;var H=function(){function e(t){g(this,e),this.item=P.deepMerge({},t),this.defaultContentKeyToDiffOn="text",this.textCharDiffLength=0,"string"==typeof this.item.updated_at&&(this.item.updated_at=new Date(this.item.updated_at))}return b(e,[{key:"setPreviousEntry",value:function(e){this.hasPreviousEntry=null!=e,this.item.content[this.defaultContentKeyToDiffOn]&&(this.textCharDiffLength=e?this.item.content[this.defaultContentKeyToDiffOn].length-e.item.content[this.defaultContentKeyToDiffOn].length:this.item.content[this.defaultContentKeyToDiffOn].length)}},{key:"operationVector",value:function(){return null!=this.textCharDiffLength?this.hasPreviousEntry&&0!=this.textCharDiffLength?this.textCharDiffLength<0?-1:1:0:1}},{key:"deltaSize",value:function(){return null!=this.textCharDiffLength?Math.abs(this.textCharDiffLength):1}},{key:"isSameAsEntry",value:function(e){if(!e)return!1;var t=new P(this.item),r=new P(e.item);return t.isItemContentEqualWith(r)}}]),e}();n.SFItemHistoryEntry=H,x="undefined"!=typeof window?window:void 0!==e?e:null;var z=function(){function e(){g(this,e),this.DefaultPBKDF2Length=768}var t,r,n,i,a,o,s,c,l,f,h,p,d,y,m;return b(e,[{key:"generateUUIDSync",value:function(){var e=x.crypto||x.msCrypto;if(e){var t=new Uint32Array(4);e.getRandomValues(t);var r=-1;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){r++;var n=t[r>>3]>>r%8*4&15;return("x"==e?n:3&n|8).toString(16)}))}var n=(new Date).getTime();return x.performance&&"function"==typeof x.performance.now&&(n+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"==e?t:3&t|8).toString(16)}))}},{key:"generateUUID",value:(m=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.generateUUIDSync());case 1:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"timingSafeEqual",value:function(e,t){var r=String(e),n=String(t),i=r.length,a=0;i!==n.length&&(n=r,a=1);for(var o=0;o<i;o++)a|=r.charCodeAt(o)^n.charCodeAt(o);return 0===a}},{key:"decryptText",value:(y=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,c,l,f,h,p=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=(t=p.length>0&&void 0!==p[0]?p[0]:{}).ciphertextToAuth,n=t.contentCiphertext,i=t.encryptionKey,a=t.iv,o=t.authHash,s=t.authKey,!(p.length>1?p[1]:void 0)||o){e.next=5;break}return console.error("Auth hash is required."),e.abrupt("return");case 5:if(!o){e.next=12;break}return e.next=8,this.hmac256(r,s);case 8:if(c=e.sent,!1!==this.timingSafeEqual(o,c)){e.next=12;break}return console.error("Auth hash does not match, returning null."),e.abrupt("return",null);case 12:return l=u.enc.Hex.parse(i),f=u.enc.Hex.parse(a||""),h=u.AES.decrypt(n,l,{iv:f,mode:u.mode.CBC,padding:u.pad.Pkcs7}),e.abrupt("return",h.toString(u.enc.Utf8));case 16:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"encryptText",value:(d=v(regeneratorRuntime.mark((function e(t,r,n){var i,a,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=u.enc.Hex.parse(r),a=u.enc.Hex.parse(n||""),o=u.AES.encrypt(t,i,{iv:a,mode:u.mode.CBC,padding:u.pad.Pkcs7}),e.abrupt("return",o.toString());case 4:case"end":return e.stop()}}),e)}))),function(e,t,r){return d.apply(this,arguments)})},{key:"generateRandomKey",value:(p=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u.lib.WordArray.random(t/8).toString());case 1:case"end":return e.stop()}}),e)}))),function(e){return p.apply(this,arguments)})},{key:"generateItemEncryptionKey",value:(h=v(regeneratorRuntime.mark((function e(){var t,r,n,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=512,r=1,e.next=4,this.generateRandomKey(t);case 4:return n=e.sent,e.next=7,this.generateRandomKey(t);case 7:return i=e.sent,e.abrupt("return",this.pbkdf2(i,n,r,t));case 9:case"end":return e.stop()}}),e,this)}))),function(){return h.apply(this,arguments)})},{key:"firstHalfOfKey",value:(f=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.substring(0,t.length/2));case 1:case"end":return e.stop()}}),e)}))),function(e){return f.apply(this,arguments)})},{key:"secondHalfOfKey",value:(l=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.substring(t.length/2,t.length));case 1:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"base64",value:(c=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",x.btoa(encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)}))));case 1:case"end":return e.stop()}}),e)}))),function(e){return c.apply(this,arguments)})},{key:"base64Decode",value:(s=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",x.atob(t));case 1:case"end":return e.stop()}}),e)}))),function(e){return s.apply(this,arguments)})},{key:"sha256",value:(o=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u.SHA256(t).toString());case 1:case"end":return e.stop()}}),e)}))),function(e){return o.apply(this,arguments)})},{key:"hmac256",value:(a=v(regeneratorRuntime.mark((function e(t,r){var n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=u.enc.Hex.parse(r),i=u.enc.Utf8.parse(t),a=u.HmacSHA256(i,n).toString(),e.abrupt("return",a);case 4:case"end":return e.stop()}}),e)}))),function(e,t){return a.apply(this,arguments)})},{key:"generateSalt",value:(i=v(regeneratorRuntime.mark((function e(t,r,n,i){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sha256([t,"SF",r,n,i].join(":"));case 2:return a=e.sent,e.abrupt("return",a);case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return i.apply(this,arguments)})},{key:"generateSymmetricKeyPair",value:(n=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,u,c,l,f=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=(t=f.length>0&&void 0!==f[0]?f[0]:{}).password,n=t.pw_salt,i=t.pw_cost,e.next=3,this.pbkdf2(r,n,i,this.DefaultPBKDF2Length);case 3:return a=e.sent,o=a.length,s=o/3,u=a.slice(0,s),c=a.slice(s,2*s),l=a.slice(2*s,3*s),e.abrupt("return",[u,c,l]);case 10:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"computeEncryptionKeysForUser",value:(r=v(regeneratorRuntime.mark((function e(t,r){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("003"!=r.version){e.next=9;break}if(r.identifier){e.next=4;break}return console.error("authParams is missing identifier."),e.abrupt("return");case 4:return e.next=6,this.generateSalt(r.identifier,r.version,r.pw_cost,r.pw_nonce);case 6:n=e.sent,e.next=10;break;case 9:n=r.pw_salt;case 10:return e.abrupt("return",this.generateSymmetricKeyPair({password:t,pw_salt:n,pw_cost:r.pw_cost}).then((function(e){return{pw:e[0],mk:e[1],ak:e[2]}})));case 11:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"generateInitialKeysAndAuthParamsForUser",value:(t=v(regeneratorRuntime.mark((function e(t,r){var n,i,a,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.SFJS.version,i=this.SFJS.defaultPasswordGenerationCost,e.next=4,this.generateRandomKey(256);case 4:return a=e.sent,e.next=7,this.generateSalt(t,n,i,a);case 7:return o=e.sent,e.abrupt("return",this.generateSymmetricKeyPair({password:r,pw_salt:o,pw_cost:i}).then((function(e){var r={pw_nonce:a,pw_cost:i,identifier:t,version:n};return{keys:{pw:e[0],mk:e[1],ak:e[2]},authParams:r}})));case 9:case"end":return e.stop()}}),e,this)}))),function(e,r){return t.apply(this,arguments)})}]),e}();n.SFAbstractCrypto=z;var U=function(e){function t(){return g(this,t),c(this,l(t).apply(this,arguments))}var r;return f(t,e),b(t,[{key:"pbkdf2",value:(r=v(regeneratorRuntime.mark((function e(t,r,n,i){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a={keySize:i/32,hasher:u.algo.SHA512,iterations:n},e.abrupt("return",u.PBKDF2(t,r,a).toString());case 2:case"end":return e.stop()}}),e)}))),function(e,t,n,i){return r.apply(this,arguments)})}]),t}(z);n.SFCryptoJS=U;var N=(x="undefined"!=typeof window?window:void 0!==e?e:null).crypto?x.crypto.subtle:null,K=function(e){function t(){return g(this,t),c(this,l(t).apply(this,arguments))}var r,n,i,a,o,s,u,h,p,d,y,m,k,w;return f(t,e),b(t,[{key:"pbkdf2",value:(w=v(regeneratorRuntime.mark((function e(t,r,n,i){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.webCryptoImportKey(t,"PBKDF2",["deriveBits"]);case 2:if(a=e.sent){e.next=6;break}return console.log("Key is null, unable to continue"),e.abrupt("return",null);case 6:return e.abrupt("return",this.webCryptoDeriveBits(a,r,n,i));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return w.apply(this,arguments)})},{key:"generateRandomKey",value:(k=v(regeneratorRuntime.mark((function e(t){var r=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",N.generateKey({name:"AES-CBC",length:t},!0,["encrypt","decrypt"]).then((function(e){return N.exportKey("raw",e).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.arrayBufferToHexString(new Uint8Array(t));case 2:return n=e.sent,e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){console.error("Error exporting key",e)}))})).catch((function(e){console.error("Error generating key",e)})));case 2:case"end":return e.stop()}}),e)}))),function(e){return k.apply(this,arguments)})},{key:"generateItemEncryptionKey",value:(m=v(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Promise.all([this.generateRandomKey(256),this.generateRandomKey(256)]).then((function(e){return e.join("")})));case 2:case"end":return e.stop()}}),e,this)}))),function(){return m.apply(this,arguments)})},{key:"encryptText",value:(y=v(regeneratorRuntime.mark((function e(t,r,n){var i,a,o,s,u,c=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!n){e.next=6;break}return e.next=3,this.hexStringToArrayBuffer(n);case 3:e.t0=e.sent,e.next=7;break;case 6:e.t0=new ArrayBuffer(16);case 7:return i=e.t0,a={name:"AES-CBC",iv:i},e.next=11,this.hexStringToArrayBuffer(r);case 11:return o=e.sent,e.next=14,this.webCryptoImportKey(o,a.name,["encrypt"]);case 14:return s=e.sent,e.next=17,this.stringToArrayBuffer(t);case 17:return u=e.sent,e.abrupt("return",crypto.subtle.encrypt(a,s,u).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,c.arrayBufferToBase64(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 19:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return y.apply(this,arguments)})},{key:"decryptText",value:(d=v(regeneratorRuntime.mark((function e(){var t,r,n,i,a,o,s,u,c,l,f,h,p,d=this,y=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=(t=y.length>0&&void 0!==y[0]?y[0]:{}).ciphertextToAuth,n=t.contentCiphertext,i=t.encryptionKey,a=t.iv,o=t.authHash,s=t.authKey,!(y.length>1?y[1]:void 0)||o){e.next=5;break}return console.error("Auth hash is required."),e.abrupt("return");case 5:if(!o){e.next=12;break}return e.next=8,this.hmac256(r,s);case 8:if(u=e.sent,!1!==this.timingSafeEqual(o,u)){e.next=12;break}return console.error("Auth hash does not match, returning null. ".concat(o," != ").concat(u)),e.abrupt("return",null);case 12:if(!a){e.next=18;break}return e.next=15,this.hexStringToArrayBuffer(a);case 15:e.t0=e.sent,e.next=19;break;case 18:e.t0=new ArrayBuffer(16);case 19:return c=e.t0,l={name:"AES-CBC",iv:c},e.next=23,this.hexStringToArrayBuffer(i);case 23:return f=e.sent,e.next=26,this.webCryptoImportKey(f,l.name,["decrypt"]);case 26:return h=e.sent,e.next=29,this.base64ToArrayBuffer(n);case 29:return p=e.sent,e.abrupt("return",crypto.subtle.decrypt(l,h,p).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,d.arrayBufferToString(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){console.error("Error decrypting:",e)})));case 31:case"end":return e.stop()}}),e,this)}))),function(){return d.apply(this,arguments)})},{key:"hmac256",value:(p=v(regeneratorRuntime.mark((function e(t,r){var n,i,a,o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.hexStringToArrayBuffer(r);case 2:return n=e.sent,e.next=5,this.webCryptoImportKey(n,"HMAC",["sign"],{name:"SHA-256"});case 5:return i=e.sent,e.next=8,this.stringToArrayBuffer(t);case 8:return a=e.sent,e.abrupt("return",crypto.subtle.sign({name:"HMAC"},i,a).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.arrayBufferToHexString(t);case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){console.error("Error computing hmac",e)})));case 10:case"end":return e.stop()}}),e,this)}))),function(e,t){return p.apply(this,arguments)})},{key:"webCryptoImportKey",value:(h=v(regeneratorRuntime.mark((function e(t,r,n,i){var a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"!=typeof t){e.next=6;break}return e.next=3,this.stringToArrayBuffer(t);case 3:e.t0=e.sent,e.next=7;break;case 6:e.t0=t;case 7:return a=e.t0,e.abrupt("return",N.importKey("raw",a,{name:r,hash:i},!1,n).then((function(e){return e})).catch((function(e){return console.error(e),null})));case 9:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return h.apply(this,arguments)})},{key:"webCryptoDeriveBits",value:(u=v(regeneratorRuntime.mark((function e(t,r,n,i){var a,o=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.stringToArrayBuffer(r);case 2:return e.t0=e.sent,e.t1=n,e.t2={name:"SHA-512"},a={name:"PBKDF2",salt:e.t0,iterations:e.t1,hash:e.t2},e.abrupt("return",N.deriveBits(a,t,i).then(function(){var e=v(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.arrayBufferToHexString(new Uint8Array(t));case 2:return r=e.sent,e.abrupt("return",r);case 4:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()).catch((function(e){return console.error(e),null})));case 7:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n){return u.apply(this,arguments)})},{key:"stringToArrayBuffer",value:(s=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){var n=new Blob([t]),i=new FileReader;i.onload=function(t){e(t.target.result)},i.readAsArrayBuffer(n)})));case 1:case"end":return e.stop()}}),e)}))),function(e){return s.apply(this,arguments)})},{key:"arrayBufferToString",value:(o=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){var n=new Blob([t]),i=new FileReader;i.onload=function(t){e(t.target.result)},i.readAsText(n)})));case 1:case"end":return e.stop()}}),e)}))),function(e){return o.apply(this,arguments)})},{key:"arrayBufferToHexString",value:(a=v(regeneratorRuntime.mark((function e(t){var r,n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=new Uint8Array(t),n="",a=0;a<r.byteLength;a++)(i=r[a].toString(16)).length<2&&(i="0"+i),n+=i;return e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)}))),function(e){return a.apply(this,arguments)})},{key:"hexStringToArrayBuffer",value:(i=v(regeneratorRuntime.mark((function e(t){var r,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(r=[],n=0;n<t.length;n+=2)r.push(parseInt(t.substr(n,2),16));return e.abrupt("return",new Uint8Array(r));case 2:case"end":return e.stop()}}),e)}))),function(e){return i.apply(this,arguments)})},{key:"base64ToArrayBuffer",value:(n=v(regeneratorRuntime.mark((function e(t){var r,n,i,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.base64Decode(t);case 2:for(r=e.sent,n=r.length,i=new Uint8Array(n),a=0;a<n;a++)i[a]=r.charCodeAt(a);return e.abrupt("return",i.buffer);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"arrayBufferToBase64",value:(r=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){var n=new Blob([t],{type:"application/octet-binary"}),i=new FileReader;i.onload=function(t){var r=t.target.result;e(r.substr(r.indexOf(",")+1))},i.readAsDataURL(n)})));case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})}]),t}(z);n.SFCryptoWeb=K;var W=function(){function e(t){g(this,e),this.crypto=t}var t,r,n,i;return b(e,[{key:"_private_encryptString",value:(i=v(regeneratorRuntime.mark((function e(t,r,n,i,a){var o,s,u,c,l,f;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("001"!==a.version){e.next=7;break}return e.next=3,this.crypto.encryptText(t,r,null);case 3:s=e.sent,o=a.version+s,e.next=21;break;case 7:return e.next=9,this.crypto.generateRandomKey(128);case 9:return u=e.sent,e.next=12,this.crypto.encryptText(t,r,u);case 12:return s=e.sent,c=[a.version,i,u,s].join(":"),e.next=16,this.crypto.hmac256(c,n);case 16:return l=e.sent,e.next=19,this.crypto.base64(JSON.stringify(a));case 19:f=e.sent,o=[a.version,l,i,u,s,f].join(":");case 21:return e.abrupt("return",o);case 22:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return i.apply(this,arguments)})},{key:"encryptItem",value:(n=v(regeneratorRuntime.mark((function e(t,r,n){var i,a,o,s,u,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i={},e.next=3,this.crypto.generateItemEncryptionKey();case 3:if(a=e.sent,"001"!==n.version){e.next=10;break}return e.next=7,this.crypto.encryptText(a,r.mk,null);case 7:i.enc_item_key=e.sent,e.next=13;break;case 10:return e.next=12,this._private_encryptString(a,r.mk,r.ak,t.uuid,n);case 12:i.enc_item_key=e.sent;case 13:return e.next=15,this.crypto.firstHalfOfKey(a);case 15:return o=e.sent,e.next=18,this.crypto.secondHalfOfKey(a);case 18:return s=e.sent,e.next=21,this._private_encryptString(JSON.stringify(t.createContentJSONFromProperties()),o,s,t.uuid,n);case 21:if(u=e.sent,"001"!==n.version){e.next=27;break}return e.next=25,this.crypto.hmac256(u,s);case 25:c=e.sent,i.auth_hash=c;case 27:return i.content=u,e.abrupt("return",i);case 29:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"encryptionComponentsFromString",value:function(e,t,r){var n=e.substring(0,3);if("001"===n)return{contentCiphertext:e.substring(3,e.length),encryptionVersion:n,ciphertextToAuth:e,iv:null,authHash:null,encryptionKey:t,authKey:r};var i=e.split(":");return{encryptionVersion:i[0],authHash:i[1],uuid:i[2],iv:i[3],contentCiphertext:i[4],authParams:i[5],ciphertextToAuth:[i[0],i[2],i[3],i[4]].join(":"),encryptionKey:t,authKey:r}}},{key:"decryptItem",value:(r=v(regeneratorRuntime.mark((function e(t,r){var n,i,a,o,s,u,c,l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("string"==typeof t.content){e.next=2;break}return e.abrupt("return");case 2:if(!t.content.startsWith("000")){e.next=14;break}return e.prev=3,e.t0=JSON,e.next=7,this.crypto.base64Decode(t.content.substring(3,t.content.length));case 7:e.t1=e.sent,t.content=e.t0.parse.call(e.t0,e.t1),e.next=13;break;case 11:e.prev=11,e.t2=e.catch(3);case 13:return e.abrupt("return");case 14:if(t.enc_item_key){e.next=17;break}return console.log("Missing item encryption key, skipping decryption."),e.abrupt("return");case 17:if(n=t.enc_item_key,i=!0,n.startsWith("002")||n.startsWith("003")||(n="001"+n,i=!1),!(a=this.encryptionComponentsFromString(n,r.mk,r.ak)).uuid||a.uuid===t.uuid){e.next=26;break}return console.error("Item key params UUID does not match item UUID"),t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0,e.abrupt("return");case 26:return e.next=28,this.crypto.decryptText(a,i);case 28:if(o=e.sent){e.next=34;break}return console.log("Error decrypting item",t),t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0,e.abrupt("return");case 34:return e.next=36,this.crypto.firstHalfOfKey(o);case 36:return s=e.sent,e.next=39,this.crypto.secondHalfOfKey(o);case 39:return u=e.sent,c=this.encryptionComponentsFromString(t.content,s,u),e.prev=41,e.t3=JSON,e.next=45,this.crypto.base64Decode(c.authParams);case 45:e.t4=e.sent,t.auth_params=e.t3.parse.call(e.t3,e.t4),e.next=51;break;case 49:e.prev=49,e.t5=e.catch(41);case 51:if(!c.uuid||c.uuid===t.uuid){e.next=55;break}return t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0,e.abrupt("return");case 55:return c.authHash||(c.authHash=t.auth_hash),e.next=58,this.crypto.decryptText(c,!0);case 58:(l=e.sent)?(1==t.errorDecrypting&&(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!1,t.content=l):(t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0);case 60:case"end":return e.stop()}}),e,this,[[3,11],[41,49]])}))),function(e,t){return r.apply(this,arguments)})},{key:"decryptMultipleItems",value:(t=v(regeneratorRuntime.mark((function e(t,r,n){var i,a=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=function(){var e=v(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return");case 2:if(1!=t.deleted||null!=t.content){e.next=4;break}return e.abrupt("return");case 4:if(!("string"==typeof t.content||t.content instanceof String)){e.next=19;break}return e.prev=6,e.next=9,a.decryptItem(t,r);case 9:e.next=19;break;case 11:if(e.prev=11,e.t0=e.catch(6),t.errorDecrypting||(t.errorDecryptingValueChanged=!0),t.errorDecrypting=!0,!n){e.next=17;break}throw e.t0;case 17:return console.error("Error decrypting item",t,e.t0),e.abrupt("return");case 19:case"end":return e.stop()}}),e,null,[[6,11]])})));return function(t){return e.apply(this,arguments)}}(),e.abrupt("return",Promise.all(t.map((function(e){return i(e)}))));case 2:case"end":return e.stop()}}),e)}))),function(e,r,n){return t.apply(this,arguments)})}]),e}();n.SFItemTransformer=W,x="undefined"!=typeof window?window:void 0!==e?e:null;var J=function(){function e(t){g(this,e),x&&("undefined"!=typeof document&&document.documentMode||/Edge/.test(navigator.userAgent)||!x.crypto||!x.crypto.subtle?this.crypto=new U:this.crypto=new K),t&&(this.crypto=t),this.itemTransformer=new W(this.crypto),this.crypto.SFJS={version:this.version(),defaultPasswordGenerationCost:this.defaultPasswordGenerationCost()}}return b(e,[{key:"version",value:function(){return"003"}},{key:"supportsPasswordDerivationCost",value:function(e){return!(e>5e3)||this.crypto instanceof K}},{key:"supportedVersions",value:function(){return["001","002","003"]}},{key:"isVersionNewerThanLibraryVersion",value:function(e){var t=this.version();return parseInt(e)>parseInt(t)}},{key:"isProtocolVersionOutdated",value:function(e){var t={"001":Date.parse("2018-01-01"),"002":Date.parse("2020-01-01")}[e];return!!t&&new Date>t}},{key:"costMinimumForVersion",value:function(e){return{"001":3e3,"002":3e3,"003":11e4}[e]}},{key:"defaultPasswordGenerationCost",value:function(){return this.costMinimumForVersion(this.version())}}]),e}();if(n.StandardFile=J,x)try{x.StandardFile=J,x.SFJS=new J,x.SFCryptoWeb=K,x.SFCryptoJS=U,x.SFItemTransformer=W,x.SFModelManager=I,x.SFItem=P,x.SFItemParams=j,x.SFHttpManager=S,x.SFStorageManager=O,x.SFSyncManager=F,x.SFAuthManager=w,x.SFMigrationManager=R,x.SFAlertManager=k,x.SFPredicate=E,x.SFHistorySession=B,x.SFSessionHistoryManager=D,x.SFItemHistory=T,x.SFItemHistoryEntry=H,x.SFPrivilegesManager=A,x.SFPrivileges=L,x.SFSingletonManager=M}catch(e){console.log("Exception while exporting window variables",e)}}).call(this,void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}]},{},[1])(1)}).call(this,r(2))},function(e,t){!function(t){"use strict";var r=Object.prototype,n=r.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",o=i.asyncIterator||"@@asyncIterator",s=i.toStringTag||"@@toStringTag",u="object"==typeof e,c=t.regeneratorRuntime;if(c)u&&(e.exports=c);else{(c=t.regeneratorRuntime=u?e.exports:{}).wrap=y;var l={},f={};f[a]=function(){return this};var h=Object.getPrototypeOf,p=h&&h(h(I([])));p&&p!==r&&n.call(p,a)&&(f=p);var d=b.prototype=g.prototype=Object.create(f);m.prototype=d.constructor=b,b.constructor=m,b[s]=m.displayName="GeneratorFunction",c.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},c.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,b):(e.__proto__=b,s in e||(e[s]="GeneratorFunction")),e.prototype=Object.create(d),e},c.awrap=function(e){return{__await:e}},k(w.prototype),w.prototype[o]=function(){return this},c.AsyncIterator=w,c.async=function(e,t,r,n){var i=new w(y(e,t,r,n));return c.isGeneratorFunction(t)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},k(d),d[s]="Generator",d[a]=function(){return this},d.toString=function(){return"[object Generator]"},c.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},c.values=I,R.prototype={constructor:R,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return o.type="throw",o.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],o=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var s=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),_(r),l}},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;_(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:I(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}}}function y(e,t,r,n){var i=t&&t.prototype instanceof g?t:g,a=Object.create(i.prototype),o=new R(n||[]);return a._invoke=function(e,t,r){var n="suspendedStart";return function(i,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw a;return{value:void 0,done:!0}}for(r.method=i,r.arg=a;;){var o=r.delegate;if(o){var s=x(o,r);if(s){if(s===l)continue;return s}}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 u=v(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(e,r,o),a}function v(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}function g(){}function m(){}function b(){}function k(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function w(e){var t;this._invoke=function(r,i){function a(){return new Promise((function(t,a){!function t(r,i,a,o){var s=v(e[r],e,i);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"==typeof c&&n.call(c,"__await")?Promise.resolve(c.__await).then((function(e){t("next",e,a,o)}),(function(e){t("throw",e,a,o)})):Promise.resolve(c).then((function(e){u.value=e,a(u)}),o)}o(s.arg)}(r,i,t,a)}))}return t=t?t.then(a,a):a()}}function x(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=v(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var i=n.arg;return i?i.done?(t[e.resultName]=i.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):i:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function S(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 _(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function R(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function I(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:A}}function A(){return{value:void 0,done:!0}}}(function(){return this}()||Function("return this")())},function(e,t){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){(function(e,n){var i;(function(){function a(e,t){return e.set(t[0],t[1]),e}function o(e,t){return e.add(t),e}function s(e,t){for(var r=-1,n=null==e?0:e.length,i=0,a=[];++r<n;){var o=e[r];t(o,r,e)&&(a[i++]=o)}return a}function u(e,t){return!(null==e||!e.length)&&-1<d(e,t,0)}function c(e,t){for(var r=-1,n=null==e?0:e.length,i=Array(n);++r<n;)i[r]=t(e[r],r,e);return i}function l(e,t){for(var r=-1,n=t.length,i=e.length;++r<n;)e[i+r]=t[r];return e}function f(e,t,r){for(var n=-1,i=null==e?0:e.length;++n<i;)r=t(r,e[n],n,e);return r}function h(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1}function p(e,t,r){var n=e.length;for(r+=-1;++r<n;)if(t(e[r],r,e))return r;return-1}function d(e,t,r){if(t==t)e:{--r;for(var n=e.length;++r<n;)if(e[r]===t){e=r;break e}e=-1}else e=p(e,y,r);return e}function y(e){return e!=e}function v(e,t){return e.has(t)}function g(e){var t=-1,r=Array(e.size);return e.forEach((function(e,n){r[++t]=[n,e]})),r}function m(e){var t=Object;return function(r){return e(t(r))}}function b(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r}function k(){}function w(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function x(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function S(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function _(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new S;++t<r;)this.add(e[t])}function R(e){this.size=(this.__data__=new x(e)).size}function I(e,t){var r,n=kr(e),i=!n&&br(e),a=!n&&!i&&wr(e),o=!n&&!i&&!a&&xr(e);if(n=n||i||a||o){i=e.length;for(var s=String,u=-1,c=Array(i);++u<i;)c[u]=s(u);i=c}else i=[];for(r in s=i.length,e)!t&&!_t.call(e,r)||n&&("length"==r||a&&("offset"==r||"parent"==r)||o&&("buffer"==r||"byteLength"==r||"byteOffset"==r)||ue(r,s))||i.push(r);return i}function A(e,t,r){(r===Ve||ke(e[t],r))&&(r!==Ve||t in e)||O(e,t,r)}function D(e,t,r){var n=e[t];_t.call(e,t)&&ke(n,r)&&(r!==Ve||t in e)||O(e,t,r)}function M(e,t){for(var r=e.length;r--;)if(ke(e[r][0],t))return r;return-1}function O(e,t,r){"__proto__"==t&&Ht?Ht(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}function C(e,t,r,n,i,a){var o,s=1&t,u=2&t,c=4&t;if(r&&(o=i?r(e,n,i,a):r(e)),o!==Ve)return o;if(!Re(e))return e;if(n=kr(e)){if(o=function(e){var t=e.length,r=e.constructor(t);return t&&"string"==typeof e[0]&&_t.call(e,"index")&&(r.index=e.index,r.input=e.input),r}(e),!s)return $(e,o)}else{var l=dr(e),f="[object Function]"==l||"[object GeneratorFunction]"==l;if(wr(e))return J(e,s);if("[object Object]"==l||"[object Arguments]"==l||f&&!i){if(o=u||f?{}:ae(e),!s)return u?function(e,t){return G(e,pr(e),t)}(e,function(e,t){return e&&G(t,Te(t),e)}(o,e)):function(e,t){return G(e,hr(e),t)}(e,function(e,t){return e&&G(t,Be(t),e)}(o,e))}else{if(!ct[l])return i?e:{};o=oe(e,l,C,s)}}if(a||(a=new R),i=a.get(e))return i;a.set(e,o),u=c?u?te:ee:u?Te:Be;var h=n?Ve:u(e);return function(e,t){for(var r=-1,n=null==e?0:e.length;++r<n&&!1!==t(e[r],r););}(h||e,(function(n,i){h&&(n=e[i=n]),D(o,i,C(n,t,r,i,e,a))})),o}function F(e,t){var r=[];return ur(e,(function(e,n,i){t(e,n,i)&&r.push(e)})),r}function P(e,t){for(var r=0,n=(t=W(t,e)).length;null!=e&&r<n;)e=e[pe(t[r++])];return r&&r==n?e:Ve}function j(e,t,r){return t=t(e),kr(e)?t:l(t,r(e))}function E(e){if(null==e)e=e===Ve?"[object Undefined]":"[object Null]";else if(Tt&&Tt in Object(e)){var t=_t.call(e,Tt),r=e[Tt];try{e[Tt]=Ve;var n=!0}catch(e){}var i=It.call(e);n&&(t?e[Tt]=r:delete e[Tt]),e=i}else e=It.call(e);return e}function L(e){return Ie(e)&&"[object Arguments]"==E(e)}function B(e,t,r,n,i){if(e===t)t=!0;else if(null==e||null==t||!Ie(e)&&!Ie(t))t=e!=e&&t!=t;else e:{var a,o,s=kr(e),u=kr(t),c="[object Object]"==(a="[object Arguments]"==(a=s?"[object Array]":dr(e))?"[object Object]":a);if(u="[object Object]"==(o="[object Arguments]"==(o=u?"[object Array]":dr(t))?"[object Object]":o),(o=a==o)&&wr(e)){if(!wr(t)){t=!1;break e}s=!0,c=!1}if(o&&!c)i||(i=new R),t=s||xr(e)?Q(e,t,r,n,B,i):function(e,t,r,n,i,a,o){switch(r){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)break;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":if(e.byteLength!=t.byteLength||!a(new Ct(e),new Ct(t)))break;return!0;case"[object Boolean]":case"[object Date]":case"[object Number]":return ke(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var s=g;case"[object Set]":if(s||(s=b),e.size!=t.size&&!(1&n))break;return(r=o.get(e))?r==t:(n|=2,o.set(e,t),t=Q(s(e),s(t),n,i,a,o),o.delete(e),t);case"[object Symbol]":if(ar)return ar.call(e)==ar.call(t)}return!1}(e,t,a,r,n,B,i);else{if(!(1&r)&&(s=c&&_t.call(e,"__wrapped__"),a=u&&_t.call(t,"__wrapped__"),s||a)){e=s?e.value():e,t=a?t.value():t,i||(i=new R),t=B(e,t,r,n,i);break e}if(o)t:if(i||(i=new R),s=1&r,a=ee(e),u=a.length,o=ee(t).length,u==o||s){for(c=u;c--;){var l=a[c];if(!(s?l in t:_t.call(t,l))){t=!1;break t}}if((o=i.get(e))&&i.get(t))t=o==t;else{o=!0,i.set(e,t),i.set(t,e);for(var f=s;++c<u;){var h=e[l=a[c]],p=t[l];if(n)var d=s?n(p,h,l,t,e,i):n(h,p,l,e,t,i);if(d===Ve?h!==p&&!B(h,p,r,n,i):!d){o=!1;break}f||(f="constructor"==l)}o&&!f&&(r=e.constructor)!=(n=t.constructor)&&"constructor"in e&&"constructor"in t&&!("function"==typeof r&&r instanceof r&&"function"==typeof n&&n instanceof n)&&(o=!1),i.delete(e),i.delete(t),t=o}}else t=!1;else t=!1}}return t}function T(e){return"function"==typeof e?e:null==e?Ue:"object"==typeof e?kr(e)?function(e,t){return ce(e)&&t==t&&!Re(t)?fe(pe(e),t):function(r){var n=Ee(r,e);return n===Ve&&n===t?Le(r,e):B(t,n,3)}}(e[0],e[1]):function(e){var t=function(e){for(var t=Be(e),r=t.length;r--;){var n=t[r],i=e[n];t[r]=[n,i,i==i&&!Re(i)]}return t}(e);return 1==t.length&&t[0][2]?fe(t[0][0],t[0][1]):function(r){return r===e||function(e,t){var r=t.length,n=r;if(null==e)return!n;for(e=Object(e);r--;)if((i=t[r])[2]?i[1]!==e[i[0]]:!(i[0]in e))return!1;for(;++r<n;){var i,a=(i=t[r])[0],o=e[a],s=i[1];if(i[2]){if(o===Ve&&!(a in e))return!1}else if(!B(s,o,3,void 0,i=new R))return!1}return!0}(r,t)}}(e):We(e)}function H(e,t){var r=-1,n=we(e)?Array(e.length):[];return ur(e,(function(e,i,a){n[++r]=t(e,i,a)})),n}function z(e,t,r,n,i){e!==t&&cr(t,(function(a,o){if(Re(a)){i||(i=new R);var s=i,u=e[o],c=t[o];if(d=s.get(c))A(e,o,d);else{var l=(d=n?n(u,c,o+"",e,t,s):Ve)===Ve;if(l){var f=kr(c),h=!f&&wr(c),p=!f&&!h&&xr(c),d=c;f||h||p?kr(u)?d=u:xe(u)?d=$(u):h?(l=!1,d=J(c,!0)):p?(l=!1,d=V(c,!0)):d=[]:Ae(c)||br(c)?(d=u,br(u)?d=Pe(u):(!Re(u)||r&&Se(u))&&(d=ae(c))):l=!1}l&&(s.set(c,d),z(d,c,r,n,s),s.delete(c)),A(e,o,d)}}else(s=n?n(e[o],a,o+"",e,t,i):Ve)===Ve&&(s=a),A(e,o,s)}),Te)}function U(e){return yr(he(e,void 0,Ue),e+"")}function N(e){if("string"==typeof e)return e;if(kr(e))return c(e,N)+"";if(Me(e))return or?or.call(e):"";var t=e+"";return"0"==t&&1/e==-$e?"-0":t}function K(e,t){var r;if(2>(t=W(t,e)).length)r=e;else{var n=0,i=-1,a=-1,o=(r=t).length;for(0>n&&(n=-n>o?0:o+n),0>(i=i>o?o:i)&&(i+=o),o=n>i?0:i-n>>>0,n>>>=0,i=Array(o);++a<o;)i[a]=r[a+n];r=P(e,i)}null==(e=r)||delete e[pe(ge(t))]}function W(e,t){return kr(e)?e:ce(e,t)?[e]:vr(je(e))}function J(e,t){if(t)return e.slice();var r=e.length;return r=Ft?Ft(r):new e.constructor(r),e.copy(r),r}function q(e){var t=new e.constructor(e.byteLength);return new Ct(t).set(new Ct(e)),t}function V(e,t){return new e.constructor(t?q(e.buffer):e.buffer,e.byteOffset,e.length)}function $(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t}function G(e,t,r){var n=!r;r||(r={});for(var i=-1,a=t.length;++i<a;){var o=t[i],s=Ve;s===Ve&&(s=e[o]),n?O(r,o,s):D(r,o,s)}return r}function X(e){return U((function(t,r){var n,i=-1,a=r.length,o=1<a?r[a-1]:Ve,s=2<a?r[2]:Ve;if(o=3<e.length&&"function"==typeof o?(a--,o):Ve,n=s){n=r[0];var u=r[1];if(Re(s)){var c=typeof u;n=!!("number"==c?we(s)&&ue(u,s.length):"string"==c&&u in s)&&ke(s[u],n)}else n=!1}for(n&&(o=3>a?Ve:o,a=1),t=Object(t);++i<a;)(s=r[i])&&e(t,s,i,o);return t}))}function Y(e){return Ae(e)?Ve:e}function Q(e,t,r,n,i,a){var o=1&r,s=e.length;if(s!=(u=t.length)&&!(o&&u>s))return!1;if((u=a.get(e))&&a.get(t))return u==t;var u=-1,c=!0,l=2&r?new _:Ve;for(a.set(e,t),a.set(t,e);++u<s;){var f=e[u],p=t[u];if(n)var d=o?n(p,f,u,t,e,a):n(f,p,u,e,t,a);if(d!==Ve){if(d)continue;c=!1;break}if(l){if(!h(t,(function(e,t){if(!v(l,t)&&(f===e||i(f,e,r,n,a)))return l.push(t)}))){c=!1;break}}else if(f!==p&&!i(f,p,r,n,a)){c=!1;break}}return a.delete(e),a.delete(t),c}function Z(e){return yr(he(e,Ve,ve),e+"")}function ee(e){return j(e,Be,hr)}function te(e){return j(e,Te,pr)}function re(){var e=(e=k.iteratee||Ne)===Ne?T:e;return arguments.length?e(arguments[0],arguments[1]):e}function ne(e,t){var r=e.__data__,n=typeof t;return("string"==n||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==t:null===t)?r["string"==typeof t?"string":"hash"]:r.map}function ie(e,t){var r=null==e?Ve:e[t];return!Re(r)||Rt&&Rt in r||!(Se(r)?Dt:at).test(de(r))?Ve:r}function ae(e){return"function"!=typeof e.constructor||le(e)?{}:sr(Pt(e))}function oe(e,t,r,n){var i=e.constructor;switch(t){case"[object ArrayBuffer]":return q(e);case"[object Boolean]":case"[object Date]":return new i(+e);case"[object DataView]":return t=n?q(e.buffer):e.buffer,new e.constructor(t,e.byteOffset,e.byteLength);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return V(e,n);case"[object Map]":return f(t=n?r(g(e),1):g(e),a,new e.constructor);case"[object Number]":case"[object String]":return new i(e);case"[object RegExp]":return(t=new e.constructor(e.source,rt.exec(e))).lastIndex=e.lastIndex,t;case"[object Set]":return f(t=n?r(b(e),1):b(e),o,new e.constructor);case"[object Symbol]":return ar?Object(ar.call(e)):{}}}function se(e){return kr(e)||br(e)||!!(Bt&&e&&e[Bt])}function ue(e,t){return!!(t=null==t?9007199254740991:t)&&("number"==typeof e||st.test(e))&&-1<e&&0==e%1&&e<t}function ce(e,t){if(kr(e))return!1;var r=typeof e;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!Me(e))||Ye.test(e)||!Xe.test(e)||null!=t&&e in Object(t)}function le(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||wt)}function fe(e,t){return function(r){return null!=r&&r[e]===t&&(t!==Ve||e in Object(r))}}function he(e,t,r){return t=Wt(t===Ve?e.length-1:t,0),function(){for(var n=arguments,i=-1,a=Wt(n.length-t,0),o=Array(a);++i<a;)o[i]=n[t+i];for(i=-1,a=Array(t+1);++i<t;)a[i]=n[i];return a[t]=r(o),function(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}(e,this,a)}}function pe(e){if("string"==typeof e||Me(e))return e;var t=e+"";return"0"==t&&1/e==-$e?"-0":t}function de(e){if(null!=e){try{return St.call(e)}catch(e){}return e+""}return""}function ye(e,t,r){var n=null==e?0:e.length;return n?(0>(r=null==r?0:Ce(r))&&(r=Wt(n+r,0)),p(e,re(t,3),r)):-1}function ve(e){return null!=e&&e.length?function e(t,r,n,i,a){var o=-1,s=t.length;for(n||(n=se),a||(a=[]);++o<s;){var u=t[o];0<r&&n(u)?1<r?e(u,r-1,n,i,a):l(a,u):i||(a[a.length]=u)}return a}(e,1):[]}function ge(e){var t=null==e?0:e.length;return t?e[t-1]:Ve}function me(e,t){var r;if(e&&e.length&&t&&t.length){var n=d,i=-1,a=(r=t).length;for(e===r&&(r=$(r));++i<a;)for(var o=0,s=r[i];-1<(o=n(e,s,o,void 0));)e!=e&&Lt.call(e,o,1),Lt.call(e,o,1);r=e}else r=e;return r}function be(e,t){function r(){var n=arguments,i=t?t.apply(this,n):n[0],a=r.cache;return a.has(i)?a.get(i):(n=e.apply(this,n),r.cache=a.set(i,n)||a,n)}if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");return r.cache=new(be.Cache||S),r}function ke(e,t){return e===t||e!=e&&t!=t}function we(e){return null!=e&&_e(e.length)&&!Se(e)}function xe(e){return Ie(e)&&we(e)}function Se(e){return!!Re(e)&&("[object Function]"==(e=E(e))||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e)}function _e(e){return"number"==typeof e&&-1<e&&0==e%1&&9007199254740991>=e}function Re(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function Ie(e){return null!=e&&"object"==typeof e}function Ae(e){return!(!Ie(e)||"[object Object]"!=E(e))&&(null===(e=Pt(e))||"function"==typeof(e=_t.call(e,"constructor")&&e.constructor)&&e instanceof e&&St.call(e)==At)}function De(e){return"string"==typeof e||!kr(e)&&Ie(e)&&"[object String]"==E(e)}function Me(e){return"symbol"==typeof e||Ie(e)&&"[object Symbol]"==E(e)}function Oe(e){return e?(e=Fe(e))===$e||e===-$e?17976931348623157e292*(0>e?-1:1):e==e?e:0:0===e?e:0}function Ce(e){var t=(e=Oe(e))%1;return e==e?t?e-t:e:0}function Fe(e){if("number"==typeof e)return e;if(Me(e))return Ge;if(Re(e)&&(e=Re(e="function"==typeof e.valueOf?e.valueOf():e)?e+"":e),"string"!=typeof e)return 0===e?e:+e;e=e.replace(et,"");var t=it.test(e);return t||ot.test(e)?ft(e.slice(2),t?2:8):nt.test(e)?Ge:+e}function Pe(e){return G(e,Te(e))}function je(e){return null==e?"":N(e)}function Ee(e,t,r){return(e=null==e?Ve:P(e,t))===Ve?r:e}function Le(e,t){var r;if(r=null!=e){for(var n,i=-1,a=(n=W(t,r=e)).length,o=!1;++i<a;){var s=pe(n[i]);if(!(o=null!=r&&null!=r&&s in Object(r)))break;r=r[s]}r=o||++i!=a?o:!!(a=null==r?0:r.length)&&_e(a)&&ue(s,a)&&(kr(r)||br(r))}return r}function Be(e){if(we(e))e=I(e);else if(le(e)){var t,r=[];for(t in Object(e))_t.call(e,t)&&"constructor"!=t&&r.push(t);e=r}else e=Kt(e);return e}function Te(e){if(we(e))e=I(e,!0);else if(Re(e)){var t,r=le(e),n=[];for(t in e)("constructor"!=t||!r&&_t.call(e,t))&&n.push(t);e=n}else{if(t=[],null!=e)for(r in Object(e))t.push(r);e=t}return e}function He(e){return null==e?[]:function(e,t){return c(t,(function(t){return e[t]}))}(e,Be(e))}function ze(e){return function(){return e}}function Ue(e){return e}function Ne(e){return T("function"==typeof e?e:C(e,1))}function Ke(){}function We(e){return ce(e)?function(e){return function(t){return null==t?Ve:t[e]}}(pe(e)):function(e){return function(t){return P(t,e)}}(e)}function Je(){return[]}function qe(){return!1}var Ve,$e=1/0,Ge=NaN,Xe=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ye=/^\w*$/,Qe=/^\./,Ze=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,et=/^\s+|\s+$/g,tt=/\\(\\)?/g,rt=/\w*$/,nt=/^[-+]0x[0-9a-f]+$/i,it=/^0b[01]+$/i,at=/^\[object .+?Constructor\]$/,ot=/^0o[0-7]+$/i,st=/^(?:0|[1-9]\d*)$/,ut={};ut["[object Float32Array]"]=ut["[object Float64Array]"]=ut["[object Int8Array]"]=ut["[object Int16Array]"]=ut["[object Int32Array]"]=ut["[object Uint8Array]"]=ut["[object Uint8ClampedArray]"]=ut["[object Uint16Array]"]=ut["[object Uint32Array]"]=!0,ut["[object Arguments]"]=ut["[object Array]"]=ut["[object ArrayBuffer]"]=ut["[object Boolean]"]=ut["[object DataView]"]=ut["[object Date]"]=ut["[object Error]"]=ut["[object Function]"]=ut["[object Map]"]=ut["[object Number]"]=ut["[object Object]"]=ut["[object RegExp]"]=ut["[object Set]"]=ut["[object String]"]=ut["[object WeakMap]"]=!1;var ct={};ct["[object Arguments]"]=ct["[object Array]"]=ct["[object ArrayBuffer]"]=ct["[object DataView]"]=ct["[object Boolean]"]=ct["[object Date]"]=ct["[object Float32Array]"]=ct["[object Float64Array]"]=ct["[object Int8Array]"]=ct["[object Int16Array]"]=ct["[object Int32Array]"]=ct["[object Map]"]=ct["[object Number]"]=ct["[object Object]"]=ct["[object RegExp]"]=ct["[object Set]"]=ct["[object String]"]=ct["[object Symbol]"]=ct["[object Uint8Array]"]=ct["[object Uint8ClampedArray]"]=ct["[object Uint16Array]"]=ct["[object Uint32Array]"]=!0,ct["[object Error]"]=ct["[object Function]"]=ct["[object WeakMap]"]=!1;var lt,ft=parseInt,ht="object"==typeof e&&e&&e.Object===Object&&e,pt="object"==typeof self&&self&&self.Object===Object&&self,dt=ht||pt||Function("return this")(),yt=t&&!t.nodeType&&t,vt=yt&&"object"==typeof n&&n&&!n.nodeType&&n,gt=vt&&vt.exports===yt,mt=gt&&ht.process;e:{try{lt=mt&&mt.binding&&mt.binding("util");break e}catch(a){}lt=void 0}var bt=lt&<.isTypedArray,kt=Array.prototype,wt=Object.prototype,xt=dt["__core-js_shared__"],St=Function.prototype.toString,_t=wt.hasOwnProperty,Rt=function(){var e=/[^.]+$/.exec(xt&&xt.keys&&xt.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),It=wt.toString,At=St.call(Object),Dt=RegExp("^"+St.call(_t).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Mt=gt?dt.Buffer:Ve,Ot=dt.Symbol,Ct=dt.Uint8Array,Ft=Mt?Mt.a:Ve,Pt=m(Object.getPrototypeOf),jt=Object.create,Et=wt.propertyIsEnumerable,Lt=kt.splice,Bt=Ot?Ot.isConcatSpreadable:Ve,Tt=Ot?Ot.toStringTag:Ve,Ht=function(){try{var e=ie(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),zt=Math.floor,Ut=Object.getOwnPropertySymbols,Nt=Mt?Mt.isBuffer:Ve,Kt=m(Object.keys),Wt=Math.max,Jt=Math.min,qt=Date.now,Vt=ie(dt,"DataView"),$t=ie(dt,"Map"),Gt=ie(dt,"Promise"),Xt=ie(dt,"Set"),Yt=ie(dt,"WeakMap"),Qt=ie(Object,"create"),Zt=de(Vt),er=de($t),tr=de(Gt),rr=de(Xt),nr=de(Yt),ir=Ot?Ot.prototype:Ve,ar=ir?ir.valueOf:Ve,or=ir?ir.toString:Ve,sr=function(){function e(){}return function(t){return Re(t)?jt?jt(t):(e.prototype=t,t=new e,e.prototype=Ve,t):{}}}();w.prototype.clear=function(){this.__data__=Qt?Qt(null):{},this.size=0},w.prototype.delete=function(e){return e=this.has(e)&&delete this.__data__[e],this.size-=e?1:0,e},w.prototype.get=function(e){var t=this.__data__;return Qt?"__lodash_hash_undefined__"===(e=t[e])?Ve:e:_t.call(t,e)?t[e]:Ve},w.prototype.has=function(e){var t=this.__data__;return Qt?t[e]!==Ve:_t.call(t,e)},w.prototype.set=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Qt&&t===Ve?"__lodash_hash_undefined__":t,this},x.prototype.clear=function(){this.__data__=[],this.size=0},x.prototype.delete=function(e){var t=this.__data__;return!(0>(e=M(t,e))||(e==t.length-1?t.pop():Lt.call(t,e,1),--this.size,0))},x.prototype.get=function(e){var t=this.__data__;return 0>(e=M(t,e))?Ve:t[e][1]},x.prototype.has=function(e){return-1<M(this.__data__,e)},x.prototype.set=function(e,t){var r=this.__data__,n=M(r,e);return 0>n?(++this.size,r.push([e,t])):r[n][1]=t,this},S.prototype.clear=function(){this.size=0,this.__data__={hash:new w,map:new($t||x),string:new w}},S.prototype.delete=function(e){return e=ne(this,e).delete(e),this.size-=e?1:0,e},S.prototype.get=function(e){return ne(this,e).get(e)},S.prototype.has=function(e){return ne(this,e).has(e)},S.prototype.set=function(e,t){var r=ne(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this},_.prototype.add=_.prototype.push=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},_.prototype.has=function(e){return this.__data__.has(e)},R.prototype.clear=function(){this.__data__=new x,this.size=0},R.prototype.delete=function(e){var t=this.__data__;return e=t.delete(e),this.size=t.size,e},R.prototype.get=function(e){return this.__data__.get(e)},R.prototype.has=function(e){return this.__data__.has(e)},R.prototype.set=function(e,t){var r=this.__data__;if(r instanceof x){var n=r.__data__;if(!$t||199>n.length)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new S(n)}return r.set(e,t),this.size=r.size,this};var ur=function(e,t){if(null==e)return e;if(!we(e))return function(e,t){return e&&cr(e,t,Be)}(e,t);for(var r=e.length,n=-1,i=Object(e);++n<r&&!1!==t(i[n],n,i););return e},cr=function(e,t,r){for(var n=-1,i=Object(e),a=(r=r(e)).length;a--;){var o=r[++n];if(!1===t(i[o],o,i))break}return e},lr=Ht?function(e,t){return Ht(e,"toString",{configurable:!0,enumerable:!1,value:ze(t),writable:!0})}:Ue,fr=Xt&&1/b(new Xt([,-0]))[1]==$e?function(e){return new Xt(e)}:Ke,hr=Ut?function(e){return null==e?[]:(e=Object(e),s(Ut(e),(function(t){return Et.call(e,t)})))}:Je,pr=Ut?function(e){for(var t=[];e;)l(t,hr(e)),e=Pt(e);return t}:Je,dr=E;(Vt&&"[object DataView]"!=dr(new Vt(new ArrayBuffer(1)))||$t&&"[object Map]"!=dr(new $t)||Gt&&"[object Promise]"!=dr(Gt.resolve())||Xt&&"[object Set]"!=dr(new Xt)||Yt&&"[object WeakMap]"!=dr(new Yt))&&(dr=function(e){var t=E(e);if(e=(e="[object Object]"==t?e.constructor:Ve)?de(e):"")switch(e){case Zt:return"[object DataView]";case er:return"[object Map]";case tr:return"[object Promise]";case rr:return"[object Set]";case nr:return"[object WeakMap]"}return t});var yr=function(e){var t=0,r=0;return function(){var n=qt(),i=16-(n-r);if(r=n,0<i){if(800<=++t)return arguments[0]}else t=0;return e.apply(Ve,arguments)}}(lr),vr=function(e){var t=(e=be(e,(function(e){return 500===t.size&&t.clear(),e}))).cache;return e}((function(e){var t=[];return Qe.test(e)&&t.push(""),e.replace(Ze,(function(e,r,n,i){t.push(n?i.replace(tt,"$1"):r||e)})),t})),gr=U(me),mr=function(e){return function(t,r,n){var i=Object(t);if(!we(t)){var a=re(r,3);t=Be(t),r=function(e){return a(i[e],e,i)}}return-1<(r=e(t,r,n))?i[a?t[r]:r]:Ve}}(ye);be.Cache=S;var br=L(function(){return arguments}())?L:function(e){return Ie(e)&&_t.call(e,"callee")&&!Et.call(e,"callee")},kr=Array.isArray,wr=Nt||qe,xr=bt?function(e){return function(t){return e(t)}}(bt):function(e){return Ie(e)&&_e(e.length)&&!!ut[E(e)]},Sr=X((function(e,t,r){z(e,t,r)})),_r=X((function(e,t,r,n){z(e,t,r,n)})),Rr=Z((function(e,t){var r={};if(null==e)return r;var n=!1;t=c(t,(function(t){return t=W(t,e),n||(n=1<t.length),t})),G(e,te(e),r),n&&(r=C(r,7,Y));for(var i=t.length;i--;)K(r,t[i]);return r})),Ir=Z((function(e,t){return null==e?{}:function(e,t){return function(e,t,r){for(var n=-1,i=t.length,a={};++n<i;){var o=t[n],s=P(e,o);if(r(0,o)){var u=a;if(o=W(o,e),Re(u))for(var c=-1,l=(o=W(o,u)).length,f=l-1;null!=u&&++c<l;){var h=pe(o[c]),p=s;if(c!=f){var d=u[h];(p=Ve)===Ve&&(p=Re(d)?d:ue(o[c+1])?[]:{})}D(u,h,p),u=u[h]}}}return a}(e,t,(function(t,r){return Le(e,r)}))}(e,t)}));k.constant=ze,k.filter=function(e,t){return(kr(e)?s:F)(e,re(t,3))},k.flatten=ve,k.iteratee=Ne,k.keys=Be,k.keysIn=Te,k.map=function(e,t){return(kr(e)?c:H)(e,re(t,3))},k.memoize=be,k.merge=Sr,k.mergeWith=_r,k.omit=Rr,k.pick=Ir,k.property=We,k.pull=gr,k.pullAll=me,k.remove=function(e,t){var r=[];if(!e||!e.length)return r;var n=-1,i=[],a=e.length;for(t=re(t,3);++n<a;){var o=e[n];t(o,n,e)&&(r.push(o),i.push(n))}for(a=(n=e?i.length:0)-1;n--;)if(o=i[n],n==a||o!==s){var s=o;ue(o)?Lt.call(e,o,1):K(e,o)}return r},k.toPlainObject=Pe,k.uniq=function(e){if(e&&e.length)e:{var t=-1,r=u,n=e.length,i=!0,a=[],o=a;if(200<=n){if(r=fr(e)){e=b(r);break e}i=!1,r=v,o=new _}else o=a;t:for(;++t<n;){var s=c=e[t],c=0!==c?c:0;if(i&&s==s){for(var l=o.length;l--;)if(o[l]===s)continue t;a.push(c)}else r(o,s,void 0)||(o!==a&&o.push(s),a.push(c))}e=a}else e=[];return e},k.values=He,k.cloneDeep=function(e){return C(e,5)},k.eq=ke,k.find=mr,k.findIndex=ye,k.get=Ee,k.hasIn=Le,k.identity=Ue,k.includes=function(e,t,r,n){return e=we(e)?e:He(e),r=r&&!n?Ce(r):0,n=e.length,0>r&&(r=Wt(n+r,0)),De(e)?r<=n&&-1<e.indexOf(t,r):!!n&&-1<d(e,t,r)},k.isArguments=br,k.isArray=kr,k.isArrayLike=we,k.isArrayLikeObject=xe,k.isBuffer=wr,k.isFunction=Se,k.isLength=_e,k.isObject=Re,k.isObjectLike=Ie,k.isPlainObject=Ae,k.isString=De,k.isSymbol=Me,k.isTypedArray=xr,k.last=ge,k.stubArray=Je,k.stubFalse=qe,k.noop=Ke,k.sortedIndexBy=function(e,t,r){t=(r=re(r,2))(t);for(var n=0,i=null==e?0:e.length,a=t!=t,o=null===t,s=Me(t),u=t===Ve;n<i;){var c=zt((n+i)/2),l=r(e[c]),f=l!==Ve,h=null===l,p=l==l,d=Me(l);(a?p:u?p&&f:o?p&&f&&!h:s?p&&f&&!h&&!d:!h&&!d&&l<t)?n=c+1:i=c}return Jt(i,4294967294)},k.toFinite=Oe,k.toInteger=Ce,k.toNumber=Fe,k.toString=je,k.VERSION="4.17.4",dt._=k,void 0===(i=function(){return k}.call(t,r,t,n))||(n.exports=i)}).call(this)}).call(this,r(2),r(4)(e))},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,r){"use strict";r.r(t),r(1),r(3);var n=r(0);function i(e){return(i="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)}function a(){a=function(){return t};var e,t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},s="function"==typeof Symbol?Symbol:{},u=s.iterator||"@@iterator",c=s.asyncIterator||"@@asyncIterator",l=s.toStringTag||"@@toStringTag";function f(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{f({},"")}catch(e){f=function(e,t,r){return e[t]=r}}function h(e,t,r,n){var i=t&&t.prototype instanceof m?t:m,a=Object.create(i.prototype),s=new C(n||[]);return o(a,"_invoke",{value:A(e,r,s)}),a}function p(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}t.wrap=h;var d="suspendedStart",y="executing",v="completed",g={};function m(){}function b(){}function k(){}var w={};f(w,u,(function(){return this}));var x=Object.getPrototypeOf,S=x&&x(x(F([])));S&&S!==r&&n.call(S,u)&&(w=S);var _=k.prototype=m.prototype=Object.create(w);function R(e){["next","throw","return"].forEach((function(t){f(e,t,(function(e){return this._invoke(t,e)}))}))}function I(e,t){function r(a,o,s,u){var c=p(e[a],e,o);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==i(f)&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,s,u)}),(function(e){r("throw",e,s,u)})):t.resolve(f).then((function(e){l.value=e,s(l)}),(function(e){return r("throw",e,s,u)}))}u(c.arg)}var a;o(this,"_invoke",{value:function(e,n){function i(){return new t((function(t,i){r(e,n,t,i)}))}return a=a?a.then(i,i):i()}})}function A(t,r,n){var i=d;return function(a,o){if(i===y)throw new Error("Generator is already running");if(i===v){if("throw"===a)throw o;return{value:e,done:!0}}for(n.method=a,n.arg=o;;){var s=n.delegate;if(s){var u=D(s,n);if(u){if(u===g)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===d)throw i=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=y;var c=p(t,r,n);if("normal"===c.type){if(i=n.done?v:"suspendedYield",c.arg===g)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(i=v,n.method="throw",n.arg=c.arg)}}}function D(t,r){var n=r.method,i=t.iterator[n];if(i===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,D(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var a=p(i,t.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,g;var o=a.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,g):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function M(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 O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function C(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(M,this),this.reset(!0)}function F(t){if(t||""===t){var r=t[u];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,o=function r(){for(;++a<t.length;)if(n.call(t,a))return r.value=t[a],r.done=!1,r;return r.value=e,r.done=!0,r};return o.next=o}}throw new TypeError(i(t)+" is not iterable")}return b.prototype=k,o(_,"constructor",{value:k,configurable:!0}),o(k,"constructor",{value:b,configurable:!0}),b.displayName=f(k,l,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===b||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,k):(e.__proto__=k,f(e,l,"GeneratorFunction")),e.prototype=Object.create(_),e},t.awrap=function(e){return{__await:e}},R(I.prototype),f(I.prototype,c,(function(){return this})),t.AsyncIterator=I,t.async=function(e,r,n,i,a){void 0===a&&(a=Promise);var o=new I(h(e,r,n,i),a);return t.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},R(_),f(_,l,"Generator"),f(_,u,(function(){return this})),f(_,"toString",(function(){return"[object Generator]"})),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=F,C.prototype={constructor:C,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function i(n,i){return s.type="throw",s.arg=t,r.next=n,i&&(r.method="next",r.arg=e),!!i}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return i(o.catchLoc,!0);if(this.prev<o.finallyLoc)return i(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return i(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return i(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,g):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),g},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),g}},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;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:F(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),g}},t}function o(e,t,r,n,i,a,o){try{var s=e[a](o),u=s.value}catch(e){return void r(e)}s.done?t(u):Promise.resolve(u).then(n,i)}function s(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var a=e.apply(t,r);function s(e){o(a,n,i,s,u,"next",e)}function u(e){o(a,n,i,s,u,"throw",e)}s(void 0)}))}}var u=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.httpManger=new n.SFHttpManager,this.httpManger.setJWTRequestHandler((function(){}))}var t,r,o,u,c;return t=e,(r=[{key:"setCredentials",value:function(e){this.credentials=e}},{key:"getIntegrationRelayUrl",value:function(e){return e.content.relayUrl.replace("filesafe.standardnotes.org","filesafe.standardnotes.com")}},{key:"uploadFile",value:(c=s(a().mark((function e(t,r,n){var i,o,s=this;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i="".concat(this.getIntegrationRelayUrl(n),"/integrations/save-item"),o={file:{name:t,item:r},source:n.content.source,authorization:n.content.authorization},e.abrupt("return",new Promise((function(e,t){s.httpManger.postAbsolute(i,o,(function(t){e(t.metadata)}),(function(e){var r=e.error;r||(r={message:"File upload failed."}),console.log("Upload error response",r),t(r)}))})));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return c.apply(this,arguments)})},{key:"downloadFile",value:(u=s(a().mark((function e(t,r){var n,i,o=this;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n="".concat(this.getIntegrationRelayUrl(r),"/integrations/download-item"),i={metadata:t.content.serverMetadata,authorization:r.content.authorization},e.abrupt("return",new Promise((function(e,t){o.httpManger.postAbsolute(n,i,(function(t){e(t)}),(function(e){var r=e.error;console.log("Download error response",e),t(r)}))})));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"deleteFile",value:(o=s(a().mark((function e(t,r){var n,i,o=this;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n="".concat(this.getIntegrationRelayUrl(r),"/integrations/delete-item"),i={metadata:t.content.serverMetadata,authorization:r.content.authorization},e.abrupt("return",new Promise((function(e,t){o.httpManger.postAbsolute(n,i,(function(t){e(t)}),(function(e){var r=e.error;console.log("Download error response",e),t(r)}))})));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,(a=function(e,t){if("object"!==i(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!==i(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key),"symbol"===i(a)?a:String(a)),n)}var a}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();self.addEventListener("message",(async function(e){const t=e.data;if("encrypt"==t.operation){const e=new n.SFItem({content_type:t.contentType,content:{rawData:t.fileData,fileName:t.fileName,fileType:t.fileType}});new n.SFItemParams(e,t.keys,t.authParams).paramsForSync().then((e=>{self.postMessage({fileItem:e})}))}else if("decrypt"==t.operation)SFJS.itemTransformer.decryptItem(t.item,t.keys).then((()=>{const e=new n.SFItem(t.item),r=e.content.rawData;e.errorDecrypting?self.postMessage({error:{message:"Error decrypting."}}):self.postMessage({decryptedData:r,decryptedItem:e})})).catch((e=>{console.log("Decryption error:",e),self.postMessage({error:e})}));else if("upload"==t.operation){const e=new u;e.setCredentials(t.credentials),e.uploadFile(t.outputFileName,t.fileItem,t.integration).then((e=>{self.postMessage({metadata:e})})).catch((e=>{self.postMessage({error:e}),console.log("Upload exception",e)}))}}),!1)}]);
|