@rankcli/agent-runtime 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/dist/index.d.mts +43 -393
  2. package/dist/index.d.ts +43 -393
  3. package/dist/index.js +306 -6526
  4. package/dist/index.mjs +202 -6412
  5. package/package.json +6 -1
  6. package/scripts/build-deno.ts +0 -134
  7. package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
  8. package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
  9. package/src/analyzers/geo-analyzer.test.ts +0 -310
  10. package/src/analyzers/geo-analyzer.ts +0 -814
  11. package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
  12. package/src/analyzers/image-optimization-analyzer.ts +0 -348
  13. package/src/analyzers/index.ts +0 -233
  14. package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
  15. package/src/analyzers/internal-linking-analyzer.ts +0 -419
  16. package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
  17. package/src/analyzers/mobile-seo-analyzer.ts +0 -455
  18. package/src/analyzers/security-headers-analyzer.test.ts +0 -115
  19. package/src/analyzers/security-headers-analyzer.ts +0 -318
  20. package/src/analyzers/structured-data-analyzer.test.ts +0 -210
  21. package/src/analyzers/structured-data-analyzer.ts +0 -590
  22. package/src/audit/ai/analyzer.ts +0 -347
  23. package/src/audit/ai/index.ts +0 -29
  24. package/src/audit/ai/prompts/content-analysis.ts +0 -271
  25. package/src/audit/ai/types.ts +0 -179
  26. package/src/audit/checks/additional-checks.ts +0 -439
  27. package/src/audit/checks/agent-experience.ts +0 -108
  28. package/src/audit/checks/ai-citation-worthiness.ts +0 -399
  29. package/src/audit/checks/ai-content-structure.ts +0 -325
  30. package/src/audit/checks/ai-readiness.ts +0 -406
  31. package/src/audit/checks/anchor-text.ts +0 -179
  32. package/src/audit/checks/answer-conciseness.ts +0 -322
  33. package/src/audit/checks/asset-minification.ts +0 -270
  34. package/src/audit/checks/bing-optimization.ts +0 -206
  35. package/src/audit/checks/brand-mention-optimization.ts +0 -349
  36. package/src/audit/checks/caching-headers.ts +0 -305
  37. package/src/audit/checks/canonical-advanced.ts +0 -150
  38. package/src/audit/checks/canonical-domain.ts +0 -196
  39. package/src/audit/checks/citation-quality.ts +0 -358
  40. package/src/audit/checks/client-rendering.ts +0 -542
  41. package/src/audit/checks/color-contrast.ts +0 -342
  42. package/src/audit/checks/content-freshness.ts +0 -170
  43. package/src/audit/checks/content-science.ts +0 -589
  44. package/src/audit/checks/conversion-elements.ts +0 -526
  45. package/src/audit/checks/crawlability.ts +0 -220
  46. package/src/audit/checks/directory-listing.ts +0 -172
  47. package/src/audit/checks/dom-analysis.ts +0 -191
  48. package/src/audit/checks/dom-size.ts +0 -246
  49. package/src/audit/checks/duplicate-content.ts +0 -194
  50. package/src/audit/checks/eeat-signals.ts +0 -990
  51. package/src/audit/checks/entity-seo.ts +0 -396
  52. package/src/audit/checks/featured-snippet.ts +0 -473
  53. package/src/audit/checks/freshness-signals.ts +0 -443
  54. package/src/audit/checks/funnel-intent.ts +0 -463
  55. package/src/audit/checks/hreflang.ts +0 -174
  56. package/src/audit/checks/html-compliance.ts +0 -302
  57. package/src/audit/checks/image-dimensions.ts +0 -167
  58. package/src/audit/checks/images.ts +0 -160
  59. package/src/audit/checks/indexnow.ts +0 -275
  60. package/src/audit/checks/interactive-tools.ts +0 -475
  61. package/src/audit/checks/internal-link-graph.ts +0 -436
  62. package/src/audit/checks/keyword-analysis.ts +0 -239
  63. package/src/audit/checks/keyword-cannibalization.ts +0 -385
  64. package/src/audit/checks/keyword-placement.ts +0 -471
  65. package/src/audit/checks/links.ts +0 -273
  66. package/src/audit/checks/llms-txt.ts +0 -224
  67. package/src/audit/checks/local-seo.ts +0 -296
  68. package/src/audit/checks/mobile.ts +0 -167
  69. package/src/audit/checks/modern-images.ts +0 -226
  70. package/src/audit/checks/navboost-signals.ts +0 -395
  71. package/src/audit/checks/on-page.ts +0 -209
  72. package/src/audit/checks/page-resources.ts +0 -285
  73. package/src/audit/checks/pagination.ts +0 -180
  74. package/src/audit/checks/performance.ts +0 -153
  75. package/src/audit/checks/platform-presence.ts +0 -580
  76. package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
  77. package/src/audit/checks/rag-chunk-readiness.ts +0 -163
  78. package/src/audit/checks/redirect-analysis.ts +0 -153
  79. package/src/audit/checks/redirect-chain.ts +0 -389
  80. package/src/audit/checks/resource-hints.ts +0 -420
  81. package/src/audit/checks/responsive-css.ts +0 -247
  82. package/src/audit/checks/responsive-images.ts +0 -396
  83. package/src/audit/checks/review-ecosystem.ts +0 -415
  84. package/src/audit/checks/robots-validation.ts +0 -373
  85. package/src/audit/checks/security-headers.ts +0 -188
  86. package/src/audit/checks/security.ts +0 -144
  87. package/src/audit/checks/serp-preview.ts +0 -251
  88. package/src/audit/checks/site-maturity.ts +0 -453
  89. package/src/audit/checks/social-meta.test.ts +0 -275
  90. package/src/audit/checks/social-meta.ts +0 -134
  91. package/src/audit/checks/soft-404.ts +0 -151
  92. package/src/audit/checks/structured-data.ts +0 -238
  93. package/src/audit/checks/tech-detection.ts +0 -496
  94. package/src/audit/checks/topical-clusters.ts +0 -435
  95. package/src/audit/checks/tracker-bloat.ts +0 -462
  96. package/src/audit/checks/tracking-verification.test.ts +0 -371
  97. package/src/audit/checks/tracking-verification.ts +0 -636
  98. package/src/audit/checks/url-safety.ts +0 -682
  99. package/src/audit/deno-entry.ts +0 -66
  100. package/src/audit/discovery/index.ts +0 -15
  101. package/src/audit/discovery/link-crawler.ts +0 -233
  102. package/src/audit/discovery/repo-routes.ts +0 -347
  103. package/src/audit/engine.ts +0 -633
  104. package/src/audit/fixes/index.ts +0 -209
  105. package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
  106. package/src/audit/fixes/social-meta-fixes.ts +0 -463
  107. package/src/audit/index.ts +0 -74
  108. package/src/audit/runner.test.ts +0 -299
  109. package/src/audit/runner.ts +0 -130
  110. package/src/audit/types.ts +0 -1987
  111. package/src/content/featured-snippet.ts +0 -367
  112. package/src/content/generator.test.ts +0 -534
  113. package/src/content/generator.ts +0 -501
  114. package/src/content/headline.ts +0 -317
  115. package/src/content/index.ts +0 -62
  116. package/src/content/intent.ts +0 -258
  117. package/src/content/keyword-density.ts +0 -349
  118. package/src/content/readability.ts +0 -262
  119. package/src/executor.ts +0 -336
  120. package/src/fixer/framework-fixes.test.ts +0 -489
  121. package/src/fixer/framework-fixes.ts +0 -5287
  122. package/src/fixer/index.ts +0 -6
  123. package/src/fixer/schemas.ts +0 -971
  124. package/src/fixer.ts +0 -642
  125. package/src/frameworks/detector.test.ts +0 -248
  126. package/src/frameworks/detector.ts +0 -899
  127. package/src/frameworks/index.ts +0 -68
  128. package/src/frameworks/recipes/angular.yaml +0 -171
  129. package/src/frameworks/recipes/astro.yaml +0 -206
  130. package/src/frameworks/recipes/django.yaml +0 -180
  131. package/src/frameworks/recipes/laravel.yaml +0 -137
  132. package/src/frameworks/recipes/nextjs.yaml +0 -268
  133. package/src/frameworks/recipes/nuxt.yaml +0 -175
  134. package/src/frameworks/recipes/rails.yaml +0 -188
  135. package/src/frameworks/recipes/react.yaml +0 -202
  136. package/src/frameworks/recipes/sveltekit.yaml +0 -154
  137. package/src/frameworks/recipes/vue.yaml +0 -137
  138. package/src/frameworks/recipes/wordpress.yaml +0 -209
  139. package/src/frameworks/suggestion-engine.ts +0 -357
  140. package/src/geo/geo-content.test.ts +0 -305
  141. package/src/geo/geo-content.ts +0 -266
  142. package/src/geo/geo-history.test.ts +0 -473
  143. package/src/geo/geo-history.ts +0 -433
  144. package/src/geo/geo-tracker.test.ts +0 -359
  145. package/src/geo/geo-tracker.ts +0 -411
  146. package/src/geo/index.ts +0 -11
  147. package/src/geo/llm-citation-checker.ts +0 -188
  148. package/src/git/commit-helper.test.ts +0 -261
  149. package/src/git/commit-helper.ts +0 -329
  150. package/src/git/index.ts +0 -12
  151. package/src/git/pr-helper.test.ts +0 -284
  152. package/src/git/pr-helper.ts +0 -307
  153. package/src/index.ts +0 -76
  154. package/src/keywords/ai-keyword-engine.ts +0 -1062
  155. package/src/keywords/ai-summarizer.ts +0 -387
  156. package/src/keywords/ci-mode.ts +0 -555
  157. package/src/keywords/engine.ts +0 -359
  158. package/src/keywords/index.ts +0 -151
  159. package/src/keywords/llm-judge.ts +0 -357
  160. package/src/keywords/nlp-analysis.ts +0 -706
  161. package/src/keywords/prioritizer.ts +0 -295
  162. package/src/keywords/site-crawler.ts +0 -342
  163. package/src/keywords/sources/autocomplete.ts +0 -139
  164. package/src/keywords/sources/competitive-search.ts +0 -450
  165. package/src/keywords/sources/competitor-analysis.ts +0 -374
  166. package/src/keywords/sources/dataforseo.ts +0 -206
  167. package/src/keywords/sources/free-sources.ts +0 -294
  168. package/src/keywords/sources/gsc.ts +0 -123
  169. package/src/keywords/topic-grouping.ts +0 -327
  170. package/src/keywords/types.ts +0 -144
  171. package/src/keywords/wizard.ts +0 -457
  172. package/src/loader.ts +0 -40
  173. package/src/ranking/index.ts +0 -5
  174. package/src/ranking/serp-client.ts +0 -348
  175. package/src/ranking/tracker.ts +0 -380
  176. package/src/ranking/types.ts +0 -123
  177. package/src/reports/index.ts +0 -7
  178. package/src/reports/report-generator.test.ts +0 -293
  179. package/src/reports/report-generator.ts +0 -713
  180. package/src/scheduler/alerts.test.ts +0 -458
  181. package/src/scheduler/alerts.ts +0 -328
  182. package/src/scheduler/index.ts +0 -8
  183. package/src/scheduler/scheduled-audit.test.ts +0 -377
  184. package/src/scheduler/scheduled-audit.ts +0 -149
  185. package/src/test/integration-test.ts +0 -325
  186. package/src/tools/analyzer.ts +0 -373
  187. package/src/tools/crawl.ts +0 -293
  188. package/src/tools/files.ts +0 -301
  189. package/src/tools/h1-fixer.ts +0 -249
  190. package/src/tools/index.ts +0 -67
  191. package/src/tracking/github-action.ts +0 -326
  192. package/src/tracking/google-analytics.ts +0 -265
  193. package/src/tracking/index.ts +0 -45
  194. package/src/tracking/report-generator.ts +0 -386
  195. package/src/tracking/search-console.ts +0 -335
  196. package/src/types.ts +0 -148
  197. package/src/utils/http.ts +0 -302
  198. package/src/wasm-adapter.ts +0 -297
  199. package/src/wasm-entry.ts +0 -14
  200. package/tsconfig.json +0 -17
  201. package/tsup.wasm.config.ts +0 -26
  202. package/vitest.config.ts +0 -15
