@xeno-js/core 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1509,15 +1509,15 @@ var init_logger_utils = __esm({
1509
1509
  */
1510
1510
  async addLogger(container, opts) {
1511
1511
  const loggerDependencies = [];
1512
- const { Guards: Guards45, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1513
- if (!Guards45.isDefined(opts) || opts.console) {
1512
+ const { Guards: Guards46, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1513
+ if (!Guards46.isDefined(opts) || opts.console) {
1514
1514
  const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
1515
1515
  container.addSingleton(TOKENS4.CONSOLE_LOGGER, () => new ConsoleLogger2(opts?.level));
1516
1516
  loggerDependencies.push(TOKENS4.CONSOLE_LOGGER);
1517
1517
  }
1518
1518
  const customLoggerFactories = [];
1519
- if (Guards45.isDefined(opts)) {
1520
- if (Guards45.isDefined(opts.sentry.config)) {
1519
+ if (Guards46.isDefined(opts)) {
1520
+ if (Guards46.isDefined(opts.sentry.config)) {
1521
1521
  const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
1522
1522
  container.addSingleton(TOKENS4.SENTRY_LOGGER, () => {
1523
1523
  const factory = new SentryLoggerFactory2();
@@ -1525,7 +1525,7 @@ var init_logger_utils = __esm({
1525
1525
  });
1526
1526
  loggerDependencies.push(TOKENS4.SENTRY_LOGGER);
1527
1527
  }
1528
- if (Guards45.isDefined(opts.pino.config)) {
1528
+ if (Guards46.isDefined(opts.pino.config)) {
1529
1529
  const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
1530
1530
  container.addSingleton(TOKENS4.PINO_LOGGER, () => {
1531
1531
  const factory = new PinoLoggerFactory2();
@@ -1533,10 +1533,10 @@ var init_logger_utils = __esm({
1533
1533
  });
1534
1534
  loggerDependencies.push(TOKENS4.PINO_LOGGER);
1535
1535
  }
1536
- if (!Guards45.isNullOrEmpty(opts.customLoggers)) {
1536
+ if (!Guards46.isNullOrEmpty(opts.customLoggers)) {
1537
1537
  const customLoggers = opts.customLoggers;
1538
1538
  customLoggers.forEach((f) => {
1539
- if (Guards45.isDefined(f)) {
1539
+ if (Guards46.isDefined(f)) {
1540
1540
  customLoggerFactories.push(f);
1541
1541
  }
1542
1542
  });
@@ -1709,8 +1709,8 @@ var init_cache_utils = __esm({
1709
1709
  * @link https://github.com/xeno-js/xeno-js
1710
1710
  */
1711
1711
  async addCache(container, opts) {
1712
- const { Guards: Guards45, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1713
- if (!opts.inMemory && !Guards45.isDefined(opts.redis)) {
1712
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1713
+ if (!opts.inMemory && !Guards46.isDefined(opts.redis)) {
1714
1714
  throw new Error(
1715
1715
  "No cache strategies are configured. Please provide at least one cache strategy."
1716
1716
  );
@@ -1720,12 +1720,12 @@ var init_cache_utils = __esm({
1720
1720
  TOKENS4.CACHE_KEY_BUILDER,
1721
1721
  (c) => new CacheKeyBuilder(c.resolve(TOKENS4.IDENTITY_ACCESSOR))
1722
1722
  );
1723
- if (opts.inMemory || !Guards45.isDefined(opts.redis)) {
1723
+ if (opts.inMemory || !Guards46.isDefined(opts.redis)) {
1724
1724
  const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
1725
1725
  container.addSingleton(TOKENS4.CACHE, () => new InMemoryCacheExtended2());
1726
1726
  return;
1727
1727
  }
1728
- if (Guards45.isDefined(opts.redis)) {
1728
+ if (Guards46.isDefined(opts.redis)) {
1729
1729
  const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
1730
1730
  container.addSingleton(TOKENS4.CACHE, () => {
1731
1731
  const config = opts.redis;
@@ -1925,29 +1925,20 @@ var init_csrf_token_service = __esm({
1925
1925
  async generate(subject) {
1926
1926
  const randomBuffer = this._cryptoService.randomBytes(32);
1927
1927
  const nonce = btoa(String.fromCharCode(...randomBuffer)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
1928
- const signature = await this._cryptoService.hmacSha256(
1929
- this._secret,
1930
- `${subject}.${nonce}`
1931
- );
1928
+ const signature = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
1932
1929
  return `${nonce}.${signature}`;
1933
1930
  }
1934
1931
  async validate(token, subject) {
1935
1932
  const separatorIndex = token.indexOf(".");
1936
- if (separatorIndex <= 0)
1937
- return false;
1933
+ if (separatorIndex <= 0) return false;
1938
1934
  const nonce = token.slice(0, separatorIndex);
1939
1935
  const signature = token.slice(separatorIndex + 1);
1940
- if (import_shared44.Guards.isNullOrEmpty(nonce) || import_shared44.Guards.isNullOrEmpty(signature))
1941
- return false;
1942
- const expected = await this._cryptoService.hmacSha256(
1943
- this._secret,
1944
- `${subject}.${nonce}`
1945
- );
1936
+ if (import_shared44.Guards.isNullOrEmpty(nonce) || import_shared44.Guards.isNullOrEmpty(signature)) return false;
1937
+ const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
1946
1938
  const encoder = new TextEncoder();
1947
1939
  const actualBuffer = encoder.encode(signature);
1948
1940
  const expectedBuffer = encoder.encode(expected);
1949
- if (actualBuffer.length !== expectedBuffer.length)
1950
- return false;
1941
+ if (actualBuffer.length !== expectedBuffer.length) return false;
1951
1942
  return this._cryptoService.timingSafeEqual(actualBuffer, expectedBuffer);
1952
1943
  }
1953
1944
  };
@@ -2046,15 +2037,12 @@ var init_http_cookie_extractor = __esm({
2046
2037
  import_shared47 = require("@xeno-js/shared");
2047
2038
  HttpCookieExtractor = class {
2048
2039
  extract(cookie) {
2049
- if (!import_shared47.Guards.isDefined(cookie.header))
2050
- return void 0;
2040
+ if (!import_shared47.Guards.isDefined(cookie.header)) return void 0;
2051
2041
  for (const rawCookie of cookie.header.split(";")) {
2052
2042
  const separatorIndex = rawCookie.indexOf("=");
2053
- if (separatorIndex <= 0)
2054
- continue;
2043
+ if (separatorIndex <= 0) continue;
2055
2044
  const name = rawCookie.slice(0, separatorIndex).trim();
2056
- if (name !== cookie.name)
2057
- continue;
2045
+ if (name !== cookie.name) continue;
2058
2046
  const value = rawCookie.slice(separatorIndex + 1).trim();
2059
2047
  try {
2060
2048
  return decodeURIComponent(value);
@@ -2111,12 +2099,10 @@ var init_http_header_extractor = __esm({
2111
2099
  const expiration = import_shared48.StringHelper.getSingleValue(headers["x-expiration"]);
2112
2100
  const csrf = import_shared48.StringHelper.getSingleValue(headers["x-csrf-token"]);
2113
2101
  const cookieHeader = import_shared48.StringHelper.getSingleValue(headers["cookie"]);
2114
- const csrfCookie = this._cookieExtractor.extract(
2115
- {
2116
- header: cookieHeader,
2117
- name: this._cookieName
2118
- }
2119
- );
2102
+ const csrfCookie = this._cookieExtractor.extract({
2103
+ header: cookieHeader,
2104
+ name: this._cookieName
2105
+ });
2120
2106
  const origin = import_shared48.StringHelper.getSingleValue(headers["origin"]);
2121
2107
  const cleanOrigin = import_shared48.HttpHelper.sanitizeOriginUrl(origin);
2122
2108
  const referer = import_shared48.StringHelper.getSingleValue(headers["referer"]);
@@ -2236,10 +2222,8 @@ var init_client_ip_resolver = __esm({
2236
2222
  if (!import_shared51.Guards.isDefined(socketIp))
2237
2223
  return !import_shared51.Guards.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
2238
2224
  const isTrustedProxy = this._trustedProxies.includes(socketIp);
2239
- if (!isTrustedProxy)
2240
- return socketIp;
2241
- if (import_shared51.Guards.isDefined(clientIp))
2242
- return clientIp.split(",")[0].trim();
2225
+ if (!isTrustedProxy) return socketIp;
2226
+ if (import_shared51.Guards.isDefined(clientIp)) return clientIp.split(",")[0].trim();
2243
2227
  return socketIp;
2244
2228
  }
2245
2229
  };
@@ -2784,8 +2768,8 @@ var init_auth_utils = __esm({
2784
2768
  const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
2785
2769
  const pipelines = [];
2786
2770
  const strategies = [];
2787
- const { Guards: Guards45 } = await import("@xeno-js/shared");
2788
- if (Guards45.isDefined(opts.policies)) {
2771
+ const { Guards: Guards46 } = await import("@xeno-js/shared");
2772
+ if (Guards46.isDefined(opts.policies)) {
2789
2773
  const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2790
2774
  container.addSingleton(TOKENS4.POLICY_REGISTRY, () => new PolicyRegistry2());
2791
2775
  const policyRegistry = opts.policies;
@@ -2794,16 +2778,16 @@ var init_auth_utils = __esm({
2794
2778
  for (const [intent, policy] of Object.entries(policyRegistry)) {
2795
2779
  const intentLower = intent.toLowerCase();
2796
2780
  registryInstance.addPolicy(intentLower, policy);
2797
- if (!Guards45.isNullOrEmpty(policy.roles)) {
2781
+ if (!Guards46.isNullOrEmpty(policy.roles)) {
2798
2782
  Policies.add("roles");
2799
2783
  }
2800
- if (!Guards45.isNullOrEmpty(policy.permissions)) {
2784
+ if (!Guards46.isNullOrEmpty(policy.permissions)) {
2801
2785
  Policies.add("permissions");
2802
2786
  }
2803
- if (!Guards45.isNullOrEmpty(policy.userId)) {
2787
+ if (!Guards46.isNullOrEmpty(policy.userId)) {
2804
2788
  Policies.add("userId");
2805
2789
  }
2806
- if (!Guards45.isNullOrEmpty(policy.tenantId)) {
2790
+ if (!Guards46.isNullOrEmpty(policy.tenantId)) {
2807
2791
  Policies.add("tenantId");
2808
2792
  }
2809
2793
  }
@@ -2852,10 +2836,10 @@ var init_auth_utils = __esm({
2852
2836
  strategies.push(TOKENS4.TENANT_AUTHORIZATION_PIPELINE);
2853
2837
  }
2854
2838
  }
2855
- if (!Guards45.isNullOrEmpty(opts.customAuthorizationStrategy)) {
2839
+ if (!Guards46.isNullOrEmpty(opts.customAuthorizationStrategy)) {
2856
2840
  const customStrategies = opts.customAuthorizationStrategy;
2857
2841
  customStrategies.forEach((strategyToken, index) => {
2858
- if (Guards45.isDefined(strategyToken)) {
2842
+ if (Guards46.isDefined(strategyToken)) {
2859
2843
  const token = `CUSTOM_AUTHORIZATION_STRATEGY_${index}`;
2860
2844
  container.addSingleton(token, (c) => {
2861
2845
  return strategyToken(c);
@@ -3058,7 +3042,7 @@ var init_db_module = __esm({
3058
3042
  "use strict";
3059
3043
  DbModule = class {
3060
3044
  async configure(container, opts) {
3061
- const { Guards: Guards45, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3045
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3062
3046
  const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
3063
3047
  const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
3064
3048
  const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
@@ -3075,7 +3059,7 @@ var init_db_module = __esm({
3075
3059
  return new Proxy(db, {
3076
3060
  get(_target, prop, receiver) {
3077
3061
  const activeState = ttx.state;
3078
- if (Guards45.isDefined(activeState)) {
3062
+ if (Guards46.isDefined(activeState)) {
3079
3063
  if (prop === "transaction") {
3080
3064
  return activeState.transaction.bind(activeState);
3081
3065
  }
@@ -3112,14 +3096,14 @@ var init_http_utils = __esm({
3112
3096
  */
3113
3097
  async addAxios(container, opts) {
3114
3098
  const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
3115
- const { Guards: Guards45 } = await import("@xeno-js/shared");
3116
- if (!Guards45.isDefined(opts.token)) {
3099
+ const { Guards: Guards46 } = await import("@xeno-js/shared");
3100
+ if (!Guards46.isDefined(opts.token)) {
3117
3101
  throw new Error("HttpConfig.token is required and must be defined.");
3118
3102
  }
3119
3103
  container.addSingleton(opts.token, () => {
3120
3104
  const factory = new NodeAxiosFactory2();
3121
3105
  const instance = factory.create(opts.client);
3122
- if (!Guards45.hasMethod(instance, "get") || !Guards45.hasMethod(instance, "post") || !Guards45.hasMethod(instance, "put") || !Guards45.hasMethod(instance, "patch") || !Guards45.hasMethod(instance, "delete")) {
3106
+ if (!Guards46.hasMethod(instance, "get") || !Guards46.hasMethod(instance, "post") || !Guards46.hasMethod(instance, "put") || !Guards46.hasMethod(instance, "patch") || !Guards46.hasMethod(instance, "delete")) {
3123
3107
  throw new Error(
3124
3108
  "The created HTTP client instance does not implement the required methods of IHttpClient."
3125
3109
  );
@@ -3146,8 +3130,8 @@ var init_http_utils = __esm({
3146
3130
  });
3147
3131
  },
3148
3132
  async addAllowOrigin(container, opts) {
3149
- const { Guards: Guards45 } = await import("@xeno-js/shared");
3150
- if (Guards45.isNullOrEmpty(opts)) throw new Error("At least an allow origin must be passed");
3133
+ const { Guards: Guards46 } = await import("@xeno-js/shared");
3134
+ if (Guards46.isNullOrEmpty(opts)) throw new Error("At least an allow origin must be passed");
3151
3135
  const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3152
3136
  const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
3153
3137
  const allowOrigin = [];
@@ -3207,13 +3191,13 @@ var init_validation_utils = __esm({
3207
3191
  * @link https://github.com/xeno-js/xeno-js
3208
3192
  */
3209
3193
  async addValidation(container, opts, logger) {
3210
- const { Guards: Guards45, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3211
- if (!Guards45.isDefined(opts.zod) && Guards45.isNullOrEmpty(opts.customValidationStrategy)) {
3194
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3195
+ if (!Guards46.isDefined(opts.zod) && Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
3212
3196
  return [];
3213
3197
  }
3214
3198
  const pipelines = [];
3215
3199
  const validationStrategies = [];
3216
- if (Guards45.isDefined(opts.zod)) {
3200
+ if (Guards46.isDefined(opts.zod)) {
3217
3201
  const config = opts.zod;
3218
3202
  const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_zod_validator_factory(), zod_validator_factory_exports));
3219
3203
  container.addSingleton(TOKENS4.ZOD_VALIDATOR, () => {
@@ -3227,9 +3211,9 @@ var init_validation_utils = __esm({
3227
3211
  validationStrategies.push(TOKENS4.SCHEMA_VALIDATION_STRATEGY);
3228
3212
  }
3229
3213
  const customValidationFactory = [];
3230
- if (!Guards45.isNullOrEmpty(opts.customValidationStrategy)) {
3214
+ if (!Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
3231
3215
  for (const strategyToken of opts.customValidationStrategy) {
3232
- if (Guards45.isDefined(strategyToken)) {
3216
+ if (Guards46.isDefined(strategyToken)) {
3233
3217
  customValidationFactory.push(strategyToken);
3234
3218
  }
3235
3219
  }
@@ -3332,8 +3316,8 @@ var init_pipeline_utils = __esm({
3332
3316
  */
3333
3317
  async addCommand(container, opts) {
3334
3318
  const pipelines = [];
3335
- const { Guards: Guards45, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3336
- if (Guards45.isDefined(opts.idempotency)) {
3319
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3320
+ if (Guards46.isDefined(opts.idempotency)) {
3337
3321
  const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency_store(), idempotency_store_exports));
3338
3322
  container.addSingleton(
3339
3323
  TOKENS4.IDEMPOTENCY_STORE,
@@ -3353,7 +3337,7 @@ var init_pipeline_utils = __esm({
3353
3337
  });
3354
3338
  pipelines.push(TOKENS4.IDEMPOTENCY_PIPELINE);
3355
3339
  }
3356
- if (Guards45.isDefined(opts.concurrency)) {
3340
+ if (Guards46.isDefined(opts.concurrency)) {
3357
3341
  const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3358
3342
  container.addSingleton(TOKENS4.CONCURRENCY_RETRY_PIPELINE, () => {
3359
3343
  const config = opts.concurrency;
@@ -3433,13 +3417,13 @@ var init_cqrs_module = __esm({
3433
3417
  return new PerformancePipeline2(logger, thresholdMs);
3434
3418
  });
3435
3419
  pipelines.push(TOKENS4.PERFORMANCE_PIPELINE);
3436
- const { Guards: Guards45 } = await import("@xeno-js/shared");
3437
- if (Guards45.isDefined(opts.authorization.policies) || Guards45.isDefined(opts.authorization.customAuthorizationStrategy)) {
3420
+ const { Guards: Guards46 } = await import("@xeno-js/shared");
3421
+ if (Guards46.isDefined(opts.authorization.policies) || Guards46.isDefined(opts.authorization.customAuthorizationStrategy)) {
3438
3422
  const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
3439
3423
  const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
3440
3424
  pipelines.push(...authPipelines);
3441
3425
  }
3442
- if (Guards45.isDefined(opts.validation.zod) || Guards45.isDefined(opts.validation.customValidationStrategy)) {
3426
+ if (Guards46.isDefined(opts.validation.zod) || Guards46.isDefined(opts.validation.customValidationStrategy)) {
3443
3427
  const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
3444
3428
  const logger = container.resolve(TOKENS4.LOGGER);
3445
3429
  const validationPipelines = await ValidationUtils2.addValidation(
@@ -3451,11 +3435,11 @@ var init_cqrs_module = __esm({
3451
3435
  }
3452
3436
  const commandPipelines = pipelines;
3453
3437
  const queryPipelines = pipelines;
3454
- if ((Guards45.isDefined(opts.commandBus.idempotency) || opts.queryBus.isEnabled) && opts.isCache) {
3438
+ if ((Guards46.isDefined(opts.commandBus.idempotency) || opts.queryBus.isEnabled) && opts.isCache) {
3455
3439
  const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
3456
3440
  await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
3457
3441
  }
3458
- if (Guards45.isDefined(opts.commandBus.idempotency) || Guards45.isDefined(opts.commandBus.concurrency)) {
3442
+ if (Guards46.isDefined(opts.commandBus.idempotency) || Guards46.isDefined(opts.commandBus.concurrency)) {
3459
3443
  const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
3460
3444
  const newCommandPipelines = await PipelineUtils2.addCommand(container, {
3461
3445
  ...opts.commandBus,
@@ -3854,10 +3838,7 @@ var init_csrf_middleware = __esm({
3854
3838
  }
3855
3839
  );
3856
3840
  }
3857
- if (!import_shared66.Guards.isDefined(identity?.userId) || !await this._csrfTokenService.validate(
3858
- headerToken,
3859
- identity?.userId
3860
- )) {
3841
+ if (!import_shared66.Guards.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
3861
3842
  return import_shared66.HttpHelper.error(
3862
3843
  {
3863
3844
  success: false,
@@ -3905,10 +3886,8 @@ var init_csrf_cookie_middleware = __esm({
3905
3886
  const context = this._requestContext.getContext();
3906
3887
  const identity = context?.identity;
3907
3888
  const network = context?.network;
3908
- if (!import_shared67.Guards.isDefined(identity?.userId))
3909
- return response;
3910
- if (import_shared67.Guards.isDefined(network?.csrfCookie))
3911
- return response;
3889
+ if (!import_shared67.Guards.isDefined(identity?.userId)) return response;
3890
+ if (import_shared67.Guards.isDefined(network?.csrfCookie)) return response;
3912
3891
  const token = await this._csrfTokenService.generate(identity.userId);
3913
3892
  const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
3914
3893
  const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
@@ -3917,10 +3896,7 @@ var init_csrf_cookie_middleware = __esm({
3917
3896
  const existingCookies = response.headers["Set-Cookie"];
3918
3897
  response.headers = {
3919
3898
  ...response.headers ?? {},
3920
- "Set-Cookie": [
3921
- ...existingCookies ?? [],
3922
- cookie
3923
- ]
3899
+ "Set-Cookie": [...existingCookies ?? [], cookie]
3924
3900
  };
3925
3901
  return response;
3926
3902
  }
@@ -3978,6 +3954,27 @@ var init_rate_limiter_middleware = __esm({
3978
3954
  _opts;
3979
3955
  async execute(req, _headers, next) {
3980
3956
  const { network, tracing } = this._ctxAccessor.getContext() ?? {};
3957
+ if (!import_shared69.Guards.isDefined(network?.clientIp))
3958
+ return import_shared69.HttpHelper.error(
3959
+ {
3960
+ success: false,
3961
+ error: {
3962
+ code: import_shared69.ERROR_CODES.SYSTEM_ERROR,
3963
+ message: "IP undefined. Please contact the administrator.",
3964
+ details: `IP undefined. Please contact the administrator.`,
3965
+ path: req.path
3966
+ },
3967
+ correlationId: tracing?.correlationId ?? import_shared69.GuidHelper.generate(),
3968
+ requestId: network?.requestId ?? import_shared69.GuidHelper.generate(),
3969
+ spanId: tracing?.spanId ?? import_shared69.GuidHelper.generate(),
3970
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
3971
+ },
3972
+ import_shared69.STATUS_CODES.SERVICE_UNAVAILABLE,
3973
+ {
3974
+ "Content-Type": [network?.formatIndicator ?? "application/json"],
3975
+ "Retry-After": [String(this._opts.windowSeconds)]
3976
+ }
3977
+ );
3981
3978
  const clientIp = network?.clientIp;
3982
3979
  const cacheKey = `rate_limit:${clientIp}`;
3983
3980
  const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
@@ -3997,7 +3994,7 @@ var init_rate_limiter_middleware = __esm({
3997
3994
  spanId: tracing?.spanId ?? import_shared69.GuidHelper.generate(),
3998
3995
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
3999
3996
  },
4000
- 429,
3997
+ import_shared69.STATUS_CODES.TOO_MANY_REQUESTS,
4001
3998
  {
4002
3999
  "Content-Type": [network?.formatIndicator ?? "application/json"],
4003
4000
  "Retry-After": [String(this._opts.windowSeconds)]
@@ -4219,7 +4216,12 @@ var init_middleware_module = __esm({
4219
4216
  const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4220
4217
  container.addSingleton(
4221
4218
  TOKENS4.SERVICE_EXTRACTOR,
4222
- (c) => new HttpHeaderExtractor2(c.resolve(TOKENS4.BEARER_TOKEN_EXTRACTOR), c.resolve("COOKIE_EXTRACTOR"), opts.trustedIpHeader, opts.csrf?.cookieName ?? "__Host-xeno-csrf")
4219
+ (c) => new HttpHeaderExtractor2(
4220
+ c.resolve(TOKENS4.BEARER_TOKEN_EXTRACTOR),
4221
+ c.resolve("COOKIE_EXTRACTOR"),
4222
+ opts.trustedIpHeader,
4223
+ opts.csrf?.cookieName ?? "__Host-xeno-csrf"
4224
+ )
4223
4225
  );
4224
4226
  if (!opts.isLogger) {
4225
4227
  const { LoggerUtils: LoggerUtils2 } = await Promise.resolve().then(() => (init_logger_utils(), logger_utils_exports));
@@ -4238,16 +4240,9 @@ var init_middleware_module = __esm({
4238
4240
  c.resolve(TOKENS4.LOGGER)
4239
4241
  )
4240
4242
  );
4241
- if (opts.optionsMiddleware) {
4242
- const { OptionsMiddleware: OptionsMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4243
- container.addSingleton(
4244
- TOKENS4.OPTIONS_MIDDLEWARE,
4245
- (c) => new OptionsMiddleware2(c.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR))
4246
- );
4247
- middlewares.push(TOKENS4.OPTIONS_MIDDLEWARE);
4248
- }
4249
4243
  if (!import_shared72.Guards.isNullOrEmpty(opts.allowOrigins)) {
4250
- if (import_shared72.Guards.isDefined(opts.httpConfig.withCredentials) && opts.allowOrigins.includes("*"))
4244
+ const withCredentials = import_shared72.Guards.isDefined(opts.httpConfig.withCredentials) ? opts.httpConfig.withCredentials : false;
4245
+ if (withCredentials && opts.allowOrigins.includes("*"))
4251
4246
  throw new Error("Wildcard CORS origin is not allowed when withCredentials is set to true");
4252
4247
  const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4253
4248
  container.addSingleton("ALLOW_ORIGIN", () => {
@@ -4263,6 +4258,14 @@ var init_middleware_module = __esm({
4263
4258
  });
4264
4259
  middlewares.push(TOKENS4.ALLOW_ORIGIN_MIDDLEWARE);
4265
4260
  }
4261
+ if (opts.optionsMiddleware) {
4262
+ const { OptionsMiddleware: OptionsMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4263
+ container.addSingleton(
4264
+ TOKENS4.OPTIONS_MIDDLEWARE,
4265
+ (c) => new OptionsMiddleware2(c.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR))
4266
+ );
4267
+ middlewares.push(TOKENS4.OPTIONS_MIDDLEWARE);
4268
+ }
4266
4269
  if (opts.cors) {
4267
4270
  const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4268
4271
  container.addSingleton(TOKENS4.CORS_MIDDLEWARE, (c) => {
@@ -4298,18 +4301,23 @@ var init_middleware_module = __esm({
4298
4301
  const csrf = opts.csrf;
4299
4302
  const { CsrfTokenService: CsrfTokenService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4300
4303
  container.addSingleton("CSRF_TOKEN_SERVICE", (c) => {
4301
- return new CsrfTokenService2(
4302
- csrf.secret,
4303
- c.resolve("CRYPTO_SERVICE")
4304
- );
4304
+ return new CsrfTokenService2(csrf.secret, c.resolve("CRYPTO_SERVICE"));
4305
4305
  });
4306
4306
  const { CsrfCookieMiddleware: CsrfCookieMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4307
4307
  container.addSingleton("CSRF_COOKIE_MIDDLEWARE", (c) => {
4308
- return new CsrfCookieMiddleware2(c.resolve(TOKENS4.REQUEST_CONTEXT), c.resolve("CSRF_TOKEN_SERVICE"), csrf);
4308
+ return new CsrfCookieMiddleware2(
4309
+ c.resolve(TOKENS4.REQUEST_CONTEXT),
4310
+ c.resolve("CSRF_TOKEN_SERVICE"),
4311
+ csrf
4312
+ );
4309
4313
  });
4314
+ middlewares.push("CSRF_COOKIE_MIDDLEWARE");
4310
4315
  const { CsrfMiddleware: CsrfMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4311
4316
  container.addSingleton(TOKENS4.CSRF_MIDDLEWARE, (c) => {
4312
- return new CsrfMiddleware2(c.resolve(TOKENS4.REQUEST_CONTEXT), c.resolve("CSRF_TOKEN_SERVICE"));
4317
+ return new CsrfMiddleware2(
4318
+ c.resolve(TOKENS4.REQUEST_CONTEXT),
4319
+ c.resolve("CSRF_TOKEN_SERVICE")
4320
+ );
4313
4321
  });
4314
4322
  middlewares.push(TOKENS4.CSRF_MIDDLEWARE);
4315
4323
  }
@@ -4684,7 +4692,9 @@ var AppBuilder = class {
4684
4692
  () => new EnvironmentConfigurationService()
4685
4693
  );
4686
4694
  this._configuration = this._container.resolve(import_shared73.TOKENS.CONFIGURATION_SERVICE);
4687
- this._middlewareConfig.allowOrigins?.push(this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`);
4695
+ this._middlewareConfig.allowOrigins?.push(
4696
+ this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
4697
+ );
4688
4698
  }
4689
4699
  // --- Module Configurations ---
4690
4700
  _modules = [];