@docbrasil/api-systemmanager 1.0.70 → 1.0.72
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 +95 -7
- package/dist/bundle.cjs +94 -6
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +319 -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,12 +498,87 @@ 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
|
|
503
578
|
* @param {buffer} params.content The content of the file (Buffer)
|
|
504
579
|
* @param {string} params.signedUrl The signed URL
|
|
505
580
|
* @param {string} params.type The file mime type
|
|
581
|
+
* @param {string} params.onUploadProgress A callback for the upload progress. It will return a progressEvent.
|
|
506
582
|
* @return {Promise<boolean>} True if success
|
|
507
583
|
*
|
|
508
584
|
* @public
|
|
@@ -519,8 +595,13 @@ class Documents {
|
|
|
519
595
|
* type: 'application/pdf'
|
|
520
596
|
* };
|
|
521
597
|
* const retData = await api.user.document.uploadSignedDocument(params);
|
|
598
|
+
*
|
|
599
|
+
* onUploadProgress return the progressEvent
|
|
600
|
+
* - lengthComputable: A Boolean that indicates whether or not the total number of bytes is known.
|
|
601
|
+
* - loaded: The number of bytes of the file that have been uploaded.
|
|
602
|
+
* - total: The total number of bytes in the file.
|
|
522
603
|
*/
|
|
523
|
-
async uploadSignedDocument(params) {
|
|
604
|
+
async uploadSignedDocument(params= {}) {
|
|
524
605
|
const { content, signedUrl, type } = params;
|
|
525
606
|
Joi.assert(params, Joi.object().required());
|
|
526
607
|
Joi.assert(params.content, Joi.required());
|
|
@@ -528,14 +609,21 @@ class Documents {
|
|
|
528
609
|
Joi.assert(params.type, Joi.string().required());
|
|
529
610
|
|
|
530
611
|
const self = this;
|
|
531
|
-
const
|
|
612
|
+
const reqOpts = {
|
|
532
613
|
headers: {
|
|
533
614
|
'Content-Type': type
|
|
534
615
|
}
|
|
535
616
|
};
|
|
617
|
+
|
|
618
|
+
const onUploadProgress = params.onUploadProgress;
|
|
619
|
+
|
|
620
|
+
if(onUploadProgress) {
|
|
621
|
+
reqOpts.onUploadProgress = onUploadProgress;
|
|
622
|
+
}
|
|
623
|
+
|
|
536
624
|
const apiCall = self._client
|
|
537
|
-
.put(signedUrl, content,
|
|
538
|
-
|
|
625
|
+
.put(signedUrl, content, reqOpts);
|
|
626
|
+
self._returnData(await apiCall);
|
|
539
627
|
return true;
|
|
540
628
|
}
|
|
541
629
|
|
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,12 +1050,87 @@ 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
|
|
1055
1130
|
* @param {buffer} params.content The content of the file (Buffer)
|
|
1056
1131
|
* @param {string} params.signedUrl The signed URL
|
|
1057
1132
|
* @param {string} params.type The file mime type
|
|
1133
|
+
* @param {string} params.onUploadProgress A callback for the upload progress. It will return a progressEvent.
|
|
1058
1134
|
* @return {Promise<boolean>} True if success
|
|
1059
1135
|
*
|
|
1060
1136
|
* @public
|
|
@@ -1071,8 +1147,13 @@ class Documents {
|
|
|
1071
1147
|
* type: 'application/pdf'
|
|
1072
1148
|
* };
|
|
1073
1149
|
* const retData = await api.user.document.uploadSignedDocument(params);
|
|
1150
|
+
*
|
|
1151
|
+
* onUploadProgress return the progressEvent
|
|
1152
|
+
* - lengthComputable: A Boolean that indicates whether or not the total number of bytes is known.
|
|
1153
|
+
* - loaded: The number of bytes of the file that have been uploaded.
|
|
1154
|
+
* - total: The total number of bytes in the file.
|
|
1074
1155
|
*/
|
|
1075
|
-
async uploadSignedDocument(params) {
|
|
1156
|
+
async uploadSignedDocument(params= {}) {
|
|
1076
1157
|
const { content, signedUrl, type } = params;
|
|
1077
1158
|
Joi__default["default"].assert(params, Joi__default["default"].object().required());
|
|
1078
1159
|
Joi__default["default"].assert(params.content, Joi__default["default"].required());
|
|
@@ -1080,13 +1161,20 @@ class Documents {
|
|
|
1080
1161
|
Joi__default["default"].assert(params.type, Joi__default["default"].string().required());
|
|
1081
1162
|
|
|
1082
1163
|
const self = this;
|
|
1083
|
-
const
|
|
1164
|
+
const reqOpts = {
|
|
1084
1165
|
headers: {
|
|
1085
1166
|
'Content-Type': type
|
|
1086
1167
|
}
|
|
1087
1168
|
};
|
|
1169
|
+
|
|
1170
|
+
const onUploadProgress = params.onUploadProgress;
|
|
1171
|
+
|
|
1172
|
+
if(onUploadProgress) {
|
|
1173
|
+
reqOpts.onUploadProgress = onUploadProgress;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1088
1176
|
const apiCall = self._client
|
|
1089
|
-
.put(signedUrl, content,
|
|
1177
|
+
.put(signedUrl, content, reqOpts);
|
|
1090
1178
|
self._returnData(await apiCall);
|
|
1091
1179
|
return true;
|
|
1092
1180
|
}
|