@genesislcap/foundation-user 14.137.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +43 -0
- package/dist/dts/config.d.ts +53 -0
- package/dist/dts/config.d.ts.map +1 -0
- package/dist/dts/index.d.ts +5 -0
- package/dist/dts/index.d.ts.map +1 -0
- package/dist/dts/index.federated.d.ts +1 -0
- package/dist/dts/index.federated.d.ts.map +1 -0
- package/dist/dts/logger.d.ts +5 -0
- package/dist/dts/logger.d.ts.map +1 -0
- package/dist/dts/tsdoc-metadata.json +11 -0
- package/dist/dts/types.d.ts +134 -0
- package/dist/dts/types.d.ts.map +1 -0
- package/dist/dts/user.d.ts +167 -0
- package/dist/dts/user.d.ts.map +1 -0
- package/dist/esm/config.js +57 -0
- package/dist/esm/index.federated.js +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/logger.js +5 -0
- package/dist/esm/types.js +5 -0
- package/dist/esm/user.js +182 -0
- package/dist/foundation-user.api.json +3350 -0
- package/dist/foundation-user.d.ts +374 -0
- package/docs/.gitattributes +2 -0
- package/docs/api/foundation-user.defaultuser.actionhistory.md +13 -0
- package/docs/api/foundation-user.defaultuser.addauthenticationchangelistener.md +22 -0
- package/docs/api/foundation-user.defaultuser.clearactions.md +17 -0
- package/docs/api/foundation-user.defaultuser.clearpaths.md +17 -0
- package/docs/api/foundation-user.defaultuser.cleartrackinghistory.md +16 -0
- package/docs/api/foundation-user.defaultuser.details.md +12 -0
- package/docs/api/foundation-user.defaultuser.haspermission.md +22 -0
- package/docs/api/foundation-user.defaultuser.hasprofile.md +22 -0
- package/docs/api/foundation-user.defaultuser.isadmin.md +16 -0
- package/docs/api/foundation-user.defaultuser.isanonymous.md +12 -0
- package/docs/api/foundation-user.defaultuser.isauthenticated.md +12 -0
- package/docs/api/foundation-user.defaultuser.isbanned.md +16 -0
- package/docs/api/foundation-user.defaultuser.lastaction.md +17 -0
- package/docs/api/foundation-user.defaultuser.lastpath.md +19 -0
- package/docs/api/foundation-user.defaultuser.md +51 -0
- package/docs/api/foundation-user.defaultuser.pathhistory.md +13 -0
- package/docs/api/foundation-user.defaultuser.permission.md +12 -0
- package/docs/api/foundation-user.defaultuser.profile.md +12 -0
- package/docs/api/foundation-user.defaultuser.rawproperties.md +18 -0
- package/docs/api/foundation-user.defaultuser.set.md +22 -0
- package/docs/api/foundation-user.defaultuser.sourceref.md +12 -0
- package/docs/api/foundation-user.defaultuser.trackaction.md +24 -0
- package/docs/api/foundation-user.defaultuser.trackpath.md +17 -0
- package/docs/api/foundation-user.defaultuser.unset.md +16 -0
- package/docs/api/foundation-user.defaultuser.userkvs.md +14 -0
- package/docs/api/foundation-user.defaultuser.username.md +12 -0
- package/docs/api/foundation-user.defaultuserconfig.md +13 -0
- package/docs/api/foundation-user.getuser.md +30 -0
- package/docs/api/foundation-user.logger.md +12 -0
- package/docs/api/foundation-user.md +47 -0
- package/docs/api/foundation-user.setuserproperties.details.md +11 -0
- package/docs/api/foundation-user.setuserproperties.md +26 -0
- package/docs/api/foundation-user.setuserproperties.permission.md +11 -0
- package/docs/api/foundation-user.setuserproperties.profile.md +11 -0
- package/docs/api/foundation-user.setuserproperties.sourceref.md +11 -0
- package/docs/api/foundation-user.setuserproperties.userkvs.md +11 -0
- package/docs/api/foundation-user.setuserproperties.username.md +11 -0
- package/docs/api/foundation-user.user.addauthenticationchangelistener.md +33 -0
- package/docs/api/foundation-user.user.cleartrackinghistory.md +15 -0
- package/docs/api/foundation-user.user.details.md +11 -0
- package/docs/api/foundation-user.user.haspermission.md +22 -0
- package/docs/api/foundation-user.user.hasprofile.md +22 -0
- package/docs/api/foundation-user.user.isadmin.md +15 -0
- package/docs/api/foundation-user.user.isanonymous.md +11 -0
- package/docs/api/foundation-user.user.isauthenticated.md +11 -0
- package/docs/api/foundation-user.user.isbanned.md +15 -0
- package/docs/api/foundation-user.user.md +56 -0
- package/docs/api/foundation-user.user.permission.md +11 -0
- package/docs/api/foundation-user.user.profile.md +11 -0
- package/docs/api/foundation-user.user.rawproperties.md +18 -0
- package/docs/api/foundation-user.user.set.md +22 -0
- package/docs/api/foundation-user.user.sourceref.md +11 -0
- package/docs/api/foundation-user.user.unset.md +15 -0
- package/docs/api/foundation-user.user.userkvs.md +13 -0
- package/docs/api/foundation-user.user.username.md +11 -0
- package/docs/api/foundation-user.useractionhistory.actionhistory.md +13 -0
- package/docs/api/foundation-user.useractionhistory.clearactions.md +17 -0
- package/docs/api/foundation-user.useractionhistory.lastaction.md +17 -0
- package/docs/api/foundation-user.useractionhistory.md +32 -0
- package/docs/api/foundation-user.useractionhistory.trackaction.md +24 -0
- package/docs/api/foundation-user.userauthenticationchangeevent.md +18 -0
- package/docs/api/foundation-user.userauthenticationchangetype.md +13 -0
- package/docs/api/foundation-user.userconfig.md +28 -0
- package/docs/api/foundation-user.userconfig.setuser.md +29 -0
- package/docs/api/foundation-user.userconfig.trackactionexclusions.md +15 -0
- package/docs/api/foundation-user.userconfig.trackpathexclusions.md +15 -0
- package/docs/api/foundation-user.userconfig.unsetuser.md +24 -0
- package/docs/api/foundation-user.userdetailsproductproperty.md +20 -0
- package/docs/api/foundation-user.userdetailsproductproperty.name.md +11 -0
- package/docs/api/foundation-user.userdetailsproductproperty.version.md +11 -0
- package/docs/api/foundation-user.userdetailsproperty.daystopasswordexpiry.md +11 -0
- package/docs/api/foundation-user.userdetailsproperty.failedloginattempts.md +11 -0
- package/docs/api/foundation-user.userdetailsproperty.heartbeatintervalsecs.md +11 -0
- package/docs/api/foundation-user.userdetailsproperty.lastlogindatetime.md +11 -0
- package/docs/api/foundation-user.userdetailsproperty.md +25 -0
- package/docs/api/foundation-user.userdetailsproperty.product.md +11 -0
- package/docs/api/foundation-user.userdetailsproperty.rejectedloginattempts.md +11 -0
- package/docs/api/foundation-user.userdetailsproperty.system.md +11 -0
- package/docs/api/foundation-user.userdetailssystemproperty.date.md +11 -0
- package/docs/api/foundation-user.userdetailssystemproperty.md +19 -0
- package/docs/api/foundation-user.userkvsproperty.md +12 -0
- package/docs/api/foundation-user.userpathhistory.clearpaths.md +17 -0
- package/docs/api/foundation-user.userpathhistory.lastpath.md +19 -0
- package/docs/api/foundation-user.userpathhistory.md +32 -0
- package/docs/api/foundation-user.userpathhistory.pathhistory.md +13 -0
- package/docs/api/foundation-user.userpathhistory.trackpath.md +17 -0
- package/docs/api/foundation-user.userqueueproperties.md +22 -0
- package/docs/api/foundation-user.userqueueproperties.updatequeue.md +11 -0
- package/docs/api/foundation-user.userqueueproperties.zeromqproxyinboundport.md +11 -0
- package/docs/api/foundation-user.userqueueproperties.zeromqproxymodeenabled.md +11 -0
- package/docs/api/foundation-user.userqueueproperties.zeromqproxyoutboundport.md +11 -0
- package/docs/api/index.md +12 -0
- package/docs/api-report.md +277 -0
- package/license.txt +46 -0
- package/package.json +48 -0
package/dist/esm/user.js
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
import { __decorate } from "tslib";
|
2
|
+
import { createObserver } from '@genesislcap/foundation-utils';
|
3
|
+
import { Observable, observable } from '@microsoft/fast-element';
|
4
|
+
import { DI } from '@microsoft/fast-foundation';
|
5
|
+
import { UserConfig } from './config';
|
6
|
+
import { UserAuthenticationChangeType } from './types';
|
7
|
+
/**
|
8
|
+
* Default User implementation.
|
9
|
+
* @public
|
10
|
+
*/
|
11
|
+
export class DefaultUser {
|
12
|
+
constructor() {
|
13
|
+
/** {@inheritDoc UserPathHistory.pathHistory} */
|
14
|
+
this.pathHistory = [];
|
15
|
+
/** {@inheritDoc UserActionHistory.actionHistory} */
|
16
|
+
this.actionHistory = [];
|
17
|
+
/** {@inheritDoc User.isAuthenticated} */
|
18
|
+
this.isAuthenticated = false;
|
19
|
+
/** @internal */
|
20
|
+
this.authenticationChangeListeners = createObserver();
|
21
|
+
}
|
22
|
+
/** {@inheritDoc User.set} */
|
23
|
+
set(properties) {
|
24
|
+
return this.config.setUser(this, properties);
|
25
|
+
}
|
26
|
+
/** {@inheritDoc User.unset} */
|
27
|
+
unset() {
|
28
|
+
return this.config.unsetUser(this);
|
29
|
+
}
|
30
|
+
/** @internal */
|
31
|
+
userNameChanged() {
|
32
|
+
Observable.notify(this, 'username');
|
33
|
+
}
|
34
|
+
/** {@inheritDoc User.username} */
|
35
|
+
get username() {
|
36
|
+
Observable.track(this, 'username');
|
37
|
+
return this.userName;
|
38
|
+
}
|
39
|
+
/** {@inheritDoc User.isAnonymous} */
|
40
|
+
get isAnonymous() {
|
41
|
+
return !this.isAuthenticated;
|
42
|
+
}
|
43
|
+
/** {@inheritDoc User.isAdmin} */
|
44
|
+
isAdmin() {
|
45
|
+
return this.hasProfile('ADMIN');
|
46
|
+
}
|
47
|
+
/** {@inheritDoc User.isBanned} */
|
48
|
+
isBanned() {
|
49
|
+
return this.hasProfile('BANNED');
|
50
|
+
}
|
51
|
+
/** {@inheritDoc User.hasPermission} */
|
52
|
+
hasPermission(permission) {
|
53
|
+
return this.hasKey(this.permission, permission);
|
54
|
+
}
|
55
|
+
/** {@inheritDoc User.hasProfile} */
|
56
|
+
hasProfile(profile) {
|
57
|
+
return this.hasKey(this.profile, profile);
|
58
|
+
}
|
59
|
+
/** {@inheritDoc UserPathHistory.trackPath} */
|
60
|
+
trackPath() {
|
61
|
+
const { pathname, search, hash } = location;
|
62
|
+
const path = `${pathname !== '/' ? pathname : ''}`;
|
63
|
+
const urlPath = `${path}${search}${hash}`;
|
64
|
+
if (this.config.trackPathExclusions.includes(urlPath)) {
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
this.pathHistory.push(urlPath);
|
68
|
+
return urlPath;
|
69
|
+
}
|
70
|
+
/** {@inheritDoc UserPathHistory.clearPaths} */
|
71
|
+
clearPaths() {
|
72
|
+
this.pathHistory = [];
|
73
|
+
}
|
74
|
+
/** {@inheritDoc UserPathHistory.lastPath} */
|
75
|
+
lastPath() {
|
76
|
+
const length = this.pathHistory.length;
|
77
|
+
return length > 0 ? this.pathHistory[length - 1] : undefined;
|
78
|
+
}
|
79
|
+
/** {@inheritDoc UserActionHistory.trackAction} */
|
80
|
+
trackAction(details) {
|
81
|
+
if (this.config.trackActionExclusions.includes(details)) {
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
this.actionHistory.push(details);
|
85
|
+
}
|
86
|
+
/** {@inheritDoc UserActionHistory.clearActions} */
|
87
|
+
clearActions() {
|
88
|
+
this.actionHistory = [];
|
89
|
+
}
|
90
|
+
/** {@inheritDoc UserActionHistory.lastAction} */
|
91
|
+
lastAction() {
|
92
|
+
const length = this.actionHistory.length;
|
93
|
+
return length > 0 ? this.actionHistory[length - 1] : undefined;
|
94
|
+
}
|
95
|
+
/** {@inheritDoc User.clearTrackingHistory} */
|
96
|
+
clearTrackingHistory() {
|
97
|
+
this.clearPaths();
|
98
|
+
this.clearActions();
|
99
|
+
}
|
100
|
+
/** @internal */
|
101
|
+
hasKey(keys, key) {
|
102
|
+
if (!keys || !keys.length || !key) {
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
if (!Array.isArray(key)) {
|
106
|
+
key = [key];
|
107
|
+
}
|
108
|
+
return key.some((k) => keys.includes(k));
|
109
|
+
}
|
110
|
+
/** {@inheritDoc User.addAuthenticationChangeListener} */
|
111
|
+
addAuthenticationChangeListener(listener) {
|
112
|
+
var _a;
|
113
|
+
return (_a = this.authenticationChangeListeners) === null || _a === void 0 ? void 0 : _a.subscribe(listener);
|
114
|
+
}
|
115
|
+
/** @internal */
|
116
|
+
isAuthenticatedChanged() {
|
117
|
+
var _a;
|
118
|
+
(_a = this.authenticationChangeListeners) === null || _a === void 0 ? void 0 : _a.publish(new CustomEvent(UserAuthenticationChangeType, {
|
119
|
+
detail: this.isAuthenticated,
|
120
|
+
}));
|
121
|
+
}
|
122
|
+
}
|
123
|
+
__decorate([
|
124
|
+
UserConfig
|
125
|
+
], DefaultUser.prototype, "config", void 0);
|
126
|
+
__decorate([
|
127
|
+
observable
|
128
|
+
], DefaultUser.prototype, "pathHistory", void 0);
|
129
|
+
__decorate([
|
130
|
+
observable
|
131
|
+
], DefaultUser.prototype, "actionHistory", void 0);
|
132
|
+
__decorate([
|
133
|
+
observable
|
134
|
+
], DefaultUser.prototype, "isAuthenticated", void 0);
|
135
|
+
__decorate([
|
136
|
+
observable
|
137
|
+
], DefaultUser.prototype, "userKVs", void 0);
|
138
|
+
__decorate([
|
139
|
+
observable
|
140
|
+
], DefaultUser.prototype, "details", void 0);
|
141
|
+
__decorate([
|
142
|
+
observable
|
143
|
+
], DefaultUser.prototype, "permission", void 0);
|
144
|
+
__decorate([
|
145
|
+
observable
|
146
|
+
], DefaultUser.prototype, "profile", void 0);
|
147
|
+
__decorate([
|
148
|
+
observable
|
149
|
+
], DefaultUser.prototype, "sourceRef", void 0);
|
150
|
+
__decorate([
|
151
|
+
observable
|
152
|
+
], DefaultUser.prototype, "userName", void 0);
|
153
|
+
__decorate([
|
154
|
+
observable
|
155
|
+
], DefaultUser.prototype, "rawProperties", void 0);
|
156
|
+
/**
|
157
|
+
* User DI key.
|
158
|
+
*
|
159
|
+
* @privateRemarks
|
160
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
161
|
+
*
|
162
|
+
* @internal
|
163
|
+
*/
|
164
|
+
export const User = DI.createInterface((x) => x.singleton(DefaultUser));
|
165
|
+
/**
|
166
|
+
* Gets User from the DI container.
|
167
|
+
*
|
168
|
+
* @remarks
|
169
|
+
* A utility method for host applications that are not using decorators or the DI container.
|
170
|
+
*
|
171
|
+
* @example
|
172
|
+
* ```ts
|
173
|
+
* import { getUser, User } from '@genesislcap/foundation-user';
|
174
|
+
* ...
|
175
|
+
* private user: User = getUser();
|
176
|
+
* ```
|
177
|
+
*
|
178
|
+
* @public
|
179
|
+
*/
|
180
|
+
export function getUser() {
|
181
|
+
return DI.getOrCreateDOMContainer().get(User);
|
182
|
+
}
|