@docbrasil/api-systemmanager 1.0.107 → 1.0.109

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 (73) hide show
  1. package/.github/workflows/static.yml +43 -0
  2. package/api/external.js +41 -0
  3. package/dist/bundle.cjs +41 -0
  4. package/dist/bundle.mjs +1 -1
  5. package/doc/api.md +382 -0
  6. package/docs/Admin.html +336 -0
  7. package/docs/AdminDocuments.html +2235 -0
  8. package/docs/AdminForm.html +934 -0
  9. package/docs/AdminLists.html +895 -0
  10. package/docs/AdminMessage.html +1490 -0
  11. package/docs/AdminNotification.html +1636 -0
  12. package/docs/AdminPlugin.html +696 -0
  13. package/docs/AdminPolicy.html +451 -0
  14. package/docs/AdminProcesses.html +692 -0
  15. package/docs/AdminTask.html +740 -0
  16. package/docs/AdminUser.html +1203 -0
  17. package/docs/Datasource.html +660 -0
  18. package/docs/Dispatch.html +624 -0
  19. package/docs/Documents.html +4875 -0
  20. package/docs/External.html +1497 -0
  21. package/docs/GeoLocation.html +503 -0
  22. package/docs/Login.html +1839 -0
  23. package/docs/Notification.html +625 -0
  24. package/docs/Organization.html +2767 -0
  25. package/docs/Process.html +1598 -0
  26. package/docs/Register.html +1604 -0
  27. package/docs/Session.html +482 -0
  28. package/docs/Task.html +1394 -0
  29. package/docs/TaskAvailable.html +893 -0
  30. package/docs/User.html +2002 -0
  31. package/docs/Users.html +569 -0
  32. package/docs/admin_doctypes.js.html +193 -0
  33. package/docs/admin_document.js.html +449 -0
  34. package/docs/admin_form.js.html +268 -0
  35. package/docs/admin_index.js.html +163 -0
  36. package/docs/admin_list.js.html +250 -0
  37. package/docs/admin_message.js.html +311 -0
  38. package/docs/admin_notification.js.html +350 -0
  39. package/docs/admin_organization.js.html +241 -0
  40. package/docs/admin_plugin.js.html +233 -0
  41. package/docs/admin_policy.js.html +195 -0
  42. package/docs/admin_processes.js.html +487 -0
  43. package/docs/admin_task.js.html +242 -0
  44. package/docs/admin_user.js.html +302 -0
  45. package/docs/dispatch.js.html +218 -0
  46. package/docs/external.js.html +333 -0
  47. package/docs/general_geoLocation.js.html +205 -0
  48. package/docs/general_index.js.html +140 -0
  49. package/docs/index.html +129 -0
  50. package/docs/login.js.html +384 -0
  51. package/docs/scripts/app.min.js +1 -0
  52. package/docs/scripts/linenumber.js +26 -0
  53. package/docs/scripts/search.js +39 -0
  54. package/docs/session.js.html +202 -0
  55. package/docs/styles/app.min.css +1 -0
  56. package/docs/styles/iframe.css +13 -0
  57. package/docs/styles/prettify-jsdoc.css +111 -0
  58. package/docs/styles/prettify-tomorrow.css +132 -0
  59. package/docs/styles/reset.css +44 -0
  60. package/docs/user_datasource.js.html +261 -0
  61. package/docs/user_document.js.html +847 -0
  62. package/docs/user_index.js.html +156 -0
  63. package/docs/user_notification.js.html +218 -0
  64. package/docs/user_organization.js.html +347 -0
  65. package/docs/user_process.js.html +352 -0
  66. package/docs/user_register.js.html +322 -0
  67. package/docs/user_task.js.html +319 -0
  68. package/docs/user_task_available.js.html +252 -0
  69. package/docs/user_user.js.html +404 -0
  70. package/docs/utils_promises.js.html +235 -0
  71. package/package.json +7 -4
  72. package/readme.md +7 -8
  73. package/doc.md +0 -653
