@xeno-js/core 5.0.2 → 5.1.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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { IRequest, IHandler, IFactory, UserContext, Optional, ResultType, ICommand, RequestType, IStrategy, IPolicyRegistry, IContextAccessor, RequestContext, Identity, IValidatorService, IPipelineBehavior, Delegate, IQuery, ICacheableOptions, ISpecification, XenoRegistry, IXenoApplication, IServiceContainer, ServicesProxy, XenoIncomingRequest, ResponseDto, NativeListenOptions, IAppBuilder, IConfigurationService, Nullable, HttpServerPlugin, NativeRouteDefinition, SetupAction, MiddlewareConfig, ContextPlugin, LoggerPlugin, LoggerConfig, CachePlugin, CacheConfig, AuthPlugin, AuthModuleOptions, DbPlugin, PipelinePlugin, HttpPlugin, HttpConfig, IModule, IRequestContext, ITransactionalDb, DbModuleOptions, IServiceScope, IUnitOfWork, IDisposable, AuthorizationOptions, ConcurrencyOptions, XenoPlugin, IdempotencyOptions, LogLevel, PerformanceOptions, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, IMediator, Dictionary, AppError } from '@xeno-js/shared';
1
+ import { IRequest, IHandler, IFactory, UserContext, Optional, ResultType, ICommand, RequestType, IStrategy, IPolicyRegistry, IContextAccessor, RequestContext, Identity, IValidatorService, IPipelineBehavior, Delegate, IQuery, ICacheableOptions, ISpecification, XenoRegistry, IXenoApplication, IServiceContainer, ServicesProxy, XenoIncomingRequest, ResponseDto, NativeListenOptions, IAppBuilder, IConfigurationService, Nullable, HttpServerPlugin, NativeRouteDefinition, SetupAction, MiddlewareConfig, ContextPlugin, LoggerPlugin, LoggerConfig, CachePlugin, CacheConfig, AuthPlugin, AuthModuleOptions, DbPlugin, PipelinePlugin, HttpPlugin, HttpConfig, IModule, IRequestContext, ITransactionalDb, DbModuleOptions, IServiceScope, IUnitOfWork, IDisposable, AuthorizationOptions, ConcurrencyOptions, XenoPlugin, IdempotencyOptions, IdentityEnrichmentOptions, LogLevel, PerformanceOptions, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, IMediator, Dictionary, AppError } from '@xeno-js/shared';
2
2
  export * from '@xeno-js/shared';
3
3
 
