@alanszp/eventbridge-client 12.0.2 → 12.0.3

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 (151) hide show
  1. package/package.json +4 -7
  2. package/.gitignore +0 -3
  3. package/.npmignore +0 -3
  4. package/node_modules/@cspotcode/source-map-support/LICENSE.md +0 -21
  5. package/node_modules/@cspotcode/source-map-support/README.md +0 -289
  6. package/node_modules/@cspotcode/source-map-support/browser-source-map-support.js +0 -114
  7. package/node_modules/@cspotcode/source-map-support/package.json +0 -50
  8. package/node_modules/@cspotcode/source-map-support/register-hook-require.d.ts +0 -7
  9. package/node_modules/@cspotcode/source-map-support/register-hook-require.js +0 -3
  10. package/node_modules/@cspotcode/source-map-support/register.d.ts +0 -7
  11. package/node_modules/@cspotcode/source-map-support/register.js +0 -1
  12. package/node_modules/@cspotcode/source-map-support/source-map-support.d.ts +0 -76
  13. package/node_modules/@cspotcode/source-map-support/source-map-support.js +0 -938
  14. package/node_modules/@jridgewell/trace-mapping/LICENSE +0 -19
  15. package/node_modules/@jridgewell/trace-mapping/README.md +0 -193
  16. package/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs +0 -514
  17. package/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs.map +0 -1
  18. package/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js +0 -528
  19. package/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js.map +0 -1
  20. package/node_modules/@jridgewell/trace-mapping/dist/types/any-map.d.ts +0 -8
  21. package/node_modules/@jridgewell/trace-mapping/dist/types/binary-search.d.ts +0 -32
  22. package/node_modules/@jridgewell/trace-mapping/dist/types/by-source.d.ts +0 -7
  23. package/node_modules/@jridgewell/trace-mapping/dist/types/resolve.d.ts +0 -1
  24. package/node_modules/@jridgewell/trace-mapping/dist/types/sort.d.ts +0 -2
  25. package/node_modules/@jridgewell/trace-mapping/dist/types/sourcemap-segment.d.ts +0 -16
  26. package/node_modules/@jridgewell/trace-mapping/dist/types/strip-filename.d.ts +0 -4
  27. package/node_modules/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts +0 -70
  28. package/node_modules/@jridgewell/trace-mapping/dist/types/types.d.ts +0 -85
  29. package/node_modules/@jridgewell/trace-mapping/package.json +0 -70
  30. package/node_modules/@types/node/LICENSE +0 -21
  31. package/node_modules/@types/node/README.md +0 -15
  32. package/node_modules/@types/node/assert/strict.d.ts +0 -8
  33. package/node_modules/@types/node/assert.d.ts +0 -996
  34. package/node_modules/@types/node/async_hooks.d.ts +0 -539
  35. package/node_modules/@types/node/buffer.d.ts +0 -2362
  36. package/node_modules/@types/node/child_process.d.ts +0 -1540
  37. package/node_modules/@types/node/cluster.d.ts +0 -432
  38. package/node_modules/@types/node/console.d.ts +0 -415
  39. package/node_modules/@types/node/constants.d.ts +0 -19
  40. package/node_modules/@types/node/crypto.d.ts +0 -4487
  41. package/node_modules/@types/node/dgram.d.ts +0 -596
  42. package/node_modules/@types/node/diagnostics_channel.d.ts +0 -545
  43. package/node_modules/@types/node/dns/promises.d.ts +0 -425
  44. package/node_modules/@types/node/dns.d.ts +0 -809
  45. package/node_modules/@types/node/dom-events.d.ts +0 -122
  46. package/node_modules/@types/node/domain.d.ts +0 -170
  47. package/node_modules/@types/node/events.d.ts +0 -879
  48. package/node_modules/@types/node/fs/promises.d.ts +0 -1239
  49. package/node_modules/@types/node/fs.d.ts +0 -4311
  50. package/node_modules/@types/node/globals.d.ts +0 -411
  51. package/node_modules/@types/node/globals.global.d.ts +0 -1
  52. package/node_modules/@types/node/http.d.ts +0 -1887
  53. package/node_modules/@types/node/http2.d.ts +0 -2382
  54. package/node_modules/@types/node/https.d.ts +0 -550
  55. package/node_modules/@types/node/index.d.ts +0 -88
  56. package/node_modules/@types/node/inspector.d.ts +0 -2747
  57. package/node_modules/@types/node/module.d.ts +0 -315
  58. package/node_modules/@types/node/net.d.ts +0 -949
  59. package/node_modules/@types/node/os.d.ts +0 -478
  60. package/node_modules/@types/node/package.json +0 -229
  61. package/node_modules/@types/node/path.d.ts +0 -191
  62. package/node_modules/@types/node/perf_hooks.d.ts +0 -645
  63. package/node_modules/@types/node/process.d.ts +0 -1561
  64. package/node_modules/@types/node/punycode.d.ts +0 -117
  65. package/node_modules/@types/node/querystring.d.ts +0 -141
  66. package/node_modules/@types/node/readline/promises.d.ts +0 -150
  67. package/node_modules/@types/node/readline.d.ts +0 -539
  68. package/node_modules/@types/node/repl.d.ts +0 -430
  69. package/node_modules/@types/node/stream/consumers.d.ts +0 -12
  70. package/node_modules/@types/node/stream/promises.d.ts +0 -83
  71. package/node_modules/@types/node/stream/web.d.ts +0 -366
  72. package/node_modules/@types/node/stream.d.ts +0 -1701
  73. package/node_modules/@types/node/string_decoder.d.ts +0 -67
  74. package/node_modules/@types/node/test.d.ts +0 -1465
  75. package/node_modules/@types/node/timers/promises.d.ts +0 -93
  76. package/node_modules/@types/node/timers.d.ts +0 -240
  77. package/node_modules/@types/node/tls.d.ts +0 -1210
  78. package/node_modules/@types/node/trace_events.d.ts +0 -182
  79. package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
  80. package/node_modules/@types/node/ts4.8/assert.d.ts +0 -996
  81. package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -539
  82. package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2362
  83. package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1540
  84. package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
  85. package/node_modules/@types/node/ts4.8/console.d.ts +0 -415
  86. package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
  87. package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4487
  88. package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -596
  89. package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -545
  90. package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -425
  91. package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
  92. package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
  93. package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
  94. package/node_modules/@types/node/ts4.8/events.d.ts +0 -879
  95. package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1239
  96. package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4311
  97. package/node_modules/@types/node/ts4.8/globals.d.ts +0 -411
  98. package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
  99. package/node_modules/@types/node/ts4.8/http.d.ts +0 -1887
  100. package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2382
  101. package/node_modules/@types/node/ts4.8/https.d.ts +0 -550
  102. package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
  103. package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2747
  104. package/node_modules/@types/node/ts4.8/module.d.ts +0 -315
  105. package/node_modules/@types/node/ts4.8/net.d.ts +0 -949
  106. package/node_modules/@types/node/ts4.8/os.d.ts +0 -478
  107. package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
  108. package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -645
  109. package/node_modules/@types/node/ts4.8/process.d.ts +0 -1561
  110. package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
  111. package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
  112. package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -150
  113. package/node_modules/@types/node/ts4.8/readline.d.ts +0 -539
  114. package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
  115. package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
  116. package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
  117. package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -366
  118. package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1701
  119. package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
  120. package/node_modules/@types/node/ts4.8/test.d.ts +0 -1465
  121. package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
  122. package/node_modules/@types/node/ts4.8/timers.d.ts +0 -240
  123. package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1210
  124. package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -182
  125. package/node_modules/@types/node/ts4.8/tty.d.ts +0 -208
  126. package/node_modules/@types/node/ts4.8/url.d.ts +0 -927
  127. package/node_modules/@types/node/ts4.8/util.d.ts +0 -2183
  128. package/node_modules/@types/node/ts4.8/v8.d.ts +0 -764
  129. package/node_modules/@types/node/ts4.8/vm.d.ts +0 -903
  130. package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -179
  131. package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -691
  132. package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
  133. package/node_modules/@types/node/tty.d.ts +0 -208
  134. package/node_modules/@types/node/url.d.ts +0 -927
  135. package/node_modules/@types/node/util.d.ts +0 -2183
  136. package/node_modules/@types/node/v8.d.ts +0 -764
  137. package/node_modules/@types/node/vm.d.ts +0 -903
  138. package/node_modules/@types/node/wasi.d.ts +0 -179
  139. package/node_modules/@types/node/worker_threads.d.ts +0 -691
  140. package/node_modules/@types/node/zlib.d.ts +0 -517
  141. package/src/aws/awsEventbridgeClient.ts +0 -4
  142. package/src/aws/awsTypes.ts +0 -10
  143. package/src/aws/index.ts +0 -2
  144. package/src/basicEventbridgeClient.test.ts +0 -149
  145. package/src/basicEventbridgeClient.ts +0 -160
  146. package/src/helpers/mapLaraEventToAWSEvent.ts +0 -37
  147. package/src/index.ts +0 -3
  148. package/src/mockEventbridgeClient.ts +0 -11
  149. package/src/mocks/fixtures/eventbridgeFixture.ts +0 -41
  150. package/src/types/UpdatedEvent.ts +0 -39
  151. package/src/types/index.ts +0 -1
