@rankcli/agent-runtime 0.0.1
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.
- package/README.md +242 -0
- package/dist/analyzer-2CSWIQGD.mjs +6 -0
- package/dist/chunk-YNZYHEYM.mjs +774 -0
- package/dist/index.d.mts +4012 -0
- package/dist/index.d.ts +4012 -0
- package/dist/index.js +29672 -0
- package/dist/index.mjs +28602 -0
- package/package.json +53 -0
- package/scripts/build-deno.ts +134 -0
- package/src/audit/ai/analyzer.ts +347 -0
- package/src/audit/ai/index.ts +29 -0
- package/src/audit/ai/prompts/content-analysis.ts +271 -0
- package/src/audit/ai/types.ts +179 -0
- package/src/audit/checks/additional-checks.ts +439 -0
- package/src/audit/checks/ai-citation-worthiness.ts +399 -0
- package/src/audit/checks/ai-content-structure.ts +325 -0
- package/src/audit/checks/ai-readiness.ts +339 -0
- package/src/audit/checks/anchor-text.ts +179 -0
- package/src/audit/checks/answer-conciseness.ts +322 -0
- package/src/audit/checks/asset-minification.ts +270 -0
- package/src/audit/checks/bing-optimization.ts +206 -0
- package/src/audit/checks/brand-mention-optimization.ts +349 -0
- package/src/audit/checks/caching-headers.ts +305 -0
- package/src/audit/checks/canonical-advanced.ts +150 -0
- package/src/audit/checks/canonical-domain.ts +196 -0
- package/src/audit/checks/citation-quality.ts +358 -0
- package/src/audit/checks/client-rendering.ts +542 -0
- package/src/audit/checks/color-contrast.ts +342 -0
- package/src/audit/checks/content-freshness.ts +170 -0
- package/src/audit/checks/content-science.ts +589 -0
- package/src/audit/checks/conversion-elements.ts +526 -0
- package/src/audit/checks/crawlability.ts +220 -0
- package/src/audit/checks/directory-listing.ts +172 -0
- package/src/audit/checks/dom-analysis.ts +191 -0
- package/src/audit/checks/dom-size.ts +246 -0
- package/src/audit/checks/duplicate-content.ts +194 -0
- package/src/audit/checks/eeat-signals.ts +990 -0
- package/src/audit/checks/entity-seo.ts +396 -0
- package/src/audit/checks/featured-snippet.ts +473 -0
- package/src/audit/checks/freshness-signals.ts +443 -0
- package/src/audit/checks/funnel-intent.ts +463 -0
- package/src/audit/checks/hreflang.ts +174 -0
- package/src/audit/checks/html-compliance.ts +302 -0
- package/src/audit/checks/image-dimensions.ts +167 -0
- package/src/audit/checks/images.ts +160 -0
- package/src/audit/checks/indexnow.ts +275 -0
- package/src/audit/checks/interactive-tools.ts +475 -0
- package/src/audit/checks/internal-link-graph.ts +436 -0
- package/src/audit/checks/keyword-analysis.ts +239 -0
- package/src/audit/checks/keyword-cannibalization.ts +385 -0
- package/src/audit/checks/keyword-placement.ts +471 -0
- package/src/audit/checks/links.ts +203 -0
- package/src/audit/checks/llms-txt.ts +224 -0
- package/src/audit/checks/local-seo.ts +296 -0
- package/src/audit/checks/mobile.ts +167 -0
- package/src/audit/checks/modern-images.ts +226 -0
- package/src/audit/checks/navboost-signals.ts +395 -0
- package/src/audit/checks/on-page.ts +209 -0
- package/src/audit/checks/page-resources.ts +285 -0
- package/src/audit/checks/pagination.ts +180 -0
- package/src/audit/checks/performance.ts +153 -0
- package/src/audit/checks/platform-presence.ts +580 -0
- package/src/audit/checks/redirect-analysis.ts +153 -0
- package/src/audit/checks/redirect-chain.ts +389 -0
- package/src/audit/checks/resource-hints.ts +420 -0
- package/src/audit/checks/responsive-css.ts +247 -0
- package/src/audit/checks/responsive-images.ts +396 -0
- package/src/audit/checks/review-ecosystem.ts +415 -0
- package/src/audit/checks/robots-validation.ts +373 -0
- package/src/audit/checks/security-headers.ts +172 -0
- package/src/audit/checks/security.ts +144 -0
- package/src/audit/checks/serp-preview.ts +251 -0
- package/src/audit/checks/site-maturity.ts +444 -0
- package/src/audit/checks/social-meta.test.ts +275 -0
- package/src/audit/checks/social-meta.ts +134 -0
- package/src/audit/checks/soft-404.ts +151 -0
- package/src/audit/checks/structured-data.ts +238 -0
- package/src/audit/checks/tech-detection.ts +496 -0
- package/src/audit/checks/topical-clusters.ts +435 -0
- package/src/audit/checks/tracker-bloat.ts +462 -0
- package/src/audit/checks/tracking-verification.test.ts +371 -0
- package/src/audit/checks/tracking-verification.ts +636 -0
- package/src/audit/checks/url-safety.ts +682 -0
- package/src/audit/deno-entry.ts +66 -0
- package/src/audit/discovery/index.ts +15 -0
- package/src/audit/discovery/link-crawler.ts +232 -0
- package/src/audit/discovery/repo-routes.ts +347 -0
- package/src/audit/engine.ts +620 -0
- package/src/audit/fixes/index.ts +209 -0
- package/src/audit/fixes/social-meta-fixes.test.ts +329 -0
- package/src/audit/fixes/social-meta-fixes.ts +463 -0
- package/src/audit/index.ts +74 -0
- package/src/audit/runner.test.ts +299 -0
- package/src/audit/runner.ts +130 -0
- package/src/audit/types.ts +1953 -0
- package/src/content/featured-snippet.ts +367 -0
- package/src/content/generator.test.ts +534 -0
- package/src/content/generator.ts +501 -0
- package/src/content/headline.ts +317 -0
- package/src/content/index.ts +62 -0
- package/src/content/intent.ts +258 -0
- package/src/content/keyword-density.ts +349 -0
- package/src/content/readability.ts +262 -0
- package/src/executor.ts +336 -0
- package/src/fixer.ts +416 -0
- package/src/frameworks/detector.test.ts +248 -0
- package/src/frameworks/detector.ts +371 -0
- package/src/frameworks/index.ts +68 -0
- package/src/frameworks/recipes/angular.yaml +171 -0
- package/src/frameworks/recipes/astro.yaml +206 -0
- package/src/frameworks/recipes/django.yaml +180 -0
- package/src/frameworks/recipes/laravel.yaml +137 -0
- package/src/frameworks/recipes/nextjs.yaml +268 -0
- package/src/frameworks/recipes/nuxt.yaml +175 -0
- package/src/frameworks/recipes/rails.yaml +188 -0
- package/src/frameworks/recipes/react.yaml +202 -0
- package/src/frameworks/recipes/sveltekit.yaml +154 -0
- package/src/frameworks/recipes/vue.yaml +137 -0
- package/src/frameworks/recipes/wordpress.yaml +209 -0
- package/src/frameworks/suggestion-engine.ts +320 -0
- package/src/geo/geo-content.test.ts +305 -0
- package/src/geo/geo-content.ts +266 -0
- package/src/geo/geo-history.test.ts +473 -0
- package/src/geo/geo-history.ts +433 -0
- package/src/geo/geo-tracker.test.ts +359 -0
- package/src/geo/geo-tracker.ts +411 -0
- package/src/geo/index.ts +10 -0
- package/src/git/commit-helper.test.ts +261 -0
- package/src/git/commit-helper.ts +329 -0
- package/src/git/index.ts +12 -0
- package/src/git/pr-helper.test.ts +284 -0
- package/src/git/pr-helper.ts +307 -0
- package/src/index.ts +66 -0
- package/src/keywords/ai-keyword-engine.ts +1062 -0
- package/src/keywords/ai-summarizer.ts +387 -0
- package/src/keywords/ci-mode.ts +555 -0
- package/src/keywords/engine.ts +359 -0
- package/src/keywords/index.ts +151 -0
- package/src/keywords/llm-judge.ts +357 -0
- package/src/keywords/nlp-analysis.ts +706 -0
- package/src/keywords/prioritizer.ts +295 -0
- package/src/keywords/site-crawler.ts +342 -0
- package/src/keywords/sources/autocomplete.ts +139 -0
- package/src/keywords/sources/competitive-search.ts +450 -0
- package/src/keywords/sources/competitor-analysis.ts +374 -0
- package/src/keywords/sources/dataforseo.ts +206 -0
- package/src/keywords/sources/free-sources.ts +294 -0
- package/src/keywords/sources/gsc.ts +123 -0
- package/src/keywords/topic-grouping.ts +327 -0
- package/src/keywords/types.ts +144 -0
- package/src/keywords/wizard.ts +457 -0
- package/src/loader.ts +40 -0
- package/src/reports/index.ts +7 -0
- package/src/reports/report-generator.test.ts +293 -0
- package/src/reports/report-generator.ts +713 -0
- package/src/scheduler/alerts.test.ts +458 -0
- package/src/scheduler/alerts.ts +328 -0
- package/src/scheduler/index.ts +8 -0
- package/src/scheduler/scheduled-audit.test.ts +377 -0
- package/src/scheduler/scheduled-audit.ts +149 -0
- package/src/test/integration-test.ts +325 -0
- package/src/tools/analyzer.ts +373 -0
- package/src/tools/crawl.ts +293 -0
- package/src/tools/files.ts +301 -0
- package/src/tools/h1-fixer.ts +249 -0
- package/src/tools/index.ts +67 -0
- package/src/tracking/github-action.ts +326 -0
- package/src/tracking/google-analytics.ts +265 -0
- package/src/tracking/index.ts +45 -0
- package/src/tracking/report-generator.ts +386 -0
- package/src/tracking/search-console.ts +335 -0
- package/src/types.ts +134 -0
- package/src/utils/http.ts +302 -0
- package/src/wasm-adapter.ts +297 -0
- package/src/wasm-entry.ts +14 -0
- package/tsconfig.json +17 -0
- package/tsup.wasm.config.ts +26 -0
- package/vitest.config.ts +15 -0
|
@@ -0,0 +1,349 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,305 @@
|
|
|
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
|
+
}
|