@docbrasil/api-systemmanager 1.0.104 → 1.0.106

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(responseToken) {
42
+ _setHeader(authorization) {
43
43
  return {
44
44
  headers: {
45
- responseToken,
45
+ authorization,
46
46
  }
47
47
  };
48
48
  }
@@ -55,8 +55,8 @@ class External {
55
55
  * @return {Promise<object>} data
56
56
  * @return {string} _id the id of the form
57
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.
58
+ * @return {string} authorization the unique token registered internally by the system for all the next calls to the external form APIs
59
+ * The authorization is unique and is ONLY valid for this session.
60
60
  * @return {array<object>} groups the form groups to render
61
61
  * @public
62
62
  * @async
@@ -90,7 +90,7 @@ class External {
90
90
  * @author CloudBrasil <abernardo.br@gmail.com>
91
91
  * @description Get an upload signed url, so it will be possible to upload documents temporarily during the use of the external form
92
92
  * @param {string} mime the mime type of the document
93
- * @param {string} responseToken a legal responseToken
93
+ * @param {string} authorization a legal authorization
94
94
  * @returns {Promise<object>} doc
95
95
  * @returns {string} doc.mime the original mime type of the document
96
96
  * @returns {string} doc.signedUrl the signed url to upload the document
@@ -102,21 +102,67 @@ class External {
102
102
  *
103
103
  * const API = require('@docbrasil/api-systemmanager');
104
104
  * const api = new API();
105
- * const responseToken = '...';
105
+ * const authorization = '...';
106
106
  * const doc = {
107
107
  * mime: 'application/pdf'
108
108
  * };
109
- * const retDoc = await api.external.getUploadDocumentSignedUrl(doc, responseToken);
109
+ * const retDoc = await api.external.getUploadDocumentSignedUrl(doc, authorization);
110
110
  */
111
- async getUploadDocumentSignedUrl(mime, responseToken) {
111
+ async getUploadDocumentSignedUrl(mime, authorization) {
112
112
  const self = this;
113
113
 
114
114
  try {
115
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')));
116
+ Joi.assert(authorization, Joi.string().required().error(new Error('authorization is required')));
117
117
 
118
118
  const apiCall = self._client
119
- .get(`/external/forms/upload/signedurl?mime=${encodeURIComponent(mime)}`, self._setHeader(responseToken));
119
+ .get(`/external/forms/upload/signedurl?mime=${encodeURIComponent(mime)}`, self._setHeader(authorization));
120
+
121
+ return self._returnData(await apiCall);
122
+ } catch (ex) {
123
+ throw ex;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * @author CloudBrasil <abernardo.br@gmail.com>
129
+ * @description Handles the execution of an external form
130
+ * @param {string} authorization a legal authorization
131
+ * @param {object} params the parameters to handle the execution of an external form
132
+ * @param {array<object>} params.payload the payload of the external form. It should represent the form groups of the external form
133
+ * @param {string} params.payload.name the name of the group
134
+ * @param {array<object>} params.payload.fields the fields that belong to each group
135
+ * @param {*|{}} params.payload.fields.value besides all the data inside a field, it should have the value of the the field
136
+ * @returns {Promise<boolean>} true|false if success
137
+ * @public
138
+ * @async
139
+ * @example
140
+ *
141
+ * const API = require('@docbrasil/api-systemmanager');
142
+ * const api = new API();
143
+ * const authorization = '...';
144
+ * const params = {
145
+ * payload: [
146
+ * {
147
+ * name: 'My Group One',
148
+ * fields: [
149
+ * {}
150
+ * ]
151
+ * }
152
+ * ]
153
+ * };
154
+ * const success = await api.external.handle(params, authorization);
155
+ */
156
+ async handle(params, authorization) {
157
+ const self = this;
158
+
159
+ try {
160
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
161
+ Joi.assert(params.payload, Joi.array().required().error(new Error('form payload is required')));
162
+ Joi.assert(authorization, Joi.string().required().error(new Error('authorization is required')));
163
+
164
+ const apiCall = self._client
165
+ .put('/external/forms', params, self._setHeader(authorization));
120
166
 
121
167
  return self._returnData(await apiCall);
122
168
  } catch (ex) {
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(responseToken) {
11618
+ _setHeader(authorization) {
11619
11619
  return {
11620
11620
  headers: {
11621
- responseToken,
11621
+ authorization,
11622
11622
  }
11623
11623
  };
11624
11624
  }
@@ -11631,8 +11631,8 @@ class External {
11631
11631
  * @return {Promise<object>} data
11632
11632
  * @return {string} _id the id of the form
11633
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.
11634
+ * @return {string} authorization the unique token registered internally by the system for all the next calls to the external form APIs
11635
+ * The authorization is unique and is ONLY valid for this session.
11636
11636
  * @return {array<object>} groups the form groups to render
11637
11637
  * @public
11638
11638
  * @async
@@ -11666,7 +11666,7 @@ class External {
11666
11666
  * @author CloudBrasil <abernardo.br@gmail.com>
11667
11667
  * @description Get an upload signed url, so it will be possible to upload documents temporarily during the use of the external form
11668
11668
  * @param {string} mime the mime type of the document
11669
- * @param {string} responseToken a legal responseToken
11669
+ * @param {string} authorization a legal authorization
11670
11670
  * @returns {Promise<object>} doc
11671
11671
  * @returns {string} doc.mime the original mime type of the document
11672
11672
  * @returns {string} doc.signedUrl the signed url to upload the document
@@ -11678,21 +11678,67 @@ class External {
11678
11678
  *
11679
11679
  * const API = require('@docbrasil/api-systemmanager');
11680
11680
  * const api = new API();
11681
- * const responseToken = '...';
11681
+ * const authorization = '...';
11682
11682
  * const doc = {
11683
11683
  * mime: 'application/pdf'
11684
11684
  * };
11685
- * const retDoc = await api.external.getUploadDocumentSignedUrl(doc, responseToken);
11685
+ * const retDoc = await api.external.getUploadDocumentSignedUrl(doc, authorization);
11686
11686
  */
11687
- async getUploadDocumentSignedUrl(mime, responseToken) {
11687
+ async getUploadDocumentSignedUrl(mime, authorization) {
11688
11688
  const self = this;
11689
11689
 
11690
11690
  try {
11691
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')));
11692
+ Joi__default["default"].assert(authorization, Joi__default["default"].string().required().error(new Error('authorization is required')));
11693
11693
 
11694
11694
  const apiCall = self._client
11695
- .get(`/external/forms/upload/signedurl?mime=${encodeURIComponent(mime)}`, self._setHeader(responseToken));
11695
+ .get(`/external/forms/upload/signedurl?mime=${encodeURIComponent(mime)}`, self._setHeader(authorization));
11696
+
11697
+ return self._returnData(await apiCall);
11698
+ } catch (ex) {
11699
+ throw ex;
11700
+ }
11701
+ }
11702
+
11703
+ /**
11704
+ * @author CloudBrasil <abernardo.br@gmail.com>
11705
+ * @description Handles the execution of an external form
11706
+ * @param {string} authorization a legal authorization
11707
+ * @param {object} params the parameters to handle the execution of an external form
11708
+ * @param {array<object>} params.payload the payload of the external form. It should represent the form groups of the external form
11709
+ * @param {string} params.payload.name the name of the group
11710
+ * @param {array<object>} params.payload.fields the fields that belong to each group
11711
+ * @param {*|{}} params.payload.fields.value besides all the data inside a field, it should have the value of the the field
11712
+ * @returns {Promise<boolean>} true|false if success
11713
+ * @public
11714
+ * @async
11715
+ * @example
11716
+ *
11717
+ * const API = require('@docbrasil/api-systemmanager');
11718
+ * const api = new API();
11719
+ * const authorization = '...';
11720
+ * const params = {
11721
+ * payload: [
11722
+ * {
11723
+ * name: 'My Group One',
11724
+ * fields: [
11725
+ * {}
11726
+ * ]
11727
+ * }
11728
+ * ]
11729
+ * };
11730
+ * const success = await api.external.handle(params, authorization);
11731
+ */
11732
+ async handle(params, authorization) {
11733
+ const self = this;
11734
+
11735
+ try {
11736
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
11737
+ Joi__default["default"].assert(params.payload, Joi__default["default"].array().required().error(new Error('form payload is required')));
11738
+ Joi__default["default"].assert(authorization, Joi__default["default"].string().required().error(new Error('authorization is required')));
11739
+
11740
+ const apiCall = self._client
11741
+ .put('/external/forms', params, self._setHeader(authorization));
11696
11742
 
11697
11743
  return self._returnData(await apiCall);
11698
11744
  } catch (ex) {