UNPKG

watchtower-node-sdk

Version:

A TypeScript Node.js SDK for the Watchtower API, providing API key management, connection string generation, and more

207 lines 6.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkHealth = checkHealth; exports.verifyOrgApiKey = verifyOrgApiKey; exports.verifyAppApiKey = verifyAppApiKey; exports.createLog = createLog; exports.getLogs = getLogs; exports.analyzeLogs = analyzeLogs; exports.createBatchLogs = createBatchLogs; exports.createTenant = createTenant; exports.validateTenant = validateTenant; exports.getAppStatusOverview = getAppStatusOverview; exports.analyzeCurrentLog = analyzeCurrentLog; exports.getLatestAnalysis = getLatestAnalysis; const index_1 = require("./index"); /** * Required environment variables: * WATCHTOWER_API_URL - The base URL for the Watchtower API * WATCHTOWER_TIMEOUT - (Optional) Request timeout in milliseconds (default: 30000) * * Example .env file: * WATCHTOWER_API_URL=https://api.watchtower.example.com * WATCHTOWER_TIMEOUT=30000 */ // Initialize the SDK const watchtower = new index_1.WatchtowerSDK(); // Example: Check service health async function checkHealth() { try { const response = await watchtower.getHealth(); console.log('Health Status:', response.data); } catch (error) { console.error('Error:', error); } } // Example: Verify organization API key async function verifyOrgApiKey(apiKey) { try { const response = await watchtower.verifyOrganizationApiKey({ apiKey }); console.log('Organization ID:', response.data.organization_id); } catch (error) { console.error('Error:', error); } } // Example: Verify app API key async function verifyAppApiKey(apiKey) { try { const response = await watchtower.verifyAppApiKey({ apiKey }); console.log('App ID:', response.data.app_id); } catch (error) { console.error('Error:', error); } } // Example: Create a log entry async function createLog(organization_apikey, app_apikey, tenant_apikey, item_id, metrics) { try { const response = await watchtower.createLog({ organization_apikey, app_apikey, tenant_apikey, log_entry: { item_id, timestamp: new Date().toISOString(), metrics } }); console.log('Log created:', response.data); } catch (error) { console.error('Error:', error); } } // Example: Retrieve logs async function getLogs(organization_apikey, app_apikey, tenant_apikey, item_id, limit, days) { try { const response = await watchtower.getLogs({ organization_apikey, app_apikey, tenant_apikey, item_id, limit, days }); console.log('Logs:', response.data.logs); console.log('Total count:', response.data.total_count); } catch (error) { console.error('Error:', error); } } // Example: Analyze logs async function analyzeLogs(organization_apikey, app_apikey, tenant_apikey, item_id, limit, days) { try { const response = await watchtower.analyze({ organization_apikey, app_apikey, tenant_apikey, item_id, limit, days }); console.log('Analysis:', response.data); } catch (error) { console.error('Error:', error); } } // Example: Create batch logs async function createBatchLogs(organization_apikey, app_apikey, tenant_apikey, log_entries) { try { const response = await watchtower.createBatchLogs({ organization_apikey, app_apikey, tenant_apikey, log_entries: log_entries.map(entry => ({ ...entry, timestamp: new Date().toISOString() })) }); console.log('Batch logs created:', response.data); } catch (error) { console.error('Error:', error); } } // Example: Create a tenant async function createTenant(org_apikey, app_apikey, client_email) { try { const response = await watchtower.createTenant({ org_apikey, app_apikey, client_email }); console.log('Tenant created:', response.data); } catch (error) { console.error('Error:', error); } } // Example: Validate a tenant async function validateTenant(apikey) { try { const response = await watchtower.validateTenant({ apikey }); console.log('Tenant validation:', response.data); } catch (error) { console.error('Error:', error); } } // Example: Get app status overview async function getAppStatusOverview(organization_apikey, app_apikey, tenant_apikey) { try { const response = await watchtower.getAppStatusOverview({ organization_apikey, app_apikey, tenant_apikey }); console.log('App status:', response.data); } catch (error) { console.error('Error:', error); } } // Example: Analyze current log async function analyzeCurrentLog(organization_apikey, app_apikey, tenant_apikey, item_id, metrics) { try { const response = await watchtower.analyzeCurrent({ organization_apikey, app_apikey, tenant_apikey, log_entry: { item_id, timestamp: new Date().toISOString(), metrics } }); console.log('Current analysis:', response.data); } catch (error) { console.error('Error:', error); } } // Example: Get latest analysis async function getLatestAnalysis(organization_apikey, app_apikey, tenant_apikey, item_id) { try { const response = await watchtower.getLatestAnalysis({ organization_apikey, app_apikey, tenant_apikey, item_id }); console.log('Latest analysis:', response.data); } catch (error) { console.error('Error:', error); } } //# sourceMappingURL=watchtowerapi.js.map