@xube/kit-aws-hooks 0.0.36 → 0.0.38

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.
Files changed (3) hide show
  1. package/dist/send.js +28 -18
  2. package/package.json +5 -5
  3. package/src/send.ts +41 -36
package/dist/send.js CHANGED
@@ -6,6 +6,7 @@ const keys_1 = require("./keys");
6
6
  const types_1 = require("./types");
7
7
  const kit_request_1 = require("@xube/kit-request");
8
8
  const webhook_1 = require("./schemas/webhook");
9
+ const kit_constants_1 = require("@xube/kit-constants");
9
10
  const sendDataToEndpoints = async (webhookTableName, indexName, items) => {
10
11
  const endpointSends = [];
11
12
  for (const item of items) {
@@ -40,30 +41,39 @@ const sendDataToEndpoints = async (webhookTableName, indexName, items) => {
40
41
  }
41
42
  }
42
43
  }
43
- const responses = await Promise.all(endpointSends);
44
- const failedEndpointSendUrls = [];
45
- let failedResponseCount = 0;
46
- for (const response of responses) {
47
- if (!response.ok) {
48
- failedEndpointSendUrls.push(response.url);
49
- failedResponseCount++;
44
+ try {
45
+ const responses = await Promise.all(endpointSends);
46
+ const failedEndpointSendUrls = [];
47
+ let failedResponseCount = 0;
48
+ for (const response of responses) {
49
+ if (!response.ok) {
50
+ failedEndpointSendUrls.push(response.url);
51
+ failedResponseCount++;
52
+ }
53
+ }
54
+ if (failedResponseCount == endpointSends.length) {
55
+ return new kit_request_1.XubeResponse({
56
+ statusCode: 500,
57
+ error: `Failed to send data to all endpoints: ${JSON.stringify(failedEndpointSendUrls, null, 2)}`,
58
+ });
59
+ }
60
+ if (failedResponseCount) {
61
+ return new kit_request_1.XubeResponse({
62
+ statusCode: 207,
63
+ error: `Failed to send data to ${failedResponseCount} of ${endpointSends.length} endpoints: ${JSON.stringify(failedEndpointSendUrls, null, 2)}`,
64
+ });
50
65
  }
51
- }
52
- if (failedResponseCount == endpointSends.length) {
53
66
  return new kit_request_1.XubeResponse({
54
- statusCode: 500,
55
- error: `Failed to send data to all endpoints: ${JSON.stringify(failedEndpointSendUrls, null, 2)}`,
67
+ statusCode: 200,
68
+ data: true,
56
69
  });
57
70
  }
58
- if (failedResponseCount) {
71
+ catch (e) {
72
+ console.error("Error sending data to endpoints:", e);
59
73
  return new kit_request_1.XubeResponse({
60
- statusCode: 207,
61
- error: `Failed to send data to ${failedResponseCount} of ${endpointSends.length} endpoints: ${JSON.stringify(failedEndpointSendUrls, null, 2)}`,
74
+ statusCode: kit_constants_1.StatusCode.InternalError,
75
+ error: `Error sending data to endpoints: ${e}`,
62
76
  });
63
77
  }
64
- return new kit_request_1.XubeResponse({
65
- statusCode: 200,
66
- data: true,
67
- });
68
78
  };
69
79
  exports.sendDataToEndpoints = sendDataToEndpoints;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xube/kit-aws-hooks",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
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.36"
20
+ "@xube/kit-build": "^0.0.38"
21
21
  },
22
22
  "dependencies": {
23
- "@xube/kit-aws": "^0.0.36",
24
- "@xube/kit-log": "^0.0.36",
25
- "@xube/kit-request": "^0.0.36",
23
+ "@xube/kit-aws": "^0.0.38",
24
+ "@xube/kit-log": "^0.0.38",
25
+ "@xube/kit-request": "^0.0.38",
26
26
  "zod": "^3.22.4"
27
27
  }
28
28
  }
