- Grove → Project - Tree → Package - Fruit → Artifact - Graft → Tag - Cultivate → Upload - Harvest → Download Updated across: - Backend models, schemas, and routes - Frontend types, API client, and components - README documentation - API endpoints now use /project/:project/packages pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import { Project, Package, Tag, Artifact, UploadResponse } from './types';
|
|
|
|
const API_BASE = '/api/v1';
|
|
|
|
async function handleResponse<T>(response: Response): Promise<T> {
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({ detail: 'Unknown error' }));
|
|
throw new Error(error.detail || `HTTP ${response.status}`);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
// Project API
|
|
export async function listProjects(): Promise<Project[]> {
|
|
const response = await fetch(`${API_BASE}/projects`);
|
|
return handleResponse<Project[]>(response);
|
|
}
|
|
|
|
export async function createProject(data: { name: string; description?: string; is_public?: boolean }): Promise<Project> {
|
|
const response = await fetch(`${API_BASE}/projects`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data),
|
|
});
|
|
return handleResponse<Project>(response);
|
|
}
|
|
|
|
export async function getProject(name: string): Promise<Project> {
|
|
const response = await fetch(`${API_BASE}/projects/${name}`);
|
|
return handleResponse<Project>(response);
|
|
}
|
|
|
|
// Package API
|
|
export async function listPackages(projectName: string): Promise<Package[]> {
|
|
const response = await fetch(`${API_BASE}/project/${projectName}/packages`);
|
|
return handleResponse<Package[]>(response);
|
|
}
|
|
|
|
export async function createPackage(projectName: string, data: { name: string; description?: string }): Promise<Package> {
|
|
const response = await fetch(`${API_BASE}/project/${projectName}/packages`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data),
|
|
});
|
|
return handleResponse<Package>(response);
|
|
}
|
|
|
|
// Tag API
|
|
export async function listTags(projectName: string, packageName: string): Promise<Tag[]> {
|
|
const response = await fetch(`${API_BASE}/project/${projectName}/${packageName}/tags`);
|
|
return handleResponse<Tag[]>(response);
|
|
}
|
|
|
|
export async function createTag(projectName: string, packageName: string, data: { name: string; artifact_id: string }): Promise<Tag> {
|
|
const response = await fetch(`${API_BASE}/project/${projectName}/${packageName}/tags`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(data),
|
|
});
|
|
return handleResponse<Tag>(response);
|
|
}
|
|
|
|
// Artifact API
|
|
export async function getArtifact(artifactId: string): Promise<Artifact> {
|
|
const response = await fetch(`${API_BASE}/artifact/${artifactId}`);
|
|
return handleResponse<Artifact>(response);
|
|
}
|
|
|
|
// Upload
|
|
export async function uploadArtifact(projectName: string, packageName: string, file: File, tag?: string): Promise<UploadResponse> {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
if (tag) {
|
|
formData.append('tag', tag);
|
|
}
|
|
|
|
const response = await fetch(`${API_BASE}/project/${projectName}/${packageName}/upload`, {
|
|
method: 'POST',
|
|
body: formData,
|
|
});
|
|
return handleResponse<UploadResponse>(response);
|
|
}
|
|
|
|
// Download URL
|
|
export function getDownloadUrl(projectName: string, packageName: string, ref: string): string {
|
|
return `${API_BASE}/project/${projectName}/${packageName}/+/${ref}`;
|
|
}
|