@authorizerdev/authorizer-js 1.2.2-beta.2 → 1.2.3
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 +2 -2
- package/lib/index.d.ts +1 -1
- package/package.json +3 -4
package/lib/authorizer.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var __AUTHORIZER_JS__=(()=>{var pe=Object.create;var A=Object.defineProperty,ye=Object.defineProperties,we=Object.getOwnPropertyDescriptor,me=Object.getOwnPropertyDescriptors,_e=Object.getOwnPropertyNames,V=Object.getOwnPropertySymbols,ge=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var j=(o,e,t)=>e in o?A(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,O=(o,e)=>{for(var t in e||(e={}))J.call(e,t)&&j(o,t,e[t]);if(V)for(var t of V(e))be.call(e,t)&&j(o,t,e[t]);return o},G=(o,e)=>ye(o,me(e)),n=(o,e)=>A(o,"name",{value:e,configurable:!0});var Ee=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),ve=(o,e)=>{for(var t in e)A(o,t,{get:e[t],enumerable:!0})},W=(o,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of _e(e))!J.call(o,c)&&c!==t&&A(o,c,{get:()=>e[c],enumerable:!(s=we(e,c))||s.enumerable});return o};var Te=(o,e,t)=>(t=o!=null?pe(ge(o)):{},W(e||!o||!o.__esModule?A(t,"default",{value:o,enumerable:!0}):t,o)),Re=o=>W(A({},"__esModule",{value:!0}),o);var l=(o,e,t)=>(j(o,typeof e!="symbol"?e+"":e,t),t);var f=(o,e,t)=>new Promise((s,c)=>{var u=_=>{try{m(t.next(_))}catch(w){c(w)}},g=_=>{try{m(t.throw(_))}catch(w){c(w)}},m=_=>_.done?s(_.value):Promise.resolve(_.value).then(u,g);m((t=t.apply(o,e)).next())});var K=Ee((E,X)=>{var Z=typeof self!="undefined"?self:E,P=function(){function o(){this.fetch=!1,this.DOMException=Z.DOMException}return n(o,"F"),o.prototype=Z,new o}();(function(o){var e=function(t){var s={searchParams:"URLSearchParams"in o,iterable:"Symbol"in o&&"iterator"in Symbol,blob:"FileReader"in o&&"Blob"in o&&function(){try{return new Blob,!0}catch(r){return!1}}(),formData:"FormData"in o,arrayBuffer:"ArrayBuffer"in o};function c(r){return r&&DataView.prototype.isPrototypeOf(r)}if(n(c,"isDataView"),s.arrayBuffer)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],g=ArrayBuffer.isView||function(r){return r&&u.indexOf(Object.prototype.toString.call(r))>-1};function m(r){if(typeof r!="string"&&(r=String(r)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(r))throw new TypeError("Invalid character in header field name");return r.toLowerCase()}n(m,"normalizeName");function _(r){return typeof r!="string"&&(r=String(r)),r}n(_,"normalizeValue");function w(r){var i={next:function(){var a=r.shift();return{done:a===void 0,value:a}}};return s.iterable&&(i[Symbol.iterator]=function(){return i}),i}n(w,"iteratorFor");function d(r){this.map={},r instanceof d?r.forEach(function(i,a){this.append(a,i)},this):Array.isArray(r)?r.forEach(function(i){this.append(i[0],i[1])},this):r&&Object.getOwnPropertyNames(r).forEach(function(i){this.append(i,r[i])},this)}n(d,"Headers"),d.prototype.append=function(r,i){r=m(r),i=_(i);var a=this.map[r];this.map[r]=a?a+", "+i:i},d.prototype.delete=function(r){delete this.map[m(r)]},d.prototype.get=function(r){return r=m(r),this.has(r)?this.map[r]:null},d.prototype.has=function(r){return this.map.hasOwnProperty(m(r))},d.prototype.set=function(r,i){this.map[m(r)]=_(i)},d.prototype.forEach=function(r,i){for(var a in this.map)this.map.hasOwnProperty(a)&&r.call(i,this.map[a],a,this)},d.prototype.keys=function(){var r=[];return this.forEach(function(i,a){r.push(a)}),w(r)},d.prototype.values=function(){var r=[];return this.forEach(function(i){r.push(i)}),w(r)},d.prototype.entries=function(){var r=[];return this.forEach(function(i,a){r.push([a,i])}),w(r)},s.iterable&&(d.prototype[Symbol.iterator]=d.prototype.entries);function B(r){if(r.bodyUsed)return Promise.reject(new TypeError("Already read"));r.bodyUsed=!0}n(B,"consumed");function H(r){return new Promise(function(i,a){r.onload=function(){i(r.result)},r.onerror=function(){a(r.error)}})}n(H,"fileReaderReady");function se(r){var i=new FileReader,a=H(i);return i.readAsArrayBuffer(r),a}n(se,"readBlobAsArrayBuffer");function ae(r){var i=new FileReader,a=H(i);return i.readAsText(r),a}n(ae,"readBlobAsText");function ce(r){for(var i=new Uint8Array(r),a=new Array(i.length),y=0;y<i.length;y++)a[y]=String.fromCharCode(i[y]);return a.join("")}n(ce,"readArrayBufferAsText");function N(r){if(r.slice)return r.slice(0);var i=new Uint8Array(r.byteLength);return i.set(new Uint8Array(r)),i.buffer}n(N,"bufferClone");function Q(){return this.bodyUsed=!1,this._initBody=function(r){this._bodyInit=r,r?typeof r=="string"?this._bodyText=r:s.blob&&Blob.prototype.isPrototypeOf(r)?this._bodyBlob=r:s.formData&&FormData.prototype.isPrototypeOf(r)?this._bodyFormData=r:s.searchParams&&URLSearchParams.prototype.isPrototypeOf(r)?this._bodyText=r.toString():s.arrayBuffer&&s.blob&&c(r)?(this._bodyArrayBuffer=N(r.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(r)||g(r))?this._bodyArrayBuffer=N(r):this._bodyText=r=Object.prototype.toString.call(r):this._bodyText="",this.headers.get("content-type")||(typeof r=="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(r)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s.blob&&(this.blob=function(){var r=B(this);if(r)return r;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?B(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(se)}),this.text=function(){var r=B(this);if(r)return r;if(this._bodyBlob)return ae(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(ce(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(fe)}),this.json=function(){return this.text().then(JSON.parse)},this}n(Q,"Body");var ue=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function he(r){var i=r.toUpperCase();return ue.indexOf(i)>-1?i:r}n(he,"normalizeMethod");function T(r,i){i=i||{};var a=i.body;if(r instanceof T){if(r.bodyUsed)throw new TypeError("Already read");this.url=r.url,this.credentials=r.credentials,i.headers||(this.headers=new d(r.headers)),this.method=r.method,this.mode=r.mode,this.signal=r.signal,!a&&r._bodyInit!=null&&(a=r._bodyInit,r.bodyUsed=!0)}else this.url=String(r);if(this.credentials=i.credentials||this.credentials||"same-origin",(i.headers||!this.headers)&&(this.headers=new d(i.headers)),this.method=he(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")&&a)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(a)}n(T,"Request"),T.prototype.clone=function(){return new T(this,{body:this._bodyInit})};function fe(r){var i=new FormData;return r.trim().split("&").forEach(function(a){if(a){var y=a.split("="),p=y.shift().replace(/\+/g," "),h=y.join("=").replace(/\+/g," ");i.append(decodeURIComponent(p),decodeURIComponent(h))}}),i}n(fe,"decode");function de(r){var i=new d,a=r.replace(/\r?\n[\t ]+/g," ");return a.split(/\r?\n/).forEach(function(y){var p=y.split(":"),h=p.shift().trim();if(h){var q=p.join(":").trim();i.append(h,q)}}),i}n(de,"parseHeaders"),Q.call(T.prototype);function b(r,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 d(i.headers),this.url=i.url||"",this._initBody(r)}n(b,"Response"),Q.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},b.error=function(){var r=new b(null,{status:0,statusText:""});return r.type="error",r};var le=[301,302,303,307,308];b.redirect=function(r,i){if(le.indexOf(i)===-1)throw new RangeError("Invalid status code");return new b(null,{status:i,headers:{location:r}})},t.DOMException=o.DOMException;try{new t.DOMException}catch(r){t.DOMException=function(i,a){this.message=i,this.name=a;var y=Error(i);this.stack=y.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function D(r,i){return new Promise(function(a,y){var p=new T(r,i);if(p.signal&&p.signal.aborted)return y(new t.DOMException("Aborted","AbortError"));var h=new XMLHttpRequest;function q(){h.abort()}n(q,"abortXhr"),h.onload=function(){var x={status:h.status,statusText:h.statusText,headers:de(h.getAllResponseHeaders()||"")};x.url="responseURL"in h?h.responseURL:x.headers.get("X-Request-URL");var C="response"in h?h.response:h.responseText;a(new b(C,x))},h.onerror=function(){y(new TypeError("Network request failed"))},h.ontimeout=function(){y(new TypeError("Network request failed"))},h.onabort=function(){y(new t.DOMException("Aborted","AbortError"))},h.open(p.method,p.url,!0),p.credentials==="include"?h.withCredentials=!0:p.credentials==="omit"&&(h.withCredentials=!1),"responseType"in h&&s.blob&&(h.responseType="blob"),p.headers.forEach(function(x,C){h.setRequestHeader(C,x)}),p.signal&&(p.signal.addEventListener("abort",q),h.onreadystatechange=function(){h.readyState===4&&p.signal.removeEventListener("abort",q)}),h.send(typeof p._bodyInit=="undefined"?null:p._bodyInit)})}return n(D,"fetch"),D.polyfill=!0,o.fetch||(o.fetch=D,o.Headers=d,o.Request=T,o.Response=b),t.Headers=d,t.Request=T,t.Response=b,t.fetch=D,Object.defineProperty(t,"__esModule",{value:!0}),t}({})})(P);P.fetch.ponyfill=!0;delete P.fetch.polyfill;var I=P;E=I.fetch;E.default=I.fetch;E.fetch=I.fetch;E.Headers=I.Headers;E.Request=I.Request;E.Response=I.Response;X.exports=E});var Le={};ve(Le,{Authorizer:()=>$,OAuthProviders:()=>S,ResponseTypes:()=>L});var ie=Te(K());var S;(function(o){o.Apple="apple",o.Github="github",o.Google="google",o.Facebook="facebook",o.LinkedIn="linkedin"})(S||(S={}));var L;(function(o){o.Code="code",o.Token="token"})(L||(L={}));var R=n(()=>typeof window!="undefined","hasWindow"),M=n(o=>{let e=o.trim();return e[e.length-1]==="/"&&(e=e.slice(0,-1)),e},"trimURL"),Y=n(()=>R()?window.crypto||window.msCrypto:null,"getCrypto"),Oe=n(()=>{let o=Y();return o&&o.subtle||o.webkitSubtle},"getCryptoSubtle"),U=n(()=>{let o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.",e="",t=Y();return t&&Array.from(t.getRandomValues(new Uint8Array(43))).forEach(c=>e+=o[c%o.length]),e},"createRandomString"),v=n(o=>R()?btoa(o):Buffer.from(o).toString("base64"),"encode");var ee=n(o=>Object.keys(o).filter(e=>typeof o[e]!="undefined").map(e=>`${encodeURIComponent(e)}=${encodeURIComponent(o[e])}`).join("&"),"createQueryParams"),re=n(o=>f(void 0,null,function*(){let e=Oe().digest({name:"SHA-256"},new TextEncoder().encode(o));return window.msCrypto?new Promise((t,s)=>{e.oncomplete=c=>{t(c.target.result)},e.onerror=c=>{s(c.error)},e.onabort=()=>{s(new Error("The digest operation was aborted"))}}):yield e}),"sha256"),Ie=n(o=>{let e={"+":"-","/":"_","=":""};return o.replace(/[+/=]/g,t=>e[t])},"urlEncodeB64");var te=n(o=>{let e=new Uint8Array(o);return Ie(window.btoa(String.fromCharCode(...Array.from(e))))},"bufferToBase64UrlEncoded"),oe=n((o,e,t=60)=>new Promise((s,c)=>{let u=window.document.createElement("iframe");u.setAttribute("id","authorizer-iframe"),u.setAttribute("width","0"),u.setAttribute("height","0"),u.style.display="none";let g,m=n(()=>{window.document.body.contains(u)&&(window.document.body.removeChild(u),window.removeEventListener("message",g,!1))},"removeIframe"),_=setTimeout(()=>{m()},t*1e3);g=n(function(w){if(w.origin!==e||!w.data||!w.data.response)return;let d=w.source;d&&d.close(),w.data.response.error?c(w.data.response):s(w.data.response),clearTimeout(_),window.removeEventListener("message",g,!1),setTimeout(m,2*1e3)},"iframeEventHandler"),window.addEventListener("message",g,!1),window.document.body.appendChild(u),u.setAttribute("src",o)}),"executeIframe");var ne="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 is_multi_factor_auth_enabled ",k=`message access_token expires_in refresh_token id_token should_show_otp_screen user { ${ne} }`,z=n(()=>R()?window.fetch:ie.default,"getFetcher"),$=class{constructor(e){l(this,"authorize",n(e=>f(this,null,function*(){if(!R())throw new Error("this feature is only supported in browser");let t=["openid","profile","email"];e.use_refresh_token&&t.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:t.join(" "),client_id:this.config.clientID};if(e.response_type===L.Code){this.codeVerifier=U();let u=yield re(this.codeVerifier),g=te(u);s.code_challenge=g}let c=`${this.config.authorizerURL}/authorize?${ee(s)}`;if(s.response_mode!=="web_message"){window.location.replace(c);return}try{let u=yield oe(c,this.config.authorizerURL,60);return e.response_type===L.Code?yield this.getToken({code:u.code}):u}catch(u){throw u.error&&window.location.replace(`${this.config.authorizerURL}/app?state=${v(JSON.stringify(this.config))}&redirect_uri=${this.config.redirectURL}`),u}}),"authorize"));l(this,"browserLogin",n(()=>f(this,null,function*(){try{return yield this.getSession()}catch(e){if(!R())throw new Error("browserLogin is only supported for browsers");window.location.replace(`${this.config.authorizerURL}/app?state=${v(JSON.stringify(this.config))}&redirect_uri=${this.config.redirectURL}`)}}),"browserLogin"));l(this,"forgotPassword",n(e=>f(this,null,function*(){e.state||(e.state=v(U())),e.redirect_uri||(e.redirect_uri=this.config.redirectURL);try{return(yield this.graphqlQuery({query:"mutation forgotPassword($data: ForgotPasswordInput!) { forgot_password(params: $data) { message } }",variables:{data:e}})).forgot_password}catch(t){throw new Error(t)}}),"forgotPassword"));l(this,"getMetaData",n(()=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:"query { meta { version 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_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled } }"})).meta}catch(e){throw new Error(e)}}),"getMetaData"));l(this,"getProfile",n(e=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:`query { profile { ${ne} } }`,headers:e})).profile}catch(t){throw new Error(t)}}),"getProfile"));l(this,"getSession",n((e,t)=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:`query getSession($params: SessionQueryInput){session(params: $params) { ${k} } }`,headers:e,variables:{params:t}})).session}catch(s){throw new Error(s)}}),"getSession"));l(this,"getToken",n(e=>f(this,null,function*(){if(e.grant_type||(e.grant_type="authorization_code"),e.grant_type==="refresh_token"&&!e.refresh_token)throw new Error("Invalid refresh_token");if(e.grant_type==="authorization_code"&&!this.codeVerifier)throw new Error("Invalid code verifier");let t={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 z()(`${this.config.authorizerURL}/oauth/token`,{method:"POST",body:JSON.stringify(t),headers:O({},this.config.extraHeaders),credentials:"include"}),u=yield c.json();if(c.status>=400)throw new Error(u);return u}catch(s){throw new Error(s)}}),"getToken"));l(this,"graphqlQuery",n(e=>f(this,null,function*(){let c=yield(yield z()(`${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"})).json();if(c.errors&&c.errors.length)throw console.error(c.errors),new Error(c.errors[0].message);return c.data}),"graphqlQuery"));l(this,"login",n(e=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:`
|
|
1
|
+
var authorizerdev=(()=>{var pe=Object.create;var A=Object.defineProperty,ye=Object.defineProperties,we=Object.getOwnPropertyDescriptor,me=Object.getOwnPropertyDescriptors,_e=Object.getOwnPropertyNames,V=Object.getOwnPropertySymbols,ge=Object.getPrototypeOf,J=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable;var j=(o,e,t)=>e in o?A(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,O=(o,e)=>{for(var t in e||(e={}))J.call(e,t)&&j(o,t,e[t]);if(V)for(var t of V(e))be.call(e,t)&&j(o,t,e[t]);return o},G=(o,e)=>ye(o,me(e)),n=(o,e)=>A(o,"name",{value:e,configurable:!0});var Ee=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),ve=(o,e)=>{for(var t in e)A(o,t,{get:e[t],enumerable:!0})},W=(o,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of _e(e))!J.call(o,c)&&c!==t&&A(o,c,{get:()=>e[c],enumerable:!(s=we(e,c))||s.enumerable});return o};var Te=(o,e,t)=>(t=o!=null?pe(ge(o)):{},W(e||!o||!o.__esModule?A(t,"default",{value:o,enumerable:!0}):t,o)),Re=o=>W(A({},"__esModule",{value:!0}),o);var l=(o,e,t)=>(j(o,typeof e!="symbol"?e+"":e,t),t);var f=(o,e,t)=>new Promise((s,c)=>{var u=_=>{try{m(t.next(_))}catch(w){c(w)}},g=_=>{try{m(t.throw(_))}catch(w){c(w)}},m=_=>_.done?s(_.value):Promise.resolve(_.value).then(u,g);m((t=t.apply(o,e)).next())});var K=Ee((E,X)=>{var Z=typeof self!="undefined"?self:E,P=function(){function o(){this.fetch=!1,this.DOMException=Z.DOMException}return n(o,"F"),o.prototype=Z,new o}();(function(o){var e=function(t){var s={searchParams:"URLSearchParams"in o,iterable:"Symbol"in o&&"iterator"in Symbol,blob:"FileReader"in o&&"Blob"in o&&function(){try{return new Blob,!0}catch(r){return!1}}(),formData:"FormData"in o,arrayBuffer:"ArrayBuffer"in o};function c(r){return r&&DataView.prototype.isPrototypeOf(r)}if(n(c,"isDataView"),s.arrayBuffer)var u=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],g=ArrayBuffer.isView||function(r){return r&&u.indexOf(Object.prototype.toString.call(r))>-1};function m(r){if(typeof r!="string"&&(r=String(r)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(r))throw new TypeError("Invalid character in header field name");return r.toLowerCase()}n(m,"normalizeName");function _(r){return typeof r!="string"&&(r=String(r)),r}n(_,"normalizeValue");function w(r){var i={next:function(){var a=r.shift();return{done:a===void 0,value:a}}};return s.iterable&&(i[Symbol.iterator]=function(){return i}),i}n(w,"iteratorFor");function d(r){this.map={},r instanceof d?r.forEach(function(i,a){this.append(a,i)},this):Array.isArray(r)?r.forEach(function(i){this.append(i[0],i[1])},this):r&&Object.getOwnPropertyNames(r).forEach(function(i){this.append(i,r[i])},this)}n(d,"Headers"),d.prototype.append=function(r,i){r=m(r),i=_(i);var a=this.map[r];this.map[r]=a?a+", "+i:i},d.prototype.delete=function(r){delete this.map[m(r)]},d.prototype.get=function(r){return r=m(r),this.has(r)?this.map[r]:null},d.prototype.has=function(r){return this.map.hasOwnProperty(m(r))},d.prototype.set=function(r,i){this.map[m(r)]=_(i)},d.prototype.forEach=function(r,i){for(var a in this.map)this.map.hasOwnProperty(a)&&r.call(i,this.map[a],a,this)},d.prototype.keys=function(){var r=[];return this.forEach(function(i,a){r.push(a)}),w(r)},d.prototype.values=function(){var r=[];return this.forEach(function(i){r.push(i)}),w(r)},d.prototype.entries=function(){var r=[];return this.forEach(function(i,a){r.push([a,i])}),w(r)},s.iterable&&(d.prototype[Symbol.iterator]=d.prototype.entries);function B(r){if(r.bodyUsed)return Promise.reject(new TypeError("Already read"));r.bodyUsed=!0}n(B,"consumed");function H(r){return new Promise(function(i,a){r.onload=function(){i(r.result)},r.onerror=function(){a(r.error)}})}n(H,"fileReaderReady");function se(r){var i=new FileReader,a=H(i);return i.readAsArrayBuffer(r),a}n(se,"readBlobAsArrayBuffer");function ae(r){var i=new FileReader,a=H(i);return i.readAsText(r),a}n(ae,"readBlobAsText");function ce(r){for(var i=new Uint8Array(r),a=new Array(i.length),y=0;y<i.length;y++)a[y]=String.fromCharCode(i[y]);return a.join("")}n(ce,"readArrayBufferAsText");function N(r){if(r.slice)return r.slice(0);var i=new Uint8Array(r.byteLength);return i.set(new Uint8Array(r)),i.buffer}n(N,"bufferClone");function Q(){return this.bodyUsed=!1,this._initBody=function(r){this._bodyInit=r,r?typeof r=="string"?this._bodyText=r:s.blob&&Blob.prototype.isPrototypeOf(r)?this._bodyBlob=r:s.formData&&FormData.prototype.isPrototypeOf(r)?this._bodyFormData=r:s.searchParams&&URLSearchParams.prototype.isPrototypeOf(r)?this._bodyText=r.toString():s.arrayBuffer&&s.blob&&c(r)?(this._bodyArrayBuffer=N(r.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):s.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(r)||g(r))?this._bodyArrayBuffer=N(r):this._bodyText=r=Object.prototype.toString.call(r):this._bodyText="",this.headers.get("content-type")||(typeof r=="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(r)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},s.blob&&(this.blob=function(){var r=B(this);if(r)return r;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?B(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(se)}),this.text=function(){var r=B(this);if(r)return r;if(this._bodyBlob)return ae(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(ce(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(fe)}),this.json=function(){return this.text().then(JSON.parse)},this}n(Q,"Body");var ue=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function he(r){var i=r.toUpperCase();return ue.indexOf(i)>-1?i:r}n(he,"normalizeMethod");function T(r,i){i=i||{};var a=i.body;if(r instanceof T){if(r.bodyUsed)throw new TypeError("Already read");this.url=r.url,this.credentials=r.credentials,i.headers||(this.headers=new d(r.headers)),this.method=r.method,this.mode=r.mode,this.signal=r.signal,!a&&r._bodyInit!=null&&(a=r._bodyInit,r.bodyUsed=!0)}else this.url=String(r);if(this.credentials=i.credentials||this.credentials||"same-origin",(i.headers||!this.headers)&&(this.headers=new d(i.headers)),this.method=he(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")&&a)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(a)}n(T,"Request"),T.prototype.clone=function(){return new T(this,{body:this._bodyInit})};function fe(r){var i=new FormData;return r.trim().split("&").forEach(function(a){if(a){var y=a.split("="),p=y.shift().replace(/\+/g," "),h=y.join("=").replace(/\+/g," ");i.append(decodeURIComponent(p),decodeURIComponent(h))}}),i}n(fe,"decode");function de(r){var i=new d,a=r.replace(/\r?\n[\t ]+/g," ");return a.split(/\r?\n/).forEach(function(y){var p=y.split(":"),h=p.shift().trim();if(h){var q=p.join(":").trim();i.append(h,q)}}),i}n(de,"parseHeaders"),Q.call(T.prototype);function b(r,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 d(i.headers),this.url=i.url||"",this._initBody(r)}n(b,"Response"),Q.call(b.prototype),b.prototype.clone=function(){return new b(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new d(this.headers),url:this.url})},b.error=function(){var r=new b(null,{status:0,statusText:""});return r.type="error",r};var le=[301,302,303,307,308];b.redirect=function(r,i){if(le.indexOf(i)===-1)throw new RangeError("Invalid status code");return new b(null,{status:i,headers:{location:r}})},t.DOMException=o.DOMException;try{new t.DOMException}catch(r){t.DOMException=function(i,a){this.message=i,this.name=a;var y=Error(i);this.stack=y.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function D(r,i){return new Promise(function(a,y){var p=new T(r,i);if(p.signal&&p.signal.aborted)return y(new t.DOMException("Aborted","AbortError"));var h=new XMLHttpRequest;function q(){h.abort()}n(q,"abortXhr"),h.onload=function(){var x={status:h.status,statusText:h.statusText,headers:de(h.getAllResponseHeaders()||"")};x.url="responseURL"in h?h.responseURL:x.headers.get("X-Request-URL");var C="response"in h?h.response:h.responseText;a(new b(C,x))},h.onerror=function(){y(new TypeError("Network request failed"))},h.ontimeout=function(){y(new TypeError("Network request failed"))},h.onabort=function(){y(new t.DOMException("Aborted","AbortError"))},h.open(p.method,p.url,!0),p.credentials==="include"?h.withCredentials=!0:p.credentials==="omit"&&(h.withCredentials=!1),"responseType"in h&&s.blob&&(h.responseType="blob"),p.headers.forEach(function(x,C){h.setRequestHeader(C,x)}),p.signal&&(p.signal.addEventListener("abort",q),h.onreadystatechange=function(){h.readyState===4&&p.signal.removeEventListener("abort",q)}),h.send(typeof p._bodyInit=="undefined"?null:p._bodyInit)})}return n(D,"fetch"),D.polyfill=!0,o.fetch||(o.fetch=D,o.Headers=d,o.Request=T,o.Response=b),t.Headers=d,t.Request=T,t.Response=b,t.fetch=D,Object.defineProperty(t,"__esModule",{value:!0}),t}({})})(P);P.fetch.ponyfill=!0;delete P.fetch.polyfill;var I=P;E=I.fetch;E.default=I.fetch;E.fetch=I.fetch;E.Headers=I.Headers;E.Request=I.Request;E.Response=I.Response;X.exports=E});var Le={};ve(Le,{Authorizer:()=>$,OAuthProviders:()=>S,ResponseTypes:()=>L});var ie=Te(K());var S;(function(o){o.Apple="apple",o.Github="github",o.Google="google",o.Facebook="facebook",o.LinkedIn="linkedin"})(S||(S={}));var L;(function(o){o.Code="code",o.Token="token"})(L||(L={}));var R=n(()=>typeof window!="undefined","hasWindow"),M=n(o=>{let e=o.trim();return e[e.length-1]==="/"&&(e=e.slice(0,-1)),e},"trimURL"),Y=n(()=>R()?window.crypto||window.msCrypto:null,"getCrypto"),Oe=n(()=>{let o=Y();return o&&o.subtle||o.webkitSubtle},"getCryptoSubtle"),U=n(()=>{let o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.",e="",t=Y();return t&&Array.from(t.getRandomValues(new Uint8Array(43))).forEach(c=>e+=o[c%o.length]),e},"createRandomString"),v=n(o=>R()?btoa(o):Buffer.from(o).toString("base64"),"encode");var ee=n(o=>Object.keys(o).filter(e=>typeof o[e]!="undefined").map(e=>`${encodeURIComponent(e)}=${encodeURIComponent(o[e])}`).join("&"),"createQueryParams"),re=n(o=>f(void 0,null,function*(){let e=Oe().digest({name:"SHA-256"},new TextEncoder().encode(o));return window.msCrypto?new Promise((t,s)=>{e.oncomplete=c=>{t(c.target.result)},e.onerror=c=>{s(c.error)},e.onabort=()=>{s(new Error("The digest operation was aborted"))}}):yield e}),"sha256"),Ie=n(o=>{let e={"+":"-","/":"_","=":""};return o.replace(/[+/=]/g,t=>e[t])},"urlEncodeB64");var te=n(o=>{let e=new Uint8Array(o);return Ie(window.btoa(String.fromCharCode(...Array.from(e))))},"bufferToBase64UrlEncoded"),oe=n((o,e,t=60)=>new Promise((s,c)=>{let u=window.document.createElement("iframe");u.setAttribute("id","authorizer-iframe"),u.setAttribute("width","0"),u.setAttribute("height","0"),u.style.display="none";let g,m=n(()=>{window.document.body.contains(u)&&(window.document.body.removeChild(u),window.removeEventListener("message",g,!1))},"removeIframe"),_=setTimeout(()=>{m()},t*1e3);g=n(function(w){if(w.origin!==e||!w.data||!w.data.response)return;let d=w.source;d&&d.close(),w.data.response.error?c(w.data.response):s(w.data.response),clearTimeout(_),window.removeEventListener("message",g,!1),setTimeout(m,2*1e3)},"iframeEventHandler"),window.addEventListener("message",g,!1),window.document.body.appendChild(u),u.setAttribute("src",o)}),"executeIframe");var ne="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 is_multi_factor_auth_enabled ",k=`message access_token expires_in refresh_token id_token should_show_otp_screen user { ${ne} }`,z=n(()=>R()?window.fetch:ie.default,"getFetcher"),$=class{constructor(e){l(this,"authorize",n(e=>f(this,null,function*(){if(!R())throw new Error("this feature is only supported in browser");let t=["openid","profile","email"];e.use_refresh_token&&t.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:t.join(" "),client_id:this.config.clientID};if(e.response_type===L.Code){this.codeVerifier=U();let u=yield re(this.codeVerifier),g=te(u);s.code_challenge=g}let c=`${this.config.authorizerURL}/authorize?${ee(s)}`;if(s.response_mode!=="web_message"){window.location.replace(c);return}try{let u=yield oe(c,this.config.authorizerURL,60);return e.response_type===L.Code?yield this.getToken({code:u.code}):u}catch(u){throw u.error&&window.location.replace(`${this.config.authorizerURL}/app?state=${v(JSON.stringify(this.config))}&redirect_uri=${this.config.redirectURL}`),u}}),"authorize"));l(this,"browserLogin",n(()=>f(this,null,function*(){try{return yield this.getSession()}catch(e){if(!R())throw new Error("browserLogin is only supported for browsers");window.location.replace(`${this.config.authorizerURL}/app?state=${v(JSON.stringify(this.config))}&redirect_uri=${this.config.redirectURL}`)}}),"browserLogin"));l(this,"forgotPassword",n(e=>f(this,null,function*(){e.state||(e.state=v(U())),e.redirect_uri||(e.redirect_uri=this.config.redirectURL);try{return(yield this.graphqlQuery({query:"mutation forgotPassword($data: ForgotPasswordInput!) { forgot_password(params: $data) { message } }",variables:{data:e}})).forgot_password}catch(t){throw new Error(t)}}),"forgotPassword"));l(this,"getMetaData",n(()=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:"query { meta { version 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_email_verification_enabled is_basic_authentication_enabled is_magic_link_login_enabled is_sign_up_enabled is_strong_password_enabled } }"})).meta}catch(e){throw new Error(e)}}),"getMetaData"));l(this,"getProfile",n(e=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:`query { profile { ${ne} } }`,headers:e})).profile}catch(t){throw new Error(t)}}),"getProfile"));l(this,"getSession",n((e,t)=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:`query getSession($params: SessionQueryInput){session(params: $params) { ${k} } }`,headers:e,variables:{params:t}})).session}catch(s){throw new Error(s)}}),"getSession"));l(this,"getToken",n(e=>f(this,null,function*(){if(e.grant_type||(e.grant_type="authorization_code"),e.grant_type==="refresh_token"&&!e.refresh_token)throw new Error("Invalid refresh_token");if(e.grant_type==="authorization_code"&&!this.codeVerifier)throw new Error("Invalid code verifier");let t={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 z()(`${this.config.authorizerURL}/oauth/token`,{method:"POST",body:JSON.stringify(t),headers:O({},this.config.extraHeaders),credentials:"include"}),u=yield c.json();if(c.status>=400)throw new Error(u);return u}catch(s){throw new Error(s)}}),"getToken"));l(this,"graphqlQuery",n(e=>f(this,null,function*(){let c=yield(yield z()(`${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"})).json();if(c.errors&&c.errors.length)throw console.error(c.errors),new Error(c.errors[0].message);return c.data}),"graphqlQuery"));l(this,"login",n(e=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:`
|
|
2
2
|
mutation login($data: LoginInput!) { login(params: $data) { ${k}}}
|
|
3
3
|
`,variables:{data:e}})).login}catch(t){throw new Error(t)}}),"login"));l(this,"logout",n(e=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:" mutation { logout { message } } ",headers:e})).logout}catch(t){console.error(t)}}),"logout"));l(this,"magicLinkLogin",n(e=>f(this,null,function*(){try{return e.state||(e.state=v(U())),e.redirect_uri||(e.redirect_uri=this.config.redirectURL),(yield this.graphqlQuery({query:`
|
|
4
4
|
mutation magicLinkLogin($data: MagicLinkLoginInput!) { magic_link_login(params: $data) { message }}
|
|
@@ -11,4 +11,4 @@ var __AUTHORIZER_JS__=(()=>{var pe=Object.create;var A=Object.defineProperty,ye=
|
|
|
11
11
|
`,variables:{data:e}})).verify_email}catch(t){throw new Error(t)}}),"verifyEmail"));l(this,"verifyOtp",n(e=>f(this,null,function*(){try{return(yield this.graphqlQuery({query:`
|
|
12
12
|
mutation verifyOtp($data: VerifyOTPRequest!) { verify_otp(params: $data) { ${k}}}
|
|
13
13
|
`,variables:{data:e}})).verify_otp}catch(t){throw new Error(t)}}),"verifyOtp"));if(!e)throw new Error("Configuration is required");if(this.config=e,!e.authorizerURL&&!e.authorizerURL.trim())throw new Error("Invalid authorizerURL");if(e.authorizerURL&&(this.config.authorizerURL=M(e.authorizerURL)),!e.redirectURL&&!e.redirectURL.trim())throw new Error("Invalid redirectURL");this.config.redirectURL=M(e.redirectURL),this.config.extraHeaders=G(O({},e.extraHeaders||{}),{"x-authorizer-url":this.config.authorizerURL,"Content-Type":"application/json"}),this.config.clientID=e.clientID.trim()}};n($,"Authorizer");return Re(Le);})();
|
|
14
|
-
window.__TAURI__ =
|
|
14
|
+
window.__TAURI__ = authorizerdev
|
package/lib/index.d.ts
CHANGED
|
@@ -175,7 +175,7 @@ interface GetTokenResponse {
|
|
|
175
175
|
refresh_token?: string;
|
|
176
176
|
}
|
|
177
177
|
interface ValidateJWTTokenInput {
|
|
178
|
-
token_type:
|
|
178
|
+
token_type: 'access_token' | 'id_token' | 'refresh_token';
|
|
179
179
|
token: string;
|
|
180
180
|
roles?: string[];
|
|
181
181
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.3",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"types": "lib/index.d.ts",
|
|
5
5
|
"main": "lib/index.js",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"@swc/core": "^1.3.37",
|
|
40
40
|
"bumpp": "^9.0.0",
|
|
41
41
|
"eslint": "^8.35.0",
|
|
42
|
-
"encoding": "^0.1.13",
|
|
43
42
|
"husky": "^7.0.1",
|
|
44
43
|
"jest": "^27.0.6",
|
|
45
44
|
"rimraf": "^2.7.1",
|
|
@@ -60,7 +59,7 @@
|
|
|
60
59
|
"build": "tsup",
|
|
61
60
|
"test": "npm run build && jest --testTimeout=20000 --runInBand",
|
|
62
61
|
"release": "pnpm build && bumpp --commit --push --tag && pnpm publish",
|
|
63
|
-
"lint": "eslint --ext .ts,.tsx,.js,.jsx .",
|
|
64
|
-
"lint:fix": "eslint --ext .ts,.tsx,.js,.jsx . --fix"
|
|
62
|
+
"lint": "eslint --ignore-pattern 'tsup.config.ts' --ext .ts,.tsx,.js,.jsx .",
|
|
63
|
+
"lint:fix": "eslint --ignore-pattern 'tsup.config.ts' --ext .ts,.tsx,.js,.jsx . --fix"
|
|
65
64
|
}
|
|
66
65
|
}
|