@singularsystems/neo-core 0.10.77 → 0.10.79

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.
@@ -2,6 +2,7 @@ import { __awaiter, __decorate, __generator, __metadata, __param } from "tslib";
2
2
  import { injectable, inject } from 'inversify';
3
3
  import { ModalUtils } from './Modal/ModalUtils';
4
4
  import NeoTypes from '../AppServices/NeoTypes';
5
+ import NeoStrings from '../Localisation/NeoStrings';
5
6
  export var ErrorDisplayType;
6
7
  (function (ErrorDisplayType) {
7
8
  /** Show the error text in a modal. */
@@ -94,16 +95,16 @@ var ErrorHandler = /** @class */ (function () {
94
95
  });
95
96
  };
96
97
  ErrorHandler.prototype.get400Error = function (error) {
97
- return this.parseAxiosError("Invalid data", "Cannot continue due to the following validation errors:", error);
98
+ return this.parseAxiosError(NeoStrings.errors.invalidDataTitle, NeoStrings.errors.invalidDataBody, error);
98
99
  };
99
100
  ErrorHandler.prototype.get401Error = function (error) {
100
- return this.parseAxiosError("Not authenticated", "You are not logged in. Please reload the page to login again.", error);
101
+ return this.parseAxiosError(NeoStrings.errors.notAuthenticatedTitle, NeoStrings.errors.notAuthenticatedBody, error);
101
102
  };
102
103
  ErrorHandler.prototype.get403Error = function (error) {
103
- return this.parseAxiosError("Unauthorised", "You do not have access to perform this operation.", error);
104
+ return this.parseAxiosError(NeoStrings.errors.unAuthorisedTitle, NeoStrings.errors.unAuthorisedBody, error);
104
105
  };
105
106
  ErrorHandler.prototype.get409Error = function (error) {
106
- return this.parseAxiosError("Concurrency error", "Someone else modified the record before you saved it. Please reload it and try again.", error);
107
+ return this.parseAxiosError(NeoStrings.errors.concurrencyTitle, NeoStrings.errors.concurrencyBody, error);
107
108
  };
108
109
  /**
109
110
  * Parses an axios response into an IErrorDisplay object.
@@ -180,7 +181,7 @@ var ErrorHandler = /** @class */ (function () {
180
181
  };
181
182
  ErrorHandler.prototype.getGeneralError = function (error) {
182
183
  var errorDescription = error.message ? error.message : error;
183
- return { header: "Error", body: errorDescription };
184
+ return { header: NeoStrings.errors.generalTitle, body: errorDescription };
184
185
  };
185
186
  ErrorHandler.prototype.displayError = function (displayType, error, errorDisplay) {
186
187
  if (error instanceof Error) {
@@ -7,6 +7,7 @@ import { NeoTypes } from '../../AppServices';
7
7
  import { ErrorDisplayType } from '../ErrorHandler';
8
8
  import { Settings } from '../../Settings';
9
9
  import { FileUploadBatch } from './FileUploadBatch';
10
+ import NeoStrings from '../../Localisation/NeoStrings';
10
11
  var fileInputSymbol = Symbol("FileInput");
11
12
  var FileManagerBase = /** @class */ (function () {
12
13
  function FileManagerBase(uploadEndpointOrOptions, options) {
@@ -87,7 +88,7 @@ var FileManagerBase = /** @class */ (function () {
87
88
  return true;
88
89
  }
89
90
  else {
90
- ModalUtils.showMessage("File Upload", "File extension: " + checkResult.extension + " is not allowed.");
91
+ ModalUtils.showMessage(NeoStrings.fileManager.uploadErrorTitle, NeoStrings.fileManager.uploadErrorBody.format(checkResult.extension));
91
92
  return false;
92
93
  }
93
94
  };
@@ -1,5 +1,8 @@
1
+ import { __assign } from "tslib";
1
2
  import Globals from '../../Globals';
2
3
  import { NeoTypes } from '../../AppServices';
4
+ import { Settings } from '../../Settings';
5
+ import NeoStrings from '../../Localisation/NeoStrings';
3
6
  export var ModalResult;
4
7
  (function (ModalResult) {
5
8
  ModalResult[ModalResult["Yes"] = 1] = "Yes";
@@ -12,7 +15,16 @@ var ModalHelpers = /** @class */ (function () {
12
15
  ModalHelpers.prototype.showMessage = function (title, message, resultValue) {
13
16
  var _this = this;
14
17
  return new Promise(function (resolve, reject) {
15
- _this.showModal(title, message, { onClose: resolve, closeButton: { text: "Ok", onClick: function () { return resultValue ? resolve(resultValue) : resolve(); } } });
18
+ var button = { text: NeoStrings.modals.ok, onClick: function () { return resultValue ? resolve(resultValue) : resolve(); } };
19
+ var options = { onClose: resolve };
20
+ if (Settings.modal.okIsAccept) {
21
+ options.acceptButton = button;
22
+ options.closeButton = false;
23
+ }
24
+ else {
25
+ options.closeButton = button;
26
+ }
27
+ _this.showModal(title, message, options);
16
28
  });
17
29
  };
18
30
  /**
@@ -47,8 +59,8 @@ var ModalHelpers = /** @class */ (function () {
47
59
  _this.showModal(title, message, {
48
60
  onClose: function () { return resolve(ModalResult.No); },
49
61
  showCancelButton: allowCancel,
50
- acceptButton: { text: "Yes", onClick: onAccept },
51
- closeButton: { text: "No", onClick: function () { return resolve(ModalResult.No); } }
62
+ acceptButton: { text: NeoStrings.modals.yes, onClick: onAccept },
63
+ closeButton: { text: NeoStrings.modals.no, onClick: function () { return resolve(ModalResult.No); } }
52
64
  });
53
65
  });
54
66
  };
@@ -64,9 +76,9 @@ var ModalHelpers = /** @class */ (function () {
64
76
  return new Promise(function (resolve, reject) {
65
77
  _this.showModal(title, message, {
66
78
  onClose: function () { return resolve(ModalResult.Cancel); },
67
- acceptButton: { text: "Ok", onClick: function () { return resolve(ModalResult.Yes); } },
68
- closeButton: { text: "Cancel", variant: "light", onClick: function () { return resolve(ModalResult.Cancel); } },
69
- formProps: { model: model }
79
+ acceptButton: { text: NeoStrings.modals.ok, onClick: function () { return resolve(ModalResult.Yes); } },
80
+ closeButton: __assign(__assign({}, Settings.modal.cancelButton), { text: NeoStrings.modals.cancel, onClick: function () { return resolve(ModalResult.Cancel); } }),
81
+ formProps: { model: model },
70
82
  });
71
83
  });
72
84
  };
@@ -88,9 +100,9 @@ var ModalHelpers = /** @class */ (function () {
88
100
  _this.showModal(title, message, {
89
101
  onClose: function () { return resolve(ModalResult.Cancel); },
90
102
  buttons: [
91
- { text: "Yes", variant: "primary", onClick: onAccept },
92
- { text: "No", variant: "secondary", onClick: function () { return resolve(ModalResult.No); } },
93
- { text: "Cancel", variant: "light", onClick: function () { return resolve(ModalResult.Cancel); } }
103
+ __assign(__assign({}, Settings.modal.acceptButton), { text: NeoStrings.modals.yes, onClick: onAccept }),
104
+ __assign(__assign({}, Settings.modal.closeButton), { text: NeoStrings.modals.no, onClick: function () { return resolve(ModalResult.No); } }),
105
+ __assign(__assign({}, Settings.modal.cancelButton), { text: NeoStrings.modals.cancel, onClick: function () { return resolve(ModalResult.Cancel); } })
94
106
  ]
95
107
  });
96
108
  });
@@ -0,0 +1,40 @@
1
+ declare const NeoStrings: {
2
+ errors: {
3
+ concurrencyTitle: string;
4
+ concurrencyBody: string;
5
+ generalTitle: string;
6
+ invalidDataTitle: string;
7
+ invalidDataBody: string;
8
+ notAuthenticatedTitle: string;
9
+ notAuthenticatedBody: string;
10
+ unAuthorisedTitle: string;
11
+ unAuthorisedBody: string;
12
+ };
13
+ fileManager: {
14
+ uploadErrorTitle: string;
15
+ /** {0} is the extension of the file */
16
+ uploadErrorBody: string;
17
+ };
18
+ modals: {
19
+ cancel: string;
20
+ no: string;
21
+ ok: string;
22
+ yes: string;
23
+ };
24
+ validation: {
25
+ /** Default text to display for built in rules. */
26
+ rules: {
27
+ /** {0} is the field name */
28
+ required: string;
29
+ /** {0} is the current value */
30
+ emailAddress: string;
31
+ /** {0} is the field name */
32
+ regExp: string;
33
+ /** Displayed when the string is too short */
34
+ stringLengthLessThan: string;
35
+ /** Displayed when the string is too long */
36
+ stringLengthMoreThan: string;
37
+ };
38
+ };
39
+ };
40
+ export default NeoStrings;
@@ -0,0 +1,40 @@
1
+ var NeoStrings = {
2
+ errors: {
3
+ concurrencyTitle: "Concurrency error",
4
+ concurrencyBody: "Someone else modified the record before you saved it. Please reload it and try again.",
5
+ generalTitle: "Error",
6
+ invalidDataTitle: "Invalid data",
7
+ invalidDataBody: "Cannot continue due to the following validation errors:",
8
+ notAuthenticatedTitle: "Not authenticated",
9
+ notAuthenticatedBody: "You are not logged in. Please reload the page to login again.",
10
+ unAuthorisedTitle: "Unauthorised",
11
+ unAuthorisedBody: "You do not have access to perform this operation."
12
+ },
13
+ fileManager: {
14
+ uploadErrorTitle: "File upload error",
15
+ /** {0} is the extension of the file */
16
+ uploadErrorBody: "File extension: {0} is not allowed."
17
+ },
18
+ modals: {
19
+ cancel: "Cancel",
20
+ no: "No",
21
+ ok: "Ok",
22
+ yes: "Yes",
23
+ },
24
+ validation: {
25
+ /** Default text to display for built in rules. */
26
+ rules: {
27
+ /** {0} is the field name */
28
+ required: "{0} is required",
29
+ /** {0} is the current value */
30
+ emailAddress: "{0} is not a valid email address",
31
+ /** {0} is the field name */
32
+ regExp: "{0} is in an invalid format",
33
+ /** Displayed when the string is too short */
34
+ stringLengthLessThan: "{0} cannot be less than {1} characters in length",
35
+ /** Displayed when the string is too long */
36
+ stringLengthMoreThan: "{0} cannot be more than {1} characters in length"
37
+ }
38
+ }
39
+ };
40
+ export default NeoStrings;
@@ -38,6 +38,7 @@ export default abstract class OidcAuthService<TUser extends OidcUser = OidcUser>
38
38
  endSignInSilent(): Promise<any>;
39
39
  private onUserLoaded;
40
40
  protected afterUserLoaded(): Promise<void> | void;
41
+ private completeAfterUserLoaded;
41
42
  protected createUser(user: IOidcUser): OidcUser;
42
43
  private onUserUnloaded;
43
44
  private setUser;
@@ -37,11 +37,14 @@ var OidcAuthService = /** @class */ (function () {
37
37
  case 0: return [4 /*yield*/, this.userManager.getUser()];
38
38
  case 1:
39
39
  user = _a.sent();
40
- if (user) {
41
- // Get user does not raise the onUserLoaded event, so we call it manually.
42
- this.onUserLoaded(user);
43
- }
44
- return [2 /*return*/, this.user];
40
+ if (!user) return [3 /*break*/, 3];
41
+ // Get user does not raise the onUserLoaded event, so we call it manually.
42
+ this.onUserLoaded(user);
43
+ return [4 /*yield*/, this.completeAfterUserLoaded()];
44
+ case 2:
45
+ _a.sent();
46
+ _a.label = 3;
47
+ case 3: return [2 /*return*/, this.user];
45
48
  }
46
49
  });
47
50
  });
@@ -102,24 +105,21 @@ var OidcAuthService = /** @class */ (function () {
102
105
  loginErrorHandler = Misc.Globals.appService.get(NeoTypes.Security.LoginErrorHandler);
103
106
  if (!(!stateKey || window.localStorage.getItem("oidc." + stateKey) === null)) return [3 /*break*/, 1];
104
107
  loginErrorHandler.onMissingLoginState();
105
- return [3 /*break*/, 6];
108
+ return [3 /*break*/, 5];
106
109
  case 1:
107
- _a.trys.push([1, 5, , 6]);
110
+ _a.trys.push([1, 4, , 5]);
108
111
  return [4 /*yield*/, this.endSignIn()];
109
112
  case 2:
110
113
  redirectPath = _a.sent();
111
- if (!this.afterUserLoadedPromise) return [3 /*break*/, 4];
112
- return [4 /*yield*/, this.afterUserLoadedPromise];
114
+ return [4 /*yield*/, this.completeAfterUserLoaded()];
113
115
  case 3:
114
116
  _a.sent();
115
- this.afterUserLoadedPromise = undefined;
116
- _a.label = 4;
117
- case 4: return [2 /*return*/, new SignInResult(true, redirectPath)];
118
- case 5:
117
+ return [2 /*return*/, new SignInResult(true, redirectPath)];
118
+ case 4:
119
119
  e_2 = _a.sent();
120
120
  loginErrorHandler.onException(e_2);
121
- return [3 /*break*/, 6];
122
- case 6: return [2 /*return*/, new SignInResult(false, "")];
121
+ return [3 /*break*/, 5];
122
+ case 5: return [2 /*return*/, new SignInResult(false, "")];
123
123
  }
124
124
  });
125
125
  });
@@ -133,6 +133,22 @@ var OidcAuthService = /** @class */ (function () {
133
133
  };
134
134
  OidcAuthService.prototype.afterUserLoaded = function () {
135
135
  };
136
+ OidcAuthService.prototype.completeAfterUserLoaded = function () {
137
+ return __awaiter(this, void 0, void 0, function () {
138
+ return __generator(this, function (_a) {
139
+ switch (_a.label) {
140
+ case 0:
141
+ if (!this.afterUserLoadedPromise) return [3 /*break*/, 2];
142
+ return [4 /*yield*/, this.afterUserLoadedPromise];
143
+ case 1:
144
+ _a.sent();
145
+ this.afterUserLoadedPromise = undefined;
146
+ _a.label = 2;
147
+ case 2: return [2 /*return*/];
148
+ }
149
+ });
150
+ });
151
+ };
136
152
  OidcAuthService.prototype.createUser = function (user) {
137
153
  return new OidcUser(user);
138
154
  };
@@ -49,8 +49,13 @@ export declare const Settings: {
49
49
  useStickyHeaders: boolean;
50
50
  };
51
51
  modal: {
52
+ /** Set to true if ModalUtils.showMessage() should show an accept button instead of close button. */
53
+ okIsAccept: boolean;
52
54
  acceptButton: IButtonOptions;
55
+ /** Settings for close button shown in footer. */
53
56
  closeButton: IButtonOptions;
57
+ /** Settings for cancel button shown in footer. */
58
+ cancelButton: IButtonOptions;
54
59
  };
55
60
  pager: {
56
61
  firstText: string;
package/dist/Settings.js CHANGED
@@ -72,14 +72,22 @@ export var Settings = {
72
72
  useStickyHeaders: false,
73
73
  },
74
74
  modal: {
75
+ /** Set to true if ModalUtils.showMessage() should show an accept button instead of close button. */
76
+ okIsAccept: false,
75
77
  acceptButton: {
76
78
  text: "Ok",
77
79
  variant: "primary"
78
80
  },
81
+ /** Settings for close button shown in footer. */
79
82
  closeButton: {
80
83
  text: "Close",
81
84
  variant: "secondary"
82
85
  },
86
+ /** Settings for cancel button shown in footer. */
87
+ cancelButton: {
88
+ variant: "light",
89
+ isOutline: false,
90
+ },
83
91
  },
84
92
  pager: {
85
93
  firstText: "«",
package/dist/Utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { __spreadArray } from "tslib";
1
+ import { __assign, __spreadArray } from "tslib";
2
2
  import { DebounceHelper } from './DebounceHelper';
3
3
  import { ensureTypeInfo } from './Model/NeoTypeInfo';
4
4
  var lut = [];
@@ -104,12 +104,8 @@ var Utils = /** @class */ (function () {
104
104
  */
105
105
  Utils.populatePartialWithDefaults = function (partial, defaults) {
106
106
  if (!partial)
107
- partial = {};
108
- for (var key in defaults) {
109
- if (!partial[key])
110
- partial[key] = defaults[key];
111
- }
112
- return partial;
107
+ return defaults;
108
+ return __assign(__assign({}, defaults), partial);
113
109
  };
114
110
  /**
115
111
  * Converts a string like 'user' to 'fa fa-user' or 'fa-user' to 'fa fa-user' or 'far-user' to 'far fa-user'
@@ -1,12 +1,13 @@
1
1
  import { __assign } from "tslib";
2
2
  import * as Rules from './Rules';
3
3
  import { ensureTypeInfo } from '../Model/NeoTypeInfo';
4
+ import NeoStrings from '../Localisation/NeoStrings';
4
5
  function addRuleToType(type, propertyName, rule) {
5
6
  ensureTypeInfo(type.constructor).neo.addAttributeRule(propertyName, rule);
6
7
  }
7
8
  export function Required(errorTextOrOptions) {
8
9
  return function (type, propertyKey) {
9
- var options = { errorText: "{0} is required", allowZero: false };
10
+ var options = { errorText: NeoStrings.validation.rules.required, allowZero: false };
10
11
  if (errorTextOrOptions !== undefined) {
11
12
  if (typeof errorTextOrOptions === "string") {
12
13
  options.errorText = errorTextOrOptions;
@@ -20,16 +21,14 @@ export function Required(errorTextOrOptions) {
20
21
  };
21
22
  }
22
23
  export function EmailAddress(errorText) {
23
- if (errorText === void 0) { errorText = "{0} is not a valid email address"; }
24
24
  return function (type, propertyKey) {
25
- var emailAddressRule = new Rules.EmailAddressRule(errorText);
25
+ var emailAddressRule = new Rules.EmailAddressRule(errorText !== null && errorText !== void 0 ? errorText : NeoStrings.validation.rules.emailAddress);
26
26
  addRuleToType(type, propertyKey, emailAddressRule);
27
27
  };
28
28
  }
29
29
  export function RegExp(expression, errorText) {
30
- if (errorText === void 0) { errorText = "{0} is in an invalid format"; }
31
30
  return function (type, propertyKey) {
32
- var regExpRule = new Rules.RegExpRule(expression, errorText);
31
+ var regExpRule = new Rules.RegExpRule(expression, errorText !== null && errorText !== void 0 ? errorText : NeoStrings.validation.rules.regExp);
33
32
  addRuleToType(type, propertyKey, regExpRule);
34
33
  };
35
34
  }
@@ -1,6 +1,7 @@
1
1
  import { __extends } from "tslib";
2
2
  import { RuleSeverity } from './ValidationState';
3
3
  import { Utils } from '../Utils';
4
+ import NeoStrings from '../Localisation/NeoStrings';
4
5
  var Rule = /** @class */ (function () {
5
6
  function Rule() {
6
7
  this.ruleId = Utils.uuidv4();
@@ -40,12 +41,12 @@ var StringLengthRule = /** @class */ (function (_super) {
40
41
  var errorTextValue = this.errorText;
41
42
  if (this.minLength && (!value || value.length < this.minLength)) {
42
43
  if (!errorTextValue)
43
- errorTextValue = "{0} cannot be less than {1} characters in length";
44
+ errorTextValue = NeoStrings.validation.rules.stringLengthLessThan;
44
45
  context.addError(errorTextValue.format(propertyInstance.propertyInfo.readableName, this.minLength.toString(), this.maxLength.toString()));
45
46
  }
46
47
  else if (value && value.length > this.maxLength) {
47
48
  if (!errorTextValue)
48
- errorTextValue = "{0} cannot be more than {1} characters in length";
49
+ errorTextValue = NeoStrings.validation.rules.stringLengthMoreThan;
49
50
  context.addError(errorTextValue.format(propertyInstance.propertyInfo.readableName, this.maxLength.toString()));
50
51
  }
51
52
  };
package/dist/index.d.ts CHANGED
@@ -12,6 +12,7 @@ import { MenuUtils } from './Components/ContextMenu/MenuUtils';
12
12
  import FileUtils from "./FileUtils";
13
13
  import { runInTask } from './Components/TaskRunner/Decorators';
14
14
  import { createProperty } from "./Model/PropertyInstance";
15
+ import NeoStrings from "./Localisation/NeoStrings";
15
16
  import * as Attributes from './Model/Decorators';
16
17
  import * as Rules from './Validation/Decorators';
17
18
  import * as AppServices from './AppServices';
@@ -28,7 +29,7 @@ import * as SignalR from './SignalR';
28
29
  import * as Validation from './Validation';
29
30
  import * as Views from './Views/IViewBase';
30
31
  declare const NotifyUtils: Components.INotificationHelper;
31
- export { AppServices, Attributes, Components, Data, DateUtils, DebounceHelper, EnumHelper, FileUtils, JsonSchema, Localisation, List, MenuUtils, Misc, ModalUtils, Model, NeoModel, Network, NotifyUtils, NumberUtils, Routing, Rules, Security, SignalR, StringUtils, Validation, Views, };
32
+ export { AppServices, Attributes, Components, Data, DateUtils, DebounceHelper, EnumHelper, FileUtils, JsonSchema, Localisation, List, MenuUtils, Misc, ModalUtils, Model, NeoModel, NeoStrings, Network, NotifyUtils, NumberUtils, Routing, Rules, Security, SignalR, StringUtils, Validation, Views, };
32
33
  export { runInTask, createProperty };
33
34
  export { default as ModelBase } from './Model/ModelBase';
34
35
  export { default as ValueObject } from './Model/ValueObject';
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ import { MenuUtils } from './Components/ContextMenu/MenuUtils';
13
13
  import FileUtils from "./FileUtils";
14
14
  import { runInTask } from './Components/TaskRunner/Decorators';
15
15
  import { createProperty } from "./Model/PropertyInstance";
16
+ import NeoStrings from "./Localisation/NeoStrings";
16
17
  // Namespaced exports from 1 file
17
18
  import * as Attributes from './Model/Decorators';
18
19
  import * as Rules from './Validation/Decorators';
@@ -33,7 +34,7 @@ import * as Views from './Views/IViewBase';
33
34
  import { NotificationHelper } from './Components/Notifications/NotificationHelper';
34
35
  var NotifyUtils = new NotificationHelper();
35
36
  // Types
36
- export { AppServices, Attributes, Components, Data, DateUtils, DebounceHelper, EnumHelper, FileUtils, JsonSchema, Localisation, List, MenuUtils, Misc, ModalUtils, Model, NeoModel, Network, NotifyUtils, NumberUtils, Routing, Rules, Security, SignalR, StringUtils, Validation, Views, };
37
+ export { AppServices, Attributes, Components, Data, DateUtils, DebounceHelper, EnumHelper, FileUtils, JsonSchema, Localisation, List, MenuUtils, Misc, ModalUtils, Model, NeoModel, NeoStrings, Network, NotifyUtils, NumberUtils, Routing, Rules, Security, SignalR, StringUtils, Validation, Views, };
37
38
  // Functions
38
39
  export { runInTask, createProperty };
39
40
  export { default as ModelBase } from './Model/ModelBase';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "0.10.77",
3
+ "version": "0.10.79",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/CHANGELOG.md DELETED
@@ -1,15 +0,0 @@
1
-
2
-
3
- # Breaking changes
4
-
5
- ## 0.10.65 (6 March 2023)
6
-
7
- * `IErrorHandler` now requires the return type to be `Promise<IErrorDisplay>` instead of `IErrorDisplay`.
8
- * Most of the protected methods in `ErrorHandler` have been changed to `async`.
9
- * These changes were required in order to be able to read errors from axios blob responses.
10
-
11
- # Change Log
12
-
13
- ## 0.10.65 (6 March 2023)
14
-
15
- * Fixed error handler not parsing axios responses when response type is `blob`.