@xube/kit-aws-hooks 0.0.38 → 0.0.40

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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { TableItem } from "@xube/kit-aws";
2
2
  import { XubeResponse } from "@xube/kit-request";
3
- export declare const sendDataToEndpoints: (webhookTableName: string, indexName: string, items: TableItem[]) => Promise<XubeResponse<boolean>>;
3
+ import { XubeLog } from "@xube/kit-log";
4
+ export declare const sendDataToEndpoints: (webhookTableName: string, indexName: string, items: TableItem[], log?: XubeLog) => Promise<XubeResponse<boolean>>;
package/dist/send.js CHANGED
@@ -7,21 +7,27 @@ const types_1 = require("./types");
7
7
  const kit_request_1 = require("@xube/kit-request");
8
8
  const webhook_1 = require("./schemas/webhook");
9
9
  const kit_constants_1 = require("@xube/kit-constants");
10
- const sendDataToEndpoints = async (webhookTableName, indexName, items) => {
10
+ const kit_log_1 = require("@xube/kit-log");
11
+ const sendDataToEndpoints = async (webhookTableName, indexName, items, log = kit_log_1.XubeLog.getInstance()) => {
11
12
  const endpointSends = [];
13
+ log.info(`Sending data to endpoints.`);
12
14
  for (const item of items) {
13
15
  const invertedWebhookKey = {
14
16
  PK: (0, keys_1.getWebhookSortKey)(item.id, types_1.WebhookTypes.data),
15
17
  };
18
+ log.info(`Searching for webhooks with key: ${JSON.stringify(invertedWebhookKey)}`);
16
19
  const getWebhookEndpointsResponse = await (0, kit_aws_1.queryItemsFromTable)(webhookTableName, invertedWebhookKey, indexName);
17
20
  if (getWebhookEndpointsResponse.hasFailed()) {
21
+ log.error(`Failed to get webhook endpoints for webhook endpoint ${item.id} and type ${types_1.WebhookTypes.data}`);
22
+ log.info(`${JSON.stringify(getWebhookEndpointsResponse, null, 2)}}`);
18
23
  return getWebhookEndpointsResponse.switchXubeResponseType();
19
24
  }
20
25
  if (!getWebhookEndpointsResponse.data ||
21
26
  !getWebhookEndpointsResponse.data.length) {
22
- console.log(`No webhook endpoints found for webhook endpoint ${item.id} and type ${types_1.WebhookTypes.data}`);
27
+ log.info(`No webhook endpoints found for webhook endpoint ${item.id} and type ${types_1.WebhookTypes.data}`);
23
28
  continue;
24
29
  }
30
+ log.info(`Found webhook endpoint ${JSON.stringify(invertedWebhookKey)} for id: ${item.id}`);
25
31
  const webhookEndpoints = getWebhookEndpointsResponse.data;
26
32
  for (const webhookEndpoint of webhookEndpoints) {
27
33
  if (!(0, webhook_1.isWebhookEndpoint)(webhookEndpoint)) {
@@ -29,9 +35,10 @@ const sendDataToEndpoints = async (webhookTableName, indexName, items) => {
29
35
  continue;
30
36
  }
31
37
  if (!webhookEndpoint.endpoints || !webhookEndpoint.endpoints.length) {
32
- console.log(`No endpoints found for webhook endpoint ${webhookEndpoint.id}`);
38
+ log.info(`No endpoints found for webhook endpoint ${webhookEndpoint.id}`);
33
39
  continue;
34
40
  }
41
+ log.info(`Preparing to send data to endpoints: ${JSON.stringify(webhookEndpoint.endpoints, null, 2)}`);
35
42
  for (const endpoint of webhookEndpoint.endpoints) {
36
43
  endpointSends.push(fetch(endpoint.url, {
37
44
  body: JSON.stringify(item),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xube/kit-aws-hooks",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -17,12 +17,12 @@
17
17
  },
18
18
  "homepage": "https://github.com/XubeLtd/dev-kit#readme",
19
19
  "devDependencies": {
20
- "@xube/kit-build": "^0.0.38"
20
+ "@xube/kit-build": "^0.0.40"
21
21
  },
22
22
  "dependencies": {
23
- "@xube/kit-aws": "^0.0.38",
24
- "@xube/kit-log": "^0.0.38",
25
- "@xube/kit-request": "^0.0.38",
23
+ "@xube/kit-aws": "^0.0.40",
24
+ "@xube/kit-log": "^0.0.40",
25
+ "@xube/kit-request": "^0.0.40",
26
26
  "zod": "^3.22.4"
27
27
  }
28
28
  }
package/src/send.ts CHANGED
@@ -4,19 +4,27 @@ import { WebhookTypes } from "./types";
4
4
  import { XubeResponse } from "@xube/kit-request";
5
5
  import { isWebhookEndpoint } from "./schemas/webhook";
6
6
  import { StatusCode } from "@xube/kit-constants";
7
+ import { XubeLog } from "@xube/kit-log";
7
8
 
8
9
  export const sendDataToEndpoints = async (
9
10
  webhookTableName: string,
10
11
  indexName: string,
11
- items: TableItem[]
12
+ items: TableItem[],
13
+ log: XubeLog = XubeLog.getInstance()
12
14
  ): Promise<XubeResponse<boolean>> => {
13
15
  const endpointSends: Promise<Response>[] = [];
14
16
 
17
+ log.info(`Sending data to endpoints.`);
18
+
15
19
  for (const item of items) {
16
20
  const invertedWebhookKey: PartialTableKey = {
17
21
  PK: getWebhookSortKey(item.id, WebhookTypes.data),
18
22
  };
19
23
 
24
+ log.info(
25
+ `Searching for webhooks with key: ${JSON.stringify(invertedWebhookKey)}`
26
+ );
27
+
20
28
  const getWebhookEndpointsResponse = await queryItemsFromTable(
21
29
  webhookTableName,
22
30
  invertedWebhookKey,
@@ -24,6 +32,10 @@ export const sendDataToEndpoints = async (
24
32
  );
25
33
 
26
34
  if (getWebhookEndpointsResponse.hasFailed()) {
35
+ log.error(
36
+ `Failed to get webhook endpoints for webhook endpoint ${item.id} and type ${WebhookTypes.data}`
37
+ );
38
+ log.info(`${JSON.stringify(getWebhookEndpointsResponse, null, 2)}}`);
27
39
  return getWebhookEndpointsResponse.switchXubeResponseType();
28
40
  }
29
41
 
@@ -31,12 +43,18 @@ export const sendDataToEndpoints = async (
31
43
  !getWebhookEndpointsResponse.data ||
32
44
  !getWebhookEndpointsResponse.data.length
33
45
  ) {
34
- console.log(
46
+ log.info(
35
47
  `No webhook endpoints found for webhook endpoint ${item.id} and type ${WebhookTypes.data}`
36
48
  );
37
49
  continue;
38
50
  }
39
51
 
52
+ log.info(
53
+ `Found webhook endpoint ${JSON.stringify(invertedWebhookKey)} for id: ${
54
+ item.id
55
+ }`
56
+ );
57
+
40
58
  const webhookEndpoints: TableItem[] = getWebhookEndpointsResponse.data;
41
59
 
42
60
  for (const webhookEndpoint of webhookEndpoints) {
@@ -48,12 +66,20 @@ export const sendDataToEndpoints = async (
48
66
  }
49
67
 
50
68
  if (!webhookEndpoint.endpoints || !webhookEndpoint.endpoints.length) {
51
- console.log(
69
+ log.info(
52
70
  `No endpoints found for webhook endpoint ${webhookEndpoint.id}`
53
71
  );
54
72
  continue;
55
73
  }
56
74
 
75
+ log.info(
76
+ `Preparing to send data to endpoints: ${JSON.stringify(
77
+ webhookEndpoint.endpoints,
78
+ null,
79
+ 2
80
+ )}`
81
+ );
82
+
57
83
  for (const endpoint of webhookEndpoint.endpoints) {
58
84
  endpointSends.push(
59
85
  fetch(endpoint.url, {