@xeno-js/core 1.0.0 → 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 +6 -7
- package/dist/index.cjs +416 -340
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +269 -192
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1500,30 +1500,30 @@ var init_logger_utils = __esm({
|
|
|
1500
1500
|
*/
|
|
1501
1501
|
async addLogger(container, opts) {
|
|
1502
1502
|
const loggerDependencies = [];
|
|
1503
|
-
const { Guards:
|
|
1504
|
-
if (!
|
|
1503
|
+
const { Guards: Guards47, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
1504
|
+
if (!Guards47.isDefined(opts) || opts.console) {
|
|
1505
1505
|
const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
|
|
1506
1506
|
loggerDependencies.push(new ConsoleLogger2(opts?.level));
|
|
1507
1507
|
}
|
|
1508
|
-
if (
|
|
1509
|
-
if (
|
|
1508
|
+
if (Guards47.isDefined(opts)) {
|
|
1509
|
+
if (Guards47.isDefined(opts.sentry.config)) {
|
|
1510
1510
|
const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
|
|
1511
1511
|
loggerDependencies.push(new SentryLoggerFactory2().create(opts));
|
|
1512
1512
|
}
|
|
1513
|
-
if (
|
|
1513
|
+
if (Guards47.isDefined(opts.pino.config)) {
|
|
1514
1514
|
const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
|
|
1515
1515
|
loggerDependencies.push(new PinoLoggerFactory2().create(opts));
|
|
1516
1516
|
}
|
|
1517
|
-
if (!
|
|
1517
|
+
if (!Guards47.isNullOrEmpty(opts.customLoggers)) {
|
|
1518
1518
|
const customLoggers = opts.customLoggers;
|
|
1519
1519
|
customLoggers.forEach((fn) => {
|
|
1520
|
-
if (
|
|
1520
|
+
if (Guards47.isDefined(fn)) loggerDependencies.push(fn(container));
|
|
1521
1521
|
});
|
|
1522
1522
|
}
|
|
1523
1523
|
}
|
|
1524
1524
|
const { BaseLogger } = await import("@xeno-js/shared");
|
|
1525
|
-
container.addSingleton(
|
|
1526
|
-
const context = c.resolve(
|
|
1525
|
+
container.addSingleton(TOKENS5.LOGGER, (c) => {
|
|
1526
|
+
const context = c.resolve(TOKENS5.CONTEXT_ACCESSOR);
|
|
1527
1527
|
return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, loggerDependencies);
|
|
1528
1528
|
});
|
|
1529
1529
|
}
|
|
@@ -1684,25 +1684,25 @@ var init_cache_utils = __esm({
|
|
|
1684
1684
|
* @link https://github.com/xeno-js/xeno-js
|
|
1685
1685
|
*/
|
|
1686
1686
|
async addCache(container, opts) {
|
|
1687
|
-
const { Guards:
|
|
1688
|
-
if (!opts.inMemory && !
|
|
1687
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
1688
|
+
if (!opts.inMemory && !Guards47.isDefined(opts.redis)) {
|
|
1689
1689
|
throw new Error(
|
|
1690
1690
|
"No cache strategies are configured. Please provide at least one cache strategy."
|
|
1691
1691
|
);
|
|
1692
1692
|
}
|
|
1693
1693
|
const { CacheKeyBuilder } = await import("@xeno-js/shared");
|
|
1694
1694
|
container.addSingleton(
|
|
1695
|
-
|
|
1696
|
-
(c) => new CacheKeyBuilder(c.resolve(
|
|
1695
|
+
TOKENS5.CACHE_KEY_BUILDER,
|
|
1696
|
+
(c) => new CacheKeyBuilder(c.resolve(TOKENS5.IDENTITY_ACCESSOR))
|
|
1697
1697
|
);
|
|
1698
|
-
if (opts.inMemory || !
|
|
1698
|
+
if (opts.inMemory || !Guards47.isDefined(opts.redis)) {
|
|
1699
1699
|
const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
|
|
1700
|
-
container.addSingleton(
|
|
1700
|
+
container.addSingleton(TOKENS5.CACHE, () => new InMemoryCacheExtended2());
|
|
1701
1701
|
return;
|
|
1702
1702
|
}
|
|
1703
|
-
if (
|
|
1703
|
+
if (Guards47.isDefined(opts.redis)) {
|
|
1704
1704
|
const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
|
|
1705
|
-
container.addSingleton(
|
|
1705
|
+
container.addSingleton(TOKENS5.CACHE, () => {
|
|
1706
1706
|
const config = opts.redis;
|
|
1707
1707
|
return new RedisCacheFactory2().create(config);
|
|
1708
1708
|
});
|
|
@@ -1848,6 +1848,73 @@ var init_concurrency = __esm({
|
|
|
1848
1848
|
}
|
|
1849
1849
|
});
|
|
1850
1850
|
|
|
1851
|
+
// src/infrastructure/services/cookies/cookies.service.ts
|
|
1852
|
+
import { Guards as Guards24 } from "@xeno-js/shared";
|
|
1853
|
+
var CookieHandler;
|
|
1854
|
+
var init_cookies_service = __esm({
|
|
1855
|
+
"src/infrastructure/services/cookies/cookies.service.ts"() {
|
|
1856
|
+
"use strict";
|
|
1857
|
+
CookieHandler = class {
|
|
1858
|
+
constructor(contextAccessor, _config, _cookieOpts) {
|
|
1859
|
+
this.contextAccessor = contextAccessor;
|
|
1860
|
+
this._config = _config;
|
|
1861
|
+
this._cookieOpts = _cookieOpts;
|
|
1862
|
+
}
|
|
1863
|
+
contextAccessor;
|
|
1864
|
+
_config;
|
|
1865
|
+
_cookieOpts;
|
|
1866
|
+
getAll() {
|
|
1867
|
+
const network = this.contextAccessor.getNetworkContext();
|
|
1868
|
+
const req = network?.transport?.req;
|
|
1869
|
+
if (!Guards24.isDefined(req) || Guards24.isNullOrEmpty(req.headers.get("cookie"))) return [];
|
|
1870
|
+
return req.headers.get("cookie")?.split(";").map((cookie) => {
|
|
1871
|
+
const [name, ...rest] = cookie.split("=");
|
|
1872
|
+
return { name: name.trim(), value: rest.join("=") };
|
|
1873
|
+
}) ?? [];
|
|
1874
|
+
}
|
|
1875
|
+
setAll(cookies) {
|
|
1876
|
+
const network = this.contextAccessor.getNetworkContext();
|
|
1877
|
+
const res = network?.transport?.res;
|
|
1878
|
+
if (!Guards24.isDefined(res)) return;
|
|
1879
|
+
const serializedCookies = cookies.map((c) => this.serialize(c));
|
|
1880
|
+
const existingSetCookie = res.headers.getSetCookie();
|
|
1881
|
+
res.headers.delete("Set-Cookie");
|
|
1882
|
+
for (const cookie of [...existingSetCookie, ...serializedCookies]) {
|
|
1883
|
+
res.headers.append("Set-Cookie", cookie);
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
serialize(cookie) {
|
|
1887
|
+
const safeName = encodeURIComponent(cookie.name);
|
|
1888
|
+
const safeValue = encodeURIComponent(cookie.value);
|
|
1889
|
+
let str = `${safeName}=${safeValue}`;
|
|
1890
|
+
const isProd = this._config.get("NODE_ENV") === "production";
|
|
1891
|
+
const defaultOptions = {
|
|
1892
|
+
path: this._cookieOpts.path,
|
|
1893
|
+
httpOnly: this._cookieOpts.httpOnly,
|
|
1894
|
+
secure: this._cookieOpts.secure ?? isProd,
|
|
1895
|
+
sameSite: this._cookieOpts.sameSite ?? "Lax"
|
|
1896
|
+
};
|
|
1897
|
+
const opts = { ...defaultOptions, ...cookie.options ?? {} };
|
|
1898
|
+
str += `; Path=${opts.path}`;
|
|
1899
|
+
if (Guards24.isDefined(opts.maxAge)) str += `; Max-Age=${opts.maxAge}`;
|
|
1900
|
+
if (Guards24.isDefined(opts.domain)) str += `; Domain=${opts.domain}`;
|
|
1901
|
+
if (Guards24.isDefined(opts.sameSite)) str += `; SameSite=${opts.sameSite}`;
|
|
1902
|
+
if (opts.secure) str += `; Secure`;
|
|
1903
|
+
if (opts.httpOnly) str += `; HttpOnly`;
|
|
1904
|
+
return str;
|
|
1905
|
+
}
|
|
1906
|
+
};
|
|
1907
|
+
}
|
|
1908
|
+
});
|
|
1909
|
+
|
|
1910
|
+
// src/infrastructure/services/cookies/index.ts
|
|
1911
|
+
var init_cookies = __esm({
|
|
1912
|
+
"src/infrastructure/services/cookies/index.ts"() {
|
|
1913
|
+
"use strict";
|
|
1914
|
+
init_cookies_service();
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
|
|
1851
1918
|
// src/infrastructure/services/crypto/crypto.service.ts
|
|
1852
1919
|
var EdgeCryptoService;
|
|
1853
1920
|
var init_crypto_service = __esm({
|
|
@@ -1896,7 +1963,7 @@ var init_crypto = __esm({
|
|
|
1896
1963
|
});
|
|
1897
1964
|
|
|
1898
1965
|
// src/infrastructure/services/csrf/csrf-token.service.ts
|
|
1899
|
-
import { Guards as
|
|
1966
|
+
import { Guards as Guards25 } from "@xeno-js/shared";
|
|
1900
1967
|
var CsrfTokenService;
|
|
1901
1968
|
var init_csrf_token_service = __esm({
|
|
1902
1969
|
"src/infrastructure/services/csrf/csrf-token.service.ts"() {
|
|
@@ -1919,7 +1986,7 @@ var init_csrf_token_service = __esm({
|
|
|
1919
1986
|
if (separatorIndex <= 0) return false;
|
|
1920
1987
|
const nonce = token.slice(0, separatorIndex);
|
|
1921
1988
|
const signature = token.slice(separatorIndex + 1);
|
|
1922
|
-
if (
|
|
1989
|
+
if (Guards25.isNullOrEmpty(nonce) || Guards25.isNullOrEmpty(signature)) return false;
|
|
1923
1990
|
const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1924
1991
|
const encoder = new TextEncoder();
|
|
1925
1992
|
const actualBuffer = encoder.encode(signature);
|
|
@@ -1940,7 +2007,7 @@ var init_csrf = __esm({
|
|
|
1940
2007
|
});
|
|
1941
2008
|
|
|
1942
2009
|
// src/infrastructure/services/extractors/extract-bearer.extractor.ts
|
|
1943
|
-
import { Guards as
|
|
2010
|
+
import { Guards as Guards26 } from "@xeno-js/shared";
|
|
1944
2011
|
var BearerTokenExtractor;
|
|
1945
2012
|
var init_extract_bearer_extractor = __esm({
|
|
1946
2013
|
"src/infrastructure/services/extractors/extract-bearer.extractor.ts"() {
|
|
@@ -1952,14 +2019,14 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1952
2019
|
_cookiePrefix;
|
|
1953
2020
|
extract(headers) {
|
|
1954
2021
|
const authHeader = headers.get("Authorization");
|
|
1955
|
-
if (
|
|
2022
|
+
if (Guards26.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1956
2023
|
return authHeader.substring(7);
|
|
1957
2024
|
}
|
|
1958
2025
|
const cookieHeader = headers.get("cookie");
|
|
1959
|
-
if (
|
|
2026
|
+
if (Guards26.isDefined(cookieHeader)) {
|
|
1960
2027
|
const regex = new RegExp(`${this._cookiePrefix}=([^;]+)`);
|
|
1961
2028
|
const match = regex.exec(cookieHeader);
|
|
1962
|
-
if (!
|
|
2029
|
+
if (!Guards26.isNullOrEmpty(match) && Guards26.isDefined(match[1])) {
|
|
1963
2030
|
return match[1].trim();
|
|
1964
2031
|
}
|
|
1965
2032
|
}
|
|
@@ -1970,7 +2037,7 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1970
2037
|
});
|
|
1971
2038
|
|
|
1972
2039
|
// src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts
|
|
1973
|
-
import { Guards as
|
|
2040
|
+
import { Guards as Guards27, StringHelper as StringHelper2 } from "@xeno-js/shared";
|
|
1974
2041
|
var SupabaseSsrTokenExtractor;
|
|
1975
2042
|
var init_extract_ssr_bearer_extractor = __esm({
|
|
1976
2043
|
"src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts"() {
|
|
@@ -1978,36 +2045,36 @@ var init_extract_ssr_bearer_extractor = __esm({
|
|
|
1978
2045
|
SupabaseSsrTokenExtractor = class {
|
|
1979
2046
|
extract(headers) {
|
|
1980
2047
|
const authHeader = headers.get("authorization");
|
|
1981
|
-
if (
|
|
2048
|
+
if (Guards27.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1982
2049
|
return authHeader.substring(7);
|
|
1983
2050
|
}
|
|
1984
2051
|
const cookieHeader = headers.get("cookie");
|
|
1985
|
-
if (
|
|
2052
|
+
if (Guards27.isNullOrEmpty(cookieHeader)) return void 0;
|
|
1986
2053
|
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
1987
2054
|
const tokenChunks = {};
|
|
1988
2055
|
let unchunkedToken;
|
|
1989
2056
|
for (const cookie of cookies) {
|
|
1990
2057
|
const [name, ...rest] = cookie.split("=");
|
|
1991
|
-
if (!
|
|
2058
|
+
if (!Guards27.isDefined(name) || Guards27.isNullOrEmpty(rest)) continue;
|
|
1992
2059
|
const value = decodeURIComponent(rest.join("="));
|
|
1993
|
-
if (
|
|
2060
|
+
if (Guards27.isDefined(/^sb-[a-z0-9]+-auth-token$/.exec(name))) {
|
|
1994
2061
|
unchunkedToken = value;
|
|
1995
2062
|
} else {
|
|
1996
2063
|
const match = /^sb-[a-z0-9]+-auth-token\.(\d+)$/.exec(name);
|
|
1997
|
-
if (
|
|
2064
|
+
if (Guards27.isDefined(match)) tokenChunks[parseInt(match[1], 10)] = value;
|
|
1998
2065
|
}
|
|
1999
2066
|
}
|
|
2000
2067
|
let fullTokenString = unchunkedToken;
|
|
2001
|
-
if (!
|
|
2068
|
+
if (!Guards27.isDefined(fullTokenString) && Object.keys(tokenChunks).length > 0) {
|
|
2002
2069
|
const indices = Object.keys(tokenChunks).map(Number).sort((a, b) => a - b);
|
|
2003
2070
|
fullTokenString = indices.map((i) => tokenChunks[i]).join("");
|
|
2004
2071
|
}
|
|
2005
|
-
if (
|
|
2072
|
+
if (Guards27.isNullOrEmpty(fullTokenString)) return void 0;
|
|
2006
2073
|
try {
|
|
2007
2074
|
const parsed = StringHelper2.safeParse(fullTokenString);
|
|
2008
|
-
if (
|
|
2075
|
+
if (Guards27.isDefined(parsed) && Guards27.isObject(parsed) && "access_token" in parsed) {
|
|
2009
2076
|
const accessToken = parsed["access_token"];
|
|
2010
|
-
if (
|
|
2077
|
+
if (Guards27.isString(accessToken)) return accessToken;
|
|
2011
2078
|
}
|
|
2012
2079
|
} catch {
|
|
2013
2080
|
return void 0;
|
|
@@ -2018,14 +2085,14 @@ var init_extract_ssr_bearer_extractor = __esm({
|
|
|
2018
2085
|
});
|
|
2019
2086
|
|
|
2020
2087
|
// src/infrastructure/services/extractors/http-cookie.extractor.ts
|
|
2021
|
-
import { Guards as
|
|
2088
|
+
import { Guards as Guards28 } from "@xeno-js/shared";
|
|
2022
2089
|
var HttpCookieExtractor;
|
|
2023
2090
|
var init_http_cookie_extractor = __esm({
|
|
2024
2091
|
"src/infrastructure/services/extractors/http-cookie.extractor.ts"() {
|
|
2025
2092
|
"use strict";
|
|
2026
2093
|
HttpCookieExtractor = class {
|
|
2027
2094
|
extract(cookie) {
|
|
2028
|
-
if (!
|
|
2095
|
+
if (!Guards28.isDefined(cookie.header)) return void 0;
|
|
2029
2096
|
for (const rawCookie of cookie.header.split(";")) {
|
|
2030
2097
|
const separatorIndex = rawCookie.indexOf("=");
|
|
2031
2098
|
if (separatorIndex <= 0) continue;
|
|
@@ -2045,7 +2112,7 @@ var init_http_cookie_extractor = __esm({
|
|
|
2045
2112
|
});
|
|
2046
2113
|
|
|
2047
2114
|
// src/infrastructure/services/extractors/http-header.extractor.ts
|
|
2048
|
-
import { Guards as
|
|
2115
|
+
import { Guards as Guards29, GuidHelper as GuidHelper4, HttpHelper, MathHelper } from "@xeno-js/shared";
|
|
2049
2116
|
var HttpHeaderExtractor;
|
|
2050
2117
|
var init_http_header_extractor = __esm({
|
|
2051
2118
|
"src/infrastructure/services/extractors/http-header.extractor.ts"() {
|
|
@@ -2113,10 +2180,10 @@ var init_http_header_extractor = __esm({
|
|
|
2113
2180
|
referer: cleanReferer,
|
|
2114
2181
|
sequence: {
|
|
2115
2182
|
sequenceId,
|
|
2116
|
-
position:
|
|
2117
|
-
size:
|
|
2183
|
+
position: Guards29.isDefined(position) ? MathHelper.toNumber(position) : void 0,
|
|
2184
|
+
size: Guards29.isDefined(size) ? MathHelper.toNumber(size) : void 0
|
|
2118
2185
|
},
|
|
2119
|
-
expiration:
|
|
2186
|
+
expiration: Guards29.isDefined(expiration) ? MathHelper.toNumber(expiration) : void 0
|
|
2120
2187
|
};
|
|
2121
2188
|
return metadata;
|
|
2122
2189
|
}
|
|
@@ -2163,7 +2230,7 @@ var init_resiliences = __esm({
|
|
|
2163
2230
|
});
|
|
2164
2231
|
|
|
2165
2232
|
// src/infrastructure/services/resolver/utils/socket.utils.ts
|
|
2166
|
-
import { Guards as
|
|
2233
|
+
import { Guards as Guards30 } from "@xeno-js/shared";
|
|
2167
2234
|
var SocketIpExtractor;
|
|
2168
2235
|
var init_socket_utils = __esm({
|
|
2169
2236
|
"src/infrastructure/services/resolver/utils/socket.utils.ts"() {
|
|
@@ -2175,7 +2242,7 @@ var init_socket_utils = __esm({
|
|
|
2175
2242
|
* @returns The IP address of the remote socket, or undefined if not available.
|
|
2176
2243
|
*/
|
|
2177
2244
|
extract(req) {
|
|
2178
|
-
if (
|
|
2245
|
+
if (Guards30.isDefined(req) && Guards30.isObject(req)) {
|
|
2179
2246
|
const candidate = req;
|
|
2180
2247
|
return candidate.socket?.remoteAddress ?? candidate.connection?.remoteAddress;
|
|
2181
2248
|
}
|
|
@@ -2194,7 +2261,7 @@ var init_utils = __esm({
|
|
|
2194
2261
|
});
|
|
2195
2262
|
|
|
2196
2263
|
// src/infrastructure/services/resolver/client-ip.resolver.ts
|
|
2197
|
-
import { Guards as
|
|
2264
|
+
import { Guards as Guards31 } from "@xeno-js/shared";
|
|
2198
2265
|
var ClientIpResolver;
|
|
2199
2266
|
var init_client_ip_resolver = __esm({
|
|
2200
2267
|
"src/infrastructure/services/resolver/client-ip.resolver.ts"() {
|
|
@@ -2207,11 +2274,11 @@ var init_client_ip_resolver = __esm({
|
|
|
2207
2274
|
_trustedProxies;
|
|
2208
2275
|
resolve(req, clientIp) {
|
|
2209
2276
|
const socketIp = SocketIpExtractor.extract(req);
|
|
2210
|
-
if (!
|
|
2211
|
-
return !
|
|
2277
|
+
if (!Guards31.isDefined(socketIp))
|
|
2278
|
+
return !Guards31.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
2212
2279
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
2213
2280
|
if (!isTrustedProxy) return socketIp;
|
|
2214
|
-
if (
|
|
2281
|
+
if (Guards31.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
2215
2282
|
return socketIp;
|
|
2216
2283
|
}
|
|
2217
2284
|
};
|
|
@@ -2233,6 +2300,7 @@ __export(services_exports, {
|
|
|
2233
2300
|
AllowOrigin: () => AllowOrigin,
|
|
2234
2301
|
BearerTokenExtractor: () => BearerTokenExtractor,
|
|
2235
2302
|
ClientIpResolver: () => ClientIpResolver,
|
|
2303
|
+
CookieHandler: () => CookieHandler,
|
|
2236
2304
|
CsrfTokenService: () => CsrfTokenService,
|
|
2237
2305
|
EdgeCryptoService: () => EdgeCryptoService,
|
|
2238
2306
|
HttpCookieExtractor: () => HttpCookieExtractor,
|
|
@@ -2247,6 +2315,7 @@ var init_services = __esm({
|
|
|
2247
2315
|
init_allow_methods();
|
|
2248
2316
|
init_allow_origins();
|
|
2249
2317
|
init_concurrency();
|
|
2318
|
+
init_cookies();
|
|
2250
2319
|
init_crypto();
|
|
2251
2320
|
init_csrf();
|
|
2252
2321
|
init_extractors();
|
|
@@ -2314,7 +2383,7 @@ var init_axios_factory = __esm({
|
|
|
2314
2383
|
});
|
|
2315
2384
|
|
|
2316
2385
|
// src/infrastructure/factories/cockatiel-resilience.factory.ts
|
|
2317
|
-
import { AppError as AppError13, Guards as
|
|
2386
|
+
import { AppError as AppError13, Guards as Guards32, RESILIENCE_DEFAULTS } from "@xeno-js/shared";
|
|
2318
2387
|
import {
|
|
2319
2388
|
bulkhead,
|
|
2320
2389
|
circuitBreaker,
|
|
@@ -2391,13 +2460,13 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2391
2460
|
return new ServiceResilience(wrap(bulkheadPolicy, circuitBreakerPolicy, retryPolicy));
|
|
2392
2461
|
}
|
|
2393
2462
|
isTransientError(error) {
|
|
2394
|
-
if (!
|
|
2463
|
+
if (!Guards32.isDefined(error) || !Guards32.isObject(error)) return false;
|
|
2395
2464
|
let status;
|
|
2396
2465
|
let isNetworkError = false;
|
|
2397
2466
|
if (error instanceof AppError13) {
|
|
2398
2467
|
status = error.status;
|
|
2399
2468
|
const cause = error.cause;
|
|
2400
|
-
if (
|
|
2469
|
+
if (Guards32.isDefined(cause) && Guards32.isString(cause.code)) {
|
|
2401
2470
|
isNetworkError = [
|
|
2402
2471
|
"ECONNABORTED",
|
|
2403
2472
|
"ECONNRESET",
|
|
@@ -2409,7 +2478,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2409
2478
|
} else {
|
|
2410
2479
|
const err = error;
|
|
2411
2480
|
status = err.status;
|
|
2412
|
-
if (
|
|
2481
|
+
if (Guards32.isString(err.code)) {
|
|
2413
2482
|
isNetworkError = [
|
|
2414
2483
|
"ECONNABORTED",
|
|
2415
2484
|
"ECONNRESET",
|
|
@@ -2420,7 +2489,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2420
2489
|
}
|
|
2421
2490
|
}
|
|
2422
2491
|
if (isNetworkError) return true;
|
|
2423
|
-
if (
|
|
2492
|
+
if (Guards32.isDefined(status)) return status === 408 || status >= 500 && status < 600;
|
|
2424
2493
|
return false;
|
|
2425
2494
|
}
|
|
2426
2495
|
isTransientAndIdempotent(error) {
|
|
@@ -2428,22 +2497,22 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
2428
2497
|
let method;
|
|
2429
2498
|
if (error instanceof AppError13) {
|
|
2430
2499
|
const cause = error.cause;
|
|
2431
|
-
if (
|
|
2500
|
+
if (Guards32.isDefined(cause) && Guards32.isDefined(cause.config) && Guards32.isString(cause.config.method)) {
|
|
2432
2501
|
method = cause.config.method.toUpperCase();
|
|
2433
2502
|
}
|
|
2434
2503
|
} else {
|
|
2435
2504
|
const err = error;
|
|
2436
|
-
if (
|
|
2505
|
+
if (Guards32.isDefined(err.config) && Guards32.isString(err.config.method)) {
|
|
2437
2506
|
method = err.config.method.toUpperCase();
|
|
2438
2507
|
}
|
|
2439
2508
|
}
|
|
2440
|
-
if (
|
|
2509
|
+
if (Guards32.isNullOrEmpty(method)) return false;
|
|
2441
2510
|
const idempotentMethods = ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
|
|
2442
2511
|
return idempotentMethods.includes(method);
|
|
2443
2512
|
}
|
|
2444
2513
|
checkConfigValue(value, defaultValue, message) {
|
|
2445
|
-
if (
|
|
2446
|
-
|
|
2514
|
+
if (Guards32.isDefined(value)) {
|
|
2515
|
+
Guards32.throwIfNegative(value, message);
|
|
2447
2516
|
return value;
|
|
2448
2517
|
}
|
|
2449
2518
|
return defaultValue;
|
|
@@ -2475,7 +2544,7 @@ var init_db_client_factory = __esm({
|
|
|
2475
2544
|
});
|
|
2476
2545
|
|
|
2477
2546
|
// src/infrastructure/context/request-context.ts
|
|
2478
|
-
import { Guards as
|
|
2547
|
+
import { Guards as Guards33 } from "@xeno-js/shared";
|
|
2479
2548
|
var NodeRequestContext;
|
|
2480
2549
|
var init_request_context = __esm({
|
|
2481
2550
|
"src/infrastructure/context/request-context.ts"() {
|
|
@@ -2507,7 +2576,7 @@ var init_request_context = __esm({
|
|
|
2507
2576
|
}
|
|
2508
2577
|
updateIdentity(identity) {
|
|
2509
2578
|
const store = this._storage.getStore();
|
|
2510
|
-
if (
|
|
2579
|
+
if (Guards33.isDefined(store) && Guards33.isDefined(store.context)) {
|
|
2511
2580
|
store.context = Object.freeze({
|
|
2512
2581
|
...store.context,
|
|
2513
2582
|
identity: Object.freeze(identity)
|
|
@@ -2516,23 +2585,23 @@ var init_request_context = __esm({
|
|
|
2516
2585
|
}
|
|
2517
2586
|
getContext() {
|
|
2518
2587
|
const store = this._storage.getStore();
|
|
2519
|
-
if (!
|
|
2588
|
+
if (!Guards33.isDefined(store)) return void 0;
|
|
2520
2589
|
const context = store.context;
|
|
2521
2590
|
return Object.freeze(context);
|
|
2522
2591
|
}
|
|
2523
2592
|
getIdentity() {
|
|
2524
2593
|
const store = this._storage.getStore();
|
|
2525
|
-
if (!
|
|
2594
|
+
if (!Guards33.isDefined(store)) return void 0;
|
|
2526
2595
|
return Object.freeze(store.context?.identity);
|
|
2527
2596
|
}
|
|
2528
2597
|
getScope() {
|
|
2529
2598
|
const store = this._storage.getStore();
|
|
2530
|
-
if (!
|
|
2599
|
+
if (!Guards33.isDefined(store)) return void 0;
|
|
2531
2600
|
return store.scope;
|
|
2532
2601
|
}
|
|
2533
2602
|
getNetworkContext() {
|
|
2534
2603
|
const store = this._storage.getStore();
|
|
2535
|
-
if (!
|
|
2604
|
+
if (!Guards33.isDefined(store)) return void 0;
|
|
2536
2605
|
return Object.freeze(store.context?.network);
|
|
2537
2606
|
}
|
|
2538
2607
|
};
|
|
@@ -2607,41 +2676,42 @@ var init_sql_light_db_client_factory = __esm({
|
|
|
2607
2676
|
// src/infrastructure/factories/supabase.factory.ts
|
|
2608
2677
|
import { createServerClient } from "@supabase/ssr";
|
|
2609
2678
|
import {
|
|
2610
|
-
Guards as
|
|
2679
|
+
Guards as Guards34,
|
|
2611
2680
|
SupabaseAuthService,
|
|
2612
2681
|
SupabaseClaimsMapper,
|
|
2613
|
-
SupabaseSessionMapper
|
|
2682
|
+
SupabaseSessionMapper,
|
|
2683
|
+
TOKENS as TOKENS3
|
|
2614
2684
|
} from "@xeno-js/shared";
|
|
2615
2685
|
var SupabaseServerAuthFactory;
|
|
2616
2686
|
var init_supabase_factory = __esm({
|
|
2617
2687
|
"src/infrastructure/factories/supabase.factory.ts"() {
|
|
2618
2688
|
"use strict";
|
|
2689
|
+
init_services();
|
|
2619
2690
|
SupabaseServerAuthFactory = class {
|
|
2620
2691
|
create({
|
|
2621
2692
|
config,
|
|
2622
2693
|
container
|
|
2623
2694
|
}) {
|
|
2624
|
-
|
|
2625
|
-
throw new Error(
|
|
2626
|
-
"ISsrCookieHandler is required for @supabase/ssr initialization., Please provide it in the config object."
|
|
2627
|
-
);
|
|
2628
|
-
}
|
|
2629
|
-
const cookieService = config.ssrOpts(container);
|
|
2695
|
+
const cookieService = this._getCookieSsr(config.ssrOpts, container, config.cookieOpts);
|
|
2630
2696
|
const client = createServerClient(config.url, config.key, {
|
|
2631
2697
|
...config.opts,
|
|
2632
|
-
cookies:
|
|
2633
|
-
getAll() {
|
|
2634
|
-
return cookieService.getAll();
|
|
2635
|
-
},
|
|
2636
|
-
setAll(cookiesToSet) {
|
|
2637
|
-
cookieService.setAll(cookiesToSet);
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2698
|
+
cookies: cookieService
|
|
2640
2699
|
});
|
|
2641
2700
|
const mapper = new SupabaseClaimsMapper();
|
|
2642
2701
|
const sessionMapper = new SupabaseSessionMapper(mapper);
|
|
2643
2702
|
return new SupabaseAuthService(client, mapper, sessionMapper, config);
|
|
2644
2703
|
}
|
|
2704
|
+
_getCookieSsr(ssrOpts, container, config) {
|
|
2705
|
+
if (Guards34.isDefined(ssrOpts)) {
|
|
2706
|
+
return ssrOpts(container);
|
|
2707
|
+
} else {
|
|
2708
|
+
return new CookieHandler(
|
|
2709
|
+
container.resolve(TOKENS3.REQUEST_CONTEXT),
|
|
2710
|
+
container.resolve(TOKENS3.CONFIGURATION_SERVICE),
|
|
2711
|
+
config
|
|
2712
|
+
);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2645
2715
|
};
|
|
2646
2716
|
}
|
|
2647
2717
|
});
|
|
@@ -2651,7 +2721,7 @@ var user_context_factory_exports = {};
|
|
|
2651
2721
|
__export(user_context_factory_exports, {
|
|
2652
2722
|
UserContextFactory: () => UserContextFactory
|
|
2653
2723
|
});
|
|
2654
|
-
import { Guards as
|
|
2724
|
+
import { Guards as Guards35 } from "@xeno-js/shared";
|
|
2655
2725
|
var UserContextFactory;
|
|
2656
2726
|
var init_user_context_factory = __esm({
|
|
2657
2727
|
"src/infrastructure/factories/user-context.factory.ts"() {
|
|
@@ -2676,7 +2746,7 @@ var init_user_context_factory = __esm({
|
|
|
2676
2746
|
tenantId: void 0
|
|
2677
2747
|
};
|
|
2678
2748
|
const identity = this._identityFactory.getIdentity();
|
|
2679
|
-
if (
|
|
2749
|
+
if (Guards35.isDefined(identity)) {
|
|
2680
2750
|
output.userId = identity.userId;
|
|
2681
2751
|
output.tenantId = identity.tenantId;
|
|
2682
2752
|
}
|
|
@@ -2762,28 +2832,28 @@ var init_auth_utils = __esm({
|
|
|
2762
2832
|
* @link https://github.com/xeno-js/xeno-js
|
|
2763
2833
|
*/
|
|
2764
2834
|
async addAuthZ(container, opts) {
|
|
2765
|
-
const { TOKENS:
|
|
2835
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2766
2836
|
const strategies = [];
|
|
2767
|
-
const { Guards:
|
|
2768
|
-
if (
|
|
2837
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
2838
|
+
if (Guards47.isDefined(opts.policies)) {
|
|
2769
2839
|
const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
2770
2840
|
const policyRegistry = opts.policies;
|
|
2771
2841
|
const registryInstance = new PolicyRegistry2();
|
|
2772
|
-
const ctxAccessor = container.resolve(
|
|
2842
|
+
const ctxAccessor = container.resolve(TOKENS5.CONTEXT_ACCESSOR);
|
|
2773
2843
|
const Policies = /* @__PURE__ */ new Set();
|
|
2774
2844
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2775
2845
|
const intentLower = intent.toLowerCase();
|
|
2776
2846
|
registryInstance.addPolicy(intentLower, policy);
|
|
2777
|
-
if (!
|
|
2847
|
+
if (!Guards47.isNullOrEmpty(policy.roles)) {
|
|
2778
2848
|
Policies.add("roles");
|
|
2779
2849
|
}
|
|
2780
|
-
if (!
|
|
2850
|
+
if (!Guards47.isNullOrEmpty(policy.permissions)) {
|
|
2781
2851
|
Policies.add("permissions");
|
|
2782
2852
|
}
|
|
2783
|
-
if (!
|
|
2853
|
+
if (!Guards47.isNullOrEmpty(policy.userId)) {
|
|
2784
2854
|
Policies.add("userId");
|
|
2785
2855
|
}
|
|
2786
|
-
if (!
|
|
2856
|
+
if (!Guards47.isNullOrEmpty(policy.tenantId)) {
|
|
2787
2857
|
Policies.add("tenantId");
|
|
2788
2858
|
}
|
|
2789
2859
|
}
|
|
@@ -2804,10 +2874,10 @@ var init_auth_utils = __esm({
|
|
|
2804
2874
|
strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
|
|
2805
2875
|
}
|
|
2806
2876
|
}
|
|
2807
|
-
if (!
|
|
2877
|
+
if (!Guards47.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2808
2878
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2809
2879
|
customStrategies.forEach((strategyToken) => {
|
|
2810
|
-
if (
|
|
2880
|
+
if (Guards47.isDefined(strategyToken)) {
|
|
2811
2881
|
strategies.push(strategyToken(container));
|
|
2812
2882
|
}
|
|
2813
2883
|
});
|
|
@@ -2827,23 +2897,23 @@ var init_auth_utils = __esm({
|
|
|
2827
2897
|
* @link https://github.com/xeno-js/xeno-js
|
|
2828
2898
|
*/
|
|
2829
2899
|
async addAuthN(container, opts) {
|
|
2830
|
-
const { Guards:
|
|
2831
|
-
if (
|
|
2900
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
2901
|
+
if (Guards47.isDefined(opts.customAuth)) {
|
|
2832
2902
|
const authService = opts.customAuth.authExtendedService();
|
|
2833
|
-
container.addScoped(
|
|
2903
|
+
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2834
2904
|
return authService;
|
|
2835
2905
|
});
|
|
2836
|
-
container.addSingleton(
|
|
2906
|
+
container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
|
|
2837
2907
|
return authService;
|
|
2838
2908
|
});
|
|
2839
2909
|
} else {
|
|
2840
2910
|
const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
2841
2911
|
const factory = new SupabaseServerAuthFactory2();
|
|
2842
2912
|
const supabase = factory.create({ config: opts, container });
|
|
2843
|
-
container.addScoped(
|
|
2913
|
+
container.addScoped(TOKENS5.AUTH_SERVICE, () => {
|
|
2844
2914
|
return supabase;
|
|
2845
2915
|
});
|
|
2846
|
-
container.addSingleton(
|
|
2916
|
+
container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
|
|
2847
2917
|
return supabase;
|
|
2848
2918
|
});
|
|
2849
2919
|
}
|
|
@@ -2939,7 +3009,7 @@ __export(unit_of_work_exports, {
|
|
|
2939
3009
|
UnitOfWork: () => UnitOfWork
|
|
2940
3010
|
});
|
|
2941
3011
|
import { AppError as AppError14 } from "@xeno-js/shared";
|
|
2942
|
-
import { Guards as
|
|
3012
|
+
import { Guards as Guards36 } from "@xeno-js/shared";
|
|
2943
3013
|
var UnitOfWork;
|
|
2944
3014
|
var init_unit_of_work = __esm({
|
|
2945
3015
|
"src/infrastructure/transaction/unit-of-work.ts"() {
|
|
@@ -2974,9 +3044,9 @@ var init_unit_of_work = __esm({
|
|
|
2974
3044
|
});
|
|
2975
3045
|
}
|
|
2976
3046
|
async dispose() {
|
|
2977
|
-
if (
|
|
3047
|
+
if (Guards36.isDefined(this._ttx.state)) {
|
|
2978
3048
|
try {
|
|
2979
|
-
if (
|
|
3049
|
+
if (Guards36.hasMethod(this._ttx.state, "rollback")) {
|
|
2980
3050
|
await this._ttx.state.rollback();
|
|
2981
3051
|
}
|
|
2982
3052
|
} finally {
|
|
@@ -2999,7 +3069,7 @@ var init_db_module = __esm({
|
|
|
2999
3069
|
"use strict";
|
|
3000
3070
|
DbModule = class {
|
|
3001
3071
|
async configure(container, opts) {
|
|
3002
|
-
const { Guards:
|
|
3072
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3003
3073
|
const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
|
|
3004
3074
|
const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
|
|
3005
3075
|
const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
|
|
@@ -3007,16 +3077,16 @@ var init_db_module = __esm({
|
|
|
3007
3077
|
return new TransactionState2();
|
|
3008
3078
|
});
|
|
3009
3079
|
const { UnitOfWork: UnitOfWork2 } = await Promise.resolve().then(() => (init_unit_of_work(), unit_of_work_exports));
|
|
3010
|
-
container.addScoped(
|
|
3080
|
+
container.addScoped(TOKENS5.UNIT_OF_WORK, (c) => {
|
|
3011
3081
|
const ttx = c.resolve("TRANSACTION_STATE");
|
|
3012
3082
|
return new UnitOfWork2(db, ttx);
|
|
3013
3083
|
});
|
|
3014
|
-
container.addScoped(
|
|
3084
|
+
container.addScoped(TOKENS5.DB_CONTEXT, (c) => {
|
|
3015
3085
|
const ttx = c.resolve("TRANSACTION_STATE");
|
|
3016
3086
|
return new Proxy(db, {
|
|
3017
3087
|
get(_target, prop, receiver) {
|
|
3018
3088
|
const activeState = ttx.state;
|
|
3019
|
-
if (
|
|
3089
|
+
if (Guards47.isDefined(activeState)) {
|
|
3020
3090
|
if (prop === "transaction") {
|
|
3021
3091
|
return activeState.transaction.bind(activeState);
|
|
3022
3092
|
}
|
|
@@ -3053,14 +3123,14 @@ var init_http_utils = __esm({
|
|
|
3053
3123
|
*/
|
|
3054
3124
|
async addAxios(container, opts) {
|
|
3055
3125
|
const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3056
|
-
const { Guards:
|
|
3057
|
-
if (!
|
|
3126
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
3127
|
+
if (!Guards47.isDefined(opts.token)) {
|
|
3058
3128
|
throw new Error("HttpConfig.token is required and must be defined.");
|
|
3059
3129
|
}
|
|
3060
3130
|
container.addSingleton(opts.token, () => {
|
|
3061
3131
|
const factory = new NodeAxiosFactory2();
|
|
3062
3132
|
const instance = factory.create(opts.client);
|
|
3063
|
-
if (!
|
|
3133
|
+
if (!Guards47.hasMethod(instance, "get") || !Guards47.hasMethod(instance, "post") || !Guards47.hasMethod(instance, "put") || !Guards47.hasMethod(instance, "patch") || !Guards47.hasMethod(instance, "delete")) {
|
|
3064
3134
|
throw new Error(
|
|
3065
3135
|
"The created HTTP client instance does not implement the required methods of IHttpClient."
|
|
3066
3136
|
);
|
|
@@ -3079,9 +3149,9 @@ var init_http_utils = __esm({
|
|
|
3079
3149
|
* @link https://github.com/xeno-js/xeno-js
|
|
3080
3150
|
*/
|
|
3081
3151
|
async addResilience(container, opts) {
|
|
3082
|
-
const { TOKENS:
|
|
3152
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3083
3153
|
const { CockatielResilienceFactory: CockatielResilienceFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3084
|
-
container.addSingleton(
|
|
3154
|
+
container.addSingleton(TOKENS5.RESILIENCE_CLIENT, () => {
|
|
3085
3155
|
const factory = new CockatielResilienceFactory2();
|
|
3086
3156
|
return factory.create(opts);
|
|
3087
3157
|
});
|
|
@@ -3130,22 +3200,22 @@ var init_validation_utils = __esm({
|
|
|
3130
3200
|
* @link https://github.com/xeno-js/xeno-js
|
|
3131
3201
|
*/
|
|
3132
3202
|
async addValidation(container, opts, logger) {
|
|
3133
|
-
const { Guards:
|
|
3134
|
-
if (!
|
|
3203
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3204
|
+
if (!Guards47.isDefined(opts.zod) && Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3135
3205
|
return;
|
|
3136
3206
|
}
|
|
3137
3207
|
const validationStrategies = [];
|
|
3138
|
-
if (
|
|
3208
|
+
if (Guards47.isDefined(opts.zod)) {
|
|
3139
3209
|
const config = opts.zod;
|
|
3140
3210
|
const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
3141
3211
|
const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3142
3212
|
const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
|
|
3143
|
-
container.addSingleton(
|
|
3213
|
+
container.addSingleton(TOKENS5.VALIDATOR_SERVICE, () => validatorService);
|
|
3144
3214
|
validationStrategies.push(new SchemaValidationStrategy2(validatorService));
|
|
3145
3215
|
}
|
|
3146
|
-
if (!
|
|
3216
|
+
if (!Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
|
|
3147
3217
|
for (const strategyToken of opts.customValidationStrategy) {
|
|
3148
|
-
if (
|
|
3218
|
+
if (Guards47.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
|
|
3149
3219
|
}
|
|
3150
3220
|
}
|
|
3151
3221
|
const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
@@ -3245,16 +3315,16 @@ var init_pipeline_utils = __esm({
|
|
|
3245
3315
|
* @link https://github.com/xeno-js/xeno-js
|
|
3246
3316
|
*/
|
|
3247
3317
|
async addCommand(container, opts) {
|
|
3248
|
-
const { Guards:
|
|
3318
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3249
3319
|
const pipelines = [];
|
|
3250
|
-
if (
|
|
3320
|
+
if (Guards47.isDefined(opts.idempotency)) {
|
|
3251
3321
|
const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
|
|
3252
3322
|
const imdStore = new IdempotencyStore2(
|
|
3253
|
-
container.resolve(
|
|
3254
|
-
container.resolve(
|
|
3323
|
+
container.resolve(TOKENS5.CACHE),
|
|
3324
|
+
container.resolve(TOKENS5.CACHE_KEY_BUILDER)
|
|
3255
3325
|
);
|
|
3256
3326
|
const { IdempotencyPipeline: IdempotencyPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3257
|
-
const requestContext = container.resolve(
|
|
3327
|
+
const requestContext = container.resolve(TOKENS5.NETWORK_CONTEXT_ACCESSOR);
|
|
3258
3328
|
const config = opts.idempotency;
|
|
3259
3329
|
pipelines.push(
|
|
3260
3330
|
new IdempotencyPipeline2(
|
|
@@ -3265,7 +3335,7 @@ var init_pipeline_utils = __esm({
|
|
|
3265
3335
|
)
|
|
3266
3336
|
);
|
|
3267
3337
|
}
|
|
3268
|
-
if (
|
|
3338
|
+
if (Guards47.isDefined(opts.concurrency)) {
|
|
3269
3339
|
const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3270
3340
|
const config = opts.concurrency;
|
|
3271
3341
|
pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
|
|
@@ -3283,12 +3353,12 @@ var init_pipeline_utils = __esm({
|
|
|
3283
3353
|
* @link https://github.com/xeno-js/xeno-js
|
|
3284
3354
|
*/
|
|
3285
3355
|
async addQuery(container) {
|
|
3286
|
-
const { TOKENS:
|
|
3356
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3287
3357
|
const { QueryCachingPipeline: QueryCachingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3288
3358
|
return new QueryCachingPipeline2(
|
|
3289
|
-
container.resolve(
|
|
3290
|
-
container.resolve(
|
|
3291
|
-
container.resolve(
|
|
3359
|
+
container.resolve(TOKENS5.CACHE),
|
|
3360
|
+
container.resolve(TOKENS5.CACHE_KEY_BUILDER),
|
|
3361
|
+
container.resolve(TOKENS5.LOGGER)
|
|
3292
3362
|
);
|
|
3293
3363
|
}
|
|
3294
3364
|
});
|
|
@@ -3306,11 +3376,11 @@ var init_cqrs_module = __esm({
|
|
|
3306
3376
|
"use strict";
|
|
3307
3377
|
CqrsModule = class {
|
|
3308
3378
|
async configure(container, opts) {
|
|
3309
|
-
const { TOKENS:
|
|
3310
|
-
const logger = container.resolve(
|
|
3379
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
3380
|
+
const logger = container.resolve(TOKENS5.LOGGER);
|
|
3311
3381
|
const { Mediator: Mediator2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3312
|
-
container.addSingleton(
|
|
3313
|
-
const serviceScopeAccessor = c.resolve(
|
|
3382
|
+
container.addSingleton(TOKENS5.MEDIATOR, (c) => {
|
|
3383
|
+
const serviceScopeAccessor = c.resolve(TOKENS5.SERVICE_SCOPE_ACCESSOR);
|
|
3314
3384
|
return new Mediator2(serviceScopeAccessor);
|
|
3315
3385
|
});
|
|
3316
3386
|
const { ExceptionPipeline: ExceptionPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
@@ -3322,24 +3392,24 @@ var init_cqrs_module = __esm({
|
|
|
3322
3392
|
new LoggingPipeline2(logger),
|
|
3323
3393
|
new PerformancePipeline2(logger, thresholdMs)
|
|
3324
3394
|
];
|
|
3325
|
-
const { Guards:
|
|
3326
|
-
if (
|
|
3395
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
3396
|
+
if (Guards47.isDefined(opts.authorization.policies) || Guards47.isDefined(opts.authorization.customAuthorizationStrategy)) {
|
|
3327
3397
|
const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
|
|
3328
3398
|
const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
|
|
3329
3399
|
pipelines.push(authPipelines);
|
|
3330
3400
|
}
|
|
3331
|
-
if (
|
|
3401
|
+
if (Guards47.isDefined(opts.validation.zod) || Guards47.isDefined(opts.validation.customValidationStrategy)) {
|
|
3332
3402
|
const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
|
|
3333
3403
|
const validationPipelines = await ValidationUtils2.addValidation(
|
|
3334
3404
|
container,
|
|
3335
3405
|
opts.validation,
|
|
3336
3406
|
logger
|
|
3337
3407
|
);
|
|
3338
|
-
if (
|
|
3408
|
+
if (Guards47.isDefined(validationPipelines)) pipelines.push(validationPipelines);
|
|
3339
3409
|
}
|
|
3340
3410
|
const commandPipelines = [...pipelines];
|
|
3341
3411
|
const queryPipelines = [...pipelines];
|
|
3342
|
-
if (
|
|
3412
|
+
if (Guards47.isDefined(opts.commandBus.idempotency) || Guards47.isDefined(opts.commandBus.concurrency)) {
|
|
3343
3413
|
const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
|
|
3344
3414
|
const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
|
|
3345
3415
|
commandPipelines.push(...newCommandPipelines);
|
|
@@ -3350,10 +3420,10 @@ var init_cqrs_module = __esm({
|
|
|
3350
3420
|
queryPipelines.push(newQueryPipelines);
|
|
3351
3421
|
}
|
|
3352
3422
|
const { CompositePipeline: CompositePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
|
|
3353
|
-
container.addSingleton(
|
|
3423
|
+
container.addSingleton(TOKENS5.COMMAND_PIPELINES_BEHAVIOR, () => {
|
|
3354
3424
|
return new CompositePipeline2(commandPipelines);
|
|
3355
3425
|
});
|
|
3356
|
-
container.addSingleton(
|
|
3426
|
+
container.addSingleton(TOKENS5.QUERY_PIPELINES_BEHAVIOR, () => {
|
|
3357
3427
|
return new CompositePipeline2(queryPipelines);
|
|
3358
3428
|
});
|
|
3359
3429
|
}
|
|
@@ -3654,7 +3724,7 @@ var init_composite_middleware = __esm({
|
|
|
3654
3724
|
});
|
|
3655
3725
|
|
|
3656
3726
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3657
|
-
import { Guards as
|
|
3727
|
+
import { Guards as Guards37 } from "@xeno-js/shared";
|
|
3658
3728
|
var CORSMiddleware;
|
|
3659
3729
|
var init_cors_middleware = __esm({
|
|
3660
3730
|
"src/presentation/middlewares/cors.middleware.ts"() {
|
|
@@ -3670,7 +3740,7 @@ var init_cors_middleware = __esm({
|
|
|
3670
3740
|
const { network } = this._requestContext.getContext() ?? {};
|
|
3671
3741
|
const origin = network?.origin;
|
|
3672
3742
|
const response = await next();
|
|
3673
|
-
if (
|
|
3743
|
+
if (Guards37.isDefined(origin))
|
|
3674
3744
|
response.headers = {
|
|
3675
3745
|
...response.headers ?? {},
|
|
3676
3746
|
"Access-Control-Allow-Origin": origin,
|
|
@@ -3687,7 +3757,7 @@ var init_cors_middleware = __esm({
|
|
|
3687
3757
|
import {
|
|
3688
3758
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES5,
|
|
3689
3759
|
ERROR_CODES as ERROR_CODES6,
|
|
3690
|
-
Guards as
|
|
3760
|
+
Guards as Guards38,
|
|
3691
3761
|
GuidHelper as GuidHelper9,
|
|
3692
3762
|
HttpHelper as HttpHelper6,
|
|
3693
3763
|
STATUS_CODES as STATUS_CODES7
|
|
@@ -3710,7 +3780,7 @@ var init_csrf_middleware = __esm({
|
|
|
3710
3780
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3711
3781
|
const headerToken = network?.csrf;
|
|
3712
3782
|
const cookieToken = network?.csrfCookie;
|
|
3713
|
-
if (!
|
|
3783
|
+
if (!Guards38.isDefined(headerToken) || !Guards38.isDefined(cookieToken)) {
|
|
3714
3784
|
return HttpHelper6.error(
|
|
3715
3785
|
{
|
|
3716
3786
|
success: false,
|
|
@@ -3752,7 +3822,7 @@ var init_csrf_middleware = __esm({
|
|
|
3752
3822
|
}
|
|
3753
3823
|
);
|
|
3754
3824
|
}
|
|
3755
|
-
if (!
|
|
3825
|
+
if (!Guards38.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3756
3826
|
return HttpHelper6.error(
|
|
3757
3827
|
{
|
|
3758
3828
|
success: false,
|
|
@@ -3781,7 +3851,7 @@ var init_csrf_middleware = __esm({
|
|
|
3781
3851
|
});
|
|
3782
3852
|
|
|
3783
3853
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3784
|
-
import { Guards as
|
|
3854
|
+
import { Guards as Guards39 } from "@xeno-js/shared";
|
|
3785
3855
|
var CsrfCookieMiddleware;
|
|
3786
3856
|
var init_csrf_cookie_middleware = __esm({
|
|
3787
3857
|
"src/presentation/middlewares/csrf-cookie.middleware.ts"() {
|
|
@@ -3800,8 +3870,8 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3800
3870
|
const context = this._requestContext.getContext();
|
|
3801
3871
|
const identity = context?.identity;
|
|
3802
3872
|
const network = context?.network;
|
|
3803
|
-
if (!
|
|
3804
|
-
if (
|
|
3873
|
+
if (!Guards39.isDefined(identity?.userId)) return response;
|
|
3874
|
+
if (Guards39.isDefined(network?.csrfCookie)) return response;
|
|
3805
3875
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3806
3876
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3807
3877
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3819,7 +3889,7 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3819
3889
|
});
|
|
3820
3890
|
|
|
3821
3891
|
// src/presentation/middlewares/options.middleware.ts
|
|
3822
|
-
import { Guards as
|
|
3892
|
+
import { Guards as Guards40, HttpHelper as HttpHelper7, STATUS_CODES as STATUS_CODES8 } from "@xeno-js/shared";
|
|
3823
3893
|
var OptionsMiddleware;
|
|
3824
3894
|
var init_options_middleware = __esm({
|
|
3825
3895
|
"src/presentation/middlewares/options.middleware.ts"() {
|
|
@@ -3840,7 +3910,7 @@ var init_options_middleware = __esm({
|
|
|
3840
3910
|
const network = this._requestContext.getNetworkContext();
|
|
3841
3911
|
const origin = network?.origin;
|
|
3842
3912
|
const headers = {};
|
|
3843
|
-
if (
|
|
3913
|
+
if (Guards40.isDefined(origin)) {
|
|
3844
3914
|
headers["Access-Control-Allow-Origin"] = origin;
|
|
3845
3915
|
headers["Access-Control-Allow-Credentials"] = this._withCredentials;
|
|
3846
3916
|
headers["Vary"] = "Origin";
|
|
@@ -3859,7 +3929,7 @@ var init_options_middleware = __esm({
|
|
|
3859
3929
|
import {
|
|
3860
3930
|
ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES6,
|
|
3861
3931
|
ERROR_CODES as ERROR_CODES7,
|
|
3862
|
-
Guards as
|
|
3932
|
+
Guards as Guards41,
|
|
3863
3933
|
GuidHelper as GuidHelper10,
|
|
3864
3934
|
HttpHelper as HttpHelper8,
|
|
3865
3935
|
STATUS_CODES as STATUS_CODES9
|
|
@@ -3884,7 +3954,7 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3884
3954
|
async execute(req, _res, next) {
|
|
3885
3955
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3886
3956
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3887
|
-
if (!
|
|
3957
|
+
if (!Guards41.isDefined(cacheKey))
|
|
3888
3958
|
return HttpHelper8.error(
|
|
3889
3959
|
{
|
|
3890
3960
|
success: false,
|
|
@@ -3936,10 +4006,10 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3936
4006
|
});
|
|
3937
4007
|
|
|
3938
4008
|
// src/presentation/mappers/context.mapper.ts
|
|
3939
|
-
import { Guards as
|
|
4009
|
+
import { Guards as Guards42 } from "@xeno-js/shared";
|
|
3940
4010
|
function _buildMessagingContext(meta) {
|
|
3941
|
-
const hasSequenceData =
|
|
3942
|
-
const hasMessagingData = hasSequenceData ||
|
|
4011
|
+
const hasSequenceData = Guards42.isDefined(meta.sequence?.sequenceId) || Guards42.isDefined(meta.sequence?.position) || Guards42.isDefined(meta.sequence?.size);
|
|
4012
|
+
const hasMessagingData = hasSequenceData || Guards42.isDefined(meta.expiration) || Guards42.isDefined(meta.returnAddress);
|
|
3943
4013
|
const messaging = hasMessagingData ? {
|
|
3944
4014
|
returnAddress: meta.returnAddress,
|
|
3945
4015
|
expiration: meta.expiration,
|
|
@@ -4123,7 +4193,7 @@ var init_presentation = __esm({
|
|
|
4123
4193
|
});
|
|
4124
4194
|
|
|
4125
4195
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
4126
|
-
import { Guards as
|
|
4196
|
+
import { Guards as Guards43 } from "@xeno-js/shared";
|
|
4127
4197
|
var RateLimitKeyBuilder;
|
|
4128
4198
|
var init_rate_limit_key_builder_cache = __esm({
|
|
4129
4199
|
"src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
|
|
@@ -4138,12 +4208,12 @@ var init_rate_limit_key_builder_cache = __esm({
|
|
|
4138
4208
|
const tenantId = ctx?.identity?.tenantId;
|
|
4139
4209
|
const userId = ctx?.identity?.userId;
|
|
4140
4210
|
const clientIp = ctx?.network?.clientIp;
|
|
4141
|
-
if (!
|
|
4211
|
+
if (!Guards43.isNullOrEmpty(tenantId) && !Guards43.isNullOrEmpty(userId))
|
|
4142
4212
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
4143
|
-
if (!
|
|
4213
|
+
if (!Guards43.isNullOrEmpty(tenantId) && !Guards43.isNullOrEmpty(clientIp))
|
|
4144
4214
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
4145
|
-
if (!
|
|
4146
|
-
if (!
|
|
4215
|
+
if (!Guards43.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
4216
|
+
if (!Guards43.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
4147
4217
|
return void 0;
|
|
4148
4218
|
}
|
|
4149
4219
|
};
|
|
@@ -4177,7 +4247,7 @@ var init_middleware_module = __esm({
|
|
|
4177
4247
|
"use strict";
|
|
4178
4248
|
MiddlewareModule = class {
|
|
4179
4249
|
async configure(container, opts) {
|
|
4180
|
-
const { Guards:
|
|
4250
|
+
const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4181
4251
|
const { HttpCookieExtractor: HttpCookieExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4182
4252
|
const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4183
4253
|
const tokenExtractor = await this._getTokenExtractor(
|
|
@@ -4186,7 +4256,7 @@ var init_middleware_module = __esm({
|
|
|
4186
4256
|
opts.customTokenExtractor
|
|
4187
4257
|
);
|
|
4188
4258
|
container.addSingleton(
|
|
4189
|
-
|
|
4259
|
+
TOKENS5.SERVICE_EXTRACTOR,
|
|
4190
4260
|
() => new HttpHeaderExtractor2(
|
|
4191
4261
|
tokenExtractor,
|
|
4192
4262
|
new HttpCookieExtractor2(),
|
|
@@ -4196,18 +4266,18 @@ var init_middleware_module = __esm({
|
|
|
4196
4266
|
);
|
|
4197
4267
|
const { ClientIpResolver: ClientIpResolver2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4198
4268
|
const middlewares = [];
|
|
4199
|
-
const requestContext = container.resolve(
|
|
4200
|
-
const logger = container.resolve(
|
|
4269
|
+
const requestContext = container.resolve(TOKENS5.REQUEST_CONTEXT);
|
|
4270
|
+
const logger = container.resolve(TOKENS5.LOGGER);
|
|
4201
4271
|
const { RequestContextMiddleware: RequestContextMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4202
4272
|
middlewares.push(
|
|
4203
4273
|
new RequestContextMiddleware2(
|
|
4204
4274
|
requestContext,
|
|
4205
|
-
container.resolve(
|
|
4275
|
+
container.resolve(TOKENS5.SERVICE_EXTRACTOR),
|
|
4206
4276
|
new ClientIpResolver2(opts.trustedProxies),
|
|
4207
4277
|
logger
|
|
4208
4278
|
)
|
|
4209
4279
|
);
|
|
4210
|
-
if (!
|
|
4280
|
+
if (!Guards47.isNullOrEmpty(opts.allowOrigins)) {
|
|
4211
4281
|
if (opts.withCredentials && opts.allowOrigins.includes("*"))
|
|
4212
4282
|
throw new Error(
|
|
4213
4283
|
"Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
|
|
@@ -4233,7 +4303,7 @@ var init_middleware_module = __esm({
|
|
|
4233
4303
|
const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4234
4304
|
middlewares.push(new CORSMiddleware2(requestContext, withCredentials));
|
|
4235
4305
|
}
|
|
4236
|
-
if (
|
|
4306
|
+
if (Guards47.isDefined(opts.routeRegistry)) {
|
|
4237
4307
|
const { MethodCheckMiddleware: MethodCheckMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4238
4308
|
middlewares.push(new MethodCheckMiddleware2(requestContext, allowMethod));
|
|
4239
4309
|
}
|
|
@@ -4255,31 +4325,31 @@ var init_middleware_module = __esm({
|
|
|
4255
4325
|
new AuthenticationMiddleware2(
|
|
4256
4326
|
requestContext,
|
|
4257
4327
|
tokenExtractor,
|
|
4258
|
-
new GateKeeper2(container.resolve(
|
|
4328
|
+
new GateKeeper2(container.resolve(TOKENS5.BASE_AUTH_SERVICE), new ClaimsIdentityMapper2()),
|
|
4259
4329
|
logger
|
|
4260
4330
|
)
|
|
4261
4331
|
);
|
|
4262
4332
|
}
|
|
4263
|
-
if (
|
|
4333
|
+
if (Guards47.isDefined(opts.rateLimite.maxRequests) || Guards47.isDefined(opts.rateLimite.windowSeconds)) {
|
|
4264
4334
|
const maxRequests = opts.rateLimite.maxRequests ?? 30;
|
|
4265
|
-
|
|
4266
|
-
|
|
4335
|
+
Guards47.throwIfNegative(maxRequests, "MaxRequests must be positive");
|
|
4336
|
+
Guards47.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
|
|
4267
4337
|
const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
|
|
4268
|
-
|
|
4269
|
-
|
|
4338
|
+
Guards47.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
|
|
4339
|
+
Guards47.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
|
|
4270
4340
|
const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
|
|
4271
4341
|
const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4272
4342
|
middlewares.push(
|
|
4273
4343
|
new RateLimitMiddleware2(
|
|
4274
4344
|
requestContext,
|
|
4275
|
-
container.resolve(
|
|
4345
|
+
container.resolve(TOKENS5.CACHE),
|
|
4276
4346
|
new RateLimitKeyBuilder2(requestContext),
|
|
4277
4347
|
logger,
|
|
4278
4348
|
{ maxRequests, windowSeconds }
|
|
4279
4349
|
)
|
|
4280
4350
|
);
|
|
4281
4351
|
}
|
|
4282
|
-
if (
|
|
4352
|
+
if (Guards47.isDefined(opts.csrf)) {
|
|
4283
4353
|
const csrf = opts.csrf;
|
|
4284
4354
|
const { EdgeCryptoService: EdgeCryptoService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4285
4355
|
container.addSingleton("CRYPTO_SERVICE", () => new EdgeCryptoService2());
|
|
@@ -4299,13 +4369,13 @@ var init_middleware_module = __esm({
|
|
|
4299
4369
|
middlewares.push(new CsrfMiddleware2(requestContext, container.resolve("CSRF_TOKEN_SERVICE")));
|
|
4300
4370
|
}
|
|
4301
4371
|
const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
|
|
4302
|
-
container.addSingleton(
|
|
4372
|
+
container.addSingleton(TOKENS5.MIDDLEWARE, () => {
|
|
4303
4373
|
return new CompositeMiddleware2(middlewares);
|
|
4304
4374
|
});
|
|
4305
4375
|
}
|
|
4306
4376
|
async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
|
|
4307
|
-
const { Guards:
|
|
4308
|
-
if (
|
|
4377
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
4378
|
+
if (Guards47.isDefined(customTokenExtractor)) return customTokenExtractor();
|
|
4309
4379
|
if (isSSR) {
|
|
4310
4380
|
const { SupabaseSsrTokenExtractor: SupabaseSsrTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
|
|
4311
4381
|
return new SupabaseSsrTokenExtractor2();
|
|
@@ -4315,8 +4385,8 @@ var init_middleware_module = __esm({
|
|
|
4315
4385
|
}
|
|
4316
4386
|
}
|
|
4317
4387
|
async _getAllowMethod(configure, opts) {
|
|
4318
|
-
const { Guards:
|
|
4319
|
-
if (!configure || !
|
|
4388
|
+
const { Guards: Guards47 } = await import("@xeno-js/shared");
|
|
4389
|
+
if (!configure || !Guards47.isDefined(opts)) return void 0;
|
|
4320
4390
|
const { AllowMethodFactory: AllowMethodFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
|
|
4321
4391
|
return new AllowMethodFactory2().create(opts);
|
|
4322
4392
|
}
|
|
@@ -4335,17 +4405,17 @@ var init_context_module = __esm({
|
|
|
4335
4405
|
"use strict";
|
|
4336
4406
|
ContextModule = class {
|
|
4337
4407
|
async configure(container) {
|
|
4338
|
-
const { TOKENS:
|
|
4408
|
+
const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
|
|
4339
4409
|
const { ServiceScopeFactory: ServiceScopeFactory2 } = await Promise.resolve().then(() => (init_service_scope_factory(), service_scope_factory_exports));
|
|
4340
4410
|
const { NodeRequestContextFactory: NodeRequestContextFactory2 } = await Promise.resolve().then(() => (init_request_context_factory(), request_context_factory_exports));
|
|
4341
4411
|
const requestContext = new NodeRequestContextFactory2(
|
|
4342
4412
|
new ServiceScopeFactory2(container)
|
|
4343
4413
|
).create();
|
|
4344
|
-
container.addSingleton(
|
|
4345
|
-
container.addSingleton(
|
|
4346
|
-
container.addSingleton(
|
|
4347
|
-
container.addSingleton(
|
|
4348
|
-
container.addSingleton(
|
|
4414
|
+
container.addSingleton(TOKENS5.REQUEST_CONTEXT, () => requestContext);
|
|
4415
|
+
container.addSingleton(TOKENS5.CONTEXT_ACCESSOR, () => requestContext);
|
|
4416
|
+
container.addSingleton(TOKENS5.IDENTITY_ACCESSOR, () => requestContext);
|
|
4417
|
+
container.addSingleton(TOKENS5.SERVICE_SCOPE_ACCESSOR, () => requestContext);
|
|
4418
|
+
container.addSingleton(TOKENS5.NETWORK_CONTEXT_ACCESSOR, () => requestContext);
|
|
4349
4419
|
const { UserContextFactory: UserContextFactory2 } = await Promise.resolve().then(() => (init_user_context_factory(), user_context_factory_exports));
|
|
4350
4420
|
container.addSingleton("USER_CONTEXT_FACTORY", () => {
|
|
4351
4421
|
return new UserContextFactory2(requestContext);
|
|
@@ -4374,7 +4444,7 @@ __export(index_exports, {
|
|
|
4374
4444
|
init_application();
|
|
4375
4445
|
|
|
4376
4446
|
// src/infrastructure/builder/app.builder.ts
|
|
4377
|
-
import { Guards as
|
|
4447
|
+
import { Guards as Guards44, LOG_LEVEL as LOG_LEVEL6, TOKENS as TOKENS4 } from "@xeno-js/shared";
|
|
4378
4448
|
|
|
4379
4449
|
// src/infrastructure/configuration/configuration.ts
|
|
4380
4450
|
import { Guards as Guards13 } from "@xeno-js/shared";
|
|
@@ -4653,13 +4723,14 @@ var AppBuilder = class {
|
|
|
4653
4723
|
constructor(container) {
|
|
4654
4724
|
this._container = container ?? new ServiceContainer();
|
|
4655
4725
|
this._container.addSingleton(
|
|
4656
|
-
|
|
4726
|
+
TOKENS4.CONFIGURATION_SERVICE,
|
|
4657
4727
|
() => new EnvironmentConfigurationService()
|
|
4658
4728
|
);
|
|
4659
|
-
this._configuration = this._container.resolve(
|
|
4729
|
+
this._configuration = this._container.resolve(TOKENS4.CONFIGURATION_SERVICE);
|
|
4660
4730
|
this._middlewareConfig.allowOrigins?.push(
|
|
4661
4731
|
this._configuration.get("APP_URL") ?? `http://localhost:${this._configuration.getNumber("PORT", 3e3)}`
|
|
4662
4732
|
);
|
|
4733
|
+
this.addContext();
|
|
4663
4734
|
}
|
|
4664
4735
|
// --- Module Configurations ---
|
|
4665
4736
|
_modules = [];
|
|
@@ -4705,7 +4776,13 @@ var AppBuilder = class {
|
|
|
4705
4776
|
redirectTo: "",
|
|
4706
4777
|
storageOpts: { type: "memory", cookieOpts: void 0, storage: void 0 },
|
|
4707
4778
|
ssrOpts: void 0,
|
|
4708
|
-
customAuth: void 0
|
|
4779
|
+
customAuth: void 0,
|
|
4780
|
+
cookieOpts: {
|
|
4781
|
+
path: "/",
|
|
4782
|
+
httpOnly: true,
|
|
4783
|
+
sameSite: "lax",
|
|
4784
|
+
secure: true
|
|
4785
|
+
}
|
|
4709
4786
|
};
|
|
4710
4787
|
_httpConfig = {
|
|
4711
4788
|
dataSourceToken: void 0,
|
|
@@ -4784,7 +4861,7 @@ var AppBuilder = class {
|
|
|
4784
4861
|
* @link https://github.com/xeno-js/xeno-js
|
|
4785
4862
|
*/
|
|
4786
4863
|
addLogger(setupAction) {
|
|
4787
|
-
if (
|
|
4864
|
+
if (Guards44.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
|
|
4788
4865
|
if (this._isLoggerModuleQueued) return this;
|
|
4789
4866
|
this._isLoggerModuleQueued = true;
|
|
4790
4867
|
this._modules.push({
|
|
@@ -4809,7 +4886,7 @@ var AppBuilder = class {
|
|
|
4809
4886
|
* @link https://github.com/xeno-js/xeno-js
|
|
4810
4887
|
*/
|
|
4811
4888
|
addCache(setupAction) {
|
|
4812
|
-
if (
|
|
4889
|
+
if (Guards44.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
4813
4890
|
if (this._isCacheModuleQueued) return this;
|
|
4814
4891
|
this._isCacheModuleQueued = true;
|
|
4815
4892
|
this._modules.push({
|
|
@@ -4912,7 +4989,7 @@ var AppBuilder = class {
|
|
|
4912
4989
|
* @link https://github.com/xeno-js/xeno-js
|
|
4913
4990
|
*/
|
|
4914
4991
|
addPipeline(setupAction) {
|
|
4915
|
-
if (
|
|
4992
|
+
if (Guards44.isDefined(setupAction)) {
|
|
4916
4993
|
setupAction(this._pipelineConfig, this._configuration);
|
|
4917
4994
|
}
|
|
4918
4995
|
this._queuePipelineModule();
|
|
@@ -5033,7 +5110,7 @@ var AppBuilder = class {
|
|
|
5033
5110
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
5034
5111
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
5035
5112
|
`);
|
|
5036
|
-
if (error instanceof Error &&
|
|
5113
|
+
if (error instanceof Error && Guards44.isDefined(error.stack)) {
|
|
5037
5114
|
console.error(error.stack);
|
|
5038
5115
|
}
|
|
5039
5116
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5190,7 +5267,7 @@ init_validation_utils();
|
|
|
5190
5267
|
|
|
5191
5268
|
// src/infrastructure/repositories/read-dao.ts
|
|
5192
5269
|
import { AppError as AppError16, Result as Result17 } from "@xeno-js/shared";
|
|
5193
|
-
import { Guards as
|
|
5270
|
+
import { Guards as Guards45 } from "@xeno-js/shared";
|
|
5194
5271
|
var ReadDao = class {
|
|
5195
5272
|
/**
|
|
5196
5273
|
* Constructs a new ReadDao instance.
|
|
@@ -5212,7 +5289,7 @@ var ReadDao = class {
|
|
|
5212
5289
|
async findById(id, ctx, signal) {
|
|
5213
5290
|
AppError16.throwIfAborted(signal, "ReadDao.findById");
|
|
5214
5291
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5215
|
-
if (
|
|
5292
|
+
if (Guards45.isNullOrEmpty(result)) return Result17.ok();
|
|
5216
5293
|
const entity = this._mapper.toEntity(result);
|
|
5217
5294
|
return Result17.ok(entity);
|
|
5218
5295
|
}
|
|
@@ -5226,7 +5303,7 @@ var ReadDao = class {
|
|
|
5226
5303
|
|
|
5227
5304
|
// src/infrastructure/repositories/repository.ts
|
|
5228
5305
|
import { AppError as AppError17, Result as Result18 } from "@xeno-js/shared";
|
|
5229
|
-
import { Guards as
|
|
5306
|
+
import { Guards as Guards46 } from "@xeno-js/shared";
|
|
5230
5307
|
var Repository = class {
|
|
5231
5308
|
/**
|
|
5232
5309
|
* Constructs a new Repository instance.
|
|
@@ -5248,7 +5325,7 @@ var Repository = class {
|
|
|
5248
5325
|
async findById(id, ctx, signal) {
|
|
5249
5326
|
AppError17.throwIfAborted(signal, "Repository.findById");
|
|
5250
5327
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5251
|
-
if (
|
|
5328
|
+
if (Guards46.isNullOrEmpty(result)) return Result18.ok();
|
|
5252
5329
|
const entity = this._mapper.toEntity(result);
|
|
5253
5330
|
return Result18.ok(entity);
|
|
5254
5331
|
}
|