@merlean/analyzer 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/analyzer.js +30 -4
  2. package/package.json +1 -1
package/lib/analyzer.js CHANGED
@@ -131,6 +131,25 @@ function extractApiPatterns(content, filePath) {
131
131
 
132
132
  let hasApiCalls = false;
133
133
  const extractedBlocks = [];
134
+
135
+ // FIRST: Extract API base URL definitions (critical for resolving paths)
136
+ const baseUrlDefinitions = [];
137
+ for (let i = 0; i < lines.length; i++) {
138
+ const line = lines[i];
139
+ // Match: const API_BASE = ..., const baseURL = ..., const apiUrl = ..., etc.
140
+ if (/^\s*(const|let|var)\s+(API_BASE|API_URL|BASE_URL|baseURL|apiUrl|apiBase|API_ENDPOINT)/i.test(line)) {
141
+ baseUrlDefinitions.push(`${i + 1}: ${line}`);
142
+ }
143
+ // Also match: axios.defaults.baseURL = ...
144
+ if (/baseURL\s*[:=]/i.test(line)) {
145
+ baseUrlDefinitions.push(`${i + 1}: ${line}`);
146
+ }
147
+ }
148
+
149
+ if (baseUrlDefinitions.length > 0) {
150
+ extractedBlocks.push('// API BASE URL DEFINITIONS (use these to resolve full paths):\n' + baseUrlDefinitions.join('\n'));
151
+ hasApiCalls = true;
152
+ }
134
153
 
135
154
  // Line-by-line extraction with context
136
155
  for (let i = 0; i < lines.length; i++) {
@@ -142,14 +161,21 @@ function extractApiPatterns(content, filePath) {
142
161
  patterns.forEach(p => p.regex.lastIndex = 0);
143
162
 
144
163
  // Also check for common API keywords
145
- const hasKeyword = /fetch|axios|\.ajax|\.get\(|\.post\(|\.put\(|\.delete\(|\/api\/|endpoint|baseURL/i.test(line);
164
+ const hasKeyword = /fetch|axios|\.ajax|\.get\(|\.post\(|\.put\(|\.delete\(|\/api\/|endpoint/i.test(line);
165
+
166
+ // Check if this is a POST/PUT request - need more context for body structure
167
+ const isPostRequest = /method:\s*['"]POST|\.post\(|method:\s*['"]PUT|\.put\(/i.test(line);
146
168
 
147
169
  if (hasPattern || hasKeyword) {
148
170
  hasApiCalls = true;
149
171
 
150
- // Get context: 3 lines before and 5 lines after
151
- const startLine = Math.max(0, i - 3);
152
- const endLine = Math.min(lines.length - 1, i + 5);
172
+ // Get MORE context for POST/PUT requests to capture body structure definitions
173
+ // Body objects are often defined 15-25 lines before the fetch call
174
+ const contextBefore = isPostRequest ? 25 : 3; // More context for POST
175
+ const contextAfter = isPostRequest ? 10 : 5;
176
+
177
+ const startLine = Math.max(0, i - contextBefore);
178
+ const endLine = Math.min(lines.length - 1, i + contextAfter);
153
179
 
154
180
  const block = lines.slice(startLine, endLine + 1)
155
181
  .map((l, idx) => `${startLine + idx + 1}: ${l}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merlean/analyzer",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "AI Bot codebase analyzer - generates site maps for AI assistant integration",
5
5
  "keywords": ["ai", "bot", "analyzer", "claude", "anthropic", "widget"],
6
6
  "author": "zmaren",