@docbrasil/api-systemmanager 1.0.94 → 1.0.96

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 (58) hide show
  1. package/api/admin/doctypes.js +76 -76
  2. package/api/admin/document.js +332 -332
  3. package/api/admin/form.js +151 -151
  4. package/api/admin/index.js +46 -46
  5. package/api/admin/list.js +133 -133
  6. package/api/admin/message.js +194 -194
  7. package/api/admin/notification.js +233 -233
  8. package/api/admin/organization.js +124 -124
  9. package/api/admin/plugin.js +116 -116
  10. package/api/admin/policy.js +78 -78
  11. package/api/admin/processes.js +370 -370
  12. package/api/admin/task.js +125 -125
  13. package/api/admin/user.js +185 -185
  14. package/api/dispatch.js +101 -101
  15. package/api/general/geoLocation.js +88 -88
  16. package/api/general/index.js +23 -23
  17. package/api/login.js +267 -267
  18. package/api/session.js +85 -85
  19. package/api/user/datasource.js +144 -144
  20. package/api/user/document.js +730 -730
  21. package/api/user/index.js +39 -39
  22. package/api/user/notification.js +101 -101
  23. package/api/user/organization.js +230 -230
  24. package/api/user/process.js +191 -191
  25. package/api/user/register.js +205 -205
  26. package/api/user/task.js +201 -201
  27. package/api/user/task_available.js +135 -135
  28. package/api/user/user.js +287 -287
  29. package/api/utils/cypher.js +37 -37
  30. package/api/utils/promises.js +118 -118
  31. package/bundleRollup.js +158 -158
  32. package/dist/bundle.cjs +4875 -4875
  33. package/dist/bundle.mjs +1 -1
  34. package/doc/api.md +675 -337
  35. package/doc.md +653 -653
  36. package/helper/boom.js +487 -487
  37. package/helper/cryptojs.js +6067 -6067
  38. package/index.js +85 -85
  39. package/package-lock.json +4635 -4635
  40. package/package.json +68 -68
  41. package/readme.md +25 -25
  42. package/tests/admin/document.spec.js +45 -45
  43. package/tests/admin/form.spec.js +74 -74
  44. package/tests/admin/list.spec.js +86 -86
  45. package/tests/admin/message.js +92 -92
  46. package/tests/admin/notification.spec.js +174 -174
  47. package/tests/admin/pluginspec..js +71 -71
  48. package/tests/admin/policy.spec.js +71 -71
  49. package/tests/admin/processes.spec.js +119 -119
  50. package/tests/admin/users.spec.js +127 -127
  51. package/tests/documents.spec.js +164 -164
  52. package/tests/login.spec.js +91 -91
  53. package/tests/session.spec..js +58 -58
  54. package/tests/user/documents.js +164 -164
  55. package/tests/user/organization.js +122 -122
  56. package/tests/user/process.js +71 -71
  57. package/tests/user/task_available.js +75 -75
  58. package/tests/user/user.js +88 -88
