@xeno-js/core 1.0.0 → 1.2.0
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/README.md +6 -7
- package/dist/index.cjs +1545 -1224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -3
- package/dist/index.d.ts +100 -3
- package/dist/index.js +1336 -1014
- package/dist/index.js.map +1 -1
- package/package.json +11 -1
package/dist/index.cjs
CHANGED
|
@@ -69,8 +69,10 @@ var init_container_utils = __esm({
|
|
|
69
69
|
* @throws Error If the service is not a scoped service.
|
|
70
70
|
*/
|
|
71
71
|
async runExecute(res, req, container, action) {
|
|
72
|
+
const adapter = container.resolve("HTTP_ADAPTER");
|
|
73
|
+
const { request, response } = adapter.adapt(req, res);
|
|
72
74
|
const middleware = container.resolve(import_shared.TOKENS.MIDDLEWARE);
|
|
73
|
-
return await middleware.execute(
|
|
75
|
+
return await middleware.execute(request, response, async () => {
|
|
74
76
|
return await action();
|
|
75
77
|
});
|
|
76
78
|
}
|
|
@@ -1258,470 +1260,193 @@ var init_application = __esm({
|
|
|
1258
1260
|
}
|
|
1259
1261
|
});
|
|
1260
1262
|
|
|
1261
|
-
// src/infrastructure/
|
|
1262
|
-
var
|
|
1263
|
-
__export(
|
|
1264
|
-
|
|
1265
|
-
});
|
|
1266
|
-
var import_shared34, ConsoleLogger;
|
|
1267
|
-
var init_console_logger = __esm({
|
|
1268
|
-
"src/infrastructure/loggers/console.logger.ts"() {
|
|
1269
|
-
"use strict";
|
|
1270
|
-
import_shared34 = require("@xeno-js/shared");
|
|
1271
|
-
ConsoleLogger = class {
|
|
1272
|
-
/**
|
|
1273
|
-
* 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.
|
|
1274
|
-
* @param _minLevel The minimum log level for logging messages. Messages with a log level below this threshold will not be logged. Default is LOG_LEVEL.DEBUG.
|
|
1275
|
-
|
|
1276
|
-
*
|
|
1277
|
-
* @author Xeno
|
|
1278
|
-
* @version 1.0.0
|
|
1279
|
-
* @since 2025-09-30
|
|
1280
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1281
|
-
*/
|
|
1282
|
-
constructor(_minLevel = import_shared34.LOG_LEVEL.DEBUG) {
|
|
1283
|
-
this._minLevel = _minLevel;
|
|
1284
|
-
}
|
|
1285
|
-
_minLevel;
|
|
1286
|
-
track(level, message, context, error = void 0) {
|
|
1287
|
-
if (level < this._minLevel) return;
|
|
1288
|
-
const logMessage = `[${level}] ${message}`;
|
|
1289
|
-
const payload = import_shared34.Guards.isDefined(error) ? { ...context, error } : context;
|
|
1290
|
-
switch (level) {
|
|
1291
|
-
case import_shared34.LOG_LEVEL.ERROR:
|
|
1292
|
-
console.error(logMessage, payload ?? {});
|
|
1293
|
-
break;
|
|
1294
|
-
case import_shared34.LOG_LEVEL.WARN:
|
|
1295
|
-
console.warn(logMessage, payload ?? {});
|
|
1296
|
-
break;
|
|
1297
|
-
case import_shared34.LOG_LEVEL.DEBUG:
|
|
1298
|
-
console.debug(logMessage, payload ?? {});
|
|
1299
|
-
break;
|
|
1300
|
-
default:
|
|
1301
|
-
console.info(logMessage, payload ?? {});
|
|
1302
|
-
break;
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
};
|
|
1306
|
-
}
|
|
1307
|
-
});
|
|
1308
|
-
|
|
1309
|
-
// src/infrastructure/loggers/sentry.logger.ts
|
|
1310
|
-
var import_shared35, SentryLogger;
|
|
1311
|
-
var init_sentry_logger = __esm({
|
|
1312
|
-
"src/infrastructure/loggers/sentry.logger.ts"() {
|
|
1313
|
-
"use strict";
|
|
1314
|
-
import_shared35 = require("@xeno-js/shared");
|
|
1315
|
-
SentryLogger = class {
|
|
1316
|
-
constructor(_client, _minLevel) {
|
|
1317
|
-
this._client = _client;
|
|
1318
|
-
this._minLevel = _minLevel;
|
|
1319
|
-
}
|
|
1320
|
-
_client;
|
|
1321
|
-
_minLevel;
|
|
1322
|
-
track(level, message, context = void 0, error = void 0) {
|
|
1323
|
-
if (level < this._minLevel) return;
|
|
1324
|
-
if (level === import_shared35.LOG_LEVEL.ERROR || level === import_shared35.LOG_LEVEL.WARN) {
|
|
1325
|
-
this._client.withScope((scope) => {
|
|
1326
|
-
if (import_shared35.Guards.isDefined(context)) scope.setExtras(context);
|
|
1327
|
-
if (import_shared35.Guards.isDefined(error)) {
|
|
1328
|
-
this._client.captureException(error);
|
|
1329
|
-
} else {
|
|
1330
|
-
this._client.captureMessage(message, "warning");
|
|
1331
|
-
}
|
|
1332
|
-
});
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
});
|
|
1338
|
-
|
|
1339
|
-
// src/infrastructure/factories/sentry-logger.factory.ts
|
|
1340
|
-
var sentry_logger_factory_exports = {};
|
|
1341
|
-
__export(sentry_logger_factory_exports, {
|
|
1342
|
-
SentryLoggerFactory: () => SentryLoggerFactory
|
|
1343
|
-
});
|
|
1344
|
-
var Sentry, import_shared36, SentryLoggerFactory;
|
|
1345
|
-
var init_sentry_logger_factory = __esm({
|
|
1346
|
-
"src/infrastructure/factories/sentry-logger.factory.ts"() {
|
|
1347
|
-
"use strict";
|
|
1348
|
-
Sentry = __toESM(require("@sentry/node"), 1);
|
|
1349
|
-
import_shared36 = require("@xeno-js/shared");
|
|
1350
|
-
init_sentry_logger();
|
|
1351
|
-
SentryLoggerFactory = class {
|
|
1352
|
-
create(config) {
|
|
1353
|
-
const level = config.level ?? import_shared36.LOG_LEVEL.WARN;
|
|
1354
|
-
const sentryConfig = config.sentry?.config;
|
|
1355
|
-
const env = sentryConfig?.environment ?? process.env.NODE_ENV ?? "development";
|
|
1356
|
-
if (!import_shared36.Guards.isDefined(sentryConfig))
|
|
1357
|
-
throw new Error("Sentry configuration is required when Sentry logging is enabled.");
|
|
1358
|
-
if (!import_shared36.Guards.isDefined(sentryConfig.dsn))
|
|
1359
|
-
throw new Error("Sentry DSN is required when Sentry logging is enabled.");
|
|
1360
|
-
Sentry.init({
|
|
1361
|
-
dsn: sentryConfig.dsn,
|
|
1362
|
-
environment: env,
|
|
1363
|
-
tracesSampleRate: env === "production" ? 0.1 : 1,
|
|
1364
|
-
integrations: [Sentry.httpIntegration()],
|
|
1365
|
-
beforeSend(event, hint) {
|
|
1366
|
-
const error = hint.originalException;
|
|
1367
|
-
if (error instanceof Error && error.name === "ZodError") {
|
|
1368
|
-
return null;
|
|
1369
|
-
}
|
|
1370
|
-
return event;
|
|
1371
|
-
}
|
|
1372
|
-
});
|
|
1373
|
-
return new SentryLogger(Sentry, level);
|
|
1374
|
-
}
|
|
1375
|
-
};
|
|
1376
|
-
}
|
|
1263
|
+
// src/infrastructure/factories/service-scope.factory.ts
|
|
1264
|
+
var service_scope_factory_exports = {};
|
|
1265
|
+
__export(service_scope_factory_exports, {
|
|
1266
|
+
ServiceScopeFactory: () => ServiceScopeFactory
|
|
1377
1267
|
});
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
var init_pino_logger = __esm({
|
|
1382
|
-
"src/infrastructure/loggers/pino.logger.ts"() {
|
|
1268
|
+
var ServiceScopeFactory;
|
|
1269
|
+
var init_service_scope_factory = __esm({
|
|
1270
|
+
"src/infrastructure/factories/service-scope.factory.ts"() {
|
|
1383
1271
|
"use strict";
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
* Constructs a new instance of the PinoTransport class, which takes an optional minimum log level and an optional instance of the Pino logger. If no logger instance is provided, it initializes a new Pino logger with default settings. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.
|
|
1388
|
-
* @param _logger The Pino logger instance used for logging messages.
|
|
1389
|
-
* @param _minLevel The minimum log level for logging messages. Messages with a log level below this threshold will not be logged. Default is LOG_LEVEL.DEBUG.
|
|
1390
|
-
|
|
1391
|
-
*
|
|
1392
|
-
* @author Xeno
|
|
1393
|
-
* @version 1.0.0
|
|
1394
|
-
* @since 2025-09-30
|
|
1395
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1396
|
-
*/
|
|
1397
|
-
constructor(_logger, _minLevel = import_shared37.LOG_LEVEL.DEBUG) {
|
|
1398
|
-
this._logger = _logger;
|
|
1399
|
-
this._minLevel = _minLevel;
|
|
1400
|
-
}
|
|
1401
|
-
_logger;
|
|
1402
|
-
_minLevel;
|
|
1403
|
-
track(level, message, context, error = void 0) {
|
|
1404
|
-
if (level < this._minLevel) return;
|
|
1405
|
-
const payload = import_shared37.Guards.isDefined(error) ? { ...context, error } : context;
|
|
1406
|
-
switch (level) {
|
|
1407
|
-
case import_shared37.LOG_LEVEL.ERROR:
|
|
1408
|
-
this._logger.error(payload ?? {}, message);
|
|
1409
|
-
break;
|
|
1410
|
-
case import_shared37.LOG_LEVEL.WARN:
|
|
1411
|
-
this._logger.warn(payload ?? {}, message);
|
|
1412
|
-
break;
|
|
1413
|
-
case import_shared37.LOG_LEVEL.DEBUG:
|
|
1414
|
-
this._logger.debug(payload ?? {}, message);
|
|
1415
|
-
break;
|
|
1416
|
-
default:
|
|
1417
|
-
this._logger.info(payload ?? {}, message);
|
|
1418
|
-
break;
|
|
1419
|
-
}
|
|
1272
|
+
ServiceScopeFactory = class {
|
|
1273
|
+
constructor(_container) {
|
|
1274
|
+
this._container = _container;
|
|
1420
1275
|
}
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
// src/infrastructure/factories/pino-logger.factory.ts
|
|
1426
|
-
var pino_logger_factory_exports = {};
|
|
1427
|
-
__export(pino_logger_factory_exports, {
|
|
1428
|
-
PinoLoggerFactory: () => PinoLoggerFactory
|
|
1429
|
-
});
|
|
1430
|
-
var import_shared38, import_pino, PinoLoggerFactory;
|
|
1431
|
-
var init_pino_logger_factory = __esm({
|
|
1432
|
-
"src/infrastructure/factories/pino-logger.factory.ts"() {
|
|
1433
|
-
"use strict";
|
|
1434
|
-
import_shared38 = require("@xeno-js/shared");
|
|
1435
|
-
import_pino = __toESM(require("pino"), 1);
|
|
1436
|
-
init_pino_logger();
|
|
1437
|
-
PinoLoggerFactory = class {
|
|
1438
|
-
create(config) {
|
|
1439
|
-
const level = config.level ?? import_shared38.LOG_LEVEL.DEBUG;
|
|
1440
|
-
const env = config.pino.config?.env ?? process.env.NODE_ENV ?? "development";
|
|
1441
|
-
const destinationType = config.pino.config?.destination ?? "stdout";
|
|
1442
|
-
const filePath = config.pino.config?.filePath ?? "logs/app.log";
|
|
1443
|
-
const prettyPrint = config.pino.config?.prettyPrint ?? env === "development";
|
|
1444
|
-
const options = {
|
|
1445
|
-
level: "trace",
|
|
1446
|
-
serializers: {
|
|
1447
|
-
err: import_pino.default.stdSerializers.err
|
|
1448
|
-
},
|
|
1449
|
-
timestamp: import_pino.default.stdTimeFunctions.isoTime,
|
|
1450
|
-
redact: {
|
|
1451
|
-
paths: ["password", "token", "secret", "authorization", "headers.authorization"],
|
|
1452
|
-
censor: "***"
|
|
1453
|
-
}
|
|
1454
|
-
};
|
|
1455
|
-
if (prettyPrint) {
|
|
1456
|
-
return new PinoLogger(
|
|
1457
|
-
(0, import_pino.default)({
|
|
1458
|
-
...options,
|
|
1459
|
-
transport: {
|
|
1460
|
-
target: "pino-pretty",
|
|
1461
|
-
options: {
|
|
1462
|
-
colorize: true,
|
|
1463
|
-
ignore: "pid,hostname",
|
|
1464
|
-
translateTime: "SYS:standard"
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
}),
|
|
1468
|
-
level
|
|
1469
|
-
);
|
|
1470
|
-
}
|
|
1471
|
-
if (destinationType === "file") {
|
|
1472
|
-
const destination = import_pino.default.destination({ dest: filePath, sync: false });
|
|
1473
|
-
return new PinoLogger((0, import_pino.default)(options, destination), level);
|
|
1474
|
-
} else {
|
|
1475
|
-
const stream = import_pino.default.destination({ dest: 1, sync: false });
|
|
1476
|
-
return new PinoLogger((0, import_pino.default)(options, stream), level);
|
|
1477
|
-
}
|
|
1276
|
+
_container;
|
|
1277
|
+
create() {
|
|
1278
|
+
return this._container.createScope();
|
|
1478
1279
|
}
|
|
1479
1280
|
};
|
|
1480
1281
|
}
|
|
1481
1282
|
});
|
|
1482
1283
|
|
|
1483
|
-
// src/infrastructure/
|
|
1484
|
-
var
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
});
|
|
1488
|
-
var LoggerUtils;
|
|
1489
|
-
var init_logger_utils = __esm({
|
|
1490
|
-
"src/infrastructure/modules/utils/logger.utils.ts"() {
|
|
1284
|
+
// src/infrastructure/context/request-context.ts
|
|
1285
|
+
var import_shared34, NodeRequestContext;
|
|
1286
|
+
var init_request_context = __esm({
|
|
1287
|
+
"src/infrastructure/context/request-context.ts"() {
|
|
1491
1288
|
"use strict";
|
|
1492
|
-
|
|
1289
|
+
import_shared34 = require("@xeno-js/shared");
|
|
1290
|
+
NodeRequestContext = class {
|
|
1493
1291
|
/**
|
|
1494
|
-
* @description
|
|
1292
|
+
* @description Constructs a new instance of the NodeRequestContext class, which requires an instance of AsyncLocalStorage to manage the request context. The AsyncLocalStorage instance is used to create and access the context for each request, allowing for the storage of identity information and other relevant data that needs to be accessible across asynchronous operations. This constructor initializes the NodeRequestContext with the provided AsyncLocalStorage, enabling it to implement the methods defined in the IRequestContext interface for managing request-specific context data.
|
|
1293
|
+
* @param _storage An instance of AsyncLocalStorage that is used to manage the request context, allowing for the storage and retrieval of identity information and other relevant data across asynchronous operations.
|
|
1294
|
+
* @param _factoryScope An instance of IFactory that is used to create a new IServiceScope for managing service dependencies during the execution of the request. This allows for proper scoping and disposal of services after the request is processed, ensuring that resources are managed efficiently and preventing memory leaks.
|
|
1495
1295
|
*
|
|
1496
|
-
* @param container - The service container to register logging services with.
|
|
1497
|
-
* @param opts - The LoggerConfig options to determine which loggers to enable and their configurations.
|
|
1498
|
-
|
|
1499
|
-
*
|
|
1500
|
-
* @author Xeno
|
|
1501
|
-
* @version 1.0.0
|
|
1502
|
-
* @since 2025-09-30
|
|
1503
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1504
|
-
*/
|
|
1505
|
-
async addLogger(container, opts) {
|
|
1506
|
-
const loggerDependencies = [];
|
|
1507
|
-
const { Guards: Guards46, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
1508
|
-
if (!Guards46.isDefined(opts) || opts.console) {
|
|
1509
|
-
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
1510
|
-
loggerDependencies.push(new ConsoleLogger2(opts?.level));
|
|
1511
|
-
}
|
|
1512
|
-
if (Guards46.isDefined(opts)) {
|
|
1513
|
-
if (Guards46.isDefined(opts.sentry.config)) {
|
|
1514
|
-
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
1515
|
-
loggerDependencies.push(new SentryLoggerFactory2().create(opts));
|
|
1516
|
-
}
|
|
1517
|
-
if (Guards46.isDefined(opts.pino.config)) {
|
|
1518
|
-
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
1519
|
-
loggerDependencies.push(new PinoLoggerFactory2().create(opts));
|
|
1520
|
-
}
|
|
1521
|
-
if (!Guards46.isNullOrEmpty(opts.customLoggers)) {
|
|
1522
|
-
const customLoggers = opts.customLoggers;
|
|
1523
|
-
customLoggers.forEach((fn) => {
|
|
1524
|
-
if (Guards46.isDefined(fn)) loggerDependencies.push(fn(container));
|
|
1525
|
-
});
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
const { BaseLogger } = await import("@xeno-js/shared");
|
|
1529
|
-
container.addSingleton(TOKENS4.LOGGER, (c) => {
|
|
1530
|
-
const context = c.resolve(TOKENS4.CONTEXT_ACCESSOR);
|
|
1531
|
-
return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, loggerDependencies);
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
|
-
});
|
|
1535
|
-
}
|
|
1536
|
-
});
|
|
1537
|
-
|
|
1538
|
-
// src/infrastructure/cache/inmemory.cache.ts
|
|
1539
|
-
var inmemory_cache_exports = {};
|
|
1540
|
-
__export(inmemory_cache_exports, {
|
|
1541
|
-
InMemoryCacheExtended: () => InMemoryCacheExtended
|
|
1542
|
-
});
|
|
1543
|
-
var import_shared39, InMemoryCacheExtended;
|
|
1544
|
-
var init_inmemory_cache = __esm({
|
|
1545
|
-
"src/infrastructure/cache/inmemory.cache.ts"() {
|
|
1546
|
-
"use strict";
|
|
1547
|
-
import_shared39 = require("@xeno-js/shared");
|
|
1548
|
-
InMemoryCacheExtended = class extends import_shared39.InMemoryCache {
|
|
1549
|
-
async increment(key, ttlSeconds) {
|
|
1550
|
-
const current = await this.get(key) ?? 0;
|
|
1551
|
-
const next = Number(current) + 1;
|
|
1552
|
-
const ttl = import_shared39.Guards.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
1553
|
-
await this.set(key, next, ttl);
|
|
1554
|
-
return next;
|
|
1555
|
-
}
|
|
1556
|
-
};
|
|
1557
|
-
}
|
|
1558
|
-
});
|
|
1559
|
-
|
|
1560
|
-
// src/infrastructure/cache/redis.cache.ts
|
|
1561
|
-
var import_shared40, RedisCache;
|
|
1562
|
-
var init_redis_cache = __esm({
|
|
1563
|
-
"src/infrastructure/cache/redis.cache.ts"() {
|
|
1564
|
-
"use strict";
|
|
1565
|
-
import_shared40 = require("@xeno-js/shared");
|
|
1566
|
-
RedisCache = class {
|
|
1567
|
-
/**
|
|
1568
|
-
* @description Constructs a new instance of the RedisCache class, which takes an instance of the Redis client as a parameter. This client is used to perform caching operations such as setting, getting, and removing values from the Redis database. The constructor initializes the RedisCache with the provided Redis client, allowing it to interact with the Redis server for all caching operations defined in the ICache interface.
|
|
1569
|
-
* @param _redisClient An instance of the Redis client from the ioredis library, used to perform caching operations in the Redis database.
|
|
1570
|
-
|
|
1571
|
-
*
|
|
1572
1296
|
* @author Xeno
|
|
1573
1297
|
* @version 1.0.0
|
|
1574
1298
|
* @since 2025-09-30
|
|
1575
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1299
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
1576
1300
|
*/
|
|
1577
|
-
constructor(
|
|
1578
|
-
this.
|
|
1579
|
-
|
|
1580
|
-
_redisClient;
|
|
1581
|
-
async increment(key, ttlSeconds) {
|
|
1582
|
-
const multi = this._redisClient.multi();
|
|
1583
|
-
multi.incr(key);
|
|
1584
|
-
multi.expire(key, ttlSeconds ?? 60);
|
|
1585
|
-
const results = await multi.exec();
|
|
1586
|
-
return results?.[0]?.[1] ?? 1;
|
|
1301
|
+
constructor(_storage, _factoryScope) {
|
|
1302
|
+
this._storage = _storage;
|
|
1303
|
+
this._factoryScope = _factoryScope;
|
|
1587
1304
|
}
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1305
|
+
_storage;
|
|
1306
|
+
_factoryScope;
|
|
1307
|
+
async runAsync(context, fn) {
|
|
1308
|
+
const scope = this._factoryScope.create();
|
|
1309
|
+
try {
|
|
1310
|
+
return await this._storage.run({ context, scope }, fn);
|
|
1311
|
+
} finally {
|
|
1312
|
+
await scope.dispose();
|
|
1592
1313
|
}
|
|
1593
|
-
return JSON.parse(value);
|
|
1594
|
-
}
|
|
1595
|
-
async set(key, value, ttl) {
|
|
1596
|
-
const stringValue = import_shared40.StringHelper.safeStringify(value);
|
|
1597
|
-
const ttlOption = import_shared40.Guards.isDefined(ttl) ? ttl : 86400;
|
|
1598
|
-
await this._redisClient.set(key, stringValue, "EX", ttlOption);
|
|
1599
1314
|
}
|
|
1600
|
-
|
|
1601
|
-
const
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1315
|
+
updateIdentity(identity) {
|
|
1316
|
+
const store = this._storage.getStore();
|
|
1317
|
+
if (import_shared34.Guards.isDefined(store) && import_shared34.Guards.isDefined(store.context)) {
|
|
1318
|
+
store.context = Object.freeze({
|
|
1319
|
+
...store.context,
|
|
1320
|
+
identity: Object.freeze(identity)
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1605
1323
|
}
|
|
1606
|
-
|
|
1607
|
-
|
|
1324
|
+
getContext() {
|
|
1325
|
+
const store = this._storage.getStore();
|
|
1326
|
+
if (!import_shared34.Guards.isDefined(store)) return void 0;
|
|
1327
|
+
const context = store.context;
|
|
1328
|
+
return Object.freeze(context);
|
|
1608
1329
|
}
|
|
1609
|
-
|
|
1610
|
-
const
|
|
1611
|
-
return
|
|
1330
|
+
getIdentity() {
|
|
1331
|
+
const store = this._storage.getStore();
|
|
1332
|
+
if (!import_shared34.Guards.isDefined(store)) return void 0;
|
|
1333
|
+
return Object.freeze(store.context?.identity);
|
|
1612
1334
|
}
|
|
1613
|
-
|
|
1614
|
-
|
|
1335
|
+
getScope() {
|
|
1336
|
+
const store = this._storage.getStore();
|
|
1337
|
+
if (!import_shared34.Guards.isDefined(store)) return void 0;
|
|
1338
|
+
return store.scope;
|
|
1339
|
+
}
|
|
1340
|
+
getNetworkContext() {
|
|
1341
|
+
const store = this._storage.getStore();
|
|
1342
|
+
if (!import_shared34.Guards.isDefined(store)) return void 0;
|
|
1343
|
+
return Object.freeze(store.context?.network);
|
|
1615
1344
|
}
|
|
1616
1345
|
};
|
|
1617
1346
|
}
|
|
1618
1347
|
});
|
|
1619
1348
|
|
|
1620
|
-
// src/infrastructure/factories/
|
|
1621
|
-
var
|
|
1622
|
-
__export(
|
|
1623
|
-
|
|
1349
|
+
// src/infrastructure/factories/request-context.factory.ts
|
|
1350
|
+
var request_context_factory_exports = {};
|
|
1351
|
+
__export(request_context_factory_exports, {
|
|
1352
|
+
NodeRequestContextFactory: () => NodeRequestContextFactory
|
|
1624
1353
|
});
|
|
1625
|
-
var
|
|
1626
|
-
var
|
|
1627
|
-
"src/infrastructure/factories/
|
|
1354
|
+
var import_node_async_hooks2, NodeRequestContextFactory;
|
|
1355
|
+
var init_request_context_factory = __esm({
|
|
1356
|
+
"src/infrastructure/factories/request-context.factory.ts"() {
|
|
1628
1357
|
"use strict";
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
const maxRetries = config?.maxRetriesPerRequest ?? 3;
|
|
1640
|
-
const redisOptions = {
|
|
1641
|
-
host,
|
|
1642
|
-
port,
|
|
1643
|
-
maxRetriesPerRequest: maxRetries,
|
|
1644
|
-
// Strategia di riconnessione esponenziale per garantire resilienza
|
|
1645
|
-
retryStrategy(times) {
|
|
1646
|
-
const delay = Math.min(times * 50, 2e3);
|
|
1647
|
-
return delay;
|
|
1648
|
-
}
|
|
1649
|
-
};
|
|
1650
|
-
if (import_shared41.Guards.isDefined(password)) {
|
|
1651
|
-
redisOptions.password = password;
|
|
1652
|
-
}
|
|
1653
|
-
if (import_shared41.Guards.isDefined(username)) {
|
|
1654
|
-
redisOptions.username = username;
|
|
1655
|
-
}
|
|
1656
|
-
if (useTls) {
|
|
1657
|
-
redisOptions.tls = {};
|
|
1658
|
-
}
|
|
1659
|
-
const nativeRedisInstance = new import_ioredis.Redis(redisOptions);
|
|
1660
|
-
nativeRedisInstance.on("error", (err) => {
|
|
1661
|
-
console.error("\u274C [Redis Error]:", err.message);
|
|
1662
|
-
});
|
|
1663
|
-
return new RedisCache(nativeRedisInstance);
|
|
1358
|
+
import_node_async_hooks2 = require("async_hooks");
|
|
1359
|
+
init_request_context();
|
|
1360
|
+
NodeRequestContextFactory = class {
|
|
1361
|
+
constructor(_factoryScope) {
|
|
1362
|
+
this._factoryScope = _factoryScope;
|
|
1363
|
+
}
|
|
1364
|
+
_factoryScope;
|
|
1365
|
+
_store = new import_node_async_hooks2.AsyncLocalStorage();
|
|
1366
|
+
create() {
|
|
1367
|
+
return new NodeRequestContext(this._store, this._factoryScope);
|
|
1664
1368
|
}
|
|
1665
1369
|
};
|
|
1666
1370
|
}
|
|
1667
1371
|
});
|
|
1668
1372
|
|
|
1669
|
-
// src/infrastructure/
|
|
1670
|
-
var
|
|
1671
|
-
__export(
|
|
1672
|
-
|
|
1373
|
+
// src/infrastructure/factories/user-context.factory.ts
|
|
1374
|
+
var user_context_factory_exports = {};
|
|
1375
|
+
__export(user_context_factory_exports, {
|
|
1376
|
+
UserContextFactory: () => UserContextFactory
|
|
1673
1377
|
});
|
|
1674
|
-
var
|
|
1675
|
-
var
|
|
1676
|
-
"src/infrastructure/
|
|
1378
|
+
var import_shared35, UserContextFactory;
|
|
1379
|
+
var init_user_context_factory = __esm({
|
|
1380
|
+
"src/infrastructure/factories/user-context.factory.ts"() {
|
|
1677
1381
|
"use strict";
|
|
1678
|
-
|
|
1382
|
+
import_shared35 = require("@xeno-js/shared");
|
|
1383
|
+
UserContextFactory = class {
|
|
1679
1384
|
/**
|
|
1680
|
-
* @description
|
|
1681
|
-
* @param
|
|
1682
|
-
* @param opts The cache configuration options.
|
|
1683
|
-
* @returns True if any cache strategies are required, false otherwise.
|
|
1385
|
+
* @description Constructs an instance of UserContextFactory.
|
|
1386
|
+
* @param _identityFactory - An instance of IIdentityAccessor that provides access to the current identity. This factory is used to retrieve the identity details when creating a UserContext instance.
|
|
1684
1387
|
*
|
|
1685
1388
|
* @author Xeno
|
|
1686
1389
|
* @version 1.0.0
|
|
1687
1390
|
* @since 2025-09-30
|
|
1688
1391
|
* @link https://github.com/xeno-js/xeno-js
|
|
1689
1392
|
*/
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
1704
|
-
container.addSingleton(TOKENS4.CACHE, () => new InMemoryCacheExtended2());
|
|
1705
|
-
return;
|
|
1706
|
-
}
|
|
1707
|
-
if (Guards46.isDefined(opts.redis)) {
|
|
1708
|
-
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
1709
|
-
container.addSingleton(TOKENS4.CACHE, () => {
|
|
1710
|
-
const config = opts.redis;
|
|
1711
|
-
return new RedisCacheFactory2().create(config);
|
|
1712
|
-
});
|
|
1393
|
+
constructor(_identityFactory) {
|
|
1394
|
+
this._identityFactory = _identityFactory;
|
|
1395
|
+
}
|
|
1396
|
+
_identityFactory;
|
|
1397
|
+
create() {
|
|
1398
|
+
const output = {
|
|
1399
|
+
userId: void 0,
|
|
1400
|
+
tenantId: void 0
|
|
1401
|
+
};
|
|
1402
|
+
const identity = this._identityFactory.getIdentity();
|
|
1403
|
+
if (import_shared35.Guards.isDefined(identity)) {
|
|
1404
|
+
output.userId = identity.userId;
|
|
1405
|
+
output.tenantId = identity.tenantId;
|
|
1713
1406
|
}
|
|
1407
|
+
return output;
|
|
1714
1408
|
}
|
|
1715
|
-
}
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
});
|
|
1412
|
+
|
|
1413
|
+
// src/infrastructure/modules/context.module.ts
|
|
1414
|
+
var context_module_exports = {};
|
|
1415
|
+
__export(context_module_exports, {
|
|
1416
|
+
ContextModule: () => ContextModule
|
|
1417
|
+
});
|
|
1418
|
+
var ContextModule;
|
|
1419
|
+
var init_context_module = __esm({
|
|
1420
|
+
"src/infrastructure/modules/context.module.ts"() {
|
|
1421
|
+
"use strict";
|
|
1422
|
+
ContextModule = class {
|
|
1423
|
+
async configure(container) {
|
|
1424
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
1425
|
+
const { ServiceScopeFactory: ServiceScopeFactory2 } = await Promise.resolve().then(() => (init_service_scope_factory(), service_scope_factory_exports));
|
|
1426
|
+
const { NodeRequestContextFactory: NodeRequestContextFactory2 } = await Promise.resolve().then(() => (init_request_context_factory(), request_context_factory_exports));
|
|
1427
|
+
const requestContext = new NodeRequestContextFactory2(
|
|
1428
|
+
new ServiceScopeFactory2(container)
|
|
1429
|
+
).create();
|
|
1430
|
+
container.addSingleton(TOKENS5.REQUEST_CONTEXT, () => requestContext);
|
|
1431
|
+
container.addSingleton(TOKENS5.CONTEXT_ACCESSOR, () => requestContext);
|
|
1432
|
+
container.addSingleton(TOKENS5.IDENTITY_ACCESSOR, () => requestContext);
|
|
1433
|
+
container.addSingleton(TOKENS5.SERVICE_SCOPE_ACCESSOR, () => requestContext);
|
|
1434
|
+
container.addSingleton(TOKENS5.NETWORK_CONTEXT_ACCESSOR, () => requestContext);
|
|
1435
|
+
const { UserContextFactory: UserContextFactory2 } = await Promise.resolve().then(() => (init_user_context_factory(), user_context_factory_exports));
|
|
1436
|
+
container.addSingleton("USER_CONTEXT_FACTORY", () => {
|
|
1437
|
+
return new UserContextFactory2(requestContext);
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1716
1441
|
}
|
|
1717
1442
|
});
|
|
1718
1443
|
|
|
1719
1444
|
// src/infrastructure/services/allow_methods/allow-method.service.ts
|
|
1720
|
-
var
|
|
1445
|
+
var import_shared36, AllowMethodRegistry;
|
|
1721
1446
|
var init_allow_method_service = __esm({
|
|
1722
1447
|
"src/infrastructure/services/allow_methods/allow-method.service.ts"() {
|
|
1723
1448
|
"use strict";
|
|
1724
|
-
|
|
1449
|
+
import_shared36 = require("@xeno-js/shared");
|
|
1725
1450
|
AllowMethodRegistry = class {
|
|
1726
1451
|
_staticRoutes = /* @__PURE__ */ new Map();
|
|
1727
1452
|
_dynamicRoutes = [];
|
|
@@ -1737,7 +1462,7 @@ var init_allow_method_service = __esm({
|
|
|
1737
1462
|
check(path, method) {
|
|
1738
1463
|
const cleanPath = this.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1739
1464
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1740
|
-
if (
|
|
1465
|
+
if (import_shared36.Guards.isDefined(staticMethods)) return staticMethods.includes(method);
|
|
1741
1466
|
for (const route of this._dynamicRoutes) {
|
|
1742
1467
|
if (route.pattern.test(cleanPath)) return route.methods.includes(method);
|
|
1743
1468
|
}
|
|
@@ -1746,11 +1471,11 @@ var init_allow_method_service = __esm({
|
|
|
1746
1471
|
getMethods(path) {
|
|
1747
1472
|
const cleanPath = this.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1748
1473
|
const methods = this.findMethods(cleanPath);
|
|
1749
|
-
return
|
|
1474
|
+
return import_shared36.Guards.isDefined(methods) ? methods.join(", ").toUpperCase() : "";
|
|
1750
1475
|
}
|
|
1751
1476
|
findMethods(cleanPath) {
|
|
1752
1477
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1753
|
-
if (
|
|
1478
|
+
if (import_shared36.Guards.isDefined(staticMethods)) return staticMethods;
|
|
1754
1479
|
for (const route of this._dynamicRoutes) if (route.pattern.test(cleanPath)) return route.methods;
|
|
1755
1480
|
return void 0;
|
|
1756
1481
|
}
|
|
@@ -1785,18 +1510,18 @@ var init_allow_methods = __esm({
|
|
|
1785
1510
|
});
|
|
1786
1511
|
|
|
1787
1512
|
// src/infrastructure/services/allow_origins/allow-origin.http.ts
|
|
1788
|
-
var
|
|
1513
|
+
var import_shared37, AllowOrigin;
|
|
1789
1514
|
var init_allow_origin_http = __esm({
|
|
1790
1515
|
"src/infrastructure/services/allow_origins/allow-origin.http.ts"() {
|
|
1791
1516
|
"use strict";
|
|
1792
|
-
|
|
1517
|
+
import_shared37 = require("@xeno-js/shared");
|
|
1793
1518
|
AllowOrigin = class {
|
|
1794
1519
|
constructor(_list) {
|
|
1795
1520
|
this._list = _list;
|
|
1796
1521
|
}
|
|
1797
1522
|
_list;
|
|
1798
1523
|
isAllowed(origin) {
|
|
1799
|
-
if (
|
|
1524
|
+
if (import_shared37.Guards.isNullOrEmpty(origin)) return true;
|
|
1800
1525
|
const cleanOrigin = origin.trim().toLowerCase();
|
|
1801
1526
|
for (const pattern of this._list) {
|
|
1802
1527
|
const cleanPattern = pattern.trim().toLowerCase();
|
|
@@ -1806,7 +1531,7 @@ var init_allow_origin_http = __esm({
|
|
|
1806
1531
|
const domainSuffix = cleanPattern.substring(1);
|
|
1807
1532
|
if (cleanOrigin.endsWith(domainSuffix)) {
|
|
1808
1533
|
const prefix = cleanOrigin.slice(0, cleanOrigin.length - domainSuffix.length);
|
|
1809
|
-
if (!
|
|
1534
|
+
if (!import_shared37.Guards.isNullOrEmpty(prefix) && !prefix.includes(".")) return true;
|
|
1810
1535
|
}
|
|
1811
1536
|
}
|
|
1812
1537
|
}
|
|
@@ -1852,6 +1577,73 @@ var init_concurrency = __esm({
|
|
|
1852
1577
|
}
|
|
1853
1578
|
});
|
|
1854
1579
|
|
|
1580
|
+
// src/infrastructure/services/cookies/cookies.service.ts
|
|
1581
|
+
var import_shared38, CookieHandler;
|
|
1582
|
+
var init_cookies_service = __esm({
|
|
1583
|
+
"src/infrastructure/services/cookies/cookies.service.ts"() {
|
|
1584
|
+
"use strict";
|
|
1585
|
+
import_shared38 = require("@xeno-js/shared");
|
|
1586
|
+
CookieHandler = class {
|
|
1587
|
+
constructor(contextAccessor, _config, _cookieOpts) {
|
|
1588
|
+
this.contextAccessor = contextAccessor;
|
|
1589
|
+
this._config = _config;
|
|
1590
|
+
this._cookieOpts = _cookieOpts;
|
|
1591
|
+
}
|
|
1592
|
+
contextAccessor;
|
|
1593
|
+
_config;
|
|
1594
|
+
_cookieOpts;
|
|
1595
|
+
getAll() {
|
|
1596
|
+
const network = this.contextAccessor.getNetworkContext();
|
|
1597
|
+
const req = network?.transport?.req;
|
|
1598
|
+
if (!import_shared38.Guards.isDefined(req) || import_shared38.Guards.isNullOrEmpty(req.headers.get("cookie"))) return [];
|
|
1599
|
+
return req.headers.get("cookie")?.split(";").map((cookie) => {
|
|
1600
|
+
const [name, ...rest] = cookie.split("=");
|
|
1601
|
+
return { name: name.trim(), value: rest.join("=") };
|
|
1602
|
+
}) ?? [];
|
|
1603
|
+
}
|
|
1604
|
+
setAll(cookies) {
|
|
1605
|
+
const network = this.contextAccessor.getNetworkContext();
|
|
1606
|
+
const res = network?.transport?.res;
|
|
1607
|
+
if (!import_shared38.Guards.isDefined(res)) return;
|
|
1608
|
+
const serializedCookies = cookies.map((c) => this.serialize(c));
|
|
1609
|
+
const existingSetCookie = res.headers.getSetCookie();
|
|
1610
|
+
res.headers.delete("Set-Cookie");
|
|
1611
|
+
for (const cookie of [...existingSetCookie, ...serializedCookies]) {
|
|
1612
|
+
res.headers.append("Set-Cookie", cookie);
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
serialize(cookie) {
|
|
1616
|
+
const safeName = encodeURIComponent(cookie.name);
|
|
1617
|
+
const safeValue = encodeURIComponent(cookie.value);
|
|
1618
|
+
let str = `${safeName}=${safeValue}`;
|
|
1619
|
+
const isProd = this._config.get("NODE_ENV") === "production";
|
|
1620
|
+
const defaultOptions = {
|
|
1621
|
+
path: this._cookieOpts.path,
|
|
1622
|
+
httpOnly: this._cookieOpts.httpOnly,
|
|
1623
|
+
secure: this._cookieOpts.secure ?? isProd,
|
|
1624
|
+
sameSite: this._cookieOpts.sameSite ?? "Lax"
|
|
1625
|
+
};
|
|
1626
|
+
const opts = { ...defaultOptions, ...cookie.options ?? {} };
|
|
1627
|
+
str += `; Path=${opts.path}`;
|
|
1628
|
+
if (import_shared38.Guards.isDefined(opts.maxAge)) str += `; Max-Age=${opts.maxAge}`;
|
|
1629
|
+
if (import_shared38.Guards.isDefined(opts.domain)) str += `; Domain=${opts.domain}`;
|
|
1630
|
+
if (import_shared38.Guards.isDefined(opts.sameSite)) str += `; SameSite=${opts.sameSite}`;
|
|
1631
|
+
if (opts.secure) str += `; Secure`;
|
|
1632
|
+
if (opts.httpOnly) str += `; HttpOnly`;
|
|
1633
|
+
return str;
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
|
|
1639
|
+
// src/infrastructure/services/cookies/index.ts
|
|
1640
|
+
var init_cookies = __esm({
|
|
1641
|
+
"src/infrastructure/services/cookies/index.ts"() {
|
|
1642
|
+
"use strict";
|
|
1643
|
+
init_cookies_service();
|
|
1644
|
+
}
|
|
1645
|
+
});
|
|
1646
|
+
|
|
1855
1647
|
// src/infrastructure/services/crypto/crypto.service.ts
|
|
1856
1648
|
var EdgeCryptoService;
|
|
1857
1649
|
var init_crypto_service = __esm({
|
|
@@ -1900,11 +1692,11 @@ var init_crypto = __esm({
|
|
|
1900
1692
|
});
|
|
1901
1693
|
|
|
1902
1694
|
// src/infrastructure/services/csrf/csrf-token.service.ts
|
|
1903
|
-
var
|
|
1695
|
+
var import_shared39, CsrfTokenService;
|
|
1904
1696
|
var init_csrf_token_service = __esm({
|
|
1905
1697
|
"src/infrastructure/services/csrf/csrf-token.service.ts"() {
|
|
1906
1698
|
"use strict";
|
|
1907
|
-
|
|
1699
|
+
import_shared39 = require("@xeno-js/shared");
|
|
1908
1700
|
CsrfTokenService = class {
|
|
1909
1701
|
constructor(_secret, _cryptoService) {
|
|
1910
1702
|
this._secret = _secret;
|
|
@@ -1923,7 +1715,7 @@ var init_csrf_token_service = __esm({
|
|
|
1923
1715
|
if (separatorIndex <= 0) return false;
|
|
1924
1716
|
const nonce = token.slice(0, separatorIndex);
|
|
1925
1717
|
const signature = token.slice(separatorIndex + 1);
|
|
1926
|
-
if (
|
|
1718
|
+
if (import_shared39.Guards.isNullOrEmpty(nonce) || import_shared39.Guards.isNullOrEmpty(signature)) return false;
|
|
1927
1719
|
const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1928
1720
|
const encoder = new TextEncoder();
|
|
1929
1721
|
const actualBuffer = encoder.encode(signature);
|
|
@@ -1944,11 +1736,11 @@ var init_csrf = __esm({
|
|
|
1944
1736
|
});
|
|
1945
1737
|
|
|
1946
1738
|
// src/infrastructure/services/extractors/extract-bearer.extractor.ts
|
|
1947
|
-
var
|
|
1739
|
+
var import_shared40, BearerTokenExtractor;
|
|
1948
1740
|
var init_extract_bearer_extractor = __esm({
|
|
1949
1741
|
"src/infrastructure/services/extractors/extract-bearer.extractor.ts"() {
|
|
1950
1742
|
"use strict";
|
|
1951
|
-
|
|
1743
|
+
import_shared40 = require("@xeno-js/shared");
|
|
1952
1744
|
BearerTokenExtractor = class {
|
|
1953
1745
|
constructor(_cookiePrefix) {
|
|
1954
1746
|
this._cookiePrefix = _cookiePrefix;
|
|
@@ -1956,14 +1748,14 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1956
1748
|
_cookiePrefix;
|
|
1957
1749
|
extract(headers) {
|
|
1958
1750
|
const authHeader = headers.get("Authorization");
|
|
1959
|
-
if (
|
|
1751
|
+
if (import_shared40.Guards.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1960
1752
|
return authHeader.substring(7);
|
|
1961
1753
|
}
|
|
1962
1754
|
const cookieHeader = headers.get("cookie");
|
|
1963
|
-
if (
|
|
1755
|
+
if (import_shared40.Guards.isDefined(cookieHeader)) {
|
|
1964
1756
|
const regex = new RegExp(`${this._cookiePrefix}=([^;]+)`);
|
|
1965
1757
|
const match = regex.exec(cookieHeader);
|
|
1966
|
-
if (!
|
|
1758
|
+
if (!import_shared40.Guards.isNullOrEmpty(match) && import_shared40.Guards.isDefined(match[1])) {
|
|
1967
1759
|
return match[1].trim();
|
|
1968
1760
|
}
|
|
1969
1761
|
}
|
|
@@ -1974,44 +1766,44 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1974
1766
|
});
|
|
1975
1767
|
|
|
1976
1768
|
// src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts
|
|
1977
|
-
var
|
|
1769
|
+
var import_shared41, SupabaseSsrTokenExtractor;
|
|
1978
1770
|
var init_extract_ssr_bearer_extractor = __esm({
|
|
1979
1771
|
"src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts"() {
|
|
1980
1772
|
"use strict";
|
|
1981
|
-
|
|
1773
|
+
import_shared41 = require("@xeno-js/shared");
|
|
1982
1774
|
SupabaseSsrTokenExtractor = class {
|
|
1983
1775
|
extract(headers) {
|
|
1984
1776
|
const authHeader = headers.get("authorization");
|
|
1985
|
-
if (
|
|
1777
|
+
if (import_shared41.Guards.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1986
1778
|
return authHeader.substring(7);
|
|
1987
1779
|
}
|
|
1988
1780
|
const cookieHeader = headers.get("cookie");
|
|
1989
|
-
if (
|
|
1781
|
+
if (import_shared41.Guards.isNullOrEmpty(cookieHeader)) return void 0;
|
|
1990
1782
|
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
1991
1783
|
const tokenChunks = {};
|
|
1992
1784
|
let unchunkedToken;
|
|
1993
1785
|
for (const cookie of cookies) {
|
|
1994
1786
|
const [name, ...rest] = cookie.split("=");
|
|
1995
|
-
if (!
|
|
1787
|
+
if (!import_shared41.Guards.isDefined(name) || import_shared41.Guards.isNullOrEmpty(rest)) continue;
|
|
1996
1788
|
const value = decodeURIComponent(rest.join("="));
|
|
1997
|
-
if (
|
|
1789
|
+
if (import_shared41.Guards.isDefined(/^sb-[a-z0-9]+-auth-token$/.exec(name))) {
|
|
1998
1790
|
unchunkedToken = value;
|
|
1999
1791
|
} else {
|
|
2000
1792
|
const match = /^sb-[a-z0-9]+-auth-token\.(\d+)$/.exec(name);
|
|
2001
|
-
if (
|
|
1793
|
+
if (import_shared41.Guards.isDefined(match)) tokenChunks[parseInt(match[1], 10)] = value;
|
|
2002
1794
|
}
|
|
2003
1795
|
}
|
|
2004
1796
|
let fullTokenString = unchunkedToken;
|
|
2005
|
-
if (!
|
|
1797
|
+
if (!import_shared41.Guards.isDefined(fullTokenString) && Object.keys(tokenChunks).length > 0) {
|
|
2006
1798
|
const indices = Object.keys(tokenChunks).map(Number).sort((a, b) => a - b);
|
|
2007
1799
|
fullTokenString = indices.map((i) => tokenChunks[i]).join("");
|
|
2008
1800
|
}
|
|
2009
|
-
if (
|
|
1801
|
+
if (import_shared41.Guards.isNullOrEmpty(fullTokenString)) return void 0;
|
|
2010
1802
|
try {
|
|
2011
|
-
const parsed =
|
|
2012
|
-
if (
|
|
1803
|
+
const parsed = import_shared41.StringHelper.safeParse(fullTokenString);
|
|
1804
|
+
if (import_shared41.Guards.isDefined(parsed) && import_shared41.Guards.isObject(parsed) && "access_token" in parsed) {
|
|
2013
1805
|
const accessToken = parsed["access_token"];
|
|
2014
|
-
if (
|
|
1806
|
+
if (import_shared41.Guards.isString(accessToken)) return accessToken;
|
|
2015
1807
|
}
|
|
2016
1808
|
} catch {
|
|
2017
1809
|
return void 0;
|
|
@@ -2022,14 +1814,14 @@ var init_extract_ssr_bearer_extractor = __esm({
|
|
|
2022
1814
|
});
|
|
2023
1815
|
|
|
2024
1816
|
// src/infrastructure/services/extractors/http-cookie.extractor.ts
|
|
2025
|
-
var
|
|
1817
|
+
var import_shared42, HttpCookieExtractor;
|
|
2026
1818
|
var init_http_cookie_extractor = __esm({
|
|
2027
1819
|
"src/infrastructure/services/extractors/http-cookie.extractor.ts"() {
|
|
2028
1820
|
"use strict";
|
|
2029
|
-
|
|
1821
|
+
import_shared42 = require("@xeno-js/shared");
|
|
2030
1822
|
HttpCookieExtractor = class {
|
|
2031
1823
|
extract(cookie) {
|
|
2032
|
-
if (!
|
|
1824
|
+
if (!import_shared42.Guards.isDefined(cookie.header)) return void 0;
|
|
2033
1825
|
for (const rawCookie of cookie.header.split(";")) {
|
|
2034
1826
|
const separatorIndex = rawCookie.indexOf("=");
|
|
2035
1827
|
if (separatorIndex <= 0) continue;
|
|
@@ -2049,11 +1841,11 @@ var init_http_cookie_extractor = __esm({
|
|
|
2049
1841
|
});
|
|
2050
1842
|
|
|
2051
1843
|
// src/infrastructure/services/extractors/http-header.extractor.ts
|
|
2052
|
-
var
|
|
1844
|
+
var import_shared43, HttpHeaderExtractor;
|
|
2053
1845
|
var init_http_header_extractor = __esm({
|
|
2054
1846
|
"src/infrastructure/services/extractors/http-header.extractor.ts"() {
|
|
2055
1847
|
"use strict";
|
|
2056
|
-
|
|
1848
|
+
import_shared43 = require("@xeno-js/shared");
|
|
2057
1849
|
HttpHeaderExtractor = class {
|
|
2058
1850
|
/**
|
|
2059
1851
|
* @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.
|
|
@@ -2075,11 +1867,11 @@ var init_http_header_extractor = __esm({
|
|
|
2075
1867
|
_trustedIp;
|
|
2076
1868
|
_cookieName;
|
|
2077
1869
|
extract(headers) {
|
|
2078
|
-
const correlationId =
|
|
2079
|
-
const requestId =
|
|
1870
|
+
const correlationId = import_shared43.GuidHelper.parse(headers.get("x-correlation-id") ?? void 0);
|
|
1871
|
+
const requestId = import_shared43.GuidHelper.parse(headers.get("x-request-id") ?? void 0);
|
|
2080
1872
|
const token = this._bearerExtractor.extract(headers);
|
|
2081
1873
|
const clientIp = headers.get(this._trustedIp?.toLowerCase() ?? "x-forwarded-for") ?? headers.get("x-real-ip") ?? void 0;
|
|
2082
|
-
const spanId =
|
|
1874
|
+
const spanId = import_shared43.GuidHelper.parse(headers.get("x-span-id") ?? void 0);
|
|
2083
1875
|
const parentSpanId = headers.get("x-parent-span-id") ?? void 0;
|
|
2084
1876
|
const acceptHeader = headers.get("accept");
|
|
2085
1877
|
const contentTypeHeader = headers.get("content-type");
|
|
@@ -2096,9 +1888,9 @@ var init_http_header_extractor = __esm({
|
|
|
2096
1888
|
name: this._cookieName
|
|
2097
1889
|
});
|
|
2098
1890
|
const origin = headers.get("origin") ?? void 0;
|
|
2099
|
-
const cleanOrigin =
|
|
1891
|
+
const cleanOrigin = import_shared43.HttpHelper.sanitizeOriginUrl(origin);
|
|
2100
1892
|
const referer = headers.get("referer") ?? void 0;
|
|
2101
|
-
const cleanReferer =
|
|
1893
|
+
const cleanReferer = import_shared43.HttpHelper.sanitizeOriginUrl(referer);
|
|
2102
1894
|
const accept = acceptHeader === "*/*" ? void 0 : acceptHeader;
|
|
2103
1895
|
const formatIndicator = accept ?? contentTypeHeader ?? "application/json";
|
|
2104
1896
|
const metadata = {
|
|
@@ -2117,10 +1909,10 @@ var init_http_header_extractor = __esm({
|
|
|
2117
1909
|
referer: cleanReferer,
|
|
2118
1910
|
sequence: {
|
|
2119
1911
|
sequenceId,
|
|
2120
|
-
position:
|
|
2121
|
-
size:
|
|
1912
|
+
position: import_shared43.Guards.isDefined(position) ? import_shared43.MathHelper.toNumber(position) : void 0,
|
|
1913
|
+
size: import_shared43.Guards.isDefined(size) ? import_shared43.MathHelper.toNumber(size) : void 0
|
|
2122
1914
|
},
|
|
2123
|
-
expiration:
|
|
1915
|
+
expiration: import_shared43.Guards.isDefined(expiration) ? import_shared43.MathHelper.toNumber(expiration) : void 0
|
|
2124
1916
|
};
|
|
2125
1917
|
return metadata;
|
|
2126
1918
|
}
|
|
@@ -2140,18 +1932,18 @@ var init_extractors = __esm({
|
|
|
2140
1932
|
});
|
|
2141
1933
|
|
|
2142
1934
|
// src/infrastructure/services/resiliences/resilience.service.ts
|
|
2143
|
-
var
|
|
1935
|
+
var import_shared44, ServiceResilience;
|
|
2144
1936
|
var init_resilience_service = __esm({
|
|
2145
1937
|
"src/infrastructure/services/resiliences/resilience.service.ts"() {
|
|
2146
1938
|
"use strict";
|
|
2147
|
-
|
|
1939
|
+
import_shared44 = require("@xeno-js/shared");
|
|
2148
1940
|
ServiceResilience = class {
|
|
2149
1941
|
constructor(policy) {
|
|
2150
1942
|
this.policy = policy;
|
|
2151
1943
|
}
|
|
2152
1944
|
policy;
|
|
2153
1945
|
async execute(operation, signal) {
|
|
2154
|
-
|
|
1946
|
+
import_shared44.AppError.throwIfAborted(signal, "ServiceResilience.execute");
|
|
2155
1947
|
return this.policy.execute(() => operation(), signal);
|
|
2156
1948
|
}
|
|
2157
1949
|
};
|
|
@@ -2167,11 +1959,11 @@ var init_resiliences = __esm({
|
|
|
2167
1959
|
});
|
|
2168
1960
|
|
|
2169
1961
|
// src/infrastructure/services/resolver/utils/socket.utils.ts
|
|
2170
|
-
var
|
|
1962
|
+
var import_shared45, SocketIpExtractor;
|
|
2171
1963
|
var init_socket_utils = __esm({
|
|
2172
1964
|
"src/infrastructure/services/resolver/utils/socket.utils.ts"() {
|
|
2173
1965
|
"use strict";
|
|
2174
|
-
|
|
1966
|
+
import_shared45 = require("@xeno-js/shared");
|
|
2175
1967
|
SocketIpExtractor = Object.freeze({
|
|
2176
1968
|
/**
|
|
2177
1969
|
* @description Extracts the IP address of the remote socket from an incoming request.
|
|
@@ -2179,7 +1971,7 @@ var init_socket_utils = __esm({
|
|
|
2179
1971
|
* @returns The IP address of the remote socket, or undefined if not available.
|
|
2180
1972
|
*/
|
|
2181
1973
|
extract(req) {
|
|
2182
|
-
if (
|
|
1974
|
+
if (import_shared45.Guards.isDefined(req) && import_shared45.Guards.isObject(req)) {
|
|
2183
1975
|
const candidate = req;
|
|
2184
1976
|
return candidate.socket?.remoteAddress ?? candidate.connection?.remoteAddress;
|
|
2185
1977
|
}
|
|
@@ -2198,11 +1990,11 @@ var init_utils = __esm({
|
|
|
2198
1990
|
});
|
|
2199
1991
|
|
|
2200
1992
|
// src/infrastructure/services/resolver/client-ip.resolver.ts
|
|
2201
|
-
var
|
|
1993
|
+
var import_shared46, ClientIpResolver;
|
|
2202
1994
|
var init_client_ip_resolver = __esm({
|
|
2203
1995
|
"src/infrastructure/services/resolver/client-ip.resolver.ts"() {
|
|
2204
1996
|
"use strict";
|
|
2205
|
-
|
|
1997
|
+
import_shared46 = require("@xeno-js/shared");
|
|
2206
1998
|
init_utils();
|
|
2207
1999
|
ClientIpResolver = class {
|
|
2208
2000
|
constructor(_trustedProxies = []) {
|
|
@@ -2211,11 +2003,11 @@ var init_client_ip_resolver = __esm({
|
|
|
2211
2003
|
_trustedProxies;
|
|
2212
2004
|
resolve(req, clientIp) {
|
|
2213
2005
|
const socketIp = SocketIpExtractor.extract(req);
|
|
2214
|
-
if (!
|
|
2215
|
-
return !
|
|
2006
|
+
if (!import_shared46.Guards.isDefined(socketIp))
|
|
2007
|
+
return !import_shared46.Guards.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
2216
2008
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
2217
2009
|
if (!isTrustedProxy) return socketIp;
|
|
2218
|
-
if (
|
|
2010
|
+
if (import_shared46.Guards.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
2219
2011
|
return socketIp;
|
|
2220
2012
|
}
|
|
2221
2013
|
};
|
|
@@ -2237,6 +2029,7 @@ __export(services_exports, {
|
|
|
2237
2029
|
AllowOrigin: () => AllowOrigin,
|
|
2238
2030
|
BearerTokenExtractor: () => BearerTokenExtractor,
|
|
2239
2031
|
ClientIpResolver: () => ClientIpResolver,
|
|
2032
|
+
CookieHandler: () => CookieHandler,
|
|
2240
2033
|
CsrfTokenService: () => CsrfTokenService,
|
|
2241
2034
|
EdgeCryptoService: () => EdgeCryptoService,
|
|
2242
2035
|
HttpCookieExtractor: () => HttpCookieExtractor,
|
|
@@ -2251,6 +2044,7 @@ var init_services = __esm({
|
|
|
2251
2044
|
init_allow_methods();
|
|
2252
2045
|
init_allow_origins();
|
|
2253
2046
|
init_concurrency();
|
|
2047
|
+
init_cookies();
|
|
2254
2048
|
init_crypto();
|
|
2255
2049
|
init_csrf();
|
|
2256
2050
|
init_extractors();
|
|
@@ -2278,13 +2072,13 @@ var init_allow_method_factory = __esm({
|
|
|
2278
2072
|
});
|
|
2279
2073
|
|
|
2280
2074
|
// src/infrastructure/factories/axios.factory.ts
|
|
2281
|
-
var import_node_http, import_node_https,
|
|
2075
|
+
var import_node_http, import_node_https, import_shared47, import_axios, NodeAxiosFactory;
|
|
2282
2076
|
var init_axios_factory = __esm({
|
|
2283
2077
|
"src/infrastructure/factories/axios.factory.ts"() {
|
|
2284
2078
|
"use strict";
|
|
2285
2079
|
import_node_http = __toESM(require("http"), 1);
|
|
2286
2080
|
import_node_https = __toESM(require("https"), 1);
|
|
2287
|
-
|
|
2081
|
+
import_shared47 = require("@xeno-js/shared");
|
|
2288
2082
|
import_axios = __toESM(require("axios"), 1);
|
|
2289
2083
|
NodeAxiosFactory = class {
|
|
2290
2084
|
create(config) {
|
|
@@ -2311,18 +2105,18 @@ var init_axios_factory = __esm({
|
|
|
2311
2105
|
proxy: config.proxy,
|
|
2312
2106
|
withCredentials: config.withCredentials
|
|
2313
2107
|
});
|
|
2314
|
-
return new
|
|
2108
|
+
return new import_shared47.AxiosHttpClient(axiosInstance);
|
|
2315
2109
|
}
|
|
2316
2110
|
};
|
|
2317
2111
|
}
|
|
2318
2112
|
});
|
|
2319
2113
|
|
|
2320
2114
|
// src/infrastructure/factories/cockatiel-resilience.factory.ts
|
|
2321
|
-
var
|
|
2115
|
+
var import_shared48, import_cockatiel, CockatielResilienceFactory;
|
|
2322
2116
|
var init_cockatiel_resilience_factory = __esm({
|
|
2323
2117
|
"src/infrastructure/factories/cockatiel-resilience.factory.ts"() {
|
|
2324
2118
|
"use strict";
|
|
2325
|
-
|
|
2119
|
+
import_shared48 = require("@xeno-js/shared");
|
|
2326
2120
|
import_cockatiel = require("cockatiel");
|
|
2327
2121
|
init_resilience_service();
|
|
2328
2122
|
CockatielResilienceFactory = class {
|
|
@@ -2332,36 +2126,36 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2332
2126
|
retry: {
|
|
2333
2127
|
attempts: this.checkConfigValue(
|
|
2334
2128
|
config.retry.attempts,
|
|
2335
|
-
|
|
2129
|
+
import_shared48.RESILIENCE_DEFAULTS.RETRY.ATTEMPTS,
|
|
2336
2130
|
message
|
|
2337
2131
|
),
|
|
2338
2132
|
baseDelayMs: this.checkConfigValue(
|
|
2339
2133
|
config.retry.baseDelayMs,
|
|
2340
|
-
|
|
2134
|
+
import_shared48.RESILIENCE_DEFAULTS.RETRY.BASE_DELAY_MS,
|
|
2341
2135
|
message
|
|
2342
2136
|
),
|
|
2343
2137
|
maxDelayMs: this.checkConfigValue(
|
|
2344
2138
|
config.retry.maxDelayMs,
|
|
2345
|
-
|
|
2139
|
+
import_shared48.RESILIENCE_DEFAULTS.RETRY.MAX_DELAY_MS,
|
|
2346
2140
|
message
|
|
2347
2141
|
)
|
|
2348
2142
|
},
|
|
2349
2143
|
circuitBreaker: {
|
|
2350
2144
|
consecutiveFailures: this.checkConfigValue(
|
|
2351
2145
|
config.circuitBreaker.consecutiveFailures,
|
|
2352
|
-
|
|
2146
|
+
import_shared48.RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.CONSECUTIVE_FAILURES,
|
|
2353
2147
|
message
|
|
2354
2148
|
),
|
|
2355
2149
|
halfOpenTimeoutMs: this.checkConfigValue(
|
|
2356
2150
|
config.circuitBreaker.halfOpenTimeoutMs,
|
|
2357
|
-
|
|
2151
|
+
import_shared48.RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.HALF_OPEN_TIMEOUT_MS,
|
|
2358
2152
|
message
|
|
2359
2153
|
)
|
|
2360
2154
|
},
|
|
2361
2155
|
bulkhead: {
|
|
2362
2156
|
maxConcurrent: this.checkConfigValue(
|
|
2363
2157
|
config.bulkhead.maxConcurrent,
|
|
2364
|
-
|
|
2158
|
+
import_shared48.RESILIENCE_DEFAULTS.BULKHEAD.MAX_CONCURRENT,
|
|
2365
2159
|
message
|
|
2366
2160
|
)
|
|
2367
2161
|
}
|
|
@@ -2387,13 +2181,13 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2387
2181
|
return new ServiceResilience((0, import_cockatiel.wrap)(bulkheadPolicy, circuitBreakerPolicy, retryPolicy));
|
|
2388
2182
|
}
|
|
2389
2183
|
isTransientError(error) {
|
|
2390
|
-
if (!
|
|
2184
|
+
if (!import_shared48.Guards.isDefined(error) || !import_shared48.Guards.isObject(error)) return false;
|
|
2391
2185
|
let status;
|
|
2392
2186
|
let isNetworkError = false;
|
|
2393
|
-
if (error instanceof
|
|
2187
|
+
if (error instanceof import_shared48.AppError) {
|
|
2394
2188
|
status = error.status;
|
|
2395
2189
|
const cause = error.cause;
|
|
2396
|
-
if (
|
|
2190
|
+
if (import_shared48.Guards.isDefined(cause) && import_shared48.Guards.isString(cause.code)) {
|
|
2397
2191
|
isNetworkError = [
|
|
2398
2192
|
"ECONNABORTED",
|
|
2399
2193
|
"ECONNRESET",
|
|
@@ -2405,7 +2199,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2405
2199
|
} else {
|
|
2406
2200
|
const err = error;
|
|
2407
2201
|
status = err.status;
|
|
2408
|
-
if (
|
|
2202
|
+
if (import_shared48.Guards.isString(err.code)) {
|
|
2409
2203
|
isNetworkError = [
|
|
2410
2204
|
"ECONNABORTED",
|
|
2411
2205
|
"ECONNRESET",
|
|
@@ -2416,165 +2210,338 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2416
2210
|
}
|
|
2417
2211
|
}
|
|
2418
2212
|
if (isNetworkError) return true;
|
|
2419
|
-
if (
|
|
2213
|
+
if (import_shared48.Guards.isDefined(status)) return status === 408 || status >= 500 && status < 600;
|
|
2420
2214
|
return false;
|
|
2421
2215
|
}
|
|
2422
2216
|
isTransientAndIdempotent(error) {
|
|
2423
2217
|
if (!this.isTransientError(error)) return false;
|
|
2424
2218
|
let method;
|
|
2425
|
-
if (error instanceof
|
|
2219
|
+
if (error instanceof import_shared48.AppError) {
|
|
2426
2220
|
const cause = error.cause;
|
|
2427
|
-
if (
|
|
2221
|
+
if (import_shared48.Guards.isDefined(cause) && import_shared48.Guards.isDefined(cause.config) && import_shared48.Guards.isString(cause.config.method)) {
|
|
2428
2222
|
method = cause.config.method.toUpperCase();
|
|
2429
2223
|
}
|
|
2430
2224
|
} else {
|
|
2431
2225
|
const err = error;
|
|
2432
|
-
if (
|
|
2226
|
+
if (import_shared48.Guards.isDefined(err.config) && import_shared48.Guards.isString(err.config.method)) {
|
|
2433
2227
|
method = err.config.method.toUpperCase();
|
|
2434
2228
|
}
|
|
2435
2229
|
}
|
|
2436
|
-
if (
|
|
2230
|
+
if (import_shared48.Guards.isNullOrEmpty(method)) return false;
|
|
2437
2231
|
const idempotentMethods = ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
|
|
2438
2232
|
return idempotentMethods.includes(method);
|
|
2439
2233
|
}
|
|
2440
2234
|
checkConfigValue(value, defaultValue, message) {
|
|
2441
|
-
if (
|
|
2442
|
-
|
|
2235
|
+
if (import_shared48.Guards.isDefined(value)) {
|
|
2236
|
+
import_shared48.Guards.throwIfNegative(value, message);
|
|
2443
2237
|
return value;
|
|
2444
2238
|
}
|
|
2445
|
-
return defaultValue;
|
|
2239
|
+
return defaultValue;
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
|
|
2245
|
+
// src/infrastructure/factories/db-client.factory.ts
|
|
2246
|
+
var db_client_factory_exports = {};
|
|
2247
|
+
__export(db_client_factory_exports, {
|
|
2248
|
+
DbClientFactory: () => DbClientFactory
|
|
2249
|
+
});
|
|
2250
|
+
var import_node_postgres, import_pg, DbClientFactory;
|
|
2251
|
+
var init_db_client_factory = __esm({
|
|
2252
|
+
"src/infrastructure/factories/db-client.factory.ts"() {
|
|
2253
|
+
"use strict";
|
|
2254
|
+
import_node_postgres = require("drizzle-orm/node-postgres");
|
|
2255
|
+
import_pg = require("pg");
|
|
2256
|
+
DbClientFactory = class {
|
|
2257
|
+
create(opts) {
|
|
2258
|
+
const pool = new import_pg.Pool({
|
|
2259
|
+
connectionString: opts.connectionString
|
|
2260
|
+
});
|
|
2261
|
+
return (0, import_node_postgres.drizzle)({ client: pool });
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
}
|
|
2265
|
+
});
|
|
2266
|
+
|
|
2267
|
+
// src/infrastructure/loggers/pino.logger.ts
|
|
2268
|
+
var import_shared49, PinoLogger;
|
|
2269
|
+
var init_pino_logger = __esm({
|
|
2270
|
+
"src/infrastructure/loggers/pino.logger.ts"() {
|
|
2271
|
+
"use strict";
|
|
2272
|
+
import_shared49 = require("@xeno-js/shared");
|
|
2273
|
+
PinoLogger = class {
|
|
2274
|
+
/**
|
|
2275
|
+
* Constructs a new instance of the PinoTransport class, which takes an optional minimum log level and an optional instance of the Pino logger. If no logger instance is provided, it initializes a new Pino logger with default settings. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.
|
|
2276
|
+
* @param _logger The Pino logger instance used for logging messages.
|
|
2277
|
+
* @param _minLevel The minimum log level for logging messages. Messages with a log level below this threshold will not be logged. Default is LOG_LEVEL.DEBUG.
|
|
2278
|
+
|
|
2279
|
+
*
|
|
2280
|
+
* @author Xeno
|
|
2281
|
+
* @version 1.0.0
|
|
2282
|
+
* @since 2025-09-30
|
|
2283
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2284
|
+
*/
|
|
2285
|
+
constructor(_logger, _minLevel = import_shared49.LOG_LEVEL.DEBUG) {
|
|
2286
|
+
this._logger = _logger;
|
|
2287
|
+
this._minLevel = _minLevel;
|
|
2288
|
+
}
|
|
2289
|
+
_logger;
|
|
2290
|
+
_minLevel;
|
|
2291
|
+
track(level, message, context, error = void 0) {
|
|
2292
|
+
if (level < this._minLevel) return;
|
|
2293
|
+
const payload = import_shared49.Guards.isDefined(error) ? { ...context, error } : context;
|
|
2294
|
+
switch (level) {
|
|
2295
|
+
case import_shared49.LOG_LEVEL.ERROR:
|
|
2296
|
+
this._logger.error(payload ?? {}, message);
|
|
2297
|
+
break;
|
|
2298
|
+
case import_shared49.LOG_LEVEL.WARN:
|
|
2299
|
+
this._logger.warn(payload ?? {}, message);
|
|
2300
|
+
break;
|
|
2301
|
+
case import_shared49.LOG_LEVEL.DEBUG:
|
|
2302
|
+
this._logger.debug(payload ?? {}, message);
|
|
2303
|
+
break;
|
|
2304
|
+
default:
|
|
2305
|
+
this._logger.info(payload ?? {}, message);
|
|
2306
|
+
break;
|
|
2307
|
+
}
|
|
2446
2308
|
}
|
|
2447
2309
|
};
|
|
2448
2310
|
}
|
|
2449
2311
|
});
|
|
2450
2312
|
|
|
2451
|
-
// src/infrastructure/factories/
|
|
2452
|
-
var
|
|
2453
|
-
__export(
|
|
2454
|
-
|
|
2313
|
+
// src/infrastructure/factories/pino-logger.factory.ts
|
|
2314
|
+
var pino_logger_factory_exports = {};
|
|
2315
|
+
__export(pino_logger_factory_exports, {
|
|
2316
|
+
PinoLoggerFactory: () => PinoLoggerFactory
|
|
2455
2317
|
});
|
|
2456
|
-
var
|
|
2457
|
-
var
|
|
2458
|
-
"src/infrastructure/factories/
|
|
2318
|
+
var import_shared50, import_pino, PinoLoggerFactory;
|
|
2319
|
+
var init_pino_logger_factory = __esm({
|
|
2320
|
+
"src/infrastructure/factories/pino-logger.factory.ts"() {
|
|
2459
2321
|
"use strict";
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2322
|
+
import_shared50 = require("@xeno-js/shared");
|
|
2323
|
+
import_pino = __toESM(require("pino"), 1);
|
|
2324
|
+
init_pino_logger();
|
|
2325
|
+
PinoLoggerFactory = class {
|
|
2326
|
+
create(config) {
|
|
2327
|
+
const level = config.level ?? import_shared50.LOG_LEVEL.DEBUG;
|
|
2328
|
+
const env = config.pino.config?.env ?? process.env.NODE_ENV ?? "development";
|
|
2329
|
+
const destinationType = config.pino.config?.destination ?? "stdout";
|
|
2330
|
+
const filePath = config.pino.config?.filePath ?? "logs/app.log";
|
|
2331
|
+
const prettyPrint = config.pino.config?.prettyPrint ?? env === "development";
|
|
2332
|
+
const options = {
|
|
2333
|
+
level: "trace",
|
|
2334
|
+
serializers: {
|
|
2335
|
+
err: import_pino.default.stdSerializers.err
|
|
2336
|
+
},
|
|
2337
|
+
timestamp: import_pino.default.stdTimeFunctions.isoTime,
|
|
2338
|
+
redact: {
|
|
2339
|
+
paths: ["password", "token", "secret", "authorization", "headers.authorization"],
|
|
2340
|
+
censor: "***"
|
|
2341
|
+
}
|
|
2342
|
+
};
|
|
2343
|
+
if (prettyPrint) {
|
|
2344
|
+
return new PinoLogger(
|
|
2345
|
+
(0, import_pino.default)({
|
|
2346
|
+
...options,
|
|
2347
|
+
transport: {
|
|
2348
|
+
target: "pino-pretty",
|
|
2349
|
+
options: {
|
|
2350
|
+
colorize: true,
|
|
2351
|
+
ignore: "pid,hostname",
|
|
2352
|
+
translateTime: "SYS:standard"
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
}),
|
|
2356
|
+
level
|
|
2357
|
+
);
|
|
2358
|
+
}
|
|
2359
|
+
if (destinationType === "file") {
|
|
2360
|
+
const destination = import_pino.default.destination({ dest: filePath, sync: false });
|
|
2361
|
+
return new PinoLogger((0, import_pino.default)(options, destination), level);
|
|
2362
|
+
} else {
|
|
2363
|
+
const stream = import_pino.default.destination({ dest: 1, sync: false });
|
|
2364
|
+
return new PinoLogger((0, import_pino.default)(options, stream), level);
|
|
2365
|
+
}
|
|
2468
2366
|
}
|
|
2469
2367
|
};
|
|
2470
2368
|
}
|
|
2471
2369
|
});
|
|
2472
2370
|
|
|
2473
|
-
// src/infrastructure/
|
|
2474
|
-
var
|
|
2475
|
-
var
|
|
2476
|
-
"src/infrastructure/
|
|
2371
|
+
// src/infrastructure/cache/redis.cache.ts
|
|
2372
|
+
var import_shared51, RedisCache;
|
|
2373
|
+
var init_redis_cache = __esm({
|
|
2374
|
+
"src/infrastructure/cache/redis.cache.ts"() {
|
|
2477
2375
|
"use strict";
|
|
2478
|
-
|
|
2479
|
-
|
|
2376
|
+
import_shared51 = require("@xeno-js/shared");
|
|
2377
|
+
RedisCache = class {
|
|
2480
2378
|
/**
|
|
2481
|
-
* @description Constructs a new instance of the
|
|
2482
|
-
* @param
|
|
2483
|
-
|
|
2484
|
-
*
|
|
2379
|
+
* @description Constructs a new instance of the RedisCache class, which takes an instance of the Redis client as a parameter. This client is used to perform caching operations such as setting, getting, and removing values from the Redis database. The constructor initializes the RedisCache with the provided Redis client, allowing it to interact with the Redis server for all caching operations defined in the ICache interface.
|
|
2380
|
+
* @param _redisClient An instance of the Redis client from the ioredis library, used to perform caching operations in the Redis database.
|
|
2381
|
+
|
|
2382
|
+
*
|
|
2485
2383
|
* @author Xeno
|
|
2486
2384
|
* @version 1.0.0
|
|
2487
2385
|
* @since 2025-09-30
|
|
2488
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
2386
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2489
2387
|
*/
|
|
2490
|
-
constructor(
|
|
2491
|
-
this.
|
|
2492
|
-
this._factoryScope = _factoryScope;
|
|
2388
|
+
constructor(_redisClient) {
|
|
2389
|
+
this._redisClient = _redisClient;
|
|
2493
2390
|
}
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
await scope.dispose();
|
|
2502
|
-
}
|
|
2391
|
+
_redisClient;
|
|
2392
|
+
async increment(key, ttlSeconds) {
|
|
2393
|
+
const multi = this._redisClient.multi();
|
|
2394
|
+
multi.incr(key);
|
|
2395
|
+
multi.expire(key, ttlSeconds ?? 60);
|
|
2396
|
+
const results = await multi.exec();
|
|
2397
|
+
return results?.[0]?.[1] ?? 1;
|
|
2503
2398
|
}
|
|
2504
|
-
|
|
2505
|
-
const
|
|
2506
|
-
if (
|
|
2507
|
-
|
|
2508
|
-
...store.context,
|
|
2509
|
-
identity: Object.freeze(identity)
|
|
2510
|
-
});
|
|
2399
|
+
async get(key) {
|
|
2400
|
+
const value = await this._redisClient.get(key);
|
|
2401
|
+
if (!import_shared51.Guards.isDefined(value)) {
|
|
2402
|
+
return void 0;
|
|
2511
2403
|
}
|
|
2404
|
+
return JSON.parse(value);
|
|
2512
2405
|
}
|
|
2513
|
-
|
|
2514
|
-
const
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
return Object.freeze(context);
|
|
2406
|
+
async set(key, value, ttl) {
|
|
2407
|
+
const stringValue = import_shared51.StringHelper.safeStringify(value);
|
|
2408
|
+
const ttlOption = import_shared51.Guards.isDefined(ttl) ? ttl : 86400;
|
|
2409
|
+
await this._redisClient.set(key, stringValue, "EX", ttlOption);
|
|
2518
2410
|
}
|
|
2519
|
-
|
|
2520
|
-
const
|
|
2521
|
-
|
|
2522
|
-
|
|
2411
|
+
async setIfAbsent(key, value, ttl) {
|
|
2412
|
+
const stringValue = import_shared51.StringHelper.safeStringify(value);
|
|
2413
|
+
const ttlOption = import_shared51.Guards.isDefined(ttl) ? ttl : 300;
|
|
2414
|
+
const result = await this._redisClient.set(key, stringValue, "EX", ttlOption, "NX");
|
|
2415
|
+
return result === "OK";
|
|
2523
2416
|
}
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
if (!import_shared54.Guards.isDefined(store)) return void 0;
|
|
2527
|
-
return store.scope;
|
|
2417
|
+
async remove(key) {
|
|
2418
|
+
await this._redisClient.del(key);
|
|
2528
2419
|
}
|
|
2529
|
-
|
|
2530
|
-
const
|
|
2531
|
-
|
|
2532
|
-
|
|
2420
|
+
async has(key) {
|
|
2421
|
+
const exists = await this._redisClient.exists(key);
|
|
2422
|
+
return exists === 1;
|
|
2423
|
+
}
|
|
2424
|
+
async clear() {
|
|
2425
|
+
await this._redisClient.flushdb();
|
|
2533
2426
|
}
|
|
2534
2427
|
};
|
|
2535
2428
|
}
|
|
2536
2429
|
});
|
|
2537
2430
|
|
|
2538
|
-
// src/infrastructure/factories/
|
|
2539
|
-
var
|
|
2540
|
-
__export(
|
|
2541
|
-
|
|
2431
|
+
// src/infrastructure/factories/redis-cache.factory.ts
|
|
2432
|
+
var redis_cache_factory_exports = {};
|
|
2433
|
+
__export(redis_cache_factory_exports, {
|
|
2434
|
+
RedisCacheFactory: () => RedisCacheFactory
|
|
2542
2435
|
});
|
|
2543
|
-
var
|
|
2544
|
-
var
|
|
2545
|
-
"src/infrastructure/factories/
|
|
2436
|
+
var import_shared52, import_ioredis, RedisCacheFactory;
|
|
2437
|
+
var init_redis_cache_factory = __esm({
|
|
2438
|
+
"src/infrastructure/factories/redis-cache.factory.ts"() {
|
|
2546
2439
|
"use strict";
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2440
|
+
import_shared52 = require("@xeno-js/shared");
|
|
2441
|
+
import_ioredis = require("ioredis");
|
|
2442
|
+
init_redis_cache();
|
|
2443
|
+
RedisCacheFactory = class {
|
|
2444
|
+
create(config) {
|
|
2445
|
+
const host = config?.host ?? "localhost";
|
|
2446
|
+
const port = config?.port ?? 6379;
|
|
2447
|
+
const password = config?.password;
|
|
2448
|
+
const username = config?.username;
|
|
2449
|
+
const useTls = config?.tls ?? false;
|
|
2450
|
+
const maxRetries = config?.maxRetriesPerRequest ?? 3;
|
|
2451
|
+
const redisOptions = {
|
|
2452
|
+
host,
|
|
2453
|
+
port,
|
|
2454
|
+
maxRetriesPerRequest: maxRetries,
|
|
2455
|
+
// Strategia di riconnessione esponenziale per garantire resilienza
|
|
2456
|
+
retryStrategy(times) {
|
|
2457
|
+
const delay = Math.min(times * 50, 2e3);
|
|
2458
|
+
return delay;
|
|
2459
|
+
}
|
|
2460
|
+
};
|
|
2461
|
+
if (import_shared52.Guards.isDefined(password)) {
|
|
2462
|
+
redisOptions.password = password;
|
|
2463
|
+
}
|
|
2464
|
+
if (import_shared52.Guards.isDefined(username)) {
|
|
2465
|
+
redisOptions.username = username;
|
|
2466
|
+
}
|
|
2467
|
+
if (useTls) {
|
|
2468
|
+
redisOptions.tls = {};
|
|
2469
|
+
}
|
|
2470
|
+
const nativeRedisInstance = new import_ioredis.Redis(redisOptions);
|
|
2471
|
+
nativeRedisInstance.on("error", (err) => {
|
|
2472
|
+
console.error("\u274C [Redis Error]:", err.message);
|
|
2473
|
+
});
|
|
2474
|
+
return new RedisCache(nativeRedisInstance);
|
|
2552
2475
|
}
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2476
|
+
};
|
|
2477
|
+
}
|
|
2478
|
+
});
|
|
2479
|
+
|
|
2480
|
+
// src/infrastructure/loggers/sentry.logger.ts
|
|
2481
|
+
var import_shared53, SentryLogger;
|
|
2482
|
+
var init_sentry_logger = __esm({
|
|
2483
|
+
"src/infrastructure/loggers/sentry.logger.ts"() {
|
|
2484
|
+
"use strict";
|
|
2485
|
+
import_shared53 = require("@xeno-js/shared");
|
|
2486
|
+
SentryLogger = class {
|
|
2487
|
+
constructor(_client, _minLevel) {
|
|
2488
|
+
this._client = _client;
|
|
2489
|
+
this._minLevel = _minLevel;
|
|
2490
|
+
}
|
|
2491
|
+
_client;
|
|
2492
|
+
_minLevel;
|
|
2493
|
+
track(level, message, context = void 0, error = void 0) {
|
|
2494
|
+
if (level < this._minLevel) return;
|
|
2495
|
+
if (level === import_shared53.LOG_LEVEL.ERROR || level === import_shared53.LOG_LEVEL.WARN) {
|
|
2496
|
+
this._client.withScope((scope) => {
|
|
2497
|
+
if (import_shared53.Guards.isDefined(context)) scope.setExtras(context);
|
|
2498
|
+
if (import_shared53.Guards.isDefined(error)) {
|
|
2499
|
+
this._client.captureException(error);
|
|
2500
|
+
} else {
|
|
2501
|
+
this._client.captureMessage(message, "warning");
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2557
2505
|
}
|
|
2558
2506
|
};
|
|
2559
2507
|
}
|
|
2560
2508
|
});
|
|
2561
2509
|
|
|
2562
|
-
// src/infrastructure/factories/
|
|
2563
|
-
var
|
|
2564
|
-
__export(
|
|
2565
|
-
|
|
2510
|
+
// src/infrastructure/factories/sentry-logger.factory.ts
|
|
2511
|
+
var sentry_logger_factory_exports = {};
|
|
2512
|
+
__export(sentry_logger_factory_exports, {
|
|
2513
|
+
SentryLoggerFactory: () => SentryLoggerFactory
|
|
2566
2514
|
});
|
|
2567
|
-
var
|
|
2568
|
-
var
|
|
2569
|
-
"src/infrastructure/factories/
|
|
2515
|
+
var Sentry, import_shared54, SentryLoggerFactory;
|
|
2516
|
+
var init_sentry_logger_factory = __esm({
|
|
2517
|
+
"src/infrastructure/factories/sentry-logger.factory.ts"() {
|
|
2570
2518
|
"use strict";
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2519
|
+
Sentry = __toESM(require("@sentry/node"), 1);
|
|
2520
|
+
import_shared54 = require("@xeno-js/shared");
|
|
2521
|
+
init_sentry_logger();
|
|
2522
|
+
SentryLoggerFactory = class {
|
|
2523
|
+
create(config) {
|
|
2524
|
+
const level = config.level ?? import_shared54.LOG_LEVEL.WARN;
|
|
2525
|
+
const sentryConfig = config.sentry?.config;
|
|
2526
|
+
const env = sentryConfig?.environment ?? process.env.NODE_ENV ?? "development";
|
|
2527
|
+
if (!import_shared54.Guards.isDefined(sentryConfig))
|
|
2528
|
+
throw new Error("Sentry configuration is required when Sentry logging is enabled.");
|
|
2529
|
+
if (!import_shared54.Guards.isDefined(sentryConfig.dsn))
|
|
2530
|
+
throw new Error("Sentry DSN is required when Sentry logging is enabled.");
|
|
2531
|
+
Sentry.init({
|
|
2532
|
+
dsn: sentryConfig.dsn,
|
|
2533
|
+
environment: env,
|
|
2534
|
+
tracesSampleRate: env === "production" ? 0.1 : 1,
|
|
2535
|
+
integrations: [Sentry.httpIntegration()],
|
|
2536
|
+
beforeSend(event, hint) {
|
|
2537
|
+
const error = hint.originalException;
|
|
2538
|
+
if (error instanceof Error && error.name === "ZodError") {
|
|
2539
|
+
return null;
|
|
2540
|
+
}
|
|
2541
|
+
return event;
|
|
2542
|
+
}
|
|
2543
|
+
});
|
|
2544
|
+
return new SentryLogger(Sentry, level);
|
|
2578
2545
|
}
|
|
2579
2546
|
};
|
|
2580
2547
|
}
|
|
@@ -2607,85 +2574,45 @@ var init_supabase_factory = __esm({
|
|
|
2607
2574
|
"use strict";
|
|
2608
2575
|
import_ssr = require("@supabase/ssr");
|
|
2609
2576
|
import_shared55 = require("@xeno-js/shared");
|
|
2577
|
+
init_services();
|
|
2610
2578
|
SupabaseServerAuthFactory = class {
|
|
2611
2579
|
create({
|
|
2612
2580
|
config,
|
|
2613
2581
|
container
|
|
2614
2582
|
}) {
|
|
2615
|
-
|
|
2616
|
-
throw new Error(
|
|
2617
|
-
"ISsrCookieHandler is required for @supabase/ssr initialization., Please provide it in the config object."
|
|
2618
|
-
);
|
|
2619
|
-
}
|
|
2620
|
-
const cookieService = config.ssrOpts(container);
|
|
2583
|
+
const cookieService = this._getCookieSsr(config.ssrOpts, container, config.cookieOpts);
|
|
2621
2584
|
const client = (0, import_ssr.createServerClient)(config.url, config.key, {
|
|
2622
2585
|
...config.opts,
|
|
2623
|
-
cookies:
|
|
2624
|
-
getAll() {
|
|
2625
|
-
return cookieService.getAll();
|
|
2626
|
-
},
|
|
2627
|
-
setAll(cookiesToSet) {
|
|
2628
|
-
cookieService.setAll(cookiesToSet);
|
|
2629
|
-
}
|
|
2630
|
-
}
|
|
2586
|
+
cookies: cookieService
|
|
2631
2587
|
});
|
|
2632
2588
|
const mapper = new import_shared55.SupabaseClaimsMapper();
|
|
2633
2589
|
const sessionMapper = new import_shared55.SupabaseSessionMapper(mapper);
|
|
2634
2590
|
return new import_shared55.SupabaseAuthService(client, mapper, sessionMapper, config);
|
|
2635
2591
|
}
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
var import_shared56, UserContextFactory;
|
|
2646
|
-
var init_user_context_factory = __esm({
|
|
2647
|
-
"src/infrastructure/factories/user-context.factory.ts"() {
|
|
2648
|
-
"use strict";
|
|
2649
|
-
import_shared56 = require("@xeno-js/shared");
|
|
2650
|
-
UserContextFactory = class {
|
|
2651
|
-
/**
|
|
2652
|
-
* @description Constructs an instance of UserContextFactory.
|
|
2653
|
-
* @param _identityFactory - An instance of IIdentityAccessor that provides access to the current identity. This factory is used to retrieve the identity details when creating a UserContext instance.
|
|
2654
|
-
*
|
|
2655
|
-
* @author Xeno
|
|
2656
|
-
* @version 1.0.0
|
|
2657
|
-
* @since 2025-09-30
|
|
2658
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
2659
|
-
*/
|
|
2660
|
-
constructor(_identityFactory) {
|
|
2661
|
-
this._identityFactory = _identityFactory;
|
|
2662
|
-
}
|
|
2663
|
-
_identityFactory;
|
|
2664
|
-
create() {
|
|
2665
|
-
const output = {
|
|
2666
|
-
userId: void 0,
|
|
2667
|
-
tenantId: void 0
|
|
2668
|
-
};
|
|
2669
|
-
const identity = this._identityFactory.getIdentity();
|
|
2670
|
-
if (import_shared56.Guards.isDefined(identity)) {
|
|
2671
|
-
output.userId = identity.userId;
|
|
2672
|
-
output.tenantId = identity.tenantId;
|
|
2592
|
+
_getCookieSsr(ssrOpts, container, config) {
|
|
2593
|
+
if (import_shared55.Guards.isDefined(ssrOpts)) {
|
|
2594
|
+
return ssrOpts(container);
|
|
2595
|
+
} else {
|
|
2596
|
+
return new CookieHandler(
|
|
2597
|
+
container.resolve(import_shared55.TOKENS.REQUEST_CONTEXT),
|
|
2598
|
+
container.resolve(import_shared55.TOKENS.CONFIGURATION_SERVICE),
|
|
2599
|
+
config
|
|
2600
|
+
);
|
|
2673
2601
|
}
|
|
2674
|
-
return output;
|
|
2675
2602
|
}
|
|
2676
2603
|
};
|
|
2677
2604
|
}
|
|
2678
2605
|
});
|
|
2679
2606
|
|
|
2680
2607
|
// src/infrastructure/factories/zod-validator.factory.ts
|
|
2681
|
-
var
|
|
2608
|
+
var import_shared56, ZodValidatorFactory;
|
|
2682
2609
|
var init_zod_validator_factory = __esm({
|
|
2683
2610
|
"src/infrastructure/factories/zod-validator.factory.ts"() {
|
|
2684
2611
|
"use strict";
|
|
2685
|
-
|
|
2612
|
+
import_shared56 = require("@xeno-js/shared");
|
|
2686
2613
|
ZodValidatorFactory = class {
|
|
2687
2614
|
create(opts) {
|
|
2688
|
-
const validatorService = new
|
|
2615
|
+
const validatorService = new import_shared56.ZodValidatorService(/* @__PURE__ */ new Map(), opts.logger);
|
|
2689
2616
|
for (const [intentKey, schema] of Object.entries(opts.schemas)) {
|
|
2690
2617
|
validatorService.addSchema(intentKey, schema);
|
|
2691
2618
|
}
|
|
@@ -2712,137 +2639,389 @@ __export(factories_exports, {
|
|
|
2712
2639
|
UserContextFactory: () => UserContextFactory,
|
|
2713
2640
|
ZodValidatorFactory: () => ZodValidatorFactory
|
|
2714
2641
|
});
|
|
2715
|
-
var init_factories = __esm({
|
|
2716
|
-
"src/infrastructure/factories/index.ts"() {
|
|
2642
|
+
var init_factories = __esm({
|
|
2643
|
+
"src/infrastructure/factories/index.ts"() {
|
|
2644
|
+
"use strict";
|
|
2645
|
+
init_allow_method_factory();
|
|
2646
|
+
init_axios_factory();
|
|
2647
|
+
init_cockatiel_resilience_factory();
|
|
2648
|
+
init_db_client_factory();
|
|
2649
|
+
init_pino_logger_factory();
|
|
2650
|
+
init_redis_cache_factory();
|
|
2651
|
+
init_request_context_factory();
|
|
2652
|
+
init_sentry_logger_factory();
|
|
2653
|
+
init_service_scope_factory();
|
|
2654
|
+
init_sql_light_db_client_factory();
|
|
2655
|
+
init_supabase_factory();
|
|
2656
|
+
init_user_context_factory();
|
|
2657
|
+
init_zod_validator_factory();
|
|
2658
|
+
}
|
|
2659
|
+
});
|
|
2660
|
+
|
|
2661
|
+
// src/infrastructure/modules/utils/auth.utils.ts
|
|
2662
|
+
var auth_utils_exports = {};
|
|
2663
|
+
__export(auth_utils_exports, {
|
|
2664
|
+
AuthUtils: () => AuthUtils
|
|
2665
|
+
});
|
|
2666
|
+
var AuthUtils;
|
|
2667
|
+
var init_auth_utils = __esm({
|
|
2668
|
+
"src/infrastructure/modules/utils/auth.utils.ts"() {
|
|
2669
|
+
"use strict";
|
|
2670
|
+
AuthUtils = Object.freeze({
|
|
2671
|
+
/**
|
|
2672
|
+
* @description Checks if the provided authorization configuration requires any authorization strategies.
|
|
2673
|
+
* @param authorizationConfig The authorization configuration to check.
|
|
2674
|
+
* @returns True if any authorization strategies are required, false otherwise.
|
|
2675
|
+
|
|
2676
|
+
*
|
|
2677
|
+
* @author Xeno
|
|
2678
|
+
* @version 1.0.0
|
|
2679
|
+
* @since 2025-09-30
|
|
2680
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2681
|
+
*/
|
|
2682
|
+
async addAuthZ(container, opts) {
|
|
2683
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2684
|
+
const strategies = [];
|
|
2685
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
2686
|
+
if (Guards49.isDefined(opts.policies)) {
|
|
2687
|
+
const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2688
|
+
const policyRegistry = opts.policies;
|
|
2689
|
+
const registryInstance = new PolicyRegistry2();
|
|
2690
|
+
const ctxAccessor = container.resolve(TOKENS5.CONTEXT_ACCESSOR);
|
|
2691
|
+
const Policies = /* @__PURE__ */ new Set();
|
|
2692
|
+
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2693
|
+
const intentLower = intent.toLowerCase();
|
|
2694
|
+
registryInstance.addPolicy(intentLower, policy);
|
|
2695
|
+
if (!Guards49.isNullOrEmpty(policy.roles)) {
|
|
2696
|
+
Policies.add("roles");
|
|
2697
|
+
}
|
|
2698
|
+
if (!Guards49.isNullOrEmpty(policy.permissions)) {
|
|
2699
|
+
Policies.add("permissions");
|
|
2700
|
+
}
|
|
2701
|
+
if (!Guards49.isNullOrEmpty(policy.userId)) {
|
|
2702
|
+
Policies.add("userId");
|
|
2703
|
+
}
|
|
2704
|
+
if (!Guards49.isNullOrEmpty(policy.tenantId)) {
|
|
2705
|
+
Policies.add("tenantId");
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
if (Policies.has("roles")) {
|
|
2709
|
+
const { RoleAuthorizationStrategy: RoleAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2710
|
+
strategies.push(new RoleAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2711
|
+
}
|
|
2712
|
+
if (Policies.has("permissions")) {
|
|
2713
|
+
const { PermissionAuthorizationStrategy: PermissionAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2714
|
+
strategies.push(new PermissionAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2715
|
+
}
|
|
2716
|
+
if (Policies.has("userId")) {
|
|
2717
|
+
const { UserAuthorizationStrategy: UserAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2718
|
+
strategies.push(new UserAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2719
|
+
}
|
|
2720
|
+
if (Policies.has("tenantId")) {
|
|
2721
|
+
const { TenantAuthorizationStrategy: TenantAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2722
|
+
strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
if (!Guards49.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2726
|
+
const customStrategies = opts.customAuthorizationStrategy;
|
|
2727
|
+
customStrategies.forEach((strategyToken) => {
|
|
2728
|
+
if (Guards49.isDefined(strategyToken)) {
|
|
2729
|
+
strategies.push(strategyToken(container));
|
|
2730
|
+
}
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
const { AuthorizationPipeline: AuthorizationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2734
|
+
return new AuthorizationPipeline2(strategies);
|
|
2735
|
+
},
|
|
2736
|
+
/**
|
|
2737
|
+
* @description Configures the authentication service and gatekeeper in the service container.
|
|
2738
|
+
* @param container The service container to configure.
|
|
2739
|
+
* @param opts The authentication configuration options.
|
|
2740
|
+
|
|
2741
|
+
*
|
|
2742
|
+
* @author Xeno
|
|
2743
|
+
* @version 1.0.0
|
|
2744
|
+
* @since 2025-09-30
|
|
2745
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2746
|
+
*/
|
|
2747
|
+
async addAuthN(container, opts) {
|
|
2748
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2749
|
+
if (Guards49.isDefined(opts.customAuth)) {
|
|
2750
|
+
const authService = opts.customAuth.authExtendedService();
|
|
2751
|
+
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2752
|
+
return authService;
|
|
2753
|
+
});
|
|
2754
|
+
container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
|
|
2755
|
+
return authService;
|
|
2756
|
+
});
|
|
2757
|
+
} else {
|
|
2758
|
+
const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2759
|
+
const factory = new SupabaseServerAuthFactory2();
|
|
2760
|
+
const supabase = factory.create({ config: opts, container });
|
|
2761
|
+
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2762
|
+
return supabase;
|
|
2763
|
+
});
|
|
2764
|
+
container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
|
|
2765
|
+
return supabase;
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
});
|
|
2770
|
+
}
|
|
2771
|
+
});
|
|
2772
|
+
|
|
2773
|
+
// src/infrastructure/modules/utils/validation.utils.ts
|
|
2774
|
+
var validation_utils_exports = {};
|
|
2775
|
+
__export(validation_utils_exports, {
|
|
2776
|
+
ValidationUtils: () => ValidationUtils
|
|
2777
|
+
});
|
|
2778
|
+
var ValidationUtils;
|
|
2779
|
+
var init_validation_utils = __esm({
|
|
2780
|
+
"src/infrastructure/modules/utils/validation.utils.ts"() {
|
|
2781
|
+
"use strict";
|
|
2782
|
+
ValidationUtils = Object.freeze({
|
|
2783
|
+
/**
|
|
2784
|
+
* @description Checks if the provided validation configuration requires any validation strategies.
|
|
2785
|
+
* @param validationConfig The validation configuration to check.
|
|
2786
|
+
* @returns True if any validation strategies are required, false otherwise.
|
|
2787
|
+
*
|
|
2788
|
+
* @author Xeno
|
|
2789
|
+
* @version 1.0.0
|
|
2790
|
+
* @since 2025-09-30
|
|
2791
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2792
|
+
*/
|
|
2793
|
+
async addValidation(container, opts, logger) {
|
|
2794
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2795
|
+
if (!Guards49.isDefined(opts.zod) && Guards49.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
2796
|
+
return;
|
|
2797
|
+
}
|
|
2798
|
+
const validationStrategies = [];
|
|
2799
|
+
if (Guards49.isDefined(opts.zod)) {
|
|
2800
|
+
const config = opts.zod;
|
|
2801
|
+
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2802
|
+
const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2803
|
+
const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
|
|
2804
|
+
container.addSingleton(TOKENS5.VALIDATOR_SERVICE, () => validatorService);
|
|
2805
|
+
validationStrategies.push(new SchemaValidationStrategy2(validatorService));
|
|
2806
|
+
}
|
|
2807
|
+
if (!Guards49.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
2808
|
+
for (const strategyToken of opts.customValidationStrategy) {
|
|
2809
|
+
if (Guards49.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2813
|
+
return new ValidationPipeline2(validationStrategies);
|
|
2814
|
+
}
|
|
2815
|
+
});
|
|
2816
|
+
}
|
|
2817
|
+
});
|
|
2818
|
+
|
|
2819
|
+
// src/infrastructure/idempotency/idempotency-store.ts
|
|
2820
|
+
var import_shared57, IdempotencyStore;
|
|
2821
|
+
var init_idempotency_store = __esm({
|
|
2822
|
+
"src/infrastructure/idempotency/idempotency-store.ts"() {
|
|
2823
|
+
"use strict";
|
|
2824
|
+
import_shared57 = require("@xeno-js/shared");
|
|
2825
|
+
IdempotencyStore = class {
|
|
2826
|
+
/**
|
|
2827
|
+
* @description Constructs a new instance of IdempotencyStore, accepting an instance of ICache for accessing the caching system and an instance of IIdentityAccessor for obtaining the user's identity context. The IdempotencyStore uses the caching system to manage locks and results of idempotent commands, ensuring that commands with the same ID are processed only once. The identity context is used to build contextual keys, allowing for more granular management of idempotent commands in multi-tenant scenarios.
|
|
2828
|
+
* @param _cache An instance of ICache that provides methods to interact with the underlying caching system, used to store locks and results of idempotent commands.
|
|
2829
|
+
* @param _identityAccessor An instance of IIdentityAccessor that allows access to the user's identity context, used to build contextual keys for idempotent commands, supporting multi-tenant scenarios.
|
|
2830
|
+
|
|
2831
|
+
*
|
|
2832
|
+
* @author Xeno
|
|
2833
|
+
* @version 1.0.0
|
|
2834
|
+
* @since 2025-09-30
|
|
2835
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2836
|
+
*/
|
|
2837
|
+
constructor(_cache, _cacheKeyBuilder) {
|
|
2838
|
+
this._cache = _cache;
|
|
2839
|
+
this._cacheKeyBuilder = _cacheKeyBuilder;
|
|
2840
|
+
}
|
|
2841
|
+
_cache;
|
|
2842
|
+
_cacheKeyBuilder;
|
|
2843
|
+
async acquireLock(requestId, ttlSeconds) {
|
|
2844
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${requestId}`);
|
|
2845
|
+
return await this._cache.setIfAbsent(
|
|
2846
|
+
`${import_shared57.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`,
|
|
2847
|
+
import_shared57.IDEMPOTENCY_CONSTANTS.LOCKED_VALUE,
|
|
2848
|
+
ttlSeconds
|
|
2849
|
+
);
|
|
2850
|
+
}
|
|
2851
|
+
async hasBeenProcessed(commandId) {
|
|
2852
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2853
|
+
return await this._cache.has(`${import_shared57.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
2854
|
+
}
|
|
2855
|
+
async markAsProcessed(commandId, payload, ttlSeconds) {
|
|
2856
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2857
|
+
await this._cache.set(
|
|
2858
|
+
`${import_shared57.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`,
|
|
2859
|
+
payload,
|
|
2860
|
+
ttlSeconds
|
|
2861
|
+
);
|
|
2862
|
+
}
|
|
2863
|
+
async getPayload(commandId) {
|
|
2864
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2865
|
+
const payload = await this._cache.get(`${import_shared57.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
2866
|
+
return payload;
|
|
2867
|
+
}
|
|
2868
|
+
async releaseLock(commandId) {
|
|
2869
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2870
|
+
await this._cache.remove(`${import_shared57.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`);
|
|
2871
|
+
}
|
|
2872
|
+
};
|
|
2873
|
+
}
|
|
2874
|
+
});
|
|
2875
|
+
|
|
2876
|
+
// src/infrastructure/idempotency/index.ts
|
|
2877
|
+
var idempotency_exports = {};
|
|
2878
|
+
__export(idempotency_exports, {
|
|
2879
|
+
IdempotencyStore: () => IdempotencyStore
|
|
2880
|
+
});
|
|
2881
|
+
var init_idempotency = __esm({
|
|
2882
|
+
"src/infrastructure/idempotency/index.ts"() {
|
|
2717
2883
|
"use strict";
|
|
2718
|
-
|
|
2719
|
-
init_axios_factory();
|
|
2720
|
-
init_cockatiel_resilience_factory();
|
|
2721
|
-
init_db_client_factory();
|
|
2722
|
-
init_pino_logger_factory();
|
|
2723
|
-
init_redis_cache_factory();
|
|
2724
|
-
init_request_context_factory();
|
|
2725
|
-
init_sentry_logger_factory();
|
|
2726
|
-
init_service_scope_factory();
|
|
2727
|
-
init_sql_light_db_client_factory();
|
|
2728
|
-
init_supabase_factory();
|
|
2729
|
-
init_user_context_factory();
|
|
2730
|
-
init_zod_validator_factory();
|
|
2884
|
+
init_idempotency_store();
|
|
2731
2885
|
}
|
|
2732
2886
|
});
|
|
2733
2887
|
|
|
2734
|
-
// src/infrastructure/modules/utils/
|
|
2735
|
-
var
|
|
2736
|
-
__export(
|
|
2737
|
-
|
|
2888
|
+
// src/infrastructure/modules/utils/pipeline.utils.ts
|
|
2889
|
+
var pipeline_utils_exports = {};
|
|
2890
|
+
__export(pipeline_utils_exports, {
|
|
2891
|
+
PipelineUtils: () => PipelineUtils
|
|
2738
2892
|
});
|
|
2739
|
-
var
|
|
2740
|
-
var
|
|
2741
|
-
"src/infrastructure/modules/utils/
|
|
2893
|
+
var PipelineUtils;
|
|
2894
|
+
var init_pipeline_utils = __esm({
|
|
2895
|
+
"src/infrastructure/modules/utils/pipeline.utils.ts"() {
|
|
2742
2896
|
"use strict";
|
|
2743
|
-
|
|
2897
|
+
PipelineUtils = Object.freeze({
|
|
2744
2898
|
/**
|
|
2745
|
-
* @description Checks if the provided
|
|
2746
|
-
* @param
|
|
2747
|
-
* @returns True if any
|
|
2748
|
-
|
|
2749
|
-
*
|
|
2899
|
+
* @description Checks if the provided command configuration requires any command strategies.
|
|
2900
|
+
* @param commandConfig The command configuration to check.
|
|
2901
|
+
* @returns True if any command strategies are required, false otherwise.
|
|
2902
|
+
*
|
|
2750
2903
|
* @author Xeno
|
|
2751
2904
|
* @version 1.0.0
|
|
2752
2905
|
* @since 2025-09-30
|
|
2753
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
2906
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2754
2907
|
*/
|
|
2755
|
-
async
|
|
2756
|
-
const { TOKENS:
|
|
2757
|
-
const
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
const
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
const
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
Policies.add("userId");
|
|
2776
|
-
}
|
|
2777
|
-
if (!Guards46.isNullOrEmpty(policy.tenantId)) {
|
|
2778
|
-
Policies.add("tenantId");
|
|
2779
|
-
}
|
|
2780
|
-
}
|
|
2781
|
-
if (Policies.has("roles")) {
|
|
2782
|
-
const { RoleAuthorizationStrategy: RoleAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2783
|
-
strategies.push(new RoleAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2784
|
-
}
|
|
2785
|
-
if (Policies.has("permissions")) {
|
|
2786
|
-
const { PermissionAuthorizationStrategy: PermissionAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2787
|
-
strategies.push(new PermissionAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2788
|
-
}
|
|
2789
|
-
if (Policies.has("userId")) {
|
|
2790
|
-
const { UserAuthorizationStrategy: UserAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2791
|
-
strategies.push(new UserAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2792
|
-
}
|
|
2793
|
-
if (Policies.has("tenantId")) {
|
|
2794
|
-
const { TenantAuthorizationStrategy: TenantAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2795
|
-
strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2796
|
-
}
|
|
2908
|
+
async addCommand(container, opts) {
|
|
2909
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2910
|
+
const pipelines = [];
|
|
2911
|
+
if (Guards49.isDefined(opts.idempotency)) {
|
|
2912
|
+
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
|
|
2913
|
+
const imdStore = new IdempotencyStore2(
|
|
2914
|
+
container.resolve(TOKENS5.CACHE),
|
|
2915
|
+
container.resolve(TOKENS5.CACHE_KEY_BUILDER)
|
|
2916
|
+
);
|
|
2917
|
+
const { IdempotencyPipeline: IdempotencyPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2918
|
+
const requestContext = container.resolve(TOKENS5.NETWORK_CONTEXT_ACCESSOR);
|
|
2919
|
+
const config = opts.idempotency;
|
|
2920
|
+
pipelines.push(
|
|
2921
|
+
new IdempotencyPipeline2(
|
|
2922
|
+
requestContext,
|
|
2923
|
+
imdStore,
|
|
2924
|
+
config?.lockTtlSeconds,
|
|
2925
|
+
config?.processedTtlSeconds
|
|
2926
|
+
)
|
|
2927
|
+
);
|
|
2797
2928
|
}
|
|
2798
|
-
if (
|
|
2799
|
-
const
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
strategies.push(strategyToken(container));
|
|
2803
|
-
}
|
|
2804
|
-
});
|
|
2929
|
+
if (Guards49.isDefined(opts.concurrency)) {
|
|
2930
|
+
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2931
|
+
const config = opts.concurrency;
|
|
2932
|
+
pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
|
|
2805
2933
|
}
|
|
2806
|
-
|
|
2807
|
-
return new AuthorizationPipeline2(strategies);
|
|
2934
|
+
return pipelines;
|
|
2808
2935
|
},
|
|
2809
2936
|
/**
|
|
2810
|
-
* @description
|
|
2811
|
-
* @param
|
|
2812
|
-
* @
|
|
2813
|
-
|
|
2814
|
-
*
|
|
2937
|
+
* @description Checks if the provided query configuration requires any query strategies.
|
|
2938
|
+
* @param queryConfig The query configuration to check.
|
|
2939
|
+
* @returns True if any query strategies are required, false otherwise.
|
|
2940
|
+
*
|
|
2815
2941
|
* @author Xeno
|
|
2816
2942
|
* @version 1.0.0
|
|
2817
2943
|
* @since 2025-09-30
|
|
2818
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
2944
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2819
2945
|
*/
|
|
2820
|
-
async
|
|
2821
|
-
const {
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
container.
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
return authService;
|
|
2829
|
-
});
|
|
2830
|
-
} else {
|
|
2831
|
-
const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2832
|
-
const factory = new SupabaseServerAuthFactory2();
|
|
2833
|
-
const supabase = factory.create({ config: opts, container });
|
|
2834
|
-
container.addScoped(TOKENS4.AUTH_SERVICE, () => {
|
|
2835
|
-
return supabase;
|
|
2836
|
-
});
|
|
2837
|
-
container.addSingleton(TOKENS4.BASE_AUTH_SERVICE, () => {
|
|
2838
|
-
return supabase;
|
|
2839
|
-
});
|
|
2840
|
-
}
|
|
2946
|
+
async addQuery(container) {
|
|
2947
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2948
|
+
const { QueryCachingPipeline: QueryCachingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2949
|
+
return new QueryCachingPipeline2(
|
|
2950
|
+
container.resolve(TOKENS5.CACHE),
|
|
2951
|
+
container.resolve(TOKENS5.CACHE_KEY_BUILDER),
|
|
2952
|
+
container.resolve(TOKENS5.LOGGER)
|
|
2953
|
+
);
|
|
2841
2954
|
}
|
|
2842
2955
|
});
|
|
2843
2956
|
}
|
|
2844
2957
|
});
|
|
2845
2958
|
|
|
2959
|
+
// src/infrastructure/modules/cqrs.module.ts
|
|
2960
|
+
var cqrs_module_exports = {};
|
|
2961
|
+
__export(cqrs_module_exports, {
|
|
2962
|
+
CqrsModule: () => CqrsModule
|
|
2963
|
+
});
|
|
2964
|
+
var CqrsModule;
|
|
2965
|
+
var init_cqrs_module = __esm({
|
|
2966
|
+
"src/infrastructure/modules/cqrs.module.ts"() {
|
|
2967
|
+
"use strict";
|
|
2968
|
+
CqrsModule = class {
|
|
2969
|
+
async configure(container, opts) {
|
|
2970
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2971
|
+
const logger = container.resolve(TOKENS5.LOGGER);
|
|
2972
|
+
const { Mediator: Mediator2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2973
|
+
container.addSingleton(TOKENS5.MEDIATOR, (c) => {
|
|
2974
|
+
const serviceScopeAccessor = c.resolve(TOKENS5.SERVICE_SCOPE_ACCESSOR);
|
|
2975
|
+
return new Mediator2(serviceScopeAccessor);
|
|
2976
|
+
});
|
|
2977
|
+
const { ExceptionPipeline: ExceptionPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2978
|
+
const { LoggingPipeline: LoggingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2979
|
+
const { PerformancePipeline: PerformancePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2980
|
+
const thresholdMs = opts.performance?.thresholdMs;
|
|
2981
|
+
const pipelines = [
|
|
2982
|
+
new ExceptionPipeline2(),
|
|
2983
|
+
new LoggingPipeline2(logger),
|
|
2984
|
+
new PerformancePipeline2(logger, thresholdMs)
|
|
2985
|
+
];
|
|
2986
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
2987
|
+
if (Guards49.isDefined(opts.authorization.policies) || Guards49.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
2988
|
+
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
2989
|
+
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
2990
|
+
pipelines.push(authPipelines);
|
|
2991
|
+
}
|
|
2992
|
+
if (Guards49.isDefined(opts.validation.zod) || Guards49.isDefined(opts.validation.customValidationStrategy)) {
|
|
2993
|
+
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
2994
|
+
const validationPipelines = await ValidationUtils2.addValidation(
|
|
2995
|
+
container,
|
|
2996
|
+
opts.validation,
|
|
2997
|
+
logger
|
|
2998
|
+
);
|
|
2999
|
+
if (Guards49.isDefined(validationPipelines)) pipelines.push(validationPipelines);
|
|
3000
|
+
}
|
|
3001
|
+
const commandPipelines = [...pipelines];
|
|
3002
|
+
const queryPipelines = [...pipelines];
|
|
3003
|
+
if (Guards49.isDefined(opts.commandBus.idempotency) || Guards49.isDefined(opts.commandBus.concurrency)) {
|
|
3004
|
+
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3005
|
+
const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
|
|
3006
|
+
commandPipelines.push(...newCommandPipelines);
|
|
3007
|
+
}
|
|
3008
|
+
if (opts.queryBus.isEnabled) {
|
|
3009
|
+
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3010
|
+
const newQueryPipelines = await PipelineUtils2.addQuery(container);
|
|
3011
|
+
queryPipelines.push(newQueryPipelines);
|
|
3012
|
+
}
|
|
3013
|
+
const { CompositePipeline: CompositePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3014
|
+
container.addSingleton(TOKENS5.COMMAND_PIPELINES_BEHAVIOR, () => {
|
|
3015
|
+
return new CompositePipeline2(commandPipelines);
|
|
3016
|
+
});
|
|
3017
|
+
container.addSingleton(TOKENS5.QUERY_PIPELINES_BEHAVIOR, () => {
|
|
3018
|
+
return new CompositePipeline2(queryPipelines);
|
|
3019
|
+
});
|
|
3020
|
+
}
|
|
3021
|
+
};
|
|
3022
|
+
}
|
|
3023
|
+
});
|
|
3024
|
+
|
|
2846
3025
|
// src/infrastructure/modules/utils/db.utils.ts
|
|
2847
3026
|
var db_utils_exports = {};
|
|
2848
3027
|
__export(db_utils_exports, {
|
|
@@ -2990,7 +3169,7 @@ var init_db_module = __esm({
|
|
|
2990
3169
|
"use strict";
|
|
2991
3170
|
DbModule = class {
|
|
2992
3171
|
async configure(container, opts) {
|
|
2993
|
-
const { Guards:
|
|
3172
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2994
3173
|
const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
|
|
2995
3174
|
const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
|
|
2996
3175
|
const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
|
|
@@ -2998,16 +3177,16 @@ var init_db_module = __esm({
|
|
|
2998
3177
|
return new TransactionState2();
|
|
2999
3178
|
});
|
|
3000
3179
|
const { UnitOfWork: UnitOfWork2 } = await Promise.resolve().then(() => (init_unit_of_work(), unit_of_work_exports));
|
|
3001
|
-
container.addScoped(
|
|
3180
|
+
container.addScoped(TOKENS5.UNIT_OF_WORK, (c) => {
|
|
3002
3181
|
const ttx = c.resolve("TRANSACTION_STATE");
|
|
3003
3182
|
return new UnitOfWork2(db, ttx);
|
|
3004
3183
|
});
|
|
3005
|
-
container.addScoped(
|
|
3184
|
+
container.addScoped(TOKENS5.DB_CONTEXT, (c) => {
|
|
3006
3185
|
const ttx = c.resolve("TRANSACTION_STATE");
|
|
3007
3186
|
return new Proxy(db, {
|
|
3008
3187
|
get(_target, prop, receiver) {
|
|
3009
3188
|
const activeState = ttx.state;
|
|
3010
|
-
if (
|
|
3189
|
+
if (Guards49.isDefined(activeState)) {
|
|
3011
3190
|
if (prop === "transaction") {
|
|
3012
3191
|
return activeState.transaction.bind(activeState);
|
|
3013
3192
|
}
|
|
@@ -3022,6 +3201,197 @@ var init_db_module = __esm({
|
|
|
3022
3201
|
}
|
|
3023
3202
|
});
|
|
3024
3203
|
|
|
3204
|
+
// src/infrastructure/http/base.http-adapter.ts
|
|
3205
|
+
var import_shared60, BaseHttpAdapter;
|
|
3206
|
+
var init_base_http_adapter = __esm({
|
|
3207
|
+
"src/infrastructure/http/base.http-adapter.ts"() {
|
|
3208
|
+
"use strict";
|
|
3209
|
+
import_shared60 = require("@xeno-js/shared");
|
|
3210
|
+
BaseHttpAdapter = class {
|
|
3211
|
+
/**
|
|
3212
|
+
* @description Parse the URL from the request.
|
|
3213
|
+
* @param rawUrl The raw URL.
|
|
3214
|
+
* @param headers The headers.
|
|
3215
|
+
* @param queryParams The query parameters.
|
|
3216
|
+
* @returns The parsed URL.
|
|
3217
|
+
*/
|
|
3218
|
+
parseUrl(rawUrl = "/", headers, queryParams) {
|
|
3219
|
+
const protocol = import_shared60.StringHelper.getSingleValue(headers["x-forwarded-proto"]) ?? "https";
|
|
3220
|
+
const host = import_shared60.StringHelper.safeStringify(headers["host"]) ?? "localhost";
|
|
3221
|
+
const url = new URL(rawUrl, `${protocol}://${host}`);
|
|
3222
|
+
if (!import_shared60.Guards.isNullOrEmpty(queryParams)) {
|
|
3223
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
3224
|
+
if (import_shared60.Guards.isArray(value)) {
|
|
3225
|
+
value.forEach((v) => url.searchParams.append(key, String(v)));
|
|
3226
|
+
} else if (import_shared60.Guards.isDefined(value)) {
|
|
3227
|
+
url.searchParams.set(key, String(value));
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
return url;
|
|
3232
|
+
}
|
|
3233
|
+
/**
|
|
3234
|
+
* @description Parses the headers.
|
|
3235
|
+
* @param rawHeaders The raw headers.
|
|
3236
|
+
* @returns The parsed headers.
|
|
3237
|
+
*/
|
|
3238
|
+
parseHeaders(rawHeaders) {
|
|
3239
|
+
const headers = new Headers();
|
|
3240
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
3241
|
+
if (import_shared60.Guards.isDefined(value)) {
|
|
3242
|
+
if (import_shared60.Guards.isArray(value)) {
|
|
3243
|
+
value.forEach((v) => headers.append(key, String(v)));
|
|
3244
|
+
} else {
|
|
3245
|
+
headers.set(key, String(value));
|
|
3246
|
+
}
|
|
3247
|
+
}
|
|
3248
|
+
}
|
|
3249
|
+
return headers;
|
|
3250
|
+
}
|
|
3251
|
+
/**
|
|
3252
|
+
* @description Parses the body.
|
|
3253
|
+
* @param method The method.
|
|
3254
|
+
* @param rawBody The raw body.
|
|
3255
|
+
* @returns The parsed body.
|
|
3256
|
+
*/
|
|
3257
|
+
parseBody(method, rawBody) {
|
|
3258
|
+
if (!import_shared60.Guards.isDefined(method) || !["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase()) || !import_shared60.Guards.isDefined(rawBody))
|
|
3259
|
+
return void 0;
|
|
3260
|
+
if (import_shared60.Guards.isObject(rawBody)) return JSON.stringify(rawBody);
|
|
3261
|
+
if (import_shared60.Guards.isString(rawBody) || rawBody instanceof Blob || rawBody instanceof ArrayBuffer || ArrayBuffer.isView(rawBody) || rawBody instanceof URLSearchParams || rawBody instanceof FormData)
|
|
3262
|
+
return rawBody;
|
|
3263
|
+
return String(rawBody);
|
|
3264
|
+
}
|
|
3265
|
+
/**
|
|
3266
|
+
* @description Creates the XenoWebTransport.
|
|
3267
|
+
* @param url The url.
|
|
3268
|
+
* @param method The method.
|
|
3269
|
+
* @param headers The headers.
|
|
3270
|
+
* @param body The body.
|
|
3271
|
+
* @returns The XenoWebTransport.
|
|
3272
|
+
*/
|
|
3273
|
+
createXenoWebTransport(url, method = "GET", headers, body = void 0) {
|
|
3274
|
+
const init2 = {
|
|
3275
|
+
method: method.toUpperCase(),
|
|
3276
|
+
headers
|
|
3277
|
+
};
|
|
3278
|
+
const parsedBody = this.parseBody(method, body);
|
|
3279
|
+
if (import_shared60.Guards.isDefined(parsedBody)) {
|
|
3280
|
+
init2.body = parsedBody;
|
|
3281
|
+
init2.duplex = "half";
|
|
3282
|
+
}
|
|
3283
|
+
return {
|
|
3284
|
+
request: {
|
|
3285
|
+
...new Request(url, init2),
|
|
3286
|
+
path: url.pathname
|
|
3287
|
+
},
|
|
3288
|
+
response: new Response()
|
|
3289
|
+
};
|
|
3290
|
+
}
|
|
3291
|
+
};
|
|
3292
|
+
}
|
|
3293
|
+
});
|
|
3294
|
+
|
|
3295
|
+
// src/infrastructure/http/fastify.http-adapter.ts
|
|
3296
|
+
var FastifyHttpAdapter;
|
|
3297
|
+
var init_fastify_http_adapter = __esm({
|
|
3298
|
+
"src/infrastructure/http/fastify.http-adapter.ts"() {
|
|
3299
|
+
"use strict";
|
|
3300
|
+
init_base_http_adapter();
|
|
3301
|
+
FastifyHttpAdapter = class extends BaseHttpAdapter {
|
|
3302
|
+
adapt(req, _res) {
|
|
3303
|
+
const headers = this.parseHeaders(req.headers);
|
|
3304
|
+
const url = this.parseUrl(req.url, req.headers, req.query);
|
|
3305
|
+
const body = req.body;
|
|
3306
|
+
return this.createXenoWebTransport(url, req.method, headers, body);
|
|
3307
|
+
}
|
|
3308
|
+
};
|
|
3309
|
+
}
|
|
3310
|
+
});
|
|
3311
|
+
|
|
3312
|
+
// src/infrastructure/http/native.http-adapter.ts
|
|
3313
|
+
var NativeHttpAdapter;
|
|
3314
|
+
var init_native_http_adapter = __esm({
|
|
3315
|
+
"src/infrastructure/http/native.http-adapter.ts"() {
|
|
3316
|
+
"use strict";
|
|
3317
|
+
init_base_http_adapter();
|
|
3318
|
+
NativeHttpAdapter = class extends BaseHttpAdapter {
|
|
3319
|
+
adapt(req, res) {
|
|
3320
|
+
return {
|
|
3321
|
+
request: {
|
|
3322
|
+
...req,
|
|
3323
|
+
path: new URL(req.url).pathname
|
|
3324
|
+
},
|
|
3325
|
+
response: res
|
|
3326
|
+
};
|
|
3327
|
+
}
|
|
3328
|
+
};
|
|
3329
|
+
}
|
|
3330
|
+
});
|
|
3331
|
+
|
|
3332
|
+
// src/infrastructure/http/vercel.http-adapter.ts
|
|
3333
|
+
var VercelHttpAdapter;
|
|
3334
|
+
var init_vercel_http_adapter = __esm({
|
|
3335
|
+
"src/infrastructure/http/vercel.http-adapter.ts"() {
|
|
3336
|
+
"use strict";
|
|
3337
|
+
init_base_http_adapter();
|
|
3338
|
+
VercelHttpAdapter = class extends BaseHttpAdapter {
|
|
3339
|
+
adapt(req, _res) {
|
|
3340
|
+
const headers = this.parseHeaders(req.headers);
|
|
3341
|
+
const url = this.parseUrl(req.url, req.headers, req.query);
|
|
3342
|
+
return this.createXenoWebTransport(url, req.method, headers, req.body);
|
|
3343
|
+
}
|
|
3344
|
+
};
|
|
3345
|
+
}
|
|
3346
|
+
});
|
|
3347
|
+
|
|
3348
|
+
// src/infrastructure/http/index.ts
|
|
3349
|
+
var http_exports = {};
|
|
3350
|
+
__export(http_exports, {
|
|
3351
|
+
BaseHttpAdapter: () => BaseHttpAdapter,
|
|
3352
|
+
FastifyHttpAdapter: () => FastifyHttpAdapter,
|
|
3353
|
+
NativeHttpAdapter: () => NativeHttpAdapter,
|
|
3354
|
+
VercelHttpAdapter: () => VercelHttpAdapter
|
|
3355
|
+
});
|
|
3356
|
+
var init_http = __esm({
|
|
3357
|
+
"src/infrastructure/http/index.ts"() {
|
|
3358
|
+
"use strict";
|
|
3359
|
+
init_base_http_adapter();
|
|
3360
|
+
init_fastify_http_adapter();
|
|
3361
|
+
init_native_http_adapter();
|
|
3362
|
+
init_vercel_http_adapter();
|
|
3363
|
+
}
|
|
3364
|
+
});
|
|
3365
|
+
|
|
3366
|
+
// src/infrastructure/modules/http-adapter.module.ts
|
|
3367
|
+
var import_shared61, HttpAdapterModule;
|
|
3368
|
+
var init_http_adapter_module = __esm({
|
|
3369
|
+
"src/infrastructure/modules/http-adapter.module.ts"() {
|
|
3370
|
+
"use strict";
|
|
3371
|
+
import_shared61 = require("@xeno-js/shared");
|
|
3372
|
+
HttpAdapterModule = class {
|
|
3373
|
+
async configure(container, opts) {
|
|
3374
|
+
const adapter = await this._getAdapter(opts);
|
|
3375
|
+
container.addSingleton("HTTP_ADAPTER", () => adapter);
|
|
3376
|
+
}
|
|
3377
|
+
async _getAdapter(opts) {
|
|
3378
|
+
if (opts.vercel) {
|
|
3379
|
+
const { VercelHttpAdapter: VercelHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
3380
|
+
return new VercelHttpAdapter2();
|
|
3381
|
+
} else if (opts.fastify) {
|
|
3382
|
+
const { FastifyHttpAdapter: FastifyHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
3383
|
+
return new FastifyHttpAdapter2();
|
|
3384
|
+
} else if (import_shared61.Guards.isDefined(opts.custom)) {
|
|
3385
|
+
return opts.custom();
|
|
3386
|
+
} else {
|
|
3387
|
+
const { NativeHttpAdapter: NativeHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
3388
|
+
return new NativeHttpAdapter2();
|
|
3389
|
+
}
|
|
3390
|
+
}
|
|
3391
|
+
};
|
|
3392
|
+
}
|
|
3393
|
+
});
|
|
3394
|
+
|
|
3025
3395
|
// src/infrastructure/modules/utils/http.utils.ts
|
|
3026
3396
|
var http_utils_exports = {};
|
|
3027
3397
|
__export(http_utils_exports, {
|
|
@@ -3044,14 +3414,14 @@ var init_http_utils = __esm({
|
|
|
3044
3414
|
*/
|
|
3045
3415
|
async addAxios(container, opts) {
|
|
3046
3416
|
const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3047
|
-
const { Guards:
|
|
3048
|
-
if (!
|
|
3417
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
3418
|
+
if (!Guards49.isDefined(opts.token)) {
|
|
3049
3419
|
throw new Error("HttpConfig.token is required and must be defined.");
|
|
3050
3420
|
}
|
|
3051
3421
|
container.addSingleton(opts.token, () => {
|
|
3052
3422
|
const factory = new NodeAxiosFactory2();
|
|
3053
3423
|
const instance = factory.create(opts.client);
|
|
3054
|
-
if (!
|
|
3424
|
+
if (!Guards49.hasMethod(instance, "get") || !Guards49.hasMethod(instance, "post") || !Guards49.hasMethod(instance, "put") || !Guards49.hasMethod(instance, "patch") || !Guards49.hasMethod(instance, "delete")) {
|
|
3055
3425
|
throw new Error(
|
|
3056
3426
|
"The created HTTP client instance does not implement the required methods of IHttpClient."
|
|
3057
3427
|
);
|
|
@@ -3066,298 +3436,46 @@ var init_http_utils = __esm({
|
|
|
3066
3436
|
*
|
|
3067
3437
|
* @author Xeno
|
|
3068
3438
|
* @version 1.0.0
|
|
3069
|
-
* @since 2025-09-30
|
|
3070
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3071
|
-
*/
|
|
3072
|
-
async addResilience(container, opts) {
|
|
3073
|
-
const { TOKENS:
|
|
3074
|
-
const { CockatielResilienceFactory: CockatielResilienceFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3075
|
-
container.addSingleton(
|
|
3076
|
-
const factory = new CockatielResilienceFactory2();
|
|
3077
|
-
return factory.create(opts);
|
|
3078
|
-
});
|
|
3079
|
-
}
|
|
3080
|
-
});
|
|
3081
|
-
}
|
|
3082
|
-
});
|
|
3083
|
-
|
|
3084
|
-
// src/infrastructure/modules/http-core.module.ts
|
|
3085
|
-
var http_core_module_exports = {};
|
|
3086
|
-
__export(http_core_module_exports, {
|
|
3087
|
-
HttpCoreModule: () => HttpCoreModule
|
|
3088
|
-
});
|
|
3089
|
-
var HttpCoreModule;
|
|
3090
|
-
var init_http_core_module = __esm({
|
|
3091
|
-
"src/infrastructure/modules/http-core.module.ts"() {
|
|
3092
|
-
"use strict";
|
|
3093
|
-
HttpCoreModule = class {
|
|
3094
|
-
async configure(container, opts) {
|
|
3095
|
-
const { HttpUtils: HttpUtils2 } = await Promise.resolve().then(() => (init_http_utils(), http_utils_exports));
|
|
3096
|
-
await HttpUtils2.addAxios(container, opts.http);
|
|
3097
|
-
await HttpUtils2.addResilience(container, opts.resilience);
|
|
3098
|
-
}
|
|
3099
|
-
};
|
|
3100
|
-
}
|
|
3101
|
-
});
|
|
3102
|
-
|
|
3103
|
-
// src/infrastructure/modules/utils/validation.utils.ts
|
|
3104
|
-
var validation_utils_exports = {};
|
|
3105
|
-
__export(validation_utils_exports, {
|
|
3106
|
-
ValidationUtils: () => ValidationUtils
|
|
3107
|
-
});
|
|
3108
|
-
var ValidationUtils;
|
|
3109
|
-
var init_validation_utils = __esm({
|
|
3110
|
-
"src/infrastructure/modules/utils/validation.utils.ts"() {
|
|
3111
|
-
"use strict";
|
|
3112
|
-
ValidationUtils = Object.freeze({
|
|
3113
|
-
/**
|
|
3114
|
-
* @description Checks if the provided validation configuration requires any validation strategies.
|
|
3115
|
-
* @param validationConfig The validation configuration to check.
|
|
3116
|
-
* @returns True if any validation strategies are required, false otherwise.
|
|
3117
|
-
*
|
|
3118
|
-
* @author Xeno
|
|
3119
|
-
* @version 1.0.0
|
|
3120
|
-
* @since 2025-09-30
|
|
3121
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3122
|
-
*/
|
|
3123
|
-
async addValidation(container, opts, logger) {
|
|
3124
|
-
const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3125
|
-
if (!Guards46.isDefined(opts.zod) && Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3126
|
-
return;
|
|
3127
|
-
}
|
|
3128
|
-
const validationStrategies = [];
|
|
3129
|
-
if (Guards46.isDefined(opts.zod)) {
|
|
3130
|
-
const config = opts.zod;
|
|
3131
|
-
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3132
|
-
const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3133
|
-
const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
|
|
3134
|
-
container.addSingleton(TOKENS4.VALIDATOR_SERVICE, () => validatorService);
|
|
3135
|
-
validationStrategies.push(new SchemaValidationStrategy2(validatorService));
|
|
3136
|
-
}
|
|
3137
|
-
if (!Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3138
|
-
for (const strategyToken of opts.customValidationStrategy) {
|
|
3139
|
-
if (Guards46.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
|
|
3140
|
-
}
|
|
3141
|
-
}
|
|
3142
|
-
const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3143
|
-
return new ValidationPipeline2(validationStrategies);
|
|
3144
|
-
}
|
|
3145
|
-
});
|
|
3146
|
-
}
|
|
3147
|
-
});
|
|
3148
|
-
|
|
3149
|
-
// src/infrastructure/idempotency/idempotency-store.ts
|
|
3150
|
-
var import_shared60, IdempotencyStore;
|
|
3151
|
-
var init_idempotency_store = __esm({
|
|
3152
|
-
"src/infrastructure/idempotency/idempotency-store.ts"() {
|
|
3153
|
-
"use strict";
|
|
3154
|
-
import_shared60 = require("@xeno-js/shared");
|
|
3155
|
-
IdempotencyStore = class {
|
|
3156
|
-
/**
|
|
3157
|
-
* @description Constructs a new instance of IdempotencyStore, accepting an instance of ICache for accessing the caching system and an instance of IIdentityAccessor for obtaining the user's identity context. The IdempotencyStore uses the caching system to manage locks and results of idempotent commands, ensuring that commands with the same ID are processed only once. The identity context is used to build contextual keys, allowing for more granular management of idempotent commands in multi-tenant scenarios.
|
|
3158
|
-
* @param _cache An instance of ICache that provides methods to interact with the underlying caching system, used to store locks and results of idempotent commands.
|
|
3159
|
-
* @param _identityAccessor An instance of IIdentityAccessor that allows access to the user's identity context, used to build contextual keys for idempotent commands, supporting multi-tenant scenarios.
|
|
3160
|
-
|
|
3161
|
-
*
|
|
3162
|
-
* @author Xeno
|
|
3163
|
-
* @version 1.0.0
|
|
3164
|
-
* @since 2025-09-30
|
|
3165
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3166
|
-
*/
|
|
3167
|
-
constructor(_cache, _cacheKeyBuilder) {
|
|
3168
|
-
this._cache = _cache;
|
|
3169
|
-
this._cacheKeyBuilder = _cacheKeyBuilder;
|
|
3170
|
-
}
|
|
3171
|
-
_cache;
|
|
3172
|
-
_cacheKeyBuilder;
|
|
3173
|
-
async acquireLock(requestId, ttlSeconds) {
|
|
3174
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${requestId}`);
|
|
3175
|
-
return await this._cache.setIfAbsent(
|
|
3176
|
-
`${import_shared60.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`,
|
|
3177
|
-
import_shared60.IDEMPOTENCY_CONSTANTS.LOCKED_VALUE,
|
|
3178
|
-
ttlSeconds
|
|
3179
|
-
);
|
|
3180
|
-
}
|
|
3181
|
-
async hasBeenProcessed(commandId) {
|
|
3182
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3183
|
-
return await this._cache.has(`${import_shared60.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
3184
|
-
}
|
|
3185
|
-
async markAsProcessed(commandId, payload, ttlSeconds) {
|
|
3186
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3187
|
-
await this._cache.set(
|
|
3188
|
-
`${import_shared60.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`,
|
|
3189
|
-
payload,
|
|
3190
|
-
ttlSeconds
|
|
3191
|
-
);
|
|
3192
|
-
}
|
|
3193
|
-
async getPayload(commandId) {
|
|
3194
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3195
|
-
const payload = await this._cache.get(`${import_shared60.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
3196
|
-
return payload;
|
|
3197
|
-
}
|
|
3198
|
-
async releaseLock(commandId) {
|
|
3199
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3200
|
-
await this._cache.remove(`${import_shared60.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`);
|
|
3201
|
-
}
|
|
3202
|
-
};
|
|
3203
|
-
}
|
|
3204
|
-
});
|
|
3205
|
-
|
|
3206
|
-
// src/infrastructure/idempotency/index.ts
|
|
3207
|
-
var idempotency_exports = {};
|
|
3208
|
-
__export(idempotency_exports, {
|
|
3209
|
-
IdempotencyStore: () => IdempotencyStore
|
|
3210
|
-
});
|
|
3211
|
-
var init_idempotency = __esm({
|
|
3212
|
-
"src/infrastructure/idempotency/index.ts"() {
|
|
3213
|
-
"use strict";
|
|
3214
|
-
init_idempotency_store();
|
|
3215
|
-
}
|
|
3216
|
-
});
|
|
3217
|
-
|
|
3218
|
-
// src/infrastructure/modules/utils/pipeline.utils.ts
|
|
3219
|
-
var pipeline_utils_exports = {};
|
|
3220
|
-
__export(pipeline_utils_exports, {
|
|
3221
|
-
PipelineUtils: () => PipelineUtils
|
|
3222
|
-
});
|
|
3223
|
-
var PipelineUtils;
|
|
3224
|
-
var init_pipeline_utils = __esm({
|
|
3225
|
-
"src/infrastructure/modules/utils/pipeline.utils.ts"() {
|
|
3226
|
-
"use strict";
|
|
3227
|
-
PipelineUtils = Object.freeze({
|
|
3228
|
-
/**
|
|
3229
|
-
* @description Checks if the provided command configuration requires any command strategies.
|
|
3230
|
-
* @param commandConfig The command configuration to check.
|
|
3231
|
-
* @returns True if any command strategies are required, false otherwise.
|
|
3232
|
-
*
|
|
3233
|
-
* @author Xeno
|
|
3234
|
-
* @version 1.0.0
|
|
3235
|
-
* @since 2025-09-30
|
|
3236
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3237
|
-
*/
|
|
3238
|
-
async addCommand(container, opts) {
|
|
3239
|
-
const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3240
|
-
const pipelines = [];
|
|
3241
|
-
if (Guards46.isDefined(opts.idempotency)) {
|
|
3242
|
-
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
|
|
3243
|
-
const imdStore = new IdempotencyStore2(
|
|
3244
|
-
container.resolve(TOKENS4.CACHE),
|
|
3245
|
-
container.resolve(TOKENS4.CACHE_KEY_BUILDER)
|
|
3246
|
-
);
|
|
3247
|
-
const { IdempotencyPipeline: IdempotencyPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3248
|
-
const requestContext = container.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR);
|
|
3249
|
-
const config = opts.idempotency;
|
|
3250
|
-
pipelines.push(
|
|
3251
|
-
new IdempotencyPipeline2(
|
|
3252
|
-
requestContext,
|
|
3253
|
-
imdStore,
|
|
3254
|
-
config?.lockTtlSeconds,
|
|
3255
|
-
config?.processedTtlSeconds
|
|
3256
|
-
)
|
|
3257
|
-
);
|
|
3258
|
-
}
|
|
3259
|
-
if (Guards46.isDefined(opts.concurrency)) {
|
|
3260
|
-
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3261
|
-
const config = opts.concurrency;
|
|
3262
|
-
pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
|
|
3263
|
-
}
|
|
3264
|
-
return pipelines;
|
|
3265
|
-
},
|
|
3266
|
-
/**
|
|
3267
|
-
* @description Checks if the provided query configuration requires any query strategies.
|
|
3268
|
-
* @param queryConfig The query configuration to check.
|
|
3269
|
-
* @returns True if any query strategies are required, false otherwise.
|
|
3270
|
-
*
|
|
3271
|
-
* @author Xeno
|
|
3272
|
-
* @version 1.0.0
|
|
3273
|
-
* @since 2025-09-30
|
|
3274
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3275
|
-
*/
|
|
3276
|
-
async addQuery(container) {
|
|
3277
|
-
const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3278
|
-
const { QueryCachingPipeline: QueryCachingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3279
|
-
return new QueryCachingPipeline2(
|
|
3280
|
-
container.resolve(TOKENS4.CACHE),
|
|
3281
|
-
container.resolve(TOKENS4.CACHE_KEY_BUILDER),
|
|
3282
|
-
container.resolve(TOKENS4.LOGGER)
|
|
3283
|
-
);
|
|
3284
|
-
}
|
|
3285
|
-
});
|
|
3286
|
-
}
|
|
3287
|
-
});
|
|
3288
|
-
|
|
3289
|
-
// src/infrastructure/modules/cqrs.module.ts
|
|
3290
|
-
var cqrs_module_exports = {};
|
|
3291
|
-
__export(cqrs_module_exports, {
|
|
3292
|
-
CqrsModule: () => CqrsModule
|
|
3293
|
-
});
|
|
3294
|
-
var CqrsModule;
|
|
3295
|
-
var init_cqrs_module = __esm({
|
|
3296
|
-
"src/infrastructure/modules/cqrs.module.ts"() {
|
|
3297
|
-
"use strict";
|
|
3298
|
-
CqrsModule = class {
|
|
3299
|
-
async configure(container, opts) {
|
|
3300
|
-
const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3301
|
-
const logger = container.resolve(TOKENS4.LOGGER);
|
|
3302
|
-
const { Mediator: Mediator2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3303
|
-
container.addSingleton(TOKENS4.MEDIATOR, (c) => {
|
|
3304
|
-
const serviceScopeAccessor = c.resolve(TOKENS4.SERVICE_SCOPE_ACCESSOR);
|
|
3305
|
-
return new Mediator2(serviceScopeAccessor);
|
|
3306
|
-
});
|
|
3307
|
-
const { ExceptionPipeline: ExceptionPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3308
|
-
const { LoggingPipeline: LoggingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3309
|
-
const { PerformancePipeline: PerformancePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3310
|
-
const thresholdMs = opts.performance?.thresholdMs;
|
|
3311
|
-
const pipelines = [
|
|
3312
|
-
new ExceptionPipeline2(),
|
|
3313
|
-
new LoggingPipeline2(logger),
|
|
3314
|
-
new PerformancePipeline2(logger, thresholdMs)
|
|
3315
|
-
];
|
|
3316
|
-
const { Guards: Guards46 } = await import("@xeno-js/shared");
|
|
3317
|
-
if (Guards46.isDefined(opts.authorization.policies) || Guards46.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
3318
|
-
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
3319
|
-
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
3320
|
-
pipelines.push(authPipelines);
|
|
3321
|
-
}
|
|
3322
|
-
if (Guards46.isDefined(opts.validation.zod) || Guards46.isDefined(opts.validation.customValidationStrategy)) {
|
|
3323
|
-
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
3324
|
-
const validationPipelines = await ValidationUtils2.addValidation(
|
|
3325
|
-
container,
|
|
3326
|
-
opts.validation,
|
|
3327
|
-
logger
|
|
3328
|
-
);
|
|
3329
|
-
if (Guards46.isDefined(validationPipelines)) pipelines.push(validationPipelines);
|
|
3330
|
-
}
|
|
3331
|
-
const commandPipelines = [...pipelines];
|
|
3332
|
-
const queryPipelines = [...pipelines];
|
|
3333
|
-
if (Guards46.isDefined(opts.commandBus.idempotency) || Guards46.isDefined(opts.commandBus.concurrency)) {
|
|
3334
|
-
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3335
|
-
const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
|
|
3336
|
-
commandPipelines.push(...newCommandPipelines);
|
|
3337
|
-
}
|
|
3338
|
-
if (opts.queryBus.isEnabled) {
|
|
3339
|
-
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3340
|
-
const newQueryPipelines = await PipelineUtils2.addQuery(container);
|
|
3341
|
-
queryPipelines.push(newQueryPipelines);
|
|
3342
|
-
}
|
|
3343
|
-
const { CompositePipeline: CompositePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3344
|
-
container.addSingleton(TOKENS4.COMMAND_PIPELINES_BEHAVIOR, () => {
|
|
3345
|
-
return new CompositePipeline2(commandPipelines);
|
|
3346
|
-
});
|
|
3347
|
-
container.addSingleton(TOKENS4.QUERY_PIPELINES_BEHAVIOR, () => {
|
|
3348
|
-
return new CompositePipeline2(queryPipelines);
|
|
3439
|
+
* @since 2025-09-30
|
|
3440
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
3441
|
+
*/
|
|
3442
|
+
async addResilience(container, opts) {
|
|
3443
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3444
|
+
const { CockatielResilienceFactory: CockatielResilienceFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3445
|
+
container.addSingleton(TOKENS5.RESILIENCE_CLIENT, () => {
|
|
3446
|
+
const factory = new CockatielResilienceFactory2();
|
|
3447
|
+
return factory.create(opts);
|
|
3349
3448
|
});
|
|
3350
3449
|
}
|
|
3450
|
+
});
|
|
3451
|
+
}
|
|
3452
|
+
});
|
|
3453
|
+
|
|
3454
|
+
// src/infrastructure/modules/http-core.module.ts
|
|
3455
|
+
var http_core_module_exports = {};
|
|
3456
|
+
__export(http_core_module_exports, {
|
|
3457
|
+
HttpCoreModule: () => HttpCoreModule
|
|
3458
|
+
});
|
|
3459
|
+
var HttpCoreModule;
|
|
3460
|
+
var init_http_core_module = __esm({
|
|
3461
|
+
"src/infrastructure/modules/http-core.module.ts"() {
|
|
3462
|
+
"use strict";
|
|
3463
|
+
HttpCoreModule = class {
|
|
3464
|
+
async configure(container, opts) {
|
|
3465
|
+
const { HttpUtils: HttpUtils2 } = await Promise.resolve().then(() => (init_http_utils(), http_utils_exports));
|
|
3466
|
+
await HttpUtils2.addAxios(container, opts.http);
|
|
3467
|
+
await HttpUtils2.addResilience(container, opts.resilience);
|
|
3468
|
+
}
|
|
3351
3469
|
};
|
|
3352
3470
|
}
|
|
3353
3471
|
});
|
|
3354
3472
|
|
|
3355
3473
|
// src/presentation/controllers/base.controller.ts
|
|
3356
|
-
var
|
|
3474
|
+
var import_shared62, BaseController;
|
|
3357
3475
|
var init_base_controller = __esm({
|
|
3358
3476
|
"src/presentation/controllers/base.controller.ts"() {
|
|
3359
3477
|
"use strict";
|
|
3360
|
-
|
|
3478
|
+
import_shared62 = require("@xeno-js/shared");
|
|
3361
3479
|
BaseController = class {
|
|
3362
3480
|
/**
|
|
3363
3481
|
* Constructs a new instance of the BaseController class.
|
|
@@ -3389,7 +3507,7 @@ var init_base_controller = __esm({
|
|
|
3389
3507
|
* @link https://github.com/xeno-js/xeno-js
|
|
3390
3508
|
*/
|
|
3391
3509
|
ok(data, status = 200, meta = {}, headers = {}) {
|
|
3392
|
-
return
|
|
3510
|
+
return import_shared62.HttpHelper.success(data, status, meta, headers);
|
|
3393
3511
|
}
|
|
3394
3512
|
/**
|
|
3395
3513
|
* Helper to automatically map a failed Result (from the CQRS pipeline)
|
|
@@ -3407,7 +3525,7 @@ var init_base_controller = __esm({
|
|
|
3407
3525
|
fail(error, details = void 0, headers = {}) {
|
|
3408
3526
|
const context = this._requestContext.getContext();
|
|
3409
3527
|
const customHeaders = error["header"];
|
|
3410
|
-
return
|
|
3528
|
+
return import_shared62.HttpHelper.error(
|
|
3411
3529
|
{
|
|
3412
3530
|
success: false,
|
|
3413
3531
|
error: {
|
|
@@ -3416,9 +3534,9 @@ var init_base_controller = __esm({
|
|
|
3416
3534
|
path: context?.network.path,
|
|
3417
3535
|
details: details ?? error.message
|
|
3418
3536
|
},
|
|
3419
|
-
correlationId: context?.tracing.correlationId ??
|
|
3420
|
-
requestId: context?.network.requestId ??
|
|
3421
|
-
spanId: context?.tracing.spanId ??
|
|
3537
|
+
correlationId: context?.tracing.correlationId ?? import_shared62.GuidHelper.generate(),
|
|
3538
|
+
requestId: context?.network.requestId ?? import_shared62.GuidHelper.generate(),
|
|
3539
|
+
spanId: context?.tracing.spanId ?? import_shared62.GuidHelper.generate(),
|
|
3422
3540
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3423
3541
|
},
|
|
3424
3542
|
error.status,
|
|
@@ -3473,11 +3591,11 @@ var init_controllers = __esm({
|
|
|
3473
3591
|
});
|
|
3474
3592
|
|
|
3475
3593
|
// src/presentation/middlewares/allow-method.middleware.ts
|
|
3476
|
-
var
|
|
3594
|
+
var import_shared63, MethodCheckMiddleware;
|
|
3477
3595
|
var init_allow_method_middleware = __esm({
|
|
3478
3596
|
"src/presentation/middlewares/allow-method.middleware.ts"() {
|
|
3479
3597
|
"use strict";
|
|
3480
|
-
|
|
3598
|
+
import_shared63 = require("@xeno-js/shared");
|
|
3481
3599
|
MethodCheckMiddleware = class {
|
|
3482
3600
|
constructor(_requestContext, _allowMethod) {
|
|
3483
3601
|
this._requestContext = _requestContext;
|
|
@@ -3489,21 +3607,21 @@ var init_allow_method_middleware = __esm({
|
|
|
3489
3607
|
const isAllowed = this._allowMethod.check(req.path, req.method);
|
|
3490
3608
|
if (!isAllowed) {
|
|
3491
3609
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3492
|
-
return
|
|
3610
|
+
return import_shared63.HttpHelper.error(
|
|
3493
3611
|
{
|
|
3494
3612
|
success: false,
|
|
3495
3613
|
error: {
|
|
3496
|
-
code:
|
|
3497
|
-
message:
|
|
3614
|
+
code: import_shared63.ERROR_CODES.NOT_ALLOWED,
|
|
3615
|
+
message: import_shared63.ERROR_CODE_MESSAGES[import_shared63.ERROR_CODES.NOT_ALLOWED],
|
|
3498
3616
|
details: `Operation blocked by allow method middleware`,
|
|
3499
3617
|
path: req.path
|
|
3500
3618
|
},
|
|
3501
|
-
correlationId: tracing?.correlationId ??
|
|
3502
|
-
requestId: network?.requestId ??
|
|
3503
|
-
spanId: tracing?.spanId ??
|
|
3619
|
+
correlationId: tracing?.correlationId ?? import_shared63.GuidHelper.generate(),
|
|
3620
|
+
requestId: network?.requestId ?? import_shared63.GuidHelper.generate(),
|
|
3621
|
+
spanId: tracing?.spanId ?? import_shared63.GuidHelper.generate(),
|
|
3504
3622
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3505
3623
|
},
|
|
3506
|
-
|
|
3624
|
+
import_shared63.STATUS_CODES.NOT_ALLOWED,
|
|
3507
3625
|
{
|
|
3508
3626
|
Allow: this._allowMethod.getMethods(req.path)
|
|
3509
3627
|
}
|
|
@@ -3516,11 +3634,11 @@ var init_allow_method_middleware = __esm({
|
|
|
3516
3634
|
});
|
|
3517
3635
|
|
|
3518
3636
|
// src/presentation/middlewares/allow-origin.middleware.ts
|
|
3519
|
-
var
|
|
3637
|
+
var import_shared64, AllowOriginMiddleware;
|
|
3520
3638
|
var init_allow_origin_middleware = __esm({
|
|
3521
3639
|
"src/presentation/middlewares/allow-origin.middleware.ts"() {
|
|
3522
3640
|
"use strict";
|
|
3523
|
-
|
|
3641
|
+
import_shared64 = require("@xeno-js/shared");
|
|
3524
3642
|
AllowOriginMiddleware = class {
|
|
3525
3643
|
constructor(_allowOrigin, _requestContext, _logger) {
|
|
3526
3644
|
this._allowOrigin = _allowOrigin;
|
|
@@ -3535,21 +3653,21 @@ var init_allow_origin_middleware = __esm({
|
|
|
3535
3653
|
const origin = network?.origin;
|
|
3536
3654
|
if (!this._allowOrigin.isAllowed(origin)) {
|
|
3537
3655
|
this._logger.warn(`Access denied by AllowOrigin policy for origin: ${origin ?? "unknown"}`);
|
|
3538
|
-
return
|
|
3656
|
+
return import_shared64.HttpHelper.error(
|
|
3539
3657
|
{
|
|
3540
3658
|
success: false,
|
|
3541
3659
|
error: {
|
|
3542
|
-
code:
|
|
3543
|
-
message:
|
|
3660
|
+
code: import_shared64.ERROR_CODES.FORBIDDEN,
|
|
3661
|
+
message: import_shared64.ERROR_CODE_MESSAGES[import_shared64.ERROR_CODES.FORBIDDEN],
|
|
3544
3662
|
details: `The origin '${origin ?? "unknown"}' is not allowed to access this resource.`,
|
|
3545
3663
|
path: req.path
|
|
3546
3664
|
},
|
|
3547
|
-
correlationId: tracing?.correlationId ??
|
|
3548
|
-
requestId: network?.requestId ??
|
|
3549
|
-
spanId: tracing?.spanId ??
|
|
3665
|
+
correlationId: tracing?.correlationId ?? import_shared64.GuidHelper.generate(),
|
|
3666
|
+
requestId: network?.requestId ?? import_shared64.GuidHelper.generate(),
|
|
3667
|
+
spanId: tracing?.spanId ?? import_shared64.GuidHelper.generate(),
|
|
3550
3668
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3551
3669
|
},
|
|
3552
|
-
|
|
3670
|
+
import_shared64.STATUS_CODES.FORBIDDEN
|
|
3553
3671
|
);
|
|
3554
3672
|
}
|
|
3555
3673
|
return next();
|
|
@@ -3559,11 +3677,11 @@ var init_allow_origin_middleware = __esm({
|
|
|
3559
3677
|
});
|
|
3560
3678
|
|
|
3561
3679
|
// src/presentation/middlewares/auth.middleware.ts
|
|
3562
|
-
var
|
|
3680
|
+
var import_shared65, AuthenticationMiddleware;
|
|
3563
3681
|
var init_auth_middleware = __esm({
|
|
3564
3682
|
"src/presentation/middlewares/auth.middleware.ts"() {
|
|
3565
3683
|
"use strict";
|
|
3566
|
-
|
|
3684
|
+
import_shared65 = require("@xeno-js/shared");
|
|
3567
3685
|
AuthenticationMiddleware = class {
|
|
3568
3686
|
constructor(_requestContext, _tokenExtractor, _gateKeeper, _logger) {
|
|
3569
3687
|
this._requestContext = _requestContext;
|
|
@@ -3584,7 +3702,7 @@ var init_auth_middleware = __esm({
|
|
|
3584
3702
|
`Authentication failed for request on path: ${req.path}. Code: ${error.code}. Error: ${error}`
|
|
3585
3703
|
);
|
|
3586
3704
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3587
|
-
return
|
|
3705
|
+
return import_shared65.HttpHelper.error(
|
|
3588
3706
|
{
|
|
3589
3707
|
success: false,
|
|
3590
3708
|
error: {
|
|
@@ -3593,12 +3711,12 @@ var init_auth_middleware = __esm({
|
|
|
3593
3711
|
details: `[Authentication Error] Failed to authenticate request on path: ${req.path}`,
|
|
3594
3712
|
path: req.path
|
|
3595
3713
|
},
|
|
3596
|
-
correlationId: tracing?.correlationId ??
|
|
3597
|
-
requestId: network?.requestId ??
|
|
3598
|
-
spanId: tracing?.spanId ??
|
|
3714
|
+
correlationId: tracing?.correlationId ?? import_shared65.GuidHelper.generate(),
|
|
3715
|
+
requestId: network?.requestId ?? import_shared65.GuidHelper.generate(),
|
|
3716
|
+
spanId: tracing?.spanId ?? import_shared65.GuidHelper.generate(),
|
|
3599
3717
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3600
3718
|
},
|
|
3601
|
-
error.status ??
|
|
3719
|
+
error.status ?? import_shared65.STATUS_CODES.UNAUTHORIZED,
|
|
3602
3720
|
{ "Content-Type": [network?.formatIndicator ?? "application/json"] }
|
|
3603
3721
|
);
|
|
3604
3722
|
}
|
|
@@ -3633,11 +3751,11 @@ var init_composite_middleware = __esm({
|
|
|
3633
3751
|
});
|
|
3634
3752
|
|
|
3635
3753
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3636
|
-
var
|
|
3754
|
+
var import_shared66, CORSMiddleware;
|
|
3637
3755
|
var init_cors_middleware = __esm({
|
|
3638
3756
|
"src/presentation/middlewares/cors.middleware.ts"() {
|
|
3639
3757
|
"use strict";
|
|
3640
|
-
|
|
3758
|
+
import_shared66 = require("@xeno-js/shared");
|
|
3641
3759
|
CORSMiddleware = class {
|
|
3642
3760
|
constructor(_requestContext, _withCredentials = "false") {
|
|
3643
3761
|
this._requestContext = _requestContext;
|
|
@@ -3649,7 +3767,7 @@ var init_cors_middleware = __esm({
|
|
|
3649
3767
|
const { network } = this._requestContext.getContext() ?? {};
|
|
3650
3768
|
const origin = network?.origin;
|
|
3651
3769
|
const response = await next();
|
|
3652
|
-
if (
|
|
3770
|
+
if (import_shared66.Guards.isDefined(origin))
|
|
3653
3771
|
response.headers = {
|
|
3654
3772
|
...response.headers ?? {},
|
|
3655
3773
|
"Access-Control-Allow-Origin": origin,
|
|
@@ -3663,11 +3781,11 @@ var init_cors_middleware = __esm({
|
|
|
3663
3781
|
});
|
|
3664
3782
|
|
|
3665
3783
|
// src/presentation/middlewares/csrf.middleware.ts
|
|
3666
|
-
var
|
|
3784
|
+
var import_shared67, CsrfMiddleware;
|
|
3667
3785
|
var init_csrf_middleware = __esm({
|
|
3668
3786
|
"src/presentation/middlewares/csrf.middleware.ts"() {
|
|
3669
3787
|
"use strict";
|
|
3670
|
-
|
|
3788
|
+
import_shared67 = require("@xeno-js/shared");
|
|
3671
3789
|
CsrfMiddleware = class {
|
|
3672
3790
|
constructor(_requestContext, _csrfTokenService) {
|
|
3673
3791
|
this._requestContext = _requestContext;
|
|
@@ -3682,64 +3800,64 @@ var init_csrf_middleware = __esm({
|
|
|
3682
3800
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3683
3801
|
const headerToken = network?.csrf;
|
|
3684
3802
|
const cookieToken = network?.csrfCookie;
|
|
3685
|
-
if (!
|
|
3686
|
-
return
|
|
3803
|
+
if (!import_shared67.Guards.isDefined(headerToken) || !import_shared67.Guards.isDefined(cookieToken)) {
|
|
3804
|
+
return import_shared67.HttpHelper.error(
|
|
3687
3805
|
{
|
|
3688
3806
|
success: false,
|
|
3689
3807
|
error: {
|
|
3690
|
-
code:
|
|
3691
|
-
message:
|
|
3808
|
+
code: import_shared67.ERROR_CODES.FORBIDDEN,
|
|
3809
|
+
message: import_shared67.ERROR_CODE_MESSAGES[import_shared67.ERROR_CODES.FORBIDDEN],
|
|
3692
3810
|
details: "CSRF token missing",
|
|
3693
3811
|
path: req.path
|
|
3694
3812
|
},
|
|
3695
|
-
correlationId: tracing?.correlationId ??
|
|
3696
|
-
requestId: network?.requestId ??
|
|
3697
|
-
spanId: tracing?.spanId ??
|
|
3813
|
+
correlationId: tracing?.correlationId ?? import_shared67.GuidHelper.generate(),
|
|
3814
|
+
requestId: network?.requestId ?? import_shared67.GuidHelper.generate(),
|
|
3815
|
+
spanId: tracing?.spanId ?? import_shared67.GuidHelper.generate(),
|
|
3698
3816
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3699
3817
|
},
|
|
3700
|
-
|
|
3818
|
+
import_shared67.STATUS_CODES.FORBIDDEN,
|
|
3701
3819
|
{
|
|
3702
3820
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3703
3821
|
}
|
|
3704
3822
|
);
|
|
3705
3823
|
}
|
|
3706
3824
|
if (headerToken !== cookieToken) {
|
|
3707
|
-
return
|
|
3825
|
+
return import_shared67.HttpHelper.error(
|
|
3708
3826
|
{
|
|
3709
3827
|
success: false,
|
|
3710
3828
|
error: {
|
|
3711
|
-
code:
|
|
3712
|
-
message:
|
|
3829
|
+
code: import_shared67.ERROR_CODES.FORBIDDEN,
|
|
3830
|
+
message: import_shared67.ERROR_CODE_MESSAGES[import_shared67.ERROR_CODES.FORBIDDEN],
|
|
3713
3831
|
details: "CSRF token mismatch",
|
|
3714
3832
|
path: req.path
|
|
3715
3833
|
},
|
|
3716
|
-
correlationId: tracing?.correlationId ??
|
|
3717
|
-
requestId: network?.requestId ??
|
|
3718
|
-
spanId: tracing?.spanId ??
|
|
3834
|
+
correlationId: tracing?.correlationId ?? import_shared67.GuidHelper.generate(),
|
|
3835
|
+
requestId: network?.requestId ?? import_shared67.GuidHelper.generate(),
|
|
3836
|
+
spanId: tracing?.spanId ?? import_shared67.GuidHelper.generate(),
|
|
3719
3837
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3720
3838
|
},
|
|
3721
|
-
|
|
3839
|
+
import_shared67.STATUS_CODES.FORBIDDEN,
|
|
3722
3840
|
{
|
|
3723
3841
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3724
3842
|
}
|
|
3725
3843
|
);
|
|
3726
3844
|
}
|
|
3727
|
-
if (!
|
|
3728
|
-
return
|
|
3845
|
+
if (!import_shared67.Guards.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3846
|
+
return import_shared67.HttpHelper.error(
|
|
3729
3847
|
{
|
|
3730
3848
|
success: false,
|
|
3731
3849
|
error: {
|
|
3732
|
-
code:
|
|
3733
|
-
message:
|
|
3850
|
+
code: import_shared67.ERROR_CODES.FORBIDDEN,
|
|
3851
|
+
message: import_shared67.ERROR_CODE_MESSAGES[import_shared67.ERROR_CODES.FORBIDDEN],
|
|
3734
3852
|
details: "CSRF token invalid",
|
|
3735
3853
|
path: req.path
|
|
3736
3854
|
},
|
|
3737
|
-
correlationId: tracing?.correlationId ??
|
|
3738
|
-
requestId: network?.requestId ??
|
|
3739
|
-
spanId: tracing?.spanId ??
|
|
3855
|
+
correlationId: tracing?.correlationId ?? import_shared67.GuidHelper.generate(),
|
|
3856
|
+
requestId: network?.requestId ?? import_shared67.GuidHelper.generate(),
|
|
3857
|
+
spanId: tracing?.spanId ?? import_shared67.GuidHelper.generate(),
|
|
3740
3858
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3741
3859
|
},
|
|
3742
|
-
|
|
3860
|
+
import_shared67.STATUS_CODES.FORBIDDEN,
|
|
3743
3861
|
{
|
|
3744
3862
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3745
3863
|
}
|
|
@@ -3753,11 +3871,11 @@ var init_csrf_middleware = __esm({
|
|
|
3753
3871
|
});
|
|
3754
3872
|
|
|
3755
3873
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3756
|
-
var
|
|
3874
|
+
var import_shared68, CsrfCookieMiddleware;
|
|
3757
3875
|
var init_csrf_cookie_middleware = __esm({
|
|
3758
3876
|
"src/presentation/middlewares/csrf-cookie.middleware.ts"() {
|
|
3759
3877
|
"use strict";
|
|
3760
|
-
|
|
3878
|
+
import_shared68 = require("@xeno-js/shared");
|
|
3761
3879
|
CsrfCookieMiddleware = class {
|
|
3762
3880
|
constructor(_requestContext, _csrfTokenService, _csrf) {
|
|
3763
3881
|
this._requestContext = _requestContext;
|
|
@@ -3772,8 +3890,8 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3772
3890
|
const context = this._requestContext.getContext();
|
|
3773
3891
|
const identity = context?.identity;
|
|
3774
3892
|
const network = context?.network;
|
|
3775
|
-
if (!
|
|
3776
|
-
if (
|
|
3893
|
+
if (!import_shared68.Guards.isDefined(identity?.userId)) return response;
|
|
3894
|
+
if (import_shared68.Guards.isDefined(network?.csrfCookie)) return response;
|
|
3777
3895
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3778
3896
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3779
3897
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3791,11 +3909,11 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3791
3909
|
});
|
|
3792
3910
|
|
|
3793
3911
|
// src/presentation/middlewares/options.middleware.ts
|
|
3794
|
-
var
|
|
3912
|
+
var import_shared69, OptionsMiddleware;
|
|
3795
3913
|
var init_options_middleware = __esm({
|
|
3796
3914
|
"src/presentation/middlewares/options.middleware.ts"() {
|
|
3797
3915
|
"use strict";
|
|
3798
|
-
|
|
3916
|
+
import_shared69 = require("@xeno-js/shared");
|
|
3799
3917
|
OptionsMiddleware = class {
|
|
3800
3918
|
constructor(_requestContext, _alloewMethod, _allowHeaders = [], _withCredentials = "false") {
|
|
3801
3919
|
this._requestContext = _requestContext;
|
|
@@ -3812,14 +3930,14 @@ var init_options_middleware = __esm({
|
|
|
3812
3930
|
const network = this._requestContext.getNetworkContext();
|
|
3813
3931
|
const origin = network?.origin;
|
|
3814
3932
|
const headers = {};
|
|
3815
|
-
if (
|
|
3933
|
+
if (import_shared69.Guards.isDefined(origin)) {
|
|
3816
3934
|
headers["Access-Control-Allow-Origin"] = origin;
|
|
3817
3935
|
headers["Access-Control-Allow-Credentials"] = this._withCredentials;
|
|
3818
3936
|
headers["Vary"] = "Origin";
|
|
3819
3937
|
}
|
|
3820
3938
|
headers["Access-Control-Allow-Methods"] = this._alloewMethod.getMethods(req.path);
|
|
3821
3939
|
headers["Access-Control-Allow-Headers"] = this._allowHeaders.join(", ");
|
|
3822
|
-
return
|
|
3940
|
+
return import_shared69.HttpHelper.success(null, import_shared69.STATUS_CODES.NO_CONTENT, {}, headers);
|
|
3823
3941
|
}
|
|
3824
3942
|
return await next();
|
|
3825
3943
|
}
|
|
@@ -3828,11 +3946,11 @@ var init_options_middleware = __esm({
|
|
|
3828
3946
|
});
|
|
3829
3947
|
|
|
3830
3948
|
// src/presentation/middlewares/rate-limiter.middleware.ts
|
|
3831
|
-
var
|
|
3949
|
+
var import_shared70, RateLimitMiddleware;
|
|
3832
3950
|
var init_rate_limiter_middleware = __esm({
|
|
3833
3951
|
"src/presentation/middlewares/rate-limiter.middleware.ts"() {
|
|
3834
3952
|
"use strict";
|
|
3835
|
-
|
|
3953
|
+
import_shared70 = require("@xeno-js/shared");
|
|
3836
3954
|
RateLimitMiddleware = class {
|
|
3837
3955
|
constructor(_ctxAccessor, _cache, _keyBuilder, _logger, _opts) {
|
|
3838
3956
|
this._ctxAccessor = _ctxAccessor;
|
|
@@ -3849,22 +3967,22 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3849
3967
|
async execute(req, _res, next) {
|
|
3850
3968
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3851
3969
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3852
|
-
if (!
|
|
3853
|
-
return
|
|
3970
|
+
if (!import_shared70.Guards.isDefined(cacheKey))
|
|
3971
|
+
return import_shared70.HttpHelper.error(
|
|
3854
3972
|
{
|
|
3855
3973
|
success: false,
|
|
3856
3974
|
error: {
|
|
3857
|
-
code:
|
|
3858
|
-
message:
|
|
3975
|
+
code: import_shared70.ERROR_CODES.SYSTEM_ERROR,
|
|
3976
|
+
message: import_shared70.ERROR_CODE_MESSAGES[import_shared70.ERROR_CODES.SYSTEM_ERROR],
|
|
3859
3977
|
details: `Bad Request: Unable to identify client context for rate limiting.`,
|
|
3860
3978
|
path: req.path
|
|
3861
3979
|
},
|
|
3862
|
-
correlationId: tracing?.correlationId ??
|
|
3863
|
-
requestId: network?.requestId ??
|
|
3864
|
-
spanId: tracing?.spanId ??
|
|
3980
|
+
correlationId: tracing?.correlationId ?? import_shared70.GuidHelper.generate(),
|
|
3981
|
+
requestId: network?.requestId ?? import_shared70.GuidHelper.generate(),
|
|
3982
|
+
spanId: tracing?.spanId ?? import_shared70.GuidHelper.generate(),
|
|
3865
3983
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3866
3984
|
},
|
|
3867
|
-
|
|
3985
|
+
import_shared70.STATUS_CODES.SERVICE_UNAVAILABLE,
|
|
3868
3986
|
{
|
|
3869
3987
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3870
3988
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3873,21 +3991,21 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3873
3991
|
const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
|
|
3874
3992
|
if (currentHits > this._opts.maxRequests) {
|
|
3875
3993
|
this._logger.warn(`[RateLimit] key ${cacheKey} has been blocked on ${req.path}`);
|
|
3876
|
-
return
|
|
3994
|
+
return import_shared70.HttpHelper.error(
|
|
3877
3995
|
{
|
|
3878
3996
|
success: false,
|
|
3879
3997
|
error: {
|
|
3880
|
-
code:
|
|
3881
|
-
message:
|
|
3998
|
+
code: import_shared70.ERROR_CODES.TOO_MANY_REQUESTS,
|
|
3999
|
+
message: import_shared70.ERROR_CODE_MESSAGES[import_shared70.ERROR_CODES.TOO_MANY_REQUESTS],
|
|
3882
4000
|
details: `Rate limit exceeded.`,
|
|
3883
4001
|
path: req.path
|
|
3884
4002
|
},
|
|
3885
|
-
correlationId: tracing?.correlationId ??
|
|
3886
|
-
requestId: network?.requestId ??
|
|
3887
|
-
spanId: tracing?.spanId ??
|
|
4003
|
+
correlationId: tracing?.correlationId ?? import_shared70.GuidHelper.generate(),
|
|
4004
|
+
requestId: network?.requestId ?? import_shared70.GuidHelper.generate(),
|
|
4005
|
+
spanId: tracing?.spanId ?? import_shared70.GuidHelper.generate(),
|
|
3888
4006
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3889
4007
|
},
|
|
3890
|
-
|
|
4008
|
+
import_shared70.STATUS_CODES.TOO_MANY_REQUESTS,
|
|
3891
4009
|
{
|
|
3892
4010
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3893
4011
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3902,8 +4020,8 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3902
4020
|
|
|
3903
4021
|
// src/presentation/mappers/context.mapper.ts
|
|
3904
4022
|
function _buildMessagingContext(meta) {
|
|
3905
|
-
const hasSequenceData =
|
|
3906
|
-
const hasMessagingData = hasSequenceData ||
|
|
4023
|
+
const hasSequenceData = import_shared71.Guards.isDefined(meta.sequence?.sequenceId) || import_shared71.Guards.isDefined(meta.sequence?.position) || import_shared71.Guards.isDefined(meta.sequence?.size);
|
|
4024
|
+
const hasMessagingData = hasSequenceData || import_shared71.Guards.isDefined(meta.expiration) || import_shared71.Guards.isDefined(meta.returnAddress);
|
|
3907
4025
|
const messaging = hasMessagingData ? {
|
|
3908
4026
|
returnAddress: meta.returnAddress,
|
|
3909
4027
|
expiration: meta.expiration,
|
|
@@ -3911,11 +4029,11 @@ function _buildMessagingContext(meta) {
|
|
|
3911
4029
|
} : void 0;
|
|
3912
4030
|
return messaging;
|
|
3913
4031
|
}
|
|
3914
|
-
var
|
|
4032
|
+
var import_shared71, ContextMapper;
|
|
3915
4033
|
var init_context_mapper = __esm({
|
|
3916
4034
|
"src/presentation/mappers/context.mapper.ts"() {
|
|
3917
4035
|
"use strict";
|
|
3918
|
-
|
|
4036
|
+
import_shared71 = require("@xeno-js/shared");
|
|
3919
4037
|
ContextMapper = Object.freeze({
|
|
3920
4038
|
/**
|
|
3921
4039
|
* @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.
|
|
@@ -3959,11 +4077,11 @@ var init_context_mapper = __esm({
|
|
|
3959
4077
|
});
|
|
3960
4078
|
|
|
3961
4079
|
// src/presentation/middlewares/request.middleware.ts
|
|
3962
|
-
var
|
|
4080
|
+
var import_shared72, RequestContextMiddleware;
|
|
3963
4081
|
var init_request_middleware = __esm({
|
|
3964
4082
|
"src/presentation/middlewares/request.middleware.ts"() {
|
|
3965
4083
|
"use strict";
|
|
3966
|
-
|
|
4084
|
+
import_shared72 = require("@xeno-js/shared");
|
|
3967
4085
|
init_context_mapper();
|
|
3968
4086
|
RequestContextMiddleware = class {
|
|
3969
4087
|
/**
|
|
@@ -3988,8 +4106,8 @@ var init_request_middleware = __esm({
|
|
|
3988
4106
|
_resolver;
|
|
3989
4107
|
_logger;
|
|
3990
4108
|
async execute(req, res, next) {
|
|
3991
|
-
const correlationId =
|
|
3992
|
-
const requestId =
|
|
4109
|
+
const correlationId = import_shared72.GuidHelper.generate();
|
|
4110
|
+
const requestId = import_shared72.GuidHelper.generate();
|
|
3993
4111
|
const spanId = correlationId;
|
|
3994
4112
|
const formatIndicator = "application/json";
|
|
3995
4113
|
try {
|
|
@@ -4005,7 +4123,7 @@ var init_request_middleware = __esm({
|
|
|
4005
4123
|
};
|
|
4006
4124
|
const tmpContext = ContextMapper.map({
|
|
4007
4125
|
metadata,
|
|
4008
|
-
identity:
|
|
4126
|
+
identity: import_shared72.GUEST,
|
|
4009
4127
|
path: req.path,
|
|
4010
4128
|
transport: { req, res }
|
|
4011
4129
|
});
|
|
@@ -4017,12 +4135,12 @@ var init_request_middleware = __esm({
|
|
|
4017
4135
|
return result;
|
|
4018
4136
|
} catch (error) {
|
|
4019
4137
|
this._logger.error("RequestContextMiddleware encountered an error", error);
|
|
4020
|
-
return
|
|
4138
|
+
return import_shared72.HttpHelper.error(
|
|
4021
4139
|
{
|
|
4022
4140
|
success: false,
|
|
4023
4141
|
error: {
|
|
4024
|
-
code:
|
|
4025
|
-
message:
|
|
4142
|
+
code: import_shared72.ERROR_CODES.SYSTEM_ERROR,
|
|
4143
|
+
message: import_shared72.ERROR_CODE_MESSAGES[import_shared72.ERROR_CODES.SYSTEM_ERROR],
|
|
4026
4144
|
details: `[Fatal System Error] Exception caught during request handling on path: ${req.path}`,
|
|
4027
4145
|
path: req.path
|
|
4028
4146
|
},
|
|
@@ -4031,7 +4149,7 @@ var init_request_middleware = __esm({
|
|
|
4031
4149
|
spanId,
|
|
4032
4150
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4033
4151
|
},
|
|
4034
|
-
|
|
4152
|
+
import_shared72.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
4035
4153
|
{ "Content-Type": [formatIndicator] }
|
|
4036
4154
|
);
|
|
4037
4155
|
}
|
|
@@ -4080,12 +4198,34 @@ var init_presentation = __esm({
|
|
|
4080
4198
|
}
|
|
4081
4199
|
});
|
|
4082
4200
|
|
|
4201
|
+
// src/infrastructure/cache/inmemory.cache.ts
|
|
4202
|
+
var inmemory_cache_exports = {};
|
|
4203
|
+
__export(inmemory_cache_exports, {
|
|
4204
|
+
InMemoryCacheExtended: () => InMemoryCacheExtended
|
|
4205
|
+
});
|
|
4206
|
+
var import_shared73, InMemoryCacheExtended;
|
|
4207
|
+
var init_inmemory_cache = __esm({
|
|
4208
|
+
"src/infrastructure/cache/inmemory.cache.ts"() {
|
|
4209
|
+
"use strict";
|
|
4210
|
+
import_shared73 = require("@xeno-js/shared");
|
|
4211
|
+
InMemoryCacheExtended = class extends import_shared73.InMemoryCache {
|
|
4212
|
+
async increment(key, ttlSeconds) {
|
|
4213
|
+
const current = await this.get(key) ?? 0;
|
|
4214
|
+
const next = Number(current) + 1;
|
|
4215
|
+
const ttl = import_shared73.Guards.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
4216
|
+
await this.set(key, next, ttl);
|
|
4217
|
+
return next;
|
|
4218
|
+
}
|
|
4219
|
+
};
|
|
4220
|
+
}
|
|
4221
|
+
});
|
|
4222
|
+
|
|
4083
4223
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
4084
|
-
var
|
|
4224
|
+
var import_shared74, RateLimitKeyBuilder;
|
|
4085
4225
|
var init_rate_limit_key_builder_cache = __esm({
|
|
4086
4226
|
"src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
|
|
4087
4227
|
"use strict";
|
|
4088
|
-
|
|
4228
|
+
import_shared74 = require("@xeno-js/shared");
|
|
4089
4229
|
RateLimitKeyBuilder = class {
|
|
4090
4230
|
constructor(_contextAccessor) {
|
|
4091
4231
|
this._contextAccessor = _contextAccessor;
|
|
@@ -4096,12 +4236,12 @@ var init_rate_limit_key_builder_cache = __esm({
|
|
|
4096
4236
|
const tenantId = ctx?.identity?.tenantId;
|
|
4097
4237
|
const userId = ctx?.identity?.userId;
|
|
4098
4238
|
const clientIp = ctx?.network?.clientIp;
|
|
4099
|
-
if (!
|
|
4239
|
+
if (!import_shared74.Guards.isNullOrEmpty(tenantId) && !import_shared74.Guards.isNullOrEmpty(userId))
|
|
4100
4240
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
4101
|
-
if (!
|
|
4241
|
+
if (!import_shared74.Guards.isNullOrEmpty(tenantId) && !import_shared74.Guards.isNullOrEmpty(clientIp))
|
|
4102
4242
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
4103
|
-
if (!
|
|
4104
|
-
if (!
|
|
4243
|
+
if (!import_shared74.Guards.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
4244
|
+
if (!import_shared74.Guards.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
4105
4245
|
return void 0;
|
|
4106
4246
|
}
|
|
4107
4247
|
};
|
|
@@ -4135,7 +4275,7 @@ var init_middleware_module = __esm({
|
|
|
4135
4275
|
"use strict";
|
|
4136
4276
|
MiddlewareModule = class {
|
|
4137
4277
|
async configure(container, opts) {
|
|
4138
|
-
const { Guards:
|
|
4278
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4139
4279
|
const { HttpCookieExtractor: HttpCookieExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4140
4280
|
const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4141
4281
|
const tokenExtractor = await this._getTokenExtractor(
|
|
@@ -4144,7 +4284,7 @@ var init_middleware_module = __esm({
|
|
|
4144
4284
|
opts.customTokenExtractor
|
|
4145
4285
|
);
|
|
4146
4286
|
container.addSingleton(
|
|
4147
|
-
|
|
4287
|
+
TOKENS5.SERVICE_EXTRACTOR,
|
|
4148
4288
|
() => new HttpHeaderExtractor2(
|
|
4149
4289
|
tokenExtractor,
|
|
4150
4290
|
new HttpCookieExtractor2(),
|
|
@@ -4154,18 +4294,18 @@ var init_middleware_module = __esm({
|
|
|
4154
4294
|
);
|
|
4155
4295
|
const { ClientIpResolver: ClientIpResolver2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4156
4296
|
const middlewares = [];
|
|
4157
|
-
const requestContext = container.resolve(
|
|
4158
|
-
const logger = container.resolve(
|
|
4297
|
+
const requestContext = container.resolve(TOKENS5.REQUEST_CONTEXT);
|
|
4298
|
+
const logger = container.resolve(TOKENS5.LOGGER);
|
|
4159
4299
|
const { RequestContextMiddleware: RequestContextMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4160
4300
|
middlewares.push(
|
|
4161
4301
|
new RequestContextMiddleware2(
|
|
4162
4302
|
requestContext,
|
|
4163
|
-
container.resolve(
|
|
4303
|
+
container.resolve(TOKENS5.SERVICE_EXTRACTOR),
|
|
4164
4304
|
new ClientIpResolver2(opts.trustedProxies),
|
|
4165
4305
|
logger
|
|
4166
4306
|
)
|
|
4167
4307
|
);
|
|
4168
|
-
if (!
|
|
4308
|
+
if (!Guards49.isNullOrEmpty(opts.allowOrigins)) {
|
|
4169
4309
|
if (opts.withCredentials && opts.allowOrigins.includes("*"))
|
|
4170
4310
|
throw new Error(
|
|
4171
4311
|
"Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
|
|
@@ -4191,7 +4331,7 @@ var init_middleware_module = __esm({
|
|
|
4191
4331
|
const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4192
4332
|
middlewares.push(new CORSMiddleware2(requestContext, withCredentials));
|
|
4193
4333
|
}
|
|
4194
|
-
if (
|
|
4334
|
+
if (Guards49.isDefined(opts.routeRegistry)) {
|
|
4195
4335
|
const { MethodCheckMiddleware: MethodCheckMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4196
4336
|
middlewares.push(new MethodCheckMiddleware2(requestContext, allowMethod));
|
|
4197
4337
|
}
|
|
@@ -4213,31 +4353,31 @@ var init_middleware_module = __esm({
|
|
|
4213
4353
|
new AuthenticationMiddleware2(
|
|
4214
4354
|
requestContext,
|
|
4215
4355
|
tokenExtractor,
|
|
4216
|
-
new GateKeeper2(container.resolve(
|
|
4356
|
+
new GateKeeper2(container.resolve(TOKENS5.BASE_AUTH_SERVICE), new ClaimsIdentityMapper2()),
|
|
4217
4357
|
logger
|
|
4218
4358
|
)
|
|
4219
4359
|
);
|
|
4220
4360
|
}
|
|
4221
|
-
if (
|
|
4361
|
+
if (Guards49.isDefined(opts.rateLimite.maxRequests) || Guards49.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4222
4362
|
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4223
|
-
|
|
4224
|
-
|
|
4363
|
+
Guards49.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4364
|
+
Guards49.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4225
4365
|
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4226
|
-
|
|
4227
|
-
|
|
4366
|
+
Guards49.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4367
|
+
Guards49.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4228
4368
|
const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
|
|
4229
4369
|
const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4230
4370
|
middlewares.push(
|
|
4231
4371
|
new RateLimitMiddleware2(
|
|
4232
4372
|
requestContext,
|
|
4233
|
-
container.resolve(
|
|
4373
|
+
container.resolve(TOKENS5.CACHE),
|
|
4234
4374
|
new RateLimitKeyBuilder2(requestContext),
|
|
4235
4375
|
logger,
|
|
4236
4376
|
{ maxRequests, windowSeconds }
|
|
4237
4377
|
)
|
|
4238
4378
|
);
|
|
4239
4379
|
}
|
|
4240
|
-
if (
|
|
4380
|
+
if (Guards49.isDefined(opts.csrf)) {
|
|
4241
4381
|
const csrf = opts.csrf;
|
|
4242
4382
|
const { EdgeCryptoService: EdgeCryptoService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4243
4383
|
container.addSingleton("CRYPTO_SERVICE", () => new EdgeCryptoService2());
|
|
@@ -4257,13 +4397,13 @@ var init_middleware_module = __esm({
|
|
|
4257
4397
|
middlewares.push(new CsrfMiddleware2(requestContext, container.resolve("CSRF_TOKEN_SERVICE")));
|
|
4258
4398
|
}
|
|
4259
4399
|
const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4260
|
-
container.addSingleton(
|
|
4400
|
+
container.addSingleton(TOKENS5.MIDDLEWARE, () => {
|
|
4261
4401
|
return new CompositeMiddleware2(middlewares);
|
|
4262
4402
|
});
|
|
4263
4403
|
}
|
|
4264
4404
|
async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
|
|
4265
|
-
const { Guards:
|
|
4266
|
-
if (
|
|
4405
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
4406
|
+
if (Guards49.isDefined(customTokenExtractor)) return customTokenExtractor();
|
|
4267
4407
|
if (isSSR) {
|
|
4268
4408
|
const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4269
4409
|
return new SupabaseSsrTokenExtractor2();
|
|
@@ -4273,8 +4413,8 @@ var init_middleware_module = __esm({
|
|
|
4273
4413
|
}
|
|
4274
4414
|
}
|
|
4275
4415
|
async _getAllowMethod(configure, opts) {
|
|
4276
|
-
const { Guards:
|
|
4277
|
-
if (!configure || !
|
|
4416
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
4417
|
+
if (!configure || !Guards49.isDefined(opts)) return void 0;
|
|
4278
4418
|
const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
4279
4419
|
return new AllowMethodFactory2().create(opts);
|
|
4280
4420
|
}
|
|
@@ -4282,37 +4422,203 @@ var init_middleware_module = __esm({
|
|
|
4282
4422
|
}
|
|
4283
4423
|
});
|
|
4284
4424
|
|
|
4285
|
-
// src/infrastructure/modules/
|
|
4286
|
-
var
|
|
4287
|
-
__export(
|
|
4288
|
-
|
|
4425
|
+
// src/infrastructure/modules/utils/cache.utils.ts
|
|
4426
|
+
var cache_utils_exports = {};
|
|
4427
|
+
__export(cache_utils_exports, {
|
|
4428
|
+
CacheUtils: () => CacheUtils
|
|
4289
4429
|
});
|
|
4290
|
-
var
|
|
4291
|
-
var
|
|
4292
|
-
"src/infrastructure/modules/
|
|
4430
|
+
var CacheUtils;
|
|
4431
|
+
var init_cache_utils = __esm({
|
|
4432
|
+
"src/infrastructure/modules/utils/cache.utils.ts"() {
|
|
4293
4433
|
"use strict";
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
const {
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4434
|
+
CacheUtils = Object.freeze({
|
|
4435
|
+
/**
|
|
4436
|
+
* @description Checks if the provided cache configuration requires any cache strategies.
|
|
4437
|
+
* @param container The service container to which the cache strategies will be added.
|
|
4438
|
+
* @param opts The cache configuration options.
|
|
4439
|
+
* @returns True if any cache strategies are required, false otherwise.
|
|
4440
|
+
*
|
|
4441
|
+
* @author Xeno
|
|
4442
|
+
* @version 1.0.0
|
|
4443
|
+
* @since 2025-09-30
|
|
4444
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
4445
|
+
*/
|
|
4446
|
+
async addCache(container, opts) {
|
|
4447
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4448
|
+
if (!opts.inMemory && !Guards49.isDefined(opts.redis)) {
|
|
4449
|
+
throw new Error(
|
|
4450
|
+
"No cache strategies are configured. Please provide at least one cache strategy."
|
|
4451
|
+
);
|
|
4452
|
+
}
|
|
4453
|
+
const { CacheKeyBuilder } = await import("@xeno-js/shared");
|
|
4454
|
+
container.addSingleton(
|
|
4455
|
+
TOKENS5.CACHE_KEY_BUILDER,
|
|
4456
|
+
(c) => new CacheKeyBuilder(c.resolve(TOKENS5.IDENTITY_ACCESSOR))
|
|
4457
|
+
);
|
|
4458
|
+
if (opts.inMemory || !Guards49.isDefined(opts.redis)) {
|
|
4459
|
+
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
4460
|
+
container.addSingleton(TOKENS5.CACHE, () => new InMemoryCacheExtended2());
|
|
4461
|
+
return;
|
|
4462
|
+
}
|
|
4463
|
+
if (Guards49.isDefined(opts.redis)) {
|
|
4464
|
+
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
4465
|
+
container.addSingleton(TOKENS5.CACHE, () => {
|
|
4466
|
+
const config = opts.redis;
|
|
4467
|
+
return new RedisCacheFactory2().create(config);
|
|
4468
|
+
});
|
|
4469
|
+
}
|
|
4470
|
+
}
|
|
4471
|
+
});
|
|
4472
|
+
}
|
|
4473
|
+
});
|
|
4474
|
+
|
|
4475
|
+
// src/infrastructure/loggers/console.logger.ts
|
|
4476
|
+
var console_logger_exports = {};
|
|
4477
|
+
__export(console_logger_exports, {
|
|
4478
|
+
ConsoleLogger: () => ConsoleLogger
|
|
4479
|
+
});
|
|
4480
|
+
var import_shared75, ConsoleLogger;
|
|
4481
|
+
var init_console_logger = __esm({
|
|
4482
|
+
"src/infrastructure/loggers/console.logger.ts"() {
|
|
4483
|
+
"use strict";
|
|
4484
|
+
import_shared75 = require("@xeno-js/shared");
|
|
4485
|
+
ConsoleLogger = class {
|
|
4486
|
+
/**
|
|
4487
|
+
* 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.
|
|
4488
|
+
* @param _minLevel The minimum log level for logging messages. Messages with a log level below this threshold will not be logged. Default is LOG_LEVEL.DEBUG.
|
|
4489
|
+
|
|
4490
|
+
*
|
|
4491
|
+
* @author Xeno
|
|
4492
|
+
* @version 1.0.0
|
|
4493
|
+
* @since 2025-09-30
|
|
4494
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
4495
|
+
*/
|
|
4496
|
+
constructor(_minLevel = import_shared75.LOG_LEVEL.DEBUG) {
|
|
4497
|
+
this._minLevel = _minLevel;
|
|
4498
|
+
}
|
|
4499
|
+
_minLevel;
|
|
4500
|
+
track(level, message, context, error = void 0) {
|
|
4501
|
+
if (level < this._minLevel) return;
|
|
4502
|
+
const logMessage = `[${level}] ${message}`;
|
|
4503
|
+
const payload = import_shared75.Guards.isDefined(error) ? { ...context, error } : context;
|
|
4504
|
+
switch (level) {
|
|
4505
|
+
case import_shared75.LOG_LEVEL.ERROR:
|
|
4506
|
+
console.error(logMessage, payload ?? {});
|
|
4507
|
+
break;
|
|
4508
|
+
case import_shared75.LOG_LEVEL.WARN:
|
|
4509
|
+
console.warn(logMessage, payload ?? {});
|
|
4510
|
+
break;
|
|
4511
|
+
case import_shared75.LOG_LEVEL.DEBUG:
|
|
4512
|
+
console.debug(logMessage, payload ?? {});
|
|
4513
|
+
break;
|
|
4514
|
+
default:
|
|
4515
|
+
console.info(logMessage, payload ?? {});
|
|
4516
|
+
break;
|
|
4517
|
+
}
|
|
4311
4518
|
}
|
|
4312
4519
|
};
|
|
4313
4520
|
}
|
|
4314
4521
|
});
|
|
4315
4522
|
|
|
4523
|
+
// src/infrastructure/modules/utils/logger.utils.ts
|
|
4524
|
+
var logger_utils_exports = {};
|
|
4525
|
+
__export(logger_utils_exports, {
|
|
4526
|
+
LoggerUtils: () => LoggerUtils
|
|
4527
|
+
});
|
|
4528
|
+
var LoggerUtils;
|
|
4529
|
+
var init_logger_utils = __esm({
|
|
4530
|
+
"src/infrastructure/modules/utils/logger.utils.ts"() {
|
|
4531
|
+
"use strict";
|
|
4532
|
+
LoggerUtils = Object.freeze({
|
|
4533
|
+
/**
|
|
4534
|
+
* @description Configures and registers the logging services in the dependency injection container based on the provided LoggerConfig options. It dynamically imports the necessary logger implementations (e.g., ConsoleLogger, SentryLogger, PinoLogger) and registers them with the container, allowing for flexible and modular logging configuration in the application.
|
|
4535
|
+
*
|
|
4536
|
+
* @param container - The service container to register logging services with.
|
|
4537
|
+
* @param opts - The LoggerConfig options to determine which loggers to enable and their configurations.
|
|
4538
|
+
|
|
4539
|
+
*
|
|
4540
|
+
* @author Xeno
|
|
4541
|
+
* @version 1.0.0
|
|
4542
|
+
* @since 2025-09-30
|
|
4543
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
4544
|
+
*/
|
|
4545
|
+
async addLogger(container, opts) {
|
|
4546
|
+
const loggerDependencies = [];
|
|
4547
|
+
const { Guards: Guards49, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4548
|
+
if (!Guards49.isDefined(opts) || opts.console) {
|
|
4549
|
+
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
4550
|
+
loggerDependencies.push(new ConsoleLogger2(opts?.level));
|
|
4551
|
+
}
|
|
4552
|
+
if (Guards49.isDefined(opts)) {
|
|
4553
|
+
if (Guards49.isDefined(opts.sentry.config)) {
|
|
4554
|
+
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
4555
|
+
loggerDependencies.push(new SentryLoggerFactory2().create(opts));
|
|
4556
|
+
}
|
|
4557
|
+
if (Guards49.isDefined(opts.pino.config)) {
|
|
4558
|
+
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
4559
|
+
loggerDependencies.push(new PinoLoggerFactory2().create(opts));
|
|
4560
|
+
}
|
|
4561
|
+
if (!Guards49.isNullOrEmpty(opts.customLoggers)) {
|
|
4562
|
+
const customLoggers = opts.customLoggers;
|
|
4563
|
+
customLoggers.forEach((fn) => {
|
|
4564
|
+
if (Guards49.isDefined(fn)) loggerDependencies.push(fn(container));
|
|
4565
|
+
});
|
|
4566
|
+
}
|
|
4567
|
+
}
|
|
4568
|
+
const { BaseLogger } = await import("@xeno-js/shared");
|
|
4569
|
+
container.addSingleton(TOKENS5.LOGGER, (c) => {
|
|
4570
|
+
const context = c.resolve(TOKENS5.CONTEXT_ACCESSOR);
|
|
4571
|
+
return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, loggerDependencies);
|
|
4572
|
+
});
|
|
4573
|
+
}
|
|
4574
|
+
});
|
|
4575
|
+
}
|
|
4576
|
+
});
|
|
4577
|
+
|
|
4578
|
+
// src/infrastructure/modules/utils/index.ts
|
|
4579
|
+
var init_utils2 = __esm({
|
|
4580
|
+
"src/infrastructure/modules/utils/index.ts"() {
|
|
4581
|
+
"use strict";
|
|
4582
|
+
init_auth_utils();
|
|
4583
|
+
init_cache_utils();
|
|
4584
|
+
init_db_utils();
|
|
4585
|
+
init_http_utils();
|
|
4586
|
+
init_logger_utils();
|
|
4587
|
+
init_pipeline_utils();
|
|
4588
|
+
init_validation_utils();
|
|
4589
|
+
}
|
|
4590
|
+
});
|
|
4591
|
+
|
|
4592
|
+
// src/infrastructure/modules/index.ts
|
|
4593
|
+
var modules_exports = {};
|
|
4594
|
+
__export(modules_exports, {
|
|
4595
|
+
AuthUtils: () => AuthUtils,
|
|
4596
|
+
CacheUtils: () => CacheUtils,
|
|
4597
|
+
ContextModule: () => ContextModule,
|
|
4598
|
+
CqrsModule: () => CqrsModule,
|
|
4599
|
+
DbModule: () => DbModule,
|
|
4600
|
+
DbUtils: () => DbUtils,
|
|
4601
|
+
HttpAdapterModule: () => HttpAdapterModule,
|
|
4602
|
+
HttpCoreModule: () => HttpCoreModule,
|
|
4603
|
+
HttpUtils: () => HttpUtils,
|
|
4604
|
+
LoggerUtils: () => LoggerUtils,
|
|
4605
|
+
MiddlewareModule: () => MiddlewareModule,
|
|
4606
|
+
PipelineUtils: () => PipelineUtils,
|
|
4607
|
+
ValidationUtils: () => ValidationUtils
|
|
4608
|
+
});
|
|
4609
|
+
var init_modules = __esm({
|
|
4610
|
+
"src/infrastructure/modules/index.ts"() {
|
|
4611
|
+
"use strict";
|
|
4612
|
+
init_context_module();
|
|
4613
|
+
init_cqrs_module();
|
|
4614
|
+
init_db_module();
|
|
4615
|
+
init_http_adapter_module();
|
|
4616
|
+
init_http_core_module();
|
|
4617
|
+
init_middleware_module();
|
|
4618
|
+
init_utils2();
|
|
4619
|
+
}
|
|
4620
|
+
});
|
|
4621
|
+
|
|
4316
4622
|
// src/index.ts
|
|
4317
4623
|
var index_exports = {};
|
|
4318
4624
|
__export(index_exports, {
|
|
@@ -4321,7 +4627,7 @@ __export(index_exports, {
|
|
|
4321
4627
|
BaseController: () => BaseController,
|
|
4322
4628
|
BaseHandler: () => BaseHandler,
|
|
4323
4629
|
BasePostgresSqlDataSource: () => BasePostgresSqlDataSource,
|
|
4324
|
-
BaseQuery: () =>
|
|
4630
|
+
BaseQuery: () => import_shared82.Query,
|
|
4325
4631
|
BaseSqliteSqlDataSource: () => BaseSqliteSqlDataSource,
|
|
4326
4632
|
ContainerUtils: () => ContainerUtils,
|
|
4327
4633
|
ReadDao: () => ReadDao,
|
|
@@ -4333,7 +4639,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
4333
4639
|
init_application();
|
|
4334
4640
|
|
|
4335
4641
|
// src/infrastructure/builder/app.builder.ts
|
|
4336
|
-
var
|
|
4642
|
+
var import_shared76 = require("@xeno-js/shared");
|
|
4337
4643
|
|
|
4338
4644
|
// src/infrastructure/configuration/configuration.ts
|
|
4339
4645
|
var import_shared32 = require("@xeno-js/shared");
|
|
@@ -4612,17 +4918,24 @@ var AppBuilder = class {
|
|
|
4612
4918
|
constructor(container) {
|
|
4613
4919
|
this._container = container ?? new ServiceContainer();
|
|
4614
4920
|
this._container.addSingleton(
|
|
4615
|
-
|
|
4921
|
+
import_shared76.TOKENS.CONFIGURATION_SERVICE,
|
|
4616
4922
|
() => new EnvironmentConfigurationService()
|
|
4617
4923
|
);
|
|
4618
|
-
this._configuration = this._container.resolve(
|
|
4924
|
+
this._configuration = this._container.resolve(import_shared76.TOKENS.CONFIGURATION_SERVICE);
|
|
4619
4925
|
this._middlewareConfig.allowOrigins?.push(
|
|
4620
4926
|
this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
|
|
4621
4927
|
);
|
|
4928
|
+
this.addContext();
|
|
4622
4929
|
}
|
|
4623
4930
|
// --- Module Configurations ---
|
|
4624
4931
|
_modules = [];
|
|
4625
4932
|
// --- Specific Configurations ---
|
|
4933
|
+
_adapterConfig = {
|
|
4934
|
+
native: true,
|
|
4935
|
+
vercel: false,
|
|
4936
|
+
fastify: false,
|
|
4937
|
+
custom: void 0
|
|
4938
|
+
};
|
|
4626
4939
|
_pipelineConfig = {
|
|
4627
4940
|
performance: { thresholdMs: 500 },
|
|
4628
4941
|
authorization: {
|
|
@@ -4664,7 +4977,13 @@ var AppBuilder = class {
|
|
|
4664
4977
|
redirectTo: "",
|
|
4665
4978
|
storageOpts: { type: "memory", cookieOpts: void 0, storage: void 0 },
|
|
4666
4979
|
ssrOpts: void 0,
|
|
4667
|
-
customAuth: void 0
|
|
4980
|
+
customAuth: void 0,
|
|
4981
|
+
cookieOpts: {
|
|
4982
|
+
path: "/",
|
|
4983
|
+
httpOnly: true,
|
|
4984
|
+
sameSite: "lax",
|
|
4985
|
+
secure: true
|
|
4986
|
+
}
|
|
4668
4987
|
};
|
|
4669
4988
|
_httpConfig = {
|
|
4670
4989
|
dataSourceToken: void 0,
|
|
@@ -4685,7 +5004,7 @@ var AppBuilder = class {
|
|
|
4685
5004
|
resilience: { retry: {}, circuitBreaker: {}, bulkhead: {} }
|
|
4686
5005
|
};
|
|
4687
5006
|
_loggerConfig = {
|
|
4688
|
-
level:
|
|
5007
|
+
level: import_shared76.LOG_LEVEL.DEBUG,
|
|
4689
5008
|
console: true,
|
|
4690
5009
|
sentry: { config: void 0 },
|
|
4691
5010
|
pino: { config: void 0 },
|
|
@@ -4700,9 +5019,24 @@ var AppBuilder = class {
|
|
|
4700
5019
|
_isDbContextModuleQueued = false;
|
|
4701
5020
|
_isConcurrencyServiceQueued = false;
|
|
4702
5021
|
_isCacheModuleQueued = false;
|
|
5022
|
+
_isAdapterModuleQueued = false;
|
|
4703
5023
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
4704
5024
|
// Application Modules Configuration
|
|
4705
5025
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
5026
|
+
addAdapter(setupAction) {
|
|
5027
|
+
if (this._isAdapterModuleQueued) return this;
|
|
5028
|
+
setupAction(this._adapterConfig, this._configuration);
|
|
5029
|
+
this._isAdapterModuleQueued = true;
|
|
5030
|
+
this._modules.push({
|
|
5031
|
+
priority: 50,
|
|
5032
|
+
name: "AdapterModule",
|
|
5033
|
+
action: async () => {
|
|
5034
|
+
const { HttpAdapterModule: HttpAdapterModule2 } = await Promise.resolve().then(() => (init_modules(), modules_exports));
|
|
5035
|
+
await new HttpAdapterModule2().configure(this._container, this._adapterConfig);
|
|
5036
|
+
}
|
|
5037
|
+
});
|
|
5038
|
+
return this;
|
|
5039
|
+
}
|
|
4706
5040
|
/**
|
|
4707
5041
|
* @description Enables the use of middlewares in the application. Middlewares can be used for cross-cutting concerns such as logging, authentication, and request/response manipulation.
|
|
4708
5042
|
* @returns The current instance of AppBuilder for method chaining.
|
|
@@ -4743,7 +5077,7 @@ var AppBuilder = class {
|
|
|
4743
5077
|
* @link https://github.com/xeno-js/xeno-js
|
|
4744
5078
|
*/
|
|
4745
5079
|
addLogger(setupAction) {
|
|
4746
|
-
if (
|
|
5080
|
+
if (import_shared76.Guards.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
|
|
4747
5081
|
if (this._isLoggerModuleQueued) return this;
|
|
4748
5082
|
this._isLoggerModuleQueued = true;
|
|
4749
5083
|
this._modules.push({
|
|
@@ -4768,7 +5102,7 @@ var AppBuilder = class {
|
|
|
4768
5102
|
* @link https://github.com/xeno-js/xeno-js
|
|
4769
5103
|
*/
|
|
4770
5104
|
addCache(setupAction) {
|
|
4771
|
-
if (
|
|
5105
|
+
if (import_shared76.Guards.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
4772
5106
|
if (this._isCacheModuleQueued) return this;
|
|
4773
5107
|
this._isCacheModuleQueued = true;
|
|
4774
5108
|
this._modules.push({
|
|
@@ -4871,7 +5205,7 @@ var AppBuilder = class {
|
|
|
4871
5205
|
* @link https://github.com/xeno-js/xeno-js
|
|
4872
5206
|
*/
|
|
4873
5207
|
addPipeline(setupAction) {
|
|
4874
|
-
if (
|
|
5208
|
+
if (import_shared76.Guards.isDefined(setupAction)) {
|
|
4875
5209
|
setupAction(this._pipelineConfig, this._configuration);
|
|
4876
5210
|
}
|
|
4877
5211
|
this._queuePipelineModule();
|
|
@@ -4992,7 +5326,7 @@ var AppBuilder = class {
|
|
|
4992
5326
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
4993
5327
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
4994
5328
|
`);
|
|
4995
|
-
if (error instanceof Error &&
|
|
5329
|
+
if (error instanceof Error && import_shared76.Guards.isDefined(error.stack)) {
|
|
4996
5330
|
console.error(error.stack);
|
|
4997
5331
|
}
|
|
4998
5332
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5120,7 +5454,7 @@ var BaseSqliteSqlDataSource = class {
|
|
|
5120
5454
|
};
|
|
5121
5455
|
|
|
5122
5456
|
// src/infrastructure/datasources/remote.datasource.ts
|
|
5123
|
-
var
|
|
5457
|
+
var import_shared77 = require("@xeno-js/shared");
|
|
5124
5458
|
|
|
5125
5459
|
// src/infrastructure/index.ts
|
|
5126
5460
|
init_factories();
|
|
@@ -5131,25 +5465,12 @@ init_console_logger();
|
|
|
5131
5465
|
init_pino_logger();
|
|
5132
5466
|
init_sentry_logger();
|
|
5133
5467
|
|
|
5134
|
-
// src/infrastructure/
|
|
5135
|
-
|
|
5136
|
-
init_cqrs_module();
|
|
5137
|
-
init_db_module();
|
|
5138
|
-
init_http_core_module();
|
|
5139
|
-
init_middleware_module();
|
|
5140
|
-
|
|
5141
|
-
// src/infrastructure/modules/utils/index.ts
|
|
5142
|
-
init_auth_utils();
|
|
5143
|
-
init_cache_utils();
|
|
5144
|
-
init_db_utils();
|
|
5145
|
-
init_http_utils();
|
|
5146
|
-
init_logger_utils();
|
|
5147
|
-
init_pipeline_utils();
|
|
5148
|
-
init_validation_utils();
|
|
5468
|
+
// src/infrastructure/index.ts
|
|
5469
|
+
init_modules();
|
|
5149
5470
|
|
|
5150
5471
|
// src/infrastructure/repositories/read-dao.ts
|
|
5151
|
-
var
|
|
5152
|
-
var
|
|
5472
|
+
var import_shared78 = require("@xeno-js/shared");
|
|
5473
|
+
var import_shared79 = require("@xeno-js/shared");
|
|
5153
5474
|
var ReadDao = class {
|
|
5154
5475
|
/**
|
|
5155
5476
|
* Constructs a new ReadDao instance.
|
|
@@ -5169,23 +5490,23 @@ var ReadDao = class {
|
|
|
5169
5490
|
_dataSource;
|
|
5170
5491
|
_mapper;
|
|
5171
5492
|
async findById(id, ctx, signal) {
|
|
5172
|
-
|
|
5493
|
+
import_shared78.AppError.throwIfAborted(signal, "ReadDao.findById");
|
|
5173
5494
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5174
|
-
if (
|
|
5495
|
+
if (import_shared79.Guards.isNullOrEmpty(result)) return import_shared78.Result.ok();
|
|
5175
5496
|
const entity = this._mapper.toEntity(result);
|
|
5176
|
-
return
|
|
5497
|
+
return import_shared78.Result.ok(entity);
|
|
5177
5498
|
}
|
|
5178
5499
|
async findAll(ctx, signal) {
|
|
5179
|
-
|
|
5500
|
+
import_shared78.AppError.throwIfAborted(signal, "ReadDao.findAll");
|
|
5180
5501
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5181
5502
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5182
|
-
return
|
|
5503
|
+
return import_shared78.Result.ok(entities);
|
|
5183
5504
|
}
|
|
5184
5505
|
};
|
|
5185
5506
|
|
|
5186
5507
|
// src/infrastructure/repositories/repository.ts
|
|
5187
|
-
var
|
|
5188
|
-
var
|
|
5508
|
+
var import_shared80 = require("@xeno-js/shared");
|
|
5509
|
+
var import_shared81 = require("@xeno-js/shared");
|
|
5189
5510
|
var Repository = class {
|
|
5190
5511
|
/**
|
|
5191
5512
|
* Constructs a new Repository instance.
|
|
@@ -5205,35 +5526,35 @@ var Repository = class {
|
|
|
5205
5526
|
_dataSource;
|
|
5206
5527
|
_mapper;
|
|
5207
5528
|
async findById(id, ctx, signal) {
|
|
5208
|
-
|
|
5529
|
+
import_shared80.AppError.throwIfAborted(signal, "Repository.findById");
|
|
5209
5530
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5210
|
-
if (
|
|
5531
|
+
if (import_shared81.Guards.isNullOrEmpty(result)) return import_shared80.Result.ok();
|
|
5211
5532
|
const entity = this._mapper.toEntity(result);
|
|
5212
|
-
return
|
|
5533
|
+
return import_shared80.Result.ok(entity);
|
|
5213
5534
|
}
|
|
5214
5535
|
async findAll(ctx, signal) {
|
|
5215
|
-
|
|
5536
|
+
import_shared80.AppError.throwIfAborted(signal, "Repository.findAll");
|
|
5216
5537
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5217
5538
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5218
|
-
return
|
|
5539
|
+
return import_shared80.Result.ok(entities);
|
|
5219
5540
|
}
|
|
5220
5541
|
async save(entity, signal) {
|
|
5221
5542
|
const dto = this._mapper.toDto(entity);
|
|
5222
|
-
|
|
5543
|
+
import_shared80.AppError.throwIfAborted(signal, "Repository.save");
|
|
5223
5544
|
await this._dataSource.insert(dto, signal);
|
|
5224
|
-
return
|
|
5545
|
+
return import_shared80.Result.ok();
|
|
5225
5546
|
}
|
|
5226
5547
|
async delete(entity, ctx, signal) {
|
|
5227
5548
|
const dto = this._mapper.toDto(entity);
|
|
5228
|
-
|
|
5549
|
+
import_shared80.AppError.throwIfAborted(signal, "Repository.delete");
|
|
5229
5550
|
await this._dataSource.delete(dto, ctx, signal);
|
|
5230
|
-
return
|
|
5551
|
+
return import_shared80.Result.ok();
|
|
5231
5552
|
}
|
|
5232
5553
|
async update(id, entity, ctx, signal) {
|
|
5233
5554
|
const dto = this._mapper.toPartialDto(entity);
|
|
5234
|
-
|
|
5555
|
+
import_shared80.AppError.throwIfAborted(signal, "Repository.update");
|
|
5235
5556
|
await this._dataSource.update(id, dto, ctx, signal);
|
|
5236
|
-
return
|
|
5557
|
+
return import_shared80.Result.ok();
|
|
5237
5558
|
}
|
|
5238
5559
|
};
|
|
5239
5560
|
|
|
@@ -5251,7 +5572,7 @@ __reExport(drizzle_types_exports, require("drizzle-orm"));
|
|
|
5251
5572
|
__reExport(index_exports, drizzle_types_exports, module.exports);
|
|
5252
5573
|
init_presentation();
|
|
5253
5574
|
__reExport(index_exports, require("@xeno-js/shared"), module.exports);
|
|
5254
|
-
var
|
|
5575
|
+
var import_shared82 = require("@xeno-js/shared");
|
|
5255
5576
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5256
5577
|
0 && (module.exports = {
|
|
5257
5578
|
AppBuilder,
|