Spaces:
Sleeping
Sleeping
File size: 4,511 Bytes
f871fed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
/**
* Auto-Update Agent API Client
*
* Functions for managing source monitoring and update notifications.
*/
import { apiClient } from './client';
import type {
SourceMonitor,
SourceMonitorCreate,
SourceMonitorUpdate,
UpdateNotification,
MonitorJobRun,
MonitoringStats,
NotificationCountResponse,
JobTriggerResponse,
} from '../types/monitoring';
// ============================================================================
// Monitor API
// ============================================================================
/**
* Create or update a source monitor
*/
export async function createMonitor(data: SourceMonitorCreate): Promise<SourceMonitor> {
const response = await apiClient.post('/monitoring/monitors', data);
return response.data;
}
/**
* List all monitors
*/
export async function listMonitors(): Promise<SourceMonitor[]> {
const response = await apiClient.get('/monitoring/monitors');
return response.data;
}
/**
* Get monitor for a specific source
*/
export async function getMonitor(sourceId: string): Promise<SourceMonitor> {
const response = await apiClient.get(`/monitoring/monitors/${sourceId}`);
return response.data;
}
/**
* Update a source monitor
*/
export async function updateMonitor(
sourceId: string,
data: SourceMonitorUpdate
): Promise<SourceMonitor> {
const response = await apiClient.patch(`/monitoring/monitors/${sourceId}`, data);
return response.data;
}
/**
* Delete a source monitor
*/
export async function deleteMonitor(sourceId: string): Promise<void> {
await apiClient.delete(`/monitoring/monitors/${sourceId}`);
}
// ============================================================================
// Notification API
// ============================================================================
/**
* List notifications
*/
export async function listNotifications(
includeDismissed = false,
limit = 100
): Promise<UpdateNotification[]> {
const response = await apiClient.get('/monitoring/notifications', {
params: { include_dismissed: includeDismissed, limit },
});
return response.data;
}
/**
* Get unread notifications
*/
export async function getUnreadNotifications(limit = 50): Promise<UpdateNotification[]> {
const response = await apiClient.get('/monitoring/notifications/unread', {
params: { limit },
});
return response.data;
}
/**
* Get notification count
*/
export async function getNotificationCount(): Promise<NotificationCountResponse> {
const response = await apiClient.get('/monitoring/notifications/count');
return response.data;
}
/**
* Mark a notification as read
*/
export async function markNotificationRead(notificationId: string): Promise<void> {
await apiClient.post(`/monitoring/notifications/${notificationId}/read`);
}
/**
* Dismiss a notification
*/
export async function dismissNotification(notificationId: string): Promise<void> {
await apiClient.post(`/monitoring/notifications/${notificationId}/dismiss`);
}
/**
* Mark all notifications as read
*/
export async function markAllNotificationsRead(): Promise<{ status: string; count: number }> {
const response = await apiClient.post('/monitoring/notifications/mark-all-read');
return response.data;
}
// ============================================================================
// Job API
// ============================================================================
/**
* Trigger a monitoring job
*/
export async function triggerMonitoringJob(
frequency?: string
): Promise<JobTriggerResponse> {
const response = await apiClient.post('/monitoring/jobs/run', null, {
params: frequency ? { frequency } : undefined,
});
return response.data;
}
/**
* Get job history
*/
export async function getJobHistory(limit = 10): Promise<MonitorJobRun[]> {
const response = await apiClient.get('/monitoring/jobs/history', {
params: { limit },
});
return response.data;
}
/**
* Get current running job
*/
export async function getCurrentJob(): Promise<MonitorJobRun | { status: string }> {
const response = await apiClient.get('/monitoring/jobs/current');
return response.data;
}
// ============================================================================
// Stats API
// ============================================================================
/**
* Get monitoring statistics
*/
export async function getMonitoringStats(): Promise<MonitoringStats> {
const response = await apiClient.get('/monitoring/stats');
return response.data;
}
|