jitz-sharepoint-utilities 1.10.65 → 1.11.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.
package/README.md CHANGED
@@ -1,110 +1,110 @@
1
- # JitzSharePointUtilities
2
-
3
- Easily pluggable data layer for SharePoint Framework(SPFx) applications following Repository pattern and some SharePoint utilities
4
-
5
- ### Prerequisites
6
-
7
- Create the SPFx project according to Microsoft's <a href="https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part" target="_blank">documentation</a>
8
-
9
-
10
- ### How to use
11
-
12
- Install the package using the command below
13
-
14
- ```
15
- npm i jitz-sharepoint-utilities
16
-
17
- ```
18
-
19
- Import the package in your project
20
-
21
- ```
22
- import UtilityService from 'jitz-sharepoint-utilities/lib/services/UtilityService';
23
- import UserService from 'jitz-sharepoint-utilities/lib/services/UserService';
24
- import { IRepository } from 'jitz-sharepoint-utilities/lib/repositories/IRepository';
25
- import Repository from 'jitz-sharepoint-utilities/lib/repositories/Repository';
26
-
27
- export interface IProduct extends IModel{
28
-
29
- }
30
-
31
- ```
32
-
33
- Create the data model for the lists used on the project
34
-
35
- ```
36
-
37
- import { IModel, IPersonOrGroup } from 'jitz-sharepoint-utilities/lib/common/IModels';
38
-
39
- export interface IProduct extends IModel{
40
- customFieldsInTheList:string;
41
- ....
42
- ....
43
- }
44
-
45
-
46
- ```
47
-
48
- Create the repository class for the list
49
-
50
- ```
51
-
52
- import { IWebPartContext } from '@microsoft/sp-webpart-base';
53
- import {IProduct} from '../yourModelFile';
54
- import Repository from 'jitz-sharepoint-utilities/lib/repositories/Repository';
55
-
56
-
57
- export default class ProductRepository extends Repository<IProduct> {
58
-
59
- constructor(context: IWebPartContext,_listName:string="Products"){
60
- super(context,_listName);
61
- }
62
-
63
-
64
- }
65
-
66
- ```
67
-
68
- Use the repository
69
-
70
- ```
71
-
72
- import { IRepository } from 'jitz-sharepoint-utilities/lib/repositories/IRepository';
73
-
74
- private _productRepository:IRepository<IProduct>;
75
-
76
- constructor(props: yourProps, state: yourState) {
77
- super(props);
78
- this.state = {
79
- ...
80
- ...
81
- };
82
-
83
- this._userService = new UserService(this.props.context);
84
- this._productRepository = new ProductRepository(this.props.context);
85
- }
86
-
87
- getProducts = () => {
88
- this._productRepository.getAll().then((data)=>{
89
- ...
90
- ...
91
- });
92
- }
93
-
94
- ```
95
-
96
- Use User service
97
-
98
- ```
99
- this._userService.getCurrentUser().then((user){});
100
- this._userService.getCurrentUserGroups().then((groups){});
101
- this._userService.checkIfCurrentUserInGroup(groupName).then((result){});
102
- this._userService.checkIfUserIsInGroup(userId, groupName).then((result){});
103
- this._userService.getUserById(id).then((user){});
104
-
105
- ```
106
- ### Keywords
107
-
108
- SPFx
109
- Typescript in SharePoint components
1
+ # JitzSharePointUtilities
2
+
3
+ Easily pluggable data layer for SharePoint Framework(SPFx) applications following Repository pattern and some SharePoint utilities
4
+
5
+ ### Prerequisites
6
+
7
+ Create the SPFx project according to Microsoft's <a href="https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part" target="_blank">documentation</a>
8
+
9
+
10
+ ### How to use
11
+
12
+ Install the package using the command below
13
+
14
+ ```
15
+ npm i jitz-sharepoint-utilities
16
+
17
+ ```
18
+
19
+ Import the package in your project
20
+
21
+ ```
22
+ import UtilityService from 'jitz-sharepoint-utilities/lib/services/UtilityService';
23
+ import UserService from 'jitz-sharepoint-utilities/lib/services/UserService';
24
+ import { IRepository } from 'jitz-sharepoint-utilities/lib/repositories/IRepository';
25
+ import Repository from 'jitz-sharepoint-utilities/lib/repositories/Repository';
26
+
27
+ export interface IProduct extends IModel{
28
+
29
+ }
30
+
31
+ ```
32
+
33
+ Create the data model for the lists used on the project
34
+
35
+ ```
36
+
37
+ import { IModel, IPersonOrGroup } from 'jitz-sharepoint-utilities/lib/common/IModels';
38
+
39
+ export interface IProduct extends IModel{
40
+ customFieldsInTheList:string;
41
+ ....
42
+ ....
43
+ }
44
+
45
+
46
+ ```
47
+
48
+ Create the repository class for the list
49
+
50
+ ```
51
+
52
+ import { IWebPartContext } from '@microsoft/sp-webpart-base';
53
+ import {IProduct} from '../yourModelFile';
54
+ import Repository from 'jitz-sharepoint-utilities/lib/repositories/Repository';
55
+
56
+
57
+ export default class ProductRepository extends Repository<IProduct> {
58
+
59
+ constructor(context: IWebPartContext,_listName:string="Products"){
60
+ super(context,_listName);
61
+ }
62
+
63
+
64
+ }
65
+
66
+ ```
67
+
68
+ Use the repository
69
+
70
+ ```
71
+
72
+ import { IRepository } from 'jitz-sharepoint-utilities/lib/repositories/IRepository';
73
+
74
+ private _productRepository:IRepository<IProduct>;
75
+
76
+ constructor(props: yourProps, state: yourState) {
77
+ super(props);
78
+ this.state = {
79
+ ...
80
+ ...
81
+ };
82
+
83
+ this._userService = new UserService(this.props.context);
84
+ this._productRepository = new ProductRepository(this.props.context);
85
+ }
86
+
87
+ getProducts = () => {
88
+ this._productRepository.getAll().then((data)=>{
89
+ ...
90
+ ...
91
+ });
92
+ }
93
+
94
+ ```
95
+
96
+ Use User service
97
+
98
+ ```
99
+ this._userService.getCurrentUser().then((user){});
100
+ this._userService.getCurrentUserGroups().then((groups){});
101
+ this._userService.checkIfCurrentUserInGroup(groupName).then((result){});
102
+ this._userService.checkIfUserIsInGroup(userId, groupName).then((result){});
103
+ this._userService.getUserById(id).then((user){});
104
+
105
+ ```
106
+ ### Keywords
107
+
108
+ SPFx
109
+ Typescript in SharePoint components
110
110
  SharePoint
