@docbrasil/api-systemmanager 1.0.97 → 1.0.99

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 (59) 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/external.js +86 -0
  16. package/api/general/geoLocation.js +88 -88
  17. package/api/general/index.js +23 -23
  18. package/api/login.js +267 -267
  19. package/api/session.js +85 -85
  20. package/api/user/datasource.js +144 -144
  21. package/api/user/document.js +730 -730
  22. package/api/user/index.js +39 -39
  23. package/api/user/notification.js +101 -101
  24. package/api/user/organization.js +230 -230
  25. package/api/user/process.js +191 -191
  26. package/api/user/register.js +205 -205
  27. package/api/user/task.js +201 -202
  28. package/api/user/task_available.js +135 -135
  29. package/api/user/user.js +287 -287
  30. package/api/utils/cypher.js +37 -37
  31. package/api/utils/promises.js +118 -118
  32. package/bundleRollup.js +158 -158
  33. package/dist/bundle.cjs +4957 -4876
  34. package/dist/bundle.mjs +1 -1
  35. package/doc/api.md +2453 -2453
  36. package/doc.md +653 -653
  37. package/helper/boom.js +487 -487
  38. package/helper/cryptojs.js +6067 -6067
  39. package/index.js +87 -85
  40. package/package-lock.json +4635 -4635
  41. package/package.json +68 -68
  42. package/readme.md +25 -25
  43. package/tests/admin/document.spec.js +45 -45
  44. package/tests/admin/form.spec.js +74 -74
  45. package/tests/admin/list.spec.js +86 -86
  46. package/tests/admin/message.js +92 -92
  47. package/tests/admin/notification.spec.js +174 -174
  48. package/tests/admin/pluginspec..js +71 -71
  49. package/tests/admin/policy.spec.js +71 -71
  50. package/tests/admin/processes.spec.js +119 -119
  51. package/tests/admin/users.spec.js +127 -127
  52. package/tests/documents.spec.js +164 -164
  53. package/tests/login.spec.js +91 -91
  54. package/tests/session.spec..js +58 -58
  55. package/tests/user/documents.js +164 -164
  56. package/tests/user/organization.js +122 -122
  57. package/tests/user/process.js +71 -71
  58. package/tests/user/task_available.js +75 -75
  59. package/tests/user/user.js +88 -88
