UNPKG

self-serve-integration-service

Version:

Self-Serve Integration Service for managing multiple funder integrations including REST APIs, SOAP APIs, and UI automation

338 lines (325 loc) 9.56 kB
import swaggerJsdoc from 'swagger-jsdoc'; import swaggerUi from 'swagger-ui-express'; import { Express } from 'express'; // Function to get server configurations based on environment const getServers = () => { const servers = []; // Always include development server servers.push({ url: 'http://localhost:3003', description: 'Development server', }); // Add production server if not in development if (process.env.NODE_ENV !== 'development') { servers.push({ url: 'https://api.selfserve.com', description: 'Production server', }); } // If a custom API_BASE_URL is provided, use it if (process.env.API_BASE_URL) { servers.push({ url: process.env.API_BASE_URL, description: 'Custom server', }); } return servers; }; const options: swaggerJsdoc.Options = { definition: { openapi: '3.0.0', info: { title: 'Self-Serve Integration Service API', version: '1.0.0', description: 'Integration service providing unified API for multiple vehicle finance funders', }, tags: [ { name: 'Integration API', description: 'Unified API for vehicle finance quotes, proposals, vehicles, and customers across multiple funders (LEX, Alphabet, etc.)', }, { name: 'Funders', description: 'Funder management and information endpoints (Public read access)', }, { name: 'Health Check', description: 'Service health and status monitoring', }, ], servers: getServers(), components: { securitySchemes: { bearerAuth: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT', }, apiKeyAuth: { type: 'apiKey', in: 'header', name: 'X-API-Key', }, }, schemas: { Funder: { type: 'object', properties: { id: { type: 'string', format: 'uuid', description: 'Unique identifier for the funder', }, name: { type: 'string', description: 'Funder name', }, code: { type: 'string', description: 'Funder code (1-10 characters)', maxLength: 10, }, displayName: { type: 'string', description: 'Human-readable display name', }, description: { type: 'string', nullable: true, description: 'Funder description', }, website: { type: 'string', format: 'uri', nullable: true, description: 'Funder website URL', }, integrationType: { type: 'string', enum: ['REST_API', 'SOAP_API', 'UI_AUTOMATION'], description: 'Type of integration', }, uiAutomationType: { type: 'string', enum: ['UIPATH', 'PLAYWRIGHT', 'CYPRESS'], nullable: true, description: 'UI automation tool type', }, baseUrl: { type: 'string', format: 'uri', nullable: true, description: 'Base URL for API calls', }, timeout: { type: 'integer', nullable: true, description: 'Request timeout in milliseconds', }, status: { type: 'string', enum: ['ACTIVE', 'INACTIVE', 'MAINTENANCE', 'DEPRECATED'], description: 'Current funder status', }, priority: { type: 'integer', description: 'Priority for funder selection (lower = higher priority)', }, supportedQuoteTypes: { type: 'array', items: { type: 'string', }, description: 'Supported quote types', }, supportedProposalTypes: { type: 'array', items: { type: 'string', }, description: 'Supported proposal types', }, responseTime: { type: 'integer', nullable: true, description: 'Average response time in milliseconds', }, successRate: { type: 'number', format: 'float', nullable: true, description: 'Success rate percentage', }, lastIntegration: { type: 'string', format: 'date-time', nullable: true, description: 'Timestamp of last integration', }, createdAt: { type: 'string', format: 'date-time', description: 'Creation timestamp', }, updatedAt: { type: 'string', format: 'date-time', description: 'Last update timestamp', }, deletedAt: { type: 'string', format: 'date-time', nullable: true, description: 'Deletion timestamp (soft delete)', }, }, }, SuccessResponse: { type: 'object', properties: { success: { type: 'boolean', description: 'Indicates if the request was successful', }, data: { type: 'object', description: 'Response data', }, message: { type: 'string', description: 'Optional success message', }, }, }, Error: { type: 'object', properties: { success: { type: 'boolean', example: false, }, error: { type: 'string', description: 'Error type or code', }, message: { type: 'string', description: 'Error message', }, details: { type: 'array', items: { type: 'object', }, description: 'Additional error details', }, }, }, }, responses: { InternalServerError: { description: 'Internal server error', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: false, }, error: { type: 'string', example: 'Internal Server Error', }, message: { type: 'string', example: 'An unexpected error occurred', }, }, }, }, }, }, Unauthorized: { description: 'Unauthorized - Authentication required', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: false, }, error: { type: 'string', example: 'Unauthorized', }, message: { type: 'string', example: 'Authorization header is required', }, }, }, }, }, }, NotFound: { description: 'Resource not found', content: { 'application/json': { schema: { type: 'object', properties: { success: { type: 'boolean', example: false, }, error: { type: 'string', example: 'Not Found', }, message: { type: 'string', example: 'The requested resource was not found', }, }, }, }, }, }, }, }, }, apis: [ './src/routes/*.ts', // Development - TypeScript files './dist/routes/*.js', // Production - Compiled JavaScript files ], }; const specs = swaggerJsdoc(options); export const setupSwagger = (app: Express): void => { // Swagger UI app.use( '/api-docs', swaggerUi.serve, swaggerUi.setup(specs, { explorer: true, customCss: '.swagger-ui .topbar { display: none }', customSiteTitle: 'Self-Serve Integration Service API', swaggerOptions: { persistAuthorization: true, displayRequestDuration: true, filter: true, }, }) ); // JSON endpoint app.get('/api-docs.json', (_req, res) => { res.setHeader('Content-Type', 'application/json'); res.send(specs); }); console.log('📚 Swagger documentation available at: http://localhost:3003/api-docs'); console.log('📄 Swagger JSON available at: http://localhost:3003/api-docs.json'); };