@alanszp/eventbridge-client 7.0.1 → 7.1.0
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/basicEventbridgeClient.d.ts +1 -3
- package/dist/basicEventbridgeClient.js.map +1 -1
- package/dist/helpers/mapLaraEventToAWSEvent.d.ts +1 -1
- package/dist/helpers/mapLaraEventToAWSEvent.js +3 -3
- package/dist/helpers/mapLaraEventToAWSEvent.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types/UpdatedEvent.d.ts +15 -0
- package/dist/types/UpdatedEvent.js +3 -0
- package/dist/types/UpdatedEvent.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +14 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +2 -2
- package/src/basicEventbridgeClient.ts +1 -3
- package/src/helpers/mapLaraEventToAWSEvent.ts +3 -3
- package/src/index.ts +1 -0
- package/src/types/UpdatedEvent.ts +34 -0
- package/src/types/index.ts +1 -0
|
@@ -5,14 +5,12 @@ import { PutEventEntryResponse } from "./aws";
|
|
|
5
5
|
* Represents an event that is sent in the Lara ecosystem.
|
|
6
6
|
*
|
|
7
7
|
* @property topic: The topic of the event. E.g.: if an employee was created, topid would be employee.created.
|
|
8
|
-
* @property lid: The lifecycle id to identify the execution that generated the event.
|
|
9
8
|
* @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
|
|
10
9
|
* will be overwritten by the id sent to this method in the parameters.
|
|
11
10
|
*/
|
|
12
11
|
export declare type LaraEvent = {
|
|
13
12
|
topic: string;
|
|
14
|
-
|
|
15
|
-
modifiedKeys: string[];
|
|
13
|
+
body: Record<string, unknown>;
|
|
16
14
|
};
|
|
17
15
|
export interface EventDispatchResult {
|
|
18
16
|
successful: PutEventEntryResponse[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basicEventbridgeClient.js","sourceRoot":"","sources":["../src/basicEventbridgeClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,mCAA4C;AAC5C,+BAA+E;AAC/E,6EAA0E;
|
|
1
|
+
{"version":3,"file":"basicEventbridgeClient.js","sourceRoot":"","sources":["../src/basicEventbridgeClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,mCAA4C;AAC5C,+BAA+E;AAC/E,6EAA0E;AAoB1E,MAAM,8BAA8B,GAAG,eAAe,CAAC;AAEvD;;;GAGG;AACH,MAAa,sBAAsB;IAQjC,YACE,OAAe,EACf,GAAW,EACX,SAAwB,EACxB,OAAsB,EACtB,GAAG,GAAG,GAAG,GAAG,IAAI,8BAA8B,EAAE;QAEhD,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;IACzB,CAAC;IAEe,UAAU,CACxB,MAAmB;;YAEnB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAEhC,MAAM,YAAY,GAAiB;gBACjC,OAAO,EAAE,IAAA,gBAAO,EACd,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACnB,IAAA,+CAAsB,EACpB,KAAK,EACL,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,GAAG,EACR,MAAM,EACN,IAAI,CAAC,OAAO,CACb,CACF,CACF;aACF,CAAC;YAEF,MAAM,MAAM,GAAG,MAAM,uBAAiB,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC;YACzE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;YAC1D,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,IAAA,kBAAS,EAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAE1E,MAAM,CAAC,IAAI,CAAC,mCAAmC,EAAE;gBAC/C,UAAU;gBACV,MAAM;aACP,CAAC,CAAC;YAEH,OAAO;gBACL,UAAU;gBACV,MAAM;gBACN,WAAW;aACZ,CAAC;QACJ,CAAC;KAAA;CACF;AAzDD,wDAyDC"}
|
|
@@ -2,4 +2,4 @@ import { LaraEvent } from "../basicEventbridgeClient";
|
|
|
2
2
|
import { PutEventsRequestEntry } from "aws-sdk/clients/eventbridge";
|
|
3
3
|
import type { ILogger } from "@alanszp/logger";
|
|
4
4
|
import type { SharedContext } from "@alanszp/shared-context";
|
|
5
|
-
export declare function mapLaraEventToAWSEvent({ topic,
|
|
5
|
+
export declare function mapLaraEventToAWSEvent({ topic, body }: LaraEvent, env: string, appName: string, bus: string, logger: ILogger, context: SharedContext): PutEventsRequestEntry | undefined;
|
|
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.mapLaraEventToAWSEvent = void 0;
|
|
7
7
|
const lodash_1 = require("lodash");
|
|
8
8
|
const cuid_1 = __importDefault(require("cuid"));
|
|
9
|
-
function mapLaraEventToAWSEvent({ topic,
|
|
9
|
+
function mapLaraEventToAWSEvent({ topic, body }, env, appName, bus, logger, context) {
|
|
10
10
|
const lid = context.getLifecycleId() || (0, cuid_1.default)();
|
|
11
11
|
const oldlLch = context.getLifecycleChain();
|
|
12
12
|
const lch = (0, lodash_1.compact)([oldlLch, "aws.eventbridge"]).join(",");
|
|
13
13
|
try {
|
|
14
14
|
return {
|
|
15
15
|
DetailType: topic,
|
|
16
|
-
Detail: JSON.stringify(Object.assign(Object.assign({},
|
|
16
|
+
Detail: JSON.stringify(Object.assign(Object.assign({}, body), { lch })),
|
|
17
17
|
Source: `${env}.lara.${appName}`,
|
|
18
18
|
EventBusName: bus,
|
|
19
19
|
Time: new Date(),
|
|
@@ -21,7 +21,7 @@ function mapLaraEventToAWSEvent({ topic, entity }, env, appName, bus, logger, co
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
catch (_a) {
|
|
24
|
-
const org =
|
|
24
|
+
const org = body.organizationReference;
|
|
25
25
|
logger.error("eventbridge.client.map_lara_to_aws_event.parse_error", {
|
|
26
26
|
topic,
|
|
27
27
|
org,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapLaraEventToAWSEvent.js","sourceRoot":"","sources":["../../src/helpers/mapLaraEventToAWSEvent.ts"],"names":[],"mappings":";;;;;;AAIA,mCAAiC;AACjC,gDAAwB;AAExB,SAAgB,sBAAsB,CACpC,EAAE,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"mapLaraEventToAWSEvent.js","sourceRoot":"","sources":["../../src/helpers/mapLaraEventToAWSEvent.ts"],"names":[],"mappings":";;;;;;AAIA,mCAAiC;AACjC,gDAAwB;AAExB,SAAgB,sBAAsB,CACpC,EAAE,KAAK,EAAE,IAAI,EAAa,EAC1B,GAAW,EACX,OAAe,EACf,GAAW,EACX,MAAe,EACf,OAAsB;IAEtB,MAAM,GAAG,GAAG,OAAO,CAAC,cAAc,EAAE,IAAI,IAAA,cAAI,GAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAC5C,MAAM,GAAG,GAAG,IAAA,gBAAO,EAAC,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5D,IAAI;QACF,OAAO;YACL,UAAU,EAAE,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,SAAS,iCAAM,IAAI,KAAE,GAAG,IAAG;YACxC,MAAM,EAAE,GAAG,GAAG,SAAS,OAAO,EAAE;YAChC,YAAY,EAAE,GAAG;YACjB,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,WAAW,EAAE,GAAG;SACjB,CAAC;KACH;IAAC,WAAM;QACN,MAAM,GAAG,GAAG,IAAI,CAAC,qBAA+B,CAAC;QACjD,MAAM,CAAC,KAAK,CAAC,sDAAsD,EAAE;YACnE,KAAK;YACL,GAAG;YACH,GAAG;SACJ,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AA7BD,wDA6BC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -12,4 +12,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./basicEventbridgeClient"), exports);
|
|
14
14
|
__exportStar(require("./aws/awsTypes"), exports);
|
|
15
|
+
__exportStar(require("./types"), exports);
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAyC;AACzC,iDAA+B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAyC;AACzC,iDAA+B;AAC/B,0CAAwB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare type PropertyKeys<T> = {
|
|
2
|
+
[K in keyof T as T[K] extends Function ? never : K]: T[K];
|
|
3
|
+
};
|
|
4
|
+
declare type UpdatedIdentifiers<Entity, Identifiers extends keyof PropertyKeys<Entity>, PartialEntity = Pick<PropertyKeys<Entity>, Identifiers>> = {
|
|
5
|
+
[K in keyof PartialEntity]: PartialEntity[K];
|
|
6
|
+
};
|
|
7
|
+
declare type UpdatedFields<Entity, Identifiers extends keyof PropertyKeys<Entity>, PartialEntity = Omit<PropertyKeys<Entity>, Identifiers>> = {
|
|
8
|
+
[K in keyof PartialEntity]?: PartialEntity[K];
|
|
9
|
+
};
|
|
10
|
+
export declare type CreatedEvent<Entity, Identifiers extends keyof PropertyKeys<Entity>> = UpdatedFields<Entity, Identifiers>;
|
|
11
|
+
export declare type UpdatedEvent<Entity, Identifiers extends keyof PropertyKeys<Entity>> = UpdatedFields<Entity, Identifiers> & UpdatedIdentifiers<Entity, Identifiers> & {
|
|
12
|
+
_previousValues?: UpdatedFields<Entity, Identifiers>;
|
|
13
|
+
modifiedKeys: (keyof UpdatedFields<Entity, Identifiers>)[];
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UpdatedEvent.js","sourceRoot":"","sources":["../../src/types/UpdatedEvent.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./UpdatedEvent";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./UpdatedEvent"), exports);
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA+B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alanszp/eventbridge-client",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Alan's basic eventbridge client.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"cuid": "^2.1.8",
|
|
31
31
|
"lodash": "^4.17.21"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "d6d13089bfd66943887f9cee0cadc28210cf0116"
|
|
34
34
|
}
|
|
@@ -8,14 +8,12 @@ import { mapLaraEventToAWSEvent } from "./helpers/mapLaraEventToAWSEvent";
|
|
|
8
8
|
* Represents an event that is sent in the Lara ecosystem.
|
|
9
9
|
*
|
|
10
10
|
* @property topic: The topic of the event. E.g.: if an employee was created, topid would be employee.created.
|
|
11
|
-
* @property lid: The lifecycle id to identify the execution that generated the event.
|
|
12
11
|
* @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
|
|
13
12
|
* will be overwritten by the id sent to this method in the parameters.
|
|
14
13
|
*/
|
|
15
14
|
export type LaraEvent = {
|
|
16
15
|
topic: string;
|
|
17
|
-
|
|
18
|
-
modifiedKeys: string[];
|
|
16
|
+
body: Record<string, unknown>;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
export interface EventDispatchResult {
|
|
@@ -6,7 +6,7 @@ import { compact } from "lodash";
|
|
|
6
6
|
import cuid from "cuid";
|
|
7
7
|
|
|
8
8
|
export function mapLaraEventToAWSEvent(
|
|
9
|
-
{ topic,
|
|
9
|
+
{ topic, body }: LaraEvent,
|
|
10
10
|
env: string,
|
|
11
11
|
appName: string,
|
|
12
12
|
bus: string,
|
|
@@ -19,14 +19,14 @@ export function mapLaraEventToAWSEvent(
|
|
|
19
19
|
try {
|
|
20
20
|
return {
|
|
21
21
|
DetailType: topic,
|
|
22
|
-
Detail: JSON.stringify({ ...
|
|
22
|
+
Detail: JSON.stringify({ ...body, lch }),
|
|
23
23
|
Source: `${env}.lara.${appName}`,
|
|
24
24
|
EventBusName: bus,
|
|
25
25
|
Time: new Date(),
|
|
26
26
|
TraceHeader: lid,
|
|
27
27
|
};
|
|
28
28
|
} catch {
|
|
29
|
-
const org =
|
|
29
|
+
const org = body.organizationReference as string;
|
|
30
30
|
logger.error("eventbridge.client.map_lara_to_aws_event.parse_error", {
|
|
31
31
|
topic,
|
|
32
32
|
org,
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./UpdatedEvent";
|