@singularsystems/neo-core 1.0.0-beta.8 → 1.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.
- package/CHANGELOG.md +15 -0
- package/README.md +4 -0
- package/dist/AppServices/Config/ConfigModel.d.ts +3 -1
- package/dist/AppServices/Config/ConfigService.d.ts +15 -4
- package/dist/AppServices/Config/ConfigService.js +40 -18
- package/dist/AppServices/NeoTypes.d.ts +6 -0
- package/dist/AppServices/NeoTypes.js +7 -1
- package/dist/AppServices/ServiceIdentifier.js +2 -1
- package/dist/AxiosUtils.d.ts +27 -0
- package/dist/AxiosUtils.js +103 -0
- package/dist/Components/ErrorHandler.d.ts +12 -14
- package/dist/Components/ErrorHandler.js +15 -36
- package/dist/Components/FileManager/FileManager.js +5 -4
- package/dist/Components/FileManager/FileUploadBatch.js +2 -1
- package/dist/Components/Notifications/Notification.js +2 -1
- package/dist/Components/Notifications/NotificationHelper.js +2 -1
- package/dist/Components/Notifications/NotificationStore.js +2 -1
- package/dist/Components/TaskRunner/ProgressState.js +2 -1
- package/dist/Components/TaskRunner/TaskRunner.js +2 -1
- package/dist/ConnectionManager.js +2 -1
- package/dist/Data/ApiDataSource.d.ts +25 -26
- package/dist/Data/ApiDataSource.js +87 -97
- package/dist/Data/AsyncDataSource.d.ts +6 -2
- package/dist/Data/AsyncDataSource.js +22 -2
- package/dist/Data/CacheService.d.ts +4 -7
- package/dist/Data/CacheService.js +7 -5
- package/dist/Data/DataCacheEntry.d.ts +0 -4
- package/dist/Data/DataCacheEntry.js +0 -6
- package/dist/Data/DataView.js +4 -2
- package/dist/Data/Paging/PageManager.js +9 -8
- package/dist/Data/Paging/PageRequest.js +2 -1
- package/dist/Data/Serialiser.js +1 -0
- package/dist/Data/StaticDataSource.d.ts +1 -2
- package/dist/Data/StaticDataSource.js +0 -3
- package/dist/Data/WindowedDataView.js +2 -1
- package/dist/Data/index.d.ts +1 -1
- package/dist/Data/index.js +1 -1
- package/dist/Dates/DateUtils.js +2 -1
- package/dist/Extensions.d.ts +0 -4
- package/dist/Extensions.js +1 -1
- package/dist/IndexDb/IDbSet.d.ts +11 -0
- package/dist/JsonSchema/JsonSchemaTypes.d.ts +1 -0
- package/dist/Localisation/NeoStrings.d.ts +3 -0
- package/dist/Localisation/NeoStrings.js +3 -0
- package/dist/Model/BaseModels/AuditValues.js +4 -2
- package/dist/Model/BaseModels/CriteriaBase.js +2 -1
- package/dist/Model/BaseModels/ReasonedUserEvent.js +2 -1
- package/dist/Model/BaseModels/UserEvent.js +4 -2
- package/dist/Model/BindableBase.js +2 -1
- package/dist/Model/IModelBase.d.ts +3 -3
- package/dist/Model/ModelCreatorBase.js +2 -1
- package/dist/Model/ModelFieldInfo.js +2 -1
- package/dist/Model/ObservableValue.js +2 -1
- package/dist/NumberUtils.d.ts +3 -1
- package/dist/NumberUtils.js +2 -2
- package/dist/Routing/MenuItemProvider.js +2 -1
- package/dist/Routing/RouteSecurityService.js +2 -1
- package/dist/Security/LoginErrorHandler.js +2 -1
- package/dist/Security/SecurityService.js +2 -1
- package/dist/SignalR/IServerMessageSubscriber.d.ts +4 -0
- package/dist/SignalR/index.d.ts +1 -0
- package/dist/Validation/DisplayHelper.d.ts +3 -1
- package/dist/Validation/RuleContext.d.ts +4 -0
- package/dist/Validation/RuleContext.js +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +9 -7
- package/dist/Decimal/DecimalService.d.ts +0 -23
- package/dist/Decimal/DecimalService.js +0 -38
- package/dist/Decimal/IDecimal.d.ts +0 -25
- package/dist/Numeric/IDecimal.d.ts +0 -25
- /package/dist/{Decimal/IDecimal.js → IndexDb/IDbSet.js} +0 -0
- /package/dist/{Numeric/IDecimal.js → SignalR/IServerMessageSubscriber.js} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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`.
|
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This project contains the core functionality of the neo client library.
|
|
4
4
|
|
|
5
|
+
## Building
|
|
6
|
+
|
|
7
|
+
Run `yarn dlx @yarnpkg/sdks vscode` to enable typescript for yarn in vscode.
|
|
8
|
+
|
|
5
9
|
## Testing
|
|
6
10
|
|
|
7
11
|
To debug the tests, you need to add the following to .vscode\launch.json
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface IConfigModelData {
|
|
2
2
|
readonly baseUrl: string;
|
|
3
3
|
/**
|
|
4
4
|
* True by default if the NODE_ENV environment variable is "development".
|
|
@@ -8,6 +8,8 @@ export interface IConfigModel {
|
|
|
8
8
|
* This must be specified in your config file to be set to true.
|
|
9
9
|
*/
|
|
10
10
|
isTest: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface IConfigModel extends IConfigModelData {
|
|
11
13
|
readonly isTestOrDevelopment: boolean;
|
|
12
14
|
initialise(): void;
|
|
13
15
|
}
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosPromise } from "axios";
|
|
2
|
+
import { IConfigModel, IConfigModelData } from './ConfigModel';
|
|
3
|
+
import { IDbSet } from "../../IndexDb/IDbSet";
|
|
2
4
|
export interface IConfigService {
|
|
3
5
|
/**
|
|
4
|
-
* Load the config file from the specified path.
|
|
6
|
+
* Load and process the config file from the specified path.
|
|
5
7
|
* Path will default to [baseUrl]/config.json
|
|
6
8
|
* @param path Optional path.
|
|
9
|
+
* @param store Offline store to allow offline retrieval.
|
|
7
10
|
*/
|
|
8
|
-
loadConfig(path?: string): Promise<IConfigModel>;
|
|
11
|
+
loadConfig(path?: string, store?: IDbSet<IConfigModelData>): Promise<IConfigModel>;
|
|
12
|
+
/** Fetch the raw config data from the server. */
|
|
13
|
+
fetchConfig(path?: string): Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* Sets the raw config data.
|
|
16
|
+
* Use this if `loadConfig` fails, and you have an offline copy of the config data. */
|
|
17
|
+
setConfig(configData: any): IConfigModel;
|
|
9
18
|
}
|
|
10
19
|
export declare class ConfigService implements IConfigService {
|
|
11
20
|
private config;
|
|
12
21
|
constructor(config: IConfigModel);
|
|
13
|
-
loadConfig(path?: string): Promise<IConfigModel>;
|
|
22
|
+
loadConfig(path?: string, store?: IDbSet<IConfigModelData>): Promise<IConfigModel>;
|
|
23
|
+
fetchConfig(path?: string | undefined): AxiosPromise<any>;
|
|
24
|
+
setConfig(configData: any): IConfigModel;
|
|
14
25
|
static get isDevelopment(): boolean;
|
|
15
26
|
}
|
|
@@ -2,37 +2,58 @@ import { __awaiter, __decorate, __generator, __metadata, __param } from "tslib";
|
|
|
2
2
|
import { injectable, inject } from 'inversify';
|
|
3
3
|
import Axios from "axios";
|
|
4
4
|
import NeoTypes from '../NeoTypes';
|
|
5
|
-
|
|
5
|
+
import AxiosUtils from "../../AxiosUtils";
|
|
6
|
+
var ConfigService = /** @class */ (function () {
|
|
6
7
|
function ConfigService(config) {
|
|
7
8
|
this.config = config;
|
|
8
9
|
}
|
|
9
|
-
ConfigService.prototype.loadConfig = function (path) {
|
|
10
|
+
ConfigService.prototype.loadConfig = function (path, store) {
|
|
10
11
|
return __awaiter(this, void 0, void 0, function () {
|
|
11
|
-
var
|
|
12
|
+
var configData, e_1;
|
|
12
13
|
return __generator(this, function (_a) {
|
|
13
14
|
switch (_a.label) {
|
|
14
15
|
case 0:
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
_a.trys.push([0, 4, , 7]);
|
|
17
|
+
return [4 /*yield*/, this.fetchConfig(path)];
|
|
17
18
|
case 1:
|
|
18
|
-
_a.
|
|
19
|
-
|
|
20
|
-
return [4 /*yield*/,
|
|
19
|
+
configData = (_a.sent()).data;
|
|
20
|
+
if (!store) return [3 /*break*/, 3];
|
|
21
|
+
return [4 /*yield*/, store.putAsync(configData, 1)];
|
|
21
22
|
case 2:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
_a.sent();
|
|
24
|
+
_a.label = 3;
|
|
25
|
+
case 3: return [3 /*break*/, 7];
|
|
26
|
+
case 4:
|
|
27
|
+
e_1 = _a.sent();
|
|
28
|
+
if (!(store && AxiosUtils.isNetworkError(e_1) && !window.navigator.onLine)) return [3 /*break*/, 6];
|
|
29
|
+
return [4 /*yield*/, store.getAsync(1)];
|
|
30
|
+
case 5:
|
|
31
|
+
// get config from index db
|
|
32
|
+
configData = _a.sent();
|
|
33
|
+
_a.label = 6;
|
|
34
|
+
case 6:
|
|
35
|
+
if (!configData) {
|
|
36
|
+
throw new Error("ConfigService - Error loading configuration: ".concat(e_1));
|
|
37
|
+
}
|
|
38
|
+
return [3 /*break*/, 7];
|
|
39
|
+
case 7: return [2 /*return*/, this.setConfig(configData)];
|
|
32
40
|
}
|
|
33
41
|
});
|
|
34
42
|
});
|
|
35
43
|
};
|
|
44
|
+
ConfigService.prototype.fetchConfig = function (path) {
|
|
45
|
+
path = path !== null && path !== void 0 ? path : "".concat(this.config.baseUrl, "/config.json");
|
|
46
|
+
// Fetch config with timestamp to prevent caching
|
|
47
|
+
var timestamp = new Date().getTime();
|
|
48
|
+
return Axios.get("".concat(path, "?").concat(timestamp));
|
|
49
|
+
};
|
|
50
|
+
ConfigService.prototype.setConfig = function (configData) {
|
|
51
|
+
// The raw parsed json objects properties are copied into the config model.
|
|
52
|
+
// It is up to the config model to transform its properties if required (in the initialise method).
|
|
53
|
+
Object.assign(this.config, configData);
|
|
54
|
+
this.config.initialise();
|
|
55
|
+
return this.config;
|
|
56
|
+
};
|
|
36
57
|
Object.defineProperty(ConfigService, "isDevelopment", {
|
|
37
58
|
get: function () {
|
|
38
59
|
return process.env.NODE_ENV === "development";
|
|
@@ -47,3 +68,4 @@ export var ConfigService = /** @class */ (function () {
|
|
|
47
68
|
], ConfigService);
|
|
48
69
|
return ConfigService;
|
|
49
70
|
}());
|
|
71
|
+
export { ConfigService };
|
|
@@ -19,6 +19,7 @@ import { IContextMenuState } from '../Components/ContextMenu/ContextMenu';
|
|
|
19
19
|
import { INavigationHelper } from '../Routing/INavigationHelper';
|
|
20
20
|
import { ILoginErrorHandler } from '../Security/ILoginErrorHandler';
|
|
21
21
|
import { IDecimalService } from "../Numeric";
|
|
22
|
+
import { IServerMessageSubscriber } from "../SignalR/IServerMessageSubscriber";
|
|
22
23
|
declare const NeoTypes: {
|
|
23
24
|
Axios: ServiceIdentifier<import("axios").AxiosStatic>;
|
|
24
25
|
Config: {
|
|
@@ -27,6 +28,7 @@ declare const NeoTypes: {
|
|
|
27
28
|
};
|
|
28
29
|
Core: {
|
|
29
30
|
AutoRunnerFactory: ServiceIdentifier<IAutoRunnerFactory>;
|
|
31
|
+
/** @deprecated Use Messaging.ConnectionManager */
|
|
30
32
|
ConnectionManager: ServiceIdentifier<IConnectionManager>;
|
|
31
33
|
DecimalService: ServiceIdentifier<IDecimalService<import("../Numeric").IDecimal>>;
|
|
32
34
|
ModelCreator: ServiceIdentifier<IModelCreatorBase>;
|
|
@@ -34,6 +36,10 @@ declare const NeoTypes: {
|
|
|
34
36
|
Localisation: {
|
|
35
37
|
LocalisationService: ServiceIdentifier<ILocalisationService>;
|
|
36
38
|
};
|
|
39
|
+
Messaging: {
|
|
40
|
+
ConnectionManager: ServiceIdentifier<IConnectionManager>;
|
|
41
|
+
ServerMessageSubscriber: ServiceIdentifier<IServerMessageSubscriber>;
|
|
42
|
+
};
|
|
37
43
|
Routing: {
|
|
38
44
|
MenuItemProvider: ServiceIdentifier<IMenuItemProvider<import("../Routing").IMenuRoute>>;
|
|
39
45
|
NavigationHelper: ServiceIdentifier<INavigationHelper>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ServiceIdentifier } from './ServiceIdentifier';
|
|
2
|
+
var connectionManagerType = new ServiceIdentifier("Neo.ConnectionManager");
|
|
2
3
|
// Neo Module Type Symbols
|
|
3
4
|
var NeoTypes = {
|
|
4
5
|
Axios: new ServiceIdentifier("Neo.Axios"),
|
|
@@ -8,13 +9,18 @@ var NeoTypes = {
|
|
|
8
9
|
},
|
|
9
10
|
Core: {
|
|
10
11
|
AutoRunnerFactory: new ServiceIdentifier("Neo.AutoRunnerFactory"),
|
|
11
|
-
|
|
12
|
+
/** @deprecated Use Messaging.ConnectionManager */
|
|
13
|
+
ConnectionManager: connectionManagerType,
|
|
12
14
|
DecimalService: new ServiceIdentifier("Neo.DecimalService"),
|
|
13
15
|
ModelCreator: new ServiceIdentifier("Neo.ModelCreator")
|
|
14
16
|
},
|
|
15
17
|
Localisation: {
|
|
16
18
|
LocalisationService: new ServiceIdentifier("Neo.Localisation")
|
|
17
19
|
},
|
|
20
|
+
Messaging: {
|
|
21
|
+
ConnectionManager: connectionManagerType,
|
|
22
|
+
ServerMessageSubscriber: new ServiceIdentifier("Neo.ServerMessageSubscriber"),
|
|
23
|
+
},
|
|
18
24
|
Routing: {
|
|
19
25
|
MenuItemProvider: new ServiceIdentifier("Neo.MenuItemProvider"),
|
|
20
26
|
NavigationHelper: new ServiceIdentifier("Neo.NavigationHelper"),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Strongly typed identifier for a service.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
var ServiceIdentifier = /** @class */ (function () {
|
|
5
5
|
/**
|
|
6
6
|
* Creates a service identifier.
|
|
7
7
|
* @param name Name used for debugging, not required to be unique.
|
|
@@ -36,3 +36,4 @@ export var ServiceIdentifier = /** @class */ (function () {
|
|
|
36
36
|
ServiceIdentifier.typeNames = new Set();
|
|
37
37
|
return ServiceIdentifier;
|
|
38
38
|
}());
|
|
39
|
+
export { ServiceIdentifier };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AxiosError, AxiosPromise, AxiosResponse } from "axios";
|
|
2
|
+
import { IErrorDetails } from "./Components/ErrorHandler";
|
|
3
|
+
interface ISuccessResponse<TData> {
|
|
4
|
+
success: true;
|
|
5
|
+
data: TData;
|
|
6
|
+
}
|
|
7
|
+
interface IFailedResponse<TData> extends IErrorDetails<TData> {
|
|
8
|
+
success: false;
|
|
9
|
+
}
|
|
10
|
+
export default class AxiosUtils {
|
|
11
|
+
/**
|
|
12
|
+
* Awaits an axios promise and returns an object indicating success or failure.
|
|
13
|
+
* @param filter Only errors matching this filter will be caught.
|
|
14
|
+
*/
|
|
15
|
+
static catchErrors<TData>(request: AxiosPromise<TData>, filter?: (r?: AxiosResponse) => boolean): Promise<ISuccessResponse<TData> | IFailedResponse<any>>;
|
|
16
|
+
/** Reads the properties of an axios error. */
|
|
17
|
+
static readError(e: AxiosError): Promise<IFailedResponse<any>>;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the error data is a blob object, and reads from it if that is the case.
|
|
20
|
+
*/
|
|
21
|
+
static ensureAxiosErrorData(responseData: any): Promise<any>;
|
|
22
|
+
static isClientError(response?: AxiosResponse): boolean;
|
|
23
|
+
static isServerError(response?: AxiosResponse): boolean;
|
|
24
|
+
/** Returns true if the error was raised from axios, and is a network error. E.g. no response was received from the server. */
|
|
25
|
+
static isNetworkError(e: any): boolean;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
import { isAxiosError } from "axios";
|
|
3
|
+
var AxiosUtils = /** @class */ (function () {
|
|
4
|
+
function AxiosUtils() {
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Awaits an axios promise and returns an object indicating success or failure.
|
|
8
|
+
* @param filter Only errors matching this filter will be caught.
|
|
9
|
+
*/
|
|
10
|
+
AxiosUtils.catchErrors = function (request, filter) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
12
|
+
var waited, e_1;
|
|
13
|
+
return __generator(this, function (_a) {
|
|
14
|
+
switch (_a.label) {
|
|
15
|
+
case 0:
|
|
16
|
+
_a.trys.push([0, 2, , 5]);
|
|
17
|
+
return [4 /*yield*/, request];
|
|
18
|
+
case 1:
|
|
19
|
+
waited = _a.sent();
|
|
20
|
+
return [2 /*return*/, {
|
|
21
|
+
data: waited.data,
|
|
22
|
+
success: true,
|
|
23
|
+
}];
|
|
24
|
+
case 2:
|
|
25
|
+
e_1 = _a.sent();
|
|
26
|
+
if (!isAxiosError(e_1)) return [3 /*break*/, 4];
|
|
27
|
+
if (!(filter === undefined || filter(e_1.response))) return [3 /*break*/, 4];
|
|
28
|
+
return [4 /*yield*/, this.readError(e_1)];
|
|
29
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
30
|
+
case 4: throw e_1;
|
|
31
|
+
case 5: return [2 /*return*/];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
/** Reads the properties of an axios error. */
|
|
37
|
+
AxiosUtils.readError = function (e) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
39
|
+
var data, isServerError;
|
|
40
|
+
var _a, _b;
|
|
41
|
+
return __generator(this, function (_c) {
|
|
42
|
+
switch (_c.label) {
|
|
43
|
+
case 0:
|
|
44
|
+
data = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
45
|
+
if (!data) return [3 /*break*/, 2];
|
|
46
|
+
return [4 /*yield*/, this.ensureAxiosErrorData(data)];
|
|
47
|
+
case 1:
|
|
48
|
+
data = _c.sent();
|
|
49
|
+
_c.label = 2;
|
|
50
|
+
case 2:
|
|
51
|
+
isServerError = false;
|
|
52
|
+
if ((_b = e.response) === null || _b === void 0 ? void 0 : _b.status) {
|
|
53
|
+
isServerError = this.isServerError(e.response);
|
|
54
|
+
}
|
|
55
|
+
return [2 /*return*/, {
|
|
56
|
+
success: false,
|
|
57
|
+
isServerError: isServerError,
|
|
58
|
+
isNetworkError: e.response === undefined,
|
|
59
|
+
data: data,
|
|
60
|
+
error: e,
|
|
61
|
+
}];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Checks if the error data is a blob object, and reads from it if that is the case.
|
|
68
|
+
*/
|
|
69
|
+
AxiosUtils.ensureAxiosErrorData = function (responseData) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var errorText;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
if (!(responseData instanceof Blob)) return [3 /*break*/, 2];
|
|
76
|
+
return [4 /*yield*/, responseData.text()];
|
|
77
|
+
case 1:
|
|
78
|
+
errorText = _a.sent();
|
|
79
|
+
if (responseData.type.toLowerCase().includes('json')) {
|
|
80
|
+
return [2 /*return*/, JSON.parse(errorText)];
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return [2 /*return*/, errorText];
|
|
84
|
+
}
|
|
85
|
+
_a.label = 2;
|
|
86
|
+
case 2: return [2 /*return*/, responseData];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
AxiosUtils.isClientError = function (response) {
|
|
92
|
+
return response !== undefined && response.status >= 400 && response.status < 500;
|
|
93
|
+
};
|
|
94
|
+
AxiosUtils.isServerError = function (response) {
|
|
95
|
+
return response !== undefined && response.status >= 500 && response.status < 600;
|
|
96
|
+
};
|
|
97
|
+
/** Returns true if the error was raised from axios, and is a network error. E.g. no response was received from the server. */
|
|
98
|
+
AxiosUtils.isNetworkError = function (e) {
|
|
99
|
+
return isAxiosError(e) && e.response === undefined;
|
|
100
|
+
};
|
|
101
|
+
return AxiosUtils;
|
|
102
|
+
}());
|
|
103
|
+
export default AxiosUtils;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { AxiosError, AxiosResponse } from 'axios';
|
|
2
2
|
import { INotificationHelper } from './Notifications/INotificationHelper';
|
|
3
|
-
export interface
|
|
4
|
-
header: string;
|
|
3
|
+
export interface IErrorDetails<TData> {
|
|
5
4
|
statusCode?: number;
|
|
6
5
|
statusText?: string;
|
|
7
|
-
|
|
8
|
-
data?: IErrorData;
|
|
6
|
+
data?: TData;
|
|
9
7
|
/** True if this is a 500 type error from the server. */
|
|
10
8
|
isServerError?: boolean;
|
|
9
|
+
/** True if the server could not be reached. */
|
|
10
|
+
isNetworkError?: boolean;
|
|
11
|
+
/** Original axios error. */
|
|
12
|
+
error: AxiosError;
|
|
13
|
+
}
|
|
14
|
+
export interface IErrorDisplay extends IErrorDetails<IErrorData> {
|
|
15
|
+
header: string;
|
|
16
|
+
body: any;
|
|
11
17
|
/** Cancels displaying of the error. */
|
|
12
18
|
cancelDisplay?: boolean;
|
|
13
19
|
}
|
|
@@ -33,11 +39,7 @@ export declare enum ErrorDisplayType {
|
|
|
33
39
|
}
|
|
34
40
|
export declare class ErrorHandler implements IErrorHandler {
|
|
35
41
|
private notifications;
|
|
36
|
-
|
|
37
|
-
constructor(notifications: INotificationHelper, blobType?: {
|
|
38
|
-
new (blobParts?: BlobPart[] | undefined, options?: BlobPropertyBag | undefined): Blob;
|
|
39
|
-
prototype: Blob;
|
|
40
|
-
});
|
|
42
|
+
constructor(notifications: INotificationHelper);
|
|
41
43
|
showError(error: any, displayType: ErrorDisplayType): Promise<void>;
|
|
42
44
|
parseError(error: any): Promise<IErrorDisplay>;
|
|
43
45
|
protected getAxiosError(error: AxiosError, response?: AxiosResponse): Promise<IErrorDisplay>;
|
|
@@ -52,11 +54,7 @@ export declare class ErrorHandler implements IErrorHandler {
|
|
|
52
54
|
* @param error Axios error.
|
|
53
55
|
*/
|
|
54
56
|
parseAxiosError(header: string, body: string, error: AxiosError): Promise<IErrorDisplay>;
|
|
55
|
-
|
|
56
|
-
* Checks if the error data is a blob object, and reads from it if that is the case.
|
|
57
|
-
*/
|
|
58
|
-
protected ensureAxiosErrorData(responseData: any): Promise<any>;
|
|
59
|
-
protected getGeneralError(error: any): IErrorDisplay;
|
|
57
|
+
protected getGeneralError(error: AxiosError): IErrorDisplay;
|
|
60
58
|
protected displayError(displayType: ErrorDisplayType, error: any, errorDisplay: IErrorDisplay): void;
|
|
61
59
|
protected displayModal(error: any, errorDisplay: IErrorDisplay): void;
|
|
62
60
|
protected displayNotification(error: any, errorDisplay: IErrorDisplay): void;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { __awaiter, __decorate, __generator, __metadata, __param } from "tslib";
|
|
2
2
|
import { injectable, inject } from 'inversify';
|
|
3
|
+
import { isAxiosError } from 'axios';
|
|
3
4
|
import { ModalUtils } from './Modal/ModalUtils';
|
|
4
5
|
import NeoTypes from '../AppServices/NeoTypes';
|
|
5
6
|
import NeoStrings from '../Localisation/NeoStrings';
|
|
7
|
+
import AxiosUtils from "../AxiosUtils";
|
|
6
8
|
export var ErrorDisplayType;
|
|
7
9
|
(function (ErrorDisplayType) {
|
|
8
10
|
/** Show the error text in a modal. */
|
|
@@ -12,11 +14,9 @@ export var ErrorDisplayType;
|
|
|
12
14
|
/** Do nothing, error will be re-thrown. */
|
|
13
15
|
ErrorDisplayType[ErrorDisplayType["ThrowError"] = 2] = "ThrowError";
|
|
14
16
|
})(ErrorDisplayType || (ErrorDisplayType = {}));
|
|
15
|
-
|
|
16
|
-
function ErrorHandler(notifications
|
|
17
|
-
if (blobType === void 0) { blobType = Blob; }
|
|
17
|
+
var ErrorHandler = /** @class */ (function () {
|
|
18
|
+
function ErrorHandler(notifications) {
|
|
18
19
|
this.notifications = notifications;
|
|
19
|
-
this.blobType = blobType;
|
|
20
20
|
}
|
|
21
21
|
ErrorHandler.prototype.showError = function (error, displayType) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -41,7 +41,7 @@ export var ErrorHandler = /** @class */ (function () {
|
|
|
41
41
|
return __generator(this, function (_a) {
|
|
42
42
|
switch (_a.label) {
|
|
43
43
|
case 0:
|
|
44
|
-
if (!error
|
|
44
|
+
if (!isAxiosError(error)) return [3 /*break*/, 2];
|
|
45
45
|
return [4 /*yield*/, this.getAxiosError(error, error.response)];
|
|
46
46
|
case 1: return [2 /*return*/, _a.sent()];
|
|
47
47
|
case 2: return [2 /*return*/, this.getGeneralError(error)];
|
|
@@ -90,6 +90,7 @@ export var ErrorHandler = /** @class */ (function () {
|
|
|
90
90
|
errorDisplay = this.getGeneralError(error);
|
|
91
91
|
// Add status code of -1 to differentiate network errors from code exceptions.
|
|
92
92
|
errorDisplay.statusCode = -1;
|
|
93
|
+
errorDisplay.isNetworkError = true;
|
|
93
94
|
_b.label = 13;
|
|
94
95
|
case 13: return [2 /*return*/, errorDisplay];
|
|
95
96
|
}
|
|
@@ -97,7 +98,9 @@ export var ErrorHandler = /** @class */ (function () {
|
|
|
97
98
|
});
|
|
98
99
|
};
|
|
99
100
|
ErrorHandler.prototype.get400Error = function (error) {
|
|
100
|
-
|
|
101
|
+
var _a;
|
|
102
|
+
var isGet = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.config.method) === "get";
|
|
103
|
+
return this.parseAxiosError(NeoStrings.errors.invalidDataTitle, isGet ? NeoStrings.errors.invalidDataBodyGet : NeoStrings.errors.invalidDataBody, error);
|
|
101
104
|
};
|
|
102
105
|
ErrorHandler.prototype.get401Error = function (error) {
|
|
103
106
|
return this.parseAxiosError(NeoStrings.errors.notAuthenticatedTitle, NeoStrings.errors.notAuthenticatedBody, error);
|
|
@@ -115,15 +118,15 @@ export var ErrorHandler = /** @class */ (function () {
|
|
|
115
118
|
* @param error Axios error.
|
|
116
119
|
*/
|
|
117
120
|
ErrorHandler.prototype.parseAxiosError = function (header, body, error) {
|
|
118
|
-
var _a;
|
|
119
121
|
return __awaiter(this, void 0, void 0, function () {
|
|
120
122
|
var errorDisplay, rawErrorData_1, errorData_1;
|
|
123
|
+
var _a;
|
|
121
124
|
return __generator(this, function (_b) {
|
|
122
125
|
switch (_b.label) {
|
|
123
126
|
case 0:
|
|
124
|
-
errorDisplay = { header: header, body: body, statusText: error.message, statusCode: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status };
|
|
127
|
+
errorDisplay = { header: header, body: body, statusText: error.message, statusCode: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status, error: error };
|
|
125
128
|
if (!error.response.data) return [3 /*break*/, 2];
|
|
126
|
-
return [4 /*yield*/,
|
|
129
|
+
return [4 /*yield*/, AxiosUtils.ensureAxiosErrorData(error.response.data)];
|
|
127
130
|
case 1:
|
|
128
131
|
rawErrorData_1 = _b.sent();
|
|
129
132
|
if (rawErrorData_1.title) {
|
|
@@ -156,34 +159,9 @@ export var ErrorHandler = /** @class */ (function () {
|
|
|
156
159
|
});
|
|
157
160
|
});
|
|
158
161
|
};
|
|
159
|
-
/**
|
|
160
|
-
* Checks if the error data is a blob object, and reads from it if that is the case.
|
|
161
|
-
*/
|
|
162
|
-
ErrorHandler.prototype.ensureAxiosErrorData = function (responseData) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
-
var errorText;
|
|
165
|
-
return __generator(this, function (_a) {
|
|
166
|
-
switch (_a.label) {
|
|
167
|
-
case 0:
|
|
168
|
-
if (!(responseData instanceof this.blobType)) return [3 /*break*/, 2];
|
|
169
|
-
return [4 /*yield*/, responseData.text()];
|
|
170
|
-
case 1:
|
|
171
|
-
errorText = _a.sent();
|
|
172
|
-
if (responseData.type.toLowerCase().includes('json')) {
|
|
173
|
-
return [2 /*return*/, JSON.parse(errorText)];
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
return [2 /*return*/, errorText];
|
|
177
|
-
}
|
|
178
|
-
_a.label = 2;
|
|
179
|
-
case 2: return [2 /*return*/, responseData];
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
162
|
ErrorHandler.prototype.getGeneralError = function (error) {
|
|
185
163
|
var errorDescription = error.message ? error.message : error;
|
|
186
|
-
return { header: NeoStrings.errors.generalTitle, body: errorDescription };
|
|
164
|
+
return { header: NeoStrings.errors.generalTitle, body: errorDescription, error: error };
|
|
187
165
|
};
|
|
188
166
|
ErrorHandler.prototype.displayError = function (displayType, error, errorDisplay) {
|
|
189
167
|
if (error instanceof Error) {
|
|
@@ -206,7 +184,8 @@ export var ErrorHandler = /** @class */ (function () {
|
|
|
206
184
|
ErrorHandler = __decorate([
|
|
207
185
|
injectable(),
|
|
208
186
|
__param(0, inject(NeoTypes.UI.GlobalNotifications.symbol)),
|
|
209
|
-
__metadata("design:paramtypes", [Object
|
|
187
|
+
__metadata("design:paramtypes", [Object])
|
|
210
188
|
], ErrorHandler);
|
|
211
189
|
return ErrorHandler;
|
|
212
190
|
}());
|
|
191
|
+
export { ErrorHandler };
|
|
@@ -9,7 +9,7 @@ import { Settings } from '../../Settings';
|
|
|
9
9
|
import { FileUploadBatch } from './FileUploadBatch';
|
|
10
10
|
import NeoStrings from '../../Localisation/NeoStrings';
|
|
11
11
|
var fileInputSymbol = Symbol("FileInput");
|
|
12
|
-
|
|
12
|
+
var FileManagerBase = /** @class */ (function () {
|
|
13
13
|
function FileManagerBase(uploadEndpointOrOptions, options) {
|
|
14
14
|
this.currentUploads = [];
|
|
15
15
|
if (uploadEndpointOrOptions === undefined || typeof uploadEndpointOrOptions === "string") {
|
|
@@ -97,9 +97,9 @@ export var FileManagerBase = /** @class */ (function () {
|
|
|
97
97
|
/**
|
|
98
98
|
* Checks if file extensions are allowed, then calls onFilesSelected, or uploadFiles
|
|
99
99
|
*/
|
|
100
|
-
FileManagerBase.prototype.processFiles = function (
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
FileManagerBase.prototype.processFiles = function (files_1) {
|
|
101
|
+
return __awaiter(this, arguments, void 0, function (files, options) {
|
|
102
|
+
if (options === void 0) { options = {}; }
|
|
103
103
|
return __generator(this, function (_a) {
|
|
104
104
|
if (files.length > 1 && !this.allowMultiple) {
|
|
105
105
|
files = [Array.from(files)[0]];
|
|
@@ -252,6 +252,7 @@ export var FileManagerBase = /** @class */ (function () {
|
|
|
252
252
|
], FileManagerBase.prototype, "currentUploads", void 0);
|
|
253
253
|
return FileManagerBase;
|
|
254
254
|
}());
|
|
255
|
+
export { FileManagerBase };
|
|
255
256
|
var FileManager = /** @class */ (function (_super) {
|
|
256
257
|
__extends(FileManager, _super);
|
|
257
258
|
function FileManager() {
|
|
@@ -2,7 +2,7 @@ import { __decorate, __metadata } from "tslib";
|
|
|
2
2
|
import { Utils } from "../../Utils";
|
|
3
3
|
import NeoModel from "../../Model/NeoModel";
|
|
4
4
|
import { Observable } from "../../Model/Decorators";
|
|
5
|
-
|
|
5
|
+
var FileUploadBatch = /** @class */ (function () {
|
|
6
6
|
function FileUploadBatch(files) {
|
|
7
7
|
this.recordIndex = {};
|
|
8
8
|
this.key = Utils.uuidv4();
|
|
@@ -81,3 +81,4 @@ export var FileUploadBatch = /** @class */ (function () {
|
|
|
81
81
|
], FileUploadBatch);
|
|
82
82
|
return FileUploadBatch;
|
|
83
83
|
}());
|
|
84
|
+
export { FileUploadBatch };
|
|
@@ -2,7 +2,7 @@ import { __decorate, __metadata } from "tslib";
|
|
|
2
2
|
import { Utils } from "../../Utils";
|
|
3
3
|
import { Observable } from '../../Model/Decorators';
|
|
4
4
|
import NeoModel from '../../Model/NeoModel';
|
|
5
|
-
|
|
5
|
+
var Notification = /** @class */ (function () {
|
|
6
6
|
function Notification(options, body) {
|
|
7
7
|
this.options = options;
|
|
8
8
|
this.body = body;
|
|
@@ -24,3 +24,4 @@ export var Notification = /** @class */ (function () {
|
|
|
24
24
|
], Notification);
|
|
25
25
|
return Notification;
|
|
26
26
|
}());
|
|
27
|
+
export { Notification };
|
|
@@ -3,7 +3,7 @@ import { Globals } from '../../Misc';
|
|
|
3
3
|
import NeoTypes from '../../AppServices/NeoTypes';
|
|
4
4
|
import { ModalUtils } from '../Modal/ModalUtils';
|
|
5
5
|
import { injectable, inject } from 'inversify';
|
|
6
|
-
|
|
6
|
+
var NotificationHelper = /** @class */ (function () {
|
|
7
7
|
/**
|
|
8
8
|
* Creates a new notification helper which can be bound to a ToastContainer / other alert ui component.
|
|
9
9
|
* @param store Optional store which contains the notification message objects.
|
|
@@ -109,3 +109,4 @@ export var NotificationHelper = /** @class */ (function () {
|
|
|
109
109
|
], NotificationHelper);
|
|
110
110
|
return NotificationHelper;
|
|
111
111
|
}());
|
|
112
|
+
export { NotificationHelper };
|
|
@@ -4,7 +4,7 @@ import { Notification } from './Notification';
|
|
|
4
4
|
import { Observable } from '../../Model/Decorators';
|
|
5
5
|
import NeoModel from '../../Model/NeoModel';
|
|
6
6
|
import { injectable } from 'inversify';
|
|
7
|
-
|
|
7
|
+
var NotificationStore = /** @class */ (function () {
|
|
8
8
|
function NotificationStore() {
|
|
9
9
|
this.notifications = [];
|
|
10
10
|
}
|
|
@@ -76,3 +76,4 @@ export var NotificationStore = /** @class */ (function () {
|
|
|
76
76
|
], NotificationStore);
|
|
77
77
|
return NotificationStore;
|
|
78
78
|
}());
|
|
79
|
+
export { NotificationStore };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import NeoModel from '../../Model/NeoModel';
|
|
3
3
|
import { Observable } from '../../Model/Decorators';
|
|
4
|
-
|
|
4
|
+
var ProgressState = /** @class */ (function () {
|
|
5
5
|
function ProgressState() {
|
|
6
6
|
this._progress = 0;
|
|
7
7
|
/** Animation state used by UI components. */
|
|
@@ -69,3 +69,4 @@ export var ProgressState = /** @class */ (function () {
|
|
|
69
69
|
], ProgressState);
|
|
70
70
|
return ProgressState;
|
|
71
71
|
}());
|
|
72
|
+
export { ProgressState };
|
|
@@ -6,7 +6,7 @@ import { injectable, inject } from 'inversify';
|
|
|
6
6
|
import { ErrorDisplayType } from '../ErrorHandler';
|
|
7
7
|
import { NeoTypes } from '../../AppServices';
|
|
8
8
|
import { ProgressState } from './ProgressState';
|
|
9
|
-
|
|
9
|
+
var TaskRunnerOptions = /** @class */ (function () {
|
|
10
10
|
function TaskRunnerOptions(taskRunner) {
|
|
11
11
|
this.taskRunner = taskRunner;
|
|
12
12
|
/** Specifies how the task runner must handle errors that are raised by your code. */
|
|
@@ -42,6 +42,7 @@ export var TaskRunnerOptions = /** @class */ (function () {
|
|
|
42
42
|
], TaskRunnerOptions);
|
|
43
43
|
return TaskRunnerOptions;
|
|
44
44
|
}());
|
|
45
|
+
export { TaskRunnerOptions };
|
|
45
46
|
var WaitForTaskRunnerOptions = /** @class */ (function (_super) {
|
|
46
47
|
__extends(WaitForTaskRunnerOptions, _super);
|
|
47
48
|
function WaitForTaskRunnerOptions() {
|