@docbrasil/api-systemmanager 1.0.53 → 1.0.56

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.
@@ -285,49 +285,6 @@ class AdminDocuments {
285
285
  return self._returnData(await apiCall);
286
286
  }
287
287
 
288
- /**
289
- *
290
- * @author CloudBrasil <abernardo.br@gmail.com>
291
- * @description Get the content of a document
292
- * @param {object} params Params to request signed url
293
- * @param {string} params.docId The unique id of the document
294
- * @param {string} params.page The page, from 0, or 'all' if all pages (the full content)
295
- * @param {string} apiKey Api Key as permission to use this functionality
296
- * @return {Promise<object>} data the document content
297
- * @return {string} data._id the _id of the document
298
- * @return {string} data.content all the pages or if asked by page, just one page, the one requested
299
- * @return {string} data.content.TextOverlay the overlay text if requested
300
- * @return {string} data.content.ParsedText the page text content
301
- * @return {number} data.total the total number of pages
302
- * @public
303
- * @async
304
- * @example
305
- *
306
- * const API = require('@docbrasil/api-systemmanager');
307
- * const api = new API();
308
- * const params - {
309
- * page: '0',
310
- * docId: '5dadd01dc4af3941d42f8c5c'
311
- * };
312
- * const apiKey: '...';
313
- * await api.admin.document.getContent(params, apiKey);
314
- */
315
- async getContent(params = {}, apiKey) {
316
-
317
- Joi.assert(params, Joi.object().required());
318
- Joi.assert(params.content, Joi.string().required());
319
- Joi.assert(params.docId, Joi.string().required());
320
- Joi.assert(params.page, Joi.string().required());
321
- Joi.assert(apiKey, Joi.string().required());
322
-
323
- const self = this;
324
- const { page, docId } = params;
325
- const url = `/api/documents/${docId}/content/${page}?apiKey=${apiKey}`;
326
- const apiCall = self._client
327
- .get(url);
328
- return self._returnData(await apiCall);
329
- }
330
-
331
288
  }
332
289
 
333
290
  export default AdminDocuments;
@@ -1,4 +1,3 @@
1
- import _ from 'lodash';
2
1
  import Joi from 'joi';
3
2
 
4
3
  import AdminDocument from './document';
@@ -12,6 +11,7 @@ import AdminUser from './user';
12
11
  import AdminProcesses from './processes';
13
12
  import AdminMessage from './message';
14
13
  import AdminDocTypes from './doctypes';
14
+ import AdminOrganizations from './organization';
15
15
 
