wsp-ms-core 1.0.75 → 1.0.77
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 +330 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +55 -1
- package/dist/index.d.ts +55 -1
- package/dist/index.js +329 -81
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ declare class UUID extends ValueObject<string> {
|
|
|
33
33
|
|
|
34
34
|
declare class DateTime extends ValueObject<string> {
|
|
35
35
|
static readonly DEFAULT_FORMAT: string;
|
|
36
|
+
static readonly FORMAT: string;
|
|
37
|
+
static readonly FORMAT_Y_M = "Y-M";
|
|
38
|
+
static readonly FORMAT_Y_M_D = "Y-M-D";
|
|
39
|
+
static readonly FORMAT_Y_M_D_H_m_s = "Y-M-D H:M:S";
|
|
40
|
+
static readonly FORMAT_D_M_Y = "D-M-Y";
|
|
41
|
+
private static readonly FORMATS;
|
|
36
42
|
private readonly _dt;
|
|
37
43
|
private static fromLuxon;
|
|
38
44
|
private static toUtcFormat;
|
|
@@ -58,6 +64,7 @@ declare class DateTime extends ValueObject<string> {
|
|
|
58
64
|
get second(): number;
|
|
59
65
|
getMonthName(locale?: string): string;
|
|
60
66
|
getWeekdayName(locale?: string): string;
|
|
67
|
+
format(format: string): string;
|
|
61
68
|
toPrimitives(): Record<string, unknown>;
|
|
62
69
|
static create(input?: string | number): DateTime;
|
|
63
70
|
static now(): DateTime;
|
|
@@ -178,6 +185,53 @@ declare class Currency extends ValueObject<string> {
|
|
|
178
185
|
static isValid(raw: string | number): boolean;
|
|
179
186
|
}
|
|
180
187
|
|
|
188
|
+
declare class Country extends ValueObject<string> {
|
|
189
|
+
static COUNTRIES: {
|
|
190
|
+
[key: string]: {
|
|
191
|
+
alpha2: string;
|
|
192
|
+
alpha3: string;
|
|
193
|
+
numeric: string;
|
|
194
|
+
uuid: string;
|
|
195
|
+
phoneCode: string;
|
|
196
|
+
url: string;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
private static readonly NAMES;
|
|
200
|
+
static readonly DEFAULT: Country;
|
|
201
|
+
static readonly ARGENTINA: Country;
|
|
202
|
+
static readonly ECUADOR: Country;
|
|
203
|
+
static readonly PERU: Country;
|
|
204
|
+
static readonly BRASIL: Country;
|
|
205
|
+
static readonly CHILE: Country;
|
|
206
|
+
static readonly VENEZUELA: Country;
|
|
207
|
+
static readonly COLOMBIA: Country;
|
|
208
|
+
static readonly BOLIVIA: Country;
|
|
209
|
+
static readonly PARAGUAY: Country;
|
|
210
|
+
static readonly USA: Country;
|
|
211
|
+
private readonly _name;
|
|
212
|
+
private readonly _alpha2;
|
|
213
|
+
private readonly _alpha3;
|
|
214
|
+
private readonly _numeric;
|
|
215
|
+
private readonly _uuid;
|
|
216
|
+
private readonly _phoneCode;
|
|
217
|
+
private readonly _url;
|
|
218
|
+
private constructor();
|
|
219
|
+
protected validate(country: string): void;
|
|
220
|
+
name(): string;
|
|
221
|
+
alpha2(): string;
|
|
222
|
+
alpha3(): string;
|
|
223
|
+
numeric(): string;
|
|
224
|
+
uuid(): string;
|
|
225
|
+
phoneCode(): string;
|
|
226
|
+
url(): string;
|
|
227
|
+
static findCountryByAlpha2(alpha2: string): Country;
|
|
228
|
+
static findCountryByUUID(uuid: string): Country;
|
|
229
|
+
static create(country: string): Country;
|
|
230
|
+
static createOrDefault(country: string): Country;
|
|
231
|
+
toPrimitives(): Record<string, unknown>;
|
|
232
|
+
static isValid(country: string): boolean;
|
|
233
|
+
}
|
|
234
|
+
|
|
181
235
|
declare class Email extends ValueObject<string> {
|
|
182
236
|
static readonly REGEX: RegExp;
|
|
183
237
|
private constructor();
|
|
@@ -520,4 +574,4 @@ declare class ExchangeRates extends BaseObject<ExchangeRatesProps> {
|
|
|
520
574
|
static createFromPrimitives(data: any): ExchangeRates;
|
|
521
575
|
}
|
|
522
576
|
|
|
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 };
|
|
577
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -103,6 +103,13 @@ var _DateTime = class _DateTime extends ValueObject {
|
|
|
103
103
|
getWeekdayName(locale = "en") {
|
|
104
104
|
return this._dt.setLocale(locale).toFormat("cccc");
|
|
105
105
|
}
|
|
106
|
+
format(format) {
|
|
107
|
+
if (!_DateTime.FORMATS.hasOwnProperty(format)) {
|
|
108
|
+
throw new Error(`Invalid format: ${format}`);
|
|
109
|
+
}
|
|
110
|
+
const formatString = _DateTime.FORMATS[format];
|
|
111
|
+
return this._dt.toFormat(formatString);
|
|
112
|
+
}
|
|
106
113
|
toPrimitives() {
|
|
107
114
|
return {
|
|
108
115
|
value: this.value
|
|
@@ -128,6 +135,35 @@ var _DateTime = class _DateTime extends ValueObject {
|
|
|
128
135
|
}
|
|
129
136
|
};
|
|
130
137
|
_DateTime.DEFAULT_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
|
138
|
+
_DateTime.FORMAT = "Y-M-D H:M:S";
|
|
139
|
+
_DateTime.FORMAT_Y_M = "Y-M";
|
|
140
|
+
_DateTime.FORMAT_Y_M_D = "Y-M-D";
|
|
141
|
+
_DateTime.FORMAT_Y_M_D_H_m_s = "Y-M-D H:M:S";
|
|
142
|
+
_DateTime.FORMAT_D_M_Y = "D-M-Y";
|
|
143
|
+
_DateTime.FORMATS = {
|
|
144
|
+
"Y-M": "yyyy-MM",
|
|
145
|
+
"Y-M-D": "yyyy-MM-dd",
|
|
146
|
+
"D/M/Y": "dd/MM/yyyy",
|
|
147
|
+
"Y/M/D": "yyyy/MM/dd",
|
|
148
|
+
"D-M-Y": "dd-MM-yyyy",
|
|
149
|
+
"Y.M.D": "yyyy.MM.dd",
|
|
150
|
+
"D.M.Y": "dd.MM.yyyy",
|
|
151
|
+
"Y-M-D H:M": "yyyy-MM-dd HH:mm",
|
|
152
|
+
"D/M/Y H:M": "dd/MM/yyyy HH:mm",
|
|
153
|
+
"Y/M/D H:M": "yyyy/MM/dd HH:mm",
|
|
154
|
+
"D-M-Y H:M": "dd-MM-yyyy HH:mm",
|
|
155
|
+
"Y.M.D H:M": "yyyy.MM.dd HH:mm",
|
|
156
|
+
"D.M.Y H:M": "dd.MM.yyyy HH:mm",
|
|
157
|
+
"Y-M-D H:M:S": "yyyy-MM-dd HH:mm:ss",
|
|
158
|
+
"Y-M-D H:M:S:SSS": "yyyy-MM-dd HH:mm:ss.SSS",
|
|
159
|
+
"D/M/Y H:M:S": "dd/MM/yyyy HH:mm:ss",
|
|
160
|
+
"Y/M/D H:M:S": "yyyy/MM/dd HH:mm:ss",
|
|
161
|
+
"D-M-Y H:M:S": "dd-MM-yyyy HH:mm:ss",
|
|
162
|
+
"Y.M.D H:M:S": "yyyy.MM.dd HH:mm:ss",
|
|
163
|
+
"D.M.Y H:M:S": "dd.MM.yyyy HH:mm:ss",
|
|
164
|
+
"H:M": "HH:mm",
|
|
165
|
+
"H:M:S": "HH:mm:ss"
|
|
166
|
+
};
|
|
131
167
|
var DateTime = _DateTime;
|
|
132
168
|
|
|
133
169
|
// src/domain/contracts/DomainEntity.ts
|
|
@@ -256,7 +292,7 @@ var DomainEvent = class _DomainEvent {
|
|
|
256
292
|
this._topic = topic;
|
|
257
293
|
this._payload = payload;
|
|
258
294
|
this._status = status;
|
|
259
|
-
this._attempts =
|
|
295
|
+
this._attempts = attempts;
|
|
260
296
|
this._errorMessage = errorMessage;
|
|
261
297
|
this._publishedAt = publishedAt;
|
|
262
298
|
this._lastAttempt = lastAttempt;
|
|
@@ -438,6 +474,297 @@ _Currency.ARS = new _Currency("ARS");
|
|
|
438
474
|
_Currency.BRL = new _Currency("BRL");
|
|
439
475
|
var Currency = _Currency;
|
|
440
476
|
|
|
477
|
+
// src/utils/StringVars.ts
|
|
478
|
+
var StringVars = class {
|
|
479
|
+
static parse(str, ob) {
|
|
480
|
+
const regex = /{{(.*?)}}/g;
|
|
481
|
+
return str.replace(regex, (match, variable) => {
|
|
482
|
+
if (ob.hasOwnProperty(variable.trim())) {
|
|
483
|
+
return ob[variable.trim()];
|
|
484
|
+
} else {
|
|
485
|
+
return match;
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// src/infrastructure/errors/ErrorManager.ts
|
|
492
|
+
var _ErrorManager = class _ErrorManager {
|
|
493
|
+
constructor(logger = null) {
|
|
494
|
+
this.logger = logger;
|
|
495
|
+
}
|
|
496
|
+
getDefaultMessage(lang) {
|
|
497
|
+
return _ErrorManager.DEFAULT_MESSAGES[lang.value] || _ErrorManager.DEFAULT_MESSAGES[lang.base()] || "error";
|
|
498
|
+
}
|
|
499
|
+
onFatal(err, lang) {
|
|
500
|
+
this.logger?.fatal(err.type, err.message);
|
|
501
|
+
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
502
|
+
}
|
|
503
|
+
onInternal(err, lang) {
|
|
504
|
+
this.logger?.error(err.type, err.message);
|
|
505
|
+
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
506
|
+
}
|
|
507
|
+
onUsage(err, lang) {
|
|
508
|
+
const tmpl = _ErrorManager.TEMPLATES.get(err.type);
|
|
509
|
+
if (!tmpl) {
|
|
510
|
+
this.logger?.error("TEMPLATE_NOT_FOUND", `${err.type}`);
|
|
511
|
+
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
512
|
+
}
|
|
513
|
+
const code = lang.value;
|
|
514
|
+
const base = lang.base();
|
|
515
|
+
const rawMsg = tmpl.languages[code] ?? tmpl.languages[base] ?? this.getDefaultMessage(lang);
|
|
516
|
+
return {
|
|
517
|
+
status: 400,
|
|
518
|
+
message: StringVars.parse(rawMsg, err.vars)
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
onUnknown(err, lang) {
|
|
522
|
+
this.logger?.error("UNKNOWN_ERROR", err.message);
|
|
523
|
+
return { status: "ERROR", message: this.getDefaultMessage(lang) };
|
|
524
|
+
}
|
|
525
|
+
handle(err, lang) {
|
|
526
|
+
if (["local", "dev"].includes(process.env.ENVIRONMENT ?? "")) {
|
|
527
|
+
console.log(err);
|
|
528
|
+
}
|
|
529
|
+
if (err instanceof FatalError) {
|
|
530
|
+
return this.onFatal(err, lang);
|
|
531
|
+
}
|
|
532
|
+
if (err instanceof InternalError) {
|
|
533
|
+
return this.onInternal(err, lang);
|
|
534
|
+
}
|
|
535
|
+
if (err instanceof UsageError) {
|
|
536
|
+
return this.onUsage(err, lang);
|
|
537
|
+
}
|
|
538
|
+
return this.onUnknown(err, lang);
|
|
539
|
+
}
|
|
540
|
+
static addTemplate(template) {
|
|
541
|
+
_ErrorManager.TEMPLATES.set(template.type, template);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
_ErrorManager.DEFAULT_MESSAGES = {
|
|
545
|
+
"es": "Ups, hemos encontrado un error. Nuestro equipo ya est\xE1 trabajando para solucionarlo",
|
|
546
|
+
"en": "Ups, we found an error. Our team is working on it.",
|
|
547
|
+
"pt": "Ops, encontramos um bug. Nossa equipe j\xE1 est\xE1 trabalhando para resolver isso."
|
|
548
|
+
};
|
|
549
|
+
_ErrorManager.APP_ERRORS = {
|
|
550
|
+
UNDEFINED: "UNDEFINED_ERROR",
|
|
551
|
+
PROCESS: "PROCESS_ERROR",
|
|
552
|
+
DATABASE: "DATABASE_ERROR"
|
|
553
|
+
};
|
|
554
|
+
_ErrorManager.TEMPLATES = /* @__PURE__ */ new Map();
|
|
555
|
+
var ErrorManager = _ErrorManager;
|
|
556
|
+
|
|
557
|
+
// src/domain/value-objects/Country.ts
|
|
558
|
+
ErrorManager.addTemplate({
|
|
559
|
+
type: "INVALID_COUNTRY",
|
|
560
|
+
languages: {
|
|
561
|
+
"es": "El pa\xEDs <{{country}}> no es v\xE1lido o no est\xE1 soportado",
|
|
562
|
+
"en": "Country <{{country}}> is not valid or not supported"
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
ErrorManager.addTemplate({
|
|
566
|
+
type: "COUNTRY_NOT_FOUND_BY_ALPHA2",
|
|
567
|
+
languages: {
|
|
568
|
+
"es": "No se encontr\xF3 pa\xEDs con c\xF3digo alpha2 <{{alpha2}}>",
|
|
569
|
+
"en": "Country not found with alpha2 code <{{alpha2}}>"
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
ErrorManager.addTemplate({
|
|
573
|
+
type: "COUNTRY_NOT_FOUND_BY_UUID",
|
|
574
|
+
languages: {
|
|
575
|
+
"es": "No se encontr\xF3 pa\xEDs con UUID <{{uuid}}>",
|
|
576
|
+
"en": "Country not found with UUID <{{uuid}}>"
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
var _Country = class _Country extends ValueObject {
|
|
580
|
+
constructor(country) {
|
|
581
|
+
const normalizedCountry = country.toUpperCase().trim();
|
|
582
|
+
super(normalizedCountry);
|
|
583
|
+
this._name = normalizedCountry;
|
|
584
|
+
this._alpha2 = _Country.COUNTRIES[normalizedCountry].alpha2;
|
|
585
|
+
this._alpha3 = _Country.COUNTRIES[normalizedCountry].alpha3;
|
|
586
|
+
this._numeric = _Country.COUNTRIES[normalizedCountry].numeric;
|
|
587
|
+
this._uuid = _Country.COUNTRIES[normalizedCountry].uuid;
|
|
588
|
+
this._phoneCode = _Country.COUNTRIES[normalizedCountry].phoneCode;
|
|
589
|
+
this._url = _Country.COUNTRIES[normalizedCountry].url;
|
|
590
|
+
}
|
|
591
|
+
validate(country) {
|
|
592
|
+
if (!_Country.NAMES.includes(country)) {
|
|
593
|
+
throw new UsageError("INVALID_COUNTRY", { country });
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
name() {
|
|
597
|
+
return this._name;
|
|
598
|
+
}
|
|
599
|
+
alpha2() {
|
|
600
|
+
return this._alpha2;
|
|
601
|
+
}
|
|
602
|
+
alpha3() {
|
|
603
|
+
return this._alpha3;
|
|
604
|
+
}
|
|
605
|
+
numeric() {
|
|
606
|
+
return this._numeric;
|
|
607
|
+
}
|
|
608
|
+
uuid() {
|
|
609
|
+
return this._uuid;
|
|
610
|
+
}
|
|
611
|
+
phoneCode() {
|
|
612
|
+
return this._phoneCode;
|
|
613
|
+
}
|
|
614
|
+
url() {
|
|
615
|
+
return this._url;
|
|
616
|
+
}
|
|
617
|
+
static findCountryByAlpha2(alpha2) {
|
|
618
|
+
for (const [country, codes] of Object.entries(_Country.COUNTRIES)) {
|
|
619
|
+
if (codes.alpha2 === alpha2.toUpperCase()) {
|
|
620
|
+
return new _Country(country);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
throw new UsageError("COUNTRY_NOT_FOUND_BY_ALPHA2", { alpha2 });
|
|
624
|
+
}
|
|
625
|
+
static findCountryByUUID(uuid) {
|
|
626
|
+
for (const [country, codes] of Object.entries(_Country.COUNTRIES)) {
|
|
627
|
+
if (codes.uuid === uuid) {
|
|
628
|
+
return new _Country(country);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
throw new UsageError("COUNTRY_NOT_FOUND_BY_UUID", { uuid });
|
|
632
|
+
}
|
|
633
|
+
static create(country) {
|
|
634
|
+
return new _Country(country);
|
|
635
|
+
}
|
|
636
|
+
static createOrDefault(country) {
|
|
637
|
+
try {
|
|
638
|
+
return new _Country(country);
|
|
639
|
+
} catch (error) {
|
|
640
|
+
return _Country.DEFAULT;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
toPrimitives() {
|
|
644
|
+
return {
|
|
645
|
+
value: this.value,
|
|
646
|
+
name: this._name,
|
|
647
|
+
alpha2: this._alpha2,
|
|
648
|
+
alpha3: this._alpha3,
|
|
649
|
+
numeric: this._numeric,
|
|
650
|
+
uuid: this._uuid,
|
|
651
|
+
phoneCode: this._phoneCode,
|
|
652
|
+
url: this._url
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
static isValid(country) {
|
|
656
|
+
try {
|
|
657
|
+
_Country.create(country);
|
|
658
|
+
return true;
|
|
659
|
+
} catch {
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
_Country.COUNTRIES = {
|
|
665
|
+
URUGUAY: {
|
|
666
|
+
alpha2: "UY",
|
|
667
|
+
alpha3: "URY",
|
|
668
|
+
numeric: "858",
|
|
669
|
+
phoneCode: "+598",
|
|
670
|
+
uuid: "5739ecc0-d12b-4db5-8897-e03a04a95c72",
|
|
671
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/uruguay.png"
|
|
672
|
+
},
|
|
673
|
+
ARGENTINA: {
|
|
674
|
+
alpha2: "AR",
|
|
675
|
+
alpha3: "ARG",
|
|
676
|
+
numeric: "032",
|
|
677
|
+
phoneCode: "+54",
|
|
678
|
+
uuid: "66663efe-ab7a-4166-b971-9f36fd0ea6b2",
|
|
679
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/argentina.png"
|
|
680
|
+
},
|
|
681
|
+
ECUADOR: {
|
|
682
|
+
alpha2: "EC",
|
|
683
|
+
alpha3: "ECU",
|
|
684
|
+
numeric: "218",
|
|
685
|
+
phoneCode: "+593",
|
|
686
|
+
uuid: "ee109239-0150-4e5f-9ff2-a85f270092b1",
|
|
687
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/ecuador.png"
|
|
688
|
+
},
|
|
689
|
+
PERU: {
|
|
690
|
+
alpha2: "PE",
|
|
691
|
+
alpha3: "PER",
|
|
692
|
+
numeric: "604",
|
|
693
|
+
phoneCode: "+51",
|
|
694
|
+
uuid: "e4d61ef5-b92d-4f9c-8ec1-23f4beb50abd",
|
|
695
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/peru.png"
|
|
696
|
+
},
|
|
697
|
+
BRASIL: {
|
|
698
|
+
alpha2: "BR",
|
|
699
|
+
alpha3: "BRA",
|
|
700
|
+
numeric: "076",
|
|
701
|
+
phoneCode: "+55",
|
|
702
|
+
uuid: "b7b91d72-deaf-4641-957c-a65003e33104",
|
|
703
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/brasil.png"
|
|
704
|
+
},
|
|
705
|
+
CHILE: {
|
|
706
|
+
alpha2: "CL",
|
|
707
|
+
alpha3: "CHL",
|
|
708
|
+
numeric: "152",
|
|
709
|
+
phoneCode: "+56",
|
|
710
|
+
uuid: "f69b35f4-d734-4c76-866c-29a18bf000fb",
|
|
711
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/chile.png"
|
|
712
|
+
},
|
|
713
|
+
VENEZUELA: {
|
|
714
|
+
alpha2: "VE",
|
|
715
|
+
alpha3: "VEN",
|
|
716
|
+
numeric: "862",
|
|
717
|
+
phoneCode: "+58",
|
|
718
|
+
uuid: "31b6c591-63f6-43db-8ea9-829bb03746c5",
|
|
719
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/venezuela.png"
|
|
720
|
+
},
|
|
721
|
+
COLOMBIA: {
|
|
722
|
+
alpha2: "CO",
|
|
723
|
+
alpha3: "COL",
|
|
724
|
+
numeric: "170",
|
|
725
|
+
phoneCode: "+57",
|
|
726
|
+
uuid: "6fdfe34b-6726-4604-96af-665ea5fc9239",
|
|
727
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/colombia.png"
|
|
728
|
+
},
|
|
729
|
+
BOLIVIA: {
|
|
730
|
+
alpha2: "BO",
|
|
731
|
+
alpha3: "BOL",
|
|
732
|
+
numeric: "068",
|
|
733
|
+
phoneCode: "+591",
|
|
734
|
+
uuid: "948886db-c280-4ba7-a777-a76c180b295b",
|
|
735
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/bolivia.png"
|
|
736
|
+
},
|
|
737
|
+
PARAGUAY: {
|
|
738
|
+
alpha2: "PY",
|
|
739
|
+
alpha3: "PRY",
|
|
740
|
+
numeric: "600",
|
|
741
|
+
phoneCode: "+595",
|
|
742
|
+
uuid: "d67b3472-e38d-4900-8ae3-02d99cd1d884",
|
|
743
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/paraguay.png"
|
|
744
|
+
},
|
|
745
|
+
USA: {
|
|
746
|
+
alpha2: "US",
|
|
747
|
+
alpha3: "USA",
|
|
748
|
+
numeric: "840",
|
|
749
|
+
phoneCode: "+1",
|
|
750
|
+
uuid: "16ac3b9b-8f7b-4c54-91d5-d62c7cd74ad4",
|
|
751
|
+
url: "https://dev-wonasports.s3.us-east-2.amazonaws.com/assets/usa.png"
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
_Country.NAMES = Object.keys(_Country.COUNTRIES);
|
|
755
|
+
_Country.DEFAULT = new _Country("URUGUAY");
|
|
756
|
+
_Country.ARGENTINA = new _Country("ARGENTINA");
|
|
757
|
+
_Country.ECUADOR = new _Country("ECUADOR");
|
|
758
|
+
_Country.PERU = new _Country("PERU");
|
|
759
|
+
_Country.BRASIL = new _Country("BRASIL");
|
|
760
|
+
_Country.CHILE = new _Country("CHILE");
|
|
761
|
+
_Country.VENEZUELA = new _Country("VENEZUELA");
|
|
762
|
+
_Country.COLOMBIA = new _Country("COLOMBIA");
|
|
763
|
+
_Country.BOLIVIA = new _Country("BOLIVIA");
|
|
764
|
+
_Country.PARAGUAY = new _Country("PARAGUAY");
|
|
765
|
+
_Country.USA = new _Country("USA");
|
|
766
|
+
var Country = _Country;
|
|
767
|
+
|
|
441
768
|
// src/domain/value-objects/Email.ts
|
|
442
769
|
var _Email = class _Email extends ValueObject {
|
|
443
770
|
constructor(email) {
|
|
@@ -561,86 +888,6 @@ _Language.SPANISH_NICARAGUA = new _Language("es-ni");
|
|
|
561
888
|
_Language.SPANISH_PUERTO_RICO = new _Language("es-pr");
|
|
562
889
|
var Language = _Language;
|
|
563
890
|
|
|
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
|
-
|
|
644
891
|
// src/domain/value-objects/Price.ts
|
|
645
892
|
ErrorManager.addTemplate({
|
|
646
893
|
type: "INVALID_PRICE_AMOUNT",
|
|
@@ -1351,6 +1598,7 @@ export {
|
|
|
1351
1598
|
BaseObject,
|
|
1352
1599
|
BasicUnitOfWork,
|
|
1353
1600
|
BasicUnitOfWorkFactory,
|
|
1601
|
+
Country,
|
|
1354
1602
|
Currency,
|
|
1355
1603
|
DateTime,
|
|
1356
1604
|
DomainEntity,
|