@openfort/openfort-js 0.7.14 → 0.7.15

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/index.cjs CHANGED
@@ -3195,57 +3195,6 @@ var CodeChallengeMethodEnum;
3195
3195
  CodeChallengeMethodEnum["S256"] = "S256";
3196
3196
  })(CodeChallengeMethodEnum || (CodeChallengeMethodEnum = {}));
3197
3197
 
3198
- var OpenfortErrorType;
3199
- (function (OpenfortErrorType) {
3200
- OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
3201
- OpenfortErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
3202
- OpenfortErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
3203
- OpenfortErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
3204
- OpenfortErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
3205
- OpenfortErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
3206
- OpenfortErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
3207
- OpenfortErrorType["MISSING_SESSION_SIGNER_ERROR"] = "MISSING_SESSION_SIGNER_ERROR";
3208
- OpenfortErrorType["MISSING_EMBEDDED_SIGNER_ERROR"] = "MISSING_EMBEDDED_SIGNER_ERROR";
3209
- OpenfortErrorType["MISSING_SIGNER_ERROR"] = "MISSING_SIGNER_ERROR";
3210
- })(OpenfortErrorType || (OpenfortErrorType = {}));
3211
- function isAPIError(error) {
3212
- return 'type' in error && 'message' in error;
3213
- }
3214
- class OpenfortError extends Error {
3215
- type;
3216
- constructor(message, type) {
3217
- super(message);
3218
- this.type = type;
3219
- }
3220
- }
3221
- const withOpenfortError = async (fn, customErrorType) => {
3222
- try {
3223
- return await fn();
3224
- }
3225
- catch (error) {
3226
- let errorMessage;
3227
- if (globalAxios.isAxiosError(error) && error.response?.data && isAPIError(error.response.data)) {
3228
- errorMessage = error.response.data.message;
3229
- }
3230
- else {
3231
- errorMessage = error.message;
3232
- }
3233
- throw new OpenfortError(errorMessage, customErrorType);
3234
- }
3235
- };
3236
-
3237
- const validateConfiguration = (configuration, requiredKeys, prefix) => {
3238
- const missingKeys = requiredKeys
3239
- .map((key) => !configuration[key] && key)
3240
- .filter((n) => n)
3241
- .join(', ');
3242
- if (missingKeys !== '') {
3243
- const errorMessage = prefix
3244
- ? `${prefix} - ${missingKeys} cannot be null`
3245
- : `${missingKeys} cannot be null`;
3246
- throw new OpenfortError(errorMessage, OpenfortErrorType.INVALID_CONFIGURATION);
3247
- }
3248
- };
3249
3198
  class OpenfortConfiguration {
3250
3199
  publishableKey;
3251
3200
  constructor(options) {
@@ -3273,17 +3222,12 @@ class SDKConfiguration {
3273
3222
  this.shieldConfiguration = shieldConfiguration;
3274
3223
  this.baseConfiguration = baseConfiguration;
3275
3224
  if (overrides) {
3276
- validateConfiguration(overrides, [
3277
- 'backendUrl',
3278
- 'iframeUrl',
3279
- 'shieldUrl',
3280
- ], 'overrides');
3281
- this.backendUrl = overrides.backendUrl;
3282
- this.iframeUrl = overrides.iframeUrl;
3283
- this.shieldUrl = overrides.shieldUrl;
3225
+ this.backendUrl = overrides.backendUrl || 'https://api.openfort.xyz';
3226
+ this.iframeUrl = overrides.iframeUrl || 'https://iframe.openfort.xyz';
3227
+ this.shieldUrl = overrides.shieldUrl || 'https://shield.openfort.xyz';
3284
3228
  this.openfortAPIConfig = {
3285
3229
  backend: createConfig({
3286
- basePath: overrides.backendUrl,
3230
+ basePath: overrides.backendUrl || 'https://api.openfort.xyz',
3287
3231
  accessToken: baseConfiguration.publishableKey,
3288
3232
  }),
3289
3233
  };
@@ -4742,6 +4686,69 @@ function announceProvider(detail) {
4742
4686
  window.addEventListener('eip6963:requestProvider', handler);
4743
4687
  }
4744
4688
 
4689
+ exports.OpenfortErrorType = void 0;
4690
+ (function (OpenfortErrorType) {
4691
+ OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
4692
+ OpenfortErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
4693
+ OpenfortErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
4694
+ OpenfortErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
4695
+ OpenfortErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
4696
+ OpenfortErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
4697
+ OpenfortErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
4698
+ OpenfortErrorType["MISSING_SESSION_SIGNER_ERROR"] = "MISSING_SESSION_SIGNER_ERROR";
4699
+ OpenfortErrorType["MISSING_EMBEDDED_SIGNER_ERROR"] = "MISSING_EMBEDDED_SIGNER_ERROR";
4700
+ OpenfortErrorType["MISSING_SIGNER_ERROR"] = "MISSING_SIGNER_ERROR";
4701
+ OpenfortErrorType["USER_NOT_AUTHORIZED_ON_ECOSYSTEM"] = "USER_NOT_AUTHORIZED_ON_ECOSYSTEM";
4702
+ })(exports.OpenfortErrorType || (exports.OpenfortErrorType = {}));
4703
+ function isAPIError(error) {
4704
+ return 'type' in error && 'message' in error;
4705
+ }
4706
+ class OpenfortError extends Error {
4707
+ type;
4708
+ data;
4709
+ constructor(message, type, data = {}) {
4710
+ super(message);
4711
+ this.type = type;
4712
+ this.data = data;
4713
+ }
4714
+ }
4715
+ const withOpenfortError = async (fn, customErrorType) => {
4716
+ try {
4717
+ return await fn();
4718
+ }
4719
+ catch (error) {
4720
+ let errorMessage;
4721
+ const data = {};
4722
+ let errorType = customErrorType.default;
4723
+ if (globalAxios.isAxiosError(error)) {
4724
+ const statusCode = error.response?.status;
4725
+ errorType = statusCode ? customErrorType[statusCode] || customErrorType.default : customErrorType.default;
4726
+ if (error.response?.data && error.response.data.error) {
4727
+ const jsonData = JSON.parse(JSON.stringify(error.response.data.error));
4728
+ // eslint-disable-next-line no-restricted-syntax
4729
+ for (const key in jsonData) {
4730
+ if (key !== 'message' && key !== 'type') {
4731
+ data[key] = jsonData[key];
4732
+ }
4733
+ }
4734
+ if (isAPIError(error.response.data)) {
4735
+ errorMessage = error.response.data.message;
4736
+ }
4737
+ else {
4738
+ errorMessage = error.message;
4739
+ }
4740
+ }
4741
+ else {
4742
+ errorMessage = error.message;
4743
+ }
4744
+ }
4745
+ else {
4746
+ errorMessage = error.message;
4747
+ }
4748
+ throw new OpenfortError(errorMessage, errorType, data);
4749
+ }
4750
+ };
4751
+
4745
4752
  var SignerType;
4746
4753
  (function (SignerType) {
4747
4754
  SignerType["EMBEDDED"] = "embedded";
@@ -4787,7 +4794,7 @@ class AuthManager {
4787
4794
  this.backendApiClients = backendApiClients;
4788
4795
  this.instanceManager = instanceManager;
4789
4796
  }
4790
- async initOAuth(provider, options) {
4797
+ async initOAuth(provider, options, ecosystemGame) {
4791
4798
  const usePooling = options?.usePooling ?? false;
4792
4799
  // eslint-disable-next-line no-param-reassign
4793
4800
  delete options?.usePooling;
@@ -4798,7 +4805,7 @@ class AuthManager {
4798
4805
  usePooling,
4799
4806
  },
4800
4807
  };
4801
- const result = await this.backendApiClients.authenticationApi.initOAuth(request);
4808
+ const result = await this.backendApiClients.authenticationApi.initOAuth(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4802
4809
  if (isBrowser() && options?.skipBrowserRedirect) {
4803
4810
  window.location.assign(result.data.url);
4804
4811
  }
@@ -4839,7 +4846,7 @@ class AuthManager {
4839
4846
  }
4840
4847
  throw new Error('Failed to pool OAuth, try again later');
4841
4848
  }
4842
- async authenticateThirdParty(provider, token, tokenType) {
4849
+ async authenticateThirdParty(provider, token, tokenType, ecosystemGame) {
4843
4850
  const request = {
4844
4851
  thirdPartyOAuthRequest: {
4845
4852
  provider,
@@ -4848,17 +4855,17 @@ class AuthManager {
4848
4855
  },
4849
4856
  };
4850
4857
  return withOpenfortError(async () => {
4851
- const response = await this.backendApiClients.authenticationApi.thirdParty(request);
4858
+ const response = await this.backendApiClients.authenticationApi.thirdParty(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4852
4859
  return response.data;
4853
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4860
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
4854
4861
  }
4855
- async initSIWE(address) {
4862
+ async initSIWE(address, ecosystemGame) {
4856
4863
  const request = {
4857
4864
  sIWERequest: {
4858
4865
  address,
4859
4866
  },
4860
4867
  };
4861
- const result = await this.backendApiClients.authenticationApi.initSIWE(request);
4868
+ const result = await this.backendApiClients.authenticationApi.initSIWE(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4862
4869
  return {
4863
4870
  address: result.data.address,
4864
4871
  nonce: result.data.nonce,
@@ -4877,9 +4884,20 @@ class AuthManager {
4877
4884
  return withOpenfortError(async () => {
4878
4885
  const response = await this.backendApiClients.authenticationApi.authenticateSIWE(request);
4879
4886
  return response.data;
4880
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4887
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
4888
+ }
4889
+ static getEcosystemGameOptsOrUndefined(ecosystemGame) {
4890
+ if (ecosystemGame) {
4891
+ return {
4892
+ headers: {
4893
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4894
+ 'x-game': ecosystemGame,
4895
+ },
4896
+ };
4897
+ }
4898
+ return undefined;
4881
4899
  }
4882
- async loginEmailPassword(email, password) {
4900
+ async loginEmailPassword(email, password, ecosystemGame) {
4883
4901
  const request = {
4884
4902
  loginRequest: {
4885
4903
  email,
@@ -4887,9 +4905,10 @@ class AuthManager {
4887
4905
  },
4888
4906
  };
4889
4907
  return withOpenfortError(async () => {
4890
- const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request);
4908
+ const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4891
4909
  return response.data;
4892
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4910
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4911
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR, 403: exports.OpenfortErrorType.USER_NOT_AUTHORIZED_ON_ECOSYSTEM });
4893
4912
  }
4894
4913
  async requestResetPassword(email, redirectUrl) {
4895
4914
  const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
@@ -4926,7 +4945,7 @@ class AuthManager {
4926
4945
  },
4927
4946
  };
4928
4947
  await this.backendApiClients.authenticationApi.resetPassword(request);
4929
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4948
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
4930
4949
  }
4931
4950
  async requestEmailVerification(email, redirectUrl) {
4932
4951
  const verifier = base64URLEncode(crypto__namespace.randomBytes(32));
@@ -4962,9 +4981,9 @@ class AuthManager {
4962
4981
  },
4963
4982
  };
4964
4983
  await this.backendApiClients.authenticationApi.verifyEmail(request);
4965
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4984
+ }, { default: exports.OpenfortErrorType.AUTHENTICATION_ERROR });
4966
4985
  }
4967
- async signupEmailPassword(email, password, name) {
4986
+ async signupEmailPassword(email, password, name, ecosystemGame) {
4968
4987
  const request = {
4969
4988
  signupRequest: {
4970
4989
  email,
@@ -4973,16 +4992,16 @@ class AuthManager {
4973
4992
  },
4974
4993
  };
4975
4994
  return withOpenfortError(async () => {
4976
- const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request);
4995
+ const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4977
4996
  return response.data;
4978
- }, OpenfortErrorType.USER_REGISTRATION_ERROR);
4997
+ }, { default: exports.OpenfortErrorType.USER_REGISTRATION_ERROR });
4979
4998
  }
4980
4999
  async validateCredentials(forceRefresh) {
4981
5000
  const jwk = await this.instanceManager.getJWK();
4982
5001
  const accessToken = this.instanceManager.getAccessToken()?.token;
4983
5002
  const refreshToken = this.instanceManager.getRefreshToken();
4984
5003
  if (!accessToken || !refreshToken || !jwk) {
4985
- throw new OpenfortError('Must be logged in to validate and refresh token', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
5004
+ throw new OpenfortError('Must be logged in to validate and refresh token', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
4986
5005
  }
4987
5006
  if (forceRefresh) {
4988
5007
  return this.refreshTokens(refreshToken, forceRefresh);
@@ -5022,7 +5041,7 @@ class AuthManager {
5022
5041
  accessToken: response.data.token,
5023
5042
  refreshToken: response.data.refreshToken,
5024
5043
  };
5025
- }, OpenfortErrorType.REFRESH_TOKEN_ERROR);
5044
+ }, { default: exports.OpenfortErrorType.REFRESH_TOKEN_ERROR });
5026
5045
  }
5027
5046
  async logout(accessToken, refreshToken) {
5028
5047
  const request = {
@@ -5038,7 +5057,7 @@ class AuthManager {
5038
5057
  'x-player-token': accessToken,
5039
5058
  },
5040
5059
  });
5041
- }, OpenfortErrorType.LOGOUT_ERROR);
5060
+ }, { default: exports.OpenfortErrorType.LOGOUT_ERROR });
5042
5061
  }
5043
5062
  async getUser(accessToken) {
5044
5063
  // TODO: Add storage of user info
@@ -5051,7 +5070,7 @@ class AuthManager {
5051
5070
  });
5052
5071
  return response.data;
5053
5072
  }
5054
- async linkOAuth(provider, playerToken, options) {
5073
+ async linkOAuth(provider, playerToken, options, ecosystemGame) {
5055
5074
  const request = {
5056
5075
  oAuthInitRequest: {
5057
5076
  provider,
@@ -5064,6 +5083,8 @@ class AuthManager {
5064
5083
  authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
5065
5084
  // eslint-disable-next-line @typescript-eslint/naming-convention
5066
5085
  'x-player-token': playerToken,
5086
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5087
+ 'x-game': ecosystemGame || undefined,
5067
5088
  },
5068
5089
  });
5069
5090
  if (isBrowser() && !options?.skipBrowserRedirect) {
@@ -5137,7 +5158,7 @@ class AuthManager {
5137
5158
  });
5138
5159
  return authPlayerResponse.data;
5139
5160
  }
5140
- async linkEmail(email, password, accessToken) {
5161
+ async linkEmail(email, password, accessToken, ecosystemGame) {
5141
5162
  const request = {
5142
5163
  loginRequest: {
5143
5164
  email,
@@ -5149,6 +5170,8 @@ class AuthManager {
5149
5170
  authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
5150
5171
  // eslint-disable-next-line @typescript-eslint/naming-convention
5151
5172
  'x-player-token': accessToken,
5173
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5174
+ 'x-game': ecosystemGame || undefined,
5152
5175
  },
5153
5176
  });
5154
5177
  return authPlayerResponse.data;
@@ -6068,7 +6091,7 @@ class Openfort {
6068
6091
  */
6069
6092
  getEthereumProvider(options = { announceProvider: true }) {
6070
6093
  if (!(this.signer instanceof EmbeddedSigner)) {
6071
- throw new OpenfortError('Embedded signer must be configured to get Ethereum provider', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
6094
+ throw new OpenfortError('Embedded signer must be configured to get Ethereum provider', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
6072
6095
  }
6073
6096
  const address = this.instanceManager.getAccountAddress();
6074
6097
  const provider = new EvmProvider({
@@ -6094,7 +6117,7 @@ class Openfort {
6094
6117
  */
6095
6118
  configureSessionKey() {
6096
6119
  if (this.instanceManager.getSignerType() === SignerType.EMBEDDED) {
6097
- throw new OpenfortError('Session signer must be configured to sign a session', OpenfortErrorType.MISSING_SESSION_SIGNER_ERROR);
6120
+ throw new OpenfortError('Session signer must be configured to sign a session', exports.OpenfortErrorType.MISSING_SESSION_SIGNER_ERROR);
6098
6121
  }
6099
6122
  const signer = new SessionSigner(this.instanceManager);
6100
6123
  this.signer = signer;
@@ -6131,11 +6154,12 @@ class Openfort {
6131
6154
  *
6132
6155
  * @param email - User's email.
6133
6156
  * @param password - User's password.
6157
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6134
6158
  * @returns An AuthResponse object containing authentication details.
6135
6159
  */
6136
- async logInWithEmailPassword({ email, password }) {
6160
+ async logInWithEmailPassword({ email, password, ecosystemGame }) {
6137
6161
  this.logout();
6138
- const result = await this.authManager.loginEmailPassword(email, password);
6162
+ const result = await this.authManager.loginEmailPassword(email, password, ecosystemGame);
6139
6163
  this.storeCredentials({
6140
6164
  player: result.player.id,
6141
6165
  accessToken: result.token,
@@ -6149,11 +6173,12 @@ class Openfort {
6149
6173
  * @param email - User's email.
6150
6174
  * @param password - User's password.
6151
6175
  * @param options - Additional options for the sign-up process.
6176
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6152
6177
  * @returns An AuthResponse object containing authentication details.
6153
6178
  */
6154
- async signUpWithEmailPassword({ email, password, options }) {
6179
+ async signUpWithEmailPassword({ email, password, options, ecosystemGame, }) {
6155
6180
  this.logout();
6156
- const result = await this.authManager.signupEmailPassword(email, password, options?.data.name);
6181
+ const result = await this.authManager.signupEmailPassword(email, password, options?.data.name, ecosystemGame);
6157
6182
  this.storeCredentials({
6158
6183
  player: result.player.id,
6159
6184
  accessToken: result.token,
@@ -6167,11 +6192,11 @@ class Openfort {
6167
6192
  * @param email - User's email.
6168
6193
  * @param password - User's password.
6169
6194
  * @param authToken - Authentication token.
6195
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6170
6196
  * @returns An AuthPlayerResponse object.
6171
6197
  */
6172
- async linkEmailPassword({ email, password, authToken }) {
6173
- const result = await this.authManager.linkEmail(email, password, authToken);
6174
- return result;
6198
+ async linkEmailPassword({ email, password, authToken, ecosystemGame, }) {
6199
+ return await this.authManager.linkEmail(email, password, authToken, ecosystemGame);
6175
6200
  }
6176
6201
  /**
6177
6202
  * Unlinks an email and password from an existing account using an authentication token.
@@ -6181,8 +6206,7 @@ class Openfort {
6181
6206
  * @returns An AuthPlayerResponse object.
6182
6207
  */
6183
6208
  async unlinkEmailPassword({ email, authToken }) {
6184
- const result = await this.authManager.unlinkEmail(email, authToken);
6185
- return result;
6209
+ return await this.authManager.unlinkEmail(email, authToken);
6186
6210
  }
6187
6211
  /**
6188
6212
  * Requests an email verification link.
@@ -6226,12 +6250,12 @@ class Openfort {
6226
6250
  *
6227
6251
  * @param provider - OAuth provider.
6228
6252
  * @param options - Additional options for initialization.
6253
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6229
6254
  * @returns An InitAuthResponse object.
6230
6255
  */
6231
- async initOAuth({ provider, options }) {
6256
+ async initOAuth({ provider, options, ecosystemGame }) {
6232
6257
  this.logout();
6233
- const authResponse = await this.authManager.initOAuth(provider, options);
6234
- return authResponse;
6258
+ return await this.authManager.initOAuth(provider, options, ecosystemGame);
6235
6259
  }
6236
6260
  /**
6237
6261
  * Initializes an OAuth linking process.
@@ -6239,10 +6263,11 @@ class Openfort {
6239
6263
  * @param provider - OAuth provider.
6240
6264
  * @param authToken - Authentication token.
6241
6265
  * @param options - Additional options for initialization.
6266
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6242
6267
  * @returns An InitAuthResponse object.
6243
6268
  */
6244
- async initLinkOAuth({ provider, authToken, options }) {
6245
- return await this.authManager.linkOAuth(provider, authToken, options);
6269
+ async initLinkOAuth({ provider, authToken, options, ecosystemGame, }) {
6270
+ return await this.authManager.linkOAuth(provider, authToken, options, ecosystemGame);
6246
6271
  }
6247
6272
  /**
6248
6273
  * Unlinks an OAuth provider from the account.
@@ -6252,8 +6277,7 @@ class Openfort {
6252
6277
  * @returns An AuthPlayerResponse object.
6253
6278
  */
6254
6279
  async unlinkOAuth({ provider, authToken }) {
6255
- const result = await this.authManager.unlinkOAuth(provider, authToken);
6256
- return result;
6280
+ return await this.authManager.unlinkOAuth(provider, authToken);
6257
6281
  }
6258
6282
  /**
6259
6283
  * Polls for OAuth authentication completion.
@@ -6270,10 +6294,11 @@ class Openfort {
6270
6294
  * @param provider - Third-party OAuth provider.
6271
6295
  * @param token - OAuth token.
6272
6296
  * @param tokenType - Type of the OAuth token.
6297
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6273
6298
  * @returns An AuthPlayerResponse object.
6274
6299
  */
6275
- async authenticateWithThirdPartyProvider({ provider, token, tokenType }) {
6276
- const result = await this.authManager.authenticateThirdParty(provider, token, tokenType);
6300
+ async authenticateWithThirdPartyProvider({ provider, token, tokenType, ecosystemGame, }) {
6301
+ const result = await this.authManager.authenticateThirdParty(provider, token, tokenType, ecosystemGame);
6277
6302
  this.instanceManager.setAccessToken({
6278
6303
  token,
6279
6304
  thirdPartyProvider: provider,
@@ -6289,10 +6314,11 @@ class Openfort {
6289
6314
  * Initializes Sign-In with Ethereum (SIWE).
6290
6315
  *
6291
6316
  * @param address - Ethereum address.
6317
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6292
6318
  * @returns A SIWEInitResponse object.
6293
6319
  */
6294
- async initSIWE({ address }) {
6295
- return await this.authManager.initSIWE(address);
6320
+ async initSIWE({ address, ecosystemGame }) {
6321
+ return await this.authManager.initSIWE(address, ecosystemGame);
6296
6322
  }
6297
6323
  /**
6298
6324
  * Authenticates using Sign-In with Ethereum (SIWE).
@@ -6326,8 +6352,7 @@ class Openfort {
6326
6352
  * @returns An AuthPlayerResponse object.
6327
6353
  */
6328
6354
  async linkWallet({ signature, message, walletClientType, connectorType, authToken, }) {
6329
- const result = await this.authManager.linkWallet(signature, message, walletClientType, connectorType, authToken);
6330
- return result;
6355
+ return await this.authManager.linkWallet(signature, message, walletClientType, connectorType, authToken);
6331
6356
  }
6332
6357
  /**
6333
6358
  * Unlinks a wallet.
@@ -6337,8 +6362,7 @@ class Openfort {
6337
6362
  * @returns An AuthPlayerResponse object.
6338
6363
  */
6339
6364
  async unlinkWallet({ address, authToken }) {
6340
- const result = await this.authManager.unlinkWallet(address, authToken);
6341
- return result;
6365
+ return await this.authManager.unlinkWallet(address, authToken);
6342
6366
  }
6343
6367
  /**
6344
6368
  * Stores authentication credentials.
@@ -6369,11 +6393,11 @@ class Openfort {
6369
6393
  let newSignature = signature;
6370
6394
  if (!newSignature) {
6371
6395
  if (!userOperationHash) {
6372
- throw new OpenfortError('No userOperationHash or signature provided', OpenfortErrorType.OPERATION_NOT_SUPPORTED_ERROR);
6396
+ throw new OpenfortError('No userOperationHash or signature provided', exports.OpenfortErrorType.OPERATION_NOT_SUPPORTED_ERROR);
6373
6397
  }
6374
6398
  await this.recoverSigner();
6375
6399
  if (!this.signer) {
6376
- throw new OpenfortError('In order to sign a transaction intent, a signer must be configured', OpenfortErrorType.MISSING_SIGNER_ERROR);
6400
+ throw new OpenfortError('In order to sign a transaction intent, a signer must be configured', exports.OpenfortErrorType.MISSING_SIGNER_ERROR);
6377
6401
  }
6378
6402
  if (this.signer.useCredentials()) {
6379
6403
  await this.validateAndRefreshToken();
@@ -6401,7 +6425,7 @@ class Openfort {
6401
6425
  async signMessage(message, options) {
6402
6426
  await this.recoverSigner();
6403
6427
  if (!this.signer) {
6404
- throw new OpenfortError('In order to sign a message, an embedded signer must be configured', OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
6428
+ throw new OpenfortError('In order to sign a message, an embedded signer must be configured', exports.OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
6405
6429
  }
6406
6430
  if (this.signer.useCredentials()) {
6407
6431
  await this.validateAndRefreshToken();
@@ -6421,7 +6445,7 @@ class Openfort {
6421
6445
  async signTypedData(domain, types, value) {
6422
6446
  await this.recoverSigner();
6423
6447
  if (!this.signer) {
6424
- throw new OpenfortError('In order to sign a message, an embedded signer must be configured', OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
6448
+ throw new OpenfortError('In order to sign a message, an embedded signer must be configured', exports.OpenfortErrorType.MISSING_EMBEDDED_SIGNER_ERROR);
6425
6449
  }
6426
6450
  if (this.signer.useCredentials()) {
6427
6451
  await this.validateAndRefreshToken();
@@ -6508,7 +6532,7 @@ class Openfort {
6508
6532
  await this.validateAndRefreshToken();
6509
6533
  const accessToken = this.instanceManager.getAccessToken();
6510
6534
  if (!accessToken) {
6511
- throw new OpenfortError('No accessToken found', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
6535
+ throw new OpenfortError('No accessToken found', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
6512
6536
  }
6513
6537
  return await this.authManager.getUser(accessToken.token);
6514
6538
  }
@@ -6518,7 +6542,7 @@ class Openfort {
6518
6542
  async validateAndRefreshToken(forceRefresh) {
6519
6543
  const authType = this.credentialsProvided();
6520
6544
  if (!authType) {
6521
- throw new OpenfortError('Must be logged in to validate and refresh token', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
6545
+ throw new OpenfortError('Must be logged in to validate and refresh token', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
6522
6546
  }
6523
6547
  if (authType === exports.AuthType.OPENFORT) {
6524
6548
  const auth = await this.authManager.validateCredentials(forceRefresh);
@@ -6577,7 +6601,7 @@ class Openfort {
6577
6601
  }
6578
6602
  newEmbeddedSigner(chainId) {
6579
6603
  if (!this.credentialsProvided()) {
6580
- throw new OpenfortError('Must be logged in to configure embedded signer', OpenfortErrorType.NOT_LOGGED_IN_ERROR);
6604
+ throw new OpenfortError('Must be logged in to configure embedded signer', exports.OpenfortErrorType.NOT_LOGGED_IN_ERROR);
6581
6605
  }
6582
6606
  let shieldAuthType = this.instanceManager.getShieldAuthType();
6583
6607
  if (!shieldAuthType) {
@@ -6590,7 +6614,7 @@ class Openfort {
6590
6614
  ? this.instanceManager.getAccessToken()?.token
6591
6615
  : this.instanceManager.getShieldAuthToken();
6592
6616
  if (!token) {
6593
- throw new OpenfortError('Shield auth token is not set', OpenfortErrorType.INVALID_CONFIGURATION);
6617
+ throw new OpenfortError('Shield auth token is not set', exports.OpenfortErrorType.INVALID_CONFIGURATION);
6594
6618
  }
6595
6619
  const shieldAuth = {
6596
6620
  auth: shieldAuthType,
package/dist/index.d.ts CHANGED
@@ -95,9 +95,9 @@ type InitializeOAuthOptions = {
95
95
  skipBrowserRedirect?: boolean;
96
96
  };
97
97
  interface SDKOverrides {
98
- backendUrl: string;
99
- iframeUrl: string;
100
- shieldUrl: string;
98
+ backendUrl?: string;
99
+ iframeUrl?: string;
100
+ shieldUrl?: string;
101
101
  }
102
102
  declare enum TokenType {
103
103
  ID_TOKEN = "idToken",
@@ -561,11 +561,13 @@ declare class Openfort {
561
561
  *
562
562
  * @param email - User's email.
563
563
  * @param password - User's password.
564
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
564
565
  * @returns An AuthResponse object containing authentication details.
565
566
  */
566
- logInWithEmailPassword({ email, password }: {
567
+ logInWithEmailPassword({ email, password, ecosystemGame }: {
567
568
  email: string;
568
569
  password: string;
570
+ ecosystemGame?: string;
569
571
  }): Promise<AuthResponse>;
570
572
  /**
571
573
  * Signs up a new user with email and password.
@@ -573,9 +575,10 @@ declare class Openfort {
573
575
  * @param email - User's email.
574
576
  * @param password - User's password.
575
577
  * @param options - Additional options for the sign-up process.
578
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
576
579
  * @returns An AuthResponse object containing authentication details.
577
580
  */
578
- signUpWithEmailPassword({ email, password, options }: {
581
+ signUpWithEmailPassword({ email, password, options, ecosystemGame, }: {
579
582
  email: string;
580
583
  password: string;
581
584
  options?: {
@@ -583,6 +586,7 @@ declare class Openfort {
583
586
  name: string;
584
587
  };
585
588
  };
589
+ ecosystemGame?: string;
586
590
  }): Promise<AuthResponse>;
587
591
  /**
588
592
  * Links an email and password to an existing account using an authentication token.
@@ -590,12 +594,14 @@ declare class Openfort {
590
594
  * @param email - User's email.
591
595
  * @param password - User's password.
592
596
  * @param authToken - Authentication token.
597
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
593
598
  * @returns An AuthPlayerResponse object.
594
599
  */
595
- linkEmailPassword({ email, password, authToken }: {
600
+ linkEmailPassword({ email, password, authToken, ecosystemGame, }: {
596
601
  email: string;
597
602
  password: string;
598
603
  authToken: string;
604
+ ecosystemGame?: string;
599
605
  }): Promise<AuthPlayerResponse>;
600
606
  /**
601
607
  * Unlinks an email and password from an existing account using an authentication token.
@@ -655,11 +661,13 @@ declare class Openfort {
655
661
  *
656
662
  * @param provider - OAuth provider.
657
663
  * @param options - Additional options for initialization.
664
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
658
665
  * @returns An InitAuthResponse object.
659
666
  */
660
- initOAuth({ provider, options }: {
667
+ initOAuth({ provider, options, ecosystemGame }: {
661
668
  provider: OAuthProvider;
662
669
  options?: InitializeOAuthOptions;
670
+ ecosystemGame?: string;
663
671
  }): Promise<InitAuthResponse>;
664
672
  /**
665
673
  * Initializes an OAuth linking process.
@@ -667,12 +675,14 @@ declare class Openfort {
667
675
  * @param provider - OAuth provider.
668
676
  * @param authToken - Authentication token.
669
677
  * @param options - Additional options for initialization.
678
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
670
679
  * @returns An InitAuthResponse object.
671
680
  */
672
- initLinkOAuth({ provider, authToken, options }: {
681
+ initLinkOAuth({ provider, authToken, options, ecosystemGame, }: {
673
682
  provider: OAuthProvider;
674
683
  authToken: string;
675
684
  options?: InitializeOAuthOptions;
685
+ ecosystemGame?: string;
676
686
  }): Promise<InitAuthResponse>;
677
687
  /**
678
688
  * Unlinks an OAuth provider from the account.
@@ -698,21 +708,25 @@ declare class Openfort {
698
708
  * @param provider - Third-party OAuth provider.
699
709
  * @param token - OAuth token.
700
710
  * @param tokenType - Type of the OAuth token.
711
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
701
712
  * @returns An AuthPlayerResponse object.
702
713
  */
703
- authenticateWithThirdPartyProvider({ provider, token, tokenType }: {
714
+ authenticateWithThirdPartyProvider({ provider, token, tokenType, ecosystemGame, }: {
704
715
  provider: ThirdPartyOAuthProvider;
705
716
  token: string;
706
717
  tokenType: TokenType;
718
+ ecosystemGame?: string;
707
719
  }): Promise<AuthPlayerResponse>;
708
720
  /**
709
721
  * Initializes Sign-In with Ethereum (SIWE).
710
722
  *
711
723
  * @param address - Ethereum address.
724
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
712
725
  * @returns A SIWEInitResponse object.
713
726
  */
714
- initSIWE({ address }: {
727
+ initSIWE({ address, ecosystemGame }: {
715
728
  address: string;
729
+ ecosystemGame?: string;
716
730
  }): Promise<SIWEInitResponse>;
717
731
  /**
718
732
  * Authenticates using Sign-In with Ethereum (SIWE).
@@ -845,11 +859,16 @@ declare enum OpenfortErrorType {
845
859
  OPERATION_NOT_SUPPORTED_ERROR = "OPERATION_NOT_SUPPORTED_ERROR",
846
860
  MISSING_SESSION_SIGNER_ERROR = "MISSING_SESSION_SIGNER_ERROR",
847
861
  MISSING_EMBEDDED_SIGNER_ERROR = "MISSING_EMBEDDED_SIGNER_ERROR",
848
- MISSING_SIGNER_ERROR = "MISSING_SIGNER_ERROR"
862
+ MISSING_SIGNER_ERROR = "MISSING_SIGNER_ERROR",
863
+ USER_NOT_AUTHORIZED_ON_ECOSYSTEM = "USER_NOT_AUTHORIZED_ON_ECOSYSTEM"
864
+ }
865
+ interface Data {
866
+ [key: string]: any;
849
867
  }
850
868
  declare class OpenfortError extends Error {
851
869
  type: OpenfortErrorType;
852
- constructor(message: string, type: OpenfortErrorType);
870
+ data: Data;
871
+ constructor(message: string, type: OpenfortErrorType, data?: Data);
853
872
  }
854
873
 
855
874
  declare enum ShieldAuthProvider {
@@ -866,4 +885,4 @@ interface ShieldAuthOptions {
866
885
  authProvider: ShieldAuthProvider;
867
886
  }
868
887
 
869
- export { AuthPlayerResponse, AuthType, BasicAuthProvider, EmbeddedState, InitializeOAuthOptions, OAuthProvider, OpenfortConfiguration, OpenfortError, Provider, SDKConfiguration, SDKOverrides, SessionResponse, ShieldAuthOptions, ShieldAuthType, ShieldAuthentication, ShieldConfiguration, ShieldOptions, ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataDomain, TypedDataField, Openfort as default };
888
+ export { AuthPlayerResponse, AuthType, BasicAuthProvider, EmbeddedState, InitializeOAuthOptions, OAuthProvider, OpenfortConfiguration, OpenfortError, OpenfortErrorType, Provider, SDKConfiguration, SDKOverrides, SessionResponse, ShieldAuthOptions, ShieldAuthType, ShieldAuthentication, ShieldConfiguration, ShieldOptions, ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataDomain, TypedDataField, Openfort as default };
package/dist/index.js CHANGED
@@ -3172,57 +3172,6 @@ var CodeChallengeMethodEnum;
3172
3172
  CodeChallengeMethodEnum["S256"] = "S256";
3173
3173
  })(CodeChallengeMethodEnum || (CodeChallengeMethodEnum = {}));
3174
3174
 
3175
- var OpenfortErrorType;
3176
- (function (OpenfortErrorType) {
3177
- OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
3178
- OpenfortErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
3179
- OpenfortErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
3180
- OpenfortErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
3181
- OpenfortErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
3182
- OpenfortErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
3183
- OpenfortErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
3184
- OpenfortErrorType["MISSING_SESSION_SIGNER_ERROR"] = "MISSING_SESSION_SIGNER_ERROR";
3185
- OpenfortErrorType["MISSING_EMBEDDED_SIGNER_ERROR"] = "MISSING_EMBEDDED_SIGNER_ERROR";
3186
- OpenfortErrorType["MISSING_SIGNER_ERROR"] = "MISSING_SIGNER_ERROR";
3187
- })(OpenfortErrorType || (OpenfortErrorType = {}));
3188
- function isAPIError(error) {
3189
- return 'type' in error && 'message' in error;
3190
- }
3191
- class OpenfortError extends Error {
3192
- type;
3193
- constructor(message, type) {
3194
- super(message);
3195
- this.type = type;
3196
- }
3197
- }
3198
- const withOpenfortError = async (fn, customErrorType) => {
3199
- try {
3200
- return await fn();
3201
- }
3202
- catch (error) {
3203
- let errorMessage;
3204
- if (isAxiosError(error) && error.response?.data && isAPIError(error.response.data)) {
3205
- errorMessage = error.response.data.message;
3206
- }
3207
- else {
3208
- errorMessage = error.message;
3209
- }
3210
- throw new OpenfortError(errorMessage, customErrorType);
3211
- }
3212
- };
3213
-
3214
- const validateConfiguration = (configuration, requiredKeys, prefix) => {
3215
- const missingKeys = requiredKeys
3216
- .map((key) => !configuration[key] && key)
3217
- .filter((n) => n)
3218
- .join(', ');
3219
- if (missingKeys !== '') {
3220
- const errorMessage = prefix
3221
- ? `${prefix} - ${missingKeys} cannot be null`
3222
- : `${missingKeys} cannot be null`;
3223
- throw new OpenfortError(errorMessage, OpenfortErrorType.INVALID_CONFIGURATION);
3224
- }
3225
- };
3226
3175
  class OpenfortConfiguration {
3227
3176
  publishableKey;
3228
3177
  constructor(options) {
@@ -3250,17 +3199,12 @@ class SDKConfiguration {
3250
3199
  this.shieldConfiguration = shieldConfiguration;
3251
3200
  this.baseConfiguration = baseConfiguration;
3252
3201
  if (overrides) {
3253
- validateConfiguration(overrides, [
3254
- 'backendUrl',
3255
- 'iframeUrl',
3256
- 'shieldUrl',
3257
- ], 'overrides');
3258
- this.backendUrl = overrides.backendUrl;
3259
- this.iframeUrl = overrides.iframeUrl;
3260
- this.shieldUrl = overrides.shieldUrl;
3202
+ this.backendUrl = overrides.backendUrl || 'https://api.openfort.xyz';
3203
+ this.iframeUrl = overrides.iframeUrl || 'https://iframe.openfort.xyz';
3204
+ this.shieldUrl = overrides.shieldUrl || 'https://shield.openfort.xyz';
3261
3205
  this.openfortAPIConfig = {
3262
3206
  backend: createConfig({
3263
- basePath: overrides.backendUrl,
3207
+ basePath: overrides.backendUrl || 'https://api.openfort.xyz',
3264
3208
  accessToken: baseConfiguration.publishableKey,
3265
3209
  }),
3266
3210
  };
@@ -4719,6 +4663,69 @@ function announceProvider(detail) {
4719
4663
  window.addEventListener('eip6963:requestProvider', handler);
4720
4664
  }
4721
4665
 
4666
+ var OpenfortErrorType;
4667
+ (function (OpenfortErrorType) {
4668
+ OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
4669
+ OpenfortErrorType["INVALID_CONFIGURATION"] = "INVALID_CONFIGURATION";
4670
+ OpenfortErrorType["NOT_LOGGED_IN_ERROR"] = "NOT_LOGGED_IN_ERROR";
4671
+ OpenfortErrorType["REFRESH_TOKEN_ERROR"] = "REFRESH_TOKEN_ERROR";
4672
+ OpenfortErrorType["USER_REGISTRATION_ERROR"] = "USER_REGISTRATION_ERROR";
4673
+ OpenfortErrorType["LOGOUT_ERROR"] = "LOGOUT_ERROR";
4674
+ OpenfortErrorType["OPERATION_NOT_SUPPORTED_ERROR"] = "OPERATION_NOT_SUPPORTED_ERROR";
4675
+ OpenfortErrorType["MISSING_SESSION_SIGNER_ERROR"] = "MISSING_SESSION_SIGNER_ERROR";
4676
+ OpenfortErrorType["MISSING_EMBEDDED_SIGNER_ERROR"] = "MISSING_EMBEDDED_SIGNER_ERROR";
4677
+ OpenfortErrorType["MISSING_SIGNER_ERROR"] = "MISSING_SIGNER_ERROR";
4678
+ OpenfortErrorType["USER_NOT_AUTHORIZED_ON_ECOSYSTEM"] = "USER_NOT_AUTHORIZED_ON_ECOSYSTEM";
4679
+ })(OpenfortErrorType || (OpenfortErrorType = {}));
4680
+ function isAPIError(error) {
4681
+ return 'type' in error && 'message' in error;
4682
+ }
4683
+ class OpenfortError extends Error {
4684
+ type;
4685
+ data;
4686
+ constructor(message, type, data = {}) {
4687
+ super(message);
4688
+ this.type = type;
4689
+ this.data = data;
4690
+ }
4691
+ }
4692
+ const withOpenfortError = async (fn, customErrorType) => {
4693
+ try {
4694
+ return await fn();
4695
+ }
4696
+ catch (error) {
4697
+ let errorMessage;
4698
+ const data = {};
4699
+ let errorType = customErrorType.default;
4700
+ if (isAxiosError(error)) {
4701
+ const statusCode = error.response?.status;
4702
+ errorType = statusCode ? customErrorType[statusCode] || customErrorType.default : customErrorType.default;
4703
+ if (error.response?.data && error.response.data.error) {
4704
+ const jsonData = JSON.parse(JSON.stringify(error.response.data.error));
4705
+ // eslint-disable-next-line no-restricted-syntax
4706
+ for (const key in jsonData) {
4707
+ if (key !== 'message' && key !== 'type') {
4708
+ data[key] = jsonData[key];
4709
+ }
4710
+ }
4711
+ if (isAPIError(error.response.data)) {
4712
+ errorMessage = error.response.data.message;
4713
+ }
4714
+ else {
4715
+ errorMessage = error.message;
4716
+ }
4717
+ }
4718
+ else {
4719
+ errorMessage = error.message;
4720
+ }
4721
+ }
4722
+ else {
4723
+ errorMessage = error.message;
4724
+ }
4725
+ throw new OpenfortError(errorMessage, errorType, data);
4726
+ }
4727
+ };
4728
+
4722
4729
  var SignerType;
4723
4730
  (function (SignerType) {
4724
4731
  SignerType["EMBEDDED"] = "embedded";
@@ -4764,7 +4771,7 @@ class AuthManager {
4764
4771
  this.backendApiClients = backendApiClients;
4765
4772
  this.instanceManager = instanceManager;
4766
4773
  }
4767
- async initOAuth(provider, options) {
4774
+ async initOAuth(provider, options, ecosystemGame) {
4768
4775
  const usePooling = options?.usePooling ?? false;
4769
4776
  // eslint-disable-next-line no-param-reassign
4770
4777
  delete options?.usePooling;
@@ -4775,7 +4782,7 @@ class AuthManager {
4775
4782
  usePooling,
4776
4783
  },
4777
4784
  };
4778
- const result = await this.backendApiClients.authenticationApi.initOAuth(request);
4785
+ const result = await this.backendApiClients.authenticationApi.initOAuth(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4779
4786
  if (isBrowser() && options?.skipBrowserRedirect) {
4780
4787
  window.location.assign(result.data.url);
4781
4788
  }
@@ -4816,7 +4823,7 @@ class AuthManager {
4816
4823
  }
4817
4824
  throw new Error('Failed to pool OAuth, try again later');
4818
4825
  }
4819
- async authenticateThirdParty(provider, token, tokenType) {
4826
+ async authenticateThirdParty(provider, token, tokenType, ecosystemGame) {
4820
4827
  const request = {
4821
4828
  thirdPartyOAuthRequest: {
4822
4829
  provider,
@@ -4825,17 +4832,17 @@ class AuthManager {
4825
4832
  },
4826
4833
  };
4827
4834
  return withOpenfortError(async () => {
4828
- const response = await this.backendApiClients.authenticationApi.thirdParty(request);
4835
+ const response = await this.backendApiClients.authenticationApi.thirdParty(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4829
4836
  return response.data;
4830
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4837
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
4831
4838
  }
4832
- async initSIWE(address) {
4839
+ async initSIWE(address, ecosystemGame) {
4833
4840
  const request = {
4834
4841
  sIWERequest: {
4835
4842
  address,
4836
4843
  },
4837
4844
  };
4838
- const result = await this.backendApiClients.authenticationApi.initSIWE(request);
4845
+ const result = await this.backendApiClients.authenticationApi.initSIWE(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4839
4846
  return {
4840
4847
  address: result.data.address,
4841
4848
  nonce: result.data.nonce,
@@ -4854,9 +4861,20 @@ class AuthManager {
4854
4861
  return withOpenfortError(async () => {
4855
4862
  const response = await this.backendApiClients.authenticationApi.authenticateSIWE(request);
4856
4863
  return response.data;
4857
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4864
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
4858
4865
  }
4859
- async loginEmailPassword(email, password) {
4866
+ static getEcosystemGameOptsOrUndefined(ecosystemGame) {
4867
+ if (ecosystemGame) {
4868
+ return {
4869
+ headers: {
4870
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4871
+ 'x-game': ecosystemGame,
4872
+ },
4873
+ };
4874
+ }
4875
+ return undefined;
4876
+ }
4877
+ async loginEmailPassword(email, password, ecosystemGame) {
4860
4878
  const request = {
4861
4879
  loginRequest: {
4862
4880
  email,
@@ -4864,9 +4882,10 @@ class AuthManager {
4864
4882
  },
4865
4883
  };
4866
4884
  return withOpenfortError(async () => {
4867
- const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request);
4885
+ const response = await this.backendApiClients.authenticationApi.loginEmailPassword(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4868
4886
  return response.data;
4869
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4887
+ // eslint-disable-next-line @typescript-eslint/naming-convention
4888
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR, 403: OpenfortErrorType.USER_NOT_AUTHORIZED_ON_ECOSYSTEM });
4870
4889
  }
4871
4890
  async requestResetPassword(email, redirectUrl) {
4872
4891
  const verifier = base64URLEncode(crypto.randomBytes(32));
@@ -4903,7 +4922,7 @@ class AuthManager {
4903
4922
  },
4904
4923
  };
4905
4924
  await this.backendApiClients.authenticationApi.resetPassword(request);
4906
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4925
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
4907
4926
  }
4908
4927
  async requestEmailVerification(email, redirectUrl) {
4909
4928
  const verifier = base64URLEncode(crypto.randomBytes(32));
@@ -4939,9 +4958,9 @@ class AuthManager {
4939
4958
  },
4940
4959
  };
4941
4960
  await this.backendApiClients.authenticationApi.verifyEmail(request);
4942
- }, OpenfortErrorType.AUTHENTICATION_ERROR);
4961
+ }, { default: OpenfortErrorType.AUTHENTICATION_ERROR });
4943
4962
  }
4944
- async signupEmailPassword(email, password, name) {
4963
+ async signupEmailPassword(email, password, name, ecosystemGame) {
4945
4964
  const request = {
4946
4965
  signupRequest: {
4947
4966
  email,
@@ -4950,9 +4969,9 @@ class AuthManager {
4950
4969
  },
4951
4970
  };
4952
4971
  return withOpenfortError(async () => {
4953
- const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request);
4972
+ const response = await this.backendApiClients.authenticationApi.signupEmailPassword(request, AuthManager.getEcosystemGameOptsOrUndefined(ecosystemGame));
4954
4973
  return response.data;
4955
- }, OpenfortErrorType.USER_REGISTRATION_ERROR);
4974
+ }, { default: OpenfortErrorType.USER_REGISTRATION_ERROR });
4956
4975
  }
4957
4976
  async validateCredentials(forceRefresh) {
4958
4977
  const jwk = await this.instanceManager.getJWK();
@@ -4999,7 +5018,7 @@ class AuthManager {
4999
5018
  accessToken: response.data.token,
5000
5019
  refreshToken: response.data.refreshToken,
5001
5020
  };
5002
- }, OpenfortErrorType.REFRESH_TOKEN_ERROR);
5021
+ }, { default: OpenfortErrorType.REFRESH_TOKEN_ERROR });
5003
5022
  }
5004
5023
  async logout(accessToken, refreshToken) {
5005
5024
  const request = {
@@ -5015,7 +5034,7 @@ class AuthManager {
5015
5034
  'x-player-token': accessToken,
5016
5035
  },
5017
5036
  });
5018
- }, OpenfortErrorType.LOGOUT_ERROR);
5037
+ }, { default: OpenfortErrorType.LOGOUT_ERROR });
5019
5038
  }
5020
5039
  async getUser(accessToken) {
5021
5040
  // TODO: Add storage of user info
@@ -5028,7 +5047,7 @@ class AuthManager {
5028
5047
  });
5029
5048
  return response.data;
5030
5049
  }
5031
- async linkOAuth(provider, playerToken, options) {
5050
+ async linkOAuth(provider, playerToken, options, ecosystemGame) {
5032
5051
  const request = {
5033
5052
  oAuthInitRequest: {
5034
5053
  provider,
@@ -5041,6 +5060,8 @@ class AuthManager {
5041
5060
  authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
5042
5061
  // eslint-disable-next-line @typescript-eslint/naming-convention
5043
5062
  'x-player-token': playerToken,
5063
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5064
+ 'x-game': ecosystemGame || undefined,
5044
5065
  },
5045
5066
  });
5046
5067
  if (isBrowser() && !options?.skipBrowserRedirect) {
@@ -5114,7 +5135,7 @@ class AuthManager {
5114
5135
  });
5115
5136
  return authPlayerResponse.data;
5116
5137
  }
5117
- async linkEmail(email, password, accessToken) {
5138
+ async linkEmail(email, password, accessToken, ecosystemGame) {
5118
5139
  const request = {
5119
5140
  loginRequest: {
5120
5141
  email,
@@ -5126,6 +5147,8 @@ class AuthManager {
5126
5147
  authorization: `Bearer ${this.config.baseConfiguration.publishableKey}`,
5127
5148
  // eslint-disable-next-line @typescript-eslint/naming-convention
5128
5149
  'x-player-token': accessToken,
5150
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5151
+ 'x-game': ecosystemGame || undefined,
5129
5152
  },
5130
5153
  });
5131
5154
  return authPlayerResponse.data;
@@ -6108,11 +6131,12 @@ class Openfort {
6108
6131
  *
6109
6132
  * @param email - User's email.
6110
6133
  * @param password - User's password.
6134
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6111
6135
  * @returns An AuthResponse object containing authentication details.
6112
6136
  */
6113
- async logInWithEmailPassword({ email, password }) {
6137
+ async logInWithEmailPassword({ email, password, ecosystemGame }) {
6114
6138
  this.logout();
6115
- const result = await this.authManager.loginEmailPassword(email, password);
6139
+ const result = await this.authManager.loginEmailPassword(email, password, ecosystemGame);
6116
6140
  this.storeCredentials({
6117
6141
  player: result.player.id,
6118
6142
  accessToken: result.token,
@@ -6126,11 +6150,12 @@ class Openfort {
6126
6150
  * @param email - User's email.
6127
6151
  * @param password - User's password.
6128
6152
  * @param options - Additional options for the sign-up process.
6153
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6129
6154
  * @returns An AuthResponse object containing authentication details.
6130
6155
  */
6131
- async signUpWithEmailPassword({ email, password, options }) {
6156
+ async signUpWithEmailPassword({ email, password, options, ecosystemGame, }) {
6132
6157
  this.logout();
6133
- const result = await this.authManager.signupEmailPassword(email, password, options?.data.name);
6158
+ const result = await this.authManager.signupEmailPassword(email, password, options?.data.name, ecosystemGame);
6134
6159
  this.storeCredentials({
6135
6160
  player: result.player.id,
6136
6161
  accessToken: result.token,
@@ -6144,11 +6169,11 @@ class Openfort {
6144
6169
  * @param email - User's email.
6145
6170
  * @param password - User's password.
6146
6171
  * @param authToken - Authentication token.
6172
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6147
6173
  * @returns An AuthPlayerResponse object.
6148
6174
  */
6149
- async linkEmailPassword({ email, password, authToken }) {
6150
- const result = await this.authManager.linkEmail(email, password, authToken);
6151
- return result;
6175
+ async linkEmailPassword({ email, password, authToken, ecosystemGame, }) {
6176
+ return await this.authManager.linkEmail(email, password, authToken, ecosystemGame);
6152
6177
  }
6153
6178
  /**
6154
6179
  * Unlinks an email and password from an existing account using an authentication token.
@@ -6158,8 +6183,7 @@ class Openfort {
6158
6183
  * @returns An AuthPlayerResponse object.
6159
6184
  */
6160
6185
  async unlinkEmailPassword({ email, authToken }) {
6161
- const result = await this.authManager.unlinkEmail(email, authToken);
6162
- return result;
6186
+ return await this.authManager.unlinkEmail(email, authToken);
6163
6187
  }
6164
6188
  /**
6165
6189
  * Requests an email verification link.
@@ -6203,12 +6227,12 @@ class Openfort {
6203
6227
  *
6204
6228
  * @param provider - OAuth provider.
6205
6229
  * @param options - Additional options for initialization.
6230
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6206
6231
  * @returns An InitAuthResponse object.
6207
6232
  */
6208
- async initOAuth({ provider, options }) {
6233
+ async initOAuth({ provider, options, ecosystemGame }) {
6209
6234
  this.logout();
6210
- const authResponse = await this.authManager.initOAuth(provider, options);
6211
- return authResponse;
6235
+ return await this.authManager.initOAuth(provider, options, ecosystemGame);
6212
6236
  }
6213
6237
  /**
6214
6238
  * Initializes an OAuth linking process.
@@ -6216,10 +6240,11 @@ class Openfort {
6216
6240
  * @param provider - OAuth provider.
6217
6241
  * @param authToken - Authentication token.
6218
6242
  * @param options - Additional options for initialization.
6243
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6219
6244
  * @returns An InitAuthResponse object.
6220
6245
  */
6221
- async initLinkOAuth({ provider, authToken, options }) {
6222
- return await this.authManager.linkOAuth(provider, authToken, options);
6246
+ async initLinkOAuth({ provider, authToken, options, ecosystemGame, }) {
6247
+ return await this.authManager.linkOAuth(provider, authToken, options, ecosystemGame);
6223
6248
  }
6224
6249
  /**
6225
6250
  * Unlinks an OAuth provider from the account.
@@ -6229,8 +6254,7 @@ class Openfort {
6229
6254
  * @returns An AuthPlayerResponse object.
6230
6255
  */
6231
6256
  async unlinkOAuth({ provider, authToken }) {
6232
- const result = await this.authManager.unlinkOAuth(provider, authToken);
6233
- return result;
6257
+ return await this.authManager.unlinkOAuth(provider, authToken);
6234
6258
  }
6235
6259
  /**
6236
6260
  * Polls for OAuth authentication completion.
@@ -6247,10 +6271,11 @@ class Openfort {
6247
6271
  * @param provider - Third-party OAuth provider.
6248
6272
  * @param token - OAuth token.
6249
6273
  * @param tokenType - Type of the OAuth token.
6274
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6250
6275
  * @returns An AuthPlayerResponse object.
6251
6276
  */
6252
- async authenticateWithThirdPartyProvider({ provider, token, tokenType }) {
6253
- const result = await this.authManager.authenticateThirdParty(provider, token, tokenType);
6277
+ async authenticateWithThirdPartyProvider({ provider, token, tokenType, ecosystemGame, }) {
6278
+ const result = await this.authManager.authenticateThirdParty(provider, token, tokenType, ecosystemGame);
6254
6279
  this.instanceManager.setAccessToken({
6255
6280
  token,
6256
6281
  thirdPartyProvider: provider,
@@ -6266,10 +6291,11 @@ class Openfort {
6266
6291
  * Initializes Sign-In with Ethereum (SIWE).
6267
6292
  *
6268
6293
  * @param address - Ethereum address.
6294
+ * @param ecosystemGame - In case of ecosystem, the game that wants to authenticate.
6269
6295
  * @returns A SIWEInitResponse object.
6270
6296
  */
6271
- async initSIWE({ address }) {
6272
- return await this.authManager.initSIWE(address);
6297
+ async initSIWE({ address, ecosystemGame }) {
6298
+ return await this.authManager.initSIWE(address, ecosystemGame);
6273
6299
  }
6274
6300
  /**
6275
6301
  * Authenticates using Sign-In with Ethereum (SIWE).
@@ -6303,8 +6329,7 @@ class Openfort {
6303
6329
  * @returns An AuthPlayerResponse object.
6304
6330
  */
6305
6331
  async linkWallet({ signature, message, walletClientType, connectorType, authToken, }) {
6306
- const result = await this.authManager.linkWallet(signature, message, walletClientType, connectorType, authToken);
6307
- return result;
6332
+ return await this.authManager.linkWallet(signature, message, walletClientType, connectorType, authToken);
6308
6333
  }
6309
6334
  /**
6310
6335
  * Unlinks a wallet.
@@ -6314,8 +6339,7 @@ class Openfort {
6314
6339
  * @returns An AuthPlayerResponse object.
6315
6340
  */
6316
6341
  async unlinkWallet({ address, authToken }) {
6317
- const result = await this.authManager.unlinkWallet(address, authToken);
6318
- return result;
6342
+ return await this.authManager.unlinkWallet(address, authToken);
6319
6343
  }
6320
6344
  /**
6321
6345
  * Stores authentication credentials.
@@ -6612,4 +6636,4 @@ class Openfort {
6612
6636
  }
6613
6637
  }
6614
6638
 
6615
- export { AuthType, BasicAuthProvider, EmbeddedState, OAuthProvider, OpenfortConfiguration, OpenfortError, SDKConfiguration, ShieldAuthType, ShieldConfiguration, ThirdPartyOAuthProvider, TokenType, Openfort as default };
6639
+ export { AuthType, BasicAuthProvider, EmbeddedState, OAuthProvider, OpenfortConfiguration, OpenfortError, OpenfortErrorType, SDKConfiguration, ShieldAuthType, ShieldConfiguration, ThirdPartyOAuthProvider, TokenType, Openfort as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "0.7.14",
3
+ "version": "0.7.15",
4
4
  "author": "Openfort (https://www.openfort.xyz)",
5
5
  "bugs": "https://github.com/openfort-xyz/openfort-js/issues",
6
6
  "repository": "openfort-xyz/openfort-js.git",