wsp-ms-core 1.0.83 → 1.0.84

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
@@ -36,6 +36,7 @@ __export(src_exports, {
36
36
  Country: () => Country,
37
37
  Currency: () => Currency,
38
38
  DateTime: () => DateTime,
39
+ DefaultMysqlInboxRunner: () => DefaultMysqlInboxRunner,
39
40
  DefaultMysqlOutboxRunner: () => DefaultMysqlOutboxRunner,
40
41
  DomainEntity: () => DomainEntity,
41
42
  DomainError: () => DomainError,
@@ -49,6 +50,7 @@ __export(src_exports, {
49
50
  FatalError: () => FatalError,
50
51
  HttpHealthCheckController: () => HttpHealthCheckController,
51
52
  HttpNotFoundController: () => HttpNotFoundController,
53
+ InboxRecord: () => InboxRecord,
52
54
  IntegrationEvent: () => IntegrationEvent,
53
55
  InternalError: () => InternalError,
54
56
  KafkaManager: () => KafkaManager,
@@ -1312,6 +1314,102 @@ var OutboxRecord = class _OutboxRecord {
1312
1314
  }
1313
1315
  };
1314
1316
 
1317
+ // src/infrastructure/contracts/InboxRecord.ts
1318
+ var InboxRecord = class _InboxRecord {
1319
+ constructor(eventUuid, tenantUuid, topic, producer, payload, status, attempts, errorMessage, lastAttempt, processedAt, createdAt) {
1320
+ this._eventUuid = eventUuid;
1321
+ this._tenantUuid = tenantUuid;
1322
+ this._topic = topic;
1323
+ this._producer = producer;
1324
+ this._payload = payload;
1325
+ this._status = status;
1326
+ this._attempts = attempts ?? 0;
1327
+ this._errorMessage = errorMessage ?? void 0;
1328
+ this._lastAttempt = lastAttempt ?? void 0;
1329
+ this._processedAt = processedAt ?? void 0;
1330
+ this._createdAt = createdAt ?? DateTime.now();
1331
+ }
1332
+ get eventUuid() {
1333
+ return this._eventUuid;
1334
+ }
1335
+ get tenantUuid() {
1336
+ return this._tenantUuid;
1337
+ }
1338
+ get topic() {
1339
+ return this._topic;
1340
+ }
1341
+ get producer() {
1342
+ return this._producer;
1343
+ }
1344
+ get payload() {
1345
+ return this._payload;
1346
+ }
1347
+ get status() {
1348
+ return this._status;
1349
+ }
1350
+ get attempts() {
1351
+ return this._attempts;
1352
+ }
1353
+ get errorMessage() {
1354
+ return this._errorMessage;
1355
+ }
1356
+ get lastAttempt() {
1357
+ return this._lastAttempt;
1358
+ }
1359
+ get processedAt() {
1360
+ return this._processedAt;
1361
+ }
1362
+ get createdAt() {
1363
+ return this._createdAt;
1364
+ }
1365
+ incrementAttempts() {
1366
+ this._attempts++;
1367
+ this._lastAttempt = DateTime.now();
1368
+ }
1369
+ markProcessed() {
1370
+ this._status = ProcessStatus.PROCESSED;
1371
+ this._processedAt = DateTime.now();
1372
+ }
1373
+ markProcessing() {
1374
+ this.incrementAttempts();
1375
+ this._status = ProcessStatus.PROCESSING;
1376
+ }
1377
+ markWithError(error) {
1378
+ this._status = this.attempts < 5 ? ProcessStatus.FAILED : ProcessStatus.DEAD;
1379
+ this._errorMessage = error;
1380
+ }
1381
+ toPrimitives() {
1382
+ return {
1383
+ eventUuid: this.eventUuid.value,
1384
+ tenantUuid: this.tenantUuid.value,
1385
+ topic: this.topic,
1386
+ producer: this.producer,
1387
+ payload: this.payload,
1388
+ status: this.status.value,
1389
+ attempts: this.attempts,
1390
+ errorMessage: this.errorMessage ?? void 0,
1391
+ lastAttempt: this.lastAttempt?.value ?? void 0,
1392
+ processedAt: this.processedAt?.value ?? void 0,
1393
+ createdAt: this.createdAt.value
1394
+ };
1395
+ }
1396
+ static reconstitute(data) {
1397
+ return new _InboxRecord(
1398
+ UUID.create(data.event_uuid),
1399
+ UUID.create(data.tenant_uuid),
1400
+ String(data.topic),
1401
+ String(data.producer),
1402
+ String(data.payload),
1403
+ ProcessStatus.create(data.status),
1404
+ Number(data.attempts),
1405
+ data.error_message ?? void 0,
1406
+ data.last_attempt ? DateTime.create(data.last_attempt) : void 0,
1407
+ data.processed_at ? DateTime.create(data.processed_at) : void 0,
1408
+ data.created_at ? DateTime.create(data.created_at) : void 0
1409
+ );
1410
+ }
1411
+ };
1412
+
1315
1413
  // src/infrastructure/event-bus/EventBusMysqlRepository.ts
1316
1414
  var EventBusMysqlRepository = class {
1317
1415
  constructor(connection) {
@@ -1560,7 +1658,7 @@ var KafkaManager = class extends EventManager {
1560
1658
  topic: String(json.topic),
1561
1659
  producer: String(json.producer),
1562
1660
  tenant: UUID.create(String(json.tenant)),
1563
- message: String(json.message)
1661
+ message: json.message
1564
1662
  });
1565
1663
  const next = (BigInt(message.offset) + 1n).toString();
1566
1664
  await this.consumer.commitOffsets([{ topic, partition, offset: next }]);
@@ -1714,6 +1812,7 @@ var DefaultMysqlOutboxRunner = class {
1714
1812
  async sleep() {
1715
1813
  return new Promise((r) => setTimeout(r, this.maxEvents));
1716
1814
  }
1815
+ // HACER QUE PUEDA MANDAR UN OBJETO NO UN STRING POR KAFKA
1717
1816
  async processOutboxRecord(e, eventBusRepository) {
1718
1817
  try {
1719
1818
  e.markProcessing();
@@ -1722,7 +1821,7 @@ var DefaultMysqlOutboxRunner = class {
1722
1821
  topic: e.topic,
1723
1822
  producer: process.env.NAME && process.env.ENVIRONMENT ? `${process.env.NAME}-${process.env.ENVIRONMENT}` : "unknown",
1724
1823
  tenant: e.tenantUuid,
1725
- message: e.payload
1824
+ message: JSON.parse(e.payload)
1726
1825
  });
1727
1826
  e.markProcessed();
1728
1827
  } catch (error) {
@@ -1757,6 +1856,36 @@ var DefaultMysqlOutboxRunner = class {
1757
1856
  }
1758
1857
  };
1759
1858
 
1859
+ // src/infrastructure/runners/default-mysql-inbox-runner.ts
1860
+ var DefaultMysqlInboxRunner = class {
1861
+ constructor(uowFactory, eventManager) {
1862
+ this.errors = [];
1863
+ this.uowFactory = uowFactory;
1864
+ this.eventManager = eventManager;
1865
+ this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
1866
+ this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
1867
+ }
1868
+ async saveEvent(e, repository) {
1869
+ let record = new InboxRecord(
1870
+ UUID.create(),
1871
+ e.tenant,
1872
+ e.topic,
1873
+ e.producer,
1874
+ JSON.stringify(e.message),
1875
+ ProcessStatus.PENDING
1876
+ );
1877
+ try {
1878
+ await repository.create(record);
1879
+ } catch (error) {
1880
+ const type = String(error.type);
1881
+ record.markWithError(type);
1882
+ throw new Error(type);
1883
+ } finally {
1884
+ await repository.update(record);
1885
+ }
1886
+ }
1887
+ };
1888
+
1760
1889
  // src/utils/ExchangeRates.ts
1761
1890
  var ExchangeRates = class _ExchangeRates extends BaseObject {
1762
1891
  constructor(props) {
@@ -1817,6 +1946,7 @@ var ExchangeRates = class _ExchangeRates extends BaseObject {
1817
1946
  Country,
1818
1947
  Currency,
1819
1948
  DateTime,
1949
+ DefaultMysqlInboxRunner,
1820
1950
  DefaultMysqlOutboxRunner,
1821
1951
  DomainEntity,
1822
1952
  DomainError,
@@ -1830,6 +1960,7 @@ var ExchangeRates = class _ExchangeRates extends BaseObject {
1830
1960
  FatalError,
1831
1961
  HttpHealthCheckController,
1832
1962
  HttpNotFoundController,
1963
+ InboxRecord,
1833
1964
  IntegrationEvent,
1834
1965
  InternalError,
1835
1966
  KafkaManager,