- Rewrote Drizzle schema: 20 tables with enums, relations, indexes - Generated migration with DROP TABLE records (v1 EAV removal) - Added passkey auth routes (register/login) - Added requireWorkspaceAccess helper - Added seedDefaultData for Personal workspace + welcome note - Updated SSE endpoint for v2 entities + workspace_id filtering - Created recordActivity helper (insert + pg_notify) - Updated sidebar: Graph replaces Reports, removed Analytics - Updated command palette for v2 entities - Created AGENTS.md with locked contract - Created llm-wiki scaffold (5 stubs) - Added inline AGENT INSTRUCTION comments to all 50 API route files - Fixed globals.css border-border class conflict - Updated database.ts stub for v1 compatibility
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
|
|
// 1. Insert activity feed entry
|
|
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
|
|
// See AGENTS.md for full rules.
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { withAuth, createErrorResponse } from '@/lib/auth';
|
|
import { createPocketBaseClient } from '@/lib/pocketbase';
|
|
import { createWebhookSchema } from '@project-e/shared';
|
|
import { z } from 'zod';
|
|
|
|
// GET /api/webhooks — List webhooks with filtering, sorting, pagination
|
|
export const GET = withAuth(async (request: NextRequest, _user) => {
|
|
const { searchParams } = new URL(request.url);
|
|
const page = parseInt(searchParams.get('page') || '1');
|
|
const perPage = parseInt(searchParams.get('perPage') || '50');
|
|
const filter = searchParams.get('filter') || undefined;
|
|
const sort = searchParams.get('sort') || '-created';
|
|
|
|
const pb = createPocketBaseClient();
|
|
const result = await pb.collection('webhooks').getList(page, perPage, {
|
|
...(filter ? { filter } : {}),
|
|
sort,
|
|
});
|
|
|
|
return NextResponse.json({
|
|
items: result.items,
|
|
totalItems: result.totalItems,
|
|
totalPages: result.totalPages,
|
|
page: result.page,
|
|
perPage: result.perPage,
|
|
});
|
|
});
|
|
|
|
// POST /api/webhooks — Create a webhook
|
|
export const POST = withAuth(async (request: NextRequest, _user) => {
|
|
try {
|
|
const body = await request.json();
|
|
const data = createWebhookSchema.parse(body);
|
|
|
|
const pb = createPocketBaseClient();
|
|
const webhook = await pb.collection('webhooks').create(data);
|
|
|
|
return NextResponse.json(webhook, { status: 201 });
|
|
} catch (error) {
|
|
if (error instanceof z.ZodError) {
|
|
return createErrorResponse('VALIDATION_ERROR', 'Invalid input', 400, error.issues);
|
|
}
|
|
throw error;
|
|
}
|
|
});
|