@docbrasil/api-systemmanager 1.0.96 → 1.0.98

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.
@@ -0,0 +1,86 @@
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Class for documents, permission user
7
+ * @class
8
+ */
9
+ class External {
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
+ throw 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 CloudBrasil <abernardo.br@gmail.com>
52
+ * @description Create new document
53
+ * @param {object} params Object for add new document
54
+ * @param {string} params.id Organization form id
55
+ * @return {Promise<object>}
56
+ * @public
57
+ * @async
58
+ * @example
59
+ *
60
+ * const API = require('@docbrasil/api-systemmanager');
61
+ * const api = new API();
62
+ * const params = {
63
+ * id: 'cloundbrasil'
64
+ * };
65
+ * const retForm = await api.external.context(params);
66
+ */
67
+ async context(params) {
68
+ const self = this;
69
+
70
+ try {
71
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
72
+ Joi.assert(params.id, Joi.string().required().error(new Error('organization form id is required')));
73
+
74
+ const { id } = params;
75
+ const apiCall = self._client
76
+ .get(`/component/external/forms/${id}`);
77
+
78
+ return self._returnData(await apiCall);
79
+ } catch (ex) {
80
+ throw ex;
81
+ }
82
+ }
83
+
84
+ }
85
+
86
+ export default Documents;
package/dist/bundle.cjs CHANGED
@@ -559,7 +559,7 @@ class Users$1 {
559
559
  * Class for documents, permission user
560
560
  * @class
561
561
  */
562
- class Documents {
562
+ class Documents$1 {
563
563
 
564
564
  constructor(options) {
565
565
  Joi__default["default"].assert(options, Joi__default["default"].object().required());
@@ -9481,7 +9481,7 @@ class Users {
9481
9481
  Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
9482
9482
 
9483
9483
  const self = this;
9484
- self.document = new Documents(options);
9484
+ self.document = new Documents$1(options);
9485
9485
  self.datasource = new Datasource(options);
9486
9486
  self.organization = new Organization$1(options);
9487
9487
  self.process = new Process(options);
@@ -11578,6 +11578,8 @@ class Admin {
11578
11578
  }
11579
11579
  }
11580
11580
 
11581
+ var External = Documents;
11582
+
11581
11583
  /**
11582
11584
  * Class API
11583
11585
  */
@@ -11648,6 +11650,7 @@ class API {
11648
11650
  self.general = new Users$1({parent: self});
11649
11651
  self.user = new Users({parent: self});
11650
11652
  self.admin = new Admin({parent: self});
11653
+ self.external = new External({parent: self});
11651
11654
  }
11652
11655
  }
11653
11656