@docbrasil/api-systemmanager 1.0.107 → 1.0.108
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/.github/workflows/static.yml +43 -0
- package/api/external.js +41 -0
- package/dist/bundle.cjs +41 -0
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +382 -0
- package/docs/Admin.html +336 -0
- package/docs/AdminDocuments.html +2235 -0
- package/docs/AdminForm.html +934 -0
- package/docs/AdminLists.html +895 -0
- package/docs/AdminMessage.html +1490 -0
- package/docs/AdminNotification.html +1636 -0
- package/docs/AdminPlugin.html +696 -0
- package/docs/AdminPolicy.html +451 -0
- package/docs/AdminProcesses.html +692 -0
- package/docs/AdminTask.html +740 -0
- package/docs/AdminUser.html +1203 -0
- package/docs/Datasource.html +660 -0
- package/docs/Dispatch.html +624 -0
- package/docs/Documents.html +4875 -0
- package/docs/External.html +1203 -0
- package/docs/GeoLocation.html +503 -0
- package/docs/Login.html +1839 -0
- package/docs/Notification.html +625 -0
- package/docs/Organization.html +2767 -0
- package/docs/Process.html +1598 -0
- package/docs/Register.html +1604 -0
- package/docs/Session.html +482 -0
- package/docs/Task.html +1394 -0
- package/docs/TaskAvailable.html +893 -0
- package/docs/User.html +2002 -0
- package/docs/Users.html +569 -0
- package/docs/admin_doctypes.js.html +193 -0
- package/docs/admin_document.js.html +449 -0
- package/docs/admin_form.js.html +268 -0
- package/docs/admin_index.js.html +163 -0
- package/docs/admin_list.js.html +250 -0
- package/docs/admin_message.js.html +311 -0
- package/docs/admin_notification.js.html +350 -0
- package/docs/admin_organization.js.html +241 -0
- package/docs/admin_plugin.js.html +233 -0
- package/docs/admin_policy.js.html +195 -0
- package/docs/admin_processes.js.html +487 -0
- package/docs/admin_task.js.html +242 -0
- package/docs/admin_user.js.html +302 -0
- package/docs/dispatch.js.html +218 -0
- package/docs/external.js.html +333 -0
- package/docs/general_geoLocation.js.html +205 -0
- package/docs/general_index.js.html +140 -0
- package/docs/index.html +129 -0
- package/docs/login.js.html +384 -0
- package/docs/scripts/app.min.js +1 -0
- package/docs/scripts/linenumber.js +26 -0
- package/docs/scripts/search.js +39 -0
- package/docs/session.js.html +202 -0
- package/docs/styles/app.min.css +1 -0
- package/docs/styles/iframe.css +13 -0
- package/docs/styles/prettify-jsdoc.css +111 -0
- package/docs/styles/prettify-tomorrow.css +132 -0
- package/docs/styles/reset.css +44 -0
- package/docs/user_datasource.js.html +261 -0
- package/docs/user_document.js.html +847 -0
- package/docs/user_index.js.html +156 -0
- package/docs/user_notification.js.html +218 -0
- package/docs/user_organization.js.html +347 -0
- package/docs/user_process.js.html +352 -0
- package/docs/user_register.js.html +322 -0
- package/docs/user_task.js.html +319 -0
- package/docs/user_task_available.js.html +252 -0
- package/docs/user_user.js.html +404 -0
- package/docs/utils_promises.js.html +235 -0
- package/package.json +7 -4
- package/readme.md +7 -8
- package/doc.md +0 -653
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
|
|
6
|
+
<head>
|
|
7
|
+
|
|
8
|
+
<meta charset="utf-8">
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
+
<title> user/user.js</title>
|
|
11
|
+
|
|
12
|
+
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
|
|
13
|
+
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
|
14
|
+
<script src="./build/entry.js"></script>
|
|
15
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
16
|
+
<!--[if lt IE 9]>
|
|
17
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
18
|
+
<![endif]-->
|
|
19
|
+
<link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
|
|
20
|
+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
|
|
21
|
+
<link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
|
|
22
|
+
<link type="text/css" rel="stylesheet" href="styles/app.min.css">
|
|
23
|
+
<link type="text/css" rel="stylesheet" href="styles/iframe.css">
|
|
24
|
+
<link type="text/css" rel="stylesheet" href="">
|
|
25
|
+
<script async defer src="https://buttons.github.io/buttons.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<body class="layout small-header">
|
|
33
|
+
<div id="stickyNavbarOverlay"></div>
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<div class="top-nav">
|
|
37
|
+
<div class="inner">
|
|
38
|
+
<a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
|
|
39
|
+
<span aria-hidden="true"></span>
|
|
40
|
+
<span aria-hidden="true"></span>
|
|
41
|
+
<span aria-hidden="true"></span>
|
|
42
|
+
</a>
|
|
43
|
+
<div class="logo">
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
</div>
|
|
47
|
+
<div class="menu">
|
|
48
|
+
|
|
49
|
+
<div class="navigation">
|
|
50
|
+
<a
|
|
51
|
+
href="index.html"
|
|
52
|
+
class="link"
|
|
53
|
+
>
|
|
54
|
+
Documentation
|
|
55
|
+
</a>
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div id="main">
|
|
64
|
+
<div
|
|
65
|
+
class="sidebar "
|
|
66
|
+
id="sidebarNav"
|
|
67
|
+
>
|
|
68
|
+
|
|
69
|
+
<nav>
|
|
70
|
+
|
|
71
|
+
<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Classes</h3><ul><li><a href="Admin.html">Admin</a></li><li><a href="AdminDocuments.html">AdminDocuments</a></li><li><a href="AdminForm.html">AdminForm</a></li><li><a href="AdminLists.html">AdminLists</a></li><li><a href="AdminMessage.html">AdminMessage</a></li><li><a href="AdminNotification.html">AdminNotification</a></li><li><a href="AdminPlugin.html">AdminPlugin</a></li><li><a href="AdminPolicy.html">AdminPolicy</a></li><li><a href="AdminProcesses.html">AdminProcesses</a></li><li><a href="AdminTask.html">AdminTask</a></li><li><a href="AdminUser.html">AdminUser</a></li><li><a href="Datasource.html">Datasource</a></li><li><a href="Dispatch.html">Dispatch</a></li><li><a href="Documents.html">Documents</a></li><li><a href="External.html">External</a></li><li><a href="GeoLocation.html">GeoLocation</a></li><li><a href="Login.html">Login</a></li><li><a href="Notification.html">Notification</a></li><li><a href="Organization.html">Organization</a></li><li><a href="Process.html">Process</a></li><li><a href="Register.html">Register</a></li><li><a href="Session.html">Session</a></li><li><a href="Task.html">Task</a></li><li><a href="TaskAvailable.html">TaskAvailable</a></li><li><a href="User.html">User</a></li><li><a href="Users.html">Users</a></li></ul></div>
|
|
72
|
+
|
|
73
|
+
</nav>
|
|
74
|
+
</div>
|
|
75
|
+
<div class="core" id="main-content-wrapper">
|
|
76
|
+
<div class="content">
|
|
77
|
+
<header class="page-title">
|
|
78
|
+
<p>Source</p>
|
|
79
|
+
<h1>user/user.js</h1>
|
|
80
|
+
</header>
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
<section>
|
|
87
|
+
<article>
|
|
88
|
+
<pre class="prettyprint source linenums"><code>import _ from 'lodash';
|
|
89
|
+
import Boom from '@hapi/boom';
|
|
90
|
+
import Joi from 'joi';
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Class for user, permission user
|
|
94
|
+
* @class
|
|
95
|
+
*/
|
|
96
|
+
class User {
|
|
97
|
+
|
|
98
|
+
constructor(options) {
|
|
99
|
+
Joi.assert(options, Joi.object().required());
|
|
100
|
+
Joi.assert(options.parent, Joi.object().required());
|
|
101
|
+
|
|
102
|
+
const self = this;
|
|
103
|
+
self._parent = options.parent;
|
|
104
|
+
self._client = self._parent.dispatch.getClient();
|
|
105
|
+
self.gender = {
|
|
106
|
+
male: 1,
|
|
107
|
+
female: 2,
|
|
108
|
+
nonBinary: 3
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
114
|
+
* @description Get the return data and check for errors
|
|
115
|
+
* @param {object} retData Response HTTP
|
|
116
|
+
* @return {*}
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
_returnData(retData, def = {}) {
|
|
120
|
+
if (retData.status !== 200) {
|
|
121
|
+
return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
122
|
+
} else {
|
|
123
|
+
return _.get(retData, 'data', def);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
129
|
+
* @description Set header with new session
|
|
130
|
+
* @param {string} session Session, token JWT
|
|
131
|
+
* @return {object} header with new session
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
_setHeader(session) {
|
|
135
|
+
return {
|
|
136
|
+
headers: {
|
|
137
|
+
authorization: session,
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
144
|
+
* @description Update avatar of user by session of user not allow session user SU
|
|
145
|
+
* @param {object} params Params to update avatar
|
|
146
|
+
* @param {string} params.avatar Image in base64 to update
|
|
147
|
+
* @param {string} params.type mimeType (image/png)
|
|
148
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
149
|
+
* @return {Promise}
|
|
150
|
+
* @public
|
|
151
|
+
* @async
|
|
152
|
+
* @example
|
|
153
|
+
*
|
|
154
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
155
|
+
* const api = new API();
|
|
156
|
+
* const params = {
|
|
157
|
+
* avatar: '55e4a3bd6be6b45210833fae',
|
|
158
|
+
* type: '123456',
|
|
159
|
+
* };
|
|
160
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
161
|
+
* await api.user.profile.updateAvatar(params, session);
|
|
162
|
+
*/
|
|
163
|
+
async updateAvatar(params, session) {
|
|
164
|
+
const self = this;
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
Joi.assert(params, Joi.object().required());
|
|
168
|
+
Joi.assert(params.avatar, Joi.string().required());
|
|
169
|
+
Joi.assert(params.type, Joi.string().required());
|
|
170
|
+
Joi.assert(session, Joi.string().required());
|
|
171
|
+
|
|
172
|
+
const {avatar, type} = params;
|
|
173
|
+
const payload = {avatar, type};
|
|
174
|
+
|
|
175
|
+
const apiCall = self._client.post(`/users/avatar`, payload, self._setHeader(session));
|
|
176
|
+
return self._returnData(await apiCall);
|
|
177
|
+
} catch (ex) {
|
|
178
|
+
throw ex;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
184
|
+
* @description Remove avatar of user by session of user not allow session user SU
|
|
185
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
186
|
+
* @return {Promise}
|
|
187
|
+
* @public
|
|
188
|
+
* @async
|
|
189
|
+
* @example
|
|
190
|
+
*
|
|
191
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
192
|
+
* const api = new API();
|
|
193
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
194
|
+
* await api.user.profile.removeAvatar(session);
|
|
195
|
+
*/
|
|
196
|
+
async removeAvatar(session) {
|
|
197
|
+
const self = this;
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
Joi.assert(session, Joi.string().required());
|
|
201
|
+
|
|
202
|
+
const apiCall = self._client.delete(`/users/avatar`, self._setHeader(session));
|
|
203
|
+
return self._returnData(await apiCall);
|
|
204
|
+
} catch (ex) {
|
|
205
|
+
throw ex;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
211
|
+
* @description Remove the signature of user by session
|
|
212
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
213
|
+
* @return {Promise}
|
|
214
|
+
* @public
|
|
215
|
+
* @async
|
|
216
|
+
* @example
|
|
217
|
+
*
|
|
218
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
219
|
+
* const api = new API();
|
|
220
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
221
|
+
* await api.user.profile.removeSignature(session);
|
|
222
|
+
*/
|
|
223
|
+
async removeSignature(session) {
|
|
224
|
+
const self = this;
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
Joi.assert(session, Joi.string().required());
|
|
228
|
+
|
|
229
|
+
const apiCall = self._client.delete(`/users/signature`, self._setHeader(session));
|
|
230
|
+
return self._returnData(await apiCall);
|
|
231
|
+
} catch (ex) {
|
|
232
|
+
throw ex;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
238
|
+
* @description Sava a new signature of user by session
|
|
239
|
+
* @param {object} data The signature data to save
|
|
240
|
+
* @param {string} data.type CURSIVE or HANDWRITE
|
|
241
|
+
* @param {string} data.file CURSIVE the <fontname>:<name used on the signature>
|
|
242
|
+
* HANDWRITE the base 64 image (w/o the mime a base prefix)
|
|
243
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
244
|
+
* @return {Promise}
|
|
245
|
+
* @public
|
|
246
|
+
* @async
|
|
247
|
+
* @example
|
|
248
|
+
*
|
|
249
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
250
|
+
* const api = new API();
|
|
251
|
+
* const data = {
|
|
252
|
+
* type: 'CURSIVE',
|
|
253
|
+
* file: 'allura:Mary John Heart'
|
|
254
|
+
* };
|
|
255
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
256
|
+
* await api.user.profile.saveSignature(data, session);
|
|
257
|
+
*
|
|
258
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
259
|
+
* const api = new API();
|
|
260
|
+
* const data = {
|
|
261
|
+
* type: 'HANDWRITE',
|
|
262
|
+
* file: 'iVBORw0KGgoAAAANSUhEUgAAAj...'
|
|
263
|
+
* };
|
|
264
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
265
|
+
* await api.user.profile.saveSignature(session);
|
|
266
|
+
*/
|
|
267
|
+
async saveSignature(data, session) {
|
|
268
|
+
const self = this;
|
|
269
|
+
|
|
270
|
+
try {
|
|
271
|
+
Joi.assert(data, Joi.object().required());
|
|
272
|
+
Joi.assert(data.type, Joi.string().required());
|
|
273
|
+
Joi.assert(data.file, Joi.string().required());
|
|
274
|
+
Joi.assert(session, Joi.string().required());
|
|
275
|
+
|
|
276
|
+
const apiCall = self._client.put(`/users/signature`, data, self._setHeader(session));
|
|
277
|
+
return self._returnData(await apiCall);
|
|
278
|
+
} catch (ex) {
|
|
279
|
+
throw ex;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
285
|
+
* @description Update a user profile by id
|
|
286
|
+
* @param {object} params Params to update task
|
|
287
|
+
* @param {string} params.name The name of the user
|
|
288
|
+
* @param {string} params.site The site of the user
|
|
289
|
+
* @param {string} params.faceboook The faceboook of the user
|
|
290
|
+
* @param {string} params.linkedin The linkedin of the user
|
|
291
|
+
* @param {date} params.dob The date of birth of the user
|
|
292
|
+
* @param {number<UserGender>} params.gender The gender of of the user self.gender
|
|
293
|
+
* @param {string} params.phone The phone
|
|
294
|
+
* @param {string} params.phone2 The phone 2
|
|
295
|
+
* @param {string} params.phone3 The phone 3
|
|
296
|
+
* @param {string} params.password The password to change
|
|
297
|
+
* @param {string} params.secQuestion The security question
|
|
298
|
+
* @param {string} params.secAnswer The security answer
|
|
299
|
+
* @param {string} params.timezone The timezone
|
|
300
|
+
* @param {string} params.userLanguage The user language
|
|
301
|
+
* @param {string} params.changePassword (required) If we need to change the status and we changed the password
|
|
302
|
+
* @param {string} params.acceptTermsOfUse If the user has accepted the terms of change
|
|
303
|
+
* @param {string} session Session, token JWT
|
|
304
|
+
* @return {Promise<void>}
|
|
305
|
+
* @public
|
|
306
|
+
* @async
|
|
307
|
+
* @example
|
|
308
|
+
*
|
|
309
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
310
|
+
* const api = new API();
|
|
311
|
+
* const params = {
|
|
312
|
+
* name: 'New Name'
|
|
313
|
+
* };
|
|
314
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
315
|
+
* await api.user.profile.findByIdAndUpdate(params, session);
|
|
316
|
+
*/
|
|
317
|
+
async findByIdAndUpdate(params = {}, session) {
|
|
318
|
+
const self = this;
|
|
319
|
+
|
|
320
|
+
try {
|
|
321
|
+
Joi.assert(session, Joi.string().required());
|
|
322
|
+
Joi.assert(params, Joi.object().required());
|
|
323
|
+
Joi.assert(params.changePassword, Joi.boolean().required());
|
|
324
|
+
|
|
325
|
+
if(_.isEmpty(params)) return;
|
|
326
|
+
|
|
327
|
+
const { changePassword = false, password = '' } = params;
|
|
328
|
+
|
|
329
|
+
if(changePassword && password === '') {
|
|
330
|
+
throw new Error('It is required to change the password')
|
|
331
|
+
} else {
|
|
332
|
+
params.changePassword = false;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const url = 'users';
|
|
336
|
+
const apiCall = self._client.put(url, params, self._setHeader(session));
|
|
337
|
+
return self._returnData(await apiCall);
|
|
338
|
+
} catch (ex) {
|
|
339
|
+
throw ex;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
345
|
+
* @description Change a user's organization
|
|
346
|
+
* @param {string} id Organization id
|
|
347
|
+
* @param {string} session Is token JWT of user NOT allow SU
|
|
348
|
+
* @return {Promise}
|
|
349
|
+
* @public
|
|
350
|
+
* @async
|
|
351
|
+
* @example
|
|
352
|
+
*
|
|
353
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
354
|
+
* const api = new API();
|
|
355
|
+
* const id = '616eccaaa9360a05293b10fe';
|
|
356
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
357
|
+
* await api.user.changeOrganization.updateAvatar(id, session);
|
|
358
|
+
*/
|
|
359
|
+
async changeOrganization(id, session) {
|
|
360
|
+
const self = this;
|
|
361
|
+
|
|
362
|
+
try {
|
|
363
|
+
Joi.assert(id, Joi.string().required());
|
|
364
|
+
Joi.assert(session, Joi.string().required());
|
|
365
|
+
|
|
366
|
+
const apiCall = self._client.put(`/organizations/${id}/change`, null, self._setHeader(session));
|
|
367
|
+
return self._returnData(await apiCall);
|
|
368
|
+
} catch (ex) {
|
|
369
|
+
throw ex;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export default User;
|
|
375
|
+
</code></pre>
|
|
376
|
+
</article>
|
|
377
|
+
</section>
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
</div>
|
|
383
|
+
|
|
384
|
+
<footer class="footer">
|
|
385
|
+
<div class="content has-text-centered">
|
|
386
|
+
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
|
|
387
|
+
<p class="sidebar-created-by">
|
|
388
|
+
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
389
|
+
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
390
|
+
</p>
|
|
391
|
+
</div>
|
|
392
|
+
</footer>
|
|
393
|
+
|
|
394
|
+
</div>
|
|
395
|
+
<div id="side-nav" class="side-nav">
|
|
396
|
+
</div>
|
|
397
|
+
</div>
|
|
398
|
+
<script src="scripts/app.min.js"></script>
|
|
399
|
+
<script>PR.prettyPrint();</script>
|
|
400
|
+
<script src="scripts/linenumber.js"> </script>
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
</body>
|
|
404
|
+
</html>
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
<!DOCTYPE html>
|
|
4
|
+
<html lang="en">
|
|
5
|
+
|
|
6
|
+
<head>
|
|
7
|
+
|
|
8
|
+
<meta charset="utf-8">
|
|
9
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
10
|
+
<title> utils/promises.js</title>
|
|
11
|
+
|
|
12
|
+
<script src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js"></script>
|
|
13
|
+
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
|
14
|
+
<script src="./build/entry.js"></script>
|
|
15
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
|
16
|
+
<!--[if lt IE 9]>
|
|
17
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
18
|
+
<![endif]-->
|
|
19
|
+
<link href="https://fonts.googleapis.com/css?family=Roboto:100,400,700|Inconsolata,700" rel="stylesheet">
|
|
20
|
+
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
|
|
21
|
+
<link type="text/css" rel="stylesheet" href="https://jmblog.github.io/color-themes-for-google-code-prettify/themes/tomorrow-night.min.css">
|
|
22
|
+
<link type="text/css" rel="stylesheet" href="styles/app.min.css">
|
|
23
|
+
<link type="text/css" rel="stylesheet" href="styles/iframe.css">
|
|
24
|
+
<link type="text/css" rel="stylesheet" href="">
|
|
25
|
+
<script async defer src="https://buttons.github.io/buttons.js"></script>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
</head>
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<body class="layout small-header">
|
|
33
|
+
<div id="stickyNavbarOverlay"></div>
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<div class="top-nav">
|
|
37
|
+
<div class="inner">
|
|
38
|
+
<a id="hamburger" role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
|
|
39
|
+
<span aria-hidden="true"></span>
|
|
40
|
+
<span aria-hidden="true"></span>
|
|
41
|
+
<span aria-hidden="true"></span>
|
|
42
|
+
</a>
|
|
43
|
+
<div class="logo">
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
</div>
|
|
47
|
+
<div class="menu">
|
|
48
|
+
|
|
49
|
+
<div class="navigation">
|
|
50
|
+
<a
|
|
51
|
+
href="index.html"
|
|
52
|
+
class="link"
|
|
53
|
+
>
|
|
54
|
+
Documentation
|
|
55
|
+
</a>
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
<div id="main">
|
|
64
|
+
<div
|
|
65
|
+
class="sidebar "
|
|
66
|
+
id="sidebarNav"
|
|
67
|
+
>
|
|
68
|
+
|
|
69
|
+
<nav>
|
|
70
|
+
|
|
71
|
+
<h2><a href="index.html">Documentation</a></h2><div class="category"><h3>Classes</h3><ul><li><a href="Admin.html">Admin</a></li><li><a href="AdminDocuments.html">AdminDocuments</a></li><li><a href="AdminForm.html">AdminForm</a></li><li><a href="AdminLists.html">AdminLists</a></li><li><a href="AdminMessage.html">AdminMessage</a></li><li><a href="AdminNotification.html">AdminNotification</a></li><li><a href="AdminPlugin.html">AdminPlugin</a></li><li><a href="AdminPolicy.html">AdminPolicy</a></li><li><a href="AdminProcesses.html">AdminProcesses</a></li><li><a href="AdminTask.html">AdminTask</a></li><li><a href="AdminUser.html">AdminUser</a></li><li><a href="Datasource.html">Datasource</a></li><li><a href="Dispatch.html">Dispatch</a></li><li><a href="Documents.html">Documents</a></li><li><a href="External.html">External</a></li><li><a href="GeoLocation.html">GeoLocation</a></li><li><a href="Login.html">Login</a></li><li><a href="Notification.html">Notification</a></li><li><a href="Organization.html">Organization</a></li><li><a href="Process.html">Process</a></li><li><a href="Register.html">Register</a></li><li><a href="Session.html">Session</a></li><li><a href="Task.html">Task</a></li><li><a href="TaskAvailable.html">TaskAvailable</a></li><li><a href="User.html">User</a></li><li><a href="Users.html">Users</a></li></ul></div>
|
|
72
|
+
|
|
73
|
+
</nav>
|
|
74
|
+
</div>
|
|
75
|
+
<div class="core" id="main-content-wrapper">
|
|
76
|
+
<div class="content">
|
|
77
|
+
<header class="page-title">
|
|
78
|
+
<p>Source</p>
|
|
79
|
+
<h1>utils/promises.js</h1>
|
|
80
|
+
</header>
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
<section>
|
|
87
|
+
<article>
|
|
88
|
+
<pre class="prettyprint source linenums"><code>import _ from 'lodash';
|
|
89
|
+
import Boom from '@hapi/boom';
|
|
90
|
+
|
|
91
|
+
class ThePromise {
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @description Logger call api professional
|
|
95
|
+
* @param {object} context Process or Domain
|
|
96
|
+
* @param {string} message Message to log
|
|
97
|
+
* @param {object} data Object to show log
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
_logger({context = null, message, data}) {
|
|
101
|
+
try {
|
|
102
|
+
|
|
103
|
+
if (context) {
|
|
104
|
+
data = _.isObject(data) ? data : {data};
|
|
105
|
+
|
|
106
|
+
const logSystemMager = _.hasIn(context, 'logger')
|
|
107
|
+
&& _.isFunction(context.logger)
|
|
108
|
+
&& _.hasIn(context.logger(), 'trace')
|
|
109
|
+
&& _.isFunction(context.logger().trace);
|
|
110
|
+
|
|
111
|
+
const logMicroservices = _.hasIn(context, 'log')
|
|
112
|
+
&& _.isFunction(context.log)
|
|
113
|
+
&& _.hasIn(context.log(), 'info')
|
|
114
|
+
&& _.isFunction(context.log().info);
|
|
115
|
+
|
|
116
|
+
if (logSystemMager) {
|
|
117
|
+
context.logger().trace(message, data);
|
|
118
|
+
} else if (logMicroservices) {
|
|
119
|
+
context.log().info(message, data);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch (ex) {
|
|
123
|
+
const message = _.hasIn(ex, 'message') ? ex.message : `Fail logger action: ${message}`;
|
|
124
|
+
throw new Error(message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @description Clean process, when call API in process
|
|
130
|
+
* @param {object} params
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
_cleanParams(params) {
|
|
134
|
+
if (_.hasIn(params, 'process')) {
|
|
135
|
+
delete params.process;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @description Calls to execute a promise or a callback, so we can support promises and callbacks at the same time
|
|
141
|
+
* NOTE: This promise is focused on the process area.
|
|
142
|
+
* @param {object} options
|
|
143
|
+
* - process || domain (optional): if you want to log into the process || Domain
|
|
144
|
+
* - funcName (optional): the name of the function you are calling
|
|
145
|
+
* - params (optional): parameters to log
|
|
146
|
+
* - cb (optional): the callback, if we have one
|
|
147
|
+
* - debug: Show or hide debug
|
|
148
|
+
* @param func: the function to call to execute
|
|
149
|
+
* @return {*}
|
|
150
|
+
*/
|
|
151
|
+
exec(options, func) {
|
|
152
|
+
const self = this;
|
|
153
|
+
|
|
154
|
+
return new Promise(async (resolve, reject) => {
|
|
155
|
+
const {debug, cb, context, funcName, params} = options || {};
|
|
156
|
+
const {success: debugForSuccess, error: debugForError} = debug;
|
|
157
|
+
|
|
158
|
+
let err;
|
|
159
|
+
let retData;
|
|
160
|
+
|
|
161
|
+
// Ensure we remove it, since we do not have it. It can cause circular referenfe on JSON stringify.
|
|
162
|
+
self._cleanParams(params);
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
if (debugForSuccess) {
|
|
166
|
+
self._logger({context, message: `START: ${funcName} executed successfully`, data: params});
|
|
167
|
+
}
|
|
168
|
+
retData = await func();
|
|
169
|
+
} catch (ex) {
|
|
170
|
+
err = ex;
|
|
171
|
+
|
|
172
|
+
} finally {
|
|
173
|
+
|
|
174
|
+
if (retData === null) {
|
|
175
|
+
err = Boom.notFound(`ERROR: ${funcName} cannot find item`);
|
|
176
|
+
if (debugForError) {
|
|
177
|
+
self._logger({context, message: `ERROR: ${funcName} cannot find item`, data: params});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (_.isFunction(cb)) {
|
|
181
|
+
|
|
182
|
+
if (debugForError) {
|
|
183
|
+
self._logger({context, message: `ERROR: ${funcName}`, data: params});
|
|
184
|
+
}
|
|
185
|
+
cb(err, retData);
|
|
186
|
+
}
|
|
187
|
+
if (err) {
|
|
188
|
+
if (debugForError) {
|
|
189
|
+
self._logger({context, message: `ERROR: ${funcName}`, data: params});
|
|
190
|
+
}
|
|
191
|
+
reject(err);
|
|
192
|
+
} else {
|
|
193
|
+
if (debugForSuccess) {
|
|
194
|
+
self._logger({context, message: `END: ${funcName} executed successfully`, data: {params, retData}});
|
|
195
|
+
}
|
|
196
|
+
resolve(retData);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const thePromise = new ThePromise();
|
|
204
|
+
|
|
205
|
+
export default thePromise;
|
|
206
|
+
</code></pre>
|
|
207
|
+
</article>
|
|
208
|
+
</section>
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<footer class="footer">
|
|
216
|
+
<div class="content has-text-centered">
|
|
217
|
+
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
|
|
218
|
+
<p class="sidebar-created-by">
|
|
219
|
+
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
220
|
+
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
221
|
+
</p>
|
|
222
|
+
</div>
|
|
223
|
+
</footer>
|
|
224
|
+
|
|
225
|
+
</div>
|
|
226
|
+
<div id="side-nav" class="side-nav">
|
|
227
|
+
</div>
|
|
228
|
+
</div>
|
|
229
|
+
<script src="scripts/app.min.js"></script>
|
|
230
|
+
<script>PR.prettyPrint();</script>
|
|
231
|
+
<script src="scripts/linenumber.js"> </script>
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
</body>
|
|
235
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docbrasil/api-systemmanager",
|
|
3
3
|
"description": "Module API System Manager",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.108",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"
|
|
7
|
-
"doc
|
|
6
|
+
"htmldoc": "rm -rf docs && jsdoc api/** -d docs -t ./node_modules/better-docs",
|
|
7
|
+
"doc": "rm -rf doc && mkdir doc && jsdoc2md api/**/* api/* > doc/api.md",
|
|
8
|
+
"doc:w": "rimraf doc/api.md && jsdoc2md api/**/* > doc/api.md",
|
|
8
9
|
"build": "node bundleRollup.js"
|
|
9
10
|
},
|
|
10
11
|
"type": "module",
|
|
@@ -35,7 +36,6 @@
|
|
|
35
36
|
"crypto-js": "^4.1.1",
|
|
36
37
|
"i": "^0.3.7",
|
|
37
38
|
"joi": "^17.4.2",
|
|
38
|
-
"jsdoc-to-markdown": "^6.0.1",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
40
40
|
"moment": "^2.27.0",
|
|
41
41
|
"npm": "^6.14.6"
|
|
@@ -46,9 +46,12 @@
|
|
|
46
46
|
"@rollup/plugin-json": "^4.1.0",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
48
48
|
"axios-esm": "^1.0.0",
|
|
49
|
+
"better-docs": "^2.7.2",
|
|
49
50
|
"chai": "^4.3.7",
|
|
50
51
|
"dayjs": "^1.10.7",
|
|
51
52
|
"glob": "~7.1.1",
|
|
53
|
+
"jsdoc": "^4.0.2",
|
|
54
|
+
"jsdoc-to-markdown": "^6.0.1",
|
|
52
55
|
"license-checker": "^8.0.4",
|
|
53
56
|
"lodash-es": "^4.17.21",
|
|
54
57
|
"mocha": "^10.2.0",
|