#!/usr/bin/env node
import dotenv from 'dotenv';
import { UmbrellaAuth } from './auth.js';
import { UmbrellaApiClient } from './api-client.js';
import { getTestCredentialSets } from './auth-helper.js';
dotenv.config();
async function testMSPCustomerEndpoints() {
console.log('🧪 FOCUSED MSP CUSTOMER ENDPOINT TESTING');
console.log('=====================================');
const baseURL = process.env.UMBRELLA_API_BASE_URL || 'https://api.umbrellacost.io/api/v1';
const credentialSets = getTestCredentialSets();
if (!credentialSets || credentialSets.length === 0) {
console.error('❌ No test credentials available');
return;
}
// Use the MSP account (first credential set)
const mspCreds = credentialSets[0];
console.log(`\n🔍 Testing MSP Account: ${mspCreds.username}`);
console.log('='.repeat(50));
const auth = new UmbrellaAuth(baseURL);
const apiClient = new UmbrellaApiClient(baseURL);
try {
// Authenticate with MSP account
console.log('🔐 Authenticating MSP account...');
await auth.authenticate(mspCreds);
apiClient.setAuthToken(auth.getAuthHeaders());
console.log('✅ MSP authentication successful');
// Test different customer-related endpoints
const customerEndpoints = [
'/user-management/customers',
'/users',
'/user-management/organizations',
'/customers',
'/organizations'
];
for (const endpoint of customerEndpoints) {
console.log(`\n🔍 Testing endpoint: ${endpoint}`);
console.log('-'.repeat(40));
try {
const response = await apiClient.makeRequest(endpoint);
if (response.success && response.data) {
console.log(`✅ SUCCESS: ${endpoint}`);
console.log(` Data type: ${Array.isArray(response.data) ? 'Array' : typeof response.data}`);
if (Array.isArray(response.data)) {
console.log(` Count: ${response.data.length} items`);
if (response.data.length > 0) {
console.log(` Sample keys: ${Object.keys(response.data[0]).join(', ')}`);
}
} else if (typeof response.data === 'object') {
console.log(` Keys: ${Object.keys(response.data).join(', ')}`);
}
} else {
console.log(`❌ FAILED: ${endpoint}`);
console.log(` Error: ${response.error}`);
console.log(` Message: ${response.message || 'No message'}`);
}
} catch (error: any) {
console.log(`❌ EXCEPTION: ${endpoint}`);
console.log(` Error: ${error.message}`);
}
}
// Test with different query parameters
console.log(`\n🔍 Testing /user-management/customers with parameters`);
console.log('-'.repeat(50));
const testParams = [
{},
{ limit: 10 },
{ status: 'active' },
{ type: 'customer' },
{ includeInactive: true },
{ organizationType: 'customer' }
];
for (const params of testParams) {
const paramStr = Object.keys(params).length > 0 ? JSON.stringify(params) : 'no params';
console.log(`\n Testing with params: ${paramStr}`);
try {
const response = await apiClient.makeRequest('/user-management/customers', params);
if (response.success && response.data) {
console.log(` ✅ SUCCESS with ${paramStr}`);
console.log(` Data type: ${Array.isArray(response.data) ? 'Array' : typeof response.data}`);
if (Array.isArray(response.data)) {
console.log(` Count: ${response.data.length} items`);
}
} else {
console.log(` ❌ FAILED with ${paramStr}: ${response.error}`);
}
} catch (error: any) {
console.log(` ❌ EXCEPTION with ${paramStr}: ${error.message}`);
}
}
} catch (error: any) {
console.error(`❌ Authentication failed: ${error.message}`);
}
console.log('\n📊 MSP CUSTOMER ENDPOINT TEST COMPLETE');
console.log('=====================================');
}
testMSPCustomerEndpoints().catch(console.error);