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.
@@ -1,15 +1,15 @@
1
- import { IJitzSPContext } from "../jitzSPHttpClient";
2
- import { IPersonOrGroup } from "../common/IModels";
3
- export default class UserService {
4
- private _context;
5
- private _webAbsoluteUrl;
6
- constructor(context: IJitzSPContext);
7
- getCurrentUser: () => any;
8
- getUserProperties: (accountName: string) => Promise<any>;
9
- getUserPropertiesByEmail: (email: string) => Promise<any>;
10
- getCurrentUserGroups(): Promise<IPersonOrGroup[]>;
11
- checkIfCurrentUserInGroup(groupName: string): Promise<boolean>;
12
- checkIfUserIsInGroup(userId: number, groupName: string): Promise<boolean>;
13
- getUserById: (id: number) => any;
14
- getCurrentUserPermissions: () => any;
15
- }
1
+ import { IJitzSPContext } from "../jitzSPHttpClient";
2
+ import { IPersonOrGroup } from "../common/IModels";
3
+ export default class UserService {
4
+ private _context;
5
+ private _webAbsoluteUrl;
6
+ constructor(context: IJitzSPContext);
7
+ getCurrentUser: () => any;
8
+ getUserProperties: (accountName: string) => Promise<any>;
9
+ getUserPropertiesByEmail: (email: string) => Promise<any>;
10
+ getCurrentUserGroups(): Promise<IPersonOrGroup[]>;
11
+ checkIfCurrentUserInGroup(groupName: string): Promise<boolean>;
12
+ checkIfUserIsInGroup(userId: number, groupName: string): Promise<boolean>;
13
+ getUserById: (id: number) => any;
14
+ getCurrentUserPermissions: () => any;
15
+ }
@@ -1,202 +1,202 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var UserService = /** @class */ (function () {
4
- function UserService(context) {
5
- var _this = this;
6
- this.getCurrentUser = function () {
7
- return _this._context.client
8
- .get(_this._webAbsoluteUrl + "/_api/web/CurrentUser/?$expand=groups")
9
- .then(function (response) {
10
- if (response.status >= 200 && response.status <= 300) {
11
- return response.data.d;
12
- }
13
- else {
14
- return Promise.reject(new Error(JSON.stringify(response)));
15
- }
16
- })
17
- .then(function (data) {
18
- var user = {
19
- Id: data.Id,
20
- Email: data.Email,
21
- EMail: data.EMail,
22
- Name: data.Name,
23
- LoginName: data.LoginName,
24
- Title: data.Title,
25
- IsGroup: false,
26
- };
27
- var groups = [];
28
- if (data.Groups != undefined && data.Groups.results != undefined) {
29
- data.Groups.results.map(function (group) {
30
- groups.push({
31
- Id: group.Id,
32
- Email: "",
33
- EMail: "",
34
- Name: group.Name,
35
- IsGroup: true,
36
- LoginName: group.LoginName,
37
- Title: group.Title,
38
- });
39
- });
40
- }
41
- user.Groups = groups;
42
- return user;
43
- });
44
- };
45
- this.getUserProperties = function (accountName) {
46
- return _this._context.client
47
- .get(_this._webAbsoluteUrl +
48
- ("/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'"))
49
- .then(function (response) {
50
- if (response.status >= 200 && response.status <= 300) {
51
- return response.data.d;
52
- }
53
- else {
54
- return Promise.reject(new Error(JSON.stringify(response)));
55
- }
56
- })
57
- .then(function (data) {
58
- return data;
59
- });
60
- };
61
- this.getUserPropertiesByEmail = function (email) {
62
- return _this._context.client
63
- .get(_this._webAbsoluteUrl + ("/_api/Web/SiteUsers?$filter=Email eq '" + email + "'"))
64
- .then(function (response) {
65
- if (response.status >= 200 && response.status <= 300) {
66
- return response.data.d;
67
- }
68
- else {
69
- return Promise.reject(new Error(JSON.stringify(response)));
70
- }
71
- })
72
- .then(function (data) {
73
- return data;
74
- });
75
- };
76
- this.getUserById = function (id) {
77
- return _this._context.client
78
- .get(_this._webAbsoluteUrl + ("/_api/web/getUserById(" + id + ")?$expand=groups"))
79
- .then(function (response) {
80
- if (response.status >= 200 && response.status <= 300) {
81
- return response.data.d;
82
- }
83
- else {
84
- return Promise.reject(new Error(JSON.stringify(response)));
85
- }
86
- })
87
- .then(function (data) {
88
- var user = {
89
- Id: data.Id,
90
- Email: data.Email,
91
- EMail: data.EMail,
92
- Name: data.Name,
93
- LoginName: data.LoginName,
94
- Title: data.Title,
95
- IsGroup: false,
96
- };
97
- var groups = [];
98
- if (data.Groups != undefined && data.Groups.results != undefined) {
99
- data.Groups.results.map(function (group) {
100
- groups.push({
101
- Id: group.Id,
102
- Email: "",
103
- EMail: "",
104
- Name: group.Name,
105
- IsGroup: true,
106
- LoginName: group.LoginName,
107
- Title: group.Title,
108
- });
109
- });
110
- }
111
- user.Groups = groups;
112
- return user;
113
- });
114
- };
115
- this.getCurrentUserPermissions = function () {
116
- var requestUrl = _this._context.siteUrl + "/_api/Web/effectiveBasePermissions";
117
- return _this._context.client
118
- .get(requestUrl)
119
- .then(function (response) {
120
- if (response.status >= 200 && response.status <= 300) {
121
- return response.data.d;
122
- }
123
- else {
124
- return Promise.reject(new Error(JSON.stringify(response)));
125
- }
126
- })
127
- .then(function (data) {
128
- return data;
129
- });
130
- };
131
- this._context = context;
132
- this._webAbsoluteUrl = context.siteUrl;
133
- }
134
- UserService.prototype.getCurrentUserGroups = function () {
135
- var requestUrl = this._context.siteUrl + "/_api/web/currentuser/?$expand=groups";
136
- return this._context.client
137
- .get(requestUrl)
138
- .then(function (response) {
139
- if (response.status >= 200 && response.status <= 300) {
140
- return response.data.d;
141
- }
142
- else {
143
- return Promise.reject(new Error(JSON.stringify(response)));
144
- }
145
- })
146
- .then(function (data) {
147
- var groups = [];
148
- data.Groups.results.map(function (group) {
149
- groups.push({
150
- Id: group.Id,
151
- Email: "",
152
- EMail: "",
153
- Name: group.Name,
154
- IsGroup: true,
155
- LoginName: group.LoginName,
156
- Title: group.Title,
157
- });
158
- });
159
- return groups;
160
- });
161
- };
162
- UserService.prototype.checkIfCurrentUserInGroup = function (groupName) {
163
- var requestUrl = this._context.siteUrl + "/_api/web/currentuser/?$expand=groups";
164
- return this._context.client
165
- .get(requestUrl)
166
- .then(function (response) {
167
- if (response.status >= 200 && response.status <= 300) {
168
- return response.data.d;
169
- }
170
- else {
171
- return Promise.reject(new Error(JSON.stringify(response)));
172
- }
173
- })
174
- .then(function (data) {
175
- var filteredArr = data.Groups.filter(function (g) {
176
- return g.Title == groupName;
177
- });
178
- return filteredArr.length > 0;
179
- });
180
- };
181
- UserService.prototype.checkIfUserIsInGroup = function (userId, groupName) {
182
- var requestUrl = this._context.siteUrl + "/_api/web/getUserById(" + userId + ")?$expand=groups";
183
- return this._context.client
184
- .get(requestUrl)
185
- .then(function (response) {
186
- if (response.status >= 200 && response.status <= 300) {
187
- return response.data.d;
188
- }
189
- else {
190
- return Promise.reject(new Error(JSON.stringify(response)));
191
- }
192
- })
193
- .then(function (data) {
194
- var filteredArr = data.Groups.filter(function (g) {
195
- return g.Title == groupName;
196
- });
197
- return filteredArr.length > 0;
198
- });
199
- };
200
- return UserService;
201
- }());
202
- exports.default = UserService;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var UserService = /** @class */ (function () {
4
+ function UserService(context) {
5
+ var _this = this;
6
+ this.getCurrentUser = function () {
7
+ return _this._context.client
8
+ .get(_this._webAbsoluteUrl + "/_api/web/CurrentUser/?$expand=groups")
9
+ .then(function (response) {
10
+ if (response.status >= 200 && response.status <= 300) {
11
+ return response.data.d;
12
+ }
13
+ else {
14
+ return Promise.reject(new Error(JSON.stringify(response)));
15
+ }
16
+ })
17
+ .then(function (data) {
18
+ var user = {
19
+ Id: data.Id,
20
+ Email: data.Email,
21
+ EMail: data.EMail,
22
+ Name: data.Name,
23
+ LoginName: data.LoginName,
24
+ Title: data.Title,
25
+ IsGroup: false,
26
+ };
27
+ var groups = [];
28
+ if (data.Groups != undefined && data.Groups.results != undefined) {
29
+ data.Groups.results.map(function (group) {
30
+ groups.push({
31
+ Id: group.Id,
32
+ Email: "",
33
+ EMail: "",
34
+ Name: group.Name,
35
+ IsGroup: true,
36
+ LoginName: group.LoginName,
37
+ Title: group.Title,
38
+ });
39
+ });
40
+ }
41
+ user.Groups = groups;
42
+ return user;
43
+ });
44
+ };
45
+ this.getUserProperties = function (accountName) {
46
+ return _this._context.client
47
+ .get(_this._webAbsoluteUrl +
48
+ ("/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'"))
49
+ .then(function (response) {
50
+ if (response.status >= 200 && response.status <= 300) {
51
+ return response.data.d;
52
+ }
53
+ else {
54
+ return Promise.reject(new Error(JSON.stringify(response)));
55
+ }
56
+ })
57
+ .then(function (data) {
58
+ return data;
59
+ });
60
+ };
61
+ this.getUserPropertiesByEmail = function (email) {
62
+ return _this._context.client
63
+ .get(_this._webAbsoluteUrl + ("/_api/Web/SiteUsers?$filter=Email eq '" + email + "'"))
64
+ .then(function (response) {
65
+ if (response.status >= 200 && response.status <= 300) {
66
+ return response.data.d;
67
+ }
68
+ else {
69
+ return Promise.reject(new Error(JSON.stringify(response)));
70
+ }
71
+ })
72
+ .then(function (data) {
73
+ return data;
74
+ });
75
+ };
76
+ this.getUserById = function (id) {
77
+ return _this._context.client
78
+ .get(_this._webAbsoluteUrl + ("/_api/web/getUserById(" + id + ")?$expand=groups"))
79
+ .then(function (response) {
80
+ if (response.status >= 200 && response.status <= 300) {
81
+ return response.data.d;
82
+ }
83
+ else {
84
+ return Promise.reject(new Error(JSON.stringify(response)));
85
+ }
86
+ })
87
+ .then(function (data) {
88
+ var user = {
89
+ Id: data.Id,
90
+ Email: data.Email,
91
+ EMail: data.EMail,
92
+ Name: data.Name,
93
+ LoginName: data.LoginName,
94
+ Title: data.Title,
95
+ IsGroup: false,
96
+ };
97
+ var groups = [];
98
+ if (data.Groups != undefined && data.Groups.results != undefined) {
99
+ data.Groups.results.map(function (group) {
100
+ groups.push({
101
+ Id: group.Id,
102
+ Email: "",
103
+ EMail: "",
104
+ Name: group.Name,
105
+ IsGroup: true,
106
+ LoginName: group.LoginName,
107
+ Title: group.Title,
108
+ });
109
+ });
110
+ }
111
+ user.Groups = groups;
112
+ return user;
113
+ });
114
+ };
115
+ this.getCurrentUserPermissions = function () {
116
+ var requestUrl = _this._context.siteUrl + "/_api/Web/effectiveBasePermissions";
117
+ return _this._context.client
118
+ .get(requestUrl)
119
+ .then(function (response) {
120
+ if (response.status >= 200 && response.status <= 300) {
121
+ return response.data.d;
122
+ }
123
+ else {
124
+ return Promise.reject(new Error(JSON.stringify(response)));
125
+ }
126
+ })
127
+ .then(function (data) {
128
+ return data;
129
+ });
130
+ };
131
+ this._context = context;
132
+ this._webAbsoluteUrl = context.siteUrl;
133
+ }
134
+ UserService.prototype.getCurrentUserGroups = function () {
135
+ var requestUrl = this._context.siteUrl + "/_api/web/currentuser/?$expand=groups";
136
+ return this._context.client
137
+ .get(requestUrl)
138
+ .then(function (response) {
139
+ if (response.status >= 200 && response.status <= 300) {
140
+ return response.data.d;
141
+ }
142
+ else {
143
+ return Promise.reject(new Error(JSON.stringify(response)));
144
+ }
145
+ })
146
+ .then(function (data) {
147
+ var groups = [];
148
+ data.Groups.results.map(function (group) {
149
+ groups.push({
150
+ Id: group.Id,
151
+ Email: "",
152
+ EMail: "",
153
+ Name: group.Name,
154
+ IsGroup: true,
155
+ LoginName: group.LoginName,
156
+ Title: group.Title,
157
+ });
158
+ });
159
+ return groups;
160
+ });
161
+ };
162
+ UserService.prototype.checkIfCurrentUserInGroup = function (groupName) {
163
+ var requestUrl = this._context.siteUrl + "/_api/web/currentuser/?$expand=groups";
164
+ return this._context.client
165
+ .get(requestUrl)
166
+ .then(function (response) {
167
+ if (response.status >= 200 && response.status <= 300) {
168
+ return response.data.d;
169
+ }
170
+ else {
171
+ return Promise.reject(new Error(JSON.stringify(response)));
172
+ }
173
+ })
174
+ .then(function (data) {
175
+ var filteredArr = data.Groups.filter(function (g) {
176
+ return g.Title == groupName;
177
+ });
178
+ return filteredArr.length > 0;
179
+ });
180
+ };
181
+ UserService.prototype.checkIfUserIsInGroup = function (userId, groupName) {
182
+ var requestUrl = this._context.siteUrl + "/_api/web/getUserById(" + userId + ")?$expand=groups";
183
+ return this._context.client
184
+ .get(requestUrl)
185
+ .then(function (response) {
186
+ if (response.status >= 200 && response.status <= 300) {
187
+ return response.data.d;
188
+ }
189
+ else {
190
+ return Promise.reject(new Error(JSON.stringify(response)));
191
+ }
192
+ })
193
+ .then(function (data) {
194
+ var filteredArr = data.Groups.filter(function (g) {
195
+ return g.Title == groupName;
196
+ });
197
+ return filteredArr.length > 0;
198
+ });
199
+ };
200
+ return UserService;
201
+ }());
202
+ exports.default = UserService;
@@ -1,22 +1,22 @@
1
- import { IJitzSPContext } from "../jitzSPHttpClient";
2
- export default class UtilityService {
3
- private _context;
4
- private _webAbsoluteUrl;
5
- constructor(context: IJitzSPContext);
6
- static monthNames: string[];
7
- static monthNamesFull: string[];
8
- static setCookie: (name: string, val: string, validMinutes?: number) => void;
9
- static getCookie: (name: string) => string | undefined;
10
- static deleteCookie: (name: string) => void;
11
- static formatDate: (date: Date) => string;
12
- static formatDateToMonthAndDate: (date: Date) => string;
13
- static getMonthFullNameOfTheDate: (date: Date) => string;
14
- static getMonthOfTheDate: (date: Date) => string;
15
- static addMonthsToDate: (date: Date, months: number) => Date;
16
- static addDaysToDate: (date: Date, days: number) => Date;
17
- static addHoursToDate: (date: Date, hours: number) => Date;
18
- static addMinutesToDate: (date: Date, minutes: number) => Date;
19
- static generateGUID: () => string;
20
- static exportJsonAsExcelSheet: (json: any[], fileTitle: string) => void;
21
- static LightenDarkenColor: (col: string, amt: number) => string;
22
- }
1
+ import { IJitzSPContext } from "../jitzSPHttpClient";
2
+ export default class UtilityService {
3
+ private _context;
4
+ private _webAbsoluteUrl;
5
+ constructor(context: IJitzSPContext);
6
+ static monthNames: string[];
7
+ static monthNamesFull: string[];
8
+ static setCookie: (name: string, val: string, validMinutes?: number) => void;
9
+ static getCookie: (name: string) => string | undefined;
10
+ static deleteCookie: (name: string) => void;
11
+ static formatDate: (date: Date) => string;
12
+ static formatDateToMonthAndDate: (date: Date) => string;
13
+ static getMonthFullNameOfTheDate: (date: Date) => string;
14
+ static getMonthOfTheDate: (date: Date) => string;
15
+ static addMonthsToDate: (date: Date, months: number) => Date;
16
+ static addDaysToDate: (date: Date, days: number) => Date;
17
+ static addHoursToDate: (date: Date, hours: number) => Date;
18
+ static addMinutesToDate: (date: Date, minutes: number) => Date;
19
+ static generateGUID: () => string;
20
+ static exportJsonAsExcelSheet: (json: any[], fileTitle: string) => void;
21
+ static LightenDarkenColor: (col: string, amt: number) => string;
22
+ }