optio-dashboard 0.1.0

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.
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Optio Dashboard</title>
7
+ <script type="module" crossorigin src="/assets/index-B-yEPWQd.js"></script>
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ </body>
12
+ </html>
@@ -0,0 +1,9 @@
1
+ export interface DashboardConfig {
2
+ mongodbUrl: string;
3
+ redisUrl: string;
4
+ port: number;
5
+ password: string;
6
+ verbose: boolean;
7
+ }
8
+ export declare function startServer(config: DashboardConfig): Promise<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
9
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,eAAe,oUA8GxD"}
package/dist/server.js ADDED
@@ -0,0 +1,113 @@
1
+ import Fastify from 'fastify';
2
+ import fastifyStatic from '@fastify/static';
3
+ import { MongoClient } from 'mongodb';
4
+ import { Redis } from 'ioredis';
5
+ import { registerOptioApi } from 'optio-api/fastify';
6
+ import { fromNodeHeaders } from 'better-auth/node';
7
+ import { createAuth, upsertAdminUser } from './auth-server.js';
8
+ import path from 'path';
9
+ import { fileURLToPath } from 'url';
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+ export async function startServer(config) {
12
+ const app = Fastify({
13
+ logger: {
14
+ transport: {
15
+ target: 'pino-pretty',
16
+ options: { translateTime: 'HH:MM:ss', ignore: 'pid,hostname' },
17
+ },
18
+ },
19
+ disableRequestLogging: !config.verbose,
20
+ });
21
+ // Connect to MongoDB
22
+ app.log.info(`Connecting to MongoDB: ${config.mongodbUrl}`);
23
+ const mongoClient = new MongoClient(config.mongodbUrl);
24
+ await mongoClient.connect();
25
+ const dbName = new URL(config.mongodbUrl).pathname.slice(1) || 'optio';
26
+ const db = mongoClient.db(dbName);
27
+ // Connect to Redis
28
+ app.log.info(`Connecting to Redis: ${config.redisUrl}`);
29
+ const redis = new Redis(config.redisUrl);
30
+ // Set up Better Auth (use the password as the signing secret so
31
+ // changing the password automatically invalidates all sessions)
32
+ const baseURL = process.env.BETTER_AUTH_URL ?? `http://localhost:${config.port}`;
33
+ const auth = createAuth(db, config.password, baseURL);
34
+ await upsertAdminUser(auth, config.password);
35
+ // Mount Better Auth routes at /api/auth/*
36
+ app.route({
37
+ method: ['GET', 'POST'],
38
+ url: '/api/auth/*',
39
+ async handler(request, reply) {
40
+ const url = new URL(request.url, `http://${request.headers.host}`);
41
+ const headers = fromNodeHeaders(request.headers);
42
+ const req = new Request(url.toString(), {
43
+ method: request.method,
44
+ headers,
45
+ ...(request.body ? { body: JSON.stringify(request.body) } : {}),
46
+ });
47
+ const response = await auth.handler(req);
48
+ reply.status(response.status);
49
+ response.headers.forEach((value, key) => reply.header(key, value));
50
+ const body = await response.text();
51
+ reply.send(body || null);
52
+ },
53
+ });
54
+ // Register Optio API routes with session-based authenticate
55
+ await registerOptioApi(app, {
56
+ mongoClient,
57
+ redis,
58
+ verbose: config.verbose,
59
+ authenticate: async (request) => {
60
+ const url = request.url;
61
+ // Only enforce auth on Optio API routes.
62
+ // Static files (served by fastify-static) and Better Auth routes
63
+ // (/api/auth/*) must pass through — the client-side auth gate and
64
+ // Better Auth itself handle those respectively.
65
+ if (!url.startsWith('/api/') || url.startsWith('/api/auth/')) {
66
+ return 'operator';
67
+ }
68
+ const session = await auth.api.getSession({
69
+ headers: fromNodeHeaders(request.headers),
70
+ });
71
+ return session ? 'operator' : null;
72
+ },
73
+ });
74
+ // Serve the pre-built React app
75
+ await app.register(fastifyStatic, {
76
+ root: path.join(__dirname, 'public'),
77
+ wildcard: false,
78
+ });
79
+ // SPA fallback: serve index.html for all non-API, non-file routes
80
+ app.setNotFoundHandler(async (request, reply) => {
81
+ if (request.url.startsWith('/api/')) {
82
+ reply.code(404).send({ message: 'Not found' });
83
+ return;
84
+ }
85
+ return reply.sendFile('index.html');
86
+ });
87
+ // Graceful shutdown
88
+ let shuttingDown = false;
89
+ const shutdown = async () => {
90
+ if (shuttingDown) {
91
+ process.exit(1);
92
+ }
93
+ shuttingDown = true;
94
+ app.log.info('Shutting down...');
95
+ // Force exit after 3 seconds if app.close() hangs (e.g., open SSE connections)
96
+ const forceTimer = setTimeout(() => process.exit(0), 3000);
97
+ forceTimer.unref();
98
+ try {
99
+ await app.close();
100
+ redis.disconnect();
101
+ await mongoClient.close();
102
+ }
103
+ catch {
104
+ // Ignore close errors during shutdown
105
+ }
106
+ process.exit(0);
107
+ };
108
+ process.on('SIGTERM', shutdown);
109
+ process.on('SIGINT', shutdown);
110
+ await app.listen({ port: config.port, host: '0.0.0.0' });
111
+ return app;
112
+ }
113
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,m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AAO,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,oBAAoB;IACpB,IAAI,YAAY,GAAG,KAAK,CAAC;IACzB,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,YAAY,GAAG,IAAI,CAAC;QACpB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACjC,+EAA+E;QAC/E,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAC3D,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;YAClB,KAAK,CAAC,UAAU,EAAE,CAAC;YACnB,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC;YACP,sCAAsC;QACxC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE/B,MAAM,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAEzD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "optio-dashboard",
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "description": "Standalone optio dashboard app — install and run for a ready-to-use process management UI.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/deai-network/optio.git",
9
+ "directory": "packages/optio-dashboard"
10
+ },
11
+ "homepage": "https://github.com/deai-network/optio/tree/main/packages/optio-dashboard#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/deai-network/optio/issues"
14
+ },
15
+ "author": "Kristof Csillag <kristof.csillag@deai-labs.com>",
16
+ "type": "module",
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "bin": {
23
+ "optio-dashboard": "./dist/cli.js"
24
+ },
25
+ "dependencies": {
26
+ "@ant-design/icons": "^5.6.0",
27
+ "@fastify/static": "^8.0.0",
28
+ "@tanstack/react-query": "^5.95.2",
29
+ "@ts-rest/core": "^3.51.0",
30
+ "@ts-rest/fastify": "^3.51.0",
31
+ "@ts-rest/react-query": "^3.51.0",
32
+ "antd": "^5.29.3",
33
+ "better-auth": "^1.6.2",
34
+ "fastify": "^5.2.0",
35
+ "i18next": "^25.10.10",
36
+ "ioredis": "^5.4.0",
37
+ "mongodb": "^6.12.0",
38
+ "pino-pretty": "^13.1.3",
39
+ "react": "^19.2.4",
40
+ "react-dom": "^19.2.4",
41
+ "react-i18next": "^17.0.0",
42
+ "zod": "^3.25.76",
43
+ "optio-api": "0.1.0",
44
+ "optio-ui": "0.1.0",
45
+ "optio-contracts": "0.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^22.0.0",
49
+ "@types/react": "^19.0.0",
50
+ "@types/react-dom": "^19.0.0",
51
+ "@vitejs/plugin-react": "^4.0.0",
52
+ "typescript": "^5.7.0",
53
+ "vite": "^6.0.0"
54
+ },
55
+ "scripts": {
56
+ "dev": "vite",
57
+ "dev:playground": "vite --config playground/vite.config.ts",
58
+ "build": "vite build && tsc -p tsconfig.json",
59
+ "build:app": "vite build",
60
+ "build:server": "tsc -p tsconfig.json",
61
+ "start": "node dist/cli.js"
62
+ }
63
+ }