@docbrasil/api-systemmanager 1.0.99 → 1.0.101

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
  }
@@ -52,7 +52,12 @@ class External {
52
52
  * @description Create new document
53
53
  * @param {object} params Object for add new document
54
54
  * @param {string} params.id Organization form id
55
- * @return {Promise<object>}
55
+ * @return {Promise<object>} data
56
+ * @return {string} _id the id of the form
57
+ * @return {string} orgId the organization id of the form
58
+ * @return {string} responseToken the unique token registered internally by the system for all the next calls to the external form APIs
59
+ * The responseToken is unique and is ONLY valid for this session.
60
+ * @return {array<object>} groups the form groups to render
56
61
  * @public
57
62
  * @async
58
63
  * @example
@@ -60,7 +65,7 @@ class External {
60
65
  * const API = require('@docbrasil/api-systemmanager');
61
66
  * const api = new API();
62
67
  * const params = {
63
- * id: 'cloundbrasil'
68
+ * id: '611e679741cc63168c26d7ee'
64
69
  * };
65
70
  * const retForm = await api.external.context(params);
66
71
  */
@@ -81,6 +86,46 @@ class External {
81
86
  }
82
87
  }
83
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 {object} doc the document we are doing the upload to the temporary area
93
+ * @param {string} doc.mime the mime type of the document
94
+ * @param {string} responseToken a legal responseToken
95
+ * @returns {Promise<object>} doc
96
+ * @returns {string} doc.mime the original mime type of the document
97
+ * @returns {string} doc.signedUrl the signed url to upload the document
98
+ * @returns {string} doc.filename the filename of the uploaded file
99
+ * @returns {string} doc.extension the extension of the filename, obtained from the mime type
100
+ * @public
101
+ * @async
102
+ * @example
103
+ *
104
+ * const API = require('@docbrasil/api-systemmanager');
105
+ * const api = new API();
106
+ * const responseToken = '...';
107
+ * const doc = {
108
+ * mime: 'application/pdf'
109
+ * };
110
+ * const retDoc = await api.external.getUploadDocumentSignedUrl(doc, responseToken);
111
+ */
112
+ async getUploadDocumentSignedUrl(doc, responseToken) {
113
+ const self = this;
114
+
115
+ try {
116
+ Joi.assert(doc, Joi.object().required().error(new Error('doc is required')));
117
+ Joi.assert(doc.mime, Joi.string().required().error(new Error('mime type is required')));
118
+ Joi.assert(responseToken, Joi.string().required().error(new Error('responseToken is required')));
119
+
120
+ const apiCall = self._client
121
+ .post('/external/forms/upload/signedurl', { doc }, self._setHeader(responseToken));
122
+
123
+ return self._returnData(await apiCall);
124
+ } catch (ex) {
125
+ throw ex;
126
+ }
127
+ }
128
+
84
129
  }
85
130
 
86
131
  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
  }
@@ -11628,7 +11628,12 @@ class External {
11628
11628
  * @description Create new document
11629
11629
  * @param {object} params Object for add new document
11630
11630
  * @param {string} params.id Organization form id
11631
- * @return {Promise<object>}
11631
+ * @return {Promise<object>} data
11632
+ * @return {string} _id the id of the form
11633
+ * @return {string} orgId the organization id of the form
11634
+ * @return {string} responseToken the unique token registered internally by the system for all the next calls to the external form APIs
11635
+ * The responseToken is unique and is ONLY valid for this session.
11636
+ * @return {array<object>} groups the form groups to render
11632
11637
  * @public
11633
11638
  * @async
11634
11639
  * @example
@@ -11636,7 +11641,7 @@ class External {
11636
11641
  * const API = require('@docbrasil/api-systemmanager');
11637
11642
  * const api = new API();
11638
11643
  * const params = {
11639
- * id: 'cloundbrasil'
11644
+ * id: '611e679741cc63168c26d7ee'
11640
11645
  * };
11641
11646
  * const retForm = await api.external.context(params);
11642
11647
  */
@@ -11657,6 +11662,46 @@ class External {
11657
11662
  }
11658
11663
  }
11659
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 {object} doc the document we are doing the upload to the temporary area
11669
+ * @param {string} doc.mime the mime type of the document
11670
+ * @param {string} responseToken a legal responseToken
11671
+ * @returns {Promise<object>} doc
11672
+ * @returns {string} doc.mime the original mime type of the document
11673
+ * @returns {string} doc.signedUrl the signed url to upload the document
11674
+ * @returns {string} doc.filename the filename of the uploaded file
11675
+ * @returns {string} doc.extension the extension of the filename, obtained from the mime type
11676
+ * @public
11677
+ * @async
11678
+ * @example
11679
+ *
11680
+ * const API = require('@docbrasil/api-systemmanager');
11681
+ * const api = new API();
11682
+ * const responseToken = '...';
11683
+ * const doc = {
11684
+ * mime: 'application/pdf'
11685
+ * };
11686
+ * const retDoc = await api.external.getUploadDocumentSignedUrl(doc, responseToken);
11687
+ */
11688
+ async getUploadDocumentSignedUrl(doc, responseToken) {
11689
+ const self = this;
11690
+
11691
+ try {
11692
+ Joi__default["default"].assert(doc, Joi__default["default"].object().required().error(new Error('doc is required')));
11693
+ Joi__default["default"].assert(doc.mime, Joi__default["default"].string().required().error(new Error('mime type is required')));
11694
+ Joi__default["default"].assert(responseToken, Joi__default["default"].string().required().error(new Error('responseToken is required')));
11695
+
11696
+ const apiCall = self._client
11697
+ .post('/external/forms/upload/signedurl', { doc }, self._setHeader(responseToken));
11698
+
11699
+ return self._returnData(await apiCall);
11700
+ } catch (ex) {
11701
+ throw ex;
11702
+ }
11703
+ }
11704
+
11660
11705
  }
11661
11706
 
11662
11707
  /**