Skip to content

Commit 0605ea2

Browse files
committed
feat: whois endpoint
1 parent 838ffc2 commit 0605ea2

File tree

16 files changed

+1008
-584
lines changed

16 files changed

+1008
-584
lines changed

\

Lines changed: 0 additions & 132 deletions
This file was deleted.

evault.docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ services:
1111
- NEO4J_URI=${NEO4J_URI}
1212
- NEO4J_USER=${NEO4J_USER}
1313
- NEO4J_PASSWORD=${NEO4J_PASSWORD}
14+
- SECRETS_STORE_PATH=/app/secrets/secrets.json
15+
- ENCRYPTION_PASSWORD=${ENCRYPTION_PASSWORD}
16+
- W3ID=${W3ID}
17+
volumes:
18+
- secrets:/app/secrets
1419
networks:
1520
- graphnet
1621
depends_on:
@@ -44,6 +49,7 @@ services:
4449
volumes:
4550
neo4j_data:
4651
neo4j_logs:
52+
secrets:
4753

4854
networks:
4955
graphnet:

infrastructure/evault-core/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424
"vitest": "^3.0.9"
2525
},
2626
"dependencies": {
27-
"@testcontainers/neo4j": "^10.24.2",
2827
"@fastify/swagger": "^8.14.0",
2928
"@fastify/swagger-ui": "^3.0.0",
29+
"@testcontainers/neo4j": "^10.24.2",
3030
"fastify": "^4.26.2",
3131
"graphql": "^16.10.0",
3232
"graphql-type-json": "^0.3.2",
3333
"graphql-voyager": "^2.1.0",
3434
"graphql-yoga": "^5.13.4",
3535
"json-schema": "^0.4.0",
36+
"multiformats": "^13.3.2",
3637
"neo4j-driver": "^5.28.1",
38+
"tweetnacl": "^1.0.3",
3739
"w3id": "workspace:*"
3840
}
3941
}

infrastructure/evault-core/src/evault.ts

Lines changed: 86 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,109 @@
11
import { DbService } from "./db/db.service";
2+
import { LogService } from "./w3id/log-service";
23
import { GraphQLServer } from "./protocol/graphql-server";
34
import { registerHttpRoutes } from "./http/server";
45
import fastify, {
5-
FastifyInstance,
6-
FastifyRequest,
7-
FastifyReply,
6+
FastifyInstance,
7+
FastifyRequest,
8+
FastifyReply,
89
} from "fastify";
910
import { renderVoyagerPage } from "graphql-voyager/middleware";
1011
import { createYoga } from "graphql-yoga";
1112
import dotenv from "dotenv";
1213
import path from "path";
13-
import neo4j from "neo4j-driver";
14+
import neo4j, { Driver } from "neo4j-driver";
15+
import { W3ID } from "./w3id/w3id";
1416

1517
dotenv.config({ path: path.resolve(__dirname, "../../../.env") });
1618

