previolet
Version:
Previolet Javascript SDK
7 lines (6 loc) • 50.9 kB
JavaScript
/**
* Previolet Javascript SDK v1.1.7
* https://github.com/previolet/previolet-js-sdk
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).PrevioletSDK={})}(this,(function(e){"use strict";function t(e){var t,n;function o(t,n){try{var i=e[t](n),a=i.value,c=a instanceof r;Promise.resolve(c?a.v:a).then((function(r){if(c){var n="return"===t?"return":"next";if(!a.k||r.done)return o(n,r);r=e[n](r).value}s(i.done?"return":"normal",r)}),(function(e){o("throw",e)}))}catch(e){s("throw",e)}}function s(e,r){switch(e){case"return":t.resolve({value:r,done:!0});break;case"throw":t.reject(r);break;default:t.resolve({value:r,done:!1})}(t=t.next)?o(t.key,t.arg):n=null}this._invoke=function(e,r){return new Promise((function(s,i){var a={key:e,arg:r,resolve:s,reject:i,next:null};n?n=n.next=a:(t=n=a,o(e,r))}))},"function"!=typeof e.return&&(this.return=void 0)}function r(e,t){this.v=e,this.k=t}function n(e){return new r(e,0)}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function i(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}t.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},t.prototype.next=function(e){return this._invoke("next",e)},t.prototype.throw=function(e){return this._invoke("throw",e)},t.prototype.return=function(e){return this._invoke("return",e)};const a={},c={},u={btoa:e=>e,atob:e=>e,setInterval(){},open(){},location:{origin:""},localStorage:{setItem(e,t){a[e]=t},getItem:e=>a[e],removeItem(e){delete a[e]}},sessionStorage:{setItem(e,t){c[e]=t},getItem:e=>c[e],removeItem(e){delete c[e]}},isFakeWindow:!0},l={userAgent:null,userLanguage:null,language:null,platform:"undefined"!=typeof __previoletNamespace?"psdk:"+__previoletNamespace:null,standalone:!1},d="undefined"!=typeof window&&"function"==typeof window.btoa&&"function"==typeof window.atob?window:u,h="undefined"!=typeof navigator?navigator:l;var f=function(e,t){return function(){for(var r=new Array(arguments.length),n=0;n<r.length;n++)r[n]=arguments[n];return e.apply(t,r)}},p=Object.prototype.toString;function g(e){return"[object Array]"===p.call(e)}function m(e){return void 0===e}function b(e){return null!==e&&"object"==typeof e}function _(e){if("[object Object]"!==p.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function v(e){return"[object Function]"===p.call(e)}function k(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),g(e))for(var r=0,n=e.length;r<n;r++)t.call(null,e[r],r,e);else for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.call(null,e[o],o,e)}var y={isArray:g,isArrayBuffer:function(e){return"[object ArrayBuffer]"===p.call(e)},isBuffer:function(e){return null!==e&&!m(e)&&null!==e.constructor&&!m(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){return"undefined"!=typeof FormData&&e instanceof FormData},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:b,isPlainObject:_,isUndefined:m,isDate:function(e){return"[object Date]"===p.call(e)},isFile:function(e){return"[object File]"===p.call(e)},isBlob:function(e){return"[object Blob]"===p.call(e)},isFunction:v,isStream:function(e){return b(e)&&v(e.pipe)},isURLSearchParams:function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:k,merge:function e(){var t={};function r(r,n){_(t[n])&&_(r)?t[n]=e(t[n],r):_(r)?t[n]=e({},r):g(r)?t[n]=r.slice():t[n]=r}for(var n=0,o=arguments.length;n<o;n++)k(arguments[n],r);return t},extend:function(e,t,r){return k(t,(function(t,n){e[n]=r&&"function"==typeof t?f(t,r):t})),e},trim:function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e}};function w(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var E=function(e,t,r){if(!t)return e;var n;if(r)n=r(t);else if(y.isURLSearchParams(t))n=t.toString();else{var o=[];y.forEach(t,(function(e,t){null!=e&&(y.isArray(e)?t+="[]":e=[e],y.forEach(e,(function(e){y.isDate(e)?e=e.toISOString():y.isObject(e)&&(e=JSON.stringify(e)),o.push(w(t)+"="+w(e))})))})),n=o.join("&")}if(n){var s=e.indexOf("#");-1!==s&&(e=e.slice(0,s)),e+=(-1===e.indexOf("?")?"?":"&")+n}return e};function S(){this.handlers=[]}S.prototype.use=function(e,t,r){return this.handlers.push({fulfilled:e,rejected:t,synchronous:!!r&&r.synchronous,runWhen:r?r.runWhen:null}),this.handlers.length-1},S.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},S.prototype.forEach=function(e){y.forEach(this.handlers,(function(t){null!==t&&e(t)}))};var T=S,x="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function O(){throw new Error("setTimeout has not been defined")}function j(){throw new Error("clearTimeout has not been defined")}var A=O,P=j;function C(e){if(A===setTimeout)return setTimeout(e,0);if((A===O||!A)&&setTimeout)return A=setTimeout,setTimeout(e,0);try{return A(e,0)}catch(t){try{return A.call(null,e,0)}catch(t){return A.call(this,e,0)}}}"function"==typeof x.setTimeout&&(A=setTimeout),"function"==typeof x.clearTimeout&&(P=clearTimeout);var U,I=[],N=!1,D=-1;function R(){N&&U&&(N=!1,U.length?I=U.concat(I):D=-1,I.length&&B())}function B(){if(!N){var e=C(R);N=!0;for(var t=I.length;t;){for(U=I,I=[];++D<t;)U&&U[D].run();D=-1,t=I.length}U=null,N=!1,function(e){if(P===clearTimeout)return clearTimeout(e);if((P===j||!P)&&clearTimeout)return P=clearTimeout,clearTimeout(e);try{P(e)}catch(t){try{return P.call(null,e)}catch(t){return P.call(this,e)}}}(e)}}function F(e,t){this.fun=e,this.array=t}F.prototype.run=function(){this.fun.apply(null,this.array)};function L(){}var q=L,G=L,H=L,J=L,V=L,M=L,z=L;var K=x.performance||{},W=K.now||K.mozNow||K.msNow||K.oNow||K.webkitNow||function(){return(new Date).getTime()};var $=new Date;var X={nextTick:function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];I.push(new F(e,t)),1!==I.length||N||C(B)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:q,addListener:G,once:H,off:J,removeListener:V,removeAllListeners:M,emit:z,binding:function(e){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(e){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(e){var t=.001*W.call(K),r=Math.floor(t),n=Math.floor(t%1*1e9);return e&&(r-=e[0],(n-=e[1])<0&&(r--,n+=1e9)),[r,n]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-$)/1e3}},Q=function(e,t){y.forEach(e,(function(r,n){n!==t&&n.toUpperCase()===t.toUpperCase()&&(e[t]=r,delete e[n])}))},Z=function(e,t,r,n,o){return e.config=t,r&&(e.code=r),e.request=n,e.response=o,e.isAxiosError=!0,e.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},e},Y=function(e,t,r,n,o){var s=new Error(e);return Z(s,t,r,n,o)},ee=function(e,t,r){var n=r.config.validateStatus;r.status&&n&&!n(r.status)?t(Y("Request failed with status code "+r.status,r.config,null,r.request,r)):e(r)},te=y.isStandardBrowserEnv()?{write:function(e,t,r,n,o,s){var i=[];i.push(e+"="+encodeURIComponent(t)),y.isNumber(r)&&i.push("expires="+new Date(r).toGMTString()),y.isString(n)&&i.push("path="+n),y.isString(o)&&i.push("domain="+o),!0===s&&i.push("secure"),document.cookie=i.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}},re=function(e,t){return e&&!/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(t)?function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}(e,t):t},ne=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"],oe=y.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),r=document.createElement("a");function n(e){var n=e;return t&&(r.setAttribute("href",n),n=r.href),r.setAttribute("href",n),{href:r.href,protocol:r.protocol?r.protocol.replace(/:$/,""):"",host:r.host,search:r.search?r.search.replace(/^\?/,""):"",hash:r.hash?r.hash.replace(/^#/,""):"",hostname:r.hostname,port:r.port,pathname:"/"===r.pathname.charAt(0)?r.pathname:"/"+r.pathname}}return e=n(window.location.href),function(t){var r=y.isString(t)?n(t):t;return r.protocol===e.protocol&&r.host===e.host}}():function(){return!0},se=function(e){return new Promise((function(t,r){var n=e.data,o=e.headers,s=e.responseType;y.isFormData(n)&&delete o["Content-Type"];var i=new XMLHttpRequest;if(e.auth){var a=e.auth.username||"",c=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";o.Authorization="Basic "+btoa(a+":"+c)}var u=re(e.baseURL,e.url);function l(){if(i){var n,o,a,c,u,l="getAllResponseHeaders"in i?(n=i.getAllResponseHeaders(),u={},n?(y.forEach(n.split("\n"),(function(e){if(c=e.indexOf(":"),o=y.trim(e.substr(0,c)).toLowerCase(),a=y.trim(e.substr(c+1)),o){if(u[o]&&ne.indexOf(o)>=0)return;u[o]="set-cookie"===o?(u[o]?u[o]:[]).concat([a]):u[o]?u[o]+", "+a:a}})),u):u):null,d={data:s&&"text"!==s&&"json"!==s?i.response:i.responseText,status:i.status,statusText:i.statusText,headers:l,config:e,request:i};ee(t,r,d),i=null}}if(i.open(e.method.toUpperCase(),E(u,e.params,e.paramsSerializer),!0),i.timeout=e.timeout,"onloadend"in i?i.onloadend=l:i.onreadystatechange=function(){i&&4===i.readyState&&(0!==i.status||i.responseURL&&0===i.responseURL.indexOf("file:"))&&setTimeout(l)},i.onabort=function(){i&&(r(Y("Request aborted",e,"ECONNABORTED",i)),i=null)},i.onerror=function(){r(Y("Network Error",e,null,i)),i=null},i.ontimeout=function(){var t="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),r(Y(t,e,e.transitional&&e.transitional.clarifyTimeoutError?"ETIMEDOUT":"ECONNABORTED",i)),i=null},y.isStandardBrowserEnv()){var d=(e.withCredentials||oe(u))&&e.xsrfCookieName?te.read(e.xsrfCookieName):void 0;d&&(o[e.xsrfHeaderName]=d)}"setRequestHeader"in i&&y.forEach(o,(function(e,t){void 0===n&&"content-type"===t.toLowerCase()?delete o[t]:i.setRequestHeader(t,e)})),y.isUndefined(e.withCredentials)||(i.withCredentials=!!e.withCredentials),s&&"json"!==s&&(i.responseType=e.responseType),"function"==typeof e.onDownloadProgress&&i.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&i.upload&&i.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then((function(e){i&&(i.abort(),r(e),i=null)})),n||(n=null),i.send(n)}))},ie={"Content-Type":"application/x-www-form-urlencoded"};function ae(e,t){!y.isUndefined(e)&&y.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var ce,ue={transitional:{silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},adapter:(("undefined"!=typeof XMLHttpRequest||void 0!==X&&"[object process]"===Object.prototype.toString.call(X))&&(ce=se),ce),transformRequest:[function(e,t){return Q(t,"Accept"),Q(t,"Content-Type"),y.isFormData(e)||y.isArrayBuffer(e)||y.isBuffer(e)||y.isStream(e)||y.isFile(e)||y.isBlob(e)?e:y.isArrayBufferView(e)?e.buffer:y.isURLSearchParams(e)?(ae(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):y.isObject(e)||t&&"application/json"===t["Content-Type"]?(ae(t,"application/json"),function(e,t,r){if(y.isString(e))try{return(t||JSON.parse)(e),y.trim(e)}catch(e){if("SyntaxError"!==e.name)throw e}return(r||JSON.stringify)(e)}(e)):e}],transformResponse:[function(e){var t=this.transitional,r=t&&t.silentJSONParsing,n=t&&t.forcedJSONParsing,o=!r&&"json"===this.responseType;if(o||n&&y.isString(e)&&e.length)try{return JSON.parse(e)}catch(e){if(o){if("SyntaxError"===e.name)throw Z(e,this,"E_JSON_PARSE");throw e}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300}};ue.headers={common:{Accept:"application/json, text/plain, */*"}},y.forEach(["delete","get","head"],(function(e){ue.headers[e]={}})),y.forEach(["post","put","patch"],(function(e){ue.headers[e]=y.merge(ie)}));var le=ue,de=function(e,t,r){var n=this||le;return y.forEach(r,(function(r){e=r.call(n,e,t)})),e},he=function(e){return!(!e||!e.__CANCEL__)};function fe(e){e.cancelToken&&e.cancelToken.throwIfRequested()}var pe=function(e){return fe(e),e.headers=e.headers||{},e.data=de.call(e,e.data,e.headers,e.transformRequest),e.headers=y.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),y.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||le.adapter)(e).then((function(t){return fe(e),t.data=de.call(e,t.data,t.headers,e.transformResponse),t}),(function(t){return he(t)||(fe(e),t&&t.response&&(t.response.data=de.call(e,t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))},ge=function(e,t){t=t||{};var r={},n=["url","method","data"],o=["headers","auth","proxy","params"],s=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],i=["validateStatus"];function a(e,t){return y.isPlainObject(e)&&y.isPlainObject(t)?y.merge(e,t):y.isPlainObject(t)?y.merge({},t):y.isArray(t)?t.slice():t}function c(n){y.isUndefined(t[n])?y.isUndefined(e[n])||(r[n]=a(void 0,e[n])):r[n]=a(e[n],t[n])}y.forEach(n,(function(e){y.isUndefined(t[e])||(r[e]=a(void 0,t[e]))})),y.forEach(o,c),y.forEach(s,(function(n){y.isUndefined(t[n])?y.isUndefined(e[n])||(r[n]=a(void 0,e[n])):r[n]=a(void 0,t[n])})),y.forEach(i,(function(n){n in t?r[n]=a(e[n],t[n]):n in e&&(r[n]=a(void 0,e[n]))}));var u=n.concat(o).concat(s).concat(i),l=Object.keys(e).concat(Object.keys(t)).filter((function(e){return-1===u.indexOf(e)}));return y.forEach(l,c),r},me="axios@0.21.4",be="sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",_e={},ve={type:"range",registry:!0,raw:"axios@^0.21.4",name:"axios",escapedName:"axios",rawSpec:"^0.21.4",saveSpec:null,fetchSpec:"^0.21.4"},ke=["/previolet"],ye="https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",we="c67b90dc0568e5c1cf2b0b858c43ba28e2eda575",Ee="/Users/vioreldram/Work/previolet-js-sdk",Se={name:"Matt Zabriskie"},Te={"./lib/adapters/http.js":"./lib/adapters/xhr.js"},xe={url:"https://github.com/axios/axios/issues"},Oe=[{path:"./dist/axios.min.js",threshold:"5kB"}],je={"follow-redirects":"^1.14.0"},Ae="Promise based HTTP client for the browser and node.js",Pe={coveralls:"^3.0.0","es6-promise":"^4.2.4",grunt:"^1.3.0","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^23.0.0","grunt-karma":"^4.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^4.0.2","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1",karma:"^6.3.2","karma-chrome-launcher":"^3.1.0","karma-firefox-launcher":"^2.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^4.3.6","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.8","karma-webpack":"^4.0.2","load-grunt-tasks":"^3.5.2",minimist:"^1.2.0",mocha:"^8.2.1",sinon:"^4.5.0","terser-webpack-plugin":"^4.2.3",typescript:"^4.0.5","url-search-params":"^0.10.0",webpack:"^4.44.2","webpack-dev-server":"^3.11.0"},Ce=["xhr","http","ajax","promise","node"],Ue={type:"git",url:"git+https://github.com/axios/axios.git"},Ie={build:"NODE_ENV=production grunt build",coveralls:"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",examples:"node ./examples/server.js",fix:"eslint --fix lib/**/*.js",postversion:"git push && git push --tags",preversion:"npm test",start:"node ./sandbox/server.js",test:"grunt test",version:"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json"},Ne="dist/axios.min.js",De={_from:"axios@^0.21.4",_id:me,_inBundle:!1,_integrity:be,_location:"/previolet/axios",_phantomChildren:_e,_requested:ve,_requiredBy:ke,_resolved:ye,_shasum:we,_spec:"axios@^0.21.4",_where:Ee,author:Se,browser:Te,bugs:xe,bundleDependencies:!1,bundlesize:Oe,dependencies:je,deprecated:!1,description:Ae,devDependencies:Pe,homepage:"https://axios-http.com",jsdelivr:"dist/axios.min.js",keywords:Ce,license:"MIT",main:"index.js",name:"axios",repository:Ue,scripts:Ie,typings:"./index.d.ts",unpkg:Ne,version:"0.21.4"};function Re(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&r.path)}},r.exports),r.exports}var Be,Fe=(Be=Object.freeze({__proto__:null,_from:"axios@^0.21.4",_id:me,_inBundle:!1,_integrity:be,_location:"/previolet/axios",_phantomChildren:_e,_requested:ve,_requiredBy:ke,_resolved:ye,_shasum:we,_spec:"axios@^0.21.4",_where:Ee,author:Se,browser:Te,bugs:xe,bundleDependencies:!1,bundlesize:Oe,dependencies:je,deprecated:!1,description:Ae,devDependencies:Pe,homepage:"https://axios-http.com",jsdelivr:"dist/axios.min.js",keywords:Ce,license:"MIT",main:"index.js",name:"axios",repository:Ue,scripts:Ie,typings:"./index.d.ts",unpkg:Ne,version:"0.21.4",default:De}))&&Be.default||Be,Le={};["object","boolean","number","function","string","symbol"].forEach((function(e,t){Le[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}}));var qe={},Ge=Fe.version.split(".");function He(e,t){for(var r=t?t.split("."):Ge,n=e.split("."),o=0;o<3;o++){if(r[o]>n[o])return!0;if(r[o]<n[o])return!1}return!1}Le.transitional=function(e,t,r){var n=t&&He(t);function o(e,t){return"[Axios v"+Fe.version+"] Transitional option '"+e+"'"+t+(r?". "+r:"")}return function(r,s,i){if(!1===e)throw new Error(o(s," has been removed in "+t));return n&&!qe[s]&&(qe[s]=!0,console.warn(o(s," has been deprecated since v"+t+" and will be removed in the near future"))),!e||e(r,s,i)}};var Je={isOlderVersion:He,assertOptions:function(e,t,r){if("object"!=typeof e)throw new TypeError("options must be an object");for(var n=Object.keys(e),o=n.length;o-- >0;){var s=n[o],i=t[s];if(i){var a=e[s],c=void 0===a||i(a,s,e);if(!0!==c)throw new TypeError("option "+s+" must be "+c)}else if(!0!==r)throw Error("Unknown option "+s)}},validators:Le},Ve=Je.validators;function Me(e){this.defaults=e,this.interceptors={request:new T,response:new T}}Me.prototype.request=function(e){"string"==typeof e?(e=arguments[1]||{}).url=arguments[0]:e=e||{},(e=ge(this.defaults,e)).method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var t=e.transitional;void 0!==t&&Je.assertOptions(t,{silentJSONParsing:Ve.transitional(Ve.boolean,"1.0.0"),forcedJSONParsing:Ve.transitional(Ve.boolean,"1.0.0"),clarifyTimeoutError:Ve.transitional(Ve.boolean,"1.0.0")},!1);var r=[],n=!0;this.interceptors.request.forEach((function(t){"function"==typeof t.runWhen&&!1===t.runWhen(e)||(n=n&&t.synchronous,r.unshift(t.fulfilled,t.rejected))}));var o,s=[];if(this.interceptors.response.forEach((function(e){s.push(e.fulfilled,e.rejected)})),!n){var i=[pe,void 0];for(Array.prototype.unshift.apply(i,r),i=i.concat(s),o=Promise.resolve(e);i.length;)o=o.then(i.shift(),i.shift());return o}for(var a=e;r.length;){var c=r.shift(),u=r.shift();try{a=c(a)}catch(e){u(e);break}}try{o=pe(a)}catch(e){return Promise.reject(e)}for(;s.length;)o=o.then(s.shift(),s.shift());return o},Me.prototype.getUri=function(e){return e=ge(this.defaults,e),E(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},y.forEach(["delete","get","head","options"],(function(e){Me.prototype[e]=function(t,r){return this.request(ge(r||{},{method:e,url:t,data:(r||{}).data}))}})),y.forEach(["post","put","patch"],(function(e){Me.prototype[e]=function(t,r,n){return this.request(ge(n||{},{method:e,url:t,data:r}))}}));var ze=Me;function Ke(e){this.message=e}Ke.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},Ke.prototype.__CANCEL__=!0;var We=Ke;function $e(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var r=this;e((function(e){r.reason||(r.reason=new We(e),t(r.reason))}))}$e.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},$e.source=function(){var e;return{token:new $e((function(t){e=t})),cancel:e}};var Xe=$e;function Qe(e){var t=new ze(e),r=f(ze.prototype.request,t);return y.extend(r,ze.prototype,t),y.extend(r,t),r}var Ze=Qe(le);Ze.Axios=ze,Ze.create=function(e){return Qe(ge(Ze.defaults,e))},Ze.Cancel=We,Ze.CancelToken=Xe,Ze.isCancel=he,Ze.all=function(e){return Promise.all(e)},Ze.spread=function(e){return function(t){return e.apply(null,t)}},Ze.isAxiosError=function(e){return"object"==typeof e&&!0===e.isAxiosError};var Ye=Ze,et=Ze;Ye.default=et;var tt=Ye;function rt(e,t){t=t||e.instance;var r=e.baseUrl.replace("{{instance}}",t);return r=(r=r.replace("{{region}}",e.region)).replace("{{version}}",e.version)}function nt(e,t){return"json"==t?JSON.stringify(e):d.btoa(unescape(encodeURIComponent(JSON.stringify(e))))}function ot(){let e="browser";return(h.standalone||"function"==typeof d.matchMedia&&d.matchMedia("(display-mode: standalone)").matches)&&(e="standalone"),e}function st(e,t){return t.responseType="json",tt(e,t).then(e=>e.data).catch(e=>{throw console.log(e),e})}function it(e){tt.defaults.adapter=e}async function at(e,t){let r;try{r=await fetch(e)}catch(r){return Promise.reject(Y("Network Error",t,null,e))}const n={ok:r.ok,status:r.status,statusText:r.statusText,headers:new Headers(r.headers),config:t,request:e};if(r.status>=200&&204!==r.status)switch(t.responseType){case"arraybuffer":n.data=await r.arrayBuffer();break;case"blob":n.data=await r.blob();break;case"json":n.data=await r.json();break;case"formData":n.data=await r.formData();break;default:n.data=await r.text()}return Promise.resolve(n)}async function ct(e){const t=function(e){const t=new Headers(e.headers);if(e.auth){const r=e.auth.username||"",n=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";t.set("Authorization","Basic "+btoa(r+":"+n))}const r=e.method.toUpperCase(),n={headers:t,method:r};"GET"!==r&&"HEAD"!==r&&(n.body=e.data),e.mode&&(n.mode=e.mode),e.cache&&(n.cache=e.cache),e.integrity&&(n.integrity=e.integrity),e.redirect&&(n.integrity=e.redirect),e.referrer&&(n.integrity=e.referrer),y.isUndefined(e.withCredentials)||(n.credentials=e.withCredentials?"include":"omit");const o=re(e.baseURL,e.url),s=E(o,e.params,e.paramsSerializer);return new Request(s,n)}(e),r=[at(t,e)];e.timeout&&e.timeout>0&&r.push(new Promise(r=>{setTimeout(()=>{const n=e.timeoutErrorMessage?e.timeoutErrorMessage:"timeout of "+e.timeout+"ms exceeded";r(Y(n,e,"ECONNABORTED",t))},e.timeout)}));const n=await Promise.race(r);return new Promise((t,r)=>{n instanceof Error?r(n):"[object Function]"===Object.prototype.toString.call(e.settle)?e.settle(t,r,n):ee(t,r,n)})}"undefined"!=typeof overrideAxiosDefaultAdapter&&it(overrideAxiosDefaultAdapter);var ut={baseUrl:"https://{{instance}}.{{region}}.previolet.com/{{version}}",region:"eu.west1",version:"v1",guestTokenExpiration:3600,userTokenExpiration:864e3,storageType:"localStorage",storageNamespace:"previolet-sdk",tokenName:"token",applicationStorage:"app",browserIdentification:"bid",userStorage:"user",debug:!1,reqIndex:1,sdkVersion:"1.1.7",appVersion:"-",defaultConfig:{},tokenOverride:!1,xhrAdapter:null,requestAdapterName:null,tokenFallback:!1,localStorageObject:null,localStorageEncode:"complex",localStorageAsync:!0},lt=1,dt=7,ht=8,ft=1010,pt=Re((function(e){!function(){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r={rotl:function(e,t){return e<<t|e>>>32-t},rotr:function(e,t){return e<<32-t|e>>>t},endian:function(e){if(e.constructor==Number)return 16711935&r.rotl(e,8)|4278255360&r.rotl(e,24);for(var t=0;t<e.length;t++)e[t]=r.endian(e[t]);return e},randomBytes:function(e){for(var t=[];e>0;e--)t.push(Math.floor(256*Math.random()));return t},bytesToWords:function(e){for(var t=[],r=0,n=0;r<e.length;r++,n+=8)t[n>>>5]|=e[r]<<24-n%32;return t},wordsToBytes:function(e){for(var t=[],r=0;r<32*e.length;r+=8)t.push(e[r>>>5]>>>24-r%32&255);return t},bytesToHex:function(e){for(var t=[],r=0;r<e.length;r++)t.push((e[r]>>>4).toString(16)),t.push((15&e[r]).toString(16));return t.join("")},hexToBytes:function(e){for(var t=[],r=0;r<e.length;r+=2)t.push(parseInt(e.substr(r,2),16));return t},bytesToBase64:function(e){for(var r=[],n=0;n<e.length;n+=3)for(var o=e[n]<<16|e[n+1]<<8|e[n+2],s=0;s<4;s++)8*n+6*s<=8*e.length?r.push(t.charAt(o>>>6*(3-s)&63)):r.push("=");return r.join("")},base64ToBytes:function(e){e=e.replace(/[^A-Z0-9+\/]/gi,"");for(var r=[],n=0,o=0;n<e.length;o=++n%4)0!=o&&r.push((t.indexOf(e.charAt(n-1))&Math.pow(2,-2*o+8)-1)<<2*o|t.indexOf(e.charAt(n))>>>6-2*o);return r}};e.exports=r}()})),gt={utf8:{stringToBytes:function(e){return gt.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(gt.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],r=0;r<e.length;r++)t.push(255&e.charCodeAt(r));return t},bytesToString:function(e){for(var t=[],r=0;r<e.length;r++)t.push(String.fromCharCode(e[r]));return t.join("")}}},mt=gt,bt=function(e){return null!=e&&(_t(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&_t(e.slice(0,0))}(e)||!!e._isBuffer)};function _t(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)}var vt=Re((function(e){!function(){var t=pt,r=mt.utf8,n=bt,o=mt.bin,s=function(e,i){e.constructor==String?e=i&&"binary"===i.encoding?o.stringToBytes(e):r.stringToBytes(e):n(e)?e=Array.prototype.slice.call(e,0):Array.isArray(e)||e.constructor===Uint8Array||(e=e.toString());for(var a=t.bytesToWords(e),c=8*e.length,u=1732584193,l=-271733879,d=-1732584194,h=271733878,f=0;f<a.length;f++)a[f]=16711935&(a[f]<<8|a[f]>>>24)|4278255360&(a[f]<<24|a[f]>>>8);a[c>>>5]|=128<<c%32,a[14+(c+64>>>9<<4)]=c;var p=s._ff,g=s._gg,m=s._hh,b=s._ii;for(f=0;f<a.length;f+=16){var _=u,v=l,k=d,y=h;u=p(u,l,d,h,a[f+0],7,-680876936),h=p(h,u,l,d,a[f+1],12,-389564586),d=p(d,h,u,l,a[f+2],17,606105819),l=p(l,d,h,u,a[f+3],22,-1044525330),u=p(u,l,d,h,a[f+4],7,-176418897),h=p(h,u,l,d,a[f+5],12,1200080426),d=p(d,h,u,l,a[f+6],17,-1473231341),l=p(l,d,h,u,a[f+7],22,-45705983),u=p(u,l,d,h,a[f+8],7,1770035416),h=p(h,u,l,d,a[f+9],12,-1958414417),d=p(d,h,u,l,a[f+10],17,-42063),l=p(l,d,h,u,a[f+11],22,-1990404162),u=p(u,l,d,h,a[f+12],7,1804603682),h=p(h,u,l,d,a[f+13],12,-40341101),d=p(d,h,u,l,a[f+14],17,-1502002290),u=g(u,l=p(l,d,h,u,a[f+15],22,1236535329),d,h,a[f+1],5,-165796510),h=g(h,u,l,d,a[f+6],9,-1069501632),d=g(d,h,u,l,a[f+11],14,643717713),l=g(l,d,h,u,a[f+0],20,-373897302),u=g(u,l,d,h,a[f+5],5,-701558691),h=g(h,u,l,d,a[f+10],9,38016083),d=g(d,h,u,l,a[f+15],14,-660478335),l=g(l,d,h,u,a[f+4],20,-405537848),u=g(u,l,d,h,a[f+9],5,568446438),h=g(h,u,l,d,a[f+14],9,-1019803690),d=g(d,h,u,l,a[f+3],14,-187363961),l=g(l,d,h,u,a[f+8],20,1163531501),u=g(u,l,d,h,a[f+13],5,-1444681467),h=g(h,u,l,d,a[f+2],9,-51403784),d=g(d,h,u,l,a[f+7],14,1735328473),u=m(u,l=g(l,d,h,u,a[f+12],20,-1926607734),d,h,a[f+5],4,-378558),h=m(h,u,l,d,a[f+8],11,-2022574463),d=m(d,h,u,l,a[f+11],16,1839030562),l=m(l,d,h,u,a[f+14],23,-35309556),u=m(u,l,d,h,a[f+1],4,-1530992060),h=m(h,u,l,d,a[f+4],11,1272893353),d=m(d,h,u,l,a[f+7],16,-155497632),l=m(l,d,h,u,a[f+10],23,-1094730640),u=m(u,l,d,h,a[f+13],4,681279174),h=m(h,u,l,d,a[f+0],11,-358537222),d=m(d,h,u,l,a[f+3],16,-722521979),l=m(l,d,h,u,a[f+6],23,76029189),u=m(u,l,d,h,a[f+9],4,-640364487),h=m(h,u,l,d,a[f+12],11,-421815835),d=m(d,h,u,l,a[f+15],16,530742520),u=b(u,l=m(l,d,h,u,a[f+2],23,-995338651),d,h,a[f+0],6,-198630844),h=b(h,u,l,d,a[f+7],10,1126891415),d=b(d,h,u,l,a[f+14],15,-1416354905),l=b(l,d,h,u,a[f+5],21,-57434055),u=b(u,l,d,h,a[f+12],6,1700485571),h=b(h,u,l,d,a[f+3],10,-1894986606),d=b(d,h,u,l,a[f+10],15,-1051523),l=b(l,d,h,u,a[f+1],21,-2054922799),u=b(u,l,d,h,a[f+8],6,1873313359),h=b(h,u,l,d,a[f+15],10,-30611744),d=b(d,h,u,l,a[f+6],15,-1560198380),l=b(l,d,h,u,a[f+13],21,1309151649),u=b(u,l,d,h,a[f+4],6,-145523070),h=b(h,u,l,d,a[f+11],10,-1120210379),d=b(d,h,u,l,a[f+2],15,718787259),l=b(l,d,h,u,a[f+9],21,-343485551),u=u+_>>>0,l=l+v>>>0,d=d+k>>>0,h=h+y>>>0}return t.endian([u,l,d,h])};s._ff=function(e,t,r,n,o,s,i){var a=e+(t&r|~t&n)+(o>>>0)+i;return(a<<s|a>>>32-s)+t},s._gg=function(e,t,r,n,o,s,i){var a=e+(t&n|r&~n)+(o>>>0)+i;return(a<<s|a>>>32-s)+t},s._hh=function(e,t,r,n,o,s,i){var a=e+(t^r^n)+(o>>>0)+i;return(a<<s|a>>>32-s)+t},s._ii=function(e,t,r,n,o,s,i){var a=e+(r^(t|~n))+(o>>>0)+i;return(a<<s|a>>>32-s)+t},s._blocksize=16,s._digestsize=16,e.exports=function(e,r){if(null==e)throw new Error("Illegal argument "+e);var n=t.wordsToBytes(s(e,r));return r&&r.asBytes?n:r&&r.asString?o.bytesToString(n):t.bytesToHex(n)}}()}));class kt{constructor(e){this.namespace=e||null,this.origin=d.location&&d.location.origin?vt(d.location.origin).substr(0,8):null}setItem(e,t){d.localStorage.setItem(this._getStorageKey(e),t)}getItem(e){return d.localStorage.getItem(this._getStorageKey(e))}removeItem(e){d.localStorage.removeItem(this._getStorageKey(e))}_getStorageKey(e){return this.namespace?[this.origin,this.namespace,e].join("."):e}}class yt{constructor(e){this.namespace=e||null,this.origin=d.location&&d.location.origin?vt(d.location.origin).substr(0,8):null}setItem(e,t){return Promise.resolve(d.localStorage.setItem(this._getStorageKey(e),t))}getItem(e){return Promise.resolve(d.localStorage.getItem(this._getStorageKey(e)))}removeItem(e){return Promise.resolve(d.localStorage.removeItem(this._getStorageKey(e)))}_getStorageKey(e){return this.namespace?[this.origin,this.namespace,e].join("."):e}}class wt{constructor(e){this.sdk=e,this.errorChain=[]}addToErrorChain(e,t){return"function"==typeof t?(this.errorChain.push({context:e,func:t}),this.sdk.options.debug):this.sdk.options.debug&&console.log("Cannot add function to error chain, not a function",e,t),this}__getTokenToUse(){var e=null;return this.sdk.token&&(this.sdk.options.debug&&console.log("Using stored token",this.sdk.token),e=this.sdk.token),!e&&this.sdk.options.tokenFallback&&(this.sdk.options.debug&&console.log("Token is now the fallback option",this.sdk.options.tokenFallback),e=this.sdk.options.tokenFallback),this.sdk.options.tokenOverride&&(this.sdk.options.debug&&console.log("Token is now the override option",this.sdk.options.tokenOverride),e=this.sdk.options.tokenOverride),e}__call(e,t){let r=this.__getTokenToUse(),n=this.sdk.browserIdentification;this.sdk.options.debug&&console.log("Using Identification",n),t.headers=Object.assign({},{Authorization:r,Identification:d.btoa(JSON.stringify(n))});let o=rt(this.sdk.options)+e,s=this.sdk.options.reqIndex++;return this.sdk.options.debug&&console.log(`> Request (${s}, ${r}):`,o,t),st(o,t)}__call_log(e,t){let r=function(e,t,r){t=t||e.instance;var n=e.baseUrl.replace("{{instance}}","log-"+t+"-"+r);return n=(n=n.replace("{{region}}",e.region)).replace("{{version}}",e.version)}(this.sdk.options,null,e).replace("/v1","/"),n=this.sdk.options.reqIndex++;return this.sdk.options.debug&&console.log("> XHR Bucket Request ("+n+"): ",r),$axios(r,t).catch(e=>{throw e})}__checkError(e,t){if(t.error){if(!this.errorChain.length)throw this.sdk.options.debug&&console.log("%cBackend error details","color: #FF3333",t),t;this.errorChain.forEach(e=>{e.func&&"function"==typeof e.func&&(this.sdk.options.debug&&console.log("Propagating error",t),e.func(e.context,t))})}}__sleep(e){return new Promise(t=>setTimeout(t,e))}}class Et extends wt{constructor(e){super(e),this.currentDatabase=null}serverInfo(){return this.__call("/__/server",{method:"GET"}).then(e=>e.result)}getAll(){return this.__call("/__/index",{method:"GET"}).then(e=>(this.__checkError(this,e),e&&e.result&&e.result.objects?e.result.objects:[]))}select(e){return this.currentDatabase=e,this}getSelected(){return this.currentDatabase}add(e){const t={method:"POST",data:e=e||{}};return this.__callDatabase(t).then(e=>(this.__checkError(this,e),e.result?e.result:e))}getRaw(e,t){let r="";e=e||{},t&&(r="?"+function e(t,r){var n,o=[];for(n in t)if(t.hasOwnProperty(n)){var s=r?r+"["+n+"]":n,i=t[n];o.push(null!==i&&"object"==typeof i?e(i,s):encodeURIComponent(s)+"="+encodeURIComponent(i))}return o.join("&")}(t,"_fields"));const n={method:"GET",params:e};return this.__callDatabase(n,r).then(e=>(this.__checkError(this,e),e))}get(e,t){return this.getRaw(e,t).then(e=>e.result?e.result:[])}getOne(e){(e=e||{})._limit=1;const t={method:"GET",params:e};return this.__callDatabase(t).then(e=>(this.__checkError(this,e),!(!e.result||!e.result[0])&&e.result[0]))}getCount(e){const t={method:"GET",params:e=e||{}};return this.__callDatabase(t,"/count").then(e=>(this.__checkError(this,e),e.result?parseInt(e.result):0))}update(e,t){const r={method:"PUT",data:t=t||{}};return this.__callDatabase(r,"/"+e).then(t=>(this.__checkError(this,t),"user"==this.currentDatabase&&e==this.sdk.currentUser._id&&t.result&&t.result.update&&t.result.data&&t.result.data._id==e&&(this.sdk.currentUser=t.result.data),t.result?t.result:t))}updateByFieldValue(e,t,r){const n={method:"PUT",data:r=r||{}};return this.__callDatabase(n,"/"+encodeURIComponent(e)+"/"+encodeURIComponent(t)).then(e=>(this.__checkError(this,e),e.result?e.result:e))}delete(e){return this.__callDatabase({method:"DELETE"},"/"+e).then(e=>(this.__checkError(this,e),e.result?e.result:e))}deleteByFieldValue(e,t){return this.__callDatabase({method:"DELETE"},"/"+encodeURIComponent(e)+"/"+encodeURIComponent(t)).then(e=>(this.__checkError(this,e),e.result?e.result:e))}fieldExists(e){}addField(e){}getFields(e){const t={method:"GET",params:e=e||{}};return this.__callDatabase(t,"/structure/fields").then(e=>(this.__checkError(this,e),e.result?e.result:[]))}getStructure(e){const t={method:"GET",params:e=e||{}};return this.__callDatabase(t,"/structure").then(e=>(this.__checkError(this,e),e.result?e.result:[]))}getFilters(e){const t={method:"GET",params:e=e||{}};return this.__callDatabase(t,"/structure/filters").then(e=>(this.__checkError(this,e),e.result?e.result:[]))}getViews(e){const t={method:"GET",params:e=e||{}};return this.__callDatabase(t,"/structure/views").then(e=>(this.__checkError(this,e),e.result?e.result:[]))}getDistinct(e,t){return this.__callDatabase({method:"GET"},"/"+encodeURIComponent(e)+"/distinct").then(e=>(this.__checkError(this,e),e.result?e.result:e))}messages(){const e=this;return null===e.currentDatabase?Promise.reject(new Error("Please select a database")):{add(t,r){if(!t)return Promise.reject(new Error("Please specify a record Id"));const n={method:"POST",data:{database:e.currentDatabase,record_id:t,message:r}};return e.__call("/__/message-stream",n).then(e=>e.result||[])},notify(t,r,n,o){if(!t)return Promise.reject(new Error("Please specify a record Id"));o=o||"mention";const s={method:"POST",data:{database:e.currentDatabase,record_id:t,message:{content:[n]},from:e.currentUser,to:{email:r},type:o}};return e.__call(`/__/message-stream/${e.currentDatabase}/${t}/notify`,s).then(e=>e.result||[])},get(t,r){if(!t)return Promise.reject(new Error("Please specify a record Id"));const n={method:"GET",params:r};return e.__call(`/__/message-stream/${e.currentDatabase}/${t}`,n).then(e=>e.result||[])},delete(t){if(!t)return Promise.reject(new Error("Please specify a record Id"));return e.__call("/__/message-stream/"+t,{method:"DELETE"}).then(e=>e.result)}}}getDistinctCount(e,t){}iterator(e,r){var o,i=this;return(o=function*(){let t,o=0;do{t=yield n(i.get(s(s({},e),{},{_offset:o,_limit:10}),r));for(const e of t)yield e;o+=10,yield n(i.__sleep(1e3))}while(10==t.length)},function(){return new t(o.apply(this,arguments))})()}__callDatabase(e,t){return t=t||"",null===this.currentDatabase?Promise.reject(new Error("Please select a database")):this.__call("/"+this.currentDatabase+t,e)}}class St extends wt{constructor(e){super(e)}getAll(){return this.__call("/__/function",{method:"GET"}).then(e=>e.result)}run(e,t){const r={method:"POST",data:t=t||!1};return this.__call("/__/function/"+e,r).then(e=>e.result?e.result:e)}getFunctionIdUrl(e){return rt(this.sdk.options)+"/__/function/"+e+"?token="+this.__getTokenToUse()}}class Tt extends wt{constructor(e){super(e)}upload(e){const t={method:"POST",data:e=e||{}};return this.__call("/__/storage",t).then(e=>(this.__checkError(this,e),e.result?e.result:e))}uploadBase64(e,t){return this.upload({file_name:e,file_base64:t})}getAll(){return this.__call("/__/storage",{method:"GET"}).then(e=>e.result)}getUploadUrl(){return rt(this.sdk.options)+"/__/storage?token="+this.__getTokenToUse()}includeToken(e,t){let r=t&&t.resize;return e&&-1!=e.indexOf("__/storage/static/")&&(r&&(e=e.replace("__/storage/static/","__/storage/static/w_250/")),-1==e.indexOf("?token=")&&-1==e.indexOf("&token=")&&(e=-1==e.indexOf("?")?e+"?token="+this.__getTokenToUse():e+"&token="+this.__getTokenToUse())),e}}class xt extends wt{constructor(e){super(e)}get(){const e=this;return this.__call("/__/remote-config",{method:"GET"}).then(t=>{if("object"==typeof t){var r=e.sdk.options.defaultConfig;return Object.keys(t).forEach(e=>{r[e]=t[e]}),r}return e.sdk.options.defaultConfig})}defaultConfig(e){this.sdk.options.defaultConfig=e}}class Ot extends wt{constructor(e){super(e),this.currentBucket=null}select(e){return this.currentBucket=e,this}add(e){return null===this.currentBucket?Promise.reject(new Error("Please select a bucket")):this.log(this.currentBucket,e)}log(e,t){if(!Number.isInteger(e))return void(this.sdk.options.debug&&console.log("Bucket name should be an integer and not",e));if("object"!=typeof t)return void(this.sdk.options.debug&&console.log("Bucket params should be send as object and not "+typeof t,t));const r={method:"GET",params:t};return this.__call_log(e,r)}}class jt extends wt{constructor(e){super(e)}add(e){let t={p:e,__token:this.__getTokenToUse(),__identification:this.sdk.browserIdentification};window.location&&window.location.href&&(t.u=window.location.href);const r={method:"GET",params:t};return this.__call_log(0,r)}}var At="1.1.7";class Pt{constructor(e){const t=this;let r=Object.assign({},ut,e);t.options=r;let n="<%= previolet"+String.fromCharCode(46);if(r.debug&&console.log(`%cPreviolet Javascript SDK (v${At}) instantiated in debug mode`,"color: #CC00FF"),r.instance&&r.instance==n+"options.instance %>"&&r.fallback&&r.fallback.instance&&(r.debug&&console.log("Using fallback instance",r.fallback.instance),r.instance=r.fallback.instance),r.tokenFallback&&r.tokenOverride)throw"Cannot define both tokenFallback and tokenOverride";if(r.tokenFallback&&r.tokenFallback==n+"token.guest %>"&&(r.fallback&&r.fallback.tokenFallback?(r.debug&&console.log("Using fallback tokenFallback",r.fallback.tokenFallback),r.tokenFallback=r.fallback.tokenFallback):(r.debug&&console.log("No fallback tokenFallback provided, defaulting to false"),r.tokenFallback=!1)),r.tokenOverride&&r.tokenOverride==n+"token.guest %>"&&(r.fallback&&r.fallback.tokenOverride?(r.debug&&console.log("Using fallback tokenOverride",r.fallback.tokenOverride),r.tokenOverride=r.fallback.tokenOverride):(r.debug&&console.log("No fallback tokenOverride provided, defaulting to false"),r.tokenOverride=!1)),r.instance==n+"options.instance %>"){const e=process.env.PREVIOLET_INSTANCE||process.env.VUE_APP_PREVIOLET_INSTANCE;process&&process.env&&e?(console.log("Using environment variable as instance",e),r.instance=e):console.log("PREVIOLET_INSTANCE or VUE_APP_PREVIOLET_INSTANCE environment variable not found")}"fetch"==r.requestAdapterName&&(r.debug&&console.log("Switching to fetch axios adapter"),it(ct)),null!==r.xhrAdapter&&(r.debug&&console.log("Switching to custom axios adapter"),it(r.xhrAdapter));let o=!1,i=null,a=null,c=null,u={};t.changeHooks=[];let l={ua:h.userAgent,lang:h.language||h.userLanguage,plat:h.platform,vsdk:t.options.sdkVersion,vapp:t.options.appVersion,ver:t.options.version,dspm:ot()};"undefined"!=typeof __previoletRayId&&(l.ray=__previoletRayId),t.onAuthDataCallback=e=>e,t.storageApi=function(e){if(null!==e.localStorageObject)return e.localStorageObject;switch(e.debug&&e.localStorageAsync&&console.log("Using AsyncLocalStorage"),e.storageType){case"localStorage":try{return d.localStorage.setItem("testKey","test"),d.localStorage.removeItem("testKey"),e.localStorageAsync?new yt(e.storageNamespace):new kt(e.storageNamespace)}catch(e){}default:return e.localStorageAsync?new yt(e.storageNamespace):new kt(e.storageNamespace)}}(r),t.auth=()=>({GithubAuthProvider:{id:"github"},GoogleAuthProvider:{id:"google"},FacebookAuthProvider:{id:"facebook"},logout:e=>{if(!t.auth().isAuthenticated())return this.options.debug&&console.log("There is no authenticated user"),!1;(e=e||{}).preventUserStatePropagation=e.preventUserStatePropagation||!1;const r={method:"DELETE",data:JSON.stringify({token:t.token})};return t.options.debug&&console.log("Logging Out"),t.token=!1,t.currentUser=null,t.storageApi.removeItem(t.options.tokenName),t.storageApi.removeItem(t.options.applicationStorage),t.storageApi.removeItem(t.options.userStorage),e.preventUserStatePropagation||t.__propagateUserState(!1),t.__call("/__/token",r,"token").then(e=>e)},loginWithUsernameAndPassword:(e,r)=>{if(!e)return Promise.reject(new Error("username required"));if(!r)return Promise.reject(new Error("password required"));t.options.debug&&console.log("Logging In with username and password",e,r);const n={method:"POST",data:JSON.stringify({name:e,challenge:r,expire:t.options.userTokenExpiration})};return t.__call("/__/auth",n).then(e=>(t.__checkError(t,e),e&&e.result&&e.result.emailSent?e.result:(e=t.onAuthDataCallback(e),t.__loadAuthenticationDataFromResponse(e),null!==t.currentUser&&t.__propagateUserState(t.currentUser),e.result.data)))},loginWithIdentityProvider:(e,r)=>{r=r||this.lastAccessToken,this.lastAccessToken=r,this.options.debug&&console.log("Logging In with identity provider:",e,r);const n={method:"POST",params:{access_token:r}};return this.__call("/__/auth/identity/"+e,n).then(e=>(this.__checkError(t,e),e.result?e.result&&(e.result.token&&e.result.auth?(e=t.onAuthDataCallback(e),t.__loadAuthenticationDataFromResponse(e),t.__propagateUserState(e.result.auth)):t.__propagateUserState(!1)):t.__propagateUserState(!1),e.result))},loginWithUsernameAndPin:(e,r)=>t.auth().loginWithUsernameAndPassword(e,"_pin:"+r),sendLoginPin:e=>t.auth().loginWithUsernameAndPassword(e,"_sendEmailPin"),forgotPassword:(e,r)=>{if(!e)return Promise.reject(new Error("username required"));let n=r&&r.origin?r.origin:d.location.origin,o=!(!r||!r.skip_email)&&r.skip_email;const s={method:"POST",data:JSON.stringify({name:e,origin:n,skip_email:o})};return t.__call("/__/auth/reset",s).then(e=>(t.__checkError(t,e),e.result))},forgotPasswordConfirmation:(e,r,n)=>{if(!e)return Promise.reject(new Error("challenge required"));if(!r)return Promise.reject(new Error("confirm_challenge required"));if(!n)return Promise.reject(new Error("hash required"));const o={method:"POST",data:JSON.stringify({challenge:e,confirm_challenge:r,hash:n})};return t.__call("/__/auth/reset/confirm",o).then(e=>(t.__checkError(t,e),e.result))},registerWithIdentityProvider:(e,r,n,o)=>{n=n||this.lastAccessToken,o=o||!0,this.lastAccessToken=n;const s={method:"POST",data:{access_token:n,email:r,role:"admin"}};return this.__call("/__/auth/identity/"+e+"/register",s).then(r=>(this.__checkError(t,r),o?this.loginWithIdentityProvider(e,n):r))},isAuthenticated:()=>{let e=this.token;return("string"!=typeof e||"null"!==e)&&!!e},loginAsGuest:()=>{const e={method:"POST",data:JSON.stringify({expire:t.options.guestTokenExpiration})};return t.__call("/__/auth/guest",e).then(e=>{if(!e.error_code)return e=t.onAuthDataCallback(e),t.__loadAuthenticationDataFromResponse(e),null!==t.currentUser&&t.__propagateUserState(t.currentUser),e.result.data;t.auth().logout()})},onAuthStateChanged:async e=>{if(await t.resourcesToLoad,"function"==typeof e){-1==t.changeHooks.indexOf(e)?(t.options.debug&&console.log("Registered callback function: onAuthStateChanged",e),t.changeHooks.push(e)):t.options.debug&&console.log("Callback function onAuthStateChanged is already registered",e);let r=t.currentUser,n=t.token;return t.options.debug&&(r&&n?console.log("User is logged in",r):console.log("User is not logged in")),e(!(!n||!r)&&r)}return t.options.debug&&console.log("User is not logged in"),!1},onAuthData:e=>{"function"==typeof e&&(t.onAuthDataCallback=e,t.options.debug&&console.log("Replacing onAuthData callback with custom one",e))},getToken:()=>this.db().__getTokenToUse(),getCurrentUser:()=>this.currentUser}),Object.defineProperties(t,{token:{get:()=>o,set(e){e!=o&&(o=e,t.storageApi.setItem(r.tokenName,o))}},headers:{get:()=>u},currentApp:{get:()=>i,set(e){i=e,t.initialSetupCompleted&&t.storageApi.setItem(r.applicationStorage,nt(e,r.localStorageEncode))}},currentUser:{get:()=>a,set(e){a=e,t.initialSetupCompleted&&t.storageApi.setItem(r.userStorage,nt(e,r.localStorageEncode))}},browserIdentification:{get:()=>c,set(e){var n,o;c=e,r.debug&&console.log("Setting brower identification",e),e&&(e.ts=e.ts||Date.now(),e.rnd=e.rnd||(n=(n=1e5)||100,o=(o=999999)||999,Math.floor(Math.random()*o+n)),t.storageApi.setItem(r.browserIdentification,nt(e,r.localStorageEncode)))}}});let f=new Et(t).addToErrorChain(t,t.__checkError);t.db=()=>f;let p=new St(t).addToErrorChain(t,t.__checkError);t.functions=()=>p;let g=new Tt(t).addToErrorChain(t,t.__checkError);t.storage=()=>g;let m=new xt(t).addToErrorChain(t,t.__checkError);t.remoteConfig=()=>m;let b=new Ot(t).addToErrorChain(t,t.__checkError);t.bucket=()=>b;let _=new jt(t).addToErrorChain(t,t.__checkError);t.trace=()=>_,t.version=()=>t.options.sdkVersion,t.app=()=>({region:t.options.region,token:t.token,data:t.currentApp}),t.user=()=>({data:t.currentUser});t.resourcesToLoad=(async e=>{let[t,r,n,o]=await Promise.all([e.storageApi.getItem(e.options.tokenName),e.__storageGet(e.options.userStorage),e.__storageGet(e.options.applicationStorage),e.__storageGet(e.options.browserIdentification)]);if(e.token=t,e.currentUser=r,e.currentApp=n,e.browserIdentification=o,e.browserIdentification){e.options.debug&&console.log("Browser identification exists: ",e.browserIdentification);let t=s(s({},l),{},{ts:e.browserIdentification.ts,rnd:e.browserIdentification.rnd});JSON.stringify(t)!=JSON.stringify(e.browserIdentification)&&(e.options.debug&&console.log("Browser identification changed, renewing",t),e.browserIdentification=t)}else e.browserIdentification=s({},l),e.options.debug&&console.log("Generating browser identification",e.browserIdentification);return e.initialSetupCompleted=!0,Promise.resolve(!0)})(t)}getDefaultHeaders(){return Object.assign({},this.headers,{})}getRemoteConfig(){const e=this;return this.functions().getRemoteConfig().then(t=>{if("object"==typeof t){let r=e.options.defaultConfig;return Object.keys(t).forEach(e=>{r[e]=t[e]}),r}return e.options.defaultConfig})}updateOptions(e){const t=this;t.options=Object.assign({},t.options,e),t.options.debug&&console.log("Updated SDK Options",t.options)}__propagateUserState(e){const t=this;t.changeHooks.forEach(r=>{t.options.debug&&console.log("Triggering onAuthStateChanged callback",e),r(e)})}__loadAuthenticationDataFromResponse(e){e.result.token&&(this.options.debug&&console.log("Saving token",e.result.token),this.token=e.result.token),e.result.auth?(this.options.debug&&console.log("Saving user details",e.result.auth),this.currentUser=e.result.auth):(this.options.debug&&console.log("Saving default guest details"),this.currentUser={name:"Guest",username:"guest",guest:!0}),e.result.data&&(e.result.data[this.options.instance]&&e.result.data[this.options.instance].instance_data?(this.currentApp=e.result.data[this.options.instance].instance_data,this.options.debug&&console.log("Saving application details",this.currentApp)):this.options.debug&&console.log(