@docbrasil/api-systemmanager 1.0.54 → 1.0.55
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/document.js +0 -42
- package/api/admin/index.js +6 -5
- package/api/admin/organization.js +124 -0
- package/dist/bundle.cjs +0 -43
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +0 -257
- package/package.json +1 -1
package/api/admin/document.js
CHANGED
|
@@ -285,48 +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.docId, Joi.string().required());
|
|
319
|
-
Joi.assert(params.page, Joi.string().required());
|
|
320
|
-
Joi.assert(apiKey, Joi.string().required());
|
|
321
|
-
|
|
322
|
-
const self = this;
|
|
323
|
-
const { page, docId } = params;
|
|
324
|
-
const url = `/api/documents/${docId}/content/${page}?apiKey=${apiKey}`;
|
|
325
|
-
const apiCall = self._client
|
|
326
|
-
.get(url);
|
|
327
|
-
return self._returnData(await apiCall);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
288
|
}
|
|
331
289
|
|
|
332
290
|
export default AdminDocuments;
|
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/dist/bundle.cjs
CHANGED
|
@@ -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
|
/**
|