ptech-shell-dev 1.6.5 → 1.6.7

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.
Files changed (2) hide show
  1. package/dist/index.js +31 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1779,6 +1779,17 @@ function toUserAccessToken(response, fallbackScopes) {
1779
1779
  expiresAt: response.expiresOn ? response.expiresOn.getTime() : void 0
1780
1780
  };
1781
1781
  }
1782
+ function getUserSnapshotCacheKey(user) {
1783
+ const rolesKey = Array.isArray(user.roles) ? [...user.roles].sort().join(",") : "";
1784
+ return [
1785
+ user.id ?? "",
1786
+ user.username ?? "",
1787
+ user.email ?? "",
1788
+ user.name ?? "",
1789
+ user.tenantId ?? "",
1790
+ rolesKey
1791
+ ].join("|");
1792
+ }
1782
1793
  function createMsalUserService(options) {
1783
1794
  const {
1784
1795
  msal,
@@ -1792,6 +1803,8 @@ function createMsalUserService(options) {
1792
1803
  let callbackId = null;
1793
1804
  let cachedIdToken;
1794
1805
  let cachedIdTokenClaims;
1806
+ let cachedUserSnapshotKey = null;
1807
+ let cachedUserSnapshot = null;
1795
1808
  function emitChanged() {
1796
1809
  for (const listener of listeners) {
1797
1810
  listener();
@@ -1829,6 +1842,21 @@ function createMsalUserService(options) {
1829
1842
  }
1830
1843
  return null;
1831
1844
  }
1845
+ function mapUserSnapshot(account) {
1846
+ if (!account) {
1847
+ cachedUserSnapshotKey = null;
1848
+ cachedUserSnapshot = null;
1849
+ return null;
1850
+ }
1851
+ const mappedUser = mapUser(account);
1852
+ const cacheKey = getUserSnapshotCacheKey(mappedUser);
1853
+ if (cachedUserSnapshotKey === cacheKey && cachedUserSnapshot) {
1854
+ return cachedUserSnapshot;
1855
+ }
1856
+ cachedUserSnapshotKey = cacheKey;
1857
+ cachedUserSnapshot = mappedUser;
1858
+ return mappedUser;
1859
+ }
1832
1860
  function attachMsalCallback() {
1833
1861
  if (callbackId || !msal.addEventCallback) {
1834
1862
  return;
@@ -1889,7 +1917,7 @@ function createMsalUserService(options) {
1889
1917
  return {
1890
1918
  getSnapshot: () => {
1891
1919
  const account = normalizeActiveAccount();
1892
- return account ? mapUser(account) : null;
1920
+ return mapUserSnapshot(account);
1893
1921
  },
1894
1922
  getSession: () => {
1895
1923
  const account = normalizeActiveAccount();
@@ -1945,6 +1973,8 @@ function createMsalUserService(options) {
1945
1973
  }
1946
1974
  cachedIdToken = void 0;
1947
1975
  cachedIdTokenClaims = void 0;
1976
+ cachedUserSnapshotKey = null;
1977
+ cachedUserSnapshot = null;
1948
1978
  emitChanged();
1949
1979
  },
1950
1980
  subscribe: (listener) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ptech-shell-dev",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "description": "Standalone/mock shell service implementations for Module Federation apps.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",