package/src/send.ts CHANGED
@@ -1,12 +1,9 @@
1
- import {
2
- PartialTableKey,
3
- TableItem,
4
- queryItemsFromTable,
5
- } from "@xube/kit-aws";
1
+ import { PartialTableKey, TableItem, queryItemsFromTable } from "@xube/kit-aws";
6
2
  import { getWebhookSortKey } from "./keys";
7
3
  import { WebhookTypes } from "./types";
8
4
  import { XubeResponse } from "@xube/kit-request";
9
5
  import { isWebhookEndpoint } from "./schemas/webhook";
6
+ import { StatusCode } from "@xube/kit-constants";
10
7
 
11
8
  export const sendDataToEndpoints = async (
12
9
  webhookTableName: string,
@@ -34,9 +31,9 @@ export const sendDataToEndpoints = async (
34
31
  !getWebhookEndpointsResponse.data ||
35
32
  !getWebhookEndpointsResponse.data.length
36
33
  ) {
37
- console.log(
38
- `No webhook endpoints found for webhook endpoint ${item.id} and type ${WebhookTypes.data}`
39
- );
34
+ console.log(
35
+ `No webhook endpoints found for webhook endpoint ${item.id} and type ${WebhookTypes.data}`
36
+ );
40
37
  continue;
41
38
  }
42
39
 
@@ -69,40 +66,48 @@ export const sendDataToEndpoints = async (
69
66
  }
70
67
  }
71
68
 
72
- const responses: Response[] = await Promise.all(endpointSends);
69
+ try {
70
+ const responses: Response[] = await Promise.all(endpointSends);
71
+
72
+ const failedEndpointSendUrls: string[] = [];
73
+ let failedResponseCount: number = 0;
73
74
 
74
- const failedEndpointSendUrls: string[] = [];
75
- let failedResponseCount: number = 0;
75
+ for (const response of responses) {
76
+ if (!response.ok) {
77
+ failedEndpointSendUrls.push(response.url);
78
+ failedResponseCount++;
79
+ }
80
+ }
76
81
 
77
- for (const response of responses) {
78
- if (!response.ok) {
79
- failedEndpointSendUrls.push(response.url);
80
- failedResponseCount++;
82
+ if (failedResponseCount == endpointSends.length) {
83
+ return new XubeResponse({
84
+ statusCode: 500,
85
+ error: `Failed to send data to all endpoints: ${JSON.stringify(
86
+ failedEndpointSendUrls,
87
+ null,
88
+ 2
89
+ )}`,
90
+ });
91
+ }
92
+
93
+ if (failedResponseCount) {
94
+ return new XubeResponse({
95
+ statusCode: 207,
96
+ error: `Failed to send data to ${failedResponseCount} of ${
97
+ endpointSends.length
98
+ } endpoints: ${JSON.stringify(failedEndpointSendUrls, null, 2)}`,
99
+ });
81
100
  }
82
- }
83
101
 
84
- if (failedResponseCount == endpointSends.length) {
85
102
  return new XubeResponse({
86
- statusCode: 500,
87
- error: `Failed to send data to all endpoints: ${JSON.stringify(
88
- failedEndpointSendUrls,
89
- null,
90
- 2
91
- )}`,
103
+ statusCode: 200,
104
+ data: true,
92
105
  });
93
- }
94
-
95
- if (failedResponseCount) {
106
+ } catch (e) {
107
+ console.error("Error sending data to endpoints:", e);
96
108
  return new XubeResponse({
97
- statusCode: 207,
98
- error: `Failed to send data to ${failedResponseCount} of ${
99
- endpointSends.length
100
- } endpoints: ${JSON.stringify(failedEndpointSendUrls, null, 2)}`,
109
+ statusCode: StatusCode.InternalError,
110
+ error: `Error sending data to endpoints: ${e}`,
101
111
  });
102
112
  }
103
-
104
- return new XubeResponse({
105
- statusCode: 200,
106
- data: true,
107
- });
108
- };
113
+ };