@docbrasil/api-systemmanager 1.0.86 → 1.0.88

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 +731 -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 +4876 -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
@@ -1,205 +1,205 @@
1
- import _ from 'lodash';
2
- import Boom from '@hapi/boom';
3
- import Joi from 'joi';
4
- import Cypher from '../utils/cypher';
5
-
6
- /**
7
- * Class for user registration in a user
8
- * @class
9
- */
10
- class Register {
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
- return 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 CloudBrasil <abernardo.br@gmail.com>
53
- * @param {object} params.registerId The registerId that comes with the registration page context
54
- * @return {string} orgname The orgname of the organization in the registerId
55
- * @public
56
- * @example
57
- *
58
- * const API = require('@docbrasil/api-systemmanager');
59
- * const api = new API();
60
- * const params = {
61
- * registerId: 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...'
62
- * };
63
- * const orgname = await api.user.register.getOrgname(params);
64
- */
65
- getOrgname(registerId) {
66
- const { orgname = '' } = Cypher.get(registerId) || {};
67
- return orgname;
68
- }
69
-
70
- /**
71
- * @author CloudBrasil <abernardo.br@gmail.com>
72
- * @description Method to find task by id
73
- * @param {object} params Params to get task
74
- * @param {string} params.registerId The registerId that comes with the registration page context
75
- * @param {object} params.email The email to validate
76
- * @returns {promise<object>} data
77
- * @returns {boolean} data.success If the operation was successfully done (true|false)
78
- * @returns {boolean} data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned
79
- * @returns {string} data.registrationEmailInfoRaw The fully cryptographed registration information
80
- * @returns {object} data.registrationEmailInfo The registration information
81
- * @returns {string} data.registrationEmailInfo.orgname The orgname
82
- * @returns {string} data.registrationEmailInfo.orgId The orgId of the organization
83
- * @returns {string} data.registrationEmailInfo.guid The unique id for the registration
84
- * @returns {object} data.registrationEmailInfo.emailValidation The email validation information
85
- * @returns {string} data.registrationEmailInfo.emailValidation.email The email that the code was sent to
86
- * @returns {string} data.registrationEmailInfo.emailValidation.code The 4 digit code to validate the email
87
- * @public
88
- * @example
89
- *
90
- * const API = require('@docbrasil/api-systemmanager');
91
- * const api = new API();
92
- * const params = {
93
- * registerId: 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
94
- * email: 'myemail@company.com'
95
- * };
96
- * const retData = await api.user.register.validateEmail(params);
97
- */
98
- async validateEmail(params = {}) {
99
- const self = this;
100
-
101
- try {
102
- Joi.assert(params, Joi.object().required(), 'Params to get task');
103
- Joi.assert(params.registerId, Joi.string().required(), ' RegisterId for registration');
104
- Joi.assert(params.email, Joi.string().required(), ' The emnail to register');
105
-
106
- const { registerId = '', email = '' } = params;
107
- const registerInfo = Cypher.get(registerId) || {};
108
- const infoData = { ...registerInfo, email };
109
- const payload = { info: Cypher.set(infoData) };
110
- const apiCall = self._client
111
- .post(`/users/validate/email`, payload);
112
-
113
- const { success = false, info = '', userAlreadyExists = false } = self._returnData(await apiCall);
114
- const retData = { success, userAlreadyExists, registrationEmailInfoRaw: info, registrationEmailInfo: Cypher.get(info) };
115
- return retData;
116
- } catch (ex) {
117
- throw ex;
118
- }
119
- }
120
-
121
- /**
122
- * @author CloudBrasil <abernardo.br@gmail.com>
123
- * @description Method to register a user
124
- * @param {object} params Params to get task
125
- * @param {string} params.registerId The registerId that comes with the registration page context
126
- * @param {string} params.type=sign The type of the registration. By defailt,
127
- * @param {boolean} params.login=false If we want to login the user directly after registering the user successfully. If you have a redirect, the best option is to login automatically.
128
- * @param {object} params.emailInfo The information for the email validation
129
- * @param {string} params.emailInfo.email The email validation information
130
- * @param {string} params.emailInfo.code The 4 digit code to validate the email
131
- * @param {object} params.registerData The registration data
132
- * @param {string} params.registerData.name The name if the user
133
- * @param {string} params.registerData.registerEmail The email of the user
134
- * @param {string} params.registerData.phone The phone of the user
135
- * @param {string} params.registerData.idcard The ID card of the user
136
- * @param {string} params.registerData.registerPassword The user password in open text
137
- * @param {string} params.registerData.emailValidationCode The code used to validate the email
138
- * @param {string} params.registerData.phoneValidationCode The code used to validate the phone
139
- * @param {string} params.registerData.language The defaulf navigator language (i.e.: navigator.language)
140
- * @param {string} params.registerData.timezone The defaulf navigator timezone (i.e.: Intl.DateTimeFormat().resolvedOptions().timeZone)
141
- * @returns {promise<object>} data
142
- * @returns {boolean} data.success If the operation was successfully done (true|false)
143
- * @returns {boolean} data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned
144
- * @returns {object} auth The full authentication data with session, if login is true.
145
- * @returns {string} auth.redirectUrl The url to redirect.
146
- * @public
147
- * @example
148
- *
149
- * const API = require('@docbrasil/api-systemmanager');
150
- * const api = new API();
151
- * const params ={
152
- * "registerId": 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
153
- * "type": 'sign',
154
- * "login": false,
155
- * "emailInfo": {
156
- * "code": "5974",
157
- * "email": "cbtoto_1@mailinator.com"
158
- * },
159
- * "registerData": {
160
- * "name": "Augusto Totlo",
161
- * "registerEmail": "cbtoto_1@mailinator.com",
162
- * "phone": "",
163
- * "idcard": "",
164
- * "dob": "1978-01-12T03:00:00.000Z",
165
- * "registerPassword": "123456",
166
- * "emailValidationCode": "5974",
167
- * "phoneValidationCode": "",
168
- * "language": "en-US",
169
- * "timezone": "Europe/Dublin"
170
- * }
171
- * };
172
- * const retData = await api.user.register.execute(params);
173
- */
174
- async execute(params = {}) {
175
- const self = this;
176
-
177
- try {
178
- Joi.assert(params, Joi.object().required(), 'Params to get task');
179
- Joi.assert(params.registerId, Joi.string().required(), ' RegisterId for registration');
180
- Joi.assert(params.emailInfo, Joi.object().required(), ' The email info');
181
- Joi.assert(params.registerData, Joi.object().required(), ' The registerData');
182
-
183
- const {
184
- type = 'sign',
185
- registerId = '',
186
- emailInfo = {},
187
- registerData = {},
188
- login = false
189
- } = params;
190
- const registerInfo = Cypher.get(registerId) || {};
191
- const payload = { ...registerInfo, type, login, emailInfo, registerData };
192
- const payloadInfo = { info: Cypher.set(payload) };
193
- const apiCall = self._client
194
- .put(`/users/register`, payloadInfo);
195
-
196
- const { success = false, userAlreadyExists = false, auth } = self._returnData(await apiCall);
197
- const retData = { success, userAlreadyExists, auth };
198
- return retData;
199
- } catch (ex) {
200
- throw ex;
201
- }
202
- }
203
- }
204
-
205
- export default Register;
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+ import Cypher from '../utils/cypher';
5
+
6
+ /**
7
+ * Class for user registration in a user
8
+ * @class
9
+ */
10
+ class Register {
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
+ return 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 CloudBrasil <abernardo.br@gmail.com>
53
+ * @param {object} params.registerId The registerId that comes with the registration page context
54
+ * @return {string} orgname The orgname of the organization in the registerId
55
+ * @public
56
+ * @example
57
+ *
58
+ * const API = require('@docbrasil/api-systemmanager');
59
+ * const api = new API();
60
+ * const params = {
61
+ * registerId: 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...'
62
+ * };
63
+ * const orgname = await api.user.register.getOrgname(params);
64
+ */
65
+ getOrgname(registerId) {
66
+ const { orgname = '' } = Cypher.get(registerId) || {};
67
+ return orgname;
68
+ }
69
+
70
+ /**
71
+ * @author CloudBrasil <abernardo.br@gmail.com>
72
+ * @description Method to find task by id
73
+ * @param {object} params Params to get task
74
+ * @param {string} params.registerId The registerId that comes with the registration page context
75
+ * @param {object} params.email The email to validate
76
+ * @returns {promise<object>} data
77
+ * @returns {boolean} data.success If the operation was successfully done (true|false)
78
+ * @returns {boolean} data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned
79
+ * @returns {string} data.registrationEmailInfoRaw The fully cryptographed registration information
80
+ * @returns {object} data.registrationEmailInfo The registration information
81
+ * @returns {string} data.registrationEmailInfo.orgname The orgname
82
+ * @returns {string} data.registrationEmailInfo.orgId The orgId of the organization
83
+ * @returns {string} data.registrationEmailInfo.guid The unique id for the registration
84
+ * @returns {object} data.registrationEmailInfo.emailValidation The email validation information
85
+ * @returns {string} data.registrationEmailInfo.emailValidation.email The email that the code was sent to
86
+ * @returns {string} data.registrationEmailInfo.emailValidation.code The 4 digit code to validate the email
87
+ * @public
88
+ * @example
89
+ *
90
+ * const API = require('@docbrasil/api-systemmanager');
91
+ * const api = new API();
92
+ * const params = {
93
+ * registerId: 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
94
+ * email: 'myemail@company.com'
95
+ * };
96
+ * const retData = await api.user.register.validateEmail(params);
97
+ */
98
+ async validateEmail(params = {}) {
99
+ const self = this;
100
+
101
+ try {
102
+ Joi.assert(params, Joi.object().required(), 'Params to get task');
103
+ Joi.assert(params.registerId, Joi.string().required(), ' RegisterId for registration');
104
+ Joi.assert(params.email, Joi.string().required(), ' The emnail to register');
105
+
106
+ const { registerId = '', email = '' } = params;
107
+ const registerInfo = Cypher.get(registerId) || {};
108
+ const infoData = { ...registerInfo, email };
109
+ const payload = { info: Cypher.set(infoData) };
110
+ const apiCall = self._client
111
+ .post(`/users/validate/email`, payload);
112
+
113
+ const { success = false, info = '', userAlreadyExists = false } = self._returnData(await apiCall);
114
+ const retData = { success, userAlreadyExists, registrationEmailInfoRaw: info, registrationEmailInfo: Cypher.get(info) };
115
+ return retData;
116
+ } catch (ex) {
117
+ throw ex;
118
+ }
119
+ }
120
+
121
+ /**
122
+ * @author CloudBrasil <abernardo.br@gmail.com>
123
+ * @description Method to register a user
124
+ * @param {object} params Params to get task
125
+ * @param {string} params.registerId The registerId that comes with the registration page context
126
+ * @param {string} params.type=sign The type of the registration. By defailt,
127
+ * @param {boolean} params.login=false If we want to login the user directly after registering the user successfully. If you have a redirect, the best option is to login automatically.
128
+ * @param {object} params.emailInfo The information for the email validation
129
+ * @param {string} params.emailInfo.email The email validation information
130
+ * @param {string} params.emailInfo.code The 4 digit code to validate the email
131
+ * @param {object} params.registerData The registration data
132
+ * @param {string} params.registerData.name The name if the user
133
+ * @param {string} params.registerData.registerEmail The email of the user
134
+ * @param {string} params.registerData.phone The phone of the user
135
+ * @param {string} params.registerData.idcard The ID card of the user
136
+ * @param {string} params.registerData.registerPassword The user password in open text
137
+ * @param {string} params.registerData.emailValidationCode The code used to validate the email
138
+ * @param {string} params.registerData.phoneValidationCode The code used to validate the phone
139
+ * @param {string} params.registerData.language The defaulf navigator language (i.e.: navigator.language)
140
+ * @param {string} params.registerData.timezone The defaulf navigator timezone (i.e.: Intl.DateTimeFormat().resolvedOptions().timeZone)
141
+ * @returns {promise<object>} data
142
+ * @returns {boolean} data.success If the operation was successfully done (true|false)
143
+ * @returns {boolean} data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned
144
+ * @returns {object} auth The full authentication data with session, if login is true.
145
+ * @returns {string} auth.redirectUrl The url to redirect.
146
+ * @public
147
+ * @example
148
+ *
149
+ * const API = require('@docbrasil/api-systemmanager');
150
+ * const api = new API();
151
+ * const params ={
152
+ * "registerId": 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
153
+ * "type": 'sign',
154
+ * "login": false,
155
+ * "emailInfo": {
156
+ * "code": "5974",
157
+ * "email": "cbtoto_1@mailinator.com"
158
+ * },
159
+ * "registerData": {
160
+ * "name": "Augusto Totlo",
161
+ * "registerEmail": "cbtoto_1@mailinator.com",
162
+ * "phone": "",
163
+ * "idcard": "",
164
+ * "dob": "1978-01-12T03:00:00.000Z",
165
+ * "registerPassword": "123456",
166
+ * "emailValidationCode": "5974",
167
+ * "phoneValidationCode": "",
168
+ * "language": "en-US",
169
+ * "timezone": "Europe/Dublin"
170
+ * }
171
+ * };
172
+ * const retData = await api.user.register.execute(params);
173
+ */
174
+ async execute(params = {}) {
175
+ const self = this;
176
+
177
+ try {
178
+ Joi.assert(params, Joi.object().required(), 'Params to get task');
179
+ Joi.assert(params.registerId, Joi.string().required(), ' RegisterId for registration');
180
+ Joi.assert(params.emailInfo, Joi.object().required(), ' The email info');
181
+ Joi.assert(params.registerData, Joi.object().required(), ' The registerData');
182
+
183
+ const {
184
+ type = 'sign',
185
+ registerId = '',
186
+ emailInfo = {},
187
+ registerData = {},
188
+ login = false
189
+ } = params;
190
+ const registerInfo = Cypher.get(registerId) || {};
191
+ const payload = { ...registerInfo, type, login, emailInfo, registerData };
192
+ const payloadInfo = { info: Cypher.set(payload) };
193
+ const apiCall = self._client
194
+ .put(`/users/register`, payloadInfo);
195
+
196
+ const { success = false, userAlreadyExists = false, auth } = self._returnData(await apiCall);
197
+ const retData = { success, userAlreadyExists, auth };
198
+ return retData;
199
+ } catch (ex) {
200
+ throw ex;
201
+ }
202
+ }
203
+ }
204
+
205
+ export default Register;