jitz-sharepoint-utilities 1.11.2 → 2.0.0

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 (94) hide show
  1. package/@types/allTypes.d.ts +1 -0
  2. package/controls/JitzGrid.tsx +639 -0
  3. package/controls/JitzImage.tsx +38 -0
  4. package/controls/JitzPeoplePicker.tsx +419 -0
  5. package/controls/JitzPersonInfo.tsx +114 -0
  6. package/controls/JitzPersona.tsx +53 -0
  7. package/data/context/CommonRepository.ts +287 -0
  8. package/data/context/JitzContext.ts +33 -0
  9. package/data/context/JitzSPContext.ts +16 -0
  10. package/data/context/JitzSPHttpClient.ts +133 -0
  11. package/data/context/List.ts +415 -0
  12. package/data/context/Repository.ts +395 -0
  13. package/data/interfaces/ICommonRepository.ts +7 -0
  14. package/data/interfaces/IJitzContext.ts +11 -0
  15. package/data/interfaces/IJitzSPContext.ts +7 -0
  16. package/data/interfaces/IJitzSPHttpClient.ts +6 -0
  17. package/data/interfaces/IList.ts +41 -0
  18. package/data/interfaces/IModels.ts +33 -0
  19. package/data/interfaces/IRepository.ts +31 -0
  20. package/lib/common/IModels.d.ts +9 -1
  21. package/lib/common/IObjects.d.ts +72 -0
  22. package/lib/common/IObjects.js +30 -0
  23. package/lib/controls/JitzGrid.d.ts +75 -0
  24. package/lib/controls/JitzGrid.js +606 -0
  25. package/lib/controls/JitzImage.d.ts +14 -0
  26. package/lib/controls/JitzImage.js +37 -0
  27. package/lib/controls/JitzPeoplePicker.d.ts +49 -0
  28. package/lib/controls/JitzPeoplePicker.js +311 -0
  29. package/lib/controls/JitzPersonInfo.d.ts +32 -0
  30. package/lib/controls/JitzPersonInfo.js +98 -0
  31. package/lib/controls/JitzPersona.d.ts +23 -0
  32. package/lib/controls/JitzPersona.js +48 -0
  33. package/lib/data/Activities.d.ts +6 -0
  34. package/lib/data/Activities.js +36 -0
  35. package/lib/data/Attachments.d.ts +6 -0
  36. package/lib/data/Attachments.js +30 -0
  37. package/lib/data/Configurations.d.ts +6 -0
  38. package/lib/data/Configurations.js +30 -0
  39. package/lib/data/CustomStylesheet.d.ts +6 -0
  40. package/lib/data/CustomStylesheet.js +30 -0
  41. package/lib/data/EmailTemplates.d.ts +6 -0
  42. package/lib/data/EmailTemplates.js +31 -0
  43. package/lib/data/FAQs.d.ts +6 -0
  44. package/lib/data/FAQs.js +30 -0
  45. package/lib/data/HomePageTexts.d.ts +6 -0
  46. package/lib/data/HomePageTexts.js +30 -0
  47. package/lib/data/TicketCategories.d.ts +6 -0
  48. package/lib/data/TicketCategories.js +26 -0
  49. package/lib/data/TicketComments.d.ts +6 -0
  50. package/lib/data/TicketComments.js +32 -0
  51. package/lib/data/TicketPriorities.d.ts +6 -0
  52. package/lib/data/TicketPriorities.js +31 -0
  53. package/lib/data/TicketStatuses.d.ts +6 -0
  54. package/lib/data/TicketStatuses.js +31 -0
  55. package/lib/data/TicketSubcategories.d.ts +6 -0
  56. package/lib/data/TicketSubcategories.js +26 -0
  57. package/lib/data/Tickets.d.ts +6 -0
  58. package/lib/data/Tickets.js +45 -0
  59. package/lib/data/context/CommonRepository.d.ts +17 -0
  60. package/lib/data/context/CommonRepository.js +288 -0
  61. package/lib/data/context/JitzContext.d.ts +13 -0
  62. package/lib/data/context/JitzContext.js +80 -0
  63. package/lib/data/context/JitzSPContext.d.ts +8 -0
  64. package/lib/data/context/JitzSPContext.js +58 -0
  65. package/lib/data/context/JitzSPHttpClient.d.ts +14 -0
  66. package/lib/data/context/JitzSPHttpClient.js +173 -0
  67. package/lib/data/context/List.d.ts +35 -0
  68. package/lib/data/context/List.js +442 -0
  69. package/lib/data/context/Repository.d.ts +19 -0
  70. package/lib/data/context/Repository.js +421 -0
  71. package/lib/data/interfaces/ICommonRepository.d.ts +6 -0
  72. package/lib/data/interfaces/ICommonRepository.js +2 -0
  73. package/lib/data/interfaces/IJitzContext.d.ts +10 -0
  74. package/lib/data/interfaces/IJitzContext.js +2 -0
  75. package/lib/data/interfaces/IJitzSPContext.d.ts +6 -0
  76. package/lib/data/interfaces/IJitzSPContext.js +2 -0
  77. package/lib/data/interfaces/IJitzSPHttpClient.d.ts +6 -0
  78. package/lib/data/interfaces/IJitzSPHttpClient.js +2 -0
  79. package/lib/data/interfaces/IList.d.ts +25 -0
  80. package/lib/data/interfaces/IList.js +2 -0
  81. package/lib/data/interfaces/IModels.d.ts +32 -0
  82. package/lib/data/interfaces/IModels.js +2 -0
  83. package/lib/data/interfaces/IRepository.d.ts +14 -0
  84. package/lib/data/interfaces/IRepository.js +2 -0
  85. package/lib/jitzSPHttpClient.js +5 -3
  86. package/lib/repositories/CommonRepository.js +89 -33
  87. package/lib/repositories/Repository.js +22 -21
  88. package/lib/services/GraphService.d.ts +10 -0
  89. package/lib/services/GraphService.js +105 -0
  90. package/lib/services/UserService.d.ts +1 -1
  91. package/lib/services/UserService.js +9 -9
  92. package/lib/services/UtilityService.d.ts +18 -12
  93. package/lib/services/UtilityService.js +157 -58
  94. package/package.json +7 -5
