vtlab-generic-functions 1.0.39 → 1.0.41

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.
@@ -57,14 +57,24 @@ module.exports = class Lambda {
57
57
  }
58
58
 
59
59
  recoverFullPayload = async () => {
60
- if (this.event?.s3PayloadPath) {
61
- let contentResponse = await this.s3.download(this.event.s3PayloadPath);
60
+ if (this.event?.s3PayloadPath || this.event?.payloadS3Key) {
61
+ let contentResponse = await this.s3.download(this.event.s3PayloadPath || this.event.payloadS3Key);
62
62
  this.jobs = JSON.parse(contentResponse.Body.toString());
63
63
  } else {
64
64
  this.jobs = this.event?.payload || [];
65
65
  }
66
66
  };
67
67
 
68
+ initialize = async () => {
69
+ try {
70
+ if(this.event?.s3PayloadPath || this.event?.payloadS3Key) {
71
+ await this.recoverFullPayload();
72
+ }
73
+ } catch (error) {
74
+ throw error;
75
+ }
76
+ };
77
+
68
78
  s3 = {
69
79
  upload: async (data, path, options = {}) => {
70
80
  return await s3bucket.uploadToS3(path, data, {
@@ -265,7 +275,18 @@ module.exports = class Lambda {
265
275
  return objToReturn;
266
276
  };
267
277
 
268
- endSuccess = () => {
278
+ uploadResultToS3 = async () => {
279
+ return await this.s3.upload(Buffer.from(utils.dataToString(this.results, "data").res), `tmp/results/${this.carrier}-${new Date().getTime()}.json`);
280
+ };
281
+ endSuccess = async () => {
282
+ //check if the response is bigger than 6291400 bytes
283
+ if(Buffer.byteLength(utils.dataToString(this.results, "data").res) > 6291400) {
284
+ return {
285
+ isBase64Encoded: false, statusCode: 200, body: utils.dataToString({
286
+ pathS3Result: (await this.uploadResultToS3())
287
+ }, "data").res,
288
+ };
289
+ }
269
290
  return {
270
291
  isBase64Encoded: false, statusCode: 200, body: utils.dataToString(this.results, "data").res,
271
292
  };
@@ -282,4 +303,4 @@ module.exports = class Lambda {
282
303
  const encodedToken = Buffer.from(token).toString("base64");
283
304
  return encodedToken;
284
305
  };
285
- };
306
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtlab-generic-functions",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "scripts": {
5
5
  "test": "jest"
6
6
  },
package/soap/index.js CHANGED
@@ -26,7 +26,7 @@ var xml2js = require('xml2js');
26
26
  * }
27
27
  * @throw error: If validate method fails.
28
28
  */
29
- const sendSoapRequest = async ({url, headers, xml, timeout=3000 }) => {
29
+ const sendSoapRequest = async ({url, headers, xml, timeout=60000 }) => {
30
30
  try{
31
31
  let {response} = await soapRequest({ url: url, headers: headers, xml: xml, timeout});
32
32
  return response; //{ headers, body, statusCode }