#!/usr/bin/env node
const { spawn } = require('child_process');
class BankHapoalimUnblendedCosts {
constructor() {
this.server = null;
this.requestId = 1;
}
async start() {
console.log('🏦 BANK HAPOALIM UNBLENDED MONTHLY COSTS COMPARISON');
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 Unblended', 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');
// Test 1: Explicitly UNBLENDED costs
console.log('💰 TEST 1: EXPLICITLY UNBLENDED COSTS (isUnblended=true)');
console.log('=========================================================\n');
const unblendedResp = await this.sendRequest('tools/call', {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-08-01',
endDate: '2025-08-31',
costType: ['cost'],
groupBy: 'none',
periodGranLevel: 'month',
isUnblended: true, // Explicitly request unblended
cloud_context: 'aws',
customer_account_key: '16185'
}
});
const unblendedContent = unblendedResp.result?.content?.[0]?.text;
// Extract the cost from the response
let unblendedCost = 0;
if (unblendedContent) {
const match = unblendedContent.match(/"total_cost":\s*([\d.]+)/);
if (match) {
unblendedCost = parseFloat(match[1]);
}
console.log(`August 2025 Unblended Cost: $${unblendedCost.toFixed(2)}`);
}
// Test 2: AMORTIZED costs
console.log('\n💰 TEST 2: AMORTIZED COSTS (isAmortized=true)');
console.log('=============================================\n');
const amortizedResp = await this.sendRequest('tools/call', {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-08-01',
endDate: '2025-08-31',
costType: ['cost'],
groupBy: 'none',
periodGranLevel: 'month',
isAmortized: true, // Request amortized
cloud_context: 'aws',
customer_account_key: '16185'
}
});
const amortizedContent = amortizedResp.result?.content?.[0]?.text;
// Extract the cost
let amortizedCost = 0;
if (amortizedContent) {
const match = amortizedContent.match(/"total_cost":\s*([\d.]+)/);
if (match) {
amortizedCost = parseFloat(match[1]);
}
console.log(`August 2025 Amortized Cost: $${amortizedCost.toFixed(2)}`);
}
// Test 3: DEFAULT (what we used before - should be unblended)
console.log('\n💰 TEST 3: DEFAULT COSTS (no flags - should default to unblended)');
console.log('=================================================================\n');
const defaultResp = await this.sendRequest('tools/call', {
name: 'api___invoices_caui',
arguments: {
startDate: '2025-08-01',
endDate: '2025-08-31',
costType: ['cost'],
groupBy: 'none',
periodGranLevel: 'month',
cloud_context: 'aws',
customer_account_key: '16185'
}
});
const defaultContent = defaultResp.result?.content?.[0]?.text;
// Extract the cost
let defaultCost = 0;
if (defaultContent) {
const match = defaultContent.match(/"total_cost":\s*([\d.]+)/);
if (match) {
defaultCost = parseFloat(match[1]);
}
console.log(`August 2025 Default Cost: $${defaultCost.toFixed(2)}`);
}
// Summary
console.log('\n📊 COST TYPE COMPARISON FOR AUGUST 2025:');
console.log('=========================================');
console.log(`Unblended (explicit): $${unblendedCost.toFixed(2)}`);
console.log(`Amortized: $${amortizedCost.toFixed(2)}`);
console.log(`Default: $${defaultCost.toFixed(2)}`);
if (Math.abs(defaultCost - unblendedCost) < 0.01) {
console.log('\n✅ Default costs are UNBLENDED (matches explicit unblended)');
} else if (Math.abs(defaultCost - amortizedCost) < 0.01) {
console.log('\n✅ Default costs are AMORTIZED (matches amortized)');
} else {
console.log('\n❓ Default cost type is unclear (doesn\'t match either)');
}
} 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 Type Analysis Complete');
}
}
}
const costQuery = new BankHapoalimUnblendedCosts();
costQuery.run();