initial commit

This commit is contained in:
Maya
2025-07-29 20:36:10 -04:00
parent 2045c2fea3
commit 8f191355d8
4 changed files with 372 additions and 34 deletions

226
package-lock.json generated
View File

@@ -15,6 +15,7 @@
"@sveltejs/vite-plugin-svelte": "^6.0.0",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/vite": "^4.0.0",
"autoprefixer": "^10.4.21",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-svelte": "^3.0.0",
@@ -1835,6 +1836,44 @@
"node": ">= 0.4"
}
},
"node_modules/autoprefixer": {
"version": "10.4.21",
"resolved": "https://registry.npmjs.org/autoprefixer/-/autoprefixer-10.4.21.tgz",
"integrity": "sha512-O+A6LWV5LDHSJD3LjHYoNi4VLsj/Whi7k6zG12xTYaU4cQ8oxQGckXNX8cRHK5yOZ/ppVHe0ZBXGzSV9jXdVbQ==",
"dev": true,
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/postcss/"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/autoprefixer"
},
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"license": "MIT",
"dependencies": {
"browserslist": "^4.24.4",
"caniuse-lite": "^1.0.30001702",
"fraction.js": "^4.3.7",
"normalize-range": "^0.1.2",
"picocolors": "^1.1.1",
"postcss-value-parser": "^4.2.0"
},
"bin": {
"autoprefixer": "bin/autoprefixer"
},
"engines": {
"node": "^10 || ^12 || >=14"
},
"peerDependencies": {
"postcss": "^8.1.0"
}
},
"node_modules/axobject-query": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz",
@@ -1876,6 +1915,39 @@
"node": ">=8"
}
},
"node_modules/browserslist": {
"version": "4.25.1",
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.25.1.tgz",
"integrity": "sha512-KGj0KoOMXLpSNkkEI6Z6mShmQy0bc1I+T7K9N81k4WWMrfz+6fQ6es80B/YLAeRoKvjYE1YSHHOW1qe9xIVzHw==",
"dev": true,
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/browserslist"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/browserslist"
},
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"license": "MIT",
"dependencies": {
"caniuse-lite": "^1.0.30001726",
"electron-to-chromium": "^1.5.173",
"node-releases": "^2.0.19",
"update-browserslist-db": "^1.1.3"
},
"bin": {
"browserslist": "cli.js"
},
"engines": {
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
}
},
"node_modules/callsites": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
@@ -1886,6 +1958,27 @@
"node": ">=6"
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001731",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001731.tgz",
"integrity": "sha512-lDdp2/wrOmTRWuoB5DpfNkC0rJDU8DqRa6nYL6HK6sytw70QMopt/NIc/9SM7ylItlBWfACXk0tEn37UWM/+mg==",
"dev": true,
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/browserslist"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
},
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"license": "CC-BY-4.0"
},
"node_modules/chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
@@ -2056,6 +2149,13 @@
"dev": true,
"license": "MIT"
},
"node_modules/electron-to-chromium": {
"version": "1.5.192",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.192.tgz",
"integrity": "sha512-rP8Ez0w7UNw/9j5eSXCe10o1g/8B1P5SM90PCCMVkIRQn2R0LEHWz4Eh9RnxkniuDe1W0cTSOB3MLlkTGDcuCg==",
"dev": true,
"license": "ISC"
},
"node_modules/enhanced-resolve": {
"version": "5.18.2",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.18.2.tgz",
@@ -2112,6 +2212,16 @@
"@esbuild/win32-x64": "0.25.8"
}
},
"node_modules/escalade": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/escape-string-regexp": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz",
@@ -2487,6 +2597,20 @@
"dev": true,
"license": "ISC"
},
"node_modules/fraction.js": {
"version": "4.3.7",
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz",
"integrity": "sha512-ZsDfxO51wGAXREY55a7la9LScWpwv9RxIrYABrlvOFBlH/ShPnrtsXeuUIfXKKOVicNxQ+o8JTbJvjS4M89yew==",
"dev": true,
"license": "MIT",
"engines": {
"node": "*"
},
"funding": {
"type": "patreon",
"url": "https://github.com/sponsors/rawify"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
@@ -3037,6 +3161,19 @@
"node": ">=8.6"
}
},
"node_modules/micromatch/node_modules/picomatch": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8.6"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/mini-svg-data-uri": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz",
@@ -3152,6 +3289,23 @@
"dev": true,
"license": "MIT"
},
"node_modules/node-releases": {
"version": "2.0.19",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.19.tgz",
"integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==",
"dev": true,
"license": "MIT"
},
"node_modules/normalize-range": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/normalize-range/-/normalize-range-0.1.2.tgz",
"integrity": "sha512-bdok/XvKII3nUpklnV6P2hxtMNrCboOjAcyBuQnWEhO665FwrSNRxU+AqpsyvO6LgGYPspN+lu5CLtw4jPRKNA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/optionator": {
"version": "0.9.4",
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz",
@@ -3243,13 +3397,13 @@
"license": "ISC"
},
"node_modules/picomatch": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz",
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz",
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8.6"
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
@@ -3392,6 +3546,13 @@
"node": ">=4"
}
},
"node_modules/postcss-value-parser": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==",
"dev": true,
"license": "MIT"
},
"node_modules/prelude-ls": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
@@ -3884,19 +4045,6 @@
"url": "https://github.com/sponsors/SuperchupuDev"
}
},
"node_modules/tinyglobby/node_modules/picomatch": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz",
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
@@ -3984,6 +4132,37 @@
"typescript": ">=4.8.4 <5.9.0"
}
},
"node_modules/update-browserslist-db": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.3.tgz",
"integrity": "sha512-UxhIZQ+QInVdunkDAaiazvvT/+fXL5Osr0JZlJulepYu6Jd7qJtDZjlur0emRlT71EN3ScPoE7gvsuIKKNavKw==",
"dev": true,
"funding": [
{
"type": "opencollective",
"url": "https://opencollective.com/browserslist"
},
{
"type": "tidelift",
"url": "https://tidelift.com/funding/github/npm/browserslist"
},
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"license": "MIT",
"dependencies": {
"escalade": "^3.2.0",
"picocolors": "^1.1.1"
},
"bin": {
"update-browserslist-db": "cli.js"
},
"peerDependencies": {
"browserslist": ">= 4.21.0"
}
},
"node_modules/uri-js": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
@@ -4076,19 +4255,6 @@
}
}
},
"node_modules/vite/node_modules/picomatch": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz",
"integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/vitefu": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/vitefu/-/vitefu-1.1.1.tgz",