16
16
  /**
17
17
  * @class API request, admin permission level
@@ -28,17 +28,18 @@ class Admin {
28
28
  Joi.assert(options.parent, Joi.object().required());
29
29
 
30
30
  const self = this;
31
+ self.doctypes = new AdminDocTypes(options);
31
32
  self.document = new AdminDocument(options);
32
33
  self.form = new AdminForm(options);
33
- self.notification = new AdminNotification(options);
34
34
  self.list = new AdminList(options);
35
+ self.message = new AdminMessage(options);
36
+ self.organizations = new AdminOrganizations(options);
37
+ self.notification = new AdminNotification(options);
35
38
  self.plugin = new AdminPlugin(options);
36
39
  self.policy = new AdminPolicy(options);
40
+ self.processes = new AdminProcesses(options);
37
41
  self.task = new AdminTask(options);
38
42
  self.user = new AdminUser(options);
39
- self.processes = new AdminProcesses(options);
40
- self.message = new AdminMessage(options);
41
- self.doctypes = new AdminDocTypes(options);
42
43
  }
43
44
  }
44
45
 
@@ -0,0 +1,124 @@
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Class for organizations, permission user
7
+ * @class
8
+ */
9
+ class Organization {
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 Update avatar of organization by session of user not allow session user SU
53
+ * @param {object} params Params to update avatar
54
+ * @param {string} params.orgId - Organization id
55
+ * @param {string} params.avatar - Image in base64 to update
56
+ * @param {string} params.type - MimeType (image/png)
57
+ * @param {string} session - Is token JWT of user SU
58
+ * @return {Promise}
59
+ * @public
60
+ * @async
61
+ * @example
62
+ *
63
+ * const API = require('@docbrasil/api-systemmanager');
64
+ * const api = new API();
65
+ * const params = {
66
+ * orgId: '5dadd01dc4af3941d42f8c5c',
67
+ * avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
68
+ * type: 'image/png',
69
+ * };
70
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
71
+ * await api.admin.organizations.upsertAvatar(params, session);
72
+ */
73
+ async upsertAvatar(params = {}, session) {
74
+ const self = this;
75
+
76
+ try {
77
+ Joi.assert(params, Joi.object().required());
78
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id');
79
+ Joi.assert(params.avatar, Joi.string().required(), 'Image in base64 to update');
80
+ Joi.assert(params.type, Joi.string().required(), 'MimeType (image/png)');
81
+ Joi.assert(session, Joi.string().required(), 'Is token JWT of user SU');
82
+
83
+ const {orgId, avatar, type} = params;
84
+ const payload = {avatar, type};
85
+
86
+ const apiCall = self._client.put(`/admin/organizations/${orgId}/logo`, payload, self._setHeader(session));
87
+ return self._returnData(await apiCall);
88
+ } catch (ex) {
89
+ throw ex;
90
+ }
91
+ }
92
+
93
+ /**
94
+ * @author CloudBrasil <abernardo.br@gmail.com>
95
+ * @description Remove avatar of user by session of user not allow session user SU
96
+ * @param {string} params.orgId - Organization id
97
+ * @param {string} session - Is token JWT of user SU
98
+ * @return {Promise}
99
+ * @public
100
+ * @async
101
+ * @example
102
+ *
103
+ * const API = require('@docbrasil/api-systemmanager');
104
+ * const api = new API();
105
+ * const orgId = '5dadd01dc4af3941d42f8c5c';
106
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
107
+ * await api.admin.organizations.removeAvatar(orgId, session);
108
+ */
109
+ async removeAvatar(orgId, session) {
110
+ const self = this;
111
+
112
+ try {
113
+ Joi.assert(orgId, Joi.string().required(), 'Organization id');
114
+ Joi.assert(session, Joi.string().required(), 'Is token JWT of user SU');
115
+
116
+ const apiCall = self._client.delete(`/admin/organizations/${orgId}/logo`, self._setHeader(session));
117
+ return self._returnData(await apiCall);
118
+ } catch (ex) {
119
+ throw ex;
120
+ }
121
+ }
122
+ }
123
+
124
+ export default Organization;
package/dist/bundle.cjs CHANGED
@@ -1065,7 +1065,7 @@ class Documents {
1065
1065
  * Class for organizations, permission user
1066
1066
  * @class
1067
1067
  */
1068
- class Organization {
1068
+ class Organization$1 {
1069
1069
 
1070
1070
  constructor(options) {
1071
1071
  Joi__default["default"].assert(options, Joi__default["default"].object().required());
@@ -8733,7 +8733,7 @@ class Users {
8733
8733
 
8734
8734
  const self = this;
8735
8735
  self.document = new Documents(options);
8736
- self.organization = new Organization(options);
8736
+ self.organization = new Organization$1(options);
8737
8737
  self.process = new Process(options);
8738
8738
  self.task = new Task(options);
8739
8739
  self.user = self.profile = new User(options);
@@ -9024,49 +9024,6 @@ class AdminDocuments {
9024
9024
  return self._returnData(await apiCall);
9025
9025
  }
9026
9026
 
9027
- /**
9028
- *
9029
- * @author CloudBrasil <abernardo.br@gmail.com>
9030
- * @description Get the content of a document
9031
- * @param {object} params Params to request signed url
9032
- * @param {string} params.docId The unique id of the document
9033
- * @param {string} params.page The page, from 0, or 'all' if all pages (the full content)
9034
- * @param {string} apiKey Api Key as permission to use this functionality
9035
- * @return {Promise<object>} data the document content
9036
- * @return {string} data._id the _id of the document
9037
- * @return {string} data.content all the pages or if asked by page, just one page, the one requested
9038
- * @return {string} data.content.TextOverlay the overlay text if requested
9039
- * @return {string} data.content.ParsedText the page text content
9040
- * @return {number} data.total the total number of pages
9041
- * @public
9042
- * @async
9043
- * @example
9044
- *
9045
- * const API = require('@docbrasil/api-systemmanager');
9046
- * const api = new API();
9047
- * const params - {
9048
- * page: '0',
9049
- * docId: '5dadd01dc4af3941d42f8c5c'
9050
- * };
9051
- * const apiKey: '...';
9052
- * await api.admin.document.getContent(params, apiKey);
9053
- */
9054
- async getContent(params = {}, apiKey) {
9055
-
9056
- Joi__default["default"].assert(params, Joi__default["default"].object().required());
9057
- Joi__default["default"].assert(params.content, Joi__default["default"].string().required());
9058
- Joi__default["default"].assert(params.docId, Joi__default["default"].string().required());
9059
- Joi__default["default"].assert(params.page, Joi__default["default"].string().required());
9060
- Joi__default["default"].assert(apiKey, Joi__default["default"].string().required());
9061
-
9062
- const self = this;
9063
- const { page, docId } = params;
9064
- const url = `/api/documents/${docId}/content/${page}?apiKey=${apiKey}`;
9065
- const apiCall = self._client
9066
- .get(url);
9067
- return self._returnData(await apiCall);
9068
- }
9069
-
9070
9027
  }
9071
9028
 
9072
9029
  /**
@@ -10643,6 +10600,125 @@ class AdminDocTypes {
10643
10600
  }
10644
10601
  }
10645
10602
 
10603
+ /**
10604
+ * Class for organizations, permission user
10605
+ * @class
10606
+ */
10607
+ class Organization {
10608
+
10609
+ constructor(options) {
10610
+ Joi__default["default"].assert(options, Joi__default["default"].object().required());
10611
+ Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
10612
+
10613
+ const self = this;
10614
+ self.parent = options.parent;
10615
+ self._client = self.parent.dispatch.getClient();
10616
+ }
10617
+
10618
+ /**
10619
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
10620
+ * @description Get the return data and check for errors
10621
+ * @param {object} retData Response HTTP
10622
+ * @return {*}
10623
+ * @private
10624
+ */
10625
+ _returnData(retData, def = {}) {
10626
+ if (retData.status !== 200) {
10627
+ throw Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
10628
+ } else {
10629
+ return ___default["default"].get(retData, 'data', def);
10630
+ }
10631
+ }
10632
+
10633
+ /**
10634
+ * @author CloudBrasil <abernardo.br@gmail.com>
10635
+ * @description Set header with new session
10636
+ * @param {string} session Session, token JWT
10637
+ * @return {object} header with new session
10638
+ * @private
10639
+ */
10640
+ _setHeader(session) {
10641
+ return {
10642
+ headers: {
10643
+ authorization: session,
10644
+ }
10645
+ };
10646
+ }
10647
+
10648
+ /**
10649
+ * @author CloudBrasil <abernardo.br@gmail.com>
10650
+ * @description Update avatar of organization by session of user not allow session user SU
10651
+ * @param {object} params Params to update avatar
10652
+ * @param {string} params.orgId - Organization id
10653
+ * @param {string} params.avatar - Image in base64 to update
10654
+ * @param {string} params.type - MimeType (image/png)
10655
+ * @param {string} session - Is token JWT of user SU
10656
+ * @return {Promise}
10657
+ * @public
10658
+ * @async
10659
+ * @example
10660
+ *
10661
+ * const API = require('@docbrasil/api-systemmanager');
10662
+ * const api = new API();
10663
+ * const params = {
10664
+ * orgId: '5dadd01dc4af3941d42f8c5c',
10665
+ * avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
10666
+ * type: 'image/png',
10667
+ * };
10668
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
10669
+ * await api.admin.organizations.upsertAvatar(params, session);
10670
+ */
10671
+ async upsertAvatar(params = {}, session) {
10672
+ const self = this;
10673
+
10674
+ try {
10675
+ Joi__default["default"].assert(params, Joi__default["default"].object().required());
10676
+ Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required(), 'Organization id');
10677
+ Joi__default["default"].assert(params.avatar, Joi__default["default"].string().required(), 'Image in base64 to update');
10678
+ Joi__default["default"].assert(params.type, Joi__default["default"].string().required(), 'MimeType (image/png)');
10679
+ Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Is token JWT of user SU');
10680
+
10681
+ const {orgId, avatar, type} = params;
10682
+ const payload = {avatar, type};
10683
+
10684
+ const apiCall = self._client.put(`/admin/organizations/${orgId}/logo`, payload, self._setHeader(session));
10685
+ return self._returnData(await apiCall);
10686
+ } catch (ex) {
10687
+ throw ex;
10688
+ }
10689
+ }
10690
+
10691
+ /**
10692
+ * @author CloudBrasil <abernardo.br@gmail.com>
10693
+ * @description Remove avatar of user by session of user not allow session user SU
10694
+ * @param {string} params.orgId - Organization id
10695
+ * @param {string} session - Is token JWT of user SU
10696
+ * @return {Promise}
10697
+ * @public
10698
+ * @async
10699
+ * @example
10700
+ *
10701
+ * const API = require('@docbrasil/api-systemmanager');
10702
+ * const api = new API();
10703
+ * const orgId = '5dadd01dc4af3941d42f8c5c';
10704
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
10705
+ * await api.admin.organizations.removeAvatar(orgId, session);
10706
+ */
10707
+ async removeAvatar(orgId, session) {
10708
+ const self = this;
10709
+
10710
+ try {
10711
+ Joi__default["default"].assert(orgId, Joi__default["default"].string().required(), 'Organization id');
10712
+ Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Is token JWT of user SU');
10713
+
10714
+ const apiCall = self._client.delete(`/admin/organizations/${orgId}/logo`, self._setHeader(session));
10715
+ return self._returnData(await apiCall);
10716
+ } catch (ex) {
10717
+ throw ex;
10718
+ }
10719
+ }
10720
+ }
10721
+
10646
10722
  /**
10647
10723
  * @class API request, admin permission level
10648
10724
  */
@@ -10658,17 +10734,18 @@ class Admin {
10658
10734
  Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
10659
10735
 
10660
10736
  const self = this;
10737
+ self.doctypes = new AdminDocTypes(options);
10661
10738
  self.document = new AdminDocuments(options);
10662
10739
  self.form = new AdminForm(options);
10663
- self.notification = new AdminNotification(options);
10664
10740
  self.list = new AdminLists(options);
10741
+ self.message = new AdminMessage(options);
10742
+ self.organizations = new Organization(options);
10743
+ self.notification = new AdminNotification(options);
10665
10744
  self.plugin = new AdminPlugin(options);
10666
10745
  self.policy = new AdminPolicy(options);
10746
+ self.processes = new AdminProcesses(options);
10667
10747
  self.task = new AdminTask(options);
10668
10748
  self.user = new AdminUser(options);
10669
- self.processes = new AdminProcesses(options);
10670
- self.message = new AdminMessage(options);
10671
- self.doctypes = new AdminDocTypes(options);
10672
10749
  }
10673
10750
  }
10674
10751