wsp-ms-core 1.0.70 → 1.0.72

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.d.ts CHANGED
@@ -178,53 +178,6 @@ declare class Currency extends ValueObject<string> {
178
178
  static isValid(raw: string | number): boolean;
179
179
  }
180
180
 
181
- declare class Country extends ValueObject<string> {
182
- static COUNTRIES: {
183
- [key: string]: {
184
- alpha2: string;
185
- alpha3: string;
186
- numeric: string;
187
- uuid: string;
188
- phoneCode: string;
189
- url: string;
190
- };
191
- };
192
- private static readonly NAMES;
193
- static readonly DEFAULT: Country;
194
- static readonly ARGENTINA: Country;
195
- static readonly ECUADOR: Country;
196
- static readonly PERU: Country;
197
- static readonly BRASIL: Country;
198
- static readonly CHILE: Country;
199
- static readonly VENEZUELA: Country;
200
- static readonly COLOMBIA: Country;
201
- static readonly BOLIVIA: Country;
202
- static readonly PARAGUAY: Country;
203
- static readonly USA: Country;
204
- private readonly _name;
205
- private readonly _alpha2;
206
- private readonly _alpha3;
207
- private readonly _numeric;
208
- private readonly _uuid;
209
- private readonly _phoneCode;
210
- private readonly _url;
211
- private constructor();
212
- protected validate(country: string): void;
213
- name(): string;
214
- alpha2(): string;
215
- alpha3(): string;
216
- numeric(): string;
217
- uuid(): string;
218
- phoneCode(): string;
219
- url(): string;
220
- static findCountryByAlpha2(alpha2: string): Country;
221
- static findCountryByUUID(uuid: string): Country;
222
- static create(country: string): Country;
223
- static createOrDefault(country: string): Country;
224
- toPrimitives(): Record<string, unknown>;
225
- static isValid(country: string): boolean;
226
- }
227
-
228
181
  declare class Email extends ValueObject<string> {
229
182
  static readonly REGEX: RegExp;
230
183
  private constructor();
@@ -542,6 +495,7 @@ declare class KafkaManager extends EventManager {
542
495
  constructor(connection: EventManagerConnection);
543
496
  private run;
544
497
  send(message: EventMessage): Promise<void>;
498
+ sendRaw(message: string, topic: string): Promise<void>;
545
499
  start(autocommit?: boolean): Promise<void>;
546
500
  pause(): Promise<void>;
547
501
  restart(): Promise<void>;
@@ -566,4 +520,4 @@ declare class ExchangeRates extends BaseObject<ExchangeRatesProps> {
566
520
  static createFromPrimitives(data: any): ExchangeRates;
567
521
  }
568
522
 
569
- export { BaseEntity, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Country, Currency, DatabaseConnection, DatabaseConnector, DateTime, DomainEntity, DomainError, DomainEvent, DomainEventStatus, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, EventMessage, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, PaymentGateway, PaymentStatus, Price, RouteCallback, RoutesCallbackList, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
523
+ export { BaseEntity, BaseObject, BasicUnitOfWork, BasicUnitOfWorkFactory, Currency, DatabaseConnection, DatabaseConnector, DateTime, DomainEntity, DomainError, DomainEvent, DomainEventStatus, Email, ErrorManager, ErrorManagerHandleResult, ErrorTemplate, EventBus, EventBusMysqlRepository, EventBusRepository, EventManager, EventManagerConnection, EventMessage, ExchangeRates, FatalError, HttpController, HttpHealthCheckController, HttpNotFoundController, HttpRequest, HttpResponse, InternalError, KafkaManager, Language, Logger, MysqlConnection, MysqlConnector, PaymentGateway, PaymentStatus, Price, RouteCallback, RoutesCallbackList, UUID, UnitOfWork, UploadedFile, UsageError, ValueObject, adaptExpressErrorHandler, adaptExpressRoute };
package/dist/index.js CHANGED
@@ -310,6 +310,7 @@ var DomainEvent = class _DomainEvent {
310
310
  this._publishedAt = DateTime.now();
311
311
  }
312
312
  markProcessing() {
313
+ this.incrementAttempts();
313
314
  this._status = DomainEventStatus.PROCESSING;
314
315
  }
315
316
  markWithError(error) {
@@ -437,297 +438,6 @@ _Currency.ARS = new _Currency("ARS");
437
438
  _Currency.BRL = new _Currency("BRL");
438
439
  var Currency = _Currency;
439
440
 
440
- // src/utils/StringVars.ts
441
- var StringVars = class {
442
- static parse(str, ob) {
443
- const regex = /{{(.*?)}}/g;
444
- return str.replace(regex, (match, variable) => {
445
- if (ob.hasOwnProperty(variable.trim())) {
446
- return ob[variable.trim()];
447
- } else {
448
- return match;
449
- }
450
- });
451
- }
452
- };
453
-
454
- // src/infrastructure/errors/ErrorManager.ts
455
- var _ErrorManager = class _ErrorManager {
456
- constructor(logger = null) {
457
- this.logger = logger;
458
- }
459
- getDefaultMessage(lang) {
460
- return _ErrorManager.DEFAULT_MESSAGES[lang.value] || _ErrorManager.DEFAULT_MESSAGES[lang.base()] || "error";
461
- }
462
- onFatal(err, lang) {
463
- this.logger?.fatal(err.type, err.message);
464
- return { status: "ERROR", message: this.getDefaultMessage(lang) };
465
- }
466
- onInternal(err, lang) {
467
- this.logger?.error(err.type, err.message);
468
- return { status: "ERROR", message: this.getDefaultMessage(lang) };
469
- }
470
- onUsage(err, lang) {
471
- const tmpl = _ErrorManager.TEMPLATES.get(err.type);
472
- if (!tmpl) {
473
- this.logger?.error("TEMPLATE_NOT_FOUND", `${err.type}`);
474
- return { status: "ERROR", message: this.getDefaultMessage(lang) };
475
- }
476
- const code = lang.value;
477
- const base = lang.base();
478
- const rawMsg = tmpl.languages[code] ?? tmpl.languages[base] ?? this.getDefaultMessage(lang);
479
- return {
480
- status: 400,
481
- message: StringVars.parse(rawMsg, err.vars)
482
- };
483
- }
484
- onUnknown(err, lang) {
485
- this.logger?.error("UNKNOWN_ERROR", err.message);
486
- return { status: "ERROR", message: this.getDefaultMessage(lang) };
487
- }
488
- handle(err, lang) {
489
- if (["local", "dev"].includes(process.env.ENVIRONMENT ?? "")) {
490
- console.log(err);
491
- }
492
- if (err instanceof FatalError) {
493
- return this.onFatal(err, lang);
494
- }
495
- if (err instanceof InternalError) {
496
- return this.onInternal(err, lang);
497
- }
498
- if (err instanceof UsageError) {
499
- return this.onUsage(err, lang);
500
- }
501
- return this.onUnknown(err, lang);
502
- }
503
- static addTemplate(template) {
504
- _ErrorManager.TEMPLATES.set(template.type, template);
505
- }
506
- };
507
- _ErrorManager.DEFAULT_MESSAGES = {
508
- "es": "Ups, hemos encontrado un error. Nuestro equipo ya est\xE1 trabajando para solucionarlo",
509
- "en": "Ups, we found an error. Our team is working on it.",
510
- "pt": "Ops, encontramos um bug. Nossa equipe j\xE1 est\xE1 trabalhando para resolver isso."
511
- };
512
- _ErrorManager.APP_ERRORS = {
513
- UNDEFINED: "UNDEFINED_ERROR",
514
- PROCESS: "PROCESS_ERROR",
515
- DATABASE: "DATABASE_ERROR"
516
- };
517
- _ErrorManager.TEMPLATES = /* @__PURE__ */ new Map();
518
- var ErrorManager = _ErrorManager;
519
-
520
- // src/domain/value-objects/Country.ts
521
- ErrorManager.addTemplate({
522
- type: "INVALID_COUNTRY",
523
- languages: {
524
- "es": "El pa\xEDs <{{country}}> no es v\xE1lido o no est\xE1 soportado",
525
- "en": "Country <{{country}}> is not valid or not supported"
526
- }
527
- });
528
- ErrorManager.addTemplate({
529
- type: "COUNTRY_NOT_FOUND_BY_ALPHA2",
530
- languages: {
531
- "es": "No se encontr\xF3 pa\xEDs con c\xF3digo alpha2 <{{alpha2}}>",
532
- "en": "Country not found with alpha2 code <{{alpha2}}>"
533
- }
534
- });
535
- ErrorManager.addTemplate({
536
- type: "COUNTRY_NOT_FOUND_BY_UUID",
537
- languages: {
538
- "es": "No se encontr\xF3 pa\xEDs con UUID <{{uuid}}>",
539
- "en": "Country not found with UUID <{{uuid}}>"
540
- }
541
- });
542
- var _Country = class _Country extends ValueObject {
543
- constructor(country) {
544
- const normalizedCountry = country.toUpperCase().trim();
545
- super(normalizedCountry);
546
- this._name = normalizedCountry;
547
- this._alpha2 = _Country.COUNTRIES[normalizedCountry].alpha2;
548
- this._alpha3 = _Country.COUNTRIES[normalizedCountry].alpha3;
549
- this._numeric = _Country.COUNTRIES[normalizedCountry].numeric;
550
- this._uuid = _Country.COUNTRIES[normalizedCountry].uuid;
551
- this._phoneCode = _Country.COUNTRIES[normalizedCountry].phoneCode;
552
- this._url = _Country.COUNTRIES[normalizedCountry].url;
553
- }
554
- validate(country) {
555
- if (!_Country.NAMES.includes(country)) {
556
- throw new UsageError("INVALID_COUNTRY", { country });
557
- }
558
- }
559
- name() {
560
- return this._name;
561
- }
562
- alpha2() {
563
- return this._alpha2;
564
- }
565
- alpha3() {
566
- return this._alpha3;
567
- }
568
- numeric() {
569
- return this._numeric;
570
- }
571
- uuid() {
572
- return this._uuid;
573
- }
574
- phoneCode() {
575
- return this._phoneCode;
576
- }
577
- url() {
578
- return this._url;
579
- }
580
- static findCountryByAlpha2(alpha2) {
581
- for (const [country, codes] of Object.entries(_Country.COUNTRIES)) {
582
- if (codes.alpha2 === alpha2.toUpperCase()) {
583
- return new _Country(country);
584
- }
585
- }
586
- throw new UsageError("COUNTRY_NOT_FOUND_BY_ALPHA2", { alpha2 });
587
- }
588
- static findCountryByUUID(uuid) {
589
- for (const [country, codes] of Object.entries(_Country.COUNTRIES)) {
590
- if (codes.uuid === uuid) {
591
- return new _Country(country);
592
- }
593
- }
594
- throw new UsageError("COUNTRY_NOT_FOUND_BY_UUID", { uuid });
595
- }
596
- static create(country) {
597
- return new _Country(country);
598
- }
599
- static createOrDefault(country) {
600
- try {
601
- return new _Country(country);
602
- } catch (error) {
603
- return _Country.DEFAULT;
604
- }
605
- }
606
- toPrimitives() {
607
- return {
608
- value: this.value,
609
- name: this._name,
610
- alpha2: this._alpha2,
611
- alpha3: this._alpha3,
612
- numeric: this._numeric,
613
- uuid: this._uuid,
614
- phoneCode: this._phoneCode,
615
- url: this._url
616
- };
617
- }
618
- static isValid(country) {
619
- try {
620
- _Country.create(country);
621
- return true;
622
- } catch {
623
- return false;
624
- }
625
- }
626
- };
627
- _Country.COUNTRIES = {
628
- URUGUAY: {
629
- alpha2: "UY",
630
- alpha3: "URY",
631
- numeric: "858",
632
- phoneCode: "+598",
633
- uuid: "5739ecc0-d12b-4db5-8897-e03a04a95c72",
634
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/uruguay.png"
635
- },
636
- ARGENTINA: {
637
- alpha2: "AR",
638
- alpha3: "ARG",
639
- numeric: "032",
640
- phoneCode: "+54",
641
- uuid: "66663efe-ab7a-4166-b971-9f36fd0ea6b2",
642
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/argentina.png"
643
- },
644
- ECUADOR: {
645
- alpha2: "EC",
646
- alpha3: "ECU",
647
- numeric: "218",
648
- phoneCode: "+593",
649
- uuid: "ee109239-0150-4e5f-9ff2-a85f270092b1",
650
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/ecuador.png"
651
- },
652
- PERU: {
653
- alpha2: "PE",
654
- alpha3: "PER",
655
- numeric: "604",
656
- phoneCode: "+51",
657
- uuid: "e4d61ef5-b92d-4f9c-8ec1-23f4beb50abd",
658
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/peru.png"
659
- },
660
- BRASIL: {
661
- alpha2: "BR",
662
- alpha3: "BRA",
663
- numeric: "076",
664
- phoneCode: "+55",
665
- uuid: "b7b91d72-deaf-4641-957c-a65003e33104",
666
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/brasil.png"
667
- },
668
- CHILE: {
669
- alpha2: "CL",
670
- alpha3: "CHL",
671
- numeric: "152",
672
- phoneCode: "+56",
673
- uuid: "f69b35f4-d734-4c76-866c-29a18bf000fb",
674
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/chile.png"
675
- },
676
- VENEZUELA: {
677
- alpha2: "VE",
678
- alpha3: "VEN",
679
- numeric: "862",
680
- phoneCode: "+58",
681
- uuid: "31b6c591-63f6-43db-8ea9-829bb03746c5",
682
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/venezuela.png"
683
- },
684
- COLOMBIA: {
685
- alpha2: "CO",
686
- alpha3: "COL",
687
- numeric: "170",
688
- phoneCode: "+57",
689
- uuid: "6fdfe34b-6726-4604-96af-665ea5fc9239",
690
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/colombia.png"
691
- },
692
- BOLIVIA: {
693
- alpha2: "BO",
694
- alpha3: "BOL",
695
- numeric: "068",
696
- phoneCode: "+591",
697
- uuid: "948886db-c280-4ba7-a777-a76c180b295b",
698
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/bolivia.png"
699
- },
700
- PARAGUAY: {
701
- alpha2: "PY",
702
- alpha3: "PRY",
703
- numeric: "600",
704
- phoneCode: "+595",
705
- uuid: "d67b3472-e38d-4900-8ae3-02d99cd1d884",
706
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/paraguay.png"
707
- },
708
- USA: {
709
- alpha2: "US",
710
- alpha3: "USA",
711
- numeric: "840",
712
- phoneCode: "+1",
713
- uuid: "16ac3b9b-8f7b-4c54-91d5-d62c7cd74ad4",
714
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/usa.png"
715
- }
716
- };
717
- _Country.NAMES = Object.keys(_Country.COUNTRIES);
718
- _Country.DEFAULT = new _Country("URUGUAY");
719
- _Country.ARGENTINA = new _Country("ARGENTINA");
720
- _Country.ECUADOR = new _Country("ECUADOR");
721
- _Country.PERU = new _Country("PERU");
722
- _Country.BRASIL = new _Country("BRASIL");
723
- _Country.CHILE = new _Country("CHILE");
724
- _Country.VENEZUELA = new _Country("VENEZUELA");
725
- _Country.COLOMBIA = new _Country("COLOMBIA");
726
- _Country.BOLIVIA = new _Country("BOLIVIA");
727
- _Country.PARAGUAY = new _Country("PARAGUAY");
728
- _Country.USA = new _Country("USA");
729
- var Country = _Country;
730
-
731
441
  // src/domain/value-objects/Email.ts
732
442
  var _Email = class _Email extends ValueObject {
733
443
  constructor(email) {
@@ -851,6 +561,86 @@ _Language.SPANISH_NICARAGUA = new _Language("es-ni");
851
561
  _Language.SPANISH_PUERTO_RICO = new _Language("es-pr");
852
562
  var Language = _Language;
853
563
 
564
+ // src/utils/StringVars.ts
565
+ var StringVars = class {
566
+ static parse(str, ob) {
567
+ const regex = /{{(.*?)}}/g;
568
+ return str.replace(regex, (match, variable) => {
569
+ if (ob.hasOwnProperty(variable.trim())) {
570
+ return ob[variable.trim()];
571
+ } else {
572
+ return match;
573
+ }
574
+ });
575
+ }
576
+ };
577
+
578
+ // src/infrastructure/errors/ErrorManager.ts
579
+ var _ErrorManager = class _ErrorManager {
580
+ constructor(logger = null) {
581
+ this.logger = logger;
582
+ }
583
+ getDefaultMessage(lang) {
584
+ return _ErrorManager.DEFAULT_MESSAGES[lang.value] || _ErrorManager.DEFAULT_MESSAGES[lang.base()] || "error";
585
+ }
586
+ onFatal(err, lang) {
587
+ this.logger?.fatal(err.type, err.message);
588
+ return { status: "ERROR", message: this.getDefaultMessage(lang) };
589
+ }
590
+ onInternal(err, lang) {
591
+ this.logger?.error(err.type, err.message);
592
+ return { status: "ERROR", message: this.getDefaultMessage(lang) };
593
+ }
594
+ onUsage(err, lang) {
595
+ const tmpl = _ErrorManager.TEMPLATES.get(err.type);
596
+ if (!tmpl) {
597
+ this.logger?.error("TEMPLATE_NOT_FOUND", `${err.type}`);
598
+ return { status: "ERROR", message: this.getDefaultMessage(lang) };
599
+ }
600
+ const code = lang.value;
601
+ const base = lang.base();
602
+ const rawMsg = tmpl.languages[code] ?? tmpl.languages[base] ?? this.getDefaultMessage(lang);
603
+ return {
604
+ status: 400,
605
+ message: StringVars.parse(rawMsg, err.vars)
606
+ };
607
+ }
608
+ onUnknown(err, lang) {
609
+ this.logger?.error("UNKNOWN_ERROR", err.message);
610
+ return { status: "ERROR", message: this.getDefaultMessage(lang) };
611
+ }
612
+ handle(err, lang) {
613
+ if (["local", "dev"].includes(process.env.ENVIRONMENT ?? "")) {
614
+ console.log(err);
615
+ }
616
+ if (err instanceof FatalError) {
617
+ return this.onFatal(err, lang);
618
+ }
619
+ if (err instanceof InternalError) {
620
+ return this.onInternal(err, lang);
621
+ }
622
+ if (err instanceof UsageError) {
623
+ return this.onUsage(err, lang);
624
+ }
625
+ return this.onUnknown(err, lang);
626
+ }
627
+ static addTemplate(template) {
628
+ _ErrorManager.TEMPLATES.set(template.type, template);
629
+ }
630
+ };
631
+ _ErrorManager.DEFAULT_MESSAGES = {
632
+ "es": "Ups, hemos encontrado un error. Nuestro equipo ya est\xE1 trabajando para solucionarlo",
633
+ "en": "Ups, we found an error. Our team is working on it.",
634
+ "pt": "Ops, encontramos um bug. Nossa equipe j\xE1 est\xE1 trabalhando para resolver isso."
635
+ };
636
+ _ErrorManager.APP_ERRORS = {
637
+ UNDEFINED: "UNDEFINED_ERROR",
638
+ PROCESS: "PROCESS_ERROR",
639
+ DATABASE: "DATABASE_ERROR"
640
+ };
641
+ _ErrorManager.TEMPLATES = /* @__PURE__ */ new Map();
642
+ var ErrorManager = _ErrorManager;
643
+
854
644
  // src/domain/value-objects/Price.ts
855
645
  ErrorManager.addTemplate({
856
646
  type: "INVALID_PRICE_AMOUNT",
@@ -1379,6 +1169,7 @@ var EventBusMysqlRepository = class {
1379
1169
  }
1380
1170
  async update(event) {
1381
1171
  const values = [event.status.value, event.attempts, event.errorMessage, event.publishedAt?.value, event.lastAttempt?.value, event.eventUuid.value];
1172
+ console.log(values);
1382
1173
  await this.connection.query(
1383
1174
  `UPDATE events_outbox
1384
1175
  SET status = ?,
@@ -1474,6 +1265,21 @@ var KafkaManager = class extends EventManager {
1474
1265
  await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
1475
1266
  }
1476
1267
  }
1268
+ async sendRaw(message, topic) {
1269
+ try {
1270
+ if (!this.producer) {
1271
+ throw new InternalError(ErrorManager.APP_ERRORS.PROCESS, "Producer not initialized");
1272
+ }
1273
+ await this.producer.connect();
1274
+ await this.producer.send({
1275
+ topic,
1276
+ messages: [{ value: message }]
1277
+ });
1278
+ await this.producer.disconnect();
1279
+ } catch (error) {
1280
+ await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
1281
+ }
1282
+ }
1477
1283
  async start(autocommit = false) {
1478
1284
  this.consumer.on(this.consumer.events.CRASH, async (error) => {
1479
1285
  await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.payload.error.stack));
@@ -1546,7 +1352,6 @@ export {
1546
1352
  BaseObject,
1547
1353
  BasicUnitOfWork,
1548
1354
  BasicUnitOfWorkFactory,
1549
- Country,
1550
1355
  Currency,
1551
1356
  DateTime,
1552
1357
  DomainEntity,