#!/usr/bin/env node
import dotenv from 'dotenv';
import { UmbrellaAuth } from './auth.js';
import { UmbrellaApiClient } from './api-client.js';
dotenv.config();
async function compareMspVsDirect() {
console.log('π COMPARING MSP vs DIRECT CUSTOMER COST ACCESS');
console.log('==============================================');
const baseURL = process.env.UMBRELLA_API_BASE_URL || 'https://api.umbrellacost.io/api/v1';
const credentials = [
{
type: 'MSP Customer',
username: 'elisha@umbrellacost.cloud',
password: '6K2UX6DoYSgV%E'
},
{
type: 'Direct Customer',
username: 'elisha@umbrellacost.net',
password: 'G37oi57Kp@cNzx'
}
];
const now = new Date();
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
const startDate = startOfMonth.toISOString().split('T')[0];
const endDate = now.toISOString().split('T')[0];
for (const cred of credentials) {
console.log(`\n${'='.repeat(50)}`);
console.log(`π TESTING: ${cred.type} (${cred.username})`);
console.log(`${'='.repeat(50)}`);
try {
// Authenticate
const auth = new UmbrellaAuth(baseURL);
await auth.authenticate(cred);
const apiClient = new UmbrellaApiClient(baseURL);
apiClient.setAuthToken(auth.getAuthHeaders());
console.log(`β
Authentication successful`);
// Get accounts
const accountsResponse = await apiClient.makeRequest('/user-management/accounts');
if (!accountsResponse.success) {
console.log(`β Cannot get accounts: ${accountsResponse.error}`);
continue;
}
const accounts = accountsResponse.data;
console.log(`π Found ${accounts.length} accounts`);
// Show account structure
accounts.slice(0, 2).forEach((account: any, index: number) => {
console.log(`${index + 1}. ${account.accountName}`);
console.log(` ID: ${account.accountId}, Key: ${account.accountKey}`);
});
// Test cost API with different approaches
console.log(`\nπ° Testing cost API approaches:`);
// Approach 1: Try with numeric account if available
const numericAccount = accounts.find((acc: any) => /^\d+$/.test(acc.accountId));
if (numericAccount) {
console.log(`\nπ’ Testing with numeric account: ${numericAccount.accountId}`);
try {
const costResponse = await apiClient.makeRequest('/invoices/caui', {
startDate,
endDate,
accountId: numericAccount.accountId
});
if (costResponse.success) {
console.log(`β
SUCCESS with numeric account!`);
console.log(` Data: ${JSON.stringify(costResponse.data).substring(0, 100)}...`);
} else {
console.log(`β Failed: ${costResponse.error}`);
}
} catch (error: any) {
console.log(`β Error: ${error.message}`);
}
}
// Approach 2: Try without accountId (maybe gives aggregated?)
console.log(`\nπ Testing without accountId (aggregated?):`);
try {
const costResponse = await apiClient.makeRequest('/invoices/caui', {
startDate,
endDate
});
if (costResponse.success) {
console.log(`β
SUCCESS without accountId!`);
console.log(` Data: ${JSON.stringify(costResponse.data).substring(0, 100)}...`);
} else {
console.log(`β Failed: ${costResponse.error}`);
}
} catch (error: any) {
console.log(`β Error: ${error.message}`);
}
// Approach 3: Try with different working endpoints
console.log(`\nπ§ Testing alternative endpoints:`);
const alternativeEndpoints = [
'/user-management/cost-summary',
'/budgets',
'/recommendations/waste-detector'
];
for (const endpoint of alternativeEndpoints) {
try {
const response = await apiClient.makeRequest(endpoint);
if (response.success) {
console.log(`β
${endpoint} - SUCCESS`);
console.log(` Data type: ${typeof response.data}, Items: ${Array.isArray(response.data) ? response.data.length : 'Object'}`);
} else {
console.log(`β ${endpoint} - Failed: ${response.error}`);
}
} catch (error: any) {
console.log(`β ${endpoint} - Error: ${error.message}`);
}
}
} catch (error: any) {
console.log(`β ${cred.type} test failed: ${error.message}`);
}
}
console.log(`\n${'π'.repeat(20)}`);
console.log('COMPARISON COMPLETE');
console.log(`${'π'.repeat(20)}`);
}
compareMspVsDirect().catch(console.error);