new file: .claude/settings.local.json

new file:   .gitignore
	new file:   backend/.env.example
	new file:   backend/.gitignore
	new file:   backend/ecosystem.config.js
	new file:   backend/nodemon.json
	new file:   backend/package-lock.json
	new file:   backend/package.json
	new file:   backend/src/config/database.ts
	new file:   backend/src/config/dynamicSwagger.ts
	new file:   backend/src/config/environment.ts
	new file:   backend/src/config/swagger.ts
	new file:   backend/src/controllers/apiKeyController.ts
	new file:   backend/src/controllers/authController.ts
	new file:   backend/src/controllers/databaseController.ts
	new file:   backend/src/controllers/databaseManagementController.ts
	new file:   backend/src/controllers/dynamicApiController.ts
	new file:   backend/src/controllers/endpointController.ts
	new file:   backend/src/controllers/folderController.ts
	new file:   backend/src/controllers/logsController.ts
	new file:   backend/src/controllers/userController.ts
	new file:   backend/src/middleware/apiKey.ts
	new file:   backend/src/middleware/auth.ts
	new file:   backend/src/middleware/logging.ts
	new file:   backend/src/migrations/001_initial_schema.sql
	new file:   backend/src/migrations/002_add_logging.sql
	new file:   backend/src/migrations/003_add_scripting.sql
	new file:   backend/src/migrations/004_add_superadmin.sql
	new file:   backend/src/migrations/run.ts
	new file:   backend/src/migrations/seed.ts
	new file:   backend/src/routes/apiKeys.ts
	new file:   backend/src/routes/auth.ts
	new file:   backend/src/routes/databaseManagement.ts
	new file:   backend/src/routes/databases.ts
	new file:   backend/src/routes/dynamic.ts
	new file:   backend/src/routes/endpoints.ts
	new file:   backend/src/routes/folders.ts
	new file:   backend/src/routes/logs.ts
	new file:   backend/src/routes/users.ts
	new file:   backend/src/server.ts
	new file:   backend/src/services/DatabasePoolManager.ts
	new file:   backend/src/services/ScriptExecutor.ts
	new file:   backend/src/services/SqlExecutor.ts
	new file:   backend/src/types/index.ts
	new file:   backend/tsconfig.json
	new file:   frontend/.gitignore
	new file:   frontend/index.html
	new file:   frontend/nginx.conf
	new file:   frontend/package-lock.json
	new file:   frontend/package.json
	new file:   frontend/postcss.config.js
	new file:   frontend/src/App.tsx
	new file:   frontend/src/components/CodeEditor.tsx
This commit is contained in:
GEgorov
2025-10-07 00:04:04 +03:00
commit 8943f5a070
79 changed files with 17032 additions and 0 deletions

View File

@@ -0,0 +1,171 @@
import axios from 'axios';
import { AuthResponse, User, Endpoint, Folder, ApiKey, Database, QueryTestResult } from '@/types';
const api = axios.create({
baseURL: '/api',
headers: {
'Content-Type': 'application/json',
},
});
// Request interceptor to add auth token
api.interceptors.request.use((config) => {
const token = localStorage.getItem('auth_token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
// Response interceptor for error handling
api.interceptors.response.use(
(response) => response,
(error) => {
if (error.response?.status === 401) {
localStorage.removeItem('auth_token');
window.location.href = '/login';
}
return Promise.reject(error);
}
);
// Auth API
export const authApi = {
login: (username: string, password: string) =>
api.post<AuthResponse>('/auth/login', { username, password }),
getMe: () =>
api.get<User>('/auth/me'),
};
// Users API (superadmin only)
export const usersApi = {
getAll: () =>
api.get<User[]>('/users'),
create: (data: { username: string; password: string; role?: string; is_superadmin?: boolean }) =>
api.post<User>('/users', data),
update: (id: string, data: Partial<User> & { password?: string }) =>
api.put<User>(`/users/${id}`, data),
delete: (id: string) =>
api.delete(`/users/${id}`),
};
// Database Management API (admin only)
// Logs API
export const logsApi = {
getAll: (filters?: any) =>
api.get('/logs', { params: filters }),
getById: (id: string) =>
api.get(`/logs/${id}`),
delete: (id: string) =>
api.delete(`/logs/${id}`),
clear: (data: any) =>
api.post('/logs/clear', data),
};
// Database Management API (admin only)
export const dbManagementApi = {
getAll: () =>
api.get<any[]>('/db-management'),
getById: (id: string) =>
api.get<any>(`/db-management/${id}`),
create: (data: any) =>
api.post<any>('/db-management', data),
update: (id: string, data: any) =>
api.put<any>(`/db-management/${id}`, data),
delete: (id: string) =>
api.delete(`/db-management/${id}`),
test: (id: string) =>
api.get<{ success: boolean; message: string }>(`/db-management/${id}/test`),
};
// Endpoints API
export const endpointsApi = {
getAll: (search?: string, folderId?: string) =>
api.get<Endpoint[]>('/endpoints', { params: { search, folder_id: folderId } }),
getById: (id: string) =>
api.get<Endpoint>(`/endpoints/${id}`),
create: (data: Partial<Endpoint>) =>
api.post<Endpoint>('/endpoints', data),
update: (id: string, data: Partial<Endpoint>) =>
api.put<Endpoint>(`/endpoints/${id}`, data),
delete: (id: string) =>
api.delete(`/endpoints/${id}`),
test: (data: {
database_id: string;
execution_type?: 'sql' | 'script';
sql_query?: string;
parameters?: any[];
endpoint_parameters?: any[];
script_language?: 'javascript' | 'python';
script_code?: string;
script_queries?: any[];
}) =>
api.post<QueryTestResult>('/endpoints/test', data),
};
// Folders API
export const foldersApi = {
getAll: () =>
api.get<Folder[]>('/folders'),
getById: (id: string) =>
api.get<Folder>(`/folders/${id}`),
create: (name: string, parentId?: string) =>
api.post<Folder>('/folders', { name, parent_id: parentId }),
update: (id: string, name: string, parentId?: string) =>
api.put<Folder>(`/folders/${id}`, { name, parent_id: parentId }),
delete: (id: string) =>
api.delete(`/folders/${id}`),
};
// API Keys API
export const apiKeysApi = {
getAll: () =>
api.get<ApiKey[]>('/keys'),
create: (name: string, permissions: string[], expiresAt?: string, enableLogging?: boolean) =>
api.post<ApiKey>('/keys', { name, permissions, expires_at: expiresAt, enable_logging: enableLogging }),
update: (id: string, data: Partial<ApiKey>) =>
api.put<ApiKey>(`/keys/${id}`, data),
delete: (id: string) =>
api.delete(`/keys/${id}`),
};
// Databases API
export const databasesApi = {
getAll: () =>
api.get<Database[]>('/databases'),
test: (databaseId: string) =>
api.get<{ success: boolean; message: string }>(`/databases/${databaseId}/test`),
getTables: (databaseId: string) =>
api.get<{ tables: string[] }>(`/databases/${databaseId}/tables`),
getTableSchema: (databaseId: string, tableName: string) =>
api.get<{ schema: any[] }>(`/databases/${databaseId}/tables/${tableName}/schema`),
};
export default api;