diff --git a/server/index.ts b/server/index.ts index 2dfa71c..f89420c 100644 --- a/server/index.ts +++ b/server/index.ts @@ -181,6 +181,33 @@ app.post("/api/communities", async (c) => { return c.json({ url: `https://${slug}.rspace.online`, slug, name, visibility, ownerDID: claims.sub }, 201); }); +// POST /api/internal/provision — auth-free, called by rSpace Registry +app.post("/api/internal/provision", async (c) => { + const body = await c.req.json<{ space?: string; description?: string; public?: boolean }>(); + const space = body.space?.trim(); + if (!space) return c.json({ error: "Missing space name" }, 400); + + if (await communityExists(space)) { + return c.json({ status: "exists", slug: space }); + } + + const visibility: SpaceVisibility = body.public ? "public" : "public_read"; + await createCommunity( + space.charAt(0).toUpperCase() + space.slice(1), + space, + `did:system:${space}`, + visibility, + ); + + for (const mod of getAllModules()) { + if (mod.onSpaceCreate) { + try { await mod.onSpaceCreate(space); } catch (e) { console.error(`Module ${mod.id} onSpaceCreate:`, e); } + } + } + + return c.json({ status: "created", slug: space }, 201); +}); + // POST /api/communities/demo/reset app.post("/api/communities/demo/reset", async (c) => { const now = Date.now();