@xeno-js/core 4.1.2 → 4.1.4
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 +20 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +243 -228
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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.
|
|
@@ -1696,8 +1712,8 @@ var HttpHeaderExtractor = class {
|
|
|
1696
1712
|
const clientIp = headers.get(this._trustedIp?.toLowerCase() ?? "x-forwarded-for") ?? headers.get("x-real-ip") ?? void 0;
|
|
1697
1713
|
const spanId = GuidHelper4.parse(headers.get("x-span-id") ?? void 0);
|
|
1698
1714
|
const parentSpanId = headers.get("x-parent-span-id") ?? void 0;
|
|
1699
|
-
const acceptHeader = headers.get("accept");
|
|
1700
|
-
const contentTypeHeader = headers.get("content-type");
|
|
1715
|
+
const acceptHeader = headers.get("accept") ?? void 0;
|
|
1716
|
+
const contentTypeHeader = headers.get("content-type") ?? void 0;
|
|
1701
1717
|
const userAgent = headers.get("user-agent") ?? void 0;
|
|
1702
1718
|
const returnAddress = headers.get("x-return-address") ?? void 0;
|
|
1703
1719
|
const sequenceId = headers.get("x-sequence-id") ?? void 0;
|
|
@@ -1714,8 +1730,7 @@ var HttpHeaderExtractor = class {
|
|
|
1714
1730
|
const cleanOrigin = HttpHelper5.sanitizeOriginUrl(origin);
|
|
1715
1731
|
const referer = headers.get("referer") ?? void 0;
|
|
1716
1732
|
const cleanReferer = HttpHelper5.sanitizeOriginUrl(referer);
|
|
1717
|
-
const
|
|
1718
|
-
const formatIndicator = accept ?? contentTypeHeader ?? "application/json";
|
|
1733
|
+
const formatIndicator = HttpHelper5.resolveFormatIndicator(acceptHeader, contentTypeHeader);
|
|
1719
1734
|
const metadata = {
|
|
1720
1735
|
correlationId,
|
|
1721
1736
|
requestId,
|
|
@@ -1732,17 +1747,17 @@ var HttpHeaderExtractor = class {
|
|
|
1732
1747
|
referer: cleanReferer,
|
|
1733
1748
|
sequence: {
|
|
1734
1749
|
sequenceId,
|
|
1735
|
-
position:
|
|
1736
|
-
size:
|
|
1750
|
+
position: Guards21.isDefined(position) ? MathHelper.toNumber(position) : void 0,
|
|
1751
|
+
size: Guards21.isDefined(size) ? MathHelper.toNumber(size) : void 0
|
|
1737
1752
|
},
|
|
1738
|
-
expiration:
|
|
1753
|
+
expiration: Guards21.isDefined(expiration) ? MathHelper.toNumber(expiration) : void 0
|
|
1739
1754
|
};
|
|
1740
1755
|
return metadata;
|
|
1741
1756
|
}
|
|
1742
1757
|
};
|
|
1743
1758
|
|
|
1744
1759
|
// src/infrastructure/services/resolver/client-ip.resolver.ts
|
|
1745
|
-
import { Guards as
|
|
1760
|
+
import { Guards as Guards22 } from "@xeno-js/shared";
|
|
1746
1761
|
var ClientIpResolver = class {
|
|
1747
1762
|
constructor(_trustedProxies = []) {
|
|
1748
1763
|
this._trustedProxies = _trustedProxies;
|
|
@@ -1750,11 +1765,11 @@ var ClientIpResolver = class {
|
|
|
1750
1765
|
_trustedProxies;
|
|
1751
1766
|
resolve(req, clientIp) {
|
|
1752
1767
|
const socketIp = req.socket?.remoteAddress;
|
|
1753
|
-
if (!
|
|
1754
|
-
return !
|
|
1768
|
+
if (!Guards22.isDefined(socketIp))
|
|
1769
|
+
return !Guards22.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
1755
1770
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
1756
1771
|
if (!isTrustedProxy) return socketIp;
|
|
1757
|
-
if (
|
|
1772
|
+
if (Guards22.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
1758
1773
|
return socketIp;
|
|
1759
1774
|
}
|
|
1760
1775
|
};
|
|
@@ -1762,17 +1777,17 @@ var ClientIpResolver = class {
|
|
|
1762
1777
|
// src/infrastructure/modules/auth.module.ts
|
|
1763
1778
|
var AuthModule = class {
|
|
1764
1779
|
async configure(container, opts) {
|
|
1765
|
-
if (!
|
|
1780
|
+
if (!Guards23.isDefined(opts.authService))
|
|
1766
1781
|
throw new Error(
|
|
1767
1782
|
"[AuthModule Error]: An authService instance is required to configure AuthModule."
|
|
1768
1783
|
);
|
|
1769
|
-
if (
|
|
1770
|
-
if (
|
|
1784
|
+
if (Guards23.isDefined(opts.cookieHandlerOptions)) {
|
|
1785
|
+
if (Guards23.isDefined(opts.cookieHandlerOptions.cookieHandlerCustom)) {
|
|
1771
1786
|
container.addScoped(
|
|
1772
1787
|
TOKENS2.COOKIE_HANDLER,
|
|
1773
1788
|
(c) => opts.cookieHandlerOptions.cookieHandlerCustom(c)
|
|
1774
1789
|
);
|
|
1775
|
-
} else if (
|
|
1790
|
+
} else if (Guards23.isDefined(opts.cookieHandlerOptions.enableDefault) && opts.cookieHandlerOptions.enableDefault.enable) {
|
|
1776
1791
|
container.addScoped(
|
|
1777
1792
|
TOKENS2.COOKIE_HANDLER,
|
|
1778
1793
|
(c) => new CookieHandler(
|
|
@@ -1788,7 +1803,7 @@ var AuthModule = class {
|
|
|
1788
1803
|
container.addScoped(TOKENS2.BASE_AUTH_SERVICE, (c) => c.resolve(TOKENS2.AUTH_SERVICE));
|
|
1789
1804
|
}
|
|
1790
1805
|
getExtractor(opts, container) {
|
|
1791
|
-
if (
|
|
1806
|
+
if (Guards23.isDefined(opts.tokenExtractor)) {
|
|
1792
1807
|
container.addSingleton(TOKENS2.TOKEN_SERVICE_EXTRACTOR, (c) => opts.tokenExtractor(c));
|
|
1793
1808
|
} else {
|
|
1794
1809
|
container.addSingleton(
|
|
@@ -1800,10 +1815,10 @@ var AuthModule = class {
|
|
|
1800
1815
|
};
|
|
1801
1816
|
|
|
1802
1817
|
// src/infrastructure/modules/cache.module.ts
|
|
1803
|
-
import { Guards as
|
|
1818
|
+
import { Guards as Guards30, TOKENS as TOKENS6 } from "@xeno-js/shared";
|
|
1804
1819
|
|
|
1805
1820
|
// src/infrastructure/cache/inmemory.cache.ts
|
|
1806
|
-
import { Guards as
|
|
1821
|
+
import { Guards as Guards24, StringHelper as StringHelper2 } from "@xeno-js/shared";
|
|
1807
1822
|
var InMemoryCache = class {
|
|
1808
1823
|
/**
|
|
1809
1824
|
* @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 +1840,21 @@ var InMemoryCache = class {
|
|
|
1825
1840
|
_cache;
|
|
1826
1841
|
_cleanupInterval;
|
|
1827
1842
|
_isNodeTimeout(timer) {
|
|
1828
|
-
return
|
|
1843
|
+
return Guards24.isDefined(timer) && Guards24.isObject(timer) && Guards24.hasMethod(timer, "unref");
|
|
1829
1844
|
}
|
|
1830
1845
|
async get(key) {
|
|
1831
1846
|
const entry = this._cache.get(key);
|
|
1832
|
-
if (!
|
|
1847
|
+
if (!Guards24.isDefined(entry)) {
|
|
1833
1848
|
return void 0;
|
|
1834
1849
|
}
|
|
1835
|
-
if (
|
|
1850
|
+
if (Guards24.isDefined(entry.expiresAt) && entry.expiresAt < Date.now()) {
|
|
1836
1851
|
this._cache.delete(key);
|
|
1837
1852
|
return void 0;
|
|
1838
1853
|
}
|
|
1839
1854
|
return JSON.parse(entry.value);
|
|
1840
1855
|
}
|
|
1841
1856
|
async set(key, value, ttl) {
|
|
1842
|
-
const expiresAt =
|
|
1857
|
+
const expiresAt = Guards24.isDefined(ttl) ? Date.now() + ttl * 1e3 : void 0;
|
|
1843
1858
|
this._cache.set(key, { value: StringHelper2.safeStringify(value), expiresAt });
|
|
1844
1859
|
}
|
|
1845
1860
|
async setIfAbsent(key, value, ttl) {
|
|
@@ -1854,10 +1869,10 @@ var InMemoryCache = class {
|
|
|
1854
1869
|
}
|
|
1855
1870
|
async has(key) {
|
|
1856
1871
|
const entry = this._cache.get(key);
|
|
1857
|
-
if (!
|
|
1872
|
+
if (!Guards24.isDefined(entry)) {
|
|
1858
1873
|
return false;
|
|
1859
1874
|
}
|
|
1860
|
-
if (
|
|
1875
|
+
if (Guards24.isDefined(entry.expiresAt) && entry.expiresAt < Date.now()) {
|
|
1861
1876
|
this._cache.delete(key);
|
|
1862
1877
|
return false;
|
|
1863
1878
|
}
|
|
@@ -1869,7 +1884,7 @@ var InMemoryCache = class {
|
|
|
1869
1884
|
async increment(key, ttlSeconds) {
|
|
1870
1885
|
const entry = this._cache.get(key);
|
|
1871
1886
|
const now = Date.now();
|
|
1872
|
-
if (
|
|
1887
|
+
if (Guards24.isDefined(entry) && (!Guards24.isDefined(entry.expiresAt) || entry.expiresAt > now)) {
|
|
1873
1888
|
const nextValue = Number(StringHelper2.safeParse(entry.value)) + 1;
|
|
1874
1889
|
this._cache.set(key, {
|
|
1875
1890
|
value: StringHelper2.safeStringify(nextValue),
|
|
@@ -1877,7 +1892,7 @@ var InMemoryCache = class {
|
|
|
1877
1892
|
});
|
|
1878
1893
|
return nextValue;
|
|
1879
1894
|
}
|
|
1880
|
-
const ttl = !
|
|
1895
|
+
const ttl = !Guards24.isNullOrEmpty(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
1881
1896
|
const expiresAt = now + ttl * 1e3;
|
|
1882
1897
|
this._cache.set(key, { value: StringHelper2.safeStringify(1), expiresAt });
|
|
1883
1898
|
return 1;
|
|
@@ -1885,7 +1900,7 @@ var InMemoryCache = class {
|
|
|
1885
1900
|
evictExpired() {
|
|
1886
1901
|
const now = Date.now();
|
|
1887
1902
|
for (const [key, entry] of this._cache.entries()) {
|
|
1888
|
-
if (!
|
|
1903
|
+
if (!Guards24.isDefined(entry.expiresAt) || entry.expiresAt > now) {
|
|
1889
1904
|
this._cache.delete(key);
|
|
1890
1905
|
}
|
|
1891
1906
|
}
|
|
@@ -1907,7 +1922,7 @@ var InMemoryCache = class {
|
|
|
1907
1922
|
};
|
|
1908
1923
|
|
|
1909
1924
|
// src/infrastructure/cache/key-builder.cache.ts
|
|
1910
|
-
import { Guards as
|
|
1925
|
+
import { Guards as Guards25 } from "@xeno-js/shared";
|
|
1911
1926
|
var CacheKeyBuilder = class {
|
|
1912
1927
|
/**
|
|
1913
1928
|
* @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 +1939,14 @@ var CacheKeyBuilder = class {
|
|
|
1924
1939
|
_identityAccessor;
|
|
1925
1940
|
buildContextualKey(key) {
|
|
1926
1941
|
const identity = this._identityAccessor.getIdentity();
|
|
1927
|
-
if (
|
|
1942
|
+
if (Guards25.isDefined(identity) && !Guards25.isNullOrEmpty(identity.tenantId)) {
|
|
1928
1943
|
return `tenant:${identity.tenantId}:${key}`;
|
|
1929
1944
|
}
|
|
1930
1945
|
return `${key}:public`;
|
|
1931
1946
|
}
|
|
1932
1947
|
buildUserScopedKey(key) {
|
|
1933
1948
|
const identity = this._identityAccessor.getIdentity();
|
|
1934
|
-
if (
|
|
1949
|
+
if (Guards25.isDefined(identity) && !Guards25.isNullOrEmpty(identity.userId)) {
|
|
1935
1950
|
return this.buildContextualKey(`user:${identity.userId}:${key}`);
|
|
1936
1951
|
}
|
|
1937
1952
|
return this.buildContextualKey(key);
|
|
@@ -1939,7 +1954,7 @@ var CacheKeyBuilder = class {
|
|
|
1939
1954
|
};
|
|
1940
1955
|
|
|
1941
1956
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
1942
|
-
import { Guards as
|
|
1957
|
+
import { Guards as Guards26 } from "@xeno-js/shared";
|
|
1943
1958
|
var RateLimitKeyBuilder = class {
|
|
1944
1959
|
constructor(_contextAccessor) {
|
|
1945
1960
|
this._contextAccessor = _contextAccessor;
|
|
@@ -1950,18 +1965,18 @@ var RateLimitKeyBuilder = class {
|
|
|
1950
1965
|
const tenantId = ctx?.identity?.tenantId;
|
|
1951
1966
|
const userId = ctx?.identity?.userId;
|
|
1952
1967
|
const clientIp = ctx?.network?.clientIp;
|
|
1953
|
-
if (!
|
|
1968
|
+
if (!Guards26.isNullOrEmpty(tenantId) && !Guards26.isNullOrEmpty(userId))
|
|
1954
1969
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
1955
|
-
if (!
|
|
1970
|
+
if (!Guards26.isNullOrEmpty(tenantId) && !Guards26.isNullOrEmpty(clientIp))
|
|
1956
1971
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
1957
|
-
if (!
|
|
1958
|
-
if (!
|
|
1972
|
+
if (!Guards26.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
1973
|
+
if (!Guards26.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
1959
1974
|
return void 0;
|
|
1960
1975
|
}
|
|
1961
1976
|
};
|
|
1962
1977
|
|
|
1963
1978
|
// src/infrastructure/modules/utils/auth.utils.ts
|
|
1964
|
-
import { Guards as
|
|
1979
|
+
import { Guards as Guards27 } from "@xeno-js/shared";
|
|
1965
1980
|
import {
|
|
1966
1981
|
TOKENS as TOKENS3
|
|
1967
1982
|
} from "@xeno-js/shared";
|
|
@@ -1978,7 +1993,7 @@ var AuthUtils = Object.freeze({
|
|
|
1978
1993
|
*/
|
|
1979
1994
|
async addAuthZ(container, opts) {
|
|
1980
1995
|
const strategies = [];
|
|
1981
|
-
if (
|
|
1996
|
+
if (Guards27.isDefined(opts.policies)) {
|
|
1982
1997
|
const policyRegistry = opts.policies;
|
|
1983
1998
|
const registryInstance = new PolicyRegistry();
|
|
1984
1999
|
const ctxAccessor = container.resolve(TOKENS3.CONTEXT_ACCESSOR);
|
|
@@ -1986,16 +2001,16 @@ var AuthUtils = Object.freeze({
|
|
|
1986
2001
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
1987
2002
|
const intentLower = intent.toLowerCase();
|
|
1988
2003
|
registryInstance.addPolicy(intentLower, policy);
|
|
1989
|
-
if (!
|
|
2004
|
+
if (!Guards27.isNullOrEmpty(policy.roles)) {
|
|
1990
2005
|
Policies.add("roles");
|
|
1991
2006
|
}
|
|
1992
|
-
if (!
|
|
2007
|
+
if (!Guards27.isNullOrEmpty(policy.permissions)) {
|
|
1993
2008
|
Policies.add("permissions");
|
|
1994
2009
|
}
|
|
1995
|
-
if (!
|
|
2010
|
+
if (!Guards27.isNullOrEmpty(policy.userId)) {
|
|
1996
2011
|
Policies.add("userId");
|
|
1997
2012
|
}
|
|
1998
|
-
if (!
|
|
2013
|
+
if (!Guards27.isNullOrEmpty(policy.tenantId)) {
|
|
1999
2014
|
Policies.add("tenantId");
|
|
2000
2015
|
}
|
|
2001
2016
|
}
|
|
@@ -2012,10 +2027,10 @@ var AuthUtils = Object.freeze({
|
|
|
2012
2027
|
strategies.push(new TenantAuthorizationStrategy(registryInstance, ctxAccessor));
|
|
2013
2028
|
}
|
|
2014
2029
|
}
|
|
2015
|
-
if (!
|
|
2030
|
+
if (!Guards27.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2016
2031
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2017
2032
|
customStrategies.forEach((strategyToken) => {
|
|
2018
|
-
if (
|
|
2033
|
+
if (Guards27.isDefined(strategyToken)) {
|
|
2019
2034
|
strategies.push(strategyToken(container));
|
|
2020
2035
|
}
|
|
2021
2036
|
});
|
|
@@ -2044,11 +2059,11 @@ var CacheUtils = Object.freeze({
|
|
|
2044
2059
|
});
|
|
2045
2060
|
|
|
2046
2061
|
// src/infrastructure/modules/utils/logger.utils.ts
|
|
2047
|
-
import { Guards as
|
|
2062
|
+
import { Guards as Guards29, LOG_LEVEL as LOG_LEVEL3 } from "@xeno-js/shared";
|
|
2048
2063
|
import { TOKENS as TOKENS5 } from "@xeno-js/shared";
|
|
2049
2064
|
|
|
2050
2065
|
// src/infrastructure/loggers/console.logger.ts
|
|
2051
|
-
import { Guards as
|
|
2066
|
+
import { Guards as Guards28, LOG_LEVEL as LOG_LEVEL2 } from "@xeno-js/shared";
|
|
2052
2067
|
var ConsoleLogger = class {
|
|
2053
2068
|
/**
|
|
2054
2069
|
* 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 +2082,7 @@ var ConsoleLogger = class {
|
|
|
2067
2082
|
track(level, message, context, error = void 0) {
|
|
2068
2083
|
if (level < this._minLevel) return;
|
|
2069
2084
|
const logMessage = `[${level}] ${message}`;
|
|
2070
|
-
const payload =
|
|
2085
|
+
const payload = Guards28.isDefined(error) ? { ...context, error } : context;
|
|
2071
2086
|
switch (level) {
|
|
2072
2087
|
case LOG_LEVEL2.ERROR:
|
|
2073
2088
|
console.error(logMessage, payload ?? {});
|
|
@@ -2101,7 +2116,7 @@ var LoggerUtils2 = Object.freeze({
|
|
|
2101
2116
|
async addLogger(container, opts) {
|
|
2102
2117
|
const loggerDependencies = [];
|
|
2103
2118
|
if (opts.console) loggerDependencies.push(new ConsoleLogger(opts?.level));
|
|
2104
|
-
if (!
|
|
2119
|
+
if (!Guards29.isNullOrEmpty(opts.customLoggers)) {
|
|
2105
2120
|
const customLoggers = opts.customLoggers;
|
|
2106
2121
|
for (const logger of customLoggers) {
|
|
2107
2122
|
loggerDependencies.push(logger(container));
|
|
@@ -2121,21 +2136,21 @@ var CacheModule = class {
|
|
|
2121
2136
|
TOKENS6.CACHE_KEY_BUILDER,
|
|
2122
2137
|
(c) => new CacheKeyBuilder(c.resolve(TOKENS6.IDENTITY_ACCESSOR))
|
|
2123
2138
|
);
|
|
2124
|
-
if (opts.inMemory &&
|
|
2139
|
+
if (opts.inMemory && Guards30.isDefined(opts.provider))
|
|
2125
2140
|
throw new Error("Cannot use both in memory and provider cache");
|
|
2126
2141
|
else if (opts.inMemory) {
|
|
2127
2142
|
await CacheUtils.addCache(container);
|
|
2128
|
-
} else if (
|
|
2143
|
+
} else if (Guards30.isDefined(opts.provider)) {
|
|
2129
2144
|
container.addSingleton(TOKENS6.CACHE, (c) => opts.provider(c));
|
|
2130
2145
|
} else throw new Error("No cache provider specified");
|
|
2131
2146
|
}
|
|
2132
2147
|
};
|
|
2133
2148
|
|
|
2134
2149
|
// src/infrastructure/modules/context.module.ts
|
|
2135
|
-
import { Guards as
|
|
2150
|
+
import { Guards as Guards36, TOKENS as TOKENS7 } from "@xeno-js/shared";
|
|
2136
2151
|
|
|
2137
2152
|
// src/infrastructure/events/event.dispatcher.ts
|
|
2138
|
-
import { AppError as AppError12, Guards as
|
|
2153
|
+
import { AppError as AppError12, Guards as Guards31, Result as Result16 } from "@xeno-js/shared";
|
|
2139
2154
|
var EventDispatcher = class {
|
|
2140
2155
|
_handlers = /* @__PURE__ */ new Map();
|
|
2141
2156
|
subscribe(eventType, handler) {
|
|
@@ -2146,7 +2161,7 @@ var EventDispatcher = class {
|
|
|
2146
2161
|
async publish(event, signal) {
|
|
2147
2162
|
AppError12.throwIfAborted(signal, "EventDispatcher.publish");
|
|
2148
2163
|
const handlers = this._handlers.get(event.eventType);
|
|
2149
|
-
if (
|
|
2164
|
+
if (Guards31.isNullOrEmpty(handlers)) return Result16.ok();
|
|
2150
2165
|
try {
|
|
2151
2166
|
for (const handler of handlers) {
|
|
2152
2167
|
const result = await handler.handle(event, signal);
|
|
@@ -2196,7 +2211,7 @@ var ServiceScopeFactory = class {
|
|
|
2196
2211
|
};
|
|
2197
2212
|
|
|
2198
2213
|
// src/infrastructure/factories/user-context.factory.ts
|
|
2199
|
-
import { Guards as
|
|
2214
|
+
import { Guards as Guards33 } from "@xeno-js/shared";
|
|
2200
2215
|
var UserContextFactory = class {
|
|
2201
2216
|
/**
|
|
2202
2217
|
* @description Constructs an instance of UserContextFactory.
|
|
@@ -2217,7 +2232,7 @@ var UserContextFactory = class {
|
|
|
2217
2232
|
tenantId: void 0
|
|
2218
2233
|
};
|
|
2219
2234
|
const identity = this._identityFactory.getIdentity();
|
|
2220
|
-
if (
|
|
2235
|
+
if (Guards33.isDefined(identity)) {
|
|
2221
2236
|
output.userId = identity.userId;
|
|
2222
2237
|
output.tenantId = identity.tenantId;
|
|
2223
2238
|
}
|
|
@@ -2226,7 +2241,7 @@ var UserContextFactory = class {
|
|
|
2226
2241
|
};
|
|
2227
2242
|
|
|
2228
2243
|
// src/infrastructure/http/adapter.http.ts
|
|
2229
|
-
import { Guards as
|
|
2244
|
+
import { Guards as Guards34, HttpHelper as HttpHelper6, HttpRouteParamHelper } from "@xeno-js/shared";
|
|
2230
2245
|
var HttpAdapter = class {
|
|
2231
2246
|
constructor(_urlFactory) {
|
|
2232
2247
|
this._urlFactory = _urlFactory;
|
|
@@ -2246,7 +2261,7 @@ var HttpAdapter = class {
|
|
|
2246
2261
|
headers: req.headers
|
|
2247
2262
|
};
|
|
2248
2263
|
const parsedBody = HttpHelper6.parseBody(method, req.body);
|
|
2249
|
-
if (
|
|
2264
|
+
if (Guards34.isDefined(parsedBody)) {
|
|
2250
2265
|
init.body = parsedBody;
|
|
2251
2266
|
init.duplex = "half";
|
|
2252
2267
|
}
|
|
@@ -2259,14 +2274,14 @@ var HttpAdapter = class {
|
|
|
2259
2274
|
};
|
|
2260
2275
|
|
|
2261
2276
|
// src/infrastructure/http/url-builder.http.ts
|
|
2262
|
-
import { Guards as
|
|
2277
|
+
import { Guards as Guards35 } from "@xeno-js/shared";
|
|
2263
2278
|
var UrlBuilder = class {
|
|
2264
2279
|
create(headers) {
|
|
2265
2280
|
const forwardedProto = headers.get("x-forwarded-proto");
|
|
2266
|
-
const protocol =
|
|
2281
|
+
const protocol = Guards35.isDefined(forwardedProto) ? forwardedProto.split(",")[0].trim() : "http";
|
|
2267
2282
|
const forwardedHost = headers.get("x-forwarded-host");
|
|
2268
2283
|
const hostHeader = headers.get("host");
|
|
2269
|
-
const host =
|
|
2284
|
+
const host = Guards35.isDefined(forwardedHost) ? forwardedHost.split(",")[0].trim() : hostHeader ?? "localhost";
|
|
2270
2285
|
return `${protocol}://${host}`;
|
|
2271
2286
|
}
|
|
2272
2287
|
};
|
|
@@ -2307,7 +2322,7 @@ var ContextModule = class {
|
|
|
2307
2322
|
container.addSingleton(TOKENS7.EVENT_DISPATCHER, () => new EventDispatcher());
|
|
2308
2323
|
}
|
|
2309
2324
|
async _getRequestContext(container, opts) {
|
|
2310
|
-
if (
|
|
2325
|
+
if (Guards36.isDefined(opts)) return opts;
|
|
2311
2326
|
const { NodeRequestContextFactory: NodeRequestContextFactory2 } = await Promise.resolve().then(() => (init_request_context_factory(), request_context_factory_exports));
|
|
2312
2327
|
return new NodeRequestContextFactory2(
|
|
2313
2328
|
new ServiceScopeFactory(container)
|
|
@@ -2316,11 +2331,11 @@ var ContextModule = class {
|
|
|
2316
2331
|
};
|
|
2317
2332
|
|
|
2318
2333
|
// src/infrastructure/modules/cqrs.module.ts
|
|
2319
|
-
import { Guards as
|
|
2334
|
+
import { Guards as Guards39, LOG_LEVEL as LOG_LEVEL4 } from "@xeno-js/shared";
|
|
2320
2335
|
import { TOKENS as TOKENS8 } from "@xeno-js/shared";
|
|
2321
2336
|
|
|
2322
2337
|
// src/application/cqrs/pipelines/cache-invalidation.pipeline.ts
|
|
2323
|
-
import { Guards as
|
|
2338
|
+
import { Guards as Guards37 } from "@xeno-js/shared";
|
|
2324
2339
|
var CommandCacheInvalidationBehavior = class {
|
|
2325
2340
|
constructor(_cacheService, _logger) {
|
|
2326
2341
|
this._cacheService = _cacheService;
|
|
@@ -2330,16 +2345,16 @@ var CommandCacheInvalidationBehavior = class {
|
|
|
2330
2345
|
_logger;
|
|
2331
2346
|
async handle(request, next) {
|
|
2332
2347
|
const result = await next();
|
|
2333
|
-
if (result.isOk() &&
|
|
2348
|
+
if (result.isOk() && Guards37.isDefined(request.cacheInvalidation)) {
|
|
2334
2349
|
try {
|
|
2335
2350
|
const { keys, patterns } = request.cacheInvalidation;
|
|
2336
|
-
if (
|
|
2351
|
+
if (Guards37.isArray(keys)) {
|
|
2337
2352
|
for (const key of keys) {
|
|
2338
2353
|
await this._cacheService.remove(key);
|
|
2339
2354
|
this._logger.debug(`[Cache Invalidation] Removed key: ${key}`);
|
|
2340
2355
|
}
|
|
2341
2356
|
}
|
|
2342
|
-
if (
|
|
2357
|
+
if (Guards37.isArray(patterns) && Guards37.hasMethod(this._cacheService, "removePattern")) {
|
|
2343
2358
|
for (const pattern of patterns) {
|
|
2344
2359
|
await this._cacheService.removePattern(pattern);
|
|
2345
2360
|
this._logger.debug(`[Cache Invalidation] Removed pattern: ${pattern}`);
|
|
@@ -2408,7 +2423,7 @@ var IdempotencyStore = class {
|
|
|
2408
2423
|
|
|
2409
2424
|
// src/infrastructure/pipeline_setup/setup.pipeline.ts
|
|
2410
2425
|
import {
|
|
2411
|
-
Guards as
|
|
2426
|
+
Guards as Guards38
|
|
2412
2427
|
} from "@xeno-js/shared";
|
|
2413
2428
|
var PipelineSetupContext = class {
|
|
2414
2429
|
isQueryCaching = false;
|
|
@@ -2420,14 +2435,14 @@ var PipelineSetupContext = class {
|
|
|
2420
2435
|
this._idempotencyOpts = opts;
|
|
2421
2436
|
}
|
|
2422
2437
|
get idempotencyOpts() {
|
|
2423
|
-
if (
|
|
2438
|
+
if (Guards38.isDefined(this._idempotencyOpts)) return Object.freeze(this._idempotencyOpts);
|
|
2424
2439
|
return this._idempotencyOpts;
|
|
2425
2440
|
}
|
|
2426
2441
|
set authzOpts(opts) {
|
|
2427
2442
|
this._authzOpts = opts;
|
|
2428
2443
|
}
|
|
2429
2444
|
get authzOpts() {
|
|
2430
|
-
if (
|
|
2445
|
+
if (Guards38.isDefined(this._authzOpts)) return Object.freeze(this._authzOpts);
|
|
2431
2446
|
return this._authzOpts;
|
|
2432
2447
|
}
|
|
2433
2448
|
addCommon(behavior, order = 50) {
|
|
@@ -2468,14 +2483,14 @@ var CqrsModule = class {
|
|
|
2468
2483
|
context.addCommon(new LoggingPipeline(logger), 10);
|
|
2469
2484
|
for (const plugin of opts.plugins)
|
|
2470
2485
|
await plugin(opts.builder, container.resolve(TOKENS8.CONFIGURATION_SERVICE), context);
|
|
2471
|
-
if (
|
|
2486
|
+
if (Guards39.isDefined(context.authzOpts)) {
|
|
2472
2487
|
const authzPipeline = await AuthUtils.addAuthZ(container, context.authzOpts);
|
|
2473
2488
|
context.addCommon(authzPipeline, 40);
|
|
2474
2489
|
}
|
|
2475
|
-
if ((
|
|
2490
|
+
if ((Guards39.isDefined(context.idempotencyOpts) || context.isQueryCaching) && !container.isRegistered(TOKENS8.CACHE)) {
|
|
2476
2491
|
await new CacheModule().configure(container);
|
|
2477
2492
|
}
|
|
2478
|
-
if (
|
|
2493
|
+
if (Guards39.isDefined(context.idempotencyOpts)) {
|
|
2479
2494
|
const store = new IdempotencyStore(
|
|
2480
2495
|
container.resolve(TOKENS8.CACHE),
|
|
2481
2496
|
container.resolve(TOKENS8.CACHE_KEY_BUILDER)
|
|
@@ -2515,12 +2530,12 @@ var CqrsModule = class {
|
|
|
2515
2530
|
};
|
|
2516
2531
|
|
|
2517
2532
|
// src/infrastructure/modules/db.module.ts
|
|
2518
|
-
import { Guards as
|
|
2533
|
+
import { Guards as Guards41 } from "@xeno-js/shared";
|
|
2519
2534
|
import { TOKENS as TOKENS9 } from "@xeno-js/shared";
|
|
2520
2535
|
|
|
2521
2536
|
// src/infrastructure/transaction/unit-of-work.ts
|
|
2522
2537
|
import { AppError as AppError13 } from "@xeno-js/shared";
|
|
2523
|
-
import { Guards as
|
|
2538
|
+
import { Guards as Guards40 } from "@xeno-js/shared";
|
|
2524
2539
|
var UnitOfWork = class {
|
|
2525
2540
|
/**
|
|
2526
2541
|
* Creates an instance of UnitOfWork.
|
|
@@ -2551,9 +2566,9 @@ var UnitOfWork = class {
|
|
|
2551
2566
|
});
|
|
2552
2567
|
}
|
|
2553
2568
|
async dispose() {
|
|
2554
|
-
if (
|
|
2569
|
+
if (Guards40.isDefined(this._ttx.state)) {
|
|
2555
2570
|
try {
|
|
2556
|
-
if (
|
|
2571
|
+
if (Guards40.hasMethod(this._ttx.state, "rollback")) {
|
|
2557
2572
|
await this._ttx.state.rollback();
|
|
2558
2573
|
}
|
|
2559
2574
|
} finally {
|
|
@@ -2599,7 +2614,7 @@ var DbModule = class {
|
|
|
2599
2614
|
container.addScoped(TOKENS9.TRANSACTION_STATE, () => {
|
|
2600
2615
|
return new TransactionState();
|
|
2601
2616
|
});
|
|
2602
|
-
if (
|
|
2617
|
+
if (Guards41.isDefined(opts.uow)) {
|
|
2603
2618
|
container.addScoped(TOKENS9.UNIT_OF_WORK, (c) => {
|
|
2604
2619
|
return opts.uow(c);
|
|
2605
2620
|
});
|
|
@@ -2614,9 +2629,9 @@ var DbModule = class {
|
|
|
2614
2629
|
return new Proxy(db, {
|
|
2615
2630
|
get(_target, prop, receiver) {
|
|
2616
2631
|
const activeState = ttx.state;
|
|
2617
|
-
if (
|
|
2632
|
+
if (Guards41.isDefined(activeState)) {
|
|
2618
2633
|
const value = Reflect.get(activeState, prop, receiver);
|
|
2619
|
-
if (
|
|
2634
|
+
if (Guards41.isFunction(value)) {
|
|
2620
2635
|
return value.bind(activeState);
|
|
2621
2636
|
}
|
|
2622
2637
|
return value;
|
|
@@ -2636,7 +2651,7 @@ import { RoutePatternHelper as RoutePatternHelper3 } from "@xeno-js/shared";
|
|
|
2636
2651
|
|
|
2637
2652
|
// src/infrastructure/http/route-matcher.http.ts
|
|
2638
2653
|
import {
|
|
2639
|
-
Guards as
|
|
2654
|
+
Guards as Guards42,
|
|
2640
2655
|
HttpHelper as HttpHelper7,
|
|
2641
2656
|
RoutePatternHelper as RoutePatternHelper2,
|
|
2642
2657
|
STATUS_CODES as STATUS_CODES4
|
|
@@ -2647,14 +2662,14 @@ var RouteMatcher = class {
|
|
|
2647
2662
|
}
|
|
2648
2663
|
_compiledRoutes;
|
|
2649
2664
|
match(rawUrl, method) {
|
|
2650
|
-
const url = !
|
|
2665
|
+
const url = !Guards42.isNullOrEmpty(rawUrl) ? rawUrl : "/";
|
|
2651
2666
|
const safeUrl = HttpHelper7.parseSafeUrl(url);
|
|
2652
2667
|
const parsedPath = RoutePatternHelper2.normalizePath(safeUrl.pathname);
|
|
2653
2668
|
const upperMethod = method.toUpperCase();
|
|
2654
2669
|
const matched = this._compiledRoutes.find(
|
|
2655
2670
|
(r) => r.upperMethod === upperMethod && r.pattern.test(parsedPath)
|
|
2656
2671
|
);
|
|
2657
|
-
if (
|
|
2672
|
+
if (Guards42.isDefined(matched)) return matched.definition;
|
|
2658
2673
|
if (upperMethod === "OPTIONS") {
|
|
2659
2674
|
const pathExists = this._compiledRoutes.some((r) => r.pattern.test(parsedPath));
|
|
2660
2675
|
if (pathExists) {
|
|
@@ -2736,17 +2751,17 @@ var HttpServerModule = class {
|
|
|
2736
2751
|
};
|
|
2737
2752
|
|
|
2738
2753
|
// src/infrastructure/modules/logger.module.ts
|
|
2739
|
-
import { Guards as
|
|
2754
|
+
import { Guards as Guards44 } from "@xeno-js/shared";
|
|
2740
2755
|
|
|
2741
2756
|
// src/infrastructure/loggers/setup.logger.ts
|
|
2742
|
-
import { Guards as
|
|
2757
|
+
import { Guards as Guards43, LOG_LEVEL as LOG_LEVEL5 } from "@xeno-js/shared";
|
|
2743
2758
|
var LoggerSetupContext = class {
|
|
2744
2759
|
console = false;
|
|
2745
2760
|
level = LOG_LEVEL5.DEBUG;
|
|
2746
2761
|
_customLoggers = [];
|
|
2747
2762
|
addConsole(enabled = true, level) {
|
|
2748
2763
|
this.console = enabled;
|
|
2749
|
-
if (
|
|
2764
|
+
if (Guards43.isDefined(level)) {
|
|
2750
2765
|
this.level = level;
|
|
2751
2766
|
}
|
|
2752
2767
|
}
|
|
@@ -2763,9 +2778,9 @@ var LoggerModule = class {
|
|
|
2763
2778
|
async configure(container, opts) {
|
|
2764
2779
|
const loggerSetup = new LoggerSetupContext();
|
|
2765
2780
|
loggerSetup.addConsole(opts.console, opts.level);
|
|
2766
|
-
if (!
|
|
2781
|
+
if (!Guards44.isNullOrEmpty(opts.plugins))
|
|
2767
2782
|
opts.plugins.forEach((plugin) => plugin(opts.builder, opts.config, loggerSetup));
|
|
2768
|
-
if (!
|
|
2783
|
+
if (!Guards44.isNullOrEmpty(opts.customLoggers)) {
|
|
2769
2784
|
for (const logger of opts.customLoggers) {
|
|
2770
2785
|
loggerSetup.addCustomLogger((c) => logger(c));
|
|
2771
2786
|
}
|
|
@@ -2780,7 +2795,7 @@ var LoggerModule = class {
|
|
|
2780
2795
|
};
|
|
2781
2796
|
|
|
2782
2797
|
// src/infrastructure/modules/middleware.module.ts
|
|
2783
|
-
import { Guards as
|
|
2798
|
+
import { Guards as Guards54, LOG_LEVEL as LOG_LEVEL6 } from "@xeno-js/shared";
|
|
2784
2799
|
import { TOKENS as TOKENS12 } from "@xeno-js/shared";
|
|
2785
2800
|
|
|
2786
2801
|
// src/presentation/controllers/base.controller.ts
|
|
@@ -2936,7 +2951,7 @@ var MethodCheckMiddleware = class {
|
|
|
2936
2951
|
import {
|
|
2937
2952
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES4,
|
|
2938
2953
|
ERROR_CODES as ERROR_CODES5,
|
|
2939
|
-
Guards as
|
|
2954
|
+
Guards as Guards45,
|
|
2940
2955
|
GuidHelper as GuidHelper7,
|
|
2941
2956
|
HttpHelper as HttpHelper10,
|
|
2942
2957
|
STATUS_CODES as STATUS_CODES6
|
|
@@ -2979,7 +2994,7 @@ var AllowOriginMiddleware = class {
|
|
|
2979
2994
|
return next();
|
|
2980
2995
|
}
|
|
2981
2996
|
checkOrigin(policy, origin) {
|
|
2982
|
-
if (
|
|
2997
|
+
if (Guards45.isDefined(policy.allowOrigins)) {
|
|
2983
2998
|
return policy.allowOrigins.includes("*") || policy.allowOrigins.includes(origin ?? "");
|
|
2984
2999
|
} else {
|
|
2985
3000
|
return this._allowOrigin.isAllowed(origin);
|
|
@@ -3050,7 +3065,7 @@ var CompositeMiddleware = class {
|
|
|
3050
3065
|
};
|
|
3051
3066
|
|
|
3052
3067
|
// src/presentation/middlewares/cookie-response.middleware.ts
|
|
3053
|
-
import { Guards as
|
|
3068
|
+
import { Guards as Guards46 } from "@xeno-js/shared";
|
|
3054
3069
|
import { TOKENS as TOKENS11 } from "@xeno-js/shared";
|
|
3055
3070
|
var CookieResponseMiddleware = class {
|
|
3056
3071
|
constructor(_requestContext) {
|
|
@@ -3060,15 +3075,15 @@ var CookieResponseMiddleware = class {
|
|
|
3060
3075
|
async execute(req, next) {
|
|
3061
3076
|
const response = await next();
|
|
3062
3077
|
const scope = this._requestContext.getScope();
|
|
3063
|
-
if (!
|
|
3078
|
+
if (!Guards46.isDefined(scope)) {
|
|
3064
3079
|
return response;
|
|
3065
3080
|
}
|
|
3066
3081
|
try {
|
|
3067
3082
|
const cookieHandler = scope.resolve(TOKENS11.COOKIE_HANDLER);
|
|
3068
3083
|
const pending = cookieHandler.getPendingCookies();
|
|
3069
|
-
if (!
|
|
3084
|
+
if (!Guards46.isNullOrEmpty(pending)) {
|
|
3070
3085
|
const existingSetCookie = response.headers?.["Set-Cookie"];
|
|
3071
|
-
const mergedCookies =
|
|
3086
|
+
const mergedCookies = Guards46.isArray(existingSetCookie) ? [...existingSetCookie, ...pending] : Guards46.isDefined(existingSetCookie) ? [String(existingSetCookie), ...pending] : [...pending];
|
|
3072
3087
|
response.headers = {
|
|
3073
3088
|
...response?.headers ?? {},
|
|
3074
3089
|
"Set-Cookie": mergedCookies
|
|
@@ -3081,7 +3096,7 @@ var CookieResponseMiddleware = class {
|
|
|
3081
3096
|
};
|
|
3082
3097
|
|
|
3083
3098
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3084
|
-
import { Guards as
|
|
3099
|
+
import { Guards as Guards47 } from "@xeno-js/shared";
|
|
3085
3100
|
var CORSMiddleware = class {
|
|
3086
3101
|
constructor(_requestContext, _getRouteMatcher, _withCredentials = "false") {
|
|
3087
3102
|
this._requestContext = _requestContext;
|
|
@@ -3096,12 +3111,12 @@ var CORSMiddleware = class {
|
|
|
3096
3111
|
const origin = network?.origin;
|
|
3097
3112
|
const response = await next();
|
|
3098
3113
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, req.method);
|
|
3099
|
-
const withCredentials =
|
|
3114
|
+
const withCredentials = Guards47.isDefined(policy.withCredentials) ? policy.withCredentials ? "true" : "false" : this._withCredentials;
|
|
3100
3115
|
const allowOrigins = policy.allowOrigins;
|
|
3101
|
-
if (
|
|
3116
|
+
if (Guards47.isDefined(origin) || Guards47.isDefined(allowOrigins) && allowOrigins.includes("*")) {
|
|
3102
3117
|
response.headers = {
|
|
3103
3118
|
...response?.headers ?? {},
|
|
3104
|
-
"Access-Control-Allow-Origin":
|
|
3119
|
+
"Access-Control-Allow-Origin": Guards47.isDefined(allowOrigins) && allowOrigins.includes("*") && withCredentials === "false" ? "*" : origin,
|
|
3105
3120
|
"Access-Control-Allow-Credentials": withCredentials,
|
|
3106
3121
|
"Vary": "Origin"
|
|
3107
3122
|
};
|
|
@@ -3114,7 +3129,7 @@ var CORSMiddleware = class {
|
|
|
3114
3129
|
import {
|
|
3115
3130
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES5,
|
|
3116
3131
|
ERROR_CODES as ERROR_CODES6,
|
|
3117
|
-
Guards as
|
|
3132
|
+
Guards as Guards48,
|
|
3118
3133
|
GuidHelper as GuidHelper9,
|
|
3119
3134
|
HttpHelper as HttpHelper12,
|
|
3120
3135
|
STATUS_CODES as STATUS_CODES8
|
|
@@ -3133,11 +3148,11 @@ var CsrfMiddleware = class {
|
|
|
3133
3148
|
const isStateChanging = ["POST", "PUT", "DELETE", "PATCH"].includes(method);
|
|
3134
3149
|
if (isStateChanging) {
|
|
3135
3150
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, method);
|
|
3136
|
-
if (
|
|
3151
|
+
if (Guards48.isDefined(policy.withCsrf) && !policy.withCsrf) return await next();
|
|
3137
3152
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3138
3153
|
const headerToken = network?.csrf;
|
|
3139
3154
|
const cookieToken = network?.csrfCookie;
|
|
3140
|
-
if (!
|
|
3155
|
+
if (!Guards48.isDefined(headerToken) || !Guards48.isDefined(cookieToken)) {
|
|
3141
3156
|
return HttpHelper12.error(
|
|
3142
3157
|
{
|
|
3143
3158
|
success: false,
|
|
@@ -3179,7 +3194,7 @@ var CsrfMiddleware = class {
|
|
|
3179
3194
|
}
|
|
3180
3195
|
);
|
|
3181
3196
|
}
|
|
3182
|
-
if (!
|
|
3197
|
+
if (!Guards48.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3183
3198
|
return HttpHelper12.error(
|
|
3184
3199
|
{
|
|
3185
3200
|
success: false,
|
|
@@ -3206,7 +3221,7 @@ var CsrfMiddleware = class {
|
|
|
3206
3221
|
};
|
|
3207
3222
|
|
|
3208
3223
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3209
|
-
import { Guards as
|
|
3224
|
+
import { Guards as Guards49 } from "@xeno-js/shared";
|
|
3210
3225
|
var CsrfCookieMiddleware = class {
|
|
3211
3226
|
constructor(_requestContext, _csrfTokenService, _csrf) {
|
|
3212
3227
|
this._requestContext = _requestContext;
|
|
@@ -3221,8 +3236,8 @@ var CsrfCookieMiddleware = class {
|
|
|
3221
3236
|
const context = this._requestContext.getContext();
|
|
3222
3237
|
const identity = context?.identity;
|
|
3223
3238
|
const network = context?.network;
|
|
3224
|
-
if (!
|
|
3225
|
-
if (
|
|
3239
|
+
if (!Guards49.isDefined(identity?.userId)) return response;
|
|
3240
|
+
if (Guards49.isDefined(network?.csrfCookie)) return response;
|
|
3226
3241
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3227
3242
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3228
3243
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3238,7 +3253,7 @@ var CsrfCookieMiddleware = class {
|
|
|
3238
3253
|
};
|
|
3239
3254
|
|
|
3240
3255
|
// src/presentation/middlewares/options.middleware.ts
|
|
3241
|
-
import { Guards as
|
|
3256
|
+
import { Guards as Guards50, HttpHelper as HttpHelper13, STATUS_CODES as STATUS_CODES9 } from "@xeno-js/shared";
|
|
3242
3257
|
var OptionsMiddleware = class {
|
|
3243
3258
|
constructor(_requestContext, _allowMethod, _getRouteMatcher, _allowHeaders = [], _withCredentials = "false") {
|
|
3244
3259
|
this._requestContext = _requestContext;
|
|
@@ -3258,10 +3273,10 @@ var OptionsMiddleware = class {
|
|
|
3258
3273
|
const origin = network?.origin;
|
|
3259
3274
|
const targetMethod = req.headers.get("access-control-request-method") ?? "GET";
|
|
3260
3275
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, targetMethod);
|
|
3261
|
-
const withCredentials =
|
|
3276
|
+
const withCredentials = Guards50.isDefined(policy.withCredentials) ? policy.withCredentials ? "true" : "false" : this._withCredentials;
|
|
3262
3277
|
const headers = {};
|
|
3263
|
-
if (
|
|
3264
|
-
headers["Access-Control-Allow-Origin"] =
|
|
3278
|
+
if (Guards50.isDefined(origin) || Guards50.isDefined(policy.allowOrigins) && policy.allowOrigins.includes("*")) {
|
|
3279
|
+
headers["Access-Control-Allow-Origin"] = Guards50.isDefined(policy.allowOrigins) && policy.allowOrigins.includes("*") && withCredentials === "false" ? "*" : origin;
|
|
3265
3280
|
headers["Access-Control-Allow-Credentials"] = withCredentials;
|
|
3266
3281
|
headers["Vary"] = "Origin";
|
|
3267
3282
|
}
|
|
@@ -3277,7 +3292,7 @@ var OptionsMiddleware = class {
|
|
|
3277
3292
|
import {
|
|
3278
3293
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES6,
|
|
3279
3294
|
ERROR_CODES as ERROR_CODES7,
|
|
3280
|
-
Guards as
|
|
3295
|
+
Guards as Guards51,
|
|
3281
3296
|
GuidHelper as GuidHelper10,
|
|
3282
3297
|
HttpHelper as HttpHelper14,
|
|
3283
3298
|
STATUS_CODES as STATUS_CODES10
|
|
@@ -3298,7 +3313,7 @@ var RateLimitMiddleware = class {
|
|
|
3298
3313
|
async execute(req, next) {
|
|
3299
3314
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3300
3315
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3301
|
-
if (!
|
|
3316
|
+
if (!Guards51.isDefined(cacheKey))
|
|
3302
3317
|
return HttpHelper14.error(
|
|
3303
3318
|
{
|
|
3304
3319
|
success: false,
|
|
@@ -3358,7 +3373,7 @@ import {
|
|
|
3358
3373
|
} from "@xeno-js/shared";
|
|
3359
3374
|
|
|
3360
3375
|
// src/presentation/mappers/context.mapper.ts
|
|
3361
|
-
import { Guards as
|
|
3376
|
+
import { Guards as Guards52 } from "@xeno-js/shared";
|
|
3362
3377
|
var ContextMapper = Object.freeze({
|
|
3363
3378
|
/**
|
|
3364
3379
|
* @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 +3414,13 @@ var ContextMapper = Object.freeze({
|
|
|
3399
3414
|
}
|
|
3400
3415
|
});
|
|
3401
3416
|
function _buildMessagingContext(meta) {
|
|
3402
|
-
const hasSequenceData =
|
|
3403
|
-
const hasMessagingData = hasSequenceData ||
|
|
3417
|
+
const hasSequenceData = Guards52.isDefined(meta.sequence?.sequenceId) || Guards52.isDefined(meta.sequence?.position) || Guards52.isDefined(meta.sequence?.size);
|
|
3418
|
+
const hasMessagingData = hasSequenceData || Guards52.isDefined(meta.expiration) || Guards52.isDefined(meta.returnAddress);
|
|
3404
3419
|
if (!hasMessagingData) return void 0;
|
|
3405
3420
|
return {
|
|
3406
3421
|
returnAddress: meta.returnAddress,
|
|
3407
3422
|
expiration: meta.expiration,
|
|
3408
|
-
sequence: hasSequenceData &&
|
|
3423
|
+
sequence: hasSequenceData && Guards52.isDefined(meta.sequence) ? {
|
|
3409
3424
|
sequenceId: meta.sequence.sequenceId,
|
|
3410
3425
|
position: meta.sequence.position,
|
|
3411
3426
|
size: meta.sequence.size
|
|
@@ -3488,7 +3503,7 @@ var RequestContextMiddleware = class {
|
|
|
3488
3503
|
};
|
|
3489
3504
|
|
|
3490
3505
|
// src/infrastructure/http/dispatcher.http.ts
|
|
3491
|
-
import { Guards as
|
|
3506
|
+
import { Guards as Guards53 } from "@xeno-js/shared";
|
|
3492
3507
|
var HttpDispatcher = class {
|
|
3493
3508
|
constructor(_requestContext, _middleware, _serviceProxy) {
|
|
3494
3509
|
this._requestContext = _requestContext;
|
|
@@ -3501,14 +3516,14 @@ var HttpDispatcher = class {
|
|
|
3501
3516
|
async handle(req, token, input) {
|
|
3502
3517
|
return await this._middleware.execute(req, async () => {
|
|
3503
3518
|
const scope = this._requestContext.getScope();
|
|
3504
|
-
if (!
|
|
3519
|
+
if (!Guards53.isDefined(scope)) {
|
|
3505
3520
|
throw new Error(
|
|
3506
3521
|
"[HttpDispatcher Error]: Active scope not found. Execution outside RequestContext."
|
|
3507
3522
|
);
|
|
3508
3523
|
}
|
|
3509
3524
|
const services = this._serviceProxy.getServiceProxy(scope);
|
|
3510
3525
|
const controller = services[token];
|
|
3511
|
-
if (!
|
|
3526
|
+
if (!Guards53.isDefined(controller) || !Guards53.hasMethod(controller, "handle")) {
|
|
3512
3527
|
throw new Error(
|
|
3513
3528
|
`[HttpDispatcher Error]: The provided '${String(token)}' does not implement the 'handle' method.`
|
|
3514
3529
|
);
|
|
@@ -3537,7 +3552,7 @@ var MiddlewareModule = class {
|
|
|
3537
3552
|
)
|
|
3538
3553
|
);
|
|
3539
3554
|
const getRouteMatcher = () => container.resolve(TOKENS12.ROUTE_MATCHER);
|
|
3540
|
-
const withCredentials =
|
|
3555
|
+
const withCredentials = Guards54.isDefined(opts.cors?.withCredentials) && opts.cors?.withCredentials ? "true" : "false";
|
|
3541
3556
|
const [optionsMw, cookieRespMw, corsMw, authMw, csrfMws] = [
|
|
3542
3557
|
this._buildOptionsMiddleware(
|
|
3543
3558
|
opts,
|
|
@@ -3564,7 +3579,7 @@ var MiddlewareModule = class {
|
|
|
3564
3579
|
logger
|
|
3565
3580
|
);
|
|
3566
3581
|
const defaultOrigin = configuration.get("APP_URL") ?? `http://localhost:${configuration.getNumber("PORT", 3e3)}`;
|
|
3567
|
-
const origins = !
|
|
3582
|
+
const origins = !Guards54.isNullOrEmpty(opts.cors?.allowOrigins) ? opts.cors.allowOrigins : [defaultOrigin];
|
|
3568
3583
|
const allowOriginMw = new AllowOriginMiddleware(
|
|
3569
3584
|
new AllowOrigin(origins),
|
|
3570
3585
|
requestContext,
|
|
@@ -3574,14 +3589,14 @@ var MiddlewareModule = class {
|
|
|
3574
3589
|
const methodCheckMw = new MethodCheckMiddleware(requestContext, allowMethod);
|
|
3575
3590
|
const pipeline = [
|
|
3576
3591
|
requestCtxMw,
|
|
3577
|
-
...
|
|
3592
|
+
...Guards54.isDefined(cookieRespMw) ? [cookieRespMw] : [],
|
|
3578
3593
|
allowOriginMw,
|
|
3579
|
-
...
|
|
3580
|
-
...!
|
|
3581
|
-
...
|
|
3582
|
-
...
|
|
3594
|
+
...Guards54.isDefined(optionsMw) && !Guards54.isNullOrEmpty(opts.routes) ? [optionsMw] : [],
|
|
3595
|
+
...!Guards54.isNullOrEmpty(opts.routes) ? [methodCheckMw] : [],
|
|
3596
|
+
...Guards54.isDefined(corsMw) ? [corsMw] : [],
|
|
3597
|
+
...Guards54.isDefined(rateLimitMw) ? [rateLimitMw] : [],
|
|
3583
3598
|
authMw,
|
|
3584
|
-
...!
|
|
3599
|
+
...!Guards54.isNullOrEmpty(csrfMws) ? csrfMws : []
|
|
3585
3600
|
];
|
|
3586
3601
|
container.addSingleton(TOKENS12.MIDDLEWARE, () => new CompositeMiddleware(pipeline));
|
|
3587
3602
|
container.addSingleton(
|
|
@@ -3594,11 +3609,11 @@ var MiddlewareModule = class {
|
|
|
3594
3609
|
);
|
|
3595
3610
|
}
|
|
3596
3611
|
_buildCookieResponseMiddleware(opts, requestContext) {
|
|
3597
|
-
if (!
|
|
3612
|
+
if (!Guards54.isDefined(opts.isSSR) || !opts.isSSR) return void 0;
|
|
3598
3613
|
return new CookieResponseMiddleware(requestContext);
|
|
3599
3614
|
}
|
|
3600
3615
|
_buildCsrfMiddlewares(opts, container, requestContext, routePolicyCheck) {
|
|
3601
|
-
if (!
|
|
3616
|
+
if (!Guards54.isDefined(opts.csrf)) return [];
|
|
3602
3617
|
const csrf = opts.csrf;
|
|
3603
3618
|
container.addSingleton(TOKENS12.CRYPTO_SERVICE, () => new EdgeCryptoService());
|
|
3604
3619
|
container.addSingleton(TOKENS12.CSRF_TOKEN_SERVICE, (c) => {
|
|
@@ -3614,7 +3629,7 @@ var MiddlewareModule = class {
|
|
|
3614
3629
|
];
|
|
3615
3630
|
}
|
|
3616
3631
|
async _buildRateLimitMiddleware(opts, container, requestContext, logger) {
|
|
3617
|
-
if (
|
|
3632
|
+
if (Guards54.isDefined(opts.rateLimit?.enabled) && opts.rateLimit?.enabled) {
|
|
3618
3633
|
const maxRequests = opts.rateLimit?.maxRequests ?? 100;
|
|
3619
3634
|
const windowSeconds = opts.rateLimit?.windowSeconds ?? 60;
|
|
3620
3635
|
if (!container.isRegistered(TOKENS12.CACHE)) {
|
|
@@ -3630,12 +3645,12 @@ var MiddlewareModule = class {
|
|
|
3630
3645
|
}
|
|
3631
3646
|
}
|
|
3632
3647
|
_buildCorsMiddleware(opts, requestContext, withCredentials, routePolicyCheck) {
|
|
3633
|
-
if (
|
|
3648
|
+
if (Guards54.isDefined(opts.cors?.enabled) && opts.cors.enabled) {
|
|
3634
3649
|
return new CORSMiddleware(requestContext, routePolicyCheck, withCredentials);
|
|
3635
3650
|
}
|
|
3636
3651
|
}
|
|
3637
3652
|
_buildOptionsMiddleware(opts, requestContext, allowMethod, withCredentials, routePolicyCheck) {
|
|
3638
|
-
if (
|
|
3653
|
+
if (Guards54.isDefined(opts.cors?.enablePreflight) && opts.cors?.enablePreflight) {
|
|
3639
3654
|
const allowHeaders = Array.from(
|
|
3640
3655
|
/* @__PURE__ */ new Set([
|
|
3641
3656
|
"x-csrf-token",
|
|
@@ -3687,7 +3702,7 @@ var MiddlewareModule = class {
|
|
|
3687
3702
|
tokenExtractor,
|
|
3688
3703
|
new GateKeeper(() => {
|
|
3689
3704
|
const scope = requestContext.getScope();
|
|
3690
|
-
if (!
|
|
3705
|
+
if (!Guards54.isDefined(scope)) {
|
|
3691
3706
|
throw new Error("[GateKeeper Error]: No active scope found.");
|
|
3692
3707
|
}
|
|
3693
3708
|
return scope.resolve(TOKENS12.BASE_AUTH_SERVICE);
|
|
@@ -3760,12 +3775,12 @@ var withAuth = (setup) => {
|
|
|
3760
3775
|
};
|
|
3761
3776
|
|
|
3762
3777
|
// src/infrastructure/plugin/authz.plugin.ts
|
|
3763
|
-
import { Guards as
|
|
3778
|
+
import { Guards as Guards55 } from "@xeno-js/shared";
|
|
3764
3779
|
var withAuthZ = (setup) => {
|
|
3765
3780
|
return definePlugin(
|
|
3766
3781
|
"pipeline",
|
|
3767
3782
|
(_builder, config, context) => {
|
|
3768
|
-
if (!
|
|
3783
|
+
if (!Guards55.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
3769
3784
|
const options = {
|
|
3770
3785
|
policies: void 0
|
|
3771
3786
|
};
|
|
@@ -3777,25 +3792,25 @@ var withAuthZ = (setup) => {
|
|
|
3777
3792
|
|
|
3778
3793
|
// src/infrastructure/plugin/concurrency.plugin.ts
|
|
3779
3794
|
import {
|
|
3780
|
-
Guards as
|
|
3795
|
+
Guards as Guards56
|
|
3781
3796
|
} from "@xeno-js/shared";
|
|
3782
3797
|
var withConcurrency = (setup) => {
|
|
3783
3798
|
return definePlugin(
|
|
3784
3799
|
"pipeline",
|
|
3785
3800
|
(_builder, config, context) => {
|
|
3786
|
-
if (!
|
|
3801
|
+
if (!Guards56.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
3787
3802
|
const options = {};
|
|
3788
|
-
if (
|
|
3803
|
+
if (Guards56.isDefined(setup)) setup(options, config);
|
|
3789
3804
|
context.addCommand(new ConcurrencyRetryPipeline(options), 70);
|
|
3790
3805
|
}
|
|
3791
3806
|
);
|
|
3792
3807
|
};
|
|
3793
3808
|
|
|
3794
3809
|
// src/infrastructure/plugin/http.plugin.ts
|
|
3795
|
-
import { Guards as
|
|
3810
|
+
import { Guards as Guards59 } from "@xeno-js/shared";
|
|
3796
3811
|
|
|
3797
3812
|
// src/infrastructure/modules/http-core.module.ts
|
|
3798
|
-
import { Guards as
|
|
3813
|
+
import { Guards as Guards58 } from "@xeno-js/shared";
|
|
3799
3814
|
import { TOKENS as TOKENS14 } from "@xeno-js/shared";
|
|
3800
3815
|
|
|
3801
3816
|
// src/infrastructure/datasources/remote.datasource.ts
|
|
@@ -3884,7 +3899,7 @@ var RemoteDataSource = class {
|
|
|
3884
3899
|
};
|
|
3885
3900
|
|
|
3886
3901
|
// src/infrastructure/factories/http.factory.ts
|
|
3887
|
-
import { AppError as AppError15, Guards as
|
|
3902
|
+
import { AppError as AppError15, Guards as Guards57 } from "@xeno-js/shared";
|
|
3888
3903
|
var HttpClientFactory = class {
|
|
3889
3904
|
_clients = /* @__PURE__ */ new Map();
|
|
3890
3905
|
add(name, client) {
|
|
@@ -3895,7 +3910,7 @@ var HttpClientFactory = class {
|
|
|
3895
3910
|
}
|
|
3896
3911
|
get(name = "default") {
|
|
3897
3912
|
const client = this._clients.get(name);
|
|
3898
|
-
if (!
|
|
3913
|
+
if (!Guards57.isDefined(client)) {
|
|
3899
3914
|
const available = Array.from(this._clients.keys()).join(", ") ?? "none";
|
|
3900
3915
|
throw AppError15.notFound(
|
|
3901
3916
|
"HttpClientFactory",
|
|
@@ -3928,7 +3943,7 @@ var HttpCoreModule = class {
|
|
|
3928
3943
|
container.addSingleton(TOKENS14.HTTP_CLIENT_FACTORY, () => factory);
|
|
3929
3944
|
}
|
|
3930
3945
|
getResilienceService(container, resilience) {
|
|
3931
|
-
if (!
|
|
3946
|
+
if (!Guards58.isDefined(resilience)) {
|
|
3932
3947
|
return new NoOpResilienceService();
|
|
3933
3948
|
} else {
|
|
3934
3949
|
return resilience(container);
|
|
@@ -3941,9 +3956,9 @@ var withCustomHttp = (config) => {
|
|
|
3941
3956
|
return definePlugin(
|
|
3942
3957
|
"http",
|
|
3943
3958
|
(builder, _config) => {
|
|
3944
|
-
const clientEntries =
|
|
3959
|
+
const clientEntries = Guards59.isArray(config.clients) ? config.clients : [config.clients];
|
|
3945
3960
|
const entries = clientEntries.map((item) => {
|
|
3946
|
-
if (!
|
|
3961
|
+
if (!Guards59.isDefined(item.client)) {
|
|
3947
3962
|
throw new Error(
|
|
3948
3963
|
`[withCustomHttp Error]: 'client' instance is required for registration '${item.name ?? "default"}'.`
|
|
3949
3964
|
);
|
|
@@ -3963,27 +3978,27 @@ var withCustomHttp = (config) => {
|
|
|
3963
3978
|
|
|
3964
3979
|
// src/infrastructure/plugin/idempotency.plugin.ts
|
|
3965
3980
|
import {
|
|
3966
|
-
Guards as
|
|
3981
|
+
Guards as Guards60
|
|
3967
3982
|
} from "@xeno-js/shared";
|
|
3968
3983
|
var withIdempotency = (setup) => {
|
|
3969
3984
|
return definePlugin(
|
|
3970
3985
|
"pipeline",
|
|
3971
3986
|
(_builder, config, context) => {
|
|
3972
|
-
if (!
|
|
3987
|
+
if (!Guards60.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
3973
3988
|
const options = {};
|
|
3974
|
-
if (
|
|
3989
|
+
if (Guards60.isDefined(setup)) setup(options, config);
|
|
3975
3990
|
context.idempotencyOpts = options;
|
|
3976
3991
|
}
|
|
3977
3992
|
);
|
|
3978
3993
|
};
|
|
3979
3994
|
|
|
3980
3995
|
// src/infrastructure/plugin/logger.plugin.ts
|
|
3981
|
-
import { Guards as
|
|
3996
|
+
import { Guards as Guards61, LOG_LEVEL as LOG_LEVEL7 } from "@xeno-js/shared";
|
|
3982
3997
|
var withConsoleLogger = (setup) => {
|
|
3983
3998
|
return definePlugin(
|
|
3984
3999
|
"logger",
|
|
3985
4000
|
(_builder, config, ctx) => {
|
|
3986
|
-
if (!
|
|
4001
|
+
if (!Guards61.isDefined(ctx)) throw new Error("LoggerSetup is not defined.");
|
|
3987
4002
|
const options = {
|
|
3988
4003
|
isEnabled: true,
|
|
3989
4004
|
level: LOG_LEVEL7.DEBUG
|
|
@@ -3996,16 +4011,16 @@ var withConsoleLogger = (setup) => {
|
|
|
3996
4011
|
|
|
3997
4012
|
// src/infrastructure/plugin/performance.plugin.ts
|
|
3998
4013
|
import {
|
|
3999
|
-
Guards as
|
|
4014
|
+
Guards as Guards62
|
|
4000
4015
|
} from "@xeno-js/shared";
|
|
4001
4016
|
import { TOKENS as TOKENS15 } from "@xeno-js/shared";
|
|
4002
4017
|
var withPerformance = (setup) => {
|
|
4003
4018
|
return definePlugin(
|
|
4004
4019
|
"pipeline",
|
|
4005
4020
|
(builder, config, context) => {
|
|
4006
|
-
if (!
|
|
4021
|
+
if (!Guards62.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4007
4022
|
const options = {};
|
|
4008
|
-
if (
|
|
4023
|
+
if (Guards62.isDefined(setup)) setup(options, config);
|
|
4009
4024
|
const logger = builder.resolve(TOKENS15.LOGGER);
|
|
4010
4025
|
context.addCommon(
|
|
4011
4026
|
new PerformancePipeline(logger, options?.intentThresholdMs, options?.thresholdMs ?? 500),
|
|
@@ -4016,12 +4031,12 @@ var withPerformance = (setup) => {
|
|
|
4016
4031
|
};
|
|
4017
4032
|
|
|
4018
4033
|
// src/infrastructure/plugin/query.plugin.ts
|
|
4019
|
-
import { Guards as
|
|
4034
|
+
import { Guards as Guards63 } from "@xeno-js/shared";
|
|
4020
4035
|
var withQueryCaching = () => {
|
|
4021
4036
|
return definePlugin(
|
|
4022
4037
|
"pipeline",
|
|
4023
4038
|
(_builder, _config, context) => {
|
|
4024
|
-
if (!
|
|
4039
|
+
if (!Guards63.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4025
4040
|
context.addQuery();
|
|
4026
4041
|
}
|
|
4027
4042
|
);
|
|
@@ -4029,16 +4044,16 @@ var withQueryCaching = () => {
|
|
|
4029
4044
|
|
|
4030
4045
|
// src/infrastructure/plugin/validation.plugin.ts
|
|
4031
4046
|
import {
|
|
4032
|
-
Guards as
|
|
4047
|
+
Guards as Guards64
|
|
4033
4048
|
} from "@xeno-js/shared";
|
|
4034
4049
|
var withValidation = (setup) => {
|
|
4035
4050
|
return definePlugin(
|
|
4036
4051
|
"pipeline",
|
|
4037
4052
|
(_builder, config, context) => {
|
|
4038
|
-
if (!
|
|
4053
|
+
if (!Guards64.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4039
4054
|
const strategies = [];
|
|
4040
4055
|
setup(strategies, config);
|
|
4041
|
-
if (
|
|
4056
|
+
if (Guards64.isNullOrEmpty(strategies)) return;
|
|
4042
4057
|
const validationPipeline = new ValidationPipeline(strategies);
|
|
4043
4058
|
context.addCommon(validationPipeline, 50);
|
|
4044
4059
|
}
|
|
@@ -4046,7 +4061,7 @@ var withValidation = (setup) => {
|
|
|
4046
4061
|
};
|
|
4047
4062
|
|
|
4048
4063
|
// src/infrastructure/xeno_application/xeno.application.ts
|
|
4049
|
-
import { AppError as AppError17, Guards as
|
|
4064
|
+
import { AppError as AppError17, Guards as Guards65, GUEST as GUEST5, GuidHelper as GuidHelper13 } from "@xeno-js/shared";
|
|
4050
4065
|
import { TOKENS as TOKENS16 } from "@xeno-js/shared";
|
|
4051
4066
|
var XenoApplication = class {
|
|
4052
4067
|
constructor(_container) {
|
|
@@ -4073,7 +4088,7 @@ var XenoApplication = class {
|
|
|
4073
4088
|
const serviceProxy = this._container.resolve(TOKENS16.SERVICE_PROXY);
|
|
4074
4089
|
const requestContext = this._container.resolve(TOKENS16.REQUEST_CONTEXT);
|
|
4075
4090
|
const scope = requestContext.getScope();
|
|
4076
|
-
if (!
|
|
4091
|
+
if (!Guards65.isDefined(scope)) {
|
|
4077
4092
|
throw AppError17.notFound(
|
|
4078
4093
|
"[XenoApplication Error]",
|
|
4079
4094
|
'Active scope not found.\nPlease use the "runInScope" or "handle" method for tasks outside the HTTP transport.'
|
|
@@ -4150,7 +4165,7 @@ var XenoAppBuilder = class {
|
|
|
4150
4165
|
this._container.addSingleton(TOKENS17.CONFIGURATION_SERVICE, () => this._configuration);
|
|
4151
4166
|
}
|
|
4152
4167
|
_getConfigurationService(service) {
|
|
4153
|
-
if (!
|
|
4168
|
+
if (!Guards66.isDefined(service) || service === "node")
|
|
4154
4169
|
return new EnvironmentConfigurationService();
|
|
4155
4170
|
if (service === "vite") return new ViteConfigurationService();
|
|
4156
4171
|
return service;
|
|
@@ -4238,7 +4253,7 @@ var XenoAppBuilder = class {
|
|
|
4238
4253
|
*/
|
|
4239
4254
|
addMiddlewares(setupAction) {
|
|
4240
4255
|
if (this._isMiddlewareModuleQueued) return this;
|
|
4241
|
-
if (
|
|
4256
|
+
if (Guards66.isDefined(setupAction)) setupAction(this._middlewareConfig, this._configuration);
|
|
4242
4257
|
this._modules.push({
|
|
4243
4258
|
priority: 4,
|
|
4244
4259
|
name: "MiddlewareModule",
|
|
@@ -4264,7 +4279,7 @@ var XenoAppBuilder = class {
|
|
|
4264
4279
|
*/
|
|
4265
4280
|
addContext(plugin) {
|
|
4266
4281
|
if (this._isContextModuleQueued) return this;
|
|
4267
|
-
if (
|
|
4282
|
+
if (Guards66.isDefined(plugin)) plugin(this, this._configuration);
|
|
4268
4283
|
else
|
|
4269
4284
|
this._modules.push({
|
|
4270
4285
|
priority: 0,
|
|
@@ -4279,7 +4294,7 @@ var XenoAppBuilder = class {
|
|
|
4279
4294
|
}
|
|
4280
4295
|
addLogger(pluginOrSetup) {
|
|
4281
4296
|
if (this._isLoggerModuleQueued) return this;
|
|
4282
|
-
if (!
|
|
4297
|
+
if (!Guards66.isDefined(pluginOrSetup)) {
|
|
4283
4298
|
this._modules.push({
|
|
4284
4299
|
priority: 1,
|
|
4285
4300
|
name: "LoggerModule",
|
|
@@ -4293,7 +4308,7 @@ var XenoAppBuilder = class {
|
|
|
4293
4308
|
});
|
|
4294
4309
|
}
|
|
4295
4310
|
});
|
|
4296
|
-
} else if (
|
|
4311
|
+
} else if (Guards66.isArray(pluginOrSetup)) {
|
|
4297
4312
|
this._modules.push({
|
|
4298
4313
|
priority: 1,
|
|
4299
4314
|
name: "LoggerModule",
|
|
@@ -4347,7 +4362,7 @@ var XenoAppBuilder = class {
|
|
|
4347
4362
|
}
|
|
4348
4363
|
addCache(pluginOrSetup) {
|
|
4349
4364
|
if (this._isCacheModuleQueued) return this;
|
|
4350
|
-
if (!
|
|
4365
|
+
if (!Guards66.isDefined(pluginOrSetup))
|
|
4351
4366
|
this._modules.push({
|
|
4352
4367
|
priority: 2,
|
|
4353
4368
|
name: "CacheModule",
|
|
@@ -4444,8 +4459,8 @@ var XenoAppBuilder = class {
|
|
|
4444
4459
|
*/
|
|
4445
4460
|
addPipeline(pluginOrPlugins) {
|
|
4446
4461
|
if (this._isPipelineModuleQueued) return this;
|
|
4447
|
-
if (
|
|
4448
|
-
this._pipelinePlugins =
|
|
4462
|
+
if (Guards66.isDefined(pluginOrPlugins))
|
|
4463
|
+
this._pipelinePlugins = Guards66.isArray(pluginOrPlugins) ? pluginOrPlugins : [pluginOrPlugins];
|
|
4449
4464
|
this._modules.push({
|
|
4450
4465
|
priority: 5,
|
|
4451
4466
|
name: "CqrsModule",
|
|
@@ -4546,7 +4561,7 @@ var XenoAppBuilder = class {
|
|
|
4546
4561
|
* @link https://github.com/xeno-js/xeno-js
|
|
4547
4562
|
*/
|
|
4548
4563
|
build() {
|
|
4549
|
-
if (
|
|
4564
|
+
if (Guards66.isDefined(this._buildPromise)) {
|
|
4550
4565
|
return this._buildPromise;
|
|
4551
4566
|
}
|
|
4552
4567
|
const attempt = this._executeBuild();
|
|
@@ -4592,21 +4607,21 @@ var XenoAppBuilder = class {
|
|
|
4592
4607
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
4593
4608
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
4594
4609
|
`);
|
|
4595
|
-
if (error instanceof Error &&
|
|
4610
|
+
if (error instanceof Error && Guards66.isDefined(error.stack)) {
|
|
4596
4611
|
console.error(error.stack);
|
|
4597
4612
|
}
|
|
4598
4613
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
4599
4614
|
}
|
|
4600
4615
|
}
|
|
4601
4616
|
console.info("\u2705 Application modules bootstrapped successfully.");
|
|
4602
|
-
if (
|
|
4617
|
+
if (Guards66.isDefined(this._appFactory)) return this._appFactory(this._container);
|
|
4603
4618
|
return new XenoApplication(this._container);
|
|
4604
4619
|
}
|
|
4605
4620
|
};
|
|
4606
4621
|
|
|
4607
4622
|
// src/infrastructure/repositories/read-dao.ts
|
|
4608
4623
|
import { AppError as AppError18, Result as Result18 } from "@xeno-js/shared";
|
|
4609
|
-
import { Guards as
|
|
4624
|
+
import { Guards as Guards67 } from "@xeno-js/shared";
|
|
4610
4625
|
var ReadDao = class {
|
|
4611
4626
|
/**
|
|
4612
4627
|
* Constructs a new ReadDao instance.
|
|
@@ -4628,7 +4643,7 @@ var ReadDao = class {
|
|
|
4628
4643
|
async findById(id, ctx, signal) {
|
|
4629
4644
|
AppError18.throwIfAborted(signal, "ReadDao.findById");
|
|
4630
4645
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
4631
|
-
if (
|
|
4646
|
+
if (Guards67.isNullOrEmpty(result)) return Result18.ok();
|
|
4632
4647
|
const entity = this._mapper.toEntity(result);
|
|
4633
4648
|
return Result18.ok(entity);
|
|
4634
4649
|
}
|
|
@@ -4642,7 +4657,7 @@ var ReadDao = class {
|
|
|
4642
4657
|
|
|
4643
4658
|
// src/infrastructure/repositories/repository.ts
|
|
4644
4659
|
import { AppError as AppError19, Result as Result19 } from "@xeno-js/shared";
|
|
4645
|
-
import { Guards as
|
|
4660
|
+
import { Guards as Guards68 } from "@xeno-js/shared";
|
|
4646
4661
|
var Repository = class {
|
|
4647
4662
|
/**
|
|
4648
4663
|
* Constructs a new Repository instance.
|
|
@@ -4664,7 +4679,7 @@ var Repository = class {
|
|
|
4664
4679
|
async findById(id, ctx, signal) {
|
|
4665
4680
|
AppError19.throwIfAborted(signal, "Repository.findById");
|
|
4666
4681
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
4667
|
-
if (
|
|
4682
|
+
if (Guards68.isNullOrEmpty(result)) return Result19.ok();
|
|
4668
4683
|
const entity = this._mapper.toEntity(result);
|
|
4669
4684
|
return Result19.ok(entity);
|
|
4670
4685
|
}
|