@dashwire/server 0.1.0 → 0.3.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.
Files changed (39) hide show
  1. package/dist/auth.service.d.ts +16 -0
  2. package/dist/auth.service.js +65 -0
  3. package/dist/db/client.d.ts +2 -0
  4. package/{src/db/client.ts → dist/db/client.js} +1 -4
  5. package/dist/db/schema.d.ts +570 -0
  6. package/dist/db/schema.js +46 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +114 -0
  9. package/dist/logs.service.d.ts +1 -0
  10. package/dist/logs.service.js +14 -0
  11. package/dist/overview.service.d.ts +12 -0
  12. package/dist/overview.service.js +20 -0
  13. package/dist/projects.service.d.ts +40 -0
  14. package/dist/projects.service.js +180 -0
  15. package/dist/realtime/dashboardNamespace.d.ts +2 -0
  16. package/dist/realtime/dashboardNamespace.js +26 -0
  17. package/dist/realtime/sdkNamespace.d.ts +2 -0
  18. package/dist/realtime/sdkNamespace.js +69 -0
  19. package/dist/routes/auth.d.ts +2 -0
  20. package/dist/routes/auth.js +76 -0
  21. package/dist/routes/overview.d.ts +2 -0
  22. package/dist/routes/overview.js +21 -0
  23. package/dist/routes/projects.d.ts +3 -0
  24. package/dist/routes/projects.js +66 -0
  25. package/package.json +5 -4
  26. package/dashwire.db +0 -0
  27. package/drizzle.config.ts +0 -10
  28. package/src/auth.service.ts +0 -76
  29. package/src/db/schema.ts +0 -52
  30. package/src/index.ts +0 -44
  31. package/src/logs.service.ts +0 -15
  32. package/src/overview.service.ts +0 -28
  33. package/src/projects.service.ts +0 -204
  34. package/src/realtime/dashboardNamespace.ts +0 -36
  35. package/src/realtime/sdkNamespace.ts +0 -88
  36. package/src/routes/auth.ts +0 -90
  37. package/src/routes/overview.ts +0 -27
  38. package/src/routes/projects.ts +0 -93
  39. package/tsconfig.json +0 -11
