@xeno-js/core 0.1.1 → 0.1.3

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 { IPipelineBehavior, IRequest, IExtendendService, IBaseAuthService, IServiceExtractor, HttpHeaders, Optional, ICache, ICacheKeyBuilder, IBaseMapper, AuthClaims, Identity, ICommand, IQuery, IConcurrencyService, IConfigurationService, ILoggerClient, IGateKeeper, IIdempotencyStore, ILogger, IMediator, IMiddleware, IStrategy, IPolicyRegistry, HttpMethod, RequestContext, IServiceResilience, Metadata, IFactory, ITransactionState, IUnitOfWork, IDisposable, IValidatorService, IIdentityAccessor, IContextAccessor, INetworkContextAccessor, UserContext, Factory, IBaseAccessor, AuthConfig, CookieOptions, SetupAction, HttpClientConfig, LogLevel, Dictionary, AuthPolicy, ResponseDto, IHandler, ResultType, ISpecification, CacheConfig, DbConfig, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, AppError } from '@xeno-js/shared';
1
+ import { ICache, Optional, IPipelineBehavior, IRequest, IExtendendService, IBaseAuthService, IServiceExtractor, HttpHeaders, ICacheKeyBuilder, IBaseMapper, AuthClaims, Identity, ICommand, IQuery, IConcurrencyService, IConfigurationService, ILoggerClient, IGateKeeper, IIdempotencyStore, ILogger, IMediator, IMiddleware, IStrategy, IPolicyRegistry, HttpMethod, RequestContext, IServiceResilience, Metadata, IFactory, ITransactionState, IUnitOfWork, IDisposable, IValidatorService, IIdentityAccessor, IContextAccessor, INetworkContextAccessor, UserContext, Factory, IBaseAccessor, AuthConfig, CookieOptions, SetupAction, HttpClientConfig, LogLevel, Dictionary, AuthPolicy, ResponseDto, IHandler, ResultType, ISpecification, CacheConfig, DbConfig, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, AppError } from '@xeno-js/shared';
2
2
  export * from '@xeno-js/shared';
3
3
  export { Query as BaseQuery } from '@xeno-js/shared';
4
4
  import { SupabaseClientOptions } from '@supabase/supabase-js';
@@ -8,6 +8,21 @@ import { NodePgDatabase } from 'drizzle-orm/node-postgres';
8
8
  export * from 'drizzle-orm';
9
9
  export { Query } from 'drizzle-orm';
10
10
 
11
+ /**
12
+ * @description IAtomicCache is an interface that extends the ICache interface and adds an increment method. The increment method takes a key and an optional ttlSeconds parameter and returns a Promise that resolves to an incremented value.
13
+ *
14
+ */
15
+ interface IAtomicCache extends ICache {
16
+ /**
17
+ * @description The increment method increments the value associated with the given key in the cache. If the key does not exist, it is created with an initial value of 1. The method returns a Promise that resolves to the incremented value.
18
+ *
19
+ * @param key The key to increment the value for.
20
+ * @param ttlSeconds The time-to-live (TTL) in seconds for the key-value pair. If not provided, the default TTL is used.
21
+ * @returns A Promise that resolves to the incremented value.
22
+ */
23
+ increment(key: string, ttlSeconds: Optional<number | string>): Promise<number>;
24
+ }
25
+
11
26
  /**
12
27
  * @description This file defines the injection tokens used for dependency injection in the application.
13
28
  * Injection tokens are unique identifiers that are used to register and resolve dependencies in the container.
@@ -53,7 +68,7 @@ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
53
68
  * @since 2025-09-30
54
69
  * @link https://github.com/xeno-js/xeno-js
55
70
  */
56
- readonly CACHE: ICache;
71
+ readonly CACHE: IAtomicCache;
57
72
  /** @description Token used to register and resolve the CacheKeyBuilder instance in the dependency injection container.
58
73
  *
59
74
  * @author Xeno
@@ -118,6 +133,33 @@ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
118
133
  * @link https://github.com/xeno-js/xeno-js
119
134
  */
120
135
  readonly CONSOLE_LOGGER: ILoggerClient;