4
4
  /**
@@ -601,6 +601,8 @@ declare const withCustomHttp: <TRegistry extends XenoRegistry = XenoRegistry>(co
601
601
 
602
602
  declare const withIdempotency: <TRegistry extends XenoRegistry = XenoRegistry>(setup?: SetupAction<IdempotencyOptions, IConfigurationService>) => PipelinePlugin<TRegistry>;
603
603
 
604
+ declare const withEnrichmentIdentity: <TRegistry extends XenoRegistry = XenoRegistry>(setup?: SetupAction<IdentityEnrichmentOptions, IConfigurationService>) => PipelinePlugin<TRegistry>;
605
+
604
606
  interface ConsoleOptions {
605
607
  isEnabled?: boolean;
606
608
  level?: LogLevel;
@@ -794,4 +796,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
794
796
  protected getContext(): Optional<RequestContext>;
795
797
  }
796
798
 
797
- export { AuthModule, BaseAuthorizationStrategy, BaseController, BaseHandler, CacheModule, Command, ContextModule, DbModule, HttpServerModule, LoggerModule, Query, ReadDao, Repository, SchemaValidationStrategy, Specification, ValidationPipeline, XenoAppBuilder, definePlugin, withAuth, withAuthZ, withConcurrency, withConsoleLogger, withCors, withCsrf, withCustomHttp, withIdempotency, withPerformance, withQueryCaching, withValidation, withoutCsrf };
799
+ export { AuthModule, BaseAuthorizationStrategy, BaseController, BaseHandler, CacheModule, Command, ContextModule, DbModule, HttpServerModule, LoggerModule, Query, ReadDao, Repository, SchemaValidationStrategy, Specification, ValidationPipeline, XenoAppBuilder, definePlugin, withAuth, withAuthZ, withConcurrency, withConsoleLogger, withCors, withCsrf, withCustomHttp, withEnrichmentIdentity, withIdempotency, withPerformance, withQueryCaching, withValidation, withoutCsrf };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IRequest, IHandler, IFactory, UserContext, Optional, ResultType, ICommand, RequestType, IStrategy, IPolicyRegistry, IContextAccessor, RequestContext, Identity, IValidatorService, IPipelineBehavior, Delegate, IQuery, ICacheableOptions, ISpecification, XenoRegistry, IXenoApplication, IServiceContainer, ServicesProxy, XenoIncomingRequest, ResponseDto, NativeListenOptions, IAppBuilder, IConfigurationService, Nullable, HttpServerPlugin, NativeRouteDefinition, SetupAction, MiddlewareConfig, ContextPlugin, LoggerPlugin, LoggerConfig, CachePlugin, CacheConfig, AuthPlugin, AuthModuleOptions, DbPlugin, PipelinePlugin, HttpPlugin, HttpConfig, IModule, IRequestContext, ITransactionalDb, DbModuleOptions, IServiceScope, IUnitOfWork, IDisposable, AuthorizationOptions, ConcurrencyOptions, XenoPlugin, IdempotencyOptions, LogLevel, PerformanceOptions, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, IMediator, Dictionary, AppError } from '@xeno-js/shared';
1
+ import { IRequest, IHandler, IFactory, UserContext, Optional, ResultType, ICommand, RequestType, IStrategy, IPolicyRegistry, IContextAccessor, RequestContext, Identity, IValidatorService, IPipelineBehavior, Delegate, IQuery, ICacheableOptions, ISpecification, XenoRegistry, IXenoApplication, IServiceContainer, ServicesProxy, XenoIncomingRequest, ResponseDto, NativeListenOptions, IAppBuilder, IConfigurationService, Nullable, HttpServerPlugin, NativeRouteDefinition, SetupAction, MiddlewareConfig, ContextPlugin, LoggerPlugin, LoggerConfig, CachePlugin, CacheConfig, AuthPlugin, AuthModuleOptions, DbPlugin, PipelinePlugin, HttpPlugin, HttpConfig, IModule, IRequestContext, ITransactionalDb, DbModuleOptions, IServiceScope, IUnitOfWork, IDisposable, AuthorizationOptions, ConcurrencyOptions, XenoPlugin, IdempotencyOptions, IdentityEnrichmentOptions, LogLevel, PerformanceOptions, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, IMediator, Dictionary, AppError } from '@xeno-js/shared';
2
2
  export * from '@xeno-js/shared';
3
3
 
4
4
  /**
@@ -601,6 +601,8 @@ declare const withCustomHttp: <TRegistry extends XenoRegistry = XenoRegistry>(co
601
601
 
602
602
  declare const withIdempotency: <TRegistry extends XenoRegistry = XenoRegistry>(setup?: SetupAction<IdempotencyOptions, IConfigurationService>) => PipelinePlugin<TRegistry>;
603
603
 
604
+ declare const withEnrichmentIdentity: <TRegistry extends XenoRegistry = XenoRegistry>(setup?: SetupAction<IdentityEnrichmentOptions, IConfigurationService>) => PipelinePlugin<TRegistry>;
605
+
604
606
  interface ConsoleOptions {
605
607
  isEnabled?: boolean;
606
608
  level?: LogLevel;
@@ -794,4 +796,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
794
796
  protected getContext(): Optional<RequestContext>;
795
797
  }
796
798
 
797
- export { AuthModule, BaseAuthorizationStrategy, BaseController, BaseHandler, CacheModule, Command, ContextModule, DbModule, HttpServerModule, LoggerModule, Query, ReadDao, Repository, SchemaValidationStrategy, Specification, ValidationPipeline, XenoAppBuilder, definePlugin, withAuth, withAuthZ, withConcurrency, withConsoleLogger, withCors, withCsrf, withCustomHttp, withIdempotency, withPerformance, withQueryCaching, withValidation, withoutCsrf };
799
+ export { AuthModule, BaseAuthorizationStrategy, BaseController, BaseHandler, CacheModule, Command, ContextModule, DbModule, HttpServerModule, LoggerModule, Query, ReadDao, Repository, SchemaValidationStrategy, Specification, ValidationPipeline, XenoAppBuilder, definePlugin, withAuth, withAuthZ, withConcurrency, withConsoleLogger, withCors, withCsrf, withCustomHttp, withEnrichmentIdentity, withIdempotency, withPerformance, withQueryCaching, withValidation, withoutCsrf };
package/dist/index.js CHANGED
@@ -489,6 +489,21 @@ var IdempotencyPipeline = class _IdempotencyPipeline {
489
489
  }
490
490
  };
491
491
 
492
+ // src/application/cqrs/pipelines/identity-enrichment.pipeline.ts
493
+ var IdentityEnrichmentPipeline = class {
494
+ constructor(_requestContext, _strategy) {
495
+ this._requestContext = _requestContext;
496
+ this._strategy = _strategy;
497
+ }
498
+ _requestContext;
499
+ _strategy;
500
+ async handle(request, next) {
501
+ const identity = this._requestContext.getIdentity() ?? {};
502
+ await this._strategy.execute(identity);
503
+ return next();
504
+ }
505
+ };
506
+
492
507
  // src/application/cqrs/pipelines/logging.pipeline.ts
493
508
  var LoggingPipeline = class {
494
509
  /**
@@ -733,8 +748,16 @@ var UserAuthorizationStrategy = class extends BaseAuthorizationStrategy {
733
748
  }
734
749
  };
735
750
 
751
+ // src/application/cqrs/pipelines/pipeline_strategies/enrichment/noop-identity-enrichment.strategy.ts
752
+ import { Result as Result11 } from "@xeno-js/shared";
753
+ var NoopIdentityEnrichmentStrategy = class {
754
+ async execute(_identity) {
755
+ return Result11.ok();
756
+ }
757
+ };
758
+
736
759
  // src/application/cqrs/pipelines/pipeline_strategies/validation/schema-validation.strategy.ts
737
- import { AppError as AppError11, Result as Result11 } from "@xeno-js/shared";
760
+ import { AppError as AppError11, Result as Result12 } from "@xeno-js/shared";
738
761
  var SchemaValidationStrategy = class {
739
762
  /**
740
763
  * @description Constructs a new instance of the SchemaValidationStrategy class, which takes an IValidatorService as a parameter. This service is used to check for the existence of validation schemas and to perform the actual validation of requests against those schemas. The constructor initializes the strategy with the provided validator service, allowing it to execute the validation logic when handling requests in the CQRS pipeline.
@@ -755,18 +778,18 @@ var SchemaValidationStrategy = class {
755
778
  if (!parseResult.isOk()) {
756
779
  const validatorError = parseResult.getErrorOrThrow();
757
780
  const details = validatorError.cause instanceof Error ? validatorError.cause.message : validatorError.message;
758
- return Result11.fail(
781
+ return Result12.fail(
759
782
  Object.assign(AppError11.validationError(request.intent, `Validation failed: ${details}`), {
760
783
  validatorError
761
784
  })
762
785
  );
763
786
  }
764
- return Result11.ok(true);
787
+ return Result12.ok(true);
765
788
  }
766
789
  };
767
790
 
768
791
  // src/application/cqrs/pipelines/query-caching.pipeline.ts
769
- import { Result as Result12 } from "@xeno-js/shared";
792
+ import { Result as Result13 } from "@xeno-js/shared";
770
793
  import { Guards as Guards9 } from "@xeno-js/shared";
771
794
  var QueryCachingPipeline = class {
772
795
  /**
@@ -800,7 +823,7 @@ var QueryCachingPipeline = class {
800
823
  this._logger.debug(
801
824
  `[Cache HIT] Returning data from cache for: ${request.cacheOptions.cacheKey}`
802
825
  );
803
- return Result12.ok(cachedResponse);
826
+ return Result13.ok(cachedResponse);
804
827
  }
805
828
  } catch (error) {
806
829
  this._logger.warn(
@@ -824,7 +847,7 @@ var QueryCachingPipeline = class {
824
847
  };
825
848
 
826
849
  // src/application/cqrs/pipelines/validation.pipeline.ts
827
- import { Result as Result13 } from "@xeno-js/shared";
850
+ import { Result as Result14 } from "@xeno-js/shared";
828
851
  var ValidationPipeline = class {
829
852
  /** @description Constructs a new instance of the ValidationPipeline class, which takes an array of IStrategy instances as validators. These validators are used to perform validation checks on the incoming requests. The constructor initializes the pipeline with the provided validators, allowing it to execute the validation logic when handling requests in the CQRS pipeline.
830
853
  * @param _validators An array of IStrategy instances that represent the validation strategies to be applied to incoming requests. Each strategy should implement the isApplicable method to determine if it should be applied to a given request and the execute method to perform the actual validation logic, returning a Result indicating the success or failure of the validation.
@@ -842,7 +865,7 @@ var ValidationPipeline = class {
842
865
  for (const validator of this._validators) {
843
866
  const validationResult = await validator.execute(request);
844
867
  if (!validationResult.isOk()) {
845
- return Result13.fail(validationResult.getErrorOrThrow());
868
+ return Result14.fail(validationResult.getErrorOrThrow());
846
869
  }
847
870
  }
848
871
  return next();
@@ -862,7 +885,7 @@ var Query = class {
862
885
  };
863
886
 
864
887
  // src/application/gate_keepers/gate-keeper.ts
865
- import { Result as Result14 } from "@xeno-js/shared";
888
+ import { Result as Result15 } from "@xeno-js/shared";
866
889
  import { Guards as Guards10, GUEST } from "@xeno-js/shared";
867
890
  var GateKeeper = class {
868
891
  constructor(_authServiceResolver, _mapper) {
@@ -876,29 +899,29 @@ var GateKeeper = class {
876
899
  const authService = this._authServiceResolver();
877
900
  if (!Guards10.isNullOrEmpty(token)) {
878
901
  const authResult = await authService.authenticate(token);
879
- if (!authResult.isOk()) return Result14.fail(authResult.getErrorOrThrow());
902
+ if (!authResult.isOk()) return Result15.fail(authResult.getErrorOrThrow());
880
903
  const claims = authResult.getValueOrThrow();
881
- if (!Guards10.isNullOrEmpty(claims)) return Result14.ok(this._mapper.map(claims));
882
- return Result14.ok(guest);
904
+ if (!Guards10.isNullOrEmpty(claims)) return Result15.ok(this._mapper.map(claims));
905
+ return Result15.ok(guest);
883
906
  }
884
907
  const userResult = await authService.getUser();
885
908
  if (userResult.isOk()) {
886
909
  const user = userResult.getValueOrThrow();
887
910
  if (Guards10.isDefined(user)) {
888
- return Result14.ok(this._mapper.map(user));
911
+ return Result15.ok(this._mapper.map(user));
889
912
  }
890
913
  }
891
- return Result14.ok(guest);
914
+ return Result15.ok(guest);
892
915
  }
893
916
  };
894
917
 
895
918
  // src/application/gate_keepers/noauth.gate-keeper.ts
896
- import { Result as Result15 } from "@xeno-js/shared";
919
+ import { Result as Result16 } from "@xeno-js/shared";
897
920
  import { GUEST as GUEST2 } from "@xeno-js/shared";
898
921
  var NoAuthGateKeeper = class {
899
922
  async authenticate(_token) {
900
923
  const guest = GUEST2;
901
- return Result15.ok(guest);
924
+ return Result16.ok(guest);
902
925
  }
903
926
  };
904
927
 
@@ -929,7 +952,7 @@ var LoggerUtils = Object.freeze({
929
952
  correlationId: ctx?.tracing?.correlationId,
930
953
  spanId: ctx?.tracing?.spanId,
931
954
  startTime: ctx?.tracing?.startTime,
932
- parentSpanId: ctx?.tracing.parentSpanId
955
+ parentSpanId: ctx?.tracing?.parentSpanId
933
956
  },
934
957
  messaging: ctx?.messaging
935
958
  };
@@ -938,18 +961,17 @@ var LoggerUtils = Object.freeze({
938
961
  toNormalizeError(error) {
939
962
  if (error instanceof Error) {
940
963
  return {
941
- message: error.message,
964
+ ...error,
942
965
  name: error.name,
966
+ message: error.message,
943
967
  stack: error.stack,
944
- cause: error.cause
968
+ cause: Guards11.isDefined(error.cause) ? LoggerUtils.toNormalizeError(error.cause) : error.cause
945
969
  };
946
970
  }
947
- const errorString = Guards11.isString(error) ? error : StringHelper.safeStringify(error);
948
- const customError = new Error(errorString);
949
- if (Guards11.isObject(error) && Guards11.isDefined(error)) {
950
- Object.assign(customError, error);
971
+ if (Guards11.isObject(error)) {
972
+ return { ...error };
951
973
  }
952
- return customError;
974
+ return { message: Guards11.isString(error) ? error : StringHelper.safeStringify(error) };
953
975
  }
954
976
  });
955
977
 
@@ -1004,8 +1026,9 @@ var BaseLogger = class {
1004
1026
  const logMessage = `[${LOG_LEVEL_NAMES[level]}] ${message}`;
1005
1027
  const context = this._requestContext.getContext();
1006
1028
  const safeContext = LoggerUtils.toSafeContext(context);
1029
+ const safeError = LoggerUtils.toNormalizeError(error);
1007
1030
  for (const logger of this._loggers) {
1008
- logger.track(level, logMessage, safeContext, error);
1031
+ logger.track(level, logMessage, safeContext, safeError);
1009
1032
  }
1010
1033
  }
1011
1034
  };
@@ -1143,7 +1166,7 @@ var NotSpecification = class extends Specification {
1143
1166
  };
1144
1167
 
1145
1168
  // src/infrastructure/builder/app.builder.ts
1146
- import { Guards as Guards66, LOG_LEVEL as LOG_LEVEL8, TOKENS as TOKENS17 } from "@xeno-js/shared";
1169
+ import { Guards as Guards67, LOG_LEVEL as LOG_LEVEL8, TOKENS as TOKENS17 } from "@xeno-js/shared";
1147
1170
 
1148
1171
  // src/infrastructure/configuration/node.configuration.ts
1149
1172
  import { Guards as Guards12 } from "@xeno-js/shared";
@@ -2167,7 +2190,7 @@ var CacheModule = class {
2167
2190
  import { Guards as Guards36, TOKENS as TOKENS7 } from "@xeno-js/shared";
2168
2191
 
2169
2192
  // src/infrastructure/events/event.dispatcher.ts
2170
- import { AppError as AppError12, Guards as Guards31, Result as Result16 } from "@xeno-js/shared";
2193
+ import { AppError as AppError12, Guards as Guards31, Result as Result17 } from "@xeno-js/shared";
2171
2194
  var EventDispatcher = class {
2172
2195
  _handlers = /* @__PURE__ */ new Map();
