@interopio/gateway-server 0.6.0-beta → 0.6.1-beta

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
@@ -1257,9 +1257,9 @@ var localIp = (() => {
1257
1257
  return a.length > 0 ? a[0] : void 0;
1258
1258
  }
1259
1259
  const addresses = Object.values(networkInterfaces()).flatMap((details) => {
1260
- return (details ?? []).filter((info) => info.family === "IPv4");
1261
- }).reduce((acc, info) => {
1262
- acc[info.internal ? "internal" : "external"].push(info);
1260
+ return (details ?? []).filter((info2) => info2.family === "IPv4");
1261
+ }).reduce((acc, info2) => {
1262
+ acc[info2.internal ? "internal" : "external"].push(info2);
1263
1263
  return acc;
1264
1264
  }, { internal: [], external: [] });
1265
1265
  return (first(addresses.internal) ?? first(addresses.external))?.address;
@@ -1479,16 +1479,17 @@ function regexifyOriginFilters(originFilters) {
1479
1479
  }
1480
1480
 
1481
1481
  // src/server/server-header.ts
1482
+ import info from "@interopio/gateway-server/package.json" with { type: "json" };
1482
1483
  var serverHeader = (server) => {
1483
- const enabled = typeof server === "string";
1484
+ server ??= `${info.name} - v${info.version}`;
1484
1485
  return async ({ response }, next) => {
1485
- if (server != false && !response.headers.has("server")) {
1486
+ if (server !== false && !response.headers.has("server")) {
1486
1487
  response.headers.set("Server", server);
1487
1488
  }
1488
1489
  await next();
1489
1490
  };
1490
1491
  };
1491
- var server_header_default = (server = "gateway-server") => serverHeader(server);
1492
+ var server_header_default = (server) => serverHeader(server);
1492
1493
 
1493
1494
  // src/app/route.ts
1494
1495
  function findSocketRoute({ request }, { sockets: routes3 }) {
@@ -2740,8 +2741,9 @@ async function createCorsConfigSource(context) {
2740
2741
  // src/app/auth.ts
2741
2742
  function createSecurityConfig(context) {
2742
2743
  const authorize = [];
2744
+ const defaultAccess = { access: context.authConfig?.type !== "none" ? "authenticated" : "permitted" };
2743
2745
  for (const [path, route] of context.sockets) {
2744
- const rule = route.authorize ?? { access: "authenticated" };
2746
+ const rule = route.authorize ?? defaultAccess;
2745
2747
  let matcher = pattern(path, { method: "GET" });
2746
2748
  matcher = and([upgradeMatcher, matcher]);
2747
2749
  authorize.push([matcher, rule]);
@@ -2752,7 +2754,7 @@ function createSecurityConfig(context) {
2752
2754
  if (context.authorize.length > 0) {
2753
2755
  authorize.push(...context.authorize);
2754
2756
  }
2755
- authorize.push(["any-exchange", { access: "authenticated" }]);
2757
+ authorize.push(["any-exchange", defaultAccess]);
2756
2758
  return {
2757
2759
  authorize,
2758
2760
  basic: {
@@ -2796,23 +2798,23 @@ async function createListener(middleware, context, onSocketError) {
2796
2798
  if ((request.method === "GET" || request.method === "CONNECT") && upgradeMatchResult.match) {
2797
2799
  const socket = request.socket;
2798
2800
  const host = request.host;
2799
- const info = socketKey(request._req.socket);
2801
+ const info2 = socketKey(request._req.socket);
2800
2802
  if (route.wss) {
2801
2803
  socket.removeListener("error", onSocketError);
2802
2804
  const wss = route.wss;
2803
2805
  if (route.maxConnections !== void 0 && wss.clients?.size >= route.maxConnections) {
2804
- logger10.warn(`${info} dropping ws connection request from ${host} on ${path}. max connections exceeded.`);
2806
+ logger10.warn(`${info2} dropping ws connection request from ${host} on ${path}. max connections exceeded.`);
2805
2807
  socket.destroy();
2806
2808
  return;
2807
2809
  }
2808
2810
  const origin = request.headers.one("origin");
2809
2811
  if (!acceptsOrigin(origin, route.originFilters)) {
2810
- logger10.info(`${info} dropping ws connection request from ${host} on ${path}. origin ${origin ?? "<missing>"}`);
2812
+ logger10.info(`${info2} dropping ws connection request from ${host} on ${path}. origin ${origin ?? "<missing>"}`);
2811
2813
  socket.destroy();
2812
2814
  return;
2813
2815
  }
2814
2816
  if (logger10.enabledFor("debug")) {
2815
- logger10.debug(`${info} accepted new ws connection request from ${host} on ${path}`);
2817
+ logger10.debug(`${info2} accepted new ws connection request from ${host} on ${path}`);
2816
2818
  }
2817
2819
  wss.handleUpgrade(request._req, socket, request._req["_upgradeHead"], (ws) => {
2818
2820
  response._res["_header"] = true;
@@ -2822,7 +2824,7 @@ async function createListener(middleware, context, onSocketError) {
2822
2824
  wss.emit("connection", ws, request._req);
2823
2825
  });
2824
2826
  } else {
2825
- logger10.warn(`${info} rejected upgrade request from ${host} on ${path}`);
2827
+ logger10.warn(`${info2} rejected upgrade request from ${host} on ${path}`);
2826
2828
  socket.destroy();
2827
2829
  }
2828
2830
  } else {
@@ -2976,12 +2978,12 @@ var Factory = async (options) => {
2976
2978
  }
2977
2979
  });
2978
2980
  server2.on("listening", async () => {
2979
- const info = server2.address();
2981
+ const info2 = server2.address();
2980
2982
  for (const [path, route] of context.sockets) {
2981
2983
  try {
2982
2984
  logger10.info(`creating ws server for [${path}]. max connections: ${route.maxConnections ?? "<unlimited>"}, origin filters: ${route.originFilters ? JSON.stringify(route.originFilters, regexAwareReplacer) : "<none>"}`);
2983
2985
  const wss = new WebSocketServer({ noServer: true });
2984
- const endpoint = `${ssl ? "wss" : "ws"}://${localIp}:${info.port}${path}`;
2986
+ const endpoint = `${ssl ? "wss" : "ws"}://${localIp}:${info2.port}${path}`;
2985
2987
  const handler = await route.factory({ endpoint, wss, storage: context.storage });
2986
2988
  const pingInterval = route.ping;
2987
2989
  if (pingInterval) {
@@ -3004,7 +3006,7 @@ var Factory = async (options) => {
3004
3006
  logger10.warn(`failed to init route ${path}`, e);
3005
3007
  }
3006
3008
  }
3007
- logger10.info(`http server listening on ${info.address}:${info.port}`);
3009
+ logger10.info(`http server listening on ${info2.address}:${info2.port}`);
3008
3010
  resolve(server2);
3009
3011
  });
3010
3012
  server2.on("upgrade", (req, socket, head) => {