@genesislcap/foundation-comms 14.167.3-alpha-69ba23f.0 → 14.168.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/dts/auth/auth.d.ts.map +1 -1
- package/dist/dts/connect/connect.d.ts +11 -1
- package/dist/dts/connect/connect.d.ts.map +1 -1
- package/dist/dts/connect/connect.events.d.ts +173 -0
- package/dist/dts/connect/connect.events.d.ts.map +1 -0
- package/dist/dts/connect/http.connect.d.ts +1 -0
- package/dist/dts/connect/http.connect.d.ts.map +1 -1
- package/dist/dts/connect/index.d.ts +2 -0
- package/dist/dts/connect/index.d.ts.map +1 -1
- package/dist/dts/connect/message.d.ts +51 -0
- package/dist/dts/connect/message.d.ts.map +1 -1
- package/dist/dts/connect/socket.d.ts +72 -8
- package/dist/dts/connect/socket.d.ts.map +1 -1
- package/dist/dts/connect/socket.status.d.ts +79 -0
- package/dist/dts/connect/socket.status.d.ts.map +1 -0
- package/dist/dts/datasource/datasource.d.ts +9 -0
- package/dist/dts/datasource/datasource.d.ts.map +1 -1
- package/dist/dts/fdc3/fdc3.d.ts +17 -1
- package/dist/dts/fdc3/fdc3.d.ts.map +1 -1
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/networkMonitor/config.d.ts +56 -0
- package/dist/dts/networkMonitor/config.d.ts.map +1 -0
- package/dist/dts/networkMonitor/index.d.ts +4 -0
- package/dist/dts/networkMonitor/index.d.ts.map +1 -0
- package/dist/dts/networkMonitor/service.d.ts +193 -0
- package/dist/dts/networkMonitor/service.d.ts.map +1 -0
- package/dist/dts/networkMonitor/types.d.ts +133 -0
- package/dist/dts/networkMonitor/types.d.ts.map +1 -0
- package/dist/dts/testing/mocks/connect/connect.d.ts +1 -0
- package/dist/dts/testing/mocks/connect/connect.d.ts.map +1 -1
- package/dist/dts/testing/mocks/connect/socket.d.ts +5 -1
- package/dist/dts/testing/mocks/connect/socket.d.ts.map +1 -1
- package/dist/dts/testing/mocks/datasource/datasource.d.ts +1 -0
- package/dist/dts/testing/mocks/datasource/datasource.d.ts.map +1 -1
- package/dist/dts/user/user.d.ts +15 -0
- package/dist/dts/user/user.d.ts.map +1 -1
- package/dist/esm/auth/auth.js +5 -2
- package/dist/esm/connect/connect.events.js +113 -0
- package/dist/esm/connect/connect.js +30 -8
- package/dist/esm/connect/http.connect.js +6 -0
- package/dist/esm/connect/index.js +2 -0
- package/dist/esm/connect/message.js +25 -4
- package/dist/esm/connect/socket.js +113 -44
- package/dist/esm/connect/socket.status.js +119 -0
- package/dist/esm/datasource/datasource.js +18 -8
- package/dist/esm/fdc3/fdc3.js +4 -4
- package/dist/esm/index.js +1 -0
- package/dist/esm/networkMonitor/config.js +46 -0
- package/dist/esm/networkMonitor/index.js +3 -0
- package/dist/esm/networkMonitor/service.js +445 -0
- package/dist/esm/networkMonitor/types.js +5 -0
- package/dist/esm/testing/mocks/connect/connect.js +3 -0
- package/dist/esm/testing/mocks/connect/socket.js +1 -1
- package/dist/esm/testing/mocks/datasource/datasource.js +1 -0
- package/dist/esm/user/user.js +22 -1
- package/dist/foundation-comms.api.json +14711 -8166
- package/dist/foundation-comms.d.ts +841 -13
- package/docs/api/foundation-comms.commitevent.md +14 -0
- package/docs/api/foundation-comms.commiteventdetail.md +17 -0
- package/docs/api/foundation-comms.commiteventtype.md +12 -0
- package/docs/api/foundation-comms.connect.getmorecolumns.md +26 -0
- package/docs/api/foundation-comms.connect.md +1 -0
- package/docs/api/foundation-comms.connectevents.addcommitlistener.md +24 -0
- package/docs/api/foundation-comms.connectevents.addmetadatalistener.md +24 -0
- package/docs/api/foundation-comms.connectevents.addstreamlistener.md +25 -0
- package/docs/api/foundation-comms.connectevents.md +22 -0
- package/docs/api/foundation-comms.connecteventsemitter.md +24 -0
- package/docs/api/foundation-comms.connecteventsemitter.oncommitevent.md +25 -0
- package/docs/api/foundation-comms.connecteventsemitter.onmetadataevent.md +26 -0
- package/docs/api/foundation-comms.connecteventsemitter.onstreamcompleteevent.md +24 -0
- package/docs/api/foundation-comms.connecteventsemitter.onstreamevent.md +27 -0
- package/docs/api/foundation-comms.currentuser.md +2 -0
- package/docs/api/foundation-comms.currentuser.set.md +22 -0
- package/docs/api/foundation-comms.currentuser.unset.md +15 -0
- package/docs/api/foundation-comms.datasource.destroy.md +17 -0
- package/docs/api/foundation-comms.datasource.md +1 -0
- package/docs/api/foundation-comms.defaultconnect._constructor_.md +2 -1
- package/docs/api/foundation-comms.defaultconnect.getmorecolumns.md +22 -0
- package/docs/api/foundation-comms.defaultconnect.md +2 -1
- package/docs/api/foundation-comms.defaultconnectevents.addcommitlistener.md +24 -0
- package/docs/api/foundation-comms.defaultconnectevents.addmetadatalistener.md +24 -0
- package/docs/api/foundation-comms.defaultconnectevents.addstreamlistener.md +25 -0
- package/docs/api/foundation-comms.defaultconnectevents.md +27 -0
- package/docs/api/foundation-comms.defaultconnectevents.oncommitevent.md +25 -0
- package/docs/api/foundation-comms.defaultconnectevents.onmetadataevent.md +26 -0
- package/docs/api/foundation-comms.defaultconnectevents.onstreamcompleteevent.md +24 -0
- package/docs/api/foundation-comms.defaultconnectevents.onstreamevent.md +27 -0
- package/docs/api/foundation-comms.defaultdatasource.destroy.md +17 -0
- package/docs/api/foundation-comms.defaultdatasource.md +1 -0
- package/docs/api/foundation-comms.defaulthttpconnect.getmorecolumns.md +22 -0
- package/docs/api/foundation-comms.defaulthttpconnect.md +1 -0
- package/docs/api/foundation-comms.defaultmessagebuilder._constructor_.md +21 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createchangepasswordmessage.md +24 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createcommitmessage.md +23 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createdatalogoffmessage.md +22 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createdatalogonmessage.md +23 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createforgotpasswordmessage.md +24 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createforgotpasswordtokenmessage.md +25 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createhttpheadersfrommessage.md +23 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createloginmessage.md +22 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createlogoutmessage.md +22 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createmetarequestmessage.md +23 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createmorecolumnsmessage.md +22 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createmorerowsmessage.md +22 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createrefreshtokenmessage.md +15 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createrequestmessage.md +23 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.createresourcesmessage.md +22 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.md +41 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor.addresource.md +23 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor.create.md +16 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor.destroy.md +16 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor.md +31 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor.removeresource.md +22 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor.runallchecks.md +11 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor.status.md +12 -0
- package/docs/api/foundation-comms.defaultnetworkmonitorconfig.md +13 -0
- package/docs/api/foundation-comms.defaultsocket._constructor_.md +24 -0
- package/docs/api/foundation-comms.defaultsocket.connect.md +24 -0
- package/docs/api/foundation-comms.defaultsocket.hasvalidsession.md +13 -0
- package/docs/api/foundation-comms.defaultsocket.isconfigured.md +11 -0
- package/docs/api/foundation-comms.defaultsocket.isconnected.md +11 -0
- package/docs/api/foundation-comms.defaultsocket.isconnectedsubject.md +11 -0
- package/docs/api/foundation-comms.defaultsocket.isconnecting.md +11 -0
- package/docs/api/foundation-comms.defaultsocket.isdisconnected.md +11 -0
- package/docs/api/foundation-comms.defaultsocket.isdisconnectedbyserver.md +11 -0
- package/docs/api/foundation-comms.defaultsocket.isreconnecting.md +11 -0
- package/docs/api/foundation-comms.defaultsocket.md +44 -0
- package/docs/api/foundation-comms.defaultsocket.reset.md +15 -0
- package/docs/api/foundation-comms.defaultsocket.send.md +23 -0
- package/docs/api/foundation-comms.defaultsocket.sendforstream.md +25 -0
- package/docs/api/foundation-comms.defaultsocket.socketmessages.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.closedclean.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.closedcode.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.closedreason.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.hasvalidsession.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isconfigured.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isconnected.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isconnectedchanged.md +15 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isconnectedsubject.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isconnecting.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isdisconnected.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isdisconnectedbyserver.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isreconnecting.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.isreconnectingchanged.md +15 -0
- package/docs/api/foundation-comms.defaultsocketstatus.md +42 -0
- package/docs/api/foundation-comms.defaultsocketstatus.onclose.md +22 -0
- package/docs/api/foundation-comms.defaultsocketstatus.reconnectionlimitreached.md +11 -0
- package/docs/api/foundation-comms.defaultsocketstatus.resetclosedstate.md +15 -0
- package/docs/api/foundation-comms.defaultsocketstatus.serialize.md +15 -0
- package/docs/api/foundation-comms.genesisconnectevents.md +18 -0
- package/docs/api/foundation-comms.getnetworkmonitor.md +30 -0
- package/docs/api/foundation-comms.getsocket.md +30 -0
- package/docs/api/foundation-comms.getsocketstatus.md +30 -0
- package/docs/api/foundation-comms.md +39 -0
- package/docs/api/foundation-comms.messagebuilder.createmorecolumnsmessage.md +30 -0
- package/docs/api/foundation-comms.messagebuilder.md +1 -0
- package/docs/api/foundation-comms.messagehaserrorcode.md +13 -0
- package/docs/api/foundation-comms.messagetype.md +2 -0
- package/docs/api/foundation-comms.metadataevent.md +14 -0
- package/docs/api/foundation-comms.metadataeventdetail.md +18 -0
- package/docs/api/foundation-comms.metadataeventtype.md +12 -0
- package/docs/api/foundation-comms.monitoredresource.md +15 -0
- package/docs/api/foundation-comms.monitoredresourcechecks.md +15 -0
- package/docs/api/foundation-comms.monitoredresourcechecksresult.isconnected.md +11 -0
- package/docs/api/foundation-comms.monitoredresourcechecksresult.lastmessage.md +11 -0
- package/docs/api/foundation-comms.monitoredresourcechecksresult.lastupdated.md +11 -0
- package/docs/api/foundation-comms.monitoredresourcechecksresult.md +23 -0
- package/docs/api/foundation-comms.monitoredresourcechecksresult.timeout.md +11 -0
- package/docs/api/foundation-comms.monitoredresourcedatalogon.md +15 -0
- package/docs/api/foundation-comms.monitoredresourcemetadata.md +15 -0
- package/docs/api/foundation-comms.networklogger.md +12 -0
- package/docs/api/foundation-comms.networkmonitor.addresource.md +23 -0
- package/docs/api/foundation-comms.networkmonitor.create.md +15 -0
- package/docs/api/foundation-comms.networkmonitor.destroy.md +15 -0
- package/docs/api/foundation-comms.networkmonitor.md +34 -0
- package/docs/api/foundation-comms.networkmonitor.removeresource.md +22 -0
- package/docs/api/foundation-comms.networkmonitor.runallchecks.md +23 -0
- package/docs/api/foundation-comms.networkmonitor.status.md +11 -0
- package/docs/api/foundation-comms.networkmonitorconfig.checkinterval.md +13 -0
- package/docs/api/foundation-comms.networkmonitorconfig.checktimeout.md +13 -0
- package/docs/api/foundation-comms.networkmonitorconfig.documentevents.md +13 -0
- package/docs/api/foundation-comms.networkmonitorconfig.eventemitter.md +13 -0
- package/docs/api/foundation-comms.networkmonitorconfig.genesisconnectevents.md +13 -0
- package/docs/api/foundation-comms.networkmonitorconfig.md +27 -0
- package/docs/api/foundation-comms.networkmonitorconfig.resourcechecks.md +13 -0
- package/docs/api/foundation-comms.networkmonitorconfig.resourcedatalogon.md +18 -0
- package/docs/api/foundation-comms.networkmonitorconfig.windowevents.md +13 -0
- package/docs/api/foundation-comms.resourcehealth.md +19 -0
- package/docs/api/foundation-comms.serializedsocketstatus.closedclean.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.closedcode.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.closedreason.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.hasvalidsession.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.isconfigured.md +13 -0
- package/docs/api/foundation-comms.serializedsocketstatus.isconnected.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.isconnecting.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.isdisconnected.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.isdisconnectedbyserver.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.isreconnecting.md +11 -0
- package/docs/api/foundation-comms.serializedsocketstatus.md +30 -0
- package/docs/api/foundation-comms.serializedsocketstatus.reconnectionlimitreached.md +11 -0
- package/docs/api/foundation-comms.socket.md +3 -11
- package/docs/api/foundation-comms.socket.sendforstream.md +2 -1
- package/docs/api/{foundation-comms.socket.isconnectedsubject.md → foundation-comms.socketstatus.isconnectedsubject.md} +2 -2
- package/docs/api/foundation-comms.socketstatus.md +28 -0
- package/docs/api/foundation-comms.socketstatus.onclose.md +22 -0
- package/docs/api/foundation-comms.socketstatus.serialize.md +15 -0
- package/docs/api/foundation-comms.streamcompleteevent.md +14 -0
- package/docs/api/foundation-comms.streamcompleteeventtype.md +12 -0
- package/docs/api/foundation-comms.streamevent.md +14 -0
- package/docs/api/foundation-comms.streameventdetail.md +19 -0
- package/docs/api/foundation-comms.streameventfunctions.md +19 -0
- package/docs/api/foundation-comms.streameventtype.md +12 -0
- package/docs/api/foundation-comms.systemhealthchanged.md +13 -0
- package/docs/api/foundation-comms.systemhealthchangedevent.md +15 -0
- package/docs/api/foundation-comms.systemhealthstatus.md +29 -0
- package/docs/api/foundation-comms.user.md +2 -0
- package/docs/api/foundation-comms.user.set.md +22 -0
- package/docs/api/foundation-comms.user.unset.md +15 -0
- package/docs/api-report.md +520 -16
- package/package.json +13 -11
- package/docs/api/foundation-comms.socket.hasvalidsession.md +0 -11
- package/docs/api/foundation-comms.socket.isconnected.md +0 -11
- package/docs/api/foundation-comms.socket.isreconnecting.md +0 -11
@@ -0,0 +1,445 @@
|
|
1
|
+
var _a;
|
2
|
+
import { __awaiter, __decorate } from "tslib";
|
3
|
+
import { createLogger, LogLevel } from '@genesislcap/foundation-logger';
|
4
|
+
import { formatDateTimeTimestamp, resolveAfter } from '@genesislcap/foundation-utils';
|
5
|
+
import { observable } from '@microsoft/fast-element';
|
6
|
+
import { DI } from '@microsoft/fast-foundation';
|
7
|
+
import Bowser from 'bowser';
|
8
|
+
import { StatusCodes } from 'http-status-codes';
|
9
|
+
import { ConnectEvents } from '../connect/connect.events';
|
10
|
+
import { messageHasErrorCode, MessageType } from '../connect/message';
|
11
|
+
import { SocketStatus } from '../connect/socket.status';
|
12
|
+
import { User } from '../user/user';
|
13
|
+
import { NetworkMonitorConfig } from './config';
|
14
|
+
import { SystemHealthChanged, } from './types';
|
15
|
+
/**
|
16
|
+
* @public
|
17
|
+
*/
|
18
|
+
export const networkLogger = createLogger('network-monitor', { level: LogLevel.Info });
|
19
|
+
/**
|
20
|
+
* @internal
|
21
|
+
*/
|
22
|
+
const firstUpdated = Date.now();
|
23
|
+
/**
|
24
|
+
* @internal
|
25
|
+
*/
|
26
|
+
const browserInformation = ((_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent)
|
27
|
+
? Bowser.parse(window.navigator.userAgent)
|
28
|
+
: undefined;
|
29
|
+
/**
|
30
|
+
* Default NetworkMonitor implementation.
|
31
|
+
* @public
|
32
|
+
*/
|
33
|
+
export class DefaultNetworkMonitor {
|
34
|
+
constructor() {
|
35
|
+
/**
|
36
|
+
* @internal
|
37
|
+
*/
|
38
|
+
this.unsubscribableObservers = [];
|
39
|
+
/**
|
40
|
+
* {@inheritDoc NetworkMonitor.runAllChecks}
|
41
|
+
*/
|
42
|
+
this.runAllChecks = (source, force) => __awaiter(this, void 0, void 0, function* () {
|
43
|
+
/**
|
44
|
+
* Abort if checks are already running and the call is not forced
|
45
|
+
*/
|
46
|
+
if (this.isRunningChecks && !force) {
|
47
|
+
return;
|
48
|
+
}
|
49
|
+
networkLogger.info(`Run health checks, triggered by`, source, `| Active resources`, this.resources.size);
|
50
|
+
this.isRunningChecks = true;
|
51
|
+
/**
|
52
|
+
* Synchronise check interval given this has multiple non-automated triggers
|
53
|
+
*/
|
54
|
+
this.synchroniseCheckInterval();
|
55
|
+
let formattedTimestamp = this.getFormattedTimestamp(this.getNowTimestamp());
|
56
|
+
const isOnline = yield this.isOnlineCheck();
|
57
|
+
if (!isOnline) {
|
58
|
+
networkLogger.warn(`Network disconnected at ${formattedTimestamp}`);
|
59
|
+
const socket = this.normaliseSerializedSocketStatus(this.socketStatus.serialize(), false);
|
60
|
+
const resources = [...this.resources].reduce((output, [_, metadata]) => {
|
61
|
+
const existingEntry = output[metadata.resourceName];
|
62
|
+
if (existingEntry) {
|
63
|
+
existingEntry.sourceRef = [...existingEntry.sourceRef, metadata.message.SOURCE_REF];
|
64
|
+
return output;
|
65
|
+
}
|
66
|
+
return Object.assign(Object.assign({}, output), { [metadata.resourceName]: this.normaliseResourceHealth({
|
67
|
+
name: metadata.resourceName,
|
68
|
+
sourceRef: [metadata.message.SOURCE_REF],
|
69
|
+
isConnected: false,
|
70
|
+
lastUpdated: undefined,
|
71
|
+
}, false) });
|
72
|
+
}, {});
|
73
|
+
this.reportSystemHealth({
|
74
|
+
isAuthenticated: socket.hasValidSession,
|
75
|
+
isOnline: false,
|
76
|
+
resources,
|
77
|
+
resourcesAllConnected: false,
|
78
|
+
socket,
|
79
|
+
});
|
80
|
+
this.isRunningChecks = false;
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
networkLogger.debug(`Network connected at ${formattedTimestamp}`);
|
84
|
+
const socket = this.normaliseSerializedSocketStatus(this.socketStatus.serialize());
|
85
|
+
if (socket.isConnecting) {
|
86
|
+
networkLogger.debug(`Aborting remaining health checks as socket is still connecting`);
|
87
|
+
this.isRunningChecks = false;
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
let resourcesAllConnected = true;
|
91
|
+
const allChecks = [];
|
92
|
+
this.resources.forEach((meta, resource) => {
|
93
|
+
const { resourceName: name, message, functions } = meta;
|
94
|
+
const { resourceChecks = this.config.resourceChecks, resourceDataLogon = this.config.resourceDataLogon, } = functions;
|
95
|
+
const { SOURCE_REF: sourceRef } = message;
|
96
|
+
let isConnected = false;
|
97
|
+
let lastUpdated;
|
98
|
+
let lastMessage;
|
99
|
+
let lastError;
|
100
|
+
let timeout;
|
101
|
+
let attemptDataLogon;
|
102
|
+
const checkEnvelope = () => __awaiter(this, void 0, void 0, function* () {
|
103
|
+
var _a;
|
104
|
+
try {
|
105
|
+
networkLogger.debug(`Running health check against ${name}`);
|
106
|
+
const result = yield Promise.race([
|
107
|
+
resourceChecks(sourceRef, resource),
|
108
|
+
resolveAfter(this.config.checkTimeout, () => ({
|
109
|
+
isConnected: false,
|
110
|
+
lastUpdated: this.getNowTimestamp(),
|
111
|
+
timeout: true,
|
112
|
+
})),
|
113
|
+
]);
|
114
|
+
isConnected = result.isConnected;
|
115
|
+
lastUpdated = result.lastUpdated;
|
116
|
+
lastMessage = result.lastMessage;
|
117
|
+
timeout = result.timeout;
|
118
|
+
attemptDataLogon =
|
119
|
+
timeout ||
|
120
|
+
(lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.MESSAGE_TYPE) === MessageType.MSG_NACK ||
|
121
|
+
messageHasErrorCode(lastMessage, StatusCodes.NOT_FOUND);
|
122
|
+
}
|
123
|
+
catch (e) {
|
124
|
+
isConnected = false;
|
125
|
+
lastUpdated = this.getNowTimestamp();
|
126
|
+
lastError = e;
|
127
|
+
lastMessage = (_a = e === null || e === void 0 ? void 0 : e.receivedMessage) !== null && _a !== void 0 ? _a : e;
|
128
|
+
attemptDataLogon =
|
129
|
+
(lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.MESSAGE_TYPE) === MessageType.MSG_NACK ||
|
130
|
+
messageHasErrorCode(lastMessage, StatusCodes.NOT_FOUND);
|
131
|
+
}
|
132
|
+
formattedTimestamp = this.getFormattedTimestamp(lastUpdated !== null && lastUpdated !== void 0 ? lastUpdated : this.getNowTimestamp());
|
133
|
+
if (isConnected) {
|
134
|
+
networkLogger.debug(`${name} is healthy at ${formattedTimestamp}`);
|
135
|
+
}
|
136
|
+
else {
|
137
|
+
networkLogger.warn(`${name} is not healthy at ${formattedTimestamp}`);
|
138
|
+
}
|
139
|
+
if (lastError) {
|
140
|
+
networkLogger.error(`${name} errored at ${formattedTimestamp}`, lastError);
|
141
|
+
}
|
142
|
+
if (attemptDataLogon) {
|
143
|
+
networkLogger.error(`${name} timed out at ${formattedTimestamp}. Re-attempting data logon.`);
|
144
|
+
resourceDataLogon(meta);
|
145
|
+
}
|
146
|
+
/**
|
147
|
+
* Apply the last resource's isConnected while `resourcesAllConnected` remains true.
|
148
|
+
*/
|
149
|
+
if (resourcesAllConnected) {
|
150
|
+
resourcesAllConnected = isConnected;
|
151
|
+
}
|
152
|
+
/**
|
153
|
+
* Return the resource health
|
154
|
+
*/
|
155
|
+
return {
|
156
|
+
name,
|
157
|
+
sourceRef: [sourceRef],
|
158
|
+
isConnected,
|
159
|
+
lastUpdated,
|
160
|
+
lastError,
|
161
|
+
};
|
162
|
+
});
|
163
|
+
allChecks.push(checkEnvelope());
|
164
|
+
});
|
165
|
+
const results = yield Promise.allSettled(allChecks);
|
166
|
+
const resources = results.reduce((prev, curr) => {
|
167
|
+
if (curr.status === 'fulfilled') {
|
168
|
+
const existingEntry = prev[curr.value.name];
|
169
|
+
if (existingEntry) {
|
170
|
+
existingEntry.sourceRef = [...existingEntry.sourceRef, ...curr.value.sourceRef];
|
171
|
+
return prev;
|
172
|
+
}
|
173
|
+
return Object.assign(Object.assign({}, prev), { [curr.value.name]: this.normaliseResourceHealth(curr.value) });
|
174
|
+
}
|
175
|
+
networkLogger.warn(`Unexpected promise rejection occurred. Please check any custom resourceChecks return MonitoredResourceChecksResult.`);
|
176
|
+
return prev;
|
177
|
+
}, {});
|
178
|
+
this.reportSystemHealth({
|
179
|
+
isAuthenticated: socket.hasValidSession,
|
180
|
+
isOnline,
|
181
|
+
resources,
|
182
|
+
resourcesAllConnected,
|
183
|
+
socket,
|
184
|
+
});
|
185
|
+
this.isRunningChecks = false;
|
186
|
+
});
|
187
|
+
}
|
188
|
+
/**
|
189
|
+
* {@inheritDoc NetworkMonitor.create}
|
190
|
+
*/
|
191
|
+
create() {
|
192
|
+
if (this.resources) {
|
193
|
+
networkLogger.warn(`NetworkMonitor already created. If this is intentional, please call NetworkMonitor.destroy first.`);
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
this.addListeners();
|
197
|
+
this.resources = new Map();
|
198
|
+
this.synchroniseCheckInterval();
|
199
|
+
/**
|
200
|
+
* Report system health on creation to populate initial status data.
|
201
|
+
*/
|
202
|
+
this.runAllChecks('network monitor create');
|
203
|
+
}
|
204
|
+
/**
|
205
|
+
* {@inheritDoc NetworkMonitor.destroy}
|
206
|
+
*/
|
207
|
+
destroy() {
|
208
|
+
this.removeListeners();
|
209
|
+
clearInterval(this.internalId);
|
210
|
+
this.resources.clear();
|
211
|
+
this.resources = undefined;
|
212
|
+
this.status = undefined;
|
213
|
+
}
|
214
|
+
/**
|
215
|
+
* @internal
|
216
|
+
*/
|
217
|
+
isOnlineCheck() {
|
218
|
+
return Promise.resolve(navigator.onLine);
|
219
|
+
}
|
220
|
+
/**
|
221
|
+
* {@inheritDoc NetworkMonitor.addResource}
|
222
|
+
*/
|
223
|
+
addResource(resource, metadata) {
|
224
|
+
if (!this.resources) {
|
225
|
+
this.create();
|
226
|
+
}
|
227
|
+
this.resources.set(resource, metadata);
|
228
|
+
}
|
229
|
+
/**
|
230
|
+
* {@inheritDoc NetworkMonitor.removeResource}
|
231
|
+
*/
|
232
|
+
removeResource(resource) {
|
233
|
+
this.resources.delete(resource);
|
234
|
+
}
|
235
|
+
/**
|
236
|
+
* @internal
|
237
|
+
*/
|
238
|
+
addListeners() {
|
239
|
+
var _a, _b;
|
240
|
+
(_a = this.config.windowEvents) === null || _a === void 0 ? void 0 : _a.forEach((eventName) => window.addEventListener(eventName, this.runAllChecks));
|
241
|
+
(_b = this.config.documentEvents) === null || _b === void 0 ? void 0 : _b.forEach((eventName) => document.addEventListener(eventName, this.runAllChecks));
|
242
|
+
if (this.config.genesisConnectEvents.includes('stream')) {
|
243
|
+
this.unsubscribableObservers.push(this.connectEvents.addStreamListener(({ detail }) => {
|
244
|
+
const { functions, message, resourceName, stream } = detail;
|
245
|
+
this.addResource(stream, {
|
246
|
+
functions,
|
247
|
+
message,
|
248
|
+
resourceName,
|
249
|
+
});
|
250
|
+
}, ({ detail }) => {
|
251
|
+
this.removeResource(detail);
|
252
|
+
}));
|
253
|
+
}
|
254
|
+
if (this.config.genesisConnectEvents.includes('commit')) {
|
255
|
+
this.unsubscribableObservers.push(this.connectEvents.addCommitListener(this.runAllChecks));
|
256
|
+
}
|
257
|
+
this.unsubscribableObservers.push(this.connectEvents.addMetadataListener(({ detail }) => {
|
258
|
+
const { resourceName, error } = detail;
|
259
|
+
if (!!error) {
|
260
|
+
/**
|
261
|
+
* Meta/init failure edge case, data server is already down when the app loads and `connect.getMetadata` fails.
|
262
|
+
* In such cases the stream / resource is never actually created, so the `onStreamEvent` is never fired.
|
263
|
+
* Meta/init failures are only reported in console logs, however, might be a good idea to show those here.
|
264
|
+
*/
|
265
|
+
networkLogger.error(`${resourceName} had an unrecoverable error at ${this.getFormattedTimestamp(this.getNowTimestamp())}`, `Please check the resource is running.`, error);
|
266
|
+
return;
|
267
|
+
}
|
268
|
+
}));
|
269
|
+
}
|
270
|
+
/**
|
271
|
+
* @internal
|
272
|
+
*/
|
273
|
+
removeListeners() {
|
274
|
+
var _a, _b;
|
275
|
+
(_a = this.config.windowEvents) === null || _a === void 0 ? void 0 : _a.forEach((eventName) => window.removeEventListener(eventName, this.runAllChecks));
|
276
|
+
(_b = this.config.documentEvents) === null || _b === void 0 ? void 0 : _b.forEach((eventName) => document.removeEventListener(eventName, this.runAllChecks));
|
277
|
+
this.unsubscribableObservers.forEach((unsubscribe) => unsubscribe());
|
278
|
+
this.unsubscribableObservers.length = 0;
|
279
|
+
}
|
280
|
+
/**
|
281
|
+
* @internal
|
282
|
+
*/
|
283
|
+
reportSystemHealth(detail) {
|
284
|
+
var _a;
|
285
|
+
const eventEmitter = (_a = this.config.eventEmitter) !== null && _a !== void 0 ? _a : document;
|
286
|
+
this.status = this.normaliseEventDetail(detail);
|
287
|
+
const loggerFn = this.status.isHealthy ? networkLogger.debug : networkLogger.warn;
|
288
|
+
loggerFn(`Emitting 'system-health-changed' event`, this.status);
|
289
|
+
eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.dispatchEvent(new CustomEvent(SystemHealthChanged, {
|
290
|
+
detail: this.status,
|
291
|
+
bubbles: eventEmitter !== document,
|
292
|
+
composed: true,
|
293
|
+
}));
|
294
|
+
/**
|
295
|
+
* Kill the network monitor if the reconnection limit has been reached
|
296
|
+
*/
|
297
|
+
if (this.status.socket.reconnectionLimitReached) {
|
298
|
+
networkLogger.debug('Network monitoring no longer required. Please check your network and reload your application.');
|
299
|
+
this.destroy();
|
300
|
+
}
|
301
|
+
}
|
302
|
+
/**
|
303
|
+
* @internal
|
304
|
+
*/
|
305
|
+
reportStabilityToGenesis(detail) {
|
306
|
+
return __awaiter(this, void 0, void 0, function* () {
|
307
|
+
networkLogger.debug('User requested report stability to Genesis.');
|
308
|
+
networkLogger.info('Please attach this data to your Genesis Support request: \n', JSON.stringify(detail, null, 2));
|
309
|
+
return true;
|
310
|
+
});
|
311
|
+
}
|
312
|
+
/**
|
313
|
+
* @remarks
|
314
|
+
* Deal with false positives.
|
315
|
+
*
|
316
|
+
* @privateRemarks
|
317
|
+
* There's an argument here for and against normalising ResourceHealth. I think it's more useful to consumers like
|
318
|
+
* visual overlays if there is no conflicting information. If we're offline and using the cache, then that should be
|
319
|
+
* reflected here.
|
320
|
+
*
|
321
|
+
* @internal
|
322
|
+
*/
|
323
|
+
normaliseResourceHealth(health, isOnline = true) {
|
324
|
+
var _a;
|
325
|
+
const isConnected = isOnline ? health.isConnected : false;
|
326
|
+
const lastUpdated = (_a = health.lastUpdated) !== null && _a !== void 0 ? _a : this.getNowTimestamp();
|
327
|
+
return Object.assign(Object.assign({}, health), { isConnected,
|
328
|
+
lastUpdated });
|
329
|
+
}
|
330
|
+
/**
|
331
|
+
* @remarks
|
332
|
+
* Deal with false positives.
|
333
|
+
*
|
334
|
+
* @privateRemarks
|
335
|
+
* There's an argument here for and against a normalised SerializedSocketStatus. I think it's more useful to consumers
|
336
|
+
* like visual overlays if there is no conflicting information. If we're offline and using the cache, then that
|
337
|
+
* should be reflected here.
|
338
|
+
*
|
339
|
+
* @internal
|
340
|
+
*/
|
341
|
+
normaliseSerializedSocketStatus(socketStatus, isOnline = true) {
|
342
|
+
const isConnected = isOnline ? socketStatus.isConnected : false;
|
343
|
+
const isDisconnected = !isConnected;
|
344
|
+
/**
|
345
|
+
* I think hasValidSession might be best left as is given there are transient network issues. If we toggle it to
|
346
|
+
* false, consumers may try to move the app to the login screen.
|
347
|
+
*
|
348
|
+
* const hasValidSession = isOnline ? socketStatus.hasValidSession : false;
|
349
|
+
*/
|
350
|
+
return Object.assign(Object.assign({}, socketStatus), { isConnected,
|
351
|
+
isDisconnected });
|
352
|
+
}
|
353
|
+
/**
|
354
|
+
* @internal
|
355
|
+
*/
|
356
|
+
normaliseEventDetail(detail) {
|
357
|
+
var _a, _b, _c, _d;
|
358
|
+
const isHealthy = !!(((_a = detail.socket) === null || _a === void 0 ? void 0 : _a.isConfigured)
|
359
|
+
? detail.isOnline && ((_b = detail.socket) === null || _b === void 0 ? void 0 : _b.isConnected) && detail.resourcesAllConnected
|
360
|
+
: detail.isOnline);
|
361
|
+
const lastUpdated = (_c = detail.lastUpdated) !== null && _c !== void 0 ? _c : this.getNowTimestamp();
|
362
|
+
const nextUpdate = (_d = detail.nextUpdate) !== null && _d !== void 0 ? _d : this.getNextTimestamp();
|
363
|
+
const username = detail.isAuthenticated && this.user ? this.user.username : undefined;
|
364
|
+
const normalisedDetail = Object.assign(Object.assign({}, detail), { browserInformation,
|
365
|
+
username,
|
366
|
+
isHealthy,
|
367
|
+
lastUpdated,
|
368
|
+
nextUpdate,
|
369
|
+
firstUpdated, runAllChecks: () => {
|
370
|
+
networkLogger.debug('User activated run checks command starting.');
|
371
|
+
this.runAllChecks('user requested');
|
372
|
+
}, reportStabilityToGenesis: () => {
|
373
|
+
return this.reportStabilityToGenesis(normalisedDetail);
|
374
|
+
} });
|
375
|
+
return normalisedDetail;
|
376
|
+
}
|
377
|
+
/**
|
378
|
+
* @internal
|
379
|
+
*/
|
380
|
+
getFormattedTimestamp(milliseconds) {
|
381
|
+
return formatDateTimeTimestamp(milliseconds);
|
382
|
+
}
|
383
|
+
/**
|
384
|
+
* @internal
|
385
|
+
*/
|
386
|
+
getNowTimestamp() {
|
387
|
+
return Date.now();
|
388
|
+
}
|
389
|
+
/**
|
390
|
+
* @internal
|
391
|
+
*/
|
392
|
+
getNextTimestamp() {
|
393
|
+
const next = new Date(Date.now() + this.config.checkInterval);
|
394
|
+
return next.getTime();
|
395
|
+
}
|
396
|
+
/**
|
397
|
+
* @internal
|
398
|
+
*/
|
399
|
+
synchroniseCheckInterval() {
|
400
|
+
clearInterval(this.internalId);
|
401
|
+
this.internalId = setInterval(() => this.runAllChecks('check interval'), this.config.checkInterval);
|
402
|
+
}
|
403
|
+
}
|
404
|
+
__decorate([
|
405
|
+
NetworkMonitorConfig
|
406
|
+
], DefaultNetworkMonitor.prototype, "config", void 0);
|
407
|
+
__decorate([
|
408
|
+
SocketStatus
|
409
|
+
], DefaultNetworkMonitor.prototype, "socketStatus", void 0);
|
410
|
+
__decorate([
|
411
|
+
ConnectEvents
|
412
|
+
], DefaultNetworkMonitor.prototype, "connectEvents", void 0);
|
413
|
+
__decorate([
|
414
|
+
User
|
415
|
+
], DefaultNetworkMonitor.prototype, "user", void 0);
|
416
|
+
__decorate([
|
417
|
+
observable
|
418
|
+
], DefaultNetworkMonitor.prototype, "status", void 0);
|
419
|
+
/**
|
420
|
+
* NetworkMonitor DI key.
|
421
|
+
*
|
422
|
+
* @privateRemarks
|
423
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
424
|
+
*
|
425
|
+
* @internal
|
426
|
+
*/
|
427
|
+
export const NetworkMonitor = DI.createInterface((x) => x.singleton(DefaultNetworkMonitor));
|
428
|
+
/**
|
429
|
+
* Gets NetworkMonitor from the DI container.
|
430
|
+
*
|
431
|
+
* @remarks
|
432
|
+
* A utility method for host applications that are not using decorators or the DI container.
|
433
|
+
*
|
434
|
+
* @example
|
435
|
+
* ```ts
|
436
|
+
* import { getNetworkMonitor } from '@genesislcap/foundation-comms';
|
437
|
+
* ...
|
438
|
+
* private monitor = getNetworkMonitor();
|
439
|
+
* ```
|
440
|
+
*
|
441
|
+
* @public
|
442
|
+
*/
|
443
|
+
export function getNetworkMonitor() {
|
444
|
+
return DI.getOrCreateDOMContainer().get(NetworkMonitor);
|
445
|
+
}
|
@@ -50,6 +50,9 @@ export class ConnectMock {
|
|
50
50
|
getMoreRows(sourceRef) {
|
51
51
|
return Promise.resolve(this.nextMessage);
|
52
52
|
}
|
53
|
+
getMoreColumns(sourceRef) {
|
54
|
+
return Promise.resolve(this.nextMessage);
|
55
|
+
}
|
53
56
|
dataLogoff(sourceRef) {
|
54
57
|
return Promise.resolve(this.nextMessage);
|
55
58
|
}
|
@@ -15,7 +15,7 @@ export class SocketMock {
|
|
15
15
|
send(message) {
|
16
16
|
return Promise.resolve(this.nextMessage);
|
17
17
|
}
|
18
|
-
sendForStream(message, onMessage, onError) {
|
18
|
+
sendForStream(message, onMessage, onError, onComplete) {
|
19
19
|
return from(Promise.resolve(this.nextMessage));
|
20
20
|
}
|
21
21
|
socketMessages() {
|
package/dist/esm/user/user.js
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
import { __decorate } from "tslib";
|
2
2
|
import { observable } from '@microsoft/fast-element';
|
3
|
+
import { DI } from '@microsoft/fast-foundation';
|
3
4
|
/**
|
4
5
|
* Represents the current user (i.e. the user that is currently logged in).
|
5
6
|
* @public
|
6
7
|
*/
|
7
8
|
export class CurrentUser {
|
8
9
|
constructor(options) {
|
9
|
-
|
10
|
+
this.set(options);
|
11
|
+
}
|
12
|
+
set(options) {
|
13
|
+
if (!options) {
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
this.permissions = options.permissions;
|
17
|
+
this.profiles = options.profiles;
|
18
|
+
this.username = options.username;
|
19
|
+
}
|
20
|
+
unset() {
|
21
|
+
this.permissions = undefined;
|
22
|
+
this.profiles = undefined;
|
23
|
+
this.username = undefined;
|
10
24
|
}
|
11
25
|
hasAdminProfile() {
|
12
26
|
return this.hasProfile('ADMIN');
|
@@ -43,3 +57,10 @@ __decorate([
|
|
43
57
|
__decorate([
|
44
58
|
observable
|
45
59
|
], CurrentUser.prototype, "username", void 0);
|
60
|
+
/**
|
61
|
+
* User DI key.
|
62
|
+
* @privateRemarks
|
63
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
64
|
+
* @internal
|
65
|
+
*/
|
66
|
+
export const User = DI.createInterface((x) => x.singleton(CurrentUser));
|