2173
2196
  subscribe(eventType, handler) {
@@ -2178,17 +2201,17 @@ var EventDispatcher = class {
2178
2201
  async publish(event, signal) {
2179
2202
  AppError12.throwIfAborted(signal, "EventDispatcher.publish");
2180
2203
  const handlers = this._handlers.get(event.eventType);
2181
- if (Guards31.isNullOrEmpty(handlers)) return Result16.ok();
2204
+ if (Guards31.isNullOrEmpty(handlers)) return Result17.ok();
2182
2205
  try {
2183
2206
  for (const handler of handlers) {
2184
2207
  const result = await handler.handle(event, signal);
2185
2208
  if (!result.isOk()) {
2186
- return Result16.fail(result.getErrorOrThrow());
2209
+ return Result17.fail(result.getErrorOrThrow());
2187
2210
  }
2188
2211
  }
2189
- return Result16.ok();
2212
+ return Result17.ok();
2190
2213
  } catch (error) {
2191
- return Result16.fail(AppError12.internalServerError("EventDispatcher", error));
2214
+ return Result17.fail(AppError12.internalServerError("EventDispatcher", error));
2192
2215
  }
2193
2216
  }
2194
2217
  };
@@ -2448,6 +2471,7 @@ var PipelineSetupContext = class {
2448
2471
  _queryBehaviors = [];
2449
2472
  _authzOpts = void 0;
2450
2473
  _idempotencyOpts = void 0;
2474
+ _identityEnrichmentOpts = void 0;
2451
2475
  set idempotencyOpts(opts) {
2452
2476
  this._idempotencyOpts = opts;
2453
2477
  }
@@ -2455,6 +2479,14 @@ var PipelineSetupContext = class {
2455
2479
  if (Guards38.isDefined(this._idempotencyOpts)) return Object.freeze(this._idempotencyOpts);
2456
2480
  return this._idempotencyOpts;
2457
2481
  }
2482
+ set identityEnrichmentOpts(opts) {
2483
+ this._identityEnrichmentOpts = opts;
2484
+ }
2485
+ get identityEnrichmentOpts() {
2486
+ if (Guards38.isDefined(this._identityEnrichmentOpts))
2487
+ return Object.freeze(this._identityEnrichmentOpts);
2488
+ return this._identityEnrichmentOpts;
2489
+ }
2458
2490
  set authzOpts(opts) {
2459
2491
  this._authzOpts = opts;
2460
2492
  }
@@ -2504,6 +2536,11 @@ var CqrsModule = class {
2504
2536
  const authzPipeline = await AuthUtils.addAuthZ(container, context.authzOpts);
2505
2537
  context.addCommon(authzPipeline, 40);
2506
2538
  }
2539
+ if (Guards39.isDefined(context.identityEnrichmentOpts)) {
2540
+ const requestContext = container.resolve(TOKENS8.REQUEST_CONTEXT);
2541
+ const strategy = context.identityEnrichmentOpts.strategy ?? new NoopIdentityEnrichmentStrategy();
2542
+ context.addCommon(new IdentityEnrichmentPipeline(requestContext, strategy), 20);
2543
+ }
2507
2544
  if ((Guards39.isDefined(context.idempotencyOpts) || context.isQueryCaching) && !container.isRegistered(TOKENS8.CACHE)) {
2508
2545
  await new CacheModule().configure(container);
2509
2546
  }
@@ -3831,7 +3868,7 @@ import { Guards as Guards58 } from "@xeno-js/shared";
3831
3868
  import { TOKENS as TOKENS14 } from "@xeno-js/shared";
3832
3869
 
3833
3870
  // src/infrastructure/datasources/remote.datasource.ts
3834
- import { AppError as AppError14, Result as Result17 } from "@xeno-js/shared";
3871
+ import { AppError as AppError14, Result as Result18 } from "@xeno-js/shared";
3835
3872
  var RemoteDataSource = class {
3836
3873
  /** The constructor of the RemoteDataSource class takes two dependencies: an instance of an agnostic HTTP client that implements the IHttpClient interface, and an instance of a resilience service that implements the IServiceResilience interface.
3837
3874
  * These dependencies are injected into the class, allowing for greater flexibility and testability.
@@ -3880,7 +3917,7 @@ var RemoteDataSource = class {
3880
3917
  );
3881
3918
  }
3882
3919
  }, options.signal);
3883
- return Result17.ok(response.data);
3920
+ return Result18.ok(response.data);
3884
3921
  }
3885
3922
  setOptions(request, method, body = void 0) {
3886
3923
  return {
@@ -4009,13 +4046,29 @@ var withIdempotency = (setup) => {
4009
4046
  );
4010
4047
  };
4011
4048
 
4049
+ // src/infrastructure/plugin/identity-enrichment.plugin.ts
4050
+ import {
4051
+ Guards as Guards61
4052
+ } from "@xeno-js/shared";
4053
+ var withEnrichmentIdentity = (setup) => {
4054
+ return definePlugin(
4055
+ "pipeline",
4056
+ (_builder, config, context) => {
4057
+ if (!Guards61.isDefined(context)) throw new Error("Pipeline setup is not available.");
4058
+ const options = {};
4059
+ if (Guards61.isDefined(setup)) setup(options, config);
4060
+ context.identityEnrichmentOpts = options;
4061
+ }
4062
+ );
4063
+ };
4064
+
4012
4065
  // src/infrastructure/plugin/logger.plugin.ts
4013
- import { Guards as Guards61, LOG_LEVEL as LOG_LEVEL7 } from "@xeno-js/shared";
4066
+ import { Guards as Guards62, LOG_LEVEL as LOG_LEVEL7 } from "@xeno-js/shared";
4014
4067
  var withConsoleLogger = (setup) => {
4015
4068
  return definePlugin(
4016
4069
  "logger",
4017
4070
  (_builder, config, ctx) => {
4018
- if (!Guards61.isDefined(ctx)) throw new Error("LoggerSetup is not defined.");
4071
+ if (!Guards62.isDefined(ctx)) throw new Error("LoggerSetup is not defined.");
4019
4072
  const options = {
4020
4073
  isEnabled: true,
4021
4074
  level: LOG_LEVEL7.DEBUG
@@ -4028,16 +4081,16 @@ var withConsoleLogger = (setup) => {
4028
4081
 
4029
4082
  // src/infrastructure/plugin/performance.plugin.ts
4030
4083
  import {
4031
- Guards as Guards62
4084
+ Guards as Guards63
4032
4085
  } from "@xeno-js/shared";
4033
4086
  import { TOKENS as TOKENS15 } from "@xeno-js/shared";
4034
4087
  var withPerformance = (setup) => {
4035
4088
  return definePlugin(
4036
4089
  "pipeline",
4037
4090
  (builder, config, context) => {
4038
- if (!Guards62.isDefined(context)) throw new Error("Pipeline setup is not available.");
4091
+ if (!Guards63.isDefined(context)) throw new Error("Pipeline setup is not available.");
4039
4092
  const options = {};
4040
- if (Guards62.isDefined(setup)) setup(options, config);
4093
+ if (Guards63.isDefined(setup)) setup(options, config);
4041
4094
  const logger = builder.resolve(TOKENS15.LOGGER);
4042
4095
  context.addCommon(
4043
4096
  new PerformancePipeline(logger, options?.intentThresholdMs, options?.thresholdMs ?? 500),
@@ -4048,12 +4101,12 @@ var withPerformance = (setup) => {
4048
4101
  };
4049
4102
 
4050
4103
  // src/infrastructure/plugin/query.plugin.ts
4051
- import { Guards as Guards63 } from "@xeno-js/shared";
4104
+ import { Guards as Guards64 } from "@xeno-js/shared";
4052
4105
  var withQueryCaching = () => {
4053
4106
  return definePlugin(
4054
4107
  "pipeline",
4055
4108
  (_builder, _config, context) => {
4056
- if (!Guards63.isDefined(context)) throw new Error("Pipeline setup is not available.");
4109
+ if (!Guards64.isDefined(context)) throw new Error("Pipeline setup is not available.");
4057
4110
  context.addQuery();
4058
4111
  }
4059
4112
  );
@@ -4061,16 +4114,16 @@ var withQueryCaching = () => {
4061
4114
 
4062
4115
  // src/infrastructure/plugin/validation.plugin.ts
4063
4116
  import {
4064
- Guards as Guards64
4117
+ Guards as Guards65
4065
4118
  } from "@xeno-js/shared";
4066
4119
  var withValidation = (setup) => {
4067
4120
  return definePlugin(
4068
4121
  "pipeline",
4069
4122
  (_builder, config, context) => {
4070
- if (!Guards64.isDefined(context)) throw new Error("Pipeline setup is not available.");
4123
+ if (!Guards65.isDefined(context)) throw new Error("Pipeline setup is not available.");
4071
4124
  const strategies = [];
4072
4125
  setup(strategies, config);
4073
- if (Guards64.isNullOrEmpty(strategies)) return;
4126
+ if (Guards65.isNullOrEmpty(strategies)) return;
4074
4127
  const validationPipeline = new ValidationPipeline(strategies);
4075
4128
  context.addCommon(validationPipeline, 50);
4076
4129
  }
@@ -4078,7 +4131,7 @@ var withValidation = (setup) => {
4078
4131
  };
4079
4132
 
4080
4133
  // src/infrastructure/xeno_application/xeno.application.ts
4081
- import { AppError as AppError17, Guards as Guards65, GUEST as GUEST5, GuidHelper as GuidHelper13 } from "@xeno-js/shared";
4134
+ import { AppError as AppError17, Guards as Guards66, GUEST as GUEST5, GuidHelper as GuidHelper13 } from "@xeno-js/shared";
4082
4135
  import { TOKENS as TOKENS16 } from "@xeno-js/shared";
4083
4136
  var XenoApplication = class {
4084
4137
  constructor(_container) {
@@ -4105,7 +4158,7 @@ var XenoApplication = class {
4105
4158
  const serviceProxy = this._container.resolve(TOKENS16.SERVICE_PROXY);
4106
4159
  const requestContext = this._container.resolve(TOKENS16.REQUEST_CONTEXT);
4107
4160
  const scope = requestContext.getScope();
4108
- if (!Guards65.isDefined(scope)) {
4161
+ if (!Guards66.isDefined(scope)) {
4109
4162
  throw AppError17.notFound(
4110
4163
  "[XenoApplication Error]",
4111
4164
  'Active scope not found.\nPlease use the "runInScope" or "handle" method for tasks outside the HTTP transport.'
@@ -4182,7 +4235,7 @@ var XenoAppBuilder = class {
4182
4235
  this._container.addSingleton(TOKENS17.CONFIGURATION_SERVICE, () => this._configuration);
4183
4236
  }
4184
4237
  _getConfigurationService(service) {
4185
- if (!Guards66.isDefined(service) || service === "node")
4238
+ if (!Guards67.isDefined(service) || service === "node")
4186
4239
  return new EnvironmentConfigurationService();
4187
4240
  if (service === "vite") return new ViteConfigurationService();
4188
4241
  return service;
@@ -4270,7 +4323,7 @@ var XenoAppBuilder = class {
4270
4323
  */
4271
4324
  addMiddlewares(setupAction) {
4272
4325
  if (this._isMiddlewareModuleQueued) return this;
4273
- if (Guards66.isDefined(setupAction)) setupAction(this._middlewareConfig, this._configuration);
4326
+ if (Guards67.isDefined(setupAction)) setupAction(this._middlewareConfig, this._configuration);
4274
4327
  this._modules.push({
4275
4328
  priority: 4,
4276
4329
  name: "MiddlewareModule",
@@ -4296,7 +4349,7 @@ var XenoAppBuilder = class {
4296
4349
  */
4297
4350
  addContext(plugin) {
4298
4351
  if (this._isContextModuleQueued) return this;
4299
- if (Guards66.isDefined(plugin)) plugin(this, this._configuration);
4352
+ if (Guards67.isDefined(plugin)) plugin(this, this._configuration);
4300
4353
  else
4301
4354
  this._modules.push({
4302
4355
  priority: 0,
@@ -4311,7 +4364,7 @@ var XenoAppBuilder = class {
4311
4364
  }
4312
4365
  addLogger(pluginOrSetup) {
4313
4366
  if (this._isLoggerModuleQueued) return this;
4314
- if (!Guards66.isDefined(pluginOrSetup)) {
4367
+ if (!Guards67.isDefined(pluginOrSetup)) {
4315
4368
  this._modules.push({
4316
4369
  priority: 1,
4317
4370
  name: "LoggerModule",
@@ -4325,7 +4378,7 @@ var XenoAppBuilder = class {
4325
4378
  });
4326
4379
  }
4327
4380
  });
4328
- } else if (Guards66.isArray(pluginOrSetup)) {
4381
+ } else if (Guards67.isArray(pluginOrSetup)) {
4329
4382
  this._modules.push({
4330
4383
  priority: 1,
4331
4384
  name: "LoggerModule",
@@ -4379,7 +4432,7 @@ var XenoAppBuilder = class {
4379
4432
  }
4380
4433
  addCache(pluginOrSetup) {
4381
4434
  if (this._isCacheModuleQueued) return this;
4382
- if (!Guards66.isDefined(pluginOrSetup))
4435
+ if (!Guards67.isDefined(pluginOrSetup))
4383
4436
  this._modules.push({
4384
4437
  priority: 2,
4385
4438
  name: "CacheModule",
@@ -4476,8 +4529,8 @@ var XenoAppBuilder = class {
4476
4529
  */
4477
4530
  addPipeline(pluginOrPlugins) {
4478
4531
  if (this._isPipelineModuleQueued) return this;
4479
- if (Guards66.isDefined(pluginOrPlugins))
4480
- this._pipelinePlugins = Guards66.isArray(pluginOrPlugins) ? pluginOrPlugins : [pluginOrPlugins];
4532
+ if (Guards67.isDefined(pluginOrPlugins))
4533
+ this._pipelinePlugins = Guards67.isArray(pluginOrPlugins) ? pluginOrPlugins : [pluginOrPlugins];
4481
4534
  this._modules.push({
4482
4535
  priority: 5,
4483
4536
  name: "CqrsModule",
@@ -4578,7 +4631,7 @@ var XenoAppBuilder = class {
4578
4631
  * @link https://github.com/xeno-js/xeno-js
4579
4632
  */
4580
4633
  build() {
4581
- if (Guards66.isDefined(this._buildPromise)) {
4634
+ if (Guards67.isDefined(this._buildPromise)) {
4582
4635
  return this._buildPromise;
4583
4636
  }
4584
4637
  const attempt = this._executeBuild();
@@ -4624,21 +4677,21 @@ var XenoAppBuilder = class {
4624
4677
  console.error(`\u{1F449} Module: **${queued.name}**`);
4625
4678
  console.error(`\u{1F4DD} Reason: ${errorMessage}
4626
4679
  `);
4627
- if (error instanceof Error && Guards66.isDefined(error.stack)) {
4680
+ if (error instanceof Error && Guards67.isDefined(error.stack)) {
4628
4681
  console.error(error.stack);
4629
4682
  }
4630
4683
  throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
4631
4684
  }
4632
4685
  }
4633
4686
  console.info("\u2705 Application modules bootstrapped successfully.");
4634
- if (Guards66.isDefined(this._appFactory)) return this._appFactory(this._container);
4687
+ if (Guards67.isDefined(this._appFactory)) return this._appFactory(this._container);
4635
4688
  return new XenoApplication(this._container);
4636
4689
  }
4637
4690
  };
4638
4691
 
4639
4692
  // src/infrastructure/repositories/read-dao.ts
4640
- import { AppError as AppError18, Result as Result18 } from "@xeno-js/shared";
4641
- import { Guards as Guards67 } from "@xeno-js/shared";
4693
+ import { AppError as AppError18, Result as Result19 } from "@xeno-js/shared";
4694
+ import { Guards as Guards68 } from "@xeno-js/shared";
4642
4695
  var ReadDao = class {
4643
4696
  /**
4644
4697
  * Constructs a new ReadDao instance.
@@ -4660,21 +4713,21 @@ var ReadDao = class {
4660
4713
  async findById(id, ctx, signal) {
4661
4714
  AppError18.throwIfAborted(signal, "ReadDao.findById");
4662
4715
  const result = await this._dataSource.findById(id, ctx, signal);
4663
- if (Guards67.isNullOrEmpty(result)) return Result18.ok();
4716
+ if (Guards68.isNullOrEmpty(result)) return Result19.ok();
4664
4717
  const entity = this._mapper.toEntity(result);
4665
- return Result18.ok(entity);
4718
+ return Result19.ok(entity);
4666
4719
  }
4667
4720
  async findAll(ctx, signal) {
4668
4721
  AppError18.throwIfAborted(signal, "ReadDao.findAll");
4669
4722
  const results = await this._dataSource.findAll(ctx, signal);
4670
4723
  const entities = results.map((result) => this._mapper.toEntity(result));
4671
- return Result18.ok(entities);
4724
+ return Result19.ok(entities);
4672
4725
  }
4673
4726
  };
4674
4727
 
4675
4728
  // src/infrastructure/repositories/repository.ts
4676
- import { AppError as AppError19, Result as Result19 } from "@xeno-js/shared";
4677
- import { Guards as Guards68 } from "@xeno-js/shared";
4729
+ import { AppError as AppError19, Result as Result20 } from "@xeno-js/shared";
4730
+ import { Guards as Guards69 } from "@xeno-js/shared";
4678
4731
  var Repository = class {
4679
4732
  /**
4680
4733
  * Constructs a new Repository instance.
@@ -4696,33 +4749,33 @@ var Repository = class {
4696
4749
  async findById(id, ctx, signal) {
4697
4750
  AppError19.throwIfAborted(signal, "Repository.findById");
4698
4751
  const result = await this._dataSource.findById(id, ctx, signal);
4699
- if (Guards68.isNullOrEmpty(result)) return Result19.ok();
4752
+ if (Guards69.isNullOrEmpty(result)) return Result20.ok();
4700
4753
  const entity = this._mapper.toEntity(result);
4701
- return Result19.ok(entity);
4754
+ return Result20.ok(entity);
4702
4755
  }
4703
4756
  async findAll(ctx, signal) {
4704
4757
  AppError19.throwIfAborted(signal, "Repository.findAll");
4705
4758
  const results = await this._dataSource.findAll(ctx, signal);
4706
4759
  const entities = results.map((result) => this._mapper.toEntity(result));
4707
- return Result19.ok(entities);
4760
+ return Result20.ok(entities);
4708
4761
  }
4709
4762
  async save(entity, signal) {
4710
4763
  const dto = this._mapper.toDto(entity);
4711
4764
  AppError19.throwIfAborted(signal, "Repository.save");
4712
4765
  await this._dataSource.insert(dto, signal);
4713
- return Result19.ok();
4766
+ return Result20.ok();
4714
4767
  }
4715
4768
  async delete(entity, ctx, signal) {
4716
4769
  const dto = this._mapper.toDto(entity);
4717
4770
  AppError19.throwIfAborted(signal, "Repository.delete");
4718
4771
  await this._dataSource.delete(dto, ctx, signal);
4719
- return Result19.ok();
4772
+ return Result20.ok();
4720
4773
  }
4721
4774
  async update(id, entity, ctx, signal) {
4722
4775
  const dto = this._mapper.toPartialDto(entity);
4723
4776
  AppError19.throwIfAborted(signal, "Repository.update");
4724
4777
  await this._dataSource.update(id, dto, ctx, signal);
4725
- return Result19.ok();
4778
+ return Result20.ok();
4726
4779
  }
4727
4780
  };
4728
4781
 
@@ -4784,6 +4837,7 @@ export {
4784
4837
  withCors,
4785
4838
  withCsrf,
4786
4839
  withCustomHttp,
4840
+ withEnrichmentIdentity,
4787
4841
  withIdempotency,
4788
4842
  withPerformance,
4789
4843
  withQueryCaching,