@dashwire/server 0.1.0 → 0.2.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 +2 -0
  8. package/dist/index.js +35 -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 +4 -3
  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,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
- }