@xeno-js/core 1.2.4 → 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 +286 -210
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +170 -94
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1592,7 +1592,7 @@ var init_cookies_service = __esm({
|
|
|
1592
1592
|
contextAccessor;
|
|
1593
1593
|
_config;
|
|
1594
1594
|
_cookieOpts;
|
|
1595
|
-
getAll
|
|
1595
|
+
getAll() {
|
|
1596
1596
|
const network = this.contextAccessor.getNetworkContext();
|
|
1597
1597
|
const req = network?.transport?.req;
|
|
1598
1598
|
if (!import_shared38.Guards.isDefined(req) || import_shared38.Guards.isNullOrEmpty(req.headers.get("cookie"))) return [];
|
|
@@ -1600,8 +1600,8 @@ var init_cookies_service = __esm({
|
|
|
1600
1600
|
const [name, ...rest] = cookie.split("=");
|
|
1601
1601
|
return { name: name.trim(), value: rest.join("=") };
|
|
1602
1602
|
}) ?? [];
|
|
1603
|
-
}
|
|
1604
|
-
setAll
|
|
1603
|
+
}
|
|
1604
|
+
setAll(cookies) {
|
|
1605
1605
|
const network = this.contextAccessor.getNetworkContext();
|
|
1606
1606
|
const res = network?.transport?.res;
|
|
1607
1607
|
if (!import_shared38.Guards.isDefined(res)) return;
|
|
@@ -1611,7 +1611,7 @@ var init_cookies_service = __esm({
|
|
|
1611
1611
|
for (const cookie of [...existingSetCookie, ...serializedCookies]) {
|
|
1612
1612
|
res.headers.append("Set-Cookie", cookie);
|
|
1613
1613
|
}
|
|
1614
|
-
}
|
|
1614
|
+
}
|
|
1615
1615
|
serialize(cookie) {
|
|
1616
1616
|
const safeName = encodeURIComponent(cookie.name);
|
|
1617
1617
|
const safeValue = encodeURIComponent(cookie.value);
|
|
@@ -2583,7 +2583,14 @@ var init_supabase_factory = __esm({
|
|
|
2583
2583
|
const cookieService = this._getCookieSsr(config.ssrOpts, container, config.cookieOpts);
|
|
2584
2584
|
const client = (0, import_ssr.createServerClient)(config.url, config.key, {
|
|
2585
2585
|
...config.opts,
|
|
2586
|
-
cookies:
|
|
2586
|
+
cookies: {
|
|
2587
|
+
getAll() {
|
|
2588
|
+
return cookieService.getAll();
|
|
2589
|
+
},
|
|
2590
|
+
setAll(cookiesToSet) {
|
|
2591
|
+
cookieService.setAll(cookiesToSet);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2587
2594
|
});
|
|
2588
2595
|
const mapper = new import_shared55.SupabaseClaimsMapper();
|
|
2589
2596
|
const sessionMapper = new import_shared55.SupabaseSessionMapper(mapper);
|
|
@@ -2682,8 +2689,8 @@ var init_auth_utils = __esm({
|
|
|
2682
2689
|
async addAuthZ(container, opts) {
|
|
2683
2690
|
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2684
2691
|
const strategies = [];
|
|
2685
|
-
const { Guards:
|
|
2686
|
-
if (
|
|
2692
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
2693
|
+
if (Guards51.isDefined(opts.policies)) {
|
|
2687
2694
|
const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2688
2695
|
const policyRegistry = opts.policies;
|
|
2689
2696
|
const registryInstance = new PolicyRegistry2();
|
|
@@ -2692,16 +2699,16 @@ var init_auth_utils = __esm({
|
|
|
2692
2699
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2693
2700
|
const intentLower = intent.toLowerCase();
|
|
2694
2701
|
registryInstance.addPolicy(intentLower, policy);
|
|
2695
|
-
if (!
|
|
2702
|
+
if (!Guards51.isNullOrEmpty(policy.roles)) {
|
|
2696
2703
|
Policies.add("roles");
|
|
2697
2704
|
}
|
|
2698
|
-
if (!
|
|
2705
|
+
if (!Guards51.isNullOrEmpty(policy.permissions)) {
|
|
2699
2706
|
Policies.add("permissions");
|
|
2700
2707
|
}
|
|
2701
|
-
if (!
|
|
2708
|
+
if (!Guards51.isNullOrEmpty(policy.userId)) {
|
|
2702
2709
|
Policies.add("userId");
|
|
2703
2710
|
}
|
|
2704
|
-
if (!
|
|
2711
|
+
if (!Guards51.isNullOrEmpty(policy.tenantId)) {
|
|
2705
2712
|
Policies.add("tenantId");
|
|
2706
2713
|
}
|
|
2707
2714
|
}
|
|
@@ -2722,10 +2729,10 @@ var init_auth_utils = __esm({
|
|
|
2722
2729
|
strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2723
2730
|
}
|
|
2724
2731
|
}
|
|
2725
|
-
if (!
|
|
2732
|
+
if (!Guards51.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2726
2733
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2727
2734
|
customStrategies.forEach((strategyToken) => {
|
|
2728
|
-
if (
|
|
2735
|
+
if (Guards51.isDefined(strategyToken)) {
|
|
2729
2736
|
strategies.push(strategyToken(container));
|
|
2730
2737
|
}
|
|
2731
2738
|
});
|
|
@@ -2745,8 +2752,8 @@ var init_auth_utils = __esm({
|
|
|
2745
2752
|
* @link https://github.com/xeno-js/xeno-js
|
|
2746
2753
|
*/
|
|
2747
2754
|
async addAuthN(container, opts) {
|
|
2748
|
-
const { Guards:
|
|
2749
|
-
if (
|
|
2755
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2756
|
+
if (Guards51.isDefined(opts.customAuth)) {
|
|
2750
2757
|
const authService = opts.customAuth.authExtendedService();
|
|
2751
2758
|
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2752
2759
|
return authService;
|
|
@@ -2791,12 +2798,12 @@ var init_validation_utils = __esm({
|
|
|
2791
2798
|
* @link https://github.com/xeno-js/xeno-js
|
|
2792
2799
|
*/
|
|
2793
2800
|
async addValidation(container, opts, logger) {
|
|
2794
|
-
const { Guards:
|
|
2795
|
-
if (!
|
|
2801
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2802
|
+
if (!Guards51.isDefined(opts.zod) && Guards51.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
2796
2803
|
return;
|
|
2797
2804
|
}
|
|
2798
2805
|
const validationStrategies = [];
|
|
2799
|
-
if (
|
|
2806
|
+
if (Guards51.isDefined(opts.zod)) {
|
|
2800
2807
|
const config = opts.zod;
|
|
2801
2808
|
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2802
2809
|
const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
@@ -2804,9 +2811,9 @@ var init_validation_utils = __esm({
|
|
|
2804
2811
|
container.addSingleton(TOKENS5.VALIDATOR_SERVICE, () => validatorService);
|
|
2805
2812
|
validationStrategies.push(new SchemaValidationStrategy2(validatorService));
|
|
2806
2813
|
}
|
|
2807
|
-
if (!
|
|
2814
|
+
if (!Guards51.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
2808
2815
|
for (const strategyToken of opts.customValidationStrategy) {
|
|
2809
|
-
if (
|
|
2816
|
+
if (Guards51.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
|
|
2810
2817
|
}
|
|
2811
2818
|
}
|
|
2812
2819
|
const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
@@ -2906,9 +2913,9 @@ var init_pipeline_utils = __esm({
|
|
|
2906
2913
|
* @link https://github.com/xeno-js/xeno-js
|
|
2907
2914
|
*/
|
|
2908
2915
|
async addCommand(container, opts) {
|
|
2909
|
-
const { Guards:
|
|
2916
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2910
2917
|
const pipelines = [];
|
|
2911
|
-
if (
|
|
2918
|
+
if (Guards51.isDefined(opts.idempotency)) {
|
|
2912
2919
|
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
|
|
2913
2920
|
const imdStore = new IdempotencyStore2(
|
|
2914
2921
|
container.resolve(TOKENS5.CACHE),
|
|
@@ -2926,7 +2933,7 @@ var init_pipeline_utils = __esm({
|
|
|
2926
2933
|
)
|
|
2927
2934
|
);
|
|
2928
2935
|
}
|
|
2929
|
-
if (
|
|
2936
|
+
if (Guards51.isDefined(opts.concurrency)) {
|
|
2930
2937
|
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2931
2938
|
const config = opts.concurrency;
|
|
2932
2939
|
pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
|
|
@@ -2983,24 +2990,24 @@ var init_cqrs_module = __esm({
|
|
|
2983
2990
|
new LoggingPipeline2(logger),
|
|
2984
2991
|
new PerformancePipeline2(logger, thresholdMs)
|
|
2985
2992
|
];
|
|
2986
|
-
const { Guards:
|
|
2987
|
-
if (
|
|
2993
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
2994
|
+
if (Guards51.isDefined(opts.authorization.policies) || Guards51.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
2988
2995
|
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
2989
2996
|
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
2990
2997
|
pipelines.push(authPipelines);
|
|
2991
2998
|
}
|
|
2992
|
-
if (
|
|
2999
|
+
if (Guards51.isDefined(opts.validation.zod) || Guards51.isDefined(opts.validation.customValidationStrategy)) {
|
|
2993
3000
|
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
2994
3001
|
const validationPipelines = await ValidationUtils2.addValidation(
|
|
2995
3002
|
container,
|
|
2996
3003
|
opts.validation,
|
|
2997
3004
|
logger
|
|
2998
3005
|
);
|
|
2999
|
-
if (
|
|
3006
|
+
if (Guards51.isDefined(validationPipelines)) pipelines.push(validationPipelines);
|
|
3000
3007
|
}
|
|
3001
3008
|
const commandPipelines = [...pipelines];
|
|
3002
3009
|
const queryPipelines = [...pipelines];
|
|
3003
|
-
if (
|
|
3010
|
+
if (Guards51.isDefined(opts.commandBus.idempotency) || Guards51.isDefined(opts.commandBus.concurrency)) {
|
|
3004
3011
|
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3005
3012
|
const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
|
|
3006
3013
|
commandPipelines.push(...newCommandPipelines);
|
|
@@ -3169,7 +3176,7 @@ var init_db_module = __esm({
|
|
|
3169
3176
|
"use strict";
|
|
3170
3177
|
DbModule = class {
|
|
3171
3178
|
async configure(container, opts) {
|
|
3172
|
-
const { Guards:
|
|
3179
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3173
3180
|
const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
|
|
3174
3181
|
const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
|
|
3175
3182
|
const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
|
|
@@ -3186,7 +3193,7 @@ var init_db_module = __esm({
|
|
|
3186
3193
|
return new Proxy(db, {
|
|
3187
3194
|
get(_target, prop, receiver) {
|
|
3188
3195
|
const activeState = ttx.state;
|
|
3189
|
-
if (
|
|
3196
|
+
if (Guards51.isDefined(activeState)) {
|
|
3190
3197
|
if (prop === "transaction") {
|
|
3191
3198
|
return activeState.transaction.bind(activeState);
|
|
3192
3199
|
}
|
|
@@ -3271,7 +3278,7 @@ var init_base_http_adapter = __esm({
|
|
|
3271
3278
|
* @param body The body.
|
|
3272
3279
|
* @returns The XenoWebTransport.
|
|
3273
3280
|
*/
|
|
3274
|
-
createXenoWebTransport(url, method = "GET", headers, body = void 0) {
|
|
3281
|
+
createXenoWebTransport(url, method = "GET", headers, body = void 0, res = void 0) {
|
|
3275
3282
|
const init2 = {
|
|
3276
3283
|
method: method.toUpperCase(),
|
|
3277
3284
|
headers
|
|
@@ -3283,9 +3290,27 @@ var init_base_http_adapter = __esm({
|
|
|
3283
3290
|
}
|
|
3284
3291
|
const extendedRequest = new Request(url, init2);
|
|
3285
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
|
+
}
|
|
3286
3311
|
return {
|
|
3287
3312
|
request: extendedRequest,
|
|
3288
|
-
response:
|
|
3313
|
+
response: webResponse
|
|
3289
3314
|
};
|
|
3290
3315
|
}
|
|
3291
3316
|
};
|
|
@@ -3293,10 +3318,11 @@ var init_base_http_adapter = __esm({
|
|
|
3293
3318
|
});
|
|
3294
3319
|
|
|
3295
3320
|
// src/infrastructure/http/fastify.http-adapter.ts
|
|
3296
|
-
var FastifyHttpAdapter;
|
|
3321
|
+
var import_shared61, FastifyHttpAdapter;
|
|
3297
3322
|
var init_fastify_http_adapter = __esm({
|
|
3298
3323
|
"src/infrastructure/http/fastify.http-adapter.ts"() {
|
|
3299
3324
|
"use strict";
|
|
3325
|
+
import_shared61 = require("@xeno-js/shared");
|
|
3300
3326
|
init_base_http_adapter();
|
|
3301
3327
|
FastifyHttpAdapter = class extends BaseHttpAdapter {
|
|
3302
3328
|
adapt(req, _res) {
|
|
@@ -3305,6 +3331,29 @@ var init_fastify_http_adapter = __esm({
|
|
|
3305
3331
|
const body = req.body;
|
|
3306
3332
|
return this.createXenoWebTransport(url, req.method, headers, body);
|
|
3307
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
|
+
}
|
|
3308
3357
|
};
|
|
3309
3358
|
}
|
|
3310
3359
|
});
|
|
@@ -3324,15 +3373,19 @@ var init_native_http_adapter = __esm({
|
|
|
3324
3373
|
response: res
|
|
3325
3374
|
};
|
|
3326
3375
|
}
|
|
3376
|
+
handleHeaderChange(_res, _name, _value, _action) {
|
|
3377
|
+
return;
|
|
3378
|
+
}
|
|
3327
3379
|
};
|
|
3328
3380
|
}
|
|
3329
3381
|
});
|
|
3330
3382
|
|
|
3331
3383
|
// src/infrastructure/http/vercel.http-adapter.ts
|
|
3332
|
-
var VercelHttpAdapter;
|
|
3384
|
+
var import_shared62, VercelHttpAdapter;
|
|
3333
3385
|
var init_vercel_http_adapter = __esm({
|
|
3334
3386
|
"src/infrastructure/http/vercel.http-adapter.ts"() {
|
|
3335
3387
|
"use strict";
|
|
3388
|
+
import_shared62 = require("@xeno-js/shared");
|
|
3336
3389
|
init_base_http_adapter();
|
|
3337
3390
|
VercelHttpAdapter = class extends BaseHttpAdapter {
|
|
3338
3391
|
adapt(req, _res) {
|
|
@@ -3340,6 +3393,29 @@ var init_vercel_http_adapter = __esm({
|
|
|
3340
3393
|
const url = this.parseUrl(req.url, req.headers, req.query);
|
|
3341
3394
|
return this.createXenoWebTransport(url, req.method, headers, req.body);
|
|
3342
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
|
+
}
|
|
3343
3419
|
};
|
|
3344
3420
|
}
|
|
3345
3421
|
});
|
|
@@ -3363,11 +3439,11 @@ var init_http = __esm({
|
|
|
3363
3439
|
});
|
|
3364
3440
|
|
|
3365
3441
|
// src/infrastructure/modules/http-adapter.module.ts
|
|
3366
|
-
var
|
|
3442
|
+
var import_shared63, HttpAdapterModule;
|
|
3367
3443
|
var init_http_adapter_module = __esm({
|
|
3368
3444
|
"src/infrastructure/modules/http-adapter.module.ts"() {
|
|
3369
3445
|
"use strict";
|
|
3370
|
-
|
|
3446
|
+
import_shared63 = require("@xeno-js/shared");
|
|
3371
3447
|
HttpAdapterModule = class {
|
|
3372
3448
|
async configure(container, opts) {
|
|
3373
3449
|
const adapter = await this._getAdapter(opts);
|
|
@@ -3380,7 +3456,7 @@ var init_http_adapter_module = __esm({
|
|
|
3380
3456
|
} else if (opts.fastify) {
|
|
3381
3457
|
const { FastifyHttpAdapter: FastifyHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
3382
3458
|
return new FastifyHttpAdapter2();
|
|
3383
|
-
} else if (
|
|
3459
|
+
} else if (import_shared63.Guards.isDefined(opts.custom)) {
|
|
3384
3460
|
return opts.custom();
|
|
3385
3461
|
} else {
|
|
3386
3462
|
const { NativeHttpAdapter: NativeHttpAdapter2 } = await Promise.resolve().then(() => (init_http(), http_exports));
|
|
@@ -3413,14 +3489,14 @@ var init_http_utils = __esm({
|
|
|
3413
3489
|
*/
|
|
3414
3490
|
async addAxios(container, opts) {
|
|
3415
3491
|
const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3416
|
-
const { Guards:
|
|
3417
|
-
if (!
|
|
3492
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
3493
|
+
if (!Guards51.isDefined(opts.token)) {
|
|
3418
3494
|
throw new Error("HttpConfig.token is required and must be defined.");
|
|
3419
3495
|
}
|
|
3420
3496
|
container.addSingleton(opts.token, () => {
|
|
3421
3497
|
const factory = new NodeAxiosFactory2();
|
|
3422
3498
|
const instance = factory.create(opts.client);
|
|
3423
|
-
if (!
|
|
3499
|
+
if (!Guards51.hasMethod(instance, "get") || !Guards51.hasMethod(instance, "post") || !Guards51.hasMethod(instance, "put") || !Guards51.hasMethod(instance, "patch") || !Guards51.hasMethod(instance, "delete")) {
|
|
3424
3500
|
throw new Error(
|
|
3425
3501
|
"The created HTTP client instance does not implement the required methods of IHttpClient."
|
|
3426
3502
|
);
|
|
@@ -3470,11 +3546,11 @@ var init_http_core_module = __esm({
|
|
|
3470
3546
|
});
|
|
3471
3547
|
|
|
3472
3548
|
// src/presentation/controllers/base.controller.ts
|
|
3473
|
-
var
|
|
3549
|
+
var import_shared64, BaseController;
|
|
3474
3550
|
var init_base_controller = __esm({
|
|
3475
3551
|
"src/presentation/controllers/base.controller.ts"() {
|
|
3476
3552
|
"use strict";
|
|
3477
|
-
|
|
3553
|
+
import_shared64 = require("@xeno-js/shared");
|
|
3478
3554
|
BaseController = class {
|
|
3479
3555
|
/**
|
|
3480
3556
|
* Constructs a new instance of the BaseController class.
|
|
@@ -3506,7 +3582,7 @@ var init_base_controller = __esm({
|
|
|
3506
3582
|
* @link https://github.com/xeno-js/xeno-js
|
|
3507
3583
|
*/
|
|
3508
3584
|
ok(data, status = 200, meta = {}, headers = {}) {
|
|
3509
|
-
return
|
|
3585
|
+
return import_shared64.HttpHelper.success(data, status, meta, headers);
|
|
3510
3586
|
}
|
|
3511
3587
|
/**
|
|
3512
3588
|
* Helper to automatically map a failed Result (from the CQRS pipeline)
|
|
@@ -3524,7 +3600,7 @@ var init_base_controller = __esm({
|
|
|
3524
3600
|
fail(error, details = void 0, headers = {}) {
|
|
3525
3601
|
const context = this._requestContext.getContext();
|
|
3526
3602
|
const customHeaders = error["header"];
|
|
3527
|
-
return
|
|
3603
|
+
return import_shared64.HttpHelper.error(
|
|
3528
3604
|
{
|
|
3529
3605
|
success: false,
|
|
3530
3606
|
error: {
|
|
@@ -3533,9 +3609,9 @@ var init_base_controller = __esm({
|
|
|
3533
3609
|
path: context?.network.path,
|
|
3534
3610
|
details: details ?? error.message
|
|
3535
3611
|
},
|
|
3536
|
-
correlationId: context?.tracing.correlationId ??
|
|
3537
|
-
requestId: context?.network.requestId ??
|
|
3538
|
-
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(),
|
|
3539
3615
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3540
3616
|
},
|
|
3541
3617
|
error.status,
|
|
@@ -3590,11 +3666,11 @@ var init_controllers = __esm({
|
|
|
3590
3666
|
});
|
|
3591
3667
|
|
|
3592
3668
|
// src/presentation/middlewares/allow-method.middleware.ts
|
|
3593
|
-
var
|
|
3669
|
+
var import_shared65, MethodCheckMiddleware;
|
|
3594
3670
|
var init_allow_method_middleware = __esm({
|
|
3595
3671
|
"src/presentation/middlewares/allow-method.middleware.ts"() {
|
|
3596
3672
|
"use strict";
|
|
3597
|
-
|
|
3673
|
+
import_shared65 = require("@xeno-js/shared");
|
|
3598
3674
|
MethodCheckMiddleware = class {
|
|
3599
3675
|
constructor(_requestContext, _allowMethod) {
|
|
3600
3676
|
this._requestContext = _requestContext;
|
|
@@ -3606,21 +3682,21 @@ var init_allow_method_middleware = __esm({
|
|
|
3606
3682
|
const isAllowed = this._allowMethod.check(req.path, req.method);
|
|
3607
3683
|
if (!isAllowed) {
|
|
3608
3684
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3609
|
-
return
|
|
3685
|
+
return import_shared65.HttpHelper.error(
|
|
3610
3686
|
{
|
|
3611
3687
|
success: false,
|
|
3612
3688
|
error: {
|
|
3613
|
-
code:
|
|
3614
|
-
message:
|
|
3689
|
+
code: import_shared65.ERROR_CODES.NOT_ALLOWED,
|
|
3690
|
+
message: import_shared65.ERROR_CODE_MESSAGES[import_shared65.ERROR_CODES.NOT_ALLOWED],
|
|
3615
3691
|
details: `Operation blocked by allow method middleware`,
|
|
3616
3692
|
path: req.path
|
|
3617
3693
|
},
|
|
3618
|
-
correlationId: tracing?.correlationId ??
|
|
3619
|
-
requestId: network?.requestId ??
|
|
3620
|
-
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(),
|
|
3621
3697
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3622
3698
|
},
|
|
3623
|
-
|
|
3699
|
+
import_shared65.STATUS_CODES.NOT_ALLOWED,
|
|
3624
3700
|
{
|
|
3625
3701
|
Allow: this._allowMethod.getMethods(req.path)
|
|
3626
3702
|
}
|
|
@@ -3633,11 +3709,11 @@ var init_allow_method_middleware = __esm({
|
|
|
3633
3709
|
});
|
|
3634
3710
|
|
|
3635
3711
|
// src/presentation/middlewares/allow-origin.middleware.ts
|
|
3636
|
-
var
|
|
3712
|
+
var import_shared66, AllowOriginMiddleware;
|
|
3637
3713
|
var init_allow_origin_middleware = __esm({
|
|
3638
3714
|
"src/presentation/middlewares/allow-origin.middleware.ts"() {
|
|
3639
3715
|
"use strict";
|
|
3640
|
-
|
|
3716
|
+
import_shared66 = require("@xeno-js/shared");
|
|
3641
3717
|
AllowOriginMiddleware = class {
|
|
3642
3718
|
constructor(_allowOrigin, _requestContext, _logger) {
|
|
3643
3719
|
this._allowOrigin = _allowOrigin;
|
|
@@ -3652,21 +3728,21 @@ var init_allow_origin_middleware = __esm({
|
|
|
3652
3728
|
const origin = network?.origin;
|
|
3653
3729
|
if (!this._allowOrigin.isAllowed(origin)) {
|
|
3654
3730
|
this._logger.warn(`Access denied by AllowOrigin policy for origin: ${origin ?? "unknown"}`);
|
|
3655
|
-
return
|
|
3731
|
+
return import_shared66.HttpHelper.error(
|
|
3656
3732
|
{
|
|
3657
3733
|
success: false,
|
|
3658
3734
|
error: {
|
|
3659
|
-
code:
|
|
3660
|
-
message:
|
|
3735
|
+
code: import_shared66.ERROR_CODES.FORBIDDEN,
|
|
3736
|
+
message: import_shared66.ERROR_CODE_MESSAGES[import_shared66.ERROR_CODES.FORBIDDEN],
|
|
3661
3737
|
details: `The origin '${origin ?? "unknown"}' is not allowed to access this resource.`,
|
|
3662
3738
|
path: req.path
|
|
3663
3739
|
},
|
|
3664
|
-
correlationId: tracing?.correlationId ??
|
|
3665
|
-
requestId: network?.requestId ??
|
|
3666
|
-
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(),
|
|
3667
3743
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3668
3744
|
},
|
|
3669
|
-
|
|
3745
|
+
import_shared66.STATUS_CODES.FORBIDDEN
|
|
3670
3746
|
);
|
|
3671
3747
|
}
|
|
3672
3748
|
return next();
|
|
@@ -3676,11 +3752,11 @@ var init_allow_origin_middleware = __esm({
|
|
|
3676
3752
|
});
|
|
3677
3753
|
|
|
3678
3754
|
// src/presentation/middlewares/auth.middleware.ts
|
|
3679
|
-
var
|
|
3755
|
+
var import_shared67, AuthenticationMiddleware;
|
|
3680
3756
|
var init_auth_middleware = __esm({
|
|
3681
3757
|
"src/presentation/middlewares/auth.middleware.ts"() {
|
|
3682
3758
|
"use strict";
|
|
3683
|
-
|
|
3759
|
+
import_shared67 = require("@xeno-js/shared");
|
|
3684
3760
|
AuthenticationMiddleware = class {
|
|
3685
3761
|
constructor(_requestContext, _tokenExtractor, _gateKeeper, _logger) {
|
|
3686
3762
|
this._requestContext = _requestContext;
|
|
@@ -3701,7 +3777,7 @@ var init_auth_middleware = __esm({
|
|
|
3701
3777
|
`Authentication failed for request on path: ${req.path}. Code: ${error.code}. Error: ${error}`
|
|
3702
3778
|
);
|
|
3703
3779
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3704
|
-
return
|
|
3780
|
+
return import_shared67.HttpHelper.error(
|
|
3705
3781
|
{
|
|
3706
3782
|
success: false,
|
|
3707
3783
|
error: {
|
|
@@ -3710,12 +3786,12 @@ var init_auth_middleware = __esm({
|
|
|
3710
3786
|
details: `[Authentication Error] Failed to authenticate request on path: ${req.path}`,
|
|
3711
3787
|
path: req.path
|
|
3712
3788
|
},
|
|
3713
|
-
correlationId: tracing?.correlationId ??
|
|
3714
|
-
requestId: network?.requestId ??
|
|
3715
|
-
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(),
|
|
3716
3792
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3717
3793
|
},
|
|
3718
|
-
error.status ??
|
|
3794
|
+
error.status ?? import_shared67.STATUS_CODES.UNAUTHORIZED,
|
|
3719
3795
|
{ "Content-Type": [network?.formatIndicator ?? "application/json"] }
|
|
3720
3796
|
);
|
|
3721
3797
|
}
|
|
@@ -3750,11 +3826,11 @@ var init_composite_middleware = __esm({
|
|
|
3750
3826
|
});
|
|
3751
3827
|
|
|
3752
3828
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3753
|
-
var
|
|
3829
|
+
var import_shared68, CORSMiddleware;
|
|
3754
3830
|
var init_cors_middleware = __esm({
|
|
3755
3831
|
"src/presentation/middlewares/cors.middleware.ts"() {
|
|
3756
3832
|
"use strict";
|
|
3757
|
-
|
|
3833
|
+
import_shared68 = require("@xeno-js/shared");
|
|
3758
3834
|
CORSMiddleware = class {
|
|
3759
3835
|
constructor(_requestContext, _withCredentials = "false") {
|
|
3760
3836
|
this._requestContext = _requestContext;
|
|
@@ -3766,7 +3842,7 @@ var init_cors_middleware = __esm({
|
|
|
3766
3842
|
const { network } = this._requestContext.getContext() ?? {};
|
|
3767
3843
|
const origin = network?.origin;
|
|
3768
3844
|
const response = await next();
|
|
3769
|
-
if (
|
|
3845
|
+
if (import_shared68.Guards.isDefined(origin))
|
|
3770
3846
|
response.headers = {
|
|
3771
3847
|
...response.headers ?? {},
|
|
3772
3848
|
"Access-Control-Allow-Origin": origin,
|
|
@@ -3780,11 +3856,11 @@ var init_cors_middleware = __esm({
|
|
|
3780
3856
|
});
|
|
3781
3857
|
|
|
3782
3858
|
// src/presentation/middlewares/csrf.middleware.ts
|
|
3783
|
-
var
|
|
3859
|
+
var import_shared69, CsrfMiddleware;
|
|
3784
3860
|
var init_csrf_middleware = __esm({
|
|
3785
3861
|
"src/presentation/middlewares/csrf.middleware.ts"() {
|
|
3786
3862
|
"use strict";
|
|
3787
|
-
|
|
3863
|
+
import_shared69 = require("@xeno-js/shared");
|
|
3788
3864
|
CsrfMiddleware = class {
|
|
3789
3865
|
constructor(_requestContext, _csrfTokenService) {
|
|
3790
3866
|
this._requestContext = _requestContext;
|
|
@@ -3799,64 +3875,64 @@ var init_csrf_middleware = __esm({
|
|
|
3799
3875
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3800
3876
|
const headerToken = network?.csrf;
|
|
3801
3877
|
const cookieToken = network?.csrfCookie;
|
|
3802
|
-
if (!
|
|
3803
|
-
return
|
|
3878
|
+
if (!import_shared69.Guards.isDefined(headerToken) || !import_shared69.Guards.isDefined(cookieToken)) {
|
|
3879
|
+
return import_shared69.HttpHelper.error(
|
|
3804
3880
|
{
|
|
3805
3881
|
success: false,
|
|
3806
3882
|
error: {
|
|
3807
|
-
code:
|
|
3808
|
-
message:
|
|
3883
|
+
code: import_shared69.ERROR_CODES.FORBIDDEN,
|
|
3884
|
+
message: import_shared69.ERROR_CODE_MESSAGES[import_shared69.ERROR_CODES.FORBIDDEN],
|
|
3809
3885
|
details: "CSRF token missing",
|
|
3810
3886
|
path: req.path
|
|
3811
3887
|
},
|
|
3812
|
-
correlationId: tracing?.correlationId ??
|
|
3813
|
-
requestId: network?.requestId ??
|
|
3814
|
-
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(),
|
|
3815
3891
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3816
3892
|
},
|
|
3817
|
-
|
|
3893
|
+
import_shared69.STATUS_CODES.FORBIDDEN,
|
|
3818
3894
|
{
|
|
3819
3895
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3820
3896
|
}
|
|
3821
3897
|
);
|
|
3822
3898
|
}
|
|
3823
3899
|
if (headerToken !== cookieToken) {
|
|
3824
|
-
return
|
|
3900
|
+
return import_shared69.HttpHelper.error(
|
|
3825
3901
|
{
|
|
3826
3902
|
success: false,
|
|
3827
3903
|
error: {
|
|
3828
|
-
code:
|
|
3829
|
-
message:
|
|
3904
|
+
code: import_shared69.ERROR_CODES.FORBIDDEN,
|
|
3905
|
+
message: import_shared69.ERROR_CODE_MESSAGES[import_shared69.ERROR_CODES.FORBIDDEN],
|
|
3830
3906
|
details: "CSRF token mismatch",
|
|
3831
3907
|
path: req.path
|
|
3832
3908
|
},
|
|
3833
|
-
correlationId: tracing?.correlationId ??
|
|
3834
|
-
requestId: network?.requestId ??
|
|
3835
|
-
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(),
|
|
3836
3912
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3837
3913
|
},
|
|
3838
|
-
|
|
3914
|
+
import_shared69.STATUS_CODES.FORBIDDEN,
|
|
3839
3915
|
{
|
|
3840
3916
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3841
3917
|
}
|
|
3842
3918
|
);
|
|
3843
3919
|
}
|
|
3844
|
-
if (!
|
|
3845
|
-
return
|
|
3920
|
+
if (!import_shared69.Guards.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3921
|
+
return import_shared69.HttpHelper.error(
|
|
3846
3922
|
{
|
|
3847
3923
|
success: false,
|
|
3848
3924
|
error: {
|
|
3849
|
-
code:
|
|
3850
|
-
message:
|
|
3925
|
+
code: import_shared69.ERROR_CODES.FORBIDDEN,
|
|
3926
|
+
message: import_shared69.ERROR_CODE_MESSAGES[import_shared69.ERROR_CODES.FORBIDDEN],
|
|
3851
3927
|
details: "CSRF token invalid",
|
|
3852
3928
|
path: req.path
|
|
3853
3929
|
},
|
|
3854
|
-
correlationId: tracing?.correlationId ??
|
|
3855
|
-
requestId: network?.requestId ??
|
|
3856
|
-
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(),
|
|
3857
3933
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3858
3934
|
},
|
|
3859
|
-
|
|
3935
|
+
import_shared69.STATUS_CODES.FORBIDDEN,
|
|
3860
3936
|
{
|
|
3861
3937
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3862
3938
|
}
|
|
@@ -3870,11 +3946,11 @@ var init_csrf_middleware = __esm({
|
|
|
3870
3946
|
});
|
|
3871
3947
|
|
|
3872
3948
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3873
|
-
var
|
|
3949
|
+
var import_shared70, CsrfCookieMiddleware;
|
|
3874
3950
|
var init_csrf_cookie_middleware = __esm({
|
|
3875
3951
|
"src/presentation/middlewares/csrf-cookie.middleware.ts"() {
|
|
3876
3952
|
"use strict";
|
|
3877
|
-
|
|
3953
|
+
import_shared70 = require("@xeno-js/shared");
|
|
3878
3954
|
CsrfCookieMiddleware = class {
|
|
3879
3955
|
constructor(_requestContext, _csrfTokenService, _csrf) {
|
|
3880
3956
|
this._requestContext = _requestContext;
|
|
@@ -3889,8 +3965,8 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3889
3965
|
const context = this._requestContext.getContext();
|
|
3890
3966
|
const identity = context?.identity;
|
|
3891
3967
|
const network = context?.network;
|
|
3892
|
-
if (!
|
|
3893
|
-
if (
|
|
3968
|
+
if (!import_shared70.Guards.isDefined(identity?.userId)) return response;
|
|
3969
|
+
if (import_shared70.Guards.isDefined(network?.csrfCookie)) return response;
|
|
3894
3970
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3895
3971
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3896
3972
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3908,11 +3984,11 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3908
3984
|
});
|
|
3909
3985
|
|
|
3910
3986
|
// src/presentation/middlewares/options.middleware.ts
|
|
3911
|
-
var
|
|
3987
|
+
var import_shared71, OptionsMiddleware;
|
|
3912
3988
|
var init_options_middleware = __esm({
|
|
3913
3989
|
"src/presentation/middlewares/options.middleware.ts"() {
|
|
3914
3990
|
"use strict";
|
|
3915
|
-
|
|
3991
|
+
import_shared71 = require("@xeno-js/shared");
|
|
3916
3992
|
OptionsMiddleware = class {
|
|
3917
3993
|
constructor(_requestContext, _alloewMethod, _allowHeaders = [], _withCredentials = "false") {
|
|
3918
3994
|
this._requestContext = _requestContext;
|
|
@@ -3929,14 +4005,14 @@ var init_options_middleware = __esm({
|
|
|
3929
4005
|
const network = this._requestContext.getNetworkContext();
|
|
3930
4006
|
const origin = network?.origin;
|
|
3931
4007
|
const headers = {};
|
|
3932
|
-
if (
|
|
4008
|
+
if (import_shared71.Guards.isDefined(origin)) {
|
|
3933
4009
|
headers["Access-Control-Allow-Origin"] = origin;
|
|
3934
4010
|
headers["Access-Control-Allow-Credentials"] = this._withCredentials;
|
|
3935
4011
|
headers["Vary"] = "Origin";
|
|
3936
4012
|
}
|
|
3937
4013
|
headers["Access-Control-Allow-Methods"] = this._alloewMethod.getMethods(req.path);
|
|
3938
4014
|
headers["Access-Control-Allow-Headers"] = this._allowHeaders.join(", ");
|
|
3939
|
-
return
|
|
4015
|
+
return import_shared71.HttpHelper.success(null, import_shared71.STATUS_CODES.NO_CONTENT, {}, headers);
|
|
3940
4016
|
}
|
|
3941
4017
|
return await next();
|
|
3942
4018
|
}
|
|
@@ -3945,11 +4021,11 @@ var init_options_middleware = __esm({
|
|
|
3945
4021
|
});
|
|
3946
4022
|
|
|
3947
4023
|
// src/presentation/middlewares/rate-limiter.middleware.ts
|
|
3948
|
-
var
|
|
4024
|
+
var import_shared72, RateLimitMiddleware;
|
|
3949
4025
|
var init_rate_limiter_middleware = __esm({
|
|
3950
4026
|
"src/presentation/middlewares/rate-limiter.middleware.ts"() {
|
|
3951
4027
|
"use strict";
|
|
3952
|
-
|
|
4028
|
+
import_shared72 = require("@xeno-js/shared");
|
|
3953
4029
|
RateLimitMiddleware = class {
|
|
3954
4030
|
constructor(_ctxAccessor, _cache, _keyBuilder, _logger, _opts) {
|
|
3955
4031
|
this._ctxAccessor = _ctxAccessor;
|
|
@@ -3966,22 +4042,22 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3966
4042
|
async execute(req, _res, next) {
|
|
3967
4043
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3968
4044
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3969
|
-
if (!
|
|
3970
|
-
return
|
|
4045
|
+
if (!import_shared72.Guards.isDefined(cacheKey))
|
|
4046
|
+
return import_shared72.HttpHelper.error(
|
|
3971
4047
|
{
|
|
3972
4048
|
success: false,
|
|
3973
4049
|
error: {
|
|
3974
|
-
code:
|
|
3975
|
-
message:
|
|
4050
|
+
code: import_shared72.ERROR_CODES.SYSTEM_ERROR,
|
|
4051
|
+
message: import_shared72.ERROR_CODE_MESSAGES[import_shared72.ERROR_CODES.SYSTEM_ERROR],
|
|
3976
4052
|
details: `Bad Request: Unable to identify client context for rate limiting.`,
|
|
3977
4053
|
path: req.path
|
|
3978
4054
|
},
|
|
3979
|
-
correlationId: tracing?.correlationId ??
|
|
3980
|
-
requestId: network?.requestId ??
|
|
3981
|
-
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(),
|
|
3982
4058
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3983
4059
|
},
|
|
3984
|
-
|
|
4060
|
+
import_shared72.STATUS_CODES.SERVICE_UNAVAILABLE,
|
|
3985
4061
|
{
|
|
3986
4062
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3987
4063
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3990,21 +4066,21 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3990
4066
|
const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
|
|
3991
4067
|
if (currentHits > this._opts.maxRequests) {
|
|
3992
4068
|
this._logger.warn(`[RateLimit] key ${cacheKey} has been blocked on ${req.path}`);
|
|
3993
|
-
return
|
|
4069
|
+
return import_shared72.HttpHelper.error(
|
|
3994
4070
|
{
|
|
3995
4071
|
success: false,
|
|
3996
4072
|
error: {
|
|
3997
|
-
code:
|
|
3998
|
-
message:
|
|
4073
|
+
code: import_shared72.ERROR_CODES.TOO_MANY_REQUESTS,
|
|
4074
|
+
message: import_shared72.ERROR_CODE_MESSAGES[import_shared72.ERROR_CODES.TOO_MANY_REQUESTS],
|
|
3999
4075
|
details: `Rate limit exceeded.`,
|
|
4000
4076
|
path: req.path
|
|
4001
4077
|
},
|
|
4002
|
-
correlationId: tracing?.correlationId ??
|
|
4003
|
-
requestId: network?.requestId ??
|
|
4004
|
-
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(),
|
|
4005
4081
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4006
4082
|
},
|
|
4007
|
-
|
|
4083
|
+
import_shared72.STATUS_CODES.TOO_MANY_REQUESTS,
|
|
4008
4084
|
{
|
|
4009
4085
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
4010
4086
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -4019,8 +4095,8 @@ var init_rate_limiter_middleware = __esm({
|
|
|
4019
4095
|
|
|
4020
4096
|
// src/presentation/mappers/context.mapper.ts
|
|
4021
4097
|
function _buildMessagingContext(meta) {
|
|
4022
|
-
const hasSequenceData =
|
|
4023
|
-
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);
|
|
4024
4100
|
const messaging = hasMessagingData ? {
|
|
4025
4101
|
returnAddress: meta.returnAddress,
|
|
4026
4102
|
expiration: meta.expiration,
|
|
@@ -4028,11 +4104,11 @@ function _buildMessagingContext(meta) {
|
|
|
4028
4104
|
} : void 0;
|
|
4029
4105
|
return messaging;
|
|
4030
4106
|
}
|
|
4031
|
-
var
|
|
4107
|
+
var import_shared73, ContextMapper;
|
|
4032
4108
|
var init_context_mapper = __esm({
|
|
4033
4109
|
"src/presentation/mappers/context.mapper.ts"() {
|
|
4034
4110
|
"use strict";
|
|
4035
|
-
|
|
4111
|
+
import_shared73 = require("@xeno-js/shared");
|
|
4036
4112
|
ContextMapper = Object.freeze({
|
|
4037
4113
|
/**
|
|
4038
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.
|
|
@@ -4076,11 +4152,11 @@ var init_context_mapper = __esm({
|
|
|
4076
4152
|
});
|
|
4077
4153
|
|
|
4078
4154
|
// src/presentation/middlewares/request.middleware.ts
|
|
4079
|
-
var
|
|
4155
|
+
var import_shared74, RequestContextMiddleware;
|
|
4080
4156
|
var init_request_middleware = __esm({
|
|
4081
4157
|
"src/presentation/middlewares/request.middleware.ts"() {
|
|
4082
4158
|
"use strict";
|
|
4083
|
-
|
|
4159
|
+
import_shared74 = require("@xeno-js/shared");
|
|
4084
4160
|
init_context_mapper();
|
|
4085
4161
|
RequestContextMiddleware = class {
|
|
4086
4162
|
/**
|
|
@@ -4105,8 +4181,8 @@ var init_request_middleware = __esm({
|
|
|
4105
4181
|
_resolver;
|
|
4106
4182
|
_logger;
|
|
4107
4183
|
async execute(req, res, next) {
|
|
4108
|
-
const correlationId =
|
|
4109
|
-
const requestId =
|
|
4184
|
+
const correlationId = import_shared74.GuidHelper.generate();
|
|
4185
|
+
const requestId = import_shared74.GuidHelper.generate();
|
|
4110
4186
|
const spanId = correlationId;
|
|
4111
4187
|
const formatIndicator = "application/json";
|
|
4112
4188
|
try {
|
|
@@ -4122,7 +4198,7 @@ var init_request_middleware = __esm({
|
|
|
4122
4198
|
};
|
|
4123
4199
|
const tmpContext = ContextMapper.map({
|
|
4124
4200
|
metadata,
|
|
4125
|
-
identity:
|
|
4201
|
+
identity: import_shared74.GUEST,
|
|
4126
4202
|
path: req.path,
|
|
4127
4203
|
transport: { req, res }
|
|
4128
4204
|
});
|
|
@@ -4134,12 +4210,12 @@ var init_request_middleware = __esm({
|
|
|
4134
4210
|
return result;
|
|
4135
4211
|
} catch (error) {
|
|
4136
4212
|
this._logger.error("RequestContextMiddleware encountered an error", error);
|
|
4137
|
-
return
|
|
4213
|
+
return import_shared74.HttpHelper.error(
|
|
4138
4214
|
{
|
|
4139
4215
|
success: false,
|
|
4140
4216
|
error: {
|
|
4141
|
-
code:
|
|
4142
|
-
message:
|
|
4217
|
+
code: import_shared74.ERROR_CODES.SYSTEM_ERROR,
|
|
4218
|
+
message: import_shared74.ERROR_CODE_MESSAGES[import_shared74.ERROR_CODES.SYSTEM_ERROR],
|
|
4143
4219
|
details: `[Fatal System Error] Exception caught during request handling on path: ${req.path}`,
|
|
4144
4220
|
path: req.path
|
|
4145
4221
|
},
|
|
@@ -4148,7 +4224,7 @@ var init_request_middleware = __esm({
|
|
|
4148
4224
|
spanId,
|
|
4149
4225
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4150
4226
|
},
|
|
4151
|
-
|
|
4227
|
+
import_shared74.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
4152
4228
|
{ "Content-Type": [formatIndicator] }
|
|
4153
4229
|
);
|
|
4154
4230
|
}
|
|
@@ -4202,16 +4278,16 @@ var inmemory_cache_exports = {};
|
|
|
4202
4278
|
__export(inmemory_cache_exports, {
|
|
4203
4279
|
InMemoryCacheExtended: () => InMemoryCacheExtended
|
|
4204
4280
|
});
|
|
4205
|
-
var
|
|
4281
|
+
var import_shared75, InMemoryCacheExtended;
|
|
4206
4282
|
var init_inmemory_cache = __esm({
|
|
4207
4283
|
"src/infrastructure/cache/inmemory.cache.ts"() {
|
|
4208
4284
|
"use strict";
|
|
4209
|
-
|
|
4210
|
-
InMemoryCacheExtended = class extends
|
|
4285
|
+
import_shared75 = require("@xeno-js/shared");
|
|
4286
|
+
InMemoryCacheExtended = class extends import_shared75.InMemoryCache {
|
|
4211
4287
|
async increment(key, ttlSeconds) {
|
|
4212
4288
|
const current = await this.get(key) ?? 0;
|
|
4213
4289
|
const next = Number(current) + 1;
|
|
4214
|
-
const ttl =
|
|
4290
|
+
const ttl = import_shared75.Guards.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
4215
4291
|
await this.set(key, next, ttl);
|
|
4216
4292
|
return next;
|
|
4217
4293
|
}
|
|
@@ -4220,11 +4296,11 @@ var init_inmemory_cache = __esm({
|
|
|
4220
4296
|
});
|
|
4221
4297
|
|
|
4222
4298
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
4223
|
-
var
|
|
4299
|
+
var import_shared76, RateLimitKeyBuilder;
|
|
4224
4300
|
var init_rate_limit_key_builder_cache = __esm({
|
|
4225
4301
|
"src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
|
|
4226
4302
|
"use strict";
|
|
4227
|
-
|
|
4303
|
+
import_shared76 = require("@xeno-js/shared");
|
|
4228
4304
|
RateLimitKeyBuilder = class {
|
|
4229
4305
|
constructor(_contextAccessor) {
|
|
4230
4306
|
this._contextAccessor = _contextAccessor;
|
|
@@ -4235,12 +4311,12 @@ var init_rate_limit_key_builder_cache = __esm({
|
|
|
4235
4311
|
const tenantId = ctx?.identity?.tenantId;
|
|
4236
4312
|
const userId = ctx?.identity?.userId;
|
|
4237
4313
|
const clientIp = ctx?.network?.clientIp;
|
|
4238
|
-
if (!
|
|
4314
|
+
if (!import_shared76.Guards.isNullOrEmpty(tenantId) && !import_shared76.Guards.isNullOrEmpty(userId))
|
|
4239
4315
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
4240
|
-
if (!
|
|
4316
|
+
if (!import_shared76.Guards.isNullOrEmpty(tenantId) && !import_shared76.Guards.isNullOrEmpty(clientIp))
|
|
4241
4317
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
4242
|
-
if (!
|
|
4243
|
-
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}`;
|
|
4244
4320
|
return void 0;
|
|
4245
4321
|
}
|
|
4246
4322
|
};
|
|
@@ -4274,7 +4350,7 @@ var init_middleware_module = __esm({
|
|
|
4274
4350
|
"use strict";
|
|
4275
4351
|
MiddlewareModule = class {
|
|
4276
4352
|
async configure(container, opts) {
|
|
4277
|
-
const { Guards:
|
|
4353
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4278
4354
|
const { HttpCookieExtractor: HttpCookieExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4279
4355
|
const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4280
4356
|
const tokenExtractor = await this._getTokenExtractor(
|
|
@@ -4304,7 +4380,7 @@ var init_middleware_module = __esm({
|
|
|
4304
4380
|
logger
|
|
4305
4381
|
)
|
|
4306
4382
|
);
|
|
4307
|
-
if (!
|
|
4383
|
+
if (!Guards51.isNullOrEmpty(opts.allowOrigins)) {
|
|
4308
4384
|
if (opts.withCredentials && opts.allowOrigins.includes("*"))
|
|
4309
4385
|
throw new Error(
|
|
4310
4386
|
"Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
|
|
@@ -4330,7 +4406,7 @@ var init_middleware_module = __esm({
|
|
|
4330
4406
|
const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4331
4407
|
middlewares.push(new CORSMiddleware2(requestContext, withCredentials));
|
|
4332
4408
|
}
|
|
4333
|
-
if (
|
|
4409
|
+
if (Guards51.isDefined(opts.routeRegistry)) {
|
|
4334
4410
|
const { MethodCheckMiddleware: MethodCheckMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4335
4411
|
middlewares.push(new MethodCheckMiddleware2(requestContext, allowMethod));
|
|
4336
4412
|
}
|
|
@@ -4357,13 +4433,13 @@ var init_middleware_module = __esm({
|
|
|
4357
4433
|
)
|
|
4358
4434
|
);
|
|
4359
4435
|
}
|
|
4360
|
-
if (
|
|
4436
|
+
if (Guards51.isDefined(opts.rateLimite.maxRequests) || Guards51.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4361
4437
|
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4362
|
-
|
|
4363
|
-
|
|
4438
|
+
Guards51.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4439
|
+
Guards51.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4364
4440
|
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4365
|
-
|
|
4366
|
-
|
|
4441
|
+
Guards51.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4442
|
+
Guards51.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4367
4443
|
const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
|
|
4368
4444
|
const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4369
4445
|
middlewares.push(
|
|
@@ -4376,7 +4452,7 @@ var init_middleware_module = __esm({
|
|
|
4376
4452
|
)
|
|
4377
4453
|
);
|
|
4378
4454
|
}
|
|
4379
|
-
if (
|
|
4455
|
+
if (Guards51.isDefined(opts.csrf)) {
|
|
4380
4456
|
const csrf = opts.csrf;
|
|
4381
4457
|
const { EdgeCryptoService: EdgeCryptoService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4382
4458
|
container.addSingleton("CRYPTO_SERVICE", () => new EdgeCryptoService2());
|
|
@@ -4401,8 +4477,8 @@ var init_middleware_module = __esm({
|
|
|
4401
4477
|
});
|
|
4402
4478
|
}
|
|
4403
4479
|
async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
|
|
4404
|
-
const { Guards:
|
|
4405
|
-
if (
|
|
4480
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
4481
|
+
if (Guards51.isDefined(customTokenExtractor)) return customTokenExtractor();
|
|
4406
4482
|
if (isSSR) {
|
|
4407
4483
|
const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4408
4484
|
return new SupabaseSsrTokenExtractor2();
|
|
@@ -4412,8 +4488,8 @@ var init_middleware_module = __esm({
|
|
|
4412
4488
|
}
|
|
4413
4489
|
}
|
|
4414
4490
|
async _getAllowMethod(configure, opts) {
|
|
4415
|
-
const { Guards:
|
|
4416
|
-
if (!configure || !
|
|
4491
|
+
const { Guards: Guards51 } = await import("@xeno-js/shared");
|
|
4492
|
+
if (!configure || !Guards51.isDefined(opts)) return void 0;
|
|
4417
4493
|
const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
4418
4494
|
return new AllowMethodFactory2().create(opts);
|
|
4419
4495
|
}
|
|
@@ -4443,8 +4519,8 @@ var init_cache_utils = __esm({
|
|
|
4443
4519
|
* @link https://github.com/xeno-js/xeno-js
|
|
4444
4520
|
*/
|
|
4445
4521
|
async addCache(container, opts) {
|
|
4446
|
-
const { Guards:
|
|
4447
|
-
if (!opts.inMemory && !
|
|
4522
|
+
const { Guards: Guards51, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4523
|
+
if (!opts.inMemory && !Guards51.isDefined(opts.redis)) {
|
|
4448
4524
|
throw new Error(
|
|
4449
4525
|
"No cache strategies are configured. Please provide at least one cache strategy."
|
|
4450
4526
|
);
|
|
@@ -4454,12 +4530,12 @@ var init_cache_utils = __esm({
|
|
|
4454
4530
|
TOKENS5.CACHE_KEY_BUILDER,
|
|
4455
4531
|
(c) => new CacheKeyBuilder(c.resolve(TOKENS5.IDENTITY_ACCESSOR))
|
|
4456
4532
|
);
|
|
4457
|
-
if (opts.inMemory || !
|
|
4533
|
+
if (opts.inMemory || !Guards51.isDefined(opts.redis)) {
|
|
4458
4534
|
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
4459
4535
|
container.addSingleton(TOKENS5.CACHE, () => new InMemoryCacheExtended2());
|
|
4460
4536
|
return;
|
|
4461
4537
|
}
|
|
4462
|
-
if (
|
|
4538
|
+
if (Guards51.isDefined(opts.redis)) {
|
|
4463
4539
|
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
4464
4540
|
container.addSingleton(TOKENS5.CACHE, () => {
|
|
4465
4541
|
const config = opts.redis;
|
|
@@ -4476,11 +4552,11 @@ var console_logger_exports = {};
|
|
|
4476
4552
|
__export(console_logger_exports, {
|
|
4477
4553
|
ConsoleLogger: () => ConsoleLogger
|
|
4478
4554
|
});
|
|
4479
|
-
var
|
|
4555
|
+
var import_shared77, ConsoleLogger;
|
|
4480
4556
|
var init_console_logger = __esm({
|
|
4481
4557
|
"src/infrastructure/loggers/console.logger.ts"() {
|
|
4482
4558
|
"use strict";
|
|
4483
|
-
|
|
4559
|
+
import_shared77 = require("@xeno-js/shared");
|
|
4484
4560
|
ConsoleLogger = class {
|
|
4485
4561
|
/**
|
|
4486
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.
|
|
@@ -4492,22 +4568,22 @@ var init_console_logger = __esm({
|
|
|
4492
4568
|
* @since 2025-09-30
|
|
4493
4569
|
* @link https://github.com/xeno-js/xeno-js
|
|
4494
4570
|
*/
|
|
4495
|
-
constructor(_minLevel =
|
|
4571
|
+
constructor(_minLevel = import_shared77.LOG_LEVEL.DEBUG) {
|
|
4496
4572
|
this._minLevel = _minLevel;
|
|
4497
4573
|
}
|
|
4498
4574
|
_minLevel;
|
|
4499
4575
|
track(level, message, context, error = void 0) {
|
|
4500
4576
|
if (level < this._minLevel) return;
|
|
4501
4577
|
const logMessage = `[${level}] ${message}`;
|
|
4502
|
-
const payload =
|
|
4578
|
+
const payload = import_shared77.Guards.isDefined(error) ? { ...context, error } : context;
|
|
4503
4579
|
switch (level) {
|
|
4504
|
-
case
|
|
4580
|
+
case import_shared77.LOG_LEVEL.ERROR:
|
|
4505
4581
|
console.error(logMessage, payload ?? {});
|
|
4506
4582
|
break;
|
|
4507
|
-
case
|
|
4583
|
+
case import_shared77.LOG_LEVEL.WARN:
|
|
4508
4584
|
console.warn(logMessage, payload ?? {});
|
|
4509
4585
|
break;
|
|
4510
|
-
case
|
|
4586
|
+
case import_shared77.LOG_LEVEL.DEBUG:
|
|
4511
4587
|
console.debug(logMessage, payload ?? {});
|
|
4512
4588
|
break;
|
|
4513
4589
|
default:
|
|
@@ -4543,24 +4619,24 @@ var init_logger_utils = __esm({
|
|
|
4543
4619
|
*/
|
|
4544
4620
|
async addLogger(container, opts) {
|
|
4545
4621
|
const loggerDependencies = [];
|
|
4546
|
-
const { Guards:
|
|
4547
|
-
if (!
|
|
4622
|
+
const { Guards: Guards51, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4623
|
+
if (!Guards51.isDefined(opts) || opts.console) {
|
|
4548
4624
|
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
4549
4625
|
loggerDependencies.push(new ConsoleLogger2(opts?.level));
|
|
4550
4626
|
}
|
|
4551
|
-
if (
|
|
4552
|
-
if (
|
|
4627
|
+
if (Guards51.isDefined(opts)) {
|
|
4628
|
+
if (Guards51.isDefined(opts.sentry.config)) {
|
|
4553
4629
|
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
4554
4630
|
loggerDependencies.push(new SentryLoggerFactory2().create(opts));
|
|
4555
4631
|
}
|
|
4556
|
-
if (
|
|
4632
|
+
if (Guards51.isDefined(opts.pino.config)) {
|
|
4557
4633
|
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
4558
4634
|
loggerDependencies.push(new PinoLoggerFactory2().create(opts));
|
|
4559
4635
|
}
|
|
4560
|
-
if (!
|
|
4636
|
+
if (!Guards51.isNullOrEmpty(opts.customLoggers)) {
|
|
4561
4637
|
const customLoggers = opts.customLoggers;
|
|
4562
4638
|
customLoggers.forEach((fn) => {
|
|
4563
|
-
if (
|
|
4639
|
+
if (Guards51.isDefined(fn)) loggerDependencies.push(fn(container));
|
|
4564
4640
|
});
|
|
4565
4641
|
}
|
|
4566
4642
|
}
|
|
@@ -4626,7 +4702,7 @@ __export(index_exports, {
|
|
|
4626
4702
|
BaseController: () => BaseController,
|
|
4627
4703
|
BaseHandler: () => BaseHandler,
|
|
4628
4704
|
BasePostgresSqlDataSource: () => BasePostgresSqlDataSource,
|
|
4629
|
-
BaseQuery: () =>
|
|
4705
|
+
BaseQuery: () => import_shared84.Query,
|
|
4630
4706
|
BaseSqliteSqlDataSource: () => BaseSqliteSqlDataSource,
|
|
4631
4707
|
ContainerUtils: () => ContainerUtils,
|
|
4632
4708
|
ReadDao: () => ReadDao,
|
|
@@ -4638,7 +4714,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
4638
4714
|
init_application();
|
|
4639
4715
|
|
|
4640
4716
|
// src/infrastructure/builder/app.builder.ts
|
|
4641
|
-
var
|
|
4717
|
+
var import_shared78 = require("@xeno-js/shared");
|
|
4642
4718
|
|
|
4643
4719
|
// src/infrastructure/configuration/configuration.ts
|
|
4644
4720
|
var import_shared32 = require("@xeno-js/shared");
|
|
@@ -4917,10 +4993,10 @@ var AppBuilder = class {
|
|
|
4917
4993
|
constructor(container) {
|
|
4918
4994
|
this._container = container ?? new ServiceContainer();
|
|
4919
4995
|
this._container.addSingleton(
|
|
4920
|
-
|
|
4996
|
+
import_shared78.TOKENS.CONFIGURATION_SERVICE,
|
|
4921
4997
|
() => new EnvironmentConfigurationService()
|
|
4922
4998
|
);
|
|
4923
|
-
this._configuration = this._container.resolve(
|
|
4999
|
+
this._configuration = this._container.resolve(import_shared78.TOKENS.CONFIGURATION_SERVICE);
|
|
4924
5000
|
this._middlewareConfig.allowOrigins?.push(
|
|
4925
5001
|
this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
|
|
4926
5002
|
);
|
|
@@ -5003,7 +5079,7 @@ var AppBuilder = class {
|
|
|
5003
5079
|
resilience: { retry: {}, circuitBreaker: {}, bulkhead: {} }
|
|
5004
5080
|
};
|
|
5005
5081
|
_loggerConfig = {
|
|
5006
|
-
level:
|
|
5082
|
+
level: import_shared78.LOG_LEVEL.DEBUG,
|
|
5007
5083
|
console: true,
|
|
5008
5084
|
sentry: { config: void 0 },
|
|
5009
5085
|
pino: { config: void 0 },
|
|
@@ -5076,7 +5152,7 @@ var AppBuilder = class {
|
|
|
5076
5152
|
* @link https://github.com/xeno-js/xeno-js
|
|
5077
5153
|
*/
|
|
5078
5154
|
addLogger(setupAction) {
|
|
5079
|
-
if (
|
|
5155
|
+
if (import_shared78.Guards.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
|
|
5080
5156
|
if (this._isLoggerModuleQueued) return this;
|
|
5081
5157
|
this._isLoggerModuleQueued = true;
|
|
5082
5158
|
this._modules.push({
|
|
@@ -5101,7 +5177,7 @@ var AppBuilder = class {
|
|
|
5101
5177
|
* @link https://github.com/xeno-js/xeno-js
|
|
5102
5178
|
*/
|
|
5103
5179
|
addCache(setupAction) {
|
|
5104
|
-
if (
|
|
5180
|
+
if (import_shared78.Guards.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
5105
5181
|
if (this._isCacheModuleQueued) return this;
|
|
5106
5182
|
this._isCacheModuleQueued = true;
|
|
5107
5183
|
this._modules.push({
|
|
@@ -5204,7 +5280,7 @@ var AppBuilder = class {
|
|
|
5204
5280
|
* @link https://github.com/xeno-js/xeno-js
|
|
5205
5281
|
*/
|
|
5206
5282
|
addPipeline(setupAction) {
|
|
5207
|
-
if (
|
|
5283
|
+
if (import_shared78.Guards.isDefined(setupAction)) {
|
|
5208
5284
|
setupAction(this._pipelineConfig, this._configuration);
|
|
5209
5285
|
}
|
|
5210
5286
|
this._queuePipelineModule();
|
|
@@ -5325,7 +5401,7 @@ var AppBuilder = class {
|
|
|
5325
5401
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
5326
5402
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
5327
5403
|
`);
|
|
5328
|
-
if (error instanceof Error &&
|
|
5404
|
+
if (error instanceof Error && import_shared78.Guards.isDefined(error.stack)) {
|
|
5329
5405
|
console.error(error.stack);
|
|
5330
5406
|
}
|
|
5331
5407
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5453,7 +5529,7 @@ var BaseSqliteSqlDataSource = class {
|
|
|
5453
5529
|
};
|
|
5454
5530
|
|
|
5455
5531
|
// src/infrastructure/datasources/remote.datasource.ts
|
|
5456
|
-
var
|
|
5532
|
+
var import_shared79 = require("@xeno-js/shared");
|
|
5457
5533
|
|
|
5458
5534
|
// src/infrastructure/index.ts
|
|
5459
5535
|
init_factories();
|
|
@@ -5468,8 +5544,8 @@ init_sentry_logger();
|
|
|
5468
5544
|
init_modules();
|
|
5469
5545
|
|
|
5470
5546
|
// src/infrastructure/repositories/read-dao.ts
|
|
5471
|
-
var
|
|
5472
|
-
var
|
|
5547
|
+
var import_shared80 = require("@xeno-js/shared");
|
|
5548
|
+
var import_shared81 = require("@xeno-js/shared");
|
|
5473
5549
|
var ReadDao = class {
|
|
5474
5550
|
/**
|
|
5475
5551
|
* Constructs a new ReadDao instance.
|
|
@@ -5489,23 +5565,23 @@ var ReadDao = class {
|
|
|
5489
5565
|
_dataSource;
|
|
5490
5566
|
_mapper;
|
|
5491
5567
|
async findById(id, ctx, signal) {
|
|
5492
|
-
|
|
5568
|
+
import_shared80.AppError.throwIfAborted(signal, "ReadDao.findById");
|
|
5493
5569
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5494
|
-
if (
|
|
5570
|
+
if (import_shared81.Guards.isNullOrEmpty(result)) return import_shared80.Result.ok();
|
|
5495
5571
|
const entity = this._mapper.toEntity(result);
|
|
5496
|
-
return
|
|
5572
|
+
return import_shared80.Result.ok(entity);
|
|
5497
5573
|
}
|
|
5498
5574
|
async findAll(ctx, signal) {
|
|
5499
|
-
|
|
5575
|
+
import_shared80.AppError.throwIfAborted(signal, "ReadDao.findAll");
|
|
5500
5576
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5501
5577
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5502
|
-
return
|
|
5578
|
+
return import_shared80.Result.ok(entities);
|
|
5503
5579
|
}
|
|
5504
5580
|
};
|
|
5505
5581
|
|
|
5506
5582
|
// src/infrastructure/repositories/repository.ts
|
|
5507
|
-
var
|
|
5508
|
-
var
|
|
5583
|
+
var import_shared82 = require("@xeno-js/shared");
|
|
5584
|
+
var import_shared83 = require("@xeno-js/shared");
|
|
5509
5585
|
var Repository = class {
|
|
5510
5586
|
/**
|
|
5511
5587
|
* Constructs a new Repository instance.
|
|
@@ -5525,35 +5601,35 @@ var Repository = class {
|
|
|
5525
5601
|
_dataSource;
|
|
5526
5602
|
_mapper;
|
|
5527
5603
|
async findById(id, ctx, signal) {
|
|
5528
|
-
|
|
5604
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.findById");
|
|
5529
5605
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5530
|
-
if (
|
|
5606
|
+
if (import_shared83.Guards.isNullOrEmpty(result)) return import_shared82.Result.ok();
|
|
5531
5607
|
const entity = this._mapper.toEntity(result);
|
|
5532
|
-
return
|
|
5608
|
+
return import_shared82.Result.ok(entity);
|
|
5533
5609
|
}
|
|
5534
5610
|
async findAll(ctx, signal) {
|
|
5535
|
-
|
|
5611
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.findAll");
|
|
5536
5612
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5537
5613
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5538
|
-
return
|
|
5614
|
+
return import_shared82.Result.ok(entities);
|
|
5539
5615
|
}
|
|
5540
5616
|
async save(entity, signal) {
|
|
5541
5617
|
const dto = this._mapper.toDto(entity);
|
|
5542
|
-
|
|
5618
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.save");
|
|
5543
5619
|
await this._dataSource.insert(dto, signal);
|
|
5544
|
-
return
|
|
5620
|
+
return import_shared82.Result.ok();
|
|
5545
5621
|
}
|
|
5546
5622
|
async delete(entity, ctx, signal) {
|
|
5547
5623
|
const dto = this._mapper.toDto(entity);
|
|
5548
|
-
|
|
5624
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.delete");
|
|
5549
5625
|
await this._dataSource.delete(dto, ctx, signal);
|
|
5550
|
-
return
|
|
5626
|
+
return import_shared82.Result.ok();
|
|
5551
5627
|
}
|
|
5552
5628
|
async update(id, entity, ctx, signal) {
|
|
5553
5629
|
const dto = this._mapper.toPartialDto(entity);
|
|
5554
|
-
|
|
5630
|
+
import_shared82.AppError.throwIfAborted(signal, "Repository.update");
|
|
5555
5631
|
await this._dataSource.update(id, dto, ctx, signal);
|
|
5556
|
-
return
|
|
5632
|
+
return import_shared82.Result.ok();
|
|
5557
5633
|
}
|
|
5558
5634
|
};
|
|
5559
5635
|
|
|
@@ -5571,7 +5647,7 @@ __reExport(drizzle_types_exports, require("drizzle-orm"));
|
|
|
5571
5647
|
__reExport(index_exports, drizzle_types_exports, module.exports);
|
|
5572
5648
|
init_presentation();
|
|
5573
5649
|
__reExport(index_exports, require("@xeno-js/shared"), module.exports);
|
|
5574
|
-
var
|
|
5650
|
+
var import_shared84 = require("@xeno-js/shared");
|
|
5575
5651
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5576
5652
|
0 && (module.exports = {
|
|
5577
5653
|
AppBuilder,
|