@betha-plataforma/oauth
Version:
Biblioteca JavaScript para lidar com o fluxo do OAuth 2.0 em aplicações Web, com suporte a TypeScript.
8 lines • 43 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.OAuth=e():t.OAuth=e()}(window,(function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=13)}([function(t,e,r){"use strict";var n=r(6),i=r(7),o=r(3);t.exports={formats:o,parse:i,stringify:n}},function(t,e,r){var n,i;
/*!
* JavaScript Cookie v2.2.1
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/!function(o){if(void 0===(i="function"==typeof(n=o)?n.call(e,r,e,t):n)||(t.exports=i),!0,t.exports=o(),!!0){var s=window.Cookies,a=window.Cookies=o();a.noConflict=function(){return window.Cookies=s,a}}}((function(){function t(){for(var t=0,e={};t<arguments.length;t++){var r=arguments[t];for(var n in r)e[n]=r[n]}return e}function e(t){return t.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}return function r(n){function i(){}function o(e,r,o){if("undefined"!=typeof document){"number"==typeof(o=t({path:"/"},i.defaults,o)).expires&&(o.expires=new Date(1*new Date+864e5*o.expires)),o.expires=o.expires?o.expires.toUTCString():"";try{var s=JSON.stringify(r);/^[\{\[]/.test(s)&&(r=s)}catch(t){}r=n.write?n.write(r,e):encodeURIComponent(String(r)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),e=encodeURIComponent(String(e)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var a="";for(var c in o)o[c]&&(a+="; "+c,!0!==o[c]&&(a+="="+o[c].split(";")[0]));return document.cookie=e+"="+r+a}}function s(t,r){if("undefined"!=typeof document){for(var i={},o=document.cookie?document.cookie.split("; "):[],s=0;s<o.length;s++){var a=o[s].split("="),c=a.slice(1).join("=");r||'"'!==c.charAt(0)||(c=c.slice(1,-1));try{var u=e(a[0]);if(c=(n.read||n)(c,u)||e(c),r)try{c=JSON.parse(c)}catch(t){}if(i[u]=c,t===u)break}catch(t){}}return t?i[t]:i}}return i.set=o,i.get=function(t){return s(t,!1)},i.getJSON=function(t){return s(t,!0)},i.remove=function(e,r){o(e,"",t(r,{expires:-1}))},i.defaults={},i.withConverter=r,i}((function(){}))}))},function(t,e,r){"use strict";var n=Object.prototype.hasOwnProperty,i=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),o=function(t,e){for(var r=e&&e.plainObjects?Object.create(null):{},n=0;n<t.length;++n)void 0!==t[n]&&(r[n]=t[n]);return r};t.exports={arrayToObject:o,assign:function(t,e){return Object.keys(e).reduce((function(t,r){return t[r]=e[r],t}),t)},compact:function(t){for(var e=[{obj:{o:t},prop:"o"}],r=[],n=0;n<e.length;++n)for(var i=e[n],o=i.obj[i.prop],s=Object.keys(o),a=0;a<s.length;++a){var c=s[a],u=o[c];"object"==typeof u&&null!==u&&-1===r.indexOf(u)&&(e.push({obj:o,prop:c}),r.push(u))}return function(t){for(var e;t.length;){var r=t.pop();if(e=r.obj[r.prop],Array.isArray(e)){for(var n=[],i=0;i<e.length;++i)void 0!==e[i]&&n.push(e[i]);r.obj[r.prop]=n}}return e}(e)},decode:function(t){try{return decodeURIComponent(t.replace(/\+/g," "))}catch(e){return t}},encode:function(t){if(0===t.length)return t;for(var e="string"==typeof t?t:String(t),r="",n=0;n<e.length;++n){var o=e.charCodeAt(n);45===o||46===o||95===o||126===o||o>=48&&o<=57||o>=65&&o<=90||o>=97&&o<=122?r+=e.charAt(n):o<128?r+=i[o]:o<2048?r+=i[192|o>>6]+i[128|63&o]:o<55296||o>=57344?r+=i[224|o>>12]+i[128|o>>6&63]+i[128|63&o]:(n+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(n)),r+=i[240|o>>18]+i[128|o>>12&63]+i[128|o>>6&63]+i[128|63&o])}return r},isBuffer:function(t){return null!=t&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},merge:function t(e,r,i){if(!r)return e;if("object"!=typeof r){if(Array.isArray(e))e.push(r);else{if("object"!=typeof e)return[e,r];(i.plainObjects||i.allowPrototypes||!n.call(Object.prototype,r))&&(e[r]=!0)}return e}if("object"!=typeof e)return[e].concat(r);var s=e;return Array.isArray(e)&&!Array.isArray(r)&&(s=o(e,i)),Array.isArray(e)&&Array.isArray(r)?(r.forEach((function(r,o){n.call(e,o)?e[o]&&"object"==typeof e[o]?e[o]=t(e[o],r,i):e.push(r):e[o]=r})),e):Object.keys(r).reduce((function(e,o){var s=r[o];return n.call(e,o)?e[o]=t(e[o],s,i):e[o]=s,e}),s)}}},function(t,e,r){"use strict";var n=String.prototype.replace,i=/%20/g;t.exports={default:"RFC3986",formatters:{RFC1738:function(t){return n.call(t,i,"+")},RFC3986:function(t){return t}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},function(t,e,r){"use strict";t.exports=function(t){return null!==t&&"object"==typeof t}},function(t,e,r){var n;"undefined"!=typeof window?n=window:"undefined"!=typeof self?n=self:(console.warn("Using browser-only version of superagent in non-browser environment"),n=this);var i=r(8),o=r(9),s=r(4),a=r(10),c=r(12);function u(){}var h=e=t.exports=function(t,r){return"function"==typeof r?new e.Request("GET",t).end(r):1==arguments.length?new e.Request("GET",t):new e.Request(t,r)};e.Request=m,h.getXHR=function(){if(!(!n.XMLHttpRequest||n.location&&"file:"==n.location.protocol&&n.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}throw Error("Browser-only version of superagent could not find XHR")};var l="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};function p(t){if(!s(t))return t;var e=[];for(var r in t)d(e,r,t[r]);return e.join("&")}function d(t,e,r){if(null!=r)if(Array.isArray(r))r.forEach((function(r){d(t,e,r)}));else if(s(r))for(var n in r)d(t,e+"["+n+"]",r[n]);else t.push(encodeURIComponent(e)+"="+encodeURIComponent(r));else null===r&&t.push(encodeURIComponent(e))}function f(t){for(var e,r,n={},i=t.split("&"),o=0,s=i.length;o<s;++o)-1==(r=(e=i[o]).indexOf("="))?n[decodeURIComponent(e)]="":n[decodeURIComponent(e.slice(0,r))]=decodeURIComponent(e.slice(r+1));return n}function y(t){return/[\/+]json($|[^-\w])/.test(t)}function v(t){this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||void 0===this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText;var e=this.xhr.status;1223===e&&(e=204),this._setStatusProperties(e),this.header=this.headers=function(t){for(var e,r,n,i,o=t.split(/\r?\n/),s={},a=0,c=o.length;a<c;++a)-1!==(e=(r=o[a]).indexOf(":"))&&(n=r.slice(0,e).toLowerCase(),i=l(r.slice(e+1)),s[n]=i);return s}(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),null===this.text&&t._responseType?this.body=this.xhr.response:this.body="HEAD"!=this.req.method?this._parseBody(this.text?this.text:this.xhr.response):null}function m(t,e){var r=this;this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",(function(){var t,e=null,n=null;try{n=new v(r)}catch(t){return(e=new Error("Parser is unable to parse the response")).parse=!0,e.original=t,r.xhr?(e.rawResponse=void 0===r.xhr.responseType?r.xhr.responseText:r.xhr.response,e.status=r.xhr.status?r.xhr.status:null,e.statusCode=e.status):(e.rawResponse=null,e.status=null),r.callback(e)}r.emit("response",n);try{r._isResponseOK(n)||(t=new Error(n.statusText||"Unsuccessful HTTP response"))}catch(e){t=e}t?(t.original=e,t.response=n,t.status=n.status,r.callback(t,n)):r.callback(null,n)}))}function g(t,e,r){var n=h("DELETE",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n}h.serializeObject=p,h.parseString=f,h.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},h.serialize={"application/x-www-form-urlencoded":p,"application/json":JSON.stringify},h.parse={"application/x-www-form-urlencoded":f,"application/json":JSON.parse},a(v.prototype),v.prototype._parseBody=function(t){var e=h.parse[this.type];return this.req._parser?this.req._parser(this,t):(!e&&y(this.type)&&(e=h.parse["application/json"]),e&&t&&(t.length||t instanceof Object)?e(t):null)},v.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,n="cannot "+e+" "+r+" ("+this.status+")",i=new Error(n);return i.status=this.status,i.method=e,i.url=r,i},h.Response=v,i(m.prototype),o(m.prototype),m.prototype.type=function(t){return this.set("Content-Type",h.types[t]||t),this},m.prototype.accept=function(t){return this.set("Accept",h.types[t]||t),this},m.prototype.auth=function(t,e,r){1===arguments.length&&(e=""),"object"==typeof e&&null!==e&&(r=e,e=""),r||(r={type:"function"==typeof btoa?"basic":"auto"});var n=function(t){if("function"==typeof btoa)return btoa(t);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(t,e,r,n)},m.prototype.query=function(t){return"string"!=typeof t&&(t=p(t)),t&&this._query.push(t),this},m.prototype.attach=function(t,e,r){if(e){if(this._data)throw Error("superagent can't mix .send() and .attach()");this._getFormData().append(t,e,r||e.name)}return this},m.prototype._getFormData=function(){return this._formData||(this._formData=new n.FormData),this._formData},m.prototype.callback=function(t,e){if(this._shouldRetry(t,e))return this._retry();var r=this._callback;this.clearTimeout(),t&&(this._maxRetries&&(t.retries=this._retries-1),this.emit("error",t)),r(t,e)},m.prototype.crossDomainError=function(){var t=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");t.crossDomain=!0,t.status=this.status,t.method=this.method,t.url=this.url,this.callback(t)},m.prototype.buffer=m.prototype.ca=m.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},m.prototype.pipe=m.prototype.write=function(){throw Error("Streaming is not supported in browser version of superagent")},m.prototype._isHost=function(t){return t&&"object"==typeof t&&!Array.isArray(t)&&"[object Object]"!==Object.prototype.toString.call(t)},m.prototype.end=function(t){return this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=t||u,this._finalizeQueryString(),this._end()},m.prototype._end=function(){var t=this,e=this.xhr=h.getXHR(),r=this._formData||this._data;this._setTimeouts(),e.onreadystatechange=function(){var r=e.readyState;if(r>=2&&t._responseTimeoutTimer&&clearTimeout(t._responseTimeoutTimer),4==r){var n;try{n=e.status}catch(t){n=0}if(!n){if(t.timedout||t._aborted)return;return t.crossDomainError()}t.emit("end")}};var n=function(e,r){r.total>0&&(r.percent=r.loaded/r.total*100),r.direction=e,t.emit("progress",r)};if(this.hasListeners("progress"))try{e.onprogress=n.bind(null,"download"),e.upload&&(e.upload.onprogress=n.bind(null,"upload"))}catch(t){}try{this.username&&this.password?e.open(this.method,this.url,!0,this.username,this.password):e.open(this.method,this.url,!0)}catch(t){return this.callback(t)}if(this._withCredentials&&(e.withCredentials=!0),!this._formData&&"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof r&&!this._isHost(r)){var i=this._header["content-type"],o=this._serializer||h.serialize[i?i.split(";")[0]:""];!o&&y(i)&&(o=h.serialize["application/json"]),o&&(r=o(r))}for(var s in this.header)null!=this.header[s]&&this.header.hasOwnProperty(s)&&e.setRequestHeader(s,this.header[s]);return this._responseType&&(e.responseType=this._responseType),this.emit("request",this),e.send(void 0!==r?r:null),this},h.agent=function(){return new c},["GET","POST","OPTIONS","PATCH","PUT","DELETE"].forEach((function(t){c.prototype[t.toLowerCase()]=function(e,r){var n=new h.Request(t,e);return this._setDefaults(n),r&&n.end(r),n}})),c.prototype.del=c.prototype.delete,h.get=function(t,e,r){var n=h("GET",t);return"function"==typeof e&&(r=e,e=null),e&&n.query(e),r&&n.end(r),n},h.head=function(t,e,r){var n=h("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&n.query(e),r&&n.end(r),n},h.options=function(t,e,r){var n=h("OPTIONS",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},h.del=g,h.delete=g,h.patch=function(t,e,r){var n=h("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},h.post=function(t,e,r){var n=h("POST",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n},h.put=function(t,e,r){var n=h("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&n.send(e),r&&n.end(r),n}},function(t,e,r){"use strict";var n=r(2),i=r(3),o={brackets:function(t){return t+"[]"},indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},s=Date.prototype.toISOString,a={delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,serializeDate:function(t){return s.call(t)},skipNulls:!1,strictNullHandling:!1},c=function t(e,r,i,o,s,c,u,h,l,p,d,f){var y=e;if("function"==typeof u)y=u(r,y);else if(y instanceof Date)y=p(y);else if(null===y){if(o)return c&&!f?c(r,a.encoder):r;y=""}if("string"==typeof y||"number"==typeof y||"boolean"==typeof y||n.isBuffer(y))return c?[d(f?r:c(r,a.encoder))+"="+d(c(y,a.encoder))]:[d(r)+"="+d(String(y))];var v,m=[];if(void 0===y)return m;if(Array.isArray(u))v=u;else{var g=Object.keys(y);v=h?g.sort(h):g}for(var w=0;w<v.length;++w){var b=v[w];s&&null===y[b]||(m=Array.isArray(y)?m.concat(t(y[b],i(r,b),i,o,s,c,u,h,l,p,d,f)):m.concat(t(y[b],r+(l?"."+b:"["+b+"]"),i,o,s,c,u,h,l,p,d,f)))}return m};t.exports=function(t,e){var r=t,s=e?n.assign({},e):{};if(null!==s.encoder&&void 0!==s.encoder&&"function"!=typeof s.encoder)throw new TypeError("Encoder has to be a function.");var u=void 0===s.delimiter?a.delimiter:s.delimiter,h="boolean"==typeof s.strictNullHandling?s.strictNullHandling:a.strictNullHandling,l="boolean"==typeof s.skipNulls?s.skipNulls:a.skipNulls,p="boolean"==typeof s.encode?s.encode:a.encode,d="function"==typeof s.encoder?s.encoder:a.encoder,f="function"==typeof s.sort?s.sort:null,y=void 0!==s.allowDots&&s.allowDots,v="function"==typeof s.serializeDate?s.serializeDate:a.serializeDate,m="boolean"==typeof s.encodeValuesOnly?s.encodeValuesOnly:a.encodeValuesOnly;if(void 0===s.format)s.format=i.default;else if(!Object.prototype.hasOwnProperty.call(i.formatters,s.format))throw new TypeError("Unknown format option provided.");var g,w,b=i.formatters[s.format];"function"==typeof s.filter?r=(w=s.filter)("",r):Array.isArray(s.filter)&&(g=w=s.filter);var _,x=[];if("object"!=typeof r||null===r)return"";_=s.arrayFormat in o?s.arrayFormat:"indices"in s?s.indices?"indices":"repeat":"indices";var T=o[_];g||(g=Object.keys(r)),f&&g.sort(f);for(var O=0;O<g.length;++O){var S=g[O];l&&null===r[S]||(x=x.concat(c(r[S],S,T,h,l,p?d:null,w,f,y,v,b,m)))}var C=x.join(u),k=!0===s.addQueryPrefix?"?":"";return C.length>0?k+C:""}},function(t,e,r){"use strict";var n=r(2),i=Object.prototype.hasOwnProperty,o={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:n.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},s=function(t,e,r){if(t){var n=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/g,s=/(\[[^[\]]*])/.exec(n),a=s?n.slice(0,s.index):n,c=[];if(a){if(!r.plainObjects&&i.call(Object.prototype,a)&&!r.allowPrototypes)return;c.push(a)}for(var u=0;null!==(s=o.exec(n))&&u<r.depth;){if(u+=1,!r.plainObjects&&i.call(Object.prototype,s[1].slice(1,-1))&&!r.allowPrototypes)return;c.push(s[1])}return s&&c.push("["+n.slice(s.index)+"]"),function(t,e,r){for(var n=e,i=t.length-1;i>=0;--i){var o,s=t[i];if("[]"===s)o=(o=[]).concat(n);else{o=r.plainObjects?Object.create(null):{};var a="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,c=parseInt(a,10);!isNaN(c)&&s!==a&&String(c)===a&&c>=0&&r.parseArrays&&c<=r.arrayLimit?(o=[])[c]=n:o[a]=n}n=o}return n}(c,e,r)}};t.exports=function(t,e){var r=e?n.assign({},e):{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.ignoreQueryPrefix=!0===r.ignoreQueryPrefix,r.delimiter="string"==typeof r.delimiter||n.isRegExp(r.delimiter)?r.delimiter:o.delimiter,r.depth="number"==typeof r.depth?r.depth:o.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:o.arrayLimit,r.parseArrays=!1!==r.parseArrays,r.decoder="function"==typeof r.decoder?r.decoder:o.decoder,r.allowDots="boolean"==typeof r.allowDots?r.allowDots:o.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:o.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:o.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:o.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:o.strictNullHandling,""===t||null==t)return r.plainObjects?Object.create(null):{};for(var a="string"==typeof t?function(t,e){for(var r={},n=e.ignoreQueryPrefix?t.replace(/^\?/,""):t,s=e.parameterLimit===1/0?void 0:e.parameterLimit,a=n.split(e.delimiter,s),c=0;c<a.length;++c){var u,h,l=a[c],p=l.indexOf("]="),d=-1===p?l.indexOf("="):p+1;-1===d?(u=e.decoder(l,o.decoder),h=e.strictNullHandling?null:""):(u=e.decoder(l.slice(0,d),o.decoder),h=e.decoder(l.slice(d+1),o.decoder)),i.call(r,u)?r[u]=[].concat(r[u]).concat(h):r[u]=h}return r}(t,r):t,c=r.plainObjects?Object.create(null):{},u=Object.keys(a),h=0;h<u.length;++h){var l=u[h],p=s(l,a[l],r);c=n.merge(c,p,r)}return n.compact(c)}},function(t,e,r){function n(t){if(t)return function(t){for(var e in n.prototype)t[e]=n.prototype[e];return t}(t)}t.exports=n,n.prototype.on=n.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},n.prototype.once=function(t,e){function r(){this.off(t,r),e.apply(this,arguments)}return r.fn=e,this.on(t,r),this},n.prototype.off=n.prototype.removeListener=n.prototype.removeAllListeners=n.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r,n=this._callbacks["$"+t];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i=0;i<n.length;i++)if((r=n[i])===e||r.fn===e){n.splice(i,1);break}return 0===n.length&&delete this._callbacks["$"+t],this},n.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),r=this._callbacks["$"+t],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(r){n=0;for(var i=(r=r.slice(0)).length;n<i;++n)r[n].apply(this,e)}return this},n.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},n.prototype.hasListeners=function(t){return!!this.listeners(t).length}},function(t,e,r){"use strict";var n=r(4);function i(t){if(t)return function(t){for(var e in i.prototype)t[e]=i.prototype[e];return t}(t)}t.exports=i,i.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,this},i.prototype.parse=function(t){return this._parser=t,this},i.prototype.responseType=function(t){return this._responseType=t,this},i.prototype.serialize=function(t){return this._serializer=t,this},i.prototype.timeout=function(t){if(!t||"object"!=typeof t)return this._timeout=t,this._responseTimeout=0,this;for(var e in t)switch(e){case"deadline":this._timeout=t.deadline;break;case"response":this._responseTimeout=t.response;break;default:console.warn("Unknown timeout option",e)}return this},i.prototype.retry=function(t,e){return 0!==arguments.length&&!0!==t||(t=1),t<=0&&(t=0),this._maxRetries=t,this._retries=0,this._retryCallback=e,this};var o=["ECONNRESET","ETIMEDOUT","EADDRINFO","ESOCKETTIMEDOUT"];i.prototype._shouldRetry=function(t,e){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{var r=this._retryCallback(t,e);if(!0===r)return!0;if(!1===r)return!1}catch(t){console.error(t)}if(e&&e.status&&e.status>=500&&501!=e.status)return!0;if(t){if(t.code&&~o.indexOf(t.code))return!0;if(t.timeout&&"ECONNABORTED"==t.code)return!0;if(t.crossDomain)return!0}return!1},i.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this._end()},i.prototype.then=function(t,e){if(!this._fullfilledPromise){var r=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise((function(t,e){r.end((function(r,n){r?e(r):t(n)}))}))}return this._fullfilledPromise.then(t,e)},i.prototype.catch=function(t){return this.then(void 0,t)},i.prototype.use=function(t){return t(this),this},i.prototype.ok=function(t){if("function"!=typeof t)throw Error("Callback required");return this._okCallback=t,this},i.prototype._isResponseOK=function(t){return!!t&&(this._okCallback?this._okCallback(t):t.status>=200&&t.status<300)},i.prototype.get=function(t){return this._header[t.toLowerCase()]},i.prototype.getHeader=i.prototype.get,i.prototype.set=function(t,e){if(n(t)){for(var r in t)this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},i.prototype.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},i.prototype.field=function(t,e){if(null==t)throw new Error(".field(name, val) name can not be empty");if(this._data&&console.error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()"),n(t)){for(var r in t)this.field(r,t[r]);return this}if(Array.isArray(e)){for(var i in e)this.field(t,e[i]);return this}if(null==e)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof e&&(e=""+e),this._getFormData().append(t,e),this},i.prototype.abort=function(){return this._aborted||(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort")),this},i.prototype._auth=function(t,e,r,n){switch(r.type){case"basic":this.set("Authorization","Basic "+n(t+":"+e));break;case"auto":this.username=t,this.password=e;break;case"bearer":this.set("Authorization","Bearer "+t)}return this},i.prototype.withCredentials=function(t){return null==t&&(t=!0),this._withCredentials=t,this},i.prototype.redirects=function(t){return this._maxRedirects=t,this},i.prototype.maxResponseSize=function(t){if("number"!=typeof t)throw TypeError("Invalid argument");return this._maxResponseSize=t,this},i.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},i.prototype.send=function(t){var e=n(t),r=this._header["content-type"];if(this._formData&&console.error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()"),e&&!this._data)Array.isArray(t)?this._data=[]:this._isHost(t)||(this._data={});else if(t&&this._data&&this._isHost(this._data))throw Error("Can't merge these send calls");if(e&&n(this._data))for(var i in t)this._data[i]=t[i];else"string"==typeof t?(r||this.type("form"),r=this._header["content-type"],this._data="application/x-www-form-urlencoded"==r?this._data?this._data+"&"+t:t:(this._data||"")+t):this._data=t;return!e||this._isHost(t)||r||this.type("json"),this},i.prototype.sortQuery=function(t){return this._sort=void 0===t||t,this},i.prototype._finalizeQueryString=function(){var t=this._query.join("&");if(t&&(this.url+=(this.url.indexOf("?")>=0?"&":"?")+t),this._query.length=0,this._sort){var e=this.url.indexOf("?");if(e>=0){var r=this.url.substring(e+1).split("&");"function"==typeof this._sort?r.sort(this._sort):r.sort(),this.url=this.url.substring(0,e)+"?"+r.join("&")}}},i.prototype._appendQueryString=function(){console.trace("Unsupported")},i.prototype._timeoutError=function(t,e,r){if(!this._aborted){var n=new Error(t+e+"ms exceeded");n.timeout=e,n.code="ECONNABORTED",n.errno=r,this.timedout=!0,this.abort(),this.callback(n)}},i.prototype._setTimeouts=function(){var t=this;this._timeout&&!this._timer&&(this._timer=setTimeout((function(){t._timeoutError("Timeout of ",t._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((function(){t._timeoutError("Response timeout of ",t._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))}},function(t,e,r){"use strict";var n=r(11);function i(t){if(t)return function(t){for(var e in i.prototype)t[e]=i.prototype[e];return t}(t)}t.exports=i,i.prototype.get=function(t){return this.header[t.toLowerCase()]},i.prototype._setHeaderProperties=function(t){var e=t["content-type"]||"";this.type=n.type(e);var r=n.params(e);for(var i in r)this[i]=r[i];this.links={};try{t.link&&(this.links=n.parseLinks(t.link))}catch(t){}},i.prototype._setStatusProperties=function(t){var e=t/100|0;this.status=this.statusCode=t,this.statusType=e,this.info=1==e,this.ok=2==e,this.redirect=3==e,this.clientError=4==e,this.serverError=5==e,this.error=(4==e||5==e)&&this.toError(),this.created=201==t,this.accepted=202==t,this.noContent=204==t,this.badRequest=400==t,this.unauthorized=401==t,this.notAcceptable=406==t,this.forbidden=403==t,this.notFound=404==t,this.unprocessableEntity=422==t}},function(t,e,r){"use strict";e.type=function(t){return t.split(/ *; */).shift()},e.params=function(t){return t.split(/ *; */).reduce((function(t,e){var r=e.split(/ *= */),n=r.shift(),i=r.shift();return n&&i&&(t[n]=i),t}),{})},e.parseLinks=function(t){return t.split(/ *, */).reduce((function(t,e){var r=e.split(/ *; */),n=r[0].slice(1,-1);return t[r[1].split(/ *= */)[1].slice(1,-1)]=n,t}),{})},e.cleanHeader=function(t,e){return delete t["content-type"],delete t["content-length"],delete t["transfer-encoding"],delete t.host,e&&(delete t.authorization,delete t.cookie),t}},function(t,e){function r(){this._defaults=[]}["use","on","once","set","query","type","accept","auth","withCredentials","sortQuery","retry","ok","redirects","timeout","buffer","serialize","parse","ca","key","pfx","cert"].forEach((function(t){r.prototype[t]=function(){return this._defaults.push({fn:t,arguments:arguments}),this}})),r.prototype._setDefaults=function(t){this._defaults.forEach((function(e){t[e.fn].apply(t,e.arguments)}))},t.exports=r},function(t,e,r){"use strict";r.r(e),r.d(e,"Authorization",(function(){return l})),r.d(e,"Introspect",(function(){return d})),r.d(e,"Api",(function(){return v})),r.d(e,"UserInfo",(function(){return y})),r.d(e,"OAuthApplication",(function(){return Q})),r.d(e,"OAuthMonitor",(function(){return J})),r.d(e,"parseResponse",(function(){return a})),r.d(e,"generateCodeChallengePair",(function(){return E})),r.d(e,"CodePKCEFlow",(function(){return H})),r.d(e,"ImplicitFlow",(function(){return I})),r.d(e,"parseFlow",(function(){return N})),r.d(e,"LastPageStore",(function(){return F})),r.d(e,"SessionStore",(function(){return B})),r.d(e,"UserStore",(function(){return $})),r.d(e,"TransactionManager",(function(){return D})),r.d(e,"resolveProvider",(function(){return V})),r.d(e,"parsePersistence",(function(){return O})),r.d(e,"CookiePersistence",(function(){return T}));var n=r(0),i=r(5),o=r.n(i),s=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};const a=t=>(t=>!!t&&"error"in t)(t)?Promise.reject((t=>({error:t.error,error_description:t.error_description,error_uri:t.error_uri}))(t)):(t=>s(void 0,void 0,void 0,(function*(){return t})))(t);var c=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};const u=({body:t,method:e="GET",query:r,retries:n=3,type:i="application/x-www-form-urlencoded",url:s})=>c(void 0,void 0,void 0,(function*(){try{const c=yield o()(e,s).retry(n).type(i).query(r).send(t).accept("json");return a(c.body)}catch(t){return Promise.reject({error:"invalid_request",error_description:"bad request for authorization server"})}}));var h=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};class l{constructor(t){this.getAuthorizeURL=(t,e=!1,r=!1,i={})=>{const o=Object.assign(Object.assign({client_id:this.config.clientId,prompt:e?"none":"login",redirect_uri:e?this.config.silentRedirectUri:this.config.redirectUri,scope:this.config.scope,access_mode:r?"anonymous":void 0},t),i);return`${this.config.provider.authorization_endpoint}?${Object(n.stringify)(o)}`},this.token=(t,e=!1)=>h(this,void 0,void 0,(function*(){const r=Object.assign({client_id:this.config.clientId,client_secret:this.config.clientSecret,redirect_uri:e?this.config.silentRedirectUri:this.config.redirectUri,scope:this.config.scope},t);return u({body:r,method:"POST",url:""+this.config.provider.token_endpoint})})),this.config=t}}var p=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};class d{constructor(t){this.get=t=>p(this,void 0,void 0,(function*(){return u({query:{access_token:t},url:this.config.provider.introspect_endpoint})})),this.config=t}}var f=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};class y{constructor(t){this.get=t=>f(this,void 0,void 0,(function*(){return u({query:{access_token:t},url:this.config.provider.userinfo_endpoint})})),this.config=t}}class v{constructor(t){this.authorization=new l(t),this.introspect=new d(t),this.userInfo=new y(t)}}const m=()=>window,g=t=>(m().location.href=t,Promise.resolve());class w{constructor(t,e){this.load=()=>new Promise(t=>{this.element.onload=()=>{t()},this.timeoutHandler=this.timeoutMillis?setTimeout(this.handleTimeout,this.timeoutMillis):void 0,this.window.document.body.appendChild(this.element),this.window.addEventListener("message",this.handleMessage,!1)}),this.destroy=()=>{clearTimeout(this.timeoutHandler),this.window.removeEventListener("message",this.handleMessage,!1),this.element.parentNode.removeChild(this.element)},this.postMessage=t=>{this.element.contentWindow.postMessage(t,this.targetOrigin)},this.isSameOrigin=t=>t.source===this.element.contentWindow,this.handleMessage=t=>this.isSameOrigin(t)?this.onMessage(t):void 0,this.handleTimeout=()=>(this.destroy(),this.onTimeout?this.onTimeout():void 0),this.onMessage=e.onMessage,this.window=t.window,this.timeoutMillis=t.timeout,this.element=((t,e)=>{const r=t.document.createElement("iframe");return r.style.display="none",r.style.visibility="hidden",r.style.position="absolute",r.style.width="0",r.style.height="0",r.src=e,r})(this.window,t.url),this.onTimeout=e.onTimeout,this.targetOrigin=t.url.substr(0,t.url.indexOf("/",t.url.indexOf("//")+2))}}var b=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};var _=r(1),x=r.n(_);class T{constructor(t){this.remove=t=>{const e=this.retrieve(t),r=this.storageKeyFor(t);return x.a.remove(r),e},this.retrieve=t=>{const e=this.storageKeyFor(t);return x.a.getJSON(e)},this.store=(t,e,r=1/48)=>{const n=this.storageKeyFor(t);return x.a.set(n,e,{expires:r}),e},this.storageKeyFor=t=>`br.com.betha.oauth.${this.config.clientId}.${t}`,this.config=t}}const O=t=>(t.persistence,new T(t));var S=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};const C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",k=t=>{const e=new Uint8Array(t);return window.crypto.getRandomValues(e),String.fromCharCode.apply(null,e.map(t=>C.charCodeAt(t%C.length)))};var A=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};const j=t=>{return btoa((e=t,String.fromCharCode(...e.match(/.{1,2}/g).map(t=>parseInt(t,16))))).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_");var e},P=t=>A(void 0,void 0,void 0,(function*(){const e=yield(r=t,S(void 0,void 0,void 0,(function*(){const t=(new TextEncoder).encode(r),e=yield window.crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(e)).map(t=>("00"+t.toString(16)).slice(-2)).join("")})));var r;return j(e)})),E=()=>A(void 0,void 0,void 0,(function*(){const t=k(32);return{challenge:yield P(t),verifier:t}})),R={ignoreQueryPrefix:!0,decoder(t){const e=t.replace(/\+/g," ");if(/^(\d+|\d*\.\d+)$/.test(t))return parseFloat(t);const r={false:!1,null:null,true:!0,undefined:void 0};if(t in r)return r[t];try{return decodeURIComponent(e)}catch(t){return e}}},U=t=>Object(n.parse)(t.slice(1),R);var z=new class{prepare(){return Promise.resolve()}navigate(t){return((t,e=3e4)=>b(void 0,void 0,void 0,(function*(){return new Promise((r,n)=>{const i=new w({timeout:e,url:t,window:m()},{onMessage:t=>{i.destroy(),r(t.data)},onTimeout:()=>{n()}});i.load()})})))(t)}callback(){return Promise.resolve()}};var L=new class{prepare(){return Promise.resolve()}navigate(t){return g(t)}callback(){return Promise.resolve()}};class D{constructor(t){this.startTransaction=t=>{const e={data:t,nonce:k(32),state:k(32)};return this.storage.store(e.state,e,1/48)},this.getStoredTransaction=t=>this.storage.remove(t),this.storage=t}}var q=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};class H{constructor(t,e){this.authorize=(t,e)=>q(this,void 0,void 0,(function*(){const t=yield this.getAuthorizeURL(!1,e);return L.navigate(t)})),this.handleAuthorizeResponse=()=>q(this,void 0,void 0,(function*(){return this.handleBasicAuthorize()})),this.silentAuthorize=()=>q(this,void 0,void 0,(function*(){const t=yield this.getAuthorizeURL(!1),e=yield z.navigate(t);return this.handleBasicAuthorize(e)})),this.exchangeCode=(t,e=!1)=>q(this,void 0,void 0,(function*(){const r=this.transactionManager.getStoredTransaction(t.state);return r?this.api.authorization.token({code:t.code,code_verifier:r&&r.data?r.data.verifier:void 0,grant_type:"authorization_code"},e):Promise.reject({error:"invalid_state",error_description:"application state not found"})})),this.handleBasicAuthorize=(t=(()=>m().location.search)())=>q(this,void 0,void 0,(function*(){const e=yield U(t),r=yield U(t);return{accessToken:yield this.exchangeCode(e),sessionState:r}})),this.getAuthorizeURL=(t=!1,e={})=>q(this,void 0,void 0,(function*(){const r=yield E(),n=this.transactionManager.startTransaction(r);return this.api.authorization.getAuthorizeURL({code_challenge:n.data.challenge,code_challenge_method:"S256",response_type:"code",state:n.state},t,!1,e)})),this.api=t,this.transactionManager=new D(e)}}var M=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};class I{constructor(t){this.authorize=(t=!1,e)=>{const r=this.getAuthorizeURL(!1,t,e);return L.navigate(r)},this.handleAuthorizeResponse=()=>M(this,void 0,void 0,(function*(){return this.handleBasicAuthorize()})),this.silentAuthorize=(t=!1)=>M(this,void 0,void 0,(function*(){const e=yield z.navigate(this.getAuthorizeURL(!0,t));return this.handleBasicAuthorize(e)})),this.handleBasicAuthorize=(t=(()=>m().location.hash)())=>M(this,void 0,void 0,(function*(){return{accessToken:yield U(t),sessionState:yield U(t)}})),this.getAuthorizeURL=(t=!1,e=!1,r={})=>this.api.authorization.getAuthorizeURL({response_type:"token"},t,e,r),this.api=t}}const N=(t,e,r)=>{switch(t){case"CODE_WITH_PKCE":return new H(e,r);case"IMPLICIT":default:return new I(e)}};class F{constructor(t){this.storeLastPage=()=>{const t={url:m().location.href};return this.storage.store("last_page",t,1/24),t.url},this.retrieveLastPage=()=>{const t=this.storage.remove("last_page");return t?t.url:"/"},this.storage=t}}class B{constructor(t){this.storeSession=t=>{const{expires_in:e}=t.accessToken;return this.storage.store("session",t,e/86400)},this.retrieveSession=()=>this.storage.retrieve("session"),this.clear=()=>{this.storage.remove("session")},this.storage=t}}class ${constructor(t){this.storeUser=t=>this.storage.store("user",t,1/24),this.retrieveUser=()=>this.storage.retrieve("user"),this.storage=t}}var X=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};class Q{constructor(t){this.login=(t=!1,e={})=>X(this,void 0,void 0,(function*(){return this.lastPageStore.storeLastPage(),this.flow.authorize(t,e)})),this.logout=t=>X(this,void 0,void 0,(function*(){return this.invalidateSession(),g(t||this.config.provider.end_session_endpoint)})),this.invalidateSession=()=>{this.sessionStore.clear()},this.silentRefresh=(t=!1)=>X(this,void 0,void 0,(function*(){const e=yield this.flow.silentAuthorize(t);return this.establishUserSession(e)})),this.getUser=()=>this.userStore.retrieveUser(),this.getSession=()=>this.sessionStore.retrieveSession(),this.handleCallback=()=>X(this,void 0,void 0,(function*(){const t=yield this.flow.handleAuthorizeResponse();yield this.establishUserSession(t);const e=this.lastPageStore.retrieveLastPage();return g(e)})),this.hasActiveSession=()=>{var t;const e=this.getSession();return!!e&&!!(null===(t=e.accessToken)||void 0===t?void 0:t.access_token)},this.establishUserSession=t=>X(this,void 0,void 0,(function*(){return this.sessionStore.storeSession(t),this.loadUser()})),this.loadUser=()=>X(this,void 0,void 0,(function*(){const t=this.getSession(),{access_token:e}=t.accessToken,r=yield this.api.userInfo.get(e);return this.userStore.storeUser(r)})),this.config=t,this.api=new v(t),this.storage=O(t),this.flow=N(t.flow,this.api,this.storage),this.lastPageStore=new F(this.storage),this.sessionStore=new B(this.storage),this.userStore=new $(this.storage)}}var K=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};class J{constructor({app:t,interval:e=1e3},{onSessionChanged:r=(()=>{}),onSessionEnded:n=(()=>{}),onSessionRestablished:i=(()=>{})}){this.start=()=>K(this,void 0,void 0,(function*(){return this.isRunning&&this.stop(),this.isRunning=!0,this.session=this.app.getSession(),this.frame=new w({url:this.app.config.provider.check_session_iframe,window:m()},{onMessage:this.handleMessage}),this.frame.load().then(()=>{this.timer=setInterval(this.checkSession,this.interval)})})),this.stop=()=>{if(this.isRunning)try{clearInterval(this.timer),this.frame.destroy(),this.currentStat="unchanged"}finally{this.isRunning=!1}},this.checkSession=()=>{this.session||(this.session=this.app.getSession());const t=`${this.app.config.clientId} ${this.session.sessionState.session_state}`;this.frame.postMessage(t)},this.handleMessage=t=>{const e=t.data;e===this.currentStat?"changed"===e&&this.handleChangedSameStatus():(this.currentStat=e,"changed"===e?this.handleChanged():"unchanged"===e&&this.handleUnchanged())},this.handleUnchanged=()=>K(this,void 0,void 0,(function*(){return this.handlers.onSessionRestablished(),this.start()})),this.handleChangedSameStatus=()=>K(this,void 0,void 0,(function*(){this.isSameUser()?this.usersChanged=!1:(this.usersChanged||this.handlers.onSessionChanged(),this.usersChanged=!0)})),this.handleChanged=()=>K(this,void 0,void 0,(function*(){const t=this.app;try{yield t.silentRefresh()}catch(e){return this.handlers.onSessionEnded(),t.invalidateSession()}return this.start()})),this.isSameUser=()=>{const t=this.app.getSession();return!t||t.accessToken.principal===this.session.accessToken.principal},this.app=t,this.currentStat="unchanged",this.interval=e,this.handlers={onSessionChanged:r,onSessionEnded:n,onSessionRestablished:i},this.isRunning=!1,this.usersChanged=!1}}var G=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{c(n.next(t))}catch(t){o(t)}}function a(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};const V=t=>G(void 0,void 0,void 0,(function*(){return u({url:t})}))}])}));