@docbrasil/api-systemmanager 1.0.49 → 1.0.53

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,49 @@ 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.content, Joi.string().required());
319
+ Joi.assert(params.docId, Joi.string().required());
320
+ Joi.assert(params.page, Joi.string().required());
321
+ Joi.assert(apiKey, Joi.string().required());
322
+
323
+ const self = this;
324
+ const { page, docId } = params;
325
+ const url = `/api/documents/${docId}/content/${page}?apiKey=${apiKey}`;
326
+ const apiCall = self._client
327
+ .get(url);
328
+ return self._returnData(await apiCall);
329
+ }
330
+
288
331
  }
289
332
 
290
333
  export default AdminDocuments;
@@ -499,7 +499,7 @@ class Documents {
499
499
  /**
500
500
  * Uploads the file
501
501
  * @param {object} params Params to upload document
502
- * @param {string|buffer} params.content The content of the file (base64 or Buffer)
502
+ * @param {buffer} params.content The content of the file (Buffer)
503
503
  * @param {string} params.signedUrl The signed URL
504
504
  * @param {string} params.type The file mime type
505
505
  * @return {Promise<boolean>} True if success
@@ -522,7 +522,7 @@ class Documents {
522
522
  async uploadSignedDocument(params) {
523
523
  const { content, signedUrl, type } = params;
524
524
  Joi.assert(params, Joi.object().required());
525
- Joi.assert(params.content, Joi.string().required());
525
+ Joi.assert(params.content, Joi.required());
526
526
  Joi.assert(params.signedUrl, Joi.string().required());
527
527
  Joi.assert(params.type, Joi.string().required());
528
528
 
@@ -174,16 +174,6 @@ class Organization {
174
174
  }
175
175
 
176
176
  /**
177
- * @author Augusto Pissarra <abernardo.br@gmail.com>
178
- * @description Call URL internal
179
- * @param {!object} params Params to call fectch (URL internal)
180
- * @param {!string} params.url URL to call
181
- * @param {!string} [params.method=POST] Fetch Method
182
- * @param {string} params.payload Payload to send
183
- * @returns {promise}
184
- * @public
185
- * @async
186
- /**
187
177
  * @author Thiago Anselmo <thiagoo.anselmoo@gmail.com>
188
178
  * @description Call URL internal, need auth JWT (session)
189
179
  * @param {!object} params Params to call fectch (URL internal)
@@ -1,5 +1,5 @@
1
- imnport _ from 'lodash';
2
- imnport Boom from '@hapi/boom';
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
3
 
4
4
  class ThePromise {
5
5
 
@@ -0,0 +1,158 @@
1
+ import * as rollup from 'rollup';
2
+
3
+ import nodePolyfills from 'rollup-plugin-node-polyfills';
4
+ import cleanup from 'rollup-plugin-cleanup';
5
+ import {uglify} from "rollup-plugin-uglify";
6
+
7
+ import json from '@rollup/plugin-json';
8
+ import commonjs from '@rollup/plugin-commonjs';
9
+ import alias from '@rollup/plugin-alias';
10
+ import {nodeResolve} from '@rollup/plugin-node-resolve';
11
+
12
+ import moment from 'moment';
13
+
14
+ /**
15
+ * @description Class to bukld munti file type (CJS and MJS)
16
+ */
17
+ class BuildRollup {
18
+
19
+ /**
20
+ * @description Alist to change modules to esm for use in frontend
21
+ * @type {({find: string, replacement: string}|{find: string, replacement: string}|{find: string, replacement: string}|{find: string, replacement: string})[]}
22
+ */
23
+ #aliasList = [
24
+ {
25
+ find: 'lodash',
26
+ replacement: 'lodash-es'
27
+ },
28
+ {
29
+ find: 'moment',
30
+ replacement: 'dayjs/esm'
31
+ },
32
+ {
33
+ find: 'axios',
34
+ replacement: 'axios-esm'
35
+ },
36
+ {
37
+ find: 'joi',
38
+ replacement: 'joi/dist/joi-browser.min.js'
39
+ }
40
+ ];
41
+
42
+ /**
43
+ * @description Not add in bundle bellow module, install external to use.
44
+ * @type {string[]}
45
+ */
46
+ #externalPlugins = ['lodash', 'axios', '@hapi/boom', 'joi', 'moment'];
47
+
48
+ /**
49
+ * @description Mount list of plugin backend and frontend
50
+ * @type {{mjs: (*)[], cjs: [*, *, *, *]}}
51
+ */
52
+ #pluginList = {
53
+ cjs: [
54
+ commonjs(),
55
+ nodePolyfills(),
56
+ json(),
57
+ nodeResolve(),
58
+ ],
59
+
60
+ mjs: [
61
+ alias({entries: this.#aliasList}),
62
+
63
+ commonjs(),
64
+ nodePolyfills(),
65
+ json(),
66
+ nodeResolve(),
67
+ cleanup(),
68
+ uglify()
69
+ ]
70
+ };
71
+
72
+ /**
73
+ * @description Mount configuration to build
74
+ * @type {{mjs: {output: {file: string, format: string}, entry: {input: string, plugins: *[]}}, cjs: {output: {file: string, format: string}, entry: {input: string, external: [], plugins: (*)[]}}}}
75
+ */
76
+ #rollupConfig = {
77
+ cjs: {
78
+ entry: {
79
+ input: './index.js',
80
+ external: this.#externalPlugins,
81
+ plugins: this.#pluginList.cjs,
82
+ },
83
+ output: {
84
+ file: 'dist/bundle.cjs',
85
+ format: 'cjs'
86
+ }
87
+ },
88
+
89
+ mjs: {
90
+ entry: {
91
+ input: './index.js',
92
+ plugins: this.#pluginList.mjs,
93
+ },
94
+ output: {
95
+ file: 'dist/bundle.mjs',
96
+ format: 'esm'
97
+ }
98
+ }
99
+ }
100
+
101
+ /**
102
+ * @see https://rollupjs.org/guide/en/#rolluprollup
103
+ * @description Build all types (CJS backend 'require' | MJS Frontend 'import')
104
+ */
105
+ async #rollupBuild(config) {
106
+ const self = this;
107
+
108
+ try {
109
+ const bundle = await rollup.rollup(config.entry);
110
+ self.log('Bundle generated');
111
+
112
+ await bundle.write(config.output);
113
+ self.log('Bundle writen');
114
+
115
+ await bundle.close();
116
+ self.log('Bundle finished\n');
117
+
118
+ } catch (ex) {
119
+ throw ex;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * @description Log in terminal process
125
+ * @param {string} text - text to log in terminal
126
+ */
127
+ log(text, type = 'log') {
128
+ const dateNow = moment().format('DD/MM/YYYY HH:mm:ss');
129
+ console[type](`${dateNow}\t ${text}`);
130
+ }
131
+
132
+ async init() {
133
+ const self = this;
134
+
135
+ try {
136
+ self.log('Start process to bundle files');
137
+
138
+ for await (const bundleType of Object.keys(self.#rollupConfig)) {
139
+ self.log(`Start process to bundle type ${bundleType}`);
140
+
141
+ const bundleConfig = self.#rollupConfig[bundleType];
142
+ await self.#rollupBuild(bundleConfig);
143
+ }
144
+
145
+ self.log('Done! All to bundle generated with success');
146
+
147
+ } catch (ex) {
148
+ throw ex;
149
+ }
150
+ }
151
+ }
152
+
153
+ // ------------ //
154
+ // START BUNDLE //
155
+ // ------------ //
156
+
157
+ const buildRollup = new BuildRollup();
158
+ buildRollup.init();