FRE-4529: Transfer ShieldAI code from FrenoCorp repo
Transferred ShieldAI-related files mistakenly placed in ~/code/FrenoCorp:
- Services: spamshield (feature-flags, audit-logger, error-handler), voiceprint (config, service, feature-flags), darkwatch (pipeline, scan, scheduler, watchlist, webhook)
- Packages: shared-analytics, shared-auth, shared-ui, shared-utils (new); shared-billing, jobs supplemented with unique FC files
- Server: alerts (FC version newer), routes (spamshield, darkwatch, voiceprint)
- Config: turbo.json, tsconfig.base.json, vite/vitest configs, drizzle, Dockerfile
- VoicePrint ML service
- Examples
Pending: apps/{api,web,mobile}/ structured merge, shared-db/db mapping
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -1,33 +1,142 @@
|
||||
import { FastifyInstance } from "fastify";
|
||||
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
|
||||
import { authMiddleware, AuthRequest } from './auth.middleware';
|
||||
import { voiceprintRoutes } from './voiceprint.routes';
|
||||
import { spamshieldRoutes } from './spamshield.routes';
|
||||
import { darkwatchRoutes } from './darkwatch.routes';
|
||||
|
||||
export function darkwatchRoutes(fastify: FastifyInstance) {
|
||||
fastify.register(async (root) => {
|
||||
const watchlist = (await import("./watchlist.routes")).watchlistRoutes;
|
||||
const exposures = (await import("./exposure.routes")).exposureRoutes;
|
||||
const alerts = (await import("./alert.routes")).alertRoutes;
|
||||
const scans = (await import("./scan.routes")).scanRoutes;
|
||||
const scheduler = (await import("./scheduler.routes")).schedulerRoutes;
|
||||
const webhooks = (await import("./webhook.routes")).webhookRoutes;
|
||||
export async function routes(fastify: FastifyInstance) {
|
||||
// Authenticated routes group
|
||||
fastify.register(
|
||||
async (authenticated) => {
|
||||
// Add auth requirement
|
||||
authenticated.addHook('onRequest', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
await fastify.requireAuth(request as AuthRequest);
|
||||
});
|
||||
|
||||
root.register(watchlist, { prefix: "/watchlist" });
|
||||
root.register(exposures, { prefix: "/exposures" });
|
||||
root.register(alerts, { prefix: "/alerts" });
|
||||
root.register(scans, { prefix: "/scan" });
|
||||
root.register(scheduler, { prefix: "/scheduler" });
|
||||
root.register(webhooks, { prefix: "/webhooks" });
|
||||
}, { prefix: "/api/v1/darkwatch" });
|
||||
}
|
||||
|
||||
export function voiceprintRoutes(fastify: FastifyInstance) {
|
||||
fastify.register(async (root) => {
|
||||
const voiceprint = (await import("./voiceprint.routes")).voiceprintRoutes;
|
||||
root.register(voiceprint);
|
||||
}, { prefix: "/api/v1/voiceprint" });
|
||||
}
|
||||
|
||||
export function correlationRoutes(fastify: FastifyInstance) {
|
||||
fastify.register(async (root) => {
|
||||
const correlation = (await import("./correlation.routes")).correlationRoutes;
|
||||
root.register(correlation);
|
||||
}, { prefix: "/api/v1/correlation" });
|
||||
// Example authenticated endpoint
|
||||
authenticated.get('/user/me', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
const authReq = request as AuthRequest;
|
||||
return {
|
||||
user: authReq.user,
|
||||
authType: authReq.authType,
|
||||
};
|
||||
});
|
||||
|
||||
// Example service endpoint
|
||||
authenticated.get('/services', async (request: FastifyRequest, reply: FastifyReply) => {
|
||||
return {
|
||||
services: [
|
||||
{
|
||||
name: 'user-service',
|
||||
url: '/api/v1/services/user',
|
||||
status: 'healthy',
|
||||
},
|
||||
{
|
||||
name: 'billing-service',
|
||||
url: '/api/v1/services/billing',
|
||||
status: 'healthy',
|
||||
},
|
||||
{
|
||||
name: 'notification-service',
|
||||
url: '/api/v1/services/notifications',
|
||||
status: 'healthy',
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
},
|
||||
{ prefix: '/auth' }
|
||||
);
|
||||
|
||||
// Public API routes
|
||||
fastify.register(
|
||||
async (publicRouter) => {
|
||||
// Version info
|
||||
publicRouter.get('/info', async () => {
|
||||
return {
|
||||
version: '1.0.0',
|
||||
environment: process.env.NODE_ENV || 'development',
|
||||
build: process.env.npm_package_version || 'unknown',
|
||||
};
|
||||
});
|
||||
|
||||
// API documentation
|
||||
publicRouter.get('/docs', async () => {
|
||||
return {
|
||||
title: 'FrenoCorp API Gateway',
|
||||
version: '1.0.0',
|
||||
endpoints: {
|
||||
public: [
|
||||
{ method: 'GET', path: '/', description: 'Root endpoint' },
|
||||
{ method: 'GET', path: '/health', description: 'Health check' },
|
||||
{ method: 'GET', path: '/api/v1/info', description: 'API version info' },
|
||||
{ method: 'GET', path: '/api/v1/docs', description: 'API documentation' },
|
||||
],
|
||||
authenticated: [
|
||||
{ method: 'GET', path: '/api/v1/auth/user/me', description: 'Get current user' },
|
||||
{ method: 'GET', path: '/api/v1/auth/services', description: 'List available services' },
|
||||
],
|
||||
},
|
||||
};
|
||||
});
|
||||
},
|
||||
{ prefix: '/api/v1' }
|
||||
);
|
||||
|
||||
// Service proxy placeholder (for future microservice routing)
|
||||
fastify.register(
|
||||
async (services) => {
|
||||
services.get('/services/user', async (request, reply) => {
|
||||
// In production, proxy to actual user service
|
||||
return {
|
||||
service: 'user-service',
|
||||
message: 'User service endpoint',
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
});
|
||||
|
||||
services.get('/services/billing', async (request, reply) => {
|
||||
// In production, proxy to actual billing service
|
||||
return {
|
||||
service: 'billing-service',
|
||||
message: 'Billing service endpoint',
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
});
|
||||
|
||||
services.get('/services/notifications', async (request, reply) => {
|
||||
// In production, proxy to actual notification service
|
||||
return {
|
||||
service: 'notification-service',
|
||||
message: 'Notification service endpoint',
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
});
|
||||
},
|
||||
{ prefix: '/api/v1/services' }
|
||||
);
|
||||
|
||||
// VoicePrint service routes
|
||||
fastify.register(
|
||||
async (voiceprintRouter) => {
|
||||
await voiceprintRoutes(voiceprintRouter);
|
||||
},
|
||||
{ prefix: '/voiceprint' }
|
||||
);
|
||||
|
||||
// SpamShield service routes
|
||||
fastify.register(
|
||||
async (spamshieldRouter) => {
|
||||
await spamshieldRoutes(spamshieldRouter);
|
||||
},
|
||||
{ prefix: '/spamshield' }
|
||||
);
|
||||
|
||||
// DarkWatch service routes
|
||||
fastify.register(
|
||||
async (darkwatchRouter) => {
|
||||
await darkwatchRoutes(darkwatchRouter);
|
||||
},
|
||||
{ prefix: '/darkwatch' }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user