@docbrasil/api-systemmanager 1.0.94 → 1.0.95
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/api/admin/doctypes.js +76 -76
- package/api/admin/document.js +332 -332
- package/api/admin/form.js +151 -151
- package/api/admin/index.js +46 -46
- package/api/admin/list.js +133 -133
- package/api/admin/message.js +194 -194
- package/api/admin/notification.js +233 -233
- package/api/admin/organization.js +124 -124
- package/api/admin/plugin.js +116 -116
- package/api/admin/policy.js +78 -78
- package/api/admin/processes.js +370 -370
- package/api/admin/task.js +125 -125
- package/api/admin/user.js +185 -185
- package/api/dispatch.js +101 -101
- package/api/general/geoLocation.js +88 -88
- package/api/general/index.js +23 -23
- package/api/login.js +267 -267
- package/api/session.js +85 -85
- package/api/user/datasource.js +144 -144
- package/api/user/document.js +730 -730
- package/api/user/index.js +39 -39
- package/api/user/notification.js +101 -101
- package/api/user/organization.js +230 -230
- package/api/user/process.js +191 -191
- package/api/user/register.js +205 -205
- package/api/user/task.js +201 -201
- package/api/user/task_available.js +135 -135
- package/api/user/user.js +287 -287
- package/api/utils/cypher.js +37 -37
- package/api/utils/promises.js +118 -118
- package/bundleRollup.js +158 -158
- package/dist/bundle.cjs +4875 -4875
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +675 -337
- package/doc.md +653 -653
- package/helper/boom.js +487 -487
- package/helper/cryptojs.js +6067 -6067
- package/index.js +85 -85
- package/package-lock.json +4635 -4635
- package/package.json +68 -68
- package/readme.md +25 -25
- package/tests/admin/document.spec.js +45 -45
- package/tests/admin/form.spec.js +74 -74
- package/tests/admin/list.spec.js +86 -86
- package/tests/admin/message.js +92 -92
- package/tests/admin/notification.spec.js +174 -174
- package/tests/admin/pluginspec..js +71 -71
- package/tests/admin/policy.spec.js +71 -71
- package/tests/admin/processes.spec.js +119 -119
- package/tests/admin/users.spec.js +127 -127
- package/tests/documents.spec.js +164 -164
- package/tests/login.spec.js +91 -91
- package/tests/session.spec..js +58 -58
- package/tests/user/documents.js +164 -164
- package/tests/user/organization.js +122 -122
- package/tests/user/process.js +71 -71
- package/tests/user/task_available.js +75 -75
- package/tests/user/user.js +88 -88
package/api/admin/message.js
CHANGED
|
@@ -1,194 +1,194 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import Boom from '@hapi/boom';
|
|
3
|
-
import Joi from 'joi';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Admin Class for user, permission admin
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class AdminMessage {
|
|
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 CloudBrasil <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 Pagination SMS texts
|
|
52
|
-
* @param {!object} params - Params to pagintion SMS
|
|
53
|
-
* @param {!string} params.message - Message to pagination
|
|
54
|
-
* @param {!number} params.limitSize=130 - Limit of the start pagination
|
|
55
|
-
* @param {!number} params.continueText=continua... - Text to continue other SMS
|
|
56
|
-
*/
|
|
57
|
-
_paginationOfTheSMS(params) {
|
|
58
|
-
const self = this;
|
|
59
|
-
try {
|
|
60
|
-
Joi.assert(params, Joi.object().required(), 'Params to paginate SMS');
|
|
61
|
-
Joi.assert(params.message, Joi.string(), 'Message to pagination');
|
|
62
|
-
Joi.assert(params.limitSize, Joi.number(), 'Limit of the start pagination');
|
|
63
|
-
Joi.assert(params.continueText, Joi.string(), 'Text to continue other SMS');
|
|
64
|
-
|
|
65
|
-
const defaultSize = 130;
|
|
66
|
-
const defaultContinue = 'continua...';
|
|
67
|
-
const { message, limitSize = defaultSize, continueText = defaultContinue } = params;
|
|
68
|
-
|
|
69
|
-
const size = limitSize - continueText.length;
|
|
70
|
-
const regex = new RegExp(`.{1,${size}}`, 'g');
|
|
71
|
-
const smsData = message.match(regex).map(item => item.trim());
|
|
72
|
-
const smsDataWithContinue = smsData.map((message, index, arr) => {
|
|
73
|
-
return index !== (arr.length - 1)
|
|
74
|
-
? `${message} ${continueText}`
|
|
75
|
-
: message;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return smsDataWithContinue;
|
|
79
|
-
|
|
80
|
-
} catch (ex) {
|
|
81
|
-
throw ex;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @description Validation struct to send email
|
|
87
|
-
* @param {!object} params - Params to send email
|
|
88
|
-
* @param {!string} params.subject - Subject of the email
|
|
89
|
-
* @param {!string} params.message - Body of the email
|
|
90
|
-
* @param {!string} params.to - Destination email
|
|
91
|
-
* @param {?string} params.from - Source email
|
|
92
|
-
*/
|
|
93
|
-
_validItemToSendEmail(params) {
|
|
94
|
-
try {
|
|
95
|
-
Joi.assert(params, Joi.object().required(), 'Params to send email');
|
|
96
|
-
Joi.assert(params.subject, Joi.string().required(), 'Subject of the email');
|
|
97
|
-
Joi.assert(params.message, Joi.string().required(), 'Body of the email');
|
|
98
|
-
Joi.assert(params.to, Joi.string().required(), 'Destination email');
|
|
99
|
-
Joi.assert(params.from, Joi.string(), 'Source email');
|
|
100
|
-
|
|
101
|
-
return true;
|
|
102
|
-
} catch (ex) {
|
|
103
|
-
throw ex;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @description Send an SMS message
|
|
109
|
-
* @param {!object} params - Params to send SMS
|
|
110
|
-
* @param {!string} params.apiKey - Organization API key
|
|
111
|
-
* @param {!string} params.message - The text message to send
|
|
112
|
-
* @param {!string} params.recipient - The telephone number without with only numbers
|
|
113
|
-
* @param {?number} params.limitSize=130 - Size limit to send SMS
|
|
114
|
-
* @return {Promise<{}>}
|
|
115
|
-
*/
|
|
116
|
-
async sendSMS(params) {
|
|
117
|
-
const self = this;
|
|
118
|
-
try {
|
|
119
|
-
Joi.assert(params, Joi.object().required(), 'Params to send SMS');
|
|
120
|
-
Joi.assert(params.apiKey, Joi.string().required(), 'Organization API key');
|
|
121
|
-
Joi.assert(params.message, Joi.string().required(), 'The text message to send');
|
|
122
|
-
Joi.assert(params.recipient, Joi.string().required(), 'The telephone number without with only numbers');
|
|
123
|
-
Joi.assert(params.limitSize, Joi.number(), 'Size limit to send SMS');
|
|
124
|
-
|
|
125
|
-
const defaultSize = 130;
|
|
126
|
-
const { apiKey, message, recipient, limitSize = defaultSize } = params;
|
|
127
|
-
|
|
128
|
-
const paramsOfThePagination = { message, limitSize };
|
|
129
|
-
const smsData = self._paginationOfTheSMS(paramsOfThePagination);
|
|
130
|
-
|
|
131
|
-
for await (const smsText of smsData) {
|
|
132
|
-
const payload = { apiKey, data: { message: smsText }, recipient };
|
|
133
|
-
await self.client.post('/sms/send', payload);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return { success: true, send: smsData.length };
|
|
137
|
-
|
|
138
|
-
} catch (ex) {
|
|
139
|
-
throw ex;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @description Send email, array with email list or send one email
|
|
145
|
-
* @param {!object} params - Params to send email
|
|
146
|
-
* @param {!string} params.subject - Subject of the email
|
|
147
|
-
* @param {!string} params.message - Body of the email
|
|
148
|
-
* @param {!string} params.to - Destination email
|
|
149
|
-
* @param {?string} params.from - Source email
|
|
150
|
-
* @param {string} session - Session, token JWT
|
|
151
|
-
* @return {Promise<{success: boolean, sent: object[]}>} - Success and email sent
|
|
152
|
-
* @example
|
|
153
|
-
*
|
|
154
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
155
|
-
* const api = new API();
|
|
156
|
-
* const params = {
|
|
157
|
-
* subject: 'Test email',
|
|
158
|
-
* message: '<h1>Hi!</h1>',
|
|
159
|
-
* to: 'destination@gmail.com'
|
|
160
|
-
* };
|
|
161
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
162
|
-
* await api.admin.message.sendEmail(params, session);
|
|
163
|
-
*/
|
|
164
|
-
async sendEmail(params, session) {
|
|
165
|
-
const self = this;
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
Joi.assert(session, Joi.string().required(), 'Session, token JWT');
|
|
169
|
-
|
|
170
|
-
let emailList = [];
|
|
171
|
-
const emailSent = [];
|
|
172
|
-
|
|
173
|
-
if (Array.isArray(params)) {
|
|
174
|
-
params.forEach(element => self._validItemToSendEmail(element));
|
|
175
|
-
emailList = [...params];
|
|
176
|
-
} else {
|
|
177
|
-
self._validItemToSendEmail(params);
|
|
178
|
-
emailList = [params];
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
for await (const email of emailList) {
|
|
182
|
-
await self.client.post('/admin/email', email, self._setHeader(session));
|
|
183
|
-
emailSent.push(email);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return { success: true, sent: emailSent };
|
|
187
|
-
|
|
188
|
-
} catch (ex) {
|
|
189
|
-
throw ex;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export default AdminMessage;
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Admin Class for user, permission admin
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class AdminMessage {
|
|
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 CloudBrasil <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 Pagination SMS texts
|
|
52
|
+
* @param {!object} params - Params to pagintion SMS
|
|
53
|
+
* @param {!string} params.message - Message to pagination
|
|
54
|
+
* @param {!number} params.limitSize=130 - Limit of the start pagination
|
|
55
|
+
* @param {!number} params.continueText=continua... - Text to continue other SMS
|
|
56
|
+
*/
|
|
57
|
+
_paginationOfTheSMS(params) {
|
|
58
|
+
const self = this;
|
|
59
|
+
try {
|
|
60
|
+
Joi.assert(params, Joi.object().required(), 'Params to paginate SMS');
|
|
61
|
+
Joi.assert(params.message, Joi.string(), 'Message to pagination');
|
|
62
|
+
Joi.assert(params.limitSize, Joi.number(), 'Limit of the start pagination');
|
|
63
|
+
Joi.assert(params.continueText, Joi.string(), 'Text to continue other SMS');
|
|
64
|
+
|
|
65
|
+
const defaultSize = 130;
|
|
66
|
+
const defaultContinue = 'continua...';
|
|
67
|
+
const { message, limitSize = defaultSize, continueText = defaultContinue } = params;
|
|
68
|
+
|
|
69
|
+
const size = limitSize - continueText.length;
|
|
70
|
+
const regex = new RegExp(`.{1,${size}}`, 'g');
|
|
71
|
+
const smsData = message.match(regex).map(item => item.trim());
|
|
72
|
+
const smsDataWithContinue = smsData.map((message, index, arr) => {
|
|
73
|
+
return index !== (arr.length - 1)
|
|
74
|
+
? `${message} ${continueText}`
|
|
75
|
+
: message;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return smsDataWithContinue;
|
|
79
|
+
|
|
80
|
+
} catch (ex) {
|
|
81
|
+
throw ex;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @description Validation struct to send email
|
|
87
|
+
* @param {!object} params - Params to send email
|
|
88
|
+
* @param {!string} params.subject - Subject of the email
|
|
89
|
+
* @param {!string} params.message - Body of the email
|
|
90
|
+
* @param {!string} params.to - Destination email
|
|
91
|
+
* @param {?string} params.from - Source email
|
|
92
|
+
*/
|
|
93
|
+
_validItemToSendEmail(params) {
|
|
94
|
+
try {
|
|
95
|
+
Joi.assert(params, Joi.object().required(), 'Params to send email');
|
|
96
|
+
Joi.assert(params.subject, Joi.string().required(), 'Subject of the email');
|
|
97
|
+
Joi.assert(params.message, Joi.string().required(), 'Body of the email');
|
|
98
|
+
Joi.assert(params.to, Joi.string().required(), 'Destination email');
|
|
99
|
+
Joi.assert(params.from, Joi.string(), 'Source email');
|
|
100
|
+
|
|
101
|
+
return true;
|
|
102
|
+
} catch (ex) {
|
|
103
|
+
throw ex;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @description Send an SMS message
|
|
109
|
+
* @param {!object} params - Params to send SMS
|
|
110
|
+
* @param {!string} params.apiKey - Organization API key
|
|
111
|
+
* @param {!string} params.message - The text message to send
|
|
112
|
+
* @param {!string} params.recipient - The telephone number without with only numbers
|
|
113
|
+
* @param {?number} params.limitSize=130 - Size limit to send SMS
|
|
114
|
+
* @return {Promise<{}>}
|
|
115
|
+
*/
|
|
116
|
+
async sendSMS(params) {
|
|
117
|
+
const self = this;
|
|
118
|
+
try {
|
|
119
|
+
Joi.assert(params, Joi.object().required(), 'Params to send SMS');
|
|
120
|
+
Joi.assert(params.apiKey, Joi.string().required(), 'Organization API key');
|
|
121
|
+
Joi.assert(params.message, Joi.string().required(), 'The text message to send');
|
|
122
|
+
Joi.assert(params.recipient, Joi.string().required(), 'The telephone number without with only numbers');
|
|
123
|
+
Joi.assert(params.limitSize, Joi.number(), 'Size limit to send SMS');
|
|
124
|
+
|
|
125
|
+
const defaultSize = 130;
|
|
126
|
+
const { apiKey, message, recipient, limitSize = defaultSize } = params;
|
|
127
|
+
|
|
128
|
+
const paramsOfThePagination = { message, limitSize };
|
|
129
|
+
const smsData = self._paginationOfTheSMS(paramsOfThePagination);
|
|
130
|
+
|
|
131
|
+
for await (const smsText of smsData) {
|
|
132
|
+
const payload = { apiKey, data: { message: smsText }, recipient };
|
|
133
|
+
await self.client.post('/sms/send', payload);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return { success: true, send: smsData.length };
|
|
137
|
+
|
|
138
|
+
} catch (ex) {
|
|
139
|
+
throw ex;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @description Send email, array with email list or send one email
|
|
145
|
+
* @param {!object} params - Params to send email
|
|
146
|
+
* @param {!string} params.subject - Subject of the email
|
|
147
|
+
* @param {!string} params.message - Body of the email
|
|
148
|
+
* @param {!string} params.to - Destination email
|
|
149
|
+
* @param {?string} params.from - Source email
|
|
150
|
+
* @param {string} session - Session, token JWT
|
|
151
|
+
* @return {Promise<{success: boolean, sent: object[]}>} - Success and email sent
|
|
152
|
+
* @example
|
|
153
|
+
*
|
|
154
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
155
|
+
* const api = new API();
|
|
156
|
+
* const params = {
|
|
157
|
+
* subject: 'Test email',
|
|
158
|
+
* message: '<h1>Hi!</h1>',
|
|
159
|
+
* to: 'destination@gmail.com'
|
|
160
|
+
* };
|
|
161
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
162
|
+
* await api.admin.message.sendEmail(params, session);
|
|
163
|
+
*/
|
|
164
|
+
async sendEmail(params, session) {
|
|
165
|
+
const self = this;
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
Joi.assert(session, Joi.string().required(), 'Session, token JWT');
|
|
169
|
+
|
|
170
|
+
let emailList = [];
|
|
171
|
+
const emailSent = [];
|
|
172
|
+
|
|
173
|
+
if (Array.isArray(params)) {
|
|
174
|
+
params.forEach(element => self._validItemToSendEmail(element));
|
|
175
|
+
emailList = [...params];
|
|
176
|
+
} else {
|
|
177
|
+
self._validItemToSendEmail(params);
|
|
178
|
+
emailList = [params];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for await (const email of emailList) {
|
|
182
|
+
await self.client.post('/admin/email', email, self._setHeader(session));
|
|
183
|
+
emailSent.push(email);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return { success: true, sent: emailSent };
|
|
187
|
+
|
|
188
|
+
} catch (ex) {
|
|
189
|
+
throw ex;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export default AdminMessage;
|