@docbrasil/api-systemmanager 1.0.100 → 1.0.102

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/external.js CHANGED
@@ -39,10 +39,10 @@ class External {
39
39
  * @return {object} header with new session
40
40
  * @private
41
41
  */
42
- _setHeader(session) {
42
+ _setHeader(responseToken) {
43
43
  return {
44
44
  headers: {
45
- authorization: session,
45
+ responseToken,
46
46
  }
47
47
  };
48
48
  }
@@ -65,7 +65,7 @@ class External {
65
65
  * const API = require('@docbrasil/api-systemmanager');
66
66
  * const api = new API();
67
67
  * const params = {
68
- * id: 'cloundbrasil'
68
+ * id: '611e679741cc63168c26d7ee'
69
69
  * };
70
70
  * const retForm = await api.external.context(params);
71
71
  */
@@ -86,6 +86,44 @@ class External {
86
86
  }
87
87
  }
88
88
 
89
+ /**
90
+ * @author CloudBrasil <abernardo.br@gmail.com>
91
+ * @description Get an upload signed url, so it will be possible to upload documents temporarily during the use of the external form
92
+ * @param {string} mime the mime type of the document
93
+ * @param {string} responseToken a legal responseToken
94
+ * @returns {Promise<object>} doc
95
+ * @returns {string} doc.mime the original mime type of the document
96
+ * @returns {string} doc.signedUrl the signed url to upload the document
97
+ * @returns {string} doc.filename the filename of the uploaded file
98
+ * @returns {string} doc.extension the extension of the filename, obtained from the mime type
99
+ * @public
100
+ * @async
101
+ * @example
102
+ *
103
+ * const API = require('@docbrasil/api-systemmanager');
104
+ * const api = new API();
105
+ * const responseToken = '...';
106
+ * const doc = {
107
+ * mime: 'application/pdf'
108
+ * };
109
+ * const retDoc = await api.external.getUploadDocumentSignedUrl(doc, responseToken);
110
+ */
111
+ async getUploadDocumentSignedUrl(mime, responseToken) {
112
+ const self = this;
113
+
114
+ try {
115
+ Joi.assert(mime, Joi.string().required().error(new Error('mime type is required')));
116
+ Joi.assert(responseToken, Joi.string().required().error(new Error('responseToken is required')));
117
+
118
+ const apiCall = self._client
119
+ .get(`/external/forms/upload/signedurl?mime=${doc.mime}`, self._setHeader(responseToken));
120
+
121
+ return self._returnData(await apiCall);
122
+ } catch (ex) {
123
+ throw ex;
124
+ }
125
+ }
126
+
89
127
  }
90
128
 
91
129
  export default External;
package/dist/bundle.cjs CHANGED
@@ -11615,10 +11615,10 @@ class External {
11615
11615
  * @return {object} header with new session
11616
11616
  * @private
11617
11617
  */
11618
- _setHeader(session) {
11618
+ _setHeader(responseToken) {
11619
11619
  return {
11620
11620
  headers: {
11621
- authorization: session,
11621
+ responseToken,
11622
11622
  }
11623
11623
  };
11624
11624
  }
@@ -11641,7 +11641,7 @@ class External {
11641
11641
  * const API = require('@docbrasil/api-systemmanager');
11642
11642
  * const api = new API();
11643
11643
  * const params = {
11644
- * id: 'cloundbrasil'
11644
+ * id: '611e679741cc63168c26d7ee'
11645
11645
  * };
11646
11646
  * const retForm = await api.external.context(params);
11647
11647
  */
@@ -11662,6 +11662,44 @@ class External {
11662
11662
  }
11663
11663
  }
11664
11664
 
11665
+ /**
11666
+ * @author CloudBrasil <abernardo.br@gmail.com>
11667
+ * @description Get an upload signed url, so it will be possible to upload documents temporarily during the use of the external form
11668
+ * @param {string} mime the mime type of the document
11669
+ * @param {string} responseToken a legal responseToken
11670
+ * @returns {Promise<object>} doc
11671
+ * @returns {string} doc.mime the original mime type of the document
11672
+ * @returns {string} doc.signedUrl the signed url to upload the document
11673
+ * @returns {string} doc.filename the filename of the uploaded file
11674
+ * @returns {string} doc.extension the extension of the filename, obtained from the mime type
11675
+ * @public
11676
+ * @async
11677
+ * @example
11678
+ *
11679
+ * const API = require('@docbrasil/api-systemmanager');
11680
+ * const api = new API();
11681
+ * const responseToken = '...';
11682
+ * const doc = {
11683
+ * mime: 'application/pdf'
11684
+ * };
11685
+ * const retDoc = await api.external.getUploadDocumentSignedUrl(doc, responseToken);
11686
+ */
11687
+ async getUploadDocumentSignedUrl(mime, responseToken) {
11688
+ const self = this;
11689
+
11690
+ try {
11691
+ Joi__default["default"].assert(mime, Joi__default["default"].string().required().error(new Error('mime type is required')));
11692
+ Joi__default["default"].assert(responseToken, Joi__default["default"].string().required().error(new Error('responseToken is required')));
11693
+
11694
+ const apiCall = self._client
11695
+ .get(`/external/forms/upload/signedurl?mime=${doc.mime}`, self._setHeader(responseToken));
11696
+
11697
+ return self._returnData(await apiCall);
11698
+ } catch (ex) {
11699
+ throw ex;
11700
+ }
11701
+ }
11702
+
11665
11703
  }
11666
11704
 
11667
11705
  /**