@xeno-js/core 0.1.3 → 0.1.5
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 +109 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +135 -123
- package/dist/index.js.map +1 -1
- package/package.json +160 -160
package/dist/index.js
CHANGED
|
@@ -1508,15 +1508,15 @@ var init_logger_utils = __esm({
|
|
|
1508
1508
|
*/
|
|
1509
1509
|
async addLogger(container, opts) {
|
|
1510
1510
|
const loggerDependencies = [];
|
|
1511
|
-
const { Guards:
|
|
1512
|
-
if (!
|
|
1511
|
+
const { Guards: Guards46, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
1512
|
+
if (!Guards46.isDefined(opts) || opts.console) {
|
|
1513
1513
|
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
1514
1514
|
container.addSingleton(TOKENS4.CONSOLE_LOGGER, () => new ConsoleLogger2(opts?.level));
|
|
1515
1515
|
loggerDependencies.push(TOKENS4.CONSOLE_LOGGER);
|
|
1516
1516
|
}
|
|
1517
1517
|
const customLoggerFactories = [];
|
|
1518
|
-
if (
|
|
1519
|
-
if (
|
|
1518
|
+
if (Guards46.isDefined(opts)) {
|
|
1519
|
+
if (Guards46.isDefined(opts.sentry.config)) {
|
|
1520
1520
|
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
1521
1521
|
container.addSingleton(TOKENS4.SENTRY_LOGGER, () => {
|
|
1522
1522
|
const factory = new SentryLoggerFactory2();
|
|
@@ -1524,7 +1524,7 @@ var init_logger_utils = __esm({
|
|
|
1524
1524
|
});
|
|
1525
1525
|
loggerDependencies.push(TOKENS4.SENTRY_LOGGER);
|
|
1526
1526
|
}
|
|
1527
|
-
if (
|
|
1527
|
+
if (Guards46.isDefined(opts.pino.config)) {
|
|
1528
1528
|
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
1529
1529
|
container.addSingleton(TOKENS4.PINO_LOGGER, () => {
|
|
1530
1530
|
const factory = new PinoLoggerFactory2();
|
|
@@ -1532,10 +1532,10 @@ var init_logger_utils = __esm({
|
|
|
1532
1532
|
});
|
|
1533
1533
|
loggerDependencies.push(TOKENS4.PINO_LOGGER);
|
|
1534
1534
|
}
|
|
1535
|
-
if (!
|
|
1535
|
+
if (!Guards46.isNullOrEmpty(opts.customLoggers)) {
|
|
1536
1536
|
const customLoggers = opts.customLoggers;
|
|
1537
1537
|
customLoggers.forEach((f) => {
|
|
1538
|
-
if (
|
|
1538
|
+
if (Guards46.isDefined(f)) {
|
|
1539
1539
|
customLoggerFactories.push(f);
|
|
1540
1540
|
}
|
|
1541
1541
|
});
|
|
@@ -1708,8 +1708,8 @@ var init_cache_utils = __esm({
|
|
|
1708
1708
|
* @link https://github.com/xeno-js/xeno-js
|
|
1709
1709
|
*/
|
|
1710
1710
|
async addCache(container, opts) {
|
|
1711
|
-
const { Guards:
|
|
1712
|
-
if (!opts.inMemory && !
|
|
1711
|
+
const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
1712
|
+
if (!opts.inMemory && !Guards46.isDefined(opts.redis)) {
|
|
1713
1713
|
throw new Error(
|
|
1714
1714
|
"No cache strategies are configured. Please provide at least one cache strategy."
|
|
1715
1715
|
);
|
|
@@ -1719,12 +1719,12 @@ var init_cache_utils = __esm({
|
|
|
1719
1719
|
TOKENS4.CACHE_KEY_BUILDER,
|
|
1720
1720
|
(c) => new CacheKeyBuilder(c.resolve(TOKENS4.IDENTITY_ACCESSOR))
|
|
1721
1721
|
);
|
|
1722
|
-
if (opts.inMemory || !
|
|
1722
|
+
if (opts.inMemory || !Guards46.isDefined(opts.redis)) {
|
|
1723
1723
|
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
1724
1724
|
container.addSingleton(TOKENS4.CACHE, () => new InMemoryCacheExtended2());
|
|
1725
1725
|
return;
|
|
1726
1726
|
}
|
|
1727
|
-
if (
|
|
1727
|
+
if (Guards46.isDefined(opts.redis)) {
|
|
1728
1728
|
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
1729
1729
|
container.addSingleton(TOKENS4.CACHE, () => {
|
|
1730
1730
|
const config = opts.redis;
|
|
@@ -1924,29 +1924,20 @@ var init_csrf_token_service = __esm({
|
|
|
1924
1924
|
async generate(subject) {
|
|
1925
1925
|
const randomBuffer = this._cryptoService.randomBytes(32);
|
|
1926
1926
|
const nonce = btoa(String.fromCharCode(...randomBuffer)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
1927
|
-
const signature = await this._cryptoService.hmacSha256(
|
|
1928
|
-
this._secret,
|
|
1929
|
-
`${subject}.${nonce}`
|
|
1930
|
-
);
|
|
1927
|
+
const signature = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1931
1928
|
return `${nonce}.${signature}`;
|
|
1932
1929
|
}
|
|
1933
1930
|
async validate(token, subject) {
|
|
1934
1931
|
const separatorIndex = token.indexOf(".");
|
|
1935
|
-
if (separatorIndex <= 0)
|
|
1936
|
-
return false;
|
|
1932
|
+
if (separatorIndex <= 0) return false;
|
|
1937
1933
|
const nonce = token.slice(0, separatorIndex);
|
|
1938
1934
|
const signature = token.slice(separatorIndex + 1);
|
|
1939
|
-
if (Guards24.isNullOrEmpty(nonce) || Guards24.isNullOrEmpty(signature))
|
|
1940
|
-
|
|
1941
|
-
const expected = await this._cryptoService.hmacSha256(
|
|
1942
|
-
this._secret,
|
|
1943
|
-
`${subject}.${nonce}`
|
|
1944
|
-
);
|
|
1935
|
+
if (Guards24.isNullOrEmpty(nonce) || Guards24.isNullOrEmpty(signature)) return false;
|
|
1936
|
+
const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1945
1937
|
const encoder = new TextEncoder();
|
|
1946
1938
|
const actualBuffer = encoder.encode(signature);
|
|
1947
1939
|
const expectedBuffer = encoder.encode(expected);
|
|
1948
|
-
if (actualBuffer.length !== expectedBuffer.length)
|
|
1949
|
-
return false;
|
|
1940
|
+
if (actualBuffer.length !== expectedBuffer.length) return false;
|
|
1950
1941
|
return this._cryptoService.timingSafeEqual(actualBuffer, expectedBuffer);
|
|
1951
1942
|
}
|
|
1952
1943
|
};
|
|
@@ -2048,15 +2039,12 @@ var init_http_cookie_extractor = __esm({
|
|
|
2048
2039
|
"use strict";
|
|
2049
2040
|
HttpCookieExtractor = class {
|
|
2050
2041
|
extract(cookie) {
|
|
2051
|
-
if (!Guards27.isDefined(cookie.header))
|
|
2052
|
-
return void 0;
|
|
2042
|
+
if (!Guards27.isDefined(cookie.header)) return void 0;
|
|
2053
2043
|
for (const rawCookie of cookie.header.split(";")) {
|
|
2054
2044
|
const separatorIndex = rawCookie.indexOf("=");
|
|
2055
|
-
if (separatorIndex <= 0)
|
|
2056
|
-
continue;
|
|
2045
|
+
if (separatorIndex <= 0) continue;
|
|
2057
2046
|
const name = rawCookie.slice(0, separatorIndex).trim();
|
|
2058
|
-
if (name !== cookie.name)
|
|
2059
|
-
continue;
|
|
2047
|
+
if (name !== cookie.name) continue;
|
|
2060
2048
|
const value = rawCookie.slice(separatorIndex + 1).trim();
|
|
2061
2049
|
try {
|
|
2062
2050
|
return decodeURIComponent(value);
|
|
@@ -2119,12 +2107,10 @@ var init_http_header_extractor = __esm({
|
|
|
2119
2107
|
const expiration = StringHelper4.getSingleValue(headers["x-expiration"]);
|
|
2120
2108
|
const csrf = StringHelper4.getSingleValue(headers["x-csrf-token"]);
|
|
2121
2109
|
const cookieHeader = StringHelper4.getSingleValue(headers["cookie"]);
|
|
2122
|
-
const csrfCookie = this._cookieExtractor.extract(
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
}
|
|
2127
|
-
);
|
|
2110
|
+
const csrfCookie = this._cookieExtractor.extract({
|
|
2111
|
+
header: cookieHeader,
|
|
2112
|
+
name: this._cookieName
|
|
2113
|
+
});
|
|
2128
2114
|
const origin = StringHelper4.getSingleValue(headers["origin"]);
|
|
2129
2115
|
const cleanOrigin = HttpHelper.sanitizeOriginUrl(origin);
|
|
2130
2116
|
const referer = StringHelper4.getSingleValue(headers["referer"]);
|
|
@@ -2244,10 +2230,8 @@ var init_client_ip_resolver = __esm({
|
|
|
2244
2230
|
if (!Guards30.isDefined(socketIp))
|
|
2245
2231
|
return !Guards30.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
2246
2232
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
2247
|
-
if (!isTrustedProxy)
|
|
2248
|
-
|
|
2249
|
-
if (Guards30.isDefined(clientIp))
|
|
2250
|
-
return clientIp.split(",")[0].trim();
|
|
2233
|
+
if (!isTrustedProxy) return socketIp;
|
|
2234
|
+
if (Guards30.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
2251
2235
|
return socketIp;
|
|
2252
2236
|
}
|
|
2253
2237
|
};
|
|
@@ -2805,8 +2789,8 @@ var init_auth_utils = __esm({
|
|
|
2805
2789
|
const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
2806
2790
|
const pipelines = [];
|
|
2807
2791
|
const strategies = [];
|
|
2808
|
-
const { Guards:
|
|
2809
|
-
if (
|
|
2792
|
+
const { Guards: Guards46 } = await import("@xeno-js/shared");
|
|
2793
|
+
if (Guards46.isDefined(opts.policies)) {
|
|
2810
2794
|
const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2811
2795
|
container.addSingleton(TOKENS4.POLICY_REGISTRY, () => new PolicyRegistry2());
|
|
2812
2796
|
const policyRegistry = opts.policies;
|
|
@@ -2815,16 +2799,16 @@ var init_auth_utils = __esm({
|
|
|
2815
2799
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2816
2800
|
const intentLower = intent.toLowerCase();
|
|
2817
2801
|
registryInstance.addPolicy(intentLower, policy);
|
|
2818
|
-
if (!
|
|
2802
|
+
if (!Guards46.isNullOrEmpty(policy.roles)) {
|
|
2819
2803
|
Policies.add("roles");
|
|
2820
2804
|
}
|
|
2821
|
-
if (!
|
|
2805
|
+
if (!Guards46.isNullOrEmpty(policy.permissions)) {
|
|
2822
2806
|
Policies.add("permissions");
|
|
2823
2807
|
}
|
|
2824
|
-
if (!
|
|
2808
|
+
if (!Guards46.isNullOrEmpty(policy.userId)) {
|
|
2825
2809
|
Policies.add("userId");
|
|
2826
2810
|
}
|
|
2827
|
-
if (!
|
|
2811
|
+
if (!Guards46.isNullOrEmpty(policy.tenantId)) {
|
|
2828
2812
|
Policies.add("tenantId");
|
|
2829
2813
|
}
|
|
2830
2814
|
}
|
|
@@ -2873,10 +2857,10 @@ var init_auth_utils = __esm({
|
|
|
2873
2857
|
strategies.push(TOKENS4.TENANT_AUTHORIZATION_PIPELINE);
|
|
2874
2858
|
}
|
|
2875
2859
|
}
|
|
2876
|
-
if (!
|
|
2860
|
+
if (!Guards46.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2877
2861
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2878
2862
|
customStrategies.forEach((strategyToken, index) => {
|
|
2879
|
-
if (
|
|
2863
|
+
if (Guards46.isDefined(strategyToken)) {
|
|
2880
2864
|
const token = `CUSTOM_AUTHORIZATION_STRATEGY_${index}`;
|
|
2881
2865
|
container.addSingleton(token, (c) => {
|
|
2882
2866
|
return strategyToken(c);
|
|
@@ -3079,7 +3063,7 @@ var init_db_module = __esm({
|
|
|
3079
3063
|
"use strict";
|
|
3080
3064
|
DbModule = class {
|
|
3081
3065
|
async configure(container, opts) {
|
|
3082
|
-
const { Guards:
|
|
3066
|
+
const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3083
3067
|
const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
|
|
3084
3068
|
const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
|
|
3085
3069
|
const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
|
|
@@ -3096,7 +3080,7 @@ var init_db_module = __esm({
|
|
|
3096
3080
|
return new Proxy(db, {
|
|
3097
3081
|
get(_target, prop, receiver) {
|
|
3098
3082
|
const activeState = ttx.state;
|
|
3099
|
-
if (
|
|
3083
|
+
if (Guards46.isDefined(activeState)) {
|
|
3100
3084
|
if (prop === "transaction") {
|
|
3101
3085
|
return activeState.transaction.bind(activeState);
|
|
3102
3086
|
}
|
|
@@ -3133,14 +3117,14 @@ var init_http_utils = __esm({
|
|
|
3133
3117
|
*/
|
|
3134
3118
|
async addAxios(container, opts) {
|
|
3135
3119
|
const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3136
|
-
const { Guards:
|
|
3137
|
-
if (!
|
|
3120
|
+
const { Guards: Guards46 } = await import("@xeno-js/shared");
|
|
3121
|
+
if (!Guards46.isDefined(opts.token)) {
|
|
3138
3122
|
throw new Error("HttpConfig.token is required and must be defined.");
|
|
3139
3123
|
}
|
|
3140
3124
|
container.addSingleton(opts.token, () => {
|
|
3141
3125
|
const factory = new NodeAxiosFactory2();
|
|
3142
3126
|
const instance = factory.create(opts.client);
|
|
3143
|
-
if (!
|
|
3127
|
+
if (!Guards46.hasMethod(instance, "get") || !Guards46.hasMethod(instance, "post") || !Guards46.hasMethod(instance, "put") || !Guards46.hasMethod(instance, "patch") || !Guards46.hasMethod(instance, "delete")) {
|
|
3144
3128
|
throw new Error(
|
|
3145
3129
|
"The created HTTP client instance does not implement the required methods of IHttpClient."
|
|
3146
3130
|
);
|
|
@@ -3167,8 +3151,8 @@ var init_http_utils = __esm({
|
|
|
3167
3151
|
});
|
|
3168
3152
|
},
|
|
3169
3153
|
async addAllowOrigin(container, opts) {
|
|
3170
|
-
const { Guards:
|
|
3171
|
-
if (
|
|
3154
|
+
const { Guards: Guards46 } = await import("@xeno-js/shared");
|
|
3155
|
+
if (Guards46.isNullOrEmpty(opts)) throw new Error("At least an allow origin must be passed");
|
|
3172
3156
|
const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3173
3157
|
const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
3174
3158
|
const allowOrigin = [];
|
|
@@ -3228,13 +3212,13 @@ var init_validation_utils = __esm({
|
|
|
3228
3212
|
* @link https://github.com/xeno-js/xeno-js
|
|
3229
3213
|
*/
|
|
3230
3214
|
async addValidation(container, opts, logger) {
|
|
3231
|
-
const { Guards:
|
|
3232
|
-
if (!
|
|
3215
|
+
const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3216
|
+
if (!Guards46.isDefined(opts.zod) && Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3233
3217
|
return [];
|
|
3234
3218
|
}
|
|
3235
3219
|
const pipelines = [];
|
|
3236
3220
|
const validationStrategies = [];
|
|
3237
|
-
if (
|
|
3221
|
+
if (Guards46.isDefined(opts.zod)) {
|
|
3238
3222
|
const config = opts.zod;
|
|
3239
3223
|
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_zod_validator_factory(), zod_validator_factory_exports));
|
|
3240
3224
|
container.addSingleton(TOKENS4.ZOD_VALIDATOR, () => {
|
|
@@ -3248,9 +3232,9 @@ var init_validation_utils = __esm({
|
|
|
3248
3232
|
validationStrategies.push(TOKENS4.SCHEMA_VALIDATION_STRATEGY);
|
|
3249
3233
|
}
|
|
3250
3234
|
const customValidationFactory = [];
|
|
3251
|
-
if (!
|
|
3235
|
+
if (!Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3252
3236
|
for (const strategyToken of opts.customValidationStrategy) {
|
|
3253
|
-
if (
|
|
3237
|
+
if (Guards46.isDefined(strategyToken)) {
|
|
3254
3238
|
customValidationFactory.push(strategyToken);
|
|
3255
3239
|
}
|
|
3256
3240
|
}
|
|
@@ -3353,8 +3337,8 @@ var init_pipeline_utils = __esm({
|
|
|
3353
3337
|
*/
|
|
3354
3338
|
async addCommand(container, opts) {
|
|
3355
3339
|
const pipelines = [];
|
|
3356
|
-
const { Guards:
|
|
3357
|
-
if (
|
|
3340
|
+
const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
|
|
3341
|
+
if (Guards46.isDefined(opts.idempotency)) {
|
|
3358
3342
|
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency_store(), idempotency_store_exports));
|
|
3359
3343
|
container.addSingleton(
|
|
3360
3344
|
TOKENS4.IDEMPOTENCY_STORE,
|
|
@@ -3374,7 +3358,7 @@ var init_pipeline_utils = __esm({
|
|
|
3374
3358
|
});
|
|
3375
3359
|
pipelines.push(TOKENS4.IDEMPOTENCY_PIPELINE);
|
|
3376
3360
|
}
|
|
3377
|
-
if (
|
|
3361
|
+
if (Guards46.isDefined(opts.concurrency)) {
|
|
3378
3362
|
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3379
3363
|
container.addSingleton(TOKENS4.CONCURRENCY_RETRY_PIPELINE, () => {
|
|
3380
3364
|
const config = opts.concurrency;
|
|
@@ -3454,13 +3438,13 @@ var init_cqrs_module = __esm({
|
|
|
3454
3438
|
return new PerformancePipeline2(logger, thresholdMs);
|
|
3455
3439
|
});
|
|
3456
3440
|
pipelines.push(TOKENS4.PERFORMANCE_PIPELINE);
|
|
3457
|
-
const { Guards:
|
|
3458
|
-
if (
|
|
3441
|
+
const { Guards: Guards46 } = await import("@xeno-js/shared");
|
|
3442
|
+
if (Guards46.isDefined(opts.authorization.policies) || Guards46.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
3459
3443
|
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
3460
3444
|
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
3461
3445
|
pipelines.push(...authPipelines);
|
|
3462
3446
|
}
|
|
3463
|
-
if (
|
|
3447
|
+
if (Guards46.isDefined(opts.validation.zod) || Guards46.isDefined(opts.validation.customValidationStrategy)) {
|
|
3464
3448
|
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
3465
3449
|
const logger = container.resolve(TOKENS4.LOGGER);
|
|
3466
3450
|
const validationPipelines = await ValidationUtils2.addValidation(
|
|
@@ -3472,11 +3456,11 @@ var init_cqrs_module = __esm({
|
|
|
3472
3456
|
}
|
|
3473
3457
|
const commandPipelines = pipelines;
|
|
3474
3458
|
const queryPipelines = pipelines;
|
|
3475
|
-
if ((
|
|
3459
|
+
if ((Guards46.isDefined(opts.commandBus.idempotency) || opts.queryBus.isEnabled) && opts.isCache) {
|
|
3476
3460
|
const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
|
|
3477
3461
|
await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
|
|
3478
3462
|
}
|
|
3479
|
-
if (
|
|
3463
|
+
if (Guards46.isDefined(opts.commandBus.idempotency) || Guards46.isDefined(opts.commandBus.concurrency)) {
|
|
3480
3464
|
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3481
3465
|
const newCommandPipelines = await PipelineUtils2.addCommand(container, {
|
|
3482
3466
|
...opts.commandBus,
|
|
@@ -3894,10 +3878,7 @@ var init_csrf_middleware = __esm({
|
|
|
3894
3878
|
}
|
|
3895
3879
|
);
|
|
3896
3880
|
}
|
|
3897
|
-
if (!Guards37.isDefined(identity?.userId) || !await this._csrfTokenService.validate(
|
|
3898
|
-
headerToken,
|
|
3899
|
-
identity?.userId
|
|
3900
|
-
)) {
|
|
3881
|
+
if (!Guards37.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3901
3882
|
return HttpHelper6.error(
|
|
3902
3883
|
{
|
|
3903
3884
|
success: false,
|
|
@@ -3945,10 +3926,8 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3945
3926
|
const context = this._requestContext.getContext();
|
|
3946
3927
|
const identity = context?.identity;
|
|
3947
3928
|
const network = context?.network;
|
|
3948
|
-
if (!Guards38.isDefined(identity?.userId))
|
|
3949
|
-
|
|
3950
|
-
if (Guards38.isDefined(network?.csrfCookie))
|
|
3951
|
-
return response;
|
|
3929
|
+
if (!Guards38.isDefined(identity?.userId)) return response;
|
|
3930
|
+
if (Guards38.isDefined(network?.csrfCookie)) return response;
|
|
3952
3931
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3953
3932
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3954
3933
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3957,10 +3936,7 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3957
3936
|
const existingCookies = response.headers["Set-Cookie"];
|
|
3958
3937
|
response.headers = {
|
|
3959
3938
|
...response.headers ?? {},
|
|
3960
|
-
"Set-Cookie": [
|
|
3961
|
-
...existingCookies ?? [],
|
|
3962
|
-
cookie
|
|
3963
|
-
]
|
|
3939
|
+
"Set-Cookie": [...existingCookies ?? [], cookie]
|
|
3964
3940
|
};
|
|
3965
3941
|
return response;
|
|
3966
3942
|
}
|
|
@@ -4000,7 +3976,7 @@ var init_options_middleware = __esm({
|
|
|
4000
3976
|
});
|
|
4001
3977
|
|
|
4002
3978
|
// src/presentation/middlewares/rate-limiter.middleware.ts
|
|
4003
|
-
import { ERROR_CODES as ERROR_CODES7, GuidHelper as GuidHelper10, HttpHelper as HttpHelper8 } from "@xeno-js/shared";
|
|
3979
|
+
import { ERROR_CODES as ERROR_CODES7, Guards as Guards40, GuidHelper as GuidHelper10, HttpHelper as HttpHelper8, STATUS_CODES as STATUS_CODES9 } from "@xeno-js/shared";
|
|
4004
3980
|
var RateLimitMiddleware;
|
|
4005
3981
|
var init_rate_limiter_middleware = __esm({
|
|
4006
3982
|
"src/presentation/middlewares/rate-limiter.middleware.ts"() {
|
|
@@ -4018,6 +3994,27 @@ var init_rate_limiter_middleware = __esm({
|
|
|
4018
3994
|
_opts;
|
|
4019
3995
|
async execute(req, _headers, next) {
|
|
4020
3996
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3997
|
+
if (!Guards40.isDefined(network?.clientIp))
|
|
3998
|
+
return HttpHelper8.error(
|
|
3999
|
+
{
|
|
4000
|
+
success: false,
|
|
4001
|
+
error: {
|
|
4002
|
+
code: ERROR_CODES7.SYSTEM_ERROR,
|
|
4003
|
+
message: "IP undefined. Please contact the administrator.",
|
|
4004
|
+
details: `IP undefined. Please contact the administrator.`,
|
|
4005
|
+
path: req.path
|
|
4006
|
+
},
|
|
4007
|
+
correlationId: tracing?.correlationId ?? GuidHelper10.generate(),
|
|
4008
|
+
requestId: network?.requestId ?? GuidHelper10.generate(),
|
|
4009
|
+
spanId: tracing?.spanId ?? GuidHelper10.generate(),
|
|
4010
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4011
|
+
},
|
|
4012
|
+
STATUS_CODES9.SERVICE_UNAVAILABLE,
|
|
4013
|
+
{
|
|
4014
|
+
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
4015
|
+
"Retry-After": [String(this._opts.windowSeconds)]
|
|
4016
|
+
}
|
|
4017
|
+
);
|
|
4021
4018
|
const clientIp = network?.clientIp;
|
|
4022
4019
|
const cacheKey = `rate_limit:${clientIp}`;
|
|
4023
4020
|
const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
|
|
@@ -4037,7 +4034,7 @@ var init_rate_limiter_middleware = __esm({
|
|
|
4037
4034
|
spanId: tracing?.spanId ?? GuidHelper10.generate(),
|
|
4038
4035
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4039
4036
|
},
|
|
4040
|
-
|
|
4037
|
+
STATUS_CODES9.TOO_MANY_REQUESTS,
|
|
4041
4038
|
{
|
|
4042
4039
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
4043
4040
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -4051,10 +4048,10 @@ var init_rate_limiter_middleware = __esm({
|
|
|
4051
4048
|
});
|
|
4052
4049
|
|
|
4053
4050
|
// src/presentation/mappers/context.mapper.ts
|
|
4054
|
-
import { Guards as
|
|
4051
|
+
import { Guards as Guards41 } from "@xeno-js/shared";
|
|
4055
4052
|
function _buildMessagingContext(meta) {
|
|
4056
|
-
const hasSequenceData =
|
|
4057
|
-
const hasMessagingData = hasSequenceData ||
|
|
4053
|
+
const hasSequenceData = Guards41.isDefined(meta.sequence?.sequenceId) || Guards41.isDefined(meta.sequence?.position) || Guards41.isDefined(meta.sequence?.size);
|
|
4054
|
+
const hasMessagingData = hasSequenceData || Guards41.isDefined(meta.expiration) || Guards41.isDefined(meta.returnAddress);
|
|
4058
4055
|
const messaging = hasMessagingData ? {
|
|
4059
4056
|
returnAddress: meta.returnAddress,
|
|
4060
4057
|
expiration: meta.expiration,
|
|
@@ -4115,7 +4112,7 @@ import {
|
|
|
4115
4112
|
GUEST as GUEST3,
|
|
4116
4113
|
GuidHelper as GuidHelper11,
|
|
4117
4114
|
HttpHelper as HttpHelper9,
|
|
4118
|
-
STATUS_CODES as
|
|
4115
|
+
STATUS_CODES as STATUS_CODES10
|
|
4119
4116
|
} from "@xeno-js/shared";
|
|
4120
4117
|
var RequestContextMiddleware;
|
|
4121
4118
|
var init_request_middleware = __esm({
|
|
@@ -4188,7 +4185,7 @@ var init_request_middleware = __esm({
|
|
|
4188
4185
|
spanId,
|
|
4189
4186
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4190
4187
|
},
|
|
4191
|
-
|
|
4188
|
+
STATUS_CODES10.INTERNAL_SERVER_ERROR,
|
|
4192
4189
|
{ "Content-Type": [formatIndicator] }
|
|
4193
4190
|
);
|
|
4194
4191
|
}
|
|
@@ -4242,7 +4239,9 @@ var middleware_module_exports = {};
|
|
|
4242
4239
|
__export(middleware_module_exports, {
|
|
4243
4240
|
MiddlewareModule: () => MiddlewareModule
|
|
4244
4241
|
});
|
|
4245
|
-
import {
|
|
4242
|
+
import {
|
|
4243
|
+
Guards as Guards42
|
|
4244
|
+
} from "@xeno-js/shared";
|
|
4246
4245
|
var MiddlewareModule;
|
|
4247
4246
|
var init_middleware_module = __esm({
|
|
4248
4247
|
"src/infrastructure/modules/middleware.module.ts"() {
|
|
@@ -4266,7 +4265,12 @@ var init_middleware_module = __esm({
|
|
|
4266
4265
|
const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4267
4266
|
container.addSingleton(
|
|
4268
4267
|
TOKENS4.SERVICE_EXTRACTOR,
|
|
4269
|
-
(c) => new HttpHeaderExtractor2(
|
|
4268
|
+
(c) => new HttpHeaderExtractor2(
|
|
4269
|
+
c.resolve(TOKENS4.BEARER_TOKEN_EXTRACTOR),
|
|
4270
|
+
c.resolve("COOKIE_EXTRACTOR"),
|
|
4271
|
+
opts.trustedIpHeader,
|
|
4272
|
+
opts.csrf?.cookieName ?? "__Host-xeno-csrf"
|
|
4273
|
+
)
|
|
4270
4274
|
);
|
|
4271
4275
|
if (!opts.isLogger) {
|
|
4272
4276
|
const { LoggerUtils: LoggerUtils2 } = await Promise.resolve().then(() => (init_logger_utils(), logger_utils_exports));
|
|
@@ -4285,16 +4289,9 @@ var init_middleware_module = __esm({
|
|
|
4285
4289
|
c.resolve(TOKENS4.LOGGER)
|
|
4286
4290
|
)
|
|
4287
4291
|
);
|
|
4288
|
-
if (opts.
|
|
4289
|
-
const
|
|
4290
|
-
|
|
4291
|
-
TOKENS4.OPTIONS_MIDDLEWARE,
|
|
4292
|
-
(c) => new OptionsMiddleware2(c.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR))
|
|
4293
|
-
);
|
|
4294
|
-
middlewares.push(TOKENS4.OPTIONS_MIDDLEWARE);
|
|
4295
|
-
}
|
|
4296
|
-
if (!Guards41.isNullOrEmpty(opts.allowOrigins)) {
|
|
4297
|
-
if (Guards41.isDefined(opts.httpConfig.withCredentials) && opts.allowOrigins.includes("*"))
|
|
4292
|
+
if (!Guards42.isNullOrEmpty(opts.allowOrigins)) {
|
|
4293
|
+
const withCredentials = Guards42.isDefined(opts.httpConfig.withCredentials) ? opts.httpConfig.withCredentials : false;
|
|
4294
|
+
if (withCredentials && opts.allowOrigins.includes("*"))
|
|
4298
4295
|
throw new Error("Wildcard CORS origin is not allowed when withCredentials is set to true");
|
|
4299
4296
|
const { AllowOrigin: AllowOrigin2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4300
4297
|
container.addSingleton("ALLOW_ORIGIN", () => {
|
|
@@ -4310,6 +4307,14 @@ var init_middleware_module = __esm({
|
|
|
4310
4307
|
});
|
|
4311
4308
|
middlewares.push(TOKENS4.ALLOW_ORIGIN_MIDDLEWARE);
|
|
4312
4309
|
}
|
|
4310
|
+
if (opts.optionsMiddleware) {
|
|
4311
|
+
const { OptionsMiddleware: OptionsMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4312
|
+
container.addSingleton(
|
|
4313
|
+
TOKENS4.OPTIONS_MIDDLEWARE,
|
|
4314
|
+
(c) => new OptionsMiddleware2(c.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR))
|
|
4315
|
+
);
|
|
4316
|
+
middlewares.push(TOKENS4.OPTIONS_MIDDLEWARE);
|
|
4317
|
+
}
|
|
4313
4318
|
if (opts.cors) {
|
|
4314
4319
|
const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4315
4320
|
container.addSingleton(TOKENS4.CORS_MIDDLEWARE, (c) => {
|
|
@@ -4317,7 +4322,7 @@ var init_middleware_module = __esm({
|
|
|
4317
4322
|
});
|
|
4318
4323
|
middlewares.push(TOKENS4.CORS_MIDDLEWARE);
|
|
4319
4324
|
}
|
|
4320
|
-
if (
|
|
4325
|
+
if (Guards42.isDefined(opts.routeRegistry)) {
|
|
4321
4326
|
const registry = opts.routeRegistry;
|
|
4322
4327
|
const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
4323
4328
|
container.addSingleton(TOKENS4.ALLOW_METHOD, () => new AllowMethodFactory2().create(registry));
|
|
@@ -4341,32 +4346,37 @@ var init_middleware_module = __esm({
|
|
|
4341
4346
|
);
|
|
4342
4347
|
});
|
|
4343
4348
|
middlewares.push(TOKENS4.AUTH_MIDDLEWARE);
|
|
4344
|
-
if (
|
|
4349
|
+
if (Guards42.isDefined(opts.csrf)) {
|
|
4345
4350
|
const csrf = opts.csrf;
|
|
4346
4351
|
const { CsrfTokenService: CsrfTokenService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4347
4352
|
container.addSingleton("CSRF_TOKEN_SERVICE", (c) => {
|
|
4348
|
-
return new CsrfTokenService2(
|
|
4349
|
-
csrf.secret,
|
|
4350
|
-
c.resolve("CRYPTO_SERVICE")
|
|
4351
|
-
);
|
|
4353
|
+
return new CsrfTokenService2(csrf.secret, c.resolve("CRYPTO_SERVICE"));
|
|
4352
4354
|
});
|
|
4353
4355
|
const { CsrfCookieMiddleware: CsrfCookieMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4354
4356
|
container.addSingleton("CSRF_COOKIE_MIDDLEWARE", (c) => {
|
|
4355
|
-
return new CsrfCookieMiddleware2(
|
|
4357
|
+
return new CsrfCookieMiddleware2(
|
|
4358
|
+
c.resolve(TOKENS4.REQUEST_CONTEXT),
|
|
4359
|
+
c.resolve("CSRF_TOKEN_SERVICE"),
|
|
4360
|
+
csrf
|
|
4361
|
+
);
|
|
4356
4362
|
});
|
|
4363
|
+
middlewares.push("CSRF_COOKIE_MIDDLEWARE");
|
|
4357
4364
|
const { CsrfMiddleware: CsrfMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4358
4365
|
container.addSingleton(TOKENS4.CSRF_MIDDLEWARE, (c) => {
|
|
4359
|
-
return new CsrfMiddleware2(
|
|
4366
|
+
return new CsrfMiddleware2(
|
|
4367
|
+
c.resolve(TOKENS4.REQUEST_CONTEXT),
|
|
4368
|
+
c.resolve("CSRF_TOKEN_SERVICE")
|
|
4369
|
+
);
|
|
4360
4370
|
});
|
|
4361
4371
|
middlewares.push(TOKENS4.CSRF_MIDDLEWARE);
|
|
4362
4372
|
}
|
|
4363
|
-
if (
|
|
4373
|
+
if (Guards42.isDefined(opts.rateLimite.maxRequests) || Guards42.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4364
4374
|
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4365
|
-
|
|
4366
|
-
|
|
4375
|
+
Guards42.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4376
|
+
Guards42.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4367
4377
|
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4368
|
-
|
|
4369
|
-
|
|
4378
|
+
Guards42.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4379
|
+
Guards42.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4370
4380
|
if (!opts.isCache) {
|
|
4371
4381
|
const { CacheUtils: CacheUtils2 } = await Promise.resolve().then(() => (init_cache_utils(), cache_utils_exports));
|
|
4372
4382
|
await CacheUtils2.addCache(container, { inMemory: true, redis: void 0 });
|
|
@@ -4454,7 +4464,7 @@ __export(index_exports, {
|
|
|
4454
4464
|
init_application();
|
|
4455
4465
|
|
|
4456
4466
|
// src/infrastructure/builder/app.builder.ts
|
|
4457
|
-
import { Guards as
|
|
4467
|
+
import { Guards as Guards43, LOG_LEVEL as LOG_LEVEL6, TOKENS as TOKENS3 } from "@xeno-js/shared";
|
|
4458
4468
|
|
|
4459
4469
|
// src/infrastructure/configuration/configuration.ts
|
|
4460
4470
|
import { Guards as Guards13 } from "@xeno-js/shared";
|
|
@@ -4730,7 +4740,9 @@ var AppBuilder = class {
|
|
|
4730
4740
|
() => new EnvironmentConfigurationService()
|
|
4731
4741
|
);
|
|
4732
4742
|
this._configuration = this._container.resolve(TOKENS3.CONFIGURATION_SERVICE);
|
|
4733
|
-
this._middlewareConfig.allowOrigins?.push(
|
|
4743
|
+
this._middlewareConfig.allowOrigins?.push(
|
|
4744
|
+
this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
|
|
4745
|
+
);
|
|
4734
4746
|
}
|
|
4735
4747
|
// --- Module Configurations ---
|
|
4736
4748
|
_modules = [];
|
|
@@ -4846,7 +4858,7 @@ var AppBuilder = class {
|
|
|
4846
4858
|
pino: { config: void 0 },
|
|
4847
4859
|
customLoggers: void 0
|
|
4848
4860
|
};
|
|
4849
|
-
if (
|
|
4861
|
+
if (Guards43.isDefined(setupAction) && Guards43.isDefined(config))
|
|
4850
4862
|
setupAction(config, this._configuration);
|
|
4851
4863
|
this._modules.push({
|
|
4852
4864
|
priority: 3,
|
|
@@ -4872,7 +4884,7 @@ var AppBuilder = class {
|
|
|
4872
4884
|
addCache(setupAction) {
|
|
4873
4885
|
if (this._isCacheModuleQueued) return this;
|
|
4874
4886
|
this._isCacheModuleQueued = true;
|
|
4875
|
-
if (
|
|
4887
|
+
if (Guards43.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
4876
4888
|
this._modules.push({
|
|
4877
4889
|
priority: 3,
|
|
4878
4890
|
name: "CacheModule",
|
|
@@ -4981,7 +4993,7 @@ var AppBuilder = class {
|
|
|
4981
4993
|
* @link https://github.com/xeno-js/xeno-js
|
|
4982
4994
|
*/
|
|
4983
4995
|
addPipeline(setupAction) {
|
|
4984
|
-
if (
|
|
4996
|
+
if (Guards43.isDefined(setupAction)) {
|
|
4985
4997
|
setupAction(this._pipelineConfig, this._configuration);
|
|
4986
4998
|
}
|
|
4987
4999
|
this._queuePipelineModule();
|
|
@@ -5115,7 +5127,7 @@ var AppBuilder = class {
|
|
|
5115
5127
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
5116
5128
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
5117
5129
|
`);
|
|
5118
|
-
if (error instanceof Error &&
|
|
5130
|
+
if (error instanceof Error && Guards43.isDefined(error.stack)) {
|
|
5119
5131
|
console.error(error.stack);
|
|
5120
5132
|
}
|
|
5121
5133
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5245,7 +5257,7 @@ init_validation_utils();
|
|
|
5245
5257
|
|
|
5246
5258
|
// src/infrastructure/repositories/read-dao.ts
|
|
5247
5259
|
import { AppError as AppError16, Result as Result17 } from "@xeno-js/shared";
|
|
5248
|
-
import { Guards as
|
|
5260
|
+
import { Guards as Guards44 } from "@xeno-js/shared";
|
|
5249
5261
|
var ReadDao = class {
|
|
5250
5262
|
/**
|
|
5251
5263
|
* Constructs a new ReadDao instance.
|
|
@@ -5267,7 +5279,7 @@ var ReadDao = class {
|
|
|
5267
5279
|
async findById(id, ctx, signal) {
|
|
5268
5280
|
AppError16.throwIfAborted(signal, "ReadDao.findById");
|
|
5269
5281
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5270
|
-
if (
|
|
5282
|
+
if (Guards44.isNullOrEmpty(result)) return Result17.ok();
|
|
5271
5283
|
const entity = this._mapper.toEntity(result);
|
|
5272
5284
|
return Result17.ok(entity);
|
|
5273
5285
|
}
|
|
@@ -5281,7 +5293,7 @@ var ReadDao = class {
|
|
|
5281
5293
|
|
|
5282
5294
|
// src/infrastructure/repositories/repository.ts
|
|
5283
5295
|
import { AppError as AppError17, Result as Result18 } from "@xeno-js/shared";
|
|
5284
|
-
import { Guards as
|
|
5296
|
+
import { Guards as Guards45 } from "@xeno-js/shared";
|
|
5285
5297
|
var Repository = class {
|
|
5286
5298
|
/**
|
|
5287
5299
|
* Constructs a new Repository instance.
|
|
@@ -5303,7 +5315,7 @@ var Repository = class {
|
|
|
5303
5315
|
async findById(id, ctx, signal) {
|
|
5304
5316
|
AppError17.throwIfAborted(signal, "Repository.findById");
|
|
5305
5317
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5306
|
-
if (
|
|
5318
|
+
if (Guards45.isNullOrEmpty(result)) return Result18.ok();
|
|
5307
5319
|
const entity = this._mapper.toEntity(result);
|
|
5308
5320
|
return Result18.ok(entity);
|
|
5309
5321
|
}
|