@authorizerdev/authorizer-js 3.0.0 → 3.0.2

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:`
1
+ var authorizerdev=(()=>{var we=Object.create;var q=Object.defineProperty,be=Object.defineProperties,Re=Object.getOwnPropertyDescriptor,ve=Object.getOwnPropertyDescriptors,Ee=Object.getOwnPropertyNames,K=Object.getOwnPropertySymbols,Te=Object.getPrototypeOf,Y=Object.prototype.hasOwnProperty,Ue=Object.prototype.propertyIsEnumerable;var N=(n,e,o)=>e in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o,O=(n,e)=>{for(var o in e||(e={}))Y.call(e,o)&&N(n,o,e[o]);if(K)for(var o of K(e))Ue.call(e,o)&&N(n,o,e[o]);return n},ee=(n,e)=>be(n,ve(e)),a=(n,e)=>q(n,"name",{value:e,configurable:!0});var ke=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ae=(n,e)=>{for(var o in e)q(n,o,{get:e[o],enumerable:!0})},re=(n,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ee(e))!Y.call(n,r)&&r!==o&&q(n,r,{get:()=>e[r],enumerable:!(s=Re(e,r))||s.enumerable});return n};var xe=(n,e,o)=>(o=n!=null?we(Te(n)):{},re(e||!n||!n.__esModule?q(o,"default",{value:n,enumerable:!0}):o,n)),qe=n=>re(q({},"__esModule",{value:!0}),n);var d=(n,e,o)=>N(n,typeof e!="symbol"?e+"":e,o);var p=(n,e,o)=>new Promise((s,r)=>{var c=m=>{try{y(o.next(m))}catch(b){r(b)}},f=m=>{try{y(o.throw(m))}catch(b){r(b)}},y=m=>m.done?s(m.value):Promise.resolve(m.value).then(c,f);y((o=o.apply(n,e)).next())});var oe=ke((T,te)=>{var $=typeof globalThis!="undefined"&&globalThis||typeof self!="undefined"&&self||typeof global!="undefined"&&global,B=(function(){function n(){this.fetch=!1,this.DOMException=$.DOMException}return a(n,"F"),n.prototype=$,new n})();(function(n){var e=(function(o){var s=typeof n!="undefined"&&n||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 f=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],y=ArrayBuffer.isView||function(t){return t&&f.indexOf(Object.prototype.toString.call(t))>-1};function m(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(m,"normalizeName");function b(t){return typeof t!="string"&&(t=String(t)),t}a(b,"normalizeValue");function R(t){var i={next:a(function(){var u=t.shift();return{done:u===void 0,value:u}},"next")};return r.iterable&&(i[Symbol.iterator]=function(){return i}),i}a(R,"iteratorFor");function _(t){this.map={},t instanceof _?t.forEach(function(i,u){this.append(u,i)},this):Array.isArray(t)?t.forEach(function(i){if(i.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+i.length);this.append(i[0],i[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(i){this.append(i,t[i])},this)}a(_,"Headers"),_.prototype.append=function(t,i){t=m(t),i=b(i);var u=this.map[t];this.map[t]=u?u+", "+i:i},_.prototype.delete=function(t){delete this.map[m(t)]},_.prototype.get=function(t){return t=m(t),this.has(t)?this.map[t]:null},_.prototype.has=function(t){return this.map.hasOwnProperty(m(t))},_.prototype.set=function(t,i){this.map[m(t)]=b(i)},_.prototype.forEach=function(t,i){for(var u in this.map)this.map.hasOwnProperty(u)&&t.call(i,this.map[u],u,this)},_.prototype.keys=function(){var t=[];return this.forEach(function(i,u){t.push(u)}),R(t)},_.prototype.values=function(){var t=[];return this.forEach(function(i){t.push(i)}),R(t)},_.prototype.entries=function(){var t=[];return this.forEach(function(i,u){t.push([u,i])}),R(t)},r.iterable&&(_.prototype[Symbol.iterator]=_.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(i,u){t.onload=function(){i(t.result)},t.onerror=function(){u(t.error)}})}a(G,"fileReaderReady");function fe(t){var i=new FileReader,u=G(i);return i.readAsArrayBuffer(t),u}a(fe,"readBlobAsArrayBuffer");function de(t){var i=new FileReader,u=G(i),l=/charset=([A-Za-z0-9_-]+)/.exec(t.type),g=l?l[1]:"utf-8";return i.readAsText(t,g),u}a(de,"readBlobAsText");function le(t){for(var i=new Uint8Array(t),u=new Array(i.length),l=0;l<i.length;l++)u[l]=String.fromCharCode(i[l]);return u.join("")}a(le,"readArrayBufferAsText");function W(t){if(t.slice)return t.slice(0);var i=new Uint8Array(t.byteLength);return i.set(new Uint8Array(t)),i.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)||y(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(fe);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var t=C(this);if(t)return t;if(this._bodyBlob)return de(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(_e)}),this.json=function(){return this.text().then(JSON.parse)},this}a(Z,"Body");var pe=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function ye(t){var i=t.toUpperCase();return pe.indexOf(i)>-1?i:t}a(ye,"normalizeMethod");function E(t,i){if(!(this instanceof E))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');i=i||{};var u=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 _(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,!u&&t._bodyInit!=null&&(u=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 _(i.headers)),this.method=ye(i.method||this.method||"GET"),this.mode=i.mode||this.mode||null,this.signal=i.signal||this.signal||(function(){if("AbortController"in s){var h=new AbortController;return h.signal}})(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&u)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(u),(this.method==="GET"||this.method==="HEAD")&&(i.cache==="no-store"||i.cache==="no-cache")){var l=/([?&])_=[^&]*/;if(l.test(this.url))this.url=this.url.replace(l,"$1_="+new Date().getTime());else{var g=/\?/;this.url+=(g.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}a(E,"Request"),E.prototype.clone=function(){return new E(this,{body:this._bodyInit})};function _e(t){var i=new FormData;return t.trim().split("&").forEach(function(u){if(u){var l=u.split("="),g=l.shift().replace(/\+/g," "),h=l.join("=").replace(/\+/g," ");i.append(decodeURIComponent(g),decodeURIComponent(h))}}),i}a(_e,"decode");function ge(t){var i=new _,u=t.replace(/\r?\n[\t ]+/g," ");return u.split("\r").map(function(l){return l.indexOf(`
2
+ `)===0?l.substr(1,l.length):l}).forEach(function(l){var g=l.split(":"),h=g.shift().trim();if(h){var I=g.join(":").trim();try{i.append(h,I)}catch(H){console.warn("Response "+H.message)}}}),i}a(ge,"parseHeaders"),Z.call(E.prototype);function v(t,i){if(!(this instanceof v))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(i||(i={}),this.type="default",this.status=i.status===void 0?200:i.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=i.statusText===void 0?"":""+i.statusText,this.headers=new _(i.headers),this.url=i.url||"",this._initBody(t)}a(v,"Response"),Z.call(v.prototype),v.prototype.clone=function(){return new v(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new _(this.headers),url:this.url})},v.error=function(){var t=new v(null,{status:200,statusText:""});return t.ok=!1,t.status=0,t.type="error",t};var me=[301,302,303,307,308];v.redirect=function(t,i){if(me.indexOf(i)===-1)throw new RangeError("Invalid status code");return new v(null,{status:i,headers:{location:t}})},o.DOMException=s.DOMException;try{new o.DOMException}catch(t){o.DOMException=function(i,u){this.message=i,this.name=u;var l=Error(i);this.stack=l.stack},o.DOMException.prototype=Object.create(Error.prototype),o.DOMException.prototype.constructor=o.DOMException}function P(t,i){return new Promise(function(u,l){var g=new E(t,i);if(g.signal&&g.signal.aborted)return l(new o.DOMException("Aborted","AbortError"));var h=new XMLHttpRequest;function I(){h.abort()}a(I,"abortXhr"),h.onload=function(){var w={statusText:h.statusText,headers:ge(h.getAllResponseHeaders()||"")};g.url.indexOf("file://")===0&&(h.status<200||h.status>599)?w.status=200:w.status=h.status,w.url="responseURL"in h?h.responseURL:w.headers.get("X-Request-URL");var k="response"in h?h.response:h.responseText;setTimeout(function(){u(new v(k,w))},0)},h.onerror=function(){setTimeout(function(){l(new TypeError("Network request failed"))},0)},h.ontimeout=function(){setTimeout(function(){l(new TypeError("Network request timed out"))},0)},h.onabort=function(){setTimeout(function(){l(new o.DOMException("Aborted","AbortError"))},0)};function H(w){try{return w===""&&s.location.href?s.location.href:w}catch(k){return w}}if(a(H,"fixUrl"),h.open(g.method,H(g.url),!0),g.credentials==="include"?h.withCredentials=!0:g.credentials==="omit"&&(h.withCredentials=!1),"responseType"in h&&(r.blob?h.responseType="blob":r.arrayBuffer&&(h.responseType="arraybuffer")),i&&typeof i.headers=="object"&&!(i.headers instanceof _||s.Headers&&i.headers instanceof s.Headers)){var X=[];Object.getOwnPropertyNames(i.headers).forEach(function(w){X.push(m(w)),h.setRequestHeader(w,b(i.headers[w]))}),g.headers.forEach(function(w,k){X.indexOf(k)===-1&&h.setRequestHeader(k,w)})}else g.headers.forEach(function(w,k){h.setRequestHeader(k,w)});g.signal&&(g.signal.addEventListener("abort",I),h.onreadystatechange=function(){h.readyState===4&&g.signal.removeEventListener("abort",I)}),h.send(typeof g._bodyInit=="undefined"?null:g._bodyInit)})}return a(P,"fetch"),P.polyfill=!0,s.fetch||(s.fetch=P,s.Headers=_,s.Request=E,s.Response=v),o.Headers=_,o.Request=E,o.Response=v,o.fetch=P,o})({})})(B);B.fetch.ponyfill=!0;delete B.fetch.polyfill;var L=$.fetch?$:B;T=L.fetch;T.default=L.fetch;T.fetch=L.fetch;T.Headers=L.Headers;T.Request=L.Request;T.Response=L.Response;te.exports=T});var Be={};Ae(Be,{Authorizer:()=>V,OAuthProviders:()=>F,ResponseTypes:()=>D});var he=xe(oe());var F=(function(n){return 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",n})({}),D=(function(n){return n.Code="code",n.Token="token",n})({});var A=a(()=>typeof window!="undefined","hasWindow"),z=a(n=>{let e=n.trim();return e[e.length-1]==="/"&&(e=e.slice(0,-1)),e},"trimURL"),se=a(()=>A()?window.crypto||window.msCrypto:null,"getCrypto"),Se=a(()=>{let n=se();return n&&n.subtle||n.webkitSubtle},"getCryptoSubtle"),x=a(()=>{let n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.",e="",o=se();return o&&Array.from(o.getRandomValues(new Uint8Array(43))).forEach(r=>e+=n[r%n.length]),e},"createRandomString"),U=a(n=>A()?btoa(n):Buffer.from(n).toString("base64"),"encode");var ne=a(n=>Object.keys(n).filter(e=>typeof n[e]!="undefined").map(e=>`${encodeURIComponent(e)}=${encodeURIComponent(n[e])}`).join("&"),"createQueryParams"),ie=a(n=>p(null,null,function*(){let e=Se();if(!e)throw new Error("Web Crypto API is not available");let o=e.digest({name:"SHA-256"},new TextEncoder().encode(n));return window.msCrypto?new Promise((s,r)=>{o.oncomplete=c=>{s(c.target.result)},o.onerror=c=>{r(c.error)},o.onabort=()=>{r(new Error("The digest operation was aborted"))}}):yield o}),"sha256"),Ie=a(n=>{let e={"+":"-","/":"_","=":""};return n.replace(/[+/=]/g,o=>e[o])},"urlEncodeB64");var ae=a(n=>{let e=new Uint8Array(n);return Ie(window.btoa(String.fromCharCode(...Array.from(e))))},"bufferToBase64UrlEncoded"),$e=a(n=>{try{return new URL(n).origin}catch(e){return n}},"originFromAuthorizerUrl"),ce=a((n,e,o=60)=>new Promise((s,r)=>{let c=$e(e),f=window.document.createElement("iframe");f.setAttribute("id","authorizer-iframe"),f.setAttribute("width","0"),f.setAttribute("height","0"),f.style.display="none";let y=a(()=>{window.document.body.contains(f)&&(window.document.body.removeChild(f),window.removeEventListener("message",b,!1))},"removeIframe"),m=setTimeout(()=>{r(new Error("Authorization timeout")),y()},o*1e3),b=a(function(R){if(R.origin!==c||!R.data||!R.data.response)return;let _=R.source;_&&_.close(),R.data.response.error?r(R.data.response):s(R.data.response),clearTimeout(m),window.removeEventListener("message",b,!1),setTimeout(y,2*1e3)},"iframeEventHandler");window.addEventListener("message",b,!1),window.document.body.appendChild(f),f.setAttribute("src",n)}),"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",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 { ${Q} }`,M=a(()=>A()?window.fetch:he.default,"getFetcher");function ue(n){if(Array.isArray(n))return n.map(e=>e instanceof Error?e:e&&typeof e=="object"&&"message"in e?new Error(String(e.message)):new Error(String(e)));if(n instanceof Error)return[n];if(n!==null&&typeof n=="object"){let e=n;if(typeof e.error_description=="string")return[new Error(e.error_description)];if(typeof e.error=="string"){let o=typeof e.error_description=="string"?`: ${e.error_description}`:"";return[new Error(`${e.error}${o}`)]}if(typeof e.message=="string")return[new Error(e.message)]}return n==null?[new Error("Unknown error")]:[new Error(String(n))]}a(ue,"toErrorList");var J=class J{constructor(e){d(this,"config");d(this,"codeVerifier");d(this,"authorize",a(e=>p(this,null,function*(){var c;if(!A())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:U(x()),nonce:U(x()),response_type:e.response_type,scope:o.join(" "),client_id:((c=this.config)==null?void 0:c.clientID)||""};if(e.response_type===D.Code){this.codeVerifier=x();let f=yield ie(this.codeVerifier),y=ae(f);s.code_challenge=y,s.code_challenge_method="S256"}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 f=yield ce(r,this.config.authorizerURL,60);if(e.response_type===D.Code){let y=yield this.getToken({code:f.code});return y.errors.length?this.errorResponse(y.errors):this.okResponse(y.data)}return this.okResponse(f)}catch(f){return f.error&&window.location.replace(`${this.config.authorizerURL}/app?state=${U(JSON.stringify({clientID:this.config.clientID,redirectURL:this.config.redirectURL,authorizerURL:this.config.authorizerURL}))}&redirect_uri=${encodeURIComponent(this.config.redirectURL||"")}`),this.errorResponse(f)}}),"authorize"));d(this,"browserLogin",a(()=>p(this,null,function*(){try{let e=yield this.getSession();return e.errors.length?this.errorResponse(e.errors):this.okResponse(e.data)}catch(e){return A()?(window.location.replace(`${this.config.authorizerURL}/app?state=${U(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"));d(this,"forgotPassword",a(e=>p(this,null,function*(){var o,s;e.state||(e.state=U(x())),e.redirect_uri||(e.redirect_uri=this.config.redirectURL);try{let r=yield this.graphqlQuery({query:"mutation forgotPassword($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }",variables:{data:e}});return(o=r==null?void 0:r.errors)!=null&&o.length?this.errorResponse(r.errors):this.okResponse((s=r==null?void 0:r.data)==null?void 0:s.forgot_password)}catch(r){return this.errorResponse([r])}}),"forgotPassword"));d(this,"getMetaData",a(()=>p(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"));d(this,"getProfile",a(e=>p(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"));d(this,"getSession",a((e,o)=>p(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"));d(this,"getToken",a(e=>p(this,null,function*(){var s;if(e.grant_type||(e.grant_type="authorization_code"),e.grant_type==="refresh_token"&&!((s=e.refresh_token)!=null&&s.trim()))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 c=yield M()(`${this.config.authorizerURL}/oauth/token`,{method:"POST",body:JSON.stringify(o),headers:O({},this.config.extraHeaders),credentials:"include"}),f=yield c.text(),y={};if(f)try{y=JSON.parse(f)}catch(m){return this.errorResponse([new Error(c.ok?"Invalid JSON from token endpoint":`HTTP ${c.status}`)])}return c.ok?this.okResponse(y):this.errorResponse([new Error(String(y.error_description||y.error||`HTTP ${c.status}`))])}catch(r){return this.errorResponse(r)}}),"getToken"));d(this,"login",a(e=>p(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
2
3
  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:`
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(r)}}),"login"));d(this,"logout",a(e=>p(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.logout)}catch(r){return this.errorResponse([r])}}),"logout"));d(this,"magicLinkLogin",a(e=>p(this,null,function*(){var o,s;try{e.state||(e.state=U(x())),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"));d(this,"oauthLogin",a((e,o,s,r)=>p(this,null,function*(){let c=r;c||(c=U(x()));let f=Object.values(F);if(!f.includes(e))throw new Error(`only following oauth providers are supported: ${f.join(", ")}`);if(!A())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"));d(this,"resendOtp",a(e=>p(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
+ `,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"));d(this,"resetPassword",a(e=>p(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"));d(this,"revokeToken",a(e=>p(this,null,function*(){var o;if(!((o=e.refresh_token)!=null&&o.trim()))return this.errorResponse([new Error("Invalid refresh_token")]);try{let r=yield M()(`${this.config.authorizerURL}/oauth/revoke`,{method:"POST",headers:O({},this.config.extraHeaders),body:JSON.stringify({refresh_token:e.refresh_token,client_id:this.config.clientID})}),c=yield r.text(),f={};if(c)try{f=JSON.parse(c)}catch(y){return this.errorResponse([new Error(r.ok?"Invalid JSON from revoke endpoint":`HTTP ${r.status}`)])}if(!r.ok){let y=f;return this.errorResponse([new Error(String(y.error_description||y.error||`HTTP ${r.status}`))])}return this.okResponse(f)}catch(s){return this.errorResponse(s)}}),"revokeToken"));d(this,"signup",a(e=>p(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
8
9
  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
+ `,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"));d(this,"updateProfile",a((e,o)=>p(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"));d(this,"deactivateAccount",a(e=>p(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"));d(this,"validateJWTToken",a(e=>p(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"));d(this,"validateSession",a(e=>p(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"));d(this,"verifyEmail",a(e=>p(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
10
11
  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:`
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"));d(this,"resendVerifyEmail",a(e=>p(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
+ `,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"));d(this,"verifyOtp",a(e=>p(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
14
15
  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);})();
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"));d(this,"graphqlQuery",a(e=>p(this,null,function*(){var f;let s=yield M()(`${this.config.authorizerURL}/graphql`,{method:"POST",body:JSON.stringify({query:e.query,variables:e.variables||{}}),headers:O(O({},this.config.extraHeaders),e.headers||{}),credentials:"include"}),r=yield s.text(),c={};if(r)try{c=JSON.parse(r)}catch(y){return{data:void 0,errors:[new Error(s.ok?"Invalid JSON from GraphQL endpoint":`HTTP ${s.status}`)]}}else if(!s.ok)return{data:void 0,errors:[new Error(`HTTP ${s.status}`)]};return(f=c==null?void 0:c.errors)!=null&&f.length?{data:void 0,errors:ue(c.errors)}:s.ok?{data:c.data,errors:[]}:{data:void 0,errors:[new Error(`HTTP ${s.status}`)]}}),"graphqlQuery"));d(this,"errorResponse",a(e=>({data:void 0,errors:ue(e)}),"errorResponse"));d(this,"okResponse",a(e=>({data:e,errors:[]}),"okResponse"));var o,s;if(!e)throw new Error("Configuration is required");if(this.config=e,!((o=e.authorizerURL)!=null&&o.trim()))throw new Error("Invalid authorizerURL");if(this.config.authorizerURL=z(e.authorizerURL),!((s=e.redirectURL)!=null&&s.trim()))throw new Error("Invalid redirectURL");this.config.redirectURL=z(e.redirectURL),this.config.clientID=((e==null?void 0:e.clientID)||"").trim(),this.config.extraHeaders=ee(O({},e.extraHeaders||{}),{"x-authorizer-url":e.authorizerURL,"x-authorizer-client-id":e.clientID||"","Content-Type":"application/json"})}};a(J,"Authorizer");var V=J;return qe(Be);})();
16
17
  if (typeof window !== "undefined") { window.authorizerdev = authorizerdev; }
package/lib/index.d.mts CHANGED
@@ -333,7 +333,7 @@ declare class Authorizer {
333
333
  resendVerifyEmail: (data: ResendVerifyEmailRequest) => Promise<ApiResponse<GenericResponse>>;
334
334
  verifyOtp: (data: VerifyOtpRequest) => Promise<ApiResponse<AuthToken>>;
335
335
  graphqlQuery: (data: GraphqlQueryRequest) => Promise<GrapQlResponseType>;
336
- errorResponse: (errors: Error[]) => ApiResponse<any>;
336
+ errorResponse: (errors: unknown) => ApiResponse<any>;
337
337
  okResponse: (data: any) => ApiResponse<any>;
338
338
  }
339
339
 
package/lib/index.d.ts CHANGED
@@ -333,7 +333,7 @@ declare class Authorizer {
333
333
  resendVerifyEmail: (data: ResendVerifyEmailRequest) => Promise<ApiResponse<GenericResponse>>;
334
334
  verifyOtp: (data: VerifyOtpRequest) => Promise<ApiResponse<AuthToken>>;
335
335
  graphqlQuery: (data: GraphqlQueryRequest) => Promise<GrapQlResponseType>;
336
- errorResponse: (errors: Error[]) => ApiResponse<any>;
336
+ errorResponse: (errors: unknown) => ApiResponse<any>;
337
337
  okResponse: (data: any) => ApiResponse<any>;
338
338
  }
339
339