@@ -0,0 +1,287 @@
1
+ import { ICommonRepository } from "../interfaces/ICommonRepository";
2
+ import IJitzSPContext from "../interfaces/IJitzSPContext";
3
+ import { IEmail } from "../interfaces/IModels";
4
+
5
+ export default class CommonRepository implements ICommonRepository {
6
+ public context: IJitzSPContext;
7
+
8
+ constructor(context: IJitzSPContext) {
9
+ this.context = context;
10
+ }
11
+
12
+ public sendEmail(email: IEmail): Promise<boolean> {
13
+ email.properties.__metadata = {
14
+ type: "SP.Utilities.EmailProperties",
15
+ };
16
+ // console.log(JSON.stringify(email.properties));
17
+ var requestUrl = `${this.context.siteUrl}/_api/SP.Utilities.Utility.SendEmail`;
18
+ return this.context.client
19
+ .post(requestUrl, email, {
20
+ Accept: "application/json;odata=nometadata",
21
+ "Content-type": "application/json;odata=verbose",
22
+ "odata-version": "",
23
+ })
24
+ .then((response: any): Promise<boolean> => {
25
+ if (response.status >= 200 && response.status < 300) {
26
+ var json = response;
27
+ return json;
28
+ } else {
29
+ return Promise.reject(new Error(JSON.stringify(response)));
30
+ }
31
+ });
32
+ }
33
+
34
+ public getData(
35
+ listName: string,
36
+ selectFields?: string,
37
+ expand?: string,
38
+ filters?: string,
39
+ orderBy?: string,
40
+ top?: number,
41
+ skipTokenUniqueField?: string,
42
+ skipTokenUniqueFieldValue?: string
43
+ ): Promise<any> {
44
+ let queryUrlGetAllItems: string =
45
+ `/_api/web/lists/GetByTitle('` + listName + `')/items`;
46
+
47
+ if (selectFields != null && selectFields != "") {
48
+ queryUrlGetAllItems = queryUrlGetAllItems + `?$select=` + selectFields;
49
+ } else {
50
+ queryUrlGetAllItems = queryUrlGetAllItems + `?$select=*`;
51
+ }
52
+ if (expand != null && expand != "") {
53
+ queryUrlGetAllItems = queryUrlGetAllItems + `&$expand=` + expand;
54
+ }
55
+ if (top != null && top != undefined && top > 0) {
56
+ queryUrlGetAllItems = queryUrlGetAllItems + `&$top=` + top;
57
+ }
58
+ if (filters != null && filters != "") {
59
+ queryUrlGetAllItems = queryUrlGetAllItems + `&$filter=` + filters;
60
+ }
61
+ if (orderBy != null && orderBy != "") {
62
+ queryUrlGetAllItems = queryUrlGetAllItems + `&$orderby=` + orderBy;
63
+ }
64
+ if (
65
+ skipTokenUniqueField != null &&
66
+ skipTokenUniqueField != undefined &&
67
+ skipTokenUniqueFieldValue != null &&
68
+ skipTokenUniqueFieldValue != undefined
69
+ ) {
70
+ if (skipTokenUniqueField == "Id" || skipTokenUniqueField == "id") {
71
+ skipTokenUniqueField = "ID";
72
+ }
73
+ queryUrlGetAllItems =
74
+ queryUrlGetAllItems +
75
+ `&$skiptoken=Paged=TRUE%26p_${skipTokenUniqueField}=${skipTokenUniqueFieldValue}`;
76
+ }
77
+
78
+ return this.context.client
79
+ .get(queryUrlGetAllItems)
80
+ .then((response: any) => {
81
+ if (response.status >= 200 && response.status < 300) {
82
+ return response.data.d;
83
+ } else {
84
+ return Promise.reject(new Error(JSON.stringify(response)));
85
+ }
86
+ })
87
+ .then((data: any) => {
88
+ return data;
89
+ })
90
+ .catch((ex: any) => {
91
+ console.log("load Items > JitzSPHttpClient.get()...catch:", ex);
92
+ throw ex;
93
+ });
94
+ }
95
+
96
+ public get(url: string): Promise<any> {
97
+ return this.context.client
98
+ .get(url)
99
+ .then((response: any) => {
100
+ if (response.status >= 200 && response.status < 300) {
101
+ return response.data.d;
102
+ } else {
103
+ return Promise.reject(new Error(JSON.stringify(response)));
104
+ }
105
+ })
106
+ .then((data: any) => {
107
+ return data;
108
+ })
109
+ .catch((ex: any) => {
110
+ console.log("load Items > JitzSPHttpClient.get()...catch:", ex);
111
+ throw ex;
112
+ });
113
+ }
114
+
115
+ public post(url: string, data: any, header?: any): Promise<any> {
116
+ return this.context.client
117
+ .post(url, data, header)
118
+ .then((response: any) => {
119
+ if (response.status >= 200 && response.status < 300) {
120
+ return response.data;
121
+ } else {
122
+ return Promise.reject(new Error(JSON.stringify(response)));
123
+ }
124
+ })
125
+ .then((data: any) => {
126
+ return data;
127
+ })
128
+ .catch((ex: any) => {
129
+ console.log("load Items > JitzSPHttpClient.get()...catch:", ex);
130
+ throw ex;
131
+ });
132
+ }
133
+
134
+ public getFiles(
135
+ libraryName: string,
136
+ selectFields: string,
137
+ filter: string,
138
+ expandFields: string
139
+ ): Promise<any> {
140
+ let url: string = `/_api/web/lists/getbytitle('${libraryName}')/Items?$select=*,File/Name,File/ServerRelativeUrl`;
141
+ if (selectFields != undefined && selectFields.length > 0) {
142
+ url = `${url},${selectFields}`;
143
+ }
144
+ if (filter != undefined && filter.length > 0) {
145
+ url = `${url}&$filter=${filter}`;
146
+ }
147
+ url = `${url}&$expand=File`;
148
+ if (expandFields != undefined && expandFields.length > 0) {
149
+ url = `${url},${expandFields}`;
150
+ }
151
+ return this.context.client.get(url).then((response: any) => {
152
+ if (response.status >= 200 && response.status <= 300) {
153
+ var json = response.data.d.results;
154
+ return json;
155
+ } else {
156
+ return Promise.reject(new Error(JSON.stringify(response)));
157
+ }
158
+ });
159
+ }
160
+
161
+ public uploadFile(
162
+ libraryName: string,
163
+ fileName: string,
164
+ arrayBuffer: ArrayBuffer
165
+ ): Promise<any> {
166
+ return this.context.client
167
+ .postWithOutStringify(
168
+ `/_api/Web/Lists/getByTitle('${libraryName}')/RootFolder/Files/Add(url='${fileName}', overwrite=true)`,
169
+ arrayBuffer,
170
+ {
171
+ Accept: "application/json;odata=verbose",
172
+ "content-length": arrayBuffer.byteLength.toString(),
173
+ }
174
+ )
175
+ .then((response: any) => {
176
+ if (response.status >= 200 && response.status <= 300) {
177
+ var json = response.data.d;
178
+ return json;
179
+ } else {
180
+ return Promise.reject(new Error(JSON.stringify(response)));
181
+ }
182
+ });
183
+ }
184
+
185
+ public getFileItem(libraryName: string, fileUrl: string): Promise<any> {
186
+ // `${this._webAbsoluteUrl}/_api/web/GetFileByServerRelativeUrl('${fileUrl}')/$value`
187
+ return this.context.client
188
+ .get(
189
+ `/_api/web/lists/getbytitle('${libraryName}')/Items?$filter=FileLeafRef eq '${fileUrl}'&$select=Id`
190
+ )
191
+ .then((response: any) => {
192
+ if (response.status >= 200 && response.status <= 300) {
193
+ var json = response.data.d;
194
+ return json;
195
+ } else {
196
+ return Promise.reject(new Error(JSON.stringify(response)));
197
+ }
198
+ });
199
+ }
200
+
201
+ public async updateMetadata(listName: string, item: any): Promise<any> {
202
+ var item = await this.getEntityType(listName).then((entityType) => {
203
+ item.__metadata = {
204
+ //etag: "1",
205
+ type: entityType,
206
+ };
207
+ var requestUrl = `_api/web/lists/getbytitle('${listName}')/items(${item.Id})`;
208
+ return this.context.client
209
+ .post(requestUrl, item, {
210
+ Accept: "application/json;odata=nometadata",
211
+ "Content-type": "application/json;odata=verbose",
212
+ "odata-version": "",
213
+ "IF-MATCH": "*",
214
+ "X-HTTP-Method": "MERGE",
215
+ })
216
+ .then((response: any) => {
217
+ if (response.status >= 200 && response.status < 300) {
218
+ return item;
219
+ } else {
220
+ console.log(JSON.stringify(response));
221
+ return Promise.reject(new Error(JSON.stringify(response)));
222
+ }
223
+ });
224
+ });
225
+
226
+ let url: string = `/_api/web/lists/getbytitle('${listName}')/items(${item.Id})?$select=*,File/Name,File/ServerRelativeUrl&$expand=File`;
227
+ return this.context.client.get(url).then((response: any) => {
228
+ if (response.status >= 200 && response.status <= 300) {
229
+ var json = response.data.d;
230
+ return json;
231
+ } else {
232
+ return Promise.reject(new Error(JSON.stringify(response)));
233
+ }
234
+ });
235
+ }
236
+
237
+ public deleteFile(listName: string, id: number): Promise<boolean> {
238
+ var requestUrl = `_api/web/lists/getbytitle('${listName}')/items(${id})`;
239
+ return this.context.client
240
+ .post(
241
+ requestUrl,
242
+ {},
243
+ {
244
+ Accept: "application/json;odata=nometadata",
245
+ "Content-type": "application/json;odata=verbose",
246
+ "odata-version": "",
247
+ "IF-MATCH": "*",
248
+ "X-HTTP-Method": "DELETE",
249
+ }
250
+ )
251
+ .then((response: any) => {
252
+ if (response.status >= 200 && response.status < 300) {
253
+ return true;
254
+ } else {
255
+ return Promise.reject(new Error(JSON.stringify(response)));
256
+ }
257
+ });
258
+ }
259
+
260
+ private getEntityType(listName: string): Promise<string> {
261
+ return new Promise<string>(
262
+ (
263
+ resolve: (listItemEntityTypeName: string) => void,
264
+ reject: (error: any) => void
265
+ ): void => {
266
+ this.context.client
267
+ .get(
268
+ `_api/web/lists/getbytitle('${listName}')?$select=ListItemEntityTypeFullName`
269
+ )
270
+ .then(
271
+ (
272
+ response: any
273
+ ): Promise<{ ListItemEntityTypeFullName: string }> => {
274
+ return response;
275
+ },
276
+ (error: any): void => {
277
+ reject(error);
278
+ }
279
+ )
280
+ .then((response: any): void => {
281
+ var _listEntityType = response.data.d.ListItemEntityTypeFullName;
282
+ resolve(_listEntityType || "");
283
+ });
284
+ }
285
+ );
286
+ }
287
+ }
@@ -0,0 +1,33 @@
1
+ import { WebPartContext } from "@microsoft/sp-webpart-base";
2
+ import { MSGraphClientV3 } from "@microsoft/sp-http";
3
+ import IJitzContext from "../interfaces/IJitzContext";
4
+ import IJitzSPContext from "../interfaces/IJitzSPContext";
5
+ import JitzSPContext from "./JitzSPContext";
6
+
7
+ export default class JitzContext implements IJitzContext {
8
+ spContext: IJitzSPContext;
9
+ webpartContext: WebPartContext;
10
+ graphClient: MSGraphClientV3;
11
+ siteId: string;
12
+
13
+ constructor(webpartContext: WebPartContext) {
14
+ this.spContext = new JitzSPContext(
15
+ webpartContext.pageContext.site.absoluteUrl
16
+ );
17
+ this.webpartContext = webpartContext;
18
+ this.siteId = this.webpartContext.pageContext.site.id.toString();
19
+ }
20
+
21
+ public async init() {
22
+ await this.spContext.init();
23
+ await this.initGraphClient();
24
+ }
25
+
26
+ private async initGraphClient() {
27
+ await this.webpartContext.msGraphClientFactory
28
+ .getClient("3") // Init Microsoft Graph Client
29
+ .then((client: MSGraphClientV3) => {
30
+ this.graphClient = client;
31
+ });
32
+ }
33
+ }
@@ -0,0 +1,16 @@
1
+ import IJitzSPContext from "../interfaces/IJitzSPContext";
2
+ import IJitzSPHttpClient from "../interfaces/IJitzSPHttpClient";
3
+ import JitzSPHttpClient from "./JitzSPHttpClient";
4
+
5
+ export default class JitzSPContext implements IJitzSPContext {
6
+ public client: IJitzSPHttpClient;
7
+ public siteUrl: string;
8
+
9
+ constructor(siteUrl: string) {
10
+ this.siteUrl = siteUrl;
11
+ this.client = new JitzSPHttpClient(siteUrl);
12
+ }
13
+ public init = async () => {
14
+ await this.client.init();
15
+ };
16
+ }
@@ -0,0 +1,133 @@
1
+ import axios from "axios";
2
+ import IJitzSPHttpClient from "../interfaces/IJitzSPHttpClient";
3
+
4
+ export default class JitzSPHttpClient implements IJitzSPHttpClient {
5
+ public siteUrl: string;
6
+ public client: any;
7
+ public securityToken: string = "";
8
+ private header: any = {
9
+ Accept: "application/json;odata=verbose",
10
+ "Content-Type": "application/json;odata=verbose",
11
+ };
12
+
13
+ constructor(siteUrl: string = "") {
14
+ this.siteUrl = siteUrl;
15
+ this.securityToken = "";
16
+ this.client = axios.create({
17
+ baseURL: this.siteUrl,
18
+ });
19
+ }
20
+
21
+ public init = async () => {
22
+ await this.refreshSecurityValidation();
23
+ };
24
+
25
+ public get = (url: string, header?: any) => {
26
+ header = header || this.header;
27
+ header["X-RequestDigest"] = this.securityToken;
28
+ var authOptions = {
29
+ method: "GET",
30
+ url: url,
31
+ data: JSON.stringify({}),
32
+ headers: header,
33
+ json: true,
34
+ };
35
+
36
+ return this.client(authOptions);
37
+
38
+ // return this.getSecurityValidation().then((ctx: any) => {
39
+ // this.securityToken = ctx.data.d.GetContextWebInformation.FormDigestValue;
40
+ // header["X-RequestDigest"] = this.securityToken;
41
+ // var authOptions = {
42
+ // method: "GET",
43
+ // url: url,
44
+ // data: JSON.stringify({}),
45
+ // headers: header,
46
+ // json: true,
47
+ // };
48
+
49
+ // return this.client(authOptions);
50
+ // });
51
+ };
52
+
53
+ public post = (url: string, data: any, header?: any) => {
54
+ header = header || this.header;
55
+ header["X-RequestDigest"] = this.securityToken;
56
+ header["Accept"] = "application/json;odata=verbose";
57
+ header["Content-Type"] = "application/json;odata=verbose";
58
+ var authOptions = {
59
+ method: "POST",
60
+ url: url,
61
+ data: JSON.stringify(data),
62
+ headers: header,
63
+ json: true,
64
+ };
65
+
66
+ return this.client(authOptions);
67
+
68
+ // return this.getSecurityValidation().then((ctx: any) => {
69
+ // this.securityToken = ctx.data.d.GetContextWebInformation.FormDigestValue;
70
+ // header["X-RequestDigest"] = this.securityToken;
71
+ // var authOptions = {
72
+ // method: "POST",
73
+ // url: url,
74
+ // data: JSON.stringify(data),
75
+ // headers: header,
76
+ // json: true,
77
+ // };
78
+
79
+ // return this.client(authOptions);
80
+ // });
81
+ };
82
+
83
+ public postWithOutStringify = (url: string, data: any, header?: any) => {
84
+ header = header || this.header;
85
+ header["X-RequestDigest"] = this.securityToken;
86
+ var authOptions = {
87
+ method: "POST",
88
+ url: url,
89
+ data: data,
90
+ headers: header,
91
+ json: true,
92
+ };
93
+
94
+ return this.client(authOptions);
95
+ };
96
+
97
+ public getSecurityValidation = () => {
98
+ var authOptions = {
99
+ method: "POST",
100
+ url: "/_api/contextinfo",
101
+ data: JSON.stringify({}),
102
+ headers: {
103
+ Accept: "application/json;odata=verbose",
104
+ "Content-Type": "application/json;odata=verbose",
105
+ },
106
+ json: true,
107
+ };
108
+ return this.client(authOptions);
109
+ };
110
+
111
+ public refreshSecurityValidation = async () => {
112
+ var authOptions = {
113
+ method: "POST",
114
+ url: "/_api/contextinfo",
115
+ data: JSON.stringify({}),
116
+ headers: {
117
+ Accept: "application/json;odata=verbose",
118
+ "Content-Type": "application/json;odata=verbose",
119
+ },
120
+ json: true,
121
+ };
122
+
123
+ await this.client(authOptions).then((context: any) => {
124
+ this.securityToken =
125
+ context.data.d.GetContextWebInformation.FormDigestValue;
126
+ // console.log("Token:- "+this.securityToken);
127
+ var interval = setInterval(() => {
128
+ this.refreshSecurityValidation();
129
+ clearInterval(interval);
130
+ }, 600000); //300000
131
+ });
132
+ };
133
+ }