wsp-ms-core 1.0.69 → 1.0.70
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 +293 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +48 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.js +292 -80
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ __export(src_exports, {
|
|
|
32
32
|
BaseObject: () => BaseObject,
|
|
33
33
|
BasicUnitOfWork: () => BasicUnitOfWork,
|
|
34
34
|
BasicUnitOfWorkFactory: () => BasicUnitOfWorkFactory,
|
|
35
|
+
Country: () => Country,
|
|
35
36
|
Currency: () => Currency,
|
|
36
37
|
DateTime: () => DateTime,
|
|
37
38
|
DomainEntity: () => DomainEntity,
|
|
@@ -502,6 +503,297 @@ _Currency.ARS = new _Currency("ARS");
|
|
|
502
503
|
_Currency.BRL = new _Currency("BRL");
|
|
503
504
|
var Currency = _Currency;
|
|
504
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
|
+
|
|
505
797
|
// src/domain/value-objects/Email.ts
|
|
506
798
|
var _Email = class _Email extends ValueObject {
|
|
507
799
|
constructor(email) {
|
|
@@ -625,86 +917,6 @@ _Language.SPANISH_NICARAGUA = new _Language("es-ni");
|
|
|
625
917
|
_Language.SPANISH_PUERTO_RICO = new _Language("es-pr");
|
|
626
918
|
var Language = _Language;
|
|
627
919
|
|
|
628
|
-
// src/utils/StringVars.ts
|
|
629
|
-
var StringVars = class {
|
|
630
|
-
static parse(str, ob) {
|
|
631
|
-
const regex = /{{(.*?)}}/g;
|
|
632
|
-
return str.replace(regex, (match, variable) => {
|
|
633
|
-
if (ob.hasOwnProperty(variable.trim())) {
|
|
634
|
-
return ob[variable.trim()];
|
|
635
|
-
} else {
|
|
636
|
-
return match;
|
|
637
|
-
}
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
// src/infrastructure/errors/ErrorManager.ts
|
|
643
|
-
var _ErrorManager = class _ErrorManager {
|
|
644
|
-
constructor(logger = null) {
|
|
645
|
-
this.logger = logger;
|
|
646
|
-
}
|
|
647
|
-
getDefaultMessage(lang) {
|
|
648
|
-
return _ErrorManager.DEFAULT_MESSAGES[lang.value] || _ErrorManager.DEFAULT_MESSAGES[lang.base()] || "error";
|
|
649
|
-
}
|
|
650
|
-
onFatal(err, lang) {
|
|
651
|
-
this.logger?.fatal(err.type, err.message);
|
|
652
|
-
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
653
|
-
}
|
|
654
|
-
onInternal(err, lang) {
|
|
655
|
-
this.logger?.error(err.type, err.message);
|
|
656
|
-
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
657
|
-
}
|
|
658
|
-
onUsage(err, lang) {
|
|
659
|
-
const tmpl = _ErrorManager.TEMPLATES.get(err.type);
|
|
660
|
-
if (!tmpl) {
|
|
661
|
-
this.logger?.error("TEMPLATE_NOT_FOUND", `${err.type}`);
|
|
662
|
-
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
663
|
-
}
|
|
664
|
-
const code = lang.value;
|
|
665
|
-
const base = lang.base();
|
|
666
|
-
const rawMsg = tmpl.languages[code] ?? tmpl.languages[base] ?? this.getDefaultMessage(lang);
|
|
667
|
-
return {
|
|
668
|
-
status: 400,
|
|
669
|
-
message: StringVars.parse(rawMsg, err.vars)
|
|
670
|
-
};
|
|
671
|
-
}
|
|
672
|
-
onUnknown(err, lang) {
|
|
673
|
-
this.logger?.error("UNKNOWN_ERROR", err.message);
|
|
674
|
-
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
675
|
-
}
|
|
676
|
-
handle(err, lang) {
|
|
677
|
-
if (["local", "dev"].includes(process.env.ENVIRONMENT ?? "")) {
|
|
678
|
-
console.log(err);
|
|
679
|
-
}
|
|
680
|
-
if (err instanceof FatalError) {
|
|
681
|
-
return this.onFatal(err, lang);
|
|
682
|
-
}
|
|
683
|
-
if (err instanceof InternalError) {
|
|
684
|
-
return this.onInternal(err, lang);
|
|
685
|
-
}
|
|
686
|
-
if (err instanceof UsageError) {
|
|
687
|
-
return this.onUsage(err, lang);
|
|
688
|
-
}
|
|
689
|
-
return this.onUnknown(err, lang);
|
|
690
|
-
}
|
|
691
|
-
static addTemplate(template) {
|
|
692
|
-
_ErrorManager.TEMPLATES.set(template.type, template);
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
_ErrorManager.DEFAULT_MESSAGES = {
|
|
696
|
-
"es": "Ups, hemos encontrado un error. Nuestro equipo ya est\xE1 trabajando para solucionarlo",
|
|
697
|
-
"en": "Ups, we found an error. Our team is working on it.",
|
|
698
|
-
"pt": "Ops, encontramos um bug. Nossa equipe j\xE1 est\xE1 trabalhando para resolver isso."
|
|
699
|
-
};
|
|
700
|
-
_ErrorManager.APP_ERRORS = {
|
|
701
|
-
UNDEFINED: "UNDEFINED_ERROR",
|
|
702
|
-
PROCESS: "PROCESS_ERROR",
|
|
703
|
-
DATABASE: "DATABASE_ERROR"
|
|
704
|
-
};
|
|
705
|
-
_ErrorManager.TEMPLATES = /* @__PURE__ */ new Map();
|
|
706
|
-
var ErrorManager = _ErrorManager;
|
|
707
|
-
|
|
708
920
|
// src/domain/value-objects/Price.ts
|
|
709
921
|
ErrorManager.addTemplate({
|
|
710
922
|
type: "INVALID_PRICE_AMOUNT",
|
|
@@ -1401,6 +1613,7 @@ var ExchangeRates = class _ExchangeRates extends BaseObject {
|
|
|
1401
1613
|
BaseObject,
|
|
1402
1614
|
BasicUnitOfWork,
|
|
1403
1615
|
BasicUnitOfWorkFactory,
|
|
1616
|
+
Country,
|
|
1404
1617
|
Currency,
|
|
1405
1618
|
DateTime,
|
|
1406
1619
|
DomainEntity,
|