@interopio/gateway-server 0.12.0-beta.0 → 0.13.0-beta.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
@@ -13,22 +13,22 @@ import http2 from "node:http";
13
13
  import https from "node:https";
14
14
  import { readFileSync } from "node:fs";
15
15
  import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
16
- import { IOGateway as IOGateway7 } from "@interopio/gateway";
16
+ import { IOGateway as IOGateway6 } from "@interopio/gateway";
17
17
 
18
18
  // src/logger.ts
19
- import { IOGateway } from "@interopio/gateway";
20
- function getLogger(name) {
21
- return IOGateway.Logging.getLogger(`gateway.server.${name}`);
19
+ import * as GatewayLogging from "@interopio/gateway/logging/core";
20
+ function getLogger2(name) {
21
+ return GatewayLogging.getLogger(`gateway.server.${name}`);
22
22
  }
23
23
  function regexAwareReplacer(_key, value) {
24
24
  return value instanceof RegExp ? value.toString() : value;
25
25
  }
26
26
 
27
27
  // src/gateway/ws/core.ts
28
- import { IOGateway as IOGateway2 } from "@interopio/gateway";
28
+ import { IOGateway } from "@interopio/gateway";
29
29
  import { AsyncLocalStorage } from "node:async_hooks";
30
- var GatewayEncoders = IOGateway2.Encoding;
31
- var log = getLogger("ws");
30
+ var GatewayEncoders = IOGateway.Encoding;
31
+ var log = getLogger2("ws");
32
32
  var codec = GatewayEncoders.json();
33
33
  function principalName(authentication) {
34
34
  let name;
@@ -1041,7 +1041,7 @@ var localIp = (() => {
1041
1041
  // src/server/monitoring.ts
1042
1042
  import { getHeapStatistics, writeHeapSnapshot } from "node:v8";
1043
1043
  import { access, mkdir, rename, unlink } from "node:fs/promises";
1044
- var log2 = getLogger("monitoring");
1044
+ var log2 = getLogger2("monitoring");
1045
1045
  var DEFAULT_OPTIONS = {
1046
1046
  memoryLimit: 1024 * 1024 * 1024,
1047
1047
  // 1GB
@@ -1195,8 +1195,8 @@ var serverHeader = (server) => {
1195
1195
  var server_header_default = (server) => serverHeader(server);
1196
1196
 
1197
1197
  // src/server/ws-client-verify.ts
1198
- import { IOGateway as IOGateway3 } from "@interopio/gateway";
1199
- var log3 = getLogger("gateway.ws.client-verify");
1198
+ import { IOGateway as IOGateway2 } from "@interopio/gateway";
1199
+ var log3 = getLogger2("gateway.ws.client-verify");
1200
1200
  function acceptsMissing(originFilters) {
1201
1201
  switch (originFilters.missing) {
1202
1202
  case "allow":
@@ -1214,10 +1214,10 @@ function acceptsMissing(originFilters) {
1214
1214
  function tryMatch(originFilters, origin) {
1215
1215
  const block = originFilters.block ?? originFilters["blacklist"];
1216
1216
  const allow = originFilters.allow ?? originFilters["whitelist"];
1217
- if (block.length > 0 && IOGateway3.Filtering.valuesMatch(block, origin)) {
1217
+ if (block.length > 0 && IOGateway2.Filtering.valuesMatch(block, origin)) {
1218
1218
  log3.warn(`origin ${origin} matches block filter`);
1219
1219
  return false;
1220
- } else if (allow.length > 0 && IOGateway3.Filtering.valuesMatch(allow, origin)) {
1220
+ } else if (allow.length > 0 && IOGateway2.Filtering.valuesMatch(allow, origin)) {
1221
1221
  if (log3.enabledFor("debug")) {
1222
1222
  log3.debug(`origin ${origin} matches allow filter`);
1223
1223
  }
@@ -1255,8 +1255,8 @@ function acceptsOrigin(origin, originFilters) {
1255
1255
  }
1256
1256
  function regexifyOriginFilters(originFilters) {
1257
1257
  if (originFilters) {
1258
- const block = (originFilters.block ?? originFilters.blacklist ?? []).map(IOGateway3.Filtering.regexify);
1259
- const allow = (originFilters.allow ?? originFilters.whitelist ?? []).map(IOGateway3.Filtering.regexify);
1258
+ const block = (originFilters.block ?? originFilters.blacklist ?? []).map(IOGateway2.Filtering.regexify);
1259
+ const allow = (originFilters.allow ?? originFilters.whitelist ?? []).map(IOGateway2.Filtering.regexify);
1260
1260
  return {
1261
1261
  non_matched: originFilters.non_matched ?? "allow",
1262
1262
  missing: originFilters.missing ?? "allow",
@@ -1371,12 +1371,12 @@ var upgradeMatcher = async ({ request }) => {
1371
1371
  upgradeMatcher.toString = () => "websocket upgrade";
1372
1372
 
1373
1373
  // src/app/route.ts
1374
- import { IOGateway as IOGateway4 } from "@interopio/gateway";
1374
+ import { IOGateway as IOGateway3 } from "@interopio/gateway";
1375
1375
  async function configure(app, config, routes) {
1376
1376
  const applyCors = (request, options) => {
1377
1377
  if (options?.cors) {
1378
1378
  const cors = options.cors === true ? {
1379
- allowOrigins: options.origins?.allow?.map(IOGateway4.Filtering.regexify),
1379
+ allowOrigins: options.origins?.allow?.map(IOGateway3.Filtering.regexify),
1380
1380
  allowMethods: request.method === void 0 ? ["*"] : [request.method],
1381
1381
  allowCredentials: options.authorize?.access !== "permitted" ? true : void 0
1382
1382
  } : options.cors;
@@ -1387,7 +1387,7 @@ async function configure(app, config, routes) {
1387
1387
  const configurer = new class {
1388
1388
  handle(...handlers) {
1389
1389
  handlers.forEach(({ request, options, handler }) => {
1390
- const matcher = pattern(IOGateway4.Filtering.regexify(request.path), { method: request.method });
1390
+ const matcher = pattern(IOGateway3.Filtering.regexify(request.path), { method: request.method });
1391
1391
  if (options?.authorize) {
1392
1392
  routes.authorize.push([matcher, options.authorize]);
1393
1393
  }
@@ -1421,7 +1421,7 @@ async function configure(app, config, routes) {
1421
1421
  }
1422
1422
 
1423
1423
  // src/server/cors.ts
1424
- import { IOGateway as IOGateway5 } from "@interopio/gateway";
1424
+ import { IOGateway as IOGateway4 } from "@interopio/gateway";
1425
1425
  function isSameOrigin(request) {
1426
1426
  const origin = request.headers.one("origin");
1427
1427
  if (origin === void 0) {
@@ -1511,7 +1511,7 @@ function validateCorsConfig(config) {
1511
1511
  ...config,
1512
1512
  allowOrigins: allowOrigins.map((origin) => {
1513
1513
  if (typeof origin === "string" && origin !== ALL) {
1514
- origin = IOGateway5.Filtering.regexify(origin);
1514
+ origin = IOGateway4.Filtering.regexify(origin);
1515
1515
  if (typeof origin === "string") {
1516
1516
  return trimTrailingSlash(origin).toLowerCase();
1517
1517
  }
@@ -1574,7 +1574,7 @@ var corsFilter = (opts) => {
1574
1574
  };
1575
1575
  };
1576
1576
  var cors_default = corsFilter;
1577
- var logger = getLogger("cors");
1577
+ var logger = getLogger2("cors");
1578
1578
  function rejectRequest(response) {
1579
1579
  response.setStatusCode(HttpStatus.FORBIDDEN);
1580
1580
  }
@@ -1653,7 +1653,7 @@ function checkOrigin(config, origin) {
1653
1653
  }
1654
1654
  const originToCheck = trimTrailingSlash(origin.toLowerCase());
1655
1655
  for (const allowedOrigin of allowedOrigins) {
1656
- if (allowedOrigin === ALL || IOGateway5.Filtering.valueMatches(allowedOrigin, originToCheck)) {
1656
+ if (allowedOrigin === ALL || IOGateway4.Filtering.valueMatches(allowedOrigin, originToCheck)) {
1657
1657
  return origin;
1658
1658
  }
1659
1659
  }
@@ -1666,7 +1666,7 @@ function checkMethods(config, requestMethod) {
1666
1666
  if (allowedMethods === ALL) {
1667
1667
  return [requestMethod];
1668
1668
  }
1669
- if (IOGateway5.Filtering.valuesMatch(allowedMethods, requestMethod)) {
1669
+ if (IOGateway4.Filtering.valuesMatch(allowedMethods, requestMethod)) {
1670
1670
  return allowedMethods;
1671
1671
  }
1672
1672
  }
@@ -1725,7 +1725,7 @@ var matchingCorsConfigSource = (opts) => {
1725
1725
  };
1726
1726
 
1727
1727
  // src/app/cors.ts
1728
- import { IOGateway as IOGateway6 } from "@interopio/gateway";
1728
+ import { IOGateway as IOGateway5 } from "@interopio/gateway";
1729
1729
  function createCorsConfigSource(context) {
1730
1730
  const { sockets: routes, cors } = context;
1731
1731
  const defaultCorsConfig = context.corsConfig === false ? void 0 : combineCorsConfig(PERMIT_DEFAULT_CONFIG, context.corsConfig);
@@ -1733,7 +1733,7 @@ function createCorsConfigSource(context) {
1733
1733
  for (const [path, route] of routes) {
1734
1734
  let routeCorsConfig = defaultCorsConfig;
1735
1735
  for (const [matcher, config2] of cors) {
1736
- if (IOGateway6.Filtering.valueMatches(matcher, path)) {
1736
+ if (IOGateway5.Filtering.valueMatches(matcher, path)) {
1737
1737
  if (config2 === void 0) {
1738
1738
  routeCorsConfig = void 0;
1739
1739
  } else {
@@ -2139,7 +2139,7 @@ var httpStatusEntryPoint = (opts) => {
2139
2139
  };
2140
2140
 
2141
2141
  // src/server/security/delegating-entry-point.ts
2142
- var logger2 = getLogger("auth.entry-point");
2142
+ var logger2 = getLogger2("auth.entry-point");
2143
2143
  var delegatingEntryPoint = (opts) => {
2144
2144
  const defaultEntryPoint = opts.defaultEntryPoint ?? (async ({ response }, _error) => {
2145
2145
  response.setStatusCode(HttpStatus.UNAUTHORIZED);
@@ -2495,7 +2495,7 @@ var errorFilter = (opts) => {
2495
2495
  };
2496
2496
 
2497
2497
  // src/server/security/delegating-authorization-manager.ts
2498
- var logger3 = getLogger("security.auth");
2498
+ var logger3 = getLogger2("security.auth");
2499
2499
  function delegatingAuthorizationManager(opts) {
2500
2500
  const check = async (authentication, exchange) => {
2501
2501
  let decision;
@@ -2516,7 +2516,7 @@ function delegatingAuthorizationManager(opts) {
2516
2516
  }
2517
2517
 
2518
2518
  // src/server/security/authorization-filter.ts
2519
- var logger4 = getLogger("security.auth");
2519
+ var logger4 = getLogger2("security.auth");
2520
2520
  function authorizationFilter(opts) {
2521
2521
  const { manager, storage } = opts;
2522
2522
  return async (exchange, next) => {
@@ -2886,7 +2886,7 @@ var WebHttpHandlerBuilder = class {
2886
2886
  this.#webHandler = webHandler;
2887
2887
  }
2888
2888
  build() {
2889
- const logger7 = getLogger("http");
2889
+ const logger7 = getLogger2("http");
2890
2890
  const adapter = new HandlerAdapter(logger7, this.#webHandler);
2891
2891
  if (this.#storage !== void 0) adapter.storage = this.#storage;
2892
2892
  adapter.enableLoggingRequestDetails = false;
@@ -2969,7 +2969,7 @@ var ExtendedWebSocket = class extends WebSocket {
2969
2969
  }
2970
2970
  connected;
2971
2971
  };
2972
- var logger5 = getLogger("ws");
2972
+ var logger5 = getLogger2("ws");
2973
2973
  function upgradeStrategy(path, route, wss, onSocketError) {
2974
2974
  return (exchange) => {
2975
2975
  const { logPrefix, request } = exchange;
@@ -3081,7 +3081,7 @@ async function initRoute(path, route, endpoint, storage, onSocketError) {
3081
3081
  }
3082
3082
 
3083
3083
  // src/server.ts
3084
- var logger6 = getLogger("app");
3084
+ var logger6 = getLogger2("app");
3085
3085
  function secureContextOptions(ssl) {
3086
3086
  const options = {};
3087
3087
  if (ssl.key) options.key = readFileSync(ssl.key);
@@ -3181,7 +3181,7 @@ var Factory = async (options) => {
3181
3181
  storage: new AsyncLocalStorage4(),
3182
3182
  sockets: /* @__PURE__ */ new Map()
3183
3183
  };
3184
- const gw = IOGateway7.Factory({ ...options.gateway });
3184
+ const gw = IOGateway6.Factory({ ...options.gateway });
3185
3185
  if (options.gateway) {
3186
3186
  const config = options.gateway;
3187
3187
  await configure(async (configurer) => {
@@ -3199,7 +3199,8 @@ var Factory = async (options) => {
3199
3199
  const serverP = new Promise((resolve, reject) => {
3200
3200
  const server2 = createServer({
3201
3201
  IncomingMessage: ExtendedHttpIncomingMessage,
3202
- ServerResponse: ExtendedHttpServerResponse
3202
+ ServerResponse: ExtendedHttpServerResponse,
3203
+ ...options.http
3203
3204
  }, listener);
3204
3205
  server2.on("error", (e) => {
3205
3206
  if (e["code"] === "EADDRINUSE") {