tested
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
* Service for interacting with the Connection Management API.
|
||||
*/
|
||||
|
||||
const API_BASE = '/api/settings/connections';
|
||||
import { requestApi } from '../lib/api';
|
||||
|
||||
const API_BASE = '/settings/connections';
|
||||
|
||||
// [DEF:getConnections:Function]
|
||||
/* @PURPOSE: Fetch a list of saved connections.
|
||||
@@ -14,11 +16,7 @@ const API_BASE = '/api/settings/connections';
|
||||
* @returns {Promise<Array>} List of connections.
|
||||
*/
|
||||
export async function getConnections() {
|
||||
const response = await fetch(API_BASE);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch connections: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
return requestApi(API_BASE);
|
||||
}
|
||||
// [/DEF:getConnections:Function]
|
||||
|
||||
@@ -33,19 +31,7 @@ export async function getConnections() {
|
||||
* @returns {Promise<Object>} The created connection instance.
|
||||
*/
|
||||
export async function createConnection(connectionData) {
|
||||
const response = await fetch(API_BASE, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(connectionData)
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.detail || `Failed to create connection: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
return requestApi(API_BASE, 'POST', connectionData);
|
||||
}
|
||||
// [/DEF:createConnection:Function]
|
||||
|
||||
@@ -59,12 +45,6 @@ export async function createConnection(connectionData) {
|
||||
* @param {string} connectionId - The ID of the connection to delete.
|
||||
*/
|
||||
export async function deleteConnection(connectionId) {
|
||||
const response = await fetch(`${API_BASE}/${connectionId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to delete connection: ${response.statusText}`);
|
||||
}
|
||||
return requestApi(`${API_BASE}/${connectionId}`, 'DELETE');
|
||||
}
|
||||
// [/DEF:deleteConnection:Function]
|
||||
@@ -6,7 +6,9 @@
|
||||
* @RELATION: DEPENDS_ON -> specs/011-git-integration-dashboard/contracts/api.md
|
||||
*/
|
||||
|
||||
const API_BASE = '/api/git';
|
||||
import { requestApi } from '../lib/api';
|
||||
|
||||
const API_BASE = '/git';
|
||||
|
||||
// [DEF:gitService:Action]
|
||||
export const gitService = {
|
||||
@@ -19,9 +21,7 @@ export const gitService = {
|
||||
*/
|
||||
async getConfigs() {
|
||||
console.log('[getConfigs][Action] Fetching Git configs');
|
||||
const response = await fetch(`${API_BASE}/config`);
|
||||
if (!response.ok) throw new Error('Failed to fetch Git configs');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/config`);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -34,13 +34,7 @@ export const gitService = {
|
||||
*/
|
||||
async createConfig(config) {
|
||||
console.log('[createConfig][Action] Creating Git config');
|
||||
const response = await fetch(`${API_BASE}/config`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to create Git config');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/config`, 'POST', config);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -53,11 +47,7 @@ export const gitService = {
|
||||
*/
|
||||
async deleteConfig(configId) {
|
||||
console.log(`[deleteConfig][Action] Deleting Git config ${configId}`);
|
||||
const response = await fetch(`${API_BASE}/config/${configId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to delete Git config');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/config/${configId}`, 'DELETE');
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -70,12 +60,7 @@ export const gitService = {
|
||||
*/
|
||||
async testConnection(config) {
|
||||
console.log('[testConnection][Action] Testing Git connection');
|
||||
const response = await fetch(`${API_BASE}/config/test`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/config/test`, 'POST', config);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -90,16 +75,10 @@ export const gitService = {
|
||||
*/
|
||||
async initRepository(dashboardId, configId, remoteUrl) {
|
||||
console.log(`[initRepository][Action] Initializing repo for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/init`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ config_id: configId, remote_url: remoteUrl })
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/init`, 'POST', {
|
||||
config_id: configId,
|
||||
remote_url: remoteUrl
|
||||
});
|
||||
if (!response.ok) {
|
||||
const err = await response.json();
|
||||
throw new Error(err.detail || 'Failed to initialize repository');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -112,9 +91,7 @@ export const gitService = {
|
||||
*/
|
||||
async getBranches(dashboardId) {
|
||||
console.log(`[getBranches][Action] Fetching branches for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/branches`);
|
||||
if (!response.ok) throw new Error('Failed to fetch branches');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/branches`);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -129,13 +106,10 @@ export const gitService = {
|
||||
*/
|
||||
async createBranch(dashboardId, name, fromBranch) {
|
||||
console.log(`[createBranch][Action] Creating branch ${name} for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/branches`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, from_branch: fromBranch })
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/branches`, 'POST', {
|
||||
name,
|
||||
from_branch: fromBranch
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to create branch');
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -149,13 +123,7 @@ export const gitService = {
|
||||
*/
|
||||
async checkoutBranch(dashboardId, name) {
|
||||
console.log(`[checkoutBranch][Action] Checking out branch ${name} for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/checkout`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name })
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to checkout branch');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/checkout`, 'POST', { name });
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -170,13 +138,7 @@ export const gitService = {
|
||||
*/
|
||||
async commit(dashboardId, message, files) {
|
||||
console.log(`[commit][Action] Committing changes for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/commit`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ message, files })
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to commit changes');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/commit`, 'POST', { message, files });
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -189,11 +151,7 @@ export const gitService = {
|
||||
*/
|
||||
async push(dashboardId) {
|
||||
console.log(`[push][Action] Pushing changes for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/push`, {
|
||||
method: 'POST'
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to push changes');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/push`, 'POST');
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -206,11 +164,7 @@ export const gitService = {
|
||||
*/
|
||||
async pull(dashboardId) {
|
||||
console.log(`[pull][Action] Pulling changes for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/pull`, {
|
||||
method: 'POST'
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to pull changes');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/pull`, 'POST');
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -221,9 +175,7 @@ export const gitService = {
|
||||
*/
|
||||
async getEnvironments() {
|
||||
console.log('[getEnvironments][Action] Fetching environments');
|
||||
const response = await fetch(`${API_BASE}/environments`);
|
||||
if (!response.ok) throw new Error('Failed to fetch environments');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/environments`);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -237,13 +189,9 @@ export const gitService = {
|
||||
*/
|
||||
async deploy(dashboardId, environmentId) {
|
||||
console.log(`[deploy][Action] Deploying dashboard ${dashboardId} to environment ${environmentId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/deploy`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ environment_id: environmentId })
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/deploy`, 'POST', {
|
||||
environment_id: environmentId
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to deploy dashboard');
|
||||
return response.json();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -255,9 +203,7 @@ export const gitService = {
|
||||
*/
|
||||
async getHistory(dashboardId, limit = 50) {
|
||||
console.log(`[getHistory][Action] Fetching history for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/history?limit=${limit}`);
|
||||
if (!response.ok) throw new Error('Failed to fetch commit history');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/history?limit=${limit}`);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -269,17 +215,9 @@ export const gitService = {
|
||||
*/
|
||||
async sync(dashboardId, sourceEnvId = null) {
|
||||
console.log(`[sync][Action] Syncing dashboard ${dashboardId}`);
|
||||
const url = new URL(`${window.location.origin}${API_BASE}/repositories/${dashboardId}/sync`);
|
||||
if (sourceEnvId) url.searchParams.append('source_env_id', sourceEnvId);
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST'
|
||||
});
|
||||
if (!response.ok) {
|
||||
const err = await response.json();
|
||||
throw new Error(err.detail || 'Failed to sync dashboard');
|
||||
}
|
||||
return response.json();
|
||||
let endpoint = `${API_BASE}/repositories/${dashboardId}/sync`;
|
||||
if (sourceEnvId) endpoint += `?source_env_id=${sourceEnvId}`;
|
||||
return requestApi(endpoint, 'POST');
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -292,9 +230,7 @@ export const gitService = {
|
||||
*/
|
||||
async getStatus(dashboardId) {
|
||||
console.log(`[getStatus][Action] Fetching status for dashboard ${dashboardId}`);
|
||||
const response = await fetch(`${API_BASE}/repositories/${dashboardId}/status`);
|
||||
if (!response.ok) throw new Error('Failed to fetch status');
|
||||
return response.json();
|
||||
return requestApi(`${API_BASE}/repositories/${dashboardId}/status`);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -309,15 +245,12 @@ export const gitService = {
|
||||
*/
|
||||
async getDiff(dashboardId, filePath = null, staged = false) {
|
||||
console.log(`[getDiff][Action] Fetching diff for dashboard ${dashboardId} (file: ${filePath}, staged: ${staged})`);
|
||||
let url = `${API_BASE}/repositories/${dashboardId}/diff`;
|
||||
let endpoint = `${API_BASE}/repositories/${dashboardId}/diff`;
|
||||
const params = new URLSearchParams();
|
||||
if (filePath) params.append('file_path', filePath);
|
||||
if (staged) params.append('staged', 'true');
|
||||
if (params.toString()) url += `?${params.toString()}`;
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) throw new Error('Failed to fetch diff');
|
||||
return response.json();
|
||||
if (params.toString()) endpoint += `?${params.toString()}`;
|
||||
return requestApi(endpoint);
|
||||
}
|
||||
};
|
||||
// [/DEF:gitService:Action]
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
* Service for interacting with the Task Management API.
|
||||
*/
|
||||
|
||||
const API_BASE = '/api/tasks';
|
||||
import { requestApi } from '../lib/api';
|
||||
|
||||
const API_BASE = '/tasks';
|
||||
|
||||
// [DEF:getTasks:Function]
|
||||
/* @PURPOSE: Fetch a list of tasks with pagination and optional status filter.
|
||||
@@ -25,11 +27,7 @@ export async function getTasks(limit = 10, offset = 0, status = null) {
|
||||
params.append('status', status);
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE}?${params.toString()}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch tasks: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
return requestApi(`${API_BASE}?${params.toString()}`);
|
||||
}
|
||||
// [/DEF:getTasks:Function]
|
||||
|
||||
@@ -44,11 +42,7 @@ export async function getTasks(limit = 10, offset = 0, status = null) {
|
||||
* @returns {Promise<Object>} Task details.
|
||||
*/
|
||||
export async function getTask(taskId) {
|
||||
const response = await fetch(`${API_BASE}/${taskId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch task ${taskId}: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
return requestApi(`${API_BASE}/${taskId}`);
|
||||
}
|
||||
// [/DEF:getTask:Function]
|
||||
|
||||
@@ -86,19 +80,7 @@ export async function getTaskLogs(taskId) {
|
||||
* @returns {Promise<Object>} Updated task object.
|
||||
*/
|
||||
export async function resumeTask(taskId, passwords) {
|
||||
const response = await fetch(`${API_BASE}/${taskId}/resume`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ passwords })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.detail || `Failed to resume task: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
return requestApi(`${API_BASE}/${taskId}/resume`, 'POST', { passwords });
|
||||
}
|
||||
// [/DEF:resumeTask:Function]
|
||||
|
||||
@@ -114,19 +96,7 @@ export async function resumeTask(taskId, passwords) {
|
||||
* @returns {Promise<Object>} Updated task object.
|
||||
*/
|
||||
export async function resolveTask(taskId, resolutionParams) {
|
||||
const response = await fetch(`${API_BASE}/${taskId}/resolve`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ resolution_params: resolutionParams })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.detail || `Failed to resolve task: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
return requestApi(`${API_BASE}/${taskId}/resolve`, 'POST', { resolution_params: resolutionParams });
|
||||
}
|
||||
// [/DEF:resolveTask:Function]
|
||||
|
||||
@@ -145,12 +115,6 @@ export async function clearTasks(status = null) {
|
||||
params.append('status', status);
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE}?${params.toString()}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to clear tasks: ${response.statusText}`);
|
||||
}
|
||||
return requestApi(`${API_BASE}?${params.toString()}`, 'DELETE');
|
||||
}
|
||||
// [/DEF:clearTasks:Function]
|
||||
@@ -2,7 +2,9 @@
|
||||
* Service for generic Task API communication used by Tools.
|
||||
*/
|
||||
|
||||
const API_BASE = '/api/tasks';
|
||||
import { requestApi } from '../lib/api';
|
||||
|
||||
const API_BASE = '/tasks';
|
||||
|
||||
// [DEF:runTask:Function]
|
||||
/* @PURPOSE: Start a new task for a given plugin.
|
||||
@@ -16,19 +18,7 @@ const API_BASE = '/api/tasks';
|
||||
* @returns {Promise<Object>} The created task instance.
|
||||
*/
|
||||
export async function runTask(pluginId, params) {
|
||||
const response = await fetch(API_BASE, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ plugin_id: pluginId, params })
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.detail || `Failed to start task: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
return requestApi(API_BASE, 'POST', { plugin_id: pluginId, params });
|
||||
}
|
||||
// [/DEF:runTask:Function]
|
||||
|
||||
@@ -43,10 +33,6 @@ export async function runTask(pluginId, params) {
|
||||
* @returns {Promise<Object>} Task details.
|
||||
*/
|
||||
export async function getTaskStatus(taskId) {
|
||||
const response = await fetch(`${API_BASE}/${taskId}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch task ${taskId}: ${response.statusText}`);
|
||||
}
|
||||
return await response.json();
|
||||
return requestApi(`${API_BASE}/${taskId}`);
|
||||
}
|
||||
// [/DEF:getTaskStatus:Function]
|
||||
Reference in New Issue
Block a user