auth-core-migration.ts53 lines · main
1/**
2 * briven-engine migration API (Phase 7 surface).
3 *
4 * POST /v1/auth-core/migration/users
5 */
6
7import { Hono } from 'hono';
8
9import { requireAuthCoreDashboard } from '../middleware/auth-core-guard.js';
10import { BRIVEN_ENGINE_ID } from '../services/auth-core/engine.js';
11import {
12 importBrivenEngineUsers,
13 type ImportUserInput,
14} from '../services/auth-core/migration.js';
15import type { AppEnv } from '../types/app-env.js';
16
17export const authCoreMigrationRouter = new Hono<AppEnv>();
18
19authCoreMigrationRouter.use(
20 '/v1/auth-core/migration/*',
21 requireAuthCoreDashboard(),
22);
23
24authCoreMigrationRouter.post('/v1/auth-core/migration/users', async (c) => {
25 let body: { users?: ImportUserInput[] } = {};
26 try {
27 body = await c.req.json();
28 } catch {
29 body = {};
30 }
31 if (!Array.isArray(body.users) || body.users.length === 0) {
32 return c.json(
33 {
34 engine: BRIVEN_ENGINE_ID,
35 code: 'users_array_required',
36 message: 'Body must be { users: [...] }',
37 },
38 400,
39 );
40 }
41 if (body.users.length > 500) {
42 return c.json(
43 {
44 engine: BRIVEN_ENGINE_ID,
45 code: 'batch_too_large',
46 message: 'Max 500 users per request',
47 },
48 400,
49 );
50 }
51 const result = await importBrivenEngineUsers(body.users);
52 return c.json(result, result.ok ? 200 : 503);
53});