@cosmotech/core 1.19.1-beta.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);
@@ -57496,20 +57512,21 @@ var refreshTokens = /*#__PURE__*/function () {
57496
57512
  };
57497
57513
  }();
57498
57514
  var getUserEmail = () => {
57499
- var _ref6, _readFromStorage, _msalApp$getAllAccoun2;
57515
+ var _ref6, _readFromStorage;
57500
57516
  if (!checkInit()) return;
57517
+ var account = getActiveAccountFromMSAL();
57501
57518
  // Note: account data from MSAL seems to contain user email in the 'username' property
57502
- return (_ref6 = (_readFromStorage = readFromStorage('authEmail')) !== null && _readFromStorage !== void 0 ? _readFromStorage : authData === null || authData === void 0 ? void 0 : authData.userEmail) !== null && _ref6 !== void 0 ? _ref6 : (_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;
57503
57520
  };
57504
57521
  var getUserName = () => {
57505
- var _authData$name, _msalApp$getAllAccoun3;
57522
+ var _authData$name, _getActiveAccountFrom;
57506
57523
  if (!checkInit()) return;
57507
- 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;
57508
57525
  };
57509
57526
  var getUserId = () => {
57510
- var _authData$userId, _msalApp$getAllAccoun4;
57527
+ var _authData$userId, _getActiveAccountFrom2;
57511
57528
  if (!checkInit()) return;
57512
- 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;
57513
57530
  };
57514
57531
  var getUserRoles = () => {
57515
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);
@@ -57494,20 +57510,21 @@ var refreshTokens = /*#__PURE__*/function () {
57494
57510
  };
57495
57511
  }();
57496
57512
  var getUserEmail = () => {
57497
- var _ref6, _readFromStorage, _msalApp$getAllAccoun2;
57513
+ var _ref6, _readFromStorage;
57498
57514
  if (!checkInit()) return;
57515
+ var account = getActiveAccountFromMSAL();
57499
57516
  // Note: account data from MSAL seems to contain user email in the 'username' property
57500
- return (_ref6 = (_readFromStorage = readFromStorage('authEmail')) !== null && _readFromStorage !== void 0 ? _readFromStorage : authData === null || authData === void 0 ? void 0 : authData.userEmail) !== null && _ref6 !== void 0 ? _ref6 : (_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;
57501
57518
  };
57502
57519
  var getUserName = () => {
57503
- var _authData$name, _msalApp$getAllAccoun3;
57520
+ var _authData$name, _getActiveAccountFrom;
57504
57521
  if (!checkInit()) return;
57505
- 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;
57506
57523
  };
57507
57524
  var getUserId = () => {
57508
- var _authData$userId, _msalApp$getAllAccoun4;
57525
+ var _authData$userId, _getActiveAccountFrom2;
57509
57526
  if (!checkInit()) return;
57510
- 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;
57511
57528
  };
57512
57529
  var getUserRoles = () => {
57513
57530
  if (!checkInit()) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmotech/core",
3
- "version": "1.19.1-beta.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",