@plusscommunities/pluss-core-aws 2.1.1-beta.0 → 2.1.1-beta.2

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.
@@ -18,12 +18,12 @@ module.exports = async (table, key, value) => {
18
18
  };
19
19
  params.Key[key] = value;
20
20
 
21
- // log("deleteRef", "Params", JSON.stringify(params), logId, true);
21
+ log("deleteRef", "Params", JSON.stringify(params), logId, true);
22
22
 
23
23
  try {
24
24
  // write the todo to the database
25
25
  const data = await dynamoDb.send(new DeleteCommand(params));
26
- // log("deleteRef", "Success", "Deleted item", logId, true);
26
+ log("deleteRef", "Success", "Deleted item", logId, true);
27
27
  return data;
28
28
  } catch (error) {
29
29
  // handle potential errors
@@ -16,10 +16,10 @@ module.exports = async (table, key, value) => {
16
16
  };
17
17
  query.Key[key] = value;
18
18
 
19
- // log("getRef", "Query", query, logId, true);
19
+ log("getRef", "Query", query, logId, true);
20
20
 
21
21
  const data = await dynamoDb.send(new GetCommand(query));
22
- // log("getRef", "Success", data.Item, logId, true);
22
+ log("getRef", "Success", data.Item, logId, true);
23
23
  return data.Item;
24
24
  } catch (error) {
25
25
  log("getRef", "Error", error, logId);
@@ -1,5 +1,8 @@
1
1
  const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
2
- const { DynamoDBDocumentClient, QueryCommand } = require("@aws-sdk/lib-dynamodb");
2
+ const {
3
+ DynamoDBDocumentClient,
4
+ QueryCommand,
5
+ } = require("@aws-sdk/lib-dynamodb");
3
6
  const { log, generateLogId } = require("../../helper");
4
7
 
5
8
  const client = new DynamoDBClient({});
@@ -11,16 +14,18 @@ module.exports = async (table, query) => {
11
14
  const logId = generateLogId();
12
15
  query.TableName = `${process.env.tablePrefix}${table}`;
13
16
 
14
- // log("indexQuery", "Query", JSON.stringify(query), logId);
17
+ log("indexQuery", "Query", JSON.stringify(query), logId, true);
15
18
 
16
19
  try {
17
20
  // write the todo to the database
18
21
  const data = await dynamoDb.send(new QueryCommand(query));
19
- // log("indexQuery", "ResultLength", data.Items.length, logId);
22
+ log("indexQuery", "ResultLength", data.Items.length, logId, true);
20
23
  return data;
21
24
  } catch (error) {
22
25
  // handle potential errors
23
26
  log("indexQuery", "Error", error, logId);
27
+ log("indexQuery", "Error:Message", error.message, logId);
28
+ log("indexQuery", "Query", query, logId);
24
29
  throw error;
25
30
  }
26
31
  };
@@ -1,5 +1,8 @@
1
1
  const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
2
- const { DynamoDBDocumentClient, UpdateCommand } = require("@aws-sdk/lib-dynamodb");
2
+ const {
3
+ DynamoDBDocumentClient,
4
+ UpdateCommand,
5
+ } = require("@aws-sdk/lib-dynamodb");
3
6
  const { log, generateLogId } = require("../../helper");
4
7
 
5
8
  const client = new DynamoDBClient({});
@@ -25,11 +28,11 @@ module.exports = async (
25
28
  [attributeKey]: { Action: action, Value: attributeValue },
26
29
  },
27
30
  };
28
- // log("updateAttribute", "Params", params, logId);
31
+ log("updateAttribute", "Params", params, logId, true);
29
32
 
30
33
  try {
31
34
  const data = await dynamoDb.send(new UpdateCommand(params));
32
- // log("updateAttribute", "Success", data, logId);
35
+ log("updateAttribute", "Success", data, logId, true);
33
36
  return data;
34
37
  } catch (err) {
35
38
  log("updateAttribute", "Error", err, logId);
@@ -14,12 +14,12 @@ module.exports = async (table, data) => {
14
14
  Item: data,
15
15
  };
16
16
 
17
- // log("updateRef", "Params", params, logId);
17
+ log("updateRef", "Params", params, logId, true);
18
18
 
19
19
  try {
20
20
  // write the todo to the database
21
21
  await dynamoDb.send(new PutCommand(params));
22
- // log("updateRef", "Result", data, logId);
22
+ log("updateRef", "Result", data, logId, true);
23
23
  return data;
24
24
  } catch (error) {
25
25
  // handle potential errors
package/helper/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const _ = require("lodash");
2
2
  const uuid = require("uuid");
3
3
  const { encode, decode } = require("html-entities");
4
+ const { getConfig } = require("../config");
4
5
 
5
6
  exports.thisOrDefault = (val, def) => {
6
7
  if (val) {
@@ -46,16 +47,18 @@ exports.getBody = (event) => {
46
47
  // .substring(0, 7);
47
48
  // };
48
49
 
49
- exports.log = (action, logKey, data, logId) => {
50
+ exports.log = (action, logKey, data, logId, useConfig = false) => {
50
51
  if (!logId) {
51
52
  logId = this.generateLogId();
52
53
  }
53
- console.log(
54
- `[${action}]:[${logId}]:[${logKey}]`,
55
- typeof data === "string" || typeof data === "number"
56
- ? data
57
- : JSON.stringify(data)
58
- );
54
+ if (useConfig && !getConfig().databaseConfig?.enableLog) return logId;
55
+
56
+ let output = data;
57
+ try {
58
+ output = JSON.parse(data);
59
+ } catch {}
60
+
61
+ console.log(`[${action}]:[${logId}]:[${logKey}]`, output);
59
62
  return logId;
60
63
  };
61
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "2.1.1-beta.0",
3
+ "version": "2.1.1-beta.2",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "betapatch": "npm version prepatch --preid=beta",