@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.
Files changed (58) hide show
  1. package/api/admin/doctypes.js +76 -76
  2. package/api/admin/document.js +332 -332
  3. package/api/admin/form.js +151 -151
  4. package/api/admin/index.js +46 -46
  5. package/api/admin/list.js +133 -133
  6. package/api/admin/message.js +194 -194
  7. package/api/admin/notification.js +233 -233
  8. package/api/admin/organization.js +124 -124
  9. package/api/admin/plugin.js +116 -116
  10. package/api/admin/policy.js +78 -78
  11. package/api/admin/processes.js +370 -370
  12. package/api/admin/task.js +125 -125
  13. package/api/admin/user.js +185 -185
  14. package/api/dispatch.js +101 -101
  15. package/api/general/geoLocation.js +88 -88
  16. package/api/general/index.js +23 -23
  17. package/api/login.js +267 -267
  18. package/api/session.js +85 -85
  19. package/api/user/datasource.js +144 -144
  20. package/api/user/document.js +730 -730
  21. package/api/user/index.js +39 -39
  22. package/api/user/notification.js +101 -101
  23. package/api/user/organization.js +230 -230
  24. package/api/user/process.js +191 -191
  25. package/api/user/register.js +205 -205
  26. package/api/user/task.js +201 -201
  27. package/api/user/task_available.js +135 -135
  28. package/api/user/user.js +287 -287
  29. package/api/utils/cypher.js +37 -37
  30. package/api/utils/promises.js +118 -118
  31. package/bundleRollup.js +158 -158
  32. package/dist/bundle.cjs +4875 -4875
  33. package/dist/bundle.mjs +1 -1
  34. package/doc/api.md +336 -674
  35. package/doc.md +653 -653
  36. package/helper/boom.js +487 -487
  37. package/helper/cryptojs.js +6067 -6067
  38. package/index.js +85 -85
  39. package/package-lock.json +4635 -4635
  40. package/package.json +68 -68
  41. package/readme.md +25 -25
  42. package/tests/admin/document.spec.js +45 -45
  43. package/tests/admin/form.spec.js +74 -74
  44. package/tests/admin/list.spec.js +86 -86
  45. package/tests/admin/message.js +92 -92
  46. package/tests/admin/notification.spec.js +174 -174
  47. package/tests/admin/pluginspec..js +71 -71
  48. package/tests/admin/policy.spec.js +71 -71
  49. package/tests/admin/processes.spec.js +119 -119
  50. package/tests/admin/users.spec.js +127 -127
  51. package/tests/documents.spec.js +164 -164
  52. package/tests/login.spec.js +91 -91
  53. package/tests/session.spec..js +58 -58
  54. package/tests/user/documents.js +164 -164
  55. package/tests/user/organization.js +122 -122
  56. package/tests/user/process.js +71 -71
  57. package/tests/user/task_available.js +75 -75
  58. package/tests/user/user.js +88 -88
