@itzworking/events-manager 0.0.150 → 0.0.156
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/README.md +6 -10
- package/{src → dist}/application-event-detail-metadata.d.ts +1 -0
- package/dist/application-event-detail-metadata.d.ts.map +1 -0
- package/dist/application-event-detail-metadata.js +35 -0
- package/{src → dist}/application-event-detail.d.ts +1 -0
- package/dist/application-event-detail.d.ts.map +1 -0
- package/dist/application-event-detail.js +34 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/{src → dist}/errors/missing-environment-variables-error.d.ts +1 -0
- package/dist/errors/missing-environment-variables-error.d.ts.map +1 -0
- package/dist/errors/missing-environment-variables-error.js +9 -0
- package/{src → dist}/eventbridge/eventbridge.d.ts +1 -0
- package/dist/eventbridge/eventbridge.d.ts.map +1 -0
- package/dist/eventbridge/eventbridge.js +2 -0
- package/dist/eventbridge/index.d.ts +3 -0
- package/dist/eventbridge/index.d.ts.map +1 -0
- package/{src → dist}/eventbridge/put-eb-events.d.ts +1 -0
- package/dist/eventbridge/put-eb-events.d.ts.map +1 -0
- package/dist/eventbridge/put-eb-events.js +24 -0
- package/{src → dist}/events-manager.d.ts +1 -0
- package/dist/events-manager.d.ts.map +1 -0
- package/dist/events-manager.js +84 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/package.json +38 -9
- package/src/application-event-detail-metadata.js +0 -27
- package/src/application-event-detail-metadata.js.map +0 -1
- package/src/application-event-detail.js +0 -27
- package/src/application-event-detail.js.map +0 -1
- package/src/errors/index.js +0 -5
- package/src/errors/index.js.map +0 -1
- package/src/errors/missing-environment-variables-error.js +0 -14
- package/src/errors/missing-environment-variables-error.js.map +0 -1
- package/src/eventbridge/eventbridge.js +0 -6
- package/src/eventbridge/eventbridge.js.map +0 -1
- package/src/eventbridge/index.js +0 -6
- package/src/eventbridge/index.js.map +0 -1
- package/src/eventbridge/put-eb-events.js +0 -30
- package/src/eventbridge/put-eb-events.js.map +0 -1
- package/src/events-manager.js +0 -90
- package/src/events-manager.js.map +0 -1
- package/src/index.js +0 -9
- package/src/index.js.map +0 -1
- /package/{src/errors/index.d.ts → dist/errors/index.js} +0 -0
- /package/{src/eventbridge/index.d.ts → dist/eventbridge/index.js} +0 -0
- /package/{src/index.d.ts → dist/index.js} +0 -0
package/README.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# events-manager
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Building
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- [Key features](#key-features)
|
|
9
|
-
- [Usage](#usage)
|
|
7
|
+
Run `nx build events-manager` to build the library.
|
|
10
8
|
|
|
11
|
-
##
|
|
9
|
+
## Running unit tests
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
11
|
+
Run `nx test events-manager` to execute the unit tests via [Jest](https://jestjs.io).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-event-detail-metadata.d.ts","sourceRoot":"","sources":["../src/application-event-detail-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EACf,MAAM,6BAA6B,CAAC;AAGrC,qBAAa,8BAA+B,SAAQ,cAAc;IAEhE,cAAc,EAAE,MAAM,CAAC;IAGvB,SAAS,EAAE,MAAM,CAAC;gBAEN,KAAK,CAAC,EAAE,GAAG;CASxB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
|
+
import { Attribute, AttributeType, DecoratedClass, } from "@itzworking/decorated-class";
|
|
3
|
+
import { v4 as uuid } from "uuid";
|
|
4
|
+
let ApplicationEventDetailMetadata = (() => {
|
|
5
|
+
let _classSuper = DecoratedClass;
|
|
6
|
+
let _idempotencyKey_decorators;
|
|
7
|
+
let _idempotencyKey_initializers = [];
|
|
8
|
+
let _idempotencyKey_extraInitializers = [];
|
|
9
|
+
let _createdAt_decorators;
|
|
10
|
+
let _createdAt_initializers = [];
|
|
11
|
+
let _createdAt_extraInitializers = [];
|
|
12
|
+
return class ApplicationEventDetailMetadata extends _classSuper {
|
|
13
|
+
static {
|
|
14
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
15
|
+
_idempotencyKey_decorators = [Attribute(AttributeType.String)];
|
|
16
|
+
_createdAt_decorators = [Attribute(AttributeType.Integer)];
|
|
17
|
+
__esDecorate(null, null, _idempotencyKey_decorators, { kind: "field", name: "idempotencyKey", static: false, private: false, access: { has: obj => "idempotencyKey" in obj, get: obj => obj.idempotencyKey, set: (obj, value) => { obj.idempotencyKey = value; } }, metadata: _metadata }, _idempotencyKey_initializers, _idempotencyKey_extraInitializers);
|
|
18
|
+
__esDecorate(null, null, _createdAt_decorators, { kind: "field", name: "createdAt", static: false, private: false, access: { has: obj => "createdAt" in obj, get: obj => obj.createdAt, set: (obj, value) => { obj.createdAt = value; } }, metadata: _metadata }, _createdAt_initializers, _createdAt_extraInitializers);
|
|
19
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
20
|
+
}
|
|
21
|
+
idempotencyKey = __runInitializers(this, _idempotencyKey_initializers, void 0);
|
|
22
|
+
createdAt = (__runInitializers(this, _idempotencyKey_extraInitializers), __runInitializers(this, _createdAt_initializers, void 0));
|
|
23
|
+
constructor(props) {
|
|
24
|
+
super(props);
|
|
25
|
+
__runInitializers(this, _createdAt_extraInitializers);
|
|
26
|
+
if (!props?.idempotencyKey) {
|
|
27
|
+
this.idempotencyKey = uuid();
|
|
28
|
+
}
|
|
29
|
+
if (!props?.createdAt) {
|
|
30
|
+
this.createdAt = Date.now();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
export { ApplicationEventDetailMetadata };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-event-detail.d.ts","sourceRoot":"","sources":["../src/application-event-detail.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EAEf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAErF,qBAAa,sBAAsB,CACjC,CAAC,SAAS,cAAc,CACxB,SAAQ,cAAc;IAKtB,QAAQ,EAAE,8BAA8B,CAAC;IAGzC,IAAI,EAAE,CAAC,CAAC;gBAEI,KAAK,CAAC,EAAE,GAAG;CAMxB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { __esDecorate, __runInitializers } from "tslib";
|
|
2
|
+
import { Attribute, AttributeType, DecoratedClass, NotNull, } from "@itzworking/decorated-class";
|
|
3
|
+
import { ApplicationEventDetailMetadata } from "./application-event-detail-metadata";
|
|
4
|
+
let ApplicationEventDetail = (() => {
|
|
5
|
+
let _classSuper = DecoratedClass;
|
|
6
|
+
let _metadata_decorators;
|
|
7
|
+
let _metadata_initializers = [];
|
|
8
|
+
let _metadata_extraInitializers = [];
|
|
9
|
+
let _data_decorators;
|
|
10
|
+
let _data_initializers = [];
|
|
11
|
+
let _data_extraInitializers = [];
|
|
12
|
+
return class ApplicationEventDetail extends _classSuper {
|
|
13
|
+
static {
|
|
14
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
15
|
+
_metadata_decorators = [NotNull, Attribute(AttributeType.Object, {
|
|
16
|
+
nestedType: ApplicationEventDetailMetadata,
|
|
17
|
+
})];
|
|
18
|
+
_data_decorators = [Attribute(AttributeType.Object)];
|
|
19
|
+
__esDecorate(null, null, _metadata_decorators, { kind: "field", name: "metadata", static: false, private: false, access: { has: obj => "metadata" in obj, get: obj => obj.metadata, set: (obj, value) => { obj.metadata = value; } }, metadata: _metadata }, _metadata_initializers, _metadata_extraInitializers);
|
|
20
|
+
__esDecorate(null, null, _data_decorators, { kind: "field", name: "data", static: false, private: false, access: { has: obj => "data" in obj, get: obj => obj.data, set: (obj, value) => { obj.data = value; } }, metadata: _metadata }, _data_initializers, _data_extraInitializers);
|
|
21
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
22
|
+
}
|
|
23
|
+
metadata = __runInitializers(this, _metadata_initializers, void 0);
|
|
24
|
+
data = (__runInitializers(this, _metadata_extraInitializers), __runInitializers(this, _data_initializers, void 0));
|
|
25
|
+
constructor(props) {
|
|
26
|
+
super(props);
|
|
27
|
+
__runInitializers(this, _data_extraInitializers);
|
|
28
|
+
if (!props?.metadata) {
|
|
29
|
+
this.metadata = new ApplicationEventDetailMetadata(props?.metadata);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
export { ApplicationEventDetail };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"missing-environment-variables-error.d.ts","sourceRoot":"","sources":["../../src/errors/missing-environment-variables-error.ts"],"names":[],"mappings":"AAAA,qBAAa,gCAAiC,SAAQ,KAAK;gBAC7C,2BAA2B,EAAE,MAAM,EAAE;CAWlD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class MissingEnvironmentVariablesError extends Error {
|
|
2
|
+
constructor(missingEnvironmentVariables) {
|
|
3
|
+
super(JSON.stringify({
|
|
4
|
+
name: "MissingEnvironmentVariablesError",
|
|
5
|
+
message: `Missing environment variables: ${missingEnvironmentVariables.join(", ")}`,
|
|
6
|
+
}));
|
|
7
|
+
this.name = "MissingEnvironmentVariablesError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventbridge.d.ts","sourceRoot":"","sources":["../../src/eventbridge/eventbridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,eAAO,MAAM,WAAW,mBAA4B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/eventbridge/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"put-eb-events.d.ts","sourceRoot":"","sources":["../../src/eventbridge/put-eb-events.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,qBAAqB,EACtB,MAAM,6BAA6B,CAAC;AAGrC,eAAO,MAAM,WAAW,UAAiB,qBAAqB,0EAmB7D,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { logger } from "@itzworking/powertools";
|
|
2
|
+
import { PutEventsCommand, } from "@aws-sdk/client-eventbridge";
|
|
3
|
+
import { eventbridge } from "./eventbridge";
|
|
4
|
+
export const putEbEvents = async (input) => {
|
|
5
|
+
logger.debug({
|
|
6
|
+
message: "send eventbridge PutEventsCommand",
|
|
7
|
+
awsService: "eventbridge",
|
|
8
|
+
action: "PutEventsCommand",
|
|
9
|
+
input,
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
return eventbridge.send(new PutEventsCommand(input));
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
logger.error({
|
|
16
|
+
message: "send eventbridge PutEventsCommand",
|
|
17
|
+
awsService: "eventbridge",
|
|
18
|
+
action: "PutEventsCommand",
|
|
19
|
+
input,
|
|
20
|
+
error,
|
|
21
|
+
});
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events-manager.d.ts","sourceRoot":"","sources":["../src/events-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAa,MAAM,6BAA6B,CAAC;AAMxE,cAAM,kBAAkB;IACtB,KAAK,UAAS;IAEd,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IAEpB,KAAK;IAsCC,YAAY,CAAC,CAAC,SAAS,cAAc,EACzC,WAAW,EAAE,KAAK,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,EACnC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,CAAC;CAiDV;AAED,eAAO,MAAM,aAAa,oBAA2B,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { validator } from "@itzworking/decorated-class";
|
|
2
|
+
import { logger } from "@itzworking/powertools";
|
|
3
|
+
import { ApplicationEventDetail } from "./application-event-detail";
|
|
4
|
+
import { putEbEvents } from "./eventbridge";
|
|
5
|
+
import { MissingEnvironmentVariablesError } from "./errors";
|
|
6
|
+
class EventsManagerClass {
|
|
7
|
+
ready = false;
|
|
8
|
+
serviceName;
|
|
9
|
+
eventBusName;
|
|
10
|
+
eventSource;
|
|
11
|
+
setup() {
|
|
12
|
+
if (this.ready) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
this.serviceName = process.env.SERVICE_NAME || "";
|
|
16
|
+
this.eventBusName =
|
|
17
|
+
process.env.EVENT_BUS_NAME || process.env.MAIN_EVENT_BUS_NAME || "";
|
|
18
|
+
this.eventSource = process.env.NAMESPACE || "";
|
|
19
|
+
const missingEnvironmentVariables = [];
|
|
20
|
+
if (!this.serviceName) {
|
|
21
|
+
missingEnvironmentVariables.push("SERVICE_NAME");
|
|
22
|
+
}
|
|
23
|
+
if (!this.eventBusName) {
|
|
24
|
+
missingEnvironmentVariables.push("EVENT_BUS_NAME or MAIN_EVENT_BUS_NAME");
|
|
25
|
+
}
|
|
26
|
+
if (!this.eventSource) {
|
|
27
|
+
missingEnvironmentVariables.push("NAMESPACE");
|
|
28
|
+
}
|
|
29
|
+
if (missingEnvironmentVariables.length > 0) {
|
|
30
|
+
logger.error("Missing environment variables", {
|
|
31
|
+
missing: missingEnvironmentVariables,
|
|
32
|
+
});
|
|
33
|
+
throw new MissingEnvironmentVariablesError(missingEnvironmentVariables);
|
|
34
|
+
}
|
|
35
|
+
logger.debug("EventsManager initialized", {
|
|
36
|
+
serviceName: this.serviceName,
|
|
37
|
+
eventBusName: this.eventBusName,
|
|
38
|
+
eventSource: this.eventSource,
|
|
39
|
+
});
|
|
40
|
+
this.ready = true;
|
|
41
|
+
}
|
|
42
|
+
async publishEvent(entityClass, eventName, data) {
|
|
43
|
+
this.setup();
|
|
44
|
+
logger.debug("Publishing event", {
|
|
45
|
+
eventName,
|
|
46
|
+
entityClass: entityClass.name,
|
|
47
|
+
});
|
|
48
|
+
const applicationEventDetail = new ApplicationEventDetail({
|
|
49
|
+
data: data instanceof entityClass ? data : new entityClass(data),
|
|
50
|
+
});
|
|
51
|
+
try {
|
|
52
|
+
validator.validate(applicationEventDetail);
|
|
53
|
+
const events = {
|
|
54
|
+
Entries: [
|
|
55
|
+
{
|
|
56
|
+
Detail: JSON.stringify(applicationEventDetail),
|
|
57
|
+
DetailType: `${this.serviceName}.${eventName}`,
|
|
58
|
+
Source: this.eventSource,
|
|
59
|
+
EventBusName: this.eventBusName,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
logger.debug("Sending event to EventBridge", {
|
|
64
|
+
detailType: events.Entries[0].DetailType,
|
|
65
|
+
eventBusName: this.eventBusName,
|
|
66
|
+
});
|
|
67
|
+
const result = await putEbEvents(events);
|
|
68
|
+
logger.info("Event published successfully", {
|
|
69
|
+
eventName,
|
|
70
|
+
detailType: events.Entries[0].DetailType,
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logger.error("Failed to publish event", {
|
|
76
|
+
eventName,
|
|
77
|
+
error: error.message,
|
|
78
|
+
entityClass: entityClass.name,
|
|
79
|
+
});
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export const EventsManager = new EventsManagerClass();
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAE9B,cAAc,qCAAqC,CAAC;AACpD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itzworking/events-manager",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.156",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"development": "./src/index.ts",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"!**/*.tsbuildinfo"
|
|
20
|
+
],
|
|
21
|
+
"nx": {
|
|
22
|
+
"targets": {
|
|
23
|
+
"publish": {
|
|
24
|
+
"dependsOn": [
|
|
25
|
+
"build"
|
|
26
|
+
],
|
|
27
|
+
"executor": "nx:run-commands",
|
|
28
|
+
"options": {
|
|
29
|
+
"command": "node scripts/ci/publish.mjs {projectRoot}"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"tags": [
|
|
34
|
+
"type:lib"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
4
37
|
"dependencies": {
|
|
5
38
|
"tslib": "^2.3.0"
|
|
6
39
|
},
|
|
7
40
|
"peerDependencies": {
|
|
8
41
|
"@aws-sdk/client-eventbridge": "3.x",
|
|
9
|
-
"@itzworking/decorated-class": "0.0.
|
|
10
|
-
"@itzworking/powertools": "0.0.
|
|
42
|
+
"@itzworking/decorated-class": "0.0.156",
|
|
43
|
+
"@itzworking/powertools": "0.0.156",
|
|
11
44
|
"uuid": "10.x"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
"main": "./src/index.js",
|
|
15
|
-
"typings": "./src/index.d.ts",
|
|
16
|
-
"types": "./src/index.d.ts"
|
|
17
|
-
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApplicationEventDetailMetadata = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const decorated_class_1 = require("@itzworking/decorated-class");
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
7
|
-
class ApplicationEventDetailMetadata extends decorated_class_1.DecoratedClass {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
if (!(props === null || props === void 0 ? void 0 : props.idempotencyKey)) {
|
|
11
|
-
this.idempotencyKey = (0, uuid_1.v4)();
|
|
12
|
-
}
|
|
13
|
-
if (!(props === null || props === void 0 ? void 0 : props.createdAt)) {
|
|
14
|
-
this.createdAt = Date.now();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.ApplicationEventDetailMetadata = ApplicationEventDetailMetadata;
|
|
19
|
-
tslib_1.__decorate([
|
|
20
|
-
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String),
|
|
21
|
-
tslib_1.__metadata("design:type", String)
|
|
22
|
-
], ApplicationEventDetailMetadata.prototype, "idempotencyKey", void 0);
|
|
23
|
-
tslib_1.__decorate([
|
|
24
|
-
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Integer),
|
|
25
|
-
tslib_1.__metadata("design:type", Number)
|
|
26
|
-
], ApplicationEventDetailMetadata.prototype, "createdAt", void 0);
|
|
27
|
-
//# sourceMappingURL=application-event-detail-metadata.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application-event-detail-metadata.js","sourceRoot":"","sources":["../../../../libs/events-manager/src/application-event-detail-metadata.ts"],"names":[],"mappings":";;;;AAAA,iEAIqC;AACrC,+BAAkC;AAElC,MAAa,8BAA+B,SAAQ,gCAAc;IAOhE,YAAY,KAAW;QACrB,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,cAAc,CAAA,EAAE,CAAC;YAC3B,IAAI,CAAC,cAAc,GAAG,IAAA,SAAI,GAAE,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,CAAA,EAAE,CAAC;YACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;CACF;AAhBD,wEAgBC;AAdC;IADC,IAAA,2BAAS,EAAC,+BAAa,CAAC,MAAM,CAAC;;sEACT;AAGvB;IADC,IAAA,2BAAS,EAAC,+BAAa,CAAC,OAAO,CAAC;;iEACf"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApplicationEventDetail = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const decorated_class_1 = require("@itzworking/decorated-class");
|
|
6
|
-
const application_event_detail_metadata_1 = require("./application-event-detail-metadata");
|
|
7
|
-
class ApplicationEventDetail extends decorated_class_1.DecoratedClass {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
if (!(props === null || props === void 0 ? void 0 : props.metadata)) {
|
|
11
|
-
this.metadata = new application_event_detail_metadata_1.ApplicationEventDetailMetadata(props === null || props === void 0 ? void 0 : props.metadata);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.ApplicationEventDetail = ApplicationEventDetail;
|
|
16
|
-
tslib_1.__decorate([
|
|
17
|
-
decorated_class_1.NotNull,
|
|
18
|
-
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Object, {
|
|
19
|
-
nestedType: application_event_detail_metadata_1.ApplicationEventDetailMetadata,
|
|
20
|
-
}),
|
|
21
|
-
tslib_1.__metadata("design:type", application_event_detail_metadata_1.ApplicationEventDetailMetadata)
|
|
22
|
-
], ApplicationEventDetail.prototype, "metadata", void 0);
|
|
23
|
-
tslib_1.__decorate([
|
|
24
|
-
(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Object),
|
|
25
|
-
tslib_1.__metadata("design:type", Object)
|
|
26
|
-
], ApplicationEventDetail.prototype, "data", void 0);
|
|
27
|
-
//# sourceMappingURL=application-event-detail.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application-event-detail.js","sourceRoot":"","sources":["../../../../libs/events-manager/src/application-event-detail.ts"],"names":[],"mappings":";;;;AAAA,iEAKqC;AACrC,2FAAqF;AAErF,MAAa,sBAEX,SAAQ,gCAAc;IAUtB,YAAY,KAAW;QACrB,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,CAAA,EAAE,CAAC;YACrB,IAAI,CAAC,QAAQ,GAAG,IAAI,kEAA8B,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,QAAQ,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;CACF;AAlBD,wDAkBC;AAXC;IAJC,yBAAO;IACP,IAAA,2BAAS,EAAC,+BAAa,CAAC,MAAM,EAAE;QAC/B,UAAU,EAAE,kEAA8B;KAC3C,CAAC;sCACQ,kEAA8B;wDAAC;AAGzC;IADC,IAAA,2BAAS,EAAC,+BAAa,CAAC,MAAM,CAAC;;oDACxB"}
|
package/src/errors/index.js
DELETED
package/src/errors/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/events-manager/src/errors/index.ts"],"names":[],"mappings":";;;AAAA,gFAAsD"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MissingEnvironmentVariablesError = void 0;
|
|
4
|
-
class MissingEnvironmentVariablesError extends Error {
|
|
5
|
-
constructor(missingEnvironmentVariables) {
|
|
6
|
-
super(JSON.stringify({
|
|
7
|
-
name: "MissingEnvironmentVariablesError",
|
|
8
|
-
message: `Missing environment variables: ${missingEnvironmentVariables.join(", ")}`,
|
|
9
|
-
}));
|
|
10
|
-
this.name = "MissingEnvironmentVariablesError";
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.MissingEnvironmentVariablesError = MissingEnvironmentVariablesError;
|
|
14
|
-
//# sourceMappingURL=missing-environment-variables-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"missing-environment-variables-error.js","sourceRoot":"","sources":["../../../../../libs/events-manager/src/errors/missing-environment-variables-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,gCAAiC,SAAQ,KAAK;IACzD,YAAY,2BAAqC;QAC/C,KAAK,CACH,IAAI,CAAC,SAAS,CAAC;YACb,IAAI,EAAE,kCAAkC;YACxC,OAAO,EAAE,kCAAkC,2BAA2B,CAAC,IAAI,CACzE,IAAI,CACL,EAAE;SACJ,CAAC,CACH,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,kCAAkC,CAAC;IACjD,CAAC;CACF;AAZD,4EAYC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eventbridge = void 0;
|
|
4
|
-
const client_eventbridge_1 = require("@aws-sdk/client-eventbridge");
|
|
5
|
-
exports.eventbridge = new client_eventbridge_1.EventBridgeClient({});
|
|
6
|
-
//# sourceMappingURL=eventbridge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"eventbridge.js","sourceRoot":"","sources":["../../../../../libs/events-manager/src/eventbridge/eventbridge.ts"],"names":[],"mappings":";;;AAAA,oEAAgE;AAEnD,QAAA,WAAW,GAAG,IAAI,sCAAiB,CAAC,EAAE,CAAC,CAAC"}
|
package/src/eventbridge/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./eventbridge"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./put-eb-events"), exports);
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/events-manager/src/eventbridge/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAE9B,0DAAgC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.putEbEvents = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const powertools_1 = require("@itzworking/powertools");
|
|
6
|
-
const client_eventbridge_1 = require("@aws-sdk/client-eventbridge");
|
|
7
|
-
const eventbridge_1 = require("./eventbridge");
|
|
8
|
-
const putEbEvents = (input) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
-
powertools_1.logger.debug({
|
|
10
|
-
message: "send eventbridge PutEventsCommand",
|
|
11
|
-
awsService: "eventbridge",
|
|
12
|
-
action: "PutEventsCommand",
|
|
13
|
-
input,
|
|
14
|
-
});
|
|
15
|
-
try {
|
|
16
|
-
return eventbridge_1.eventbridge.send(new client_eventbridge_1.PutEventsCommand(input));
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
powertools_1.logger.error({
|
|
20
|
-
message: "send eventbridge PutEventsCommand",
|
|
21
|
-
awsService: "eventbridge",
|
|
22
|
-
action: "PutEventsCommand",
|
|
23
|
-
input,
|
|
24
|
-
error,
|
|
25
|
-
});
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
exports.putEbEvents = putEbEvents;
|
|
30
|
-
//# sourceMappingURL=put-eb-events.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"put-eb-events.js","sourceRoot":"","sources":["../../../../../libs/events-manager/src/eventbridge/put-eb-events.ts"],"names":[],"mappings":";;;;AAAA,uDAAgD;AAChD,oEAGqC;AACrC,+CAA4C;AAErC,MAAM,WAAW,GAAG,CAAO,KAA4B,EAAE,EAAE;IAChE,mBAAM,CAAC,KAAK,CAAC;QACX,OAAO,EAAE,mCAAmC;QAC5C,UAAU,EAAE,aAAa;QACzB,MAAM,EAAE,kBAAkB;QAC1B,KAAK;KACN,CAAC,CAAC;IACH,IAAI,CAAC;QACH,OAAO,yBAAW,CAAC,IAAI,CAAC,IAAI,qCAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,mBAAM,CAAC,KAAK,CAAC;YACX,OAAO,EAAE,mCAAmC;YAC5C,UAAU,EAAE,aAAa;YACzB,MAAM,EAAE,kBAAkB;YAC1B,KAAK;YACL,KAAK;SACN,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAA,CAAC;AAnBW,QAAA,WAAW,eAmBtB"}
|
package/src/events-manager.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventsManager = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const decorated_class_1 = require("@itzworking/decorated-class");
|
|
6
|
-
const powertools_1 = require("@itzworking/powertools");
|
|
7
|
-
const application_event_detail_1 = require("./application-event-detail");
|
|
8
|
-
const eventbridge_1 = require("./eventbridge");
|
|
9
|
-
const errors_1 = require("./errors");
|
|
10
|
-
class EventsManagerClass {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.ready = false;
|
|
13
|
-
}
|
|
14
|
-
setup() {
|
|
15
|
-
if (this.ready) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
this.serviceName = process.env.SERVICE_NAME || "";
|
|
19
|
-
this.eventBusName =
|
|
20
|
-
process.env.EVENT_BUS_NAME || process.env.MAIN_EVENT_BUS_NAME || "";
|
|
21
|
-
this.eventSource = process.env.NAMESPACE || "";
|
|
22
|
-
const missingEnvironmentVariables = [];
|
|
23
|
-
if (!this.serviceName) {
|
|
24
|
-
missingEnvironmentVariables.push("SERVICE_NAME");
|
|
25
|
-
}
|
|
26
|
-
if (!this.eventBusName) {
|
|
27
|
-
missingEnvironmentVariables.push("EVENT_BUS_NAME or MAIN_EVENT_BUS_NAME");
|
|
28
|
-
}
|
|
29
|
-
if (!this.eventSource) {
|
|
30
|
-
missingEnvironmentVariables.push("NAMESPACE");
|
|
31
|
-
}
|
|
32
|
-
if (missingEnvironmentVariables.length > 0) {
|
|
33
|
-
powertools_1.logger.error("Missing environment variables", {
|
|
34
|
-
missing: missingEnvironmentVariables,
|
|
35
|
-
});
|
|
36
|
-
throw new errors_1.MissingEnvironmentVariablesError(missingEnvironmentVariables);
|
|
37
|
-
}
|
|
38
|
-
powertools_1.logger.debug("EventsManager initialized", {
|
|
39
|
-
serviceName: this.serviceName,
|
|
40
|
-
eventBusName: this.eventBusName,
|
|
41
|
-
eventSource: this.eventSource,
|
|
42
|
-
});
|
|
43
|
-
this.ready = true;
|
|
44
|
-
}
|
|
45
|
-
publishEvent(entityClass, eventName, data) {
|
|
46
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
47
|
-
this.setup();
|
|
48
|
-
powertools_1.logger.debug("Publishing event", {
|
|
49
|
-
eventName,
|
|
50
|
-
entityClass: entityClass.name,
|
|
51
|
-
});
|
|
52
|
-
const applicationEventDetail = new application_event_detail_1.ApplicationEventDetail({
|
|
53
|
-
data: data instanceof entityClass ? data : new entityClass(data),
|
|
54
|
-
});
|
|
55
|
-
try {
|
|
56
|
-
decorated_class_1.validator.validate(applicationEventDetail);
|
|
57
|
-
const events = {
|
|
58
|
-
Entries: [
|
|
59
|
-
{
|
|
60
|
-
Detail: JSON.stringify(applicationEventDetail),
|
|
61
|
-
DetailType: `${this.serviceName}.${eventName}`,
|
|
62
|
-
Source: this.eventSource,
|
|
63
|
-
EventBusName: this.eventBusName,
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
};
|
|
67
|
-
powertools_1.logger.debug("Sending event to EventBridge", {
|
|
68
|
-
detailType: events.Entries[0].DetailType,
|
|
69
|
-
eventBusName: this.eventBusName,
|
|
70
|
-
});
|
|
71
|
-
const result = yield (0, eventbridge_1.putEbEvents)(events);
|
|
72
|
-
powertools_1.logger.info("Event published successfully", {
|
|
73
|
-
eventName,
|
|
74
|
-
detailType: events.Entries[0].DetailType,
|
|
75
|
-
});
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
powertools_1.logger.error("Failed to publish event", {
|
|
80
|
-
eventName,
|
|
81
|
-
error: error.message,
|
|
82
|
-
entityClass: entityClass.name,
|
|
83
|
-
});
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.EventsManager = new EventsManagerClass();
|
|
90
|
-
//# sourceMappingURL=events-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"events-manager.js","sourceRoot":"","sources":["../../../../libs/events-manager/src/events-manager.ts"],"names":[],"mappings":"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"}
|
package/src/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./errors"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./eventbridge"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./application-event-detail-metadata"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./application-event-detail"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./events-manager"), exports);
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/events-manager/src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAyB;AACzB,wDAA8B;AAE9B,8EAAoD;AACpD,qEAA2C;AAC3C,2DAAiC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|