@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/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Genesis User
|
2
|
+
|
3
|
+
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)
|
4
|
+
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](https://www.typescriptlang.org/)
|
5
|
+
|
6
|
+
`foundation-user` provides the [User](./docs/api/foundation-user.user.md) singleton, which always exists in either an
|
7
|
+
anonymous or authenticated mode.
|
8
|
+
|
9
|
+
### Get User reference
|
10
|
+
User is a singleton. You can access it via the DI container.
|
11
|
+
```ts
|
12
|
+
import { User } from '@genesislcap/foundation-user';
|
13
|
+
...
|
14
|
+
@User private user: User
|
15
|
+
```
|
16
|
+
|
17
|
+
...or via a utility if your app is not using decorators or the DI container.
|
18
|
+
```ts
|
19
|
+
import { getUser } from '@genesislcap/foundation-user';
|
20
|
+
...
|
21
|
+
private user = getUser();
|
22
|
+
```
|
23
|
+
|
24
|
+
User properties are decorated with `@observable`, meaning in FAST terms it's reactive, and you can bind to properties
|
25
|
+
directly. For example, `this.user.isAuthenticated`. However, you can also monitor the user's authentication status using
|
26
|
+
an event listener.
|
27
|
+
|
28
|
+
```ts
|
29
|
+
import type { UserAuthenticationChangeEvent } from '@genesislcap/foundation-user';
|
30
|
+
...
|
31
|
+
const unsubscribeUser = this.user.addAuthenticationChangeListener((event: UserAuthenticationChangeEvent) => {
|
32
|
+
console.log('User authenticated?', event.detail); // < boolean === this.user.isAuthenticated
|
33
|
+
});
|
34
|
+
```
|
35
|
+
|
36
|
+
See the [User API Docs](./docs/api/foundation-user.user.md) for more information.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
Note: this project provides front-end dependencies and uses licensed components listed in the next section; thus, licenses for those components are required during development. Contact [Genesis Global](https://genesis.global/contact-us/) for more details.
|
41
|
+
|
42
|
+
### Licensed components
|
43
|
+
Genesis low-code platform
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { SetUserProperties } from './types';
|
2
|
+
import type { User } from './user';
|
3
|
+
/**
|
4
|
+
* @internal
|
5
|
+
*/
|
6
|
+
type WriteableUser = {
|
7
|
+
-readonly [P in keyof User]: User[P];
|
8
|
+
};
|
9
|
+
/**
|
10
|
+
* UserConfig DI interface.
|
11
|
+
*
|
12
|
+
* @public
|
13
|
+
*/
|
14
|
+
export interface UserConfig {
|
15
|
+
/**
|
16
|
+
* Exclude certain actions from tracking.
|
17
|
+
*
|
18
|
+
* See {@link UserPathHistory}
|
19
|
+
*/
|
20
|
+
trackActionExclusions: unknown[];
|
21
|
+
/**
|
22
|
+
* Exclude certain paths from tracking.
|
23
|
+
*
|
24
|
+
* See {@link UserActionHistory}
|
25
|
+
*/
|
26
|
+
trackPathExclusions: string[];
|
27
|
+
/**
|
28
|
+
* User property setter.
|
29
|
+
*
|
30
|
+
* @remarks
|
31
|
+
* The user is typically set from the result of a LoginAck.
|
32
|
+
*/
|
33
|
+
setUser(user: WriteableUser, properties: Partial<SetUserProperties>): User;
|
34
|
+
/**
|
35
|
+
* User property un-setter.
|
36
|
+
*/
|
37
|
+
unsetUser(user: WriteableUser): User;
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* Default UserConfig DI implementation.
|
41
|
+
* @public
|
42
|
+
*/
|
43
|
+
export declare const defaultUserConfig: UserConfig;
|
44
|
+
/**
|
45
|
+
* UserConfig DI key.
|
46
|
+
*
|
47
|
+
* @internal
|
48
|
+
* @privateRemarks
|
49
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
50
|
+
*/
|
51
|
+
export declare const UserConfig: import("@microsoft/fast-foundation").InterfaceSymbol<UserConfig>;
|
52
|
+
export {};
|
53
|
+
//# sourceMappingURL=config.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC;;GAEG;AACH,KAAK,aAAa,GAAG;IAAE,CAAC,UAAU,CAAC,IAAI,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;CAAE,CAAC;AAE9D;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,qBAAqB,EAAE,OAAO,EAAE,CAAC;IAEjC;;;;OAIG;IACH,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAE9B;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;IAE3E;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAAC;CACtC;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,UA0C/B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,kEAAuE,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
//# sourceMappingURL=index.federated.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.federated.d.ts","sourceRoot":"","sources":["../../src/index.federated.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,MAAM,iDAAkC,CAAC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
3
|
+
{
|
4
|
+
"tsdocVersion": "0.12",
|
5
|
+
"toolPackages": [
|
6
|
+
{
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
8
|
+
"packageVersion": "7.34.9"
|
9
|
+
}
|
10
|
+
]
|
11
|
+
}
|
@@ -0,0 +1,134 @@
|
|
1
|
+
/**
|
2
|
+
* UserAuthenticationChangeType.
|
3
|
+
* @public
|
4
|
+
*/
|
5
|
+
export declare const UserAuthenticationChangeType = "user-authentication-change";
|
6
|
+
/**
|
7
|
+
* UserAuthenticationChangeEvent.
|
8
|
+
*
|
9
|
+
* @remarks
|
10
|
+
* Detail will either be `true` or `false` to indicate authentication status.
|
11
|
+
*
|
12
|
+
* @public
|
13
|
+
*/
|
14
|
+
export type UserAuthenticationChangeEvent = CustomEvent<boolean>;
|
15
|
+
/**
|
16
|
+
* UserPathHistory.
|
17
|
+
*
|
18
|
+
* @remarks
|
19
|
+
* APIs to track a user's path history. Includes the pathname, search and hash only.
|
20
|
+
* This is not intended proxy or replace the History API.
|
21
|
+
*
|
22
|
+
* @privateRemarks
|
23
|
+
* Integrate with foundation analytics? Users could then simply call `user.trackPath` and we could engage analytics.
|
24
|
+
* We should move analytics out of comms first.
|
25
|
+
*
|
26
|
+
* @public
|
27
|
+
*/
|
28
|
+
export interface UserPathHistory {
|
29
|
+
/**
|
30
|
+
* Array of paths that have been tracked.
|
31
|
+
*/
|
32
|
+
readonly pathHistory: string[];
|
33
|
+
/**
|
34
|
+
* Track current path.
|
35
|
+
*/
|
36
|
+
trackPath(): string;
|
37
|
+
/**
|
38
|
+
* Clears path history.
|
39
|
+
*/
|
40
|
+
clearPaths(): void;
|
41
|
+
/**
|
42
|
+
* May be used to return to a target path after authentication.
|
43
|
+
* @returns The last stored path.
|
44
|
+
*/
|
45
|
+
lastPath(): string | undefined;
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* UserActionHistory.
|
49
|
+
*
|
50
|
+
* @remarks
|
51
|
+
* APIs to track a user's action history.
|
52
|
+
*
|
53
|
+
* @privateRemarks
|
54
|
+
* Integrate with foundation analytics? Users could then simply call `user.trackAction` and we could engage analytics.
|
55
|
+
* We should move analytics out of comms first.
|
56
|
+
*
|
57
|
+
* @public
|
58
|
+
*/
|
59
|
+
export interface UserActionHistory {
|
60
|
+
/**
|
61
|
+
* Array of actions that have been tracked.
|
62
|
+
*/
|
63
|
+
readonly actionHistory: unknown[];
|
64
|
+
/**
|
65
|
+
* Track an action.
|
66
|
+
*/
|
67
|
+
trackAction<TDetails = unknown>(details: TDetails): void;
|
68
|
+
/**
|
69
|
+
* Clears action history.
|
70
|
+
*/
|
71
|
+
clearActions(): void;
|
72
|
+
/**
|
73
|
+
* @returns The last stored action.
|
74
|
+
*/
|
75
|
+
lastAction(): unknown;
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* @public
|
79
|
+
*/
|
80
|
+
export interface UserKVsProperty {
|
81
|
+
readonly [key: string]: any;
|
82
|
+
}
|
83
|
+
/**
|
84
|
+
* @public
|
85
|
+
*/
|
86
|
+
export interface UserDetailsSystemProperty {
|
87
|
+
readonly date: string;
|
88
|
+
readonly [key: string]: any;
|
89
|
+
}
|
90
|
+
/**
|
91
|
+
* @public
|
92
|
+
*/
|
93
|
+
export interface UserDetailsProductProperty {
|
94
|
+
readonly name: string;
|
95
|
+
readonly version: string;
|
96
|
+
readonly [key: string]: any;
|
97
|
+
}
|
98
|
+
/**
|
99
|
+
* @public
|
100
|
+
*/
|
101
|
+
export interface UserQueueProperties {
|
102
|
+
readonly updateQueue: string;
|
103
|
+
readonly zeroMqProxyModeEnabled: boolean;
|
104
|
+
readonly zeroMqProxyInboundPort: number;
|
105
|
+
readonly zeroMqProxyOutboundPort: number;
|
106
|
+
}
|
107
|
+
/**
|
108
|
+
* @public
|
109
|
+
*/
|
110
|
+
export interface UserDetailsProperty {
|
111
|
+
readonly system: UserDetailsSystemProperty;
|
112
|
+
readonly product: UserDetailsProductProperty[];
|
113
|
+
readonly heartbeatIntervalSecs: number;
|
114
|
+
readonly failedLoginAttempts: number;
|
115
|
+
readonly rejectedLoginAttempts: number;
|
116
|
+
readonly lastLoginDatetime: number;
|
117
|
+
readonly daysToPasswordExpiry: number;
|
118
|
+
readonly [key: string]: any;
|
119
|
+
}
|
120
|
+
/**
|
121
|
+
* SetUserProperties is a partial match of `LoginAck` from `@genesislcap/foundation-auth`.
|
122
|
+
*
|
123
|
+
* @public
|
124
|
+
*/
|
125
|
+
export interface SetUserProperties extends Partial<UserQueueProperties> {
|
126
|
+
readonly sourceRef: string;
|
127
|
+
readonly userName: string;
|
128
|
+
readonly userKVs: UserKVsProperty;
|
129
|
+
readonly details: UserDetailsProperty;
|
130
|
+
readonly permission: string[];
|
131
|
+
readonly profile: string[];
|
132
|
+
readonly [key: string]: any;
|
133
|
+
}
|
134
|
+
//# sourceMappingURL=types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,4BAA4B,+BAA+B,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,MAAM,6BAA6B,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;AAEj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W,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,yBAAyB,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,0BAA0B,EAAE,CAAC;IAC/C,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAkB,SAAQ,OAAO,CAAC,mBAAmB,CAAC;IACrE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CAC7B"}
|
@@ -0,0 +1,167 @@
|
|
1
|
+
import { Listener } from '@genesislcap/foundation-utils';
|
2
|
+
import { UserConfig } from './config';
|
3
|
+
import type { SetUserProperties, UserActionHistory, UserAuthenticationChangeEvent, UserPathHistory } from './types';
|
4
|
+
/**
|
5
|
+
* User interface.
|
6
|
+
*
|
7
|
+
* @remarks
|
8
|
+
* The user singleton, which always exists in either an anonymous or authenticated mode.
|
9
|
+
*
|
10
|
+
* @privateRemarks
|
11
|
+
* Provides `username` and `userName` for backwards compatability.
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* ```ts
|
15
|
+
* import { User } from '@genesislcap/foundation-user';
|
16
|
+
* ...
|
17
|
+
* @User private user: User
|
18
|
+
* ```
|
19
|
+
*
|
20
|
+
* @public
|
21
|
+
*/
|
22
|
+
export interface User extends UserPathHistory, UserActionHistory {
|
23
|
+
readonly isAuthenticated: boolean;
|
24
|
+
readonly isAnonymous: boolean;
|
25
|
+
readonly userKVs: {
|
26
|
+
[key: string]: any;
|
27
|
+
};
|
28
|
+
readonly details: SetUserProperties['details'];
|
29
|
+
readonly permission: string[];
|
30
|
+
readonly profile: string[];
|
31
|
+
readonly sourceRef: string;
|
32
|
+
readonly userName: string;
|
33
|
+
readonly username: string;
|
34
|
+
/**
|
35
|
+
* A structuredClone of the raw unmanaged properties used to set the user.
|
36
|
+
*
|
37
|
+
* @remarks
|
38
|
+
* This offers developers an escape hatch to the raw properties. If you feel there's a gap in the User interface based
|
39
|
+
* on your application requirements, please raise a request for such properties to be moved onto the interface.
|
40
|
+
*/
|
41
|
+
readonly rawProperties: Partial<SetUserProperties>;
|
42
|
+
/**
|
43
|
+
* @param properties - The UserProperties used to populate the User.
|
44
|
+
*/
|
45
|
+
set(properties: Partial<SetUserProperties>): User;
|
46
|
+
unset(): User;
|
47
|
+
isAdmin(): boolean;
|
48
|
+
isBanned(): boolean;
|
49
|
+
/**
|
50
|
+
* @param permission - A permission string or an array of permission strings to check.
|
51
|
+
*/
|
52
|
+
hasPermission(permission: string | string[]): boolean;
|
53
|
+
/**
|
54
|
+
* @param profile - A profile string or an array of profile strings to check.
|
55
|
+
*/
|
56
|
+
hasProfile(profile: string | string[]): boolean;
|
57
|
+
/**
|
58
|
+
* @example
|
59
|
+
* ```ts
|
60
|
+
* import type { UserAuthenticationChangeEvent } from '@genesislcap/foundation-user';
|
61
|
+
* ...
|
62
|
+
* const unsubscribe = this.user.addAuthenticationChangeListener((event: UserAuthenticationChangeEvent) => {
|
63
|
+
* console.log('User authenticated?', event.detail);
|
64
|
+
* });
|
65
|
+
* ```
|
66
|
+
*
|
67
|
+
* @param listener - A listener function.
|
68
|
+
*/
|
69
|
+
addAuthenticationChangeListener(listener: Listener<UserAuthenticationChangeEvent>): () => void;
|
70
|
+
clearTrackingHistory(): void;
|
71
|
+
}
|
72
|
+
/**
|
73
|
+
* Default User implementation.
|
74
|
+
* @public
|
75
|
+
*/
|
76
|
+
export declare class DefaultUser implements User {
|
77
|
+
/** @internal */
|
78
|
+
protected config: UserConfig;
|
79
|
+
/** {@inheritDoc UserPathHistory.pathHistory} */
|
80
|
+
pathHistory: string[];
|
81
|
+
/** {@inheritDoc UserActionHistory.actionHistory} */
|
82
|
+
actionHistory: unknown[];
|
83
|
+
/** {@inheritDoc User.isAuthenticated} */
|
84
|
+
isAuthenticated: boolean;
|
85
|
+
/** {@inheritDoc User.userKVs} */
|
86
|
+
userKVs: {
|
87
|
+
[key: string]: any;
|
88
|
+
};
|
89
|
+
/** {@inheritDoc User.details} */
|
90
|
+
details: SetUserProperties['details'];
|
91
|
+
/** {@inheritDoc User.permission} */
|
92
|
+
permission: string[];
|
93
|
+
/** {@inheritDoc User.profile} */
|
94
|
+
profile: string[];
|
95
|
+
/** {@inheritDoc User.sourceRef} */
|
96
|
+
sourceRef: string;
|
97
|
+
/** {@inheritDoc User.userName} */
|
98
|
+
userName: string;
|
99
|
+
/** {@inheritDoc User.rawProperties} */
|
100
|
+
rawProperties: Partial<SetUserProperties>;
|
101
|
+
/** {@inheritDoc User.set} */
|
102
|
+
set(properties: Partial<SetUserProperties>): User;
|
103
|
+
/** {@inheritDoc User.unset} */
|
104
|
+
unset(): User;
|
105
|
+
/** @internal */
|
106
|
+
protected userNameChanged(): void;
|
107
|
+
/** {@inheritDoc User.username} */
|
108
|
+
get username(): string;
|
109
|
+
/** {@inheritDoc User.isAnonymous} */
|
110
|
+
get isAnonymous(): boolean;
|
111
|
+
/** {@inheritDoc User.isAdmin} */
|
112
|
+
isAdmin(): boolean;
|
113
|
+
/** {@inheritDoc User.isBanned} */
|
114
|
+
isBanned(): boolean;
|
115
|
+
/** {@inheritDoc User.hasPermission} */
|
116
|
+
hasPermission(permission: string | string[]): boolean;
|
117
|
+
/** {@inheritDoc User.hasProfile} */
|
118
|
+
hasProfile(profile: string | string[]): boolean;
|
119
|
+
/** {@inheritDoc UserPathHistory.trackPath} */
|
120
|
+
trackPath(): string;
|
121
|
+
/** {@inheritDoc UserPathHistory.clearPaths} */
|
122
|
+
clearPaths(): void;
|
123
|
+
/** {@inheritDoc UserPathHistory.lastPath} */
|
124
|
+
lastPath(): string;
|
125
|
+
/** {@inheritDoc UserActionHistory.trackAction} */
|
126
|
+
trackAction<TDetails = unknown>(details: TDetails): void;
|
127
|
+
/** {@inheritDoc UserActionHistory.clearActions} */
|
128
|
+
clearActions(): void;
|
129
|
+
/** {@inheritDoc UserActionHistory.lastAction} */
|
130
|
+
lastAction(): unknown;
|
131
|
+
/** {@inheritDoc User.clearTrackingHistory} */
|
132
|
+
clearTrackingHistory(): void;
|
133
|
+
/** @internal */
|
134
|
+
protected hasKey(keys: string[], key: string | string[]): boolean;
|
135
|
+
/** @internal */
|
136
|
+
protected authenticationChangeListeners: import("@genesislcap/foundation-utils").Observer<UserAuthenticationChangeEvent>;
|
137
|
+
/** {@inheritDoc User.addAuthenticationChangeListener} */
|
138
|
+
addAuthenticationChangeListener(listener: Listener<UserAuthenticationChangeEvent>): () => void;
|
139
|
+
/** @internal */
|
140
|
+
protected isAuthenticatedChanged(): void;
|
141
|
+
}
|
142
|
+
/**
|
143
|
+
* User DI key.
|
144
|
+
*
|
145
|
+
* @privateRemarks
|
146
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
147
|
+
*
|
148
|
+
* @internal
|
149
|
+
*/
|
150
|
+
export declare const User: import("@microsoft/fast-foundation").InterfaceSymbol<User>;
|
151
|
+
/**
|
152
|
+
* Gets User from the DI container.
|
153
|
+
*
|
154
|
+
* @remarks
|
155
|
+
* A utility method for host applications that are not using decorators or the DI container.
|
156
|
+
*
|
157
|
+
* @example
|
158
|
+
* ```ts
|
159
|
+
* import { getUser, User } from '@genesislcap/foundation-user';
|
160
|
+
* ...
|
161
|
+
* private user: User = getUser();
|
162
|
+
* ```
|
163
|
+
*
|
164
|
+
* @public
|
165
|
+
*/
|
166
|
+
export declare function getUser(): User;
|
167
|
+
//# sourceMappingURL=user.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAGzE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,6BAA6B,EAC7B,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,IAAK,SAAQ,eAAe,EAAE,iBAAiB;IAC9D,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,CAAC;IACzC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;;;;OAMG;IACH,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnD;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;IAClD,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,IAA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Q,WAGX;IAED,qCAAqC;IACrC,IAAI,WAAW,YAEd;IAED,iCAAiC;IACjC,OAAO;IAIP,kCAAkC;IAClC,QAAQ;IAIR,uCAAuC;IACvC,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IAI3C,oCAAoC;IACpC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAIrC,8CAA8C;IAC9C,SAAS;IAWT,+CAA+C;IAC/C,UAAU;IAIV,6CAA6C;IAC7C,QAAQ;IAKR,kDAAkD;IAClD,WAAW,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,EAAE,QAAQ;IAOjD,mDAAmD;IACnD,YAAY;IAIZ,iDAAiD;IACjD,UAAU;IAKV,8CAA8C;IAC9C,oBAAoB;IAKpB,gBAAgB;IAChB,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE;IAUvD,gBAAgB;IAChB,SAAS,CAAC,6BAA6B,kFAAmD;IAE1F,yDAAyD;IACzD,+BAA+B,CAAC,QAAQ,EAAE,QAAQ,CAAC,6BAA6B,CAAC;IAIjF,gBAAgB;IAChB,SAAS,CAAC,sBAAsB;CAOjC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,4DAA4D,CAAC;AAE9E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAE9B"}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
2
|
+
import { logger } from './logger';
|
3
|
+
/**
|
4
|
+
* Default UserConfig DI implementation.
|
5
|
+
* @public
|
6
|
+
*/
|
7
|
+
export const defaultUserConfig = {
|
8
|
+
trackActionExclusions: [],
|
9
|
+
trackPathExclusions: [''],
|
10
|
+
setUser(user, properties) {
|
11
|
+
if (user.isAuthenticated) {
|
12
|
+
throw new Error(`User already set. If this is intentional, please call User.unset first.`);
|
13
|
+
}
|
14
|
+
logger.debug('setUser', properties);
|
15
|
+
/**
|
16
|
+
* Create a clone of the raw properties.
|
17
|
+
*/
|
18
|
+
user.rawProperties = structuredClone(properties);
|
19
|
+
/**
|
20
|
+
* Set managed properties
|
21
|
+
*/
|
22
|
+
user.userKVs = properties.userKVs;
|
23
|
+
user.details = properties.details;
|
24
|
+
user.permission = properties.permission;
|
25
|
+
user.profile = properties.profile;
|
26
|
+
user.sourceRef = properties.sourceRef;
|
27
|
+
user.userName = properties.userName;
|
28
|
+
user.isAuthenticated = true;
|
29
|
+
return user;
|
30
|
+
},
|
31
|
+
unsetUser(user) {
|
32
|
+
logger.debug('unsetUser');
|
33
|
+
/**
|
34
|
+
* Unset raw properties ref
|
35
|
+
*/
|
36
|
+
user.rawProperties = undefined;
|
37
|
+
/**
|
38
|
+
* Unset managed properties
|
39
|
+
*/
|
40
|
+
user.userKVs = undefined;
|
41
|
+
user.details = undefined;
|
42
|
+
user.permission = undefined;
|
43
|
+
user.profile = undefined;
|
44
|
+
user.sourceRef = undefined;
|
45
|
+
user.userName = undefined;
|
46
|
+
user.isAuthenticated = false;
|
47
|
+
return user;
|
48
|
+
},
|
49
|
+
};
|
50
|
+
/**
|
51
|
+
* UserConfig DI key.
|
52
|
+
*
|
53
|
+
* @internal
|
54
|
+
* @privateRemarks
|
55
|
+
* Marked as internal to stop api-extractor becoming confused cross-linking tokens with the same name.
|
56
|
+
*/
|
57
|
+
export const UserConfig = DI.createInterface((x) => x.instance(defaultUserConfig));
|
@@ -0,0 +1 @@
|
|
1
|
+
import('./index');
|