vtlab-generic-functions 1.0.33 → 1.0.34
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/customers/marketplace/bringg/auth.js +1 -1
- package/ftp/ftpClientClass.js +45 -1
- package/lambdaClass/index.js +2 -2
- package/package.json +1 -1
- package/utils/index.js +40 -0
|
@@ -47,7 +47,7 @@ const getAuthToken = async ({
|
|
|
47
47
|
} catch (err) {
|
|
48
48
|
let {res} = utils.dataToString(err);
|
|
49
49
|
await cloudwatch.putLogEvents(
|
|
50
|
-
logId + "
|
|
50
|
+
logId + "Finished BRINGG LOGIN Process with errors: " + res,
|
|
51
51
|
logGroupName
|
|
52
52
|
);
|
|
53
53
|
throw err;
|
package/ftp/ftpClientClass.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
const promiseFTP = require("promise-ftp");
|
|
3
3
|
const promiseSFTP = require("ssh2-sftp-client");
|
|
4
|
+
// For FTP, we need to create a temporary file and upload it
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
4
8
|
|
|
5
9
|
|
|
6
10
|
/**
|
|
@@ -241,8 +245,48 @@ class FTPClientV2 {
|
|
|
241
245
|
if (!this._isConnected) {
|
|
242
246
|
await this.connect(this._ftpCredentials);
|
|
243
247
|
}
|
|
244
|
-
|
|
248
|
+
|
|
249
|
+
// Check if source file exists
|
|
250
|
+
const fileExists = await this.isFileExists(ftpPathOrigin);
|
|
251
|
+
if (!fileExists) {
|
|
252
|
+
throw new Error(`Source file does not exist: ${ftpPathOrigin}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Download the file from origin
|
|
256
|
+
const fileContent = await this.downloadFile(ftpPathOrigin);
|
|
257
|
+
|
|
258
|
+
// Upload the file to destination
|
|
259
|
+
switch (this._ftpCredentials.type) {
|
|
260
|
+
case 'sftpWithKey':
|
|
261
|
+
// For SFTP, we can use the buffer directly
|
|
262
|
+
await this._ftpInstance.put(Buffer.concat(fileContent), ftpPathDestination);
|
|
263
|
+
break;
|
|
264
|
+
default:
|
|
265
|
+
// Create a temporary file
|
|
266
|
+
const tempFile = path.join(os.tmpdir(), `temp_${Date.now()}_${path.basename(ftpPathOrigin)}`);
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
// Write the downloaded content to temp file
|
|
270
|
+
fs.writeFileSync(tempFile, Buffer.concat(fileContent));
|
|
271
|
+
|
|
272
|
+
// Upload the temp file to destination
|
|
273
|
+
await this._ftpInstance.put(tempFile, ftpPathDestination);
|
|
274
|
+
|
|
275
|
+
// Clean up temp file
|
|
276
|
+
fs.unlinkSync(tempFile);
|
|
277
|
+
} catch (tempError) {
|
|
278
|
+
// Clean up temp file if it exists
|
|
279
|
+
if (fs.existsSync(tempFile)) {
|
|
280
|
+
fs.unlinkSync(tempFile);
|
|
281
|
+
}
|
|
282
|
+
throw tempError;
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Delete the original file
|
|
245
288
|
await this.deleteFile(ftpPathOrigin);
|
|
289
|
+
|
|
246
290
|
return { code: 200, message: "FTP successful moved" };
|
|
247
291
|
} catch (error) {
|
|
248
292
|
throw new Error(`Failed to move file inside FTP server: ${error.message}`);
|
package/lambdaClass/index.js
CHANGED
|
@@ -225,9 +225,9 @@ module.exports = class Lambda {
|
|
|
225
225
|
logFinishProcess = async ({error} = {}) => {
|
|
226
226
|
if (this.results.totalError || error) {
|
|
227
227
|
error = error && error.message ? error.message : error;
|
|
228
|
-
await this.logMessage("
|
|
228
|
+
await this.logMessage("Finished Process with errors: " + (error || "") + " " + JSON.stringify(this.results));
|
|
229
229
|
} else {
|
|
230
|
-
await this.logMessage("
|
|
230
|
+
await this.logMessage("Finished Process Sucessfully: " + JSON.stringify(this.results));
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
233
|
|
package/package.json
CHANGED
package/utils/index.js
CHANGED
|
@@ -635,6 +635,45 @@ const getMessageAndCodeFromError = (err) => {
|
|
|
635
635
|
return returnData;
|
|
636
636
|
};
|
|
637
637
|
|
|
638
|
+
const normalizeString = (_str) => {
|
|
639
|
+
// Handle null/undefined
|
|
640
|
+
if (_str === null || _str === undefined) return _str;
|
|
641
|
+
|
|
642
|
+
// Handle numbers
|
|
643
|
+
if (typeof _str === 'number') return _str;
|
|
644
|
+
|
|
645
|
+
// Handle arrays
|
|
646
|
+
if (Array.isArray(_str)) {
|
|
647
|
+
return _str.map(item => normalizeString(item));
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Handle objects
|
|
651
|
+
if (typeof _str === 'object') {
|
|
652
|
+
const normalizedObj = {};
|
|
653
|
+
for (const [key, value] of Object.entries(_str)) {
|
|
654
|
+
normalizedObj[key] = normalizeString(value);
|
|
655
|
+
}
|
|
656
|
+
return normalizedObj;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// Handle strings
|
|
660
|
+
if (typeof _str === 'string') {
|
|
661
|
+
if (!_str.length) return _str;
|
|
662
|
+
if (_str.trim() === "-") return "-";
|
|
663
|
+
|
|
664
|
+
let str = _str.trim();
|
|
665
|
+
str = str.replace(/&/g, "&");
|
|
666
|
+
str = str.replace(/</g, "<");
|
|
667
|
+
str = str.replace(/>/g, ">");
|
|
668
|
+
str = str.replace(/"/g, """);
|
|
669
|
+
str = str.replace(/'/g, "'");
|
|
670
|
+
return str;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// Return as is for any other type
|
|
674
|
+
return _str;
|
|
675
|
+
};
|
|
676
|
+
|
|
638
677
|
module.exports = {
|
|
639
678
|
dataToString,
|
|
640
679
|
getMessageFromValidator,
|
|
@@ -659,4 +698,5 @@ module.exports = {
|
|
|
659
698
|
getValueOrNullControlWithFallback,
|
|
660
699
|
getMimeTypeFromBase64,
|
|
661
700
|
getTipoPortes,
|
|
701
|
+
normalizeString,
|
|
662
702
|
};
|