fix: remove node_modules

This commit is contained in:
2025-08-25 11:41:29 +02:00
parent d5b8b5d8d4
commit f72e4ba220
614 changed files with 884 additions and 67686 deletions

View File

@@ -1,74 +1,89 @@
/**
* Example usage of the SPORE API Client
* Example usage of the SPORE API Client with Discovery
*/
const SporeApiClient = require('./index');
async function main() {
// Create client instance
const client = new SporeApiClient('http://10.0.1.60');
console.log('🚀 SPORE API Client Example');
console.log('============================\n');
console.log('🚀 SPORE API Client Example with Discovery');
console.log('==========================================\n');
// First, check if we can discover nodes through the backend
console.log('1. Checking for discovered nodes...');
try {
const response = await fetch('http://localhost:3001/api/discovery/nodes');
const discoveryData = await response.json();
if (discoveryData.totalNodes > 0) {
console.log(`✅ Found ${discoveryData.totalNodes} discovered node(s)`);
console.log(`Primary node: ${discoveryData.primaryNode}`);
// Use the discovered primary node
const client = new SporeApiClient(`http://${discoveryData.primaryNode}`);
await runExamples(client);
} else {
console.log('❌ No nodes discovered yet.');
console.log('💡 Start the backend server and send CLUSTER_DISCOVERY messages');
console.log('💡 Use: npm run test-discovery broadcast');
return;
}
} catch (error) {
console.log('❌ Could not connect to backend discovery service');
console.log('💡 Make sure the backend server is running on port 3001');
console.log('💡 Use: npm start');
return;
}
}
async function runExamples(client) {
console.log('\n2. Getting system status...');
try {
// Example 1: Get system status
console.log('1. Getting system status...');
const systemStatus = await client.getSystemStatus();
console.log('✅ System Status:', JSON.stringify(systemStatus, null, 2));
console.log('');
} catch (error) {
console.log('❌ Failed to get system status:', error.message);
}
console.log('');
// Example 2: Get task status
console.log('2. Getting task status...');
console.log('3. Getting task status...');
try {
const taskStatus = await client.getTaskStatus();
console.log('✅ Task Status:', JSON.stringify(taskStatus, null, 2));
console.log('');
} catch (error) {
console.log('❌ Failed to get task status:', error.message);
}
console.log('');
// Example 3: Get device information
console.log('3. Getting device information...');
const deviceInfo = await client.getDeviceInfo();
console.log('✅ Device Info:', JSON.stringify(deviceInfo, null, 2));
console.log('');
// Example 4: Get cluster discovery
console.log('4. Getting cluster discovery...');
console.log('4. Getting cluster discovery...');
try {
const discovery = await client.getClusterDiscovery();
console.log('✅ Cluster Discovery:', JSON.stringify(discovery, null, 2));
console.log('');
// Example 5: Get network configuration
console.log('5. Getting network configuration...');
const networkConfig = await client.getNetworkConfig();
console.log('✅ Network Config:', JSON.stringify(networkConfig, null, 2));
console.log('');
// Example 6: Get health metrics
console.log('6. Getting health metrics...');
const healthMetrics = await client.getHealthMetrics();
console.log('✅ Health Metrics:', JSON.stringify(healthMetrics, null, 2));
console.log('');
// Example 7: Get system logs (limited to 5 entries)
console.log('7. Getting recent system logs...');
const logs = await client.getSystemLogs({ limit: 5 });
console.log('✅ System Logs:', JSON.stringify(logs, null, 2));
console.log('');
console.log('🎉 All API calls completed successfully!');
} catch (error) {
console.error('❌ Error occurred:', error.message);
if (error.message.includes('fetch')) {
console.log('\n💡 Make sure the SPORE device is running and accessible at the specified IP address.');
console.log('💡 Check if the device is powered on and connected to the network.');
}
console.log('❌ Failed to get cluster discovery:', error.message);
}
console.log('');
console.log('🎉 API calls completed!');
}
// Alternative: Direct connection to a specific IP (for testing)
async function directConnection(ip) {
console.log(`\n🔌 Direct connection to ${ip}...`);
const client = new SporeApiClient(`http://${ip}`);
await runExamples(client);
}
// Run the example if this file is executed directly
if (require.main === module) {
main().catch(console.error);
const args = process.argv.slice(2);
if (args.length > 0) {
// Allow direct connection for testing: node example.js 192.168.1.100
directConnection(args[0]).catch(console.error);
} else {
// Use discovery system
main().catch(console.error);
}
}
module.exports = { main };
module.exports = { main, directConnection };

View File

@@ -4,7 +4,10 @@
*/
class SporeApiClient {
constructor(baseUrl = 'http://10.0.1.60') {
constructor(baseUrl) {
if (!baseUrl) {
throw new Error('baseUrl is required for SporeApiClient');
}
this.baseUrl = baseUrl;
this.defaultHeaders = {
'Content-Type': 'application/json',