@@ -1,90 +0,0 @@
1
- import type { FastifyInstance } from "fastify";
2
- import { hasAnyAdmin, createAdminUser, authenticateUser, createUserRecord, verifyAuthToken, listUsers, deleteUser } from "../auth.service.js";
3
-
4
- export function authRoutes(app: FastifyInstance) {
5
- app.get("/api/auth/status", async (_req, reply) => {
6
- return reply.send({ hasAdmin: hasAnyAdmin() });
7
- });
8
-
9
- app.post<{ Body: { username?: string; password?: string } }>(
10
- "/api/auth/setup",
11
- async (req, reply) => {
12
- const { username, password } = req.body || {};
13
- if (!username || !password) {
14
- return reply.code(400).send({ error: "Gebruikersnaam en wachtwoord zijn verplicht." });
15
- }
16
- try {
17
- if (hasAnyAdmin()) {
18
- return reply.code(400).send({ error: "Setup is al voltooid." });
19
- }
20
- const token = createAdminUser(username, password);
21
- return reply.send({ token });
22
- } catch (err: any) {
23
- return reply.code(400).send({ error: err.message });
24
- }
25
- }
26
- );
27
-
28
- app.post<{ Body: { username?: string; password?: string } }>(
29
- "/api/auth/login",
30
- async (req, reply) => {
31
- const { username, password } = req.body || {};
32
- if (!username || !password) {
33
- return reply.code(400).send({ error: "Vul alle velden in." });
34
- }
35
- try {
36
- const token = authenticateUser(username, password);
37
- return reply.send({ token });
38
- } catch (err: any) {
39
- return reply.code(401).send({ error: err.message });
40
- }
41
- }
42
- );
43
-
44
- app.get("/api/users", async (req, reply) => {
45
- const authHeader = req.headers.authorization;
46
- const token = authHeader?.startsWith("Bearer ") ? authHeader.substring(7) : "";
47
- const verified = verifyAuthToken(token);
48
- if (!verified || verified.role !== "admin") {
49
- return reply.code(403).send({ error: "Toegang geweigerd. Alleen voor admins." });
50
- }
51
- return reply.send(listUsers());
52
- });
53
-
54
- app.post<{ Body: { username: string; password: string; role?: "admin" | "user" } }>(
55
- "/api/users",
56
- async (req, reply) => {
57
- const authHeader = req.headers.authorization;
58
- const token = authHeader?.startsWith("Bearer ") ? authHeader.substring(7) : "";
59
- const verified = verifyAuthToken(token);
60
- if (!verified || verified.role !== "admin") {
61
- return reply.code(403).send({ error: "Toegang geweigerd. Alleen voor admins." });
62
- }
63
- try {
64
- const { username, password, role } = req.body;
65
- const newUser = createUserRecord(username, password, role || "user");
66
- return reply.send(newUser);
67
- } catch (err: any) {
68
- return reply.code(400).send({ error: err.message });
69
- }
70
- }
71
- );
72
-
73
- // --- AANPASSING IN: de DELETE /api/users/:userId route ---
74
- app.delete<{ Params: { userId: string } }>("/api/users/:userId", async (req, reply) => {
75
- const authHeader = req.headers.authorization;
76
- const token = authHeader?.startsWith("Bearer ") ? authHeader.substring(7) : "";
77
- const verified = verifyAuthToken(token);
78
-
79
- if (!verified || verified.role !== "admin") {
80
- return reply.code(403).send({ error: "Toegang geweigerd." });
81
- }
82
-
83
- try {
84
- deleteUser(req.params.userId, verified.id);
85
- return reply.send({ success: true });
86
- } catch (err: any) {
87
- return reply.code(400).send({ error: err.message });
88
- }
89
- });
90
- }
@@ -1,27 +0,0 @@
1
- import type { FastifyInstance } from "fastify";
2
- import { getOverviewConfig, setOverviewConfig } from "../overview.service.js";
3
-
4
- function requireAdmin(req: any, reply: any): boolean {
5
- const token = req.headers["x-admin-token"];
6
- const expected = process.env.DASHWIRE_ADMIN_TOKEN;
7
- if (!expected || token !== expected) {
8
- reply.status(401).send({ error: "unauthorized" });
9
- return false;
10
- }
11
- return true;
12
- }
13
-
14
- export function overviewRoutes(app: FastifyInstance) {
15
- app.get("/api/overview-config", async () => {
16
- return getOverviewConfig();
17
- });
18
-
19
- app.put<{ Body: { entries: { projectId: string; capabilityPath: string; order: number }[] } }>(
20
- "/api/overview-config",
21
- async (req, reply) => {
22
- if (!requireAdmin(req, reply)) return;
23
- setOverviewConfig(req.body.entries);
24
- return reply.send({ ok: true });
25
- },
26
- );
27
- }
@@ -1,93 +0,0 @@
1
- import type { FastifyInstance } from "fastify";
2
- import type { Server as SocketServer } from "socket.io";
3
- import { registerProject, listProjects, getProject, listAllTokens, createTokenForProject, setTokenActiveStatus, deleteToken } from "../projects.service.js";
4
- import type { DashboardStructure } from "@dashwire/core";
5
- import { logs } from "../db/schema.js";
6
- import { desc } from "drizzle-orm/sql/expressions/select";
7
- import { eq } from "drizzle-orm/sql/expressions/conditions";
8
- import { db } from "../db/client.js";
9
-
10
- export function projectRoutes(app: FastifyInstance, io: SocketServer) {
11
- app.post<{ Params: { id: string }; Body: { projectName: string; structure: DashboardStructure } }>(
12
- "/api/projects/:id/register",
13
- async (req, reply) => {
14
- const { id: projectId } = req.params;
15
- const authHeader = req.headers.authorization;
16
- const authToken = authHeader?.startsWith("Bearer ") ? authHeader.substring(7) : undefined;
17
- const { projectName, structure } = req.body;
18
-
19
- try {
20
- const result = registerProject(projectId, projectName, structure, authToken);
21
- return reply.send(result);
22
- } catch (err: any) {
23
- return reply.code(401).send({ error: err.message });
24
- }
25
- }
26
- );
27
-
28
- app.get("/api/projects", async (_req, reply) => {
29
- return reply.send(listProjects());
30
- });
31
-
32
- app.get("/api/projects/tokens/all", async (_req, reply) => {
33
- return reply.send(listAllTokens());
34
- });
35
-
36
- app.post<{ Body: { label?: string } }>(
37
- "/api/projects/tokens/new",
38
- async (req, reply) => {
39
- const body = req.body as { label?: string };
40
- try {
41
- const token = createTokenForProject(body?.label);
42
- return reply.send({ token });
43
- } catch (err: any) {
44
- return reply.code(400).send({ error: err.message });
45
- }
46
- }
47
- );
48
-
49
- app.patch<{ Params: { tokenId: string }; Body: { active: boolean } }>(
50
- "/api/projects/tokens/:tokenId",
51
- async (req, reply) => {
52
- const { tokenId } = req.params;
53
- const { active } = req.body;
54
- setTokenActiveStatus(tokenId, active);
55
- return reply.send({ success: true });
56
- }
57
- );
58
-
59
- app.delete<{ Params: { tokenId: string } }>(
60
- "/api/projects/tokens/:tokenId",
61
- async (req, reply) => {
62
- const { tokenId } = req.params;
63
- deleteToken(tokenId);
64
- return reply.send({ success: true });
65
- }
66
- );
67
-
68
- app.get<{ Params: { id: string } }>("/api/projects/:id", async (req, reply) => {
69
- const { id: projectId } = req.params;
70
- const project = getProject(projectId);
71
- if (!project) {
72
- return reply.code(404).send({ error: "Project niet gevonden" });
73
- }
74
- return reply.send(project);
75
- });
76
-
77
- app.get<{ Params: { id: string }; Querystring: { limit?: string } }>(
78
- "/api/projects/:id/logs",
79
- async (req, reply) => {
80
- const { id: projectId } = req.params;
81
- const limit = Number(req.query.limit ?? 50);
82
-
83
- const projectLogs = db.select()
84
- .from(logs)
85
- .where(eq(logs.projectId, projectId))
86
- .orderBy(desc(logs.id))
87
- .limit(limit)
88
- .all();
89
-
90
- return reply.send(projectLogs.reverse());
91
- }
92
- );
93
- }
package/tsconfig.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src",
6
- "module": "NodeNext",
7
- "moduleResolution": "NodeNext",
8
- "types": ["node"]
9
- },
10
- "include": ["src"]
11
- }