@plusscommunities/pluss-core-aws 2.0.20 → 2.1.1-beta.0
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/db/common/deleteRef.js +26 -22
- package/db/common/getRef.js +22 -25
- package/db/common/getTableCount.js +21 -21
- package/db/common/indexQuery.js +19 -18
- package/db/common/scanRef.js +21 -21
- package/db/common/updateAttribute.js +27 -24
- package/db/common/updateRef.js +22 -21
- package/package.json +4 -2
package/db/common/deleteRef.js
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
|
|
2
|
+
const {
|
|
3
|
+
DynamoDBDocumentClient,
|
|
4
|
+
DeleteCommand,
|
|
5
|
+
} = require("@aws-sdk/lib-dynamodb");
|
|
3
6
|
const { log, generateLogId } = require("../../helper");
|
|
4
7
|
|
|
8
|
+
const client = new DynamoDBClient({});
|
|
9
|
+
const dynamoDb = DynamoDBDocumentClient.from(client, {
|
|
10
|
+
convertEmptyValues: true,
|
|
11
|
+
});
|
|
12
|
+
|
|
5
13
|
module.exports = async (table, key, value) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
params.Key[key] = value;
|
|
14
|
+
const logId = generateLogId();
|
|
15
|
+
const params = {
|
|
16
|
+
TableName: `${process.env.tablePrefix}${table}`,
|
|
17
|
+
Key: {},
|
|
18
|
+
};
|
|
19
|
+
params.Key[key] = value;
|
|
13
20
|
|
|
14
|
-
|
|
21
|
+
// log("deleteRef", "Params", JSON.stringify(params), logId, true);
|
|
15
22
|
|
|
23
|
+
try {
|
|
16
24
|
// write the todo to the database
|
|
17
|
-
dynamoDb.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
resolve(data);
|
|
26
|
-
return;
|
|
27
|
-
});
|
|
28
|
-
});
|
|
25
|
+
const data = await dynamoDb.send(new DeleteCommand(params));
|
|
26
|
+
// log("deleteRef", "Success", "Deleted item", logId, true);
|
|
27
|
+
return data;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
// handle potential errors
|
|
30
|
+
log("deleteRef", "Error", error, logId);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
29
33
|
};
|
package/db/common/getRef.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
|
|
2
|
+
const { DynamoDBDocumentClient, GetCommand } = require("@aws-sdk/lib-dynamodb");
|
|
3
3
|
const { log, generateLogId } = require("../../helper");
|
|
4
4
|
|
|
5
|
+
const client = new DynamoDBClient({});
|
|
6
|
+
const dynamoDb = DynamoDBDocumentClient.from(client, {
|
|
7
|
+
convertEmptyValues: true,
|
|
8
|
+
});
|
|
9
|
+
|
|
5
10
|
module.exports = async (table, key, value) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
query.Key[key] = value;
|
|
11
|
+
const logId = generateLogId();
|
|
12
|
+
try {
|
|
13
|
+
const query = {
|
|
14
|
+
TableName: `${process.env.tablePrefix}${table}`,
|
|
15
|
+
Key: {},
|
|
16
|
+
};
|
|
17
|
+
query.Key[key] = value;
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
// log("getRef", "Query", query, logId, true);
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
resolve(data.Item);
|
|
25
|
-
return;
|
|
26
|
-
});
|
|
27
|
-
} catch (e) {
|
|
28
|
-
log("getRef", "Error:Caught", e, logId);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
21
|
+
const data = await dynamoDb.send(new GetCommand(query));
|
|
22
|
+
// log("getRef", "Success", data.Item, logId, true);
|
|
23
|
+
return data.Item;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
log("getRef", "Error", error, logId);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
31
28
|
};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
|
|
2
|
+
const { DynamoDBDocumentClient, ScanCommand } = require("@aws-sdk/lib-dynamodb");
|
|
3
3
|
const { log, generateLogId } = require("../../helper");
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
TableName: `${process.env.tablePrefix}${table}`,
|
|
10
|
-
Select: "COUNT",
|
|
11
|
-
};
|
|
5
|
+
const client = new DynamoDBClient({});
|
|
6
|
+
const dynamoDb = DynamoDBDocumentClient.from(client, {
|
|
7
|
+
convertEmptyValues: true,
|
|
8
|
+
});
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
module.exports = async (table) => {
|
|
11
|
+
const logId = generateLogId();
|
|
12
|
+
const query = {
|
|
13
|
+
TableName: `${process.env.tablePrefix}${table}`,
|
|
14
|
+
Select: "COUNT",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const result = await dynamoDb.send(new ScanCommand(query));
|
|
19
|
+
return result;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
// handle potential errors
|
|
22
|
+
log("getTableCount", "Error", error, logId);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
25
|
};
|
package/db/common/indexQuery.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
|
|
2
|
+
const { DynamoDBDocumentClient, QueryCommand } = require("@aws-sdk/lib-dynamodb");
|
|
3
3
|
const { log, generateLogId } = require("../../helper");
|
|
4
4
|
|
|
5
|
+
const client = new DynamoDBClient({});
|
|
6
|
+
const dynamoDb = DynamoDBDocumentClient.from(client, {
|
|
7
|
+
convertEmptyValues: true,
|
|
8
|
+
});
|
|
9
|
+
|
|
5
10
|
module.exports = async (table, query) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
query.TableName = `${process.env.tablePrefix}${table}`;
|
|
11
|
+
const logId = generateLogId();
|
|
12
|
+
query.TableName = `${process.env.tablePrefix}${table}`;
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
// log("indexQuery", "Query", JSON.stringify(query), logId);
|
|
11
15
|
|
|
16
|
+
try {
|
|
12
17
|
// write the todo to the database
|
|
13
|
-
dynamoDb.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
resolve(data);
|
|
22
|
-
return;
|
|
23
|
-
});
|
|
24
|
-
});
|
|
18
|
+
const data = await dynamoDb.send(new QueryCommand(query));
|
|
19
|
+
// log("indexQuery", "ResultLength", data.Items.length, logId);
|
|
20
|
+
return data;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
// handle potential errors
|
|
23
|
+
log("indexQuery", "Error", error, logId);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
25
26
|
};
|
package/db/common/scanRef.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
|
|
2
|
+
const { DynamoDBDocumentClient, ScanCommand } = require("@aws-sdk/lib-dynamodb");
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
query.TableName = `${process.env.tablePrefix}${table}`;
|
|
4
|
+
const client = new DynamoDBClient({});
|
|
5
|
+
const dynamoDb = DynamoDBDocumentClient.from(client, {
|
|
6
|
+
convertEmptyValues: true,
|
|
7
|
+
});
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
});
|
|
23
|
-
|
|
9
|
+
module.exports = async (table, query) => {
|
|
10
|
+
if (!query) {
|
|
11
|
+
query = {};
|
|
12
|
+
}
|
|
13
|
+
query.TableName = `${process.env.tablePrefix}${table}`;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const result = await dynamoDb.send(new ScanCommand(query));
|
|
17
|
+
return result;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
// handle potential errors
|
|
20
|
+
console.error(`Table Scan fail: ${table}`);
|
|
21
|
+
console.error(error);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
24
|
};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
|
|
2
|
+
const { DynamoDBDocumentClient, UpdateCommand } = require("@aws-sdk/lib-dynamodb");
|
|
3
3
|
const { log, generateLogId } = require("../../helper");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const client = new DynamoDBClient({});
|
|
6
|
+
const dynamoDb = DynamoDBDocumentClient.from(client, {
|
|
7
|
+
convertEmptyValues: true,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
module.exports = async (
|
|
6
11
|
table,
|
|
7
12
|
tableKey,
|
|
8
13
|
tableValue,
|
|
@@ -10,26 +15,24 @@ module.exports = (
|
|
|
10
15
|
attributeValue,
|
|
11
16
|
action
|
|
12
17
|
) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// log("updateAttribute", "Params", params, logId);
|
|
18
|
+
const logId = generateLogId();
|
|
19
|
+
const params = {
|
|
20
|
+
TableName: `${process.env.tablePrefix}${table}`,
|
|
21
|
+
Key: {
|
|
22
|
+
[tableKey]: tableValue,
|
|
23
|
+
},
|
|
24
|
+
AttributeUpdates: {
|
|
25
|
+
[attributeKey]: { Action: action, Value: attributeValue },
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
// log("updateAttribute", "Params", params, logId);
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
30
|
+
try {
|
|
31
|
+
const data = await dynamoDb.send(new UpdateCommand(params));
|
|
32
|
+
// log("updateAttribute", "Success", data, logId);
|
|
33
|
+
return data;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
log("updateAttribute", "Error", err, logId);
|
|
36
|
+
throw err;
|
|
37
|
+
}
|
|
35
38
|
};
|
package/db/common/updateRef.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
|
|
2
|
+
const { DynamoDBDocumentClient, PutCommand } = require("@aws-sdk/lib-dynamodb");
|
|
3
3
|
const { log, generateLogId } = require("../../helper");
|
|
4
4
|
|
|
5
|
+
const client = new DynamoDBClient({});
|
|
6
|
+
const dynamoDb = DynamoDBDocumentClient.from(client, {
|
|
7
|
+
convertEmptyValues: true,
|
|
8
|
+
});
|
|
9
|
+
|
|
5
10
|
module.exports = async (table, data) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
11
|
+
const logId = generateLogId();
|
|
12
|
+
const params = {
|
|
13
|
+
TableName: `${process.env.tablePrefix}${table}`,
|
|
14
|
+
Item: data,
|
|
15
|
+
};
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
// log("updateRef", "Params", params, logId);
|
|
14
18
|
|
|
19
|
+
try {
|
|
15
20
|
// write the todo to the database
|
|
16
|
-
dynamoDb.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
resolve(data);
|
|
25
|
-
return;
|
|
26
|
-
});
|
|
27
|
-
});
|
|
21
|
+
await dynamoDb.send(new PutCommand(params));
|
|
22
|
+
// log("updateRef", "Result", data, logId);
|
|
23
|
+
return data;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
// handle potential errors
|
|
26
|
+
log("updateRef", "Error", error, logId);
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
28
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusscommunities/pluss-core-aws",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.1-beta.0",
|
|
4
4
|
"description": "Core extension package for Pluss Communities platform",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"betapatch": "npm version prepatch --preid=beta",
|
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
"author": "Thorbjorn Kappel Davis",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"@aws-sdk/client-dynamodb": "^3.855.0",
|
|
17
|
+
"@aws-sdk/lib-dynamodb": "^3.855.0",
|
|
16
18
|
"@aws/dynamodb-auto-marshaller": "^0.7.1",
|
|
17
19
|
"amazon-cognito-identity-js": "^2.0.19",
|
|
18
|
-
"axios": "^1.6.8",
|
|
19
20
|
"aws-sdk": "^2.1591.0",
|
|
21
|
+
"axios": "^1.6.8",
|
|
20
22
|
"expo-server-sdk": "^3.0.1",
|
|
21
23
|
"html-entities": "^2.3.2",
|
|
22
24
|
"https": "^1.0.0",
|