@kwiz/common 1.0.2 → 1.0.3

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