@@ -1,179 +0,0 @@
1
- // AI-Powered SEO Analysis Types
2
-
3
- export interface AIConfig {
4
- openaiApiKey: string;
5
- model?: 'gpt-4o' | 'gpt-4o-mini' | 'gpt-4-turbo';
6
- maxTokens?: number;
7
- temperature?: number;
8
- }
9
-
10
- // Content Analysis Types
11
- export interface AIContentAnalysis {
12
- overallScore: number;
13
- searchIntentMatch: number;
14
- contentDepth: 'shallow' | 'moderate' | 'comprehensive';
15
- keywordNaturalness: number;
16
-
17
- eeatSignals: {
18
- experience: string[];
19
- expertise: string[];
20
- authority: string[];
21
- trust: string[];
22
- };
23
-
24
- improvements: {
25
- priority: number;
26
- suggestion: string;
27
- impact: string;
28
- }[];
29
-
30
- uniqueValue: string;
31
- missingTopics: string[];
32
- targetKeyword?: string;
33
- keywordDensity?: number;
34
- }
35
-
36
- // Meta Tag Analysis Types
37
- export interface AIMetaAnalysis {
38
- titleAnalysis: {
39
- effectiveness: number;
40
- clickPotential: number;
41
- keywordPlacement: 'optimal' | 'suboptimal' | 'missing';
42
- emotionalTriggers: string[];
43
- suggestions: string[];
44
- };
45
-
46
- descriptionAnalysis: {
47
- effectiveness: number;
48
- hasCallToAction: boolean;
49
- hasUniqueSellingProposition: boolean;
50
- keywordNaturalness: number;
51
- suggestions: string[];
52
- };
53
-
54
- serpPrediction: {
55
- predictedCTR: number;
56
- competitiveStrength: 'weak' | 'average' | 'strong';
57
- improvements: string[];
58
- };
59
- }
60
-
61
- // Schema/Structured Data Analysis Types
62
- export interface AISchemaAnalysis {
63
- detectedPageType: string;
64
- recommendedSchemas: {
65
- type: string;
66
- priority: 'critical' | 'high' | 'medium' | 'low';
67
- reason: string;
68
- }[];
69
-
70
- generatedSchemas: {
71
- type: string;
72
- jsonLd: object;
73
- explanation: string;
74
- }[];
75
-
76
- richSnippetPotential: {
77
- type: string;
78
- eligible: boolean;
79
- requirements: string[];
80
- }[];
81
- }
82
-
83
- // Link Quality Analysis Types
84
- export interface AILinkAnalysis {
85
- internalLinkQuality: {
86
- topicalRelevance: number;
87
- anchorTextQuality: 'descriptive' | 'generic' | 'over-optimized';
88
- distribution: 'balanced' | 'top-heavy' | 'sparse';
89
- };
90
-
91
- suggestedInternalLinks: {
92
- targetUrl: string;
93
- suggestedAnchor: string;
94
- contextReason: string;
95
- }[];
96
-
97
- externalLinkQuality: {
98
- authorityScore: number;
99
- relevanceScore: number;
100
- concerningLinks: {
101
- url: string;
102
- concern: string;
103
- }[];
104
- };
105
- }
106
-
107
- // AI Visibility Analysis Types
108
- export interface AIVisibilityAnalysis {
109
- llmReadability: {
110
- score: number;
111
- structureClarity: number;
112
- contextClarity: number;
113
- citationPotential: number;
114
- improvements: string[];
115
- };
116
-
117
- botAccessRecommendation: {
118
- shouldAllowGPTBot: boolean;
119
- shouldAllowClaudeBot: boolean;
120
- shouldAllowPerplexityBot: boolean;
121
- shouldAllowGoogleExtended: boolean;
122
- rationale: string;
123
- };
124
-
125
- llmsTxtSuggestion?: {
126
- content: string;
127
- explanation: string;
128
- };
129
- }
130
-
131
- // Fix Prioritization Types
132
- export interface AIFixPrioritization {
133
- prioritizedIssues: {
134
- issueCode: string;
135
- impactScore: number;
136
- effortScore: number;
137
- roiScore: number;
138
- rationale: string;
139
- }[];
140
-
141
- fixBatches: {
142
- batch: number;
143
- theme: string;
144
- estimatedImpact: string;
145
- issueCodes: string[];
146
- }[];
147
- }
148
-
149
- // Combined AI Analysis Result
150
- export interface AIAnalysisResult {
151
- content?: AIContentAnalysis;
152
- meta?: AIMetaAnalysis;
153
- schema?: AISchemaAnalysis;
154
- links?: AILinkAnalysis;
155
- aiVisibility?: AIVisibilityAnalysis;
156
- fixPrioritization?: AIFixPrioritization;
157
-
158
- // Metadata
159
- analysisTime: number;
160
- tokensUsed: number;
161
- modelUsed: string;
162
- cached: boolean;
163
- }
164
-
165
- // Page Context for AI Analysis
166
- export interface PageContext {
167
- url: string;
168
- title?: string;
169
- metaDescription?: string;
170
- h1?: string;
171
- headings?: { level: number; text: string }[];
172
- textContent: string;
173
- wordCount: number;
174
- links?: { href: string; text: string; isInternal: boolean }[];
175
- images?: { src: string; alt?: string }[];
176
- schema?: object[];
177
- framework?: string;
178
- industry?: string;
179
- }
@@ -1,439 +0,0 @@
1
- // Additional SEO Checks
2
- // AMP detection, ads.txt, DMARC, email privacy, and more
3
-
4
- import { httpGet } from '../../utils/http.js';
5
- import * as cheerio from 'cheerio';
6
- import type { AuditIssue } from '../types.js';
7
- import { ISSUE_DEFINITIONS } from '../types.js';
8
-
9
- /**
10
- * Isomorphic DNS TXT record lookup using DNS-over-HTTPS (Cloudflare)
11
- * Works in both Node.js and Deno/browser environments
12
- */
13
- async function resolveTxtDoH(domain: string): Promise<string[][]> {
14
- const url = `https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=TXT`;
15
-
16
- const response = await fetch(url, {
17
- headers: {
18
- 'Accept': 'application/dns-json'
19
- }
20
- });
21
-
22
- if (!response.ok) {
23
- throw new Error(`DNS lookup failed: ${response.status}`);
24
- }
25
-
26
- const data = await response.json() as { Answer?: Array<{ data: string }> };
27
-
28
- if (!data.Answer || data.Answer.length === 0) {
29
- return [];
30
- }
31
-
32
- // Parse TXT records - they come with quotes that need to be removed
33
- return data.Answer.map(record => {
34
- const txt = record.data.replace(/^"|"$/g, '');
35
- return [txt];
36
- });
37
- }
38
-
39
- export interface AdsTxtData {
40
- exists: boolean;
41
- valid: boolean;
42
- entries: number;
43
- errors: string[];
44
- }
45
-
46
- export interface DMARCData {
47
- exists: boolean;
48
- policy: string | null;
49
- record: string | null;
50
- }
51
-
52
- export interface SPFData {
53
- exists: boolean;
54
- record: string | null;
55
- }
56
-
57
- export interface AMPData {
58
- hasAmpLink: boolean;
59
- ampUrl: string | null;
60
- ampValid: boolean | null;
61
- }
62
-
63
- export interface AdditionalChecksData {
64
- adsTxt: AdsTxtData;
65
- dmarc: DMARCData;
66
- spf: SPFData;
67
- amp: AMPData;
68
- plaintextEmails: string[];
69
- hasAppleTouchIcon: boolean;
70
- faviconFormat: string | null;
71
- }
72
-
73
- /**
74
- * Check for ads.txt file
75
- */
76
- export async function checkAdsTxt(baseUrl: string): Promise<{ issues: AuditIssue[]; data: AdsTxtData }> {
77
- const issues: AuditIssue[] = [];
78
- const url = new URL('/ads.txt', baseUrl).href;
79
-
80
- try {
81
- const response = await httpGet<string>(url, {
82
-
83
- timeout: 10000,
84
- validateStatus: () => true,
85
- });
86
-
87
- if (response.status === 404 || response.status >= 400) {
88
- // Not an error for most sites - only relevant for publishers
89
- return {
90
- issues,
91
- data: { exists: false, valid: false, entries: 0, errors: [] },
92
- };
93
- }
94
-
95
- const content = response.data as string;
96
- const lines = content.split('\n').filter((line) => line.trim() && !line.trim().startsWith('#'));
97
-
98
- // Basic validation
99
- const errors: string[] = [];
100
- let validEntries = 0;
101
-
102
- for (const line of lines) {
103
- // ads.txt format: domain, publisher-account-id, account-type, certification-authority-id
104
- const parts = line.split(',').map((p) => p.trim());
105
- if (parts.length >= 3) {
106
- validEntries++;
107
- } else if (line.trim()) {
108
- errors.push(`Invalid line format: ${line.substring(0, 50)}`);
109
- }
110
- }
111
-
112
- const valid = errors.length === 0 && validEntries > 0;
113
-
114
- if (!valid && validEntries > 0) {
115
- issues.push({
116
- ...ISSUE_DEFINITIONS.ADS_TXT_INVALID,
117
- affectedUrls: [url],
118
- details: { errors, validEntries },
119
- });
120
- }
121
-
122
- return {
123
- issues,
124
- data: { exists: true, valid, entries: validEntries, errors },
125
- };
126
- } catch {
127
- return {
128
- issues,
129
- data: { exists: false, valid: false, entries: 0, errors: ['Failed to fetch'] },
130
- };
131
- }
132
- }
133
-
134
- /**
135
- * Check DMARC DNS record
136
- */
137
- export async function checkDMARC(domain: string): Promise<{ issues: AuditIssue[]; data: DMARCData }> {
138
- const issues: AuditIssue[] = [];
139
-
140
- try {
141
- // Extract domain from URL if needed
142
- let cleanDomain = domain;
143
- try {
144
- cleanDomain = new URL(domain).hostname;
145
- } catch {
146
- // Already a domain
147
- }
148
-
149
- // Remove www prefix
150
- cleanDomain = cleanDomain.replace(/^www\./, '');
151
-
152
- // Query DMARC record using DNS-over-HTTPS
153
- const dmarcDomain = `_dmarc.${cleanDomain}`;
154
- const records = await resolveTxtDoH(dmarcDomain);
155
-
156
- // Find DMARC record
157
- const dmarcRecord = records.flat().find((r) => r.startsWith('v=DMARC1'));
158
-
159
- if (dmarcRecord) {
160
- // Parse policy
161
- const policyMatch = dmarcRecord.match(/p=(\w+)/);
162
- const policy = policyMatch ? policyMatch[1] : null;
163
-
164
- return {
165
- issues,
166
- data: { exists: true, policy, record: dmarcRecord },
167
- };
168
- } else {
169
- issues.push({
170
- ...ISSUE_DEFINITIONS.DMARC_MISSING,
171
- affectedUrls: [domain],
172
- });
173
- return {
174
- issues,
175
- data: { exists: false, policy: null, record: null },
176
- };
177
- }
178
- } catch {
179
- issues.push({
180
- ...ISSUE_DEFINITIONS.DMARC_MISSING,
181
- affectedUrls: [domain],
182
- });
183
- return {
184
- issues,
185
- data: { exists: false, policy: null, record: null },
186
- };
187
- }
188
- }
189
-
190
- /**
191
- * Check SPF DNS record
192
- */
193
- export async function checkSPF(domain: string): Promise<{ issues: AuditIssue[]; data: SPFData }> {
194
- const issues: AuditIssue[] = [];
195
-
196
- try {
197
- let cleanDomain = domain;
198
- try {
199
- cleanDomain = new URL(domain).hostname;
200
- } catch {
201
- // Already a domain
202
- }
203
- cleanDomain = cleanDomain.replace(/^www\./, '');
204
-
205
- const records = await resolveTxtDoH(cleanDomain);
206
- const spfRecord = records.flat().find((r) => r.startsWith('v=spf1'));
207
-
208
- if (spfRecord) {
209
- return {
210
- issues,
211
- data: { exists: true, record: spfRecord },
212
- };
213
- } else {
214
- issues.push({
215
- ...ISSUE_DEFINITIONS.SPF_MISSING,
216
- affectedUrls: [domain],
217
- });
218
- return {
219
- issues,
220
- data: { exists: false, record: null },
221
- };
222
- }
223
- } catch {
224
- // DNS lookup failed - could be many reasons
225
- return {
226
- issues,
227
- data: { exists: false, record: null },
228
- };
229
- }
230
- }
231
-
232
- /**
233
- * Check for AMP version
234
- */
235
- export function checkAMP(html: string, url: string): { issues: AuditIssue[]; data: AMPData } {
236
- const issues: AuditIssue[] = [];
237
- const $ = cheerio.load(html);
238
-
239
- // Check for amphtml link
240
- const ampLink = $('link[rel="amphtml"]').attr('href');
241
-
242
- if (ampLink) {
243
- return {
244
- issues,
245
- data: {
246
- hasAmpLink: true,
247
- ampUrl: ampLink,
248
- ampValid: null, // Would need to validate the AMP page
249
- },
250
- };
251
- }
252
-
253
- // Check if current page is AMP
254
- const isAmpPage = $('html[amp]').length > 0 || $('html[⚡]').length > 0;
255
-
256
- if (isAmpPage) {
257
- return {
258
- issues,
259
- data: {
260
- hasAmpLink: false,
261
- ampUrl: url,
262
- ampValid: null,
263
- },
264
- };
265
- }
266
-
267
- // Only flag AMP missing for content-heavy pages (articles, news)
268
- const isArticle =
269
- $('article').length > 0 ||
270
- $('meta[property="og:type"][content="article"]').length > 0 ||
271
- html.toLowerCase().includes('blog') ||
272
- html.toLowerCase().includes('news');
273
-
274
- if (isArticle) {
275
- issues.push({
276
- ...ISSUE_DEFINITIONS.AMP_MISSING,
277
- affectedUrls: [url],
278
- });
279
- }
280
-
281
- return {
282
- issues,
283
- data: {
284
- hasAmpLink: false,
285
- ampUrl: null,
286
- ampValid: null,
287
- },
288
- };
289
- }
290
-
291
- /**
292
- * Check for plaintext email addresses
293
- */
294
- export function checkPlaintextEmails(html: string, url: string): { issues: AuditIssue[]; emails: string[] } {
295
- const issues: AuditIssue[] = [];
296
- const $ = cheerio.load(html);
297
-
298
- // Remove script and style content
299
- $('script, style').remove();
300
- const text = $('body').text();
301
-
302
- // Email regex
303
- const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
304
- const emails = text.match(emailRegex) || [];
305
-
306
- // Filter out common false positives
307
- const filteredEmails = emails.filter((email) => {
308
- const lowerEmail = email.toLowerCase();
309
- return (
310
- !lowerEmail.includes('example.com') &&
311
- !lowerEmail.includes('yoursite.com') &&
312
- !lowerEmail.includes('yourdomain') &&
313
- !lowerEmail.endsWith('.png') &&
314
- !lowerEmail.endsWith('.jpg')
315
- );
316
- });
317
-
318
- // Deduplicate
319
- const uniqueEmails = [...new Set(filteredEmails)];
320
-
321
- if (uniqueEmails.length > 0) {
322
- issues.push({
323
- ...ISSUE_DEFINITIONS.PLAINTEXT_EMAIL,
324
- affectedUrls: [url],
325
- details: {
326
- emails: uniqueEmails,
327
- count: uniqueEmails.length,
328
- },
329
- });
330
- }
331
-
332
- return { issues, emails: uniqueEmails };
333
- }
334
-
335
- /**
336
- * Check for Apple Touch Icon
337
- */
338
- export function checkAppleTouchIcon(html: string, url: string): { issues: AuditIssue[]; exists: boolean } {
339
- const issues: AuditIssue[] = [];
340
- const $ = cheerio.load(html);
341
-
342
- const hasAppleTouchIcon =
343
- $('link[rel="apple-touch-icon"]').length > 0 || $('link[rel="apple-touch-icon-precomposed"]').length > 0;
344
-
345
- if (!hasAppleTouchIcon) {
346
- issues.push({
347
- ...ISSUE_DEFINITIONS.APPLE_TOUCH_ICON_MISSING,
348
- affectedUrls: [url],
349
- });
350
- }
351
-
352
- return { issues, exists: hasAppleTouchIcon };
353
- }
354
-
355
- /**
356
- * Check favicon format
357
- */
358
- export function checkFaviconFormat(html: string, url: string): { issues: AuditIssue[]; format: string | null } {
359
- const issues: AuditIssue[] = [];
360
- const $ = cheerio.load(html);
361
-
362
- // Check for favicon links
363
- const faviconLink =
364
- $('link[rel="icon"]').attr('href') ||
365
- $('link[rel="shortcut icon"]').attr('href') ||
366
- null;
367
-
368
- if (!faviconLink) {
369
- return { issues, format: null };
370
- }
371
-
372
- // Determine format
373
- let format: string | null = null;
374
- const lowerHref = faviconLink.toLowerCase();
375
-
376
- if (lowerHref.endsWith('.ico')) {
377
- format = 'ico';
378
- } else if (lowerHref.endsWith('.png')) {
379
- format = 'png';
380
- } else if (lowerHref.endsWith('.svg')) {
381
- format = 'svg';
382
- } else if (lowerHref.includes('data:image/')) {
383
- format = 'inline';
384
- } else {
385
- format = 'unknown';
386
- }
387
-
388
- // Note: Not having .ico is just a notice, not a critical issue
389
- // Modern browsers support PNG/SVG favicons well
390
-
391
- return { issues, format };
392
- }
393
-
394
- /**
395
- * Run all additional checks
396
- */
397
- export async function runAdditionalChecks(
398
- url: string,
399
- html: string
400
- ): Promise<{ issues: AuditIssue[]; data: AdditionalChecksData }> {
401
- const allIssues: AuditIssue[] = [];
402
-
403
- // Run parallel checks
404
- const [adsTxtResult, dmarcResult, spfResult] = await Promise.all([
405
- checkAdsTxt(url),
406
- checkDMARC(url),
407
- checkSPF(url),
408
- ]);
409
-
410
- allIssues.push(...adsTxtResult.issues);
411
- allIssues.push(...dmarcResult.issues);
412
- allIssues.push(...spfResult.issues);
413
-
414
- // Run HTML-based checks
415
- const ampResult = checkAMP(html, url);
416
- allIssues.push(...ampResult.issues);
417
-
418
- const emailResult = checkPlaintextEmails(html, url);
419
- allIssues.push(...emailResult.issues);
420
-
421
- const touchIconResult = checkAppleTouchIcon(html, url);
422
- allIssues.push(...touchIconResult.issues);
423
-
424
- const faviconResult = checkFaviconFormat(html, url);
425
- allIssues.push(...faviconResult.issues);
426
-
427
- return {
428
- issues: allIssues,
429
- data: {
430
- adsTxt: adsTxtResult.data,
431
- dmarc: dmarcResult.data,
432
- spf: spfResult.data,
433
- amp: ampResult.data,
434
- plaintextEmails: emailResult.emails,
435
- hasAppleTouchIcon: touchIconResult.exists,
436
- faviconFormat: faviconResult.format,
437
- },
438
- };
439
- }