@docbrasil/api-systemmanager 1.0.55 → 1.0.58

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,6 +285,48 @@ 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
+
288
330
  }
289
331
 
290
332
  export default AdminDocuments;
package/api/login.js CHANGED
@@ -231,6 +231,37 @@ class Login {
231
231
  throw ex;
232
232
  }
233
233
  }
234
+
235
+ /**
236
+ * @author CloudBrasil <abernardo.br@gmail.com>
237
+ * @description Recover the password
238
+ * @param {string} username The username or email
239
+ * @return {promise<object>}} data
240
+ * @return {boolean} data.success true|false
241
+ * @public
242
+ * @async
243
+ * @example
244
+ *
245
+ * const API = require('@docbrasil/api-systemmanager');
246
+ *
247
+ * // Params of the instance
248
+ * const params = {...}
249
+ * const api = new API(params);
250
+ * const { success } = await api.login.recover('myusername');
251
+ */
252
+ async recover(username) {
253
+ const self = this;
254
+
255
+ try {
256
+ Joi.assert(username, Joi.string().required());
257
+
258
+ const url = `users/${username}/sendResetEmail`;
259
+ const apiCall = self._client.get(url);
260
+ return self._returnData(await apiCall);
261
+ } catch (ex) {
262
+ throw ex;
263
+ }
264
+ }
234
265
  }
235
266
 
236
267
  export default Login;
@@ -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._setHeader(session));
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._setHeader(session));
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);
@@ -9024,6 +9041,48 @@ class AdminDocuments {
9024
9041
  return self._returnData(await apiCall);
9025
9042
  }
9026
9043
 
9044
+ /**
9045
+ *
9046
+ * @author CloudBrasil <abernardo.br@gmail.com>
9047
+ * @description Get the content of a document
9048
+ * @param {object} params Params to request signed url
9049
+ * @param {string} params.docId The unique id of the document
9050
+ * @param {string} params.page The page, from 0, or 'all' if all pages (the full content)
9051
+ * @param {string} apiKey Api Key as permission to use this functionality
9052
+ * @return {Promise<object>} data the document content
9053
+ * @return {string} data._id the _id of the document
9054
+ * @return {string} data.content all the pages or if asked by page, just one page, the one requested
9055
+ * @return {string} data.content.TextOverlay the overlay text if requested
9056
+ * @return {string} data.content.ParsedText the page text content
9057
+ * @return {number} data.total the total number of pages
9058
+ * @public
9059
+ * @async
9060
+ * @example
9061
+ *
9062
+ * const API = require('@docbrasil/api-systemmanager');
9063
+ * const api = new API();
9064
+ * const params - {
9065
+ * page: '0',
9066
+ * docId: '5dadd01dc4af3941d42f8c5c'
9067
+ * };
9068
+ * const apiKey: '...';
9069
+ * await api.admin.document.getContent(params, apiKey);
9070
+ */
9071
+ async getContent(params = {}, apiKey) {
9072
+
9073
+ Joi__default["default"].assert(params, Joi__default["default"].object().required());
9074
+ Joi__default["default"].assert(params.docId, Joi__default["default"].string().required());
9075
+ Joi__default["default"].assert(params.page, Joi__default["default"].string().required());
9076
+ Joi__default["default"].assert(apiKey, Joi__default["default"].string().required());
9077
+
9078
+ const self = this;
9079
+ const { page, docId } = params;
9080
+ const url = `/api/documents/${docId}/content/${page}?apiKey=${apiKey}`;
9081
+ const apiCall = self._client
9082
+ .get(url);
9083
+ return self._returnData(await apiCall);
9084
+ }
9085
+
9027
9086
  }
9028
9087
 
9029
9088
  /**
@@ -10600,6 +10659,125 @@ class AdminDocTypes {
10600
10659
  }
10601
10660
  }
10602
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
+
10603
10781
  /**
10604
10782
  * @class API request, admin permission level
10605
10783
  */
@@ -10615,17 +10793,18 @@ class Admin {
10615
10793
  Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
10616
10794
 
10617
10795
  const self = this;
10796
+ self.doctypes = new AdminDocTypes(options);
10618
10797
  self.document = new AdminDocuments(options);
10619
10798
  self.form = new AdminForm(options);
10620
- self.notification = new AdminNotification(options);
10621
10799
  self.list = new AdminLists(options);
10800
+ self.message = new AdminMessage(options);
10801
+ self.organizations = new Organization(options);
10802
+ self.notification = new AdminNotification(options);
10622
10803
  self.plugin = new AdminPlugin(options);
10623
10804
  self.policy = new AdminPolicy(options);
10805
+ self.processes = new AdminProcesses(options);
10624
10806
  self.task = new AdminTask(options);
10625
10807
  self.user = new AdminUser(options);
10626
- self.processes = new AdminProcesses(options);
10627
- self.message = new AdminMessage(options);
10628
- self.doctypes = new AdminDocTypes(options);
10629
10808
  }
10630
10809
  }
10631
10810