#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
console.log('🔍 VERIFYING: Will apikey be in headers after restart?\n');
console.log('='.repeat(80));
const apiClientPath = path.join(__dirname, '../../src/api-client.ts');
const apiClientCode = fs.readFileSync(apiClientPath, 'utf8');
console.log('\nđź“‹ STEP 1: Check how apikey is added to headers\n');
console.log('-'.repeat(80));
// Find getAuthHeaders function
const getAuthHeadersMatch = apiClientCode.match(/private getAuthHeaders\([\s\S]*?\n \}/);
if (getAuthHeadersMatch) {
console.log('Found getAuthHeaders function:');
const lines = getAuthHeadersMatch[0].split('\n').slice(0, 20);
lines.forEach(line => console.log(' ', line));
}
console.log('\nđź“‹ STEP 2: Check where headers are sent in request\n');
console.log('-'.repeat(80));
// Find where axios config is built
const axiosConfigMatches = apiClientCode.match(/const config.*?=.*?\{[\s\S]*?headers:[\s\S]*?\}/g);
if (axiosConfigMatches) {
console.log('Found axios config building:');
axiosConfigMatches.forEach((match, i) => {
if (match.includes('getAuthHeaders')) {
console.log(`\nConfig ${i + 1} (includes getAuthHeaders):`);
console.log(match.substring(0, 300) + '...');
}
});
}
console.log('\nđź“‹ STEP 3: Check recommendations-specific code\n');
console.log('-'.repeat(80));
// Check recommendations list handling
const recsListMatch = apiClientCode.match(/if \(path === '\/v2\/recommendations\/list'\)[\s\S]*?\}/);
if (recsListMatch) {
console.log('Found /v2/recommendations/list handling:');
console.log(recsListMatch[0]);
}
// Check recommendations heatmap handling
const recsHeatmapMatch = apiClientCode.match(/if \(path === '\/v1\/recommendationsNew\/heatmap\/summary'\)[\s\S]*?\}/);
if (recsHeatmapMatch) {
console.log('\nFound /v1/recommendationsNew/heatmap/summary handling:');
console.log(recsHeatmapMatch[0]);
}
console.log('\nđź“‹ STEP 4: Trace the complete flow\n');
console.log('-'.repeat(80));
console.log(`
EXPECTED FLOW AFTER RESTART:
1. Claude sends: {accountKey: "24223", divisionId: "1"}
2. server-with-auth.ts validates with QueryParamsSchema (NOW includes accountKey)
3. validatedParams.accountKey = "24223" âś…
4. Mapping happens:
validatedParams.customer_account_key = "24223"
validatedParams.customer_division_id = "1"
5. api-client.ts makeRequest() is called with:
params: {customer_account_key: "24223", customer_division_id: "1"}
6. getAuthHeaders(customerAccountKey="24223", customerDivisionId="1") is called
7. In getAuthHeaders:
- Extracts base key: "57ade50e-c9a8-49f3-8ce7-28d44536a669"
- Builds: apiKey = baseKey + ":" + customerAccountKey + ":" + customerDivisionId
- Result: "57ade50e-c9a8-49f3-8ce7-28d44536a669:24223:1"
8. Returns headers object with:
{
"Authorization": "Bearer [token]",
"apikey": "57ade50e-c9a8-49f3-8ce7-28d44536a669:24223:1"
}
`);
console.log('\nđź“‹ STEP 5: Check current getAuthHeaders implementation\n');
console.log('-'.repeat(80));
// Find the specific part that builds customer API key
const customerKeyBuildMatch = apiClientCode.match(/\/\/ 1\. Customer-specific account key[\s\S]*?if \(customerAccountKey\) \{[\s\S]*?\}/);
if (customerKeyBuildMatch) {
console.log('Customer API key building logic:');
console.log(customerKeyBuildMatch[0]);
}
console.log('\nđź“‹ STEP 6: CRITICAL CHECK - Is apikey added to ALL requests?\n');
console.log('-'.repeat(80));
// Check if apikey is always in headers
const headersAlwaysHasApikey = apiClientCode.includes('apikey: apiKey');
console.log(`Headers object includes apikey: ${headersAlwaysHasApikey}`);
// Check the actual headers construction
const headersConstruction = apiClientCode.match(/return \{[\s\S]*?Authorization:[\s\S]*?apikey:[\s\S]*?\}/);
if (headersConstruction) {
console.log('\nHeaders construction in getAuthHeaders:');
console.log(headersConstruction[0]);
}
console.log('\n' + '='.repeat(80));
console.log('CONCLUSION:');
console.log('='.repeat(80));
console.log(`
After restart, the apikey WILL be in headers IF:
1. âś… accountKey passes validation (fixed by adding to schema)
2. âś… Gets mapped to customer_account_key (server-with-auth.ts lines 776-777)
3. âś… api-client receives customerAccountKey parameter
4. âś… getAuthHeaders builds the correct apikey
5. âś… Headers object includes the apikey field
ALL CONDITIONS ARE MET - apikey will be in headers!
Expected header: apikey: "57ade50e-c9a8-49f3-8ce7-28d44536a669:24223:1"
`);