@itzworking/events-manager 0.0.158 → 0.0.159

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.
@@ -1,8 +1,11 @@
1
- import { __esDecorate, __runInitializers } from "tslib";
2
- import { Attribute, AttributeType, DecoratedClass, } from "@itzworking/decorated-class";
3
- import { v4 as uuid } from "uuid";
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");
4
7
  let ApplicationEventDetailMetadata = (() => {
5
- let _classSuper = DecoratedClass;
8
+ let _classSuper = decorated_class_1.DecoratedClass;
6
9
  let _idempotencyKey_decorators;
7
10
  let _idempotencyKey_initializers = [];
8
11
  let _idempotencyKey_extraInitializers = [];
@@ -12,19 +15,19 @@ let ApplicationEventDetailMetadata = (() => {
12
15
  return class ApplicationEventDetailMetadata extends _classSuper {
13
16
  static {
14
17
  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);
18
+ _idempotencyKey_decorators = [(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.String)];
19
+ _createdAt_decorators = [(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Integer)];
20
+ tslib_1.__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);
21
+ tslib_1.__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
22
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
20
23
  }
21
- idempotencyKey = __runInitializers(this, _idempotencyKey_initializers, void 0);
22
- createdAt = (__runInitializers(this, _idempotencyKey_extraInitializers), __runInitializers(this, _createdAt_initializers, void 0));
24
+ idempotencyKey = tslib_1.__runInitializers(this, _idempotencyKey_initializers, void 0);
25
+ createdAt = (tslib_1.__runInitializers(this, _idempotencyKey_extraInitializers), tslib_1.__runInitializers(this, _createdAt_initializers, void 0));
23
26
  constructor(props) {
24
27
  super(props);
25
- __runInitializers(this, _createdAt_extraInitializers);
28
+ tslib_1.__runInitializers(this, _createdAt_extraInitializers);
26
29
  if (!props?.idempotencyKey) {
27
- this.idempotencyKey = uuid();
30
+ this.idempotencyKey = (0, uuid_1.v4)();
28
31
  }
29
32
  if (!props?.createdAt) {
30
33
  this.createdAt = Date.now();
@@ -32,4 +35,4 @@ let ApplicationEventDetailMetadata = (() => {
32
35
  }
33
36
  };
34
37
  })();
35
- export { ApplicationEventDetailMetadata };
38
+ exports.ApplicationEventDetailMetadata = ApplicationEventDetailMetadata;
@@ -1,8 +1,11 @@
1
- import { __esDecorate, __runInitializers } from "tslib";
2
- import { Attribute, AttributeType, DecoratedClass, NotNull, } from "@itzworking/decorated-class";
3
- import { ApplicationEventDetailMetadata } from "./application-event-detail-metadata";
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");
4
7
  let ApplicationEventDetail = (() => {
5
- let _classSuper = DecoratedClass;
8
+ let _classSuper = decorated_class_1.DecoratedClass;
6
9
  let _metadata_decorators;
7
10
  let _metadata_initializers = [];
8
11
  let _metadata_extraInitializers = [];
@@ -12,23 +15,23 @@ let ApplicationEventDetail = (() => {
12
15
  return class ApplicationEventDetail extends _classSuper {
13
16
  static {
14
17
  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,
18
+ _metadata_decorators = [decorated_class_1.NotNull, (0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Object, {
19
+ nestedType: application_event_detail_metadata_1.ApplicationEventDetailMetadata,
17
20
  })];
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
+ _data_decorators = [(0, decorated_class_1.Attribute)(decorated_class_1.AttributeType.Object)];
22
+ tslib_1.__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);
23
+ tslib_1.__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
24
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
22
25
  }
23
- metadata = __runInitializers(this, _metadata_initializers, void 0);
24
- data = (__runInitializers(this, _metadata_extraInitializers), __runInitializers(this, _data_initializers, void 0));
26
+ metadata = tslib_1.__runInitializers(this, _metadata_initializers, void 0);
27
+ data = (tslib_1.__runInitializers(this, _metadata_extraInitializers), tslib_1.__runInitializers(this, _data_initializers, void 0));
25
28
  constructor(props) {
26
29
  super(props);
27
- __runInitializers(this, _data_extraInitializers);
30
+ tslib_1.__runInitializers(this, _data_extraInitializers);
28
31
  if (!props?.metadata) {
29
- this.metadata = new ApplicationEventDetailMetadata(props?.metadata);
32
+ this.metadata = new application_event_detail_metadata_1.ApplicationEventDetailMetadata(props?.metadata);
30
33
  }
31
34
  }
32
35
  };
33
36
  })();
34
- export { ApplicationEventDetail };
37
+ exports.ApplicationEventDetail = ApplicationEventDetail;
@@ -1 +1,4 @@
1
- export * from "./missing-environment-variables-error";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./missing-environment-variables-error"), exports);
@@ -1,4 +1,7 @@
1
- export class MissingEnvironmentVariablesError extends Error {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MissingEnvironmentVariablesError = void 0;
4
+ class MissingEnvironmentVariablesError extends Error {
2
5
  constructor(missingEnvironmentVariables) {
3
6
  super(JSON.stringify({
4
7
  name: "MissingEnvironmentVariablesError",
@@ -7,3 +10,4 @@ export class MissingEnvironmentVariablesError extends Error {
7
10
  this.name = "MissingEnvironmentVariablesError";
8
11
  }
9
12
  }
13
+ exports.MissingEnvironmentVariablesError = MissingEnvironmentVariablesError;
@@ -1,2 +1,5 @@
1
- import { EventBridgeClient } from "@aws-sdk/client-eventbridge";
2
- export const eventbridge = new EventBridgeClient({});
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({});
@@ -1,2 +1,5 @@
1
- export * from "./eventbridge";
2
- export * from "./put-eb-events";
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);
@@ -1,18 +1,21 @@
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({
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.putEbEvents = void 0;
4
+ const powertools_1 = require("@itzworking/powertools");
5
+ const client_eventbridge_1 = require("@aws-sdk/client-eventbridge");
6
+ const eventbridge_1 = require("./eventbridge");
7
+ const putEbEvents = async (input) => {
8
+ powertools_1.logger.debug({
6
9
  message: "send eventbridge PutEventsCommand",
7
10
  awsService: "eventbridge",
8
11
  action: "PutEventsCommand",
9
12
  input,
10
13
  });
11
14
  try {
12
- return eventbridge.send(new PutEventsCommand(input));
15
+ return eventbridge_1.eventbridge.send(new client_eventbridge_1.PutEventsCommand(input));
13
16
  }
14
17
  catch (error) {
15
- logger.error({
18
+ powertools_1.logger.error({
16
19
  message: "send eventbridge PutEventsCommand",
17
20
  awsService: "eventbridge",
18
21
  action: "PutEventsCommand",
@@ -22,3 +25,4 @@ export const putEbEvents = async (input) => {
22
25
  throw error;
23
26
  }
24
27
  };
28
+ exports.putEbEvents = putEbEvents;
@@ -1,8 +1,11 @@
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";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventsManager = void 0;
4
+ const decorated_class_1 = require("@itzworking/decorated-class");
5
+ const powertools_1 = require("@itzworking/powertools");
6
+ const application_event_detail_1 = require("./application-event-detail");
7
+ const eventbridge_1 = require("./eventbridge");
8
+ const errors_1 = require("./errors");
6
9
  class EventsManagerClass {
7
10
  ready = false;
8
11
  serviceName;
@@ -27,12 +30,12 @@ class EventsManagerClass {
27
30
  missingEnvironmentVariables.push("NAMESPACE");
28
31
  }
29
32
  if (missingEnvironmentVariables.length > 0) {
30
- logger.error("Missing environment variables", {
33
+ powertools_1.logger.error("Missing environment variables", {
31
34
  missing: missingEnvironmentVariables,
32
35
  });
33
- throw new MissingEnvironmentVariablesError(missingEnvironmentVariables);
36
+ throw new errors_1.MissingEnvironmentVariablesError(missingEnvironmentVariables);
34
37
  }
35
- logger.debug("EventsManager initialized", {
38
+ powertools_1.logger.debug("EventsManager initialized", {
36
39
  serviceName: this.serviceName,
37
40
  eventBusName: this.eventBusName,
38
41
  eventSource: this.eventSource,
@@ -41,15 +44,15 @@ class EventsManagerClass {
41
44
  }
42
45
  async publishEvent(entityClass, eventName, data) {
43
46
  this.setup();
44
- logger.debug("Publishing event", {
47
+ powertools_1.logger.debug("Publishing event", {
45
48
  eventName,
46
49
  entityClass: entityClass.name,
47
50
  });
48
- const applicationEventDetail = new ApplicationEventDetail({
51
+ const applicationEventDetail = new application_event_detail_1.ApplicationEventDetail({
49
52
  data: data instanceof entityClass ? data : new entityClass(data),
50
53
  });
51
54
  try {
52
- validator.validate(applicationEventDetail);
55
+ decorated_class_1.validator.validate(applicationEventDetail);
53
56
  const events = {
54
57
  Entries: [
55
58
  {
@@ -60,19 +63,19 @@ class EventsManagerClass {
60
63
  },
61
64
  ],
62
65
  };
63
- logger.debug("Sending event to EventBridge", {
66
+ powertools_1.logger.debug("Sending event to EventBridge", {
64
67
  detailType: events.Entries[0].DetailType,
65
68
  eventBusName: this.eventBusName,
66
69
  });
67
- const result = await putEbEvents(events);
68
- logger.info("Event published successfully", {
70
+ const result = await (0, eventbridge_1.putEbEvents)(events);
71
+ powertools_1.logger.info("Event published successfully", {
69
72
  eventName,
70
73
  detailType: events.Entries[0].DetailType,
71
74
  });
72
75
  return result;
73
76
  }
74
77
  catch (error) {
75
- logger.error("Failed to publish event", {
78
+ powertools_1.logger.error("Failed to publish event", {
76
79
  eventName,
77
80
  error: error.message,
78
81
  entityClass: entityClass.name,
@@ -81,4 +84,4 @@ class EventsManagerClass {
81
84
  }
82
85
  }
83
86
  }
84
- export const EventsManager = new EventsManagerClass();
87
+ exports.EventsManager = new EventsManagerClass();
package/dist/index.js CHANGED
@@ -1,5 +1,8 @@
1
- export * from "./errors";
2
- export * from "./eventbridge";
3
- export * from "./application-event-detail-metadata";
4
- export * from "./application-event-detail";
5
- export * from "./events-manager";
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itzworking/events-manager",
3
- "version": "0.0.158",
3
+ "version": "0.0.159",
4
4
  "type": "commonjs",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@aws-sdk/client-eventbridge": "3.x",
42
- "@itzworking/decorated-class": "0.0.158",
43
- "@itzworking/powertools": "0.0.158",
42
+ "@itzworking/decorated-class": "0.0.159",
43
+ "@itzworking/powertools": "0.0.159",
44
44
  "uuid": "10.x"
45
45
  }
46
46
  }