@openfort/openfort-js 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +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 n(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}}function s(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.authenticationV2Api.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.authenticationV2Api.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.anonymousApi.signInAnonymousPost({headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:n(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.authenticationV2Api.socialSignIn(i,{headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:n(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.siweApi.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.siweApi.linkSiweNoncePost(i,{headers:{authorization:`Bearer ${t.token}`,"x-project-key":`${this.publishableKey}`}}),{context:"linkSIWE"})).data.nonce}}async authenticateSIWE(e,t,i,r,s){const o={siweVerifyPostRequest:{signature:e,walletAddress:s,message:t,walletClientType:i,connectorType:r}};return a.withApiError(async()=>{const e=await this.backendApiClients.siweApi.siweVerifyPost(o,{headers:{"x-project-key":`${this.publishableKey}`}}),t=e.data.user;return{token:e.data.token,user:n(t)}},{context:"authenticateSIWE"})}async loginEmailPassword(e,t){return a.withApiError(async()=>{const i=(await this.backendApiClients.authenticationV2Api.signInEmailPost({signInEmailPostRequest:{email:e,password:t}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:n(i.user)}},{context:"loginEmailPassword"})}async requestResetPassword(e,t){await a.withApiError(async()=>{await this.backendApiClients.authenticationV2Api.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.authenticationV2Api.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.authenticationV2Api.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.authenticationV2Api.verifyEmailGet({token:e,callbackURL:t})},{context:"verifyEmail"})}async signupEmailPassword(e,t,i,s,o){return a.withApiError(async()=>{const a=(await this.backendApiClients.authenticationV2Api.signUpEmailPost({signUpEmailPostRequest:{email:e,password:t,name:i,callbackURL:s}},{headers:this.buildAuthHeaders(o)})).data;return a.token?{token:a.token,user:n(a.user)}:{action:r.AuthActionRequiredActions.ACTION_VERIFY_EMAIL}},{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:n(a.user),session:s(a.session)}}async logout(e){return a.withApiError(async()=>{await this.backendApiClients.authenticationV2Api.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()=>n((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 listAccounts(e){return a.withApiError(async()=>(await this.backendApiClients.authenticationV2Api.listAccountsGet({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:"listAccounts"})}async linkOAuth(e,t,i,r){const n=r?.skipBrowserRedirect??!1,s={linkSocialPostRequest:{provider:t,callbackURL:i,scopes:r?.scopes?.split(" "),disableRedirect:n}},o=await a.withApiError(async()=>this.backendApiClients.authenticationV2Api.linkSocialPost(s,{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 a.withApiError(async()=>(await this.backendApiClients.authenticationV2Api.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.authenticationV2Api.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.siweApi.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,n,s,o){const h={siweVerifyPostRequest:{signature:e,message:t,walletAddress:n,chainId:s,walletClientType:i,connectorType:r}};return a.withApiError(async()=>(await this.backendApiClients.siweApi.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.emailOTPApi.emailOtpSendVerificationOtpPost(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestEmailOTP"})}async verifyEmailOtp(e,t,i){await a.withApiError(async()=>(await this.backendApiClients.emailOTPApi.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.emailOTPApi.signInEmailOtpPost({signInEmailOtpPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data;return{token:a.token,user:n(a.user)}},{context:"loginWithEmailOTP"})}async requestPhoneOtp(e){const t={phoneNumberSendOtpPostRequest:{phoneNumber:e}};await a.withApiError(async()=>(await this.backendApiClients.smsOTPApi.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.smsOTPApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:n(i.user)}},{context:"loginWithSMSOTP"})}async linkSMSOTP(e,t,i){return await a.withApiError(async()=>{const a=(await this.backendApiClients.smsOTPApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e,updatePhoneNumber:!0}},{headers:{authorization:`Bearer ${i.token}`,"x-project-key":`${this.publishableKey}`}})).data;return{token:a.token,user:n(a.user)}},{context:"linkSMSOTP"})}async getSessionWithToken(e,t){return await a.withApiError(async()=>(await this.backendApiClients.authenticationV2Api.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 n(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}}function s(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.authenticationV2Api.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.authenticationV2Api.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.anonymousApi.signInAnonymousPost({headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:n(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.authenticationV2Api.socialSignIn(i,{headers:{"x-project-key":`${this.publishableKey}`}});return{token:e.data.token,user:n(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.siweApi.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.siweApi.linkSiweNoncePost(i,{headers:{authorization:`Bearer ${t.token}`,"x-project-key":`${this.publishableKey}`}}),{context:"linkSIWE"})).data.nonce}}async authenticateSIWE(e,t,i,r,s){const o={siweVerifyPostRequest:{signature:e,walletAddress:s,message:t,walletClientType:i,connectorType:r}};return a.withApiError(async()=>{const e=await this.backendApiClients.siweApi.siweVerifyPost(o,{headers:{"x-project-key":`${this.publishableKey}`}}),t=e.data.user;return{token:e.data.token,user:n(t)}},{context:"authenticateSIWE"})}async loginEmailPassword(e,t){return a.withApiError(async()=>{const i=(await this.backendApiClients.authenticationV2Api.signInEmailPost({signInEmailPostRequest:{email:e,password:t}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:n(i.user)}},{context:"loginEmailPassword"})}async requestResetPassword(e,t){await a.withApiError(async()=>{await this.backendApiClients.authenticationV2Api.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.authenticationV2Api.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.authenticationV2Api.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.authenticationV2Api.verifyEmailGet({token:e,callbackURL:t})},{context:"verifyEmail"})}async signupEmailPassword(e,t,i,s,o){return a.withApiError(async()=>{const a=(await this.backendApiClients.authenticationV2Api.signUpEmailPost({signUpEmailPostRequest:{email:e,password:t,name:i,callbackURL:s}},{headers:this.buildAuthHeaders(o)})).data;return null===a.token?{action:r.AuthActionRequiredActions.ACTION_VERIFY_EMAIL}:{token:a.token,user:n(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:n(a.user),session:s(a.session)}}async logout(e){return a.withApiError(async()=>{await this.backendApiClients.authenticationV2Api.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()=>n((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 listAccounts(e){return a.withApiError(async()=>(await this.backendApiClients.authenticationV2Api.listAccountsGet({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:"listAccounts"})}async linkOAuth(e,t,i,r){const n=r?.skipBrowserRedirect??!1,s={linkSocialPostRequest:{provider:t,callbackURL:i,scopes:r?.scopes?.split(" "),disableRedirect:n}},o=await a.withApiError(async()=>this.backendApiClients.authenticationV2Api.linkSocialPost(s,{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 a.withApiError(async()=>(await this.backendApiClients.authenticationV2Api.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.authenticationV2Api.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.siweApi.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,n,s,o){const h={siweVerifyPostRequest:{signature:e,message:t,walletAddress:n,chainId:s,walletClientType:i,connectorType:r}};return a.withApiError(async()=>(await this.backendApiClients.siweApi.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.emailOTPApi.emailOtpSendVerificationOtpPost(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestEmailOTP"})}async verifyEmailOtp(e,t,i){await a.withApiError(async()=>(await this.backendApiClients.emailOTPApi.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.emailOTPApi.signInEmailOtpPost({signInEmailOtpPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data;return{token:a.token,user:n(a.user)}},{context:"loginWithEmailOTP"})}async requestPhoneOtp(e){const t={phoneNumberSendOtpPostRequest:{phoneNumber:e}};await a.withApiError(async()=>(await this.backendApiClients.smsOTPApi.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.smsOTPApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e}},{headers:{"x-project-key":`${this.publishableKey}`}})).data;return{token:i.token,user:n(i.user)}},{context:"loginWithSMSOTP"})}async linkSMSOTP(e,t,i){return await a.withApiError(async()=>{const a=(await this.backendApiClients.smsOTPApi.phoneNumberVerifyPost({phoneNumberVerifyPostRequest:{code:t,phoneNumber:e,updatePhoneNumber:!0}},{headers:{authorization:`Bearer ${i.token}`,"x-project-key":`${this.publishableKey}`}})).data;return{token:a.token,user:n(a.user)}},{context:"linkSMSOTP"})}async getSessionWithToken(e,t){return await a.withApiError(async()=>(await this.backendApiClients.authenticationV2Api.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.0";
1
+ "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.0.1";
@@ -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 n}from"../core/errors/withApiError.js";import{AuthActionRequiredActions as s}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}}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 n(async()=>(await this.backendApiClients.authenticationV2Api.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 n(async()=>(await this.backendApiClients.authenticationV2Api.socialSignIn({socialSignInRequest:{provider:t,callbackURL:i}},{headers:{authorization:`Bearer ${e.token}`,"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async registerGuest(){return n(async()=>{const e=await this.backendApiClients.anonymousApi.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 n(async()=>{const e=await this.backendApiClients.authenticationV2Api.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 n(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 n(async()=>this.backendApiClients.siweApi.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 n(async()=>this.backendApiClients.siweApi.linkSiweNoncePost(i,{headers:{authorization:`Bearer ${t.token}`,"x-project-key":`${this.publishableKey}`}}),{context:"linkSIWE"})).data.nonce}}async authenticateSIWE(e,t,i,a,s){const o={siweVerifyPostRequest:{signature:e,walletAddress:s,message:t,walletClientType:i,connectorType:a}};return n(async()=>{const e=await this.backendApiClients.siweApi.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 n(async()=>{const i=(await this.backendApiClients.authenticationV2Api.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 n(async()=>{await this.backendApiClients.authenticationV2Api.requestPasswordResetPost({forgetPasswordPostRequest:{email:e,redirectTo:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestResetPassword"})}async resetPassword(e,t){return n(async()=>{await this.backendApiClients.authenticationV2Api.resetPasswordPost({resetPasswordPostRequest:{newPassword:e,token:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"resetPassword"})}async requestEmailVerification(e,t){await n(async()=>{await this.backendApiClients.authenticationV2Api.sendVerificationEmailPost({sendVerificationEmailPostRequest:{email:e,callbackURL:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestEmailVerification"})}async verifyEmail(e,t){return n(async()=>{await this.backendApiClients.authenticationV2Api.verifyEmailGet({token:e,callbackURL:t})},{context:"verifyEmail"})}async signupEmailPassword(e,t,i,a,o){return n(async()=>{const n=(await this.backendApiClients.authenticationV2Api.signUpEmailPost({signUpEmailPostRequest:{email:e,password:t,name:i,callbackURL:a}},{headers:this.buildAuthHeaders(o)})).data;return n.token?{token:n.token,user:r(n.user)}:{action:s.ACTION_VERIFY_EMAIL}},{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 n(async()=>{await this.backendApiClients.authenticationV2Api.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 n(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 listAccounts(e){return n(async()=>(await this.backendApiClients.authenticationV2Api.listAccountsGet({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:"listAccounts"})}async linkOAuth(e,t,i,a){const s=a?.skipBrowserRedirect??!1,r={linkSocialPostRequest:{provider:t,callbackURL:i,scopes:a?.scopes?.split(" "),disableRedirect:s}},o=await n(async()=>this.backendApiClients.authenticationV2Api.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&&!s&&o.data.url&&window.location.assign(o.data.url),o.data.url||""}async unlinkOAuth(e,t){const i={unlinkAccountPostRequest:{providerId:e}};return n(async()=>(await this.backendApiClients.authenticationV2Api.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 n(async()=>(await this.backendApiClients.authenticationV2Api.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 n(async()=>(await this.backendApiClients.siweApi.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,s,r,o){const d={siweVerifyPostRequest:{signature:e,message:t,walletAddress:s,chainId:r,walletClientType:i,connectorType:a}};return n(async()=>(await this.backendApiClients.siweApi.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 n(async()=>(await this.backendApiClients.emailOTPApi.emailOtpSendVerificationOtpPost(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestEmailOTP"})}async verifyEmailOtp(e,t,i){await n(async()=>(await this.backendApiClients.emailOTPApi.emailOtpVerifyEmailPost({emailOtpVerifyEmailPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data,{context:"verifyEmailOtp"})}async loginWithEmailOTP(e,t,i){return await n(async()=>{const a=(await this.backendApiClients.emailOTPApi.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 n(async()=>(await this.backendApiClients.smsOTPApi.phoneNumberSendOtpPost(t,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestPhoneOtp"})}async loginWithSMSOTP(e,t){return await n(async()=>{const i=(await this.backendApiClients.smsOTPApi.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 n(async()=>{const a=(await this.backendApiClients.smsOTPApi.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 n(async()=>(await this.backendApiClients.authenticationV2Api.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 n}from"../core/errors/withApiError.js";import{AuthActionRequiredActions as s}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}}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 n(async()=>(await this.backendApiClients.authenticationV2Api.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 n(async()=>(await this.backendApiClients.authenticationV2Api.socialSignIn({socialSignInRequest:{provider:t,callbackURL:i}},{headers:{authorization:`Bearer ${e.token}`,"x-project-key":`${this.publishableKey}`}})).data.url||"",{context:"initOAuth"})}async registerGuest(){return n(async()=>{const e=await this.backendApiClients.anonymousApi.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 n(async()=>{const e=await this.backendApiClients.authenticationV2Api.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 n(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 n(async()=>this.backendApiClients.siweApi.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 n(async()=>this.backendApiClients.siweApi.linkSiweNoncePost(i,{headers:{authorization:`Bearer ${t.token}`,"x-project-key":`${this.publishableKey}`}}),{context:"linkSIWE"})).data.nonce}}async authenticateSIWE(e,t,i,a,s){const o={siweVerifyPostRequest:{signature:e,walletAddress:s,message:t,walletClientType:i,connectorType:a}};return n(async()=>{const e=await this.backendApiClients.siweApi.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 n(async()=>{const i=(await this.backendApiClients.authenticationV2Api.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 n(async()=>{await this.backendApiClients.authenticationV2Api.requestPasswordResetPost({forgetPasswordPostRequest:{email:e,redirectTo:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestResetPassword"})}async resetPassword(e,t){return n(async()=>{await this.backendApiClients.authenticationV2Api.resetPasswordPost({resetPasswordPostRequest:{newPassword:e,token:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"resetPassword"})}async requestEmailVerification(e,t){await n(async()=>{await this.backendApiClients.authenticationV2Api.sendVerificationEmailPost({sendVerificationEmailPostRequest:{email:e,callbackURL:t}},{headers:{"x-project-key":`${this.publishableKey}`}})},{context:"requestEmailVerification"})}async verifyEmail(e,t){return n(async()=>{await this.backendApiClients.authenticationV2Api.verifyEmailGet({token:e,callbackURL:t})},{context:"verifyEmail"})}async signupEmailPassword(e,t,i,a,o){return n(async()=>{const n=(await this.backendApiClients.authenticationV2Api.signUpEmailPost({signUpEmailPostRequest:{email:e,password:t,name:i,callbackURL:a}},{headers:this.buildAuthHeaders(o)})).data;return null===n.token?{action:s.ACTION_VERIFY_EMAIL}:{token:n.token,user:r(n.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 n(async()=>{await this.backendApiClients.authenticationV2Api.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 n(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 listAccounts(e){return n(async()=>(await this.backendApiClients.authenticationV2Api.listAccountsGet({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:"listAccounts"})}async linkOAuth(e,t,i,a){const s=a?.skipBrowserRedirect??!1,r={linkSocialPostRequest:{provider:t,callbackURL:i,scopes:a?.scopes?.split(" "),disableRedirect:s}},o=await n(async()=>this.backendApiClients.authenticationV2Api.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&&!s&&o.data.url&&window.location.assign(o.data.url),o.data.url||""}async unlinkOAuth(e,t){const i={unlinkAccountPostRequest:{providerId:e}};return n(async()=>(await this.backendApiClients.authenticationV2Api.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 n(async()=>(await this.backendApiClients.authenticationV2Api.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 n(async()=>(await this.backendApiClients.siweApi.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,s,r,o){const d={siweVerifyPostRequest:{signature:e,message:t,walletAddress:s,chainId:r,walletClientType:i,connectorType:a}};return n(async()=>(await this.backendApiClients.siweApi.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 n(async()=>(await this.backendApiClients.emailOTPApi.emailOtpSendVerificationOtpPost(i,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestEmailOTP"})}async verifyEmailOtp(e,t,i){await n(async()=>(await this.backendApiClients.emailOTPApi.emailOtpVerifyEmailPost({emailOtpVerifyEmailPostRequest:{email:e,otp:t}},{headers:this.buildAuthHeaders(i)})).data,{context:"verifyEmailOtp"})}async loginWithEmailOTP(e,t,i){return await n(async()=>{const a=(await this.backendApiClients.emailOTPApi.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 n(async()=>(await this.backendApiClients.smsOTPApi.phoneNumberSendOtpPost(t,{headers:{"x-project-key":`${this.publishableKey}`}})).data,{context:"requestPhoneOtp"})}async loginWithSMSOTP(e,t){return await n(async()=>{const i=(await this.backendApiClients.smsOTPApi.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 n(async()=>{const a=(await this.backendApiClients.smsOTPApi.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 n(async()=>(await this.backendApiClients.authenticationV2Api.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 +1 @@
1
- const o="1.0.0",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
1
+ const o="1.0.1",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "Openfort (https://www.openfort.io)",
5
5
  "bugs": "https://github.com/openfort-xyz/openfort-js/issues",
6
6
  "repository": "openfort-xyz/openfort-js.git",