@kwiz/common 1.0.95 → 1.0.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/.github/workflows/npm-publish.yml +24 -24
  2. package/.madgerc +2 -2
  3. package/LICENSE +21 -21
  4. package/fix-folder-imports.js +26 -26
  5. package/lib/cjs/types/libs/msal.types.js +26 -26
  6. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  7. package/lib/esm/types/libs/msal.types.js +26 -26
  8. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  9. package/package.json +81 -81
  10. package/readme.md +17 -17
  11. package/src/_dependencies.ts +12 -12
  12. package/src/config.ts +17 -17
  13. package/src/helpers/Guid.ts +181 -181
  14. package/src/helpers/base64.ts +173 -173
  15. package/src/helpers/browser.test.js +13 -13
  16. package/src/helpers/browser.ts +1399 -1399
  17. package/src/helpers/browserinfo.ts +292 -292
  18. package/src/helpers/collections.base.test.js +25 -25
  19. package/src/helpers/collections.base.ts +437 -437
  20. package/src/helpers/collections.ts +107 -107
  21. package/src/helpers/color.ts +54 -54
  22. package/src/helpers/cookies.ts +59 -59
  23. package/src/helpers/date.test.js +119 -119
  24. package/src/helpers/date.ts +188 -188
  25. package/src/helpers/debug.ts +186 -186
  26. package/src/helpers/diagrams.ts +43 -43
  27. package/src/helpers/emails.ts +6 -6
  28. package/src/helpers/eval.ts +5 -5
  29. package/src/helpers/file.test.js +50 -50
  30. package/src/helpers/file.ts +60 -60
  31. package/src/helpers/flatted.ts +149 -149
  32. package/src/helpers/functions.ts +16 -16
  33. package/src/helpers/graph/calendar.types.ts +10 -10
  34. package/src/helpers/http.ts +69 -69
  35. package/src/helpers/images.ts +22 -22
  36. package/src/helpers/json.ts +38 -38
  37. package/src/helpers/md5.ts +189 -189
  38. package/src/helpers/objects.test.js +33 -33
  39. package/src/helpers/objects.ts +274 -274
  40. package/src/helpers/promises.test.js +37 -37
  41. package/src/helpers/promises.ts +165 -165
  42. package/src/helpers/random.ts +27 -27
  43. package/src/helpers/scheduler/scheduler.test.js +103 -103
  44. package/src/helpers/scheduler/scheduler.ts +131 -131
  45. package/src/helpers/sharepoint.ts +776 -776
  46. package/src/helpers/strings.test.js +101 -101
  47. package/src/helpers/strings.ts +317 -317
  48. package/src/helpers/typecheckers.test.js +34 -34
  49. package/src/helpers/typecheckers.ts +266 -266
  50. package/src/helpers/url.test.js +43 -43
  51. package/src/helpers/url.ts +207 -207
  52. package/src/helpers/urlhelper.ts +111 -111
  53. package/src/index.ts +6 -6
  54. package/src/types/auth.ts +54 -54
  55. package/src/types/common.types.ts +15 -15
  56. package/src/types/flatted.types.ts +59 -59
  57. package/src/types/globals.types.ts +6 -6
  58. package/src/types/graph/calendar.types.ts +80 -80
  59. package/src/types/knownscript.types.ts +18 -18
  60. package/src/types/libs/datajs.types.ts +28 -28
  61. package/src/types/libs/ics.types.ts +30 -30
  62. package/src/types/libs/msal.types.ts +49 -49
  63. package/src/types/locales.ts +124 -124
  64. package/src/types/localstoragecache.types.ts +8 -8
  65. package/src/types/location.types.ts +27 -27
  66. package/src/types/moment.ts +11 -11
  67. package/src/types/regex.types.ts +16 -16
  68. package/src/types/rest.types.ts +95 -95
  69. package/src/types/sharepoint.types.ts +1465 -1465
  70. package/src/types/sharepoint.utils.types.ts +287 -287
  71. package/src/utils/auth/common.ts +74 -74
  72. package/src/utils/auth/discovery.test.js +12 -12
  73. package/src/utils/auth/discovery.ts +132 -132
  74. package/src/utils/base64.ts +27 -27
  75. package/src/utils/consolelogger.ts +320 -320
  76. package/src/utils/date.ts +35 -35
  77. package/src/utils/emails.ts +24 -24
  78. package/src/utils/knownscript.ts +286 -286
  79. package/src/utils/localstoragecache.ts +441 -441
  80. package/src/utils/rest.ts +501 -501
  81. package/src/utils/script.ts +170 -170
  82. package/src/utils/sharepoint.rest/common.ts +154 -154
  83. package/src/utils/sharepoint.rest/date.ts +62 -62
  84. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  85. package/src/utils/sharepoint.rest/item.ts +547 -547
  86. package/src/utils/sharepoint.rest/list.ts +1480 -1480
  87. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  88. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  89. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  90. package/src/utils/sharepoint.rest/location.ts +141 -141
  91. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  92. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  93. package/src/utils/sharepoint.rest/user.ts +491 -491
  94. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  95. package/src/utils/sod.ts +194 -194
