auth-core-status.ts88 lines · main
| 1 | /** |
| 2 | * Option B — briven-engine status surface. |
| 3 | * |
| 4 | * - GET /v1/auth-core/info |
| 5 | * - GET /v1/auth-core/ready |
| 6 | * - GET /v1/auth-core/map/:projectId |
| 7 | * |
| 8 | * App login (password) is on auth-core-fdi (Phase 2). Platform login stays /v1/auth/*. |
| 9 | */ |
| 10 | |
| 11 | import { Hono } from 'hono'; |
| 12 | |
| 13 | import { mapProjectToAuthCore } from '../services/auth-core/project-map.js'; |
| 14 | import { |
| 15 | BRIVEN_ENGINE_ID, |
| 16 | BRIVEN_ENGINE_VERSION, |
| 17 | probeBrivenEngine, |
| 18 | } from '../services/auth-core/engine.js'; |
| 19 | import { getAuthEmailDeliveryStatus } from '../services/auth-core/delivery.js'; |
| 20 | import type { AppEnv } from '../types/app-env.js'; |
| 21 | import { BUILD_AT, BUILD_SHA } from './health.js'; |
| 22 | |
| 23 | export const authCoreStatusRouter = new Hono<AppEnv>(); |
| 24 | |
| 25 | authCoreStatusRouter.get('/v1/auth-core/info', async (c) => { |
| 26 | const core = await probeBrivenEngine(); |
| 27 | const emailDelivery = getAuthEmailDeliveryStatus(); |
| 28 | return c.json({ |
| 29 | service: 'briven-auth-core', |
| 30 | product: 'Briven Auth', |
| 31 | engine: BRIVEN_ENGINE_ID, |
| 32 | engineVersion: BRIVEN_ENGINE_VERSION, |
| 33 | productStatus: 'enterprise-sso', |
| 34 | notice: |
| 35 | 'login APIs + yellow dashboard + enterprise SAML/OIDC SSO on Doltgres', |
| 36 | buildSha: BUILD_SHA, |
| 37 | buildAt: BUILD_AT, |
| 38 | emailDelivery, |
| 39 | ...core, |
| 40 | }); |
| 41 | }); |
| 42 | |
| 43 | authCoreStatusRouter.get('/v1/auth-core/ready', async (c) => { |
| 44 | const core = await probeBrivenEngine(); |
| 45 | const emailDelivery = getAuthEmailDeliveryStatus(); |
| 46 | if (!core.ok) { |
| 47 | return c.json( |
| 48 | { |
| 49 | status: 'not_ready', |
| 50 | engine: BRIVEN_ENGINE_ID, |
| 51 | engineVersion: BRIVEN_ENGINE_VERSION, |
| 52 | emailDelivery, |
| 53 | ...core, |
| 54 | }, |
| 55 | 503, |
| 56 | ); |
| 57 | } |
| 58 | return c.json({ |
| 59 | status: 'ready', |
| 60 | engine: BRIVEN_ENGINE_ID, |
| 61 | engineVersion: BRIVEN_ENGINE_VERSION, |
| 62 | notice: |
| 63 | 'login APIs + yellow dashboard + enterprise SAML/OIDC SSO on Doltgres', |
| 64 | emailDelivery, |
| 65 | ...core, |
| 66 | }); |
| 67 | }); |
| 68 | |
| 69 | /** Project id → tenant map (rule-based; no login). */ |
| 70 | authCoreStatusRouter.get('/v1/auth-core/map/:projectId', (c) => { |
| 71 | const projectId = c.req.param('projectId'); |
| 72 | try { |
| 73 | return c.json({ |
| 74 | engine: BRIVEN_ENGINE_ID, |
| 75 | appLoginReady: false, |
| 76 | ...mapProjectToAuthCore(projectId), |
| 77 | }); |
| 78 | } catch (err) { |
| 79 | return c.json( |
| 80 | { |
| 81 | code: 'invalid_project_id', |
| 82 | engine: BRIVEN_ENGINE_ID, |
| 83 | message: err instanceof Error ? err.message : String(err), |
| 84 | }, |
| 85 | 400, |
| 86 | ); |
| 87 | } |
| 88 | }); |