mcp-web-validator 1.3.51 → 1.3.54

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 (174) hide show
  1. package/CHANGELOG.md +55 -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/mcp-bounds.js +8 -3
  9. package/dist/mcp-bounds.js.map +1 -1
  10. package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
  11. package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
  12. package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
  13. package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
  14. package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
  15. package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
  16. package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
  17. package/dist/modules/browser-ux/media-diagnostics.js +183 -0
  18. package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
  19. package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
  20. package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
  21. package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
  22. package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
  23. package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
  24. package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
  25. package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
  26. package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
  27. package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
  28. package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
  29. package/dist/modules/browser-ux/resource-failures.js +178 -0
  30. package/dist/modules/browser-ux/resource-failures.js.map +1 -0
  31. package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
  32. package/dist/modules/browser-ux/viewport-parity-probe.js +316 -0
  33. package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
  34. package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
  35. package/dist/modules/browser-ux/viewport-parity.js +224 -0
  36. package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
  37. package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
  38. package/dist/modules/browser-ux/wcag-interactions.js +360 -0
  39. package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
  40. package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
  41. package/dist/modules/change-regression/availability-history-store.js +168 -0
  42. package/dist/modules/change-regression/availability-history-store.js.map +1 -0
  43. package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
  44. package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
  45. package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
  46. package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
  47. package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
  48. package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
  49. package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
  50. package/dist/modules/change-regression/historical-comparisons.js +330 -0
  51. package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
  52. package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
  53. package/dist/modules/change-regression/production-change-comparison.js +214 -0
  54. package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
  55. package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
  56. package/dist/modules/change-regression/regression-alerts.js +183 -0
  57. package/dist/modules/change-regression/regression-alerts.js.map +1 -0
  58. package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
  59. package/dist/modules/change-regression/strict-observation-time.js +31 -0
  60. package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
  61. package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
  62. package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
  63. package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
  64. package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
  65. package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
  66. package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
  67. package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
  68. package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
  69. package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
  70. package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
  71. package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
  72. package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
  73. package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
  74. package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
  75. package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
  76. package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
  77. package/dist/modules/content-schema/extract-main-content.js +33 -0
  78. package/dist/modules/content-schema/extract-main-content.js.map +1 -0
  79. package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
  80. package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
  81. package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
  82. package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
  83. package/dist/modules/content-schema/extract-product-claims.js +58 -0
  84. package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
  85. package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
  86. package/dist/modules/content-schema/extract-structured-data.js +25 -0
  87. package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
  88. package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
  89. package/dist/modules/content-schema/metadata-consistency.js +282 -0
  90. package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
  91. package/dist/modules/content-schema/product-claims.d.ts +73 -0
  92. package/dist/modules/content-schema/product-claims.js +195 -0
  93. package/dist/modules/content-schema/product-claims.js.map +1 -0
  94. package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
  95. package/dist/modules/content-schema/same-language-duplicates.js +158 -0
  96. package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
  97. package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
  98. package/dist/modules/content-schema/structured-data-validation.js +385 -0
  99. package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
  100. package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
  101. package/dist/modules/external-metrics/crux-field-probe.js +113 -0
  102. package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
  103. package/dist/modules/external-metrics/crux-field.d.ts +61 -0
  104. package/dist/modules/external-metrics/crux-field.js +231 -0
  105. package/dist/modules/external-metrics/crux-field.js.map +1 -0
  106. package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
  107. package/dist/modules/http-crawl/availability-observations.js +206 -0
  108. package/dist/modules/http-crawl/availability-observations.js.map +1 -0
  109. package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
  110. package/dist/modules/http-crawl/availability-probe.js +46 -0
  111. package/dist/modules/http-crawl/availability-probe.js.map +1 -0
  112. package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
  113. package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
  114. package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
  115. package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
  116. package/dist/modules/http-crawl/crawler-access.js +404 -0
  117. package/dist/modules/http-crawl/crawler-access.js.map +1 -0
  118. package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
  119. package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
  120. package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
  121. package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
  122. package/dist/modules/http-crawl/http-delivery.js +273 -0
  123. package/dist/modules/http-crawl/http-delivery.js.map +1 -0
  124. package/dist/modules/http-crawl/https-security.d.ts +84 -0
  125. package/dist/modules/http-crawl/https-security.js +441 -0
  126. package/dist/modules/http-crawl/https-security.js.map +1 -0
  127. package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
  128. package/dist/modules/http-crawl/non-html-directives.js +353 -0
  129. package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
  130. package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
  131. package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
  132. package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
  133. package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
  134. package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
  135. package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
  136. package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
  137. package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
  138. package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
  139. package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
  140. package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
  141. package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
  142. package/dist/modules/http-crawl/url-variants.d.ts +86 -0
  143. package/dist/modules/http-crawl/url-variants.js +379 -0
  144. package/dist/modules/http-crawl/url-variants.js.map +1 -0
  145. package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
  146. package/dist/modules/site-architecture/extract-internal-links.js +88 -0
  147. package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
  148. package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
  149. package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
  150. package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
  151. package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
  152. package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
  153. package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
  154. package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
  155. package/dist/modules/site-architecture/internal-link-graph.js +414 -0
  156. package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
  157. package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
  158. package/dist/modules/site-architecture/internal-link-quality.js +260 -0
  159. package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
  160. package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
  161. package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
  162. package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
  163. package/dist/network.d.ts +4 -0
  164. package/dist/network.js +25 -8
  165. package/dist/network.js.map +1 -1
  166. package/dist/presentation.d.ts +53 -0
  167. package/dist/presentation.js +526 -0
  168. package/dist/presentation.js.map +1 -1
  169. package/dist/screenshot.d.ts +2 -1
  170. package/dist/screenshot.js +4 -2
  171. package/dist/screenshot.js.map +1 -1
  172. package/dist/seo-auditor.js +16 -6
  173. package/dist/seo-auditor.js.map +1 -1
  174. package/package.json +7 -4
