@openfort/openfort-js 1.0.6 → 1.1.0
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/dist/cjs/sdk/src/api/auth.cjs +1 -1
- package/dist/cjs/sdk/src/auth/authManager.cjs +1 -1
- package/dist/cjs/sdk/src/version.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/sdk/src/api/auth.js +1 -1
- package/dist/sdk/src/auth/authManager.js +1 -1
- package/dist/sdk/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("../core/configuration/authentication.cjs"),e=require("../core/errors/authErrorCodes.cjs"),i=require("../core/errors/openfortError.cjs"),a=require("../types/types.cjs");exports.AuthApi=class{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,i,a,n){this.storage=t,this.authManager=e,this.validateAndRefreshToken=i,this.ensureInitialized=a,this.eventEmitter=n}async logInWithEmailPassword({email:n,password:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"email"});try{const e=await this.authManager.loginEmailPassword(n,r);return null===e?.token||(new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async signUpGuest(){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"guest"});try{const e=await this.authManager.registerGuest();return new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async signUpWithEmailPassword({email:n,password:r,name:s,callbackURL:o}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"email"});try{const e=s||n,i=await this.authManager.signupEmailPassword(n,r,e,o);return i instanceof Object&&"action"in i||(new t.Authentication("session",i.token,i.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,i)),i}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async initOAuth({provider:n,redirectTo:r,options:s}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"oauth",provider:n});try{return await this.authManager.initOAuth(n,r,s)}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async logInWithIdToken({provider:n,token:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"idToken",provider:n});try{const e=await this.authManager.loginWithIdToken(n,r);return new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async storeCredentials({token:e,userId:a}){if(await this.ensureInitialized(),!a)throw new i.ConfigurationError("User ID is required to store credentials");const n=encodeURIComponent(e);new t.Authentication("session",n,a).save(this.storage)}async logout(){const e=await t.Authentication.fromStorage(this.storage);if(e){try{"third_party"!==e.type&&await this.authManager.logout(e)}catch(t){}t.Authentication.clear(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_LOGOUT)}}async requestEmailOtp({email:e}){await this.ensureInitialized();const i=await t.Authentication.fromStorage(this.storage);this.eventEmitter.emit(a.OpenfortEvents.ON_OTP_REQUEST,{method:"email"});const n=!!i&&(await this.authManager.getUser(i)).isAnonymous;try{await this.authManager.requestEmailOTP(e,i?.token&&!n?"email-verification":"sign-in")}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_OTP_FAILURE,t),t}}async logInWithEmailOtp({email:n,otp:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"email"});try{const e=await this.authManager.loginWithEmailOTP(n,r);return null===e?.token||(new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async requestPhoneOtp({phoneNumber:t}){await this.ensureInitialized(),this.eventEmitter.emit(a.OpenfortEvents.ON_OTP_REQUEST,{method:"phone",provider:"phone"});try{await this.authManager.requestPhoneOtp(t)}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_OTP_FAILURE,t),t}}async linkPhoneOtp({phoneNumber:n,otp:r}){await this.ensureInitialized(),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"phone"});const s=await t.Authentication.fromStorage(this.storage);if(!s)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");try{const e=await this.authManager.linkSMSOTP(n,r,s);return null===e?.token||(new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async logInWithPhoneOtp({phoneNumber:n,otp:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"phone"});try{const e=await this.authManager.loginWithSMSOTP(n,r);return null===e?.token||(new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async resetPassword({password:t,token:e}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async verifyEmail({token:t,callbackURL:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async verifyEmailOtp({email:t,otp:e}){await this.ensureInitialized(),await this.authManager.verifyEmailOtp(t,e)}async initLinkOAuth({provider:n,redirectTo:r,options:s}){await this.validateAndRefreshToken();const o=await t.Authentication.fromStorage(this.storage);if(!o)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");return this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"oauth",provider:n}),(await this.authManager.getUser(o)).isAnonymous?this.authManager.linkOAuthToAnonymous(o,n,r):await this.authManager.linkOAuth(o,n,r,s)}async unlinkOAuth({provider:a}){await this.validateAndRefreshToken();const n=await t.Authentication.fromStorage(this.storage);if(!n)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");return await this.authManager.unlinkOAuth(a,n)}async
|
|
1
|
+
"use strict";var t=require("../core/configuration/authentication.cjs"),e=require("../core/errors/authErrorCodes.cjs"),i=require("../core/errors/openfortError.cjs"),a=require("../types/types.cjs");exports.AuthApi=class{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,i,a,n){this.storage=t,this.authManager=e,this.validateAndRefreshToken=i,this.ensureInitialized=a,this.eventEmitter=n}async logInWithEmailPassword({email:n,password:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"email"});try{const e=await this.authManager.loginEmailPassword(n,r);return null===e?.token||(new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async signUpGuest(){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"guest"});try{const e=await this.authManager.registerGuest();return new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async signUpWithEmailPassword({email:n,password:r,name:s,callbackURL:o}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"email"});try{const e=s||n,i=await this.authManager.signupEmailPassword(n,r,e,o);return i instanceof Object&&"action"in i||(new t.Authentication("session",i.token,i.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,i)),i}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async initOAuth({provider:n,redirectTo:r,options:s}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"oauth",provider:n});try{return await this.authManager.initOAuth(n,r,s)}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async logInWithIdToken({provider:n,token:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"idToken",provider:n});try{const e=await this.authManager.loginWithIdToken(n,r);return new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async storeCredentials({token:e,userId:a}){if(await this.ensureInitialized(),!a)throw new i.ConfigurationError("User ID is required to store credentials");const n=encodeURIComponent(e);new t.Authentication("session",n,a).save(this.storage)}async logout(){const e=await t.Authentication.fromStorage(this.storage);if(e){try{"third_party"!==e.type&&await this.authManager.logout(e)}catch(t){}t.Authentication.clear(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_LOGOUT)}}async requestEmailOtp({email:e}){await this.ensureInitialized();const i=await t.Authentication.fromStorage(this.storage);this.eventEmitter.emit(a.OpenfortEvents.ON_OTP_REQUEST,{method:"email"});const n=!!i&&(await this.authManager.getUser(i)).isAnonymous;try{await this.authManager.requestEmailOTP(e,i?.token&&!n?"email-verification":"sign-in")}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_OTP_FAILURE,t),t}}async logInWithEmailOtp({email:n,otp:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"email"});try{const e=await this.authManager.loginWithEmailOTP(n,r);return null===e?.token||(new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async requestPhoneOtp({phoneNumber:t}){await this.ensureInitialized(),this.eventEmitter.emit(a.OpenfortEvents.ON_OTP_REQUEST,{method:"phone",provider:"phone"});try{await this.authManager.requestPhoneOtp(t)}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_OTP_FAILURE,t),t}}async linkPhoneOtp({phoneNumber:n,otp:r}){await this.ensureInitialized(),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"phone"});const s=await t.Authentication.fromStorage(this.storage);if(!s)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");try{const e=await this.authManager.linkSMSOTP(n,r,s);return null===e?.token||(new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async logInWithPhoneOtp({phoneNumber:n,otp:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"phone"});try{const e=await this.authManager.loginWithSMSOTP(n,r);return null===e?.token||(new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async resetPassword({password:t,token:e}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async verifyEmail({token:t,callbackURL:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async verifyEmailOtp({email:t,otp:e}){await this.ensureInitialized(),await this.authManager.verifyEmailOtp(t,e)}async initLinkOAuth({provider:n,redirectTo:r,options:s}){await this.validateAndRefreshToken();const o=await t.Authentication.fromStorage(this.storage);if(!o)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");return this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"oauth",provider:n}),(await this.authManager.getUser(o)).isAnonymous?this.authManager.linkOAuthToAnonymous(o,n,r):await this.authManager.linkOAuth(o,n,r,s)}async unlinkOAuth({provider:a}){await this.validateAndRefreshToken();const n=await t.Authentication.fromStorage(this.storage);if(!n)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");return await this.authManager.unlinkOAuth(a,n)}async initSiwe({address:t}){return await this.ensureInitialized(),await this.authManager.initSIWE(t)}async initLinkSiwe({address:a}){await this.ensureInitialized();const n=await t.Authentication.fromStorage(this.storage);if(!n)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");return await this.authManager.linkSIWE(a,n)}async loginWithSiwe({signature:n,message:r,walletClientType:s,connectorType:o,address:h}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_INIT,{method:"siwe"});try{const e=await this.authManager.authenticateSIWE(n,r,s,o,h);return new t.Authentication("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(a.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async linkWithSiwe({signature:a,message:n,walletClientType:r,connectorType:s,address:o,chainId:h}){await this.validateAndRefreshToken();const E=await t.Authentication.fromStorage(this.storage);if(!E)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");return await this.authManager.linkWallet(a,n,r,s,o,h,E)}async unlinkWallet({address:a,chainId:n}){await this.validateAndRefreshToken();const r=await t.Authentication.fromStorage(this.storage);if(!r)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");return await this.authManager.unlinkWallet(a,n,r)}async addEmail(a){await this.validateAndRefreshToken();const n=await t.Authentication.fromStorage(this.storage);if(!n)throw new i.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No authentication found");if((await this.authManager.getUser(n)).email)throw new i.ConfigurationError("User already has an email");return await this.authManager.addEmail(a.email,a.callbackURL,n)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../utils/debug.cjs"),t=require("../core/errors/authErrorCodes.cjs"),i=require("../core/errors/openfortError.cjs"),a=require("../core/errors/withApiError.cjs"),r=require("../types/types.cjs");function s(e){if(!e)throw new i.OpenfortError(t.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"User data is missing");return{id:e.id||"",email:e.email,name:e.name??void 0,image:e.image??void 0,emailVerified:e.emailVerified,isAnonymous:e.isAnonymous,createdAt:e.createdAt,updatedAt:e.updatedAt,phoneNumber:e.phoneNumber,phoneNumberVerified:e.phoneNumberVerified,linkedAccounts:e.linkedAccounts}}function n(e){if(e)return{id:e.id,token:e.token,userId:e.userId,expiresAt:e.expiresAt,createdAt:e.createdAt,updatedAt:e.updatedAt}}exports.AuthManager=class{backendApiClientsInstance;publishableKeyInstance;setBackendApiClients(e,t){this.backendApiClientsInstance=e,this.publishableKeyInstance=t}get backendApiClients(){if(!this.backendApiClientsInstance)throw new i.ConfigurationError("Backend API clients not initialized");return this.backendApiClientsInstance}get publishableKey(){if(!this.publishableKeyInstance)throw new i.ConfigurationError("Publishable key not initialized");return this.publishableKeyInstance}buildAuthHeaders(e){return{"x-project-key":this.publishableKey,...e&&{authorization:`Bearer ${e}`}}}async initOAuth(e,t,i){return await a.withApiError(async()=>(await this.backendApiClients.authApi.socialSignIn({socialSignInRequest:{provider:e,callbackURL:t,scopes:i?.scopes?.split(" "),disableRedirect:i?.skipBrowserRedirect??!1}},{headers:{"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async linkOAuthToAnonymous(e,t,i){return await a.withApiError(async()=>(await this.backendApiClients.authApi.socialSignIn({socialSignInRequest:{provider:t,callbackURL:i}},{headers:{authorization:`Bearer ${e.token}`,"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async registerGuest(){return a.withApiError(async()=>{const e=await this.backendApiClients.authApi.signInAnonymousPost({headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:s(e.data.user)}},{context:"registerGuest"})}async loginWithIdToken(e,t){const i={socialSignInRequest:{provider:e,idToken:{token:t}}};return await a.withApiError(async()=>{const e=await this.backendApiClients.authApi.socialSignIn(i,{headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:s(e.data.user)}},{context:"loginWithIdToken"})}async authenticateThirdParty(e,t){const i={thirdPartyOAuthRequest:{provider:e,token:t}};return a.withApiError(async()=>({userId:(await this.backendApiClients.userApi.thirdPartyV2(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data.id}),{context:"authenticateThirdParty"})}async initSIWE(e){const t={siweNoncePostRequest:{walletAddress:e}};return{address:e,nonce:(await a.withApiError(async()=>this.backendApiClients.authApi.siweNoncePost(t,{headers:{"x-project-key":`${this.publishableKey}`}}),{context:"initSIWE"})).data.nonce}}async linkSIWE(e,t){const i={siweNoncePostRequest:{walletAddress:e}};return{address:e,nonce:(await a.withApiError(async()=>this.backendApiClients.authApi.linkSiweNoncePost(i,{headers:{authorization:`Bearer ${t.token}`,"x-project-key":`${this.publishableKey}`}}),{context:"linkSIWE"})).data.nonce}}async authenticateSIWE(e,t,i,r,n){const o={siweVerifyPostRequest:{signature:e,walletAddress:n,message:t,walletClientType:i,connectorType:r}};return a.withApiError(async()=>{const e=await this.backendApiClients.authApi.siweVerifyPost(o,{headers:{"x-project-key":`${this.publishableKey}`}}),t=e.data.user;return{token:e.data.token,user:s(t)}},{context:"authenticateSIWE"})}async loginEmailPassword(e,t){return a.withApiError(async()=>{const i=(await this.backendApiClients.authApi.signInEmailPost({signInEmailPostRequest:{email:e,password:t}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:s(i.user)}},{context:"loginEmailPassword"})}async requestResetPassword(e,t){await a.withApiError(async()=>{await this.backendApiClients.authApi.requestPasswordResetPost({forgetPasswordPostRequest:{email:e,redirectTo:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestResetPassword"})}async resetPassword(e,t){return a.withApiError(async()=>{await this.backendApiClients.authApi.resetPasswordPost({resetPasswordPostRequest:{newPassword:e,token:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"resetPassword"})}async requestEmailVerification(e,t){await a.withApiError(async()=>{await this.backendApiClients.authApi.sendVerificationEmailPost({sendVerificationEmailPostRequest:{email:e,callbackURL:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestEmailVerification"})}async verifyEmail(e,t){return a.withApiError(async()=>{await this.backendApiClients.authApi.verifyEmailGet({token:e,callbackURL:t})},{context:"verifyEmail"})}async signupEmailPassword(e,t,i,n,o){return a.withApiError(async()=>{const a=(await this.backendApiClients.authApi.signUpEmailPost({signUpEmailPostRequest:{email:e,password:t,name:i,callbackURL:n}},{headers:this.buildAuthHeaders(o)})).data;return null===a.token?{action:r.AuthActionRequiredActions.ACTION_VERIFY_EMAIL}:{token:a.token,user:s(a.user)}},{context:"signupEmailPassword"})}async validateCredentials(t,i){e.debugLog("Validating credentials with token:",t.token);const a=await this.getSessionWithToken(t,i);return{token:a.session.token,user:s(a.user),session:n(a.session)}}async logout(e){return a.withApiError(async()=>{await this.backendApiClients.authApi.signOutPost(void 0,{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})},{context:"logout"})}async getUser(e){return a.withApiError(async()=>s((await this.backendApiClients.userApi.meV2({headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})).data),{context:"getUser"})}async linkOAuth(e,t,i,r){const s=r?.skipBrowserRedirect??!1,n={linkSocialPostRequest:{provider:t,callbackURL:i,scopes:r?.scopes?.split(" "),disableRedirect:s}},o=await a.withApiError(async()=>this.backendApiClients.authApi.linkSocialPost(n,{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)}),{context:"linkOAuth"});return"undefined"!=typeof window&&!s&&o.data.url&&window.location.assign(o.data.url),o.data.url||""}async unlinkOAuth(e,t){const i={unlinkAccountPostRequest:{providerId:e}};return a.withApiError(async()=>(await this.backendApiClients.authApi.unlinkAccountPost(i,{headers:t.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t.token,"x-auth-provider":t.thirdPartyProvider,"x-token-type":t.thirdPartyTokenType}:this.buildAuthHeaders(t.token)})).data,{context:"unlinkOAuth"})}async addEmail(e,t,i){return a.withApiError(async()=>(await this.backendApiClients.authApi.changeEmailPost({changeEmailPostRequest:{newEmail:e,callbackURL:t}},{headers:i.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:this.buildAuthHeaders(i.token)})).data,{context:"addEmail"})}async unlinkWallet(e,t,i){const r={linkSiweUnlinkPostRequest:{walletAddress:e,chaindId:t}};return a.withApiError(async()=>(await this.backendApiClients.authApi.linkSiweUnlinkPost(r,{headers:i.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:this.buildAuthHeaders(i.token)})).data,{context:"unlinkWallet"})}async linkWallet(e,t,i,r,s,n,o){const h={siweVerifyPostRequest:{signature:e,message:t,walletAddress:s,chainId:n,walletClientType:i,connectorType:r}};return a.withApiError(async()=>(await this.backendApiClients.authApi.linkSiweVerifyPost(h,{headers:o.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}:this.buildAuthHeaders(o.token)})).data,{context:"linkWallet"})}async requestEmailOTP(e,t){const i={emailOtpSendVerificationOtpPostRequest:{email:e,type:t}};await a.withApiError(async()=>(await this.backendApiClients.authApi.emailOtpSendVerificationOtpPost(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestEmailOTP"})}async verifyEmailOtp(e,t,i){await a.withApiError(async()=>(await this.backendApiClients.authApi.emailOtpVerifyEmailPost({emailOtpVerifyEmailPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data,{context:"verifyEmailOtp"})}async loginWithEmailOTP(e,t,i){return await a.withApiError(async()=>{const a=(await this.backendApiClients.authApi.signInEmailOtpPost({signInEmailOtpPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data;return{token:a.token,user:s(a.user)}},{context:"loginWithEmailOTP"})}async requestPhoneOtp(e){const t={phoneNumberSendOtpPostRequest:{phoneNumber:e}};await a.withApiError(async()=>(await this.backendApiClients.authApi.phoneNumberSendOtpPost(t,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestPhoneOtp"})}async loginWithSMSOTP(e,t){return await a.withApiError(async()=>{const i=(await this.backendApiClients.authApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:s(i.user)}},{context:"loginWithSMSOTP"})}async linkSMSOTP(e,t,i){return await a.withApiError(async()=>{const a=(await this.backendApiClients.authApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e,updatePhoneNumber:!0}},{headers:{authorization:`Bearer ${i.token}`,"x-project-key":`${this.publishableKey}`}})).data;return{token:a.token,user:s(a.user)}},{context:"linkSMSOTP"})}async getSessionWithToken(e,t){return await a.withApiError(async()=>(await this.backendApiClients.authApi.getSessionGet({disableCookieCache:t},{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})).data,{context:"getSessionWithToken"})}};
|
|
1
|
+
"use strict";var e=require("../utils/debug.cjs"),t=require("../core/errors/authErrorCodes.cjs"),i=require("../core/errors/openfortError.cjs"),a=require("../core/errors/withApiError.cjs"),r=require("../types/types.cjs");function s(e){if(!e)throw new i.OpenfortError(t.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"User data is missing");return{id:e.id||"",email:e.email,name:e.name??void 0,image:e.image??void 0,emailVerified:e.emailVerified,isAnonymous:e.isAnonymous,createdAt:e.createdAt,updatedAt:e.updatedAt,phoneNumber:e.phoneNumber,phoneNumberVerified:e.phoneNumberVerified,linkedAccounts:e.linkedAccounts}}function n(e){if(e)return{id:e.id,token:e.token,userId:e.userId,expiresAt:e.expiresAt,createdAt:e.createdAt,updatedAt:e.updatedAt}}exports.AuthManager=class{backendApiClientsInstance;publishableKeyInstance;setBackendApiClients(e,t){this.backendApiClientsInstance=e,this.publishableKeyInstance=t}get backendApiClients(){if(!this.backendApiClientsInstance)throw new i.ConfigurationError("Backend API clients not initialized");return this.backendApiClientsInstance}get publishableKey(){if(!this.publishableKeyInstance)throw new i.ConfigurationError("Publishable key not initialized");return this.publishableKeyInstance}buildAuthHeaders(e){return{"x-project-key":this.publishableKey,...e&&{authorization:`Bearer ${e}`}}}async initOAuth(e,t,i){return await a.withApiError(async()=>(await this.backendApiClients.authApi.socialSignIn({socialSignInRequest:{provider:e,callbackURL:t,scopes:i?.scopes?.split(" "),disableRedirect:i?.skipBrowserRedirect??!1}},{headers:{"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async linkOAuthToAnonymous(e,t,i){return await a.withApiError(async()=>(await this.backendApiClients.authApi.socialSignIn({socialSignInRequest:{provider:t,callbackURL:i}},{headers:{authorization:`Bearer ${e.token}`,"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async registerGuest(){return a.withApiError(async()=>{const e=await this.backendApiClients.authApi.signInAnonymousPost({headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:s(e.data.user)}},{context:"registerGuest"})}async loginWithIdToken(e,t){const i={socialSignInRequest:{provider:e,idToken:{token:t}}};return await a.withApiError(async()=>{const e=await this.backendApiClients.authApi.socialSignIn(i,{headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:s(e.data.user)}},{context:"loginWithIdToken"})}async authenticateThirdParty(e,t){const i={thirdPartyOAuthRequest:{provider:e,token:t}};return a.withApiError(async()=>({userId:(await this.backendApiClients.userApi.thirdPartyV2(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data.id}),{context:"authenticateThirdParty"})}async initSIWE(e){const t={siweNoncePostRequest:{walletAddress:e}};return{address:e,nonce:(await a.withApiError(async()=>this.backendApiClients.authApi.siweNoncePost(t,{headers:{"x-project-key":`${this.publishableKey}`}}),{context:"initSIWE"})).data.nonce}}async linkSIWE(e,t){const i={siweNoncePostRequest:{walletAddress:e}};return{address:e,nonce:(await a.withApiError(async()=>this.backendApiClients.authApi.linkSiweNoncePost(i,{headers:t.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t.token,"x-auth-provider":t.thirdPartyProvider,"x-token-type":t.thirdPartyTokenType}:this.buildAuthHeaders(t.token)}),{context:"linkSIWE"})).data.nonce}}async authenticateSIWE(e,t,i,r,n){const o={siweVerifyPostRequest:{signature:e,walletAddress:n,message:t,walletClientType:i,connectorType:r}};return a.withApiError(async()=>{const e=await this.backendApiClients.authApi.siweVerifyPost(o,{headers:{"x-project-key":`${this.publishableKey}`}}),t=e.data.user;return{token:e.data.token,user:s(t)}},{context:"authenticateSIWE"})}async loginEmailPassword(e,t){return a.withApiError(async()=>{const i=(await this.backendApiClients.authApi.signInEmailPost({signInEmailPostRequest:{email:e,password:t}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:s(i.user)}},{context:"loginEmailPassword"})}async requestResetPassword(e,t){await a.withApiError(async()=>{await this.backendApiClients.authApi.requestPasswordResetPost({forgetPasswordPostRequest:{email:e,redirectTo:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestResetPassword"})}async resetPassword(e,t){return a.withApiError(async()=>{await this.backendApiClients.authApi.resetPasswordPost({resetPasswordPostRequest:{newPassword:e,token:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"resetPassword"})}async requestEmailVerification(e,t){await a.withApiError(async()=>{await this.backendApiClients.authApi.sendVerificationEmailPost({sendVerificationEmailPostRequest:{email:e,callbackURL:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestEmailVerification"})}async verifyEmail(e,t){return a.withApiError(async()=>{await this.backendApiClients.authApi.verifyEmailGet({token:e,callbackURL:t})},{context:"verifyEmail"})}async signupEmailPassword(e,t,i,n,o){return a.withApiError(async()=>{const a=(await this.backendApiClients.authApi.signUpEmailPost({signUpEmailPostRequest:{email:e,password:t,name:i,callbackURL:n}},{headers:this.buildAuthHeaders(o)})).data;return null===a.token?{action:r.AuthActionRequiredActions.ACTION_VERIFY_EMAIL}:{token:a.token,user:s(a.user)}},{context:"signupEmailPassword"})}async validateCredentials(t,i){e.debugLog("Validating credentials with token:",t.token);const a=await this.getSessionWithToken(t,i);return{token:a.session.token,user:s(a.user),session:n(a.session)}}async logout(e){return a.withApiError(async()=>{await this.backendApiClients.authApi.signOutPost(void 0,{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})},{context:"logout"})}async getUser(e){return a.withApiError(async()=>s((await this.backendApiClients.userApi.meV2({headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})).data),{context:"getUser"})}async linkOAuth(e,t,i,r){const s=r?.skipBrowserRedirect??!1,n={linkSocialPostRequest:{provider:t,callbackURL:i,scopes:r?.scopes?.split(" "),disableRedirect:s}},o=await a.withApiError(async()=>this.backendApiClients.authApi.linkSocialPost(n,{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)}),{context:"linkOAuth"});return"undefined"!=typeof window&&!s&&o.data.url&&window.location.assign(o.data.url),o.data.url||""}async unlinkOAuth(e,t){const i={unlinkAccountPostRequest:{providerId:e}};return a.withApiError(async()=>(await this.backendApiClients.authApi.unlinkAccountPost(i,{headers:t.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t.token,"x-auth-provider":t.thirdPartyProvider,"x-token-type":t.thirdPartyTokenType}:this.buildAuthHeaders(t.token)})).data,{context:"unlinkOAuth"})}async addEmail(e,t,i){return a.withApiError(async()=>(await this.backendApiClients.authApi.changeEmailPost({changeEmailPostRequest:{newEmail:e,callbackURL:t}},{headers:i.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:this.buildAuthHeaders(i.token)})).data,{context:"addEmail"})}async unlinkWallet(e,t,i){const r={linkSiweUnlinkPostRequest:{walletAddress:e,chaindId:t}};return a.withApiError(async()=>(await this.backendApiClients.authApi.linkSiweUnlinkPost(r,{headers:i.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:this.buildAuthHeaders(i.token)})).data,{context:"unlinkWallet"})}async linkWallet(e,t,i,r,s,n,o){const h={siweVerifyPostRequest:{signature:e,message:t,walletAddress:s,chainId:n,walletClientType:i,connectorType:r}};return a.withApiError(async()=>(await this.backendApiClients.authApi.linkSiweVerifyPost(h,{headers:o.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}:this.buildAuthHeaders(o.token)})).data,{context:"linkWallet"})}async requestEmailOTP(e,t){const i={emailOtpSendVerificationOtpPostRequest:{email:e,type:t}};await a.withApiError(async()=>(await this.backendApiClients.authApi.emailOtpSendVerificationOtpPost(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestEmailOTP"})}async verifyEmailOtp(e,t,i){await a.withApiError(async()=>(await this.backendApiClients.authApi.emailOtpVerifyEmailPost({emailOtpVerifyEmailPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data,{context:"verifyEmailOtp"})}async loginWithEmailOTP(e,t,i){return await a.withApiError(async()=>{const a=(await this.backendApiClients.authApi.signInEmailOtpPost({signInEmailOtpPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data;return{token:a.token,user:s(a.user)}},{context:"loginWithEmailOTP"})}async requestPhoneOtp(e){const t={phoneNumberSendOtpPostRequest:{phoneNumber:e}};await a.withApiError(async()=>(await this.backendApiClients.authApi.phoneNumberSendOtpPost(t,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestPhoneOtp"})}async loginWithSMSOTP(e,t){return await a.withApiError(async()=>{const i=(await this.backendApiClients.authApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:s(i.user)}},{context:"loginWithSMSOTP"})}async linkSMSOTP(e,t,i){return await a.withApiError(async()=>{const a=(await this.backendApiClients.authApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e,updatePhoneNumber:!0}},{headers:{authorization:`Bearer ${i.token}`,"x-project-key":`${this.publishableKey}`}})).data;return{token:a.token,user:s(a.user)}},{context:"linkSMSOTP"})}async getSessionWithToken(e,t){return await a.withApiError(async()=>(await this.backendApiClients.authApi.getSessionGet({disableCookieCache:t},{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})).data,{context:"getSessionWithToken"})}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.0
|
|
1
|
+
"use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.1.0";
|
package/dist/index.d.cts
CHANGED
|
@@ -11754,20 +11754,20 @@ declare class AuthApi {
|
|
|
11754
11754
|
unlinkOAuth({ provider }: {
|
|
11755
11755
|
provider: OAuthProvider;
|
|
11756
11756
|
}): Promise<UnlinkAccountResponse>;
|
|
11757
|
-
|
|
11757
|
+
initSiwe({ address }: {
|
|
11758
11758
|
address: string;
|
|
11759
11759
|
}): Promise<SIWEInitResponse>;
|
|
11760
|
-
|
|
11760
|
+
initLinkSiwe({ address }: {
|
|
11761
11761
|
address: string;
|
|
11762
11762
|
}): Promise<SIWEInitResponse>;
|
|
11763
|
-
|
|
11763
|
+
loginWithSiwe({ signature, message, walletClientType, connectorType, address, }: {
|
|
11764
11764
|
signature: string;
|
|
11765
11765
|
message: string;
|
|
11766
11766
|
walletClientType: string;
|
|
11767
11767
|
connectorType: string;
|
|
11768
11768
|
address: string;
|
|
11769
11769
|
}): Promise<AuthResponse>;
|
|
11770
|
-
|
|
11770
|
+
linkWithSiwe({ signature, message, walletClientType, connectorType, address, chainId, }: {
|
|
11771
11771
|
signature: string;
|
|
11772
11772
|
message: string;
|
|
11773
11773
|
walletClientType: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -11754,20 +11754,20 @@ declare class AuthApi {
|
|
|
11754
11754
|
unlinkOAuth({ provider }: {
|
|
11755
11755
|
provider: OAuthProvider;
|
|
11756
11756
|
}): Promise<UnlinkAccountResponse>;
|
|
11757
|
-
|
|
11757
|
+
initSiwe({ address }: {
|
|
11758
11758
|
address: string;
|
|
11759
11759
|
}): Promise<SIWEInitResponse>;
|
|
11760
|
-
|
|
11760
|
+
initLinkSiwe({ address }: {
|
|
11761
11761
|
address: string;
|
|
11762
11762
|
}): Promise<SIWEInitResponse>;
|
|
11763
|
-
|
|
11763
|
+
loginWithSiwe({ signature, message, walletClientType, connectorType, address, }: {
|
|
11764
11764
|
signature: string;
|
|
11765
11765
|
message: string;
|
|
11766
11766
|
walletClientType: string;
|
|
11767
11767
|
connectorType: string;
|
|
11768
11768
|
address: string;
|
|
11769
11769
|
}): Promise<AuthResponse>;
|
|
11770
|
-
|
|
11770
|
+
linkWithSiwe({ signature, message, walletClientType, connectorType, address, chainId, }: {
|
|
11771
11771
|
signature: string;
|
|
11772
11772
|
message: string;
|
|
11773
11773
|
walletClientType: string;
|
package/dist/sdk/src/api/auth.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Authentication as t}from"../core/configuration/authentication.js";import{OPENFORT_AUTH_ERROR_CODES as e}from"../core/errors/authErrorCodes.js";import{SessionError as i,ConfigurationError as a}from"../core/errors/openfortError.js";import{OpenfortEvents as
|
|
1
|
+
import{Authentication as t}from"../core/configuration/authentication.js";import{OPENFORT_AUTH_ERROR_CODES as e}from"../core/errors/authErrorCodes.js";import{SessionError as i,ConfigurationError as a}from"../core/errors/openfortError.js";import{OpenfortEvents as n}from"../types/types.js";class r{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,i,a,n){this.storage=t,this.authManager=e,this.validateAndRefreshToken=i,this.ensureInitialized=a,this.eventEmitter=n}async logInWithEmailPassword({email:a,password:r}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new i(e.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"email"});try{const e=await this.authManager.loginEmailPassword(a,r);return null===e?.token||(new t("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(n.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async signUpGuest(){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new i(e.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"guest"});try{const e=await this.authManager.registerGuest();return new t("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(n.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async signUpWithEmailPassword({email:a,password:r,name:s,callbackURL:o}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new i(e.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"email"});try{const e=s||a,i=await this.authManager.signupEmailPassword(a,r,e,o);return i instanceof Object&&"action"in i||(new t("session",i.token,i.user?.id).save(this.storage),this.eventEmitter.emit(n.ON_AUTH_SUCCESS,i)),i}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async initOAuth({provider:a,redirectTo:r,options:s}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new i(e.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"oauth",provider:a});try{return await this.authManager.initOAuth(a,r,s)}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async logInWithIdToken({provider:a,token:r}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new i(e.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"idToken",provider:a});try{const e=await this.authManager.loginWithIdToken(a,r);return new t("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(n.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async storeCredentials({token:e,userId:i}){if(await this.ensureInitialized(),!i)throw new a("User ID is required to store credentials");const n=encodeURIComponent(e);new t("session",n,i).save(this.storage)}async logout(){const e=await t.fromStorage(this.storage);if(e){try{"third_party"!==e.type&&await this.authManager.logout(e)}catch(t){}t.clear(this.storage),this.eventEmitter.emit(n.ON_LOGOUT)}}async requestEmailOtp({email:e}){await this.ensureInitialized();const i=await t.fromStorage(this.storage);this.eventEmitter.emit(n.ON_OTP_REQUEST,{method:"email"});const a=!!i&&(await this.authManager.getUser(i)).isAnonymous;try{await this.authManager.requestEmailOTP(e,i?.token&&!a?"email-verification":"sign-in")}catch(t){throw this.eventEmitter.emit(n.ON_OTP_FAILURE,t),t}}async logInWithEmailOtp({email:a,otp:r}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new i(e.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"email"});try{const e=await this.authManager.loginWithEmailOTP(a,r);return null===e?.token||(new t("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(n.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async requestPhoneOtp({phoneNumber:t}){await this.ensureInitialized(),this.eventEmitter.emit(n.ON_OTP_REQUEST,{method:"phone",provider:"phone"});try{await this.authManager.requestPhoneOtp(t)}catch(t){throw this.eventEmitter.emit(n.ON_OTP_FAILURE,t),t}}async linkPhoneOtp({phoneNumber:a,otp:r}){await this.ensureInitialized(),this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"phone"});const s=await t.fromStorage(this.storage);if(!s)throw new i(e.NOT_LOGGED_IN,"No authentication found");try{const e=await this.authManager.linkSMSOTP(a,r,s);return null===e?.token||(new t("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(n.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async logInWithPhoneOtp({phoneNumber:a,otp:r}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new i(e.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"phone"});try{const e=await this.authManager.loginWithSMSOTP(a,r);return null===e?.token||(new t("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(n.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async resetPassword({password:t,token:e}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async verifyEmail({token:t,callbackURL:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async verifyEmailOtp({email:t,otp:e}){await this.ensureInitialized(),await this.authManager.verifyEmailOtp(t,e)}async initLinkOAuth({provider:a,redirectTo:r,options:s}){await this.validateAndRefreshToken();const o=await t.fromStorage(this.storage);if(!o)throw new i(e.NOT_LOGGED_IN,"No authentication found");return this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"oauth",provider:a}),(await this.authManager.getUser(o)).isAnonymous?this.authManager.linkOAuthToAnonymous(o,a,r):await this.authManager.linkOAuth(o,a,r,s)}async unlinkOAuth({provider:a}){await this.validateAndRefreshToken();const n=await t.fromStorage(this.storage);if(!n)throw new i(e.NOT_LOGGED_IN,"No authentication found");return await this.authManager.unlinkOAuth(a,n)}async initSiwe({address:t}){return await this.ensureInitialized(),await this.authManager.initSIWE(t)}async initLinkSiwe({address:a}){await this.ensureInitialized();const n=await t.fromStorage(this.storage);if(!n)throw new i(e.NOT_LOGGED_IN,"No authentication found");return await this.authManager.linkSIWE(a,n)}async loginWithSiwe({signature:a,message:r,walletClientType:s,connectorType:o,address:h}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new i(e.ALREADY_LOGGED_IN,"Already logged in");this.eventEmitter.emit(n.ON_AUTH_INIT,{method:"siwe"});try{const e=await this.authManager.authenticateSIWE(a,r,s,o,h);return new t("session",e.token,e.user?.id).save(this.storage),this.eventEmitter.emit(n.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(n.ON_AUTH_FAILURE,t),t}}async linkWithSiwe({signature:a,message:n,walletClientType:r,connectorType:s,address:o,chainId:h}){await this.validateAndRefreshToken();const m=await t.fromStorage(this.storage);if(!m)throw new i(e.NOT_LOGGED_IN,"No authentication found");return await this.authManager.linkWallet(a,n,r,s,o,h,m)}async unlinkWallet({address:a,chainId:n}){await this.validateAndRefreshToken();const r=await t.fromStorage(this.storage);if(!r)throw new i(e.NOT_LOGGED_IN,"No authentication found");return await this.authManager.unlinkWallet(a,n,r)}async addEmail(n){await this.validateAndRefreshToken();const r=await t.fromStorage(this.storage);if(!r)throw new i(e.NOT_LOGGED_IN,"No authentication found");if((await this.authManager.getUser(r)).email)throw new a("User already has an email");return await this.authManager.addEmail(n.email,n.callbackURL,r)}}export{r as AuthApi};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{debugLog as e}from"../utils/debug.js";import{OPENFORT_AUTH_ERROR_CODES as t}from"../core/errors/authErrorCodes.js";import{ConfigurationError as i,OpenfortError as a}from"../core/errors/openfortError.js";import{withApiError as s}from"../core/errors/withApiError.js";import{AuthActionRequiredActions as n}from"../types/types.js";function r(e){if(!e)throw new a(t.INTERNAL_ERROR,"User data is missing");return{id:e.id||"",email:e.email,name:e.name??void 0,image:e.image??void 0,emailVerified:e.emailVerified,isAnonymous:e.isAnonymous,createdAt:e.createdAt,updatedAt:e.updatedAt,phoneNumber:e.phoneNumber,phoneNumberVerified:e.phoneNumberVerified,linkedAccounts:e.linkedAccounts}}function o(e){if(e)return{id:e.id,token:e.token,userId:e.userId,expiresAt:e.expiresAt,createdAt:e.createdAt,updatedAt:e.updatedAt}}class d{backendApiClientsInstance;publishableKeyInstance;setBackendApiClients(e,t){this.backendApiClientsInstance=e,this.publishableKeyInstance=t}get backendApiClients(){if(!this.backendApiClientsInstance)throw new i("Backend API clients not initialized");return this.backendApiClientsInstance}get publishableKey(){if(!this.publishableKeyInstance)throw new i("Publishable key not initialized");return this.publishableKeyInstance}buildAuthHeaders(e){return{"x-project-key":this.publishableKey,...e&&{authorization:`Bearer ${e}`}}}async initOAuth(e,t,i){return await s(async()=>(await this.backendApiClients.authApi.socialSignIn({socialSignInRequest:{provider:e,callbackURL:t,scopes:i?.scopes?.split(" "),disableRedirect:i?.skipBrowserRedirect??!1}},{headers:{"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async linkOAuthToAnonymous(e,t,i){return await s(async()=>(await this.backendApiClients.authApi.socialSignIn({socialSignInRequest:{provider:t,callbackURL:i}},{headers:{authorization:`Bearer ${e.token}`,"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async registerGuest(){return s(async()=>{const e=await this.backendApiClients.authApi.signInAnonymousPost({headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:r(e.data.user)}},{context:"registerGuest"})}async loginWithIdToken(e,t){const i={socialSignInRequest:{provider:e,idToken:{token:t}}};return await s(async()=>{const e=await this.backendApiClients.authApi.socialSignIn(i,{headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:r(e.data.user)}},{context:"loginWithIdToken"})}async authenticateThirdParty(e,t){const i={thirdPartyOAuthRequest:{provider:e,token:t}};return s(async()=>({userId:(await this.backendApiClients.userApi.thirdPartyV2(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data.id}),{context:"authenticateThirdParty"})}async initSIWE(e){const t={siweNoncePostRequest:{walletAddress:e}};return{address:e,nonce:(await s(async()=>this.backendApiClients.authApi.siweNoncePost(t,{headers:{"x-project-key":`${this.publishableKey}`}}),{context:"initSIWE"})).data.nonce}}async linkSIWE(e,t){const i={siweNoncePostRequest:{walletAddress:e}};return{address:e,nonce:(await s(async()=>this.backendApiClients.authApi.linkSiweNoncePost(i,{headers:{authorization:`Bearer ${t.token}`,"x-project-key":`${this.publishableKey}`}}),{context:"linkSIWE"})).data.nonce}}async authenticateSIWE(e,t,i,a,n){const o={siweVerifyPostRequest:{signature:e,walletAddress:n,message:t,walletClientType:i,connectorType:a}};return s(async()=>{const e=await this.backendApiClients.authApi.siweVerifyPost(o,{headers:{"x-project-key":`${this.publishableKey}`}}),t=e.data.user;return{token:e.data.token,user:r(t)}},{context:"authenticateSIWE"})}async loginEmailPassword(e,t){return s(async()=>{const i=(await this.backendApiClients.authApi.signInEmailPost({signInEmailPostRequest:{email:e,password:t}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:r(i.user)}},{context:"loginEmailPassword"})}async requestResetPassword(e,t){await s(async()=>{await this.backendApiClients.authApi.requestPasswordResetPost({forgetPasswordPostRequest:{email:e,redirectTo:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestResetPassword"})}async resetPassword(e,t){return s(async()=>{await this.backendApiClients.authApi.resetPasswordPost({resetPasswordPostRequest:{newPassword:e,token:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"resetPassword"})}async requestEmailVerification(e,t){await s(async()=>{await this.backendApiClients.authApi.sendVerificationEmailPost({sendVerificationEmailPostRequest:{email:e,callbackURL:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestEmailVerification"})}async verifyEmail(e,t){return s(async()=>{await this.backendApiClients.authApi.verifyEmailGet({token:e,callbackURL:t})},{context:"verifyEmail"})}async signupEmailPassword(e,t,i,a,o){return s(async()=>{const s=(await this.backendApiClients.authApi.signUpEmailPost({signUpEmailPostRequest:{email:e,password:t,name:i,callbackURL:a}},{headers:this.buildAuthHeaders(o)})).data;return null===s.token?{action:n.ACTION_VERIFY_EMAIL}:{token:s.token,user:r(s.user)}},{context:"signupEmailPassword"})}async validateCredentials(t,i){e("Validating credentials with token:",t.token);const a=await this.getSessionWithToken(t,i);return{token:a.session.token,user:r(a.user),session:o(a.session)}}async logout(e){return s(async()=>{await this.backendApiClients.authApi.signOutPost(void 0,{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})},{context:"logout"})}async getUser(e){return s(async()=>r((await this.backendApiClients.userApi.meV2({headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})).data),{context:"getUser"})}async linkOAuth(e,t,i,a){const n=a?.skipBrowserRedirect??!1,r={linkSocialPostRequest:{provider:t,callbackURL:i,scopes:a?.scopes?.split(" "),disableRedirect:n}},o=await s(async()=>this.backendApiClients.authApi.linkSocialPost(r,{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)}),{context:"linkOAuth"});return"undefined"!=typeof window&&!n&&o.data.url&&window.location.assign(o.data.url),o.data.url||""}async unlinkOAuth(e,t){const i={unlinkAccountPostRequest:{providerId:e}};return s(async()=>(await this.backendApiClients.authApi.unlinkAccountPost(i,{headers:t.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t.token,"x-auth-provider":t.thirdPartyProvider,"x-token-type":t.thirdPartyTokenType}:this.buildAuthHeaders(t.token)})).data,{context:"unlinkOAuth"})}async addEmail(e,t,i){return s(async()=>(await this.backendApiClients.authApi.changeEmailPost({changeEmailPostRequest:{newEmail:e,callbackURL:t}},{headers:i.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:this.buildAuthHeaders(i.token)})).data,{context:"addEmail"})}async unlinkWallet(e,t,i){const a={linkSiweUnlinkPostRequest:{walletAddress:e,chaindId:t}};return s(async()=>(await this.backendApiClients.authApi.linkSiweUnlinkPost(a,{headers:i.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:this.buildAuthHeaders(i.token)})).data,{context:"unlinkWallet"})}async linkWallet(e,t,i,a,n,r,o){const d={siweVerifyPostRequest:{signature:e,message:t,walletAddress:n,chainId:r,walletClientType:i,connectorType:a}};return s(async()=>(await this.backendApiClients.authApi.linkSiweVerifyPost(d,{headers:o.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}:this.buildAuthHeaders(o.token)})).data,{context:"linkWallet"})}async requestEmailOTP(e,t){const i={emailOtpSendVerificationOtpPostRequest:{email:e,type:t}};await s(async()=>(await this.backendApiClients.authApi.emailOtpSendVerificationOtpPost(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestEmailOTP"})}async verifyEmailOtp(e,t,i){await s(async()=>(await this.backendApiClients.authApi.emailOtpVerifyEmailPost({emailOtpVerifyEmailPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data,{context:"verifyEmailOtp"})}async loginWithEmailOTP(e,t,i){return await s(async()=>{const a=(await this.backendApiClients.authApi.signInEmailOtpPost({signInEmailOtpPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data;return{token:a.token,user:r(a.user)}},{context:"loginWithEmailOTP"})}async requestPhoneOtp(e){const t={phoneNumberSendOtpPostRequest:{phoneNumber:e}};await s(async()=>(await this.backendApiClients.authApi.phoneNumberSendOtpPost(t,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestPhoneOtp"})}async loginWithSMSOTP(e,t){return await s(async()=>{const i=(await this.backendApiClients.authApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:r(i.user)}},{context:"loginWithSMSOTP"})}async linkSMSOTP(e,t,i){return await s(async()=>{const a=(await this.backendApiClients.authApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e,updatePhoneNumber:!0}},{headers:{authorization:`Bearer ${i.token}`,"x-project-key":`${this.publishableKey}`}})).data;return{token:a.token,user:r(a.user)}},{context:"linkSMSOTP"})}async getSessionWithToken(e,t){return await s(async()=>(await this.backendApiClients.authApi.getSessionGet({disableCookieCache:t},{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})).data,{context:"getSessionWithToken"})}}export{d as AuthManager};
|
|
1
|
+
import{debugLog as e}from"../utils/debug.js";import{OPENFORT_AUTH_ERROR_CODES as t}from"../core/errors/authErrorCodes.js";import{ConfigurationError as i,OpenfortError as a}from"../core/errors/openfortError.js";import{withApiError as s}from"../core/errors/withApiError.js";import{AuthActionRequiredActions as n}from"../types/types.js";function r(e){if(!e)throw new a(t.INTERNAL_ERROR,"User data is missing");return{id:e.id||"",email:e.email,name:e.name??void 0,image:e.image??void 0,emailVerified:e.emailVerified,isAnonymous:e.isAnonymous,createdAt:e.createdAt,updatedAt:e.updatedAt,phoneNumber:e.phoneNumber,phoneNumberVerified:e.phoneNumberVerified,linkedAccounts:e.linkedAccounts}}function o(e){if(e)return{id:e.id,token:e.token,userId:e.userId,expiresAt:e.expiresAt,createdAt:e.createdAt,updatedAt:e.updatedAt}}class d{backendApiClientsInstance;publishableKeyInstance;setBackendApiClients(e,t){this.backendApiClientsInstance=e,this.publishableKeyInstance=t}get backendApiClients(){if(!this.backendApiClientsInstance)throw new i("Backend API clients not initialized");return this.backendApiClientsInstance}get publishableKey(){if(!this.publishableKeyInstance)throw new i("Publishable key not initialized");return this.publishableKeyInstance}buildAuthHeaders(e){return{"x-project-key":this.publishableKey,...e&&{authorization:`Bearer ${e}`}}}async initOAuth(e,t,i){return await s(async()=>(await this.backendApiClients.authApi.socialSignIn({socialSignInRequest:{provider:e,callbackURL:t,scopes:i?.scopes?.split(" "),disableRedirect:i?.skipBrowserRedirect??!1}},{headers:{"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async linkOAuthToAnonymous(e,t,i){return await s(async()=>(await this.backendApiClients.authApi.socialSignIn({socialSignInRequest:{provider:t,callbackURL:i}},{headers:{authorization:`Bearer ${e.token}`,"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async registerGuest(){return s(async()=>{const e=await this.backendApiClients.authApi.signInAnonymousPost({headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:r(e.data.user)}},{context:"registerGuest"})}async loginWithIdToken(e,t){const i={socialSignInRequest:{provider:e,idToken:{token:t}}};return await s(async()=>{const e=await this.backendApiClients.authApi.socialSignIn(i,{headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:r(e.data.user)}},{context:"loginWithIdToken"})}async authenticateThirdParty(e,t){const i={thirdPartyOAuthRequest:{provider:e,token:t}};return s(async()=>({userId:(await this.backendApiClients.userApi.thirdPartyV2(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data.id}),{context:"authenticateThirdParty"})}async initSIWE(e){const t={siweNoncePostRequest:{walletAddress:e}};return{address:e,nonce:(await s(async()=>this.backendApiClients.authApi.siweNoncePost(t,{headers:{"x-project-key":`${this.publishableKey}`}}),{context:"initSIWE"})).data.nonce}}async linkSIWE(e,t){const i={siweNoncePostRequest:{walletAddress:e}};return{address:e,nonce:(await s(async()=>this.backendApiClients.authApi.linkSiweNoncePost(i,{headers:t.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t.token,"x-auth-provider":t.thirdPartyProvider,"x-token-type":t.thirdPartyTokenType}:this.buildAuthHeaders(t.token)}),{context:"linkSIWE"})).data.nonce}}async authenticateSIWE(e,t,i,a,n){const o={siweVerifyPostRequest:{signature:e,walletAddress:n,message:t,walletClientType:i,connectorType:a}};return s(async()=>{const e=await this.backendApiClients.authApi.siweVerifyPost(o,{headers:{"x-project-key":`${this.publishableKey}`}}),t=e.data.user;return{token:e.data.token,user:r(t)}},{context:"authenticateSIWE"})}async loginEmailPassword(e,t){return s(async()=>{const i=(await this.backendApiClients.authApi.signInEmailPost({signInEmailPostRequest:{email:e,password:t}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:r(i.user)}},{context:"loginEmailPassword"})}async requestResetPassword(e,t){await s(async()=>{await this.backendApiClients.authApi.requestPasswordResetPost({forgetPasswordPostRequest:{email:e,redirectTo:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestResetPassword"})}async resetPassword(e,t){return s(async()=>{await this.backendApiClients.authApi.resetPasswordPost({resetPasswordPostRequest:{newPassword:e,token:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"resetPassword"})}async requestEmailVerification(e,t){await s(async()=>{await this.backendApiClients.authApi.sendVerificationEmailPost({sendVerificationEmailPostRequest:{email:e,callbackURL:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestEmailVerification"})}async verifyEmail(e,t){return s(async()=>{await this.backendApiClients.authApi.verifyEmailGet({token:e,callbackURL:t})},{context:"verifyEmail"})}async signupEmailPassword(e,t,i,a,o){return s(async()=>{const s=(await this.backendApiClients.authApi.signUpEmailPost({signUpEmailPostRequest:{email:e,password:t,name:i,callbackURL:a}},{headers:this.buildAuthHeaders(o)})).data;return null===s.token?{action:n.ACTION_VERIFY_EMAIL}:{token:s.token,user:r(s.user)}},{context:"signupEmailPassword"})}async validateCredentials(t,i){e("Validating credentials with token:",t.token);const a=await this.getSessionWithToken(t,i);return{token:a.session.token,user:r(a.user),session:o(a.session)}}async logout(e){return s(async()=>{await this.backendApiClients.authApi.signOutPost(void 0,{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})},{context:"logout"})}async getUser(e){return s(async()=>r((await this.backendApiClients.userApi.meV2({headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})).data),{context:"getUser"})}async linkOAuth(e,t,i,a){const n=a?.skipBrowserRedirect??!1,r={linkSocialPostRequest:{provider:t,callbackURL:i,scopes:a?.scopes?.split(" "),disableRedirect:n}},o=await s(async()=>this.backendApiClients.authApi.linkSocialPost(r,{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)}),{context:"linkOAuth"});return"undefined"!=typeof window&&!n&&o.data.url&&window.location.assign(o.data.url),o.data.url||""}async unlinkOAuth(e,t){const i={unlinkAccountPostRequest:{providerId:e}};return s(async()=>(await this.backendApiClients.authApi.unlinkAccountPost(i,{headers:t.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":t.token,"x-auth-provider":t.thirdPartyProvider,"x-token-type":t.thirdPartyTokenType}:this.buildAuthHeaders(t.token)})).data,{context:"unlinkOAuth"})}async addEmail(e,t,i){return s(async()=>(await this.backendApiClients.authApi.changeEmailPost({changeEmailPostRequest:{newEmail:e,callbackURL:t}},{headers:i.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:this.buildAuthHeaders(i.token)})).data,{context:"addEmail"})}async unlinkWallet(e,t,i){const a={linkSiweUnlinkPostRequest:{walletAddress:e,chaindId:t}};return s(async()=>(await this.backendApiClients.authApi.linkSiweUnlinkPost(a,{headers:i.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:this.buildAuthHeaders(i.token)})).data,{context:"unlinkWallet"})}async linkWallet(e,t,i,a,n,r,o){const d={siweVerifyPostRequest:{signature:e,message:t,walletAddress:n,chainId:r,walletClientType:i,connectorType:a}};return s(async()=>(await this.backendApiClients.authApi.linkSiweVerifyPost(d,{headers:o.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":o.token,"x-auth-provider":o.thirdPartyProvider,"x-token-type":o.thirdPartyTokenType}:this.buildAuthHeaders(o.token)})).data,{context:"linkWallet"})}async requestEmailOTP(e,t){const i={emailOtpSendVerificationOtpPostRequest:{email:e,type:t}};await s(async()=>(await this.backendApiClients.authApi.emailOtpSendVerificationOtpPost(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestEmailOTP"})}async verifyEmailOtp(e,t,i){await s(async()=>(await this.backendApiClients.authApi.emailOtpVerifyEmailPost({emailOtpVerifyEmailPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data,{context:"verifyEmailOtp"})}async loginWithEmailOTP(e,t,i){return await s(async()=>{const a=(await this.backendApiClients.authApi.signInEmailOtpPost({signInEmailOtpPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data;return{token:a.token,user:r(a.user)}},{context:"loginWithEmailOTP"})}async requestPhoneOtp(e){const t={phoneNumberSendOtpPostRequest:{phoneNumber:e}};await s(async()=>(await this.backendApiClients.authApi.phoneNumberSendOtpPost(t,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestPhoneOtp"})}async loginWithSMSOTP(e,t){return await s(async()=>{const i=(await this.backendApiClients.authApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:r(i.user)}},{context:"loginWithSMSOTP"})}async linkSMSOTP(e,t,i){return await s(async()=>{const a=(await this.backendApiClients.authApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e,updatePhoneNumber:!0}},{headers:{authorization:`Bearer ${i.token}`,"x-project-key":`${this.publishableKey}`}})).data;return{token:a.token,user:r(a.user)}},{context:"linkSMSOTP"})}async getSessionWithToken(e,t){return await s(async()=>(await this.backendApiClients.authApi.getSessionGet({disableCookieCache:t},{headers:e.thirdPartyProvider?{authorization:`Bearer ${this.publishableKey}`,"x-player-token":e.token,"x-auth-provider":e.thirdPartyProvider,"x-token-type":e.thirdPartyTokenType}:this.buildAuthHeaders(e.token)})).data,{context:"getSessionWithToken"})}}export{d as AuthManager};
|
package/dist/sdk/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="1.0
|
|
1
|
+
const o="1.1.0",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
|
package/package.json
CHANGED