@openfort/openfort-js 0.10.2 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var t=require("../utils/debug.js"),e=require("../core/configuration/authentication.js"),a=require("../core/errors/openfortError.js"),i=require("../types/types.js");exports.AuthApi=class{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,a,i,r){this.storage=t,this.authManager=e,this.validateAndRefreshToken=a,this.ensureInitialized=i,this.eventEmitter=r}async logInWithEmailPassword({email:t,password:i,ecosystemGame:r}){await this.ensureInitialized();if(await e.Authentication.fromStorage(this.storage))throw new a.OpenfortError("Already logged in",a.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const n=await this.authManager.loginEmailPassword(t,i,r);return"action"in n||new e.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async signUpGuest(){await this.ensureInitialized();if(await e.Authentication.fromStorage(this.storage))throw new a.OpenfortError("Already logged in",a.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const t=await this.authManager.registerGuest();return new e.Authentication("jwt",t.token,t.player.id,t.refreshToken).save(this.storage),t}async signUpWithEmailPassword({email:t,password:i,options:r,ecosystemGame:n}){await this.ensureInitialized();if(await e.Authentication.fromStorage(this.storage))throw new a.OpenfortError("Already logged in",a.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const s=await this.authManager.signupEmailPassword(t,i,r?.data.name,n);return"action"in s||new e.Authentication("jwt",s.token,s.player.id,s.refreshToken).save(this.storage),s}async linkEmailPassword({email:t,password:e,authToken:a,ecosystemGame:i}){return await this.validateAndRefreshToken(),await this.authManager.linkEmail(t,e,a,i)}async unlinkEmailPassword({email:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkEmail(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async resetPassword({email:t,password:e,state:a}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e,a)}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async verifyEmail({email:t,state:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async initOAuth({provider:t,options:i,ecosystemGame:r}){await this.ensureInitialized();if(await e.Authentication.fromStorage(this.storage))throw new a.OpenfortError("Already logged in",a.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);return await this.authManager.initOAuth(t,i,r)}async initLinkOAuth({provider:t,options:i,ecosystemGame:r}){await this.validateAndRefreshToken();const n=await e.Authentication.fromStorage(this.storage);if(!n)throw new a.OpenfortError("No authentication found",a.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(n,t,i,r)}async linkThirdPartyProvider({provider:t,token:i,tokenType:r}){await this.validateAndRefreshToken();const n=await e.Authentication.fromStorage(this.storage);if(!n)throw new a.OpenfortError("No authentication found",a.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkThirdParty(n,t,i,r)}async unlinkOAuth({provider:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkOAuth(t,e)}async poolOAuth(t){await this.ensureInitialized();const a=await this.authManager.poolOAuth(t);return new e.Authentication("jwt",a.token,a.player.id,a.refreshToken).save(this.storage),a}async authenticateWithThirdPartyProvider(){t.debugLog("Authenticating with third party provider"),await this.ensureInitialized(),await this.validateAndRefreshToken();const i=await e.Authentication.fromStorage(this.storage);if(!i)throw new a.OpenfortError("No access token found",a.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.getUser(i)}async loginWithIdToken({provider:t,token:i,ecosystemGame:r}){await this.ensureInitialized();if(await e.Authentication.fromStorage(this.storage))throw new a.OpenfortError("Already logged in",a.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const n=await this.authManager.loginWithIdToken(t,i,r);return new e.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async initSIWE({address:t,ecosystemGame:e}){return await this.ensureInitialized(),await this.authManager.initSIWE(t,e)}async authenticateWithSIWE({signature:t,message:i,walletClientType:r,connectorType:n}){await this.ensureInitialized();if(await e.Authentication.fromStorage(this.storage))throw new a.OpenfortError("Already logged in",a.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const s=await this.authManager.authenticateSIWE(t,i,r,n);return new e.Authentication("jwt",s.token,s.player.id,s.refreshToken).save(this.storage),s}async linkWallet({signature:t,message:e,walletClientType:a,connectorType:i,authToken:r}){return await this.validateAndRefreshToken(),await this.authManager.linkWallet(t,e,a,i,r)}async unlinkWallet({address:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkWallet(t,e)}async storeCredentials(t){if(await this.ensureInitialized(),!t.player)throw new a.OpenfortError("Player ID is required to store credentials",a.OpenfortErrorType.INVALID_CONFIGURATION);new e.Authentication("jwt",t.accessToken,t.player,t.refreshToken).save(this.storage)}async logout(){const t=await e.Authentication.fromStorage(this.storage);if(t){try{"third_party"!==t.type&&await this.authManager.logout(t.token,t?.refreshToken)}catch(t){}e.Authentication.clear(this.storage),this.eventEmitter.emit(i.OpenfortEvents.LOGGED_OUT)}}};
1
+ "use strict";var t=require("../core/configuration/authentication.js"),e=require("../core/errors/openfortError.js"),a=require("../types/types.js");exports.AuthApi=class{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,a,i,r){this.storage=t,this.authManager=e,this.validateAndRefreshToken=a,this.ensureInitialized=i,this.eventEmitter=r}async logInWithEmailPassword({email:a,password:i,ecosystemGame:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const n=await this.authManager.loginEmailPassword(a,i,r);return"action"in n||new t.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async signUpGuest(){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const a=await this.authManager.registerGuest();return new t.Authentication("jwt",a.token,a.player.id,a.refreshToken).save(this.storage),a}async signUpWithEmailPassword({email:a,password:i,options:r,ecosystemGame:n}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const s=await this.authManager.signupEmailPassword(a,i,r?.data.name,n);return"action"in s||new t.Authentication("jwt",s.token,s.player.id,s.refreshToken).save(this.storage),s}async linkEmailPassword({email:t,password:e,authToken:a,ecosystemGame:i}){return await this.validateAndRefreshToken(),await this.authManager.linkEmail(t,e,a,i)}async unlinkEmailPassword({email:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkEmail(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async resetPassword({email:t,password:e,state:a}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e,a)}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async verifyEmail({email:t,state:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async initOAuth({provider:a,options:i,ecosystemGame:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);return await this.authManager.initOAuth(a,i,r)}async initLinkOAuth({provider:a,options:i,ecosystemGame:r}){await this.validateAndRefreshToken();const n=await t.Authentication.fromStorage(this.storage);if(!n)throw new e.OpenfortError("No authentication found",e.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(n,a,i,r)}async unlinkOAuth({provider:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkOAuth(t,e)}async poolOAuth(e){await this.ensureInitialized();const a=await this.authManager.poolOAuth(e);return new t.Authentication("jwt",a.token,a.player.id,a.refreshToken).save(this.storage),a}async loginWithIdToken({provider:a,token:i,ecosystemGame:r}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const n=await this.authManager.loginWithIdToken(a,i,r);return new t.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async initSIWE({address:t,ecosystemGame:e}){return await this.ensureInitialized(),await this.authManager.initSIWE(t,e)}async authenticateWithSIWE({signature:a,message:i,walletClientType:r,connectorType:n}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);const s=await this.authManager.authenticateSIWE(a,i,r,n);return new t.Authentication("jwt",s.token,s.player.id,s.refreshToken).save(this.storage),s}async linkWallet({signature:t,message:e,walletClientType:a,connectorType:i,authToken:r}){return await this.validateAndRefreshToken(),await this.authManager.linkWallet(t,e,a,i,r)}async unlinkWallet({address:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkWallet(t,e)}async storeCredentials(a){if(await this.ensureInitialized(),!a.player)throw new e.OpenfortError("Player ID is required to store credentials",e.OpenfortErrorType.INVALID_CONFIGURATION);new t.Authentication("jwt",a.accessToken,a.player,a.refreshToken).save(this.storage)}async logout(){const e=await t.Authentication.fromStorage(this.storage);if(e){try{"third_party"!==e.type&&await this.authManager.logout(e.token,e?.refreshToken)}catch(t){}t.Authentication.clear(this.storage),this.eventEmitter.emit(a.OpenfortEvents.LOGGED_OUT)}}};
@@ -1 +1 @@
1
- "use strict";var e=require("../../utils/crypto.js");class i{baseConfiguration;shieldConfiguration;shieldUrl;iframeUrl;backendUrl;storage;getAccessToken;thirdPartyAuthProvider;static instance=null;constructor({baseConfiguration:t,shieldConfiguration:s,overrides:r}){this.shieldConfiguration=s,this.baseConfiguration=t,this.backendUrl=r?.backendUrl||"https://api.openfort.io",this.iframeUrl=r?.iframeUrl||"https://embed.openfort.io",this.iframeUrl=`${this.iframeUrl}/iframe/${this.baseConfiguration.publishableKey}`,s?.debug&&(this.iframeUrl=`${this.iframeUrl}?debug=true`),this.shieldUrl=r?.shieldUrl||"https://shield.openfort.io",this.storage=r?.storage,this.getAccessToken=r?.getAccessToken,this.thirdPartyAuthProvider=r?.thirdPartyAuthProvider,r?.crypto?.digest&&e.setCryptoDigestOverride(r.crypto.digest),i.instance=this}static getInstance(){return i.instance}}exports.OpenfortConfiguration=class{publishableKey;constructor(e){this.publishableKey=e.publishableKey}},exports.SDKConfiguration=i,exports.ShieldConfiguration=class{shieldPublishableKey;shieldEncryptionKey;debug=!1;constructor(e){this.shieldPublishableKey=e.shieldPublishableKey,this.shieldEncryptionKey=e.shieldEncryptionKey,this.debug=e.shieldDebug||!1}};
1
+ "use strict";var i=require("../../utils/crypto.js");class t{baseConfiguration;shieldConfiguration;thirdPartyAuth;shieldUrl;iframeUrl;backendUrl;storage;static instance=null;constructor({baseConfiguration:e,shieldConfiguration:s,overrides:r,thirdPartyAuth:o}){this.shieldConfiguration=s,this.baseConfiguration=e,this.backendUrl=r?.backendUrl||"https://api.openfort.io",this.iframeUrl=r?.iframeUrl||"https://embed.openfort.io",this.iframeUrl=`${this.iframeUrl}/iframe/${this.baseConfiguration.publishableKey}`,s?.debug&&(this.iframeUrl=`${this.iframeUrl}?debug=true`),this.shieldUrl=r?.shieldUrl||"https://shield.openfort.io",this.storage=r?.storage,this.thirdPartyAuth=o,r?.crypto?.digest&&i.setCryptoDigestOverride(r.crypto.digest),t.instance=this}static getInstance(){return t.instance}}exports.OpenfortConfiguration=class{publishableKey;constructor(i){this.publishableKey=i.publishableKey}},exports.SDKConfiguration=t,exports.ShieldConfiguration=class{shieldPublishableKey;shieldEncryptionKey;debug=!1;constructor(i){this.shieldPublishableKey=i.shieldPublishableKey,this.shieldEncryptionKey=i.shieldEncryptionKey,this.debug=i.shieldDebug||!1}};
@@ -1 +1 @@
1
- "use strict";var e=require("./errors/openfortError.js"),t=require("../types/types.js");require("../storage/istorage.js"),require("../wallets/messaging/browserMessenger/backwardCompatibility.js");var r=require("../utils/debug.js"),n=require("./configuration/authentication.js");require("../wallets/types.js"),require("./errors/sentry.js");var i=require("./config/config.js");require("jose"),require("../wallets/evm/types.js"),require("../wallets/evm/JsonRpcError.js"),require("eventemitter3"),require("../wallets/evm/provider/eip6963.js");exports.OpenfortInternal=class{storage;authManager;eventEmitter;constructor(e,t,r){this.storage=e,this.authManager=t,this.eventEmitter=r}async getAccessToken(){return(await n.Authentication.fromStorage(this.storage))?.token??null}async saveThirdPartyAuth(){const r=i.SDKConfiguration.getInstance();if(!r)throw new e.OpenfortError("No SDK configuration",e.OpenfortErrorType.INTERNAL_ERROR);const{getAccessToken:o,thirdPartyAuthProvider:a}=r;if(!o||!a)throw new e.OpenfortError("Third party is not configured. Please configure getAccessToken and thirdPartyAuthProvider in your Openfort instance",e.OpenfortErrorType.INVALID_CONFIGURATION);const s=await o();if(!s)throw new e.OpenfortError("Could not get access token",e.OpenfortErrorType.AUTHENTICATION_ERROR);let u=(await n.Authentication.fromStorage(this.storage))?.player;if(!u){const e=await this.authManager.authenticateThirdParty(a,s,t.TokenType.ID_TOKEN);u=e?.id}new n.Authentication("third_party",s,u,null,a,t.TokenType.ID_TOKEN).save(this.storage),this.eventEmitter.emit(t.OpenfortEvents.TOKEN_REFRESHED)}async validateAndRefreshToken(o){if(i.SDKConfiguration.getInstance()?.thirdPartyAuthProvider)return void await this.saveThirdPartyAuth();const a=await n.Authentication.fromStorage(this.storage);if(!a)throw new e.OpenfortError("Must be logged in to validate and refresh token",e.OpenfortErrorType.NOT_LOGGED_IN_ERROR);let s;r.debugLog("validating credentials...");try{s=await this.authManager.validateCredentials(a,o)}catch(e){throw n.Authentication.clear(this.storage),this.eventEmitter.emit(t.OpenfortEvents.LOGGED_OUT),e}if(!s.player)throw new e.OpenfortError("No user found in credentials",e.OpenfortErrorType.INTERNAL_ERROR);s.accessToken!==a.token&&(r.debugLog("tokens refreshed"),new n.Authentication("jwt",s.accessToken,s.player,s.refreshToken).save(this.storage),this.eventEmitter.emit(t.OpenfortEvents.TOKEN_REFRESHED))}};
1
+ "use strict";var e=require("./errors/openfortError.js"),t=require("../types/types.js");require("../storage/istorage.js"),require("../wallets/messaging/browserMessenger/backwardCompatibility.js");var r=require("../utils/debug.js"),n=require("./configuration/authentication.js");require("../wallets/types.js"),require("./errors/sentry.js");var i=require("./config/config.js");require("jose"),require("../wallets/evm/types.js"),require("../wallets/evm/JsonRpcError.js"),require("eventemitter3"),require("../wallets/evm/provider/eip6963.js");exports.OpenfortInternal=class{storage;authManager;eventEmitter;constructor(e,t,r){this.storage=e,this.authManager=t,this.eventEmitter=r}async getThirdPartyAuthToken(){const r=i.SDKConfiguration.getInstance();if(!r?.thirdPartyAuth)throw new e.OpenfortError("No third party configuration found",e.OpenfortErrorType.INTERNAL_ERROR);const{getAccessToken:o,provider:a}=r.thirdPartyAuth;if(!o||!a)throw new e.OpenfortError("Third party is not configured. Please configure getAccessToken and thirdPartyAuthProvider in your Openfort instance",e.OpenfortErrorType.INVALID_CONFIGURATION);const s=await o();if(!s)throw new e.OpenfortError("Could not get access token",e.OpenfortErrorType.AUTHENTICATION_ERROR);let h=(await n.Authentication.fromStorage(this.storage))?.player;if(!h){const e=await this.authManager.authenticateThirdParty(a,s,t.TokenType.ID_TOKEN);h=e?.id}return new n.Authentication("third_party",s,h,null,a,t.TokenType.ID_TOKEN).save(this.storage),this.eventEmitter.emit(t.OpenfortEvents.TOKEN_REFRESHED),s}async getAccessToken(){if(i.SDKConfiguration.getInstance()?.thirdPartyAuth)return this.getThirdPartyAuthToken();return(await n.Authentication.fromStorage(this.storage))?.token??null}async validateAndRefreshToken(o){if(i.SDKConfiguration.getInstance()?.thirdPartyAuth)return void await this.getThirdPartyAuthToken();const a=await n.Authentication.fromStorage(this.storage);if(!a)throw new e.OpenfortError("Must be logged in to validate and refresh token",e.OpenfortErrorType.NOT_LOGGED_IN_ERROR);let s;r.debugLog("validating credentials...");try{s=await this.authManager.validateCredentials(a,o)}catch(e){throw n.Authentication.clear(this.storage),this.eventEmitter.emit(t.OpenfortEvents.LOGGED_OUT),e}if(!s.player)throw new e.OpenfortError("No user found in credentials",e.OpenfortErrorType.INTERNAL_ERROR);s.accessToken!==a.token&&(r.debugLog("tokens refreshed"),new n.Authentication("jwt",s.accessToken,s.player,s.refreshToken).save(this.storage),this.eventEmitter.emit(t.OpenfortEvents.TOKEN_REFRESHED))}};
@@ -1 +1 @@
1
- "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="0.10.2";
1
+ "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="0.10.3";
package/dist/index.d.ts CHANGED
@@ -448,8 +448,10 @@ interface SDKOverrides {
448
448
  digest?: (algorithm: string, data: BufferSource) => Promise<ArrayBuffer>;
449
449
  };
450
450
  storage?: IStorage;
451
- getAccessToken?: () => Promise<string | null>;
452
- thirdPartyAuthProvider?: ThirdPartyOAuthProvider$1;
451
+ }
452
+ interface ThirdPartyAuthConfiguration {
453
+ provider: ThirdPartyOAuthProvider$1;
454
+ getAccessToken: () => Promise<string | null>;
453
455
  }
454
456
  declare class OpenfortConfiguration {
455
457
  readonly publishableKey: string;
@@ -472,18 +474,18 @@ type OpenfortSDKConfiguration = {
472
474
  baseConfiguration: OpenfortConfiguration;
473
475
  shieldConfiguration?: ShieldConfiguration;
474
476
  overrides?: SDKOverrides;
477
+ thirdPartyAuth?: ThirdPartyAuthConfiguration;
475
478
  };
476
479
  declare class SDKConfiguration {
477
480
  readonly baseConfiguration: OpenfortConfiguration;
478
481
  readonly shieldConfiguration?: ShieldConfiguration;
482
+ readonly thirdPartyAuth?: ThirdPartyAuthConfiguration;
479
483
  readonly shieldUrl: string;
480
484
  readonly iframeUrl: string;
481
485
  readonly backendUrl: string;
482
486
  readonly storage?: IStorage;
483
- readonly getAccessToken?: () => Promise<string | null>;
484
- readonly thirdPartyAuthProvider?: ThirdPartyOAuthProvider$1;
485
487
  static instance: SDKConfiguration | null;
486
- constructor({ baseConfiguration, shieldConfiguration, overrides, }: OpenfortSDKConfiguration);
488
+ constructor({ baseConfiguration, shieldConfiguration, overrides, thirdPartyAuth, }: OpenfortSDKConfiguration);
487
489
  static getInstance(): SDKConfiguration | null;
488
490
  }
489
491
 
@@ -7200,21 +7202,11 @@ declare class AuthApi {
7200
7202
  options?: InitializeOAuthOptions;
7201
7203
  ecosystemGame?: string;
7202
7204
  }): Promise<InitAuthResponse>;
7203
- linkThirdPartyProvider({ provider, token, tokenType, }: {
7204
- provider: ThirdPartyAuthProvider;
7205
- token: string;
7206
- tokenType: TokenType$1;
7207
- }): Promise<AuthPlayerResponse$1>;
7208
7205
  unlinkOAuth({ provider, authToken }: {
7209
7206
  provider: OAuthProvider$1;
7210
7207
  authToken: string;
7211
7208
  }): Promise<AuthPlayerResponse$1>;
7212
7209
  poolOAuth(key: string): Promise<AuthResponse$1>;
7213
- /**
7214
- * Authenticates the user with a third party provider.
7215
- * Set up the third party auth provider in the SDK configuration.
7216
- */
7217
- authenticateWithThirdPartyProvider(): Promise<AuthPlayerResponse$1>;
7218
7210
  loginWithIdToken({ provider, token, ecosystemGame, }: {
7219
7211
  provider: OAuthProvider$1;
7220
7212
  token: string;
@@ -7392,8 +7384,8 @@ declare class OpenfortInternal {
7392
7384
  private authManager;
7393
7385
  private eventEmitter;
7394
7386
  constructor(storage: IStorage, authManager: AuthManager, eventEmitter: TypedEventEmitter<OpenfortEventMap>);
7387
+ getThirdPartyAuthToken(): Promise<string>;
7395
7388
  getAccessToken(): Promise<string | null>;
7396
- saveThirdPartyAuth(): Promise<void>;
7397
7389
  /**
7398
7390
  * Validates and refreshes the access token if needed.
7399
7391
  */
@@ -1 +1 @@
1
- import{debugLog as t}from"../utils/debug.js";import{Authentication as a}from"../core/configuration/authentication.js";import{OpenfortError as e,OpenfortErrorType as i}from"../core/errors/openfortError.js";import{OpenfortEvents as r}from"../types/types.js";class s{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,a,e,i,r){this.storage=t,this.authManager=a,this.validateAndRefreshToken=e,this.ensureInitialized=i,this.eventEmitter=r}async logInWithEmailPassword({email:t,password:r,ecosystemGame:s}){await this.ensureInitialized();if(await a.fromStorage(this.storage))throw new e("Already logged in",i.ALREADY_LOGGED_IN_ERROR);const n=await this.authManager.loginEmailPassword(t,r,s);return"action"in n||new a("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async signUpGuest(){await this.ensureInitialized();if(await a.fromStorage(this.storage))throw new e("Already logged in",i.ALREADY_LOGGED_IN_ERROR);const t=await this.authManager.registerGuest();return new a("jwt",t.token,t.player.id,t.refreshToken).save(this.storage),t}async signUpWithEmailPassword({email:t,password:r,options:s,ecosystemGame:n}){await this.ensureInitialized();if(await a.fromStorage(this.storage))throw new e("Already logged in",i.ALREADY_LOGGED_IN_ERROR);const o=await this.authManager.signupEmailPassword(t,r,s?.data.name,n);return"action"in o||new a("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkEmailPassword({email:t,password:a,authToken:e,ecosystemGame:i}){return await this.validateAndRefreshToken(),await this.authManager.linkEmail(t,a,e,i)}async unlinkEmailPassword({email:t,authToken:a}){return await this.validateAndRefreshToken(),await this.authManager.unlinkEmail(t,a)}async requestEmailVerification({email:t,redirectUrl:a}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,a)}async resetPassword({email:t,password:a,state:e}){await this.ensureInitialized(),await this.authManager.resetPassword(t,a,e)}async requestResetPassword({email:t,redirectUrl:a}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,a)}async verifyEmail({email:t,state:a}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,a)}async initOAuth({provider:t,options:r,ecosystemGame:s}){await this.ensureInitialized();if(await a.fromStorage(this.storage))throw new e("Already logged in",i.ALREADY_LOGGED_IN_ERROR);return await this.authManager.initOAuth(t,r,s)}async initLinkOAuth({provider:t,options:r,ecosystemGame:s}){await this.validateAndRefreshToken();const n=await a.fromStorage(this.storage);if(!n)throw new e("No authentication found",i.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(n,t,r,s)}async linkThirdPartyProvider({provider:t,token:r,tokenType:s}){await this.validateAndRefreshToken();const n=await a.fromStorage(this.storage);if(!n)throw new e("No authentication found",i.NOT_LOGGED_IN_ERROR);return await this.authManager.linkThirdParty(n,t,r,s)}async unlinkOAuth({provider:t,authToken:a}){return await this.validateAndRefreshToken(),await this.authManager.unlinkOAuth(t,a)}async poolOAuth(t){await this.ensureInitialized();const e=await this.authManager.poolOAuth(t);return new a("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),e}async authenticateWithThirdPartyProvider(){t("Authenticating with third party provider"),await this.ensureInitialized(),await this.validateAndRefreshToken();const r=await a.fromStorage(this.storage);if(!r)throw new e("No access token found",i.NOT_LOGGED_IN_ERROR);return await this.authManager.getUser(r)}async loginWithIdToken({provider:t,token:r,ecosystemGame:s}){await this.ensureInitialized();if(await a.fromStorage(this.storage))throw new e("Already logged in",i.ALREADY_LOGGED_IN_ERROR);const n=await this.authManager.loginWithIdToken(t,r,s);return new a("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async initSIWE({address:t,ecosystemGame:a}){return await this.ensureInitialized(),await this.authManager.initSIWE(t,a)}async authenticateWithSIWE({signature:t,message:r,walletClientType:s,connectorType:n}){await this.ensureInitialized();if(await a.fromStorage(this.storage))throw new e("Already logged in",i.ALREADY_LOGGED_IN_ERROR);const o=await this.authManager.authenticateSIWE(t,r,s,n);return new a("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkWallet({signature:t,message:a,walletClientType:e,connectorType:i,authToken:r}){return await this.validateAndRefreshToken(),await this.authManager.linkWallet(t,a,e,i,r)}async unlinkWallet({address:t,authToken:a}){return await this.validateAndRefreshToken(),await this.authManager.unlinkWallet(t,a)}async storeCredentials(t){if(await this.ensureInitialized(),!t.player)throw new e("Player ID is required to store credentials",i.INVALID_CONFIGURATION);new a("jwt",t.accessToken,t.player,t.refreshToken).save(this.storage)}async logout(){const t=await a.fromStorage(this.storage);if(t){try{"third_party"!==t.type&&await this.authManager.logout(t.token,t?.refreshToken)}catch(t){}a.clear(this.storage),this.eventEmitter.emit(r.LOGGED_OUT)}}}export{s as AuthApi};
1
+ import{Authentication as e}from"../core/configuration/authentication.js";import{OpenfortError as a,OpenfortErrorType as t}from"../core/errors/openfortError.js";import{OpenfortEvents as i}from"../types/types.js";class s{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(e,a,t,i,s){this.storage=e,this.authManager=a,this.validateAndRefreshToken=t,this.ensureInitialized=i,this.eventEmitter=s}async logInWithEmailPassword({email:i,password:s,ecosystemGame:r}){await this.ensureInitialized();if(await e.fromStorage(this.storage))throw new a("Already logged in",t.ALREADY_LOGGED_IN_ERROR);const n=await this.authManager.loginEmailPassword(i,s,r);return"action"in n||new e("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async signUpGuest(){await this.ensureInitialized();if(await e.fromStorage(this.storage))throw new a("Already logged in",t.ALREADY_LOGGED_IN_ERROR);const i=await this.authManager.registerGuest();return new e("jwt",i.token,i.player.id,i.refreshToken).save(this.storage),i}async signUpWithEmailPassword({email:i,password:s,options:r,ecosystemGame:n}){await this.ensureInitialized();if(await e.fromStorage(this.storage))throw new a("Already logged in",t.ALREADY_LOGGED_IN_ERROR);const o=await this.authManager.signupEmailPassword(i,s,r?.data.name,n);return"action"in o||new e("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkEmailPassword({email:e,password:a,authToken:t,ecosystemGame:i}){return await this.validateAndRefreshToken(),await this.authManager.linkEmail(e,a,t,i)}async unlinkEmailPassword({email:e,authToken:a}){return await this.validateAndRefreshToken(),await this.authManager.unlinkEmail(e,a)}async requestEmailVerification({email:e,redirectUrl:a}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(e,a)}async resetPassword({email:e,password:a,state:t}){await this.ensureInitialized(),await this.authManager.resetPassword(e,a,t)}async requestResetPassword({email:e,redirectUrl:a}){await this.ensureInitialized(),await this.authManager.requestResetPassword(e,a)}async verifyEmail({email:e,state:a}){await this.ensureInitialized(),await this.authManager.verifyEmail(e,a)}async initOAuth({provider:i,options:s,ecosystemGame:r}){await this.ensureInitialized();if(await e.fromStorage(this.storage))throw new a("Already logged in",t.ALREADY_LOGGED_IN_ERROR);return await this.authManager.initOAuth(i,s,r)}async initLinkOAuth({provider:i,options:s,ecosystemGame:r}){await this.validateAndRefreshToken();const n=await e.fromStorage(this.storage);if(!n)throw new a("No authentication found",t.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(n,i,s,r)}async unlinkOAuth({provider:e,authToken:a}){return await this.validateAndRefreshToken(),await this.authManager.unlinkOAuth(e,a)}async poolOAuth(a){await this.ensureInitialized();const t=await this.authManager.poolOAuth(a);return new e("jwt",t.token,t.player.id,t.refreshToken).save(this.storage),t}async loginWithIdToken({provider:i,token:s,ecosystemGame:r}){await this.ensureInitialized();if(await e.fromStorage(this.storage))throw new a("Already logged in",t.ALREADY_LOGGED_IN_ERROR);const n=await this.authManager.loginWithIdToken(i,s,r);return new e("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async initSIWE({address:e,ecosystemGame:a}){return await this.ensureInitialized(),await this.authManager.initSIWE(e,a)}async authenticateWithSIWE({signature:i,message:s,walletClientType:r,connectorType:n}){await this.ensureInitialized();if(await e.fromStorage(this.storage))throw new a("Already logged in",t.ALREADY_LOGGED_IN_ERROR);const o=await this.authManager.authenticateSIWE(i,s,r,n);return new e("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkWallet({signature:e,message:a,walletClientType:t,connectorType:i,authToken:s}){return await this.validateAndRefreshToken(),await this.authManager.linkWallet(e,a,t,i,s)}async unlinkWallet({address:e,authToken:a}){return await this.validateAndRefreshToken(),await this.authManager.unlinkWallet(e,a)}async storeCredentials(i){if(await this.ensureInitialized(),!i.player)throw new a("Player ID is required to store credentials",t.INVALID_CONFIGURATION);new e("jwt",i.accessToken,i.player,i.refreshToken).save(this.storage)}async logout(){const a=await e.fromStorage(this.storage);if(a){try{"third_party"!==a.type&&await this.authManager.logout(a.token,a?.refreshToken)}catch(e){}e.clear(this.storage),this.eventEmitter.emit(i.LOGGED_OUT)}}}export{s as AuthApi};
@@ -1 +1 @@
1
- import{setCryptoDigestOverride as i}from"../../utils/crypto.js";class e{publishableKey;constructor(i){this.publishableKey=i.publishableKey}}class t{shieldPublishableKey;shieldEncryptionKey;debug=!1;constructor(i){this.shieldPublishableKey=i.shieldPublishableKey,this.shieldEncryptionKey=i.shieldEncryptionKey,this.debug=i.shieldDebug||!1}}class s{baseConfiguration;shieldConfiguration;shieldUrl;iframeUrl;backendUrl;storage;getAccessToken;thirdPartyAuthProvider;static instance=null;constructor({baseConfiguration:e,shieldConfiguration:t,overrides:r}){this.shieldConfiguration=t,this.baseConfiguration=e,this.backendUrl=r?.backendUrl||"https://api.openfort.io",this.iframeUrl=r?.iframeUrl||"https://embed.openfort.io",this.iframeUrl=`${this.iframeUrl}/iframe/${this.baseConfiguration.publishableKey}`,t?.debug&&(this.iframeUrl=`${this.iframeUrl}?debug=true`),this.shieldUrl=r?.shieldUrl||"https://shield.openfort.io",this.storage=r?.storage,this.getAccessToken=r?.getAccessToken,this.thirdPartyAuthProvider=r?.thirdPartyAuthProvider,r?.crypto?.digest&&i(r.crypto.digest),s.instance=this}static getInstance(){return s.instance}}export{e as OpenfortConfiguration,s as SDKConfiguration,t as ShieldConfiguration};
1
+ import{setCryptoDigestOverride as i}from"../../utils/crypto.js";class t{publishableKey;constructor(i){this.publishableKey=i.publishableKey}}class e{shieldPublishableKey;shieldEncryptionKey;debug=!1;constructor(i){this.shieldPublishableKey=i.shieldPublishableKey,this.shieldEncryptionKey=i.shieldEncryptionKey,this.debug=i.shieldDebug||!1}}class s{baseConfiguration;shieldConfiguration;thirdPartyAuth;shieldUrl;iframeUrl;backendUrl;storage;static instance=null;constructor({baseConfiguration:t,shieldConfiguration:e,overrides:r,thirdPartyAuth:h}){this.shieldConfiguration=e,this.baseConfiguration=t,this.backendUrl=r?.backendUrl||"https://api.openfort.io",this.iframeUrl=r?.iframeUrl||"https://embed.openfort.io",this.iframeUrl=`${this.iframeUrl}/iframe/${this.baseConfiguration.publishableKey}`,e?.debug&&(this.iframeUrl=`${this.iframeUrl}?debug=true`),this.shieldUrl=r?.shieldUrl||"https://shield.openfort.io",this.storage=r?.storage,this.thirdPartyAuth=h,r?.crypto?.digest&&i(r.crypto.digest),s.instance=this}static getInstance(){return s.instance}}export{t as OpenfortConfiguration,s as SDKConfiguration,e as ShieldConfiguration};
@@ -1 +1 @@
1
- import{OpenfortError as t,OpenfortErrorType as e}from"./errors/openfortError.js";import{TokenType as r,OpenfortEvents as s}from"../types/types.js";import"../storage/istorage.js";import"../wallets/messaging/browserMessenger/backwardCompatibility.js";import{debugLog as i}from"../utils/debug.js";import{Authentication as a}from"./configuration/authentication.js";import"../wallets/types.js";import"./errors/sentry.js";import{SDKConfiguration as o}from"./config/config.js";import"jose";import"../wallets/evm/types.js";import"../wallets/evm/JsonRpcError.js";import"eventemitter3";import"../wallets/evm/provider/eip6963.js";class n{storage;authManager;eventEmitter;constructor(t,e,r){this.storage=t,this.authManager=e,this.eventEmitter=r}async getAccessToken(){return(await a.fromStorage(this.storage))?.token??null}async saveThirdPartyAuth(){const i=o.getInstance();if(!i)throw new t("No SDK configuration",e.INTERNAL_ERROR);const{getAccessToken:n,thirdPartyAuthProvider:h}=i;if(!n||!h)throw new t("Third party is not configured. Please configure getAccessToken and thirdPartyAuthProvider in your Openfort instance",e.INVALID_CONFIGURATION);const c=await n();if(!c)throw new t("Could not get access token",e.AUTHENTICATION_ERROR);let g=(await a.fromStorage(this.storage))?.player;if(!g){const t=await this.authManager.authenticateThirdParty(h,c,r.ID_TOKEN);g=t?.id}new a("third_party",c,g,null,h,r.ID_TOKEN).save(this.storage),this.eventEmitter.emit(s.TOKEN_REFRESHED)}async validateAndRefreshToken(r){if(o.getInstance()?.thirdPartyAuthProvider)return void await this.saveThirdPartyAuth();const n=await a.fromStorage(this.storage);if(!n)throw new t("Must be logged in to validate and refresh token",e.NOT_LOGGED_IN_ERROR);let h;i("validating credentials...");try{h=await this.authManager.validateCredentials(n,r)}catch(t){throw a.clear(this.storage),this.eventEmitter.emit(s.LOGGED_OUT),t}if(!h.player)throw new t("No user found in credentials",e.INTERNAL_ERROR);h.accessToken!==n.token&&(i("tokens refreshed"),new a("jwt",h.accessToken,h.player,h.refreshToken).save(this.storage),this.eventEmitter.emit(s.TOKEN_REFRESHED))}}export{n as OpenfortInternal};
1
+ import{OpenfortError as t,OpenfortErrorType as e}from"./errors/openfortError.js";import{TokenType as r,OpenfortEvents as i}from"../types/types.js";import"../storage/istorage.js";import"../wallets/messaging/browserMessenger/backwardCompatibility.js";import{debugLog as s}from"../utils/debug.js";import{Authentication as a}from"./configuration/authentication.js";import"../wallets/types.js";import"./errors/sentry.js";import{SDKConfiguration as o}from"./config/config.js";import"jose";import"../wallets/evm/types.js";import"../wallets/evm/JsonRpcError.js";import"eventemitter3";import"../wallets/evm/provider/eip6963.js";class n{storage;authManager;eventEmitter;constructor(t,e,r){this.storage=t,this.authManager=e,this.eventEmitter=r}async getThirdPartyAuthToken(){const s=o.getInstance();if(!s?.thirdPartyAuth)throw new t("No third party configuration found",e.INTERNAL_ERROR);const{getAccessToken:n,provider:h}=s.thirdPartyAuth;if(!n||!h)throw new t("Third party is not configured. Please configure getAccessToken and thirdPartyAuthProvider in your Openfort instance",e.INVALID_CONFIGURATION);const c=await n();if(!c)throw new t("Could not get access token",e.AUTHENTICATION_ERROR);let g=(await a.fromStorage(this.storage))?.player;if(!g){const t=await this.authManager.authenticateThirdParty(h,c,r.ID_TOKEN);g=t?.id}return new a("third_party",c,g,null,h,r.ID_TOKEN).save(this.storage),this.eventEmitter.emit(i.TOKEN_REFRESHED),c}async getAccessToken(){if(o.getInstance()?.thirdPartyAuth)return this.getThirdPartyAuthToken();return(await a.fromStorage(this.storage))?.token??null}async validateAndRefreshToken(r){if(o.getInstance()?.thirdPartyAuth)return void await this.getThirdPartyAuthToken();const n=await a.fromStorage(this.storage);if(!n)throw new t("Must be logged in to validate and refresh token",e.NOT_LOGGED_IN_ERROR);let h;s("validating credentials...");try{h=await this.authManager.validateCredentials(n,r)}catch(t){throw a.clear(this.storage),this.eventEmitter.emit(i.LOGGED_OUT),t}if(!h.player)throw new t("No user found in credentials",e.INTERNAL_ERROR);h.accessToken!==n.token&&(s("tokens refreshed"),new a("jwt",h.accessToken,h.player,h.refreshToken).save(this.storage),this.eventEmitter.emit(i.TOKEN_REFRESHED))}}export{n as OpenfortInternal};
@@ -1 +1 @@
1
- const o="0.10.2",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
1
+ const o="0.10.3",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": "0.10.2",
3
+ "version": "0.10.3",
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",