@rebilder/agent-readability 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +860 -5
- package/dist/index.d.cts +276 -3
- package/dist/index.d.ts +276 -3
- package/dist/index.js +847 -6
- package/dist/index.js.map +1 -1
- package/dist/probe/index.cjs +112 -10
- package/dist/probe/index.d.cts +2 -2
- package/dist/probe/index.d.ts +2 -2
- package/dist/probe/index.js +112 -10
- package/dist/probe/index.js.map +1 -1
- package/dist/probe/local.cjs +112 -10
- package/dist/probe/local.d.cts +1 -1
- package/dist/probe/local.d.ts +1 -1
- package/dist/probe/local.js +112 -10
- package/dist/probe/local.js.map +1 -1
- package/dist/{robots-policy-BeffrTf0.d.cts → robots-policy-C7cfPpu2.d.cts} +1 -1
- package/dist/{robots-policy-BeffrTf0.d.ts → robots-policy-C7cfPpu2.d.ts} +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -752,10 +752,9 @@ function parseStartTag(html, start) {
|
|
|
752
752
|
}
|
|
753
753
|
return { tag, attrs, selfClosing, end: i };
|
|
754
754
|
}
|
|
755
|
-
function findRawTextEnd(
|
|
755
|
+
function findRawTextEnd(lowerHtml, from, tag) {
|
|
756
756
|
const needle = `</${tag}`;
|
|
757
|
-
const
|
|
758
|
-
const at = lower.indexOf(needle, from);
|
|
757
|
+
const at = lowerHtml.indexOf(needle, from);
|
|
759
758
|
return at === -1 ? -1 : at;
|
|
760
759
|
}
|
|
761
760
|
function ownExclusion(tag, attrs) {
|
|
@@ -819,6 +818,7 @@ function tokenizeHtml(html) {
|
|
|
819
818
|
};
|
|
820
819
|
let i = 0;
|
|
821
820
|
let textStart = 0;
|
|
821
|
+
let lowerHtml = null;
|
|
822
822
|
while (i < html.length) {
|
|
823
823
|
const lt = html.indexOf("<", i);
|
|
824
824
|
if (lt === -1) break;
|
|
@@ -870,7 +870,8 @@ function tokenizeHtml(html) {
|
|
|
870
870
|
const isRcdata = RCDATA_ELEMENTS.has(parsed.tag);
|
|
871
871
|
if (isRawText || isRcdata) {
|
|
872
872
|
const contentStart = i;
|
|
873
|
-
|
|
873
|
+
lowerHtml ??= html.toLowerCase();
|
|
874
|
+
const close = findRawTextEnd(lowerHtml, contentStart, parsed.tag);
|
|
874
875
|
const contentEnd = close === -1 ? html.length : close;
|
|
875
876
|
if (contentEnd > contentStart) {
|
|
876
877
|
const wasTop = stack.length;
|
|
@@ -2394,7 +2395,10 @@ function parseRobots(text) {
|
|
|
2394
2395
|
else current.disallow.push(value);
|
|
2395
2396
|
continue;
|
|
2396
2397
|
}
|
|
2397
|
-
if (field === "crawl-delay" || field === "host" || field === "clean-param")
|
|
2398
|
+
if (field === "crawl-delay" || field === "host" || field === "clean-param" || field === "content-signal") {
|
|
2399
|
+
if (field === "content-signal" && current !== null) openingGroup = false;
|
|
2400
|
+
continue;
|
|
2401
|
+
}
|
|
2398
2402
|
malformedLines++;
|
|
2399
2403
|
}
|
|
2400
2404
|
return { groups, sitemaps, malformedLines, orphanRules };
|
|
@@ -4944,6 +4948,843 @@ function robotsDisallowsScanner(robotsBody, path) {
|
|
|
4944
4948
|
return null;
|
|
4945
4949
|
}
|
|
4946
4950
|
|
|
4951
|
+
// src/site-signals.ts
|
|
4952
|
+
var EDGE_CHALLENGE_VENDOR_LABEL = {
|
|
4953
|
+
cloudflare: "Cloudflare",
|
|
4954
|
+
vercel: "Vercel",
|
|
4955
|
+
datadome: "DataDome",
|
|
4956
|
+
human: "HUMAN"
|
|
4957
|
+
};
|
|
4958
|
+
var BODY_SCAN_CHARS = 256 * 1024;
|
|
4959
|
+
function headerValues(input, name) {
|
|
4960
|
+
const direct = input.headers[name];
|
|
4961
|
+
if (direct !== void 0) return direct.map((value) => value.toLowerCase());
|
|
4962
|
+
const target = name.toLowerCase();
|
|
4963
|
+
const out = [];
|
|
4964
|
+
for (const [key, values] of Object.entries(input.headers)) {
|
|
4965
|
+
if (key.toLowerCase() === target) {
|
|
4966
|
+
for (const value of values) out.push(value.toLowerCase());
|
|
4967
|
+
}
|
|
4968
|
+
}
|
|
4969
|
+
return out;
|
|
4970
|
+
}
|
|
4971
|
+
function hasToken(values, token) {
|
|
4972
|
+
return values.some(
|
|
4973
|
+
(value) => value.split(",").map((part) => part.trim()).includes(token)
|
|
4974
|
+
);
|
|
4975
|
+
}
|
|
4976
|
+
function isRobotsTxtTarget(input) {
|
|
4977
|
+
for (const raw of [input.requestedUrl, input.finalUrl]) {
|
|
4978
|
+
if (typeof raw !== "string" || raw.length === 0) continue;
|
|
4979
|
+
try {
|
|
4980
|
+
if (new URL(raw).pathname.toLowerCase() === "/robots.txt") return true;
|
|
4981
|
+
} catch {
|
|
4982
|
+
const path = (raw.split("#")[0]?.split("?")[0] ?? "").toLowerCase();
|
|
4983
|
+
if (path === "/robots.txt" || path.endsWith("/robots.txt")) return true;
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
return false;
|
|
4987
|
+
}
|
|
4988
|
+
function detectEdgeChallenge(input) {
|
|
4989
|
+
const status = input.status;
|
|
4990
|
+
const body = typeof input.body === "string" ? input.body.slice(0, BODY_SCAN_CHARS) : "";
|
|
4991
|
+
const server = headerValues(input, "server");
|
|
4992
|
+
const contentTypes = headerValues(input, "content-type");
|
|
4993
|
+
const isHtmlContent = contentTypes.some(
|
|
4994
|
+
(value) => value.includes("text/html") || value.includes("application/xhtml+xml")
|
|
4995
|
+
);
|
|
4996
|
+
const lowerBodyHead = body.slice(0, 4096).toLowerCase();
|
|
4997
|
+
const isPlainTextWithoutMarkup = contentTypes.some((value) => value.includes("text/plain")) && !lowerBodyHead.includes("<html") && !lowerBodyHead.includes("<script") && !lowerBodyHead.includes("<!doctype html");
|
|
4998
|
+
const isRobotsHtmlChallenge = isRobotsTxtTarget(input) && isHtmlContent;
|
|
4999
|
+
if (hasToken(headerValues(input, "cf-mitigated"), "challenge")) {
|
|
5000
|
+
return { vendor: "cloudflare", signal: "cf-mitigated: challenge", status };
|
|
5001
|
+
}
|
|
5002
|
+
if ((status === 403 || status === 429 || status === 503 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && server.some((value) => value.includes("cloudflare")) && body.includes("/cdn-cgi/challenge-platform/")) {
|
|
5003
|
+
return { vendor: "cloudflare", signal: "Cloudflare challenge page", status };
|
|
5004
|
+
}
|
|
5005
|
+
if (hasToken(headerValues(input, "x-vercel-mitigated"), "challenge")) {
|
|
5006
|
+
return { vendor: "vercel", signal: "x-vercel-mitigated: challenge", status };
|
|
5007
|
+
}
|
|
5008
|
+
if ((status < 200 || status >= 300 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && server.some((value) => value.includes("vercel")) && body.includes("Vercel Security Checkpoint")) {
|
|
5009
|
+
return { vendor: "vercel", signal: "Vercel Security Checkpoint page", status };
|
|
5010
|
+
}
|
|
5011
|
+
if ((status === 401 || status === 403) && headerValues(input, "x-datadome").length > 0) {
|
|
5012
|
+
return { vendor: "datadome", signal: `x-datadome with HTTP ${status}`, status };
|
|
5013
|
+
}
|
|
5014
|
+
if ((status === 403 || status === 429 || isRobotsHtmlChallenge && status === 200) && !isPlainTextWithoutMarkup && body.includes("px-captcha") && body.includes("_pxAppId")) {
|
|
5015
|
+
return { vendor: "human", signal: "HUMAN block page", status };
|
|
5016
|
+
}
|
|
5017
|
+
return null;
|
|
5018
|
+
}
|
|
5019
|
+
var DETAIL_PREFIX = "edge-challenge";
|
|
5020
|
+
var DETAIL_PATTERN = /^edge-challenge; vendor=([a-z]+); status=(\d{3}); signal=(.{1,120})$/;
|
|
5021
|
+
function challengeDetail(challenge) {
|
|
5022
|
+
return `${DETAIL_PREFIX}; vendor=${challenge.vendor}; status=${challenge.status}; signal=${challenge.signal.slice(0, 120)}`;
|
|
5023
|
+
}
|
|
5024
|
+
function parseChallengeDetail(detail) {
|
|
5025
|
+
if (typeof detail !== "string") return null;
|
|
5026
|
+
const match = DETAIL_PATTERN.exec(detail);
|
|
5027
|
+
if (match === null) return null;
|
|
5028
|
+
const vendor = match[1];
|
|
5029
|
+
if (!(vendor in EDGE_CHALLENGE_VENDOR_LABEL)) return null;
|
|
5030
|
+
return { vendor, status: Number(match[2]), signal: match[3] ?? "" };
|
|
5031
|
+
}
|
|
5032
|
+
function edgeChallengeOf(evidence) {
|
|
5033
|
+
if (typeof evidence !== "object" || evidence === null) return null;
|
|
5034
|
+
const agent = evidence.probes?.agent?.result;
|
|
5035
|
+
if (typeof agent !== "object" || agent === null) return null;
|
|
5036
|
+
const result = agent;
|
|
5037
|
+
if (result.ok !== false || result.error !== "challenge") return null;
|
|
5038
|
+
return parseChallengeDetail(result.detail);
|
|
5039
|
+
}
|
|
5040
|
+
function robotsEdgeChallengeOf(evidence) {
|
|
5041
|
+
if (typeof evidence !== "object" || evidence === null) return null;
|
|
5042
|
+
const robots = evidence.probes?.robotsTxt?.result;
|
|
5043
|
+
if (typeof robots !== "object" || robots === null) return null;
|
|
5044
|
+
const result = robots;
|
|
5045
|
+
if (result.ok === false && result.error === "challenge") {
|
|
5046
|
+
return parseChallengeDetail(result.detail);
|
|
5047
|
+
}
|
|
5048
|
+
if (result.ok === true && result.capture !== void 0 && typeof result.capture === "object") {
|
|
5049
|
+
return detectEdgeChallenge(result.capture);
|
|
5050
|
+
}
|
|
5051
|
+
return null;
|
|
5052
|
+
}
|
|
5053
|
+
var CLOUDFLARE_MANAGED_MARKER = "# begin cloudflare managed content";
|
|
5054
|
+
function parseContentSignals(robotsTxt) {
|
|
5055
|
+
let cloudflareManaged = false;
|
|
5056
|
+
const rules = [];
|
|
5057
|
+
let currentAgents = [];
|
|
5058
|
+
let openingGroup = false;
|
|
5059
|
+
for (const rawLine of robotsTxt.split(/\r?\n/)) {
|
|
5060
|
+
const trimmedRaw = rawLine.trim();
|
|
5061
|
+
if (trimmedRaw.toLowerCase().includes(CLOUDFLARE_MANAGED_MARKER)) {
|
|
5062
|
+
cloudflareManaged = true;
|
|
5063
|
+
}
|
|
5064
|
+
const withoutComment = rawLine.split("#")[0] ?? "";
|
|
5065
|
+
const line = withoutComment.trim();
|
|
5066
|
+
if (line.length === 0) continue;
|
|
5067
|
+
const colon = line.indexOf(":");
|
|
5068
|
+
if (colon <= 0) continue;
|
|
5069
|
+
const field = line.slice(0, colon).trim().toLowerCase();
|
|
5070
|
+
const value = line.slice(colon + 1).trim();
|
|
5071
|
+
if (field === "user-agent") {
|
|
5072
|
+
if (!openingGroup) {
|
|
5073
|
+
currentAgents = [];
|
|
5074
|
+
openingGroup = true;
|
|
5075
|
+
}
|
|
5076
|
+
if (value.length > 0) currentAgents.push(value.toLowerCase());
|
|
5077
|
+
continue;
|
|
5078
|
+
}
|
|
5079
|
+
if (field === "allow" || field === "disallow") {
|
|
5080
|
+
openingGroup = false;
|
|
5081
|
+
continue;
|
|
5082
|
+
}
|
|
5083
|
+
if (field === "content-signal") {
|
|
5084
|
+
if (currentAgents.length > 0) openingGroup = false;
|
|
5085
|
+
const parsed = {};
|
|
5086
|
+
for (const part of value.split(",")) {
|
|
5087
|
+
const eq = part.indexOf("=");
|
|
5088
|
+
if (eq <= 0) continue;
|
|
5089
|
+
const key = part.slice(0, eq).trim().toLowerCase();
|
|
5090
|
+
const val = part.slice(eq + 1).trim().toLowerCase();
|
|
5091
|
+
if (key.length > 0 && val.length > 0) {
|
|
5092
|
+
parsed[key] = val;
|
|
5093
|
+
}
|
|
5094
|
+
}
|
|
5095
|
+
rules.push({
|
|
5096
|
+
agents: [...currentAgents],
|
|
5097
|
+
raw: value,
|
|
5098
|
+
signals: parsed
|
|
5099
|
+
});
|
|
5100
|
+
}
|
|
5101
|
+
}
|
|
5102
|
+
let search = null;
|
|
5103
|
+
let aiInput = null;
|
|
5104
|
+
let aiTrain = null;
|
|
5105
|
+
const wildcardRules = rules.filter((rule) => rule.agents.includes("*"));
|
|
5106
|
+
const summarySource = wildcardRules.length > 0 ? wildcardRules : rules.filter((rule) => rule.agents.length === 0);
|
|
5107
|
+
for (const rule of summarySource) {
|
|
5108
|
+
if (rule.signals["search"] !== void 0) search = rule.signals["search"];
|
|
5109
|
+
if (rule.signals["ai-input"] !== void 0) aiInput = rule.signals["ai-input"];
|
|
5110
|
+
if (rule.signals["ai-train"] !== void 0) aiTrain = rule.signals["ai-train"];
|
|
5111
|
+
}
|
|
5112
|
+
return {
|
|
5113
|
+
present: rules.length > 0,
|
|
5114
|
+
cloudflareManaged,
|
|
5115
|
+
rules,
|
|
5116
|
+
summary: { search, aiInput, aiTrain }
|
|
5117
|
+
};
|
|
5118
|
+
}
|
|
5119
|
+
var ROBOTS_DIRECTIVES = /* @__PURE__ */ new Set([
|
|
5120
|
+
"all",
|
|
5121
|
+
"noindex",
|
|
5122
|
+
"nofollow",
|
|
5123
|
+
"none",
|
|
5124
|
+
"noarchive",
|
|
5125
|
+
"nosnippet",
|
|
5126
|
+
"notranslate",
|
|
5127
|
+
"noimageindex",
|
|
5128
|
+
"unavailable_after",
|
|
5129
|
+
"max-snippet",
|
|
5130
|
+
"max-image-preview",
|
|
5131
|
+
"max-video-preview",
|
|
5132
|
+
"indexifembedded",
|
|
5133
|
+
"noai",
|
|
5134
|
+
"noimageai"
|
|
5135
|
+
]);
|
|
5136
|
+
var AGENT_META_NAMES = new Set(
|
|
5137
|
+
[
|
|
5138
|
+
...DEFAULT_RULESET.audienceTokens.assistant,
|
|
5139
|
+
...DEFAULT_RULESET.audienceTokens.training,
|
|
5140
|
+
...DEFAULT_RULESET.audienceTokens.search,
|
|
5141
|
+
"googlebot",
|
|
5142
|
+
"bingbot"
|
|
5143
|
+
].map((token) => token.toLowerCase())
|
|
5144
|
+
);
|
|
5145
|
+
function splitRobotTokens(directives) {
|
|
5146
|
+
return directives.toLowerCase().split(",").map((part) => part.trim()).filter((part) => part.length > 0);
|
|
5147
|
+
}
|
|
5148
|
+
function blocksIndexing(directives) {
|
|
5149
|
+
return splitRobotTokens(directives).some((part) => part === "noindex" || part === "none");
|
|
5150
|
+
}
|
|
5151
|
+
function extractRestrictions(directives) {
|
|
5152
|
+
const found = [];
|
|
5153
|
+
for (const part of splitRobotTokens(directives)) {
|
|
5154
|
+
if (part === "nosnippet") found.push("nosnippet");
|
|
5155
|
+
else if (/^max-snippet\s*:\s*0$/.test(part)) found.push("max-snippet:0");
|
|
5156
|
+
else if (part === "noai") found.push("noai");
|
|
5157
|
+
else if (part === "noimageai") found.push("noimageai");
|
|
5158
|
+
}
|
|
5159
|
+
return found;
|
|
5160
|
+
}
|
|
5161
|
+
function parseHeaderRobots(values) {
|
|
5162
|
+
const noindex = [];
|
|
5163
|
+
const restrictions = [];
|
|
5164
|
+
for (const value of values) {
|
|
5165
|
+
const trimmed = value.trim();
|
|
5166
|
+
const prefixed = /^\s*([A-Za-z0-9_.-]+)\s*:\s*(.*)$/.exec(value);
|
|
5167
|
+
const prefix = prefixed?.[1]?.toLowerCase();
|
|
5168
|
+
let agent = "robots";
|
|
5169
|
+
let directiveBody = value;
|
|
5170
|
+
if (prefixed !== null && prefix !== void 0 && !ROBOTS_DIRECTIVES.has(prefix)) {
|
|
5171
|
+
agent = prefix;
|
|
5172
|
+
directiveBody = prefixed[2] ?? "";
|
|
5173
|
+
}
|
|
5174
|
+
if (blocksIndexing(directiveBody)) {
|
|
5175
|
+
noindex.push({ agent, source: "header", value: trimmed });
|
|
5176
|
+
}
|
|
5177
|
+
for (const directive of extractRestrictions(directiveBody)) {
|
|
5178
|
+
restrictions.push({ agent, source: "header", directive, value: trimmed });
|
|
5179
|
+
}
|
|
5180
|
+
}
|
|
5181
|
+
return { noindex, restrictions };
|
|
5182
|
+
}
|
|
5183
|
+
function summarizeCanonicals(canonicals) {
|
|
5184
|
+
let htmlCount = 0;
|
|
5185
|
+
let headerCount = 0;
|
|
5186
|
+
const distinct = /* @__PURE__ */ new Set();
|
|
5187
|
+
for (const entry of canonicals) {
|
|
5188
|
+
if (entry.source === "html") htmlCount++;
|
|
5189
|
+
else headerCount++;
|
|
5190
|
+
distinct.add(entry.url);
|
|
5191
|
+
}
|
|
5192
|
+
return {
|
|
5193
|
+
duplicateCanonical: htmlCount > 1 || headerCount > 1,
|
|
5194
|
+
conflictingCanonical: distinct.size > 1
|
|
5195
|
+
};
|
|
5196
|
+
}
|
|
5197
|
+
function indexSignalsOf(capture) {
|
|
5198
|
+
const parsedHeaders = parseHeaderRobots(headerAll(capture.headers, "x-robots-tag"));
|
|
5199
|
+
const noindex = [...parsedHeaders.noindex];
|
|
5200
|
+
const restrictions = [...parsedHeaders.restrictions];
|
|
5201
|
+
const canonicals = [];
|
|
5202
|
+
let canonical = null;
|
|
5203
|
+
for (const link of parseLinkHeaders(headerAll(capture.headers, "link"))) {
|
|
5204
|
+
if (link.rel.includes("canonical")) {
|
|
5205
|
+
const resolved = absoluteUrl(link.url, capture.finalUrl);
|
|
5206
|
+
if (resolved !== null) {
|
|
5207
|
+
canonicals.push({ source: "header", url: resolved });
|
|
5208
|
+
if (canonical === null) canonical = resolved;
|
|
5209
|
+
}
|
|
5210
|
+
}
|
|
5211
|
+
}
|
|
5212
|
+
const representation = buildRepresentation(capture);
|
|
5213
|
+
const doc = representation?.doc ?? null;
|
|
5214
|
+
if (doc !== null) {
|
|
5215
|
+
for (const meta of doc.metas) {
|
|
5216
|
+
const name = meta.name;
|
|
5217
|
+
if (name === null || meta.content === null) continue;
|
|
5218
|
+
const targetAgent = name === "robots" ? "robots" : AGENT_META_NAMES.has(name) ? name : null;
|
|
5219
|
+
if (targetAgent === null) continue;
|
|
5220
|
+
if (blocksIndexing(meta.content)) {
|
|
5221
|
+
noindex.push({ agent: targetAgent, source: "meta", value: meta.content });
|
|
5222
|
+
}
|
|
5223
|
+
for (const directive of extractRestrictions(meta.content)) {
|
|
5224
|
+
restrictions.push({
|
|
5225
|
+
agent: targetAgent,
|
|
5226
|
+
source: "meta",
|
|
5227
|
+
directive,
|
|
5228
|
+
value: meta.content
|
|
5229
|
+
});
|
|
5230
|
+
}
|
|
5231
|
+
}
|
|
5232
|
+
for (const link of doc.links) {
|
|
5233
|
+
if (link.rel.includes("canonical") && link.href !== null) {
|
|
5234
|
+
const resolved = absoluteUrl(link.href, capture.finalUrl);
|
|
5235
|
+
if (resolved !== null) {
|
|
5236
|
+
canonicals.push({ source: "html", url: resolved });
|
|
5237
|
+
if (canonical === null) canonical = resolved;
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
5240
|
+
}
|
|
5241
|
+
}
|
|
5242
|
+
const { duplicateCanonical, conflictingCanonical } = summarizeCanonicals(canonicals);
|
|
5243
|
+
return {
|
|
5244
|
+
status: capture.status,
|
|
5245
|
+
finalUrl: capture.finalUrl,
|
|
5246
|
+
redirected: capture.redirects.length > 0,
|
|
5247
|
+
noindex,
|
|
5248
|
+
canonical,
|
|
5249
|
+
restrictions,
|
|
5250
|
+
nosnippet: restrictions.some((r) => r.directive === "nosnippet"),
|
|
5251
|
+
maxSnippetZero: restrictions.some((r) => r.directive === "max-snippet:0"),
|
|
5252
|
+
noai: restrictions.some((r) => r.directive === "noai"),
|
|
5253
|
+
noimageai: restrictions.some((r) => r.directive === "noimageai"),
|
|
5254
|
+
canonicals,
|
|
5255
|
+
duplicateCanonical,
|
|
5256
|
+
conflictingCanonical,
|
|
5257
|
+
payPerCrawl: capture.status === 402
|
|
5258
|
+
};
|
|
5259
|
+
}
|
|
5260
|
+
function pageIndexSignals(evidence) {
|
|
5261
|
+
const browser = evidence.probes.browser.result;
|
|
5262
|
+
const agent = evidence.probes.agent.result;
|
|
5263
|
+
const capture = browser.ok ? browser.capture : agent.ok ? agent.capture : null;
|
|
5264
|
+
if (capture === null) return null;
|
|
5265
|
+
const signals = indexSignalsOf(capture);
|
|
5266
|
+
if (browser.ok && agent.ok) {
|
|
5267
|
+
const agentRobots = parseHeaderRobots(headerAll(agent.capture.headers, "x-robots-tag"));
|
|
5268
|
+
const seenNoindex = new Set(signals.noindex.map((d) => `${d.agent}|${d.source}|${d.value}`));
|
|
5269
|
+
for (const directive of agentRobots.noindex) {
|
|
5270
|
+
const key = `${directive.agent}|${directive.source}|${directive.value}`;
|
|
5271
|
+
if (!seenNoindex.has(key)) {
|
|
5272
|
+
seenNoindex.add(key);
|
|
5273
|
+
signals.noindex.push(directive);
|
|
5274
|
+
}
|
|
5275
|
+
}
|
|
5276
|
+
const seenRestrictions = new Set(
|
|
5277
|
+
signals.restrictions.map((d) => `${d.agent}|${d.source}|${d.directive}|${d.value}`)
|
|
5278
|
+
);
|
|
5279
|
+
for (const directive of agentRobots.restrictions) {
|
|
5280
|
+
const key = `${directive.agent}|${directive.source}|${directive.directive}|${directive.value}`;
|
|
5281
|
+
if (!seenRestrictions.has(key)) {
|
|
5282
|
+
seenRestrictions.add(key);
|
|
5283
|
+
signals.restrictions.push(directive);
|
|
5284
|
+
}
|
|
5285
|
+
}
|
|
5286
|
+
signals.nosnippet = signals.restrictions.some((r) => r.directive === "nosnippet");
|
|
5287
|
+
signals.maxSnippetZero = signals.restrictions.some((r) => r.directive === "max-snippet:0");
|
|
5288
|
+
signals.noai = signals.restrictions.some((r) => r.directive === "noai");
|
|
5289
|
+
signals.noimageai = signals.restrictions.some((r) => r.directive === "noimageai");
|
|
5290
|
+
const seenCanonicals = new Set(signals.canonicals.map((c) => `${c.source}|${c.url}`));
|
|
5291
|
+
let canonicalsAdded = false;
|
|
5292
|
+
for (const link of parseLinkHeaders(headerAll(agent.capture.headers, "link"))) {
|
|
5293
|
+
if (!link.rel.includes("canonical")) continue;
|
|
5294
|
+
const resolved = absoluteUrl(link.url, agent.capture.finalUrl);
|
|
5295
|
+
if (resolved === null) continue;
|
|
5296
|
+
const key = `header|${resolved}`;
|
|
5297
|
+
if (!seenCanonicals.has(key)) {
|
|
5298
|
+
seenCanonicals.add(key);
|
|
5299
|
+
signals.canonicals.push({ source: "header", url: resolved });
|
|
5300
|
+
if (signals.canonical === null) signals.canonical = resolved;
|
|
5301
|
+
canonicalsAdded = true;
|
|
5302
|
+
}
|
|
5303
|
+
}
|
|
5304
|
+
if (canonicalsAdded) {
|
|
5305
|
+
const summary = summarizeCanonicals(signals.canonicals);
|
|
5306
|
+
signals.duplicateCanonical = summary.duplicateCanonical;
|
|
5307
|
+
signals.conflictingCanonical = summary.conflictingCanonical;
|
|
5308
|
+
}
|
|
5309
|
+
if (agent.capture.status === 402) {
|
|
5310
|
+
signals.payPerCrawl = true;
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
5313
|
+
return signals;
|
|
5314
|
+
}
|
|
5315
|
+
var SPA_MOUNT_ROOT_IDS = /* @__PURE__ */ new Set(["root", "app", "__next", "__nuxt"]);
|
|
5316
|
+
var NOSCRIPT_JS_PATTERNS = [
|
|
5317
|
+
/\benable\s+javascript\b/i,
|
|
5318
|
+
/\bjavascript\s+(?:is\s+required|must\s+be\s+enabled|is\s+disabled)\b/i,
|
|
5319
|
+
/\brequires?\s+javascript\b/i,
|
|
5320
|
+
/\bturn\s+on\s+javascript\b/i,
|
|
5321
|
+
/\bwithout\s+javascript\b/i,
|
|
5322
|
+
/\bdoes\s+not\s+support\s+javascript\b/i,
|
|
5323
|
+
/\bneed\s+javascript\b/i
|
|
5324
|
+
];
|
|
5325
|
+
function hasAncestorTag(doc, startIndex, tags) {
|
|
5326
|
+
let current = startIndex;
|
|
5327
|
+
for (let hops = 0; hops < 128 && current >= 0; hops++) {
|
|
5328
|
+
const el = doc.elements[current];
|
|
5329
|
+
if (el === void 0) break;
|
|
5330
|
+
if (tags.has(el.tag)) return true;
|
|
5331
|
+
current = el.parent;
|
|
5332
|
+
}
|
|
5333
|
+
return false;
|
|
5334
|
+
}
|
|
5335
|
+
var NON_BODY_TEXT_TAGS = /* @__PURE__ */ new Set(["title", "noscript"]);
|
|
5336
|
+
function detectSpaJsDependency(html) {
|
|
5337
|
+
const doc = tokenizeHtml(html);
|
|
5338
|
+
const emptyMountRoots = [];
|
|
5339
|
+
for (const el of doc.elements) {
|
|
5340
|
+
const id = el.attrs["id"]?.trim().toLowerCase();
|
|
5341
|
+
if (id === void 0 || !SPA_MOUNT_ROOT_IDS.has(id)) continue;
|
|
5342
|
+
const text = elementText(doc, el.index);
|
|
5343
|
+
if (text.length === 0) {
|
|
5344
|
+
const selector = `#${el.attrs["id"]?.trim() ?? id}`;
|
|
5345
|
+
if (!emptyMountRoots.includes(selector)) emptyMountRoots.push(selector);
|
|
5346
|
+
}
|
|
5347
|
+
}
|
|
5348
|
+
let jsRequiredNoscript = false;
|
|
5349
|
+
let noscriptSnippet = null;
|
|
5350
|
+
for (const el of doc.elements) {
|
|
5351
|
+
if (el.tag !== "noscript") continue;
|
|
5352
|
+
const text = elementText(doc, el.index);
|
|
5353
|
+
if (text.length === 0) continue;
|
|
5354
|
+
if (NOSCRIPT_JS_PATTERNS.some((pattern) => pattern.test(text))) {
|
|
5355
|
+
jsRequiredNoscript = true;
|
|
5356
|
+
if (noscriptSnippet === null) noscriptSnippet = text.slice(0, 200);
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
const visibleParts = [];
|
|
5360
|
+
for (const node of doc.texts) {
|
|
5361
|
+
if (node.excludedBy !== null) continue;
|
|
5362
|
+
if (hasAncestorTag(doc, node.parent, NON_BODY_TEXT_TAGS)) continue;
|
|
5363
|
+
visibleParts.push(node.text);
|
|
5364
|
+
}
|
|
5365
|
+
const visibleBodyText = visibleParts.join(" ").replace(/\s+/g, " ").trim();
|
|
5366
|
+
const visibleWordCount = visibleBodyText.length === 0 ? 0 : visibleBodyText.split(/\s+/).filter(Boolean).length;
|
|
5367
|
+
const visibleTextBytes = utf8Length(visibleBodyText);
|
|
5368
|
+
let scriptBytes = 0;
|
|
5369
|
+
let externalScriptCount = 0;
|
|
5370
|
+
let hasNextData = false;
|
|
5371
|
+
let hasNextFlight = false;
|
|
5372
|
+
let hydrationPayloadBytes = 0;
|
|
5373
|
+
const nextDataElements = /* @__PURE__ */ new Set();
|
|
5374
|
+
for (const el of doc.elements) {
|
|
5375
|
+
if (el.tag !== "script") continue;
|
|
5376
|
+
const typeAttr = el.attrs["type"]?.trim().toLowerCase() ?? "";
|
|
5377
|
+
if (typeAttr === "application/ld+json") continue;
|
|
5378
|
+
if (typeof el.attrs["src"] === "string" && el.attrs["src"].trim().length > 0) {
|
|
5379
|
+
externalScriptCount++;
|
|
5380
|
+
}
|
|
5381
|
+
if (el.attrs["id"]?.trim().toLowerCase() === "__next_data__") {
|
|
5382
|
+
hasNextData = true;
|
|
5383
|
+
nextDataElements.add(el.index);
|
|
5384
|
+
}
|
|
5385
|
+
}
|
|
5386
|
+
for (const node of doc.texts) {
|
|
5387
|
+
if (node.excludedBy !== "script") continue;
|
|
5388
|
+
scriptBytes += node.bytes;
|
|
5389
|
+
if (nextDataElements.has(node.parent)) {
|
|
5390
|
+
hydrationPayloadBytes += node.bytes;
|
|
5391
|
+
} else if (node.text.includes("__next_f")) {
|
|
5392
|
+
hasNextFlight = true;
|
|
5393
|
+
hydrationPayloadBytes += node.bytes;
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
5396
|
+
const unrenderedHydrationPayload = (hasNextData || hasNextFlight) && hydrationPayloadBytes >= 1024 && (visibleWordCount < 50 || visibleWordCount < 100 && visibleTextBytes > 0 && hydrationPayloadBytes / visibleTextBytes >= 4);
|
|
5397
|
+
const scriptToTextRatio = visibleTextBytes > 0 ? Number((scriptBytes / visibleTextBytes).toFixed(2)) : scriptBytes > 0 ? null : 0;
|
|
5398
|
+
const lowTextToScriptRatio = visibleWordCount < 40 && (scriptBytes >= 2048 || externalScriptCount >= 2) || visibleWordCount < 80 && visibleTextBytes > 0 && scriptBytes / visibleTextBytes >= 20;
|
|
5399
|
+
const reasons = [];
|
|
5400
|
+
if (emptyMountRoots.length > 0) reasons.push("empty-mount-root");
|
|
5401
|
+
if (jsRequiredNoscript) reasons.push("noscript-js-required");
|
|
5402
|
+
if (unrenderedHydrationPayload) reasons.push("unrendered-next-payload");
|
|
5403
|
+
if (lowTextToScriptRatio) reasons.push("low-text-vs-script");
|
|
5404
|
+
const likelySpaShell = emptyMountRoots.length > 0 && visibleWordCount < 50 || jsRequiredNoscript && visibleWordCount < 80 || unrenderedHydrationPayload || reasons.length >= 2;
|
|
5405
|
+
return {
|
|
5406
|
+
likelySpaShell,
|
|
5407
|
+
reasons,
|
|
5408
|
+
emptyMountRoots,
|
|
5409
|
+
jsRequiredNoscript,
|
|
5410
|
+
noscriptSnippet,
|
|
5411
|
+
hasNextData,
|
|
5412
|
+
hasNextFlight,
|
|
5413
|
+
hydrationPayloadBytes,
|
|
5414
|
+
unrenderedHydrationPayload,
|
|
5415
|
+
visibleWordCount,
|
|
5416
|
+
visibleTextBytes,
|
|
5417
|
+
scriptBytes,
|
|
5418
|
+
externalScriptCount,
|
|
5419
|
+
scriptToTextRatio,
|
|
5420
|
+
lowTextToScriptRatio
|
|
5421
|
+
};
|
|
5422
|
+
}
|
|
5423
|
+
var SAAS_QUOTA_UNITS = [
|
|
5424
|
+
"seats",
|
|
5425
|
+
"users",
|
|
5426
|
+
"projects",
|
|
5427
|
+
"pages",
|
|
5428
|
+
"sites",
|
|
5429
|
+
"requests",
|
|
5430
|
+
"tokens",
|
|
5431
|
+
"credits",
|
|
5432
|
+
"calls",
|
|
5433
|
+
"events",
|
|
5434
|
+
"contacts",
|
|
5435
|
+
"workspaces",
|
|
5436
|
+
"domains",
|
|
5437
|
+
"rows"
|
|
5438
|
+
];
|
|
5439
|
+
var QUOTA_UNIT_CANONICAL = {
|
|
5440
|
+
seat: "seats",
|
|
5441
|
+
seats: "seats",
|
|
5442
|
+
user: "users",
|
|
5443
|
+
users: "users",
|
|
5444
|
+
project: "projects",
|
|
5445
|
+
projects: "projects",
|
|
5446
|
+
page: "pages",
|
|
5447
|
+
pages: "pages",
|
|
5448
|
+
site: "sites",
|
|
5449
|
+
sites: "sites",
|
|
5450
|
+
request: "requests",
|
|
5451
|
+
requests: "requests",
|
|
5452
|
+
token: "tokens",
|
|
5453
|
+
tokens: "tokens",
|
|
5454
|
+
credit: "credits",
|
|
5455
|
+
credits: "credits",
|
|
5456
|
+
call: "calls",
|
|
5457
|
+
calls: "calls",
|
|
5458
|
+
event: "events",
|
|
5459
|
+
events: "events",
|
|
5460
|
+
contact: "contacts",
|
|
5461
|
+
contacts: "contacts",
|
|
5462
|
+
workspace: "workspaces",
|
|
5463
|
+
workspaces: "workspaces",
|
|
5464
|
+
domain: "domains",
|
|
5465
|
+
domains: "domains",
|
|
5466
|
+
row: "rows",
|
|
5467
|
+
rows: "rows"
|
|
5468
|
+
};
|
|
5469
|
+
var PRICE_TOKEN_PATTERN = /(?:[$€£¥] ?\d[\d,.]*|\b(?:USD|EUR|GBP|CAD|AUD) \d[\d,.]*)/gi;
|
|
5470
|
+
var TIER_CONTAINER_TAGS = /* @__PURE__ */ new Set(["article", "section", "div", "li"]);
|
|
5471
|
+
var TIER_ATTR_HINT = /(?:^|[-_\s])(plan|tier|pricing[-_]?card|price[-_]?card|package)(?:$|[-_\s])/i;
|
|
5472
|
+
var TIER_TEXT_HINT = /\b(?:free|custom pricing|custom|contact sales|enterprise|talk to sales)\b/i;
|
|
5473
|
+
var ICON_CLASS_HINT = /(?:icon|check|tick|cross|dash|minus|yes|no|fa-|lucide|heroicon|badge)/i;
|
|
5474
|
+
var TOGGLE_ELEMENT_TAGS = /* @__PURE__ */ new Set(["button", "input", "label", "select", "div", "span", "fieldset"]);
|
|
5475
|
+
var ANNUAL_PRICE_CONTEXT = /\b(?:billed (?:annually|yearly)|annual billing|per year|annually|yearly)\b|\/(?:yr|year)\b/i;
|
|
5476
|
+
var MONTHLY_PRICE_CONTEXT = /\b(?:billed monthly|monthly billing|per month|monthly)\b|\/(?:mo|month)\b/i;
|
|
5477
|
+
var CADENCE_PATTERNS = [
|
|
5478
|
+
/\/(?:mo|month|yr|year|quarter|week|day|seat|user|member)\b/gi,
|
|
5479
|
+
/\bper (?:month|mo|year|yr|quarter|week|day|hour|seat|user|member|workspace|project|site|domain|request|call|credit|token|contact|unit)\b/gi,
|
|
5480
|
+
/\bbilled (?:annually|yearly|monthly|quarterly)\b/gi,
|
|
5481
|
+
/\bone-time\b/gi
|
|
5482
|
+
];
|
|
5483
|
+
var QUOTA_MODIFIER_WORDS = /* @__PURE__ */ new Set([
|
|
5484
|
+
"active",
|
|
5485
|
+
"custom",
|
|
5486
|
+
"monthly",
|
|
5487
|
+
"annual",
|
|
5488
|
+
"api",
|
|
5489
|
+
"team",
|
|
5490
|
+
"tracked",
|
|
5491
|
+
"monitored",
|
|
5492
|
+
"included",
|
|
5493
|
+
"free",
|
|
5494
|
+
"extra",
|
|
5495
|
+
"total",
|
|
5496
|
+
"concurrent",
|
|
5497
|
+
"unique"
|
|
5498
|
+
]);
|
|
5499
|
+
var QUOTA_QUANTITY_TOKEN = /^(?:unlimited|\d[\d,.]*[kmb]?\+?)$/i;
|
|
5500
|
+
var QUOTA_VALUE_CELL = /^(?:unlimited|up to \d[\d,.]*[kmb]?|\d[\d,.]*[kmb]?\+?)$/i;
|
|
5501
|
+
function isAncestorOf(doc, ancestor, descendant) {
|
|
5502
|
+
let current = descendant;
|
|
5503
|
+
for (let hops = 0; hops < 128 && current >= 0; hops++) {
|
|
5504
|
+
if (current === ancestor) return true;
|
|
5505
|
+
current = doc.elements[current]?.parent ?? -1;
|
|
5506
|
+
}
|
|
5507
|
+
return false;
|
|
5508
|
+
}
|
|
5509
|
+
function collectOfferRecords(nodes) {
|
|
5510
|
+
const offers = [];
|
|
5511
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5512
|
+
const visit = (obj, depth) => {
|
|
5513
|
+
if (depth > 8 || obj === null || typeof obj !== "object") return;
|
|
5514
|
+
if (Array.isArray(obj)) {
|
|
5515
|
+
for (const item of obj) visit(item, depth + 1);
|
|
5516
|
+
return;
|
|
5517
|
+
}
|
|
5518
|
+
if (seen.has(obj)) return;
|
|
5519
|
+
seen.add(obj);
|
|
5520
|
+
const rec = obj;
|
|
5521
|
+
const rawType = rec["@type"];
|
|
5522
|
+
const types = typeof rawType === "string" ? [rawType.replace(/^https?:\/\/schema\.org\//, "")] : Array.isArray(rawType) ? rawType.filter((t) => typeof t === "string").map((t) => t.replace(/^https?:\/\/schema\.org\//, "")) : [];
|
|
5523
|
+
if (types.includes("Offer")) offers.push(rec);
|
|
5524
|
+
if (rec["offers"] !== void 0) visit(rec["offers"], depth + 1);
|
|
5525
|
+
};
|
|
5526
|
+
for (const node of nodes) {
|
|
5527
|
+
if (!seen.has(node.value)) {
|
|
5528
|
+
seen.add(node.value);
|
|
5529
|
+
if (node.types.includes("Offer")) offers.push(node.value);
|
|
5530
|
+
}
|
|
5531
|
+
if (node.value["offers"] !== void 0) visit(node.value["offers"], 1);
|
|
5532
|
+
}
|
|
5533
|
+
return offers;
|
|
5534
|
+
}
|
|
5535
|
+
function hasOfferPrice(offer) {
|
|
5536
|
+
if (offer["price"] !== void 0 && offer["price"] !== null && String(offer["price"]).trim() !== "") {
|
|
5537
|
+
return true;
|
|
5538
|
+
}
|
|
5539
|
+
const spec = offer["priceSpecification"];
|
|
5540
|
+
const specs = Array.isArray(spec) ? spec : spec !== void 0 && spec !== null ? [spec] : [];
|
|
5541
|
+
return specs.some((entry) => {
|
|
5542
|
+
if (entry === null || typeof entry !== "object") return false;
|
|
5543
|
+
const record = entry;
|
|
5544
|
+
return record["price"] !== void 0 && String(record["price"]).trim() !== "" || record["minPrice"] !== void 0 && String(record["minPrice"]).trim() !== "";
|
|
5545
|
+
});
|
|
5546
|
+
}
|
|
5547
|
+
function normalizePriceMatch(raw) {
|
|
5548
|
+
return raw.replace(/[.,]+$/, "").replace(/\s+/g, "").toUpperCase();
|
|
5549
|
+
}
|
|
5550
|
+
function directChildrenOfTag(doc, parentIndex, tag) {
|
|
5551
|
+
const out = [];
|
|
5552
|
+
for (const el of doc.elements) {
|
|
5553
|
+
if (el.parent === parentIndex && el.tag === tag) out.push(el);
|
|
5554
|
+
}
|
|
5555
|
+
return out;
|
|
5556
|
+
}
|
|
5557
|
+
function descendantsOf(doc, ancestorIndex) {
|
|
5558
|
+
const out = [];
|
|
5559
|
+
for (let i = ancestorIndex + 1; i < doc.elements.length; i++) {
|
|
5560
|
+
const el = doc.elements[i];
|
|
5561
|
+
if (el === void 0) continue;
|
|
5562
|
+
if (el.depth <= (doc.elements[ancestorIndex]?.depth ?? 0)) break;
|
|
5563
|
+
if (isAncestorOf(doc, ancestorIndex, el.index)) out.push(el);
|
|
5564
|
+
}
|
|
5565
|
+
return out;
|
|
5566
|
+
}
|
|
5567
|
+
function quotaUnitFromLabel(label) {
|
|
5568
|
+
const words = label.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter(Boolean);
|
|
5569
|
+
for (const word of words) {
|
|
5570
|
+
const mapped = QUOTA_UNIT_CANONICAL[word];
|
|
5571
|
+
if (mapped !== void 0) return mapped;
|
|
5572
|
+
}
|
|
5573
|
+
return null;
|
|
5574
|
+
}
|
|
5575
|
+
function auditPricingAndLimits(html, jsonLdNodes) {
|
|
5576
|
+
const doc = tokenizeHtml(html);
|
|
5577
|
+
const nodes = jsonLdNodes !== void 0 ? jsonLdNodes : parseJsonLd(doc.jsonLd).nodes;
|
|
5578
|
+
const offerRecords = collectOfferRecords(nodes);
|
|
5579
|
+
const jsonLdOfferCount = offerRecords.length;
|
|
5580
|
+
const jsonLdPricedOfferCount = offerRecords.filter(hasOfferPrice).length;
|
|
5581
|
+
const visibleParts = [];
|
|
5582
|
+
for (const node of doc.texts) {
|
|
5583
|
+
if (node.excludedBy !== null) continue;
|
|
5584
|
+
if (hasAncestorTag(doc, node.parent, NON_BODY_TEXT_TAGS)) continue;
|
|
5585
|
+
visibleParts.push(node.text);
|
|
5586
|
+
}
|
|
5587
|
+
const visibleText = visibleParts.join(" ").replace(/\s+/g, " ").trim();
|
|
5588
|
+
const priceMatches = [];
|
|
5589
|
+
PRICE_TOKEN_PATTERN.lastIndex = 0;
|
|
5590
|
+
let match;
|
|
5591
|
+
while ((match = PRICE_TOKEN_PATTERN.exec(visibleText)) !== null) {
|
|
5592
|
+
priceMatches.push({ raw: match[0], index: match.index });
|
|
5593
|
+
}
|
|
5594
|
+
const visiblePriceCount = priceMatches.length;
|
|
5595
|
+
const distinctVisiblePriceCount = new Set(priceMatches.map((m) => normalizePriceMatch(m.raw))).size;
|
|
5596
|
+
const candidateCards = [];
|
|
5597
|
+
for (const el of doc.elements) {
|
|
5598
|
+
if (!TIER_CONTAINER_TAGS.has(el.tag) || el.excludedBy !== null) continue;
|
|
5599
|
+
const hasDataPlan = el.attrs["data-plan"] !== void 0 || el.attrs["data-tier"] !== void 0 || el.attrs["data-pricing-tier"] !== void 0;
|
|
5600
|
+
const hintStr = `${el.attrs["class"] ?? ""} ${el.attrs["id"] ?? ""}`;
|
|
5601
|
+
if (!hasDataPlan && !TIER_ATTR_HINT.test(hintStr)) continue;
|
|
5602
|
+
const text = elementText(doc, el.index);
|
|
5603
|
+
if (text.length === 0) continue;
|
|
5604
|
+
PRICE_TOKEN_PATTERN.lastIndex = 0;
|
|
5605
|
+
if (PRICE_TOKEN_PATTERN.test(text) || TIER_TEXT_HINT.test(text)) {
|
|
5606
|
+
candidateCards.push(el);
|
|
5607
|
+
}
|
|
5608
|
+
}
|
|
5609
|
+
const leafCards = candidateCards.filter(
|
|
5610
|
+
(card) => !candidateCards.some((other) => other.index !== card.index && isAncestorOf(doc, card.index, other.index))
|
|
5611
|
+
);
|
|
5612
|
+
let iconOnlyCellCount = 0;
|
|
5613
|
+
let pricingTableTierCount = 0;
|
|
5614
|
+
const unitCounts = {};
|
|
5615
|
+
const incrementUnit = (unit) => {
|
|
5616
|
+
unitCounts[unit] = (unitCounts[unit] ?? 0) + 1;
|
|
5617
|
+
};
|
|
5618
|
+
for (const el of doc.elements) {
|
|
5619
|
+
if (el.tag !== "table" || el.excludedBy !== null) continue;
|
|
5620
|
+
const tableDescendants = descendantsOf(doc, el.index);
|
|
5621
|
+
const rows = tableDescendants.filter((child) => child.tag === "tr");
|
|
5622
|
+
if (rows.length === 0) continue;
|
|
5623
|
+
const tableText = elementText(doc, el.index);
|
|
5624
|
+
PRICE_TOKEN_PATTERN.lastIndex = 0;
|
|
5625
|
+
const tableHasPrices = PRICE_TOKEN_PATTERN.test(tableText);
|
|
5626
|
+
for (const row of rows) {
|
|
5627
|
+
const cells = [
|
|
5628
|
+
...directChildrenOfTag(doc, row.index, "th"),
|
|
5629
|
+
...directChildrenOfTag(doc, row.index, "td")
|
|
5630
|
+
].sort((a, b) => a.index - b.index);
|
|
5631
|
+
if (cells.length >= 3 && tableHasPrices) {
|
|
5632
|
+
const thCount = cells.filter((c) => c.tag === "th").length;
|
|
5633
|
+
if (thCount >= 3) {
|
|
5634
|
+
pricingTableTierCount = Math.max(pricingTableTierCount, thCount - 1);
|
|
5635
|
+
}
|
|
5636
|
+
}
|
|
5637
|
+
const firstCell = cells[0];
|
|
5638
|
+
const rowQuotaUnit = firstCell !== void 0 && cells.length >= 2 ? quotaUnitFromLabel(elementText(doc, firstCell.index)) : null;
|
|
5639
|
+
for (let cellIdx = 0; cellIdx < cells.length; cellIdx++) {
|
|
5640
|
+
const cell = cells[cellIdx];
|
|
5641
|
+
if (cell === void 0 || cell.tag !== "td") continue;
|
|
5642
|
+
const cellText = elementText(doc, cell.index);
|
|
5643
|
+
if (cellIdx > 0 && rowQuotaUnit !== null && QUOTA_VALUE_CELL.test(cellText)) {
|
|
5644
|
+
incrementUnit(rowQuotaUnit);
|
|
5645
|
+
}
|
|
5646
|
+
if (cells.length >= 2 && cellText.length === 0) {
|
|
5647
|
+
const cellDescendants = descendantsOf(doc, cell.index);
|
|
5648
|
+
const hasIconOnly = cellDescendants.some((desc) => {
|
|
5649
|
+
if (desc.tag === "svg") return true;
|
|
5650
|
+
if (desc.tag === "img" && (desc.attrs["alt"] ?? "").trim().length === 0) return true;
|
|
5651
|
+
if ((desc.tag === "i" || desc.tag === "span") && ICON_CLASS_HINT.test(desc.attrs["class"] ?? "")) {
|
|
5652
|
+
return true;
|
|
5653
|
+
}
|
|
5654
|
+
return false;
|
|
5655
|
+
});
|
|
5656
|
+
if (hasIconOnly) iconOnlyCellCount++;
|
|
5657
|
+
}
|
|
5658
|
+
}
|
|
5659
|
+
}
|
|
5660
|
+
}
|
|
5661
|
+
const visibleTierCount = Math.max(leafCards.length, pricingTableTierCount, distinctVisiblePriceCount);
|
|
5662
|
+
const iconOnlyFeatureMatrix = iconOnlyCellCount > 0;
|
|
5663
|
+
let hasBillingToggleHint = false;
|
|
5664
|
+
let sawMonthlyControl = false;
|
|
5665
|
+
let sawAnnualControl = false;
|
|
5666
|
+
for (const el of doc.elements) {
|
|
5667
|
+
if (!TOGGLE_ELEMENT_TAGS.has(el.tag) || el.excludedBy !== null) continue;
|
|
5668
|
+
const role = el.attrs["role"]?.toLowerCase() ?? "";
|
|
5669
|
+
const isInteractive = el.tag === "button" || el.tag === "input" || el.tag === "label" || el.tag === "select" || role === "switch" || role === "tab" || role === "tablist" || role === "radiogroup";
|
|
5670
|
+
if (!isInteractive) continue;
|
|
5671
|
+
const labelText = [
|
|
5672
|
+
elementText(doc, el.index),
|
|
5673
|
+
el.attrs["aria-label"] ?? "",
|
|
5674
|
+
el.attrs["name"] ?? "",
|
|
5675
|
+
el.attrs["id"] ?? "",
|
|
5676
|
+
el.attrs["data-billing"] ?? "",
|
|
5677
|
+
el.attrs["data-period"] ?? ""
|
|
5678
|
+
].join(" ").toLowerCase();
|
|
5679
|
+
const hasMonthly = /\b(?:monthly|month)\b/.test(labelText);
|
|
5680
|
+
const hasAnnual = /\b(?:annual(?:ly)?|yearly|year)\b/.test(labelText);
|
|
5681
|
+
if (hasMonthly && hasAnnual) {
|
|
5682
|
+
hasBillingToggleHint = true;
|
|
5683
|
+
break;
|
|
5684
|
+
}
|
|
5685
|
+
if (hasMonthly) sawMonthlyControl = true;
|
|
5686
|
+
if (hasAnnual) sawAnnualControl = true;
|
|
5687
|
+
}
|
|
5688
|
+
if (sawMonthlyControl && sawAnnualControl) hasBillingToggleHint = true;
|
|
5689
|
+
let monthlyPricePresent = false;
|
|
5690
|
+
let annualPricePresent = false;
|
|
5691
|
+
for (let i = 0; i < priceMatches.length; i++) {
|
|
5692
|
+
const pm = priceMatches[i];
|
|
5693
|
+
if (pm === void 0) continue;
|
|
5694
|
+
const nextPriceIndex = priceMatches[i + 1]?.index ?? visibleText.length;
|
|
5695
|
+
const contextEnd = Math.min(nextPriceIndex, pm.index + 48);
|
|
5696
|
+
const context = visibleText.slice(pm.index, contextEnd);
|
|
5697
|
+
if (ANNUAL_PRICE_CONTEXT.test(context)) {
|
|
5698
|
+
annualPricePresent = true;
|
|
5699
|
+
} else if (MONTHLY_PRICE_CONTEXT.test(context)) {
|
|
5700
|
+
monthlyPricePresent = true;
|
|
5701
|
+
}
|
|
5702
|
+
}
|
|
5703
|
+
const billingToggleSinglePeriodOnly = hasBillingToggleHint && monthlyPricePresent !== annualPricePresent;
|
|
5704
|
+
const billingCadences = [];
|
|
5705
|
+
const seenCadences = /* @__PURE__ */ new Set();
|
|
5706
|
+
for (const pattern of CADENCE_PATTERNS) {
|
|
5707
|
+
pattern.lastIndex = 0;
|
|
5708
|
+
let cadenceMatch;
|
|
5709
|
+
while ((cadenceMatch = pattern.exec(visibleText)) !== null) {
|
|
5710
|
+
const normalized = cadenceMatch[0].replace(/\s+/g, " ").trim().toLowerCase();
|
|
5711
|
+
if (normalized.length > 0 && !seenCadences.has(normalized)) {
|
|
5712
|
+
seenCadences.add(normalized);
|
|
5713
|
+
billingCadences.push(normalized);
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5716
|
+
}
|
|
5717
|
+
const words = visibleText.toLowerCase().split(/[^a-z0-9.,+]+/).map((token) => token.replace(/^[.,]+/, "").replace(/[.,]+$/, "")).filter((token) => token.length > 0);
|
|
5718
|
+
for (let i = 0; i + 1 < words.length; i++) {
|
|
5719
|
+
const qty = words[i];
|
|
5720
|
+
if (qty === void 0 || !QUOTA_QUANTITY_TOKEN.test(qty)) continue;
|
|
5721
|
+
const next = words[i + 1];
|
|
5722
|
+
if (next === void 0) continue;
|
|
5723
|
+
const direct = QUOTA_UNIT_CANONICAL[next];
|
|
5724
|
+
if (direct !== void 0) {
|
|
5725
|
+
incrementUnit(direct);
|
|
5726
|
+
i += 1;
|
|
5727
|
+
continue;
|
|
5728
|
+
}
|
|
5729
|
+
if (QUOTA_MODIFIER_WORDS.has(next)) {
|
|
5730
|
+
const after = words[i + 2];
|
|
5731
|
+
const modified = after !== void 0 ? QUOTA_UNIT_CANONICAL[after] : void 0;
|
|
5732
|
+
if (modified !== void 0) {
|
|
5733
|
+
incrementUnit(modified);
|
|
5734
|
+
i += 2;
|
|
5735
|
+
}
|
|
5736
|
+
}
|
|
5737
|
+
}
|
|
5738
|
+
const detectedQuotaUnits = SAAS_QUOTA_UNITS.filter((unit) => (unitCounts[unit] ?? 0) > 0);
|
|
5739
|
+
const featureLimitCount = detectedQuotaUnits.reduce((sum, unit) => sum + (unitCounts[unit] ?? 0), 0);
|
|
5740
|
+
return {
|
|
5741
|
+
jsonLdOfferCount,
|
|
5742
|
+
jsonLdPricedOfferCount,
|
|
5743
|
+
visibleTierCount,
|
|
5744
|
+
visiblePriceCount,
|
|
5745
|
+
iconOnlyFeatureMatrix,
|
|
5746
|
+
iconOnlyCellCount,
|
|
5747
|
+
hasBillingToggleHint,
|
|
5748
|
+
billingToggleSinglePeriodOnly,
|
|
5749
|
+
billingCadences,
|
|
5750
|
+
featureLimitCount,
|
|
5751
|
+
featureLimitUnits: unitCounts,
|
|
5752
|
+
detectedQuotaUnits
|
|
5753
|
+
};
|
|
5754
|
+
}
|
|
5755
|
+
function declaredPageFacts(evidence) {
|
|
5756
|
+
const browser = evidence.probes.browser.result;
|
|
5757
|
+
const agent = evidence.probes.agent.result;
|
|
5758
|
+
const capture = browser.ok ? browser.capture : agent.ok ? agent.capture : null;
|
|
5759
|
+
if (capture === null) return null;
|
|
5760
|
+
const representation = buildRepresentation(capture);
|
|
5761
|
+
if (representation === null) return null;
|
|
5762
|
+
const extract = (kinds, currencyHint) => {
|
|
5763
|
+
const profile = {
|
|
5764
|
+
pageKind: "unknown",
|
|
5765
|
+
core: kinds,
|
|
5766
|
+
extended: [],
|
|
5767
|
+
byteReference: DEFAULT_RULESET.maxBodyBytes
|
|
5768
|
+
};
|
|
5769
|
+
return extractFacts(representation, {
|
|
5770
|
+
profile,
|
|
5771
|
+
ruleset: DEFAULT_RULESET,
|
|
5772
|
+
baseUrl: capture.finalUrl,
|
|
5773
|
+
origin: evidence.target.origin,
|
|
5774
|
+
currencyHint
|
|
5775
|
+
});
|
|
5776
|
+
};
|
|
5777
|
+
const currency = extract(["currency"], void 0).find((fact) => fact.kind === "currency");
|
|
5778
|
+
const facts = extract(["updated", "price"], currency?.normalized);
|
|
5779
|
+
let updated = null;
|
|
5780
|
+
const priceSources = [];
|
|
5781
|
+
for (const fact of facts) {
|
|
5782
|
+
if (fact.kind === "updated" && updated === null) updated = fact.normalized;
|
|
5783
|
+
if (fact.kind === "price" && !priceSources.includes(fact.source)) priceSources.push(fact.source);
|
|
5784
|
+
}
|
|
5785
|
+
return { updated, priceSources };
|
|
5786
|
+
}
|
|
5787
|
+
|
|
4947
5788
|
exports.AGENT_ACCEPT = AGENT_ACCEPT;
|
|
4948
5789
|
exports.ARS_CORPUS_HASH = ARS_CORPUS_HASH;
|
|
4949
5790
|
exports.ARS_HEURISTIC_WEIGHT = ARS_HEURISTIC_WEIGHT;
|
|
@@ -4956,22 +5797,36 @@ exports.BROWSER_ACCEPT = BROWSER_ACCEPT;
|
|
|
4956
5797
|
exports.CHECK_META = CHECK_META;
|
|
4957
5798
|
exports.DEFAULT_RULESET = DEFAULT_RULESET;
|
|
4958
5799
|
exports.DIMENSION_META = DIMENSION_META;
|
|
5800
|
+
exports.EDGE_CHALLENGE_VENDOR_LABEL = EDGE_CHALLENGE_VENDOR_LABEL;
|
|
4959
5801
|
exports.PROFILES = PROFILES;
|
|
5802
|
+
exports.SAAS_QUOTA_UNITS = SAAS_QUOTA_UNITS;
|
|
4960
5803
|
exports.SUBPOINTS = SUBPOINTS;
|
|
5804
|
+
exports.auditPricingAndLimits = auditPricingAndLimits;
|
|
4961
5805
|
exports.bandFor = bandFor;
|
|
4962
5806
|
exports.canonicalJson = canonicalJson;
|
|
5807
|
+
exports.challengeDetail = challengeDetail;
|
|
4963
5808
|
exports.classify = classify;
|
|
5809
|
+
exports.decideRobots = decideRobots;
|
|
4964
5810
|
exports.declaredMarkdownAlternates = declaredMarkdownAlternates;
|
|
5811
|
+
exports.declaredPageFacts = declaredPageFacts;
|
|
5812
|
+
exports.detectEdgeChallenge = detectEdgeChallenge;
|
|
5813
|
+
exports.detectSpaJsDependency = detectSpaJsDependency;
|
|
5814
|
+
exports.edgeChallengeOf = edgeChallengeOf;
|
|
4965
5815
|
exports.evidenceHash = evidenceHash;
|
|
5816
|
+
exports.indexSignalsOf = indexSignalsOf;
|
|
4966
5817
|
exports.isMachineCopy = isMachineCopy;
|
|
4967
5818
|
exports.markdownAlternateTarget = markdownAlternateTarget;
|
|
4968
5819
|
exports.minorUnitDigits = minorUnitDigits;
|
|
5820
|
+
exports.pageIndexSignals = pageIndexSignals;
|
|
5821
|
+
exports.parseChallengeDetail = parseChallengeDetail;
|
|
5822
|
+
exports.parseContentSignals = parseContentSignals;
|
|
4969
5823
|
exports.parseMoneyText = parseMoneyText;
|
|
4970
5824
|
exports.parseRobots = parseRobots;
|
|
4971
5825
|
exports.pathMatches = pathMatches;
|
|
4972
5826
|
exports.profileFor = profileFor;
|
|
4973
5827
|
exports.recommend = recommend;
|
|
4974
5828
|
exports.robotsDisallowsScanner = robotsDisallowsScanner;
|
|
5829
|
+
exports.robotsEdgeChallengeOf = robotsEdgeChallengeOf;
|
|
4975
5830
|
exports.rulesetHash = rulesetHash;
|
|
4976
5831
|
exports.score = score;
|
|
4977
5832
|
exports.sha256Hex = sha256Hex;
|