Add internal provision endpoint for rSpace Registry
Auth-free POST /api/internal/provision creates community via Hono route, triggers onSpaceCreate for all registered modules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
07a7a083f4
commit
5b3c41c559
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue