docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands - CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround - CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check - NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere - MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates - LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
145
site-manager-api/src/cli/index.ts
Normal file
145
site-manager-api/src/cli/index.ts
Normal file
@@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Site Manager API CLI Tool
|
||||
* Command-line interface for Site Manager Cloud API operations
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { homedir } from 'os';
|
||||
import { SiteManagerClient } from '../client/SiteManagerClient.js';
|
||||
import { HostsService } from '../services/HostsService.js';
|
||||
import { SitesService } from '../services/SitesService.js';
|
||||
import { DevicesService } from '../services/DevicesService.js';
|
||||
import { MetricsService } from '../services/MetricsService.js';
|
||||
|
||||
// Load environment variables
|
||||
const envPath = join(homedir(), '.env');
|
||||
function loadEnvFile(filePath: string): boolean {
|
||||
try {
|
||||
const envFile = readFileSync(filePath, 'utf8');
|
||||
const envVars = envFile.split('\n').filter(
|
||||
(line) => line.includes('=') && !line.trim().startsWith('#')
|
||||
);
|
||||
for (const line of envVars) {
|
||||
const [key, ...values] = line.split('=');
|
||||
if (key && values.length > 0 && /^[A-Z_][A-Z0-9_]*$/.test(key.trim())) {
|
||||
let value = values.join('=').trim();
|
||||
if (
|
||||
(value.startsWith('"') && value.endsWith('"')) ||
|
||||
(value.startsWith("'") && value.endsWith("'"))
|
||||
) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
process.env[key.trim()] = value;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
loadEnvFile(envPath);
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.name('site-manager-cli')
|
||||
.description('CLI tool for UniFi Site Manager Cloud API operations')
|
||||
.version('1.0.0');
|
||||
|
||||
function createClient(): SiteManagerClient {
|
||||
const apiKey = process.env.SITE_MANAGER_API_KEY;
|
||||
if (!apiKey) {
|
||||
throw new Error('SITE_MANAGER_API_KEY environment variable is required');
|
||||
}
|
||||
|
||||
return new SiteManagerClient({
|
||||
apiKey,
|
||||
baseUrl: process.env.SITE_MANAGER_BASE_URL,
|
||||
});
|
||||
}
|
||||
|
||||
// Hosts commands
|
||||
program
|
||||
.command('hosts')
|
||||
.description('List all hosts')
|
||||
.action(async () => {
|
||||
try {
|
||||
const client = createClient();
|
||||
const hostsService = new HostsService(client);
|
||||
const hosts = await hostsService.listHosts();
|
||||
console.log(JSON.stringify(hosts, null, 2));
|
||||
} catch (error) {
|
||||
console.error('Error:', error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Sites commands
|
||||
program
|
||||
.command('sites')
|
||||
.description('List all sites')
|
||||
.action(async () => {
|
||||
try {
|
||||
const client = createClient();
|
||||
const sitesService = new SitesService(client);
|
||||
const sites = await sitesService.listSites();
|
||||
console.log(JSON.stringify(sites, null, 2));
|
||||
} catch (error) {
|
||||
console.error('Error:', error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Devices commands
|
||||
program
|
||||
.command('devices')
|
||||
.description('List all devices')
|
||||
.action(async () => {
|
||||
try {
|
||||
const client = createClient();
|
||||
const devicesService = new DevicesService(client);
|
||||
const devices = await devicesService.listDevices();
|
||||
console.log(JSON.stringify(devices, null, 2));
|
||||
} catch (error) {
|
||||
console.error('Error:', error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Metrics commands
|
||||
program
|
||||
.command('isp-metrics')
|
||||
.description('Get ISP metrics')
|
||||
.action(async () => {
|
||||
try {
|
||||
const client = createClient();
|
||||
const metricsService = new MetricsService(client);
|
||||
const metrics = await metricsService.getISPMetrics();
|
||||
console.log(JSON.stringify(metrics, null, 2));
|
||||
} catch (error) {
|
||||
console.error('Error:', error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
program
|
||||
.command('sd-wan-configs')
|
||||
.description('List SD-WAN configurations')
|
||||
.action(async () => {
|
||||
try {
|
||||
const client = createClient();
|
||||
const metricsService = new MetricsService(client);
|
||||
const configs = await metricsService.listSDWANConfigs();
|
||||
console.log(JSON.stringify(configs, null, 2));
|
||||
} catch (error) {
|
||||
console.error('Error:', error instanceof Error ? error.message : String(error));
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
program.parse();
|
||||
Reference in New Issue
Block a user