@xeno-js/core 3.0.5 → 4.0.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,1599 +1,158 @@
1
- import { ICache, Optional, IExtendendAuthService, IBaseAuthService, ICacheKeyBuilder, IPipelineBehavior, ICommand, IConcurrencyService, IConfigurationService, ILogger, IMediator, IMiddleware, IQuery, RequestContext, IServiceResilience, IServiceExtractor, Metadata, IUnitOfWork, IDisposable, IValidatorService, IIdentityAccessor, IContextAccessor, INetworkContextAccessor, IFactory, UserContext, ITransactionState, Factory, IBaseAccessor, Identity, ExtendedRequest, HttpMethod, AuthConfig, CookieOptions, SetupAction, HttpClientConfig, LogLevel, ILoggerClient, Dictionary, AuthPolicy, IStrategy, IRequest, ResponseDto, ResultType, ISpecification, Nullable, CacheConfig, IReadDao, IReadDataSource, IMapper, IRepository, IWriteDataSource, IController, AppError } from '@xeno-js/shared';
1
+ import { IRequest, IHandler, IFactory, UserContext, Optional, ResultType, ICommand, RequestType, IStrategy, 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';
2
2
  export * from '@xeno-js/shared';
3
- export { Query } from '@xeno-js/shared';
4
3
 
5
4
  /**
6
- * @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.
5
+ * BaseHandler is an abstract class that implements the IHandler interface.
6
+ * It provides a base implementation for handling requests and executing strategies.
7
7
  *
8
- */
9
- interface IAtomicCache extends ICache {
10
- /**
11
- * @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.
12
- *
13
- * @param key The key to increment the value for.
14
- * @param ttlSeconds The time-to-live (TTL) in seconds for the key-value pair. If not provided, the default TTL is used.
15
- * @returns A Promise that resolves to the incremented value.
16
- */
17
- increment(key: string, ttlSeconds: Optional<number | string>): Promise<number>;
18
- }
19
-
20
- /**
21
- * @description An interface that defines the contract for a rate limit key builder in a Xeno Vue application. This interface requires the implementation of a single method, buildRateLimitKey, which takes a resource and a client IP address as parameters and returns a string representing the rate limit key.
22
- *
23
- * @author Xeno
24
- * @version 1.0.0
25
- * @since 2025-09-30
26
- * @link https://github.com/xeno-js/xeno-vue
27
- * @copyright Xeno
28
- * @license MIT
29
- */
30
- interface IRateLimitKeyBuilder {
31
- /**
32
- * Builds a rate limit key based on the provided resource and client IP address
33
- * @param resource the resource to limit
34
- * @param clientIp the client IP address
35
- */
36
- buildRateLimitKey(resource: string): Optional<string>;
37
- }
38
-
39
- /**
40
- * @description This file defines the injection tokens used for dependency injection in the application.
41
- * Injection tokens are unique identifiers that are used to register and resolve dependencies in the container.
42
- * They can be symbols, strings, or classes, but using symbols is a common practice to avoid naming collisions.
43
- *
44
- * @author Xeno
45
- * @version 1.0.0
46
- * @since 2025-09-30
47
- * @link https://github.com/xeno-js/xeno-js
48
- */
49
- interface ApplicationRegistry<T = unknown, Ttx = unknown> {
50
- /** @description Token used to register and resolve the Extended AuthService instance in the dependency injection container.
51
- *
52
- * @author Xeno
53
- * @version 1.0.0
54
- * @since 2025-09-30
55
- * @link https://github.com/xeno-js/xeno-js
56
- */
57
- readonly AUTH_SERVICE: IExtendendAuthService;
58
- /** @description Token used to register and resolve the BaseAuthService instance in the dependency injection container.
59
- *
60
- * @author Xeno
61
- * @version 1.0.0
62
- * @since 2025-09-30
63
- * @link https://github.com/xeno-js/xeno-js
64
- */
65
- readonly BASE_AUTH_SERVICE: IBaseAuthService;
66
- /** @description Token used to register and resolve the InMemoryCache instance in the dependency injection container.
67
- *
68
- * @author Xeno
69
- * @version 1.0.0
70
- * @since 2025-09-30
71
- * @link https://github.com/xeno-js/xeno-js
72
- */
73
- readonly CACHE: IAtomicCache;
74
- /** @description Token used to register and resolve the CacheKeyBuilder instance in the dependency injection container.
75
- *
76
- * @author Xeno
77
- * @version 1.0.0
78
- * @since 2025-09-30
79
- * @link https://github.com/xeno-js/xeno-js
80
- */
81
- readonly CACHE_KEY_BUILDER: ICacheKeyBuilder;
82
- /** @description Token used to register and resolve the CommandPipeline behaviors in the dependency injection container.
83
- *
84
- * @author Xeno
85
- * @version 1.0.0
86
- * @since 2025-09-30
87
- * @link https://github.com/xeno-js/xeno-js
88
- */
89
- readonly COMMAND_PIPELINES_BEHAVIOR: IPipelineBehavior<ICommand, unknown>;
90
- /** @description Token used to register and resolve the ConcurrencyService instance in the dependency injection container.
91
- *
92
- * @author Xeno
93
- * @version 1.0.0
94
- * @since 2025-09-30
95
- * @link https://github.com/xeno-js/xeno-js
96
- */
97
- readonly CONCURRENCY_SERVICE: IConcurrencyService;
98
- /** @description Token used to register and resolve the ConfigurationService instance in the dependency injection container.
99
- *
100
- * @author Xeno
101
- * @version 1.0.0
102
- * @since 2025-09-30
103
- * @link https://github.com/xeno-js/xeno-js
104
- */
105
- readonly CONFIGURATION_SERVICE: IConfigurationService;
106
- /** @description Token used to register and resolve the CsrfTokenService instance in the dependency injection container.
107
- *
108
- * @author Xeno
109
- * @version 1.0.0
110
- * @since 2025-09-30
111
- * @link https://github.com/xeno-js/xeno-js
112
- */
113
- readonly CSRF_TOKEN_SERVICE: ICsrfTokenService;
114
- /** @description Token used to register and resolve the CryptoService instance in the dependency injection container.
115
- *
116
- * @author Xeno
117
- * @version 1.0.0
118
- * @since 2025-09-30
119
- * @link https://github.com/xeno-js/xeno-js
120
- */
121
- readonly CRYPTO_SERVICE: ICryptoService;
122
- /** @description Token used to register and resolve the DbContext instance in the dependency injection container.
123
- *
124
- * @author Xeno
125
- * @version 1.0.0
126
- * @since 2025-09-30
127
- * @link https://github.com/xeno-js/xeno-js
128
- */
129
- readonly DB_CONTEXT: T;
130
- /** @description Token used to register and resolve the HTTP Adapter instance in the dependency injection container.
131
- *
132
- * @author Xeno
133
- * @version 1.2.1
134
- * @since 2025-09-30
135
- * @link https://github.com/xeno-js/xeno-js
136
- */
137
- readonly HTTP_ADAPTER: IHttpAdapter<unknown, unknown>;
138
- /** @description Token used to register and resolve the Logger instance in the dependency injection container.
139
- *
140
- * @author Xeno
141
- * @version 1.0.0
142
- * @since 2025-09-30
143
- * @link https://github.com/xeno-js/xeno-js
144
- */
145
- readonly LOGGER: ILogger;
146
- /** @description Token used to register and resolve the Mediator instance in the dependency injection container.
147
- *
148
- * @author Xeno
149
- * @version 1.0.0
150
- * @since 2025-09-30
151
- * @link https://github.com/xeno-js/xeno-js
152
- */
153
- readonly MEDIATOR: IMediator;
154
- /** @description Token used to register and resolve the RequestContextMiddleware in the dependency injection container.
155
- *
156
- * @author Xeno
157
- * @version 1.0.0
158
- * @since 2025-09-30
159
- * @link https://github.com/xeno-js/xeno-js
160
- */
161
- readonly MIDDLEWARE: IMiddleware;
162
- /** @description Token used to register and resolve the QueryPipeline behaviors in the dependency injection container.
163
- *
164
- * @author Xeno
165
- * @version 1.0.0
166
- * @since 2025-09-30
167
- * @link https://github.com/xeno-js/xeno-js
168
- */
169
- readonly QUERY_PIPELINES_BEHAVIOR: IPipelineBehavior<IQuery, unknown>;
170
- /** @description Token used to register and resolve the RequestContext instance in the dependency injection container.
171
- *
172
- * @author Xeno
173
- * @version 1.0.0
174
- * @since 2025-09-30
175
- * @link https://github.com/xeno-js/xeno-js
176
- */
177
- readonly REQUEST_CONTEXT: IRequestContext<RequestContext, ApplicationRegistry<T>>;
178
- /** @description Token used to register and resolve the IServiceResilience instance in the dependency injection container.
179
- *
180
- * @author Xeno
181
- * @version 1.0.0
182
- * @since 2025-09-30
183
- * @link https://github.com/xeno-js/xeno-js
184
- */
185
- readonly RESILIENCE_CLIENT: IServiceResilience;
186
- /** @description Token used to register and resolve the ServiceContainer instance in the dependency injection container.
187
- *
188
- * @author Xeno
189
- * @version 1.0.0
190
- * @since 2025-09-30
191
- * @link https://github.com/xeno-js/xeno-js
192
- */
193
- readonly SERVICE_CONTAINER: IServiceContainer;
194
- /** @description Token used to register and resolve the ServiceExtractor instance in the dependency injection container.
195
- *
196
- * @author Xeno
197
- * @version 1.0.0
198
- * @since 2025-09-30
199
- * @link https://github.com/xeno-js/xeno-js
200
- */
201
- readonly SERVICE_EXTRACTOR: IServiceExtractor<Request['headers'], Metadata>;
202
- /** @description Token used to register and resolve the UnitOfWork instance in the dependency injection container.
203
- *
204
- * @author Xeno
205
- * @version 1.0.0
206
- * @since 2025-09-30
207
- * @link https://github.com/xeno-js/xeno-js
208
- */
209
- readonly UNIT_OF_WORK: IUnitOfWork & IDisposable;
210
- /** @description Token used to register and resolve the ZodValidator instance in the dependency injection container.
211
- *
212
- * @author Xeno
213
- * @version 1.0.0
214
- * @since 2025-09-30
215
- * @link https://github.com/xeno-js/xeno-js
216
- */
217
- readonly VALIDATOR_SERVICE: IValidatorService;
218
- /** @description Token used to register and resolve the IIdentityAccessor in the dependency injection container, allowing access only to current user identity information.
219
- *
220
- * @author Xeno
221
- * @version 1.0.0
222
- * @since 2025-09-30
223
- * @link https://github.com/xeno-js/xeno-js
224
- */
225
- readonly IDENTITY_ACCESSOR: IIdentityAccessor;
226
- /** @description Token used to register and resolve the IServiceScopeAccessor in the dependency injection container, granting controlled access to the current request scope.
227
- *
228
- * @author Xeno
229
- * @version 1.0.0
230
- * @since 2025-09-30
231
- * @link https://github.com/xeno-js/xeno-js
232
- */
233
- readonly SERVICE_SCOPE_ACCESSOR: IServiceScopeAccessor<ApplicationRegistry<T>>;
234
- /** @description Token used to register and resolve the IContextAccessor instance in the dependency injection container to fetch execution context properties.
235
- *
236
- * @author Xeno
237
- * @version 1.0.0
238
- * @since 2025-09-30
239
- * @link https://github.com/xeno-js/xeno-js
240
- */
241
- readonly CONTEXT_ACCESSOR: IContextAccessor<RequestContext>;
242
- /** @description Token used to register and resolve the INetworkContextAccessor instance in the dependency injection container to fetch networking/observability context data.
243
- *
244
- * @author Xeno
245
- * @version 1.0.0
246
- * @since 2025-09-30
247
- * @link https://github.com/xeno-js/xeno-js
248
- */
249
- readonly NETWORK_CONTEXT_ACCESSOR: INetworkContextAccessor;
250
- /** @description Token used to register and resolve the UserContext factory in the dependency injection container.
251
- *
252
- * @author Xeno
253
- * @version 1.0.0
254
- * @since 2025-09-30
255
- * @link https://github.com/xeno-js/xeno-js
256
- */
257
- readonly USER_CONTEXT_FACTORY: IFactory<void, UserContext>;
258
- /** @description Token used to register and resolve the TransactionState instance in the dependency injection container.
259
- *
260
- * @author Xeno
261
- * @version 1.0.0
262
- * @since 2025-09-30
263
- * @link https://github.com/xeno-js/xeno-js
264
- */
265
- readonly TRANSACTION_STATE: ITransactionState<Ttx>;
266
- }
267
-
268
- /**
269
- * @fileoverview Defines the IServiceScope interface for scoped dependency injection.
270
- *
271
- * @author Xeno
272
- * @version 1.0.0
273
- * @since 2025-09-30
274
- * @link https://github.com/xeno-js/xeno-js
275
- */
276
- /**
277
- * @description Represents a logical scope for resolving scoped services,
278
- * mimicking the .NET `IServiceScope` pattern.
279
- *
280
- * A scope is created by {@link IServiceContainer.createScope} and provides
281
- * its own isolated instance cache for services registered with scoped lifetime.
282
- * Singleton and transient services are still resolved through the root container.
283
- *
284
- * Call {@link dispose} when the scope is no longer needed to release all
285
- * scoped instances and invalidate the scope.
286
- *
287
- * @author Xeno
288
- * @version 1.0.0
289
- * @since 2025-09-30
290
- * @link https://github.com/xeno-js/xeno-js
291
- */
292
- interface IServiceScope<Registry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> extends IDisposable {
293
- /**
294
- * Resolves and returns the service registered under the given token.
295
- * Scoped services can only be resolved through a scope;
296
- * resolving them directly from the root container throws an error.
297
- *
298
- * @param token - The injection token identifying the service to resolve.
299
- * @returns The resolved service instance of type `T`.
300
- * @throws An error if no registration is found for the given token.
301
- * @throws An error if the scope has already been disposed.
302
- *
303
- * @author Xeno
304
- * @version 1.0.0
305
- * @since 2025-09-30
306
- * @link https://github.com/xeno-js/xeno-js
307
- */
308
- resolve<K extends keyof Registry>(token: K): Registry[K];
309
- }
310
-
311
- /**
312
- * @fileoverview Defines the IServiceContainer interface for a dependency injection container.
313
- *
314
- * @author Xeno
315
- * @version 1.0.0
316
- * @since 2025-09-30
317
- * @link https://github.com/xeno-js/xeno-js
318
- */
319
- interface IServiceProvider<Registry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> {
320
- /**
321
- * Resolves and returns the service registered under the given token.
322
- * Scoped services can only be resolved through a scope;
323
- * resolving them directly from the root container throws an error.
324
- *
325
- * @param token - The injection token identifying the service to resolve.
326
- * @returns The resolved service instance of type `T`.
327
- * @throws An error if no registration is found for the given token.
328
- * @throws An error if the scope has already been disposed.
329
- *
330
- * @author Xeno
331
- * @version 1.0.0
332
- * @since 2025-09-30
333
- * @link https://github.com/xeno-js/xeno-js
334
- */
335
- resolve<K extends keyof Registry>(token: K): Registry[K];
336
- }
337
- /**
338
- * @description Agnostic contract for a dependency injection container that mimics
339
- * the .NET ServiceCollection builder pattern.
340
- *
341
- * Each registration method returns `this` to enable a fluent builder chain.
342
- * Dependencies are expressed as an ordered array of injection tokens
343
- * that the container will resolve and inject into the constructor.
344
- *
345
- * @author Xeno
346
- * @version 1.0.0
347
- * @since 2025-09-30
348
- * @link https://github.com/xeno-js/xeno-js
349
- */
350
- interface IServiceContainer<Registry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> extends IServiceProvider<Registry>, IDisposable {
351
- /**
352
- * Registers an implementation under the given token with **singleton** lifetime.
353
- * A single instance is created on first resolution and reused for every
354
- * subsequent call within the container's lifetime.
355
- *
356
- * @param token - The unique injection token that identifies this service binding.
357
- * @param factory - Factory function that creates the service instance, receiving the scope as an argument.
358
- * @returns The container instance to allow method chaining.
359
- *
360
- * @author Xeno
361
- * @version 1.0.0
362
- * @since 2025-09-30
363
- * @link https://github.com/xeno-js/xeno-js
364
- */
365
- addSingleton<K extends keyof Registry>(token: K, factory: Factory<Registry[K], [IServiceScope<Registry>]>): this;
366
- /**
367
- * Registers an implementation under the given token with **transient** lifetime.
368
- * A new instance is created on every call to {@link resolve}.
369
- *
370
- * @param token - The unique injection token that identifies this service binding.
371
- * @param factory - Factory function that creates the service instance, receiving the scope as an argument.
372
- * @returns The container instance to allow method chaining.
373
- *
374
- * @author Xeno
375
- * @version 1.0.0
376
- * @since 2025-09-30
377
- * @link https://github.com/xeno-js/xeno-js
378
- */
379
- addTransient<K extends keyof Registry>(token: K, factory: Factory<Registry[K], [IServiceScope<Registry>]>): this;
380
- /**
381
- * Registers an implementation under the given token with **scoped** lifetime.
382
- * One instance is created per logical scope (e.g. per HTTP request).
383
- * Scoped services must be resolved through an {@link IServiceScope} obtained
384
- * via {@link createScope}; resolving them directly from the root container throws.
385
- *
386
- * @param token - The unique injection token that identifies this service binding.
387
- * @param factory - Factory function that creates the service instance, receiving the scope as an argument.
388
- * @returns The container instance to allow method chaining.
389
- *
390
- * @author Xeno
391
- * @version 1.0.0
392
- * @since 2025-09-30
393
- * @link https://github.com/xeno-js/xeno-js
394
- */
395
- addScoped<K extends keyof Registry>(token: K, factory: Factory<Registry[K], [IServiceScope<Registry>]>): this;
396
- /**
397
- * Creates a new {@link IServiceScope}.
398
- *
399
- * The returned scope shares singleton instances with the root container
400
- * and maintains its own isolated cache for scoped services.
401
- * Call {@link IServiceScope.dispose} when the scope is no longer needed.
402
- *
403
- * @returns A new scope instance.
404
- *
405
- * @author Xeno
406
- * @version 1.0.0
407
- * @since 2025-09-30
408
- * @link https://github.com/xeno-js/xeno-js
409
- */
410
- createScope(): IServiceScope<Registry>;
411
- }
412
-
413
- /**
414
- * @fileoverview Defines the ServiceDescriptor type for service registrations.
415
-
416
- *
417
- * @author Xeno
418
- * @version 1.0.0
419
- * @since 2025-09-30
420
- * @link https://github.com/xeno-js/xeno-js
421
- */
422
- /**
423
- * @description The possible lifetimes for a service registration, determining
424
- * how instances are managed and cached by the container.
425
-
426
- *
427
- * @author Xeno
428
- * @version 1.0.0
429
- * @since 2025-09-30
430
- * @link https://github.com/xeno-js/xeno-js
431
- */
432
- type Lifetime = 'singleton' | 'transient' | 'scoped';
433
- /**
434
- * @description Describes a service registration in the container, including
435
- * the implementation constructor, its dependencies, and its lifetime.
436
-
437
- *
438
- * @author Xeno
439
- * @version 1.0.0
440
- * @since 2025-09-30
441
- * @link https://github.com/xeno-js/xeno-js
442
- */
443
- interface ServiceDescriptor<T, TRegistry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> {
444
- /**
445
- * @description The injection token that uniquely identifies this service registration.
446
-
447
- *
448
- * @author Xeno
449
- * @version 1.0.0
450
- * @since 2025-09-30
451
- * @link https://github.com/xeno-js/xeno-js
452
- */
453
- readonly token: keyof TRegistry;
454
- /**
455
- * @description The lifetime of the service, determining how instances are
456
- * managed and cached by the container.
457
-
458
- *
459
- * @author Xeno
460
- * @version 1.0.0
461
- * @since 2025-09-30
462
- * @link https://github.com/xeno-js/xeno-js
463
- */
464
- readonly lifetime: Lifetime;
465
- /**
466
- * @description Factory function to create the service instance.
467
- * This factory will be used instead of the constructor.
468
-
469
- *
470
- * @author Xeno
471
- * @version 1.0.0
472
- * @since 2025-09-30
473
- * @link https://github.com/xeno-js/xeno-js
474
- */
475
- readonly factory: (container: IServiceProvider<TRegistry>) => T;
476
- }
477
-
478
- /**
479
- * @description This file defines the types for the execution context used in the application. The execution context includes the request context, which contains information about the identity of the user or system executing the request, as well as network and tracing contexts for observability. Additionally, it includes a service scope for managing dependencies during the execution of a request.
480
- *
481
- * @author Xeno
482
- * @version 1.0.0
483
- * @since 2025-09-30
484
- * @link https://github.com/xeno-js/xeno-js
485
- */
486
-
487
- /**
488
- * The ExecutionContext interface represents the context of a request execution, encapsulating the request context and the service scope. The request context contains information about the identity of the user or system executing the request, as well as network and tracing contexts for observability. The service scope allows for managing dependencies during the execution of a request, ensuring that services are properly scoped and disposed of after the request is processed.
489
-
490
- *
491
- * @author Xeno
492
- * @version 1.0.0
493
- * @since 2025-09-30
494
- * @link https://github.com/xeno-js/xeno-js
495
- */
496
- interface ExecutionContext<TRegistry extends ApplicationRegistry = ApplicationRegistry> {
497
- /** The request context containing information about the identity, network, and tracing contexts for the current request execution.
498
- *
499
- * @author Xeno
500
- * @version 1.0.0
501
- * @since 2025-09-30
502
- * @link https://github.com/xeno-js/xeno-js
503
- */
504
- context: RequestContext;
505
- /** The service scope for managing dependencies during the execution of a request. This allows for proper scoping and disposal of services after the request is processed.
506
- *
507
- * @author Xeno
508
- * @version 1.0.0
509
- * @since 2025-09-30
510
- * @link https://github.com/xeno-js/xeno-js
511
- */
512
- scope: IServiceScope<TRegistry>;
513
- }
514
-
515
- /**
516
- * @fileoverview Defines the IRequestContext interface for managing user identity context within the application.
517
- *
518
- * @author Xeno
519
- * @version 1.0.0
520
- * @since 2025-09-30
521
- * @link https://github.com/xeno-js/xeno-js
522
- */
523
-
524
- /**
525
- * An interface for managing user identity context within the application. This interface provides methods for executing asynchronous functions with the current user's identity context and retrieving the current user's identity information. It allows for seamless integration of identity management into various parts of the application, ensuring that identity-related data is properly propagated and accessible when needed.
526
- *
527
- * @author Xeno
528
- * @version 1.0.0
529
- * @since 2025-09-30
530
- * @link https://github.com/xeno-js/xeno-js
531
- */
532
- interface IRequestContext<TCtx, TRegistry extends ApplicationRegistry = ApplicationRegistry> extends IBaseAccessor<TCtx>, IServiceScopeAccessor<TRegistry> {
533
- /**
534
- * Executes the provided asynchronous function with the current user's identity context. This allows the function to access identity information such as user ID, roles, and correlation ID while performing its operations. The function will be executed within the scope of the current request's identity, ensuring that any identity-related data is properly propagated throughout the execution flow.
535
- * @param ctx The current user's identity context.
536
- * @param fn An asynchronous function that takes the current user's identity as an argument and returns a promise of type T. This function will be executed with the identity context of the current request.
537
- * @returns A promise that resolves to the result of the provided function, allowing the caller to handle the outcome of the operation performed within the identity context.
538
- *
539
- * @author Xeno
540
- * @version 1.0.0
541
- * @since 2025-09-30
542
- * @link https://github.com/xeno-js/xeno-js
543
- */
544
- runAsync<T = unknown>(ctx: TCtx, fn: () => Promise<T>): Promise<T>;
545
- updateIdentity(identity: Identity): void;
546
- }
547
- /**
548
- * @description The IIdentityAccessor interface is a contract that defines the structure and behavior of an identity accessor within the application. It provides a method for retrieving the current user's identity information, including user ID, roles, and correlation ID. This interface is essential for managing user identity and ensuring that identity-related data is accessible when needed.
549
- *
550
- *
551
- * @author Xeno
552
- * @version 1.0.0
553
- * @since 2025-09-30
554
- * @link https://github.com/xeno-js/xeno-js
555
- */
556
- interface IServiceScopeAccessor<TRegistry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> {
557
- /**
558
- * Retrieves the current service scope, which allows for managing dependencies during the execution of a request. This method enables access to the service scope, ensuring that services are properly scoped and disposed of after the request is processed.
559
- * @returns An object representing the current service scope, allowing for resolution of dependencies and management of services during the execution of a request.
560
- *
561
- * @author Xeno
562
- * @version 1.0.0
563
- * @since 2025-09-30
564
- * @link https://github.com/xeno-js/xeno-js
565
- */
566
- getScope(): Optional<IServiceScope<TRegistry>>;
567
- }
568
-
569
- /**
570
- * @description Interface for the crypto service
571
- */
572
- interface ICryptoService {
573
- /**
574
- * @description Generates a random byte array of the specified size.
575
- * @param size The size of the byte array to generate.
576
- * @returns A random byte array of the specified size.
577
- */
578
- randomBytes(size: number): Uint8Array;
579
- /**
580
- * @description Generates a HMAC SHA-256 hash of the specified data using the specified secret.
581
- * @param secret The secret to use for the HMAC SHA-256 hash.
582
- * @param data The data to hash.
583
- * @returns A promise that resolves to the HMAC SHA-256 hash of the specified data.
584
- */
585
- hmacSha256(secret: string, data: string): Promise<string>;
586
- /**
587
- * @description Compares two byte arrays in a way that is resistant to timing attacks.
588
- * @param a The first byte array to compare.
589
- * @param b The second byte array to compare.
590
- * @returns True if the two byte arrays are equal, false otherwise.
591
- */
592
- timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean;
593
- }
594
-
595
- /**
596
- * @description Interface for a WebTransport.
597
- * @author Xeno
598
- * @version 1.2.1
599
- * @since 2025-09-30
600
- * @link https://github.com/xeno-js/xeno-js
601
- */
602
- interface XenoWebTransport {
603
- /**
604
- * @description The Extendend native request.
605
- * @type ExtendedRequest
606
- */
607
- request: ExtendedRequest;
608
- /**
609
- * @description The native response.
610
- * @type Response
611
- */
612
- response: Response;
613
- }
614
- /**
615
- * @description Interface for an HTTP adapter.
616
- * @author Xeno
617
- * @version 1.2.1
618
- * @since 2025-09-30
619
- * @link https://github.com/xeno-js/xeno-js
620
- */
621
- interface IHttpAdapter<TReq = Request, TRes = Response> {
622
- /**
623
- * @description Adapts an HTTP request and response to an ExtendedRequest and Response.
624
- * @param req - The HTTP request.
625
- * @param res - The HTTP response.
626
- * @returns An object containing the adapted ExtendedRequest and Response.
627
- */
628
- adapt(req: TReq, res: TRes): XenoWebTransport;
629
- }
630
-
631
- /**
632
- * @description Represents a module that can be registered with the service container.
633
- *
634
- * @template TOptions - The type of configuration options for the module.
635
-
636
- *
637
- * @author Xeno
638
- * @version 1.0.0
639
- * @since 2025-09-30
640
- * @link https://github.com/xeno-js/xeno-js
641
- */
642
- interface IModule<TRegistry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>, TOptions = unknown> {
643
- /**
644
- * @description Configures the module with the provided options.
645
- *
646
- * @param container - The service container to register services with.
647
- * @param opts - The configuration options for the module.
648
-
649
- *
650
- * @author Xeno
651
- * @version 1.0.0
652
- * @since 2025-09-30
653
- * @link https://github.com/xeno-js/xeno-js
654
- */
655
- configure(container: IServiceContainer<TRegistry>, opts?: Optional<TOptions>): Promise<void>;
656
- }
657
-
658
- /**
659
- * @description IIPResolver is a generic interface that defines a contract for resolving IP addresses.
660
- */
661
- interface IIPResolver {
662
- /**
663
- * @description Resolves a optional string based on the input of type T.
664
- * @param request The input of type T.
665
- * @param ip The optional IP address of the client.
666
- * @returns The resolved optional string.
667
- */
668
- resolve<T>(request: T, ip: Optional<string>): Optional<string>;
669
- }
670
-
671
- /**
672
- * @description Interface for the allow method service.
673
- *
674
- * @author Xeno
675
- * @version 1.0.0
676
- * @since 2025-09-30
677
- * @link https://github.com/xeno-js/xeno-js
678
- */
679
- interface IAllowMethod {
680
- /** @description Check if the given method is allowed for the given path.
681
- * @param path The path to check.
682
- * @param method The method to check.
683
- * @returns True if the method is allowed, false otherwise.
684
- *
685
- * @author Xeno
686
- * @version 1.0.0
687
- * @since 2025-09-30
688
- * @link https://github.com/xeno-js/xeno-js
689
- */
690
- check(path: string, method: HttpMethod): boolean;
691
- /**
692
- * @description Get the allowed methods for the given path.
693
- * @param path the path to get the allowed methods for.
694
- * @returns the allowed methods for the given path.
695
- * @author Xeno
696
- * @version 1.0.0
697
- * @since 2025-09-30
698
- * @link https://github.com/xeno-js/xeno-js
699
- */
700
- getMethods(path: string): string;
701
- }
702
-
703
- /**
704
- * @description Interface for the allow origin service.
705
- *
706
- * @author Xeno
707
- * @version 1.0.0
708
- * @since 2025-09-30
709
- * @link https://github.com/xeno-js/xeno-js
710
- */
711
- interface IAllowOrigin {
712
- /** @description Check if the given origin is allowed.
713
- * @param origin The origin to check.
714
- * @returns True if the origin is allowed, false otherwise.
715
- *
716
- * @author Xeno
717
- * @version 1.0.0
718
- * @since 2025-09-30
719
- * @link https://github.com/xeno-js/xeno-js
720
- */
721
- isAllowed(origin: Optional<string>): boolean;
722
- }
723
-
724
- /**
725
- * @description Interface for the CSRF token service
726
- */
727
- interface ICsrfTokenService {
728
- /**
729
- * @description Generate a new CSRF token
730
- * @param subject The subject of the token
731
- * @returns A promise that resolves to the token
732
- */
733
- generate(subject: string): Promise<string>;
734
- /**
735
- * @description Validate a CSRF token
736
- * @param token The token to validate
737
- * @param subject The subject of the token
738
- * @returns A priomise that resolves to true if the token is valid, false otherwise
739
- */
740
- validate(token: string, subject: string): Promise<boolean>;
741
- }
742
-
743
- interface ITransactionalDb<TTransaction = unknown> {
744
- transaction<T>(callback: (tx: TTransaction) => Promise<T>): Promise<T>;
745
- }
746
-
747
- interface ISsrCookie {
748
- name: string;
749
- value: string;
750
- }
751
- interface ISsrCookieToSet extends ISsrCookie {
752
- options?: CookieOptions;
753
- }
754
- interface ISsrCookieHandler {
755
- getAll(): ISsrCookie[];
756
- setAll(cookies: ISsrCookieToSet[]): void;
757
- }
758
- interface CookieHandlerOptions extends CookieOptions {
759
- httpOnly: boolean;
760
- }
761
- interface AuthSsrConfig<TOption = unknown, TRegistry extends ApplicationRegistry = ApplicationRegistry> extends AuthConfig<TOption> {
762
- ssrOpts: Optional<(container: IServiceContainer<TRegistry>) => ISsrCookieHandler>;
763
- cookieOpts: CookieHandlerOptions;
764
- customAuth: Optional<{
765
- authHeaderExtractor: () => IServiceExtractor<Request['headers'], Optional<string>>;
766
- authExtendedService: () => IExtendendAuthService;
767
- }>;
768
- }
769
-
770
- /**
771
- * @description Options for configuring the database module.
772
- * @author Xeno
773
- * @version 1.0.0
774
- * @since 2025-09-30
775
- * @link https://github.com/xeno-js/xeno-js
776
- */
777
- interface DbModuleOptions<TDb extends ITransactionalDb<Ttx>, Ttx = unknown> {
778
- /** The database client to use. */
779
- readonly client: TDb;
780
- }
781
-
782
- /**
783
- * @description This file defines the ResilienceConfig interface, which specifies the configuration options for implementing resilience features such as retries, circuit breakers, and bulkheads in service calls. The ResilienceConfig interface includes properties for configuring retry attempts, base delay, maximum delay, consecutive failures for circuit breakers, half-open timeout, and maximum concurrent operations for bulkheads. This configuration can be used to enhance the reliability of service interactions by automatically handling transient faults and preventing cascading failures in distributed systems.
784
-
785
- *
786
- * @author Xeno
787
- * @version 1.0.0
788
- * @since 2025-09-30
789
- * @link https://github.com/xeno-js/xeno-js
790
- */
791
- interface ResilienceConfig {
792
- /**
793
- * @description Configuration for retry mechanism, including the number of retry attempts, base delay in milliseconds for the first retry, and maximum delay in milliseconds for subsequent retries. This configuration allows for implementing an exponential backoff strategy to manage retries effectively and avoid overwhelming the service with rapid retry attempts.
794
-
795
- *
796
- * @author Xeno
797
- * @version 1.0.0
798
- * @since 2025-09-30
799
- * @link https://github.com/xeno-js/xeno-js
800
- */
801
- retry: {
802
- /** @description The number of retry attempts to be made before giving up on the operation. This helps to ensure that transient faults are handled gracefully without overwhelming the service with excessive retries.
803
- *
804
- * @author Xeno
805
- * @version 1.0.0
806
- * @since 2025-09-30
807
- * @link https://github.com/xeno-js/xeno-js
808
- */
809
- attempts: Optional<number>;
810
- /** @description The base delay in milliseconds for the first retry attempt. This value is used to calculate the delay for subsequent retries using an exponential backoff strategy, which helps to manage retries effectively and avoid overwhelming the service with rapid retry attempts.
811
- *
812
- * @author Xeno
813
- * @version 1.0.0
814
- * @since 2025-09-30
815
- * @link https://github.com/xeno-js/xeno-js
816
- */
817
- baseDelayMs: Optional<number>;
818
- /** @description The maximum delay in milliseconds for subsequent retry attempts. This value is used to cap the delay for retries when using an exponential backoff strategy, ensuring that the delay does not grow indefinitely and allowing for a reasonable retry strategy that balances between retrying too quickly and waiting too long.
819
- *
820
- * @author Xeno
821
- * @version 1.0.0
822
- * @since 2025-09-30
823
- * @link https://github.com/xeno-js/xeno-js
824
- */
825
- maxDelayMs: Optional<number>;
826
- };
827
- /**
828
- * @description Configuration for circuit breaker mechanism, including the number of consecutive failures required to trip the circuit breaker and the timeout duration in milliseconds for the half-open state. This configuration helps to prevent cascading failures by temporarily blocking calls to a service that is experiencing issues, allowing it time to recover before accepting new requests.
829
-
830
- *
831
- * @author Xeno
832
- * @version 1.0.0
833
- * @since 2025-09-30
834
- * @link https://github.com/xeno-js/xeno-js
835
- */
836
- circuitBreaker: {
837
- /** @description The number of consecutive failures required to trip the circuit breaker. When the number of consecutive failures reaches this threshold, the circuit breaker will open, preventing further calls to the service until it is allowed to half-open after a specified timeout. This helps to prevent cascading failures by temporarily blocking calls to a service that is experiencing issues, allowing it time to recover before accepting new requests.
838
- *
839
- * @author Xeno
840
- * @version 1.0.0
841
- * @since 2025-09-30
842
- * @link https://github.com/xeno-js/xeno-js
843
- */
844
- consecutiveFailures: Optional<number>;
845
- /** @description The timeout duration in milliseconds for the half-open state of the circuit breaker. After the circuit breaker has been tripped and is in the open state, it will transition to the half-open state after this timeout duration. In the half-open state, a limited number of calls will be allowed to test if the service has recovered. If the calls succeed, the circuit breaker will close and allow normal operation to resume. If the calls fail, the circuit breaker will open again, preventing further calls until the next timeout period. This configuration helps to manage the recovery process of a service that is experiencing issues and ensures that it can return to normal operation gracefully.
846
- *
847
- * @author Xeno
848
- * @version 1.0.0
849
- * @since 2025-09-30
850
- * @link https://github.com/xeno-js/xeno-js
851
- */
852
- halfOpenTimeoutMs: Optional<number>;
853
- };
854
- /**
855
- * @description Configuration for bulkhead mechanism, including the maximum number of concurrent operations allowed. This configuration helps to isolate failures and prevent resource exhaustion by limiting the number of concurrent calls to a service, ensuring that other parts of the system can continue to function even if one service is experiencing issues.
856
-
857
- *
858
- * @author Xeno
859
- * @version 1.0.0
860
- * @since 2025-09-30
861
- * @link https://github.com/xeno-js/xeno-js
862
- */
863
- bulkhead: {
864
- /** @description The maximum number of concurrent operations allowed. This helps to isolate failures and prevent resource exhaustion by limiting the number of concurrent calls to a service, ensuring that other parts of the system can continue to function even if one service is experiencing issues.
865
- *
866
- * @author Xeno
867
- * @version 1.0.0
868
- * @since 2025-09-30
869
- * @link https://github.com/xeno-js/xeno-js
870
- */
871
- maxConcurrent: Optional<number>;
872
- };
873
- }
874
-
875
- /**
876
- * @description HttpCoreConfig is an interface that defines the configuration options for the core HTTP functionality of the application. It includes two properties: 'http' of type HttpConfig, which specifies the configuration for the HTTP client, and 'resilience' of type ResilienceConfig, which provides the settings for implementing resilience strategies such as retries, circuit breakers, and timeouts. This interface allows for a centralized configuration of both HTTP and resilience features in the application.
877
- *
878
- * @author Xeno
879
- * @version 1.0.0
880
- * @since 2025-09-30
881
- * @link https://github.com/xeno-js/xeno-js
882
- */
883
- interface HttpCoreConfig<TRegistry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> {
884
- /** @description A unique token used for identifying the RemoteDataSource instance in the dependency injection container.
885
- *
886
- * @author Xeno
887
- * @version 1.0.0
888
- * @since 2025-09-30
889
- * @link https://github.com/xeno-js/xeno-js
890
- */
891
- dataSourceToken: SetupAction<IServiceContainer<TRegistry>>;
892
- /** @description The configuration options for the HTTP client, including default headers, base URL, and timeout settings.
893
- *
894
- * @author Xeno
895
- * @version 1.0.0
896
- * @since 2025-09-30
897
- * @link https://github.com/xeno-js/xeno-js
898
- */
899
- http: HttpConfig<TRegistry>;
900
- /** @description The configuration options for implementing resilience strategies, including retries, circuit breakers, and timeouts. This allows for enhancing the reliability of service interactions by automatically handling transient faults and preventing cascading failures in distributed systems.
901
- *
902
- * @author Xeno
903
- * @version 1.0.0
904
- * @since 2025-09-30
905
- * @link https://github.com/xeno-js/xeno-js
906
- */
907
- resilience: ResilienceConfig;
908
- }
909
- /**
910
- * @description HttpConfig is an interface that defines the configuration options for an HTTP client. It includes a required 'client' property of type HttpClientConfig, which specifies the default headers, base URL, and timeout for the HTTP client. Additionally, it has an optional 'resilience' property that indicates whether resilience features are enabled and provides the corresponding ResilienceConfig if they are.
911
- *
912
- * @author Xeno
913
- * @version 1.0.0
914
- * @since 2025-09-30
915
- * @link https://github.com/xeno-js/xeno-js
916
- */
917
- interface HttpConfig<TRegistry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>> {
918
- /** @description A unique token used for identifying the HTTP client configuration in the dependency injection container.
919
- *
920
- * @author Xeno
921
- * @version 1.0.0
922
- * @since 2025-09-30
923
- * @link https://github.com/xeno-js/xeno-js
924
- */
925
- token: keyof TRegistry;
926
- /** @description The configuration options for the HTTP client, including default headers, base URL, and timeout settings.
927
- *
928
- * @author Xeno
929
- * @version 1.0.0
930
- * @since 2025-09-30
931
- * @link https://github.com/xeno-js/xeno-js
932
- */
933
- client: HttpClientConfig;
934
- }
935
- /**
936
- * @description The configuration options for the HTTP client, including default headers, base URL, and timeout settings.
937
8
  * @author Xeno
938
- * @version 1.2.1
939
- * @since 2025-09-30
940
- * @link https://github.com/xeno-js/xeno-js
941
- */
942
- interface HttpAdapterConfig {
943
- /**
944
- * @description Boolean for Native node js adapter (default true).
945
- * @type boolean
946
- * @author Xeno
947
- * @version 1.2.1
948
- * @since 2025-09-30
949
- * @link https://github.com/xeno-js/xeno-js
950
- */
951
- native: boolean;
952
- /**
953
- * @description Boolean for Vercel adapter.
954
- * @type boolean
955
- * @author Xeno
956
- * @version 1.2.1
957
- * @since 2025-09-30
958
- * @link https://github.com/xeno-js/xeno-js
959
- */
960
- vercel: boolean;
961
- /**
962
- * @description Boolean for Fastify adapter.
963
- * @type boolean
964
- * @author Xeno
965
- * @version 1.2.1
966
- * @since 2025-09-30
967
- * @link https://github.com/xeno-js/xeno-js
968
- */
969
- fastify: boolean;
970
- /**
971
- * @description Optional function for custom adapter.
972
- * @type Optional<() => IHttpAdapter>
973
- * @author Xeno
974
- * @version 1.2.1
975
- * @since 2025-09-30
976
- * @link https://github.com/xeno-js/xeno-js
977
- */
978
- custom: Optional<() => IHttpAdapter>;
979
- }
980
-
981
- /**
982
- * @description Interface defining the structure of a logger configuration object. This includes properties such as the minimum log level that should be captured by the logger. The log level determines the severity of log messages that will be processed and forwarded to the logging clients, allowing developers to control the verbosity of logs based on the needs of the application and its operational context.
983
- *
984
- *
985
- * @author Xeno
986
- * @version 1.0.0
987
- * @since 2025-09-30
988
- * @link https://github.com/xeno-js/xeno-js
989
- */
990
- interface LoggerConfig<TRegistry extends ApplicationRegistry = ApplicationRegistry> {
991
- /**
992
- * @description
993
- * The level property specifies the minimum log level that should be captured by the logger. Log levels typically include DEBUG, INFO, WARN, and ERROR, with each level representing a different severity of log messages. By setting the log level, developers can control the verbosity of the logs and ensure that only relevant information is captured based on the needs of the application and its operational context.
994
-
995
- *
996
- * @author Xeno
997
- * @version 1.0.0
998
- * @since 2025-09-30
999
- * @link https://github.com/xeno-js/xeno-js
1000
- */
1001
- level: Optional<LogLevel>;
1002
- /** @description Flag to enable or disable console logging. If set to true, log messages will be output to the console. If set to false or not defined, console logging will be disabled, and log messages will not be output to the console.
1003
- *
1004
- * @author Xeno
1005
- * @version 1.0.0
1006
- * @since 2025-09-30
1007
- * @link https://github.com/xeno-js/xeno-js
1008
- */
1009
- console: boolean;
1010
- /** @description Optional configuration for Sentry logger integration. If provided and enabled, the application will use Sentry as a logging client to capture and report log messages to the Sentry service. The configuration includes specific details for Sentry integration, such as the Data Source Name (DSN) and environment, allowing for flexible and modular logging configuration in the application.
1011
- *
1012
- * @author Xeno
1013
- * @version 1.0.0
1014
- * @since 2025-09-30
1015
- * @link https://github.com/xeno-js/xeno-js
1016
- */
1017
- sentry: {
1018
- /** @description Optional configuration for Sentry logger integration, including details such as the Data Source Name (DSN) and environment. If provided, this configuration will be used to initialize the Sentry logger client for capturing and reporting log messages to the Sentry service. If not defined, default Sentry configuration settings will be used.
1019
- *
1020
- * @author Xeno
1021
- * @version 1.0.0
1022
- * @since 2025-09-30
1023
- * @link https://github.com/xeno-js/xeno-js
1024
- */
1025
- config: Optional<SentryLoggerConfig>;
1026
- };
1027
- /** @description Optional configuration for Pino logger integration. If provided and enabled, the application will use Pino as a logging client to capture and manage log messages. The configuration includes specific details for Pino integration, such as the destination for log output, allowing for flexible and modular logging configuration in the application.
1028
- *
1029
- * @author Xeno
1030
- * @version 1.0.0
1031
- * @since 2025-09-30
1032
- * @link https://github.com/xeno-js/xeno-js
1033
- */
1034
- pino: {
1035
- /** @description Optional configuration for Pino logger integration, including details such as the destination for log output. If provided, this configuration will be used to initialize the Pino logger client for capturing and managing log messages. If not defined, default Pino configuration settings will be used.
1036
- *
1037
- * @author Xeno
1038
- * @version 1.0.0
1039
- * @since 2025-09-30
1040
- * @link https://github.com/xeno-js/xeno-js
1041
- */
1042
- config: Optional<PinoLoggerConfig>;
1043
- };
1044
- /** @description Optional array of custom logger clients to be used in addition to the built-in console, Sentry, and Pino loggers. If provided, these custom loggers will be registered and used for capturing and managing log messages based on their respective configurations. If not defined or empty, only the enabled built-in loggers will be used.
1045
- *
1046
- * @author Xeno
1047
- * @version 1.0.0
1048
- * @since 2025-09-30
1049
- * @link https://github.com/xeno-js/xeno-js
1050
- */
1051
- customLoggers: Optional<(container: IServiceScope<TRegistry>) => ILoggerClient>[];
1052
- }
1053
- /**
1054
- * @description Interface defining the structure of the configuration object required to initialize a logger. This includes properties such as the Data Source Name (DSN) for connecting to the logging service, the environment in which the application is running (e.g., development, production), and the minimum log level that should be captured by the logger.
1055
-
1056
- *
1057
- * @author Xeno
1058
- * @version 1.0.0
1059
- * @since 2025-09-30
1060
- * @link https://github.com/xeno-js/xeno-js
1061
- */
1062
- interface SentryLoggerConfig {
1063
- /**
1064
- * @description
1065
- * The Data Source Name (DSN) is a string that provides the necessary information for the logger to connect to the logging service. It typically includes the protocol, public key, secret key, host, and project ID. The DSN is essential for authenticating and routing log data to the correct destination in the logging infrastructure.
1066
-
1067
- *
1068
- * @author Xeno
1069
- * @version 1.0.0
1070
- * @since 2025-09-30
1071
- * @link https://github.com/xeno-js/xeno-js
1072
- */
1073
- dsn: Optional<string>;
1074
- /**
1075
- * @description
1076
- * The environment property indicates the context in which the application is running, such as 'development', 'staging', or 'production'. This information can be used by the logging service to categorize and filter logs based on the environment, allowing for better organization and analysis of log data.
1077
-
1078
- *
1079
- * @author Xeno
1080
- * @version 1.0.0
1081
- * @since 2025-09-30
1082
- * @link https://github.com/xeno-js/xeno-js
1083
- */
1084
- environment: Optional<string>;
1085
- }
1086
- /**
1087
- * @description Interface defining the structure of the configuration object required to initialize a Pino logger. This includes properties such as the destination for log output, which can be a file path, a stream, or a logging service endpoint. By configuring the destination, developers can control where the log data is stored or sent, enabling integration with various logging infrastructures and facilitating log management and analysis.
1088
-
1089
- *
1090
- * @author Xeno
1091
- * @version 1.0.0
1092
- * @since 2025-09-30
1093
- * @link https://github.com/xeno-js/xeno-js
1094
- */
1095
- interface PinoLoggerConfig {
1096
- /**
1097
- * @description
1098
- * The destination property specifies the output destination for the logs generated by the Pino logger. This can be a file path, a stream, or a logging service endpoint. By configuring the destination, developers can control where the log data is stored or sent, enabling integration with various logging infrastructures and facilitating log management and analysis.
1099
-
1100
- *
1101
- * @author Xeno
1102
- * @version 1.0.0
1103
- * @since 2025-09-30
1104
- * @link https://github.com/xeno-js/xeno-js
1105
- */
1106
- destination?: Optional<Destination>;
1107
- /** @description Optional environment name for the Pino logger configuration. This can be used to specify the context in which the application is running (e.g., development, production) and can help with categorizing and filtering log messages based on the environment.
1108
- *
1109
- * @author Xeno
1110
- * @version 1.0.0
1111
- * @since 2025-09-30
1112
- * @link https://github.com/xeno-js/xeno-js
1113
- */
1114
- env?: Optional<string>;
1115
- /** @description Optional file path for the Pino logger configuration. If specified, log messages will be written to the specified file instead of the default output destination. This allows for flexible log management and storage based on application requirements.
1116
- *
1117
- * @author Xeno
1118
- * @version 1.0.0
1119
- * @since 2025-09-30
1120
- * @link https://github.com/xeno-js/xeno-js
1121
- */
1122
- filePath?: Optional<string>;
1123
- /** @description Optional flag to enable pretty printing of log messages. When set to true, log messages will be formatted in a more human-readable way, which can be useful for development and debugging purposes.
1124
- *
1125
- * @author Xeno
1126
- * @version 1.0.0
1127
- * @since 2025-09-30
1128
- * @link https://github.com/xeno-js/xeno-js
1129
- */
1130
- prettyPrint?: Optional<boolean>;
1131
- }
1132
- type Destination = 'stdout' | 'file';
1133
-
1134
- /**
1135
- * @description Configuration for the middleware.
1136
- *
1137
- * @author Xeno
1138
- * @version 1.0.0
1139
- * @since 2025-09-30
1140
- * @link https://github.com/xeno-js/xeno-js
1141
- */
1142
- interface MiddlewareConfig {
1143
- /**
1144
- * @description
1145
- * The isSSR property is a boolean flag that indicates whether the application is running in a server-side rendering (SSR) environment. In an SSR environment, the application is rendered on the server-side and then sent to the client-side for display. This property is useful for configuring middleware or other components that may behave differently in an SSR environment. For example, certain middleware may need to be disabled or modified when running in an SSR environment to prevent issues with server-side rendering. By setting the isSSR property to true or false, developers can configure middleware or other components to behave appropriately in an SSR environment.
1146
- *
1147
- * @author Xeno
1148
- * @version 1.0.0
1149
- * @since 2025-09-30
1150
- * @link https://github.com/xeno-js/xeno-js
1151
- */
1152
- isSSR: boolean;
1153
- /**
1154
- * @description
1155
- * The rateLimite property is an object that contains two properties: maxRequests and windowSeconds. These properties are used to configure rate limiting for the application. Rate limiting is a technique used to prevent abuse or excessive use of a system or service by limiting the number of requests that can be made within a given time period. The maxRequests property specifies the maximum number of requests that can be made within the specified windowSeconds, and the windowSeconds property specifies the duration of the window in seconds.
1156
- *
1157
- * @author Xeno
1158
- * @version 1.0.0
1159
- * @since 2025-09-30
1160
- * @link https://github.com/xeno-js/xeno-js
1161
- */
1162
- rateLimite: {
1163
- /**
1164
- * @description
1165
- * The maxRequests property specifies the maximum number of requests that can be made within the specified windowSeconds. This property is used to configure rate limiting for the application. Rate limiting is a technique used to prevent abuse or excessive use of a system or service by limiting the number of requests that can be made within a given time period. The maxRequests property specifies the maximum number of requests that can be made within the specified windowSeconds, and the windowSeconds property specifies the duration of the window in seconds.
1166
- *
1167
- * @author Xeno
1168
- * @version 1.0.0
1169
- * @since 2025-09-30
1170
- * @link https://github.com/xeno-js/xeno-js
1171
- */
1172
- maxRequests: Optional<number>;
1173
- /**
1174
- * @description
1175
- * The windowSeconds property specifies the duration of the window in seconds. This property is used to configure rate limiting for the application. Rate limiting is a technique used to prevent abuse or excessive use of a system or service by limiting the number of requests that can be made within a given time period. The windowSeconds property specifies the duration of the window in seconds, and the maxRequests property specifies the maximum number of requests that can be made within the specified windowSeconds.
1176
- *
1177
- * @author Xeno
1178
- * @version 1.0.0
1179
- * @since 2025-09-30
1180
- * @link https://github.com/xeno-js/xeno-js
1181
- */
1182
- windowSeconds: Optional<number>;
1183
- };
1184
- /**
1185
- * @description
1186
- * 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.
1187
- *
1188
- * @author Xeno
1189
- * @version 1.0.0
1190
- * @since 2025-09-30
1191
- * @link https://github.com/xeno-js/xeno-js
1192
- */
1193
- csrf: Optional<CsrfConfig>;
1194
- /**
1195
- * @description
1196
- * 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.
1197
- *
1198
- * @author Xeno
1199
- * @version 1.0.0
1200
- * @since 2025-09-30
1201
- * @link https://github.com/xeno-js/xeno-js
1202
- */
1203
- optionsMiddleware: boolean;
1204
- /**
1205
- * @description
1206
- * The routeRegistry property is an optional property that can be used to configure the routing of HTTP requests in the application. It is an object that contains properties to define the routes and their corresponding HTTP methods. The routeRegistry property is used to map incoming HTTP requests to the appropriate route handlers, allowing the application to handle requests based on the defined routes and methods.
1207
- *
1208
- * @author Xeno
1209
- * @version 1.0.0
1210
- * @since 2025-09-30
1211
- * @link https://github.com/xeno-js/xeno-js
1212
- */
1213
- routeRegistry: Optional<Dictionary<HttpMethod[]>>;
1214
- /**
1215
- * @description
1216
- * The trustedIpHeader property is an optional property that can be used to configure the trusted IP header for the application. It is a string that specifies the name of the header that contains the trusted IP address. This property is used to determine the trusted IP address of the client making the request, which can be useful for security and authentication purposes.
1217
- *
1218
- * @author Xeno
1219
- * @version 1.0.0
1220
- * @since 2025-09-30
1221
- * @link https://github.com/xeno-js/xeno-js
1222
- */
1223
- trustedIpHeader: Optional<string>;
1224
- /**
1225
- * @description
1226
- * 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.
1227
- *
1228
- * @author Xeno
1229
- * @version 1.0.0
1230
- * @since 2025-09-30
1231
- * @link https://github.com/xeno-js/xeno-js
1232
- */
1233
- trustedProxies: Optional<string[]>;
1234
- /**
1235
- * @description
1236
- * 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.
1237
- *
1238
- * @author Xeno
1239
- * @version 1.0.0
1240
- * @since 2025-09-30
1241
- * @link https://github.com/xeno-js/xeno-js
1242
- */
1243
- allowOrigins: Optional<string[]>;
1244
- /**
1245
- * @description
1246
- * The allowMethods property is an optional property that can be used to configure the allowed methods for the application. It is an array of strings that specifies the methods that are allowed to be used in requests to the application. This property is used to implement CORS and restrict access to the application based on the method of the request.
1247
- *
1248
- * @author Xeno
1249
- * @version 1.0.0
1250
- * @since 2025-09-30
1251
- * @link https://github.com/xeno-js/xeno-js
1252
- */
1253
- allowHeaders: Optional<string[]>;
1254
- /**
1255
- * @description
1256
- * The cors property is a boolean property that is used to enable or disable 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 first resource was served. This property is used to configure the CORS middleware that is responsible for handling CORS requests and responses.
1257
- *
1258
- * @author Xeno
1259
- * @version 1.0.0
1260
- * @since 2025-09-30
1261
- * @link https://github.com/xeno-js/xeno-js
1262
- */
1263
- cors: boolean;
1264
- /**
1265
- * @description The exposeHeaders property is an array of strings that specifies the headers that should be exposed to the client. This property is used to configure the CORS middleware that is responsible for handling CORS requests and responses.
1266
- *
1267
- * @author Xeno
1268
- * @version 1.0.0
1269
- * @since 2025-09-30
1270
- * @link https://github.com/xeno-js/xeno-js
1271
- */
1272
- withCredentials: boolean;
1273
- /**
1274
- * @description The cookie prefix
1275
- */
1276
- authCookieName: Optional<string>;
1277
- }
1278
- /**
1279
- * @description
1280
- * 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.
1281
- */
1282
- interface CsrfConfig {
1283
- /**
1284
- * Secret used to sign CSRF tokens.
1285
- */
1286
- secret: string;
1287
- /**
1288
- * @description the name of the cookie that will be used to store the CSRF token.
1289
- */
1290
- cookieName: Optional<string>;
1291
- /**
1292
- * @description the name of the header that will be used to send the CSRF token.
1293
- */
1294
- headerName: Optional<string>;
1295
- /**
1296
- * @description the number of seconds that the CSRF token will be valid for.
1297
- */
1298
- cookieMaxAgeSeconds: Optional<number>;
1299
- /**
1300
- * Cookie SameSite policy.
1301
- */
1302
- sameSite?: 'strict' | 'lax' | 'none';
1303
- /**
1304
- * Enforce Origin/Referer validation for unsafe requests.
1305
- */
1306
- enforceOrigin?: boolean;
1307
- }
1308
-
1309
- /**
1310
- * @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.
1311
-
1312
- *
1313
- * @author Xeno
1314
- * @version 1.0.0
1315
- * @since 2025-09-30
1316
- * @link https://github.com/xeno-js/xeno-js
1317
- */
1318
- interface PipelineConfig<TRegistry extends ApplicationRegistry<unknown> = ApplicationRegistry<unknown>, TSchema = unknown> {
1319
- /** @description Configuration for performance monitoring, including the ability to set a threshold in milliseconds for logging slow operations. If enabled, the PerformancePipeline will log a warning whenever the execution of a command or query exceeds the specified threshold, helping to identify potential performance bottlenecks in the application. If the threshold is not defined, all operations will be monitored without duration-based filtering.
1320
- *
1321
- * @author Xeno
1322
- * @version 1.0.0
1323
- * @since 2025-09-30
1324
- * @link https://github.com/xeno-js/xeno-js
1325
- */
1326
- performance: {
1327
- /** @description Optional threshold in milliseconds for logging slow operations. If defined, the PerformancePipeline will log a warning whenever the execution of a command or query exceeds this duration, allowing for performance monitoring and optimization. If not defined, all operations will be monitored without duration-based filtering.
1328
- *
1329
- * @author Xeno
1330
- * @version 1.0.0
1331
- * @since 2025-09-30
1332
- * @link https://github.com/xeno-js/xeno-js
1333
- */
1334
- thresholdMs: Optional<number>;
1335
- /** @description Optional threshold in milliseconds for logging slow operations by intent. If defined, the PerformancePipeline will log a warning whenever the execution of a command or query exceeds this duration, allowing for performance monitoring and optimization. If not defined, all operations will be monitored without duration-based filtering.
1336
- *
1337
- * @author Xeno
1338
- * @version 1.0.0
1339
- * @since 2025-09-30
1340
- * @link https://github.com/xeno-js/xeno-js
1341
- */
1342
- intentThresholdMs: Optional<Dictionary<number>>;
1343
- };
1344
- /** @description Configuration for authorization, allowing the enabling of authorization strategies based on tenant, policy, roles, and permissions. If enabled, the authorization pipeline will evaluate the specified strategies for each command or query, ensuring that only authorized users can perform certain actions. The configuration also includes the ability to define custom authorization strategies via injection tokens, providing flexibility in implementing application-specific access rules.
1345
- *
1346
- * @author Xeno
1347
- * @version 1.0.0
1348
- * @since 2025-09-30
1349
- * @link https://github.com/xeno-js/xeno-js
1350
- */
1351
- authorization: {
1352
- /** @description Configuration for policy-based authorization, allowing the definition of a policy registry and the option to enable role-based or permission-based checks. If policy-based authorization is enabled, the authorization pipeline will include a strategy that evaluates the defined policies for each command or query, ensuring that users meet the necessary criteria based on their roles and permissions. The policy registry allows for central management of authorization policies, making it easier to maintain and update access rules across the application.
1353
- *
1354
- * @author Xeno
1355
- * @version 1.0.0
1356
- * @since 2025-09-30
1357
- * @link https://github.com/xeno-js/xeno-js
1358
- */
1359
- policies: Optional<Dictionary<AuthPolicy>>;
1360
- /** @description An optional array of custom authorization strategies defined via injection tokens. If provided, these strategies will be included in the authorization pipeline and evaluated for each command or query, allowing for custom logic to determine if a user is authorized to perform a specific action. This provides flexibility in implementing application-specific access rules that may not fit into standard tenant-based or policy-based checks. Each strategy should implement the IStrategy interface and return a boolean indicating whether the command or query is authorized.
1361
- *
1362
- * @author Xeno
1363
- * @version 1.0.0
1364
- * @since 2025-09-30
1365
- * @link https://github.com/xeno-js/xeno-js
1366
- */
1367
- customAuthorizationStrategy?: Optional<(container: IServiceScope<TRegistry>) => IStrategy<IRequest>>[];
1368
- };
1369
- /** @description Configuration for validation, allowing the enabling of validation based on Zod schemas or custom validation strategies. If enabled, the validation pipeline will validate commands and queries based on the specified criteria, ensuring that input data meets expectations before further processing. The configuration includes the ability to define Zod schemas for structural validation or to use custom strategies via injection tokens, providing flexibility in implementing application-specific validation rules.
1370
- *
1371
- * @author Xeno
1372
- * @version 1.0.0
1373
- * @since 2025-09-30
1374
- * @link https://github.com/xeno-js/xeno-js
1375
- */
1376
- validation: {
1377
- /** @description An optional configuration for Zod-based validation, allowing the definition of schemas for validating the structure and content of commands and queries. If provided, the validation pipeline will use these schemas to validate incoming requests, ensuring that they conform to the expected format and contain valid data before being processed further. This provides a powerful and flexible way to enforce data integrity and prevent invalid input from causing issues in the application.
1378
- *
1379
- * @author Xeno
1380
- * @version 1.0.0
1381
- * @since 2025-09-30
1382
- * @link https://github.com/xeno-js/xeno-js
1383
- */
1384
- zod: Optional<SchemaConfig<TSchema>>;
1385
- /** @description An optional array of custom validation strategies defined via injection tokens. If provided, these strategies will be included in the validation pipeline and evaluated for each command or query, allowing for custom logic to determine if the input data is valid. This provides flexibility in implementing application-specific validation rules that may not fit into standard schema-based validation. Each strategy should implement the IStrategy interface and return a boolean indicating whether the command or query is valid.
1386
- *
1387
- * @author Xeno
1388
- * @version 1.0.0
1389
- * @since 2025-09-30
1390
- * @link https://github.com/xeno-js/xeno-js
1391
- */
1392
- customValidationStrategy?: Optional<(container: IServiceScope<TRegistry>) => IStrategy<IRequest, boolean>>[];
1393
- };
1394
- /** @description Configuration for the command bus, allowing the enabling of features such as idempotency and concurrency management. If enabled, the command bus pipeline will include specific behaviors to handle these features, such as acquiring locks to ensure idempotency or managing retries in case of concurrency conflicts. The configuration includes specific details for each feature, such as TTLs for idempotency locks or delay strategies for concurrency retries, providing granular control over how commands are processed and managed within the application.
9
+ * @version 1.0.0
10
+ * @since 2025-09-30
11
+ * @link https://github.com/xeno-js/xeno-js
12
+ */
13
+ declare abstract class BaseHandler<TRequest extends IRequest<TResponse>, TResponse> implements IHandler<TRequest, TResponse> {
14
+ private readonly _identityFactory;
15
+ constructor(_identityFactory: IFactory<void, UserContext>);
16
+ handle(request: TRequest, signal: Optional<AbortSignal>): Promise<ResultType<TResponse>>;
17
+ /**
18
+ * Executes the strategy for the given request.
19
+ * @param request - The request to be handled.
20
+ * @param signal - (Optional) The abort signal for the request.
21
+ * @throws {AppError} If the strategy execution fails.
22
+ * @protected - This method should be overridden by subclasses.
23
+ * @abstract - This method must be implemented by subclasses.
24
+ * @async - This method is asynchronous.
25
+ * @template TRequest - The type of the request.
26
+ * @template TResponse - The type of the response.
27
+ * @returns {Promise<ResultType<TResponse>>} A promise that resolves to the result of the strategy execution.
1395
28
  *
1396
29
  * @author Xeno
1397
30
  * @version 1.0.0
1398
31
  * @since 2025-09-30
1399
32
  * @link https://github.com/xeno-js/xeno-js
1400
33
  */
1401
- commandBus: {
1402
- idempotency: Optional<IdempotencyConfig>;
1403
- concurrency: Optional<ConcurrencyConfig>;
1404
- };
1405
- /** @description Configuration for the query bus, allowing the enabling of features such as result caching. If enabled, the query bus pipeline will include specific behaviors to handle caching, such as storing query results in a cache system and retrieving results from the cache when available. The configuration includes specific details for caching, such as settings for Redis integration or the ability to use a custom cache via injection tokens, providing flexibility in how query results are stored and retrieved within the application.
1406
- *
1407
- * @author Xeno
1408
- * @version 1.0.0
1409
- * @since 2025-09-30
1410
- * @link https://github.com/xeno-js/xeno-js
34
+ protected abstract executeAsync(request: TRequest, signal?: Optional<AbortSignal>): Promise<ResultType<TResponse>>;
35
+ /**
36
+ * Gets the current context.
37
+ * @returns {UserContext} The current context.
38
+ * {@link UserContext}
1411
39
  */
1412
- queryBus: {
1413
- /** @description Flag to enable or disable query bus features. If set to true, the query bus pipeline will include additional behaviors based on the specified configuration, such as result caching. If set to false or not defined, the query bus will operate without these additional features, allowing queries to be processed in a standard manner without caching or other enhancements.
1414
- *
1415
- * @author Xeno
1416
- * @version 1.0.0
1417
- * @since 2025-09-30
1418
- * @link https://github.com/xeno-js/xeno-js
1419
- */
1420
- isEnabled: boolean;
1421
- };
40
+ protected _getCurrentContext(): UserContext;
1422
41
  }
1423
- /** @description Configuration for caching, allowing the enabling of Redis integration or the use of a custom cache. If enabled, the query bus and command bus (in case of idempotency) pipelines will use the configured cache system to store and retrieve data efficiently. The configuration includes specific details for Redis integration, such as host, port, and credentials, as well as the ability to define a custom cache via injection tokens, providing flexibility in how the cache is implemented and used within the application.
1424
- *
42
+
43
+ /**
44
+ * @description Base class for all commands.
1425
45
  * @author Xeno
1426
46
  * @version 1.0.0
1427
47
  * @since 2025-09-30
1428
48
  * @link https://github.com/xeno-js/xeno-js
1429
49
  */
1430
- interface SchemaConfig<TSchema> {
1431
- /** @description A record of Zod schemas, where each key represents a specific command or query type, and the corresponding value is the Zod schema used to validate that type. If provided, the validation pipeline will use these schemas to validate incoming requests, ensuring that they conform to the expected format and contain valid data before being processed further. This allows for powerful and flexible validation rules based on the structure and content of commands and queries.
1432
- *
1433
- * @author Xeno
1434
- * @version 1.0.0
1435
- * @since 2025-09-30
1436
- * @link https://github.com/xeno-js/xeno-js
1437
- */
1438
- schemas: Dictionary<TSchema>;
50
+ declare abstract class Command<TResponse = unknown> implements ICommand<TResponse> {
51
+ readonly intent: string;
52
+ readonly type: RequestType;
53
+ readonly cacheInvalidation: Optional<{
54
+ keys?: string[];
55
+ patterns?: string[];
56
+ }>;
57
+ constructor(intent: string, cacheInvalidation?: {
58
+ keys?: string[];
59
+ patterns?: string[];
60
+ });
1439
61
  }
1440
- /** @description Configuration for idempotency, allowing the definition of TTLs for locks and processed results. If enabled, the command bus pipeline will include specific behaviors to handle idempotency, such as acquiring locks to ensure that a command with the same ID is processed only once and storing the results of processed commands for a defined period. The configuration includes specific details for TTLs, such as the duration of the lock and the duration for which processed results are retained, providing granular control over how idempotency is managed within the application.
62
+
63
+ /**
64
+ * @description Abstract base class for authorization strategies in the CQRS pipeline. This class implements the IStrategy interface and provides a common structure for performing authorization checks based on the identity of the authenticated user. It defines an abstract method performAuthorizationCheck that must be implemented by concrete authorization strategies to specify the logic for checking if the user has the necessary permissions to execute a given request. The execute method retrieves the user's identity from the request context and ensures that the user is authenticated before delegating to the performAuthorizationCheck method for further authorization validation. If the user is not authenticated, it returns a failed Result with an appropriate AppError indicating that authentication is required.
1441
65
  *
1442
66
  * @author Xeno
1443
67
  * @version 1.0.0
1444
68
  * @since 2025-09-30
1445
69
  * @link https://github.com/xeno-js/xeno-js
1446
70
  */
1447
- interface IdempotencyConfig {
1448
- /** @description Optional TTL in seconds for the idempotency lock. This defines how long the lock should be held to prevent duplicate processing of commands with the same ID. If not defined, a default value will be used.
71
+ declare abstract class BaseAuthorizationStrategy<TInput extends IRequest> implements IStrategy<TInput> {
72
+ private readonly _requestContext;
73
+ /**
74
+ * @description Constructs a new instance of the BaseAuthorizationStrategy class, which serves as an abstract base for specific authorization strategies in the CQRS pipeline. It takes an IRequestContext as a parameter, which is used to retrieve the identity of the currently authenticated user during the authorization process. This context is essential for performing the authorization checks based on the user's identity when executing requests that require specific permissions.
75
+ * @param requestContext An instance of IRequestContext used to access the identity of the currently authenticated user. This context is essential for performing the authorization checks based on the user's identity when executing requests that require specific permissions.
1449
76
  *
1450
77
  * @author Xeno
1451
78
  * @version 1.0.0
1452
79
  * @since 2025-09-30
1453
80
  * @link https://github.com/xeno-js/xeno-js
1454
81
  */
1455
- lockTtlSeconds: Optional<number>;
1456
- /** @description Optional TTL in seconds for storing the results of processed commands. This defines how long the results of a processed command should be retained in the cache, allowing for retrieval if the same command is received again within that period. If not defined, a default value will be used.
82
+ constructor(_requestContext: IContextAccessor<RequestContext>);
83
+ execute(request: IRequest): Promise<ResultType<void>>;
84
+ /**
85
+ * @description Abstract method that must be implemented by concrete authorization strategies to perform the actual authorization check. This method is called after the user's identity has been retrieved and verified. It receives the request and the user's identity as parameters and should return a Result indicating whether the authorization check passed or failed.
86
+ * @param request The incoming request for which the authorization check is being performed. This request contains information about the action being attempted and any relevant data needed for the authorization logic.
87
+ * @param auth The identity of the currently authenticated user, which includes information such as the user's ID, tenant ID, and roles. This context is used to determine if the user has the necessary permissions to execute the request.
88
+ * @returns A Result indicating the outcome of the authorization check. If the check passes, it should return a successful Result with a void value. If the check fails, it should return a failed Result with an appropriate AppError describing the reason for the failure.
1457
89
  *
1458
90
  * @author Xeno
1459
91
  * @version 1.0.0
1460
92
  * @since 2025-09-30
1461
93
  * @link https://github.com/xeno-js/xeno-js
1462
94
  */
1463
- processedTtlSeconds: Optional<number>;
95
+ protected abstract performAuthorizationCheck(request: IRequest, auth: Identity): Promise<ResultType<void>>;
1464
96
  }
1465
- /** @description Configuration for concurrency management, allowing the definition of maximum retries and delay strategies for retries. If enabled, the command bus pipeline will include specific behaviors to handle concurrency conflicts, such as retrying a command in case of failure due to a conflict. The configuration includes specific details for retries, such as the maximum number of attempts and delay strategies (e.g., exponential backoff with jitter) between attempts, providing granular control over how concurrency is managed within the application.
97
+
98
+ /**
99
+ * @description Strategy that validates incoming requests against predefined schemas. It implements the IStrategy interface and uses a schema registry to determine if a schema exists for the given request type. If a schema is found, it validates the request against the schema using a safe parsing method. If the validation fails, it returns a failed Result with an appropriate AppError indicating a validation error. If the validation succeeds, it returns a successful Result with a boolean value of true.
1466
100
  *
1467
101
  * @author Xeno
1468
102
  * @version 1.0.0
1469
103
  * @since 2025-09-30
1470
104
  * @link https://github.com/xeno-js/xeno-js
1471
105
  */
1472
- interface ConcurrencyConfig {
1473
- /** @description Optional maximum number of retry attempts in case of concurrency conflicts. This defines how many times the command bus should attempt to retry a command if it fails due to a concurrency issue, such as a version conflict in an optimistic concurrency control scenario. If not defined, a default value will be used.
106
+ declare class SchemaValidationStrategy implements IStrategy<IRequest, boolean> {
107
+ private readonly _validator;
108
+ /**
109
+ * @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.
110
+ * @param _validator An instance of IValidatorService that provides methods to check for the existence of validation schemas and to validate data against those schemas. This service is essential for performing the schema validation logic in this strategy.
1474
111
  *
1475
112
  * @author Xeno
1476
113
  * @version 1.0.0
1477
114
  * @since 2025-09-30
1478
115
  * @link https://github.com/xeno-js/xeno-js
1479
116
  */
1480
- maxRetries?: Optional<number>; /** @description Optional configuration for delay strategies between retry attempts. This can include settings for exponential backoff, jitter, or fixed delays to manage the timing of retries in case of concurrency conflicts. If not defined, a default delay strategy will be used.
117
+ constructor(_validator: IValidatorService);
118
+ execute(request: IRequest): Promise<ResultType<boolean>>;
119
+ }
120
+
121
+ /**
122
+ * @description A pipeline behavior that performs validation on the incoming request in a CQRS architecture. It checks if the request has a validate method and, if so, invokes it to perform validation. If the validation fails, it returns a failed Result containing the validation error. If the validation succeeds or if there is no validate method, it proceeds to the next behavior in the pipeline. This allows for a structured approach to ensuring that requests meet certain criteria before being processed further in the CQRS pipeline.
123
+
124
+ *
125
+ * @author Xeno
126
+ * @version 1.0.0
127
+ * @since 2025-09-30
128
+ * @link https://github.com/xeno-js/xeno-js
129
+ */
130
+ declare class ValidationPipeline<TInput extends IRequest<TResult>, TResult> implements IPipelineBehavior<TInput, TResult> {
131
+ private readonly _validators;
132
+ /** @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.
133
+ * @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.
1481
134
  *
1482
135
  * @author Xeno
1483
136
  * @version 1.0.0
1484
137
  * @since 2025-09-30
1485
138
  * @link https://github.com/xeno-js/xeno-js
1486
139
  */
1487
- delayConfig: {
1488
- /** @description Base delay in milliseconds for retries. This defines the initial delay before the first retry attempt in case of a concurrency conflict. If using an exponential backoff strategy, this base delay will be multiplied for each subsequent retry attempt. If not defined, a default value will be used.
1489
- *
1490
- * @author Xeno
1491
- * @version 1.0.0
1492
- * @since 2025-09-30
1493
- * @link https://github.com/xeno-js/xeno-js
1494
- */
1495
- baseDelayMs: number;
1496
- /** @description Optional maximum delay in milliseconds for retries. This defines the upper limit for the delay between retry attempts, preventing excessively long delays in case of multiple retries. If not defined, a default value will be used.
1497
- *
1498
- * @author Xeno
1499
- * @version 1.0.0
1500
- * @since 2025-09-30
1501
- * @link https://github.com/xeno-js/xeno-js
1502
- */
1503
- maxJitterMs: number;
1504
- };
140
+ constructor(_validators: readonly IStrategy<TInput, boolean>[]);
141
+ handle(request: TInput, next: Delegate<TResult>): Promise<ResultType<TResult>>;
1505
142
  }
1506
143
 
1507
- declare const TOKENS: Readonly<{
1508
- USER_CONTEXT_FACTORY: "USER_CONTEXT_FACTORY";
1509
- AUTH_SERVICE: "AUTH_SERVICE";
1510
- BASE_AUTH_SERVICE: "BASE_AUTH_SERVICE";
1511
- CACHE: "CACHE";
1512
- CACHE_KEY_BUILDER: "CACHE_KEY_BUILDER";
1513
- COMMAND_PIPELINES_BEHAVIOR: "COMMAND_PIPELINES_BEHAVIOR";
1514
- CONCURRENCY_SERVICE: "CONCURRENCY_SERVICE";
1515
- CONFIGURATION_SERVICE: "CONFIGURATION_SERVICE";
1516
- CONTEXT_ACCESSOR: "CONTEXT_ACCESSOR";
1517
- CRYPTO_SERVICE: "CRYPTO_SERVICE";
1518
- CSRF_TOKEN_SERVICE: "CSRF_TOKEN_SERVICE";
1519
- DB_CONTEXT: "DB_CONTEXT";
1520
- IDENTITY_ACCESSOR: "IDENTITY_ACCESSOR";
1521
- LOGGER: "LOGGER";
1522
- MEDIATOR: "MEDIATOR";
1523
- NETWORK_CONTEXT_ACCESSOR: "NETWORK_CONTEXT_ACCESSOR";
1524
- QUERY_PIPELINES_BEHAVIOR: "QUERY_PIPELINES_BEHAVIOR";
1525
- REQUEST_CONTEXT: "REQUEST_CONTEXT";
1526
- MIDDLEWARE: "MIDDLEWARE";
1527
- RESILIENCE_CLIENT: "RESILIENCE_CLIENT";
1528
- SCHEMA_VALIDATION_STRATEGY: "SCHEMA_VALIDATION_STRATEGY";
1529
- SERVICE_CONTAINER: "SERVICE_CONTAINER";
1530
- SERVICE_EXTRACTOR: "SERVICE_EXTRACTOR";
1531
- SERVICE_SCOPE_ACCESSOR: "SERVICE_SCOPE_ACCESSOR";
1532
- UNIT_OF_WORK: "UNIT_OF_WORK";
1533
- VALIDATOR_SERVICE: "VALIDATOR_SERVICE";
1534
- }>;
1535
-
1536
- /**
1537
- * Utils that provide utility functions for interacting with the service container and managing scoped service resolution.
1538
- */
1539
- declare const ContainerUtils: Readonly<{
1540
- /**
1541
- * Resolves a scoped service from the container using the provided token.
1542
- * @param token * The token to resolve from the registry.
1543
- * @param container * The container to resolve the service from.
1544
- *
1545
- * @returns The resolved service instance.
1546
- * @throws Error if the active service scope is not available.
1547
- */
1548
- resolveServiceScoped<K extends keyof T, T extends ApplicationRegistry>(token: K, container: IServiceContainer<T>): T[K];
1549
- /**
1550
- * Executes a service action within the context of a scoped service.
1551
- * @param res * The response DTO to be returned.
1552
- * @param req * The request DTO to be passed to the action.
1553
- * @param container * The container to resolve the service from.
1554
- * @param action * The action to execute within the scoped service.
1555
- *
1556
- * @returns Promise<ResponseDto<TResponse>> A promise that resolves to the response DTO of the executed action.
1557
- * @throws Error If the active service scope is not available.
1558
- * @throws Error If the service is not found in the container.
1559
- * @throws Error If the service is not a scoped service.
1560
- */
1561
- runExecute<TResponse, T extends ApplicationRegistry, TRes, TReq>(res: TRes, req: TReq, container: IServiceContainer<T>, action: () => Promise<ResponseDto<TResponse>>): Promise<ResponseDto<TResponse>>;
1562
- }>;
1563
-
1564
144
  /**
1565
- * @description Abstract base class for authorization strategies in the CQRS pipeline. This class implements the IStrategy interface and provides a common structure for performing authorization checks based on the identity of the authenticated user. It defines an abstract method performAuthorizationCheck that must be implemented by concrete authorization strategies to specify the logic for checking if the user has the necessary permissions to execute a given request. The execute method retrieves the user's identity from the request context and ensures that the user is authenticated before delegating to the performAuthorizationCheck method for further authorization validation. If the user is not authenticated, it returns a failed Result with an appropriate AppError indicating that authentication is required.
1566
- *
145
+ * @description Base class for all queries.
1567
146
  * @author Xeno
1568
147
  * @version 1.0.0
1569
148
  * @since 2025-09-30
1570
149
  * @link https://github.com/xeno-js/xeno-js
1571
150
  */
1572
- declare abstract class BaseAuthorizationStrategy<TInput extends IRequest> implements IStrategy<TInput> {
1573
- private readonly _requestContext;
1574
- /**
1575
- * @description Constructs a new instance of the BaseAuthorizationStrategy class, which serves as an abstract base for specific authorization strategies in the CQRS pipeline. It takes an IRequestContext as a parameter, which is used to retrieve the identity of the currently authenticated user during the authorization process. This context is essential for performing the authorization checks based on the user's identity when executing requests that require specific permissions.
1576
- * @param requestContext An instance of IRequestContext used to access the identity of the currently authenticated user. This context is essential for performing the authorization checks based on the user's identity when executing requests that require specific permissions.
1577
- *
1578
- * @author Xeno
1579
- * @version 1.0.0
1580
- * @since 2025-09-30
1581
- * @link https://github.com/xeno-js/xeno-js
1582
- */
1583
- constructor(_requestContext: IContextAccessor<RequestContext>);
1584
- execute(request: IRequest): Promise<ResultType<void>>;
1585
- /**
1586
- * @description Abstract method that must be implemented by concrete authorization strategies to perform the actual authorization check. This method is called after the user's identity has been retrieved and verified. It receives the request and the user's identity as parameters and should return a Result indicating whether the authorization check passed or failed.
1587
- * @param request The incoming request for which the authorization check is being performed. This request contains information about the action being attempted and any relevant data needed for the authorization logic.
1588
- * @param auth The identity of the currently authenticated user, which includes information such as the user's ID, tenant ID, and roles. This context is used to determine if the user has the necessary permissions to execute the request.
1589
- * @returns A Result indicating the outcome of the authorization check. If the check passes, it should return a successful Result with a void value. If the check fails, it should return a failed Result with an appropriate AppError describing the reason for the failure.
1590
- *
1591
- * @author Xeno
1592
- * @version 1.0.0
1593
- * @since 2025-09-30
1594
- * @link https://github.com/xeno-js/xeno-js
1595
- */
1596
- protected abstract performAuthorizationCheck(request: IRequest, auth: Identity): Promise<ResultType<void>>;
151
+ declare abstract class Query<TResponse = unknown> implements IQuery<TResponse> {
152
+ readonly intent: string;
153
+ readonly cacheOptions: ICacheableOptions;
154
+ readonly type: RequestType;
155
+ constructor(intent: string, cacheOptions: ICacheableOptions);
1597
156
  }
1598
157
 
1599
158
  /**
@@ -1661,15 +220,51 @@ declare abstract class Specification<T> implements ISpecification<T> {
1661
220
  not(): ISpecification<T>;
1662
221
  }
1663
222
 
223
+ declare class XenoApplication<TRegistry extends XenoRegistry = XenoRegistry> implements IXenoApplication<TRegistry> {
224
+ protected readonly _container: IServiceContainer<TRegistry>;
225
+ constructor(_container: IServiceContainer<TRegistry>);
226
+ /**
227
+ * @description Resolve the services proxy
228
+ * @returns The services proxy
229
+ */
230
+ getServices(): ServicesProxy<TRegistry>;
231
+ /**
232
+ * @description Resolve the services proxy for the current request scope.
233
+ * @returns {ServicesProxy<TRegistry>} The services proxy.
234
+ */
235
+ getScopedServices(): ServicesProxy<TRegistry>;
236
+ /**
237
+ * @description Run the given operation in a new scope.
238
+ * @param {Function} operation The operation to run.
239
+ * @param {Partial<RequestContext>} [ctx] The request context.
240
+ * @returns {Promise<T>} The result of the operation.
241
+ */
242
+ runInScope<T>(operation: (services: ServicesProxy<TRegistry>) => Promise<T>, ctx?: Optional<Partial<RequestContext>>): Promise<T>;
243
+ /**
244
+ * @description Runs a controller operation in the context of a request.
245
+ * Use it only if middlewares are registered in the container.
246
+ * @param req The XenoIncomingRequest request object.
247
+ * @param token The token of the controller operation to run.
248
+ * @param input The input to the controller operation.
249
+ * @returns A promise that resolves to the output of the controller operation.
250
+ */
251
+ handle<TInput, TOutput, K extends keyof TRegistry>(req: XenoIncomingRequest, token: K, input?: Optional<TInput>): Promise<ResponseDto<TOutput>>;
252
+ /**
253
+ * @description Resolves the HTTP server and starts listening on the specified port.
254
+ * @param options The options for the HTTP server.
255
+ * @returns A promise that resolves to the result of the HTTP server listen method.
256
+ */
257
+ listen(options?: NativeListenOptions): Promise<unknown>;
258
+ }
259
+
1664
260
  /**
1665
261
  * @description The AppBuilder class provides a fluent, .NET-style API for configuring and bootstrapping the application. It orchestrates the registration of various modules (CQRS, HTTP, Database, Logging, Auth) into the ServiceContainer.
1666
-
1667
- *
1668
- * @author Xeno
1669
- * @version 1.0.0
1670
- * @since 2025-09-30
1671
- * @link https://github.com/xeno-js/xeno-js
1672
- */
262
+ *
263
+ * @author Xeno
264
+ * @version 1.0.0
265
+ * @since 2025-09-30
266
+ * @link https://github.com/xeno-js/xeno-js
267
+ */
1673
268
  interface QueuedModule {
1674
269
  priority: number;
1675
270
  name: string;
@@ -1678,27 +273,23 @@ interface QueuedModule {
1678
273
  /**
1679
274
  * @description The AppBuilder class provides a fluent, .NET-style API for configuring and bootstrapping the application.
1680
275
  * It orchestrates the registration of various modules (CQRS, HTTP, Database, Logging, Auth) into the ServiceContainer.
1681
-
1682
- *
1683
- * @author Xeno
1684
- * @version 1.0.0
1685
- * @since 2025-09-30
1686
- * @link https://github.com/xeno-js/xeno-js
1687
- */
1688
- declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegistry> {
276
+ *
277
+ * @author Xeno
278
+ * @version 1.0.0
279
+ * @since 2025-09-30
280
+ * @link https://github.com/xeno-js/xeno-js
281
+ */
282
+ declare class XenoAppBuilder<TRegistry extends XenoRegistry = XenoRegistry, TApp extends XenoApplication<TRegistry> = XenoApplication<TRegistry>> implements IAppBuilder<TRegistry, TApp> {
1689
283
  protected _container: IServiceContainer<TRegistry>;
1690
284
  protected readonly _configuration: IConfigurationService;
1691
- protected _buildPromise: Nullable<Promise<IServiceContainer<TRegistry>>>;
1692
- constructor(container?: IServiceContainer<TRegistry>, configurationService?: IConfigurationService);
285
+ protected _buildPromise: Nullable<Promise<TApp>>;
286
+ private _pipelinePlugins;
287
+ private _appFactory;
288
+ constructor(container?: IServiceContainer<TRegistry>, configurationService?: 'vite' | 'node' | IConfigurationService);
289
+ private _getConfigurationService;
1693
290
  protected readonly _modules: QueuedModule[];
1694
- private _adapterConfig;
1695
- private _pipelineConfig;
1696
- private _config;
1697
291
  private _middlewareConfig;
1698
- private readonly _authConfig;
1699
- private readonly _httpConfig;
1700
- private readonly _loggerConfig;
1701
- private _isContextModuleQueued;
292
+ private _routes;
1702
293
  private _isMiddlewareModuleQueued;
1703
294
  private _isPipelineModuleQueued;
1704
295
  private _isLoggerModuleQueued;
@@ -1706,32 +297,51 @@ declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegi
1706
297
  private _isDbContextModuleQueued;
1707
298
  private _isConcurrencyServiceQueued;
1708
299
  private _isCacheModuleQueued;
1709
- private _isAdapterModuleQueued;
1710
- protected addAdapter(setupAction: SetupAction<HttpAdapterConfig, IConfigurationService>): this;
300
+ private _isHttpCoreQueued;
301
+ private _isHttpServerQueued;
302
+ private _isRouteModuleQueued;
303
+ private _isContextModuleQueued;
304
+ protected setApplicationFactory(factory: (container: IServiceContainer<TRegistry>) => TApp): this;
305
+ /**
306
+ * @description Add http server plugin to the application.
307
+ * @param plugin - The http server plugin to be added.
308
+ * @returns {this} The current instance of the class.
309
+ */
310
+ addHttpServer(plugin: HttpServerPlugin<TRegistry>): this;
311
+ /**
312
+ * @description Add a new route to the application.
313
+ * @param routes - The routes to be added.
314
+ * @returns {this} The current instance of the class.
315
+ */
316
+ addRoutes(routes: NativeRouteDefinition<TRegistry>[]): this;
1711
317
  /**
1712
318
  * @description Enables the use of middlewares in the application. Middlewares can be used for cross-cutting concerns such as logging, authentication, and request/response manipulation.
1713
319
  * @returns The current instance of AppBuilder for method chaining.
1714
-
1715
320
  *
1716
321
  * @author Xeno
1717
322
  * @version 1.0.0
1718
323
  * @since 2025-09-30
1719
324
  * @link https://github.com/xeno-js/xeno-js
1720
325
  */
1721
- addMiddlewares(setupAction: SetupAction<MiddlewareConfig, IConfigurationService>): this;
326
+ addMiddlewares(setupAction?: SetupAction<MiddlewareConfig, IConfigurationService>): this;
1722
327
  /**
1723
328
  * @description Enables the use of context in the application. Context can be used to store and manage request-specific data, such as user information, correlation IDs, and other metadata that needs to be accessible throughout the request lifecycle.
1724
329
  * @returns The current instance of AppBuilder for method chaining.
1725
-
1726
330
  *
1727
331
  * @author Xeno
1728
332
  * @version 1.0.0
1729
333
  * @since 2025-09-30
1730
334
  * @link https://github.com/xeno-js/xeno-js
1731
335
  */
1732
- addContext(): this;
336
+ addContext(plugin?: ContextPlugin<TRegistry>): this;
337
+ /**
338
+ * @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 custom logging services.
339
+ * @param plugin A LoggerPlugin instance or an array of LoggerPlugin instances to configure the logger.
340
+ * @returns The current instance of AppBuilder for method chaining.
341
+ */
342
+ addLogger(plugin?: LoggerPlugin<TRegistry> | LoggerPlugin<TRegistry>[]): this;
1733
343
  /**
1734
- * @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.
344
+ * @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 custom logging services.
1735
345
  * @param setupAction A callback function that receives a LoggerConfig object to configure the logger settings.
1736
346
  * @returns The current instance of AppBuilder for method chaining.
1737
347
  *
@@ -1743,40 +353,45 @@ declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegi
1743
353
  addLogger(setupAction?: SetupAction<LoggerConfig<TRegistry>, IConfigurationService>): this;
1744
354
  /**
1745
355
  * @description Configures the caching settings for the application. This method allows you to set up caching options such as Redis configuration or in-memory caching.
1746
- * @param setupAction A callback function that receives a CacheConfig object to configure the caching settings.
356
+ * @param plugin Optional plugin function to configure the caching module.
357
+ * @defaults The default caching module is the in-memory caching module.
1747
358
  * @returns The current instance of AppBuilder for method chaining.
1748
-
1749
359
  *
1750
360
  * @author Xeno
1751
361
  * @version 1.0.0
1752
362
  * @since 2025-09-30
1753
363
  * @link https://github.com/xeno-js/xeno-js
1754
364
  */
365
+ addCache(plugin?: CachePlugin<TRegistry>): this;
1755
366
  addCache(setupAction?: SetupAction<CacheConfig, IConfigurationService>): this;
1756
367
  /**
1757
368
  * @description Configures the authentication client for the application. This method allows you to set up authentication options such as the authentication server URL, API key, and additional options.
1758
- * @param setupAction A callback function that receives an AuthClientConfig object to configure the authentication client settings.
369
+ * @param plugin A plugin function that configures the authentication client.
370
+ * @returns The current instance of AppBuilder for method chaining.
371
+ */
372
+ addAuth(plugin: AuthPlugin<TRegistry>): this;
373
+ /**
374
+ * @description Configures the authentication client for the application. This method allows you to set up authentication options such as the authentication server URL, API key, and additional options.
375
+ * @param setupAction A function that configures the authentication client.
1759
376
  * @returns The current instance of AppBuilder for method chaining.
1760
-
1761
377
  *
1762
378
  * @author Xeno
1763
379
  * @version 1.0.0
1764
380
  * @since 2025-09-30
1765
381
  * @link https://github.com/xeno-js/xeno-js
1766
382
  */
1767
- addAuth(setupAction: SetupAction<AuthSsrConfig, IConfigurationService>): this;
383
+ addAuth(setupAction: SetupAction<AuthModuleOptions<TRegistry>, IConfigurationService>): this;
1768
384
  /**
1769
385
  * @description Configures the database settings for the application. This method allows you to set up database options such as enabling/disabling the database, connection string, and table definitions.
1770
- * @param setupAction A callback function that receives a DbConfig object to configure the database settings.
386
+ * @param plugin A callback function that receives a DbConfig object to configure the database settings.
1771
387
  * @returns The current instance of AppBuilder for method chaining.
1772
-
1773
388
  *
1774
389
  * @author Xeno
1775
390
  * @version 1.0.0
1776
391
  * @since 2025-09-30
1777
392
  * @link https://github.com/xeno-js/xeno-js
1778
393
  */
1779
- addDb(plugin: (builder: this, config: IConfigurationService) => this): this;
394
+ addDb(plugin: DbPlugin<TRegistry>): this;
1780
395
  /**
1781
396
  * @description Enables the use of the service for concurrency control in the application. This method allows you to limit the number of concurrent asynchronous tasks being executed, which is useful for managing system resources and preventing event loop blocking during massive batch operations.
1782
397
  * @returns The current instance of AppBuilder for method chaining.
@@ -1799,19 +414,24 @@ declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegi
1799
414
  * @since 2025-09-30
1800
415
  * @link https://github.com/xeno-js/xeno-js
1801
416
  */
1802
- addPipeline(setupAction?: SetupAction<PipelineConfig<TRegistry>, IConfigurationService>): this;
417
+ addPipeline(pluginOrPlugins?: PipelinePlugin<TRegistry> | PipelinePlugin<TRegistry>[]): this;
418
+ /**
419
+ * @description Configures the HTTP core settings for the application. This method allows you to set up HTTP core options such as data source token and HTTP client configuration.
420
+ * @param plugin A HttpPlugin object that contains the HTTP core configuration.
421
+ * @returns The current instance of AppBuilder for method chaining.
422
+ */
423
+ addHttpClient(plugin: HttpPlugin<TRegistry>): this;
1803
424
  /**
1804
425
  * @description Configures the HTTP core settings for the application. This method allows you to set up HTTP core options such as data source token, HTTP client configuration, and resilience settings.
1805
- * @param setupAction A callback function that receives an HttpCoreConfig object to configure the HTTP core settings.
426
+ * @param setupAction A callback function that receives an SetupAction<HttpConfig, IConfigurationService> object to configure the HTTP core settings.
1806
427
  * @returns The current instance of AppBuilder for method chaining.
1807
-
1808
428
  *
1809
429
  * @author Xeno
1810
430
  * @version 1.0.0
1811
431
  * @since 2025-09-30
1812
432
  * @link https://github.com/xeno-js/xeno-js
1813
433
  */
1814
- addHttpCore(setupAction: SetupAction<HttpCoreConfig<TRegistry>, IConfigurationService>): this;
434
+ addHttpClient(setupAction: SetupAction<HttpConfig, IConfigurationService>): this;
1815
435
  /**
1816
436
  * @description Registers services in the application. This method allows you to add custom services to the dependency injection container, enabling modular and organized configuration of services.
1817
437
  * @param setupAction A callback function that receives the IServiceContainer to register services.
@@ -1822,7 +442,7 @@ declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegi
1822
442
  * @since 2025-09-30
1823
443
  * @link https://github.com/xeno-js/xeno-js
1824
444
  */
1825
- addServices(setupAction: SetupAction<IServiceContainer<TRegistry>, IConfigurationService>): this;
445
+ addServices(setupAction: SetupAction<IServiceContainer<TRegistry>, IConfigurationService>, priority?: number): this;
1826
446
  /**
1827
447
  * @description Registers a module in the application. A module is a self-contained unit of functionality that can configure services and dependencies in the service container. This method allows you to add custom modules to the application, enabling modular and organized configuration of services.
1828
448
  * @param factory A factory function that creates the module instance.
@@ -1835,7 +455,7 @@ declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegi
1835
455
  * @since 2025-09-30
1836
456
  * @link https://github.com/xeno-js/xeno-js
1837
457
  */
1838
- addModule<T>(name: string, factory: () => Promise<IModule<TRegistry, T>>, opts?: T): this;
458
+ addModule<T>(name: string, factory: () => Promise<IModule<TRegistry, T>>, opts?: T, priority?: number): this;
1839
459
  /**
1840
460
  * @description Resolves a service from the dependency injection container.
1841
461
  * @param token The injection token used to identify the service.
@@ -1856,93 +476,56 @@ declare class AppBuilder<TRegistry extends ApplicationRegistry = ApplicationRegi
1856
476
  * @since 2025-09-30
1857
477
  * @link https://github.com/xeno-js/xeno-js
1858
478
  */
1859
- build(): Promise<IServiceContainer<TRegistry>>;
479
+ build(): Promise<TApp>;
1860
480
  protected _resetContainer(): Promise<void>;
1861
481
  /**
1862
482
  * @description Executes the build process by initializing all registered modules in the container.
1863
483
  */
1864
484
  private _executeBuild;
1865
- /**
1866
- * @description Queues the configuration of the CQRS pipeline module if it has not already been queued. This method ensures that the pipeline module is only added once, even if multiple pipeline-related configurations are made.
1867
- *
1868
- * @author Xeno
1869
- * @version 1.0.0
1870
- * @since 2025-09-30
1871
- * @link https://github.com/xeno-js/xeno-js
1872
- */
1873
- private _queuePipelineModule;
1874
- /**
1875
- * @description Queues the configuration of the middleware module if it has not already been queued. This method ensures that the middleware module is only added once, even if multiple middleware-related configurations are made.
1876
- *
1877
- * @author Xeno
1878
- * @version 1.0.0
1879
- * @since 2025-09-30
1880
- * @link https://github.com/xeno-js/xeno-js
1881
- */
1882
- private _queueMiddlewareModule;
1883
- /**
1884
- * @description Queues the configuration of the context module if it has not already been queued. This method ensures that the context module is only added once, even if multiple context-related configurations are made.
1885
-
1886
- *
1887
- * @author Xeno
1888
- * @version 1.0.0
1889
- * @since 2025-09-30
1890
- * @link https://github.com/xeno-js/xeno-js
1891
- */
1892
- private _queueContextModule;
1893
485
  }
1894
486
 
1895
487
  /**
1896
- * @description Base HTTP adapter.
488
+ * @description AuthModule is responsible for registering authentication services and
489
+ * the token extractor in the IoC container. If no custom tokenExtractor is provided,
490
+ * it falls back to the default BearerTokenExtractor.
491
+ *
1897
492
  * @author Xeno
1898
- * @version 1.2.1
493
+ * @version 1.0.0
1899
494
  * @since 2025-09-30
1900
495
  * @link https://github.com/xeno-js/xeno-js
1901
496
  */
1902
- declare abstract class BaseHttpAdapter<TReq = ExtendedRequest, TRes = Response> implements IHttpAdapter<TReq, TRes> {
1903
- abstract adapt(req: TReq, res: TRes): XenoWebTransport;
1904
- /**
1905
- * @description Parse the URL from the request.
1906
- * @param rawUrl The raw URL.
1907
- * @param headers The headers.
1908
- * @param queryParams The query parameters.
1909
- * @returns The parsed URL.
1910
- */
1911
- protected parseUrl(rawUrl: string | undefined, headers: Dictionary<Optional<string | string[]>>, queryParams: Optional<Dictionary>): URL;
1912
- /**
1913
- * @description Parses the headers.
1914
- * @param rawHeaders The raw headers.
1915
- * @returns The parsed headers.
1916
- */
1917
- protected parseHeaders(rawHeaders: Dictionary<Optional<string | string[]>>): Headers;
1918
- /**
1919
- * @description Parses the body.
1920
- * @param method The method.
1921
- * @param rawBody The raw body.
1922
- * @returns The parsed body.
1923
- */
1924
- protected parseBody(method: Optional<string>, rawBody: unknown): Optional<RequestInit['body']>;
1925
- /**
1926
- * @description Handles the header change.
1927
- * @param res The response.
1928
- * @param name The name.
1929
- * @param value The value.
1930
- * @param action The action.
1931
- * @param action The action.
1932
- * @returns void
1933
- */
1934
- protected abstract handleHeaderChange(_res: TRes, _name: string, _value: string, _action: 'set' | 'append' | 'delete'): void;
1935
- /**
1936
- * @description Creates the XenoWebTransport.
1937
- * @param url The url.
1938
- * @param method The method.
1939
- * @param headers The headers.
1940
- * @param body The body.
1941
- * @returns The XenoWebTransport.
1942
- */
1943
- protected createXenoWebTransport(url: URL, method: string | undefined, headers: Headers, body?: Optional<unknown>, res?: Optional<TRes>): XenoWebTransport;
497
+ declare class AuthModule<TRegistry extends XenoRegistry = XenoRegistry> implements IModule<TRegistry, AuthModuleOptions<TRegistry>> {
498
+ configure(container: IServiceContainer<TRegistry>, opts: AuthModuleOptions<TRegistry>): Promise<void>;
499
+ private getExtractor;
500
+ }
501
+
502
+ /**
503
+ * @description CacheModule is responsible for registering cache services in the IoC container. Default implementation is in-memory
504
+ *
505
+ * @author Xeno
506
+ * @version 1.0.0
507
+ * @since 2025-09-30
508
+ * @link https://github.com/xeno-js/xeno-js
509
+ */
510
+ declare class CacheModule<TRegistry extends XenoRegistry = XenoRegistry> implements IModule<TRegistry, CacheConfig> {
511
+ configure(container: IServiceContainer<TRegistry>, opts?: CacheConfig): Promise<void>;
512
+ }
513
+
514
+ /**
515
+ * @description ContextModule is responsible for configuring and registering the necessary services and dependencies related to the request context in the application. It sets up the RequestContext service, which provides a way to manage and access contextual information related to a specific request or operation. By registering the RequestContext in the dependency injection container, it enables other parts of the application to easily resolve and utilize its functionality for managing request-specific data and state.
516
+ *
517
+ * @author Xeno
518
+ * @version 1.0.0
519
+ * @since 2025-09-30
520
+ * @link https://github.com/xeno-js/xeno-js
521
+ */
522
+ declare class ContextModule<TRegistry extends XenoRegistry = XenoRegistry> implements IModule<TRegistry, Optional<IRequestContext<RequestContext, TRegistry>>> {
523
+ configure(container: IServiceContainer<TRegistry>, opts?: IRequestContext<RequestContext, TRegistry>): Promise<void>;
524
+ private _getRequestContext;
1944
525
  }
1945
526
 
527
+ interface OptionalUnitOfWork<TTx = unknown> extends IUnitOfWork<TTx>, IDisposable {
528
+ }
1946
529
  /**
1947
530
  * @description The DbModule class is responsible for configuring the database module within the application. It implements the IModule interface, allowing it to be integrated into the application's dependency injection system. The configure method registers a singleton factory for creating an IDbClient instance using the provided configuration options. This design promotes modularity and allows for easy management of database connections and operations throughout the application.
1948
531
  *
@@ -1951,9 +534,92 @@ declare abstract class BaseHttpAdapter<TReq = ExtendedRequest, TRes = Response>
1951
534
  * @since 2025-09-30
1952
535
  * @link https://github.com/xeno-js/xeno-js
1953
536
  */
1954
- declare class DbModule<TRegistry extends ApplicationRegistry<DbContext, DbTransaction>, DbContext extends ITransactionalDb<DbTransaction>, DbTransaction = unknown> implements IModule<TRegistry, DbModuleOptions<DbContext, DbTransaction>> {
1955
- configure(container: IServiceContainer<TRegistry>, opts: DbModuleOptions<DbContext, DbTransaction>): Promise<void>;
537
+ declare class DbModule<TRegistry extends XenoRegistry<DbContext, DbTransaction>, DbContext extends ITransactionalDb<DbTransaction>, DbTransaction = unknown> implements IModule<TRegistry, DbModuleOptions<DbContext, DbTransaction> & {
538
+ uow?: (c: IServiceScope<TRegistry>) => OptionalUnitOfWork<DbContext>;
539
+ }> {
540
+ configure(container: IServiceContainer<TRegistry>, opts: DbModuleOptions<DbContext, DbTransaction> & {
541
+ uow?: (c: IServiceScope<TRegistry>) => OptionalUnitOfWork<DbContext>;
542
+ }): Promise<void>;
543
+ }
544
+
545
+ declare class HttpServerModule<TRegistry extends XenoRegistry = XenoRegistry> implements IModule<TRegistry> {
546
+ configure(container: IServiceContainer<TRegistry>): Promise<void>;
547
+ }
548
+
549
+ /**
550
+ * @description CacheModule is responsible for registering cache services in the IoC container. Default implementation is in-memory
551
+ *
552
+ * @author Xeno
553
+ * @version 1.0.0
554
+ * @since 2025-09-30
555
+ * @link https://github.com/xeno-js/xeno-js
556
+ */
557
+ declare class LoggerModule<TRegistry extends XenoRegistry = XenoRegistry> implements IModule<TRegistry, LoggerConfig<TRegistry> & {
558
+ plugins?: LoggerPlugin<TRegistry>[];
559
+ }> {
560
+ configure(container: IServiceContainer<TRegistry>, opts: LoggerConfig<TRegistry> & {
561
+ builder: IAppBuilder<TRegistry, IXenoApplication<TRegistry>>;
562
+ config: IConfigurationService;
563
+ plugins?: LoggerPlugin<TRegistry>[];
564
+ }): Promise<void>;
565
+ }
566
+
567
+ /**
568
+ * @description Generic plugin to register any custom authentication implementation into Xeno.JS.
569
+ * It delegates the registration to the Core AuthModule.
570
+ *
571
+ * @param configurator Either the AuthModuleOptions object or a factory receiving the configuration service.
572
+ * @returns A XenoPlugin ready to be passed to builder.addAuth(...)
573
+ *
574
+ * @author Xeno
575
+ * @version 1.0.0
576
+ * @since 2025-09-30
577
+ * @link https://github.com/xeno-js/xeno-js
578
+ */
579
+ declare const withAuth: <TRegistry extends XenoRegistry = XenoRegistry>(setup: SetupAction<AuthModuleOptions<TRegistry>, IConfigurationService>) => AuthPlugin<TRegistry>;
580
+
581
+ declare const withAuthZ: <TRegistry extends XenoRegistry = XenoRegistry>(setup: SetupAction<AuthorizationOptions<TRegistry>, IConfigurationService>) => PipelinePlugin<TRegistry>;
582
+
583
+ declare const withConcurrency: <TRegistry extends XenoRegistry = XenoRegistry>(setup?: SetupAction<ConcurrencyOptions, IConfigurationService>) => PipelinePlugin<TRegistry>;
584
+
585
+ declare const definePlugin: <TKind extends string, TRegistry extends XenoRegistry = XenoRegistry, TCtx = unknown>(kind: TKind, fn: (builder: IAppBuilder<TRegistry, IXenoApplication<TRegistry>>, config: IConfigurationService, ctx?: TCtx) => unknown) => XenoPlugin<TKind, TRegistry, TCtx>;
586
+
587
+ /**
588
+ * @description Generic plugin to register any custom authentication implementation into Xeno.JS.
589
+ * It delegates the registration to the Core AuthModule.
590
+ *
591
+ * @param configurator Either the AuthModuleOptions object or a factory receiving the configuration service.
592
+ * @returns A XenoPlugin ready to be passed to builder.addAuth(...)
593
+ *
594
+ * @author Xeno
595
+ * @version 1.0.0
596
+ * @since 2025-09-30
597
+ * @link https://github.com/xeno-js/xeno-js
598
+ */
599
+ declare const withCustomHttp: <TRegistry extends XenoRegistry = XenoRegistry>(config: HttpConfig<TRegistry>) => HttpPlugin<TRegistry>;
600
+
601
+ declare const withIdempotency: <TRegistry extends XenoRegistry = XenoRegistry>(setup?: SetupAction<IdempotencyOptions, IConfigurationService>) => PipelinePlugin<TRegistry>;
602
+
603
+ interface ConsoleOptions {
604
+ isEnabled?: boolean;
605
+ level?: LogLevel;
1956
606
  }
607
+ /**
608
+ * @description Plugin for configuring the logger in the application.
609
+ *
610
+ * @param builder - The application builder instance.
611
+ * @param config - The configuration service instance.
612
+ * @returns void
613
+ *
614
+ * @author Xeno
615
+ */
616
+ declare const withConsoleLogger: <TRegistry extends XenoRegistry = XenoRegistry>(setup: SetupAction<ConsoleOptions, IConfigurationService>) => LoggerPlugin<TRegistry>;
617
+
618
+ declare const withPerformance: <TRegistry extends XenoRegistry = XenoRegistry>(setup?: SetupAction<PerformanceOptions, IConfigurationService>) => PipelinePlugin<TRegistry>;
619
+
620
+ declare const withQueryCaching: <TRegistry extends XenoRegistry = XenoRegistry>() => PipelinePlugin<TRegistry>;
621
+
622
+ declare const withValidation: <TRegistry extends XenoRegistry = XenoRegistry>(setup: SetupAction<IStrategy<IRequest, boolean>[], IConfigurationService>) => PipelinePlugin<TRegistry>;
1957
623
 
1958
624
  /**
1959
625
  * An abstract generic read-only DAO that provides basic read operations for entities of type T, using a Data Transfer Object (DTO) of type TDto for data access. This class relies on an IReadDataSource to perform database operations and an IMapper to convert between entities and DTOs.
@@ -2019,13 +685,33 @@ declare abstract class Repository<T, TDto> implements IRepository<T> {
2019
685
  }
2020
686
 
2021
687
  /**
2022
- * @description The XenoRegistry type is an alias for the ApplicationRegistry specialized with DbContext. It represents the registry of application services and dependencies, specifically tailored for applications that utilize a database context. This type is used throughout the application to ensure consistent typing and to facilitate dependency injection and service resolution.
2023
- * @author Xeno
2024
- * @version 1.0.0
2025
- * @since 2025-09-30
2026
- * @link https://github.com/xeno-js/xeno-js
688
+ * @description Add CORS headers to a route definition.
689
+ * Remember to add CORS middleware to your application during bootstrap.
690
+ *
691
+ * @param route The route to add CORS headers to.
692
+ * @param allowOrigins Array of allowed origins (eg. ['https://example.com'] or ['*']).
693
+ * @param withCredentials Whether to allow credentials. Default: true.
694
+ * @returns The route definition with CORS headers added.
695
+ */
696
+ declare function withCors<TRegistry extends XenoRegistry = XenoRegistry>(route: NativeRouteDefinition<TRegistry>, allowOrigins: string[], withCredentials?: boolean): NativeRouteDefinition<TRegistry>;
697
+ /**
698
+ * @description Disable CSRF protection for a route definition.
699
+ * Use this if you need to allow cross-origin requests without CSRF protection. (eg. for Server to Server or a Webhook)
700
+ *
701
+ * @param route The route to disable CSRF protection for.
702
+ * @returns The route definition with CSRF protection disabled.
703
+ */
704
+ declare function withoutCsrf<TRegistry extends XenoRegistry = XenoRegistry>(route: NativeRouteDefinition<TRegistry>): NativeRouteDefinition<TRegistry>;
705
+ /**
706
+ * @description Allow CSRF protection for a route definition.
707
+ * Remember to add CSRF middleware to your application during bootstrap.
708
+ *
709
+ * (Methods POST/PUT/PATCH/DELETE have a default CSRF protection if you added it during bootstrap, use this function if you want to force it for another method).
710
+ *
711
+ * @param route The route to disable CSRF protection for.
712
+ * @returns The route definition with CSRF protection disabled.
2027
713
  */
2028
- type XenoRegistry<TExtensions = object> = ApplicationRegistry & Readonly<Omit<TExtensions, keyof ApplicationRegistry>>;
714
+ declare function withCsrf<TRegistry extends XenoRegistry = XenoRegistry>(route: NativeRouteDefinition<TRegistry>): NativeRouteDefinition<TRegistry>;
2029
715
 
2030
716
  /**
2031
717
  * BaseController is an abstract class that implements the IController interface. It provides a foundation for creating specific controllers that handle incoming requests and return responses. The class requires a mediator to facilitate communication between different parts of the application.
@@ -2051,7 +737,7 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
2051
737
  * @link https://github.com/xeno-js/xeno-js
2052
738
  */
2053
739
  constructor(_requestContext: IContextAccessor<RequestContext>, _mediator: IMediator);
2054
- abstract handle(request: TRequest, signal: AbortSignal): Promise<ResponseDto<TResponse>>;
740
+ abstract handle(request: TRequest, signal: Optional<AbortSignal>): Promise<ResponseDto<TResponse>>;
2055
741
  /**
2056
742
  * Helper to return a successful 200/201 response.
2057
743
  * @param data - The data to include in the response.
@@ -2091,7 +777,7 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
2091
777
  * @since 2025-09-30
2092
778
  * @link https://github.com/xeno-js/xeno-js
2093
779
  */
2094
- protected _query(request: IQuery<TResponse>, signal: AbortSignal): Promise<ResultType<TResponse>>;
780
+ protected _query(request: IQuery<TResponse>, signal: Optional<AbortSignal>): Promise<ResultType<TResponse>>;
2095
781
  /**
2096
782
  * Helper to send a command through the mediator and return the result.
2097
783
  * @param request - The ICommand instance to be sent.
@@ -2103,8 +789,8 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
2103
789
  * @since 2025-09-30
2104
790
  * @link https://github.com/xeno-js/xeno-js
2105
791
  */
2106
- protected _send(request: ICommand<TResponse>, signal: AbortSignal): Promise<ResultType<TResponse>>;
792
+ protected _send(request: ICommand<TResponse>, signal: Optional<AbortSignal>): Promise<ResultType<TResponse>>;
2107
793
  protected getContext(): Optional<RequestContext>;
2108
794
  }
2109
795
 
2110
- export { AppBuilder, type ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHttpAdapter, ContainerUtils, type CookieHandlerOptions, DbModule, type DbModuleOptions, type ExecutionContext, type HttpAdapterConfig, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, type IAtomicCache, type ICryptoService, type ICsrfTokenService, type IHttpAdapter, type IIPResolver, type IModule, type IRateLimitKeyBuilder, type IRequestContext, type IServiceContainer, type IServiceProvider, type IServiceScope, type IServiceScopeAccessor, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type ITransactionalDb, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, TOKENS, type XenoRegistry, type XenoWebTransport };
796
+ 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 };