View File

@@ -21,6 +21,7 @@
"@sveltejs/vite-plugin-svelte": "^6.0.0",
"@tailwindcss/forms": "^0.5.9",
"@tailwindcss/vite": "^4.0.0",
"autoprefixer": "^10.4.21",
"eslint": "^9.18.0",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-svelte": "^3.0.0",

172
src/lib/api-client.ts Normal file
View File

@@ -0,0 +1,172 @@
// API client for HTTP backend (replaces tauri-commands.ts)
import type { NetworkNode, Test, DiagnosticResults, CheckResult, CheckConfig } from './types';
interface ApiResponse<T> {
success: boolean;
data?: T;
error?: string;
}
class ApiClient {
private baseUrl: string;
constructor() {
// Auto-detect API endpoint
if (typeof window !== 'undefined') {
// In browser - use current origin with /api prefix
this.baseUrl = `${window.location.origin}/api`;
} else {
// SSR/build time - use default
this.baseUrl = 'http://localhost:3000/api';
}
}
private async request<T>(
endpoint: string,
options: RequestInit = {}
): Promise<T> {
const url = `${this.baseUrl}${endpoint}`;
const response = await fetch(url, {
headers: {
'Content-Type': 'application/json',
...options.headers,
},
...options,
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const result: ApiResponse<T> = await response.json();
if (!result.success) {
throw new Error(result.error || 'API request failed');
}
return result.data!;
}
// Health check
async health(): Promise<Record<string, string>> {
return this.request('/health');
}
// Node operations
async getNodes(): Promise<NetworkNode[]> {
return this.request('/nodes');
}
async saveNode(node: Omit<NetworkNode, 'id' | 'created_at' | 'updated_at'>): Promise<NetworkNode> {
return this.request('/nodes', {
method: 'POST',
body: JSON.stringify(node),
});
}
async updateNode(id: string, node: Omit<NetworkNode, 'id' | 'created_at' | 'updated_at'>): Promise<NetworkNode> {
return this.request(`/nodes/${id}`, {
method: 'PUT',
body: JSON.stringify(node),
});
}
async deleteNode(id: string): Promise<void> {
return this.request(`/nodes/${id}`, {
method: 'DELETE',
});
}
// Test operations
async getTests(): Promise<Test[]> {
return this.request('/tests');
}
async saveTest(test: Omit<Test, 'id' | 'created_at' | 'updated_at'>): Promise<Test> {
return this.request('/tests', {
method: 'POST',
body: JSON.stringify({
name: test.name,
description: test.description,
version: test.version,
layers: test.layers,
}),
});
}
async updateTest(id: string, test: Omit<Test, 'id' | 'created_at' | 'updated_at'>): Promise<Test> {
return this.request(`/tests/${id}`, {
method: 'PUT',
body: JSON.stringify({
name: test.name,
description: test.description,
version: test.version,
layers: test.layers,
}),
});
}
async deleteTest(id: string): Promise<void> {
return this.request(`/tests/${id}`, {
method: 'DELETE',
});
}
// Diagnostics
async runDiagnostics(testId: string): Promise<DiagnosticResults> {
return this.request(`/diagnostics/run/${testId}`, {
method: 'POST',
});
}
async getDiagnosticResults(testId?: string, limit?: number): Promise<DiagnosticResults[]> {
const params = new URLSearchParams();
if (testId) params.set('test_id', testId);
if (limit) params.set('limit', limit.toString());
const query = params.toString();
return this.request(`/diagnostics/results${query ? `?${query}` : ''}`);
}
// Individual checks
async executeCheck(checkType: string, config: CheckConfig): Promise<CheckResult> {
return this.request(`/checks/${checkType}`, {
method: 'POST',
body: JSON.stringify({ config }),
});
}
// Configuration
async getConfig(): Promise<any> {
return this.request('/config');
}
}
// Export singleton instance
export const apiClient = new ApiClient();
// Export commands interface that matches the existing tauri-commands structure
export const commands = {
// Health
health: () => apiClient.health(),
// Nodes
getNodes: () => apiClient.getNodes(),
saveNode: (node: Omit<NetworkNode, 'id' | 'created_at' | 'updated_at'>) => apiClient.saveNode(node),
updateNode: (id: string, node: Omit<NetworkNode, 'id' | 'created_at' | 'updated_at'>) => apiClient.updateNode(id, node),
deleteNode: (id: string) => apiClient.deleteNode(id),
// Tests
getTests: () => apiClient.getTests(),
saveTest: (test: Omit<Test, 'id' | 'created_at' | 'updated_at'>) => apiClient.saveTest(test),
updateTest: (id: string, test: Omit<Test, 'id' | 'created_at' | 'updated_at'>) => apiClient.updateTest(id, test),
deleteTest: (id: string) => apiClient.deleteTest(id),
// Diagnostics
runDiagnostics: (test: Test) => apiClient.runDiagnostics(test.id),
getDiagnosticResults: (testId?: string, limit?: number) => apiClient.getDiagnosticResults(testId, limit),
// Checks - maintaining the same interface as the original tauri commands
executeCheck: (checkType: string, config: CheckConfig) => apiClient.executeCheck(checkType, config),
};

View File

@@ -80,17 +80,16 @@ export interface Layer {
name: string;
description: string;
checks: Check[];
failureActions?: string[];
}
export interface Test {
id?: string;
id: string;
name: string;
description: string;
version: string;
layers: Layer[];
createdAt?: string;
updatedAt?: string;
createdAt: string;
updatedAt: string;
}
export interface CheckResult {