@rankcli/agent-runtime 0.0.14 → 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 (199) hide show
  1. package/dist/index.d.mts +77 -393
  2. package/dist/index.d.ts +77 -393
  3. package/dist/index.js +417 -6443
  4. package/dist/index.mjs +296 -6313
  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/ai-citation-worthiness.ts +0 -399
  28. package/src/audit/checks/ai-content-structure.ts +0 -325
  29. package/src/audit/checks/ai-readiness.ts +0 -339
  30. package/src/audit/checks/anchor-text.ts +0 -179
  31. package/src/audit/checks/answer-conciseness.ts +0 -322
  32. package/src/audit/checks/asset-minification.ts +0 -270
  33. package/src/audit/checks/bing-optimization.ts +0 -206
  34. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  35. package/src/audit/checks/caching-headers.ts +0 -305
  36. package/src/audit/checks/canonical-advanced.ts +0 -150
  37. package/src/audit/checks/canonical-domain.ts +0 -196
  38. package/src/audit/checks/citation-quality.ts +0 -358
  39. package/src/audit/checks/client-rendering.ts +0 -542
  40. package/src/audit/checks/color-contrast.ts +0 -342
  41. package/src/audit/checks/content-freshness.ts +0 -170
  42. package/src/audit/checks/content-science.ts +0 -589
  43. package/src/audit/checks/conversion-elements.ts +0 -526
  44. package/src/audit/checks/crawlability.ts +0 -220
  45. package/src/audit/checks/directory-listing.ts +0 -172
  46. package/src/audit/checks/dom-analysis.ts +0 -191
  47. package/src/audit/checks/dom-size.ts +0 -246
  48. package/src/audit/checks/duplicate-content.ts +0 -194
  49. package/src/audit/checks/eeat-signals.ts +0 -990
  50. package/src/audit/checks/entity-seo.ts +0 -396
  51. package/src/audit/checks/featured-snippet.ts +0 -473
  52. package/src/audit/checks/freshness-signals.ts +0 -443
  53. package/src/audit/checks/funnel-intent.ts +0 -463
  54. package/src/audit/checks/hreflang.ts +0 -174
  55. package/src/audit/checks/html-compliance.ts +0 -302
  56. package/src/audit/checks/image-dimensions.ts +0 -167
  57. package/src/audit/checks/images.ts +0 -160
  58. package/src/audit/checks/indexnow.ts +0 -275
  59. package/src/audit/checks/interactive-tools.ts +0 -475
  60. package/src/audit/checks/internal-link-graph.ts +0 -436
  61. package/src/audit/checks/keyword-analysis.ts +0 -239
  62. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  63. package/src/audit/checks/keyword-placement.ts +0 -471
  64. package/src/audit/checks/links.ts +0 -273
  65. package/src/audit/checks/llms-txt.ts +0 -224
  66. package/src/audit/checks/local-seo.ts +0 -296
  67. package/src/audit/checks/mobile.ts +0 -167
  68. package/src/audit/checks/modern-images.ts +0 -226
  69. package/src/audit/checks/navboost-signals.ts +0 -395
  70. package/src/audit/checks/on-page.ts +0 -209
  71. package/src/audit/checks/page-resources.ts +0 -285
  72. package/src/audit/checks/pagination.ts +0 -180
  73. package/src/audit/checks/performance.ts +0 -153
  74. package/src/audit/checks/platform-presence.ts +0 -580
  75. package/src/audit/checks/redirect-analysis.ts +0 -153
  76. package/src/audit/checks/redirect-chain.ts +0 -389
  77. package/src/audit/checks/resource-hints.ts +0 -420
  78. package/src/audit/checks/responsive-css.ts +0 -247
  79. package/src/audit/checks/responsive-images.ts +0 -396
  80. package/src/audit/checks/review-ecosystem.ts +0 -415
  81. package/src/audit/checks/robots-validation.ts +0 -373
  82. package/src/audit/checks/security-headers.ts +0 -188
  83. package/src/audit/checks/security.ts +0 -144
  84. package/src/audit/checks/serp-preview.ts +0 -251
  85. package/src/audit/checks/site-maturity.ts +0 -453
  86. package/src/audit/checks/social-meta.test.ts +0 -275
  87. package/src/audit/checks/social-meta.ts +0 -134
  88. package/src/audit/checks/soft-404.ts +0 -151
  89. package/src/audit/checks/structured-data.ts +0 -238
  90. package/src/audit/checks/tech-detection.ts +0 -496
  91. package/src/audit/checks/topical-clusters.ts +0 -435
  92. package/src/audit/checks/tracker-bloat.ts +0 -462
  93. package/src/audit/checks/tracking-verification.test.ts +0 -371
  94. package/src/audit/checks/tracking-verification.ts +0 -636
  95. package/src/audit/checks/url-safety.ts +0 -682
  96. package/src/audit/deno-entry.ts +0 -66
  97. package/src/audit/discovery/index.ts +0 -15
  98. package/src/audit/discovery/link-crawler.ts +0 -233
  99. package/src/audit/discovery/repo-routes.ts +0 -347
  100. package/src/audit/engine.ts +0 -627
  101. package/src/audit/fixes/index.ts +0 -209
  102. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  103. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  104. package/src/audit/index.ts +0 -74
  105. package/src/audit/runner.test.ts +0 -299
  106. package/src/audit/runner.ts +0 -130
  107. package/src/audit/types.ts +0 -1963
  108. package/src/content/featured-snippet.ts +0 -367
  109. package/src/content/generator.test.ts +0 -534
  110. package/src/content/generator.ts +0 -501
  111. package/src/content/headline.ts +0 -317
  112. package/src/content/index.ts +0 -62
  113. package/src/content/intent.ts +0 -258
  114. package/src/content/keyword-density.ts +0 -349
  115. package/src/content/readability.ts +0 -262
  116. package/src/executor.ts +0 -336
  117. package/src/fixer/framework-fixes.test.ts +0 -489
  118. package/src/fixer/framework-fixes.ts +0 -5287
  119. package/src/fixer/index.ts +0 -6
  120. package/src/fixer/schemas.ts +0 -971
  121. package/src/fixer.ts +0 -642
  122. package/src/frameworks/detector.test.ts +0 -248
  123. package/src/frameworks/detector.ts +0 -899
  124. package/src/frameworks/index.ts +0 -68
  125. package/src/frameworks/recipes/angular.yaml +0 -171
  126. package/src/frameworks/recipes/astro.yaml +0 -206
  127. package/src/frameworks/recipes/django.yaml +0 -180
  128. package/src/frameworks/recipes/laravel.yaml +0 -137
  129. package/src/frameworks/recipes/nextjs.yaml +0 -268
  130. package/src/frameworks/recipes/nuxt.yaml +0 -175
  131. package/src/frameworks/recipes/rails.yaml +0 -188
  132. package/src/frameworks/recipes/react.yaml +0 -202
  133. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  134. package/src/frameworks/recipes/vue.yaml +0 -137
  135. package/src/frameworks/recipes/wordpress.yaml +0 -209
  136. package/src/frameworks/suggestion-engine.ts +0 -357
  137. package/src/geo/geo-content.test.ts +0 -305
  138. package/src/geo/geo-content.ts +0 -266
  139. package/src/geo/geo-history.test.ts +0 -473
  140. package/src/geo/geo-history.ts +0 -433
  141. package/src/geo/geo-tracker.test.ts +0 -359
  142. package/src/geo/geo-tracker.ts +0 -411
  143. package/src/geo/index.ts +0 -11
  144. package/src/geo/llm-citation-checker.ts +0 -188
  145. package/src/git/commit-helper.test.ts +0 -261
  146. package/src/git/commit-helper.ts +0 -329
  147. package/src/git/index.ts +0 -12
  148. package/src/git/pr-helper.test.ts +0 -284
  149. package/src/git/pr-helper.ts +0 -307
  150. package/src/index.ts +0 -76
  151. package/src/keywords/ai-keyword-engine.ts +0 -1062
  152. package/src/keywords/ai-summarizer.ts +0 -387
  153. package/src/keywords/ci-mode.ts +0 -555
  154. package/src/keywords/engine.ts +0 -359
  155. package/src/keywords/index.ts +0 -151
  156. package/src/keywords/llm-judge.ts +0 -357
  157. package/src/keywords/nlp-analysis.ts +0 -706
  158. package/src/keywords/prioritizer.ts +0 -295
  159. package/src/keywords/site-crawler.ts +0 -342
  160. package/src/keywords/sources/autocomplete.ts +0 -139
  161. package/src/keywords/sources/competitive-search.ts +0 -450
  162. package/src/keywords/sources/competitor-analysis.ts +0 -374
  163. package/src/keywords/sources/dataforseo.ts +0 -206
  164. package/src/keywords/sources/free-sources.ts +0 -294
  165. package/src/keywords/sources/gsc.ts +0 -123
  166. package/src/keywords/topic-grouping.ts +0 -327
  167. package/src/keywords/types.ts +0 -144
  168. package/src/keywords/wizard.ts +0 -457
  169. package/src/loader.ts +0 -40
  170. package/src/ranking/index.ts +0 -5
  171. package/src/ranking/serp-client.ts +0 -348
  172. package/src/ranking/tracker.ts +0 -380
  173. package/src/ranking/types.ts +0 -123
  174. package/src/reports/index.ts +0 -7
  175. package/src/reports/report-generator.test.ts +0 -293
  176. package/src/reports/report-generator.ts +0 -713
  177. package/src/scheduler/alerts.test.ts +0 -458
  178. package/src/scheduler/alerts.ts +0 -328
  179. package/src/scheduler/index.ts +0 -8
  180. package/src/scheduler/scheduled-audit.test.ts +0 -377
  181. package/src/scheduler/scheduled-audit.ts +0 -149
  182. package/src/test/integration-test.ts +0 -325
  183. package/src/tools/analyzer.ts +0 -373
  184. package/src/tools/crawl.ts +0 -293
  185. package/src/tools/files.ts +0 -301
  186. package/src/tools/h1-fixer.ts +0 -249
  187. package/src/tools/index.ts +0 -67
  188. package/src/tracking/github-action.ts +0 -326
  189. package/src/tracking/google-analytics.ts +0 -265
  190. package/src/tracking/index.ts +0 -45
  191. package/src/tracking/report-generator.ts +0 -386
  192. package/src/tracking/search-console.ts +0 -335
  193. package/src/types.ts +0 -148
  194. package/src/utils/http.ts +0 -302
  195. package/src/wasm-adapter.ts +0 -297
  196. package/src/wasm-entry.ts +0 -14
  197. package/tsconfig.json +0 -17
  198. package/tsup.wasm.config.ts +0 -26
  199. package/vitest.config.ts +0 -15
