@alanszp/eventbridge-client 7.5.0 → 7.8.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.
- package/dist/aws/awsEventbridgeClient.d.ts +1 -1
- package/dist/aws/awsEventbridgeClient.js +3 -2
- package/dist/aws/awsEventbridgeClient.js.map +1 -1
- package/dist/basicEventbridgeClient.d.ts +2 -1
- package/dist/basicEventbridgeClient.js +3 -2
- package/dist/basicEventbridgeClient.js.map +1 -1
- package/dist/basicEventbridgeClient.test.js +41 -33
- package/dist/basicEventbridgeClient.test.js.map +1 -1
- package/dist/types/UpdatedEvent.d.ts +1 -0
- package/package.json +2 -2
- package/src/aws/awsEventbridgeClient.ts +2 -1
- package/src/basicEventbridgeClient.test.ts +62 -46
- package/src/basicEventbridgeClient.ts +8 -5
- package/src/types/UpdatedEvent.ts +5 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import AWS from "aws-sdk";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const getEventbridgeClient: (endpoint?: string | undefined, region?: string | undefined) => AWS.EventBridge;
|
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getEventbridgeClient = void 0;
|
|
7
7
|
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
8
|
-
|
|
8
|
+
const getEventbridgeClient = (endpoint, region) => new aws_sdk_1.default.EventBridge(endpoint ? { endpoint, region } : {});
|
|
9
|
+
exports.getEventbridgeClient = getEventbridgeClient;
|
|
9
10
|
//# sourceMappingURL=awsEventbridgeClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"awsEventbridgeClient.js","sourceRoot":"","sources":["../../src/aws/awsEventbridgeClient.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA0B;
|
|
1
|
+
{"version":3,"file":"awsEventbridgeClient.js","sourceRoot":"","sources":["../../src/aws/awsEventbridgeClient.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA0B;AAEnB,MAAM,oBAAoB,GAAG,CAAC,QAAiB,EAAE,MAAe,EAAE,EAAE,CACzE,IAAI,iBAAG,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAD/C,QAAA,oBAAoB,wBAC2B"}
|
|
@@ -28,8 +28,9 @@ export declare class BasicEventbridgeClient {
|
|
|
28
28
|
private appName;
|
|
29
29
|
private env;
|
|
30
30
|
private bus;
|
|
31
|
+
private client;
|
|
31
32
|
protected getLogger: () => ILogger;
|
|
32
33
|
protected context: SharedContext;
|
|
33
|
-
constructor(appName: string, env: string, getLogger: () => ILogger, context: SharedContext, bus: string);
|
|
34
|
+
constructor(appName: string, env: string, getLogger: () => ILogger, context: SharedContext, bus: string, customEndpoint?: string, customRegion?: string);
|
|
34
35
|
protected sendEvents(events: LaraEvent[]): Promise<EventDispatchResult>;
|
|
35
36
|
}
|
|
@@ -22,12 +22,13 @@ const MAX_BATCH_SIZE = 10;
|
|
|
22
22
|
* Usage will be done by extending this class and implementing methods that internally call the protected sendEvents method.
|
|
23
23
|
*/
|
|
24
24
|
class BasicEventbridgeClient {
|
|
25
|
-
constructor(appName, env, getLogger, context, bus) {
|
|
25
|
+
constructor(appName, env, getLogger, context, bus, customEndpoint, customRegion) {
|
|
26
26
|
this.appName = appName;
|
|
27
27
|
this.env = env;
|
|
28
28
|
this.bus = bus;
|
|
29
29
|
this.getLogger = getLogger;
|
|
30
30
|
this.context = context;
|
|
31
|
+
this.client = (0, aws_1.getEventbridgeClient)(customEndpoint, customRegion);
|
|
31
32
|
}
|
|
32
33
|
sendEvents(events) {
|
|
33
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -43,7 +44,7 @@ class BasicEventbridgeClient {
|
|
|
43
44
|
* Eventbridge in US-EAST-1 has a limit of 10.000 events/second.
|
|
44
45
|
* We should be fine without a limiter here.
|
|
45
46
|
*/
|
|
46
|
-
const results = yield Promise.all(eventsToSend.map((singleEventArray) =>
|
|
47
|
+
const results = yield Promise.all(eventsToSend.map((singleEventArray) => this.client
|
|
47
48
|
.putEvents(singleEventArray)
|
|
48
49
|
.promise()
|
|
49
50
|
.then(({ Entries, FailedEntryCount }) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basicEventbridgeClient.js","sourceRoot":"","sources":["../src/basicEventbridgeClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,
|
|
1
|
+
{"version":3,"file":"basicEventbridgeClient.js","sourceRoot":"","sources":["../src/basicEventbridgeClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,mCAAgD;AAChD,+BAIe;AACf,6EAA0E;AAwB1E;;GAEG;AACH,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;;GAGG;AACH,MAAa,sBAAsB;IASjC,YACE,OAAe,EACf,GAAW,EACX,SAAwB,EACxB,OAAsB,EACtB,GAAW,EACX,cAAuB,EACvB,YAAqB;QAErB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,IAAA,0BAAoB,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACnE,CAAC;IAEe,UAAU,CACxB,MAAmB;;YAEnB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAEhC,MAAM,YAAY,GAAG,IAAA,cAAK,EAAC,MAAM,CAAC;iBAC/B,GAAG,CAAC,CAAC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,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;gBAE/C,OAAO;oBACL,gBAAgB,EAAE;wBAChB,GAAG,CAAC,gBAAgB,IAAI,EAAE,CAAC;wBAC3B,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;qBACtB;oBACD,WAAW,EAAE,CAAC,WAAW,IAAI,CAAC,CAAC,GAAG,CAAC,cAAc,IAAI,CAAC,CAAC;iBACxD,CAAC;YACJ,CAAC,EACD;gBACE,gBAAgB,EAAE,EAAE;gBACpB,WAAW,EAAE,CAAC;aACf,CACF,CAAC;YAEF,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,GAAG,gBAAgB,CAAC;YAE3D,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAS,EACpC,gBAAgB,EAChB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CACzB,CAAC;YAEF,MAAM,CAAC,IAAI,CAAC,mCAAmC,EAAE;gBAC/C,UAAU;gBACV,MAAM;aACP,CAAC,CAAC;YAEH,OAAO;gBACL,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,EAAE,CAC7C,IAAA,aAAI,EAAC,eAAe,EAAE,OAAO,CAAC,CAC/B;gBACD,MAAM;gBACN,WAAW;aACZ,CAAC;QACJ,CAAC;KAAA;CACF;AAtHD,wDAsHC"}
|
|
@@ -15,21 +15,23 @@ const awsEventbridgeClient_1 = require("./aws/awsEventbridgeClient");
|
|
|
15
15
|
const mockEventbridgeClient_1 = require("./mockEventbridgeClient");
|
|
16
16
|
const eventbridgeFixture_1 = require("./mocks/fixtures/eventbridgeFixture");
|
|
17
17
|
jest.mock("./aws/awsEventbridgeClient");
|
|
18
|
-
const
|
|
18
|
+
const createClient = () => new mockEventbridgeClient_1.MockEventbridgeClient("appName", "env", () => (0, logger_1.createMockLogger)({}), new shared_context_1.SharedContext(), "busName");
|
|
19
19
|
describe("BasicEventbridgeClient", () => {
|
|
20
20
|
describe("sendEvents", () => {
|
|
21
21
|
describe("when there are two events", () => {
|
|
22
22
|
describe("when they're all successful", () => {
|
|
23
23
|
it("should send two requests, aggregate results, and show no failures", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
awsEventbridgeClient_1.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
awsEventbridgeClient_1.getEventbridgeClient.mockImplementationOnce((_, __) => ({
|
|
25
|
+
putEvents: jest
|
|
26
|
+
.fn()
|
|
27
|
+
.mockImplementationOnce((_) => ({
|
|
28
|
+
promise: () => Promise.resolve(eventbridgeFixture_1.twoSuccessfulResponses[0]),
|
|
29
|
+
}))
|
|
30
|
+
.mockImplementationOnce((_) => ({
|
|
31
|
+
promise: () => Promise.resolve(eventbridgeFixture_1.twoSuccessfulResponses[1]),
|
|
32
|
+
})),
|
|
30
33
|
}));
|
|
31
|
-
const response = yield
|
|
32
|
-
expect(awsEventbridgeClient_1.eventbridgeClient.putEvents).toHaveBeenCalledTimes(2);
|
|
34
|
+
const response = yield createClient().mockSendEvents(eventbridgeFixture_1.twoEventsToSend);
|
|
33
35
|
expect(response.failedCount).toBe(0);
|
|
34
36
|
expect(response.successful.length).toBe(2);
|
|
35
37
|
expect(response.failed.length).toBe(0);
|
|
@@ -37,15 +39,17 @@ describe("BasicEventbridgeClient", () => {
|
|
|
37
39
|
});
|
|
38
40
|
describe("when they're all unsuccessful", () => {
|
|
39
41
|
it("should send two requests, aggregate results, and show two failures", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
awsEventbridgeClient_1.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
awsEventbridgeClient_1.getEventbridgeClient.mockImplementationOnce((_, __) => ({
|
|
43
|
+
putEvents: jest
|
|
44
|
+
.fn()
|
|
45
|
+
.mockImplementationOnce((_) => ({
|
|
46
|
+
promise: () => Promise.resolve(eventbridgeFixture_1.twoUnsuccessfulResponses[0]),
|
|
47
|
+
}))
|
|
48
|
+
.mockImplementationOnce((_) => ({
|
|
49
|
+
promise: () => Promise.resolve(eventbridgeFixture_1.twoUnsuccessfulResponses[1]),
|
|
50
|
+
})),
|
|
46
51
|
}));
|
|
47
|
-
const response = yield
|
|
48
|
-
expect(awsEventbridgeClient_1.eventbridgeClient.putEvents).toHaveBeenCalledTimes(2);
|
|
52
|
+
const response = yield createClient().mockSendEvents(eventbridgeFixture_1.twoEventsToSend);
|
|
49
53
|
expect(response.failedCount).toBe(2);
|
|
50
54
|
expect(response.successful.length).toBe(0);
|
|
51
55
|
expect(response.failed.length).toBe(2);
|
|
@@ -57,15 +61,17 @@ describe("BasicEventbridgeClient", () => {
|
|
|
57
61
|
});
|
|
58
62
|
describe("when one isn't successful", () => {
|
|
59
63
|
it("should send two requests, aggregate results, and show one failure", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
awsEventbridgeClient_1.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
awsEventbridgeClient_1.getEventbridgeClient.mockImplementationOnce((_, __) => ({
|
|
65
|
+
putEvents: jest
|
|
66
|
+
.fn()
|
|
67
|
+
.mockImplementationOnce((_) => ({
|
|
68
|
+
promise: () => Promise.resolve(eventbridgeFixture_1.oneSuccessfulOneUnsuccessfulResponses[0]),
|
|
69
|
+
}))
|
|
70
|
+
.mockImplementationOnce((_) => ({
|
|
71
|
+
promise: () => Promise.resolve(eventbridgeFixture_1.oneSuccessfulOneUnsuccessfulResponses[1]),
|
|
72
|
+
})),
|
|
66
73
|
}));
|
|
67
|
-
const response = yield
|
|
68
|
-
expect(awsEventbridgeClient_1.eventbridgeClient.putEvents).toHaveBeenCalledTimes(2);
|
|
74
|
+
const response = yield createClient().mockSendEvents(eventbridgeFixture_1.twoEventsToSend);
|
|
69
75
|
expect(response.failedCount).toBe(1);
|
|
70
76
|
expect(response.successful.length).toBe(1);
|
|
71
77
|
expect(response.failed.length).toBe(1);
|
|
@@ -76,15 +82,17 @@ describe("BasicEventbridgeClient", () => {
|
|
|
76
82
|
});
|
|
77
83
|
describe("when a request to eventbridge fails", () => {
|
|
78
84
|
it("shouldn't break following requests and should count as a failure", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
-
awsEventbridgeClient_1.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
awsEventbridgeClient_1.getEventbridgeClient.mockImplementationOnce((_, __) => ({
|
|
86
|
+
putEvents: jest
|
|
87
|
+
.fn()
|
|
88
|
+
.mockImplementationOnce((_) => ({
|
|
89
|
+
promise: () => Promise.reject(),
|
|
90
|
+
}))
|
|
91
|
+
.mockImplementationOnce((_) => ({
|
|
92
|
+
promise: () => Promise.resolve(eventbridgeFixture_1.twoSuccessfulResponses[1]),
|
|
93
|
+
})),
|
|
85
94
|
}));
|
|
86
|
-
const response = yield
|
|
87
|
-
expect(awsEventbridgeClient_1.eventbridgeClient.putEvents).toHaveBeenCalledTimes(2);
|
|
95
|
+
const response = yield createClient().mockSendEvents(eventbridgeFixture_1.twoEventsToSend);
|
|
88
96
|
expect(response.failedCount).toBe(1);
|
|
89
97
|
expect(response.successful.length).toBe(1);
|
|
90
98
|
expect(response.failed.length).toBe(1);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basicEventbridgeClient.test.js","sourceRoot":"","sources":["../src/basicEventbridgeClient.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAAmD;AACnD,4DAAwD;AACxD,
|
|
1
|
+
{"version":3,"file":"basicEventbridgeClient.test.js","sourceRoot":"","sources":["../src/basicEventbridgeClient.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAAmD;AACnD,4DAAwD;AACxD,qEAAkE;AAClE,mEAAgE;AAChE,4EAO6C;AAE7C,IAAI,CAAC,IAAI,CAAC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AC;iBACN,CAAC,CAAC,CAAC;gBAEJ,MAAM,QAAQ,GAAG,MAAM,YAAY,EAAE,CAAC,cAAc,CAAC,oCAAe,CAAC,CAAC;gBAEtE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACrC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBAC3C,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;gBACvC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,2BAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC5D,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,aAAa,iCAEhE,2BAAM,CAAC,CAAC,CAAC,KACZ,GAAG,EAAE,iBAAiB,IAEzB,CAAC;YACJ,CAAC,CAAA,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -12,4 +12,5 @@ export declare type UpdatedEvent<Entity, Identifiers extends keyof PropertyKeys<
|
|
|
12
12
|
_previousValues?: UpdatedFields<Entity, Identifiers>;
|
|
13
13
|
modifiedKeys: (keyof UpdatedFields<Entity, Identifiers>)[];
|
|
14
14
|
};
|
|
15
|
+
export declare type DeletedEvent<Entity, Identifiers extends keyof PropertyKeys<Entity>> = UpdatedIdentifiers<Entity, Identifiers>;
|
|
15
16
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/eventbridge-client",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.8.2",
|
|
4
4
|
"description": "Alan's basic eventbridge client.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"cuid": "^2.1.8",
|
|
36
36
|
"lodash": "^4.17.21"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "98d47c12b292f89677b1d966bb1e788ff5ae1da5"
|
|
39
39
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createMockLogger } from "@alanszp/logger";
|
|
2
2
|
import { SharedContext } from "@alanszp/shared-context";
|
|
3
|
-
import {
|
|
3
|
+
import { getEventbridgeClient } from "./aws/awsEventbridgeClient";
|
|
4
4
|
import { MockEventbridgeClient } from "./mockEventbridgeClient";
|
|
5
5
|
import {
|
|
6
6
|
twoEventsToSend,
|
|
@@ -13,30 +13,35 @@ import {
|
|
|
13
13
|
|
|
14
14
|
jest.mock("./aws/awsEventbridgeClient");
|
|
15
15
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const createClient = () =>
|
|
17
|
+
new MockEventbridgeClient(
|
|
18
|
+
"appName",
|
|
19
|
+
"env",
|
|
20
|
+
() => createMockLogger({}),
|
|
21
|
+
new SharedContext(),
|
|
22
|
+
"busName"
|
|
23
|
+
);
|
|
23
24
|
|
|
24
25
|
describe("BasicEventbridgeClient", () => {
|
|
25
26
|
describe("sendEvents", () => {
|
|
26
27
|
describe("when there are two events", () => {
|
|
27
28
|
describe("when they're all successful", () => {
|
|
28
29
|
it("should send two requests, aggregate results, and show no failures", async () => {
|
|
29
|
-
(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
(getEventbridgeClient as jest.Mock).mockImplementationOnce(
|
|
31
|
+
(_, __) => ({
|
|
32
|
+
putEvents: jest
|
|
33
|
+
.fn()
|
|
34
|
+
.mockImplementationOnce((_) => ({
|
|
35
|
+
promise: () => Promise.resolve(twoSuccessfulResponses[0]),
|
|
36
|
+
}))
|
|
37
|
+
.mockImplementationOnce((_) => ({
|
|
38
|
+
promise: () => Promise.resolve(twoSuccessfulResponses[1]),
|
|
39
|
+
})),
|
|
40
|
+
})
|
|
41
|
+
);
|
|
36
42
|
|
|
37
|
-
const response = await
|
|
43
|
+
const response = await createClient().mockSendEvents(twoEventsToSend);
|
|
38
44
|
|
|
39
|
-
expect(eventbridgeClient.putEvents).toHaveBeenCalledTimes(2);
|
|
40
45
|
expect(response.failedCount).toBe(0);
|
|
41
46
|
expect(response.successful.length).toBe(2);
|
|
42
47
|
expect(response.failed.length).toBe(0);
|
|
@@ -45,17 +50,21 @@ describe("BasicEventbridgeClient", () => {
|
|
|
45
50
|
|
|
46
51
|
describe("when they're all unsuccessful", () => {
|
|
47
52
|
it("should send two requests, aggregate results, and show two failures", async () => {
|
|
48
|
-
(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
(getEventbridgeClient as jest.Mock).mockImplementationOnce(
|
|
54
|
+
(_, __) => ({
|
|
55
|
+
putEvents: jest
|
|
56
|
+
.fn()
|
|
57
|
+
.mockImplementationOnce((_) => ({
|
|
58
|
+
promise: () => Promise.resolve(twoUnsuccessfulResponses[0]),
|
|
59
|
+
}))
|
|
60
|
+
.mockImplementationOnce((_) => ({
|
|
61
|
+
promise: () => Promise.resolve(twoUnsuccessfulResponses[1]),
|
|
62
|
+
})),
|
|
63
|
+
})
|
|
64
|
+
);
|
|
55
65
|
|
|
56
|
-
const response = await
|
|
66
|
+
const response = await createClient().mockSendEvents(twoEventsToSend);
|
|
57
67
|
|
|
58
|
-
expect(eventbridgeClient.putEvents).toHaveBeenCalledTimes(2);
|
|
59
68
|
expect(response.failedCount).toBe(2);
|
|
60
69
|
expect(response.successful.length).toBe(0);
|
|
61
70
|
expect(response.failed.length).toBe(2);
|
|
@@ -78,19 +87,23 @@ describe("BasicEventbridgeClient", () => {
|
|
|
78
87
|
|
|
79
88
|
describe("when one isn't successful", () => {
|
|
80
89
|
it("should send two requests, aggregate results, and show one failure", async () => {
|
|
81
|
-
(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
(getEventbridgeClient as jest.Mock).mockImplementationOnce(
|
|
91
|
+
(_, __) => ({
|
|
92
|
+
putEvents: jest
|
|
93
|
+
.fn()
|
|
94
|
+
.mockImplementationOnce((_) => ({
|
|
95
|
+
promise: () =>
|
|
96
|
+
Promise.resolve(oneSuccessfulOneUnsuccessfulResponses[0]),
|
|
97
|
+
}))
|
|
98
|
+
.mockImplementationOnce((_) => ({
|
|
99
|
+
promise: () =>
|
|
100
|
+
Promise.resolve(oneSuccessfulOneUnsuccessfulResponses[1]),
|
|
101
|
+
})),
|
|
102
|
+
})
|
|
103
|
+
);
|
|
90
104
|
|
|
91
|
-
const response = await
|
|
105
|
+
const response = await createClient().mockSendEvents(twoEventsToSend);
|
|
92
106
|
|
|
93
|
-
expect(eventbridgeClient.putEvents).toHaveBeenCalledTimes(2);
|
|
94
107
|
expect(response.failedCount).toBe(1);
|
|
95
108
|
expect(response.successful.length).toBe(1);
|
|
96
109
|
expect(response.failed.length).toBe(1);
|
|
@@ -104,19 +117,22 @@ describe("BasicEventbridgeClient", () => {
|
|
|
104
117
|
});
|
|
105
118
|
});
|
|
106
119
|
});
|
|
120
|
+
|
|
107
121
|
describe("when a request to eventbridge fails", () => {
|
|
108
122
|
it("shouldn't break following requests and should count as a failure", async () => {
|
|
109
|
-
(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
(getEventbridgeClient as jest.Mock).mockImplementationOnce((_, __) => ({
|
|
124
|
+
putEvents: jest
|
|
125
|
+
.fn()
|
|
126
|
+
.mockImplementationOnce((_) => ({
|
|
127
|
+
promise: () => Promise.reject(),
|
|
128
|
+
}))
|
|
129
|
+
.mockImplementationOnce((_) => ({
|
|
130
|
+
promise: () => Promise.resolve(twoSuccessfulResponses[1]),
|
|
131
|
+
})),
|
|
132
|
+
}));
|
|
116
133
|
|
|
117
|
-
const response = await
|
|
134
|
+
const response = await createClient().mockSendEvents(twoEventsToSend);
|
|
118
135
|
|
|
119
|
-
expect(eventbridgeClient.putEvents).toHaveBeenCalledTimes(2);
|
|
120
136
|
expect(response.failedCount).toBe(1);
|
|
121
137
|
expect(response.successful.length).toBe(1);
|
|
122
138
|
expect(response.failed.length).toBe(1);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { ILogger } from "@alanszp/logger";
|
|
2
2
|
import { SharedContext } from "@alanszp/shared-context";
|
|
3
|
-
import { chain,
|
|
3
|
+
import { chain, omit, partition } from "lodash";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
EventRequest,
|
|
5
|
+
getEventbridgeClient,
|
|
7
6
|
PutEventEntryRequest,
|
|
8
7
|
PutEventEntryResponse,
|
|
9
8
|
} from "./aws";
|
|
@@ -44,6 +43,7 @@ export class BasicEventbridgeClient {
|
|
|
44
43
|
private appName: string;
|
|
45
44
|
private env: string;
|
|
46
45
|
private bus: string;
|
|
46
|
+
private client;
|
|
47
47
|
|
|
48
48
|
protected getLogger: () => ILogger;
|
|
49
49
|
protected context: SharedContext;
|
|
@@ -53,13 +53,16 @@ export class BasicEventbridgeClient {
|
|
|
53
53
|
env: string,
|
|
54
54
|
getLogger: () => ILogger,
|
|
55
55
|
context: SharedContext,
|
|
56
|
-
bus: string
|
|
56
|
+
bus: string,
|
|
57
|
+
customEndpoint?: string,
|
|
58
|
+
customRegion?: string
|
|
57
59
|
) {
|
|
58
60
|
this.appName = appName;
|
|
59
61
|
this.env = env;
|
|
60
62
|
this.bus = bus;
|
|
61
63
|
this.getLogger = getLogger;
|
|
62
64
|
this.context = context;
|
|
65
|
+
this.client = getEventbridgeClient(customEndpoint, customRegion);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
protected async sendEvents(
|
|
@@ -90,7 +93,7 @@ export class BasicEventbridgeClient {
|
|
|
90
93
|
*/
|
|
91
94
|
const results = await Promise.all(
|
|
92
95
|
eventsToSend.map((singleEventArray) =>
|
|
93
|
-
|
|
96
|
+
this.client
|
|
94
97
|
.putEvents(singleEventArray)
|
|
95
98
|
.promise()
|
|
96
99
|
.then(({ Entries, FailedEntryCount }) => ({
|
|
@@ -32,3 +32,8 @@ export type UpdatedEvent<
|
|
|
32
32
|
_previousValues?: UpdatedFields<Entity, Identifiers>;
|
|
33
33
|
modifiedKeys: (keyof UpdatedFields<Entity, Identifiers>)[];
|
|
34
34
|
};
|
|
35
|
+
|
|
36
|
+
export type DeletedEvent<
|
|
37
|
+
Entity,
|
|
38
|
+
Identifiers extends keyof PropertyKeys<Entity>
|
|
39
|
+
> = UpdatedIdentifiers<Entity, Identifiers>;
|