@xeno-js/core 0.1.13 → 1.1.1
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/README.md +20 -21
- package/dist/index.cjs +499 -408
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -11
- package/dist/index.d.ts +24 -11
- package/dist/index.js +358 -278
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -68,15 +68,11 @@ var init_container_utils = __esm({
|
|
|
68
68
|
* @throws Error If the service is not found in the container.
|
|
69
69
|
* @throws Error If the service is not a scoped service.
|
|
70
70
|
*/
|
|
71
|
-
async runExecute(
|
|
71
|
+
async runExecute(res, req, container, action) {
|
|
72
72
|
const middleware = container.resolve(import_shared.TOKENS.MIDDLEWARE);
|
|
73
|
-
return await middleware.execute(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
async () => {
|
|
77
|
-
return await action();
|
|
78
|
-
}
|
|
79
|
-
);
|
|
73
|
+
return await middleware.execute(req, res, async () => {
|
|
74
|
+
return await action();
|
|
75
|
+
});
|
|
80
76
|
}
|
|
81
77
|
});
|
|
82
78
|
}
|
|
@@ -1024,7 +1020,6 @@ var init_gate_keeper = __esm({
|
|
|
1024
1020
|
}
|
|
1025
1021
|
}
|
|
1026
1022
|
return import_shared27.Result.ok(guest);
|
|
1027
|
-
return import_shared27.Result.ok(guest);
|
|
1028
1023
|
}
|
|
1029
1024
|
};
|
|
1030
1025
|
}
|
|
@@ -1509,30 +1504,30 @@ var init_logger_utils = __esm({
|
|
|
1509
1504
|
*/
|
|
1510
1505
|
async addLogger(container, opts) {
|
|
1511
1506
|
const loggerDependencies = [];
|
|
1512
|
-
const { Guards:
|
|
1513
|
-
if (!
|
|
1507
|
+
const { Guards: Guards47, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
1508
|
+
if (!Guards47.isDefined(opts) || opts.console) {
|
|
1514
1509
|
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
1515
1510
|
loggerDependencies.push(new ConsoleLogger2(opts?.level));
|
|
1516
1511
|
}
|
|
1517
|
-
if (
|
|
1518
|
-
if (
|
|
1512
|
+
if (Guards47.isDefined(opts)) {
|
|
1513
|
+
if (Guards47.isDefined(opts.sentry.config)) {
|
|
1519
1514
|
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
1520
1515
|
loggerDependencies.push(new SentryLoggerFactory2().create(opts));
|
|
1521
1516
|
}
|
|
1522
|
-
if (
|
|
1517
|
+
if (Guards47.isDefined(opts.pino.config)) {
|
|
1523
1518
|
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
1524
1519
|
loggerDependencies.push(new PinoLoggerFactory2().create(opts));
|
|
1525
1520
|
}
|
|
1526
|
-
if (!
|
|
1521
|
+
if (!Guards47.isNullOrEmpty(opts.customLoggers)) {
|
|
1527
1522
|
const customLoggers = opts.customLoggers;
|
|
1528
1523
|
customLoggers.forEach((fn) => {
|
|
1529
|
-
if (
|
|
1524
|
+
if (Guards47.isDefined(fn)) loggerDependencies.push(fn(container));
|
|
1530
1525
|
});
|
|
1531
1526
|
}
|
|
1532
1527
|
}
|
|
1533
1528
|
const { BaseLogger } = await import("@xeno-js/shared");
|
|
1534
|
-
container.addSingleton(
|
|
1535
|
-
const context = c.resolve(
|
|
1529
|
+
container.addSingleton(TOKENS5.LOGGER, (c) => {
|
|
1530
|
+
const context = c.resolve(TOKENS5.CONTEXT_ACCESSOR);
|
|
1536
1531
|
return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, loggerDependencies);
|
|
1537
1532
|
});
|
|
1538
1533
|
}
|
|
@@ -1693,25 +1688,25 @@ var init_cache_utils = __esm({
|
|
|
1693
1688
|
* @link https://github.com/xeno-js/xeno-js
|
|
1694
1689
|
*/
|
|
1695
1690
|
async addCache(container, opts) {
|
|
1696
|
-
const { Guards:
|
|
1697
|
-
if (!opts.inMemory && !
|
|
1691
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
1692
|
+
if (!opts.inMemory && !Guards47.isDefined(opts.redis)) {
|
|
1698
1693
|
throw new Error(
|
|
1699
1694
|
"No cache strategies are configured. Please provide at least one cache strategy."
|
|
1700
1695
|
);
|
|
1701
1696
|
}
|
|
1702
1697
|
const { CacheKeyBuilder } = await import("@xeno-js/shared");
|
|
1703
1698
|
container.addSingleton(
|
|
1704
|
-
|
|
1705
|
-
(c) => new CacheKeyBuilder(c.resolve(
|
|
1699
|
+
TOKENS5.CACHE_KEY_BUILDER,
|
|
1700
|
+
(c) => new CacheKeyBuilder(c.resolve(TOKENS5.IDENTITY_ACCESSOR))
|
|
1706
1701
|
);
|
|
1707
|
-
if (opts.inMemory || !
|
|
1702
|
+
if (opts.inMemory || !Guards47.isDefined(opts.redis)) {
|
|
1708
1703
|
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
1709
|
-
container.addSingleton(
|
|
1704
|
+
container.addSingleton(TOKENS5.CACHE, () => new InMemoryCacheExtended2());
|
|
1710
1705
|
return;
|
|
1711
1706
|
}
|
|
1712
|
-
if (
|
|
1707
|
+
if (Guards47.isDefined(opts.redis)) {
|
|
1713
1708
|
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
1714
|
-
container.addSingleton(
|
|
1709
|
+
container.addSingleton(TOKENS5.CACHE, () => {
|
|
1715
1710
|
const config = opts.redis;
|
|
1716
1711
|
return new RedisCacheFactory2().create(config);
|
|
1717
1712
|
});
|
|
@@ -1857,6 +1852,73 @@ var init_concurrency = __esm({
|
|
|
1857
1852
|
}
|
|
1858
1853
|
});
|
|
1859
1854
|
|
|
1855
|
+
// src/infrastructure/services/cookies/cookies.service.ts
|
|
1856
|
+
var import_shared44, CookieHandler;
|
|
1857
|
+
var init_cookies_service = __esm({
|
|
1858
|
+
"src/infrastructure/services/cookies/cookies.service.ts"() {
|
|
1859
|
+
"use strict";
|
|
1860
|
+
import_shared44 = require("@xeno-js/shared");
|
|
1861
|
+
CookieHandler = class {
|
|
1862
|
+
constructor(contextAccessor, _config, _cookieOpts) {
|
|
1863
|
+
this.contextAccessor = contextAccessor;
|
|
1864
|
+
this._config = _config;
|
|
1865
|
+
this._cookieOpts = _cookieOpts;
|
|
1866
|
+
}
|
|
1867
|
+
contextAccessor;
|
|
1868
|
+
_config;
|
|
1869
|
+
_cookieOpts;
|
|
1870
|
+
getAll() {
|
|
1871
|
+
const network = this.contextAccessor.getNetworkContext();
|
|
1872
|
+
const req = network?.transport?.req;
|
|
1873
|
+
if (!import_shared44.Guards.isDefined(req) || import_shared44.Guards.isNullOrEmpty(req.headers.get("cookie"))) return [];
|
|
1874
|
+
return req.headers.get("cookie")?.split(";").map((cookie) => {
|
|
1875
|
+
const [name, ...rest] = cookie.split("=");
|
|
1876
|
+
return { name: name.trim(), value: rest.join("=") };
|
|
1877
|
+
}) ?? [];
|
|
1878
|
+
}
|
|
1879
|
+
setAll(cookies) {
|
|
1880
|
+
const network = this.contextAccessor.getNetworkContext();
|
|
1881
|
+
const res = network?.transport?.res;
|
|
1882
|
+
if (!import_shared44.Guards.isDefined(res)) return;
|
|
1883
|
+
const serializedCookies = cookies.map((c) => this.serialize(c));
|
|
1884
|
+
const existingSetCookie = res.headers.getSetCookie();
|
|
1885
|
+
res.headers.delete("Set-Cookie");
|
|
1886
|
+
for (const cookie of [...existingSetCookie, ...serializedCookies]) {
|
|
1887
|
+
res.headers.append("Set-Cookie", cookie);
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
serialize(cookie) {
|
|
1891
|
+
const safeName = encodeURIComponent(cookie.name);
|
|
1892
|
+
const safeValue = encodeURIComponent(cookie.value);
|
|
1893
|
+
let str = `${safeName}=${safeValue}`;
|
|
1894
|
+
const isProd = this._config.get("NODE_ENV") === "production";
|
|
1895
|
+
const defaultOptions = {
|
|
1896
|
+
path: this._cookieOpts.path,
|
|
1897
|
+
httpOnly: this._cookieOpts.httpOnly,
|
|
1898
|
+
secure: this._cookieOpts.secure ?? isProd,
|
|
1899
|
+
sameSite: this._cookieOpts.sameSite ?? "Lax"
|
|
1900
|
+
};
|
|
1901
|
+
const opts = { ...defaultOptions, ...cookie.options ?? {} };
|
|
1902
|
+
str += `; Path=${opts.path}`;
|
|
1903
|
+
if (import_shared44.Guards.isDefined(opts.maxAge)) str += `; Max-Age=${opts.maxAge}`;
|
|
1904
|
+
if (import_shared44.Guards.isDefined(opts.domain)) str += `; Domain=${opts.domain}`;
|
|
1905
|
+
if (import_shared44.Guards.isDefined(opts.sameSite)) str += `; SameSite=${opts.sameSite}`;
|
|
1906
|
+
if (opts.secure) str += `; Secure`;
|
|
1907
|
+
if (opts.httpOnly) str += `; HttpOnly`;
|
|
1908
|
+
return str;
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1912
|
+
});
|
|
1913
|
+
|
|
1914
|
+
// src/infrastructure/services/cookies/index.ts
|
|
1915
|
+
var init_cookies = __esm({
|
|
1916
|
+
"src/infrastructure/services/cookies/index.ts"() {
|
|
1917
|
+
"use strict";
|
|
1918
|
+
init_cookies_service();
|
|
1919
|
+
}
|
|
1920
|
+
});
|
|
1921
|
+
|
|
1860
1922
|
// src/infrastructure/services/crypto/crypto.service.ts
|
|
1861
1923
|
var EdgeCryptoService;
|
|
1862
1924
|
var init_crypto_service = __esm({
|
|
@@ -1905,11 +1967,11 @@ var init_crypto = __esm({
|
|
|
1905
1967
|
});
|
|
1906
1968
|
|
|
1907
1969
|
// src/infrastructure/services/csrf/csrf-token.service.ts
|
|
1908
|
-
var
|
|
1970
|
+
var import_shared45, CsrfTokenService;
|
|
1909
1971
|
var init_csrf_token_service = __esm({
|
|
1910
1972
|
"src/infrastructure/services/csrf/csrf-token.service.ts"() {
|
|
1911
1973
|
"use strict";
|
|
1912
|
-
|
|
1974
|
+
import_shared45 = require("@xeno-js/shared");
|
|
1913
1975
|
CsrfTokenService = class {
|
|
1914
1976
|
constructor(_secret, _cryptoService) {
|
|
1915
1977
|
this._secret = _secret;
|
|
@@ -1928,7 +1990,7 @@ var init_csrf_token_service = __esm({
|
|
|
1928
1990
|
if (separatorIndex <= 0) return false;
|
|
1929
1991
|
const nonce = token.slice(0, separatorIndex);
|
|
1930
1992
|
const signature = token.slice(separatorIndex + 1);
|
|
1931
|
-
if (
|
|
1993
|
+
if (import_shared45.Guards.isNullOrEmpty(nonce) || import_shared45.Guards.isNullOrEmpty(signature)) return false;
|
|
1932
1994
|
const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1933
1995
|
const encoder = new TextEncoder();
|
|
1934
1996
|
const actualBuffer = encoder.encode(signature);
|
|
@@ -1949,24 +2011,26 @@ var init_csrf = __esm({
|
|
|
1949
2011
|
});
|
|
1950
2012
|
|
|
1951
2013
|
// src/infrastructure/services/extractors/extract-bearer.extractor.ts
|
|
1952
|
-
var
|
|
2014
|
+
var import_shared46, BearerTokenExtractor;
|
|
1953
2015
|
var init_extract_bearer_extractor = __esm({
|
|
1954
2016
|
"src/infrastructure/services/extractors/extract-bearer.extractor.ts"() {
|
|
1955
2017
|
"use strict";
|
|
1956
|
-
|
|
2018
|
+
import_shared46 = require("@xeno-js/shared");
|
|
1957
2019
|
BearerTokenExtractor = class {
|
|
2020
|
+
constructor(_cookiePrefix) {
|
|
2021
|
+
this._cookiePrefix = _cookiePrefix;
|
|
2022
|
+
}
|
|
2023
|
+
_cookiePrefix;
|
|
1958
2024
|
extract(headers) {
|
|
1959
|
-
const authHeader =
|
|
1960
|
-
if (
|
|
1961
|
-
return void 0;
|
|
1962
|
-
}
|
|
1963
|
-
if (authHeader.toLowerCase().startsWith("bearer ")) {
|
|
2025
|
+
const authHeader = headers.get("Authorization");
|
|
2026
|
+
if (import_shared46.Guards.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1964
2027
|
return authHeader.substring(7);
|
|
1965
2028
|
}
|
|
1966
|
-
const cookieHeader =
|
|
1967
|
-
if (
|
|
1968
|
-
const
|
|
1969
|
-
|
|
2029
|
+
const cookieHeader = headers.get("cookie");
|
|
2030
|
+
if (import_shared46.Guards.isDefined(cookieHeader)) {
|
|
2031
|
+
const regex = new RegExp(`${this._cookiePrefix}=([^;]+)`);
|
|
2032
|
+
const match = regex.exec(cookieHeader);
|
|
2033
|
+
if (!import_shared46.Guards.isNullOrEmpty(match) && import_shared46.Guards.isDefined(match[1])) {
|
|
1970
2034
|
return match[1].trim();
|
|
1971
2035
|
}
|
|
1972
2036
|
}
|
|
@@ -1977,44 +2041,44 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1977
2041
|
});
|
|
1978
2042
|
|
|
1979
2043
|
// src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts
|
|
1980
|
-
var
|
|
2044
|
+
var import_shared47, SupabaseSsrTokenExtractor;
|
|
1981
2045
|
var init_extract_ssr_bearer_extractor = __esm({
|
|
1982
2046
|
"src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts"() {
|
|
1983
2047
|
"use strict";
|
|
1984
|
-
|
|
2048
|
+
import_shared47 = require("@xeno-js/shared");
|
|
1985
2049
|
SupabaseSsrTokenExtractor = class {
|
|
1986
2050
|
extract(headers) {
|
|
1987
|
-
const authHeader =
|
|
1988
|
-
if (
|
|
2051
|
+
const authHeader = headers.get("authorization");
|
|
2052
|
+
if (import_shared47.Guards.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1989
2053
|
return authHeader.substring(7);
|
|
1990
2054
|
}
|
|
1991
|
-
const cookieHeader =
|
|
1992
|
-
if (
|
|
2055
|
+
const cookieHeader = headers.get("cookie");
|
|
2056
|
+
if (import_shared47.Guards.isNullOrEmpty(cookieHeader)) return void 0;
|
|
1993
2057
|
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
1994
2058
|
const tokenChunks = {};
|
|
1995
2059
|
let unchunkedToken;
|
|
1996
2060
|
for (const cookie of cookies) {
|
|
1997
2061
|
const [name, ...rest] = cookie.split("=");
|
|
1998
|
-
if (!
|
|
2062
|
+
if (!import_shared47.Guards.isDefined(name) || import_shared47.Guards.isNullOrEmpty(rest)) continue;
|
|
1999
2063
|
const value = decodeURIComponent(rest.join("="));
|
|
2000
|
-
if (
|
|
2064
|
+
if (import_shared47.Guards.isDefined(/^sb-[a-z0-9]+-auth-token$/.exec(name))) {
|
|
2001
2065
|
unchunkedToken = value;
|
|
2002
2066
|
} else {
|
|
2003
2067
|
const match = /^sb-[a-z0-9]+-auth-token\.(\d+)$/.exec(name);
|
|
2004
|
-
if (
|
|
2068
|
+
if (import_shared47.Guards.isDefined(match)) tokenChunks[parseInt(match[1], 10)] = value;
|
|
2005
2069
|
}
|
|
2006
2070
|
}
|
|
2007
2071
|
let fullTokenString = unchunkedToken;
|
|
2008
|
-
if (!
|
|
2072
|
+
if (!import_shared47.Guards.isDefined(fullTokenString) && Object.keys(tokenChunks).length > 0) {
|
|
2009
2073
|
const indices = Object.keys(tokenChunks).map(Number).sort((a, b) => a - b);
|
|
2010
2074
|
fullTokenString = indices.map((i) => tokenChunks[i]).join("");
|
|
2011
2075
|
}
|
|
2012
|
-
if (
|
|
2076
|
+
if (import_shared47.Guards.isNullOrEmpty(fullTokenString)) return void 0;
|
|
2013
2077
|
try {
|
|
2014
|
-
const parsed =
|
|
2015
|
-
if (
|
|
2078
|
+
const parsed = import_shared47.StringHelper.safeParse(fullTokenString);
|
|
2079
|
+
if (import_shared47.Guards.isDefined(parsed) && import_shared47.Guards.isObject(parsed) && "access_token" in parsed) {
|
|
2016
2080
|
const accessToken = parsed["access_token"];
|
|
2017
|
-
if (
|
|
2081
|
+
if (import_shared47.Guards.isString(accessToken)) return accessToken;
|
|
2018
2082
|
}
|
|
2019
2083
|
} catch {
|
|
2020
2084
|
return void 0;
|
|
@@ -2025,14 +2089,14 @@ var init_extract_ssr_bearer_extractor = __esm({
|
|
|
2025
2089
|
});
|
|
2026
2090
|
|
|
2027
2091
|
// src/infrastructure/services/extractors/http-cookie.extractor.ts
|
|
2028
|
-
var
|
|
2092
|
+
var import_shared48, HttpCookieExtractor;
|
|
2029
2093
|
var init_http_cookie_extractor = __esm({
|
|
2030
2094
|
"src/infrastructure/services/extractors/http-cookie.extractor.ts"() {
|
|
2031
2095
|
"use strict";
|
|
2032
|
-
|
|
2096
|
+
import_shared48 = require("@xeno-js/shared");
|
|
2033
2097
|
HttpCookieExtractor = class {
|
|
2034
2098
|
extract(cookie) {
|
|
2035
|
-
if (!
|
|
2099
|
+
if (!import_shared48.Guards.isDefined(cookie.header)) return void 0;
|
|
2036
2100
|
for (const rawCookie of cookie.header.split(";")) {
|
|
2037
2101
|
const separatorIndex = rawCookie.indexOf("=");
|
|
2038
2102
|
if (separatorIndex <= 0) continue;
|
|
@@ -2052,11 +2116,11 @@ var init_http_cookie_extractor = __esm({
|
|
|
2052
2116
|
});
|
|
2053
2117
|
|
|
2054
2118
|
// src/infrastructure/services/extractors/http-header.extractor.ts
|
|
2055
|
-
var
|
|
2119
|
+
var import_shared49, HttpHeaderExtractor;
|
|
2056
2120
|
var init_http_header_extractor = __esm({
|
|
2057
2121
|
"src/infrastructure/services/extractors/http-header.extractor.ts"() {
|
|
2058
2122
|
"use strict";
|
|
2059
|
-
|
|
2123
|
+
import_shared49 = require("@xeno-js/shared");
|
|
2060
2124
|
HttpHeaderExtractor = class {
|
|
2061
2125
|
/**
|
|
2062
2126
|
* @description Constructor for HttpHeaderExtractor. It takes an instance of IServiceExtractor for extracting Bearer tokens, allowing for separation of concerns and adherence to the Single Responsibility Principle (SRP). This design enables the HttpHeaderExtractor to focus on general header extraction while delegating the specific logic of Bearer token extraction to a dedicated extractor, promoting code reusability and maintainability.
|
|
@@ -2078,30 +2142,30 @@ var init_http_header_extractor = __esm({
|
|
|
2078
2142
|
_trustedIp;
|
|
2079
2143
|
_cookieName;
|
|
2080
2144
|
extract(headers) {
|
|
2081
|
-
const correlationId =
|
|
2082
|
-
const requestId =
|
|
2145
|
+
const correlationId = import_shared49.GuidHelper.parse(headers.get("x-correlation-id") ?? void 0);
|
|
2146
|
+
const requestId = import_shared49.GuidHelper.parse(headers.get("x-request-id") ?? void 0);
|
|
2083
2147
|
const token = this._bearerExtractor.extract(headers);
|
|
2084
|
-
const clientIp =
|
|
2085
|
-
const spanId =
|
|
2086
|
-
const parentSpanId =
|
|
2087
|
-
const acceptHeader =
|
|
2088
|
-
const contentTypeHeader =
|
|
2089
|
-
const userAgent =
|
|
2090
|
-
const returnAddress =
|
|
2091
|
-
const sequenceId =
|
|
2092
|
-
const position =
|
|
2093
|
-
const size =
|
|
2094
|
-
const expiration =
|
|
2095
|
-
const csrf =
|
|
2096
|
-
const cookieHeader =
|
|
2148
|
+
const clientIp = headers.get(this._trustedIp?.toLowerCase() ?? "x-forwarded-for") ?? headers.get("x-real-ip") ?? void 0;
|
|
2149
|
+
const spanId = import_shared49.GuidHelper.parse(headers.get("x-span-id") ?? void 0);
|
|
2150
|
+
const parentSpanId = headers.get("x-parent-span-id") ?? void 0;
|
|
2151
|
+
const acceptHeader = headers.get("accept");
|
|
2152
|
+
const contentTypeHeader = headers.get("content-type");
|
|
2153
|
+
const userAgent = headers.get("user-agent") ?? void 0;
|
|
2154
|
+
const returnAddress = headers.get("x-return-address") ?? void 0;
|
|
2155
|
+
const sequenceId = headers.get("x-sequence-id") ?? void 0;
|
|
2156
|
+
const position = headers.get("x-sequence-position");
|
|
2157
|
+
const size = headers.get("x-sequence-size");
|
|
2158
|
+
const expiration = headers.get("x-expiration");
|
|
2159
|
+
const csrf = headers.get("x-csrf-token") ?? void 0;
|
|
2160
|
+
const cookieHeader = headers.get("cookie") ?? void 0;
|
|
2097
2161
|
const csrfCookie = this._cookieExtractor.extract({
|
|
2098
2162
|
header: cookieHeader,
|
|
2099
2163
|
name: this._cookieName
|
|
2100
2164
|
});
|
|
2101
|
-
const origin =
|
|
2102
|
-
const cleanOrigin =
|
|
2103
|
-
const referer =
|
|
2104
|
-
const cleanReferer =
|
|
2165
|
+
const origin = headers.get("origin") ?? void 0;
|
|
2166
|
+
const cleanOrigin = import_shared49.HttpHelper.sanitizeOriginUrl(origin);
|
|
2167
|
+
const referer = headers.get("referer") ?? void 0;
|
|
2168
|
+
const cleanReferer = import_shared49.HttpHelper.sanitizeOriginUrl(referer);
|
|
2105
2169
|
const accept = acceptHeader === "*/*" ? void 0 : acceptHeader;
|
|
2106
2170
|
const formatIndicator = accept ?? contentTypeHeader ?? "application/json";
|
|
2107
2171
|
const metadata = {
|
|
@@ -2120,10 +2184,10 @@ var init_http_header_extractor = __esm({
|
|
|
2120
2184
|
referer: cleanReferer,
|
|
2121
2185
|
sequence: {
|
|
2122
2186
|
sequenceId,
|
|
2123
|
-
position:
|
|
2124
|
-
size:
|
|
2187
|
+
position: import_shared49.Guards.isDefined(position) ? import_shared49.MathHelper.toNumber(position) : void 0,
|
|
2188
|
+
size: import_shared49.Guards.isDefined(size) ? import_shared49.MathHelper.toNumber(size) : void 0
|
|
2125
2189
|
},
|
|
2126
|
-
expiration:
|
|
2190
|
+
expiration: import_shared49.Guards.isDefined(expiration) ? import_shared49.MathHelper.toNumber(expiration) : void 0
|
|
2127
2191
|
};
|
|
2128
2192
|
return metadata;
|
|
2129
2193
|
}
|
|
@@ -2143,18 +2207,18 @@ var init_extractors = __esm({
|
|
|
2143
2207
|
});
|
|
2144
2208
|
|
|
2145
2209
|
// src/infrastructure/services/resiliences/resilience.service.ts
|
|
2146
|
-
var
|
|
2210
|
+
var import_shared50, ServiceResilience;
|
|
2147
2211
|
var init_resilience_service = __esm({
|
|
2148
2212
|
"src/infrastructure/services/resiliences/resilience.service.ts"() {
|
|
2149
2213
|
"use strict";
|
|
2150
|
-
|
|
2214
|
+
import_shared50 = require("@xeno-js/shared");
|
|
2151
2215
|
ServiceResilience = class {
|
|
2152
2216
|
constructor(policy) {
|
|
2153
2217
|
this.policy = policy;
|
|
2154
2218
|
}
|
|
2155
2219
|
policy;
|
|
2156
2220
|
async execute(operation, signal) {
|
|
2157
|
-
|
|
2221
|
+
import_shared50.AppError.throwIfAborted(signal, "ServiceResilience.execute");
|
|
2158
2222
|
return this.policy.execute(() => operation(), signal);
|
|
2159
2223
|
}
|
|
2160
2224
|
};
|
|
@@ -2170,11 +2234,11 @@ var init_resiliences = __esm({
|
|
|
2170
2234
|
});
|
|
2171
2235
|
|
|
2172
2236
|
// src/infrastructure/services/resolver/utils/socket.utils.ts
|
|
2173
|
-
var
|
|
2237
|
+
var import_shared51, SocketIpExtractor;
|
|
2174
2238
|
var init_socket_utils = __esm({
|
|
2175
2239
|
"src/infrastructure/services/resolver/utils/socket.utils.ts"() {
|
|
2176
2240
|
"use strict";
|
|
2177
|
-
|
|
2241
|
+
import_shared51 = require("@xeno-js/shared");
|
|
2178
2242
|
SocketIpExtractor = Object.freeze({
|
|
2179
2243
|
/**
|
|
2180
2244
|
* @description Extracts the IP address of the remote socket from an incoming request.
|
|
@@ -2182,7 +2246,7 @@ var init_socket_utils = __esm({
|
|
|
2182
2246
|
* @returns The IP address of the remote socket, or undefined if not available.
|
|
2183
2247
|
*/
|
|
2184
2248
|
extract(req) {
|
|
2185
|
-
if (
|
|
2249
|
+
if (import_shared51.Guards.isDefined(req) && import_shared51.Guards.isObject(req)) {
|
|
2186
2250
|
const candidate = req;
|
|
2187
2251
|
return candidate.socket?.remoteAddress ?? candidate.connection?.remoteAddress;
|
|
2188
2252
|
}
|
|
@@ -2201,11 +2265,11 @@ var init_utils = __esm({
|
|
|
2201
2265
|
});
|
|
2202
2266
|
|
|
2203
2267
|
// src/infrastructure/services/resolver/client-ip.resolver.ts
|
|
2204
|
-
var
|
|
2268
|
+
var import_shared52, ClientIpResolver;
|
|
2205
2269
|
var init_client_ip_resolver = __esm({
|
|
2206
2270
|
"src/infrastructure/services/resolver/client-ip.resolver.ts"() {
|
|
2207
2271
|
"use strict";
|
|
2208
|
-
|
|
2272
|
+
import_shared52 = require("@xeno-js/shared");
|
|
2209
2273
|
init_utils();
|
|
2210
2274
|
ClientIpResolver = class {
|
|
2211
2275
|
constructor(_trustedProxies = []) {
|
|
@@ -2214,11 +2278,11 @@ var init_client_ip_resolver = __esm({
|
|
|
2214
2278
|
_trustedProxies;
|
|
2215
2279
|
resolve(req, clientIp) {
|
|
2216
2280
|
const socketIp = SocketIpExtractor.extract(req);
|
|
2217
|
-
if (!
|
|
2218
|
-
return !
|
|
2281
|
+
if (!import_shared52.Guards.isDefined(socketIp))
|
|
2282
|
+
return !import_shared52.Guards.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
2219
2283
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
2220
2284
|
if (!isTrustedProxy) return socketIp;
|
|
2221
|
-
if (
|
|
2285
|
+
if (import_shared52.Guards.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
2222
2286
|
return socketIp;
|
|
2223
2287
|
}
|
|
2224
2288
|
};
|
|
@@ -2240,6 +2304,7 @@ __export(services_exports, {
|
|
|
2240
2304
|
AllowOrigin: () => AllowOrigin,
|
|
2241
2305
|
BearerTokenExtractor: () => BearerTokenExtractor,
|
|
2242
2306
|
ClientIpResolver: () => ClientIpResolver,
|
|
2307
|
+
CookieHandler: () => CookieHandler,
|
|
2243
2308
|
CsrfTokenService: () => CsrfTokenService,
|
|
2244
2309
|
EdgeCryptoService: () => EdgeCryptoService,
|
|
2245
2310
|
HttpCookieExtractor: () => HttpCookieExtractor,
|
|
@@ -2254,6 +2319,7 @@ var init_services = __esm({
|
|
|
2254
2319
|
init_allow_methods();
|
|
2255
2320
|
init_allow_origins();
|
|
2256
2321
|
init_concurrency();
|
|
2322
|
+
init_cookies();
|
|
2257
2323
|
init_crypto();
|
|
2258
2324
|
init_csrf();
|
|
2259
2325
|
init_extractors();
|
|
@@ -2281,15 +2347,15 @@ var init_allow_method_factory = __esm({
|
|
|
2281
2347
|
});
|
|
2282
2348
|
|
|
2283
2349
|
// src/infrastructure/factories/axios.factory.ts
|
|
2284
|
-
var import_node_http, import_node_https,
|
|
2350
|
+
var import_node_http, import_node_https, import_shared53, import_axios, NodeAxiosFactory;
|
|
2285
2351
|
var init_axios_factory = __esm({
|
|
2286
2352
|
"src/infrastructure/factories/axios.factory.ts"() {
|
|
2287
2353
|
"use strict";
|
|
2288
2354
|
import_node_http = __toESM(require("http"), 1);
|
|
2289
2355
|
import_node_https = __toESM(require("https"), 1);
|
|
2290
|
-
|
|
2356
|
+
import_shared53 = require("@xeno-js/shared");
|
|
2291
2357
|
import_axios = __toESM(require("axios"), 1);
|
|
2292
|
-
NodeAxiosFactory = class
|
|
2358
|
+
NodeAxiosFactory = class {
|
|
2293
2359
|
create(config) {
|
|
2294
2360
|
const isKeepAlive = config.keepAlive ?? true;
|
|
2295
2361
|
const maxSockets = config.maxSockets ?? 100;
|
|
@@ -2314,18 +2380,18 @@ var init_axios_factory = __esm({
|
|
|
2314
2380
|
proxy: config.proxy,
|
|
2315
2381
|
withCredentials: config.withCredentials
|
|
2316
2382
|
});
|
|
2317
|
-
return new
|
|
2383
|
+
return new import_shared53.AxiosHttpClient(axiosInstance);
|
|
2318
2384
|
}
|
|
2319
2385
|
};
|
|
2320
2386
|
}
|
|
2321
2387
|
});
|
|
2322
2388
|
|
|
2323
2389
|
// src/infrastructure/factories/cockatiel-resilience.factory.ts
|
|
2324
|
-
var
|
|
2390
|
+
var import_shared54, import_cockatiel, CockatielResilienceFactory;
|
|
2325
2391
|
var init_cockatiel_resilience_factory = __esm({
|
|
2326
2392
|
"src/infrastructure/factories/cockatiel-resilience.factory.ts"() {
|
|
2327
2393
|
"use strict";
|
|
2328
|
-
|
|
2394
|
+
import_shared54 = require("@xeno-js/shared");
|
|
2329
2395
|
import_cockatiel = require("cockatiel");
|
|
2330
2396
|
init_resilience_service();
|
|
2331
2397
|
CockatielResilienceFactory = class {
|
|
@@ -2335,36 +2401,36 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2335
2401
|
retry: {
|
|
2336
2402
|
attempts: this.checkConfigValue(
|
|
2337
2403
|
config.retry.attempts,
|
|
2338
|
-
|
|
2404
|
+
import_shared54.RESILIENCE_DEFAULTS.RETRY.ATTEMPTS,
|
|
2339
2405
|
message
|
|
2340
2406
|
),
|
|
2341
2407
|
baseDelayMs: this.checkConfigValue(
|
|
2342
2408
|
config.retry.baseDelayMs,
|
|
2343
|
-
|
|
2409
|
+
import_shared54.RESILIENCE_DEFAULTS.RETRY.BASE_DELAY_MS,
|
|
2344
2410
|
message
|
|
2345
2411
|
),
|
|
2346
2412
|
maxDelayMs: this.checkConfigValue(
|
|
2347
2413
|
config.retry.maxDelayMs,
|
|
2348
|
-
|
|
2414
|
+
import_shared54.RESILIENCE_DEFAULTS.RETRY.MAX_DELAY_MS,
|
|
2349
2415
|
message
|
|
2350
2416
|
)
|
|
2351
2417
|
},
|
|
2352
2418
|
circuitBreaker: {
|
|
2353
2419
|
consecutiveFailures: this.checkConfigValue(
|
|
2354
2420
|
config.circuitBreaker.consecutiveFailures,
|
|
2355
|
-
|
|
2421
|
+
import_shared54.RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.CONSECUTIVE_FAILURES,
|
|
2356
2422
|
message
|
|
2357
2423
|
),
|
|
2358
2424
|
halfOpenTimeoutMs: this.checkConfigValue(
|
|
2359
2425
|
config.circuitBreaker.halfOpenTimeoutMs,
|
|
2360
|
-
|
|
2426
|
+
import_shared54.RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.HALF_OPEN_TIMEOUT_MS,
|
|
2361
2427
|
message
|
|
2362
2428
|
)
|
|
2363
2429
|
},
|
|
2364
2430
|
bulkhead: {
|
|
2365
2431
|
maxConcurrent: this.checkConfigValue(
|
|
2366
2432
|
config.bulkhead.maxConcurrent,
|
|
2367
|
-
|
|
2433
|
+
import_shared54.RESILIENCE_DEFAULTS.BULKHEAD.MAX_CONCURRENT,
|
|
2368
2434
|
message
|
|
2369
2435
|
)
|
|
2370
2436
|
}
|
|
@@ -2390,13 +2456,13 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2390
2456
|
return new ServiceResilience((0, import_cockatiel.wrap)(bulkheadPolicy, circuitBreakerPolicy, retryPolicy));
|
|
2391
2457
|
}
|
|
2392
2458
|
isTransientError(error) {
|
|
2393
|
-
if (!
|
|
2459
|
+
if (!import_shared54.Guards.isDefined(error) || !import_shared54.Guards.isObject(error)) return false;
|
|
2394
2460
|
let status;
|
|
2395
2461
|
let isNetworkError = false;
|
|
2396
|
-
if (error instanceof
|
|
2462
|
+
if (error instanceof import_shared54.AppError) {
|
|
2397
2463
|
status = error.status;
|
|
2398
2464
|
const cause = error.cause;
|
|
2399
|
-
if (
|
|
2465
|
+
if (import_shared54.Guards.isDefined(cause) && import_shared54.Guards.isString(cause.code)) {
|
|
2400
2466
|
isNetworkError = [
|
|
2401
2467
|
"ECONNABORTED",
|
|
2402
2468
|
"ECONNRESET",
|
|
@@ -2408,7 +2474,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2408
2474
|
} else {
|
|
2409
2475
|
const err = error;
|
|
2410
2476
|
status = err.status;
|
|
2411
|
-
if (
|
|
2477
|
+
if (import_shared54.Guards.isString(err.code)) {
|
|
2412
2478
|
isNetworkError = [
|
|
2413
2479
|
"ECONNABORTED",
|
|
2414
2480
|
"ECONNRESET",
|
|
@@ -2419,30 +2485,30 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2419
2485
|
}
|
|
2420
2486
|
}
|
|
2421
2487
|
if (isNetworkError) return true;
|
|
2422
|
-
if (
|
|
2488
|
+
if (import_shared54.Guards.isDefined(status)) return status === 408 || status >= 500 && status < 600;
|
|
2423
2489
|
return false;
|
|
2424
2490
|
}
|
|
2425
2491
|
isTransientAndIdempotent(error) {
|
|
2426
2492
|
if (!this.isTransientError(error)) return false;
|
|
2427
2493
|
let method;
|
|
2428
|
-
if (error instanceof
|
|
2494
|
+
if (error instanceof import_shared54.AppError) {
|
|
2429
2495
|
const cause = error.cause;
|
|
2430
|
-
if (
|
|
2496
|
+
if (import_shared54.Guards.isDefined(cause) && import_shared54.Guards.isDefined(cause.config) && import_shared54.Guards.isString(cause.config.method)) {
|
|
2431
2497
|
method = cause.config.method.toUpperCase();
|
|
2432
2498
|
}
|
|
2433
2499
|
} else {
|
|
2434
2500
|
const err = error;
|
|
2435
|
-
if (
|
|
2501
|
+
if (import_shared54.Guards.isDefined(err.config) && import_shared54.Guards.isString(err.config.method)) {
|
|
2436
2502
|
method = err.config.method.toUpperCase();
|
|
2437
2503
|
}
|
|
2438
2504
|
}
|
|
2439
|
-
if (
|
|
2505
|
+
if (import_shared54.Guards.isNullOrEmpty(method)) return false;
|
|
2440
2506
|
const idempotentMethods = ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
|
|
2441
2507
|
return idempotentMethods.includes(method);
|
|
2442
2508
|
}
|
|
2443
2509
|
checkConfigValue(value, defaultValue, message) {
|
|
2444
|
-
if (
|
|
2445
|
-
|
|
2510
|
+
if (import_shared54.Guards.isDefined(value)) {
|
|
2511
|
+
import_shared54.Guards.throwIfNegative(value, message);
|
|
2446
2512
|
return value;
|
|
2447
2513
|
}
|
|
2448
2514
|
return defaultValue;
|
|
@@ -2474,11 +2540,11 @@ var init_db_client_factory = __esm({
|
|
|
2474
2540
|
});
|
|
2475
2541
|
|
|
2476
2542
|
// src/infrastructure/context/request-context.ts
|
|
2477
|
-
var
|
|
2543
|
+
var import_shared55, NodeRequestContext;
|
|
2478
2544
|
var init_request_context = __esm({
|
|
2479
2545
|
"src/infrastructure/context/request-context.ts"() {
|
|
2480
2546
|
"use strict";
|
|
2481
|
-
|
|
2547
|
+
import_shared55 = require("@xeno-js/shared");
|
|
2482
2548
|
NodeRequestContext = class {
|
|
2483
2549
|
/**
|
|
2484
2550
|
* @description Constructs a new instance of the NodeRequestContext class, which requires an instance of AsyncLocalStorage to manage the request context. The AsyncLocalStorage instance is used to create and access the context for each request, allowing for the storage of identity information and other relevant data that needs to be accessible across asynchronous operations. This constructor initializes the NodeRequestContext with the provided AsyncLocalStorage, enabling it to implement the methods defined in the IRequestContext interface for managing request-specific context data.
|
|
@@ -2506,7 +2572,7 @@ var init_request_context = __esm({
|
|
|
2506
2572
|
}
|
|
2507
2573
|
updateIdentity(identity) {
|
|
2508
2574
|
const store = this._storage.getStore();
|
|
2509
|
-
if (
|
|
2575
|
+
if (import_shared55.Guards.isDefined(store) && import_shared55.Guards.isDefined(store.context)) {
|
|
2510
2576
|
store.context = Object.freeze({
|
|
2511
2577
|
...store.context,
|
|
2512
2578
|
identity: Object.freeze(identity)
|
|
@@ -2515,23 +2581,23 @@ var init_request_context = __esm({
|
|
|
2515
2581
|
}
|
|
2516
2582
|
getContext() {
|
|
2517
2583
|
const store = this._storage.getStore();
|
|
2518
|
-
if (!
|
|
2584
|
+
if (!import_shared55.Guards.isDefined(store)) return void 0;
|
|
2519
2585
|
const context = store.context;
|
|
2520
2586
|
return Object.freeze(context);
|
|
2521
2587
|
}
|
|
2522
2588
|
getIdentity() {
|
|
2523
2589
|
const store = this._storage.getStore();
|
|
2524
|
-
if (!
|
|
2590
|
+
if (!import_shared55.Guards.isDefined(store)) return void 0;
|
|
2525
2591
|
return Object.freeze(store.context?.identity);
|
|
2526
2592
|
}
|
|
2527
2593
|
getScope() {
|
|
2528
2594
|
const store = this._storage.getStore();
|
|
2529
|
-
if (!
|
|
2595
|
+
if (!import_shared55.Guards.isDefined(store)) return void 0;
|
|
2530
2596
|
return store.scope;
|
|
2531
2597
|
}
|
|
2532
2598
|
getNetworkContext() {
|
|
2533
2599
|
const store = this._storage.getStore();
|
|
2534
|
-
if (!
|
|
2600
|
+
if (!import_shared55.Guards.isDefined(store)) return void 0;
|
|
2535
2601
|
return Object.freeze(store.context?.network);
|
|
2536
2602
|
}
|
|
2537
2603
|
};
|
|
@@ -2604,37 +2670,37 @@ var init_sql_light_db_client_factory = __esm({
|
|
|
2604
2670
|
});
|
|
2605
2671
|
|
|
2606
2672
|
// src/infrastructure/factories/supabase.factory.ts
|
|
2607
|
-
var import_ssr,
|
|
2673
|
+
var import_ssr, import_shared56, SupabaseServerAuthFactory;
|
|
2608
2674
|
var init_supabase_factory = __esm({
|
|
2609
2675
|
"src/infrastructure/factories/supabase.factory.ts"() {
|
|
2610
2676
|
"use strict";
|
|
2611
2677
|
import_ssr = require("@supabase/ssr");
|
|
2612
|
-
|
|
2678
|
+
import_shared56 = require("@xeno-js/shared");
|
|
2679
|
+
init_services();
|
|
2613
2680
|
SupabaseServerAuthFactory = class {
|
|
2614
2681
|
create({
|
|
2615
2682
|
config,
|
|
2616
2683
|
container
|
|
2617
2684
|
}) {
|
|
2618
|
-
|
|
2619
|
-
throw new Error(
|
|
2620
|
-
"ISsrCookieHandler is required for @supabase/ssr initialization., Please provide it in the config object."
|
|
2621
|
-
);
|
|
2622
|
-
}
|
|
2623
|
-
const cookieService = config.ssrOpts(container);
|
|
2685
|
+
const cookieService = this._getCookieSsr(config.ssrOpts, container, config.cookieOpts);
|
|
2624
2686
|
const client = (0, import_ssr.createServerClient)(config.url, config.key, {
|
|
2625
2687
|
...config.opts,
|
|
2626
|
-
cookies:
|
|
2627
|
-
getAll() {
|
|
2628
|
-
return cookieService.getAll();
|
|
2629
|
-
},
|
|
2630
|
-
setAll(cookiesToSet) {
|
|
2631
|
-
cookieService.setAll(cookiesToSet);
|
|
2632
|
-
}
|
|
2633
|
-
}
|
|
2688
|
+
cookies: cookieService
|
|
2634
2689
|
});
|
|
2635
|
-
const mapper = new
|
|
2636
|
-
const sessionMapper = new
|
|
2637
|
-
return new
|
|
2690
|
+
const mapper = new import_shared56.SupabaseClaimsMapper();
|
|
2691
|
+
const sessionMapper = new import_shared56.SupabaseSessionMapper(mapper);
|
|
2692
|
+
return new import_shared56.SupabaseAuthService(client, mapper, sessionMapper, config);
|
|
2693
|
+
}
|
|
2694
|
+
_getCookieSsr(ssrOpts, container, config) {
|
|
2695
|
+
if (import_shared56.Guards.isDefined(ssrOpts)) {
|
|
2696
|
+
return ssrOpts(container);
|
|
2697
|
+
} else {
|
|
2698
|
+
return new CookieHandler(
|
|
2699
|
+
container.resolve(import_shared56.TOKENS.REQUEST_CONTEXT),
|
|
2700
|
+
container.resolve(import_shared56.TOKENS.CONFIGURATION_SERVICE),
|
|
2701
|
+
config
|
|
2702
|
+
);
|
|
2703
|
+
}
|
|
2638
2704
|
}
|
|
2639
2705
|
};
|
|
2640
2706
|
}
|
|
@@ -2645,11 +2711,11 @@ var user_context_factory_exports = {};
|
|
|
2645
2711
|
__export(user_context_factory_exports, {
|
|
2646
2712
|
UserContextFactory: () => UserContextFactory
|
|
2647
2713
|
});
|
|
2648
|
-
var
|
|
2714
|
+
var import_shared57, UserContextFactory;
|
|
2649
2715
|
var init_user_context_factory = __esm({
|
|
2650
2716
|
"src/infrastructure/factories/user-context.factory.ts"() {
|
|
2651
2717
|
"use strict";
|
|
2652
|
-
|
|
2718
|
+
import_shared57 = require("@xeno-js/shared");
|
|
2653
2719
|
UserContextFactory = class {
|
|
2654
2720
|
/**
|
|
2655
2721
|
* @description Constructs an instance of UserContextFactory.
|
|
@@ -2670,7 +2736,7 @@ var init_user_context_factory = __esm({
|
|
|
2670
2736
|
tenantId: void 0
|
|
2671
2737
|
};
|
|
2672
2738
|
const identity = this._identityFactory.getIdentity();
|
|
2673
|
-
if (
|
|
2739
|
+
if (import_shared57.Guards.isDefined(identity)) {
|
|
2674
2740
|
output.userId = identity.userId;
|
|
2675
2741
|
output.tenantId = identity.tenantId;
|
|
2676
2742
|
}
|
|
@@ -2681,14 +2747,14 @@ var init_user_context_factory = __esm({
|
|
|
2681
2747
|
});
|
|
2682
2748
|
|
|
2683
2749
|
// src/infrastructure/factories/zod-validator.factory.ts
|
|
2684
|
-
var
|
|
2750
|
+
var import_shared58, ZodValidatorFactory;
|
|
2685
2751
|
var init_zod_validator_factory = __esm({
|
|
2686
2752
|
"src/infrastructure/factories/zod-validator.factory.ts"() {
|
|
2687
2753
|
"use strict";
|
|
2688
|
-
|
|
2754
|
+
import_shared58 = require("@xeno-js/shared");
|
|
2689
2755
|
ZodValidatorFactory = class {
|
|
2690
2756
|
create(opts) {
|
|
2691
|
-
const validatorService = new
|
|
2757
|
+
const validatorService = new import_shared58.ZodValidatorService(/* @__PURE__ */ new Map(), opts.logger);
|
|
2692
2758
|
for (const [intentKey, schema] of Object.entries(opts.schemas)) {
|
|
2693
2759
|
validatorService.addSchema(intentKey, schema);
|
|
2694
2760
|
}
|
|
@@ -2756,28 +2822,28 @@ var init_auth_utils = __esm({
|
|
|
2756
2822
|
* @link https://github.com/xeno-js/xeno-js
|
|
2757
2823
|
*/
|
|
2758
2824
|
async addAuthZ(container, opts) {
|
|
2759
|
-
const { TOKENS:
|
|
2825
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2760
2826
|
const strategies = [];
|
|
2761
|
-
const { Guards:
|
|
2762
|
-
if (
|
|
2827
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
2828
|
+
if (Guards47.isDefined(opts.policies)) {
|
|
2763
2829
|
const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2764
2830
|
const policyRegistry = opts.policies;
|
|
2765
2831
|
const registryInstance = new PolicyRegistry2();
|
|
2766
|
-
const ctxAccessor = container.resolve(
|
|
2832
|
+
const ctxAccessor = container.resolve(TOKENS5.CONTEXT_ACCESSOR);
|
|
2767
2833
|
const Policies = /* @__PURE__ */ new Set();
|
|
2768
2834
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2769
2835
|
const intentLower = intent.toLowerCase();
|
|
2770
2836
|
registryInstance.addPolicy(intentLower, policy);
|
|
2771
|
-
if (!
|
|
2837
|
+
if (!Guards47.isNullOrEmpty(policy.roles)) {
|
|
2772
2838
|
Policies.add("roles");
|
|
2773
2839
|
}
|
|
2774
|
-
if (!
|
|
2840
|
+
if (!Guards47.isNullOrEmpty(policy.permissions)) {
|
|
2775
2841
|
Policies.add("permissions");
|
|
2776
2842
|
}
|
|
2777
|
-
if (!
|
|
2843
|
+
if (!Guards47.isNullOrEmpty(policy.userId)) {
|
|
2778
2844
|
Policies.add("userId");
|
|
2779
2845
|
}
|
|
2780
|
-
if (!
|
|
2846
|
+
if (!Guards47.isNullOrEmpty(policy.tenantId)) {
|
|
2781
2847
|
Policies.add("tenantId");
|
|
2782
2848
|
}
|
|
2783
2849
|
}
|
|
@@ -2798,10 +2864,10 @@ var init_auth_utils = __esm({
|
|
|
2798
2864
|
strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2799
2865
|
}
|
|
2800
2866
|
}
|
|
2801
|
-
if (!
|
|
2867
|
+
if (!Guards47.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2802
2868
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2803
2869
|
customStrategies.forEach((strategyToken) => {
|
|
2804
|
-
if (
|
|
2870
|
+
if (Guards47.isDefined(strategyToken)) {
|
|
2805
2871
|
strategies.push(strategyToken(container));
|
|
2806
2872
|
}
|
|
2807
2873
|
});
|
|
@@ -2821,17 +2887,26 @@ var init_auth_utils = __esm({
|
|
|
2821
2887
|
* @link https://github.com/xeno-js/xeno-js
|
|
2822
2888
|
*/
|
|
2823
2889
|
async addAuthN(container, opts) {
|
|
2824
|
-
const { TOKENS:
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2890
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2891
|
+
if (Guards47.isDefined(opts.customAuth)) {
|
|
2892
|
+
const authService = opts.customAuth.authExtendedService();
|
|
2893
|
+
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2894
|
+
return authService;
|
|
2895
|
+
});
|
|
2896
|
+
container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
|
|
2897
|
+
return authService;
|
|
2898
|
+
});
|
|
2899
|
+
} else {
|
|
2900
|
+
const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2901
|
+
const factory = new SupabaseServerAuthFactory2();
|
|
2902
|
+
const supabase = factory.create({ config: opts, container });
|
|
2903
|
+
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2904
|
+
return supabase;
|
|
2905
|
+
});
|
|
2906
|
+
container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
|
|
2907
|
+
return supabase;
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2835
2910
|
}
|
|
2836
2911
|
});
|
|
2837
2912
|
}
|
|
@@ -2923,12 +2998,12 @@ var unit_of_work_exports = {};
|
|
|
2923
2998
|
__export(unit_of_work_exports, {
|
|
2924
2999
|
UnitOfWork: () => UnitOfWork
|
|
2925
3000
|
});
|
|
2926
|
-
var
|
|
3001
|
+
var import_shared59, import_shared60, UnitOfWork;
|
|
2927
3002
|
var init_unit_of_work = __esm({
|
|
2928
3003
|
"src/infrastructure/transaction/unit-of-work.ts"() {
|
|
2929
3004
|
"use strict";
|
|
2930
|
-
import_shared58 = require("@xeno-js/shared");
|
|
2931
3005
|
import_shared59 = require("@xeno-js/shared");
|
|
3006
|
+
import_shared60 = require("@xeno-js/shared");
|
|
2932
3007
|
UnitOfWork = class {
|
|
2933
3008
|
/**
|
|
2934
3009
|
* Creates an instance of UnitOfWork.
|
|
@@ -2947,7 +3022,7 @@ var init_unit_of_work = __esm({
|
|
|
2947
3022
|
_dbContext;
|
|
2948
3023
|
_ttx;
|
|
2949
3024
|
async runInTransaction(callback, signal) {
|
|
2950
|
-
|
|
3025
|
+
import_shared59.AppError.throwIfAborted(signal, "UnitOfWork.runInTransaction");
|
|
2951
3026
|
return this._dbContext.transaction(async (tx) => {
|
|
2952
3027
|
this._ttx.state = tx;
|
|
2953
3028
|
try {
|
|
@@ -2959,9 +3034,9 @@ var init_unit_of_work = __esm({
|
|
|
2959
3034
|
});
|
|
2960
3035
|
}
|
|
2961
3036
|
async dispose() {
|
|
2962
|
-
if (
|
|
3037
|
+
if (import_shared60.Guards.isDefined(this._ttx.state)) {
|
|
2963
3038
|
try {
|
|
2964
|
-
if (
|
|
3039
|
+
if (import_shared60.Guards.hasMethod(this._ttx.state, "rollback")) {
|
|
2965
3040
|
await this._ttx.state.rollback();
|
|
2966
3041
|
}
|
|
2967
3042
|
} finally {
|
|
@@ -2984,7 +3059,7 @@ var init_db_module = __esm({
|
|
|
2984
3059
|
"use strict";
|
|
2985
3060
|
DbModule = class {
|
|
2986
3061
|
async configure(container, opts) {
|
|
2987
|
-
const { Guards:
|
|
3062
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2988
3063
|
const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
|
|
2989
3064
|
const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
|
|
2990
3065
|
const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
|
|
@@ -2992,16 +3067,16 @@ var init_db_module = __esm({
|
|
|
2992
3067
|
return new TransactionState2();
|
|
2993
3068
|
});
|
|
2994
3069
|
const { UnitOfWork: UnitOfWork2 } = await Promise.resolve().then(() => (init_unit_of_work(), unit_of_work_exports));
|
|
2995
|
-
container.addScoped(
|
|
3070
|
+
container.addScoped(TOKENS5.UNIT_OF_WORK, (c) => {
|
|
2996
3071
|
const ttx = c.resolve("TRANSACTION_STATE");
|
|
2997
3072
|
return new UnitOfWork2(db, ttx);
|
|
2998
3073
|
});
|
|
2999
|
-
container.addScoped(
|
|
3074
|
+
container.addScoped(TOKENS5.DB_CONTEXT, (c) => {
|
|
3000
3075
|
const ttx = c.resolve("TRANSACTION_STATE");
|
|
3001
3076
|
return new Proxy(db, {
|
|
3002
3077
|
get(_target, prop, receiver) {
|
|
3003
3078
|
const activeState = ttx.state;
|
|
3004
|
-
if (
|
|
3079
|
+
if (Guards47.isDefined(activeState)) {
|
|
3005
3080
|
if (prop === "transaction") {
|
|
3006
3081
|
return activeState.transaction.bind(activeState);
|
|
3007
3082
|
}
|
|
@@ -3038,14 +3113,14 @@ var init_http_utils = __esm({
|
|
|
3038
3113
|
*/
|
|
3039
3114
|
async addAxios(container, opts) {
|
|
3040
3115
|
const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3041
|
-
const { Guards:
|
|
3042
|
-
if (!
|
|
3116
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
3117
|
+
if (!Guards47.isDefined(opts.token)) {
|
|
3043
3118
|
throw new Error("HttpConfig.token is required and must be defined.");
|
|
3044
3119
|
}
|
|
3045
3120
|
container.addSingleton(opts.token, () => {
|
|
3046
3121
|
const factory = new NodeAxiosFactory2();
|
|
3047
3122
|
const instance = factory.create(opts.client);
|
|
3048
|
-
if (!
|
|
3123
|
+
if (!Guards47.hasMethod(instance, "get") || !Guards47.hasMethod(instance, "post") || !Guards47.hasMethod(instance, "put") || !Guards47.hasMethod(instance, "patch") || !Guards47.hasMethod(instance, "delete")) {
|
|
3049
3124
|
throw new Error(
|
|
3050
3125
|
"The created HTTP client instance does not implement the required methods of IHttpClient."
|
|
3051
3126
|
);
|
|
@@ -3064,9 +3139,9 @@ var init_http_utils = __esm({
|
|
|
3064
3139
|
* @link https://github.com/xeno-js/xeno-js
|
|
3065
3140
|
*/
|
|
3066
3141
|
async addResilience(container, opts) {
|
|
3067
|
-
const { TOKENS:
|
|
3142
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3068
3143
|
const { CockatielResilienceFactory: CockatielResilienceFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3069
|
-
container.addSingleton(
|
|
3144
|
+
container.addSingleton(TOKENS5.RESILIENCE_CLIENT, () => {
|
|
3070
3145
|
const factory = new CockatielResilienceFactory2();
|
|
3071
3146
|
return factory.create(opts);
|
|
3072
3147
|
});
|
|
@@ -3115,22 +3190,22 @@ var init_validation_utils = __esm({
|
|
|
3115
3190
|
* @link https://github.com/xeno-js/xeno-js
|
|
3116
3191
|
*/
|
|
3117
3192
|
async addValidation(container, opts, logger) {
|
|
3118
|
-
const { Guards:
|
|
3119
|
-
if (!
|
|
3193
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3194
|
+
if (!Guards47.isDefined(opts.zod) && Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3120
3195
|
return;
|
|
3121
3196
|
}
|
|
3122
3197
|
const validationStrategies = [];
|
|
3123
|
-
if (
|
|
3198
|
+
if (Guards47.isDefined(opts.zod)) {
|
|
3124
3199
|
const config = opts.zod;
|
|
3125
3200
|
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3126
3201
|
const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3127
3202
|
const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
|
|
3128
|
-
container.addSingleton(
|
|
3203
|
+
container.addSingleton(TOKENS5.VALIDATOR_SERVICE, () => validatorService);
|
|
3129
3204
|
validationStrategies.push(new SchemaValidationStrategy2(validatorService));
|
|
3130
3205
|
}
|
|
3131
|
-
if (!
|
|
3206
|
+
if (!Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3132
3207
|
for (const strategyToken of opts.customValidationStrategy) {
|
|
3133
|
-
if (
|
|
3208
|
+
if (Guards47.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
|
|
3134
3209
|
}
|
|
3135
3210
|
}
|
|
3136
3211
|
const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
@@ -3141,11 +3216,11 @@ var init_validation_utils = __esm({
|
|
|
3141
3216
|
});
|
|
3142
3217
|
|
|
3143
3218
|
// src/infrastructure/idempotency/idempotency-store.ts
|
|
3144
|
-
var
|
|
3219
|
+
var import_shared61, IdempotencyStore;
|
|
3145
3220
|
var init_idempotency_store = __esm({
|
|
3146
3221
|
"src/infrastructure/idempotency/idempotency-store.ts"() {
|
|
3147
3222
|
"use strict";
|
|
3148
|
-
|
|
3223
|
+
import_shared61 = require("@xeno-js/shared");
|
|
3149
3224
|
IdempotencyStore = class {
|
|
3150
3225
|
/**
|
|
3151
3226
|
* @description Constructs a new instance of IdempotencyStore, accepting an instance of ICache for accessing the caching system and an instance of IIdentityAccessor for obtaining the user's identity context. The IdempotencyStore uses the caching system to manage locks and results of idempotent commands, ensuring that commands with the same ID are processed only once. The identity context is used to build contextual keys, allowing for more granular management of idempotent commands in multi-tenant scenarios.
|
|
@@ -3167,31 +3242,31 @@ var init_idempotency_store = __esm({
|
|
|
3167
3242
|
async acquireLock(requestId, ttlSeconds) {
|
|
3168
3243
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${requestId}`);
|
|
3169
3244
|
return await this._cache.setIfAbsent(
|
|
3170
|
-
`${
|
|
3171
|
-
|
|
3245
|
+
`${import_shared61.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`,
|
|
3246
|
+
import_shared61.IDEMPOTENCY_CONSTANTS.LOCKED_VALUE,
|
|
3172
3247
|
ttlSeconds
|
|
3173
3248
|
);
|
|
3174
3249
|
}
|
|
3175
3250
|
async hasBeenProcessed(commandId) {
|
|
3176
3251
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3177
|
-
return await this._cache.has(`${
|
|
3252
|
+
return await this._cache.has(`${import_shared61.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
3178
3253
|
}
|
|
3179
3254
|
async markAsProcessed(commandId, payload, ttlSeconds) {
|
|
3180
3255
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3181
3256
|
await this._cache.set(
|
|
3182
|
-
`${
|
|
3257
|
+
`${import_shared61.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`,
|
|
3183
3258
|
payload,
|
|
3184
3259
|
ttlSeconds
|
|
3185
3260
|
);
|
|
3186
3261
|
}
|
|
3187
3262
|
async getPayload(commandId) {
|
|
3188
3263
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3189
|
-
const payload = await this._cache.get(`${
|
|
3264
|
+
const payload = await this._cache.get(`${import_shared61.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
3190
3265
|
return payload;
|
|
3191
3266
|
}
|
|
3192
3267
|
async releaseLock(commandId) {
|
|
3193
3268
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
3194
|
-
await this._cache.remove(`${
|
|
3269
|
+
await this._cache.remove(`${import_shared61.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`);
|
|
3195
3270
|
}
|
|
3196
3271
|
};
|
|
3197
3272
|
}
|
|
@@ -3230,16 +3305,16 @@ var init_pipeline_utils = __esm({
|
|
|
3230
3305
|
* @link https://github.com/xeno-js/xeno-js
|
|
3231
3306
|
*/
|
|
3232
3307
|
async addCommand(container, opts) {
|
|
3233
|
-
const { Guards:
|
|
3308
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3234
3309
|
const pipelines = [];
|
|
3235
|
-
if (
|
|
3310
|
+
if (Guards47.isDefined(opts.idempotency)) {
|
|
3236
3311
|
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
|
|
3237
3312
|
const imdStore = new IdempotencyStore2(
|
|
3238
|
-
container.resolve(
|
|
3239
|
-
container.resolve(
|
|
3313
|
+
container.resolve(TOKENS5.CACHE),
|
|
3314
|
+
container.resolve(TOKENS5.CACHE_KEY_BUILDER)
|
|
3240
3315
|
);
|
|
3241
3316
|
const { IdempotencyPipeline: IdempotencyPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3242
|
-
const requestContext = container.resolve(
|
|
3317
|
+
const requestContext = container.resolve(TOKENS5.NETWORK_CONTEXT_ACCESSOR);
|
|
3243
3318
|
const config = opts.idempotency;
|
|
3244
3319
|
pipelines.push(
|
|
3245
3320
|
new IdempotencyPipeline2(
|
|
@@ -3250,7 +3325,7 @@ var init_pipeline_utils = __esm({
|
|
|
3250
3325
|
)
|
|
3251
3326
|
);
|
|
3252
3327
|
}
|
|
3253
|
-
if (
|
|
3328
|
+
if (Guards47.isDefined(opts.concurrency)) {
|
|
3254
3329
|
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3255
3330
|
const config = opts.concurrency;
|
|
3256
3331
|
pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
|
|
@@ -3268,12 +3343,12 @@ var init_pipeline_utils = __esm({
|
|
|
3268
3343
|
* @link https://github.com/xeno-js/xeno-js
|
|
3269
3344
|
*/
|
|
3270
3345
|
async addQuery(container) {
|
|
3271
|
-
const { TOKENS:
|
|
3346
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3272
3347
|
const { QueryCachingPipeline: QueryCachingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3273
3348
|
return new QueryCachingPipeline2(
|
|
3274
|
-
container.resolve(
|
|
3275
|
-
container.resolve(
|
|
3276
|
-
container.resolve(
|
|
3349
|
+
container.resolve(TOKENS5.CACHE),
|
|
3350
|
+
container.resolve(TOKENS5.CACHE_KEY_BUILDER),
|
|
3351
|
+
container.resolve(TOKENS5.LOGGER)
|
|
3277
3352
|
);
|
|
3278
3353
|
}
|
|
3279
3354
|
});
|
|
@@ -3291,11 +3366,11 @@ var init_cqrs_module = __esm({
|
|
|
3291
3366
|
"use strict";
|
|
3292
3367
|
CqrsModule = class {
|
|
3293
3368
|
async configure(container, opts) {
|
|
3294
|
-
const { TOKENS:
|
|
3295
|
-
const logger = container.resolve(
|
|
3369
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3370
|
+
const logger = container.resolve(TOKENS5.LOGGER);
|
|
3296
3371
|
const { Mediator: Mediator2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3297
|
-
container.addSingleton(
|
|
3298
|
-
const serviceScopeAccessor = c.resolve(
|
|
3372
|
+
container.addSingleton(TOKENS5.MEDIATOR, (c) => {
|
|
3373
|
+
const serviceScopeAccessor = c.resolve(TOKENS5.SERVICE_SCOPE_ACCESSOR);
|
|
3299
3374
|
return new Mediator2(serviceScopeAccessor);
|
|
3300
3375
|
});
|
|
3301
3376
|
const { ExceptionPipeline: ExceptionPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
@@ -3307,24 +3382,24 @@ var init_cqrs_module = __esm({
|
|
|
3307
3382
|
new LoggingPipeline2(logger),
|
|
3308
3383
|
new PerformancePipeline2(logger, thresholdMs)
|
|
3309
3384
|
];
|
|
3310
|
-
const { Guards:
|
|
3311
|
-
if (
|
|
3385
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
3386
|
+
if (Guards47.isDefined(opts.authorization.policies) || Guards47.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
3312
3387
|
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
3313
3388
|
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
3314
3389
|
pipelines.push(authPipelines);
|
|
3315
3390
|
}
|
|
3316
|
-
if (
|
|
3391
|
+
if (Guards47.isDefined(opts.validation.zod) || Guards47.isDefined(opts.validation.customValidationStrategy)) {
|
|
3317
3392
|
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
3318
3393
|
const validationPipelines = await ValidationUtils2.addValidation(
|
|
3319
3394
|
container,
|
|
3320
3395
|
opts.validation,
|
|
3321
3396
|
logger
|
|
3322
3397
|
);
|
|
3323
|
-
if (
|
|
3398
|
+
if (Guards47.isDefined(validationPipelines)) pipelines.push(validationPipelines);
|
|
3324
3399
|
}
|
|
3325
3400
|
const commandPipelines = [...pipelines];
|
|
3326
3401
|
const queryPipelines = [...pipelines];
|
|
3327
|
-
if (
|
|
3402
|
+
if (Guards47.isDefined(opts.commandBus.idempotency) || Guards47.isDefined(opts.commandBus.concurrency)) {
|
|
3328
3403
|
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3329
3404
|
const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
|
|
3330
3405
|
commandPipelines.push(...newCommandPipelines);
|
|
@@ -3335,10 +3410,10 @@ var init_cqrs_module = __esm({
|
|
|
3335
3410
|
queryPipelines.push(newQueryPipelines);
|
|
3336
3411
|
}
|
|
3337
3412
|
const { CompositePipeline: CompositePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3338
|
-
container.addSingleton(
|
|
3413
|
+
container.addSingleton(TOKENS5.COMMAND_PIPELINES_BEHAVIOR, () => {
|
|
3339
3414
|
return new CompositePipeline2(commandPipelines);
|
|
3340
3415
|
});
|
|
3341
|
-
container.addSingleton(
|
|
3416
|
+
container.addSingleton(TOKENS5.QUERY_PIPELINES_BEHAVIOR, () => {
|
|
3342
3417
|
return new CompositePipeline2(queryPipelines);
|
|
3343
3418
|
});
|
|
3344
3419
|
}
|
|
@@ -3347,11 +3422,11 @@ var init_cqrs_module = __esm({
|
|
|
3347
3422
|
});
|
|
3348
3423
|
|
|
3349
3424
|
// src/presentation/controllers/base.controller.ts
|
|
3350
|
-
var
|
|
3425
|
+
var import_shared62, BaseController;
|
|
3351
3426
|
var init_base_controller = __esm({
|
|
3352
3427
|
"src/presentation/controllers/base.controller.ts"() {
|
|
3353
3428
|
"use strict";
|
|
3354
|
-
|
|
3429
|
+
import_shared62 = require("@xeno-js/shared");
|
|
3355
3430
|
BaseController = class {
|
|
3356
3431
|
/**
|
|
3357
3432
|
* Constructs a new instance of the BaseController class.
|
|
@@ -3383,7 +3458,7 @@ var init_base_controller = __esm({
|
|
|
3383
3458
|
* @link https://github.com/xeno-js/xeno-js
|
|
3384
3459
|
*/
|
|
3385
3460
|
ok(data, status = 200, meta = {}, headers = {}) {
|
|
3386
|
-
return
|
|
3461
|
+
return import_shared62.HttpHelper.success(data, status, meta, headers);
|
|
3387
3462
|
}
|
|
3388
3463
|
/**
|
|
3389
3464
|
* Helper to automatically map a failed Result (from the CQRS pipeline)
|
|
@@ -3401,7 +3476,7 @@ var init_base_controller = __esm({
|
|
|
3401
3476
|
fail(error, details = void 0, headers = {}) {
|
|
3402
3477
|
const context = this._requestContext.getContext();
|
|
3403
3478
|
const customHeaders = error["header"];
|
|
3404
|
-
return
|
|
3479
|
+
return import_shared62.HttpHelper.error(
|
|
3405
3480
|
{
|
|
3406
3481
|
success: false,
|
|
3407
3482
|
error: {
|
|
@@ -3410,9 +3485,9 @@ var init_base_controller = __esm({
|
|
|
3410
3485
|
path: context?.network.path,
|
|
3411
3486
|
details: details ?? error.message
|
|
3412
3487
|
},
|
|
3413
|
-
correlationId: context?.tracing.correlationId ??
|
|
3414
|
-
requestId: context?.network.requestId ??
|
|
3415
|
-
spanId: context?.tracing.spanId ??
|
|
3488
|
+
correlationId: context?.tracing.correlationId ?? import_shared62.GuidHelper.generate(),
|
|
3489
|
+
requestId: context?.network.requestId ?? import_shared62.GuidHelper.generate(),
|
|
3490
|
+
spanId: context?.tracing.spanId ?? import_shared62.GuidHelper.generate(),
|
|
3416
3491
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3417
3492
|
},
|
|
3418
3493
|
error.status,
|
|
@@ -3426,6 +3501,7 @@ var init_base_controller = __esm({
|
|
|
3426
3501
|
/**
|
|
3427
3502
|
* Helper to send a query through the mediator and return the result.
|
|
3428
3503
|
* @param request - The IQuery instance to be sent.
|
|
3504
|
+
* @param signal - The AbortSignal
|
|
3429
3505
|
* @returns A promise resolving to the result of the query.
|
|
3430
3506
|
*
|
|
3431
3507
|
* @author Xeno
|
|
@@ -3433,13 +3509,13 @@ var init_base_controller = __esm({
|
|
|
3433
3509
|
* @since 2025-09-30
|
|
3434
3510
|
* @link https://github.com/xeno-js/xeno-js
|
|
3435
3511
|
*/
|
|
3436
|
-
_query(request) {
|
|
3437
|
-
const signal = new AbortController().signal;
|
|
3512
|
+
_query(request, signal) {
|
|
3438
3513
|
return this._mediator.query(request, signal);
|
|
3439
3514
|
}
|
|
3440
3515
|
/**
|
|
3441
3516
|
* Helper to send a command through the mediator and return the result.
|
|
3442
3517
|
* @param request - The ICommand instance to be sent.
|
|
3518
|
+
* @param signal - The AbortSignal
|
|
3443
3519
|
* @returns A promise resolving to the result of the command.
|
|
3444
3520
|
*
|
|
3445
3521
|
* @author Xeno
|
|
@@ -3447,8 +3523,7 @@ var init_base_controller = __esm({
|
|
|
3447
3523
|
* @since 2025-09-30
|
|
3448
3524
|
* @link https://github.com/xeno-js/xeno-js
|
|
3449
3525
|
*/
|
|
3450
|
-
_send(request) {
|
|
3451
|
-
const signal = new AbortController().signal;
|
|
3526
|
+
_send(request, signal) {
|
|
3452
3527
|
return this._mediator.send(request, signal);
|
|
3453
3528
|
}
|
|
3454
3529
|
getContext() {
|
|
@@ -3467,11 +3542,11 @@ var init_controllers = __esm({
|
|
|
3467
3542
|
});
|
|
3468
3543
|
|
|
3469
3544
|
// src/presentation/middlewares/allow-method.middleware.ts
|
|
3470
|
-
var
|
|
3545
|
+
var import_shared63, MethodCheckMiddleware;
|
|
3471
3546
|
var init_allow_method_middleware = __esm({
|
|
3472
3547
|
"src/presentation/middlewares/allow-method.middleware.ts"() {
|
|
3473
3548
|
"use strict";
|
|
3474
|
-
|
|
3549
|
+
import_shared63 = require("@xeno-js/shared");
|
|
3475
3550
|
MethodCheckMiddleware = class {
|
|
3476
3551
|
constructor(_requestContext, _allowMethod) {
|
|
3477
3552
|
this._requestContext = _requestContext;
|
|
@@ -3479,25 +3554,25 @@ var init_allow_method_middleware = __esm({
|
|
|
3479
3554
|
}
|
|
3480
3555
|
_requestContext;
|
|
3481
3556
|
_allowMethod;
|
|
3482
|
-
async execute(req,
|
|
3557
|
+
async execute(req, _res, next) {
|
|
3483
3558
|
const isAllowed = this._allowMethod.check(req.path, req.method);
|
|
3484
3559
|
if (!isAllowed) {
|
|
3485
3560
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3486
|
-
return
|
|
3561
|
+
return import_shared63.HttpHelper.error(
|
|
3487
3562
|
{
|
|
3488
3563
|
success: false,
|
|
3489
3564
|
error: {
|
|
3490
|
-
code:
|
|
3491
|
-
message:
|
|
3565
|
+
code: import_shared63.ERROR_CODES.NOT_ALLOWED,
|
|
3566
|
+
message: import_shared63.ERROR_CODE_MESSAGES[import_shared63.ERROR_CODES.NOT_ALLOWED],
|
|
3492
3567
|
details: `Operation blocked by allow method middleware`,
|
|
3493
3568
|
path: req.path
|
|
3494
3569
|
},
|
|
3495
|
-
correlationId: tracing?.correlationId ??
|
|
3496
|
-
requestId: network?.requestId ??
|
|
3497
|
-
spanId: tracing?.spanId ??
|
|
3570
|
+
correlationId: tracing?.correlationId ?? import_shared63.GuidHelper.generate(),
|
|
3571
|
+
requestId: network?.requestId ?? import_shared63.GuidHelper.generate(),
|
|
3572
|
+
spanId: tracing?.spanId ?? import_shared63.GuidHelper.generate(),
|
|
3498
3573
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3499
3574
|
},
|
|
3500
|
-
|
|
3575
|
+
import_shared63.STATUS_CODES.NOT_ALLOWED,
|
|
3501
3576
|
{
|
|
3502
3577
|
Allow: this._allowMethod.getMethods(req.path)
|
|
3503
3578
|
}
|
|
@@ -3510,11 +3585,11 @@ var init_allow_method_middleware = __esm({
|
|
|
3510
3585
|
});
|
|
3511
3586
|
|
|
3512
3587
|
// src/presentation/middlewares/allow-origin.middleware.ts
|
|
3513
|
-
var
|
|
3588
|
+
var import_shared64, AllowOriginMiddleware;
|
|
3514
3589
|
var init_allow_origin_middleware = __esm({
|
|
3515
3590
|
"src/presentation/middlewares/allow-origin.middleware.ts"() {
|
|
3516
3591
|
"use strict";
|
|
3517
|
-
|
|
3592
|
+
import_shared64 = require("@xeno-js/shared");
|
|
3518
3593
|
AllowOriginMiddleware = class {
|
|
3519
3594
|
constructor(_allowOrigin, _requestContext, _logger) {
|
|
3520
3595
|
this._allowOrigin = _allowOrigin;
|
|
@@ -3524,26 +3599,26 @@ var init_allow_origin_middleware = __esm({
|
|
|
3524
3599
|
_allowOrigin;
|
|
3525
3600
|
_requestContext;
|
|
3526
3601
|
_logger;
|
|
3527
|
-
async execute(req,
|
|
3602
|
+
async execute(req, _res, next) {
|
|
3528
3603
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3529
3604
|
const origin = network?.origin;
|
|
3530
3605
|
if (!this._allowOrigin.isAllowed(origin)) {
|
|
3531
3606
|
this._logger.warn(`Access denied by AllowOrigin policy for origin: ${origin ?? "unknown"}`);
|
|
3532
|
-
return
|
|
3607
|
+
return import_shared64.HttpHelper.error(
|
|
3533
3608
|
{
|
|
3534
3609
|
success: false,
|
|
3535
3610
|
error: {
|
|
3536
|
-
code:
|
|
3537
|
-
message:
|
|
3611
|
+
code: import_shared64.ERROR_CODES.FORBIDDEN,
|
|
3612
|
+
message: import_shared64.ERROR_CODE_MESSAGES[import_shared64.ERROR_CODES.FORBIDDEN],
|
|
3538
3613
|
details: `The origin '${origin ?? "unknown"}' is not allowed to access this resource.`,
|
|
3539
3614
|
path: req.path
|
|
3540
3615
|
},
|
|
3541
|
-
correlationId: tracing?.correlationId ??
|
|
3542
|
-
requestId: network?.requestId ??
|
|
3543
|
-
spanId: tracing?.spanId ??
|
|
3616
|
+
correlationId: tracing?.correlationId ?? import_shared64.GuidHelper.generate(),
|
|
3617
|
+
requestId: network?.requestId ?? import_shared64.GuidHelper.generate(),
|
|
3618
|
+
spanId: tracing?.spanId ?? import_shared64.GuidHelper.generate(),
|
|
3544
3619
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3545
3620
|
},
|
|
3546
|
-
|
|
3621
|
+
import_shared64.STATUS_CODES.FORBIDDEN
|
|
3547
3622
|
);
|
|
3548
3623
|
}
|
|
3549
3624
|
return next();
|
|
@@ -3553,11 +3628,11 @@ var init_allow_origin_middleware = __esm({
|
|
|
3553
3628
|
});
|
|
3554
3629
|
|
|
3555
3630
|
// src/presentation/middlewares/auth.middleware.ts
|
|
3556
|
-
var
|
|
3631
|
+
var import_shared65, AuthenticationMiddleware;
|
|
3557
3632
|
var init_auth_middleware = __esm({
|
|
3558
3633
|
"src/presentation/middlewares/auth.middleware.ts"() {
|
|
3559
3634
|
"use strict";
|
|
3560
|
-
|
|
3635
|
+
import_shared65 = require("@xeno-js/shared");
|
|
3561
3636
|
AuthenticationMiddleware = class {
|
|
3562
3637
|
constructor(_requestContext, _tokenExtractor, _gateKeeper, _logger) {
|
|
3563
3638
|
this._requestContext = _requestContext;
|
|
@@ -3569,8 +3644,8 @@ var init_auth_middleware = __esm({
|
|
|
3569
3644
|
_tokenExtractor;
|
|
3570
3645
|
_gateKeeper;
|
|
3571
3646
|
_logger;
|
|
3572
|
-
async execute(req,
|
|
3573
|
-
const token = this._tokenExtractor.extract(headers);
|
|
3647
|
+
async execute(req, _res, next) {
|
|
3648
|
+
const token = this._tokenExtractor.extract(req.headers);
|
|
3574
3649
|
const authResult = await this._gateKeeper.authenticate(token);
|
|
3575
3650
|
if (!authResult.isOk()) {
|
|
3576
3651
|
const error = authResult.getErrorOrThrow();
|
|
@@ -3578,7 +3653,7 @@ var init_auth_middleware = __esm({
|
|
|
3578
3653
|
`Authentication failed for request on path: ${req.path}. Code: ${error.code}. Error: ${error}`
|
|
3579
3654
|
);
|
|
3580
3655
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3581
|
-
return
|
|
3656
|
+
return import_shared65.HttpHelper.error(
|
|
3582
3657
|
{
|
|
3583
3658
|
success: false,
|
|
3584
3659
|
error: {
|
|
@@ -3587,12 +3662,12 @@ var init_auth_middleware = __esm({
|
|
|
3587
3662
|
details: `[Authentication Error] Failed to authenticate request on path: ${req.path}`,
|
|
3588
3663
|
path: req.path
|
|
3589
3664
|
},
|
|
3590
|
-
correlationId: tracing?.correlationId ??
|
|
3591
|
-
requestId: network?.requestId ??
|
|
3592
|
-
spanId: tracing?.spanId ??
|
|
3665
|
+
correlationId: tracing?.correlationId ?? import_shared65.GuidHelper.generate(),
|
|
3666
|
+
requestId: network?.requestId ?? import_shared65.GuidHelper.generate(),
|
|
3667
|
+
spanId: tracing?.spanId ?? import_shared65.GuidHelper.generate(),
|
|
3593
3668
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3594
3669
|
},
|
|
3595
|
-
error.status ??
|
|
3670
|
+
error.status ?? import_shared65.STATUS_CODES.UNAUTHORIZED,
|
|
3596
3671
|
{ "Content-Type": [network?.formatIndicator ?? "application/json"] }
|
|
3597
3672
|
);
|
|
3598
3673
|
}
|
|
@@ -3613,12 +3688,12 @@ var init_composite_middleware = __esm({
|
|
|
3613
3688
|
this._middlewares = _middlewares;
|
|
3614
3689
|
}
|
|
3615
3690
|
_middlewares;
|
|
3616
|
-
async execute(req,
|
|
3691
|
+
async execute(req, res, next) {
|
|
3617
3692
|
let currentNext = next;
|
|
3618
3693
|
for (let i = this._middlewares.length - 1; i >= 0; i--) {
|
|
3619
3694
|
const currentBehavior = this._middlewares[i];
|
|
3620
3695
|
const previousNext = currentNext;
|
|
3621
|
-
currentNext = () => currentBehavior.execute(req,
|
|
3696
|
+
currentNext = () => currentBehavior.execute(req, res, previousNext);
|
|
3622
3697
|
}
|
|
3623
3698
|
return currentNext();
|
|
3624
3699
|
}
|
|
@@ -3627,11 +3702,11 @@ var init_composite_middleware = __esm({
|
|
|
3627
3702
|
});
|
|
3628
3703
|
|
|
3629
3704
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3630
|
-
var
|
|
3705
|
+
var import_shared66, CORSMiddleware;
|
|
3631
3706
|
var init_cors_middleware = __esm({
|
|
3632
3707
|
"src/presentation/middlewares/cors.middleware.ts"() {
|
|
3633
3708
|
"use strict";
|
|
3634
|
-
|
|
3709
|
+
import_shared66 = require("@xeno-js/shared");
|
|
3635
3710
|
CORSMiddleware = class {
|
|
3636
3711
|
constructor(_requestContext, _withCredentials = "false") {
|
|
3637
3712
|
this._requestContext = _requestContext;
|
|
@@ -3639,11 +3714,11 @@ var init_cors_middleware = __esm({
|
|
|
3639
3714
|
}
|
|
3640
3715
|
_requestContext;
|
|
3641
3716
|
_withCredentials;
|
|
3642
|
-
async execute(_req,
|
|
3717
|
+
async execute(_req, _res, next) {
|
|
3643
3718
|
const { network } = this._requestContext.getContext() ?? {};
|
|
3644
3719
|
const origin = network?.origin;
|
|
3645
3720
|
const response = await next();
|
|
3646
|
-
if (
|
|
3721
|
+
if (import_shared66.Guards.isDefined(origin))
|
|
3647
3722
|
response.headers = {
|
|
3648
3723
|
...response.headers ?? {},
|
|
3649
3724
|
"Access-Control-Allow-Origin": origin,
|
|
@@ -3657,11 +3732,11 @@ var init_cors_middleware = __esm({
|
|
|
3657
3732
|
});
|
|
3658
3733
|
|
|
3659
3734
|
// src/presentation/middlewares/csrf.middleware.ts
|
|
3660
|
-
var
|
|
3735
|
+
var import_shared67, CsrfMiddleware;
|
|
3661
3736
|
var init_csrf_middleware = __esm({
|
|
3662
3737
|
"src/presentation/middlewares/csrf.middleware.ts"() {
|
|
3663
3738
|
"use strict";
|
|
3664
|
-
|
|
3739
|
+
import_shared67 = require("@xeno-js/shared");
|
|
3665
3740
|
CsrfMiddleware = class {
|
|
3666
3741
|
constructor(_requestContext, _csrfTokenService) {
|
|
3667
3742
|
this._requestContext = _requestContext;
|
|
@@ -3669,71 +3744,71 @@ var init_csrf_middleware = __esm({
|
|
|
3669
3744
|
}
|
|
3670
3745
|
_requestContext;
|
|
3671
3746
|
_csrfTokenService;
|
|
3672
|
-
async execute(req,
|
|
3747
|
+
async execute(req, _res, next) {
|
|
3673
3748
|
const method = req.method.toUpperCase();
|
|
3674
3749
|
const isStateChanging = ["POST", "PUT", "DELETE", "PATCH"].includes(method);
|
|
3675
3750
|
if (isStateChanging) {
|
|
3676
3751
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3677
3752
|
const headerToken = network?.csrf;
|
|
3678
3753
|
const cookieToken = network?.csrfCookie;
|
|
3679
|
-
if (!
|
|
3680
|
-
return
|
|
3754
|
+
if (!import_shared67.Guards.isDefined(headerToken) || !import_shared67.Guards.isDefined(cookieToken)) {
|
|
3755
|
+
return import_shared67.HttpHelper.error(
|
|
3681
3756
|
{
|
|
3682
3757
|
success: false,
|
|
3683
3758
|
error: {
|
|
3684
|
-
code:
|
|
3685
|
-
message:
|
|
3759
|
+
code: import_shared67.ERROR_CODES.FORBIDDEN,
|
|
3760
|
+
message: import_shared67.ERROR_CODE_MESSAGES[import_shared67.ERROR_CODES.FORBIDDEN],
|
|
3686
3761
|
details: "CSRF token missing",
|
|
3687
3762
|
path: req.path
|
|
3688
3763
|
},
|
|
3689
|
-
correlationId: tracing?.correlationId ??
|
|
3690
|
-
requestId: network?.requestId ??
|
|
3691
|
-
spanId: tracing?.spanId ??
|
|
3764
|
+
correlationId: tracing?.correlationId ?? import_shared67.GuidHelper.generate(),
|
|
3765
|
+
requestId: network?.requestId ?? import_shared67.GuidHelper.generate(),
|
|
3766
|
+
spanId: tracing?.spanId ?? import_shared67.GuidHelper.generate(),
|
|
3692
3767
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3693
3768
|
},
|
|
3694
|
-
|
|
3769
|
+
import_shared67.STATUS_CODES.FORBIDDEN,
|
|
3695
3770
|
{
|
|
3696
3771
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3697
3772
|
}
|
|
3698
3773
|
);
|
|
3699
3774
|
}
|
|
3700
3775
|
if (headerToken !== cookieToken) {
|
|
3701
|
-
return
|
|
3776
|
+
return import_shared67.HttpHelper.error(
|
|
3702
3777
|
{
|
|
3703
3778
|
success: false,
|
|
3704
3779
|
error: {
|
|
3705
|
-
code:
|
|
3706
|
-
message:
|
|
3780
|
+
code: import_shared67.ERROR_CODES.FORBIDDEN,
|
|
3781
|
+
message: import_shared67.ERROR_CODE_MESSAGES[import_shared67.ERROR_CODES.FORBIDDEN],
|
|
3707
3782
|
details: "CSRF token mismatch",
|
|
3708
3783
|
path: req.path
|
|
3709
3784
|
},
|
|
3710
|
-
correlationId: tracing?.correlationId ??
|
|
3711
|
-
requestId: network?.requestId ??
|
|
3712
|
-
spanId: tracing?.spanId ??
|
|
3785
|
+
correlationId: tracing?.correlationId ?? import_shared67.GuidHelper.generate(),
|
|
3786
|
+
requestId: network?.requestId ?? import_shared67.GuidHelper.generate(),
|
|
3787
|
+
spanId: tracing?.spanId ?? import_shared67.GuidHelper.generate(),
|
|
3713
3788
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3714
3789
|
},
|
|
3715
|
-
|
|
3790
|
+
import_shared67.STATUS_CODES.FORBIDDEN,
|
|
3716
3791
|
{
|
|
3717
3792
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3718
3793
|
}
|
|
3719
3794
|
);
|
|
3720
3795
|
}
|
|
3721
|
-
if (!
|
|
3722
|
-
return
|
|
3796
|
+
if (!import_shared67.Guards.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3797
|
+
return import_shared67.HttpHelper.error(
|
|
3723
3798
|
{
|
|
3724
3799
|
success: false,
|
|
3725
3800
|
error: {
|
|
3726
|
-
code:
|
|
3727
|
-
message:
|
|
3801
|
+
code: import_shared67.ERROR_CODES.FORBIDDEN,
|
|
3802
|
+
message: import_shared67.ERROR_CODE_MESSAGES[import_shared67.ERROR_CODES.FORBIDDEN],
|
|
3728
3803
|
details: "CSRF token invalid",
|
|
3729
3804
|
path: req.path
|
|
3730
3805
|
},
|
|
3731
|
-
correlationId: tracing?.correlationId ??
|
|
3732
|
-
requestId: network?.requestId ??
|
|
3733
|
-
spanId: tracing?.spanId ??
|
|
3806
|
+
correlationId: tracing?.correlationId ?? import_shared67.GuidHelper.generate(),
|
|
3807
|
+
requestId: network?.requestId ?? import_shared67.GuidHelper.generate(),
|
|
3808
|
+
spanId: tracing?.spanId ?? import_shared67.GuidHelper.generate(),
|
|
3734
3809
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3735
3810
|
},
|
|
3736
|
-
|
|
3811
|
+
import_shared67.STATUS_CODES.FORBIDDEN,
|
|
3737
3812
|
{
|
|
3738
3813
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3739
3814
|
}
|
|
@@ -3747,11 +3822,11 @@ var init_csrf_middleware = __esm({
|
|
|
3747
3822
|
});
|
|
3748
3823
|
|
|
3749
3824
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3750
|
-
var
|
|
3825
|
+
var import_shared68, CsrfCookieMiddleware;
|
|
3751
3826
|
var init_csrf_cookie_middleware = __esm({
|
|
3752
3827
|
"src/presentation/middlewares/csrf-cookie.middleware.ts"() {
|
|
3753
3828
|
"use strict";
|
|
3754
|
-
|
|
3829
|
+
import_shared68 = require("@xeno-js/shared");
|
|
3755
3830
|
CsrfCookieMiddleware = class {
|
|
3756
3831
|
constructor(_requestContext, _csrfTokenService, _csrf) {
|
|
3757
3832
|
this._requestContext = _requestContext;
|
|
@@ -3761,13 +3836,13 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3761
3836
|
_requestContext;
|
|
3762
3837
|
_csrfTokenService;
|
|
3763
3838
|
_csrf;
|
|
3764
|
-
async execute(_req,
|
|
3839
|
+
async execute(_req, _res, next) {
|
|
3765
3840
|
const response = await next();
|
|
3766
3841
|
const context = this._requestContext.getContext();
|
|
3767
3842
|
const identity = context?.identity;
|
|
3768
3843
|
const network = context?.network;
|
|
3769
|
-
if (!
|
|
3770
|
-
if (
|
|
3844
|
+
if (!import_shared68.Guards.isDefined(identity?.userId)) return response;
|
|
3845
|
+
if (import_shared68.Guards.isDefined(network?.csrfCookie)) return response;
|
|
3771
3846
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3772
3847
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3773
3848
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3785,11 +3860,11 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3785
3860
|
});
|
|
3786
3861
|
|
|
3787
3862
|
// src/presentation/middlewares/options.middleware.ts
|
|
3788
|
-
var
|
|
3863
|
+
var import_shared69, OptionsMiddleware;
|
|
3789
3864
|
var init_options_middleware = __esm({
|
|
3790
3865
|
"src/presentation/middlewares/options.middleware.ts"() {
|
|
3791
3866
|
"use strict";
|
|
3792
|
-
|
|
3867
|
+
import_shared69 = require("@xeno-js/shared");
|
|
3793
3868
|
OptionsMiddleware = class {
|
|
3794
3869
|
constructor(_requestContext, _alloewMethod, _allowHeaders = [], _withCredentials = "false") {
|
|
3795
3870
|
this._requestContext = _requestContext;
|
|
@@ -3801,19 +3876,19 @@ var init_options_middleware = __esm({
|
|
|
3801
3876
|
_alloewMethod;
|
|
3802
3877
|
_allowHeaders;
|
|
3803
3878
|
_withCredentials;
|
|
3804
|
-
async execute(req,
|
|
3879
|
+
async execute(req, _res, next) {
|
|
3805
3880
|
if (req.method.toUpperCase() === "OPTIONS") {
|
|
3806
3881
|
const network = this._requestContext.getNetworkContext();
|
|
3807
3882
|
const origin = network?.origin;
|
|
3808
3883
|
const headers = {};
|
|
3809
|
-
if (
|
|
3884
|
+
if (import_shared69.Guards.isDefined(origin)) {
|
|
3810
3885
|
headers["Access-Control-Allow-Origin"] = origin;
|
|
3811
3886
|
headers["Access-Control-Allow-Credentials"] = this._withCredentials;
|
|
3812
3887
|
headers["Vary"] = "Origin";
|
|
3813
3888
|
}
|
|
3814
3889
|
headers["Access-Control-Allow-Methods"] = this._alloewMethod.getMethods(req.path);
|
|
3815
3890
|
headers["Access-Control-Allow-Headers"] = this._allowHeaders.join(", ");
|
|
3816
|
-
return
|
|
3891
|
+
return import_shared69.HttpHelper.success(null, import_shared69.STATUS_CODES.NO_CONTENT, {}, headers);
|
|
3817
3892
|
}
|
|
3818
3893
|
return await next();
|
|
3819
3894
|
}
|
|
@@ -3822,11 +3897,11 @@ var init_options_middleware = __esm({
|
|
|
3822
3897
|
});
|
|
3823
3898
|
|
|
3824
3899
|
// src/presentation/middlewares/rate-limiter.middleware.ts
|
|
3825
|
-
var
|
|
3900
|
+
var import_shared70, RateLimitMiddleware;
|
|
3826
3901
|
var init_rate_limiter_middleware = __esm({
|
|
3827
3902
|
"src/presentation/middlewares/rate-limiter.middleware.ts"() {
|
|
3828
3903
|
"use strict";
|
|
3829
|
-
|
|
3904
|
+
import_shared70 = require("@xeno-js/shared");
|
|
3830
3905
|
RateLimitMiddleware = class {
|
|
3831
3906
|
constructor(_ctxAccessor, _cache, _keyBuilder, _logger, _opts) {
|
|
3832
3907
|
this._ctxAccessor = _ctxAccessor;
|
|
@@ -3840,25 +3915,25 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3840
3915
|
_keyBuilder;
|
|
3841
3916
|
_logger;
|
|
3842
3917
|
_opts;
|
|
3843
|
-
async execute(req,
|
|
3918
|
+
async execute(req, _res, next) {
|
|
3844
3919
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3845
3920
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3846
|
-
if (!
|
|
3847
|
-
return
|
|
3921
|
+
if (!import_shared70.Guards.isDefined(cacheKey))
|
|
3922
|
+
return import_shared70.HttpHelper.error(
|
|
3848
3923
|
{
|
|
3849
3924
|
success: false,
|
|
3850
3925
|
error: {
|
|
3851
|
-
code:
|
|
3852
|
-
message:
|
|
3926
|
+
code: import_shared70.ERROR_CODES.SYSTEM_ERROR,
|
|
3927
|
+
message: import_shared70.ERROR_CODE_MESSAGES[import_shared70.ERROR_CODES.SYSTEM_ERROR],
|
|
3853
3928
|
details: `Bad Request: Unable to identify client context for rate limiting.`,
|
|
3854
3929
|
path: req.path
|
|
3855
3930
|
},
|
|
3856
|
-
correlationId: tracing?.correlationId ??
|
|
3857
|
-
requestId: network?.requestId ??
|
|
3858
|
-
spanId: tracing?.spanId ??
|
|
3931
|
+
correlationId: tracing?.correlationId ?? import_shared70.GuidHelper.generate(),
|
|
3932
|
+
requestId: network?.requestId ?? import_shared70.GuidHelper.generate(),
|
|
3933
|
+
spanId: tracing?.spanId ?? import_shared70.GuidHelper.generate(),
|
|
3859
3934
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3860
3935
|
},
|
|
3861
|
-
|
|
3936
|
+
import_shared70.STATUS_CODES.SERVICE_UNAVAILABLE,
|
|
3862
3937
|
{
|
|
3863
3938
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3864
3939
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3867,21 +3942,21 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3867
3942
|
const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
|
|
3868
3943
|
if (currentHits > this._opts.maxRequests) {
|
|
3869
3944
|
this._logger.warn(`[RateLimit] key ${cacheKey} has been blocked on ${req.path}`);
|
|
3870
|
-
return
|
|
3945
|
+
return import_shared70.HttpHelper.error(
|
|
3871
3946
|
{
|
|
3872
3947
|
success: false,
|
|
3873
3948
|
error: {
|
|
3874
|
-
code:
|
|
3875
|
-
message:
|
|
3949
|
+
code: import_shared70.ERROR_CODES.TOO_MANY_REQUESTS,
|
|
3950
|
+
message: import_shared70.ERROR_CODE_MESSAGES[import_shared70.ERROR_CODES.TOO_MANY_REQUESTS],
|
|
3876
3951
|
details: `Rate limit exceeded.`,
|
|
3877
3952
|
path: req.path
|
|
3878
3953
|
},
|
|
3879
|
-
correlationId: tracing?.correlationId ??
|
|
3880
|
-
requestId: network?.requestId ??
|
|
3881
|
-
spanId: tracing?.spanId ??
|
|
3954
|
+
correlationId: tracing?.correlationId ?? import_shared70.GuidHelper.generate(),
|
|
3955
|
+
requestId: network?.requestId ?? import_shared70.GuidHelper.generate(),
|
|
3956
|
+
spanId: tracing?.spanId ?? import_shared70.GuidHelper.generate(),
|
|
3882
3957
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3883
3958
|
},
|
|
3884
|
-
|
|
3959
|
+
import_shared70.STATUS_CODES.TOO_MANY_REQUESTS,
|
|
3885
3960
|
{
|
|
3886
3961
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3887
3962
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3896,8 +3971,8 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3896
3971
|
|
|
3897
3972
|
// src/presentation/mappers/context.mapper.ts
|
|
3898
3973
|
function _buildMessagingContext(meta) {
|
|
3899
|
-
const hasSequenceData =
|
|
3900
|
-
const hasMessagingData = hasSequenceData ||
|
|
3974
|
+
const hasSequenceData = import_shared71.Guards.isDefined(meta.sequence?.sequenceId) || import_shared71.Guards.isDefined(meta.sequence?.position) || import_shared71.Guards.isDefined(meta.sequence?.size);
|
|
3975
|
+
const hasMessagingData = hasSequenceData || import_shared71.Guards.isDefined(meta.expiration) || import_shared71.Guards.isDefined(meta.returnAddress);
|
|
3901
3976
|
const messaging = hasMessagingData ? {
|
|
3902
3977
|
returnAddress: meta.returnAddress,
|
|
3903
3978
|
expiration: meta.expiration,
|
|
@@ -3905,11 +3980,11 @@ function _buildMessagingContext(meta) {
|
|
|
3905
3980
|
} : void 0;
|
|
3906
3981
|
return messaging;
|
|
3907
3982
|
}
|
|
3908
|
-
var
|
|
3983
|
+
var import_shared71, ContextMapper;
|
|
3909
3984
|
var init_context_mapper = __esm({
|
|
3910
3985
|
"src/presentation/mappers/context.mapper.ts"() {
|
|
3911
3986
|
"use strict";
|
|
3912
|
-
|
|
3987
|
+
import_shared71 = require("@xeno-js/shared");
|
|
3913
3988
|
ContextMapper = Object.freeze({
|
|
3914
3989
|
/**
|
|
3915
3990
|
* @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.
|
|
@@ -3953,11 +4028,11 @@ var init_context_mapper = __esm({
|
|
|
3953
4028
|
});
|
|
3954
4029
|
|
|
3955
4030
|
// src/presentation/middlewares/request.middleware.ts
|
|
3956
|
-
var
|
|
4031
|
+
var import_shared72, RequestContextMiddleware;
|
|
3957
4032
|
var init_request_middleware = __esm({
|
|
3958
4033
|
"src/presentation/middlewares/request.middleware.ts"() {
|
|
3959
4034
|
"use strict";
|
|
3960
|
-
|
|
4035
|
+
import_shared72 = require("@xeno-js/shared");
|
|
3961
4036
|
init_context_mapper();
|
|
3962
4037
|
RequestContextMiddleware = class {
|
|
3963
4038
|
/**
|
|
@@ -3981,14 +4056,14 @@ var init_request_middleware = __esm({
|
|
|
3981
4056
|
_extractor;
|
|
3982
4057
|
_resolver;
|
|
3983
4058
|
_logger;
|
|
3984
|
-
async execute(req,
|
|
3985
|
-
const correlationId =
|
|
3986
|
-
const requestId =
|
|
4059
|
+
async execute(req, res, next) {
|
|
4060
|
+
const correlationId = import_shared72.GuidHelper.generate();
|
|
4061
|
+
const requestId = import_shared72.GuidHelper.generate();
|
|
3987
4062
|
const spanId = correlationId;
|
|
3988
4063
|
const formatIndicator = "application/json";
|
|
3989
4064
|
try {
|
|
3990
|
-
const meta = this._extractor.extract(headers);
|
|
3991
|
-
const clientIp = this._resolver.resolve(req
|
|
4065
|
+
const meta = this._extractor.extract(req.headers);
|
|
4066
|
+
const clientIp = this._resolver.resolve(req, meta.clientIp);
|
|
3992
4067
|
const metadata = {
|
|
3993
4068
|
...meta,
|
|
3994
4069
|
clientIp,
|
|
@@ -3999,9 +4074,9 @@ var init_request_middleware = __esm({
|
|
|
3999
4074
|
};
|
|
4000
4075
|
const tmpContext = ContextMapper.map({
|
|
4001
4076
|
metadata,
|
|
4002
|
-
identity:
|
|
4077
|
+
identity: import_shared72.GUEST,
|
|
4003
4078
|
path: req.path,
|
|
4004
|
-
transport: req
|
|
4079
|
+
transport: { req, res }
|
|
4005
4080
|
});
|
|
4006
4081
|
const result = await this._requestContext.runAsync(tmpContext, async () => {
|
|
4007
4082
|
return next();
|
|
@@ -4011,12 +4086,12 @@ var init_request_middleware = __esm({
|
|
|
4011
4086
|
return result;
|
|
4012
4087
|
} catch (error) {
|
|
4013
4088
|
this._logger.error("RequestContextMiddleware encountered an error", error);
|
|
4014
|
-
return
|
|
4089
|
+
return import_shared72.HttpHelper.error(
|
|
4015
4090
|
{
|
|
4016
4091
|
success: false,
|
|
4017
4092
|
error: {
|
|
4018
|
-
code:
|
|
4019
|
-
message:
|
|
4093
|
+
code: import_shared72.ERROR_CODES.SYSTEM_ERROR,
|
|
4094
|
+
message: import_shared72.ERROR_CODE_MESSAGES[import_shared72.ERROR_CODES.SYSTEM_ERROR],
|
|
4020
4095
|
details: `[Fatal System Error] Exception caught during request handling on path: ${req.path}`,
|
|
4021
4096
|
path: req.path
|
|
4022
4097
|
},
|
|
@@ -4025,7 +4100,7 @@ var init_request_middleware = __esm({
|
|
|
4025
4100
|
spanId,
|
|
4026
4101
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4027
4102
|
},
|
|
4028
|
-
|
|
4103
|
+
import_shared72.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
4029
4104
|
{ "Content-Type": [formatIndicator] }
|
|
4030
4105
|
);
|
|
4031
4106
|
}
|
|
@@ -4075,11 +4150,11 @@ var init_presentation = __esm({
|
|
|
4075
4150
|
});
|
|
4076
4151
|
|
|
4077
4152
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
4078
|
-
var
|
|
4153
|
+
var import_shared73, RateLimitKeyBuilder;
|
|
4079
4154
|
var init_rate_limit_key_builder_cache = __esm({
|
|
4080
4155
|
"src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
|
|
4081
4156
|
"use strict";
|
|
4082
|
-
|
|
4157
|
+
import_shared73 = require("@xeno-js/shared");
|
|
4083
4158
|
RateLimitKeyBuilder = class {
|
|
4084
4159
|
constructor(_contextAccessor) {
|
|
4085
4160
|
this._contextAccessor = _contextAccessor;
|
|
@@ -4090,12 +4165,12 @@ var init_rate_limit_key_builder_cache = __esm({
|
|
|
4090
4165
|
const tenantId = ctx?.identity?.tenantId;
|
|
4091
4166
|
const userId = ctx?.identity?.userId;
|
|
4092
4167
|
const clientIp = ctx?.network?.clientIp;
|
|
4093
|
-
if (!
|
|
4168
|
+
if (!import_shared73.Guards.isNullOrEmpty(tenantId) && !import_shared73.Guards.isNullOrEmpty(userId))
|
|
4094
4169
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
4095
|
-
if (!
|
|
4170
|
+
if (!import_shared73.Guards.isNullOrEmpty(tenantId) && !import_shared73.Guards.isNullOrEmpty(clientIp))
|
|
4096
4171
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
4097
|
-
if (!
|
|
4098
|
-
if (!
|
|
4172
|
+
if (!import_shared73.Guards.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
4173
|
+
if (!import_shared73.Guards.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
4099
4174
|
return void 0;
|
|
4100
4175
|
}
|
|
4101
4176
|
};
|
|
@@ -4129,12 +4204,16 @@ var init_middleware_module = __esm({
|
|
|
4129
4204
|
"use strict";
|
|
4130
4205
|
MiddlewareModule = class {
|
|
4131
4206
|
async configure(container, opts) {
|
|
4132
|
-
const { Guards:
|
|
4207
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4133
4208
|
const { HttpCookieExtractor: HttpCookieExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4134
4209
|
const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4135
|
-
const tokenExtractor = await this._getTokenExtractor(
|
|
4210
|
+
const tokenExtractor = await this._getTokenExtractor(
|
|
4211
|
+
opts.isSSR,
|
|
4212
|
+
opts.authCookieName,
|
|
4213
|
+
opts.customTokenExtractor
|
|
4214
|
+
);
|
|
4136
4215
|
container.addSingleton(
|
|
4137
|
-
|
|
4216
|
+
TOKENS5.SERVICE_EXTRACTOR,
|
|
4138
4217
|
() => new HttpHeaderExtractor2(
|
|
4139
4218
|
tokenExtractor,
|
|
4140
4219
|
new HttpCookieExtractor2(),
|
|
@@ -4144,18 +4223,18 @@ var init_middleware_module = __esm({
|
|
|
4144
4223
|
);
|
|
4145
4224
|
const { ClientIpResolver: ClientIpResolver2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4146
4225
|
const middlewares = [];
|
|
4147
|
-
const requestContext = container.resolve(
|
|
4148
|
-
const logger = container.resolve(
|
|
4226
|
+
const requestContext = container.resolve(TOKENS5.REQUEST_CONTEXT);
|
|
4227
|
+
const logger = container.resolve(TOKENS5.LOGGER);
|
|
4149
4228
|
const { RequestContextMiddleware: RequestContextMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4150
4229
|
middlewares.push(
|
|
4151
4230
|
new RequestContextMiddleware2(
|
|
4152
4231
|
requestContext,
|
|
4153
|
-
container.resolve(
|
|
4232
|
+
container.resolve(TOKENS5.SERVICE_EXTRACTOR),
|
|
4154
4233
|
new ClientIpResolver2(opts.trustedProxies),
|
|
4155
4234
|
logger
|
|
4156
4235
|
)
|
|
4157
4236
|
);
|
|
4158
|
-
if (!
|
|
4237
|
+
if (!Guards47.isNullOrEmpty(opts.allowOrigins)) {
|
|
4159
4238
|
if (opts.withCredentials && opts.allowOrigins.includes("*"))
|
|
4160
4239
|
throw new Error(
|
|
4161
4240
|
"Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
|
|
@@ -4181,7 +4260,7 @@ var init_middleware_module = __esm({
|
|
|
4181
4260
|
const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4182
4261
|
middlewares.push(new CORSMiddleware2(requestContext, withCredentials));
|
|
4183
4262
|
}
|
|
4184
|
-
if (
|
|
4263
|
+
if (Guards47.isDefined(opts.routeRegistry)) {
|
|
4185
4264
|
const { MethodCheckMiddleware: MethodCheckMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4186
4265
|
middlewares.push(new MethodCheckMiddleware2(requestContext, allowMethod));
|
|
4187
4266
|
}
|
|
@@ -4203,31 +4282,31 @@ var init_middleware_module = __esm({
|
|
|
4203
4282
|
new AuthenticationMiddleware2(
|
|
4204
4283
|
requestContext,
|
|
4205
4284
|
tokenExtractor,
|
|
4206
|
-
new GateKeeper2(container.resolve(
|
|
4285
|
+
new GateKeeper2(container.resolve(TOKENS5.BASE_AUTH_SERVICE), new ClaimsIdentityMapper2()),
|
|
4207
4286
|
logger
|
|
4208
4287
|
)
|
|
4209
4288
|
);
|
|
4210
4289
|
}
|
|
4211
|
-
if (
|
|
4290
|
+
if (Guards47.isDefined(opts.rateLimite.maxRequests) || Guards47.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4212
4291
|
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4213
|
-
|
|
4214
|
-
|
|
4292
|
+
Guards47.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4293
|
+
Guards47.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4215
4294
|
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4216
|
-
|
|
4217
|
-
|
|
4295
|
+
Guards47.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4296
|
+
Guards47.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4218
4297
|
const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
|
|
4219
4298
|
const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4220
4299
|
middlewares.push(
|
|
4221
4300
|
new RateLimitMiddleware2(
|
|
4222
4301
|
requestContext,
|
|
4223
|
-
container.resolve(
|
|
4302
|
+
container.resolve(TOKENS5.CACHE),
|
|
4224
4303
|
new RateLimitKeyBuilder2(requestContext),
|
|
4225
4304
|
logger,
|
|
4226
4305
|
{ maxRequests, windowSeconds }
|
|
4227
4306
|
)
|
|
4228
4307
|
);
|
|
4229
4308
|
}
|
|
4230
|
-
if (
|
|
4309
|
+
if (Guards47.isDefined(opts.csrf)) {
|
|
4231
4310
|
const csrf = opts.csrf;
|
|
4232
4311
|
const { EdgeCryptoService: EdgeCryptoService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4233
4312
|
container.addSingleton("CRYPTO_SERVICE", () => new EdgeCryptoService2());
|
|
@@ -4247,22 +4326,24 @@ var init_middleware_module = __esm({
|
|
|
4247
4326
|
middlewares.push(new CsrfMiddleware2(requestContext, container.resolve("CSRF_TOKEN_SERVICE")));
|
|
4248
4327
|
}
|
|
4249
4328
|
const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4250
|
-
container.addSingleton(
|
|
4329
|
+
container.addSingleton(TOKENS5.MIDDLEWARE, () => {
|
|
4251
4330
|
return new CompositeMiddleware2(middlewares);
|
|
4252
4331
|
});
|
|
4253
4332
|
}
|
|
4254
|
-
async _getTokenExtractor(isSSR) {
|
|
4333
|
+
async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
|
|
4334
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
4335
|
+
if (Guards47.isDefined(customTokenExtractor)) return customTokenExtractor();
|
|
4255
4336
|
if (isSSR) {
|
|
4256
4337
|
const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4257
4338
|
return new SupabaseSsrTokenExtractor2();
|
|
4258
4339
|
} else {
|
|
4259
4340
|
const { BearerTokenExtractor: BearerTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4260
|
-
return new BearerTokenExtractor2();
|
|
4341
|
+
return new BearerTokenExtractor2(cookieName ?? "sb-access-token");
|
|
4261
4342
|
}
|
|
4262
4343
|
}
|
|
4263
4344
|
async _getAllowMethod(configure, opts) {
|
|
4264
|
-
const { Guards:
|
|
4265
|
-
if (!configure || !
|
|
4345
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
4346
|
+
if (!configure || !Guards47.isDefined(opts)) return void 0;
|
|
4266
4347
|
const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
4267
4348
|
return new AllowMethodFactory2().create(opts);
|
|
4268
4349
|
}
|
|
@@ -4281,17 +4362,17 @@ var init_context_module = __esm({
|
|
|
4281
4362
|
"use strict";
|
|
4282
4363
|
ContextModule = class {
|
|
4283
4364
|
async configure(container) {
|
|
4284
|
-
const { TOKENS:
|
|
4365
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4285
4366
|
const { ServiceScopeFactory: ServiceScopeFactory2 } = await Promise.resolve().then(() => (init_service_scope_factory(), service_scope_factory_exports));
|
|
4286
4367
|
const { NodeRequestContextFactory: NodeRequestContextFactory2 } = await Promise.resolve().then(() => (init_request_context_factory(), request_context_factory_exports));
|
|
4287
4368
|
const requestContext = new NodeRequestContextFactory2(
|
|
4288
4369
|
new ServiceScopeFactory2(container)
|
|
4289
4370
|
).create();
|
|
4290
|
-
container.addSingleton(
|
|
4291
|
-
container.addSingleton(
|
|
4292
|
-
container.addSingleton(
|
|
4293
|
-
container.addSingleton(
|
|
4294
|
-
container.addSingleton(
|
|
4371
|
+
container.addSingleton(TOKENS5.REQUEST_CONTEXT, () => requestContext);
|
|
4372
|
+
container.addSingleton(TOKENS5.CONTEXT_ACCESSOR, () => requestContext);
|
|
4373
|
+
container.addSingleton(TOKENS5.IDENTITY_ACCESSOR, () => requestContext);
|
|
4374
|
+
container.addSingleton(TOKENS5.SERVICE_SCOPE_ACCESSOR, () => requestContext);
|
|
4375
|
+
container.addSingleton(TOKENS5.NETWORK_CONTEXT_ACCESSOR, () => requestContext);
|
|
4295
4376
|
const { UserContextFactory: UserContextFactory2 } = await Promise.resolve().then(() => (init_user_context_factory(), user_context_factory_exports));
|
|
4296
4377
|
container.addSingleton("USER_CONTEXT_FACTORY", () => {
|
|
4297
4378
|
return new UserContextFactory2(requestContext);
|
|
@@ -4309,7 +4390,7 @@ __export(index_exports, {
|
|
|
4309
4390
|
BaseController: () => BaseController,
|
|
4310
4391
|
BaseHandler: () => BaseHandler,
|
|
4311
4392
|
BasePostgresSqlDataSource: () => BasePostgresSqlDataSource,
|
|
4312
|
-
BaseQuery: () =>
|
|
4393
|
+
BaseQuery: () => import_shared80.Query,
|
|
4313
4394
|
BaseSqliteSqlDataSource: () => BaseSqliteSqlDataSource,
|
|
4314
4395
|
ContainerUtils: () => ContainerUtils,
|
|
4315
4396
|
ReadDao: () => ReadDao,
|
|
@@ -4321,7 +4402,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
4321
4402
|
init_application();
|
|
4322
4403
|
|
|
4323
4404
|
// src/infrastructure/builder/app.builder.ts
|
|
4324
|
-
var
|
|
4405
|
+
var import_shared74 = require("@xeno-js/shared");
|
|
4325
4406
|
|
|
4326
4407
|
// src/infrastructure/configuration/configuration.ts
|
|
4327
4408
|
var import_shared32 = require("@xeno-js/shared");
|
|
@@ -4600,13 +4681,14 @@ var AppBuilder = class {
|
|
|
4600
4681
|
constructor(container) {
|
|
4601
4682
|
this._container = container ?? new ServiceContainer();
|
|
4602
4683
|
this._container.addSingleton(
|
|
4603
|
-
|
|
4684
|
+
import_shared74.TOKENS.CONFIGURATION_SERVICE,
|
|
4604
4685
|
() => new EnvironmentConfigurationService()
|
|
4605
4686
|
);
|
|
4606
|
-
this._configuration = this._container.resolve(
|
|
4687
|
+
this._configuration = this._container.resolve(import_shared74.TOKENS.CONFIGURATION_SERVICE);
|
|
4607
4688
|
this._middlewareConfig.allowOrigins?.push(
|
|
4608
4689
|
this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
|
|
4609
4690
|
);
|
|
4691
|
+
this.addContext();
|
|
4610
4692
|
}
|
|
4611
4693
|
// --- Module Configurations ---
|
|
4612
4694
|
_modules = [];
|
|
@@ -4642,7 +4724,23 @@ var AppBuilder = class {
|
|
|
4642
4724
|
allowOrigins: [],
|
|
4643
4725
|
allowHeaders: [],
|
|
4644
4726
|
cors: true,
|
|
4645
|
-
withCredentials: true
|
|
4727
|
+
withCredentials: true,
|
|
4728
|
+
authCookieName: "sb-access-token"
|
|
4729
|
+
};
|
|
4730
|
+
_authConfig = {
|
|
4731
|
+
url: "",
|
|
4732
|
+
key: "",
|
|
4733
|
+
opts: void 0,
|
|
4734
|
+
redirectTo: "",
|
|
4735
|
+
storageOpts: { type: "memory", cookieOpts: void 0, storage: void 0 },
|
|
4736
|
+
ssrOpts: void 0,
|
|
4737
|
+
customAuth: void 0,
|
|
4738
|
+
cookieOpts: {
|
|
4739
|
+
path: "/",
|
|
4740
|
+
httpOnly: true,
|
|
4741
|
+
sameSite: "lax",
|
|
4742
|
+
secure: true
|
|
4743
|
+
}
|
|
4646
4744
|
};
|
|
4647
4745
|
_httpConfig = {
|
|
4648
4746
|
dataSourceToken: void 0,
|
|
@@ -4663,7 +4761,7 @@ var AppBuilder = class {
|
|
|
4663
4761
|
resilience: { retry: {}, circuitBreaker: {}, bulkhead: {} }
|
|
4664
4762
|
};
|
|
4665
4763
|
_loggerConfig = {
|
|
4666
|
-
level:
|
|
4764
|
+
level: import_shared74.LOG_LEVEL.DEBUG,
|
|
4667
4765
|
console: true,
|
|
4668
4766
|
sentry: { config: void 0 },
|
|
4669
4767
|
pino: { config: void 0 },
|
|
@@ -4721,7 +4819,7 @@ var AppBuilder = class {
|
|
|
4721
4819
|
* @link https://github.com/xeno-js/xeno-js
|
|
4722
4820
|
*/
|
|
4723
4821
|
addLogger(setupAction) {
|
|
4724
|
-
if (
|
|
4822
|
+
if (import_shared74.Guards.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
|
|
4725
4823
|
if (this._isLoggerModuleQueued) return this;
|
|
4726
4824
|
this._isLoggerModuleQueued = true;
|
|
4727
4825
|
this._modules.push({
|
|
@@ -4746,7 +4844,7 @@ var AppBuilder = class {
|
|
|
4746
4844
|
* @link https://github.com/xeno-js/xeno-js
|
|
4747
4845
|
*/
|
|
4748
4846
|
addCache(setupAction) {
|
|
4749
|
-
if (
|
|
4847
|
+
if (import_shared74.Guards.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
4750
4848
|
if (this._isCacheModuleQueued) return this;
|
|
4751
4849
|
this._isCacheModuleQueued = true;
|
|
4752
4850
|
this._modules.push({
|
|
@@ -4773,21 +4871,13 @@ var AppBuilder = class {
|
|
|
4773
4871
|
addAuth(setupAction) {
|
|
4774
4872
|
if (this._isAuthModuleQueued) return this;
|
|
4775
4873
|
this._isAuthModuleQueued = true;
|
|
4776
|
-
|
|
4777
|
-
url: "",
|
|
4778
|
-
key: "",
|
|
4779
|
-
opts: void 0,
|
|
4780
|
-
redirectTo: "",
|
|
4781
|
-
storageOpts: { type: "memory", cookieOpts: void 0, storage: void 0 },
|
|
4782
|
-
ssrOpts: void 0
|
|
4783
|
-
};
|
|
4784
|
-
setupAction(config, this._configuration);
|
|
4874
|
+
setupAction(this._authConfig, this._configuration);
|
|
4785
4875
|
this._modules.push({
|
|
4786
4876
|
priority: 3,
|
|
4787
4877
|
name: "AuthModule",
|
|
4788
4878
|
action: async () => {
|
|
4789
4879
|
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
4790
|
-
await AuthUtils2.addAuthN(this._container,
|
|
4880
|
+
await AuthUtils2.addAuthN(this._container, this._authConfig);
|
|
4791
4881
|
}
|
|
4792
4882
|
});
|
|
4793
4883
|
return this;
|
|
@@ -4857,7 +4947,7 @@ var AppBuilder = class {
|
|
|
4857
4947
|
* @link https://github.com/xeno-js/xeno-js
|
|
4858
4948
|
*/
|
|
4859
4949
|
addPipeline(setupAction) {
|
|
4860
|
-
if (
|
|
4950
|
+
if (import_shared74.Guards.isDefined(setupAction)) {
|
|
4861
4951
|
setupAction(this._pipelineConfig, this._configuration);
|
|
4862
4952
|
}
|
|
4863
4953
|
this._queuePipelineModule();
|
|
@@ -4978,7 +5068,7 @@ var AppBuilder = class {
|
|
|
4978
5068
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
4979
5069
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
4980
5070
|
`);
|
|
4981
|
-
if (error instanceof Error &&
|
|
5071
|
+
if (error instanceof Error && import_shared74.Guards.isDefined(error.stack)) {
|
|
4982
5072
|
console.error(error.stack);
|
|
4983
5073
|
}
|
|
4984
5074
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5039,7 +5129,8 @@ var AppBuilder = class {
|
|
|
5039
5129
|
const middlewareModule = new MiddlewareModule2();
|
|
5040
5130
|
await middlewareModule.configure(this._container, {
|
|
5041
5131
|
...this._middlewareConfig,
|
|
5042
|
-
isAuth: this._isAuthModuleQueued
|
|
5132
|
+
isAuth: this._isAuthModuleQueued,
|
|
5133
|
+
customTokenExtractor: this._authConfig.customAuth?.authHeaderExtractor
|
|
5043
5134
|
});
|
|
5044
5135
|
}
|
|
5045
5136
|
});
|
|
@@ -5105,7 +5196,7 @@ var BaseSqliteSqlDataSource = class {
|
|
|
5105
5196
|
};
|
|
5106
5197
|
|
|
5107
5198
|
// src/infrastructure/datasources/remote.datasource.ts
|
|
5108
|
-
var
|
|
5199
|
+
var import_shared75 = require("@xeno-js/shared");
|
|
5109
5200
|
|
|
5110
5201
|
// src/infrastructure/index.ts
|
|
5111
5202
|
init_factories();
|
|
@@ -5133,8 +5224,8 @@ init_pipeline_utils();
|
|
|
5133
5224
|
init_validation_utils();
|
|
5134
5225
|
|
|
5135
5226
|
// src/infrastructure/repositories/read-dao.ts
|
|
5136
|
-
var import_shared75 = require("@xeno-js/shared");
|
|
5137
5227
|
var import_shared76 = require("@xeno-js/shared");
|
|
5228
|
+
var import_shared77 = require("@xeno-js/shared");
|
|
5138
5229
|
var ReadDao = class {
|
|
5139
5230
|
/**
|
|
5140
5231
|
* Constructs a new ReadDao instance.
|
|
@@ -5154,23 +5245,23 @@ var ReadDao = class {
|
|
|
5154
5245
|
_dataSource;
|
|
5155
5246
|
_mapper;
|
|
5156
5247
|
async findById(id, ctx, signal) {
|
|
5157
|
-
|
|
5248
|
+
import_shared76.AppError.throwIfAborted(signal, "ReadDao.findById");
|
|
5158
5249
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5159
|
-
if (
|
|
5250
|
+
if (import_shared77.Guards.isNullOrEmpty(result)) return import_shared76.Result.ok();
|
|
5160
5251
|
const entity = this._mapper.toEntity(result);
|
|
5161
|
-
return
|
|
5252
|
+
return import_shared76.Result.ok(entity);
|
|
5162
5253
|
}
|
|
5163
5254
|
async findAll(ctx, signal) {
|
|
5164
|
-
|
|
5255
|
+
import_shared76.AppError.throwIfAborted(signal, "ReadDao.findAll");
|
|
5165
5256
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5166
5257
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5167
|
-
return
|
|
5258
|
+
return import_shared76.Result.ok(entities);
|
|
5168
5259
|
}
|
|
5169
5260
|
};
|
|
5170
5261
|
|
|
5171
5262
|
// src/infrastructure/repositories/repository.ts
|
|
5172
|
-
var import_shared77 = require("@xeno-js/shared");
|
|
5173
5263
|
var import_shared78 = require("@xeno-js/shared");
|
|
5264
|
+
var import_shared79 = require("@xeno-js/shared");
|
|
5174
5265
|
var Repository = class {
|
|
5175
5266
|
/**
|
|
5176
5267
|
* Constructs a new Repository instance.
|
|
@@ -5190,35 +5281,35 @@ var Repository = class {
|
|
|
5190
5281
|
_dataSource;
|
|
5191
5282
|
_mapper;
|
|
5192
5283
|
async findById(id, ctx, signal) {
|
|
5193
|
-
|
|
5284
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.findById");
|
|
5194
5285
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5195
|
-
if (
|
|
5286
|
+
if (import_shared79.Guards.isNullOrEmpty(result)) return import_shared78.Result.ok();
|
|
5196
5287
|
const entity = this._mapper.toEntity(result);
|
|
5197
|
-
return
|
|
5288
|
+
return import_shared78.Result.ok(entity);
|
|
5198
5289
|
}
|
|
5199
5290
|
async findAll(ctx, signal) {
|
|
5200
|
-
|
|
5291
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.findAll");
|
|
5201
5292
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5202
5293
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5203
|
-
return
|
|
5294
|
+
return import_shared78.Result.ok(entities);
|
|
5204
5295
|
}
|
|
5205
5296
|
async save(entity, signal) {
|
|
5206
5297
|
const dto = this._mapper.toDto(entity);
|
|
5207
|
-
|
|
5298
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.save");
|
|
5208
5299
|
await this._dataSource.insert(dto, signal);
|
|
5209
|
-
return
|
|
5300
|
+
return import_shared78.Result.ok();
|
|
5210
5301
|
}
|
|
5211
5302
|
async delete(entity, ctx, signal) {
|
|
5212
5303
|
const dto = this._mapper.toDto(entity);
|
|
5213
|
-
|
|
5304
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.delete");
|
|
5214
5305
|
await this._dataSource.delete(dto, ctx, signal);
|
|
5215
|
-
return
|
|
5306
|
+
return import_shared78.Result.ok();
|
|
5216
5307
|
}
|
|
5217
5308
|
async update(id, entity, ctx, signal) {
|
|
5218
5309
|
const dto = this._mapper.toPartialDto(entity);
|
|
5219
|
-
|
|
5310
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.update");
|
|
5220
5311
|
await this._dataSource.update(id, dto, ctx, signal);
|
|
5221
|
-
return
|
|
5312
|
+
return import_shared78.Result.ok();
|
|
5222
5313
|
}
|
|
5223
5314
|
};
|
|
5224
5315
|
|
|
@@ -5236,7 +5327,7 @@ __reExport(drizzle_types_exports, require("drizzle-orm"));
|
|
|
5236
5327
|
__reExport(index_exports, drizzle_types_exports, module.exports);
|
|
5237
5328
|
init_presentation();
|
|
5238
5329
|
__reExport(index_exports, require("@xeno-js/shared"), module.exports);
|
|
5239
|
-
var
|
|
5330
|
+
var import_shared80 = require("@xeno-js/shared");
|
|
5240
5331
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5241
5332
|
0 && (module.exports = {
|
|
5242
5333
|
AppBuilder,
|