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.cjs CHANGED
@@ -32,7 +32,6 @@ __export(src_exports, {
32
32
  BaseObject: () => BaseObject,
33
33
  BasicUnitOfWork: () => BasicUnitOfWork,
34
34
  BasicUnitOfWorkFactory: () => BasicUnitOfWorkFactory,
35
- Country: () => Country,
36
35
  Currency: () => Currency,
37
36
  DateTime: () => DateTime,
38
37
  DomainEntity: () => DomainEntity,
@@ -376,6 +375,7 @@ var DomainEvent = class _DomainEvent {
376
375
  this._publishedAt = DateTime.now();
377
376
  }
378
377
  markProcessing() {
378
+ this.incrementAttempts();
379
379
  this._status = DomainEventStatus.PROCESSING;
380
380
  }
381
381
  markWithError(error) {
@@ -503,297 +503,6 @@ _Currency.ARS = new _Currency("ARS");
503
503
  _Currency.BRL = new _Currency("BRL");
504
504
  var Currency = _Currency;
505
505
 
506
- // src/utils/StringVars.ts
507
- var StringVars = class {
508
- static parse(str, ob) {
509
- const regex = /{{(.*?)}}/g;
510
- return str.replace(regex, (match, variable) => {
511
- if (ob.hasOwnProperty(variable.trim())) {
512
- return ob[variable.trim()];
513
- } else {
514
- return match;
515
- }
516
- });
517
- }
518
- };
519
-
520
- // src/infrastructure/errors/ErrorManager.ts
521
- var _ErrorManager = class _ErrorManager {
522
- constructor(logger = null) {
523
- this.logger = logger;
524
- }
525
- getDefaultMessage(lang) {
526
- return _ErrorManager.DEFAULT_MESSAGES[lang.value] || _ErrorManager.DEFAULT_MESSAGES[lang.base()] || "error";
527
- }
528
- onFatal(err, lang) {
529
- this.logger?.fatal(err.type, err.message);
530
- return { status: "ERROR", message: this.getDefaultMessage(lang) };
531
- }
532
- onInternal(err, lang) {
533
- this.logger?.error(err.type, err.message);
534
- return { status: "ERROR", message: this.getDefaultMessage(lang) };
535
- }
536
- onUsage(err, lang) {
537
- const tmpl = _ErrorManager.TEMPLATES.get(err.type);
538
- if (!tmpl) {
539
- this.logger?.error("TEMPLATE_NOT_FOUND", `${err.type}`);
540
- return { status: "ERROR", message: this.getDefaultMessage(lang) };
541
- }
542
- const code = lang.value;
543
- const base = lang.base();
544
- const rawMsg = tmpl.languages[code] ?? tmpl.languages[base] ?? this.getDefaultMessage(lang);
545
- return {
546
- status: 400,
547
- message: StringVars.parse(rawMsg, err.vars)
548
- };
549
- }
550
- onUnknown(err, lang) {
551
- this.logger?.error("UNKNOWN_ERROR", err.message);
552
- return { status: "ERROR", message: this.getDefaultMessage(lang) };
553
- }
554
- handle(err, lang) {
555
- if (["local", "dev"].includes(process.env.ENVIRONMENT ?? "")) {
556
- console.log(err);
557
- }
558
- if (err instanceof FatalError) {
559
- return this.onFatal(err, lang);
560
- }
561
- if (err instanceof InternalError) {
562
- return this.onInternal(err, lang);
563
- }
564
- if (err instanceof UsageError) {
565
- return this.onUsage(err, lang);
566
- }
567
- return this.onUnknown(err, lang);
568
- }
569
- static addTemplate(template) {
570
- _ErrorManager.TEMPLATES.set(template.type, template);
571
- }
572
- };
573
- _ErrorManager.DEFAULT_MESSAGES = {
574
- "es": "Ups, hemos encontrado un error. Nuestro equipo ya est\xE1 trabajando para solucionarlo",
575
- "en": "Ups, we found an error. Our team is working on it.",
576
- "pt": "Ops, encontramos um bug. Nossa equipe j\xE1 est\xE1 trabalhando para resolver isso."
577
- };
578
- _ErrorManager.APP_ERRORS = {
579
- UNDEFINED: "UNDEFINED_ERROR",
580
- PROCESS: "PROCESS_ERROR",
581
- DATABASE: "DATABASE_ERROR"
582
- };
583
- _ErrorManager.TEMPLATES = /* @__PURE__ */ new Map();
584
- var ErrorManager = _ErrorManager;
585
-
586
- // src/domain/value-objects/Country.ts
587
- ErrorManager.addTemplate({
588
- type: "INVALID_COUNTRY",
589
- languages: {
590
- "es": "El pa\xEDs <{{country}}> no es v\xE1lido o no est\xE1 soportado",
591
- "en": "Country <{{country}}> is not valid or not supported"
592
- }
593
- });
594
- ErrorManager.addTemplate({
595
- type: "COUNTRY_NOT_FOUND_BY_ALPHA2",
596
- languages: {
597
- "es": "No se encontr\xF3 pa\xEDs con c\xF3digo alpha2 <{{alpha2}}>",
598
- "en": "Country not found with alpha2 code <{{alpha2}}>"
599
- }
600
- });
601
- ErrorManager.addTemplate({
602
- type: "COUNTRY_NOT_FOUND_BY_UUID",
603
- languages: {
604
- "es": "No se encontr\xF3 pa\xEDs con UUID <{{uuid}}>",
605
- "en": "Country not found with UUID <{{uuid}}>"
606
- }
607
- });
608
- var _Country = class _Country extends ValueObject {
609
- constructor(country) {
610
- const normalizedCountry = country.toUpperCase().trim();
611
- super(normalizedCountry);
612
- this._name = normalizedCountry;
613
- this._alpha2 = _Country.COUNTRIES[normalizedCountry].alpha2;
614
- this._alpha3 = _Country.COUNTRIES[normalizedCountry].alpha3;
615
- this._numeric = _Country.COUNTRIES[normalizedCountry].numeric;
616
- this._uuid = _Country.COUNTRIES[normalizedCountry].uuid;
617
- this._phoneCode = _Country.COUNTRIES[normalizedCountry].phoneCode;
618
- this._url = _Country.COUNTRIES[normalizedCountry].url;
619
- }
620
- validate(country) {
621
- if (!_Country.NAMES.includes(country)) {
622
- throw new UsageError("INVALID_COUNTRY", { country });
623
- }
624
- }
625
- name() {
626
- return this._name;
627
- }
628
- alpha2() {
629
- return this._alpha2;
630
- }
631
- alpha3() {
632
- return this._alpha3;
633
- }
634
- numeric() {
635
- return this._numeric;
636
- }
637
- uuid() {
638
- return this._uuid;
639
- }
640
- phoneCode() {
641
- return this._phoneCode;
642
- }
643
- url() {
644
- return this._url;
645
- }
646
- static findCountryByAlpha2(alpha2) {
647
- for (const [country, codes] of Object.entries(_Country.COUNTRIES)) {
648
- if (codes.alpha2 === alpha2.toUpperCase()) {
649
- return new _Country(country);
650
- }
651
- }
652
- throw new UsageError("COUNTRY_NOT_FOUND_BY_ALPHA2", { alpha2 });
653
- }
654
- static findCountryByUUID(uuid) {
655
- for (const [country, codes] of Object.entries(_Country.COUNTRIES)) {
656
- if (codes.uuid === uuid) {
657
- return new _Country(country);
658
- }
659
- }
660
- throw new UsageError("COUNTRY_NOT_FOUND_BY_UUID", { uuid });
661
- }
662
- static create(country) {
663
- return new _Country(country);
664
- }
665
- static createOrDefault(country) {
666
- try {
667
- return new _Country(country);
668
- } catch (error) {
669
- return _Country.DEFAULT;
670
- }
671
- }
672
- toPrimitives() {
673
- return {
674
- value: this.value,
675
- name: this._name,
676
- alpha2: this._alpha2,
677
- alpha3: this._alpha3,
678
- numeric: this._numeric,
679
- uuid: this._uuid,
680
- phoneCode: this._phoneCode,
681
- url: this._url
682
- };
683
- }
684
- static isValid(country) {
685
- try {
686
- _Country.create(country);
687
- return true;
688
- } catch {
689
- return false;
690
- }
691
- }
692
- };
693
- _Country.COUNTRIES = {
694
- URUGUAY: {
695
- alpha2: "UY",
696
- alpha3: "URY",
697
- numeric: "858",
698
- phoneCode: "+598",
699
- uuid: "5739ecc0-d12b-4db5-8897-e03a04a95c72",
700
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/uruguay.png"
701
- },
702
- ARGENTINA: {
703
- alpha2: "AR",
704
- alpha3: "ARG",
705
- numeric: "032",
706
- phoneCode: "+54",
707
- uuid: "66663efe-ab7a-4166-b971-9f36fd0ea6b2",
708
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/argentina.png"
709
- },
710
- ECUADOR: {
711
- alpha2: "EC",
712
- alpha3: "ECU",
713
- numeric: "218",
714
- phoneCode: "+593",
715
- uuid: "ee109239-0150-4e5f-9ff2-a85f270092b1",
716
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/ecuador.png"
717
- },
718
- PERU: {
719
- alpha2: "PE",
720
- alpha3: "PER",
721
- numeric: "604",
722
- phoneCode: "+51",
723
- uuid: "e4d61ef5-b92d-4f9c-8ec1-23f4beb50abd",
724
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/peru.png"
725
- },
726
- BRASIL: {
727
- alpha2: "BR",
728
- alpha3: "BRA",
729
- numeric: "076",
730
- phoneCode: "+55",
731
- uuid: "b7b91d72-deaf-4641-957c-a65003e33104",
732
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/brasil.png"
733
- },
734
- CHILE: {
735
- alpha2: "CL",
736
- alpha3: "CHL",
737
- numeric: "152",
738
- phoneCode: "+56",
739
- uuid: "f69b35f4-d734-4c76-866c-29a18bf000fb",
740
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/chile.png"
741
- },
742
- VENEZUELA: {
743
- alpha2: "VE",
744
- alpha3: "VEN",
745
- numeric: "862",
746
- phoneCode: "+58",
747
- uuid: "31b6c591-63f6-43db-8ea9-829bb03746c5",
748
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/venezuela.png"
749
- },
750
- COLOMBIA: {
751
- alpha2: "CO",
752
- alpha3: "COL",
753
- numeric: "170",
754
- phoneCode: "+57",
755
- uuid: "6fdfe34b-6726-4604-96af-665ea5fc9239",
756
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/colombia.png"
757
- },
758
- BOLIVIA: {
759
- alpha2: "BO",
760
- alpha3: "BOL",
761
- numeric: "068",
762
- phoneCode: "+591",
763
- uuid: "948886db-c280-4ba7-a777-a76c180b295b",
764
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/bolivia.png"
765
- },
766
- PARAGUAY: {
767
- alpha2: "PY",
768
- alpha3: "PRY",
769
- numeric: "600",
770
- phoneCode: "+595",
771
- uuid: "d67b3472-e38d-4900-8ae3-02d99cd1d884",
772
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/paraguay.png"
773
- },
774
- USA: {
775
- alpha2: "US",
776
- alpha3: "USA",
777
- numeric: "840",
778
- phoneCode: "+1",
779
- uuid: "16ac3b9b-8f7b-4c54-91d5-d62c7cd74ad4",
780
- url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/usa.png"
781
- }
782
- };
783
- _Country.NAMES = Object.keys(_Country.COUNTRIES);
784
- _Country.DEFAULT = new _Country("URUGUAY");
785
- _Country.ARGENTINA = new _Country("ARGENTINA");
786
- _Country.ECUADOR = new _Country("ECUADOR");
787
- _Country.PERU = new _Country("PERU");
788
- _Country.BRASIL = new _Country("BRASIL");
789
- _Country.CHILE = new _Country("CHILE");
790
- _Country.VENEZUELA = new _Country("VENEZUELA");
791
- _Country.COLOMBIA = new _Country("COLOMBIA");
792
- _Country.BOLIVIA = new _Country("BOLIVIA");
793
- _Country.PARAGUAY = new _Country("PARAGUAY");
794
- _Country.USA = new _Country("USA");
795
- var Country = _Country;
796
-
797
506
  // src/domain/value-objects/Email.ts
798
507
  var _Email = class _Email extends ValueObject {
799
508
  constructor(email) {
@@ -917,6 +626,86 @@ _Language.SPANISH_NICARAGUA = new _Language("es-ni");
917
626
  _Language.SPANISH_PUERTO_RICO = new _Language("es-pr");
918
627
  var Language = _Language;
919
628
 
629
+ // src/utils/StringVars.ts
630
+ var StringVars = class {
631
+ static parse(str, ob) {
632
+ const regex = /{{(.*?)}}/g;
633
+ return str.replace(regex, (match, variable) => {
634
+ if (ob.hasOwnProperty(variable.trim())) {
635
+ return ob[variable.trim()];
636
+ } else {
637
+ return match;
638
+ }
639
+ });
640
+ }
641
+ };
642
+
643
+ // src/infrastructure/errors/ErrorManager.ts
644
+ var _ErrorManager = class _ErrorManager {
645
+ constructor(logger = null) {
646
+ this.logger = logger;
647
+ }
648
+ getDefaultMessage(lang) {
649
+ return _ErrorManager.DEFAULT_MESSAGES[lang.value] || _ErrorManager.DEFAULT_MESSAGES[lang.base()] || "error";
650
+ }
651
+ onFatal(err, lang) {
652
+ this.logger?.fatal(err.type, err.message);
653
+ return { status: "ERROR", message: this.getDefaultMessage(lang) };
654
+ }
655
+ onInternal(err, lang) {
656
+ this.logger?.error(err.type, err.message);
657
+ return { status: "ERROR", message: this.getDefaultMessage(lang) };
658
+ }
659
+ onUsage(err, lang) {
660
+ const tmpl = _ErrorManager.TEMPLATES.get(err.type);
661
+ if (!tmpl) {
662
+ this.logger?.error("TEMPLATE_NOT_FOUND", `${err.type}`);
663
+ return { status: "ERROR", message: this.getDefaultMessage(lang) };
664
+ }
665
+ const code = lang.value;
666
+ const base = lang.base();
667
+ const rawMsg = tmpl.languages[code] ?? tmpl.languages[base] ?? this.getDefaultMessage(lang);
668
+ return {
669
+ status: 400,
670
+ message: StringVars.parse(rawMsg, err.vars)
671
+ };
672
+ }
673
+ onUnknown(err, lang) {
674
+ this.logger?.error("UNKNOWN_ERROR", err.message);
675
+ return { status: "ERROR", message: this.getDefaultMessage(lang) };
676
+ }
677
+ handle(err, lang) {
678
+ if (["local", "dev"].includes(process.env.ENVIRONMENT ?? "")) {
679
+ console.log(err);
680
+ }
681
+ if (err instanceof FatalError) {
682
+ return this.onFatal(err, lang);
683
+ }
684
+ if (err instanceof InternalError) {
685
+ return this.onInternal(err, lang);
686
+ }
687
+ if (err instanceof UsageError) {
688
+ return this.onUsage(err, lang);
689
+ }
690
+ return this.onUnknown(err, lang);
691
+ }
692
+ static addTemplate(template) {
693
+ _ErrorManager.TEMPLATES.set(template.type, template);
694
+ }
695
+ };
696
+ _ErrorManager.DEFAULT_MESSAGES = {
697
+ "es": "Ups, hemos encontrado un error. Nuestro equipo ya est\xE1 trabajando para solucionarlo",
698
+ "en": "Ups, we found an error. Our team is working on it.",
699
+ "pt": "Ops, encontramos um bug. Nossa equipe j\xE1 est\xE1 trabalhando para resolver isso."
700
+ };
701
+ _ErrorManager.APP_ERRORS = {
702
+ UNDEFINED: "UNDEFINED_ERROR",
703
+ PROCESS: "PROCESS_ERROR",
704
+ DATABASE: "DATABASE_ERROR"
705
+ };
706
+ _ErrorManager.TEMPLATES = /* @__PURE__ */ new Map();
707
+ var ErrorManager = _ErrorManager;
708
+
920
709
  // src/domain/value-objects/Price.ts
921
710
  ErrorManager.addTemplate({
922
711
  type: "INVALID_PRICE_AMOUNT",
@@ -1445,6 +1234,7 @@ var EventBusMysqlRepository = class {
1445
1234
  }
1446
1235
  async update(event) {
1447
1236
  const values = [event.status.value, event.attempts, event.errorMessage, event.publishedAt?.value, event.lastAttempt?.value, event.eventUuid.value];
1237
+ console.log(values);
1448
1238
  await this.connection.query(
1449
1239
  `UPDATE events_outbox
1450
1240
  SET status = ?,
@@ -1540,6 +1330,21 @@ var KafkaManager = class extends EventManager {
1540
1330
  await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
1541
1331
  }
1542
1332
  }
1333
+ async sendRaw(message, topic) {
1334
+ try {
1335
+ if (!this.producer) {
1336
+ throw new InternalError(ErrorManager.APP_ERRORS.PROCESS, "Producer not initialized");
1337
+ }
1338
+ await this.producer.connect();
1339
+ await this.producer.send({
1340
+ topic,
1341
+ messages: [{ value: message }]
1342
+ });
1343
+ await this.producer.disconnect();
1344
+ } catch (error) {
1345
+ await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
1346
+ }
1347
+ }
1543
1348
  async start(autocommit = false) {
1544
1349
  this.consumer.on(this.consumer.events.CRASH, async (error) => {
1545
1350
  await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.payload.error.stack));
@@ -1613,7 +1418,6 @@ var ExchangeRates = class _ExchangeRates extends BaseObject {
1613
1418
  BaseObject,
1614
1419
  BasicUnitOfWork,
1615
1420
  BasicUnitOfWorkFactory,
1616
- Country,
1617
1421
  Currency,
1618
1422
  DateTime,
1619
1423
  DomainEntity,