vtlab-generic-functions 1.0.37 → 1.0.39

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.
@@ -23,7 +23,7 @@ module.exports = class Lambda {
23
23
  totalError: 0, totalSuccess: 0, error: [], success: [],
24
24
  };
25
25
 
26
- constructor({carrier, event, DEBUG = false}) {
26
+ constructor({ carrier, event, DEBUG = false }) {
27
27
  this.DEBUG = false;
28
28
  this.carrier = carrier;
29
29
  if (event.body) {
@@ -68,7 +68,7 @@ module.exports = class Lambda {
68
68
  s3 = {
69
69
  upload: async (data, path, options = {}) => {
70
70
  return await s3bucket.uploadToS3(path, data, {
71
- ContentEncoding: options.contentEncoding || "base64", ContentType: options.ContentType || "image/png",
71
+ ContentEncoding: options.contentEncoding || "base64", ContentType: options.ContentType || "image/png",
72
72
  });
73
73
  }, download: async (path) => {
74
74
  return await s3bucket.downloadFileFromS3(path);
@@ -77,28 +77,37 @@ module.exports = class Lambda {
77
77
  http = {
78
78
  get: async (URL, params, headers = {}) => {
79
79
  return await axiosRequest.get(URL, {
80
- auth: {}, logId: this.logGroupName, headers: {...headers}, ...params
80
+ auth: {}, logId: this.logGroupName, headers: { ...headers }, ...params
81
81
  });
82
- }, delete: async (URL, params, headers) => {
82
+ },
83
+ delete: async (URL, params, headers) => {
83
84
  return await axiosRequest.deletion(URL, {
84
- auth: {}, logId: this.logGroupName, headers: {...headers}, ...params
85
+ auth: {}, logId: this.logGroupName, headers: { ...headers }, ...params
85
86
  });
86
- }, post: async (URL, params, headers) => {
87
+ },
88
+ post: async (URL, params, headers) => {
87
89
  return await axiosRequest.post(URL, {
88
- auth: {}, logId: this.logGroupName, headers: {...headers}, ...params,
90
+ auth: {}, logId: this.logGroupName, headers: { ...headers }, ...params,
89
91
  });
90
- }, put: async (URL, params, headers) => {
92
+ },
93
+ put: async (URL, params, headers) => {
91
94
  return await axiosRequest.put(URL, {
92
- auth: {}, logId: this.logGroupName, headers: {...headers}, ...params
95
+ auth: {}, logId: this.logGroupName, headers: { ...headers }, ...params
93
96
  });
94
- }, downloadFile: async (method, URL, params, s3Path) => {
97
+ },
98
+ patch: async (URL, params, headers) => {
99
+ return await axiosRequest.patch(URL, {
100
+ auth: {}, logId: this.logGroupName, headers: { ...headers }, ...params
101
+ });
102
+ },
103
+ downloadFile: async (method, URL, params, s3Path) => {
95
104
  let response = await axiosRequest[method](URL, {
96
- auth: {}, logId: this.logGroupName, headers: {}, config: {responseType: 'arraybuffer'}, ...params
105
+ auth: {}, logId: this.logGroupName, headers: {}, config: { responseType: 'arraybuffer' }, ...params
97
106
  });
98
107
  let buff = Buffer.from(response.data, "binary");
99
108
  let s3PathUploaded = await this.s3.upload(buff, s3Path);
100
109
  return s3PathUploaded;
101
- }, postForm: async (URL, {attachment, document}, _headers) => {
110
+ }, postForm: async (URL, { attachment, document }, _headers) => {
102
111
  const formData = new FormData();
103
112
  formData.append('document', JSON.stringify(document));
104
113
  formData.append('attachment', attachment, "document.pdf");
@@ -125,25 +134,25 @@ module.exports = class Lambda {
125
134
  await this.ftpConnection.connect(this.configFTP);
126
135
  this.logMessage(`Correctly Connected To FTP`, true);
127
136
  } catch (error) {
128
- throw {message: "Error from FTP"};
137
+ throw { message: "Error from FTP" };
129
138
  }
130
139
  }, listFolder: async (folderAndRegexp) => {
131
- if (!this.ftpConnection) throw {message: "No connection was stablished"};
140
+ if (!this.ftpConnection) throw { message: "No connection was stablished" };
132
141
  let files = await this.ftpConnection.list(folderAndRegexp);
133
- if (!files || files.length < 1) throw {message: "No files were found"};
142
+ if (!files || files.length < 1) throw { message: "No files were found" };
134
143
  this.logMessage(`Files Found: ${files.map((f) => f.name)}`);
135
144
  return files;
136
- }, download: async ({folder, file}) => {
137
- if (!this.ftpConnection) throw {message: "No connection was stablished"};
145
+ }, download: async ({ folder, file }) => {
146
+ if (!this.ftpConnection) throw { message: "No connection was stablished" };
138
147
  let downloadedFile = await promiseFTPWrapper.downloadFromFTP(this.ftpConnection, `${folder}${file}`);
139
148
  return downloadedFile;
140
- }, putFile: async ({path, file}) => {
149
+ }, putFile: async ({ path, file }) => {
141
150
  await promiseFTPWrapper.uploadFileToFTP(this.configFTP, file, path);
142
- }, downloadFiles: async ({folder, _files, removeFiles = false}) => {
151
+ }, downloadFiles: async ({ folder, _files, removeFiles = false }) => {
143
152
  const files = [..._files];
144
- if (!this.ftpConnection) throw {message: "No connection was stablished"};
153
+ if (!this.ftpConnection) throw { message: "No connection was stablished" };
145
154
  for (let i = 0; i < files.length; i++) {
146
- let file = await this.ftp.download({folder, file: files[i].name});
155
+ let file = await this.ftp.download({ folder, file: files[i].name });
147
156
  if (file) {
148
157
  files[i].file = file;
149
158
  if (removeFiles) await this.ftp.deleteFile(folder, files[i]);
@@ -153,7 +162,7 @@ module.exports = class Lambda {
153
162
  }, deleteFile: async (folder, file) => {
154
163
  await promiseFTPWrapper.deleteFileFromFTP(this.ftpConnection, `${folder}/${file}`);
155
164
  }, closeConnection: async () => {
156
- if (!this.ftpConnection) throw {message: "No connection was stablished"};
165
+ if (!this.ftpConnection) throw { message: "No connection was stablished" };
157
166
  this.ftpConnection.end();
158
167
  }, sortFiles: (filesList) => {
159
168
  return filesList.sort((a, b) => {
@@ -168,7 +177,7 @@ module.exports = class Lambda {
168
177
  return 0;
169
178
  });
170
179
  }, getJobMatchingFile: (file) => {
171
- if (!file) throw {message: "No file was sent"};
180
+ if (!file) throw { message: "No file was sent" };
172
181
  let jobFound = [...this.jobs].find((job) => {
173
182
  return String(file.name).includes(utils.getValueOrNull(job, "externalCarrier.trackingId"));
174
183
  });
@@ -189,11 +198,11 @@ module.exports = class Lambda {
189
198
  };
190
199
 
191
200
  logSendingToCarrier = async (payload) => {
192
- await this.logMessage(`Sending to ${this.carrier} ${utils.dataToString({...payload}, "data").res}`, true);
201
+ await this.logMessage(`Sending to ${this.carrier} ${utils.dataToString({ ...payload }, "data").res}`, true);
193
202
  };
194
203
 
195
204
  logReceivedFromCarrier = async (payload, status) => {
196
- await this.logMessage(`Received from ${this.carrier} (${status}) ${utils.dataToString({...payload}, "data").res}`, true);
205
+ await this.logMessage(`Received from ${this.carrier} (${status}) ${utils.dataToString({ ...payload }, "data").res}`, true);
197
206
  };
198
207
 
199
208
  addSuccessResult = (payload) => {
@@ -231,7 +240,7 @@ module.exports = class Lambda {
231
240
  }));
232
241
  };
233
242
 
234
- logFinishProcess = async ({error} = {}) => {
243
+ logFinishProcess = async ({ error } = {}) => {
235
244
  if (this.results.totalError || error) {
236
245
  error = error && error.message ? error.message : error;
237
246
  await this.logMessage("Finished Process with errors: " + (error || "") + " " + JSON.stringify(this.results));
@@ -241,16 +250,16 @@ module.exports = class Lambda {
241
250
  };
242
251
 
243
252
  validatePayload = () => {
244
- if (this.jobs.length < 1) throw {message: "No Jobs were sent"};
253
+ if (this.jobs.length < 1) throw { message: "No Jobs were sent" };
245
254
  };
246
255
 
247
256
  getJobsByTrackingId = () => {
248
257
  let objToReturn = {};
249
258
  this.jobs.forEach((job) => {
250
259
  let valueFound = utils.getValueOrNull(job, "externalCarrier.trackingId");
251
- if (valueFound) objToReturn[job._id] = {trackingId: valueFound};
260
+ if (valueFound) objToReturn[job._id] = { trackingId: valueFound };
252
261
  objToReturn[job._id].jobOwner = {
253
- account: {_id: job.jobOwner.account._id},
262
+ account: { _id: job.jobOwner.account._id },
254
263
  };
255
264
  });
256
265
  return objToReturn;
@@ -262,11 +271,11 @@ module.exports = class Lambda {
262
271
  };
263
272
  };
264
273
  endError = (e) => {
265
- let {code, res} = utils.dataToString(e);
274
+ let { code, res } = utils.dataToString(e);
266
275
  let body = {
267
276
  code, message: res, carrierCode: e.carrierCode, carrierMessage: e.carrierMessage,
268
277
  };
269
- return {isBase64Encoded: false, statusCode: code ? code : 417, body: res};
278
+ return { isBase64Encoded: false, statusCode: code ? code : 417, body: res };
270
279
  };
271
280
  getToken = () => {
272
281
  const token = `${this.auth.username}:${this.auth.password}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtlab-generic-functions",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "scripts": {
5
5
  "test": "jest"
6
6
  },
@@ -40,5 +40,8 @@
40
40
  "jest": "^29.7.0",
41
41
  "nodemailer-mock": "^2.0.3",
42
42
  "sinon": "^17.0.1"
43
+ },
44
+ "overrides": {
45
+ "@icetee/ftp": "1.0.8"
43
46
  }
44
47
  }