@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/dist/index.js CHANGED
@@ -20,10 +20,7 @@ var __copyProps = (to, from, except, desc) => {
20
20
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
21
 
22
22
  // src/application/containers/container.utils.ts
23
- import {
24
- Guards,
25
- TOKENS
26
- } from "@xeno-js/shared";
23
+ import { Guards, TOKENS } from "@xeno-js/shared";
27
24
  var ContainerUtils;
28
25
  var init_container_utils = __esm({
29
26
  "src/application/containers/container.utils.ts"() {
@@ -59,15 +56,11 @@ var init_container_utils = __esm({
59
56
  * @throws Error If the service is not found in the container.
60
57
  * @throws Error If the service is not a scoped service.
61
58
  */
62
- async runExecute(endpoint, method, headers, transport, container, action) {
59
+ async runExecute(res, req, container, action) {
63
60
  const middleware = container.resolve(TOKENS.MIDDLEWARE);
64
- return await middleware.execute(
65
- { path: endpoint, method: method ?? "GET", transport },
66
- { ...headers },
67
- async () => {
68
- return await action();
69
- }
70
- );
61
+ return await middleware.execute(req, res, async () => {
62
+ return await action();
63
+ });
71
64
  }
72
65
  });
73
66
  }
@@ -1023,7 +1016,6 @@ var init_gate_keeper = __esm({
1023
1016
  }
1024
1017
  }
1025
1018
  return Result14.ok(guest);
1026
- return Result14.ok(guest);
1027
1019
  }
1028
1020
  };
1029
1021
  }
@@ -1508,30 +1500,30 @@ var init_logger_utils = __esm({
1508
1500
  */
1509
1501
  async addLogger(container, opts) {
1510
1502
  const loggerDependencies = [];
1511
- const { Guards: Guards46, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1512
- if (!Guards46.isDefined(opts) || opts.console) {
1503
+ const { Guards: Guards47, LOG_LEVEL: LOG_LEVEL7, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
1504
+ if (!Guards47.isDefined(opts) || opts.console) {
1513
1505
  const { ConsoleLogger: ConsoleLogger2 } = await Promise.resolve().then(() => (init_console_logger(), console_logger_exports));
1514
1506
  loggerDependencies.push(new ConsoleLogger2(opts?.level));
1515
1507
  }
1516
- if (Guards46.isDefined(opts)) {
1517
- if (Guards46.isDefined(opts.sentry.config)) {
1508
+ if (Guards47.isDefined(opts)) {
1509
+ if (Guards47.isDefined(opts.sentry.config)) {
1518
1510
  const { SentryLoggerFactory: SentryLoggerFactory2 } = await Promise.resolve().then(() => (init_sentry_logger_factory(), sentry_logger_factory_exports));
1519
1511
  loggerDependencies.push(new SentryLoggerFactory2().create(opts));
1520
1512
  }
1521
- if (Guards46.isDefined(opts.pino.config)) {
1513
+ if (Guards47.isDefined(opts.pino.config)) {
1522
1514
  const { PinoLoggerFactory: PinoLoggerFactory2 } = await Promise.resolve().then(() => (init_pino_logger_factory(), pino_logger_factory_exports));
1523
1515
  loggerDependencies.push(new PinoLoggerFactory2().create(opts));
1524
1516
  }
1525
- if (!Guards46.isNullOrEmpty(opts.customLoggers)) {
1517
+ if (!Guards47.isNullOrEmpty(opts.customLoggers)) {
1526
1518
  const customLoggers = opts.customLoggers;
1527
1519
  customLoggers.forEach((fn) => {
1528
- if (Guards46.isDefined(fn)) loggerDependencies.push(fn(container));
1520
+ if (Guards47.isDefined(fn)) loggerDependencies.push(fn(container));
1529
1521
  });
1530
1522
  }
1531
1523
  }
1532
1524
  const { BaseLogger } = await import("@xeno-js/shared");
1533
- container.addSingleton(TOKENS4.LOGGER, (c) => {
1534
- const context = c.resolve(TOKENS4.CONTEXT_ACCESSOR);
1525
+ container.addSingleton(TOKENS5.LOGGER, (c) => {
1526
+ const context = c.resolve(TOKENS5.CONTEXT_ACCESSOR);
1535
1527
  return new BaseLogger(context, opts?.level ?? LOG_LEVEL7.DEBUG, loggerDependencies);
1536
1528
  });
1537
1529
  }
@@ -1692,25 +1684,25 @@ var init_cache_utils = __esm({
1692
1684
  * @link https://github.com/xeno-js/xeno-js
1693
1685
  */
1694
1686
  async addCache(container, opts) {
1695
- const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
1696
- if (!opts.inMemory && !Guards46.isDefined(opts.redis)) {
1687
+ const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
1688
+ if (!opts.inMemory && !Guards47.isDefined(opts.redis)) {
1697
1689
  throw new Error(
1698
1690
  "No cache strategies are configured. Please provide at least one cache strategy."
1699
1691
  );
1700
1692
  }
1701
1693
  const { CacheKeyBuilder } = await import("@xeno-js/shared");
1702
1694
  container.addSingleton(
1703
- TOKENS4.CACHE_KEY_BUILDER,
1704
- (c) => new CacheKeyBuilder(c.resolve(TOKENS4.IDENTITY_ACCESSOR))
1695
+ TOKENS5.CACHE_KEY_BUILDER,
1696
+ (c) => new CacheKeyBuilder(c.resolve(TOKENS5.IDENTITY_ACCESSOR))
1705
1697
  );
1706
- if (opts.inMemory || !Guards46.isDefined(opts.redis)) {
1698
+ if (opts.inMemory || !Guards47.isDefined(opts.redis)) {
1707
1699
  const { InMemoryCacheExtended: InMemoryCacheExtended2 } = await Promise.resolve().then(() => (init_inmemory_cache(), inmemory_cache_exports));
1708
- container.addSingleton(TOKENS4.CACHE, () => new InMemoryCacheExtended2());
1700
+ container.addSingleton(TOKENS5.CACHE, () => new InMemoryCacheExtended2());
1709
1701
  return;
1710
1702
  }
1711
- if (Guards46.isDefined(opts.redis)) {
1703
+ if (Guards47.isDefined(opts.redis)) {
1712
1704
  const { RedisCacheFactory: RedisCacheFactory2 } = await Promise.resolve().then(() => (init_redis_cache_factory(), redis_cache_factory_exports));
1713
- container.addSingleton(TOKENS4.CACHE, () => {
1705
+ container.addSingleton(TOKENS5.CACHE, () => {
1714
1706
  const config = opts.redis;
1715
1707
  return new RedisCacheFactory2().create(config);
1716
1708
  });
@@ -1856,6 +1848,73 @@ var init_concurrency = __esm({
1856
1848
  }
1857
1849
  });
1858
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
+
1859
1918
  // src/infrastructure/services/crypto/crypto.service.ts
1860
1919
  var EdgeCryptoService;
1861
1920
  var init_crypto_service = __esm({
@@ -1904,7 +1963,7 @@ var init_crypto = __esm({
1904
1963
  });
1905
1964
 
1906
1965
  // src/infrastructure/services/csrf/csrf-token.service.ts
1907
- import { Guards as Guards24 } from "@xeno-js/shared";
1966
+ import { Guards as Guards25 } from "@xeno-js/shared";
1908
1967
  var CsrfTokenService;
1909
1968
  var init_csrf_token_service = __esm({
1910
1969
  "src/infrastructure/services/csrf/csrf-token.service.ts"() {
@@ -1927,7 +1986,7 @@ var init_csrf_token_service = __esm({
1927
1986
  if (separatorIndex <= 0) return false;
1928
1987
  const nonce = token.slice(0, separatorIndex);
1929
1988
  const signature = token.slice(separatorIndex + 1);
1930
- if (Guards24.isNullOrEmpty(nonce) || Guards24.isNullOrEmpty(signature)) return false;
1989
+ if (Guards25.isNullOrEmpty(nonce) || Guards25.isNullOrEmpty(signature)) return false;
1931
1990
  const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
1932
1991
  const encoder = new TextEncoder();
1933
1992
  const actualBuffer = encoder.encode(signature);
@@ -1948,24 +2007,26 @@ var init_csrf = __esm({
1948
2007
  });
1949
2008
 
1950
2009
  // src/infrastructure/services/extractors/extract-bearer.extractor.ts
1951
- import { Guards as Guards25, StringHelper as StringHelper2 } from "@xeno-js/shared";
2010
+ import { Guards as Guards26 } from "@xeno-js/shared";
1952
2011
  var BearerTokenExtractor;
1953
2012
  var init_extract_bearer_extractor = __esm({
1954
2013
  "src/infrastructure/services/extractors/extract-bearer.extractor.ts"() {
1955
2014
  "use strict";
1956
2015
  BearerTokenExtractor = class {
2016
+ constructor(_cookiePrefix) {
2017
+ this._cookiePrefix = _cookiePrefix;
2018
+ }
2019
+ _cookiePrefix;
1957
2020
  extract(headers) {
1958
- const authHeader = StringHelper2.getSingleValue(headers["authorization"]);
1959
- if (!Guards25.isDefined(authHeader)) {
1960
- return void 0;
1961
- }
1962
- if (authHeader.toLowerCase().startsWith("bearer ")) {
2021
+ const authHeader = headers.get("Authorization");
2022
+ if (Guards26.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
1963
2023
  return authHeader.substring(7);
1964
2024
  }
1965
- const cookieHeader = StringHelper2.getSingleValue(headers["cookie"]);
1966
- if (Guards25.isDefined(cookieHeader)) {
1967
- const match = /sb-access-token=([^;]+)/.exec(cookieHeader);
1968
- if (!Guards25.isNullOrEmpty(match) && Guards25.isDefined(match[1])) {
2025
+ const cookieHeader = headers.get("cookie");
2026
+ if (Guards26.isDefined(cookieHeader)) {
2027
+ const regex = new RegExp(`${this._cookiePrefix}=([^;]+)`);
2028
+ const match = regex.exec(cookieHeader);
2029
+ if (!Guards26.isNullOrEmpty(match) && Guards26.isDefined(match[1])) {
1969
2030
  return match[1].trim();
1970
2031
  }
1971
2032
  }
@@ -1976,47 +2037,44 @@ var init_extract_bearer_extractor = __esm({
1976
2037
  });
1977
2038
 
1978
2039
  // src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts
1979
- import {
1980
- Guards as Guards26,
1981
- StringHelper as StringHelper3
1982
- } from "@xeno-js/shared";
2040
+ import { Guards as Guards27, StringHelper as StringHelper2 } from "@xeno-js/shared";
1983
2041
  var SupabaseSsrTokenExtractor;
1984
2042
  var init_extract_ssr_bearer_extractor = __esm({
1985
2043
  "src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts"() {
1986
2044
  "use strict";
1987
2045
  SupabaseSsrTokenExtractor = class {
1988
2046
  extract(headers) {
1989
- const authHeader = StringHelper3.getSingleValue(headers["authorization"]);
1990
- if (Guards26.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
2047
+ const authHeader = headers.get("authorization");
2048
+ if (Guards27.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
1991
2049
  return authHeader.substring(7);
1992
2050
  }
1993
- const cookieHeader = StringHelper3.getSingleValue(headers["cookie"]);
1994
- if (Guards26.isNullOrEmpty(cookieHeader)) return void 0;
2051
+ const cookieHeader = headers.get("cookie");
2052
+ if (Guards27.isNullOrEmpty(cookieHeader)) return void 0;
1995
2053
  const cookies = cookieHeader.split(";").map((c) => c.trim());
1996
2054
  const tokenChunks = {};
1997
2055
  let unchunkedToken;
1998
2056
  for (const cookie of cookies) {
1999
2057
  const [name, ...rest] = cookie.split("=");
2000
- if (!Guards26.isDefined(name) || Guards26.isNullOrEmpty(rest)) continue;
2058
+ if (!Guards27.isDefined(name) || Guards27.isNullOrEmpty(rest)) continue;
2001
2059
  const value = decodeURIComponent(rest.join("="));
2002
- if (Guards26.isDefined(/^sb-[a-z0-9]+-auth-token$/.exec(name))) {
2060
+ if (Guards27.isDefined(/^sb-[a-z0-9]+-auth-token$/.exec(name))) {
2003
2061
  unchunkedToken = value;
2004
2062
  } else {
2005
2063
  const match = /^sb-[a-z0-9]+-auth-token\.(\d+)$/.exec(name);
2006
- if (Guards26.isDefined(match)) tokenChunks[parseInt(match[1], 10)] = value;
2064
+ if (Guards27.isDefined(match)) tokenChunks[parseInt(match[1], 10)] = value;
2007
2065
  }
2008
2066
  }
2009
2067
  let fullTokenString = unchunkedToken;
2010
- if (!Guards26.isDefined(fullTokenString) && Object.keys(tokenChunks).length > 0) {
2068
+ if (!Guards27.isDefined(fullTokenString) && Object.keys(tokenChunks).length > 0) {
2011
2069
  const indices = Object.keys(tokenChunks).map(Number).sort((a, b) => a - b);
2012
2070
  fullTokenString = indices.map((i) => tokenChunks[i]).join("");
2013
2071
  }
2014
- if (Guards26.isNullOrEmpty(fullTokenString)) return void 0;
2072
+ if (Guards27.isNullOrEmpty(fullTokenString)) return void 0;
2015
2073
  try {
2016
- const parsed = StringHelper3.safeParse(fullTokenString);
2017
- if (Guards26.isDefined(parsed) && Guards26.isObject(parsed) && "access_token" in parsed) {
2074
+ const parsed = StringHelper2.safeParse(fullTokenString);
2075
+ if (Guards27.isDefined(parsed) && Guards27.isObject(parsed) && "access_token" in parsed) {
2018
2076
  const accessToken = parsed["access_token"];
2019
- if (Guards26.isString(accessToken)) return accessToken;
2077
+ if (Guards27.isString(accessToken)) return accessToken;
2020
2078
  }
2021
2079
  } catch {
2022
2080
  return void 0;
@@ -2027,14 +2085,14 @@ var init_extract_ssr_bearer_extractor = __esm({
2027
2085
  });
2028
2086
 
2029
2087
  // src/infrastructure/services/extractors/http-cookie.extractor.ts
2030
- import { Guards as Guards27 } from "@xeno-js/shared";
2088
+ import { Guards as Guards28 } from "@xeno-js/shared";
2031
2089
  var HttpCookieExtractor;
2032
2090
  var init_http_cookie_extractor = __esm({
2033
2091
  "src/infrastructure/services/extractors/http-cookie.extractor.ts"() {
2034
2092
  "use strict";
2035
2093
  HttpCookieExtractor = class {
2036
2094
  extract(cookie) {
2037
- if (!Guards27.isDefined(cookie.header)) return void 0;
2095
+ if (!Guards28.isDefined(cookie.header)) return void 0;
2038
2096
  for (const rawCookie of cookie.header.split(";")) {
2039
2097
  const separatorIndex = rawCookie.indexOf("=");
2040
2098
  if (separatorIndex <= 0) continue;
@@ -2054,13 +2112,7 @@ var init_http_cookie_extractor = __esm({
2054
2112
  });
2055
2113
 
2056
2114
  // src/infrastructure/services/extractors/http-header.extractor.ts
2057
- import {
2058
- Guards as Guards28,
2059
- GuidHelper as GuidHelper4,
2060
- HttpHelper,
2061
- MathHelper,
2062
- StringHelper as StringHelper4
2063
- } from "@xeno-js/shared";
2115
+ import { Guards as Guards29, GuidHelper as GuidHelper4, HttpHelper, MathHelper } from "@xeno-js/shared";
2064
2116
  var HttpHeaderExtractor;
2065
2117
  var init_http_header_extractor = __esm({
2066
2118
  "src/infrastructure/services/extractors/http-header.extractor.ts"() {
@@ -2086,29 +2138,29 @@ var init_http_header_extractor = __esm({
2086
2138
  _trustedIp;
2087
2139
  _cookieName;
2088
2140
  extract(headers) {
2089
- const correlationId = GuidHelper4.parse(StringHelper4.getSingleValue(headers["x-correlation-id"]));
2090
- const requestId = GuidHelper4.parse(StringHelper4.getSingleValue(headers["x-request-id"]));
2141
+ const correlationId = GuidHelper4.parse(headers.get("x-correlation-id") ?? void 0);
2142
+ const requestId = GuidHelper4.parse(headers.get("x-request-id") ?? void 0);
2091
2143
  const token = this._bearerExtractor.extract(headers);
2092
- const clientIp = StringHelper4.getSingleValue(headers[this._trustedIp?.toLowerCase() ?? "x-forwarded-for"]) ?? StringHelper4.getSingleValue(headers["x-real-ip"]);
2093
- const spanId = GuidHelper4.parse(StringHelper4.getSingleValue(headers["x-span-id"]));
2094
- const parentSpanId = StringHelper4.getSingleValue(headers["x-parent-span-id"]);
2095
- const acceptHeader = StringHelper4.getSingleValue(headers["accept"]);
2096
- const contentTypeHeader = StringHelper4.getSingleValue(headers["content-type"]);
2097
- const userAgent = StringHelper4.getSingleValue(headers["user-agent"]);
2098
- const returnAddress = StringHelper4.getSingleValue(headers["x-return-address"]);
2099
- const sequenceId = StringHelper4.getSingleValue(headers["x-sequence-id"]);
2100
- const position = StringHelper4.getSingleValue(headers["x-sequence-position"]);
2101
- const size = StringHelper4.getSingleValue(headers["x-sequence-size"]);
2102
- const expiration = StringHelper4.getSingleValue(headers["x-expiration"]);
2103
- const csrf = StringHelper4.getSingleValue(headers["x-csrf-token"]);
2104
- const cookieHeader = StringHelper4.getSingleValue(headers["cookie"]);
2144
+ const clientIp = headers.get(this._trustedIp?.toLowerCase() ?? "x-forwarded-for") ?? headers.get("x-real-ip") ?? void 0;
2145
+ const spanId = GuidHelper4.parse(headers.get("x-span-id") ?? void 0);
2146
+ const parentSpanId = headers.get("x-parent-span-id") ?? void 0;
2147
+ const acceptHeader = headers.get("accept");
2148
+ const contentTypeHeader = headers.get("content-type");
2149
+ const userAgent = headers.get("user-agent") ?? void 0;
2150
+ const returnAddress = headers.get("x-return-address") ?? void 0;
2151
+ const sequenceId = headers.get("x-sequence-id") ?? void 0;
2152
+ const position = headers.get("x-sequence-position");
2153
+ const size = headers.get("x-sequence-size");
2154
+ const expiration = headers.get("x-expiration");
2155
+ const csrf = headers.get("x-csrf-token") ?? void 0;
2156
+ const cookieHeader = headers.get("cookie") ?? void 0;
2105
2157
  const csrfCookie = this._cookieExtractor.extract({
2106
2158
  header: cookieHeader,
2107
2159
  name: this._cookieName
2108
2160
  });
2109
- const origin = StringHelper4.getSingleValue(headers["origin"]);
2161
+ const origin = headers.get("origin") ?? void 0;
2110
2162
  const cleanOrigin = HttpHelper.sanitizeOriginUrl(origin);
2111
- const referer = StringHelper4.getSingleValue(headers["referer"]);
2163
+ const referer = headers.get("referer") ?? void 0;
2112
2164
  const cleanReferer = HttpHelper.sanitizeOriginUrl(referer);
2113
2165
  const accept = acceptHeader === "*/*" ? void 0 : acceptHeader;
2114
2166
  const formatIndicator = accept ?? contentTypeHeader ?? "application/json";
@@ -2128,10 +2180,10 @@ var init_http_header_extractor = __esm({
2128
2180
  referer: cleanReferer,
2129
2181
  sequence: {
2130
2182
  sequenceId,
2131
- position: Guards28.isDefined(position) ? MathHelper.toNumber(position) : void 0,
2132
- size: Guards28.isDefined(size) ? MathHelper.toNumber(size) : void 0
2183
+ position: Guards29.isDefined(position) ? MathHelper.toNumber(position) : void 0,
2184
+ size: Guards29.isDefined(size) ? MathHelper.toNumber(size) : void 0
2133
2185
  },
2134
- expiration: Guards28.isDefined(expiration) ? MathHelper.toNumber(expiration) : void 0
2186
+ expiration: Guards29.isDefined(expiration) ? MathHelper.toNumber(expiration) : void 0
2135
2187
  };
2136
2188
  return metadata;
2137
2189
  }
@@ -2178,7 +2230,7 @@ var init_resiliences = __esm({
2178
2230
  });
2179
2231
 
2180
2232
  // src/infrastructure/services/resolver/utils/socket.utils.ts
2181
- import { Guards as Guards29 } from "@xeno-js/shared";
2233
+ import { Guards as Guards30 } from "@xeno-js/shared";
2182
2234
  var SocketIpExtractor;
2183
2235
  var init_socket_utils = __esm({
2184
2236
  "src/infrastructure/services/resolver/utils/socket.utils.ts"() {
@@ -2190,7 +2242,7 @@ var init_socket_utils = __esm({
2190
2242
  * @returns The IP address of the remote socket, or undefined if not available.
2191
2243
  */
2192
2244
  extract(req) {
2193
- if (Guards29.isDefined(req) && Guards29.isObject(req)) {
2245
+ if (Guards30.isDefined(req) && Guards30.isObject(req)) {
2194
2246
  const candidate = req;
2195
2247
  return candidate.socket?.remoteAddress ?? candidate.connection?.remoteAddress;
2196
2248
  }
@@ -2209,7 +2261,7 @@ var init_utils = __esm({
2209
2261
  });
2210
2262
 
2211
2263
  // src/infrastructure/services/resolver/client-ip.resolver.ts
2212
- import { Guards as Guards30 } from "@xeno-js/shared";
2264
+ import { Guards as Guards31 } from "@xeno-js/shared";
2213
2265
  var ClientIpResolver;
2214
2266
  var init_client_ip_resolver = __esm({
2215
2267
  "src/infrastructure/services/resolver/client-ip.resolver.ts"() {
@@ -2222,11 +2274,11 @@ var init_client_ip_resolver = __esm({
2222
2274
  _trustedProxies;
2223
2275
  resolve(req, clientIp) {
2224
2276
  const socketIp = SocketIpExtractor.extract(req);
2225
- if (!Guards30.isDefined(socketIp))
2226
- return !Guards30.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
2277
+ if (!Guards31.isDefined(socketIp))
2278
+ return !Guards31.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
2227
2279
  const isTrustedProxy = this._trustedProxies.includes(socketIp);
2228
2280
  if (!isTrustedProxy) return socketIp;
2229
- if (Guards30.isDefined(clientIp)) return clientIp.split(",")[0].trim();
2281
+ if (Guards31.isDefined(clientIp)) return clientIp.split(",")[0].trim();
2230
2282
  return socketIp;
2231
2283
  }
2232
2284
  };
@@ -2248,6 +2300,7 @@ __export(services_exports, {
2248
2300
  AllowOrigin: () => AllowOrigin,
2249
2301
  BearerTokenExtractor: () => BearerTokenExtractor,
2250
2302
  ClientIpResolver: () => ClientIpResolver,
2303
+ CookieHandler: () => CookieHandler,
2251
2304
  CsrfTokenService: () => CsrfTokenService,
2252
2305
  EdgeCryptoService: () => EdgeCryptoService,
2253
2306
  HttpCookieExtractor: () => HttpCookieExtractor,
@@ -2262,6 +2315,7 @@ var init_services = __esm({
2262
2315
  init_allow_methods();
2263
2316
  init_allow_origins();
2264
2317
  init_concurrency();
2318
+ init_cookies();
2265
2319
  init_crypto();
2266
2320
  init_csrf();
2267
2321
  init_extractors();
@@ -2291,13 +2345,13 @@ var init_allow_method_factory = __esm({
2291
2345
  // src/infrastructure/factories/axios.factory.ts
2292
2346
  import http from "http";
2293
2347
  import https from "https";
2294
- import { AxiosFactory, AxiosHttpClient } from "@xeno-js/shared";
2348
+ import { AxiosHttpClient } from "@xeno-js/shared";
2295
2349
  import axios from "axios";
2296
2350
  var NodeAxiosFactory;
2297
2351
  var init_axios_factory = __esm({
2298
2352
  "src/infrastructure/factories/axios.factory.ts"() {
2299
2353
  "use strict";
2300
- NodeAxiosFactory = class extends AxiosFactory {
2354
+ NodeAxiosFactory = class {
2301
2355
  create(config) {
2302
2356
  const isKeepAlive = config.keepAlive ?? true;
2303
2357
  const maxSockets = config.maxSockets ?? 100;
@@ -2329,7 +2383,7 @@ var init_axios_factory = __esm({
2329
2383
  });
2330
2384
 
2331
2385
  // src/infrastructure/factories/cockatiel-resilience.factory.ts
2332
- import { AppError as AppError13, Guards as Guards31, RESILIENCE_DEFAULTS } from "@xeno-js/shared";
2386
+ import { AppError as AppError13, Guards as Guards32, RESILIENCE_DEFAULTS } from "@xeno-js/shared";
2333
2387
  import {
2334
2388
  bulkhead,
2335
2389
  circuitBreaker,
@@ -2406,13 +2460,13 @@ var init_cockatiel_resilience_factory = __esm({
2406
2460
  return new ServiceResilience(wrap(bulkheadPolicy, circuitBreakerPolicy, retryPolicy));
2407
2461
  }
2408
2462
  isTransientError(error) {
2409
- if (!Guards31.isDefined(error) || !Guards31.isObject(error)) return false;
2463
+ if (!Guards32.isDefined(error) || !Guards32.isObject(error)) return false;
2410
2464
  let status;
2411
2465
  let isNetworkError = false;
2412
2466
  if (error instanceof AppError13) {
2413
2467
  status = error.status;
2414
2468
  const cause = error.cause;
2415
- if (Guards31.isDefined(cause) && Guards31.isString(cause.code)) {
2469
+ if (Guards32.isDefined(cause) && Guards32.isString(cause.code)) {
2416
2470
  isNetworkError = [
2417
2471
  "ECONNABORTED",
2418
2472
  "ECONNRESET",
@@ -2424,7 +2478,7 @@ var init_cockatiel_resilience_factory = __esm({
2424
2478
  } else {
2425
2479
  const err = error;
2426
2480
  status = err.status;
2427
- if (Guards31.isString(err.code)) {
2481
+ if (Guards32.isString(err.code)) {
2428
2482
  isNetworkError = [
2429
2483
  "ECONNABORTED",
2430
2484
  "ECONNRESET",
@@ -2435,7 +2489,7 @@ var init_cockatiel_resilience_factory = __esm({
2435
2489
  }
2436
2490
  }
2437
2491
  if (isNetworkError) return true;
2438
- if (Guards31.isDefined(status)) return status === 408 || status >= 500 && status < 600;
2492
+ if (Guards32.isDefined(status)) return status === 408 || status >= 500 && status < 600;
2439
2493
  return false;
2440
2494
  }
2441
2495
  isTransientAndIdempotent(error) {
@@ -2443,22 +2497,22 @@ var init_cockatiel_resilience_factory = __esm({
2443
2497
  let method;
2444
2498
  if (error instanceof AppError13) {
2445
2499
  const cause = error.cause;
2446
- if (Guards31.isDefined(cause) && Guards31.isDefined(cause.config) && Guards31.isString(cause.config.method)) {
2500
+ if (Guards32.isDefined(cause) && Guards32.isDefined(cause.config) && Guards32.isString(cause.config.method)) {
2447
2501
  method = cause.config.method.toUpperCase();
2448
2502
  }
2449
2503
  } else {
2450
2504
  const err = error;
2451
- if (Guards31.isDefined(err.config) && Guards31.isString(err.config.method)) {
2505
+ if (Guards32.isDefined(err.config) && Guards32.isString(err.config.method)) {
2452
2506
  method = err.config.method.toUpperCase();
2453
2507
  }
2454
2508
  }
2455
- if (Guards31.isNullOrEmpty(method)) return false;
2509
+ if (Guards32.isNullOrEmpty(method)) return false;
2456
2510
  const idempotentMethods = ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
2457
2511
  return idempotentMethods.includes(method);
2458
2512
  }
2459
2513
  checkConfigValue(value, defaultValue, message) {
2460
- if (Guards31.isDefined(value)) {
2461
- Guards31.throwIfNegative(value, message);
2514
+ if (Guards32.isDefined(value)) {
2515
+ Guards32.throwIfNegative(value, message);
2462
2516
  return value;
2463
2517
  }
2464
2518
  return defaultValue;
@@ -2490,7 +2544,7 @@ var init_db_client_factory = __esm({
2490
2544
  });
2491
2545
 
2492
2546
  // src/infrastructure/context/request-context.ts
2493
- import { Guards as Guards32 } from "@xeno-js/shared";
2547
+ import { Guards as Guards33 } from "@xeno-js/shared";
2494
2548
  var NodeRequestContext;
2495
2549
  var init_request_context = __esm({
2496
2550
  "src/infrastructure/context/request-context.ts"() {
@@ -2522,7 +2576,7 @@ var init_request_context = __esm({
2522
2576
  }
2523
2577
  updateIdentity(identity) {
2524
2578
  const store = this._storage.getStore();
2525
- if (Guards32.isDefined(store) && Guards32.isDefined(store.context)) {
2579
+ if (Guards33.isDefined(store) && Guards33.isDefined(store.context)) {
2526
2580
  store.context = Object.freeze({
2527
2581
  ...store.context,
2528
2582
  identity: Object.freeze(identity)
@@ -2531,23 +2585,23 @@ var init_request_context = __esm({
2531
2585
  }
2532
2586
  getContext() {
2533
2587
  const store = this._storage.getStore();
2534
- if (!Guards32.isDefined(store)) return void 0;
2588
+ if (!Guards33.isDefined(store)) return void 0;
2535
2589
  const context = store.context;
2536
2590
  return Object.freeze(context);
2537
2591
  }
2538
2592
  getIdentity() {
2539
2593
  const store = this._storage.getStore();
2540
- if (!Guards32.isDefined(store)) return void 0;
2594
+ if (!Guards33.isDefined(store)) return void 0;
2541
2595
  return Object.freeze(store.context?.identity);
2542
2596
  }
2543
2597
  getScope() {
2544
2598
  const store = this._storage.getStore();
2545
- if (!Guards32.isDefined(store)) return void 0;
2599
+ if (!Guards33.isDefined(store)) return void 0;
2546
2600
  return store.scope;
2547
2601
  }
2548
2602
  getNetworkContext() {
2549
2603
  const store = this._storage.getStore();
2550
- if (!Guards32.isDefined(store)) return void 0;
2604
+ if (!Guards33.isDefined(store)) return void 0;
2551
2605
  return Object.freeze(store.context?.network);
2552
2606
  }
2553
2607
  };
@@ -2622,41 +2676,42 @@ var init_sql_light_db_client_factory = __esm({
2622
2676
  // src/infrastructure/factories/supabase.factory.ts
2623
2677
  import { createServerClient } from "@supabase/ssr";
2624
2678
  import {
2625
- Guards as Guards33,
2679
+ Guards as Guards34,
2626
2680
  SupabaseAuthService,
2627
2681
  SupabaseClaimsMapper,
2628
- SupabaseSessionMapper
2682
+ SupabaseSessionMapper,
2683
+ TOKENS as TOKENS3
2629
2684
  } from "@xeno-js/shared";
2630
2685
  var SupabaseServerAuthFactory;
2631
2686
  var init_supabase_factory = __esm({
2632
2687
  "src/infrastructure/factories/supabase.factory.ts"() {
2633
2688
  "use strict";
2689
+ init_services();
2634
2690
  SupabaseServerAuthFactory = class {
2635
2691
  create({
2636
2692
  config,
2637
2693
  container
2638
2694
  }) {
2639
- if (!Guards33.isDefined(config.ssrOpts)) {
2640
- throw new Error(
2641
- "ISsrCookieHandler is required for @supabase/ssr initialization., Please provide it in the config object."
2642
- );
2643
- }
2644
- const cookieService = config.ssrOpts(container);
2695
+ const cookieService = this._getCookieSsr(config.ssrOpts, container, config.cookieOpts);
2645
2696
  const client = createServerClient(config.url, config.key, {
2646
2697
  ...config.opts,
2647
- cookies: {
2648
- getAll() {
2649
- return cookieService.getAll();
2650
- },
2651
- setAll(cookiesToSet) {
2652
- cookieService.setAll(cookiesToSet);
2653
- }
2654
- }
2698
+ cookies: cookieService
2655
2699
  });
2656
2700
  const mapper = new SupabaseClaimsMapper();
2657
2701
  const sessionMapper = new SupabaseSessionMapper(mapper);
2658
2702
  return new SupabaseAuthService(client, mapper, sessionMapper, config);
2659
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
+ }
2660
2715
  };
2661
2716
  }
2662
2717
  });
@@ -2666,7 +2721,7 @@ var user_context_factory_exports = {};
2666
2721
  __export(user_context_factory_exports, {
2667
2722
  UserContextFactory: () => UserContextFactory
2668
2723
  });
2669
- import { Guards as Guards34 } from "@xeno-js/shared";
2724
+ import { Guards as Guards35 } from "@xeno-js/shared";
2670
2725
  var UserContextFactory;
2671
2726
  var init_user_context_factory = __esm({
2672
2727
  "src/infrastructure/factories/user-context.factory.ts"() {
@@ -2691,7 +2746,7 @@ var init_user_context_factory = __esm({
2691
2746
  tenantId: void 0
2692
2747
  };
2693
2748
  const identity = this._identityFactory.getIdentity();
2694
- if (Guards34.isDefined(identity)) {
2749
+ if (Guards35.isDefined(identity)) {
2695
2750
  output.userId = identity.userId;
2696
2751
  output.tenantId = identity.tenantId;
2697
2752
  }
@@ -2777,28 +2832,28 @@ var init_auth_utils = __esm({
2777
2832
  * @link https://github.com/xeno-js/xeno-js
2778
2833
  */
2779
2834
  async addAuthZ(container, opts) {
2780
- const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
2835
+ const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
2781
2836
  const strategies = [];
2782
- const { Guards: Guards46 } = await import("@xeno-js/shared");
2783
- if (Guards46.isDefined(opts.policies)) {
2837
+ const { Guards: Guards47 } = await import("@xeno-js/shared");
2838
+ if (Guards47.isDefined(opts.policies)) {
2784
2839
  const { PolicyRegistry: PolicyRegistry2 } = await Promise.resolve().then(() => (init_application(), application_exports));
2785
2840
  const policyRegistry = opts.policies;
2786
2841
  const registryInstance = new PolicyRegistry2();
2787
- const ctxAccessor = container.resolve(TOKENS4.CONTEXT_ACCESSOR);
2842
+ const ctxAccessor = container.resolve(TOKENS5.CONTEXT_ACCESSOR);
2788
2843
  const Policies = /* @__PURE__ */ new Set();
2789
2844
  for (const [intent, policy] of Object.entries(policyRegistry)) {
2790
2845
  const intentLower = intent.toLowerCase();
2791
2846
  registryInstance.addPolicy(intentLower, policy);
2792
- if (!Guards46.isNullOrEmpty(policy.roles)) {
2847
+ if (!Guards47.isNullOrEmpty(policy.roles)) {
2793
2848
  Policies.add("roles");
2794
2849
  }
2795
- if (!Guards46.isNullOrEmpty(policy.permissions)) {
2850
+ if (!Guards47.isNullOrEmpty(policy.permissions)) {
2796
2851
  Policies.add("permissions");
2797
2852
  }
2798
- if (!Guards46.isNullOrEmpty(policy.userId)) {
2853
+ if (!Guards47.isNullOrEmpty(policy.userId)) {
2799
2854
  Policies.add("userId");
2800
2855
  }
2801
- if (!Guards46.isNullOrEmpty(policy.tenantId)) {
2856
+ if (!Guards47.isNullOrEmpty(policy.tenantId)) {
2802
2857
  Policies.add("tenantId");
2803
2858
  }
2804
2859
  }
@@ -2819,10 +2874,10 @@ var init_auth_utils = __esm({
2819
2874
  strategies.push(new TenantAuthorizationStrategy2(registryInstance, ctxAccessor));
2820
2875
  }
2821
2876
  }
2822
- if (!Guards46.isNullOrEmpty(opts.customAuthorizationStrategy)) {
2877
+ if (!Guards47.isNullOrEmpty(opts.customAuthorizationStrategy)) {
2823
2878
  const customStrategies = opts.customAuthorizationStrategy;
2824
2879
  customStrategies.forEach((strategyToken) => {
2825
- if (Guards46.isDefined(strategyToken)) {
2880
+ if (Guards47.isDefined(strategyToken)) {
2826
2881
  strategies.push(strategyToken(container));
2827
2882
  }
2828
2883
  });
@@ -2842,17 +2897,26 @@ var init_auth_utils = __esm({
2842
2897
  * @link https://github.com/xeno-js/xeno-js
2843
2898
  */
2844
2899
  async addAuthN(container, opts) {
2845
- const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
2846
- const _t = opts;
2847
- const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
2848
- const factory = new SupabaseServerAuthFactory2();
2849
- const supabase = factory.create({ config: opts, container });
2850
- container.addScoped(TOKENS4.AUTH_SERVICE, () => {
2851
- return supabase;
2852
- });
2853
- container.addSingleton(TOKENS4.BASE_AUTH_SERVICE, () => {
2854
- return supabase;
2855
- });
2900
+ const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
2901
+ if (Guards47.isDefined(opts.customAuth)) {
2902
+ const authService = opts.customAuth.authExtendedService();
2903
+ container.addScoped(TOKENS5.AUTH_SERVICE, () => {
2904
+ return authService;
2905
+ });
2906
+ container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
2907
+ return authService;
2908
+ });
2909
+ } else {
2910
+ const { SupabaseServerAuthFactory: SupabaseServerAuthFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
2911
+ const factory = new SupabaseServerAuthFactory2();
2912
+ const supabase = factory.create({ config: opts, container });
2913
+ container.addScoped(TOKENS5.AUTH_SERVICE, () => {
2914
+ return supabase;
2915
+ });
2916
+ container.addSingleton(TOKENS5.BASE_AUTH_SERVICE, () => {
2917
+ return supabase;
2918
+ });
2919
+ }
2856
2920
  }
2857
2921
  });
2858
2922
  }
@@ -2945,7 +3009,7 @@ __export(unit_of_work_exports, {
2945
3009
  UnitOfWork: () => UnitOfWork
2946
3010
  });
2947
3011
  import { AppError as AppError14 } from "@xeno-js/shared";
2948
- import { Guards as Guards35 } from "@xeno-js/shared";
3012
+ import { Guards as Guards36 } from "@xeno-js/shared";
2949
3013
  var UnitOfWork;
2950
3014
  var init_unit_of_work = __esm({
2951
3015
  "src/infrastructure/transaction/unit-of-work.ts"() {
@@ -2980,9 +3044,9 @@ var init_unit_of_work = __esm({
2980
3044
  });
2981
3045
  }
2982
3046
  async dispose() {
2983
- if (Guards35.isDefined(this._ttx.state)) {
3047
+ if (Guards36.isDefined(this._ttx.state)) {
2984
3048
  try {
2985
- if (Guards35.hasMethod(this._ttx.state, "rollback")) {
3049
+ if (Guards36.hasMethod(this._ttx.state, "rollback")) {
2986
3050
  await this._ttx.state.rollback();
2987
3051
  }
2988
3052
  } finally {
@@ -3005,7 +3069,7 @@ var init_db_module = __esm({
3005
3069
  "use strict";
3006
3070
  DbModule = class {
3007
3071
  async configure(container, opts) {
3008
- const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3072
+ const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
3009
3073
  const { DbUtils: DbUtils2 } = await Promise.resolve().then(() => (init_db_utils(), db_utils_exports));
3010
3074
  const db = opts.enableSqlLite ? await DbUtils2.addSqlLite(opts) : await DbUtils2.addDbClient(opts);
3011
3075
  const { TransactionState: TransactionState2 } = await Promise.resolve().then(() => (init_transaction_state(), transaction_state_exports));
@@ -3013,16 +3077,16 @@ var init_db_module = __esm({
3013
3077
  return new TransactionState2();
3014
3078
  });
3015
3079
  const { UnitOfWork: UnitOfWork2 } = await Promise.resolve().then(() => (init_unit_of_work(), unit_of_work_exports));
3016
- container.addScoped(TOKENS4.UNIT_OF_WORK, (c) => {
3080
+ container.addScoped(TOKENS5.UNIT_OF_WORK, (c) => {
3017
3081
  const ttx = c.resolve("TRANSACTION_STATE");
3018
3082
  return new UnitOfWork2(db, ttx);
3019
3083
  });
3020
- container.addScoped(TOKENS4.DB_CONTEXT, (c) => {
3084
+ container.addScoped(TOKENS5.DB_CONTEXT, (c) => {
3021
3085
  const ttx = c.resolve("TRANSACTION_STATE");
3022
3086
  return new Proxy(db, {
3023
3087
  get(_target, prop, receiver) {
3024
3088
  const activeState = ttx.state;
3025
- if (Guards46.isDefined(activeState)) {
3089
+ if (Guards47.isDefined(activeState)) {
3026
3090
  if (prop === "transaction") {
3027
3091
  return activeState.transaction.bind(activeState);
3028
3092
  }
@@ -3059,14 +3123,14 @@ var init_http_utils = __esm({
3059
3123
  */
3060
3124
  async addAxios(container, opts) {
3061
3125
  const { NodeAxiosFactory: NodeAxiosFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
3062
- const { Guards: Guards46 } = await import("@xeno-js/shared");
3063
- if (!Guards46.isDefined(opts.token)) {
3126
+ const { Guards: Guards47 } = await import("@xeno-js/shared");
3127
+ if (!Guards47.isDefined(opts.token)) {
3064
3128
  throw new Error("HttpConfig.token is required and must be defined.");
3065
3129
  }
3066
3130
  container.addSingleton(opts.token, () => {
3067
3131
  const factory = new NodeAxiosFactory2();
3068
3132
  const instance = factory.create(opts.client);
3069
- if (!Guards46.hasMethod(instance, "get") || !Guards46.hasMethod(instance, "post") || !Guards46.hasMethod(instance, "put") || !Guards46.hasMethod(instance, "patch") || !Guards46.hasMethod(instance, "delete")) {
3133
+ if (!Guards47.hasMethod(instance, "get") || !Guards47.hasMethod(instance, "post") || !Guards47.hasMethod(instance, "put") || !Guards47.hasMethod(instance, "patch") || !Guards47.hasMethod(instance, "delete")) {
3070
3134
  throw new Error(
3071
3135
  "The created HTTP client instance does not implement the required methods of IHttpClient."
3072
3136
  );
@@ -3085,9 +3149,9 @@ var init_http_utils = __esm({
3085
3149
  * @link https://github.com/xeno-js/xeno-js
3086
3150
  */
3087
3151
  async addResilience(container, opts) {
3088
- const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3152
+ const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
3089
3153
  const { CockatielResilienceFactory: CockatielResilienceFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
3090
- container.addSingleton(TOKENS4.RESILIENCE_CLIENT, () => {
3154
+ container.addSingleton(TOKENS5.RESILIENCE_CLIENT, () => {
3091
3155
  const factory = new CockatielResilienceFactory2();
3092
3156
  return factory.create(opts);
3093
3157
  });
@@ -3136,22 +3200,22 @@ var init_validation_utils = __esm({
3136
3200
  * @link https://github.com/xeno-js/xeno-js
3137
3201
  */
3138
3202
  async addValidation(container, opts, logger) {
3139
- const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3140
- if (!Guards46.isDefined(opts.zod) && Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
3203
+ const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
3204
+ if (!Guards47.isDefined(opts.zod) && Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
3141
3205
  return;
3142
3206
  }
3143
3207
  const validationStrategies = [];
3144
- if (Guards46.isDefined(opts.zod)) {
3208
+ if (Guards47.isDefined(opts.zod)) {
3145
3209
  const config = opts.zod;
3146
3210
  const { ZodValidatorFactory: ZodValidatorFactory2 } = await Promise.resolve().then(() => (init_factories(), factories_exports));
3147
3211
  const { SchemaValidationStrategy: SchemaValidationStrategy2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3148
3212
  const validatorService = new ZodValidatorFactory2().create({ ...config, logger });
3149
- container.addSingleton(TOKENS4.VALIDATOR_SERVICE, () => validatorService);
3213
+ container.addSingleton(TOKENS5.VALIDATOR_SERVICE, () => validatorService);
3150
3214
  validationStrategies.push(new SchemaValidationStrategy2(validatorService));
3151
3215
  }
3152
- if (!Guards46.isNullOrEmpty(opts.customValidationStrategy)) {
3216
+ if (!Guards47.isNullOrEmpty(opts.customValidationStrategy)) {
3153
3217
  for (const strategyToken of opts.customValidationStrategy) {
3154
- if (Guards46.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
3218
+ if (Guards47.isDefined(strategyToken)) validationStrategies.push(strategyToken(container));
3155
3219
  }
3156
3220
  }
3157
3221
  const { ValidationPipeline: ValidationPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
@@ -3251,16 +3315,16 @@ var init_pipeline_utils = __esm({
3251
3315
  * @link https://github.com/xeno-js/xeno-js
3252
3316
  */
3253
3317
  async addCommand(container, opts) {
3254
- const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3318
+ const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
3255
3319
  const pipelines = [];
3256
- if (Guards46.isDefined(opts.idempotency)) {
3320
+ if (Guards47.isDefined(opts.idempotency)) {
3257
3321
  const { IdempotencyStore: IdempotencyStore2 } = await Promise.resolve().then(() => (init_idempotency(), idempotency_exports));
3258
3322
  const imdStore = new IdempotencyStore2(
3259
- container.resolve(TOKENS4.CACHE),
3260
- container.resolve(TOKENS4.CACHE_KEY_BUILDER)
3323
+ container.resolve(TOKENS5.CACHE),
3324
+ container.resolve(TOKENS5.CACHE_KEY_BUILDER)
3261
3325
  );
3262
3326
  const { IdempotencyPipeline: IdempotencyPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3263
- const requestContext = container.resolve(TOKENS4.NETWORK_CONTEXT_ACCESSOR);
3327
+ const requestContext = container.resolve(TOKENS5.NETWORK_CONTEXT_ACCESSOR);
3264
3328
  const config = opts.idempotency;
3265
3329
  pipelines.push(
3266
3330
  new IdempotencyPipeline2(
@@ -3271,7 +3335,7 @@ var init_pipeline_utils = __esm({
3271
3335
  )
3272
3336
  );
3273
3337
  }
3274
- if (Guards46.isDefined(opts.concurrency)) {
3338
+ if (Guards47.isDefined(opts.concurrency)) {
3275
3339
  const { ConcurrencyRetryPipeline: ConcurrencyRetryPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3276
3340
  const config = opts.concurrency;
3277
3341
  pipelines.push(new ConcurrencyRetryPipeline2(config?.maxRetries, config?.delayConfig));
@@ -3289,12 +3353,12 @@ var init_pipeline_utils = __esm({
3289
3353
  * @link https://github.com/xeno-js/xeno-js
3290
3354
  */
3291
3355
  async addQuery(container) {
3292
- const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3356
+ const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
3293
3357
  const { QueryCachingPipeline: QueryCachingPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3294
3358
  return new QueryCachingPipeline2(
3295
- container.resolve(TOKENS4.CACHE),
3296
- container.resolve(TOKENS4.CACHE_KEY_BUILDER),
3297
- container.resolve(TOKENS4.LOGGER)
3359
+ container.resolve(TOKENS5.CACHE),
3360
+ container.resolve(TOKENS5.CACHE_KEY_BUILDER),
3361
+ container.resolve(TOKENS5.LOGGER)
3298
3362
  );
3299
3363
  }
3300
3364
  });
@@ -3312,11 +3376,11 @@ var init_cqrs_module = __esm({
3312
3376
  "use strict";
3313
3377
  CqrsModule = class {
3314
3378
  async configure(container, opts) {
3315
- const { TOKENS: TOKENS4 } = await import("@xeno-js/shared");
3316
- const logger = container.resolve(TOKENS4.LOGGER);
3379
+ const { TOKENS: TOKENS5 } = await import("@xeno-js/shared");
3380
+ const logger = container.resolve(TOKENS5.LOGGER);
3317
3381
  const { Mediator: Mediator2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3318
- container.addSingleton(TOKENS4.MEDIATOR, (c) => {
3319
- const serviceScopeAccessor = c.resolve(TOKENS4.SERVICE_SCOPE_ACCESSOR);
3382
+ container.addSingleton(TOKENS5.MEDIATOR, (c) => {
3383
+ const serviceScopeAccessor = c.resolve(TOKENS5.SERVICE_SCOPE_ACCESSOR);
3320
3384
  return new Mediator2(serviceScopeAccessor);
3321
3385
  });
3322
3386
  const { ExceptionPipeline: ExceptionPipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
@@ -3328,24 +3392,24 @@ var init_cqrs_module = __esm({
3328
3392
  new LoggingPipeline2(logger),
3329
3393
  new PerformancePipeline2(logger, thresholdMs)
3330
3394
  ];
3331
- const { Guards: Guards46 } = await import("@xeno-js/shared");
3332
- if (Guards46.isDefined(opts.authorization.policies) || Guards46.isDefined(opts.authorization.customAuthorizationStrategy)) {
3395
+ const { Guards: Guards47 } = await import("@xeno-js/shared");
3396
+ if (Guards47.isDefined(opts.authorization.policies) || Guards47.isDefined(opts.authorization.customAuthorizationStrategy)) {
3333
3397
  const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
3334
3398
  const authPipelines = await AuthUtils2.addAuthZ(container, opts.authorization);
3335
3399
  pipelines.push(authPipelines);
3336
3400
  }
3337
- if (Guards46.isDefined(opts.validation.zod) || Guards46.isDefined(opts.validation.customValidationStrategy)) {
3401
+ if (Guards47.isDefined(opts.validation.zod) || Guards47.isDefined(opts.validation.customValidationStrategy)) {
3338
3402
  const { ValidationUtils: ValidationUtils2 } = await Promise.resolve().then(() => (init_validation_utils(), validation_utils_exports));
3339
3403
  const validationPipelines = await ValidationUtils2.addValidation(
3340
3404
  container,
3341
3405
  opts.validation,
3342
3406
  logger
3343
3407
  );
3344
- if (Guards46.isDefined(validationPipelines)) pipelines.push(validationPipelines);
3408
+ if (Guards47.isDefined(validationPipelines)) pipelines.push(validationPipelines);
3345
3409
  }
3346
3410
  const commandPipelines = [...pipelines];
3347
3411
  const queryPipelines = [...pipelines];
3348
- if (Guards46.isDefined(opts.commandBus.idempotency) || Guards46.isDefined(opts.commandBus.concurrency)) {
3412
+ if (Guards47.isDefined(opts.commandBus.idempotency) || Guards47.isDefined(opts.commandBus.concurrency)) {
3349
3413
  const { PipelineUtils: PipelineUtils2 } = await Promise.resolve().then(() => (init_pipeline_utils(), pipeline_utils_exports));
3350
3414
  const newCommandPipelines = await PipelineUtils2.addCommand(container, opts.commandBus);
3351
3415
  commandPipelines.push(...newCommandPipelines);
@@ -3356,10 +3420,10 @@ var init_cqrs_module = __esm({
3356
3420
  queryPipelines.push(newQueryPipelines);
3357
3421
  }
3358
3422
  const { CompositePipeline: CompositePipeline2 } = await Promise.resolve().then(() => (init_application(), application_exports));
3359
- container.addSingleton(TOKENS4.COMMAND_PIPELINES_BEHAVIOR, () => {
3423
+ container.addSingleton(TOKENS5.COMMAND_PIPELINES_BEHAVIOR, () => {
3360
3424
  return new CompositePipeline2(commandPipelines);
3361
3425
  });
3362
- container.addSingleton(TOKENS4.QUERY_PIPELINES_BEHAVIOR, () => {
3426
+ container.addSingleton(TOKENS5.QUERY_PIPELINES_BEHAVIOR, () => {
3363
3427
  return new CompositePipeline2(queryPipelines);
3364
3428
  });
3365
3429
  }
@@ -3447,6 +3511,7 @@ var init_base_controller = __esm({
3447
3511
  /**
3448
3512
  * Helper to send a query through the mediator and return the result.
3449
3513
  * @param request - The IQuery instance to be sent.
3514
+ * @param signal - The AbortSignal
3450
3515
  * @returns A promise resolving to the result of the query.
3451
3516
  *
3452
3517
  * @author Xeno
@@ -3454,13 +3519,13 @@ var init_base_controller = __esm({
3454
3519
  * @since 2025-09-30
3455
3520
  * @link https://github.com/xeno-js/xeno-js
3456
3521
  */
3457
- _query(request) {
3458
- const signal = new AbortController().signal;
3522
+ _query(request, signal) {
3459
3523
  return this._mediator.query(request, signal);
3460
3524
  }
3461
3525
  /**
3462
3526
  * Helper to send a command through the mediator and return the result.
3463
3527
  * @param request - The ICommand instance to be sent.
3528
+ * @param signal - The AbortSignal
3464
3529
  * @returns A promise resolving to the result of the command.
3465
3530
  *
3466
3531
  * @author Xeno
@@ -3468,8 +3533,7 @@ var init_base_controller = __esm({
3468
3533
  * @since 2025-09-30
3469
3534
  * @link https://github.com/xeno-js/xeno-js
3470
3535
  */
3471
- _send(request) {
3472
- const signal = new AbortController().signal;
3536
+ _send(request, signal) {
3473
3537
  return this._mediator.send(request, signal);
3474
3538
  }
3475
3539
  getContext() {
@@ -3506,7 +3570,7 @@ var init_allow_method_middleware = __esm({
3506
3570
  }
3507
3571
  _requestContext;
3508
3572
  _allowMethod;
3509
- async execute(req, _headers, next) {
3573
+ async execute(req, _res, next) {
3510
3574
  const isAllowed = this._allowMethod.check(req.path, req.method);
3511
3575
  if (!isAllowed) {
3512
3576
  const { network, tracing } = this._requestContext.getContext() ?? {};
@@ -3557,7 +3621,7 @@ var init_allow_origin_middleware = __esm({
3557
3621
  _allowOrigin;
3558
3622
  _requestContext;
3559
3623
  _logger;
3560
- async execute(req, _headers, next) {
3624
+ async execute(req, _res, next) {
3561
3625
  const { network, tracing } = this._requestContext.getContext() ?? {};
3562
3626
  const origin = network?.origin;
3563
3627
  if (!this._allowOrigin.isAllowed(origin)) {
@@ -3602,8 +3666,8 @@ var init_auth_middleware = __esm({
3602
3666
  _tokenExtractor;
3603
3667
  _gateKeeper;
3604
3668
  _logger;
3605
- async execute(req, headers, next) {
3606
- const token = this._tokenExtractor.extract(headers);
3669
+ async execute(req, _res, next) {
3670
+ const token = this._tokenExtractor.extract(req.headers);
3607
3671
  const authResult = await this._gateKeeper.authenticate(token);
3608
3672
  if (!authResult.isOk()) {
3609
3673
  const error = authResult.getErrorOrThrow();
@@ -3646,12 +3710,12 @@ var init_composite_middleware = __esm({
3646
3710
  this._middlewares = _middlewares;
3647
3711
  }
3648
3712
  _middlewares;
3649
- async execute(req, headers, next) {
3713
+ async execute(req, res, next) {
3650
3714
  let currentNext = next;
3651
3715
  for (let i = this._middlewares.length - 1; i >= 0; i--) {
3652
3716
  const currentBehavior = this._middlewares[i];
3653
3717
  const previousNext = currentNext;
3654
- currentNext = () => currentBehavior.execute(req, headers, previousNext);
3718
+ currentNext = () => currentBehavior.execute(req, res, previousNext);
3655
3719
  }
3656
3720
  return currentNext();
3657
3721
  }
@@ -3660,7 +3724,7 @@ var init_composite_middleware = __esm({
3660
3724
  });
3661
3725
 
3662
3726
  // src/presentation/middlewares/cors.middleware.ts
3663
- import { Guards as Guards36 } from "@xeno-js/shared";
3727
+ import { Guards as Guards37 } from "@xeno-js/shared";
3664
3728
  var CORSMiddleware;
3665
3729
  var init_cors_middleware = __esm({
3666
3730
  "src/presentation/middlewares/cors.middleware.ts"() {
@@ -3672,11 +3736,11 @@ var init_cors_middleware = __esm({
3672
3736
  }
3673
3737
  _requestContext;
3674
3738
  _withCredentials;
3675
- async execute(_req, _headers, next) {
3739
+ async execute(_req, _res, next) {
3676
3740
  const { network } = this._requestContext.getContext() ?? {};
3677
3741
  const origin = network?.origin;
3678
3742
  const response = await next();
3679
- if (Guards36.isDefined(origin))
3743
+ if (Guards37.isDefined(origin))
3680
3744
  response.headers = {
3681
3745
  ...response.headers ?? {},
3682
3746
  "Access-Control-Allow-Origin": origin,
@@ -3693,7 +3757,7 @@ var init_cors_middleware = __esm({
3693
3757
  import {
3694
3758
  ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES5,
3695
3759
  ERROR_CODES as ERROR_CODES6,
3696
- Guards as Guards37,
3760
+ Guards as Guards38,
3697
3761
  GuidHelper as GuidHelper9,
3698
3762
  HttpHelper as HttpHelper6,
3699
3763
  STATUS_CODES as STATUS_CODES7
@@ -3709,14 +3773,14 @@ var init_csrf_middleware = __esm({
3709
3773
  }
3710
3774
  _requestContext;
3711
3775
  _csrfTokenService;
3712
- async execute(req, _headers, next) {
3776
+ async execute(req, _res, next) {
3713
3777
  const method = req.method.toUpperCase();
3714
3778
  const isStateChanging = ["POST", "PUT", "DELETE", "PATCH"].includes(method);
3715
3779
  if (isStateChanging) {
3716
3780
  const { network, tracing, identity } = this._requestContext.getContext() ?? {};
3717
3781
  const headerToken = network?.csrf;
3718
3782
  const cookieToken = network?.csrfCookie;
3719
- if (!Guards37.isDefined(headerToken) || !Guards37.isDefined(cookieToken)) {
3783
+ if (!Guards38.isDefined(headerToken) || !Guards38.isDefined(cookieToken)) {
3720
3784
  return HttpHelper6.error(
3721
3785
  {
3722
3786
  success: false,
@@ -3758,7 +3822,7 @@ var init_csrf_middleware = __esm({
3758
3822
  }
3759
3823
  );
3760
3824
  }
3761
- if (!Guards37.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
3825
+ if (!Guards38.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
3762
3826
  return HttpHelper6.error(
3763
3827
  {
3764
3828
  success: false,
@@ -3787,7 +3851,7 @@ var init_csrf_middleware = __esm({
3787
3851
  });
3788
3852
 
3789
3853
  // src/presentation/middlewares/csrf-cookie.middleware.ts
3790
- import { Guards as Guards38 } from "@xeno-js/shared";
3854
+ import { Guards as Guards39 } from "@xeno-js/shared";
3791
3855
  var CsrfCookieMiddleware;
3792
3856
  var init_csrf_cookie_middleware = __esm({
3793
3857
  "src/presentation/middlewares/csrf-cookie.middleware.ts"() {
@@ -3801,13 +3865,13 @@ var init_csrf_cookie_middleware = __esm({
3801
3865
  _requestContext;
3802
3866
  _csrfTokenService;
3803
3867
  _csrf;
3804
- async execute(_req, _headers, next) {
3868
+ async execute(_req, _res, next) {
3805
3869
  const response = await next();
3806
3870
  const context = this._requestContext.getContext();
3807
3871
  const identity = context?.identity;
3808
3872
  const network = context?.network;
3809
- if (!Guards38.isDefined(identity?.userId)) return response;
3810
- if (Guards38.isDefined(network?.csrfCookie)) return response;
3873
+ if (!Guards39.isDefined(identity?.userId)) return response;
3874
+ if (Guards39.isDefined(network?.csrfCookie)) return response;
3811
3875
  const token = await this._csrfTokenService.generate(identity.userId);
3812
3876
  const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
3813
3877
  const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
@@ -3825,7 +3889,7 @@ var init_csrf_cookie_middleware = __esm({
3825
3889
  });
3826
3890
 
3827
3891
  // src/presentation/middlewares/options.middleware.ts
3828
- import { Guards as Guards39, HttpHelper as HttpHelper7, STATUS_CODES as STATUS_CODES8 } from "@xeno-js/shared";
3892
+ import { Guards as Guards40, HttpHelper as HttpHelper7, STATUS_CODES as STATUS_CODES8 } from "@xeno-js/shared";
3829
3893
  var OptionsMiddleware;
3830
3894
  var init_options_middleware = __esm({
3831
3895
  "src/presentation/middlewares/options.middleware.ts"() {
@@ -3841,12 +3905,12 @@ var init_options_middleware = __esm({
3841
3905
  _alloewMethod;
3842
3906
  _allowHeaders;
3843
3907
  _withCredentials;
3844
- async execute(req, _headers, next) {
3908
+ async execute(req, _res, next) {
3845
3909
  if (req.method.toUpperCase() === "OPTIONS") {
3846
3910
  const network = this._requestContext.getNetworkContext();
3847
3911
  const origin = network?.origin;
3848
3912
  const headers = {};
3849
- if (Guards39.isDefined(origin)) {
3913
+ if (Guards40.isDefined(origin)) {
3850
3914
  headers["Access-Control-Allow-Origin"] = origin;
3851
3915
  headers["Access-Control-Allow-Credentials"] = this._withCredentials;
3852
3916
  headers["Vary"] = "Origin";
@@ -3865,7 +3929,7 @@ var init_options_middleware = __esm({
3865
3929
  import {
3866
3930
  ERROR_CODE_MESSAGES as ERROR_CODE_MESSAGES6,
3867
3931
  ERROR_CODES as ERROR_CODES7,
3868
- Guards as Guards40,
3932
+ Guards as Guards41,
3869
3933
  GuidHelper as GuidHelper10,
3870
3934
  HttpHelper as HttpHelper8,
3871
3935
  STATUS_CODES as STATUS_CODES9
@@ -3887,10 +3951,10 @@ var init_rate_limiter_middleware = __esm({
3887
3951
  _keyBuilder;
3888
3952
  _logger;
3889
3953
  _opts;
3890
- async execute(req, _headers, next) {
3954
+ async execute(req, _res, next) {
3891
3955
  const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
3892
3956
  const { network, tracing } = this._ctxAccessor.getContext() ?? {};
3893
- if (!Guards40.isDefined(cacheKey))
3957
+ if (!Guards41.isDefined(cacheKey))
3894
3958
  return HttpHelper8.error(
3895
3959
  {
3896
3960
  success: false,
@@ -3942,10 +4006,10 @@ var init_rate_limiter_middleware = __esm({
3942
4006
  });
3943
4007
 
3944
4008
  // src/presentation/mappers/context.mapper.ts
3945
- import { Guards as Guards41 } from "@xeno-js/shared";
4009
+ import { Guards as Guards42 } from "@xeno-js/shared";
3946
4010
  function _buildMessagingContext(meta) {
3947
- const hasSequenceData = Guards41.isDefined(meta.sequence?.sequenceId) || Guards41.isDefined(meta.sequence?.position) || Guards41.isDefined(meta.sequence?.size);
3948
- const hasMessagingData = hasSequenceData || Guards41.isDefined(meta.expiration) || Guards41.isDefined(meta.returnAddress);
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);
3949
4013
  const messaging = hasMessagingData ? {
3950
4014
  returnAddress: meta.returnAddress,
3951
4015
  expiration: meta.expiration,
@@ -4035,14 +4099,14 @@ var init_request_middleware = __esm({
4035
4099
  _extractor;
4036
4100
  _resolver;
4037
4101
  _logger;
4038
- async execute(req, headers, next) {
4102
+ async execute(req, res, next) {
4039
4103
  const correlationId = GuidHelper11.generate();
4040
4104
  const requestId = GuidHelper11.generate();
4041
4105
  const spanId = correlationId;
4042
4106
  const formatIndicator = "application/json";
4043
4107
  try {
4044
- const meta = this._extractor.extract(headers);
4045
- const clientIp = this._resolver.resolve(req.transport.req, meta.clientIp);
4108
+ const meta = this._extractor.extract(req.headers);
4109
+ const clientIp = this._resolver.resolve(req, meta.clientIp);
4046
4110
  const metadata = {
4047
4111
  ...meta,
4048
4112
  clientIp,
@@ -4055,7 +4119,7 @@ var init_request_middleware = __esm({
4055
4119
  metadata,
4056
4120
  identity: GUEST3,
4057
4121
  path: req.path,
4058
- transport: req.transport
4122
+ transport: { req, res }
4059
4123
  });
4060
4124
  const result = await this._requestContext.runAsync(tmpContext, async () => {
4061
4125
  return next();
@@ -4129,7 +4193,7 @@ var init_presentation = __esm({
4129
4193
  });
4130
4194
 
4131
4195
  // src/infrastructure/cache/rate-limit-key-builder.cache.ts
4132
- import { Guards as Guards42 } from "@xeno-js/shared";
4196
+ import { Guards as Guards43 } from "@xeno-js/shared";
4133
4197
  var RateLimitKeyBuilder;
4134
4198
  var init_rate_limit_key_builder_cache = __esm({
4135
4199
  "src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
@@ -4144,12 +4208,12 @@ var init_rate_limit_key_builder_cache = __esm({
4144
4208
  const tenantId = ctx?.identity?.tenantId;
4145
4209
  const userId = ctx?.identity?.userId;
4146
4210
  const clientIp = ctx?.network?.clientIp;
4147
- if (!Guards42.isNullOrEmpty(tenantId) && !Guards42.isNullOrEmpty(userId))
4211
+ if (!Guards43.isNullOrEmpty(tenantId) && !Guards43.isNullOrEmpty(userId))
4148
4212
  return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
4149
- if (!Guards42.isNullOrEmpty(tenantId) && !Guards42.isNullOrEmpty(clientIp))
4213
+ if (!Guards43.isNullOrEmpty(tenantId) && !Guards43.isNullOrEmpty(clientIp))
4150
4214
  return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
4151
- if (!Guards42.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
4152
- if (!Guards42.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
4215
+ if (!Guards43.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
4216
+ if (!Guards43.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
4153
4217
  return void 0;
4154
4218
  }
4155
4219
  };
@@ -4183,12 +4247,16 @@ var init_middleware_module = __esm({
4183
4247
  "use strict";
4184
4248
  MiddlewareModule = class {
4185
4249
  async configure(container, opts) {
4186
- const { Guards: Guards46, TOKENS: TOKENS4 } = await import("@xeno-js/shared");
4250
+ const { Guards: Guards47, TOKENS: TOKENS5 } = await import("@xeno-js/shared");
4187
4251
  const { HttpCookieExtractor: HttpCookieExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4188
4252
  const { HttpHeaderExtractor: HttpHeaderExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4189
- const tokenExtractor = await this._getTokenExtractor(opts.isSSR);
4253
+ const tokenExtractor = await this._getTokenExtractor(
4254
+ opts.isSSR,
4255
+ opts.authCookieName,
4256
+ opts.customTokenExtractor
4257
+ );
4190
4258
  container.addSingleton(
4191
- TOKENS4.SERVICE_EXTRACTOR,
4259
+ TOKENS5.SERVICE_EXTRACTOR,
4192
4260
  () => new HttpHeaderExtractor2(
4193
4261
  tokenExtractor,
4194
4262
  new HttpCookieExtractor2(),
@@ -4198,18 +4266,18 @@ var init_middleware_module = __esm({
4198
4266
  );
4199
4267
  const { ClientIpResolver: ClientIpResolver2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4200
4268
  const middlewares = [];
4201
- const requestContext = container.resolve(TOKENS4.REQUEST_CONTEXT);
4202
- const logger = container.resolve(TOKENS4.LOGGER);
4269
+ const requestContext = container.resolve(TOKENS5.REQUEST_CONTEXT);
4270
+ const logger = container.resolve(TOKENS5.LOGGER);
4203
4271
  const { RequestContextMiddleware: RequestContextMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4204
4272
  middlewares.push(
4205
4273
  new RequestContextMiddleware2(
4206
4274
  requestContext,
4207
- container.resolve(TOKENS4.SERVICE_EXTRACTOR),
4275
+ container.resolve(TOKENS5.SERVICE_EXTRACTOR),
4208
4276
  new ClientIpResolver2(opts.trustedProxies),
4209
4277
  logger
4210
4278
  )
4211
4279
  );
4212
- if (!Guards46.isNullOrEmpty(opts.allowOrigins)) {
4280
+ if (!Guards47.isNullOrEmpty(opts.allowOrigins)) {
4213
4281
  if (opts.withCredentials && opts.allowOrigins.includes("*"))
4214
4282
  throw new Error(
4215
4283
  "Wildcard CORS origin is not allowed when withCredentials is set to true in addHttpCore"
@@ -4235,7 +4303,7 @@ var init_middleware_module = __esm({
4235
4303
  const { CORSMiddleware: CORSMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4236
4304
  middlewares.push(new CORSMiddleware2(requestContext, withCredentials));
4237
4305
  }
4238
- if (Guards46.isDefined(opts.routeRegistry)) {
4306
+ if (Guards47.isDefined(opts.routeRegistry)) {
4239
4307
  const { MethodCheckMiddleware: MethodCheckMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4240
4308
  middlewares.push(new MethodCheckMiddleware2(requestContext, allowMethod));
4241
4309
  }
@@ -4257,31 +4325,31 @@ var init_middleware_module = __esm({
4257
4325
  new AuthenticationMiddleware2(
4258
4326
  requestContext,
4259
4327
  tokenExtractor,
4260
- new GateKeeper2(container.resolve(TOKENS4.BASE_AUTH_SERVICE), new ClaimsIdentityMapper2()),
4328
+ new GateKeeper2(container.resolve(TOKENS5.BASE_AUTH_SERVICE), new ClaimsIdentityMapper2()),
4261
4329
  logger
4262
4330
  )
4263
4331
  );
4264
4332
  }
4265
- if (Guards46.isDefined(opts.rateLimite.maxRequests) || Guards46.isDefined(opts.rateLimite.windowSeconds)) {
4333
+ if (Guards47.isDefined(opts.rateLimite.maxRequests) || Guards47.isDefined(opts.rateLimite.windowSeconds)) {
4266
4334
  const maxRequests = opts.rateLimite.maxRequests ?? 30;
4267
- Guards46.throwIfNegative(maxRequests, "MaxRequests must be positive");
4268
- Guards46.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
4335
+ Guards47.throwIfNegative(maxRequests, "MaxRequests must be positive");
4336
+ Guards47.throwIfNotInteger(maxRequests, "MaxRequests must be an integer");
4269
4337
  const windowSeconds = opts.rateLimite.windowSeconds ?? 30;
4270
- Guards46.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
4271
- Guards46.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
4338
+ Guards47.throwIfNegative(windowSeconds, "WindowSeconds must be positive");
4339
+ Guards47.throwIfNotInteger(windowSeconds, "WindowSeconds must be an integer");
4272
4340
  const { RateLimitKeyBuilder: RateLimitKeyBuilder2 } = await Promise.resolve().then(() => (init_cache(), cache_exports));
4273
4341
  const { RateLimitMiddleware: RateLimitMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4274
4342
  middlewares.push(
4275
4343
  new RateLimitMiddleware2(
4276
4344
  requestContext,
4277
- container.resolve(TOKENS4.CACHE),
4345
+ container.resolve(TOKENS5.CACHE),
4278
4346
  new RateLimitKeyBuilder2(requestContext),
4279
4347
  logger,
4280
4348
  { maxRequests, windowSeconds }
4281
4349
  )
4282
4350
  );
4283
4351
  }
4284
- if (Guards46.isDefined(opts.csrf)) {
4352
+ if (Guards47.isDefined(opts.csrf)) {
4285
4353
  const csrf = opts.csrf;
4286
4354
  const { EdgeCryptoService: EdgeCryptoService2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4287
4355
  container.addSingleton("CRYPTO_SERVICE", () => new EdgeCryptoService2());
@@ -4301,22 +4369,24 @@ var init_middleware_module = __esm({
4301
4369
  middlewares.push(new CsrfMiddleware2(requestContext, container.resolve("CSRF_TOKEN_SERVICE")));
4302
4370
  }
4303
4371
  const { CompositeMiddleware: CompositeMiddleware2 } = await Promise.resolve().then(() => (init_presentation(), presentation_exports));
4304
- container.addSingleton(TOKENS4.MIDDLEWARE, () => {
4372
+ container.addSingleton(TOKENS5.MIDDLEWARE, () => {
4305
4373
  return new CompositeMiddleware2(middlewares);
4306
4374
  });
4307
4375
  }
4308
- async _getTokenExtractor(isSSR) {
4376
+ async _getTokenExtractor(isSSR, cookieName, customTokenExtractor) {
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();
4312
4382
  } else {
4313
4383
  const { BearerTokenExtractor: BearerTokenExtractor2 } = await Promise.resolve().then(() => (init_services(), services_exports));
4314
- return new BearerTokenExtractor2();
4384
+ return new BearerTokenExtractor2(cookieName ?? "sb-access-token");
4315
4385
  }
4316
4386
  }
4317
4387
  async _getAllowMethod(configure, opts) {
4318
- const { Guards: Guards46 } = await import("@xeno-js/shared");
4319
- if (!configure || !Guards46.isDefined(opts)) return void 0;
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: TOKENS4 } = await import("@xeno-js/shared");
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(TOKENS4.REQUEST_CONTEXT, () => requestContext);
4345
- container.addSingleton(TOKENS4.CONTEXT_ACCESSOR, () => requestContext);
4346
- container.addSingleton(TOKENS4.IDENTITY_ACCESSOR, () => requestContext);
4347
- container.addSingleton(TOKENS4.SERVICE_SCOPE_ACCESSOR, () => requestContext);
4348
- container.addSingleton(TOKENS4.NETWORK_CONTEXT_ACCESSOR, () => requestContext);
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 Guards43, LOG_LEVEL as LOG_LEVEL6, TOKENS as TOKENS3 } from "@xeno-js/shared";
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
- TOKENS3.CONFIGURATION_SERVICE,
4726
+ TOKENS4.CONFIGURATION_SERVICE,
4657
4727
  () => new EnvironmentConfigurationService()
4658
4728
  );
4659
- this._configuration = this._container.resolve(TOKENS3.CONFIGURATION_SERVICE);
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 = [];
@@ -4695,7 +4766,23 @@ var AppBuilder = class {
4695
4766
  allowOrigins: [],
4696
4767
  allowHeaders: [],
4697
4768
  cors: true,
4698
- withCredentials: true
4769
+ withCredentials: true,
4770
+ authCookieName: "sb-access-token"
4771
+ };
4772
+ _authConfig = {
4773
+ url: "",
4774
+ key: "",
4775
+ opts: void 0,
4776
+ redirectTo: "",
4777
+ storageOpts: { type: "memory", cookieOpts: void 0, storage: void 0 },
4778
+ ssrOpts: void 0,
4779
+ customAuth: void 0,
4780
+ cookieOpts: {
4781
+ path: "/",
4782
+ httpOnly: true,
4783
+ sameSite: "lax",
4784
+ secure: true
4785
+ }
4699
4786
  };
4700
4787
  _httpConfig = {
4701
4788
  dataSourceToken: void 0,
@@ -4774,7 +4861,7 @@ var AppBuilder = class {
4774
4861
  * @link https://github.com/xeno-js/xeno-js
4775
4862
  */
4776
4863
  addLogger(setupAction) {
4777
- if (Guards43.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
4864
+ if (Guards44.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
4778
4865
  if (this._isLoggerModuleQueued) return this;
4779
4866
  this._isLoggerModuleQueued = true;
4780
4867
  this._modules.push({
@@ -4799,7 +4886,7 @@ var AppBuilder = class {
4799
4886
  * @link https://github.com/xeno-js/xeno-js
4800
4887
  */
4801
4888
  addCache(setupAction) {
4802
- if (Guards43.isDefined(setupAction)) setupAction(this._config, this._configuration);
4889
+ if (Guards44.isDefined(setupAction)) setupAction(this._config, this._configuration);
4803
4890
  if (this._isCacheModuleQueued) return this;
4804
4891
  this._isCacheModuleQueued = true;
4805
4892
  this._modules.push({
@@ -4826,21 +4913,13 @@ var AppBuilder = class {
4826
4913
  addAuth(setupAction) {
4827
4914
  if (this._isAuthModuleQueued) return this;
4828
4915
  this._isAuthModuleQueued = true;
4829
- const config = {
4830
- url: "",
4831
- key: "",
4832
- opts: void 0,
4833
- redirectTo: "",
4834
- storageOpts: { type: "memory", cookieOpts: void 0, storage: void 0 },
4835
- ssrOpts: void 0
4836
- };
4837
- setupAction(config, this._configuration);
4916
+ setupAction(this._authConfig, this._configuration);
4838
4917
  this._modules.push({
4839
4918
  priority: 3,
4840
4919
  name: "AuthModule",
4841
4920
  action: async () => {
4842
4921
  const { AuthUtils: AuthUtils2 } = await Promise.resolve().then(() => (init_auth_utils(), auth_utils_exports));
4843
- await AuthUtils2.addAuthN(this._container, config);
4922
+ await AuthUtils2.addAuthN(this._container, this._authConfig);
4844
4923
  }
4845
4924
  });
4846
4925
  return this;
@@ -4910,7 +4989,7 @@ var AppBuilder = class {
4910
4989
  * @link https://github.com/xeno-js/xeno-js
4911
4990
  */
4912
4991
  addPipeline(setupAction) {
4913
- if (Guards43.isDefined(setupAction)) {
4992
+ if (Guards44.isDefined(setupAction)) {
4914
4993
  setupAction(this._pipelineConfig, this._configuration);
4915
4994
  }
4916
4995
  this._queuePipelineModule();
@@ -5031,7 +5110,7 @@ var AppBuilder = class {
5031
5110
  console.error(`\u{1F449} Module: **${queued.name}**`);
5032
5111
  console.error(`\u{1F4DD} Reason: ${errorMessage}
5033
5112
  `);
5034
- if (error instanceof Error && Guards43.isDefined(error.stack)) {
5113
+ if (error instanceof Error && Guards44.isDefined(error.stack)) {
5035
5114
  console.error(error.stack);
5036
5115
  }
5037
5116
  throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
@@ -5092,7 +5171,8 @@ var AppBuilder = class {
5092
5171
  const middlewareModule = new MiddlewareModule2();
5093
5172
  await middlewareModule.configure(this._container, {
5094
5173
  ...this._middlewareConfig,
5095
- isAuth: this._isAuthModuleQueued
5174
+ isAuth: this._isAuthModuleQueued,
5175
+ customTokenExtractor: this._authConfig.customAuth?.authHeaderExtractor
5096
5176
  });
5097
5177
  }
5098
5178
  });
@@ -5187,7 +5267,7 @@ init_validation_utils();
5187
5267
 
5188
5268
  // src/infrastructure/repositories/read-dao.ts
5189
5269
  import { AppError as AppError16, Result as Result17 } from "@xeno-js/shared";
5190
- import { Guards as Guards44 } from "@xeno-js/shared";
5270
+ import { Guards as Guards45 } from "@xeno-js/shared";
5191
5271
  var ReadDao = class {
5192
5272
  /**
5193
5273
  * Constructs a new ReadDao instance.
@@ -5209,7 +5289,7 @@ var ReadDao = class {
5209
5289
  async findById(id, ctx, signal) {
5210
5290
  AppError16.throwIfAborted(signal, "ReadDao.findById");
5211
5291
  const result = await this._dataSource.findById(id, ctx, signal);
5212
- if (Guards44.isNullOrEmpty(result)) return Result17.ok();
5292
+ if (Guards45.isNullOrEmpty(result)) return Result17.ok();
5213
5293
  const entity = this._mapper.toEntity(result);
5214
5294
  return Result17.ok(entity);
5215
5295
  }
@@ -5223,7 +5303,7 @@ var ReadDao = class {
5223
5303
 
5224
5304
  // src/infrastructure/repositories/repository.ts
5225
5305
  import { AppError as AppError17, Result as Result18 } from "@xeno-js/shared";
5226
- import { Guards as Guards45 } from "@xeno-js/shared";
5306
+ import { Guards as Guards46 } from "@xeno-js/shared";
5227
5307
  var Repository = class {
5228
5308
  /**
5229
5309
  * Constructs a new Repository instance.
@@ -5245,7 +5325,7 @@ var Repository = class {
5245
5325
  async findById(id, ctx, signal) {
5246
5326
  AppError17.throwIfAborted(signal, "Repository.findById");
5247
5327
  const result = await this._dataSource.findById(id, ctx, signal);
5248
- if (Guards45.isNullOrEmpty(result)) return Result18.ok();
5328
+ if (Guards46.isNullOrEmpty(result)) return Result18.ok();
5249
5329
  const entity = this._mapper.toEntity(result);
5250
5330
  return Result18.ok(entity);
5251
5331
  }