@xeno-js/core 0.1.5 → 0.1.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 +214 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -1
- package/dist/index.d.ts +41 -1
- package/dist/index.js +203 -104
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1509,15 +1509,15 @@ var init_logger_utils = __esm({
|
|
|
1509
1509
|
*/
|
|
1510
1510
|
async addLogger(container, opts) {
|
|
1511
1511
|
const loggerDependencies = [];
|
|
1512
|
-
const { Guards:
|
|
1513
|
-
if (!
|
|
1512
|
+
const { Guards: Guards47, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
1513
|
+
if (!Guards47.isDefined(opts) || opts.console) {
|
|
1514
1514
|
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
1515
1515
|
container.addSingleton(TOKENS4.CONSOLE_LOGGER, () => new ConsoleLogger2(opts?.level));
|
|
1516
1516
|
loggerDependencies.push(TOKENS4.CONSOLE_LOGGER);
|
|
1517
1517
|
}
|
|
1518
1518
|
const customLoggerFactories = [];
|
|
1519
|
-
if (
|
|
1520
|
-
if (
|
|
1519
|
+
if (Guards47.isDefined(opts)) {
|
|
1520
|
+
if (Guards47.isDefined(opts.sentry.config)) {
|
|
1521
1521
|
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
1522
1522
|
container.addSingleton(TOKENS4.SENTRY_LOGGER, () => {
|
|
1523
1523
|
const factory = new SentryLoggerFactory2();
|
|
@@ -1525,7 +1525,7 @@ var init_logger_utils = __esm({
|
|
|
1525
1525
|
});
|
|
1526
1526
|
loggerDependencies.push(TOKENS4.SENTRY_LOGGER);
|
|
1527
1527
|
}
|
|
1528
|
-
if (
|
|
1528
|
+
if (Guards47.isDefined(opts.pino.config)) {
|
|
1529
1529
|
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
1530
1530
|
container.addSingleton(TOKENS4.PINO_LOGGER, () => {
|
|
1531
1531
|
const factory = new PinoLoggerFactory2();
|
|
@@ -1533,10 +1533,10 @@ var init_logger_utils = __esm({
|
|
|
1533
1533
|
});
|
|
1534
1534
|
loggerDependencies.push(TOKENS4.PINO_LOGGER);
|
|
1535
1535
|
}
|
|
1536
|
-
if (!
|
|
1536
|
+
if (!Guards47.isNullOrEmpty(opts.customLoggers)) {
|
|
1537
1537
|
const customLoggers = opts.customLoggers;
|
|
1538
1538
|
customLoggers.forEach((f) => {
|
|
1539
|
-
if (
|
|
1539
|
+
if (Guards47.isDefined(f)) {
|
|
1540
1540
|
customLoggerFactories.push(f);
|
|
1541
1541
|
}
|
|
1542
1542
|
});
|
|
@@ -1709,8 +1709,8 @@ var init_cache_utils = __esm({
|
|
|
1709
1709
|
* @link https://github.com/xeno-js/xeno-js
|
|
1710
1710
|
*/
|
|
1711
1711
|
async addCache(container, opts) {
|
|
1712
|
-
const { Guards:
|
|
1713
|
-
if (!opts.inMemory && !
|
|
1712
|
+
const { Guards: Guards47, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
1713
|
+
if (!opts.inMemory && !Guards47.isDefined(opts.redis)) {
|
|
1714
1714
|
throw new Error(
|
|
1715
1715
|
"No cache strategies are configured. Please provide at least one cache strategy."
|
|
1716
1716
|
);
|
|
@@ -1720,12 +1720,12 @@ var init_cache_utils = __esm({
|
|
|
1720
1720
|
TOKENS4.CACHE_KEY_BUILDER,
|
|
1721
1721
|
(c) => new CacheKeyBuilder(c.resolve(TOKENS4.IDENTITY_ACCESSOR))
|
|
1722
1722
|
);
|
|
1723
|
-
if (opts.inMemory || !
|
|
1723
|
+
if (opts.inMemory || !Guards47.isDefined(opts.redis)) {
|
|
1724
1724
|
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
1725
1725
|
container.addSingleton(TOKENS4.CACHE, () => new InMemoryCacheExtended2());
|
|
1726
1726
|
return;
|
|
1727
1727
|
}
|
|
1728
|
-
if (
|
|
1728
|
+
if (Guards47.isDefined(opts.redis)) {
|
|
1729
1729
|
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
1730
1730
|
container.addSingleton(TOKENS4.CACHE, () => {
|
|
1731
1731
|
const config = opts.redis;
|
|
@@ -1764,6 +1764,17 @@ var init_allow_method_service = __esm({
|
|
|
1764
1764
|
}
|
|
1765
1765
|
return false;
|
|
1766
1766
|
}
|
|
1767
|
+
getMethods(path) {
|
|
1768
|
+
const cleanPath = this.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1769
|
+
const methods = this.findMethods(cleanPath);
|
|
1770
|
+
return import_shared42.Guards.isDefined(methods) ? methods.join(", ").toUpperCase() : "";
|
|
1771
|
+
}
|
|
1772
|
+
findMethods(cleanPath) {
|
|
1773
|
+
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1774
|
+
if (import_shared42.Guards.isDefined(staticMethods)) return staticMethods;
|
|
1775
|
+
for (const route of this._dynamicRoutes) if (route.pattern.test(cleanPath)) return route.methods;
|
|
1776
|
+
return void 0;
|
|
1777
|
+
}
|
|
1767
1778
|
isDynamicPath(path) {
|
|
1768
1779
|
return path.includes(":") || path.includes("{") && path.includes("}");
|
|
1769
1780
|
}
|
|
@@ -2768,8 +2779,8 @@ var init_auth_utils = __esm({
|
|
|
2768
2779
|
const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
2769
2780
|
const pipelines = [];
|
|
2770
2781
|
const strategies = [];
|
|
2771
|
-
const { Guards:
|
|
2772
|
-
if (
|
|
2782
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
2783
|
+
if (Guards47.isDefined(opts.policies)) {
|
|
2773
2784
|
const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2774
2785
|
container.addSingleton(TOKENS4.POLICY_REGISTRY, () => new PolicyRegistry2());
|
|
2775
2786
|
const policyRegistry = opts.policies;
|
|
@@ -2778,16 +2789,16 @@ var init_auth_utils = __esm({
|
|
|
2778
2789
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2779
2790
|
const intentLower = intent.toLowerCase();
|
|
2780
2791
|
registryInstance.addPolicy(intentLower, policy);
|
|
2781
|
-
if (!
|
|
2792
|
+
if (!Guards47.isNullOrEmpty(policy.roles)) {
|
|
2782
2793
|
Policies.add("roles");
|
|
2783
2794
|
}
|
|
2784
|
-
if (!
|
|
2795
|
+
if (!Guards47.isNullOrEmpty(policy.permissions)) {
|
|
2785
2796
|
Policies.add("permissions");
|
|
2786
2797
|
}
|
|
2787
|
-
if (!
|
|
2798
|
+
if (!Guards47.isNullOrEmpty(policy.userId)) {
|
|
2788
2799
|
Policies.add("userId");
|
|
2789
2800
|
}
|
|
2790
|
-
if (!
|
|
2801
|
+
if (!Guards47.isNullOrEmpty(policy.tenantId)) {
|
|
2791
2802
|
Policies.add("tenantId");
|
|
2792
2803
|
}
|
|
2793
2804
|
}
|
|
@@ -2836,10 +2847,10 @@ var init_auth_utils = __esm({
|
|
|
2836
2847
|
strategies.push(TOKENS4.TENANT_AUTHORIZATION_PIPELINE);
|
|
2837
2848
|
}
|
|
2838
2849
|
}
|
|
2839
|
-
if (!
|
|
2850
|
+
if (!Guards47.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2840
2851
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2841
2852
|
customStrategies.forEach((strategyToken, index) => {
|
|
2842
|
-
if (
|
|
2853
|
+
if (Guards47.isDefined(strategyToken)) {
|
|
2843
2854
|
const token = `CUSTOM_AUTHORIZATION_STRATEGY_${index}`;
|
|
2844
2855
|
container.addSingleton(token, (c) => {
|
|
2845
2856
|
return strategyToken(c);
|
|
@@ -3042,7 +3053,7 @@ var init_db_module = __esm({
|
|
|
3042
3053
|
"use strict";
|
|
3043
3054
|
DbModule = class {
|
|
3044
3055
|
async configure(container, opts) {
|
|
3045
|
-
const { Guards:
|
|
3056
|
+
const { Guards: Guards47, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3046
3057
|
const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
|
|
3047
3058
|
const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
|
|
3048
3059
|
const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
|
|
@@ -3059,7 +3070,7 @@ var init_db_module = __esm({
|
|
|
3059
3070
|
return new Proxy(db, {
|
|
3060
3071
|
get(_target, prop, receiver) {
|
|
3061
3072
|
const activeState = ttx.state;
|
|
3062
|
-
if (
|
|
3073
|
+
if (Guards47.isDefined(activeState)) {
|
|
3063
3074
|
if (prop === "transaction") {
|
|
3064
3075
|
return activeState.transaction.bind(activeState);
|
|
3065
3076
|
}
|
|
@@ -3096,14 +3107,14 @@ var init_http_utils = __esm({
|
|
|
3096
3107
|
*/
|
|
3097
3108
|
async addAxios(container, opts) {
|
|
3098
3109
|
const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3099
|
-
const { Guards:
|
|
3100
|
-
if (!
|
|
3110
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
3111
|
+
if (!Guards47.isDefined(opts.token)) {
|
|
3101
3112
|
throw new Error("HttpConfig.token is required and must be defined.");
|
|
3102
3113
|
}
|
|
3103
3114
|
container.addSingleton(opts.token, () => {
|
|
3104
3115
|
const factory = new NodeAxiosFactory2();
|
|
3105
3116
|
const instance = factory.create(opts.client);
|
|
3106
|
-
if (!
|
|
3117
|
+
if (!Guards47.hasMethod(instance, "get") || !Guards47.hasMethod(instance, "post") || !Guards47.hasMethod(instance, "put") || !Guards47.hasMethod(instance, "patch") || !Guards47.hasMethod(instance, "delete")) {
|
|
3107
3118
|
throw new Error(
|
|
3108
3119
|
"The created HTTP client instance does not implement the required methods of IHttpClient."
|
|
3109
3120
|
);
|
|
@@ -3130,8 +3141,8 @@ var init_http_utils = __esm({
|
|
|
3130
3141
|
});
|
|
3131
3142
|
},
|
|
3132
3143
|
async addAllowOrigin(container, opts) {
|
|
3133
|
-
const { Guards:
|
|
3134
|
-
if (
|
|
3144
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
3145
|
+
if (Guards47.isNullOrEmpty(opts)) throw new Error("At least an allow origin must be passed");
|
|
3135
3146
|
const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3136
3147
|
const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
3137
3148
|
const allowOrigin = [];
|
|
@@ -3191,13 +3202,13 @@ var init_validation_utils = __esm({
|
|
|
3191
3202
|
* @link https://github.com/xeno-js/xeno-js
|
|
3192
3203
|
*/
|
|
3193
3204
|
async addValidation(container, opts, logger) {
|
|
3194
|
-
const { Guards:
|
|
3195
|
-
if (!
|
|
3205
|
+
const { Guards: Guards47, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3206
|
+
if (!Guards47.isDefined(opts.zod) && Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3196
3207
|
return [];
|
|
3197
3208
|
}
|
|
3198
3209
|
const pipelines = [];
|
|
3199
3210
|
const validationStrategies = [];
|
|
3200
|
-
if (
|
|
3211
|
+
if (Guards47.isDefined(opts.zod)) {
|
|
3201
3212
|
const config = opts.zod;
|
|
3202
3213
|
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_zod_validator_factory(), zod_validator_factory_exports));
|
|
3203
3214
|
container.addSingleton(TOKENS4.ZOD_VALIDATOR, () => {
|
|
@@ -3211,9 +3222,9 @@ var init_validation_utils = __esm({
|
|
|
3211
3222
|
validationStrategies.push(TOKENS4.SCHEMA_VALIDATION_STRATEGY);
|
|
3212
3223
|
}
|
|
3213
3224
|
const customValidationFactory = [];
|
|
3214
|
-
if (!
|
|
3225
|
+
if (!Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3215
3226
|
for (const strategyToken of opts.customValidationStrategy) {
|
|
3216
|
-
if (
|
|
3227
|
+
if (Guards47.isDefined(strategyToken)) {
|
|
3217
3228
|
customValidationFactory.push(strategyToken);
|
|
3218
3229
|
}
|
|
3219
3230
|
}
|
|
@@ -3316,8 +3327,8 @@ var init_pipeline_utils = __esm({
|
|
|
3316
3327
|
*/
|
|
3317
3328
|
async addCommand(container, opts) {
|
|
3318
3329
|
const pipelines = [];
|
|
3319
|
-
const { Guards:
|
|
3320
|
-
if (
|
|
3330
|
+
const { Guards: Guards47, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3331
|
+
if (Guards47.isDefined(opts.idempotency)) {
|
|
3321
3332
|
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency_store(), idempotency_store_exports));
|
|
3322
3333
|
container.addSingleton(
|
|
3323
3334
|
TOKENS4.IDEMPOTENCY_STORE,
|
|
@@ -3337,7 +3348,7 @@ var init_pipeline_utils = __esm({
|
|
|
3337
3348
|
});
|
|
3338
3349
|
pipelines.push(TOKENS4.IDEMPOTENCY_PIPELINE);
|
|
3339
3350
|
}
|
|
3340
|
-
if (
|
|
3351
|
+
if (Guards47.isDefined(opts.concurrency)) {
|
|
3341
3352
|
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3342
3353
|
container.addSingleton(TOKENS4.CONCURRENCY_RETRY_PIPELINE, () => {
|
|
3343
3354
|
const config = opts.concurrency;
|
|
@@ -3417,13 +3428,13 @@ var init_cqrs_module = __esm({
|
|
|
3417
3428
|
return new PerformancePipeline2(logger, thresholdMs);
|
|
3418
3429
|
});
|
|
3419
3430
|
pipelines.push(TOKENS4.PERFORMANCE_PIPELINE);
|
|
3420
|
-
const { Guards:
|
|
3421
|
-
if (
|
|
3431
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
3432
|
+
if (Guards47.isDefined(opts.authorization.policies) || Guards47.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
3422
3433
|
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
3423
3434
|
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
3424
3435
|
pipelines.push(...authPipelines);
|
|
3425
3436
|
}
|
|
3426
|
-
if (
|
|
3437
|
+
if (Guards47.isDefined(opts.validation.zod) || Guards47.isDefined(opts.validation.customValidationStrategy)) {
|
|
3427
3438
|
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
3428
3439
|
const logger = container.resolve(TOKENS4.LOGGER);
|
|
3429
3440
|
const validationPipelines = await ValidationUtils2.addValidation(
|
|
@@ -3435,11 +3446,11 @@ var init_cqrs_module = __esm({
|
|
|
3435
3446
|
}
|
|
3436
3447
|
const commandPipelines = pipelines;
|
|
3437
3448
|
const queryPipelines = pipelines;
|
|
3438
|
-
if ((
|
|
3449
|
+
if ((Guards47.isDefined(opts.commandBus.idempotency) || opts.queryBus.isEnabled) && opts.isCache) {
|
|
3439
3450
|
const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
|
|
3440
3451
|
await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
|
|
3441
3452
|
}
|
|
3442
|
-
if (
|
|
3453
|
+
if (Guards47.isDefined(opts.commandBus.idempotency) || Guards47.isDefined(opts.commandBus.concurrency)) {
|
|
3443
3454
|
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3444
3455
|
const newCommandPipelines = await PipelineUtils2.addCommand(container, {
|
|
3445
3456
|
...opts.commandBus,
|
|
@@ -3622,7 +3633,10 @@ var init_allow_method_middleware = __esm({
|
|
|
3622
3633
|
spanId: tracing?.spanId ?? import_shared62.GuidHelper.generate(),
|
|
3623
3634
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3624
3635
|
},
|
|
3625
|
-
import_shared62.STATUS_CODES.NOT_ALLOWED
|
|
3636
|
+
import_shared62.STATUS_CODES.NOT_ALLOWED,
|
|
3637
|
+
{
|
|
3638
|
+
Allow: this._allowMethod.getMethods(req.path)
|
|
3639
|
+
}
|
|
3626
3640
|
);
|
|
3627
3641
|
}
|
|
3628
3642
|
return await next();
|
|
@@ -3755,11 +3769,13 @@ var init_cors_middleware = __esm({
|
|
|
3755
3769
|
"use strict";
|
|
3756
3770
|
import_shared65 = require("@xeno-js/shared");
|
|
3757
3771
|
CORSMiddleware = class {
|
|
3758
|
-
constructor(_requestContext) {
|
|
3772
|
+
constructor(_requestContext, _withCredentials = "false") {
|
|
3759
3773
|
this._requestContext = _requestContext;
|
|
3774
|
+
this._withCredentials = _withCredentials;
|
|
3760
3775
|
}
|
|
3761
3776
|
_requestContext;
|
|
3762
|
-
|
|
3777
|
+
_withCredentials;
|
|
3778
|
+
async execute(_req, _headers, next) {
|
|
3763
3779
|
const { network } = this._requestContext.getContext() ?? {};
|
|
3764
3780
|
const origin = network?.origin;
|
|
3765
3781
|
const response = await next();
|
|
@@ -3767,7 +3783,7 @@ var init_cors_middleware = __esm({
|
|
|
3767
3783
|
response.headers = {
|
|
3768
3784
|
...response.headers ?? {},
|
|
3769
3785
|
"Access-Control-Allow-Origin": origin,
|
|
3770
|
-
"Access-Control-Allow-Credentials":
|
|
3786
|
+
"Access-Control-Allow-Credentials": this._withCredentials,
|
|
3771
3787
|
"Vary": "Origin"
|
|
3772
3788
|
};
|
|
3773
3789
|
return response;
|
|
@@ -3911,10 +3927,16 @@ var init_options_middleware = __esm({
|
|
|
3911
3927
|
"use strict";
|
|
3912
3928
|
import_shared68 = require("@xeno-js/shared");
|
|
3913
3929
|
OptionsMiddleware = class {
|
|
3914
|
-
constructor(_requestContext) {
|
|
3930
|
+
constructor(_requestContext, _alloewMethod, _allowHeaders = [], _withCredentials = "false") {
|
|
3915
3931
|
this._requestContext = _requestContext;
|
|
3932
|
+
this._alloewMethod = _alloewMethod;
|
|
3933
|
+
this._allowHeaders = _allowHeaders;
|
|
3934
|
+
this._withCredentials = _withCredentials;
|
|
3916
3935
|
}
|
|
3917
3936
|
_requestContext;
|
|
3937
|
+
_alloewMethod;
|
|
3938
|
+
_allowHeaders;
|
|
3939
|
+
_withCredentials;
|
|
3918
3940
|
async execute(req, _headers, next) {
|
|
3919
3941
|
if (req.method.toUpperCase() === "OPTIONS") {
|
|
3920
3942
|
const network = this._requestContext.getNetworkContext();
|
|
@@ -3922,11 +3944,11 @@ var init_options_middleware = __esm({
|
|
|
3922
3944
|
const headers = {};
|
|
3923
3945
|
if (import_shared68.Guards.isDefined(origin)) {
|
|
3924
3946
|
headers["Access-Control-Allow-Origin"] = origin;
|
|
3925
|
-
headers["Access-Control-Allow-Credentials"] =
|
|
3947
|
+
headers["Access-Control-Allow-Credentials"] = this._withCredentials;
|
|
3926
3948
|
headers["Vary"] = "Origin";
|
|
3927
3949
|
}
|
|
3928
|
-
headers["Access-Control-Allow-Methods"] =
|
|
3929
|
-
headers["Access-Control-Allow-Headers"] = "
|
|
3950
|
+
headers["Access-Control-Allow-Methods"] = this._alloewMethod.getMethods(req.path);
|
|
3951
|
+
headers["Access-Control-Allow-Headers"] = this._allowHeaders.join(", ");
|
|
3930
3952
|
return import_shared68.HttpHelper.success(null, import_shared68.STATUS_CODES.NO_CONTENT, {}, headers);
|
|
3931
3953
|
}
|
|
3932
3954
|
return await next();
|
|
@@ -3942,26 +3964,29 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3942
3964
|
"use strict";
|
|
3943
3965
|
import_shared69 = require("@xeno-js/shared");
|
|
3944
3966
|
RateLimitMiddleware = class {
|
|
3945
|
-
constructor(_ctxAccessor, _cache, _logger, _opts) {
|
|
3967
|
+
constructor(_ctxAccessor, _cache, _keyBuilder, _logger, _opts) {
|
|
3946
3968
|
this._ctxAccessor = _ctxAccessor;
|
|
3947
3969
|
this._cache = _cache;
|
|
3970
|
+
this._keyBuilder = _keyBuilder;
|
|
3948
3971
|
this._logger = _logger;
|
|
3949
3972
|
this._opts = _opts;
|
|
3950
3973
|
}
|
|
3951
3974
|
_ctxAccessor;
|
|
3952
3975
|
_cache;
|
|
3976
|
+
_keyBuilder;
|
|
3953
3977
|
_logger;
|
|
3954
3978
|
_opts;
|
|
3955
3979
|
async execute(req, _headers, next) {
|
|
3980
|
+
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3956
3981
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3957
|
-
if (!import_shared69.Guards.isDefined(
|
|
3982
|
+
if (!import_shared69.Guards.isDefined(cacheKey))
|
|
3958
3983
|
return import_shared69.HttpHelper.error(
|
|
3959
3984
|
{
|
|
3960
3985
|
success: false,
|
|
3961
3986
|
error: {
|
|
3962
3987
|
code: import_shared69.ERROR_CODES.SYSTEM_ERROR,
|
|
3963
|
-
message:
|
|
3964
|
-
details: `
|
|
3988
|
+
message: import_shared69.ERROR_CODE_MESSAGES[import_shared69.ERROR_CODES.SYSTEM_ERROR],
|
|
3989
|
+
details: `Bad Request: Unable to identify client context for rate limiting.`,
|
|
3965
3990
|
path: req.path
|
|
3966
3991
|
},
|
|
3967
3992
|
correlationId: tracing?.correlationId ?? import_shared69.GuidHelper.generate(),
|
|
@@ -3975,18 +4000,16 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3975
4000
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
3976
4001
|
}
|
|
3977
4002
|
);
|
|
3978
|
-
const clientIp = network?.clientIp;
|
|
3979
|
-
const cacheKey = `rate_limit:${clientIp}`;
|
|
3980
4003
|
const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
|
|
3981
4004
|
if (currentHits > this._opts.maxRequests) {
|
|
3982
|
-
this._logger.warn(`[RateLimit]
|
|
4005
|
+
this._logger.warn(`[RateLimit] key ${cacheKey} has been blocked on ${req.path}`);
|
|
3983
4006
|
return import_shared69.HttpHelper.error(
|
|
3984
4007
|
{
|
|
3985
4008
|
success: false,
|
|
3986
4009
|
error: {
|
|
3987
4010
|
code: import_shared69.ERROR_CODES.TOO_MANY_REQUESTS,
|
|
3988
|
-
message:
|
|
3989
|
-
details: `
|
|
4011
|
+
message: import_shared69.ERROR_CODE_MESSAGES[import_shared69.ERROR_CODES.TOO_MANY_REQUESTS],
|
|
4012
|
+
details: `Rate limit exceeded. Key ${cacheKey} throttled.`,
|
|
3990
4013
|
path: req.path
|
|
3991
4014
|
},
|
|
3992
4015
|
correlationId: tracing?.correlationId ?? import_shared69.GuidHelper.generate(),
|
|
@@ -4187,16 +4210,60 @@ var init_presentation = __esm({
|
|
|
4187
4210
|
}
|
|
4188
4211
|
});
|
|
4189
4212
|
|
|
4213
|
+
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
4214
|
+
var import_shared72, RateLimitKeyBuilder;
|
|
4215
|
+
var init_rate_limit_key_builder_cache = __esm({
|
|
4216
|
+
"src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
|
|
4217
|
+
"use strict";
|
|
4218
|
+
import_shared72 = require("@xeno-js/shared");
|
|
4219
|
+
RateLimitKeyBuilder = class {
|
|
4220
|
+
constructor(_contextAccessor) {
|
|
4221
|
+
this._contextAccessor = _contextAccessor;
|
|
4222
|
+
}
|
|
4223
|
+
_contextAccessor;
|
|
4224
|
+
buildRateLimitKey(resource) {
|
|
4225
|
+
const ctx = this._contextAccessor.getContext();
|
|
4226
|
+
const tenantId = ctx?.identity?.tenantId;
|
|
4227
|
+
const userId = ctx?.identity?.userId;
|
|
4228
|
+
const clientIp = ctx?.network?.clientIp;
|
|
4229
|
+
if (!import_shared72.Guards.isNullOrEmpty(tenantId) && !import_shared72.Guards.isNullOrEmpty(userId))
|
|
4230
|
+
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
4231
|
+
if (!import_shared72.Guards.isNullOrEmpty(tenantId) && !import_shared72.Guards.isNullOrEmpty(clientIp))
|
|
4232
|
+
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
4233
|
+
if (!import_shared72.Guards.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
4234
|
+
if (!import_shared72.Guards.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
4235
|
+
return void 0;
|
|
4236
|
+
}
|
|
4237
|
+
};
|
|
4238
|
+
}
|
|
4239
|
+
});
|
|
4240
|
+
|
|
4241
|
+
// src/infrastructure/cache/index.ts
|
|
4242
|
+
var cache_exports = {};
|
|
4243
|
+
__export(cache_exports, {
|
|
4244
|
+
InMemoryCacheExtended: () => InMemoryCacheExtended,
|
|
4245
|
+
RateLimitKeyBuilder: () => RateLimitKeyBuilder,
|
|
4246
|
+
RedisCache: () => RedisCache
|
|
4247
|
+
});
|
|
4248
|
+
var init_cache = __esm({
|
|
4249
|
+
"src/infrastructure/cache/index.ts"() {
|
|
4250
|
+
"use strict";
|
|
4251
|
+
init_inmemory_cache();
|
|
4252
|
+
init_rate_limit_key_builder_cache();
|
|
4253
|
+
init_redis_cache();
|
|
4254
|
+
}
|
|
4255
|
+
});
|
|
4256
|
+
|
|
4190
4257
|
// src/infrastructure/modules/middleware.module.ts
|
|
4191
4258
|
var middleware_module_exports = {};
|
|
4192
4259
|
__export(middleware_module_exports, {
|
|
4193
4260
|
MiddlewareModule: () => MiddlewareModule
|
|
4194
4261
|
});
|
|
4195
|
-
var
|
|
4262
|
+
var import_shared73, MiddlewareModule;
|
|
4196
4263
|
var init_middleware_module = __esm({
|
|
4197
4264
|
"src/infrastructure/modules/middleware.module.ts"() {
|
|
4198
4265
|
"use strict";
|
|
4199
|
-
|
|
4266
|
+
import_shared73 = require("@xeno-js/shared");
|
|
4200
4267
|
MiddlewareModule = class {
|
|
4201
4268
|
async configure(container, opts) {
|
|
4202
4269
|
const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
@@ -4240,10 +4307,12 @@ var init_middleware_module = __esm({
|
|
|
4240
4307
|
c.resolve(TOKENS4.LOGGER)
|
|
4241
4308
|
)
|
|
4242
4309
|
);
|
|
4243
|
-
if (!
|
|
4244
|
-
const
|
|
4245
|
-
if (
|
|
4246
|
-
throw new Error(
|
|
4310
|
+
if (!import_shared73.Guards.isNullOrEmpty(opts.allowOrigins)) {
|
|
4311
|
+
const withCredentials2 = opts.httpConfig.withCredentials ?? false;
|
|
4312
|
+
if (withCredentials2 && opts.allowOrigins.includes("*"))
|
|
4313
|
+
throw new Error(
|
|
4314
|
+
"Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
|
|
4315
|
+
);
|
|
4247
4316
|
const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4248
4317
|
container.addSingleton("ALLOW_ORIGIN", () => {
|
|
4249
4318
|
return new AllowOrigin2(opts.allowOrigins);
|
|
@@ -4258,22 +4327,28 @@ var init_middleware_module = __esm({
|
|
|
4258
4327
|
});
|
|
4259
4328
|
middlewares.push(TOKENS4.ALLOW_ORIGIN_MIDDLEWARE);
|
|
4260
4329
|
}
|
|
4330
|
+
const withCredentials = import_shared73.Guards.isDefined(opts.httpConfig.withCredentials) && opts.httpConfig.withCredentials ? "true" : "false";
|
|
4261
4331
|
if (opts.optionsMiddleware) {
|
|
4262
4332
|
const { OptionsMiddleware: OptionsMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4263
4333
|
container.addSingleton(
|
|
4264
4334
|
TOKENS4.OPTIONS_MIDDLEWARE,
|
|
4265
|
-
(c) => new OptionsMiddleware2(
|
|
4335
|
+
(c) => new OptionsMiddleware2(
|
|
4336
|
+
c.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR),
|
|
4337
|
+
c.resolve(TOKENS4.ALLOW_METHOD),
|
|
4338
|
+
opts.allowHeaders,
|
|
4339
|
+
withCredentials
|
|
4340
|
+
)
|
|
4266
4341
|
);
|
|
4267
4342
|
middlewares.push(TOKENS4.OPTIONS_MIDDLEWARE);
|
|
4268
4343
|
}
|
|
4269
4344
|
if (opts.cors) {
|
|
4270
4345
|
const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4271
4346
|
container.addSingleton(TOKENS4.CORS_MIDDLEWARE, (c) => {
|
|
4272
|
-
return new CORSMiddleware2(c.resolve(TOKENS4.CONTEXT_ACCESSOR));
|
|
4347
|
+
return new CORSMiddleware2(c.resolve(TOKENS4.CONTEXT_ACCESSOR), withCredentials);
|
|
4273
4348
|
});
|
|
4274
4349
|
middlewares.push(TOKENS4.CORS_MIDDLEWARE);
|
|
4275
4350
|
}
|
|
4276
|
-
if (
|
|
4351
|
+
if (import_shared73.Guards.isDefined(opts.routeRegistry)) {
|
|
4277
4352
|
const registry = opts.routeRegistry;
|
|
4278
4353
|
const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
4279
4354
|
container.addSingleton(TOKENS4.ALLOW_METHOD, () => new AllowMethodFactory2().create(registry));
|
|
@@ -4297,7 +4372,38 @@ var init_middleware_module = __esm({
|
|
|
4297
4372
|
);
|
|
4298
4373
|
});
|
|
4299
4374
|
middlewares.push(TOKENS4.AUTH_MIDDLEWARE);
|
|
4300
|
-
if (
|
|
4375
|
+
if (import_shared73.Guards.isDefined(opts.rateLimite.maxRequests) || import_shared73.Guards.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4376
|
+
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4377
|
+
import_shared73.Guards.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4378
|
+
import_shared73.Guards.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4379
|
+
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4380
|
+
import_shared73.Guards.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4381
|
+
import_shared73.Guards.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4382
|
+
if (!opts.isCache) {
|
|
4383
|
+
const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
|
|
4384
|
+
await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
|
|
4385
|
+
}
|
|
4386
|
+
const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
|
|
4387
|
+
container.addSingleton(
|
|
4388
|
+
"RATE_LIMIT_KEY_BUILDER",
|
|
4389
|
+
(c) => new RateLimitKeyBuilder2(c.resolve(TOKENS4.REQUEST_CONTEXT))
|
|
4390
|
+
);
|
|
4391
|
+
const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4392
|
+
container.addSingleton(TOKENS4.RATE_LIMITER_MIDDLEWARE, (c) => {
|
|
4393
|
+
return new RateLimitMiddleware2(
|
|
4394
|
+
c.resolve(TOKENS4.CONTEXT_ACCESSOR),
|
|
4395
|
+
c.resolve(TOKENS4.CACHE),
|
|
4396
|
+
c.resolve("RATE_LIMIT_KEY_BUILDER"),
|
|
4397
|
+
c.resolve(TOKENS4.LOGGER),
|
|
4398
|
+
{
|
|
4399
|
+
maxRequests,
|
|
4400
|
+
windowSeconds
|
|
4401
|
+
}
|
|
4402
|
+
);
|
|
4403
|
+
});
|
|
4404
|
+
middlewares.push(TOKENS4.RATE_LIMITER_MIDDLEWARE);
|
|
4405
|
+
}
|
|
4406
|
+
if (import_shared73.Guards.isDefined(opts.csrf)) {
|
|
4301
4407
|
const csrf = opts.csrf;
|
|
4302
4408
|
const { CsrfTokenService: CsrfTokenService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4303
4409
|
container.addSingleton("CSRF_TOKEN_SERVICE", (c) => {
|
|
@@ -4321,31 +4427,6 @@ var init_middleware_module = __esm({
|
|
|
4321
4427
|
});
|
|
4322
4428
|
middlewares.push(TOKENS4.CSRF_MIDDLEWARE);
|
|
4323
4429
|
}
|
|
4324
|
-
if (import_shared72.Guards.isDefined(opts.rateLimite.maxRequests) || import_shared72.Guards.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4325
|
-
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4326
|
-
import_shared72.Guards.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4327
|
-
import_shared72.Guards.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4328
|
-
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4329
|
-
import_shared72.Guards.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4330
|
-
import_shared72.Guards.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4331
|
-
if (!opts.isCache) {
|
|
4332
|
-
const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
|
|
4333
|
-
await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
|
|
4334
|
-
}
|
|
4335
|
-
const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4336
|
-
container.addSingleton(TOKENS4.RATE_LIMITER_MIDDLEWARE, (c) => {
|
|
4337
|
-
return new RateLimitMiddleware2(
|
|
4338
|
-
c.resolve(TOKENS4.CONTEXT_ACCESSOR),
|
|
4339
|
-
c.resolve(TOKENS4.CACHE),
|
|
4340
|
-
c.resolve(TOKENS4.LOGGER),
|
|
4341
|
-
{
|
|
4342
|
-
maxRequests,
|
|
4343
|
-
windowSeconds
|
|
4344
|
-
}
|
|
4345
|
-
);
|
|
4346
|
-
});
|
|
4347
|
-
middlewares.push(TOKENS4.RATE_LIMITER_MIDDLEWARE);
|
|
4348
|
-
}
|
|
4349
4430
|
const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4350
4431
|
container.addSingleton(TOKENS4.MIDDLEWARE, (c) => {
|
|
4351
4432
|
const resolvedMiddleware = middlewares.map(
|
|
@@ -4405,7 +4486,7 @@ __export(index_exports, {
|
|
|
4405
4486
|
BaseAuthorizationStrategy: () => BaseAuthorizationStrategy,
|
|
4406
4487
|
BaseController: () => BaseController,
|
|
4407
4488
|
BaseHandler: () => BaseHandler,
|
|
4408
|
-
BaseQuery: () =>
|
|
4489
|
+
BaseQuery: () => import_shared80.Query,
|
|
4409
4490
|
ContainerUtils: () => ContainerUtils,
|
|
4410
4491
|
ReadDao: () => ReadDao,
|
|
4411
4492
|
Repository: () => Repository,
|
|
@@ -4416,7 +4497,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
4416
4497
|
init_application();
|
|
4417
4498
|
|
|
4418
4499
|
// src/infrastructure/builder/app.builder.ts
|
|
4419
|
-
var
|
|
4500
|
+
var import_shared74 = require("@xeno-js/shared");
|
|
4420
4501
|
|
|
4421
4502
|
// src/infrastructure/configuration/configuration.ts
|
|
4422
4503
|
var import_shared32 = require("@xeno-js/shared");
|
|
@@ -4688,10 +4769,10 @@ var AppBuilder = class {
|
|
|
4688
4769
|
constructor(container) {
|
|
4689
4770
|
this._container = container ?? new ServiceContainer();
|
|
4690
4771
|
this._container.addSingleton(
|
|
4691
|
-
|
|
4772
|
+
import_shared74.TOKENS.CONFIGURATION_SERVICE,
|
|
4692
4773
|
() => new EnvironmentConfigurationService()
|
|
4693
4774
|
);
|
|
4694
|
-
this._configuration = this._container.resolve(
|
|
4775
|
+
this._configuration = this._container.resolve(import_shared74.TOKENS.CONFIGURATION_SERVICE);
|
|
4695
4776
|
this._middlewareConfig.allowOrigins?.push(
|
|
4696
4777
|
this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
|
|
4697
4778
|
);
|
|
@@ -4728,6 +4809,7 @@ var AppBuilder = class {
|
|
|
4728
4809
|
trustedIpHeader: void 0,
|
|
4729
4810
|
trustedProxies: [],
|
|
4730
4811
|
allowOrigins: [],
|
|
4812
|
+
allowHeaders: [],
|
|
4731
4813
|
cors: true
|
|
4732
4814
|
};
|
|
4733
4815
|
_httpConfig = {
|
|
@@ -4804,13 +4886,13 @@ var AppBuilder = class {
|
|
|
4804
4886
|
if (this._isLoggerModuleQueued) return this;
|
|
4805
4887
|
this._isLoggerModuleQueued = true;
|
|
4806
4888
|
const config = {
|
|
4807
|
-
level:
|
|
4889
|
+
level: import_shared74.LOG_LEVEL.DEBUG,
|
|
4808
4890
|
console: true,
|
|
4809
4891
|
sentry: { config: void 0 },
|
|
4810
4892
|
pino: { config: void 0 },
|
|
4811
4893
|
customLoggers: void 0
|
|
4812
4894
|
};
|
|
4813
|
-
if (
|
|
4895
|
+
if (import_shared74.Guards.isDefined(setupAction) && import_shared74.Guards.isDefined(config))
|
|
4814
4896
|
setupAction(config, this._configuration);
|
|
4815
4897
|
this._modules.push({
|
|
4816
4898
|
priority: 3,
|
|
@@ -4836,7 +4918,7 @@ var AppBuilder = class {
|
|
|
4836
4918
|
addCache(setupAction) {
|
|
4837
4919
|
if (this._isCacheModuleQueued) return this;
|
|
4838
4920
|
this._isCacheModuleQueued = true;
|
|
4839
|
-
if (
|
|
4921
|
+
if (import_shared74.Guards.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
4840
4922
|
this._modules.push({
|
|
4841
4923
|
priority: 3,
|
|
4842
4924
|
name: "CacheModule",
|
|
@@ -4945,7 +5027,7 @@ var AppBuilder = class {
|
|
|
4945
5027
|
* @link https://github.com/xeno-js/xeno-js
|
|
4946
5028
|
*/
|
|
4947
5029
|
addPipeline(setupAction) {
|
|
4948
|
-
if (
|
|
5030
|
+
if (import_shared74.Guards.isDefined(setupAction)) {
|
|
4949
5031
|
setupAction(this._pipelineConfig, this._configuration);
|
|
4950
5032
|
}
|
|
4951
5033
|
this._queuePipelineModule();
|
|
@@ -5079,7 +5161,7 @@ var AppBuilder = class {
|
|
|
5079
5161
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
5080
5162
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
5081
5163
|
`);
|
|
5082
|
-
if (error instanceof Error &&
|
|
5164
|
+
if (error instanceof Error && import_shared74.Guards.isDefined(error.stack)) {
|
|
5083
5165
|
console.error(error.stack);
|
|
5084
5166
|
}
|
|
5085
5167
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5171,14 +5253,14 @@ var AppBuilder = class {
|
|
|
5171
5253
|
}
|
|
5172
5254
|
};
|
|
5173
5255
|
|
|
5174
|
-
// src/infrastructure/
|
|
5175
|
-
|
|
5256
|
+
// src/infrastructure/index.ts
|
|
5257
|
+
init_cache();
|
|
5176
5258
|
|
|
5177
5259
|
// src/infrastructure/context/index.ts
|
|
5178
5260
|
init_request_context();
|
|
5179
5261
|
|
|
5180
5262
|
// src/infrastructure/datasources/remote.datasource.ts
|
|
5181
|
-
var
|
|
5263
|
+
var import_shared75 = require("@xeno-js/shared");
|
|
5182
5264
|
|
|
5183
5265
|
// src/infrastructure/index.ts
|
|
5184
5266
|
init_factories();
|
|
@@ -5208,8 +5290,8 @@ init_pipeline_utils();
|
|
|
5208
5290
|
init_validation_utils();
|
|
5209
5291
|
|
|
5210
5292
|
// src/infrastructure/repositories/read-dao.ts
|
|
5211
|
-
var import_shared75 = require("@xeno-js/shared");
|
|
5212
5293
|
var import_shared76 = require("@xeno-js/shared");
|
|
5294
|
+
var import_shared77 = require("@xeno-js/shared");
|
|
5213
5295
|
var ReadDao = class {
|
|
5214
5296
|
/**
|
|
5215
5297
|
* Constructs a new ReadDao instance.
|
|
@@ -5229,23 +5311,23 @@ var ReadDao = class {
|
|
|
5229
5311
|
_dataSource;
|
|
5230
5312
|
_mapper;
|
|
5231
5313
|
async findById(id, ctx, signal) {
|
|
5232
|
-
|
|
5314
|
+
import_shared76.AppError.throwIfAborted(signal, "ReadDao.findById");
|
|
5233
5315
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5234
|
-
if (
|
|
5316
|
+
if (import_shared77.Guards.isNullOrEmpty(result)) return import_shared76.Result.ok();
|
|
5235
5317
|
const entity = this._mapper.toEntity(result);
|
|
5236
|
-
return
|
|
5318
|
+
return import_shared76.Result.ok(entity);
|
|
5237
5319
|
}
|
|
5238
5320
|
async findAll(ctx, signal) {
|
|
5239
|
-
|
|
5321
|
+
import_shared76.AppError.throwIfAborted(signal, "ReadDao.findAll");
|
|
5240
5322
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5241
5323
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5242
|
-
return
|
|
5324
|
+
return import_shared76.Result.ok(entities);
|
|
5243
5325
|
}
|
|
5244
5326
|
};
|
|
5245
5327
|
|
|
5246
5328
|
// src/infrastructure/repositories/repository.ts
|
|
5247
|
-
var import_shared77 = require("@xeno-js/shared");
|
|
5248
5329
|
var import_shared78 = require("@xeno-js/shared");
|
|
5330
|
+
var import_shared79 = require("@xeno-js/shared");
|
|
5249
5331
|
var Repository = class {
|
|
5250
5332
|
/**
|
|
5251
5333
|
* Constructs a new Repository instance.
|
|
@@ -5265,35 +5347,35 @@ var Repository = class {
|
|
|
5265
5347
|
_dataSource;
|
|
5266
5348
|
_mapper;
|
|
5267
5349
|
async findById(id, ctx, signal) {
|
|
5268
|
-
|
|
5350
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.findById");
|
|
5269
5351
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5270
|
-
if (
|
|
5352
|
+
if (import_shared79.Guards.isNullOrEmpty(result)) return import_shared78.Result.ok();
|
|
5271
5353
|
const entity = this._mapper.toEntity(result);
|
|
5272
|
-
return
|
|
5354
|
+
return import_shared78.Result.ok(entity);
|
|
5273
5355
|
}
|
|
5274
5356
|
async findAll(ctx, signal) {
|
|
5275
|
-
|
|
5357
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.findAll");
|
|
5276
5358
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5277
5359
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5278
|
-
return
|
|
5360
|
+
return import_shared78.Result.ok(entities);
|
|
5279
5361
|
}
|
|
5280
5362
|
async save(entity, signal) {
|
|
5281
5363
|
const dto = this._mapper.toDto(entity);
|
|
5282
|
-
|
|
5364
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.save");
|
|
5283
5365
|
await this._dataSource.insert(dto, signal);
|
|
5284
|
-
return
|
|
5366
|
+
return import_shared78.Result.ok();
|
|
5285
5367
|
}
|
|
5286
5368
|
async delete(entity, ctx, signal) {
|
|
5287
5369
|
const dto = this._mapper.toDto(entity);
|
|
5288
|
-
|
|
5370
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.delete");
|
|
5289
5371
|
await this._dataSource.delete(dto, ctx, signal);
|
|
5290
|
-
return
|
|
5372
|
+
return import_shared78.Result.ok();
|
|
5291
5373
|
}
|
|
5292
5374
|
async update(id, entity, ctx, signal) {
|
|
5293
5375
|
const dto = this._mapper.toPartialDto(entity);
|
|
5294
|
-
|
|
5376
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.update");
|
|
5295
5377
|
await this._dataSource.update(id, dto, ctx, signal);
|
|
5296
|
-
return
|
|
5378
|
+
return import_shared78.Result.ok();
|
|
5297
5379
|
}
|
|
5298
5380
|
};
|
|
5299
5381
|
|
|
@@ -5311,7 +5393,7 @@ __reExport(drizzle_types_exports, require("drizzle-orm"));
|
|
|
5311
5393
|
__reExport(index_exports, drizzle_types_exports, module.exports);
|
|
5312
5394
|
init_presentation();
|
|
5313
5395
|
__reExport(index_exports, require("@xeno-js/shared"), module.exports);
|
|
5314
|
-
var
|
|
5396
|
+
var import_shared80 = require("@xeno-js/shared");
|
|
5315
5397
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5316
5398
|
0 && (module.exports = {
|
|
5317
5399
|
AppBuilder,
|
|
@@ -5335,4 +5417,14 @@ var import_shared79 = require("@xeno-js/shared");
|
|
|
5335
5417
|
* @link https://github.com/xeno-js/xeno-js
|
|
5336
5418
|
* @license MIT
|
|
5337
5419
|
*/
|
|
5420
|
+
/**
|
|
5421
|
+
* @description The RateLimitKeyBuilder class implements the IRateLimitKeyBuilder interface, providing a method to build rate limit keys based on the user's identity. This class utilizes an instance of IIdentityAccessor to retrieve the current user's identity, allowing for the creation of tenant-specific rate limit keys in multi-tenant applications. If a tenant ID is present in the identity, the rate limit key is prefixed with the tenant ID; otherwise, it defaults to a public rate limit key. This approach ensures that rate limit data is appropriately scoped to the user's context, preventing data leakage between tenants.
|
|
5422
|
+
*
|
|
5423
|
+
* @author Xeno
|
|
5424
|
+
* @version 1.0.0
|
|
5425
|
+
* @since 2025-09-30
|
|
5426
|
+
* @link https://github.com/xeno-js/xeno-vue
|
|
5427
|
+
* @copyright Xeno
|
|
5428
|
+
* @license MIT
|
|
5429
|
+
*/
|
|
5338
5430
|
//# sourceMappingURL=index.cjs.map
|