mcp-web-validator 1.3.51 → 1.3.53

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 (172) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +64 -4
  3. package/dist/audit-history.d.ts +9 -0
  4. package/dist/audit-history.js +27 -0
  5. package/dist/audit-history.js.map +1 -1
  6. package/dist/index.js +2508 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
  9. package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
  10. package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
  11. package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
  12. package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
  13. package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
  14. package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
  15. package/dist/modules/browser-ux/media-diagnostics.js +183 -0
  16. package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
  17. package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
  18. package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
  19. package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
  20. package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
  21. package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
  22. package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
  23. package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
  24. package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
  25. package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
  26. package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
  27. package/dist/modules/browser-ux/resource-failures.js +178 -0
  28. package/dist/modules/browser-ux/resource-failures.js.map +1 -0
  29. package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
  30. package/dist/modules/browser-ux/viewport-parity-probe.js +307 -0
  31. package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
  32. package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
  33. package/dist/modules/browser-ux/viewport-parity.js +224 -0
  34. package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
  35. package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
  36. package/dist/modules/browser-ux/wcag-interactions.js +360 -0
  37. package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
  38. package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
  39. package/dist/modules/change-regression/availability-history-store.js +168 -0
  40. package/dist/modules/change-regression/availability-history-store.js.map +1 -0
  41. package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
  42. package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
  43. package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
  44. package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
  45. package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
  46. package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
  47. package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
  48. package/dist/modules/change-regression/historical-comparisons.js +330 -0
  49. package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
  50. package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
  51. package/dist/modules/change-regression/production-change-comparison.js +214 -0
  52. package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
  53. package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
  54. package/dist/modules/change-regression/regression-alerts.js +183 -0
  55. package/dist/modules/change-regression/regression-alerts.js.map +1 -0
  56. package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
  57. package/dist/modules/change-regression/strict-observation-time.js +31 -0
  58. package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
  59. package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
  60. package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
  61. package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
  62. package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
  63. package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
  64. package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
  65. package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
  66. package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
  67. package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
  68. package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
  69. package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
  70. package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
  71. package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
  72. package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
  73. package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
  74. package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
  75. package/dist/modules/content-schema/extract-main-content.js +33 -0
  76. package/dist/modules/content-schema/extract-main-content.js.map +1 -0
  77. package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
  78. package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
  79. package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
  80. package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
  81. package/dist/modules/content-schema/extract-product-claims.js +58 -0
  82. package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
  83. package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
  84. package/dist/modules/content-schema/extract-structured-data.js +25 -0
  85. package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
  86. package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
  87. package/dist/modules/content-schema/metadata-consistency.js +282 -0
  88. package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
  89. package/dist/modules/content-schema/product-claims.d.ts +73 -0
  90. package/dist/modules/content-schema/product-claims.js +195 -0
  91. package/dist/modules/content-schema/product-claims.js.map +1 -0
  92. package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
  93. package/dist/modules/content-schema/same-language-duplicates.js +158 -0
  94. package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
  95. package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
  96. package/dist/modules/content-schema/structured-data-validation.js +385 -0
  97. package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
  98. package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
  99. package/dist/modules/external-metrics/crux-field-probe.js +113 -0
  100. package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
  101. package/dist/modules/external-metrics/crux-field.d.ts +61 -0
  102. package/dist/modules/external-metrics/crux-field.js +231 -0
  103. package/dist/modules/external-metrics/crux-field.js.map +1 -0
  104. package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
  105. package/dist/modules/http-crawl/availability-observations.js +206 -0
  106. package/dist/modules/http-crawl/availability-observations.js.map +1 -0
  107. package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
  108. package/dist/modules/http-crawl/availability-probe.js +46 -0
  109. package/dist/modules/http-crawl/availability-probe.js.map +1 -0
  110. package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
  111. package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
  112. package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
  113. package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
  114. package/dist/modules/http-crawl/crawler-access.js +404 -0
  115. package/dist/modules/http-crawl/crawler-access.js.map +1 -0
  116. package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
  117. package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
  118. package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
  119. package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
  120. package/dist/modules/http-crawl/http-delivery.js +269 -0
  121. package/dist/modules/http-crawl/http-delivery.js.map +1 -0
  122. package/dist/modules/http-crawl/https-security.d.ts +84 -0
  123. package/dist/modules/http-crawl/https-security.js +441 -0
  124. package/dist/modules/http-crawl/https-security.js.map +1 -0
  125. package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
  126. package/dist/modules/http-crawl/non-html-directives.js +353 -0
  127. package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
  128. package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
  129. package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
  130. package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
  131. package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
  132. package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
  133. package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
  134. package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
  135. package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
  136. package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
  137. package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
  138. package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
  139. package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
  140. package/dist/modules/http-crawl/url-variants.d.ts +86 -0
  141. package/dist/modules/http-crawl/url-variants.js +379 -0
  142. package/dist/modules/http-crawl/url-variants.js.map +1 -0
  143. package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
  144. package/dist/modules/site-architecture/extract-internal-links.js +88 -0
  145. package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
  146. package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
  147. package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
  148. package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
  149. package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
  150. package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
  151. package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
  152. package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
  153. package/dist/modules/site-architecture/internal-link-graph.js +414 -0
  154. package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
  155. package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
  156. package/dist/modules/site-architecture/internal-link-quality.js +260 -0
  157. package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
  158. package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
  159. package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
  160. package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
  161. package/dist/network.d.ts +4 -0
  162. package/dist/network.js +18 -2
  163. package/dist/network.js.map +1 -1
  164. package/dist/presentation.d.ts +53 -0
  165. package/dist/presentation.js +526 -0
  166. package/dist/presentation.js.map +1 -1
  167. package/dist/screenshot.d.ts +2 -1
  168. package/dist/screenshot.js +4 -2
  169. package/dist/screenshot.js.map +1 -1
  170. package/dist/seo-auditor.js +16 -6
  171. package/dist/seo-auditor.js.map +1 -1
  172. package/package.json +7 -4
