@xeno-js/core 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +274 -205
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +158 -89
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2689,8 +2689,8 @@ var init_auth_utils = __esm({
|
|
|
2689
2689
|
async addAuthZ(container, opts) {
|
|
2690
2690
|
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2691
2691
|
const strategies = [];
|
|
2692
|
-
const { Guards:
|
|
2693
|
-
if (
|
|
2692
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
2693
|
+
if (Guards51.isDefined(opts.policies)) {
|
|
2694
2694
|
const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2695
2695
|
const policyRegistry = opts.policies;
|
|
2696
2696
|
const registryInstance = new PolicyRegistry2();
|
|
@@ -2699,16 +2699,16 @@ var init_auth_utils = __esm({
|
|
|
2699
2699
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2700
2700
|
const intentLower = intent.toLowerCase();
|
|
2701
2701
|
registryInstance.addPolicy(intentLower, policy);
|
|
2702
|
-
if (!
|
|
2702
|
+
if (!Guards51.isNullOrEmpty(policy.roles)) {
|
|
2703
2703
|
Policies.add("roles");
|
|
2704
2704
|
}
|
|
2705
|
-
if (!
|
|
2705
|
+
if (!Guards51.isNullOrEmpty(policy.permissions)) {
|
|
2706
2706
|
Policies.add("permissions");
|
|
2707
2707
|
}
|
|
2708
|
-
if (!
|
|
2708
|
+
if (!Guards51.isNullOrEmpty(policy.userId)) {
|
|
2709
2709
|
Policies.add("userId");
|
|
2710
2710
|
}
|
|
2711
|
-
if (!
|
|
2711
|
+
if (!Guards51.isNullOrEmpty(policy.tenantId)) {
|
|
2712
2712
|
Policies.add("tenantId");
|
|
2713
2713
|
}
|
|
2714
2714
|
}
|
|
@@ -2729,10 +2729,10 @@ var init_auth_utils = __esm({
|
|
|
2729
2729
|
strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2730
2730
|
}
|
|
2731
2731
|
}
|
|
2732
|
-
if (!
|
|
2732
|
+
if (!Guards51.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2733
2733
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2734
2734
|
customStrategies.forEach((strategyToken) => {
|
|
2735
|
-
if (
|
|
2735
|
+
if (Guards51.isDefined(strategyToken)) {
|
|
2736
2736
|
strategies.push(strategyToken(container));
|
|
2737
2737
|
}
|
|
2738
2738
|
});
|
|
@@ -2752,8 +2752,8 @@ var init_auth_utils = __esm({
|
|
|
2752
2752
|
* @link https://github.com/xeno-js/xeno-js
|
|
2753
2753
|
*/
|
|
2754
2754
|
async addAuthN(container, opts) {
|
|
2755
|
-
const { Guards:
|
|
2756
|
-
if (
|
|
2755
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2756
|
+
if (Guards51.isDefined(opts.customAuth)) {
|
|
2757
2757
|
const authService = opts.customAuth.authExtendedService();
|
|
2758
2758
|
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2759
2759
|
return authService;
|
|
@@ -2798,12 +2798,12 @@ var init_validation_utils = __esm({
|
|
|
2798
2798
|
* @link https://github.com/xeno-js/xeno-js
|
|
2799
2799
|
*/
|
|
2800
2800
|
async addValidation(container, opts, logger) {
|
|
2801
|
-
const { Guards:
|
|
2802
|
-
if (!
|
|
2801
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2802
|
+
if (!Guards51.isDefined(opts.zod) && Guards51.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
2803
2803
|
return;
|
|
2804
2804
|
}
|
|
2805
2805
|
const validationStrategies = [];
|
|
2806
|
-
if (
|
|
2806
|
+
if (Guards51.isDefined(opts.zod)) {
|
|
2807
2807
|
const config = opts.zod;
|
|
2808
2808
|
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2809
2809
|
const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
@@ -2811,9 +2811,9 @@ var init_validation_utils = __esm({
|
|
|
2811
2811
|
container.addSingleton(TOKENS5.VALIDATOR_SERVICE, () => validatorService);
|
|
2812
2812
|
validationStrategies.push(new SchemaValidationStrategy2(validatorService));
|
|
2813
2813
|
}
|
|
2814
|
-
if (!
|
|
2814
|
+
if (!Guards51.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
2815
2815
|
for (const strategyToken of opts.customValidationStrategy) {
|
|
2816
|
-
if (
|
|
2816
|
+
if (Guards51.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
|
|
2817
2817
|
}
|
|
2818
2818
|
}
|
|
2819
2819
|
const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
@@ -2913,9 +2913,9 @@ var init_pipeline_utils = __esm({
|
|
|
2913
2913
|
* @link https://github.com/xeno-js/xeno-js
|
|
2914
2914
|
*/
|
|
2915
2915
|
async addCommand(container, opts) {
|
|
2916
|
-
const { Guards:
|
|
2916
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2917
2917
|
const pipelines = [];
|
|
2918
|
-
if (
|
|
2918
|
+
if (Guards51.isDefined(opts.idempotency)) {
|
|
2919
2919
|
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
|
|
2920
2920
|
const imdStore = new IdempotencyStore2(
|
|
2921
2921
|
container.resolve(TOKENS5.CACHE),
|
|
@@ -2933,7 +2933,7 @@ var init_pipeline_utils = __esm({
|
|
|
2933
2933
|
)
|
|
2934
2934
|
);
|
|
2935
2935
|
}
|
|
2936
|
-
if (
|
|
2936
|
+
if (Guards51.isDefined(opts.concurrency)) {
|
|
2937
2937
|
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2938
2938
|
const config = opts.concurrency;
|
|
2939
2939
|
pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
|
|
@@ -2990,24 +2990,24 @@ var init_cqrs_module = __esm({
|
|
|
2990
2990
|
new LoggingPipeline2(logger),
|
|
2991
2991
|
new PerformancePipeline2(logger, thresholdMs)
|
|
2992
2992
|
];
|
|
2993
|
-
const { Guards:
|
|
2994
|
-
if (
|
|
2993
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
2994
|
+
if (Guards51.isDefined(opts.authorization.policies) || Guards51.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
2995
2995
|
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
2996
2996
|
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
2997
2997
|
pipelines.push(authPipelines);
|
|
2998
2998
|
}
|
|
2999
|
-
if (
|
|
2999
|
+
if (Guards51.isDefined(opts.validation.zod) || Guards51.isDefined(opts.validation.customValidationStrategy)) {
|
|
3000
3000
|
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
3001
3001
|
const validationPipelines = await ValidationUtils2.addValidation(
|
|
3002
3002
|
container,
|
|
3003
3003
|
opts.validation,
|
|
3004
3004
|
logger
|
|
3005
3005
|
);
|
|
3006
|
-
if (
|
|
3006
|
+
if (Guards51.isDefined(validationPipelines)) pipelines.push(validationPipelines);
|
|
3007
3007
|
}
|
|
3008
3008
|
const commandPipelines = [...pipelines];
|
|
3009
3009
|
const queryPipelines = [...pipelines];
|
|
3010
|
-
if (
|
|
3010
|
+
if (Guards51.isDefined(opts.commandBus.idempotency) || Guards51.isDefined(opts.commandBus.concurrency)) {
|
|
3011
3011
|
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3012
3012
|
const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
|
|
3013
3013
|
commandPipelines.push(...newCommandPipelines);
|
|
@@ -3176,7 +3176,7 @@ var init_db_module = __esm({
|
|
|
3176
3176
|
"use strict";
|
|
3177
3177
|
DbModule = class {
|
|
3178
3178
|
async configure(container, opts) {
|
|
3179
|
-
const { Guards:
|
|
3179
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3180
3180
|
const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
|
|
3181
3181
|
const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
|
|
3182
3182
|
const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
|
|
@@ -3193,7 +3193,7 @@ var init_db_module = __esm({
|
|
|
3193
3193
|
return new Proxy(db, {
|
|
3194
3194
|
get(_target, prop, receiver) {
|
|
3195
3195
|
const activeState = ttx.state;
|
|
3196
|
-
if (
|
|
3196
|
+
if (Guards51.isDefined(activeState)) {
|
|
3197
3197
|
if (prop === "transaction") {
|
|
3198
3198
|
return activeState.transaction.bind(activeState);
|
|
3199
3199
|
}
|
|
@@ -3278,7 +3278,7 @@ var init_base_http_adapter = __esm({
|
|
|
3278
3278
|
* @param body The body.
|
|
3279
3279
|
* @returns The XenoWebTransport.
|
|
3280
3280
|
*/
|
|
3281
|
-
createXenoWebTransport(url, method = "GET", headers, body = void 0) {
|
|
3281
|
+
createXenoWebTransport(url, method = "GET", headers, body = void 0, res = void 0) {
|
|
3282
3282
|
const init2 = {
|
|
3283
3283
|
method: method.toUpperCase(),
|
|
3284
3284
|
headers
|
|
@@ -3290,9 +3290,27 @@ var init_base_http_adapter = __esm({
|
|
|
3290
3290
|
}
|
|
3291
3291
|
const extendedRequest = new Request(url, init2);
|
|
3292
3292
|
extendedRequest.path = url.pathname;
|
|
3293
|
+
const webResponse = new Response();
|
|
3294
|
+
if (import_shared60.Guards.isDefined(res)) {
|
|
3295
|
+
const originalAppend = webResponse.headers.append.bind(webResponse.headers);
|
|
3296
|
+
const originalSet = webResponse.headers.set.bind(webResponse.headers);
|
|
3297
|
+
const originalDelete = webResponse.headers.delete.bind(webResponse.headers);
|
|
3298
|
+
webResponse.headers.append = (name, value) => {
|
|
3299
|
+
originalAppend(name, value);
|
|
3300
|
+
this.handleHeaderChange(res, name, value, "append");
|
|
3301
|
+
};
|
|
3302
|
+
webResponse.headers.set = (name, value) => {
|
|
3303
|
+
originalSet(name, value);
|
|
3304
|
+
this.handleHeaderChange(res, name, value, "set");
|
|
3305
|
+
};
|
|
3306
|
+
webResponse.headers.delete = (name) => {
|
|
3307
|
+
originalDelete(name);
|
|
3308
|
+
this.handleHeaderChange(res, name, "", "delete");
|
|
3309
|
+
};
|
|
3310
|
+
}
|
|
3293
3311
|
return {
|
|
3294
3312
|
request: extendedRequest,
|
|
3295
|
-
response:
|
|
3313
|
+
response: webResponse
|
|
3296
3314
|
};
|
|
3297
3315
|
}
|
|
3298
3316
|
};
|
|
@@ -3300,10 +3318,11 @@ var init_base_http_adapter = __esm({
|
|
|
3300
3318
|
});
|
|
3301
3319
|
|
|
3302
3320
|
// src/infrastructure/http/fastify.http-adapter.ts
|
|
3303
|
-
var FastifyHttpAdapter;
|
|
3321
|
+
var import_shared61, FastifyHttpAdapter;
|
|
3304
3322
|
var init_fastify_http_adapter = __esm({
|
|
3305
3323
|
"src/infrastructure/http/fastify.http-adapter.ts"() {
|
|
3306
3324
|
"use strict";
|
|
3325
|
+
import_shared61 = require("@xeno-js/shared");
|
|
3307
3326
|
init_base_http_adapter();
|
|
3308
3327
|
FastifyHttpAdapter = class extends BaseHttpAdapter {
|
|
3309
3328
|
adapt(req, _res) {
|
|
@@ -3312,6 +3331,29 @@ var init_fastify_http_adapter = __esm({
|
|
|
3312
3331
|
const body = req.body;
|
|
3313
3332
|
return this.createXenoWebTransport(url, req.method, headers, body);
|
|
3314
3333
|
}
|
|
3334
|
+
handleHeaderChange(res, name, value, action) {
|
|
3335
|
+
if (action === "delete") {
|
|
3336
|
+
res.removeHeader(name);
|
|
3337
|
+
return;
|
|
3338
|
+
}
|
|
3339
|
+
if (name.toLowerCase() === "set-cookie") {
|
|
3340
|
+
const existing = res.getHeader("set-cookie");
|
|
3341
|
+
let cookies = [];
|
|
3342
|
+
if (import_shared61.Guards.isArray(existing)) {
|
|
3343
|
+
cookies = existing;
|
|
3344
|
+
} else if (import_shared61.Guards.isString(existing)) {
|
|
3345
|
+
cookies = [existing];
|
|
3346
|
+
}
|
|
3347
|
+
if (action === "append") {
|
|
3348
|
+
cookies.push(value);
|
|
3349
|
+
} else {
|
|
3350
|
+
cookies = [value];
|
|
3351
|
+
}
|
|
3352
|
+
res.header("set-cookie", cookies);
|
|
3353
|
+
} else {
|
|
3354
|
+
res.header(name, value);
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3315
3357
|
};
|
|
3316
3358
|
}
|
|
3317
3359
|
});
|
|
@@ -3331,15 +3373,19 @@ var init_native_http_adapter = __esm({
|
|
|
3331
3373
|
response: res
|
|
3332
3374
|
};
|
|
3333
3375
|
}
|
|
3376
|
+
handleHeaderChange(_res, _name, _value, _action) {
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3334
3379
|
};
|
|
3335
3380
|
}
|
|
3336
3381
|
});
|
|
3337
3382
|
|
|
3338
3383
|
// src/infrastructure/http/vercel.http-adapter.ts
|
|
3339
|
-
var VercelHttpAdapter;
|
|
3384
|
+
var import_shared62, VercelHttpAdapter;
|
|
3340
3385
|
var init_vercel_http_adapter = __esm({
|
|
3341
3386
|
"src/infrastructure/http/vercel.http-adapter.ts"() {
|
|
3342
3387
|
"use strict";
|
|
3388
|
+
import_shared62 = require("@xeno-js/shared");
|
|
3343
3389
|
init_base_http_adapter();
|
|
3344
3390
|
VercelHttpAdapter = class extends BaseHttpAdapter {
|
|
3345
3391
|
adapt(req, _res) {
|
|
@@ -3347,6 +3393,29 @@ var init_vercel_http_adapter = __esm({
|
|
|
3347
3393
|
const url = this.parseUrl(req.url, req.headers, req.query);
|
|
3348
3394
|
return this.createXenoWebTransport(url, req.method, headers, req.body);
|
|
3349
3395
|
}
|
|
3396
|
+
handleHeaderChange(res, name, value, action) {
|
|
3397
|
+
if (action === "delete") {
|
|
3398
|
+
res.removeHeader(name);
|
|
3399
|
+
return;
|
|
3400
|
+
}
|
|
3401
|
+
if (name.toLowerCase() === "set-cookie") {
|
|
3402
|
+
const existing = res.getHeader("Set-Cookie");
|
|
3403
|
+
let cookies = [];
|
|
3404
|
+
if (import_shared62.Guards.isArray(existing)) {
|
|
3405
|
+
cookies = existing;
|
|
3406
|
+
} else if (import_shared62.Guards.isString(existing)) {
|
|
3407
|
+
cookies = [existing];
|
|
3408
|
+
}
|
|
3409
|
+
if (action === "append") {
|
|
3410
|
+
cookies.push(value);
|
|
3411
|
+
} else {
|
|
3412
|
+
cookies = [value];
|
|
3413
|
+
}
|
|
3414
|
+
res.setHeader("Set-Cookie", cookies);
|
|
3415
|
+
} else {
|
|
3416
|
+
res.setHeader(name, value);
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3350
3419
|
};
|
|
3351
3420
|
}
|
|
3352
3421
|
});
|
|
@@ -3370,11 +3439,11 @@ var init_http = __esm({
|
|
|
3370
3439
|
});
|
|
3371
3440
|
|
|
3372
3441
|
// src/infrastructure/modules/http-adapter.module.ts
|
|
3373
|
-
var
|
|
3442
|
+
var import_shared63, HttpAdapterModule;
|
|
3374
3443
|
var init_http_adapter_module = __esm({
|
|
3375
3444
|
"src/infrastructure/modules/http-adapter.module.ts"() {
|
|
3376
3445
|
"use strict";
|
|
3377
|
-
|
|
3446
|
+
import_shared63 = require("@xeno-js/shared");
|
|
3378
3447
|
HttpAdapterModule = class {
|
|
3379
3448
|
async configure(container, opts) {
|
|
3380
3449
|
const adapter = await this._getAdapter(opts);
|
|
@@ -3387,7 +3456,7 @@ var init_http_adapter_module = __esm({
|
|
|
3387
3456
|
} else if (opts.fastify) {
|
|
3388
3457
|
const { FastifyHttpAdapter: FastifyHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
3389
3458
|
return new FastifyHttpAdapter2();
|
|
3390
|
-
} else if (
|
|
3459
|
+
} else if (import_shared63.Guards.isDefined(opts.custom)) {
|
|
3391
3460
|
return opts.custom();
|
|
3392
3461
|
} else {
|
|
3393
3462
|
const { NativeHttpAdapter: NativeHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
@@ -3420,14 +3489,14 @@ var init_http_utils = __esm({
|
|
|
3420
3489
|
*/
|
|
3421
3490
|
async addAxios(container, opts) {
|
|
3422
3491
|
const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3423
|
-
const { Guards:
|
|
3424
|
-
if (!
|
|
3492
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
3493
|
+
if (!Guards51.isDefined(opts.token)) {
|
|
3425
3494
|
throw new Error("HttpConfig.token is required and must be defined.");
|
|
3426
3495
|
}
|
|
3427
3496
|
container.addSingleton(opts.token, () => {
|
|
3428
3497
|
const factory = new NodeAxiosFactory2();
|
|
3429
3498
|
const instance = factory.create(opts.client);
|
|
3430
|
-
if (!
|
|
3499
|
+
if (!Guards51.hasMethod(instance, "get") || !Guards51.hasMethod(instance, "post") || !Guards51.hasMethod(instance, "put") || !Guards51.hasMethod(instance, "patch") || !Guards51.hasMethod(instance, "delete")) {
|
|
3431
3500
|
throw new Error(
|
|
3432
3501
|
"The created HTTP client instance does not implement the required methods of IHttpClient."
|
|
3433
3502
|
);
|
|
@@ -3477,11 +3546,11 @@ var init_http_core_module = __esm({
|
|
|
3477
3546
|
});
|
|
3478
3547
|
|
|
3479
3548
|
// src/presentation/controllers/base.controller.ts
|
|
3480
|
-
var
|
|
3549
|
+
var import_shared64, BaseController;
|
|
3481
3550
|
var init_base_controller = __esm({
|
|
3482
3551
|
"src/presentation/controllers/base.controller.ts"() {
|
|
3483
3552
|
"use strict";
|
|
3484
|
-
|
|
3553
|
+
import_shared64 = require("@xeno-js/shared");
|
|
3485
3554
|
BaseController = class {
|
|
3486
3555
|
/**
|
|
3487
3556
|
* Constructs a new instance of the BaseController class.
|
|
@@ -3513,7 +3582,7 @@ var init_base_controller = __esm({
|
|
|
3513
3582
|
* @link https://github.com/xeno-js/xeno-js
|
|
3514
3583
|
*/
|
|
3515
3584
|
ok(data, status = 200, meta = {}, headers = {}) {
|
|
3516
|
-
return
|
|
3585
|
+
return import_shared64.HttpHelper.success(data, status, meta, headers);
|
|
3517
3586
|
}
|
|
3518
3587
|
/**
|
|
3519
3588
|
* Helper to automatically map a failed Result (from the CQRS pipeline)
|
|
@@ -3531,7 +3600,7 @@ var init_base_controller = __esm({
|
|
|
3531
3600
|
fail(error, details = void 0, headers = {}) {
|
|
3532
3601
|
const context = this._requestContext.getContext();
|
|
3533
3602
|
const customHeaders = error["header"];
|
|
3534
|
-
return
|
|
3603
|
+
return import_shared64.HttpHelper.error(
|
|
3535
3604
|
{
|
|
3536
3605
|
success: false,
|
|
3537
3606
|
error: {
|
|
@@ -3540,9 +3609,9 @@ var init_base_controller = __esm({
|
|
|
3540
3609
|
path: context?.network.path,
|
|
3541
3610
|
details: details ?? error.message
|
|
3542
3611
|
},
|
|
3543
|
-
correlationId: context?.tracing.correlationId ??
|
|
3544
|
-
requestId: context?.network.requestId ??
|
|
3545
|
-
spanId: context?.tracing.spanId ??
|
|
3612
|
+
correlationId: context?.tracing.correlationId ?? import_shared64.GuidHelper.generate(),
|
|
3613
|
+
requestId: context?.network.requestId ?? import_shared64.GuidHelper.generate(),
|
|
3614
|
+
spanId: context?.tracing.spanId ?? import_shared64.GuidHelper.generate(),
|
|
3546
3615
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3547
3616
|
},
|
|
3548
3617
|
error.status,
|
|
@@ -3597,11 +3666,11 @@ var init_controllers = __esm({
|
|
|
3597
3666
|
});
|
|
3598
3667
|
|
|
3599
3668
|
// src/presentation/middlewares/allow-method.middleware.ts
|
|
3600
|
-
var
|
|
3669
|
+
var import_shared65, MethodCheckMiddleware;
|
|
3601
3670
|
var init_allow_method_middleware = __esm({
|
|
3602
3671
|
"src/presentation/middlewares/allow-method.middleware.ts"() {
|
|
3603
3672
|
"use strict";
|
|
3604
|
-
|
|
3673
|
+
import_shared65 = require("@xeno-js/shared");
|
|
3605
3674
|
MethodCheckMiddleware = class {
|
|
3606
3675
|
constructor(_requestContext, _allowMethod) {
|
|
3607
3676
|
this._requestContext = _requestContext;
|
|
@@ -3613,21 +3682,21 @@ var init_allow_method_middleware = __esm({
|
|
|
3613
3682
|
const isAllowed = this._allowMethod.check(req.path, req.method);
|
|
3614
3683
|
if (!isAllowed) {
|
|
3615
3684
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3616
|
-
return
|
|
3685
|
+
return import_shared65.HttpHelper.error(
|
|
3617
3686
|
{
|
|
3618
3687
|
success: false,
|
|
3619
3688
|
error: {
|
|
3620
|
-
code:
|
|
3621
|
-
message:
|
|
3689
|
+
code: import_shared65.ERROR_CODES.NOT_ALLOWED,
|
|
3690
|
+
message: import_shared65.ERROR_CODE_MESSAGES[import_shared65.ERROR_CODES.NOT_ALLOWED],
|
|
3622
3691
|
details: `Operation blocked by allow method middleware`,
|
|
3623
3692
|
path: req.path
|
|
3624
3693
|
},
|
|
3625
|
-
correlationId: tracing?.correlationId ??
|
|
3626
|
-
requestId: network?.requestId ??
|
|
3627
|
-
spanId: tracing?.spanId ??
|
|
3694
|
+
correlationId: tracing?.correlationId ?? import_shared65.GuidHelper.generate(),
|
|
3695
|
+
requestId: network?.requestId ?? import_shared65.GuidHelper.generate(),
|
|
3696
|
+
spanId: tracing?.spanId ?? import_shared65.GuidHelper.generate(),
|
|
3628
3697
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3629
3698
|
},
|
|
3630
|
-
|
|
3699
|
+
import_shared65.STATUS_CODES.NOT_ALLOWED,
|
|
3631
3700
|
{
|
|
3632
3701
|
Allow: this._allowMethod.getMethods(req.path)
|
|
3633
3702
|
}
|
|
@@ -3640,11 +3709,11 @@ var init_allow_method_middleware = __esm({
|
|
|
3640
3709
|
});
|
|
3641
3710
|
|
|
3642
3711
|
// src/presentation/middlewares/allow-origin.middleware.ts
|
|
3643
|
-
var
|
|
3712
|
+
var import_shared66, AllowOriginMiddleware;
|
|
3644
3713
|
var init_allow_origin_middleware = __esm({
|
|
3645
3714
|
"src/presentation/middlewares/allow-origin.middleware.ts"() {
|
|
3646
3715
|
"use strict";
|
|
3647
|
-
|
|
3716
|
+
import_shared66 = require("@xeno-js/shared");
|
|
3648
3717
|
AllowOriginMiddleware = class {
|
|
3649
3718
|
constructor(_allowOrigin, _requestContext, _logger) {
|
|
3650
3719
|
this._allowOrigin = _allowOrigin;
|
|
@@ -3659,21 +3728,21 @@ var init_allow_origin_middleware = __esm({
|
|
|
3659
3728
|
const origin = network?.origin;
|
|
3660
3729
|
if (!this._allowOrigin.isAllowed(origin)) {
|
|
3661
3730
|
this._logger.warn(`Access denied by AllowOrigin policy for origin: ${origin ?? "unknown"}`);
|
|
3662
|
-
return
|
|
3731
|
+
return import_shared66.HttpHelper.error(
|
|
3663
3732
|
{
|
|
3664
3733
|
success: false,
|
|
3665
3734
|
error: {
|
|
3666
|
-
code:
|
|
3667
|
-
message:
|
|
3735
|
+
code: import_shared66.ERROR_CODES.FORBIDDEN,
|
|
3736
|
+
message: import_shared66.ERROR_CODE_MESSAGES[import_shared66.ERROR_CODES.FORBIDDEN],
|
|
3668
3737
|
details: `The origin '${origin ?? "unknown"}' is not allowed to access this resource.`,
|
|
3669
3738
|
path: req.path
|
|
3670
3739
|
},
|
|
3671
|
-
correlationId: tracing?.correlationId ??
|
|
3672
|
-
requestId: network?.requestId ??
|
|
3673
|
-
spanId: tracing?.spanId ??
|
|
3740
|
+
correlationId: tracing?.correlationId ?? import_shared66.GuidHelper.generate(),
|
|
3741
|
+
requestId: network?.requestId ?? import_shared66.GuidHelper.generate(),
|
|
3742
|
+
spanId: tracing?.spanId ?? import_shared66.GuidHelper.generate(),
|
|
3674
3743
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3675
3744
|
},
|
|
3676
|
-
|
|
3745
|
+
import_shared66.STATUS_CODES.FORBIDDEN
|
|
3677
3746
|
);
|
|
3678
3747
|
}
|
|
3679
3748
|
return next();
|
|
@@ -3683,11 +3752,11 @@ var init_allow_origin_middleware = __esm({
|
|
|
3683
3752
|
});
|
|
3684
3753
|
|
|
3685
3754
|
// src/presentation/middlewares/auth.middleware.ts
|
|
3686
|
-
var
|
|
3755
|
+
var import_shared67, AuthenticationMiddleware;
|
|
3687
3756
|
var init_auth_middleware = __esm({
|
|
3688
3757
|
"src/presentation/middlewares/auth.middleware.ts"() {
|
|
3689
3758
|
"use strict";
|
|
3690
|
-
|
|
3759
|
+
import_shared67 = require("@xeno-js/shared");
|
|
3691
3760
|
AuthenticationMiddleware = class {
|
|
3692
3761
|
constructor(_requestContext, _tokenExtractor, _gateKeeper, _logger) {
|
|
3693
3762
|
this._requestContext = _requestContext;
|
|
@@ -3708,7 +3777,7 @@ var init_auth_middleware = __esm({
|
|
|
3708
3777
|
`Authentication failed for request on path: ${req.path}. Code: ${error.code}. Error: ${error}`
|
|
3709
3778
|
);
|
|
3710
3779
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3711
|
-
return
|
|
3780
|
+
return import_shared67.HttpHelper.error(
|
|
3712
3781
|
{
|
|
3713
3782
|
success: false,
|
|
3714
3783
|
error: {
|
|
@@ -3717,12 +3786,12 @@ var init_auth_middleware = __esm({
|
|
|
3717
3786
|
details: `[Authentication Error] Failed to authenticate request on path: ${req.path}`,
|
|
3718
3787
|
path: req.path
|
|
3719
3788
|
},
|
|
3720
|
-
correlationId: tracing?.correlationId ??
|
|
3721
|
-
requestId: network?.requestId ??
|
|
3722
|
-
spanId: tracing?.spanId ??
|
|
3789
|
+
correlationId: tracing?.correlationId ?? import_shared67.GuidHelper.generate(),
|
|
3790
|
+
requestId: network?.requestId ?? import_shared67.GuidHelper.generate(),
|
|
3791
|
+
spanId: tracing?.spanId ?? import_shared67.GuidHelper.generate(),
|
|
3723
3792
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3724
3793
|
},
|
|
3725
|
-
error.status ??
|
|
3794
|
+
error.status ?? import_shared67.STATUS_CODES.UNAUTHORIZED,
|
|
3726
3795
|
{ "Content-Type": [network?.formatIndicator ?? "application/json"] }
|
|
3727
3796
|
);
|
|
3728
3797
|
}
|
|
@@ -3757,11 +3826,11 @@ var init_composite_middleware = __esm({
|
|
|
3757
3826
|
});
|
|
3758
3827
|
|
|
3759
3828
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3760
|
-
var
|
|
3829
|
+
var import_shared68, CORSMiddleware;
|
|
3761
3830
|
var init_cors_middleware = __esm({
|
|
3762
3831
|
"src/presentation/middlewares/cors.middleware.ts"() {
|
|
3763
3832
|
"use strict";
|
|
3764
|
-
|
|
3833
|
+
import_shared68 = require("@xeno-js/shared");
|
|
3765
3834
|
CORSMiddleware = class {
|
|
3766
3835
|
constructor(_requestContext, _withCredentials = "false") {
|
|
3767
3836
|
this._requestContext = _requestContext;
|
|
@@ -3773,7 +3842,7 @@ var init_cors_middleware = __esm({
|
|
|
3773
3842
|
const { network } = this._requestContext.getContext() ?? {};
|
|
3774
3843
|
const origin = network?.origin;
|
|
3775
3844
|
const response = await next();
|
|
3776
|
-
if (
|
|
3845
|
+
if (import_shared68.Guards.isDefined(origin))
|
|
3777
3846
|
response.headers = {
|
|
3778
3847
|
...response.headers ?? {},
|
|
3779
3848
|
"Access-Control-Allow-Origin": origin,
|
|
@@ -3787,11 +3856,11 @@ var init_cors_middleware = __esm({
|
|
|
3787
3856
|
});
|
|
3788
3857
|
|
|
3789
3858
|
// src/presentation/middlewares/csrf.middleware.ts
|
|
3790
|
-
var
|
|
3859
|
+
var import_shared69, CsrfMiddleware;
|
|
3791
3860
|
var init_csrf_middleware = __esm({
|
|
3792
3861
|
"src/presentation/middlewares/csrf.middleware.ts"() {
|
|
3793
3862
|
"use strict";
|
|
3794
|
-
|
|
3863
|
+
import_shared69 = require("@xeno-js/shared");
|
|
3795
3864
|
CsrfMiddleware = class {
|
|
3796
3865
|
constructor(_requestContext, _csrfTokenService) {
|
|
3797
3866
|
this._requestContext = _requestContext;
|
|
@@ -3806,64 +3875,64 @@ var init_csrf_middleware = __esm({
|
|
|
3806
3875
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3807
3876
|
const headerToken = network?.csrf;
|
|
3808
3877
|
const cookieToken = network?.csrfCookie;
|
|
3809
|
-
if (!
|
|
3810
|
-
return
|
|
3878
|
+
if (!import_shared69.Guards.isDefined(headerToken) || !import_shared69.Guards.isDefined(cookieToken)) {
|
|
3879
|
+
return import_shared69.HttpHelper.error(
|
|
3811
3880
|
{
|
|
3812
3881
|
success: false,
|
|
3813
3882
|
error: {
|
|
3814
|
-
code:
|
|
3815
|
-
message:
|
|
3883
|
+
code: import_shared69.ERROR_CODES.FORBIDDEN,
|
|
3884
|
+
message: import_shared69.ERROR_CODE_MESSAGES[import_shared69.ERROR_CODES.FORBIDDEN],
|
|
3816
3885
|
details: "CSRF token missing",
|
|
3817
3886
|
path: req.path
|
|
3818
3887
|
},
|
|
3819
|
-
correlationId: tracing?.correlationId ??
|
|
3820
|
-
requestId: network?.requestId ??
|
|
3821
|
-
spanId: tracing?.spanId ??
|
|
3888
|
+
correlationId: tracing?.correlationId ?? import_shared69.GuidHelper.generate(),
|
|
3889
|
+
requestId: network?.requestId ?? import_shared69.GuidHelper.generate(),
|
|
3890
|
+
spanId: tracing?.spanId ?? import_shared69.GuidHelper.generate(),
|
|
3822
3891
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3823
3892
|
},
|
|
3824
|
-
|
|
3893
|
+
import_shared69.STATUS_CODES.FORBIDDEN,
|
|
3825
3894
|
{
|
|
3826
3895
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3827
3896
|
}
|
|
3828
3897
|
);
|
|
3829
3898
|
}
|
|
3830
3899
|
if (headerToken !== cookieToken) {
|
|
3831
|
-
return
|
|
3900
|
+
return import_shared69.HttpHelper.error(
|
|
3832
3901
|
{
|
|
3833
3902
|
success: false,
|
|
3834
3903
|
error: {
|
|
3835
|
-
code:
|
|
3836
|
-
message:
|
|
3904
|
+
code: import_shared69.ERROR_CODES.FORBIDDEN,
|
|
3905
|
+
message: import_shared69.ERROR_CODE_MESSAGES[import_shared69.ERROR_CODES.FORBIDDEN],
|
|
3837
3906
|
details: "CSRF token mismatch",
|
|
3838
3907
|
path: req.path
|
|
3839
3908
|
},
|
|
3840
|
-
correlationId: tracing?.correlationId ??
|
|
3841
|
-
requestId: network?.requestId ??
|
|
3842
|
-
spanId: tracing?.spanId ??
|
|
3909
|
+
correlationId: tracing?.correlationId ?? import_shared69.GuidHelper.generate(),
|
|
3910
|
+
requestId: network?.requestId ?? import_shared69.GuidHelper.generate(),
|
|
3911
|
+
spanId: tracing?.spanId ?? import_shared69.GuidHelper.generate(),
|
|
3843
3912
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3844
3913
|
},
|
|
3845
|
-
|
|
3914
|
+
import_shared69.STATUS_CODES.FORBIDDEN,
|
|
3846
3915
|
{
|
|
3847
3916
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3848
3917
|
}
|
|
3849
3918
|
);
|
|
3850
3919
|
}
|
|
3851
|
-
if (!
|
|
3852
|
-
return
|
|
3920
|
+
if (!import_shared69.Guards.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3921
|
+
return import_shared69.HttpHelper.error(
|
|
3853
3922
|
{
|
|
3854
3923
|
success: false,
|
|
3855
3924
|
error: {
|
|
3856
|
-
code:
|
|
3857
|
-
message:
|
|
3925
|
+
code: import_shared69.ERROR_CODES.FORBIDDEN,
|
|
3926
|
+
message: import_shared69.ERROR_CODE_MESSAGES[import_shared69.ERROR_CODES.FORBIDDEN],
|
|
3858
3927
|
details: "CSRF token invalid",
|
|
3859
3928
|
path: req.path
|
|
3860
3929
|
},
|
|
3861
|
-
correlationId: tracing?.correlationId ??
|
|
3862
|
-
requestId: network?.requestId ??
|
|
3863
|
-
spanId: tracing?.spanId ??
|
|
3930
|
+
correlationId: tracing?.correlationId ?? import_shared69.GuidHelper.generate(),
|
|
3931
|
+
requestId: network?.requestId ?? import_shared69.GuidHelper.generate(),
|
|
3932
|
+
spanId: tracing?.spanId ?? import_shared69.GuidHelper.generate(),
|
|
3864
3933
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3865
3934
|
},
|
|
3866
|
-
|
|
3935
|
+
import_shared69.STATUS_CODES.FORBIDDEN,
|
|
3867
3936
|
{
|
|
3868
3937
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3869
3938
|
}
|
|
@@ -3877,11 +3946,11 @@ var init_csrf_middleware = __esm({
|
|
|
3877
3946
|
});
|
|
3878
3947
|
|
|
3879
3948
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3880
|
-
var
|
|
3949
|
+
var import_shared70, CsrfCookieMiddleware;
|
|
3881
3950
|
var init_csrf_cookie_middleware = __esm({
|
|
3882
3951
|
"src/presentation/middlewares/csrf-cookie.middleware.ts"() {
|
|
3883
3952
|
"use strict";
|
|
3884
|
-
|
|
3953
|
+
import_shared70 = require("@xeno-js/shared");
|
|
3885
3954
|
CsrfCookieMiddleware = class {
|
|
3886
3955
|
constructor(_requestContext, _csrfTokenService, _csrf) {
|
|
3887
3956
|
this._requestContext = _requestContext;
|
|
@@ -3896,8 +3965,8 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3896
3965
|
const context = this._requestContext.getContext();
|
|
3897
3966
|
const identity = context?.identity;
|
|
3898
3967
|
const network = context?.network;
|
|
3899
|
-
if (!
|
|
3900
|
-
if (
|
|
3968
|
+
if (!import_shared70.Guards.isDefined(identity?.userId)) return response;
|
|
3969
|
+
if (import_shared70.Guards.isDefined(network?.csrfCookie)) return response;
|
|
3901
3970
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3902
3971
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3903
3972
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3915,11 +3984,11 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3915
3984
|
});
|
|
3916
3985
|
|
|
3917
3986
|
// src/presentation/middlewares/options.middleware.ts
|
|
3918
|
-
var
|
|
3987
|
+
var import_shared71, OptionsMiddleware;
|
|
3919
3988
|
var init_options_middleware = __esm({
|
|
3920
3989
|
"src/presentation/middlewares/options.middleware.ts"() {
|
|
3921
3990
|
"use strict";
|
|
3922
|
-
|
|
3991
|
+
import_shared71 = require("@xeno-js/shared");
|
|
3923
3992
|
OptionsMiddleware = class {
|
|
3924
3993
|
constructor(_requestContext, _alloewMethod, _allowHeaders = [], _withCredentials = "false") {
|
|
3925
3994
|
this._requestContext = _requestContext;
|
|
@@ -3936,14 +4005,14 @@ var init_options_middleware = __esm({
|
|
|
3936
4005
|
const network = this._requestContext.getNetworkContext();
|
|
3937
4006
|
const origin = network?.origin;
|
|
3938
4007
|
const headers = {};
|
|
3939
|
-
if (
|
|
4008
|
+
if (import_shared71.Guards.isDefined(origin)) {
|
|
3940
4009
|
headers["Access-Control-Allow-Origin"] = origin;
|
|
3941
4010
|
headers["Access-Control-Allow-Credentials"] = this._withCredentials;
|
|
3942
4011
|
headers["Vary"] = "Origin";
|
|
3943
4012
|
}
|
|
3944
4013
|
headers["Access-Control-Allow-Methods"] = this._alloewMethod.getMethods(req.path);
|
|
3945
4014
|
headers["Access-Control-Allow-Headers"] = this._allowHeaders.join(", ");
|
|
3946
|
-
return
|
|
4015
|
+
return import_shared71.HttpHelper.success(null, import_shared71.STATUS_CODES.NO_CONTENT, {}, headers);
|
|
3947
4016
|
}
|
|
3948
4017
|
return await next();
|
|
3949
4018
|
}
|
|
@@ -3952,11 +4021,11 @@ var init_options_middleware = __esm({
|
|
|
3952
4021
|
});
|
|
3953
4022
|
|
|
3954
4023
|
// src/presentation/middlewares/rate-limiter.middleware.ts
|
|
3955
|
-
var
|
|
4024
|
+
var import_shared72, RateLimitMiddleware;
|
|
3956
4025
|
var init_rate_limiter_middleware = __esm({
|
|
3957
4026
|
"src/presentation/middlewares/rate-limiter.middleware.ts"() {
|
|
3958
4027
|
"use strict";
|
|
3959
|
-
|
|
4028
|
+
import_shared72 = require("@xeno-js/shared");
|
|
3960
4029
|
RateLimitMiddleware = class {
|
|
3961
4030
|
constructor(_ctxAccessor, _cache, _keyBuilder, _logger, _opts) {
|
|
3962
4031
|
this._ctxAccessor = _ctxAccessor;
|
|
@@ -3973,22 +4042,22 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3973
4042
|
async execute(req, _res, next) {
|
|
3974
4043
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3975
4044
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3976
|
-
if (!
|
|
3977
|
-
return
|
|
4045
|
+
if (!import_shared72.Guards.isDefined(cacheKey))
|
|
4046
|
+
return import_shared72.HttpHelper.error(
|
|
3978
4047
|
{
|
|
3979
4048
|
success: false,
|
|
3980
4049
|
error: {
|
|
3981
|
-
code:
|
|
3982
|
-
message:
|
|
4050
|
+
code: import_shared72.ERROR_CODES.SYSTEM_ERROR,
|
|
4051
|
+
message: import_shared72.ERROR_CODE_MESSAGES[import_shared72.ERROR_CODES.SYSTEM_ERROR],
|
|
3983
4052
|
details: `Bad Request: Unable to identify client context for rate limiting.`,
|
|
3984
4053
|
path: req.path
|
|
3985
4054
|
},
|
|
3986
|
-
correlationId: tracing?.correlationId ??
|
|
3987
|
-
requestId: network?.requestId ??
|
|
3988
|
-
spanId: tracing?.spanId ??
|
|
4055
|
+
correlationId: tracing?.correlationId ?? import_shared72.GuidHelper.generate(),
|
|
4056
|
+
requestId: network?.requestId ?? import_shared72.GuidHelper.generate(),
|
|
4057
|
+
spanId: tracing?.spanId ?? import_shared72.GuidHelper.generate(),
|
|
3989
4058
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3990
4059
|
},
|
|
3991
|
-
|
|
4060
|
+
import_shared72.STATUS_CODES.SERVICE_UNAVAILABLE,
|
|
3992
4061
|
{
|
|
3993
4062
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3994
4063
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3997,21 +4066,21 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3997
4066
|
const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
|
|
3998
4067
|
if (currentHits > this._opts.maxRequests) {
|
|
3999
4068
|
this._logger.warn(`[RateLimit] key ${cacheKey} has been blocked on ${req.path}`);
|
|
4000
|
-
return
|
|
4069
|
+
return import_shared72.HttpHelper.error(
|
|
4001
4070
|
{
|
|
4002
4071
|
success: false,
|
|
4003
4072
|
error: {
|
|
4004
|
-
code:
|
|
4005
|
-
message:
|
|
4073
|
+
code: import_shared72.ERROR_CODES.TOO_MANY_REQUESTS,
|
|
4074
|
+
message: import_shared72.ERROR_CODE_MESSAGES[import_shared72.ERROR_CODES.TOO_MANY_REQUESTS],
|
|
4006
4075
|
details: `Rate limit exceeded.`,
|
|
4007
4076
|
path: req.path
|
|
4008
4077
|
},
|
|
4009
|
-
correlationId: tracing?.correlationId ??
|
|
4010
|
-
requestId: network?.requestId ??
|
|
4011
|
-
spanId: tracing?.spanId ??
|
|
4078
|
+
correlationId: tracing?.correlationId ?? import_shared72.GuidHelper.generate(),
|
|
4079
|
+
requestId: network?.requestId ?? import_shared72.GuidHelper.generate(),
|
|
4080
|
+
spanId: tracing?.spanId ?? import_shared72.GuidHelper.generate(),
|
|
4012
4081
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4013
4082
|
},
|
|
4014
|
-
|
|
4083
|
+
import_shared72.STATUS_CODES.TOO_MANY_REQUESTS,
|
|
4015
4084
|
{
|
|
4016
4085
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
4017
4086
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -4026,8 +4095,8 @@ var init_rate_limiter_middleware = __esm({
|
|
|
4026
4095
|
|
|
4027
4096
|
// src/presentation/mappers/context.mapper.ts
|
|
4028
4097
|
function _buildMessagingContext(meta) {
|
|
4029
|
-
const hasSequenceData =
|
|
4030
|
-
const hasMessagingData = hasSequenceData ||
|
|
4098
|
+
const hasSequenceData = import_shared73.Guards.isDefined(meta.sequence?.sequenceId) || import_shared73.Guards.isDefined(meta.sequence?.position) || import_shared73.Guards.isDefined(meta.sequence?.size);
|
|
4099
|
+
const hasMessagingData = hasSequenceData || import_shared73.Guards.isDefined(meta.expiration) || import_shared73.Guards.isDefined(meta.returnAddress);
|
|
4031
4100
|
const messaging = hasMessagingData ? {
|
|
4032
4101
|
returnAddress: meta.returnAddress,
|
|
4033
4102
|
expiration: meta.expiration,
|
|
@@ -4035,11 +4104,11 @@ function _buildMessagingContext(meta) {
|
|
|
4035
4104
|
} : void 0;
|
|
4036
4105
|
return messaging;
|
|
4037
4106
|
}
|
|
4038
|
-
var
|
|
4107
|
+
var import_shared73, ContextMapper;
|
|
4039
4108
|
var init_context_mapper = __esm({
|
|
4040
4109
|
"src/presentation/mappers/context.mapper.ts"() {
|
|
4041
4110
|
"use strict";
|
|
4042
|
-
|
|
4111
|
+
import_shared73 = require("@xeno-js/shared");
|
|
4043
4112
|
ContextMapper = Object.freeze({
|
|
4044
4113
|
/**
|
|
4045
4114
|
* @description Maps to RequestContext. It extracts relevant information from the object, such as correlation ID, request ID, authentication token, client IP, user agent, format indicator, and messaging context (if available). The method constructs a RequestContext object that encapsulates all this information, providing a structured representation of the request context for further processing in the application.
|
|
@@ -4083,11 +4152,11 @@ var init_context_mapper = __esm({
|
|
|
4083
4152
|
});
|
|
4084
4153
|
|
|
4085
4154
|
// src/presentation/middlewares/request.middleware.ts
|
|
4086
|
-
var
|
|
4155
|
+
var import_shared74, RequestContextMiddleware;
|
|
4087
4156
|
var init_request_middleware = __esm({
|
|
4088
4157
|
"src/presentation/middlewares/request.middleware.ts"() {
|
|
4089
4158
|
"use strict";
|
|
4090
|
-
|
|
4159
|
+
import_shared74 = require("@xeno-js/shared");
|
|
4091
4160
|
init_context_mapper();
|
|
4092
4161
|
RequestContextMiddleware = class {
|
|
4093
4162
|
/**
|
|
@@ -4112,8 +4181,8 @@ var init_request_middleware = __esm({
|
|
|
4112
4181
|
_resolver;
|
|
4113
4182
|
_logger;
|
|
4114
4183
|
async execute(req, res, next) {
|
|
4115
|
-
const correlationId =
|
|
4116
|
-
const requestId =
|
|
4184
|
+
const correlationId = import_shared74.GuidHelper.generate();
|
|
4185
|
+
const requestId = import_shared74.GuidHelper.generate();
|
|
4117
4186
|
const spanId = correlationId;
|
|
4118
4187
|
const formatIndicator = "application/json";
|
|
4119
4188
|
try {
|
|
@@ -4129,7 +4198,7 @@ var init_request_middleware = __esm({
|
|
|
4129
4198
|
};
|
|
4130
4199
|
const tmpContext = ContextMapper.map({
|
|
4131
4200
|
metadata,
|
|
4132
|
-
identity:
|
|
4201
|
+
identity: import_shared74.GUEST,
|
|
4133
4202
|
path: req.path,
|
|
4134
4203
|
transport: { req, res }
|
|
4135
4204
|
});
|
|
@@ -4141,12 +4210,12 @@ var init_request_middleware = __esm({
|
|
|
4141
4210
|
return result;
|
|
4142
4211
|
} catch (error) {
|
|
4143
4212
|
this._logger.error("RequestContextMiddleware encountered an error", error);
|
|
4144
|
-
return
|
|
4213
|
+
return import_shared74.HttpHelper.error(
|
|
4145
4214
|
{
|
|
4146
4215
|
success: false,
|
|
4147
4216
|
error: {
|
|
4148
|
-
code:
|
|
4149
|
-
message:
|
|
4217
|
+
code: import_shared74.ERROR_CODES.SYSTEM_ERROR,
|
|
4218
|
+
message: import_shared74.ERROR_CODE_MESSAGES[import_shared74.ERROR_CODES.SYSTEM_ERROR],
|
|
4150
4219
|
details: `[Fatal System Error] Exception caught during request handling on path: ${req.path}`,
|
|
4151
4220
|
path: req.path
|
|
4152
4221
|
},
|
|
@@ -4155,7 +4224,7 @@ var init_request_middleware = __esm({
|
|
|
4155
4224
|
spanId,
|
|
4156
4225
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4157
4226
|
},
|
|
4158
|
-
|
|
4227
|
+
import_shared74.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
4159
4228
|
{ "Content-Type": [formatIndicator] }
|
|
4160
4229
|
);
|
|
4161
4230
|
}
|
|
@@ -4209,16 +4278,16 @@ var inmemory_cache_exports = {};
|
|
|
4209
4278
|
__export(inmemory_cache_exports, {
|
|
4210
4279
|
InMemoryCacheExtended: () => InMemoryCacheExtended
|
|
4211
4280
|
});
|
|
4212
|
-
var
|
|
4281
|
+
var import_shared75, InMemoryCacheExtended;
|
|
4213
4282
|
var init_inmemory_cache = __esm({
|
|
4214
4283
|
"src/infrastructure/cache/inmemory.cache.ts"() {
|
|
4215
4284
|
"use strict";
|
|
4216
|
-
|
|
4217
|
-
InMemoryCacheExtended = class extends
|
|
4285
|
+
import_shared75 = require("@xeno-js/shared");
|
|
4286
|
+
InMemoryCacheExtended = class extends import_shared75.InMemoryCache {
|
|
4218
4287
|
async increment(key, ttlSeconds) {
|
|
4219
4288
|
const current = await this.get(key) ?? 0;
|
|
4220
4289
|
const next = Number(current) + 1;
|
|
4221
|
-
const ttl =
|
|
4290
|
+
const ttl = import_shared75.Guards.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
4222
4291
|
await this.set(key, next, ttl);
|
|
4223
4292
|
return next;
|
|
4224
4293
|
}
|
|
@@ -4227,11 +4296,11 @@ var init_inmemory_cache = __esm({
|
|
|
4227
4296
|
});
|
|
4228
4297
|
|
|
4229
4298
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
4230
|
-
var
|
|
4299
|
+
var import_shared76, RateLimitKeyBuilder;
|
|
4231
4300
|
var init_rate_limit_key_builder_cache = __esm({
|
|
4232
4301
|
"src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
|
|
4233
4302
|
"use strict";
|
|
4234
|
-
|
|
4303
|
+
import_shared76 = require("@xeno-js/shared");
|
|
4235
4304
|
RateLimitKeyBuilder = class {
|
|
4236
4305
|
constructor(_contextAccessor) {
|
|
4237
4306
|
this._contextAccessor = _contextAccessor;
|
|
@@ -4242,12 +4311,12 @@ var init_rate_limit_key_builder_cache = __esm({
|
|
|
4242
4311
|
const tenantId = ctx?.identity?.tenantId;
|
|
4243
4312
|
const userId = ctx?.identity?.userId;
|
|
4244
4313
|
const clientIp = ctx?.network?.clientIp;
|
|
4245
|
-
if (!
|
|
4314
|
+
if (!import_shared76.Guards.isNullOrEmpty(tenantId) && !import_shared76.Guards.isNullOrEmpty(userId))
|
|
4246
4315
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
4247
|
-
if (!
|
|
4316
|
+
if (!import_shared76.Guards.isNullOrEmpty(tenantId) && !import_shared76.Guards.isNullOrEmpty(clientIp))
|
|
4248
4317
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
4249
|
-
if (!
|
|
4250
|
-
if (!
|
|
4318
|
+
if (!import_shared76.Guards.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
4319
|
+
if (!import_shared76.Guards.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
4251
4320
|
return void 0;
|
|
4252
4321
|
}
|
|
4253
4322
|
};
|
|
@@ -4281,7 +4350,7 @@ var init_middleware_module = __esm({
|
|
|
4281
4350
|
"use strict";
|
|
4282
4351
|
MiddlewareModule = class {
|
|
4283
4352
|
async configure(container, opts) {
|
|
4284
|
-
const { Guards:
|
|
4353
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4285
4354
|
const { HttpCookieExtractor: HttpCookieExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4286
4355
|
const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4287
4356
|
const tokenExtractor = await this._getTokenExtractor(
|
|
@@ -4311,7 +4380,7 @@ var init_middleware_module = __esm({
|
|
|
4311
4380
|
logger
|
|
4312
4381
|
)
|
|
4313
4382
|
);
|
|
4314
|
-
if (!
|
|
4383
|
+
if (!Guards51.isNullOrEmpty(opts.allowOrigins)) {
|
|
4315
4384
|
if (opts.withCredentials && opts.allowOrigins.includes("*"))
|
|
4316
4385
|
throw new Error(
|
|
4317
4386
|
"Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
|
|
@@ -4337,7 +4406,7 @@ var init_middleware_module = __esm({
|
|
|
4337
4406
|
const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4338
4407
|
middlewares.push(new CORSMiddleware2(requestContext, withCredentials));
|
|
4339
4408
|
}
|
|
4340
|
-
if (
|
|
4409
|
+
if (Guards51.isDefined(opts.routeRegistry)) {
|
|
4341
4410
|
const { MethodCheckMiddleware: MethodCheckMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4342
4411
|
middlewares.push(new MethodCheckMiddleware2(requestContext, allowMethod));
|
|
4343
4412
|
}
|
|
@@ -4364,13 +4433,13 @@ var init_middleware_module = __esm({
|
|
|
4364
4433
|
)
|
|
4365
4434
|
);
|
|
4366
4435
|
}
|
|
4367
|
-
if (
|
|
4436
|
+
if (Guards51.isDefined(opts.rateLimite.maxRequests) || Guards51.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4368
4437
|
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4369
|
-
|
|
4370
|
-
|
|
4438
|
+
Guards51.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4439
|
+
Guards51.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4371
4440
|
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4372
|
-
|
|
4373
|
-
|
|
4441
|
+
Guards51.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4442
|
+
Guards51.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4374
4443
|
const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
|
|
4375
4444
|
const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4376
4445
|
middlewares.push(
|
|
@@ -4383,7 +4452,7 @@ var init_middleware_module = __esm({
|
|
|
4383
4452
|
)
|
|
4384
4453
|
);
|
|
4385
4454
|
}
|
|
4386
|
-
if (
|
|
4455
|
+
if (Guards51.isDefined(opts.csrf)) {
|
|
4387
4456
|
const csrf = opts.csrf;
|
|
4388
4457
|
const { EdgeCryptoService: EdgeCryptoService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4389
4458
|
container.addSingleton("CRYPTO_SERVICE", () => new EdgeCryptoService2());
|
|
@@ -4408,8 +4477,8 @@ var init_middleware_module = __esm({
|
|
|
4408
4477
|
});
|
|
4409
4478
|
}
|
|
4410
4479
|
async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
|
|
4411
|
-
const { Guards:
|
|
4412
|
-
if (
|
|
4480
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
4481
|
+
if (Guards51.isDefined(customTokenExtractor)) return customTokenExtractor();
|
|
4413
4482
|
if (isSSR) {
|
|
4414
4483
|
const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4415
4484
|
return new SupabaseSsrTokenExtractor2();
|
|
@@ -4419,8 +4488,8 @@ var init_middleware_module = __esm({
|
|
|
4419
4488
|
}
|
|
4420
4489
|
}
|
|
4421
4490
|
async _getAllowMethod(configure, opts) {
|
|
4422
|
-
const { Guards:
|
|
4423
|
-
if (!configure || !
|
|
4491
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
4492
|
+
if (!configure || !Guards51.isDefined(opts)) return void 0;
|
|
4424
4493
|
const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
4425
4494
|
return new AllowMethodFactory2().create(opts);
|
|
4426
4495
|
}
|
|
@@ -4450,8 +4519,8 @@ var init_cache_utils = __esm({
|
|
|
4450
4519
|
* @link https://github.com/xeno-js/xeno-js
|
|
4451
4520
|
*/
|
|
4452
4521
|
async addCache(container, opts) {
|
|
4453
|
-
const { Guards:
|
|
4454
|
-
if (!opts.inMemory && !
|
|
4522
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4523
|
+
if (!opts.inMemory && !Guards51.isDefined(opts.redis)) {
|
|
4455
4524
|
throw new Error(
|
|
4456
4525
|
"No cache strategies are configured. Please provide at least one cache strategy."
|
|
4457
4526
|
);
|
|
@@ -4461,12 +4530,12 @@ var init_cache_utils = __esm({
|
|
|
4461
4530
|
TOKENS5.CACHE_KEY_BUILDER,
|
|
4462
4531
|
(c) => new CacheKeyBuilder(c.resolve(TOKENS5.IDENTITY_ACCESSOR))
|
|
4463
4532
|
);
|
|
4464
|
-
if (opts.inMemory || !
|
|
4533
|
+
if (opts.inMemory || !Guards51.isDefined(opts.redis)) {
|
|
4465
4534
|
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
4466
4535
|
container.addSingleton(TOKENS5.CACHE, () => new InMemoryCacheExtended2());
|
|
4467
4536
|
return;
|
|
4468
4537
|
}
|
|
4469
|
-
if (
|
|
4538
|
+
if (Guards51.isDefined(opts.redis)) {
|
|
4470
4539
|
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
4471
4540
|
container.addSingleton(TOKENS5.CACHE, () => {
|
|
4472
4541
|
const config = opts.redis;
|
|
@@ -4483,11 +4552,11 @@ var console_logger_exports = {};
|
|
|
4483
4552
|
__export(console_logger_exports, {
|
|
4484
4553
|
ConsoleLogger: () => ConsoleLogger
|
|
4485
4554
|
});
|
|
4486
|
-
var
|
|
4555
|
+
var import_shared77, ConsoleLogger;
|
|
4487
4556
|
var init_console_logger = __esm({
|
|
4488
4557
|
"src/infrastructure/loggers/console.logger.ts"() {
|
|
4489
4558
|
"use strict";
|
|
4490
|
-
|
|
4559
|
+
import_shared77 = require("@xeno-js/shared");
|
|
4491
4560
|
ConsoleLogger = class {
|
|
4492
4561
|
/**
|
|
4493
4562
|
* Constructs a new instance of the ConsoleLogger class, which takes an optional minimum log level. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.
|
|
@@ -4499,22 +4568,22 @@ var init_console_logger = __esm({
|
|
|
4499
4568
|
* @since 2025-09-30
|
|
4500
4569
|
* @link https://github.com/xeno-js/xeno-js
|
|
4501
4570
|
*/
|
|
4502
|
-
constructor(_minLevel =
|
|
4571
|
+
constructor(_minLevel = import_shared77.LOG_LEVEL.DEBUG) {
|
|
4503
4572
|
this._minLevel = _minLevel;
|
|
4504
4573
|
}
|
|
4505
4574
|
_minLevel;
|
|
4506
4575
|
track(level, message, context, error = void 0) {
|
|
4507
4576
|
if (level < this._minLevel) return;
|
|
4508
4577
|
const logMessage = `[${level}] ${message}`;
|
|
4509
|
-
const payload =
|
|
4578
|
+
const payload = import_shared77.Guards.isDefined(error) ? { ...context, error } : context;
|
|
4510
4579
|
switch (level) {
|
|
4511
|
-
case
|
|
4580
|
+
case import_shared77.LOG_LEVEL.ERROR:
|
|
4512
4581
|
console.error(logMessage, payload ?? {});
|
|
4513
4582
|
break;
|
|
4514
|
-
case
|
|
4583
|
+
case import_shared77.LOG_LEVEL.WARN:
|
|
4515
4584
|
console.warn(logMessage, payload ?? {});
|
|
4516
4585
|
break;
|
|
4517
|
-
case
|
|
4586
|
+
case import_shared77.LOG_LEVEL.DEBUG:
|
|
4518
4587
|
console.debug(logMessage, payload ?? {});
|
|
4519
4588
|
break;
|
|
4520
4589
|
default:
|
|
@@ -4550,24 +4619,24 @@ var init_logger_utils = __esm({
|
|
|
4550
4619
|
*/
|
|
4551
4620
|
async addLogger(container, opts) {
|
|
4552
4621
|
const loggerDependencies = [];
|
|
4553
|
-
const { Guards:
|
|
4554
|
-
if (!
|
|
4622
|
+
const { Guards: Guards51, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4623
|
+
if (!Guards51.isDefined(opts) || opts.console) {
|
|
4555
4624
|
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
4556
4625
|
loggerDependencies.push(new ConsoleLogger2(opts?.level));
|
|
4557
4626
|
}
|
|
4558
|
-
if (
|
|
4559
|
-
if (
|
|
4627
|
+
if (Guards51.isDefined(opts)) {
|
|
4628
|
+
if (Guards51.isDefined(opts.sentry.config)) {
|
|
4560
4629
|
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
4561
4630
|
loggerDependencies.push(new SentryLoggerFactory2().create(opts));
|
|
4562
4631
|
}
|
|
4563
|
-
if (
|
|
4632
|
+
if (Guards51.isDefined(opts.pino.config)) {
|
|
4564
4633
|
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
4565
4634
|
loggerDependencies.push(new PinoLoggerFactory2().create(opts));
|
|
4566
4635
|
}
|
|
4567
|
-
if (!
|
|
4636
|
+
if (!Guards51.isNullOrEmpty(opts.customLoggers)) {
|
|
4568
4637
|
const customLoggers = opts.customLoggers;
|
|
4569
4638
|
customLoggers.forEach((fn) => {
|
|
4570
|
-
if (
|
|
4639
|
+
if (Guards51.isDefined(fn)) loggerDependencies.push(fn(container));
|
|
4571
4640
|
});
|
|
4572
4641
|
}
|
|
4573
4642
|
}
|
|
@@ -4633,7 +4702,7 @@ __export(index_exports, {
|
|
|
4633
4702
|
BaseController: () => BaseController,
|
|
4634
4703
|
BaseHandler: () => BaseHandler,
|
|
4635
4704
|
BasePostgresSqlDataSource: () => BasePostgresSqlDataSource,
|
|
4636
|
-
BaseQuery: () =>
|
|
4705
|
+
BaseQuery: () => import_shared84.Query,
|
|
4637
4706
|
BaseSqliteSqlDataSource: () => BaseSqliteSqlDataSource,
|
|
4638
4707
|
ContainerUtils: () => ContainerUtils,
|
|
4639
4708
|
ReadDao: () => ReadDao,
|
|
@@ -4645,7 +4714,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
4645
4714
|
init_application();
|
|
4646
4715
|
|
|
4647
4716
|
// src/infrastructure/builder/app.builder.ts
|
|
4648
|
-
var
|
|
4717
|
+
var import_shared78 = require("@xeno-js/shared");
|
|
4649
4718
|
|
|
4650
4719
|
// src/infrastructure/configuration/configuration.ts
|
|
4651
4720
|
var import_shared32 = require("@xeno-js/shared");
|
|
@@ -4924,10 +4993,10 @@ var AppBuilder = class {
|
|
|
4924
4993
|
constructor(container) {
|
|
4925
4994
|
this._container = container ?? new ServiceContainer();
|
|
4926
4995
|
this._container.addSingleton(
|
|
4927
|
-
|
|
4996
|
+
import_shared78.TOKENS.CONFIGURATION_SERVICE,
|
|
4928
4997
|
() => new EnvironmentConfigurationService()
|
|
4929
4998
|
);
|
|
4930
|
-
this._configuration = this._container.resolve(
|
|
4999
|
+
this._configuration = this._container.resolve(import_shared78.TOKENS.CONFIGURATION_SERVICE);
|
|
4931
5000
|
this._middlewareConfig.allowOrigins?.push(
|
|
4932
5001
|
this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
|
|
4933
5002
|
);
|
|
@@ -5010,7 +5079,7 @@ var AppBuilder = class {
|
|
|
5010
5079
|
resilience: { retry: {}, circuitBreaker: {}, bulkhead: {} }
|
|
5011
5080
|
};
|
|
5012
5081
|
_loggerConfig = {
|
|
5013
|
-
level:
|
|
5082
|
+
level: import_shared78.LOG_LEVEL.DEBUG,
|
|
5014
5083
|
console: true,
|
|
5015
5084
|
sentry: { config: void 0 },
|
|
5016
5085
|
pino: { config: void 0 },
|
|
@@ -5083,7 +5152,7 @@ var AppBuilder = class {
|
|
|
5083
5152
|
* @link https://github.com/xeno-js/xeno-js
|
|
5084
5153
|
*/
|
|
5085
5154
|
addLogger(setupAction) {
|
|
5086
|
-
if (
|
|
5155
|
+
if (import_shared78.Guards.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
|
|
5087
5156
|
if (this._isLoggerModuleQueued) return this;
|
|
5088
5157
|
this._isLoggerModuleQueued = true;
|
|
5089
5158
|
this._modules.push({
|
|
@@ -5108,7 +5177,7 @@ var AppBuilder = class {
|
|
|
5108
5177
|
* @link https://github.com/xeno-js/xeno-js
|
|
5109
5178
|
*/
|
|
5110
5179
|
addCache(setupAction) {
|
|
5111
|
-
if (
|
|
5180
|
+
if (import_shared78.Guards.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
5112
5181
|
if (this._isCacheModuleQueued) return this;
|
|
5113
5182
|
this._isCacheModuleQueued = true;
|
|
5114
5183
|
this._modules.push({
|
|
@@ -5211,7 +5280,7 @@ var AppBuilder = class {
|
|
|
5211
5280
|
* @link https://github.com/xeno-js/xeno-js
|
|
5212
5281
|
*/
|
|
5213
5282
|
addPipeline(setupAction) {
|
|
5214
|
-
if (
|
|
5283
|
+
if (import_shared78.Guards.isDefined(setupAction)) {
|
|
5215
5284
|
setupAction(this._pipelineConfig, this._configuration);
|
|
5216
5285
|
}
|
|
5217
5286
|
this._queuePipelineModule();
|
|
@@ -5332,7 +5401,7 @@ var AppBuilder = class {
|
|
|
5332
5401
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
5333
5402
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
5334
5403
|
`);
|
|
5335
|
-
if (error instanceof Error &&
|
|
5404
|
+
if (error instanceof Error && import_shared78.Guards.isDefined(error.stack)) {
|
|
5336
5405
|
console.error(error.stack);
|
|
5337
5406
|
}
|
|
5338
5407
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5460,7 +5529,7 @@ var BaseSqliteSqlDataSource = class {
|
|
|
5460
5529
|
};
|
|
5461
5530
|
|
|
5462
5531
|
// src/infrastructure/datasources/remote.datasource.ts
|
|
5463
|
-
var
|
|
5532
|
+
var import_shared79 = require("@xeno-js/shared");
|
|
5464
5533
|
|
|
5465
5534
|
// src/infrastructure/index.ts
|
|
5466
5535
|
init_factories();
|
|
@@ -5475,8 +5544,8 @@ init_sentry_logger();
|
|
|
5475
5544
|
init_modules();
|
|
5476
5545
|
|
|
5477
5546
|
// src/infrastructure/repositories/read-dao.ts
|
|
5478
|
-
var
|
|
5479
|
-
var
|
|
5547
|
+
var import_shared80 = require("@xeno-js/shared");
|
|
5548
|
+
var import_shared81 = require("@xeno-js/shared");
|
|
5480
5549
|
var ReadDao = class {
|
|
5481
5550
|
/**
|
|
5482
5551
|
* Constructs a new ReadDao instance.
|
|
@@ -5496,23 +5565,23 @@ var ReadDao = class {
|
|
|
5496
5565
|
_dataSource;
|
|
5497
5566
|
_mapper;
|
|
5498
5567
|
async findById(id, ctx, signal) {
|
|
5499
|
-
|
|
5568
|
+
import_shared80.AppError.throwIfAborted(signal, "ReadDao.findById");
|
|
5500
5569
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5501
|
-
if (
|
|
5570
|
+
if (import_shared81.Guards.isNullOrEmpty(result)) return import_shared80.Result.ok();
|
|
5502
5571
|
const entity = this._mapper.toEntity(result);
|
|
5503
|
-
return
|
|
5572
|
+
return import_shared80.Result.ok(entity);
|
|
5504
5573
|
}
|
|
5505
5574
|
async findAll(ctx, signal) {
|
|
5506
|
-
|
|
5575
|
+
import_shared80.AppError.throwIfAborted(signal, "ReadDao.findAll");
|
|
5507
5576
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5508
5577
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5509
|
-
return
|
|
5578
|
+
return import_shared80.Result.ok(entities);
|
|
5510
5579
|
}
|
|
5511
5580
|
};
|
|
5512
5581
|
|
|
5513
5582
|
// src/infrastructure/repositories/repository.ts
|
|
5514
|
-
var
|
|
5515
|
-
var
|
|
5583
|
+
var import_shared82 = require("@xeno-js/shared");
|
|
5584
|
+
var import_shared83 = require("@xeno-js/shared");
|
|
5516
5585
|
var Repository = class {
|
|
5517
5586
|
/**
|
|
5518
5587
|
* Constructs a new Repository instance.
|
|
@@ -5532,35 +5601,35 @@ var Repository = class {
|
|
|
5532
5601
|
_dataSource;
|
|
5533
5602
|
_mapper;
|
|
5534
5603
|
async findById(id, ctx, signal) {
|
|
5535
|
-
|
|
5604
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.findById");
|
|
5536
5605
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5537
|
-
if (
|
|
5606
|
+
if (import_shared83.Guards.isNullOrEmpty(result)) return import_shared82.Result.ok();
|
|
5538
5607
|
const entity = this._mapper.toEntity(result);
|
|
5539
|
-
return
|
|
5608
|
+
return import_shared82.Result.ok(entity);
|
|
5540
5609
|
}
|
|
5541
5610
|
async findAll(ctx, signal) {
|
|
5542
|
-
|
|
5611
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.findAll");
|
|
5543
5612
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5544
5613
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5545
|
-
return
|
|
5614
|
+
return import_shared82.Result.ok(entities);
|
|
5546
5615
|
}
|
|
5547
5616
|
async save(entity, signal) {
|
|
5548
5617
|
const dto = this._mapper.toDto(entity);
|
|
5549
|
-
|
|
5618
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.save");
|
|
5550
5619
|
await this._dataSource.insert(dto, signal);
|
|
5551
|
-
return
|
|
5620
|
+
return import_shared82.Result.ok();
|
|
5552
5621
|
}
|
|
5553
5622
|
async delete(entity, ctx, signal) {
|
|
5554
5623
|
const dto = this._mapper.toDto(entity);
|
|
5555
|
-
|
|
5624
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.delete");
|
|
5556
5625
|
await this._dataSource.delete(dto, ctx, signal);
|
|
5557
|
-
return
|
|
5626
|
+
return import_shared82.Result.ok();
|
|
5558
5627
|
}
|
|
5559
5628
|
async update(id, entity, ctx, signal) {
|
|
5560
5629
|
const dto = this._mapper.toPartialDto(entity);
|
|
5561
|
-
|
|
5630
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.update");
|
|
5562
5631
|
await this._dataSource.update(id, dto, ctx, signal);
|
|
5563
|
-
return
|
|
5632
|
+
return import_shared82.Result.ok();
|
|
5564
5633
|
}
|
|
5565
5634
|
};
|
|
5566
5635
|
|
|
@@ -5578,7 +5647,7 @@ __reExport(drizzle_types_exports, require("drizzle-orm"));
|
|
|
5578
5647
|
__reExport(index_exports, drizzle_types_exports, module.exports);
|
|
5579
5648
|
init_presentation();
|
|
5580
5649
|
__reExport(index_exports, require("@xeno-js/shared"), module.exports);
|
|
5581
|
-
var
|
|
5650
|
+
var import_shared84 = require("@xeno-js/shared");
|
|
5582
5651
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5583
5652
|
0 && (module.exports = {
|
|
5584
5653
|
AppBuilder,
|