@xeno-js/shared 0.1.5 → 0.1.6

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
@@ -2720,6 +2720,12 @@ declare const GuidHelper: Readonly<{
2720
2720
  * @link https://github.com/xeno-js/xeno-js
2721
2721
  */
2722
2722
  declare const HttpHelper: Readonly<{
2723
+ /**
2724
+ * @description A function that masks the IP address in the given headers object.
2725
+ * @param ip The IP address to mask.
2726
+ * @returns The masked IP address.
2727
+ */
2728
+ readonly maskIp: (ip: Optional<string>) => Optional<string>;
2723
2729
  /**
2724
2730
  * @description Normalizes HTTP headers by converting all header values to strings. If a header value is an array, it joins the array elements into a single string separated by commas. This method ensures that the headers are in a consistent format, which can be particularly useful when working with different HTTP client libraries that may represent headers in various ways. If the input headers are not defined or not an object, it returns an empty object.
2725
2731
  * @param headers The input headers to be normalized, which can be of any type. The method checks if the headers are defined and are an object before processing them.
@@ -3686,6 +3692,15 @@ interface NetworkContext {
3686
3692
  * @link https://github.com/xeno-js/xeno-js
3687
3693
  */
3688
3694
  readonly csrf: Optional<string>;
3695
+ /**
3696
+ * @description The CSRF cookie for the request, which can be used for preventing cross-site request forgery attacks.
3697
+ *
3698
+ * @author Xeno
3699
+ * @version 1.0.0
3700
+ * @since 2025-09-30
3701
+ * @link https://github.com/xeno-js/xeno-js
3702
+ */
3703
+ readonly csrfCookie: Optional<string>;
3689
3704
  /**
3690
3705
  * @description The transport used for the request, which can be used for logging, monitoring, or applying specific middleware logic.
3691
3706
  *
@@ -4969,6 +4984,29 @@ interface ILoggerClient {
4969
4984
  track<T>(level: LogLevel, message: string, context: Optional<T>, error: Optional<unknown>): void;
4970
4985
  }
4971
4986
 
4987
+ /**
4988
+ * @description LoggerContext defines the structure for logging-related information used in logging and monitoring. It includes identity, network, and tracing information, as well as optional messaging context for distributed tracing.
4989
+ */
4990
+ interface LoggerContext {
4991
+ identity: {
4992
+ userId: Optional<string>;
4993
+ tenantId: Optional<string>;
4994
+ };
4995
+ network: {
4996
+ requestId: Optional<string>;
4997
+ path: Optional<string>;
4998
+ origin: Optional<string>;
4999
+ clientIp: Optional<string>;
5000
+ };
5001
+ tracing: {
5002
+ correlationId: Optional<string>;
5003
+ spanId: Optional<string>;
5004
+ startTime: Optional<number>;
5005
+ parentSpanId: Optional<string>;
5006
+ };
5007
+ messaging?: Maybe<MessagingContext>;
5008
+ }
5009
+
4972
5010
  /**
4973
5011
  * @description Generic mapper interface defining a contract for mapping objects of type TSource to type TDestination. Mappers are used to convert data between different layers of the application, such as transforming DTOs to domain entities or vice versa. This interface defines a contract that all mappers must implement, ensuring consistency and maintainability of the code.
4974
5012
  * @template TSource The type of the source object to be mapped.
@@ -5874,6 +5912,18 @@ declare class BaseLogger implements ILogger {
5874
5912
  private broadcast;
5875
5913
  }
5876
5914
 
5915
+ /**
5916
+ * @description LoggerUtils provides utility functions for working with LoggerContext objects.
5917
+ */
5918
+ declare const LoggerUtils: Readonly<{
5919
+ /**
5920
+ * @description toSafeContext converts a RequestContext object to a LoggerContext object, ensuring that only the necessary fields are included.
5921
+ * @param ctx The RequestContext object to convert.
5922
+ * @returns The converted LoggerContext object.
5923
+ */
5924
+ readonly toSafeContext: (ctx: Optional<RequestContext>) => LoggerContext;
5925
+ }>;
5926
+
5877
5927
  declare const StorageHelper: Readonly<{
5878
5928
  readonly create: (opts: {
5879
5929
  type: Optional<"local" | "session" | "memory" | "cookie">;
@@ -6068,4 +6118,4 @@ declare class ZodValidatorService implements IValidatorService {
6068
6118
  validate<T>(key: string, data: T): Promise<ResultType<boolean>>;
6069
6119
  }
6070
6120
 
6071
- export { AbortSignalHelper, type AbstractConstructor, type ApiResponseDto, AppError, type AsyncFactory, type AsyncResolver, type AuthClaims, type AuthConfig, type AuthPolicy, AxiosFactory, AxiosHttpClient, BaseLogger, type CacheClientConfig, type CacheConfig, CacheKeyBuilder, Command, type Constructor, type CookieOptions, DEFAULT_CONCURRENCY, DateHelper, type DbConfig, type Delegate, type Dictionary, ERROR_CODES, ERROR_CODE_MESSAGES, Entity, Enumerable, type ErrorCode, type ErrorResponseDto, type Factory, GUEST, Guards, type Guid, GuidHelper, type HttpBaseRequest, type HttpClientConfig, type HttpHeaders, HttpHelper, type HttpMethod, type HttpOptions, type HttpQueryValue, type HttpRequest, type HttpResponse, type HttpResponseType, type IAuthService, type IBaseAccessor, type IBaseAuthService, type IBaseMapper, type ICache, type ICacheKeyBuilder, type ICacheableOptions, type ICommand, type IConcurrencyService, type IConfigurationService, type IContextAccessor, type IController, IDEMPOTENCY_CONSTANTS, type IDisposable, type IEntity, type IExtendendService, type IFactory, type IGateKeeper, type IHandler, type IHttpClient, type IIdempotencyStore, type IIdentityAccessor, type ILogger, type ILoggerClient, type IMapper, type IMediator, type IMiddleware, type INetworkContextAccessor, type IPaginatedResult, type IPipelineBehavior, type IPolicyRegistry, type IQuery, type IReadDao, type IReadDataSource, type IRemoteDataSource, type IRepository, type IRequest, type IServiceExtractor, type IServiceResilience, type ISpecification, type IStorage, type IStrategy, type ITransactionState, type IUnitOfWork, type IValidatorService, type IValueObject, type IWriteDataSource, type Identity, InMemoryCache, type InjectionToken, type KeysOfType, LOG_LEVEL, LOG_LEVEL_NAMES, type LogLevel, MathHelper, type Maybe, type MessageSequence, type MessagingContext, type Metadata, type NetworkContext, type Nullable, type Optional, type Override, PAGINATION_DEFAULTS, PERMISSIONS, type Permission, PromiseHelper, type Provider, type ProxyConfig, Query, REQUEST_TYPE, RESILIENCE_DEFAULTS, ROLES, type RequestContext, type RequestType, type RequireKeys, type Resolver, type ResponseDto, Result, type ResultType, type Role, SORT_DIRECTION, STATUS_CODES, SanitizeHelper, type Session, type SetupAction, type SortDirection, type StatusCode, StorageHelper, StringHelper, type SuccessResponseDto, SupabaseAuthService, SupabaseClaimsMapper, SupabaseSessionMapper, TOKENS, type TracingContext, UniqueId, type UserContext, ValueObject, ZodUtils, ZodValidatorService };
6121
+ export { AbortSignalHelper, type AbstractConstructor, type ApiResponseDto, AppError, type AsyncFactory, type AsyncResolver, type AuthClaims, type AuthConfig, type AuthPolicy, AxiosFactory, AxiosHttpClient, BaseLogger, type CacheClientConfig, type CacheConfig, CacheKeyBuilder, Command, type Constructor, type CookieOptions, DEFAULT_CONCURRENCY, DateHelper, type DbConfig, type Delegate, type Dictionary, ERROR_CODES, ERROR_CODE_MESSAGES, Entity, Enumerable, type ErrorCode, type ErrorResponseDto, type Factory, GUEST, Guards, type Guid, GuidHelper, type HttpBaseRequest, type HttpClientConfig, type HttpHeaders, HttpHelper, type HttpMethod, type HttpOptions, type HttpQueryValue, type HttpRequest, type HttpResponse, type HttpResponseType, type IAuthService, type IBaseAccessor, type IBaseAuthService, type IBaseMapper, type ICache, type ICacheKeyBuilder, type ICacheableOptions, type ICommand, type IConcurrencyService, type IConfigurationService, type IContextAccessor, type IController, IDEMPOTENCY_CONSTANTS, type IDisposable, type IEntity, type IExtendendService, type IFactory, type IGateKeeper, type IHandler, type IHttpClient, type IIdempotencyStore, type IIdentityAccessor, type ILogger, type ILoggerClient, type IMapper, type IMediator, type IMiddleware, type INetworkContextAccessor, type IPaginatedResult, type IPipelineBehavior, type IPolicyRegistry, type IQuery, type IReadDao, type IReadDataSource, type IRemoteDataSource, type IRepository, type IRequest, type IServiceExtractor, type IServiceResilience, type ISpecification, type IStorage, type IStrategy, type ITransactionState, type IUnitOfWork, type IValidatorService, type IValueObject, type IWriteDataSource, type Identity, InMemoryCache, type InjectionToken, type KeysOfType, LOG_LEVEL, LOG_LEVEL_NAMES, type LogLevel, type LoggerContext, LoggerUtils, MathHelper, type Maybe, type MessageSequence, type MessagingContext, type Metadata, type NetworkContext, type Nullable, type Optional, type Override, PAGINATION_DEFAULTS, PERMISSIONS, type Permission, PromiseHelper, type Provider, type ProxyConfig, Query, REQUEST_TYPE, RESILIENCE_DEFAULTS, ROLES, type RequestContext, type RequestType, type RequireKeys, type Resolver, type ResponseDto, Result, type ResultType, type Role, SORT_DIRECTION, STATUS_CODES, SanitizeHelper, type Session, type SetupAction, type SortDirection, type StatusCode, StorageHelper, StringHelper, type SuccessResponseDto, SupabaseAuthService, SupabaseClaimsMapper, SupabaseSessionMapper, TOKENS, type TracingContext, UniqueId, type UserContext, ValueObject, ZodUtils, ZodValidatorService };
package/dist/index.d.ts CHANGED
@@ -2720,6 +2720,12 @@ declare const GuidHelper: Readonly<{
2720
2720
  * @link https://github.com/xeno-js/xeno-js
2721
2721
  */
2722
2722
  declare const HttpHelper: Readonly<{
2723
+ /**
2724
+ * @description A function that masks the IP address in the given headers object.
2725
+ * @param ip The IP address to mask.
2726
+ * @returns The masked IP address.
2727
+ */
2728
+ readonly maskIp: (ip: Optional<string>) => Optional<string>;
2723
2729
  /**
2724
2730
  * @description Normalizes HTTP headers by converting all header values to strings. If a header value is an array, it joins the array elements into a single string separated by commas. This method ensures that the headers are in a consistent format, which can be particularly useful when working with different HTTP client libraries that may represent headers in various ways. If the input headers are not defined or not an object, it returns an empty object.
2725
2731
  * @param headers The input headers to be normalized, which can be of any type. The method checks if the headers are defined and are an object before processing them.
@@ -3686,6 +3692,15 @@ interface NetworkContext {
3686
3692
  * @link https://github.com/xeno-js/xeno-js
3687
3693
  */
3688
3694
  readonly csrf: Optional<string>;
3695
+ /**
3696
+ * @description The CSRF cookie for the request, which can be used for preventing cross-site request forgery attacks.
3697
+ *
3698
+ * @author Xeno
3699
+ * @version 1.0.0
3700
+ * @since 2025-09-30
3701
+ * @link https://github.com/xeno-js/xeno-js
3702
+ */
3703
+ readonly csrfCookie: Optional<string>;
3689
3704
  /**
3690
3705
  * @description The transport used for the request, which can be used for logging, monitoring, or applying specific middleware logic.
3691
3706
  *
@@ -4969,6 +4984,29 @@ interface ILoggerClient {
4969
4984
  track<T>(level: LogLevel, message: string, context: Optional<T>, error: Optional<unknown>): void;
4970
4985
  }
4971
4986
 
4987
+ /**
4988
+ * @description LoggerContext defines the structure for logging-related information used in logging and monitoring. It includes identity, network, and tracing information, as well as optional messaging context for distributed tracing.
4989
+ */
4990
+ interface LoggerContext {
4991
+ identity: {
4992
+ userId: Optional<string>;
4993
+ tenantId: Optional<string>;
4994
+ };
4995
+ network: {
4996
+ requestId: Optional<string>;
4997
+ path: Optional<string>;
4998
+ origin: Optional<string>;
4999
+ clientIp: Optional<string>;
5000
+ };
5001
+ tracing: {
5002
+ correlationId: Optional<string>;
5003
+ spanId: Optional<string>;
5004
+ startTime: Optional<number>;
5005
+ parentSpanId: Optional<string>;
5006
+ };
5007
+ messaging?: Maybe<MessagingContext>;
5008
+ }
5009
+
4972
5010
  /**
4973
5011
  * @description Generic mapper interface defining a contract for mapping objects of type TSource to type TDestination. Mappers are used to convert data between different layers of the application, such as transforming DTOs to domain entities or vice versa. This interface defines a contract that all mappers must implement, ensuring consistency and maintainability of the code.
4974
5012
  * @template TSource The type of the source object to be mapped.
@@ -5874,6 +5912,18 @@ declare class BaseLogger implements ILogger {
5874
5912
  private broadcast;
5875
5913
  }
5876
5914
 
5915
+ /**
5916
+ * @description LoggerUtils provides utility functions for working with LoggerContext objects.
5917
+ */
5918
+ declare const LoggerUtils: Readonly<{
5919
+ /**
5920
+ * @description toSafeContext converts a RequestContext object to a LoggerContext object, ensuring that only the necessary fields are included.
5921
+ * @param ctx The RequestContext object to convert.
5922
+ * @returns The converted LoggerContext object.
5923
+ */
5924
+ readonly toSafeContext: (ctx: Optional<RequestContext>) => LoggerContext;
5925
+ }>;
5926
+
5877
5927
  declare const StorageHelper: Readonly<{
5878
5928
  readonly create: (opts: {
5879
5929
  type: Optional<"local" | "session" | "memory" | "cookie">;
@@ -6068,4 +6118,4 @@ declare class ZodValidatorService implements IValidatorService {
6068
6118
  validate<T>(key: string, data: T): Promise<ResultType<boolean>>;
6069
6119
  }
6070
6120
 
6071
- export { AbortSignalHelper, type AbstractConstructor, type ApiResponseDto, AppError, type AsyncFactory, type AsyncResolver, type AuthClaims, type AuthConfig, type AuthPolicy, AxiosFactory, AxiosHttpClient, BaseLogger, type CacheClientConfig, type CacheConfig, CacheKeyBuilder, Command, type Constructor, type CookieOptions, DEFAULT_CONCURRENCY, DateHelper, type DbConfig, type Delegate, type Dictionary, ERROR_CODES, ERROR_CODE_MESSAGES, Entity, Enumerable, type ErrorCode, type ErrorResponseDto, type Factory, GUEST, Guards, type Guid, GuidHelper, type HttpBaseRequest, type HttpClientConfig, type HttpHeaders, HttpHelper, type HttpMethod, type HttpOptions, type HttpQueryValue, type HttpRequest, type HttpResponse, type HttpResponseType, type IAuthService, type IBaseAccessor, type IBaseAuthService, type IBaseMapper, type ICache, type ICacheKeyBuilder, type ICacheableOptions, type ICommand, type IConcurrencyService, type IConfigurationService, type IContextAccessor, type IController, IDEMPOTENCY_CONSTANTS, type IDisposable, type IEntity, type IExtendendService, type IFactory, type IGateKeeper, type IHandler, type IHttpClient, type IIdempotencyStore, type IIdentityAccessor, type ILogger, type ILoggerClient, type IMapper, type IMediator, type IMiddleware, type INetworkContextAccessor, type IPaginatedResult, type IPipelineBehavior, type IPolicyRegistry, type IQuery, type IReadDao, type IReadDataSource, type IRemoteDataSource, type IRepository, type IRequest, type IServiceExtractor, type IServiceResilience, type ISpecification, type IStorage, type IStrategy, type ITransactionState, type IUnitOfWork, type IValidatorService, type IValueObject, type IWriteDataSource, type Identity, InMemoryCache, type InjectionToken, type KeysOfType, LOG_LEVEL, LOG_LEVEL_NAMES, type LogLevel, MathHelper, type Maybe, type MessageSequence, type MessagingContext, type Metadata, type NetworkContext, type Nullable, type Optional, type Override, PAGINATION_DEFAULTS, PERMISSIONS, type Permission, PromiseHelper, type Provider, type ProxyConfig, Query, REQUEST_TYPE, RESILIENCE_DEFAULTS, ROLES, type RequestContext, type RequestType, type RequireKeys, type Resolver, type ResponseDto, Result, type ResultType, type Role, SORT_DIRECTION, STATUS_CODES, SanitizeHelper, type Session, type SetupAction, type SortDirection, type StatusCode, StorageHelper, StringHelper, type SuccessResponseDto, SupabaseAuthService, SupabaseClaimsMapper, SupabaseSessionMapper, TOKENS, type TracingContext, UniqueId, type UserContext, ValueObject, ZodUtils, ZodValidatorService };
6121
+ export { AbortSignalHelper, type AbstractConstructor, type ApiResponseDto, AppError, type AsyncFactory, type AsyncResolver, type AuthClaims, type AuthConfig, type AuthPolicy, AxiosFactory, AxiosHttpClient, BaseLogger, type CacheClientConfig, type CacheConfig, CacheKeyBuilder, Command, type Constructor, type CookieOptions, DEFAULT_CONCURRENCY, DateHelper, type DbConfig, type Delegate, type Dictionary, ERROR_CODES, ERROR_CODE_MESSAGES, Entity, Enumerable, type ErrorCode, type ErrorResponseDto, type Factory, GUEST, Guards, type Guid, GuidHelper, type HttpBaseRequest, type HttpClientConfig, type HttpHeaders, HttpHelper, type HttpMethod, type HttpOptions, type HttpQueryValue, type HttpRequest, type HttpResponse, type HttpResponseType, type IAuthService, type IBaseAccessor, type IBaseAuthService, type IBaseMapper, type ICache, type ICacheKeyBuilder, type ICacheableOptions, type ICommand, type IConcurrencyService, type IConfigurationService, type IContextAccessor, type IController, IDEMPOTENCY_CONSTANTS, type IDisposable, type IEntity, type IExtendendService, type IFactory, type IGateKeeper, type IHandler, type IHttpClient, type IIdempotencyStore, type IIdentityAccessor, type ILogger, type ILoggerClient, type IMapper, type IMediator, type IMiddleware, type INetworkContextAccessor, type IPaginatedResult, type IPipelineBehavior, type IPolicyRegistry, type IQuery, type IReadDao, type IReadDataSource, type IRemoteDataSource, type IRepository, type IRequest, type IServiceExtractor, type IServiceResilience, type ISpecification, type IStorage, type IStrategy, type ITransactionState, type IUnitOfWork, type IValidatorService, type IValueObject, type IWriteDataSource, type Identity, InMemoryCache, type InjectionToken, type KeysOfType, LOG_LEVEL, LOG_LEVEL_NAMES, type LogLevel, type LoggerContext, LoggerUtils, MathHelper, type Maybe, type MessageSequence, type MessagingContext, type Metadata, type NetworkContext, type Nullable, type Optional, type Override, PAGINATION_DEFAULTS, PERMISSIONS, type Permission, PromiseHelper, type Provider, type ProxyConfig, Query, REQUEST_TYPE, RESILIENCE_DEFAULTS, ROLES, type RequestContext, type RequestType, type RequireKeys, type Resolver, type ResponseDto, Result, type ResultType, type Role, SORT_DIRECTION, STATUS_CODES, SanitizeHelper, type Session, type SetupAction, type SortDirection, type StatusCode, StorageHelper, StringHelper, type SuccessResponseDto, SupabaseAuthService, SupabaseClaimsMapper, SupabaseSessionMapper, TOKENS, type TracingContext, UniqueId, type UserContext, ValueObject, ZodUtils, ZodValidatorService };
package/dist/index.js CHANGED
@@ -1548,6 +1548,29 @@ var GuidHelper = Object.freeze({
1548
1548
 
1549
1549
  // src/shared/utils/http.utils.ts
1550
1550
  var HttpHelper = Object.freeze({
1551
+ /**
1552
+ * @description A function that masks the IP address in the given headers object.
1553
+ * @param ip The IP address to mask.
1554
+ * @returns The masked IP address.
1555
+ */
1556
+ maskIp(ip) {
1557
+ if (!Guards.isDefined(ip)) return void 0;
1558
+ if (ip.includes(".")) {
1559
+ const parts = ip.split(".");
1560
+ if (parts.length === 4) {
1561
+ parts[3] = "x";
1562
+ return parts.join(".");
1563
+ }
1564
+ }
1565
+ if (ip.includes(":")) {
1566
+ const parts = ip.split(":");
1567
+ if (parts.length > 0) {
1568
+ parts[parts.length - 1] = "x";
1569
+ return parts.join(":");
1570
+ }
1571
+ }
1572
+ return ip;
1573
+ },
1551
1574
  /**
1552
1575
  * @description Normalizes HTTP headers by converting all header values to strings. If a header value is an array, it joins the array elements into a single string separated by commas. This method ensures that the headers are in a consistent format, which can be particularly useful when working with different HTTP client libraries that may represent headers in various ways. If the input headers are not defined or not an object, it returns an empty object.
1553
1576
  * @param headers The input headers to be normalized, which can be of any type. The method checks if the headers are defined and are an object before processing them.
@@ -1998,6 +2021,36 @@ var Query = class {
1998
2021
  type = REQUEST_TYPE.QUERY;
1999
2022
  };
2000
2023
 
2024
+ // src/application/loggers/utils/logger-context.utils.ts
2025
+ var LoggerUtils = Object.freeze({
2026
+ /**
2027
+ * @description toSafeContext converts a RequestContext object to a LoggerContext object, ensuring that only the necessary fields are included.
2028
+ * @param ctx The RequestContext object to convert.
2029
+ * @returns The converted LoggerContext object.
2030
+ */
2031
+ toSafeContext(ctx) {
2032
+ return {
2033
+ identity: {
2034
+ userId: ctx?.identity?.userId,
2035
+ tenantId: ctx?.identity?.tenantId
2036
+ },
2037
+ network: {
2038
+ requestId: ctx?.network?.requestId,
2039
+ path: ctx?.network?.path,
2040
+ origin: ctx?.network?.origin,
2041
+ clientIp: HttpHelper.maskIp(ctx?.network?.clientIp)
2042
+ },
2043
+ tracing: {
2044
+ correlationId: ctx?.tracing?.correlationId,
2045
+ spanId: ctx?.tracing?.spanId,
2046
+ startTime: ctx?.tracing?.startTime,
2047
+ parentSpanId: ctx?.tracing.parentSpanId
2048
+ },
2049
+ messaging: ctx?.messaging
2050
+ };
2051
+ }
2052
+ });
2053
+
2001
2054
  // src/application/loggers/base.logger.ts
2002
2055
  var BaseLogger = class {
2003
2056
  /**
@@ -2050,8 +2103,9 @@ var BaseLogger = class {
2050
2103
  if (level < this._minLevel) return;
2051
2104
  const logMessage = `[${LOG_LEVEL_NAMES[level]}] ${message}`;
2052
2105
  const context = this._requestContext.getContext();
2106
+ const safeContext = LoggerUtils.toSafeContext(context);
2053
2107
  for (const logger of this._loggers) {
2054
- logger.track(level, logMessage, context, error);
2108
+ logger.track(level, logMessage, safeContext, error);
2055
2109
  }
2056
2110
  }
2057
2111
  };
@@ -3075,6 +3129,7 @@ export {
3075
3129
  InMemoryCache,
3076
3130
  LOG_LEVEL,
3077
3131
  LOG_LEVEL_NAMES,
3132
+ LoggerUtils,
3078
3133
  MathHelper,
3079
3134
  PAGINATION_DEFAULTS,
3080
3135
  PERMISSIONS,