@docbrasil/api-systemmanager 1.0.71 → 1.0.73
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/user/document.js +78 -3
- package/dist/bundle.cjs +78 -3
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +313 -2
- package/package.json +1 -1
package/api/user/document.js
CHANGED
|
@@ -183,7 +183,7 @@ class Documents {
|
|
|
183
183
|
* orgId: '5df7f19618430c89a41a19d2',
|
|
184
184
|
* };
|
|
185
185
|
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
186
|
-
* await api.user.document.
|
|
186
|
+
* await api.user.document.add(params, session);
|
|
187
187
|
*/
|
|
188
188
|
async add(params, session) {
|
|
189
189
|
const self = this;
|
|
@@ -318,7 +318,6 @@ class Documents {
|
|
|
318
318
|
} catch (ex) {
|
|
319
319
|
throw ex;
|
|
320
320
|
}
|
|
321
|
-
|
|
322
321
|
}
|
|
323
322
|
|
|
324
323
|
/**
|
|
@@ -441,9 +440,11 @@ class Documents {
|
|
|
441
440
|
* docAreaId: '5df7f19618430c89a41a19d2',
|
|
442
441
|
* fileName: 'Foto',
|
|
443
442
|
* type: 'image/png'
|
|
443
|
+
* orgId: '5df7f19618430c89a41a19f8'
|
|
444
444
|
* };
|
|
445
445
|
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
446
|
-
*
|
|
446
|
+
* // each doc: { docId, name, areaId, type, signedUrl }
|
|
447
|
+
* const { docs } = await api.user.document.signedUrl(params, session);
|
|
447
448
|
*
|
|
448
449
|
* @example
|
|
449
450
|
*
|
|
@@ -497,6 +498,80 @@ class Documents {
|
|
|
497
498
|
}
|
|
498
499
|
}
|
|
499
500
|
|
|
501
|
+
/**
|
|
502
|
+
*
|
|
503
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
504
|
+
* @description Request signed url url to put or get
|
|
505
|
+
* @param {object} params Params to request signed url
|
|
506
|
+
* @param {array} params.docs the list of documents to get the signed urls
|
|
507
|
+
* @param {string} params.docs.docId Document id
|
|
508
|
+
* @param {string} params.docs.name File name
|
|
509
|
+
* @param {string} params.docs.areaId docAreaId of the document
|
|
510
|
+
* @param {string} params.docs.type mimeType image/png image/jpg others
|
|
511
|
+
* @param {string} params.docs.document Name document to request if method type is get
|
|
512
|
+
* @param {string} params.methodType Method type HTTP get or put
|
|
513
|
+
* @param {string} params.orgId Organization id (_id database)
|
|
514
|
+
* @param {string} session Session, token JWT
|
|
515
|
+
* @return {Promise<object>} doc Returned document data with the signed url
|
|
516
|
+
* @return {string} doc.docId Document id
|
|
517
|
+
* @return {string} doc.name The name of the document, which is the fileName
|
|
518
|
+
* @return {string} doc.areaId docAreaId of the document
|
|
519
|
+
* @return {string} doc.type the document mimi type
|
|
520
|
+
* @return {string} doc.signedUrl the signed URL to upload
|
|
521
|
+
* @public
|
|
522
|
+
* @async
|
|
523
|
+
* @example
|
|
524
|
+
*
|
|
525
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
526
|
+
* const api = new API();
|
|
527
|
+
* const params - {
|
|
528
|
+
* methodType: 'put',
|
|
529
|
+
* orgId: '5df7f19618430c89a41a19f8'
|
|
530
|
+
* docs: [
|
|
531
|
+
* {
|
|
532
|
+
* docId: '5dadd01dc4af3941d42f8c5c',
|
|
533
|
+
* areaId: '5df7f19618430c89a41a19d2',
|
|
534
|
+
* name: 'Foto.png',
|
|
535
|
+
* type: 'image/png'
|
|
536
|
+
* }
|
|
537
|
+
* ]
|
|
538
|
+
* };
|
|
539
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
540
|
+
* // each doc: { docId, name, areaId, type, signedUrl }
|
|
541
|
+
* const { docs } = await api.user.document.signedUrls(params, session);
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
*
|
|
545
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
546
|
+
* const api = new API();
|
|
547
|
+
* const params - {
|
|
548
|
+
* methodType: 'get',
|
|
549
|
+
* docs: [
|
|
550
|
+
* { document: 'pinkandthebrain/5df7f19618430c89a41a19d2/5dadd01dc4af3941d42f8c5c/9dadd01dc4af3941d42f6dd4.pdf' }
|
|
551
|
+
* ],
|
|
552
|
+
* };
|
|
553
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
554
|
+
* const base64Data = await api.user.document.signedUrls(params, session);
|
|
555
|
+
*/
|
|
556
|
+
async signedUrls(params, session) {
|
|
557
|
+
const self = this;
|
|
558
|
+
|
|
559
|
+
try {
|
|
560
|
+
Joi.assert(params, Joi.object().required());
|
|
561
|
+
Joi.assert(params.docs, Joi.array().required());
|
|
562
|
+
Joi.assert(params.orgId, Joi.string().required());
|
|
563
|
+
Joi.assert(session, Joi.string().required());
|
|
564
|
+
|
|
565
|
+
const {orgId, methodType = 'put', docs = []} = params;
|
|
566
|
+
const apiCall = self._client
|
|
567
|
+
.post(`/organizations/${orgId}/documents/getDocumentSignedUrl/${methodType}`, { docs }, self._setHeader(session));
|
|
568
|
+
|
|
569
|
+
return self._returnData(await apiCall);
|
|
570
|
+
} catch (ex) {
|
|
571
|
+
throw ex;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
500
575
|
/**
|
|
501
576
|
* Uploads the file
|
|
502
577
|
* @param {object} params Params to upload document
|
package/dist/bundle.cjs
CHANGED
|
@@ -735,7 +735,7 @@ class Documents {
|
|
|
735
735
|
* orgId: '5df7f19618430c89a41a19d2',
|
|
736
736
|
* };
|
|
737
737
|
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
738
|
-
* await api.user.document.
|
|
738
|
+
* await api.user.document.add(params, session);
|
|
739
739
|
*/
|
|
740
740
|
async add(params, session) {
|
|
741
741
|
const self = this;
|
|
@@ -870,7 +870,6 @@ class Documents {
|
|
|
870
870
|
} catch (ex) {
|
|
871
871
|
throw ex;
|
|
872
872
|
}
|
|
873
|
-
|
|
874
873
|
}
|
|
875
874
|
|
|
876
875
|
/**
|
|
@@ -993,9 +992,11 @@ class Documents {
|
|
|
993
992
|
* docAreaId: '5df7f19618430c89a41a19d2',
|
|
994
993
|
* fileName: 'Foto',
|
|
995
994
|
* type: 'image/png'
|
|
995
|
+
* orgId: '5df7f19618430c89a41a19f8'
|
|
996
996
|
* };
|
|
997
997
|
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
998
|
-
*
|
|
998
|
+
* // each doc: { docId, name, areaId, type, signedUrl }
|
|
999
|
+
* const { docs } = await api.user.document.signedUrl(params, session);
|
|
999
1000
|
*
|
|
1000
1001
|
* @example
|
|
1001
1002
|
*
|
|
@@ -1049,6 +1050,80 @@ class Documents {
|
|
|
1049
1050
|
}
|
|
1050
1051
|
}
|
|
1051
1052
|
|
|
1053
|
+
/**
|
|
1054
|
+
*
|
|
1055
|
+
* @author CloudBrasil <abernardo.br@gmail.com>
|
|
1056
|
+
* @description Request signed url url to put or get
|
|
1057
|
+
* @param {object} params Params to request signed url
|
|
1058
|
+
* @param {array} params.docs the list of documents to get the signed urls
|
|
1059
|
+
* @param {string} params.docs.docId Document id
|
|
1060
|
+
* @param {string} params.docs.name File name
|
|
1061
|
+
* @param {string} params.docs.areaId docAreaId of the document
|
|
1062
|
+
* @param {string} params.docs.type mimeType image/png image/jpg others
|
|
1063
|
+
* @param {string} params.docs.document Name document to request if method type is get
|
|
1064
|
+
* @param {string} params.methodType Method type HTTP get or put
|
|
1065
|
+
* @param {string} params.orgId Organization id (_id database)
|
|
1066
|
+
* @param {string} session Session, token JWT
|
|
1067
|
+
* @return {Promise<object>} doc Returned document data with the signed url
|
|
1068
|
+
* @return {string} doc.docId Document id
|
|
1069
|
+
* @return {string} doc.name The name of the document, which is the fileName
|
|
1070
|
+
* @return {string} doc.areaId docAreaId of the document
|
|
1071
|
+
* @return {string} doc.type the document mimi type
|
|
1072
|
+
* @return {string} doc.signedUrl the signed URL to upload
|
|
1073
|
+
* @public
|
|
1074
|
+
* @async
|
|
1075
|
+
* @example
|
|
1076
|
+
*
|
|
1077
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
1078
|
+
* const api = new API();
|
|
1079
|
+
* const params - {
|
|
1080
|
+
* methodType: 'put',
|
|
1081
|
+
* orgId: '5df7f19618430c89a41a19f8'
|
|
1082
|
+
* docs: [
|
|
1083
|
+
* {
|
|
1084
|
+
* docId: '5dadd01dc4af3941d42f8c5c',
|
|
1085
|
+
* areaId: '5df7f19618430c89a41a19d2',
|
|
1086
|
+
* name: 'Foto.png',
|
|
1087
|
+
* type: 'image/png'
|
|
1088
|
+
* }
|
|
1089
|
+
* ]
|
|
1090
|
+
* };
|
|
1091
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
1092
|
+
* // each doc: { docId, name, areaId, type, signedUrl }
|
|
1093
|
+
* const { docs } = await api.user.document.signedUrls(params, session);
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
*
|
|
1097
|
+
* const API = require('@docbrasil/api-systemmanager');
|
|
1098
|
+
* const api = new API();
|
|
1099
|
+
* const params - {
|
|
1100
|
+
* methodType: 'get',
|
|
1101
|
+
* docs: [
|
|
1102
|
+
* { document: 'pinkandthebrain/5df7f19618430c89a41a19d2/5dadd01dc4af3941d42f8c5c/9dadd01dc4af3941d42f6dd4.pdf' }
|
|
1103
|
+
* ],
|
|
1104
|
+
* };
|
|
1105
|
+
* const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
|
|
1106
|
+
* const base64Data = await api.user.document.signedUrls(params, session);
|
|
1107
|
+
*/
|
|
1108
|
+
async signedUrls(params, session) {
|
|
1109
|
+
const self = this;
|
|
1110
|
+
|
|
1111
|
+
try {
|
|
1112
|
+
Joi__default["default"].assert(params, Joi__default["default"].object().required());
|
|
1113
|
+
Joi__default["default"].assert(params.docs, Joi__default["default"].array().required());
|
|
1114
|
+
Joi__default["default"].assert(params.orgId, Joi__default["default"].string().required());
|
|
1115
|
+
Joi__default["default"].assert(session, Joi__default["default"].string().required());
|
|
1116
|
+
|
|
1117
|
+
const {orgId, methodType = 'put', docs = []} = params;
|
|
1118
|
+
const apiCall = self._client
|
|
1119
|
+
.post(`/organizations/${orgId}/documents/getDocumentSignedUrl/${methodType}`, { docs }, self._setHeader(session));
|
|
1120
|
+
|
|
1121
|
+
return self._returnData(await apiCall);
|
|
1122
|
+
} catch (ex) {
|
|
1123
|
+
throw ex;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1052
1127
|
/**
|
|
1053
1128
|
* Uploads the file
|
|
1054
1129
|
* @param {object} params Params to upload document
|