@docbrasil/api-systemmanager 1.0.117 → 1.0.118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api/user/index.js CHANGED
@@ -8,6 +8,7 @@ import Task from './task.js';
8
8
  import User from './user.js';
9
9
  import Register from './register.js';
10
10
  import Notification from './notification.js';
11
+ import Updates from './updates.js';
11
12
  import Datasource from './datasource.js';
12
13
 
13
14
  /**
@@ -33,6 +34,7 @@ class Users {
33
34
  self.user = self.profile = new User(options);
34
35
  self.register = new Register(options);
35
36
  self.notification = new Notification(options);
37
+ self.updates = new Updates(options);
36
38
  }
37
39
  }
38
40
 
@@ -0,0 +1,78 @@
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Class for user registration in a user
7
+ * @class
8
+ */
9
+ class Updates {
10
+
11
+ constructor(options) {
12
+ Joi.assert(options, Joi.object().required());
13
+ Joi.assert(options.parent, Joi.object().required());
14
+
15
+ const self = this;
16
+ self.parent = options.parent;
17
+ self._client = self.parent.dispatch.getClient();
18
+ }
19
+
20
+ /**
21
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
22
+ * @description Get the return data and check for errors
23
+ * @param {object} retData Response HTTP
24
+ * @return {*}
25
+ * @private
26
+ */
27
+ _returnData(retData, def = {}) {
28
+ if (retData.status !== 200) {
29
+ return Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
30
+ } else {
31
+ return _.get(retData, 'data', def);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @author CloudBrasil <abernardo.br@gmail.com>
37
+ * @description Set header with new session
38
+ * @param {string} session Session, token JWT
39
+ * @return {object} header with new session
40
+ * @private
41
+ */
42
+ _setHeader(session) {
43
+ return {
44
+ headers: {
45
+ authorization: session,
46
+ }
47
+ };
48
+ }
49
+
50
+ /**
51
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
52
+ * @description get updates
53
+ * @param {string} session JWT token
54
+ * @public
55
+ * @async
56
+ * @example
57
+ *
58
+ * const API = require('@docbrasil/api-systemmanager');
59
+ * const api = new API();
60
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
61
+ * await api.user.updates.get(session);
62
+ */
63
+ async get(session) {
64
+ const self = this;
65
+
66
+ try {
67
+ Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
68
+
69
+ const apiCall = self._client.get('/updates', self._setHeader(session));
70
+ return self._returnData(await apiCall);
71
+ } catch (ex) {
72
+ throw ex;
73
+ }
74
+ }
75
+
76
+ }
77
+
78
+ export default Notification;
package/dist/bundle.cjs CHANGED
@@ -9488,7 +9488,7 @@ class Register {
9488
9488
  * Class for user registration in a user
9489
9489
  * @class
9490
9490
  */
9491
- class Notification {
9491
+ class Notification$1 {
9492
9492
 
9493
9493
  constructor(options) {
9494
9494
  Joi__default["default"].assert(options, Joi__default["default"].object().required());
@@ -9704,6 +9704,8 @@ class Notification {
9704
9704
  }
9705
9705
  }
9706
9706
 
9707
+ var Updates = Notification;
9708
+
9707
9709
  /**
9708
9710
  * Class for user datasource access, to be used with when creating new documents
9709
9711
  * @class
@@ -9865,7 +9867,8 @@ class Users {
9865
9867
  self.task = new Task(options);
9866
9868
  self.user = self.profile = new User(options);
9867
9869
  self.register = new Register(options);
9868
- self.notification = new Notification(options);
9870
+ self.notification = new Notification$1(options);
9871
+ self.updates = new Updates(options);
9869
9872
  }
9870
9873
  }
9871
9874