@xeno-js/core 4.1.2 → 4.1.3
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 +17 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +240 -224
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ var init_concurrency = __esm({
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
// src/infrastructure/context/request-context.ts
|
|
40
|
-
import { Guards as
|
|
40
|
+
import { Guards as Guards32 } from "@xeno-js/shared";
|
|
41
41
|
var NodeRequestContext;
|
|
42
42
|
var init_request_context = __esm({
|
|
43
43
|
"src/infrastructure/context/request-context.ts"() {
|
|
@@ -69,7 +69,7 @@ var init_request_context = __esm({
|
|
|
69
69
|
}
|
|
70
70
|
updateIdentity(identity) {
|
|
71
71
|
const store = this._storage.getStore();
|
|
72
|
-
if (
|
|
72
|
+
if (Guards32.isDefined(store) && Guards32.isDefined(store.context)) {
|
|
73
73
|
store.context = Object.freeze({
|
|
74
74
|
...store.context,
|
|
75
75
|
identity: Object.freeze(identity)
|
|
@@ -78,28 +78,28 @@ var init_request_context = __esm({
|
|
|
78
78
|
}
|
|
79
79
|
getContext() {
|
|
80
80
|
const store = this._storage.getStore();
|
|
81
|
-
if (!
|
|
81
|
+
if (!Guards32.isDefined(store)) return void 0;
|
|
82
82
|
const context = store.context;
|
|
83
83
|
return Object.freeze(context);
|
|
84
84
|
}
|
|
85
85
|
getIdentity() {
|
|
86
86
|
const store = this._storage.getStore();
|
|
87
|
-
if (!
|
|
87
|
+
if (!Guards32.isDefined(store)) return void 0;
|
|
88
88
|
return Object.freeze(store.context?.identity);
|
|
89
89
|
}
|
|
90
90
|
getScope() {
|
|
91
91
|
const store = this._storage.getStore();
|
|
92
|
-
if (!
|
|
92
|
+
if (!Guards32.isDefined(store)) return void 0;
|
|
93
93
|
return store.scope;
|
|
94
94
|
}
|
|
95
95
|
getNetworkContext() {
|
|
96
96
|
const store = this._storage.getStore();
|
|
97
|
-
if (!
|
|
97
|
+
if (!Guards32.isDefined(store)) return void 0;
|
|
98
98
|
return Object.freeze(store.context?.network);
|
|
99
99
|
}
|
|
100
100
|
getTracingContext() {
|
|
101
101
|
const store = this._storage.getStore();
|
|
102
|
-
if (!
|
|
102
|
+
if (!Guards32.isDefined(store)) return void 0;
|
|
103
103
|
return Object.freeze(store.context?.tracing);
|
|
104
104
|
}
|
|
105
105
|
};
|
|
@@ -898,7 +898,7 @@ var NoAuthGateKeeper = class {
|
|
|
898
898
|
import { LOG_LEVEL, LOG_LEVEL_NAMES } from "@xeno-js/shared";
|
|
899
899
|
|
|
900
900
|
// src/application/loggers/utils/logger-context.utils.ts
|
|
901
|
-
import { HttpHelper, StringHelper } from "@xeno-js/shared";
|
|
901
|
+
import { Guards as Guards11, HttpHelper, StringHelper } from "@xeno-js/shared";
|
|
902
902
|
var LoggerUtils = Object.freeze({
|
|
903
903
|
/**
|
|
904
904
|
* @description toSafeContext converts a RequestContext object to a LoggerContext object, ensuring that only the necessary fields are included.
|
|
@@ -925,7 +925,23 @@ var LoggerUtils = Object.freeze({
|
|
|
925
925
|
},
|
|
926
926
|
messaging: ctx?.messaging
|
|
927
927
|
};
|
|
928
|
-
return StringHelper.
|
|
928
|
+
return StringHelper.safeStringifyObject(context);
|
|
929
|
+
},
|
|
930
|
+
toNormalizeError(error) {
|
|
931
|
+
if (error instanceof Error) {
|
|
932
|
+
return {
|
|
933
|
+
message: error.message,
|
|
934
|
+
name: error.name,
|
|
935
|
+
stack: error.stack,
|
|
936
|
+
cause: error.cause
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
const errorString = Guards11.isString(error) ? error : StringHelper.safeStringify(error);
|
|
940
|
+
const customError = new Error(errorString);
|
|
941
|
+
if (Guards11.isObject(error) && Guards11.isDefined(error)) {
|
|
942
|
+
Object.assign(customError, error);
|
|
943
|
+
}
|
|
944
|
+
return customError;
|
|
929
945
|
}
|
|
930
946
|
});
|
|
931
947
|
|
|
@@ -1114,10 +1130,10 @@ var NotSpecification = class extends Specification {
|
|
|
1114
1130
|
};
|
|
1115
1131
|
|
|
1116
1132
|
// src/infrastructure/builder/app.builder.ts
|
|
1117
|
-
import { Guards as
|
|
1133
|
+
import { Guards as Guards66, LOG_LEVEL as LOG_LEVEL8, TOKENS as TOKENS17 } from "@xeno-js/shared";
|
|
1118
1134
|
|
|
1119
1135
|
// src/infrastructure/configuration/node.configuration.ts
|
|
1120
|
-
import { Guards as
|
|
1136
|
+
import { Guards as Guards12 } from "@xeno-js/shared";
|
|
1121
1137
|
var EnvironmentConfigurationService = class {
|
|
1122
1138
|
/**
|
|
1123
1139
|
* @description Internal dictionary to hold environment variables.
|
|
@@ -1139,7 +1155,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1139
1155
|
}
|
|
1140
1156
|
get(key, defaultValue) {
|
|
1141
1157
|
const value = this._env[key];
|
|
1142
|
-
if (
|
|
1158
|
+
if (Guards12.isNullOrEmpty(value)) {
|
|
1143
1159
|
return defaultValue;
|
|
1144
1160
|
}
|
|
1145
1161
|
return value;
|
|
@@ -1149,7 +1165,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1149
1165
|
}
|
|
1150
1166
|
getNumber(key, defaultValue) {
|
|
1151
1167
|
const value = this.get(key);
|
|
1152
|
-
if (
|
|
1168
|
+
if (Guards12.isNullOrEmpty(value)) {
|
|
1153
1169
|
return defaultValue;
|
|
1154
1170
|
}
|
|
1155
1171
|
const parsed = Number(value);
|
|
@@ -1162,7 +1178,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1162
1178
|
}
|
|
1163
1179
|
getBoolean(key, defaultValue) {
|
|
1164
1180
|
const value = this.get(key);
|
|
1165
|
-
if (
|
|
1181
|
+
if (Guards12.isNullOrEmpty(value)) {
|
|
1166
1182
|
return defaultValue;
|
|
1167
1183
|
}
|
|
1168
1184
|
const normalized = value.toLowerCase().trim();
|
|
@@ -1174,7 +1190,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1174
1190
|
}
|
|
1175
1191
|
getOrThrow(key) {
|
|
1176
1192
|
const value = this.get(key);
|
|
1177
|
-
if (!
|
|
1193
|
+
if (!Guards12.isDefined(value)) {
|
|
1178
1194
|
throw new Error(
|
|
1179
1195
|
`[Configuration Error]: Required configuration key "${key}" is missing in the environment.`
|
|
1180
1196
|
);
|
|
@@ -1184,7 +1200,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1184
1200
|
};
|
|
1185
1201
|
|
|
1186
1202
|
// src/infrastructure/configuration/vite.configuration.ts
|
|
1187
|
-
import { Guards as
|
|
1203
|
+
import { Guards as Guards13 } from "@xeno-js/shared";
|
|
1188
1204
|
var VITE_PREFIX = "VITE_";
|
|
1189
1205
|
var ViteConfigurationService = class {
|
|
1190
1206
|
constructor(_env = import.meta.env ?? {}) {
|
|
@@ -1194,12 +1210,12 @@ var ViteConfigurationService = class {
|
|
|
1194
1210
|
get(key, defaultValue) {
|
|
1195
1211
|
const fullKey = key.startsWith(VITE_PREFIX) ? key : `VITE_${key}`;
|
|
1196
1212
|
const value = String(this._env[fullKey]);
|
|
1197
|
-
if (!
|
|
1213
|
+
if (!Guards13.isNullOrEmpty(value)) return value;
|
|
1198
1214
|
return defaultValue;
|
|
1199
1215
|
}
|
|
1200
1216
|
getNumber(key, defaultValue) {
|
|
1201
1217
|
const rawValue = this.get(key);
|
|
1202
|
-
if (
|
|
1218
|
+
if (Guards13.isDefined(rawValue)) {
|
|
1203
1219
|
const parsed = Number(rawValue);
|
|
1204
1220
|
if (!Number.isNaN(parsed)) return parsed;
|
|
1205
1221
|
}
|
|
@@ -1207,7 +1223,7 @@ var ViteConfigurationService = class {
|
|
|
1207
1223
|
}
|
|
1208
1224
|
getBoolean(key, defaultValue) {
|
|
1209
1225
|
const rawValue = this.get(key);
|
|
1210
|
-
if (
|
|
1226
|
+
if (Guards13.isDefined(rawValue)) {
|
|
1211
1227
|
const str = String(rawValue).toLowerCase().trim();
|
|
1212
1228
|
if (str.toLowerCase() === "true" || str === "1") return true;
|
|
1213
1229
|
if (str.toLowerCase() === "false" || str === "0") return false;
|
|
@@ -1216,7 +1232,7 @@ var ViteConfigurationService = class {
|
|
|
1216
1232
|
}
|
|
1217
1233
|
getOrThrow(key) {
|
|
1218
1234
|
const val = this.get(key);
|
|
1219
|
-
if (!
|
|
1235
|
+
if (!Guards13.isDefined(val)) {
|
|
1220
1236
|
throw new Error(`[Configuration Error]: Missing required environment variable "${key}".`);
|
|
1221
1237
|
}
|
|
1222
1238
|
return val;
|
|
@@ -1227,7 +1243,7 @@ var ViteConfigurationService = class {
|
|
|
1227
1243
|
};
|
|
1228
1244
|
|
|
1229
1245
|
// src/infrastructure/container/service-container.ts
|
|
1230
|
-
import { Guards as
|
|
1246
|
+
import { Guards as Guards14 } from "@xeno-js/shared";
|
|
1231
1247
|
var ContainerScope = class {
|
|
1232
1248
|
constructor(container, parentScope) {
|
|
1233
1249
|
this.container = container;
|
|
@@ -1333,7 +1349,7 @@ var ServiceContainer = class {
|
|
|
1333
1349
|
* @link https://github.com/xeno-js/xeno-js
|
|
1334
1350
|
*/
|
|
1335
1351
|
internalExecuteInContext(callback) {
|
|
1336
|
-
if (
|
|
1352
|
+
if (Guards14.isDefined(this.resolutionStack)) return callback();
|
|
1337
1353
|
this.resolutionStack = {
|
|
1338
1354
|
stack: /* @__PURE__ */ new Set()
|
|
1339
1355
|
};
|
|
@@ -1358,14 +1374,14 @@ var ServiceContainer = class {
|
|
|
1358
1374
|
*/
|
|
1359
1375
|
internalResolveInternal(token, currentScope) {
|
|
1360
1376
|
const registration = this.registrations.get(token);
|
|
1361
|
-
if (!
|
|
1377
|
+
if (!Guards14.isDefined(registration)) {
|
|
1362
1378
|
const tokenName = token.toString();
|
|
1363
1379
|
throw new Error(
|
|
1364
1380
|
`[DI Container Error]: Registration not found for token '${tokenName}'. Ensure the service is registered before resolving.`
|
|
1365
1381
|
);
|
|
1366
1382
|
}
|
|
1367
1383
|
const currentStack = this.resolutionStack;
|
|
1368
|
-
if (!
|
|
1384
|
+
if (!Guards14.isDefined(currentStack)) {
|
|
1369
1385
|
throw new Error(`[DI Container Error]: Execution outside the IoC container context.`);
|
|
1370
1386
|
}
|
|
1371
1387
|
if (currentStack.stack.has(token)) {
|
|
@@ -1405,7 +1421,7 @@ var ServiceContainer = class {
|
|
|
1405
1421
|
}
|
|
1406
1422
|
if (registration.lifetime === "scoped") {
|
|
1407
1423
|
const existingInstance = currentScope.getScopedInstance(token);
|
|
1408
|
-
if (
|
|
1424
|
+
if (Guards14.isDefined(existingInstance)) {
|
|
1409
1425
|
return existingInstance;
|
|
1410
1426
|
}
|
|
1411
1427
|
return executeWithStackIsolation("scoped", () => {
|
|
@@ -1430,16 +1446,16 @@ var ServiceContainer = class {
|
|
|
1430
1446
|
};
|
|
1431
1447
|
var isDisposable = Object.freeze({
|
|
1432
1448
|
check: (obj) => {
|
|
1433
|
-
return
|
|
1449
|
+
return Guards14.isDefined(obj) && Guards14.isObject(obj) && "dispose" in obj && Guards14.hasMethod(obj, "dispose");
|
|
1434
1450
|
}
|
|
1435
1451
|
});
|
|
1436
1452
|
|
|
1437
1453
|
// src/infrastructure/modules/auth.module.ts
|
|
1438
|
-
import { Guards as
|
|
1454
|
+
import { Guards as Guards23 } from "@xeno-js/shared";
|
|
1439
1455
|
import { TOKENS as TOKENS2 } from "@xeno-js/shared";
|
|
1440
1456
|
|
|
1441
1457
|
// src/infrastructure/services/allow_methods/allow-method.service.ts
|
|
1442
|
-
import { Guards as
|
|
1458
|
+
import { Guards as Guards15, RoutePatternHelper } from "@xeno-js/shared";
|
|
1443
1459
|
var AllowMethodRegistry = class {
|
|
1444
1460
|
_staticRoutes = /* @__PURE__ */ new Map();
|
|
1445
1461
|
_dynamicRoutes = [];
|
|
@@ -1455,7 +1471,7 @@ var AllowMethodRegistry = class {
|
|
|
1455
1471
|
check(path, method) {
|
|
1456
1472
|
const cleanPath = RoutePatternHelper.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1457
1473
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1458
|
-
if (
|
|
1474
|
+
if (Guards15.isDefined(staticMethods)) return staticMethods.includes(method);
|
|
1459
1475
|
for (const route of this._dynamicRoutes) {
|
|
1460
1476
|
if (route.pattern.test(cleanPath)) return route.methods.includes(method);
|
|
1461
1477
|
}
|
|
@@ -1464,11 +1480,11 @@ var AllowMethodRegistry = class {
|
|
|
1464
1480
|
getMethods(path) {
|
|
1465
1481
|
const cleanPath = RoutePatternHelper.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1466
1482
|
const methods = this.findMethods(cleanPath);
|
|
1467
|
-
return
|
|
1483
|
+
return Guards15.isDefined(methods) ? methods.join(", ").toUpperCase() : "";
|
|
1468
1484
|
}
|
|
1469
1485
|
findMethods(cleanPath) {
|
|
1470
1486
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1471
|
-
if (
|
|
1487
|
+
if (Guards15.isDefined(staticMethods)) return staticMethods;
|
|
1472
1488
|
for (const route of this._dynamicRoutes) {
|
|
1473
1489
|
if (route.pattern.test(cleanPath)) return route.methods;
|
|
1474
1490
|
}
|
|
@@ -1477,14 +1493,14 @@ var AllowMethodRegistry = class {
|
|
|
1477
1493
|
};
|
|
1478
1494
|
|
|
1479
1495
|
// src/infrastructure/services/allow_origins/allow-origin.http.ts
|
|
1480
|
-
import { Guards as
|
|
1496
|
+
import { Guards as Guards16 } from "@xeno-js/shared";
|
|
1481
1497
|
var AllowOrigin = class {
|
|
1482
1498
|
constructor(_list) {
|
|
1483
1499
|
this._list = _list;
|
|
1484
1500
|
}
|
|
1485
1501
|
_list;
|
|
1486
1502
|
isAllowed(origin) {
|
|
1487
|
-
if (
|
|
1503
|
+
if (Guards16.isNullOrEmpty(origin)) return true;
|
|
1488
1504
|
const cleanOrigin = origin.trim().toLowerCase();
|
|
1489
1505
|
for (const pattern of this._list) {
|
|
1490
1506
|
const cleanPattern = pattern.trim().toLowerCase();
|
|
@@ -1494,7 +1510,7 @@ var AllowOrigin = class {
|
|
|
1494
1510
|
const domainSuffix = cleanPattern.substring(1);
|
|
1495
1511
|
if (cleanOrigin.endsWith(domainSuffix)) {
|
|
1496
1512
|
const prefix = cleanOrigin.slice(0, cleanOrigin.length - domainSuffix.length);
|
|
1497
|
-
if (!
|
|
1513
|
+
if (!Guards16.isNullOrEmpty(prefix) && !prefix.includes(".")) return true;
|
|
1498
1514
|
}
|
|
1499
1515
|
}
|
|
1500
1516
|
}
|
|
@@ -1506,7 +1522,7 @@ var AllowOrigin = class {
|
|
|
1506
1522
|
init_concurrency();
|
|
1507
1523
|
|
|
1508
1524
|
// src/infrastructure/services/cookies/cookies.service.ts
|
|
1509
|
-
import { Guards as
|
|
1525
|
+
import { Guards as Guards17, HttpHelper as HttpHelper2 } from "@xeno-js/shared";
|
|
1510
1526
|
var CookieHandler = class {
|
|
1511
1527
|
constructor(_contextAccessor, _config, _defaultOpts) {
|
|
1512
1528
|
this._contextAccessor = _contextAccessor;
|
|
@@ -1520,7 +1536,7 @@ var CookieHandler = class {
|
|
|
1520
1536
|
getAll() {
|
|
1521
1537
|
const network = this._contextAccessor.getNetworkContext();
|
|
1522
1538
|
const cookie = network?.cookies;
|
|
1523
|
-
if (
|
|
1539
|
+
if (Guards17.isNullOrEmpty(cookie)) return [];
|
|
1524
1540
|
const parsedCookies = HttpHelper2.parseCookies(network?.cookies);
|
|
1525
1541
|
return Object.entries(parsedCookies).map(([name, value]) => ({
|
|
1526
1542
|
name,
|
|
@@ -1546,14 +1562,14 @@ var CookieHandler = class {
|
|
|
1546
1562
|
...this._defaultOpts,
|
|
1547
1563
|
...cookie
|
|
1548
1564
|
};
|
|
1549
|
-
if (!
|
|
1550
|
-
if (!
|
|
1551
|
-
if (!
|
|
1552
|
-
if (!
|
|
1553
|
-
if (!
|
|
1554
|
-
if (!
|
|
1555
|
-
if (!
|
|
1556
|
-
if (
|
|
1565
|
+
if (!Guards17.isNullOrEmpty(merged.path)) str += `; Path=${merged.path}`;
|
|
1566
|
+
if (!Guards17.isNullOrEmpty(merged.maxAge)) str += `; Max-Age=${merged.maxAge}`;
|
|
1567
|
+
if (!Guards17.isNullOrEmpty(merged.expires)) str += `; Expires=${merged.expires.toUTCString()}`;
|
|
1568
|
+
if (!Guards17.isNullOrEmpty(merged.domain)) str += `; Domain=${merged.domain}`;
|
|
1569
|
+
if (!Guards17.isNullOrEmpty(merged.secure) && merged.secure) str += "; Secure";
|
|
1570
|
+
if (!Guards17.isNullOrEmpty(merged.httpOnly) && merged.httpOnly) str += "; HttpOnly";
|
|
1571
|
+
if (!Guards17.isNullOrEmpty(merged.sameSite)) {
|
|
1572
|
+
if (Guards17.isBoolean(merged.sameSite)) {
|
|
1557
1573
|
str += merged.sameSite ? "; SameSite=Strict" : "";
|
|
1558
1574
|
} else {
|
|
1559
1575
|
const val = merged.sameSite.toLowerCase();
|
|
@@ -1561,8 +1577,8 @@ var CookieHandler = class {
|
|
|
1561
1577
|
str += `; SameSite=${formatted}`;
|
|
1562
1578
|
}
|
|
1563
1579
|
}
|
|
1564
|
-
if (
|
|
1565
|
-
if (
|
|
1580
|
+
if (Guards17.isDefined(merged.partitioned)) str += "; Partitioned";
|
|
1581
|
+
if (Guards17.isDefined(merged.priority)) {
|
|
1566
1582
|
const p = merged.priority.toLowerCase();
|
|
1567
1583
|
const formattedPriority = p.charAt(0).toUpperCase() + p.slice(1);
|
|
1568
1584
|
str += `; Priority=${formattedPriority}`;
|
|
@@ -1605,7 +1621,7 @@ var EdgeCryptoService = class {
|
|
|
1605
1621
|
};
|
|
1606
1622
|
|
|
1607
1623
|
// src/infrastructure/services/csrf/csrf-token.service.ts
|
|
1608
|
-
import { Guards as
|
|
1624
|
+
import { Guards as Guards18 } from "@xeno-js/shared";
|
|
1609
1625
|
var CsrfTokenService = class {
|
|
1610
1626
|
constructor(_secret, _cryptoService) {
|
|
1611
1627
|
this._secret = _secret;
|
|
@@ -1624,7 +1640,7 @@ var CsrfTokenService = class {
|
|
|
1624
1640
|
if (separatorIndex <= 0) return false;
|
|
1625
1641
|
const nonce = token.slice(0, separatorIndex);
|
|
1626
1642
|
const signature = token.slice(separatorIndex + 1);
|
|
1627
|
-
if (
|
|
1643
|
+
if (Guards18.isNullOrEmpty(nonce) || Guards18.isNullOrEmpty(signature)) return false;
|
|
1628
1644
|
const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1629
1645
|
const encoder = new TextEncoder();
|
|
1630
1646
|
const actualBuffer = encoder.encode(signature);
|
|
@@ -1635,7 +1651,7 @@ var CsrfTokenService = class {
|
|
|
1635
1651
|
};
|
|
1636
1652
|
|
|
1637
1653
|
// src/infrastructure/services/extractors/extract-bearer.extractor.ts
|
|
1638
|
-
import { Guards as
|
|
1654
|
+
import { Guards as Guards19, HttpHelper as HttpHelper3 } from "@xeno-js/shared";
|
|
1639
1655
|
var BearerTokenExtractor = class {
|
|
1640
1656
|
constructor(_cookiePrefix) {
|
|
1641
1657
|
this._cookiePrefix = _cookiePrefix;
|
|
@@ -1643,14 +1659,14 @@ var BearerTokenExtractor = class {
|
|
|
1643
1659
|
_cookiePrefix;
|
|
1644
1660
|
extract(headers) {
|
|
1645
1661
|
const authHeader = headers.get("Authorization");
|
|
1646
|
-
if (
|
|
1662
|
+
if (Guards19.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1647
1663
|
return authHeader.substring(7);
|
|
1648
1664
|
}
|
|
1649
1665
|
const cookieHeader = headers.get("cookie");
|
|
1650
|
-
if (
|
|
1666
|
+
if (Guards19.isDefined(cookieHeader)) {
|
|
1651
1667
|
const cookies = HttpHelper3.parseCookies(cookieHeader);
|
|
1652
1668
|
const token = cookies[this._cookiePrefix];
|
|
1653
|
-
if (
|
|
1669
|
+
if (Guards19.isDefined(token)) {
|
|
1654
1670
|
return token;
|
|
1655
1671
|
}
|
|
1656
1672
|
}
|
|
@@ -1659,17 +1675,17 @@ var BearerTokenExtractor = class {
|
|
|
1659
1675
|
};
|
|
1660
1676
|
|
|
1661
1677
|
// src/infrastructure/services/extractors/http-cookie.extractor.ts
|
|
1662
|
-
import { Guards as
|
|
1678
|
+
import { Guards as Guards20, HttpHelper as HttpHelper4 } from "@xeno-js/shared";
|
|
1663
1679
|
var HttpCookieExtractor = class {
|
|
1664
1680
|
extract(cookie) {
|
|
1665
|
-
if (!
|
|
1681
|
+
if (!Guards20.isDefined(cookie.header)) return void 0;
|
|
1666
1682
|
const cookies = HttpHelper4.parseCookies(cookie.header);
|
|
1667
1683
|
return cookies[cookie.name];
|
|
1668
1684
|
}
|
|
1669
1685
|
};
|
|
1670
1686
|
|
|
1671
1687
|
// src/infrastructure/services/extractors/http-header.extractor.ts
|
|
1672
|
-
import { Guards as
|
|
1688
|
+
import { Guards as Guards21, GuidHelper as GuidHelper4, HttpHelper as HttpHelper5, MathHelper } from "@xeno-js/shared";
|
|
1673
1689
|
var HttpHeaderExtractor = class {
|
|
1674
1690
|
/**
|
|
1675
1691
|
* @description Constructor for HttpHeaderExtractor. It takes an instance of IServiceExtractor for extracting Bearer tokens, allowing for separation of concerns and adherence to the Single Responsibility Principle (SRP). This design enables the HttpHeaderExtractor to focus on general header extraction while delegating the specific logic of Bearer token extraction to a dedicated extractor, promoting code reusability and maintainability.
|
|
@@ -1732,17 +1748,17 @@ var HttpHeaderExtractor = class {
|
|
|
1732
1748
|
referer: cleanReferer,
|
|
1733
1749
|
sequence: {
|
|
1734
1750
|
sequenceId,
|
|
1735
|
-
position:
|
|
1736
|
-
size:
|
|
1751
|
+
position: Guards21.isDefined(position) ? MathHelper.toNumber(position) : void 0,
|
|
1752
|
+
size: Guards21.isDefined(size) ? MathHelper.toNumber(size) : void 0
|
|
1737
1753
|
},
|
|
1738
|
-
expiration:
|
|
1754
|
+
expiration: Guards21.isDefined(expiration) ? MathHelper.toNumber(expiration) : void 0
|
|
1739
1755
|
};
|
|
1740
1756
|
return metadata;
|
|
1741
1757
|
}
|
|
1742
1758
|
};
|
|
1743
1759
|
|
|
1744
1760
|
// src/infrastructure/services/resolver/client-ip.resolver.ts
|
|
1745
|
-
import { Guards as
|
|
1761
|
+
import { Guards as Guards22 } from "@xeno-js/shared";
|
|
1746
1762
|
var ClientIpResolver = class {
|
|
1747
1763
|
constructor(_trustedProxies = []) {
|
|
1748
1764
|
this._trustedProxies = _trustedProxies;
|
|
@@ -1750,11 +1766,11 @@ var ClientIpResolver = class {
|
|
|
1750
1766
|
_trustedProxies;
|
|
1751
1767
|
resolve(req, clientIp) {
|
|
1752
1768
|
const socketIp = req.socket?.remoteAddress;
|
|
1753
|
-
if (!
|
|
1754
|
-
return !
|
|
1769
|
+
if (!Guards22.isDefined(socketIp))
|
|
1770
|
+
return !Guards22.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
1755
1771
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
1756
1772
|
if (!isTrustedProxy) return socketIp;
|
|
1757
|
-
if (
|
|
1773
|
+
if (Guards22.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
1758
1774
|
return socketIp;
|
|
1759
1775
|
}
|
|
1760
1776
|
};
|
|
@@ -1762,17 +1778,17 @@ var ClientIpResolver = class {
|
|
|
1762
1778
|
// src/infrastructure/modules/auth.module.ts
|
|
1763
1779
|
var AuthModule = class {
|
|
1764
1780
|
async configure(container, opts) {
|
|
1765
|
-
if (!
|
|
1781
|
+
if (!Guards23.isDefined(opts.authService))
|
|
1766
1782
|
throw new Error(
|
|
1767
1783
|
"[AuthModule Error]: An authService instance is required to configure AuthModule."
|
|
1768
1784
|
);
|
|
1769
|
-
if (
|
|
1770
|
-
if (
|
|
1785
|
+
if (Guards23.isDefined(opts.cookieHandlerOptions)) {
|
|
1786
|
+
if (Guards23.isDefined(opts.cookieHandlerOptions.cookieHandlerCustom)) {
|
|
1771
1787
|
container.addScoped(
|
|
1772
1788
|
TOKENS2.COOKIE_HANDLER,
|
|
1773
1789
|
(c) => opts.cookieHandlerOptions.cookieHandlerCustom(c)
|
|
1774
1790
|
);
|
|
1775
|
-
} else if (
|
|
1791
|
+
} else if (Guards23.isDefined(opts.cookieHandlerOptions.enableDefault) && opts.cookieHandlerOptions.enableDefault.enable) {
|
|
1776
1792
|
container.addScoped(
|
|
1777
1793
|
TOKENS2.COOKIE_HANDLER,
|
|
1778
1794
|
(c) => new CookieHandler(
|
|
@@ -1788,7 +1804,7 @@ var AuthModule = class {
|
|
|
1788
1804
|
container.addScoped(TOKENS2.BASE_AUTH_SERVICE, (c) => c.resolve(TOKENS2.AUTH_SERVICE));
|
|
1789
1805
|
}
|
|
1790
1806
|
getExtractor(opts, container) {
|
|
1791
|
-
if (
|
|
1807
|
+
if (Guards23.isDefined(opts.tokenExtractor)) {
|
|
1792
1808
|
container.addSingleton(TOKENS2.TOKEN_SERVICE_EXTRACTOR, (c) => opts.tokenExtractor(c));
|
|
1793
1809
|
} else {
|
|
1794
1810
|
container.addSingleton(
|
|
@@ -1800,10 +1816,10 @@ var AuthModule = class {
|
|
|
1800
1816
|
};
|
|
1801
1817
|
|
|
1802
1818
|
// src/infrastructure/modules/cache.module.ts
|
|
1803
|
-
import { Guards as
|
|
1819
|
+
import { Guards as Guards30, TOKENS as TOKENS6 } from "@xeno-js/shared";
|
|
1804
1820
|
|
|
1805
1821
|
// src/infrastructure/cache/inmemory.cache.ts
|
|
1806
|
-
import { Guards as
|
|
1822
|
+
import { Guards as Guards24, StringHelper as StringHelper2 } from "@xeno-js/shared";
|
|
1807
1823
|
var InMemoryCache = class {
|
|
1808
1824
|
/**
|
|
1809
1825
|
* @description Constructs a new instance of the InMemoryCache class, which initializes an internal Map to store cached values. The Map is used to associate cache keys with their corresponding values and expiration times, allowing for efficient retrieval and management of cached data. The constructor does not take any parameters, as the in-memory cache is self-contained and does not require external dependencies or configuration.
|
|
@@ -1825,21 +1841,21 @@ var InMemoryCache = class {
|
|
|
1825
1841
|
_cache;
|
|
1826
1842
|
_cleanupInterval;
|
|
1827
1843
|
_isNodeTimeout(timer) {
|
|
1828
|
-
return
|
|
1844
|
+
return Guards24.isDefined(timer) && Guards24.isObject(timer) && Guards24.hasMethod(timer, "unref");
|
|
1829
1845
|
}
|
|
1830
1846
|
async get(key) {
|
|
1831
1847
|
const entry = this._cache.get(key);
|
|
1832
|
-
if (!
|
|
1848
|
+
if (!Guards24.isDefined(entry)) {
|
|
1833
1849
|
return void 0;
|
|
1834
1850
|
}
|
|
1835
|
-
if (
|
|
1851
|
+
if (Guards24.isDefined(entry.expiresAt) && entry.expiresAt < Date.now()) {
|
|
1836
1852
|
this._cache.delete(key);
|
|
1837
1853
|
return void 0;
|
|
1838
1854
|
}
|
|
1839
1855
|
return JSON.parse(entry.value);
|
|
1840
1856
|
}
|
|
1841
1857
|
async set(key, value, ttl) {
|
|
1842
|
-
const expiresAt =
|
|
1858
|
+
const expiresAt = Guards24.isDefined(ttl) ? Date.now() + ttl * 1e3 : void 0;
|
|
1843
1859
|
this._cache.set(key, { value: StringHelper2.safeStringify(value), expiresAt });
|
|
1844
1860
|
}
|
|
1845
1861
|
async setIfAbsent(key, value, ttl) {
|
|
@@ -1854,10 +1870,10 @@ var InMemoryCache = class {
|
|
|
1854
1870
|
}
|
|
1855
1871
|
async has(key) {
|
|
1856
1872
|
const entry = this._cache.get(key);
|
|
1857
|
-
if (!
|
|
1873
|
+
if (!Guards24.isDefined(entry)) {
|
|
1858
1874
|
return false;
|
|
1859
1875
|
}
|
|
1860
|
-
if (
|
|
1876
|
+
if (Guards24.isDefined(entry.expiresAt) && entry.expiresAt < Date.now()) {
|
|
1861
1877
|
this._cache.delete(key);
|
|
1862
1878
|
return false;
|
|
1863
1879
|
}
|
|
@@ -1869,7 +1885,7 @@ var InMemoryCache = class {
|
|
|
1869
1885
|
async increment(key, ttlSeconds) {
|
|
1870
1886
|
const entry = this._cache.get(key);
|
|
1871
1887
|
const now = Date.now();
|
|
1872
|
-
if (
|
|
1888
|
+
if (Guards24.isDefined(entry) && (!Guards24.isDefined(entry.expiresAt) || entry.expiresAt > now)) {
|
|
1873
1889
|
const nextValue = Number(StringHelper2.safeParse(entry.value)) + 1;
|
|
1874
1890
|
this._cache.set(key, {
|
|
1875
1891
|
value: StringHelper2.safeStringify(nextValue),
|
|
@@ -1877,7 +1893,7 @@ var InMemoryCache = class {
|
|
|
1877
1893
|
});
|
|
1878
1894
|
return nextValue;
|
|
1879
1895
|
}
|
|
1880
|
-
const ttl = !
|
|
1896
|
+
const ttl = !Guards24.isNullOrEmpty(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
1881
1897
|
const expiresAt = now + ttl * 1e3;
|
|
1882
1898
|
this._cache.set(key, { value: StringHelper2.safeStringify(1), expiresAt });
|
|
1883
1899
|
return 1;
|
|
@@ -1885,7 +1901,7 @@ var InMemoryCache = class {
|
|
|
1885
1901
|
evictExpired() {
|
|
1886
1902
|
const now = Date.now();
|
|
1887
1903
|
for (const [key, entry] of this._cache.entries()) {
|
|
1888
|
-
if (!
|
|
1904
|
+
if (!Guards24.isDefined(entry.expiresAt) || entry.expiresAt > now) {
|
|
1889
1905
|
this._cache.delete(key);
|
|
1890
1906
|
}
|
|
1891
1907
|
}
|
|
@@ -1907,7 +1923,7 @@ var InMemoryCache = class {
|
|
|
1907
1923
|
};
|
|
1908
1924
|
|
|
1909
1925
|
// src/infrastructure/cache/key-builder.cache.ts
|
|
1910
|
-
import { Guards as
|
|
1926
|
+
import { Guards as Guards25 } from "@xeno-js/shared";
|
|
1911
1927
|
var CacheKeyBuilder = class {
|
|
1912
1928
|
/**
|
|
1913
1929
|
* @description Constructs a new instance of the CacheKeyBuilder class, which requires an IIdentityAccessor to access the current user's identity. The constructor initializes the dependency needed for building contextual cache keys based on the user's identity, enabling tenant-specific caching behavior in multi-tenant applications.
|
|
@@ -1924,14 +1940,14 @@ var CacheKeyBuilder = class {
|
|
|
1924
1940
|
_identityAccessor;
|
|
1925
1941
|
buildContextualKey(key) {
|
|
1926
1942
|
const identity = this._identityAccessor.getIdentity();
|
|
1927
|
-
if (
|
|
1943
|
+
if (Guards25.isDefined(identity) && !Guards25.isNullOrEmpty(identity.tenantId)) {
|
|
1928
1944
|
return `tenant:${identity.tenantId}:${key}`;
|
|
1929
1945
|
}
|
|
1930
1946
|
return `${key}:public`;
|
|
1931
1947
|
}
|
|
1932
1948
|
buildUserScopedKey(key) {
|
|
1933
1949
|
const identity = this._identityAccessor.getIdentity();
|
|
1934
|
-
if (
|
|
1950
|
+
if (Guards25.isDefined(identity) && !Guards25.isNullOrEmpty(identity.userId)) {
|
|
1935
1951
|
return this.buildContextualKey(`user:${identity.userId}:${key}`);
|
|
1936
1952
|
}
|
|
1937
1953
|
return this.buildContextualKey(key);
|
|
@@ -1939,7 +1955,7 @@ var CacheKeyBuilder = class {
|
|
|
1939
1955
|
};
|
|
1940
1956
|
|
|
1941
1957
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
1942
|
-
import { Guards as
|
|
1958
|
+
import { Guards as Guards26 } from "@xeno-js/shared";
|
|
1943
1959
|
var RateLimitKeyBuilder = class {
|
|
1944
1960
|
constructor(_contextAccessor) {
|
|
1945
1961
|
this._contextAccessor = _contextAccessor;
|
|
@@ -1950,18 +1966,18 @@ var RateLimitKeyBuilder = class {
|
|
|
1950
1966
|
const tenantId = ctx?.identity?.tenantId;
|
|
1951
1967
|
const userId = ctx?.identity?.userId;
|
|
1952
1968
|
const clientIp = ctx?.network?.clientIp;
|
|
1953
|
-
if (!
|
|
1969
|
+
if (!Guards26.isNullOrEmpty(tenantId) && !Guards26.isNullOrEmpty(userId))
|
|
1954
1970
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
1955
|
-
if (!
|
|
1971
|
+
if (!Guards26.isNullOrEmpty(tenantId) && !Guards26.isNullOrEmpty(clientIp))
|
|
1956
1972
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
1957
|
-
if (!
|
|
1958
|
-
if (!
|
|
1973
|
+
if (!Guards26.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
1974
|
+
if (!Guards26.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
1959
1975
|
return void 0;
|
|
1960
1976
|
}
|
|
1961
1977
|
};
|
|
1962
1978
|
|
|
1963
1979
|
// src/infrastructure/modules/utils/auth.utils.ts
|
|
1964
|
-
import { Guards as
|
|
1980
|
+
import { Guards as Guards27 } from "@xeno-js/shared";
|
|
1965
1981
|
import {
|
|
1966
1982
|
TOKENS as TOKENS3
|
|
1967
1983
|
} from "@xeno-js/shared";
|
|
@@ -1978,7 +1994,7 @@ var AuthUtils = Object.freeze({
|
|
|
1978
1994
|
*/
|
|
1979
1995
|
async addAuthZ(container, opts) {
|
|
1980
1996
|
const strategies = [];
|
|
1981
|
-
if (
|
|
1997
|
+
if (Guards27.isDefined(opts.policies)) {
|
|
1982
1998
|
const policyRegistry = opts.policies;
|
|
1983
1999
|
const registryInstance = new PolicyRegistry();
|
|
1984
2000
|
const ctxAccessor = container.resolve(TOKENS3.CONTEXT_ACCESSOR);
|
|
@@ -1986,16 +2002,16 @@ var AuthUtils = Object.freeze({
|
|
|
1986
2002
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
1987
2003
|
const intentLower = intent.toLowerCase();
|
|
1988
2004
|
registryInstance.addPolicy(intentLower, policy);
|
|
1989
|
-
if (!
|
|
2005
|
+
if (!Guards27.isNullOrEmpty(policy.roles)) {
|
|
1990
2006
|
Policies.add("roles");
|
|
1991
2007
|
}
|
|
1992
|
-
if (!
|
|
2008
|
+
if (!Guards27.isNullOrEmpty(policy.permissions)) {
|
|
1993
2009
|
Policies.add("permissions");
|
|
1994
2010
|
}
|
|
1995
|
-
if (!
|
|
2011
|
+
if (!Guards27.isNullOrEmpty(policy.userId)) {
|
|
1996
2012
|
Policies.add("userId");
|
|
1997
2013
|
}
|
|
1998
|
-
if (!
|
|
2014
|
+
if (!Guards27.isNullOrEmpty(policy.tenantId)) {
|
|
1999
2015
|
Policies.add("tenantId");
|
|
2000
2016
|
}
|
|
2001
2017
|
}
|
|
@@ -2012,10 +2028,10 @@ var AuthUtils = Object.freeze({
|
|
|
2012
2028
|
strategies.push(new TenantAuthorizationStrategy(registryInstance, ctxAccessor));
|
|
2013
2029
|
}
|
|
2014
2030
|
}
|
|
2015
|
-
if (!
|
|
2031
|
+
if (!Guards27.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2016
2032
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2017
2033
|
customStrategies.forEach((strategyToken) => {
|
|
2018
|
-
if (
|
|
2034
|
+
if (Guards27.isDefined(strategyToken)) {
|
|
2019
2035
|
strategies.push(strategyToken(container));
|
|
2020
2036
|
}
|
|
2021
2037
|
});
|
|
@@ -2044,11 +2060,11 @@ var CacheUtils = Object.freeze({
|
|
|
2044
2060
|
});
|
|
2045
2061
|
|
|
2046
2062
|
// src/infrastructure/modules/utils/logger.utils.ts
|
|
2047
|
-
import { Guards as
|
|
2063
|
+
import { Guards as Guards29, LOG_LEVEL as LOG_LEVEL3 } from "@xeno-js/shared";
|
|
2048
2064
|
import { TOKENS as TOKENS5 } from "@xeno-js/shared";
|
|
2049
2065
|
|
|
2050
2066
|
// src/infrastructure/loggers/console.logger.ts
|
|
2051
|
-
import { Guards as
|
|
2067
|
+
import { Guards as Guards28, LOG_LEVEL as LOG_LEVEL2 } from "@xeno-js/shared";
|
|
2052
2068
|
var ConsoleLogger = class {
|
|
2053
2069
|
/**
|
|
2054
2070
|
* Constructs a new instance of the ConsoleLogger class, which takes an optional minimum log level. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.
|
|
@@ -2067,7 +2083,7 @@ var ConsoleLogger = class {
|
|
|
2067
2083
|
track(level, message, context, error = void 0) {
|
|
2068
2084
|
if (level < this._minLevel) return;
|
|
2069
2085
|
const logMessage = `[${level}] ${message}`;
|
|
2070
|
-
const payload =
|
|
2086
|
+
const payload = Guards28.isDefined(error) ? { ...context, error } : context;
|
|
2071
2087
|
switch (level) {
|
|
2072
2088
|
case LOG_LEVEL2.ERROR:
|
|
2073
2089
|
console.error(logMessage, payload ?? {});
|
|
@@ -2101,7 +2117,7 @@ var LoggerUtils2 = Object.freeze({
|
|
|
2101
2117
|
async addLogger(container, opts) {
|
|
2102
2118
|
const loggerDependencies = [];
|
|
2103
2119
|
if (opts.console) loggerDependencies.push(new ConsoleLogger(opts?.level));
|
|
2104
|
-
if (!
|
|
2120
|
+
if (!Guards29.isNullOrEmpty(opts.customLoggers)) {
|
|
2105
2121
|
const customLoggers = opts.customLoggers;
|
|
2106
2122
|
for (const logger of customLoggers) {
|
|
2107
2123
|
loggerDependencies.push(logger(container));
|
|
@@ -2121,21 +2137,21 @@ var CacheModule = class {
|
|
|
2121
2137
|
TOKENS6.CACHE_KEY_BUILDER,
|
|
2122
2138
|
(c) => new CacheKeyBuilder(c.resolve(TOKENS6.IDENTITY_ACCESSOR))
|
|
2123
2139
|
);
|
|
2124
|
-
if (opts.inMemory &&
|
|
2140
|
+
if (opts.inMemory && Guards30.isDefined(opts.provider))
|
|
2125
2141
|
throw new Error("Cannot use both in memory and provider cache");
|
|
2126
2142
|
else if (opts.inMemory) {
|
|
2127
2143
|
await CacheUtils.addCache(container);
|
|
2128
|
-
} else if (
|
|
2144
|
+
} else if (Guards30.isDefined(opts.provider)) {
|
|
2129
2145
|
container.addSingleton(TOKENS6.CACHE, (c) => opts.provider(c));
|
|
2130
2146
|
} else throw new Error("No cache provider specified");
|
|
2131
2147
|
}
|
|
2132
2148
|
};
|
|
2133
2149
|
|
|
2134
2150
|
// src/infrastructure/modules/context.module.ts
|
|
2135
|
-
import { Guards as
|
|
2151
|
+
import { Guards as Guards36, TOKENS as TOKENS7 } from "@xeno-js/shared";
|
|
2136
2152
|
|
|
2137
2153
|
// src/infrastructure/events/event.dispatcher.ts
|
|
2138
|
-
import { AppError as AppError12, Guards as
|
|
2154
|
+
import { AppError as AppError12, Guards as Guards31, Result as Result16 } from "@xeno-js/shared";
|
|
2139
2155
|
var EventDispatcher = class {
|
|
2140
2156
|
_handlers = /* @__PURE__ */ new Map();
|
|
2141
2157
|
subscribe(eventType, handler) {
|
|
@@ -2146,7 +2162,7 @@ var EventDispatcher = class {
|
|
|
2146
2162
|
async publish(event, signal) {
|
|
2147
2163
|
AppError12.throwIfAborted(signal, "EventDispatcher.publish");
|
|
2148
2164
|
const handlers = this._handlers.get(event.eventType);
|
|
2149
|
-
if (
|
|
2165
|
+
if (Guards31.isNullOrEmpty(handlers)) return Result16.ok();
|
|
2150
2166
|
try {
|
|
2151
2167
|
for (const handler of handlers) {
|
|
2152
2168
|
const result = await handler.handle(event, signal);
|
|
@@ -2196,7 +2212,7 @@ var ServiceScopeFactory = class {
|
|
|
2196
2212
|
};
|
|
2197
2213
|
|
|
2198
2214
|
// src/infrastructure/factories/user-context.factory.ts
|
|
2199
|
-
import { Guards as
|
|
2215
|
+
import { Guards as Guards33 } from "@xeno-js/shared";
|
|
2200
2216
|
var UserContextFactory = class {
|
|
2201
2217
|
/**
|
|
2202
2218
|
* @description Constructs an instance of UserContextFactory.
|
|
@@ -2217,7 +2233,7 @@ var UserContextFactory = class {
|
|
|
2217
2233
|
tenantId: void 0
|
|
2218
2234
|
};
|
|
2219
2235
|
const identity = this._identityFactory.getIdentity();
|
|
2220
|
-
if (
|
|
2236
|
+
if (Guards33.isDefined(identity)) {
|
|
2221
2237
|
output.userId = identity.userId;
|
|
2222
2238
|
output.tenantId = identity.tenantId;
|
|
2223
2239
|
}
|
|
@@ -2226,7 +2242,7 @@ var UserContextFactory = class {
|
|
|
2226
2242
|
};
|
|
2227
2243
|
|
|
2228
2244
|
// src/infrastructure/http/adapter.http.ts
|
|
2229
|
-
import { Guards as
|
|
2245
|
+
import { Guards as Guards34, HttpHelper as HttpHelper6, HttpRouteParamHelper } from "@xeno-js/shared";
|
|
2230
2246
|
var HttpAdapter = class {
|
|
2231
2247
|
constructor(_urlFactory) {
|
|
2232
2248
|
this._urlFactory = _urlFactory;
|
|
@@ -2246,7 +2262,7 @@ var HttpAdapter = class {
|
|
|
2246
2262
|
headers: req.headers
|
|
2247
2263
|
};
|
|
2248
2264
|
const parsedBody = HttpHelper6.parseBody(method, req.body);
|
|
2249
|
-
if (
|
|
2265
|
+
if (Guards34.isDefined(parsedBody)) {
|
|
2250
2266
|
init.body = parsedBody;
|
|
2251
2267
|
init.duplex = "half";
|
|
2252
2268
|
}
|
|
@@ -2259,14 +2275,14 @@ var HttpAdapter = class {
|
|
|
2259
2275
|
};
|
|
2260
2276
|
|
|
2261
2277
|
// src/infrastructure/http/url-builder.http.ts
|
|
2262
|
-
import { Guards as
|
|
2278
|
+
import { Guards as Guards35 } from "@xeno-js/shared";
|
|
2263
2279
|
var UrlBuilder = class {
|
|
2264
2280
|
create(headers) {
|
|
2265
2281
|
const forwardedProto = headers.get("x-forwarded-proto");
|
|
2266
|
-
const protocol =
|
|
2282
|
+
const protocol = Guards35.isDefined(forwardedProto) ? forwardedProto.split(",")[0].trim() : "http";
|
|
2267
2283
|
const forwardedHost = headers.get("x-forwarded-host");
|
|
2268
2284
|
const hostHeader = headers.get("host");
|
|
2269
|
-
const host =
|
|
2285
|
+
const host = Guards35.isDefined(forwardedHost) ? forwardedHost.split(",")[0].trim() : hostHeader ?? "localhost";
|
|
2270
2286
|
return `${protocol}://${host}`;
|
|
2271
2287
|
}
|
|
2272
2288
|
};
|
|
@@ -2307,7 +2323,7 @@ var ContextModule = class {
|
|
|
2307
2323
|
container.addSingleton(TOKENS7.EVENT_DISPATCHER, () => new EventDispatcher());
|
|
2308
2324
|
}
|
|
2309
2325
|
async _getRequestContext(container, opts) {
|
|
2310
|
-
if (
|
|
2326
|
+
if (Guards36.isDefined(opts)) return opts;
|
|
2311
2327
|
const { NodeRequestContextFactory: NodeRequestContextFactory2 } = await Promise.resolve().then(() => (init_request_context_factory(), request_context_factory_exports));
|
|
2312
2328
|
return new NodeRequestContextFactory2(
|
|
2313
2329
|
new ServiceScopeFactory(container)
|
|
@@ -2316,11 +2332,11 @@ var ContextModule = class {
|
|
|
2316
2332
|
};
|
|
2317
2333
|
|
|
2318
2334
|
// src/infrastructure/modules/cqrs.module.ts
|
|
2319
|
-
import { Guards as
|
|
2335
|
+
import { Guards as Guards39, LOG_LEVEL as LOG_LEVEL4 } from "@xeno-js/shared";
|
|
2320
2336
|
import { TOKENS as TOKENS8 } from "@xeno-js/shared";
|
|
2321
2337
|
|
|
2322
2338
|
// src/application/cqrs/pipelines/cache-invalidation.pipeline.ts
|
|
2323
|
-
import { Guards as
|
|
2339
|
+
import { Guards as Guards37 } from "@xeno-js/shared";
|
|
2324
2340
|
var CommandCacheInvalidationBehavior = class {
|
|
2325
2341
|
constructor(_cacheService, _logger) {
|
|
2326
2342
|
this._cacheService = _cacheService;
|
|
@@ -2330,16 +2346,16 @@ var CommandCacheInvalidationBehavior = class {
|
|
|
2330
2346
|
_logger;
|
|
2331
2347
|
async handle(request, next) {
|
|
2332
2348
|
const result = await next();
|
|
2333
|
-
if (result.isOk() &&
|
|
2349
|
+
if (result.isOk() && Guards37.isDefined(request.cacheInvalidation)) {
|
|
2334
2350
|
try {
|
|
2335
2351
|
const { keys, patterns } = request.cacheInvalidation;
|
|
2336
|
-
if (
|
|
2352
|
+
if (Guards37.isArray(keys)) {
|
|
2337
2353
|
for (const key of keys) {
|
|
2338
2354
|
await this._cacheService.remove(key);
|
|
2339
2355
|
this._logger.debug(`[Cache Invalidation] Removed key: ${key}`);
|
|
2340
2356
|
}
|
|
2341
2357
|
}
|
|
2342
|
-
if (
|
|
2358
|
+
if (Guards37.isArray(patterns) && Guards37.hasMethod(this._cacheService, "removePattern")) {
|
|
2343
2359
|
for (const pattern of patterns) {
|
|
2344
2360
|
await this._cacheService.removePattern(pattern);
|
|
2345
2361
|
this._logger.debug(`[Cache Invalidation] Removed pattern: ${pattern}`);
|
|
@@ -2408,7 +2424,7 @@ var IdempotencyStore = class {
|
|
|
2408
2424
|
|
|
2409
2425
|
// src/infrastructure/pipeline_setup/setup.pipeline.ts
|
|
2410
2426
|
import {
|
|
2411
|
-
Guards as
|
|
2427
|
+
Guards as Guards38
|
|
2412
2428
|
} from "@xeno-js/shared";
|
|
2413
2429
|
var PipelineSetupContext = class {
|
|
2414
2430
|
isQueryCaching = false;
|
|
@@ -2420,14 +2436,14 @@ var PipelineSetupContext = class {
|
|
|
2420
2436
|
this._idempotencyOpts = opts;
|
|
2421
2437
|
}
|
|
2422
2438
|
get idempotencyOpts() {
|
|
2423
|
-
if (
|
|
2439
|
+
if (Guards38.isDefined(this._idempotencyOpts)) return Object.freeze(this._idempotencyOpts);
|
|
2424
2440
|
return this._idempotencyOpts;
|
|
2425
2441
|
}
|
|
2426
2442
|
set authzOpts(opts) {
|
|
2427
2443
|
this._authzOpts = opts;
|
|
2428
2444
|
}
|
|
2429
2445
|
get authzOpts() {
|
|
2430
|
-
if (
|
|
2446
|
+
if (Guards38.isDefined(this._authzOpts)) return Object.freeze(this._authzOpts);
|
|
2431
2447
|
return this._authzOpts;
|
|
2432
2448
|
}
|
|
2433
2449
|
addCommon(behavior, order = 50) {
|
|
@@ -2468,14 +2484,14 @@ var CqrsModule = class {
|
|
|
2468
2484
|
context.addCommon(new LoggingPipeline(logger), 10);
|
|
2469
2485
|
for (const plugin of opts.plugins)
|
|
2470
2486
|
await plugin(opts.builder, container.resolve(TOKENS8.CONFIGURATION_SERVICE), context);
|
|
2471
|
-
if (
|
|
2487
|
+
if (Guards39.isDefined(context.authzOpts)) {
|
|
2472
2488
|
const authzPipeline = await AuthUtils.addAuthZ(container, context.authzOpts);
|
|
2473
2489
|
context.addCommon(authzPipeline, 40);
|
|
2474
2490
|
}
|
|
2475
|
-
if ((
|
|
2491
|
+
if ((Guards39.isDefined(context.idempotencyOpts) || context.isQueryCaching) && !container.isRegistered(TOKENS8.CACHE)) {
|
|
2476
2492
|
await new CacheModule().configure(container);
|
|
2477
2493
|
}
|
|
2478
|
-
if (
|
|
2494
|
+
if (Guards39.isDefined(context.idempotencyOpts)) {
|
|
2479
2495
|
const store = new IdempotencyStore(
|
|
2480
2496
|
container.resolve(TOKENS8.CACHE),
|
|
2481
2497
|
container.resolve(TOKENS8.CACHE_KEY_BUILDER)
|
|
@@ -2515,12 +2531,12 @@ var CqrsModule = class {
|
|
|
2515
2531
|
};
|
|
2516
2532
|
|
|
2517
2533
|
// src/infrastructure/modules/db.module.ts
|
|
2518
|
-
import { Guards as
|
|
2534
|
+
import { Guards as Guards41 } from "@xeno-js/shared";
|
|
2519
2535
|
import { TOKENS as TOKENS9 } from "@xeno-js/shared";
|
|
2520
2536
|
|
|
2521
2537
|
// src/infrastructure/transaction/unit-of-work.ts
|
|
2522
2538
|
import { AppError as AppError13 } from "@xeno-js/shared";
|
|
2523
|
-
import { Guards as
|
|
2539
|
+
import { Guards as Guards40 } from "@xeno-js/shared";
|
|
2524
2540
|
var UnitOfWork = class {
|
|
2525
2541
|
/**
|
|
2526
2542
|
* Creates an instance of UnitOfWork.
|
|
@@ -2551,9 +2567,9 @@ var UnitOfWork = class {
|
|
|
2551
2567
|
});
|
|
2552
2568
|
}
|
|
2553
2569
|
async dispose() {
|
|
2554
|
-
if (
|
|
2570
|
+
if (Guards40.isDefined(this._ttx.state)) {
|
|
2555
2571
|
try {
|
|
2556
|
-
if (
|
|
2572
|
+
if (Guards40.hasMethod(this._ttx.state, "rollback")) {
|
|
2557
2573
|
await this._ttx.state.rollback();
|
|
2558
2574
|
}
|
|
2559
2575
|
} finally {
|
|
@@ -2599,7 +2615,7 @@ var DbModule = class {
|
|
|
2599
2615
|
container.addScoped(TOKENS9.TRANSACTION_STATE, () => {
|
|
2600
2616
|
return new TransactionState();
|
|
2601
2617
|
});
|
|
2602
|
-
if (
|
|
2618
|
+
if (Guards41.isDefined(opts.uow)) {
|
|
2603
2619
|
container.addScoped(TOKENS9.UNIT_OF_WORK, (c) => {
|
|
2604
2620
|
return opts.uow(c);
|
|
2605
2621
|
});
|
|
@@ -2614,9 +2630,9 @@ var DbModule = class {
|
|
|
2614
2630
|
return new Proxy(db, {
|
|
2615
2631
|
get(_target, prop, receiver) {
|
|
2616
2632
|
const activeState = ttx.state;
|
|
2617
|
-
if (
|
|
2633
|
+
if (Guards41.isDefined(activeState)) {
|
|
2618
2634
|
const value = Reflect.get(activeState, prop, receiver);
|
|
2619
|
-
if (
|
|
2635
|
+
if (Guards41.isFunction(value)) {
|
|
2620
2636
|
return value.bind(activeState);
|
|
2621
2637
|
}
|
|
2622
2638
|
return value;
|
|
@@ -2636,7 +2652,7 @@ import { RoutePatternHelper as RoutePatternHelper3 } from "@xeno-js/shared";
|
|
|
2636
2652
|
|
|
2637
2653
|
// src/infrastructure/http/route-matcher.http.ts
|
|
2638
2654
|
import {
|
|
2639
|
-
Guards as
|
|
2655
|
+
Guards as Guards42,
|
|
2640
2656
|
HttpHelper as HttpHelper7,
|
|
2641
2657
|
RoutePatternHelper as RoutePatternHelper2,
|
|
2642
2658
|
STATUS_CODES as STATUS_CODES4
|
|
@@ -2647,14 +2663,14 @@ var RouteMatcher = class {
|
|
|
2647
2663
|
}
|
|
2648
2664
|
_compiledRoutes;
|
|
2649
2665
|
match(rawUrl, method) {
|
|
2650
|
-
const url = !
|
|
2666
|
+
const url = !Guards42.isNullOrEmpty(rawUrl) ? rawUrl : "/";
|
|
2651
2667
|
const safeUrl = HttpHelper7.parseSafeUrl(url);
|
|
2652
2668
|
const parsedPath = RoutePatternHelper2.normalizePath(safeUrl.pathname);
|
|
2653
2669
|
const upperMethod = method.toUpperCase();
|
|
2654
2670
|
const matched = this._compiledRoutes.find(
|
|
2655
2671
|
(r) => r.upperMethod === upperMethod && r.pattern.test(parsedPath)
|
|
2656
2672
|
);
|
|
2657
|
-
if (
|
|
2673
|
+
if (Guards42.isDefined(matched)) return matched.definition;
|
|
2658
2674
|
if (upperMethod === "OPTIONS") {
|
|
2659
2675
|
const pathExists = this._compiledRoutes.some((r) => r.pattern.test(parsedPath));
|
|
2660
2676
|
if (pathExists) {
|
|
@@ -2736,17 +2752,17 @@ var HttpServerModule = class {
|
|
|
2736
2752
|
};
|
|
2737
2753
|
|
|
2738
2754
|
// src/infrastructure/modules/logger.module.ts
|
|
2739
|
-
import { Guards as
|
|
2755
|
+
import { Guards as Guards44 } from "@xeno-js/shared";
|
|
2740
2756
|
|
|
2741
2757
|
// src/infrastructure/loggers/setup.logger.ts
|
|
2742
|
-
import { Guards as
|
|
2758
|
+
import { Guards as Guards43, LOG_LEVEL as LOG_LEVEL5 } from "@xeno-js/shared";
|
|
2743
2759
|
var LoggerSetupContext = class {
|
|
2744
2760
|
console = false;
|
|
2745
2761
|
level = LOG_LEVEL5.DEBUG;
|
|
2746
2762
|
_customLoggers = [];
|
|
2747
2763
|
addConsole(enabled = true, level) {
|
|
2748
2764
|
this.console = enabled;
|
|
2749
|
-
if (
|
|
2765
|
+
if (Guards43.isDefined(level)) {
|
|
2750
2766
|
this.level = level;
|
|
2751
2767
|
}
|
|
2752
2768
|
}
|
|
@@ -2763,9 +2779,9 @@ var LoggerModule = class {
|
|
|
2763
2779
|
async configure(container, opts) {
|
|
2764
2780
|
const loggerSetup = new LoggerSetupContext();
|
|
2765
2781
|
loggerSetup.addConsole(opts.console, opts.level);
|
|
2766
|
-
if (!
|
|
2782
|
+
if (!Guards44.isNullOrEmpty(opts.plugins))
|
|
2767
2783
|
opts.plugins.forEach((plugin) => plugin(opts.builder, opts.config, loggerSetup));
|
|
2768
|
-
if (!
|
|
2784
|
+
if (!Guards44.isNullOrEmpty(opts.customLoggers)) {
|
|
2769
2785
|
for (const logger of opts.customLoggers) {
|
|
2770
2786
|
loggerSetup.addCustomLogger((c) => logger(c));
|
|
2771
2787
|
}
|
|
@@ -2780,7 +2796,7 @@ var LoggerModule = class {
|
|
|
2780
2796
|
};
|
|
2781
2797
|
|
|
2782
2798
|
// src/infrastructure/modules/middleware.module.ts
|
|
2783
|
-
import { Guards as
|
|
2799
|
+
import { Guards as Guards54, LOG_LEVEL as LOG_LEVEL6 } from "@xeno-js/shared";
|
|
2784
2800
|
import { TOKENS as TOKENS12 } from "@xeno-js/shared";
|
|
2785
2801
|
|
|
2786
2802
|
// src/presentation/controllers/base.controller.ts
|
|
@@ -2936,7 +2952,7 @@ var MethodCheckMiddleware = class {
|
|
|
2936
2952
|
import {
|
|
2937
2953
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES4,
|
|
2938
2954
|
ERROR_CODES as ERROR_CODES5,
|
|
2939
|
-
Guards as
|
|
2955
|
+
Guards as Guards45,
|
|
2940
2956
|
GuidHelper as GuidHelper7,
|
|
2941
2957
|
HttpHelper as HttpHelper10,
|
|
2942
2958
|
STATUS_CODES as STATUS_CODES6
|
|
@@ -2979,7 +2995,7 @@ var AllowOriginMiddleware = class {
|
|
|
2979
2995
|
return next();
|
|
2980
2996
|
}
|
|
2981
2997
|
checkOrigin(policy, origin) {
|
|
2982
|
-
if (
|
|
2998
|
+
if (Guards45.isDefined(policy.allowOrigins)) {
|
|
2983
2999
|
return policy.allowOrigins.includes("*") || policy.allowOrigins.includes(origin ?? "");
|
|
2984
3000
|
} else {
|
|
2985
3001
|
return this._allowOrigin.isAllowed(origin);
|
|
@@ -3050,7 +3066,7 @@ var CompositeMiddleware = class {
|
|
|
3050
3066
|
};
|
|
3051
3067
|
|
|
3052
3068
|
// src/presentation/middlewares/cookie-response.middleware.ts
|
|
3053
|
-
import { Guards as
|
|
3069
|
+
import { Guards as Guards46 } from "@xeno-js/shared";
|
|
3054
3070
|
import { TOKENS as TOKENS11 } from "@xeno-js/shared";
|
|
3055
3071
|
var CookieResponseMiddleware = class {
|
|
3056
3072
|
constructor(_requestContext) {
|
|
@@ -3060,15 +3076,15 @@ var CookieResponseMiddleware = class {
|
|
|
3060
3076
|
async execute(req, next) {
|
|
3061
3077
|
const response = await next();
|
|
3062
3078
|
const scope = this._requestContext.getScope();
|
|
3063
|
-
if (!
|
|
3079
|
+
if (!Guards46.isDefined(scope)) {
|
|
3064
3080
|
return response;
|
|
3065
3081
|
}
|
|
3066
3082
|
try {
|
|
3067
3083
|
const cookieHandler = scope.resolve(TOKENS11.COOKIE_HANDLER);
|
|
3068
3084
|
const pending = cookieHandler.getPendingCookies();
|
|
3069
|
-
if (!
|
|
3085
|
+
if (!Guards46.isNullOrEmpty(pending)) {
|
|
3070
3086
|
const existingSetCookie = response.headers?.["Set-Cookie"];
|
|
3071
|
-
const mergedCookies =
|
|
3087
|
+
const mergedCookies = Guards46.isArray(existingSetCookie) ? [...existingSetCookie, ...pending] : Guards46.isDefined(existingSetCookie) ? [String(existingSetCookie), ...pending] : [...pending];
|
|
3072
3088
|
response.headers = {
|
|
3073
3089
|
...response?.headers ?? {},
|
|
3074
3090
|
"Set-Cookie": mergedCookies
|
|
@@ -3081,7 +3097,7 @@ var CookieResponseMiddleware = class {
|
|
|
3081
3097
|
};
|
|
3082
3098
|
|
|
3083
3099
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3084
|
-
import { Guards as
|
|
3100
|
+
import { Guards as Guards47 } from "@xeno-js/shared";
|
|
3085
3101
|
var CORSMiddleware = class {
|
|
3086
3102
|
constructor(_requestContext, _getRouteMatcher, _withCredentials = "false") {
|
|
3087
3103
|
this._requestContext = _requestContext;
|
|
@@ -3096,12 +3112,12 @@ var CORSMiddleware = class {
|
|
|
3096
3112
|
const origin = network?.origin;
|
|
3097
3113
|
const response = await next();
|
|
3098
3114
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, req.method);
|
|
3099
|
-
const withCredentials =
|
|
3115
|
+
const withCredentials = Guards47.isDefined(policy.withCredentials) ? policy.withCredentials ? "true" : "false" : this._withCredentials;
|
|
3100
3116
|
const allowOrigins = policy.allowOrigins;
|
|
3101
|
-
if (
|
|
3117
|
+
if (Guards47.isDefined(origin) || Guards47.isDefined(allowOrigins) && allowOrigins.includes("*")) {
|
|
3102
3118
|
response.headers = {
|
|
3103
3119
|
...response?.headers ?? {},
|
|
3104
|
-
"Access-Control-Allow-Origin":
|
|
3120
|
+
"Access-Control-Allow-Origin": Guards47.isDefined(allowOrigins) && allowOrigins.includes("*") && withCredentials === "false" ? "*" : origin,
|
|
3105
3121
|
"Access-Control-Allow-Credentials": withCredentials,
|
|
3106
3122
|
"Vary": "Origin"
|
|
3107
3123
|
};
|
|
@@ -3114,7 +3130,7 @@ var CORSMiddleware = class {
|
|
|
3114
3130
|
import {
|
|
3115
3131
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES5,
|
|
3116
3132
|
ERROR_CODES as ERROR_CODES6,
|
|
3117
|
-
Guards as
|
|
3133
|
+
Guards as Guards48,
|
|
3118
3134
|
GuidHelper as GuidHelper9,
|
|
3119
3135
|
HttpHelper as HttpHelper12,
|
|
3120
3136
|
STATUS_CODES as STATUS_CODES8
|
|
@@ -3133,11 +3149,11 @@ var CsrfMiddleware = class {
|
|
|
3133
3149
|
const isStateChanging = ["POST", "PUT", "DELETE", "PATCH"].includes(method);
|
|
3134
3150
|
if (isStateChanging) {
|
|
3135
3151
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, method);
|
|
3136
|
-
if (
|
|
3152
|
+
if (Guards48.isDefined(policy.withCsrf) && !policy.withCsrf) return await next();
|
|
3137
3153
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3138
3154
|
const headerToken = network?.csrf;
|
|
3139
3155
|
const cookieToken = network?.csrfCookie;
|
|
3140
|
-
if (!
|
|
3156
|
+
if (!Guards48.isDefined(headerToken) || !Guards48.isDefined(cookieToken)) {
|
|
3141
3157
|
return HttpHelper12.error(
|
|
3142
3158
|
{
|
|
3143
3159
|
success: false,
|
|
@@ -3179,7 +3195,7 @@ var CsrfMiddleware = class {
|
|
|
3179
3195
|
}
|
|
3180
3196
|
);
|
|
3181
3197
|
}
|
|
3182
|
-
if (!
|
|
3198
|
+
if (!Guards48.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3183
3199
|
return HttpHelper12.error(
|
|
3184
3200
|
{
|
|
3185
3201
|
success: false,
|
|
@@ -3206,7 +3222,7 @@ var CsrfMiddleware = class {
|
|
|
3206
3222
|
};
|
|
3207
3223
|
|
|
3208
3224
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3209
|
-
import { Guards as
|
|
3225
|
+
import { Guards as Guards49 } from "@xeno-js/shared";
|
|
3210
3226
|
var CsrfCookieMiddleware = class {
|
|
3211
3227
|
constructor(_requestContext, _csrfTokenService, _csrf) {
|
|
3212
3228
|
this._requestContext = _requestContext;
|
|
@@ -3221,8 +3237,8 @@ var CsrfCookieMiddleware = class {
|
|
|
3221
3237
|
const context = this._requestContext.getContext();
|
|
3222
3238
|
const identity = context?.identity;
|
|
3223
3239
|
const network = context?.network;
|
|
3224
|
-
if (!
|
|
3225
|
-
if (
|
|
3240
|
+
if (!Guards49.isDefined(identity?.userId)) return response;
|
|
3241
|
+
if (Guards49.isDefined(network?.csrfCookie)) return response;
|
|
3226
3242
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3227
3243
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3228
3244
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3238,7 +3254,7 @@ var CsrfCookieMiddleware = class {
|
|
|
3238
3254
|
};
|
|
3239
3255
|
|
|
3240
3256
|
// src/presentation/middlewares/options.middleware.ts
|
|
3241
|
-
import { Guards as
|
|
3257
|
+
import { Guards as Guards50, HttpHelper as HttpHelper13, STATUS_CODES as STATUS_CODES9 } from "@xeno-js/shared";
|
|
3242
3258
|
var OptionsMiddleware = class {
|
|
3243
3259
|
constructor(_requestContext, _allowMethod, _getRouteMatcher, _allowHeaders = [], _withCredentials = "false") {
|
|
3244
3260
|
this._requestContext = _requestContext;
|
|
@@ -3258,10 +3274,10 @@ var OptionsMiddleware = class {
|
|
|
3258
3274
|
const origin = network?.origin;
|
|
3259
3275
|
const targetMethod = req.headers.get("access-control-request-method") ?? "GET";
|
|
3260
3276
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, targetMethod);
|
|
3261
|
-
const withCredentials =
|
|
3277
|
+
const withCredentials = Guards50.isDefined(policy.withCredentials) ? policy.withCredentials ? "true" : "false" : this._withCredentials;
|
|
3262
3278
|
const headers = {};
|
|
3263
|
-
if (
|
|
3264
|
-
headers["Access-Control-Allow-Origin"] =
|
|
3279
|
+
if (Guards50.isDefined(origin) || Guards50.isDefined(policy.allowOrigins) && policy.allowOrigins.includes("*")) {
|
|
3280
|
+
headers["Access-Control-Allow-Origin"] = Guards50.isDefined(policy.allowOrigins) && policy.allowOrigins.includes("*") && withCredentials === "false" ? "*" : origin;
|
|
3265
3281
|
headers["Access-Control-Allow-Credentials"] = withCredentials;
|
|
3266
3282
|
headers["Vary"] = "Origin";
|
|
3267
3283
|
}
|
|
@@ -3277,7 +3293,7 @@ var OptionsMiddleware = class {
|
|
|
3277
3293
|
import {
|
|
3278
3294
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES6,
|
|
3279
3295
|
ERROR_CODES as ERROR_CODES7,
|
|
3280
|
-
Guards as
|
|
3296
|
+
Guards as Guards51,
|
|
3281
3297
|
GuidHelper as GuidHelper10,
|
|
3282
3298
|
HttpHelper as HttpHelper14,
|
|
3283
3299
|
STATUS_CODES as STATUS_CODES10
|
|
@@ -3298,7 +3314,7 @@ var RateLimitMiddleware = class {
|
|
|
3298
3314
|
async execute(req, next) {
|
|
3299
3315
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3300
3316
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3301
|
-
if (!
|
|
3317
|
+
if (!Guards51.isDefined(cacheKey))
|
|
3302
3318
|
return HttpHelper14.error(
|
|
3303
3319
|
{
|
|
3304
3320
|
success: false,
|
|
@@ -3358,7 +3374,7 @@ import {
|
|
|
3358
3374
|
} from "@xeno-js/shared";
|
|
3359
3375
|
|
|
3360
3376
|
// src/presentation/mappers/context.mapper.ts
|
|
3361
|
-
import { Guards as
|
|
3377
|
+
import { Guards as Guards52 } from "@xeno-js/shared";
|
|
3362
3378
|
var ContextMapper = Object.freeze({
|
|
3363
3379
|
/**
|
|
3364
3380
|
* @description Maps to RequestContext. It extracts relevant information from the object, such as correlation ID, request ID, authentication token, client IP, user agent, format indicator, and messaging context (if available). The method constructs a RequestContext object that encapsulates all this information, providing a structured representation of the request context for further processing in the application.
|
|
@@ -3399,13 +3415,13 @@ var ContextMapper = Object.freeze({
|
|
|
3399
3415
|
}
|
|
3400
3416
|
});
|
|
3401
3417
|
function _buildMessagingContext(meta) {
|
|
3402
|
-
const hasSequenceData =
|
|
3403
|
-
const hasMessagingData = hasSequenceData ||
|
|
3418
|
+
const hasSequenceData = Guards52.isDefined(meta.sequence?.sequenceId) || Guards52.isDefined(meta.sequence?.position) || Guards52.isDefined(meta.sequence?.size);
|
|
3419
|
+
const hasMessagingData = hasSequenceData || Guards52.isDefined(meta.expiration) || Guards52.isDefined(meta.returnAddress);
|
|
3404
3420
|
if (!hasMessagingData) return void 0;
|
|
3405
3421
|
return {
|
|
3406
3422
|
returnAddress: meta.returnAddress,
|
|
3407
3423
|
expiration: meta.expiration,
|
|
3408
|
-
sequence: hasSequenceData &&
|
|
3424
|
+
sequence: hasSequenceData && Guards52.isDefined(meta.sequence) ? {
|
|
3409
3425
|
sequenceId: meta.sequence.sequenceId,
|
|
3410
3426
|
position: meta.sequence.position,
|
|
3411
3427
|
size: meta.sequence.size
|
|
@@ -3488,7 +3504,7 @@ var RequestContextMiddleware = class {
|
|
|
3488
3504
|
};
|
|
3489
3505
|
|
|
3490
3506
|
// src/infrastructure/http/dispatcher.http.ts
|
|
3491
|
-
import { Guards as
|
|
3507
|
+
import { Guards as Guards53 } from "@xeno-js/shared";
|
|
3492
3508
|
var HttpDispatcher = class {
|
|
3493
3509
|
constructor(_requestContext, _middleware, _serviceProxy) {
|
|
3494
3510
|
this._requestContext = _requestContext;
|
|
@@ -3501,14 +3517,14 @@ var HttpDispatcher = class {
|
|
|
3501
3517
|
async handle(req, token, input) {
|
|
3502
3518
|
return await this._middleware.execute(req, async () => {
|
|
3503
3519
|
const scope = this._requestContext.getScope();
|
|
3504
|
-
if (!
|
|
3520
|
+
if (!Guards53.isDefined(scope)) {
|
|
3505
3521
|
throw new Error(
|
|
3506
3522
|
"[HttpDispatcher Error]: Active scope not found. Execution outside RequestContext."
|
|
3507
3523
|
);
|
|
3508
3524
|
}
|
|
3509
3525
|
const services = this._serviceProxy.getServiceProxy(scope);
|
|
3510
3526
|
const controller = services[token];
|
|
3511
|
-
if (!
|
|
3527
|
+
if (!Guards53.isDefined(controller) || !Guards53.hasMethod(controller, "handle")) {
|
|
3512
3528
|
throw new Error(
|
|
3513
3529
|
`[HttpDispatcher Error]: The provided '${String(token)}' does not implement the 'handle' method.`
|
|
3514
3530
|
);
|
|
@@ -3537,7 +3553,7 @@ var MiddlewareModule = class {
|
|
|
3537
3553
|
)
|
|
3538
3554
|
);
|
|
3539
3555
|
const getRouteMatcher = () => container.resolve(TOKENS12.ROUTE_MATCHER);
|
|
3540
|
-
const withCredentials =
|
|
3556
|
+
const withCredentials = Guards54.isDefined(opts.cors?.withCredentials) && opts.cors?.withCredentials ? "true" : "false";
|
|
3541
3557
|
const [optionsMw, cookieRespMw, corsMw, authMw, csrfMws] = [
|
|
3542
3558
|
this._buildOptionsMiddleware(
|
|
3543
3559
|
opts,
|
|
@@ -3564,7 +3580,7 @@ var MiddlewareModule = class {
|
|
|
3564
3580
|
logger
|
|
3565
3581
|
);
|
|
3566
3582
|
const defaultOrigin = configuration.get("APP_URL") ?? `http://localhost:${configuration.getNumber("PORT", 3e3)}`;
|
|
3567
|
-
const origins = !
|
|
3583
|
+
const origins = !Guards54.isNullOrEmpty(opts.cors?.allowOrigins) ? opts.cors.allowOrigins : [defaultOrigin];
|
|
3568
3584
|
const allowOriginMw = new AllowOriginMiddleware(
|
|
3569
3585
|
new AllowOrigin(origins),
|
|
3570
3586
|
requestContext,
|
|
@@ -3574,14 +3590,14 @@ var MiddlewareModule = class {
|
|
|
3574
3590
|
const methodCheckMw = new MethodCheckMiddleware(requestContext, allowMethod);
|
|
3575
3591
|
const pipeline = [
|
|
3576
3592
|
requestCtxMw,
|
|
3577
|
-
...
|
|
3593
|
+
...Guards54.isDefined(cookieRespMw) ? [cookieRespMw] : [],
|
|
3578
3594
|
allowOriginMw,
|
|
3579
|
-
...
|
|
3580
|
-
...!
|
|
3581
|
-
...
|
|
3582
|
-
...
|
|
3595
|
+
...Guards54.isDefined(optionsMw) && !Guards54.isNullOrEmpty(opts.routes) ? [optionsMw] : [],
|
|
3596
|
+
...!Guards54.isNullOrEmpty(opts.routes) ? [methodCheckMw] : [],
|
|
3597
|
+
...Guards54.isDefined(corsMw) ? [corsMw] : [],
|
|
3598
|
+
...Guards54.isDefined(rateLimitMw) ? [rateLimitMw] : [],
|
|
3583
3599
|
authMw,
|
|
3584
|
-
...!
|
|
3600
|
+
...!Guards54.isNullOrEmpty(csrfMws) ? csrfMws : []
|
|
3585
3601
|
];
|
|
3586
3602
|
container.addSingleton(TOKENS12.MIDDLEWARE, () => new CompositeMiddleware(pipeline));
|
|
3587
3603
|
container.addSingleton(
|
|
@@ -3594,11 +3610,11 @@ var MiddlewareModule = class {
|
|
|
3594
3610
|
);
|
|
3595
3611
|
}
|
|
3596
3612
|
_buildCookieResponseMiddleware(opts, requestContext) {
|
|
3597
|
-
if (!
|
|
3613
|
+
if (!Guards54.isDefined(opts.isSSR) || !opts.isSSR) return void 0;
|
|
3598
3614
|
return new CookieResponseMiddleware(requestContext);
|
|
3599
3615
|
}
|
|
3600
3616
|
_buildCsrfMiddlewares(opts, container, requestContext, routePolicyCheck) {
|
|
3601
|
-
if (!
|
|
3617
|
+
if (!Guards54.isDefined(opts.csrf)) return [];
|
|
3602
3618
|
const csrf = opts.csrf;
|
|
3603
3619
|
container.addSingleton(TOKENS12.CRYPTO_SERVICE, () => new EdgeCryptoService());
|
|
3604
3620
|
container.addSingleton(TOKENS12.CSRF_TOKEN_SERVICE, (c) => {
|
|
@@ -3614,7 +3630,7 @@ var MiddlewareModule = class {
|
|
|
3614
3630
|
];
|
|
3615
3631
|
}
|
|
3616
3632
|
async _buildRateLimitMiddleware(opts, container, requestContext, logger) {
|
|
3617
|
-
if (
|
|
3633
|
+
if (Guards54.isDefined(opts.rateLimit?.enabled) && opts.rateLimit?.enabled) {
|
|
3618
3634
|
const maxRequests = opts.rateLimit?.maxRequests ?? 100;
|
|
3619
3635
|
const windowSeconds = opts.rateLimit?.windowSeconds ?? 60;
|
|
3620
3636
|
if (!container.isRegistered(TOKENS12.CACHE)) {
|
|
@@ -3630,12 +3646,12 @@ var MiddlewareModule = class {
|
|
|
3630
3646
|
}
|
|
3631
3647
|
}
|
|
3632
3648
|
_buildCorsMiddleware(opts, requestContext, withCredentials, routePolicyCheck) {
|
|
3633
|
-
if (
|
|
3649
|
+
if (Guards54.isDefined(opts.cors?.enabled) && opts.cors.enabled) {
|
|
3634
3650
|
return new CORSMiddleware(requestContext, routePolicyCheck, withCredentials);
|
|
3635
3651
|
}
|
|
3636
3652
|
}
|
|
3637
3653
|
_buildOptionsMiddleware(opts, requestContext, allowMethod, withCredentials, routePolicyCheck) {
|
|
3638
|
-
if (
|
|
3654
|
+
if (Guards54.isDefined(opts.cors?.enablePreflight) && opts.cors?.enablePreflight) {
|
|
3639
3655
|
const allowHeaders = Array.from(
|
|
3640
3656
|
/* @__PURE__ */ new Set([
|
|
3641
3657
|
"x-csrf-token",
|
|
@@ -3687,7 +3703,7 @@ var MiddlewareModule = class {
|
|
|
3687
3703
|
tokenExtractor,
|
|
3688
3704
|
new GateKeeper(() => {
|
|
3689
3705
|
const scope = requestContext.getScope();
|
|
3690
|
-
if (!
|
|
3706
|
+
if (!Guards54.isDefined(scope)) {
|
|
3691
3707
|
throw new Error("[GateKeeper Error]: No active scope found.");
|
|
3692
3708
|
}
|
|
3693
3709
|
return scope.resolve(TOKENS12.BASE_AUTH_SERVICE);
|
|
@@ -3760,12 +3776,12 @@ var withAuth = (setup) => {
|
|
|
3760
3776
|
};
|
|
3761
3777
|
|
|
3762
3778
|
// src/infrastructure/plugin/authz.plugin.ts
|
|
3763
|
-
import { Guards as
|
|
3779
|
+
import { Guards as Guards55 } from "@xeno-js/shared";
|
|
3764
3780
|
var withAuthZ = (setup) => {
|
|
3765
3781
|
return definePlugin(
|
|
3766
3782
|
"pipeline",
|
|
3767
3783
|
(_builder, config, context) => {
|
|
3768
|
-
if (!
|
|
3784
|
+
if (!Guards55.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
3769
3785
|
const options = {
|
|
3770
3786
|
policies: void 0
|
|
3771
3787
|
};
|
|
@@ -3777,25 +3793,25 @@ var withAuthZ = (setup) => {
|
|
|
3777
3793
|
|
|
3778
3794
|
// src/infrastructure/plugin/concurrency.plugin.ts
|
|
3779
3795
|
import {
|
|
3780
|
-
Guards as
|
|
3796
|
+
Guards as Guards56
|
|
3781
3797
|
} from "@xeno-js/shared";
|
|
3782
3798
|
var withConcurrency = (setup) => {
|
|
3783
3799
|
return definePlugin(
|
|
3784
3800
|
"pipeline",
|
|
3785
3801
|
(_builder, config, context) => {
|
|
3786
|
-
if (!
|
|
3802
|
+
if (!Guards56.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
3787
3803
|
const options = {};
|
|
3788
|
-
if (
|
|
3804
|
+
if (Guards56.isDefined(setup)) setup(options, config);
|
|
3789
3805
|
context.addCommand(new ConcurrencyRetryPipeline(options), 70);
|
|
3790
3806
|
}
|
|
3791
3807
|
);
|
|
3792
3808
|
};
|
|
3793
3809
|
|
|
3794
3810
|
// src/infrastructure/plugin/http.plugin.ts
|
|
3795
|
-
import { Guards as
|
|
3811
|
+
import { Guards as Guards59 } from "@xeno-js/shared";
|
|
3796
3812
|
|
|
3797
3813
|
// src/infrastructure/modules/http-core.module.ts
|
|
3798
|
-
import { Guards as
|
|
3814
|
+
import { Guards as Guards58 } from "@xeno-js/shared";
|
|
3799
3815
|
import { TOKENS as TOKENS14 } from "@xeno-js/shared";
|
|
3800
3816
|
|
|
3801
3817
|
// src/infrastructure/datasources/remote.datasource.ts
|
|
@@ -3884,7 +3900,7 @@ var RemoteDataSource = class {
|
|
|
3884
3900
|
};
|
|
3885
3901
|
|
|
3886
3902
|
// src/infrastructure/factories/http.factory.ts
|
|
3887
|
-
import { AppError as AppError15, Guards as
|
|
3903
|
+
import { AppError as AppError15, Guards as Guards57 } from "@xeno-js/shared";
|
|
3888
3904
|
var HttpClientFactory = class {
|
|
3889
3905
|
_clients = /* @__PURE__ */ new Map();
|
|
3890
3906
|
add(name, client) {
|
|
@@ -3895,7 +3911,7 @@ var HttpClientFactory = class {
|
|
|
3895
3911
|
}
|
|
3896
3912
|
get(name = "default") {
|
|
3897
3913
|
const client = this._clients.get(name);
|
|
3898
|
-
if (!
|
|
3914
|
+
if (!Guards57.isDefined(client)) {
|
|
3899
3915
|
const available = Array.from(this._clients.keys()).join(", ") ?? "none";
|
|
3900
3916
|
throw AppError15.notFound(
|
|
3901
3917
|
"HttpClientFactory",
|
|
@@ -3928,7 +3944,7 @@ var HttpCoreModule = class {
|
|
|
3928
3944
|
container.addSingleton(TOKENS14.HTTP_CLIENT_FACTORY, () => factory);
|
|
3929
3945
|
}
|
|
3930
3946
|
getResilienceService(container, resilience) {
|
|
3931
|
-
if (!
|
|
3947
|
+
if (!Guards58.isDefined(resilience)) {
|
|
3932
3948
|
return new NoOpResilienceService();
|
|
3933
3949
|
} else {
|
|
3934
3950
|
return resilience(container);
|
|
@@ -3941,9 +3957,9 @@ var withCustomHttp = (config) => {
|
|
|
3941
3957
|
return definePlugin(
|
|
3942
3958
|
"http",
|
|
3943
3959
|
(builder, _config) => {
|
|
3944
|
-
const clientEntries =
|
|
3960
|
+
const clientEntries = Guards59.isArray(config.clients) ? config.clients : [config.clients];
|
|
3945
3961
|
const entries = clientEntries.map((item) => {
|
|
3946
|
-
if (!
|
|
3962
|
+
if (!Guards59.isDefined(item.client)) {
|
|
3947
3963
|
throw new Error(
|
|
3948
3964
|
`[withCustomHttp Error]: 'client' instance is required for registration '${item.name ?? "default"}'.`
|
|
3949
3965
|
);
|
|
@@ -3963,27 +3979,27 @@ var withCustomHttp = (config) => {
|
|
|
3963
3979
|
|
|
3964
3980
|
// src/infrastructure/plugin/idempotency.plugin.ts
|
|
3965
3981
|
import {
|
|
3966
|
-
Guards as
|
|
3982
|
+
Guards as Guards60
|
|
3967
3983
|
} from "@xeno-js/shared";
|
|
3968
3984
|
var withIdempotency = (setup) => {
|
|
3969
3985
|
return definePlugin(
|
|
3970
3986
|
"pipeline",
|
|
3971
3987
|
(_builder, config, context) => {
|
|
3972
|
-
if (!
|
|
3988
|
+
if (!Guards60.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
3973
3989
|
const options = {};
|
|
3974
|
-
if (
|
|
3990
|
+
if (Guards60.isDefined(setup)) setup(options, config);
|
|
3975
3991
|
context.idempotencyOpts = options;
|
|
3976
3992
|
}
|
|
3977
3993
|
);
|
|
3978
3994
|
};
|
|
3979
3995
|
|
|
3980
3996
|
// src/infrastructure/plugin/logger.plugin.ts
|
|
3981
|
-
import { Guards as
|
|
3997
|
+
import { Guards as Guards61, LOG_LEVEL as LOG_LEVEL7 } from "@xeno-js/shared";
|
|
3982
3998
|
var withConsoleLogger = (setup) => {
|
|
3983
3999
|
return definePlugin(
|
|
3984
4000
|
"logger",
|
|
3985
4001
|
(_builder, config, ctx) => {
|
|
3986
|
-
if (!
|
|
4002
|
+
if (!Guards61.isDefined(ctx)) throw new Error("LoggerSetup is not defined.");
|
|
3987
4003
|
const options = {
|
|
3988
4004
|
isEnabled: true,
|
|
3989
4005
|
level: LOG_LEVEL7.DEBUG
|
|
@@ -3996,16 +4012,16 @@ var withConsoleLogger = (setup) => {
|
|
|
3996
4012
|
|
|
3997
4013
|
// src/infrastructure/plugin/performance.plugin.ts
|
|
3998
4014
|
import {
|
|
3999
|
-
Guards as
|
|
4015
|
+
Guards as Guards62
|
|
4000
4016
|
} from "@xeno-js/shared";
|
|
4001
4017
|
import { TOKENS as TOKENS15 } from "@xeno-js/shared";
|
|
4002
4018
|
var withPerformance = (setup) => {
|
|
4003
4019
|
return definePlugin(
|
|
4004
4020
|
"pipeline",
|
|
4005
4021
|
(builder, config, context) => {
|
|
4006
|
-
if (!
|
|
4022
|
+
if (!Guards62.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4007
4023
|
const options = {};
|
|
4008
|
-
if (
|
|
4024
|
+
if (Guards62.isDefined(setup)) setup(options, config);
|
|
4009
4025
|
const logger = builder.resolve(TOKENS15.LOGGER);
|
|
4010
4026
|
context.addCommon(
|
|
4011
4027
|
new PerformancePipeline(logger, options?.intentThresholdMs, options?.thresholdMs ?? 500),
|
|
@@ -4016,12 +4032,12 @@ var withPerformance = (setup) => {
|
|
|
4016
4032
|
};
|
|
4017
4033
|
|
|
4018
4034
|
// src/infrastructure/plugin/query.plugin.ts
|
|
4019
|
-
import { Guards as
|
|
4035
|
+
import { Guards as Guards63 } from "@xeno-js/shared";
|
|
4020
4036
|
var withQueryCaching = () => {
|
|
4021
4037
|
return definePlugin(
|
|
4022
4038
|
"pipeline",
|
|
4023
4039
|
(_builder, _config, context) => {
|
|
4024
|
-
if (!
|
|
4040
|
+
if (!Guards63.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4025
4041
|
context.addQuery();
|
|
4026
4042
|
}
|
|
4027
4043
|
);
|
|
@@ -4029,16 +4045,16 @@ var withQueryCaching = () => {
|
|
|
4029
4045
|
|
|
4030
4046
|
// src/infrastructure/plugin/validation.plugin.ts
|
|
4031
4047
|
import {
|
|
4032
|
-
Guards as
|
|
4048
|
+
Guards as Guards64
|
|
4033
4049
|
} from "@xeno-js/shared";
|
|
4034
4050
|
var withValidation = (setup) => {
|
|
4035
4051
|
return definePlugin(
|
|
4036
4052
|
"pipeline",
|
|
4037
4053
|
(_builder, config, context) => {
|
|
4038
|
-
if (!
|
|
4054
|
+
if (!Guards64.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4039
4055
|
const strategies = [];
|
|
4040
4056
|
setup(strategies, config);
|
|
4041
|
-
if (
|
|
4057
|
+
if (Guards64.isNullOrEmpty(strategies)) return;
|
|
4042
4058
|
const validationPipeline = new ValidationPipeline(strategies);
|
|
4043
4059
|
context.addCommon(validationPipeline, 50);
|
|
4044
4060
|
}
|
|
@@ -4046,7 +4062,7 @@ var withValidation = (setup) => {
|
|
|
4046
4062
|
};
|
|
4047
4063
|
|
|
4048
4064
|
// src/infrastructure/xeno_application/xeno.application.ts
|
|
4049
|
-
import { AppError as AppError17, Guards as
|
|
4065
|
+
import { AppError as AppError17, Guards as Guards65, GUEST as GUEST5, GuidHelper as GuidHelper13 } from "@xeno-js/shared";
|
|
4050
4066
|
import { TOKENS as TOKENS16 } from "@xeno-js/shared";
|
|
4051
4067
|
var XenoApplication = class {
|
|
4052
4068
|
constructor(_container) {
|
|
@@ -4073,7 +4089,7 @@ var XenoApplication = class {
|
|
|
4073
4089
|
const serviceProxy = this._container.resolve(TOKENS16.SERVICE_PROXY);
|
|
4074
4090
|
const requestContext = this._container.resolve(TOKENS16.REQUEST_CONTEXT);
|
|
4075
4091
|
const scope = requestContext.getScope();
|
|
4076
|
-
if (!
|
|
4092
|
+
if (!Guards65.isDefined(scope)) {
|
|
4077
4093
|
throw AppError17.notFound(
|
|
4078
4094
|
"[XenoApplication Error]",
|
|
4079
4095
|
'Active scope not found.\nPlease use the "runInScope" or "handle" method for tasks outside the HTTP transport.'
|
|
@@ -4150,7 +4166,7 @@ var XenoAppBuilder = class {
|
|
|
4150
4166
|
this._container.addSingleton(TOKENS17.CONFIGURATION_SERVICE, () => this._configuration);
|
|
4151
4167
|
}
|
|
4152
4168
|
_getConfigurationService(service) {
|
|
4153
|
-
if (!
|
|
4169
|
+
if (!Guards66.isDefined(service) || service === "node")
|
|
4154
4170
|
return new EnvironmentConfigurationService();
|
|
4155
4171
|
if (service === "vite") return new ViteConfigurationService();
|
|
4156
4172
|
return service;
|
|
@@ -4238,7 +4254,7 @@ var XenoAppBuilder = class {
|
|
|
4238
4254
|
*/
|
|
4239
4255
|
addMiddlewares(setupAction) {
|
|
4240
4256
|
if (this._isMiddlewareModuleQueued) return this;
|
|
4241
|
-
if (
|
|
4257
|
+
if (Guards66.isDefined(setupAction)) setupAction(this._middlewareConfig, this._configuration);
|
|
4242
4258
|
this._modules.push({
|
|
4243
4259
|
priority: 4,
|
|
4244
4260
|
name: "MiddlewareModule",
|
|
@@ -4264,7 +4280,7 @@ var XenoAppBuilder = class {
|
|
|
4264
4280
|
*/
|
|
4265
4281
|
addContext(plugin) {
|
|
4266
4282
|
if (this._isContextModuleQueued) return this;
|
|
4267
|
-
if (
|
|
4283
|
+
if (Guards66.isDefined(plugin)) plugin(this, this._configuration);
|
|
4268
4284
|
else
|
|
4269
4285
|
this._modules.push({
|
|
4270
4286
|
priority: 0,
|
|
@@ -4279,7 +4295,7 @@ var XenoAppBuilder = class {
|
|
|
4279
4295
|
}
|
|
4280
4296
|
addLogger(pluginOrSetup) {
|
|
4281
4297
|
if (this._isLoggerModuleQueued) return this;
|
|
4282
|
-
if (!
|
|
4298
|
+
if (!Guards66.isDefined(pluginOrSetup)) {
|
|
4283
4299
|
this._modules.push({
|
|
4284
4300
|
priority: 1,
|
|
4285
4301
|
name: "LoggerModule",
|
|
@@ -4293,7 +4309,7 @@ var XenoAppBuilder = class {
|
|
|
4293
4309
|
});
|
|
4294
4310
|
}
|
|
4295
4311
|
});
|
|
4296
|
-
} else if (
|
|
4312
|
+
} else if (Guards66.isArray(pluginOrSetup)) {
|
|
4297
4313
|
this._modules.push({
|
|
4298
4314
|
priority: 1,
|
|
4299
4315
|
name: "LoggerModule",
|
|
@@ -4347,7 +4363,7 @@ var XenoAppBuilder = class {
|
|
|
4347
4363
|
}
|
|
4348
4364
|
addCache(pluginOrSetup) {
|
|
4349
4365
|
if (this._isCacheModuleQueued) return this;
|
|
4350
|
-
if (!
|
|
4366
|
+
if (!Guards66.isDefined(pluginOrSetup))
|
|
4351
4367
|
this._modules.push({
|
|
4352
4368
|
priority: 2,
|
|
4353
4369
|
name: "CacheModule",
|
|
@@ -4444,8 +4460,8 @@ var XenoAppBuilder = class {
|
|
|
4444
4460
|
*/
|
|
4445
4461
|
addPipeline(pluginOrPlugins) {
|
|
4446
4462
|
if (this._isPipelineModuleQueued) return this;
|
|
4447
|
-
if (
|
|
4448
|
-
this._pipelinePlugins =
|
|
4463
|
+
if (Guards66.isDefined(pluginOrPlugins))
|
|
4464
|
+
this._pipelinePlugins = Guards66.isArray(pluginOrPlugins) ? pluginOrPlugins : [pluginOrPlugins];
|
|
4449
4465
|
this._modules.push({
|
|
4450
4466
|
priority: 5,
|
|
4451
4467
|
name: "CqrsModule",
|
|
@@ -4546,7 +4562,7 @@ var XenoAppBuilder = class {
|
|
|
4546
4562
|
* @link https://github.com/xeno-js/xeno-js
|
|
4547
4563
|
*/
|
|
4548
4564
|
build() {
|
|
4549
|
-
if (
|
|
4565
|
+
if (Guards66.isDefined(this._buildPromise)) {
|
|
4550
4566
|
return this._buildPromise;
|
|
4551
4567
|
}
|
|
4552
4568
|
const attempt = this._executeBuild();
|
|
@@ -4592,21 +4608,21 @@ var XenoAppBuilder = class {
|
|
|
4592
4608
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
4593
4609
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
4594
4610
|
`);
|
|
4595
|
-
if (error instanceof Error &&
|
|
4611
|
+
if (error instanceof Error && Guards66.isDefined(error.stack)) {
|
|
4596
4612
|
console.error(error.stack);
|
|
4597
4613
|
}
|
|
4598
4614
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
4599
4615
|
}
|
|
4600
4616
|
}
|
|
4601
4617
|
console.info("\u2705 Application modules bootstrapped successfully.");
|
|
4602
|
-
if (
|
|
4618
|
+
if (Guards66.isDefined(this._appFactory)) return this._appFactory(this._container);
|
|
4603
4619
|
return new XenoApplication(this._container);
|
|
4604
4620
|
}
|
|
4605
4621
|
};
|
|
4606
4622
|
|
|
4607
4623
|
// src/infrastructure/repositories/read-dao.ts
|
|
4608
4624
|
import { AppError as AppError18, Result as Result18 } from "@xeno-js/shared";
|
|
4609
|
-
import { Guards as
|
|
4625
|
+
import { Guards as Guards67 } from "@xeno-js/shared";
|
|
4610
4626
|
var ReadDao = class {
|
|
4611
4627
|
/**
|
|
4612
4628
|
* Constructs a new ReadDao instance.
|
|
@@ -4628,7 +4644,7 @@ var ReadDao = class {
|
|
|
4628
4644
|
async findById(id, ctx, signal) {
|
|
4629
4645
|
AppError18.throwIfAborted(signal, "ReadDao.findById");
|
|
4630
4646
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
4631
|
-
if (
|
|
4647
|
+
if (Guards67.isNullOrEmpty(result)) return Result18.ok();
|
|
4632
4648
|
const entity = this._mapper.toEntity(result);
|
|
4633
4649
|
return Result18.ok(entity);
|
|
4634
4650
|
}
|
|
@@ -4642,7 +4658,7 @@ var ReadDao = class {
|
|
|
4642
4658
|
|
|
4643
4659
|
// src/infrastructure/repositories/repository.ts
|
|
4644
4660
|
import { AppError as AppError19, Result as Result19 } from "@xeno-js/shared";
|
|
4645
|
-
import { Guards as
|
|
4661
|
+
import { Guards as Guards68 } from "@xeno-js/shared";
|
|
4646
4662
|
var Repository = class {
|
|
4647
4663
|
/**
|
|
4648
4664
|
* Constructs a new Repository instance.
|
|
@@ -4664,7 +4680,7 @@ var Repository = class {
|
|
|
4664
4680
|
async findById(id, ctx, signal) {
|
|
4665
4681
|
AppError19.throwIfAborted(signal, "Repository.findById");
|
|
4666
4682
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
4667
|
-
if (
|
|
4683
|
+
if (Guards68.isNullOrEmpty(result)) return Result19.ok();
|
|
4668
4684
|
const entity = this._mapper.toEntity(result);
|
|
4669
4685
|
return Result19.ok(entity);
|
|
4670
4686
|
}
|