@genesislcap/foundation-user 14.137.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. package/README.md +43 -0
  2. package/dist/dts/config.d.ts +53 -0
  3. package/dist/dts/config.d.ts.map +1 -0
  4. package/dist/dts/index.d.ts +5 -0
  5. package/dist/dts/index.d.ts.map +1 -0
  6. package/dist/dts/index.federated.d.ts +1 -0
  7. package/dist/dts/index.federated.d.ts.map +1 -0
  8. package/dist/dts/logger.d.ts +5 -0
  9. package/dist/dts/logger.d.ts.map +1 -0
  10. package/dist/dts/tsdoc-metadata.json +11 -0
  11. package/dist/dts/types.d.ts +134 -0
  12. package/dist/dts/types.d.ts.map +1 -0
  13. package/dist/dts/user.d.ts +167 -0
  14. package/dist/dts/user.d.ts.map +1 -0
  15. package/dist/esm/config.js +57 -0
  16. package/dist/esm/index.federated.js +1 -0
  17. package/dist/esm/index.js +4 -0
  18. package/dist/esm/logger.js +5 -0
  19. package/dist/esm/types.js +5 -0
  20. package/dist/esm/user.js +182 -0
  21. package/dist/foundation-user.api.json +3350 -0
  22. package/dist/foundation-user.d.ts +374 -0
  23. package/docs/.gitattributes +2 -0
  24. package/docs/api/foundation-user.defaultuser.actionhistory.md +13 -0
  25. package/docs/api/foundation-user.defaultuser.addauthenticationchangelistener.md +22 -0
  26. package/docs/api/foundation-user.defaultuser.clearactions.md +17 -0
  27. package/docs/api/foundation-user.defaultuser.clearpaths.md +17 -0
  28. package/docs/api/foundation-user.defaultuser.cleartrackinghistory.md +16 -0
  29. package/docs/api/foundation-user.defaultuser.details.md +12 -0
  30. package/docs/api/foundation-user.defaultuser.haspermission.md +22 -0
  31. package/docs/api/foundation-user.defaultuser.hasprofile.md +22 -0
  32. package/docs/api/foundation-user.defaultuser.isadmin.md +16 -0
  33. package/docs/api/foundation-user.defaultuser.isanonymous.md +12 -0
  34. package/docs/api/foundation-user.defaultuser.isauthenticated.md +12 -0
  35. package/docs/api/foundation-user.defaultuser.isbanned.md +16 -0
  36. package/docs/api/foundation-user.defaultuser.lastaction.md +17 -0
  37. package/docs/api/foundation-user.defaultuser.lastpath.md +19 -0
  38. package/docs/api/foundation-user.defaultuser.md +51 -0
  39. package/docs/api/foundation-user.defaultuser.pathhistory.md +13 -0
  40. package/docs/api/foundation-user.defaultuser.permission.md +12 -0
  41. package/docs/api/foundation-user.defaultuser.profile.md +12 -0
  42. package/docs/api/foundation-user.defaultuser.rawproperties.md +18 -0
  43. package/docs/api/foundation-user.defaultuser.set.md +22 -0
  44. package/docs/api/foundation-user.defaultuser.sourceref.md +12 -0
  45. package/docs/api/foundation-user.defaultuser.trackaction.md +24 -0
  46. package/docs/api/foundation-user.defaultuser.trackpath.md +17 -0
  47. package/docs/api/foundation-user.defaultuser.unset.md +16 -0
  48. package/docs/api/foundation-user.defaultuser.userkvs.md +14 -0
  49. package/docs/api/foundation-user.defaultuser.username.md +12 -0
  50. package/docs/api/foundation-user.defaultuserconfig.md +13 -0
  51. package/docs/api/foundation-user.getuser.md +30 -0
  52. package/docs/api/foundation-user.logger.md +12 -0
  53. package/docs/api/foundation-user.md +47 -0
  54. package/docs/api/foundation-user.setuserproperties.details.md +11 -0
  55. package/docs/api/foundation-user.setuserproperties.md +26 -0
  56. package/docs/api/foundation-user.setuserproperties.permission.md +11 -0
  57. package/docs/api/foundation-user.setuserproperties.profile.md +11 -0
  58. package/docs/api/foundation-user.setuserproperties.sourceref.md +11 -0
  59. package/docs/api/foundation-user.setuserproperties.userkvs.md +11 -0
  60. package/docs/api/foundation-user.setuserproperties.username.md +11 -0
  61. package/docs/api/foundation-user.user.addauthenticationchangelistener.md +33 -0
  62. package/docs/api/foundation-user.user.cleartrackinghistory.md +15 -0
  63. package/docs/api/foundation-user.user.details.md +11 -0
  64. package/docs/api/foundation-user.user.haspermission.md +22 -0
  65. package/docs/api/foundation-user.user.hasprofile.md +22 -0
  66. package/docs/api/foundation-user.user.isadmin.md +15 -0
  67. package/docs/api/foundation-user.user.isanonymous.md +11 -0
  68. package/docs/api/foundation-user.user.isauthenticated.md +11 -0
  69. package/docs/api/foundation-user.user.isbanned.md +15 -0
  70. package/docs/api/foundation-user.user.md +56 -0
  71. package/docs/api/foundation-user.user.permission.md +11 -0
  72. package/docs/api/foundation-user.user.profile.md +11 -0
  73. package/docs/api/foundation-user.user.rawproperties.md +18 -0
  74. package/docs/api/foundation-user.user.set.md +22 -0
  75. package/docs/api/foundation-user.user.sourceref.md +11 -0
  76. package/docs/api/foundation-user.user.unset.md +15 -0
  77. package/docs/api/foundation-user.user.userkvs.md +13 -0
  78. package/docs/api/foundation-user.user.username.md +11 -0
  79. package/docs/api/foundation-user.useractionhistory.actionhistory.md +13 -0
  80. package/docs/api/foundation-user.useractionhistory.clearactions.md +17 -0
  81. package/docs/api/foundation-user.useractionhistory.lastaction.md +17 -0
  82. package/docs/api/foundation-user.useractionhistory.md +32 -0
  83. package/docs/api/foundation-user.useractionhistory.trackaction.md +24 -0
  84. package/docs/api/foundation-user.userauthenticationchangeevent.md +18 -0
  85. package/docs/api/foundation-user.userauthenticationchangetype.md +13 -0
  86. package/docs/api/foundation-user.userconfig.md +28 -0
  87. package/docs/api/foundation-user.userconfig.setuser.md +29 -0
  88. package/docs/api/foundation-user.userconfig.trackactionexclusions.md +15 -0
  89. package/docs/api/foundation-user.userconfig.trackpathexclusions.md +15 -0
  90. package/docs/api/foundation-user.userconfig.unsetuser.md +24 -0
  91. package/docs/api/foundation-user.userdetailsproductproperty.md +20 -0
  92. package/docs/api/foundation-user.userdetailsproductproperty.name.md +11 -0
  93. package/docs/api/foundation-user.userdetailsproductproperty.version.md +11 -0
  94. package/docs/api/foundation-user.userdetailsproperty.daystopasswordexpiry.md +11 -0
  95. package/docs/api/foundation-user.userdetailsproperty.failedloginattempts.md +11 -0
  96. package/docs/api/foundation-user.userdetailsproperty.heartbeatintervalsecs.md +11 -0
  97. package/docs/api/foundation-user.userdetailsproperty.lastlogindatetime.md +11 -0
  98. package/docs/api/foundation-user.userdetailsproperty.md +25 -0
  99. package/docs/api/foundation-user.userdetailsproperty.product.md +11 -0
  100. package/docs/api/foundation-user.userdetailsproperty.rejectedloginattempts.md +11 -0
  101. package/docs/api/foundation-user.userdetailsproperty.system.md +11 -0
  102. package/docs/api/foundation-user.userdetailssystemproperty.date.md +11 -0
  103. package/docs/api/foundation-user.userdetailssystemproperty.md +19 -0
  104. package/docs/api/foundation-user.userkvsproperty.md +12 -0
  105. package/docs/api/foundation-user.userpathhistory.clearpaths.md +17 -0
  106. package/docs/api/foundation-user.userpathhistory.lastpath.md +19 -0
  107. package/docs/api/foundation-user.userpathhistory.md +32 -0
  108. package/docs/api/foundation-user.userpathhistory.pathhistory.md +13 -0
  109. package/docs/api/foundation-user.userpathhistory.trackpath.md +17 -0
  110. package/docs/api/foundation-user.userqueueproperties.md +22 -0
  111. package/docs/api/foundation-user.userqueueproperties.updatequeue.md +11 -0
  112. package/docs/api/foundation-user.userqueueproperties.zeromqproxyinboundport.md +11 -0
  113. package/docs/api/foundation-user.userqueueproperties.zeromqproxymodeenabled.md +11 -0
  114. package/docs/api/foundation-user.userqueueproperties.zeromqproxyoutboundport.md +11 -0
  115. package/docs/api/index.md +12 -0
  116. package/docs/api-report.md +277 -0
  117. package/license.txt +46 -0
  118. package/package.json +48 -0
@@ -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
+ }