@imtbl/sdk 0.23.0-alpha → 0.23.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/passport.js CHANGED
@@ -1785,7 +1785,7 @@ class MultiRollupApiClients {
1785
1785
  }
1786
1786
 
1787
1787
  // eslint-disable-next-line @typescript-eslint/naming-convention
1788
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.23.0-alpha' };
1788
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.23.2-alpha.1' };
1789
1789
  const createConfig = ({ basePath, headers, }) => {
1790
1790
  if (!basePath.trim()) {
1791
1791
  throw Error('basePath can not be empty');
@@ -1841,7 +1841,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
1841
1841
  chainID,
1842
1842
  coreContractAddress,
1843
1843
  registrationContractAddress,
1844
- sdkVersion: 'ts-immutable-sdk-0.23.0-alpha',
1844
+ sdkVersion: 'ts-immutable-sdk-0.23.2-alpha.1',
1845
1845
  });
1846
1846
  /**
1847
1847
  * Sets `sdkVersion` at the time of build
@@ -6686,14 +6686,25 @@ class AuthManager {
6686
6686
  this.deviceCredentialsManager.clearCredentials();
6687
6687
  }, PassportErrorType.LOGOUT_ERROR);
6688
6688
  }
6689
- async loginSilent() {
6690
- return withPassportError(async () => this.getUser(), PassportErrorType.SILENT_LOGIN_ERROR);
6689
+ async loginSilent({ forceRefresh } = { forceRefresh: false }) {
6690
+ // eslint-disable-next-line arrow-body-style
6691
+ return withPassportError(async () => {
6692
+ return this.getUser({ forceRefresh });
6693
+ }, PassportErrorType.SILENT_LOGIN_ERROR);
6691
6694
  }
6692
- async getWebUser() {
6695
+ /**
6696
+ * Get the user from the cache or refresh the token if it's expired.
6697
+ * @param forceRefresh If set to true, force an HTTP call to the OIDC server's authorization endpoint. This call will
6698
+ * throw an error if there's no refresh token.
6699
+ */
6700
+ async getWebUser({ forceRefresh = false }) {
6701
+ if (forceRefresh) {
6702
+ const newOidcUser = await this.userManager.signinSilent();
6703
+ return newOidcUser ? AuthManager.mapOidcUserToDomainModel(newOidcUser) : null;
6704
+ }
6693
6705
  const oidcUser = await this.userManager.getUser();
6694
- if (!oidcUser) {
6706
+ if (!oidcUser)
6695
6707
  return null;
6696
- }
6697
6708
  const tokenExpired = isTokenExpired(oidcUser);
6698
6709
  if (!tokenExpired) {
6699
6710
  return AuthManager.mapOidcUserToDomainModel(oidcUser);
@@ -6706,9 +6717,9 @@ class AuthManager {
6706
6717
  }
6707
6718
  return null;
6708
6719
  }
6709
- async getUser() {
6720
+ async getUser({ forceRefresh } = { forceRefresh: false }) {
6710
6721
  return withPassportError(async () => {
6711
- const user = await this.getWebUser();
6722
+ const user = await this.getWebUser({ forceRefresh });
6712
6723
  if (user) {
6713
6724
  return user;
6714
6725
  }
@@ -7486,7 +7497,7 @@ class PassportImxProviderFactory {
7486
7497
  }, jwt);
7487
7498
  // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
7488
7499
  const updatedUser = await retryWithDelay(async () => {
7489
- const user = await this.authManager.loginSilent();
7500
+ const user = await this.authManager.loginSilent({ forceRefresh: true }); // force refresh to get updated user info
7490
7501
  const metadataExists = !!user?.imx;
7491
7502
  if (metadataExists) {
7492
7503
  return user;
@@ -7986,7 +7997,7 @@ async function registerZkEvmUser({ authManager, config, magicProvider, multiRoll
7986
7997
  user = await authManager.refreshToken(credentials.refresh_token);
7987
7998
  }
7988
7999
  else {
7989
- user = await authManager.loginSilent();
8000
+ user = await authManager.loginSilent({ forceRefresh: true });
7990
8001
  }
7991
8002
  if (!user?.zkEvm) {
7992
8003
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, 'Failed to refresh user details');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.23.0-alpha",
4
+ "version": "0.23.2-alpha.1",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",