wsp-ms-core 1.0.82 → 1.0.83

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/index.cjs CHANGED
@@ -1161,9 +1161,9 @@ var EventManager = class {
1161
1161
  this._onCrash = null;
1162
1162
  this._onReconnect = null;
1163
1163
  }
1164
- async execRoute(topic, message) {
1164
+ async execRoute(topic, event) {
1165
1165
  if (this._callbackList[topic]) {
1166
- await this._callbackList[topic](message);
1166
+ await this._callbackList[topic](event);
1167
1167
  }
1168
1168
  }
1169
1169
  async execCallback(callback, data) {
@@ -1219,7 +1219,7 @@ var OutboxRecord = class _OutboxRecord {
1219
1219
  this._errorMessage = errorMessage;
1220
1220
  this._publishedAt = publishedAt;
1221
1221
  this._lastAttempt = lastAttempt;
1222
- this._createdAt = createdAt;
1222
+ this._createdAt = createdAt ?? DateTime.now();
1223
1223
  }
1224
1224
  get eventUuid() {
1225
1225
  return this._eventUuid;
@@ -1317,25 +1317,25 @@ var EventBusMysqlRepository = class {
1317
1317
  constructor(connection) {
1318
1318
  this.connection = connection;
1319
1319
  }
1320
- eventToRowValues(e) {
1320
+ recordToRowValues(record) {
1321
1321
  return [
1322
- e.eventUuid.value,
1323
- e.eventType,
1324
- e.tenantUuid.value,
1325
- e.aggregateUuid.value,
1326
- e.aggregateType,
1327
- e.topic,
1328
- e.payload,
1329
- e.status.value,
1330
- e.attempts,
1331
- e.errorMessage,
1332
- e.publishedAt?.value,
1333
- e.lastAttempt?.value,
1334
- e.createdAt.value
1322
+ record.eventUuid.value,
1323
+ record.eventType,
1324
+ record.tenantUuid.value,
1325
+ record.aggregateUuid.value,
1326
+ record.aggregateType,
1327
+ record.topic,
1328
+ record.payload,
1329
+ record.status.value,
1330
+ record.attempts,
1331
+ record.errorMessage,
1332
+ record.publishedAt?.value,
1333
+ record.lastAttempt?.value,
1334
+ record.createdAt.value
1335
1335
  ];
1336
1336
  }
1337
- async create(event) {
1338
- const values = this.eventToRowValues(event);
1337
+ async create(record) {
1338
+ const values = this.recordToRowValues(record);
1339
1339
  await this.connection.query(
1340
1340
  `INSERT INTO events_outbox (event_uuid, event_type, tenant_uuid, aggregate_uuid, aggregate_type, topic,
1341
1341
  payload, status, attempts, error_message, published_at, last_attempt, created_at)
@@ -1343,8 +1343,8 @@ var EventBusMysqlRepository = class {
1343
1343
  values
1344
1344
  );
1345
1345
  }
1346
- async update(event) {
1347
- const values = [event.status.value, event.attempts, event.errorMessage, event.publishedAt?.value, event.lastAttempt?.value, event.eventUuid.value];
1346
+ async update(record) {
1347
+ const values = [record.status.value, record.attempts, record.errorMessage, record.publishedAt?.value, record.lastAttempt?.value, record.eventUuid.value];
1348
1348
  await this.connection.query(
1349
1349
  `UPDATE events_outbox
1350
1350
  SET status = ?,
@@ -1358,7 +1358,7 @@ var EventBusMysqlRepository = class {
1358
1358
  }
1359
1359
  async listPending(limit) {
1360
1360
  const result = await this.connection.query(
1361
- `SELECT * FROM events_outbox WHERE status IN ('PENDING','FAILED') AND published_at IS NULL LIMIT 50`,
1361
+ `SELECT * FROM events_outbox WHERE status IN ('PENDING','FAILED') AND published_at IS NULL LIMIT ${limit}`,
1362
1362
  []
1363
1363
  );
1364
1364
  return result.length > 0 ? result.map((r) => OutboxRecord.reconstitute(r)) : [];
@@ -1555,7 +1555,13 @@ var KafkaManager = class extends EventManager {
1555
1555
  eachMessage: async ({ topic, partition, message, heartbeat }) => {
1556
1556
  try {
1557
1557
  await this.execCallback(this._onMessage, `[New message detected for ${topic}]: ${message.value?.toString()}`);
1558
- await this.execRoute(topic, String(message.value?.toString()));
1558
+ const json = JSON.parse(String(message.value?.toString()));
1559
+ await this.execRoute(topic, {
1560
+ topic: String(json.topic),
1561
+ producer: String(json.producer),
1562
+ tenant: UUID.create(String(json.tenant)),
1563
+ message: String(json.message)
1564
+ });
1559
1565
  const next = (BigInt(message.offset) + 1n).toString();
1560
1566
  await this.consumer.commitOffsets([{ topic, partition, offset: next }]);
1561
1567
  await heartbeat();
@@ -1571,11 +1577,12 @@ var KafkaManager = class extends EventManager {
1571
1577
  await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
1572
1578
  }
1573
1579
  }
1574
- async send(topic, message) {
1580
+ async send(e) {
1575
1581
  const evt = {
1576
1582
  date: DateTime.now().value,
1577
- producer: process.env.NAME && process.env.ENVIRONMENT ? `${process.env.NAME}-${process.env.ENVIRONMENT}` : "unknown",
1578
- data: message
1583
+ tenant: e.tenant.value,
1584
+ producer: e.producer,
1585
+ data: e.message
1579
1586
  };
1580
1587
  try {
1581
1588
  if (!this.producer) {
@@ -1583,7 +1590,7 @@ var KafkaManager = class extends EventManager {
1583
1590
  }
1584
1591
  await this.producer.connect();
1585
1592
  await this.producer.send({
1586
- topic,
1593
+ topic: e.topic,
1587
1594
  messages: [{ value: JSON.stringify(evt) }]
1588
1595
  });
1589
1596
  await this.producer.disconnect();
@@ -1711,7 +1718,12 @@ var DefaultMysqlOutboxRunner = class {
1711
1718
  try {
1712
1719
  e.markProcessing();
1713
1720
  await eventBusRepository.update(e);
1714
- await this.eventManager.send(e.topic, e.payload);
1721
+ await this.eventManager.send({
1722
+ topic: e.topic,
1723
+ producer: process.env.NAME && process.env.ENVIRONMENT ? `${process.env.NAME}-${process.env.ENVIRONMENT}` : "unknown",
1724
+ tenant: e.tenantUuid,
1725
+ message: e.payload
1726
+ });
1715
1727
  e.markProcessed();
1716
1728
  } catch (error) {
1717
1729
  const type = String(error.type);