@xeno-js/core 1.2.12 → 2.0.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/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
2
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
3
  var __esm = (fn, res) => function __init() {
6
4
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
7
5
  };
@@ -9,15 +7,6 @@ var __export = (target, all) => {
9
7
  for (var name in all)
10
8
  __defProp(target, name, { get: all[name], enumerable: true });
11
9
  };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
10
 
22
11
  // src/application/containers/container.utils.ts
23
12
  import { Guards, TOKENS } from "@xeno-js/shared";
@@ -2058,646 +2047,73 @@ var init_services = __esm({
2058
2047
  }
2059
2048
  });
2060
2049
 
2061
- // src/infrastructure/factories/allow-method.factory.ts
2062
- var AllowMethodFactory;
2063
- var init_allow_method_factory = __esm({
2064
- "src/infrastructure/factories/allow-method.factory.ts"() {
2065
- "use strict";
2066
- init_services();
2067
- AllowMethodFactory = class {
2068
- create(opts) {
2069
- const allowMethodService = new AllowMethodRegistry();
2070
- for (const [intentKey, schema] of Object.entries(opts)) {
2071
- allowMethodService.add(intentKey, schema);
2072
- }
2073
- return allowMethodService;
2074
- }
2075
- };
2076
- }
2077
- });
2078
-
2079
- // src/infrastructure/factories/axios.factory.ts
2080
- import http from "http";
2081
- import https from "https";
2082
- import { AxiosHttpClient } from "@xeno-js/shared";
2083
- import axios from "axios";
2084
- var NodeAxiosFactory;
2085
- var init_axios_factory = __esm({
2086
- "src/infrastructure/factories/axios.factory.ts"() {
2087
- "use strict";
2088
- NodeAxiosFactory = class {
2089
- create(config) {
2090
- const isKeepAlive = config.keepAlive ?? true;
2091
- const maxSockets = config.maxSockets ?? 100;
2092
- const httpAgent = new http.Agent({
2093
- keepAlive: isKeepAlive,
2094
- maxSockets,
2095
- scheduling: "lifo"
2096
- });
2097
- const httpsAgent = new https.Agent({
2098
- keepAlive: isKeepAlive,
2099
- maxSockets,
2100
- scheduling: "lifo"
2101
- });
2102
- const axiosInstance = axios.create({
2103
- baseURL: config.baseURL,
2104
- headers: config.defaultHeaders,
2105
- timeout: config.timeoutMs,
2106
- httpAgent,
2107
- httpsAgent,
2108
- maxRedirects: config.maxRedirects ?? 5,
2109
- decompress: config.decompress ?? true,
2110
- proxy: config.proxy,
2111
- withCredentials: config.withCredentials
2112
- });
2113
- return new AxiosHttpClient(axiosInstance);
2114
- }
2115
- };
2116
- }
2050
+ // src/infrastructure/factories/supabase.factory.ts
2051
+ var supabase_factory_exports = {};
2052
+ __export(supabase_factory_exports, {
2053
+ SupabaseServerAuthFactory: () => SupabaseServerAuthFactory
2117
2054
  });
2118
-
2119
- // src/infrastructure/factories/cockatiel-resilience.factory.ts
2120
- import { AppError as AppError13, Guards as Guards27, RESILIENCE_DEFAULTS } from "@xeno-js/shared";
2055
+ import { createServerClient } from "@supabase/ssr";
2056
+ import { Guards as Guards27, TOKENS as TOKENS3 } from "@xeno-js/shared";
2121
2057
  import {
2122
- bulkhead,
2123
- circuitBreaker,
2124
- ConsecutiveBreaker,
2125
- ExponentialBackoff,
2126
- handleWhen,
2127
- retry,
2128
- wrap
2129
- } from "cockatiel";
2130
- var CockatielResilienceFactory;
2131
- var init_cockatiel_resilience_factory = __esm({
2132
- "src/infrastructure/factories/cockatiel-resilience.factory.ts"() {
2058
+ SupabaseAuthService,
2059
+ SupabaseClaimsMapper,
2060
+ SupabaseSessionMapper
2061
+ } from "@xeno-js/shared/supabase";
2062
+ var SupabaseServerAuthFactory;
2063
+ var init_supabase_factory = __esm({
2064
+ "src/infrastructure/factories/supabase.factory.ts"() {
2133
2065
  "use strict";
2134
- init_resilience_service();
2135
- CockatielResilienceFactory = class {
2136
- create(config) {
2137
- const message = "The resilience configuration provided is invalid. Please ensure that all values are non-negative numbers.";
2138
- const normalizedConfig = {
2139
- retry: {
2140
- attempts: this.checkConfigValue(
2141
- config.retry.attempts,
2142
- RESILIENCE_DEFAULTS.RETRY.ATTEMPTS,
2143
- message
2144
- ),
2145
- baseDelayMs: this.checkConfigValue(
2146
- config.retry.baseDelayMs,
2147
- RESILIENCE_DEFAULTS.RETRY.BASE_DELAY_MS,
2148
- message
2149
- ),
2150
- maxDelayMs: this.checkConfigValue(
2151
- config.retry.maxDelayMs,
2152
- RESILIENCE_DEFAULTS.RETRY.MAX_DELAY_MS,
2153
- message
2154
- )
2155
- },
2156
- circuitBreaker: {
2157
- consecutiveFailures: this.checkConfigValue(
2158
- config.circuitBreaker.consecutiveFailures,
2159
- RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.CONSECUTIVE_FAILURES,
2160
- message
2161
- ),
2162
- halfOpenTimeoutMs: this.checkConfigValue(
2163
- config.circuitBreaker.halfOpenTimeoutMs,
2164
- RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.HALF_OPEN_TIMEOUT_MS,
2165
- message
2166
- )
2167
- },
2168
- bulkhead: {
2169
- maxConcurrent: this.checkConfigValue(
2170
- config.bulkhead.maxConcurrent,
2171
- RESILIENCE_DEFAULTS.BULKHEAD.MAX_CONCURRENT,
2172
- message
2173
- )
2174
- }
2175
- };
2176
- const retryPolicy = retry(
2177
- handleWhen((error) => this.isTransientAndIdempotent(error)),
2178
- {
2179
- maxAttempts: normalizedConfig.retry.attempts,
2180
- backoff: new ExponentialBackoff({
2181
- initialDelay: normalizedConfig.retry.baseDelayMs,
2182
- maxDelay: normalizedConfig.retry.maxDelayMs
2183
- })
2184
- }
2185
- );
2186
- const circuitBreakerPolicy = circuitBreaker(
2187
- handleWhen((error) => this.isTransientError(error)),
2188
- {
2189
- breaker: new ConsecutiveBreaker(normalizedConfig.circuitBreaker.consecutiveFailures),
2190
- halfOpenAfter: normalizedConfig.circuitBreaker.halfOpenTimeoutMs
2191
- }
2192
- );
2193
- const bulkheadPolicy = bulkhead(normalizedConfig.bulkhead.maxConcurrent);
2194
- return new ServiceResilience(wrap(bulkheadPolicy, circuitBreakerPolicy, retryPolicy));
2195
- }
2196
- isTransientError(error) {
2197
- if (!Guards27.isDefined(error) || !Guards27.isObject(error)) return false;
2198
- let status;
2199
- let isNetworkError = false;
2200
- if (error instanceof AppError13) {
2201
- status = error.status;
2202
- const cause = error.cause;
2203
- if (Guards27.isDefined(cause) && Guards27.isString(cause.code)) {
2204
- isNetworkError = [
2205
- "ECONNABORTED",
2206
- "ECONNRESET",
2207
- "ETIMEDOUT",
2208
- "ENOTFOUND",
2209
- "ECONNREFUSED"
2210
- ].includes(cause.code.toUpperCase());
2211
- }
2212
- } else {
2213
- const err = error;
2214
- status = err.status;
2215
- if (Guards27.isString(err.code)) {
2216
- isNetworkError = [
2217
- "ECONNABORTED",
2218
- "ECONNRESET",
2219
- "ETIMEDOUT",
2220
- "ENOTFOUND",
2221
- "ECONNREFUSED"
2222
- ].includes(err.code.toUpperCase());
2066
+ init_services();
2067
+ SupabaseServerAuthFactory = class {
2068
+ create({
2069
+ config,
2070
+ container
2071
+ }) {
2072
+ const cookieService = this._getCookieSsr(config.ssrOpts, container, config.cookieOpts);
2073
+ const client = createServerClient(config.url, config.key, {
2074
+ ...config.opts,
2075
+ cookies: {
2076
+ getAll() {
2077
+ return cookieService.getAll();
2078
+ },
2079
+ setAll(cookiesToSet) {
2080
+ cookieService.setAll(cookiesToSet);
2081
+ }
2223
2082
  }
2224
- }
2225
- if (isNetworkError) return true;
2226
- if (Guards27.isDefined(status)) return status === 408 || status >= 500 && status < 600;
2227
- return false;
2083
+ });
2084
+ const mapper = new SupabaseClaimsMapper();
2085
+ const sessionMapper = new SupabaseSessionMapper(mapper);
2086
+ return new SupabaseAuthService(client, mapper, sessionMapper, config);
2228
2087
  }
2229
- isTransientAndIdempotent(error) {
2230
- if (!this.isTransientError(error)) return false;
2231
- let method;
2232
- if (error instanceof AppError13) {
2233
- const cause = error.cause;
2234
- if (Guards27.isDefined(cause) && Guards27.isDefined(cause.config) && Guards27.isString(cause.config.method)) {
2235
- method = cause.config.method.toUpperCase();
2236
- }
2088
+ _getCookieSsr(ssrOpts, container, config) {
2089
+ if (Guards27.isDefined(ssrOpts)) {
2090
+ return ssrOpts(container);
2237
2091
  } else {
2238
- const err = error;
2239
- if (Guards27.isDefined(err.config) && Guards27.isString(err.config.method)) {
2240
- method = err.config.method.toUpperCase();
2241
- }
2242
- }
2243
- if (Guards27.isNullOrEmpty(method)) return false;
2244
- const idempotentMethods = ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
2245
- return idempotentMethods.includes(method);
2246
- }
2247
- checkConfigValue(value, defaultValue, message) {
2248
- if (Guards27.isDefined(value)) {
2249
- Guards27.throwIfNegative(value, message);
2250
- return value;
2092
+ return new CookieHandler(
2093
+ container.resolve(TOKENS3.NETWORK_CONTEXT_ACCESSOR),
2094
+ container.resolve(TOKENS3.CONFIGURATION_SERVICE),
2095
+ config
2096
+ );
2251
2097
  }
2252
- return defaultValue;
2253
2098
  }
2254
2099
  };
2255
2100
  }
2256
2101
  });
2257
2102
 
2258
- // src/infrastructure/factories/db-client.factory.ts
2259
- var db_client_factory_exports = {};
2260
- __export(db_client_factory_exports, {
2261
- DbClientFactory: () => DbClientFactory
2262
- });
2263
- import { drizzle } from "drizzle-orm/node-postgres";
2264
- import { Pool } from "pg";
2265
- var DbClientFactory;
2266
- var init_db_client_factory = __esm({
2267
- "src/infrastructure/factories/db-client.factory.ts"() {
2268
- "use strict";
2269
- DbClientFactory = class {
2270
- create(opts) {
2271
- const pool = new Pool({
2272
- connectionString: opts.connectionString
2273
- });
2274
- return drizzle({ client: pool });
2275
- }
2276
- };
2277
- }
2103
+ // src/infrastructure/modules/utils/auth.utils.ts
2104
+ var auth_utils_exports = {};
2105
+ __export(auth_utils_exports, {
2106
+ AuthUtils: () => AuthUtils
2278
2107
  });
2279
-
2280
- // src/infrastructure/loggers/pino.logger.ts
2281
- import { Guards as Guards28, LOG_LEVEL } from "@xeno-js/shared";
2282
- var PinoLogger;
2283
- var init_pino_logger = __esm({
2284
- "src/infrastructure/loggers/pino.logger.ts"() {
2108
+ var AuthUtils;
2109
+ var init_auth_utils = __esm({
2110
+ "src/infrastructure/modules/utils/auth.utils.ts"() {
2285
2111
  "use strict";
2286
- PinoLogger = class {
2112
+ AuthUtils = Object.freeze({
2287
2113
  /**
2288
- * 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.
2289
- * @param _logger The Pino logger instance used for logging messages.
2290
- * @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.
2291
-
2292
- *
2293
- * @author Xeno
2294
- * @version 1.0.0
2295
- * @since 2025-09-30
2296
- * @link https://github.com/xeno-js/xeno-js
2297
- */
2298
- constructor(_logger, _minLevel = LOG_LEVEL.DEBUG) {
2299
- this._logger = _logger;
2300
- this._minLevel = _minLevel;
2301
- }
2302
- _logger;
2303
- _minLevel;
2304
- track(level, message, context, error = void 0) {
2305
- if (level < this._minLevel) return;
2306
- const payload = Guards28.isDefined(error) ? { ...context, error } : context;
2307
- switch (level) {
2308
- case LOG_LEVEL.ERROR:
2309
- this._logger.error(payload ?? {}, message);
2310
- break;
2311
- case LOG_LEVEL.WARN:
2312
- this._logger.warn(payload ?? {}, message);
2313
- break;
2314
- case LOG_LEVEL.DEBUG:
2315
- this._logger.debug(payload ?? {}, message);
2316
- break;
2317
- default:
2318
- this._logger.info(payload ?? {}, message);
2319
- break;
2320
- }
2321
- }
2322
- };
2323
- }
2324
- });
2325
-
2326
- // src/infrastructure/factories/pino-logger.factory.ts
2327
- var pino_logger_factory_exports = {};
2328
- __export(pino_logger_factory_exports, {
2329
- PinoLoggerFactory: () => PinoLoggerFactory
2330
- });
2331
- import { LOG_LEVEL as LOG_LEVEL2 } from "@xeno-js/shared";
2332
- import pino from "pino";
2333
- var PinoLoggerFactory;
2334
- var init_pino_logger_factory = __esm({
2335
- "src/infrastructure/factories/pino-logger.factory.ts"() {
2336
- "use strict";
2337
- init_pino_logger();
2338
- PinoLoggerFactory = class {
2339
- create(config) {
2340
- const level = config.level ?? LOG_LEVEL2.DEBUG;
2341
- const env = config.pino.config?.env ?? process.env.NODE_ENV ?? "development";
2342
- const destinationType = config.pino.config?.destination ?? "stdout";
2343
- const filePath = config.pino.config?.filePath ?? "logs/app.log";
2344
- const prettyPrint = config.pino.config?.prettyPrint ?? env === "development";
2345
- const options = {
2346
- level: "trace",
2347
- serializers: {
2348
- err: pino.stdSerializers.err
2349
- },
2350
- timestamp: pino.stdTimeFunctions.isoTime,
2351
- redact: {
2352
- paths: ["password", "token", "secret", "authorization", "headers.authorization"],
2353
- censor: "***"
2354
- }
2355
- };
2356
- if (prettyPrint) {
2357
- return new PinoLogger(
2358
- pino({
2359
- ...options,
2360
- transport: {
2361
- target: "pino-pretty",
2362
- options: {
2363
- colorize: true,
2364
- ignore: "pid,hostname",
2365
- translateTime: "SYS:standard"
2366
- }
2367
- }
2368
- }),
2369
- level
2370
- );
2371
- }
2372
- if (destinationType === "file") {
2373
- const destination = pino.destination({ dest: filePath, sync: false });
2374
- return new PinoLogger(pino(options, destination), level);
2375
- } else {
2376
- const stream = pino.destination({ dest: 1, sync: false });
2377
- return new PinoLogger(pino(options, stream), level);
2378
- }
2379
- }
2380
- };
2381
- }
2382
- });
2383
-
2384
- // src/infrastructure/cache/redis.cache.ts
2385
- import { Guards as Guards29, StringHelper as StringHelper2 } from "@xeno-js/shared";
2386
- var RedisCache;
2387
- var init_redis_cache = __esm({
2388
- "src/infrastructure/cache/redis.cache.ts"() {
2389
- "use strict";
2390
- RedisCache = class {
2391
- /**
2392
- * @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.
2393
- * @param _redisClient An instance of the Redis client from the ioredis library, used to perform caching operations in the Redis database.
2394
-
2395
- *
2396
- * @author Xeno
2397
- * @version 1.0.0
2398
- * @since 2025-09-30
2399
- * @link https://github.com/xeno-js/xeno-js
2400
- */
2401
- constructor(_redisClient) {
2402
- this._redisClient = _redisClient;
2403
- }
2404
- _redisClient;
2405
- async increment(key, ttlSeconds) {
2406
- const multi = this._redisClient.multi();
2407
- multi.incr(key);
2408
- multi.expire(key, ttlSeconds ?? 60);
2409
- const results = await multi.exec();
2410
- return results?.[0]?.[1] ?? 1;
2411
- }
2412
- async get(key) {
2413
- const value = await this._redisClient.get(key);
2414
- if (!Guards29.isDefined(value)) {
2415
- return void 0;
2416
- }
2417
- return JSON.parse(value);
2418
- }
2419
- async set(key, value, ttl) {
2420
- const stringValue = StringHelper2.safeStringify(value);
2421
- const ttlOption = Guards29.isDefined(ttl) ? ttl : 86400;
2422
- await this._redisClient.set(key, stringValue, "EX", ttlOption);
2423
- }
2424
- async setIfAbsent(key, value, ttl) {
2425
- const stringValue = StringHelper2.safeStringify(value);
2426
- const ttlOption = Guards29.isDefined(ttl) ? ttl : 300;
2427
- const result = await this._redisClient.set(key, stringValue, "EX", ttlOption, "NX");
2428
- return result === "OK";
2429
- }
2430
- async remove(key) {
2431
- await this._redisClient.del(key);
2432
- }
2433
- async has(key) {
2434
- const exists = await this._redisClient.exists(key);
2435
- return exists === 1;
2436
- }
2437
- async clear() {
2438
- await this._redisClient.flushdb();
2439
- }
2440
- };
2441
- }
2442
- });
2443
-
2444
- // src/infrastructure/factories/redis-cache.factory.ts
2445
- var redis_cache_factory_exports = {};
2446
- __export(redis_cache_factory_exports, {
2447
- RedisCacheFactory: () => RedisCacheFactory
2448
- });
2449
- import { Guards as Guards30 } from "@xeno-js/shared";
2450
- import { Redis } from "ioredis";
2451
- var RedisCacheFactory;
2452
- var init_redis_cache_factory = __esm({
2453
- "src/infrastructure/factories/redis-cache.factory.ts"() {
2454
- "use strict";
2455
- init_redis_cache();
2456
- RedisCacheFactory = class {
2457
- create(config) {
2458
- const host = config?.host ?? "localhost";
2459
- const port = config?.port ?? 6379;
2460
- const password = config?.password;
2461
- const username = config?.username;
2462
- const useTls = config?.tls ?? false;
2463
- const maxRetries = config?.maxRetriesPerRequest ?? 3;
2464
- const redisOptions = {
2465
- host,
2466
- port,
2467
- maxRetriesPerRequest: maxRetries,
2468
- // Strategia di riconnessione esponenziale per garantire resilienza
2469
- retryStrategy(times) {
2470
- const delay = Math.min(times * 50, 2e3);
2471
- return delay;
2472
- }
2473
- };
2474
- if (Guards30.isDefined(password)) {
2475
- redisOptions.password = password;
2476
- }
2477
- if (Guards30.isDefined(username)) {
2478
- redisOptions.username = username;
2479
- }
2480
- if (useTls) {
2481
- redisOptions.tls = {};
2482
- }
2483
- const nativeRedisInstance = new Redis(redisOptions);
2484
- nativeRedisInstance.on("error", (err) => {
2485
- console.error("\u274C [Redis Error]:", err.message);
2486
- });
2487
- return new RedisCache(nativeRedisInstance);
2488
- }
2489
- };
2490
- }
2491
- });
2492
-
2493
- // src/infrastructure/loggers/sentry.logger.ts
2494
- import { Guards as Guards31, LOG_LEVEL as LOG_LEVEL3 } from "@xeno-js/shared";
2495
- var SentryLogger;
2496
- var init_sentry_logger = __esm({
2497
- "src/infrastructure/loggers/sentry.logger.ts"() {
2498
- "use strict";
2499
- SentryLogger = class {
2500
- constructor(_client, _minLevel) {
2501
- this._client = _client;
2502
- this._minLevel = _minLevel;
2503
- }
2504
- _client;
2505
- _minLevel;
2506
- track(level, message, context = void 0, error = void 0) {
2507
- if (level < this._minLevel) return;
2508
- if (level === LOG_LEVEL3.ERROR || level === LOG_LEVEL3.WARN) {
2509
- this._client.withScope((scope) => {
2510
- if (Guards31.isDefined(context)) scope.setExtras(context);
2511
- if (Guards31.isDefined(error)) {
2512
- this._client.captureException(error);
2513
- } else {
2514
- this._client.captureMessage(message, "warning");
2515
- }
2516
- });
2517
- }
2518
- }
2519
- };
2520
- }
2521
- });
2522
-
2523
- // src/infrastructure/factories/sentry-logger.factory.ts
2524
- var sentry_logger_factory_exports = {};
2525
- __export(sentry_logger_factory_exports, {
2526
- SentryLoggerFactory: () => SentryLoggerFactory
2527
- });
2528
- import * as Sentry from "@sentry/node";
2529
- import { Guards as Guards32, LOG_LEVEL as LOG_LEVEL4 } from "@xeno-js/shared";
2530
- var SentryLoggerFactory;
2531
- var init_sentry_logger_factory = __esm({
2532
- "src/infrastructure/factories/sentry-logger.factory.ts"() {
2533
- "use strict";
2534
- init_sentry_logger();
2535
- SentryLoggerFactory = class {
2536
- create(config) {
2537
- const level = config.level ?? LOG_LEVEL4.WARN;
2538
- const sentryConfig = config.sentry?.config;
2539
- const env = sentryConfig?.environment ?? process.env.NODE_ENV ?? "development";
2540
- if (!Guards32.isDefined(sentryConfig))
2541
- throw new Error("Sentry configuration is required when Sentry logging is enabled.");
2542
- if (!Guards32.isDefined(sentryConfig.dsn))
2543
- throw new Error("Sentry DSN is required when Sentry logging is enabled.");
2544
- Sentry.init({
2545
- dsn: sentryConfig.dsn,
2546
- environment: env,
2547
- tracesSampleRate: env === "production" ? 0.1 : 1,
2548
- integrations: [Sentry.httpIntegration()],
2549
- beforeSend(event, hint) {
2550
- const error = hint.originalException;
2551
- if (error instanceof Error && error.name === "ZodError") {
2552
- return null;
2553
- }
2554
- return event;
2555
- }
2556
- });
2557
- return new SentryLogger(Sentry, level);
2558
- }
2559
- };
2560
- }
2561
- });
2562
-
2563
- // src/infrastructure/factories/sql-light-db-client.factory.ts
2564
- var sql_light_db_client_factory_exports = {};
2565
- __export(sql_light_db_client_factory_exports, {
2566
- DbSqlLiteClientFactory: () => DbSqlLiteClientFactory
2567
- });
2568
- import { createClient } from "@libsql/client";
2569
- import { drizzle as drizzle2 } from "drizzle-orm/libsql";
2570
- var DbSqlLiteClientFactory;
2571
- var init_sql_light_db_client_factory = __esm({
2572
- "src/infrastructure/factories/sql-light-db-client.factory.ts"() {
2573
- "use strict";
2574
- DbSqlLiteClientFactory = class {
2575
- create(opts) {
2576
- const client = createClient({ url: opts.connectionString });
2577
- return drizzle2({ client });
2578
- }
2579
- };
2580
- }
2581
- });
2582
-
2583
- // src/infrastructure/factories/supabase.factory.ts
2584
- import { createServerClient } from "@supabase/ssr";
2585
- import {
2586
- Guards as Guards33,
2587
- SupabaseAuthService,
2588
- SupabaseClaimsMapper,
2589
- SupabaseSessionMapper,
2590
- TOKENS as TOKENS3
2591
- } from "@xeno-js/shared";
2592
- var SupabaseServerAuthFactory;
2593
- var init_supabase_factory = __esm({
2594
- "src/infrastructure/factories/supabase.factory.ts"() {
2595
- "use strict";
2596
- init_services();
2597
- SupabaseServerAuthFactory = class {
2598
- create({
2599
- config,
2600
- container
2601
- }) {
2602
- const cookieService = this._getCookieSsr(config.ssrOpts, container, config.cookieOpts);
2603
- const client = createServerClient(config.url, config.key, {
2604
- ...config.opts,
2605
- cookies: {
2606
- getAll() {
2607
- return cookieService.getAll();
2608
- },
2609
- setAll(cookiesToSet) {
2610
- cookieService.setAll(cookiesToSet);
2611
- }
2612
- }
2613
- });
2614
- const mapper = new SupabaseClaimsMapper();
2615
- const sessionMapper = new SupabaseSessionMapper(mapper);
2616
- return new SupabaseAuthService(client, mapper, sessionMapper, config);
2617
- }
2618
- _getCookieSsr(ssrOpts, container, config) {
2619
- if (Guards33.isDefined(ssrOpts)) {
2620
- return ssrOpts(container);
2621
- } else {
2622
- return new CookieHandler(
2623
- container.resolve(TOKENS3.NETWORK_CONTEXT_ACCESSOR),
2624
- container.resolve(TOKENS3.CONFIGURATION_SERVICE),
2625
- config
2626
- );
2627
- }
2628
- }
2629
- };
2630
- }
2631
- });
2632
-
2633
- // src/infrastructure/factories/zod-validator.factory.ts
2634
- import { ZodValidatorService } from "@xeno-js/shared";
2635
- var ZodValidatorFactory;
2636
- var init_zod_validator_factory = __esm({
2637
- "src/infrastructure/factories/zod-validator.factory.ts"() {
2638
- "use strict";
2639
- ZodValidatorFactory = class {
2640
- create(opts) {
2641
- const validatorService = new ZodValidatorService(/* @__PURE__ */ new Map(), opts.logger);
2642
- for (const [intentKey, schema] of Object.entries(opts.schemas)) {
2643
- validatorService.addSchema(intentKey, schema);
2644
- }
2645
- return validatorService;
2646
- }
2647
- };
2648
- }
2649
- });
2650
-
2651
- // src/infrastructure/factories/index.ts
2652
- var factories_exports = {};
2653
- __export(factories_exports, {
2654
- AllowMethodFactory: () => AllowMethodFactory,
2655
- CockatielResilienceFactory: () => CockatielResilienceFactory,
2656
- DbClientFactory: () => DbClientFactory,
2657
- DbSqlLiteClientFactory: () => DbSqlLiteClientFactory,
2658
- NodeAxiosFactory: () => NodeAxiosFactory,
2659
- NodeRequestContextFactory: () => NodeRequestContextFactory,
2660
- PinoLoggerFactory: () => PinoLoggerFactory,
2661
- RedisCacheFactory: () => RedisCacheFactory,
2662
- SentryLoggerFactory: () => SentryLoggerFactory,
2663
- ServiceScopeFactory: () => ServiceScopeFactory,
2664
- SupabaseServerAuthFactory: () => SupabaseServerAuthFactory,
2665
- UserContextFactory: () => UserContextFactory,
2666
- ZodValidatorFactory: () => ZodValidatorFactory
2667
- });
2668
- var init_factories = __esm({
2669
- "src/infrastructure/factories/index.ts"() {
2670
- "use strict";
2671
- init_allow_method_factory();
2672
- init_axios_factory();
2673
- init_cockatiel_resilience_factory();
2674
- init_db_client_factory();
2675
- init_pino_logger_factory();
2676
- init_redis_cache_factory();
2677
- init_request_context_factory();
2678
- init_sentry_logger_factory();
2679
- init_service_scope_factory();
2680
- init_sql_light_db_client_factory();
2681
- init_supabase_factory();
2682
- init_user_context_factory();
2683
- init_zod_validator_factory();
2684
- }
2685
- });
2686
-
2687
- // src/infrastructure/modules/utils/auth.utils.ts
2688
- var auth_utils_exports = {};
2689
- __export(auth_utils_exports, {
2690
- AuthUtils: () => AuthUtils
2691
- });
2692
- var AuthUtils;
2693
- var init_auth_utils = __esm({
2694
- "src/infrastructure/modules/utils/auth.utils.ts"() {
2695
- "use strict";
2696
- AuthUtils = Object.freeze({
2697
- /**
2698
- * @description Checks if the provided authorization configuration requires any authorization strategies.
2699
- * @param authorizationConfig The authorization configuration to check.
2700
- * @returns True if any authorization strategies are required, false otherwise.
2114
+ * @description Checks if the provided authorization configuration requires any authorization strategies.
2115
+ * @param authorizationConfig The authorization configuration to check.
2116
+ * @returns True if any authorization strategies are required, false otherwise.
2701
2117
 
2702
2118
  *
2703
2119
  * @author Xeno
@@ -2781,7 +2197,7 @@ var init_auth_utils = __esm({
2781
2197
  return authService;
2782
2198
  });
2783
2199
  } else {
2784
- const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
2200
+ const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_supabase_factory(), supabase_factory_exports));
2785
2201
  const factory = new SupabaseServerAuthFactory2();
2786
2202
  const supabase = factory.create({ config: opts, container });
2787
2203
  container.addScoped(TOKENS5.AUTH_SERVICE, () => {
@@ -2796,6 +2212,28 @@ var init_auth_utils = __esm({
2796
2212
  }
2797
2213
  });
2798
2214
 
2215
+ // src/infrastructure/factories/zod-validator.factory.ts
2216
+ var zod_validator_factory_exports = {};
2217
+ __export(zod_validator_factory_exports, {
2218
+ ZodValidatorFactory: () => ZodValidatorFactory
2219
+ });
2220
+ import { ZodValidatorService } from "@xeno-js/shared/zod";
2221
+ var ZodValidatorFactory;
2222
+ var init_zod_validator_factory = __esm({
2223
+ "src/infrastructure/factories/zod-validator.factory.ts"() {
2224
+ "use strict";
2225
+ ZodValidatorFactory = class {
2226
+ create(opts) {
2227
+ const validatorService = new ZodValidatorService(/* @__PURE__ */ new Map(), opts.logger);
2228
+ for (const [intentKey, schema] of Object.entries(opts.schemas)) {
2229
+ validatorService.addSchema(intentKey, schema);
2230
+ }
2231
+ return validatorService;
2232
+ }
2233
+ };
2234
+ }
2235
+ });
2236
+
2799
2237
  // src/infrastructure/modules/utils/validation.utils.ts
2800
2238
  var validation_utils_exports = {};
2801
2239
  __export(validation_utils_exports, {
@@ -2824,7 +2262,7 @@ var init_validation_utils = __esm({
2824
2262
  const validationStrategies = [];
2825
2263
  if (Guards51.isDefined(opts.zod)) {
2826
2264
  const config = opts.zod;
2827
- const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
2265
+ const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_zod_validator_factory(), zod_validator_factory_exports));
2828
2266
  const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2829
2267
  const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
2830
2268
  container.addSingleton(TOKENS5.VALIDATOR_SERVICE, () => validatorService);
@@ -3047,6 +2485,48 @@ var init_cqrs_module = __esm({
3047
2485
  }
3048
2486
  });
3049
2487
 
2488
+ // src/infrastructure/factories/sql-light-db-client.factory.ts
2489
+ var sql_light_db_client_factory_exports = {};
2490
+ __export(sql_light_db_client_factory_exports, {
2491
+ DbSqlLiteClientFactory: () => DbSqlLiteClientFactory
2492
+ });
2493
+ import { createClient } from "@libsql/client";
2494
+ import { drizzle } from "drizzle-orm/libsql";
2495
+ var DbSqlLiteClientFactory;
2496
+ var init_sql_light_db_client_factory = __esm({
2497
+ "src/infrastructure/factories/sql-light-db-client.factory.ts"() {
2498
+ "use strict";
2499
+ DbSqlLiteClientFactory = class {
2500
+ create(opts) {
2501
+ const client = createClient({ url: opts.connectionString });
2502
+ return drizzle({ client });
2503
+ }
2504
+ };
2505
+ }
2506
+ });
2507
+
2508
+ // src/infrastructure/factories/db-client.factory.ts
2509
+ var db_client_factory_exports = {};
2510
+ __export(db_client_factory_exports, {
2511
+ DbClientFactory: () => DbClientFactory
2512
+ });
2513
+ import { drizzle as drizzle2 } from "drizzle-orm/node-postgres";
2514
+ import { Pool } from "pg";
2515
+ var DbClientFactory;
2516
+ var init_db_client_factory = __esm({
2517
+ "src/infrastructure/factories/db-client.factory.ts"() {
2518
+ "use strict";
2519
+ DbClientFactory = class {
2520
+ create(opts) {
2521
+ const pool = new Pool({
2522
+ connectionString: opts.connectionString
2523
+ });
2524
+ return drizzle2({ client: pool });
2525
+ }
2526
+ };
2527
+ }
2528
+ });
2529
+
3050
2530
  // src/infrastructure/modules/utils/db.utils.ts
3051
2531
  var db_utils_exports = {};
3052
2532
  __export(db_utils_exports, {
@@ -3133,8 +2613,8 @@ var unit_of_work_exports = {};
3133
2613
  __export(unit_of_work_exports, {
3134
2614
  UnitOfWork: () => UnitOfWork
3135
2615
  });
3136
- import { AppError as AppError14 } from "@xeno-js/shared";
3137
- import { Guards as Guards34 } from "@xeno-js/shared";
2616
+ import { AppError as AppError13 } from "@xeno-js/shared";
2617
+ import { Guards as Guards28 } from "@xeno-js/shared";
3138
2618
  var UnitOfWork;
3139
2619
  var init_unit_of_work = __esm({
3140
2620
  "src/infrastructure/transaction/unit-of-work.ts"() {
@@ -3157,7 +2637,7 @@ var init_unit_of_work = __esm({
3157
2637
  _dbContext;
3158
2638
  _ttx;
3159
2639
  async runInTransaction(callback, signal) {
3160
- AppError14.throwIfAborted(signal, "UnitOfWork.runInTransaction");
2640
+ AppError13.throwIfAborted(signal, "UnitOfWork.runInTransaction");
3161
2641
  return this._dbContext.transaction(async (tx) => {
3162
2642
  this._ttx.state = tx;
3163
2643
  try {
@@ -3169,9 +2649,9 @@ var init_unit_of_work = __esm({
3169
2649
  });
3170
2650
  }
3171
2651
  async dispose() {
3172
- if (Guards34.isDefined(this._ttx.state)) {
2652
+ if (Guards28.isDefined(this._ttx.state)) {
3173
2653
  try {
3174
- if (Guards34.hasMethod(this._ttx.state, "rollback")) {
2654
+ if (Guards28.hasMethod(this._ttx.state, "rollback")) {
3175
2655
  await this._ttx.state.rollback();
3176
2656
  }
3177
2657
  } finally {
@@ -3227,7 +2707,7 @@ var init_db_module = __esm({
3227
2707
  });
3228
2708
 
3229
2709
  // src/infrastructure/http/base.http-adapter.ts
3230
- import { Guards as Guards35, StringHelper as StringHelper3 } from "@xeno-js/shared";
2710
+ import { Guards as Guards29, StringHelper as StringHelper2 } from "@xeno-js/shared";
3231
2711
  var BaseHttpAdapter;
3232
2712
  var init_base_http_adapter = __esm({
3233
2713
  "src/infrastructure/http/base.http-adapter.ts"() {
@@ -3241,15 +2721,15 @@ var init_base_http_adapter = __esm({
3241
2721
  * @returns The parsed URL.
3242
2722
  */
3243
2723
  parseUrl(rawUrl = "/", headers, queryParams) {
3244
- const protocol = StringHelper3.getSingleValue(headers["x-forwarded-proto"]) ?? "https";
3245
- const host = StringHelper3.safeStringify(headers["host"]) ?? "localhost";
2724
+ const protocol = StringHelper2.getSingleValue(headers["x-forwarded-proto"]) ?? "https";
2725
+ const host = StringHelper2.safeStringify(headers["host"]) ?? "localhost";
3246
2726
  const cleanHost = host.replace(/['"]/g, "");
3247
2727
  const url = new URL(rawUrl, `${protocol}://${cleanHost}`);
3248
- if (!Guards35.isNullOrEmpty(queryParams)) {
2728
+ if (!Guards29.isNullOrEmpty(queryParams)) {
3249
2729
  for (const [key, value] of Object.entries(queryParams)) {
3250
- if (Guards35.isArray(value)) {
2730
+ if (Guards29.isArray(value)) {
3251
2731
  value.forEach((v) => url.searchParams.append(key, String(v)));
3252
- } else if (Guards35.isDefined(value)) {
2732
+ } else if (Guards29.isDefined(value)) {
3253
2733
  url.searchParams.set(key, String(value));
3254
2734
  }
3255
2735
  }
@@ -3264,8 +2744,8 @@ var init_base_http_adapter = __esm({
3264
2744
  parseHeaders(rawHeaders) {
3265
2745
  const headers = new Headers();
3266
2746
  for (const [key, value] of Object.entries(rawHeaders)) {
3267
- if (Guards35.isDefined(value)) {
3268
- if (Guards35.isArray(value)) {
2747
+ if (Guards29.isDefined(value)) {
2748
+ if (Guards29.isArray(value)) {
3269
2749
  value.forEach((v) => headers.append(key, String(v)));
3270
2750
  } else {
3271
2751
  headers.set(key, String(value));
@@ -3281,10 +2761,10 @@ var init_base_http_adapter = __esm({
3281
2761
  * @returns The parsed body.
3282
2762
  */
3283
2763
  parseBody(method, rawBody) {
3284
- if (!Guards35.isDefined(method) || !["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase()) || !Guards35.isDefined(rawBody))
2764
+ if (!Guards29.isDefined(method) || !["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase()) || !Guards29.isDefined(rawBody))
3285
2765
  return void 0;
3286
- if (Guards35.isObject(rawBody)) return JSON.stringify(rawBody);
3287
- if (Guards35.isString(rawBody) || rawBody instanceof Blob || rawBody instanceof ArrayBuffer || ArrayBuffer.isView(rawBody) || rawBody instanceof URLSearchParams || rawBody instanceof FormData)
2766
+ if (Guards29.isObject(rawBody)) return JSON.stringify(rawBody);
2767
+ if (Guards29.isString(rawBody) || rawBody instanceof Blob || rawBody instanceof ArrayBuffer || ArrayBuffer.isView(rawBody) || rawBody instanceof URLSearchParams || rawBody instanceof FormData)
3288
2768
  return rawBody;
3289
2769
  return String(rawBody);
3290
2770
  }
@@ -3302,14 +2782,14 @@ var init_base_http_adapter = __esm({
3302
2782
  headers
3303
2783
  };
3304
2784
  const parsedBody = this.parseBody(method, body);
3305
- if (Guards35.isDefined(parsedBody)) {
2785
+ if (Guards29.isDefined(parsedBody)) {
3306
2786
  init2.body = parsedBody;
3307
2787
  init2.duplex = "half";
3308
2788
  }
3309
2789
  const extendedRequest = new Request(url, init2);
3310
2790
  extendedRequest.path = url.pathname;
3311
2791
  const webResponse = new Response();
3312
- if (Guards35.isDefined(res)) {
2792
+ if (Guards29.isDefined(res)) {
3313
2793
  const originalAppend = webResponse.headers.append.bind(webResponse.headers);
3314
2794
  const originalSet = webResponse.headers.set.bind(webResponse.headers);
3315
2795
  const originalDelete = webResponse.headers.delete.bind(webResponse.headers);
@@ -3335,8 +2815,56 @@ var init_base_http_adapter = __esm({
3335
2815
  }
3336
2816
  });
3337
2817
 
2818
+ // src/infrastructure/http/vercel.http-adapter.ts
2819
+ var vercel_http_adapter_exports = {};
2820
+ __export(vercel_http_adapter_exports, {
2821
+ VercelHttpAdapter: () => VercelHttpAdapter
2822
+ });
2823
+ import { Guards as Guards30 } from "@xeno-js/shared";
2824
+ var VercelHttpAdapter;
2825
+ var init_vercel_http_adapter = __esm({
2826
+ "src/infrastructure/http/vercel.http-adapter.ts"() {
2827
+ "use strict";
2828
+ init_base_http_adapter();
2829
+ VercelHttpAdapter = class extends BaseHttpAdapter {
2830
+ adapt(req, res) {
2831
+ const headers = this.parseHeaders(req.headers);
2832
+ const url = this.parseUrl(req.url, req.headers, req.query);
2833
+ return this.createXenoWebTransport(url, req.method, headers, req.body, res);
2834
+ }
2835
+ handleHeaderChange(res, name, value, action) {
2836
+ if (action === "delete") {
2837
+ res.removeHeader(name);
2838
+ return;
2839
+ }
2840
+ if (name.toLowerCase() === "set-cookie") {
2841
+ const existing = res.getHeader("Set-Cookie");
2842
+ let cookies = [];
2843
+ if (Guards30.isArray(existing)) {
2844
+ cookies = existing;
2845
+ } else if (Guards30.isString(existing)) {
2846
+ cookies = [existing];
2847
+ }
2848
+ if (action === "append") {
2849
+ cookies.push(value);
2850
+ } else {
2851
+ cookies = [value];
2852
+ }
2853
+ res.setHeader("Set-Cookie", cookies);
2854
+ } else {
2855
+ res.setHeader(name, value);
2856
+ }
2857
+ }
2858
+ };
2859
+ }
2860
+ });
2861
+
3338
2862
  // src/infrastructure/http/fastify.http-adapter.ts
3339
- import { Guards as Guards36 } from "@xeno-js/shared";
2863
+ var fastify_http_adapter_exports = {};
2864
+ __export(fastify_http_adapter_exports, {
2865
+ FastifyHttpAdapter: () => FastifyHttpAdapter
2866
+ });
2867
+ import { Guards as Guards31 } from "@xeno-js/shared";
3340
2868
  var FastifyHttpAdapter;
3341
2869
  var init_fastify_http_adapter = __esm({
3342
2870
  "src/infrastructure/http/fastify.http-adapter.ts"() {
@@ -3357,9 +2885,9 @@ var init_fastify_http_adapter = __esm({
3357
2885
  if (name.toLowerCase() === "set-cookie") {
3358
2886
  const existing = res.getHeader("set-cookie");
3359
2887
  let cookies = [];
3360
- if (Guards36.isArray(existing)) {
2888
+ if (Guards31.isArray(existing)) {
3361
2889
  cookies = existing;
3362
- } else if (Guards36.isString(existing)) {
2890
+ } else if (Guards31.isString(existing)) {
3363
2891
  cookies = [existing];
3364
2892
  }
3365
2893
  if (action === "append") {
@@ -3367,119 +2895,252 @@ var init_fastify_http_adapter = __esm({
3367
2895
  } else {
3368
2896
  cookies = [value];
3369
2897
  }
3370
- res.header("set-cookie", cookies);
2898
+ res.header("set-cookie", cookies);
2899
+ } else {
2900
+ res.header(name, value);
2901
+ }
2902
+ }
2903
+ };
2904
+ }
2905
+ });
2906
+
2907
+ // src/infrastructure/http/native.http-adapter.ts
2908
+ var native_http_adapter_exports = {};
2909
+ __export(native_http_adapter_exports, {
2910
+ NativeHttpAdapter: () => NativeHttpAdapter
2911
+ });
2912
+ var NativeHttpAdapter;
2913
+ var init_native_http_adapter = __esm({
2914
+ "src/infrastructure/http/native.http-adapter.ts"() {
2915
+ "use strict";
2916
+ init_base_http_adapter();
2917
+ NativeHttpAdapter = class extends BaseHttpAdapter {
2918
+ adapt(req, res) {
2919
+ const extendedRequest = req;
2920
+ extendedRequest.path = new URL(req.url).pathname;
2921
+ return {
2922
+ request: extendedRequest,
2923
+ response: res
2924
+ };
2925
+ }
2926
+ handleHeaderChange(_res, _name, _value, _action) {
2927
+ return;
2928
+ }
2929
+ };
2930
+ }
2931
+ });
2932
+
2933
+ // src/infrastructure/modules/http-adapter.module.ts
2934
+ import { Guards as Guards32 } from "@xeno-js/shared";
2935
+ var HttpAdapterModule;
2936
+ var init_http_adapter_module = __esm({
2937
+ "src/infrastructure/modules/http-adapter.module.ts"() {
2938
+ "use strict";
2939
+ HttpAdapterModule = class {
2940
+ async configure(container, opts) {
2941
+ const adapter = await this._getAdapter(opts);
2942
+ container.addSingleton("HTTP_ADAPTER", () => adapter);
2943
+ }
2944
+ async _getAdapter(opts) {
2945
+ if (opts.vercel) {
2946
+ const { VercelHttpAdapter: VercelHttpAdapter2 } = await Promise.resolve().then(() => (init_vercel_http_adapter(), vercel_http_adapter_exports));
2947
+ return new VercelHttpAdapter2();
2948
+ } else if (opts.fastify) {
2949
+ const { FastifyHttpAdapter: FastifyHttpAdapter2 } = await Promise.resolve().then(() => (init_fastify_http_adapter(), fastify_http_adapter_exports));
2950
+ return new FastifyHttpAdapter2();
2951
+ } else if (Guards32.isDefined(opts.custom)) {
2952
+ return opts.custom();
2953
+ } else {
2954
+ const { NativeHttpAdapter: NativeHttpAdapter2 } = await Promise.resolve().then(() => (init_native_http_adapter(), native_http_adapter_exports));
2955
+ return new NativeHttpAdapter2();
2956
+ }
2957
+ }
2958
+ };
2959
+ }
2960
+ });
2961
+
2962
+ // src/infrastructure/factories/axios.factory.ts
2963
+ var axios_factory_exports = {};
2964
+ __export(axios_factory_exports, {
2965
+ NodeAxiosFactory: () => NodeAxiosFactory
2966
+ });
2967
+ import http from "http";
2968
+ import https from "https";
2969
+ import { AxiosHttpClient } from "@xeno-js/shared/axios";
2970
+ import axios from "axios";
2971
+ var NodeAxiosFactory;
2972
+ var init_axios_factory = __esm({
2973
+ "src/infrastructure/factories/axios.factory.ts"() {
2974
+ "use strict";
2975
+ NodeAxiosFactory = class {
2976
+ create(config) {
2977
+ const isKeepAlive = config.keepAlive ?? true;
2978
+ const maxSockets = config.maxSockets ?? 100;
2979
+ const httpAgent = new http.Agent({
2980
+ keepAlive: isKeepAlive,
2981
+ maxSockets,
2982
+ scheduling: "lifo"
2983
+ });
2984
+ const httpsAgent = new https.Agent({
2985
+ keepAlive: isKeepAlive,
2986
+ maxSockets,
2987
+ scheduling: "lifo"
2988
+ });
2989
+ const axiosInstance = axios.create({
2990
+ baseURL: config.baseURL,
2991
+ headers: config.defaultHeaders,
2992
+ timeout: config.timeoutMs,
2993
+ httpAgent,
2994
+ httpsAgent,
2995
+ maxRedirects: config.maxRedirects ?? 5,
2996
+ decompress: config.decompress ?? true,
2997
+ proxy: config.proxy,
2998
+ withCredentials: config.withCredentials
2999
+ });
3000
+ return new AxiosHttpClient(axiosInstance);
3001
+ }
3002
+ };
3003
+ }
3004
+ });
3005
+
3006
+ // src/infrastructure/factories/cockatiel-resilience.factory.ts
3007
+ var cockatiel_resilience_factory_exports = {};
3008
+ __export(cockatiel_resilience_factory_exports, {
3009
+ CockatielResilienceFactory: () => CockatielResilienceFactory
3010
+ });
3011
+ import { AppError as AppError14, Guards as Guards33, RESILIENCE_DEFAULTS } from "@xeno-js/shared";
3012
+ import {
3013
+ bulkhead,
3014
+ circuitBreaker,
3015
+ ConsecutiveBreaker,
3016
+ ExponentialBackoff,
3017
+ handleWhen,
3018
+ retry,
3019
+ wrap
3020
+ } from "cockatiel";
3021
+ var CockatielResilienceFactory;
3022
+ var init_cockatiel_resilience_factory = __esm({
3023
+ "src/infrastructure/factories/cockatiel-resilience.factory.ts"() {
3024
+ "use strict";
3025
+ init_resilience_service();
3026
+ CockatielResilienceFactory = class {
3027
+ create(config) {
3028
+ const message = "The resilience configuration provided is invalid. Please ensure that all values are non-negative numbers.";
3029
+ const normalizedConfig = {
3030
+ retry: {
3031
+ attempts: this.checkConfigValue(
3032
+ config.retry.attempts,
3033
+ RESILIENCE_DEFAULTS.RETRY.ATTEMPTS,
3034
+ message
3035
+ ),
3036
+ baseDelayMs: this.checkConfigValue(
3037
+ config.retry.baseDelayMs,
3038
+ RESILIENCE_DEFAULTS.RETRY.BASE_DELAY_MS,
3039
+ message
3040
+ ),
3041
+ maxDelayMs: this.checkConfigValue(
3042
+ config.retry.maxDelayMs,
3043
+ RESILIENCE_DEFAULTS.RETRY.MAX_DELAY_MS,
3044
+ message
3045
+ )
3046
+ },
3047
+ circuitBreaker: {
3048
+ consecutiveFailures: this.checkConfigValue(
3049
+ config.circuitBreaker.consecutiveFailures,
3050
+ RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.CONSECUTIVE_FAILURES,
3051
+ message
3052
+ ),
3053
+ halfOpenTimeoutMs: this.checkConfigValue(
3054
+ config.circuitBreaker.halfOpenTimeoutMs,
3055
+ RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.HALF_OPEN_TIMEOUT_MS,
3056
+ message
3057
+ )
3058
+ },
3059
+ bulkhead: {
3060
+ maxConcurrent: this.checkConfigValue(
3061
+ config.bulkhead.maxConcurrent,
3062
+ RESILIENCE_DEFAULTS.BULKHEAD.MAX_CONCURRENT,
3063
+ message
3064
+ )
3065
+ }
3066
+ };
3067
+ const retryPolicy = retry(
3068
+ handleWhen((error) => this.isTransientAndIdempotent(error)),
3069
+ {
3070
+ maxAttempts: normalizedConfig.retry.attempts,
3071
+ backoff: new ExponentialBackoff({
3072
+ initialDelay: normalizedConfig.retry.baseDelayMs,
3073
+ maxDelay: normalizedConfig.retry.maxDelayMs
3074
+ })
3075
+ }
3076
+ );
3077
+ const circuitBreakerPolicy = circuitBreaker(
3078
+ handleWhen((error) => this.isTransientError(error)),
3079
+ {
3080
+ breaker: new ConsecutiveBreaker(normalizedConfig.circuitBreaker.consecutiveFailures),
3081
+ halfOpenAfter: normalizedConfig.circuitBreaker.halfOpenTimeoutMs
3082
+ }
3083
+ );
3084
+ const bulkheadPolicy = bulkhead(normalizedConfig.bulkhead.maxConcurrent);
3085
+ return new ServiceResilience(wrap(bulkheadPolicy, circuitBreakerPolicy, retryPolicy));
3086
+ }
3087
+ isTransientError(error) {
3088
+ if (!Guards33.isDefined(error) || !Guards33.isObject(error)) return false;
3089
+ let status;
3090
+ let isNetworkError = false;
3091
+ if (error instanceof AppError14) {
3092
+ status = error.status;
3093
+ const cause = error.cause;
3094
+ if (Guards33.isDefined(cause) && Guards33.isString(cause.code)) {
3095
+ isNetworkError = [
3096
+ "ECONNABORTED",
3097
+ "ECONNRESET",
3098
+ "ETIMEDOUT",
3099
+ "ENOTFOUND",
3100
+ "ECONNREFUSED"
3101
+ ].includes(cause.code.toUpperCase());
3102
+ }
3371
3103
  } else {
3372
- res.header(name, value);
3104
+ const err = error;
3105
+ status = err.status;
3106
+ if (Guards33.isString(err.code)) {
3107
+ isNetworkError = [
3108
+ "ECONNABORTED",
3109
+ "ECONNRESET",
3110
+ "ETIMEDOUT",
3111
+ "ENOTFOUND",
3112
+ "ECONNREFUSED"
3113
+ ].includes(err.code.toUpperCase());
3114
+ }
3373
3115
  }
3116
+ if (isNetworkError) return true;
3117
+ if (Guards33.isDefined(status)) return status === 408 || status >= 500 && status < 600;
3118
+ return false;
3374
3119
  }
3375
- };
3376
- }
3377
- });
3378
-
3379
- // src/infrastructure/http/native.http-adapter.ts
3380
- var NativeHttpAdapter;
3381
- var init_native_http_adapter = __esm({
3382
- "src/infrastructure/http/native.http-adapter.ts"() {
3383
- "use strict";
3384
- init_base_http_adapter();
3385
- NativeHttpAdapter = class extends BaseHttpAdapter {
3386
- adapt(req, res) {
3387
- const extendedRequest = req;
3388
- extendedRequest.path = new URL(req.url).pathname;
3389
- return {
3390
- request: extendedRequest,
3391
- response: res
3392
- };
3393
- }
3394
- handleHeaderChange(_res, _name, _value, _action) {
3395
- return;
3396
- }
3397
- };
3398
- }
3399
- });
3400
-
3401
- // src/infrastructure/http/vercel.http-adapter.ts
3402
- import { Guards as Guards37 } from "@xeno-js/shared";
3403
- var VercelHttpAdapter;
3404
- var init_vercel_http_adapter = __esm({
3405
- "src/infrastructure/http/vercel.http-adapter.ts"() {
3406
- "use strict";
3407
- init_base_http_adapter();
3408
- VercelHttpAdapter = class extends BaseHttpAdapter {
3409
- adapt(req, res) {
3410
- const headers = this.parseHeaders(req.headers);
3411
- const url = this.parseUrl(req.url, req.headers, req.query);
3412
- return this.createXenoWebTransport(url, req.method, headers, req.body, res);
3413
- }
3414
- handleHeaderChange(res, name, value, action) {
3415
- if (action === "delete") {
3416
- res.removeHeader(name);
3417
- return;
3418
- }
3419
- if (name.toLowerCase() === "set-cookie") {
3420
- const existing = res.getHeader("Set-Cookie");
3421
- let cookies = [];
3422
- if (Guards37.isArray(existing)) {
3423
- cookies = existing;
3424
- } else if (Guards37.isString(existing)) {
3425
- cookies = [existing];
3426
- }
3427
- if (action === "append") {
3428
- cookies.push(value);
3429
- } else {
3430
- cookies = [value];
3120
+ isTransientAndIdempotent(error) {
3121
+ if (!this.isTransientError(error)) return false;
3122
+ let method;
3123
+ if (error instanceof AppError14) {
3124
+ const cause = error.cause;
3125
+ if (Guards33.isDefined(cause) && Guards33.isDefined(cause.config) && Guards33.isString(cause.config.method)) {
3126
+ method = cause.config.method.toUpperCase();
3431
3127
  }
3432
- res.setHeader("Set-Cookie", cookies);
3433
3128
  } else {
3434
- res.setHeader(name, value);
3129
+ const err = error;
3130
+ if (Guards33.isDefined(err.config) && Guards33.isString(err.config.method)) {
3131
+ method = err.config.method.toUpperCase();
3132
+ }
3435
3133
  }
3134
+ if (Guards33.isNullOrEmpty(method)) return false;
3135
+ const idempotentMethods = ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
3136
+ return idempotentMethods.includes(method);
3436
3137
  }
3437
- };
3438
- }
3439
- });
3440
-
3441
- // src/infrastructure/http/index.ts
3442
- var http_exports = {};
3443
- __export(http_exports, {
3444
- BaseHttpAdapter: () => BaseHttpAdapter,
3445
- FastifyHttpAdapter: () => FastifyHttpAdapter,
3446
- NativeHttpAdapter: () => NativeHttpAdapter,
3447
- VercelHttpAdapter: () => VercelHttpAdapter
3448
- });
3449
- var init_http = __esm({
3450
- "src/infrastructure/http/index.ts"() {
3451
- "use strict";
3452
- init_base_http_adapter();
3453
- init_fastify_http_adapter();
3454
- init_native_http_adapter();
3455
- init_vercel_http_adapter();
3456
- }
3457
- });
3458
-
3459
- // src/infrastructure/modules/http-adapter.module.ts
3460
- import { Guards as Guards38 } from "@xeno-js/shared";
3461
- var HttpAdapterModule;
3462
- var init_http_adapter_module = __esm({
3463
- "src/infrastructure/modules/http-adapter.module.ts"() {
3464
- "use strict";
3465
- HttpAdapterModule = class {
3466
- async configure(container, opts) {
3467
- const adapter = await this._getAdapter(opts);
3468
- container.addSingleton("HTTP_ADAPTER", () => adapter);
3469
- }
3470
- async _getAdapter(opts) {
3471
- if (opts.vercel) {
3472
- const { VercelHttpAdapter: VercelHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
3473
- return new VercelHttpAdapter2();
3474
- } else if (opts.fastify) {
3475
- const { FastifyHttpAdapter: FastifyHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
3476
- return new FastifyHttpAdapter2();
3477
- } else if (Guards38.isDefined(opts.custom)) {
3478
- return opts.custom();
3479
- } else {
3480
- const { NativeHttpAdapter: NativeHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
3481
- return new NativeHttpAdapter2();
3138
+ checkConfigValue(value, defaultValue, message) {
3139
+ if (Guards33.isDefined(value)) {
3140
+ Guards33.throwIfNegative(value, message);
3141
+ return value;
3482
3142
  }
3143
+ return defaultValue;
3483
3144
  }
3484
3145
  };
3485
3146
  }
@@ -3506,7 +3167,7 @@ var init_http_utils = __esm({
3506
3167
  * @link https://github.com/xeno-js/xeno-js
3507
3168
  */
3508
3169
  async addAxios(container, opts) {
3509
- const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
3170
+ const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_axios_factory(), axios_factory_exports));
3510
3171
  const { Guards: Guards51 } = await import("@xeno-js/shared");
3511
3172
  if (!Guards51.isDefined(opts.token)) {
3512
3173
  throw new Error("HttpConfig.token is required and must be defined.");
@@ -3534,7 +3195,7 @@ var init_http_utils = __esm({
3534
3195
  */
3535
3196
  async addResilience(container, opts) {
3536
3197
  const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
3537
- const { CockatielResilienceFactory: CockatielResilienceFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
3198
+ const { CockatielResilienceFactory: CockatielResilienceFactory2 } = await Promise.resolve().then(() => (init_cockatiel_resilience_factory(), cockatiel_resilience_factory_exports));
3538
3199
  container.addSingleton(TOKENS5.RESILIENCE_CLIENT, () => {
3539
3200
  const factory = new CockatielResilienceFactory2();
3540
3201
  return factory.create(opts);
@@ -3856,7 +3517,7 @@ var init_composite_middleware = __esm({
3856
3517
  });
3857
3518
 
3858
3519
  // src/presentation/middlewares/cors.middleware.ts
3859
- import { Guards as Guards39 } from "@xeno-js/shared";
3520
+ import { Guards as Guards34 } from "@xeno-js/shared";
3860
3521
  var CORSMiddleware;
3861
3522
  var init_cors_middleware = __esm({
3862
3523
  "src/presentation/middlewares/cors.middleware.ts"() {
@@ -3872,7 +3533,7 @@ var init_cors_middleware = __esm({
3872
3533
  const { network } = this._requestContext.getContext() ?? {};
3873
3534
  const origin = network?.origin;
3874
3535
  const response = await next();
3875
- if (Guards39.isDefined(origin))
3536
+ if (Guards34.isDefined(origin))
3876
3537
  response.headers = {
3877
3538
  ...response.headers ?? {},
3878
3539
  "Access-Control-Allow-Origin": origin,
@@ -3889,7 +3550,7 @@ var init_cors_middleware = __esm({
3889
3550
  import {
3890
3551
  ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES5,
3891
3552
  ERROR_CODES as ERROR_CODES6,
3892
- Guards as Guards40,
3553
+ Guards as Guards35,
3893
3554
  GuidHelper as GuidHelper9,
3894
3555
  HttpHelper as HttpHelper6,
3895
3556
  STATUS_CODES as STATUS_CODES7
@@ -3912,7 +3573,7 @@ var init_csrf_middleware = __esm({
3912
3573
  const { network, tracing, identity } = this._requestContext.getContext() ?? {};
3913
3574
  const headerToken = network?.csrf;
3914
3575
  const cookieToken = network?.csrfCookie;
3915
- if (!Guards40.isDefined(headerToken) || !Guards40.isDefined(cookieToken)) {
3576
+ if (!Guards35.isDefined(headerToken) || !Guards35.isDefined(cookieToken)) {
3916
3577
  return HttpHelper6.error(
3917
3578
  {
3918
3579
  success: false,
@@ -3954,7 +3615,7 @@ var init_csrf_middleware = __esm({
3954
3615
  }
3955
3616
  );
3956
3617
  }
3957
- if (!Guards40.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
3618
+ if (!Guards35.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
3958
3619
  return HttpHelper6.error(
3959
3620
  {
3960
3621
  success: false,
@@ -3983,7 +3644,7 @@ var init_csrf_middleware = __esm({
3983
3644
  });
3984
3645
 
3985
3646
  // src/presentation/middlewares/csrf-cookie.middleware.ts
3986
- import { Guards as Guards41 } from "@xeno-js/shared";
3647
+ import { Guards as Guards36 } from "@xeno-js/shared";
3987
3648
  var CsrfCookieMiddleware;
3988
3649
  var init_csrf_cookie_middleware = __esm({
3989
3650
  "src/presentation/middlewares/csrf-cookie.middleware.ts"() {
@@ -4002,8 +3663,8 @@ var init_csrf_cookie_middleware = __esm({
4002
3663
  const context = this._requestContext.getContext();
4003
3664
  const identity = context?.identity;
4004
3665
  const network = context?.network;
4005
- if (!Guards41.isDefined(identity?.userId)) return response;
4006
- if (Guards41.isDefined(network?.csrfCookie)) return response;
3666
+ if (!Guards36.isDefined(identity?.userId)) return response;
3667
+ if (Guards36.isDefined(network?.csrfCookie)) return response;
4007
3668
  const token = await this._csrfTokenService.generate(identity.userId);
4008
3669
  const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
4009
3670
  const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
@@ -4021,7 +3682,7 @@ var init_csrf_cookie_middleware = __esm({
4021
3682
  });
4022
3683
 
4023
3684
  // src/presentation/middlewares/options.middleware.ts
4024
- import { Guards as Guards42, HttpHelper as HttpHelper7, STATUS_CODES as STATUS_CODES8 } from "@xeno-js/shared";
3685
+ import { Guards as Guards37, HttpHelper as HttpHelper7, STATUS_CODES as STATUS_CODES8 } from "@xeno-js/shared";
4025
3686
  var OptionsMiddleware;
4026
3687
  var init_options_middleware = __esm({
4027
3688
  "src/presentation/middlewares/options.middleware.ts"() {
@@ -4042,7 +3703,7 @@ var init_options_middleware = __esm({
4042
3703
  const network = this._requestContext.getNetworkContext();
4043
3704
  const origin = network?.origin;
4044
3705
  const headers = {};
4045
- if (Guards42.isDefined(origin)) {
3706
+ if (Guards37.isDefined(origin)) {
4046
3707
  headers["Access-Control-Allow-Origin"] = origin;
4047
3708
  headers["Access-Control-Allow-Credentials"] = this._withCredentials;
4048
3709
  headers["Vary"] = "Origin";
@@ -4061,7 +3722,7 @@ var init_options_middleware = __esm({
4061
3722
  import {
4062
3723
  ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES6,
4063
3724
  ERROR_CODES as ERROR_CODES7,
4064
- Guards as Guards43,
3725
+ Guards as Guards38,
4065
3726
  GuidHelper as GuidHelper10,
4066
3727
  HttpHelper as HttpHelper8,
4067
3728
  STATUS_CODES as STATUS_CODES9
@@ -4086,7 +3747,7 @@ var init_rate_limiter_middleware = __esm({
4086
3747
  async execute(req, _res, next) {
4087
3748
  const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
4088
3749
  const { network, tracing } = this._ctxAccessor.getContext() ?? {};
4089
- if (!Guards43.isDefined(cacheKey))
3750
+ if (!Guards38.isDefined(cacheKey))
4090
3751
  return HttpHelper8.error(
4091
3752
  {
4092
3753
  success: false,
@@ -4138,10 +3799,10 @@ var init_rate_limiter_middleware = __esm({
4138
3799
  });
4139
3800
 
4140
3801
  // src/presentation/mappers/context.mapper.ts
4141
- import { Guards as Guards44 } from "@xeno-js/shared";
3802
+ import { Guards as Guards39 } from "@xeno-js/shared";
4142
3803
  function _buildMessagingContext(meta) {
4143
- const hasSequenceData = Guards44.isDefined(meta.sequence?.sequenceId) || Guards44.isDefined(meta.sequence?.position) || Guards44.isDefined(meta.sequence?.size);
4144
- const hasMessagingData = hasSequenceData || Guards44.isDefined(meta.expiration) || Guards44.isDefined(meta.returnAddress);
3804
+ const hasSequenceData = Guards39.isDefined(meta.sequence?.sequenceId) || Guards39.isDefined(meta.sequence?.position) || Guards39.isDefined(meta.sequence?.size);
3805
+ const hasMessagingData = hasSequenceData || Guards39.isDefined(meta.expiration) || Guards39.isDefined(meta.returnAddress);
4145
3806
  const messaging = hasMessagingData ? {
4146
3807
  returnAddress: meta.returnAddress,
4147
3808
  expiration: meta.expiration,
@@ -4329,7 +3990,7 @@ var inmemory_cache_exports = {};
4329
3990
  __export(inmemory_cache_exports, {
4330
3991
  InMemoryCacheExtended: () => InMemoryCacheExtended
4331
3992
  });
4332
- import { Guards as Guards45, InMemoryCache } from "@xeno-js/shared";
3993
+ import { Guards as Guards40, InMemoryCache } from "@xeno-js/shared";
4333
3994
  var InMemoryCacheExtended;
4334
3995
  var init_inmemory_cache = __esm({
4335
3996
  "src/infrastructure/cache/inmemory.cache.ts"() {
@@ -4338,7 +3999,7 @@ var init_inmemory_cache = __esm({
4338
3999
  async increment(key, ttlSeconds) {
4339
4000
  const current = await this.get(key) ?? 0;
4340
4001
  const next = Number(current) + 1;
4341
- const ttl = Guards45.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
4002
+ const ttl = Guards40.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
4342
4003
  await this.set(key, next, ttl);
4343
4004
  return next;
4344
4005
  }
@@ -4347,7 +4008,7 @@ var init_inmemory_cache = __esm({
4347
4008
  });
4348
4009
 
4349
4010
  // src/infrastructure/cache/rate-limit-key-builder.cache.ts
4350
- import { Guards as Guards46 } from "@xeno-js/shared";
4011
+ import { Guards as Guards41 } from "@xeno-js/shared";
4351
4012
  var RateLimitKeyBuilder;
4352
4013
  var init_rate_limit_key_builder_cache = __esm({
4353
4014
  "src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
@@ -4362,18 +4023,78 @@ var init_rate_limit_key_builder_cache = __esm({
4362
4023
  const tenantId = ctx?.identity?.tenantId;
4363
4024
  const userId = ctx?.identity?.userId;
4364
4025
  const clientIp = ctx?.network?.clientIp;
4365
- if (!Guards46.isNullOrEmpty(tenantId) && !Guards46.isNullOrEmpty(userId))
4026
+ if (!Guards41.isNullOrEmpty(tenantId) && !Guards41.isNullOrEmpty(userId))
4366
4027
  return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
4367
- if (!Guards46.isNullOrEmpty(tenantId) && !Guards46.isNullOrEmpty(clientIp))
4028
+ if (!Guards41.isNullOrEmpty(tenantId) && !Guards41.isNullOrEmpty(clientIp))
4368
4029
  return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
4369
- if (!Guards46.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
4370
- if (!Guards46.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
4030
+ if (!Guards41.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
4031
+ if (!Guards41.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
4371
4032
  return void 0;
4372
4033
  }
4373
4034
  };
4374
4035
  }
4375
4036
  });
4376
4037
 
4038
+ // src/infrastructure/cache/redis.cache.ts
4039
+ import { Guards as Guards42, StringHelper as StringHelper3 } from "@xeno-js/shared";
4040
+ var RedisCache;
4041
+ var init_redis_cache = __esm({
4042
+ "src/infrastructure/cache/redis.cache.ts"() {
4043
+ "use strict";
4044
+ RedisCache = class {
4045
+ /**
4046
+ * @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.
4047
+ * @param _redisClient An instance of the Redis client from the ioredis library, used to perform caching operations in the Redis database.
4048
+
4049
+ *
4050
+ * @author Xeno
4051
+ * @version 1.0.0
4052
+ * @since 2025-09-30
4053
+ * @link https://github.com/xeno-js/xeno-js
4054
+ */
4055
+ constructor(_redisClient) {
4056
+ this._redisClient = _redisClient;
4057
+ }
4058
+ _redisClient;
4059
+ async increment(key, ttlSeconds) {
4060
+ const multi = this._redisClient.multi();
4061
+ multi.incr(key);
4062
+ multi.expire(key, ttlSeconds ?? 60);
4063
+ const results = await multi.exec();
4064
+ return results?.[0]?.[1] ?? 1;
4065
+ }
4066
+ async get(key) {
4067
+ const value = await this._redisClient.get(key);
4068
+ if (!Guards42.isDefined(value)) {
4069
+ return void 0;
4070
+ }
4071
+ return JSON.parse(value);
4072
+ }
4073
+ async set(key, value, ttl) {
4074
+ const stringValue = StringHelper3.safeStringify(value);
4075
+ const ttlOption = Guards42.isDefined(ttl) ? ttl : 86400;
4076
+ await this._redisClient.set(key, stringValue, "EX", ttlOption);
4077
+ }
4078
+ async setIfAbsent(key, value, ttl) {
4079
+ const stringValue = StringHelper3.safeStringify(value);
4080
+ const ttlOption = Guards42.isDefined(ttl) ? ttl : 300;
4081
+ const result = await this._redisClient.set(key, stringValue, "EX", ttlOption, "NX");
4082
+ return result === "OK";
4083
+ }
4084
+ async remove(key) {
4085
+ await this._redisClient.del(key);
4086
+ }
4087
+ async has(key) {
4088
+ const exists = await this._redisClient.exists(key);
4089
+ return exists === 1;
4090
+ }
4091
+ async clear() {
4092
+ await this._redisClient.flushdb();
4093
+ }
4094
+ };
4095
+ }
4096
+ });
4097
+
4377
4098
  // src/infrastructure/cache/index.ts
4378
4099
  var cache_exports = {};
4379
4100
  __export(cache_exports, {
@@ -4390,6 +4111,28 @@ var init_cache = __esm({
4390
4111
  }
4391
4112
  });
4392
4113
 
4114
+ // src/infrastructure/factories/allow-method.factory.ts
4115
+ var allow_method_factory_exports = {};
4116
+ __export(allow_method_factory_exports, {
4117
+ AllowMethodFactory: () => AllowMethodFactory
4118
+ });
4119
+ var AllowMethodFactory;
4120
+ var init_allow_method_factory = __esm({
4121
+ "src/infrastructure/factories/allow-method.factory.ts"() {
4122
+ "use strict";
4123
+ init_services();
4124
+ AllowMethodFactory = class {
4125
+ create(opts) {
4126
+ const allowMethodService = new AllowMethodRegistry();
4127
+ for (const [intentKey, schema] of Object.entries(opts)) {
4128
+ allowMethodService.add(intentKey, schema);
4129
+ }
4130
+ return allowMethodService;
4131
+ }
4132
+ };
4133
+ }
4134
+ });
4135
+
4393
4136
  // src/infrastructure/modules/middleware.module.ts
4394
4137
  var middleware_module_exports = {};
4395
4138
  __export(middleware_module_exports, {
@@ -4431,17 +4174,16 @@ var init_middleware_module = __esm({
4431
4174
  logger
4432
4175
  )
4433
4176
  );
4434
- if (!Guards51.isNullOrEmpty(opts.allowOrigins)) {
4435
- if (opts.withCredentials && opts.allowOrigins.includes("*"))
4436
- throw new Error(
4437
- "Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
4438
- );
4439
- const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4440
- const { AllowOriginMiddleware: AllowOriginMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4441
- middlewares.push(
4442
- new AllowOriginMiddleware2(new AllowOrigin2(opts.allowOrigins), requestContext, logger)
4177
+ const configuration = container.resolve(TOKENS5.CONFIGURATION_SERVICE);
4178
+ const defaultOrigin = configuration.get("APP_URL") ?? `http://localhost:${configuration.getNumber("PORT", 3e3)}`;
4179
+ const origins = !Guards51.isNullOrEmpty(opts.allowOrigins) ? opts.allowOrigins : [defaultOrigin];
4180
+ if (opts.withCredentials && origins.includes("*"))
4181
+ throw new Error(
4182
+ "Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
4443
4183
  );
4444
- }
4184
+ const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4185
+ const { AllowOriginMiddleware: AllowOriginMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4186
+ middlewares.push(new AllowOriginMiddleware2(new AllowOrigin2(origins), requestContext, logger));
4445
4187
  const withCredentials = opts.withCredentials ? "true" : "false";
4446
4188
  const allowMethod = await this._getAllowMethod(
4447
4189
  opts.optionsMiddleware || opts.cors,
@@ -4522,27 +4264,76 @@ var init_middleware_module = __esm({
4522
4264
  const { CsrfMiddleware: CsrfMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4523
4265
  middlewares.push(new CsrfMiddleware2(requestContext, container.resolve("CSRF_TOKEN_SERVICE")));
4524
4266
  }
4525
- const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4526
- container.addSingleton(TOKENS5.MIDDLEWARE, () => {
4527
- return new CompositeMiddleware2(middlewares);
4528
- });
4529
- }
4530
- async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
4531
- const { Guards: Guards51 } = await import("@xeno-js/shared");
4532
- if (Guards51.isDefined(customTokenExtractor)) return customTokenExtractor();
4533
- if (isSSR) {
4534
- const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4535
- return new SupabaseSsrTokenExtractor2();
4536
- } else {
4537
- const { BearerTokenExtractor: BearerTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4538
- return new BearerTokenExtractor2(cookieName ?? "sb-access-token");
4267
+ const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4268
+ container.addSingleton(TOKENS5.MIDDLEWARE, () => {
4269
+ return new CompositeMiddleware2(middlewares);
4270
+ });
4271
+ }
4272
+ async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
4273
+ const { Guards: Guards51 } = await import("@xeno-js/shared");
4274
+ if (Guards51.isDefined(customTokenExtractor)) return customTokenExtractor();
4275
+ if (isSSR) {
4276
+ const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4277
+ return new SupabaseSsrTokenExtractor2();
4278
+ } else {
4279
+ const { BearerTokenExtractor: BearerTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4280
+ return new BearerTokenExtractor2(cookieName ?? "sb-access-token");
4281
+ }
4282
+ }
4283
+ async _getAllowMethod(configure, opts) {
4284
+ const { Guards: Guards51 } = await import("@xeno-js/shared");
4285
+ if (!configure || !Guards51.isDefined(opts)) return void 0;
4286
+ const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_allow_method_factory(), allow_method_factory_exports));
4287
+ return new AllowMethodFactory2().create(opts);
4288
+ }
4289
+ };
4290
+ }
4291
+ });
4292
+
4293
+ // src/infrastructure/factories/redis-cache.factory.ts
4294
+ var redis_cache_factory_exports = {};
4295
+ __export(redis_cache_factory_exports, {
4296
+ RedisCacheFactory: () => RedisCacheFactory
4297
+ });
4298
+ import { Guards as Guards43 } from "@xeno-js/shared";
4299
+ import { Redis } from "ioredis";
4300
+ var RedisCacheFactory;
4301
+ var init_redis_cache_factory = __esm({
4302
+ "src/infrastructure/factories/redis-cache.factory.ts"() {
4303
+ "use strict";
4304
+ init_redis_cache();
4305
+ RedisCacheFactory = class {
4306
+ create(config) {
4307
+ const host = config?.host ?? "localhost";
4308
+ const port = config?.port ?? 6379;
4309
+ const password = config?.password;
4310
+ const username = config?.username;
4311
+ const useTls = config?.tls ?? false;
4312
+ const maxRetries = config?.maxRetriesPerRequest ?? 3;
4313
+ const redisOptions = {
4314
+ host,
4315
+ port,
4316
+ maxRetriesPerRequest: maxRetries,
4317
+ // Strategia di riconnessione esponenziale per garantire resilienza
4318
+ retryStrategy(times) {
4319
+ const delay = Math.min(times * 50, 2e3);
4320
+ return delay;
4321
+ }
4322
+ };
4323
+ if (Guards43.isDefined(password)) {
4324
+ redisOptions.password = password;
4325
+ }
4326
+ if (Guards43.isDefined(username)) {
4327
+ redisOptions.username = username;
4539
4328
  }
4540
- }
4541
- async _getAllowMethod(configure, opts) {
4542
- const { Guards: Guards51 } = await import("@xeno-js/shared");
4543
- if (!configure || !Guards51.isDefined(opts)) return void 0;
4544
- const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
4545
- return new AllowMethodFactory2().create(opts);
4329
+ if (useTls) {
4330
+ redisOptions.tls = {};
4331
+ }
4332
+ const nativeRedisInstance = new Redis(redisOptions);
4333
+ nativeRedisInstance.on("error", (err) => {
4334
+ console.error("\u274C [Redis Error]:", err.message);
4335
+ });
4336
+ return new RedisCache(nativeRedisInstance);
4546
4337
  }
4547
4338
  };
4548
4339
  }
@@ -4603,7 +4394,7 @@ var console_logger_exports = {};
4603
4394
  __export(console_logger_exports, {
4604
4395
  ConsoleLogger: () => ConsoleLogger
4605
4396
  });
4606
- import { Guards as Guards47, LOG_LEVEL as LOG_LEVEL5 } from "@xeno-js/shared";
4397
+ import { Guards as Guards44, LOG_LEVEL } from "@xeno-js/shared";
4607
4398
  var ConsoleLogger;
4608
4399
  var init_console_logger = __esm({
4609
4400
  "src/infrastructure/loggers/console.logger.ts"() {
@@ -4619,22 +4410,22 @@ var init_console_logger = __esm({
4619
4410
  * @since 2025-09-30
4620
4411
  * @link https://github.com/xeno-js/xeno-js
4621
4412
  */
4622
- constructor(_minLevel = LOG_LEVEL5.DEBUG) {
4413
+ constructor(_minLevel = LOG_LEVEL.DEBUG) {
4623
4414
  this._minLevel = _minLevel;
4624
4415
  }
4625
4416
  _minLevel;
4626
4417
  track(level, message, context, error = void 0) {
4627
4418
  if (level < this._minLevel) return;
4628
4419
  const logMessage = `[${level}] ${message}`;
4629
- const payload = Guards47.isDefined(error) ? { ...context, error } : context;
4420
+ const payload = Guards44.isDefined(error) ? { ...context, error } : context;
4630
4421
  switch (level) {
4631
- case LOG_LEVEL5.ERROR:
4422
+ case LOG_LEVEL.ERROR:
4632
4423
  console.error(logMessage, payload ?? {});
4633
4424
  break;
4634
- case LOG_LEVEL5.WARN:
4425
+ case LOG_LEVEL.WARN:
4635
4426
  console.warn(logMessage, payload ?? {});
4636
4427
  break;
4637
- case LOG_LEVEL5.DEBUG:
4428
+ case LOG_LEVEL.DEBUG:
4638
4429
  console.debug(logMessage, payload ?? {});
4639
4430
  break;
4640
4431
  default:
@@ -4646,6 +4437,180 @@ var init_console_logger = __esm({
4646
4437
  }
4647
4438
  });
4648
4439
 
4440
+ // src/infrastructure/loggers/sentry.logger.ts
4441
+ import { Guards as Guards45, LOG_LEVEL as LOG_LEVEL2 } from "@xeno-js/shared";
4442
+ var SentryLogger;
4443
+ var init_sentry_logger = __esm({
4444
+ "src/infrastructure/loggers/sentry.logger.ts"() {
4445
+ "use strict";
4446
+ SentryLogger = class {
4447
+ constructor(_client, _minLevel) {
4448
+ this._client = _client;
4449
+ this._minLevel = _minLevel;
4450
+ }
4451
+ _client;
4452
+ _minLevel;
4453
+ track(level, message, context = void 0, error = void 0) {
4454
+ if (level < this._minLevel) return;
4455
+ if (level === LOG_LEVEL2.ERROR || level === LOG_LEVEL2.WARN) {
4456
+ this._client.withScope((scope) => {
4457
+ if (Guards45.isDefined(context)) scope.setExtras(context);
4458
+ if (Guards45.isDefined(error)) {
4459
+ this._client.captureException(error);
4460
+ } else {
4461
+ this._client.captureMessage(message, "warning");
4462
+ }
4463
+ });
4464
+ }
4465
+ }
4466
+ };
4467
+ }
4468
+ });
4469
+
4470
+ // src/infrastructure/factories/sentry-logger.factory.ts
4471
+ var sentry_logger_factory_exports = {};
4472
+ __export(sentry_logger_factory_exports, {
4473
+ SentryLoggerFactory: () => SentryLoggerFactory
4474
+ });
4475
+ import * as Sentry from "@sentry/node";
4476
+ import { Guards as Guards46, LOG_LEVEL as LOG_LEVEL3 } from "@xeno-js/shared";
4477
+ var SentryLoggerFactory;
4478
+ var init_sentry_logger_factory = __esm({
4479
+ "src/infrastructure/factories/sentry-logger.factory.ts"() {
4480
+ "use strict";
4481
+ init_sentry_logger();
4482
+ SentryLoggerFactory = class {
4483
+ create(config) {
4484
+ const level = config.level ?? LOG_LEVEL3.WARN;
4485
+ const sentryConfig = config.sentry?.config;
4486
+ const env = sentryConfig?.environment ?? process.env.NODE_ENV ?? "development";
4487
+ if (!Guards46.isDefined(sentryConfig))
4488
+ throw new Error("Sentry configuration is required when Sentry logging is enabled.");
4489
+ if (!Guards46.isDefined(sentryConfig.dsn))
4490
+ throw new Error("Sentry DSN is required when Sentry logging is enabled.");
4491
+ Sentry.init({
4492
+ dsn: sentryConfig.dsn,
4493
+ environment: env,
4494
+ tracesSampleRate: env === "production" ? 0.1 : 1,
4495
+ integrations: [Sentry.httpIntegration()],
4496
+ beforeSend(event, hint) {
4497
+ const error = hint.originalException;
4498
+ if (error instanceof Error && error.name === "ZodError") {
4499
+ return null;
4500
+ }
4501
+ return event;
4502
+ }
4503
+ });
4504
+ return new SentryLogger(Sentry, level);
4505
+ }
4506
+ };
4507
+ }
4508
+ });
4509
+
4510
+ // src/infrastructure/loggers/pino.logger.ts
4511
+ import { Guards as Guards47, LOG_LEVEL as LOG_LEVEL4 } from "@xeno-js/shared";
4512
+ var PinoLogger;
4513
+ var init_pino_logger = __esm({
4514
+ "src/infrastructure/loggers/pino.logger.ts"() {
4515
+ "use strict";
4516
+ PinoLogger = class {
4517
+ /**
4518
+ * 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.
4519
+ * @param _logger The Pino logger instance used for logging messages.
4520
+ * @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.
4521
+
4522
+ *
4523
+ * @author Xeno
4524
+ * @version 1.0.0
4525
+ * @since 2025-09-30
4526
+ * @link https://github.com/xeno-js/xeno-js
4527
+ */
4528
+ constructor(_logger, _minLevel = LOG_LEVEL4.DEBUG) {
4529
+ this._logger = _logger;
4530
+ this._minLevel = _minLevel;
4531
+ }
4532
+ _logger;
4533
+ _minLevel;
4534
+ track(level, message, context, error = void 0) {
4535
+ if (level < this._minLevel) return;
4536
+ const payload = Guards47.isDefined(error) ? { ...context, error } : context;
4537
+ switch (level) {
4538
+ case LOG_LEVEL4.ERROR:
4539
+ this._logger.error(payload ?? {}, message);
4540
+ break;
4541
+ case LOG_LEVEL4.WARN:
4542
+ this._logger.warn(payload ?? {}, message);
4543
+ break;
4544
+ case LOG_LEVEL4.DEBUG:
4545
+ this._logger.debug(payload ?? {}, message);
4546
+ break;
4547
+ default:
4548
+ this._logger.info(payload ?? {}, message);
4549
+ break;
4550
+ }
4551
+ }
4552
+ };
4553
+ }
4554
+ });
4555
+
4556
+ // src/infrastructure/factories/pino-logger.factory.ts
4557
+ var pino_logger_factory_exports = {};
4558
+ __export(pino_logger_factory_exports, {
4559
+ PinoLoggerFactory: () => PinoLoggerFactory
4560
+ });
4561
+ import { LOG_LEVEL as LOG_LEVEL5 } from "@xeno-js/shared";
4562
+ import pino from "pino";
4563
+ var PinoLoggerFactory;
4564
+ var init_pino_logger_factory = __esm({
4565
+ "src/infrastructure/factories/pino-logger.factory.ts"() {
4566
+ "use strict";
4567
+ init_pino_logger();
4568
+ PinoLoggerFactory = class {
4569
+ create(config) {
4570
+ const level = config.level ?? LOG_LEVEL5.DEBUG;
4571
+ const env = config.pino.config?.env ?? process.env.NODE_ENV ?? "development";
4572
+ const destinationType = config.pino.config?.destination ?? "stdout";
4573
+ const filePath = config.pino.config?.filePath ?? "logs/app.log";
4574
+ const prettyPrint = config.pino.config?.prettyPrint ?? env === "development";
4575
+ const options = {
4576
+ level: "trace",
4577
+ serializers: {
4578
+ err: pino.stdSerializers.err
4579
+ },
4580
+ timestamp: pino.stdTimeFunctions.isoTime,
4581
+ redact: {
4582
+ paths: ["password", "token", "secret", "authorization", "headers.authorization"],
4583
+ censor: "***"
4584
+ }
4585
+ };
4586
+ if (prettyPrint) {
4587
+ return new PinoLogger(
4588
+ pino({
4589
+ ...options,
4590
+ transport: {
4591
+ target: "pino-pretty",
4592
+ options: {
4593
+ colorize: true,
4594
+ ignore: "pid,hostname",
4595
+ translateTime: "SYS:standard"
4596
+ }
4597
+ }
4598
+ }),
4599
+ level
4600
+ );
4601
+ }
4602
+ if (destinationType === "file") {
4603
+ const destination = pino.destination({ dest: filePath, sync: false });
4604
+ return new PinoLogger(pino(options, destination), level);
4605
+ } else {
4606
+ const stream = pino.destination({ dest: 1, sync: false });
4607
+ return new PinoLogger(pino(options, stream), level);
4608
+ }
4609
+ }
4610
+ };
4611
+ }
4612
+ });
4613
+
4649
4614
  // src/infrastructure/modules/utils/logger.utils.ts
4650
4615
  var logger_utils_exports = {};
4651
4616
  __export(logger_utils_exports, {
@@ -4746,22 +4711,6 @@ var init_modules = __esm({
4746
4711
  });
4747
4712
 
4748
4713
  // src/index.ts
4749
- var index_exports = {};
4750
- __export(index_exports, {
4751
- AppBuilder: () => AppBuilder,
4752
- BaseAuthorizationStrategy: () => BaseAuthorizationStrategy,
4753
- BaseController: () => BaseController,
4754
- BaseHandler: () => BaseHandler,
4755
- BaseHttpAdapter: () => BaseHttpAdapter,
4756
- BasePostgresSqlDataSource: () => BasePostgresSqlDataSource,
4757
- BaseQuery: () => Query,
4758
- BaseSqliteSqlDataSource: () => BaseSqliteSqlDataSource,
4759
- ContainerUtils: () => ContainerUtils,
4760
- ReadDao: () => ReadDao,
4761
- Repository: () => Repository,
4762
- Specification: () => Specification,
4763
- SupabaseServerAuthFactory: () => SupabaseServerAuthFactory
4764
- });
4765
4714
  init_application();
4766
4715
 
4767
4716
  // src/infrastructure/builder/app.builder.ts
@@ -5041,16 +4990,10 @@ var AppBuilder = class {
5041
4990
  _container = new ServiceContainer();
5042
4991
  _configuration;
5043
4992
  _isBuilded = false;
5044
- constructor(container) {
4993
+ constructor(container, configurationService) {
5045
4994
  this._container = container ?? new ServiceContainer();
5046
- this._container.addSingleton(
5047
- TOKENS4.CONFIGURATION_SERVICE,
5048
- () => new EnvironmentConfigurationService()
5049
- );
5050
- this._configuration = this._container.resolve(TOKENS4.CONFIGURATION_SERVICE);
5051
- this._middlewareConfig.allowOrigins?.push(
5052
- this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
5053
- );
4995
+ this._configuration = configurationService ?? new EnvironmentConfigurationService();
4996
+ this._container.addSingleton(TOKENS4.CONFIGURATION_SERVICE, () => this._configuration);
5054
4997
  this.addContext();
5055
4998
  }
5056
4999
  // --- Module Configurations ---
@@ -5414,12 +5357,11 @@ var AppBuilder = class {
5414
5357
  * @description Resolves a service from the dependency injection container.
5415
5358
  * @param token The injection token used to identify the service.
5416
5359
  * @returns The resolved service instance.
5417
-
5418
- *
5360
+ *
5419
5361
  * @author Xeno
5420
5362
  * @version 1.0.0
5421
5363
  * @since 2025-09-30
5422
- * @link https://github.com/xeno-js/xeno-js
5364
+ * @link https://github.com/xeno-js/xeno-js
5423
5365
  */
5424
5366
  resolve(token) {
5425
5367
  return this._container.resolve(token);
@@ -5430,12 +5372,11 @@ var AppBuilder = class {
5430
5372
  /**
5431
5373
  * @description Finalizes the configuration and initializes all registered modules in the container.
5432
5374
  * @returns The fully configured ServiceContainer.
5433
-
5434
- *
5375
+ *
5435
5376
  * @author Xeno
5436
5377
  * @version 1.0.0
5437
5378
  * @since 2025-09-30
5438
- * @link https://github.com/xeno-js/xeno-js
5379
+ * @link https://github.com/xeno-js/xeno-js
5439
5380
  */
5440
5381
  async build() {
5441
5382
  if (this._isBuilded) return this._container;
@@ -5467,12 +5408,11 @@ var AppBuilder = class {
5467
5408
  // ─────────────────────────────────────────────────────────────────────────────
5468
5409
  /**
5469
5410
  * @description Queues the configuration of the CQRS pipeline module if it has not already been queued. This method ensures that the pipeline module is only added once, even if multiple pipeline-related configurations are made.
5470
-
5471
- *
5411
+ *
5472
5412
  * @author Xeno
5473
5413
  * @version 1.0.0
5474
5414
  * @since 2025-09-30
5475
- * @link https://github.com/xeno-js/xeno-js
5415
+ * @link https://github.com/xeno-js/xeno-js
5476
5416
  */
5477
5417
  _queuePipelineModule() {
5478
5418
  if (this._isPipelineModuleQueued) return;
@@ -5492,12 +5432,11 @@ var AppBuilder = class {
5492
5432
  }
5493
5433
  /**
5494
5434
  * @description Queues the configuration of the middleware module if it has not already been queued. This method ensures that the middleware module is only added once, even if multiple middleware-related configurations are made.
5495
-
5496
- *
5435
+ *
5497
5436
  * @author Xeno
5498
5437
  * @version 1.0.0
5499
5438
  * @since 2025-09-30
5500
- * @link https://github.com/xeno-js/xeno-js
5439
+ * @link https://github.com/xeno-js/xeno-js
5501
5440
  */
5502
5441
  _queueMiddlewareModule() {
5503
5442
  if (this._isMiddlewareModuleQueued) return;
@@ -5543,60 +5482,11 @@ var AppBuilder = class {
5543
5482
  }
5544
5483
  };
5545
5484
 
5546
- // src/infrastructure/index.ts
5547
- init_cache();
5548
-
5549
- // src/infrastructure/context/index.ts
5550
- init_request_context();
5551
-
5552
- // src/infrastructure/datasources/base-postgressql.datasource.ts
5553
- var BasePostgresSqlDataSource = class {
5554
- constructor(_db) {
5555
- this._db = _db;
5556
- }
5557
- _db;
5558
- /**
5559
- * @description Returns the database connection.
5560
- * @returns {NodePgDatabase<TSchema>} The database connection.
5561
- */
5562
- get db() {
5563
- return this._db;
5564
- }
5565
- };
5566
-
5567
- // src/infrastructure/datasources/base-sqllite.datasource.ts
5568
- var BaseSqliteSqlDataSource = class {
5569
- constructor(_db) {
5570
- this._db = _db;
5571
- }
5572
- _db;
5573
- /**
5574
- * @description Returns the SQLite database connection.
5575
- * @returns {LibSQLDatabase<TSchema>} The database connection.
5576
- */
5577
- get db() {
5578
- return this._db;
5579
- }
5580
- };
5581
-
5582
- // src/infrastructure/datasources/remote.datasource.ts
5583
- import { AppError as AppError15, Result as Result16 } from "@xeno-js/shared";
5584
-
5585
- // src/infrastructure/index.ts
5586
- init_factories();
5587
- init_http();
5588
- init_idempotency();
5589
-
5590
- // src/infrastructure/loggers/index.ts
5591
- init_console_logger();
5592
- init_pino_logger();
5593
- init_sentry_logger();
5594
-
5595
- // src/infrastructure/index.ts
5596
- init_modules();
5485
+ // src/infrastructure/http/index.ts
5486
+ init_base_http_adapter();
5597
5487
 
5598
5488
  // src/infrastructure/repositories/read-dao.ts
5599
- import { AppError as AppError16, Result as Result17 } from "@xeno-js/shared";
5489
+ import { AppError as AppError15, Result as Result16 } from "@xeno-js/shared";
5600
5490
  import { Guards as Guards49 } from "@xeno-js/shared";
5601
5491
  var ReadDao = class {
5602
5492
  /**
@@ -5617,22 +5507,22 @@ var ReadDao = class {
5617
5507
  _dataSource;
5618
5508
  _mapper;
5619
5509
  async findById(id, ctx, signal) {
5620
- AppError16.throwIfAborted(signal, "ReadDao.findById");
5510
+ AppError15.throwIfAborted(signal, "ReadDao.findById");
5621
5511
  const result = await this._dataSource.findById(id, ctx, signal);
5622
- if (Guards49.isNullOrEmpty(result)) return Result17.ok();
5512
+ if (Guards49.isNullOrEmpty(result)) return Result16.ok();
5623
5513
  const entity = this._mapper.toEntity(result);
5624
- return Result17.ok(entity);
5514
+ return Result16.ok(entity);
5625
5515
  }
5626
5516
  async findAll(ctx, signal) {
5627
- AppError16.throwIfAborted(signal, "ReadDao.findAll");
5517
+ AppError15.throwIfAborted(signal, "ReadDao.findAll");
5628
5518
  const results = await this._dataSource.findAll(ctx, signal);
5629
5519
  const entities = results.map((result) => this._mapper.toEntity(result));
5630
- return Result17.ok(entities);
5520
+ return Result16.ok(entities);
5631
5521
  }
5632
5522
  };
5633
5523
 
5634
5524
  // src/infrastructure/repositories/repository.ts
5635
- import { AppError as AppError17, Result as Result18 } from "@xeno-js/shared";
5525
+ import { AppError as AppError16, Result as Result17 } from "@xeno-js/shared";
5636
5526
  import { Guards as Guards50 } from "@xeno-js/shared";
5637
5527
  var Repository = class {
5638
5528
  /**
@@ -5653,51 +5543,39 @@ var Repository = class {
5653
5543
  _dataSource;
5654
5544
  _mapper;
5655
5545
  async findById(id, ctx, signal) {
5656
- AppError17.throwIfAborted(signal, "Repository.findById");
5546
+ AppError16.throwIfAborted(signal, "Repository.findById");
5657
5547
  const result = await this._dataSource.findById(id, ctx, signal);
5658
- if (Guards50.isNullOrEmpty(result)) return Result18.ok();
5548
+ if (Guards50.isNullOrEmpty(result)) return Result17.ok();
5659
5549
  const entity = this._mapper.toEntity(result);
5660
- return Result18.ok(entity);
5550
+ return Result17.ok(entity);
5661
5551
  }
5662
5552
  async findAll(ctx, signal) {
5663
- AppError17.throwIfAborted(signal, "Repository.findAll");
5553
+ AppError16.throwIfAborted(signal, "Repository.findAll");
5664
5554
  const results = await this._dataSource.findAll(ctx, signal);
5665
5555
  const entities = results.map((result) => this._mapper.toEntity(result));
5666
- return Result18.ok(entities);
5556
+ return Result17.ok(entities);
5667
5557
  }
5668
5558
  async save(entity, signal) {
5669
5559
  const dto = this._mapper.toDto(entity);
5670
- AppError17.throwIfAborted(signal, "Repository.save");
5560
+ AppError16.throwIfAborted(signal, "Repository.save");
5671
5561
  await this._dataSource.insert(dto, signal);
5672
- return Result18.ok();
5562
+ return Result17.ok();
5673
5563
  }
5674
5564
  async delete(entity, ctx, signal) {
5675
5565
  const dto = this._mapper.toDto(entity);
5676
- AppError17.throwIfAborted(signal, "Repository.delete");
5566
+ AppError16.throwIfAborted(signal, "Repository.delete");
5677
5567
  await this._dataSource.delete(dto, ctx, signal);
5678
- return Result18.ok();
5568
+ return Result17.ok();
5679
5569
  }
5680
5570
  async update(id, entity, ctx, signal) {
5681
5571
  const dto = this._mapper.toPartialDto(entity);
5682
- AppError17.throwIfAborted(signal, "Repository.update");
5572
+ AppError16.throwIfAborted(signal, "Repository.update");
5683
5573
  await this._dataSource.update(id, dto, ctx, signal);
5684
- return Result18.ok();
5574
+ return Result17.ok();
5685
5575
  }
5686
5576
  };
5687
5577
 
5688
- // src/infrastructure/index.ts
5689
- init_services();
5690
-
5691
- // src/infrastructure/transaction/index.ts
5692
- init_unit_of_work();
5693
-
5694
- // src/infrastructure/db/drizzle.types.ts
5695
- var drizzle_types_exports = {};
5696
- __reExport(drizzle_types_exports, drizzle_orm_star);
5697
- import * as drizzle_orm_star from "drizzle-orm";
5698
-
5699
5578
  // src/index.ts
5700
- __reExport(index_exports, drizzle_types_exports);
5701
5579
  init_presentation();
5702
5580
  export * from "@xeno-js/shared";
5703
5581
  import { Query } from "@xeno-js/shared";
@@ -5707,14 +5585,11 @@ export {
5707
5585
  BaseController,
5708
5586
  BaseHandler,
5709
5587
  BaseHttpAdapter,
5710
- BasePostgresSqlDataSource,
5711
- Query as BaseQuery,
5712
- BaseSqliteSqlDataSource,
5713
5588
  ContainerUtils,
5589
+ Query,
5714
5590
  ReadDao,
5715
5591
  Repository,
5716
- Specification,
5717
- SupabaseServerAuthFactory
5592
+ Specification
5718
5593
  };
5719
5594
  /**
5720
5595
  * @description The CsrfCookieMiddleware class implements the IMiddleware interface, providing a concrete implementation for handling CSRF token validation and cookie management. It checks the incoming request for a valid CSRF token and sets a CSRF cookie if necessary.