@@ -1,253 +1,253 @@
1
- import { firstIndexOf } from "../../helpers/collections.base";
2
- import { contentTypes, jsonTypes } from "../../types/rest.types";
3
- import { PrincipalType } from "../../types/sharepoint.types";
4
- import { IUserInfo } from "../../types/sharepoint.utils.types";
5
- import { GetJson } from "../rest";
6
- import { EnsureUser } from "./user";
7
-
8
- export interface iPeoplePickerUserItem {
9
- /** LoginName or Id of the principal in the site. */
10
- id: string;
11
- /** LoginName of the principal. */
12
- loginName: string;
13
- imageUrl: string;
14
- imageInitials: string;
15
- text: string; // name
16
- secondaryText: string; // role
17
- tertiaryText: string; // status
18
- optionalText: string; // anything
19
- }
20
- /**
21
- * Service implementation to search people in SharePoint
22
- */
23
- export class SPPeopleSearchService {
24
- private cachedLocalUsers: { [siteUrl: string]: IUserInfo[] };
25
-
26
- /**
27
- * Service constructor
28
- */
29
- constructor(private context: { siteUrl }) {
30
- this.cachedLocalUsers = {};
31
- this.cachedLocalUsers[this.context.siteUrl] = [];
32
- }
33
-
34
- /**
35
- * Generate the user photo link using SharePoint user photo endpoint.
36
- *
37
- * @param value
38
- */
39
- public generateUserPhotoLink(value: string, size: "S" | "M" = "M"): string {
40
- return `${this.context.siteUrl}/_layouts/15/userphoto.aspx?accountname=${encodeURIComponent(value)}&size=M`;
41
- }
42
-
43
- /**
44
- * Generate sum of principal types
45
- *
46
- * PrincipalType controls the type of entities that are returned in the results.
47
- * Choices are All - 15, Distribution List - 2 , Security Groups - 4, SharePoint Groups - 8, User - 1.
48
- * These values can be combined (example: 13 is security + SP groups + users)
49
- *
50
- * @param principalTypes
51
- */
52
- public getSumOfPrincipalTypes(principalTypes: PrincipalType[]) {
53
- return !!principalTypes && principalTypes.length > 0 ? principalTypes.reduce((a, b) => a + b, 0) : 1;
54
- }
55
-
56
- /**
57
- * Retrieve the specified group
58
- *
59
- * @param groupName
60
- * @param siteUrl
61
- */
62
- public async getGroupId(groupName: string, siteUrl: string = null): Promise<number | null> {
63
- // if (Environment.type === EnvironmentType.Local) {
64
- // return 1;
65
- // } else {
66
- const groups = await this.searchTenant(siteUrl, groupName, 1, [PrincipalType.SharePointGroup], false, 0);
67
- return (groups && groups.length > 0) ? parseInt(groups[0].id) : null;
68
- //}
69
- }
70
-
71
- /**
72
- * Search person by its email or login name
73
- */
74
- public async searchPersonByEmailOrLogin(email: string, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<iPeoplePickerUserItem> {
75
- // if (Environment.type === EnvironmentType.Local) {
76
- // // If the running environment is local, load the data from the mock
77
- // const mockUsers = await this.searchPeopleFromMock(email);
78
- // return (mockUsers && mockUsers.length > 0) ? mockUsers[0] : null;
79
- // } else {
80
- const userResults = await this.searchTenant(siteUrl, email, 1, principalTypes, ensureUser, groupId);
81
- return (userResults && userResults.length > 0) ? userResults[0] : null;
82
- //}
83
- }
84
-
85
- /**
86
- * Search All Users from the SharePoint People database
87
- */
88
- public async searchPeople(query: string, maximumSuggestions: number, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<iPeoplePickerUserItem[]> {
89
- // if (Environment.type === EnvironmentType.Local) {
90
- // // If the running environment is local, load the data from the mock
91
- // return this.searchPeopleFromMock(query);
92
- // } else {
93
- return await this.searchTenant(siteUrl, query, maximumSuggestions, principalTypes, ensureUser, groupId);
94
- //}
95
- }
96
-
97
- /**
98
- * Tenant search
99
- */
100
- private async searchTenant(siteUrl: string, query: string, maximumSuggestions: number, principalTypes: PrincipalType[], ensureUser: boolean, groupId: number): Promise<iPeoplePickerUserItem[]> {
101
- try {
102
- // If the running env is SharePoint, loads from the peoplepicker web service
103
- const userRequestUrl: string = `${siteUrl || this.context.siteUrl}/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser`;
104
- const searchBody = {
105
- queryParams: {
106
- AllowEmailAddresses: true,
107
- AllowMultipleEntities: false,
108
- AllUrlZones: false,
109
- MaximumEntitySuggestions: maximumSuggestions,
110
- PrincipalSource: 15,
111
- PrincipalType: this.getSumOfPrincipalTypes(principalTypes),
112
- QueryString: query
113
- }
114
- };
115
-
116
- // Search on the local site when "0"
117
- if (siteUrl) {
118
- searchBody.queryParams["SharePointGroupID"] = 0;
119
- }
120
-
121
- // Check if users need to be searched in a specific group
122
- if (groupId) {
123
- searchBody.queryParams["SharePointGroupID"] = groupId;
124
- }
125
-
126
- // Do the call against the People REST API endpoint
127
- const userDataResp = await GetJson<{ value: string; }>(
128
- userRequestUrl,
129
- JSON.stringify(searchBody),
130
- {
131
- headers: {
132
- Accept: jsonTypes.standard,
133
- "content-type": contentTypes.json
134
- }
135
- })
136
-
137
- if (userDataResp && userDataResp.value && userDataResp.value.length > 0) {
138
- let values: any = userDataResp.value;
139
-
140
- if (typeof userDataResp.value === "string") {
141
- values = JSON.parse(userDataResp.value);
142
- }
143
-
144
- // Filter out "UNVALIDATED_EMAIL_ADDRESS"
145
- values = values.filter(v => !(v.EntityData && v.EntityData.PrincipalType && v.EntityData.PrincipalType === "UNVALIDATED_EMAIL_ADDRESS"));
146
-
147
- // Check if local user IDs need to be retrieved
148
- if (ensureUser) {
149
- for (const value of values) {
150
- // Only ensure the user if it is not a SharePoint group
151
- if (!value.EntityData || (value.EntityData && typeof value.EntityData.SPGroupID === "undefined")) {
152
- const id = await this.ensureUser(value.Key);
153
- value.LoginName = value.Key;
154
- value.Key = id;
155
- }
156
- }
157
- }
158
-
159
- // Filter out NULL keys
160
- values = values.filter(v => v.Key !== null);
161
- const userResults = values.map(element => {
162
- switch (element.EntityType) {
163
- case 'User':
164
- return {
165
- id: element.Key,
166
- loginName: element.LoginName ? element.LoginName : element.Key,
167
- imageUrl: this.generateUserPhotoLink(element.Description || ""),
168
- imageInitials: this.getFullNameInitials(element.DisplayText),
169
- text: element.DisplayText, // name
170
- secondaryText: element.EntityData.Email || element.Description, // email
171
- tertiaryText: "", // status
172
- optionalText: "" // anything
173
- } as iPeoplePickerUserItem;
174
- case 'SecGroup':
175
- return {
176
- id: element.Key,
177
- loginName: element.LoginName ? element.LoginName : element.Key,
178
- imageInitials: this.getFullNameInitials(element.DisplayText),
179
- text: element.DisplayText,
180
- secondaryText: element.ProviderName
181
- } as iPeoplePickerUserItem;
182
- case 'FormsRole':
183
- return {
184
- id: element.Key,
185
- loginName: element.LoginName ? element.LoginName : element.Key,
186
- imageInitials: this.getFullNameInitials(element.DisplayText),
187
- text: element.DisplayText,
188
- secondaryText: element.ProviderName
189
- } as iPeoplePickerUserItem;
190
- default:
191
- return {
192
- id: element.EntityData.SPGroupID,
193
- loginName: element.EntityData.AccountName,
194
- imageInitials: this.getFullNameInitials(element.DisplayText),
195
- text: element.DisplayText,
196
- secondaryText: element.EntityData.AccountName
197
- } as iPeoplePickerUserItem;
198
- }
199
- });
200
-
201
- return userResults;
202
- }
203
-
204
-
205
- // Nothing to return
206
- return [];
207
- } catch (e) {
208
- console.error("PeopleSearchService::searchTenant: error occured while fetching the users.");
209
- return [];
210
- }
211
- }
212
-
213
- /**
214
- * Retrieves the local user ID
215
- *
216
- * @param userId
217
- */
218
- private async ensureUser(userId: string): Promise<number> {
219
- const siteUrl = this.context.siteUrl;
220
- if (this.cachedLocalUsers && this.cachedLocalUsers[siteUrl]) {
221
- const users = this.cachedLocalUsers[siteUrl];
222
- const userIdx = firstIndexOf(users, u => u.LoginName === userId);
223
- if (userIdx !== -1) {
224
- return users[userIdx].Id;
225
- }
226
- }
227
-
228
- const user = await EnsureUser(siteUrl, userId)
229
- if (user && user.Id) {
230
- this.cachedLocalUsers[siteUrl].push(user);
231
- return user.Id;
232
- }
233
- return null;
234
- }
235
-
236
- /**
237
- * Generates Initials from a full name
238
- */
239
- private getFullNameInitials(fullName: string): string {
240
- if (fullName === null) {
241
- return fullName;
242
- }
243
-
244
- const words: string[] = fullName.split(' ');
245
- if (words.length === 0) {
246
- return '';
247
- } else if (words.length === 1) {
248
- return words[0].charAt(0);
249
- } else {
250
- return (words[0].charAt(0) + words[1].charAt(0));
251
- }
252
- }
1
+ import { firstIndexOf } from "../../helpers/collections.base";
2
+ import { contentTypes, jsonTypes } from "../../types/rest.types";
3
+ import { PrincipalType } from "../../types/sharepoint.types";
4
+ import { IUserInfo } from "../../types/sharepoint.utils.types";
5
+ import { GetJson } from "../rest";
6
+ import { EnsureUser } from "./user";
7
+
8
+ export interface iPeoplePickerUserItem {
9
+ /** LoginName or Id of the principal in the site. */
10
+ id: string;
11
+ /** LoginName of the principal. */
12
+ loginName: string;
13
+ imageUrl: string;
14
+ imageInitials: string;
15
+ text: string; // name
16
+ secondaryText: string; // role
17
+ tertiaryText: string; // status
18
+ optionalText: string; // anything
19
+ }
20
+ /**
21
+ * Service implementation to search people in SharePoint
22
+ */
23
+ export class SPPeopleSearchService {
24
+ private cachedLocalUsers: { [siteUrl: string]: IUserInfo[] };
25
+
26
+ /**
27
+ * Service constructor
28
+ */
29
+ constructor(private context: { siteUrl }) {
30
+ this.cachedLocalUsers = {};
31
+ this.cachedLocalUsers[this.context.siteUrl] = [];
32
+ }
33
+
34
+ /**
35
+ * Generate the user photo link using SharePoint user photo endpoint.
36
+ *
37
+ * @param value
38
+ */
39
+ public generateUserPhotoLink(value: string, size: "S" | "M" = "M"): string {
40
+ return `${this.context.siteUrl}/_layouts/15/userphoto.aspx?accountname=${encodeURIComponent(value)}&size=M`;
41
+ }
42
+
43
+ /**
44
+ * Generate sum of principal types
45
+ *
46
+ * PrincipalType controls the type of entities that are returned in the results.
47
+ * Choices are All - 15, Distribution List - 2 , Security Groups - 4, SharePoint Groups - 8, User - 1.
48
+ * These values can be combined (example: 13 is security + SP groups + users)
49
+ *
50
+ * @param principalTypes
51
+ */
52
+ public getSumOfPrincipalTypes(principalTypes: PrincipalType[]) {
53
+ return !!principalTypes && principalTypes.length > 0 ? principalTypes.reduce((a, b) => a + b, 0) : 1;
54
+ }
55
+
56
+ /**
57
+ * Retrieve the specified group
58
+ *
59
+ * @param groupName
60
+ * @param siteUrl
61
+ */
62
+ public async getGroupId(groupName: string, siteUrl: string = null): Promise<number | null> {
63
+ // if (Environment.type === EnvironmentType.Local) {
64
+ // return 1;
65
+ // } else {
66
+ const groups = await this.searchTenant(siteUrl, groupName, 1, [PrincipalType.SharePointGroup], false, 0);
67
+ return (groups && groups.length > 0) ? parseInt(groups[0].id) : null;
68
+ //}
69
+ }
70
+
71
+ /**
72
+ * Search person by its email or login name
73
+ */
74
+ public async searchPersonByEmailOrLogin(email: string, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<iPeoplePickerUserItem> {
75
+ // if (Environment.type === EnvironmentType.Local) {
76
+ // // If the running environment is local, load the data from the mock
77
+ // const mockUsers = await this.searchPeopleFromMock(email);
78
+ // return (mockUsers && mockUsers.length > 0) ? mockUsers[0] : null;
79
+ // } else {
80
+ const userResults = await this.searchTenant(siteUrl, email, 1, principalTypes, ensureUser, groupId);
81
+ return (userResults && userResults.length > 0) ? userResults[0] : null;
82
+ //}
83
+ }
84
+
85
+ /**
86
+ * Search All Users from the SharePoint People database
87
+ */
88
+ public async searchPeople(query: string, maximumSuggestions: number, principalTypes: PrincipalType[], siteUrl: string = null, groupId: number = null, ensureUser: boolean = false): Promise<iPeoplePickerUserItem[]> {
89
+ // if (Environment.type === EnvironmentType.Local) {
90
+ // // If the running environment is local, load the data from the mock
91
+ // return this.searchPeopleFromMock(query);
92
+ // } else {
93
+ return await this.searchTenant(siteUrl, query, maximumSuggestions, principalTypes, ensureUser, groupId);
94
+ //}
95
+ }
96
+
97
+ /**
98
+ * Tenant search
99
+ */
100
+ private async searchTenant(siteUrl: string, query: string, maximumSuggestions: number, principalTypes: PrincipalType[], ensureUser: boolean, groupId: number): Promise<iPeoplePickerUserItem[]> {
101
+ try {
102
+ // If the running env is SharePoint, loads from the peoplepicker web service
103
+ const userRequestUrl: string = `${siteUrl || this.context.siteUrl}/_api/SP.UI.ApplicationPages.ClientPeoplePickerWebServiceInterface.clientPeoplePickerSearchUser`;
104
+ const searchBody = {
105
+ queryParams: {
106
+ AllowEmailAddresses: true,
107
+ AllowMultipleEntities: false,
108
+ AllUrlZones: false,
109
+ MaximumEntitySuggestions: maximumSuggestions,
110
+ PrincipalSource: 15,
111
+ PrincipalType: this.getSumOfPrincipalTypes(principalTypes),
112
+ QueryString: query
113
+ }
114
+ };
115
+
116
+ // Search on the local site when "0"
117
+ if (siteUrl) {
118
+ searchBody.queryParams["SharePointGroupID"] = 0;
119
+ }
120
+
121
+ // Check if users need to be searched in a specific group
122
+ if (groupId) {
123
+ searchBody.queryParams["SharePointGroupID"] = groupId;
124
+ }
125
+
126
+ // Do the call against the People REST API endpoint
127
+ const userDataResp = await GetJson<{ value: string; }>(
128
+ userRequestUrl,
129
+ JSON.stringify(searchBody),
130
+ {
131
+ headers: {
132
+ Accept: jsonTypes.standard,
133
+ "content-type": contentTypes.json
134
+ }
135
+ })
136
+
137
+ if (userDataResp && userDataResp.value && userDataResp.value.length > 0) {
138
+ let values: any = userDataResp.value;
139
+
140
+ if (typeof userDataResp.value === "string") {
141
+ values = JSON.parse(userDataResp.value);
142
+ }
143
+
144
+ // Filter out "UNVALIDATED_EMAIL_ADDRESS"
145
+ values = values.filter(v => !(v.EntityData && v.EntityData.PrincipalType && v.EntityData.PrincipalType === "UNVALIDATED_EMAIL_ADDRESS"));
146
+
147
+ // Check if local user IDs need to be retrieved
148
+ if (ensureUser) {
149
+ for (const value of values) {
150
+ // Only ensure the user if it is not a SharePoint group
151
+ if (!value.EntityData || (value.EntityData && typeof value.EntityData.SPGroupID === "undefined")) {
152
+ const id = await this.ensureUser(value.Key);
153
+ value.LoginName = value.Key;
154
+ value.Key = id;
155
+ }
156
+ }
157
+ }
158
+
159
+ // Filter out NULL keys
160
+ values = values.filter(v => v.Key !== null);
161
+ const userResults = values.map(element => {
162
+ switch (element.EntityType) {
163
+ case 'User':
164
+ return {
165
+ id: element.Key,
166
+ loginName: element.LoginName ? element.LoginName : element.Key,
167
+ imageUrl: this.generateUserPhotoLink(element.Description || ""),
168
+ imageInitials: this.getFullNameInitials(element.DisplayText),
169
+ text: element.DisplayText, // name
170
+ secondaryText: element.EntityData.Email || element.Description, // email
171
+ tertiaryText: "", // status
172
+ optionalText: "" // anything
173
+ } as iPeoplePickerUserItem;
174
+ case 'SecGroup':
175
+ return {
176
+ id: element.Key,
177
+ loginName: element.LoginName ? element.LoginName : element.Key,
178
+ imageInitials: this.getFullNameInitials(element.DisplayText),
179
+ text: element.DisplayText,
180
+ secondaryText: element.ProviderName
181
+ } as iPeoplePickerUserItem;
182
+ case 'FormsRole':
183
+ return {
184
+ id: element.Key,
185
+ loginName: element.LoginName ? element.LoginName : element.Key,
186
+ imageInitials: this.getFullNameInitials(element.DisplayText),
187
+ text: element.DisplayText,
188
+ secondaryText: element.ProviderName
189
+ } as iPeoplePickerUserItem;
190
+ default:
191
+ return {
192
+ id: element.EntityData.SPGroupID,
193
+ loginName: element.EntityData.AccountName,
194
+ imageInitials: this.getFullNameInitials(element.DisplayText),
195
+ text: element.DisplayText,
196
+ secondaryText: element.EntityData.AccountName
197
+ } as iPeoplePickerUserItem;
198
+ }
199
+ });
200
+
201
+ return userResults;
202
+ }
203
+
204
+
205
+ // Nothing to return
206
+ return [];
207
+ } catch (e) {
208
+ console.error("PeopleSearchService::searchTenant: error occured while fetching the users.");
209
+ return [];
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Retrieves the local user ID
215
+ *
216
+ * @param userId
217
+ */
218
+ private async ensureUser(userId: string): Promise<number> {
219
+ const siteUrl = this.context.siteUrl;
220
+ if (this.cachedLocalUsers && this.cachedLocalUsers[siteUrl]) {
221
+ const users = this.cachedLocalUsers[siteUrl];
222
+ const userIdx = firstIndexOf(users, u => u.LoginName === userId);
223
+ if (userIdx !== -1) {
224
+ return users[userIdx].Id;
225
+ }
226
+ }
227
+
228
+ const user = await EnsureUser(siteUrl, userId)
229
+ if (user && user.Id) {
230
+ this.cachedLocalUsers[siteUrl].push(user);
231
+ return user.Id;
232
+ }
233
+ return null;
234
+ }
235
+
236
+ /**
237
+ * Generates Initials from a full name
238
+ */
239
+ private getFullNameInitials(fullName: string): string {
240
+ if (fullName === null) {
241
+ return fullName;
242
+ }
243
+
244
+ const words: string[] = fullName.split(' ');
245
+ if (words.length === 0) {
246
+ return '';
247
+ } else if (words.length === 1) {
248
+ return words[0].charAt(0);
249
+ } else {
250
+ return (words[0].charAt(0) + words[1].charAt(0));
251
+ }
252
+ }
253
253
  }