136
+ /** @description Token used to register and resolve the CookieExtractor instance in the dependency injection container.
137
+ *
138
+ * @author Xeno
139
+ * @version 1.0.0
140
+ * @since 2025-09-30
141
+ * @link https://github.com/xeno-js/xeno-js
142
+ */
143
+ readonly COOKIE_EXTRACTOR: IServiceExtractor<{
144
+ header: Optional<string>;
145
+ name: string;
146
+ }, Optional<string>>;
147
+ /** @description Token used to register and resolve the CsrfTokenService instance in the dependency injection container.
148
+ *
149
+ * @author Xeno
150
+ * @version 1.0.0
151
+ * @since 2025-09-30
152
+ * @link https://github.com/xeno-js/xeno-js
153
+ */
154
+ readonly CSRF_TOKEN_SERVICE: ICsrfTokenService;
155
+ /** @description Token used to register and resolve the CryptoService instance in the dependency injection container.
156
+ *
157
+ * @author Xeno
158
+ * @version 1.0.0
159
+ * @since 2025-09-30
160
+ * @link https://github.com/xeno-js/xeno-js
161
+ */
162
+ readonly CRYPTO_SERVICE: ICryptoService;
121
163
  /** @description Token used to register and resolve the DbContext instance in the dependency injection container.
122
164
  *
123
165
  * @author Xeno
@@ -192,6 +234,7 @@ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
192
234
  readonly MIDDLEWARE: IMiddleware<HttpHeaders>;
193
235
  readonly AUTH_MIDDLEWARE: IMiddleware<HttpHeaders>;
194
236
  readonly CSRF_MIDDLEWARE: IMiddleware<HttpHeaders>;
237
+ readonly CSRF_COOKIE_MIDDLEWARE: IMiddleware<HttpHeaders>;
195
238
  readonly ALLOW_ORIGIN_MIDDLEWARE: IMiddleware<HttpHeaders>;
196
239
  readonly CORS_MIDDLEWARE: IMiddleware<HttpHeaders>;
197
240
  readonly METHOD_CHECK_MIDDLEWARE: IMiddleware<HttpHeaders>;
@@ -270,6 +313,14 @@ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
270
313
  * @link https://github.com/xeno-js/xeno-js
271
314
  */
272
315
  readonly RESILIENCE_CLIENT: IServiceResilience;
