@xeno-js/core 2.0.1 → 2.0.2
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.cjs +439 -470
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -41
- package/dist/index.d.ts +2 -41
- package/dist/index.js +42 -74
- package/dist/index.js.map +1 -1
- package/package.json +7 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Optional, RequestContext, HttpMethod, AuthConfig, CookieOptions, IServiceExtractor, IExtendendAuthService, SetupAction, HttpClientConfig, LogLevel, ILoggerClient, Dictionary, AuthPolicy, IStrategy, IRequest, ResponseDto,
|
|
1
|
+
import { Optional, RequestContext, HttpMethod, AuthConfig, CookieOptions, IServiceExtractor, IExtendendAuthService, SetupAction, HttpClientConfig, LogLevel, ILoggerClient, Dictionary, AuthPolicy, IStrategy, IRequest, ResponseDto, IContextAccessor, ResultType, Identity, ISpecification, IConfigurationService, CacheConfig, DbConfig, ExtendedRequest, IReadDao, IReadDataSource, IMapper, UserContext, IRepository, IWriteDataSource, IController, IMediator, AppError, IQuery, ICommand } from '@xeno-js/shared';
|
|
2
2
|
export * from '@xeno-js/shared';
|
|
3
3
|
export { Query } from '@xeno-js/shared';
|
|
4
4
|
import { A as ApplicationRegistry, I as IServiceProvider, a as IServiceScope, b as IServiceContainer, c as IHttpAdapter, X as XenoWebTransport } from './itoken-service.contracts-3GrRvKeZ.cjs';
|
|
@@ -994,45 +994,6 @@ declare const ContainerUtils: Readonly<{
|
|
|
994
994
|
runExecute<TResponse, T extends ApplicationRegistry, TRes, TReq>(res: TRes, req: TReq, container: IServiceContainer<T>, action: () => Promise<ResponseDto<TResponse>>): Promise<ResponseDto<TResponse>>;
|
|
995
995
|
}>;
|
|
996
996
|
|
|
997
|
-
/**
|
|
998
|
-
* BaseHandler is an abstract class that implements the IHandler interface.
|
|
999
|
-
* It provides a base implementation for handling requests and executing strategies.
|
|
1000
|
-
*
|
|
1001
|
-
* @author Xeno
|
|
1002
|
-
* @version 1.0.0
|
|
1003
|
-
* @since 2025-09-30
|
|
1004
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1005
|
-
*/
|
|
1006
|
-
declare abstract class BaseHandler<TRequest extends IRequest<TResponse>, TResponse> implements IHandler<TRequest, TResponse> {
|
|
1007
|
-
private readonly _identityFactory;
|
|
1008
|
-
constructor(_identityFactory: IFactory<void, UserContext>);
|
|
1009
|
-
handle(request: TRequest, signal: AbortSignal): Promise<ResultType<TResponse>>;
|
|
1010
|
-
/**
|
|
1011
|
-
* Executes the strategy for the given request.
|
|
1012
|
-
* @param request - The request to be handled.
|
|
1013
|
-
* @param signal - (Optional) The abort signal for the request.
|
|
1014
|
-
* @throws {AppError} If the strategy execution fails.
|
|
1015
|
-
* @protected - This method should be overridden by subclasses.
|
|
1016
|
-
* @abstract - This method must be implemented by subclasses.
|
|
1017
|
-
* @async - This method is asynchronous.
|
|
1018
|
-
* @template TRequest - The type of the request.
|
|
1019
|
-
* @template TResponse - The type of the response.
|
|
1020
|
-
* @returns {Promise<ResultType<TResponse>>} A promise that resolves to the result of the strategy execution.
|
|
1021
|
-
*
|
|
1022
|
-
* @author Xeno
|
|
1023
|
-
* @version 1.0.0
|
|
1024
|
-
* @since 2025-09-30
|
|
1025
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1026
|
-
*/
|
|
1027
|
-
protected abstract executeAsync(request: TRequest, signal?: Optional<AbortSignal>): Promise<ResultType<TResponse>>;
|
|
1028
|
-
/**
|
|
1029
|
-
* Gets the current context.
|
|
1030
|
-
* @returns {UserContext} The current context.
|
|
1031
|
-
* {@link UserContext}
|
|
1032
|
-
*/
|
|
1033
|
-
protected _getCurrentContext(): UserContext;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
997
|
/**
|
|
1037
998
|
* @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.
|
|
1038
999
|
*
|
|
@@ -1548,4 +1509,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
|
|
|
1548
1509
|
protected getContext(): Optional<RequestContext>;
|
|
1549
1510
|
}
|
|
1550
1511
|
|
|
1551
|
-
export { AppBuilder, ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController,
|
|
1512
|
+
export { AppBuilder, ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHttpAdapter, ContainerUtils, type CookieHandlerOptions, type ExecutionContext, type HttpAdapterConfig, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, IHttpAdapter, type IIPResolver, type IModule, type IRateLimitKeyBuilder, IServiceContainer, IServiceProvider, IServiceScope, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, type XenoRegistry, XenoWebTransport };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Optional, RequestContext, HttpMethod, AuthConfig, CookieOptions, IServiceExtractor, IExtendendAuthService, SetupAction, HttpClientConfig, LogLevel, ILoggerClient, Dictionary, AuthPolicy, IStrategy, IRequest, ResponseDto,
|
|
1
|
+
import { Optional, RequestContext, HttpMethod, AuthConfig, CookieOptions, IServiceExtractor, IExtendendAuthService, SetupAction, HttpClientConfig, LogLevel, ILoggerClient, Dictionary, AuthPolicy, IStrategy, IRequest, ResponseDto, IContextAccessor, ResultType, Identity, ISpecification, IConfigurationService, CacheConfig, DbConfig, ExtendedRequest, IReadDao, IReadDataSource, IMapper, UserContext, IRepository, IWriteDataSource, IController, IMediator, AppError, IQuery, ICommand } from '@xeno-js/shared';
|
|
2
2
|
export * from '@xeno-js/shared';
|
|
3
3
|
export { Query } from '@xeno-js/shared';
|
|
4
4
|
import { A as ApplicationRegistry, I as IServiceProvider, a as IServiceScope, b as IServiceContainer, c as IHttpAdapter, X as XenoWebTransport } from './itoken-service.contracts-3GrRvKeZ.js';
|
|
@@ -994,45 +994,6 @@ declare const ContainerUtils: Readonly<{
|
|
|
994
994
|
runExecute<TResponse, T extends ApplicationRegistry, TRes, TReq>(res: TRes, req: TReq, container: IServiceContainer<T>, action: () => Promise<ResponseDto<TResponse>>): Promise<ResponseDto<TResponse>>;
|
|
995
995
|
}>;
|
|
996
996
|
|
|
997
|
-
/**
|
|
998
|
-
* BaseHandler is an abstract class that implements the IHandler interface.
|
|
999
|
-
* It provides a base implementation for handling requests and executing strategies.
|
|
1000
|
-
*
|
|
1001
|
-
* @author Xeno
|
|
1002
|
-
* @version 1.0.0
|
|
1003
|
-
* @since 2025-09-30
|
|
1004
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1005
|
-
*/
|
|
1006
|
-
declare abstract class BaseHandler<TRequest extends IRequest<TResponse>, TResponse> implements IHandler<TRequest, TResponse> {
|
|
1007
|
-
private readonly _identityFactory;
|
|
1008
|
-
constructor(_identityFactory: IFactory<void, UserContext>);
|
|
1009
|
-
handle(request: TRequest, signal: AbortSignal): Promise<ResultType<TResponse>>;
|
|
1010
|
-
/**
|
|
1011
|
-
* Executes the strategy for the given request.
|
|
1012
|
-
* @param request - The request to be handled.
|
|
1013
|
-
* @param signal - (Optional) The abort signal for the request.
|
|
1014
|
-
* @throws {AppError} If the strategy execution fails.
|
|
1015
|
-
* @protected - This method should be overridden by subclasses.
|
|
1016
|
-
* @abstract - This method must be implemented by subclasses.
|
|
1017
|
-
* @async - This method is asynchronous.
|
|
1018
|
-
* @template TRequest - The type of the request.
|
|
1019
|
-
* @template TResponse - The type of the response.
|
|
1020
|
-
* @returns {Promise<ResultType<TResponse>>} A promise that resolves to the result of the strategy execution.
|
|
1021
|
-
*
|
|
1022
|
-
* @author Xeno
|
|
1023
|
-
* @version 1.0.0
|
|
1024
|
-
* @since 2025-09-30
|
|
1025
|
-
* @link https://github.com/xeno-js/xeno-js
|
|
1026
|
-
*/
|
|
1027
|
-
protected abstract executeAsync(request: TRequest, signal?: Optional<AbortSignal>): Promise<ResultType<TResponse>>;
|
|
1028
|
-
/**
|
|
1029
|
-
* Gets the current context.
|
|
1030
|
-
* @returns {UserContext} The current context.
|
|
1031
|
-
* {@link UserContext}
|
|
1032
|
-
*/
|
|
1033
|
-
protected _getCurrentContext(): UserContext;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
997
|
/**
|
|
1037
998
|
* @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.
|
|
1038
999
|
*
|
|
@@ -1548,4 +1509,4 @@ declare abstract class BaseController<TRequest, TResponse> implements IControlle
|
|
|
1548
1509
|
protected getContext(): Optional<RequestContext>;
|
|
1549
1510
|
}
|
|
1550
1511
|
|
|
1551
|
-
export { AppBuilder, ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController,
|
|
1512
|
+
export { AppBuilder, ApplicationRegistry, type AuthSsrConfig, BaseAuthorizationStrategy, BaseController, BaseHttpAdapter, ContainerUtils, type CookieHandlerOptions, type ExecutionContext, type HttpAdapterConfig, type HttpConfig, type HttpCoreConfig, type IAllowMethod, type IAllowOrigin, IHttpAdapter, type IIPResolver, type IModule, type IRateLimitKeyBuilder, IServiceContainer, IServiceProvider, IServiceScope, type ISsrCookie, type ISsrCookieHandler, type ISsrCookieToSet, type Lifetime, type LoggerConfig, type MiddlewareConfig, type PinoLoggerConfig, type PipelineConfig, ReadDao, Repository, type ResilienceConfig, type SchemaConfig, type SentryLoggerConfig, type ServiceDescriptor, Specification, type XenoRegistry, XenoWebTransport };
|
package/dist/index.js
CHANGED
|
@@ -63,37 +63,8 @@ var init_containers = __esm({
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
-
// src/application/cqrs/base-handler.ts
|
|
67
|
-
import {
|
|
68
|
-
AppError
|
|
69
|
-
} from "@xeno-js/shared";
|
|
70
|
-
var BaseHandler;
|
|
71
|
-
var init_base_handler = __esm({
|
|
72
|
-
"src/application/cqrs/base-handler.ts"() {
|
|
73
|
-
"use strict";
|
|
74
|
-
BaseHandler = class {
|
|
75
|
-
constructor(_identityFactory) {
|
|
76
|
-
this._identityFactory = _identityFactory;
|
|
77
|
-
}
|
|
78
|
-
_identityFactory;
|
|
79
|
-
async handle(request, signal) {
|
|
80
|
-
AppError.throwIfAborted(signal, this.constructor.name);
|
|
81
|
-
return await this.executeAsync(request, signal);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Gets the current context.
|
|
85
|
-
* @returns {UserContext} The current context.
|
|
86
|
-
* {@link UserContext}
|
|
87
|
-
*/
|
|
88
|
-
_getCurrentContext() {
|
|
89
|
-
return this._identityFactory.create();
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
66
|
// src/application/cqrs/mediator.ts
|
|
96
|
-
import { AppError
|
|
67
|
+
import { AppError, Result } from "@xeno-js/shared";
|
|
97
68
|
import { ERROR_CODE_MESSAGES, ERROR_CODES, Guards as Guards2, STATUS_CODES, TOKENS as TOKENS2 } from "@xeno-js/shared";
|
|
98
69
|
var Mediator;
|
|
99
70
|
var init_mediator = __esm({
|
|
@@ -151,11 +122,11 @@ var init_mediator = __esm({
|
|
|
151
122
|
*/
|
|
152
123
|
async process(request, pipelineToken, signal) {
|
|
153
124
|
if (Guards2.isDefined(signal) && signal.aborted)
|
|
154
|
-
return Result.fail(
|
|
125
|
+
return Result.fail(AppError.aborted(request.intent));
|
|
155
126
|
const scope = this._factoryScope.getScope();
|
|
156
127
|
if (!Guards2.isDefined(scope))
|
|
157
128
|
return Result.fail(
|
|
158
|
-
|
|
129
|
+
AppError.create({
|
|
159
130
|
code: ERROR_CODES.SCOPE_NOT_AVAILABLE,
|
|
160
131
|
status: STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
161
132
|
name: request.intent,
|
|
@@ -166,7 +137,7 @@ var init_mediator = __esm({
|
|
|
166
137
|
const pipelines = scope.resolve(pipelineToken);
|
|
167
138
|
if (!Guards2.isDefined(pipelines) || !Guards2.hasMethod(pipelines, "handle")) {
|
|
168
139
|
return Result.fail(
|
|
169
|
-
|
|
140
|
+
AppError.create({
|
|
170
141
|
code: ERROR_CODES.PIPELINE_NOT_AVAILABLE,
|
|
171
142
|
status: STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
172
143
|
name: request.intent,
|
|
@@ -178,7 +149,7 @@ var init_mediator = __esm({
|
|
|
178
149
|
const next = () => {
|
|
179
150
|
const handler = scope.resolve(request.intent);
|
|
180
151
|
if (!Guards2.isDefined(handler) || !Guards2.hasMethod(handler, "handle")) {
|
|
181
|
-
|
|
152
|
+
AppError.throw({
|
|
182
153
|
code: ERROR_CODES.HANDLER_NOT_FOUND,
|
|
183
154
|
status: STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
184
155
|
name: request.intent,
|
|
@@ -260,7 +231,7 @@ var init_composite_pipeline = __esm({
|
|
|
260
231
|
});
|
|
261
232
|
|
|
262
233
|
// src/application/cqrs/pipelines/concurrency-retry.pipeline.ts
|
|
263
|
-
import { AppError as
|
|
234
|
+
import { AppError as AppError2, Result as Result3 } from "@xeno-js/shared";
|
|
264
235
|
import {
|
|
265
236
|
DEFAULT_CONCURRENCY,
|
|
266
237
|
ERROR_CODES as ERROR_CODES2,
|
|
@@ -341,7 +312,7 @@ var init_concurrency_retry_pipeline = __esm({
|
|
|
341
312
|
if (result.isOk() || !this.isConcurrencyError(result.getErrorOrThrow())) return result;
|
|
342
313
|
if (attempts >= this._maxRetries)
|
|
343
314
|
return Result3.fail(
|
|
344
|
-
|
|
315
|
+
AppError2.conflict(
|
|
345
316
|
request.intent,
|
|
346
317
|
`Maximum retry attempts (${this._maxRetries}) exceeded due to concurrency conflicts.`
|
|
347
318
|
)
|
|
@@ -368,7 +339,7 @@ var init_concurrency_retry_pipeline = __esm({
|
|
|
368
339
|
});
|
|
369
340
|
|
|
370
341
|
// src/application/cqrs/pipelines/exception.pipeline.ts
|
|
371
|
-
import { AppError as
|
|
342
|
+
import { AppError as AppError3, Result as Result4 } from "@xeno-js/shared";
|
|
372
343
|
import { ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES2, ERROR_CODES as ERROR_CODES3, STATUS_CODES as STATUS_CODES3 } from "@xeno-js/shared";
|
|
373
344
|
var ExceptionPipeline;
|
|
374
345
|
var init_exception_pipeline = __esm({
|
|
@@ -379,8 +350,8 @@ var init_exception_pipeline = __esm({
|
|
|
379
350
|
try {
|
|
380
351
|
return await next();
|
|
381
352
|
} catch (error) {
|
|
382
|
-
if (error instanceof
|
|
383
|
-
const appError =
|
|
353
|
+
if (error instanceof AppError3) return Result4.fail(error);
|
|
354
|
+
const appError = AppError3.create({
|
|
384
355
|
code: ERROR_CODES3.SYSTEM_ERROR,
|
|
385
356
|
message: ERROR_CODE_MESSAGES2[ERROR_CODES3.SYSTEM_ERROR],
|
|
386
357
|
status: STATUS_CODES3.INTERNAL_SERVER_ERROR,
|
|
@@ -395,7 +366,7 @@ var init_exception_pipeline = __esm({
|
|
|
395
366
|
});
|
|
396
367
|
|
|
397
368
|
// src/application/cqrs/pipelines/idempotency.pipeline.ts
|
|
398
|
-
import { AppError as
|
|
369
|
+
import { AppError as AppError4, Result as Result5 } from "@xeno-js/shared";
|
|
399
370
|
import { Guards as Guards4, IDEMPOTENCY_CONSTANTS } from "@xeno-js/shared";
|
|
400
371
|
var IdempotencyPipeline;
|
|
401
372
|
var init_idempotency_pipeline = __esm({
|
|
@@ -455,7 +426,7 @@ var init_idempotency_pipeline = __esm({
|
|
|
455
426
|
const network = this._requestContextFactory.getNetworkContext();
|
|
456
427
|
if (!Guards4.isDefined(network))
|
|
457
428
|
return Result5.fail(
|
|
458
|
-
|
|
429
|
+
AppError4.conflict(
|
|
459
430
|
request.intent,
|
|
460
431
|
`Network context is not defined for request ${request.intent}`
|
|
461
432
|
)
|
|
@@ -468,7 +439,7 @@ var init_idempotency_pipeline = __esm({
|
|
|
468
439
|
return Result5.ok(payload);
|
|
469
440
|
} else {
|
|
470
441
|
return Result5.fail(
|
|
471
|
-
|
|
442
|
+
AppError4.conflict(
|
|
472
443
|
request.intent,
|
|
473
444
|
`Idempotency store indicates request has been processed but no payload found for request ID ${network.requestId}`
|
|
474
445
|
)
|
|
@@ -481,7 +452,7 @@ var init_idempotency_pipeline = __esm({
|
|
|
481
452
|
);
|
|
482
453
|
if (!lockAcquired) {
|
|
483
454
|
return Result5.fail(
|
|
484
|
-
|
|
455
|
+
AppError4.conflict(
|
|
485
456
|
request.intent,
|
|
486
457
|
`Failed to acquire lock for request ID ${network.requestId}`
|
|
487
458
|
)
|
|
@@ -618,7 +589,7 @@ var init_performance_pipeline = __esm({
|
|
|
618
589
|
});
|
|
619
590
|
|
|
620
591
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/base-authorization.strategy.ts
|
|
621
|
-
import { AppError as
|
|
592
|
+
import { AppError as AppError5, Result as Result6 } from "@xeno-js/shared";
|
|
622
593
|
import { Guards as Guards6 } from "@xeno-js/shared";
|
|
623
594
|
var BaseAuthorizationStrategy;
|
|
624
595
|
var init_base_authorization_strategy = __esm({
|
|
@@ -641,7 +612,7 @@ var init_base_authorization_strategy = __esm({
|
|
|
641
612
|
async execute(request) {
|
|
642
613
|
const context = this._requestContext.getContext();
|
|
643
614
|
if (!Guards6.isDefined(context)) {
|
|
644
|
-
return Result6.fail(
|
|
615
|
+
return Result6.fail(AppError5.unauthorized(request.intent, "User is not authenticated."));
|
|
645
616
|
}
|
|
646
617
|
return await this.performAuthorizationCheck(request, context.identity);
|
|
647
618
|
}
|
|
@@ -650,7 +621,7 @@ var init_base_authorization_strategy = __esm({
|
|
|
650
621
|
});
|
|
651
622
|
|
|
652
623
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/permission-authorization.strategy.ts
|
|
653
|
-
import { AppError as
|
|
624
|
+
import { AppError as AppError6, Result as Result7 } from "@xeno-js/shared";
|
|
654
625
|
import { Guards as Guards7 } from "@xeno-js/shared";
|
|
655
626
|
var PermissionAuthorizationStrategy;
|
|
656
627
|
var init_permission_authorization_strategy = __esm({
|
|
@@ -681,7 +652,7 @@ var init_permission_authorization_strategy = __esm({
|
|
|
681
652
|
);
|
|
682
653
|
if (!hasRequiredPermission)
|
|
683
654
|
return Result7.fail(
|
|
684
|
-
|
|
655
|
+
AppError6.forbidden(command.intent, "User does not have the required permissions.")
|
|
685
656
|
);
|
|
686
657
|
}
|
|
687
658
|
return Result7.ok();
|
|
@@ -691,7 +662,7 @@ var init_permission_authorization_strategy = __esm({
|
|
|
691
662
|
});
|
|
692
663
|
|
|
693
664
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/role-authorization.strategy.ts
|
|
694
|
-
import { AppError as
|
|
665
|
+
import { AppError as AppError7, Result as Result8 } from "@xeno-js/shared";
|
|
695
666
|
import { Guards as Guards8 } from "@xeno-js/shared";
|
|
696
667
|
var RoleAuthorizationStrategy;
|
|
697
668
|
var init_role_authorization_strategy = __esm({
|
|
@@ -719,7 +690,7 @@ var init_role_authorization_strategy = __esm({
|
|
|
719
690
|
const hasRequiredRole = policy.roles?.some((role) => roles.includes(role));
|
|
720
691
|
if (!hasRequiredRole)
|
|
721
692
|
return Result8.fail(
|
|
722
|
-
|
|
693
|
+
AppError7.forbidden(command.intent, "User does not have the required roles.")
|
|
723
694
|
);
|
|
724
695
|
}
|
|
725
696
|
return Result8.ok();
|
|
@@ -729,7 +700,7 @@ var init_role_authorization_strategy = __esm({
|
|
|
729
700
|
});
|
|
730
701
|
|
|
731
702
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/tenant-authorization.strategy.ts
|
|
732
|
-
import { AppError as
|
|
703
|
+
import { AppError as AppError8, Result as Result9 } from "@xeno-js/shared";
|
|
733
704
|
import { Guards as Guards9, GuidHelper } from "@xeno-js/shared";
|
|
734
705
|
var TenantAuthorizationStrategy;
|
|
735
706
|
var init_tenant_authorization_strategy = __esm({
|
|
@@ -754,7 +725,7 @@ var init_tenant_authorization_strategy = __esm({
|
|
|
754
725
|
const policy = this._policy.getPolicy(command.intent);
|
|
755
726
|
if (Guards9.isDefined(policy?.tenantId)) {
|
|
756
727
|
if (Guards9.isNullOrEmpty(auth.tenantId) || !GuidHelper.isValidGuid(auth.tenantId))
|
|
757
|
-
return Result9.fail(
|
|
728
|
+
return Result9.fail(AppError8.unauthorized(command.intent, "Tenant is not authenticated."));
|
|
758
729
|
}
|
|
759
730
|
return Result9.ok();
|
|
760
731
|
}
|
|
@@ -763,7 +734,7 @@ var init_tenant_authorization_strategy = __esm({
|
|
|
763
734
|
});
|
|
764
735
|
|
|
765
736
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/user-authorization.strategy.ts
|
|
766
|
-
import { AppError as
|
|
737
|
+
import { AppError as AppError9, Result as Result10 } from "@xeno-js/shared";
|
|
767
738
|
import { Guards as Guards10, GuidHelper as GuidHelper2 } from "@xeno-js/shared";
|
|
768
739
|
var UserAuthorizationStrategy;
|
|
769
740
|
var init_user_authorization_strategy = __esm({
|
|
@@ -788,7 +759,7 @@ var init_user_authorization_strategy = __esm({
|
|
|
788
759
|
const policy = this._policy.getPolicy(command.intent);
|
|
789
760
|
if (Guards10.isDefined(policy?.userId)) {
|
|
790
761
|
if (Guards10.isNullOrEmpty(auth.userId) || !GuidHelper2.isValidGuid(auth.userId))
|
|
791
|
-
return Result10.fail(
|
|
762
|
+
return Result10.fail(AppError9.unauthorized(command.intent, "User is not authenticated."));
|
|
792
763
|
}
|
|
793
764
|
return Result10.ok();
|
|
794
765
|
}
|
|
@@ -809,7 +780,7 @@ var init_auth = __esm({
|
|
|
809
780
|
});
|
|
810
781
|
|
|
811
782
|
// src/application/cqrs/pipelines/pipeline_strategies/validation/schema-validation.strategy.ts
|
|
812
|
-
import { AppError as
|
|
783
|
+
import { AppError as AppError10, Result as Result11 } from "@xeno-js/shared";
|
|
813
784
|
var SchemaValidationStrategy;
|
|
814
785
|
var init_schema_validation_strategy = __esm({
|
|
815
786
|
"src/application/cqrs/pipelines/pipeline_strategies/validation/schema-validation.strategy.ts"() {
|
|
@@ -833,7 +804,7 @@ var init_schema_validation_strategy = __esm({
|
|
|
833
804
|
const parseResult = await this._validator.validate(key, request);
|
|
834
805
|
if (!parseResult.isOk())
|
|
835
806
|
return Result11.fail(
|
|
836
|
-
|
|
807
|
+
AppError10.validationError(
|
|
837
808
|
request.intent,
|
|
838
809
|
`Validation failed: ${parseResult.getErrorOrThrow().message}`
|
|
839
810
|
)
|
|
@@ -979,7 +950,6 @@ var init_pipelines = __esm({
|
|
|
979
950
|
var init_cqrs = __esm({
|
|
980
951
|
"src/application/cqrs/index.ts"() {
|
|
981
952
|
"use strict";
|
|
982
|
-
init_base_handler();
|
|
983
953
|
init_mediator();
|
|
984
954
|
init_pipelines();
|
|
985
955
|
}
|
|
@@ -1220,7 +1190,6 @@ var application_exports = {};
|
|
|
1220
1190
|
__export(application_exports, {
|
|
1221
1191
|
AuthorizationPipeline: () => AuthorizationPipeline,
|
|
1222
1192
|
BaseAuthorizationStrategy: () => BaseAuthorizationStrategy,
|
|
1223
|
-
BaseHandler: () => BaseHandler,
|
|
1224
1193
|
ClaimsIdentityMapper: () => ClaimsIdentityMapper,
|
|
1225
1194
|
CompositePipeline: () => CompositePipeline,
|
|
1226
1195
|
ConcurrencyRetryPipeline: () => ConcurrencyRetryPipeline,
|
|
@@ -1926,7 +1895,7 @@ var init_extractors = __esm({
|
|
|
1926
1895
|
});
|
|
1927
1896
|
|
|
1928
1897
|
// src/infrastructure/services/resiliences/resilience.service.ts
|
|
1929
|
-
import { AppError as
|
|
1898
|
+
import { AppError as AppError11 } from "@xeno-js/shared";
|
|
1930
1899
|
var ServiceResilience;
|
|
1931
1900
|
var init_resilience_service = __esm({
|
|
1932
1901
|
"src/infrastructure/services/resiliences/resilience.service.ts"() {
|
|
@@ -1937,7 +1906,7 @@ var init_resilience_service = __esm({
|
|
|
1937
1906
|
}
|
|
1938
1907
|
policy;
|
|
1939
1908
|
async execute(operation, signal) {
|
|
1940
|
-
|
|
1909
|
+
AppError11.throwIfAborted(signal, "ServiceResilience.execute");
|
|
1941
1910
|
return this.policy.execute(() => operation(), signal);
|
|
1942
1911
|
}
|
|
1943
1912
|
};
|
|
@@ -2613,7 +2582,7 @@ var unit_of_work_exports = {};
|
|
|
2613
2582
|
__export(unit_of_work_exports, {
|
|
2614
2583
|
UnitOfWork: () => UnitOfWork
|
|
2615
2584
|
});
|
|
2616
|
-
import { AppError as
|
|
2585
|
+
import { AppError as AppError12 } from "@xeno-js/shared";
|
|
2617
2586
|
import { Guards as Guards28 } from "@xeno-js/shared";
|
|
2618
2587
|
var UnitOfWork;
|
|
2619
2588
|
var init_unit_of_work = __esm({
|
|
@@ -2637,7 +2606,7 @@ var init_unit_of_work = __esm({
|
|
|
2637
2606
|
_dbContext;
|
|
2638
2607
|
_ttx;
|
|
2639
2608
|
async runInTransaction(callback, signal) {
|
|
2640
|
-
|
|
2609
|
+
AppError12.throwIfAborted(signal, "UnitOfWork.runInTransaction");
|
|
2641
2610
|
return this._dbContext.transaction(async (tx) => {
|
|
2642
2611
|
this._ttx.state = tx;
|
|
2643
2612
|
try {
|
|
@@ -3008,7 +2977,7 @@ var cockatiel_resilience_factory_exports = {};
|
|
|
3008
2977
|
__export(cockatiel_resilience_factory_exports, {
|
|
3009
2978
|
CockatielResilienceFactory: () => CockatielResilienceFactory
|
|
3010
2979
|
});
|
|
3011
|
-
import { AppError as
|
|
2980
|
+
import { AppError as AppError13, Guards as Guards33, RESILIENCE_DEFAULTS } from "@xeno-js/shared";
|
|
3012
2981
|
import {
|
|
3013
2982
|
bulkhead,
|
|
3014
2983
|
circuitBreaker,
|
|
@@ -3088,7 +3057,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
3088
3057
|
if (!Guards33.isDefined(error) || !Guards33.isObject(error)) return false;
|
|
3089
3058
|
let status;
|
|
3090
3059
|
let isNetworkError = false;
|
|
3091
|
-
if (error instanceof
|
|
3060
|
+
if (error instanceof AppError13) {
|
|
3092
3061
|
status = error.status;
|
|
3093
3062
|
const cause = error.cause;
|
|
3094
3063
|
if (Guards33.isDefined(cause) && Guards33.isString(cause.code)) {
|
|
@@ -3120,7 +3089,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
3120
3089
|
isTransientAndIdempotent(error) {
|
|
3121
3090
|
if (!this.isTransientError(error)) return false;
|
|
3122
3091
|
let method;
|
|
3123
|
-
if (error instanceof
|
|
3092
|
+
if (error instanceof AppError13) {
|
|
3124
3093
|
const cause = error.cause;
|
|
3125
3094
|
if (Guards33.isDefined(cause) && Guards33.isDefined(cause.config) && Guards33.isString(cause.config.method)) {
|
|
3126
3095
|
method = cause.config.method.toUpperCase();
|
|
@@ -5486,7 +5455,7 @@ var AppBuilder = class {
|
|
|
5486
5455
|
init_base_http_adapter();
|
|
5487
5456
|
|
|
5488
5457
|
// src/infrastructure/repositories/read-dao.ts
|
|
5489
|
-
import { AppError as
|
|
5458
|
+
import { AppError as AppError14, Result as Result16 } from "@xeno-js/shared";
|
|
5490
5459
|
import { Guards as Guards49 } from "@xeno-js/shared";
|
|
5491
5460
|
var ReadDao = class {
|
|
5492
5461
|
/**
|
|
@@ -5507,14 +5476,14 @@ var ReadDao = class {
|
|
|
5507
5476
|
_dataSource;
|
|
5508
5477
|
_mapper;
|
|
5509
5478
|
async findById(id, ctx, signal) {
|
|
5510
|
-
|
|
5479
|
+
AppError14.throwIfAborted(signal, "ReadDao.findById");
|
|
5511
5480
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5512
5481
|
if (Guards49.isNullOrEmpty(result)) return Result16.ok();
|
|
5513
5482
|
const entity = this._mapper.toEntity(result);
|
|
5514
5483
|
return Result16.ok(entity);
|
|
5515
5484
|
}
|
|
5516
5485
|
async findAll(ctx, signal) {
|
|
5517
|
-
|
|
5486
|
+
AppError14.throwIfAborted(signal, "ReadDao.findAll");
|
|
5518
5487
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5519
5488
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5520
5489
|
return Result16.ok(entities);
|
|
@@ -5522,7 +5491,7 @@ var ReadDao = class {
|
|
|
5522
5491
|
};
|
|
5523
5492
|
|
|
5524
5493
|
// src/infrastructure/repositories/repository.ts
|
|
5525
|
-
import { AppError as
|
|
5494
|
+
import { AppError as AppError15, Result as Result17 } from "@xeno-js/shared";
|
|
5526
5495
|
import { Guards as Guards50 } from "@xeno-js/shared";
|
|
5527
5496
|
var Repository = class {
|
|
5528
5497
|
/**
|
|
@@ -5543,33 +5512,33 @@ var Repository = class {
|
|
|
5543
5512
|
_dataSource;
|
|
5544
5513
|
_mapper;
|
|
5545
5514
|
async findById(id, ctx, signal) {
|
|
5546
|
-
|
|
5515
|
+
AppError15.throwIfAborted(signal, "Repository.findById");
|
|
5547
5516
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5548
5517
|
if (Guards50.isNullOrEmpty(result)) return Result17.ok();
|
|
5549
5518
|
const entity = this._mapper.toEntity(result);
|
|
5550
5519
|
return Result17.ok(entity);
|
|
5551
5520
|
}
|
|
5552
5521
|
async findAll(ctx, signal) {
|
|
5553
|
-
|
|
5522
|
+
AppError15.throwIfAborted(signal, "Repository.findAll");
|
|
5554
5523
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5555
5524
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5556
5525
|
return Result17.ok(entities);
|
|
5557
5526
|
}
|
|
5558
5527
|
async save(entity, signal) {
|
|
5559
5528
|
const dto = this._mapper.toDto(entity);
|
|
5560
|
-
|
|
5529
|
+
AppError15.throwIfAborted(signal, "Repository.save");
|
|
5561
5530
|
await this._dataSource.insert(dto, signal);
|
|
5562
5531
|
return Result17.ok();
|
|
5563
5532
|
}
|
|
5564
5533
|
async delete(entity, ctx, signal) {
|
|
5565
5534
|
const dto = this._mapper.toDto(entity);
|
|
5566
|
-
|
|
5535
|
+
AppError15.throwIfAborted(signal, "Repository.delete");
|
|
5567
5536
|
await this._dataSource.delete(dto, ctx, signal);
|
|
5568
5537
|
return Result17.ok();
|
|
5569
5538
|
}
|
|
5570
5539
|
async update(id, entity, ctx, signal) {
|
|
5571
5540
|
const dto = this._mapper.toPartialDto(entity);
|
|
5572
|
-
|
|
5541
|
+
AppError15.throwIfAborted(signal, "Repository.update");
|
|
5573
5542
|
await this._dataSource.update(id, dto, ctx, signal);
|
|
5574
5543
|
return Result17.ok();
|
|
5575
5544
|
}
|
|
@@ -5583,7 +5552,6 @@ export {
|
|
|
5583
5552
|
AppBuilder,
|
|
5584
5553
|
BaseAuthorizationStrategy,
|
|
5585
5554
|
BaseController,
|
|
5586
|
-
BaseHandler,
|
|
5587
5555
|
BaseHttpAdapter,
|
|
5588
5556
|
ContainerUtils,
|
|
5589
5557
|
Query,
|