@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.js
CHANGED
|
@@ -57,8 +57,10 @@ var init_container_utils = __esm({
|
|
|
57
57
|
* @throws Error If the service is not a scoped service.
|
|
58
58
|
*/
|
|
59
59
|
async runExecute(res, req, container, action) {
|
|
60
|
+
const adapter = container.resolve("HTTP_ADAPTER");
|
|
61
|
+
const { request, response } = adapter.adapt(req, res);
|
|
60
62
|
const middleware = container.resolve(TOKENS.MIDDLEWARE);
|
|
61
|
-
return await middleware.execute(
|
|
63
|
+
return await middleware.execute(request, response, async () => {
|
|
62
64
|
return await action();
|
|
63
65
|
});
|
|
64
66
|
}
|
|
@@ -1254,466 +1256,189 @@ var init_application = __esm({
|
|
|
1254
1256
|
}
|
|
1255
1257
|
});
|
|
1256
1258
|
|
|
1257
|
-
// src/infrastructure/
|
|
1258
|
-
var
|
|
1259
|
-
__export(
|
|
1260
|
-
|
|
1261
|
-
});
|
|
1262
|
-
import { Guards as Guards15, LOG_LEVEL } from "@xeno-js/shared";
|
|
1263
|
-
var ConsoleLogger;
|
|
1264
|
-
var init_console_logger = __esm({
|
|
1265
|
-
"src/infrastructure/loggers/console.logger.ts"() {
|
|
1266
|
-
"use strict";
|
|
1267
|
-
ConsoleLogger = class {
|
|
1268
|
-
/**
|
|
1269
|
-
* 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.
|
|
1270
|
-
* @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.
|
|
1271
|
-
|
|
1272
|
-
*
|
|
1273
|
-
* @author Xeno
|
|
1274
|
-
* @version 1.0.0
|
|
1275
|
-
* @since 2025-09-30
|
|
1276
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1277
|
-
*/
|
|
1278
|
-
constructor(_minLevel = LOG_LEVEL.DEBUG) {
|
|
1279
|
-
this._minLevel = _minLevel;
|
|
1280
|
-
}
|
|
1281
|
-
_minLevel;
|
|
1282
|
-
track(level, message, context, error = void 0) {
|
|
1283
|
-
if (level < this._minLevel) return;
|
|
1284
|
-
const logMessage = `[${level}] ${message}`;
|
|
1285
|
-
const payload = Guards15.isDefined(error) ? { ...context, error } : context;
|
|
1286
|
-
switch (level) {
|
|
1287
|
-
case LOG_LEVEL.ERROR:
|
|
1288
|
-
console.error(logMessage, payload ?? {});
|
|
1289
|
-
break;
|
|
1290
|
-
case LOG_LEVEL.WARN:
|
|
1291
|
-
console.warn(logMessage, payload ?? {});
|
|
1292
|
-
break;
|
|
1293
|
-
case LOG_LEVEL.DEBUG:
|
|
1294
|
-
console.debug(logMessage, payload ?? {});
|
|
1295
|
-
break;
|
|
1296
|
-
default:
|
|
1297
|
-
console.info(logMessage, payload ?? {});
|
|
1298
|
-
break;
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
};
|
|
1302
|
-
}
|
|
1303
|
-
});
|
|
1304
|
-
|
|
1305
|
-
// src/infrastructure/loggers/sentry.logger.ts
|
|
1306
|
-
import { Guards as Guards16, LOG_LEVEL as LOG_LEVEL2 } from "@xeno-js/shared";
|
|
1307
|
-
var SentryLogger;
|
|
1308
|
-
var init_sentry_logger = __esm({
|
|
1309
|
-
"src/infrastructure/loggers/sentry.logger.ts"() {
|
|
1310
|
-
"use strict";
|
|
1311
|
-
SentryLogger = class {
|
|
1312
|
-
constructor(_client, _minLevel) {
|
|
1313
|
-
this._client = _client;
|
|
1314
|
-
this._minLevel = _minLevel;
|
|
1315
|
-
}
|
|
1316
|
-
_client;
|
|
1317
|
-
_minLevel;
|
|
1318
|
-
track(level, message, context = void 0, error = void 0) {
|
|
1319
|
-
if (level < this._minLevel) return;
|
|
1320
|
-
if (level === LOG_LEVEL2.ERROR || level === LOG_LEVEL2.WARN) {
|
|
1321
|
-
this._client.withScope((scope) => {
|
|
1322
|
-
if (Guards16.isDefined(context)) scope.setExtras(context);
|
|
1323
|
-
if (Guards16.isDefined(error)) {
|
|
1324
|
-
this._client.captureException(error);
|
|
1325
|
-
} else {
|
|
1326
|
-
this._client.captureMessage(message, "warning");
|
|
1327
|
-
}
|
|
1328
|
-
});
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
});
|
|
1334
|
-
|
|
1335
|
-
// src/infrastructure/factories/sentry-logger.factory.ts
|
|
1336
|
-
var sentry_logger_factory_exports = {};
|
|
1337
|
-
__export(sentry_logger_factory_exports, {
|
|
1338
|
-
SentryLoggerFactory: () => SentryLoggerFactory
|
|
1339
|
-
});
|
|
1340
|
-
import * as Sentry from "@sentry/node";
|
|
1341
|
-
import { Guards as Guards17, LOG_LEVEL as LOG_LEVEL3 } from "@xeno-js/shared";
|
|
1342
|
-
var SentryLoggerFactory;
|
|
1343
|
-
var init_sentry_logger_factory = __esm({
|
|
1344
|
-
"src/infrastructure/factories/sentry-logger.factory.ts"() {
|
|
1345
|
-
"use strict";
|
|
1346
|
-
init_sentry_logger();
|
|
1347
|
-
SentryLoggerFactory = class {
|
|
1348
|
-
create(config) {
|
|
1349
|
-
const level = config.level ?? LOG_LEVEL3.WARN;
|
|
1350
|
-
const sentryConfig = config.sentry?.config;
|
|
1351
|
-
const env = sentryConfig?.environment ?? process.env.NODE_ENV ?? "development";
|
|
1352
|
-
if (!Guards17.isDefined(sentryConfig))
|
|
1353
|
-
throw new Error("Sentry configuration is required when Sentry logging is enabled.");
|
|
1354
|
-
if (!Guards17.isDefined(sentryConfig.dsn))
|
|
1355
|
-
throw new Error("Sentry DSN is required when Sentry logging is enabled.");
|
|
1356
|
-
Sentry.init({
|
|
1357
|
-
dsn: sentryConfig.dsn,
|
|
1358
|
-
environment: env,
|
|
1359
|
-
tracesSampleRate: env === "production" ? 0.1 : 1,
|
|
1360
|
-
integrations: [Sentry.httpIntegration()],
|
|
1361
|
-
beforeSend(event, hint) {
|
|
1362
|
-
const error = hint.originalException;
|
|
1363
|
-
if (error instanceof Error && error.name === "ZodError") {
|
|
1364
|
-
return null;
|
|
1365
|
-
}
|
|
1366
|
-
return event;
|
|
1367
|
-
}
|
|
1368
|
-
});
|
|
1369
|
-
return new SentryLogger(Sentry, level);
|
|
1370
|
-
}
|
|
1371
|
-
};
|
|
1372
|
-
}
|
|
1259
|
+
// src/infrastructure/factories/service-scope.factory.ts
|
|
1260
|
+
var service_scope_factory_exports = {};
|
|
1261
|
+
__export(service_scope_factory_exports, {
|
|
1262
|
+
ServiceScopeFactory: () => ServiceScopeFactory
|
|
1373
1263
|
});
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
var PinoLogger;
|
|
1378
|
-
var init_pino_logger = __esm({
|
|
1379
|
-
"src/infrastructure/loggers/pino.logger.ts"() {
|
|
1264
|
+
var ServiceScopeFactory;
|
|
1265
|
+
var init_service_scope_factory = __esm({
|
|
1266
|
+
"src/infrastructure/factories/service-scope.factory.ts"() {
|
|
1380
1267
|
"use strict";
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
* @param _logger The Pino logger instance used for logging messages.
|
|
1385
|
-
* @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.
|
|
1386
|
-
|
|
1387
|
-
*
|
|
1388
|
-
* @author Xeno
|
|
1389
|
-
* @version 1.0.0
|
|
1390
|
-
* @since 2025-09-30
|
|
1391
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1392
|
-
*/
|
|
1393
|
-
constructor(_logger, _minLevel = LOG_LEVEL4.DEBUG) {
|
|
1394
|
-
this._logger = _logger;
|
|
1395
|
-
this._minLevel = _minLevel;
|
|
1396
|
-
}
|
|
1397
|
-
_logger;
|
|
1398
|
-
_minLevel;
|
|
1399
|
-
track(level, message, context, error = void 0) {
|
|
1400
|
-
if (level < this._minLevel) return;
|
|
1401
|
-
const payload = Guards18.isDefined(error) ? { ...context, error } : context;
|
|
1402
|
-
switch (level) {
|
|
1403
|
-
case LOG_LEVEL4.ERROR:
|
|
1404
|
-
this._logger.error(payload ?? {}, message);
|
|
1405
|
-
break;
|
|
1406
|
-
case LOG_LEVEL4.WARN:
|
|
1407
|
-
this._logger.warn(payload ?? {}, message);
|
|
1408
|
-
break;
|
|
1409
|
-
case LOG_LEVEL4.DEBUG:
|
|
1410
|
-
this._logger.debug(payload ?? {}, message);
|
|
1411
|
-
break;
|
|
1412
|
-
default:
|
|
1413
|
-
this._logger.info(payload ?? {}, message);
|
|
1414
|
-
break;
|
|
1415
|
-
}
|
|
1268
|
+
ServiceScopeFactory = class {
|
|
1269
|
+
constructor(_container) {
|
|
1270
|
+
this._container = _container;
|
|
1416
1271
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
// src/infrastructure/factories/pino-logger.factory.ts
|
|
1422
|
-
var pino_logger_factory_exports = {};
|
|
1423
|
-
__export(pino_logger_factory_exports, {
|
|
1424
|
-
PinoLoggerFactory: () => PinoLoggerFactory
|
|
1425
|
-
});
|
|
1426
|
-
import { LOG_LEVEL as LOG_LEVEL5 } from "@xeno-js/shared";
|
|
1427
|
-
import pino from "pino";
|
|
1428
|
-
var PinoLoggerFactory;
|
|
1429
|
-
var init_pino_logger_factory = __esm({
|
|
1430
|
-
"src/infrastructure/factories/pino-logger.factory.ts"() {
|
|
1431
|
-
"use strict";
|
|
1432
|
-
init_pino_logger();
|
|
1433
|
-
PinoLoggerFactory = class {
|
|
1434
|
-
create(config) {
|
|
1435
|
-
const level = config.level ?? LOG_LEVEL5.DEBUG;
|
|
1436
|
-
const env = config.pino.config?.env ?? process.env.NODE_ENV ?? "development";
|
|
1437
|
-
const destinationType = config.pino.config?.destination ?? "stdout";
|
|
1438
|
-
const filePath = config.pino.config?.filePath ?? "logs/app.log";
|
|
1439
|
-
const prettyPrint = config.pino.config?.prettyPrint ?? env === "development";
|
|
1440
|
-
const options = {
|
|
1441
|
-
level: "trace",
|
|
1442
|
-
serializers: {
|
|
1443
|
-
err: pino.stdSerializers.err
|
|
1444
|
-
},
|
|
1445
|
-
timestamp: pino.stdTimeFunctions.isoTime,
|
|
1446
|
-
redact: {
|
|
1447
|
-
paths: ["password", "token", "secret", "authorization", "headers.authorization"],
|
|
1448
|
-
censor: "***"
|
|
1449
|
-
}
|
|
1450
|
-
};
|
|
1451
|
-
if (prettyPrint) {
|
|
1452
|
-
return new PinoLogger(
|
|
1453
|
-
pino({
|
|
1454
|
-
...options,
|
|
1455
|
-
transport: {
|
|
1456
|
-
target: "pino-pretty",
|
|
1457
|
-
options: {
|
|
1458
|
-
colorize: true,
|
|
1459
|
-
ignore: "pid,hostname",
|
|
1460
|
-
translateTime: "SYS:standard"
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
}),
|
|
1464
|
-
level
|
|
1465
|
-
);
|
|
1466
|
-
}
|
|
1467
|
-
if (destinationType === "file") {
|
|
1468
|
-
const destination = pino.destination({ dest: filePath, sync: false });
|
|
1469
|
-
return new PinoLogger(pino(options, destination), level);
|
|
1470
|
-
} else {
|
|
1471
|
-
const stream = pino.destination({ dest: 1, sync: false });
|
|
1472
|
-
return new PinoLogger(pino(options, stream), level);
|
|
1473
|
-
}
|
|
1272
|
+
_container;
|
|
1273
|
+
create() {
|
|
1274
|
+
return this._container.createScope();
|
|
1474
1275
|
}
|
|
1475
1276
|
};
|
|
1476
1277
|
}
|
|
1477
1278
|
});
|
|
1478
1279
|
|
|
1479
|
-
// src/infrastructure/
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
var LoggerUtils;
|
|
1485
|
-
var init_logger_utils = __esm({
|
|
1486
|
-
"src/infrastructure/modules/utils/logger.utils.ts"() {
|
|
1280
|
+
// src/infrastructure/context/request-context.ts
|
|
1281
|
+
import { Guards as Guards15 } from "@xeno-js/shared";
|
|
1282
|
+
var NodeRequestContext;
|
|
1283
|
+
var init_request_context = __esm({
|
|
1284
|
+
"src/infrastructure/context/request-context.ts"() {
|
|
1487
1285
|
"use strict";
|
|
1488
|
-
|
|
1286
|
+
NodeRequestContext = class {
|
|
1489
1287
|
/**
|
|
1490
|
-
* @description
|
|
1288
|
+
* @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.
|
|
1289
|
+
* @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.
|
|
1290
|
+
* @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.
|
|
1491
1291
|
*
|
|
1492
|
-
* @param container - The service container to register logging services with.
|
|
1493
|
-
* @param opts - The LoggerConfig options to determine which loggers to enable and their configurations.
|
|
1494
|
-
|
|
1495
|
-
*
|
|
1496
1292
|
* @author Xeno
|
|
1497
1293
|
* @version 1.0.0
|
|
1498
1294
|
* @since 2025-09-30
|
|
1499
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1500
|
-
*/
|
|
1501
|
-
async addLogger(container, opts) {
|
|
1502
|
-
const loggerDependencies = [];
|
|
1503
|
-
const { Guards: Guards46, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
1504
|
-
if (!Guards46.isDefined(opts) || opts.console) {
|
|
1505
|
-
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
1506
|
-
loggerDependencies.push(new ConsoleLogger2(opts?.level));
|
|
1507
|
-
}
|
|
1508
|
-
if (Guards46.isDefined(opts)) {
|
|
1509
|
-
if (Guards46.isDefined(opts.sentry.config)) {
|
|
1510
|
-
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
1511
|
-
loggerDependencies.push(new SentryLoggerFactory2().create(opts));
|
|
1512
|
-
}
|
|
1513
|
-
if (Guards46.isDefined(opts.pino.config)) {
|
|
1514
|
-
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
1515
|
-
loggerDependencies.push(new PinoLoggerFactory2().create(opts));
|
|
1516
|
-
}
|
|
1517
|
-
if (!Guards46.isNullOrEmpty(opts.customLoggers)) {
|
|
1518
|
-
const customLoggers = opts.customLoggers;
|
|
1519
|
-
customLoggers.forEach((fn) => {
|
|
1520
|
-
if (Guards46.isDefined(fn)) loggerDependencies.push(fn(container));
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
const { BaseLogger } = await import("@xeno-js/shared");
|
|
1525
|
-
container.addSingleton(TOKENS4.LOGGER, (c) => {
|
|
1526
|
-
const context = c.resolve(TOKENS4.CONTEXT_ACCESSOR);
|
|
1527
|
-
return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, loggerDependencies);
|
|
1528
|
-
});
|
|
1529
|
-
}
|
|
1530
|
-
});
|
|
1531
|
-
}
|
|
1532
|
-
});
|
|
1533
|
-
|
|
1534
|
-
// src/infrastructure/cache/inmemory.cache.ts
|
|
1535
|
-
var inmemory_cache_exports = {};
|
|
1536
|
-
__export(inmemory_cache_exports, {
|
|
1537
|
-
InMemoryCacheExtended: () => InMemoryCacheExtended
|
|
1538
|
-
});
|
|
1539
|
-
import { Guards as Guards19, InMemoryCache } from "@xeno-js/shared";
|
|
1540
|
-
var InMemoryCacheExtended;
|
|
1541
|
-
var init_inmemory_cache = __esm({
|
|
1542
|
-
"src/infrastructure/cache/inmemory.cache.ts"() {
|
|
1543
|
-
"use strict";
|
|
1544
|
-
InMemoryCacheExtended = class extends InMemoryCache {
|
|
1545
|
-
async increment(key, ttlSeconds) {
|
|
1546
|
-
const current = await this.get(key) ?? 0;
|
|
1547
|
-
const next = Number(current) + 1;
|
|
1548
|
-
const ttl = Guards19.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
1549
|
-
await this.set(key, next, ttl);
|
|
1550
|
-
return next;
|
|
1551
|
-
}
|
|
1552
|
-
};
|
|
1553
|
-
}
|
|
1554
|
-
});
|
|
1555
|
-
|
|
1556
|
-
// src/infrastructure/cache/redis.cache.ts
|
|
1557
|
-
import { Guards as Guards20, StringHelper } from "@xeno-js/shared";
|
|
1558
|
-
var RedisCache;
|
|
1559
|
-
var init_redis_cache = __esm({
|
|
1560
|
-
"src/infrastructure/cache/redis.cache.ts"() {
|
|
1561
|
-
"use strict";
|
|
1562
|
-
RedisCache = class {
|
|
1563
|
-
/**
|
|
1564
|
-
* @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.
|
|
1565
|
-
* @param _redisClient An instance of the Redis client from the ioredis library, used to perform caching operations in the Redis database.
|
|
1566
|
-
|
|
1567
|
-
*
|
|
1568
|
-
* @author Xeno
|
|
1569
|
-
* @version 1.0.0
|
|
1570
|
-
* @since 2025-09-30
|
|
1571
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1295
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
1572
1296
|
*/
|
|
1573
|
-
constructor(
|
|
1574
|
-
this.
|
|
1575
|
-
|
|
1576
|
-
_redisClient;
|
|
1577
|
-
async increment(key, ttlSeconds) {
|
|
1578
|
-
const multi = this._redisClient.multi();
|
|
1579
|
-
multi.incr(key);
|
|
1580
|
-
multi.expire(key, ttlSeconds ?? 60);
|
|
1581
|
-
const results = await multi.exec();
|
|
1582
|
-
return results?.[0]?.[1] ?? 1;
|
|
1297
|
+
constructor(_storage, _factoryScope) {
|
|
1298
|
+
this._storage = _storage;
|
|
1299
|
+
this._factoryScope = _factoryScope;
|
|
1583
1300
|
}
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1301
|
+
_storage;
|
|
1302
|
+
_factoryScope;
|
|
1303
|
+
async runAsync(context, fn) {
|
|
1304
|
+
const scope = this._factoryScope.create();
|
|
1305
|
+
try {
|
|
1306
|
+
return await this._storage.run({ context, scope }, fn);
|
|
1307
|
+
} finally {
|
|
1308
|
+
await scope.dispose();
|
|
1588
1309
|
}
|
|
1589
|
-
return JSON.parse(value);
|
|
1590
1310
|
}
|
|
1591
|
-
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
const ttlOption = Guards20.isDefined(ttl) ? ttl : 300;
|
|
1599
|
-
const result = await this._redisClient.set(key, stringValue, "EX", ttlOption, "NX");
|
|
1600
|
-
return result === "OK";
|
|
1601
|
-
}
|
|
1602
|
-
async remove(key) {
|
|
1603
|
-
await this._redisClient.del(key);
|
|
1604
|
-
}
|
|
1605
|
-
async has(key) {
|
|
1606
|
-
const exists = await this._redisClient.exists(key);
|
|
1607
|
-
return exists === 1;
|
|
1608
|
-
}
|
|
1609
|
-
async clear() {
|
|
1610
|
-
await this._redisClient.flushdb();
|
|
1611
|
-
}
|
|
1612
|
-
};
|
|
1613
|
-
}
|
|
1614
|
-
});
|
|
1615
|
-
|
|
1616
|
-
// src/infrastructure/factories/redis-cache.factory.ts
|
|
1617
|
-
var redis_cache_factory_exports = {};
|
|
1618
|
-
__export(redis_cache_factory_exports, {
|
|
1619
|
-
RedisCacheFactory: () => RedisCacheFactory
|
|
1620
|
-
});
|
|
1621
|
-
import { Guards as Guards21 } from "@xeno-js/shared";
|
|
1622
|
-
import { Redis } from "ioredis";
|
|
1623
|
-
var RedisCacheFactory;
|
|
1624
|
-
var init_redis_cache_factory = __esm({
|
|
1625
|
-
"src/infrastructure/factories/redis-cache.factory.ts"() {
|
|
1626
|
-
"use strict";
|
|
1627
|
-
init_redis_cache();
|
|
1628
|
-
RedisCacheFactory = class {
|
|
1629
|
-
create(config) {
|
|
1630
|
-
const host = config?.host ?? "localhost";
|
|
1631
|
-
const port = config?.port ?? 6379;
|
|
1632
|
-
const password = config?.password;
|
|
1633
|
-
const username = config?.username;
|
|
1634
|
-
const useTls = config?.tls ?? false;
|
|
1635
|
-
const maxRetries = config?.maxRetriesPerRequest ?? 3;
|
|
1636
|
-
const redisOptions = {
|
|
1637
|
-
host,
|
|
1638
|
-
port,
|
|
1639
|
-
maxRetriesPerRequest: maxRetries,
|
|
1640
|
-
// Strategia di riconnessione esponenziale per garantire resilienza
|
|
1641
|
-
retryStrategy(times) {
|
|
1642
|
-
const delay = Math.min(times * 50, 2e3);
|
|
1643
|
-
return delay;
|
|
1644
|
-
}
|
|
1645
|
-
};
|
|
1646
|
-
if (Guards21.isDefined(password)) {
|
|
1647
|
-
redisOptions.password = password;
|
|
1648
|
-
}
|
|
1649
|
-
if (Guards21.isDefined(username)) {
|
|
1650
|
-
redisOptions.username = username;
|
|
1651
|
-
}
|
|
1652
|
-
if (useTls) {
|
|
1653
|
-
redisOptions.tls = {};
|
|
1311
|
+
updateIdentity(identity) {
|
|
1312
|
+
const store = this._storage.getStore();
|
|
1313
|
+
if (Guards15.isDefined(store) && Guards15.isDefined(store.context)) {
|
|
1314
|
+
store.context = Object.freeze({
|
|
1315
|
+
...store.context,
|
|
1316
|
+
identity: Object.freeze(identity)
|
|
1317
|
+
});
|
|
1654
1318
|
}
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1319
|
+
}
|
|
1320
|
+
getContext() {
|
|
1321
|
+
const store = this._storage.getStore();
|
|
1322
|
+
if (!Guards15.isDefined(store)) return void 0;
|
|
1323
|
+
const context = store.context;
|
|
1324
|
+
return Object.freeze(context);
|
|
1325
|
+
}
|
|
1326
|
+
getIdentity() {
|
|
1327
|
+
const store = this._storage.getStore();
|
|
1328
|
+
if (!Guards15.isDefined(store)) return void 0;
|
|
1329
|
+
return Object.freeze(store.context?.identity);
|
|
1330
|
+
}
|
|
1331
|
+
getScope() {
|
|
1332
|
+
const store = this._storage.getStore();
|
|
1333
|
+
if (!Guards15.isDefined(store)) return void 0;
|
|
1334
|
+
return store.scope;
|
|
1335
|
+
}
|
|
1336
|
+
getNetworkContext() {
|
|
1337
|
+
const store = this._storage.getStore();
|
|
1338
|
+
if (!Guards15.isDefined(store)) return void 0;
|
|
1339
|
+
return Object.freeze(store.context?.network);
|
|
1660
1340
|
}
|
|
1661
1341
|
};
|
|
1662
1342
|
}
|
|
1663
1343
|
});
|
|
1664
1344
|
|
|
1665
|
-
// src/infrastructure/
|
|
1666
|
-
var
|
|
1667
|
-
__export(
|
|
1668
|
-
|
|
1345
|
+
// src/infrastructure/factories/request-context.factory.ts
|
|
1346
|
+
var request_context_factory_exports = {};
|
|
1347
|
+
__export(request_context_factory_exports, {
|
|
1348
|
+
NodeRequestContextFactory: () => NodeRequestContextFactory
|
|
1669
1349
|
});
|
|
1670
|
-
|
|
1671
|
-
var
|
|
1672
|
-
|
|
1350
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
1351
|
+
var NodeRequestContextFactory;
|
|
1352
|
+
var init_request_context_factory = __esm({
|
|
1353
|
+
"src/infrastructure/factories/request-context.factory.ts"() {
|
|
1673
1354
|
"use strict";
|
|
1674
|
-
|
|
1355
|
+
init_request_context();
|
|
1356
|
+
NodeRequestContextFactory = class {
|
|
1357
|
+
constructor(_factoryScope) {
|
|
1358
|
+
this._factoryScope = _factoryScope;
|
|
1359
|
+
}
|
|
1360
|
+
_factoryScope;
|
|
1361
|
+
_store = new AsyncLocalStorage2();
|
|
1362
|
+
create() {
|
|
1363
|
+
return new NodeRequestContext(this._store, this._factoryScope);
|
|
1364
|
+
}
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
|
|
1369
|
+
// src/infrastructure/factories/user-context.factory.ts
|
|
1370
|
+
var user_context_factory_exports = {};
|
|
1371
|
+
__export(user_context_factory_exports, {
|
|
1372
|
+
UserContextFactory: () => UserContextFactory
|
|
1373
|
+
});
|
|
1374
|
+
import { Guards as Guards16 } from "@xeno-js/shared";
|
|
1375
|
+
var UserContextFactory;
|
|
1376
|
+
var init_user_context_factory = __esm({
|
|
1377
|
+
"src/infrastructure/factories/user-context.factory.ts"() {
|
|
1378
|
+
"use strict";
|
|
1379
|
+
UserContextFactory = class {
|
|
1675
1380
|
/**
|
|
1676
|
-
* @description
|
|
1677
|
-
* @param
|
|
1678
|
-
* @param opts The cache configuration options.
|
|
1679
|
-
* @returns True if any cache strategies are required, false otherwise.
|
|
1381
|
+
* @description Constructs an instance of UserContextFactory.
|
|
1382
|
+
* @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.
|
|
1680
1383
|
*
|
|
1681
1384
|
* @author Xeno
|
|
1682
1385
|
* @version 1.0.0
|
|
1683
1386
|
* @since 2025-09-30
|
|
1684
1387
|
* @link https://github.com/xeno-js/xeno-js
|
|
1685
1388
|
*/
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
1700
|
-
container.addSingleton(TOKENS4.CACHE, () => new InMemoryCacheExtended2());
|
|
1701
|
-
return;
|
|
1702
|
-
}
|
|
1703
|
-
if (Guards46.isDefined(opts.redis)) {
|
|
1704
|
-
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
1705
|
-
container.addSingleton(TOKENS4.CACHE, () => {
|
|
1706
|
-
const config = opts.redis;
|
|
1707
|
-
return new RedisCacheFactory2().create(config);
|
|
1708
|
-
});
|
|
1389
|
+
constructor(_identityFactory) {
|
|
1390
|
+
this._identityFactory = _identityFactory;
|
|
1391
|
+
}
|
|
1392
|
+
_identityFactory;
|
|
1393
|
+
create() {
|
|
1394
|
+
const output = {
|
|
1395
|
+
userId: void 0,
|
|
1396
|
+
tenantId: void 0
|
|
1397
|
+
};
|
|
1398
|
+
const identity = this._identityFactory.getIdentity();
|
|
1399
|
+
if (Guards16.isDefined(identity)) {
|
|
1400
|
+
output.userId = identity.userId;
|
|
1401
|
+
output.tenantId = identity.tenantId;
|
|
1709
1402
|
}
|
|
1403
|
+
return output;
|
|
1710
1404
|
}
|
|
1711
|
-
}
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
|
|
1409
|
+
// src/infrastructure/modules/context.module.ts
|
|
1410
|
+
var context_module_exports = {};
|
|
1411
|
+
__export(context_module_exports, {
|
|
1412
|
+
ContextModule: () => ContextModule
|
|
1413
|
+
});
|
|
1414
|
+
var ContextModule;
|
|
1415
|
+
var init_context_module = __esm({
|
|
1416
|
+
"src/infrastructure/modules/context.module.ts"() {
|
|
1417
|
+
"use strict";
|
|
1418
|
+
ContextModule = class {
|
|
1419
|
+
async configure(container) {
|
|
1420
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
1421
|
+
const { ServiceScopeFactory: ServiceScopeFactory2 } = await Promise.resolve().then(() => (init_service_scope_factory(), service_scope_factory_exports));
|
|
1422
|
+
const { NodeRequestContextFactory: NodeRequestContextFactory2 } = await Promise.resolve().then(() => (init_request_context_factory(), request_context_factory_exports));
|
|
1423
|
+
const requestContext = new NodeRequestContextFactory2(
|
|
1424
|
+
new ServiceScopeFactory2(container)
|
|
1425
|
+
).create();
|
|
1426
|
+
container.addSingleton(TOKENS5.REQUEST_CONTEXT, () => requestContext);
|
|
1427
|
+
container.addSingleton(TOKENS5.CONTEXT_ACCESSOR, () => requestContext);
|
|
1428
|
+
container.addSingleton(TOKENS5.IDENTITY_ACCESSOR, () => requestContext);
|
|
1429
|
+
container.addSingleton(TOKENS5.SERVICE_SCOPE_ACCESSOR, () => requestContext);
|
|
1430
|
+
container.addSingleton(TOKENS5.NETWORK_CONTEXT_ACCESSOR, () => requestContext);
|
|
1431
|
+
const { UserContextFactory: UserContextFactory2 } = await Promise.resolve().then(() => (init_user_context_factory(), user_context_factory_exports));
|
|
1432
|
+
container.addSingleton("USER_CONTEXT_FACTORY", () => {
|
|
1433
|
+
return new UserContextFactory2(requestContext);
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1712
1437
|
}
|
|
1713
1438
|
});
|
|
1714
1439
|
|
|
1715
1440
|
// src/infrastructure/services/allow_methods/allow-method.service.ts
|
|
1716
|
-
import { Guards as
|
|
1441
|
+
import { Guards as Guards17 } from "@xeno-js/shared";
|
|
1717
1442
|
var AllowMethodRegistry;
|
|
1718
1443
|
var init_allow_method_service = __esm({
|
|
1719
1444
|
"src/infrastructure/services/allow_methods/allow-method.service.ts"() {
|
|
@@ -1733,7 +1458,7 @@ var init_allow_method_service = __esm({
|
|
|
1733
1458
|
check(path, method) {
|
|
1734
1459
|
const cleanPath = this.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1735
1460
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1736
|
-
if (
|
|
1461
|
+
if (Guards17.isDefined(staticMethods)) return staticMethods.includes(method);
|
|
1737
1462
|
for (const route of this._dynamicRoutes) {
|
|
1738
1463
|
if (route.pattern.test(cleanPath)) return route.methods.includes(method);
|
|
1739
1464
|
}
|
|
@@ -1742,11 +1467,11 @@ var init_allow_method_service = __esm({
|
|
|
1742
1467
|
getMethods(path) {
|
|
1743
1468
|
const cleanPath = this.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1744
1469
|
const methods = this.findMethods(cleanPath);
|
|
1745
|
-
return
|
|
1470
|
+
return Guards17.isDefined(methods) ? methods.join(", ").toUpperCase() : "";
|
|
1746
1471
|
}
|
|
1747
1472
|
findMethods(cleanPath) {
|
|
1748
1473
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1749
|
-
if (
|
|
1474
|
+
if (Guards17.isDefined(staticMethods)) return staticMethods;
|
|
1750
1475
|
for (const route of this._dynamicRoutes) if (route.pattern.test(cleanPath)) return route.methods;
|
|
1751
1476
|
return void 0;
|
|
1752
1477
|
}
|
|
@@ -1781,7 +1506,7 @@ var init_allow_methods = __esm({
|
|
|
1781
1506
|
});
|
|
1782
1507
|
|
|
1783
1508
|
// src/infrastructure/services/allow_origins/allow-origin.http.ts
|
|
1784
|
-
import { Guards as
|
|
1509
|
+
import { Guards as Guards18 } from "@xeno-js/shared";
|
|
1785
1510
|
var AllowOrigin;
|
|
1786
1511
|
var init_allow_origin_http = __esm({
|
|
1787
1512
|
"src/infrastructure/services/allow_origins/allow-origin.http.ts"() {
|
|
@@ -1792,7 +1517,7 @@ var init_allow_origin_http = __esm({
|
|
|
1792
1517
|
}
|
|
1793
1518
|
_list;
|
|
1794
1519
|
isAllowed(origin) {
|
|
1795
|
-
if (
|
|
1520
|
+
if (Guards18.isNullOrEmpty(origin)) return true;
|
|
1796
1521
|
const cleanOrigin = origin.trim().toLowerCase();
|
|
1797
1522
|
for (const pattern of this._list) {
|
|
1798
1523
|
const cleanPattern = pattern.trim().toLowerCase();
|
|
@@ -1802,7 +1527,7 @@ var init_allow_origin_http = __esm({
|
|
|
1802
1527
|
const domainSuffix = cleanPattern.substring(1);
|
|
1803
1528
|
if (cleanOrigin.endsWith(domainSuffix)) {
|
|
1804
1529
|
const prefix = cleanOrigin.slice(0, cleanOrigin.length - domainSuffix.length);
|
|
1805
|
-
if (!
|
|
1530
|
+
if (!Guards18.isNullOrEmpty(prefix) && !prefix.includes(".")) return true;
|
|
1806
1531
|
}
|
|
1807
1532
|
}
|
|
1808
1533
|
}
|
|
@@ -1848,6 +1573,73 @@ var init_concurrency = __esm({
|
|
|
1848
1573
|
}
|
|
1849
1574
|
});
|
|
1850
1575
|
|
|
1576
|
+
// src/infrastructure/services/cookies/cookies.service.ts
|
|
1577
|
+
import { Guards as Guards19 } from "@xeno-js/shared";
|
|
1578
|
+
var CookieHandler;
|
|
1579
|
+
var init_cookies_service = __esm({
|
|
1580
|
+
"src/infrastructure/services/cookies/cookies.service.ts"() {
|
|
1581
|
+
"use strict";
|
|
1582
|
+
CookieHandler = class {
|
|
1583
|
+
constructor(contextAccessor, _config, _cookieOpts) {
|
|
1584
|
+
this.contextAccessor = contextAccessor;
|
|
1585
|
+
this._config = _config;
|
|
1586
|
+
this._cookieOpts = _cookieOpts;
|
|
1587
|
+
}
|
|
1588
|
+
contextAccessor;
|
|
1589
|
+
_config;
|
|
1590
|
+
_cookieOpts;
|
|
1591
|
+
getAll() {
|
|
1592
|
+
const network = this.contextAccessor.getNetworkContext();
|
|
1593
|
+
const req = network?.transport?.req;
|
|
1594
|
+
if (!Guards19.isDefined(req) || Guards19.isNullOrEmpty(req.headers.get("cookie"))) return [];
|
|
1595
|
+
return req.headers.get("cookie")?.split(";").map((cookie) => {
|
|
1596
|
+
const [name, ...rest] = cookie.split("=");
|
|
1597
|
+
return { name: name.trim(), value: rest.join("=") };
|
|
1598
|
+
}) ?? [];
|
|
1599
|
+
}
|
|
1600
|
+
setAll(cookies) {
|
|
1601
|
+
const network = this.contextAccessor.getNetworkContext();
|
|
1602
|
+
const res = network?.transport?.res;
|
|
1603
|
+
if (!Guards19.isDefined(res)) return;
|
|
1604
|
+
const serializedCookies = cookies.map((c) => this.serialize(c));
|
|
1605
|
+
const existingSetCookie = res.headers.getSetCookie();
|
|
1606
|
+
res.headers.delete("Set-Cookie");
|
|
1607
|
+
for (const cookie of [...existingSetCookie, ...serializedCookies]) {
|
|
1608
|
+
res.headers.append("Set-Cookie", cookie);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
serialize(cookie) {
|
|
1612
|
+
const safeName = encodeURIComponent(cookie.name);
|
|
1613
|
+
const safeValue = encodeURIComponent(cookie.value);
|
|
1614
|
+
let str = `${safeName}=${safeValue}`;
|
|
1615
|
+
const isProd = this._config.get("NODE_ENV") === "production";
|
|
1616
|
+
const defaultOptions = {
|
|
1617
|
+
path: this._cookieOpts.path,
|
|
1618
|
+
httpOnly: this._cookieOpts.httpOnly,
|
|
1619
|
+
secure: this._cookieOpts.secure ?? isProd,
|
|
1620
|
+
sameSite: this._cookieOpts.sameSite ?? "Lax"
|
|
1621
|
+
};
|
|
1622
|
+
const opts = { ...defaultOptions, ...cookie.options ?? {} };
|
|
1623
|
+
str += `; Path=${opts.path}`;
|
|
1624
|
+
if (Guards19.isDefined(opts.maxAge)) str += `; Max-Age=${opts.maxAge}`;
|
|
1625
|
+
if (Guards19.isDefined(opts.domain)) str += `; Domain=${opts.domain}`;
|
|
1626
|
+
if (Guards19.isDefined(opts.sameSite)) str += `; SameSite=${opts.sameSite}`;
|
|
1627
|
+
if (opts.secure) str += `; Secure`;
|
|
1628
|
+
if (opts.httpOnly) str += `; HttpOnly`;
|
|
1629
|
+
return str;
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
});
|
|
1634
|
+
|
|
1635
|
+
// src/infrastructure/services/cookies/index.ts
|
|
1636
|
+
var init_cookies = __esm({
|
|
1637
|
+
"src/infrastructure/services/cookies/index.ts"() {
|
|
1638
|
+
"use strict";
|
|
1639
|
+
init_cookies_service();
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
|
|
1851
1643
|
// src/infrastructure/services/crypto/crypto.service.ts
|
|
1852
1644
|
var EdgeCryptoService;
|
|
1853
1645
|
var init_crypto_service = __esm({
|
|
@@ -1896,7 +1688,7 @@ var init_crypto = __esm({
|
|
|
1896
1688
|
});
|
|
1897
1689
|
|
|
1898
1690
|
// src/infrastructure/services/csrf/csrf-token.service.ts
|
|
1899
|
-
import { Guards as
|
|
1691
|
+
import { Guards as Guards20 } from "@xeno-js/shared";
|
|
1900
1692
|
var CsrfTokenService;
|
|
1901
1693
|
var init_csrf_token_service = __esm({
|
|
1902
1694
|
"src/infrastructure/services/csrf/csrf-token.service.ts"() {
|
|
@@ -1919,7 +1711,7 @@ var init_csrf_token_service = __esm({
|
|
|
1919
1711
|
if (separatorIndex <= 0) return false;
|
|
1920
1712
|
const nonce = token.slice(0, separatorIndex);
|
|
1921
1713
|
const signature = token.slice(separatorIndex + 1);
|
|
1922
|
-
if (
|
|
1714
|
+
if (Guards20.isNullOrEmpty(nonce) || Guards20.isNullOrEmpty(signature)) return false;
|
|
1923
1715
|
const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1924
1716
|
const encoder = new TextEncoder();
|
|
1925
1717
|
const actualBuffer = encoder.encode(signature);
|
|
@@ -1940,7 +1732,7 @@ var init_csrf = __esm({
|
|
|
1940
1732
|
});
|
|
1941
1733
|
|
|
1942
1734
|
// src/infrastructure/services/extractors/extract-bearer.extractor.ts
|
|
1943
|
-
import { Guards as
|
|
1735
|
+
import { Guards as Guards21 } from "@xeno-js/shared";
|
|
1944
1736
|
var BearerTokenExtractor;
|
|
1945
1737
|
var init_extract_bearer_extractor = __esm({
|
|
1946
1738
|
"src/infrastructure/services/extractors/extract-bearer.extractor.ts"() {
|
|
@@ -1952,14 +1744,14 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1952
1744
|
_cookiePrefix;
|
|
1953
1745
|
extract(headers) {
|
|
1954
1746
|
const authHeader = headers.get("Authorization");
|
|
1955
|
-
if (
|
|
1747
|
+
if (Guards21.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1956
1748
|
return authHeader.substring(7);
|
|
1957
1749
|
}
|
|
1958
1750
|
const cookieHeader = headers.get("cookie");
|
|
1959
|
-
if (
|
|
1751
|
+
if (Guards21.isDefined(cookieHeader)) {
|
|
1960
1752
|
const regex = new RegExp(`${this._cookiePrefix}=([^;]+)`);
|
|
1961
1753
|
const match = regex.exec(cookieHeader);
|
|
1962
|
-
if (!
|
|
1754
|
+
if (!Guards21.isNullOrEmpty(match) && Guards21.isDefined(match[1])) {
|
|
1963
1755
|
return match[1].trim();
|
|
1964
1756
|
}
|
|
1965
1757
|
}
|
|
@@ -1970,7 +1762,7 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1970
1762
|
});
|
|
1971
1763
|
|
|
1972
1764
|
// src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts
|
|
1973
|
-
import { Guards as
|
|
1765
|
+
import { Guards as Guards22, StringHelper } from "@xeno-js/shared";
|
|
1974
1766
|
var SupabaseSsrTokenExtractor;
|
|
1975
1767
|
var init_extract_ssr_bearer_extractor = __esm({
|
|
1976
1768
|
"src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts"() {
|
|
@@ -1978,36 +1770,36 @@ var init_extract_ssr_bearer_extractor = __esm({
|
|
|
1978
1770
|
SupabaseSsrTokenExtractor = class {
|
|
1979
1771
|
extract(headers) {
|
|
1980
1772
|
const authHeader = headers.get("authorization");
|
|
1981
|
-
if (
|
|
1773
|
+
if (Guards22.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1982
1774
|
return authHeader.substring(7);
|
|
1983
1775
|
}
|
|
1984
1776
|
const cookieHeader = headers.get("cookie");
|
|
1985
|
-
if (
|
|
1777
|
+
if (Guards22.isNullOrEmpty(cookieHeader)) return void 0;
|
|
1986
1778
|
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
1987
1779
|
const tokenChunks = {};
|
|
1988
1780
|
let unchunkedToken;
|
|
1989
1781
|
for (const cookie of cookies) {
|
|
1990
1782
|
const [name, ...rest] = cookie.split("=");
|
|
1991
|
-
if (!
|
|
1783
|
+
if (!Guards22.isDefined(name) || Guards22.isNullOrEmpty(rest)) continue;
|
|
1992
1784
|
const value = decodeURIComponent(rest.join("="));
|
|
1993
|
-
if (
|
|
1785
|
+
if (Guards22.isDefined(/^sb-[a-z0-9]+-auth-token$/.exec(name))) {
|
|
1994
1786
|
unchunkedToken = value;
|
|
1995
1787
|
} else {
|
|
1996
1788
|
const match = /^sb-[a-z0-9]+-auth-token\.(\d+)$/.exec(name);
|
|
1997
|
-
if (
|
|
1789
|
+
if (Guards22.isDefined(match)) tokenChunks[parseInt(match[1], 10)] = value;
|
|
1998
1790
|
}
|
|
1999
1791
|
}
|
|
2000
1792
|
let fullTokenString = unchunkedToken;
|
|
2001
|
-
if (!
|
|
1793
|
+
if (!Guards22.isDefined(fullTokenString) && Object.keys(tokenChunks).length > 0) {
|
|
2002
1794
|
const indices = Object.keys(tokenChunks).map(Number).sort((a, b) => a - b);
|
|
2003
1795
|
fullTokenString = indices.map((i) => tokenChunks[i]).join("");
|
|
2004
1796
|
}
|
|
2005
|
-
if (
|
|
1797
|
+
if (Guards22.isNullOrEmpty(fullTokenString)) return void 0;
|
|
2006
1798
|
try {
|
|
2007
|
-
const parsed =
|
|
2008
|
-
if (
|
|
1799
|
+
const parsed = StringHelper.safeParse(fullTokenString);
|
|
1800
|
+
if (Guards22.isDefined(parsed) && Guards22.isObject(parsed) && "access_token" in parsed) {
|
|
2009
1801
|
const accessToken = parsed["access_token"];
|
|
2010
|
-
if (
|
|
1802
|
+
if (Guards22.isString(accessToken)) return accessToken;
|
|
2011
1803
|
}
|
|
2012
1804
|
} catch {
|
|
2013
1805
|
return void 0;
|
|
@@ -2018,14 +1810,14 @@ var init_extract_ssr_bearer_extractor = __esm({
|
|
|
2018
1810
|
});
|
|
2019
1811
|
|
|
2020
1812
|
// src/infrastructure/services/extractors/http-cookie.extractor.ts
|
|
2021
|
-
import { Guards as
|
|
1813
|
+
import { Guards as Guards23 } from "@xeno-js/shared";
|
|
2022
1814
|
var HttpCookieExtractor;
|
|
2023
1815
|
var init_http_cookie_extractor = __esm({
|
|
2024
1816
|
"src/infrastructure/services/extractors/http-cookie.extractor.ts"() {
|
|
2025
1817
|
"use strict";
|
|
2026
1818
|
HttpCookieExtractor = class {
|
|
2027
1819
|
extract(cookie) {
|
|
2028
|
-
if (!
|
|
1820
|
+
if (!Guards23.isDefined(cookie.header)) return void 0;
|
|
2029
1821
|
for (const rawCookie of cookie.header.split(";")) {
|
|
2030
1822
|
const separatorIndex = rawCookie.indexOf("=");
|
|
2031
1823
|
if (separatorIndex <= 0) continue;
|
|
@@ -2045,7 +1837,7 @@ var init_http_cookie_extractor = __esm({
|
|
|
2045
1837
|
});
|
|
2046
1838
|
|
|
2047
1839
|
// src/infrastructure/services/extractors/http-header.extractor.ts
|
|
2048
|
-
import { Guards as
|
|
1840
|
+
import { Guards as Guards24, GuidHelper as GuidHelper4, HttpHelper, MathHelper } from "@xeno-js/shared";
|
|
2049
1841
|
var HttpHeaderExtractor;
|
|
2050
1842
|
var init_http_header_extractor = __esm({
|
|
2051
1843
|
"src/infrastructure/services/extractors/http-header.extractor.ts"() {
|
|
@@ -2113,10 +1905,10 @@ var init_http_header_extractor = __esm({
|
|
|
2113
1905
|
referer: cleanReferer,
|
|
2114
1906
|
sequence: {
|
|
2115
1907
|
sequenceId,
|
|
2116
|
-
position:
|
|
2117
|
-
size:
|
|
1908
|
+
position: Guards24.isDefined(position) ? MathHelper.toNumber(position) : void 0,
|
|
1909
|
+
size: Guards24.isDefined(size) ? MathHelper.toNumber(size) : void 0
|
|
2118
1910
|
},
|
|
2119
|
-
expiration:
|
|
1911
|
+
expiration: Guards24.isDefined(expiration) ? MathHelper.toNumber(expiration) : void 0
|
|
2120
1912
|
};
|
|
2121
1913
|
return metadata;
|
|
2122
1914
|
}
|
|
@@ -2163,7 +1955,7 @@ var init_resiliences = __esm({
|
|
|
2163
1955
|
});
|
|
2164
1956
|
|
|
2165
1957
|
// src/infrastructure/services/resolver/utils/socket.utils.ts
|
|
2166
|
-
import { Guards as
|
|
1958
|
+
import { Guards as Guards25 } from "@xeno-js/shared";
|
|
2167
1959
|
var SocketIpExtractor;
|
|
2168
1960
|
var init_socket_utils = __esm({
|
|
2169
1961
|
"src/infrastructure/services/resolver/utils/socket.utils.ts"() {
|
|
@@ -2175,7 +1967,7 @@ var init_socket_utils = __esm({
|
|
|
2175
1967
|
* @returns The IP address of the remote socket, or undefined if not available.
|
|
2176
1968
|
*/
|
|
2177
1969
|
extract(req) {
|
|
2178
|
-
if (
|
|
1970
|
+
if (Guards25.isDefined(req) && Guards25.isObject(req)) {
|
|
2179
1971
|
const candidate = req;
|
|
2180
1972
|
return candidate.socket?.remoteAddress ?? candidate.connection?.remoteAddress;
|
|
2181
1973
|
}
|
|
@@ -2194,7 +1986,7 @@ var init_utils = __esm({
|
|
|
2194
1986
|
});
|
|
2195
1987
|
|
|
2196
1988
|
// src/infrastructure/services/resolver/client-ip.resolver.ts
|
|
2197
|
-
import { Guards as
|
|
1989
|
+
import { Guards as Guards26 } from "@xeno-js/shared";
|
|
2198
1990
|
var ClientIpResolver;
|
|
2199
1991
|
var init_client_ip_resolver = __esm({
|
|
2200
1992
|
"src/infrastructure/services/resolver/client-ip.resolver.ts"() {
|
|
@@ -2207,11 +1999,11 @@ var init_client_ip_resolver = __esm({
|
|
|
2207
1999
|
_trustedProxies;
|
|
2208
2000
|
resolve(req, clientIp) {
|
|
2209
2001
|
const socketIp = SocketIpExtractor.extract(req);
|
|
2210
|
-
if (!
|
|
2211
|
-
return !
|
|
2002
|
+
if (!Guards26.isDefined(socketIp))
|
|
2003
|
+
return !Guards26.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
2212
2004
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
2213
2005
|
if (!isTrustedProxy) return socketIp;
|
|
2214
|
-
if (
|
|
2006
|
+
if (Guards26.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
2215
2007
|
return socketIp;
|
|
2216
2008
|
}
|
|
2217
2009
|
};
|
|
@@ -2233,6 +2025,7 @@ __export(services_exports, {
|
|
|
2233
2025
|
AllowOrigin: () => AllowOrigin,
|
|
2234
2026
|
BearerTokenExtractor: () => BearerTokenExtractor,
|
|
2235
2027
|
ClientIpResolver: () => ClientIpResolver,
|
|
2028
|
+
CookieHandler: () => CookieHandler,
|
|
2236
2029
|
CsrfTokenService: () => CsrfTokenService,
|
|
2237
2030
|
EdgeCryptoService: () => EdgeCryptoService,
|
|
2238
2031
|
HttpCookieExtractor: () => HttpCookieExtractor,
|
|
@@ -2247,6 +2040,7 @@ var init_services = __esm({
|
|
|
2247
2040
|
init_allow_methods();
|
|
2248
2041
|
init_allow_origins();
|
|
2249
2042
|
init_concurrency();
|
|
2043
|
+
init_cookies();
|
|
2250
2044
|
init_crypto();
|
|
2251
2045
|
init_csrf();
|
|
2252
2046
|
init_extractors();
|
|
@@ -2314,7 +2108,7 @@ var init_axios_factory = __esm({
|
|
|
2314
2108
|
});
|
|
2315
2109
|
|
|
2316
2110
|
// src/infrastructure/factories/cockatiel-resilience.factory.ts
|
|
2317
|
-
import { AppError as AppError13, Guards as
|
|
2111
|
+
import { AppError as AppError13, Guards as Guards27, RESILIENCE_DEFAULTS } from "@xeno-js/shared";
|
|
2318
2112
|
import {
|
|
2319
2113
|
bulkhead,
|
|
2320
2114
|
circuitBreaker,
|
|
@@ -2391,13 +2185,13 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2391
2185
|
return new ServiceResilience(wrap(bulkheadPolicy, circuitBreakerPolicy, retryPolicy));
|
|
2392
2186
|
}
|
|
2393
2187
|
isTransientError(error) {
|
|
2394
|
-
if (!
|
|
2188
|
+
if (!Guards27.isDefined(error) || !Guards27.isObject(error)) return false;
|
|
2395
2189
|
let status;
|
|
2396
2190
|
let isNetworkError = false;
|
|
2397
2191
|
if (error instanceof AppError13) {
|
|
2398
2192
|
status = error.status;
|
|
2399
2193
|
const cause = error.cause;
|
|
2400
|
-
if (
|
|
2194
|
+
if (Guards27.isDefined(cause) && Guards27.isString(cause.code)) {
|
|
2401
2195
|
isNetworkError = [
|
|
2402
2196
|
"ECONNABORTED",
|
|
2403
2197
|
"ECONNRESET",
|
|
@@ -2409,7 +2203,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2409
2203
|
} else {
|
|
2410
2204
|
const err = error;
|
|
2411
2205
|
status = err.status;
|
|
2412
|
-
if (
|
|
2206
|
+
if (Guards27.isString(err.code)) {
|
|
2413
2207
|
isNetworkError = [
|
|
2414
2208
|
"ECONNABORTED",
|
|
2415
2209
|
"ECONNRESET",
|
|
@@ -2420,7 +2214,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2420
2214
|
}
|
|
2421
2215
|
}
|
|
2422
2216
|
if (isNetworkError) return true;
|
|
2423
|
-
if (
|
|
2217
|
+
if (Guards27.isDefined(status)) return status === 408 || status >= 500 && status < 600;
|
|
2424
2218
|
return false;
|
|
2425
2219
|
}
|
|
2426
2220
|
isTransientAndIdempotent(error) {
|
|
@@ -2428,157 +2222,330 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2428
2222
|
let method;
|
|
2429
2223
|
if (error instanceof AppError13) {
|
|
2430
2224
|
const cause = error.cause;
|
|
2431
|
-
if (
|
|
2225
|
+
if (Guards27.isDefined(cause) && Guards27.isDefined(cause.config) && Guards27.isString(cause.config.method)) {
|
|
2432
2226
|
method = cause.config.method.toUpperCase();
|
|
2433
2227
|
}
|
|
2434
2228
|
} else {
|
|
2435
2229
|
const err = error;
|
|
2436
|
-
if (
|
|
2230
|
+
if (Guards27.isDefined(err.config) && Guards27.isString(err.config.method)) {
|
|
2437
2231
|
method = err.config.method.toUpperCase();
|
|
2438
2232
|
}
|
|
2439
2233
|
}
|
|
2440
|
-
if (
|
|
2234
|
+
if (Guards27.isNullOrEmpty(method)) return false;
|
|
2441
2235
|
const idempotentMethods = ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
|
|
2442
2236
|
return idempotentMethods.includes(method);
|
|
2443
2237
|
}
|
|
2444
2238
|
checkConfigValue(value, defaultValue, message) {
|
|
2445
|
-
if (
|
|
2446
|
-
|
|
2239
|
+
if (Guards27.isDefined(value)) {
|
|
2240
|
+
Guards27.throwIfNegative(value, message);
|
|
2447
2241
|
return value;
|
|
2448
2242
|
}
|
|
2449
|
-
return defaultValue;
|
|
2450
|
-
}
|
|
2451
|
-
};
|
|
2452
|
-
}
|
|
2453
|
-
});
|
|
2454
|
-
|
|
2455
|
-
// src/infrastructure/factories/db-client.factory.ts
|
|
2456
|
-
var db_client_factory_exports = {};
|
|
2457
|
-
__export(db_client_factory_exports, {
|
|
2458
|
-
DbClientFactory: () => DbClientFactory
|
|
2459
|
-
});
|
|
2460
|
-
import { drizzle } from "drizzle-orm/node-postgres";
|
|
2461
|
-
import { Pool } from "pg";
|
|
2462
|
-
var DbClientFactory;
|
|
2463
|
-
var init_db_client_factory = __esm({
|
|
2464
|
-
"src/infrastructure/factories/db-client.factory.ts"() {
|
|
2465
|
-
"use strict";
|
|
2466
|
-
DbClientFactory = class {
|
|
2467
|
-
create(opts) {
|
|
2468
|
-
const pool = new Pool({
|
|
2469
|
-
connectionString: opts.connectionString
|
|
2470
|
-
});
|
|
2471
|
-
return drizzle({ client: pool });
|
|
2243
|
+
return defaultValue;
|
|
2244
|
+
}
|
|
2245
|
+
};
|
|
2246
|
+
}
|
|
2247
|
+
});
|
|
2248
|
+
|
|
2249
|
+
// src/infrastructure/factories/db-client.factory.ts
|
|
2250
|
+
var db_client_factory_exports = {};
|
|
2251
|
+
__export(db_client_factory_exports, {
|
|
2252
|
+
DbClientFactory: () => DbClientFactory
|
|
2253
|
+
});
|
|
2254
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
2255
|
+
import { Pool } from "pg";
|
|
2256
|
+
var DbClientFactory;
|
|
2257
|
+
var init_db_client_factory = __esm({
|
|
2258
|
+
"src/infrastructure/factories/db-client.factory.ts"() {
|
|
2259
|
+
"use strict";
|
|
2260
|
+
DbClientFactory = class {
|
|
2261
|
+
create(opts) {
|
|
2262
|
+
const pool = new Pool({
|
|
2263
|
+
connectionString: opts.connectionString
|
|
2264
|
+
});
|
|
2265
|
+
return drizzle({ client: pool });
|
|
2266
|
+
}
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
});
|
|
2270
|
+
|
|
2271
|
+
// src/infrastructure/loggers/pino.logger.ts
|
|
2272
|
+
import { Guards as Guards28, LOG_LEVEL } from "@xeno-js/shared";
|
|
2273
|
+
var PinoLogger;
|
|
2274
|
+
var init_pino_logger = __esm({
|
|
2275
|
+
"src/infrastructure/loggers/pino.logger.ts"() {
|
|
2276
|
+
"use strict";
|
|
2277
|
+
PinoLogger = class {
|
|
2278
|
+
/**
|
|
2279
|
+
* 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.
|
|
2280
|
+
* @param _logger The Pino logger instance used for logging messages.
|
|
2281
|
+
* @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.
|
|
2282
|
+
|
|
2283
|
+
*
|
|
2284
|
+
* @author Xeno
|
|
2285
|
+
* @version 1.0.0
|
|
2286
|
+
* @since 2025-09-30
|
|
2287
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2288
|
+
*/
|
|
2289
|
+
constructor(_logger, _minLevel = LOG_LEVEL.DEBUG) {
|
|
2290
|
+
this._logger = _logger;
|
|
2291
|
+
this._minLevel = _minLevel;
|
|
2292
|
+
}
|
|
2293
|
+
_logger;
|
|
2294
|
+
_minLevel;
|
|
2295
|
+
track(level, message, context, error = void 0) {
|
|
2296
|
+
if (level < this._minLevel) return;
|
|
2297
|
+
const payload = Guards28.isDefined(error) ? { ...context, error } : context;
|
|
2298
|
+
switch (level) {
|
|
2299
|
+
case LOG_LEVEL.ERROR:
|
|
2300
|
+
this._logger.error(payload ?? {}, message);
|
|
2301
|
+
break;
|
|
2302
|
+
case LOG_LEVEL.WARN:
|
|
2303
|
+
this._logger.warn(payload ?? {}, message);
|
|
2304
|
+
break;
|
|
2305
|
+
case LOG_LEVEL.DEBUG:
|
|
2306
|
+
this._logger.debug(payload ?? {}, message);
|
|
2307
|
+
break;
|
|
2308
|
+
default:
|
|
2309
|
+
this._logger.info(payload ?? {}, message);
|
|
2310
|
+
break;
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
});
|
|
2316
|
+
|
|
2317
|
+
// src/infrastructure/factories/pino-logger.factory.ts
|
|
2318
|
+
var pino_logger_factory_exports = {};
|
|
2319
|
+
__export(pino_logger_factory_exports, {
|
|
2320
|
+
PinoLoggerFactory: () => PinoLoggerFactory
|
|
2321
|
+
});
|
|
2322
|
+
import { LOG_LEVEL as LOG_LEVEL2 } from "@xeno-js/shared";
|
|
2323
|
+
import pino from "pino";
|
|
2324
|
+
var PinoLoggerFactory;
|
|
2325
|
+
var init_pino_logger_factory = __esm({
|
|
2326
|
+
"src/infrastructure/factories/pino-logger.factory.ts"() {
|
|
2327
|
+
"use strict";
|
|
2328
|
+
init_pino_logger();
|
|
2329
|
+
PinoLoggerFactory = class {
|
|
2330
|
+
create(config) {
|
|
2331
|
+
const level = config.level ?? LOG_LEVEL2.DEBUG;
|
|
2332
|
+
const env = config.pino.config?.env ?? process.env.NODE_ENV ?? "development";
|
|
2333
|
+
const destinationType = config.pino.config?.destination ?? "stdout";
|
|
2334
|
+
const filePath = config.pino.config?.filePath ?? "logs/app.log";
|
|
2335
|
+
const prettyPrint = config.pino.config?.prettyPrint ?? env === "development";
|
|
2336
|
+
const options = {
|
|
2337
|
+
level: "trace",
|
|
2338
|
+
serializers: {
|
|
2339
|
+
err: pino.stdSerializers.err
|
|
2340
|
+
},
|
|
2341
|
+
timestamp: pino.stdTimeFunctions.isoTime,
|
|
2342
|
+
redact: {
|
|
2343
|
+
paths: ["password", "token", "secret", "authorization", "headers.authorization"],
|
|
2344
|
+
censor: "***"
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
if (prettyPrint) {
|
|
2348
|
+
return new PinoLogger(
|
|
2349
|
+
pino({
|
|
2350
|
+
...options,
|
|
2351
|
+
transport: {
|
|
2352
|
+
target: "pino-pretty",
|
|
2353
|
+
options: {
|
|
2354
|
+
colorize: true,
|
|
2355
|
+
ignore: "pid,hostname",
|
|
2356
|
+
translateTime: "SYS:standard"
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
}),
|
|
2360
|
+
level
|
|
2361
|
+
);
|
|
2362
|
+
}
|
|
2363
|
+
if (destinationType === "file") {
|
|
2364
|
+
const destination = pino.destination({ dest: filePath, sync: false });
|
|
2365
|
+
return new PinoLogger(pino(options, destination), level);
|
|
2366
|
+
} else {
|
|
2367
|
+
const stream = pino.destination({ dest: 1, sync: false });
|
|
2368
|
+
return new PinoLogger(pino(options, stream), level);
|
|
2369
|
+
}
|
|
2472
2370
|
}
|
|
2473
2371
|
};
|
|
2474
2372
|
}
|
|
2475
2373
|
});
|
|
2476
2374
|
|
|
2477
|
-
// src/infrastructure/
|
|
2478
|
-
import { Guards as
|
|
2479
|
-
var
|
|
2480
|
-
var
|
|
2481
|
-
"src/infrastructure/
|
|
2375
|
+
// src/infrastructure/cache/redis.cache.ts
|
|
2376
|
+
import { Guards as Guards29, StringHelper as StringHelper2 } from "@xeno-js/shared";
|
|
2377
|
+
var RedisCache;
|
|
2378
|
+
var init_redis_cache = __esm({
|
|
2379
|
+
"src/infrastructure/cache/redis.cache.ts"() {
|
|
2482
2380
|
"use strict";
|
|
2483
|
-
|
|
2381
|
+
RedisCache = class {
|
|
2484
2382
|
/**
|
|
2485
|
-
* @description Constructs a new instance of the
|
|
2486
|
-
* @param
|
|
2487
|
-
|
|
2488
|
-
*
|
|
2383
|
+
* @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.
|
|
2384
|
+
* @param _redisClient An instance of the Redis client from the ioredis library, used to perform caching operations in the Redis database.
|
|
2385
|
+
|
|
2386
|
+
*
|
|
2489
2387
|
* @author Xeno
|
|
2490
2388
|
* @version 1.0.0
|
|
2491
2389
|
* @since 2025-09-30
|
|
2492
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
2390
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2493
2391
|
*/
|
|
2494
|
-
constructor(
|
|
2495
|
-
this.
|
|
2496
|
-
this._factoryScope = _factoryScope;
|
|
2392
|
+
constructor(_redisClient) {
|
|
2393
|
+
this._redisClient = _redisClient;
|
|
2497
2394
|
}
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
await scope.dispose();
|
|
2506
|
-
}
|
|
2395
|
+
_redisClient;
|
|
2396
|
+
async increment(key, ttlSeconds) {
|
|
2397
|
+
const multi = this._redisClient.multi();
|
|
2398
|
+
multi.incr(key);
|
|
2399
|
+
multi.expire(key, ttlSeconds ?? 60);
|
|
2400
|
+
const results = await multi.exec();
|
|
2401
|
+
return results?.[0]?.[1] ?? 1;
|
|
2507
2402
|
}
|
|
2508
|
-
|
|
2509
|
-
const
|
|
2510
|
-
if (
|
|
2511
|
-
|
|
2512
|
-
...store.context,
|
|
2513
|
-
identity: Object.freeze(identity)
|
|
2514
|
-
});
|
|
2403
|
+
async get(key) {
|
|
2404
|
+
const value = await this._redisClient.get(key);
|
|
2405
|
+
if (!Guards29.isDefined(value)) {
|
|
2406
|
+
return void 0;
|
|
2515
2407
|
}
|
|
2408
|
+
return JSON.parse(value);
|
|
2516
2409
|
}
|
|
2517
|
-
|
|
2518
|
-
const
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
return Object.freeze(context);
|
|
2410
|
+
async set(key, value, ttl) {
|
|
2411
|
+
const stringValue = StringHelper2.safeStringify(value);
|
|
2412
|
+
const ttlOption = Guards29.isDefined(ttl) ? ttl : 86400;
|
|
2413
|
+
await this._redisClient.set(key, stringValue, "EX", ttlOption);
|
|
2522
2414
|
}
|
|
2523
|
-
|
|
2524
|
-
const
|
|
2525
|
-
|
|
2526
|
-
|
|
2415
|
+
async setIfAbsent(key, value, ttl) {
|
|
2416
|
+
const stringValue = StringHelper2.safeStringify(value);
|
|
2417
|
+
const ttlOption = Guards29.isDefined(ttl) ? ttl : 300;
|
|
2418
|
+
const result = await this._redisClient.set(key, stringValue, "EX", ttlOption, "NX");
|
|
2419
|
+
return result === "OK";
|
|
2527
2420
|
}
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
if (!Guards32.isDefined(store)) return void 0;
|
|
2531
|
-
return store.scope;
|
|
2421
|
+
async remove(key) {
|
|
2422
|
+
await this._redisClient.del(key);
|
|
2532
2423
|
}
|
|
2533
|
-
|
|
2534
|
-
const
|
|
2535
|
-
|
|
2536
|
-
|
|
2424
|
+
async has(key) {
|
|
2425
|
+
const exists = await this._redisClient.exists(key);
|
|
2426
|
+
return exists === 1;
|
|
2427
|
+
}
|
|
2428
|
+
async clear() {
|
|
2429
|
+
await this._redisClient.flushdb();
|
|
2537
2430
|
}
|
|
2538
2431
|
};
|
|
2539
2432
|
}
|
|
2540
2433
|
});
|
|
2541
2434
|
|
|
2542
|
-
// src/infrastructure/factories/
|
|
2543
|
-
var
|
|
2544
|
-
__export(
|
|
2545
|
-
|
|
2435
|
+
// src/infrastructure/factories/redis-cache.factory.ts
|
|
2436
|
+
var redis_cache_factory_exports = {};
|
|
2437
|
+
__export(redis_cache_factory_exports, {
|
|
2438
|
+
RedisCacheFactory: () => RedisCacheFactory
|
|
2546
2439
|
});
|
|
2547
|
-
import {
|
|
2548
|
-
|
|
2549
|
-
var
|
|
2550
|
-
|
|
2440
|
+
import { Guards as Guards30 } from "@xeno-js/shared";
|
|
2441
|
+
import { Redis } from "ioredis";
|
|
2442
|
+
var RedisCacheFactory;
|
|
2443
|
+
var init_redis_cache_factory = __esm({
|
|
2444
|
+
"src/infrastructure/factories/redis-cache.factory.ts"() {
|
|
2551
2445
|
"use strict";
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2446
|
+
init_redis_cache();
|
|
2447
|
+
RedisCacheFactory = class {
|
|
2448
|
+
create(config) {
|
|
2449
|
+
const host = config?.host ?? "localhost";
|
|
2450
|
+
const port = config?.port ?? 6379;
|
|
2451
|
+
const password = config?.password;
|
|
2452
|
+
const username = config?.username;
|
|
2453
|
+
const useTls = config?.tls ?? false;
|
|
2454
|
+
const maxRetries = config?.maxRetriesPerRequest ?? 3;
|
|
2455
|
+
const redisOptions = {
|
|
2456
|
+
host,
|
|
2457
|
+
port,
|
|
2458
|
+
maxRetriesPerRequest: maxRetries,
|
|
2459
|
+
// Strategia di riconnessione esponenziale per garantire resilienza
|
|
2460
|
+
retryStrategy(times) {
|
|
2461
|
+
const delay = Math.min(times * 50, 2e3);
|
|
2462
|
+
return delay;
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
if (Guards30.isDefined(password)) {
|
|
2466
|
+
redisOptions.password = password;
|
|
2467
|
+
}
|
|
2468
|
+
if (Guards30.isDefined(username)) {
|
|
2469
|
+
redisOptions.username = username;
|
|
2470
|
+
}
|
|
2471
|
+
if (useTls) {
|
|
2472
|
+
redisOptions.tls = {};
|
|
2473
|
+
}
|
|
2474
|
+
const nativeRedisInstance = new Redis(redisOptions);
|
|
2475
|
+
nativeRedisInstance.on("error", (err) => {
|
|
2476
|
+
console.error("\u274C [Redis Error]:", err.message);
|
|
2477
|
+
});
|
|
2478
|
+
return new RedisCache(nativeRedisInstance);
|
|
2556
2479
|
}
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2480
|
+
};
|
|
2481
|
+
}
|
|
2482
|
+
});
|
|
2483
|
+
|
|
2484
|
+
// src/infrastructure/loggers/sentry.logger.ts
|
|
2485
|
+
import { Guards as Guards31, LOG_LEVEL as LOG_LEVEL3 } from "@xeno-js/shared";
|
|
2486
|
+
var SentryLogger;
|
|
2487
|
+
var init_sentry_logger = __esm({
|
|
2488
|
+
"src/infrastructure/loggers/sentry.logger.ts"() {
|
|
2489
|
+
"use strict";
|
|
2490
|
+
SentryLogger = class {
|
|
2491
|
+
constructor(_client, _minLevel) {
|
|
2492
|
+
this._client = _client;
|
|
2493
|
+
this._minLevel = _minLevel;
|
|
2494
|
+
}
|
|
2495
|
+
_client;
|
|
2496
|
+
_minLevel;
|
|
2497
|
+
track(level, message, context = void 0, error = void 0) {
|
|
2498
|
+
if (level < this._minLevel) return;
|
|
2499
|
+
if (level === LOG_LEVEL3.ERROR || level === LOG_LEVEL3.WARN) {
|
|
2500
|
+
this._client.withScope((scope) => {
|
|
2501
|
+
if (Guards31.isDefined(context)) scope.setExtras(context);
|
|
2502
|
+
if (Guards31.isDefined(error)) {
|
|
2503
|
+
this._client.captureException(error);
|
|
2504
|
+
} else {
|
|
2505
|
+
this._client.captureMessage(message, "warning");
|
|
2506
|
+
}
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2561
2509
|
}
|
|
2562
2510
|
};
|
|
2563
2511
|
}
|
|
2564
2512
|
});
|
|
2565
2513
|
|
|
2566
|
-
// src/infrastructure/factories/
|
|
2567
|
-
var
|
|
2568
|
-
__export(
|
|
2569
|
-
|
|
2514
|
+
// src/infrastructure/factories/sentry-logger.factory.ts
|
|
2515
|
+
var sentry_logger_factory_exports = {};
|
|
2516
|
+
__export(sentry_logger_factory_exports, {
|
|
2517
|
+
SentryLoggerFactory: () => SentryLoggerFactory
|
|
2570
2518
|
});
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2519
|
+
import * as Sentry from "@sentry/node";
|
|
2520
|
+
import { Guards as Guards32, LOG_LEVEL as LOG_LEVEL4 } from "@xeno-js/shared";
|
|
2521
|
+
var SentryLoggerFactory;
|
|
2522
|
+
var init_sentry_logger_factory = __esm({
|
|
2523
|
+
"src/infrastructure/factories/sentry-logger.factory.ts"() {
|
|
2574
2524
|
"use strict";
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2525
|
+
init_sentry_logger();
|
|
2526
|
+
SentryLoggerFactory = class {
|
|
2527
|
+
create(config) {
|
|
2528
|
+
const level = config.level ?? LOG_LEVEL4.WARN;
|
|
2529
|
+
const sentryConfig = config.sentry?.config;
|
|
2530
|
+
const env = sentryConfig?.environment ?? process.env.NODE_ENV ?? "development";
|
|
2531
|
+
if (!Guards32.isDefined(sentryConfig))
|
|
2532
|
+
throw new Error("Sentry configuration is required when Sentry logging is enabled.");
|
|
2533
|
+
if (!Guards32.isDefined(sentryConfig.dsn))
|
|
2534
|
+
throw new Error("Sentry DSN is required when Sentry logging is enabled.");
|
|
2535
|
+
Sentry.init({
|
|
2536
|
+
dsn: sentryConfig.dsn,
|
|
2537
|
+
environment: env,
|
|
2538
|
+
tracesSampleRate: env === "production" ? 0.1 : 1,
|
|
2539
|
+
integrations: [Sentry.httpIntegration()],
|
|
2540
|
+
beforeSend(event, hint) {
|
|
2541
|
+
const error = hint.originalException;
|
|
2542
|
+
if (error instanceof Error && error.name === "ZodError") {
|
|
2543
|
+
return null;
|
|
2544
|
+
}
|
|
2545
|
+
return event;
|
|
2546
|
+
}
|
|
2547
|
+
});
|
|
2548
|
+
return new SentryLogger(Sentry, level);
|
|
2582
2549
|
}
|
|
2583
2550
|
};
|
|
2584
2551
|
}
|
|
@@ -2610,77 +2577,38 @@ import {
|
|
|
2610
2577
|
Guards as Guards33,
|
|
2611
2578
|
SupabaseAuthService,
|
|
2612
2579
|
SupabaseClaimsMapper,
|
|
2613
|
-
SupabaseSessionMapper
|
|
2580
|
+
SupabaseSessionMapper,
|
|
2581
|
+
TOKENS as TOKENS3
|
|
2614
2582
|
} from "@xeno-js/shared";
|
|
2615
2583
|
var SupabaseServerAuthFactory;
|
|
2616
2584
|
var init_supabase_factory = __esm({
|
|
2617
2585
|
"src/infrastructure/factories/supabase.factory.ts"() {
|
|
2618
2586
|
"use strict";
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
const
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
getAll() {
|
|
2634
|
-
return cookieService.getAll();
|
|
2635
|
-
},
|
|
2636
|
-
setAll(cookiesToSet) {
|
|
2637
|
-
cookieService.setAll(cookiesToSet);
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
});
|
|
2641
|
-
const mapper = new SupabaseClaimsMapper();
|
|
2642
|
-
const sessionMapper = new SupabaseSessionMapper(mapper);
|
|
2643
|
-
return new SupabaseAuthService(client, mapper, sessionMapper, config);
|
|
2644
|
-
}
|
|
2645
|
-
};
|
|
2646
|
-
}
|
|
2647
|
-
});
|
|
2648
|
-
|
|
2649
|
-
// src/infrastructure/factories/user-context.factory.ts
|
|
2650
|
-
var user_context_factory_exports = {};
|
|
2651
|
-
__export(user_context_factory_exports, {
|
|
2652
|
-
UserContextFactory: () => UserContextFactory
|
|
2653
|
-
});
|
|
2654
|
-
import { Guards as Guards34 } from "@xeno-js/shared";
|
|
2655
|
-
var UserContextFactory;
|
|
2656
|
-
var init_user_context_factory = __esm({
|
|
2657
|
-
"src/infrastructure/factories/user-context.factory.ts"() {
|
|
2658
|
-
"use strict";
|
|
2659
|
-
UserContextFactory = class {
|
|
2660
|
-
/**
|
|
2661
|
-
* @description Constructs an instance of UserContextFactory.
|
|
2662
|
-
* @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.
|
|
2663
|
-
*
|
|
2664
|
-
* @author Xeno
|
|
2665
|
-
* @version 1.0.0
|
|
2666
|
-
* @since 2025-09-30
|
|
2667
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
2668
|
-
*/
|
|
2669
|
-
constructor(_identityFactory) {
|
|
2670
|
-
this._identityFactory = _identityFactory;
|
|
2587
|
+
init_services();
|
|
2588
|
+
SupabaseServerAuthFactory = class {
|
|
2589
|
+
create({
|
|
2590
|
+
config,
|
|
2591
|
+
container
|
|
2592
|
+
}) {
|
|
2593
|
+
const cookieService = this._getCookieSsr(config.ssrOpts, container, config.cookieOpts);
|
|
2594
|
+
const client = createServerClient(config.url, config.key, {
|
|
2595
|
+
...config.opts,
|
|
2596
|
+
cookies: cookieService
|
|
2597
|
+
});
|
|
2598
|
+
const mapper = new SupabaseClaimsMapper();
|
|
2599
|
+
const sessionMapper = new SupabaseSessionMapper(mapper);
|
|
2600
|
+
return new SupabaseAuthService(client, mapper, sessionMapper, config);
|
|
2671
2601
|
}
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
output.tenantId = identity.tenantId;
|
|
2602
|
+
_getCookieSsr(ssrOpts, container, config) {
|
|
2603
|
+
if (Guards33.isDefined(ssrOpts)) {
|
|
2604
|
+
return ssrOpts(container);
|
|
2605
|
+
} else {
|
|
2606
|
+
return new CookieHandler(
|
|
2607
|
+
container.resolve(TOKENS3.REQUEST_CONTEXT),
|
|
2608
|
+
container.resolve(TOKENS3.CONFIGURATION_SERVICE),
|
|
2609
|
+
config
|
|
2610
|
+
);
|
|
2682
2611
|
}
|
|
2683
|
-
return output;
|
|
2684
2612
|
}
|
|
2685
2613
|
};
|
|
2686
2614
|
}
|
|
@@ -2762,28 +2690,28 @@ var init_auth_utils = __esm({
|
|
|
2762
2690
|
* @link https://github.com/xeno-js/xeno-js
|
|
2763
2691
|
*/
|
|
2764
2692
|
async addAuthZ(container, opts) {
|
|
2765
|
-
const { TOKENS:
|
|
2693
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2766
2694
|
const strategies = [];
|
|
2767
|
-
const { Guards:
|
|
2768
|
-
if (
|
|
2695
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
2696
|
+
if (Guards49.isDefined(opts.policies)) {
|
|
2769
2697
|
const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2770
2698
|
const policyRegistry = opts.policies;
|
|
2771
2699
|
const registryInstance = new PolicyRegistry2();
|
|
2772
|
-
const ctxAccessor = container.resolve(
|
|
2700
|
+
const ctxAccessor = container.resolve(TOKENS5.CONTEXT_ACCESSOR);
|
|
2773
2701
|
const Policies = /* @__PURE__ */ new Set();
|
|
2774
2702
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2775
2703
|
const intentLower = intent.toLowerCase();
|
|
2776
2704
|
registryInstance.addPolicy(intentLower, policy);
|
|
2777
|
-
if (!
|
|
2705
|
+
if (!Guards49.isNullOrEmpty(policy.roles)) {
|
|
2778
2706
|
Policies.add("roles");
|
|
2779
2707
|
}
|
|
2780
|
-
if (!
|
|
2708
|
+
if (!Guards49.isNullOrEmpty(policy.permissions)) {
|
|
2781
2709
|
Policies.add("permissions");
|
|
2782
2710
|
}
|
|
2783
|
-
if (!
|
|
2711
|
+
if (!Guards49.isNullOrEmpty(policy.userId)) {
|
|
2784
2712
|
Policies.add("userId");
|
|
2785
2713
|
}
|
|
2786
|
-
if (!
|
|
2714
|
+
if (!Guards49.isNullOrEmpty(policy.tenantId)) {
|
|
2787
2715
|
Policies.add("tenantId");
|
|
2788
2716
|
}
|
|
2789
2717
|
}
|
|
@@ -2804,10 +2732,10 @@ var init_auth_utils = __esm({
|
|
|
2804
2732
|
strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2805
2733
|
}
|
|
2806
2734
|
}
|
|
2807
|
-
if (!
|
|
2735
|
+
if (!Guards49.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2808
2736
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2809
2737
|
customStrategies.forEach((strategyToken) => {
|
|
2810
|
-
if (
|
|
2738
|
+
if (Guards49.isDefined(strategyToken)) {
|
|
2811
2739
|
strategies.push(strategyToken(container));
|
|
2812
2740
|
}
|
|
2813
2741
|
});
|
|
@@ -2827,28 +2755,280 @@ var init_auth_utils = __esm({
|
|
|
2827
2755
|
* @link https://github.com/xeno-js/xeno-js
|
|
2828
2756
|
*/
|
|
2829
2757
|
async addAuthN(container, opts) {
|
|
2830
|
-
const { Guards:
|
|
2831
|
-
if (
|
|
2758
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2759
|
+
if (Guards49.isDefined(opts.customAuth)) {
|
|
2832
2760
|
const authService = opts.customAuth.authExtendedService();
|
|
2833
|
-
container.addScoped(
|
|
2761
|
+
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2834
2762
|
return authService;
|
|
2835
2763
|
});
|
|
2836
|
-
container.addSingleton(
|
|
2764
|
+
container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
|
|
2837
2765
|
return authService;
|
|
2838
2766
|
});
|
|
2839
2767
|
} else {
|
|
2840
2768
|
const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2841
2769
|
const factory = new SupabaseServerAuthFactory2();
|
|
2842
2770
|
const supabase = factory.create({ config: opts, container });
|
|
2843
|
-
container.addScoped(
|
|
2771
|
+
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2844
2772
|
return supabase;
|
|
2845
2773
|
});
|
|
2846
|
-
container.addSingleton(
|
|
2774
|
+
container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
|
|
2847
2775
|
return supabase;
|
|
2848
2776
|
});
|
|
2849
2777
|
}
|
|
2850
2778
|
}
|
|
2851
|
-
});
|
|
2779
|
+
});
|
|
2780
|
+
}
|
|
2781
|
+
});
|
|
2782
|
+
|
|
2783
|
+
// src/infrastructure/modules/utils/validation.utils.ts
|
|
2784
|
+
var validation_utils_exports = {};
|
|
2785
|
+
__export(validation_utils_exports, {
|
|
2786
|
+
ValidationUtils: () => ValidationUtils
|
|
2787
|
+
});
|
|
2788
|
+
var ValidationUtils;
|
|
2789
|
+
var init_validation_utils = __esm({
|
|
2790
|
+
"src/infrastructure/modules/utils/validation.utils.ts"() {
|
|
2791
|
+
"use strict";
|
|
2792
|
+
ValidationUtils = Object.freeze({
|
|
2793
|
+
/**
|
|
2794
|
+
* @description Checks if the provided validation configuration requires any validation strategies.
|
|
2795
|
+
* @param validationConfig The validation configuration to check.
|
|
2796
|
+
* @returns True if any validation strategies are required, false otherwise.
|
|
2797
|
+
*
|
|
2798
|
+
* @author Xeno
|
|
2799
|
+
* @version 1.0.0
|
|
2800
|
+
* @since 2025-09-30
|
|
2801
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2802
|
+
*/
|
|
2803
|
+
async addValidation(container, opts, logger) {
|
|
2804
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2805
|
+
if (!Guards49.isDefined(opts.zod) && Guards49.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
2806
|
+
return;
|
|
2807
|
+
}
|
|
2808
|
+
const validationStrategies = [];
|
|
2809
|
+
if (Guards49.isDefined(opts.zod)) {
|
|
2810
|
+
const config = opts.zod;
|
|
2811
|
+
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2812
|
+
const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2813
|
+
const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
|
|
2814
|
+
container.addSingleton(TOKENS5.VALIDATOR_SERVICE, () => validatorService);
|
|
2815
|
+
validationStrategies.push(new SchemaValidationStrategy2(validatorService));
|
|
2816
|
+
}
|
|
2817
|
+
if (!Guards49.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
2818
|
+
for (const strategyToken of opts.customValidationStrategy) {
|
|
2819
|
+
if (Guards49.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2823
|
+
return new ValidationPipeline2(validationStrategies);
|
|
2824
|
+
}
|
|
2825
|
+
});
|
|
2826
|
+
}
|
|
2827
|
+
});
|
|
2828
|
+
|
|
2829
|
+
// src/infrastructure/idempotency/idempotency-store.ts
|
|
2830
|
+
import { IDEMPOTENCY_CONSTANTS as IDEMPOTENCY_CONSTANTS2 } from "@xeno-js/shared";
|
|
2831
|
+
var IdempotencyStore;
|
|
2832
|
+
var init_idempotency_store = __esm({
|
|
2833
|
+
"src/infrastructure/idempotency/idempotency-store.ts"() {
|
|
2834
|
+
"use strict";
|
|
2835
|
+
IdempotencyStore = class {
|
|
2836
|
+
/**
|
|
2837
|
+
* @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.
|
|
2838
|
+
* @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.
|
|
2839
|
+
* @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.
|
|
2840
|
+
|
|
2841
|
+
*
|
|
2842
|
+
* @author Xeno
|
|
2843
|
+
* @version 1.0.0
|
|
2844
|
+
* @since 2025-09-30
|
|
2845
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2846
|
+
*/
|
|
2847
|
+
constructor(_cache, _cacheKeyBuilder) {
|
|
2848
|
+
this._cache = _cache;
|
|
2849
|
+
this._cacheKeyBuilder = _cacheKeyBuilder;
|
|
2850
|
+
}
|
|
2851
|
+
_cache;
|
|
2852
|
+
_cacheKeyBuilder;
|
|
2853
|
+
async acquireLock(requestId, ttlSeconds) {
|
|
2854
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${requestId}`);
|
|
2855
|
+
return await this._cache.setIfAbsent(
|
|
2856
|
+
`${IDEMPOTENCY_CONSTANTS2.LOCK_KEY_PREFIX}${key}`,
|
|
2857
|
+
IDEMPOTENCY_CONSTANTS2.LOCKED_VALUE,
|
|
2858
|
+
ttlSeconds
|
|
2859
|
+
);
|
|
2860
|
+
}
|
|
2861
|
+
async hasBeenProcessed(commandId) {
|
|
2862
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2863
|
+
return await this._cache.has(`${IDEMPOTENCY_CONSTANTS2.PROCESSED_KEY_PREFIX}${key}`);
|
|
2864
|
+
}
|
|
2865
|
+
async markAsProcessed(commandId, payload, ttlSeconds) {
|
|
2866
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2867
|
+
await this._cache.set(
|
|
2868
|
+
`${IDEMPOTENCY_CONSTANTS2.PROCESSED_KEY_PREFIX}${key}`,
|
|
2869
|
+
payload,
|
|
2870
|
+
ttlSeconds
|
|
2871
|
+
);
|
|
2872
|
+
}
|
|
2873
|
+
async getPayload(commandId) {
|
|
2874
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2875
|
+
const payload = await this._cache.get(`${IDEMPOTENCY_CONSTANTS2.PROCESSED_KEY_PREFIX}${key}`);
|
|
2876
|
+
return payload;
|
|
2877
|
+
}
|
|
2878
|
+
async releaseLock(commandId) {
|
|
2879
|
+
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2880
|
+
await this._cache.remove(`${IDEMPOTENCY_CONSTANTS2.LOCK_KEY_PREFIX}${key}`);
|
|
2881
|
+
}
|
|
2882
|
+
};
|
|
2883
|
+
}
|
|
2884
|
+
});
|
|
2885
|
+
|
|
2886
|
+
// src/infrastructure/idempotency/index.ts
|
|
2887
|
+
var idempotency_exports = {};
|
|
2888
|
+
__export(idempotency_exports, {
|
|
2889
|
+
IdempotencyStore: () => IdempotencyStore
|
|
2890
|
+
});
|
|
2891
|
+
var init_idempotency = __esm({
|
|
2892
|
+
"src/infrastructure/idempotency/index.ts"() {
|
|
2893
|
+
"use strict";
|
|
2894
|
+
init_idempotency_store();
|
|
2895
|
+
}
|
|
2896
|
+
});
|
|
2897
|
+
|
|
2898
|
+
// src/infrastructure/modules/utils/pipeline.utils.ts
|
|
2899
|
+
var pipeline_utils_exports = {};
|
|
2900
|
+
__export(pipeline_utils_exports, {
|
|
2901
|
+
PipelineUtils: () => PipelineUtils
|
|
2902
|
+
});
|
|
2903
|
+
var PipelineUtils;
|
|
2904
|
+
var init_pipeline_utils = __esm({
|
|
2905
|
+
"src/infrastructure/modules/utils/pipeline.utils.ts"() {
|
|
2906
|
+
"use strict";
|
|
2907
|
+
PipelineUtils = Object.freeze({
|
|
2908
|
+
/**
|
|
2909
|
+
* @description Checks if the provided command configuration requires any command strategies.
|
|
2910
|
+
* @param commandConfig The command configuration to check.
|
|
2911
|
+
* @returns True if any command strategies are required, false otherwise.
|
|
2912
|
+
*
|
|
2913
|
+
* @author Xeno
|
|
2914
|
+
* @version 1.0.0
|
|
2915
|
+
* @since 2025-09-30
|
|
2916
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2917
|
+
*/
|
|
2918
|
+
async addCommand(container, opts) {
|
|
2919
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2920
|
+
const pipelines = [];
|
|
2921
|
+
if (Guards49.isDefined(opts.idempotency)) {
|
|
2922
|
+
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
|
|
2923
|
+
const imdStore = new IdempotencyStore2(
|
|
2924
|
+
container.resolve(TOKENS5.CACHE),
|
|
2925
|
+
container.resolve(TOKENS5.CACHE_KEY_BUILDER)
|
|
2926
|
+
);
|
|
2927
|
+
const { IdempotencyPipeline: IdempotencyPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2928
|
+
const requestContext = container.resolve(TOKENS5.NETWORK_CONTEXT_ACCESSOR);
|
|
2929
|
+
const config = opts.idempotency;
|
|
2930
|
+
pipelines.push(
|
|
2931
|
+
new IdempotencyPipeline2(
|
|
2932
|
+
requestContext,
|
|
2933
|
+
imdStore,
|
|
2934
|
+
config?.lockTtlSeconds,
|
|
2935
|
+
config?.processedTtlSeconds
|
|
2936
|
+
)
|
|
2937
|
+
);
|
|
2938
|
+
}
|
|
2939
|
+
if (Guards49.isDefined(opts.concurrency)) {
|
|
2940
|
+
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2941
|
+
const config = opts.concurrency;
|
|
2942
|
+
pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
|
|
2943
|
+
}
|
|
2944
|
+
return pipelines;
|
|
2945
|
+
},
|
|
2946
|
+
/**
|
|
2947
|
+
* @description Checks if the provided query configuration requires any query strategies.
|
|
2948
|
+
* @param queryConfig The query configuration to check.
|
|
2949
|
+
* @returns True if any query strategies are required, false otherwise.
|
|
2950
|
+
*
|
|
2951
|
+
* @author Xeno
|
|
2952
|
+
* @version 1.0.0
|
|
2953
|
+
* @since 2025-09-30
|
|
2954
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
2955
|
+
*/
|
|
2956
|
+
async addQuery(container) {
|
|
2957
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2958
|
+
const { QueryCachingPipeline: QueryCachingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2959
|
+
return new QueryCachingPipeline2(
|
|
2960
|
+
container.resolve(TOKENS5.CACHE),
|
|
2961
|
+
container.resolve(TOKENS5.CACHE_KEY_BUILDER),
|
|
2962
|
+
container.resolve(TOKENS5.LOGGER)
|
|
2963
|
+
);
|
|
2964
|
+
}
|
|
2965
|
+
});
|
|
2966
|
+
}
|
|
2967
|
+
});
|
|
2968
|
+
|
|
2969
|
+
// src/infrastructure/modules/cqrs.module.ts
|
|
2970
|
+
var cqrs_module_exports = {};
|
|
2971
|
+
__export(cqrs_module_exports, {
|
|
2972
|
+
CqrsModule: () => CqrsModule
|
|
2973
|
+
});
|
|
2974
|
+
var CqrsModule;
|
|
2975
|
+
var init_cqrs_module = __esm({
|
|
2976
|
+
"src/infrastructure/modules/cqrs.module.ts"() {
|
|
2977
|
+
"use strict";
|
|
2978
|
+
CqrsModule = class {
|
|
2979
|
+
async configure(container, opts) {
|
|
2980
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2981
|
+
const logger = container.resolve(TOKENS5.LOGGER);
|
|
2982
|
+
const { Mediator: Mediator2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2983
|
+
container.addSingleton(TOKENS5.MEDIATOR, (c) => {
|
|
2984
|
+
const serviceScopeAccessor = c.resolve(TOKENS5.SERVICE_SCOPE_ACCESSOR);
|
|
2985
|
+
return new Mediator2(serviceScopeAccessor);
|
|
2986
|
+
});
|
|
2987
|
+
const { ExceptionPipeline: ExceptionPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2988
|
+
const { LoggingPipeline: LoggingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2989
|
+
const { PerformancePipeline: PerformancePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2990
|
+
const thresholdMs = opts.performance?.thresholdMs;
|
|
2991
|
+
const pipelines = [
|
|
2992
|
+
new ExceptionPipeline2(),
|
|
2993
|
+
new LoggingPipeline2(logger),
|
|
2994
|
+
new PerformancePipeline2(logger, thresholdMs)
|
|
2995
|
+
];
|
|
2996
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
2997
|
+
if (Guards49.isDefined(opts.authorization.policies) || Guards49.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
2998
|
+
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
2999
|
+
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
3000
|
+
pipelines.push(authPipelines);
|
|
3001
|
+
}
|
|
3002
|
+
if (Guards49.isDefined(opts.validation.zod) || Guards49.isDefined(opts.validation.customValidationStrategy)) {
|
|
3003
|
+
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
3004
|
+
const validationPipelines = await ValidationUtils2.addValidation(
|
|
3005
|
+
container,
|
|
3006
|
+
opts.validation,
|
|
3007
|
+
logger
|
|
3008
|
+
);
|
|
3009
|
+
if (Guards49.isDefined(validationPipelines)) pipelines.push(validationPipelines);
|
|
3010
|
+
}
|
|
3011
|
+
const commandPipelines = [...pipelines];
|
|
3012
|
+
const queryPipelines = [...pipelines];
|
|
3013
|
+
if (Guards49.isDefined(opts.commandBus.idempotency) || Guards49.isDefined(opts.commandBus.concurrency)) {
|
|
3014
|
+
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3015
|
+
const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
|
|
3016
|
+
commandPipelines.push(...newCommandPipelines);
|
|
3017
|
+
}
|
|
3018
|
+
if (opts.queryBus.isEnabled) {
|
|
3019
|
+
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3020
|
+
const newQueryPipelines = await PipelineUtils2.addQuery(container);
|
|
3021
|
+
queryPipelines.push(newQueryPipelines);
|
|
3022
|
+
}
|
|
3023
|
+
const { CompositePipeline: CompositePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3024
|
+
container.addSingleton(TOKENS5.COMMAND_PIPELINES_BEHAVIOR, () => {
|
|
3025
|
+
return new CompositePipeline2(commandPipelines);
|
|
3026
|
+
});
|
|
3027
|
+
container.addSingleton(TOKENS5.QUERY_PIPELINES_BEHAVIOR, () => {
|
|
3028
|
+
return new CompositePipeline2(queryPipelines);
|
|
3029
|
+
});
|
|
3030
|
+
}
|
|
3031
|
+
};
|
|
2852
3032
|
}
|
|
2853
3033
|
});
|
|
2854
3034
|
|
|
@@ -2939,7 +3119,7 @@ __export(unit_of_work_exports, {
|
|
|
2939
3119
|
UnitOfWork: () => UnitOfWork
|
|
2940
3120
|
});
|
|
2941
3121
|
import { AppError as AppError14 } from "@xeno-js/shared";
|
|
2942
|
-
import { Guards as
|
|
3122
|
+
import { Guards as Guards34 } from "@xeno-js/shared";
|
|
2943
3123
|
var UnitOfWork;
|
|
2944
3124
|
var init_unit_of_work = __esm({
|
|
2945
3125
|
"src/infrastructure/transaction/unit-of-work.ts"() {
|
|
@@ -2974,9 +3154,9 @@ var init_unit_of_work = __esm({
|
|
|
2974
3154
|
});
|
|
2975
3155
|
}
|
|
2976
3156
|
async dispose() {
|
|
2977
|
-
if (
|
|
3157
|
+
if (Guards34.isDefined(this._ttx.state)) {
|
|
2978
3158
|
try {
|
|
2979
|
-
if (
|
|
3159
|
+
if (Guards34.hasMethod(this._ttx.state, "rollback")) {
|
|
2980
3160
|
await this._ttx.state.rollback();
|
|
2981
3161
|
}
|
|
2982
3162
|
} finally {
|
|
@@ -2999,7 +3179,7 @@ var init_db_module = __esm({
|
|
|
2999
3179
|
"use strict";
|
|
3000
3180
|
DbModule = class {
|
|
3001
3181
|
async configure(container, opts) {
|
|
3002
|
-
const { Guards:
|
|
3182
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3003
3183
|
const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
|
|
3004
3184
|
const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
|
|
3005
3185
|
const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
|
|
@@ -3007,16 +3187,16 @@ var init_db_module = __esm({
|
|
|
3007
3187
|
return new TransactionState2();
|
|
3008
3188
|
});
|
|
3009
3189
|
const { UnitOfWork: UnitOfWork2 } = await Promise.resolve().then(() => (init_unit_of_work(), unit_of_work_exports));
|
|
3010
|
-
container.addScoped(
|
|
3190
|
+
container.addScoped(TOKENS5.UNIT_OF_WORK, (c) => {
|
|
3011
3191
|
const ttx = c.resolve("TRANSACTION_STATE");
|
|
3012
3192
|
return new UnitOfWork2(db, ttx);
|
|
3013
3193
|
});
|
|
3014
|
-
container.addScoped(
|
|
3194
|
+
container.addScoped(TOKENS5.DB_CONTEXT, (c) => {
|
|
3015
3195
|
const ttx = c.resolve("TRANSACTION_STATE");
|
|
3016
3196
|
return new Proxy(db, {
|
|
3017
3197
|
get(_target, prop, receiver) {
|
|
3018
3198
|
const activeState = ttx.state;
|
|
3019
|
-
if (
|
|
3199
|
+
if (Guards49.isDefined(activeState)) {
|
|
3020
3200
|
if (prop === "transaction") {
|
|
3021
3201
|
return activeState.transaction.bind(activeState);
|
|
3022
3202
|
}
|
|
@@ -3031,331 +3211,270 @@ var init_db_module = __esm({
|
|
|
3031
3211
|
}
|
|
3032
3212
|
});
|
|
3033
3213
|
|
|
3034
|
-
// src/infrastructure/
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
var HttpUtils;
|
|
3040
|
-
var init_http_utils = __esm({
|
|
3041
|
-
"src/infrastructure/modules/utils/http.utils.ts"() {
|
|
3214
|
+
// src/infrastructure/http/base.http-adapter.ts
|
|
3215
|
+
import { Guards as Guards35, StringHelper as StringHelper3 } from "@xeno-js/shared";
|
|
3216
|
+
var BaseHttpAdapter;
|
|
3217
|
+
var init_base_http_adapter = __esm({
|
|
3218
|
+
"src/infrastructure/http/base.http-adapter.ts"() {
|
|
3042
3219
|
"use strict";
|
|
3043
|
-
|
|
3220
|
+
BaseHttpAdapter = class {
|
|
3044
3221
|
/**
|
|
3045
|
-
* @description
|
|
3046
|
-
* @param
|
|
3047
|
-
* @
|
|
3048
|
-
*
|
|
3049
|
-
* @
|
|
3050
|
-
* @version 1.0.0
|
|
3051
|
-
* @since 2025-09-30
|
|
3052
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3222
|
+
* @description Parse the URL from the request.
|
|
3223
|
+
* @param rawUrl The raw URL.
|
|
3224
|
+
* @param headers The headers.
|
|
3225
|
+
* @param queryParams The query parameters.
|
|
3226
|
+
* @returns The parsed URL.
|
|
3053
3227
|
*/
|
|
3054
|
-
|
|
3055
|
-
const
|
|
3056
|
-
const
|
|
3057
|
-
|
|
3058
|
-
|
|
3228
|
+
parseUrl(rawUrl = "/", headers, queryParams) {
|
|
3229
|
+
const protocol = StringHelper3.getSingleValue(headers["x-forwarded-proto"]) ?? "https";
|
|
3230
|
+
const host = StringHelper3.safeStringify(headers["host"]) ?? "localhost";
|
|
3231
|
+
const url = new URL(rawUrl, `${protocol}://${host}`);
|
|
3232
|
+
if (!Guards35.isNullOrEmpty(queryParams)) {
|
|
3233
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
3234
|
+
if (Guards35.isArray(value)) {
|
|
3235
|
+
value.forEach((v) => url.searchParams.append(key, String(v)));
|
|
3236
|
+
} else if (Guards35.isDefined(value)) {
|
|
3237
|
+
url.searchParams.set(key, String(value));
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3059
3240
|
}
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3241
|
+
return url;
|
|
3242
|
+
}
|
|
3243
|
+
/**
|
|
3244
|
+
* @description Parses the headers.
|
|
3245
|
+
* @param rawHeaders The raw headers.
|
|
3246
|
+
* @returns The parsed headers.
|
|
3247
|
+
*/
|
|
3248
|
+
parseHeaders(rawHeaders) {
|
|
3249
|
+
const headers = new Headers();
|
|
3250
|
+
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
3251
|
+
if (Guards35.isDefined(value)) {
|
|
3252
|
+
if (Guards35.isArray(value)) {
|
|
3253
|
+
value.forEach((v) => headers.append(key, String(v)));
|
|
3254
|
+
} else {
|
|
3255
|
+
headers.set(key, String(value));
|
|
3256
|
+
}
|
|
3067
3257
|
}
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
}
|
|
3258
|
+
}
|
|
3259
|
+
return headers;
|
|
3260
|
+
}
|
|
3071
3261
|
/**
|
|
3072
|
-
* @description
|
|
3073
|
-
* @param
|
|
3074
|
-
* @param
|
|
3075
|
-
*
|
|
3076
|
-
* @author Xeno
|
|
3077
|
-
* @version 1.0.0
|
|
3078
|
-
* @since 2025-09-30
|
|
3079
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3262
|
+
* @description Parses the body.
|
|
3263
|
+
* @param method The method.
|
|
3264
|
+
* @param rawBody The raw body.
|
|
3265
|
+
* @returns The parsed body.
|
|
3080
3266
|
*/
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
return
|
|
3087
|
-
|
|
3267
|
+
parseBody(method, rawBody) {
|
|
3268
|
+
if (!Guards35.isDefined(method) || !["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase()) || !Guards35.isDefined(rawBody))
|
|
3269
|
+
return void 0;
|
|
3270
|
+
if (Guards35.isObject(rawBody)) return JSON.stringify(rawBody);
|
|
3271
|
+
if (Guards35.isString(rawBody) || rawBody instanceof Blob || rawBody instanceof ArrayBuffer || ArrayBuffer.isView(rawBody) || rawBody instanceof URLSearchParams || rawBody instanceof FormData)
|
|
3272
|
+
return rawBody;
|
|
3273
|
+
return String(rawBody);
|
|
3088
3274
|
}
|
|
3089
|
-
|
|
3275
|
+
/**
|
|
3276
|
+
* @description Creates the XenoWebTransport.
|
|
3277
|
+
* @param url The url.
|
|
3278
|
+
* @param method The method.
|
|
3279
|
+
* @param headers The headers.
|
|
3280
|
+
* @param body The body.
|
|
3281
|
+
* @returns The XenoWebTransport.
|
|
3282
|
+
*/
|
|
3283
|
+
createXenoWebTransport(url, method = "GET", headers, body = void 0) {
|
|
3284
|
+
const init2 = {
|
|
3285
|
+
method: method.toUpperCase(),
|
|
3286
|
+
headers
|
|
3287
|
+
};
|
|
3288
|
+
const parsedBody = this.parseBody(method, body);
|
|
3289
|
+
if (Guards35.isDefined(parsedBody)) {
|
|
3290
|
+
init2.body = parsedBody;
|
|
3291
|
+
init2.duplex = "half";
|
|
3292
|
+
}
|
|
3293
|
+
return {
|
|
3294
|
+
request: {
|
|
3295
|
+
...new Request(url, init2),
|
|
3296
|
+
path: url.pathname
|
|
3297
|
+
},
|
|
3298
|
+
response: new Response()
|
|
3299
|
+
};
|
|
3300
|
+
}
|
|
3301
|
+
};
|
|
3090
3302
|
}
|
|
3091
3303
|
});
|
|
3092
3304
|
|
|
3093
|
-
// src/infrastructure/
|
|
3094
|
-
var
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
});
|
|
3098
|
-
var HttpCoreModule;
|
|
3099
|
-
var init_http_core_module = __esm({
|
|
3100
|
-
"src/infrastructure/modules/http-core.module.ts"() {
|
|
3305
|
+
// src/infrastructure/http/fastify.http-adapter.ts
|
|
3306
|
+
var FastifyHttpAdapter;
|
|
3307
|
+
var init_fastify_http_adapter = __esm({
|
|
3308
|
+
"src/infrastructure/http/fastify.http-adapter.ts"() {
|
|
3101
3309
|
"use strict";
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3310
|
+
init_base_http_adapter();
|
|
3311
|
+
FastifyHttpAdapter = class extends BaseHttpAdapter {
|
|
3312
|
+
adapt(req, _res) {
|
|
3313
|
+
const headers = this.parseHeaders(req.headers);
|
|
3314
|
+
const url = this.parseUrl(req.url, req.headers, req.query);
|
|
3315
|
+
const body = req.body;
|
|
3316
|
+
return this.createXenoWebTransport(url, req.method, headers, body);
|
|
3107
3317
|
}
|
|
3108
3318
|
};
|
|
3109
3319
|
}
|
|
3110
3320
|
});
|
|
3111
3321
|
|
|
3112
|
-
// src/infrastructure/
|
|
3113
|
-
var
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
});
|
|
3117
|
-
var ValidationUtils;
|
|
3118
|
-
var init_validation_utils = __esm({
|
|
3119
|
-
"src/infrastructure/modules/utils/validation.utils.ts"() {
|
|
3322
|
+
// src/infrastructure/http/native.http-adapter.ts
|
|
3323
|
+
var NativeHttpAdapter;
|
|
3324
|
+
var init_native_http_adapter = __esm({
|
|
3325
|
+
"src/infrastructure/http/native.http-adapter.ts"() {
|
|
3120
3326
|
"use strict";
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
*/
|
|
3132
|
-
async addValidation(container, opts, logger) {
|
|
3133
|
-
const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3134
|
-
if (!Guards46.isDefined(opts.zod) && Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3135
|
-
return;
|
|
3136
|
-
}
|
|
3137
|
-
const validationStrategies = [];
|
|
3138
|
-
if (Guards46.isDefined(opts.zod)) {
|
|
3139
|
-
const config = opts.zod;
|
|
3140
|
-
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3141
|
-
const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3142
|
-
const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
|
|
3143
|
-
container.addSingleton(TOKENS4.VALIDATOR_SERVICE, () => validatorService);
|
|
3144
|
-
validationStrategies.push(new SchemaValidationStrategy2(validatorService));
|
|
3145
|
-
}
|
|
3146
|
-
if (!Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3147
|
-
for (const strategyToken of opts.customValidationStrategy) {
|
|
3148
|
-
if (Guards46.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
|
|
3149
|
-
}
|
|
3150
|
-
}
|
|
3151
|
-
const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3152
|
-
return new ValidationPipeline2(validationStrategies);
|
|
3327
|
+
init_base_http_adapter();
|
|
3328
|
+
NativeHttpAdapter = class extends BaseHttpAdapter {
|
|
3329
|
+
adapt(req, res) {
|
|
3330
|
+
return {
|
|
3331
|
+
request: {
|
|
3332
|
+
...req,
|
|
3333
|
+
path: new URL(req.url).pathname
|
|
3334
|
+
},
|
|
3335
|
+
response: res
|
|
3336
|
+
};
|
|
3153
3337
|
}
|
|
3154
|
-
}
|
|
3338
|
+
};
|
|
3155
3339
|
}
|
|
3156
3340
|
});
|
|
3157
3341
|
|
|
3158
|
-
// src/infrastructure/
|
|
3159
|
-
|
|
3160
|
-
var
|
|
3161
|
-
|
|
3162
|
-
"src/infrastructure/idempotency/idempotency-store.ts"() {
|
|
3342
|
+
// src/infrastructure/http/vercel.http-adapter.ts
|
|
3343
|
+
var VercelHttpAdapter;
|
|
3344
|
+
var init_vercel_http_adapter = __esm({
|
|
3345
|
+
"src/infrastructure/http/vercel.http-adapter.ts"() {
|
|
3163
3346
|
"use strict";
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
*
|
|
3171
|
-
* @author Xeno
|
|
3172
|
-
* @version 1.0.0
|
|
3173
|
-
* @since 2025-09-30
|
|
3174
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3175
|
-
*/
|
|
3176
|
-
constructor(_cache, _cacheKeyBuilder) {
|
|
3177
|
-
this._cache = _cache;
|
|
3178
|
-
this._cacheKeyBuilder = _cacheKeyBuilder;
|
|
3179
|
-
}
|
|
3180
|
-
_cache;
|
|
3181
|
-
_cacheKeyBuilder;
|
|
3182
|
-
async acquireLock(requestId, ttlSeconds) {
|
|
3183
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${requestId}`);
|
|
3184
|
-
return await this._cache.setIfAbsent(
|
|
3185
|
-
`${IDEMPOTENCY_CONSTANTS2.LOCK_KEY_PREFIX}${key}`,
|
|
3186
|
-
IDEMPOTENCY_CONSTANTS2.LOCKED_VALUE,
|
|
3187
|
-
ttlSeconds
|
|
3188
|
-
);
|
|
3189
|
-
}
|
|
3190
|
-
async hasBeenProcessed(commandId) {
|
|
3191
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3192
|
-
return await this._cache.has(`${IDEMPOTENCY_CONSTANTS2.PROCESSED_KEY_PREFIX}${key}`);
|
|
3193
|
-
}
|
|
3194
|
-
async markAsProcessed(commandId, payload, ttlSeconds) {
|
|
3195
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3196
|
-
await this._cache.set(
|
|
3197
|
-
`${IDEMPOTENCY_CONSTANTS2.PROCESSED_KEY_PREFIX}${key}`,
|
|
3198
|
-
payload,
|
|
3199
|
-
ttlSeconds
|
|
3200
|
-
);
|
|
3201
|
-
}
|
|
3202
|
-
async getPayload(commandId) {
|
|
3203
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3204
|
-
const payload = await this._cache.get(`${IDEMPOTENCY_CONSTANTS2.PROCESSED_KEY_PREFIX}${key}`);
|
|
3205
|
-
return payload;
|
|
3206
|
-
}
|
|
3207
|
-
async releaseLock(commandId) {
|
|
3208
|
-
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3209
|
-
await this._cache.remove(`${IDEMPOTENCY_CONSTANTS2.LOCK_KEY_PREFIX}${key}`);
|
|
3347
|
+
init_base_http_adapter();
|
|
3348
|
+
VercelHttpAdapter = class extends BaseHttpAdapter {
|
|
3349
|
+
adapt(req, _res) {
|
|
3350
|
+
const headers = this.parseHeaders(req.headers);
|
|
3351
|
+
const url = this.parseUrl(req.url, req.headers, req.query);
|
|
3352
|
+
return this.createXenoWebTransport(url, req.method, headers, req.body);
|
|
3210
3353
|
}
|
|
3211
3354
|
};
|
|
3212
3355
|
}
|
|
3213
3356
|
});
|
|
3214
3357
|
|
|
3215
|
-
// src/infrastructure/
|
|
3216
|
-
var
|
|
3217
|
-
__export(
|
|
3218
|
-
|
|
3358
|
+
// src/infrastructure/http/index.ts
|
|
3359
|
+
var http_exports = {};
|
|
3360
|
+
__export(http_exports, {
|
|
3361
|
+
BaseHttpAdapter: () => BaseHttpAdapter,
|
|
3362
|
+
FastifyHttpAdapter: () => FastifyHttpAdapter,
|
|
3363
|
+
NativeHttpAdapter: () => NativeHttpAdapter,
|
|
3364
|
+
VercelHttpAdapter: () => VercelHttpAdapter
|
|
3219
3365
|
});
|
|
3220
|
-
var
|
|
3221
|
-
"src/infrastructure/
|
|
3366
|
+
var init_http = __esm({
|
|
3367
|
+
"src/infrastructure/http/index.ts"() {
|
|
3222
3368
|
"use strict";
|
|
3223
|
-
|
|
3369
|
+
init_base_http_adapter();
|
|
3370
|
+
init_fastify_http_adapter();
|
|
3371
|
+
init_native_http_adapter();
|
|
3372
|
+
init_vercel_http_adapter();
|
|
3224
3373
|
}
|
|
3225
3374
|
});
|
|
3226
3375
|
|
|
3227
|
-
// src/infrastructure/modules/
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3376
|
+
// src/infrastructure/modules/http-adapter.module.ts
|
|
3377
|
+
import { Guards as Guards36 } from "@xeno-js/shared";
|
|
3378
|
+
var HttpAdapterModule;
|
|
3379
|
+
var init_http_adapter_module = __esm({
|
|
3380
|
+
"src/infrastructure/modules/http-adapter.module.ts"() {
|
|
3381
|
+
"use strict";
|
|
3382
|
+
HttpAdapterModule = class {
|
|
3383
|
+
async configure(container, opts) {
|
|
3384
|
+
const adapter = await this._getAdapter(opts);
|
|
3385
|
+
container.addSingleton("HTTP_ADAPTER", () => adapter);
|
|
3386
|
+
}
|
|
3387
|
+
async _getAdapter(opts) {
|
|
3388
|
+
if (opts.vercel) {
|
|
3389
|
+
const { VercelHttpAdapter: VercelHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
3390
|
+
return new VercelHttpAdapter2();
|
|
3391
|
+
} else if (opts.fastify) {
|
|
3392
|
+
const { FastifyHttpAdapter: FastifyHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
3393
|
+
return new FastifyHttpAdapter2();
|
|
3394
|
+
} else if (Guards36.isDefined(opts.custom)) {
|
|
3395
|
+
return opts.custom();
|
|
3396
|
+
} else {
|
|
3397
|
+
const { NativeHttpAdapter: NativeHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
3398
|
+
return new NativeHttpAdapter2();
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
};
|
|
3402
|
+
}
|
|
3231
3403
|
});
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3404
|
+
|
|
3405
|
+
// src/infrastructure/modules/utils/http.utils.ts
|
|
3406
|
+
var http_utils_exports = {};
|
|
3407
|
+
__export(http_utils_exports, {
|
|
3408
|
+
HttpUtils: () => HttpUtils
|
|
3409
|
+
});
|
|
3410
|
+
var HttpUtils;
|
|
3411
|
+
var init_http_utils = __esm({
|
|
3412
|
+
"src/infrastructure/modules/utils/http.utils.ts"() {
|
|
3235
3413
|
"use strict";
|
|
3236
|
-
|
|
3414
|
+
HttpUtils = Object.freeze({
|
|
3237
3415
|
/**
|
|
3238
|
-
* @description
|
|
3239
|
-
* @param
|
|
3240
|
-
* @returns
|
|
3416
|
+
* @description Utility function to create a query string from an object of query parameters. It takes an object where the keys are the parameter names and the values are the parameter values, and returns a properly encoded query string that can be appended to a URL for making HTTP requests.
|
|
3417
|
+
* @param params - An object containing the query parameters as key-value pairs. The keys represent the parameter names, and the values represent the parameter values.
|
|
3418
|
+
* @returns A string representing the encoded query string that can be appended to a URL for making HTTP requests.
|
|
3241
3419
|
*
|
|
3242
3420
|
* @author Xeno
|
|
3243
3421
|
* @version 1.0.0
|
|
3244
3422
|
* @since 2025-09-30
|
|
3245
3423
|
* @link https://github.com/xeno-js/xeno-js
|
|
3246
3424
|
*/
|
|
3247
|
-
async
|
|
3248
|
-
const {
|
|
3249
|
-
const
|
|
3250
|
-
if (
|
|
3251
|
-
|
|
3252
|
-
const imdStore = new IdempotencyStore2(
|
|
3253
|
-
container.resolve(TOKENS4.CACHE),
|
|
3254
|
-
container.resolve(TOKENS4.CACHE_KEY_BUILDER)
|
|
3255
|
-
);
|
|
3256
|
-
const { IdempotencyPipeline: IdempotencyPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3257
|
-
const requestContext = container.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR);
|
|
3258
|
-
const config = opts.idempotency;
|
|
3259
|
-
pipelines.push(
|
|
3260
|
-
new IdempotencyPipeline2(
|
|
3261
|
-
requestContext,
|
|
3262
|
-
imdStore,
|
|
3263
|
-
config?.lockTtlSeconds,
|
|
3264
|
-
config?.processedTtlSeconds
|
|
3265
|
-
)
|
|
3266
|
-
);
|
|
3267
|
-
}
|
|
3268
|
-
if (Guards46.isDefined(opts.concurrency)) {
|
|
3269
|
-
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3270
|
-
const config = opts.concurrency;
|
|
3271
|
-
pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
|
|
3425
|
+
async addAxios(container, opts) {
|
|
3426
|
+
const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3427
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
3428
|
+
if (!Guards49.isDefined(opts.token)) {
|
|
3429
|
+
throw new Error("HttpConfig.token is required and must be defined.");
|
|
3272
3430
|
}
|
|
3273
|
-
|
|
3431
|
+
container.addSingleton(opts.token, () => {
|
|
3432
|
+
const factory = new NodeAxiosFactory2();
|
|
3433
|
+
const instance = factory.create(opts.client);
|
|
3434
|
+
if (!Guards49.hasMethod(instance, "get") || !Guards49.hasMethod(instance, "post") || !Guards49.hasMethod(instance, "put") || !Guards49.hasMethod(instance, "patch") || !Guards49.hasMethod(instance, "delete")) {
|
|
3435
|
+
throw new Error(
|
|
3436
|
+
"The created HTTP client instance does not implement the required methods of IHttpClient."
|
|
3437
|
+
);
|
|
3438
|
+
}
|
|
3439
|
+
return instance;
|
|
3440
|
+
});
|
|
3274
3441
|
},
|
|
3275
3442
|
/**
|
|
3276
|
-
* @description
|
|
3277
|
-
* @param
|
|
3278
|
-
* @
|
|
3443
|
+
* @description Utility function to add resilience features to the service container. It takes a ResilienceConfig object that specifies whether resilience features are enabled and provides the necessary settings for implementing resilience strategies such as retries, circuit breakers, and timeouts. If resilience is enabled, it registers a singleton factory in the service container that creates an instance of the resilience client based on the provided configuration.
|
|
3444
|
+
* @param container - The service container to register the resilience client with.
|
|
3445
|
+
* @param opts - The ResilienceConfig options that determine whether resilience features are enabled and provide the necessary settings for implementing resilience strategies.
|
|
3279
3446
|
*
|
|
3280
3447
|
* @author Xeno
|
|
3281
3448
|
* @version 1.0.0
|
|
3282
3449
|
* @since 2025-09-30
|
|
3283
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
3284
|
-
*/
|
|
3285
|
-
async
|
|
3286
|
-
const { TOKENS:
|
|
3287
|
-
const {
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
);
|
|
3450
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
3451
|
+
*/
|
|
3452
|
+
async addResilience(container, opts) {
|
|
3453
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3454
|
+
const { CockatielResilienceFactory: CockatielResilienceFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3455
|
+
container.addSingleton(TOKENS5.RESILIENCE_CLIENT, () => {
|
|
3456
|
+
const factory = new CockatielResilienceFactory2();
|
|
3457
|
+
return factory.create(opts);
|
|
3458
|
+
});
|
|
3293
3459
|
}
|
|
3294
3460
|
});
|
|
3295
3461
|
}
|
|
3296
3462
|
});
|
|
3297
3463
|
|
|
3298
|
-
// src/infrastructure/modules/
|
|
3299
|
-
var
|
|
3300
|
-
__export(
|
|
3301
|
-
|
|
3464
|
+
// src/infrastructure/modules/http-core.module.ts
|
|
3465
|
+
var http_core_module_exports = {};
|
|
3466
|
+
__export(http_core_module_exports, {
|
|
3467
|
+
HttpCoreModule: () => HttpCoreModule
|
|
3302
3468
|
});
|
|
3303
|
-
var
|
|
3304
|
-
var
|
|
3305
|
-
"src/infrastructure/modules/
|
|
3469
|
+
var HttpCoreModule;
|
|
3470
|
+
var init_http_core_module = __esm({
|
|
3471
|
+
"src/infrastructure/modules/http-core.module.ts"() {
|
|
3306
3472
|
"use strict";
|
|
3307
|
-
|
|
3473
|
+
HttpCoreModule = class {
|
|
3308
3474
|
async configure(container, opts) {
|
|
3309
|
-
const {
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
container.addSingleton(TOKENS4.MEDIATOR, (c) => {
|
|
3313
|
-
const serviceScopeAccessor = c.resolve(TOKENS4.SERVICE_SCOPE_ACCESSOR);
|
|
3314
|
-
return new Mediator2(serviceScopeAccessor);
|
|
3315
|
-
});
|
|
3316
|
-
const { ExceptionPipeline: ExceptionPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3317
|
-
const { LoggingPipeline: LoggingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3318
|
-
const { PerformancePipeline: PerformancePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3319
|
-
const thresholdMs = opts.performance?.thresholdMs;
|
|
3320
|
-
const pipelines = [
|
|
3321
|
-
new ExceptionPipeline2(),
|
|
3322
|
-
new LoggingPipeline2(logger),
|
|
3323
|
-
new PerformancePipeline2(logger, thresholdMs)
|
|
3324
|
-
];
|
|
3325
|
-
const { Guards: Guards46 } = await import("@xeno-js/shared");
|
|
3326
|
-
if (Guards46.isDefined(opts.authorization.policies) || Guards46.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
3327
|
-
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
3328
|
-
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
3329
|
-
pipelines.push(authPipelines);
|
|
3330
|
-
}
|
|
3331
|
-
if (Guards46.isDefined(opts.validation.zod) || Guards46.isDefined(opts.validation.customValidationStrategy)) {
|
|
3332
|
-
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
3333
|
-
const validationPipelines = await ValidationUtils2.addValidation(
|
|
3334
|
-
container,
|
|
3335
|
-
opts.validation,
|
|
3336
|
-
logger
|
|
3337
|
-
);
|
|
3338
|
-
if (Guards46.isDefined(validationPipelines)) pipelines.push(validationPipelines);
|
|
3339
|
-
}
|
|
3340
|
-
const commandPipelines = [...pipelines];
|
|
3341
|
-
const queryPipelines = [...pipelines];
|
|
3342
|
-
if (Guards46.isDefined(opts.commandBus.idempotency) || Guards46.isDefined(opts.commandBus.concurrency)) {
|
|
3343
|
-
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3344
|
-
const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
|
|
3345
|
-
commandPipelines.push(...newCommandPipelines);
|
|
3346
|
-
}
|
|
3347
|
-
if (opts.queryBus.isEnabled) {
|
|
3348
|
-
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3349
|
-
const newQueryPipelines = await PipelineUtils2.addQuery(container);
|
|
3350
|
-
queryPipelines.push(newQueryPipelines);
|
|
3351
|
-
}
|
|
3352
|
-
const { CompositePipeline: CompositePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3353
|
-
container.addSingleton(TOKENS4.COMMAND_PIPELINES_BEHAVIOR, () => {
|
|
3354
|
-
return new CompositePipeline2(commandPipelines);
|
|
3355
|
-
});
|
|
3356
|
-
container.addSingleton(TOKENS4.QUERY_PIPELINES_BEHAVIOR, () => {
|
|
3357
|
-
return new CompositePipeline2(queryPipelines);
|
|
3358
|
-
});
|
|
3475
|
+
const { HttpUtils: HttpUtils2 } = await Promise.resolve().then(() => (init_http_utils(), http_utils_exports));
|
|
3476
|
+
await HttpUtils2.addAxios(container, opts.http);
|
|
3477
|
+
await HttpUtils2.addResilience(container, opts.resilience);
|
|
3359
3478
|
}
|
|
3360
3479
|
};
|
|
3361
3480
|
}
|
|
@@ -3654,7 +3773,7 @@ var init_composite_middleware = __esm({
|
|
|
3654
3773
|
});
|
|
3655
3774
|
|
|
3656
3775
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3657
|
-
import { Guards as
|
|
3776
|
+
import { Guards as Guards37 } from "@xeno-js/shared";
|
|
3658
3777
|
var CORSMiddleware;
|
|
3659
3778
|
var init_cors_middleware = __esm({
|
|
3660
3779
|
"src/presentation/middlewares/cors.middleware.ts"() {
|
|
@@ -3670,7 +3789,7 @@ var init_cors_middleware = __esm({
|
|
|
3670
3789
|
const { network } = this._requestContext.getContext() ?? {};
|
|
3671
3790
|
const origin = network?.origin;
|
|
3672
3791
|
const response = await next();
|
|
3673
|
-
if (
|
|
3792
|
+
if (Guards37.isDefined(origin))
|
|
3674
3793
|
response.headers = {
|
|
3675
3794
|
...response.headers ?? {},
|
|
3676
3795
|
"Access-Control-Allow-Origin": origin,
|
|
@@ -3687,7 +3806,7 @@ var init_cors_middleware = __esm({
|
|
|
3687
3806
|
import {
|
|
3688
3807
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES5,
|
|
3689
3808
|
ERROR_CODES as ERROR_CODES6,
|
|
3690
|
-
Guards as
|
|
3809
|
+
Guards as Guards38,
|
|
3691
3810
|
GuidHelper as GuidHelper9,
|
|
3692
3811
|
HttpHelper as HttpHelper6,
|
|
3693
3812
|
STATUS_CODES as STATUS_CODES7
|
|
@@ -3710,7 +3829,7 @@ var init_csrf_middleware = __esm({
|
|
|
3710
3829
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3711
3830
|
const headerToken = network?.csrf;
|
|
3712
3831
|
const cookieToken = network?.csrfCookie;
|
|
3713
|
-
if (!
|
|
3832
|
+
if (!Guards38.isDefined(headerToken) || !Guards38.isDefined(cookieToken)) {
|
|
3714
3833
|
return HttpHelper6.error(
|
|
3715
3834
|
{
|
|
3716
3835
|
success: false,
|
|
@@ -3752,7 +3871,7 @@ var init_csrf_middleware = __esm({
|
|
|
3752
3871
|
}
|
|
3753
3872
|
);
|
|
3754
3873
|
}
|
|
3755
|
-
if (!
|
|
3874
|
+
if (!Guards38.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3756
3875
|
return HttpHelper6.error(
|
|
3757
3876
|
{
|
|
3758
3877
|
success: false,
|
|
@@ -3781,7 +3900,7 @@ var init_csrf_middleware = __esm({
|
|
|
3781
3900
|
});
|
|
3782
3901
|
|
|
3783
3902
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3784
|
-
import { Guards as
|
|
3903
|
+
import { Guards as Guards39 } from "@xeno-js/shared";
|
|
3785
3904
|
var CsrfCookieMiddleware;
|
|
3786
3905
|
var init_csrf_cookie_middleware = __esm({
|
|
3787
3906
|
"src/presentation/middlewares/csrf-cookie.middleware.ts"() {
|
|
@@ -3800,8 +3919,8 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3800
3919
|
const context = this._requestContext.getContext();
|
|
3801
3920
|
const identity = context?.identity;
|
|
3802
3921
|
const network = context?.network;
|
|
3803
|
-
if (!
|
|
3804
|
-
if (
|
|
3922
|
+
if (!Guards39.isDefined(identity?.userId)) return response;
|
|
3923
|
+
if (Guards39.isDefined(network?.csrfCookie)) return response;
|
|
3805
3924
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3806
3925
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3807
3926
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3819,7 +3938,7 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3819
3938
|
});
|
|
3820
3939
|
|
|
3821
3940
|
// src/presentation/middlewares/options.middleware.ts
|
|
3822
|
-
import { Guards as
|
|
3941
|
+
import { Guards as Guards40, HttpHelper as HttpHelper7, STATUS_CODES as STATUS_CODES8 } from "@xeno-js/shared";
|
|
3823
3942
|
var OptionsMiddleware;
|
|
3824
3943
|
var init_options_middleware = __esm({
|
|
3825
3944
|
"src/presentation/middlewares/options.middleware.ts"() {
|
|
@@ -3840,7 +3959,7 @@ var init_options_middleware = __esm({
|
|
|
3840
3959
|
const network = this._requestContext.getNetworkContext();
|
|
3841
3960
|
const origin = network?.origin;
|
|
3842
3961
|
const headers = {};
|
|
3843
|
-
if (
|
|
3962
|
+
if (Guards40.isDefined(origin)) {
|
|
3844
3963
|
headers["Access-Control-Allow-Origin"] = origin;
|
|
3845
3964
|
headers["Access-Control-Allow-Credentials"] = this._withCredentials;
|
|
3846
3965
|
headers["Vary"] = "Origin";
|
|
@@ -3859,7 +3978,7 @@ var init_options_middleware = __esm({
|
|
|
3859
3978
|
import {
|
|
3860
3979
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES6,
|
|
3861
3980
|
ERROR_CODES as ERROR_CODES7,
|
|
3862
|
-
Guards as
|
|
3981
|
+
Guards as Guards41,
|
|
3863
3982
|
GuidHelper as GuidHelper10,
|
|
3864
3983
|
HttpHelper as HttpHelper8,
|
|
3865
3984
|
STATUS_CODES as STATUS_CODES9
|
|
@@ -3884,7 +4003,7 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3884
4003
|
async execute(req, _res, next) {
|
|
3885
4004
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3886
4005
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3887
|
-
if (!
|
|
4006
|
+
if (!Guards41.isDefined(cacheKey))
|
|
3888
4007
|
return HttpHelper8.error(
|
|
3889
4008
|
{
|
|
3890
4009
|
success: false,
|
|
@@ -3936,10 +4055,10 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3936
4055
|
});
|
|
3937
4056
|
|
|
3938
4057
|
// src/presentation/mappers/context.mapper.ts
|
|
3939
|
-
import { Guards as
|
|
4058
|
+
import { Guards as Guards42 } from "@xeno-js/shared";
|
|
3940
4059
|
function _buildMessagingContext(meta) {
|
|
3941
|
-
const hasSequenceData =
|
|
3942
|
-
const hasMessagingData = hasSequenceData ||
|
|
4060
|
+
const hasSequenceData = Guards42.isDefined(meta.sequence?.sequenceId) || Guards42.isDefined(meta.sequence?.position) || Guards42.isDefined(meta.sequence?.size);
|
|
4061
|
+
const hasMessagingData = hasSequenceData || Guards42.isDefined(meta.expiration) || Guards42.isDefined(meta.returnAddress);
|
|
3943
4062
|
const messaging = hasMessagingData ? {
|
|
3944
4063
|
returnAddress: meta.returnAddress,
|
|
3945
4064
|
expiration: meta.expiration,
|
|
@@ -4122,8 +4241,30 @@ var init_presentation = __esm({
|
|
|
4122
4241
|
}
|
|
4123
4242
|
});
|
|
4124
4243
|
|
|
4244
|
+
// src/infrastructure/cache/inmemory.cache.ts
|
|
4245
|
+
var inmemory_cache_exports = {};
|
|
4246
|
+
__export(inmemory_cache_exports, {
|
|
4247
|
+
InMemoryCacheExtended: () => InMemoryCacheExtended
|
|
4248
|
+
});
|
|
4249
|
+
import { Guards as Guards43, InMemoryCache } from "@xeno-js/shared";
|
|
4250
|
+
var InMemoryCacheExtended;
|
|
4251
|
+
var init_inmemory_cache = __esm({
|
|
4252
|
+
"src/infrastructure/cache/inmemory.cache.ts"() {
|
|
4253
|
+
"use strict";
|
|
4254
|
+
InMemoryCacheExtended = class extends InMemoryCache {
|
|
4255
|
+
async increment(key, ttlSeconds) {
|
|
4256
|
+
const current = await this.get(key) ?? 0;
|
|
4257
|
+
const next = Number(current) + 1;
|
|
4258
|
+
const ttl = Guards43.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
4259
|
+
await this.set(key, next, ttl);
|
|
4260
|
+
return next;
|
|
4261
|
+
}
|
|
4262
|
+
};
|
|
4263
|
+
}
|
|
4264
|
+
});
|
|
4265
|
+
|
|
4125
4266
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
4126
|
-
import { Guards as
|
|
4267
|
+
import { Guards as Guards44 } from "@xeno-js/shared";
|
|
4127
4268
|
var RateLimitKeyBuilder;
|
|
4128
4269
|
var init_rate_limit_key_builder_cache = __esm({
|
|
4129
4270
|
"src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
|
|
@@ -4138,12 +4279,12 @@ var init_rate_limit_key_builder_cache = __esm({
|
|
|
4138
4279
|
const tenantId = ctx?.identity?.tenantId;
|
|
4139
4280
|
const userId = ctx?.identity?.userId;
|
|
4140
4281
|
const clientIp = ctx?.network?.clientIp;
|
|
4141
|
-
if (!
|
|
4282
|
+
if (!Guards44.isNullOrEmpty(tenantId) && !Guards44.isNullOrEmpty(userId))
|
|
4142
4283
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
4143
|
-
if (!
|
|
4284
|
+
if (!Guards44.isNullOrEmpty(tenantId) && !Guards44.isNullOrEmpty(clientIp))
|
|
4144
4285
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
4145
|
-
if (!
|
|
4146
|
-
if (!
|
|
4286
|
+
if (!Guards44.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
4287
|
+
if (!Guards44.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
4147
4288
|
return void 0;
|
|
4148
4289
|
}
|
|
4149
4290
|
};
|
|
@@ -4177,7 +4318,7 @@ var init_middleware_module = __esm({
|
|
|
4177
4318
|
"use strict";
|
|
4178
4319
|
MiddlewareModule = class {
|
|
4179
4320
|
async configure(container, opts) {
|
|
4180
|
-
const { Guards:
|
|
4321
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4181
4322
|
const { HttpCookieExtractor: HttpCookieExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4182
4323
|
const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4183
4324
|
const tokenExtractor = await this._getTokenExtractor(
|
|
@@ -4186,7 +4327,7 @@ var init_middleware_module = __esm({
|
|
|
4186
4327
|
opts.customTokenExtractor
|
|
4187
4328
|
);
|
|
4188
4329
|
container.addSingleton(
|
|
4189
|
-
|
|
4330
|
+
TOKENS5.SERVICE_EXTRACTOR,
|
|
4190
4331
|
() => new HttpHeaderExtractor2(
|
|
4191
4332
|
tokenExtractor,
|
|
4192
4333
|
new HttpCookieExtractor2(),
|
|
@@ -4196,18 +4337,18 @@ var init_middleware_module = __esm({
|
|
|
4196
4337
|
);
|
|
4197
4338
|
const { ClientIpResolver: ClientIpResolver2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4198
4339
|
const middlewares = [];
|
|
4199
|
-
const requestContext = container.resolve(
|
|
4200
|
-
const logger = container.resolve(
|
|
4340
|
+
const requestContext = container.resolve(TOKENS5.REQUEST_CONTEXT);
|
|
4341
|
+
const logger = container.resolve(TOKENS5.LOGGER);
|
|
4201
4342
|
const { RequestContextMiddleware: RequestContextMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4202
4343
|
middlewares.push(
|
|
4203
4344
|
new RequestContextMiddleware2(
|
|
4204
4345
|
requestContext,
|
|
4205
|
-
container.resolve(
|
|
4346
|
+
container.resolve(TOKENS5.SERVICE_EXTRACTOR),
|
|
4206
4347
|
new ClientIpResolver2(opts.trustedProxies),
|
|
4207
4348
|
logger
|
|
4208
4349
|
)
|
|
4209
4350
|
);
|
|
4210
|
-
if (!
|
|
4351
|
+
if (!Guards49.isNullOrEmpty(opts.allowOrigins)) {
|
|
4211
4352
|
if (opts.withCredentials && opts.allowOrigins.includes("*"))
|
|
4212
4353
|
throw new Error(
|
|
4213
4354
|
"Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
|
|
@@ -4233,7 +4374,7 @@ var init_middleware_module = __esm({
|
|
|
4233
4374
|
const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4234
4375
|
middlewares.push(new CORSMiddleware2(requestContext, withCredentials));
|
|
4235
4376
|
}
|
|
4236
|
-
if (
|
|
4377
|
+
if (Guards49.isDefined(opts.routeRegistry)) {
|
|
4237
4378
|
const { MethodCheckMiddleware: MethodCheckMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4238
4379
|
middlewares.push(new MethodCheckMiddleware2(requestContext, allowMethod));
|
|
4239
4380
|
}
|
|
@@ -4255,31 +4396,31 @@ var init_middleware_module = __esm({
|
|
|
4255
4396
|
new AuthenticationMiddleware2(
|
|
4256
4397
|
requestContext,
|
|
4257
4398
|
tokenExtractor,
|
|
4258
|
-
new GateKeeper2(container.resolve(
|
|
4399
|
+
new GateKeeper2(container.resolve(TOKENS5.BASE_AUTH_SERVICE), new ClaimsIdentityMapper2()),
|
|
4259
4400
|
logger
|
|
4260
4401
|
)
|
|
4261
4402
|
);
|
|
4262
4403
|
}
|
|
4263
|
-
if (
|
|
4404
|
+
if (Guards49.isDefined(opts.rateLimite.maxRequests) || Guards49.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4264
4405
|
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4265
|
-
|
|
4266
|
-
|
|
4406
|
+
Guards49.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4407
|
+
Guards49.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4267
4408
|
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4268
|
-
|
|
4269
|
-
|
|
4409
|
+
Guards49.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4410
|
+
Guards49.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4270
4411
|
const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
|
|
4271
4412
|
const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4272
4413
|
middlewares.push(
|
|
4273
4414
|
new RateLimitMiddleware2(
|
|
4274
4415
|
requestContext,
|
|
4275
|
-
container.resolve(
|
|
4416
|
+
container.resolve(TOKENS5.CACHE),
|
|
4276
4417
|
new RateLimitKeyBuilder2(requestContext),
|
|
4277
4418
|
logger,
|
|
4278
4419
|
{ maxRequests, windowSeconds }
|
|
4279
4420
|
)
|
|
4280
4421
|
);
|
|
4281
4422
|
}
|
|
4282
|
-
if (
|
|
4423
|
+
if (Guards49.isDefined(opts.csrf)) {
|
|
4283
4424
|
const csrf = opts.csrf;
|
|
4284
4425
|
const { EdgeCryptoService: EdgeCryptoService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4285
4426
|
container.addSingleton("CRYPTO_SERVICE", () => new EdgeCryptoService2());
|
|
@@ -4299,13 +4440,13 @@ var init_middleware_module = __esm({
|
|
|
4299
4440
|
middlewares.push(new CsrfMiddleware2(requestContext, container.resolve("CSRF_TOKEN_SERVICE")));
|
|
4300
4441
|
}
|
|
4301
4442
|
const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4302
|
-
container.addSingleton(
|
|
4443
|
+
container.addSingleton(TOKENS5.MIDDLEWARE, () => {
|
|
4303
4444
|
return new CompositeMiddleware2(middlewares);
|
|
4304
4445
|
});
|
|
4305
4446
|
}
|
|
4306
4447
|
async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
|
|
4307
|
-
const { Guards:
|
|
4308
|
-
if (
|
|
4448
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
4449
|
+
if (Guards49.isDefined(customTokenExtractor)) return customTokenExtractor();
|
|
4309
4450
|
if (isSSR) {
|
|
4310
4451
|
const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4311
4452
|
return new SupabaseSsrTokenExtractor2();
|
|
@@ -4315,8 +4456,8 @@ var init_middleware_module = __esm({
|
|
|
4315
4456
|
}
|
|
4316
4457
|
}
|
|
4317
4458
|
async _getAllowMethod(configure, opts) {
|
|
4318
|
-
const { Guards:
|
|
4319
|
-
if (!configure || !
|
|
4459
|
+
const { Guards: Guards49 } = await import("@xeno-js/shared");
|
|
4460
|
+
if (!configure || !Guards49.isDefined(opts)) return void 0;
|
|
4320
4461
|
const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
4321
4462
|
return new AllowMethodFactory2().create(opts);
|
|
4322
4463
|
}
|
|
@@ -4324,37 +4465,203 @@ var init_middleware_module = __esm({
|
|
|
4324
4465
|
}
|
|
4325
4466
|
});
|
|
4326
4467
|
|
|
4327
|
-
// src/infrastructure/modules/
|
|
4328
|
-
var
|
|
4329
|
-
__export(
|
|
4330
|
-
|
|
4468
|
+
// src/infrastructure/modules/utils/cache.utils.ts
|
|
4469
|
+
var cache_utils_exports = {};
|
|
4470
|
+
__export(cache_utils_exports, {
|
|
4471
|
+
CacheUtils: () => CacheUtils
|
|
4331
4472
|
});
|
|
4332
|
-
var
|
|
4333
|
-
var
|
|
4334
|
-
"src/infrastructure/modules/
|
|
4473
|
+
var CacheUtils;
|
|
4474
|
+
var init_cache_utils = __esm({
|
|
4475
|
+
"src/infrastructure/modules/utils/cache.utils.ts"() {
|
|
4335
4476
|
"use strict";
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
const {
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4477
|
+
CacheUtils = Object.freeze({
|
|
4478
|
+
/**
|
|
4479
|
+
* @description Checks if the provided cache configuration requires any cache strategies.
|
|
4480
|
+
* @param container The service container to which the cache strategies will be added.
|
|
4481
|
+
* @param opts The cache configuration options.
|
|
4482
|
+
* @returns True if any cache strategies are required, false otherwise.
|
|
4483
|
+
*
|
|
4484
|
+
* @author Xeno
|
|
4485
|
+
* @version 1.0.0
|
|
4486
|
+
* @since 2025-09-30
|
|
4487
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
4488
|
+
*/
|
|
4489
|
+
async addCache(container, opts) {
|
|
4490
|
+
const { Guards: Guards49, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4491
|
+
if (!opts.inMemory && !Guards49.isDefined(opts.redis)) {
|
|
4492
|
+
throw new Error(
|
|
4493
|
+
"No cache strategies are configured. Please provide at least one cache strategy."
|
|
4494
|
+
);
|
|
4495
|
+
}
|
|
4496
|
+
const { CacheKeyBuilder } = await import("@xeno-js/shared");
|
|
4497
|
+
container.addSingleton(
|
|
4498
|
+
TOKENS5.CACHE_KEY_BUILDER,
|
|
4499
|
+
(c) => new CacheKeyBuilder(c.resolve(TOKENS5.IDENTITY_ACCESSOR))
|
|
4500
|
+
);
|
|
4501
|
+
if (opts.inMemory || !Guards49.isDefined(opts.redis)) {
|
|
4502
|
+
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
4503
|
+
container.addSingleton(TOKENS5.CACHE, () => new InMemoryCacheExtended2());
|
|
4504
|
+
return;
|
|
4505
|
+
}
|
|
4506
|
+
if (Guards49.isDefined(opts.redis)) {
|
|
4507
|
+
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
4508
|
+
container.addSingleton(TOKENS5.CACHE, () => {
|
|
4509
|
+
const config = opts.redis;
|
|
4510
|
+
return new RedisCacheFactory2().create(config);
|
|
4511
|
+
});
|
|
4512
|
+
}
|
|
4513
|
+
}
|
|
4514
|
+
});
|
|
4515
|
+
}
|
|
4516
|
+
});
|
|
4517
|
+
|
|
4518
|
+
// src/infrastructure/loggers/console.logger.ts
|
|
4519
|
+
var console_logger_exports = {};
|
|
4520
|
+
__export(console_logger_exports, {
|
|
4521
|
+
ConsoleLogger: () => ConsoleLogger
|
|
4522
|
+
});
|
|
4523
|
+
import { Guards as Guards45, LOG_LEVEL as LOG_LEVEL5 } from "@xeno-js/shared";
|
|
4524
|
+
var ConsoleLogger;
|
|
4525
|
+
var init_console_logger = __esm({
|
|
4526
|
+
"src/infrastructure/loggers/console.logger.ts"() {
|
|
4527
|
+
"use strict";
|
|
4528
|
+
ConsoleLogger = class {
|
|
4529
|
+
/**
|
|
4530
|
+
* 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.
|
|
4531
|
+
* @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.
|
|
4532
|
+
|
|
4533
|
+
*
|
|
4534
|
+
* @author Xeno
|
|
4535
|
+
* @version 1.0.0
|
|
4536
|
+
* @since 2025-09-30
|
|
4537
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
4538
|
+
*/
|
|
4539
|
+
constructor(_minLevel = LOG_LEVEL5.DEBUG) {
|
|
4540
|
+
this._minLevel = _minLevel;
|
|
4541
|
+
}
|
|
4542
|
+
_minLevel;
|
|
4543
|
+
track(level, message, context, error = void 0) {
|
|
4544
|
+
if (level < this._minLevel) return;
|
|
4545
|
+
const logMessage = `[${level}] ${message}`;
|
|
4546
|
+
const payload = Guards45.isDefined(error) ? { ...context, error } : context;
|
|
4547
|
+
switch (level) {
|
|
4548
|
+
case LOG_LEVEL5.ERROR:
|
|
4549
|
+
console.error(logMessage, payload ?? {});
|
|
4550
|
+
break;
|
|
4551
|
+
case LOG_LEVEL5.WARN:
|
|
4552
|
+
console.warn(logMessage, payload ?? {});
|
|
4553
|
+
break;
|
|
4554
|
+
case LOG_LEVEL5.DEBUG:
|
|
4555
|
+
console.debug(logMessage, payload ?? {});
|
|
4556
|
+
break;
|
|
4557
|
+
default:
|
|
4558
|
+
console.info(logMessage, payload ?? {});
|
|
4559
|
+
break;
|
|
4560
|
+
}
|
|
4353
4561
|
}
|
|
4354
4562
|
};
|
|
4355
4563
|
}
|
|
4356
4564
|
});
|
|
4357
4565
|
|
|
4566
|
+
// src/infrastructure/modules/utils/logger.utils.ts
|
|
4567
|
+
var logger_utils_exports = {};
|
|
4568
|
+
__export(logger_utils_exports, {
|
|
4569
|
+
LoggerUtils: () => LoggerUtils
|
|
4570
|
+
});
|
|
4571
|
+
var LoggerUtils;
|
|
4572
|
+
var init_logger_utils = __esm({
|
|
4573
|
+
"src/infrastructure/modules/utils/logger.utils.ts"() {
|
|
4574
|
+
"use strict";
|
|
4575
|
+
LoggerUtils = Object.freeze({
|
|
4576
|
+
/**
|
|
4577
|
+
* @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.
|
|
4578
|
+
*
|
|
4579
|
+
* @param container - The service container to register logging services with.
|
|
4580
|
+
* @param opts - The LoggerConfig options to determine which loggers to enable and their configurations.
|
|
4581
|
+
|
|
4582
|
+
*
|
|
4583
|
+
* @author Xeno
|
|
4584
|
+
* @version 1.0.0
|
|
4585
|
+
* @since 2025-09-30
|
|
4586
|
+
* @link https://github.com/xeno-js/xeno-js
|
|
4587
|
+
*/
|
|
4588
|
+
async addLogger(container, opts) {
|
|
4589
|
+
const loggerDependencies = [];
|
|
4590
|
+
const { Guards: Guards49, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4591
|
+
if (!Guards49.isDefined(opts) || opts.console) {
|
|
4592
|
+
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
4593
|
+
loggerDependencies.push(new ConsoleLogger2(opts?.level));
|
|
4594
|
+
}
|
|
4595
|
+
if (Guards49.isDefined(opts)) {
|
|
4596
|
+
if (Guards49.isDefined(opts.sentry.config)) {
|
|
4597
|
+
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
4598
|
+
loggerDependencies.push(new SentryLoggerFactory2().create(opts));
|
|
4599
|
+
}
|
|
4600
|
+
if (Guards49.isDefined(opts.pino.config)) {
|
|
4601
|
+
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
4602
|
+
loggerDependencies.push(new PinoLoggerFactory2().create(opts));
|
|
4603
|
+
}
|
|
4604
|
+
if (!Guards49.isNullOrEmpty(opts.customLoggers)) {
|
|
4605
|
+
const customLoggers = opts.customLoggers;
|
|
4606
|
+
customLoggers.forEach((fn) => {
|
|
4607
|
+
if (Guards49.isDefined(fn)) loggerDependencies.push(fn(container));
|
|
4608
|
+
});
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
const { BaseLogger } = await import("@xeno-js/shared");
|
|
4612
|
+
container.addSingleton(TOKENS5.LOGGER, (c) => {
|
|
4613
|
+
const context = c.resolve(TOKENS5.CONTEXT_ACCESSOR);
|
|
4614
|
+
return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, loggerDependencies);
|
|
4615
|
+
});
|
|
4616
|
+
}
|
|
4617
|
+
});
|
|
4618
|
+
}
|
|
4619
|
+
});
|
|
4620
|
+
|
|
4621
|
+
// src/infrastructure/modules/utils/index.ts
|
|
4622
|
+
var init_utils2 = __esm({
|
|
4623
|
+
"src/infrastructure/modules/utils/index.ts"() {
|
|
4624
|
+
"use strict";
|
|
4625
|
+
init_auth_utils();
|
|
4626
|
+
init_cache_utils();
|
|
4627
|
+
init_db_utils();
|
|
4628
|
+
init_http_utils();
|
|
4629
|
+
init_logger_utils();
|
|
4630
|
+
init_pipeline_utils();
|
|
4631
|
+
init_validation_utils();
|
|
4632
|
+
}
|
|
4633
|
+
});
|
|
4634
|
+
|
|
4635
|
+
// src/infrastructure/modules/index.ts
|
|
4636
|
+
var modules_exports = {};
|
|
4637
|
+
__export(modules_exports, {
|
|
4638
|
+
AuthUtils: () => AuthUtils,
|
|
4639
|
+
CacheUtils: () => CacheUtils,
|
|
4640
|
+
ContextModule: () => ContextModule,
|
|
4641
|
+
CqrsModule: () => CqrsModule,
|
|
4642
|
+
DbModule: () => DbModule,
|
|
4643
|
+
DbUtils: () => DbUtils,
|
|
4644
|
+
HttpAdapterModule: () => HttpAdapterModule,
|
|
4645
|
+
HttpCoreModule: () => HttpCoreModule,
|
|
4646
|
+
HttpUtils: () => HttpUtils,
|
|
4647
|
+
LoggerUtils: () => LoggerUtils,
|
|
4648
|
+
MiddlewareModule: () => MiddlewareModule,
|
|
4649
|
+
PipelineUtils: () => PipelineUtils,
|
|
4650
|
+
ValidationUtils: () => ValidationUtils
|
|
4651
|
+
});
|
|
4652
|
+
var init_modules = __esm({
|
|
4653
|
+
"src/infrastructure/modules/index.ts"() {
|
|
4654
|
+
"use strict";
|
|
4655
|
+
init_context_module();
|
|
4656
|
+
init_cqrs_module();
|
|
4657
|
+
init_db_module();
|
|
4658
|
+
init_http_adapter_module();
|
|
4659
|
+
init_http_core_module();
|
|
4660
|
+
init_middleware_module();
|
|
4661
|
+
init_utils2();
|
|
4662
|
+
}
|
|
4663
|
+
});
|
|
4664
|
+
|
|
4358
4665
|
// src/index.ts
|
|
4359
4666
|
var index_exports = {};
|
|
4360
4667
|
__export(index_exports, {
|
|
@@ -4374,7 +4681,7 @@ __export(index_exports, {
|
|
|
4374
4681
|
init_application();
|
|
4375
4682
|
|
|
4376
4683
|
// src/infrastructure/builder/app.builder.ts
|
|
4377
|
-
import { Guards as
|
|
4684
|
+
import { Guards as Guards46, LOG_LEVEL as LOG_LEVEL6, TOKENS as TOKENS4 } from "@xeno-js/shared";
|
|
4378
4685
|
|
|
4379
4686
|
// src/infrastructure/configuration/configuration.ts
|
|
4380
4687
|
import { Guards as Guards13 } from "@xeno-js/shared";
|
|
@@ -4653,17 +4960,24 @@ var AppBuilder = class {
|
|
|
4653
4960
|
constructor(container) {
|
|
4654
4961
|
this._container = container ?? new ServiceContainer();
|
|
4655
4962
|
this._container.addSingleton(
|
|
4656
|
-
|
|
4963
|
+
TOKENS4.CONFIGURATION_SERVICE,
|
|
4657
4964
|
() => new EnvironmentConfigurationService()
|
|
4658
4965
|
);
|
|
4659
|
-
this._configuration = this._container.resolve(
|
|
4966
|
+
this._configuration = this._container.resolve(TOKENS4.CONFIGURATION_SERVICE);
|
|
4660
4967
|
this._middlewareConfig.allowOrigins?.push(
|
|
4661
4968
|
this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
|
|
4662
4969
|
);
|
|
4970
|
+
this.addContext();
|
|
4663
4971
|
}
|
|
4664
4972
|
// --- Module Configurations ---
|
|
4665
4973
|
_modules = [];
|
|
4666
4974
|
// --- Specific Configurations ---
|
|
4975
|
+
_adapterConfig = {
|
|
4976
|
+
native: true,
|
|
4977
|
+
vercel: false,
|
|
4978
|
+
fastify: false,
|
|
4979
|
+
custom: void 0
|
|
4980
|
+
};
|
|
4667
4981
|
_pipelineConfig = {
|
|
4668
4982
|
performance: { thresholdMs: 500 },
|
|
4669
4983
|
authorization: {
|
|
@@ -4705,7 +5019,13 @@ var AppBuilder = class {
|
|
|
4705
5019
|
redirectTo: "",
|
|
4706
5020
|
storageOpts: { type: "memory", cookieOpts: void 0, storage: void 0 },
|
|
4707
5021
|
ssrOpts: void 0,
|
|
4708
|
-
customAuth: void 0
|
|
5022
|
+
customAuth: void 0,
|
|
5023
|
+
cookieOpts: {
|
|
5024
|
+
path: "/",
|
|
5025
|
+
httpOnly: true,
|
|
5026
|
+
sameSite: "lax",
|
|
5027
|
+
secure: true
|
|
5028
|
+
}
|
|
4709
5029
|
};
|
|
4710
5030
|
_httpConfig = {
|
|
4711
5031
|
dataSourceToken: void 0,
|
|
@@ -4741,9 +5061,24 @@ var AppBuilder = class {
|
|
|
4741
5061
|
_isDbContextModuleQueued = false;
|
|
4742
5062
|
_isConcurrencyServiceQueued = false;
|
|
4743
5063
|
_isCacheModuleQueued = false;
|
|
5064
|
+
_isAdapterModuleQueued = false;
|
|
4744
5065
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
4745
5066
|
// Application Modules Configuration
|
|
4746
5067
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
5068
|
+
addAdapter(setupAction) {
|
|
5069
|
+
if (this._isAdapterModuleQueued) return this;
|
|
5070
|
+
setupAction(this._adapterConfig, this._configuration);
|
|
5071
|
+
this._isAdapterModuleQueued = true;
|
|
5072
|
+
this._modules.push({
|
|
5073
|
+
priority: 50,
|
|
5074
|
+
name: "AdapterModule",
|
|
5075
|
+
action: async () => {
|
|
5076
|
+
const { HttpAdapterModule: HttpAdapterModule2 } = await Promise.resolve().then(() => (init_modules(), modules_exports));
|
|
5077
|
+
await new HttpAdapterModule2().configure(this._container, this._adapterConfig);
|
|
5078
|
+
}
|
|
5079
|
+
});
|
|
5080
|
+
return this;
|
|
5081
|
+
}
|
|
4747
5082
|
/**
|
|
4748
5083
|
* @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.
|
|
4749
5084
|
* @returns The current instance of AppBuilder for method chaining.
|
|
@@ -4784,7 +5119,7 @@ var AppBuilder = class {
|
|
|
4784
5119
|
* @link https://github.com/xeno-js/xeno-js
|
|
4785
5120
|
*/
|
|
4786
5121
|
addLogger(setupAction) {
|
|
4787
|
-
if (
|
|
5122
|
+
if (Guards46.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
|
|
4788
5123
|
if (this._isLoggerModuleQueued) return this;
|
|
4789
5124
|
this._isLoggerModuleQueued = true;
|
|
4790
5125
|
this._modules.push({
|
|
@@ -4809,7 +5144,7 @@ var AppBuilder = class {
|
|
|
4809
5144
|
* @link https://github.com/xeno-js/xeno-js
|
|
4810
5145
|
*/
|
|
4811
5146
|
addCache(setupAction) {
|
|
4812
|
-
if (
|
|
5147
|
+
if (Guards46.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
4813
5148
|
if (this._isCacheModuleQueued) return this;
|
|
4814
5149
|
this._isCacheModuleQueued = true;
|
|
4815
5150
|
this._modules.push({
|
|
@@ -4912,7 +5247,7 @@ var AppBuilder = class {
|
|
|
4912
5247
|
* @link https://github.com/xeno-js/xeno-js
|
|
4913
5248
|
*/
|
|
4914
5249
|
addPipeline(setupAction) {
|
|
4915
|
-
if (
|
|
5250
|
+
if (Guards46.isDefined(setupAction)) {
|
|
4916
5251
|
setupAction(this._pipelineConfig, this._configuration);
|
|
4917
5252
|
}
|
|
4918
5253
|
this._queuePipelineModule();
|
|
@@ -5033,7 +5368,7 @@ var AppBuilder = class {
|
|
|
5033
5368
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
5034
5369
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
5035
5370
|
`);
|
|
5036
|
-
if (error instanceof Error &&
|
|
5371
|
+
if (error instanceof Error && Guards46.isDefined(error.stack)) {
|
|
5037
5372
|
console.error(error.stack);
|
|
5038
5373
|
}
|
|
5039
5374
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5172,25 +5507,12 @@ init_console_logger();
|
|
|
5172
5507
|
init_pino_logger();
|
|
5173
5508
|
init_sentry_logger();
|
|
5174
5509
|
|
|
5175
|
-
// src/infrastructure/
|
|
5176
|
-
|
|
5177
|
-
init_cqrs_module();
|
|
5178
|
-
init_db_module();
|
|
5179
|
-
init_http_core_module();
|
|
5180
|
-
init_middleware_module();
|
|
5181
|
-
|
|
5182
|
-
// src/infrastructure/modules/utils/index.ts
|
|
5183
|
-
init_auth_utils();
|
|
5184
|
-
init_cache_utils();
|
|
5185
|
-
init_db_utils();
|
|
5186
|
-
init_http_utils();
|
|
5187
|
-
init_logger_utils();
|
|
5188
|
-
init_pipeline_utils();
|
|
5189
|
-
init_validation_utils();
|
|
5510
|
+
// src/infrastructure/index.ts
|
|
5511
|
+
init_modules();
|
|
5190
5512
|
|
|
5191
5513
|
// src/infrastructure/repositories/read-dao.ts
|
|
5192
5514
|
import { AppError as AppError16, Result as Result17 } from "@xeno-js/shared";
|
|
5193
|
-
import { Guards as
|
|
5515
|
+
import { Guards as Guards47 } from "@xeno-js/shared";
|
|
5194
5516
|
var ReadDao = class {
|
|
5195
5517
|
/**
|
|
5196
5518
|
* Constructs a new ReadDao instance.
|
|
@@ -5212,7 +5534,7 @@ var ReadDao = class {
|
|
|
5212
5534
|
async findById(id, ctx, signal) {
|
|
5213
5535
|
AppError16.throwIfAborted(signal, "ReadDao.findById");
|
|
5214
5536
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5215
|
-
if (
|
|
5537
|
+
if (Guards47.isNullOrEmpty(result)) return Result17.ok();
|
|
5216
5538
|
const entity = this._mapper.toEntity(result);
|
|
5217
5539
|
return Result17.ok(entity);
|
|
5218
5540
|
}
|
|
@@ -5226,7 +5548,7 @@ var ReadDao = class {
|
|
|
5226
5548
|
|
|
5227
5549
|
// src/infrastructure/repositories/repository.ts
|
|
5228
5550
|
import { AppError as AppError17, Result as Result18 } from "@xeno-js/shared";
|
|
5229
|
-
import { Guards as
|
|
5551
|
+
import { Guards as Guards48 } from "@xeno-js/shared";
|
|
5230
5552
|
var Repository = class {
|
|
5231
5553
|
/**
|
|
5232
5554
|
* Constructs a new Repository instance.
|
|
@@ -5248,7 +5570,7 @@ var Repository = class {
|
|
|
5248
5570
|
async findById(id, ctx, signal) {
|
|
5249
5571
|
AppError17.throwIfAborted(signal, "Repository.findById");
|
|
5250
5572
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5251
|
-
if (
|
|
5573
|
+
if (Guards48.isNullOrEmpty(result)) return Result18.ok();
|
|
5252
5574
|
const entity = this._mapper.toEntity(result);
|
|
5253
5575
|
return Result18.ok(entity);
|
|
5254
5576
|
}
|