@@ -0,0 +1,201 @@
1
+ import * as cheerio from "cheerio";
2
+ import { MAX_PROVENANCE_DECLARATIONS, MAX_PROVENANCE_HTML_BYTES, normalizedEvidenceDate, safeDatasetVersion, safeProvenanceId, safeProvenanceUrl, } from "./citation-methodology-consistency.js";
3
+ /**
4
+ * Static-only HTML adapter. Source links and declared dates are observed but
5
+ * never dereferenced. Each runtime imports its own Cheerio installation.
6
+ */
7
+ export function observeProvenancePage(html, rawUrl) {
8
+ const url = safeProvenanceUrl(rawUrl) ?? "";
9
+ if (!url || !html || new TextEncoder().encode(html).byteLength > MAX_PROVENANCE_HTML_BYTES) {
10
+ return { url, citations: [], datasets: [], methodologies: [],
11
+ published_dates: [], modified_dates: [], invalid_dates: 0,
12
+ declarations_truncated: false, eligible: false };
13
+ }
14
+ const $ = cheerio.load(html);
15
+ const citations = [];
16
+ const datasets = [];
17
+ const methodologies = [];
18
+ const published = [];
19
+ const modified = [];
20
+ let badDates = 0;
21
+ let count = 0;
22
+ let truncated = false;
23
+ function slot() {
24
+ count += 1;
25
+ if (count > MAX_PROVENANCE_DECLARATIONS) {
26
+ truncated = true;
27
+ return false;
28
+ }
29
+ return true;
30
+ }
31
+ function date(raw, output) {
32
+ if (!raw)
33
+ return undefined;
34
+ const normalized = normalizedEvidenceDate(raw.trim());
35
+ if (normalized)
36
+ output.push(normalized);
37
+ else
38
+ badDates += 1;
39
+ return normalized;
40
+ }
41
+ function citation(id, target) {
42
+ if (!slot())
43
+ return;
44
+ citations.push({
45
+ ...(id && safeProvenanceId(id.trim()) ? { id: id.trim() } : {}),
46
+ ...(target && safeProvenanceUrl(target.trim()) ? { url: safeProvenanceUrl(target.trim()) } : {}),
47
+ });
48
+ }
49
+ function dataset(id, version, asOf, method) {
50
+ if (!slot())
51
+ return;
52
+ const safeDate = asOf ? normalizedEvidenceDate(asOf.trim()) : undefined;
53
+ if (asOf && !safeDate)
54
+ badDates += 1;
55
+ datasets.push({
56
+ ...(id && safeProvenanceId(id.trim()) ? { id: id.trim() } : {}),
57
+ ...(version && safeDatasetVersion(version.trim()) ? { version: version.trim() } : {}),
58
+ ...(safeDate ? { as_of: safeDate } : {}),
59
+ ...(method && safeProvenanceId(method.trim()) ? { methodology_id: method.trim() } : {}),
60
+ });
61
+ }
62
+ function methodology(id, target) {
63
+ if (!slot())
64
+ return;
65
+ methodologies.push({
66
+ ...(id && safeProvenanceId(id.trim()) ? { id: id.trim() } : {}),
67
+ ...(target && safeProvenanceUrl(target.trim()) ? { url: safeProvenanceUrl(target.trim()) } : {}),
68
+ });
69
+ }
70
+ const allowedTypes = new Set(["Article", "NewsArticle", "ScholarlyArticle", "Report", "CreativeWork", "Dataset"]);
71
+ const scripts = $('script[type="application/ld+json"]').toArray();
72
+ if (scripts.length > 5)
73
+ truncated = true;
74
+ for (const element of scripts.slice(0, 5)) {
75
+ const source = $(element).html() ?? "";
76
+ if (source.length > 20_000) {
77
+ truncated = true;
78
+ continue;
79
+ }
80
+ try {
81
+ const parsed = JSON.parse(source);
82
+ const roots = Array.isArray(parsed) ? parsed.slice(0, 12) : [parsed];
83
+ for (const root of roots) {
84
+ if (!root || typeof root !== "object" || Array.isArray(root))
85
+ continue;
86
+ const base = root;
87
+ const graph = Array.isArray(base["@graph"]) ? base["@graph"].slice(0, 12) : [];
88
+ if (Array.isArray(base["@graph"]) && base["@graph"].length > 12)
89
+ truncated = true;
90
+ for (const candidate of [base, ...graph]) {
91
+ if (!candidate || typeof candidate !== "object" || Array.isArray(candidate))
92
+ continue;
93
+ const object = candidate;
94
+ const kind = object["@type"];
95
+ const types = Array.isArray(kind) ? kind.filter((v) => typeof v === "string")
96
+ : typeof kind === "string" ? [kind] : [];
97
+ const recognized = types.some((type) => allowedTypes.has(type) ||
98
+ [...allowedTypes].some((allowed) => type.endsWith("/" + allowed)));
99
+ if (!recognized)
100
+ continue;
101
+ const isDataset = types.some((type) => type === "Dataset" || type.endsWith("/Dataset"));
102
+ if (!isDataset && typeof object.datePublished === "string")
103
+ date(object.datePublished, published);
104
+ if (!isDataset && typeof object.dateModified === "string")
105
+ date(object.dateModified, modified);
106
+ if (isDataset) {
107
+ const identifier = typeof object.identifier === "string" ? object.identifier : undefined;
108
+ const version = typeof object.version === "string" ? object.version : undefined;
109
+ const asOf = typeof object.dateModified === "string" ? object.dateModified : undefined;
110
+ // No semantic inference from arbitrary measurementTechnique prose.
111
+ dataset(identifier, version, asOf);
112
+ }
113
+ if (object.citation !== undefined) {
114
+ const raw = Array.isArray(object.citation) ? object.citation.slice(0, 16) : [object.citation];
115
+ if (Array.isArray(object.citation) && object.citation.length > 16)
116
+ truncated = true;
117
+ for (const item of raw) {
118
+ if (typeof item === "string")
119
+ citation(undefined, item);
120
+ else if (item && typeof item === "object" && !Array.isArray(item)) {
121
+ const entry = item;
122
+ citation(typeof entry.identifier === "string" ? entry.identifier : undefined, typeof entry.url === "string" ? entry.url :
123
+ typeof entry["@id"] === "string" ? entry["@id"] : undefined);
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+ if (Array.isArray(parsed) && parsed.length > 12)
130
+ truncated = true;
131
+ }
132
+ catch {
133
+ // Invalid JSON-LD is owned by the existing schema validator. This
134
+ // evidence tool cannot treat its unparsed contents as verified claims.
135
+ truncated = true;
136
+ }
137
+ }
138
+ const headDateTags = [
139
+ ['head meta[property="article:published_time"]', published],
140
+ ['head meta[property="article:modified_time"]', modified],
141
+ ['head meta[itemprop="datePublished"]', published],
142
+ ['head meta[itemprop="dateModified"]', modified],
143
+ ];
144
+ for (const [selector, output] of headDateTags) {
145
+ for (const element of $(selector).toArray().slice(0, 12)) {
146
+ if (!slot())
147
+ continue;
148
+ date($(element).attr("content"), output);
149
+ }
150
+ }
151
+ $("template,script,style,noscript,nav,header,footer,aside,[hidden],[aria-hidden='true']").remove();
152
+ const main = $("main,[role='main']").first();
153
+ const article = $("article").first();
154
+ const root = main.length ? main : article.length ? article : $("body").first();
155
+ if (!root.length)
156
+ return { url, citations, datasets, methodologies,
157
+ published_dates: published, modified_dates: modified,
158
+ invalid_dates: badDates, declarations_truncated: truncated, eligible: false };
159
+ for (const element of root.find("time[datetime][itemprop]").toArray().slice(0, 24)) {
160
+ if (!slot())
161
+ continue;
162
+ const itemprop = $(element).attr("itemprop");
163
+ if (itemprop === "datePublished")
164
+ date($(element).attr("datetime"), published);
165
+ if (itemprop === "dateModified")
166
+ date($(element).attr("datetime"), modified);
167
+ }
168
+ const links = root.find("a[href],a[data-citation-id],a[data-methodology-id]").toArray();
169
+ if (links.length > 150)
170
+ truncated = true;
171
+ for (const element of links.slice(0, 150)) {
172
+ const link = $(element);
173
+ const rel = (link.attr("rel") ?? "").toLowerCase().split(/\s+/);
174
+ const bibliography = link.parents('#references,#bibliography,.references,.bibliography,[role="doc-bibliography"]').length > 0;
175
+ if (rel.includes("cite") || link.attr("data-citation-id") !== undefined || bibliography) {
176
+ citation(link.attr("data-citation-id"), link.attr("href"));
177
+ }
178
+ if (link.attr("data-methodology-id") !== undefined) {
179
+ methodology(link.attr("data-methodology-id"), link.attr("href"));
180
+ }
181
+ }
182
+ const datasetNodes = root.find("[data-dataset-id],[data-dataset-version],[data-dataset-as-of]").toArray();
183
+ if (datasetNodes.length > MAX_PROVENANCE_DECLARATIONS)
184
+ truncated = true;
185
+ for (const element of datasetNodes.slice(0, MAX_PROVENANCE_DECLARATIONS)) {
186
+ const node = $(element);
187
+ dataset(node.attr("data-dataset-id"), node.attr("data-dataset-version"), node.attr("data-dataset-as-of"), node.attr("data-methodology-id"));
188
+ }
189
+ return {
190
+ url,
191
+ citations: citations.slice(0, MAX_PROVENANCE_DECLARATIONS),
192
+ datasets: datasets.slice(0, MAX_PROVENANCE_DECLARATIONS),
193
+ methodologies: methodologies.slice(0, MAX_PROVENANCE_DECLARATIONS),
194
+ published_dates: published.slice(0, MAX_PROVENANCE_DECLARATIONS),
195
+ modified_dates: modified.slice(0, MAX_PROVENANCE_DECLARATIONS),
196
+ invalid_dates: badDates,
197
+ declarations_truncated: truncated,
198
+ eligible: true,
199
+ };
200
+ }
201
+ //# sourceMappingURL=extract-citation-methodology.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-citation-methodology.js","sourceRoot":"","sources":["../../../src/modules/content-schema/extract-citation-methodology.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GAKlB,MAAM,uCAAuC,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,MAAc;IAChE,MAAM,GAAG,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5C,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,C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,CAAC,CAAC,EAAE,2BAA2B,CAAC;QAClE,eAAe,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,2BAA2B,CAAC;QAChE,cAAc,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,2BAA2B,CAAC;QAC9D,aAAa,EAAE,QAAQ;QACvB,sBAAsB,EAAE,SAAS;QACjC,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC","sourcesContent":["import * as cheerio from \"cheerio\";\nimport {\n MAX_PROVENANCE_DECLARATIONS,\n MAX_PROVENANCE_HTML_BYTES,\n normalizedEvidenceDate,\n safeDatasetVersion,\n safeProvenanceId,\n safeProvenanceUrl,\n type CitationDeclaration,\n type DatasetDeclaration,\n type MethodologyDeclaration,\n type ProvenanceObservation,\n} from \"./citation-methodology-consistency.js\";\n\n/**\n * Static-only HTML adapter. Source links and declared dates are observed but\n * never dereferenced. Each runtime imports its own Cheerio installation.\n */\nexport function observeProvenancePage(html: string, rawUrl: string): ProvenanceObservation {\n const url = safeProvenanceUrl(rawUrl) ?? \"\";\n if (!url || !html || new TextEncoder().encode(html).byteLength > MAX_PROVENANCE_HTML_BYTES) {\n return { url, citations: [], datasets: [], methodologies: [],\n published_dates: [], modified_dates: [], invalid_dates: 0,\n declarations_truncated: false, eligible: false };\n }\n const $ = cheerio.load(html);\n const citations: CitationDeclaration[] = [];\n const datasets: DatasetDeclaration[] = [];\n const methodologies: MethodologyDeclaration[] = [];\n const published: string[] = [];\n const modified: string[] = [];\n let badDates = 0;\n let count = 0;\n let truncated = false;\n function slot(): boolean {\n count += 1;\n if (count > MAX_PROVENANCE_DECLARATIONS) { truncated = true; return false; }\n return true;\n }\n function date(raw: string | undefined, output: string[]): string | undefined {\n if (!raw) return undefined;\n const normalized = normalizedEvidenceDate(raw.trim());\n if (normalized) output.push(normalized);\n else badDates += 1;\n return normalized;\n }\n function citation(id: string | undefined, target: string | undefined) {\n if (!slot()) return;\n citations.push({\n ...(id && safeProvenanceId(id.trim()) ? { id: id.trim() } : {}),\n ...(target && safeProvenanceUrl(target.trim()) ? { url: safeProvenanceUrl(target.trim()) } : {}),\n });\n }\n function dataset(id: string | undefined, version?: string, asOf?: string, method?: string) {\n if (!slot()) return;\n const safeDate = asOf ? normalizedEvidenceDate(asOf.trim()) : undefined;\n if (asOf && !safeDate) badDates += 1;\n datasets.push({\n ...(id && safeProvenanceId(id.trim()) ? { id: id.trim() } : {}),\n ...(version && safeDatasetVersion(version.trim()) ? { version: version.trim() } : {}),\n ...(safeDate ? { as_of: safeDate } : {}),\n ...(method && safeProvenanceId(method.trim()) ? { methodology_id: method.trim() } : {}),\n });\n }\n function methodology(id: string | undefined, target?: string) {\n if (!slot()) return;\n methodologies.push({\n ...(id && safeProvenanceId(id.trim()) ? { id: id.trim() } : {}),\n ...(target && safeProvenanceUrl(target.trim()) ? { url: safeProvenanceUrl(target.trim()) } : {}),\n });\n }\n const allowedTypes = new Set([\"Article\", \"NewsArticle\", \"ScholarlyArticle\", \"Report\", \"CreativeWork\", \"Dataset\"]);\n const scripts = $('script[type=\"application/ld+json\"]').toArray();\n if (scripts.length > 5) truncated = true;\n for (const element of scripts.slice(0, 5)) {\n const source = $(element).html() ?? \"\";\n if (source.length > 20_000) { truncated = true; continue; }\n try {\n const parsed: unknown = JSON.parse(source);\n const roots = Array.isArray(parsed) ? parsed.slice(0, 12) : [parsed];\n for (const root of roots) {\n if (!root || typeof root !== \"object\" || Array.isArray(root)) continue;\n const base = root as Record<string, unknown>;\n const graph = Array.isArray(base[\"@graph\"]) ? base[\"@graph\"].slice(0, 12) : [];\n if (Array.isArray(base[\"@graph\"]) && base[\"@graph\"].length > 12) truncated = true;\n for (const candidate of [base, ...graph]) {\n if (!candidate || typeof candidate !== \"object\" || Array.isArray(candidate)) continue;\n const object = candidate as Record<string, unknown>;\n const kind = object[\"@type\"];\n const types = Array.isArray(kind) ? kind.filter((v): v is string => typeof v === \"string\")\n : typeof kind === \"string\" ? [kind] : [];\n const recognized = types.some((type) => allowedTypes.has(type) ||\n [...allowedTypes].some((allowed) => type.endsWith(\"/\" + allowed)));\n if (!recognized) continue;\n const isDataset = types.some((type) => type === \"Dataset\" || type.endsWith(\"/Dataset\"));\n if (!isDataset && typeof object.datePublished === \"string\") date(object.datePublished, published);\n if (!isDataset && typeof object.dateModified === \"string\") date(object.dateModified, modified);\n if (isDataset) {\n const identifier = typeof object.identifier === \"string\" ? object.identifier : undefined;\n const version = typeof object.version === \"string\" ? object.version : undefined;\n const asOf = typeof object.dateModified === \"string\" ? object.dateModified : undefined;\n // No semantic inference from arbitrary measurementTechnique prose.\n dataset(identifier, version, asOf);\n }\n if (object.citation !== undefined) {\n const raw = Array.isArray(object.citation) ? object.citation.slice(0, 16) : [object.citation];\n if (Array.isArray(object.citation) && object.citation.length > 16) truncated = true;\n for (const item of raw) {\n if (typeof item === \"string\") citation(undefined, item);\n else if (item && typeof item === \"object\" && !Array.isArray(item)) {\n const entry = item as Record<string, unknown>;\n citation(typeof entry.identifier === \"string\" ? entry.identifier : undefined,\n typeof entry.url === \"string\" ? entry.url :\n typeof entry[\"@id\"] === \"string\" ? entry[\"@id\"] : undefined);\n }\n }\n }\n }\n }\n if (Array.isArray(parsed) && parsed.length > 12) truncated = true;\n } catch {\n // Invalid JSON-LD is owned by the existing schema validator. This\n // evidence tool cannot treat its unparsed contents as verified claims.\n truncated = true;\n }\n }\n const headDateTags: Array<[string, string[]]> = [\n ['head meta[property=\"article:published_time\"]', published],\n ['head meta[property=\"article:modified_time\"]', modified],\n ['head meta[itemprop=\"datePublished\"]', published],\n ['head meta[itemprop=\"dateModified\"]', modified],\n ];\n for (const [selector, output] of headDateTags) {\n for (const element of $(selector).toArray().slice(0, 12)) {\n if (!slot()) continue;\n date($(element).attr(\"content\"), output);\n }\n }\n $(\"template,script,style,noscript,nav,header,footer,aside,[hidden],[aria-hidden='true']\").remove();\n const main = $(\"main,[role='main']\").first();\n const article = $(\"article\").first();\n const root = main.length ? main : article.length ? article : $(\"body\").first();\n if (!root.length) return { url, citations, datasets, methodologies,\n published_dates: published, modified_dates: modified,\n invalid_dates: badDates, declarations_truncated: truncated, eligible: false };\n for (const element of root.find(\"time[datetime][itemprop]\").toArray().slice(0, 24)) {\n if (!slot()) continue;\n const itemprop = $(element).attr(\"itemprop\");\n if (itemprop === \"datePublished\") date($(element).attr(\"datetime\"), published);\n if (itemprop === \"dateModified\") date($(element).attr(\"datetime\"), modified);\n }\n const links = root.find(\"a[href],a[data-citation-id],a[data-methodology-id]\").toArray();\n if (links.length > 150) truncated = true;\n for (const element of links.slice(0, 150)) {\n const link = $(element);\n const rel = (link.attr(\"rel\") ?? \"\").toLowerCase().split(/\\s+/);\n const bibliography = link.parents(\n '#references,#bibliography,.references,.bibliography,[role=\"doc-bibliography\"]',\n ).length > 0;\n if (rel.includes(\"cite\") || link.attr(\"data-citation-id\") !== undefined || bibliography) {\n citation(link.attr(\"data-citation-id\"), link.attr(\"href\"));\n }\n if (link.attr(\"data-methodology-id\") !== undefined) {\n methodology(link.attr(\"data-methodology-id\"), link.attr(\"href\"));\n }\n }\n const datasetNodes = root.find(\"[data-dataset-id],[data-dataset-version],[data-dataset-as-of]\").toArray();\n if (datasetNodes.length > MAX_PROVENANCE_DECLARATIONS) truncated = true;\n for (const element of datasetNodes.slice(0, MAX_PROVENANCE_DECLARATIONS)) {\n const node = $(element);\n dataset(node.attr(\"data-dataset-id\"), node.attr(\"data-dataset-version\"),\n node.attr(\"data-dataset-as-of\"), node.attr(\"data-methodology-id\"));\n }\n return {\n url,\n citations: citations.slice(0, MAX_PROVENANCE_DECLARATIONS),\n datasets: datasets.slice(0, MAX_PROVENANCE_DECLARATIONS),\n methodologies: methodologies.slice(0, MAX_PROVENANCE_DECLARATIONS),\n published_dates: published.slice(0, MAX_PROVENANCE_DECLARATIONS),\n modified_dates: modified.slice(0, MAX_PROVENANCE_DECLARATIONS),\n invalid_dates: badDates,\n declarations_truncated: truncated,\n eligible: true,\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { type IntentObservation } from "./competitor-intent-comparison.js";
2
+ export declare function observeIntentHtml(html: string, rawUrl: string): IntentObservation;
@@ -0,0 +1,140 @@
1
+ import * as cheerio from "cheerio";
2
+ import { INTENTS, MAX_INTENT_HTML_BYTES, safeIntentUrl, } from "./competitor-intent-comparison.js";
3
+ const MAX_JSONLD_SCRIPTS = 4;
4
+ const MAX_JSONLD_BYTES = 24_000;
5
+ const MAX_ELEMENTS = 160;
6
+ export function observeIntentHtml(html, rawUrl) {
7
+ const url = safeIntentUrl(rawUrl) ?? "";
8
+ const signals = Object.fromEntries(INTENTS.map((intent) => [intent, []]));
9
+ const empty = {
10
+ url, title: "", h1: "", signals,
11
+ eligible: false, extraction_limited: false, main_found: false,
12
+ };
13
+ if (!url || !html || new TextEncoder().encode(html).byteLength > MAX_INTENT_HTML_BYTES)
14
+ return empty;
15
+ const $ = cheerio.load(html);
16
+ const title = $("head title").first().text().replace(/\s+/gu, " ").trim().slice(0, 360);
17
+ let truncated = $("head title").first().text().length > 360;
18
+ const scripts = $('script[type="application/ld+json"]').toArray();
19
+ if (scripts.length > MAX_JSONLD_SCRIPTS)
20
+ truncated = true;
21
+ function mark(intent, signal) {
22
+ if (!signals[intent].includes(signal))
23
+ signals[intent].push(signal);
24
+ }
25
+ for (const script of scripts.slice(0, MAX_JSONLD_SCRIPTS)) {
26
+ const content = $(script).html() ?? "";
27
+ if (new TextEncoder().encode(content).byteLength > MAX_JSONLD_BYTES) {
28
+ truncated = true;
29
+ continue;
30
+ }
31
+ try {
32
+ const parsed = JSON.parse(content);
33
+ const nodes = Array.isArray(parsed) ? parsed.slice(0, 12) : [parsed];
34
+ if (Array.isArray(parsed) && parsed.length > 12)
35
+ truncated = true;
36
+ for (const node of [...nodes]) {
37
+ if (!node || typeof node !== "object" || Array.isArray(node))
38
+ continue;
39
+ const graph = node["@graph"];
40
+ if (Array.isArray(graph)) {
41
+ if (graph.length > 12)
42
+ truncated = true;
43
+ nodes.push(...graph.slice(0, 12));
44
+ }
45
+ }
46
+ for (const node of nodes.slice(0, 24)) {
47
+ if (!node || typeof node !== "object" || Array.isArray(node))
48
+ continue;
49
+ const record = node;
50
+ const kind = record["@type"];
51
+ const types = (Array.isArray(kind) ? kind : [kind])
52
+ .filter((name) => typeof name === "string" && name.length <= 90)
53
+ .map((name) => name.split("/").at(-1));
54
+ if (types.some((type) => ["Article", "NewsArticle", "BlogPosting", "ScholarlyArticle"].includes(type ?? "")))
55
+ mark("informational", "article_schema");
56
+ if (types.includes("FAQPage"))
57
+ mark("informational", "faq_schema");
58
+ if (types.includes("HowTo"))
59
+ mark("informational", "howto_schema");
60
+ if (types.includes("Product"))
61
+ mark("commercial", "product_schema");
62
+ if (types.some((type) => ["Review", "AggregateRating"].includes(type ?? "")))
63
+ mark("commercial", "review_schema");
64
+ if (types.includes("Offer") || types.includes("AggregateOffer") ||
65
+ ((types.includes("Product")) && record.offers && typeof record.offers === "object")) {
66
+ mark("transactional", "offer_schema");
67
+ }
68
+ }
69
+ if (nodes.length > 24)
70
+ truncated = true;
71
+ }
72
+ catch {
73
+ // Parsing failure belongs to the existing JSON-LD validator; it does
74
+ // not authorize deriving intent from partially understood JSON.
75
+ truncated = true;
76
+ }
77
+ }
78
+ $("script,template,style,noscript,nav,header,footer,aside,[hidden],[aria-hidden='true']").remove();
79
+ const main = $("main,[role='main']").first();
80
+ const article = $("article").first();
81
+ const root = main.length ? main : article.length ? article : $("body").first();
82
+ if (!root.length)
83
+ return { ...empty, title, extraction_limited: truncated };
84
+ const h1Text = root.find("h1").first().text().replace(/\s+/gu, " ").trim();
85
+ const h1 = h1Text.slice(0, 360);
86
+ if (h1Text.length > 360)
87
+ truncated = true;
88
+ const headings = root.find("h2,h3").toArray();
89
+ if (headings.length > MAX_ELEMENTS)
90
+ truncated = true;
91
+ const headingText = headings.slice(0, MAX_ELEMENTS)
92
+ .map((node) => $(node).text().replace(/\s+/gu, " ").trim().toLowerCase().slice(0, 120));
93
+ if (headingText.some((value) => /\b(?:versus|compare|comparison|best|review|reviews)\b|\bvs\.?\b/iu.test(value)))
94
+ mark("commercial", "comparison_heading");
95
+ if (headingText.some((value) => /\b(?:pricing|prices|price|plans|costs)\b/iu.test(value)))
96
+ mark("commercial", "pricing_heading");
97
+ if (headingText.some((value) => /\b(?:contact|locations|find us|get in touch|directions)\b/iu.test(value)))
98
+ mark("navigational", "contact_heading");
99
+ const paragraphs = root.find("p").toArray();
100
+ if (paragraphs.length > MAX_ELEMENTS)
101
+ truncated = true;
102
+ const substantive = paragraphs.slice(0, MAX_ELEMENTS)
103
+ .filter((node) => $(node).text().trim().length >= 80).length;
104
+ if ((root.is("article") || root.find("article").length > 0) &&
105
+ headings.length >= 2 && substantive >= 2)
106
+ mark("informational", "editorial_sections");
107
+ const anchors = root.find("a[href]").toArray();
108
+ if (anchors.length > MAX_ELEMENTS)
109
+ truncated = true;
110
+ for (const anchor of anchors.slice(0, MAX_ELEMENTS)) {
111
+ const href = ($(anchor).attr("href") ?? "").toLowerCase().slice(0, 300);
112
+ const label = $(anchor).text().replace(/\s+/gu, " ").trim().toLowerCase().slice(0, 100);
113
+ if (/(?:^|[/#])(?:checkout|cart|basket|booking|reserve|order)(?:[-/?#]|$)/.test(href))
114
+ mark("transactional", "checkout_link");
115
+ if (/\b(?:buy now|add to cart|checkout|book now|reserve now|order now|purchase now)\b/i.test(label))
116
+ mark("transactional", "purchase_action");
117
+ if (/(?:^|[/#])contact(?:[-/?#]|$)/.test(href) && /\b(?:contact|location|directions)\b/.test(label))
118
+ mark("navigational", "main_contact_link");
119
+ }
120
+ const actions = root.find("button,input[type='submit'],input[type='button']").toArray();
121
+ if (actions.length > MAX_ELEMENTS)
122
+ truncated = true;
123
+ for (const action of actions.slice(0, MAX_ELEMENTS)) {
124
+ const button = $(action);
125
+ const label = (button.attr("value") ?? button.text()).replace(/\s+/gu, " ")
126
+ .trim().toLowerCase().slice(0, 100);
127
+ if (/\b(?:buy now|add to cart|checkout|book now|reserve now|order now|purchase now)\b/i.test(label)) {
128
+ mark("transactional", "purchase_action");
129
+ if (button.closest("form").length)
130
+ mark("transactional", "purchase_form");
131
+ }
132
+ }
133
+ if (root.find("address").length)
134
+ mark("navigational", "main_address");
135
+ return {
136
+ url, title, h1, signals, eligible: true,
137
+ extraction_limited: truncated, main_found: Boolean(main.length || article.length),
138
+ };
139
+ }
140
+ //# sourceMappingURL=extract-competitor-intent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-competitor-intent.js","sourceRoot":"","sources":["../../../src/modules/content-schema/extract-competitor-intent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,OAAO,EAAE,qBAAqB,EAAE,aAAa,GAE9C,MAAM,mCAAmC,CAAC;AAE3C,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAChC,MAAM,YAAY,GAAG,GAAG,CAAC;AAEzB,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,MAAc;IAC5D,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACxC,MAAM,OAAO,GACX,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAc,CAAC,CAAC,CAAmC,CAAC;IAC1G,MAAM,KAAK,GAAG;QACZ,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO;QAC/B,QAAQ,EAAE,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK;KAC9D,CAAC;IACF,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,qBAAqB;QAAE,OAAO,KAAK,CAAC;IACrG,MAAM,CAAC,GAAG,OA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E,YAAY,CAAC,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;QACzB,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;aACxE,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACtC,IAAI,mFAAmF,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACpG,IAAI,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;YACzC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM;gBAAE,IAAI,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM;QAAE,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACtE,OAAO;QACL,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI;QACvC,kBAAkB,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;KAClF,CAAC;AACJ,CAAC","sourcesContent":["import * as cheerio from \"cheerio\";\nimport {\n INTENTS, MAX_INTENT_HTML_BYTES, safeIntentUrl,\n type IntentObservation, type SearchIntent,\n} from \"./competitor-intent-comparison.js\";\n\nconst MAX_JSONLD_SCRIPTS = 4;\nconst MAX_JSONLD_BYTES = 24_000;\nconst MAX_ELEMENTS = 160;\n\nexport function observeIntentHtml(html: string, rawUrl: string): IntentObservation {\n const url = safeIntentUrl(rawUrl) ?? \"\";\n const signals: Record<SearchIntent, string[]> =\n Object.fromEntries(INTENTS.map((intent) => [intent, [] as string[]])) as Record<SearchIntent, string[]>;\n const empty = {\n url, title: \"\", h1: \"\", signals,\n eligible: false, extraction_limited: false, main_found: false,\n };\n if (!url || !html || new TextEncoder().encode(html).byteLength > MAX_INTENT_HTML_BYTES) return empty;\n const $ = cheerio.load(html);\n const title = $(\"head title\").first().text().replace(/\\s+/gu, \" \").trim().slice(0, 360);\n let truncated = $(\"head title\").first().text().length > 360;\n const scripts = $('script[type=\"application/ld+json\"]').toArray();\n if (scripts.length > MAX_JSONLD_SCRIPTS) truncated = true;\n function mark(intent: SearchIntent, signal: string) {\n if (!signals[intent].includes(signal)) signals[intent].push(signal);\n }\n for (const script of scripts.slice(0, MAX_JSONLD_SCRIPTS)) {\n const content = $(script).html() ?? \"\";\n if (new TextEncoder().encode(content).byteLength > MAX_JSONLD_BYTES) {\n truncated = true;\n continue;\n }\n try {\n const parsed: unknown = JSON.parse(content);\n const nodes: unknown[] = Array.isArray(parsed) ? parsed.slice(0, 12) : [parsed];\n if (Array.isArray(parsed) && parsed.length > 12) truncated = true;\n for (const node of [...nodes]) {\n if (!node || typeof node !== \"object\" || Array.isArray(node)) continue;\n const graph = (node as Record<string, unknown>)[\"@graph\"];\n if (Array.isArray(graph)) {\n if (graph.length > 12) truncated = true;\n nodes.push(...graph.slice(0, 12));\n }\n }\n for (const node of nodes.slice(0, 24)) {\n if (!node || typeof node !== \"object\" || Array.isArray(node)) continue;\n const record = node as Record<string, unknown>;\n const kind = record[\"@type\"];\n const types = (Array.isArray(kind) ? kind : [kind])\n .filter((name): name is string => typeof name === \"string\" && name.length <= 90)\n .map((name) => name.split(\"/\").at(-1));\n if (types.some((type) => [\"Article\", \"NewsArticle\", \"BlogPosting\", \"ScholarlyArticle\"].includes(type ?? \"\")))\n mark(\"informational\", \"article_schema\");\n if (types.includes(\"FAQPage\")) mark(\"informational\", \"faq_schema\");\n if (types.includes(\"HowTo\")) mark(\"informational\", \"howto_schema\");\n if (types.includes(\"Product\")) mark(\"commercial\", \"product_schema\");\n if (types.some((type) => [\"Review\", \"AggregateRating\"].includes(type ?? \"\")))\n mark(\"commercial\", \"review_schema\");\n if (types.includes(\"Offer\") || types.includes(\"AggregateOffer\") ||\n ((types.includes(\"Product\")) && record.offers && typeof record.offers === \"object\")) {\n mark(\"transactional\", \"offer_schema\");\n }\n }\n if (nodes.length > 24) truncated = true;\n } catch {\n // Parsing failure belongs to the existing JSON-LD validator; it does\n // not authorize deriving intent from partially understood JSON.\n truncated = true;\n }\n }\n $(\"script,template,style,noscript,nav,header,footer,aside,[hidden],[aria-hidden='true']\").remove();\n const main = $(\"main,[role='main']\").first();\n const article = $(\"article\").first();\n const root = main.length ? main : article.length ? article : $(\"body\").first();\n if (!root.length) return { ...empty, title, extraction_limited: truncated };\n const h1Text = root.find(\"h1\").first().text().replace(/\\s+/gu, \" \").trim();\n const h1 = h1Text.slice(0, 360);\n if (h1Text.length > 360) truncated = true;\n const headings = root.find(\"h2,h3\").toArray();\n if (headings.length > MAX_ELEMENTS) truncated = true;\n const headingText = headings.slice(0, MAX_ELEMENTS)\n .map((node) => $(node).text().replace(/\\s+/gu, \" \").trim().toLowerCase().slice(0, 120));\n if (headingText.some((value) => /\\b(?:versus|compare|comparison|best|review|reviews)\\b|\\bvs\\.?\\b/iu.test(value)))\n mark(\"commercial\", \"comparison_heading\");\n if (headingText.some((value) => /\\b(?:pricing|prices|price|plans|costs)\\b/iu.test(value)))\n mark(\"commercial\", \"pricing_heading\");\n if (headingText.some((value) => /\\b(?:contact|locations|find us|get in touch|directions)\\b/iu.test(value)))\n mark(\"navigational\", \"contact_heading\");\n const paragraphs = root.find(\"p\").toArray();\n if (paragraphs.length > MAX_ELEMENTS) truncated = true;\n const substantive = paragraphs.slice(0, MAX_ELEMENTS)\n .filter((node) => $(node).text().trim().length >= 80).length;\n if ((root.is(\"article\") || root.find(\"article\").length > 0) &&\n headings.length >= 2 && substantive >= 2) mark(\"informational\", \"editorial_sections\");\n const anchors = root.find(\"a[href]\").toArray();\n if (anchors.length > MAX_ELEMENTS) truncated = true;\n for (const anchor of anchors.slice(0, MAX_ELEMENTS)) {\n const href = ($(anchor).attr(\"href\") ?? \"\").toLowerCase().slice(0, 300);\n const label = $(anchor).text().replace(/\\s+/gu, \" \").trim().toLowerCase().slice(0, 100);\n if (/(?:^|[/#])(?:checkout|cart|basket|booking|reserve|order)(?:[-/?#]|$)/.test(href))\n mark(\"transactional\", \"checkout_link\");\n if (/\\b(?:buy now|add to cart|checkout|book now|reserve now|order now|purchase now)\\b/i.test(label))\n mark(\"transactional\", \"purchase_action\");\n if (/(?:^|[/#])contact(?:[-/?#]|$)/.test(href) && /\\b(?:contact|location|directions)\\b/.test(label))\n mark(\"navigational\", \"main_contact_link\");\n }\n const actions = root.find(\"button,input[type='submit'],input[type='button']\").toArray();\n if (actions.length > MAX_ELEMENTS) truncated = true;\n for (const action of actions.slice(0, MAX_ELEMENTS)) {\n const button = $(action);\n const label = (button.attr(\"value\") ?? button.text()).replace(/\\s+/gu, \" \")\n .trim().toLowerCase().slice(0, 100);\n if (/\\b(?:buy now|add to cart|checkout|book now|reserve now|order now|purchase now)\\b/i.test(label)) {\n mark(\"transactional\", \"purchase_action\");\n if (button.closest(\"form\").length) mark(\"transactional\", \"purchase_form\");\n }\n }\n if (root.find(\"address\").length) mark(\"navigational\", \"main_address\");\n return {\n url, title, h1, signals, eligible: true,\n extraction_limited: truncated, main_found: Boolean(main.length || article.length),\n };\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { MainContentObservation } from "./same-language-duplicates.js";
2
+ /**
3
+ * Inspect the static HTML supplied by the caller. This never executes scripts,
4
+ * infers language from the URL, follows links or reads assets.
5
+ */
6
+ export declare function observeMainContent(html: string, url: string): MainContentObservation;
@@ -0,0 +1,33 @@
1
+ import * as cheerio from "cheerio";
2
+ import { MAIN_CONTENT_BLOCK_SELECTORS, MAIN_CONTENT_EXCLUDED_SELECTORS } from "./same-language-duplicates.js";
3
+ /**
4
+ * Inspect the static HTML supplied by the caller. This never executes scripts,
5
+ * infers language from the URL, follows links or reads assets.
6
+ */
7
+ export function observeMainContent(html, url) {
8
+ const $ = cheerio.load(html);
9
+ const language = $("html").first().attr("lang")?.trim();
10
+ // parse5 stores <template> contents in a document fragment, so a CSS
11
+ // parent/ancestor filter alone is not sufficient to reject inert <main>.
12
+ $("template").remove();
13
+ const main = $("main,[role='main']").filter((_, element) => $(element).parents("template").length === 0).first();
14
+ const article = $("article").filter((_, element) => $(element).parents("template").length === 0).first();
15
+ const body = $("body").first();
16
+ const root = main.length ? main : article.length ? article : body;
17
+ const source = main.length ? "main" : article.length ? "article" : body.length ? "body_fallback" : "missing";
18
+ if (!root.length)
19
+ return { url, language, source: "missing", text: "" };
20
+ root.find(MAIN_CONTENT_EXCLUDED_SELECTORS).remove();
21
+ const blocks = root.find("p,li,blockquote,pre").filter((_, element) => $(element).parents("p,li,blockquote,pre").length === 0).toArray()
22
+ .map((element) => $(element).text().replace(/\s+/gu, " ").trim())
23
+ .filter(Boolean);
24
+ root.find(MAIN_CONTENT_BLOCK_SELECTORS).each((_, element) => {
25
+ $(element).before(" ");
26
+ $(element).after(" ");
27
+ });
28
+ return {
29
+ url, language, source, text: root.text(),
30
+ blocks: blocks.slice(0, 240), blocksTruncated: blocks.length > 240,
31
+ };
32
+ }
33
+ //# sourceMappingURL=extract-main-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-main-content.js","sourceRoot":"","sources":["../../../src/modules/content-schema/extract-main-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,4BAA4B,EAAE,+BAA+B,EAAE,MAAM,+BAA+B,CAAC;AAG9G;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,GAAW;IAC1D,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI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AG,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,CACpE,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE;SAChE,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;SAChE,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,IAAI,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE;QAC1D,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;IACH,OAAO;QACL,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;QACxC,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,MAAM,GAAG,GAAG;KACnE,CAAC;AACJ,CAAC","sourcesContent":["import * as cheerio from \"cheerio\";\nimport { MAIN_CONTENT_BLOCK_SELECTORS, MAIN_CONTENT_EXCLUDED_SELECTORS } from \"./same-language-duplicates.js\";\nimport type { MainContentObservation, MainContentSource } from \"./same-language-duplicates.js\";\n\n/**\n * Inspect the static HTML supplied by the caller. This never executes scripts,\n * infers language from the URL, follows links or reads assets.\n */\nexport function observeMainContent(html: string, url: string): MainContentObservation {\n const $ = cheerio.load(html);\n const language = $(\"html\").first().attr(\"lang\")?.trim();\n // parse5 stores <template> contents in a document fragment, so a CSS\n // parent/ancestor filter alone is not sufficient to reject inert <main>.\n $(\"template\").remove();\n const main = $(\"main,[role='main']\").filter((_, element) => $(element).parents(\"template\").length === 0).first();\n const article = $(\"article\").filter((_, element) => $(element).parents(\"template\").length === 0).first();\n const body = $(\"body\").first();\n const root = main.length ? main : article.length ? article : body;\n const source: MainContentSource = main.length ? \"main\" : article.length ? \"article\" : body.length ? \"body_fallback\" : \"missing\";\n if (!root.length) return { url, language, source: \"missing\", text: \"\" };\n root.find(MAIN_CONTENT_EXCLUDED_SELECTORS).remove();\n const blocks = root.find(\"p,li,blockquote,pre\").filter((_, element) =>\n $(element).parents(\"p,li,blockquote,pre\").length === 0).toArray()\n .map((element) => $(element).text().replace(/\\s+/gu, \" \").trim())\n .filter(Boolean);\n root.find(MAIN_CONTENT_BLOCK_SELECTORS).each((_, element) => {\n $(element).before(\" \");\n $(element).after(\" \");\n });\n return {\n url, language, source, text: root.text(),\n blocks: blocks.slice(0, 240), blocksTruncated: blocks.length > 240,\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { type MetadataObservation } from "./metadata-consistency.js";
2
+ /** Static in-memory HTML parsing only; no page, URL, or social endpoint fetch. */
3
+ export declare function observeMetadata(html: string, rawUrl: string): MetadataObservation;
@@ -0,0 +1,62 @@
1
+ import * as cheerio from "cheerio";
2
+ import { METADATA_FIELDS, MAX_METADATA_HTML_BYTES, MAX_METADATA_VALUES, safeMetadataLabel, } from "./metadata-consistency.js";
3
+ /** Static in-memory HTML parsing only; no page, URL, or social endpoint fetch. */
4
+ export function observeMetadata(html, rawUrl) {
5
+ const url = safeMetadataLabel(rawUrl) ?? "";
6
+ const values = Object.fromEntries(METADATA_FIELDS.map((field) => [field, []]));
7
+ const result = {
8
+ url, values, excluded_canonicals: 0, extraction_limited: false,
9
+ };
10
+ if (!url || !html || new TextEncoder().encode(html).byteLength > MAX_METADATA_HTML_BYTES) {
11
+ return { ...result, extraction_limited: true };
12
+ }
13
+ const $ = cheerio.load(html);
14
+ function push(field, value) {
15
+ const clean = value.replace(/\s+/gu, " ").trim();
16
+ const max = field === "canonical" || field === "og:url" ? 1024 : 320;
17
+ if (clean.length > max) {
18
+ result.extraction_limited = true;
19
+ return;
20
+ }
21
+ if (values[field].length < MAX_METADATA_VALUES)
22
+ values[field].push(clean);
23
+ else
24
+ result.extraction_limited = true;
25
+ }
26
+ $("head > title").each((_, element) => push("title", $(element).text()));
27
+ $("head > meta").each((_, element) => {
28
+ const meta = $(element);
29
+ const name = (meta.attr("name") ?? "").trim().toLowerCase();
30
+ const property = (meta.attr("property") ?? "").trim().toLowerCase();
31
+ const content = meta.attr("content") ?? "";
32
+ if (name === "description" || name === "twitter:title" || name === "twitter:description") {
33
+ push(name, content);
34
+ }
35
+ if (property === "og:title" || property === "og:description" || property === "og:url") {
36
+ push(property, content);
37
+ }
38
+ if (name === "robots" || name === "googlebot")
39
+ push(name, content);
40
+ });
41
+ // Explicit robots declarations in the body may be noticed by Google;
42
+ // these are source observations, not verified crawl directives.
43
+ $("body meta[name]").each((_, element) => {
44
+ const name = ($(element).attr("name") ?? "").trim().toLowerCase();
45
+ if (name === "robots" || name === "googlebot")
46
+ push(name, $(element).attr("content") ?? "");
47
+ });
48
+ $("head > link[rel]").each((_, element) => {
49
+ const item = $(element);
50
+ const rel = (item.attr("rel") ?? "").toLowerCase().split(/\s+/u);
51
+ if (!rel.includes("canonical"))
52
+ return;
53
+ if (["hreflang", "media", "type", "lang"].some((key) => item.attr(key) !== undefined)) {
54
+ result.excluded_canonicals += 1;
55
+ return;
56
+ }
57
+ push("canonical", item.attr("href") ?? "");
58
+ });
59
+ result.base_href = $("head > base[href]").first().attr("href");
60
+ return result;
61
+ }
62
+ //# sourceMappingURL=extract-metadata-consistency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract-metadata-consistency.js","sourceRoot":"","sources":["../../../src/modules/content-schema/extract-metadata-consistency.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC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AAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import * as cheerio from \"cheerio\";\nimport {\n METADATA_FIELDS,\n MAX_METADATA_HTML_BYTES,\n MAX_METADATA_VALUES,\n safeMetadataLabel,\n type MetadataField,\n type MetadataObservation,\n} from \"./metadata-consistency.js\";\n\n/** Static in-memory HTML parsing only; no page, URL, or social endpoint fetch. */\nexport function observeMetadata(html: string, rawUrl: string): MetadataObservation {\n const url = safeMetadataLabel(rawUrl) ?? \"\";\n const values = Object.fromEntries(\n METADATA_FIELDS.map((field) => [field, [] as string[]]),\n ) as Record<MetadataField, string[]>;\n const result: MetadataObservation = {\n url, values, excluded_canonicals: 0, extraction_limited: false,\n };\n if (!url || !html || new TextEncoder().encode(html).byteLength > MAX_METADATA_HTML_BYTES) {\n return { ...result, extraction_limited: true };\n }\n const $ = cheerio.load(html);\n function push(field: MetadataField, value: string) {\n const clean = value.replace(/\\s+/gu, \" \").trim();\n const max = field === \"canonical\" || field === \"og:url\" ? 1024 : 320;\n if (clean.length > max) {\n result.extraction_limited = true;\n return;\n }\n if (values[field].length < MAX_METADATA_VALUES) values[field].push(clean);\n else result.extraction_limited = true;\n }\n $(\"head > title\").each((_, element) => push(\"title\", $(element).text()));\n $(\"head > meta\").each((_, element) => {\n const meta = $(element);\n const name = (meta.attr(\"name\") ?? \"\").trim().toLowerCase();\n const property = (meta.attr(\"property\") ?? \"\").trim().toLowerCase();\n const content = meta.attr(\"content\") ?? \"\";\n if (name === \"description\" || name === \"twitter:title\" || name === \"twitter:description\") {\n push(name, content);\n }\n if (property === \"og:title\" || property === \"og:description\" || property === \"og:url\") {\n push(property, content);\n }\n if (name === \"robots\" || name === \"googlebot\") push(name, content);\n });\n // Explicit robots declarations in the body may be noticed by Google;\n // these are source observations, not verified crawl directives.\n $(\"body meta[name]\").each((_, element) => {\n const name = ($(element).attr(\"name\") ?? \"\").trim().toLowerCase();\n if (name === \"robots\" || name === \"googlebot\") push(name, $(element).attr(\"content\") ?? \"\");\n });\n $(\"head > link[rel]\").each((_, element) => {\n const item = $(element);\n const rel = (item.attr(\"rel\") ?? \"\").toLowerCase().split(/\\s+/u);\n if (!rel.includes(\"canonical\")) return;\n if ([\"hreflang\", \"media\", \"type\", \"lang\"].some((key) => item.attr(key) !== undefined)) {\n result.excluded_canonicals += 1;\n return;\n }\n push(\"canonical\", item.attr(\"href\") ?? \"\");\n });\n result.base_href = $(\"head > base[href]\").first().attr(\"href\");\n return result;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { type ProductClaimObservation } from "./product-claims.js";
2
+ /** Static, visible main-content promises only; scripts and nav never execute. */
3
+ export declare function observeProductClaims(html: string): ProductClaimObservation;
@@ -0,0 +1,58 @@
1
+ import * as cheerio from "cheerio";
2
+ import { isPublicToolName, MAX_PRODUCT_CLAIM_HTML_BYTES, MAX_PRODUCT_CLAIM_TOOLS, } from "./product-claims.js";
3
+ /** Static, visible main-content promises only; scripts and nav never execute. */
4
+ export function observeProductClaims(html) {
5
+ if (!html || Buffer.byteLength(html, "utf8") > MAX_PRODUCT_CLAIM_HTML_BYTES) {
6
+ throw new Error("Landing HTML must be present and at most 250,000 UTF-8 bytes.");
7
+ }
8
+ const $ = cheerio.load(html);
9
+ $("template,script,style,noscript,nav,header,footer,aside,[hidden],[aria-hidden='true']").remove();
10
+ const main = $("main").first();
11
+ const root = main.length ? main : $("body").first();
12
+ const headings = root.find("h2,h3").toArray();
13
+ function findToolList(term) {
14
+ const heading = headings.find((node) => term.test($(node).text().trim()));
15
+ if (!heading)
16
+ return { found: false, tools: [], truncated: false };
17
+ const section = $(heading).closest("section");
18
+ const container = section.length ? section : $(heading).parent();
19
+ const all = container.find("code,[data-mcp-tool]").toArray()
20
+ .filter((node) => $(node).closest("pre").length === 0)
21
+ .map((node) => $(node).attr("data-mcp-tool")?.trim() || $(node).text().trim())
22
+ .filter((text) => isPublicToolName(text));
23
+ return {
24
+ found: true,
25
+ tools: [...new Set(all)].slice(0, MAX_PRODUCT_CLAIM_TOOLS),
26
+ truncated: [...new Set(all)].length > MAX_PRODUCT_CLAIM_TOOLS,
27
+ };
28
+ }
29
+ const hosted = findToolList(/(?:public chatgpt capabilities|hosted(?: mcp)? tools|chatgpt tool list)/i);
30
+ const local = findToolList(/(?:local(?: mcp)? capabilities|local(?: mcp)? tools)/i);
31
+ // Use explicit short on-page statements rather than guessing from unrelated
32
+ // marketing/nav/footer content or claiming all sales prose was analyzed.
33
+ const paragraphs = root.find("p,li").toArray().slice(0, 220)
34
+ .map((node) => $(node).text().replace(/\s+/gu, " ").trim().toLowerCase())
35
+ .filter((text) => text.length > 0 && text.length <= 2000);
36
+ const body = root.text().replace(/\s+/gu, " ").slice(0, 70_000);
37
+ // Cheerio concatenates adjacent block elements without inserted whitespace.
38
+ const siteLimit = /site\s*batch\s*up\s*to\s*(\d{1,12})\s*pages/i.exec(body);
39
+ const number = siteLimit ? Number(siteLimit[1]) : undefined;
40
+ return {
41
+ hasMain: main.length > 0,
42
+ hostedSectionFound: hosted.found,
43
+ localSectionFound: local.found,
44
+ hostedTools: hosted.tools,
45
+ localTools: local.tools,
46
+ ...(number && Number.isSafeInteger(number) ? { siteBatchLimit: number } : {}),
47
+ localScreenshotClaim: paragraphs.some((p) => /\blocal\b/.test(p) &&
48
+ /(?:screenshots?|screen captures?)/.test(p) &&
49
+ !/(?:local[^\n]{0,80}(?:cannot|does not|doesn't)[^\n]{0,80}screenshot)/.test(p)),
50
+ hostedReadOnlyClaim: paragraphs.some((p) => /\bhosted\b/.test(p) &&
51
+ /\bread.only\b/.test(p)),
52
+ hostedNoScreenshotsClaim: paragraphs.some((p) => /\bhosted\b/.test(p) &&
53
+ /(?:cannot|does not|doesn't|no)\b/.test(p) && /\bscreenshots?\b/.test(p)),
54
+ extractionTruncated: hosted.truncated || local.truncated || root.find("p,li").length > 220 ||
55
+ body.length >= 70_000,
56
+ };
57
+ }
58
+ //# sourceMappingURL=extract-product-claims.js.map