@@ -0,0 +1,353 @@
1
+ /**
2
+ * P1-11: bounded, offline review of caller-observed HTTP response metadata.
3
+ * Pure module: shared by local stdio and hosted Worker, no fetch or Node APIs.
4
+ */
5
+ export const MAX_HTTP_RESOURCES = 8;
6
+ export const MAX_HTTP_FINDINGS = 12;
7
+ export const MAX_HTTP_HEADER_VALUES = 8;
8
+ export const MAX_HTTP_HEADER_BYTES = 2_048;
9
+ export const MAX_HTTP_TOTAL_BYTES = 30_000;
10
+ const MAX_LINK_ITEMS_PER_RESOURCE = 32;
11
+ const encoder = new TextEncoder();
12
+ export const HTTP_MIME_CATEGORIES = [
13
+ "html", "pdf", "image", "video", "audio", "text", "data", "binary", "unknown",
14
+ ];
15
+ export const HTTP_CANONICAL_STATES = [
16
+ "absent", "one", "repeated", "conflicting", "unresolved",
17
+ ];
18
+ export const HTTP_FINDING_CODES = [
19
+ "explicit_noindex", "googlebot_noindex", "conflicting_robots",
20
+ "explicit_noimageindex",
21
+ "unresolved_canonical", "conflicting_canonical",
22
+ "attachment_disposition", "non_success_response",
23
+ "partial_http_response", "unknown_content_type", "html_in_non_html_review",
24
+ "link_header_limited", "pdf_type_mismatch",
25
+ ];
26
+ export function emptyHttpDirectiveReview() {
27
+ return {
28
+ scope: "caller_supplied_http_headers_only", resources_sampled: 0,
29
+ non_html_resources: 0, html_resources: 0, unknown_mime_resources: 0,
30
+ non_success_resources: 0, explicit_noindex_resources: 0,
31
+ googlebot_noindex_resources: 0, conflicting_robots_resources: 0,
32
+ googlebot_noimageindex_resources: 0,
33
+ canonical_header_resources: 0, conflicting_canonical_resources: 0,
34
+ unresolved_canonical_references: 0, attachment_resources: 0,
35
+ coverage_limited: true,
36
+ limitations: ["The supplied HTTP response observations could not be reviewed within declared limits."],
37
+ resources: [], total_findings: 0, findings: [], findings_truncated: false,
38
+ };
39
+ }
40
+ /** Safe *offline label*, not permission to issue a network request. */
41
+ export function safeHttpResourceUrl(value) {
42
+ if (typeof value !== "string" || value.length > 512 || /[\u0000-\u001f\u007f]/u.test(value))
43
+ return null;
44
+ try {
45
+ const url = new URL(value);
46
+ if (!["https:", "http:"].includes(url.protocol) || !url.hostname ||
47
+ url.username || url.password || url.search || url.hash ||
48
+ value.includes("?") || value.includes("#") ||
49
+ url.port)
50
+ return null;
51
+ return url.href;
52
+ }
53
+ catch {
54
+ return null;
55
+ }
56
+ }
57
+ function checkHeader(value) {
58
+ if (value === undefined)
59
+ return 0;
60
+ if (typeof value !== "string" || /[\r\n\u0000]/u.test(value))
61
+ throw new Error("Invalid observed response header");
62
+ const bytes = encoder.encode(value).byteLength;
63
+ if (bytes > MAX_HTTP_HEADER_BYTES)
64
+ throw new Error("HTTP header observation exceeds the byte cap");
65
+ return bytes;
66
+ }
67
+ function headerList(value) {
68
+ if (value === undefined)
69
+ return [];
70
+ if (!Array.isArray(value) || value.length > MAX_HTTP_HEADER_VALUES) {
71
+ throw new Error("Too many observed response headers");
72
+ }
73
+ return value;
74
+ }
75
+ function mimeCategory(header) {
76
+ const mime = (header ?? "").split(";", 1)[0].trim().toLowerCase();
77
+ if (!mime)
78
+ return "unknown";
79
+ if (mime === "text/html" || mime === "application/xhtml+xml")
80
+ return "html";
81
+ if (mime === "application/pdf")
82
+ return "pdf";
83
+ if (/^image\/[a-z0-9.+-]+$/u.test(mime))
84
+ return "image";
85
+ if (/^video\/[a-z0-9.+-]+$/u.test(mime))
86
+ return "video";
87
+ if (/^audio\/[a-z0-9.+-]+$/u.test(mime))
88
+ return "audio";
89
+ if (/^(application\/(?:json|xml|ld\+json|[^/]+\+(?:json|xml))|text\/(?:xml|csv))$/u.test(mime))
90
+ return "data";
91
+ if (/^text\/[a-z0-9.+-]+$/u.test(mime))
92
+ return "text";
93
+ if (/^(?:application|font|model)\/[a-z0-9.+-]+$/u.test(mime))
94
+ return "binary";
95
+ return "unknown";
96
+ }
97
+ const emptyRules = () => ({
98
+ index: false, noindex: false, noimageindex: false, follow: false, nofollow: false,
99
+ });
100
+ const directiveKeys = new Set([
101
+ "index", "noindex", "follow", "nofollow", "all", "none", "noarchive",
102
+ "nosnippet", "noimageindex", "notranslate", "max-snippet", "max-image-preview",
103
+ "max-video-preview", "unavailable_after", "indexifembedded",
104
+ ]);
105
+ function parseRobotHeaders(values) {
106
+ const groups = {
107
+ generic: emptyRules(), googlebot: emptyRules(),
108
+ "googlebot-news": emptyRules(), other: emptyRules(),
109
+ };
110
+ let observed = false;
111
+ for (const header of values) {
112
+ if (!header.trim())
113
+ continue;
114
+ observed = true;
115
+ let scope = "generic";
116
+ for (const rawSegment of header.split(",")) {
117
+ let token = rawSegment.trim().toLowerCase();
118
+ const prefix = /^([a-z][a-z0-9_-]{0,39}):\s*(.*)$/u.exec(token);
119
+ if (prefix && !directiveKeys.has(prefix[1])) {
120
+ scope = prefix[1] === "googlebot" ? "googlebot"
121
+ : prefix[1] === "googlebot-news" ? "googlebot-news" : "other";
122
+ token = prefix[2].trim();
123
+ }
124
+ const rule = token.split(/\s/u, 1)[0];
125
+ const group = groups[scope];
126
+ if (rule === "noindex" || rule === "none")
127
+ group.noindex = true;
128
+ if (rule === "noimageindex")
129
+ group.noimageindex = true;
130
+ if (rule === "index" || rule === "all")
131
+ group.index = true;
132
+ if (rule === "nofollow" || rule === "none")
133
+ group.nofollow = true;
134
+ if (rule === "follow" || rule === "all")
135
+ group.follow = true;
136
+ }
137
+ }
138
+ const generic = groups.generic, bot = groups.googlebot;
139
+ const internalConflict = Object.values(groups).some((rules) => (rules.index && rules.noindex) || (rules.follow && rules.nofollow));
140
+ const crossScopeConflict = (generic.index && bot.noindex) || (generic.noindex && bot.index)
141
+ || (generic.follow && bot.nofollow) || (generic.nofollow && bot.follow);
142
+ return {
143
+ observed,
144
+ noindex: generic.noindex,
145
+ googlebotNoindex: generic.noindex || bot.noindex,
146
+ googlebotNoimageindex: generic.noimageindex || bot.noimageindex,
147
+ conflict: internalConflict || crossScopeConflict,
148
+ };
149
+ }
150
+ /** Delimit a Link HTTP field outside URI angle brackets and quoted strings. */
151
+ function splitHeader(value, delimiter, protectAngles = false) {
152
+ const result = [];
153
+ let inQuotes = false, escaped = false, inAngle = false, start = 0;
154
+ for (let i = 0; i < value.length; i++) {
155
+ const ch = value[i];
156
+ if (escaped) {
157
+ escaped = false;
158
+ continue;
159
+ }
160
+ if (ch === "\\" && inQuotes) {
161
+ escaped = true;
162
+ continue;
163
+ }
164
+ if (ch === '"') {
165
+ inQuotes = !inQuotes;
166
+ continue;
167
+ }
168
+ if (!inQuotes && protectAngles && ch === "<") {
169
+ inAngle = true;
170
+ continue;
171
+ }
172
+ if (!inQuotes && protectAngles && ch === ">") {
173
+ inAngle = false;
174
+ continue;
175
+ }
176
+ if (ch === delimiter && !inQuotes && !inAngle) {
177
+ result.push(value.slice(start, i).trim());
178
+ start = i + 1;
179
+ }
180
+ }
181
+ result.push(value.slice(start).trim());
182
+ return result;
183
+ }
184
+ function parseCanonicalHeaders(values) {
185
+ let total = 0, valid = 0, unresolved = 0, limited = false, checkedItems = 0;
186
+ const distinct = new Set();
187
+ for (const header of values) {
188
+ for (const item of splitHeader(header, ",", true)) {
189
+ if (++checkedItems > MAX_LINK_ITEMS_PER_RESOURCE) {
190
+ limited = true;
191
+ break;
192
+ }
193
+ const match = /^<([^>]*)>\s*(.*)$/u.exec(item);
194
+ // Parse Link parameters, without treating commas inside quotes as separators.
195
+ const params = splitHeader(match?.[2] ?? item, ";").slice(match ? 1 : 0);
196
+ let relation;
197
+ for (const param of params) {
198
+ const parsed = /^rel\s*=\s*(?:"((?:\\.|[^"])*)"|([^\s;]+))/iu.exec(param);
199
+ if (parsed && relation === undefined)
200
+ relation = (parsed[1] ?? parsed[2]).replace(/\\(.)/gu, "$1");
201
+ }
202
+ if (!relation?.toLowerCase().split(/\s+/u).includes("canonical"))
203
+ continue;
204
+ total++;
205
+ if (!match) {
206
+ unresolved++;
207
+ continue;
208
+ }
209
+ try {
210
+ const target = new URL(match[1]);
211
+ if (!["http:", "https:"].includes(target.protocol) || !target.hostname ||
212
+ target.username || target.password || target.hash ||
213
+ target.port) {
214
+ unresolved++;
215
+ continue;
216
+ }
217
+ valid++;
218
+ distinct.add(target.href);
219
+ }
220
+ catch {
221
+ unresolved++;
222
+ }
223
+ }
224
+ if (limited)
225
+ break;
226
+ }
227
+ return { total, valid, unresolved, distinct: distinct.size, limited };
228
+ }
229
+ export function analyzeHttpDirectives(items) {
230
+ if (!Array.isArray(items) || items.length < 1 || items.length > MAX_HTTP_RESOURCES) {
231
+ throw new Error("Provide between one and eight HTTP observations");
232
+ }
233
+ let bytes = 0, origin;
234
+ const urls = new Set();
235
+ for (const item of items) {
236
+ const safe = safeHttpResourceUrl(item.url);
237
+ if (!safe)
238
+ throw new Error("Use safe, query-free HTTP(S) resource labels");
239
+ const url = new URL(safe);
240
+ if (origin !== undefined && url.origin !== origin) {
241
+ throw new Error("HTTP observations must belong to a single origin");
242
+ }
243
+ origin = url.origin;
244
+ if (urls.has(safe))
245
+ throw new Error("Duplicate HTTP resource label");
246
+ urls.add(safe);
247
+ if (!Number.isInteger(item.status_code) || item.status_code < 100 || item.status_code > 599) {
248
+ throw new Error("Invalid observed HTTP status");
249
+ }
250
+ if (item.method !== undefined && !["HEAD", "GET"].includes(item.method)) {
251
+ throw new Error("Invalid observed HTTP method");
252
+ }
253
+ bytes += checkHeader(item.content_type) + checkHeader(item.content_disposition);
254
+ for (const header of [...headerList(item.x_robots_tag), ...headerList(item.link)]) {
255
+ bytes += checkHeader(header);
256
+ }
257
+ if (bytes > MAX_HTTP_TOTAL_BYTES)
258
+ throw new Error("HTTP header sample exceeds the combined byte cap");
259
+ }
260
+ const out = emptyHttpDirectiveReview();
261
+ out.resources_sampled = items.length;
262
+ out.limitations = [
263
+ "Only caller-supplied HTTP response metadata was examined; there was no HEAD/GET request, binary download, crawling, robots.txt inspection, or live Google indexing verification.",
264
+ "HEAD response headers may differ from GET. A missing X-Robots-Tag does not prove indexability; a declared directive does not prove crawlers saw or honored it.",
265
+ "HTTP Link rel=canonical is a declaration, not Google-selected canonical. Non-success, partial, HTML or unknown MIME responses may not represent final non-HTML documents.",
266
+ ];
267
+ const allFindings = [];
268
+ function add(code, severity, index, message) {
269
+ allFindings.push({ code, severity, resource: index, message });
270
+ }
271
+ items.forEach((item, n) => {
272
+ const index = n + 1;
273
+ const mime = mimeCategory(item.content_type);
274
+ const isNonHtml = mime !== "html" && mime !== "unknown";
275
+ const robots = parseRobotHeaders(item.x_robots_tag ?? []);
276
+ const canonicals = parseCanonicalHeaders(item.link ?? []);
277
+ const attachment = /^\s*attachment\s*(?:;|$)/iu.test(item.content_disposition ?? "");
278
+ const nonSuccess = item.status_code < 200 || item.status_code >= 300;
279
+ const canonicalState = canonicals.distinct > 1 ? "conflicting"
280
+ : canonicals.unresolved > 0 || canonicals.limited ? "unresolved"
281
+ : canonicals.total === 0 ? "absent"
282
+ : canonicals.total === 1 ? "one" : "repeated";
283
+ const evidence = {
284
+ resource: index, status_code: item.status_code, method: item.method ?? "unspecified",
285
+ mime_category: mime, non_html: isNonHtml,
286
+ x_robots_observed: robots.observed,
287
+ explicit_noindex: robots.noindex, googlebot_noindex: robots.googlebotNoindex,
288
+ googlebot_noimageindex: robots.googlebotNoimageindex,
289
+ conflicting_robots: robots.conflict,
290
+ canonical_declarations: canonicals.total, canonical_valid_targets: canonicals.valid,
291
+ canonical_state: canonicalState,
292
+ attachment_declared: attachment, header_coverage_limited: canonicals.limited,
293
+ };
294
+ out.resources.push(evidence);
295
+ if (isNonHtml)
296
+ out.non_html_resources++;
297
+ if (mime === "html")
298
+ out.html_resources++;
299
+ if (mime === "unknown")
300
+ out.unknown_mime_resources++;
301
+ if (nonSuccess)
302
+ out.non_success_resources++;
303
+ if (robots.noindex)
304
+ out.explicit_noindex_resources++;
305
+ if (robots.googlebotNoindex)
306
+ out.googlebot_noindex_resources++;
307
+ if (robots.googlebotNoimageindex)
308
+ out.googlebot_noimageindex_resources++;
309
+ if (robots.conflict)
310
+ out.conflicting_robots_resources++;
311
+ if (canonicals.total > 0)
312
+ out.canonical_header_resources++;
313
+ if (canonicalState === "conflicting")
314
+ out.conflicting_canonical_resources++;
315
+ out.unresolved_canonical_references += canonicals.unresolved;
316
+ if (attachment)
317
+ out.attachment_resources++;
318
+ if (robots.conflict)
319
+ add("conflicting_robots", "warning", index, "Conflicting indexing or following directives were declared for an overlapping crawler scope; review the effective restrictive policy.");
320
+ if (canonicalState === "conflicting")
321
+ add("conflicting_canonical", "warning", index, "Distinct HTTP canonical targets were declared; review which one is intended.");
322
+ if (canonicals.unresolved)
323
+ add("unresolved_canonical", "warning", index, "An HTTP Link canonical target is invalid, non-absolute, credential-bearing, or unsupported.");
324
+ if (canonicals.limited)
325
+ add("link_header_limited", "info", index, "The Link header item cap was reached; additional declarations were not analyzed.");
326
+ if (robots.noindex)
327
+ add("explicit_noindex", "info", index, "An unscoped HTTP noindex directive was supplied; this alone does not establish Google indexing state.");
328
+ else if (robots.googlebotNoindex)
329
+ add("googlebot_noindex", "info", index, "A Googlebot-specific HTTP noindex directive was supplied; live crawler application remains unverified.");
330
+ if (robots.googlebotNoimageindex)
331
+ add("explicit_noimageindex", "info", index, "A Googlebot-applicable noimageindex declaration was supplied; actual image indexing behavior remains unverified.");
332
+ if (attachment)
333
+ add("attachment_disposition", "info", index, "The response declares Content-Disposition attachment; this is not by itself an indexing rule.");
334
+ if (nonSuccess)
335
+ add("non_success_response", "info", index, "This observation has a non-2xx status; it may not describe a final accessible document.");
336
+ if (item.status_code === 206)
337
+ add("partial_http_response", "info", index, "HTTP 206 represents a partial response; full-resource behavior is not established.");
338
+ if (mime === "unknown")
339
+ add("unknown_content_type", "info", index, "No recognized MIME category was supplied; document type and indexability are unverified.");
340
+ if (mime === "html")
341
+ add("html_in_non_html_review", "info", index, "An HTML content type was supplied; inspect HTML-specific indexing signals separately.");
342
+ if (new URL(item.url).pathname.toLowerCase().endsWith(".pdf") && mime === "html") {
343
+ add("pdf_type_mismatch", "info", index, "A .pdf path was observed with an HTML content type; verify the intended response format.");
344
+ }
345
+ });
346
+ allFindings.sort((a, b) => (a.severity === b.severity ? 0 : a.severity === "warning" ? -1 : 1)
347
+ || a.resource - b.resource || a.code.localeCompare(b.code));
348
+ out.total_findings = allFindings.length;
349
+ out.findings = allFindings.slice(0, MAX_HTTP_FINDINGS);
350
+ out.findings_truncated = allFindings.length > MAX_HTTP_FINDINGS;
351
+ return out;
352
+ }
353
+ //# sourceMappingURL=non-html-directives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"non-html-directives.js","sourceRoot":"","sources":["../../../src/modules/http-crawl/non-html-directives.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACxC,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAC3C,MAAM,CAAC,MA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,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;WAChE,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9D,GAAG,CAAC,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC;IACxC,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;IACvD,GAAG,CAAC,kBAAkB,GAAG,WAAW,CAAC,MAAM,GAAG,iBAAiB,CAAC;IAChE,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * P1-11: bounded, offline review of caller-observed HTTP response metadata.\n * Pure module: shared by local stdio and hosted Worker, no fetch or Node APIs.\n */\nexport const MAX_HTTP_RESOURCES = 8;\nexport const MAX_HTTP_FINDINGS = 12;\nexport const MAX_HTTP_HEADER_VALUES = 8;\nexport const MAX_HTTP_HEADER_BYTES = 2_048;\nexport const MAX_HTTP_TOTAL_BYTES = 30_000;\nconst MAX_LINK_ITEMS_PER_RESOURCE = 32;\nconst encoder = new TextEncoder();\n\nexport const HTTP_MIME_CATEGORIES = [\n \"html\", \"pdf\", \"image\", \"video\", \"audio\", \"text\", \"data\", \"binary\", \"unknown\",\n] as const;\nexport type HttpMimeCategory = typeof HTTP_MIME_CATEGORIES[number];\nexport const HTTP_CANONICAL_STATES = [\n \"absent\", \"one\", \"repeated\", \"conflicting\", \"unresolved\",\n] as const;\nexport type HttpCanonicalState = typeof HTTP_CANONICAL_STATES[number];\nexport const HTTP_FINDING_CODES = [\n \"explicit_noindex\", \"googlebot_noindex\", \"conflicting_robots\",\n \"explicit_noimageindex\",\n \"unresolved_canonical\", \"conflicting_canonical\",\n \"attachment_disposition\", \"non_success_response\",\n \"partial_http_response\", \"unknown_content_type\", \"html_in_non_html_review\",\n \"link_header_limited\", \"pdf_type_mismatch\",\n] as const;\nexport type HttpFindingCode = typeof HTTP_FINDING_CODES[number];\n\nexport interface HttpResourceObservation {\n url: string;\n status_code: number;\n method?: \"HEAD\" | \"GET\";\n content_type?: string;\n content_disposition?: string;\n x_robots_tag?: string[];\n link?: string[];\n}\n\nexport interface HttpDirectiveFinding {\n code: HttpFindingCode;\n severity: \"warning\" | \"info\";\n resource: number;\n message: string;\n}\n\nexport interface HttpResourceEvidence {\n resource: number;\n status_code: number;\n method: \"HEAD\" | \"GET\" | \"unspecified\";\n mime_category: HttpMimeCategory;\n non_html: boolean;\n x_robots_observed: boolean;\n explicit_noindex: boolean;\n googlebot_noindex: boolean;\n googlebot_noimageindex: boolean;\n conflicting_robots: boolean;\n canonical_declarations: number;\n canonical_valid_targets: number;\n canonical_state: HttpCanonicalState;\n attachment_declared: boolean;\n header_coverage_limited: boolean;\n}\n\nexport interface HttpDirectiveReview {\n scope: \"caller_supplied_http_headers_only\";\n resources_sampled: number;\n non_html_resources: number;\n html_resources: number;\n unknown_mime_resources: number;\n non_success_resources: number;\n explicit_noindex_resources: number;\n googlebot_noindex_resources: number;\n googlebot_noimageindex_resources: number;\n conflicting_robots_resources: number;\n canonical_header_resources: number;\n conflicting_canonical_resources: number;\n unresolved_canonical_references: number;\n attachment_resources: number;\n coverage_limited: true;\n limitations: string[];\n resources: HttpResourceEvidence[];\n total_findings: number;\n findings: HttpDirectiveFinding[];\n findings_truncated: boolean;\n error?: string;\n}\n\nexport function emptyHttpDirectiveReview(): HttpDirectiveReview {\n return {\n scope: \"caller_supplied_http_headers_only\", resources_sampled: 0,\n non_html_resources: 0, html_resources: 0, unknown_mime_resources: 0,\n non_success_resources: 0, explicit_noindex_resources: 0,\n googlebot_noindex_resources: 0, conflicting_robots_resources: 0,\n googlebot_noimageindex_resources: 0,\n canonical_header_resources: 0, conflicting_canonical_resources: 0,\n unresolved_canonical_references: 0, attachment_resources: 0,\n coverage_limited: true,\n limitations: [\"The supplied HTTP response observations could not be reviewed within declared limits.\"],\n resources: [], total_findings: 0, findings: [], findings_truncated: false,\n };\n}\n\n/** Safe *offline label*, not permission to issue a network request. */\nexport function safeHttpResourceUrl(value: string): string | null {\n if (typeof value !== \"string\" || value.length > 512 || /[\\u0000-\\u001f\\u007f]/u.test(value)) return null;\n try {\n const url = new URL(value);\n if (![\"https:\", \"http:\"].includes(url.protocol) || !url.hostname ||\n url.username || url.password || url.search || url.hash ||\n value.includes(\"?\") || value.includes(\"#\") ||\n url.port) return null;\n return url.href;\n } catch {\n return null;\n }\n}\n\nfunction checkHeader(value: string | undefined): number {\n if (value === undefined) return 0;\n if (typeof value !== \"string\" || /[\\r\\n\\u0000]/u.test(value)) throw new Error(\"Invalid observed response header\");\n const bytes = encoder.encode(value).byteLength;\n if (bytes > MAX_HTTP_HEADER_BYTES) throw new Error(\"HTTP header observation exceeds the byte cap\");\n return bytes;\n}\n\nfunction headerList(value: string[] | undefined): string[] {\n if (value === undefined) return [];\n if (!Array.isArray(value) || value.length > MAX_HTTP_HEADER_VALUES) {\n throw new Error(\"Too many observed response headers\");\n }\n return value;\n}\n\nfunction mimeCategory(header: string | undefined): HttpMimeCategory {\n const mime = (header ?? \"\").split(\";\", 1)[0].trim().toLowerCase();\n if (!mime) return \"unknown\";\n if (mime === \"text/html\" || mime === \"application/xhtml+xml\") return \"html\";\n if (mime === \"application/pdf\") return \"pdf\";\n if (/^image\\/[a-z0-9.+-]+$/u.test(mime)) return \"image\";\n if (/^video\\/[a-z0-9.+-]+$/u.test(mime)) return \"video\";\n if (/^audio\\/[a-z0-9.+-]+$/u.test(mime)) return \"audio\";\n if (/^(application\\/(?:json|xml|ld\\+json|[^/]+\\+(?:json|xml))|text\\/(?:xml|csv))$/u.test(mime)) return \"data\";\n if (/^text\\/[a-z0-9.+-]+$/u.test(mime)) return \"text\";\n if (/^(?:application|font|model)\\/[a-z0-9.+-]+$/u.test(mime)) return \"binary\";\n return \"unknown\";\n}\n\ntype Scope = \"generic\" | \"googlebot\" | \"googlebot-news\" | \"other\";\ntype RobotSet = {\n index: boolean; noindex: boolean; noimageindex: boolean;\n follow: boolean; nofollow: boolean;\n};\nconst emptyRules = (): RobotSet => ({\n index: false, noindex: false, noimageindex: false, follow: false, nofollow: false,\n});\nconst directiveKeys = new Set([\n \"index\", \"noindex\", \"follow\", \"nofollow\", \"all\", \"none\", \"noarchive\",\n \"nosnippet\", \"noimageindex\", \"notranslate\", \"max-snippet\", \"max-image-preview\",\n \"max-video-preview\", \"unavailable_after\", \"indexifembedded\",\n]);\n\nfunction parseRobotHeaders(values: string[]): {\n observed: boolean;\n noindex: boolean;\n googlebotNoindex: boolean;\n googlebotNoimageindex: boolean;\n conflict: boolean;\n} {\n const groups: Record<Scope, RobotSet> = {\n generic: emptyRules(), googlebot: emptyRules(),\n \"googlebot-news\": emptyRules(), other: emptyRules(),\n };\n let observed = false;\n for (const header of values) {\n if (!header.trim()) continue;\n observed = true;\n let scope: Scope = \"generic\";\n for (const rawSegment of header.split(\",\")) {\n let token = rawSegment.trim().toLowerCase();\n const prefix = /^([a-z][a-z0-9_-]{0,39}):\\s*(.*)$/u.exec(token);\n if (prefix && !directiveKeys.has(prefix[1])) {\n scope = prefix[1] === \"googlebot\" ? \"googlebot\"\n : prefix[1] === \"googlebot-news\" ? \"googlebot-news\" : \"other\";\n token = prefix[2].trim();\n }\n const rule = token.split(/\\s/u, 1)[0];\n const group = groups[scope];\n if (rule === \"noindex\" || rule === \"none\") group.noindex = true;\n if (rule === \"noimageindex\") group.noimageindex = true;\n if (rule === \"index\" || rule === \"all\") group.index = true;\n if (rule === \"nofollow\" || rule === \"none\") group.nofollow = true;\n if (rule === \"follow\" || rule === \"all\") group.follow = true;\n }\n }\n const generic = groups.generic, bot = groups.googlebot;\n const internalConflict = Object.values(groups).some((rules) =>\n (rules.index && rules.noindex) || (rules.follow && rules.nofollow));\n const crossScopeConflict = (generic.index && bot.noindex) || (generic.noindex && bot.index)\n || (generic.follow && bot.nofollow) || (generic.nofollow && bot.follow);\n return {\n observed,\n noindex: generic.noindex,\n googlebotNoindex: generic.noindex || bot.noindex,\n googlebotNoimageindex: generic.noimageindex || bot.noimageindex,\n conflict: internalConflict || crossScopeConflict,\n };\n}\n\n/** Delimit a Link HTTP field outside URI angle brackets and quoted strings. */\nfunction splitHeader(value: string, delimiter: \",\" | \";\", protectAngles = false): string[] {\n const result: string[] = [];\n let inQuotes = false, escaped = false, inAngle = false, start = 0;\n for (let i = 0; i < value.length; i++) {\n const ch = value[i];\n if (escaped) { escaped = false; continue; }\n if (ch === \"\\\\\" && inQuotes) { escaped = true; continue; }\n if (ch === '\"') { inQuotes = !inQuotes; continue; }\n if (!inQuotes && protectAngles && ch === \"<\") { inAngle = true; continue; }\n if (!inQuotes && protectAngles && ch === \">\") { inAngle = false; continue; }\n if (ch === delimiter && !inQuotes && !inAngle) {\n result.push(value.slice(start, i).trim());\n start = i + 1;\n }\n }\n result.push(value.slice(start).trim());\n return result;\n}\n\nfunction parseCanonicalHeaders(values: string[]): {\n total: number;\n valid: number;\n unresolved: number;\n distinct: number;\n limited: boolean;\n} {\n let total = 0, valid = 0, unresolved = 0, limited = false, checkedItems = 0;\n const distinct = new Set<string>();\n for (const header of values) {\n for (const item of splitHeader(header, \",\", true)) {\n if (++checkedItems > MAX_LINK_ITEMS_PER_RESOURCE) { limited = true; break; }\n const match = /^<([^>]*)>\\s*(.*)$/u.exec(item);\n // Parse Link parameters, without treating commas inside quotes as separators.\n const params = splitHeader(match?.[2] ?? item, \";\").slice(match ? 1 : 0);\n let relation: string | undefined;\n for (const param of params) {\n const parsed = /^rel\\s*=\\s*(?:\"((?:\\\\.|[^\"])*)\"|([^\\s;]+))/iu.exec(param);\n if (parsed && relation === undefined) relation = (parsed[1] ?? parsed[2]).replace(/\\\\(.)/gu, \"$1\");\n }\n if (!relation?.toLowerCase().split(/\\s+/u).includes(\"canonical\")) continue;\n total++;\n if (!match) { unresolved++; continue; }\n try {\n const target = new URL(match[1]);\n if (![\"http:\", \"https:\"].includes(target.protocol) || !target.hostname ||\n target.username || target.password || target.hash ||\n target.port) {\n unresolved++;\n continue;\n }\n valid++;\n distinct.add(target.href);\n } catch {\n unresolved++;\n }\n }\n if (limited) break;\n }\n return { total, valid, unresolved, distinct: distinct.size, limited };\n}\n\nexport function analyzeHttpDirectives(items: HttpResourceObservation[]): HttpDirectiveReview {\n if (!Array.isArray(items) || items.length < 1 || items.length > MAX_HTTP_RESOURCES) {\n throw new Error(\"Provide between one and eight HTTP observations\");\n }\n let bytes = 0, origin: string | undefined;\n const urls = new Set<string>();\n for (const item of items) {\n const safe = safeHttpResourceUrl(item.url);\n if (!safe) throw new Error(\"Use safe, query-free HTTP(S) resource labels\");\n const url = new URL(safe);\n if (origin !== undefined && url.origin !== origin) {\n throw new Error(\"HTTP observations must belong to a single origin\");\n }\n origin = url.origin;\n if (urls.has(safe)) throw new Error(\"Duplicate HTTP resource label\");\n urls.add(safe);\n if (!Number.isInteger(item.status_code) || item.status_code < 100 || item.status_code > 599) {\n throw new Error(\"Invalid observed HTTP status\");\n }\n if (item.method !== undefined && ![\"HEAD\", \"GET\"].includes(item.method)) {\n throw new Error(\"Invalid observed HTTP method\");\n }\n bytes += checkHeader(item.content_type) + checkHeader(item.content_disposition);\n for (const header of [...headerList(item.x_robots_tag), ...headerList(item.link)]) {\n bytes += checkHeader(header);\n }\n if (bytes > MAX_HTTP_TOTAL_BYTES) throw new Error(\"HTTP header sample exceeds the combined byte cap\");\n }\n\n const out = emptyHttpDirectiveReview();\n out.resources_sampled = items.length;\n out.limitations = [\n \"Only caller-supplied HTTP response metadata was examined; there was no HEAD/GET request, binary download, crawling, robots.txt inspection, or live Google indexing verification.\",\n \"HEAD response headers may differ from GET. A missing X-Robots-Tag does not prove indexability; a declared directive does not prove crawlers saw or honored it.\",\n \"HTTP Link rel=canonical is a declaration, not Google-selected canonical. Non-success, partial, HTML or unknown MIME responses may not represent final non-HTML documents.\",\n ];\n const allFindings: HttpDirectiveFinding[] = [];\n function add(code: HttpFindingCode, severity: \"warning\" | \"info\", index: number, message: string) {\n allFindings.push({ code, severity, resource: index, message });\n }\n\n items.forEach((item, n) => {\n const index = n + 1;\n const mime = mimeCategory(item.content_type);\n const isNonHtml = mime !== \"html\" && mime !== \"unknown\";\n const robots = parseRobotHeaders(item.x_robots_tag ?? []);\n const canonicals = parseCanonicalHeaders(item.link ?? []);\n const attachment = /^\\s*attachment\\s*(?:;|$)/iu.test(item.content_disposition ?? \"\");\n const nonSuccess = item.status_code < 200 || item.status_code >= 300;\n const canonicalState: HttpCanonicalState = canonicals.distinct > 1 ? \"conflicting\"\n : canonicals.unresolved > 0 || canonicals.limited ? \"unresolved\"\n : canonicals.total === 0 ? \"absent\"\n : canonicals.total === 1 ? \"one\" : \"repeated\";\n const evidence: HttpResourceEvidence = {\n resource: index, status_code: item.status_code, method: item.method ?? \"unspecified\",\n mime_category: mime, non_html: isNonHtml,\n x_robots_observed: robots.observed,\n explicit_noindex: robots.noindex, googlebot_noindex: robots.googlebotNoindex,\n googlebot_noimageindex: robots.googlebotNoimageindex,\n conflicting_robots: robots.conflict,\n canonical_declarations: canonicals.total, canonical_valid_targets: canonicals.valid,\n canonical_state: canonicalState,\n attachment_declared: attachment, header_coverage_limited: canonicals.limited,\n };\n out.resources.push(evidence);\n if (isNonHtml) out.non_html_resources++;\n if (mime === \"html\") out.html_resources++;\n if (mime === \"unknown\") out.unknown_mime_resources++;\n if (nonSuccess) out.non_success_resources++;\n if (robots.noindex) out.explicit_noindex_resources++;\n if (robots.googlebotNoindex) out.googlebot_noindex_resources++;\n if (robots.googlebotNoimageindex) out.googlebot_noimageindex_resources++;\n if (robots.conflict) out.conflicting_robots_resources++;\n if (canonicals.total > 0) out.canonical_header_resources++;\n if (canonicalState === \"conflicting\") out.conflicting_canonical_resources++;\n out.unresolved_canonical_references += canonicals.unresolved;\n if (attachment) out.attachment_resources++;\n\n if (robots.conflict) add(\"conflicting_robots\", \"warning\", index,\n \"Conflicting indexing or following directives were declared for an overlapping crawler scope; review the effective restrictive policy.\");\n if (canonicalState === \"conflicting\") add(\"conflicting_canonical\", \"warning\", index,\n \"Distinct HTTP canonical targets were declared; review which one is intended.\");\n if (canonicals.unresolved) add(\"unresolved_canonical\", \"warning\", index,\n \"An HTTP Link canonical target is invalid, non-absolute, credential-bearing, or unsupported.\");\n if (canonicals.limited) add(\"link_header_limited\", \"info\", index,\n \"The Link header item cap was reached; additional declarations were not analyzed.\");\n if (robots.noindex) add(\"explicit_noindex\", \"info\", index,\n \"An unscoped HTTP noindex directive was supplied; this alone does not establish Google indexing state.\");\n else if (robots.googlebotNoindex) add(\"googlebot_noindex\", \"info\", index,\n \"A Googlebot-specific HTTP noindex directive was supplied; live crawler application remains unverified.\");\n if (robots.googlebotNoimageindex) add(\"explicit_noimageindex\", \"info\", index,\n \"A Googlebot-applicable noimageindex declaration was supplied; actual image indexing behavior remains unverified.\");\n if (attachment) add(\"attachment_disposition\", \"info\", index,\n \"The response declares Content-Disposition attachment; this is not by itself an indexing rule.\");\n if (nonSuccess) add(\"non_success_response\", \"info\", index,\n \"This observation has a non-2xx status; it may not describe a final accessible document.\");\n if (item.status_code === 206) add(\"partial_http_response\", \"info\", index,\n \"HTTP 206 represents a partial response; full-resource behavior is not established.\");\n if (mime === \"unknown\") add(\"unknown_content_type\", \"info\", index,\n \"No recognized MIME category was supplied; document type and indexability are unverified.\");\n if (mime === \"html\") add(\"html_in_non_html_review\", \"info\", index,\n \"An HTML content type was supplied; inspect HTML-specific indexing signals separately.\");\n if (new URL(item.url).pathname.toLowerCase().endsWith(\".pdf\") && mime === \"html\") {\n add(\"pdf_type_mismatch\", \"info\", index,\n \"A .pdf path was observed with an HTML content type; verify the intended response format.\");\n }\n });\n\n allFindings.sort((a, b) =>\n (a.severity === b.severity ? 0 : a.severity === \"warning\" ? -1 : 1)\n || a.resource - b.resource || a.code.localeCompare(b.code));\n out.total_findings = allFindings.length;\n out.findings = allFindings.slice(0, MAX_HTTP_FINDINGS);\n out.findings_truncated = allFindings.length > MAX_HTTP_FINDINGS;\n return out;\n}\n"]}
@@ -0,0 +1,80 @@
1
+ export declare const MAX_CHAIN_HOPS = 8;
2
+ export declare const MAX_CHAIN_FINDINGS = 24;
3
+ export declare const MAX_CHAIN_CANONICALS = 4;
4
+ export declare const MAX_CHAIN_HTML_BYTES = 1048576;
5
+ export declare const MAX_CHAIN_TOTAL_HTML_BYTES = 1500000;
6
+ export declare const CHAIN_REDIRECT_STATES: readonly ["none", "permanent", "temporary"];
7
+ export declare const CHAIN_TARGET_STATES: readonly ["none", "next_observed", "loop", "cross_origin", "https_downgrade", "query_target", "unobserved", "missing", "invalid", "mismatch"];
8
+ export declare const CHAIN_CANONICAL_STATES: readonly ["absent", "self", "sampled", "external", "unobserved", "conflicting", "invalid", "redirect_target"];
9
+ export declare const CHAIN_INDEXING_STATES: readonly ["explicit_noindex", "no_noindex_observed", "unknown"];
10
+ export declare const CHAIN_FINDING_CODES: readonly ["redirect_missing_location", "redirect_invalid_target", "redirect_loop", "redirect_cross_origin", "redirect_https_downgrade", "redirect_query_target", "redirect_observation_mismatch", "redirect_chain_unobserved", "redirect_long_chain", "redirect_destination_http_error", "redirect_destination_noindex", "redirect_destination_robots_blocked", "expected_destination_mismatch", "canonical_conflict", "canonical_invalid", "canonical_external", "canonical_unobserved", "canonical_to_redirect", "canonical_to_http_error", "canonical_to_noindex", "canonical_cycle", "canonical_chain", "final_status_unverified", "destination_indexing_unverified"];
11
+ export type ChainRedirectState = typeof CHAIN_REDIRECT_STATES[number];
12
+ export type ChainTargetState = typeof CHAIN_TARGET_STATES[number];
13
+ export type ChainCanonicalState = typeof CHAIN_CANONICAL_STATES[number];
14
+ export type ChainIndexingState = typeof CHAIN_INDEXING_STATES[number];
15
+ export type ChainFindingCode = typeof CHAIN_FINDING_CODES[number];
16
+ export interface RedirectChainObservation {
17
+ url: string;
18
+ status_code: number;
19
+ location?: string;
20
+ /** Caller-supplied canonical href values, including extracted HTTP Link rel=canonical. */
21
+ canonicals?: string[];
22
+ /** Optional static raw HTML from the HTTP GET (not rendered DOM). */
23
+ html?: string;
24
+ /** [] explicitly means the X-Robots-Tag header was checked and absent. */
25
+ x_robots_tag?: string[];
26
+ /** Actual caller-observed robots accessibility, never inferred from a GET. */
27
+ robots_allowed?: boolean;
28
+ }
29
+ export interface RedirectCanonicalInput {
30
+ source_url: string;
31
+ observations: RedirectChainObservation[];
32
+ expected_destination?: string;
33
+ }
34
+ export interface RedirectCanonicalHop {
35
+ hop: number;
36
+ status_code: number;
37
+ redirect_state: ChainRedirectState;
38
+ redirect_target: ChainTargetState;
39
+ next_hop_observed: boolean;
40
+ canonical_state: ChainCanonicalState;
41
+ canonical_declarations: number;
42
+ canonical_target_sampled: boolean;
43
+ googlebot_indexing_state: ChainIndexingState;
44
+ robots_allowed: "allowed" | "disallowed" | "unknown";
45
+ static_html_examined: boolean;
46
+ x_robots_header_examined: boolean;
47
+ }
48
+ export interface RedirectCanonicalFinding {
49
+ hop: number;
50
+ code: ChainFindingCode;
51
+ severity: "warning" | "info";
52
+ message: string;
53
+ }
54
+ export interface RedirectCanonicalReview {
55
+ scope: "caller_supplied_redirect_evidence" | "live_public_redirect_probe";
56
+ hops_observed: number;
57
+ redirects_observed: number;
58
+ permanent_redirects: number;
59
+ temporary_redirects: number;
60
+ chain_complete: boolean;
61
+ loop_detected: boolean;
62
+ final_status_code?: number;
63
+ expected_destination_match?: boolean;
64
+ conflicting_canonical_hops: number;
65
+ canonical_cycles: number;
66
+ canonical_chain_edges: number;
67
+ nonindexable_destination: boolean;
68
+ destination_indexing_state: ChainIndexingState;
69
+ coverage_limited: true;
70
+ limitations: string[];
71
+ hops: RedirectCanonicalHop[];
72
+ total_findings: number;
73
+ findings: RedirectCanonicalFinding[];
74
+ findings_truncated: boolean;
75
+ error?: string;
76
+ }
77
+ /** Extract rel=canonical hrefs from a bounded HTTP Link field, without echoing them. */
78
+ export declare function canonicalHrefsFromLinkHeader(value: string | null): string[];
79
+ export declare function emptyRedirectCanonicalReview(scope?: RedirectCanonicalReview["scope"]): RedirectCanonicalReview;
80
+ export declare function analyzeRedirectCanonicalChains(input: RedirectCanonicalInput, scope?: RedirectCanonicalReview["scope"]): RedirectCanonicalReview;