@authorizerdev/authorizer-js 3.0.2 → 3.0.4
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.
- package/lib/authorizer.min.js +16 -16
- package/lib/index.d.mts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +56 -35
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +56 -35
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
package/lib/authorizer.min.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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
|
|
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:`
|
|
3
|
-
mutation login($data: LoginRequest!) { login(params: $data) { ${
|
|
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=>
|
|
5
|
-
mutation
|
|
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)=>
|
|
7
|
-
mutation
|
|
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=>
|
|
9
|
-
mutation signup($data: SignUpRequest!) { signup(params: $data) { ${
|
|
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)=>
|
|
11
|
-
mutation
|
|
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=>
|
|
13
|
-
mutation
|
|
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=>
|
|
15
|
-
mutation
|
|
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=>
|
|
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 H=(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)&&H(n,o,e[o]);if(K)for(var o of K(e))Ue.call(e,o)&&H(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)=>H(n,typeof e!="symbol"?e+"":e,o);var y=(n,e,o)=>new Promise((s,r)=>{var c=g=>{try{p(o.next(g))}catch(b){r(b)}},h=g=>{try{p(o.throw(g))}catch(b){r(b)}},p=g=>g.done?s(g.value):Promise.resolve(g.value).then(c,h);p((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 h=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],p=ArrayBuffer.isView||function(t){return t&&h.indexOf(Object.prototype.toString.call(t))>-1};function g(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(g,"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=g(t),i=b(i);var u=this.map[t];this.map[t]=u?u+", "+i:i},_.prototype.delete=function(t){delete this.map[g(t)]},_.prototype.get=function(t){return t=g(t),this.has(t)?this.map[t]:null},_.prototype.has=function(t){return this.map.hasOwnProperty(g(t))},_.prototype.set=function(t,i){this.map[g(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 N(t){if(!t._noBody){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}}a(N,"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),m=l?l[1]:"utf-8";return i.readAsText(t,m),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)||p(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=N(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=N(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=N(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 f=new AbortController;return f.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 m=/\?/;this.url+=(m.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("="),m=l.shift().replace(/\+/g," "),f=l.join("=").replace(/\+/g," ");i.append(decodeURIComponent(m),decodeURIComponent(f))}}),i}a(_e,"decode");function me(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 m=l.split(":"),f=m.shift().trim();if(f){var S=m.join(":").trim();try{i.append(f,S)}catch(P){console.warn("Response "+P.message)}}}),i}a(me,"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 ge=[301,302,303,307,308];v.redirect=function(t,i){if(ge.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 C(t,i){return new Promise(function(u,l){var m=new E(t,i);if(m.signal&&m.signal.aborted)return l(new o.DOMException("Aborted","AbortError"));var f=new XMLHttpRequest;function S(){f.abort()}a(S,"abortXhr"),f.onload=function(){var w={statusText:f.statusText,headers:me(f.getAllResponseHeaders()||"")};m.url.indexOf("file://")===0&&(f.status<200||f.status>599)?w.status=200:w.status=f.status,w.url="responseURL"in f?f.responseURL:w.headers.get("X-Request-URL");var k="response"in f?f.response:f.responseText;setTimeout(function(){u(new v(k,w))},0)},f.onerror=function(){setTimeout(function(){l(new TypeError("Network request failed"))},0)},f.ontimeout=function(){setTimeout(function(){l(new TypeError("Network request timed out"))},0)},f.onabort=function(){setTimeout(function(){l(new o.DOMException("Aborted","AbortError"))},0)};function P(w){try{return w===""&&s.location.href?s.location.href:w}catch(k){return w}}if(a(P,"fixUrl"),f.open(m.method,P(m.url),!0),m.credentials==="include"?f.withCredentials=!0:m.credentials==="omit"&&(f.withCredentials=!1),"responseType"in f&&(r.blob?f.responseType="blob":r.arrayBuffer&&(f.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(g(w)),f.setRequestHeader(w,b(i.headers[w]))}),m.headers.forEach(function(w,k){X.indexOf(k)===-1&&f.setRequestHeader(k,w)})}else m.headers.forEach(function(w,k){f.setRequestHeader(k,w)});m.signal&&(m.signal.addEventListener("abort",S),f.onreadystatechange=function(){f.readyState===4&&m.signal.removeEventListener("abort",S)}),f.send(typeof m._bodyInit=="undefined"?null:m._bodyInit)})}return a(C,"fetch"),C.polyfill=!0,s.fetch||(s.fetch=C,s.Headers=_,s.Request=E,s.Response=v),o.Headers=_,o.Request=E,o.Response=v,o.fetch=C,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:()=>j,ResponseTypes:()=>D});var he=xe(oe());var j=(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"),Ie=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=>y(null,null,function*(){let e=Ie();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"),Se=a(n=>{let e={"+":"-","/":"_","=":""};return n.replace(/[+/=]/g,o=>e[o])},"urlEncodeB64");var ae=a(n=>{let e=new Uint8Array(n);return Se(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),h=window.document.createElement("iframe");h.setAttribute("id","authorizer-iframe"),h.setAttribute("width","0"),h.setAttribute("height","0"),h.style.display="none";let p=a(()=>{window.document.body.contains(h)&&(window.document.body.removeChild(h),window.removeEventListener("message",b,!1))},"removeIframe"),g=setTimeout(()=>{r(new Error("Authorization timeout")),p()},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(g),window.removeEventListener("message",b,!1),setTimeout(p,2*1e3)},"iframeEventHandler");window.addEventListener("message",b,!1),window.document.body.appendChild(h),h.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",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} }`,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=>y(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 h=yield ie(this.codeVerifier),p=ae(h);s.code_challenge=p,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 h=yield ce(r,this.config.authorizerURL,60);if(e.response_type===D.Code){let p=yield this.getToken({code:h.code});return p.errors.length?this.errorResponse(p.errors):this.okResponse(p.data)}return this.okResponse(h)}catch(h){return h.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(h)}}),"authorize"));d(this,"browserLogin",a(()=>y(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=>y(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 forgot_password($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }",variables:{data:e},operationName:"forgot_password"});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(()=>y(this,null,function*(){var e;try{let o=yield this.graphqlQuery({query:"query meta { 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 } }",operationName:"meta"});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=>y(this,null,function*(){var o;try{let s=yield this.graphqlQuery({query:`query profile { profile { ${Q} } }`,headers:e,operationName:"profile"});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)=>y(this,null,function*(){var s,r;try{let c=yield this.graphqlQuery({query:`query session($params: SessionQueryRequest){session(params: $params) { ${I} } }`,headers:e,variables:{params:o},operationName:"session"});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=>y(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"}),h=yield c.text(),p={};if(h)try{p=JSON.parse(h)}catch(g){return this.errorResponse([new Error(c.ok?"Invalid JSON from token endpoint":`HTTP ${c.status}`)])}return c.ok?this.okResponse(p):this.errorResponse([new Error(String(p.error_description||p.error||`HTTP ${c.status}`))])}catch(r){return this.errorResponse(r)}}),"getToken"));d(this,"login",a(e=>y(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},operationName:"login"});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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"mutation logout { logout { message } }",headers:e,operationName:"logout"});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=>y(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:`
|
|
5
|
+
mutation magic_link_login($data: MagicLinkLoginRequest!) { magic_link_login(params: $data) { message }}
|
|
6
|
+
`,variables:{data:e},operationName:"magic_link_login"});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)=>y(this,null,function*(){let c=r;c||(c=U(x()));let h=Object.values(j);if(!h.includes(e))throw new Error(`only following oauth providers are supported: ${h.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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
|
|
7
|
+
mutation resend_otp($data: ResendOTPRequest!) { resend_otp(params: $data) { message }}
|
|
8
|
+
`,variables:{data:e},operationName:"resend_otp"});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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"mutation reset_password($data: ResetPasswordRequest!) { reset_password(params: $data) { message } }",variables:{data:e},operationName:"reset_password"});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=>y(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(),h={};if(c)try{h=JSON.parse(c)}catch(p){return this.errorResponse([new Error(r.ok?"Invalid JSON from revoke endpoint":`HTTP ${r.status}`)])}if(!r.ok){let p=h;return this.errorResponse([new Error(String(p.error_description||p.error||`HTTP ${r.status}`))])}return this.okResponse(h)}catch(s){return this.errorResponse(s)}}),"revokeToken"));d(this,"signup",a(e=>y(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},operationName:"signup"});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)=>y(this,null,function*(){var s,r;try{let c=yield this.graphqlQuery({query:"mutation update_profile($data: UpdateProfileRequest!) { update_profile(params: $data) { message } }",headers:o,variables:{data:e},operationName:"update_profile"});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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"mutation deactivate_account { deactivate_account { message } }",headers:e,operationName:"deactivate_account"});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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:"query validate_jwt_token($params: ValidateJWTTokenRequest!){validate_jwt_token(params: $params) { is_valid claims } }",variables:{params:e},operationName:"validate_jwt_token"});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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`query validate_session($params: ValidateSessionRequest){validate_session(params: $params) { is_valid user { ${Q} } } }`,variables:{params:e},operationName:"validate_session"});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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
|
|
11
|
+
mutation verify_email($data: VerifyEmailRequest!) { verify_email(params: $data) { ${I}}}
|
|
12
|
+
`,variables:{data:e},operationName:"verify_email"});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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
|
|
13
|
+
mutation resend_verify_email($data: ResendVerifyEmailRequest!) { resend_verify_email(params: $data) { message }}
|
|
14
|
+
`,variables:{data:e},operationName:"resend_verify_email"});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=>y(this,null,function*(){var o,s;try{let r=yield this.graphqlQuery({query:`
|
|
15
|
+
mutation verify_otp($data: VerifyOTPRequest!) { verify_otp(params: $data) { ${I}}}
|
|
16
|
+
`,variables:{data:e},operationName:"verify_otp"});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=>y(this,null,function*(){var p;let o=M(),s={query:e.query,variables:e.variables||{}};e.operationName&&(s.operationName=e.operationName);let r=yield o(`${this.config.authorizerURL}/graphql`,{method:"POST",body:JSON.stringify(s),headers:O(O({},this.config.extraHeaders),e.headers||{}),credentials:"include"}),c=yield r.text(),h={};if(c)try{h=JSON.parse(c)}catch(g){return{data:void 0,errors:[new Error(r.ok?"Invalid JSON from GraphQL endpoint":`HTTP ${r.status}`)]}}else if(!r.ok)return{data:void 0,errors:[new Error(`HTTP ${r.status}`)]};return(p=h==null?void 0:h.errors)!=null&&p.length?{data:void 0,errors:ue(h.errors)}:r.ok?{data:h.data,errors:[]}:{data:void 0,errors:[new Error(`HTTP ${r.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);})();
|
|
17
17
|
if (typeof window !== "undefined") { window.authorizerdev = authorizerdev; }
|
package/lib/index.d.mts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -303,10 +303,11 @@ var _Authorizer = class _Authorizer {
|
|
|
303
303
|
if (!data.redirect_uri) data.redirect_uri = this.config.redirectURL;
|
|
304
304
|
try {
|
|
305
305
|
const forgotPasswordResp = await this.graphqlQuery({
|
|
306
|
-
query: "mutation
|
|
306
|
+
query: "mutation forgot_password($data: ForgotPasswordRequest!) { forgot_password(params: $data) { message should_show_mobile_otp_screen } }",
|
|
307
307
|
variables: {
|
|
308
308
|
data
|
|
309
|
-
}
|
|
309
|
+
},
|
|
310
|
+
operationName: "forgot_password"
|
|
310
311
|
});
|
|
311
312
|
return ((_a = forgotPasswordResp == null ? void 0 : forgotPasswordResp.errors) == null ? void 0 : _a.length) ? this.errorResponse(forgotPasswordResp.errors) : this.okResponse((_b = forgotPasswordResp == null ? void 0 : forgotPasswordResp.data) == null ? void 0 : _b.forgot_password);
|
|
312
313
|
} catch (error) {
|
|
@@ -319,7 +320,8 @@ var _Authorizer = class _Authorizer {
|
|
|
319
320
|
var _a;
|
|
320
321
|
try {
|
|
321
322
|
const res = await this.graphqlQuery({
|
|
322
|
-
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 } }"
|
|
323
|
+
query: "query meta { 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 } }",
|
|
324
|
+
operationName: "meta"
|
|
323
325
|
});
|
|
324
326
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse(res.data.meta);
|
|
325
327
|
} catch (error) {
|
|
@@ -332,8 +334,9 @@ var _Authorizer = class _Authorizer {
|
|
|
332
334
|
var _a;
|
|
333
335
|
try {
|
|
334
336
|
const profileRes = await this.graphqlQuery({
|
|
335
|
-
query: `query { profile { ${userFragment} } }`,
|
|
336
|
-
headers
|
|
337
|
+
query: `query profile { profile { ${userFragment} } }`,
|
|
338
|
+
headers,
|
|
339
|
+
operationName: "profile"
|
|
337
340
|
});
|
|
338
341
|
return ((_a = profileRes == null ? void 0 : profileRes.errors) == null ? void 0 : _a.length) ? this.errorResponse(profileRes.errors) : this.okResponse(profileRes.data.profile);
|
|
339
342
|
} catch (error) {
|
|
@@ -347,11 +350,12 @@ var _Authorizer = class _Authorizer {
|
|
|
347
350
|
var _a, _b;
|
|
348
351
|
try {
|
|
349
352
|
const res = await this.graphqlQuery({
|
|
350
|
-
query: `query
|
|
353
|
+
query: `query session($params: SessionQueryRequest){session(params: $params) { ${authTokenFragment} } }`,
|
|
351
354
|
headers,
|
|
352
355
|
variables: {
|
|
353
356
|
params
|
|
354
|
-
}
|
|
357
|
+
},
|
|
358
|
+
operationName: "session"
|
|
355
359
|
});
|
|
356
360
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.session);
|
|
357
361
|
} catch (err) {
|
|
@@ -414,7 +418,8 @@ var _Authorizer = class _Authorizer {
|
|
|
414
418
|
`,
|
|
415
419
|
variables: {
|
|
416
420
|
data
|
|
417
|
-
}
|
|
421
|
+
},
|
|
422
|
+
operationName: "login"
|
|
418
423
|
});
|
|
419
424
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.login);
|
|
420
425
|
} catch (err) {
|
|
@@ -425,8 +430,9 @@ var _Authorizer = class _Authorizer {
|
|
|
425
430
|
var _a, _b;
|
|
426
431
|
try {
|
|
427
432
|
const res = await this.graphqlQuery({
|
|
428
|
-
query: "
|
|
429
|
-
headers
|
|
433
|
+
query: "mutation logout { logout { message } }",
|
|
434
|
+
headers,
|
|
435
|
+
operationName: "logout"
|
|
430
436
|
});
|
|
431
437
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.logout);
|
|
432
438
|
} catch (err) {
|
|
@@ -442,11 +448,12 @@ var _Authorizer = class _Authorizer {
|
|
|
442
448
|
if (!data.redirect_uri) data.redirect_uri = this.config.redirectURL;
|
|
443
449
|
const res = await this.graphqlQuery({
|
|
444
450
|
query: `
|
|
445
|
-
mutation
|
|
451
|
+
mutation magic_link_login($data: MagicLinkLoginRequest!) { magic_link_login(params: $data) { message }}
|
|
446
452
|
`,
|
|
447
453
|
variables: {
|
|
448
454
|
data
|
|
449
|
-
}
|
|
455
|
+
},
|
|
456
|
+
operationName: "magic_link_login"
|
|
450
457
|
});
|
|
451
458
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.magic_link_login);
|
|
452
459
|
} catch (err) {
|
|
@@ -473,11 +480,12 @@ var _Authorizer = class _Authorizer {
|
|
|
473
480
|
try {
|
|
474
481
|
const res = await this.graphqlQuery({
|
|
475
482
|
query: `
|
|
476
|
-
mutation
|
|
483
|
+
mutation resend_otp($data: ResendOTPRequest!) { resend_otp(params: $data) { message }}
|
|
477
484
|
`,
|
|
478
485
|
variables: {
|
|
479
486
|
data
|
|
480
|
-
}
|
|
487
|
+
},
|
|
488
|
+
operationName: "resend_otp"
|
|
481
489
|
});
|
|
482
490
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.resend_otp);
|
|
483
491
|
} catch (err) {
|
|
@@ -490,10 +498,11 @@ var _Authorizer = class _Authorizer {
|
|
|
490
498
|
var _a, _b;
|
|
491
499
|
try {
|
|
492
500
|
const resetPasswordRes = await this.graphqlQuery({
|
|
493
|
-
query: "mutation
|
|
501
|
+
query: "mutation reset_password($data: ResetPasswordRequest!) { reset_password(params: $data) { message } }",
|
|
494
502
|
variables: {
|
|
495
503
|
data
|
|
496
|
-
}
|
|
504
|
+
},
|
|
505
|
+
operationName: "reset_password"
|
|
497
506
|
});
|
|
498
507
|
return ((_a = resetPasswordRes == null ? void 0 : resetPasswordRes.errors) == null ? void 0 : _a.length) ? this.errorResponse(resetPasswordRes.errors) : this.okResponse((_b = resetPasswordRes.data) == null ? void 0 : _b.reset_password);
|
|
499
508
|
} catch (error) {
|
|
@@ -550,7 +559,8 @@ var _Authorizer = class _Authorizer {
|
|
|
550
559
|
`,
|
|
551
560
|
variables: {
|
|
552
561
|
data
|
|
553
|
-
}
|
|
562
|
+
},
|
|
563
|
+
operationName: "signup"
|
|
554
564
|
});
|
|
555
565
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.signup);
|
|
556
566
|
} catch (err) {
|
|
@@ -563,11 +573,12 @@ var _Authorizer = class _Authorizer {
|
|
|
563
573
|
var _a, _b;
|
|
564
574
|
try {
|
|
565
575
|
const updateProfileRes = await this.graphqlQuery({
|
|
566
|
-
query: "mutation
|
|
576
|
+
query: "mutation update_profile($data: UpdateProfileRequest!) { update_profile(params: $data) { message } }",
|
|
567
577
|
headers,
|
|
568
578
|
variables: {
|
|
569
579
|
data
|
|
570
|
-
}
|
|
580
|
+
},
|
|
581
|
+
operationName: "update_profile"
|
|
571
582
|
});
|
|
572
583
|
return ((_a = updateProfileRes == null ? void 0 : updateProfileRes.errors) == null ? void 0 : _a.length) ? this.errorResponse(updateProfileRes.errors) : this.okResponse((_b = updateProfileRes.data) == null ? void 0 : _b.update_profile);
|
|
573
584
|
} catch (error) {
|
|
@@ -580,8 +591,9 @@ var _Authorizer = class _Authorizer {
|
|
|
580
591
|
var _a, _b;
|
|
581
592
|
try {
|
|
582
593
|
const res = await this.graphqlQuery({
|
|
583
|
-
query: "mutation
|
|
584
|
-
headers
|
|
594
|
+
query: "mutation deactivate_account { deactivate_account { message } }",
|
|
595
|
+
headers,
|
|
596
|
+
operationName: "deactivate_account"
|
|
585
597
|
});
|
|
586
598
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.deactivate_account);
|
|
587
599
|
} catch (error) {
|
|
@@ -594,10 +606,11 @@ var _Authorizer = class _Authorizer {
|
|
|
594
606
|
var _a, _b;
|
|
595
607
|
try {
|
|
596
608
|
const res = await this.graphqlQuery({
|
|
597
|
-
query: "query
|
|
609
|
+
query: "query validate_jwt_token($params: ValidateJWTTokenRequest!){validate_jwt_token(params: $params) { is_valid claims } }",
|
|
598
610
|
variables: {
|
|
599
611
|
params
|
|
600
|
-
}
|
|
612
|
+
},
|
|
613
|
+
operationName: "validate_jwt_token"
|
|
601
614
|
});
|
|
602
615
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.validate_jwt_token);
|
|
603
616
|
} catch (error) {
|
|
@@ -610,10 +623,11 @@ var _Authorizer = class _Authorizer {
|
|
|
610
623
|
var _a, _b;
|
|
611
624
|
try {
|
|
612
625
|
const res = await this.graphqlQuery({
|
|
613
|
-
query: `query
|
|
626
|
+
query: `query validate_session($params: ValidateSessionRequest){validate_session(params: $params) { is_valid user { ${userFragment} } } }`,
|
|
614
627
|
variables: {
|
|
615
628
|
params
|
|
616
|
-
}
|
|
629
|
+
},
|
|
630
|
+
operationName: "validate_session"
|
|
617
631
|
});
|
|
618
632
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.validate_session);
|
|
619
633
|
} catch (error) {
|
|
@@ -627,11 +641,12 @@ var _Authorizer = class _Authorizer {
|
|
|
627
641
|
try {
|
|
628
642
|
const res = await this.graphqlQuery({
|
|
629
643
|
query: `
|
|
630
|
-
mutation
|
|
644
|
+
mutation verify_email($data: VerifyEmailRequest!) { verify_email(params: $data) { ${authTokenFragment}}}
|
|
631
645
|
`,
|
|
632
646
|
variables: {
|
|
633
647
|
data
|
|
634
|
-
}
|
|
648
|
+
},
|
|
649
|
+
operationName: "verify_email"
|
|
635
650
|
});
|
|
636
651
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.verify_email);
|
|
637
652
|
} catch (err) {
|
|
@@ -645,11 +660,12 @@ var _Authorizer = class _Authorizer {
|
|
|
645
660
|
try {
|
|
646
661
|
const res = await this.graphqlQuery({
|
|
647
662
|
query: `
|
|
648
|
-
mutation
|
|
663
|
+
mutation resend_verify_email($data: ResendVerifyEmailRequest!) { resend_verify_email(params: $data) { message }}
|
|
649
664
|
`,
|
|
650
665
|
variables: {
|
|
651
666
|
data
|
|
652
|
-
}
|
|
667
|
+
},
|
|
668
|
+
operationName: "resend_verify_email"
|
|
653
669
|
});
|
|
654
670
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.resend_verify_email);
|
|
655
671
|
} catch (err) {
|
|
@@ -663,11 +679,12 @@ var _Authorizer = class _Authorizer {
|
|
|
663
679
|
try {
|
|
664
680
|
const res = await this.graphqlQuery({
|
|
665
681
|
query: `
|
|
666
|
-
mutation
|
|
682
|
+
mutation verify_otp($data: VerifyOTPRequest!) { verify_otp(params: $data) { ${authTokenFragment}}}
|
|
667
683
|
`,
|
|
668
684
|
variables: {
|
|
669
685
|
data
|
|
670
|
-
}
|
|
686
|
+
},
|
|
687
|
+
operationName: "verify_otp"
|
|
671
688
|
});
|
|
672
689
|
return ((_a = res == null ? void 0 : res.errors) == null ? void 0 : _a.length) ? this.errorResponse(res.errors) : this.okResponse((_b = res.data) == null ? void 0 : _b.verify_otp);
|
|
673
690
|
} catch (err) {
|
|
@@ -681,12 +698,16 @@ var _Authorizer = class _Authorizer {
|
|
|
681
698
|
graphqlQuery = /* @__PURE__ */ __name(async (data) => {
|
|
682
699
|
var _a;
|
|
683
700
|
const fetcher = getFetcher();
|
|
701
|
+
const body = {
|
|
702
|
+
query: data.query,
|
|
703
|
+
variables: data.variables || {}
|
|
704
|
+
};
|
|
705
|
+
if (data.operationName) {
|
|
706
|
+
body.operationName = data.operationName;
|
|
707
|
+
}
|
|
684
708
|
const res = await fetcher(`${this.config.authorizerURL}/graphql`, {
|
|
685
709
|
method: "POST",
|
|
686
|
-
body: JSON.stringify(
|
|
687
|
-
query: data.query,
|
|
688
|
-
variables: data.variables || {}
|
|
689
|
-
}),
|
|
710
|
+
body: JSON.stringify(body),
|
|
690
711
|
headers: {
|
|
691
712
|
...this.config.extraHeaders,
|
|
692
713
|
...data.headers || {}
|