@openfort/openfort-js 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/sdk/src/api/user.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 +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/sdk/src/api/user.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
|
|
1
|
+
"use strict";var r=require("../core/configuration/authentication.cjs"),e=require("../core/errors/authErrorCodes.cjs"),t=require("../core/errors/openfortError.cjs");exports.UserApi=class{storage;authManager;validateAndRefreshToken;constructor(r,e,t){this.storage=r,this.authManager=e,this.validateAndRefreshToken=t}async get(){await this.validateAndRefreshToken();const a=await r.Authentication.fromStorage(this.storage);if(!a)throw new t.SessionError(e.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");return await this.authManager.getUser(a)}};
|
|
@@ -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,linkedAccounts:e.linkedAccounts}}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 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.
|
|
1
|
+
"use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.0.2";
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PasskeyDetails } from 'wallets/types';
|
|
2
2
|
import { PasskeyHandler as PasskeyHandler$1 } from 'core/configuration/passkey';
|
|
3
3
|
import { User as User$2, ThirdPartyOAuthProvider as ThirdPartyOAuthProvider$1 } from 'types';
|
|
4
|
-
import { UserAccount } from 'types/types';
|
|
5
4
|
import { Account } from 'core/configuration/account';
|
|
6
5
|
import { Hex } from 'wallets/evm/types';
|
|
7
6
|
|
|
@@ -11276,6 +11275,8 @@ interface User {
|
|
|
11276
11275
|
phoneNumber?: string;
|
|
11277
11276
|
/** Whether the user's phone number has been verified */
|
|
11278
11277
|
phoneNumberVerified?: boolean;
|
|
11278
|
+
/** List of user linked accounts */
|
|
11279
|
+
linkedAccounts?: ListAccountsGet200ResponseInner[];
|
|
11279
11280
|
}
|
|
11280
11281
|
/**
|
|
11281
11282
|
* Session information
|
|
@@ -11496,7 +11497,6 @@ declare class AuthManager {
|
|
|
11496
11497
|
validateCredentials(authentication: Authentication, _forceRefresh?: boolean): Promise<AuthResponse>;
|
|
11497
11498
|
logout(auth: Authentication): Promise<void>;
|
|
11498
11499
|
getUser(auth: Authentication): Promise<User>;
|
|
11499
|
-
listAccounts(auth: Authentication): Promise<ListAccountsGet200ResponseInner[]>;
|
|
11500
11500
|
linkOAuth(auth: Authentication, provider: OAuthProvider, redirectTo: string, options?: InitializeOAuthOptions): Promise<string>;
|
|
11501
11501
|
unlinkOAuth(provider: OAuthProvider, auth: Authentication): Promise<UnlinkAccountResponse>;
|
|
11502
11502
|
addEmail(email: string, callbackURL: string, auth: Authentication): Promise<ChangeEmailPost200Response>;
|
|
@@ -11725,7 +11725,6 @@ declare class UserApi {
|
|
|
11725
11725
|
private validateAndRefreshToken;
|
|
11726
11726
|
constructor(storage: IStorage, authManager: AuthManager, validateAndRefreshToken: () => Promise<void>);
|
|
11727
11727
|
get(): Promise<User$2>;
|
|
11728
|
-
list(): Promise<UserAccount[]>;
|
|
11729
11728
|
}
|
|
11730
11729
|
|
|
11731
11730
|
interface SDKOverrides {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { PasskeyDetails } from 'wallets/types';
|
|
2
2
|
import { PasskeyHandler as PasskeyHandler$1 } from 'core/configuration/passkey';
|
|
3
3
|
import { User as User$2, ThirdPartyOAuthProvider as ThirdPartyOAuthProvider$1 } from 'types';
|
|
4
|
-
import { UserAccount } from 'types/types';
|
|
5
4
|
import { Account } from 'core/configuration/account';
|
|
6
5
|
import { Hex } from 'wallets/evm/types';
|
|
7
6
|
|
|
@@ -11276,6 +11275,8 @@ interface User {
|
|
|
11276
11275
|
phoneNumber?: string;
|
|
11277
11276
|
/** Whether the user's phone number has been verified */
|
|
11278
11277
|
phoneNumberVerified?: boolean;
|
|
11278
|
+
/** List of user linked accounts */
|
|
11279
|
+
linkedAccounts?: ListAccountsGet200ResponseInner[];
|
|
11279
11280
|
}
|
|
11280
11281
|
/**
|
|
11281
11282
|
* Session information
|
|
@@ -11496,7 +11497,6 @@ declare class AuthManager {
|
|
|
11496
11497
|
validateCredentials(authentication: Authentication, _forceRefresh?: boolean): Promise<AuthResponse>;
|
|
11497
11498
|
logout(auth: Authentication): Promise<void>;
|
|
11498
11499
|
getUser(auth: Authentication): Promise<User>;
|
|
11499
|
-
listAccounts(auth: Authentication): Promise<ListAccountsGet200ResponseInner[]>;
|
|
11500
11500
|
linkOAuth(auth: Authentication, provider: OAuthProvider, redirectTo: string, options?: InitializeOAuthOptions): Promise<string>;
|
|
11501
11501
|
unlinkOAuth(provider: OAuthProvider, auth: Authentication): Promise<UnlinkAccountResponse>;
|
|
11502
11502
|
addEmail(email: string, callbackURL: string, auth: Authentication): Promise<ChangeEmailPost200Response>;
|
|
@@ -11725,7 +11725,6 @@ declare class UserApi {
|
|
|
11725
11725
|
private validateAndRefreshToken;
|
|
11726
11726
|
constructor(storage: IStorage, authManager: AuthManager, validateAndRefreshToken: () => Promise<void>);
|
|
11727
11727
|
get(): Promise<User$2>;
|
|
11728
|
-
list(): Promise<UserAccount[]>;
|
|
11729
11728
|
}
|
|
11730
11729
|
|
|
11731
11730
|
interface SDKOverrides {
|
package/dist/sdk/src/api/user.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Authentication as
|
|
1
|
+
import{Authentication as r}from"../core/configuration/authentication.js";import{OPENFORT_AUTH_ERROR_CODES as t}from"../core/errors/authErrorCodes.js";import{SessionError as e}from"../core/errors/openfortError.js";class o{storage;authManager;validateAndRefreshToken;constructor(r,t,e){this.storage=r,this.authManager=t,this.validateAndRefreshToken=e}async get(){await this.validateAndRefreshToken();const o=await r.fromStorage(this.storage);if(!o)throw new e(t.NOT_LOGGED_IN,"No access token found");return await this.authManager.getUser(o)}}export{o as UserApi};
|
|
@@ -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,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 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 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};
|
package/dist/sdk/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="1.0.
|
|
1
|
+
const o="1.0.2",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
|
package/package.json
CHANGED