@docbrasil/api-systemmanager 1.0.106 → 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/api/user/process.js +44 -0
- package/api/user/task.js +1 -0
- package/api/user/task_available.js +1 -1
- package/dist/bundle.cjs +87 -1
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +412 -1
- 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,352 @@
|
|
|
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/process.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/process.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 process, permission user
|
|
94
|
+
* @class
|
|
95
|
+
*/
|
|
96
|
+
class Process {
|
|
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
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
109
|
+
* @description Get the return data and check for errors
|
|
110
|
+
* @param {object} retData Response HTTP
|
|
111
|
+
* @return {*}
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
_returnData(retData, def = {}) {
|
|
115
|
+
if (retData.status !== 200) {
|
|
116
|
+
return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
117
|
+
} else {
|
|
118
|
+
return _.get(retData, 'data', def);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
124
|
+
* @description Set header with new session
|
|
125
|
+
* @param {string} session Session, token JWT
|
|
126
|
+
* @return {object} header with new session
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
_setHeader(session) {
|
|
130
|
+
return {
|
|
131
|
+
headers: {
|
|
132
|
+
authorization: session,
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
139
|
+
* @description Set header for a bigger payload
|
|
140
|
+
* @param {string} session Session, token JWT
|
|
141
|
+
* @return {object} header with new session
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
_setMaxContentHeader(session) {
|
|
145
|
+
return {
|
|
146
|
+
headers: {
|
|
147
|
+
authorization: session
|
|
148
|
+
},
|
|
149
|
+
maxContentLength: Infinity,
|
|
150
|
+
maxBodyLength: Infinity
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
156
|
+
* @description Start process
|
|
157
|
+
* @param {object} params Params to start process
|
|
158
|
+
* @param {string} params.processId Process id (_id database);
|
|
159
|
+
* @param {string} params.orgId Organization id (_id database);
|
|
160
|
+
* @param {object} [params.payload={}] Start process with data
|
|
161
|
+
* @param {string} session Session, token JWT
|
|
162
|
+
* @return {Promise}
|
|
163
|
+
* @public
|
|
164
|
+
* @async
|
|
165
|
+
* @example
|
|
166
|
+
*
|
|
167
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
168
|
+
* const api = new API();
|
|
169
|
+
* const params = {
|
|
170
|
+
* processId: '5dadd01dc4af3941d42f8c5c',
|
|
171
|
+
* orgId: '5edd11c46b6ce9729c2c297c',
|
|
172
|
+
* payload: {}
|
|
173
|
+
* }
|
|
174
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
175
|
+
* await api.user.process.start(params, session);
|
|
176
|
+
*/
|
|
177
|
+
async start(params, session) {
|
|
178
|
+
const self = this;
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
Joi.assert(params, Joi.object().required());
|
|
182
|
+
Joi.assert(params.processId, Joi.string().required());
|
|
183
|
+
Joi.assert(params.orgId, Joi.string().required());
|
|
184
|
+
Joi.assert(params.payload, Joi.object());
|
|
185
|
+
Joi.assert(session, Joi.string().required());
|
|
186
|
+
|
|
187
|
+
const {processId, orgId, payload = {}} = params;
|
|
188
|
+
const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}`, payload, self._setMaxContentHeader(session));
|
|
189
|
+
return self._returnData(await apiCall);
|
|
190
|
+
} catch (ex) {
|
|
191
|
+
throw ex;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
197
|
+
* @description Get process properties of process
|
|
198
|
+
* @param {object} params Params to get process properties
|
|
199
|
+
* @param {string} params.processId Process id (_id database);
|
|
200
|
+
* @param {string} params.orgId Organization id (_id database);
|
|
201
|
+
* @param {string} session Session, token JWT
|
|
202
|
+
* @return {Promise}
|
|
203
|
+
* @public
|
|
204
|
+
* @async
|
|
205
|
+
* @example
|
|
206
|
+
*
|
|
207
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
208
|
+
* const api = new API();
|
|
209
|
+
* const params = {
|
|
210
|
+
* processId: '5dadd01dc4af3941d42f8c5c',
|
|
211
|
+
* orgId: '5edd11c46b6ce9729c2c297c',
|
|
212
|
+
* }
|
|
213
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
214
|
+
* await api.user.process.getProcessProperties(params, session);
|
|
215
|
+
*/
|
|
216
|
+
async getProcessProperties(params, session) {
|
|
217
|
+
const self = this;
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
Joi.assert(params, Joi.object().required());
|
|
221
|
+
Joi.assert(params.processId, Joi.string().required());
|
|
222
|
+
Joi.assert(params.orgId, Joi.string().required());
|
|
223
|
+
Joi.assert(session, Joi.string().required());
|
|
224
|
+
|
|
225
|
+
const {processId, orgId} = params;
|
|
226
|
+
const apiCall = self._client.get(`/organizations/${orgId}/process/${processId}/properties`, self._setHeader(session));
|
|
227
|
+
return self._returnData(await apiCall);
|
|
228
|
+
} catch (ex) {
|
|
229
|
+
throw ex;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
235
|
+
* @description Get the search info of a organization process
|
|
236
|
+
* @param {object} params Params to get search info
|
|
237
|
+
* @param {string} params.orgProcessId The id of an organization process (_id database);
|
|
238
|
+
* @param {string} params.orgId Organization id (_id database);
|
|
239
|
+
* @param {string} session Session, token JWT
|
|
240
|
+
* @return {Promise} the search info result
|
|
241
|
+
* @return {string} name the name of the organization process
|
|
242
|
+
* @return {object} processIndexFields the list of fields to index
|
|
243
|
+
* @return {object} processParticipantsGroup the permissions in this organization process
|
|
244
|
+
* @return {object} stepsProperties the organization process steps properties
|
|
245
|
+
* @return {string} _id the same organization id
|
|
246
|
+
* @
|
|
247
|
+
* @public
|
|
248
|
+
* @async
|
|
249
|
+
* @example
|
|
250
|
+
*
|
|
251
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
252
|
+
* const api = new API();
|
|
253
|
+
* const params = {
|
|
254
|
+
* orgProcessId: '5dadd01dc4af3941d42f8c67',
|
|
255
|
+
* orgId: '5edd11c46b6ce9729c2c297c',
|
|
256
|
+
* }
|
|
257
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
258
|
+
* const retSearchInfo = await api.user.process.getOrgProcessSearchInfo(params, session);
|
|
259
|
+
*/
|
|
260
|
+
async getOrgProcessSearchInfo(params, session) {
|
|
261
|
+
const self = this;
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
Joi.assert(params, Joi.object().required());
|
|
265
|
+
Joi.assert(params.orgProcessId, Joi.string().required());
|
|
266
|
+
Joi.assert(params.orgId, Joi.string().required());
|
|
267
|
+
Joi.assert(session, Joi.string().required());
|
|
268
|
+
|
|
269
|
+
const {orgProcessId, orgId} = params;
|
|
270
|
+
const apiCall = self._client.get(`/organizations/${orgId}/orgprocess/${orgProcessId}/search/info`, self._setHeader(session));
|
|
271
|
+
return self._returnData(await apiCall);
|
|
272
|
+
} catch (ex) {
|
|
273
|
+
throw ex;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
279
|
+
* @description Method to search processes
|
|
280
|
+
* @param {object} params Params to search processes
|
|
281
|
+
* @param {object} params.query Search process query
|
|
282
|
+
* @param {object} params.orgId Organization id (_id database)
|
|
283
|
+
* @param {string} session Session, token JWT
|
|
284
|
+
* @returns {promise} returned data from the search
|
|
285
|
+
* @returns {number} count the count of items searched
|
|
286
|
+
* @returns {array<object>} items the items returned from search
|
|
287
|
+
* @returns {number} page the page of the search (on pagination), zero indexed
|
|
288
|
+
* @returns {number} perPage how many items per page
|
|
289
|
+
* @public
|
|
290
|
+
* @example
|
|
291
|
+
*
|
|
292
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
293
|
+
* const api = new API();
|
|
294
|
+
* const params = {
|
|
295
|
+
* query: {"orgProcessId": {"value":"62c2d1cdfb5455c195d1baa1","oper":"=","type":"string"},"s":[{"historyBegin":{"order":"desc"}}],"i":1,"p":20},
|
|
296
|
+
* orgId: '55e4a3bd6be6b45210833fae',
|
|
297
|
+
* };
|
|
298
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
299
|
+
* const retSearch = await api.user.process.find(params, session);
|
|
300
|
+
*/
|
|
301
|
+
async find(params, session) {
|
|
302
|
+
const self = this;
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
Joi.assert(params, Joi.object().required(), 'Params to search processes');
|
|
306
|
+
Joi.assert(params.query, Joi.object().required(), 'The query for the search');
|
|
307
|
+
Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
|
|
308
|
+
Joi.assert(session, Joi.string().required(), 'Session token JWT');
|
|
309
|
+
|
|
310
|
+
const {query, orgId} = params;
|
|
311
|
+
const queryString = JSON.stringify(query);
|
|
312
|
+
const apiCall = self._client
|
|
313
|
+
.post(`/organizations/${orgId}/process/advsearch?query=${queryString}`, {}, self._setHeader(session));
|
|
314
|
+
|
|
315
|
+
return self._returnData(await apiCall);
|
|
316
|
+
} catch (ex) {
|
|
317
|
+
throw ex;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export default Process;
|
|
323
|
+
</code></pre>
|
|
324
|
+
</article>
|
|
325
|
+
</section>
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
</div>
|
|
331
|
+
|
|
332
|
+
<footer class="footer">
|
|
333
|
+
<div class="content has-text-centered">
|
|
334
|
+
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
|
|
335
|
+
<p class="sidebar-created-by">
|
|
336
|
+
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
337
|
+
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
338
|
+
</p>
|
|
339
|
+
</div>
|
|
340
|
+
</footer>
|
|
341
|
+
|
|
342
|
+
</div>
|
|
343
|
+
<div id="side-nav" class="side-nav">
|
|
344
|
+
</div>
|
|
345
|
+
</div>
|
|
346
|
+
<script src="scripts/app.min.js"></script>
|
|
347
|
+
<script>PR.prettyPrint();</script>
|
|
348
|
+
<script src="scripts/linenumber.js"> </script>
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
</body>
|
|
352
|
+
</html>
|
|
@@ -0,0 +1,322 @@
|
|
|
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/register.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/register.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
|
+
import Cypher from '../utils/cypher.js';
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Class for user registration in a user
|
|
95
|
+
* @class
|
|
96
|
+
*/
|
|
97
|
+
class Register {
|
|
98
|
+
|
|
99
|
+
constructor(options) {
|
|
100
|
+
Joi.assert(options, Joi.object().required());
|
|
101
|
+
Joi.assert(options.parent, Joi.object().required());
|
|
102
|
+
|
|
103
|
+
const self = this;
|
|
104
|
+
self.parent = options.parent;
|
|
105
|
+
self._client = self.parent.dispatch.getClient();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
110
|
+
* @description Get the return data and check for errors
|
|
111
|
+
* @param {object} retData Response HTTP
|
|
112
|
+
* @return {*}
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
_returnData(retData, def = {}) {
|
|
116
|
+
if (retData.status !== 200) {
|
|
117
|
+
return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
|
|
118
|
+
} else {
|
|
119
|
+
return _.get(retData, 'data', def);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
125
|
+
* @description Set header with new session
|
|
126
|
+
* @param {string} session Session, token JWT
|
|
127
|
+
* @return {object} header with new session
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
_setHeader(session) {
|
|
131
|
+
return {
|
|
132
|
+
headers: {
|
|
133
|
+
authorization: session,
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
140
|
+
* @param {object} params.registerId The registerId that comes with the registration page context
|
|
141
|
+
* @return {string} orgname The orgname of the organization in the registerId
|
|
142
|
+
* @public
|
|
143
|
+
* @example
|
|
144
|
+
*
|
|
145
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
146
|
+
* const api = new API();
|
|
147
|
+
* const params = {
|
|
148
|
+
* registerId: 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...'
|
|
149
|
+
* };
|
|
150
|
+
* const orgname = await api.user.register.getOrgname(params);
|
|
151
|
+
*/
|
|
152
|
+
getOrgname(registerId) {
|
|
153
|
+
const { orgname = '' } = Cypher.get(registerId) || {};
|
|
154
|
+
return orgname;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
159
|
+
* @description Method to find task by id
|
|
160
|
+
* @param {object} params Params to get task
|
|
161
|
+
* @param {string} params.registerId The registerId that comes with the registration page context
|
|
162
|
+
* @param {object} params.email The email to validate
|
|
163
|
+
* @returns {promise<object>} data
|
|
164
|
+
* @returns {boolean} data.success If the operation was successfully done (true|false)
|
|
165
|
+
* @returns {boolean} data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned
|
|
166
|
+
* @returns {string} data.registrationEmailInfoRaw The fully cryptographed registration information
|
|
167
|
+
* @returns {object} data.registrationEmailInfo The registration information
|
|
168
|
+
* @returns {string} data.registrationEmailInfo.orgname The orgname
|
|
169
|
+
* @returns {string} data.registrationEmailInfo.orgId The orgId of the organization
|
|
170
|
+
* @returns {string} data.registrationEmailInfo.guid The unique id for the registration
|
|
171
|
+
* @returns {object} data.registrationEmailInfo.emailValidation The email validation information
|
|
172
|
+
* @returns {string} data.registrationEmailInfo.emailValidation.email The email that the code was sent to
|
|
173
|
+
* @returns {string} data.registrationEmailInfo.emailValidation.code The 4 digit code to validate the email
|
|
174
|
+
* @public
|
|
175
|
+
* @example
|
|
176
|
+
*
|
|
177
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
178
|
+
* const api = new API();
|
|
179
|
+
* const params = {
|
|
180
|
+
* registerId: 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
|
|
181
|
+
* email: 'myemail@company.com'
|
|
182
|
+
* };
|
|
183
|
+
* const retData = await api.user.register.validateEmail(params);
|
|
184
|
+
*/
|
|
185
|
+
async validateEmail(params = {}) {
|
|
186
|
+
const self = this;
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
Joi.assert(params, Joi.object().required(), 'Params to get task');
|
|
190
|
+
Joi.assert(params.registerId, Joi.string().required(), ' RegisterId for registration');
|
|
191
|
+
Joi.assert(params.email, Joi.string().required(), ' The emnail to register');
|
|
192
|
+
|
|
193
|
+
const { registerId = '', email = '' } = params;
|
|
194
|
+
const registerInfo = Cypher.get(registerId) || {};
|
|
195
|
+
const infoData = { ...registerInfo, email };
|
|
196
|
+
const payload = { info: Cypher.set(infoData) };
|
|
197
|
+
const apiCall = self._client
|
|
198
|
+
.post(`/users/validate/email`, payload);
|
|
199
|
+
|
|
200
|
+
const { success = false, info = '', userAlreadyExists = false } = self._returnData(await apiCall);
|
|
201
|
+
const retData = { success, userAlreadyExists, registrationEmailInfoRaw: info, registrationEmailInfo: Cypher.get(info) };
|
|
202
|
+
return retData;
|
|
203
|
+
} catch (ex) {
|
|
204
|
+
throw ex;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
210
|
+
* @description Method to register a user
|
|
211
|
+
* @param {object} params Params to get task
|
|
212
|
+
* @param {string} params.registerId The registerId that comes with the registration page context
|
|
213
|
+
* @param {string} params.type=sign The type of the registration. By defailt,
|
|
214
|
+
* @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.
|
|
215
|
+
* @param {object} params.emailInfo The information for the email validation
|
|
216
|
+
* @param {string} params.emailInfo.email The email validation information
|
|
217
|
+
* @param {string} params.emailInfo.code The 4 digit code to validate the email
|
|
218
|
+
* @param {object} params.registerData The registration data
|
|
219
|
+
* @param {string} params.registerData.name The name if the user
|
|
220
|
+
* @param {string} params.registerData.registerEmail The email of the user
|
|
221
|
+
* @param {string} params.registerData.phone The phone of the user
|
|
222
|
+
* @param {string} params.registerData.idcard The ID card of the user
|
|
223
|
+
* @param {string} params.registerData.registerPassword The user password in open text
|
|
224
|
+
* @param {string} params.registerData.emailValidationCode The code used to validate the email
|
|
225
|
+
* @param {string} params.registerData.phoneValidationCode The code used to validate the phone
|
|
226
|
+
* @param {string} params.registerData.language The defaulf navigator language (i.e.: navigator.language)
|
|
227
|
+
* @param {string} params.registerData.timezone The defaulf navigator timezone (i.e.: Intl.DateTimeFormat().resolvedOptions().timeZone)
|
|
228
|
+
* @returns {promise<object>} data
|
|
229
|
+
* @returns {boolean} data.success If the operation was successfully done (true|false)
|
|
230
|
+
* @returns {boolean} data.userAlreadyExists If the user already exists (true|false), if true, then the other information is not returned
|
|
231
|
+
* @returns {object} auth The full authentication data with session, if login is true.
|
|
232
|
+
* @returns {string} auth.redirectUrl The url to redirect.
|
|
233
|
+
* @public
|
|
234
|
+
* @example
|
|
235
|
+
*
|
|
236
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
237
|
+
* const api = new API();
|
|
238
|
+
* const params ={
|
|
239
|
+
* "registerId": 'U2FsdGVkX1+xEq+sV6OSBr4aEVoiE9H1b4xzLe+vqmXB+ShVNc/FvJGxnIz4tZv6jBJkk4aQzz24O5koH+rGmdl/DjqfyWfENe5NFuQ+6xXhuOSN24Z+Topo87+e+CrRO8ox...',
|
|
240
|
+
* "type": 'sign',
|
|
241
|
+
* "login": false,
|
|
242
|
+
* "emailInfo": {
|
|
243
|
+
* "code": "5974",
|
|
244
|
+
* "email": "cbtoto_1@mailinator.com"
|
|
245
|
+
* },
|
|
246
|
+
* "registerData": {
|
|
247
|
+
* "name": "Augusto Totlo",
|
|
248
|
+
* "registerEmail": "cbtoto_1@mailinator.com",
|
|
249
|
+
* "phone": "",
|
|
250
|
+
* "idcard": "",
|
|
251
|
+
* "dob": "1978-01-12T03:00:00.000Z",
|
|
252
|
+
* "registerPassword": "123456",
|
|
253
|
+
* "emailValidationCode": "5974",
|
|
254
|
+
* "phoneValidationCode": "",
|
|
255
|
+
* "language": "en-US",
|
|
256
|
+
* "timezone": "Europe/Dublin"
|
|
257
|
+
* }
|
|
258
|
+
* };
|
|
259
|
+
* const retData = await api.user.register.execute(params);
|
|
260
|
+
*/
|
|
261
|
+
async execute(params = {}) {
|
|
262
|
+
const self = this;
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
Joi.assert(params, Joi.object().required(), 'Params to get task');
|
|
266
|
+
Joi.assert(params.registerId, Joi.string().required(), ' RegisterId for registration');
|
|
267
|
+
Joi.assert(params.emailInfo, Joi.object().required(), ' The email info');
|
|
268
|
+
Joi.assert(params.registerData, Joi.object().required(), ' The registerData');
|
|
269
|
+
|
|
270
|
+
const {
|
|
271
|
+
type = 'sign',
|
|
272
|
+
registerId = '',
|
|
273
|
+
emailInfo = {},
|
|
274
|
+
registerData = {},
|
|
275
|
+
login = false
|
|
276
|
+
} = params;
|
|
277
|
+
const registerInfo = Cypher.get(registerId) || {};
|
|
278
|
+
const payload = { ...registerInfo, type, login, emailInfo, registerData };
|
|
279
|
+
const payloadInfo = { info: Cypher.set(payload) };
|
|
280
|
+
const apiCall = self._client
|
|
281
|
+
.put(`/users/register`, payloadInfo);
|
|
282
|
+
|
|
283
|
+
const { success = false, userAlreadyExists = false, auth } = self._returnData(await apiCall);
|
|
284
|
+
const retData = { success, userAlreadyExists, auth };
|
|
285
|
+
return retData;
|
|
286
|
+
} catch (ex) {
|
|
287
|
+
throw ex;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export default Register;
|
|
293
|
+
</code></pre>
|
|
294
|
+
</article>
|
|
295
|
+
</section>
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
</div>
|
|
301
|
+
|
|
302
|
+
<footer class="footer">
|
|
303
|
+
<div class="content has-text-centered">
|
|
304
|
+
<p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
|
|
305
|
+
<p class="sidebar-created-by">
|
|
306
|
+
<a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
|
|
307
|
+
<a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
|
|
308
|
+
</p>
|
|
309
|
+
</div>
|
|
310
|
+
</footer>
|
|
311
|
+
|
|
312
|
+
</div>
|
|
313
|
+
<div id="side-nav" class="side-nav">
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
<script src="scripts/app.min.js"></script>
|
|
317
|
+
<script>PR.prettyPrint();</script>
|
|
318
|
+
<script src="scripts/linenumber.js"> </script>
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
</body>
|
|
322
|
+
</html>
|