wsp-ms-core 1.0.81 → 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
@@ -174,6 +174,9 @@ var _DateTime = class _DateTime extends ValueObject {
174
174
  getWeekdayName(locale = "en") {
175
175
  return this._dt.setLocale(locale).toFormat("cccc");
176
176
  }
177
+ getDayName(locale = "en") {
178
+ return this._dt.setLocale(locale).toFormat("EEEE");
179
+ }
177
180
  format(format) {
178
181
  if (!_DateTime.FORMATS.hasOwnProperty(format)) {
179
182
  throw new Error(`Invalid format: ${format}`);
@@ -1158,9 +1161,9 @@ var EventManager = class {
1158
1161
  this._onCrash = null;
1159
1162
  this._onReconnect = null;
1160
1163
  }
1161
- async execRoute(topic, message) {
1164
+ async execRoute(topic, event) {
1162
1165
  if (this._callbackList[topic]) {
1163
- await this._callbackList[topic](message);
1166
+ await this._callbackList[topic](event);
1164
1167
  }
1165
1168
  }
1166
1169
  async execCallback(callback, data) {
@@ -1216,7 +1219,7 @@ var OutboxRecord = class _OutboxRecord {
1216
1219
  this._errorMessage = errorMessage;
1217
1220
  this._publishedAt = publishedAt;
1218
1221
  this._lastAttempt = lastAttempt;
1219
- this._createdAt = createdAt;
1222
+ this._createdAt = createdAt ?? DateTime.now();
1220
1223
  }
1221
1224
  get eventUuid() {
1222
1225
  return this._eventUuid;
@@ -1314,25 +1317,25 @@ var EventBusMysqlRepository = class {
1314
1317
  constructor(connection) {
1315
1318
  this.connection = connection;
1316
1319
  }
1317
- eventToRowValues(e) {
1320
+ recordToRowValues(record) {
1318
1321
  return [
1319
- e.eventUuid.value,
1320
- e.eventType,
1321
- e.tenantUuid.value,
1322
- e.aggregateUuid.value,
1323
- e.aggregateType,
1324
- e.topic,
1325
- e.payload,
1326
- e.status.value,
1327
- e.attempts,
1328
- e.errorMessage,
1329
- e.publishedAt?.value,
1330
- e.lastAttempt?.value,
1331
- 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
1332
1335
  ];
1333
1336
  }
1334
- async create(event) {
1335
- const values = this.eventToRowValues(event);
1337
+ async create(record) {
1338
+ const values = this.recordToRowValues(record);
1336
1339
  await this.connection.query(
1337
1340
  `INSERT INTO events_outbox (event_uuid, event_type, tenant_uuid, aggregate_uuid, aggregate_type, topic,
1338
1341
  payload, status, attempts, error_message, published_at, last_attempt, created_at)
@@ -1340,8 +1343,8 @@ var EventBusMysqlRepository = class {
1340
1343
  values
1341
1344
  );
1342
1345
  }
1343
- async update(event) {
1344
- 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];
1345
1348
  await this.connection.query(
1346
1349
  `UPDATE events_outbox
1347
1350
  SET status = ?,
@@ -1355,7 +1358,7 @@ var EventBusMysqlRepository = class {
1355
1358
  }
1356
1359
  async listPending(limit) {
1357
1360
  const result = await this.connection.query(
1358
- `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}`,
1359
1362
  []
1360
1363
  );
1361
1364
  return result.length > 0 ? result.map((r) => OutboxRecord.reconstitute(r)) : [];
@@ -1552,7 +1555,13 @@ var KafkaManager = class extends EventManager {
1552
1555
  eachMessage: async ({ topic, partition, message, heartbeat }) => {
1553
1556
  try {
1554
1557
  await this.execCallback(this._onMessage, `[New message detected for ${topic}]: ${message.value?.toString()}`);
1555
- 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
+ });
1556
1565
  const next = (BigInt(message.offset) + 1n).toString();
1557
1566
  await this.consumer.commitOffsets([{ topic, partition, offset: next }]);
1558
1567
  await heartbeat();
@@ -1568,11 +1577,12 @@ var KafkaManager = class extends EventManager {
1568
1577
  await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
1569
1578
  }
1570
1579
  }
1571
- async send(topic, message) {
1580
+ async send(e) {
1572
1581
  const evt = {
1573
1582
  date: DateTime.now().value,
1574
- producer: process.env.NAME && process.env.ENVIRONMENT ? `${process.env.NAME}-${process.env.ENVIRONMENT}` : "unknown",
1575
- data: message
1583
+ tenant: e.tenant.value,
1584
+ producer: e.producer,
1585
+ data: e.message
1576
1586
  };
1577
1587
  try {
1578
1588
  if (!this.producer) {
@@ -1580,7 +1590,7 @@ var KafkaManager = class extends EventManager {
1580
1590
  }
1581
1591
  await this.producer.connect();
1582
1592
  await this.producer.send({
1583
- topic,
1593
+ topic: e.topic,
1584
1594
  messages: [{ value: JSON.stringify(evt) }]
1585
1595
  });
1586
1596
  await this.producer.disconnect();
@@ -1708,7 +1718,12 @@ var DefaultMysqlOutboxRunner = class {
1708
1718
  try {
1709
1719
  e.markProcessing();
1710
1720
  await eventBusRepository.update(e);
1711
- 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
+ });
1712
1727
  e.markProcessed();
1713
1728
  } catch (error) {
1714
1729
  const type = String(error.type);