@rankcli/agent-runtime 0.0.15 → 0.0.16

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 (202) hide show
  1. package/dist/index.d.mts +43 -393
  2. package/dist/index.d.ts +43 -393
  3. package/dist/index.js +306 -6526
  4. package/dist/index.mjs +202 -6412
  5. package/package.json +6 -1
  6. package/scripts/build-deno.ts +0 -134
  7. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  8. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  9. package/src/analyzers/geo-analyzer.test.ts +0 -310
  10. package/src/analyzers/geo-analyzer.ts +0 -814
  11. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  12. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  13. package/src/analyzers/index.ts +0 -233
  14. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  15. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  16. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  17. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  18. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  19. package/src/analyzers/security-headers-analyzer.ts +0 -318
  20. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  21. package/src/analyzers/structured-data-analyzer.ts +0 -590
  22. package/src/audit/ai/analyzer.ts +0 -347
  23. package/src/audit/ai/index.ts +0 -29
  24. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  25. package/src/audit/ai/types.ts +0 -179
  26. package/src/audit/checks/additional-checks.ts +0 -439
  27. package/src/audit/checks/agent-experience.ts +0 -108
  28. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  29. package/src/audit/checks/ai-content-structure.ts +0 -325
  30. package/src/audit/checks/ai-readiness.ts +0 -406
  31. package/src/audit/checks/anchor-text.ts +0 -179
  32. package/src/audit/checks/answer-conciseness.ts +0 -322
  33. package/src/audit/checks/asset-minification.ts +0 -270
  34. package/src/audit/checks/bing-optimization.ts +0 -206
  35. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  36. package/src/audit/checks/caching-headers.ts +0 -305
  37. package/src/audit/checks/canonical-advanced.ts +0 -150
  38. package/src/audit/checks/canonical-domain.ts +0 -196
  39. package/src/audit/checks/citation-quality.ts +0 -358
  40. package/src/audit/checks/client-rendering.ts +0 -542
  41. package/src/audit/checks/color-contrast.ts +0 -342
  42. package/src/audit/checks/content-freshness.ts +0 -170
  43. package/src/audit/checks/content-science.ts +0 -589
  44. package/src/audit/checks/conversion-elements.ts +0 -526
  45. package/src/audit/checks/crawlability.ts +0 -220
  46. package/src/audit/checks/directory-listing.ts +0 -172
  47. package/src/audit/checks/dom-analysis.ts +0 -191
  48. package/src/audit/checks/dom-size.ts +0 -246
  49. package/src/audit/checks/duplicate-content.ts +0 -194
  50. package/src/audit/checks/eeat-signals.ts +0 -990
  51. package/src/audit/checks/entity-seo.ts +0 -396
  52. package/src/audit/checks/featured-snippet.ts +0 -473
  53. package/src/audit/checks/freshness-signals.ts +0 -443
  54. package/src/audit/checks/funnel-intent.ts +0 -463
  55. package/src/audit/checks/hreflang.ts +0 -174
  56. package/src/audit/checks/html-compliance.ts +0 -302
  57. package/src/audit/checks/image-dimensions.ts +0 -167
  58. package/src/audit/checks/images.ts +0 -160
  59. package/src/audit/checks/indexnow.ts +0 -275
  60. package/src/audit/checks/interactive-tools.ts +0 -475
  61. package/src/audit/checks/internal-link-graph.ts +0 -436
  62. package/src/audit/checks/keyword-analysis.ts +0 -239
  63. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  64. package/src/audit/checks/keyword-placement.ts +0 -471
  65. package/src/audit/checks/links.ts +0 -273
  66. package/src/audit/checks/llms-txt.ts +0 -224
  67. package/src/audit/checks/local-seo.ts +0 -296
  68. package/src/audit/checks/mobile.ts +0 -167
  69. package/src/audit/checks/modern-images.ts +0 -226
  70. package/src/audit/checks/navboost-signals.ts +0 -395
  71. package/src/audit/checks/on-page.ts +0 -209
  72. package/src/audit/checks/page-resources.ts +0 -285
  73. package/src/audit/checks/pagination.ts +0 -180
  74. package/src/audit/checks/performance.ts +0 -153
  75. package/src/audit/checks/platform-presence.ts +0 -580
  76. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  77. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  78. package/src/audit/checks/redirect-analysis.ts +0 -153
  79. package/src/audit/checks/redirect-chain.ts +0 -389
  80. package/src/audit/checks/resource-hints.ts +0 -420
  81. package/src/audit/checks/responsive-css.ts +0 -247
  82. package/src/audit/checks/responsive-images.ts +0 -396
  83. package/src/audit/checks/review-ecosystem.ts +0 -415
  84. package/src/audit/checks/robots-validation.ts +0 -373
  85. package/src/audit/checks/security-headers.ts +0 -188
  86. package/src/audit/checks/security.ts +0 -144
  87. package/src/audit/checks/serp-preview.ts +0 -251
  88. package/src/audit/checks/site-maturity.ts +0 -453
  89. package/src/audit/checks/social-meta.test.ts +0 -275
  90. package/src/audit/checks/social-meta.ts +0 -134
  91. package/src/audit/checks/soft-404.ts +0 -151
  92. package/src/audit/checks/structured-data.ts +0 -238
  93. package/src/audit/checks/tech-detection.ts +0 -496
  94. package/src/audit/checks/topical-clusters.ts +0 -435
  95. package/src/audit/checks/tracker-bloat.ts +0 -462
  96. package/src/audit/checks/tracking-verification.test.ts +0 -371
  97. package/src/audit/checks/tracking-verification.ts +0 -636
  98. package/src/audit/checks/url-safety.ts +0 -682
  99. package/src/audit/deno-entry.ts +0 -66
  100. package/src/audit/discovery/index.ts +0 -15
  101. package/src/audit/discovery/link-crawler.ts +0 -233
  102. package/src/audit/discovery/repo-routes.ts +0 -347
  103. package/src/audit/engine.ts +0 -633
  104. package/src/audit/fixes/index.ts +0 -209
  105. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  106. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  107. package/src/audit/index.ts +0 -74
  108. package/src/audit/runner.test.ts +0 -299
  109. package/src/audit/runner.ts +0 -130
  110. package/src/audit/types.ts +0 -1987
  111. package/src/content/featured-snippet.ts +0 -367
  112. package/src/content/generator.test.ts +0 -534
  113. package/src/content/generator.ts +0 -501
  114. package/src/content/headline.ts +0 -317
  115. package/src/content/index.ts +0 -62
  116. package/src/content/intent.ts +0 -258
  117. package/src/content/keyword-density.ts +0 -349
  118. package/src/content/readability.ts +0 -262
  119. package/src/executor.ts +0 -336
  120. package/src/fixer/framework-fixes.test.ts +0 -489
  121. package/src/fixer/framework-fixes.ts +0 -5287
  122. package/src/fixer/index.ts +0 -6
  123. package/src/fixer/schemas.ts +0 -971
  124. package/src/fixer.ts +0 -642
  125. package/src/frameworks/detector.test.ts +0 -248
  126. package/src/frameworks/detector.ts +0 -899
  127. package/src/frameworks/index.ts +0 -68
  128. package/src/frameworks/recipes/angular.yaml +0 -171
  129. package/src/frameworks/recipes/astro.yaml +0 -206
  130. package/src/frameworks/recipes/django.yaml +0 -180
  131. package/src/frameworks/recipes/laravel.yaml +0 -137
  132. package/src/frameworks/recipes/nextjs.yaml +0 -268
  133. package/src/frameworks/recipes/nuxt.yaml +0 -175
  134. package/src/frameworks/recipes/rails.yaml +0 -188
  135. package/src/frameworks/recipes/react.yaml +0 -202
  136. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  137. package/src/frameworks/recipes/vue.yaml +0 -137
  138. package/src/frameworks/recipes/wordpress.yaml +0 -209
  139. package/src/frameworks/suggestion-engine.ts +0 -357
  140. package/src/geo/geo-content.test.ts +0 -305
  141. package/src/geo/geo-content.ts +0 -266
  142. package/src/geo/geo-history.test.ts +0 -473
  143. package/src/geo/geo-history.ts +0 -433
  144. package/src/geo/geo-tracker.test.ts +0 -359
  145. package/src/geo/geo-tracker.ts +0 -411
  146. package/src/geo/index.ts +0 -11
  147. package/src/geo/llm-citation-checker.ts +0 -188
  148. package/src/git/commit-helper.test.ts +0 -261
  149. package/src/git/commit-helper.ts +0 -329
  150. package/src/git/index.ts +0 -12
  151. package/src/git/pr-helper.test.ts +0 -284
  152. package/src/git/pr-helper.ts +0 -307
  153. package/src/index.ts +0 -76
  154. package/src/keywords/ai-keyword-engine.ts +0 -1062
  155. package/src/keywords/ai-summarizer.ts +0 -387
  156. package/src/keywords/ci-mode.ts +0 -555
  157. package/src/keywords/engine.ts +0 -359
  158. package/src/keywords/index.ts +0 -151
  159. package/src/keywords/llm-judge.ts +0 -357
  160. package/src/keywords/nlp-analysis.ts +0 -706
  161. package/src/keywords/prioritizer.ts +0 -295
  162. package/src/keywords/site-crawler.ts +0 -342
  163. package/src/keywords/sources/autocomplete.ts +0 -139
  164. package/src/keywords/sources/competitive-search.ts +0 -450
  165. package/src/keywords/sources/competitor-analysis.ts +0 -374
  166. package/src/keywords/sources/dataforseo.ts +0 -206
  167. package/src/keywords/sources/free-sources.ts +0 -294
  168. package/src/keywords/sources/gsc.ts +0 -123
  169. package/src/keywords/topic-grouping.ts +0 -327
  170. package/src/keywords/types.ts +0 -144
  171. package/src/keywords/wizard.ts +0 -457
  172. package/src/loader.ts +0 -40
  173. package/src/ranking/index.ts +0 -5
  174. package/src/ranking/serp-client.ts +0 -348
  175. package/src/ranking/tracker.ts +0 -380
  176. package/src/ranking/types.ts +0 -123
  177. package/src/reports/index.ts +0 -7
  178. package/src/reports/report-generator.test.ts +0 -293
  179. package/src/reports/report-generator.ts +0 -713
  180. package/src/scheduler/alerts.test.ts +0 -458
  181. package/src/scheduler/alerts.ts +0 -328
  182. package/src/scheduler/index.ts +0 -8
  183. package/src/scheduler/scheduled-audit.test.ts +0 -377
  184. package/src/scheduler/scheduled-audit.ts +0 -149
  185. package/src/test/integration-test.ts +0 -325
  186. package/src/tools/analyzer.ts +0 -373
  187. package/src/tools/crawl.ts +0 -293
  188. package/src/tools/files.ts +0 -301
  189. package/src/tools/h1-fixer.ts +0 -249
  190. package/src/tools/index.ts +0 -67
  191. package/src/tracking/github-action.ts +0 -326
  192. package/src/tracking/google-analytics.ts +0 -265
  193. package/src/tracking/index.ts +0 -45
  194. package/src/tracking/report-generator.ts +0 -386
  195. package/src/tracking/search-console.ts +0 -335
  196. package/src/types.ts +0 -148
  197. package/src/utils/http.ts +0 -302
  198. package/src/wasm-adapter.ts +0 -297
  199. package/src/wasm-entry.ts +0 -14
  200. package/tsconfig.json +0 -17
  201. package/tsup.wasm.config.ts +0 -26
  202. package/vitest.config.ts +0 -15
