@genesislcap/foundation-comms 14.176.1-alpha-6ef4895.0 → 14.177.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 +4 -4
- package/dist/dts/auth/auth.d.ts.map +1 -1
- package/dist/dts/auth/loginDTOMapper.d.ts +2 -0
- package/dist/dts/auth/loginDTOMapper.d.ts.map +1 -0
- package/dist/dts/connect/connect.d.ts +3 -0
- package/dist/dts/connect/connect.d.ts.map +1 -1
- package/dist/dts/connect/connect.events.d.ts +8 -3
- package/dist/dts/connect/connect.events.d.ts.map +1 -1
- package/dist/dts/connect/message.d.ts +42 -0
- package/dist/dts/connect/message.d.ts.map +1 -1
- package/dist/dts/connect/socket.d.ts +27 -4
- package/dist/dts/connect/socket.d.ts.map +1 -1
- package/dist/dts/connect/socket.status.d.ts +5 -1
- package/dist/dts/connect/socket.status.d.ts.map +1 -1
- package/dist/dts/networkMonitor/config.d.ts +13 -0
- package/dist/dts/networkMonitor/config.d.ts.map +1 -1
- package/dist/dts/networkMonitor/service.d.ts +11 -1
- package/dist/dts/networkMonitor/service.d.ts.map +1 -1
- package/dist/dts/storage/kv/kv.service.d.ts +19 -3
- package/dist/dts/storage/kv/kv.service.d.ts.map +1 -1
- package/dist/dts/testing/mocks/auth/auth.d.ts +2 -1
- package/dist/dts/testing/mocks/auth/auth.d.ts.map +1 -1
- package/dist/dts/user/user.d.ts +14 -43
- package/dist/dts/user/user.d.ts.map +1 -1
- package/dist/esm/auth/auth.js +19 -27
- package/dist/esm/auth/loginDTOMapper.js +49 -0
- package/dist/esm/connect/connect.events.js +5 -2
- package/dist/esm/connect/connect.js +6 -2
- package/dist/esm/connect/message.js +9 -0
- package/dist/esm/connect/socket.js +30 -22
- package/dist/esm/connect/socket.status.js +8 -4
- package/dist/esm/networkMonitor/config.js +2 -0
- package/dist/esm/networkMonitor/service.js +109 -29
- package/dist/esm/storage/kv/kv.service.js +26 -8
- package/dist/esm/user/user.js +11 -54
- package/dist/foundation-comms.api.json +559 -603
- package/dist/foundation-comms.d.ts +148 -55
- package/docs/api/foundation-comms.connecteventsemitter.md +1 -1
- package/docs/api/foundation-comms.connecteventsemitter.onstreamcompleteevent.md +2 -1
- package/docs/api/foundation-comms.currentuser.md +8 -25
- package/docs/api/foundation-comms.defaultauth._constructor_.md +2 -1
- package/docs/api/foundation-comms.defaultauth.md +2 -2
- package/docs/api/foundation-comms.defaultconnect.setvalidsession.md +5 -0
- package/docs/api/foundation-comms.defaultconnectevents.md +1 -1
- package/docs/api/foundation-comms.defaultconnectevents.onstreamcompleteevent.md +2 -1
- package/docs/api/foundation-comms.defaultmessagebuilder.createheartbeatpingmessage.md +22 -0
- package/docs/api/foundation-comms.defaultmessagebuilder.md +1 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor._constructor_.md +13 -0
- package/docs/api/foundation-comms.defaultnetworkmonitor.md +6 -0
- package/docs/api/foundation-comms.defaultsocket._constructor_.md +3 -1
- package/docs/api/foundation-comms.defaultsocket.md +2 -1
- package/docs/api/foundation-comms.defaultsocket.user.md +13 -0
- package/docs/api/foundation-comms.defaultsocketstatus.hasvalidsession.md +1 -1
- package/docs/api/foundation-comms.defaultsocketstatus.md +2 -1
- package/docs/api/foundation-comms.defaultsocketstatus.user.md +11 -0
- package/docs/api/foundation-comms.getkvstorage.md +30 -0
- package/docs/api/foundation-comms.md +4 -0
- package/docs/api/foundation-comms.messagebuilder.createheartbeatpingmessage.md +22 -0
- package/docs/api/foundation-comms.messagebuilder.md +1 -0
- package/docs/api/foundation-comms.networkmonitorconfig.ignoredgenesisresources.md +13 -0
- package/docs/api/foundation-comms.networkmonitorconfig.loglevel.md +13 -0
- package/docs/api/foundation-comms.networkmonitorconfig.md +3 -0
- package/docs/api/foundation-comms.networkmonitorconfig.startdelay.md +13 -0
- package/docs/api/foundation-comms.pingmessage.md +17 -0
- package/docs/api/foundation-comms.pongmessage.md +20 -0
- package/docs/api/foundation-comms.serializedsocketstatus.hasvalidsession.md +5 -0
- package/docs/api/foundation-comms.socketconnectoptions.md +4 -1
- package/docs/api/foundation-comms.streamcompleteevent.md +2 -2
- package/docs/api/foundation-comms.streamcompleteeventdetail.md +14 -0
- package/docs/api/foundation-comms.user.md +7 -12
- package/docs/api-report.md +71 -54
- package/package.json +13 -11
- package/docs/api/foundation-comms.currentuser._constructor_.md +0 -20
- package/docs/api/foundation-comms.currentuser.hasadminprofile.md +0 -15
- package/docs/api/foundation-comms.currentuser.haspermission.md +0 -22
- package/docs/api/foundation-comms.currentuser.hasprofile.md +0 -22
- package/docs/api/foundation-comms.currentuser.permissions.md +0 -11
- package/docs/api/foundation-comms.currentuser.profiles.md +0 -11
- package/docs/api/foundation-comms.currentuser.set.md +0 -22
- package/docs/api/foundation-comms.currentuser.unset.md +0 -15
- package/docs/api/foundation-comms.currentuser.username.md +0 -11
- package/docs/api/foundation-comms.user.hasadminprofile.md +0 -15
- package/docs/api/foundation-comms.user.haspermission.md +0 -22
- package/docs/api/foundation-comms.user.hasprofile.md +0 -22
- package/docs/api/foundation-comms.user.set.md +0 -22
- package/docs/api/foundation-comms.user.unset.md +0 -15
package/dist/esm/auth/auth.js
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
import { __awaiter, __decorate, __param } from "tslib";
|
2
|
-
import {
|
2
|
+
import { User } from '@genesislcap/foundation-user';
|
3
|
+
import { observable } from '@microsoft/fast-element';
|
3
4
|
import { DI } from '@microsoft/fast-foundation';
|
4
5
|
import { BehaviorSubject } from 'rxjs';
|
5
6
|
import { Connect } from '../connect';
|
6
7
|
import { EventMessageType, MessageBuilder, MessageCode, MessageType, } from '../connect/message';
|
7
8
|
import { CredentialManager } from '../credentialManager';
|
8
9
|
import { Session } from '../session';
|
9
|
-
import { User } from '../user';
|
10
10
|
import { logger } from '../utils';
|
11
11
|
import { AuthError } from './auth.types';
|
12
|
+
import { loginDTOMapper } from './loginDTOMapper';
|
12
13
|
/**
|
13
14
|
* The default implementation for the Auth interface.
|
14
15
|
* @public
|
15
16
|
*/
|
16
17
|
let DefaultAuth = class DefaultAuth {
|
17
|
-
loggedUserResultChanged(
|
18
|
+
loggedUserResultChanged() {
|
18
19
|
var _a;
|
19
20
|
(_a = this.isLoggedInSubject) === null || _a === void 0 ? void 0 : _a.next(this.isLoggedIn);
|
20
21
|
}
|
@@ -22,17 +23,20 @@ let DefaultAuth = class DefaultAuth {
|
|
22
23
|
return this.isLoggedInSubject.asObservable();
|
23
24
|
}
|
24
25
|
get isLoggedIn() {
|
25
|
-
return this.
|
26
|
-
? !!(this.loggedUserResult.authToken && this.loggedUserResult.sessionId)
|
27
|
-
: false;
|
26
|
+
return this.currentUser.isAuthenticated;
|
28
27
|
}
|
29
|
-
constructor(session, connect, messageBuilder, credentialManager) {
|
28
|
+
constructor(session, connect, messageBuilder, credentialManager, currentUser) {
|
30
29
|
this.session = session;
|
31
30
|
this.connect = connect;
|
32
31
|
this.messageBuilder = messageBuilder;
|
33
32
|
this.credentialManager = credentialManager;
|
33
|
+
this.currentUser = currentUser;
|
34
34
|
this.isWorking = false;
|
35
|
-
this.isLoggedInSubject = new BehaviorSubject(
|
35
|
+
this.isLoggedInSubject = new BehaviorSubject(this.isLoggedIn);
|
36
|
+
this.currentUser.addAuthenticationChangeListener((event) => {
|
37
|
+
var _a;
|
38
|
+
(_a = this.isLoggedInSubject) === null || _a === void 0 ? void 0 : _a.next(event.detail);
|
39
|
+
});
|
36
40
|
}
|
37
41
|
login(credentials) {
|
38
42
|
var _a;
|
@@ -52,6 +56,7 @@ let DefaultAuth = class DefaultAuth {
|
|
52
56
|
permissions: authResult.PERMISSION,
|
53
57
|
sessionId: authResult.SESSION_ID,
|
54
58
|
});
|
59
|
+
this.currentUser.set(loginDTOMapper(authResult));
|
55
60
|
/**
|
56
61
|
* Use the credentialManager as a proxy instead?
|
57
62
|
*/
|
@@ -66,6 +71,7 @@ let DefaultAuth = class DefaultAuth {
|
|
66
71
|
else {
|
67
72
|
// this.credentialManager.removeAll(); // < let caller manage for now, discuss later
|
68
73
|
this.removeAuthResults();
|
74
|
+
this.currentUser.unset();
|
69
75
|
throw err;
|
70
76
|
}
|
71
77
|
}
|
@@ -86,7 +92,6 @@ let DefaultAuth = class DefaultAuth {
|
|
86
92
|
const logoutMessage = this.messageBuilder.createLogoutMessage(this.loggedUserResult);
|
87
93
|
// TODO: Improve auth scenario where server timeout has the same message return as logout
|
88
94
|
this.session.deleteUserFromSessionStorage();
|
89
|
-
this.connect.setValidSession(false);
|
90
95
|
const { CODE, DETAILS, ERROR, MESSAGE_TYPE, OIDC_LOGOUT_URL } = yield this.connect.send(logoutMessage);
|
91
96
|
const error = (_a = DETAILS === null || DETAILS === void 0 ? void 0 : DETAILS.ERROR) !== null && _a !== void 0 ? _a : ERROR;
|
92
97
|
/**
|
@@ -120,6 +125,7 @@ let DefaultAuth = class DefaultAuth {
|
|
120
125
|
}
|
121
126
|
finally {
|
122
127
|
this.removeAuthResults();
|
128
|
+
this.currentUser.unset();
|
123
129
|
this.isWorking = false;
|
124
130
|
}
|
125
131
|
return logoutResult;
|
@@ -134,13 +140,13 @@ let DefaultAuth = class DefaultAuth {
|
|
134
140
|
const refreshTokenResult = yield this.connect.send(refreshTokenMessage);
|
135
141
|
if ((refreshTokenResult === null || refreshTokenResult === void 0 ? void 0 : refreshTokenResult.MESSAGE_TYPE) === EventMessageType.EVENT_LOGIN_AUTH_ACK) {
|
136
142
|
this.session.setAuthResult(refreshTokenResult);
|
137
|
-
this.
|
143
|
+
this.currentUser.set(loginDTOMapper(refreshTokenResult));
|
138
144
|
this.applyAuthResults(this.getLoggedUserFromMessage(refreshTokenResult));
|
139
145
|
return true;
|
140
146
|
}
|
141
147
|
}
|
142
148
|
this.session.deleteUserFromSessionStorage();
|
143
|
-
this.
|
149
|
+
this.currentUser.unset();
|
144
150
|
return false;
|
145
151
|
});
|
146
152
|
}
|
@@ -198,41 +204,27 @@ let DefaultAuth = class DefaultAuth {
|
|
198
204
|
permissions: result.permissions,
|
199
205
|
sessionId: result.sessionId,
|
200
206
|
};
|
201
|
-
this.currentUser = DI.getOrCreateDOMContainer().get(User);
|
202
|
-
this.currentUser.set({
|
203
|
-
permissions: result.permissions,
|
204
|
-
profiles: result.profiles,
|
205
|
-
username: result.username,
|
206
|
-
});
|
207
207
|
}
|
208
208
|
/**
|
209
209
|
* Removes the authentication results from the Auth instance.
|
210
210
|
* @internal
|
211
211
|
*/
|
212
212
|
removeAuthResults() {
|
213
|
-
var _a;
|
214
213
|
this.loggedUserResult = null;
|
215
|
-
(_a = this.currentUser) === null || _a === void 0 ? void 0 : _a.unset();
|
216
|
-
this.currentUser = null;
|
217
214
|
}
|
218
215
|
};
|
219
216
|
__decorate([
|
220
217
|
observable
|
221
218
|
], DefaultAuth.prototype, "isWorking", void 0);
|
222
|
-
__decorate([
|
223
|
-
observable
|
224
|
-
], DefaultAuth.prototype, "currentUser", void 0);
|
225
219
|
__decorate([
|
226
220
|
observable
|
227
221
|
], DefaultAuth.prototype, "loggedUserResult", void 0);
|
228
|
-
__decorate([
|
229
|
-
volatile
|
230
|
-
], DefaultAuth.prototype, "isLoggedIn", null);
|
231
222
|
DefaultAuth = __decorate([
|
232
223
|
__param(0, Session),
|
233
224
|
__param(1, Connect),
|
234
225
|
__param(2, MessageBuilder),
|
235
|
-
__param(3, CredentialManager)
|
226
|
+
__param(3, CredentialManager),
|
227
|
+
__param(4, User)
|
236
228
|
], DefaultAuth);
|
237
229
|
export { DefaultAuth };
|
238
230
|
/**
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { logger } from '../utils';
|
2
|
+
/**
|
3
|
+
* This mapper file is temporary and will be removed in v15 as this is owned by foundation-auth.
|
4
|
+
* It is loose on typing due to this.
|
5
|
+
*/
|
6
|
+
const fromSystemDTO = (system) => (system ? { date: system.DATE } : null);
|
7
|
+
const fromProductDTO = (products) => products
|
8
|
+
? products.map((p) => ({
|
9
|
+
name: p.NAME,
|
10
|
+
version: p.VERSION,
|
11
|
+
}))
|
12
|
+
: [];
|
13
|
+
const fromDTOStringArray = (arr) => Array.isArray(arr) ? arr.map((v) => (v !== null && v !== void 0 ? v : '').toLowerCase()) : [];
|
14
|
+
export const loginDTOMapper = (dto) => {
|
15
|
+
try {
|
16
|
+
if ((dto === null || dto === void 0 ? void 0 : dto.MESSAGE_TYPE) === 'EVENT_LOGIN_AUTH_ACK') {
|
17
|
+
const { DETAILS } = dto;
|
18
|
+
const ack = {
|
19
|
+
messageType: dto.MESSAGE_TYPE,
|
20
|
+
sourceRef: dto.SOURCE_REF,
|
21
|
+
userName: dto.USER_NAME,
|
22
|
+
updateQueue: dto.UPDATE_QUEUE,
|
23
|
+
zeroMqProxyModeEnabled: dto.ZERO_MQ_PROXY_MODE_ENABLED,
|
24
|
+
zeroMqProxyInboundPort: dto.ZERO_MQ_PROXY_INBOUND_PORT,
|
25
|
+
zeroMqProxyOutboundPort: dto.ZERO_MQ_PROXY_OUTBOUND_PORT,
|
26
|
+
userKVs: dto.USER,
|
27
|
+
details: DETAILS
|
28
|
+
? {
|
29
|
+
system: fromSystemDTO(DETAILS.SYSTEM),
|
30
|
+
heartbeatIntervalSecs: DETAILS.HEARTBEAT_INTERVAL_SECS,
|
31
|
+
failedLoginAttempts: DETAILS.FAILED_LOGIN_ATTEMPTS,
|
32
|
+
rejectedLoginAttempts: DETAILS.REJECTED_LOGIN_ATTEMPTS,
|
33
|
+
lastLoginDatetime: DETAILS.LAST_LOGIN_DATETIME,
|
34
|
+
daysToPasswordExpiry: DETAILS.DAYS_TO_PASSWORD_EXPIRY,
|
35
|
+
product: fromProductDTO(DETAILS.PRODUCT),
|
36
|
+
}
|
37
|
+
: null,
|
38
|
+
permission: fromDTOStringArray(dto.PERMISSION),
|
39
|
+
profile: fromDTOStringArray(dto.PROFILE),
|
40
|
+
};
|
41
|
+
return ack;
|
42
|
+
}
|
43
|
+
throw new Error('No Entity mapping implementation for provided DTO');
|
44
|
+
}
|
45
|
+
catch (e) {
|
46
|
+
logger.error(e);
|
47
|
+
throw e;
|
48
|
+
}
|
49
|
+
};
|
@@ -54,10 +54,13 @@ export class DefaultConnectEvents {
|
|
54
54
|
}));
|
55
55
|
}
|
56
56
|
/** {@inheritDoc ConnectEventsEmitter.onStreamCompleteEvent} */
|
57
|
-
onStreamCompleteEvent(stream) {
|
57
|
+
onStreamCompleteEvent(resourceName, stream) {
|
58
58
|
var _a;
|
59
59
|
(_a = this.streamCompleteListeners) === null || _a === void 0 ? void 0 : _a.publish(new CustomEvent(StreamCompleteEventType, {
|
60
|
-
detail:
|
60
|
+
detail: {
|
61
|
+
resourceName,
|
62
|
+
stream,
|
63
|
+
},
|
61
64
|
}));
|
62
65
|
}
|
63
66
|
/** {@inheritDoc ConnectEvents.addCommitListener} */
|
@@ -19,6 +19,7 @@ export const defaultConnectConfig = {
|
|
19
19
|
enableHeartbeat: true,
|
20
20
|
enableHeartbeatLogging: false,
|
21
21
|
heartbeatInterval: 10000,
|
22
|
+
verboseHeartbeat: false,
|
22
23
|
enableMessageLogging: false,
|
23
24
|
},
|
24
25
|
reconnect: {
|
@@ -53,8 +54,11 @@ let DefaultConnect = class DefaultConnect {
|
|
53
54
|
httpMode() {
|
54
55
|
return false;
|
55
56
|
}
|
57
|
+
/**
|
58
|
+
* @deprecated - Please reference {@link @genesislcap/foundation-user#User} instead.',
|
59
|
+
*/
|
56
60
|
setValidSession(valid) {
|
57
|
-
this.
|
61
|
+
logger.deprecated('setValidSession', 'Please refrain from calling this API as this state is managed internally.', '15.0.0');
|
58
62
|
}
|
59
63
|
send(message, needsHandling) {
|
60
64
|
return this.socket.send(message, needsHandling);
|
@@ -84,7 +88,7 @@ let DefaultConnect = class DefaultConnect {
|
|
84
88
|
const msg = this.messageBuilder.createDataLogonMessage(resourceName, params);
|
85
89
|
logger.debug(`${msg.MESSAGE_TYPE} (stream) message created -> `, msg);
|
86
90
|
const resource = this.socket.sendForStream(msg, onMessage, onError, () => {
|
87
|
-
this.events.onStreamCompleteEvent(resource);
|
91
|
+
this.events.onStreamCompleteEvent(resourceName, resource);
|
88
92
|
});
|
89
93
|
this.events.onStreamEvent(resourceName, msg, resource, {
|
90
94
|
onMessage,
|
@@ -241,6 +241,15 @@ let DefaultMessageBuilder = class DefaultMessageBuilder {
|
|
241
241
|
}
|
242
242
|
return headers;
|
243
243
|
}
|
244
|
+
/** {@inheritDoc MessageBuilder.createHeartbeatPingMessage} */
|
245
|
+
createHeartbeatPingMessage(verbose = false) {
|
246
|
+
return {
|
247
|
+
MESSAGE_TYPE: MessageType.HEARTBEAT_PING,
|
248
|
+
SOURCE_REF: this.uuid.createId(),
|
249
|
+
VERBOSE: verbose,
|
250
|
+
DETAILS: {},
|
251
|
+
};
|
252
|
+
}
|
244
253
|
};
|
245
254
|
DefaultMessageBuilder = __decorate([
|
246
255
|
__param(0, Session),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { __awaiter, __decorate, __param } from "tslib";
|
2
|
-
import {
|
3
|
-
import { JSONSerializer } from '@genesislcap/foundation-utils';
|
2
|
+
import { User } from '@genesislcap/foundation-user';
|
3
|
+
import { JSONSerializer, UUID } from '@genesislcap/foundation-utils';
|
4
4
|
import { observable } from '@microsoft/fast-element';
|
5
5
|
import { DI } from '@microsoft/fast-foundation';
|
6
6
|
import { Observable, of, Subject, Subscription, takeUntil, throwError } from 'rxjs';
|
@@ -8,7 +8,7 @@ import { filter, mergeMap, switchMap, takeWhile } from 'rxjs/operators';
|
|
8
8
|
import { WebSocketSubject } from 'rxjs/webSocket';
|
9
9
|
import { Session } from '../session';
|
10
10
|
import { logger } from '../utils';
|
11
|
-
import { EventMessageType, MessageBuilder, MessageType } from './message';
|
11
|
+
import { EventMessageType, MessageBuilder, MessageType, } from './message';
|
12
12
|
import { exponentialScheduler, linearScheduler, MAX_RECONNECT_ATTEMPTS, retryInterval, SocketReconnectStrategy, } from './reconnectStrategy';
|
13
13
|
import { SocketStatus } from './socket.status';
|
14
14
|
import { Ticker } from './ticker';
|
@@ -103,18 +103,25 @@ let DefaultSocket = class DefaultSocket {
|
|
103
103
|
get isReconnecting() {
|
104
104
|
return this.status.isReconnecting;
|
105
105
|
}
|
106
|
+
/** {@inheritDoc SerializedSocketStatus.hasValidSession} */
|
106
107
|
get hasValidSession() {
|
107
|
-
|
108
|
+
logger.deprecated('get hasValidSession', 'Use {@link @genesislcap/foundation-user#User.isAuthenticated} directly instead.', '15.0.0');
|
109
|
+
return this.user.isAuthenticated;
|
108
110
|
}
|
109
111
|
set hasValidSession(value) {
|
110
|
-
|
112
|
+
logger.deprecated('set hasValidSession', 'Please refrain from calling this API as this state is managed internally.', '15.0.0');
|
111
113
|
}
|
112
|
-
constructor(messageBuilder, session, serializer, uuid, status
|
114
|
+
constructor(messageBuilder, session, serializer, uuid, status,
|
115
|
+
/**
|
116
|
+
* Temp putting the user in place to bridge the hasValidSession logic.
|
117
|
+
*/
|
118
|
+
user) {
|
113
119
|
this.messageBuilder = messageBuilder;
|
114
120
|
this.session = session;
|
115
121
|
this.serializer = serializer;
|
116
122
|
this.uuid = uuid;
|
117
123
|
this.status = status;
|
124
|
+
this.user = user;
|
118
125
|
this.defaultInterval = 10000;
|
119
126
|
this.secondsMultiplier = 1000;
|
120
127
|
this.heartbeatIsEnabled = true;
|
@@ -182,7 +189,6 @@ let DefaultSocket = class DefaultSocket {
|
|
182
189
|
let nacked = false;
|
183
190
|
switch (receivedMessage.MESSAGE_TYPE) {
|
184
191
|
case EventMessageType.EVENT_LOGIN_AUTH_ACK: {
|
185
|
-
this.hasValidSession = true;
|
186
192
|
const systemDetails = receivedMessage.DETAILS;
|
187
193
|
// Reconfigures the heartbeat with system details from the login response
|
188
194
|
if (systemDetails.HEARTBEAT_INTERVAL_SECS &&
|
@@ -194,7 +200,6 @@ let DefaultSocket = class DefaultSocket {
|
|
194
200
|
break;
|
195
201
|
}
|
196
202
|
case MessageType.LOGOUT_ACK: {
|
197
|
-
this.hasValidSession = false;
|
198
203
|
messageHandler.onReceivedMessage.call(this, receivedMessage);
|
199
204
|
this.cleanMessages();
|
200
205
|
return;
|
@@ -202,13 +207,14 @@ let DefaultSocket = class DefaultSocket {
|
|
202
207
|
case MessageType.LOGON_ACK:
|
203
208
|
return;
|
204
209
|
case MessageType.LOGOFF_ACK: {
|
205
|
-
|
210
|
+
/**
|
211
|
+
* Needs review as I don't quite get the original logic, ie. LOGGED_OUT + hasValidSession.
|
212
|
+
* Perhaps these things should not be the concern of this actor. Temp putting the user in place instead.
|
213
|
+
*/
|
214
|
+
if (receivedMessage.LOGGED_OUT && this.user.isAuthenticated) {
|
206
215
|
const refreshTokenMessage = this.messageBuilder.createRefreshTokenMessage();
|
207
216
|
const refreshTokenResult = yield this.send(refreshTokenMessage);
|
208
|
-
if (
|
209
|
-
this.hasValidSession = false;
|
210
|
-
}
|
211
|
-
else if (refreshTokenResult.MESSAGE_TYPE === EventMessageType.EVENT_LOGIN_AUTH_ACK) {
|
217
|
+
if ((refreshTokenResult === null || refreshTokenResult === void 0 ? void 0 : refreshTokenResult.MESSAGE_TYPE) === EventMessageType.EVENT_LOGIN_AUTH_ACK) {
|
212
218
|
this.session.setAuthResult(refreshTokenResult);
|
213
219
|
this.wsMessageHandlers.forEach((mh) => {
|
214
220
|
if (mh.isSubscription) {
|
@@ -272,13 +278,17 @@ let DefaultSocket = class DefaultSocket {
|
|
272
278
|
this.heartbeatTicker.stop();
|
273
279
|
}
|
274
280
|
const sendHeartbeat = () => __awaiter(this, void 0, void 0, function* () {
|
281
|
+
var _e, _f, _g;
|
275
282
|
if (!this.isConnected)
|
276
283
|
return;
|
277
|
-
const ping =
|
278
|
-
|
279
|
-
|
280
|
-
}
|
284
|
+
const ping = this.messageBuilder.createHeartbeatPingMessage((_e = this.connectOptions) === null || _e === void 0 ? void 0 : _e.verboseHeartbeat);
|
285
|
+
if ((_f = this.connectOptions) === null || _f === void 0 ? void 0 : _f.heartbeatPingCallback) {
|
286
|
+
this.connectOptions.heartbeatPingCallback(ping);
|
287
|
+
}
|
281
288
|
const pong = yield this.send(ping);
|
289
|
+
if ((_g = this.connectOptions) === null || _g === void 0 ? void 0 : _g.heartbeatPongCallback) {
|
290
|
+
this.connectOptions.heartbeatPongCallback(pong);
|
291
|
+
}
|
282
292
|
this.heartbeatIsEnabled =
|
283
293
|
pong.MESSAGE_TYPE === MessageType.HEARTBEAT_PONG && pong.SOURCE_REF === ping.SOURCE_REF;
|
284
294
|
});
|
@@ -381,9 +391,6 @@ let DefaultSocket = class DefaultSocket {
|
|
381
391
|
if (!this.isConnected) {
|
382
392
|
return throwError(() => new Error('WebSocket connection is closed'));
|
383
393
|
}
|
384
|
-
if (!this.hasValidSession) {
|
385
|
-
return throwError(() => new Error(`WebSocket connection is open but there is no valid/active session, please check your auth flow`));
|
386
|
-
}
|
387
394
|
const sendingMessageLog = `Sending Message (stream) for SourceRef: ${message.SOURCE_REF} | MessageType: ${message.MESSAGE_TYPE}`;
|
388
395
|
this.logMessageTypeFlow(message.MESSAGE_TYPE, logger.info, sendingMessageLog);
|
389
396
|
this.setMessageHandler(message, onMessage, onError, true);
|
@@ -421,7 +428,7 @@ let DefaultSocket = class DefaultSocket {
|
|
421
428
|
this.wsMessageHandlers.set(message.SOURCE_REF, new SocketMessageHandler(message, onMessage, onError, isSubscription));
|
422
429
|
}
|
423
430
|
sendDataLogoff(sourceRef) {
|
424
|
-
if (
|
431
|
+
if (this.user.isAnonymous) {
|
425
432
|
return;
|
426
433
|
}
|
427
434
|
this.send(this.messageBuilder.createDataLogoffMessage(sourceRef), false);
|
@@ -470,7 +477,8 @@ DefaultSocket = __decorate([
|
|
470
477
|
__param(1, Session),
|
471
478
|
__param(2, JSONSerializer),
|
472
479
|
__param(3, UUID),
|
473
|
-
__param(4, SocketStatus)
|
480
|
+
__param(4, SocketStatus),
|
481
|
+
__param(5, User)
|
474
482
|
], DefaultSocket);
|
475
483
|
export { DefaultSocket };
|
476
484
|
/**
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { __decorate } from "tslib";
|
2
|
+
import { User } from '@genesislcap/foundation-user';
|
2
3
|
import { observable } from '@microsoft/fast-element';
|
3
4
|
import { DI } from '@microsoft/fast-foundation';
|
4
5
|
import { BehaviorSubject } from 'rxjs';
|
@@ -13,9 +14,12 @@ export class DefaultSocketStatus {
|
|
13
14
|
this.isConnected = false;
|
14
15
|
this.isReconnecting = false;
|
15
16
|
this.reconnectionLimitReached = false;
|
16
|
-
this.hasValidSession = false;
|
17
17
|
this.isConnectedSubject = new BehaviorSubject(this.isConnected);
|
18
18
|
}
|
19
|
+
/** {@inheritDoc SerializedSocketStatus.hasValidSession} */
|
20
|
+
get hasValidSession() {
|
21
|
+
return this.user.isAuthenticated;
|
22
|
+
}
|
19
23
|
get isDisconnected() {
|
20
24
|
return !this.isConnected;
|
21
25
|
}
|
@@ -78,9 +82,6 @@ __decorate([
|
|
78
82
|
__decorate([
|
79
83
|
observable
|
80
84
|
], DefaultSocketStatus.prototype, "reconnectionLimitReached", void 0);
|
81
|
-
__decorate([
|
82
|
-
observable
|
83
|
-
], DefaultSocketStatus.prototype, "hasValidSession", void 0);
|
84
85
|
__decorate([
|
85
86
|
observable
|
86
87
|
], DefaultSocketStatus.prototype, "closedCode", void 0);
|
@@ -90,6 +91,9 @@ __decorate([
|
|
90
91
|
__decorate([
|
91
92
|
observable
|
92
93
|
], DefaultSocketStatus.prototype, "closedClean", void 0);
|
94
|
+
__decorate([
|
95
|
+
User
|
96
|
+
], DefaultSocketStatus.prototype, "user", void 0);
|
93
97
|
/**
|
94
98
|
* SocketStatus DI key.
|
95
99
|
*
|
@@ -10,6 +10,8 @@ export const defaultNetworkMonitorConfig = {
|
|
10
10
|
windowEvents: ['online', 'offline', 'pageshow'],
|
11
11
|
documentEvents: ['visibilitychange'],
|
12
12
|
genesisConnectEvents: ['stream', 'commit'],
|
13
|
+
ignoredGenesisResources: [],
|
14
|
+
startDelay: 5000,
|
13
15
|
checkInterval: 10000,
|
14
16
|
checkTimeout: 3000,
|
15
17
|
/**
|