@@ -0,0 +1,384 @@
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> login.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>login.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 Joi from 'joi';
90
+
91
+ /**
92
+ * @class Login manager
93
+ */
94
+ class Login {
95
+
96
+ constructor(options) {
97
+
98
+ Joi.assert(options, Joi.object().required());
99
+ Joi.assert(options.parent, Joi.object().required());
100
+
101
+ const self = this;
102
+ self.parent = options.parent;
103
+ self._client = self.parent.dispatch.getClient();
104
+ }
105
+
106
+ /**
107
+ * @author Augusto Pissarra &lt;abernardo.br@gmail.com>
108
+ * @description Get the return data and check for errors
109
+ * @param {object} retData Response HTTP
110
+ * @return {*}
111
+ * @private
112
+ */
113
+ _returnData(retData, def = {}) {
114
+ if (retData.status !== 200) {
115
+ throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
116
+ } else {
117
+ return _.get(retData, 'data', def);
118
+ }
119
+ }
120
+
121
+ /**
122
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
123
+ * @description Set header with new session
124
+ * @param {string} session Session, token JWT
125
+ * @return {object} header with new session
126
+ * @private
127
+ */
128
+ _setHeader(session) {
129
+ return {
130
+ headers: {
131
+ authorization: session,
132
+ }
133
+ };
134
+ }
135
+
136
+ /**
137
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
138
+ * @description Login with social login Facebook
139
+ * @param {object} params Params to login Facebook
140
+ * @param {string} params.accessToken Access token of the system manager
141
+ * @param {object} params.initialUserData Object with roles default if sigin
142
+ * @param {array} params.initialUserData.externalRoles Array with permission of user
143
+ * @return {promise&lt;object>} data
144
+ * @return {object} data.auth true or false if we have the user authenticaited correctly
145
+ * @return {object} data.user the logged user
146
+ * @public
147
+ * @async
148
+ * @example
149
+ *
150
+ * const API = require('@docbrasil/api-systemmanager');
151
+ *
152
+ * // Params of the instance
153
+ * const params = {...}
154
+ * const api = new API(params);
155
+ * const params = { accessToken: 'eyJhbGciOiJIUzI1NiIsInR5cC...' };
156
+ * const { auth, user } = await api.login.facebook(params);
157
+ */
158
+ async facebook(params) {
159
+ const self = this;
160
+ try {
161
+ Joi.assert(params, Joi.object().required(), 'Params to login Facebook');
162
+ Joi.assert(params.accessToken, Joi.string().required(), 'Access token of the system manager');
163
+
164
+ if (_.hasIn(params, 'initialUserData')) {
165
+ Joi.assert(params.initialUserData, Joi.object().required(), 'Object with roles default if sigin');
166
+ Joi.assert(params.initialUserData.externalRoles, Joi.array().required(), 'Array with permission of user');
167
+ }
168
+
169
+ const apiCall = self._client.post('/login/facebook', params);
170
+ return self._returnData(await apiCall);
171
+ } catch (ex) {
172
+ throw ex;
173
+ }
174
+ }
175
+
176
+ /**
177
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
178
+ * @description Login with social login Google
179
+ * @param {object} params Params to login Google
180
+ * @param {string} params.accessToken Access token of the system manager
181
+ * @param {object} params.initialUserData Object with roles default if sigin
182
+ * @param {array} params.initialUserData.externalRoles Array with permission of user
183
+ * @return {promise&lt;object>} data
184
+ * @return {object} data.auth true or false if we have the user authenticaited correctly
185
+ * @return {object} data.user the logged user
186
+ * @public
187
+ * @async
188
+ * @example
189
+ *
190
+ * const API = require('@docbrasil/api-systemmanager');
191
+ *
192
+ * // Params of the instance
193
+ * const params = {...}
194
+ * const api = new API(params);
195
+ * const accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cC...';
196
+ * const { auth, user } = await api.login.google(accessToken);
197
+ */
198
+ async google(params) {
199
+ const self = this;
200
+ try {
201
+ Joi.assert(params, Joi.object().required(), 'Params to login Google');
202
+ Joi.assert(params.accessToken, Joi.string().required(), 'Access token of the system manager');
203
+
204
+ if (_.hasIn(params, 'initialUserData')) {
205
+ Joi.assert(params.initialUserData, Joi.object().required(), 'Object with roles default if sigin');
206
+ Joi.assert(params.initialUserData.externalRoles, Joi.array().required(), 'Array with permission of user');
207
+ }
208
+
209
+ const apiCall = self._client.post('/login/google', params);
210
+ return self._returnData(await apiCall);
211
+ } catch (ex) {
212
+ throw ex;
213
+ }
214
+ }
215
+
216
+ /**
217
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
218
+ * @description Login with apikey
219
+ * @param {string} apikey Access key
220
+ * @return {promise&lt;object>} data
221
+ * @return {object} data.auth true or false if we have the user authenticaited correctly
222
+ * @return {object} data.user the logged user
223
+ * @public
224
+ * @async
225
+ * @example
226
+ *
227
+ * const API = require('@docbrasil/api-systemmanager');
228
+ *
229
+ * // Params of the instance
230
+ * const params = {...}
231
+ * const api = new API(params);
232
+ * const apiKey = '043a0eb2-f5c3-4900-b781-7f229d00d092';
233
+ * const { auth, user } = await api.login.apiKey(apiKey);
234
+ */
235
+ async apiKey(apiKey) {
236
+ const self = this;
237
+ try {
238
+ Joi.assert(apiKey, Joi.string().required());
239
+
240
+ const apiCall = self._client.post('/login/api', {apiKey});
241
+ return self._returnData(await apiCall);
242
+ } catch (ex) {
243
+ throw ex;
244
+ }
245
+ }
246
+
247
+ /**
248
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
249
+ * @description Login with user and password
250
+ * @param {object} params Object with user and password
251
+ * @param {string} params.username Username or email of the user
252
+ * @param {string} params.password Password of the user
253
+ * @param {string} params.orgname The organame of the user
254
+ * @return {promise&lt;object>} data
255
+ * @return {object} data.auth true or false if we have the user authenticaited correctly
256
+ * @return {object} data.user the logged user
257
+ * @public
258
+ * @async
259
+ * @example
260
+ *
261
+ * const API = require('@docbrasil/api-systemmanager');
262
+ *
263
+ * // Params of the instance
264
+ * const params = {...}
265
+ * const api = new API(params);
266
+ * const params = {
267
+ * username: 'ana.silva@gmail.com',
268
+ * password: '123456'
269
+ * };
270
+ * const { auth, user } = await api.login.userPass(params);
271
+ */
272
+ async userPass(params) {
273
+ const self = this;
274
+ try {
275
+ Joi.assert(params.username, Joi.string().required());
276
+ Joi.assert(params.password, Joi.string().required());
277
+ const { orgname = '' } = params;
278
+ let url;
279
+ if(orgname !== '') {
280
+ url = `/login/${orgname}`;
281
+ } else {
282
+ url = `/login`;
283
+ }
284
+ const apiCall = self._client.post(url, params);
285
+ return self._returnData(await apiCall);
286
+ } catch (ex) {
287
+ throw ex;
288
+ }
289
+ }
290
+
291
+ /**
292
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
293
+ * @description Logout user system manager
294
+ * @param {string} session Session, token JWT
295
+ * @return {promise&lt;object>}} data
296
+ * @return {boolean} data.success true|false
297
+ * @public
298
+ * @async
299
+ * @example
300
+ *
301
+ * const API = require('@docbrasil/api-systemmanager');
302
+ *
303
+ * // Params of the instance
304
+ * const params = {...}
305
+ * const api = new API(params);
306
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
307
+ * const { success } = await api.login.logout(session);
308
+ */
309
+ async logout(session) {
310
+ const self = this;
311
+ try {
312
+ Joi.assert(session, Joi.string().required());
313
+
314
+ const apiCall = self._client.get('/logout', self._setHeader(session));
315
+ const { response = 'NOT_OK' } = self._returnData(await apiCall);
316
+ return response === 'OK';
317
+ } catch (ex) {
318
+ throw ex;
319
+ }
320
+ }
321
+
322
+ /**
323
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
324
+ * @description Recover the password
325
+ * @param {string} username The username or email
326
+ * @return {promise&lt;object>}} data
327
+ * @return {boolean} data.success true|false
328
+ * @public
329
+ * @async
330
+ * @example
331
+ *
332
+ * const API = require('@docbrasil/api-systemmanager');
333
+ *
334
+ * // Params of the instance
335
+ * const params = {...}
336
+ * const api = new API(params);
337
+ * const { success } = await api.login.recover('myusername');
338
+ */
339
+ async recover(username) {
340
+ const self = this;
341
+
342
+ try {
343
+ Joi.assert(username, Joi.string().required());
344
+
345
+ const url = `users/${username}/sendResetEmail`;
346
+ const apiCall = self._client.get(url);
347
+ return self._returnData(await apiCall);
348
+ } catch (ex) {
349
+ throw ex;
350
+ }
351
+ }
352
+ }
353
+
354
+ export default Login;
355
+ </code></pre>
356
+ </article>
357
+ </section>
358
+
359
+
360
+
361
+
362
+ </div>
363
+
364
+ <footer class="footer">
365
+ <div class="content has-text-centered">
366
+ <p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
367
+ <p class="sidebar-created-by">
368
+ <a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
369
+ <a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
370
+ </p>
371
+ </div>
372
+ </footer>
373
+
374
+ </div>
375
+ <div id="side-nav" class="side-nav">
376
+ </div>
377
+ </div>
378
+ <script src="scripts/app.min.js"></script>
379
+ <script>PR.prettyPrint();</script>
380
+ <script src="scripts/linenumber.js"> </script>
381
+
382
+
383
+ </body>
384
+ </html>
@@ -0,0 +1 @@
1
+ "use strict";$().ready(function(){});var sidebarIsVisible=!1,toggleSidebar=function(e){var a=!(0<arguments.length&&void 0!==e)||e;$("#sidebarNav").toggleClass("sticky",a),$("#stickyNavbarOverlay").toggleClass("active",a),$("#hamburger").toggleClass("is-active"),sidebarIsVisible=a};$().ready(function(){$("#hamburger").click(function(){toggleSidebar(!sidebarIsVisible)}),$("#stickyNavbarOverlay").click(function(){sidebarIsVisible&&toggleSidebar(!1)})});var OFFSET=150;$().ready(function(){var o=$("#side-nav"),c=[];if($(".vertical-section").length||o.hide(),$(".vertical-section").each(function(e,a){var i=$(a),t=i.find("> h1").text();if(t){o.append($("<h3/>").text(t));var s=$("<ul></ul>");i.find(".members h4.name").each(function(e,a){var i=$(a),t=i.find(".code-name").clone().children().remove().end().text(),n=i.find("a").attr("href"),r=$('<a href="'.concat(n,'" />')).text(t);s.append($("<li></li>").append(r)),c.push({link:r,offset:i.offset().top})}),o.append(s)}else i.find(".members h4.name").each(function(e,a){var i=$(a),t=i.find(".code-name").clone().children().remove().end().text(),n=i.find("a").attr("href"),r=$('<a href="'.concat(n,'" />')).text(t);o.append(r),c.push({link:r,offset:i.offset().top})})}),!$.trim(o.text()))return o.hide();function e(){for(var e=n.scrollTop(),a=!1,i=c.length-1;0<=i;i--){var t=c[i];t.link.removeClass("is-active"),e+OFFSET>=t.offset?a?t.link.addClass("is-past"):(t.link.addClass("is-active"),a=!0):t.link.removeClass("is-past")}}var n=$("#main-content-wrapper");n.on("scroll",e),e(),c.forEach(function(e){e.link.click(function(){n.animate({scrollTop:e.offset-OFFSET+1},500)})})}),$().ready(function(){$("#sidebarNav a").each(function(e,a){var i=$(a).attr("href");window.location.pathname.match("/"+i)&&($(a).addClass("active"),$("#sidebarNav").scrollTop($(a).offset().top-150))})});
@@ -0,0 +1,26 @@
1
+ /*global document */
2
+
3
+ (function() {
4
+ var source = document.getElementsByClassName('prettyprint source linenums');
5
+ var i = 0;
6
+ var lineNumber = 0;
7
+ var lineId;
8
+ var lines;
9
+ var totalLines;
10
+ var anchorHash;
11
+
12
+ if (source && source[0]) {
13
+ anchorHash = document.location.hash.substring(1);
14
+ lines = source[0].getElementsByTagName('li');
15
+ totalLines = lines.length;
16
+
17
+ for (; i < totalLines; i++) {
18
+ lineNumber++;
19
+ lineId = 'line' + lineNumber;
20
+ lines[i].id = lineId;
21
+ if (lineId === anchorHash) {
22
+ lines[i].className += ' selected';
23
+ }
24
+ }
25
+ }
26
+ })();
@@ -0,0 +1,39 @@
1
+ (function() {
2
+ const input = document.querySelector('#search')
3
+ const targets = [ ...document.querySelectorAll('#sidebarNav li')]
4
+ input.addEventListener('keyup', () => {
5
+ // loop over each targets and hide the not corresponding ones
6
+ targets.forEach(target => {
7
+ if (!target.innerText.toLowerCase().includes(input.value.toLowerCase())) {
8
+ target.style.display = 'none'
9
+
10
+ /**
11
+ * Detects an empty list
12
+ * Remove the list and the list's title if the list is not displayed
13
+ */
14
+ const list = [...target.parentNode.childNodes].filter( elem => elem.style.display !== 'none')
15
+
16
+ if (!list.length) {
17
+ target.parentNode.style.display = 'none'
18
+ target.parentNode.previousSibling.style.display = 'none'
19
+ }
20
+
21
+ /**
22
+ * Detects empty category
23
+ * Remove the entire category if no item is displayed
24
+ */
25
+ const category = [...target.parentNode.parentNode.childNodes]
26
+ .filter( elem => elem.tagName !== 'H2' && elem.style.display !== 'none')
27
+
28
+ if (!category.length) {
29
+ target.parentNode.parentNode.style.display = 'none'
30
+ }
31
+ } else {
32
+ target.parentNode.style.display = 'block'
33
+ target.parentNode.previousSibling.style.display = 'block'
34
+ target.parentNode.parentNode.style.display = 'block'
35
+ target.style.display = 'block'
36
+ }
37
+ })
38
+ })
39
+ })()
@@ -0,0 +1,202 @@
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> session.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>session.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 Joi from 'joi';
90
+ import Boom from '@hapi/boom';
91
+
92
+ /**
93
+ * @class Session manager of the API
94
+ */
95
+ class Session {
96
+
97
+ constructor(options) {
98
+ Joi.assert(options, Joi.object().required());
99
+ Joi.assert(options.parent, Joi.object().required());
100
+
101
+ const self = this;
102
+ self._session;
103
+ self._userData;
104
+
105
+ self.parent = options.parent;
106
+ self._client = self.parent.dispatch.getClient();
107
+ }
108
+
109
+ /**
110
+ * @author Augusto Pissarra &lt;abernardo.br@gmail.com>
111
+ * @description Get the return data and check for errors
112
+ * @param {object} retData Response HTTP
113
+ * @return {*}
114
+ * @private
115
+ */
116
+ _returnData(retData, def = {}) {
117
+ if (retData.status !== 200) {
118
+ return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
119
+ } else {
120
+ return _.get(retData, 'data', def);
121
+ }
122
+ }
123
+
124
+ /**
125
+ * @author CloudBrasil &lt;abernardo.br@gmail.com>
126
+ * @description Set header with new session
127
+ * @param {string} session Session, token JWT
128
+ * @return {object} header with new session
129
+ * @private
130
+ */
131
+ _setHeader(session) {
132
+ return {
133
+ headers: {
134
+ authorization: session,
135
+ }
136
+ };
137
+ }
138
+
139
+ /**
140
+ * @description Show information for session, thus validating the session (Valid token JWT)
141
+ * @param {string} sessionId The user session (JWT Token)
142
+ * @param {string} suSessionId=sessionId Given a JWT Token of a SU (SuperAdmin), allow to check session for another user.
143
+ * @return {Promise}
144
+ * @public
145
+ * @async
146
+ * @example
147
+ *
148
+ * const API = require('@docbrasil/api-systemmanager');
149
+ * const api = new API();
150
+ * const sessionId = 'eyJhbFVBBiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
151
+ * const suSessionId = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
152
+ * await api.session.information(sessionId, suSessionId);
153
+ *
154
+ */
155
+ async information(sessionId, suSessionId = null) {
156
+ const self = this;
157
+
158
+ try {
159
+ Joi.assert(sessionId, Joi.string().required());
160
+
161
+ // if not provided, just use the same sessionId
162
+ suSessionId = suSessionId || sessionId;
163
+
164
+ const apiCall = self._client.get(`session?token=${sessionId}`, self._setHeader(suSessionId));
165
+ return self._returnData(await apiCall);
166
+ } catch (ex) {
167
+ throw ex;
168
+ }
169
+ }
170
+ }
171
+
172
+ export default Session;
173
+ </code></pre>
174
+ </article>
175
+ </section>
176
+
177
+
178
+
179
+
180
+ </div>
181
+
182
+ <footer class="footer">
183
+ <div class="content has-text-centered">
184
+ <p>Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a></p>
185
+ <p class="sidebar-created-by">
186
+ <a href="https://github.com/SoftwareBrothers/better-docs" target="_blank">BetterDocs theme</a> provided with <i class="fas fa-heart"></i> by
187
+ <a href="http://softwarebrothers.co" target="_blank">SoftwareBrothers - JavaScript Development Agency</a>
188
+ </p>
189
+ </div>
190
+ </footer>
191
+
192
+ </div>
193
+ <div id="side-nav" class="side-nav">
194
+ </div>
195
+ </div>
196
+ <script src="scripts/app.min.js"></script>
197
+ <script>PR.prettyPrint();</script>
198
+ <script src="scripts/linenumber.js"> </script>
199
+
200
+
201
+ </body>
202
+ </html>