@@ -1,233 +1,233 @@
1
- import _ from 'lodash';
2
- import Boom from '@hapi/boom';
3
- import Joi from 'joi';
4
-
5
- /**
6
- * Admin Class for notification, permission admin
7
- * @class
8
- */
9
- class AdminNotification {
10
-
11
- constructor(options) {
12
- Joi.assert(options, Joi.object().required());
13
- Joi.assert(options.parent, Joi.object().required());
14
-
15
- const self = this;
16
- self.parent = options.parent;
17
- self.client = self.parent.dispatch.getClient();
18
- }
19
-
20
- /**
21
- * @author Augusto Pissarra <abernardo.br@gmail.com>
22
- * @description Get the return data and check for errors
23
- * @param {object} retData Response HTTP
24
- * @return {*}
25
- * @private
26
- */
27
- _returnData(retData, def = {}) {
28
- if (retData.status !== 200) {
29
- return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
30
- } else {
31
- return _.get(retData, 'data', def);
32
- }
33
- }
34
-
35
- /**
36
- * @author CloudBrasil <abernardo.br@gmail.com>
37
- * @description Set header with new session
38
- * @param {string} session Session, token JWT
39
- * @return {object} header with new session
40
- * @private
41
- */
42
- _setHeader(session) {
43
- return {
44
- headers: {
45
- authorization: session,
46
- }
47
- };
48
- }
49
-
50
- /**
51
- * @description Send real time notification
52
- * @param {object} params Params to send notification
53
- * @param {string} params.userIds Users to send notification
54
- * @param {object} params.message Object with data to send user
55
- * @param {object} session Session, token JWT
56
- * @returns {Promise<*>}
57
- */
58
- async realTime(params, session) {
59
- const self = this;
60
-
61
- try {
62
- Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
63
- Joi.assert(params.userIds, Joi.array().required(), 'OrgId of the user SU');
64
- Joi.assert(params.message, Joi.object().required(), 'Object with data to send user');
65
- Joi.assert(session, Joi.string().required(), 'Session, token JWT');
66
-
67
- const apiCall = self.client.post(`/admin/send/notifications`, params, self._setHeader(session));
68
- return self._returnData(await apiCall);
69
- } catch (ex) {
70
- throw ex;
71
- }
72
- }
73
-
74
- /**
75
- * @author CloudBrasil <abernardo.br@gmail.com>
76
- * @description Create notification
77
- * @param {object} params Params to create notification
78
- * @param {string} params.orgId OrgId of the user SU
79
- * @param {string} params.userId User to create notification
80
- * @param {object} params.message Object with data to send user
81
- * @param {string} session Session, token JWT
82
- * @return {Promise}
83
- * @public
84
- * @async
85
- * @example
86
- *
87
- * const API = require('@docbrasil/api-systemmanager');
88
- * const api = new API();
89
- * const params = {
90
- * orgId: '5edd11c46b6ce9729c2c297c',
91
- * userId: '55e4a3bd6be6b45210833fae',
92
- * message: 'Olá como vai tudo bem?'
93
- * };
94
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
95
- * await api.admin.notifications.add(params, session);
96
- */
97
- async add(params, session) {
98
- const self = this;
99
-
100
- try {
101
- Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
102
- Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
103
- Joi.assert(params.userId, Joi.string().required(), 'User to create notification');
104
- Joi.assert(params.message, Joi.object().required(), 'Object with data to send user');
105
- Joi.assert(session, Joi.string().required(), 'Session, token JWT');
106
-
107
- const {orgId, ...notificationPayload} = params;
108
- const apiCall = self.client.post(`/admin/organizations/${orgId}/notifications`, notificationPayload, self._setHeader(session));
109
- return self._returnData(await apiCall);
110
- } catch (ex) {
111
- throw ex;
112
- }
113
- }
114
-
115
- /**
116
- * @author CloudBrasil <abernardo.br@gmail.com>
117
- * @description Search notification using (notificationId or userId)
118
- * @param {object} params Params to create notification
119
- * @param {string} params.orgId OrgId of the user SU
120
- * @param {string} params.id ALERT! Id is userId or id is notificationId
121
- * @param {string} session Session, token JWT
122
- * @return {Promise}
123
- * @public
124
- * @async
125
- * @example
126
- *
127
- * const API = require('@docbrasil/api-systemmanager');
128
- * const api = new API();
129
- * const params = {
130
- * orgId: '5edd11c46b6ce9729c2c297c',
131
- * id: '55e4a3bd6be6b45210833fae',
132
- * };
133
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
134
- * await api.admin.notifications.findById(params, session);
135
- */
136
- async findById(params, session) {
137
- const self = this;
138
-
139
- try {
140
- Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
141
- Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
142
- Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
143
- Joi.assert(session, Joi.string().required(), 'Session, token JWT');
144
-
145
- const {orgId, id} = params;
146
- const apiCall = self.client.get(`/admin/organizations/${orgId}/notifications/${id}`, self._setHeader(session));
147
- return self._returnData(await apiCall);
148
- } catch (ex) {
149
- throw ex;
150
- }
151
- }
152
-
153
- /**
154
- * @author CloudBrasil <abernardo.br@gmail.com>
155
- * @description Update notification using (notificationId or userId)
156
- * @param {object} params Params to create notification
157
- * @param {string} params.orgId OrgId of the user SU
158
- * @param {string} params.id ALERT! Id is userId or id is notificationId
159
- * @param {boolean} params.read If message is read true or false
160
- * @param {string} session Session, token JWT
161
- * @return {Promise}
162
- * @public
163
- * @async
164
- * @example
165
- *
166
- * const API = require('@docbrasil/api-systemmanager');
167
- * const api = new API();
168
- * const params = {
169
- * orgId: '5edd11c46b6ce9729c2c297c',
170
- * id: '55e4a3bd6be6b45210833fae',
171
- * read: true
172
- * };
173
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
174
- * await api.admin.notifications.findByIdAndUpdate(params, session);
175
- */
176
- async findByIdAndUpdate(params, session) {
177
- const self = this;
178
-
179
- try {
180
- Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
181
- Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
182
- Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
183
- Joi.assert(params.read, Joi.boolean().required(), 'If message is read true or false');
184
- Joi.assert(session, Joi.string().required(), 'Session, token JWT');
185
-
186
- const {orgId, id, ...statusPayload} = params;
187
- const apiCall = self.client.put(`/admin/organizations/${orgId}/notifications/${id}`, statusPayload, self._setHeader(session));
188
- return self._returnData(await apiCall);
189
- } catch (ex) {
190
- throw ex;
191
- }
192
- }
193
-
194
- /**
195
- * @author CloudBrasil <abernardo.br@gmail.com>
196
- * @description Delete notification using (notificationId or userId)
197
- * @param {object} params Params to create notification
198
- * @param {string} params.orgId OrgId of the user SU
199
- * @param {string} params.id ALERT! Id is userId or id is notificationId
200
- * @param {string} session Session, token JWT
201
- * @return {Promise}
202
- * @public
203
- * @async
204
- * @example
205
- *
206
- * const API = require('@docbrasil/api-systemmanager');
207
- * const api = new API();
208
- * const params = {
209
- * orgId: '5edd11c46b6ce9729c2c297c',
210
- * id: '55e4a3bd6be6b45210833fae',
211
- * };
212
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
213
- * await api.admin.notifications.findByIdAndDelete(params, session);
214
- */
215
- async findByIdAndRemove(params, session) {
216
- const self = this;
217
-
218
- try {
219
- Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
220
- Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
221
- Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
222
- Joi.assert(session, Joi.string().required(), 'Session, token JWT');
223
-
224
- const {orgId, id} = params;
225
- const apiCall = self.client.delete(`/admin/organizations/${orgId}/notifications/${id}`, self._setHeader(session));
226
- return self._returnData(await apiCall);
227
- } catch (ex) {
228
- throw ex;
229
- }
230
- }
231
- }
232
-
233
- export default AdminNotification;
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Admin Class for notification, permission admin
7
+ * @class
8
+ */
9
+ class AdminNotification {
10
+
11
+ constructor(options) {
12
+ Joi.assert(options, Joi.object().required());
13
+ Joi.assert(options.parent, Joi.object().required());
14
+
15
+ const self = this;
16
+ self.parent = options.parent;
17
+ self.client = self.parent.dispatch.getClient();
18
+ }
19
+
20
+ /**
21
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
22
+ * @description Get the return data and check for errors
23
+ * @param {object} retData Response HTTP
24
+ * @return {*}
25
+ * @private
26
+ */
27
+ _returnData(retData, def = {}) {
28
+ if (retData.status !== 200) {
29
+ return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
30
+ } else {
31
+ return _.get(retData, 'data', def);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @author CloudBrasil <abernardo.br@gmail.com>
37
+ * @description Set header with new session
38
+ * @param {string} session Session, token JWT
39
+ * @return {object} header with new session
40
+ * @private
41
+ */
42
+ _setHeader(session) {
43
+ return {
44
+ headers: {
45
+ authorization: session,
46
+ }
47
+ };
48
+ }
49
+
50
+ /**
51
+ * @description Send real time notification
52
+ * @param {object} params Params to send notification
53
+ * @param {string} params.userIds Users to send notification
54
+ * @param {object} params.message Object with data to send user
55
+ * @param {object} session Session, token JWT
56
+ * @returns {Promise<*>}
57
+ */
58
+ async realTime(params, session) {
59
+ const self = this;
60
+
61
+ try {
62
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
63
+ Joi.assert(params.userIds, Joi.array().required(), 'OrgId of the user SU');
64
+ Joi.assert(params.message, Joi.object().required(), 'Object with data to send user');
65
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
66
+
67
+ const apiCall = self.client.post(`/admin/send/notifications`, params, self._setHeader(session));
68
+ return self._returnData(await apiCall);
69
+ } catch (ex) {
70
+ throw ex;
71
+ }
72
+ }
73
+
74
+ /**
75
+ * @author CloudBrasil <abernardo.br@gmail.com>
76
+ * @description Create notification
77
+ * @param {object} params Params to create notification
78
+ * @param {string} params.orgId OrgId of the user SU
79
+ * @param {string} params.userId User to create notification
80
+ * @param {object} params.message Object with data to send user
81
+ * @param {string} session Session, token JWT
82
+ * @return {Promise}
83
+ * @public
84
+ * @async
85
+ * @example
86
+ *
87
+ * const API = require('@docbrasil/api-systemmanager');
88
+ * const api = new API();
89
+ * const params = {
90
+ * orgId: '5edd11c46b6ce9729c2c297c',
91
+ * userId: '55e4a3bd6be6b45210833fae',
92
+ * message: 'Olá como vai tudo bem?'
93
+ * };
94
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
95
+ * await api.admin.notifications.add(params, session);
96
+ */
97
+ async add(params, session) {
98
+ const self = this;
99
+
100
+ try {
101
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
102
+ Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
103
+ Joi.assert(params.userId, Joi.string().required(), 'User to create notification');
104
+ Joi.assert(params.message, Joi.object().required(), 'Object with data to send user');
105
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
106
+
107
+ const {orgId, ...notificationPayload} = params;
108
+ const apiCall = self.client.post(`/admin/organizations/${orgId}/notifications`, notificationPayload, self._setHeader(session));
109
+ return self._returnData(await apiCall);
110
+ } catch (ex) {
111
+ throw ex;
112
+ }
113
+ }
114
+
115
+ /**
116
+ * @author CloudBrasil <abernardo.br@gmail.com>
117
+ * @description Search notification using (notificationId or userId)
118
+ * @param {object} params Params to create notification
119
+ * @param {string} params.orgId OrgId of the user SU
120
+ * @param {string} params.id ALERT! Id is userId or id is notificationId
121
+ * @param {string} session Session, token JWT
122
+ * @return {Promise}
123
+ * @public
124
+ * @async
125
+ * @example
126
+ *
127
+ * const API = require('@docbrasil/api-systemmanager');
128
+ * const api = new API();
129
+ * const params = {
130
+ * orgId: '5edd11c46b6ce9729c2c297c',
131
+ * id: '55e4a3bd6be6b45210833fae',
132
+ * };
133
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
134
+ * await api.admin.notifications.findById(params, session);
135
+ */
136
+ async findById(params, session) {
137
+ const self = this;
138
+
139
+ try {
140
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
141
+ Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
142
+ Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
143
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
144
+
145
+ const {orgId, id} = params;
146
+ const apiCall = self.client.get(`/admin/organizations/${orgId}/notifications/${id}`, self._setHeader(session));
147
+ return self._returnData(await apiCall);
148
+ } catch (ex) {
149
+ throw ex;
150
+ }
151
+ }
152
+
153
+ /**
154
+ * @author CloudBrasil <abernardo.br@gmail.com>
155
+ * @description Update notification using (notificationId or userId)
156
+ * @param {object} params Params to create notification
157
+ * @param {string} params.orgId OrgId of the user SU
158
+ * @param {string} params.id ALERT! Id is userId or id is notificationId
159
+ * @param {boolean} params.read If message is read true or false
160
+ * @param {string} session Session, token JWT
161
+ * @return {Promise}
162
+ * @public
163
+ * @async
164
+ * @example
165
+ *
166
+ * const API = require('@docbrasil/api-systemmanager');
167
+ * const api = new API();
168
+ * const params = {
169
+ * orgId: '5edd11c46b6ce9729c2c297c',
170
+ * id: '55e4a3bd6be6b45210833fae',
171
+ * read: true
172
+ * };
173
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
174
+ * await api.admin.notifications.findByIdAndUpdate(params, session);
175
+ */
176
+ async findByIdAndUpdate(params, session) {
177
+ const self = this;
178
+
179
+ try {
180
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
181
+ Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
182
+ Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
183
+ Joi.assert(params.read, Joi.boolean().required(), 'If message is read true or false');
184
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
185
+
186
+ const {orgId, id, ...statusPayload} = params;
187
+ const apiCall = self.client.put(`/admin/organizations/${orgId}/notifications/${id}`, statusPayload, self._setHeader(session));
188
+ return self._returnData(await apiCall);
189
+ } catch (ex) {
190
+ throw ex;
191
+ }
192
+ }
193
+
194
+ /**
195
+ * @author CloudBrasil <abernardo.br@gmail.com>
196
+ * @description Delete notification using (notificationId or userId)
197
+ * @param {object} params Params to create notification
198
+ * @param {string} params.orgId OrgId of the user SU
199
+ * @param {string} params.id ALERT! Id is userId or id is notificationId
200
+ * @param {string} session Session, token JWT
201
+ * @return {Promise}
202
+ * @public
203
+ * @async
204
+ * @example
205
+ *
206
+ * const API = require('@docbrasil/api-systemmanager');
207
+ * const api = new API();
208
+ * const params = {
209
+ * orgId: '5edd11c46b6ce9729c2c297c',
210
+ * id: '55e4a3bd6be6b45210833fae',
211
+ * };
212
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
213
+ * await api.admin.notifications.findByIdAndDelete(params, session);
214
+ */
215
+ async findByIdAndRemove(params, session) {
216
+ const self = this;
217
+
218
+ try {
219
+ Joi.assert(params, Joi.object().required(), 'Object with params to add notifications');
220
+ Joi.assert(params.orgId, Joi.string().required(), 'OrgId of the user SU');
221
+ Joi.assert(params.id, Joi.string().required(), 'ALERT! Id is userId or id is notificationId');
222
+ Joi.assert(session, Joi.string().required(), 'Session, token JWT');
223
+
224
+ const {orgId, id} = params;
225
+ const apiCall = self.client.delete(`/admin/organizations/${orgId}/notifications/${id}`, self._setHeader(session));
226
+ return self._returnData(await apiCall);
227
+ } catch (ex) {
228
+ throw ex;
229
+ }
230
+ }
231
+ }
232
+
233
+ export default AdminNotification;