@genesislcap/foundation-comms 14.176.1-alpha-ed9e3d4.0 → 14.177.1
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
@@ -1,15 +1,16 @@
|
|
1
1
|
var _a;
|
2
2
|
import { __awaiter, __decorate } from "tslib";
|
3
3
|
import { createLogger, LogLevel } from '@genesislcap/foundation-logger';
|
4
|
+
import { User } from '@genesislcap/foundation-user';
|
4
5
|
import { formatDateTimeTimestamp, resolveAfter } from '@genesislcap/foundation-utils';
|
5
6
|
import { observable } from '@microsoft/fast-element';
|
6
7
|
import { DI } from '@microsoft/fast-foundation';
|
7
8
|
import Bowser from 'bowser';
|
9
|
+
import safeStringify from 'fast-safe-stringify';
|
8
10
|
import { StatusCodes } from 'http-status-codes';
|
9
11
|
import { ConnectEvents } from '../connect/connect.events';
|
10
12
|
import { messageHasErrorCode, MessageType } from '../connect/message';
|
11
13
|
import { SocketStatus } from '../connect/socket.status';
|
12
|
-
import { User } from '../user/user';
|
13
14
|
import { NetworkMonitorConfig } from './config';
|
14
15
|
import { SystemHealthChanged, } from './types';
|
15
16
|
/**
|
@@ -26,6 +27,21 @@ const firstUpdated = Date.now();
|
|
26
27
|
const browserInformation = ((_a = window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent)
|
27
28
|
? Bowser.parse(window.navigator.userAgent)
|
28
29
|
: undefined;
|
30
|
+
/**
|
31
|
+
* @internal
|
32
|
+
*/
|
33
|
+
const safeStringifyValue = (value, options = {
|
34
|
+
depthLimit: 10,
|
35
|
+
edgesLimit: 10,
|
36
|
+
}) => {
|
37
|
+
if (value instanceof Event) {
|
38
|
+
return `'${value.type}' Event`;
|
39
|
+
}
|
40
|
+
if (typeof value === 'string') {
|
41
|
+
return value;
|
42
|
+
}
|
43
|
+
return safeStringify(value, undefined, 2, options);
|
44
|
+
};
|
29
45
|
/**
|
30
46
|
* Default NetworkMonitor implementation.
|
31
47
|
* @public
|
@@ -41,12 +57,12 @@ export class DefaultNetworkMonitor {
|
|
41
57
|
*/
|
42
58
|
this.runAllChecks = (source, force) => __awaiter(this, void 0, void 0, function* () {
|
43
59
|
/**
|
44
|
-
* Abort
|
60
|
+
* Abort when not ready, or when checks are already running and the call was not forced
|
45
61
|
*/
|
46
|
-
if (this.isRunningChecks && !force) {
|
62
|
+
if (!this.isReady || (this.isRunningChecks && !force)) {
|
47
63
|
return;
|
48
64
|
}
|
49
|
-
networkLogger.info(`Run health checks, triggered by`, source, `| Active resources`, this.resources.size);
|
65
|
+
networkLogger.info(`Run health checks, triggered by`, safeStringifyValue(source), `| Active resources`, this.resources.size);
|
50
66
|
this.isRunningChecks = true;
|
51
67
|
/**
|
52
68
|
* Synchronise check interval given this has multiple non-automated triggers
|
@@ -54,9 +70,19 @@ export class DefaultNetworkMonitor {
|
|
54
70
|
this.synchroniseCheckInterval();
|
55
71
|
let formattedTimestamp = this.getFormattedTimestamp(this.getNowTimestamp());
|
56
72
|
const isOnline = yield this.isOnlineCheck();
|
57
|
-
if (
|
73
|
+
if (isOnline) {
|
74
|
+
networkLogger.debug(`Network connected at ${formattedTimestamp}`);
|
75
|
+
}
|
76
|
+
else {
|
58
77
|
networkLogger.warn(`Network disconnected at ${formattedTimestamp}`);
|
59
|
-
|
78
|
+
}
|
79
|
+
const socket = this.normaliseSerializedSocketStatus(this.socketStatus.serialize(), isOnline);
|
80
|
+
const passedPreFlightSocketChecks = this.preFlightSocketChecks(socket);
|
81
|
+
if (!passedPreFlightSocketChecks) {
|
82
|
+
networkLogger.debug(`Socket pre-flight checks failed`);
|
83
|
+
}
|
84
|
+
if (!isOnline || !passedPreFlightSocketChecks) {
|
85
|
+
networkLogger.debug(`Aborting remaining health checks`);
|
60
86
|
const resources = [...this.resources].reduce((output, [_, metadata]) => {
|
61
87
|
const existingEntry = output[metadata.resourceName];
|
62
88
|
if (existingEntry) {
|
@@ -66,13 +92,13 @@ export class DefaultNetworkMonitor {
|
|
66
92
|
return Object.assign(Object.assign({}, output), { [metadata.resourceName]: this.normaliseResourceHealth({
|
67
93
|
name: metadata.resourceName,
|
68
94
|
sourceRef: [metadata.message.SOURCE_REF],
|
69
|
-
isConnected:
|
70
|
-
lastUpdated:
|
71
|
-
},
|
95
|
+
isConnected: metadata.isConnected,
|
96
|
+
lastUpdated: metadata.lastUpdated,
|
97
|
+
}, isOnline) });
|
72
98
|
}, {});
|
73
99
|
this.reportSystemHealth({
|
74
|
-
isAuthenticated:
|
75
|
-
isOnline
|
100
|
+
isAuthenticated: this.user.isAuthenticated,
|
101
|
+
isOnline,
|
76
102
|
resources,
|
77
103
|
resourcesAllConnected: false,
|
78
104
|
socket,
|
@@ -80,13 +106,6 @@ export class DefaultNetworkMonitor {
|
|
80
106
|
this.isRunningChecks = false;
|
81
107
|
return;
|
82
108
|
}
|
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
109
|
let resourcesAllConnected = true;
|
91
110
|
const allChecks = [];
|
92
111
|
this.resources.forEach((meta, resource) => {
|
@@ -136,11 +155,17 @@ export class DefaultNetworkMonitor {
|
|
136
155
|
else {
|
137
156
|
networkLogger.warn(`${name} is not healthy at ${formattedTimestamp}`);
|
138
157
|
}
|
158
|
+
if (lastMessage) {
|
159
|
+
networkLogger.debug(`${name} messaged at ${formattedTimestamp}`, safeStringifyValue(lastMessage));
|
160
|
+
}
|
139
161
|
if (lastError) {
|
140
|
-
networkLogger.error(`${name} errored at ${formattedTimestamp}`, lastError);
|
162
|
+
networkLogger.error(`${name} errored at ${formattedTimestamp}`, safeStringifyValue(lastError));
|
163
|
+
}
|
164
|
+
if (timeout) {
|
165
|
+
networkLogger.warn(`${name} timed out at ${formattedTimestamp}`);
|
141
166
|
}
|
142
167
|
if (attemptDataLogon) {
|
143
|
-
networkLogger.error(`${name}
|
168
|
+
networkLogger.error(`${name} issue, re-attempting data logon at ${formattedTimestamp}`);
|
144
169
|
resourceDataLogon(meta);
|
145
170
|
}
|
146
171
|
/**
|
@@ -175,8 +200,9 @@ export class DefaultNetworkMonitor {
|
|
175
200
|
networkLogger.warn(`Unexpected promise rejection occurred. Please check any custom resourceChecks return MonitoredResourceChecksResult.`);
|
176
201
|
return prev;
|
177
202
|
}, {});
|
203
|
+
networkLogger.debug('Health checks complete');
|
178
204
|
this.reportSystemHealth({
|
179
|
-
isAuthenticated:
|
205
|
+
isAuthenticated: this.user.isAuthenticated,
|
180
206
|
isOnline,
|
181
207
|
resources,
|
182
208
|
resourcesAllConnected,
|
@@ -184,6 +210,12 @@ export class DefaultNetworkMonitor {
|
|
184
210
|
});
|
185
211
|
this.isRunningChecks = false;
|
186
212
|
});
|
213
|
+
/**
|
214
|
+
* Apply log level from config if set
|
215
|
+
*/
|
216
|
+
if (this.config.logLevel !== undefined) {
|
217
|
+
networkLogger.level = this.config.logLevel;
|
218
|
+
}
|
187
219
|
}
|
188
220
|
/**
|
189
221
|
* {@inheritDoc NetworkMonitor.create}
|
@@ -195,11 +227,11 @@ export class DefaultNetworkMonitor {
|
|
195
227
|
}
|
196
228
|
this.addListeners();
|
197
229
|
this.resources = new Map();
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
this.
|
230
|
+
setTimeout(() => {
|
231
|
+
this.isReady = true;
|
232
|
+
this.synchroniseCheckInterval();
|
233
|
+
this.runAllChecks(`NetworkMonitor.create()`);
|
234
|
+
}, this.config.startDelay);
|
203
235
|
}
|
204
236
|
/**
|
205
237
|
* {@inheritDoc NetworkMonitor.destroy}
|
@@ -210,6 +242,7 @@ export class DefaultNetworkMonitor {
|
|
210
242
|
this.resources.clear();
|
211
243
|
this.resources = undefined;
|
212
244
|
this.status = undefined;
|
245
|
+
this.isReady = undefined;
|
213
246
|
}
|
214
247
|
/**
|
215
248
|
* @internal
|
@@ -242,17 +275,29 @@ export class DefaultNetworkMonitor {
|
|
242
275
|
if (this.config.genesisConnectEvents.includes('stream')) {
|
243
276
|
this.unsubscribableObservers.push(this.connectEvents.addStreamListener(({ detail }) => {
|
244
277
|
const { functions, message, resourceName, stream } = detail;
|
278
|
+
if (this.config.ignoredGenesisResources.includes(resourceName)) {
|
279
|
+
return;
|
280
|
+
}
|
245
281
|
this.addResource(stream, {
|
246
282
|
functions,
|
247
283
|
message,
|
248
284
|
resourceName,
|
249
285
|
});
|
250
286
|
}, ({ detail }) => {
|
251
|
-
|
287
|
+
const { resourceName, stream } = detail;
|
288
|
+
if (this.config.ignoredGenesisResources.includes(resourceName)) {
|
289
|
+
return;
|
290
|
+
}
|
291
|
+
this.removeResource(stream);
|
252
292
|
}));
|
253
293
|
}
|
254
294
|
if (this.config.genesisConnectEvents.includes('commit')) {
|
255
|
-
this.unsubscribableObservers.push(this.connectEvents.addCommitListener(
|
295
|
+
this.unsubscribableObservers.push(this.connectEvents.addCommitListener((event) => {
|
296
|
+
if (this.config.ignoredGenesisResources.includes(event.detail.eventName)) {
|
297
|
+
return;
|
298
|
+
}
|
299
|
+
this.runAllChecks(event);
|
300
|
+
}));
|
256
301
|
}
|
257
302
|
this.unsubscribableObservers.push(this.connectEvents.addMetadataListener(({ detail }) => {
|
258
303
|
const { resourceName, error } = detail;
|
@@ -285,7 +330,7 @@ export class DefaultNetworkMonitor {
|
|
285
330
|
const eventEmitter = (_a = this.config.eventEmitter) !== null && _a !== void 0 ? _a : document;
|
286
331
|
this.status = this.normaliseEventDetail(detail);
|
287
332
|
const loggerFn = this.status.isHealthy ? networkLogger.debug : networkLogger.warn;
|
288
|
-
loggerFn(`Emitting 'system-health-changed' event`, this.status);
|
333
|
+
loggerFn(`Emitting 'system-health-changed' event`, safeStringifyValue(this.status));
|
289
334
|
eventEmitter === null || eventEmitter === void 0 ? void 0 : eventEmitter.dispatchEvent(new CustomEvent(SystemHealthChanged, {
|
290
335
|
detail: this.status,
|
291
336
|
bubbles: eventEmitter !== document,
|
@@ -374,6 +419,41 @@ export class DefaultNetworkMonitor {
|
|
374
419
|
} });
|
375
420
|
return normalisedDetail;
|
376
421
|
}
|
422
|
+
/**
|
423
|
+
* @returns A flag to indicate if the socket is in a state that allows resource checking.
|
424
|
+
* @internal
|
425
|
+
*/
|
426
|
+
preFlightSocketChecks(status) {
|
427
|
+
if (!status.isConfigured) {
|
428
|
+
networkLogger.debug(`Socket not configured`);
|
429
|
+
return false;
|
430
|
+
}
|
431
|
+
if (status.isReconnecting) {
|
432
|
+
networkLogger.debug(`Socket reconnecting`);
|
433
|
+
return false;
|
434
|
+
}
|
435
|
+
if (status.isConnecting) {
|
436
|
+
networkLogger.debug(`Socket connecting`);
|
437
|
+
return false;
|
438
|
+
}
|
439
|
+
if (status.isDisconnected) {
|
440
|
+
const closedDetails = status.isDisconnectedByServer
|
441
|
+
? `by the server, code: ${status.closedCode}, reason: ${status.closedReason}`
|
442
|
+
: '';
|
443
|
+
networkLogger.debug(`Socket disconnected ${closedDetails}`);
|
444
|
+
if (status.reconnectionLimitReached) {
|
445
|
+
networkLogger.debug(`Socket reconnection limit reached`);
|
446
|
+
}
|
447
|
+
return false;
|
448
|
+
}
|
449
|
+
/**
|
450
|
+
* Socket is okay to run resource checks.
|
451
|
+
* Data servers can be set to serve anonymous users, so don't block due to session validity.
|
452
|
+
*/
|
453
|
+
const withOrWithout = this.user.isAuthenticated ? `with` : 'without';
|
454
|
+
networkLogger.debug(`Socket connected ${withOrWithout} valid session`);
|
455
|
+
return true;
|
456
|
+
}
|
377
457
|
/**
|
378
458
|
* @internal
|
379
459
|
*/
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { __awaiter, __decorate, __param } from "tslib";
|
2
|
+
import { User } from '@genesislcap/foundation-user';
|
2
3
|
import { DI, optional } from '@microsoft/fast-foundation';
|
3
|
-
import { Auth } from '../../auth';
|
4
4
|
import { Connect } from '../../connect';
|
5
5
|
import { logger } from '../../utils';
|
6
6
|
import { defaultKVStorageConfig, KVStorageConfig } from './kv-config.service';
|
@@ -10,9 +10,9 @@ import { KVEventMessageType, KVMessageType, } from './kv.types';
|
|
10
10
|
* @alpha
|
11
11
|
*/
|
12
12
|
let DefaultKVStorage = class DefaultKVStorage {
|
13
|
-
constructor(connect,
|
13
|
+
constructor(connect, user, kvStorageConfig = defaultKVStorageConfig) {
|
14
14
|
this.connect = connect;
|
15
|
-
this.
|
15
|
+
this.user = user;
|
16
16
|
this.kvStorageConfig = kvStorageConfig;
|
17
17
|
this.checkAvailability();
|
18
18
|
}
|
@@ -78,11 +78,11 @@ let DefaultKVStorage = class DefaultKVStorage {
|
|
78
78
|
* ```
|
79
79
|
*/
|
80
80
|
get(key) {
|
81
|
-
var _a
|
81
|
+
var _a;
|
82
82
|
return __awaiter(this, void 0, void 0, function* () {
|
83
83
|
const params = {
|
84
84
|
REQUEST: {
|
85
|
-
USER_NAME: (_a = this.kvStorageConfig.authEmail) !== null && _a !== void 0 ? _a :
|
85
|
+
USER_NAME: (_a = this.kvStorageConfig.authEmail) !== null && _a !== void 0 ? _a : this.user.userName,
|
86
86
|
KEY: key,
|
87
87
|
},
|
88
88
|
};
|
@@ -109,11 +109,11 @@ let DefaultKVStorage = class DefaultKVStorage {
|
|
109
109
|
* ```
|
110
110
|
*/
|
111
111
|
list() {
|
112
|
-
var _a
|
112
|
+
var _a;
|
113
113
|
return __awaiter(this, void 0, void 0, function* () {
|
114
114
|
const params = {
|
115
115
|
REQUEST: {
|
116
|
-
USER_NAME: (_a = this.kvStorageConfig.authEmail) !== null && _a !== void 0 ? _a :
|
116
|
+
USER_NAME: (_a = this.kvStorageConfig.authEmail) !== null && _a !== void 0 ? _a : this.user.userName,
|
117
117
|
},
|
118
118
|
};
|
119
119
|
const result = yield this.connect.request(KVMessageType.REQ_KEY_VALUE_LIST, params);
|
@@ -161,7 +161,7 @@ let DefaultKVStorage = class DefaultKVStorage {
|
|
161
161
|
};
|
162
162
|
DefaultKVStorage = __decorate([
|
163
163
|
__param(0, Connect),
|
164
|
-
__param(1,
|
164
|
+
__param(1, User),
|
165
165
|
__param(2, optional(KVStorageConfig))
|
166
166
|
], DefaultKVStorage);
|
167
167
|
export { DefaultKVStorage };
|
@@ -170,3 +170,21 @@ export { DefaultKVStorage };
|
|
170
170
|
* @internal
|
171
171
|
*/
|
172
172
|
export const KVStorage = DI.createInterface((x) => x.singleton(DefaultKVStorage));
|
173
|
+
/**
|
174
|
+
* Gets KVStorage from the DI container.
|
175
|
+
*
|
176
|
+
* @remarks
|
177
|
+
* A utility method for host applications that are not using decorators or the DI container.
|
178
|
+
*
|
179
|
+
* @example
|
180
|
+
* ```ts
|
181
|
+
* import { getKVStorage } from '@genesislcap/foundation-comms';
|
182
|
+
* ...
|
183
|
+
* private kvStorage = getKVStorage();
|
184
|
+
* ```
|
185
|
+
*
|
186
|
+
* @public
|
187
|
+
*/
|
188
|
+
export function getKVStorage() {
|
189
|
+
return DI.getOrCreateDOMContainer().get(KVStorage);
|
190
|
+
}
|
package/dist/esm/user/user.js
CHANGED
@@ -1,66 +1,23 @@
|
|
1
|
-
import {
|
2
|
-
import { observable } from '@microsoft/fast-element';
|
1
|
+
import { User as NextUser, DefaultUser as DefaultNextUser } from '@genesislcap/foundation-user';
|
3
2
|
import { DI } from '@microsoft/fast-foundation';
|
4
3
|
/**
|
5
4
|
* Represents the current user (i.e. the user that is currently logged in).
|
5
|
+
*
|
6
|
+
* @deprecated - Use {@link @genesislcap/foundation-user#DefaultUser} instead.
|
7
|
+
*
|
6
8
|
* @public
|
7
9
|
*/
|
8
|
-
export class CurrentUser {
|
9
|
-
constructor(options) {
|
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;
|
24
|
-
}
|
25
|
-
hasAdminProfile() {
|
26
|
-
return this.hasProfile('ADMIN');
|
27
|
-
}
|
28
|
-
hasPermission(permission) {
|
29
|
-
return this.hasKey(this.permissions, permission);
|
30
|
-
}
|
31
|
-
hasProfile(profile) {
|
32
|
-
return this.hasKey(this.profiles, profile);
|
33
|
-
}
|
34
|
-
/**
|
35
|
-
* Checks if the given key or keys are present in the given array of keys.
|
36
|
-
* @internal
|
37
|
-
* @param keys - The array of keys to check.
|
38
|
-
* @param key - The key or keys to check for.
|
39
|
-
* @returns True if the key or keys are present in the array of keys.
|
40
|
-
*/
|
41
|
-
hasKey(keys, key) {
|
42
|
-
if (!keys || !keys.length || !key) {
|
43
|
-
return false;
|
44
|
-
}
|
45
|
-
if (!Array.isArray(key)) {
|
46
|
-
key = [key];
|
47
|
-
}
|
48
|
-
return key.some((k) => keys.includes(k));
|
49
|
-
}
|
10
|
+
export class CurrentUser extends DefaultNextUser {
|
50
11
|
}
|
51
|
-
__decorate([
|
52
|
-
observable
|
53
|
-
], CurrentUser.prototype, "permissions", void 0);
|
54
|
-
__decorate([
|
55
|
-
observable
|
56
|
-
], CurrentUser.prototype, "profiles", void 0);
|
57
|
-
__decorate([
|
58
|
-
observable
|
59
|
-
], CurrentUser.prototype, "username", void 0);
|
60
12
|
/**
|
61
13
|
* User DI key.
|
14
|
+
*
|
62
15
|
* @privateRemarks
|
63
16
|
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
17
|
+
* Using aliasTo to point to {@link @genesislcap/foundation-user#User}.
|
18
|
+
*
|
19
|
+
* @deprecated - Use {@link @genesislcap/foundation-user#User} instead.
|
20
|
+
*
|
64
21
|
* @internal
|
65
22
|
*/
|
66
|
-
export const User = DI.createInterface((x) => x.
|
23
|
+
export const User = DI.createInterface((x) => x.aliasTo(NextUser));
|