@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,349 +0,0 @@
1
- /**
2
- * Brand Mention Optimization Checks
3
- *
4
- * AI systems extract and quote brand information when answering queries.
5
- * This check analyzes whether your brand is clearly defined in a way
6
- * that AI can extract, quote, and recommend.
7
- *
8
- * Key insight: "AI doesn't decide who you are. It mostly just repeats
9
- * what it finds on the internet." - Control your brand narrative.
10
- */
11
-
12
- import * as cheerio from 'cheerio';
13
- import type { AuditIssue } from '../types.js';
14
-
15
- export interface BrandMentionData {
16
- brandSignals: {
17
- hasBrandDefinition: boolean;
18
- hasUSP: boolean;
19
- hasValueProposition: boolean;
20
- hasBrandStatement: boolean;
21
- brandMentionCount: number;
22
- };
23
- brandCoverage: {
24
- hasPricingInfo: boolean;
25
- hasAboutSection: boolean;
26
- hasFAQSection: boolean;
27
- hasTestimonials: boolean;
28
- hasProofPoints: boolean;
29
- };
30
- brandConsistency: {
31
- hasConsistentNaming: boolean;
32
- hasContactInfo: boolean;
33
- hasSocialLinks: boolean;
34
- hasReviewLinks: boolean;
35
- };
36
- quotableBrandStatements: string[];
37
- brandScore: number;
38
- }
39
-
40
- // Patterns for brand-defining statements
41
- const BRAND_DEFINITION_PATTERNS = [
42
- /(?:we are|we're|is a|is the|is an)\s+(?:leading|premier|top|best|trusted|innovative|professional)/i,
43
- /(?:our mission|our vision|we help|we provide|we offer|we specialize)/i,
44
- /(?:founded in|established in|since \d{4}|for over \d+)/i,
45
- ];
46
-
47
- // USP (Unique Selling Proposition) patterns
48
- const USP_PATTERNS = [
49
- /(?:only|unique|exclusive|proprietary|patented|first|original)/i,
50
- /(?:unlike|different from|better than|compared to)/i,
51
- /(?:guarantee|warranty|promise|commitment)/i,
52
- /(?:free|no cost|complimentary|included)/i,
53
- /(?:\d+%|\d+x|\d+ times|faster|cheaper|easier)/i,
54
- ];
55
-
56
- // Value proposition patterns
57
- const VALUE_PROP_PATTERNS = [
58
- /(?:save|reduce|increase|improve|boost|grow|maximize|minimize)/i,
59
- /(?:get|achieve|reach|attain|unlock|discover)/i,
60
- /(?:without|no need|don't have to|eliminates|removes)/i,
61
- ];
62
-
63
- // Review platform domains
64
- const REVIEW_PLATFORMS = [
65
- 'trustpilot.com', 'g2.com', 'capterra.com', 'yelp.com',
66
- 'bbb.org', 'glassdoor.com', 'indeed.com', 'tripadvisor.com',
67
- 'angi.com', 'homeadvisor.com', 'avvo.com', 'healthgrades.com',
68
- 'zocdoc.com', 'clutch.co', 'producthunt.com', 'getapp.com',
69
- ];
70
-
71
- export function analyzeBrandMentionOptimization(
72
- html: string,
73
- url: string
74
- ): { issues: AuditIssue[]; data: BrandMentionData } {
75
- const issues: AuditIssue[] = [];
76
- const $ = cheerio.load(html);
77
- const parsedUrl = new URL(url);
78
-
79
- // Remove non-content elements
80
- const $content = $('body').clone();
81
- $content.find('nav, footer, script, style, noscript').remove();
82
- const bodyText = $content.text();
83
- const bodyHtml = $content.html() || '';
84
-
85
- // Extract potential brand name from domain or title
86
- const domainParts = parsedUrl.hostname.replace('www.', '').split('.');
87
- const potentialBrandName = domainParts[0];
88
- const title = $('title').text();
89
- const ogSiteName = $('meta[property="og:site_name"]').attr('content') || '';
90
-
91
- // Count brand mentions
92
- const brandNameRegex = new RegExp(potentialBrandName, 'gi');
93
- const brandMentionCount = (bodyText.match(brandNameRegex) || []).length;
94
-
95
- // Check for brand definition patterns
96
- let hasBrandDefinition = false;
97
- let hasUSP = false;
98
- let hasValueProposition = false;
99
- let hasBrandStatement = false;
100
- const quotableBrandStatements: string[] = [];
101
-
102
- // Analyze paragraphs for brand statements
103
- $content.find('p, li, h1, h2, h3').each((_, el) => {
104
- const text = $(el).text().trim();
105
- if (text.length < 20 || text.length > 300) return;
106
-
107
- // Check for brand definitions
108
- for (const pattern of BRAND_DEFINITION_PATTERNS) {
109
- if (pattern.test(text)) {
110
- hasBrandDefinition = true;
111
- if (text.length <= 200 && quotableBrandStatements.length < 5) {
112
- quotableBrandStatements.push(text);
113
- }
114
- break;
115
- }
116
- }
117
-
118
- // Check for USPs
119
- for (const pattern of USP_PATTERNS) {
120
- if (pattern.test(text)) {
121
- hasUSP = true;
122
- break;
123
- }
124
- }
125
-
126
- // Check for value propositions
127
- for (const pattern of VALUE_PROP_PATTERNS) {
128
- if (pattern.test(text)) {
129
- hasValueProposition = true;
130
- break;
131
- }
132
- }
133
- });
134
-
135
- // Check for explicit brand statement (often in hero or about section)
136
- hasBrandStatement =
137
- $('[class*="hero"] p, [class*="about"] p, [id*="hero"] p, [id*="about"] p').length > 0 ||
138
- $('main > section:first-child p').length > 0;
139
-
140
- // Check brand topic coverage
141
- const headingText = $('h1, h2, h3, h4').map((_, h) => $(h).text().toLowerCase()).get().join(' ');
142
- const linkText = $('a').map((_, a) => $(a).text().toLowerCase()).get().join(' ');
143
- const allLinks = $('a[href]').map((_, a) => $(a).attr('href') || '').get();
144
-
145
- const hasPricingInfo =
146
- headingText.includes('pricing') ||
147
- headingText.includes('plans') ||
148
- headingText.includes('cost') ||
149
- linkText.includes('pricing') ||
150
- allLinks.some(href => href.includes('pricing') || href.includes('plans'));
151
-
152
- const hasAboutSection =
153
- headingText.includes('about') ||
154
- headingText.includes('who we are') ||
155
- headingText.includes('our story') ||
156
- allLinks.some(href => href.includes('about'));
157
-
158
- const hasFAQSection =
159
- headingText.includes('faq') ||
160
- headingText.includes('frequently asked') ||
161
- headingText.includes('questions') ||
162
- $('[itemtype*="FAQPage"]').length > 0 ||
163
- $('details summary').length >= 2;
164
-
165
- const hasTestimonials =
166
- headingText.includes('testimonial') ||
167
- headingText.includes('review') ||
168
- headingText.includes('what our') ||
169
- headingText.includes('customer') ||
170
- $('[class*="testimonial"], [class*="review"], [id*="testimonial"]').length > 0 ||
171
- $('blockquote').length >= 2;
172
-
173
- const hasProofPoints =
174
- headingText.includes('case stud') ||
175
- headingText.includes('success') ||
176
- headingText.includes('results') ||
177
- /\d+\+?\s*(customers|clients|users|companies|businesses)/i.test(bodyText) ||
178
- /\d+%\s*(increase|decrease|improvement|growth)/i.test(bodyText);
179
-
180
- // Check brand consistency signals
181
- const hasConsistentNaming = brandMentionCount >= 3 && ogSiteName.length > 0;
182
-
183
- const hasContactInfo =
184
- $('a[href^="tel:"], a[href^="mailto:"]').length > 0 ||
185
- /\d{3}[-.\s]?\d{3}[-.\s]?\d{4}/.test(bodyText) ||
186
- bodyText.toLowerCase().includes('contact');
187
-
188
- const socialLinks = $('a[href*="facebook.com"], a[href*="twitter.com"], a[href*="linkedin.com"], a[href*="instagram.com"]');
189
- const hasSocialLinks = socialLinks.length >= 2;
190
-
191
- // Check for review platform links
192
- const hasReviewLinks = allLinks.some(href => {
193
- const lowerHref = href.toLowerCase();
194
- return REVIEW_PLATFORMS.some(platform => lowerHref.includes(platform));
195
- });
196
-
197
- // Calculate brand score
198
- let brandScore = 30; // Base score
199
-
200
- // Brand signals
201
- if (hasBrandDefinition) brandScore += 15;
202
- if (hasUSP) brandScore += 10;
203
- if (hasValueProposition) brandScore += 10;
204
- if (brandMentionCount >= 5) brandScore += 5;
205
-
206
- // Brand coverage
207
- if (hasPricingInfo) brandScore += 5;
208
- if (hasAboutSection) brandScore += 5;
209
- if (hasFAQSection) brandScore += 5;
210
- if (hasTestimonials) brandScore += 10;
211
- if (hasProofPoints) brandScore += 10;
212
-
213
- // Brand consistency
214
- if (hasConsistentNaming) brandScore += 5;
215
- if (hasContactInfo) brandScore += 3;
216
- if (hasSocialLinks) brandScore += 3;
217
- if (hasReviewLinks) brandScore += 5;
218
-
219
- brandScore = Math.min(100, Math.max(0, brandScore));
220
-
221
- // Generate issues
222
-
223
- // No clear brand definition
224
- if (!hasBrandDefinition) {
225
- issues.push({
226
- code: 'AI_NO_BRAND_DEFINITION',
227
- severity: 'warning',
228
- category: 'ai-readiness',
229
- title: 'No clear brand definition for AI to extract',
230
- description: 'AI systems look for clear "Brand X is..." statements to quote when recommending brands. Your page lacks quotable brand definitions.',
231
- impact: 'AI cannot accurately describe your brand, reducing recommendation likelihood.',
232
- howToFix: 'Add a clear brand definition early in your content: "[Brand] is a [category] that [key benefit]." Make it quotable (under 200 characters).',
233
- affectedUrls: [url],
234
- details: {
235
- suggestion: `Example: "${potentialBrandName.charAt(0).toUpperCase() + potentialBrandName.slice(1)} is a [category] that helps [audience] [achieve benefit]."`,
236
- },
237
- });
238
- }
239
-
240
- // No USP
241
- if (!hasUSP) {
242
- issues.push({
243
- code: 'AI_NO_USP',
244
- severity: 'notice',
245
- category: 'ai-readiness',
246
- title: 'No unique selling proposition (USP) detected',
247
- description: 'AI needs clear differentiators to recommend your brand over competitors. No USP patterns found.',
248
- impact: 'AI may not distinguish your brand from competitors when making recommendations.',
249
- howToFix: 'Add clear differentiators: "The only...", "Unlike competitors...", "Guaranteed...", specific numbers (e.g., "50% faster").',
250
- affectedUrls: [url],
251
- });
252
- }
253
-
254
- // Missing brand topic coverage
255
- const missingTopics: string[] = [];
256
- if (!hasPricingInfo) missingTopics.push('pricing');
257
- if (!hasFAQSection) missingTopics.push('FAQ');
258
- if (!hasTestimonials) missingTopics.push('testimonials/reviews');
259
- if (!hasProofPoints) missingTopics.push('proof points/case studies');
260
-
261
- if (missingTopics.length >= 2) {
262
- issues.push({
263
- code: 'AI_INCOMPLETE_BRAND_COVERAGE',
264
- severity: 'notice',
265
- category: 'ai-readiness',
266
- title: 'Incomplete brand topic coverage',
267
- description: `Missing key brand topics that AI uses to answer queries: ${missingTopics.join(', ')}. AI may rely on third-party sources instead.`,
268
- impact: 'Third-party sites may define your brand narrative instead of you.',
269
- howToFix: 'Cover key brand topics on your site: pricing, positioning, proof (testimonials, case studies), and FAQs.',
270
- affectedUrls: [url],
271
- details: {
272
- missingTopics,
273
- recommendation: 'Control your brand narrative by having authoritative content on these topics on your own site.',
274
- },
275
- });
276
- }
277
-
278
- // No review platform integration
279
- if (!hasReviewLinks && !hasTestimonials) {
280
- issues.push({
281
- code: 'AI_NO_REVIEW_INTEGRATION',
282
- severity: 'notice',
283
- category: 'ai-readiness',
284
- title: 'No review platform integration',
285
- description: 'No links to review platforms or testimonial sections found. AI uses review signals from multiple platforms for trust.',
286
- impact: 'Missing review diversity signals that AI uses for brand trust assessment.',
287
- howToFix: 'Link to your profiles on relevant review platforms (G2, Capterra, Trustpilot, etc.) and display testimonials with attribution.',
288
- affectedUrls: [url],
289
- details: {
290
- relevantPlatforms: [
291
- 'B2B SaaS: G2, Capterra, TrustRadius',
292
- 'Local: Google Business, Yelp, BBB',
293
- 'Professional: Clutch, UpCity',
294
- ],
295
- },
296
- });
297
- }
298
-
299
- // Low brand score
300
- if (brandScore < 50) {
301
- issues.push({
302
- code: 'AI_LOW_BRAND_SCORE',
303
- severity: 'warning',
304
- category: 'ai-readiness',
305
- title: 'Brand is not well-optimized for AI extraction',
306
- description: `Brand optimization score: ${brandScore}/100. AI may struggle to accurately describe and recommend your brand.`,
307
- impact: 'Low likelihood of being recommended in AI answers for brand-related queries.',
308
- howToFix: 'Improve brand clarity: add quotable definitions, USPs, testimonials, proof points, and link to review platforms.',
309
- affectedUrls: [url],
310
- details: {
311
- brandScore,
312
- hasBrandDefinition,
313
- hasUSP,
314
- hasTestimonials,
315
- hasProofPoints,
316
- hasReviewLinks,
317
- quotableBrandStatements: quotableBrandStatements.slice(0, 3),
318
- },
319
- });
320
- }
321
-
322
- return {
323
- issues,
324
- data: {
325
- brandSignals: {
326
- hasBrandDefinition,
327
- hasUSP,
328
- hasValueProposition,
329
- hasBrandStatement,
330
- brandMentionCount,
331
- },
332
- brandCoverage: {
333
- hasPricingInfo,
334
- hasAboutSection,
335
- hasFAQSection,
336
- hasTestimonials,
337
- hasProofPoints,
338
- },
339
- brandConsistency: {
340
- hasConsistentNaming,
341
- hasContactInfo,
342
- hasSocialLinks,
343
- hasReviewLinks,
344
- },
345
- quotableBrandStatements,
346
- brandScore,
347
- },
348
- };
349
- }
@@ -1,305 +0,0 @@
1
- /**
2
- * Browser Caching Headers Check
3
- *
4
- * Validates HTTP caching headers for optimal performance:
5
- * - Cache-Control header
6
- * - Expires header
7
- * - ETag header
8
- * - Last-Modified header
9
- *
10
- * Proper caching improves page load times for repeat visitors
11
- * and reduces server load.
12
- */
13
-
14
- import { httpGet } from '../../utils/http.js';
15
- import type { AuditIssue } from '../types.js';
16
-
17
- export interface CachingHeadersData {
18
- htmlCaching: {
19
- cacheControl?: string;
20
- expires?: string;
21
- etag?: string;
22
- lastModified?: string;
23
- maxAge?: number;
24
- isPublic: boolean;
25
- isPrivate: boolean;
26
- noStore: boolean;
27
- noCache: boolean;
28
- };
29
- staticAssets: AssetCachingInfo[];
30
- issues: {
31
- noCaching: number;
32
- shortTtl: number;
33
- properlyConfigured: number;
34
- };
35
- }
36
-
37
- interface AssetCachingInfo {
38
- url: string;
39
- type: string;
40
- cacheControl?: string;
41
- maxAge?: number;
42
- hasCaching: boolean;
43
- }
44
-
45
- // Recommended cache durations (in seconds)
46
- const CACHE_RECOMMENDATIONS = {
47
- html: 0, // HTML should generally not be cached or have short TTL
48
- css: 31536000, // 1 year for versioned assets
49
- js: 31536000,
50
- images: 31536000,
51
- fonts: 31536000,
52
- minimum: 86400, // 1 day minimum for static assets
53
- };
54
-
55
- export async function analyzeCachingHeaders(
56
- url: string,
57
- headers?: Record<string, string>
58
- ): Promise<{ issues: AuditIssue[]; data: CachingHeadersData }> {
59
- const issues: AuditIssue[] = [];
60
-
61
- // Analyze HTML page headers
62
- let htmlHeaders = headers;
63
- if (!htmlHeaders) {
64
- try {
65
- const response = await httpGet<string>(url, {
66
- timeout: 10000,
67
- validateStatus: () => true,
68
- });
69
- htmlHeaders = response.headers as Record<string, string>;
70
- } catch {
71
- htmlHeaders = {};
72
- }
73
- }
74
-
75
- const htmlCaching = parseCacheHeaders(htmlHeaders);
76
-
77
- // Check HTML caching (should be minimal or no caching)
78
- if (htmlCaching.maxAge && htmlCaching.maxAge > 3600) {
79
- issues.push({
80
- code: 'CACHING_HTML_TOO_LONG',
81
- severity: 'notice',
82
- category: 'performance',
83
- title: 'HTML page has long cache duration',
84
- description: `HTML page has Cache-Control max-age of ${htmlCaching.maxAge} seconds (${Math.round(htmlCaching.maxAge / 3600)} hours). HTML content changes frequently.`,
85
- impact: 'Users may see stale content. Content updates may not appear immediately.',
86
- howToFix: 'Set shorter cache duration for HTML: Cache-Control: no-cache or max-age=0, must-revalidate',
87
- affectedUrls: [url],
88
- });
89
- }
90
-
91
- // Sample static assets to check their caching
92
- const staticAssets: AssetCachingInfo[] = [];
93
- const assetUrls = await getStaticAssetUrls(url);
94
-
95
- let noCaching = 0;
96
- let shortTtl = 0;
97
- let properlyConfigured = 0;
98
-
99
- // Check up to 5 static assets
100
- const assetsToCheck = assetUrls.slice(0, 5);
101
-
102
- for (const assetUrl of assetsToCheck) {
103
- try {
104
- const assetResponse = await httpGet<string>(assetUrl, {
105
- timeout: 5000,
106
- validateStatus: () => true,
107
- });
108
-
109
- const assetCaching = parseCacheHeaders(assetResponse.headers as Record<string, string>);
110
- const type = getAssetType(assetUrl);
111
-
112
- const assetInfo: AssetCachingInfo = {
113
- url: assetUrl,
114
- type,
115
- cacheControl: assetCaching.cacheControl,
116
- maxAge: assetCaching.maxAge,
117
- hasCaching: Boolean(assetCaching.cacheControl || assetCaching.expires),
118
- };
119
-
120
- staticAssets.push(assetInfo);
121
-
122
- if (!assetInfo.hasCaching) {
123
- noCaching++;
124
- } else if (assetCaching.maxAge && assetCaching.maxAge < CACHE_RECOMMENDATIONS.minimum) {
125
- shortTtl++;
126
- } else {
127
- properlyConfigured++;
128
- }
129
- } catch {
130
- // Asset check failed, skip
131
- }
132
- }
133
-
134
- // Generate issues for static assets
135
- if (noCaching > 0) {
136
- issues.push({
137
- code: 'CACHING_STATIC_NO_CACHE',
138
- severity: 'warning',
139
- category: 'performance',
140
- title: 'Static assets missing cache headers',
141
- description: `${noCaching} static asset(s) have no Cache-Control header. This forces browsers to re-download on every visit.`,
142
- impact: 'Slower page loads for repeat visitors. Increased bandwidth usage.',
143
- howToFix: 'Add Cache-Control headers to static assets. For versioned files (with hash in filename), use: Cache-Control: public, max-age=31536000, immutable',
144
- affectedUrls: staticAssets.filter(a => !a.hasCaching).map(a => a.url),
145
- details: {
146
- recommendation: {
147
- 'versioned assets (with hash)': 'Cache-Control: public, max-age=31536000, immutable',
148
- 'non-versioned assets': 'Cache-Control: public, max-age=86400',
149
- },
150
- },
151
- });
152
- }
153
-
154
- if (shortTtl > 0) {
155
- issues.push({
156
- code: 'CACHING_STATIC_SHORT_TTL',
157
- severity: 'notice',
158
- category: 'performance',
159
- title: 'Static assets have short cache duration',
160
- description: `${shortTtl} static asset(s) have cache duration under 1 day. Consider longer caching for better performance.`,
161
- impact: 'Assets are re-downloaded more often than necessary.',
162
- howToFix: 'Increase max-age for static assets. Use versioned filenames (hash in filename) to enable long-term caching.',
163
- affectedUrls: staticAssets.filter(a => a.maxAge && a.maxAge < CACHE_RECOMMENDATIONS.minimum).map(a => a.url),
164
- });
165
- }
166
-
167
- // Check for missing ETag or Last-Modified
168
- if (!htmlCaching.etag && !htmlCaching.lastModified) {
169
- issues.push({
170
- code: 'CACHING_NO_VALIDATORS',
171
- severity: 'notice',
172
- category: 'performance',
173
- title: 'Missing cache validators (ETag/Last-Modified)',
174
- description: 'Page is missing both ETag and Last-Modified headers. These allow efficient cache validation.',
175
- impact: 'Browsers cannot efficiently validate if cached content is still fresh.',
176
- howToFix: 'Configure your server to send ETag or Last-Modified headers. Most web servers do this automatically for static files.',
177
- affectedUrls: [url],
178
- });
179
- }
180
-
181
- return {
182
- issues,
183
- data: {
184
- htmlCaching,
185
- staticAssets,
186
- issues: {
187
- noCaching,
188
- shortTtl,
189
- properlyConfigured,
190
- },
191
- },
192
- };
193
- }
194
-
195
- function parseCacheHeaders(headers: Record<string, string>): CachingHeadersData['htmlCaching'] {
196
- const cacheControl = headers['cache-control'] || headers['Cache-Control'];
197
- const expires = headers['expires'] || headers['Expires'];
198
- const etag = headers['etag'] || headers['ETag'];
199
- const lastModified = headers['last-modified'] || headers['Last-Modified'];
200
-
201
- let maxAge: number | undefined;
202
- let isPublic = false;
203
- let isPrivate = false;
204
- let noStore = false;
205
- let noCache = false;
206
-
207
- if (cacheControl) {
208
- // Parse max-age
209
- const maxAgeMatch = cacheControl.match(/max-age=(\d+)/i);
210
- if (maxAgeMatch) {
211
- maxAge = parseInt(maxAgeMatch[1], 10);
212
- }
213
-
214
- // Parse directives
215
- const lowerCC = cacheControl.toLowerCase();
216
- isPublic = lowerCC.includes('public');
217
- isPrivate = lowerCC.includes('private');
218
- noStore = lowerCC.includes('no-store');
219
- noCache = lowerCC.includes('no-cache');
220
- }
221
-
222
- return {
223
- cacheControl,
224
- expires,
225
- etag,
226
- lastModified,
227
- maxAge,
228
- isPublic,
229
- isPrivate,
230
- noStore,
231
- noCache,
232
- };
233
- }
234
-
235
- async function getStaticAssetUrls(pageUrl: string): Promise<string[]> {
236
- const assets: string[] = [];
237
-
238
- try {
239
- const response = await httpGet<string>(pageUrl, {
240
- timeout: 10000,
241
- validateStatus: () => true,
242
- });
243
-
244
- const html = response.data as string;
245
- const baseUrl = new URL(pageUrl);
246
-
247
- // Extract CSS files
248
- const cssMatches = html.match(/href="([^"]+\.css[^"]*)"/gi);
249
- if (cssMatches) {
250
- for (const match of cssMatches.slice(0, 2)) {
251
- const href = match.match(/href="([^"]+)"/)?.[1];
252
- if (href) {
253
- try {
254
- assets.push(new URL(href, baseUrl).href);
255
- } catch {
256
- // Invalid URL
257
- }
258
- }
259
- }
260
- }
261
-
262
- // Extract JS files
263
- const jsMatches = html.match(/src="([^"]+\.js[^"]*)"/gi);
264
- if (jsMatches) {
265
- for (const match of jsMatches.slice(0, 2)) {
266
- const src = match.match(/src="([^"]+)"/)?.[1];
267
- if (src) {
268
- try {
269
- assets.push(new URL(src, baseUrl).href);
270
- } catch {
271
- // Invalid URL
272
- }
273
- }
274
- }
275
- }
276
-
277
- // Extract image files
278
- const imgMatches = html.match(/src="([^"]+\.(png|jpg|jpeg|gif|webp|svg)[^"]*)"/gi);
279
- if (imgMatches) {
280
- for (const match of imgMatches.slice(0, 1)) {
281
- const src = match.match(/src="([^"]+)"/)?.[1];
282
- if (src) {
283
- try {
284
- assets.push(new URL(src, baseUrl).href);
285
- } catch {
286
- // Invalid URL
287
- }
288
- }
289
- }
290
- }
291
- } catch {
292
- // Failed to fetch page
293
- }
294
-
295
- return assets;
296
- }
297
-
298
- function getAssetType(url: string): string {
299
- const lowerUrl = url.toLowerCase();
300
- if (lowerUrl.includes('.css')) return 'css';
301
- if (lowerUrl.includes('.js')) return 'javascript';
302
- if (lowerUrl.match(/\.(png|jpg|jpeg|gif|webp|svg|ico)/)) return 'image';
303
- if (lowerUrl.match(/\.(woff|woff2|ttf|otf|eot)/)) return 'font';
304
- return 'other';
305
- }