@stackfactor/client-api 1.0.31 → 1.0.33

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/lib/role.js CHANGED
@@ -1,266 +1,259 @@
1
- import { axios } from "./axiosClient";
1
+ import axios from "./axiosClient";
2
2
 
3
- module.exports = {
4
- axios: axios,
5
-
6
- /**
7
- * Create role and set information
8
- * @param {Object} data
9
- * @param {String} token Authorization token
10
- */
11
- createRole: (data, token) => {
12
- return new Promise(function (resolve, reject) {
13
- let confirmationRequest = axios.put(
14
- "api/v1/roles",
15
- { data: data },
16
- {
17
- headers: { authorization: token },
18
- }
19
- );
20
- confirmationRequest
21
- .then((response) => {
22
- resolve(response.data);
23
- })
24
- .catch((error) => {
25
- reject(error);
26
- });
27
- });
28
- },
29
-
30
- /**
31
- * Create from from template
32
- * @param {String} templateId
33
- * @param {Object} data
34
- * @param {String} token Authorization token
35
- */
36
- createRoleFromTemplate: (templateId, data, token) => {
37
- return new Promise(function (resolve, reject) {
38
- const requestData = {
39
- templateId: templateId,
40
- data: data,
41
- };
42
- let confirmationRequest = axios.put(
43
- "api/v1/roles/createfromtemplate/",
44
- requestData,
45
- {
46
- headers: { authorization: token },
47
- }
48
- );
49
- confirmationRequest
50
- .then((response) => {
51
- resolve(response.data);
52
- })
53
- .catch((error) => {
54
- reject(error);
55
- });
56
- });
57
- },
58
-
59
- /**
60
- * Delete role
61
- * @param {String} id The id of the role to be deleted
62
- * @param {String} comment The comment included with the deletion
63
- * @param {String} token Authorization token
64
- */
65
- deleteRole: (id, comment, token) => {
66
- return new Promise(function (resolve, reject) {
67
- const data = {
68
- id: id,
69
- };
70
- if (comment) data.comment = comment;
71
- const request = axios.delete(`api/v1/roles/`, {
3
+ /**
4
+ * Create role and set information
5
+ * @param {Object} data
6
+ * @param {String} token Authorization token
7
+ */
8
+ export const createRole = (data, token) => {
9
+ return new Promise(function (resolve, reject) {
10
+ let confirmationRequest = axios.put(
11
+ "api/v1/roles",
12
+ { data: data },
13
+ {
72
14
  headers: { authorization: token },
73
- data: data,
15
+ }
16
+ );
17
+ confirmationRequest
18
+ .then((response) => {
19
+ resolve(response.data);
20
+ })
21
+ .catch((error) => {
22
+ reject(error);
74
23
  });
75
- request
76
- .then((response) => {
77
- resolve(response.data);
78
- })
79
- .catch((error) => {
80
- reject(error);
81
- });
82
- });
83
- },
24
+ });
25
+ };
84
26
 
85
- /**
86
- * Discard the role draft changes
87
- * @param {String} id The id of the role to be deleted
88
- * @param {String} token Authorization token
89
- */
90
- discardRoleChanges: (id, token) => {
91
- return new Promise(function (resolve, reject) {
92
- const data = {};
93
- const request = axios.get(`api/v1/roles/discard/${id}`, {
27
+ /**
28
+ * Create from from template
29
+ * @param {String} templateId
30
+ * @param {Object} data
31
+ * @param {String} token Authorization token
32
+ */
33
+ export const createRoleFromTemplate = (templateId, data, token) => {
34
+ return new Promise(function (resolve, reject) {
35
+ const requestData = {
36
+ templateId: templateId,
37
+ data: data,
38
+ };
39
+ let confirmationRequest = axios.put(
40
+ "api/v1/roles/createfromtemplate/",
41
+ requestData,
42
+ {
94
43
  headers: { authorization: token },
95
- data: data,
44
+ }
45
+ );
46
+ confirmationRequest
47
+ .then((response) => {
48
+ resolve(response.data);
49
+ })
50
+ .catch((error) => {
51
+ reject(error);
96
52
  });
97
- request
98
- .then((response) => {
99
- resolve(response.data);
100
- })
101
- .catch((error) => {
102
- reject(error);
103
- });
104
- });
105
- },
53
+ });
54
+ };
106
55
 
107
- /**
108
- * Get role information
109
- * @param {number} id The id of the role
110
- * @param {String} token Authorization token
111
- */
112
- getRoleInformationById: (id, version, token) => {
113
- return new Promise(function (resolve, reject) {
114
- let confirmationRequest = axios.get(
115
- `api/v1/roles/role/${id}/${version}`,
116
- {
117
- headers: { authorization: token },
118
- }
119
- );
120
- confirmationRequest
121
- .then((response) => {
122
- resolve(response.data);
123
- })
124
- .catch((error) => {
125
- reject(error);
126
- });
56
+ /**
57
+ * Delete role
58
+ * @param {String} id The id of the role to be deleted
59
+ * @param {String} comment The comment included with the deletion
60
+ * @param {String} token Authorization token
61
+ */
62
+ export const deleteRole = (id, comment, token) => {
63
+ return new Promise(function (resolve, reject) {
64
+ const data = {
65
+ id: id,
66
+ };
67
+ if (comment) data.comment = comment;
68
+ const request = axios.delete(`api/v1/roles/`, {
69
+ headers: { authorization: token },
70
+ data: data,
127
71
  });
128
- },
129
-
130
- /**
131
- * Get roles list
132
- * @param {Object} filter The filter used to select the roles
133
- * @param {String} version The version to be retrieved
134
- * @param {Boolean} includeDeleted If true it will return deleted records as well
135
- * @param {boolean} includeDetailedInformation If true it will return detailed information
136
- * @param {Boolean} returnDefaultIfVersionNotAvailable Return the default version if published not available
137
- * @param {String} token Authorization token
138
- */
139
- getRolesList: (
140
- filter,
141
- version,
142
- includeDeleted,
143
- includeDetailedInformation,
144
- returnDefaultIfVersionNotAvailable,
145
- token
146
- ) => {
147
- return new Promise(function (resolve, reject) {
148
- const requestData = {
149
- version: version,
150
- includeDeleted: includeDeleted,
151
- includeDetailedInformation: includeDetailedInformation,
152
- returnDefaultIfVersionNotAvailable: returnDefaultIfVersionNotAvailable,
153
- };
154
- if (filter) requestData.filter = filter;
155
- let confirmationRequest = axios.post(`api/v1/roles`, requestData, {
156
- headers: { authorization: token },
72
+ request
73
+ .then((response) => {
74
+ resolve(response.data);
75
+ })
76
+ .catch((error) => {
77
+ reject(error);
157
78
  });
158
- confirmationRequest
159
- .then((response) => {
160
- resolve(response.data);
161
- })
162
- .catch((error) => {
163
- reject(error);
164
- });
165
- });
166
- },
79
+ });
80
+ };
167
81
 
168
- /**
169
- * Publish role
170
- * @param {number} id The id of the role to be published
171
- * @param {String} comment The comment to be include with the request
172
- * @param {String} token Authorization token
173
- */
174
- publishRole: (id, comment, token) => {
175
- return new Promise(function (resolve, reject) {
176
- let data = {};
177
- if (comment) data.comment = comment;
178
- let confirmationRequest = axios.post(`api/v1/roles/publish/${id}`, data, {
179
- headers: { authorization: token },
180
- });
181
- confirmationRequest
182
- .then((response) => {
183
- resolve(response.data);
184
- })
185
- .catch((error) => {
186
- reject(error);
187
- });
82
+ /**
83
+ * Discard the role draft changes
84
+ * @param {String} id The id of the role to be deleted
85
+ * @param {String} token Authorization token
86
+ */
87
+ export const discardRoleChanges = (id, token) => {
88
+ return new Promise(function (resolve, reject) {
89
+ const data = {};
90
+ const request = axios.get(`api/v1/roles/discard/${id}`, {
91
+ headers: { authorization: token },
92
+ data: data,
188
93
  });
189
- },
94
+ request
95
+ .then((response) => {
96
+ resolve(response.data);
97
+ })
98
+ .catch((error) => {
99
+ reject(error);
100
+ });
101
+ });
102
+ };
190
103
 
191
- /**
192
- * Set role profile information
193
- * @param {String} id The id of the role to be updated
194
- * @param {Object} data Data used to update the role
195
- * @param {String} token Authorization token
196
- */
197
- setRoleInformation: (id, data, token) => {
198
- return new Promise(function (resolve, reject) {
199
- const requestData = {
200
- data: data,
201
- id: id,
202
- };
203
- let confirmationRequest = axios.post(`api/v1/roles/update`, requestData, {
204
- headers: { authorization: token },
104
+ /**
105
+ * Get role information
106
+ * @param {number} id The id of the role
107
+ * @param {String} token Authorization token
108
+ */
109
+ export const getRoleInformationById = (id, version, token) => {
110
+ return new Promise(function (resolve, reject) {
111
+ let confirmationRequest = axios.get(`api/v1/roles/role/${id}/${version}`, {
112
+ headers: { authorization: token },
113
+ });
114
+ confirmationRequest
115
+ .then((response) => {
116
+ resolve(response.data);
117
+ })
118
+ .catch((error) => {
119
+ reject(error);
205
120
  });
206
- confirmationRequest
207
- .then((response) => {
208
- resolve(response.data);
209
- })
210
- .catch((error) => {
211
- reject(error);
212
- });
121
+ });
122
+ };
123
+
124
+ /**
125
+ * Get roles list
126
+ * @param {Object} filter The filter used to select the roles
127
+ * @param {String} version The version to be retrieved
128
+ * @param {Boolean} includeDeleted If true it will return deleted records as well
129
+ * @param {boolean} includeDetailedInformation If true it will return detailed information
130
+ * @param {Boolean} returnDefaultIfVersionNotAvailable Return the default version if published not available
131
+ * @param {String} token Authorization token
132
+ */
133
+ export const getRolesList = (
134
+ filter,
135
+ version,
136
+ includeDeleted,
137
+ includeDetailedInformation,
138
+ returnDefaultIfVersionNotAvailable,
139
+ token
140
+ ) => {
141
+ return new Promise(function (resolve, reject) {
142
+ const requestData = {
143
+ version: version,
144
+ includeDeleted: includeDeleted,
145
+ includeDetailedInformation: includeDetailedInformation,
146
+ returnDefaultIfVersionNotAvailable: returnDefaultIfVersionNotAvailable,
147
+ };
148
+ if (filter) requestData.filter = filter;
149
+ let confirmationRequest = axios.post(`api/v1/roles`, requestData, {
150
+ headers: { authorization: token },
213
151
  });
214
- },
152
+ confirmationRequest
153
+ .then((response) => {
154
+ resolve(response.data);
155
+ })
156
+ .catch((error) => {
157
+ reject(error);
158
+ });
159
+ });
160
+ };
215
161
 
216
- /**
217
- * Set user roles
218
- * @param {String} id
219
- * @param {Array<Object>} roles
220
- * @param {String} token
221
- */
222
- setUserRoles: (id, roles, roleDescription, token) => {
223
- return new Promise(function (resolve, reject) {
224
- const requestData = {
225
- roles: roles,
226
- roleDescription: roleDescription,
227
- };
228
- if (id) requestData.userid = id;
229
- let request = axios.post(`api/v1/roles/settouser/`, requestData, {
230
- headers: { authorization: token },
162
+ /**
163
+ * Publish role
164
+ * @param {number} id The id of the role to be published
165
+ * @param {String} comment The comment to be include with the request
166
+ * @param {String} token Authorization token
167
+ */
168
+ export const publishRole = (id, comment, token) => {
169
+ return new Promise(function (resolve, reject) {
170
+ let data = {};
171
+ if (comment) data.comment = comment;
172
+ let confirmationRequest = axios.post(`api/v1/roles/publish/${id}`, data, {
173
+ headers: { authorization: token },
174
+ });
175
+ confirmationRequest
176
+ .then((response) => {
177
+ resolve(response.data);
178
+ })
179
+ .catch((error) => {
180
+ reject(error);
231
181
  });
232
- request
233
- .then((response) => {
234
- resolve(response.data);
235
- })
236
- .catch((error) => {
237
- reject(error);
238
- });
182
+ });
183
+ };
184
+
185
+ /**
186
+ * Set role profile information
187
+ * @param {String} id The id of the role to be updated
188
+ * @param {Object} data Data used to update the role
189
+ * @param {String} token Authorization token
190
+ */
191
+ export const setRoleInformation = (id, data, token) => {
192
+ return new Promise(function (resolve, reject) {
193
+ const requestData = {
194
+ data: data,
195
+ id: id,
196
+ };
197
+ let confirmationRequest = axios.post(`api/v1/roles/update`, requestData, {
198
+ headers: { authorization: token },
239
199
  });
240
- },
200
+ confirmationRequest
201
+ .then((response) => {
202
+ resolve(response.data);
203
+ })
204
+ .catch((error) => {
205
+ reject(error);
206
+ });
207
+ });
208
+ };
241
209
 
242
- /**
243
- * Watch role
244
- * @param {String} id The id of the skill to be updated
245
- * @param {Boolean} watch Set to true or false
246
- * @param {String} token Authorization token
247
- */
248
- watchRole: (id, watch, token) => {
249
- return new Promise(function (resolve, reject) {
250
- const requestData = {
251
- id: id,
252
- watch: watch,
253
- };
254
- let confirmationRequest = axios.post(`api/v1/roles/watch`, requestData, {
255
- headers: { authorization: token },
210
+ /**
211
+ * Set user roles
212
+ * @param {String} id
213
+ * @param {Array<Object>} roles
214
+ * @param {String} token
215
+ */
216
+ export const setUserRoles = (id, roles, roleDescription, token) => {
217
+ return new Promise(function (resolve, reject) {
218
+ const requestData = {
219
+ roles: roles,
220
+ roleDescription: roleDescription,
221
+ };
222
+ if (id) requestData.userid = id;
223
+ let request = axios.post(`api/v1/roles/settouser/`, requestData, {
224
+ headers: { authorization: token },
225
+ });
226
+ request
227
+ .then((response) => {
228
+ resolve(response.data);
229
+ })
230
+ .catch((error) => {
231
+ reject(error);
256
232
  });
257
- confirmationRequest
258
- .then((response) => {
259
- resolve(response.data);
260
- })
261
- .catch((error) => {
262
- reject(error);
263
- });
233
+ });
234
+ };
235
+
236
+ /**
237
+ * Watch role
238
+ * @param {String} id The id of the skill to be updated
239
+ * @param {Boolean} watch Set to true or false
240
+ * @param {String} token Authorization token
241
+ */
242
+ export const watchRole = (id, watch, token) => {
243
+ return new Promise(function (resolve, reject) {
244
+ const requestData = {
245
+ id: id,
246
+ watch: watch,
247
+ };
248
+ let confirmationRequest = axios.post(`api/v1/roles/watch`, requestData, {
249
+ headers: { authorization: token },
264
250
  });
265
- },
251
+ confirmationRequest
252
+ .then((response) => {
253
+ resolve(response.data);
254
+ })
255
+ .catch((error) => {
256
+ reject(error);
257
+ });
258
+ });
266
259
  };