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 +133 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +45 -3
- package/dist/index.d.ts +45 -3
- package/dist/index.js +131 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -355,7 +355,7 @@ declare class OutboxRecord {
|
|
|
355
355
|
private _publishedAt;
|
|
356
356
|
private _lastAttempt;
|
|
357
357
|
private readonly _createdAt;
|
|
358
|
-
|
|
358
|
+
constructor(eventUuid: UUID, eventType: string, tenantUuid: UUID, aggregateUuid: UUID, aggregateType: string, topic: string, payload: string, status: ProcessStatus, attempts: number, errorMessage: string | undefined, publishedAt: DateTime | undefined, lastAttempt: DateTime | undefined, createdAt?: DateTime);
|
|
359
359
|
get eventUuid(): UUID;
|
|
360
360
|
get tenantUuid(): UUID;
|
|
361
361
|
get aggregateUuid(): UUID;
|
|
@@ -438,7 +438,7 @@ interface EventMessage {
|
|
|
438
438
|
topic: string;
|
|
439
439
|
producer: string;
|
|
440
440
|
tenant: UUID;
|
|
441
|
-
message: string
|
|
441
|
+
message: Record<string, any>;
|
|
442
442
|
}
|
|
443
443
|
interface EventManagerConnection {
|
|
444
444
|
userName: string;
|
|
@@ -513,6 +513,38 @@ interface Logger {
|
|
|
513
513
|
fatal(type: string, message: string, meta?: Record<string, any>): void;
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
+
declare class InboxRecord {
|
|
517
|
+
private readonly _eventUuid;
|
|
518
|
+
private readonly _tenantUuid;
|
|
519
|
+
private readonly _topic;
|
|
520
|
+
private readonly _producer;
|
|
521
|
+
private readonly _payload;
|
|
522
|
+
private _status;
|
|
523
|
+
private _attempts;
|
|
524
|
+
private _errorMessage;
|
|
525
|
+
private _lastAttempt;
|
|
526
|
+
private _processedAt;
|
|
527
|
+
private readonly _createdAt;
|
|
528
|
+
constructor(eventUuid: UUID, tenantUuid: UUID, topic: string, producer: string, payload: string, status: ProcessStatus, attempts?: number, errorMessage?: string | undefined, lastAttempt?: DateTime | undefined, processedAt?: DateTime | undefined, createdAt?: DateTime);
|
|
529
|
+
get eventUuid(): UUID;
|
|
530
|
+
get tenantUuid(): UUID;
|
|
531
|
+
get topic(): string;
|
|
532
|
+
get producer(): string;
|
|
533
|
+
get payload(): string;
|
|
534
|
+
get status(): ProcessStatus;
|
|
535
|
+
get attempts(): number;
|
|
536
|
+
get errorMessage(): string | undefined;
|
|
537
|
+
get lastAttempt(): DateTime | undefined;
|
|
538
|
+
get processedAt(): DateTime | undefined;
|
|
539
|
+
get createdAt(): DateTime;
|
|
540
|
+
incrementAttempts(): void;
|
|
541
|
+
markProcessed(): void;
|
|
542
|
+
markProcessing(): void;
|
|
543
|
+
markWithError(error: string): void;
|
|
544
|
+
toPrimitives(): Record<string, unknown>;
|
|
545
|
+
static reconstitute(data: Record<string, any>): InboxRecord;
|
|
546
|
+
}
|
|
547
|
+
|
|
516
548
|
interface ErrorTemplate {
|
|
517
549
|
type: string;
|
|
518
550
|
languages: Record<string, string>;
|
|
@@ -608,6 +640,16 @@ declare class DefaultMysqlOutboxRunner {
|
|
|
608
640
|
start(): Promise<void>;
|
|
609
641
|
}
|
|
610
642
|
|
|
643
|
+
declare class DefaultMysqlInboxRunner {
|
|
644
|
+
private readonly uowFactory;
|
|
645
|
+
private readonly eventManager;
|
|
646
|
+
private readonly interval;
|
|
647
|
+
private readonly maxEvents;
|
|
648
|
+
private errors;
|
|
649
|
+
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
650
|
+
private saveEvent;
|
|
651
|
+
}
|
|
652
|
+
|
|
611
653
|
interface ExchangeRatesProps {
|
|
612
654
|
base: Currency;
|
|
613
655
|
rates: Record<string, number>;
|
|
@@ -632,4 +674,4 @@ declare class StringVars {
|
|
|
632
674
|
}): string;
|
|
633
675
|
}
|
|
634
676
|
|
|
635
|
-
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
|
677
|
+
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlInboxRunner, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, EventMessage, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InboxRecord, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
package/dist/index.d.ts
CHANGED
|
@@ -355,7 +355,7 @@ declare class OutboxRecord {
|
|
|
355
355
|
private _publishedAt;
|
|
356
356
|
private _lastAttempt;
|
|
357
357
|
private readonly _createdAt;
|
|
358
|
-
|
|
358
|
+
constructor(eventUuid: UUID, eventType: string, tenantUuid: UUID, aggregateUuid: UUID, aggregateType: string, topic: string, payload: string, status: ProcessStatus, attempts: number, errorMessage: string | undefined, publishedAt: DateTime | undefined, lastAttempt: DateTime | undefined, createdAt?: DateTime);
|
|
359
359
|
get eventUuid(): UUID;
|
|
360
360
|
get tenantUuid(): UUID;
|
|
361
361
|
get aggregateUuid(): UUID;
|
|
@@ -438,7 +438,7 @@ interface EventMessage {
|
|
|
438
438
|
topic: string;
|
|
439
439
|
producer: string;
|
|
440
440
|
tenant: UUID;
|
|
441
|
-
message: string
|
|
441
|
+
message: Record<string, any>;
|
|
442
442
|
}
|
|
443
443
|
interface EventManagerConnection {
|
|
444
444
|
userName: string;
|
|
@@ -513,6 +513,38 @@ interface Logger {
|
|
|
513
513
|
fatal(type: string, message: string, meta?: Record<string, any>): void;
|
|
514
514
|
}
|
|
515
515
|
|
|
516
|
+
declare class InboxRecord {
|
|
517
|
+
private readonly _eventUuid;
|
|
518
|
+
private readonly _tenantUuid;
|
|
519
|
+
private readonly _topic;
|
|
520
|
+
private readonly _producer;
|
|
521
|
+
private readonly _payload;
|
|
522
|
+
private _status;
|
|
523
|
+
private _attempts;
|
|
524
|
+
private _errorMessage;
|
|
525
|
+
private _lastAttempt;
|
|
526
|
+
private _processedAt;
|
|
527
|
+
private readonly _createdAt;
|
|
528
|
+
constructor(eventUuid: UUID, tenantUuid: UUID, topic: string, producer: string, payload: string, status: ProcessStatus, attempts?: number, errorMessage?: string | undefined, lastAttempt?: DateTime | undefined, processedAt?: DateTime | undefined, createdAt?: DateTime);
|
|
529
|
+
get eventUuid(): UUID;
|
|
530
|
+
get tenantUuid(): UUID;
|
|
531
|
+
get topic(): string;
|
|
532
|
+
get producer(): string;
|
|
533
|
+
get payload(): string;
|
|
534
|
+
get status(): ProcessStatus;
|
|
535
|
+
get attempts(): number;
|
|
536
|
+
get errorMessage(): string | undefined;
|
|
537
|
+
get lastAttempt(): DateTime | undefined;
|
|
538
|
+
get processedAt(): DateTime | undefined;
|
|
539
|
+
get createdAt(): DateTime;
|
|
540
|
+
incrementAttempts(): void;
|
|
541
|
+
markProcessed(): void;
|
|
542
|
+
markProcessing(): void;
|
|
543
|
+
markWithError(error: string): void;
|
|
544
|
+
toPrimitives(): Record<string, unknown>;
|
|
545
|
+
static reconstitute(data: Record<string, any>): InboxRecord;
|
|
546
|
+
}
|
|
547
|
+
|
|
516
548
|
interface ErrorTemplate {
|
|
517
549
|
type: string;
|
|
518
550
|
languages: Record<string, string>;
|
|
@@ -608,6 +640,16 @@ declare class DefaultMysqlOutboxRunner {
|
|
|
608
640
|
start(): Promise<void>;
|
|
609
641
|
}
|
|
610
642
|
|
|
643
|
+
declare class DefaultMysqlInboxRunner {
|
|
644
|
+
private readonly uowFactory;
|
|
645
|
+
private readonly eventManager;
|
|
646
|
+
private readonly interval;
|
|
647
|
+
private readonly maxEvents;
|
|
648
|
+
private errors;
|
|
649
|
+
constructor(uowFactory: BasicUnitOfWorkFactory, eventManager: EventManager);
|
|
650
|
+
private saveEvent;
|
|
651
|
+
}
|
|
652
|
+
|
|
611
653
|
interface ExchangeRatesProps {
|
|
612
654
|
base: Currency;
|
|
613
655
|
rates: Record<string, number>;
|
|
@@ -632,4 +674,4 @@ declare class StringVars {
|
|
|
632
674
|
}): string;
|
|
633
675
|
}
|
|
634
676
|
|
|
635
|
-
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
|
677
|
+
export { BaseEntity, BaseEvent, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DefaultMysqlInboxRunner, DefaultMysqlOutboxRunner, DomainEntity, DomainError, DomainEvent, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, EventMessage, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InboxRecord, IntegrationEvent, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, OutboxRecord, PaymentGateway, PaymentStatus, Price, ProcessStatus, RouteCallback, RoutesCallbackList, StringVars, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
|
package/dist/index.js
CHANGED
|
@@ -1241,6 +1241,102 @@ var OutboxRecord = class _OutboxRecord {
|
|
|
1241
1241
|
}
|
|
1242
1242
|
};
|
|
1243
1243
|
|
|
1244
|
+
// src/infrastructure/contracts/InboxRecord.ts
|
|
1245
|
+
var InboxRecord = class _InboxRecord {
|
|
1246
|
+
constructor(eventUuid, tenantUuid, topic, producer, payload, status, attempts, errorMessage, lastAttempt, processedAt, createdAt) {
|
|
1247
|
+
this._eventUuid = eventUuid;
|
|
1248
|
+
this._tenantUuid = tenantUuid;
|
|
1249
|
+
this._topic = topic;
|
|
1250
|
+
this._producer = producer;
|
|
1251
|
+
this._payload = payload;
|
|
1252
|
+
this._status = status;
|
|
1253
|
+
this._attempts = attempts ?? 0;
|
|
1254
|
+
this._errorMessage = errorMessage ?? void 0;
|
|
1255
|
+
this._lastAttempt = lastAttempt ?? void 0;
|
|
1256
|
+
this._processedAt = processedAt ?? void 0;
|
|
1257
|
+
this._createdAt = createdAt ?? DateTime.now();
|
|
1258
|
+
}
|
|
1259
|
+
get eventUuid() {
|
|
1260
|
+
return this._eventUuid;
|
|
1261
|
+
}
|
|
1262
|
+
get tenantUuid() {
|
|
1263
|
+
return this._tenantUuid;
|
|
1264
|
+
}
|
|
1265
|
+
get topic() {
|
|
1266
|
+
return this._topic;
|
|
1267
|
+
}
|
|
1268
|
+
get producer() {
|
|
1269
|
+
return this._producer;
|
|
1270
|
+
}
|
|
1271
|
+
get payload() {
|
|
1272
|
+
return this._payload;
|
|
1273
|
+
}
|
|
1274
|
+
get status() {
|
|
1275
|
+
return this._status;
|
|
1276
|
+
}
|
|
1277
|
+
get attempts() {
|
|
1278
|
+
return this._attempts;
|
|
1279
|
+
}
|
|
1280
|
+
get errorMessage() {
|
|
1281
|
+
return this._errorMessage;
|
|
1282
|
+
}
|
|
1283
|
+
get lastAttempt() {
|
|
1284
|
+
return this._lastAttempt;
|
|
1285
|
+
}
|
|
1286
|
+
get processedAt() {
|
|
1287
|
+
return this._processedAt;
|
|
1288
|
+
}
|
|
1289
|
+
get createdAt() {
|
|
1290
|
+
return this._createdAt;
|
|
1291
|
+
}
|
|
1292
|
+
incrementAttempts() {
|
|
1293
|
+
this._attempts++;
|
|
1294
|
+
this._lastAttempt = DateTime.now();
|
|
1295
|
+
}
|
|
1296
|
+
markProcessed() {
|
|
1297
|
+
this._status = ProcessStatus.PROCESSED;
|
|
1298
|
+
this._processedAt = DateTime.now();
|
|
1299
|
+
}
|
|
1300
|
+
markProcessing() {
|
|
1301
|
+
this.incrementAttempts();
|
|
1302
|
+
this._status = ProcessStatus.PROCESSING;
|
|
1303
|
+
}
|
|
1304
|
+
markWithError(error) {
|
|
1305
|
+
this._status = this.attempts < 5 ? ProcessStatus.FAILED : ProcessStatus.DEAD;
|
|
1306
|
+
this._errorMessage = error;
|
|
1307
|
+
}
|
|
1308
|
+
toPrimitives() {
|
|
1309
|
+
return {
|
|
1310
|
+
eventUuid: this.eventUuid.value,
|
|
1311
|
+
tenantUuid: this.tenantUuid.value,
|
|
1312
|
+
topic: this.topic,
|
|
1313
|
+
producer: this.producer,
|
|
1314
|
+
payload: this.payload,
|
|
1315
|
+
status: this.status.value,
|
|
1316
|
+
attempts: this.attempts,
|
|
1317
|
+
errorMessage: this.errorMessage ?? void 0,
|
|
1318
|
+
lastAttempt: this.lastAttempt?.value ?? void 0,
|
|
1319
|
+
processedAt: this.processedAt?.value ?? void 0,
|
|
1320
|
+
createdAt: this.createdAt.value
|
|
1321
|
+
};
|
|
1322
|
+
}
|
|
1323
|
+
static reconstitute(data) {
|
|
1324
|
+
return new _InboxRecord(
|
|
1325
|
+
UUID.create(data.event_uuid),
|
|
1326
|
+
UUID.create(data.tenant_uuid),
|
|
1327
|
+
String(data.topic),
|
|
1328
|
+
String(data.producer),
|
|
1329
|
+
String(data.payload),
|
|
1330
|
+
ProcessStatus.create(data.status),
|
|
1331
|
+
Number(data.attempts),
|
|
1332
|
+
data.error_message ?? void 0,
|
|
1333
|
+
data.last_attempt ? DateTime.create(data.last_attempt) : void 0,
|
|
1334
|
+
data.processed_at ? DateTime.create(data.processed_at) : void 0,
|
|
1335
|
+
data.created_at ? DateTime.create(data.created_at) : void 0
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
|
|
1244
1340
|
// src/infrastructure/event-bus/EventBusMysqlRepository.ts
|
|
1245
1341
|
var EventBusMysqlRepository = class {
|
|
1246
1342
|
constructor(connection) {
|
|
@@ -1489,7 +1585,7 @@ var KafkaManager = class extends EventManager {
|
|
|
1489
1585
|
topic: String(json.topic),
|
|
1490
1586
|
producer: String(json.producer),
|
|
1491
1587
|
tenant: UUID.create(String(json.tenant)),
|
|
1492
|
-
message:
|
|
1588
|
+
message: json.message
|
|
1493
1589
|
});
|
|
1494
1590
|
const next = (BigInt(message.offset) + 1n).toString();
|
|
1495
1591
|
await this.consumer.commitOffsets([{ topic, partition, offset: next }]);
|
|
@@ -1643,6 +1739,7 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1643
1739
|
async sleep() {
|
|
1644
1740
|
return new Promise((r) => setTimeout(r, this.maxEvents));
|
|
1645
1741
|
}
|
|
1742
|
+
// HACER QUE PUEDA MANDAR UN OBJETO NO UN STRING POR KAFKA
|
|
1646
1743
|
async processOutboxRecord(e, eventBusRepository) {
|
|
1647
1744
|
try {
|
|
1648
1745
|
e.markProcessing();
|
|
@@ -1651,7 +1748,7 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1651
1748
|
topic: e.topic,
|
|
1652
1749
|
producer: process.env.NAME && process.env.ENVIRONMENT ? `${process.env.NAME}-${process.env.ENVIRONMENT}` : "unknown",
|
|
1653
1750
|
tenant: e.tenantUuid,
|
|
1654
|
-
message: e.payload
|
|
1751
|
+
message: JSON.parse(e.payload)
|
|
1655
1752
|
});
|
|
1656
1753
|
e.markProcessed();
|
|
1657
1754
|
} catch (error) {
|
|
@@ -1686,6 +1783,36 @@ var DefaultMysqlOutboxRunner = class {
|
|
|
1686
1783
|
}
|
|
1687
1784
|
};
|
|
1688
1785
|
|
|
1786
|
+
// src/infrastructure/runners/default-mysql-inbox-runner.ts
|
|
1787
|
+
var DefaultMysqlInboxRunner = class {
|
|
1788
|
+
constructor(uowFactory, eventManager) {
|
|
1789
|
+
this.errors = [];
|
|
1790
|
+
this.uowFactory = uowFactory;
|
|
1791
|
+
this.eventManager = eventManager;
|
|
1792
|
+
this.interval = Number(process.env.OUTBOX_RUNNER_INTERVAL_MS || 5e3);
|
|
1793
|
+
this.maxEvents = Number(process.env.OUTBOX_RUNNER_MAX_EVENTS || 20);
|
|
1794
|
+
}
|
|
1795
|
+
async saveEvent(e, repository) {
|
|
1796
|
+
let record = new InboxRecord(
|
|
1797
|
+
UUID.create(),
|
|
1798
|
+
e.tenant,
|
|
1799
|
+
e.topic,
|
|
1800
|
+
e.producer,
|
|
1801
|
+
JSON.stringify(e.message),
|
|
1802
|
+
ProcessStatus.PENDING
|
|
1803
|
+
);
|
|
1804
|
+
try {
|
|
1805
|
+
await repository.create(record);
|
|
1806
|
+
} catch (error) {
|
|
1807
|
+
const type = String(error.type);
|
|
1808
|
+
record.markWithError(type);
|
|
1809
|
+
throw new Error(type);
|
|
1810
|
+
} finally {
|
|
1811
|
+
await repository.update(record);
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
};
|
|
1815
|
+
|
|
1689
1816
|
// src/utils/ExchangeRates.ts
|
|
1690
1817
|
var ExchangeRates = class _ExchangeRates extends BaseObject {
|
|
1691
1818
|
constructor(props) {
|
|
@@ -1745,6 +1872,7 @@ export {
|
|
|
1745
1872
|
Country,
|
|
1746
1873
|
Currency,
|
|
1747
1874
|
DateTime,
|
|
1875
|
+
DefaultMysqlInboxRunner,
|
|
1748
1876
|
DefaultMysqlOutboxRunner,
|
|
1749
1877
|
DomainEntity,
|
|
1750
1878
|
DomainError,
|
|
@@ -1758,6 +1886,7 @@ export {
|
|
|
1758
1886
|
FatalError,
|
|
1759
1887
|
HttpHealthCheckController,
|
|
1760
1888
|
HttpNotFoundController,
|
|
1889
|
+
InboxRecord,
|
|
1761
1890
|
IntegrationEvent,
|
|
1762
1891
|
InternalError,
|
|
1763
1892
|
KafkaManager,
|