@docbrasil/api-systemmanager 1.0.87 → 1.0.89

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 (57) 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 +22 -22
  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 -687
  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 -4832
  33. package/dist/bundle.mjs +1 -1
  34. package/doc/api.md +372 -666
  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 -67
  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/user.js +88 -88
package/api/login.js CHANGED
@@ -1,267 +1,267 @@
1
- import _ from 'lodash';
2
- import Joi from 'joi';
3
-
4
- /**
5
- * @class Login manager
6
- */
7
- class Login {
8
-
9
- constructor(options) {
10
-
11
- Joi.assert(options, Joi.object().required());
12
- Joi.assert(options.parent, Joi.object().required());
13
-
14
- const self = this;
15
- self.parent = options.parent;
16
- self._client = self.parent.dispatch.getClient();
17
- }
18
-
19
- /**
20
- * @author Augusto Pissarra <abernardo.br@gmail.com>
21
- * @description Get the return data and check for errors
22
- * @param {object} retData Response HTTP
23
- * @return {*}
24
- * @private
25
- */
26
- _returnData(retData, def = {}) {
27
- if (retData.status !== 200) {
28
- throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
29
- } else {
30
- return _.get(retData, 'data', def);
31
- }
32
- }
33
-
34
- /**
35
- * @author CloudBrasil <abernardo.br@gmail.com>
36
- * @description Set header with new session
37
- * @param {string} session Session, token JWT
38
- * @return {object} header with new session
39
- * @private
40
- */
41
- _setHeader(session) {
42
- return {
43
- headers: {
44
- authorization: session,
45
- }
46
- };
47
- }
48
-
49
- /**
50
- * @author CloudBrasil <abernardo.br@gmail.com>
51
- * @description Login with social login Facebook
52
- * @param {object} params Params to login Facebook
53
- * @param {string} params.accessToken Access token of the system manager
54
- * @param {object} params.initialUserData Object with roles default if sigin
55
- * @param {array} params.initialUserData.externalRoles Array with permission of user
56
- * @return {promise<object>} data
57
- * @return {object} data.auth true or false if we have the user authenticaited correctly
58
- * @return {object} data.user the logged user
59
- * @public
60
- * @async
61
- * @example
62
- *
63
- * const API = require('@docbrasil/api-systemmanager');
64
- *
65
- * // Params of the instance
66
- * const params = {...}
67
- * const api = new API(params);
68
- * const params = { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cC...' };
69
- * const { auth, user } = await api.login.facebook(params);
70
- */
71
- async facebook(params) {
72
- const self = this;
73
- try {
74
- Joi.assert(params, Joi.object().required(), 'Params to login Facebook');
75
- Joi.assert(params.accessToken, Joi.string().required(), 'Access token of the system manager');
76
-
77
- if (_.hasIn(params, 'initialUserData')) {
78
- Joi.assert(params.initialUserData, Joi.object().required(), 'Object with roles default if sigin');
79
- Joi.assert(params.initialUserData.externalRoles, Joi.array().required(), 'Array with permission of user');
80
- }
81
-
82
- const apiCall = self._client.post('/login/facebook', params);
83
- return self._returnData(await apiCall);
84
- } catch (ex) {
85
- throw ex;
86
- }
87
- }
88
-
89
- /**
90
- * @author CloudBrasil <abernardo.br@gmail.com>
91
- * @description Login with social login Google
92
- * @param {object} params Params to login Google
93
- * @param {string} params.accessToken Access token of the system manager
94
- * @param {object} params.initialUserData Object with roles default if sigin
95
- * @param {array} params.initialUserData.externalRoles Array with permission of user
96
- * @return {promise<object>} data
97
- * @return {object} data.auth true or false if we have the user authenticaited correctly
98
- * @return {object} data.user the logged user
99
- * @public
100
- * @async
101
- * @example
102
- *
103
- * const API = require('@docbrasil/api-systemmanager');
104
- *
105
- * // Params of the instance
106
- * const params = {...}
107
- * const api = new API(params);
108
- * const accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cC...';
109
- * const { auth, user } = await api.login.google(accessToken);
110
- */
111
- async google(params) {
112
- const self = this;
113
- try {
114
- Joi.assert(params, Joi.object().required(), 'Params to login Google');
115
- Joi.assert(params.accessToken, Joi.string().required(), 'Access token of the system manager');
116
-
117
- if (_.hasIn(params, 'initialUserData')) {
118
- Joi.assert(params.initialUserData, Joi.object().required(), 'Object with roles default if sigin');
119
- Joi.assert(params.initialUserData.externalRoles, Joi.array().required(), 'Array with permission of user');
120
- }
121
-
122
- const apiCall = self._client.post('/login/google', params);
123
- return self._returnData(await apiCall);
124
- } catch (ex) {
125
- throw ex;
126
- }
127
- }
128
-
129
- /**
130
- * @author CloudBrasil <abernardo.br@gmail.com>
131
- * @description Login with apikey
132
- * @param {string} apikey Access key
133
- * @return {promise<object>} data
134
- * @return {object} data.auth true or false if we have the user authenticaited correctly
135
- * @return {object} data.user the logged user
136
- * @public
137
- * @async
138
- * @example
139
- *
140
- * const API = require('@docbrasil/api-systemmanager');
141
- *
142
- * // Params of the instance
143
- * const params = {...}
144
- * const api = new API(params);
145
- * const apiKey = '043a0eb2-f5c3-4900-b781-7f229d00d092';
146
- * const { auth, user } = await api.login.apiKey(apiKey);
147
- */
148
- async apiKey(apiKey) {
149
- const self = this;
150
- try {
151
- Joi.assert(apiKey, Joi.string().required());
152
-
153
- const apiCall = self._client.post('/login/api', {apiKey});
154
- return self._returnData(await apiCall);
155
- } catch (ex) {
156
- throw ex;
157
- }
158
- }
159
-
160
- /**
161
- * @author CloudBrasil <abernardo.br@gmail.com>
162
- * @description Login with user and password
163
- * @param {object} params Object with user and password
164
- * @param {string} params.username Username or email of the user
165
- * @param {string} params.password Password of the user
166
- * @param {string} params.orgname The organame of the user
167
- * @return {promise<object>} data
168
- * @return {object} data.auth true or false if we have the user authenticaited correctly
169
- * @return {object} data.user the logged user
170
- * @public
171
- * @async
172
- * @example
173
- *
174
- * const API = require('@docbrasil/api-systemmanager');
175
- *
176
- * // Params of the instance
177
- * const params = {...}
178
- * const api = new API(params);
179
- * const params = {
180
- * username: 'ana.silva@gmail.com',
181
- * password: '123456'
182
- * };
183
- * const { auth, user } = await api.login.userPass(params);
184
- */
185
- async userPass(params) {
186
- const self = this;
187
- try {
188
- Joi.assert(params.username, Joi.string().required());
189
- Joi.assert(params.password, Joi.string().required());
190
- const { orgname = '' } = params;
191
- let url;
192
- if(orgname !== '') {
193
- url = `/login/${orgname}`;
194
- } else {
195
- url = `/login`;
196
- }
197
- const apiCall = self._client.post(url, params);
198
- return self._returnData(await apiCall);
199
- } catch (ex) {
200
- throw ex;
201
- }
202
- }
203
-
204
- /**
205
- * @author CloudBrasil <abernardo.br@gmail.com>
206
- * @description Logout user system manager
207
- * @param {string} session Session, token JWT
208
- * @return {promise<object>}} data
209
- * @return {boolean} data.success true|false
210
- * @public
211
- * @async
212
- * @example
213
- *
214
- * const API = require('@docbrasil/api-systemmanager');
215
- *
216
- * // Params of the instance
217
- * const params = {...}
218
- * const api = new API(params);
219
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
220
- * const { success } = await api.login.logout(session);
221
- */
222
- async logout(session) {
223
- const self = this;
224
- try {
225
- Joi.assert(session, Joi.string().required());
226
-
227
- const apiCall = self._client.get('/logout', self._setHeader(session));
228
- const { response = 'NOT_OK' } = self._returnData(await apiCall);
229
- return response === 'OK';
230
- } catch (ex) {
231
- throw ex;
232
- }
233
- }
234
-
235
- /**
236
- * @author CloudBrasil <abernardo.br@gmail.com>
237
- * @description Recover the password
238
- * @param {string} username The username or email
239
- * @return {promise<object>}} data
240
- * @return {boolean} data.success true|false
241
- * @public
242
- * @async
243
- * @example
244
- *
245
- * const API = require('@docbrasil/api-systemmanager');
246
- *
247
- * // Params of the instance
248
- * const params = {...}
249
- * const api = new API(params);
250
- * const { success } = await api.login.recover('myusername');
251
- */
252
- async recover(username) {
253
- const self = this;
254
-
255
- try {
256
- Joi.assert(username, Joi.string().required());
257
-
258
- const url = `users/${username}/sendResetEmail`;
259
- const apiCall = self._client.get(url);
260
- return self._returnData(await apiCall);
261
- } catch (ex) {
262
- throw ex;
263
- }
264
- }
265
- }
266
-
267
- export default Login;
1
+ import _ from 'lodash';
2
+ import Joi from 'joi';
3
+
4
+ /**
5
+ * @class Login manager
6
+ */
7
+ class Login {
8
+
9
+ constructor(options) {
10
+
11
+ Joi.assert(options, Joi.object().required());
12
+ Joi.assert(options.parent, Joi.object().required());
13
+
14
+ const self = this;
15
+ self.parent = options.parent;
16
+ self._client = self.parent.dispatch.getClient();
17
+ }
18
+
19
+ /**
20
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
21
+ * @description Get the return data and check for errors
22
+ * @param {object} retData Response HTTP
23
+ * @return {*}
24
+ * @private
25
+ */
26
+ _returnData(retData, def = {}) {
27
+ if (retData.status !== 200) {
28
+ throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
29
+ } else {
30
+ return _.get(retData, 'data', def);
31
+ }
32
+ }
33
+
34
+ /**
35
+ * @author CloudBrasil <abernardo.br@gmail.com>
36
+ * @description Set header with new session
37
+ * @param {string} session Session, token JWT
38
+ * @return {object} header with new session
39
+ * @private
40
+ */
41
+ _setHeader(session) {
42
+ return {
43
+ headers: {
44
+ authorization: session,
45
+ }
46
+ };
47
+ }
48
+
49
+ /**
50
+ * @author CloudBrasil <abernardo.br@gmail.com>
51
+ * @description Login with social login Facebook
52
+ * @param {object} params Params to login Facebook
53
+ * @param {string} params.accessToken Access token of the system manager
54
+ * @param {object} params.initialUserData Object with roles default if sigin
55
+ * @param {array} params.initialUserData.externalRoles Array with permission of user
56
+ * @return {promise<object>} data
57
+ * @return {object} data.auth true or false if we have the user authenticaited correctly
58
+ * @return {object} data.user the logged user
59
+ * @public
60
+ * @async
61
+ * @example
62
+ *
63
+ * const API = require('@docbrasil/api-systemmanager');
64
+ *
65
+ * // Params of the instance
66
+ * const params = {...}
67
+ * const api = new API(params);
68
+ * const params = { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cC...' };
69
+ * const { auth, user } = await api.login.facebook(params);
70
+ */
71
+ async facebook(params) {
72
+ const self = this;
73
+ try {
74
+ Joi.assert(params, Joi.object().required(), 'Params to login Facebook');
75
+ Joi.assert(params.accessToken, Joi.string().required(), 'Access token of the system manager');
76
+
77
+ if (_.hasIn(params, 'initialUserData')) {
78
+ Joi.assert(params.initialUserData, Joi.object().required(), 'Object with roles default if sigin');
79
+ Joi.assert(params.initialUserData.externalRoles, Joi.array().required(), 'Array with permission of user');
80
+ }
81
+
82
+ const apiCall = self._client.post('/login/facebook', params);
83
+ return self._returnData(await apiCall);
84
+ } catch (ex) {
85
+ throw ex;
86
+ }
87
+ }
88
+
89
+ /**
90
+ * @author CloudBrasil <abernardo.br@gmail.com>
91
+ * @description Login with social login Google
92
+ * @param {object} params Params to login Google
93
+ * @param {string} params.accessToken Access token of the system manager
94
+ * @param {object} params.initialUserData Object with roles default if sigin
95
+ * @param {array} params.initialUserData.externalRoles Array with permission of user
96
+ * @return {promise<object>} data
97
+ * @return {object} data.auth true or false if we have the user authenticaited correctly
98
+ * @return {object} data.user the logged user
99
+ * @public
100
+ * @async
101
+ * @example
102
+ *
103
+ * const API = require('@docbrasil/api-systemmanager');
104
+ *
105
+ * // Params of the instance
106
+ * const params = {...}
107
+ * const api = new API(params);
108
+ * const accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cC...';
109
+ * const { auth, user } = await api.login.google(accessToken);
110
+ */
111
+ async google(params) {
112
+ const self = this;
113
+ try {
114
+ Joi.assert(params, Joi.object().required(), 'Params to login Google');
115
+ Joi.assert(params.accessToken, Joi.string().required(), 'Access token of the system manager');
116
+
117
+ if (_.hasIn(params, 'initialUserData')) {
118
+ Joi.assert(params.initialUserData, Joi.object().required(), 'Object with roles default if sigin');
119
+ Joi.assert(params.initialUserData.externalRoles, Joi.array().required(), 'Array with permission of user');
120
+ }
121
+
122
+ const apiCall = self._client.post('/login/google', params);
123
+ return self._returnData(await apiCall);
124
+ } catch (ex) {
125
+ throw ex;
126
+ }
127
+ }
128
+
129
+ /**
130
+ * @author CloudBrasil <abernardo.br@gmail.com>
131
+ * @description Login with apikey
132
+ * @param {string} apikey Access key
133
+ * @return {promise<object>} data
134
+ * @return {object} data.auth true or false if we have the user authenticaited correctly
135
+ * @return {object} data.user the logged user
136
+ * @public
137
+ * @async
138
+ * @example
139
+ *
140
+ * const API = require('@docbrasil/api-systemmanager');
141
+ *
142
+ * // Params of the instance
143
+ * const params = {...}
144
+ * const api = new API(params);
145
+ * const apiKey = '043a0eb2-f5c3-4900-b781-7f229d00d092';
146
+ * const { auth, user } = await api.login.apiKey(apiKey);
147
+ */
148
+ async apiKey(apiKey) {
149
+ const self = this;
150
+ try {
151
+ Joi.assert(apiKey, Joi.string().required());
152
+
153
+ const apiCall = self._client.post('/login/api', {apiKey});
154
+ return self._returnData(await apiCall);
155
+ } catch (ex) {
156
+ throw ex;
157
+ }
158
+ }
159
+
160
+ /**
161
+ * @author CloudBrasil <abernardo.br@gmail.com>
162
+ * @description Login with user and password
163
+ * @param {object} params Object with user and password
164
+ * @param {string} params.username Username or email of the user
165
+ * @param {string} params.password Password of the user
166
+ * @param {string} params.orgname The organame of the user
167
+ * @return {promise<object>} data
168
+ * @return {object} data.auth true or false if we have the user authenticaited correctly
169
+ * @return {object} data.user the logged user
170
+ * @public
171
+ * @async
172
+ * @example
173
+ *
174
+ * const API = require('@docbrasil/api-systemmanager');
175
+ *
176
+ * // Params of the instance
177
+ * const params = {...}
178
+ * const api = new API(params);
179
+ * const params = {
180
+ * username: 'ana.silva@gmail.com',
181
+ * password: '123456'
182
+ * };
183
+ * const { auth, user } = await api.login.userPass(params);
184
+ */
185
+ async userPass(params) {
186
+ const self = this;
187
+ try {
188
+ Joi.assert(params.username, Joi.string().required());
189
+ Joi.assert(params.password, Joi.string().required());
190
+ const { orgname = '' } = params;
191
+ let url;
192
+ if(orgname !== '') {
193
+ url = `/login/${orgname}`;
194
+ } else {
195
+ url = `/login`;
196
+ }
197
+ const apiCall = self._client.post(url, params);
198
+ return self._returnData(await apiCall);
199
+ } catch (ex) {
200
+ throw ex;
201
+ }
202
+ }
203
+
204
+ /**
205
+ * @author CloudBrasil <abernardo.br@gmail.com>
206
+ * @description Logout user system manager
207
+ * @param {string} session Session, token JWT
208
+ * @return {promise<object>}} data
209
+ * @return {boolean} data.success true|false
210
+ * @public
211
+ * @async
212
+ * @example
213
+ *
214
+ * const API = require('@docbrasil/api-systemmanager');
215
+ *
216
+ * // Params of the instance
217
+ * const params = {...}
218
+ * const api = new API(params);
219
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
220
+ * const { success } = await api.login.logout(session);
221
+ */
222
+ async logout(session) {
223
+ const self = this;
224
+ try {
225
+ Joi.assert(session, Joi.string().required());
226
+
227
+ const apiCall = self._client.get('/logout', self._setHeader(session));
228
+ const { response = 'NOT_OK' } = self._returnData(await apiCall);
229
+ return response === 'OK';
230
+ } catch (ex) {
231
+ throw ex;
232
+ }
233
+ }
234
+
235
+ /**
236
+ * @author CloudBrasil <abernardo.br@gmail.com>
237
+ * @description Recover the password
238
+ * @param {string} username The username or email
239
+ * @return {promise<object>}} data
240
+ * @return {boolean} data.success true|false
241
+ * @public
242
+ * @async
243
+ * @example
244
+ *
245
+ * const API = require('@docbrasil/api-systemmanager');
246
+ *
247
+ * // Params of the instance
248
+ * const params = {...}
249
+ * const api = new API(params);
250
+ * const { success } = await api.login.recover('myusername');
251
+ */
252
+ async recover(username) {
253
+ const self = this;
254
+
255
+ try {
256
+ Joi.assert(username, Joi.string().required());
257
+
258
+ const url = `users/${username}/sendResetEmail`;
259
+ const apiCall = self._client.get(url);
260
+ return self._returnData(await apiCall);
261
+ } catch (ex) {
262
+ throw ex;
263
+ }
264
+ }
265
+ }
266
+
267
+ export default Login;