package/jitzHttpClient.ts CHANGED
@@ -1,44 +1,44 @@
1
- import axios from "axios";
2
-
3
- export interface IJitzHttpClient {
4
- get: (url: string, header?: any) => any;
5
- post: (url: string, data: any, header?: any) => any;
6
- }
7
-
8
- export default class JitzHttpClient implements IJitzHttpClient {
9
- private header: any = {
10
- Accept: "application/json;odata=verbose",
11
- "Content-Type": "application/json;odata=verbose",
12
- };
13
- private _client: any;
14
-
15
- constructor() {
16
- this._client = axios.create({});
17
- }
18
-
19
- public get = (url: string, header?: any) => {
20
- header = header || this.header;
21
- var authOptions = {
22
- method: "GET",
23
- url: url,
24
- data: JSON.stringify({}),
25
- headers: header,
26
- json: true,
27
- };
28
-
29
- return this._client(authOptions);
30
- };
31
-
32
- public post = (url: string, data: any, header?: any) => {
33
- header = header || this.header;
34
- var authOptions = {
35
- method: "POST",
36
- url: url,
37
- data: JSON.stringify(data),
38
- headers: header,
39
- json: true,
40
- };
41
-
42
- return this._client(authOptions);
43
- };
44
- }
1
+ import axios from "axios";
2
+
3
+ export interface IJitzHttpClient {
4
+ get: (url: string, header?: any) => any;
5
+ post: (url: string, data: any, header?: any) => any;
6
+ }
7
+
8
+ export default class JitzHttpClient implements IJitzHttpClient {
9
+ private header: any = {
10
+ Accept: "application/json;odata=verbose",
11
+ "Content-Type": "application/json;odata=verbose",
12
+ };
13
+ private _client: any;
14
+
15
+ constructor() {
16
+ this._client = axios.create({});
17
+ }
18
+
19
+ public get = (url: string, header?: any) => {
20
+ header = header || this.header;
21
+ var authOptions = {
22
+ method: "GET",
23
+ url: url,
24
+ data: JSON.stringify({}),
25
+ headers: header,
26
+ json: true,
27
+ };
28
+
29
+ return this._client(authOptions);
30
+ };
31
+
32
+ public post = (url: string, data: any, header?: any) => {
33
+ header = header || this.header;
34
+ var authOptions = {
35
+ method: "POST",
36
+ url: url,
37
+ data: JSON.stringify(data),
38
+ headers: header,
39
+ json: true,
40
+ };
41
+
42
+ return this._client(authOptions);
43
+ };
44
+ }
@@ -1,158 +1,158 @@
1
- import axios from "axios";
2
-
3
- export interface IJitzSPContext {
4
- client: IJitzSPHttpClient;
5
- siteUrl: string;
6
- init: () => void;
7
- }
8
-
9
- export class JitzSPContext implements IJitzSPContext {
10
- public client: IJitzSPHttpClient;
11
- public siteUrl: string;
12
-
13
- constructor(siteUrl: string) {
14
- this.siteUrl = siteUrl;
15
- this.client = new JitzSPHttpClient(siteUrl);
16
- }
17
- public init = async () => {
18
- await this.client.init();
19
- };
20
- }
21
-
22
- export interface IJitzSPHttpClient {
23
- init: () => void;
24
- get: (url: string, header?: any) => any;
25
- post: (url: string, data: any, header?: any) => any;
26
- postWithOutStringify: (url: string, data: any, header?: any) => any;
27
- }
28
-
29
- export default class JitzSPHttpClient implements IJitzSPHttpClient {
30
- public siteUrl: string;
31
- public client: any;
32
- public securityToken: string = "";
33
- private header: any = {
34
- Accept: "application/json;odata=verbose",
35
- "Content-Type": "application/json;odata=verbose",
36
- };
37
-
38
- constructor(siteUrl: string = "") {
39
- this.siteUrl = siteUrl;
40
- this.securityToken = "";
41
- this.client = axios.create({
42
- baseURL: this.siteUrl,
43
- });
44
- }
45
-
46
- public init = async () => {
47
- await this.refreshSecurityValidation();
48
- };
49
-
50
- public get = (url: string, header?: any) => {
51
- header = header || this.header;
52
- header["X-RequestDigest"] = this.securityToken;
53
- var authOptions = {
54
- method: "GET",
55
- url: url,
56
- data: JSON.stringify({}),
57
- headers: header,
58
- json: true,
59
- };
60
-
61
- return this.client(authOptions);
62
-
63
- // return this.getSecurityValidation().then((ctx: any) => {
64
- // this.securityToken = ctx.data.d.GetContextWebInformation.FormDigestValue;
65
- // header["X-RequestDigest"] = this.securityToken;
66
- // var authOptions = {
67
- // method: "GET",
68
- // url: url,
69
- // data: JSON.stringify({}),
70
- // headers: header,
71
- // json: true,
72
- // };
73
-
74
- // return this.client(authOptions);
75
- // });
76
- };
77
-
78
- public post = (url: string, data: any, header?: any) => {
79
- // debugger;
80
- header = header || this.header;
81
- header["X-RequestDigest"] = this.securityToken;
82
- var authOptions = {
83
- method: "POST",
84
- url: url,
85
- data: JSON.stringify(data),
86
- headers: header,
87
- json: true,
88
- };
89
-
90
- return this.client(authOptions);
91
-
92
- // return this.getSecurityValidation().then((ctx: any) => {
93
- // this.securityToken = ctx.data.d.GetContextWebInformation.FormDigestValue;
94
- // header["X-RequestDigest"] = this.securityToken;
95
- // var authOptions = {
96
- // method: "POST",
97
- // url: url,
98
- // data: JSON.stringify(data),
99
- // headers: header,
100
- // json: true,
101
- // };
102
-
103
- // return this.client(authOptions);
104
- // });
105
- };
106
-
107
- public postWithOutStringify = (url: string, data: any, header?: any) => {
108
- // debugger;
109
- header = header || this.header;
110
- header["X-RequestDigest"] = this.securityToken;
111
- var authOptions = {
112
- method: "POST",
113
- url: url,
114
- data: data,
115
- headers: header,
116
- json: true,
117
- };
118
-
119
- return this.client(authOptions);
120
- };
121
-
122
- public getSecurityValidation = () => {
123
- var authOptions = {
124
- method: "POST",
125
- url: "/_api/contextinfo",
126
- data: JSON.stringify({}),
127
- headers: {
128
- Accept: "application/json;odata=verbose",
129
- "Content-Type": "application/json;odata=verbose",
130
- },
131
- json: true,
132
- };
133
- return this.client(authOptions);
134
- };
135
-
136
- public refreshSecurityValidation = async () => {
137
- var authOptions = {
138
- method: "POST",
139
- url: "/_api/contextinfo",
140
- data: JSON.stringify({}),
141
- headers: {
142
- Accept: "application/json;odata=verbose",
143
- "Content-Type": "application/json;odata=verbose",
144
- },
145
- json: true,
146
- };
147
-
148
- await this.client(authOptions).then((context: any) => {
149
- this.securityToken =
150
- context.data.d.GetContextWebInformation.FormDigestValue;
151
- // console.log("Token:- "+this.securityToken);
152
- var interval = setInterval(() => {
153
- this.refreshSecurityValidation();
154
- clearInterval(interval);
155
- }, 600000); //300000
156
- });
157
- };
158
- }
1
+ import axios from "axios";
2
+
3
+ export interface IJitzSPContext {
4
+ client: IJitzSPHttpClient;
5
+ siteUrl: string;
6
+ init: () => void;
7
+ }
8
+
9
+ export class JitzSPContext implements IJitzSPContext {
10
+ public client: IJitzSPHttpClient;
11
+ public siteUrl: string;
12
+
13
+ constructor(siteUrl: string) {
14
+ this.siteUrl = siteUrl;
15
+ this.client = new JitzSPHttpClient(siteUrl);
16
+ }
17
+ public init = async () => {
18
+ await this.client.init();
19
+ };
20
+ }
21
+
22
+ export interface IJitzSPHttpClient {
23
+ init: () => void;
24
+ get: (url: string, header?: any) => any;
25
+ post: (url: string, data: any, header?: any) => any;
26
+ postWithOutStringify: (url: string, data: any, header?: any) => any;
27
+ }
28
+
29
+ export default class JitzSPHttpClient implements IJitzSPHttpClient {
30
+ public siteUrl: string;
31
+ public client: any;
32
+ public securityToken: string = "";
33
+ private header: any = {
34
+ Accept: "application/json;odata=verbose",
35
+ "Content-Type": "application/json;odata=verbose",
36
+ };
37
+
38
+ constructor(siteUrl: string = "") {
39
+ this.siteUrl = siteUrl;
40
+ this.securityToken = "";
41
+ this.client = axios.create({
42
+ baseURL: this.siteUrl,
43
+ });
44
+ }
45
+
46
+ public init = async () => {
47
+ await this.refreshSecurityValidation();
48
+ };
49
+
50
+ public get = (url: string, header?: any) => {
51
+ header = header || this.header;
52
+ header["X-RequestDigest"] = this.securityToken;
53
+ var authOptions = {
54
+ method: "GET",
55
+ url: url,
56
+ data: JSON.stringify({}),
57
+ headers: header,
58
+ json: true,
59
+ };
60
+
61
+ return this.client(authOptions);
62
+
63
+ // return this.getSecurityValidation().then((ctx: any) => {
64
+ // this.securityToken = ctx.data.d.GetContextWebInformation.FormDigestValue;
65
+ // header["X-RequestDigest"] = this.securityToken;
66
+ // var authOptions = {
67
+ // method: "GET",
68
+ // url: url,
69
+ // data: JSON.stringify({}),
70
+ // headers: header,
71
+ // json: true,
72
+ // };
73
+
74
+ // return this.client(authOptions);
75
+ // });
76
+ };
77
+
78
+ public post = (url: string, data: any, header?: any) => {
79
+ // debugger;
80
+ header = header || this.header;
81
+ header["X-RequestDigest"] = this.securityToken;
82
+ var authOptions = {
83
+ method: "POST",
84
+ url: url,
85
+ data: JSON.stringify(data),
86
+ headers: header,
87
+ json: true,
88
+ };
89
+
90
+ return this.client(authOptions);
91
+
92
+ // return this.getSecurityValidation().then((ctx: any) => {
93
+ // this.securityToken = ctx.data.d.GetContextWebInformation.FormDigestValue;
94
+ // header["X-RequestDigest"] = this.securityToken;
95
+ // var authOptions = {
96
+ // method: "POST",
97
+ // url: url,
98
+ // data: JSON.stringify(data),
99
+ // headers: header,
100
+ // json: true,
101
+ // };
102
+
103
+ // return this.client(authOptions);
104
+ // });
105
+ };
106
+
107
+ public postWithOutStringify = (url: string, data: any, header?: any) => {
108
+ // debugger;
109
+ header = header || this.header;
110
+ header["X-RequestDigest"] = this.securityToken;
111
+ var authOptions = {
112
+ method: "POST",
113
+ url: url,
114
+ data: data,
115
+ headers: header,
116
+ json: true,
117
+ };
118
+
119
+ return this.client(authOptions);
120
+ };
121
+
122
+ public getSecurityValidation = () => {
123
+ var authOptions = {
124
+ method: "POST",
125
+ url: "/_api/contextinfo",
126
+ data: JSON.stringify({}),
127
+ headers: {
128
+ Accept: "application/json;odata=verbose",
129
+ "Content-Type": "application/json;odata=verbose",
130
+ },
131
+ json: true,
132
+ };
133
+ return this.client(authOptions);
134
+ };
135
+
136
+ public refreshSecurityValidation = async () => {
137
+ var authOptions = {
138
+ method: "POST",
139
+ url: "/_api/contextinfo",
140
+ data: JSON.stringify({}),
141
+ headers: {
142
+ Accept: "application/json;odata=verbose",
143
+ "Content-Type": "application/json;odata=verbose",
144
+ },
145
+ json: true,
146
+ };
147
+
148
+ await this.client(authOptions).then((context: any) => {
149
+ this.securityToken =
150
+ context.data.d.GetContextWebInformation.FormDigestValue;
151
+ // console.log("Token:- "+this.securityToken);
152
+ var interval = setInterval(() => {
153
+ this.refreshSecurityValidation();
154
+ clearInterval(interval);
155
+ }, 600000); //300000
156
+ });
157
+ };
158
+ }