@@ -1,230 +1,230 @@
1
- import _ from 'lodash';
2
- import Boom from '@hapi/boom';
3
- import Joi from 'joi';
4
- import Axios from 'axios';
5
-
6
- /**
7
- * Class for organizations, permission user
8
- * @class
9
- */
10
- class Organization {
11
-
12
- constructor(options) {
13
- Joi.assert(options, Joi.object().required());
14
- Joi.assert(options.parent, Joi.object().required());
15
-
16
- const self = this;
17
- self.parent = options.parent;
18
- self._client = self.parent.dispatch.getClient();
19
- }
20
-
21
- /**
22
- * @author Augusto Pissarra <abernardo.br@gmail.com>
23
- * @description Get the return data and check for errors
24
- * @param {object} retData Response HTTP
25
- * @return {*}
26
- * @private
27
- */
28
- _returnData(retData, def = {}) {
29
- if (retData.status !== 200) {
30
- throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
31
- } else {
32
- return _.get(retData, 'data', def);
33
- }
34
- }
35
-
36
- /**
37
- * @author CloudBrasil <abernardo.br@gmail.com>
38
- * @description Set header with new session
39
- * @param {string} session Session, token JWT
40
- * @return {object} header with new session
41
- * @private
42
- */
43
- _setHeader(session) {
44
- return {
45
- headers: {
46
- authorization: session,
47
- }
48
- };
49
- }
50
-
51
- /**
52
- * @author Augusto Pissarra <abernardo.br@gmail.com>
53
- * @description Find organization by id
54
- * @param {string} orgId ID of the organization to find (_id database)
55
- * @param {string} session Is token JWT
56
- * @public
57
- * @async
58
- * @example
59
- *
60
- * const API = require('@docbrasil/api-systemmanager');
61
- * const api = new API();
62
- * const orgId = '80443245000122';
63
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
64
- * await api.user.organization.findById(idCard, session);
65
- */
66
- async findById(orgId, session) {
67
- const self = this;
68
-
69
- try {
70
- Joi.assert(orgId, Joi.string().required(), 'orgId ID of the organization to find (_id database_');
71
- Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
72
-
73
- const apiCall = self._client.get(`/organizations/${orgId}`, self._setHeader(session));
74
- return self._returnData(await apiCall);
75
- } catch (ex) {
76
- throw ex;
77
- }
78
- }
79
-
80
- /**
81
- * @author Augusto Pissarra <abernardo.br@gmail.com>
82
- * @description Check if id card exist
83
- * @param {string} idcard Check if id card exist
84
- * @param {string} session Is token JWT
85
- * @public
86
- * @async
87
- * @example
88
- *
89
- * const API = require('@docbrasil/api-systemmanager');
90
- * const api = new API();
91
- * const idCard = '80443245000122';
92
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
93
- * await api.user.organization.idCardExist(idCard, session);
94
- */
95
- async idCardExist(idCard, session) {
96
- const self = this;
97
-
98
- try {
99
- Joi.assert(idCard, Joi.string().required(), 'Check if id card exist');
100
- Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
101
-
102
- const apiCall = self._client.get(`/organizations/exist/idcard/${idCard}`, self._setHeader(session));
103
- return self._returnData(await apiCall);
104
- } catch (ex) {
105
- throw ex;
106
- }
107
- }
108
-
109
- /**
110
- * @author CloudBrasil <abernardo.br@gmail.com>
111
- * @description Update avatar of organization by session of user not allow session user SU
112
- * @param {object} params Params to update avatar
113
- * @param {string} params.avatar Image in base64 to update
114
- * @param {string} params.type mimeType (image/png)
115
- * @param {string} session Is token JWT of user NOT allow SU
116
- * @return {Promise}
117
- * @public
118
- * @async
119
- * @example
120
- *
121
- * const API = require('@docbrasil/api-systemmanager');
122
- * const api = new API();
123
- * const params = {
124
- * avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
125
- * type: 'image/png',
126
- * };
127
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
128
- * await api.user.profile.updateAvatar(params, session);
129
- */
130
- async upsertAvatar(params = {}, session) {
131
- const self = this;
132
-
133
- try {
134
- Joi.assert(params, Joi.object().required());
135
- Joi.assert(params.avatar, Joi.string().required());
136
- Joi.assert(params.type, Joi.string().required());
137
- Joi.assert(session, Joi.string().required());
138
-
139
- const {avatar, type} = params;
140
- const payload = {avatar, type};
141
-
142
- const apiCall = self._client.put('/organizations/1234567890/logo', payload, self._setHeader(session));
143
- return self._returnData(await apiCall);
144
- } catch (ex) {
145
- throw ex;
146
- }
147
- }
148
-
149
- /**
150
- * @author CloudBrasil <abernardo.br@gmail.com>
151
- * @description Remove avatar of user by session of user not allow session user SU
152
- * @param {string} session Is token JWT of user NOT allow SU
153
- * @return {Promise}
154
- * @public
155
- * @async
156
- * @example
157
- *
158
- * const API = require('@docbrasil/api-systemmanager');
159
- * const api = new API();
160
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
161
- * await api.user.profile.removeAvatar(session);
162
- */
163
- async removeAvatar(session) {
164
- const self = this;
165
-
166
- try {
167
- Joi.assert(session, Joi.string().required());
168
-
169
- const apiCall = self._client.delete('/organizations/1234567890/logo', self._setHeader(session));
170
- return self._returnData(await apiCall);
171
- } catch (ex) {
172
- throw ex;
173
- }
174
- }
175
-
176
- /**
177
- * @author Thiago Anselmo <thiagoo.anselmoo@gmail.com>
178
- * @description Call URL internal, need auth JWT (session)
179
- * @param {!object} params Params to call fectch (URL internal)
180
- * @param {!string} params.url URL to call
181
- * @param {!string} [params.method=POST] Fetch Method
182
- * @param {string} params.payload Payload to send system manager
183
- * @returns {promise}
184
- * @public
185
- * @async
186
- * @example
187
- *
188
- * const API = require('@docbrasil/api-systemmanager');
189
- * const api = new API();
190
- *
191
- * const params = {
192
- * url: 'http://localhost:8080/organizations/..../process/..../task/candidateAccepted/end/....',
193
- * method: 'POST'
194
- * }
195
- * await api.user.organization.callFetchs(params, session);
196
- */
197
- async callFetch(params, session) {
198
- const self = this;
199
-
200
- try {
201
- Joi.assert(params, Joi.object().required(), 'Params to call fectch (URL internal)');
202
- Joi.assert(params.url, Joi.string().required(), 'URL to call');
203
- Joi.assert(params.method, Joi.string(), 'Fetch Method');
204
- Joi.assert(params.payload, Joi.object(), 'Payload to send system manager');
205
- Joi.assert(session, Joi.string().required(), 'Session to call');
206
-
207
- const {url, payload = {}} = params;
208
- let {method} = params;
209
-
210
- method = method.toLowerCase();
211
- const methodWithPayload = ['post', 'put'];
212
-
213
- const options = {
214
- method,
215
- headers: {authorization: session},
216
- url,
217
- };
218
-
219
- if (methodWithPayload.indexOf(method) !== -1)
220
- options.data = payload;
221
-
222
- return await self._returnData(await Axios(options));
223
-
224
- } catch (ex) {
225
- throw ex;
226
- }
227
- }
228
- }
229
-
230
- export default Organization;
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+ import Axios from 'axios';
5
+
6
+ /**
7
+ * Class for organizations, permission user
8
+ * @class
9
+ */
10
+ class Organization {
11
+
12
+ constructor(options) {
13
+ Joi.assert(options, Joi.object().required());
14
+ Joi.assert(options.parent, Joi.object().required());
15
+
16
+ const self = this;
17
+ self.parent = options.parent;
18
+ self._client = self.parent.dispatch.getClient();
19
+ }
20
+
21
+ /**
22
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
23
+ * @description Get the return data and check for errors
24
+ * @param {object} retData Response HTTP
25
+ * @return {*}
26
+ * @private
27
+ */
28
+ _returnData(retData, def = {}) {
29
+ if (retData.status !== 200) {
30
+ throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
31
+ } else {
32
+ return _.get(retData, 'data', def);
33
+ }
34
+ }
35
+
36
+ /**
37
+ * @author CloudBrasil <abernardo.br@gmail.com>
38
+ * @description Set header with new session
39
+ * @param {string} session Session, token JWT
40
+ * @return {object} header with new session
41
+ * @private
42
+ */
43
+ _setHeader(session) {
44
+ return {
45
+ headers: {
46
+ authorization: session,
47
+ }
48
+ };
49
+ }
50
+
51
+ /**
52
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
53
+ * @description Find organization by id
54
+ * @param {string} orgId ID of the organization to find (_id database)
55
+ * @param {string} session Is token JWT
56
+ * @public
57
+ * @async
58
+ * @example
59
+ *
60
+ * const API = require('@docbrasil/api-systemmanager');
61
+ * const api = new API();
62
+ * const orgId = '80443245000122';
63
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
64
+ * await api.user.organization.findById(idCard, session);
65
+ */
66
+ async findById(orgId, session) {
67
+ const self = this;
68
+
69
+ try {
70
+ Joi.assert(orgId, Joi.string().required(), 'orgId ID of the organization to find (_id database_');
71
+ Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
72
+
73
+ const apiCall = self._client.get(`/organizations/${orgId}`, self._setHeader(session));
74
+ return self._returnData(await apiCall);
75
+ } catch (ex) {
76
+ throw ex;
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
82
+ * @description Check if id card exist
83
+ * @param {string} idcard Check if id card exist
84
+ * @param {string} session Is token JWT
85
+ * @public
86
+ * @async
87
+ * @example
88
+ *
89
+ * const API = require('@docbrasil/api-systemmanager');
90
+ * const api = new API();
91
+ * const idCard = '80443245000122';
92
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
93
+ * await api.user.organization.idCardExist(idCard, session);
94
+ */
95
+ async idCardExist(idCard, session) {
96
+ const self = this;
97
+
98
+ try {
99
+ Joi.assert(idCard, Joi.string().required(), 'Check if id card exist');
100
+ Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
101
+
102
+ const apiCall = self._client.get(`/organizations/exist/idcard/${idCard}`, self._setHeader(session));
103
+ return self._returnData(await apiCall);
104
+ } catch (ex) {
105
+ throw ex;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * @author CloudBrasil <abernardo.br@gmail.com>
111
+ * @description Update avatar of organization by session of user not allow session user SU
112
+ * @param {object} params Params to update avatar
113
+ * @param {string} params.avatar Image in base64 to update
114
+ * @param {string} params.type mimeType (image/png)
115
+ * @param {string} session Is token JWT of user NOT allow SU
116
+ * @return {Promise}
117
+ * @public
118
+ * @async
119
+ * @example
120
+ *
121
+ * const API = require('@docbrasil/api-systemmanager');
122
+ * const api = new API();
123
+ * const params = {
124
+ * avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
125
+ * type: 'image/png',
126
+ * };
127
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
128
+ * await api.user.profile.updateAvatar(params, session);
129
+ */
130
+ async upsertAvatar(params = {}, session) {
131
+ const self = this;
132
+
133
+ try {
134
+ Joi.assert(params, Joi.object().required());
135
+ Joi.assert(params.avatar, Joi.string().required());
136
+ Joi.assert(params.type, Joi.string().required());
137
+ Joi.assert(session, Joi.string().required());
138
+
139
+ const {avatar, type} = params;
140
+ const payload = {avatar, type};
141
+
142
+ const apiCall = self._client.put('/organizations/1234567890/logo', payload, self._setHeader(session));
143
+ return self._returnData(await apiCall);
144
+ } catch (ex) {
145
+ throw ex;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @author CloudBrasil <abernardo.br@gmail.com>
151
+ * @description Remove avatar of user by session of user not allow session user SU
152
+ * @param {string} session Is token JWT of user NOT allow SU
153
+ * @return {Promise}
154
+ * @public
155
+ * @async
156
+ * @example
157
+ *
158
+ * const API = require('@docbrasil/api-systemmanager');
159
+ * const api = new API();
160
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
161
+ * await api.user.profile.removeAvatar(session);
162
+ */
163
+ async removeAvatar(session) {
164
+ const self = this;
165
+
166
+ try {
167
+ Joi.assert(session, Joi.string().required());
168
+
169
+ const apiCall = self._client.delete('/organizations/1234567890/logo', self._setHeader(session));
170
+ return self._returnData(await apiCall);
171
+ } catch (ex) {
172
+ throw ex;
173
+ }
174
+ }
175
+
176
+ /**
177
+ * @author Thiago Anselmo <thiagoo.anselmoo@gmail.com>
178
+ * @description Call URL internal, need auth JWT (session)
179
+ * @param {!object} params Params to call fectch (URL internal)
180
+ * @param {!string} params.url URL to call
181
+ * @param {!string} [params.method=POST] Fetch Method
182
+ * @param {string} params.payload Payload to send system manager
183
+ * @returns {promise}
184
+ * @public
185
+ * @async
186
+ * @example
187
+ *
188
+ * const API = require('@docbrasil/api-systemmanager');
189
+ * const api = new API();
190
+ *
191
+ * const params = {
192
+ * url: 'http://localhost:8080/organizations/..../process/..../task/candidateAccepted/end/....',
193
+ * method: 'POST'
194
+ * }
195
+ * await api.user.organization.callFetchs(params, session);
196
+ */
197
+ async callFetch(params, session) {
198
+ const self = this;
199
+
200
+ try {
201
+ Joi.assert(params, Joi.object().required(), 'Params to call fectch (URL internal)');
202
+ Joi.assert(params.url, Joi.string().required(), 'URL to call');
203
+ Joi.assert(params.method, Joi.string(), 'Fetch Method');
204
+ Joi.assert(params.payload, Joi.object(), 'Payload to send system manager');
205
+ Joi.assert(session, Joi.string().required(), 'Session to call');
206
+
207
+ const {url, payload = {}} = params;
208
+ let {method} = params;
209
+
210
+ method = method.toLowerCase();
211
+ const methodWithPayload = ['post', 'put'];
212
+
213
+ const options = {
214
+ method,
215
+ headers: {authorization: session},
216
+ url,
217
+ };
218
+
219
+ if (methodWithPayload.indexOf(method) !== -1)
220
+ options.data = payload;
221
+
222
+ return await self._returnData(await Axios(options));
223
+
224
+ } catch (ex) {
225
+ throw ex;
226
+ }
227
+ }
228
+ }
229
+
230
+ export default Organization;