tagreeve 0.6.2 → 0.7.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +10 -5
  2. package/dist/cli.js +637 -226
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -583,6 +583,47 @@ function valueKinds(text2) {
583
583
  for (const c of candidates(text2)) kinds.add(c.kind);
584
584
  return kinds;
585
585
  }
586
+ function ownValueKinds(text2, identity) {
587
+ const { own, emailHashes, phoneHashes } = ownMatcher(identity);
588
+ const kinds = /* @__PURE__ */ new Set();
589
+ const isPhone = (digits2) => digits2.includes(own.phoneDigits) || digits2.includes(own.nationalDigits) || own.extraPhones.includes(digits2);
590
+ const addHash = (value) => {
591
+ const bare = value.replace(/=+$/, "");
592
+ if (emailHashes.has(bare)) kinds.add("email hash");
593
+ if (phoneHashes.has(bare)) kinds.add("phone hash");
594
+ };
595
+ for (const c of candidates(text2)) {
596
+ if (c.kind === "email") {
597
+ const email = normalizeEmail(c.value);
598
+ if (email.includes(own.email) || own.extraEmails.includes(email)) kinds.add("email");
599
+ } else if (c.kind === "phone") {
600
+ if (isPhone(c.value.replace(/\D/g, ""))) kinds.add("phone");
601
+ } else addHash(c.value.toLowerCase());
602
+ }
603
+ if (/^[+\d\s().-]+$/.test(text2) && isPhone(text2.replace(/\D/g, ""))) kinds.add("phone");
604
+ const trimmed = text2.trim();
605
+ addHash(trimmed);
606
+ addHash(trimmed.toLowerCase());
607
+ for (const variant of variants(text2)) {
608
+ for (const token of hasUrlEscapes(variant) ? [] : keyedDigests(variant)) addHash(token);
609
+ }
610
+ return kinds;
611
+ }
612
+ var matchers = /* @__PURE__ */ new WeakMap();
613
+ function ownMatcher(identity) {
614
+ let matcher = matchers.get(identity);
615
+ if (!matcher) {
616
+ const own = ownValues(identity);
617
+ const phoneExtras = (identity.extra ?? []).filter((v) => /^[+\d\s().-]+$/.test(v) && own.extraPhones.includes(v.replace(/\D/g, "")));
618
+ matcher = {
619
+ own,
620
+ emailHashes: fieldHashes(own.email, ...own.extraEmails),
621
+ phoneHashes: fieldHashes("+" + own.phoneDigits, own.phoneDigits, ...phoneExtras, ...phoneExtras.map((v) => v.replace(/\D/g, "")), ...phoneExtras.map((v) => "+" + v.replace(/\D/g, "")))
622
+ };
623
+ matchers.set(identity, matcher);
624
+ }
625
+ return matcher;
626
+ }
586
627
  function scan(text2, identity, options = {}) {
587
628
  const own = ownValues(identity);
588
629
  const found = /* @__PURE__ */ new Map();
@@ -637,6 +678,23 @@ function globToRegExp(glob) {
637
678
  // packages/core/src/limits.ts
638
679
  var MAX_POST_DATA = 64 * 1024;
639
680
 
681
+ // packages/core/src/consent-command.ts
682
+ var MAX_ARGUMENTS = 16;
683
+ var CONSENT_COMMANDS = /* @__PURE__ */ new Set(["default", "update"]);
684
+ function argumentsListOf(args) {
685
+ const [item] = args;
686
+ if (args.length !== 1 || typeof item !== "object" || item === null || Array.isArray(item)) return void 0;
687
+ const keys = Object.keys(item);
688
+ if (keys.length < 1 || keys.length > MAX_ARGUMENTS || !keys.every((k, i) => k === String(i))) return void 0;
689
+ const list3 = keys.map((_, i) => item[String(i)]);
690
+ return typeof list3[0] === "string" ? list3 : void 0;
691
+ }
692
+ function consentCommandOf(args) {
693
+ const list3 = typeof args[0] === "string" ? args : argumentsListOf(args);
694
+ if (list3 === void 0 || list3[0] !== "consent" || typeof list3[1] !== "string" || !CONSENT_COMMANDS.has(list3[1])) return void 0;
695
+ return { command: list3[1], signals: list3[2] };
696
+ }
697
+
640
698
  // packages/decoders/src/decoder.ts
641
699
  var defaultHitId = () => newId("hit");
642
700
  var vendorKeys = ["ga4", "google-ads", "meta", "meta-capi", "pinterest", "sgtm"];
@@ -884,6 +942,58 @@ function maskValuePath(path, mask) {
884
942
  return maskSegments(path.slice(0, prefix.index)) + prefix[0] + maskSegments(path.slice(end));
885
943
  }
886
944
 
945
+ // packages/decoders/src/base64.ts
946
+ var ALPHABET2 = /^[A-Za-z0-9+/_-]+={0,2}$/;
947
+ function decodeBase64Text(value) {
948
+ const v = value.replace(/ /g, "+");
949
+ if (v.length < 4 || !ALPHABET2.test(v)) return void 0;
950
+ const bare = v.replace(/=+$/, "");
951
+ if (bare.length % 4 === 1) return void 0;
952
+ const text2 = Buffer.from(bare.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8");
953
+ return text2.includes("\uFFFD") ? void 0 : text2;
954
+ }
955
+
956
+ // packages/decoders/src/stape-custom-loader.ts
957
+ var STAPE_LOADER_TRANSPORT = "stape-loader";
958
+ function unwrapStapeLoader(req) {
959
+ let url;
960
+ try {
961
+ url = new URL(req.url);
962
+ } catch {
963
+ return void 0;
964
+ }
965
+ if (!/^\/[^/]+$/.test(url.pathname)) return void 0;
966
+ const real = [];
967
+ for (const [, value] of url.searchParams) {
968
+ const decoded = decodeBase64Text(value);
969
+ if (decoded && /^\/[^/\s\\][\x21-\x7e]*$/.test(decoded)) real.push(decoded);
970
+ }
971
+ if (real.length !== 1) return void 0;
972
+ try {
973
+ return { ...req, url: new URL(real[0], url.origin).href };
974
+ } catch {
975
+ return void 0;
976
+ }
977
+ }
978
+ function createStapeCustomLoader(inner) {
979
+ return {
980
+ name: "stape-custom-loader",
981
+ match(req) {
982
+ const real = unwrapStapeLoader(req);
983
+ return real !== void 0 && inner.some((d) => d.match(real, true));
984
+ },
985
+ isCollectionEndpoint(req) {
986
+ const real = unwrapStapeLoader(req);
987
+ return real !== void 0 && inner.some((d) => d.isCollectionEndpoint(real, true));
988
+ },
989
+ decode(req, newHitId = defaultHitId) {
990
+ const real = unwrapStapeLoader(req);
991
+ if (!real) return [];
992
+ return inner.filter((d) => d.match(real, true)).flatMap((d) => d.decode(real, newHitId, true)).map((hit) => ({ ...hit, transport: `${hit.transport} via ${STAPE_LOADER_TRANSPORT}` }));
993
+ }
994
+ };
995
+ }
996
+
887
997
  // packages/decoders/src/ga4.ts
888
998
  function parseUrl(url) {
889
999
  try {
@@ -976,6 +1086,11 @@ function eventParams(p) {
976
1086
  }
977
1087
  return out;
978
1088
  }
1089
+ function ga4HitIds(req) {
1090
+ const real = isGa4Collect(req) ? req : unwrapStapeLoader(req);
1091
+ if (!real || !isGa4Collect(real)) return [];
1092
+ return eventLines(real).map((p) => ({ cid: p.get("cid") || void 0, sid: p.get("sid") || void 0 }));
1093
+ }
979
1094
  var ga4 = {
980
1095
  name: "ga4",
981
1096
  match: isGa4Collect,
@@ -1384,17 +1499,6 @@ var googleAds = {
1384
1499
  }
1385
1500
  };
1386
1501
 
1387
- // packages/decoders/src/base64.ts
1388
- var ALPHABET2 = /^[A-Za-z0-9+/_-]+={0,2}$/;
1389
- function decodeBase64Text(value) {
1390
- const v = value.replace(/ /g, "+");
1391
- if (v.length < 4 || !ALPHABET2.test(v)) return void 0;
1392
- const bare = v.replace(/=+$/, "");
1393
- if (bare.length % 4 === 1) return void 0;
1394
- const text2 = Buffer.from(bare.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8");
1395
- return text2.includes("\uFFFD") ? void 0 : text2;
1396
- }
1397
-
1398
1502
  // packages/decoders/src/sgtm-data-client.ts
1399
1503
  function parseObject(text2) {
1400
1504
  if (!text2) return {};
@@ -1491,47 +1595,6 @@ var sgtmDataClient = {
1491
1595
  }
1492
1596
  };
1493
1597
 
1494
- // packages/decoders/src/stape-custom-loader.ts
1495
- var STAPE_LOADER_TRANSPORT = "stape-loader";
1496
- function unwrapStapeLoader(req) {
1497
- let url;
1498
- try {
1499
- url = new URL(req.url);
1500
- } catch {
1501
- return void 0;
1502
- }
1503
- if (!/^\/[^/]+$/.test(url.pathname)) return void 0;
1504
- const real = [];
1505
- for (const [, value] of url.searchParams) {
1506
- const decoded = decodeBase64Text(value);
1507
- if (decoded && /^\/[^/\s\\][\x21-\x7e]*$/.test(decoded)) real.push(decoded);
1508
- }
1509
- if (real.length !== 1) return void 0;
1510
- try {
1511
- return { ...req, url: new URL(real[0], url.origin).href };
1512
- } catch {
1513
- return void 0;
1514
- }
1515
- }
1516
- function createStapeCustomLoader(inner) {
1517
- return {
1518
- name: "stape-custom-loader",
1519
- match(req) {
1520
- const real = unwrapStapeLoader(req);
1521
- return real !== void 0 && inner.some((d) => d.match(real, true));
1522
- },
1523
- isCollectionEndpoint(req) {
1524
- const real = unwrapStapeLoader(req);
1525
- return real !== void 0 && inner.some((d) => d.isCollectionEndpoint(real, true));
1526
- },
1527
- decode(req, newHitId = defaultHitId) {
1528
- const real = unwrapStapeLoader(req);
1529
- if (!real) return [];
1530
- return inner.filter((d) => d.match(real, true)).flatMap((d) => d.decode(real, newHitId, true)).map((hit) => ({ ...hit, transport: `${hit.transport} via ${STAPE_LOADER_TRANSPORT}` }));
1531
- }
1532
- };
1533
- }
1534
-
1535
1598
  // packages/decoders/src/tracker-list.ts
1536
1599
  var trackerList = [
1537
1600
  {
@@ -1804,6 +1867,131 @@ function isSpecificServerHost(pattern) {
1804
1867
  return !owned.some((vendor) => sameOrBelow(domain, vendor) || wildcard && sameOrBelow(vendor, domain));
1805
1868
  }
1806
1869
 
1870
+ // packages/expect/src/push-shape.ts
1871
+ var PUSH_FRAME_KINDS = ["main", "embedded", "unknown"];
1872
+ var NO_EVENT = "(no event)";
1873
+ var NO_STEP = "(no step)";
1874
+ var EVENT_CHARS = /^[A-Za-z0-9_.:-]+$/;
1875
+ var MAX_DEPTH2 = 8;
1876
+ var MAX_PATHS = 200;
1877
+ var SHAPE_LIMITS = { paths: MAX_PATHS, depth: MAX_DEPTH2 };
1878
+ var NO_LIMITS = { paths: Infinity, depth: Infinity };
1879
+ var GTAG_COMMANDS = /* @__PURE__ */ new Set(["config", "consent", "event", "get", "js", "set"]);
1880
+ var GTAG_OTHER = "gtag (other)";
1881
+ var PUSH_KINDS = ["gtag", "object"];
1882
+ var PUSH_TYPES = ["string", "number", "boolean", "null", "object", "array"];
1883
+ var MAX_PUSH_PATH = 128;
1884
+ function pathProblem(path) {
1885
+ if (/\[\d+\]/.test(path)) return "has a numbered index, write [*] for any item, as the --json push shapes show it";
1886
+ if (path.length > MAX_PUSH_PATH) return `is at most ${MAX_PUSH_PATH} characters`;
1887
+ const plain = path.startsWith("**.") ? path.slice(3) : path;
1888
+ if (plain === "") return "must be a key path such as ecommerce.value";
1889
+ const reading = (s) => s.replace(/\[\*\]/g, "").replace(/\*/g, "x");
1890
+ const unsafe = guardFieldName(reading(plain)) !== reading(plain) || plain.split(".").some((s) => reading(s) === "" || guardFieldName(reading(s)) !== reading(s) || isValueSegment(reading(s)));
1891
+ return unsafe ? "must be a key path as the --json push shapes show it, and this one reads like a value" : void 0;
1892
+ }
1893
+ function isEventLabel(name) {
1894
+ return name !== OTHER_NAME && safeName(name) === name || name === NO_EVENT || /^(?:consent [a-z_]+|gtag (?:config|consent|event|get|js|set))$/.test(name);
1895
+ }
1896
+ function safeName(name) {
1897
+ return EVENT_CHARS.test(name) && !isValueSegment(name) && guardFieldName(name) === name ? name : OTHER_NAME;
1898
+ }
1899
+ function safeKey(key) {
1900
+ return guardFieldName(key) === key && !isValueSegment(key) ? key : OTHER_NAME;
1901
+ }
1902
+ function typeOf(value) {
1903
+ if (value === null || value === void 0) return "null";
1904
+ return Array.isArray(value) ? "array" : typeof value;
1905
+ }
1906
+ function walk(value, path, depth, out, limits) {
1907
+ const children = typeof value !== "object" || value === null ? [] : Array.isArray(value) ? value.map((v) => ["[*]", v]) : Object.entries(value);
1908
+ if (children.length === 0 || depth >= limits.depth) {
1909
+ if (path === "" || !out.has(path) && out.size >= limits.paths) return;
1910
+ (out.get(path) ?? out.set(path, /* @__PURE__ */ new Set()).get(path)).add(typeOf(value));
1911
+ return;
1912
+ }
1913
+ for (const [key, child] of children) {
1914
+ walk(child, key === "[*]" ? `${path}[*]` : path === "" ? safeKey(key) : `${path}.${safeKey(key)}`, depth + 1, out, limits);
1915
+ }
1916
+ }
1917
+ function startsWithString(args) {
1918
+ return typeof args[0] === "string";
1919
+ }
1920
+ function commandOf(e) {
1921
+ if (startsWithString(e.args)) return { list: e.args, fromObject: false };
1922
+ const list3 = argumentsListOf(e.args);
1923
+ return list3 !== void 0 && startsWithString(list3) ? { list: list3, fromObject: true } : void 0;
1924
+ }
1925
+ function isObjectConsent(command) {
1926
+ return command?.fromObject === true && consentCommandOf(command.list) !== void 0;
1927
+ }
1928
+ function commandLabel(command) {
1929
+ const [name, second] = command.list;
1930
+ if (command.fromObject && typeof second === "string") {
1931
+ if (isObjectConsent(command)) return `consent ${second}`;
1932
+ if (name === "event") return safeName(second);
1933
+ }
1934
+ return GTAG_COMMANDS.has(name) ? `gtag ${name}` : GTAG_OTHER;
1935
+ }
1936
+ function eventLabel(e, command) {
1937
+ if (e.isConsentCommand) return `consent ${String(e.args[1])}`;
1938
+ if (e.event !== null) return safeName(e.event);
1939
+ return command === void 0 ? NO_EVENT : commandLabel(command);
1940
+ }
1941
+ function labelKind(label) {
1942
+ return label.startsWith("consent ") ? "consent" : label.startsWith("gtag ") ? "gtag" : "event";
1943
+ }
1944
+ function frameKind(e) {
1945
+ return e.frame === void 0 ? "unknown" : e.frame.main ? "main" : "embedded";
1946
+ }
1947
+ function collectPaths(e, command, into, limits) {
1948
+ if (e.event?.startsWith("gtm.")) return;
1949
+ if (command?.fromObject && command.list[0] === "event" && typeof command.list[1] === "string" && command.list[1].startsWith("gtm.")) return;
1950
+ if (e.isConsentCommand || isObjectConsent(command)) {
1951
+ const signals = (command?.fromObject ? command.list : e.args)[2];
1952
+ if (typeof signals === "object" && signals !== null) for (const [name, value] of Object.entries(signals)) walk(value, safeKey(name), 0, into, limits);
1953
+ return;
1954
+ }
1955
+ if (command !== void 0) {
1956
+ for (const arg of command.list.slice(command.list[0] === "set" ? 1 : 2)) walk(arg, "", 0, into, limits);
1957
+ return;
1958
+ }
1959
+ for (const arg of e.args) walk(arg, "", 0, into, limits);
1960
+ }
1961
+ function pushShapeOf(e) {
1962
+ const command = commandOf(e);
1963
+ const paths = /* @__PURE__ */ new Map();
1964
+ collectPaths(e, command, paths, NO_LIMITS);
1965
+ return { event: eventLabel(e, command), kind: command === void 0 ? "object" : "gtag", frame: frameKind(e), paths };
1966
+ }
1967
+ function pushShapes(records) {
1968
+ const labels = new Map((records.steps ?? []).map((s) => [s.id, s.label]));
1969
+ const steps = /* @__PURE__ */ new Map();
1970
+ for (const e of records.dataLayerEvents) {
1971
+ const step = e.stepId === null ? NO_STEP : labels.get(e.stepId) ?? NO_STEP;
1972
+ const command = commandOf(e);
1973
+ const event = eventLabel(e, command);
1974
+ const kind = command === void 0 ? "object" : "gtag";
1975
+ const frame = frameKind(e);
1976
+ const groups = steps.get(step) ?? steps.set(step, /* @__PURE__ */ new Map()).get(step);
1977
+ const key = JSON.stringify([event, kind, frame]);
1978
+ const group = groups.get(key) ?? groups.set(key, { shape: { event, kind, frame, count: 0, paths: [], ids: [] }, types: /* @__PURE__ */ new Map() }).get(key);
1979
+ group.shape.count += 1;
1980
+ group.shape.ids.push(e.id);
1981
+ collectPaths(e, command, group.types, SHAPE_LIMITS);
1982
+ }
1983
+ return {
1984
+ pushes: records.dataLayerEvents.length,
1985
+ steps: [...steps].map(([step, groups]) => ({
1986
+ step,
1987
+ events: [...groups.values()].map(({ shape, types }) => ({
1988
+ ...shape,
1989
+ paths: [...types].map(([path, set]) => ({ path, types: [...set].sort() }))
1990
+ }))
1991
+ }))
1992
+ };
1993
+ }
1994
+
1807
1995
  // packages/expect/src/payment-providers.ts
1808
1996
  var PAYMENT_PROVIDERS = [
1809
1997
  {
@@ -1851,7 +2039,7 @@ function parseViewportText(text2) {
1851
2039
  return isViewportSide(viewport.width) && isViewportSide(viewport.height) ? viewport : void 0;
1852
2040
  }
1853
2041
  var VIEWPORT_HINT = `a size such as 390x844, with each side from ${VIEWPORT_MIN} to ${VIEWPORT_MAX}`;
1854
- var BUILTIN_NAMES = ["unknownDestination", "sandboxPageUrl", "possibleRealData", "deniedIdentifiers", "earlyIdentifiers", "consentModeSetup"];
2042
+ var BUILTIN_NAMES = ["unknownDestination", "sandboxPageUrl", "possibleRealData", "deniedIdentifiers", "earlyIdentifiers", "consentModeSetup", "earlyIdentityPush", "idHandover"];
1855
2043
  var SEVERITIES = ["fail", "warn"];
1856
2044
  var IDENTITY_FIELDS = ["firstName", "lastName", "email", "phone", "address1", "city", "zip", "country"];
1857
2045
  var ScenarioError = class extends Error {
@@ -1866,6 +2054,9 @@ var VENDOR_KEYS = /* @__PURE__ */ new Set(["vendor", "event", "page", "transport
1866
2054
  var GROUP_KEYS = ["consent", "ids", "params", "identity", "body"];
1867
2055
  var COOKIE_RULE_KEYS = ["cookie", "before", "in", "after", "from"];
1868
2056
  var TAG_RULE_KEYS = ["tag", "count", "after", "from"];
2057
+ var PUSH_RULE_KEYS = ["dataLayer", "count", "before", "in", "after", "from"];
2058
+ var PUSH_SELECTOR_KEYS = ["event", "has", "types", "kind", "frame"];
2059
+ var MAX_PUSH_PATHS = 50;
1869
2060
  var TAG_SELECTOR_KEYS = ["id", "name", "container", "event", "status", "side"];
1870
2061
  var MAX_TAG_TEXT = 200;
1871
2062
  var BODY_KEYS = ["has", "only", "ignore"];
@@ -2361,6 +2552,49 @@ function parseScenario(text2, extraVendorKeys = []) {
2361
2552
  if (tag.id === void 0 === (tag.name === void 0) && issues.length === before) fail(path, "needs exactly one of id or name");
2362
2553
  return issues.length === before ? tag : void 0;
2363
2554
  }
2555
+ function parsePushSelector(v, path) {
2556
+ if (!isMap(v)) {
2557
+ fail(path, "must be a mapping with event");
2558
+ return void 0;
2559
+ }
2560
+ const before = issues.length;
2561
+ let event;
2562
+ const selector = {};
2563
+ const paths = (key, list3) => {
2564
+ const problem = list3.map(pathProblem).find((x) => x !== void 0);
2565
+ if (problem !== void 0) fail([...path, key], problem);
2566
+ return problem === void 0;
2567
+ };
2568
+ for (const [key, raw2] of Object.entries(v)) {
2569
+ const p = [...path, key];
2570
+ if (!PUSH_SELECTOR_KEYS.includes(key)) fail(p, `unknown key, expected one of ${PUSH_SELECTOR_KEYS.join(", ")}`);
2571
+ else if (key === "event") {
2572
+ if (typeof raw2 === "string" && raw2 !== "" && raw2.length <= MAX_PUSH_PATH && isEventLabel(raw2)) event = raw2;
2573
+ else fail(p, "must be an event name as the --json push shapes show it, such as purchase. A name that reads (other) there cannot be matched");
2574
+ } else if (key === "has") {
2575
+ if (!Array.isArray(raw2) || raw2.length === 0 || raw2.length > MAX_PUSH_PATHS || !raw2.every((x) => typeof x === "string" && x !== "")) {
2576
+ fail(p, `must be a list of 1 to ${MAX_PUSH_PATHS} key paths such as ecommerce.transaction_id`);
2577
+ } else if (paths(key, raw2)) selector.has = raw2;
2578
+ } else if (key === "types") {
2579
+ const entries = isMap(raw2) ? Object.entries(raw2) : [];
2580
+ if (entries.length === 0 || entries.length > MAX_PUSH_PATHS) fail(p, `must be a mapping of 1 to ${MAX_PUSH_PATHS} key paths to a type, such as ecommerce.value: number`);
2581
+ else if (paths(key, entries.map(([k]) => k))) {
2582
+ const types = {};
2583
+ for (const [k, t] of entries) {
2584
+ if (typeof t === "string" && PUSH_TYPES.includes(t)) types[k] = t;
2585
+ else fail([...p, k], `must be one of ${PUSH_TYPES.join(", ")}`);
2586
+ }
2587
+ selector.types = types;
2588
+ }
2589
+ } else if (key === "kind") {
2590
+ if (typeof raw2 === "string" && PUSH_KINDS.includes(raw2)) selector.kind = raw2;
2591
+ else fail(p, `must be one of ${PUSH_KINDS.join(", ")}`);
2592
+ } else if (typeof raw2 === "string" && PUSH_FRAME_KINDS.includes(raw2)) selector.frame = raw2;
2593
+ else fail(p, `must be one of ${PUSH_FRAME_KINDS.join(", ")}`);
2594
+ }
2595
+ if (event === void 0 && issues.length === before) fail(path, "needs event");
2596
+ return issues.length === before && event !== void 0 ? { ...selector, event } : void 0;
2597
+ }
2364
2598
  function parseRule(kind, entry, path) {
2365
2599
  if (!isMap(entry)) {
2366
2600
  fail(path, "must be a mapping of filters and rule keys");
@@ -2425,6 +2659,9 @@ function parseScenario(text2, extraVendorKeys = []) {
2425
2659
  } else if (k === "tag") {
2426
2660
  const tag = parseTagSelector(v, p);
2427
2661
  if (tag) rule.tag = tag;
2662
+ } else if (k === "dataLayer") {
2663
+ const selector = parsePushSelector(v, p);
2664
+ if (selector) rule.dataLayer = selector;
2428
2665
  } else if (k === "vendor") {
2429
2666
  const l = list3(k, v, [...vendorKeys, ...trackerVendorKeys, ...extraVendorKeys]);
2430
2667
  if (l) filter.vendor = l;
@@ -2482,6 +2719,11 @@ function parseScenario(text2, extraVendorKeys = []) {
2482
2719
  const mixed = Object.keys(flat).filter((k) => !TAG_RULE_KEYS.includes(k) && k !== "before" && k !== "in");
2483
2720
  if (mixed.length) fail(path, `tag cannot be combined with ${mixed.join(", ")}; it only takes count, after and from`);
2484
2721
  }
2722
+ if (rule.dataLayer) {
2723
+ const mixed = Object.keys(flat).filter((k) => !PUSH_RULE_KEYS.includes(k));
2724
+ if (mixed.length) fail(path, `dataLayer cannot be combined with ${mixed.join(", ")}; it only takes count, before, in, after and from`);
2725
+ if (kind === "mustNot" && rule.dataLayer.types) fail([...path, "dataLayer", "types"], "is only valid under must");
2726
+ }
2485
2727
  if (rule.from && rule.after) fail(path, "use either from or after, not both");
2486
2728
  if (rule.before && rule.inEpoch) fail(path, "use either before or in, not both");
2487
2729
  if (rule.body?.has && rule.body.only) fail(path, "body.has and body.only cannot be in the same entry");
@@ -2613,16 +2855,245 @@ function consentModeSetup(hits, dataLayer) {
2613
2855
  message: `${evidence.length} Google hit${evidence.length === 1 ? "" : "s"} show a Consent Mode signal that was never set: ${shown2}${more}.${missingNote} See ${CONSENT_MODE_URL}`
2614
2856
  };
2615
2857
  }
2616
- const pushed = dataLayer.some((e) => e.isConsentCommand && e.args[0] === "consent" && e.args[1] === "default");
2858
+ const pushed = dataLayer.some((e) => consentCommandOf(e.args)?.command === "default");
2617
2859
  if (showsDefault && !pushed) {
2618
2860
  return { pass: true, evidence: [], message: `Consent Mode signals are set on every Google hit${noGcd > 0 ? " that carried gcd" : ""}; default set outside the dataLayer (template API, TCF or other) (gcd letters: ${lettersNote(letterSets)}).${missingNote}` };
2619
2861
  }
2620
2862
  return { pass: true, evidence: [], message: `Expected Consent Mode signals to be set on Google hits, found every signal set (gcd letters: ${lettersNote(letterSets)}).${missingNote}` };
2621
2863
  }
2622
2864
 
2865
+ // packages/expect/src/early-identity-push.ts
2866
+ var MAX_DEPTH3 = 8;
2867
+ var MAX_LISTED2 = 5;
2868
+ var MIN_BARE_LOCAL = 6;
2869
+ var AT_MARKERS = ["@", "_at_", "%40", "(at)"];
2870
+ var holdsLocalPart = (key, identity) => {
2871
+ const [local = "", domain = ""] = identity.email.toLowerCase().split("@");
2872
+ if (local === "") return false;
2873
+ const k = key.toLowerCase();
2874
+ if (local.length >= MIN_BARE_LOCAL && k.includes(local)) return true;
2875
+ const label = domain.split(".")[0] ?? "";
2876
+ const next = [...AT_MARKERS, ...label === "" ? [] : [`_${label}`, `-${label}`, `.${label}`, label]];
2877
+ for (let at = k.indexOf(local); at !== -1; at = k.indexOf(local, at + 1)) {
2878
+ const rest = k.slice(at + local.length);
2879
+ if (next.some((m) => rest.startsWith(m))) return true;
2880
+ }
2881
+ return false;
2882
+ };
2883
+ var safeKey2 = (key, identity) => {
2884
+ if (guardFieldName(key) !== key || isValueSegment(key)) return OTHER_NAME;
2885
+ return holdsLocalPart(key, identity) || ownValueKinds(key, identity).size > 0 ? OTHER_NAME : key;
2886
+ };
2887
+ function ownLeaves(value, path, key, identity, depth, out) {
2888
+ if (depth > MAX_DEPTH3) return;
2889
+ if (typeof value === "string" || typeof value === "number") {
2890
+ const kinds = ownValueKinds(`${key}=${value}`, identity);
2891
+ for (const k of ownValueKinds(String(value), identity)) kinds.add(k);
2892
+ if (kinds.size === 0) return;
2893
+ const name = path || "(value)";
2894
+ const found = out.get(name) ?? /* @__PURE__ */ new Set();
2895
+ for (const k of kinds) found.add(k);
2896
+ out.set(name, found);
2897
+ return;
2898
+ }
2899
+ if (typeof value !== "object" || value === null) return;
2900
+ if (Array.isArray(value)) {
2901
+ for (const item of value) ownLeaves(item, `${path}[]`, key, identity, depth + 1, out);
2902
+ return;
2903
+ }
2904
+ for (const [k, child] of Object.entries(value)) ownLeaves(child, path === "" ? safeKey2(k, identity) : `${path}.${safeKey2(k, identity)}`, k, identity, depth + 1, out);
2905
+ }
2906
+ var withoutConsent = (epoch) => epoch.label === "mixed" ? epoch.state.adUserData === "denied" || epoch.state.analytics === "denied" : ["undecided", "denied", "withdrawn"].includes(epoch.label);
2907
+ function earlyIdentityPush(pushes, place, identity) {
2908
+ if (!identity) {
2909
+ return { pass: true, evidence: [], message: "Could not check for the run identity in pushes before consent: no identity was given and the run record holds none." };
2910
+ }
2911
+ const found = [];
2912
+ for (const push of pushes) {
2913
+ const epoch = place(push.t);
2914
+ if (!epoch || !withoutConsent(epoch)) continue;
2915
+ const leaves = /* @__PURE__ */ new Map();
2916
+ for (const arg of push.args) ownLeaves(arg, "", "", identity, 0, leaves);
2917
+ if (leaves.size > 0) found.push({ id: push.id, leaves });
2918
+ }
2919
+ if (found.length === 0) return { pass: true, evidence: [], message: "Expected no test identity in dataLayer pushes before consent, found none." };
2920
+ const describe = (f) => `${f.id} (${[...f.leaves].map(([path, kinds]) => `${path}: ${[...kinds].join(", ")}`).join("; ")})`;
2921
+ const more = found.length > MAX_LISTED2 ? `; and ${found.length - MAX_LISTED2} more` : "";
2922
+ return {
2923
+ pass: false,
2924
+ evidence: found.map((f) => f.id),
2925
+ message: `Expected no test identity in dataLayer pushes before consent, found ${found.length}: ${found.slice(0, MAX_LISTED2).map(describe).join("; ")}${more}.`
2926
+ };
2927
+ }
2928
+
2929
+ // packages/expect/src/id-handover.ts
2930
+ var MAX_LISTED3 = 3;
2931
+ var hostOf = (url) => {
2932
+ if (!url) return void 0;
2933
+ try {
2934
+ return new URL(url).hostname || void 0;
2935
+ } catch {
2936
+ return void 0;
2937
+ }
2938
+ };
2939
+ var contextLabel = (req, hit) => `${req.frame.main ? "main frame" : "sub frame"} on ${hostOf(hit.page) ?? hostOf(req.frameUrl) ?? "an unknown host"}`;
2940
+ function idHandover(hits, requests) {
2941
+ const byRequest = /* @__PURE__ */ new Map();
2942
+ for (const hit of hits) {
2943
+ if (hit.vendor !== "ga4") continue;
2944
+ byRequest.set(hit.requestId, [...byRequest.get(hit.requestId) ?? [], hit]);
2945
+ }
2946
+ const byTid = /* @__PURE__ */ new Map();
2947
+ for (const [requestId, group] of byRequest) {
2948
+ const req = requests.get(requestId);
2949
+ if (!req?.frame) continue;
2950
+ const ids = ga4HitIds(req);
2951
+ group.forEach((hit, i) => {
2952
+ const cid = ids[i]?.cid;
2953
+ if (!cid || !hit.params.tid || hit.consent.analytics === "denied") return;
2954
+ const label = contextLabel(req, hit);
2955
+ const contexts = byTid.get(hit.params.tid) ?? /* @__PURE__ */ new Map();
2956
+ const context = contexts.get(label) ?? { label, seen: [] };
2957
+ context.seen.push({ hitId: hit.id, cid, sid: ids[i]?.sid });
2958
+ contexts.set(label, context);
2959
+ byTid.set(hit.params.tid, contexts);
2960
+ });
2961
+ }
2962
+ const problems = [];
2963
+ const evidence = /* @__PURE__ */ new Set();
2964
+ const flag2 = (text2, a, b) => {
2965
+ problems.push(text2);
2966
+ for (const s of [...a.seen, ...b.seen]) evidence.add(s.hitId);
2967
+ };
2968
+ for (const [tid, contexts] of byTid) {
2969
+ const list3 = [...contexts.values()];
2970
+ for (let i = 0; i < list3.length; i++) {
2971
+ for (let j = i + 1; j < list3.length; j++) {
2972
+ const a = list3[i];
2973
+ const b = list3[j];
2974
+ const cidsB = new Set(b.seen.map((s) => s.cid));
2975
+ const shared = new Set(a.seen.map((s) => s.cid).filter((c) => cidsB.has(c)));
2976
+ if (shared.size === 0) {
2977
+ flag2(`${tid}: client ID differs between ${a.label} and ${b.label}`, a, b);
2978
+ continue;
2979
+ }
2980
+ const sidsOf = (c) => new Set(c.seen.filter((s) => shared.has(s.cid) && s.sid).map((s) => s.sid));
2981
+ const sidsA = sidsOf(a);
2982
+ const sidsB = sidsOf(b);
2983
+ if (sidsA.size > 0 && sidsB.size > 0 && ![...sidsA].some((v) => sidsB.has(v))) flag2(`${tid}: session ID differs between ${a.label} and ${b.label}`, a, b);
2984
+ }
2985
+ }
2986
+ }
2987
+ if (problems.length === 0) return { pass: true, evidence: [], message: "Expected the GA4 client and session ID to carry over between contexts, found no difference." };
2988
+ const more = problems.length > MAX_LISTED3 ? `; and ${problems.length - MAX_LISTED3} more` : "";
2989
+ return {
2990
+ pass: false,
2991
+ evidence: [...evidence],
2992
+ message: `Expected the GA4 client and session ID to carry over between contexts, found ${problems.length} difference${problems.length === 1 ? "" : "s"}: ${problems.slice(0, MAX_LISTED3).join("; ")}${more}.`
2993
+ };
2994
+ }
2995
+
2996
+ // packages/expect/src/push-rules.ts
2997
+ function fieldGlob(pattern) {
2998
+ if (!pattern.startsWith("**.")) return globToRegExp(pattern);
2999
+ return new RegExp(`^(?:.*\\.)?${globToRegExp(pattern.slice(3)).source.slice(1, -1)}$`);
3000
+ }
3001
+ function withContainers(leaves) {
3002
+ const all = /* @__PURE__ */ new Map();
3003
+ const add2 = (path, types) => {
3004
+ const set = all.get(path) ?? all.set(path, /* @__PURE__ */ new Set()).get(path);
3005
+ for (const t of types) set.add(t);
3006
+ };
3007
+ for (const [path, types] of leaves) {
3008
+ add2(path, types);
3009
+ for (let i = 1; i < path.length; i++) {
3010
+ if (path[i] === ".") add2(path.slice(0, i), ["object"]);
3011
+ else if (path.startsWith("[*]", i)) add2(path.slice(0, i), ["array"]);
3012
+ }
3013
+ }
3014
+ return all;
3015
+ }
3016
+ var plural = (n, word) => `${n} ${word}${n === 1 ? "" : /(s|x|ch|sh)$/.test(word) ? "es" : "s"}`;
3017
+ function holdsPath(push, matcher) {
3018
+ for (const path of push.paths.keys()) if (matcher.test(path)) return true;
3019
+ return false;
3020
+ }
3021
+ function typesAt(push, matcher) {
3022
+ const found = /* @__PURE__ */ new Set();
3023
+ for (const [path, types] of push.paths) if (matcher.test(path)) for (const t of types) found.add(t);
3024
+ return found.size === 0 ? ["absent"] : [...found].sort();
3025
+ }
3026
+ function evaluatePushRule(rule, input) {
3027
+ const sel = rule.dataLayer;
3028
+ const matching = input.pushes.map((e) => {
3029
+ const shape = pushShapeOf(e);
3030
+ return { id: e.id, t: e.t, shape, paths: withContainers(shape.paths) };
3031
+ }).filter((p) => p.shape.event === sel.event && (sel.kind === void 0 || p.shape.kind === sel.kind) && (sel.frame === void 0 || p.shape.frame === sel.frame));
3032
+ const selected = matching.filter((p) => input.inScope(p.t));
3033
+ const { where: where2 } = input;
3034
+ const qualifiers = [sel.kind, sel.frame && `${sel.frame} frame`].filter(Boolean);
3035
+ const subject = `"${sel.event}" push${qualifiers.length ? ` (${qualifiers.join(", ")})` : ""}`;
3036
+ const before = `${matching.length} before narrowing`;
3037
+ const matchers2 = (sel.has ?? []).map(fieldGlob);
3038
+ if (rule.kind === "mustNot") {
3039
+ const offenders = matchers2.length ? selected.filter((p) => matchers2.some((m) => holdsPath(p, m))) : selected;
3040
+ const holding2 = sel.has ? ` holding any of ${sel.has.join(", ")}` : "";
3041
+ const found = offenders.length === 0 ? "found none" : `found ${plural(offenders.length, "push")}`;
3042
+ const pass2 = offenders.length === 0;
3043
+ const warn = pass2 && input.hookIncomplete;
3044
+ if (warn) {
3045
+ return {
3046
+ pass: false,
3047
+ evidence: [],
3048
+ message: `Expected no ${subject}${holding2}${where2}, found none (${before}), but the pushes could not all be read: the dataLayer hook is incomplete here, so a push may have been missed.`,
3049
+ severity: "warn"
3050
+ };
3051
+ }
3052
+ return { pass: pass2, evidence: offenders.map((p) => p.id), message: `Expected no ${subject}${holding2}${where2}, ${found} (${before}).` };
3053
+ }
3054
+ if (sel.types) {
3055
+ const problems = [];
3056
+ const evidence = /* @__PURE__ */ new Set();
3057
+ for (const [path, type] of Object.entries(sel.types)) {
3058
+ const matcher = fieldGlob(path);
3059
+ const found = /* @__PURE__ */ new Map();
3060
+ for (const p of selected) {
3061
+ const types = typesAt(p, matcher);
3062
+ if (types.length === 1 && types[0] === type) continue;
3063
+ evidence.add(p.id);
3064
+ const label = types.join(" or ");
3065
+ found.set(label, (found.get(label) ?? 0) + 1);
3066
+ }
3067
+ if (found.size) problems.push(`${path} should be ${type}, found ${[...found].map(([label, n]) => `${label} in ${plural(n, "push")}`).join(", ")}`);
3068
+ }
3069
+ if (problems.length) {
3070
+ return { pass: false, evidence: [...evidence], message: `Expected every ${subject}${where2} to have the types in dataLayer.types: ${problems.join("; ")} (${before}).` };
3071
+ }
3072
+ }
3073
+ const holders = matchers2.length ? selected.filter((p) => matchers2.every((m) => holdsPath(p, m))) : selected;
3074
+ const count = rule.count ?? { op: ">=", n: 1 };
3075
+ const pass = countHolds(count, holders.length);
3076
+ const typed = sel.types ? ` with types ${Object.entries(sel.types).map(([path, type]) => `${path}: ${type}`).join(", ")}` : "";
3077
+ const holding = `${sel.has ? ` holding ${sel.has.join(", ")}` : ""}${typed}`;
3078
+ const unseenPushCouldBreak = sel.types !== void 0 || count.op === "<=" || count.op === "<" || count.op === "=";
3079
+ if (pass && input.hookIncomplete && unseenPushCouldBreak) {
3080
+ return {
3081
+ pass: false,
3082
+ evidence: holders.map((p) => p.id),
3083
+ message: `Expected ${describeCount(count)} ${subject}${holding}${where2}, found ${holders.length} of ${selected.length} (${before}), but the pushes could not all be read: the dataLayer hook is incomplete here, so a push may have been missed.`,
3084
+ severity: "warn"
3085
+ };
3086
+ }
3087
+ return {
3088
+ pass,
3089
+ evidence: (pass ? holders : selected).map((p) => p.id),
3090
+ message: `Expected ${describeCount(count)} ${subject}${holding}${where2}, found ${holders.length} of ${selected.length} (${before}).`
3091
+ };
3092
+ }
3093
+
2623
3094
  // packages/expect/src/tags.ts
2624
3095
  var TAG_REPORTER_HINT = "tagreeve template web --json";
2625
- var MAX_LISTED2 = 5;
3096
+ var MAX_LISTED4 = 5;
2626
3097
  var STATUS_WORD = /^[a-z_]{1,20}$/;
2627
3098
  var ID_WORD = /^[\w.-]{1,40}$/;
2628
3099
  var COARSE_SEPARATORS = /[\s/=:?&#|,;]+/;
@@ -2653,7 +3124,7 @@ function listWithMore(items, max) {
2653
3124
  return items.length > max ? `${items.slice(0, max).join(", ")} and ${items.length - max} more` : items.join(", ");
2654
3125
  }
2655
3126
  function listLabels(labels) {
2656
- return listWithMore(labels, MAX_LISTED2);
3127
+ return listWithMore(labels, MAX_LISTED4);
2657
3128
  }
2658
3129
  function evaluateTagRule(rule, input) {
2659
3130
  const selector = rule.tag;
@@ -2740,7 +3211,7 @@ function summarizeTags(reports, expected) {
2740
3211
 
2741
3212
  // packages/expect/src/evaluate.ts
2742
3213
  var DEFAULT_GRACE_MS = 50;
2743
- var MAX_LISTED3 = 5;
3214
+ var MAX_LISTED5 = 5;
2744
3215
  var MAX_NAMES = 12;
2745
3216
  function evaluate(records, scenario, options = {}) {
2746
3217
  const runRecord = records.find((r) => r.type === "run");
@@ -2758,6 +3229,9 @@ function evaluate(records, scenario, options = {}) {
2758
3229
  responses: records.filter((r) => r.type === "response"),
2759
3230
  checkpoints: records.filter((r) => r.type === "checkpoint"),
2760
3231
  tagReports: records.filter((r) => r.type === "tagReport"),
3232
+ dataLayerEvents: records.filter((r) => r.type === "dataLayerEvent"),
3233
+ flags: records.filter((r) => r.type === "flag"),
3234
+ visitTimes: records.filter((r) => r.type === "step").filter((st) => scenario.steps.some((s) => s.kind === "visit" && s.label === st.label)).map((st) => st.startedAt),
2761
3235
  expectedTags: expectedTagsOf(runRecord),
2762
3236
  networkMode: runRecord?.networkMode,
2763
3237
  grace: options.graceWindowMs ?? scenario.options.graceWindow ?? DEFAULT_GRACE_MS,
@@ -2783,12 +3257,12 @@ function evaluate(records, scenario, options = {}) {
2783
3257
  const outcome = evaluateRule(rule, ctx);
2784
3258
  const { pass, evidence, message } = outcome;
2785
3259
  const passes = (c) => evaluateRuleHits(rule, c).pass;
2786
- const scoped = !rule.tag && isScoped(rule);
3260
+ const scoped = !rule.tag && !rule.dataLayer && isScoped(rule);
2787
3261
  const failureRests = scoped && !pass && failureRestsOnProbableLink(ctx, passes, rule);
2788
3262
  const ownNote = outcome.note === "nestedNameOnly" ? void 0 : outcome.note;
2789
3263
  const note = ownNote ?? (pass && scoped && passRestsOnProbableLink(ctx, passes, rule) ? "serverSendProbableLink" : outcome.note);
2790
3264
  const countRests = kind === "must" && failureRests && !ownNote;
2791
- add2(`${kind}: ${rule.description}`, pass, evidence, message, countRests ? "warn" : void 0, countRests ? "serverSendProbableLink" : note, scoped && (pass || failureRests));
3265
+ add2(`${kind}: ${rule.description}`, pass, evidence, message, countRests ? "warn" : outcome.severity, countRests ? "serverSendProbableLink" : note, scoped && (pass || failureRests));
2792
3266
  }
2793
3267
  builtInChecks(records, scenario, ctx, add2);
2794
3268
  return results;
@@ -2837,7 +3311,7 @@ function placementsChange(ctx, rule, unlinked, probable, base2) {
2837
3311
  }
2838
3312
  function evaluateRule(rule, ctx) {
2839
3313
  const outcome = evaluateRuleHits(rule, ctx);
2840
- if (rule.cookie || rule.tag || !isScoped(rule)) return outcome;
3314
+ if (rule.cookie || rule.tag || rule.dataLayer || !isScoped(rule)) return outcome;
2841
3315
  const unjudged = ctx.hits.filter((h) => isUnlinkedServerHit(h, ctx.index) && matchesFilter(h, { ...rule.filter, consent: {} }, ctx));
2842
3316
  if (unjudged.length === 0) return outcome;
2843
3317
  if (rule.kind === "mustNot") {
@@ -2924,6 +3398,7 @@ function evaluateRuleHits(rule, ctx) {
2924
3398
  return evaluateTagRule(rule, { reports: ctx.tagReports, expected: ctx.expectedTags, window: window2 });
2925
3399
  }
2926
3400
  if (rule.cookie) return evaluateCookieRule(rule, rule.cookie, ctx);
3401
+ if (rule.dataLayer) return evaluatePushRuleIn(rule, ctx);
2927
3402
  const scope = scopedHits(rule, ctx);
2928
3403
  if ("message" in scope) return scope;
2929
3404
  const { hits, total: total2, narrowed } = scope;
@@ -2952,20 +3427,20 @@ function evaluateRuleHits(rule, ctx) {
2952
3427
  return { pass, evidence: ids, message };
2953
3428
  }
2954
3429
  var STUB_NO_COOKIES = "stub mode: stubbed endpoints set no cookies";
2955
- function cookieSightings(matchers, ctx) {
3430
+ function cookieSightings(matchers2, ctx) {
2956
3431
  const out = [];
2957
- const wanted = (name) => matchers.some((m) => m.test(name));
3432
+ const wanted = (name) => matchers2.some((m) => m.test(name));
2958
3433
  for (const response of ctx.responses) {
2959
3434
  const request = ctx.requests.get(response.requestId);
2960
3435
  const t = request?.t;
2961
- const host = request && hostOf(request.url);
3436
+ const host = request && hostOf2(request.url);
2962
3437
  for (const name of response.setCookieNames) if (wanted(name)) out.push({ name, evidence: response.requestId, t, source: "Set-Cookie", ...host && { host } });
2963
3438
  }
2964
3439
  for (const checkpoint of ctx.checkpoints)
2965
3440
  for (const cookie of checkpoint.cookies) if (wanted(cookie.name)) out.push({ name: cookie.name, evidence: checkpoint.id, t: checkpoint.t, source: `checkpoint "${checkpoint.label}"` });
2966
3441
  return out;
2967
3442
  }
2968
- function hostOf(url) {
3443
+ function hostOf2(url) {
2969
3444
  try {
2970
3445
  return new URL(url).hostname.toLowerCase();
2971
3446
  } catch {
@@ -3078,6 +3553,32 @@ function evaluateCookieRule(rule, patterns, ctx) {
3078
3553
  ...storage?.notStored && { note: "cookieNotStored" }
3079
3554
  };
3080
3555
  }
3556
+ function evaluatePushRuleIn(rule, ctx) {
3557
+ const windowStart = ruleWindowStart(rule, ctx);
3558
+ if (windowStart && "message" in windowStart) return windowStart;
3559
+ const narrowed = [];
3560
+ if (rule.before) narrowed.push("before consent");
3561
+ if (rule.inEpoch) narrowed.push(`in epoch(${rule.inEpoch})`);
3562
+ if (windowStart) narrowed.push(windowStart.text);
3563
+ const inScope = (t) => (!rule.before || beforeConsentAt(t, ctx)) && (!rule.inEpoch || inEpochAt(t, rule.inEpoch, ctx)) && (!windowStart || t >= windowStart.at);
3564
+ const hookIncomplete = ctx.flags.some(
3565
+ (f) => (f.kind === "dataLayerIncomplete" || f.kind === "dataLayerNotHooked") && (f.recordIds.length === 0 || f.recordIds.some((id) => loaderReachesScope(ctx.requests.get(id), ctx, inScope, windowStart?.at)))
3566
+ );
3567
+ return evaluatePushRule(rule, { pushes: ctx.dataLayerEvents, inScope, where: narrowed.length ? ` ${narrowed.join(", ")}` : "", hookIncomplete });
3568
+ }
3569
+ function loaderReachesScope(loader, ctx, inScope, windowStartAt) {
3570
+ if (!loader) return true;
3571
+ const navigations = [
3572
+ ...ctx.visitTimes,
3573
+ ...[...ctx.requests.values()].filter((r) => r.resourceType === "document" && r.frame?.main !== false).map((r) => r.t)
3574
+ ];
3575
+ const start = Math.max(-Infinity, ...navigations.filter((t) => t <= loader.t));
3576
+ const end = Math.min(Infinity, ...navigations.filter((t) => t > loader.t));
3577
+ const candidates2 = [start, loader.t, windowStartAt, ...ctx.epochs.flatMap((e) => [e.startT, e.startT - ctx.grace])].filter(
3578
+ (t) => t !== void 0 && t >= start && t < end
3579
+ );
3580
+ return candidates2.some(inScope);
3581
+ }
3081
3582
  var NOT_RECORDED = "cannot evaluate: field names not recorded";
3082
3583
  var BODY_CUT = "cannot evaluate: body not fully recorded";
3083
3584
  var VENDOR_IGNORE = { ga4: GA4_BODY_ONLY_IGNORE, meta: META_BODY_ONLY_IGNORE, "meta-capi": META_CAPI_BODY_ONLY_IGNORE, sgtm: SGTM_BODY_ONLY_IGNORE };
@@ -3093,10 +3594,6 @@ function cannotEvaluate(unreadable2, where2) {
3093
3594
  note: notRecorded ? "fieldsNotRecorded" : "cannotEvaluateBody"
3094
3595
  };
3095
3596
  }
3096
- function fieldGlob(pattern) {
3097
- if (!pattern.startsWith("**.")) return globToRegExp(pattern);
3098
- return new RegExp(`^(?:.*\\.)?${globToRegExp(pattern.slice(3)).source.slice(1, -1)}$`);
3099
- }
3100
3597
  function nestedNames(plain, hits) {
3101
3598
  const wanted = new Set(plain);
3102
3599
  const found = /* @__PURE__ */ new Set();
@@ -3108,7 +3605,7 @@ function evaluateBodyRule(rule, body, selected, where2, total2, vacuous) {
3108
3605
  const tail = vacuous ? ` ${vacuous}` : "";
3109
3606
  const narrowed = `${selected.length} selected hit${selected.length === 1 ? "" : "s"}${where2}`;
3110
3607
  if (body.has) {
3111
- const matchers = body.has.map(fieldGlob);
3608
+ const matchers2 = body.has.map(fieldGlob);
3112
3609
  const unreadable3 = [];
3113
3610
  const matching = [];
3114
3611
  for (const hit of selected) {
@@ -3116,7 +3613,7 @@ function evaluateBodyRule(rule, body, selected, where2, total2, vacuous) {
3116
3613
  unreadable3.push(hit);
3117
3614
  continue;
3118
3615
  }
3119
- const names2 = hit.fields.filter((f) => matchers.some((m) => m.test(f)));
3616
+ const names2 = hit.fields.filter((f) => matchers2.some((m) => m.test(f)));
3120
3617
  if (names2.length) matching.push({ hit, names: names2 });
3121
3618
  else if (hit.fieldsComplete === false) unreadable3.push(hit);
3122
3619
  }
@@ -3152,8 +3649,8 @@ function evaluateBodyRule(rule, body, selected, where2, total2, vacuous) {
3152
3649
  else if (hit.fieldsComplete === false) unreadable2.push(hit);
3153
3650
  }
3154
3651
  if (offenders.length) {
3155
- const lines = offenders.slice(0, MAX_LISTED3).map((o) => `${o.hit.id} has fields outside body.only: ${listNames(o.outside)} (${o.outside.length} of ${o.hit.fields.length})`);
3156
- const more = offenders.length > MAX_LISTED3 ? ` and ${offenders.length - MAX_LISTED3} more hits` : "";
3652
+ const lines = offenders.slice(0, MAX_LISTED5).map((o) => `${o.hit.id} has fields outside body.only: ${listNames(o.outside)} (${o.outside.length} of ${o.hit.fields.length})`);
3653
+ const more = offenders.length > MAX_LISTED5 ? ` and ${offenders.length - MAX_LISTED5} more hits` : "";
3157
3654
  return { pass: false, evidence: offenders.map((o) => o.hit.id), message: `${lines.join("; ")}${more}.${tail}` };
3158
3655
  }
3159
3656
  if (unreadable2.length) return cannotEvaluate(unreadable2, where2);
@@ -3548,7 +4045,7 @@ function countByHost(flags2, ctx) {
3548
4045
  }
3549
4046
  return [...counts].map(([host, n]) => `${host} x${n}`).join(", ");
3550
4047
  }
3551
- var DEFAULT_SEVERITY = { earlyIdentifiers: "warn", consentModeSetup: "warn" };
4048
+ var DEFAULT_SEVERITY = { earlyIdentifiers: "warn", consentModeSetup: "warn", earlyIdentityPush: "warn", idHandover: "warn" };
3552
4049
  function builtInChecks(records, scenario, ctx, addResult) {
3553
4050
  const add2 = (name, pass, evidence2, message, note, timeJudged = false) => addResult(
3554
4051
  `builtin: ${name}`,
@@ -3596,13 +4093,21 @@ function builtInChecks(records, scenario, ctx, addResult) {
3596
4093
  records.filter((r) => r.type === "dataLayerEvent")
3597
4094
  );
3598
4095
  add2("consentModeSetup", consentMode.pass, consentMode.evidence, consentMode.message);
4096
+ const early = earlyIdentityPush(
4097
+ records.filter((r) => r.type === "dataLayerEvent"),
4098
+ (t) => epochForHit(ctx.epochs, t, ctx.grace),
4099
+ ctx.identity
4100
+ );
4101
+ add2("earlyIdentityPush", early.pass, early.evidence, early.message);
4102
+ const handover = idHandover(ctx.hits.filter((h) => !ctx.serverHitIds.has(h.id)), ctx.requests);
4103
+ add2("idHandover", handover.pass, handover.evidence, handover.message);
3599
4104
  const real = flags2.filter((f) => f.kind === "possibleRealData");
3600
4105
  const flagged = new Set(real.flatMap((f) => f.recordIds));
3601
4106
  const leaks = ctx.identity ? findForeignData(ctx.requests.values(), ctx.hits, ctx.identity).filter((l) => !flagged.has(l.requestId)) : [];
3602
4107
  const evidence = [...real.flatMap((f) => [f.id, ...f.recordIds]), ...leaks.flatMap((l) => l.evidence)];
3603
4108
  const problems = [...real.map((f) => f.detail), ...leaks.map((l) => l.detail)];
3604
- const shown2 = problems.slice(0, MAX_LISTED3).join("; ");
3605
- const more = problems.length > MAX_LISTED3 ? `; and ${problems.length - MAX_LISTED3} more` : "";
4109
+ const shown2 = problems.slice(0, MAX_LISTED5).join("; ");
4110
+ const more = problems.length > MAX_LISTED5 ? `; and ${problems.length - MAX_LISTED5} more` : "";
3606
4111
  if (!ctx.identity && real.length === 0) {
3607
4112
  add2(
3608
4113
  "possibleRealData",
@@ -3664,8 +4169,8 @@ function deniedIdentifiersCheck(scenario, ctx, add2) {
3664
4169
  const [vendor, signal] = key.split("\0");
3665
4170
  return `${vendor} ${listNames([...names].sort())} (${signal} denied)`;
3666
4171
  });
3667
- const shown2 = groups.slice(0, MAX_LISTED3).join(", ");
3668
- const more = groups.length > MAX_LISTED3 ? `, and ${groups.length - MAX_LISTED3} more` : "";
4172
+ const shown2 = groups.slice(0, MAX_LISTED5).join(", ");
4173
+ const more = groups.length > MAX_LISTED5 ? `, and ${groups.length - MAX_LISTED5} more` : "";
3669
4174
  const cut = unreadable2.length > 0 ? ` ${unreadable2.length} more hit${unreadable2.length === 1 ? "" : "s"} could not be read.` : "";
3670
4175
  const unjudged = unjudgedIdentifiers(ctx);
3671
4176
  add2(
@@ -3721,8 +4226,8 @@ function earlyIdentifiersCheck(scenario, ctx, add2) {
3721
4226
  const [vendor, signal] = key.split("\0");
3722
4227
  return `${vendor} ${listNames([...names].sort())} (${signal} unknown)`;
3723
4228
  });
3724
- const shown2 = groups.slice(0, MAX_LISTED3).join(", ");
3725
- const more = groups.length > MAX_LISTED3 ? `, and ${groups.length - MAX_LISTED3} more` : "";
4229
+ const shown2 = groups.slice(0, MAX_LISTED5).join(", ");
4230
+ const more = groups.length > MAX_LISTED5 ? `, and ${groups.length - MAX_LISTED5} more` : "";
3726
4231
  const cut = unreadable2.length > 0 ? ` ${unreadable2.length} more ${hitsWord(unreadable2.length)} could not be read.` : "";
3727
4232
  const unjudged = unjudgedIdentifiers(ctx);
3728
4233
  add2(
@@ -4044,118 +4549,6 @@ function findForeignData(requests, hits, identity, dataLayerEvents = []) {
4044
4549
  return out;
4045
4550
  }
4046
4551
 
4047
- // packages/expect/src/push-shape.ts
4048
- var PUSH_FRAME_KINDS = ["main", "embedded", "unknown"];
4049
- var NO_EVENT = "(no event)";
4050
- var NO_STEP = "(no step)";
4051
- var EVENT_CHARS = /^[A-Za-z0-9_.:-]+$/;
4052
- var MAX_DEPTH2 = 8;
4053
- var MAX_PATHS = 200;
4054
- var GTAG_COMMANDS = /* @__PURE__ */ new Set(["config", "consent", "event", "get", "js", "set"]);
4055
- var GTAG_OTHER = "gtag (other)";
4056
- var MAX_ARGUMENTS = 16;
4057
- function safeName(name) {
4058
- return EVENT_CHARS.test(name) && !isValueSegment(name) && guardFieldName(name) === name ? name : OTHER_NAME;
4059
- }
4060
- function safeKey(key) {
4061
- return guardFieldName(key) === key && !isValueSegment(key) ? key : OTHER_NAME;
4062
- }
4063
- function typeOf(value) {
4064
- if (value === null || value === void 0) return "null";
4065
- return Array.isArray(value) ? "array" : typeof value;
4066
- }
4067
- function walk(value, path, depth, out) {
4068
- const children = typeof value !== "object" || value === null ? [] : Array.isArray(value) ? value.map((v) => ["[*]", v]) : Object.entries(value);
4069
- if (children.length === 0 || depth >= MAX_DEPTH2) {
4070
- if (path === "" || !out.has(path) && out.size >= MAX_PATHS) return;
4071
- (out.get(path) ?? out.set(path, /* @__PURE__ */ new Set()).get(path)).add(typeOf(value));
4072
- return;
4073
- }
4074
- for (const [key, child] of children) {
4075
- walk(child, key === "[*]" ? `${path}[*]` : path === "" ? safeKey(key) : `${path}.${safeKey(key)}`, depth + 1, out);
4076
- }
4077
- }
4078
- function startsWithString(args) {
4079
- return typeof args[0] === "string";
4080
- }
4081
- function argumentsLike(args) {
4082
- const [item] = args;
4083
- if (args.length !== 1 || typeof item !== "object" || item === null || Array.isArray(item)) return void 0;
4084
- const keys = Object.keys(item);
4085
- if (keys.length < 1 || keys.length > MAX_ARGUMENTS || !keys.every((k, i) => Object.hasOwn(item, String(i)) && k === String(i))) return void 0;
4086
- const list3 = keys.map((_, i) => item[String(i)]);
4087
- return typeof list3[0] === "string" ? list3 : void 0;
4088
- }
4089
- function commandOf(e) {
4090
- if (startsWithString(e.args)) return { list: e.args, fromObject: false };
4091
- const list3 = argumentsLike(e.args);
4092
- return list3 !== void 0 && startsWithString(list3) ? { list: list3, fromObject: true } : void 0;
4093
- }
4094
- var CONSENT_COMMANDS = /* @__PURE__ */ new Set(["default", "update"]);
4095
- function isObjectConsent(command) {
4096
- return command?.fromObject === true && command.list[0] === "consent" && typeof command.list[1] === "string" && CONSENT_COMMANDS.has(command.list[1]);
4097
- }
4098
- function commandLabel(command) {
4099
- const [name, second] = command.list;
4100
- if (command.fromObject && typeof second === "string") {
4101
- if (isObjectConsent(command)) return `consent ${second}`;
4102
- if (name === "event") return safeName(second);
4103
- }
4104
- return GTAG_COMMANDS.has(name) ? `gtag ${name}` : GTAG_OTHER;
4105
- }
4106
- function eventLabel(e, command) {
4107
- if (e.isConsentCommand) return `consent ${String(e.args[1])}`;
4108
- if (e.event !== null) return safeName(e.event);
4109
- return command === void 0 ? NO_EVENT : commandLabel(command);
4110
- }
4111
- function labelKind(label) {
4112
- return label.startsWith("consent ") ? "consent" : label.startsWith("gtag ") ? "gtag" : "event";
4113
- }
4114
- function frameKind(e) {
4115
- return e.frame === void 0 ? "unknown" : e.frame.main ? "main" : "embedded";
4116
- }
4117
- function collectPaths(e, command, into) {
4118
- if (e.event?.startsWith("gtm.")) return;
4119
- if (command?.fromObject && command.list[0] === "event" && typeof command.list[1] === "string" && command.list[1].startsWith("gtm.")) return;
4120
- if (e.isConsentCommand || isObjectConsent(command)) {
4121
- const signals = (command?.fromObject ? command.list : e.args)[2];
4122
- if (typeof signals === "object" && signals !== null) for (const [name, value] of Object.entries(signals)) walk(value, safeKey(name), 0, into);
4123
- return;
4124
- }
4125
- if (command !== void 0) {
4126
- for (const arg of command.list.slice(command.list[0] === "set" ? 1 : 2)) walk(arg, "", 0, into);
4127
- return;
4128
- }
4129
- for (const arg of e.args) walk(arg, "", 0, into);
4130
- }
4131
- function pushShapes(records) {
4132
- const labels = new Map((records.steps ?? []).map((s) => [s.id, s.label]));
4133
- const steps = /* @__PURE__ */ new Map();
4134
- for (const e of records.dataLayerEvents) {
4135
- const step = e.stepId === null ? NO_STEP : labels.get(e.stepId) ?? NO_STEP;
4136
- const command = commandOf(e);
4137
- const event = eventLabel(e, command);
4138
- const kind = command === void 0 ? "object" : "gtag";
4139
- const frame = frameKind(e);
4140
- const groups = steps.get(step) ?? steps.set(step, /* @__PURE__ */ new Map()).get(step);
4141
- const key = JSON.stringify([event, kind, frame]);
4142
- const group = groups.get(key) ?? groups.set(key, { shape: { event, kind, frame, count: 0, paths: [], ids: [] }, types: /* @__PURE__ */ new Map() }).get(key);
4143
- group.shape.count += 1;
4144
- group.shape.ids.push(e.id);
4145
- collectPaths(e, command, group.types);
4146
- }
4147
- return {
4148
- pushes: records.dataLayerEvents.length,
4149
- steps: [...steps].map(([step, groups]) => ({
4150
- step,
4151
- events: [...groups.values()].map(({ shape, types }) => ({
4152
- ...shape,
4153
- paths: [...types].map(([path, set]) => ({ path, types: [...set].sort() }))
4154
- }))
4155
- }))
4156
- };
4157
- }
4158
-
4159
4552
  // packages/expect/src/event-map.ts
4160
4553
  var EVENT_NAME = /^[A-Za-z0-9_.: -]{1,200}$/;
4161
4554
  var PATH_NAME = /^[A-Za-z0-9_.()[\]*-]{1,200}$/;
@@ -4403,13 +4796,18 @@ function pushGroups(run) {
4403
4796
  paths: [...types].sort(([x], [y]) => x < y ? -1 : x > y ? 1 : 0).map(([path, set]) => ({ path, types: [...set].sort() }))
4404
4797
  }));
4405
4798
  }
4799
+ var withoutJoin = (g) => {
4800
+ const copy = { ...g };
4801
+ delete copy.joinedTo;
4802
+ return copy;
4803
+ };
4406
4804
  function pushNodes(groups, acrossFrames, mergeKinds) {
4407
4805
  const nodes = /* @__PURE__ */ new Map();
4408
4806
  for (const g of groups) {
4409
4807
  const frame = acrossFrames ? "any" : g.frame;
4410
4808
  const kind = mergeKinds ? void 0 : g.kind;
4411
4809
  const id = JSON.stringify([g.epoch, g.event, kind ?? null, frame]);
4412
- const node = nodes.get(id) ?? { epoch: g.epoch, event: g.event, ...kind === void 0 ? {} : { kind }, frame, frames: [], types: /* @__PURE__ */ new Map(), ...g.renamedFrom === void 0 ? {} : { renamedFrom: g.renamedFrom } };
4810
+ const node = nodes.get(id) ?? { epoch: g.epoch, event: g.event, ...kind === void 0 ? {} : { kind }, frame, frames: [], types: /* @__PURE__ */ new Map(), ...g.renamedFrom === void 0 ? {} : { renamedFrom: g.renamedFrom }, ...g.joinedTo === void 0 ? {} : { joinedTo: g.joinedTo } };
4413
4811
  if (!node.frames.includes(g.frame)) node.frames.push(g.frame);
4414
4812
  for (const p of g.paths) node.types.set(p.path, [.../* @__PURE__ */ new Set([...node.types.get(p.path) ?? [], ...p.types])].sort());
4415
4813
  nodes.set(id, node);
@@ -4440,6 +4838,7 @@ function pairNames(a, b, userMap, context = {}) {
4440
4838
  const taken = new Set(inA);
4441
4839
  const claimed = /* @__PURE__ */ new Set();
4442
4840
  const joined = /* @__PURE__ */ new Map();
4841
+ const joinedEpoch = /* @__PURE__ */ new Map();
4443
4842
  const pair = (sameEpoch) => {
4444
4843
  for (const from of onlyA) {
4445
4844
  if (joined.has(epochEventId(from)) || !sameEpoch && movedNames.has(from.event)) continue;
@@ -4451,6 +4850,7 @@ function pairNames(a, b, userMap, context = {}) {
4451
4850
  claimed.add(epochEventId(to));
4452
4851
  taken.add(JSON.stringify([from.epoch, to.event]));
4453
4852
  joined.set(epochEventId(from), to.event);
4853
+ joinedEpoch.set(epochEventId(from), to.epoch);
4454
4854
  }
4455
4855
  };
4456
4856
  pair(true);
@@ -4459,7 +4859,9 @@ function pairNames(a, b, userMap, context = {}) {
4459
4859
  return normalized.map((g, i) => {
4460
4860
  const recorded = a[i];
4461
4861
  const to = joined.get(epochEventId(recorded));
4462
- return to === void 0 ? kept[i] : { ...g, event: to, renamedFrom: recorded.event };
4862
+ if (to === void 0) return withoutJoin(kept[i]);
4863
+ const target = joinedEpoch.get(epochEventId(recorded));
4864
+ return { ...withoutJoin(g), event: to, renamedFrom: recorded.event, ...target === recorded.epoch ? {} : { joinedTo: target } };
4463
4865
  });
4464
4866
  }
4465
4867
  function typesId(n) {
@@ -4507,7 +4909,17 @@ function diffPushes(a, b, options = {}) {
4507
4909
  compare(withoutEventName(g, f), withoutEventName(f, g));
4508
4910
  }
4509
4911
  const taken = /* @__PURE__ */ new Set();
4912
+ const moveEpoch = (g, to) => {
4913
+ taken.add(to);
4914
+ result.moved.push({ event: g.event, ...g.renamedFrom === void 0 ? {} : { renamedFrom: g.renamedFrom }, kind: "epoch", ...g.kind === void 0 ? {} : { pushKind: g.kind }, frame: g.frame, from: g.epoch, to: to.epoch });
4915
+ };
4916
+ const loose = [];
4510
4917
  for (const g of gone) {
4918
+ const bound = g.joinedTo === void 0 ? void 0 : fresh.find((f) => !taken.has(f) && f.epoch === g.joinedTo && f.event === g.event && f.kind === g.kind && f.frame === g.frame);
4919
+ if (bound) moveEpoch(g, bound);
4920
+ else loose.push(g);
4921
+ }
4922
+ for (const g of loose) {
4511
4923
  const match = fresh.find(
4512
4924
  (f) => !taken.has(f) && f.event === g.event && f.kind === g.kind && f.frame === g.frame && typesId(f) === typesId(g) && neighbourEpochs(order, g.epoch, f.epoch)
4513
4925
  );
@@ -4515,8 +4927,7 @@ function diffPushes(a, b, options = {}) {
4515
4927
  result.eventsRemoved.push({ ...nodeRef({ ...g, renamedFrom: void 0 }), event: g.renamedFrom ?? g.event });
4516
4928
  continue;
4517
4929
  }
4518
- taken.add(match);
4519
- result.moved.push({ event: g.event, ...g.renamedFrom === void 0 ? {} : { renamedFrom: g.renamedFrom }, kind: "epoch", ...g.kind === void 0 ? {} : { pushKind: g.kind }, frame: g.frame, from: g.epoch, to: match.epoch });
4930
+ moveEpoch(g, match);
4520
4931
  }
4521
4932
  for (const f of fresh) if (!taken.has(f)) result.eventsAdded.push(nodeRef(f));
4522
4933
  result.changed = result.eventsAdded.length + result.eventsRemoved.length + result.pathsAdded.length + result.pathsRemoved.length + result.typeChanges.length + result.kindChanged.length > 0;
@@ -4697,7 +5108,7 @@ function idPresenceChanges(a, b) {
4697
5108
  }
4698
5109
  return changes;
4699
5110
  }
4700
- function hostOf2(url) {
5111
+ function hostOf3(url) {
4701
5112
  try {
4702
5113
  return new URL(url).hostname;
4703
5114
  } catch {
@@ -4713,7 +5124,7 @@ function allowedFlagIds(run) {
4713
5124
  return /* @__PURE__ */ new Set([...platform, ...unknown.filter((id) => !blocked.has(id))]);
4714
5125
  }
4715
5126
  function flagCounts(run) {
4716
- const requestHosts = new Map(run.requests.map((r) => [r.id, hostOf2(r.url)]));
5127
+ const requestHosts = new Map(run.requests.map((r) => [r.id, hostOf3(r.url)]));
4717
5128
  const hitHosts = new Map(run.hits.map((h) => [h.id, requestHosts.get(h.requestId) ?? ""]));
4718
5129
  const allowedIds = allowedFlagIds(run);
4719
5130
  const counts = /* @__PURE__ */ new Map();
@@ -6433,7 +6844,7 @@ function buildDataLayerNotHookedFlag(input) {
6433
6844
  const listed = names.slice(0, MAX_LISTED_NAMES).join(", ");
6434
6845
  const rest = names.length - MAX_LISTED_NAMES;
6435
6846
  const shown2 = rest > 0 ? `${listed} and ${rest} more` : listed;
6436
- const plural2 = names.length > 1;
6847
+ const plural3 = names.length > 1;
6437
6848
  const advice = misses.every((m) => untrapped.has(m.name) && input.hooked.includes(m.name)) ? "The page defines them in a way the hook cannot trap." : "Add them to options.dataLayerNames.";
6438
6849
  return {
6439
6850
  type: "flag",
@@ -6441,7 +6852,7 @@ function buildDataLayerNotHookedFlag(input) {
6441
6852
  runId: input.runId,
6442
6853
  kind: "dataLayerNotHooked",
6443
6854
  recordIds: misses.map((m) => m.id),
6444
- detail: plural2 ? `Google loaders name the data layers ${shown2}, which are not hooked, so pushes to them are not recorded. ${advice}` : `A Google loader names the data layer ${shown2}, which is not hooked, so pushes to it are not recorded. ${advice.replace("them", "it")}`
6855
+ detail: plural3 ? `Google loaders name the data layers ${shown2}, which are not hooked, so pushes to them are not recorded. ${advice}` : `A Google loader names the data layer ${shown2}, which is not hooked, so pushes to it are not recorded. ${advice.replace("them", "it")}`
6445
6856
  };
6446
6857
  }
6447
6858
  function buildDataLayerReassignedFlags(input) {
@@ -7092,7 +7503,7 @@ import { isAbsolute } from "node:path";
7092
7503
 
7093
7504
  // packages/recorder/src/gtm-scrub.ts
7094
7505
  var REDACTED2 = "[redacted]";
7095
- var MAX_DEPTH3 = 8;
7506
+ var MAX_DEPTH4 = 8;
7096
7507
  var BASE64_TOKEN2 = /[A-Za-z0-9+/_-]{8,}={0,2}/g;
7097
7508
  var QUERY_LIKE = /^[\w.[\]-]+=[^&\s]*(?:&[\w.[\]-]+=[^&\s]*)*$/;
7098
7509
  function decodeBase64Text2(value) {
@@ -7116,7 +7527,7 @@ function queryValues(text2) {
7116
7527
  function containsSecret(text2, secret, depth = 0) {
7117
7528
  if (text2.length < secret.length) return false;
7118
7529
  if (text2.includes(secret)) return true;
7119
- if (depth >= MAX_DEPTH3) return false;
7530
+ if (depth >= MAX_DEPTH4) return false;
7120
7531
  const next = depth + 1;
7121
7532
  const decoded = urlDecode(text2);
7122
7533
  if (decoded !== text2 && containsSecret(decoded, secret, next)) return true;
@@ -9076,7 +9487,7 @@ function formatDuration(ms) {
9076
9487
 
9077
9488
  // packages/recorder/src/locators.ts
9078
9489
  var ROLE_FAMILIES = ["button", "radio", "checkbox", "link", "tab", "option"];
9079
- var MAX_LISTED4 = 10;
9490
+ var MAX_LISTED6 = 10;
9080
9491
  var MAX_NAME2 = 60;
9081
9492
  var POLL_MS2 = 100;
9082
9493
  async function resolveLocator(page2, locator, timeout) {
@@ -9124,7 +9535,7 @@ function parseControls(snapshot) {
9124
9535
  return found;
9125
9536
  }
9126
9537
  function controlsFromSnapshot(snapshot) {
9127
- return parseControls(snapshot).slice(0, MAX_LISTED4).map((c) => `${c.role} "${visibleName(c.name)}"`);
9538
+ return parseControls(snapshot).slice(0, MAX_LISTED6).map((c) => `${c.role} "${visibleName(c.name)}"`);
9128
9539
  }
9129
9540
  var words = (text2) => text2.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
9130
9541
  function sharedWords(a, b) {
@@ -9161,7 +9572,7 @@ async function timeoutMessage(page2, firstLine, requested) {
9161
9572
  const ofRole = parseControls(snapshot).filter((c) => c.role === requested.role);
9162
9573
  if (ofRole.length === 0) return `${firstLine} No ${requested.role} controls on the page.${general.length === 0 ? "" : ` Controls on the page: ${general.join(", ")}.`}`;
9163
9574
  const ranked = requested.name === void 0 ? ofRole : rankByName(ofRole, requested.name);
9164
- return `${firstLine} Closest ${requested.role} controls: ${ranked.slice(0, MAX_LISTED4).map((c) => `"${visibleName(c.name)}"`).join(", ")}.`;
9575
+ return `${firstLine} Closest ${requested.role} controls: ${ranked.slice(0, MAX_LISTED6).map((c) => `"${visibleName(c.name)}"`).join(", ")}.`;
9165
9576
  } catch {
9166
9577
  return firstLine;
9167
9578
  }
@@ -9204,7 +9615,7 @@ async function blockingControls(context, form = null) {
9204
9615
  const scope = live ? form : null;
9205
9616
  for (const page2 of context.pages()) {
9206
9617
  try {
9207
- const controls = await withDeadline(page2.evaluate(readBlockingControls, { max: MAX_LISTED4, form: scope }), DIAGNOSTIC_DEADLINE_MS);
9618
+ const controls = await withDeadline(page2.evaluate(readBlockingControls, { max: MAX_LISTED6, form: scope }), DIAGNOSTIC_DEADLINE_MS);
9208
9619
  for (const c of controls) {
9209
9620
  if (!BLOCK_REASONS.includes(c.reason)) continue;
9210
9621
  const kind = KINDS.includes(c.kind) ? c.kind : "control";
@@ -9213,9 +9624,9 @@ async function blockingControls(context, form = null) {
9213
9624
  }
9214
9625
  } catch {
9215
9626
  }
9216
- if (listed.length >= MAX_LISTED4) break;
9627
+ if (listed.length >= MAX_LISTED6) break;
9217
9628
  }
9218
- return listed.slice(0, MAX_LISTED4);
9629
+ return listed.slice(0, MAX_LISTED6);
9219
9630
  }
9220
9631
 
9221
9632
  // packages/recorder/src/payment.ts
@@ -9253,7 +9664,7 @@ function providerBlockedOnSite(providerId, siteHost) {
9253
9664
  }
9254
9665
  return void 0;
9255
9666
  }
9256
- function hostOf3(url) {
9667
+ function hostOf4(url) {
9257
9668
  try {
9258
9669
  return normalizeHost(new URL(url).hostname);
9259
9670
  } catch {
@@ -9290,7 +9701,7 @@ async function cardFrameServed(page2, field, cardHost, deadline) {
9290
9701
  for (const element of await withinDeadline(page2.locator(field.frame).elementHandles(), deadline)) {
9291
9702
  const frame = await withinDeadline(element.contentFrame(), deadline);
9292
9703
  if (!frame) continue;
9293
- if (hostOf3(frame.url()) !== cardHost) {
9704
+ if (hostOf4(frame.url()) !== cardHost) {
9294
9705
  elsewhere = true;
9295
9706
  } else if (!field.path.test(pathOf2(frame.url()))) {
9296
9707
  otherPath = pathOf2(frame.url());
@@ -9343,7 +9754,7 @@ async function runPayment(page2, recorder, value, identity, testPayment, record,
9343
9754
  const blocked = providerBlockedOnSite(provider.id, siteHost);
9344
9755
  if (blocked) throw new Error(blocked);
9345
9756
  const allowed = normalizeHost(testPayment.host);
9346
- if (hostOf3(page2.url()) !== allowed || normalizeHost(siteHost) !== allowed) {
9757
+ if (hostOf4(page2.url()) !== allowed || normalizeHost(siteHost) !== allowed) {
9347
9758
  throw new Error("test mode not detected (the page is not on the allowed test payment host)");
9348
9759
  }
9349
9760
  const declared = testPayment.declaredProviders?.includes(provider.id) === true;
@@ -9378,7 +9789,7 @@ async function runPayment(page2, recorder, value, identity, testPayment, record,
9378
9789
  var GONE_FRAME = "the card frame is gone or not served from the card host";
9379
9790
  async function frameStillServed(element, cardHost, field) {
9380
9791
  const frame = await element.contentFrame();
9381
- if (!frame || hostOf3(frame.url()) !== cardHost || !field.path.test(pathOf2(frame.url()))) {
9792
+ if (!frame || hostOf4(frame.url()) !== cardHost || !field.path.test(pathOf2(frame.url()))) {
9382
9793
  throw new OwnReason(GONE_FRAME);
9383
9794
  }
9384
9795
  return frame;
@@ -10649,7 +11060,7 @@ var BaselineError = class extends Error {
10649
11060
  }
10650
11061
  code;
10651
11062
  };
10652
- function hostOf4(site) {
11063
+ function hostOf5(site) {
10653
11064
  try {
10654
11065
  return new URL(site).hostname;
10655
11066
  } catch {
@@ -10660,7 +11071,7 @@ function buildBaseline(records, byPage) {
10660
11071
  return {
10661
11072
  baselineSchemaVersion: BASELINE_SCHEMA_VERSION,
10662
11073
  scenario: records.run.scenario,
10663
- site: hostOf4(records.run.site),
11074
+ site: hostOf5(records.run.site),
10664
11075
  byPage,
10665
11076
  keys: hitShape(records, { byPage }),
10666
11077
  dataLayer: pushGroups(records)
@@ -10758,7 +11169,7 @@ function compareBaseline(baseline, records) {
10758
11169
  if (scenarioName(baseline.scenario) !== scenarioName(records.run.scenario)) {
10759
11170
  warnings.push(`The baseline is from scenario ${baseline.scenario}, and this run is ${records.run.scenario}.`);
10760
11171
  }
10761
- const host = hostOf4(records.run.site);
11172
+ const host = hostOf5(records.run.site);
10762
11173
  if (baseline.site !== host) warnings.push(`The baseline is from site ${baseline.site || "(none)"}, and this run is ${host || "(none)"}.`);
10763
11174
  const epochOrder2 = [...records.consentEpochs].sort((x, y) => x.startT - y.startT).map((e) => e.label);
10764
11175
  const diff = diffShapes(baseline.keys, hitShape(records, { byPage: baseline.byPage }), { epochOrder: epochOrder2 });
@@ -11172,7 +11583,7 @@ function segmentOf(verdicts2) {
11172
11583
  if (mark === "mixed") label = MIXED_HIT;
11173
11584
  return { mark, label, hits };
11174
11585
  }
11175
- function hostOf5(url) {
11586
+ function hostOf6(url) {
11176
11587
  try {
11177
11588
  return new URL(url).host || void 0;
11178
11589
  } catch {
@@ -11182,7 +11593,7 @@ function hostOf5(url) {
11182
11593
  function flagViews(records) {
11183
11594
  const hostByRecord = /* @__PURE__ */ new Map();
11184
11595
  for (const r of records.requests) {
11185
- const host = hostOf5(r.url);
11596
+ const host = hostOf6(r.url);
11186
11597
  if (host) hostByRecord.set(r.id, host);
11187
11598
  }
11188
11599
  for (const h of records.hits) {
@@ -11281,7 +11692,7 @@ function buildReportModel(records) {
11281
11692
  startedAt: new Date(run.startedAt).toISOString(),
11282
11693
  networkMode: run.networkMode,
11283
11694
  ...run.viewport && { viewport: `${run.viewport.width}x${run.viewport.height}` },
11284
- host: hostOf5(run.site) ?? "",
11695
+ host: hostOf6(run.site) ?? "",
11285
11696
  pingwrightVersion: run.pingwrightVersion,
11286
11697
  schemaVersion: version
11287
11698
  },
@@ -11359,22 +11770,22 @@ function list2(names) {
11359
11770
  const all = [...names].sort(byVendorName).map(vendorName);
11360
11771
  return all.length < 2 ? all.join("") : `${all.slice(0, -1).join(", ")} and ${all.at(-1)}`;
11361
11772
  }
11362
- var plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
11773
+ var plural2 = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
11363
11774
  function checkParts(checks, verb, inRuns) {
11364
- return [...checks].sort(([a], [b]) => a.localeCompare(b)).map(([name, runs]) => `built-in check ${name} ${verb}${inRuns ? ` in ${plural(runs, "run")}` : ""}`);
11775
+ return [...checks].sort(([a], [b]) => a.localeCompare(b)).map(([name, runs]) => `built-in check ${name} ${verb}${inRuns ? ` in ${plural2(runs, "run")}` : ""}`);
11365
11776
  }
11366
11777
  function findingsSentence(f, inRuns = false) {
11367
11778
  const parts = [];
11368
11779
  for (const [label, vendors] of [...f.hits].sort(([a], [b]) => a.localeCompare(b))) parts.push(`${list2(vendors)} ${vendors.size === 1 ? "sends" : "send"} hits in the ${label} state`);
11369
11780
  for (const [label, vendors] of [...f.identifiers].sort(([a], [b]) => a.localeCompare(b))) parts.push(`identifiers go out to ${list2(vendors)} in the ${label} state`);
11370
11781
  if (parts.length === 0 && f.unchecked === 0) parts.push("no leaks");
11371
- if (f.failed > 0) parts.push(`${plural(f.failed, "rule")} failed`);
11782
+ if (f.failed > 0) parts.push(`${plural2(f.failed, "rule")} failed`);
11372
11783
  parts.push(...checkParts(f.failedChecks, "failed", inRuns));
11373
- if (f.unchecked > 0) parts.push(`${plural(f.unchecked, "expectation")} could not be checked`);
11374
- if (f.warned > 0) parts.push(`${plural(f.warned, "rule")} warned`);
11784
+ if (f.unchecked > 0) parts.push(`${plural2(f.unchecked, "expectation")} could not be checked`);
11785
+ if (f.warned > 0) parts.push(`${plural2(f.warned, "rule")} warned`);
11375
11786
  parts.push(...checkParts(f.warnedChecks, "warned", inRuns));
11376
- if (f.unlinkedServerHits > 0) parts.push(`${plural(f.unlinkedServerHits, "server container hit")} could not be linked to a browser hit`);
11377
- if (f.probableServerHits > 0) parts.push(`${plural(f.probableServerHits, "server container hit")} placed by a probable link`);
11787
+ if (f.unlinkedServerHits > 0) parts.push(`${plural2(f.unlinkedServerHits, "server container hit")} could not be linked to a browser hit`);
11788
+ if (f.probableServerHits > 0) parts.push(`${plural2(f.probableServerHits, "server container hit")} placed by a probable link`);
11378
11789
  return parts.join("; ");
11379
11790
  }
11380
11791
  function runVerdict(model) {
@@ -12737,7 +13148,7 @@ ${hints.join(" ")}
12737
13148
 
12738
13149
  // packages/cli/src/report/suite.ts
12739
13150
  var recordKey = (scenario, variant, store) => JSON.stringify(store === void 0 ? [scenario, variant] : [scenario, variant, store]);
12740
- function hostOf6(url) {
13151
+ function hostOf7(url) {
12741
13152
  try {
12742
13153
  return new URL(url).host;
12743
13154
  } catch {
@@ -12802,7 +13213,7 @@ function buildSuiteModel(manifest, records) {
12802
13213
  id: manifest.id,
12803
13214
  ...manifest.label !== void 0 && { label: manifest.label },
12804
13215
  startedAt: new Date(manifest.startedAt).toISOString(),
12805
- host: hostOf6(manifest.site),
13216
+ host: hostOf7(manifest.site),
12806
13217
  stores: storeNames,
12807
13218
  variants: manifest.variants,
12808
13219
  exitCode: manifest.exitCode