316
+ /** @description Token used to register and resolve the IIPResolver instance in the dependency injection container.
317
+ *
318
+ * @author Xeno
319
+ * @version 1.0.0
320
+ * @since 2025-09-30
321
+ * @link https://github.com/xeno-js/xeno-js
322
+ */
323
+ readonly IP_RESOLVER: IIPResolver;
273
324
  /** @description Token used to register and resolve the RoleAuthorizationPipeline instance in the dependency injection container.
274
325
  *
275
326
  * @author Xeno
@@ -709,6 +760,32 @@ interface IServiceScopeAccessor<TRegistry extends ApplicationRegistry<unknown> =
709
760
  getScope(): Optional<IServiceScope<TRegistry>>;
710
761
  }
711
762
 
763
+ /**
764
+ * @description Interface for the crypto service
765
+ */
766
+ interface ICryptoService {
767
+ /**
768
+ * @description Generates a random byte array of the specified size.
769
+ * @param size The size of the byte array to generate.
770
+ * @returns A random byte array of the specified size.
771
+ */
772
+ randomBytes(size: number): Uint8Array;
773
+ /**
774
+ * @description Generates a HMAC SHA-256 hash of the specified data using the specified secret.
775
+ * @param secret The secret to use for the HMAC SHA-256 hash.
776
+ * @param data The data to hash.
777
+ * @returns A promise that resolves to the HMAC SHA-256 hash of the specified data.
778
+ */
779
+ hmacSha256(secret: string, data: string): Promise<string>;
780
+ /**
781
+ * @description Compares two byte arrays in a way that is resistant to timing attacks.
782
+ * @param a The first byte array to compare.
783
+ * @param b The second byte array to compare.
784
+ * @returns True if the two byte arrays are equal, false otherwise.
785
+ */
786
+ timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
787
+ }
788
+
712
789
  /**
713
790
  * @description Represents a module that can be registered with the service container.
714
791
  *
@@ -736,6 +813,19 @@ interface IModule<TRegistry extends ApplicationRegistry<unknown> = ApplicationRe
736
813
  configure(container: IServiceContainer<TRegistry>, opts?: Optional<TOptions>): Promise<void>;
737
814
  }
738
815
 
816
+ /**
817
+ * @description IIPResolver is a generic interface that defines a contract for resolving IP addresses.
818
+ */
819
+ interface IIPResolver {
820
+ /**
821
+ * @description Resolves a optional string based on the input of type T.
822
+ * @param request The input of type T.
823
+ * @param ip The optional IP address of the client.
824
+ * @returns The resolved optional string.
825
+ */
826
+ resolve<T>(request: T, ip: Optional<string>): Optional<string>;
827
+ }
828
+
739
829
  /**
740
830
  * @description Interface for the allow method service.
741
831
  *
@@ -779,6 +869,25 @@ interface IAllowOrigin {
779
869
  isAllowed(origin: Optional<string>): boolean;
780
870
  }
781
871
 
872
+ /**
873
+ * @description Interface for the CSRF token service
874
+ */
875
+ interface ICsrfTokenService {
876
+ /**
877
+ * @description Generate a new CSRF token
878
+ * @param subject The subject of the token
879
+ * @returns A promise that resolves to the token
880
+ */
881
+ generate(subject: string): Promise<string>;
882
+ /**
883
+ * @description Validate a CSRF token
884
+ * @param token The token to validate
885
+ * @param subject The subject of the token
886
+ * @returns A priomise that resolves to true if the token is valid, false otherwise
887
+ */
888
+ validate(token: string, subject: string): Promise<boolean>;
889
+ }
890
+
782
891
  interface ISsrCookie {
783
892
  name: string;
784
893
  value: string;
@@ -1160,7 +1269,7 @@ interface MiddlewareConfig {
1160
1269
  * @since 2025-09-30
1161
1270
  * @link https://github.com/xeno-js/xeno-js
1162
1271
  */
1163
- csrf: Optional<string>;
1272
+ csrf: Optional<CsrfConfig>;
1164
1273
  /**
1165
1274
  * @description
1166
1275
  * The cors property is an optional property that can be used to configure Cross-Origin Resource Sharing (CORS) for the application. CORS is a mechanism that allows resources on a web page to be requested from another domain outside the domain from which the resource originated. The cors property is an object that contains properties to configure CORS, such as allowedOrigins, allowedMethods, allowedHeaders, and exposedHeaders.
@@ -1191,6 +1300,16 @@ interface MiddlewareConfig {
1191
1300
  * @link https://github.com/xeno-js/xeno-js
1192
1301
  */
1193
1302
  trustedIpHeader: Optional<string>;
1303
+ /**
1304
+ * @description
1305
+ * The trustedProxies property is an optional property that can be used to configure the trusted proxies for the application. It is an array of strings that specifies the IP addresses or hostnames of the proxies that are trusted by the application. This property is used to determine the trusted IP address of the client making the request and can be useful for security and authentication purposes.
1306
+ *
1307
+ * @author Xeno
1308
+ * @version 1.0.0
1309
+ * @since 2025-09-30
1310
+ * @link https://github.com/xeno-js/xeno-js
1311
+ */
1312
+ trustedProxies: Optional<string[]>;
1194
1313
  /**
1195
1314
  * @description
1196
1315
  * The allowOrigins property is an optional property that can be used to configure the allowed origins for the application. It is an array of strings that specifies the origins that are allowed to make requests to the application. This property is used to implement Cross-Origin Resource Sharing (CORS) and restrict access to the application based on the origin of the request.
@@ -1212,6 +1331,36 @@ interface MiddlewareConfig {
1212
1331
  */
1213
1332
  cors: boolean;
1214
1333
  }
1334
+ /**
1335
+ * @description
1336
+ * The csrf property is an object that contains configuration options for the CSRF middleware. The csrf property is used to configure the CSRF middleware that is responsible for handling CSRF requests and responses.
1337
+ */
1338
+ interface CsrfConfig {
1339
+ /**
1340
+ * Secret used to sign CSRF tokens.
1341
+ */
1342
+ secret: string;
1343
+ /**
1344
+ * @description the name of the cookie that will be used to store the CSRF token.
1345
+ */
1346
+ cookieName: Optional<string>;
1347
+ /**
1348
+ * @description the name of the header that will be used to send the CSRF token.
1349
+ */
1350
+ headerName: Optional<string>;
1351
+ /**
1352
+ * @description the number of seconds that the CSRF token will be valid for.
1353
+ */
1354
+ cookieMaxAgeSeconds: Optional<number>;
1355
+ /**
1356
+ * Cookie SameSite policy.
1357
+ */
1358
+ sameSite?: 'strict' | 'lax' | 'none';
1359
+ /**
1360
+ * Enforce Origin/Referer validation for unsafe requests.
1361
+ */
1362
+ enforceOrigin?: boolean;
1363
+ }
1215
1364
 
1216
1365
  /**
1217
1366
  * @description PipelineConfig defines the configuration options for the CQRS pipelines in the application. It includes settings for performance monitoring, authorization, validation, command bus, and query bus. Each section allows for enabling or disabling specific features and providing additional configuration details as needed. This configuration is used by the CqrsModule to set up the appropriate middleware and services in the dependency injection container based on the specified options.
@@ -1968,4 +2117,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
1968
2117
  protected getContext(): Optional<RequestContext>;
1969
2118
  }
1970
2119
 
1971
- export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHandler, ContainerUtils, type DbContext, type DbTransaction, type ExecutionContext, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, type IModule, type IRequestContext, type IServiceContainer, type IServiceProvider, type IServiceScope, type IServiceScopeAccessor, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, SupabaseServerAuthFactory, type XenoRegistry };
2120
+ export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHandler, ContainerUtils, type DbContext, type DbTransaction, type ExecutionContext, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, type IAtomicCache, type ICryptoService, type ICsrfTokenService, type IIPResolver, type IModule, type IRequestContext, type IServiceContainer, type IServiceProvider, type IServiceScope, type IServiceScopeAccessor, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, SupabaseServerAuthFactory, type XenoRegistry };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { IPipelineBehavior, IRequest, IExtendendService, IBaseAuthService, IServiceExtractor, HttpHeaders, Optional, ICache, ICacheKeyBuilder, IBaseMapper, AuthClaims, Identity, ICommand, IQuery, IConcurrencyService, IConfigurationService, ILoggerClient, IGateKeeper, IIdempotencyStore, ILogger, IMediator, IMiddleware, IStrategy, IPolicyRegistry, HttpMethod, RequestContext, IServiceResilience, Metadata, IFactory, ITransactionState, IUnitOfWork, IDisposable, IValidatorService, IIdentityAccessor, IContextAccessor, INetworkContextAccessor, UserContext, Factory, IBaseAccessor, AuthConfig, CookieOptions, SetupAction, HttpClientConfig, LogLevel, Dictionary, AuthPolicy, ResponseDto, IHandler, ResultType, ISpecification, CacheConfig, DbConfig, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, AppError } from '@xeno-js/shared';
1
+ import { ICache, Optional, IPipelineBehavior, IRequest, IExtendendService, IBaseAuthService, IServiceExtractor, HttpHeaders, ICacheKeyBuilder, IBaseMapper, AuthClaims, Identity, ICommand, IQuery, IConcurrencyService, IConfigurationService, ILoggerClient, IGateKeeper, IIdempotencyStore, ILogger, IMediator, IMiddleware, IStrategy, IPolicyRegistry, HttpMethod, RequestContext, IServiceResilience, Metadata, IFactory, ITransactionState, IUnitOfWork, IDisposable, IValidatorService, IIdentityAccessor, IContextAccessor, INetworkContextAccessor, UserContext, Factory, IBaseAccessor, AuthConfig, CookieOptions, SetupAction, HttpClientConfig, LogLevel, Dictionary, AuthPolicy, ResponseDto, IHandler, ResultType, ISpecification, CacheConfig, DbConfig, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, AppError } from '@xeno-js/shared';
2
2
  export * from '@xeno-js/shared';
3
3
  export { Query as BaseQuery } from '@xeno-js/shared';
4
4
  import { SupabaseClientOptions } from '@supabase/supabase-js';
@@ -8,6 +8,21 @@ import { NodePgDatabase } from 'drizzle-orm/node-postgres';
8
8
  export * from 'drizzle-orm';
9
9
  export { Query } from 'drizzle-orm';
10
10
 
11
+ /**
12
+ * @description IAtomicCache is an interface that extends the ICache interface and adds an increment method. The increment method takes a key and an optional ttlSeconds parameter and returns a Promise that resolves to an incremented value.
13
+ *
14
+ */
15
+ interface IAtomicCache extends ICache {
16
+ /**
17
+ * @description The increment method increments the value associated with the given key in the cache. If the key does not exist, it is created with an initial value of 1. The method returns a Promise that resolves to the incremented value.
18
+ *
19
+ * @param key The key to increment the value for.
20
+ * @param ttlSeconds The time-to-live (TTL) in seconds for the key-value pair. If not provided, the default TTL is used.
21
+ * @returns A Promise that resolves to the incremented value.
22
+ */
23
+ increment(key: string, ttlSeconds: Optional<number | string>): Promise<number>;
24
+ }
25
+
11
26
  /**
12
27
  * @description This file defines the injection tokens used for dependency injection in the application.
13
28
  * Injection tokens are unique identifiers that are used to register and resolve dependencies in the container.
@@ -53,7 +68,7 @@ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
53
68
  * @since 2025-09-30
54
69
  * @link https://github.com/xeno-js/xeno-js
55
70
  */
56
- readonly CACHE: ICache;
71
+ readonly CACHE: IAtomicCache;
57
72
  /** @description Token used to register and resolve the CacheKeyBuilder instance in the dependency injection container.
58
73
  *
59
74
  * @author Xeno
@@ -118,6 +133,33 @@ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
118
133
  * @link https://github.com/xeno-js/xeno-js
119
134
  */
120
135
  readonly CONSOLE_LOGGER: ILoggerClient;
136
+ /** @description Token used to register and resolve the CookieExtractor instance in the dependency injection container.
137
+ *
138
+ * @author Xeno
139
+ * @version 1.0.0
140
+ * @since 2025-09-30
141
+ * @link https://github.com/xeno-js/xeno-js
142
+ */
143
+ readonly COOKIE_EXTRACTOR: IServiceExtractor<{
144
+ header: Optional<string>;
145
+ name: string;
146
+ }, Optional<string>>;
147
+ /** @description Token used to register and resolve the CsrfTokenService instance in the dependency injection container.
148
+ *
149
+ * @author Xeno
150
+ * @version 1.0.0
151
+ * @since 2025-09-30
152
+ * @link https://github.com/xeno-js/xeno-js
153
+ */
154
+ readonly CSRF_TOKEN_SERVICE: ICsrfTokenService;
155
+ /** @description Token used to register and resolve the CryptoService instance in the dependency injection container.
156
+ *
157
+ * @author Xeno
158
+ * @version 1.0.0
159
+ * @since 2025-09-30
160
+ * @link https://github.com/xeno-js/xeno-js
161
+ */
162
+ readonly CRYPTO_SERVICE: ICryptoService;
121
163
  /** @description Token used to register and resolve the DbContext instance in the dependency injection container.
122
164
  *
123
165
  * @author Xeno
@@ -192,6 +234,7 @@ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
192
234
  readonly MIDDLEWARE: IMiddleware<HttpHeaders>;
193
235
  readonly AUTH_MIDDLEWARE: IMiddleware<HttpHeaders>;
194
236
  readonly CSRF_MIDDLEWARE: IMiddleware<HttpHeaders>;
237
+ readonly CSRF_COOKIE_MIDDLEWARE: IMiddleware<HttpHeaders>;
195
238
  readonly ALLOW_ORIGIN_MIDDLEWARE: IMiddleware<HttpHeaders>;
196
239
  readonly CORS_MIDDLEWARE: IMiddleware<HttpHeaders>;
197
240
  readonly METHOD_CHECK_MIDDLEWARE: IMiddleware<HttpHeaders>;
@@ -270,6 +313,14 @@ interface ApplicationRegistry<T = unknown, Ttx = unknown> {
270
313
  * @link https://github.com/xeno-js/xeno-js
271
314
  */
272
315
  readonly RESILIENCE_CLIENT: IServiceResilience;
316
+ /** @description Token used to register and resolve the IIPResolver instance in the dependency injection container.
317
+ *
318
+ * @author Xeno
319
+ * @version 1.0.0
320
+ * @since 2025-09-30
321
+ * @link https://github.com/xeno-js/xeno-js
322
+ */
323
+ readonly IP_RESOLVER: IIPResolver;
273
324
  /** @description Token used to register and resolve the RoleAuthorizationPipeline instance in the dependency injection container.
274
325
  *
275
326
  * @author Xeno
@@ -709,6 +760,32 @@ interface IServiceScopeAccessor<TRegistry extends ApplicationRegistry<unknown> =
709
760
  getScope(): Optional<IServiceScope<TRegistry>>;
710
761
  }
711
762
 
763
+ /**
764
+ * @description Interface for the crypto service
765
+ */
766
+ interface ICryptoService {
767
+ /**
768
+ * @description Generates a random byte array of the specified size.
769
+ * @param size The size of the byte array to generate.
770
+ * @returns A random byte array of the specified size.
771
+ */
772
+ randomBytes(size: number): Uint8Array;
773
+ /**
774
+ * @description Generates a HMAC SHA-256 hash of the specified data using the specified secret.
775
+ * @param secret The secret to use for the HMAC SHA-256 hash.
776
+ * @param data The data to hash.
777
+ * @returns A promise that resolves to the HMAC SHA-256 hash of the specified data.
778
+ */
779
+ hmacSha256(secret: string, data: string): Promise<string>;
780
+ /**
781
+ * @description Compares two byte arrays in a way that is resistant to timing attacks.
782
+ * @param a The first byte array to compare.
783
+ * @param b The second byte array to compare.
784
+ * @returns True if the two byte arrays are equal, false otherwise.
785
+ */
786
+ timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
787
+ }
788
+
712
789
  /**
713
790
  * @description Represents a module that can be registered with the service container.
714
791
  *
@@ -736,6 +813,19 @@ interface IModule<TRegistry extends ApplicationRegistry<unknown> = ApplicationRe
736
813
  configure(container: IServiceContainer<TRegistry>, opts?: Optional<TOptions>): Promise<void>;
737
814
  }
738
815
 
816
+ /**
817
+ * @description IIPResolver is a generic interface that defines a contract for resolving IP addresses.
818
+ */
819
+ interface IIPResolver {
820
+ /**
821
+ * @description Resolves a optional string based on the input of type T.
822
+ * @param request The input of type T.
823
+ * @param ip The optional IP address of the client.
824
+ * @returns The resolved optional string.
825
+ */
826
+ resolve<T>(request: T, ip: Optional<string>): Optional<string>;
827
+ }
828
+
739
829
  /**
740
830
  * @description Interface for the allow method service.
741
831
  *
@@ -779,6 +869,25 @@ interface IAllowOrigin {
779
869
  isAllowed(origin: Optional<string>): boolean;
780
870
  }
781
871
 
872
+ /**
873
+ * @description Interface for the CSRF token service
874
+ */
875
+ interface ICsrfTokenService {
876
+ /**
877
+ * @description Generate a new CSRF token
878
+ * @param subject The subject of the token
879
+ * @returns A promise that resolves to the token
880
+ */
881
+ generate(subject: string): Promise<string>;
882
+ /**
883
+ * @description Validate a CSRF token
884
+ * @param token The token to validate
885
+ * @param subject The subject of the token
886
+ * @returns A priomise that resolves to true if the token is valid, false otherwise
887
+ */
888
+ validate(token: string, subject: string): Promise<boolean>;
889
+ }
890
+
782
891
  interface ISsrCookie {
783
892
  name: string;
784
893
  value: string;
@@ -1160,7 +1269,7 @@ interface MiddlewareConfig {
1160
1269
  * @since 2025-09-30
1161
1270
  * @link https://github.com/xeno-js/xeno-js
1162
1271
  */
1163
- csrf: Optional<string>;
1272
+ csrf: Optional<CsrfConfig>;
1164
1273
  /**
1165
1274
  * @description
1166
1275
  * The cors property is an optional property that can be used to configure Cross-Origin Resource Sharing (CORS) for the application. CORS is a mechanism that allows resources on a web page to be requested from another domain outside the domain from which the resource originated. The cors property is an object that contains properties to configure CORS, such as allowedOrigins, allowedMethods, allowedHeaders, and exposedHeaders.
@@ -1191,6 +1300,16 @@ interface MiddlewareConfig {
1191
1300
  * @link https://github.com/xeno-js/xeno-js
1192
1301
  */
1193
1302
  trustedIpHeader: Optional<string>;
1303
+ /**
1304
+ * @description
1305
+ * The trustedProxies property is an optional property that can be used to configure the trusted proxies for the application. It is an array of strings that specifies the IP addresses or hostnames of the proxies that are trusted by the application. This property is used to determine the trusted IP address of the client making the request and can be useful for security and authentication purposes.
1306
+ *
1307
+ * @author Xeno
1308
+ * @version 1.0.0
1309
+ * @since 2025-09-30
1310
+ * @link https://github.com/xeno-js/xeno-js
1311
+ */
1312
+ trustedProxies: Optional<string[]>;
1194
1313
  /**
1195
1314
  * @description
1196
1315
  * The allowOrigins property is an optional property that can be used to configure the allowed origins for the application. It is an array of strings that specifies the origins that are allowed to make requests to the application. This property is used to implement Cross-Origin Resource Sharing (CORS) and restrict access to the application based on the origin of the request.
@@ -1212,6 +1331,36 @@ interface MiddlewareConfig {
1212
1331
  */
1213
1332
  cors: boolean;
1214
1333
  }
1334
+ /**
1335
+ * @description
1336
+ * The csrf property is an object that contains configuration options for the CSRF middleware. The csrf property is used to configure the CSRF middleware that is responsible for handling CSRF requests and responses.
1337
+ */
1338
+ interface CsrfConfig {
1339
+ /**
1340
+ * Secret used to sign CSRF tokens.
1341
+ */
1342
+ secret: string;
1343
+ /**
1344
+ * @description the name of the cookie that will be used to store the CSRF token.
1345
+ */
1346
+ cookieName: Optional<string>;
1347
+ /**
1348
+ * @description the name of the header that will be used to send the CSRF token.
1349
+ */
1350
+ headerName: Optional<string>;
1351
+ /**
1352
+ * @description the number of seconds that the CSRF token will be valid for.
1353
+ */
1354
+ cookieMaxAgeSeconds: Optional<number>;
1355
+ /**
1356
+ * Cookie SameSite policy.
1357
+ */
1358
+ sameSite?: 'strict' | 'lax' | 'none';
1359
+ /**
1360
+ * Enforce Origin/Referer validation for unsafe requests.
1361
+ */
1362
+ enforceOrigin?: boolean;
1363
+ }
1215
1364
 
1216
1365
  /**
1217
1366
  * @description PipelineConfig defines the configuration options for the CQRS pipelines in the application. It includes settings for performance monitoring, authorization, validation, command bus, and query bus. Each section allows for enabling or disabling specific features and providing additional configuration details as needed. This configuration is used by the CqrsModule to set up the appropriate middleware and services in the dependency injection container based on the specified options.
@@ -1968,4 +2117,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
1968
2117
  protected getContext(): Optional<RequestContext>;
1969
2118
  }
1970
2119
 
1971
- export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHandler, ContainerUtils, type DbContext, type DbTransaction, type ExecutionContext, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, type IModule, type IRequestContext, type IServiceContainer, type IServiceProvider, type IServiceScope, type IServiceScopeAccessor, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, SupabaseServerAuthFactory, type XenoRegistry };
2120
+ export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHandler, ContainerUtils, type DbContext, type DbTransaction, type ExecutionContext, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, type IAtomicCache, type ICryptoService, type ICsrfTokenService, type IIPResolver, type IModule, type IRequestContext, type IServiceContainer, type IServiceProvider, type IServiceScope, type IServiceScopeAccessor, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, SupabaseServerAuthFactory, type XenoRegistry };