vtlab-generic-functions 1.0.10 → 1.0.12

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/axios/logs.js CHANGED
@@ -64,7 +64,7 @@ const processPayload = async (payload) => {
64
64
  // get bucket name from secrets manager
65
65
  let bucket = await secretsManager.get('s3LogsBucket');
66
66
  console.log("bucket", bucket);
67
- let signedURL = s3bucket.generatePresignedUrl(bucket, path);
67
+ let signedURL = await s3bucket.generatePresignedUrl(bucket, path);
68
68
  console.log("signedURL", signedURL)
69
69
 
70
70
  // Update the response to be the presigned URL
@@ -6,6 +6,21 @@ if (!global.LOG_STREAM_NAME) {
6
6
  global.LOG_STREAM_NAME = `${process.env.AWS_LAMBDA_FUNCTION_NAME}-${process.env.AWS_LAMBDA_LOG_STREAM_NAME}-${randomUUID()}`;
7
7
  }
8
8
 
9
+ function safeStringify(obj) {
10
+ //this avoids circular references
11
+ const cache = new Set();
12
+ return JSON.stringify(obj, (key, value) => {
13
+ if (typeof value === 'object' && value !== null) {
14
+ if (cache.has(value)) {
15
+ // duplicate reference found, skip it
16
+ return;
17
+ }
18
+ cache.add(value);
19
+ }
20
+ return value;
21
+ });
22
+ }
23
+
9
24
  const putLogEvents = async (logEvents = [], logGroupName, logLevel = 2, logStreamName = null) => {
10
25
  if (logLevel === 0) {
11
26
  return;
@@ -28,6 +43,20 @@ const putLogEvents = async (logEvents = [], logGroupName, logLevel = 2, logStrea
28
43
  logEvents = [logEvents];
29
44
  }
30
45
 
46
+ //safe stringify to avoid circular references and [object Object]
47
+ logEvents = logEvents.map(event => {
48
+ if (typeof event === 'string') {
49
+ return event;
50
+ }
51
+ try {
52
+ return safeStringify(event);
53
+ } catch (error) {
54
+ // Handle or log the error as needed
55
+ console.error('Error stringifying event:', error);
56
+ return 'Error in stringifying event';
57
+ }
58
+ });
59
+
31
60
  if (logEvents.length === 0) {
32
61
  throw new Error('Empty log event');
33
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtlab-generic-functions",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "scripts": {
5
5
  "test": "jest"
6
6
  },