mcp-web-validator 1.3.51 → 1.3.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +64 -4
- package/dist/audit-history.d.ts +9 -0
- package/dist/audit-history.js +27 -0
- package/dist/audit-history.js.map +1 -1
- package/dist/index.js +2508 -2
- package/dist/index.js.map +1 -1
- package/dist/modules/browser-ux/lighthouse-lab-probe.d.ts +21 -0
- package/dist/modules/browser-ux/lighthouse-lab-probe.js +190 -0
- package/dist/modules/browser-ux/lighthouse-lab-probe.js.map +1 -0
- package/dist/modules/browser-ux/lighthouse-lab.d.ts +61 -0
- package/dist/modules/browser-ux/lighthouse-lab.js +98 -0
- package/dist/modules/browser-ux/lighthouse-lab.js.map +1 -0
- package/dist/modules/browser-ux/media-diagnostics.d.ts +41 -0
- package/dist/modules/browser-ux/media-diagnostics.js +183 -0
- package/dist/modules/browser-ux/media-diagnostics.js.map +1 -0
- package/dist/modules/browser-ux/raw-rendered-diff.d.ts +70 -0
- package/dist/modules/browser-ux/raw-rendered-diff.js +262 -0
- package/dist/modules/browser-ux/raw-rendered-diff.js.map +1 -0
- package/dist/modules/browser-ux/raw-rendered-probe.d.ts +17 -0
- package/dist/modules/browser-ux/raw-rendered-probe.js +163 -0
- package/dist/modules/browser-ux/raw-rendered-probe.js.map +1 -0
- package/dist/modules/browser-ux/resource-failures-probe.d.ts +11 -0
- package/dist/modules/browser-ux/resource-failures-probe.js +231 -0
- package/dist/modules/browser-ux/resource-failures-probe.js.map +1 -0
- package/dist/modules/browser-ux/resource-failures.d.ts +79 -0
- package/dist/modules/browser-ux/resource-failures.js +178 -0
- package/dist/modules/browser-ux/resource-failures.js.map +1 -0
- package/dist/modules/browser-ux/viewport-parity-probe.d.ts +5 -0
- package/dist/modules/browser-ux/viewport-parity-probe.js +307 -0
- package/dist/modules/browser-ux/viewport-parity-probe.js.map +1 -0
- package/dist/modules/browser-ux/viewport-parity.d.ts +112 -0
- package/dist/modules/browser-ux/viewport-parity.js +224 -0
- package/dist/modules/browser-ux/viewport-parity.js.map +1 -0
- package/dist/modules/browser-ux/wcag-interactions.d.ts +95 -0
- package/dist/modules/browser-ux/wcag-interactions.js +360 -0
- package/dist/modules/browser-ux/wcag-interactions.js.map +1 -0
- package/dist/modules/change-regression/availability-history-store.d.ts +18 -0
- package/dist/modules/change-regression/availability-history-store.js +168 -0
- package/dist/modules/change-regression/availability-history-store.js.map +1 -0
- package/dist/modules/change-regression/crawler-log-correlation.d.ts +111 -0
- package/dist/modules/change-regression/crawler-log-correlation.js +374 -0
- package/dist/modules/change-regression/crawler-log-correlation.js.map +1 -0
- package/dist/modules/change-regression/google-common-crawler-ip.d.ts +15 -0
- package/dist/modules/change-regression/google-common-crawler-ip.js +129 -0
- package/dist/modules/change-regression/google-common-crawler-ip.js.map +1 -0
- package/dist/modules/change-regression/historical-comparisons.d.ts +120 -0
- package/dist/modules/change-regression/historical-comparisons.js +330 -0
- package/dist/modules/change-regression/historical-comparisons.js.map +1 -0
- package/dist/modules/change-regression/production-change-comparison.d.ts +68 -0
- package/dist/modules/change-regression/production-change-comparison.js +214 -0
- package/dist/modules/change-regression/production-change-comparison.js.map +1 -0
- package/dist/modules/change-regression/regression-alerts.d.ts +73 -0
- package/dist/modules/change-regression/regression-alerts.js +183 -0
- package/dist/modules/change-regression/regression-alerts.js.map +1 -0
- package/dist/modules/change-regression/strict-observation-time.d.ts +7 -0
- package/dist/modules/change-regression/strict-observation-time.js +31 -0
- package/dist/modules/change-regression/strict-observation-time.js.map +1 -0
- package/dist/modules/content-schema/citation-methodology-consistency.d.ts +108 -0
- package/dist/modules/content-schema/citation-methodology-consistency.js +360 -0
- package/dist/modules/content-schema/citation-methodology-consistency.js.map +1 -0
- package/dist/modules/content-schema/competitor-intent-comparison.d.ts +74 -0
- package/dist/modules/content-schema/competitor-intent-comparison.js +185 -0
- package/dist/modules/content-schema/competitor-intent-comparison.js.map +1 -0
- package/dist/modules/content-schema/empty-boilerplate-content.d.ts +36 -0
- package/dist/modules/content-schema/empty-boilerplate-content.js +225 -0
- package/dist/modules/content-schema/empty-boilerplate-content.js.map +1 -0
- package/dist/modules/content-schema/extract-citation-methodology.d.ts +6 -0
- package/dist/modules/content-schema/extract-citation-methodology.js +201 -0
- package/dist/modules/content-schema/extract-citation-methodology.js.map +1 -0
- package/dist/modules/content-schema/extract-competitor-intent.d.ts +2 -0
- package/dist/modules/content-schema/extract-competitor-intent.js +140 -0
- package/dist/modules/content-schema/extract-competitor-intent.js.map +1 -0
- package/dist/modules/content-schema/extract-main-content.d.ts +6 -0
- package/dist/modules/content-schema/extract-main-content.js +33 -0
- package/dist/modules/content-schema/extract-main-content.js.map +1 -0
- package/dist/modules/content-schema/extract-metadata-consistency.d.ts +3 -0
- package/dist/modules/content-schema/extract-metadata-consistency.js +62 -0
- package/dist/modules/content-schema/extract-metadata-consistency.js.map +1 -0
- package/dist/modules/content-schema/extract-product-claims.d.ts +3 -0
- package/dist/modules/content-schema/extract-product-claims.js +58 -0
- package/dist/modules/content-schema/extract-product-claims.js.map +1 -0
- package/dist/modules/content-schema/extract-structured-data.d.ts +3 -0
- package/dist/modules/content-schema/extract-structured-data.js +25 -0
- package/dist/modules/content-schema/extract-structured-data.js.map +1 -0
- package/dist/modules/content-schema/metadata-consistency.d.ts +66 -0
- package/dist/modules/content-schema/metadata-consistency.js +282 -0
- package/dist/modules/content-schema/metadata-consistency.js.map +1 -0
- package/dist/modules/content-schema/product-claims.d.ts +73 -0
- package/dist/modules/content-schema/product-claims.js +195 -0
- package/dist/modules/content-schema/product-claims.js.map +1 -0
- package/dist/modules/content-schema/same-language-duplicates.d.ts +52 -0
- package/dist/modules/content-schema/same-language-duplicates.js +158 -0
- package/dist/modules/content-schema/same-language-duplicates.js.map +1 -0
- package/dist/modules/content-schema/structured-data-validation.d.ts +37 -0
- package/dist/modules/content-schema/structured-data-validation.js +385 -0
- package/dist/modules/content-schema/structured-data-validation.js.map +1 -0
- package/dist/modules/external-metrics/crux-field-probe.d.ts +10 -0
- package/dist/modules/external-metrics/crux-field-probe.js +113 -0
- package/dist/modules/external-metrics/crux-field-probe.js.map +1 -0
- package/dist/modules/external-metrics/crux-field.d.ts +61 -0
- package/dist/modules/external-metrics/crux-field.js +231 -0
- package/dist/modules/external-metrics/crux-field.js.map +1 -0
- package/dist/modules/http-crawl/availability-observations.d.ts +68 -0
- package/dist/modules/http-crawl/availability-observations.js +206 -0
- package/dist/modules/http-crawl/availability-observations.js.map +1 -0
- package/dist/modules/http-crawl/availability-probe.d.ts +8 -0
- package/dist/modules/http-crawl/availability-probe.js +46 -0
- package/dist/modules/http-crawl/availability-probe.js.map +1 -0
- package/dist/modules/http-crawl/crawler-access-probe.d.ts +6 -0
- package/dist/modules/http-crawl/crawler-access-probe.js +79 -0
- package/dist/modules/http-crawl/crawler-access-probe.js.map +1 -0
- package/dist/modules/http-crawl/crawler-access.d.ts +75 -0
- package/dist/modules/http-crawl/crawler-access.js +404 -0
- package/dist/modules/http-crawl/crawler-access.js.map +1 -0
- package/dist/modules/http-crawl/http-delivery-probe.d.ts +3 -0
- package/dist/modules/http-crawl/http-delivery-probe.js +44 -0
- package/dist/modules/http-crawl/http-delivery-probe.js.map +1 -0
- package/dist/modules/http-crawl/http-delivery.d.ts +64 -0
- package/dist/modules/http-crawl/http-delivery.js +269 -0
- package/dist/modules/http-crawl/http-delivery.js.map +1 -0
- package/dist/modules/http-crawl/https-security.d.ts +84 -0
- package/dist/modules/http-crawl/https-security.js +441 -0
- package/dist/modules/http-crawl/https-security.js.map +1 -0
- package/dist/modules/http-crawl/non-html-directives.d.ts +74 -0
- package/dist/modules/http-crawl/non-html-directives.js +353 -0
- package/dist/modules/http-crawl/non-html-directives.js.map +1 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.d.ts +80 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.js +459 -0
- package/dist/modules/http-crawl/redirect-canonical-chains.js.map +1 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.d.ts +6 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.js +83 -0
- package/dist/modules/http-crawl/redirect-canonical-probe.js.map +1 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.d.ts +8 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.js +155 -0
- package/dist/modules/http-crawl/sitemap-inventory-probe.js.map +1 -0
- package/dist/modules/http-crawl/sitemap-inventory.d.ts +107 -0
- package/dist/modules/http-crawl/sitemap-inventory.js +557 -0
- package/dist/modules/http-crawl/sitemap-inventory.js.map +1 -0
- package/dist/modules/http-crawl/url-variants.d.ts +86 -0
- package/dist/modules/http-crawl/url-variants.js +379 -0
- package/dist/modules/http-crawl/url-variants.js.map +1 -0
- package/dist/modules/site-architecture/extract-internal-links.d.ts +3 -0
- package/dist/modules/site-architecture/extract-internal-links.js +88 -0
- package/dist/modules/site-architecture/extract-internal-links.js.map +1 -0
- package/dist/modules/site-architecture/extract-multilingual-page.d.ts +2 -0
- package/dist/modules/site-architecture/extract-multilingual-page.js +29 -0
- package/dist/modules/site-architecture/extract-multilingual-page.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.d.ts +7 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.js +116 -0
- package/dist/modules/site-architecture/internal-link-graph-probe.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-graph.d.ts +113 -0
- package/dist/modules/site-architecture/internal-link-graph.js +414 -0
- package/dist/modules/site-architecture/internal-link-graph.js.map +1 -0
- package/dist/modules/site-architecture/internal-link-quality.d.ts +77 -0
- package/dist/modules/site-architecture/internal-link-quality.js +260 -0
- package/dist/modules/site-architecture/internal-link-quality.js.map +1 -0
- package/dist/modules/site-architecture/multilingual-clusters.d.ts +82 -0
- package/dist/modules/site-architecture/multilingual-clusters.js +363 -0
- package/dist/modules/site-architecture/multilingual-clusters.js.map +1 -0
- package/dist/network.d.ts +4 -0
- package/dist/network.js +18 -2
- package/dist/network.js.map +1 -1
- package/dist/presentation.d.ts +53 -0
- package/dist/presentation.js +526 -0
- package/dist/presentation.js.map +1 -1
- package/dist/screenshot.d.ts +2 -1
- package/dist/screenshot.js +4 -2
- package/dist/screenshot.js.map +1 -1
- package/dist/seo-auditor.js +16 -6
- package/dist/seo-auditor.js.map +1 -1
- package/package.json +7 -4
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** V11-FIELD: bounded, evidence-only Chrome UX Report p75 field diagnostics. */
|
|
2
|
+
export declare const CRUX_METRICS: readonly ["largest_contentful_paint", "interaction_to_next_paint", "cumulative_layout_shift", "first_contentful_paint", "experimental_time_to_first_byte"];
|
|
3
|
+
export declare const CRUX_FORMS: readonly ["ALL", "PHONE", "DESKTOP", "TABLET"];
|
|
4
|
+
export declare const CRUX_MODES: readonly ["daily", "history"];
|
|
5
|
+
export declare const CRUX_SOURCES: readonly ["caller_supplied", "verified_crux_api"];
|
|
6
|
+
export declare const MAX_CRUX_RESPONSE_BYTES = 300000;
|
|
7
|
+
export declare const MAX_CRUX_HISTORY_PERIODS = 40;
|
|
8
|
+
export declare const MAX_CRUX_RETURNED_PERIODS = 8;
|
|
9
|
+
export declare const MAX_CRUX_FINDINGS = 12;
|
|
10
|
+
export declare const CRUX_FINDING_CODES: readonly ["metric_missing", "core_web_vitals_good", "core_web_vitals_poor", "core_web_vitals_needs_improvement", "insufficient_core_web_vitals", "historical_gaps", "historical_change", "field_sample_only"];
|
|
11
|
+
export type CruxMode = typeof CRUX_MODES[number];
|
|
12
|
+
export type CruxForm = typeof CRUX_FORMS[number];
|
|
13
|
+
export type CruxSource = typeof CRUX_SOURCES[number];
|
|
14
|
+
export type CruxMetric = typeof CRUX_METRICS[number];
|
|
15
|
+
export type CruxCode = typeof CRUX_FINDING_CODES[number];
|
|
16
|
+
export type CruxVerdict = "good" | "needs_improvement" | "poor" | "unavailable";
|
|
17
|
+
type CruxMetrics = Record<CruxMetric, number | null>;
|
|
18
|
+
export interface CruxFinding {
|
|
19
|
+
code: CruxCode;
|
|
20
|
+
severity: "warning" | "info";
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CruxHistoryPoint {
|
|
24
|
+
period: number;
|
|
25
|
+
period_end: string;
|
|
26
|
+
p75: CruxMetrics;
|
|
27
|
+
core_web_vitals: "good" | "needs_improvement" | "poor" | "insufficient_data";
|
|
28
|
+
}
|
|
29
|
+
export interface CruxFieldReview {
|
|
30
|
+
scope: "crux_real_user_field_p75";
|
|
31
|
+
mode: CruxMode;
|
|
32
|
+
source: CruxSource;
|
|
33
|
+
granularity: "origin" | "url";
|
|
34
|
+
form_factor: CruxForm;
|
|
35
|
+
status: "complete" | "partial" | "unavailable";
|
|
36
|
+
period_end: string | null;
|
|
37
|
+
p75: CruxMetrics;
|
|
38
|
+
metric_verdicts: Record<CruxMetric, CruxVerdict>;
|
|
39
|
+
core_web_vitals: "good" | "needs_improvement" | "poor" | "insufficient_data";
|
|
40
|
+
periods_available: number;
|
|
41
|
+
periods_returned: number;
|
|
42
|
+
history_points: CruxHistoryPoint[];
|
|
43
|
+
first_last_delta: CruxMetrics;
|
|
44
|
+
coverage_limited: true;
|
|
45
|
+
limitations: string[];
|
|
46
|
+
total_findings: number;
|
|
47
|
+
findings: CruxFinding[];
|
|
48
|
+
findings_truncated: boolean;
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare function emptyCruxFieldReview(mode?: CruxMode, source?: CruxSource, granularity?: "origin" | "url", form?: CruxForm): CruxFieldReview;
|
|
52
|
+
export interface CruxQuery {
|
|
53
|
+
granularity: "origin" | "url";
|
|
54
|
+
target: string;
|
|
55
|
+
form_factor: CruxForm;
|
|
56
|
+
mode: CruxMode;
|
|
57
|
+
}
|
|
58
|
+
export declare function safeCruxTarget(target: unknown, granularity: "origin" | "url"): string | undefined;
|
|
59
|
+
export declare function validateCruxQuery(query: CruxQuery): CruxQuery;
|
|
60
|
+
export declare function analyzeCruxField(supplied: unknown, query: CruxQuery, source?: CruxSource): CruxFieldReview;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/** V11-FIELD: bounded, evidence-only Chrome UX Report p75 field diagnostics. */
|
|
2
|
+
export const CRUX_METRICS = [
|
|
3
|
+
"largest_contentful_paint", "interaction_to_next_paint",
|
|
4
|
+
"cumulative_layout_shift", "first_contentful_paint",
|
|
5
|
+
"experimental_time_to_first_byte",
|
|
6
|
+
];
|
|
7
|
+
export const CRUX_FORMS = ["ALL", "PHONE", "DESKTOP", "TABLET"];
|
|
8
|
+
export const CRUX_MODES = ["daily", "history"];
|
|
9
|
+
export const CRUX_SOURCES = ["caller_supplied", "verified_crux_api"];
|
|
10
|
+
export const MAX_CRUX_RESPONSE_BYTES = 300_000;
|
|
11
|
+
export const MAX_CRUX_HISTORY_PERIODS = 40;
|
|
12
|
+
export const MAX_CRUX_RETURNED_PERIODS = 8;
|
|
13
|
+
export const MAX_CRUX_FINDINGS = 12;
|
|
14
|
+
export const CRUX_FINDING_CODES = [
|
|
15
|
+
"metric_missing", "core_web_vitals_good", "core_web_vitals_poor",
|
|
16
|
+
"core_web_vitals_needs_improvement", "insufficient_core_web_vitals",
|
|
17
|
+
"historical_gaps", "historical_change", "field_sample_only",
|
|
18
|
+
];
|
|
19
|
+
const thresholds = {
|
|
20
|
+
largest_contentful_paint: [2500, 4000],
|
|
21
|
+
interaction_to_next_paint: [200, 500],
|
|
22
|
+
cumulative_layout_shift: [0.1, 0.25],
|
|
23
|
+
first_contentful_paint: [1800, 3000],
|
|
24
|
+
experimental_time_to_first_byte: [800, 1800],
|
|
25
|
+
};
|
|
26
|
+
const limitations = [
|
|
27
|
+
"CrUX percentiles represent aggregated eligible Chrome real-user experiences over rolling 28-day windows, not a current page fetch or an exhaustive sample of every visitor.",
|
|
28
|
+
"URL-level and origin-level records cover different populations; returned p75 values cannot be combined across them or interpreted as a Lighthouse laboratory score.",
|
|
29
|
+
"History entries are overlapping weekly 28-day windows, not independent weekly samples. Missing eligible data stays null; no causality, traffic, Google ranking or indexing conclusion.",
|
|
30
|
+
"Caller-supplied JSON is not authenticated CrUX evidence; live source requires an explicit opt-in and a local CRUX_API_KEY environment variable.",
|
|
31
|
+
];
|
|
32
|
+
const emptyMetrics = () => Object.fromEntries(CRUX_METRICS.map(k => [k, null]));
|
|
33
|
+
const emptyVerdicts = () => Object.fromEntries(CRUX_METRICS.map(k => [k, "unavailable"]));
|
|
34
|
+
export function emptyCruxFieldReview(mode = "daily", source = "caller_supplied", granularity = "origin", form = "ALL") {
|
|
35
|
+
return {
|
|
36
|
+
scope: "crux_real_user_field_p75", mode, source, granularity,
|
|
37
|
+
form_factor: form, status: "unavailable", period_end: null,
|
|
38
|
+
p75: emptyMetrics(), metric_verdicts: emptyVerdicts(), core_web_vitals: "insufficient_data",
|
|
39
|
+
periods_available: 0, periods_returned: 0, history_points: [],
|
|
40
|
+
first_last_delta: emptyMetrics(), coverage_limited: true, limitations,
|
|
41
|
+
total_findings: 0, findings: [], findings_truncated: false,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function recordObject(value) {
|
|
45
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
46
|
+
? value : undefined;
|
|
47
|
+
}
|
|
48
|
+
function dateValue(value) {
|
|
49
|
+
const d = recordObject(value);
|
|
50
|
+
if (!d || !Number.isInteger(d.year) || !Number.isInteger(d.month) || !Number.isInteger(d.day))
|
|
51
|
+
throw new Error("Invalid CrUX collection date");
|
|
52
|
+
const year = d.year, month = d.month, day = d.day;
|
|
53
|
+
if (year < 2000 || year > 2100 || month < 1 || month > 12 || day < 1 || day > 31)
|
|
54
|
+
throw new Error("Invalid CrUX collection date");
|
|
55
|
+
const timestamp = Date.UTC(year, month - 1, day);
|
|
56
|
+
const parsed = new Date(timestamp);
|
|
57
|
+
if (parsed.getUTCFullYear() !== year || parsed.getUTCMonth() !== month - 1 || parsed.getUTCDate() !== day)
|
|
58
|
+
throw new Error("Invalid CrUX collection date");
|
|
59
|
+
return parsed.toISOString().slice(0, 10);
|
|
60
|
+
}
|
|
61
|
+
function periodEnd(period) {
|
|
62
|
+
const p = recordObject(period);
|
|
63
|
+
if (!p)
|
|
64
|
+
throw new Error("Missing CrUX collection period");
|
|
65
|
+
const start = dateValue(p.firstDate), end = dateValue(p.lastDate);
|
|
66
|
+
const days = (Date.parse(end) - Date.parse(start)) / 86400000;
|
|
67
|
+
if (days !== 27)
|
|
68
|
+
throw new Error("Unexpected CrUX collection window");
|
|
69
|
+
return end;
|
|
70
|
+
}
|
|
71
|
+
function percentile(raw, metric) {
|
|
72
|
+
if (raw === null || raw === undefined || raw === "NaN")
|
|
73
|
+
return null;
|
|
74
|
+
const value = typeof raw === "number" ? raw :
|
|
75
|
+
metric === "cumulative_layout_shift" && typeof raw === "string" && /^\d+(?:\.\d{1,5})?$/u.test(raw)
|
|
76
|
+
? Number(raw) : Number.NaN;
|
|
77
|
+
if (!Number.isFinite(value) || value < 0 || value > (metric === "cumulative_layout_shift" ? 100 : 600000))
|
|
78
|
+
return null;
|
|
79
|
+
return metric === "cumulative_layout_shift" ? Math.round(value * 1000) / 1000 : Math.round(value);
|
|
80
|
+
}
|
|
81
|
+
function verdict(value, metric) {
|
|
82
|
+
if (value === null)
|
|
83
|
+
return "unavailable";
|
|
84
|
+
const [good, poor] = thresholds[metric];
|
|
85
|
+
return value <= good ? "good" : value <= poor ? "needs_improvement" : "poor";
|
|
86
|
+
}
|
|
87
|
+
function coreVerdict(metrics) {
|
|
88
|
+
const values = [
|
|
89
|
+
verdict(metrics.largest_contentful_paint, "largest_contentful_paint"),
|
|
90
|
+
verdict(metrics.interaction_to_next_paint, "interaction_to_next_paint"),
|
|
91
|
+
verdict(metrics.cumulative_layout_shift, "cumulative_layout_shift"),
|
|
92
|
+
];
|
|
93
|
+
if (values.includes("unavailable"))
|
|
94
|
+
return "insufficient_data";
|
|
95
|
+
if (values.includes("poor"))
|
|
96
|
+
return "poor";
|
|
97
|
+
if (values.includes("needs_improvement"))
|
|
98
|
+
return "needs_improvement";
|
|
99
|
+
return "good";
|
|
100
|
+
}
|
|
101
|
+
function metricsFrom(record, index, total) {
|
|
102
|
+
const out = emptyMetrics();
|
|
103
|
+
const metrics = recordObject(record.metrics) ?? {};
|
|
104
|
+
for (const metric of CRUX_METRICS) {
|
|
105
|
+
const entry = recordObject(metrics[metric]);
|
|
106
|
+
if (!entry)
|
|
107
|
+
continue;
|
|
108
|
+
if (index === undefined) {
|
|
109
|
+
const fields = recordObject(entry.percentiles);
|
|
110
|
+
out[metric] = percentile(fields?.p75, metric);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const fields = recordObject(entry.percentilesTimeseries);
|
|
114
|
+
const values = fields?.p75s;
|
|
115
|
+
if (!Array.isArray(values) || values.length !== total)
|
|
116
|
+
throw new Error("Malformed CrUX historical percentile series");
|
|
117
|
+
out[metric] = percentile(values[index], metric);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
function addFinding(report, code, severity, message) {
|
|
123
|
+
report.total_findings++;
|
|
124
|
+
if (report.findings.length < MAX_CRUX_FINDINGS)
|
|
125
|
+
report.findings.push({ code, severity, message });
|
|
126
|
+
}
|
|
127
|
+
export function safeCruxTarget(target, granularity) {
|
|
128
|
+
if (typeof target !== "string" || target.length > 512 || /[\u0000-\u001f\u007f\u202a-\u202e\\]/u.test(target))
|
|
129
|
+
return;
|
|
130
|
+
try {
|
|
131
|
+
const url = new URL(target);
|
|
132
|
+
if (url.protocol !== "https:" || url.username || url.password || url.port || url.search || url.hash ||
|
|
133
|
+
!url.hostname.includes(".") || /(?:^|\.)(?:localhost|local|internal|invalid|test)$/iu.test(url.hostname) ||
|
|
134
|
+
/^\d+\.\d+\.\d+\.\d+$/u.test(url.hostname) || url.hostname.includes(":"))
|
|
135
|
+
return;
|
|
136
|
+
if (granularity === "origin") {
|
|
137
|
+
if (target !== url.origin && target !== url.origin + "/")
|
|
138
|
+
return;
|
|
139
|
+
return url.origin;
|
|
140
|
+
}
|
|
141
|
+
return url.href;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export function validateCruxQuery(query) {
|
|
148
|
+
if (!query || !CRUX_MODES.includes(query.mode) || !CRUX_FORMS.includes(query.form_factor) ||
|
|
149
|
+
(query.granularity !== "origin" && query.granularity !== "url"))
|
|
150
|
+
throw new Error("Unsupported CrUX query");
|
|
151
|
+
const target = safeCruxTarget(query.target, query.granularity);
|
|
152
|
+
if (!target)
|
|
153
|
+
throw new Error("Unsafe CrUX target identifier");
|
|
154
|
+
return { ...query, target };
|
|
155
|
+
}
|
|
156
|
+
export function analyzeCruxField(supplied, query, source = "caller_supplied") {
|
|
157
|
+
const q = validateCruxQuery(query);
|
|
158
|
+
if (!CRUX_SOURCES.includes(source))
|
|
159
|
+
throw new Error("Invalid CrUX evidence source");
|
|
160
|
+
if (typeof supplied !== "object" || supplied === null)
|
|
161
|
+
throw new Error("CrUX response is not an object");
|
|
162
|
+
const root = recordObject(supplied);
|
|
163
|
+
const record = recordObject(root?.record);
|
|
164
|
+
const key = recordObject(record?.key);
|
|
165
|
+
if (!record || !key)
|
|
166
|
+
throw new Error("CrUX response is missing record identity");
|
|
167
|
+
const returned = key[q.granularity];
|
|
168
|
+
if (typeof returned !== "string" ||
|
|
169
|
+
safeCruxTarget(returned, q.granularity) !== q.target ||
|
|
170
|
+
(q.form_factor === "ALL" ? key.formFactor !== undefined :
|
|
171
|
+
key.formFactor !== q.form_factor) ||
|
|
172
|
+
(q.granularity === "url" && key.origin !== undefined) ||
|
|
173
|
+
(q.granularity === "origin" && key.url !== undefined)) {
|
|
174
|
+
throw new Error("CrUX response identity or device class does not match the requested record");
|
|
175
|
+
}
|
|
176
|
+
const review = emptyCruxFieldReview(q.mode, source, q.granularity, q.form_factor);
|
|
177
|
+
if (q.mode === "daily") {
|
|
178
|
+
review.period_end = periodEnd(record.collectionPeriod);
|
|
179
|
+
review.p75 = metricsFrom(record);
|
|
180
|
+
review.periods_available = 1;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
const periods = record.collectionPeriods;
|
|
184
|
+
if (!Array.isArray(periods) || periods.length < 1 || periods.length > MAX_CRUX_HISTORY_PERIODS)
|
|
185
|
+
throw new Error("Invalid CrUX history period count");
|
|
186
|
+
let previous = "";
|
|
187
|
+
const all = [];
|
|
188
|
+
for (let i = 0; i < periods.length; i++) {
|
|
189
|
+
const end = periodEnd(periods[i]);
|
|
190
|
+
if (end <= previous)
|
|
191
|
+
throw new Error("CrUX history periods are not strictly ascending");
|
|
192
|
+
previous = end;
|
|
193
|
+
const p75 = metricsFrom(record, i, periods.length);
|
|
194
|
+
all.push({ period: i + 1, period_end: end, p75, core_web_vitals: coreVerdict(p75) });
|
|
195
|
+
}
|
|
196
|
+
review.periods_available = periods.length;
|
|
197
|
+
review.history_points = all.slice(-MAX_CRUX_RETURNED_PERIODS);
|
|
198
|
+
review.periods_returned = review.history_points.length;
|
|
199
|
+
review.period_end = all[all.length - 1].period_end;
|
|
200
|
+
review.p75 = all[all.length - 1].p75;
|
|
201
|
+
for (const metric of CRUX_METRICS) {
|
|
202
|
+
const first = all[0].p75[metric], last = review.p75[metric];
|
|
203
|
+
review.first_last_delta[metric] = first === null || last === null ? null :
|
|
204
|
+
Math.round((last - first) * 1000) / 1000;
|
|
205
|
+
}
|
|
206
|
+
if (all.some(x => x.core_web_vitals === "insufficient_data"))
|
|
207
|
+
addFinding(review, "historical_gaps", "info", "Some historical windows do not have all eligible Core Web Vitals; missing periods were not interpolated.");
|
|
208
|
+
if (CRUX_METRICS.some(m => review.first_last_delta[m] !== null && review.first_last_delta[m] !== 0))
|
|
209
|
+
addFinding(review, "historical_change", "info", "First-versus-last field percentiles differ; overlapping 28-day windows cannot identify a specific deployment cause.");
|
|
210
|
+
}
|
|
211
|
+
review.core_web_vitals = coreVerdict(review.p75);
|
|
212
|
+
for (const metric of CRUX_METRICS) {
|
|
213
|
+
review.metric_verdicts[metric] = verdict(review.p75[metric], metric);
|
|
214
|
+
}
|
|
215
|
+
const missing = CRUX_METRICS.filter(m => review.p75[m] === null);
|
|
216
|
+
review.status = missing.length === 0 ? "complete" : missing.length === CRUX_METRICS.length ? "unavailable" : "partial";
|
|
217
|
+
if (missing.length > 0)
|
|
218
|
+
addFinding(review, "metric_missing", "info", "Some requested CrUX field percentile data are unavailable for the eligible population.");
|
|
219
|
+
if (review.core_web_vitals === "good")
|
|
220
|
+
addFinding(review, "core_web_vitals_good", "info", "All three available real-user CWV p75 values fall in good ranges for this sampled population.");
|
|
221
|
+
else if (review.core_web_vitals === "poor")
|
|
222
|
+
addFinding(review, "core_web_vitals_poor", "warning", "At least one real-user Core Web Vitals p75 value is poor; evaluate the reported device/population.");
|
|
223
|
+
else if (review.core_web_vitals === "needs_improvement")
|
|
224
|
+
addFinding(review, "core_web_vitals_needs_improvement", "warning", "At least one real-user Core Web Vitals p75 value needs improvement.");
|
|
225
|
+
else
|
|
226
|
+
addFinding(review, "insufficient_core_web_vitals", "info", "One or more LCP, INP or CLS percentiles are missing; do not declare the population passed or failed.");
|
|
227
|
+
addFinding(review, "field_sample_only", "info", "Field data are aggregated Chrome experience for an origin or exact page, not all traffic or a current deployment audit.");
|
|
228
|
+
review.findings_truncated = review.total_findings > review.findings.length;
|
|
229
|
+
return review;
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=crux-field.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crux-field.js","sourceRoot":"","sources":["../../../src/modules/external-metrics/crux-field.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,0BAA0B,EAAE,2BAA2B;IACvD,yBAAyB,EAAE,wBAAwB;IACnD,iCAAiC;CACzB,CAAC;AACX,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,SA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AAM,KAAG,CAAC,CAAA,CAAC,CAAA,UAAU,CAAA,CAAC,CAAA,OAAO,CAAC,MAAM,KAAG,YAAY,CAAC,MAAM,CAAA,CAAC,CAAA,aAAa,CAAA,CAAC,CAAA,SAAS,CAAC;IACzG,IAAG,OAAO,CAAC,MAAM,GAAC,CAAC;QAAC,UAAU,CAAC,MAAM,EAAC,gBAAgB,EAAC,MAAM,EAC3D,wFAAwF,CAAC,CAAC;IAC5F,IAAG,MAAM,CAAC,eAAe,KAAG,MAAM;QAAC,UAAU,CAAC,MAAM,EAAC,sBAAsB,EAAC,MAAM,EAChF,+FAA+F,CAAC,CAAC;SAC9F,IAAG,MAAM,CAAC,eAAe,KAAG,MAAM;QAAC,UAAU,CAAC,MAAM,EAAC,sBAAsB,EAAC,SAAS,EACxF,oGAAoG,CAAC,CAAC;SACnG,IAAG,MAAM,CAAC,eAAe,KAAG,mBAAmB;QAAC,UAAU,CAAC,MAAM,EAAC,mCAAmC,EAAC,SAAS,EAClH,qEAAqE,CAAC,CAAC;;QACpE,UAAU,CAAC,MAAM,EAAC,8BAA8B,EAAC,MAAM,EAC1D,sGAAsG,CAAC,CAAC;IAC1G,UAAU,CAAC,MAAM,EAAC,mBAAmB,EAAC,MAAM,EAC1C,yHAAyH,CAAC,CAAC;IAC7H,MAAM,CAAC,kBAAkB,GAAC,MAAM,CAAC,cAAc,GAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;IACvE,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/** V11-FIELD: bounded, evidence-only Chrome UX Report p75 field diagnostics. */\nexport const CRUX_METRICS = [\n \"largest_contentful_paint\", \"interaction_to_next_paint\",\n \"cumulative_layout_shift\", \"first_contentful_paint\",\n \"experimental_time_to_first_byte\",\n] as const;\nexport const CRUX_FORMS = [\"ALL\", \"PHONE\", \"DESKTOP\", \"TABLET\"] as const;\nexport const CRUX_MODES = [\"daily\", \"history\"] as const;\nexport const CRUX_SOURCES = [\"caller_supplied\", \"verified_crux_api\"] as const;\nexport const MAX_CRUX_RESPONSE_BYTES = 300_000;\nexport const MAX_CRUX_HISTORY_PERIODS = 40;\nexport const MAX_CRUX_RETURNED_PERIODS = 8;\nexport const MAX_CRUX_FINDINGS = 12;\nexport const CRUX_FINDING_CODES = [\n \"metric_missing\", \"core_web_vitals_good\", \"core_web_vitals_poor\",\n \"core_web_vitals_needs_improvement\", \"insufficient_core_web_vitals\",\n \"historical_gaps\", \"historical_change\", \"field_sample_only\",\n] as const;\nexport type CruxMode = typeof CRUX_MODES[number];\nexport type CruxForm = typeof CRUX_FORMS[number];\nexport type CruxSource = typeof CRUX_SOURCES[number];\nexport type CruxMetric = typeof CRUX_METRICS[number];\nexport type CruxCode = typeof CRUX_FINDING_CODES[number];\nexport type CruxVerdict = \"good\" | \"needs_improvement\" | \"poor\" | \"unavailable\";\ntype CruxMetrics = Record<CruxMetric, number | null>;\nexport interface CruxFinding { code: CruxCode; severity: \"warning\" | \"info\"; message: string }\nexport interface CruxHistoryPoint {\n period: number;\n period_end: string;\n p75: CruxMetrics;\n core_web_vitals: \"good\" | \"needs_improvement\" | \"poor\" | \"insufficient_data\";\n}\nexport interface CruxFieldReview {\n scope: \"crux_real_user_field_p75\";\n mode: CruxMode;\n source: CruxSource;\n granularity: \"origin\" | \"url\";\n form_factor: CruxForm;\n status: \"complete\" | \"partial\" | \"unavailable\";\n period_end: string | null;\n p75: CruxMetrics;\n metric_verdicts: Record<CruxMetric, CruxVerdict>;\n core_web_vitals: \"good\" | \"needs_improvement\" | \"poor\" | \"insufficient_data\";\n periods_available: number;\n periods_returned: number;\n history_points: CruxHistoryPoint[];\n first_last_delta: CruxMetrics;\n coverage_limited: true;\n limitations: string[];\n total_findings: number;\n findings: CruxFinding[];\n findings_truncated: boolean;\n error?: string;\n}\nconst thresholds: Record<CruxMetric, [number,number]> = {\n largest_contentful_paint: [2500, 4000],\n interaction_to_next_paint: [200,500],\n cumulative_layout_shift: [0.1,0.25],\n first_contentful_paint: [1800,3000],\n experimental_time_to_first_byte: [800,1800],\n};\nconst limitations = [\n \"CrUX percentiles represent aggregated eligible Chrome real-user experiences over rolling 28-day windows, not a current page fetch or an exhaustive sample of every visitor.\",\n \"URL-level and origin-level records cover different populations; returned p75 values cannot be combined across them or interpreted as a Lighthouse laboratory score.\",\n \"History entries are overlapping weekly 28-day windows, not independent weekly samples. Missing eligible data stays null; no causality, traffic, Google ranking or indexing conclusion.\",\n \"Caller-supplied JSON is not authenticated CrUX evidence; live source requires an explicit opt-in and a local CRUX_API_KEY environment variable.\",\n];\nconst emptyMetrics = (): CruxMetrics => Object.fromEntries(CRUX_METRICS.map(k=>[k,null])) as CruxMetrics;\nconst emptyVerdicts = (): Record<CruxMetric,CruxVerdict> =>\n Object.fromEntries(CRUX_METRICS.map(k=>[k,\"unavailable\"])) as Record<CruxMetric,CruxVerdict>;\nexport function emptyCruxFieldReview(\n mode: CruxMode=\"daily\", source: CruxSource=\"caller_supplied\",\n granularity:\"origin\"|\"url\"=\"origin\", form:CruxForm=\"ALL\",\n): CruxFieldReview {\n return {\n scope:\"crux_real_user_field_p75\", mode, source, granularity,\n form_factor: form, status:\"unavailable\", period_end:null,\n p75:emptyMetrics(),metric_verdicts:emptyVerdicts(),core_web_vitals:\"insufficient_data\",\n periods_available:0, periods_returned:0, history_points:[],\n first_last_delta:emptyMetrics(),coverage_limited:true,limitations,\n total_findings:0,findings:[],findings_truncated:false,\n };\n}\nfunction recordObject(value:unknown):Record<string,unknown>|undefined {\n return value !== null && typeof value===\"object\" && !Array.isArray(value)\n ? value as Record<string,unknown> : undefined;\n}\nfunction dateValue(value:unknown):string {\n const d=recordObject(value);\n if (!d||!Number.isInteger(d.year)||!Number.isInteger(d.month)||!Number.isInteger(d.day))\n throw new Error(\"Invalid CrUX collection date\");\n const year=d.year as number, month=d.month as number, day=d.day as number;\n if(year<2000||year>2100||month<1||month>12||day<1||day>31)\n throw new Error(\"Invalid CrUX collection date\");\n const timestamp=Date.UTC(year,month-1,day);\n const parsed=new Date(timestamp);\n if (parsed.getUTCFullYear()!==year||parsed.getUTCMonth()!==month-1||parsed.getUTCDate()!==day)\n throw new Error(\"Invalid CrUX collection date\");\n return parsed.toISOString().slice(0,10);\n}\nfunction periodEnd(period:unknown):string {\n const p=recordObject(period);\n if(!p) throw new Error(\"Missing CrUX collection period\");\n const start=dateValue(p.firstDate), end=dateValue(p.lastDate);\n const days=(Date.parse(end)-Date.parse(start))/86400000;\n if(days!==27) throw new Error(\"Unexpected CrUX collection window\");\n return end;\n}\nfunction percentile(raw:unknown,metric:CruxMetric):number|null {\n if(raw===null||raw===undefined||raw===\"NaN\") return null;\n const value=typeof raw===\"number\"?raw:\n metric===\"cumulative_layout_shift\"&&typeof raw===\"string\"&&/^\\d+(?:\\.\\d{1,5})?$/u.test(raw)\n ?Number(raw):Number.NaN;\n if(!Number.isFinite(value)||value<0||value>(metric===\"cumulative_layout_shift\"?100:600000)) return null;\n return metric===\"cumulative_layout_shift\"?Math.round(value*1000)/1000:Math.round(value);\n}\nfunction verdict(value:number|null,metric:CruxMetric):CruxVerdict {\n if (value===null) return \"unavailable\";\n const [good,poor]=thresholds[metric];\n return value<=good?\"good\":value<=poor?\"needs_improvement\":\"poor\";\n}\nfunction coreVerdict(metrics:CruxMetrics):CruxFieldReview[\"core_web_vitals\"] {\n const values=[\n verdict(metrics.largest_contentful_paint,\"largest_contentful_paint\"),\n verdict(metrics.interaction_to_next_paint,\"interaction_to_next_paint\"),\n verdict(metrics.cumulative_layout_shift,\"cumulative_layout_shift\"),\n ];\n if(values.includes(\"unavailable\"))return \"insufficient_data\";\n if(values.includes(\"poor\"))return \"poor\";\n if(values.includes(\"needs_improvement\"))return \"needs_improvement\";\n return \"good\";\n}\nfunction metricsFrom(record:Record<string,unknown>,index?:number,total?:number):CruxMetrics {\n const out=emptyMetrics();\n const metrics=recordObject(record.metrics)??{};\n for(const metric of CRUX_METRICS) {\n const entry=recordObject(metrics[metric]);\n if(!entry)continue;\n if (index===undefined) {\n const fields=recordObject(entry.percentiles);\n out[metric]=percentile(fields?.p75,metric);\n } else {\n const fields=recordObject(entry.percentilesTimeseries);\n const values=fields?.p75s;\n if(!Array.isArray(values)||values.length!==total) throw new Error(\"Malformed CrUX historical percentile series\");\n out[metric]=percentile(values[index],metric);\n }\n }\n return out;\n}\nfunction addFinding(report:CruxFieldReview,code:CruxCode,severity:CruxFinding[\"severity\"],message:string):void{\n report.total_findings++;\n if(report.findings.length<MAX_CRUX_FINDINGS)report.findings.push({code,severity,message});\n}\nexport interface CruxQuery {\n granularity:\"origin\"|\"url\";\n target:string;\n form_factor:CruxForm;\n mode:CruxMode;\n}\nexport function safeCruxTarget(target:unknown,granularity:\"origin\"|\"url\"):string|undefined {\n if(typeof target!==\"string\"||target.length>512||/[\\u0000-\\u001f\\u007f\\u202a-\\u202e\\\\]/u.test(target))return;\n try{\n const url=new URL(target);\n if(url.protocol!==\"https:\"||url.username||url.password||url.port||url.search||url.hash||\n !url.hostname.includes(\".\")||/(?:^|\\.)(?:localhost|local|internal|invalid|test)$/iu.test(url.hostname)||\n /^\\d+\\.\\d+\\.\\d+\\.\\d+$/u.test(url.hostname)||url.hostname.includes(\":\")) return;\n if(granularity===\"origin\") {\n if(target!==url.origin && target!==url.origin+\"/\")return;\n return url.origin;\n }\n return url.href;\n }catch{return;}\n}\nexport function validateCruxQuery(query:CruxQuery):CruxQuery{\n if(!query||!CRUX_MODES.includes(query.mode)||!CRUX_FORMS.includes(query.form_factor)||\n (query.granularity!==\"origin\"&&query.granularity!==\"url\"))throw new Error(\"Unsupported CrUX query\");\n const target=safeCruxTarget(query.target,query.granularity);\n if(!target)throw new Error(\"Unsafe CrUX target identifier\");\n return {...query,target};\n}\nexport function analyzeCruxField(\n supplied:unknown, query:CruxQuery, source:CruxSource=\"caller_supplied\",\n):CruxFieldReview {\n const q=validateCruxQuery(query);\n if(!CRUX_SOURCES.includes(source))throw new Error(\"Invalid CrUX evidence source\");\n if(typeof supplied!==\"object\"||supplied===null)throw new Error(\"CrUX response is not an object\");\n const root=recordObject(supplied);\n const record=recordObject(root?.record);\n const key=recordObject(record?.key);\n if(!record||!key)throw new Error(\"CrUX response is missing record identity\");\n const returned=key[q.granularity];\n if(typeof returned!==\"string\"||\n safeCruxTarget(returned,q.granularity)!==q.target||\n (q.form_factor===\"ALL\" ? key.formFactor!==undefined :\n key.formFactor!==q.form_factor) ||\n (q.granularity===\"url\"&&key.origin!==undefined) ||\n (q.granularity===\"origin\"&&key.url!==undefined)) {\n throw new Error(\"CrUX response identity or device class does not match the requested record\");\n }\n const review=emptyCruxFieldReview(q.mode,source,q.granularity,q.form_factor);\n if(q.mode===\"daily\"){\n review.period_end=periodEnd(record.collectionPeriod);\n review.p75=metricsFrom(record);\n review.periods_available=1;\n }else{\n const periods=record.collectionPeriods;\n if(!Array.isArray(periods)||periods.length<1||periods.length>MAX_CRUX_HISTORY_PERIODS)\n throw new Error(\"Invalid CrUX history period count\");\n let previous=\"\";\n const all:CruxHistoryPoint[]=[];\n for(let i=0;i<periods.length;i++) {\n const end=periodEnd(periods[i]);\n if(end<=previous)throw new Error(\"CrUX history periods are not strictly ascending\");\n previous=end;\n const p75=metricsFrom(record,i,periods.length);\n all.push({period:i+1,period_end:end,p75,core_web_vitals:coreVerdict(p75)});\n }\n review.periods_available=periods.length;\n review.history_points=all.slice(-MAX_CRUX_RETURNED_PERIODS);\n review.periods_returned=review.history_points.length;\n review.period_end=all[all.length-1].period_end;\n review.p75=all[all.length-1].p75;\n for(const metric of CRUX_METRICS){\n const first=all[0].p75[metric],last=review.p75[metric];\n review.first_last_delta[metric]=first===null||last===null?null:\n Math.round((last-first)*1000)/1000;\n }\n if (all.some(x=>x.core_web_vitals===\"insufficient_data\"))\n addFinding(review,\"historical_gaps\",\"info\",\n \"Some historical windows do not have all eligible Core Web Vitals; missing periods were not interpolated.\");\n if(CRUX_METRICS.some(m=>review.first_last_delta[m]!==null&&review.first_last_delta[m]!==0))\n addFinding(review,\"historical_change\",\"info\",\n \"First-versus-last field percentiles differ; overlapping 28-day windows cannot identify a specific deployment cause.\");\n }\n review.core_web_vitals=coreVerdict(review.p75);\n for(const metric of CRUX_METRICS) {\n review.metric_verdicts[metric]=verdict(review.p75[metric],metric);\n }\n const missing=CRUX_METRICS.filter(m=>review.p75[m]===null);\n review.status=missing.length===0?\"complete\":missing.length===CRUX_METRICS.length?\"unavailable\":\"partial\";\n if(missing.length>0)addFinding(review,\"metric_missing\",\"info\",\n \"Some requested CrUX field percentile data are unavailable for the eligible population.\");\n if(review.core_web_vitals===\"good\")addFinding(review,\"core_web_vitals_good\",\"info\",\n \"All three available real-user CWV p75 values fall in good ranges for this sampled population.\");\n else if(review.core_web_vitals===\"poor\")addFinding(review,\"core_web_vitals_poor\",\"warning\",\n \"At least one real-user Core Web Vitals p75 value is poor; evaluate the reported device/population.\");\n else if(review.core_web_vitals===\"needs_improvement\")addFinding(review,\"core_web_vitals_needs_improvement\",\"warning\",\n \"At least one real-user Core Web Vitals p75 value needs improvement.\");\n else addFinding(review,\"insufficient_core_web_vitals\",\"info\",\n \"One or more LCP, INP or CLS percentiles are missing; do not declare the population passed or failed.\");\n addFinding(review,\"field_sample_only\",\"info\",\n \"Field data are aggregated Chrome experience for an origin or exact page, not all traffic or a current deployment audit.\");\n review.findings_truncated=review.total_findings>review.findings.length;\n return review;\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V02: bounded point-in-time availability-history observations.
|
|
3
|
+
* This is an analyzer of observed outcomes, NOT an uptime monitor, a scheduler,
|
|
4
|
+
* a Googlebot verification tool, or evidence of continuous availability.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MAX_AVAILABILITY_OBSERVATIONS = 48;
|
|
7
|
+
export declare const MAX_AVAILABILITY_FINDINGS = 12;
|
|
8
|
+
export declare const AVAILABILITY_FAILURE_CODES: readonly ["timeout", "dns_error", "network_error", "fetch_error", "policy_blocked"];
|
|
9
|
+
export declare const AVAILABILITY_STATES: readonly ["success", "challenge", "redirect", "forbidden", "rate_limited", "client_error", "server_error", "timeout", "transport_error", "policy_blocked", "other"];
|
|
10
|
+
export declare const AVAILABILITY_FINDING_CODES: readonly ["intermittent_non_success", "latest_non_success", "rate_limiting", "server_failures", "transport_failures", "challenge_observed", "status_transitions", "sparse_samples", "large_sampling_gap"];
|
|
11
|
+
export type AvailabilityFailureCode = typeof AVAILABILITY_FAILURE_CODES[number];
|
|
12
|
+
export type AvailabilityState = typeof AVAILABILITY_STATES[number];
|
|
13
|
+
export type AvailabilityFindingCode = typeof AVAILABILITY_FINDING_CODES[number];
|
|
14
|
+
export interface AvailabilityObservation {
|
|
15
|
+
observed_at: string;
|
|
16
|
+
status_code?: number;
|
|
17
|
+
failure?: AvailabilityFailureCode;
|
|
18
|
+
cf_challenge?: boolean;
|
|
19
|
+
elapsed_ms?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface AvailabilitySample {
|
|
22
|
+
observation: number;
|
|
23
|
+
observed_at: string;
|
|
24
|
+
status_code?: number;
|
|
25
|
+
state: AvailabilityState;
|
|
26
|
+
cf_challenge: boolean;
|
|
27
|
+
elapsed_ms?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface AvailabilityFinding {
|
|
30
|
+
code: AvailabilityFindingCode;
|
|
31
|
+
severity: "warning" | "info";
|
|
32
|
+
message: string;
|
|
33
|
+
}
|
|
34
|
+
export interface AvailabilityReview {
|
|
35
|
+
scope: "caller_supplied_history" | "live_bounded_burst" | "local_saved_history";
|
|
36
|
+
observations_count: number;
|
|
37
|
+
first_observed_at?: string;
|
|
38
|
+
last_observed_at?: string;
|
|
39
|
+
sampled_window_minutes: number;
|
|
40
|
+
max_observation_gap_minutes: number;
|
|
41
|
+
observed_successes: number;
|
|
42
|
+
observed_redirects: number;
|
|
43
|
+
observed_http_4xx: number;
|
|
44
|
+
observed_http_5xx: number;
|
|
45
|
+
observed_timeouts: number;
|
|
46
|
+
observed_transport_failures: number;
|
|
47
|
+
observed_rate_limits: number;
|
|
48
|
+
observed_challenges: number;
|
|
49
|
+
observed_success_percent: number;
|
|
50
|
+
http_status_changes: number;
|
|
51
|
+
outcome_changes: number;
|
|
52
|
+
intermittent_non_success: boolean;
|
|
53
|
+
longest_non_success_streak: number;
|
|
54
|
+
current_non_success_streak: number;
|
|
55
|
+
latest_observed_state?: AvailabilityState;
|
|
56
|
+
latest_http_status?: number;
|
|
57
|
+
coverage_limited: true;
|
|
58
|
+
limitations: string[];
|
|
59
|
+
samples: AvailabilitySample[];
|
|
60
|
+
total_findings: number;
|
|
61
|
+
findings: AvailabilityFinding[];
|
|
62
|
+
findings_truncated: boolean;
|
|
63
|
+
error?: string;
|
|
64
|
+
}
|
|
65
|
+
export declare function emptyAvailabilityReview(scope?: AvailabilityReview["scope"]): AvailabilityReview;
|
|
66
|
+
export declare function validateAvailabilityObservation(value: AvailabilityObservation): number;
|
|
67
|
+
export declare function availabilityState(value: AvailabilityObservation): AvailabilityState;
|
|
68
|
+
export declare function analyzeAvailabilityHistory(observations: AvailabilityObservation[], scope?: AvailabilityReview["scope"]): AvailabilityReview;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V02: bounded point-in-time availability-history observations.
|
|
3
|
+
* This is an analyzer of observed outcomes, NOT an uptime monitor, a scheduler,
|
|
4
|
+
* a Googlebot verification tool, or evidence of continuous availability.
|
|
5
|
+
*/
|
|
6
|
+
export const MAX_AVAILABILITY_OBSERVATIONS = 48;
|
|
7
|
+
export const MAX_AVAILABILITY_FINDINGS = 12;
|
|
8
|
+
export const AVAILABILITY_FAILURE_CODES = [
|
|
9
|
+
"timeout", "dns_error", "network_error", "fetch_error", "policy_blocked",
|
|
10
|
+
];
|
|
11
|
+
export const AVAILABILITY_STATES = [
|
|
12
|
+
"success", "challenge", "redirect", "forbidden", "rate_limited", "client_error",
|
|
13
|
+
"server_error", "timeout", "transport_error", "policy_blocked", "other",
|
|
14
|
+
];
|
|
15
|
+
export const AVAILABILITY_FINDING_CODES = [
|
|
16
|
+
"intermittent_non_success", "latest_non_success", "rate_limiting",
|
|
17
|
+
"server_failures", "transport_failures", "challenge_observed",
|
|
18
|
+
"status_transitions", "sparse_samples", "large_sampling_gap",
|
|
19
|
+
];
|
|
20
|
+
const limitations = [
|
|
21
|
+
"Sampled response outcomes cannot establish continuous uptime, actual outage duration, or unobserved intervals.",
|
|
22
|
+
"The timestamps and HTTP outcomes are supplied or observed by this caller, not verified crawler-log evidence.",
|
|
23
|
+
"A short live burst tests only a brief window; repeat checks and retain snapshots for historical trend evidence.",
|
|
24
|
+
];
|
|
25
|
+
export function emptyAvailabilityReview(scope = "caller_supplied_history") {
|
|
26
|
+
return {
|
|
27
|
+
scope, observations_count: 0, sampled_window_minutes: 0, max_observation_gap_minutes: 0,
|
|
28
|
+
observed_successes: 0, observed_redirects: 0, observed_http_4xx: 0,
|
|
29
|
+
observed_http_5xx: 0, observed_timeouts: 0, observed_transport_failures: 0,
|
|
30
|
+
observed_rate_limits: 0, observed_challenges: 0, observed_success_percent: 0,
|
|
31
|
+
http_status_changes: 0, outcome_changes: 0, intermittent_non_success: false,
|
|
32
|
+
longest_non_success_streak: 0, current_non_success_streak: 0,
|
|
33
|
+
coverage_limited: true, limitations, samples: [], total_findings: 0,
|
|
34
|
+
findings: [], findings_truncated: false,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const timestampPattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/u;
|
|
38
|
+
const failures = new Set(AVAILABILITY_FAILURE_CODES);
|
|
39
|
+
export function validateAvailabilityObservation(value) {
|
|
40
|
+
if (!value || typeof value !== "object" ||
|
|
41
|
+
typeof value.observed_at !== "string" || value.observed_at.length > 40 ||
|
|
42
|
+
!timestampPattern.test(value.observed_at)) {
|
|
43
|
+
throw new Error("Each availability sample requires an ISO timestamp with an explicit UTC offset.");
|
|
44
|
+
}
|
|
45
|
+
const year = Number(value.observed_at.slice(0, 4));
|
|
46
|
+
const month = Number(value.observed_at.slice(5, 7));
|
|
47
|
+
const day = Number(value.observed_at.slice(8, 10));
|
|
48
|
+
const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
49
|
+
const daysInMonth = [31, leapYear ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
50
|
+
if (month < 1 || month > 12 || day < 1 || day > daysInMonth[month - 1]) {
|
|
51
|
+
throw new Error("Availability observation must have a real calendar day.");
|
|
52
|
+
}
|
|
53
|
+
const timestamp = Date.parse(value.observed_at);
|
|
54
|
+
if (!Number.isFinite(timestamp))
|
|
55
|
+
throw new Error("The availability timestamp must be a real date.");
|
|
56
|
+
const hasStatus = value.status_code !== undefined;
|
|
57
|
+
const hasFailure = value.failure !== undefined;
|
|
58
|
+
if (hasStatus === hasFailure) {
|
|
59
|
+
throw new Error("Exactly one of status_code or failure is required per observation.");
|
|
60
|
+
}
|
|
61
|
+
if (hasStatus && (!Number.isInteger(value.status_code) ||
|
|
62
|
+
value.status_code < 100 || value.status_code > 599)) {
|
|
63
|
+
throw new Error("HTTP status must be an observed integer between 100 and 599.");
|
|
64
|
+
}
|
|
65
|
+
if (hasFailure && !failures.has(value.failure)) {
|
|
66
|
+
throw new Error("Unrecognized availability failure code.");
|
|
67
|
+
}
|
|
68
|
+
if (value.cf_challenge !== undefined &&
|
|
69
|
+
(typeof value.cf_challenge !== "boolean" || (!hasStatus && value.cf_challenge))) {
|
|
70
|
+
throw new Error("A challenge flag requires an actual HTTP response.");
|
|
71
|
+
}
|
|
72
|
+
if (value.elapsed_ms !== undefined &&
|
|
73
|
+
(!Number.isInteger(value.elapsed_ms) || value.elapsed_ms < 0 || value.elapsed_ms > 120_000)) {
|
|
74
|
+
throw new Error("Response elapsed_ms must be a nonnegative integer at most 120,000.");
|
|
75
|
+
}
|
|
76
|
+
return timestamp;
|
|
77
|
+
}
|
|
78
|
+
export function availabilityState(value) {
|
|
79
|
+
if (value.failure === "timeout")
|
|
80
|
+
return "timeout";
|
|
81
|
+
if (value.failure === "policy_blocked")
|
|
82
|
+
return "policy_blocked";
|
|
83
|
+
if (value.failure !== undefined)
|
|
84
|
+
return "transport_error";
|
|
85
|
+
const code = value.status_code;
|
|
86
|
+
// Cloudflare challenges sometimes use HTTP 200; this is not proof that the
|
|
87
|
+
// protected page was delivered. Keep 403/429 error classes distinct.
|
|
88
|
+
if (value.cf_challenge === true && code >= 200 && code < 300)
|
|
89
|
+
return "challenge";
|
|
90
|
+
if (code === 403)
|
|
91
|
+
return "forbidden";
|
|
92
|
+
if (code === 429)
|
|
93
|
+
return "rate_limited";
|
|
94
|
+
if (code >= 500)
|
|
95
|
+
return "server_error";
|
|
96
|
+
if (code >= 400)
|
|
97
|
+
return "client_error";
|
|
98
|
+
if (code >= 300 && code < 400)
|
|
99
|
+
return "redirect";
|
|
100
|
+
if (code >= 200 && code < 300)
|
|
101
|
+
return "success";
|
|
102
|
+
return "other";
|
|
103
|
+
}
|
|
104
|
+
export function analyzeAvailabilityHistory(observations, scope = "caller_supplied_history") {
|
|
105
|
+
if (!Array.isArray(observations) || observations.length < 2 ||
|
|
106
|
+
observations.length > MAX_AVAILABILITY_OBSERVATIONS) {
|
|
107
|
+
throw new Error("Supply two to 48 ordered availability observations.");
|
|
108
|
+
}
|
|
109
|
+
const times = observations.map(validateAvailabilityObservation);
|
|
110
|
+
for (let i = 1; i < times.length; i += 1) {
|
|
111
|
+
if (times[i] <= times[i - 1]) {
|
|
112
|
+
throw new Error("Availability timestamps must be unique and strictly chronological.");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const r = emptyAvailabilityReview(scope);
|
|
116
|
+
r.observations_count = observations.length;
|
|
117
|
+
r.first_observed_at = new Date(times[0]).toISOString();
|
|
118
|
+
r.last_observed_at = new Date(times[times.length - 1]).toISOString();
|
|
119
|
+
r.sampled_window_minutes = Math.round((times[times.length - 1] - times[0]) / 600) / 100;
|
|
120
|
+
let maxGap = 0;
|
|
121
|
+
let streak = 0;
|
|
122
|
+
let hasNonSuccess = false;
|
|
123
|
+
let previousState;
|
|
124
|
+
let previousHttpStatus;
|
|
125
|
+
for (let i = 0; i < observations.length; i += 1) {
|
|
126
|
+
const value = observations[i];
|
|
127
|
+
const state = availabilityState(value);
|
|
128
|
+
const success = state === "success";
|
|
129
|
+
const challenge = value.cf_challenge === true;
|
|
130
|
+
r.samples.push({
|
|
131
|
+
observation: i + 1,
|
|
132
|
+
observed_at: new Date(times[i]).toISOString(),
|
|
133
|
+
...(value.status_code === undefined ? {} : { status_code: value.status_code }),
|
|
134
|
+
state, cf_challenge: challenge,
|
|
135
|
+
...(value.elapsed_ms === undefined ? {} : { elapsed_ms: value.elapsed_ms }),
|
|
136
|
+
});
|
|
137
|
+
if (success)
|
|
138
|
+
r.observed_successes++;
|
|
139
|
+
else {
|
|
140
|
+
hasNonSuccess = true;
|
|
141
|
+
streak += 1;
|
|
142
|
+
r.longest_non_success_streak = Math.max(r.longest_non_success_streak, streak);
|
|
143
|
+
}
|
|
144
|
+
if (success)
|
|
145
|
+
streak = 0;
|
|
146
|
+
if (state === "redirect")
|
|
147
|
+
r.observed_redirects++;
|
|
148
|
+
if (value.status_code !== undefined) {
|
|
149
|
+
if (value.status_code >= 400 && value.status_code < 500)
|
|
150
|
+
r.observed_http_4xx++;
|
|
151
|
+
if (value.status_code >= 500)
|
|
152
|
+
r.observed_http_5xx++;
|
|
153
|
+
if (value.status_code === 429)
|
|
154
|
+
r.observed_rate_limits++;
|
|
155
|
+
if (previousHttpStatus !== undefined && previousHttpStatus !== value.status_code) {
|
|
156
|
+
r.http_status_changes += 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (state === "timeout")
|
|
160
|
+
r.observed_timeouts++;
|
|
161
|
+
if (value.failure !== undefined)
|
|
162
|
+
r.observed_transport_failures++;
|
|
163
|
+
if (challenge)
|
|
164
|
+
r.observed_challenges++;
|
|
165
|
+
if (previousState !== undefined && previousState !== state)
|
|
166
|
+
r.outcome_changes += 1;
|
|
167
|
+
if (i > 0)
|
|
168
|
+
maxGap = Math.max(maxGap, times[i] - times[i - 1]);
|
|
169
|
+
previousState = state;
|
|
170
|
+
previousHttpStatus = value.status_code;
|
|
171
|
+
r.latest_observed_state = state;
|
|
172
|
+
r.latest_http_status = value.status_code;
|
|
173
|
+
}
|
|
174
|
+
r.current_non_success_streak = streak;
|
|
175
|
+
r.max_observation_gap_minutes = Math.round(maxGap / 600) / 100;
|
|
176
|
+
r.observed_success_percent = Math.round(r.observed_successes * 100 / observations.length);
|
|
177
|
+
r.intermittent_non_success = hasNonSuccess && r.observed_successes > 0;
|
|
178
|
+
const add = (code, severity, message) => {
|
|
179
|
+
r.total_findings++;
|
|
180
|
+
if (r.findings.length < MAX_AVAILABILITY_FINDINGS) {
|
|
181
|
+
r.findings.push({ code, severity, message });
|
|
182
|
+
}
|
|
183
|
+
else
|
|
184
|
+
r.findings_truncated = true;
|
|
185
|
+
};
|
|
186
|
+
if (r.intermittent_non_success)
|
|
187
|
+
add("intermittent_non_success", "warning", "Both successful and non-successful HTTP/transport outcomes occurred in these discrete samples.");
|
|
188
|
+
if (r.latest_observed_state !== "success")
|
|
189
|
+
add("latest_non_success", "warning", "The last sampled response was not a completed HTTP 2xx; verify whether the condition remains.");
|
|
190
|
+
if (r.observed_rate_limits > 0)
|
|
191
|
+
add("rate_limiting", "warning", "At least one sampled response reported HTTP 429 rate limiting.");
|
|
192
|
+
if (r.observed_http_5xx > 0)
|
|
193
|
+
add("server_failures", "warning", "One or more sampled HTTP 5xx responses were observed.");
|
|
194
|
+
if (r.observed_transport_failures > 0)
|
|
195
|
+
add("transport_failures", "warning", "One or more sampled requests returned no HTTP response.");
|
|
196
|
+
if (r.observed_challenges > 0)
|
|
197
|
+
add("challenge_observed", "warning", "One or more samples carried an explicit Cloudflare challenge flag.");
|
|
198
|
+
if (r.http_status_changes > 0)
|
|
199
|
+
add("status_transitions", "info", "HTTP status codes changed between adjacent response observations.");
|
|
200
|
+
if (observations.length < 3)
|
|
201
|
+
add("sparse_samples", "info", "Only two samples were supplied; more observations improve interpretation.");
|
|
202
|
+
if (r.max_observation_gap_minutes >= 60)
|
|
203
|
+
add("large_sampling_gap", "info", "Samples include at least one gap of an hour or more; no continuity is established during gaps.");
|
|
204
|
+
return r;
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=availability-observations.js.map
|