@xube/kit-aws-hooks 0.0.51 → 0.0.53
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/dist/send.js +13 -6
- package/package.json +8 -8
- package/src/send.ts +18 -8
package/dist/send.js
CHANGED
|
@@ -13,9 +13,16 @@ const transform_1 = require("./transform");
|
|
|
13
13
|
const sendDataToEndpoints = async (webhookTableName, indexName, items, log = kit_log_1.XubeLog.getInstance()) => {
|
|
14
14
|
const endpointSends = [];
|
|
15
15
|
log.info(`Sending data to endpoints based on ${items.length} items.}`);
|
|
16
|
+
const itemsById = {};
|
|
16
17
|
for (const item of items) {
|
|
18
|
+
if (!itemsById[item.id]) {
|
|
19
|
+
itemsById[item.id] = [];
|
|
20
|
+
}
|
|
21
|
+
itemsById[item.id].push(item);
|
|
22
|
+
}
|
|
23
|
+
for (const id in itemsById) {
|
|
17
24
|
const invertedWebhookKey = {
|
|
18
|
-
PK: (0, keys_1.getWebhookSortKey)(
|
|
25
|
+
PK: (0, keys_1.getWebhookSortKey)(id, types_1.WebhookTypes.data),
|
|
19
26
|
};
|
|
20
27
|
log.info(`Searching for webhooks with key: ${JSON.stringify(invertedWebhookKey)}`);
|
|
21
28
|
const getWebhookEndpointsResponse = await (0, kit_aws_1.queryItemsFromTable)(webhookTableName, invertedWebhookKey, indexName, {
|
|
@@ -23,19 +30,19 @@ const sendDataToEndpoints = async (webhookTableName, indexName, items, log = kit
|
|
|
23
30
|
});
|
|
24
31
|
if (getWebhookEndpointsResponse.hasFailed()) {
|
|
25
32
|
if (getWebhookEndpointsResponse.statusCode === kit_constants_1.StatusCode.NotFound) {
|
|
26
|
-
log.info(`No webhook endpoints found for webhook endpoint ${
|
|
33
|
+
log.info(`No webhook endpoints found for webhook endpoint ${id} and type ${types_1.WebhookTypes.data}`);
|
|
27
34
|
continue;
|
|
28
35
|
}
|
|
29
|
-
log.error(`Failed to get webhook endpoints for webhook endpoint ${
|
|
36
|
+
log.error(`Failed to get webhook endpoints for webhook endpoint ${id} and type ${types_1.WebhookTypes.data}`);
|
|
30
37
|
log.info(`${JSON.stringify(getWebhookEndpointsResponse, null, 2)}}`);
|
|
31
38
|
return getWebhookEndpointsResponse.switchXubeResponseType();
|
|
32
39
|
}
|
|
33
40
|
if (!getWebhookEndpointsResponse.data ||
|
|
34
41
|
!getWebhookEndpointsResponse.data.length) {
|
|
35
|
-
log.info(`No webhook endpoints found for webhook endpoint ${
|
|
42
|
+
log.info(`No webhook endpoints found for webhook endpoint ${id} and type ${types_1.WebhookTypes.data}`);
|
|
36
43
|
continue;
|
|
37
44
|
}
|
|
38
|
-
log.info(`Found webhook endpoint ${JSON.stringify(invertedWebhookKey)} for id: ${
|
|
45
|
+
log.info(`Found webhook endpoint ${JSON.stringify(invertedWebhookKey)} for id: ${id}`);
|
|
39
46
|
const webhookEndpoints = getWebhookEndpointsResponse.data;
|
|
40
47
|
log.info(`Found ${webhookEndpoints.length} webhook endpoints.`);
|
|
41
48
|
log.info(`Webhook endpoints: ${JSON.stringify(webhookEndpoints, null, 2)}`);
|
|
@@ -49,7 +56,7 @@ const sendDataToEndpoints = async (webhookTableName, indexName, items, log = kit
|
|
|
49
56
|
continue;
|
|
50
57
|
}
|
|
51
58
|
log.info(`Preparing to send data to endpoints: ${JSON.stringify(webhookEndpoint.endpoints, null, 2)}`);
|
|
52
|
-
const timeSeries = (0, transform_1.getTimeSeriesDataFromData)(
|
|
59
|
+
const timeSeries = (0, transform_1.getTimeSeriesDataFromData)(itemsById[id]);
|
|
53
60
|
for (const endpoint of webhookEndpoint.endpoints) {
|
|
54
61
|
endpointSends.push(fetch(endpoint.url, {
|
|
55
62
|
body: JSON.stringify(timeSeries),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xube/kit-aws-hooks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/XubeLtd/dev-kit#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@xube/kit-build": "^0.0.
|
|
20
|
+
"@xube/kit-build": "^0.0.53"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@xube/kit-aws": "^0.0.
|
|
24
|
-
"@xube/kit-aws-schema": "^0.0.
|
|
25
|
-
"@xube/kit-data-schema": "^0.0.
|
|
26
|
-
"@xube/kit-log": "^0.0.
|
|
27
|
-
"@xube/kit-request": "^0.0.
|
|
28
|
-
"@xube/kit-schema": "^0.0.
|
|
23
|
+
"@xube/kit-aws": "^0.0.53",
|
|
24
|
+
"@xube/kit-aws-schema": "^0.0.53",
|
|
25
|
+
"@xube/kit-data-schema": "^0.0.53",
|
|
26
|
+
"@xube/kit-log": "^0.0.53",
|
|
27
|
+
"@xube/kit-request": "^0.0.53",
|
|
28
|
+
"@xube/kit-schema": "^0.0.53",
|
|
29
29
|
"zod": "^3.22.4"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/send.ts
CHANGED
|
@@ -20,9 +20,19 @@ export const sendDataToEndpoints = async (
|
|
|
20
20
|
|
|
21
21
|
log.info(`Sending data to endpoints based on ${items.length} items.}`);
|
|
22
22
|
|
|
23
|
+
const itemsById: Record<string, TableItem[]> = {};
|
|
24
|
+
|
|
23
25
|
for (const item of items) {
|
|
26
|
+
if (!itemsById[item.id]) {
|
|
27
|
+
itemsById[item.id] = [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
itemsById[item.id].push(item);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const id in itemsById) {
|
|
24
34
|
const invertedWebhookKey: PartialTableKey = {
|
|
25
|
-
PK: getWebhookSortKey(
|
|
35
|
+
PK: getWebhookSortKey(id, WebhookTypes.data),
|
|
26
36
|
};
|
|
27
37
|
|
|
28
38
|
log.info(
|
|
@@ -41,13 +51,13 @@ export const sendDataToEndpoints = async (
|
|
|
41
51
|
if (getWebhookEndpointsResponse.hasFailed()) {
|
|
42
52
|
if (getWebhookEndpointsResponse.statusCode === StatusCode.NotFound) {
|
|
43
53
|
log.info(
|
|
44
|
-
`No webhook endpoints found for webhook endpoint ${
|
|
54
|
+
`No webhook endpoints found for webhook endpoint ${id} and type ${WebhookTypes.data}`
|
|
45
55
|
);
|
|
46
56
|
continue;
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
log.error(
|
|
50
|
-
`Failed to get webhook endpoints for webhook endpoint ${
|
|
60
|
+
`Failed to get webhook endpoints for webhook endpoint ${id} and type ${WebhookTypes.data}`
|
|
51
61
|
);
|
|
52
62
|
log.info(`${JSON.stringify(getWebhookEndpointsResponse, null, 2)}}`);
|
|
53
63
|
return getWebhookEndpointsResponse.switchXubeResponseType();
|
|
@@ -58,15 +68,15 @@ export const sendDataToEndpoints = async (
|
|
|
58
68
|
!getWebhookEndpointsResponse.data.length
|
|
59
69
|
) {
|
|
60
70
|
log.info(
|
|
61
|
-
`No webhook endpoints found for webhook endpoint ${
|
|
71
|
+
`No webhook endpoints found for webhook endpoint ${id} and type ${WebhookTypes.data}`
|
|
62
72
|
);
|
|
63
73
|
continue;
|
|
64
74
|
}
|
|
65
75
|
|
|
66
76
|
log.info(
|
|
67
|
-
`Found webhook endpoint ${JSON.stringify(
|
|
68
|
-
|
|
69
|
-
}`
|
|
77
|
+
`Found webhook endpoint ${JSON.stringify(
|
|
78
|
+
invertedWebhookKey
|
|
79
|
+
)} for id: ${id}`
|
|
70
80
|
);
|
|
71
81
|
|
|
72
82
|
const webhookEndpoints: TableItem[] = getWebhookEndpointsResponse.data;
|
|
@@ -97,7 +107,7 @@ export const sendDataToEndpoints = async (
|
|
|
97
107
|
)}`
|
|
98
108
|
);
|
|
99
109
|
|
|
100
|
-
const timeSeries = getTimeSeriesDataFromData(
|
|
110
|
+
const timeSeries = getTimeSeriesDataFromData(itemsById[id]);
|
|
101
111
|
|
|
102
112
|
for (const endpoint of webhookEndpoint.endpoints) {
|
|
103
113
|
endpointSends.push(
|