@docbrasil/api-systemmanager 1.0.54 → 1.0.57
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/admin/index.js +6 -5
- package/api/admin/organization.js +124 -0
- package/api/user/process.js +18 -1
- package/dist/bundle.cjs +144 -8
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +241 -0
- package/package.json +1 -1
package/api/admin/index.js
CHANGED
|
@@ -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/api/user/process.js
CHANGED
|
@@ -47,6 +47,23 @@ class Process {
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
52
|
+
* @description Set header for a bigger payload
|
|
53
|
+
* @param {string} session Session, token JWT
|
|
54
|
+
* @return {object} header with new session
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
_setMaxContentHeader(session) {
|
|
58
|
+
return {
|
|
59
|
+
headers: {
|
|
60
|
+
authorization: session,
|
|
61
|
+
maxContentLength: Infinity,
|
|
62
|
+
maxBodyLength: Infinity
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
50
67
|
/**
|
|
51
68
|
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
52
69
|
* @description Start process
|
|
@@ -81,7 +98,7 @@ class Process {
|
|
|
81
98
|
Joi.assert(session, Joi.string().required());
|
|
82
99
|
|
|
83
100
|
const {processId, orgId, payload = {}} = params;
|
|
84
|
-
const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}`, payload, self.
|
|
101
|
+
const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}`, payload, self._setMaxContentHeader(session));
|
|
85
102
|
return self._returnData(await apiCall);
|
|
86
103
|
} catch (ex) {
|
|
87
104
|
throw ex;
|
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());
|
|
@@ -1330,6 +1330,23 @@ class Process {
|
|
|
1330
1330
|
};
|
|
1331
1331
|
}
|
|
1332
1332
|
|
|
1333
|
+
/**
|
|
1334
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
1335
|
+
* @description Set header for a bigger payload
|
|
1336
|
+
* @param {string} session Session, token JWT
|
|
1337
|
+
* @return {object} header with new session
|
|
1338
|
+
* @private
|
|
1339
|
+
*/
|
|
1340
|
+
_setMaxContentHeader(session) {
|
|
1341
|
+
return {
|
|
1342
|
+
headers: {
|
|
1343
|
+
authorization: session,
|
|
1344
|
+
maxContentLength: Infinity,
|
|
1345
|
+
maxBodyLength: Infinity
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1333
1350
|
/**
|
|
1334
1351
|
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
1335
1352
|
* @description Start process
|
|
@@ -1364,7 +1381,7 @@ class Process {
|
|
|
1364
1381
|
Joi__default["default"].assert(session, Joi__default["default"].string().required());
|
|
1365
1382
|
|
|
1366
1383
|
const {processId, orgId, payload = {}} = params;
|
|
1367
|
-
const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}`, payload, self.
|
|
1384
|
+
const apiCall = self._client.put(`/organizations/${orgId}/process/${processId}`, payload, self._setMaxContentHeader(session));
|
|
1368
1385
|
return self._returnData(await apiCall);
|
|
1369
1386
|
} catch (ex) {
|
|
1370
1387
|
throw ex;
|
|
@@ -8733,7 +8750,7 @@ class Users {
|
|
|
8733
8750
|
|
|
8734
8751
|
const self = this;
|
|
8735
8752
|
self.document = new Documents(options);
|
|
8736
|
-
self.organization = new Organization(options);
|
|
8753
|
+
self.organization = new Organization$1(options);
|
|
8737
8754
|
self.process = new Process(options);
|
|
8738
8755
|
self.task = new Task(options);
|
|
8739
8756
|
self.user = self.profile = new User(options);
|
|
@@ -9054,7 +9071,6 @@ class AdminDocuments {
|
|
|
9054
9071
|
async getContent(params = {}, apiKey) {
|
|
9055
9072
|
|
|
9056
9073
|
Joi__default["default"].assert(params, Joi__default["default"].object().required());
|
|
9057
|
-
Joi__default["default"].assert(params.content, Joi__default["default"].string().required());
|
|
9058
9074
|
Joi__default["default"].assert(params.docId, Joi__default["default"].string().required());
|
|
9059
9075
|
Joi__default["default"].assert(params.page, Joi__default["default"].string().required());
|
|
9060
9076
|
Joi__default["default"].assert(apiKey, Joi__default["default"].string().required());
|
|
@@ -10643,6 +10659,125 @@ class AdminDocTypes {
|
|
|
10643
10659
|
}
|
|
10644
10660
|
}
|
|
10645
10661
|
|
|
10662
|
+
/**
|
|
10663
|
+
* Class for organizations, permission user
|
|
10664
|
+
* @class
|
|
10665
|
+
*/
|
|
10666
|
+
class Organization {
|
|
10667
|
+
|
|
10668
|
+
constructor(options) {
|
|
10669
|
+
Joi__default["default"].assert(options, Joi__default["default"].object().required());
|
|
10670
|
+
Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
|
|
10671
|
+
|
|
10672
|
+
const self = this;
|
|
10673
|
+
self.parent = options.parent;
|
|
10674
|
+
self._client = self.parent.dispatch.getClient();
|
|
10675
|
+
}
|
|
10676
|
+
|
|
10677
|
+
/**
|
|
10678
|
+
* @author Augusto Pissarra <abernardo.br@gmail.com>
|
|
10679
|
+
* @description Get the return data and check for errors
|
|
10680
|
+
* @param {object} retData Response HTTP
|
|
10681
|
+
* @return {*}
|
|
10682
|
+
* @private
|
|
10683
|
+
*/
|
|
10684
|
+
_returnData(retData, def = {}) {
|
|
10685
|
+
if (retData.status !== 200) {
|
|
10686
|
+
throw Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
|
|
10687
|
+
} else {
|
|
10688
|
+
return ___default["default"].get(retData, 'data', def);
|
|
10689
|
+
}
|
|
10690
|
+
}
|
|
10691
|
+
|
|
10692
|
+
/**
|
|
10693
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
10694
|
+
* @description Set header with new session
|
|
10695
|
+
* @param {string} session Session, token JWT
|
|
10696
|
+
* @return {object} header with new session
|
|
10697
|
+
* @private
|
|
10698
|
+
*/
|
|
10699
|
+
_setHeader(session) {
|
|
10700
|
+
return {
|
|
10701
|
+
headers: {
|
|
10702
|
+
authorization: session,
|
|
10703
|
+
}
|
|
10704
|
+
};
|
|
10705
|
+
}
|
|
10706
|
+
|
|
10707
|
+
/**
|
|
10708
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
10709
|
+
* @description Update avatar of organization by session of user not allow session user SU
|
|
10710
|
+
* @param {object} params Params to update avatar
|
|
10711
|
+
* @param {string} params.orgId - Organization id
|
|
10712
|
+
* @param {string} params.avatar - Image in base64 to update
|
|
10713
|
+
* @param {string} params.type - MimeType (image/png)
|
|
10714
|
+
* @param {string} session - Is token JWT of user SU
|
|
10715
|
+
* @return {Promise}
|
|
10716
|
+
* @public
|
|
10717
|
+
* @async
|
|
10718
|
+
* @example
|
|
10719
|
+
*
|
|
10720
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
10721
|
+
* const api = new API();
|
|
10722
|
+
* const params = {
|
|
10723
|
+
* orgId: '5dadd01dc4af3941d42f8c5c',
|
|
10724
|
+
* avatar: 'iVBORw0KGgoAAAANSUhEUgAAAasAAAHnCAYAAAAGi3J6AAA9BElEQVR...He3/kk/m7kl35S8AAAAASUVORK5CYII=',
|
|
10725
|
+
* type: 'image/png',
|
|
10726
|
+
* };
|
|
10727
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
10728
|
+
* await api.admin.organizations.upsertAvatar(params, session);
|
|
10729
|
+
*/
|
|
10730
|
+
async upsertAvatar(params = {}, session) {
|
|
10731
|
+
const self = this;
|
|
10732
|
+
|
|
10733
|
+
try {
|
|
10734
|
+
Joi__default["default"].assert(params, Joi__default["default"].object().required());
|
|
10735
|
+
Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required(), 'Organization id');
|
|
10736
|
+
Joi__default["default"].assert(params.avatar, Joi__default["default"].string().required(), 'Image in base64 to update');
|
|
10737
|
+
Joi__default["default"].assert(params.type, Joi__default["default"].string().required(), 'MimeType (image/png)');
|
|
10738
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Is token JWT of user SU');
|
|
10739
|
+
|
|
10740
|
+
const {orgId, avatar, type} = params;
|
|
10741
|
+
const payload = {avatar, type};
|
|
10742
|
+
|
|
10743
|
+
const apiCall = self._client.put(`/admin/organizations/${orgId}/logo`, payload, self._setHeader(session));
|
|
10744
|
+
return self._returnData(await apiCall);
|
|
10745
|
+
} catch (ex) {
|
|
10746
|
+
throw ex;
|
|
10747
|
+
}
|
|
10748
|
+
}
|
|
10749
|
+
|
|
10750
|
+
/**
|
|
10751
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
10752
|
+
* @description Remove avatar of user by session of user not allow session user SU
|
|
10753
|
+
* @param {string} params.orgId - Organization id
|
|
10754
|
+
* @param {string} session - Is token JWT of user SU
|
|
10755
|
+
* @return {Promise}
|
|
10756
|
+
* @public
|
|
10757
|
+
* @async
|
|
10758
|
+
* @example
|
|
10759
|
+
*
|
|
10760
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
10761
|
+
* const api = new API();
|
|
10762
|
+
* const orgId = '5dadd01dc4af3941d42f8c5c';
|
|
10763
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
10764
|
+
* await api.admin.organizations.removeAvatar(orgId, session);
|
|
10765
|
+
*/
|
|
10766
|
+
async removeAvatar(orgId, session) {
|
|
10767
|
+
const self = this;
|
|
10768
|
+
|
|
10769
|
+
try {
|
|
10770
|
+
Joi__default["default"].assert(orgId, Joi__default["default"].string().required(), 'Organization id');
|
|
10771
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required(), 'Is token JWT of user SU');
|
|
10772
|
+
|
|
10773
|
+
const apiCall = self._client.delete(`/admin/organizations/${orgId}/logo`, self._setHeader(session));
|
|
10774
|
+
return self._returnData(await apiCall);
|
|
10775
|
+
} catch (ex) {
|
|
10776
|
+
throw ex;
|
|
10777
|
+
}
|
|
10778
|
+
}
|
|
10779
|
+
}
|
|
10780
|
+
|
|
10646
10781
|
/**
|
|
10647
10782
|
* @class API request, admin permission level
|
|
10648
10783
|
*/
|
|
@@ -10658,17 +10793,18 @@ class Admin {
|
|
|
10658
10793
|
Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
|
|
10659
10794
|
|
|
10660
10795
|
const self = this;
|
|
10796
|
+
self.doctypes = new AdminDocTypes(options);
|
|
10661
10797
|
self.document = new AdminDocuments(options);
|
|
10662
10798
|
self.form = new AdminForm(options);
|
|
10663
|
-
self.notification = new AdminNotification(options);
|
|
10664
10799
|
self.list = new AdminLists(options);
|
|
10800
|
+
self.message = new AdminMessage(options);
|
|
10801
|
+
self.organizations = new Organization(options);
|
|
10802
|
+
self.notification = new AdminNotification(options);
|
|
10665
10803
|
self.plugin = new AdminPlugin(options);
|
|
10666
10804
|
self.policy = new AdminPolicy(options);
|
|
10805
|
+
self.processes = new AdminProcesses(options);
|
|
10667
10806
|
self.task = new AdminTask(options);
|
|
10668
10807
|
self.user = new AdminUser(options);
|
|
10669
|
-
self.processes = new AdminProcesses(options);
|
|
10670
|
-
self.message = new AdminMessage(options);
|
|
10671
|
-
self.doctypes = new AdminDocTypes(options);
|
|
10672
10808
|
}
|
|
10673
10809
|
}
|
|
10674
10810
|
|