wsp-ms-core 1.0.70 → 1.0.71
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 +95 -293
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -48
- package/dist/index.d.ts +2 -48
- package/dist/index.js +95 -292
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,
|
|
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
|
@@ -437,297 +437,6 @@ _Currency.ARS = new _Currency("ARS");
|
|
|
437
437
|
_Currency.BRL = new _Currency("BRL");
|
|
438
438
|
var Currency = _Currency;
|
|
439
439
|
|
|
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
440
|
// src/domain/value-objects/Email.ts
|
|
732
441
|
var _Email = class _Email extends ValueObject {
|
|
733
442
|
constructor(email) {
|
|
@@ -851,6 +560,86 @@ _Language.SPANISH_NICARAGUA = new _Language("es-ni");
|
|
|
851
560
|
_Language.SPANISH_PUERTO_RICO = new _Language("es-pr");
|
|
852
561
|
var Language = _Language;
|
|
853
562
|
|
|
563
|
+
// src/utils/StringVars.ts
|
|
564
|
+
var StringVars = class {
|
|
565
|
+
static parse(str, ob) {
|
|
566
|
+
const regex = /{{(.*?)}}/g;
|
|
567
|
+
return str.replace(regex, (match, variable) => {
|
|
568
|
+
if (ob.hasOwnProperty(variable.trim())) {
|
|
569
|
+
return ob[variable.trim()];
|
|
570
|
+
} else {
|
|
571
|
+
return match;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
// src/infrastructure/errors/ErrorManager.ts
|
|
578
|
+
var _ErrorManager = class _ErrorManager {
|
|
579
|
+
constructor(logger = null) {
|
|
580
|
+
this.logger = logger;
|
|
581
|
+
}
|
|
582
|
+
getDefaultMessage(lang) {
|
|
583
|
+
return _ErrorManager.DEFAULT_MESSAGES[lang.value] || _ErrorManager.DEFAULT_MESSAGES[lang.base()] || "error";
|
|
584
|
+
}
|
|
585
|
+
onFatal(err, lang) {
|
|
586
|
+
this.logger?.fatal(err.type, err.message);
|
|
587
|
+
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
588
|
+
}
|
|
589
|
+
onInternal(err, lang) {
|
|
590
|
+
this.logger?.error(err.type, err.message);
|
|
591
|
+
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
592
|
+
}
|
|
593
|
+
onUsage(err, lang) {
|
|
594
|
+
const tmpl = _ErrorManager.TEMPLATES.get(err.type);
|
|
595
|
+
if (!tmpl) {
|
|
596
|
+
this.logger?.error("TEMPLATE_NOT_FOUND", `${err.type}`);
|
|
597
|
+
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
598
|
+
}
|
|
599
|
+
const code = lang.value;
|
|
600
|
+
const base = lang.base();
|
|
601
|
+
const rawMsg = tmpl.languages[code] ?? tmpl.languages[base] ?? this.getDefaultMessage(lang);
|
|
602
|
+
return {
|
|
603
|
+
status: 400,
|
|
604
|
+
message: StringVars.parse(rawMsg, err.vars)
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
onUnknown(err, lang) {
|
|
608
|
+
this.logger?.error("UNKNOWN_ERROR", err.message);
|
|
609
|
+
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
610
|
+
}
|
|
611
|
+
handle(err, lang) {
|
|
612
|
+
if (["local", "dev"].includes(process.env.ENVIRONMENT ?? "")) {
|
|
613
|
+
console.log(err);
|
|
614
|
+
}
|
|
615
|
+
if (err instanceof FatalError) {
|
|
616
|
+
return this.onFatal(err, lang);
|
|
617
|
+
}
|
|
618
|
+
if (err instanceof InternalError) {
|
|
619
|
+
return this.onInternal(err, lang);
|
|
620
|
+
}
|
|
621
|
+
if (err instanceof UsageError) {
|
|
622
|
+
return this.onUsage(err, lang);
|
|
623
|
+
}
|
|
624
|
+
return this.onUnknown(err, lang);
|
|
625
|
+
}
|
|
626
|
+
static addTemplate(template) {
|
|
627
|
+
_ErrorManager.TEMPLATES.set(template.type, template);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
_ErrorManager.DEFAULT_MESSAGES = {
|
|
631
|
+
"es": "Ups, hemos encontrado un error. Nuestro equipo ya est\xE1 trabajando para solucionarlo",
|
|
632
|
+
"en": "Ups, we found an error. Our team is working on it.",
|
|
633
|
+
"pt": "Ops, encontramos um bug. Nossa equipe j\xE1 est\xE1 trabalhando para resolver isso."
|
|
634
|
+
};
|
|
635
|
+
_ErrorManager.APP_ERRORS = {
|
|
636
|
+
UNDEFINED: "UNDEFINED_ERROR",
|
|
637
|
+
PROCESS: "PROCESS_ERROR",
|
|
638
|
+
DATABASE: "DATABASE_ERROR"
|
|
639
|
+
};
|
|
640
|
+
_ErrorManager.TEMPLATES = /* @__PURE__ */ new Map();
|
|
641
|
+
var ErrorManager = _ErrorManager;
|
|
642
|
+
|
|
854
643
|
// src/domain/value-objects/Price.ts
|
|
855
644
|
ErrorManager.addTemplate({
|
|
856
645
|
type: "INVALID_PRICE_AMOUNT",
|
|
@@ -1474,6 +1263,21 @@ var KafkaManager = class extends EventManager {
|
|
|
1474
1263
|
await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
|
|
1475
1264
|
}
|
|
1476
1265
|
}
|
|
1266
|
+
async sendRaw(message, topic) {
|
|
1267
|
+
try {
|
|
1268
|
+
if (!this.producer) {
|
|
1269
|
+
throw new InternalError(ErrorManager.APP_ERRORS.PROCESS, "Producer not initialized");
|
|
1270
|
+
}
|
|
1271
|
+
await this.producer.connect();
|
|
1272
|
+
await this.producer.send({
|
|
1273
|
+
topic,
|
|
1274
|
+
messages: [{ value: message }]
|
|
1275
|
+
});
|
|
1276
|
+
await this.producer.disconnect();
|
|
1277
|
+
} catch (error) {
|
|
1278
|
+
await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.toString()));
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1477
1281
|
async start(autocommit = false) {
|
|
1478
1282
|
this.consumer.on(this.consumer.events.CRASH, async (error) => {
|
|
1479
1283
|
await this.execCallback(this._onError, new InternalError(ErrorManager.APP_ERRORS.PROCESS, error.payload.error.stack));
|
|
@@ -1546,7 +1350,6 @@ export {
|
|
|
1546
1350
|
BaseObject,
|
|
1547
1351
|
BasicUnitOfWork,
|
|
1548
1352
|
BasicUnitOfWorkFactory,
|
|
1549
|
-
Country,
|
|
1550
1353
|
Currency,
|
|
1551
1354
|
DateTime,
|
|
1552
1355
|
DomainEntity,
|