@authorizerdev/authorizer-js 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,17 @@
1
- var authorizerdev=(()=>{var ye=Object.create;var k=Object.defineProperty,_e=Object.defineProperties,me=Object.getOwnPropertyDescriptor,ge=Object.getOwnPropertyDescriptors,we=Object.getOwnPropertyNames,G=Object.getOwnPropertySymbols,be=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable;var P=(n,e,o)=>e in n?k(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o,q=(n,e)=>{for(var o in e||(e={}))W.call(e,o)&&P(n,o,e[o]);if(G)for(var o of G(e))Re.call(e,o)&&P(n,o,e[o]);return n},Z=(n,e)=>_e(n,ge(e)),a=(n,e)=>k(n,"name",{value:e,configurable:!0});var ve=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ee=(n,e)=>{for(var o in e)k(n,o,{get:e[o],enumerable:!0})},X=(n,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of we(e))!W.call(n,r)&&r!==o&&k(n,r,{get:()=>e[r],enumerable:!(s=me(e,r))||s.enumerable});return n};var Te=(n,e,o)=>(o=n!=null?ye(be(n)):{},X(e||!n||!n.__esModule?k(o,"default",{value:n,enumerable:!0}):o,n)),Ue=n=>X(k({},"__esModule",{value:!0}),n);var u=(n,e,o)=>(P(n,typeof e!="symbol"?e+"":e,o),o);var l=(n,e,o)=>new Promise((s,r)=>{var c=w=>{try{p(o.next(w))}catch(m){r(m)}},g=w=>{try{p(o.throw(w))}catch(m){r(m)}},p=w=>w.done?s(w.value):Promise.resolve(w.value).then(c,g);p((o=o.apply(n,e)).next())});var ee=ve((R,Y)=>{var K=typeof self!="undefined"?self:R,I=function(){function n(){this.fetch=!1,this.DOMException=K.DOMException}return a(n,"F"),n.prototype=K,new n}();(function(n){var e=function(o){var s={searchParams:"URLSearchParams"in n,iterable:"Symbol"in n&&"iterator"in Symbol,blob:"FileReader"in n&&"Blob"in n&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in n,arrayBuffer:"ArrayBuffer"in n};function r(t){return t&&DataView.prototype.isPrototypeOf(t)}if(a(r,"isDataView"),s.arrayBuffer)var c=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],g=ArrayBuffer.isView||function(t){return t&&c.indexOf(Object.prototype.toString.call(t))>-1};function p(t){if(typeof t!="string"&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}a(p,"normalizeName");function w(t){return typeof t!="string"&&(t=String(t)),t}a(w,"normalizeValue");function m(t){var i={next:function(){var h=t.shift();return{done:h===void 0,value:h}}};return s.iterable&&(i[Symbol.iterator]=function(){return i}),i}a(m,"iteratorFor");function f(t){this.map={},t instanceof f?t.forEach(function(i,h){this.append(h,i)},this):Array.isArray(t)?t.forEach(function(i){this.append(i[0],i[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(i){this.append(i,t[i])},this)}a(f,"Headers"),f.prototype.append=function(t,i){t=p(t),i=w(i);var h=this.map[t];this.map[t]=h?h+", "+i:i},f.prototype.delete=function(t){delete this.map[p(t)]},f.prototype.get=function(t){return t=p(t),this.has(t)?this.map[t]:null},f.prototype.has=function(t){return this.map.hasOwnProperty(p(t))},f.prototype.set=function(t,i){this.map[p(t)]=w(i)},f.prototype.forEach=function(t,i){for(var h in this.map)this.map.hasOwnProperty(h)&&t.call(i,this.map[h],h,this)},f.prototype.keys=function(){var t=[];return this.forEach(function(i,h){t.push(h)}),m(t)},f.prototype.values=function(){var t=[];return this.forEach(function(i){t.push(i)}),m(t)},f.prototype.entries=function(){var t=[];return this.forEach(function(i,h){t.push([h,i])}),m(t)},s.iterable&&(f.prototype[Symbol.iterator]=f.prototype.entries);function D(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}a(D,"consumed");function Q(t){return new Promise(function(i,h){t.onload=function(){i(t.result)},t.onerror=function(){h(t.error)}})}a(Q,"fileReaderReady");function ae(t){var i=new FileReader,h=Q(i);return i.readAsArrayBuffer(t),h}a(ae,"readBlobAsArrayBuffer");function ce(t){var i=new FileReader,h=Q(i);return i.readAsText(t),h}a(ce,"readBlobAsText");function he(t){for(var i=new Uint8Array(t),h=new Array(i.length),_=0;_<i.length;_++)h[_]=String.fromCharCode(i[_]);return h.join("")}a(he,"readArrayBufferAsText");function V(t){if(t.slice)return t.slice(0);var i=new Uint8Array(t.byteLength);return i.set(new Uint8Array(t)),i.buffer}a(V,"bufferClone");function J(){return this.bodyUsed=!1,this._initBody=function(t){this._bodyInit=t,t?typeof t=="string"?this._bodyText=t:s.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:s.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:s.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():s.arrayBuffer&&s.blob&&r(t)?(this._bodyArrayBuffer=V(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||g(t))?this._bodyArrayBuffer=V(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||(typeof t=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):s.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s.blob&&(this.blob=function(){var t=D(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?D(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(ae)}),this.text=function(){var t=D(this);if(t)return t;if(this._bodyBlob)return ce(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(he(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},s.formData&&(this.formData=function(){return this.text().then(le)}),this.json=function(){return this.text().then(JSON.parse)},this}a(J,"Body");var ue=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function de(t){var i=t.toUpperCase();return ue.indexOf(i)>-1?i:t}a(de,"normalizeMethod");function E(t,i){i=i||{};var h=i.body;if(t instanceof E){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,i.headers||(this.headers=new f(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,!h&&t._bodyInit!=null&&(h=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=i.credentials||this.credentials||"same-origin",(i.headers||!this.headers)&&(this.headers=new f(i.headers)),this.method=de(i.method||this.method||"GET"),this.mode=i.mode||this.mode||null,this.signal=i.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&h)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(h)}a(E,"Request"),E.prototype.clone=function(){return new E(this,{body:this._bodyInit})};function le(t){var i=new FormData;return t.trim().split("&").forEach(function(h){if(h){var _=h.split("="),y=_.shift().replace(/\+/g," "),d=_.join("=").replace(/\+/g," ");i.append(decodeURIComponent(y),decodeURIComponent(d))}}),i}a(le,"decode");function fe(t){var i=new f,h=t.replace(/\r?\n[\t ]+/g," ");return h.split(/\r?\n/).forEach(function(_){var y=_.split(":"),d=y.shift().trim();if(d){var $=y.join(":").trim();i.append(d,$)}}),i}a(fe,"parseHeaders"),J.call(E.prototype);function b(t,i){i||(i={}),this.type="default",this.status=i.status===void 0?200:i.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in i?i.statusText:"OK",this.headers=new f(i.headers),this.url=i.url||"",this._initBody(t)}a(b,"Response"),J.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new f(this.headers),url:this.url})},b.error=function(){var t=new b(null,{status:0,statusText:""});return t.type="error",t};var pe=[301,302,303,307,308];b.redirect=function(t,i){if(pe.indexOf(i)===-1)throw new RangeError("Invalid status code");return new b(null,{status:i,headers:{location:t}})},o.DOMException=n.DOMException;try{new o.DOMException}catch(t){o.DOMException=function(i,h){this.message=i,this.name=h;var _=Error(i);this.stack=_.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function B(t,i){return new Promise(function(h,_){var y=new E(t,i);if(y.signal&&y.signal.aborted)return _(new o.DOMException("Aborted","AbortError"));var d=new XMLHttpRequest;function $(){d.abort()}a($,"abortXhr"),d.onload=function(){var L={status:d.status,statusText:d.statusText,headers:fe(d.getAllResponseHeaders()||"")};L.url="responseURL"in d?d.responseURL:L.headers.get("X-Request-URL");var C="response"in d?d.response:d.responseText;h(new b(C,L))},d.onerror=function(){_(new TypeError("Network request failed"))},d.ontimeout=function(){_(new TypeError("Network request failed"))},d.onabort=function(){_(new o.DOMException("Aborted","AbortError"))},d.open(y.method,y.url,!0),y.credentials==="include"?d.withCredentials=!0:y.credentials==="omit"&&(d.withCredentials=!1),"responseType"in d&&s.blob&&(d.responseType="blob"),y.headers.forEach(function(L,C){d.setRequestHeader(C,L)}),y.signal&&(y.signal.addEventListener("abort",$),d.onreadystatechange=function(){d.readyState===4&&y.signal.removeEventListener("abort",$)}),d.send(typeof y._bodyInit=="undefined"?null:y._bodyInit)})}return a(B,"fetch"),B.polyfill=!0,n.fetch||(n.fetch=B,n.Headers=f,n.Request=E,n.Response=b),o.Headers=f,o.Request=E,o.Response=b,o.fetch=B,Object.defineProperty(o,"__esModule",{value:!0}),o}({})})(I);I.fetch.ponyfill=!0;delete I.fetch.polyfill;var x=I;R=x.fetch;R.default=x.fetch;R.fetch=x.fetch;R.Headers=x.Headers;R.Request=x.Request;R.Response=x.Response;Y.exports=R});var Le={};Ee(Le,{Authorizer:()=>H,OAuthProviders:()=>O,ResponseTypes:()=>A});var ie=Te(ee());var O;(function(n){n.Apple="apple",n.Github="github",n.Google="google",n.Facebook="facebook",n.LinkedIn="linkedin",n.Twitter="twitter",n.Microsoft="microsoft",n.Twitch="twitch",n.Roblox="roblox",n.Discord="discord"})(O||(O={}));var A;(function(n){n.Code="code",n.Token="token"})(A||(A={}));var T=a(()=>typeof window!="undefined","hasWindow"),j=a(n=>{let e=n.trim();return e[e.length-1]==="/"&&(e=e.slice(0,-1)),e},"trimURL"),re=a(()=>T()?window.crypto||window.msCrypto:null,"getCrypto"),xe=a(()=>{let n=re();return n&&n.subtle||n.webkitSubtle},"getCryptoSubtle"),U=a(()=>{let n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.",e="",o=re();return o&&Array.from(o.getRandomValues(new Uint8Array(43))).forEach(r=>e+=n[r%n.length]),e},"createRandomString"),v=a(n=>T()?btoa(n):Buffer.from(n).toString("base64"),"encode");var te=a(n=>Object.keys(n).filter(e=>typeof n[e]!="undefined").map(e=>`${encodeURIComponent(e)}=${encodeURIComponent(n[e])}`).join("&"),"createQueryParams"),oe=a(n=>l(void 0,null,function*(){let e=xe().digest({name:"SHA-256"},new TextEncoder().encode(n));return window.msCrypto?new Promise((o,s)=>{e.oncomplete=r=>{o(r.target.result)},e.onerror=r=>{s(r.error)},e.onabort=()=>{s(new Error("The digest operation was aborted"))}}):yield e}),"sha256"),Ae=a(n=>{let e={"+":"-","/":"_","=":""};return n.replace(/[+/=]/g,o=>e[o])},"urlEncodeB64");var se=a(n=>{let e=new Uint8Array(n);return Ae(window.btoa(String.fromCharCode(...Array.from(e))))},"bufferToBase64UrlEncoded"),ne=a((n,e,o=60)=>new Promise((s,r)=>{let c=window.document.createElement("iframe");c.setAttribute("id","authorizer-iframe"),c.setAttribute("width","0"),c.setAttribute("height","0"),c.style.display="none";let g=a(()=>{window.document.body.contains(c)&&(window.document.body.removeChild(c),window.removeEventListener("message",w,!1))},"removeIframe"),p=setTimeout(()=>{g()},o*1e3),w=a(function(m){if(m.origin!==e||!m.data||!m.data.response)return;let f=m.source;f&&f.close(),m.data.response.error?r(m.data.response):s(m.data.response),clearTimeout(p),window.removeEventListener("message",w,!1),setTimeout(g,2*1e3)},"iframeEventHandler");window.addEventListener("message",w,!1),window.document.body.appendChild(c),c.setAttribute("src",n)}),"executeIframe");var z="id email email_verified given_name family_name middle_name nickname preferred_username picture signup_methods gender birthdate phone_number phone_number_verified roles created_at updated_at revoked_timestamp is_multi_factor_auth_enabled app_data",S=`message access_token expires_in refresh_token id_token should_show_email_otp_screen should_show_mobile_otp_screen should_show_totp_screen authenticator_scanner_image authenticator_secret authenticator_recovery_codes user { ${z} }`,M=a(()=>T()?window.fetch:ie.default,"getFetcher"),N=class N{constructor(e){u(this,"config");u(this,"codeVerifier");u(this,"authorize",a(e=>l(this,null,function*(){var c;if(!T())return this.errorResponse([new Error("this feature is only supported in browser")]);let o=["openid","profile","email"];e.use_refresh_token&&o.push("offline_access");let s={redirect_uri:this.config.redirectURL,response_mode:e.response_mode||"web_message",state:v(U()),nonce:v(U()),response_type:e.response_type,scope:o.join(" "),client_id:((c=this.config)==null?void 0:c.clientID)||""};if(e.response_type===A.Code){this.codeVerifier=U();let g=yield oe(this.codeVerifier),p=se(g);s.code_challenge=p}let r=`${this.config.authorizerURL}/authorize?${te(s)}`;if(s.response_mode!=="web_message")return window.location.replace(r),this.okResponse(void 0);try{let g=yield ne(r,this.config.authorizerURL,60);if(e.response_type===A.Code){let p=yield this.getToken({code:g.code});return p.errors.length?this.errorResponse(p.errors):this.okResponse(p.data)}return this.okResponse(g)}catch(g){return g.error&&window.location.replace(`${this.config.authorizerURL}/app?state=${v(JSON.stringify(this.config))}&redirect_uri=${this.config.redirectURL}`),this.errorResponse(g)}}),"authorize"));u(this,"browserLogin",a(()=>l(this,null,function*(){try{let e=yield this.getSession();return e.errors.length?this.errorResponse(e.errors):this.okResponse(e.data)}catch(e){return T()?(window.location.replace(`${this.config.authorizerURL}/app?state=${v(JSON.stringify(this.config))}&redirect_uri=${this.config.redirectURL}`),this.errorResponse(e)):{data:void 0,errors:[new Error("browserLogin is only supported for browsers")]}}}),"browserLogin"));u(this,"forgotPassword",a(e=>l(this,null,function*(){var o;e.state||(e.state=v(U())),e.redirect_uri||(e.redirect_uri=this.config.redirectURL);try{let s=yield this.graphqlQuery({query:"mutation forgotPassword($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }",variables:{data:e}});return(o=s==null?void 0:s.errors)!=null&&o.length?this.errorResponse(s.errors):this.okResponse(s==null?void 0:s.data.forgot_password)}catch(s){return this.errorResponse([s])}}),"forgotPassword"));u(this,"getMetaData",a(()=>l(this,null,function*(){var e;try{let o=yield this.graphqlQuery({query:"query { meta { version client_id is_google_login_enabled is_facebook_login_enabled is_github_login_enabled is_linkedin_login_enabled is_apple_login_enabled is_twitter_login_enabled is_microsoft_login_enabled is_twitch_login_enabled is_roblox_login_enabled is_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled is_multi_factor_auth_enabled is_mobile_basic_authentication_enabled is_phone_verification_enabled } }"});return(e=o==null?void 0:o.errors)!=null&&e.length?this.errorResponse(o.errors):this.okResponse(o.data.meta)}catch(o){return this.errorResponse([o])}}),"getMetaData"));u(this,"getProfile",a(e=>l(this,null,function*(){var o;try{let s=yield this.graphqlQuery({query:`query { profile { ${z} } }`,headers:e});return(o=s==null?void 0:s.errors)!=null&&o.length?this.errorResponse(s.errors):this.okResponse(s.data.profile)}catch(s){return this.errorResponse([s])}}),"getProfile"));u(this,"getSession",a((e,o)=>l(this,null,function*(){var s,r;try{let c=yield this.graphqlQuery({query:`query getSession($params: SessionQueryRequest){session(params: $params) { ${S} } }`,headers:e,variables:{params:o}});return(s=c==null?void 0:c.errors)!=null&&s.length?this.errorResponse(c.errors):this.okResponse((r=c.data)==null?void 0:r.session)}catch(c){return this.errorResponse(c)}}),"getSession"));u(this,"getToken",a(e=>l(this,null,function*(){if(e.grant_type||(e.grant_type="authorization_code"),e.grant_type==="refresh_token"&&!e.refresh_token)return this.errorResponse([new Error("Invalid refresh_token")]);if(e.grant_type==="authorization_code"&&!this.codeVerifier)return this.errorResponse([new Error("Invalid code verifier")]);let o={client_id:this.config.clientID,code:e.code||"",code_verifier:this.codeVerifier||"",grant_type:e.grant_type||"",refresh_token:e.refresh_token||""};try{let r=yield M()(`${this.config.authorizerURL}/oauth/token`,{method:"POST",body:JSON.stringify(o),headers:q({},this.config.extraHeaders),credentials:"include"}),c=yield r.json();return r.status>=400?this.errorResponse([new Error(c.error_description||c.error)]):this.okResponse(c)}catch(s){return this.errorResponse(s)}}),"getToken"));u(this,"login",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
2
- mutation login($data: LoginRequest!) { login(params: $data) { ${S}}}
3
- `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.login)}catch(r){return this.errorResponse([new Error(r)])}}),"login"));u(this,"logout",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:" mutation { logout { message } } ",headers:e});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.response)}catch(r){return this.errorResponse([r])}}),"logout"));u(this,"magicLinkLogin",a(e=>l(this,null,function*(){var o,s;try{e.state||(e.state=v(U())),e.redirect_uri||(e.redirect_uri=this.config.redirectURL);let r=yield this.graphqlQuery({query:`
1
+ var authorizerdev=(()=>{var ge=Object.create;var L=Object.defineProperty,be=Object.defineProperties,we=Object.getOwnPropertyDescriptor,Re=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertyNames,K=Object.getOwnPropertySymbols,Ee=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var z=(i,e,o)=>e in i?L(i,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[e]=o,x=(i,e)=>{for(var o in e||(e={}))Y.call(e,o)&&z(i,o,e[o]);if(K)for(var o of K(e))Te.call(e,o)&&z(i,o,e[o]);return i},ee=(i,e)=>be(i,Re(e)),a=(i,e)=>L(i,"name",{value:e,configurable:!0});var Ue=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),ke=(i,e)=>{for(var o in e)L(i,o,{get:e[o],enumerable:!0})},re=(i,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ve(e))!Y.call(i,r)&&r!==o&&L(i,r,{get:()=>e[r],enumerable:!(s=we(e,r))||s.enumerable});return i};var Ae=(i,e,o)=>(o=i!=null?ge(Ee(i)):{},re(e||!i||!i.__esModule?L(o,"default",{value:i,enumerable:!0}):o,i)),qe=i=>re(L({},"__esModule",{value:!0}),i);var f=(i,e,o)=>z(i,typeof e!="symbol"?e+"":e,o);var d=(i,e,o)=>new Promise((s,r)=>{var c=_=>{try{w(o.next(_))}catch(g){r(g)}},b=_=>{try{w(o.throw(_))}catch(g){r(g)}},w=_=>_.done?s(_.value):Promise.resolve(_.value).then(c,b);w((o=o.apply(i,e)).next())});var oe=Ue((E,te)=>{var B=typeof globalThis!="undefined"&&globalThis||typeof self!="undefined"&&self||typeof global!="undefined"&&global,S=(function(){function i(){this.fetch=!1,this.DOMException=B.DOMException}return a(i,"F"),i.prototype=B,new i})();(function(i){var e=(function(o){var s=typeof i!="undefined"&&i||typeof self!="undefined"&&self||typeof global!="undefined"&&global||{},r={searchParams:"URLSearchParams"in s,iterable:"Symbol"in s&&"iterator"in Symbol,blob:"FileReader"in s&&"Blob"in s&&(function(){try{return new Blob,!0}catch(t){return!1}})(),formData:"FormData"in s,arrayBuffer:"ArrayBuffer"in s};function c(t){return t&&DataView.prototype.isPrototypeOf(t)}if(a(c,"isDataView"),r.arrayBuffer)var b=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],w=ArrayBuffer.isView||function(t){return t&&b.indexOf(Object.prototype.toString.call(t))>-1};function _(t){if(typeof t!="string"&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||t==="")throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}a(_,"normalizeName");function g(t){return typeof t!="string"&&(t=String(t)),t}a(g,"normalizeValue");function q(t){var n={next:a(function(){var h=t.shift();return{done:h===void 0,value:h}},"next")};return r.iterable&&(n[Symbol.iterator]=function(){return n}),n}a(q,"iteratorFor");function y(t){this.map={},t instanceof y?t.forEach(function(n,h){this.append(h,n)},this):Array.isArray(t)?t.forEach(function(n){if(n.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+n.length);this.append(n[0],n[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(n){this.append(n,t[n])},this)}a(y,"Headers"),y.prototype.append=function(t,n){t=_(t),n=g(n);var h=this.map[t];this.map[t]=h?h+", "+n:n},y.prototype.delete=function(t){delete this.map[_(t)]},y.prototype.get=function(t){return t=_(t),this.has(t)?this.map[t]:null},y.prototype.has=function(t){return this.map.hasOwnProperty(_(t))},y.prototype.set=function(t,n){this.map[_(t)]=g(n)},y.prototype.forEach=function(t,n){for(var h in this.map)this.map.hasOwnProperty(h)&&t.call(n,this.map[h],h,this)},y.prototype.keys=function(){var t=[];return this.forEach(function(n,h){t.push(h)}),q(t)},y.prototype.values=function(){var t=[];return this.forEach(function(n){t.push(n)}),q(t)},y.prototype.entries=function(){var t=[];return this.forEach(function(n,h){t.push([h,n])}),q(t)},r.iterable&&(y.prototype[Symbol.iterator]=y.prototype.entries);function C(t){if(!t._noBody){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}}a(C,"consumed");function G(t){return new Promise(function(n,h){t.onload=function(){n(t.result)},t.onerror=function(){h(t.error)}})}a(G,"fileReaderReady");function ue(t){var n=new FileReader,h=G(n);return n.readAsArrayBuffer(t),h}a(ue,"readBlobAsArrayBuffer");function fe(t){var n=new FileReader,h=G(n),l=/charset=([A-Za-z0-9_-]+)/.exec(t.type),p=l?l[1]:"utf-8";return n.readAsText(t,p),h}a(fe,"readBlobAsText");function le(t){for(var n=new Uint8Array(t),h=new Array(n.length),l=0;l<n.length;l++)h[l]=String.fromCharCode(n[l]);return h.join("")}a(le,"readArrayBufferAsText");function W(t){if(t.slice)return t.slice(0);var n=new Uint8Array(t.byteLength);return n.set(new Uint8Array(t)),n.buffer}a(W,"bufferClone");function Z(){return this.bodyUsed=!1,this._initBody=function(t){this.bodyUsed=this.bodyUsed,this._bodyInit=t,t?typeof t=="string"?this._bodyText=t:r.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:r.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():r.arrayBuffer&&r.blob&&c(t)?(this._bodyArrayBuffer=W(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||w(t))?this._bodyArrayBuffer=W(t):this._bodyText=t=Object.prototype.toString.call(t):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||(typeof t=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var t=C(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var t=C(this);return t||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else{if(r.blob)return this.blob().then(ue);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var t=C(this);if(t)return t;if(this._bodyBlob)return fe(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(le(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r.formData&&(this.formData=function(){return this.text().then(ye)}),this.json=function(){return this.text().then(JSON.parse)},this}a(Z,"Body");var de=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function pe(t){var n=t.toUpperCase();return de.indexOf(n)>-1?n:t}a(pe,"normalizeMethod");function v(t,n){if(!(this instanceof v))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');n=n||{};var h=n.body;if(t instanceof v){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,n.headers||(this.headers=new y(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,!h&&t._bodyInit!=null&&(h=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=n.credentials||this.credentials||"same-origin",(n.headers||!this.headers)&&(this.headers=new y(n.headers)),this.method=pe(n.method||this.method||"GET"),this.mode=n.mode||this.mode||null,this.signal=n.signal||this.signal||(function(){if("AbortController"in s){var u=new AbortController;return u.signal}})(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&h)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(h),(this.method==="GET"||this.method==="HEAD")&&(n.cache==="no-store"||n.cache==="no-cache")){var l=/([?&])_=[^&]*/;if(l.test(this.url))this.url=this.url.replace(l,"$1_="+new Date().getTime());else{var p=/\?/;this.url+=(p.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}a(v,"Request"),v.prototype.clone=function(){return new v(this,{body:this._bodyInit})};function ye(t){var n=new FormData;return t.trim().split("&").forEach(function(h){if(h){var l=h.split("="),p=l.shift().replace(/\+/g," "),u=l.join("=").replace(/\+/g," ");n.append(decodeURIComponent(p),decodeURIComponent(u))}}),n}a(ye,"decode");function _e(t){var n=new y,h=t.replace(/\r?\n[\t ]+/g," ");return h.split("\r").map(function(l){return l.indexOf(`
2
+ `)===0?l.substr(1,l.length):l}).forEach(function(l){var p=l.split(":"),u=p.shift().trim();if(u){var D=p.join(":").trim();try{n.append(u,D)}catch(j){console.warn("Response "+j.message)}}}),n}a(_e,"parseHeaders"),Z.call(v.prototype);function R(t,n){if(!(this instanceof R))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(n||(n={}),this.type="default",this.status=n.status===void 0?200:n.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=n.statusText===void 0?"":""+n.statusText,this.headers=new y(n.headers),this.url=n.url||"",this._initBody(t)}a(R,"Response"),Z.call(R.prototype),R.prototype.clone=function(){return new R(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new y(this.headers),url:this.url})},R.error=function(){var t=new R(null,{status:200,statusText:""});return t.ok=!1,t.status=0,t.type="error",t};var me=[301,302,303,307,308];R.redirect=function(t,n){if(me.indexOf(n)===-1)throw new RangeError("Invalid status code");return new R(null,{status:n,headers:{location:t}})},o.DOMException=s.DOMException;try{new o.DOMException}catch(t){o.DOMException=function(n,h){this.message=n,this.name=h;var l=Error(n);this.stack=l.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function P(t,n){return new Promise(function(h,l){var p=new v(t,n);if(p.signal&&p.signal.aborted)return l(new o.DOMException("Aborted","AbortError"));var u=new XMLHttpRequest;function D(){u.abort()}a(D,"abortXhr"),u.onload=function(){var m={statusText:u.statusText,headers:_e(u.getAllResponseHeaders()||"")};p.url.indexOf("file://")===0&&(u.status<200||u.status>599)?m.status=200:m.status=u.status,m.url="responseURL"in u?u.responseURL:m.headers.get("X-Request-URL");var U="response"in u?u.response:u.responseText;setTimeout(function(){h(new R(U,m))},0)},u.onerror=function(){setTimeout(function(){l(new TypeError("Network request failed"))},0)},u.ontimeout=function(){setTimeout(function(){l(new TypeError("Network request timed out"))},0)},u.onabort=function(){setTimeout(function(){l(new o.DOMException("Aborted","AbortError"))},0)};function j(m){try{return m===""&&s.location.href?s.location.href:m}catch(U){return m}}if(a(j,"fixUrl"),u.open(p.method,j(p.url),!0),p.credentials==="include"?u.withCredentials=!0:p.credentials==="omit"&&(u.withCredentials=!1),"responseType"in u&&(r.blob?u.responseType="blob":r.arrayBuffer&&(u.responseType="arraybuffer")),n&&typeof n.headers=="object"&&!(n.headers instanceof y||s.Headers&&n.headers instanceof s.Headers)){var X=[];Object.getOwnPropertyNames(n.headers).forEach(function(m){X.push(_(m)),u.setRequestHeader(m,g(n.headers[m]))}),p.headers.forEach(function(m,U){X.indexOf(U)===-1&&u.setRequestHeader(U,m)})}else p.headers.forEach(function(m,U){u.setRequestHeader(U,m)});p.signal&&(p.signal.addEventListener("abort",D),u.onreadystatechange=function(){u.readyState===4&&p.signal.removeEventListener("abort",D)}),u.send(typeof p._bodyInit=="undefined"?null:p._bodyInit)})}return a(P,"fetch"),P.polyfill=!0,s.fetch||(s.fetch=P,s.Headers=y,s.Request=v,s.Response=R),o.Headers=y,o.Request=v,o.Response=R,o.fetch=P,Object.defineProperty(o,"__esModule",{value:!0}),o})({})})(S);S.fetch.ponyfill=!0;delete S.fetch.polyfill;var O=B.fetch?B:S;E=O.fetch;E.default=O.fetch;E.fetch=O.fetch;E.Headers=O.Headers;E.Request=O.Request;E.Response=O.Response;te.exports=E});var De={};ke(De,{Authorizer:()=>V,OAuthProviders:()=>H,ResponseTypes:()=>$});var he=Ae(oe());var H=(function(i){return i.Apple="apple",i.Github="github",i.Google="google",i.Facebook="facebook",i.LinkedIn="linkedin",i.Twitter="twitter",i.Microsoft="microsoft",i.Twitch="twitch",i.Roblox="roblox",i.Discord="discord",i})({}),$=(function(i){return i.Code="code",i.Token="token",i})({});var k=a(()=>typeof window!="undefined","hasWindow"),M=a(i=>{let e=i.trim();return e[e.length-1]==="/"&&(e=e.slice(0,-1)),e},"trimURL"),se=a(()=>k()?window.crypto||window.msCrypto:null,"getCrypto"),Oe=a(()=>{let i=se();return i&&i.subtle||i.webkitSubtle},"getCryptoSubtle"),A=a(()=>{let i="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.",e="",o=se();return o&&Array.from(o.getRandomValues(new Uint8Array(43))).forEach(r=>e+=i[r%i.length]),e},"createRandomString"),T=a(i=>k()?btoa(i):Buffer.from(i).toString("base64"),"encode");var ne=a(i=>Object.keys(i).filter(e=>typeof i[e]!="undefined").map(e=>`${encodeURIComponent(e)}=${encodeURIComponent(i[e])}`).join("&"),"createQueryParams"),ie=a(i=>d(null,null,function*(){let e=Oe().digest({name:"SHA-256"},new TextEncoder().encode(i));return window.msCrypto?new Promise((o,s)=>{e.oncomplete=r=>{o(r.target.result)},e.onerror=r=>{s(r.error)},e.onabort=()=>{s(new Error("The digest operation was aborted"))}}):yield e}),"sha256"),Ie=a(i=>{let e={"+":"-","/":"_","=":""};return i.replace(/[+/=]/g,o=>e[o])},"urlEncodeB64");var ae=a(i=>{let e=new Uint8Array(i);return Ie(window.btoa(String.fromCharCode(...Array.from(e))))},"bufferToBase64UrlEncoded"),ce=a((i,e,o=60)=>new Promise((s,r)=>{let c=window.document.createElement("iframe");c.setAttribute("id","authorizer-iframe"),c.setAttribute("width","0"),c.setAttribute("height","0"),c.style.display="none";let b=a(()=>{window.document.body.contains(c)&&(window.document.body.removeChild(c),window.removeEventListener("message",_,!1))},"removeIframe"),w=setTimeout(()=>{r(new Error("Authorization timeout")),b()},o*1e3),_=a(function(g){if(g.origin!==e||!g.data||!g.data.response)return;let q=g.source;q&&q.close(),g.data.response.error?r(g.data.response):s(g.data.response),clearTimeout(w),window.removeEventListener("message",_,!1),setTimeout(b,2*1e3)},"iframeEventHandler");window.addEventListener("message",_,!1),window.document.body.appendChild(c),c.setAttribute("src",i)}),"executeIframe");var Q="id email email_verified given_name family_name middle_name nickname preferred_username picture signup_methods gender birthdate phone_number phone_number_verified roles created_at updated_at revoked_timestamp is_multi_factor_auth_enabled app_data",I=`message access_token expires_in refresh_token id_token should_show_email_otp_screen should_show_mobile_otp_screen should_show_totp_screen authenticator_scanner_image authenticator_secret authenticator_recovery_codes user { ${Q} }`,N=a(()=>k()?window.fetch:he.default,"getFetcher"),J=class J{constructor(e){f(this,"config");f(this,"codeVerifier");f(this,"authorize",a(e=>d(this,null,function*(){var c;if(!k())return this.errorResponse([new Error("this feature is only supported in browser")]);let o=["openid","profile","email"];e.use_refresh_token&&o.push("offline_access");let s={redirect_uri:this.config.redirectURL,response_mode:e.response_mode||"web_message",state:T(A()),nonce:T(A()),response_type:e.response_type,scope:o.join(" "),client_id:((c=this.config)==null?void 0:c.clientID)||""};if(e.response_type===$.Code){this.codeVerifier=A();let b=yield ie(this.codeVerifier),w=ae(b);s.code_challenge=w}let r=`${this.config.authorizerURL}/authorize?${ne(s)}`;if(s.response_mode!=="web_message")return window.location.replace(r),this.okResponse(void 0);try{let b=yield ce(r,this.config.authorizerURL,60);if(e.response_type===$.Code){let w=yield this.getToken({code:b.code});return w.errors.length?this.errorResponse(w.errors):this.okResponse(w.data)}return this.okResponse(b)}catch(b){return b.error&&window.location.replace(`${this.config.authorizerURL}/app?state=${T(JSON.stringify({clientID:this.config.clientID,redirectURL:this.config.redirectURL,authorizerURL:this.config.authorizerURL}))}&redirect_uri=${encodeURIComponent(this.config.redirectURL||"")}`),this.errorResponse(b)}}),"authorize"));f(this,"browserLogin",a(()=>d(this,null,function*(){try{let e=yield this.getSession();return e.errors.length?this.errorResponse(e.errors):this.okResponse(e.data)}catch(e){return k()?(window.location.replace(`${this.config.authorizerURL}/app?state=${T(JSON.stringify({clientID:this.config.clientID,redirectURL:this.config.redirectURL,authorizerURL:this.config.authorizerURL}))}&redirect_uri=${encodeURIComponent(this.config.redirectURL||"")}`),this.errorResponse(e)):{data:void 0,errors:[new Error("browserLogin is only supported for browsers")]}}}),"browserLogin"));f(this,"forgotPassword",a(e=>d(this,null,function*(){var o;e.state||(e.state=T(A())),e.redirect_uri||(e.redirect_uri=this.config.redirectURL);try{let s=yield this.graphqlQuery({query:"mutation forgotPassword($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }",variables:{data:e}});return(o=s==null?void 0:s.errors)!=null&&o.length?this.errorResponse(s.errors):this.okResponse(s==null?void 0:s.data.forgot_password)}catch(s){return this.errorResponse([s])}}),"forgotPassword"));f(this,"getMetaData",a(()=>d(this,null,function*(){var e;try{let o=yield this.graphqlQuery({query:"query { meta { version client_id is_google_login_enabled is_facebook_login_enabled is_github_login_enabled is_linkedin_login_enabled is_apple_login_enabled is_twitter_login_enabled is_microsoft_login_enabled is_twitch_login_enabled is_roblox_login_enabled is_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled is_multi_factor_auth_enabled is_mobile_basic_authentication_enabled is_phone_verification_enabled } }"});return(e=o==null?void 0:o.errors)!=null&&e.length?this.errorResponse(o.errors):this.okResponse(o.data.meta)}catch(o){return this.errorResponse([o])}}),"getMetaData"));f(this,"getProfile",a(e=>d(this,null,function*(){var o;try{let s=yield this.graphqlQuery({query:`query { profile { ${Q} } }`,headers:e});return(o=s==null?void 0:s.errors)!=null&&o.length?this.errorResponse(s.errors):this.okResponse(s.data.profile)}catch(s){return this.errorResponse([s])}}),"getProfile"));f(this,"getSession",a((e,o)=>d(this,null,function*(){var s,r;try{let c=yield this.graphqlQuery({query:`query getSession($params: SessionQueryRequest){session(params: $params) { ${I} } }`,headers:e,variables:{params:o}});return(s=c==null?void 0:c.errors)!=null&&s.length?this.errorResponse(c.errors):this.okResponse((r=c.data)==null?void 0:r.session)}catch(c){return this.errorResponse(c)}}),"getSession"));f(this,"getToken",a(e=>d(this,null,function*(){if(e.grant_type||(e.grant_type="authorization_code"),e.grant_type==="refresh_token"&&!e.refresh_token)return this.errorResponse([new Error("Invalid refresh_token")]);if(e.grant_type==="authorization_code"&&!this.codeVerifier)return this.errorResponse([new Error("Invalid code verifier")]);let o={client_id:this.config.clientID,code:e.code||"",code_verifier:this.codeVerifier||"",grant_type:e.grant_type||"",refresh_token:e.refresh_token||""};try{let r=yield N()(`${this.config.authorizerURL}/oauth/token`,{method:"POST",body:JSON.stringify(o),headers:x({},this.config.extraHeaders),credentials:"include"}),c=yield r.json();return r.status>=400?this.errorResponse([new Error(c.error_description||c.error)]):this.okResponse(c)}catch(s){return this.errorResponse(s)}}),"getToken"));f(this,"login",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
3
+ mutation login($data: LoginRequest!) { login(params: $data) { ${I}}}
4
+ `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.login)}catch(r){return this.errorResponse([new Error(r)])}}),"login"));f(this,"logout",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:" mutation { logout { message } } ",headers:e});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.response)}catch(r){return this.errorResponse([r])}}),"logout"));f(this,"magicLinkLogin",a(e=>d(this,null,function*(){var o,s;try{e.state||(e.state=T(A())),e.redirect_uri||(e.redirect_uri=this.config.redirectURL);let r=yield this.graphqlQuery({query:`
4
5
  mutation magicLinkLogin($data: MagicLinkLoginRequest!) { magic_link_login(params: $data) { message }}
5
- `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.magic_link_login)}catch(r){return this.errorResponse([r])}}),"magicLinkLogin"));u(this,"oauthLogin",a((e,o,s,r)=>l(this,null,function*(){let c=r;if(c||(c=v(U())),!Object.values(O).includes(e))throw new Error(`only following oauth providers are supported: ${Object.values(e).toString()}`);if(!T())throw new Error("oauthLogin is only supported for browsers");o&&o.length&&(c+=`&roles=${o.join(",")}`),window.location.replace(`${this.config.authorizerURL}/oauth_login/${e}?redirect_uri=${s||this.config.redirectURL}&state=${c}`)}),"oauthLogin"));u(this,"resendOtp",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
6
+ `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.magic_link_login)}catch(r){return this.errorResponse([r])}}),"magicLinkLogin"));f(this,"oauthLogin",a((e,o,s,r)=>d(this,null,function*(){let c=r;if(c||(c=T(A())),!Object.values(H).includes(e))throw new Error(`only following oauth providers are supported: ${Object.values(e).toString()}`);if(!k())throw new Error("oauthLogin is only supported for browsers");o&&o.length&&(c+=`&roles=${o.join(",")}`),window.location.replace(`${this.config.authorizerURL}/oauth_login/${e}?redirect_uri=${encodeURIComponent(s||this.config.redirectURL||"")}&state=${encodeURIComponent(c)}`)}),"oauthLogin"));f(this,"resendOtp",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
6
7
  mutation resendOtp($data: ResendOTPRequest!) { resend_otp(params: $data) { message }}
7
- `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.resend_otp)}catch(r){return this.errorResponse([r])}}),"resendOtp"));u(this,"resetPassword",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"mutation resetPassword($data: ResetPasswordRequest!) { reset_password(params: $data) { message } }",variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.reset_password)}catch(r){return this.errorResponse([r])}}),"resetPassword"));u(this,"revokeToken",a(e=>l(this,null,function*(){if(!e.refresh_token&&!e.refresh_token.trim())return this.errorResponse([new Error("Invalid refresh_token")]);let r=yield(yield M()(`${this.config.authorizerURL}/oauth/revoke`,{method:"POST",headers:q({},this.config.extraHeaders),body:JSON.stringify({refresh_token:e.refresh_token,client_id:this.config.clientID})})).json();return this.okResponse(r)}),"revokeToken"));u(this,"signup",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
8
- mutation signup($data: SignUpRequest!) { signup(params: $data) { ${S}}}
9
- `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.signup)}catch(r){return this.errorResponse([r])}}),"signup"));u(this,"updateProfile",a((e,o)=>l(this,null,function*(){var s,r;try{let c=yield this.graphqlQuery({query:"mutation updateProfile($data: UpdateProfileRequest!) { update_profile(params: $data) { message } }",headers:o,variables:{data:e}});return(s=c==null?void 0:c.errors)!=null&&s.length?this.errorResponse(c.errors):this.okResponse((r=c.data)==null?void 0:r.update_profile)}catch(c){return this.errorResponse([c])}}),"updateProfile"));u(this,"deactivateAccount",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"mutation deactivateAccount { deactivate_account { message } }",headers:e});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.deactivate_account)}catch(r){return this.errorResponse([r])}}),"deactivateAccount"));u(this,"validateJWTToken",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"query validateJWTToken($params: ValidateJWTTokenRequest!){validate_jwt_token(params: $params) { is_valid claims } }",variables:{params:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.validate_jwt_token)}catch(r){return this.errorResponse([r])}}),"validateJWTToken"));u(this,"validateSession",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`query validateSession($params: ValidateSessionRequest){validate_session(params: $params) { is_valid user { ${z} } } }`,variables:{params:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.validate_session)}catch(r){return this.errorResponse([r])}}),"validateSession"));u(this,"verifyEmail",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
10
- mutation verifyEmail($data: VerifyEmailRequest!) { verify_email(params: $data) { ${S}}}
11
- `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.verify_email)}catch(r){return this.errorResponse([r])}}),"verifyEmail"));u(this,"resendVerifyEmail",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
8
+ `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.resend_otp)}catch(r){return this.errorResponse([r])}}),"resendOtp"));f(this,"resetPassword",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"mutation resetPassword($data: ResetPasswordRequest!) { reset_password(params: $data) { message } }",variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.reset_password)}catch(r){return this.errorResponse([r])}}),"resetPassword"));f(this,"revokeToken",a(e=>d(this,null,function*(){if(!e.refresh_token&&!e.refresh_token.trim())return this.errorResponse([new Error("Invalid refresh_token")]);let r=yield(yield N()(`${this.config.authorizerURL}/oauth/revoke`,{method:"POST",headers:x({},this.config.extraHeaders),body:JSON.stringify({refresh_token:e.refresh_token,client_id:this.config.clientID})})).json();return this.okResponse(r)}),"revokeToken"));f(this,"signup",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
9
+ mutation signup($data: SignUpRequest!) { signup(params: $data) { ${I}}}
10
+ `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.signup)}catch(r){return this.errorResponse([r])}}),"signup"));f(this,"updateProfile",a((e,o)=>d(this,null,function*(){var s,r;try{let c=yield this.graphqlQuery({query:"mutation updateProfile($data: UpdateProfileRequest!) { update_profile(params: $data) { message } }",headers:o,variables:{data:e}});return(s=c==null?void 0:c.errors)!=null&&s.length?this.errorResponse(c.errors):this.okResponse((r=c.data)==null?void 0:r.update_profile)}catch(c){return this.errorResponse([c])}}),"updateProfile"));f(this,"deactivateAccount",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"mutation deactivateAccount { deactivate_account { message } }",headers:e});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.deactivate_account)}catch(r){return this.errorResponse([r])}}),"deactivateAccount"));f(this,"validateJWTToken",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"query validateJWTToken($params: ValidateJWTTokenRequest!){validate_jwt_token(params: $params) { is_valid claims } }",variables:{params:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.validate_jwt_token)}catch(r){return this.errorResponse([r])}}),"validateJWTToken"));f(this,"validateSession",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`query validateSession($params: ValidateSessionRequest){validate_session(params: $params) { is_valid user { ${Q} } } }`,variables:{params:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.validate_session)}catch(r){return this.errorResponse([r])}}),"validateSession"));f(this,"verifyEmail",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
11
+ mutation verifyEmail($data: VerifyEmailRequest!) { verify_email(params: $data) { ${I}}}
12
+ `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.verify_email)}catch(r){return this.errorResponse([r])}}),"verifyEmail"));f(this,"resendVerifyEmail",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
12
13
  mutation resendVerifyEmail($data: ResendVerifyEmailRequest!) { resend_verify_email(params: $data) { message }}
13
- `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.resend_verify_email)}catch(r){return this.errorResponse([r])}}),"resendVerifyEmail"));u(this,"verifyOtp",a(e=>l(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
14
- mutation verifyOtp($data: VerifyOTPRequest!) { verify_otp(params: $data) { ${S}}}
15
- `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.verify_otp)}catch(r){return this.errorResponse([r])}}),"verifyOtp"));u(this,"graphqlQuery",a(e=>l(this,null,function*(){var c;let r=yield(yield M()(`${this.config.authorizerURL}/graphql`,{method:"POST",body:JSON.stringify({query:e.query,variables:e.variables||{}}),headers:q(q({},this.config.extraHeaders),e.headers||{}),credentials:"include"})).json();return(c=r==null?void 0:r.errors)!=null&&c.length?{data:void 0,errors:r.errors}:{data:r.data,errors:[]}}),"graphqlQuery"));u(this,"errorResponse",a(e=>({data:void 0,errors:e}),"errorResponse"));u(this,"okResponse",a(e=>({data:e,errors:[]}),"okResponse"));if(!e)throw new Error("Configuration is required");if(this.config=e,!e.authorizerURL&&!e.authorizerURL.trim())throw new Error("Invalid authorizerURL");if(e.authorizerURL&&(this.config.authorizerURL=j(e.authorizerURL)),!e.redirectURL&&!e.redirectURL.trim())throw new Error("Invalid redirectURL");this.config.redirectURL=j(e.redirectURL),this.config.extraHeaders=Z(q({},e.extraHeaders||{}),{"x-authorizer-url":this.config.authorizerURL,"x-authorizer-client-id":this.config.clientID||"","Content-Type":"application/json"}),this.config.clientID=((e==null?void 0:e.clientID)||"").trim()}};a(N,"Authorizer");var H=N;return Ue(Le);})();
14
+ `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.resend_verify_email)}catch(r){return this.errorResponse([r])}}),"resendVerifyEmail"));f(this,"verifyOtp",a(e=>d(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
15
+ mutation verifyOtp($data: VerifyOTPRequest!) { verify_otp(params: $data) { ${I}}}
16
+ `,variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r.data)==null?void 0:s.verify_otp)}catch(r){return this.errorResponse([r])}}),"verifyOtp"));f(this,"graphqlQuery",a(e=>d(this,null,function*(){var c;let r=yield(yield N()(`${this.config.authorizerURL}/graphql`,{method:"POST",body:JSON.stringify({query:e.query,variables:e.variables||{}}),headers:x(x({},this.config.extraHeaders),e.headers||{}),credentials:"include"})).json();return(c=r==null?void 0:r.errors)!=null&&c.length?{data:void 0,errors:r.errors}:{data:r.data,errors:[]}}),"graphqlQuery"));f(this,"errorResponse",a(e=>({data:void 0,errors:e}),"errorResponse"));f(this,"okResponse",a(e=>({data:e,errors:[]}),"okResponse"));if(!e)throw new Error("Configuration is required");if(this.config=e,!e.authorizerURL&&!e.authorizerURL.trim())throw new Error("Invalid authorizerURL");if(e.authorizerURL&&(this.config.authorizerURL=M(e.authorizerURL)),!e.redirectURL&&!e.redirectURL.trim())throw new Error("Invalid redirectURL");this.config.redirectURL=M(e.redirectURL),this.config.extraHeaders=ee(x({},e.extraHeaders||{}),{"x-authorizer-url":this.config.authorizerURL,"x-authorizer-client-id":this.config.clientID||"","Content-Type":"application/json"}),this.config.clientID=((e==null?void 0:e.clientID)||"").trim()}};a(J,"Authorizer");var V=J;return qe(De);})();
16
17
  if (typeof window !== "undefined") { window.authorizerdev = authorizerdev; }
package/lib/index.js CHANGED
@@ -28,13 +28,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  Authorizer: () => Authorizer,
34
34
  OAuthProviders: () => OAuthProviders,
35
35
  ResponseTypes: () => ResponseTypes
36
36
  });
37
- module.exports = __toCommonJS(src_exports);
37
+ module.exports = __toCommonJS(index_exports);
38
38
  var import_cross_fetch = __toESM(require("cross-fetch"));
39
39
 
40
40
  // src/constants.ts
@@ -42,8 +42,7 @@ var DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS = 60;
42
42
  var CLEANUP_IFRAME_TIMEOUT_IN_SECONDS = 2;
43
43
 
44
44
  // src/types.ts
45
- var OAuthProviders;
46
- (function(OAuthProviders2) {
45
+ var OAuthProviders = /* @__PURE__ */ (function(OAuthProviders2) {
47
46
  OAuthProviders2["Apple"] = "apple";
48
47
  OAuthProviders2["Github"] = "github";
49
48
  OAuthProviders2["Google"] = "google";
@@ -54,20 +53,20 @@ var OAuthProviders;
54
53
  OAuthProviders2["Twitch"] = "twitch";
55
54
  OAuthProviders2["Roblox"] = "roblox";
56
55
  OAuthProviders2["Discord"] = "discord";
57
- })(OAuthProviders || (OAuthProviders = {}));
58
- var ResponseTypes;
59
- (function(ResponseTypes2) {
56
+ return OAuthProviders2;
57
+ })({});
58
+ var ResponseTypes = /* @__PURE__ */ (function(ResponseTypes2) {
60
59
  ResponseTypes2["Code"] = "code";
61
60
  ResponseTypes2["Token"] = "token";
62
- })(ResponseTypes || (ResponseTypes = {}));
61
+ return ResponseTypes2;
62
+ })({});
63
63
 
64
64
  // src/utils.ts
65
65
  var hasWindow = /* @__PURE__ */ __name(() => typeof window !== "undefined", "hasWindow");
66
66
  var trimURL = /* @__PURE__ */ __name((url) => {
67
67
  let trimmedData = url.trim();
68
68
  const lastChar = trimmedData[trimmedData.length - 1];
69
- if (lastChar === "/")
70
- trimmedData = trimmedData.slice(0, -1);
69
+ if (lastChar === "/") trimmedData = trimmedData.slice(0, -1);
71
70
  return trimmedData;
72
71
  }, "trimURL");
73
72
  var getCrypto = /* @__PURE__ */ __name(() => {
@@ -136,16 +135,14 @@ var executeIframe = /* @__PURE__ */ __name((authorizeUrl, eventOrigin, timeoutIn
136
135
  }
137
136
  }, "removeIframe");
138
137
  const timeoutSetTimeoutId = setTimeout(() => {
138
+ reject(new Error("Authorization timeout"));
139
139
  removeIframe();
140
140
  }, timeoutInSeconds * 1e3);
141
141
  const iframeEventHandler = /* @__PURE__ */ __name(function(e) {
142
- if (e.origin !== eventOrigin)
143
- return;
144
- if (!e.data || !e.data.response)
145
- return;
142
+ if (e.origin !== eventOrigin) return;
143
+ if (!e.data || !e.data.response) return;
146
144
  const eventSource = e.source;
147
- if (eventSource)
148
- eventSource.close();
145
+ if (eventSource) eventSource.close();
149
146
  e.data.response.error ? reject(e.data.response) : resolve(e.data.response);
150
147
  clearTimeout(timeoutSetTimeoutId);
151
148
  window.removeEventListener("message", iframeEventHandler, false);
@@ -167,17 +164,12 @@ var _Authorizer = class _Authorizer {
167
164
  codeVerifier;
168
165
  // constructor
169
166
  constructor(config) {
170
- if (!config)
171
- throw new Error("Configuration is required");
167
+ if (!config) throw new Error("Configuration is required");
172
168
  this.config = config;
173
- if (!config.authorizerURL && !config.authorizerURL.trim())
174
- throw new Error("Invalid authorizerURL");
175
- if (config.authorizerURL)
176
- this.config.authorizerURL = trimURL(config.authorizerURL);
177
- if (!config.redirectURL && !config.redirectURL.trim())
178
- throw new Error("Invalid redirectURL");
179
- else
180
- this.config.redirectURL = trimURL(config.redirectURL);
169
+ if (!config.authorizerURL && !config.authorizerURL.trim()) throw new Error("Invalid authorizerURL");
170
+ if (config.authorizerURL) this.config.authorizerURL = trimURL(config.authorizerURL);
171
+ if (!config.redirectURL && !config.redirectURL.trim()) throw new Error("Invalid redirectURL");
172
+ else this.config.redirectURL = trimURL(config.redirectURL);
181
173
  this.config.extraHeaders = {
182
174
  ...config.extraHeaders || {},
183
175
  "x-authorizer-url": this.config.authorizerURL,
@@ -186,19 +178,17 @@ var _Authorizer = class _Authorizer {
186
178
  };
187
179
  this.config.clientID = ((config == null ? void 0 : config.clientID) || "").trim();
188
180
  }
189
- authorize = async (data) => {
181
+ authorize = /* @__PURE__ */ __name(async (data) => {
190
182
  var _a;
191
- if (!hasWindow())
192
- return this.errorResponse([
193
- new Error("this feature is only supported in browser")
194
- ]);
183
+ if (!hasWindow()) return this.errorResponse([
184
+ new Error("this feature is only supported in browser")
185
+ ]);
195
186
  const scopes = [
196
187
  "openid",
197
188
  "profile",
198
189
  "email"
199
190
  ];
200
- if (data.use_refresh_token)
201
- scopes.push("offline_access");
191
+ if (data.use_refresh_token) scopes.push("offline_access");
202
192
  const requestData = {
203
193
  redirect_uri: this.config.redirectURL,
204
194
  response_mode: data.response_mode || "web_message",
@@ -230,12 +220,16 @@ var _Authorizer = class _Authorizer {
230
220
  return this.okResponse(iframeRes);
231
221
  } catch (err) {
232
222
  if (err.error) {
233
- window.location.replace(`${this.config.authorizerURL}/app?state=${encode(JSON.stringify(this.config))}&redirect_uri=${this.config.redirectURL}`);
223
+ window.location.replace(`${this.config.authorizerURL}/app?state=${encode(JSON.stringify({
224
+ clientID: this.config.clientID,
225
+ redirectURL: this.config.redirectURL,
226
+ authorizerURL: this.config.authorizerURL
227
+ }))}&redirect_uri=${encodeURIComponent(this.config.redirectURL || "")}`);
234
228
  }
235
229
  return this.errorResponse(err);
236
230
  }
237
- };
238
- browserLogin = async () => {
231
+ }, "authorize");
232
+ browserLogin = /* @__PURE__ */ __name(async () => {
239
233
  try {
240
234
  const tokenResp = await this.getSession();
241
235
  return tokenResp.errors.length ? this.errorResponse(tokenResp.errors) : this.okResponse(tokenResp.data);
@@ -248,16 +242,18 @@ var _Authorizer = class _Authorizer {
248
242
  ]
249
243
  };
250
244
  }
251
- window.location.replace(`${this.config.authorizerURL}/app?state=${encode(JSON.stringify(this.config))}&redirect_uri=${this.config.redirectURL}`);
245
+ window.location.replace(`${this.config.authorizerURL}/app?state=${encode(JSON.stringify({
246
+ clientID: this.config.clientID,
247
+ redirectURL: this.config.redirectURL,
248
+ authorizerURL: this.config.authorizerURL
249
+ }))}&redirect_uri=${encodeURIComponent(this.config.redirectURL || "")}`);
252
250
  return this.errorResponse(err);
253
251
  }
254
- };
255
- forgotPassword = async (data) => {
252
+ }, "browserLogin");
253
+ forgotPassword = /* @__PURE__ */ __name(async (data) => {
256
254
  var _a;
257
- if (!data.state)
258
- data.state = encode(createRandomString());
259
- if (!data.redirect_uri)
260
- data.redirect_uri = this.config.redirectURL;
255
+ if (!data.state) data.state = encode(createRandomString());
256
+ if (!data.redirect_uri) data.redirect_uri = this.config.redirectURL;
261
257
  try {
262
258
  const forgotPasswordResp = await this.graphqlQuery({
263
259
  query: "mutation forgotPassword($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }",
@@ -271,8 +267,8 @@ var _Authorizer = class _Authorizer {
271
267
  error
272
268
  ]);
273
269
  }
274
- };
275
- getMetaData = async () => {
270
+ }, "forgotPassword");
271
+ getMetaData = /* @__PURE__ */ __name(async () => {
276
272
  var _a;
277
273
  try {
278
274
  const res = await this.graphqlQuery({
@@ -284,8 +280,8 @@ var _Authorizer = class _Authorizer {
284
280
  error
285
281
  ]);
286
282
  }
287
- };
288
- getProfile = async (headers) => {
283
+ }, "getMetaData");
284
+ getProfile = /* @__PURE__ */ __name(async (headers) => {
289
285
  var _a;
290
286
  try {
291
287
  const profileRes = await this.graphqlQuery({
@@ -298,9 +294,9 @@ var _Authorizer = class _Authorizer {
298
294
  error
299
295
  ]);
300
296
  }
301
- };
297
+ }, "getProfile");
302
298
  // this is used to verify / get session using cookie by default. If using node.js pass authorization header
303
- getSession = async (headers, params) => {
299
+ getSession = /* @__PURE__ */ __name(async (headers, params) => {
304
300
  var _a, _b;
305
301
  try {
306
302
  const res = await this.graphqlQuery({
@@ -314,18 +310,15 @@ var _Authorizer = class _Authorizer {
314
310
  } catch (err) {
315
311
  return this.errorResponse(err);
316
312
  }
317
- };
318
- getToken = async (data) => {
319
- if (!data.grant_type)
320
- data.grant_type = "authorization_code";
321
- if (data.grant_type === "refresh_token" && !data.refresh_token)
322
- return this.errorResponse([
323
- new Error("Invalid refresh_token")
324
- ]);
325
- if (data.grant_type === "authorization_code" && !this.codeVerifier)
326
- return this.errorResponse([
327
- new Error("Invalid code verifier")
328
- ]);
313
+ }, "getSession");
314
+ getToken = /* @__PURE__ */ __name(async (data) => {
315
+ if (!data.grant_type) data.grant_type = "authorization_code";
316
+ if (data.grant_type === "refresh_token" && !data.refresh_token) return this.errorResponse([
317
+ new Error("Invalid refresh_token")
318
+ ]);
319
+ if (data.grant_type === "authorization_code" && !this.codeVerifier) return this.errorResponse([
320
+ new Error("Invalid code verifier")
321
+ ]);
329
322
  const requestData = {
330
323
  client_id: this.config.clientID,
331
324
  code: data.code || "",
@@ -344,16 +337,15 @@ var _Authorizer = class _Authorizer {
344
337
  credentials: "include"
345
338
  });
346
339
  const json = await res.json();
347
- if (res.status >= 400)
348
- return this.errorResponse([
349
- new Error(json.error_description || json.error)
350
- ]);
340
+ if (res.status >= 400) return this.errorResponse([
341
+ new Error(json.error_description || json.error)
342
+ ]);
351
343
  return this.okResponse(json);
352
344
  } catch (err) {
353
345
  return this.errorResponse(err);
354
346
  }
355
- };
356
- login = async (data) => {
347
+ }, "getToken");
348
+ login = /* @__PURE__ */ __name(async (data) => {
357
349
  var _a, _b;
358
350
  try {
359
351
  const res = await this.graphqlQuery({
@@ -370,8 +362,8 @@ var _Authorizer = class _Authorizer {
370
362
  new Error(err)
371
363
  ]);
372
364
  }
373
- };
374
- logout = async (headers) => {
365
+ }, "login");
366
+ logout = /* @__PURE__ */ __name(async (headers) => {
375
367
  var _a, _b;
376
368
  try {
377
369
  const res = await this.graphqlQuery({
@@ -384,14 +376,12 @@ var _Authorizer = class _Authorizer {
384
376
  err
385
377
  ]);
386
378
  }
387
- };
388
- magicLinkLogin = async (data) => {
379
+ }, "logout");
380
+ magicLinkLogin = /* @__PURE__ */ __name(async (data) => {
389
381
  var _a, _b;
390
382
  try {
391
- if (!data.state)
392
- data.state = encode(createRandomString());
393
- if (!data.redirect_uri)
394
- data.redirect_uri = this.config.redirectURL;
383
+ if (!data.state) data.state = encode(createRandomString());
384
+ if (!data.redirect_uri) data.redirect_uri = this.config.redirectURL;
395
385
  const res = await this.graphqlQuery({
396
386
  query: `
397
387
  mutation magicLinkLogin($data: MagicLinkLoginRequest!) { magic_link_login(params: $data) { message }}
@@ -406,8 +396,8 @@ var _Authorizer = class _Authorizer {
406
396
  err
407
397
  ]);
408
398
  }
409
- };
410
- oauthLogin = async (oauthProvider, roles, redirect_uri, state) => {
399
+ }, "magicLinkLogin");
400
+ oauthLogin = /* @__PURE__ */ __name(async (oauthProvider, roles, redirect_uri, state) => {
411
401
  let urlState = state;
412
402
  if (!urlState) {
413
403
  urlState = encode(createRandomString());
@@ -415,13 +405,11 @@ var _Authorizer = class _Authorizer {
415
405
  if (!Object.values(OAuthProviders).includes(oauthProvider)) {
416
406
  throw new Error(`only following oauth providers are supported: ${Object.values(oauthProvider).toString()}`);
417
407
  }
418
- if (!hasWindow())
419
- throw new Error("oauthLogin is only supported for browsers");
420
- if (roles && roles.length)
421
- urlState += `&roles=${roles.join(",")}`;
422
- window.location.replace(`${this.config.authorizerURL}/oauth_login/${oauthProvider}?redirect_uri=${redirect_uri || this.config.redirectURL}&state=${urlState}`);
423
- };
424
- resendOtp = async (data) => {
408
+ if (!hasWindow()) throw new Error("oauthLogin is only supported for browsers");
409
+ if (roles && roles.length) urlState += `&roles=${roles.join(",")}`;
410
+ window.location.replace(`${this.config.authorizerURL}/oauth_login/${oauthProvider}?redirect_uri=${encodeURIComponent(redirect_uri || this.config.redirectURL || "")}&state=${encodeURIComponent(urlState)}`);
411
+ }, "oauthLogin");
412
+ resendOtp = /* @__PURE__ */ __name(async (data) => {
425
413
  var _a, _b;
426
414
  try {
427
415
  const res = await this.graphqlQuery({
@@ -438,8 +426,8 @@ var _Authorizer = class _Authorizer {
438
426
  err
439
427
  ]);
440
428
  }
441
- };
442
- resetPassword = async (data) => {
429
+ }, "resendOtp");
430
+ resetPassword = /* @__PURE__ */ __name(async (data) => {
443
431
  var _a, _b;
444
432
  try {
445
433
  const resetPasswordRes = await this.graphqlQuery({
@@ -454,12 +442,11 @@ var _Authorizer = class _Authorizer {
454
442
  error
455
443
  ]);
456
444
  }
457
- };
458
- revokeToken = async (data) => {
459
- if (!data.refresh_token && !data.refresh_token.trim())
460
- return this.errorResponse([
461
- new Error("Invalid refresh_token")
462
- ]);
445
+ }, "resetPassword");
446
+ revokeToken = /* @__PURE__ */ __name(async (data) => {
447
+ if (!data.refresh_token && !data.refresh_token.trim()) return this.errorResponse([
448
+ new Error("Invalid refresh_token")
449
+ ]);
463
450
  const fetcher = getFetcher();
464
451
  const res = await fetcher(`${this.config.authorizerURL}/oauth/revoke`, {
465
452
  method: "POST",
@@ -473,8 +460,8 @@ var _Authorizer = class _Authorizer {
473
460
  });
474
461
  const responseData = await res.json();
475
462
  return this.okResponse(responseData);
476
- };
477
- signup = async (data) => {
463
+ }, "revokeToken");
464
+ signup = /* @__PURE__ */ __name(async (data) => {
478
465
  var _a, _b;
479
466
  try {
480
467
  const res = await this.graphqlQuery({
@@ -491,8 +478,8 @@ var _Authorizer = class _Authorizer {
491
478
  err
492
479
  ]);
493
480
  }
494
- };
495
- updateProfile = async (data, headers) => {
481
+ }, "signup");
482
+ updateProfile = /* @__PURE__ */ __name(async (data, headers) => {
496
483
  var _a, _b;
497
484
  try {
498
485
  const updateProfileRes = await this.graphqlQuery({
@@ -508,8 +495,8 @@ var _Authorizer = class _Authorizer {
508
495
  error
509
496
  ]);
510
497
  }
511
- };
512
- deactivateAccount = async (headers) => {
498
+ }, "updateProfile");
499
+ deactivateAccount = /* @__PURE__ */ __name(async (headers) => {
513
500
  var _a, _b;
514
501
  try {
515
502
  const res = await this.graphqlQuery({
@@ -522,8 +509,8 @@ var _Authorizer = class _Authorizer {
522
509
  error
523
510
  ]);
524
511
  }
525
- };
526
- validateJWTToken = async (params) => {
512
+ }, "deactivateAccount");
513
+ validateJWTToken = /* @__PURE__ */ __name(async (params) => {
527
514
  var _a, _b;
528
515
  try {
529
516
  const res = await this.graphqlQuery({
@@ -538,8 +525,8 @@ var _Authorizer = class _Authorizer {
538
525
  error
539
526
  ]);
540
527
  }
541
- };
542
- validateSession = async (params) => {
528
+ }, "validateJWTToken");
529
+ validateSession = /* @__PURE__ */ __name(async (params) => {
543
530
  var _a, _b;
544
531
  try {
545
532
  const res = await this.graphqlQuery({
@@ -554,8 +541,8 @@ var _Authorizer = class _Authorizer {
554
541
  error
555
542
  ]);
556
543
  }
557
- };
558
- verifyEmail = async (data) => {
544
+ }, "validateSession");
545
+ verifyEmail = /* @__PURE__ */ __name(async (data) => {
559
546
  var _a, _b;
560
547
  try {
561
548
  const res = await this.graphqlQuery({
@@ -572,8 +559,8 @@ var _Authorizer = class _Authorizer {
572
559
  err
573
560
  ]);
574
561
  }
575
- };
576
- resendVerifyEmail = async (data) => {
562
+ }, "verifyEmail");
563
+ resendVerifyEmail = /* @__PURE__ */ __name(async (data) => {
577
564
  var _a, _b;
578
565
  try {
579
566
  const res = await this.graphqlQuery({
@@ -590,8 +577,8 @@ var _Authorizer = class _Authorizer {
590
577
  err
591
578
  ]);
592
579
  }
593
- };
594
- verifyOtp = async (data) => {
580
+ }, "resendVerifyEmail");
581
+ verifyOtp = /* @__PURE__ */ __name(async (data) => {
595
582
  var _a, _b;
596
583
  try {
597
584
  const res = await this.graphqlQuery({
@@ -608,10 +595,10 @@ var _Authorizer = class _Authorizer {
608
595
  err
609
596
  ]);
610
597
  }
611
- };
598
+ }, "verifyOtp");
612
599
  // helper to execute graphql queries
613
600
  // takes in any query or mutation string as value
614
- graphqlQuery = async (data) => {
601
+ graphqlQuery = /* @__PURE__ */ __name(async (data) => {
615
602
  var _a;
616
603
  const fetcher = getFetcher();
617
604
  const res = await fetcher(`${this.config.authorizerURL}/graphql`, {
@@ -637,19 +624,19 @@ var _Authorizer = class _Authorizer {
637
624
  data: json.data,
638
625
  errors: []
639
626
  };
640
- };
641
- errorResponse = (errors) => {
627
+ }, "graphqlQuery");
628
+ errorResponse = /* @__PURE__ */ __name((errors) => {
642
629
  return {
643
630
  data: void 0,
644
631
  errors
645
632
  };
646
- };
647
- okResponse = (data) => {
633
+ }, "errorResponse");
634
+ okResponse = /* @__PURE__ */ __name((data) => {
648
635
  return {
649
636
  data,
650
637
  errors: []
651
638
  };
652
- };
639
+ }, "okResponse");
653
640
  };
654
641
  __name(_Authorizer, "Authorizer");
655
642
  var Authorizer = _Authorizer;