@xeno-js/core 0.1.9 → 0.1.11

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
@@ -1508,47 +1508,31 @@ var init_logger_utils = __esm({
1508
1508
  */
1509
1509
  async addLogger(container, opts) {
1510
1510
  const loggerDependencies = [];
1511
- const { Guards: Guards47, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1512
- if (!Guards47.isDefined(opts) || opts.console) {
1511
+ const { Guards: Guards46, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1512
+ if (!Guards46.isDefined(opts) || opts.console) {
1513
1513
  const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
1514
- container.addSingleton(TOKENS4.CONSOLE_LOGGER, () => new ConsoleLogger2(opts?.level));
1515
- loggerDependencies.push(TOKENS4.CONSOLE_LOGGER);
1514
+ loggerDependencies.push(new ConsoleLogger2(opts?.level));
1516
1515
  }
1517
- const customLoggerFactories = [];
1518
- if (Guards47.isDefined(opts)) {
1519
- if (Guards47.isDefined(opts.sentry.config)) {
1516
+ if (Guards46.isDefined(opts)) {
1517
+ if (Guards46.isDefined(opts.sentry.config)) {
1520
1518
  const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
1521
- container.addSingleton(TOKENS4.SENTRY_LOGGER, () => {
1522
- const factory = new SentryLoggerFactory2();
1523
- return factory.create(opts);
1524
- });
1525
- loggerDependencies.push(TOKENS4.SENTRY_LOGGER);
1519
+ loggerDependencies.push(new SentryLoggerFactory2().create(opts));
1526
1520
  }
1527
- if (Guards47.isDefined(opts.pino.config)) {
1521
+ if (Guards46.isDefined(opts.pino.config)) {
1528
1522
  const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
1529
- container.addSingleton(TOKENS4.PINO_LOGGER, () => {
1530
- const factory = new PinoLoggerFactory2();
1531
- return factory.create(opts);
1532
- });
1533
- loggerDependencies.push(TOKENS4.PINO_LOGGER);
1523
+ loggerDependencies.push(new PinoLoggerFactory2().create(opts));
1534
1524
  }
1535
- if (!Guards47.isNullOrEmpty(opts.customLoggers)) {
1525
+ if (!Guards46.isNullOrEmpty(opts.customLoggers)) {
1536
1526
  const customLoggers = opts.customLoggers;
1537
- customLoggers.forEach((f) => {
1538
- if (Guards47.isDefined(f)) {
1539
- customLoggerFactories.push(f);
1540
- }
1527
+ customLoggers.forEach((fn) => {
1528
+ if (Guards46.isDefined(fn)) loggerDependencies.push(fn(container));
1541
1529
  });
1542
1530
  }
1543
1531
  }
1544
1532
  const { BaseLogger } = await import("@xeno-js/shared");
1545
1533
  container.addSingleton(TOKENS4.LOGGER, (c) => {
1546
1534
  const context = c.resolve(TOKENS4.CONTEXT_ACCESSOR);
1547
- const resolvedDependencies = [
1548
- ...loggerDependencies.map((token) => c.resolve(token)),
1549
- ...customLoggerFactories.map((factory) => factory(c))
1550
- ];
1551
- return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, resolvedDependencies);
1535
+ return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, loggerDependencies);
1552
1536
  });
1553
1537
  }
1554
1538
  });
@@ -1708,8 +1692,8 @@ var init_cache_utils = __esm({
1708
1692
  * @link https://github.com/xeno-js/xeno-js
1709
1693
  */
1710
1694
  async addCache(container, opts) {
1711
- const { Guards: Guards47, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1712
- if (!opts.inMemory && !Guards47.isDefined(opts.redis)) {
1695
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1696
+ if (!opts.inMemory && !Guards46.isDefined(opts.redis)) {
1713
1697
  throw new Error(
1714
1698
  "No cache strategies are configured. Please provide at least one cache strategy."
1715
1699
  );
@@ -1719,12 +1703,12 @@ var init_cache_utils = __esm({
1719
1703
  TOKENS4.CACHE_KEY_BUILDER,
1720
1704
  (c) => new CacheKeyBuilder(c.resolve(TOKENS4.IDENTITY_ACCESSOR))
1721
1705
  );
1722
- if (opts.inMemory || !Guards47.isDefined(opts.redis)) {
1706
+ if (opts.inMemory || !Guards46.isDefined(opts.redis)) {
1723
1707
  const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
1724
1708
  container.addSingleton(TOKENS4.CACHE, () => new InMemoryCacheExtended2());
1725
1709
  return;
1726
1710
  }
1727
- if (Guards47.isDefined(opts.redis)) {
1711
+ if (Guards46.isDefined(opts.redis)) {
1728
1712
  const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
1729
1713
  container.addSingleton(TOKENS4.CACHE, () => {
1730
1714
  const config = opts.redis;
@@ -2655,7 +2639,9 @@ var init_supabase_factory = __esm({
2655
2639
  container
2656
2640
  }) {
2657
2641
  if (!Guards33.isDefined(config.ssrOpts)) {
2658
- throw new Error("ISsrCookieHandler is required for @supabase/ssr initialization.");
2642
+ throw new Error(
2643
+ "ISsrCookieHandler is required for @supabase/ssr initialization., Please provide it in the config object."
2644
+ );
2659
2645
  }
2660
2646
  const cookieService = config.ssrOpts(container);
2661
2647
  const client = createServerClient(config.url, config.key, {
@@ -2718,10 +2704,6 @@ var init_user_context_factory = __esm({
2718
2704
  });
2719
2705
 
2720
2706
  // src/infrastructure/factories/zod-validator.factory.ts
2721
- var zod_validator_factory_exports = {};
2722
- __export(zod_validator_factory_exports, {
2723
- ZodValidatorFactory: () => ZodValidatorFactory
2724
- });
2725
2707
  import { ZodValidatorService } from "@xeno-js/shared";
2726
2708
  var ZodValidatorFactory;
2727
2709
  var init_zod_validator_factory = __esm({
@@ -2798,97 +2780,57 @@ var init_auth_utils = __esm({
2798
2780
  */
2799
2781
  async addAuthZ(container, opts) {
2800
2782
  const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
2801
- const pipelines = [];
2802
2783
  const strategies = [];
2803
- const { Guards: Guards47 } = await import("@xeno-js/shared");
2804
- if (Guards47.isDefined(opts.policies)) {
2784
+ const { Guards: Guards46 } = await import("@xeno-js/shared");
2785
+ if (Guards46.isDefined(opts.policies)) {
2805
2786
  const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2806
- container.addSingleton(TOKENS4.POLICY_REGISTRY, () => new PolicyRegistry2());
2807
2787
  const policyRegistry = opts.policies;
2808
- const registryInstance = container.resolve(TOKENS4.POLICY_REGISTRY);
2788
+ const registryInstance = new PolicyRegistry2();
2789
+ const ctxAccessor = container.resolve(TOKENS4.CONTEXT_ACCESSOR);
2809
2790
  const Policies = /* @__PURE__ */ new Set();
2810
2791
  for (const [intent, policy] of Object.entries(policyRegistry)) {
2811
2792
  const intentLower = intent.toLowerCase();
2812
2793
  registryInstance.addPolicy(intentLower, policy);
2813
- if (!Guards47.isNullOrEmpty(policy.roles)) {
2794
+ if (!Guards46.isNullOrEmpty(policy.roles)) {
2814
2795
  Policies.add("roles");
2815
2796
  }
2816
- if (!Guards47.isNullOrEmpty(policy.permissions)) {
2797
+ if (!Guards46.isNullOrEmpty(policy.permissions)) {
2817
2798
  Policies.add("permissions");
2818
2799
  }
2819
- if (!Guards47.isNullOrEmpty(policy.userId)) {
2800
+ if (!Guards46.isNullOrEmpty(policy.userId)) {
2820
2801
  Policies.add("userId");
2821
2802
  }
2822
- if (!Guards47.isNullOrEmpty(policy.tenantId)) {
2803
+ if (!Guards46.isNullOrEmpty(policy.tenantId)) {
2823
2804
  Policies.add("tenantId");
2824
2805
  }
2825
2806
  }
2826
2807
  if (Policies.has("roles")) {
2827
2808
  const { RoleAuthorizationStrategy: RoleAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2828
- container.addSingleton(
2829
- TOKENS4.ROLE_AUTHORIZATION_PIPELINE,
2830
- (c) => new RoleAuthorizationStrategy2(
2831
- c.resolve(TOKENS4.POLICY_REGISTRY),
2832
- c.resolve(TOKENS4.CONTEXT_ACCESSOR)
2833
- )
2834
- );
2835
- strategies.push(TOKENS4.ROLE_AUTHORIZATION_PIPELINE);
2809
+ strategies.push(new RoleAuthorizationStrategy2(registryInstance, ctxAccessor));
2836
2810
  }
2837
2811
  if (Policies.has("permissions")) {
2838
2812
  const { PermissionAuthorizationStrategy: PermissionAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2839
- container.addSingleton(
2840
- TOKENS4.PERMISSION_AUTHORIZATION_PIPELINE,
2841
- (c) => new PermissionAuthorizationStrategy2(
2842
- c.resolve(TOKENS4.POLICY_REGISTRY),
2843
- c.resolve(TOKENS4.CONTEXT_ACCESSOR)
2844
- )
2845
- );
2846
- strategies.push(TOKENS4.PERMISSION_AUTHORIZATION_PIPELINE);
2813
+ strategies.push(new PermissionAuthorizationStrategy2(registryInstance, ctxAccessor));
2847
2814
  }
2848
2815
  if (Policies.has("userId")) {
2849
2816
  const { UserAuthorizationStrategy: UserAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2850
- container.addSingleton(
2851
- TOKENS4.USER_AUTHORIZATION_PIPELINE,
2852
- (c) => new UserAuthorizationStrategy2(
2853
- c.resolve(TOKENS4.POLICY_REGISTRY),
2854
- c.resolve(TOKENS4.CONTEXT_ACCESSOR)
2855
- )
2856
- );
2857
- strategies.push(TOKENS4.USER_AUTHORIZATION_PIPELINE);
2817
+ strategies.push(new UserAuthorizationStrategy2(registryInstance, ctxAccessor));
2858
2818
  }
2859
2819
  if (Policies.has("tenantId")) {
2860
2820
  const { TenantAuthorizationStrategy: TenantAuthorizationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2861
- container.addSingleton(
2862
- TOKENS4.TENANT_AUTHORIZATION_PIPELINE,
2863
- (c) => new TenantAuthorizationStrategy2(
2864
- c.resolve(TOKENS4.POLICY_REGISTRY),
2865
- c.resolve(TOKENS4.CONTEXT_ACCESSOR)
2866
- )
2867
- );
2868
- strategies.push(TOKENS4.TENANT_AUTHORIZATION_PIPELINE);
2821
+ strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
2869
2822
  }
2870
2823
  }
2871
- if (!Guards47.isNullOrEmpty(opts.customAuthorizationStrategy)) {
2824
+ if (!Guards46.isNullOrEmpty(opts.customAuthorizationStrategy)) {
2872
2825
  const customStrategies = opts.customAuthorizationStrategy;
2873
- customStrategies.forEach((strategyToken, index) => {
2874
- if (Guards47.isDefined(strategyToken)) {
2875
- const token = `CUSTOM_AUTHORIZATION_STRATEGY_${index}`;
2876
- container.addSingleton(token, (c) => {
2877
- return strategyToken(c);
2878
- });
2879
- strategies.push(token);
2826
+ customStrategies.forEach((strategyToken) => {
2827
+ if (Guards46.isDefined(strategyToken)) {
2828
+ strategies.push(strategyToken(container));
2880
2829
  }
2881
2830
  });
2882
2831
  }
2883
2832
  const { AuthorizationPipeline: AuthorizationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2884
- container.addSingleton(TOKENS4.AUTHORIZATION_PIPELINE, (c) => {
2885
- const resolvedStrategies = strategies.map(
2886
- (strategy) => c.resolve(strategy)
2887
- );
2888
- return new AuthorizationPipeline2(resolvedStrategies);
2889
- });
2890
- pipelines.push(TOKENS4.AUTHORIZATION_PIPELINE);
2891
- return pipelines;
2833
+ return new AuthorizationPipeline2(strategies);
2892
2834
  },
2893
2835
  /**
2894
2836
  * @description Configures the authentication service and gatekeeper in the service container.
@@ -2905,22 +2847,13 @@ var init_auth_utils = __esm({
2905
2847
  const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
2906
2848
  const _t = opts;
2907
2849
  const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
2850
+ const factory = new SupabaseServerAuthFactory2();
2851
+ const supabase = factory.create({ config: opts, container });
2908
2852
  container.addScoped(TOKENS4.AUTH_SERVICE, () => {
2909
- const factory = new SupabaseServerAuthFactory2();
2910
- return factory.create({ config: opts, container });
2853
+ return supabase;
2911
2854
  });
2912
2855
  container.addSingleton(TOKENS4.BASE_AUTH_SERVICE, () => {
2913
- const factory = new SupabaseServerAuthFactory2();
2914
- return factory.create({ config: opts, container });
2915
- });
2916
- const { ClaimsIdentityMapper: ClaimsIdentityMapper2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2917
- container.addSingleton(TOKENS4.CLAIMS_IDENTITY_MAPPER, () => new ClaimsIdentityMapper2());
2918
- const { GateKeeper: GateKeeper2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2919
- container.addSingleton(TOKENS4.GATE_KEEPER, (c) => {
2920
- return new GateKeeper2(
2921
- c.resolve(TOKENS4.BASE_AUTH_SERVICE),
2922
- c.resolve(TOKENS4.CLAIMS_IDENTITY_MAPPER)
2923
- );
2856
+ return supabase;
2924
2857
  });
2925
2858
  }
2926
2859
  });
@@ -3074,24 +3007,24 @@ var init_db_module = __esm({
3074
3007
  "use strict";
3075
3008
  DbModule = class {
3076
3009
  async configure(container, opts) {
3077
- const { Guards: Guards47, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3010
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3078
3011
  const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
3079
3012
  const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
3080
3013
  const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
3081
- container.addScoped(TOKENS4.TRANSACTION_STATE, () => {
3014
+ container.addScoped("TRANSACTION_STATE", () => {
3082
3015
  return new TransactionState2();
3083
3016
  });
3084
3017
  const { UnitOfWork: UnitOfWork2 } = await Promise.resolve().then(() => (init_unit_of_work(), unit_of_work_exports));
3085
3018
  container.addScoped(TOKENS4.UNIT_OF_WORK, (c) => {
3086
- const ttx = c.resolve(TOKENS4.TRANSACTION_STATE);
3019
+ const ttx = c.resolve("TRANSACTION_STATE");
3087
3020
  return new UnitOfWork2(db, ttx);
3088
3021
  });
3089
3022
  container.addScoped(TOKENS4.DB_CONTEXT, (c) => {
3090
- const ttx = c.resolve(TOKENS4.TRANSACTION_STATE);
3023
+ const ttx = c.resolve("TRANSACTION_STATE");
3091
3024
  return new Proxy(db, {
3092
3025
  get(_target, prop, receiver) {
3093
3026
  const activeState = ttx.state;
3094
- if (Guards47.isDefined(activeState)) {
3027
+ if (Guards46.isDefined(activeState)) {
3095
3028
  if (prop === "transaction") {
3096
3029
  return activeState.transaction.bind(activeState);
3097
3030
  }
@@ -3128,14 +3061,14 @@ var init_http_utils = __esm({
3128
3061
  */
3129
3062
  async addAxios(container, opts) {
3130
3063
  const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
3131
- const { Guards: Guards47 } = await import("@xeno-js/shared");
3132
- if (!Guards47.isDefined(opts.token)) {
3064
+ const { Guards: Guards46 } = await import("@xeno-js/shared");
3065
+ if (!Guards46.isDefined(opts.token)) {
3133
3066
  throw new Error("HttpConfig.token is required and must be defined.");
3134
3067
  }
3135
3068
  container.addSingleton(opts.token, () => {
3136
3069
  const factory = new NodeAxiosFactory2();
3137
3070
  const instance = factory.create(opts.client);
3138
- if (!Guards47.hasMethod(instance, "get") || !Guards47.hasMethod(instance, "post") || !Guards47.hasMethod(instance, "put") || !Guards47.hasMethod(instance, "patch") || !Guards47.hasMethod(instance, "delete")) {
3071
+ if (!Guards46.hasMethod(instance, "get") || !Guards46.hasMethod(instance, "post") || !Guards46.hasMethod(instance, "put") || !Guards46.hasMethod(instance, "patch") || !Guards46.hasMethod(instance, "delete")) {
3139
3072
  throw new Error(
3140
3073
  "The created HTTP client instance does not implement the required methods of IHttpClient."
3141
3074
  );
@@ -3160,17 +3093,6 @@ var init_http_utils = __esm({
3160
3093
  const factory = new CockatielResilienceFactory2();
3161
3094
  return factory.create(opts);
3162
3095
  });
3163
- },
3164
- async addAllowOrigin(container, opts) {
3165
- const { Guards: Guards47 } = await import("@xeno-js/shared");
3166
- if (Guards47.isNullOrEmpty(opts)) throw new Error("At least an allow origin must be passed");
3167
- const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3168
- const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
3169
- const allowOrigin = [];
3170
- opts.forEach((x) => {
3171
- allowOrigin.push(x.trim().toLowerCase());
3172
- });
3173
- container.addSingleton(TOKENS4.ALLOW_ORIGIN, () => new AllowOrigin2(allowOrigin));
3174
3096
  }
3175
3097
  });
3176
3098
  }
@@ -3179,10 +3101,9 @@ var init_http_utils = __esm({
3179
3101
  // src/infrastructure/modules/http-core.module.ts
3180
3102
  var http_core_module_exports = {};
3181
3103
  __export(http_core_module_exports, {
3182
- HttpCoreModule: () => HttpCoreModule,
3183
- HttpOriginModule: () => HttpOriginModule
3104
+ HttpCoreModule: () => HttpCoreModule
3184
3105
  });
3185
- var HttpCoreModule, HttpOriginModule;
3106
+ var HttpCoreModule;
3186
3107
  var init_http_core_module = __esm({
3187
3108
  "src/infrastructure/modules/http-core.module.ts"() {
3188
3109
  "use strict";
@@ -3193,12 +3114,6 @@ var init_http_core_module = __esm({
3193
3114
  await HttpUtils2.addResilience(container, opts.resilience);
3194
3115
  }
3195
3116
  };
3196
- HttpOriginModule = class {
3197
- async configure(container, opts) {
3198
- const { HttpUtils: HttpUtils2 } = await Promise.resolve().then(() => (init_http_utils(), http_utils_exports));
3199
- await HttpUtils2.addAllowOrigin(container, opts);
3200
- }
3201
- };
3202
3117
  }
3203
3118
  });
3204
3119
 
@@ -3223,53 +3138,32 @@ var init_validation_utils = __esm({
3223
3138
  * @link https://github.com/xeno-js/xeno-js
3224
3139
  */
3225
3140
  async addValidation(container, opts, logger) {
3226
- const { Guards: Guards47, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3227
- if (!Guards47.isDefined(opts.zod) && Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
3228
- return [];
3141
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3142
+ if (!Guards46.isDefined(opts.zod) && Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
3143
+ return;
3229
3144
  }
3230
- const pipelines = [];
3231
3145
  const validationStrategies = [];
3232
- if (Guards47.isDefined(opts.zod)) {
3146
+ if (Guards46.isDefined(opts.zod)) {
3233
3147
  const config = opts.zod;
3234
- const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_zod_validator_factory(), zod_validator_factory_exports));
3235
- container.addSingleton(TOKENS4.ZOD_VALIDATOR, () => {
3236
- return new ZodValidatorFactory2().create({ ...config, logger });
3237
- });
3148
+ const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
3238
3149
  const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3239
- container.addSingleton(
3240
- TOKENS4.SCHEMA_VALIDATION_STRATEGY,
3241
- (c) => new SchemaValidationStrategy2(c.resolve(TOKENS4.ZOD_VALIDATOR))
3242
- );
3243
- validationStrategies.push(TOKENS4.SCHEMA_VALIDATION_STRATEGY);
3150
+ const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
3151
+ container.addSingleton(TOKENS4.VALIDATOR_SERVICE, () => validatorService);
3152
+ validationStrategies.push(new SchemaValidationStrategy2(validatorService));
3244
3153
  }
3245
- const customValidationFactory = [];
3246
- if (!Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
3154
+ if (!Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
3247
3155
  for (const strategyToken of opts.customValidationStrategy) {
3248
- if (Guards47.isDefined(strategyToken)) {
3249
- customValidationFactory.push(strategyToken);
3250
- }
3156
+ if (Guards46.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
3251
3157
  }
3252
3158
  }
3253
3159
  const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3254
- container.addSingleton(TOKENS4.VALIDATION_PIPELINE, (c) => {
3255
- const resolvedStrategies = [
3256
- ...validationStrategies.map((token) => c.resolve(token)),
3257
- ...customValidationFactory.map((factory) => factory(c))
3258
- ];
3259
- return new ValidationPipeline2(resolvedStrategies);
3260
- });
3261
- pipelines.push(TOKENS4.VALIDATION_PIPELINE);
3262
- return pipelines;
3160
+ return new ValidationPipeline2(validationStrategies);
3263
3161
  }
3264
3162
  });
3265
3163
  }
3266
3164
  });
3267
3165
 
3268
3166
  // src/infrastructure/idempotency/idempotency-store.ts
3269
- var idempotency_store_exports = {};
3270
- __export(idempotency_store_exports, {
3271
- IdempotencyStore: () => IdempotencyStore
3272
- });
3273
3167
  import { IDEMPOTENCY_CONSTANTS as IDEMPOTENCY_CONSTANTS2 } from "@xeno-js/shared";
3274
3168
  var IdempotencyStore;
3275
3169
  var init_idempotency_store = __esm({
@@ -3326,6 +3220,18 @@ var init_idempotency_store = __esm({
3326
3220
  }
3327
3221
  });
3328
3222
 
3223
+ // src/infrastructure/idempotency/index.ts
3224
+ var idempotency_exports = {};
3225
+ __export(idempotency_exports, {
3226
+ IdempotencyStore: () => IdempotencyStore
3227
+ });
3228
+ var init_idempotency = __esm({
3229
+ "src/infrastructure/idempotency/index.ts"() {
3230
+ "use strict";
3231
+ init_idempotency_store();
3232
+ }
3233
+ });
3234
+
3329
3235
  // src/infrastructure/modules/utils/pipeline.utils.ts
3330
3236
  var pipeline_utils_exports = {};
3331
3237
  __export(pipeline_utils_exports, {
@@ -3347,35 +3253,30 @@ var init_pipeline_utils = __esm({
3347
3253
  * @link https://github.com/xeno-js/xeno-js
3348
3254
  */
3349
3255
  async addCommand(container, opts) {
3256
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3350
3257
  const pipelines = [];
3351
- const { Guards: Guards47, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3352
- if (Guards47.isDefined(opts.idempotency)) {
3353
- const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency_store(), idempotency_store_exports));
3354
- container.addSingleton(
3355
- TOKENS4.IDEMPOTENCY_STORE,
3356
- (c) => new IdempotencyStore2(c.resolve(TOKENS4.CACHE), c.resolve(TOKENS4.CACHE_KEY_BUILDER))
3258
+ if (Guards46.isDefined(opts.idempotency)) {
3259
+ const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
3260
+ const imdStore = new IdempotencyStore2(
3261
+ container.resolve(TOKENS4.CACHE),
3262
+ container.resolve(TOKENS4.CACHE_KEY_BUILDER)
3357
3263
  );
3358
3264
  const { IdempotencyPipeline: IdempotencyPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3359
- container.addSingleton(TOKENS4.IDEMPOTENCY_PIPELINE, (c) => {
3360
- const requestContext = c.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR);
3361
- const idempotencyStore = c.resolve(TOKENS4.IDEMPOTENCY_STORE);
3362
- const config = opts.idempotency;
3363
- return new IdempotencyPipeline2(
3265
+ const requestContext = container.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR);
3266
+ const config = opts.idempotency;
3267
+ pipelines.push(
3268
+ new IdempotencyPipeline2(
3364
3269
  requestContext,
3365
- idempotencyStore,
3270
+ imdStore,
3366
3271
  config?.lockTtlSeconds,
3367
3272
  config?.processedTtlSeconds
3368
- );
3369
- });
3370
- pipelines.push(TOKENS4.IDEMPOTENCY_PIPELINE);
3273
+ )
3274
+ );
3371
3275
  }
3372
- if (Guards47.isDefined(opts.concurrency)) {
3276
+ if (Guards46.isDefined(opts.concurrency)) {
3373
3277
  const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3374
- container.addSingleton(TOKENS4.CONCURRENCY_RETRY_PIPELINE, () => {
3375
- const config = opts.concurrency;
3376
- return new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig);
3377
- });
3378
- pipelines.push(TOKENS4.CONCURRENCY_RETRY_PIPELINE);
3278
+ const config = opts.concurrency;
3279
+ pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
3379
3280
  }
3380
3281
  return pipelines;
3381
3282
  },
@@ -3389,24 +3290,14 @@ var init_pipeline_utils = __esm({
3389
3290
  * @since 2025-09-30
3390
3291
  * @link https://github.com/xeno-js/xeno-js
3391
3292
  */
3392
- async addQuery(container, opts) {
3293
+ async addQuery(container) {
3393
3294
  const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3394
- const pipelines = [];
3395
- if (!opts.isCache) {
3396
- const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
3397
- await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
3398
- }
3399
3295
  const { QueryCachingPipeline: QueryCachingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3400
- container.addSingleton(
3401
- TOKENS4.QUERY_CACHING_PIPELINE,
3402
- (c) => new QueryCachingPipeline2(
3403
- c.resolve(TOKENS4.CACHE),
3404
- c.resolve(TOKENS4.CACHE_KEY_BUILDER),
3405
- c.resolve(TOKENS4.LOGGER)
3406
- )
3296
+ return new QueryCachingPipeline2(
3297
+ container.resolve(TOKENS4.CACHE),
3298
+ container.resolve(TOKENS4.CACHE_KEY_BUILDER),
3299
+ container.resolve(TOKENS4.LOGGER)
3407
3300
  );
3408
- pipelines.push(TOKENS4.QUERY_CACHING_PIPELINE);
3409
- return pipelines;
3410
3301
  }
3411
3302
  });
3412
3303
  }
@@ -3424,79 +3315,54 @@ var init_cqrs_module = __esm({
3424
3315
  CqrsModule = class {
3425
3316
  async configure(container, opts) {
3426
3317
  const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3427
- let isCache = opts.isCache;
3318
+ const logger = container.resolve(TOKENS4.LOGGER);
3428
3319
  const { Mediator: Mediator2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3429
3320
  container.addSingleton(TOKENS4.MEDIATOR, (c) => {
3430
3321
  const serviceScopeAccessor = c.resolve(TOKENS4.SERVICE_SCOPE_ACCESSOR);
3431
3322
  return new Mediator2(serviceScopeAccessor);
3432
3323
  });
3433
3324
  const { ExceptionPipeline: ExceptionPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3434
- container.addSingleton(TOKENS4.EXCEPTION_PIPELINE, () => new ExceptionPipeline2());
3435
- if (!opts.isLogger) {
3436
- const { LoggerUtils: LoggerUtils2 } = await Promise.resolve().then(() => (init_logger_utils(), logger_utils_exports));
3437
- await LoggerUtils2.addLogger(container, void 0);
3438
- }
3439
3325
  const { LoggingPipeline: LoggingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3440
- container.addSingleton(
3441
- TOKENS4.LOGGING_PIPELINE,
3442
- (c) => new LoggingPipeline2(c.resolve(TOKENS4.LOGGER))
3443
- );
3444
- const pipelines = [TOKENS4.EXCEPTION_PIPELINE, TOKENS4.LOGGING_PIPELINE];
3445
3326
  const { PerformancePipeline: PerformancePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3446
- container.addSingleton(TOKENS4.PERFORMANCE_PIPELINE, (c) => {
3447
- const logger = c.resolve(TOKENS4.LOGGER);
3448
- const thresholdMs = opts.performance?.thresholdMs;
3449
- return new PerformancePipeline2(logger, thresholdMs);
3450
- });
3451
- pipelines.push(TOKENS4.PERFORMANCE_PIPELINE);
3452
- const { Guards: Guards47 } = await import("@xeno-js/shared");
3453
- if (Guards47.isDefined(opts.authorization.policies) || Guards47.isDefined(opts.authorization.customAuthorizationStrategy)) {
3327
+ const thresholdMs = opts.performance?.thresholdMs;
3328
+ const pipelines = [
3329
+ new ExceptionPipeline2(),
3330
+ new LoggingPipeline2(logger),
3331
+ new PerformancePipeline2(logger, thresholdMs)
3332
+ ];
3333
+ const { Guards: Guards46 } = await import("@xeno-js/shared");
3334
+ if (Guards46.isDefined(opts.authorization.policies) || Guards46.isDefined(opts.authorization.customAuthorizationStrategy)) {
3454
3335
  const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
3455
3336
  const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
3456
- pipelines.push(...authPipelines);
3337
+ pipelines.push(authPipelines);
3457
3338
  }
3458
- if (Guards47.isDefined(opts.validation.zod) || Guards47.isDefined(opts.validation.customValidationStrategy)) {
3339
+ if (Guards46.isDefined(opts.validation.zod) || Guards46.isDefined(opts.validation.customValidationStrategy)) {
3459
3340
  const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
3460
- const logger = container.resolve(TOKENS4.LOGGER);
3461
3341
  const validationPipelines = await ValidationUtils2.addValidation(
3462
3342
  container,
3463
3343
  opts.validation,
3464
3344
  logger
3465
3345
  );
3466
- pipelines.push(...validationPipelines);
3346
+ if (Guards46.isDefined(validationPipelines)) pipelines.push(validationPipelines);
3467
3347
  }
3468
3348
  const commandPipelines = pipelines;
3469
3349
  const queryPipelines = pipelines;
3470
- if ((Guards47.isDefined(opts.commandBus.idempotency) || opts.queryBus.isEnabled) && opts.isCache) {
3471
- const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
3472
- await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
3473
- }
3474
- if (Guards47.isDefined(opts.commandBus.idempotency) || Guards47.isDefined(opts.commandBus.concurrency)) {
3350
+ if (Guards46.isDefined(opts.commandBus.idempotency) || Guards46.isDefined(opts.commandBus.concurrency)) {
3475
3351
  const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
3476
- const newCommandPipelines = await PipelineUtils2.addCommand(container, {
3477
- ...opts.commandBus,
3478
- isCache
3479
- });
3480
- isCache = true;
3352
+ const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
3481
3353
  commandPipelines.push(...newCommandPipelines);
3482
3354
  }
3483
3355
  if (opts.queryBus.isEnabled) {
3484
3356
  const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
3485
- const newQueryPipelines = await PipelineUtils2.addQuery(container, { isCache });
3486
- queryPipelines.push(...newQueryPipelines);
3357
+ const newQueryPipelines = await PipelineUtils2.addQuery(container);
3358
+ queryPipelines.push(newQueryPipelines);
3487
3359
  }
3488
3360
  const { CompositePipeline: CompositePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3489
- container.addSingleton(TOKENS4.COMMAND_PIPELINES_BEHAVIOR, (c) => {
3490
- const resolvedCommandPipelines = commandPipelines.map((token) => {
3491
- return c.resolve(token);
3492
- });
3493
- return new CompositePipeline2(resolvedCommandPipelines);
3361
+ container.addSingleton(TOKENS4.COMMAND_PIPELINES_BEHAVIOR, () => {
3362
+ return new CompositePipeline2(commandPipelines);
3494
3363
  });
3495
- container.addSingleton(TOKENS4.QUERY_PIPELINES_BEHAVIOR, (c) => {
3496
- const resolvedQueryPipelines = queryPipelines.map(
3497
- (token) => c.resolve(token)
3498
- );
3499
- return new CompositePipeline2(resolvedQueryPipelines);
3364
+ container.addSingleton(TOKENS4.QUERY_PIPELINES_BEHAVIOR, () => {
3365
+ return new CompositePipeline2(queryPipelines);
3500
3366
  });
3501
3367
  }
3502
3368
  };
@@ -4313,150 +4179,111 @@ var middleware_module_exports = {};
4313
4179
  __export(middleware_module_exports, {
4314
4180
  MiddlewareModule: () => MiddlewareModule
4315
4181
  });
4316
- import { Guards as Guards43 } from "@xeno-js/shared";
4317
4182
  var MiddlewareModule;
4318
4183
  var init_middleware_module = __esm({
4319
4184
  "src/infrastructure/modules/middleware.module.ts"() {
4320
4185
  "use strict";
4321
4186
  MiddlewareModule = class {
4322
4187
  async configure(container, opts) {
4323
- const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
4324
- if (!opts.isAuth) {
4325
- const { NoAuthGateKeeper: NoAuthGateKeeper2 } = await Promise.resolve().then(() => (init_application(), application_exports));
4326
- container.addSingleton(TOKENS4.GATE_KEEPER, () => new NoAuthGateKeeper2());
4327
- }
4328
- if (opts.isSSR) {
4329
- const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4330
- container.addSingleton(TOKENS4.BEARER_TOKEN_EXTRACTOR, () => new SupabaseSsrTokenExtractor2());
4331
- } else {
4332
- const { BearerTokenExtractor: BearerTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4333
- container.addSingleton(TOKENS4.BEARER_TOKEN_EXTRACTOR, () => new BearerTokenExtractor2());
4334
- }
4188
+ const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
4335
4189
  const { HttpCookieExtractor: HttpCookieExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4336
- container.addSingleton("COOKIE_EXTRACTOR", () => new HttpCookieExtractor2());
4337
4190
  const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4191
+ const tokenExtractor = await this._getTokenExtractor(opts.isSSR);
4338
4192
  container.addSingleton(
4339
4193
  TOKENS4.SERVICE_EXTRACTOR,
4340
- (c) => new HttpHeaderExtractor2(
4341
- c.resolve(TOKENS4.BEARER_TOKEN_EXTRACTOR),
4342
- c.resolve("COOKIE_EXTRACTOR"),
4194
+ () => new HttpHeaderExtractor2(
4195
+ tokenExtractor,
4196
+ new HttpCookieExtractor2(),
4343
4197
  opts.trustedIpHeader,
4344
4198
  opts.csrf?.cookieName ?? "__Host-xeno-csrf"
4345
4199
  )
4346
4200
  );
4347
- if (!opts.isLogger) {
4348
- const { LoggerUtils: LoggerUtils2 } = await Promise.resolve().then(() => (init_logger_utils(), logger_utils_exports));
4349
- await LoggerUtils2.addLogger(container, void 0);
4350
- }
4351
4201
  const { ClientIpResolver: ClientIpResolver2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4352
- container.addSingleton("IP_RESOLVER", () => new ClientIpResolver2(opts.trustedProxies));
4353
- const middlewares = [TOKENS4.REQUEST_CONTEXT_MIDDLEWARE];
4202
+ const middlewares = [];
4203
+ const requestContext = container.resolve(TOKENS4.REQUEST_CONTEXT);
4204
+ const logger = container.resolve(TOKENS4.LOGGER);
4354
4205
  const { RequestContextMiddleware: RequestContextMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4355
- container.addSingleton(
4356
- TOKENS4.REQUEST_CONTEXT_MIDDLEWARE,
4357
- (c) => new RequestContextMiddleware2(
4358
- c.resolve(TOKENS4.REQUEST_CONTEXT),
4359
- c.resolve(TOKENS4.SERVICE_EXTRACTOR),
4360
- c.resolve("IP_RESOLVER"),
4361
- c.resolve(TOKENS4.LOGGER)
4206
+ middlewares.push(
4207
+ new RequestContextMiddleware2(
4208
+ requestContext,
4209
+ container.resolve(TOKENS4.SERVICE_EXTRACTOR),
4210
+ new ClientIpResolver2(opts.trustedProxies),
4211
+ logger
4362
4212
  )
4363
4213
  );
4364
- if (!Guards43.isNullOrEmpty(opts.allowOrigins)) {
4214
+ if (!Guards46.isNullOrEmpty(opts.allowOrigins)) {
4365
4215
  if (opts.withCredentials && opts.allowOrigins.includes("*"))
4366
4216
  throw new Error(
4367
4217
  "Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
4368
4218
  );
4369
4219
  const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4370
- container.addSingleton("ALLOW_ORIGIN", () => {
4371
- return new AllowOrigin2(opts.allowOrigins);
4372
- });
4373
4220
  const { AllowOriginMiddleware: AllowOriginMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4374
- container.addSingleton(TOKENS4.ALLOW_ORIGIN_MIDDLEWARE, (c) => {
4375
- return new AllowOriginMiddleware2(
4376
- c.resolve(TOKENS4.ALLOW_ORIGIN),
4377
- c.resolve(TOKENS4.CONTEXT_ACCESSOR),
4378
- c.resolve(TOKENS4.LOGGER)
4379
- );
4380
- });
4381
- middlewares.push(TOKENS4.ALLOW_ORIGIN_MIDDLEWARE);
4221
+ middlewares.push(
4222
+ new AllowOriginMiddleware2(new AllowOrigin2(opts.allowOrigins), requestContext, logger)
4223
+ );
4382
4224
  }
4383
4225
  const withCredentials = opts.withCredentials ? "true" : "false";
4226
+ const allowMethod = await this._getAllowMethod(
4227
+ opts.optionsMiddleware || opts.cors,
4228
+ opts.routeRegistry
4229
+ );
4384
4230
  if (opts.optionsMiddleware) {
4385
4231
  const { OptionsMiddleware: OptionsMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4386
- container.addSingleton(
4387
- TOKENS4.OPTIONS_MIDDLEWARE,
4388
- (c) => new OptionsMiddleware2(
4389
- c.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR),
4390
- c.resolve(TOKENS4.ALLOW_METHOD),
4391
- opts.allowHeaders,
4392
- withCredentials
4393
- )
4232
+ middlewares.push(
4233
+ new OptionsMiddleware2(requestContext, allowMethod, opts.allowHeaders, withCredentials)
4394
4234
  );
4395
- middlewares.push(TOKENS4.OPTIONS_MIDDLEWARE);
4396
4235
  }
4397
4236
  if (opts.cors) {
4398
4237
  const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4399
- container.addSingleton(TOKENS4.CORS_MIDDLEWARE, (c) => {
4400
- return new CORSMiddleware2(c.resolve(TOKENS4.CONTEXT_ACCESSOR), withCredentials);
4401
- });
4402
- middlewares.push(TOKENS4.CORS_MIDDLEWARE);
4238
+ middlewares.push(new CORSMiddleware2(requestContext, withCredentials));
4403
4239
  }
4404
- if (Guards43.isDefined(opts.routeRegistry)) {
4405
- const registry = opts.routeRegistry;
4406
- const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
4407
- container.addSingleton(TOKENS4.ALLOW_METHOD, () => new AllowMethodFactory2().create(registry));
4240
+ if (Guards46.isDefined(opts.routeRegistry)) {
4408
4241
  const { MethodCheckMiddleware: MethodCheckMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4409
- container.addSingleton(
4410
- TOKENS4.METHOD_CHECK_MIDDLEWARE,
4411
- (c) => new MethodCheckMiddleware2(
4412
- c.resolve(TOKENS4.REQUEST_CONTEXT),
4413
- c.resolve(TOKENS4.ALLOW_METHOD)
4414
- )
4415
- );
4416
- middlewares.push(TOKENS4.METHOD_CHECK_MIDDLEWARE);
4242
+ middlewares.push(new MethodCheckMiddleware2(requestContext, allowMethod));
4417
4243
  }
4418
4244
  const { AuthenticationMiddleware: AuthenticationMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4419
- container.addSingleton(TOKENS4.AUTH_MIDDLEWARE, (c) => {
4420
- return new AuthenticationMiddleware2(
4421
- c.resolve(TOKENS4.REQUEST_CONTEXT),
4422
- c.resolve(TOKENS4.BEARER_TOKEN_EXTRACTOR),
4423
- c.resolve(TOKENS4.GATE_KEEPER),
4424
- c.resolve(TOKENS4.LOGGER)
4245
+ if (!opts.isAuth) {
4246
+ const { NoAuthGateKeeper: NoAuthGateKeeper2 } = await Promise.resolve().then(() => (init_application(), application_exports));
4247
+ middlewares.push(
4248
+ new AuthenticationMiddleware2(
4249
+ requestContext,
4250
+ tokenExtractor,
4251
+ new NoAuthGateKeeper2(),
4252
+ logger
4253
+ )
4425
4254
  );
4426
- });
4427
- middlewares.push(TOKENS4.AUTH_MIDDLEWARE);
4428
- if (Guards43.isDefined(opts.rateLimite.maxRequests) || Guards43.isDefined(opts.rateLimite.windowSeconds)) {
4255
+ } else {
4256
+ const { ClaimsIdentityMapper: ClaimsIdentityMapper2 } = await Promise.resolve().then(() => (init_application(), application_exports));
4257
+ const { GateKeeper: GateKeeper2 } = await Promise.resolve().then(() => (init_application(), application_exports));
4258
+ middlewares.push(
4259
+ new AuthenticationMiddleware2(
4260
+ requestContext,
4261
+ tokenExtractor,
4262
+ new GateKeeper2(container.resolve(TOKENS4.BASE_AUTH_SERVICE), new ClaimsIdentityMapper2()),
4263
+ logger
4264
+ )
4265
+ );
4266
+ }
4267
+ if (Guards46.isDefined(opts.rateLimite.maxRequests) || Guards46.isDefined(opts.rateLimite.windowSeconds)) {
4429
4268
  const maxRequests = opts.rateLimite.maxRequests ?? 30;
4430
- Guards43.throwIfNegative(maxRequests, "MaxRequests must be positive");
4431
- Guards43.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
4269
+ Guards46.throwIfNegative(maxRequests, "MaxRequests must be positive");
4270
+ Guards46.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
4432
4271
  const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
4433
- Guards43.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
4434
- Guards43.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
4435
- if (!opts.isCache) {
4436
- const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
4437
- await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
4438
- }
4272
+ Guards46.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
4273
+ Guards46.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
4439
4274
  const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
4440
- container.addSingleton(
4441
- "RATE_LIMIT_KEY_BUILDER",
4442
- (c) => new RateLimitKeyBuilder2(c.resolve(TOKENS4.REQUEST_CONTEXT))
4443
- );
4444
4275
  const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4445
- container.addSingleton(TOKENS4.RATE_LIMITER_MIDDLEWARE, (c) => {
4446
- return new RateLimitMiddleware2(
4447
- c.resolve(TOKENS4.CONTEXT_ACCESSOR),
4448
- c.resolve(TOKENS4.CACHE),
4449
- c.resolve("RATE_LIMIT_KEY_BUILDER"),
4450
- c.resolve(TOKENS4.LOGGER),
4451
- {
4452
- maxRequests,
4453
- windowSeconds
4454
- }
4455
- );
4456
- });
4457
- middlewares.push(TOKENS4.RATE_LIMITER_MIDDLEWARE);
4276
+ middlewares.push(
4277
+ new RateLimitMiddleware2(
4278
+ requestContext,
4279
+ container.resolve(TOKENS4.CACHE),
4280
+ new RateLimitKeyBuilder2(requestContext),
4281
+ logger,
4282
+ { maxRequests, windowSeconds }
4283
+ )
4284
+ );
4458
4285
  }
4459
- if (Guards43.isDefined(opts.csrf)) {
4286
+ if (Guards46.isDefined(opts.csrf)) {
4460
4287
  const csrf = opts.csrf;
4461
4288
  const { EdgeCryptoService: EdgeCryptoService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4462
4289
  container.addSingleton("CRYPTO_SERVICE", () => new EdgeCryptoService2());
@@ -4465,31 +4292,36 @@ var init_middleware_module = __esm({
4465
4292
  return new CsrfTokenService2(csrf.secret, c.resolve("CRYPTO_SERVICE"));
4466
4293
  });
4467
4294
  const { CsrfCookieMiddleware: CsrfCookieMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4468
- container.addSingleton("CSRF_COOKIE_MIDDLEWARE", (c) => {
4469
- return new CsrfCookieMiddleware2(
4470
- c.resolve(TOKENS4.REQUEST_CONTEXT),
4471
- c.resolve("CSRF_TOKEN_SERVICE"),
4472
- csrf
4473
- );
4474
- });
4475
- middlewares.push("CSRF_COOKIE_MIDDLEWARE");
4295
+ middlewares.push(
4296
+ new CsrfCookieMiddleware2(
4297
+ requestContext,
4298
+ container.resolve("CSRF_TOKEN_SERVICE"),
4299
+ opts.csrf
4300
+ )
4301
+ );
4476
4302
  const { CsrfMiddleware: CsrfMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4477
- container.addSingleton(TOKENS4.CSRF_MIDDLEWARE, (c) => {
4478
- return new CsrfMiddleware2(
4479
- c.resolve(TOKENS4.REQUEST_CONTEXT),
4480
- c.resolve("CSRF_TOKEN_SERVICE")
4481
- );
4482
- });
4483
- middlewares.push(TOKENS4.CSRF_MIDDLEWARE);
4303
+ middlewares.push(new CsrfMiddleware2(requestContext, container.resolve("CSRF_TOKEN_SERVICE")));
4484
4304
  }
4485
4305
  const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4486
- container.addSingleton(TOKENS4.MIDDLEWARE, (c) => {
4487
- const resolvedMiddleware = middlewares.map(
4488
- (token) => c.resolve(token)
4489
- );
4490
- return new CompositeMiddleware2(resolvedMiddleware);
4306
+ container.addSingleton(TOKENS4.MIDDLEWARE, () => {
4307
+ return new CompositeMiddleware2(middlewares);
4491
4308
  });
4492
4309
  }
4310
+ async _getTokenExtractor(isSSR) {
4311
+ if (isSSR) {
4312
+ const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4313
+ return new SupabaseSsrTokenExtractor2();
4314
+ } else {
4315
+ const { BearerTokenExtractor: BearerTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4316
+ return new BearerTokenExtractor2();
4317
+ }
4318
+ }
4319
+ async _getAllowMethod(configure, opts) {
4320
+ const { Guards: Guards46 } = await import("@xeno-js/shared");
4321
+ if (!configure || !Guards46.isDefined(opts)) return void 0;
4322
+ const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
4323
+ return new AllowMethodFactory2().create(opts);
4324
+ }
4493
4325
  };
4494
4326
  }
4495
4327
  });
@@ -4507,26 +4339,17 @@ var init_context_module = __esm({
4507
4339
  async configure(container) {
4508
4340
  const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
4509
4341
  const { ServiceScopeFactory: ServiceScopeFactory2 } = await Promise.resolve().then(() => (init_service_scope_factory(), service_scope_factory_exports));
4510
- container.addSingleton(TOKENS4.SERVICE_SCOPE_FACTORY, () => {
4511
- const factory = new ServiceScopeFactory2(container);
4512
- return factory;
4513
- });
4514
4342
  const { NodeRequestContextFactory: NodeRequestContextFactory2 } = await Promise.resolve().then(() => (init_request_context_factory(), request_context_factory_exports));
4515
- container.addSingleton(TOKENS4.REQUEST_CONTEXT, (c) => {
4516
- return new NodeRequestContextFactory2(
4517
- c.resolve(TOKENS4.SERVICE_SCOPE_FACTORY)
4518
- ).create();
4519
- });
4520
- container.addSingleton(TOKENS4.CONTEXT_ACCESSOR, (c) => c.resolve(TOKENS4.REQUEST_CONTEXT));
4521
- container.addSingleton(TOKENS4.IDENTITY_ACCESSOR, (c) => c.resolve(TOKENS4.REQUEST_CONTEXT));
4522
- container.addSingleton(TOKENS4.SERVICE_SCOPE_ACCESSOR, (c) => c.resolve(TOKENS4.REQUEST_CONTEXT));
4523
- container.addSingleton(
4524
- TOKENS4.NETWORK_CONTEXT_ACCESSOR,
4525
- (c) => c.resolve(TOKENS4.REQUEST_CONTEXT)
4526
- );
4343
+ const requestContext = new NodeRequestContextFactory2(
4344
+ new ServiceScopeFactory2(container)
4345
+ ).create();
4346
+ container.addSingleton(TOKENS4.REQUEST_CONTEXT, () => requestContext);
4347
+ container.addSingleton(TOKENS4.CONTEXT_ACCESSOR, () => requestContext);
4348
+ container.addSingleton(TOKENS4.IDENTITY_ACCESSOR, () => requestContext);
4349
+ container.addSingleton(TOKENS4.SERVICE_SCOPE_ACCESSOR, () => requestContext);
4350
+ container.addSingleton(TOKENS4.NETWORK_CONTEXT_ACCESSOR, () => requestContext);
4527
4351
  const { UserContextFactory: UserContextFactory2 } = await Promise.resolve().then(() => (init_user_context_factory(), user_context_factory_exports));
4528
- container.addSingleton(TOKENS4.USER_CONTEXT_FACTORY, (c) => {
4529
- const requestContext = c.resolve(TOKENS4.REQUEST_CONTEXT);
4352
+ container.addSingleton("USER_CONTEXT_FACTORY", () => {
4530
4353
  return new UserContextFactory2(requestContext);
4531
4354
  });
4532
4355
  }
@@ -4553,7 +4376,7 @@ __export(index_exports, {
4553
4376
  init_application();
4554
4377
 
4555
4378
  // src/infrastructure/builder/app.builder.ts
4556
- import { Guards as Guards44, LOG_LEVEL as LOG_LEVEL6, TOKENS as TOKENS3 } from "@xeno-js/shared";
4379
+ import { Guards as Guards43, LOG_LEVEL as LOG_LEVEL6, TOKENS as TOKENS3 } from "@xeno-js/shared";
4557
4380
 
4558
4381
  // src/infrastructure/configuration/configuration.ts
4559
4382
  import { Guards as Guards13 } from "@xeno-js/shared";
@@ -4703,6 +4526,12 @@ var ServiceContainer = class {
4703
4526
  this.registrations.set(token, { token, lifetime, factory });
4704
4527
  }
4705
4528
  resolve(token) {
4529
+ const registration = this.registrations.get(token);
4530
+ if (registration?.lifetime === "scoped") {
4531
+ throw new Error(
4532
+ `[DI Container Error]: Scoped service '${String(token)}' requires an active scope.`
4533
+ );
4534
+ }
4706
4535
  return this.internalExecuteInContext(() => this.rootScope.resolve(token));
4707
4536
  }
4708
4537
  createScope() {
@@ -4887,6 +4716,13 @@ var AppBuilder = class {
4887
4716
  },
4888
4717
  resilience: { retry: {}, circuitBreaker: {}, bulkhead: {} }
4889
4718
  };
4719
+ _loggerConfig = {
4720
+ level: LOG_LEVEL6.DEBUG,
4721
+ console: true,
4722
+ sentry: { config: void 0 },
4723
+ pino: { config: void 0 },
4724
+ customLoggers: void 0
4725
+ };
4890
4726
  // --- Module Queuing Flags ---
4891
4727
  _isContextModuleQueued = false;
4892
4728
  _isMiddlewareModuleQueued = false;
@@ -4932,31 +4768,22 @@ var AppBuilder = class {
4932
4768
  * @description Configures the logger for the application. This method allows you to set up logging options such as log level, console logging, and integration with external logging services like Sentry or Pino.
4933
4769
  * @param setupAction A callback function that receives a LoggerConfig object to configure the logger settings.
4934
4770
  * @returns The current instance of AppBuilder for method chaining.
4935
-
4936
- *
4771
+ *
4937
4772
  * @author Xeno
4938
4773
  * @version 1.0.0
4939
4774
  * @since 2025-09-30
4940
- * @link https://github.com/xeno-js/xeno-js
4775
+ * @link https://github.com/xeno-js/xeno-js
4941
4776
  */
4942
4777
  addLogger(setupAction) {
4778
+ if (Guards43.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
4943
4779
  if (this._isLoggerModuleQueued) return this;
4944
4780
  this._isLoggerModuleQueued = true;
4945
- const config = {
4946
- level: LOG_LEVEL6.DEBUG,
4947
- console: true,
4948
- sentry: { config: void 0 },
4949
- pino: { config: void 0 },
4950
- customLoggers: void 0
4951
- };
4952
- if (Guards44.isDefined(setupAction) && Guards44.isDefined(config))
4953
- setupAction(config, this._configuration);
4954
4781
  this._modules.push({
4955
- priority: 3,
4782
+ priority: 1,
4956
4783
  name: "LoggerModule",
4957
4784
  action: async () => {
4958
4785
  const { LoggerUtils: LoggerUtils2 } = await Promise.resolve().then(() => (init_logger_utils(), logger_utils_exports));
4959
- await LoggerUtils2.addLogger(this._container, config);
4786
+ await LoggerUtils2.addLogger(this._container, this._loggerConfig);
4960
4787
  }
4961
4788
  });
4962
4789
  return this;
@@ -4973,11 +4800,11 @@ var AppBuilder = class {
4973
4800
  * @link https://github.com/xeno-js/xeno-js
4974
4801
  */
4975
4802
  addCache(setupAction) {
4803
+ if (Guards43.isDefined(setupAction)) setupAction(this._config, this._configuration);
4976
4804
  if (this._isCacheModuleQueued) return this;
4977
4805
  this._isCacheModuleQueued = true;
4978
- if (Guards44.isDefined(setupAction)) setupAction(this._config, this._configuration);
4979
4806
  this._modules.push({
4980
- priority: 3,
4807
+ priority: 2,
4981
4808
  name: "CacheModule",
4982
4809
  action: async () => {
4983
4810
  const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
@@ -5010,7 +4837,7 @@ var AppBuilder = class {
5010
4837
  };
5011
4838
  setupAction(config, this._configuration);
5012
4839
  this._modules.push({
5013
- priority: 2,
4840
+ priority: 3,
5014
4841
  name: "AuthModule",
5015
4842
  action: async () => {
5016
4843
  const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
@@ -5084,7 +4911,7 @@ var AppBuilder = class {
5084
4911
  * @link https://github.com/xeno-js/xeno-js
5085
4912
  */
5086
4913
  addPipeline(setupAction) {
5087
- if (Guards44.isDefined(setupAction)) {
4914
+ if (Guards43.isDefined(setupAction)) {
5088
4915
  setupAction(this._pipelineConfig, this._configuration);
5089
4916
  }
5090
4917
  this._queuePipelineModule();
@@ -5117,20 +4944,6 @@ var AppBuilder = class {
5117
4944
  });
5118
4945
  return this;
5119
4946
  }
5120
- addAllowOrigin(setupAction) {
5121
- const config = [];
5122
- setupAction(config, this._configuration);
5123
- this._modules.push({
5124
- priority: 30,
5125
- name: "HttpCoreModule",
5126
- action: async () => {
5127
- const { HttpOriginModule: HttpOriginModule2 } = await Promise.resolve().then(() => (init_http_core_module(), http_core_module_exports));
5128
- const httpOriginModule = new HttpOriginModule2();
5129
- await httpOriginModule.configure(this._container, config);
5130
- }
5131
- });
5132
- return this;
5133
- }
5134
4947
  // ─────────────────────────────────────────────────────────────────────────────
5135
4948
  // Dependency Injection Pass-through Methods
5136
4949
  // ─────────────────────────────────────────────────────────────────────────────
@@ -5218,7 +5031,7 @@ var AppBuilder = class {
5218
5031
  console.error(`\u{1F449} Module: **${queued.name}**`);
5219
5032
  console.error(`\u{1F4DD} Reason: ${errorMessage}
5220
5033
  `);
5221
- if (error instanceof Error && Guards44.isDefined(error.stack)) {
5034
+ if (error instanceof Error && Guards43.isDefined(error.stack)) {
5222
5035
  console.error(error.stack);
5223
5036
  }
5224
5037
  throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
@@ -5243,17 +5056,15 @@ var AppBuilder = class {
5243
5056
  if (this._isPipelineModuleQueued) return;
5244
5057
  this._isPipelineModuleQueued = true;
5245
5058
  this._queueContextModule();
5059
+ if (!this._isLoggerModuleQueued) this.addLogger();
5060
+ if (!this._isCacheModuleQueued) this.addCache();
5246
5061
  this._modules.push({
5247
5062
  priority: 5,
5248
5063
  name: "CqrsModule",
5249
5064
  action: async () => {
5250
5065
  const { CqrsModule: CqrsModule2 } = await Promise.resolve().then(() => (init_cqrs_module(), cqrs_module_exports));
5251
5066
  const pipelineModule = new CqrsModule2();
5252
- await pipelineModule.configure(this._container, {
5253
- ...this._pipelineConfig,
5254
- isLogger: this._isLoggerModuleQueued || this._isMiddlewareModuleQueued,
5255
- isCache: !this._isCacheModuleQueued
5256
- });
5067
+ await pipelineModule.configure(this._container, this._pipelineConfig);
5257
5068
  }
5258
5069
  });
5259
5070
  }
@@ -5270,17 +5081,17 @@ var AppBuilder = class {
5270
5081
  if (this._isMiddlewareModuleQueued) return;
5271
5082
  this._isMiddlewareModuleQueued = true;
5272
5083
  this._queueContextModule();
5084
+ if (!this._isLoggerModuleQueued) this.addLogger();
5085
+ if (!this._isCacheModuleQueued) this.addCache();
5273
5086
  this._modules.push({
5274
- priority: 3,
5087
+ priority: 4,
5275
5088
  name: "MiddlewareModule",
5276
5089
  action: async () => {
5277
5090
  const { MiddlewareModule: MiddlewareModule2 } = await Promise.resolve().then(() => (init_middleware_module(), middleware_module_exports));
5278
5091
  const middlewareModule = new MiddlewareModule2();
5279
5092
  await middlewareModule.configure(this._container, {
5280
5093
  ...this._middlewareConfig,
5281
- isAuth: this._isAuthModuleQueued,
5282
- isLogger: this._isLoggerModuleQueued,
5283
- isCache: this._isCacheModuleQueued || this._isPipelineModuleQueued
5094
+ isAuth: this._isAuthModuleQueued
5284
5095
  });
5285
5096
  }
5286
5097
  });
@@ -5350,9 +5161,7 @@ import { AppError as AppError15, Result as Result16 } from "@xeno-js/shared";
5350
5161
 
5351
5162
  // src/infrastructure/index.ts
5352
5163
  init_factories();
5353
-
5354
- // src/infrastructure/idempotency/index.ts
5355
- init_idempotency_store();
5164
+ init_idempotency();
5356
5165
 
5357
5166
  // src/infrastructure/loggers/index.ts
5358
5167
  init_console_logger();
@@ -5377,7 +5186,7 @@ init_validation_utils();
5377
5186
 
5378
5187
  // src/infrastructure/repositories/read-dao.ts
5379
5188
  import { AppError as AppError16, Result as Result17 } from "@xeno-js/shared";
5380
- import { Guards as Guards45 } from "@xeno-js/shared";
5189
+ import { Guards as Guards44 } from "@xeno-js/shared";
5381
5190
  var ReadDao = class {
5382
5191
  /**
5383
5192
  * Constructs a new ReadDao instance.
@@ -5399,7 +5208,7 @@ var ReadDao = class {
5399
5208
  async findById(id, ctx, signal) {
5400
5209
  AppError16.throwIfAborted(signal, "ReadDao.findById");
5401
5210
  const result = await this._dataSource.findById(id, ctx, signal);
5402
- if (Guards45.isNullOrEmpty(result)) return Result17.ok();
5211
+ if (Guards44.isNullOrEmpty(result)) return Result17.ok();
5403
5212
  const entity = this._mapper.toEntity(result);
5404
5213
  return Result17.ok(entity);
5405
5214
  }
@@ -5413,7 +5222,7 @@ var ReadDao = class {
5413
5222
 
5414
5223
  // src/infrastructure/repositories/repository.ts
5415
5224
  import { AppError as AppError17, Result as Result18 } from "@xeno-js/shared";
5416
- import { Guards as Guards46 } from "@xeno-js/shared";
5225
+ import { Guards as Guards45 } from "@xeno-js/shared";
5417
5226
  var Repository = class {
5418
5227
  /**
5419
5228
  * Constructs a new Repository instance.
@@ -5435,7 +5244,7 @@ var Repository = class {
5435
5244
  async findById(id, ctx, signal) {
5436
5245
  AppError17.throwIfAborted(signal, "Repository.findById");
5437
5246
  const result = await this._dataSource.findById(id, ctx, signal);
5438
- if (Guards46.isNullOrEmpty(result)) return Result18.ok();
5247
+ if (Guards45.isNullOrEmpty(result)) return Result18.ok();
5439
5248
  const entity = this._mapper.toEntity(result);
5440
5249
  return Result18.ok(entity);
5441
5250
  }