decentralised message store

feat: xrpc routes

in future we want to use a nicer xrpc server that uses our lexicons as
contracts

serenity d6266274 fffcd95b

Changed files
+43 -1
src
lib
handlers
types
routes
xrpc
_health
systems.gmstn.development.shard.getOwner
+1
src/index.ts
···
const server = await setupServer();
for (const [url, route] of Object.entries(routes)) {
+
console.log("Registering route", url)
if (!route.wsHandler) {
const { handler, method, skipRegistrationCheck } = route;
server.route({
+9
src/lib/handlers/getOwnerDid.ts
···
+
import { OWNER_DID } from "@/lib/env";
+
import { getRegistrationState } from "@/lib/state";
+
import type { RouteHandler } from "@/lib/types/routes";
+
import { newSuccessResponse } from "@/lib/utils/http/responses";
+
+
export const getOwnerHandler: RouteHandler = () => {
+
const { registered } = getRegistrationState();
+
return newSuccessResponse({ registered, ownerDid: OWNER_DID });
+
};
+11 -1
src/lib/types/http/responses.ts
···
import { sessionInfoSchema } from "@/lib/sessions";
+
import { didSchema } from "@/lib/types/atproto";
import { httpResponseErrorInfoSchema } from "@/lib/types/http/errors";
import { z } from "zod";
···
});
export type HandshakeResponse = z.infer<typeof handshakeResponseSchema>;
-
export const httpResponseDataSchema = z.union([handshakeResponseSchema]);
+
export const getOwnerDidResponseSchema = z.object({
+
registered: z.boolean(),
+
ownerDid: didSchema,
+
});
+
export type GetOwnerDidResponse = z.infer<typeof getOwnerDidResponseSchema>;
+
+
export const httpResponseDataSchema = z.union([
+
handshakeResponseSchema,
+
getOwnerDidResponseSchema,
+
]);
export type HttpResponseData = z.infer<typeof httpResponseDataSchema>;
const httpResponseBaseSchema = z.object({
+5
src/routes/index.ts
···
import { didWebDocRoute } from "@/routes/dot-well-known/did-dot-json/route";
import { handshakeRoute } from "@/routes/handshake/route";
import { indexRoute } from "@/routes/route";
+
import { healthRoute } from "@/routes/xrpc/_health/route";
+
import { systemsGmstnDevelopmentShardGetOwnerRoute } from "@/routes/xrpc/systems.gmstn.development.shard.getOwner/route";
export const routes: Record<string, Route | WsRoute> = {
"/": indexRoute,
"/.well-known/did.json": didWebDocRoute,
"/handshake": handshakeRoute,
"/connect": connectRoute,
+
"/xrpc/_health": healthRoute,
+
"/xrpc/systems.gmstn.development.shard.getOwner":
+
systemsGmstnDevelopmentShardGetOwnerRoute,
};
+10
src/routes/xrpc/_health/route.ts
···
+
import type { Route } from "@/lib/types/routes";
+
+
export const healthRoute: Route = {
+
method: "GET",
+
handler: () => {
+
return new Response("this shard is running at 0.0.1", {
+
headers: { "content-type": "text/plain; charset=utf-8" },
+
});
+
},
+
};
+7
src/routes/xrpc/systems.gmstn.development.shard.getOwner/route.ts
···
+
import { getOwnerHandler } from "@/lib/handlers/getOwnerDid";
+
import type { Route } from "@/lib/types/routes";
+
+
export const systemsGmstnDevelopmentShardGetOwnerRoute: Route = {
+
method: "GET",
+
handler: getOwnerHandler,
+
};