Initial commit
This commit is contained in:
131
frontend/src/services/api/client.ts
Normal file
131
frontend/src/services/api/client.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
// API Client Service
|
||||
import axios, { AxiosInstance, AxiosError, InternalAxiosRequestConfig } from 'axios';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000';
|
||||
|
||||
class ApiClient {
|
||||
private client: AxiosInstance;
|
||||
|
||||
constructor() {
|
||||
this.client = axios.create({
|
||||
baseURL: API_BASE_URL,
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
this.setupInterceptors();
|
||||
}
|
||||
|
||||
private setupInterceptors() {
|
||||
// Request interceptor
|
||||
this.client.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = localStorage.getItem('auth_token');
|
||||
if (token) {
|
||||
config.headers.Authorization = `SOV-TOKEN ${token}`;
|
||||
}
|
||||
|
||||
// Add timestamp and nonce for signature (if required by backend)
|
||||
const timestamp = Date.now().toString();
|
||||
const nonce = Math.random().toString(36).substring(7);
|
||||
config.headers['X-SOV-Timestamp'] = timestamp;
|
||||
config.headers['X-SOV-Nonce'] = nonce;
|
||||
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// Response interceptor
|
||||
this.client.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error: AxiosError) => {
|
||||
if (error.response) {
|
||||
const status = error.response.status;
|
||||
|
||||
switch (status) {
|
||||
case 401:
|
||||
// Unauthorized - clear token and redirect to login
|
||||
localStorage.removeItem('auth_token');
|
||||
localStorage.removeItem('user');
|
||||
window.location.href = '/login';
|
||||
toast.error('Session expired. Please login again.');
|
||||
break;
|
||||
|
||||
case 403:
|
||||
toast.error('You do not have permission to perform this action.');
|
||||
break;
|
||||
|
||||
case 404:
|
||||
toast.error('Resource not found.');
|
||||
break;
|
||||
|
||||
case 422:
|
||||
// Validation errors
|
||||
const validationErrors = (error.response.data as any)?.error?.details;
|
||||
if (validationErrors) {
|
||||
Object.values(validationErrors).forEach((msg: any) => {
|
||||
toast.error(Array.isArray(msg) ? msg[0] : msg);
|
||||
});
|
||||
} else {
|
||||
toast.error('Validation error. Please check your input.');
|
||||
}
|
||||
break;
|
||||
|
||||
case 500:
|
||||
toast.error('Server error. Please try again later.');
|
||||
break;
|
||||
|
||||
default:
|
||||
const message = (error.response.data as any)?.error?.message || 'An error occurred';
|
||||
toast.error(message);
|
||||
}
|
||||
} else if (error.request) {
|
||||
// Network error
|
||||
toast.error('Network error. Please check your connection.');
|
||||
} else {
|
||||
toast.error('An unexpected error occurred.');
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
get instance(): AxiosInstance {
|
||||
return this.client;
|
||||
}
|
||||
|
||||
async get<T>(url: string, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||
const response = await this.client.get<T>(url, config);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async post<T>(url: string, data?: any, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||
const response = await this.client.post<T>(url, data, config);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async put<T>(url: string, data?: any, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||
const response = await this.client.put<T>(url, data, config);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async patch<T>(url: string, data?: any, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||
const response = await this.client.patch<T>(url, data, config);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async delete<T>(url: string, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||
const response = await this.client.delete<T>(url, config);
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
export const apiClient = new ApiClient();
|
||||
|
||||
131
frontend/src/services/api/dbisAdminApi.ts
Normal file
131
frontend/src/services/api/dbisAdminApi.ts
Normal file
@@ -0,0 +1,131 @@
|
||||
// DBIS Admin API Service
|
||||
import { apiClient } from './client';
|
||||
import type {
|
||||
NetworkHealthStatus,
|
||||
SettlementThroughput,
|
||||
GRULiquidityMetrics,
|
||||
RiskFlags,
|
||||
SCBStatus,
|
||||
ParticipantInfo,
|
||||
} from '@/types';
|
||||
|
||||
export interface GlobalOverviewDashboard {
|
||||
networkHealth: NetworkHealthStatus[];
|
||||
settlementThroughput: SettlementThroughput;
|
||||
gruLiquidity: GRULiquidityMetrics;
|
||||
riskFlags: RiskFlags;
|
||||
scbStatus: SCBStatus[];
|
||||
}
|
||||
|
||||
export interface JurisdictionSettings {
|
||||
scbId: string;
|
||||
allowedAssetClasses: string[];
|
||||
corridorRules: Array<{
|
||||
targetSCB: string;
|
||||
caps: number;
|
||||
allowedSettlementAssets: string[];
|
||||
}>;
|
||||
regulatoryProfiles: {
|
||||
amlStrictness: 'low' | 'medium' | 'high';
|
||||
sanctionsLists: string[];
|
||||
reportingFrequency: string;
|
||||
};
|
||||
}
|
||||
|
||||
class DBISAdminAPI {
|
||||
// Global Overview
|
||||
async getGlobalOverview(): Promise<GlobalOverviewDashboard> {
|
||||
return apiClient.get<GlobalOverviewDashboard>('/api/admin/dbis/dashboard/overview');
|
||||
}
|
||||
|
||||
// Participants
|
||||
async getParticipants(): Promise<ParticipantInfo[]> {
|
||||
return apiClient.get<ParticipantInfo[]>('/api/admin/dbis/participants');
|
||||
}
|
||||
|
||||
async getParticipantDetails(scbId: string): Promise<ParticipantInfo> {
|
||||
return apiClient.get<ParticipantInfo>(`/api/admin/dbis/participants/${scbId}`);
|
||||
}
|
||||
|
||||
async getJurisdictionSettings(scbId: string): Promise<JurisdictionSettings> {
|
||||
return apiClient.get<JurisdictionSettings>(`/api/admin/dbis/participants/${scbId}/jurisdiction`);
|
||||
}
|
||||
|
||||
async getCorridors() {
|
||||
return apiClient.get('/api/admin/dbis/corridors');
|
||||
}
|
||||
|
||||
// GRU Command
|
||||
async getGRUCommandDashboard() {
|
||||
return apiClient.get('/api/admin/dbis/gru/command');
|
||||
}
|
||||
|
||||
async createGRUIssuanceProposal(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/gru/issuance/proposal', data);
|
||||
}
|
||||
|
||||
async lockUnlockGRUClass(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/gru/lock', data);
|
||||
}
|
||||
|
||||
async setCircuitBreakers(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/gru/circuit-breakers', data);
|
||||
}
|
||||
|
||||
async manageBondIssuanceWindow(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/gru/bonds/window', data);
|
||||
}
|
||||
|
||||
async triggerEmergencyBuyback(bondId: string, amount: number) {
|
||||
return apiClient.post('/api/admin/dbis/gru/bonds/buyback', { bondId, amount });
|
||||
}
|
||||
|
||||
// GAS & QPS
|
||||
async getGASQPSDashboard() {
|
||||
return apiClient.get('/api/admin/dbis/gas-qps');
|
||||
}
|
||||
|
||||
// CBDC & FX
|
||||
async getCBDCFXDashboard() {
|
||||
return apiClient.get('/api/admin/dbis/cbdc-fx');
|
||||
}
|
||||
|
||||
// Metaverse & Edge
|
||||
async getMetaverseEdgeDashboard() {
|
||||
return apiClient.get('/api/admin/dbis/metaverse-edge');
|
||||
}
|
||||
|
||||
// Risk & Compliance
|
||||
async getRiskComplianceDashboard() {
|
||||
return apiClient.get('/api/admin/dbis/risk-compliance');
|
||||
}
|
||||
|
||||
// Corridor Controls
|
||||
async adjustCorridorCaps(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/corridors/caps', data);
|
||||
}
|
||||
|
||||
async throttleCorridor(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/corridors/throttle', data);
|
||||
}
|
||||
|
||||
async enableDisableCorridor(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/corridors/enable-disable', data);
|
||||
}
|
||||
|
||||
// Network Controls
|
||||
async quiesceSubsystem(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/network/quiesce', data);
|
||||
}
|
||||
|
||||
async activateKillSwitch(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/network/kill-switch', data);
|
||||
}
|
||||
|
||||
async escalateIncident(data: any) {
|
||||
return apiClient.post('/api/admin/dbis/network/escalate', data);
|
||||
}
|
||||
}
|
||||
|
||||
export const dbisAdminApi = new DBISAdminAPI();
|
||||
|
||||
43
frontend/src/services/api/scbAdminApi.ts
Normal file
43
frontend/src/services/api/scbAdminApi.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
// SCB Admin API Service
|
||||
import { apiClient } from './client';
|
||||
|
||||
class SCBAdminAPI {
|
||||
// SCB Overview
|
||||
async getSCBOverview(scbId: string) {
|
||||
return apiClient.get(`/api/admin/scb/dashboard/overview`);
|
||||
}
|
||||
|
||||
// FI Management
|
||||
async getFIManagementDashboard(scbId: string) {
|
||||
return apiClient.get(`/api/admin/scb/fi`);
|
||||
}
|
||||
|
||||
async approveSuspendFI(scbId: string, data: any) {
|
||||
return apiClient.post(`/api/admin/scb/fi/approve-suspend`, data);
|
||||
}
|
||||
|
||||
async setFILimits(scbId: string, data: any) {
|
||||
return apiClient.post(`/api/admin/scb/fi/limits`, data);
|
||||
}
|
||||
|
||||
async assignAPIProfile(scbId: string, data: any) {
|
||||
return apiClient.post(`/api/admin/scb/fi/api-profile`, data);
|
||||
}
|
||||
|
||||
// Corridor & FX Policy
|
||||
async getCorridorPolicyDashboard(scbId: string) {
|
||||
return apiClient.get(`/api/admin/scb/corridors`);
|
||||
}
|
||||
|
||||
// CBDC Controls
|
||||
async updateCBDCParameters(scbId: string, data: any) {
|
||||
return apiClient.post(`/api/admin/scb/cbdc/parameters`, data);
|
||||
}
|
||||
|
||||
async updateGRUPolicy(scbId: string, data: any) {
|
||||
return apiClient.post(`/api/admin/scb/gru/policy`, data);
|
||||
}
|
||||
}
|
||||
|
||||
export const scbAdminApi = new SCBAdminAPI();
|
||||
|
||||
Reference in New Issue
Block a user