@docbrasil/api-systemmanager 1.0.93 → 1.0.94
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/doctypes.js +76 -76
- package/api/admin/document.js +332 -332
- package/api/admin/form.js +151 -151
- package/api/admin/index.js +46 -46
- package/api/admin/list.js +133 -133
- package/api/admin/message.js +194 -194
- package/api/admin/notification.js +233 -233
- package/api/admin/organization.js +124 -124
- package/api/admin/plugin.js +116 -116
- package/api/admin/policy.js +78 -78
- package/api/admin/processes.js +370 -370
- package/api/admin/task.js +125 -125
- package/api/admin/user.js +185 -185
- package/api/dispatch.js +101 -101
- package/api/general/geoLocation.js +88 -88
- package/api/general/index.js +23 -23
- package/api/login.js +267 -267
- package/api/session.js +85 -85
- package/api/user/datasource.js +144 -144
- package/api/user/document.js +730 -730
- package/api/user/index.js +39 -39
- package/api/user/notification.js +101 -101
- package/api/user/organization.js +230 -230
- package/api/user/process.js +191 -191
- package/api/user/register.js +205 -205
- package/api/user/task.js +201 -201
- package/api/user/task_available.js +135 -135
- package/api/user/user.js +287 -287
- package/api/utils/cypher.js +37 -37
- package/api/utils/promises.js +118 -118
- package/bundleRollup.js +158 -158
- package/dist/bundle.cjs +4875 -4875
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +336 -674
- package/doc.md +653 -653
- package/helper/boom.js +487 -487
- package/helper/cryptojs.js +6067 -6067
- package/index.js +85 -85
- package/package-lock.json +4635 -4635
- package/package.json +68 -68
- package/readme.md +25 -25
- package/tests/admin/document.spec.js +45 -45
- package/tests/admin/form.spec.js +74 -74
- package/tests/admin/list.spec.js +86 -86
- package/tests/admin/message.js +92 -92
- package/tests/admin/notification.spec.js +174 -174
- package/tests/admin/pluginspec..js +71 -71
- package/tests/admin/policy.spec.js +71 -71
- package/tests/admin/processes.spec.js +119 -119
- package/tests/admin/users.spec.js +127 -127
- package/tests/documents.spec.js +164 -164
- package/tests/login.spec.js +91 -91
- package/tests/session.spec..js +58 -58
- package/tests/user/documents.js +164 -164
- package/tests/user/organization.js +122 -122
- package/tests/user/process.js +71 -71
- package/tests/user/task_available.js +75 -75
- package/tests/user/user.js +88 -88
|
@@ -1,124 +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;
|
|
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/admin/plugin.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import Boom from '@hapi/boom';
|
|
3
|
-
import Joi from 'joi';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Admin Class for plugin, permission admin
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class AdminPlugin {
|
|
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 Find plugins
|
|
53
|
-
* @param {object} params - Params to search plugins
|
|
54
|
-
* @param {number} params.page - Start page to pagination
|
|
55
|
-
* @param {number} params.perPage - Items per page
|
|
56
|
-
* @public
|
|
57
|
-
* @async
|
|
58
|
-
* @example
|
|
59
|
-
*
|
|
60
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
61
|
-
* const api = new API();
|
|
62
|
-
* const params = {page: 1, perPage: 200};
|
|
63
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
64
|
-
* await api.user.organization.findById(params, session);
|
|
65
|
-
*/
|
|
66
|
-
async find(params, session) {
|
|
67
|
-
const self = this;
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
Joi.assert(params, Joi.object().required(), 'Params to search plugins');
|
|
71
|
-
Joi.assert(params.page, Joi.number(), 'Start page to pagination');
|
|
72
|
-
Joi.assert(params.perPage, Joi.number(), 'Items per page');
|
|
73
|
-
Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
|
|
74
|
-
|
|
75
|
-
const {page = 1, perPage = 300} = params
|
|
76
|
-
const queryString = `page=${page}&perPage=${perPage}`;
|
|
77
|
-
|
|
78
|
-
const apiCall = self._client.post(`/admin/plugins?${queryString}`, {}, self._setHeader(session));
|
|
79
|
-
return self._returnData(await apiCall);
|
|
80
|
-
} catch (ex) {
|
|
81
|
-
throw ex;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
87
|
-
* @description Get plugin by ID
|
|
88
|
-
* @param {string} id Plugin Id (_id database)
|
|
89
|
-
* @param {string} session Session, token JWT
|
|
90
|
-
* @return {Promise}
|
|
91
|
-
* @public
|
|
92
|
-
* @async
|
|
93
|
-
* @example
|
|
94
|
-
*
|
|
95
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
96
|
-
* const api = new API();
|
|
97
|
-
* const id ='55e4a3bd6be6b45210833fae',
|
|
98
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
99
|
-
* await api.admin.plugin.findById(id, session);
|
|
100
|
-
*/
|
|
101
|
-
async findById(id, session) {
|
|
102
|
-
const self = this;
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
Joi.assert(id, Joi.string().required());
|
|
106
|
-
Joi.assert(session, Joi.string().required());
|
|
107
|
-
|
|
108
|
-
const apiCall = self._client.get(`/admin/plugins/${id}`, self._setHeader(session));
|
|
109
|
-
return self._returnData(await apiCall);
|
|
110
|
-
} catch (ex) {
|
|
111
|
-
throw ex;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default AdminPlugin;
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Admin Class for plugin, permission admin
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class AdminPlugin {
|
|
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 Find plugins
|
|
53
|
+
* @param {object} params - Params to search plugins
|
|
54
|
+
* @param {number} params.page - Start page to pagination
|
|
55
|
+
* @param {number} params.perPage - Items per page
|
|
56
|
+
* @public
|
|
57
|
+
* @async
|
|
58
|
+
* @example
|
|
59
|
+
*
|
|
60
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
61
|
+
* const api = new API();
|
|
62
|
+
* const params = {page: 1, perPage: 200};
|
|
63
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
64
|
+
* await api.user.organization.findById(params, session);
|
|
65
|
+
*/
|
|
66
|
+
async find(params, session) {
|
|
67
|
+
const self = this;
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
Joi.assert(params, Joi.object().required(), 'Params to search plugins');
|
|
71
|
+
Joi.assert(params.page, Joi.number(), 'Start page to pagination');
|
|
72
|
+
Joi.assert(params.perPage, Joi.number(), 'Items per page');
|
|
73
|
+
Joi.assert(session, Joi.string().required(), 'SM session (JWT) to call API');
|
|
74
|
+
|
|
75
|
+
const {page = 1, perPage = 300} = params
|
|
76
|
+
const queryString = `page=${page}&perPage=${perPage}`;
|
|
77
|
+
|
|
78
|
+
const apiCall = self._client.post(`/admin/plugins?${queryString}`, {}, self._setHeader(session));
|
|
79
|
+
return self._returnData(await apiCall);
|
|
80
|
+
} catch (ex) {
|
|
81
|
+
throw ex;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
87
|
+
* @description Get plugin by ID
|
|
88
|
+
* @param {string} id Plugin Id (_id database)
|
|
89
|
+
* @param {string} session Session, token JWT
|
|
90
|
+
* @return {Promise}
|
|
91
|
+
* @public
|
|
92
|
+
* @async
|
|
93
|
+
* @example
|
|
94
|
+
*
|
|
95
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
96
|
+
* const api = new API();
|
|
97
|
+
* const id ='55e4a3bd6be6b45210833fae',
|
|
98
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
99
|
+
* await api.admin.plugin.findById(id, session);
|
|
100
|
+
*/
|
|
101
|
+
async findById(id, session) {
|
|
102
|
+
const self = this;
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
Joi.assert(id, Joi.string().required());
|
|
106
|
+
Joi.assert(session, Joi.string().required());
|
|
107
|
+
|
|
108
|
+
const apiCall = self._client.get(`/admin/plugins/${id}`, self._setHeader(session));
|
|
109
|
+
return self._returnData(await apiCall);
|
|
110
|
+
} catch (ex) {
|
|
111
|
+
throw ex;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default AdminPlugin;
|
package/api/admin/policy.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import Boom from '@hapi/boom';
|
|
3
|
-
import Joi from 'joi';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Admin Class for policy, permission admin
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class AdminPolicy {
|
|
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 CloudBrasil <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 CloudBrasil <abernardo.br@gmail.com>
|
|
52
|
-
* @description Find all policies
|
|
53
|
-
* @param {string} session Session, token JWT
|
|
54
|
-
* @return {Promise}
|
|
55
|
-
* @public
|
|
56
|
-
* @async
|
|
57
|
-
* @example
|
|
58
|
-
*
|
|
59
|
-
* const API = require('@docbrasil/api-systemmanager');
|
|
60
|
-
* const api = new API();
|
|
61
|
-
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
62
|
-
* await api.admin.policy.find(session);
|
|
63
|
-
*/
|
|
64
|
-
async find(session) {
|
|
65
|
-
const self = this;
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
Joi.assert(session, Joi.string().required());
|
|
69
|
-
|
|
70
|
-
const apiCall = self._client.get('/admin/policies', self._setHeader(session));
|
|
71
|
-
return self._returnData(await apiCall);
|
|
72
|
-
} catch (ex) {
|
|
73
|
-
throw ex;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default AdminPolicy;
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Admin Class for policy, permission admin
|
|
7
|
+
* @class
|
|
8
|
+
*/
|
|
9
|
+
class AdminPolicy {
|
|
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 CloudBrasil <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 CloudBrasil <abernardo.br@gmail.com>
|
|
52
|
+
* @description Find all policies
|
|
53
|
+
* @param {string} session Session, token JWT
|
|
54
|
+
* @return {Promise}
|
|
55
|
+
* @public
|
|
56
|
+
* @async
|
|
57
|
+
* @example
|
|
58
|
+
*
|
|
59
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
60
|
+
* const api = new API();
|
|
61
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
62
|
+
* await api.admin.policy.find(session);
|
|
63
|
+
*/
|
|
64
|
+
async find(session) {
|
|
65
|
+
const self = this;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
Joi.assert(session, Joi.string().required());
|
|
69
|
+
|
|
70
|
+
const apiCall = self._client.get('/admin/policies', self._setHeader(session));
|
|
71
|
+
return self._returnData(await apiCall);
|
|
72
|
+
} catch (ex) {
|
|
73
|
+
throw ex;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default AdminPolicy;
|