@@ -1,374 +0,0 @@
1
- // Competitor Keyword Analysis (SpyFu Kombat-style)
2
- // Analyze competitor rankings to find keyword gaps and opportunities
3
-
4
- import { httpGet } from '../../utils/http.js';
5
- import * as cheerio from 'cheerio';
6
- import type { KeywordData } from '../types.js';
7
-
8
- const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36';
9
-
10
- export interface CompetitorKeywordResult {
11
- // Keywords all competitors rank for (high priority - proven market)
12
- coreKeywords: KeywordData[];
13
- // Keywords competitors rank for but you don't (opportunities)
14
- missingKeywords: KeywordData[];
15
- // Keywords only you rank for (potential advantages)
16
- uniqueKeywords: KeywordData[];
17
- // All keywords any competitor ranks for
18
- keywordUniverse: KeywordData[];
19
- // Overlap analysis
20
- competitorOverlap: CompetitorOverlap[];
21
- }
22
-
23
- export interface CompetitorOverlap {
24
- competitor: string;
25
- sharedKeywords: number;
26
- uniqueToThem: number;
27
- uniqueToYou: number;
28
- }
29
-
30
- export interface CompetitorData {
31
- domain: string;
32
- keywords: Set<string>;
33
- rankings: Map<string, number>; // keyword -> position
34
- }
35
-
36
- /**
37
- * Scrape competitor rankings from Google SERP for seed keywords
38
- * This discovers what keywords competitors appear for
39
- */
40
- export async function discoverCompetitorKeywords(
41
- yourDomain: string,
42
- seedKeywords: string[],
43
- competitors?: string[]
44
- ): Promise<CompetitorKeywordResult> {
45
- const yourKeywords = new Set<string>();
46
- const competitorKeywordsMap = new Map<string, Set<string>>();
47
- const allKeywords = new Map<string, KeywordData>();
48
-
49
- // Initialize competitor tracking
50
- const discoveredCompetitors = new Set<string>(competitors || []);
51
-
52
- console.log(' → Analyzing SERP results for competitor keywords...');
53
-
54
- // For each seed keyword, check who ranks and for what related terms
55
- for (const seed of seedKeywords) {
56
- try {
57
- // Get SERP results
58
- const serpData = await analyzeSERP(seed);
59
-
60
- // Track who ranks for this keyword
61
- for (const result of serpData.results) {
62
- const domain = extractDomain(result.url);
63
-
64
- if (domain === yourDomain || domain.includes(yourDomain) || yourDomain.includes(domain)) {
65
- yourKeywords.add(seed);
66
- } else {
67
- // Discovered competitor
68
- discoveredCompetitors.add(domain);
69
- if (!competitorKeywordsMap.has(domain)) {
70
- competitorKeywordsMap.set(domain, new Set());
71
- }
72
- competitorKeywordsMap.get(domain)!.add(seed);
73
- }
74
-
75
- // Extract keywords from competitor titles/descriptions
76
- const extractedKeywords = extractKeywordsFromText(result.title + ' ' + result.description);
77
- for (const kw of extractedKeywords) {
78
- if (!allKeywords.has(kw)) {
79
- allKeywords.set(kw, {
80
- keyword: kw,
81
- searchVolume: 0,
82
- keywordDifficulty: 0,
83
- source: 'competitor' as const,
84
- });
85
- }
86
-
87
- // Track which domains have this keyword
88
- if (domain === yourDomain || domain.includes(yourDomain)) {
89
- yourKeywords.add(kw);
90
- } else {
91
- competitorKeywordsMap.get(domain)?.add(kw);
92
- }
93
- }
94
- }
95
-
96
- // Also get related searches for more keyword ideas
97
- for (const related of serpData.relatedSearches) {
98
- if (!allKeywords.has(related)) {
99
- allKeywords.set(related, {
100
- keyword: related,
101
- searchVolume: 0,
102
- keywordDifficulty: 0,
103
- source: 'competitor' as const,
104
- });
105
- }
106
- }
107
-
108
- // Avoid rate limiting
109
- await sleep(500);
110
- } catch (error) {
111
- // Continue with other seeds
112
- }
113
- }
114
-
115
- // Calculate keyword categories
116
- const coreKeywords: KeywordData[] = [];
117
- const missingKeywords: KeywordData[] = [];
118
- const uniqueKeywords: KeywordData[] = [];
119
- const keywordUniverse: KeywordData[] = [];
120
-
121
- // Analyze each keyword
122
- for (const [keyword, data] of allKeywords) {
123
- const competitorCount = countCompetitorsWithKeyword(keyword, competitorKeywordsMap);
124
- const youHaveIt = yourKeywords.has(keyword);
125
-
126
- keywordUniverse.push(data);
127
-
128
- if (competitorCount >= 2 && youHaveIt) {
129
- // Core keyword - everyone ranks
130
- coreKeywords.push(data);
131
- } else if (competitorCount >= 1 && !youHaveIt) {
132
- // Missing keyword - competitors have it, you don't
133
- missingKeywords.push(data);
134
- } else if (competitorCount === 0 && youHaveIt) {
135
- // Unique keyword - only you have it
136
- uniqueKeywords.push(data);
137
- }
138
- }
139
-
140
- // Calculate competitor overlap
141
- const competitorOverlap: CompetitorOverlap[] = [];
142
- for (const [domain, keywords] of competitorKeywordsMap) {
143
- const shared = [...keywords].filter(k => yourKeywords.has(k)).length;
144
- const uniqueToThem = [...keywords].filter(k => !yourKeywords.has(k)).length;
145
- const uniqueToYou = [...yourKeywords].filter(k => !keywords.has(k)).length;
146
-
147
- competitorOverlap.push({
148
- competitor: domain,
149
- sharedKeywords: shared,
150
- uniqueToThem,
151
- uniqueToYou,
152
- });
153
- }
154
-
155
- // Sort by number of keywords they have that you don't
156
- competitorOverlap.sort((a, b) => b.uniqueToThem - a.uniqueToThem);
157
-
158
- return {
159
- coreKeywords,
160
- missingKeywords,
161
- uniqueKeywords,
162
- keywordUniverse,
163
- competitorOverlap,
164
- };
165
- }
166
-
167
- interface SERPResult {
168
- url: string;
169
- title: string;
170
- description: string;
171
- position: number;
172
- }
173
-
174
- interface SERPData {
175
- results: SERPResult[];
176
- relatedSearches: string[];
177
- peopleAlsoAsk: string[];
178
- }
179
-
180
- async function analyzeSERP(query: string): Promise<SERPData> {
181
- try {
182
- const response = await httpGet<string>('https://www.google.com/search', {
183
- params: { q: query, num: 20 },
184
- headers: { 'User-Agent': USER_AGENT },
185
- timeout: 10000,
186
- });
187
-
188
- const $ = cheerio.load(response.data);
189
- const results: SERPResult[] = [];
190
- const relatedSearches: string[] = [];
191
- const peopleAlsoAsk: string[] = [];
192
-
193
- // Extract search results
194
- let position = 1;
195
- $('div.g').each((_, el) => {
196
- const link = $(el).find('a').first();
197
- const url = link.attr('href');
198
- const title = $(el).find('h3').text().trim();
199
- const description = $(el).find('.VwiC3b').text().trim() ||
200
- $(el).find('[data-content-feature]').text().trim();
201
-
202
- if (url && url.startsWith('http') && title) {
203
- results.push({ url, title, description, position });
204
- position++;
205
- }
206
- });
207
-
208
- // Extract related searches
209
- $('div[data-ved] a').each((_, el) => {
210
- const href = $(el).attr('href');
211
- if (href?.includes('/search?q=')) {
212
- const text = $(el).text().trim();
213
- if (text.length > 3 && text.length < 100 && !text.includes('http')) {
214
- relatedSearches.push(text);
215
- }
216
- }
217
- });
218
-
219
- // Extract People Also Ask
220
- $('[data-sgrd]').each((_, el) => {
221
- const text = $(el).text().trim();
222
- if (text.endsWith('?') && text.length > 10) {
223
- peopleAlsoAsk.push(text);
224
- }
225
- });
226
-
227
- return {
228
- results,
229
- relatedSearches: [...new Set(relatedSearches)],
230
- peopleAlsoAsk: [...new Set(peopleAlsoAsk)],
231
- };
232
- } catch {
233
- return { results: [], relatedSearches: [], peopleAlsoAsk: [] };
234
- }
235
- }
236
-
237
- function extractDomain(url: string): string {
238
- try {
239
- const parsed = new URL(url);
240
- return parsed.hostname.replace(/^www\./, '');
241
- } catch {
242
- return '';
243
- }
244
- }
245
-
246
- function extractKeywordsFromText(text: string): string[] {
247
- // Extract 2-4 word phrases that could be keywords
248
- const words = text.toLowerCase()
249
- .replace(/[^\w\s]/g, ' ')
250
- .split(/\s+/)
251
- .filter(w => w.length > 2);
252
-
253
- const keywords: string[] = [];
254
-
255
- // Single words (4+ chars)
256
- words.filter(w => w.length >= 4).forEach(w => keywords.push(w));
257
-
258
- // 2-word phrases
259
- for (let i = 0; i < words.length - 1; i++) {
260
- const phrase = `${words[i]} ${words[i + 1]}`;
261
- if (phrase.length >= 5 && phrase.length <= 50) {
262
- keywords.push(phrase);
263
- }
264
- }
265
-
266
- // 3-word phrases
267
- for (let i = 0; i < words.length - 2; i++) {
268
- const phrase = `${words[i]} ${words[i + 1]} ${words[i + 2]}`;
269
- if (phrase.length >= 8 && phrase.length <= 60) {
270
- keywords.push(phrase);
271
- }
272
- }
273
-
274
- return [...new Set(keywords)];
275
- }
276
-
277
- function countCompetitorsWithKeyword(
278
- keyword: string,
279
- competitorKeywordsMap: Map<string, Set<string>>
280
- ): number {
281
- let count = 0;
282
- for (const [, keywords] of competitorKeywordsMap) {
283
- if (keywords.has(keyword)) {
284
- count++;
285
- }
286
- }
287
- return count;
288
- }
289
-
290
- function sleep(ms: number): Promise<void> {
291
- return new Promise(resolve => setTimeout(resolve, ms));
292
- }
293
-
294
- /**
295
- * Format competitor analysis report
296
- */
297
- export function formatCompetitorReport(result: CompetitorKeywordResult): string {
298
- const lines: string[] = [];
299
-
300
- lines.push('');
301
- lines.push('═'.repeat(70));
302
- lines.push(' COMPETITOR KEYWORD ANALYSIS');
303
- lines.push('═'.repeat(70));
304
- lines.push('');
305
-
306
- // Competitor overlap summary
307
- if (result.competitorOverlap.length > 0) {
308
- lines.push('📊 COMPETITOR OVERLAP');
309
- lines.push('─'.repeat(70));
310
- lines.push(' Domain Shared Gaps Your Wins');
311
- lines.push(' ' + '─'.repeat(60));
312
-
313
- for (const comp of result.competitorOverlap.slice(0, 5)) {
314
- const domain = comp.competitor.substring(0, 30).padEnd(32);
315
- const shared = String(comp.sharedKeywords).padStart(6);
316
- const gaps = String(comp.uniqueToThem).padStart(6);
317
- const wins = String(comp.uniqueToYou).padStart(8);
318
- lines.push(` ${domain} ${shared} ${gaps} ${wins}`);
319
- }
320
- lines.push('');
321
- }
322
-
323
- // Missing keywords (opportunities)
324
- if (result.missingKeywords.length > 0) {
325
- lines.push('🔴 KEYWORD GAPS (Competitors Rank, You Don\'t)');
326
- lines.push('─'.repeat(70));
327
- lines.push(' These are high-priority opportunities - competitors have proven');
328
- lines.push(' these keywords work in your market.');
329
- lines.push('');
330
-
331
- for (const kw of result.missingKeywords.slice(0, 10)) {
332
- lines.push(` • ${kw.keyword}`);
333
- }
334
- lines.push('');
335
- }
336
-
337
- // Core keywords
338
- if (result.coreKeywords.length > 0) {
339
- lines.push('🟢 CORE KEYWORDS (All Competitors Rank)');
340
- lines.push('─'.repeat(70));
341
- lines.push(' These keywords define your market. You should rank for these.');
342
- lines.push('');
343
-
344
- for (const kw of result.coreKeywords.slice(0, 10)) {
345
- lines.push(` • ${kw.keyword}`);
346
- }
347
- lines.push('');
348
- }
349
-
350
- // Unique keywords
351
- if (result.uniqueKeywords.length > 0) {
352
- lines.push('🔵 YOUR UNIQUE KEYWORDS (Only You Rank)');
353
- lines.push('─'.repeat(70));
354
- lines.push(' Potential competitive advantages or niche opportunities.');
355
- lines.push('');
356
-
357
- for (const kw of result.uniqueKeywords.slice(0, 10)) {
358
- lines.push(` • ${kw.keyword}`);
359
- }
360
- lines.push('');
361
- }
362
-
363
- // Summary stats
364
- lines.push('📈 SUMMARY');
365
- lines.push('─'.repeat(70));
366
- lines.push(` Total Keywords Analyzed: ${result.keywordUniverse.length}`);
367
- lines.push(` Core Keywords: ${result.coreKeywords.length}`);
368
- lines.push(` Keyword Gaps: ${result.missingKeywords.length}`);
369
- lines.push(` Your Unique Keywords: ${result.uniqueKeywords.length}`);
370
- lines.push('');
371
- lines.push('═'.repeat(70));
372
-
373
- return lines.join('\n');
374
- }
@@ -1,206 +0,0 @@
1
- // DataForSEO API Integration (Budget-Friendly Paid Option)
2
- // Pricing: ~$0.002 per request, $50 minimum deposit
3
-
4
- import { httpGet, httpPost } from '../../utils/http.js';
5
- import type { KeywordData } from '../types.js';
6
-
7
- const DATAFORSEO_BASE_URL = 'https://api.dataforseo.com/v3';
8
-
9
- export interface DataForSEOCredentials {
10
- login: string;
11
- password: string;
12
- }
13
-
14
- export interface DataForSEOKeywordResult {
15
- keyword: string;
16
- search_volume: number;
17
- keyword_difficulty: number;
18
- cpc: number;
19
- competition: number;
20
- competition_level: string;
21
- monthly_searches?: Array<{ month: string; search_volume: number }>;
22
- }
23
-
24
- // Get keyword data with search volume and difficulty
25
- export async function getKeywordData(
26
- keywords: string[],
27
- credentials: DataForSEOCredentials,
28
- location: number = 2840 // US
29
- ): Promise<KeywordData[]> {
30
- const auth = Buffer.from(`${credentials.login}:${credentials.password}`).toString('base64');
31
-
32
- try {
33
- const response = await httpPost(
34
- `${DATAFORSEO_BASE_URL}/keywords_data/google_ads/search_volume/live`,
35
- [
36
- {
37
- keywords,
38
- location_code: location,
39
- language_code: 'en',
40
- },
41
- ],
42
- {
43
- headers: {
44
- Authorization: `Basic ${auth}`,
45
- 'Content-Type': 'application/json',
46
- },
47
- timeout: 30000,
48
- }
49
- );
50
-
51
- const data = response.data as { tasks?: Array<{ result?: DataForSEOKeywordResult[] }> };
52
- const results: DataForSEOKeywordResult[] = data?.tasks?.[0]?.result || [];
53
-
54
- return results.map((r) => ({
55
- keyword: r.keyword,
56
- searchVolume: r.search_volume || 0,
57
- keywordDifficulty: r.keyword_difficulty || estimateKdFromCompetition(r.competition),
58
- cpc: r.cpc,
59
- source: 'dataforseo' as const,
60
- }));
61
- } catch (error) {
62
- console.error('DataForSEO API error:', error);
63
- throw new Error(`DataForSEO API failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
64
- }
65
- }
66
-
67
- // Get keyword suggestions from seed keyword
68
- export async function getKeywordSuggestions(
69
- seedKeyword: string,
70
- credentials: DataForSEOCredentials,
71
- location: number = 2840,
72
- limit: number = 100
73
- ): Promise<KeywordData[]> {
74
- const auth = Buffer.from(`${credentials.login}:${credentials.password}`).toString('base64');
75
-
76
- try {
77
- const response = await httpPost(
78
- `${DATAFORSEO_BASE_URL}/dataforseo_labs/google/keyword_suggestions/live`,
79
- [
80
- {
81
- keyword: seedKeyword,
82
- location_code: location,
83
- language_code: 'en',
84
- include_seed_keyword: true,
85
- limit,
86
- },
87
- ],
88
- {
89
- headers: {
90
- Authorization: `Basic ${auth}`,
91
- 'Content-Type': 'application/json',
92
- },
93
- timeout: 30000,
94
- }
95
- );
96
-
97
- const data = response.data as { tasks?: Array<{ result?: Array<{ items?: unknown[] }> }> };
98
- const results = data?.tasks?.[0]?.result?.[0]?.items || [];
99
-
100
- return results.map((item) => {
101
- const i = item as { keyword_data: DataForSEOKeywordResult };
102
- return {
103
- keyword: i.keyword_data.keyword,
104
- searchVolume: i.keyword_data.search_volume || 0,
105
- keywordDifficulty: i.keyword_data.keyword_difficulty || 0,
106
- cpc: i.keyword_data.cpc,
107
- source: 'dataforseo' as const,
108
- };
109
- });
110
- } catch (error) {
111
- console.error('DataForSEO suggestions error:', error);
112
- throw new Error(`DataForSEO API failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
113
- }
114
- }
115
-
116
- // Get related keywords
117
- export async function getRelatedKeywords(
118
- seedKeyword: string,
119
- credentials: DataForSEOCredentials,
120
- location: number = 2840,
121
- limit: number = 50
122
- ): Promise<KeywordData[]> {
123
- const auth = Buffer.from(`${credentials.login}:${credentials.password}`).toString('base64');
124
-
125
- try {
126
- const response = await httpPost(
127
- `${DATAFORSEO_BASE_URL}/dataforseo_labs/google/related_keywords/live`,
128
- [
129
- {
130
- keyword: seedKeyword,
131
- location_code: location,
132
- language_code: 'en',
133
- limit,
134
- },
135
- ],
136
- {
137
- headers: {
138
- Authorization: `Basic ${auth}`,
139
- 'Content-Type': 'application/json',
140
- },
141
- timeout: 30000,
142
- }
143
- );
144
-
145
- const data = response.data as { tasks?: Array<{ result?: Array<{ items?: unknown[] }> }> };
146
- const results = data?.tasks?.[0]?.result?.[0]?.items || [];
147
-
148
- return results.map((item) => {
149
- const i = item as { keyword_data: DataForSEOKeywordResult };
150
- return {
151
- keyword: i.keyword_data.keyword,
152
- searchVolume: i.keyword_data.search_volume || 0,
153
- keywordDifficulty: i.keyword_data.keyword_difficulty || 0,
154
- cpc: i.keyword_data.cpc,
155
- source: 'dataforseo' as const,
156
- };
157
- });
158
- } catch (error) {
159
- console.error('DataForSEO related keywords error:', error);
160
- return [];
161
- }
162
- }
163
-
164
- // Estimate KD from competition value (0-1)
165
- function estimateKdFromCompetition(competition: number): number {
166
- // Competition is Google Ads competition (0-1)
167
- // Map to KD scale (0-100)
168
- return Math.round(competition * 100);
169
- }
170
-
171
- // Location codes reference
172
- export const LOCATION_CODES = {
173
- US: 2840,
174
- UK: 2826,
175
- CA: 2124,
176
- AU: 2036,
177
- DE: 2276,
178
- FR: 2250,
179
- ES: 2724,
180
- IT: 2380,
181
- BR: 2076,
182
- IN: 2356,
183
- JP: 2392,
184
- };
185
-
186
- // Check API balance
187
- export async function checkBalance(credentials: DataForSEOCredentials): Promise<number> {
188
- const auth = Buffer.from(`${credentials.login}:${credentials.password}`).toString('base64');
189
-
190
- try {
191
- const response = await httpGet<string>(
192
- `${DATAFORSEO_BASE_URL}/appendix/user_data`,
193
- {
194
- headers: {
195
- Authorization: `Basic ${auth}`,
196
- },
197
- }
198
- );
199
-
200
- const data = typeof response.data === 'string' ? JSON.parse(response.data) : response.data;
201
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
202
- return (data as any)?.tasks?.[0]?.result?.[0]?.money?.balance || 0;
203
- } catch {
204
- return 0;
205
- }
206
- }