@@ -1,160 +0,0 @@
1
- import { ILogger } from "@alanszp/logger";
2
- import { SharedContext } from "@alanszp/shared-context";
3
- import { chain, omit, partition } from "lodash";
4
- import {
5
- getEventbridgeClient,
6
- PutEventEntryRequest,
7
- PutEventEntryResponse,
8
- } from "./aws";
9
- import { mapLaraEventToAWSEvent } from "./helpers/mapLaraEventToAWSEvent";
10
-
11
- /**
12
- * Represents an event that is sent in the Lara ecosystem.
13
- *
14
- * @property topic: The topic of the event. E.g.: if an employee was created, topid would be employee.created.
15
- * @property body: The body of the event. This will be used to match in the rules, along with the topic and maybe the id. If it has a property id it
16
- * will be overwritten by the id sent to this method in the parameters.
17
- */
18
- export type LaraEvent = {
19
- topic: string;
20
- body: Record<string, unknown>;
21
- };
22
-
23
- export type PutEventFailedEntryResponse = PutEventEntryResponse & {
24
- event: PutEventEntryRequest;
25
- };
26
-
27
- export interface EventDispatchResult {
28
- successful: PutEventEntryResponse[];
29
- failed: PutEventFailedEntryResponse[];
30
- failedCount: number | undefined;
31
- }
32
-
33
- /**
34
- * Max batch size for the putEvents request defined by AWS.
35
- */
36
- const MAX_BATCH_SIZE = 10;
37
-
38
- /**
39
- * Basic client for Eventbridge.
40
- * Usage will be done by extending this class and implementing methods that internally call the protected sendEvents method.
41
- */
42
- export class BasicEventbridgeClient {
43
- private appName: string;
44
- private env: string;
45
- private bus: string;
46
- private client;
47
-
48
- protected getLogger: () => ILogger;
49
- protected context: SharedContext;
50
-
51
- constructor(
52
- appName: string,
53
- env: string,
54
- getLogger: () => ILogger,
55
- context: SharedContext,
56
- bus: string,
57
- customEndpoint?: string,
58
- customRegion?: string
59
- ) {
60
- this.appName = appName;
61
- this.env = env;
62
- this.bus = bus;
63
- this.getLogger = getLogger;
64
- this.context = context;
65
- this.client = getEventbridgeClient(customEndpoint, customRegion);
66
- }
67
-
68
- protected async sendEvents(
69
- events: LaraEvent[]
70
- ): Promise<EventDispatchResult> {
71
- const logger = this.getLogger();
72
-
73
- const eventsToSend = chain(events)
74
- .map((event) =>
75
- mapLaraEventToAWSEvent(
76
- event,
77
- this.env,
78
- this.appName,
79
- this.bus,
80
- logger,
81
- this.context
82
- )
83
- )
84
- .compact()
85
- .map((event) => ({
86
- Entries: [event],
87
- }))
88
- .value();
89
-
90
- /**
91
- * Eventbridge in US-EAST-1 has a limit of 10.000 events/second.
92
- * We should be fine without a limiter here.
93
- */
94
- const results = await Promise.all(
95
- eventsToSend.map((singleEventArray) =>
96
- this.client
97
- .putEvents(singleEventArray)
98
- .promise()
99
- .then(({ Entries, FailedEntryCount }) => ({
100
- FailedEntryCount,
101
- Entries: [
102
- {
103
- ...(Entries || [])[0],
104
- event: singleEventArray.Entries[0],
105
- },
106
- ],
107
- }))
108
- .catch((error) => ({
109
- FailedEntryCount: 1,
110
- Entries: [
111
- {
112
- EventId: undefined,
113
- ErrorMessage: JSON.stringify(error),
114
- event: singleEventArray.Entries[0],
115
- },
116
- ],
117
- }))
118
- )
119
- );
120
-
121
- const aggregatedResult = results.reduce(
122
- (prev, act) => {
123
- const { Entries: NewEntries, FailedEntryCount: newFailedCount } = act;
124
- const { eventsDispatched, failedCount } = prev;
125
-
126
- return {
127
- eventsDispatched: [
128
- ...(eventsDispatched || []),
129
- ...(NewEntries || []),
130
- ],
131
- failedCount: (failedCount || 0) + (newFailedCount || 0),
132
- };
133
- },
134
- {
135
- eventsDispatched: [],
136
- failedCount: 0,
137
- }
138
- );
139
-
140
- const { eventsDispatched, failedCount } = aggregatedResult;
141
-
142
- const [successful, failed] = partition(
143
- eventsDispatched,
144
- (entry) => entry.EventId
145
- );
146
-
147
- logger.info("eventbridge.client.sendEvents.end", {
148
- successful,
149
- failed,
150
- });
151
-
152
- return {
153
- successful: successful.map((eventDispatched) =>
154
- omit(eventDispatched, "event")
155
- ),
156
- failed,
157
- failedCount,
158
- };
159
- }
160
- }
@@ -1,37 +0,0 @@
1
- import { LaraEvent } from "../basicEventbridgeClient";
2
- import { PutEventsRequestEntry } from "aws-sdk/clients/eventbridge";
3
- import type { ILogger } from "@alanszp/logger";
4
- import type { SharedContext } from "@alanszp/shared-context";
5
- import { compact } from "lodash";
6
- import { createId } from "@paralleldrive/cuid2";
7
-
8
- export function mapLaraEventToAWSEvent(
9
- { topic, body }: LaraEvent,
10
- env: string,
11
- appName: string,
12
- bus: string,
13
- logger: ILogger,
14
- context: SharedContext
15
- ): PutEventsRequestEntry | undefined {
16
- const lid = context.getLifecycleId() || createId();
17
- const oldlLch = context.getLifecycleChain();
18
- const lch = compact([oldlLch, "aws.eb"]).join(",");
19
- try {
20
- return {
21
- DetailType: topic,
22
- Detail: JSON.stringify({ ...body, lch, lid }), // lid is included here since the TraceHeader is not sent to the targets by aws
23
- Source: `${env}.lara.${appName}`,
24
- EventBusName: bus,
25
- Time: new Date(),
26
- TraceHeader: lid,
27
- };
28
- } catch {
29
- const org = body.organizationReference as string;
30
- logger.error("eventbridge.client.map_lara_to_aws_event.parse_error", {
31
- topic,
32
- org,
33
- lid,
34
- });
35
- return undefined;
36
- }
37
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./basicEventbridgeClient";
2
- export * from "./aws/awsTypes";
3
- export * from "./types";
@@ -1,11 +0,0 @@
1
- import {
2
- BasicEventbridgeClient,
3
- EventDispatchResult,
4
- LaraEvent,
5
- } from "./basicEventbridgeClient";
6
-
7
- export class MockEventbridgeClient extends BasicEventbridgeClient {
8
- public mockSendEvents(events: LaraEvent[]): Promise<EventDispatchResult> {
9
- return this.sendEvents(events);
10
- }
11
- }
@@ -1,41 +0,0 @@
1
- export const topics = ["topic1", "topic2"];
2
-
3
- export const events = [{ property: "1" }, { property: "2" }];
4
-
5
- export const twoEventsToSend = [
6
- { topic: topics[0], body: events[0] },
7
- { topic: topics[1], body: events[1] },
8
- ];
9
-
10
- export const twoSuccessfulResponses = [
11
- {
12
- Entries: [{ EventId: 1 }],
13
- FailedEntryCount: 0,
14
- },
15
- {
16
- Entries: [{ EventId: 2 }],
17
- FailedEntryCount: 0,
18
- },
19
- ];
20
-
21
- export const twoUnsuccessfulResponses = [
22
- {
23
- Entries: [{ EventId: undefined }],
24
- FailedEntryCount: 1,
25
- },
26
- {
27
- Entries: [{ EventId: undefined }],
28
- FailedEntryCount: 1,
29
- },
30
- ];
31
-
32
- export const oneSuccessfulOneUnsuccessfulResponses = [
33
- {
34
- Entries: [{ EventId: 1 }],
35
- FailedEntryCount: 0,
36
- },
37
- {
38
- Entries: [{ EventId: null }],
39
- FailedEntryCount: 1,
40
- },
41
- ];
@@ -1,39 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-types
2
- type PropertyKeys<T> = {
3
- [K in keyof T as T[K] extends Function ? never : K]: T[K];
4
- };
5
-
6
- type UpdatedIdentifiers<
7
- Entity,
8
- Identifiers extends keyof PropertyKeys<Entity>,
9
- PartialEntity = Pick<PropertyKeys<Entity>, Identifiers>
10
- > = {
11
- [K in keyof PartialEntity]: PartialEntity[K];
12
- };
13
-
14
- type UpdatedFields<
15
- Entity,
16
- Identifiers extends keyof PropertyKeys<Entity>,
17
- PartialEntity = Omit<PropertyKeys<Entity>, Identifiers>
18
- > = {
19
- [K in keyof PartialEntity]?: PartialEntity[K];
20
- };
21
-
22
- export type CreatedEvent<
23
- Entity,
24
- Identifiers extends keyof PropertyKeys<Entity>
25
- > = UpdatedFields<Entity, Identifiers>;
26
-
27
- export type UpdatedEvent<
28
- Entity,
29
- Identifiers extends keyof PropertyKeys<Entity>
30
- > = UpdatedFields<Entity, Identifiers> &
31
- UpdatedIdentifiers<Entity, Identifiers> & {
32
- _previousValues?: UpdatedFields<Entity, Identifiers>;
33
- modifiedKeys: (keyof UpdatedFields<Entity, Identifiers>)[];
34
- };
35
-
36
- export type DeletedEvent<
37
- Entity,
38
- Identifiers extends keyof PropertyKeys<Entity>
39
- > = UpdatedIdentifiers<Entity, Identifiers>;
@@ -1 +0,0 @@
1
- export * from "./UpdatedEvent";