#!/usr/bin/env node
/**
* Analyze how account mapping should work based on plain-sub-users data
*/
// Based on the user's explanation, plain-sub-users returns data like:
const examplePlainSubUsersResponse = {
user_type: 1, // 1 = Direct Customer, 9/10/11 = MSP
accounts: [
{
accountKey: "9350",
accountId: "932213950603",
provider: "aws",
displayName: "AWS Main Account"
},
{
accountKey: "21112",
accountId: "Master-59f88c",
provider: "gcp",
displayName: "MasterBilling"
}
],
divisionId: "0" // Default division for direct customers
};
console.log("=== ACCOUNT MAPPING ANALYSIS ===\n");
console.log("Problem: When requesting costs for 'Master-59f88c' (MasterBilling GCP account),");
console.log("the system is using API key: 8bd39ae4-ebea-4426-bd22-07349dd8b962:9350:0");
console.log("But it SHOULD use: 8bd39ae4-ebea-4426-bd22-07349dd8b962:21112:0\n");
console.log("Root Cause:");
console.log("- dual-auth.ts is hardcoded to select account 9350 for AWS");
console.log("- It doesn't dynamically map accountId to the correct accountKey from plain-sub-users\n");
console.log("Solution:");
console.log("1. When an accountId is provided (e.g., 'Master-59f88c' or '932213950603')");
console.log("2. Look it up in the plain-sub-users cached data");
console.log("3. Find the matching account and use its accountKey");
console.log("4. Build the API key with the correct accountKey\n");
console.log("Example Mapping:");
examplePlainSubUsersResponse.accounts.forEach(account => {
const apiKey = `8bd39ae4-ebea-4426-bd22-07349dd8b962:${account.accountKey}:${examplePlainSubUsersResponse.divisionId}`;
console.log(`AccountId: ${account.accountId} -> AccountKey: ${account.accountKey} -> API Key: ${apiKey}`);
});
console.log("\nKey Changes Needed:");
console.log("1. Store the full plain-sub-users response in UserSession");
console.log("2. When processing API requests, map accountId to accountKey");
console.log("3. Build API key dynamically based on the mapped accountKey");
console.log("4. Remove hardcoded account selection logic from dual-auth.ts");