(worker: OAuthClientManager)
| 248 | // ─── Hono HTTP Layer ───────────────────────────────────────── |
| 249 | |
| 250 | function createHttpApp(worker: OAuthClientManager): Hono { |
| 251 | const app = new Hono(); |
| 252 | |
| 253 | app.get("/health", (c) => c.json({ status: "ok" })); |
| 254 | |
| 255 | app.get("/applications", (c) => { |
| 256 | return c.json(worker.listAvailableApplications()); |
| 257 | }); |
| 258 | |
| 259 | app.post("/users/:userId/auth/start", async (c) => { |
| 260 | const userId = c.req.param("userId"); |
| 261 | const body = await c.req.json(); |
| 262 | const result = await worker.startAuth(userId, body); |
| 263 | if (!result.ok) { |
| 264 | const status = result.error.tag === "Validation" ? 400 : 404; |
| 265 | return c.json(result.error, status); |
| 266 | } |
| 267 | return c.json(result.data); |
| 268 | }); |
| 269 | |
| 270 | app.post("/users/:userId/auth/complete", async (c) => { |
| 271 | const userId = c.req.param("userId"); |
| 272 | const body = await c.req.json(); |
| 273 | const result = await worker.completeAuth(userId, body); |
| 274 | if (!result.ok) { |
| 275 | if (result.error.tag === "Validation" || result.error.tag === "InvalidState") |
| 276 | return c.json(result.error, 400); |
| 277 | if (result.error.tag === "UnknownApp") return c.json(result.error, 404); |
| 278 | if (result.error.tag === "AuthFailed") return c.json(result.error, 502); |
| 279 | return c.json(result.error, 500); |
| 280 | } |
| 281 | return c.json(result.data, 201); |
| 282 | }); |
| 283 | |
| 284 | app.get("/users/:userId/applications", async (c) => { |
| 285 | const userId = c.req.param("userId"); |
| 286 | const result = await worker.listApplications(userId); |
| 287 | if (!result.ok) return c.json(result.error, 500); |
| 288 | return c.json(result.data); |
| 289 | }); |
| 290 | |
| 291 | app.delete("/users/:userId/applications/:appId", async (c) => { |
| 292 | const userId = c.req.param("userId"); |
| 293 | const appId = c.req.param("appId"); |
| 294 | const result = await worker.deleteApplication(userId, appId); |
| 295 | if (!result.ok) { |
| 296 | const status = result.error.tag === "NotFound" ? 404 : 500; |
| 297 | return c.json(result.error, status); |
| 298 | } |
| 299 | return c.body(null, 204); |
| 300 | }); |
| 301 | |
| 302 | app.delete("/users/:userId", async (c) => { |
| 303 | const userId = c.req.param("userId"); |
| 304 | const result = await worker.deleteUser(userId); |
| 305 | if (!result.ok) return c.json(result.error, 500); |
| 306 | return c.json(result.data); |
| 307 | }); |
no test coverage detected