@@ -1,627 +0,0 @@
1
- import { httpGet } from '../utils/http.js';
2
- import type { AuditIssue, AuditReport, HealthScore, PageAudit } from './types.js';
3
- import { runCrawlabilityChecks } from './checks/crawlability.js';
4
- import { analyzeOnPage } from './checks/on-page.js';
5
- import { analyzeLinks } from './checks/links.js';
6
- import { analyzeImages } from './checks/images.js';
7
- import { analyzePerformance, fetchCoreWebVitals } from './checks/performance.js';
8
- import { analyzeSecurity, checkCertificate } from './checks/security.js';
9
- import { analyzeStructuredData, suggestSchemaTypes } from './checks/structured-data.js';
10
- import { analyzeMobile, checkMobileResources } from './checks/mobile.js';
11
- // Advanced checks
12
- import { analyzeHreflang } from './checks/hreflang.js';
13
- import { analyzeSocialMeta } from './checks/social-meta.js';
14
- import { detectSoft404 } from './checks/soft-404.js';
15
- import { analyzeAnchorText } from './checks/anchor-text.js';
16
- import { analyzeCanonicalAdvanced } from './checks/canonical-advanced.js';
17
- import { analyzePagination } from './checks/pagination.js';
18
- import { analyzeRedirects } from './checks/redirect-analysis.js';
19
- // New competitor-parity checks
20
- import { runAIReadinessChecks } from './checks/ai-readiness.js';
21
- import { analyzeSERPPreview } from './checks/serp-preview.js';
22
- import { analyzeLocalSEO } from './checks/local-seo.js';
23
- import { analyzeSecurityHeaders } from './checks/security-headers.js';
24
- import { analyzeContentFreshness } from './checks/content-freshness.js';
25
- import { analyzeDOMStructure } from './checks/dom-analysis.js';
26
- import { analyzeModernImages } from './checks/modern-images.js';
27
- import { detectTechnologies } from './checks/tech-detection.js';
28
- import { analyzeKeywords } from './checks/keyword-analysis.js';
29
- import { runAdditionalChecks } from './checks/additional-checks.js';
30
- // Advanced checks from SEO research
31
- import { analyzeFeaturedSnippet } from './checks/featured-snippet.js';
32
- import { analyzeInternalLinkGraph } from './checks/internal-link-graph.js';
33
- import { analyzeResourceHints } from './checks/resource-hints.js';
34
- import { analyzeEEATSignals } from './checks/eeat-signals.js';
35
- import { analyzeIndexNow } from './checks/indexnow.js';
36
- import { analyzeContentScience } from './checks/content-science.js';
37
- import { analyzeSiteMaturity } from './checks/site-maturity.js';
38
- import { analyzeKeywordCannibalizationSinglePage } from './checks/keyword-cannibalization.js';
39
- // New checks from Technical SEO for Developers & Best SEO Strategies 2025
40
- import { analyzeTrackerBloat } from './checks/tracker-bloat.js';
41
- import { analyzeClientRendering } from './checks/client-rendering.js';
42
- import { analyzeRedirectChain } from './checks/redirect-chain.js';
43
- import { analyzeResponsiveImages } from './checks/responsive-images.js';
44
- // New checks from 2026 SEO transcripts (Nathan Gotch & Neil Patel)
45
- import { analyzeConversionElements } from './checks/conversion-elements.js';
46
- import { analyzeKeywordPlacement } from './checks/keyword-placement.js';
47
- import { analyzeTopicalClusters } from './checks/topical-clusters.js';
48
- import { analyzePlatformPresence } from './checks/platform-presence.js';
49
- // Advanced SEO Tips 2026 & React SEO
50
- import { analyzeInteractiveTools } from './checks/interactive-tools.js';
51
- import { analyzeFunnelIntent } from './checks/funnel-intent.js';
52
- // Cutting-edge differentiating checks (Google leak, Entity SEO, QDF)
53
- import { analyzeNavBoostSignals } from './checks/navboost-signals.js';
54
- import { analyzeEntitySEO } from './checks/entity-seo.js';
55
- import { analyzeFreshnessSignals } from './checks/freshness-signals.js';
56
- // AI Search Optimization checks (2026 - ChatGPT, AI Overviews)
57
- import { analyzeBingOptimization } from './checks/bing-optimization.js';
58
- import { analyzeAIContentStructure } from './checks/ai-content-structure.js';
59
- import { analyzeCitationQuality } from './checks/citation-quality.js';
60
- import { analyzeAnswerConciseness } from './checks/answer-conciseness.js';
61
- // AI SEO Skills checks (brand narrative, citation worthiness, review ecosystem)
62
- import { analyzeBrandMentionOptimization } from './checks/brand-mention-optimization.js';
63
- import { analyzeAICitationWorthiness } from './checks/ai-citation-worthiness.js';
64
- import { analyzeReviewEcosystem } from './checks/review-ecosystem.js';
65
- // Competitor-parity checks (from missing-checks.md analysis)
66
- import { validateRobotsTxt } from './checks/robots-validation.js';
67
- import { analyzeLlmsTxt } from './checks/llms-txt.js';
68
- import { analyzeHtmlCompliance } from './checks/html-compliance.js';
69
- import { analyzeCanonicalDomain } from './checks/canonical-domain.js';
70
- import { analyzeCachingHeaders } from './checks/caching-headers.js';
71
- import { analyzeDomSize } from './checks/dom-size.js';
72
- import { analyzeImageDimensions } from './checks/image-dimensions.js';
73
- import { analyzeColorContrast } from './checks/color-contrast.js';
74
- // New checks from Rank Math analysis
75
- import { analyzeAssetMinification } from './checks/asset-minification.js';
76
- import { analyzePageResources } from './checks/page-resources.js';
77
- import { analyzeResponsiveCss } from './checks/responsive-css.js';
78
- import { analyzeDirectoryListing } from './checks/directory-listing.js';
79
- import { analyzeUrlSafety } from './checks/url-safety.js';
80
- import { analyzeTrackingVerification } from './checks/tracking-verification.js';
81
-
82
- export interface AuditOptions {
83
- url: string;
84
- checkBrokenLinks?: boolean;
85
- checkHreflangUrls?: boolean;
86
- checkCanonicalChain?: boolean;
87
- maxPages?: number;
88
- cruxApiKey?: string;
89
- /**
90
- * Maximum number of checks to run. Used for tier enforcement:
91
- * - 50: Free unregistered users (core checks only)
92
- * - 100: Free registered users (core + some premium checks)
93
- * - 280+: Paid users (all checks)
94
- */
95
- checksLimit?: number;
96
- }
97
-
98
- export async function runFullAudit(options: AuditOptions): Promise<AuditReport> {
99
- const { url, checkBrokenLinks = false, checkHreflangUrls = false, checkCanonicalChain = false, cruxApiKey, checksLimit = 280 } = options;
100
- const allIssues: AuditIssue[] = [];
101
- const pages: PageAudit[] = [];
102
-
103
- // Determine tier based on checksLimit
104
- // Free unregistered: 50, Free registered: 100, Paid: 280+
105
- const tier = checksLimit <= 50 ? 'free' : checksLimit <= 100 ? 'registered' : 'paid';
106
- const runPremiumChecks = tier === 'paid';
107
- const runExtendedChecks = tier !== 'free'; // registered + paid
108
-
109
- const parsedUrl = new URL(url);
110
- const domain = parsedUrl.hostname;
111
-
112
- console.log(`\n🔍 Running comprehensive SEO audit on ${url}...\n`);
113
-
114
- // ========== PHASE 1: CRAWLABILITY + FETCH (PARALLEL) ==========
115
- console.log('📋 Phase 1: Crawlability checks + page fetch (parallel)...');
116
-
117
- const [crawlabilityResult, fetchResult] = await Promise.all([
118
- runCrawlabilityChecks(url).catch(err => {
119
- console.error('Crawlability check failed:', err);
120
- return [] as AuditIssue[];
121
- }),
122
- httpGet<string>(url, {
123
- timeout: 30000,
124
- validateStatus: () => true,
125
- }).catch(err => {
126
- console.error('Main page fetch failed:', err instanceof Error ? { message: err.message, cause: (err as NodeJS.ErrnoException).cause } : err);
127
- return { error: err, data: '', headers: {} as Record<string, string> };
128
- }),
129
- ]);
130
-
131
- allIssues.push(...crawlabilityResult);
132
-
133
- // Check if fetch failed
134
- if ('error' in fetchResult) {
135
- const err = fetchResult.error;
136
- const errorMsg = err instanceof Error ? err.message : 'Unknown error';
137
- const errorCause = err instanceof Error && (err as NodeJS.ErrnoException).cause
138
- ? ` (${String((err as NodeJS.ErrnoException).cause)})`
139
- : '';
140
- allIssues.push({
141
- code: 'FETCH_ERROR',
142
- severity: 'error',
143
- category: 'indexability', // Not crawlability - robots/sitemap checks may have succeeded
144
- title: 'Page fetch failed',
145
- description: `Could not load page content: ${errorMsg}${errorCause}. Only robots.txt and sitemap checks were performed.`,
146
- impact: 'Cannot perform full SEO audit without page HTML content.',
147
- howToFix: 'Verify the URL is accessible, the server is responding, and there are no firewall/geo blocks.',
148
- affectedUrls: [url],
149
- details: { error: errorMsg, cause: errorCause || undefined },
150
- });
151
- return createReport(url, domain, allIssues, pages);
152
- }
153
-
154
- const html = fetchResult.data;
155
- const headers = fetchResult.headers;
156
-
157
- // ========== PHASE 2: SYNCHRONOUS HTML CHECKS (PARALLEL) ==========
158
- console.log(`📝 Phase 2: Running synchronous HTML checks (tier: ${tier}, limit: ${checksLimit})...`);
159
-
160
- // ===== CORE CHECKS (all tiers) =====
161
- const onPageResult = analyzeOnPage(html, url);
162
- const structuredDataResult = analyzeStructuredData(html, url);
163
- const mobileResult = analyzeMobile(html, url);
164
- const mobileResourceIssues = checkMobileResources(html, url);
165
- const socialResult = analyzeSocialMeta(html, url);
166
- const soft404Result = detectSoft404(html, url, 200);
167
- const serpResult = analyzeSERPPreview(html, url);
168
- const domResult = analyzeDOMStructure(html, url);
169
- const techResult = detectTechnologies(html, url, headers);
170
- const keywordResult = analyzeKeywords(html, url);
171
- // Pagination depends on onPageData.canonical
172
- const paginationResult = analyzePagination(html, url, onPageResult.data.canonical);
173
- // URL Safety check (local hash database - like Google Safe Browsing)
174
- const urlSafetyResult = analyzeUrlSafety(url);
175
- // Competitor-parity checks (sync) - important for all users
176
- const domSizeResult = analyzeDomSize(html, url);
177
- const imageDimensionsResult = analyzeImageDimensions(html, url);
178
- // Tracking & verification checks (GA4, GSC, Bing, Schema.org)
179
- const trackingResult = analyzeTrackingVerification(html, url);
180
-
181
- // ===== EXTENDED CHECKS (registered + paid tiers) =====
182
- const anchorResult = runExtendedChecks ? analyzeAnchorText(html, url) : { issues: [], data: {} };
183
- const localSeoResult = runExtendedChecks ? analyzeLocalSEO(html, url) : { issues: [], data: {} };
184
- const modernImageResult = runExtendedChecks ? analyzeModernImages(html, url) : { issues: [], data: {} };
185
- const resourceHintResult = runExtendedChecks ? analyzeResourceHints(html, url) : { issues: [], data: {} };
186
- const trackerResult = runExtendedChecks ? analyzeTrackerBloat(html, url) : { issues: [], data: {} };
187
- const csrResult = runExtendedChecks ? analyzeClientRendering(html, url) : { issues: [], data: {} };
188
- const responsiveImgResult = runExtendedChecks ? analyzeResponsiveImages(html, url) : { issues: [], data: {} };
189
- const colorContrastResult = runExtendedChecks ? analyzeColorContrast(html, url) : { issues: [], data: {} };
190
- const pageResourcesResult = runExtendedChecks ? analyzePageResources(html, url) : { issues: [], data: {} };
191
-
192
- // ===== PREMIUM CHECKS (paid tier only) =====
193
- const snippetResult = runPremiumChecks ? analyzeFeaturedSnippet(html, url) : { issues: [], data: {} };
194
- const linkGraphResult = runPremiumChecks ? analyzeInternalLinkGraph(html, url) : { issues: [], data: {} };
195
- const eeatResult = runPremiumChecks ? analyzeEEATSignals(html, url) : { issues: [], data: {} };
196
- const contentScienceResult = runPremiumChecks ? analyzeContentScience(html, url) : { issues: [], data: {} };
197
- const cannibalizationResult = runPremiumChecks ? analyzeKeywordCannibalizationSinglePage(html, url) : { issues: [], data: {} };
198
- const conversionResult = runPremiumChecks ? analyzeConversionElements(html, url) : { issues: [], data: {} };
199
- const keywordPlacementResult = runPremiumChecks ? analyzeKeywordPlacement(html, url) : { issues: [], data: {} };
200
- const clusterResult = runPremiumChecks ? analyzeTopicalClusters(html, url) : { issues: [], data: {} };
201
- const platformResult = runPremiumChecks ? analyzePlatformPresence(html, url) : { issues: [], data: {} };
202
- const toolResult = runPremiumChecks ? analyzeInteractiveTools(html, url) : { issues: [], data: {} };
203
- const funnelResult = runPremiumChecks ? analyzeFunnelIntent(html, url) : { issues: [], data: {} };
204
- const navboostResult = runPremiumChecks ? analyzeNavBoostSignals(html, url) : { issues: [], data: {} };
205
- const entityResult = runPremiumChecks ? analyzeEntitySEO(html, url) : { issues: [], data: {} };
206
- const qdfFreshnessResult = runPremiumChecks ? analyzeFreshnessSignals(html, url) : { issues: [], data: {} };
207
- // AI Search Optimization (2026) - Premium only
208
- const aiContentStructureResult = runPremiumChecks ? analyzeAIContentStructure(html, url) : { issues: [], data: {} };
209
- const citationQualityResult = runPremiumChecks ? analyzeCitationQuality(html, url) : { issues: [], data: {} };
210
- const answerConcisenessResult = runPremiumChecks ? analyzeAnswerConciseness(html, url) : { issues: [], data: {} };
211
- // AI SEO Skills - Premium only
212
- const brandMentionResult = runPremiumChecks ? analyzeBrandMentionOptimization(html, url) : { issues: [], data: {} };
213
- const citationWorthinessResult = runPremiumChecks ? analyzeAICitationWorthiness(html, url) : { issues: [], data: {} };
214
- const reviewEcosystemResult = runPremiumChecks ? analyzeReviewEcosystem(html, url) : { issues: [], data: {} };
215
-
216
- // Collect all sync check issues
217
- allIssues.push(
218
- ...onPageResult.issues,
219
- ...structuredDataResult.issues,
220
- ...mobileResult.issues,
221
- ...mobileResourceIssues,
222
- ...socialResult.issues,
223
- ...soft404Result.issues,
224
- ...anchorResult.issues,
225
- ...serpResult.issues,
226
- ...localSeoResult.issues,
227
- ...domResult.issues,
228
- ...modernImageResult.issues,
229
- ...techResult.issues,
230
- ...keywordResult.issues,
231
- ...snippetResult.issues,
232
- ...linkGraphResult.issues,
233
- ...resourceHintResult.issues,
234
- ...eeatResult.issues,
235
- ...contentScienceResult.issues,
236
- ...cannibalizationResult.issues,
237
- ...trackerResult.issues,
238
- ...csrResult.issues,
239
- ...responsiveImgResult.issues,
240
- ...conversionResult.issues,
241
- ...keywordPlacementResult.issues,
242
- ...clusterResult.issues,
243
- ...platformResult.issues,
244
- ...toolResult.issues,
245
- ...funnelResult.issues,
246
- ...navboostResult.issues,
247
- ...entityResult.issues,
248
- ...qdfFreshnessResult.issues,
249
- ...aiContentStructureResult.issues,
250
- ...citationQualityResult.issues,
251
- ...answerConcisenessResult.issues,
252
- ...brandMentionResult.issues,
253
- ...citationWorthinessResult.issues,
254
- ...reviewEcosystemResult.issues,
255
- ...domSizeResult.issues,
256
- ...imageDimensionsResult.issues,
257
- ...colorContrastResult.issues,
258
- ...pageResourcesResult.issues,
259
- ...urlSafetyResult.issues,
260
- ...paginationResult.issues,
261
- ...trackingResult.issues,
262
- );
263
-
264
- // Suggest schema types if none found
265
- if (!structuredDataResult.data.hasSchema) {
266
- const suggestions = suggestSchemaTypes(html, url);
267
- if (suggestions.length > 0 && structuredDataResult.issues.length > 0) {
268
- const lastSchemaIssue = structuredDataResult.issues[structuredDataResult.issues.length - 1];
269
- lastSchemaIssue.details = {
270
- ...lastSchemaIssue.details,
271
- suggestedTypes: suggestions,
272
- };
273
- }
274
- }
275
-
276
- // ========== PHASE 3: ASYNC CHECKS (PARALLEL) ==========
277
- console.log('🔗 Phase 3: Running async checks (parallel)...');
278
-
279
- // Helper to safely run async checks with error handling and timeout
280
- const safeAsync = async <T>(
281
- name: string,
282
- fn: () => Promise<{ issues: AuditIssue[]; data: T }>,
283
- timeoutMs: number = 10000, // 10 second default timeout per check
284
- ): Promise<AuditIssue[]> => {
285
- try {
286
- const resultPromise = fn();
287
- const timeoutPromise = new Promise<never>((_, reject) =>
288
- setTimeout(() => reject(new Error(`${name} timed out`)), timeoutMs)
289
- );
290
- const result = await Promise.race([resultPromise, timeoutPromise]);
291
- return result.issues;
292
- } catch (err) {
293
- console.error(`${name} failed:`, err);
294
- return [];
295
- }
296
- };
297
-
298
- // Helper for async checks that only return issues
299
- const safeAsyncIssues = async (
300
- name: string,
301
- fn: () => Promise<AuditIssue[]>,
302
- timeoutMs: number = 10000,
303
- ): Promise<AuditIssue[]> => {
304
- try {
305
- const resultPromise = fn();
306
- const timeoutPromise = new Promise<never>((_, reject) =>
307
- setTimeout(() => reject(new Error(`${name} timed out`)), timeoutMs)
308
- );
309
- return await Promise.race([resultPromise, timeoutPromise]);
310
- } catch (err) {
311
- console.error(`${name} failed:`, err);
312
- return [];
313
- }
314
- };
315
-
316
- // Run performance separately to capture data for page audit
317
- let perfData = { loadTime: 0 };
318
- const performancePromise = analyzePerformance(url)
319
- .then(result => {
320
- perfData = result.data;
321
- return result.issues;
322
- })
323
- .catch(err => {
324
- console.error('Performance check failed:', err);
325
- return [] as AuditIssue[];
326
- });
327
-
328
- // Run all async checks in parallel (respecting tier limits)
329
- const asyncChecks: Promise<AuditIssue[]>[] = [];
330
-
331
- // ===== CORE ASYNC CHECKS (all tiers) =====
332
- asyncChecks.push(safeAsync('Links', () => analyzeLinks(html, url, checkBrokenLinks)));
333
- asyncChecks.push(safeAsync('Images', () => analyzeImages(html, url, checkBrokenLinks)));
334
- asyncChecks.push(performancePromise);
335
- asyncChecks.push(safeAsync('Security', () => analyzeSecurity(html, url, headers)));
336
- asyncChecks.push(safeAsyncIssues('Certificate', async () => (await checkCertificate(url)).issues));
337
- asyncChecks.push(safeAsync('Redirects', () => analyzeRedirects(url)));
338
- asyncChecks.push(safeAsync('Robots Validation', () => validateRobotsTxt(url)));
339
- asyncChecks.push(safeAsync('Canonical Domain', () => analyzeCanonicalDomain(url)));
340
-
341
- // ===== EXTENDED ASYNC CHECKS (registered + paid tiers) =====
342
- if (runExtendedChecks) {
343
- asyncChecks.push(safeAsync('Hreflang', () => analyzeHreflang(html, url, { validateUrls: checkHreflangUrls })));
344
- asyncChecks.push(safeAsync('Canonical Advanced', () => analyzeCanonicalAdvanced(html, url, { checkChain: checkCanonicalChain })));
345
- asyncChecks.push(safeAsync('Security Headers', () => analyzeSecurityHeaders(url)));
346
- asyncChecks.push(safeAsync('Caching Headers', () => analyzeCachingHeaders(url, headers)));
347
- asyncChecks.push(safeAsync('HTML Compliance', () => analyzeHtmlCompliance(html, url, headers)));
348
- asyncChecks.push(safeAsync('Redirect Chain', () => analyzeRedirectChain(url)));
349
- asyncChecks.push(safeAsync('Asset Minification', () => analyzeAssetMinification(html, url)));
350
- asyncChecks.push(safeAsync('Responsive CSS', () => analyzeResponsiveCss(html, url)));
351
- asyncChecks.push(safeAsync('Directory Listing', () => analyzeDirectoryListing(url)));
352
- }
353
-
354
- // ===== PREMIUM ASYNC CHECKS (paid tier only) =====
355
- if (runPremiumChecks) {
356
- asyncChecks.push(safeAsync('AI Readiness', () => runAIReadinessChecks(url, html)));
357
- asyncChecks.push(safeAsync('Content Freshness', () => analyzeContentFreshness(url, html)));
358
- asyncChecks.push(safeAsync('Additional Checks', () => runAdditionalChecks(url, html)));
359
- asyncChecks.push(safeAsync('IndexNow', () => analyzeIndexNow(html, url, headers)));
360
- asyncChecks.push(safeAsync('Site Maturity', () => analyzeSiteMaturity(html, url)));
361
- asyncChecks.push(safeAsync('Bing Optimization', () => analyzeBingOptimization(html, url)));
362
- asyncChecks.push(safeAsync('LLMs.txt', () => analyzeLlmsTxt(url)));
363
- // Core Web Vitals (optional, premium only)
364
- if (cruxApiKey) {
365
- asyncChecks.push(safeAsyncIssues('Core Web Vitals', async () => {
366
- const cwv = await fetchCoreWebVitals(url, cruxApiKey);
367
- const issues: AuditIssue[] = [];
368
- if (cwv) {
369
- if (cwv.lcp?.rating === 'poor') {
370
- issues.push({
371
- code: 'LCP_POOR',
372
- severity: 'error',
373
- category: 'performance',
374
- title: 'Poor Largest Contentful Paint (LCP)',
375
- description: `LCP is ${cwv.lcp.value}ms (should be under 2500ms)`,
376
- impact: 'Direct Core Web Vitals ranking factor.',
377
- howToFix: 'Optimize hero images, preload critical resources, improve server response time.',
378
- affectedUrls: [url],
379
- details: { lcp: cwv.lcp },
380
- });
381
- }
382
- if (cwv.cls?.rating === 'poor') {
383
- issues.push({
384
- code: 'CLS_POOR',
385
- severity: 'error',
386
- category: 'performance',
387
- title: 'Poor Cumulative Layout Shift (CLS)',
388
- description: `CLS is ${cwv.cls.value} (should be under 0.1)`,
389
- impact: 'Direct Core Web Vitals ranking factor.',
390
- howToFix: 'Set image dimensions, avoid inserting content above existing content.',
391
- affectedUrls: [url],
392
- details: { cls: cwv.cls },
393
- });
394
- }
395
- }
396
- return issues;
397
- }));
398
- }
399
- }
400
-
401
- const asyncResults = await Promise.all(asyncChecks);
402
-
403
- // Collect all async issues
404
- for (const issues of asyncResults) {
405
- allIssues.push(...issues);
406
- }
407
-
408
- // ========== CREATE PAGE AUDIT ==========
409
- pages.push({
410
- url,
411
- statusCode: 200,
412
- title: onPageResult.data.title,
413
- description: onPageResult.data.description,
414
- canonical: onPageResult.data.canonical,
415
- h1: onPageResult.data.h1s,
416
- wordCount: onPageResult.data.wordCount,
417
- loadTime: perfData.loadTime,
418
- issues: allIssues.map(i => i.code),
419
- });
420
-
421
- console.log('\n✅ Audit complete!\n');
422
-
423
- return createReport(url, domain, allIssues, pages);
424
- }
425
-
426
- function createReport(url: string, domain: string, issues: AuditIssue[], pages: PageAudit[]): AuditReport {
427
- // Calculate health score
428
- const healthScore = calculateHealthScore(issues);
429
-
430
- // Count issues by severity
431
- const errors = issues.filter(i => i.severity === 'error').length;
432
- const warnings = issues.filter(i => i.severity === 'warning').length;
433
- const notices = issues.filter(i => i.severity === 'notice').length;
434
-
435
- // Calculate passed checks (rough estimate based on possible checks)
436
- const totalPossibleChecks = 310; // Approximate number of checks (expanded with Rank Math parity + URL safety checks)
437
- const passed = Math.max(0, totalPossibleChecks - errors - warnings);
438
-
439
- return {
440
- url,
441
- domain,
442
- timestamp: new Date().toISOString(),
443
- crawlStats: {
444
- totalUrls: 1,
445
- crawledUrls: 1,
446
- errorUrls: 0,
447
- redirectUrls: 0,
448
- blockedUrls: 0,
449
- },
450
- healthScore,
451
- issues,
452
- pages,
453
- summary: {
454
- errors,
455
- warnings,
456
- notices,
457
- passed,
458
- },
459
- };
460
- }
461
-
462
- function calculateHealthScore(issues: AuditIssue[]): HealthScore {
463
- // Weight issues by severity
464
- const weights: Record<string, number> = { critical: 15, error: 10, warning: 3, info: 1, notice: 1 };
465
-
466
- // Calculate deductions per category
467
- const categoryDeductions: Record<string, number> = {
468
- crawlability: 0,
469
- indexability: 0,
470
- 'on-page': 0,
471
- content: 0,
472
- links: 0,
473
- images: 0,
474
- 'structured-data': 0,
475
- performance: 0,
476
- security: 0,
477
- mobile: 0,
478
- international: 0,
479
- 'ai-readiness': 0,
480
- 'social': 0,
481
- 'local-seo': 0,
482
- 'accessibility': 0,
483
- };
484
-
485
- for (const issue of issues) {
486
- const deduction = weights[issue.severity];
487
- categoryDeductions[issue.category] = (categoryDeductions[issue.category] || 0) + deduction;
488
- }
489
-
490
- // Calculate scores (100 - deductions, min 0)
491
- const crawlability = Math.max(0, 100 - categoryDeductions.crawlability * 5);
492
- const indexability = Math.max(0, 100 - categoryDeductions.indexability * 5);
493
- const onPage = Math.max(0, 100 - categoryDeductions['on-page'] * 3);
494
- const content = Math.max(0, 100 - categoryDeductions.content * 3);
495
- const links = Math.max(0, 100 - categoryDeductions.links * 3);
496
- const performance = Math.max(0, 100 - categoryDeductions.performance * 4);
497
- const security = Math.max(0, 100 - categoryDeductions.security * 5);
498
- const aiReadiness = Math.max(0, 100 - categoryDeductions['ai-readiness'] * 3);
499
- const social = Math.max(0, 100 - categoryDeductions.social * 2);
500
- const localSeo = Math.max(0, 100 - categoryDeductions['local-seo'] * 2);
501
- const accessibility = Math.max(0, 100 - categoryDeductions.accessibility * 4);
502
-
503
- // Overall score is weighted average
504
- const overall = Math.round(
505
- (crawlability * 0.11 +
506
- indexability * 0.11 +
507
- onPage * 0.16 +
508
- content * 0.07 +
509
- links * 0.07 +
510
- performance * 0.11 +
511
- security * 0.11 +
512
- aiReadiness * 0.06 +
513
- social * 0.05 +
514
- localSeo * 0.05 +
515
- accessibility * 0.10)
516
- );
517
-
518
- return {
519
- overall,
520
- crawlability,
521
- indexability,
522
- onPage,
523
- content,
524
- links,
525
- performance,
526
- security,
527
- aiReadiness,
528
- social,
529
- localSeo,
530
- accessibility,
531
- };
532
- }
533
-
534
- // Format the report for console output
535
- export function formatReport(report: AuditReport): string {
536
- const lines: string[] = [];
537
-
538
- lines.push('');
539
- lines.push('═'.repeat(70));
540
- lines.push(' SEO AUDIT REPORT');
541
- lines.push('═'.repeat(70));
542
- lines.push(` URL: ${report.url}`);
543
- lines.push(` Domain: ${report.domain}`);
544
- lines.push(` Time: ${report.timestamp}`);
545
- lines.push('═'.repeat(70));
546
- lines.push('');
547
-
548
- // Health Score
549
- lines.push('📊 HEALTH SCORE');
550
- lines.push('─'.repeat(70));
551
- lines.push(` Overall: ${report.healthScore.overall}/100 ${getScoreEmoji(report.healthScore.overall)}`);
552
- lines.push('');
553
- lines.push(' Category Scores:');
554
- lines.push(` Crawlability: ${report.healthScore.crawlability}/100`);
555
- lines.push(` Indexability: ${report.healthScore.indexability}/100`);
556
- lines.push(` On-Page SEO: ${report.healthScore.onPage}/100`);
557
- lines.push(` Content: ${report.healthScore.content}/100`);
558
- lines.push(` Links: ${report.healthScore.links}/100`);
559
- lines.push(` Performance: ${report.healthScore.performance}/100`);
560
- lines.push(` Security: ${report.healthScore.security}/100`);
561
- lines.push(` AI Readiness: ${report.healthScore.aiReadiness}/100`);
562
- lines.push(` Social: ${report.healthScore.social}/100`);
563
- lines.push(` Local SEO: ${report.healthScore.localSeo}/100`);
564
- lines.push(` Accessibility: ${report.healthScore.accessibility}/100`);
565
- lines.push('');
566
-
567
- // Summary
568
- lines.push('📋 SUMMARY');
569
- lines.push('─'.repeat(70));
570
- lines.push(` ❌ Errors: ${report.summary.errors}`);
571
- lines.push(` ⚠️ Warnings: ${report.summary.warnings}`);
572
- lines.push(` ℹ️ Notices: ${report.summary.notices}`);
573
- lines.push(` ✅ Passed: ${report.summary.passed}`);
574
- lines.push('');
575
-
576
- // Issues by category
577
- const issuesByCategory = groupIssuesByCategory(report.issues);
578
-
579
- for (const [category, issues] of Object.entries(issuesByCategory)) {
580
- if (issues.length === 0) continue;
581
-
582
- lines.push(`📁 ${category.toUpperCase()}`);
583
- lines.push('─'.repeat(70));
584
-
585
- for (const issue of issues) {
586
- const icon = issue.severity === 'error' ? '❌' : issue.severity === 'warning' ? '⚠️' : 'ℹ️';
587
- lines.push(` ${icon} ${issue.title}`);
588
- lines.push(` ${issue.description}`);
589
- if (issue.howToFix) {
590
- lines.push(` → ${issue.howToFix}`);
591
- }
592
- lines.push('');
593
- }
594
- }
595
-
596
- lines.push('═'.repeat(70));
597
-
598
- return lines.join('\n');
599
- }
600
-
601
- function getScoreEmoji(score: number): string {
602
- if (score >= 90) return '🟢 Excellent';
603
- if (score >= 70) return '🟡 Good';
604
- if (score >= 50) return '🟠 Needs Work';
605
- return '🔴 Poor';
606
- }
607
-
608
- function groupIssuesByCategory(issues: AuditIssue[]): Record<string, AuditIssue[]> {
609
- const grouped: Record<string, AuditIssue[]> = {};
610
-
611
- for (const issue of issues) {
612
- if (!grouped[issue.category]) {
613
- grouped[issue.category] = [];
614
- }
615
- grouped[issue.category].push(issue);
616
- }
617
-
618
- // Sort by severity within each category
619
- for (const category of Object.keys(grouped)) {
620
- grouped[category].sort((a, b) => {
621
- const order: Record<string, number> = { critical: 0, error: 1, warning: 2, info: 3, notice: 4 };
622
- return (order[a.severity] ?? 5) - (order[b.severity] ?? 5);
623
- });
624
- }
625
-
626
- return grouped;
627
- }