@cosmotech/core 1.19.1 → 2.0.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## **2.0.0** <sub><sup>2025-01-23 (ba70eef...4d0f1df)</sup></sub>
2
+
3
+ ### Features
4
+
5
+ - add min & max validation in ValidationUtils and AgGridUtils file uploads ([c7f0b3d](https://github.com/Cosmo-Tech/webapp-component-core/commit/c7f0b3d))
6
+
7
+ ### Bug Fixes
8
+
9
+ - fix user email retrieved from keycloak accounts ([ba70eef](https://github.com/Cosmo-Tech/webapp-component-core/commit/ba70eef))
10
+ - remove forbidden characters constraint in scenario names ([9b67422](https://github.com/Cosmo-Tech/webapp-component-core/commit/9b67422))
11
+ - modify isValid function to return error structures on validation fail ([ce4ba32](https://github.com/Cosmo-Tech/webapp-component-core/commit/ce4ba32))
12
+
13
+ ### BREAKING CHANGES
14
+
15
+ - the function isValid now returns an Error object when the validation failed, or true if it succeeded. The Error object contains three fields: summary, context and location (the last one is set to null by the isValid function).
16
+
1
17
  ## **1.19.1** <sub><sup>2024-11-07 (6023cdc...6023cdc)</sup></sub>
2
18
 
3
19
  - update dependencies
package/dist/index.cjs.js CHANGED
@@ -13196,6 +13196,34 @@ var DateUtils = {
13196
13196
 
13197
13197
  // Copyright (c) Cosmo Tech.
13198
13198
  // Licensed under the MIT license.
13199
+
13200
+ let Error$1 = class Error {
13201
+ constructor(summary, loc, context) {
13202
+ this.summary = summary;
13203
+ this.loc = loc;
13204
+ this.context = context;
13205
+ }
13206
+ toString() {
13207
+ return "Summary: ".concat(this.summary, "\n") + "Loc: ".concat(this.loc, "\n") + "Context: ".concat(this.context);
13208
+ }
13209
+ };
13210
+
13211
+ // Copyright (c) Cosmo Tech.
13212
+ // Licensed under the MIT license.
13213
+ var forgeTypeError = (value, type, options) => {
13214
+ var expected;
13215
+ if (type === 'enum') expected = "Expected values: [".concat(options.enumValues.join(), "]");else if (type === 'date') expected = "Expected format: ".concat(options === null || options === void 0 ? void 0 : options.dateFormat);
13216
+ var error = new Error$1("Incorrect ".concat(type, " value"), null, "Incorrect value: \"".concat(value, "\" for type ").concat(type));
13217
+ if (expected) error.context += '\n' + expected;
13218
+ return error;
13219
+ };
13220
+ var forgeConfigError = errorContext => {
13221
+ console.warn("Configuration error: ".concat(errorContext));
13222
+ return {
13223
+ summary: 'Configuration error',
13224
+ context: errorContext
13225
+ };
13226
+ };
13199
13227
  var isBool = dataStr => {
13200
13228
  return validator.isBoolean(dataStr, {
13201
13229
  loose: true
@@ -13216,6 +13244,41 @@ var isNumber = dataStr => {
13216
13244
  var isString = data => {
13217
13245
  return typeof data === 'string';
13218
13246
  };
13247
+ var isInRange = (value, minValue, maxValue) => {
13248
+ if (value == null) return null;
13249
+ var errorMessage;
13250
+ if (minValue != null && value < minValue) errorMessage = "Value \"".concat(value, "\" should be greater than ").concat(minValue);
13251
+ if (maxValue != null && value > maxValue) errorMessage = "Value \"".concat(value, "\" should be less than ").concat(maxValue);
13252
+ if (errorMessage == null) return true;
13253
+ return new Error$1("Value out of range", null, errorMessage);
13254
+ };
13255
+ var castToDate = (dateOrStrValue, dateFormat) => {
13256
+ if (dateOrStrValue == null) return;
13257
+ if (dateOrStrValue instanceof Date) return dateOrStrValue;
13258
+ if (typeof dateOrStrValue !== 'string') {
13259
+ console.warn("Configuration error: ".concat(dateOrStrValue, " is not a string nor a Date."));
13260
+ return;
13261
+ }
13262
+ if (!isDate(dateOrStrValue, dateFormat)) {
13263
+ console.warn("Configuration error: ".concat(forgeTypeError(dateOrStrValue, 'date', {
13264
+ dateFormat
13265
+ }).context, "."));
13266
+ return;
13267
+ }
13268
+ return DateUtils.parse(dateOrStrValue, dateFormat);
13269
+ };
13270
+ var isDateInRange = (value, minValue, maxValue, dateFormat) => {
13271
+ var minDate = castToDate(minValue, dateFormat);
13272
+ var maxDate = castToDate(maxValue, dateFormat);
13273
+ var format = DateUtils.format;
13274
+ if (value == null) return null;
13275
+ if (dateFormat == null) return forgeConfigError("Missing option dateFormat, can't perform date validation.");
13276
+ var errorMessage;
13277
+ if (minDate != null && value < minDate) errorMessage = "Value \"".concat(format(value, dateFormat), "\" should be greater than ").concat(format(minDate, dateFormat));
13278
+ if (maxDate != null && value > maxDate) errorMessage = "Value \"".concat(format(value, dateFormat), "\" should be less than ").concat(format(maxDate, dateFormat));
13279
+ if (errorMessage == null) return true;
13280
+ return new Error$1("Value out of range", null, errorMessage);
13281
+ };
13219
13282
  var isValid = function isValid(dataStr, type, options) {
13220
13283
  var canBeEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
13221
13284
  if (canBeEmpty && dataStr === '') {
@@ -13223,28 +13286,27 @@ var isValid = function isValid(dataStr, type, options) {
13223
13286
  }
13224
13287
  switch (type) {
13225
13288
  case 'bool':
13226
- return isBool(dataStr);
13289
+ return isBool(dataStr) || forgeTypeError(dataStr, type, options);
13227
13290
  case 'date':
13228
- if (!options.dateFormat) {
13229
- console.error("Missing option dateFormat, can't perform date validation.");
13230
- return false;
13291
+ {
13292
+ if (!(options !== null && options !== void 0 && options.dateFormat)) return forgeConfigError("Missing option dateFormat, can't perform date validation.");
13293
+ if (!isDate(dataStr, options === null || options === void 0 ? void 0 : options.dateFormat)) return forgeTypeError(dataStr, type, options);
13294
+ var valueAsDate = DateUtils.parse(dataStr, options === null || options === void 0 ? void 0 : options.dateFormat);
13295
+ return isDateInRange(valueAsDate, options === null || options === void 0 ? void 0 : options.minValue, options === null || options === void 0 ? void 0 : options.maxValue, options === null || options === void 0 ? void 0 : options.dateFormat);
13231
13296
  }
13232
- return isDate(dataStr, options.dateFormat);
13233
13297
  case 'enum':
13234
- if (!options.enumValues) {
13235
- console.error("Missing option enumValues, can't perform enum validation.");
13236
- return false;
13237
- }
13238
- return isEnum(dataStr, options.enumValues);
13298
+ if (!options.enumValues) return forgeConfigError("Missing option enumValues, can't perform enum validation.");
13299
+ return isEnum(dataStr, options.enumValues) || forgeTypeError(dataStr, type, options);
13239
13300
  case 'int':
13240
- return isInt(dataStr);
13301
+ if (!isInt(dataStr)) return forgeTypeError(dataStr, type, options);
13302
+ return isInRange(Number(dataStr), options === null || options === void 0 ? void 0 : options.minValue, options === null || options === void 0 ? void 0 : options.maxValue);
13241
13303
  case 'number':
13242
- return isNumber(dataStr);
13304
+ if (!isNumber(dataStr)) return forgeTypeError(dataStr, type, options);
13305
+ return isInRange(Number(dataStr), options === null || options === void 0 ? void 0 : options.minValue, options === null || options === void 0 ? void 0 : options.maxValue);
13243
13306
  case 'string':
13244
- return isString(dataStr);
13307
+ return isString(dataStr) || forgeTypeError(dataStr, type, options);
13245
13308
  default:
13246
- console.error("Unknown type \"".concat(type, "\", can't perform type validation."));
13247
- return false;
13309
+ return forgeConfigError("Unknown type \"".concat(type, "\", can't perform type validation."));
13248
13310
  }
13249
13311
  };
13250
13312
  var ValidationUtils = {
@@ -13256,20 +13318,6 @@ var ValidationUtils = {
13256
13318
  isValid
13257
13319
  };
13258
13320
 
13259
- // Copyright (c) Cosmo Tech.
13260
- // Licensed under the MIT license.
13261
-
13262
- let Error$1 = class Error {
13263
- constructor(summary, loc, context) {
13264
- this.summary = summary;
13265
- this.loc = loc;
13266
- this.context = context;
13267
- }
13268
- toString() {
13269
- return "Summary: ".concat(this.summary, "\n") + "Loc: ".concat(this.loc, "\n") + "Context: ".concat(this.context);
13270
- }
13271
- };
13272
-
13273
13321
  var dist = {};
13274
13322
 
13275
13323
  var CSV = {};
@@ -41554,15 +41602,6 @@ var _buildNumberColumnsError = (rowLineNumber, expectedCols, row) => {
41554
41602
  var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : Expected ").concat(expectedColsCount, " fields, found ").concat(row.length, "\n") + "Expected data format : \"".concat(expectedColsName, "\"\n") + "Incorrect Row : \"".concat(row, "\"");
41555
41603
  return new Error$1(errorSummary, errorLoc, errorContext);
41556
41604
  };
41557
- var _buildTypeError = (type, rowLineNumber, colIndex, colsData, value, expected) => {
41558
- var errorSummary = "Incorrect ".concat(type, " value");
41559
- var errorLoc = "Line ".concat(rowLineNumber, ", Column ").concat(colIndex + 1, " (\"").concat(colsData[colIndex].field, "\")");
41560
- var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ")\n") + "Incorrect value : \"".concat(value, "\" for type ").concat(type);
41561
- if (!expected || expected.length === 0) {
41562
- return new Error$1(errorSummary, errorLoc, errorContext);
41563
- }
41564
- return new Error$1(errorSummary, errorLoc, errorContext + '\n' + expected);
41565
- };
41566
41605
  var DEFAULT_CSV_EXPORT_OPTIONS = {
41567
41606
  colSep: ',',
41568
41607
  dateFormat: 'yyyy-MM-dd',
@@ -41579,15 +41618,6 @@ var _forgeColumnsCountError = (row, rowLineNumber, expectedCols, errors) => {
41579
41618
  });
41580
41619
  if (row.length !== expectedCols.length) errors.push(_buildNumberColumnsError(rowLineNumber, expectedCols, row));
41581
41620
  };
41582
- var _forgeTypeError = (value, rowLineNumber, type, options, colsData, colIndex) => {
41583
- var expected = '';
41584
- if (type === 'enum') {
41585
- expected = "Expected values: [".concat(options.enumValues.join(), "]");
41586
- } else if (type === 'date') {
41587
- expected = "Expected format: ".concat(options.dateFormat);
41588
- }
41589
- return _buildTypeError(type, rowLineNumber, colIndex, colsData, value, expected);
41590
- };
41591
41621
  var _getColTypeFromTypeArray = typeArray => {
41592
41622
  if (!typeArray || typeArray.length === 0) {
41593
41623
  return 'string'; // Fall back to default type
@@ -41615,16 +41645,23 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
41615
41645
  if (colIndex < knownColsCount) {
41616
41646
  var colType = colsData[colIndex].type;
41617
41647
  if (colType && rowCell !== undefined) {
41618
- var _colsData$colIndex$en, _colsData$colIndex, _colsData$colIndex2, _ref, _colsData$colIndex$ac, _colsData$colIndex$ce;
41648
+ var _colsData$colIndex$en, _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex3, _colsData$colIndex4, _ref, _colsData$colIndex$ac, _colsData$colIndex$ce;
41619
41649
  // use of cellEditorParams is deprecated
41620
- var enumValues = (_colsData$colIndex$en = (_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) !== null && _colsData$colIndex$en !== void 0 ? _colsData$colIndex$en : (_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 || (_colsData$colIndex2 = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2 === void 0 ? void 0 : _colsData$colIndex2.enumValues;
41621
41650
  var colOptions = _objectSpread2(_objectSpread2({}, options), {}, {
41622
- enumValues
41651
+ enumValues: (_colsData$colIndex$en = (_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) !== null && _colsData$colIndex$en !== void 0 ? _colsData$colIndex$en : (_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 || (_colsData$colIndex2 = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2 === void 0 ? void 0 : _colsData$colIndex2.enumValues,
41652
+ minValue: (_colsData$colIndex3 = colsData[colIndex]) === null || _colsData$colIndex3 === void 0 ? void 0 : _colsData$colIndex3.minValue,
41653
+ maxValue: (_colsData$colIndex4 = colsData[colIndex]) === null || _colsData$colIndex4 === void 0 ? void 0 : _colsData$colIndex4.maxValue
41623
41654
  });
41624
41655
  var acceptsEmptyFields = // use of cellEditorParams is deprecated
41625
41656
  (_ref = (_colsData$colIndex$ac = colsData[colIndex].acceptsEmptyFields) !== null && _colsData$colIndex$ac !== void 0 ? _colsData$colIndex$ac : (_colsData$colIndex$ce = colsData[colIndex].cellEditorParams) === null || _colsData$colIndex$ce === void 0 ? void 0 : _colsData$colIndex$ce.acceptsEmptyFields) !== null && _ref !== void 0 ? _ref : false;
41626
- if (!ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields)) {
41627
- errors.push(_forgeTypeError(rowCell, rowIndex + 1, colType, colOptions, colsData, colIndex));
41657
+ var validationResult = ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields);
41658
+ if (validationResult !== true) {
41659
+ var {
41660
+ summary: errorSummary,
41661
+ context: errorContext
41662
+ } = validationResult;
41663
+ var errorLoc = "Line ".concat(rowIndex + 1, ", Column ").concat(colIndex + 1, " (\"").concat(colsData[colIndex].field, "\")");
41664
+ errors.push(new Error$1(errorSummary, errorLoc, errorContext));
41628
41665
  }
41629
41666
  }
41630
41667
  }
@@ -57982,13 +58019,15 @@ var acquireTokens = /*#__PURE__*/function () {
57982
58019
  }();
57983
58020
  var handleResponse = response => {
57984
58021
  if (response != null) {
58022
+ var _account$idTokenClaim, _account$idTokenClaim2;
57985
58023
  var account = response.account;
57986
58024
  _updateTokensInStorage(response);
57987
58025
  writeToStorage('authIdTokenPopup', response.idToken);
57988
58026
  writeToStorage('authAuthenticated', 'true');
57989
58027
  writeToStorage('authAccountId', account.homeAccountId);
58028
+ writeToStorage('authEmail', (_account$idTokenClaim = account.idTokenClaims) === null || _account$idTokenClaim === void 0 ? void 0 : _account$idTokenClaim.email);
57990
58029
  authData.accountId = account.homeAccountId;
57991
- authData.userEmail = account.username; // In MSAL account data, username property contains user email
58030
+ authData.userEmail = (_account$idTokenClaim2 = account.idTokenClaims) === null || _account$idTokenClaim2 === void 0 ? void 0 : _account$idTokenClaim2.email;
57992
58031
  authData.username = account.name;
57993
58032
  authData.userId = account.localAccountId;
57994
58033
  redirectOnAuthSuccess();
@@ -58014,6 +58053,7 @@ var signOut = () => {
58014
58053
  clearFromStorage('authIdToken');
58015
58054
  clearFromStorage('authAccessToken');
58016
58055
  clearFromStorage('authAccountId');
58056
+ clearFromStorage('authEmail');
58017
58057
  writeToStorage('authAuthenticated', 'false');
58018
58058
  var logoutRequest = {
58019
58059
  account: msalApp.getAccountByHomeId((_authData$accountId = authData.accountId) !== null && _authData$accountId !== void 0 ? _authData$accountId : accountId),
@@ -58105,10 +58145,10 @@ var refreshTokens = /*#__PURE__*/function () {
58105
58145
  };
58106
58146
  }();
58107
58147
  var getUserEmail = () => {
58108
- var _authData$userEmail, _msalApp$getAllAccoun2;
58148
+ var _ref6, _readFromStorage, _msalApp$getAllAccoun2;
58109
58149
  if (!checkInit()) return;
58110
58150
  // Note: account data from MSAL seems to contain user email in the 'username' property
58111
- 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;
58151
+ 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;
58112
58152
  };
58113
58153
  var getUserName = () => {
58114
58154
  var _authData$name, _msalApp$getAllAccoun3;
@@ -58168,11 +58208,6 @@ var DatasetUtils = {
58168
58208
  getDatasetNames
58169
58209
  };
58170
58210
 
58171
- // Copyright (c) Cosmo Tech.
58172
- // Licensed under the MIT license.
58173
-
58174
- var NAME_VALIDATOR = /^[a-zA-Z0-9][\w\s.-]*$/;
58175
-
58176
58211
  // Copyright (c) Cosmo Tech.
58177
58212
  // Licensed under the MIT license.
58178
58213
  var scenarioExistsInList = (scenarioName, scenarioList) => {
@@ -58192,15 +58227,8 @@ var scenarioExistsInTree = (scenarioName, scenarioTree) => {
58192
58227
  };
58193
58228
  var scenarioNameIsValid = (scenarioName, scenarioList) => {
58194
58229
  scenarioName = scenarioName.trimEnd();
58195
- if (scenarioName.length === 0) {
58196
- return 'emptyScenarioName';
58197
- } else {
58198
- if (scenarioName.match(NAME_VALIDATOR) === null) {
58199
- return 'forbiddenCharsInScenarioName';
58200
- } else if (scenarioExistsInList(scenarioName, scenarioList)) {
58201
- return 'existingScenarioName';
58202
- }
58203
- }
58230
+ if (scenarioName.length === 0) return 'emptyScenarioName';
58231
+ if (scenarioExistsInList(scenarioName, scenarioList)) return 'existingScenarioName';
58204
58232
  return null;
58205
58233
  };
58206
58234
  var getScenarioTree = (scenarioList, compareFn) => {
package/dist/index.esm.js CHANGED
@@ -13194,6 +13194,34 @@ var DateUtils = {
13194
13194
 
13195
13195
  // Copyright (c) Cosmo Tech.
13196
13196
  // Licensed under the MIT license.
13197
+
13198
+ let Error$1 = class Error {
13199
+ constructor(summary, loc, context) {
13200
+ this.summary = summary;
13201
+ this.loc = loc;
13202
+ this.context = context;
13203
+ }
13204
+ toString() {
13205
+ return "Summary: ".concat(this.summary, "\n") + "Loc: ".concat(this.loc, "\n") + "Context: ".concat(this.context);
13206
+ }
13207
+ };
13208
+
13209
+ // Copyright (c) Cosmo Tech.
13210
+ // Licensed under the MIT license.
13211
+ var forgeTypeError = (value, type, options) => {
13212
+ var expected;
13213
+ if (type === 'enum') expected = "Expected values: [".concat(options.enumValues.join(), "]");else if (type === 'date') expected = "Expected format: ".concat(options === null || options === void 0 ? void 0 : options.dateFormat);
13214
+ var error = new Error$1("Incorrect ".concat(type, " value"), null, "Incorrect value: \"".concat(value, "\" for type ").concat(type));
13215
+ if (expected) error.context += '\n' + expected;
13216
+ return error;
13217
+ };
13218
+ var forgeConfigError = errorContext => {
13219
+ console.warn("Configuration error: ".concat(errorContext));
13220
+ return {
13221
+ summary: 'Configuration error',
13222
+ context: errorContext
13223
+ };
13224
+ };
13197
13225
  var isBool = dataStr => {
13198
13226
  return validator.isBoolean(dataStr, {
13199
13227
  loose: true
@@ -13214,6 +13242,41 @@ var isNumber = dataStr => {
13214
13242
  var isString = data => {
13215
13243
  return typeof data === 'string';
13216
13244
  };
13245
+ var isInRange = (value, minValue, maxValue) => {
13246
+ if (value == null) return null;
13247
+ var errorMessage;
13248
+ if (minValue != null && value < minValue) errorMessage = "Value \"".concat(value, "\" should be greater than ").concat(minValue);
13249
+ if (maxValue != null && value > maxValue) errorMessage = "Value \"".concat(value, "\" should be less than ").concat(maxValue);
13250
+ if (errorMessage == null) return true;
13251
+ return new Error$1("Value out of range", null, errorMessage);
13252
+ };
13253
+ var castToDate = (dateOrStrValue, dateFormat) => {
13254
+ if (dateOrStrValue == null) return;
13255
+ if (dateOrStrValue instanceof Date) return dateOrStrValue;
13256
+ if (typeof dateOrStrValue !== 'string') {
13257
+ console.warn("Configuration error: ".concat(dateOrStrValue, " is not a string nor a Date."));
13258
+ return;
13259
+ }
13260
+ if (!isDate(dateOrStrValue, dateFormat)) {
13261
+ console.warn("Configuration error: ".concat(forgeTypeError(dateOrStrValue, 'date', {
13262
+ dateFormat
13263
+ }).context, "."));
13264
+ return;
13265
+ }
13266
+ return DateUtils.parse(dateOrStrValue, dateFormat);
13267
+ };
13268
+ var isDateInRange = (value, minValue, maxValue, dateFormat) => {
13269
+ var minDate = castToDate(minValue, dateFormat);
13270
+ var maxDate = castToDate(maxValue, dateFormat);
13271
+ var format = DateUtils.format;
13272
+ if (value == null) return null;
13273
+ if (dateFormat == null) return forgeConfigError("Missing option dateFormat, can't perform date validation.");
13274
+ var errorMessage;
13275
+ if (minDate != null && value < minDate) errorMessage = "Value \"".concat(format(value, dateFormat), "\" should be greater than ").concat(format(minDate, dateFormat));
13276
+ if (maxDate != null && value > maxDate) errorMessage = "Value \"".concat(format(value, dateFormat), "\" should be less than ").concat(format(maxDate, dateFormat));
13277
+ if (errorMessage == null) return true;
13278
+ return new Error$1("Value out of range", null, errorMessage);
13279
+ };
13217
13280
  var isValid = function isValid(dataStr, type, options) {
13218
13281
  var canBeEmpty = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
13219
13282
  if (canBeEmpty && dataStr === '') {
@@ -13221,28 +13284,27 @@ var isValid = function isValid(dataStr, type, options) {
13221
13284
  }
13222
13285
  switch (type) {
13223
13286
  case 'bool':
13224
- return isBool(dataStr);
13287
+ return isBool(dataStr) || forgeTypeError(dataStr, type, options);
13225
13288
  case 'date':
13226
- if (!options.dateFormat) {
13227
- console.error("Missing option dateFormat, can't perform date validation.");
13228
- return false;
13289
+ {
13290
+ if (!(options !== null && options !== void 0 && options.dateFormat)) return forgeConfigError("Missing option dateFormat, can't perform date validation.");
13291
+ if (!isDate(dataStr, options === null || options === void 0 ? void 0 : options.dateFormat)) return forgeTypeError(dataStr, type, options);
13292
+ var valueAsDate = DateUtils.parse(dataStr, options === null || options === void 0 ? void 0 : options.dateFormat);
13293
+ return isDateInRange(valueAsDate, options === null || options === void 0 ? void 0 : options.minValue, options === null || options === void 0 ? void 0 : options.maxValue, options === null || options === void 0 ? void 0 : options.dateFormat);
13229
13294
  }
13230
- return isDate(dataStr, options.dateFormat);
13231
13295
  case 'enum':
13232
- if (!options.enumValues) {
13233
- console.error("Missing option enumValues, can't perform enum validation.");
13234
- return false;
13235
- }
13236
- return isEnum(dataStr, options.enumValues);
13296
+ if (!options.enumValues) return forgeConfigError("Missing option enumValues, can't perform enum validation.");
13297
+ return isEnum(dataStr, options.enumValues) || forgeTypeError(dataStr, type, options);
13237
13298
  case 'int':
13238
- return isInt(dataStr);
13299
+ if (!isInt(dataStr)) return forgeTypeError(dataStr, type, options);
13300
+ return isInRange(Number(dataStr), options === null || options === void 0 ? void 0 : options.minValue, options === null || options === void 0 ? void 0 : options.maxValue);
13239
13301
  case 'number':
13240
- return isNumber(dataStr);
13302
+ if (!isNumber(dataStr)) return forgeTypeError(dataStr, type, options);
13303
+ return isInRange(Number(dataStr), options === null || options === void 0 ? void 0 : options.minValue, options === null || options === void 0 ? void 0 : options.maxValue);
13241
13304
  case 'string':
13242
- return isString(dataStr);
13305
+ return isString(dataStr) || forgeTypeError(dataStr, type, options);
13243
13306
  default:
13244
- console.error("Unknown type \"".concat(type, "\", can't perform type validation."));
13245
- return false;
13307
+ return forgeConfigError("Unknown type \"".concat(type, "\", can't perform type validation."));
13246
13308
  }
13247
13309
  };
13248
13310
  var ValidationUtils = {
@@ -13254,20 +13316,6 @@ var ValidationUtils = {
13254
13316
  isValid
13255
13317
  };
13256
13318
 
13257
- // Copyright (c) Cosmo Tech.
13258
- // Licensed under the MIT license.
13259
-
13260
- let Error$1 = class Error {
13261
- constructor(summary, loc, context) {
13262
- this.summary = summary;
13263
- this.loc = loc;
13264
- this.context = context;
13265
- }
13266
- toString() {
13267
- return "Summary: ".concat(this.summary, "\n") + "Loc: ".concat(this.loc, "\n") + "Context: ".concat(this.context);
13268
- }
13269
- };
13270
-
13271
13319
  var dist = {};
13272
13320
 
13273
13321
  var CSV = {};
@@ -41552,15 +41600,6 @@ var _buildNumberColumnsError = (rowLineNumber, expectedCols, row) => {
41552
41600
  var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ") : Expected ").concat(expectedColsCount, " fields, found ").concat(row.length, "\n") + "Expected data format : \"".concat(expectedColsName, "\"\n") + "Incorrect Row : \"".concat(row, "\"");
41553
41601
  return new Error$1(errorSummary, errorLoc, errorContext);
41554
41602
  };
41555
- var _buildTypeError = (type, rowLineNumber, colIndex, colsData, value, expected) => {
41556
- var errorSummary = "Incorrect ".concat(type, " value");
41557
- var errorLoc = "Line ".concat(rowLineNumber, ", Column ").concat(colIndex + 1, " (\"").concat(colsData[colIndex].field, "\")");
41558
- var errorContext = "".concat(errorSummary, " (").concat(errorLoc, ")\n") + "Incorrect value : \"".concat(value, "\" for type ").concat(type);
41559
- if (!expected || expected.length === 0) {
41560
- return new Error$1(errorSummary, errorLoc, errorContext);
41561
- }
41562
- return new Error$1(errorSummary, errorLoc, errorContext + '\n' + expected);
41563
- };
41564
41603
  var DEFAULT_CSV_EXPORT_OPTIONS = {
41565
41604
  colSep: ',',
41566
41605
  dateFormat: 'yyyy-MM-dd',
@@ -41577,15 +41616,6 @@ var _forgeColumnsCountError = (row, rowLineNumber, expectedCols, errors) => {
41577
41616
  });
41578
41617
  if (row.length !== expectedCols.length) errors.push(_buildNumberColumnsError(rowLineNumber, expectedCols, row));
41579
41618
  };
41580
- var _forgeTypeError = (value, rowLineNumber, type, options, colsData, colIndex) => {
41581
- var expected = '';
41582
- if (type === 'enum') {
41583
- expected = "Expected values: [".concat(options.enumValues.join(), "]");
41584
- } else if (type === 'date') {
41585
- expected = "Expected format: ".concat(options.dateFormat);
41586
- }
41587
- return _buildTypeError(type, rowLineNumber, colIndex, colsData, value, expected);
41588
- };
41589
41619
  var _getColTypeFromTypeArray = typeArray => {
41590
41620
  if (!typeArray || typeArray.length === 0) {
41591
41621
  return 'string'; // Fall back to default type
@@ -41613,16 +41643,23 @@ var _validateFormat = (rows, hasHeader, cols, options) => {
41613
41643
  if (colIndex < knownColsCount) {
41614
41644
  var colType = colsData[colIndex].type;
41615
41645
  if (colType && rowCell !== undefined) {
41616
- var _colsData$colIndex$en, _colsData$colIndex, _colsData$colIndex2, _ref, _colsData$colIndex$ac, _colsData$colIndex$ce;
41646
+ var _colsData$colIndex$en, _colsData$colIndex, _colsData$colIndex2, _colsData$colIndex3, _colsData$colIndex4, _ref, _colsData$colIndex$ac, _colsData$colIndex$ce;
41617
41647
  // use of cellEditorParams is deprecated
41618
- var enumValues = (_colsData$colIndex$en = (_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) !== null && _colsData$colIndex$en !== void 0 ? _colsData$colIndex$en : (_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 || (_colsData$colIndex2 = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2 === void 0 ? void 0 : _colsData$colIndex2.enumValues;
41619
41648
  var colOptions = _objectSpread2(_objectSpread2({}, options), {}, {
41620
- enumValues
41649
+ enumValues: (_colsData$colIndex$en = (_colsData$colIndex = colsData[colIndex]) === null || _colsData$colIndex === void 0 ? void 0 : _colsData$colIndex.enumValues) !== null && _colsData$colIndex$en !== void 0 ? _colsData$colIndex$en : (_colsData$colIndex2 = colsData[colIndex]) === null || _colsData$colIndex2 === void 0 || (_colsData$colIndex2 = _colsData$colIndex2.cellEditorParams) === null || _colsData$colIndex2 === void 0 ? void 0 : _colsData$colIndex2.enumValues,
41650
+ minValue: (_colsData$colIndex3 = colsData[colIndex]) === null || _colsData$colIndex3 === void 0 ? void 0 : _colsData$colIndex3.minValue,
41651
+ maxValue: (_colsData$colIndex4 = colsData[colIndex]) === null || _colsData$colIndex4 === void 0 ? void 0 : _colsData$colIndex4.maxValue
41621
41652
  });
41622
41653
  var acceptsEmptyFields = // use of cellEditorParams is deprecated
41623
41654
  (_ref = (_colsData$colIndex$ac = colsData[colIndex].acceptsEmptyFields) !== null && _colsData$colIndex$ac !== void 0 ? _colsData$colIndex$ac : (_colsData$colIndex$ce = colsData[colIndex].cellEditorParams) === null || _colsData$colIndex$ce === void 0 ? void 0 : _colsData$colIndex$ce.acceptsEmptyFields) !== null && _ref !== void 0 ? _ref : false;
41624
- if (!ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields)) {
41625
- errors.push(_forgeTypeError(rowCell, rowIndex + 1, colType, colOptions, colsData, colIndex));
41655
+ var validationResult = ValidationUtils.isValid(rowCell, colType, colOptions, acceptsEmptyFields);
41656
+ if (validationResult !== true) {
41657
+ var {
41658
+ summary: errorSummary,
41659
+ context: errorContext
41660
+ } = validationResult;
41661
+ var errorLoc = "Line ".concat(rowIndex + 1, ", Column ").concat(colIndex + 1, " (\"").concat(colsData[colIndex].field, "\")");
41662
+ errors.push(new Error$1(errorSummary, errorLoc, errorContext));
41626
41663
  }
41627
41664
  }
41628
41665
  }
@@ -57980,13 +58017,15 @@ var acquireTokens = /*#__PURE__*/function () {
57980
58017
  }();
57981
58018
  var handleResponse = response => {
57982
58019
  if (response != null) {
58020
+ var _account$idTokenClaim, _account$idTokenClaim2;
57983
58021
  var account = response.account;
57984
58022
  _updateTokensInStorage(response);
57985
58023
  writeToStorage('authIdTokenPopup', response.idToken);
57986
58024
  writeToStorage('authAuthenticated', 'true');
57987
58025
  writeToStorage('authAccountId', account.homeAccountId);
58026
+ writeToStorage('authEmail', (_account$idTokenClaim = account.idTokenClaims) === null || _account$idTokenClaim === void 0 ? void 0 : _account$idTokenClaim.email);
57988
58027
  authData.accountId = account.homeAccountId;
57989
- authData.userEmail = account.username; // In MSAL account data, username property contains user email
58028
+ authData.userEmail = (_account$idTokenClaim2 = account.idTokenClaims) === null || _account$idTokenClaim2 === void 0 ? void 0 : _account$idTokenClaim2.email;
57990
58029
  authData.username = account.name;
57991
58030
  authData.userId = account.localAccountId;
57992
58031
  redirectOnAuthSuccess();
@@ -58012,6 +58051,7 @@ var signOut = () => {
58012
58051
  clearFromStorage('authIdToken');
58013
58052
  clearFromStorage('authAccessToken');
58014
58053
  clearFromStorage('authAccountId');
58054
+ clearFromStorage('authEmail');
58015
58055
  writeToStorage('authAuthenticated', 'false');
58016
58056
  var logoutRequest = {
58017
58057
  account: msalApp.getAccountByHomeId((_authData$accountId = authData.accountId) !== null && _authData$accountId !== void 0 ? _authData$accountId : accountId),
@@ -58103,10 +58143,10 @@ var refreshTokens = /*#__PURE__*/function () {
58103
58143
  };
58104
58144
  }();
58105
58145
  var getUserEmail = () => {
58106
- var _authData$userEmail, _msalApp$getAllAccoun2;
58146
+ var _ref6, _readFromStorage, _msalApp$getAllAccoun2;
58107
58147
  if (!checkInit()) return;
58108
58148
  // Note: account data from MSAL seems to contain user email in the 'username' property
58109
- 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;
58149
+ 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;
58110
58150
  };
58111
58151
  var getUserName = () => {
58112
58152
  var _authData$name, _msalApp$getAllAccoun3;
@@ -58166,11 +58206,6 @@ var DatasetUtils = {
58166
58206
  getDatasetNames
58167
58207
  };
58168
58208
 
58169
- // Copyright (c) Cosmo Tech.
58170
- // Licensed under the MIT license.
58171
-
58172
- var NAME_VALIDATOR = /^[a-zA-Z0-9][\w\s.-]*$/;
58173
-
58174
58209
  // Copyright (c) Cosmo Tech.
58175
58210
  // Licensed under the MIT license.
58176
58211
  var scenarioExistsInList = (scenarioName, scenarioList) => {
@@ -58190,15 +58225,8 @@ var scenarioExistsInTree = (scenarioName, scenarioTree) => {
58190
58225
  };
58191
58226
  var scenarioNameIsValid = (scenarioName, scenarioList) => {
58192
58227
  scenarioName = scenarioName.trimEnd();
58193
- if (scenarioName.length === 0) {
58194
- return 'emptyScenarioName';
58195
- } else {
58196
- if (scenarioName.match(NAME_VALIDATOR) === null) {
58197
- return 'forbiddenCharsInScenarioName';
58198
- } else if (scenarioExistsInList(scenarioName, scenarioList)) {
58199
- return 'existingScenarioName';
58200
- }
58201
- }
58228
+ if (scenarioName.length === 0) return 'emptyScenarioName';
58229
+ if (scenarioExistsInList(scenarioName, scenarioList)) return 'existingScenarioName';
58202
58230
  return null;
58203
58231
  };
58204
58232
  var getScenarioTree = (scenarioList, compareFn) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmotech/core",
3
- "version": "1.19.1",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",