@naisys/supervisor 3.0.0-beta.7 → 3.0.0-beta.9

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.
@@ -40,7 +40,7 @@
40
40
  <meta name="format-detection" content="telephone=no" />
41
41
 
42
42
  <title>NAISYS Supervisor</title>
43
- <script type="module" crossorigin src="/supervisor/assets/index-BBrK4ItN.js"></script>
43
+ <script type="module" crossorigin src="/supervisor/assets/index-WzoDF0aQ.js"></script>
44
44
  <link rel="stylesheet" crossorigin href="/supervisor/assets/index-CKg0vgt5.css">
45
45
  </head>
46
46
  <body>
@@ -5,22 +5,24 @@ import { registerAuthMiddleware } from "./auth-middleware.js";
5
5
  * for the Supervisor service.
6
6
  */
7
7
  export async function registerApiReference(fastify) {
8
- await fastify.register(scalarReference, {
9
- routePrefix: "/supervisor/api-reference",
10
- configuration: {
11
- spec: { url: "/api/supervisor/openapi.json" },
12
- theme: "kepler",
13
- },
14
- });
15
- // Wrap in a scoped plugin so registerAuthMiddleware gates access
16
- // (respects PUBLIC_READ for GETs, requires auth otherwise)
8
+ // Both the reference page and spec endpoint are inside the auth scope.
9
+ // isPublicRoute treats /supervisor/api-reference as non-public (starts
10
+ // with /supervisor/api), so PUBLIC_READ=true allows GET access while
11
+ // PUBLIC_READ=false requires authentication.
17
12
  await fastify.register(async (scope) => {
18
13
  registerAuthMiddleware(scope);
19
- scope.get("/api/supervisor/openapi.json", () => {
14
+ await scope.register(scalarReference, {
15
+ routePrefix: "/supervisor/api-reference",
16
+ configuration: {
17
+ spec: { url: "/supervisor/api/openapi.json" },
18
+ theme: "kepler",
19
+ },
20
+ });
21
+ scope.get("/supervisor/api/openapi.json", () => {
20
22
  const spec = fastify.swagger();
21
23
  const filteredPaths = {};
22
24
  for (const [path, value] of Object.entries(spec.paths || {})) {
23
- if (path.startsWith("/api/supervisor/")) {
25
+ if (path.startsWith("/supervisor/api/")) {
24
26
  filteredPaths[path] = value;
25
27
  }
26
28
  }
@@ -3,17 +3,17 @@ import { extractBearerToken, hashToken, SESSION_COOKIE_NAME, } from "@naisys/com
3
3
  import { findAgentByApiKey } from "@naisys/hub-database";
4
4
  import { findSession, findUserByApiKey } from "@naisys/supervisor-database";
5
5
  import { createUserForAgent, getUserByUuid, getUserPermissions, } from "./services/userService.js";
6
- const PUBLIC_PREFIXES = ["/api/supervisor/auth/login"];
6
+ const PUBLIC_PREFIXES = ["/supervisor/api/auth/login"];
7
7
  export const authCache = new AuthCache();
8
8
  function isPublicRoute(url) {
9
- if (url === "/api/supervisor/" || url === "/api/supervisor")
9
+ if (url === "/supervisor/api/" || url === "/supervisor/api")
10
10
  return true;
11
11
  for (const prefix of PUBLIC_PREFIXES) {
12
12
  if (url.startsWith(prefix))
13
13
  return true;
14
14
  }
15
15
  // Non-supervisor-API paths (static files, ERP routes, etc.)
16
- if (!url.startsWith("/api/supervisor"))
16
+ if (!url.startsWith("/supervisor/api"))
17
17
  return true;
18
18
  return false;
19
19
  }
package/dist/hateoas.js CHANGED
@@ -1,4 +1,4 @@
1
- export const API_PREFIX = "/api/supervisor";
1
+ export const API_PREFIX = "/supervisor/api";
2
2
  export function selfLink(path, title) {
3
3
  return { rel: "self", href: `${API_PREFIX}${path}`, title };
4
4
  }
@@ -1,5 +1,5 @@
1
1
  import { PermissionEnum } from "@naisys/supervisor-shared";
2
- const API_PREFIX = "/api/supervisor";
2
+ const API_PREFIX = "/supervisor/api";
3
3
  export default function rootRoutes(fastify, _options) {
4
4
  fastify.get("/", {
5
5
  schema: {
@@ -1,11 +1,11 @@
1
- import { Server as SocketIOServer } from "socket.io";
2
1
  import { extractBearerToken } from "@naisys/common-node";
2
+ import { Server as SocketIOServer } from "socket.io";
3
3
  import { resolveUserFromApiKey, resolveUserFromToken, } from "../auth-middleware.js";
4
4
  import { isHubConnected } from "./hubConnectionService.js";
5
5
  let io = null;
6
6
  export function initBrowserSocket(httpServer, isProd) {
7
7
  io = new SocketIOServer(httpServer, {
8
- path: "/api/supervisor/ws",
8
+ path: "/supervisor/api/ws",
9
9
  cors: isProd
10
10
  ? undefined
11
11
  : { origin: ["http://localhost:3002"], credentials: true },
@@ -41,7 +41,11 @@ export function obfuscateLogs(data) {
41
41
  ...log,
42
42
  message: obfuscateText(log.message),
43
43
  attachment: log.attachment
44
- ? { id: "no-access", filename: obfuscateFilename(log.attachment.filename), fileSize: 0 }
44
+ ? {
45
+ id: "no-access",
46
+ filename: obfuscateFilename(log.attachment.filename),
47
+ fileSize: 0,
48
+ }
45
49
  : undefined,
46
50
  })),
47
51
  };
@@ -96,7 +96,7 @@ export const startServer = async (startupType, plugins = [], hubPort) => {
96
96
  await fastify.register(rateLimit, {
97
97
  max: 500,
98
98
  timeWindow: "1 minute",
99
- allowList: (request) => !request.url.startsWith("/api/"),
99
+ allowList: (request) => !request.url.match(/^\/(supervisor|erp)\/api\//),
100
100
  });
101
101
  await fastify.register(multipart, {
102
102
  limits: { fileSize: MAX_ATTACHMENT_SIZE },
@@ -126,9 +126,9 @@ export const startServer = async (startupType, plugins = [], hubPort) => {
126
126
  fastify.get("/", { schema: { hide: true } }, async (_request, reply) => {
127
127
  return reply.redirect("/supervisor/");
128
128
  });
129
- fastify.register(apiRoutes, { prefix: "/api/supervisor" });
129
+ fastify.register(apiRoutes, { prefix: "/supervisor/api" });
130
130
  // Public endpoint to expose client configuration (plugins, publicRead, etc.)
131
- fastify.get("/api/supervisor/client-config", { schema: { hide: true } }, () => ({
131
+ fastify.get("/supervisor/api/client-config", { schema: { hide: true } }, () => ({
132
132
  plugins,
133
133
  publicRead: process.env.PUBLIC_READ === "true",
134
134
  permissions: PermissionEnum.options,
@@ -148,7 +148,7 @@ export const startServer = async (startupType, plugins = [], hubPort) => {
148
148
  prefix: "/supervisor/",
149
149
  });
150
150
  fastify.setNotFoundHandler((request, reply) => {
151
- if (request.url.startsWith("/api/")) {
151
+ if (request.url.match(/^\/(supervisor|erp)\/api\//)) {
152
152
  reply.code(404).send({ error: "API endpoint not found" });
153
153
  }
154
154
  else if (request.url.startsWith("/supervisor")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naisys/supervisor",
3
- "version": "3.0.0-beta.7",
3
+ "version": "3.0.0-beta.9",
4
4
  "description": "NAISYS Supervisor - Web UI for monitoring agents, logs, and messaging",
5
5
  "type": "module",
6
6
  "main": "dist/supervisorServer.js",
@@ -33,7 +33,7 @@
33
33
  "!dist/**/*.test.*"
34
34
  ],
35
35
  "peerDependencies": {
36
- "@naisys/erp": "3.0.0-beta.7"
36
+ "@naisys/erp": "3.0.0-beta.9"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@naisys/erp": {
@@ -47,12 +47,12 @@
47
47
  "@fastify/rate-limit": "^10.3.0",
48
48
  "@fastify/static": "^9.0.0",
49
49
  "@fastify/swagger": "^9.7.0",
50
- "@naisys/supervisor-shared": "3.0.0-beta.7",
51
- "@naisys/common": "3.0.0-beta.7",
52
- "@naisys/common-node": "3.0.0-beta.7",
53
- "@naisys/hub-database": "3.0.0-beta.7",
54
- "@naisys/hub-protocol": "3.0.0-beta.7",
55
- "@naisys/supervisor-database": "3.0.0-beta.7",
50
+ "@naisys/supervisor-shared": "3.0.0-beta.9",
51
+ "@naisys/common": "3.0.0-beta.9",
52
+ "@naisys/common-node": "3.0.0-beta.9",
53
+ "@naisys/hub-database": "3.0.0-beta.9",
54
+ "@naisys/hub-protocol": "3.0.0-beta.9",
55
+ "@naisys/supervisor-database": "3.0.0-beta.9",
56
56
  "@scalar/fastify-api-reference": "^1.48.7",
57
57
  "@types/archiver": "^7.0.0",
58
58
  "archiver": "^7.0.1",