@kwiz/common 1.0.96 → 1.0.97

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 (100) 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/helpers/strings.js +20 -1
  6. package/lib/cjs/helpers/strings.js.map +1 -1
  7. package/lib/cjs/types/libs/msal.types.js +26 -26
  8. package/lib/cjs/utils/sharepoint.rest/user.js +11 -11
  9. package/lib/esm/helpers/strings.js +19 -1
  10. package/lib/esm/helpers/strings.js.map +1 -1
  11. package/lib/esm/types/libs/msal.types.js +26 -26
  12. package/lib/esm/utils/sharepoint.rest/user.js +11 -11
  13. package/lib/types/helpers/strings.d.ts +5 -0
  14. package/package.json +81 -81
  15. package/readme.md +17 -17
  16. package/src/_dependencies.ts +12 -12
  17. package/src/config.ts +17 -17
  18. package/src/helpers/Guid.ts +181 -181
  19. package/src/helpers/base64.ts +173 -173
  20. package/src/helpers/browser.test.js +13 -13
  21. package/src/helpers/browser.ts +1399 -1399
  22. package/src/helpers/browserinfo.ts +292 -292
  23. package/src/helpers/collections.base.test.js +25 -25
  24. package/src/helpers/collections.base.ts +437 -437
  25. package/src/helpers/collections.ts +107 -107
  26. package/src/helpers/color.ts +54 -54
  27. package/src/helpers/cookies.ts +59 -59
  28. package/src/helpers/date.test.js +119 -119
  29. package/src/helpers/date.ts +188 -188
  30. package/src/helpers/debug.ts +186 -186
  31. package/src/helpers/diagrams.ts +43 -43
  32. package/src/helpers/emails.ts +6 -6
  33. package/src/helpers/eval.ts +5 -5
  34. package/src/helpers/file.test.js +50 -50
  35. package/src/helpers/file.ts +60 -60
  36. package/src/helpers/flatted.ts +149 -149
  37. package/src/helpers/functions.ts +16 -16
  38. package/src/helpers/graph/calendar.types.ts +10 -10
  39. package/src/helpers/http.ts +69 -69
  40. package/src/helpers/images.ts +22 -22
  41. package/src/helpers/json.ts +38 -38
  42. package/src/helpers/md5.ts +189 -189
  43. package/src/helpers/objects.test.js +33 -33
  44. package/src/helpers/objects.ts +274 -274
  45. package/src/helpers/promises.test.js +37 -37
  46. package/src/helpers/promises.ts +165 -165
  47. package/src/helpers/random.ts +27 -27
  48. package/src/helpers/scheduler/scheduler.test.js +103 -103
  49. package/src/helpers/scheduler/scheduler.ts +131 -131
  50. package/src/helpers/sharepoint.ts +776 -776
  51. package/src/helpers/strings.test.js +122 -101
  52. package/src/helpers/strings.ts +337 -317
  53. package/src/helpers/typecheckers.test.js +34 -34
  54. package/src/helpers/typecheckers.ts +266 -266
  55. package/src/helpers/url.test.js +43 -43
  56. package/src/helpers/url.ts +207 -207
  57. package/src/helpers/urlhelper.ts +111 -111
  58. package/src/index.ts +6 -6
  59. package/src/types/auth.ts +54 -54
  60. package/src/types/common.types.ts +15 -15
  61. package/src/types/flatted.types.ts +59 -59
  62. package/src/types/globals.types.ts +6 -6
  63. package/src/types/graph/calendar.types.ts +80 -80
  64. package/src/types/knownscript.types.ts +18 -18
  65. package/src/types/libs/datajs.types.ts +28 -28
  66. package/src/types/libs/ics.types.ts +30 -30
  67. package/src/types/libs/msal.types.ts +49 -49
  68. package/src/types/locales.ts +124 -124
  69. package/src/types/localstoragecache.types.ts +8 -8
  70. package/src/types/location.types.ts +27 -27
  71. package/src/types/moment.ts +11 -11
  72. package/src/types/regex.types.ts +16 -16
  73. package/src/types/rest.types.ts +95 -95
  74. package/src/types/sharepoint.types.ts +1465 -1465
  75. package/src/types/sharepoint.utils.types.ts +287 -287
  76. package/src/utils/auth/common.ts +74 -74
  77. package/src/utils/auth/discovery.test.js +12 -12
  78. package/src/utils/auth/discovery.ts +132 -132
  79. package/src/utils/base64.ts +27 -27
  80. package/src/utils/consolelogger.ts +320 -320
  81. package/src/utils/date.ts +35 -35
  82. package/src/utils/emails.ts +24 -24
  83. package/src/utils/knownscript.ts +286 -286
  84. package/src/utils/localstoragecache.ts +441 -441
  85. package/src/utils/rest.ts +501 -501
  86. package/src/utils/script.ts +170 -170
  87. package/src/utils/sharepoint.rest/common.ts +154 -154
  88. package/src/utils/sharepoint.rest/date.ts +62 -62
  89. package/src/utils/sharepoint.rest/file.folder.ts +598 -598
  90. package/src/utils/sharepoint.rest/item.ts +547 -547
  91. package/src/utils/sharepoint.rest/list.ts +1480 -1480
  92. package/src/utils/sharepoint.rest/listutils/GetListItemsByCaml.ts +774 -774
  93. package/src/utils/sharepoint.rest/listutils/GetListItemsById.ts +275 -275
  94. package/src/utils/sharepoint.rest/listutils/common.ts +206 -206
  95. package/src/utils/sharepoint.rest/location.ts +141 -141
  96. package/src/utils/sharepoint.rest/navigation-links.ts +86 -86
  97. package/src/utils/sharepoint.rest/user-search.ts +252 -252
  98. package/src/utils/sharepoint.rest/user.ts +491 -491
  99. package/src/utils/sharepoint.rest/web.ts +1384 -1384
  100. 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
  }