@cosmotech/core 1.19.0 → 1.19.1-beta.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.
Binary file
package/dist/index.cjs.js CHANGED
@@ -57312,6 +57312,23 @@ var checkInit = () => {
57312
57312
  }
57313
57313
  return true;
57314
57314
  };
57315
+ var getActiveAccountFromMSAL = () => {
57316
+ var accountId = readFromStorage('authAccountId');
57317
+ if (!accountId) {
57318
+ return;
57319
+ }
57320
+ var allAccounts = msalApp.getAllAccounts();
57321
+ if (!allAccounts.length === 0) {
57322
+ console.warn('WARNING: no accounts found, please log in');
57323
+ return;
57324
+ }
57325
+ var account = allAccounts.find(account => account.homeAccountId === accountId);
57326
+ if (account === undefined) {
57327
+ console.warn("WARNING: no account found with id \"".concat(accountId, "\", cannot retrieve account"));
57328
+ return;
57329
+ }
57330
+ return account;
57331
+ };
57315
57332
  var redirectOnAuthSuccess = () => {
57316
57333
  var _config$msalConfig$au, _config;
57317
57334
  window.location.href = (_config$msalConfig$au = (_config = config) === null || _config === void 0 || (_config = _config.msalConfig) === null || _config === void 0 || (_config = _config.auth) === null || _config === void 0 ? void 0 : _config.redirectUri) !== null && _config$msalConfig$au !== void 0 ? _config$msalConfig$au : '/';
@@ -57347,7 +57364,6 @@ var _acquireTokensByRequestAndAccount = /*#__PURE__*/function () {
57347
57364
  // a silent request
57348
57365
  var acquireTokens = /*#__PURE__*/function () {
57349
57366
  var _ref3 = _asyncToGenerator(function* () {
57350
- var _msalApp$getAllAccoun;
57351
57367
  var forceRefresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
57352
57368
  if (!checkInit()) return;
57353
57369
  if (!forceRefresh && readFromStorage('authAuthenticated') === 'true') {
@@ -57358,7 +57374,7 @@ var acquireTokens = /*#__PURE__*/function () {
57358
57374
  idToken
57359
57375
  };
57360
57376
  }
57361
- var account = (_msalApp$getAllAccoun = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun === void 0 ? void 0 : _msalApp$getAllAccoun[0];
57377
+ var account = getActiveAccountFromMSAL();
57362
57378
  if (account === undefined) return;
57363
57379
  var tokens = yield _acquireTokensByRequestAndAccount(config.accessRequest, account);
57364
57380
  _updateTokensInStorage(tokens);
@@ -57370,13 +57386,15 @@ var acquireTokens = /*#__PURE__*/function () {
57370
57386
  }();
57371
57387
  var handleResponse = response => {
57372
57388
  if (response != null) {
57389
+ var _account$idTokenClaim, _account$idTokenClaim2;
57373
57390
  var account = response.account;
57374
57391
  _updateTokensInStorage(response);
57375
57392
  writeToStorage('authIdTokenPopup', response.idToken);
57376
57393
  writeToStorage('authAuthenticated', 'true');
57377
57394
  writeToStorage('authAccountId', account.homeAccountId);
57395
+ writeToStorage('authEmail', (_account$idTokenClaim = account.idTokenClaims) === null || _account$idTokenClaim === void 0 ? void 0 : _account$idTokenClaim.email);
57378
57396
  authData.accountId = account.homeAccountId;
57379
- authData.userEmail = account.username; // In MSAL account data, username property contains user email
57397
+ authData.userEmail = (_account$idTokenClaim2 = account.idTokenClaims) === null || _account$idTokenClaim2 === void 0 ? void 0 : _account$idTokenClaim2.email;
57380
57398
  authData.username = account.name;
57381
57399
  authData.userId = account.localAccountId;
57382
57400
  redirectOnAuthSuccess();
@@ -57402,6 +57420,7 @@ var signOut = () => {
57402
57420
  clearFromStorage('authIdToken');
57403
57421
  clearFromStorage('authAccessToken');
57404
57422
  clearFromStorage('authAccountId');
57423
+ clearFromStorage('authEmail');
57405
57424
  writeToStorage('authAuthenticated', 'false');
57406
57425
  var logoutRequest = {
57407
57426
  account: msalApp.getAccountByHomeId((_authData$accountId = authData.accountId) !== null && _authData$accountId !== void 0 ? _authData$accountId : accountId),
@@ -57493,20 +57512,21 @@ var refreshTokens = /*#__PURE__*/function () {
57493
57512
  };
57494
57513
  }();
57495
57514
  var getUserEmail = () => {
57496
- var _authData$userEmail, _msalApp$getAllAccoun2;
57515
+ var _ref6, _readFromStorage;
57497
57516
  if (!checkInit()) return;
57517
+ var account = getActiveAccountFromMSAL();
57498
57518
  // Note: account data from MSAL seems to contain user email in the 'username' property
57499
- return (_authData$userEmail = authData === null || authData === void 0 ? void 0 : authData.userEmail) !== null && _authData$userEmail !== void 0 ? _authData$userEmail : (_msalApp$getAllAccoun2 = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun2 === void 0 || (_msalApp$getAllAccoun2 = _msalApp$getAllAccoun2[0]) === null || _msalApp$getAllAccoun2 === void 0 ? void 0 : _msalApp$getAllAccoun2.username;
57519
+ return (_ref6 = (_readFromStorage = readFromStorage('authEmail')) !== null && _readFromStorage !== void 0 ? _readFromStorage : authData === null || authData === void 0 ? void 0 : authData.userEmail) !== null && _ref6 !== void 0 ? _ref6 : account === null || account === void 0 ? void 0 : account.username;
57500
57520
  };
57501
57521
  var getUserName = () => {
57502
- var _authData$name, _msalApp$getAllAccoun3;
57522
+ var _authData$name, _getActiveAccountFrom;
57503
57523
  if (!checkInit()) return;
57504
- return (_authData$name = authData === null || authData === void 0 ? void 0 : authData.name) !== null && _authData$name !== void 0 ? _authData$name : (_msalApp$getAllAccoun3 = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun3 === void 0 || (_msalApp$getAllAccoun3 = _msalApp$getAllAccoun3[0]) === null || _msalApp$getAllAccoun3 === void 0 ? void 0 : _msalApp$getAllAccoun3.name;
57524
+ return (_authData$name = authData === null || authData === void 0 ? void 0 : authData.name) !== null && _authData$name !== void 0 ? _authData$name : (_getActiveAccountFrom = getActiveAccountFromMSAL()) === null || _getActiveAccountFrom === void 0 ? void 0 : _getActiveAccountFrom.name;
57505
57525
  };
57506
57526
  var getUserId = () => {
57507
- var _authData$userId, _msalApp$getAllAccoun4;
57527
+ var _authData$userId, _getActiveAccountFrom2;
57508
57528
  if (!checkInit()) return;
57509
- return (_authData$userId = authData === null || authData === void 0 ? void 0 : authData.userId) !== null && _authData$userId !== void 0 ? _authData$userId : (_msalApp$getAllAccoun4 = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun4 === void 0 || (_msalApp$getAllAccoun4 = _msalApp$getAllAccoun4[0]) === null || _msalApp$getAllAccoun4 === void 0 ? void 0 : _msalApp$getAllAccoun4.localAccountId;
57529
+ return (_authData$userId = authData === null || authData === void 0 ? void 0 : authData.userId) !== null && _authData$userId !== void 0 ? _authData$userId : (_getActiveAccountFrom2 = getActiveAccountFromMSAL()) === null || _getActiveAccountFrom2 === void 0 ? void 0 : _getActiveAccountFrom2.localAccountId;
57510
57530
  };
57511
57531
  var getUserRoles = () => {
57512
57532
  if (!checkInit()) return;
package/dist/index.esm.js CHANGED
@@ -57310,6 +57310,23 @@ var checkInit = () => {
57310
57310
  }
57311
57311
  return true;
57312
57312
  };
57313
+ var getActiveAccountFromMSAL = () => {
57314
+ var accountId = readFromStorage('authAccountId');
57315
+ if (!accountId) {
57316
+ return;
57317
+ }
57318
+ var allAccounts = msalApp.getAllAccounts();
57319
+ if (!allAccounts.length === 0) {
57320
+ console.warn('WARNING: no accounts found, please log in');
57321
+ return;
57322
+ }
57323
+ var account = allAccounts.find(account => account.homeAccountId === accountId);
57324
+ if (account === undefined) {
57325
+ console.warn("WARNING: no account found with id \"".concat(accountId, "\", cannot retrieve account"));
57326
+ return;
57327
+ }
57328
+ return account;
57329
+ };
57313
57330
  var redirectOnAuthSuccess = () => {
57314
57331
  var _config$msalConfig$au, _config;
57315
57332
  window.location.href = (_config$msalConfig$au = (_config = config) === null || _config === void 0 || (_config = _config.msalConfig) === null || _config === void 0 || (_config = _config.auth) === null || _config === void 0 ? void 0 : _config.redirectUri) !== null && _config$msalConfig$au !== void 0 ? _config$msalConfig$au : '/';
@@ -57345,7 +57362,6 @@ var _acquireTokensByRequestAndAccount = /*#__PURE__*/function () {
57345
57362
  // a silent request
57346
57363
  var acquireTokens = /*#__PURE__*/function () {
57347
57364
  var _ref3 = _asyncToGenerator(function* () {
57348
- var _msalApp$getAllAccoun;
57349
57365
  var forceRefresh = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
57350
57366
  if (!checkInit()) return;
57351
57367
  if (!forceRefresh && readFromStorage('authAuthenticated') === 'true') {
@@ -57356,7 +57372,7 @@ var acquireTokens = /*#__PURE__*/function () {
57356
57372
  idToken
57357
57373
  };
57358
57374
  }
57359
- var account = (_msalApp$getAllAccoun = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun === void 0 ? void 0 : _msalApp$getAllAccoun[0];
57375
+ var account = getActiveAccountFromMSAL();
57360
57376
  if (account === undefined) return;
57361
57377
  var tokens = yield _acquireTokensByRequestAndAccount(config.accessRequest, account);
57362
57378
  _updateTokensInStorage(tokens);
@@ -57368,13 +57384,15 @@ var acquireTokens = /*#__PURE__*/function () {
57368
57384
  }();
57369
57385
  var handleResponse = response => {
57370
57386
  if (response != null) {
57387
+ var _account$idTokenClaim, _account$idTokenClaim2;
57371
57388
  var account = response.account;
57372
57389
  _updateTokensInStorage(response);
57373
57390
  writeToStorage('authIdTokenPopup', response.idToken);
57374
57391
  writeToStorage('authAuthenticated', 'true');
57375
57392
  writeToStorage('authAccountId', account.homeAccountId);
57393
+ writeToStorage('authEmail', (_account$idTokenClaim = account.idTokenClaims) === null || _account$idTokenClaim === void 0 ? void 0 : _account$idTokenClaim.email);
57376
57394
  authData.accountId = account.homeAccountId;
57377
- authData.userEmail = account.username; // In MSAL account data, username property contains user email
57395
+ authData.userEmail = (_account$idTokenClaim2 = account.idTokenClaims) === null || _account$idTokenClaim2 === void 0 ? void 0 : _account$idTokenClaim2.email;
57378
57396
  authData.username = account.name;
57379
57397
  authData.userId = account.localAccountId;
57380
57398
  redirectOnAuthSuccess();
@@ -57400,6 +57418,7 @@ var signOut = () => {
57400
57418
  clearFromStorage('authIdToken');
57401
57419
  clearFromStorage('authAccessToken');
57402
57420
  clearFromStorage('authAccountId');
57421
+ clearFromStorage('authEmail');
57403
57422
  writeToStorage('authAuthenticated', 'false');
57404
57423
  var logoutRequest = {
57405
57424
  account: msalApp.getAccountByHomeId((_authData$accountId = authData.accountId) !== null && _authData$accountId !== void 0 ? _authData$accountId : accountId),
@@ -57491,20 +57510,21 @@ var refreshTokens = /*#__PURE__*/function () {
57491
57510
  };
57492
57511
  }();
57493
57512
  var getUserEmail = () => {
57494
- var _authData$userEmail, _msalApp$getAllAccoun2;
57513
+ var _ref6, _readFromStorage;
57495
57514
  if (!checkInit()) return;
57515
+ var account = getActiveAccountFromMSAL();
57496
57516
  // Note: account data from MSAL seems to contain user email in the 'username' property
57497
- return (_authData$userEmail = authData === null || authData === void 0 ? void 0 : authData.userEmail) !== null && _authData$userEmail !== void 0 ? _authData$userEmail : (_msalApp$getAllAccoun2 = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun2 === void 0 || (_msalApp$getAllAccoun2 = _msalApp$getAllAccoun2[0]) === null || _msalApp$getAllAccoun2 === void 0 ? void 0 : _msalApp$getAllAccoun2.username;
57517
+ return (_ref6 = (_readFromStorage = readFromStorage('authEmail')) !== null && _readFromStorage !== void 0 ? _readFromStorage : authData === null || authData === void 0 ? void 0 : authData.userEmail) !== null && _ref6 !== void 0 ? _ref6 : account === null || account === void 0 ? void 0 : account.username;
57498
57518
  };
57499
57519
  var getUserName = () => {
57500
- var _authData$name, _msalApp$getAllAccoun3;
57520
+ var _authData$name, _getActiveAccountFrom;
57501
57521
  if (!checkInit()) return;
57502
- return (_authData$name = authData === null || authData === void 0 ? void 0 : authData.name) !== null && _authData$name !== void 0 ? _authData$name : (_msalApp$getAllAccoun3 = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun3 === void 0 || (_msalApp$getAllAccoun3 = _msalApp$getAllAccoun3[0]) === null || _msalApp$getAllAccoun3 === void 0 ? void 0 : _msalApp$getAllAccoun3.name;
57522
+ return (_authData$name = authData === null || authData === void 0 ? void 0 : authData.name) !== null && _authData$name !== void 0 ? _authData$name : (_getActiveAccountFrom = getActiveAccountFromMSAL()) === null || _getActiveAccountFrom === void 0 ? void 0 : _getActiveAccountFrom.name;
57503
57523
  };
57504
57524
  var getUserId = () => {
57505
- var _authData$userId, _msalApp$getAllAccoun4;
57525
+ var _authData$userId, _getActiveAccountFrom2;
57506
57526
  if (!checkInit()) return;
57507
- return (_authData$userId = authData === null || authData === void 0 ? void 0 : authData.userId) !== null && _authData$userId !== void 0 ? _authData$userId : (_msalApp$getAllAccoun4 = msalApp.getAllAccounts()) === null || _msalApp$getAllAccoun4 === void 0 || (_msalApp$getAllAccoun4 = _msalApp$getAllAccoun4[0]) === null || _msalApp$getAllAccoun4 === void 0 ? void 0 : _msalApp$getAllAccoun4.localAccountId;
57527
+ return (_authData$userId = authData === null || authData === void 0 ? void 0 : authData.userId) !== null && _authData$userId !== void 0 ? _authData$userId : (_getActiveAccountFrom2 = getActiveAccountFromMSAL()) === null || _getActiveAccountFrom2 === void 0 ? void 0 : _getActiveAccountFrom2.localAccountId;
57508
57528
  };
57509
57529
  var getUserRoles = () => {
57510
57530
  if (!checkInit()) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmotech/core",
3
- "version": "1.19.0",
3
+ "version": "1.19.1-beta.1",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",