1719
class EVault {
18-
server: FastifyInstance;
19-
graphqlServer: GraphQLServer;
20-
21-
constructor() {
22-
const uri = process.env.NEO4J_URI || "bolt://localhost:7687";
23-
const user = process.env.NEO4J_USER || "neo4j";
24-
const password = process.env.NEO4J_PASSWORD || "neo4j";
25-
26-
if (
27-
!process.env.NEO4J_URI ||
28-
!process.env.NEO4J_USER ||
29-
!process.env.NEO4J_PASSWORD
30-
) {
31-
console.warn(
32-
"Using default Neo4j connection parameters. Set NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD environment variables for custom configuration.",
33-
);
34-
}
35-
36-
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
37-
const dbService = new DbService(driver);
38-
this.graphqlServer = new GraphQLServer(dbService);
39-
40-
// Create Fastify server
41-
this.server = fastify({
42-
logger: true,
43-
});
20+
server: FastifyInstance;
21+
graphqlServer: GraphQLServer;
22+
logService: LogService;
23+
driver: Driver;
24+
25+
constructor() {
26+
const uri = process.env.NEO4J_URI || "bolt://localhost:7687";
27+
const user = process.env.NEO4J_USER || "neo4j";
28+
const password = process.env.NEO4J_PASSWORD || "neo4j";
29+
30+
if (
31+
!process.env.NEO4J_URI ||
32+
!process.env.NEO4J_USER ||
33+
!process.env.NEO4J_PASSWORD
34+
) {
35+
console.warn(
36+
"Using default Neo4j connection parameters. Set NEO4J_URI, NEO4J_USER, and NEO4J_PASSWORD environment variables for custom configuration."
37+
);
4438
}
4539

46-
async initialize() {
47-
// Register HTTP routes
48-
await registerHttpRoutes(this.server);
40+
this.driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
4941

50-
// Create Yoga instance with the schema from GraphQLServer
51-
const yoga = createYoga({
52-
schema: this.graphqlServer.getSchema(),
53-
graphiql: true,
54-
});
42+
const dbService = new DbService(this.driver);
43+
this.logService = new LogService(this.driver);
44+
this.graphqlServer = new GraphQLServer(dbService);
45+
46+
this.server = fastify({
47+
logger: true,
48+
});
49+
}
50+
51+
async initialize() {
52+
await registerHttpRoutes(this.server);
53+
54+
const w3id = await W3ID.get({
55+
id: process.env.W3ID as string,
56+
driver: this.driver,
57+
password: process.env.ENCRYPTION_PASSWORD,
58+
});
5559

56-
// Mount GraphQL endpoint
57-
this.server.route({
58-
url: "/graphql",
59-
method: ["GET", "POST", "OPTIONS"],
60-
handler: async (req: FastifyRequest, reply: FastifyReply) => {
61-
const response = await yoga.handleNodeRequest(
62-
req.raw,
63-
reply.raw,
64-
);
65-
response.headers.forEach((value, key) => {
66-
reply.header(key, value);
67-
});
68-
reply.status(response.status);
69-
reply.send(response.body);
70-
return reply;
71-
},
60+
const yoga = createYoga({
61+
schema: this.graphqlServer.getSchema(),
62+
graphiql: true,
63+
});
64+
// change
65+
66+
this.server.route({
67+
url: "/graphql",
68+
method: ["GET", "POST", "OPTIONS"],
69+
handler: async (req: FastifyRequest, reply: FastifyReply) => {
70+
const response = await yoga.fetch(req.url, {
71+
method: req.method,
72+
headers: req.headers,
73+
body: req.method === "POST" ? req.body : undefined,
74+
});
75+
reply.status(response.status);
76+
const headers: Record<string, string> = {};
77+
response.headers.forEach((value, key) => {
78+
headers[key] = value;
7279
});
80+
reply.headers(headers);
81+
reply.send(response.body);
82+
return reply;
83+
},
84+
});
7385

74-
// Mount Voyager endpoint
75-
this.server.get(
76-
"/voyager",
77-
(req: FastifyRequest, reply: FastifyReply) => {
78-
reply.type("text/html").send(
79-
renderVoyagerPage({
80-
endpointUrl: "/graphql",
81-
}),
82-
);
83-
},
84-
);
85-
}
86+
// Mount Voyager endpoint
87+
this.server.get("/voyager", (req: FastifyRequest, reply: FastifyReply) => {
88+
reply.type("text/html").send(
89+
renderVoyagerPage({
90+
endpointUrl: "/graphql",
91+
})
92+
);
93+
});
94+
}
8695

87-
async start() {
88-
await this.initialize();
89-
90-
const port = process.env.NOMAD_PORT_http || process.env.PORT || 4000;
91-
92-
await this.server.listen({ port: Number(port), host: "0.0.0.0" });
93-
console.log(`Server started on http://0.0.0.0:${port}`);
94-
console.log(
95-
`GraphQL endpoint available at http://0.0.0.0:${port}/graphql`,
96-
);
97-
console.log(
98-
`GraphQL Voyager available at http://0.0.0.0:${port}/voyager`,
99-
);
100-
console.log(
101-
`API Documentation available at http://0.0.0.0:${port}/documentation`,
102-
);
103-
}
96+
async start() {
97+
await this.initialize();
98+
99+
const port = process.env.NOMAD_PORT_http || process.env.PORT || 4000;
100+
101+
await this.server.listen({ port: Number(port), host: "0.0.0.0" });
102+
console.log(`Server started on http://0.0.0.0:${port}`);
103+
console.log(`GraphQL endpoint available at http://0.0.0.0:${port}/graphql`);
104+
console.log(`GraphQL Voyager available at http://0.0.0.0:${port}/voyager`);
105+
console.log(`API Documentation available at http://0.0.0.0:${port}/docs`);
106+
}
104107
}
105108

106109
const evault = new EVault();

0 commit comments

Comments
 (0)