#!/usr/bin/env node
const { spawn } = require('child_process');
class BankHapoalimCosts {
constructor() {
this.server = null;
this.requestId = 1;
}
async start() {
console.log('🏦 BANK HAPOALIM MONTHLY COSTS SINCE JANUARY 2025');
console.log('=================================================');
this.server = spawn('node', ['dist/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
await new Promise(resolve => setTimeout(resolve, 3000));
console.log('✅ Server ready\n');
}
async sendRequest(method, params = {}) {
return new Promise((resolve, reject) => {
const request = {
jsonrpc: '2.0',
id: this.requestId++,
method,
params
};
this.server.stdin.write(JSON.stringify(request) + '\n');
const timeout = setTimeout(() => {
reject(new Error(`Timeout: ${method}`));
}, 30000);
const handleData = (data) => {
clearTimeout(timeout);
this.server.stdout.removeListener('data', handleData);
try {
const lines = data.toString().split('\n').filter(line => line.trim());
for (let i = lines.length - 1; i >= 0; i--) {
const line = lines[i];
if (line.trim()) {
try {
const response = JSON.parse(line);
resolve(response);
return;
} catch (e) {
continue;
}
}
}
reject(new Error('No valid JSON response found'));
} catch (error) {
reject(error);
}
};
this.server.stdout.on('data', handleData);
});
}
async getCostData() {
try {
console.log('🔧 Initialize and Authenticate');
await this.sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: { name: 'Bank Hapoalim Costs', version: '1.0.0' }
});
await this.sendRequest('tools/call', {
name: 'authenticate_user',
arguments: {
username: 'david+allcloud@umbrellacost.com',
password: 'B4*zcI7#F7poEC'
}
});
console.log('✅ Authenticated\n');
console.log('💰 Fetching Bank Hapoalim monthly costs since January 2025...\n');
// Get monthly cost data for Bank Hapoalim
const resp = await this.sendRequest('tools/call', {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-01-01',
endDate: '2025-08-31',
costType: ['cost'],
groupBy: 'none',
periodGranLevel: 'month',
cloud_context: 'aws',
customer_account_key: '16185' // Bank Hapoalim account key
}
});
const content = resp.result?.content?.[0]?.text;
if (content) {
console.log(content);
} else {
console.log('❌ No cost data received');
}
} catch (error) {
console.error('❌ Error:', error.message);
}
}
async cleanup() {
if (this.server) {
this.server.kill();
}
}
async run() {
try {
await this.start();
await this.getCostData();
} finally {
await this.cleanup();
console.log('\n🏁 Bank Hapoalim Cost Query Complete');
}
}
}
const costQuery = new BankHapoalimCosts();
costQuery.run();