@@ -1,332 +1,332 @@
1
- import _ from 'lodash';
2
- import Boom from '@hapi/boom';
3
- import Joi from 'joi';
4
-
5
- /**
6
- * Admin Class for documents, permission admin
7
- * @class
8
- */
9
- class AdminDocuments {
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 Advanced search of document in elastic search ussing system manager
53
- * @param {!object} params - Params to search document
54
- * @param {!string} params.docId - Document id (_id database)
55
- * @param {!object} params.query - Query to search in elastic search
56
- * @param {!string} session Session, token JWT
57
- * @return {Promise}
58
- * @public
59
- * @async
60
- * @example
61
- *
62
- * const API = require('@docbrasil/api-systemmanager');
63
- * const api = new API();
64
- * const params = {
65
- * docId: '5edd11c46b6ce9729c2c297c',
66
- * query: {
67
- * "query": {
68
- * "bool": {
69
- * "minimum_should_match": 1,
70
- * "should": [
71
- * {
72
- * "match": {
73
- * "locationText.keyword": {
74
- * "query": "sao pau"
75
- * }
76
- * }
77
- * },
78
- * {
79
- * "wildcard": {
80
- * "locationText.normalized": "*sao pau*"
81
- * }
82
- * }
83
- * ]
84
- * }
85
- * }
86
- * }
87
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
88
- * await api.admin.document.advancedSearch(params, session);
89
- */
90
- async advancedSearch(params, session) {
91
- const self = this;
92
-
93
- try {
94
- Joi.assert(params, Joi.object().required(), 'Params to search document');
95
- Joi.assert(params.docId, Joi.string().required(), 'Document ID');
96
- Joi.assert(params.query, Joi.object().required(), 'eQuery, query to search document in elastic search');
97
- Joi.assert(session, Joi.string().required(), 'Session is token JWT');
98
-
99
- const {docId: docTypeId, query} = params;
100
- const payload = {docTypeId, query};
101
-
102
- const apiCall = self._client.post(`/admin/documents/search`, payload, self._setHeader(session));
103
- return self._returnData(await apiCall);
104
- } catch (ex) {
105
- throw ex;
106
- }
107
- }
108
-
109
- /**
110
- * @author CloudBrasil <abernardo.br@gmail.com>
111
- * @description Get document by id
112
- * @param {object} params - Params to get document by id
113
- * @param {string} params.docId - Document id (_id database)
114
- * @param {string} params.orgId - Organization id (_id database)
115
- * @param {string} session Session, token JWT
116
- * @return {Promise}
117
- * @public
118
- * @async
119
- * @example
120
- *
121
- * const API = require('@docbrasil/api-systemmanager');
122
- * const api = new API();
123
- * const params = {
124
- * docId: '5edd11c46b6ce9729c2c297c',
125
- * orgId: '55e4a3bd6be6b45210833fae'
126
- * };
127
- * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
128
- * await api.admin.document.findById(params, session);
129
- */
130
- async findById(params, session) {
131
- const self = this;
132
-
133
- try {
134
- Joi.assert(params, Joi.object().required(), 'Params to get document by id');
135
- Joi.assert(params.docId, Joi.string().required(), 'Document id (_id database)');
136
- Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
137
- Joi.assert(session, Joi.string().required(), 'Session is token JWT');
138
-
139
- const {docId, orgId} = params;
140
- const apiCall = self._client.get(`/admin/organizations/${orgId}/documents/${docId}`, self._setHeader(session));
141
- return self._returnData(await apiCall);
142
- } catch (ex) {
143
- throw ex;
144
- }
145
- }
146
-
147
- /**
148
- *
149
- * @author CloudBrasil <abernardo.br@gmail.com>
150
- * @description Request signed url url to put or get
151
- * @param {object} params Params to request signed url
152
- * @param {string} params.methodType Method type HTTP get or put
153
- * @param {string} params.docId The unique id of the document
154
- * @param {string} apiKey Api Key as permission to use this functionality
155
- * @return {Promise<object>} doc Returned document data with the signed url
156
- * @return {string} doc.docId Document id
157
- * @return {string} doc.name The name of the document, which is the fileName
158
- * @return {string} doc.areaId docAreaId of the document
159
- * @return {string} doc.type the document mimi type
160
- * @return {string} doc.signedUrl the signed URL to upload
161
- * @public
162
- * @async
163
- * @example
164
- *
165
- * const API = require('@docbrasil/api-systemmanager');
166
- * const api = new API();
167
- * const params - {
168
- * methodType: 'put',
169
- * docId: '5dadd01dc4af3941d42f8c5c'
170
- * };
171
- * const apiKey: '...';
172
- * const { docId, name, areaId, type, signedUrl } = await api.admin.document.signedUrl(params, apiKey);
173
- *
174
- * @example
175
- *
176
- * const API = require('@docbrasil/api-systemmanager');
177
- * const api = new API();
178
- * const params - {
179
- * methodType: 'get',
180
- * docId: '5dadd01dc4af3941d42f8c5c'
181
- * };
182
- * const apiKey: '...';
183
- * const { signedUrl, imageType } = await api.admin.document.signedUrl(params, apiKey);
184
- */
185
- async signedUrl(params = {}, apiKey) {
186
-
187
- Joi.assert(params, Joi.object().required());
188
- Joi.assert(params.methodType, Joi.string().required());
189
- Joi.assert(params.docId, Joi.string().required());
190
- Joi.assert(apiKey, Joi.string().required());
191
-
192
- const self = this;
193
- const { methodType, docId } = params;
194
- const url = `/api/documents/signedurl?apiKey=${apiKey}&methodType=${methodType}&docId=${docId}`;
195
- const apiCall = self._client
196
- .get(url);
197
-
198
- return self._returnData(await apiCall);
199
- }
200
-
201
- /**
202
- *
203
- * @author CloudBrasil <abernardo.br@gmail.com>
204
- * @description Update a document content
205
- * @param {object} params Params to request signed url
206
- * @param {string} params.content The content text
207
- * @param {string} params.docId The unique id of the document
208
- * @param {string} apiKey Api Key as permission to use this functionality
209
- * @return {Promise<object>} doc Returned document data with the signed url
210
- * @public
211
- * @async
212
- * @example
213
- *
214
- * const API = require('@docbrasil/api-systemmanager');
215
- * const api = new API();
216
- * const params - {
217
- * content: 'some text...',
218
- * docId: '5dadd01dc4af3941d42f8c5c'
219
- * };
220
- * const apiKey: '...';
221
- * await api.admin.document.updateContent(params, apiKey);
222
- */
223
- async updateContent(params = {}, apiKey) {
224
-
225
- Joi.assert(params, Joi.object().required());
226
- Joi.assert(params.content, Joi.string().required());
227
- Joi.assert(params.docId, Joi.string().required());
228
- Joi.assert(apiKey, Joi.string().required());
229
-
230
- const self = this;
231
- const { content, docId } = params;
232
- const url = `/api/documents/${docId}/content?apiKey=${apiKey}`;
233
- const data = { content };
234
- const apiCall = self._client
235
- .put(url, data, {
236
- maxContentLength: Infinity,
237
- maxBodyLength: Infinity
238
- });
239
- return self._returnData(await apiCall);
240
- }
241
-
242
- /**
243
- *
244
- * @author CloudBrasil <abernardo.br@gmail.com>
245
- * @description Update a document content
246
- * @param {object} params Params to request signed url
247
- * @param {string} params.content The content text
248
- * @param {string} params.docId The unique id of the document
249
- * @param {string} params.searchablePDFURL The searchable PDF Url
250
- * @param {object} params.overlay The overlay information
251
- * @param {array} params.entities The list of entities extracted from the text
252
- * @param {object} params.language The language detected
253
- * @param {string} params.language.name The language name detected
254
- * @param {string} params.language.confidence The confidence that it is the language
255
- * @param {string} apiKey Api Key as permission to use this functionality
256
- * @return {Promise<object>} doc Returned document data with the signed url
257
- * @public
258
- * @async
259
- * @example
260
- *
261
- * const API = require('@docbrasil/api-systemmanager');
262
- * const api = new API();
263
- * const params - {
264
- * content: 'some text...',
265
- * docId: '5dadd01dc4af3941d42f8c5c'
266
- * };
267
- * const apiKey: '...';
268
- * await api.admin.document.updateContent(params, apiKey);
269
- */
270
- async updateAI(params = {}, apiKey) {
271
-
272
- Joi.assert(params, Joi.object().required());
273
- Joi.assert(params.docId, Joi.string().required());
274
- Joi.assert(apiKey, Joi.string().required());
275
-
276
- const self = this;
277
- const { docId } = params;
278
- delete params.docId;
279
- const url = `/api/documents/${docId}/ai?apiKey=${apiKey}`;
280
- const apiCall = self._client
281
- .put(url, params, {
282
- maxContentLength: Infinity,
283
- maxBodyLength: Infinity
284
- });
285
- return self._returnData(await apiCall);
286
- }
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
- }
331
-
332
- export default AdminDocuments;
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Admin Class for documents, permission admin
7
+ * @class
8
+ */
9
+ class AdminDocuments {
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 Advanced search of document in elastic search ussing system manager
53
+ * @param {!object} params - Params to search document
54
+ * @param {!string} params.docId - Document id (_id database)
55
+ * @param {!object} params.query - Query to search in elastic search
56
+ * @param {!string} session Session, token JWT
57
+ * @return {Promise}
58
+ * @public
59
+ * @async
60
+ * @example
61
+ *
62
+ * const API = require('@docbrasil/api-systemmanager');
63
+ * const api = new API();
64
+ * const params = {
65
+ * docId: '5edd11c46b6ce9729c2c297c',
66
+ * query: {
67
+ * "query": {
68
+ * "bool": {
69
+ * "minimum_should_match": 1,
70
+ * "should": [
71
+ * {
72
+ * "match": {
73
+ * "locationText.keyword": {
74
+ * "query": "sao pau"
75
+ * }
76
+ * }
77
+ * },
78
+ * {
79
+ * "wildcard": {
80
+ * "locationText.normalized": "*sao pau*"
81
+ * }
82
+ * }
83
+ * ]
84
+ * }
85
+ * }
86
+ * }
87
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
88
+ * await api.admin.document.advancedSearch(params, session);
89
+ */
90
+ async advancedSearch(params, session) {
91
+ const self = this;
92
+
93
+ try {
94
+ Joi.assert(params, Joi.object().required(), 'Params to search document');
95
+ Joi.assert(params.docId, Joi.string().required(), 'Document ID');
96
+ Joi.assert(params.query, Joi.object().required(), 'eQuery, query to search document in elastic search');
97
+ Joi.assert(session, Joi.string().required(), 'Session is token JWT');
98
+
99
+ const {docId: docTypeId, query} = params;
100
+ const payload = {docTypeId, query};
101
+
102
+ const apiCall = self._client.post(`/admin/documents/search`, payload, self._setHeader(session));
103
+ return self._returnData(await apiCall);
104
+ } catch (ex) {
105
+ throw ex;
106
+ }
107
+ }
108
+
109
+ /**
110
+ * @author CloudBrasil <abernardo.br@gmail.com>
111
+ * @description Get document by id
112
+ * @param {object} params - Params to get document by id
113
+ * @param {string} params.docId - Document id (_id database)
114
+ * @param {string} params.orgId - Organization id (_id database)
115
+ * @param {string} session Session, token JWT
116
+ * @return {Promise}
117
+ * @public
118
+ * @async
119
+ * @example
120
+ *
121
+ * const API = require('@docbrasil/api-systemmanager');
122
+ * const api = new API();
123
+ * const params = {
124
+ * docId: '5edd11c46b6ce9729c2c297c',
125
+ * orgId: '55e4a3bd6be6b45210833fae'
126
+ * };
127
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
128
+ * await api.admin.document.findById(params, session);
129
+ */
130
+ async findById(params, session) {
131
+ const self = this;
132
+
133
+ try {
134
+ Joi.assert(params, Joi.object().required(), 'Params to get document by id');
135
+ Joi.assert(params.docId, Joi.string().required(), 'Document id (_id database)');
136
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization id (_id database)');
137
+ Joi.assert(session, Joi.string().required(), 'Session is token JWT');
138
+
139
+ const {docId, orgId} = params;
140
+ const apiCall = self._client.get(`/admin/organizations/${orgId}/documents/${docId}`, self._setHeader(session));
141
+ return self._returnData(await apiCall);
142
+ } catch (ex) {
143
+ throw ex;
144
+ }
145
+ }
146
+
147
+ /**
148
+ *
149
+ * @author CloudBrasil <abernardo.br@gmail.com>
150
+ * @description Request signed url url to put or get
151
+ * @param {object} params Params to request signed url
152
+ * @param {string} params.methodType Method type HTTP get or put
153
+ * @param {string} params.docId The unique id of the document
154
+ * @param {string} apiKey Api Key as permission to use this functionality
155
+ * @return {Promise<object>} doc Returned document data with the signed url
156
+ * @return {string} doc.docId Document id
157
+ * @return {string} doc.name The name of the document, which is the fileName
158
+ * @return {string} doc.areaId docAreaId of the document
159
+ * @return {string} doc.type the document mimi type
160
+ * @return {string} doc.signedUrl the signed URL to upload
161
+ * @public
162
+ * @async
163
+ * @example
164
+ *
165
+ * const API = require('@docbrasil/api-systemmanager');
166
+ * const api = new API();
167
+ * const params - {
168
+ * methodType: 'put',
169
+ * docId: '5dadd01dc4af3941d42f8c5c'
170
+ * };
171
+ * const apiKey: '...';
172
+ * const { docId, name, areaId, type, signedUrl } = await api.admin.document.signedUrl(params, apiKey);
173
+ *
174
+ * @example
175
+ *
176
+ * const API = require('@docbrasil/api-systemmanager');
177
+ * const api = new API();
178
+ * const params - {
179
+ * methodType: 'get',
180
+ * docId: '5dadd01dc4af3941d42f8c5c'
181
+ * };
182
+ * const apiKey: '...';
183
+ * const { signedUrl, imageType } = await api.admin.document.signedUrl(params, apiKey);
184
+ */
185
+ async signedUrl(params = {}, apiKey) {
186
+
187
+ Joi.assert(params, Joi.object().required());
188
+ Joi.assert(params.methodType, Joi.string().required());
189
+ Joi.assert(params.docId, Joi.string().required());
190
+ Joi.assert(apiKey, Joi.string().required());
191
+
192
+ const self = this;
193
+ const { methodType, docId } = params;
194
+ const url = `/api/documents/signedurl?apiKey=${apiKey}&methodType=${methodType}&docId=${docId}`;
195
+ const apiCall = self._client
196
+ .get(url);
197
+
198
+ return self._returnData(await apiCall);
199
+ }
200
+
201
+ /**
202
+ *
203
+ * @author CloudBrasil <abernardo.br@gmail.com>
204
+ * @description Update a document content
205
+ * @param {object} params Params to request signed url
206
+ * @param {string} params.content The content text
207
+ * @param {string} params.docId The unique id of the document
208
+ * @param {string} apiKey Api Key as permission to use this functionality
209
+ * @return {Promise<object>} doc Returned document data with the signed url
210
+ * @public
211
+ * @async
212
+ * @example
213
+ *
214
+ * const API = require('@docbrasil/api-systemmanager');
215
+ * const api = new API();
216
+ * const params - {
217
+ * content: 'some text...',
218
+ * docId: '5dadd01dc4af3941d42f8c5c'
219
+ * };
220
+ * const apiKey: '...';
221
+ * await api.admin.document.updateContent(params, apiKey);
222
+ */
223
+ async updateContent(params = {}, apiKey) {
224
+
225
+ Joi.assert(params, Joi.object().required());
226
+ Joi.assert(params.content, Joi.string().required());
227
+ Joi.assert(params.docId, Joi.string().required());
228
+ Joi.assert(apiKey, Joi.string().required());
229
+
230
+ const self = this;
231
+ const { content, docId } = params;
232
+ const url = `/api/documents/${docId}/content?apiKey=${apiKey}`;
233
+ const data = { content };
234
+ const apiCall = self._client
235
+ .put(url, data, {
236
+ maxContentLength: Infinity,
237
+ maxBodyLength: Infinity
238
+ });
239
+ return self._returnData(await apiCall);
240
+ }
241
+
242
+ /**
243
+ *
244
+ * @author CloudBrasil <abernardo.br@gmail.com>
245
+ * @description Update a document content
246
+ * @param {object} params Params to request signed url
247
+ * @param {string} params.content The content text
248
+ * @param {string} params.docId The unique id of the document
249
+ * @param {string} params.searchablePDFURL The searchable PDF Url
250
+ * @param {object} params.overlay The overlay information
251
+ * @param {array} params.entities The list of entities extracted from the text
252
+ * @param {object} params.language The language detected
253
+ * @param {string} params.language.name The language name detected
254
+ * @param {string} params.language.confidence The confidence that it is the language
255
+ * @param {string} apiKey Api Key as permission to use this functionality
256
+ * @return {Promise<object>} doc Returned document data with the signed url
257
+ * @public
258
+ * @async
259
+ * @example
260
+ *
261
+ * const API = require('@docbrasil/api-systemmanager');
262
+ * const api = new API();
263
+ * const params - {
264
+ * content: 'some text...',
265
+ * docId: '5dadd01dc4af3941d42f8c5c'
266
+ * };
267
+ * const apiKey: '...';
268
+ * await api.admin.document.updateContent(params, apiKey);
269
+ */
270
+ async updateAI(params = {}, apiKey) {
271
+
272
+ Joi.assert(params, Joi.object().required());
273
+ Joi.assert(params.docId, Joi.string().required());
274
+ Joi.assert(apiKey, Joi.string().required());
275
+
276
+ const self = this;
277
+ const { docId } = params;
278
+ delete params.docId;
279
+ const url = `/api/documents/${docId}/ai?apiKey=${apiKey}`;
280
+ const apiCall = self._client
281
+ .put(url, params, {
282
+ maxContentLength: Infinity,
283
+ maxBodyLength: Infinity
284
+ });
285
+ return self._returnData(await apiCall);
286
+ }
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
+ }
331
+
332
+ export default AdminDocuments;