tagreeve 0.6.0 → 0.6.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.
- package/README.md +6 -2
- package/dist/cli.js +890 -512
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -108,6 +108,7 @@ function pageTimeToEpoch(pageTime, offset) {
|
|
|
108
108
|
|
|
109
109
|
// packages/core/src/records.ts
|
|
110
110
|
var RECORD_SCHEMA_VERSION = 5;
|
|
111
|
+
var GTM_TAG_STATUSES = ["success", "failure", "exception", "timeout"];
|
|
111
112
|
|
|
112
113
|
// packages/core/src/store.ts
|
|
113
114
|
import { createReadStream } from "node:fs";
|
|
@@ -516,6 +517,9 @@ function* variants(text2, depth = 0, seen = /* @__PURE__ */ new Set()) {
|
|
|
516
517
|
if (depth >= MAX_DEPTH) return;
|
|
517
518
|
for (const decoded of base64Decodes(text2)) yield* variants(decoded, depth + 1, seen);
|
|
518
519
|
}
|
|
520
|
+
function readings(text2) {
|
|
521
|
+
return [...variants(text2)];
|
|
522
|
+
}
|
|
519
523
|
function fieldHashes(...values) {
|
|
520
524
|
const hashes = /* @__PURE__ */ new Set();
|
|
521
525
|
for (const value of values) {
|
|
@@ -909,17 +913,18 @@ var GCD_LETTERS = {
|
|
|
909
913
|
v: { notSet: false, default: "granted", update: "granted" },
|
|
910
914
|
l: { notSet: true }
|
|
911
915
|
};
|
|
916
|
+
var gcdLetterAt = (gcd, i) => gcd[2 + 2 * i];
|
|
912
917
|
function gcdSignals(gcd) {
|
|
913
918
|
if (!gcd || gcd.length < 9) return void 0;
|
|
914
919
|
const out = {};
|
|
915
920
|
GCD_SIGNALS.forEach((name, i) => {
|
|
916
|
-
out[name] = GCD_LETTERS[gcd
|
|
921
|
+
out[name] = GCD_LETTERS[gcdLetterAt(gcd, i)] ?? { notSet: false, default: "unknown", update: "unknown" };
|
|
917
922
|
});
|
|
918
923
|
return out;
|
|
919
924
|
}
|
|
920
925
|
function gcdLetters(gcd) {
|
|
921
926
|
if (!gcdSignals(gcd)) return void 0;
|
|
922
|
-
return GCD_SIGNALS.map((_, i) => gcd
|
|
927
|
+
return GCD_SIGNALS.map((_, i) => gcdLetterAt(gcd, i) in GCD_LETTERS ? gcdLetterAt(gcd, i) : "?");
|
|
923
928
|
}
|
|
924
929
|
function gcdValue(signal) {
|
|
925
930
|
if (signal.notSet) return "unknown";
|
|
@@ -1356,8 +1361,8 @@ var googleAds = {
|
|
|
1356
1361
|
const oid = p.get("oid");
|
|
1357
1362
|
if (oid) params.transaction_id = oid;
|
|
1358
1363
|
for (const [k, v] of p) {
|
|
1359
|
-
|
|
1360
|
-
|
|
1364
|
+
const name = k.startsWith("ep.") ? k.slice(3) : k.startsWith("epn.") ? k.slice(4) : void 0;
|
|
1365
|
+
if (name && name !== "conversionId") params[name] = v;
|
|
1361
1366
|
}
|
|
1362
1367
|
return [
|
|
1363
1368
|
withFields({
|
|
@@ -1861,7 +1866,6 @@ var VENDOR_KEYS = /* @__PURE__ */ new Set(["vendor", "event", "page", "transport
|
|
|
1861
1866
|
var GROUP_KEYS = ["consent", "ids", "params", "identity", "body"];
|
|
1862
1867
|
var COOKIE_RULE_KEYS = ["cookie", "before", "in", "after", "from"];
|
|
1863
1868
|
var TAG_RULE_KEYS = ["tag", "count", "after", "from"];
|
|
1864
|
-
var TAG_STATUSES = ["success", "failure", "exception", "timeout"];
|
|
1865
1869
|
var TAG_SELECTOR_KEYS = ["id", "name", "container", "event", "status", "side"];
|
|
1866
1870
|
var MAX_TAG_TEXT = 200;
|
|
1867
1871
|
var BODY_KEYS = ["has", "only", "ignore"];
|
|
@@ -1876,6 +1880,9 @@ var OPTION_KEYS = ["network", "seed", "consentTimeout", "graceWindow", "optional
|
|
|
1876
1880
|
var MAX_DATALAYER_NAMES = 8;
|
|
1877
1881
|
var DATALAYER_NAME_PATTERN = /^[A-Za-z_$][\w$]{0,63}$/;
|
|
1878
1882
|
var NEVER_TRAPPED_NAMES = ["location", "Shopify", "__proto__", "constructor", "prototype"];
|
|
1883
|
+
function isDataLayerName(name) {
|
|
1884
|
+
return typeof name === "string" && DATALAYER_NAME_PATTERN.test(name) && !NEVER_TRAPPED_NAMES.includes(name);
|
|
1885
|
+
}
|
|
1879
1886
|
var HOST_HINT = ", each a host such as cdn.example.com or a wildcard such as *.example.com";
|
|
1880
1887
|
function isRegExp(source) {
|
|
1881
1888
|
try {
|
|
@@ -1899,6 +1906,11 @@ function parseDuration(value) {
|
|
|
1899
1906
|
const unit = m[2] ?? "ms";
|
|
1900
1907
|
return Number(m[1]) * (unit === "m" ? 6e4 : unit === "s" ? 1e3 : 1);
|
|
1901
1908
|
}
|
|
1909
|
+
function durationAt(value, path, fail) {
|
|
1910
|
+
const ms = parseDuration(value);
|
|
1911
|
+
if (ms === void 0) fail(path, "must be a duration such as 4s, 500ms or 2m");
|
|
1912
|
+
return ms;
|
|
1913
|
+
}
|
|
1902
1914
|
function parseCount(value) {
|
|
1903
1915
|
const text2 = String(value).trim();
|
|
1904
1916
|
const m = /^(>=|<=|>|<|=)?\s*(\d+)$/.exec(text2);
|
|
@@ -1951,7 +1963,7 @@ function parseOptions(raw, path, fail, { keys = OPTION_KEYS, echo = true } = {})
|
|
|
1951
1963
|
} else if (k === "dataLayerNames") {
|
|
1952
1964
|
const names = Array.isArray(v) ? v : [];
|
|
1953
1965
|
if (!Array.isArray(v) || v.length === 0 || v.length > MAX_DATALAYER_NAMES) fail(p, `must be a list of 1 to ${MAX_DATALAYER_NAMES} global names such as myLayer`);
|
|
1954
|
-
else if (!names.every(
|
|
1966
|
+
else if (!names.every(isDataLayerName)) {
|
|
1955
1967
|
fail(p, `each name must be a plain identifier of at most 64 characters (letters, digits, _ and $), and not ${NEVER_TRAPPED_NAMES.join(", ")}`);
|
|
1956
1968
|
} else options.dataLayerNames = [...new Set(v)];
|
|
1957
1969
|
} else if (k === "serverHosts") {
|
|
@@ -1985,9 +1997,9 @@ function parseOptions(raw, path, fail, { keys = OPTION_KEYS, echo = true } = {})
|
|
|
1985
1997
|
if (isHostList(v)) options.firstPartyHosts = v;
|
|
1986
1998
|
else fail(p, `must be a list of hosts${HOST_HINT}`);
|
|
1987
1999
|
} else {
|
|
1988
|
-
const ms =
|
|
1989
|
-
if (ms === void 0)
|
|
1990
|
-
|
|
2000
|
+
const ms = durationAt(v, p, fail);
|
|
2001
|
+
if (ms === void 0) continue;
|
|
2002
|
+
if (k === "consentTimeout") options.consentTimeout = ms;
|
|
1991
2003
|
else if (k === "optionalTimeout") {
|
|
1992
2004
|
if (ms < 100 || ms > 3e4) fail(p, "must be from 100ms to 30s");
|
|
1993
2005
|
else options.optionalTimeout = ms;
|
|
@@ -2188,9 +2200,7 @@ function parseScenario(text2, extraVendorKeys = []) {
|
|
|
2188
2200
|
const until = value.until === void 0 ? void 0 : condition(value.until, [...at, "until"]);
|
|
2189
2201
|
const duration = (key) => {
|
|
2190
2202
|
if (value[key] === void 0) return void 0;
|
|
2191
|
-
|
|
2192
|
-
if (ms === void 0) fail([...at, key], "must be a duration such as 4s, 500ms or 10m");
|
|
2193
|
-
return ms;
|
|
2203
|
+
return durationAt(value[key], [...at, key], fail);
|
|
2194
2204
|
};
|
|
2195
2205
|
const settle = duration("settle");
|
|
2196
2206
|
const timeout = duration("timeout");
|
|
@@ -2285,8 +2295,7 @@ function parseScenario(text2, extraVendorKeys = []) {
|
|
|
2285
2295
|
const url = urlMatcher(value.url, [...path, kind, "url"]);
|
|
2286
2296
|
let timeout;
|
|
2287
2297
|
if ("timeout" in value) {
|
|
2288
|
-
timeout =
|
|
2289
|
-
if (timeout === void 0) fail([...path, kind, "timeout"], "must be a duration such as 90s or 2m");
|
|
2298
|
+
timeout = durationAt(value.timeout, [...path, kind, "timeout"], fail);
|
|
2290
2299
|
}
|
|
2291
2300
|
if (url && (!("timeout" in value) || timeout !== void 0)) add2({ kind, value: timeout === void 0 ? { url } : { url, timeout } });
|
|
2292
2301
|
}
|
|
@@ -2342,7 +2351,7 @@ function parseScenario(text2, extraVendorKeys = []) {
|
|
|
2342
2351
|
} else if (key === "status") {
|
|
2343
2352
|
const items = Array.isArray(raw2) ? raw2 : [raw2];
|
|
2344
2353
|
if (items.length === 0 || !items.every((x) => typeof x === "string" && x && x.length <= MAX_FIELD_NAME)) fail(p, "must be a status or a list of statuses");
|
|
2345
|
-
else if (!items.every((x) =>
|
|
2354
|
+
else if (!items.every((x) => GTM_TAG_STATUSES.includes(x))) fail(p, `must be one of ${GTM_TAG_STATUSES.join(", ")}`);
|
|
2346
2355
|
else tag.status = items;
|
|
2347
2356
|
} else if (key === "side") {
|
|
2348
2357
|
if (raw2 === "web" || raw2 === "server") tag.side = raw2;
|
|
@@ -2542,13 +2551,14 @@ var MAX_LETTER_SETS = 3;
|
|
|
2542
2551
|
function tagId(hit) {
|
|
2543
2552
|
const conversionId = hit.params.conversionId;
|
|
2544
2553
|
const tid = hit.vendor === "ga4" ? hit.params.tid : conversionId && /^\d+$/.test(conversionId) ? `AW-${conversionId}` : void 0;
|
|
2545
|
-
return tid && TAG_ID.test(tid) ? tid : "(no tag ID)
|
|
2554
|
+
return tid && TAG_ID.test(tid) ? tid : `${hit.vendor === "ga4" ? "GA4" : "Google Ads"} (no tag ID)`;
|
|
2546
2555
|
}
|
|
2547
2556
|
function list(names) {
|
|
2548
2557
|
return names.length < 2 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
|
|
2549
2558
|
}
|
|
2550
2559
|
function lettersNote(sets) {
|
|
2551
|
-
|
|
2560
|
+
const shown2 = [...sets].slice(0, MAX_LISTED).map(([tid, letters]) => `${tid} ${[...letters].slice(0, MAX_LETTER_SETS).join(", ")}`).join("; ");
|
|
2561
|
+
return sets.size > MAX_LISTED ? `${shown2}; and ${sets.size - MAX_LISTED} more` : shown2;
|
|
2552
2562
|
}
|
|
2553
2563
|
function consentModeSetup(hits, dataLayer) {
|
|
2554
2564
|
const google = hits.filter((h) => GOOGLE_VENDORS.has(h.vendor));
|
|
@@ -2591,7 +2601,8 @@ function consentModeSetup(hits, dataLayer) {
|
|
|
2591
2601
|
const groups = [...unset].map(([tid, names]) => {
|
|
2592
2602
|
const ordered = GCD_SIGNALS.filter((n) => names.has(n));
|
|
2593
2603
|
const note = v1Only.has(tid) ? " (a default for ad_storage and analytics_storage only, without the two v2 signals)" : "";
|
|
2594
|
-
const
|
|
2604
|
+
const unsetFirst = [...letterSets.get(tid) ?? []].sort((a, b) => Number(b.includes("l")) - Number(a.includes("l")));
|
|
2605
|
+
const letters = unsetFirst.slice(0, MAX_LETTER_SETS).join(", ");
|
|
2595
2606
|
return `Google tag ${tid} never set ${list(ordered)}${note} (gcd letters: ${letters})`;
|
|
2596
2607
|
});
|
|
2597
2608
|
const shown2 = groups.slice(0, MAX_LISTED).join("; ");
|
|
@@ -2616,10 +2627,11 @@ var STATUS_WORD = /^[a-z_]{1,20}$/;
|
|
|
2616
2627
|
var ID_WORD = /^[\w.-]{1,40}$/;
|
|
2617
2628
|
var COARSE_SEPARATORS = /[\s/=:?&#|,;]+/;
|
|
2618
2629
|
var NAME_SEPARATORS = /[\s/=:?&#|,;._+()[\]{}<>'"`]+/;
|
|
2630
|
+
var ALNUM_RUNS = /[^A-Za-z0-9]+/;
|
|
2619
2631
|
function maskTagName(name) {
|
|
2620
2632
|
const kinds = valueKinds(name);
|
|
2621
2633
|
if (kinds.has("email") || kinds.has("phone")) return OTHER_NAME;
|
|
2622
|
-
return [...name.split(COARSE_SEPARATORS), ...name.split(NAME_SEPARATORS)].some((part) => isValueSegment(part)) ? OTHER_NAME : name;
|
|
2634
|
+
return [...name.split(COARSE_SEPARATORS), ...name.split(NAME_SEPARATORS), ...name.split(ALNUM_RUNS)].some((part) => isValueSegment(part)) ? OTHER_NAME : name;
|
|
2623
2635
|
}
|
|
2624
2636
|
function maskTagId(id) {
|
|
2625
2637
|
return ID_WORD.test(id) ? id : OTHER_NAME;
|
|
@@ -2633,8 +2645,15 @@ function nameOf(report, tag, expected) {
|
|
|
2633
2645
|
return named ? { name: named, from: "expectedTags" } : void 0;
|
|
2634
2646
|
}
|
|
2635
2647
|
var tagLabel = (id, name) => name ? `${maskTagId(id)} ${maskTagName(name)}` : maskTagId(id);
|
|
2648
|
+
function expectedTagsOf(run) {
|
|
2649
|
+
const override = run?.gtmOverride;
|
|
2650
|
+
return override ? { container: override.container, tags: override.expectedTags } : void 0;
|
|
2651
|
+
}
|
|
2652
|
+
function listWithMore(items, max) {
|
|
2653
|
+
return items.length > max ? `${items.slice(0, max).join(", ")} and ${items.length - max} more` : items.join(", ");
|
|
2654
|
+
}
|
|
2636
2655
|
function listLabels(labels) {
|
|
2637
|
-
return labels
|
|
2656
|
+
return listWithMore(labels, MAX_LISTED2);
|
|
2638
2657
|
}
|
|
2639
2658
|
function evaluateTagRule(rule, input) {
|
|
2640
2659
|
const selector = rule.tag;
|
|
@@ -2723,7 +2742,6 @@ function summarizeTags(reports, expected) {
|
|
|
2723
2742
|
var DEFAULT_GRACE_MS = 50;
|
|
2724
2743
|
var MAX_LISTED3 = 5;
|
|
2725
2744
|
var MAX_NAMES = 12;
|
|
2726
|
-
var GOOGLE_VENDORS2 = /* @__PURE__ */ new Set(["ga4", "google-ads"]);
|
|
2727
2745
|
function evaluate(records, scenario, options = {}) {
|
|
2728
2746
|
const runRecord = records.find((r) => r.type === "run");
|
|
2729
2747
|
const runId = runRecord?.id ?? records.find((r) => "runId" in r)?.runId ?? newId("run");
|
|
@@ -2740,7 +2758,7 @@ function evaluate(records, scenario, options = {}) {
|
|
|
2740
2758
|
responses: records.filter((r) => r.type === "response"),
|
|
2741
2759
|
checkpoints: records.filter((r) => r.type === "checkpoint"),
|
|
2742
2760
|
tagReports: records.filter((r) => r.type === "tagReport"),
|
|
2743
|
-
|
|
2761
|
+
expectedTags: expectedTagsOf(runRecord),
|
|
2744
2762
|
networkMode: runRecord?.networkMode,
|
|
2745
2763
|
grace: options.graceWindowMs ?? scenario.options.graceWindow ?? DEFAULT_GRACE_MS,
|
|
2746
2764
|
identity: options.identity ?? identityOf(runRecord)
|
|
@@ -2766,8 +2784,11 @@ function evaluate(records, scenario, options = {}) {
|
|
|
2766
2784
|
const { pass, evidence, message } = outcome;
|
|
2767
2785
|
const passes = (c) => evaluateRuleHits(rule, c).pass;
|
|
2768
2786
|
const scoped = !rule.tag && isScoped(rule);
|
|
2769
|
-
const
|
|
2770
|
-
|
|
2787
|
+
const failureRests = scoped && !pass && failureRestsOnProbableLink(ctx, passes, rule);
|
|
2788
|
+
const ownNote = outcome.note === "nestedNameOnly" ? void 0 : outcome.note;
|
|
2789
|
+
const note = ownNote ?? (pass && scoped && passRestsOnProbableLink(ctx, passes, rule) ? "serverSendProbableLink" : outcome.note);
|
|
2790
|
+
const countRests = kind === "must" && failureRests && !ownNote;
|
|
2791
|
+
add2(`${kind}: ${rule.description}`, pass, evidence, message, countRests ? "warn" : void 0, countRests ? "serverSendProbableLink" : note, scoped && (pass || failureRests));
|
|
2771
2792
|
}
|
|
2772
2793
|
builtInChecks(records, scenario, ctx, add2);
|
|
2773
2794
|
return results;
|
|
@@ -2783,6 +2804,37 @@ function ruleWindowStart(rule, ctx) {
|
|
|
2783
2804
|
}
|
|
2784
2805
|
return rule.from ? { at: step.startedAt, text: `from ${label}` } : { at: step.endedAt ?? step.startedAt, text: `after ${label}` };
|
|
2785
2806
|
}
|
|
2807
|
+
var MAX_SEARCHED_HITS = 10;
|
|
2808
|
+
var dependsOnWhichHits = (rule) => rule.count?.op === "=" || Boolean(rule.body || rule.hashesMatch);
|
|
2809
|
+
var isPlainExactCount = (rule) => rule.count?.op === "=" && !rule.body && !rule.hashesMatch;
|
|
2810
|
+
function placementsChange(ctx, rule, unlinked, probable, base2) {
|
|
2811
|
+
const byLink = scopedIds(rule, ctx);
|
|
2812
|
+
const byOwnTime = new Set(probable.filter((h) => scopedIds(rule, asBrowserHits(ctx, [h])).has(h.id)).map((h) => h.id));
|
|
2813
|
+
const reach = probable.filter((h) => byLink.has(h.id) || byOwnTime.has(h.id));
|
|
2814
|
+
if (unlinked.length + reach.length === 0) return false;
|
|
2815
|
+
const reachIds = new Set(reach.map((h) => h.id));
|
|
2816
|
+
const run = (placed, selected) => {
|
|
2817
|
+
const chosen = new Set(selected.map((h) => h.id));
|
|
2818
|
+
const moved = asBrowserHits(ctx, selected.filter((h) => !byLink.has(h.id)));
|
|
2819
|
+
const placedCtx = { ...moved, hits: moved.hits.filter((h) => chosen.has(h.id) || !reachIds.has(h.id)), anywhere: new Set(placed.map((h) => h.id)) };
|
|
2820
|
+
return evaluateRuleHits(rule, placedCtx).pass !== base2;
|
|
2821
|
+
};
|
|
2822
|
+
if (!dependsOnWhichHits(rule)) return run(unlinked, reach) || run([], []);
|
|
2823
|
+
const prefixes = isPlainExactCount(rule);
|
|
2824
|
+
if (!prefixes && unlinked.length + reach.length > MAX_SEARCHED_HITS) return true;
|
|
2825
|
+
if (prefixes) {
|
|
2826
|
+
for (let k = 0; k <= unlinked.length + reach.length; k++) {
|
|
2827
|
+
const u = Math.min(k, unlinked.length);
|
|
2828
|
+
if (run(unlinked.slice(0, u), reach.slice(0, k - u))) return true;
|
|
2829
|
+
}
|
|
2830
|
+
return false;
|
|
2831
|
+
}
|
|
2832
|
+
for (let u = 0; u < 2 ** unlinked.length; u++) {
|
|
2833
|
+
const placed = unlinked.filter((_, i) => u & 2 ** i);
|
|
2834
|
+
for (let code = 0; code < 2 ** reach.length; code++) if (run(placed, reach.filter((_, i) => code & 2 ** i))) return true;
|
|
2835
|
+
}
|
|
2836
|
+
return false;
|
|
2837
|
+
}
|
|
2786
2838
|
function evaluateRule(rule, ctx) {
|
|
2787
2839
|
const outcome = evaluateRuleHits(rule, ctx);
|
|
2788
2840
|
if (rule.cookie || rule.tag || !isScoped(rule)) return outcome;
|
|
@@ -2790,8 +2842,13 @@ function evaluateRule(rule, ctx) {
|
|
|
2790
2842
|
if (unjudged.length === 0) return outcome;
|
|
2791
2843
|
if (rule.kind === "mustNot") {
|
|
2792
2844
|
if (!outcome.pass) return outcome;
|
|
2793
|
-
} else
|
|
2794
|
-
|
|
2845
|
+
} else {
|
|
2846
|
+
let changes = placementsChange(ctx, rule, unjudged, [], outcome.pass);
|
|
2847
|
+
if (!changes) {
|
|
2848
|
+
const probable = probableHits(ctx, rule);
|
|
2849
|
+
changes = probable.length > 0 && !placementsChange(ctx, rule, [], probable, outcome.pass) && placementsChange(ctx, rule, unjudged, probable, outcome.pass);
|
|
2850
|
+
}
|
|
2851
|
+
if (!changes) return outcome;
|
|
2795
2852
|
}
|
|
2796
2853
|
return {
|
|
2797
2854
|
pass: false,
|
|
@@ -2811,23 +2868,25 @@ function asBrowserHits(ctx, hits) {
|
|
|
2811
2868
|
}
|
|
2812
2869
|
return { ...ctx, requests, index: judgeIndex(ctx.hits, requests) };
|
|
2813
2870
|
}
|
|
2814
|
-
function
|
|
2871
|
+
function probableHits(ctx, rule) {
|
|
2815
2872
|
const probable = ctx.hits.filter((h) => h.via?.confidence === "probable" && viaHitOf(h, ctx.index) !== void 0);
|
|
2816
|
-
return probable.
|
|
2873
|
+
return rule ? probable.filter((h) => matchesFilter(h, { ...rule.filter, consent: {} }, ctx)) : probable;
|
|
2817
2874
|
}
|
|
2818
|
-
function
|
|
2819
|
-
const probable = ctx
|
|
2875
|
+
function passRestsOnProbableLink(ctx, passes, rule) {
|
|
2876
|
+
const probable = probableHits(ctx, rule);
|
|
2877
|
+
if (probable.length === 0) return false;
|
|
2878
|
+
if (!rule) return !passes(asBrowserHits(ctx, probable));
|
|
2879
|
+
return placementsChange(ctx, rule, [], probable, true);
|
|
2880
|
+
}
|
|
2881
|
+
function failureRestsOnProbableLink(ctx, passes, rule) {
|
|
2882
|
+
const probable = probableHits(ctx, rule);
|
|
2820
2883
|
if (probable.length === 0) return false;
|
|
2821
2884
|
const ids = new Set(probable.map((h) => h.id));
|
|
2822
|
-
|
|
2885
|
+
const leftOut = () => passes({ ...ctx, hits: ctx.hits.filter((h) => !ids.has(h.id)) });
|
|
2886
|
+
if (!rule) return passes(asBrowserHits(ctx, probable)) || leftOut();
|
|
2887
|
+
return placementsChange(ctx, rule, [], probable, false);
|
|
2823
2888
|
}
|
|
2824
|
-
function
|
|
2825
|
-
if (rule.tag) {
|
|
2826
|
-
const window2 = ruleWindowStart(rule, ctx);
|
|
2827
|
-
if (window2 && "message" in window2) return window2;
|
|
2828
|
-
return evaluateTagRule(rule, { reports: ctx.tagReports, expected: ctx.expectedTags, window: window2 });
|
|
2829
|
-
}
|
|
2830
|
-
if (rule.cookie) return evaluateCookieRule(rule, rule.cookie, ctx);
|
|
2889
|
+
function scopedHits(rule, ctx) {
|
|
2831
2890
|
const anywhere = (h) => ctx.anywhere?.has(h.id) ?? false;
|
|
2832
2891
|
let hits = ctx.hits.filter((h) => matchesFilter(h, anywhere(h) ? { ...rule.filter, consent: {} } : rule.filter, ctx));
|
|
2833
2892
|
const total2 = hits.length;
|
|
@@ -2852,6 +2911,22 @@ function evaluateRuleHits(rule, ctx) {
|
|
|
2852
2911
|
});
|
|
2853
2912
|
narrowed.push(text2);
|
|
2854
2913
|
}
|
|
2914
|
+
return { hits, total: total2, narrowed };
|
|
2915
|
+
}
|
|
2916
|
+
var scopedIds = (rule, ctx) => {
|
|
2917
|
+
const scope = scopedHits(rule, ctx);
|
|
2918
|
+
return new Set("hits" in scope ? scope.hits.map((h) => h.id) : []);
|
|
2919
|
+
};
|
|
2920
|
+
function evaluateRuleHits(rule, ctx) {
|
|
2921
|
+
if (rule.tag) {
|
|
2922
|
+
const window2 = ruleWindowStart(rule, ctx);
|
|
2923
|
+
if (window2 && "message" in window2) return window2;
|
|
2924
|
+
return evaluateTagRule(rule, { reports: ctx.tagReports, expected: ctx.expectedTags, window: window2 });
|
|
2925
|
+
}
|
|
2926
|
+
if (rule.cookie) return evaluateCookieRule(rule, rule.cookie, ctx);
|
|
2927
|
+
const scope = scopedHits(rule, ctx);
|
|
2928
|
+
if ("message" in scope) return scope;
|
|
2929
|
+
const { hits, total: total2, narrowed } = scope;
|
|
2855
2930
|
const where2 = narrowed.length ? ` ${narrowed.join(", ")}` : "";
|
|
2856
2931
|
const vacuous = rule.before ? vacuousBeforeConsent(rule, ctx) : void 0;
|
|
2857
2932
|
if (rule.body) return evaluateBodyRule(rule, rule.body, hits, where2, total2, vacuous);
|
|
@@ -3103,7 +3178,7 @@ function describeSelector(filter) {
|
|
|
3103
3178
|
}
|
|
3104
3179
|
function vacuousBeforeConsent(rule, ctx) {
|
|
3105
3180
|
const vendors = rule.filter.vendor;
|
|
3106
|
-
if (!vendors || vendors.some((v) =>
|
|
3181
|
+
if (!vendors || vendors.some((v) => GOOGLE_VENDORS.has(v))) return void 0;
|
|
3107
3182
|
const first = ctx.epochs[0];
|
|
3108
3183
|
const state = first?.label === "undecided" ? first.state : void 0;
|
|
3109
3184
|
const blocked = consentFields.filter((f) => {
|
|
@@ -3232,7 +3307,7 @@ function effectiveConsentAt(hit, epochs, graceMs, index) {
|
|
|
3232
3307
|
if (t === void 0) return { analytics: "unknown", ads: "unknown", adUserData: "unknown", adPersonalization: "unknown" };
|
|
3233
3308
|
const source = index && viaHitOf(hit, index) || hit;
|
|
3234
3309
|
const base2 = epochForHit(epochs, t, graceMs)?.state;
|
|
3235
|
-
const own =
|
|
3310
|
+
const own = GOOGLE_VENDORS.has(source.vendor) && consentFields.some((f) => source.consent[f] !== "unknown");
|
|
3236
3311
|
const pick2 = (f) => {
|
|
3237
3312
|
if (own) return source.consent[f];
|
|
3238
3313
|
return base2 ? base2[f] : "unknown";
|
|
@@ -3267,7 +3342,7 @@ function inEpoch(hit, selector, ctx) {
|
|
|
3267
3342
|
if (isUnlinkedServerHit(hit, ctx.index)) return false;
|
|
3268
3343
|
if (selector === "undecided") return inUndecidedEpoch(hit, ctx);
|
|
3269
3344
|
if (selector.startsWith("label=")) return epochOf(hit, ctx)?.label === selector.slice("label=".length);
|
|
3270
|
-
if ((selector === "granted" || selector === "denied") && !
|
|
3345
|
+
if ((selector === "granted" || selector === "denied") && !GOOGLE_VENDORS.has(hit.vendor)) {
|
|
3271
3346
|
const epoch = epochOf(hit, ctx);
|
|
3272
3347
|
return (epoch?.outcome ?? epoch?.label) === selector;
|
|
3273
3348
|
}
|
|
@@ -3301,6 +3376,8 @@ function joinLabels(labels) {
|
|
|
3301
3376
|
}
|
|
3302
3377
|
var PLAIN_ADDRESS_PARAMS = /* @__PURE__ */ new Set(["user_data.city", "user_data.postal_code", "user_data.country"]);
|
|
3303
3378
|
var PLAIN_ADDRESS_VENDORS = /* @__PURE__ */ new Set(["sgtm"]);
|
|
3379
|
+
var HASH_REQUIRED_VENDORS = /* @__PURE__ */ new Set(["meta-capi"]);
|
|
3380
|
+
var HASH_MESSAGE_VENDOR_LABELS = { "meta-capi": "the Conversions API" };
|
|
3304
3381
|
var DIGEST_SHAPE = /^(?:[0-9a-f]{64}|[A-Za-z0-9+/_-]{43}=?)$/i;
|
|
3305
3382
|
function allForms(h) {
|
|
3306
3383
|
return [h.hex, h.base64, h.base64url];
|
|
@@ -3324,7 +3401,7 @@ function hashJudge(identity) {
|
|
|
3324
3401
|
if (known.has(value)) return "match";
|
|
3325
3402
|
const typed = value.trim().toLowerCase();
|
|
3326
3403
|
if (plain.has(typed) || accepted.some((v) => v.trim().toLowerCase() === typed)) return "unhashed";
|
|
3327
|
-
return PLAIN_ADDRESS_PARAMS.has(name) && vendor
|
|
3404
|
+
return PLAIN_ADDRESS_PARAMS.has(name) && HASH_REQUIRED_VENDORS.has(vendor) && !DIGEST_SHAPE.test(value) ? "plainRequired" : "wrong";
|
|
3328
3405
|
};
|
|
3329
3406
|
}
|
|
3330
3407
|
function capiMatchesIdentity(hit, field, identity) {
|
|
@@ -3348,12 +3425,13 @@ function checkHashes(hits, ctx) {
|
|
|
3348
3425
|
const withHash = [];
|
|
3349
3426
|
const wrong = [];
|
|
3350
3427
|
const unhashed = [];
|
|
3351
|
-
const
|
|
3428
|
+
const plainRequired = [];
|
|
3352
3429
|
const wrongFields = /* @__PURE__ */ new Set();
|
|
3353
3430
|
const wrongParams = /* @__PURE__ */ new Set();
|
|
3354
3431
|
const matchedFields = /* @__PURE__ */ new Set();
|
|
3355
3432
|
const unhashedFields = /* @__PURE__ */ new Set();
|
|
3356
|
-
const
|
|
3433
|
+
const plainRequiredFields = /* @__PURE__ */ new Set();
|
|
3434
|
+
const plainRequiredVendors = /* @__PURE__ */ new Set();
|
|
3357
3435
|
const plainAddressFields = /* @__PURE__ */ new Set();
|
|
3358
3436
|
const uncheckedFields = /* @__PURE__ */ new Set();
|
|
3359
3437
|
for (const hit of hits) {
|
|
@@ -3369,10 +3447,12 @@ function checkHashes(hits, ctx) {
|
|
|
3369
3447
|
if (!verdict) continue;
|
|
3370
3448
|
const label = fieldLabel(identityParamName(hit.vendor, name));
|
|
3371
3449
|
if (verdict === "plain") {
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3450
|
+
plainAddressFields.add(label);
|
|
3451
|
+
continue;
|
|
3452
|
+
}
|
|
3453
|
+
if (verdict === "plainRequired") {
|
|
3454
|
+
plainRequiredFields.add(label);
|
|
3455
|
+
plainHit = true;
|
|
3376
3456
|
continue;
|
|
3377
3457
|
}
|
|
3378
3458
|
seen = true;
|
|
@@ -3392,7 +3472,10 @@ function checkHashes(hits, ctx) {
|
|
|
3392
3472
|
if (seen) withHash.push(hit.id);
|
|
3393
3473
|
if (bad2) wrong.push(hit.id);
|
|
3394
3474
|
if (raw) unhashed.push(hit.id);
|
|
3395
|
-
if (plainHit)
|
|
3475
|
+
if (plainHit) {
|
|
3476
|
+
plainRequired.push(hit.id);
|
|
3477
|
+
plainRequiredVendors.add(HASH_MESSAGE_VENDOR_LABELS[hit.vendor] ?? hit.vendor);
|
|
3478
|
+
}
|
|
3396
3479
|
}
|
|
3397
3480
|
const several = hits.length > 1;
|
|
3398
3481
|
const they = several ? "they" : "it";
|
|
@@ -3405,12 +3488,13 @@ function checkHashes(hits, ctx) {
|
|
|
3405
3488
|
const message = `the hashed ${joinLabels(wrongFields)} values ${they} carried do not match the run identity${of(wrong.length)}. Not matching: ${[...wrongParams].join(", ")}.` + (matching.size ? ` Matching: ${joinLabels(matching)}.` : "");
|
|
3406
3489
|
return { pass: false, evidence: wrong, headline: UNMATCHED_HEADLINE, message };
|
|
3407
3490
|
}
|
|
3408
|
-
if (
|
|
3491
|
+
if (plainRequired.length) {
|
|
3492
|
+
const who = joinLabels(plainRequiredVendors).replace(/^the /, "The ");
|
|
3409
3493
|
return {
|
|
3410
3494
|
pass: false,
|
|
3411
|
-
evidence:
|
|
3495
|
+
evidence: plainRequired,
|
|
3412
3496
|
headline: UNMATCHED_HEADLINE,
|
|
3413
|
-
message: `${they} carried a plain ${joinLabels(
|
|
3497
|
+
message: `${they} carried a plain ${joinLabels(plainRequiredFields)}, not a hash${of(plainRequired.length)}. ${who} ${plainRequiredVendors.size > 1 ? "take" : "takes"} these hashed.`
|
|
3414
3498
|
};
|
|
3415
3499
|
}
|
|
3416
3500
|
if (!withHash.length && uncheckedFields.size) {
|
|
@@ -3835,74 +3919,77 @@ function bodyTexts(headers, body) {
|
|
|
3835
3919
|
}
|
|
3836
3920
|
return isBinaryText(body) ? [] : [{ text: body, where: "the body" }, ...leafTexts(body)];
|
|
3837
3921
|
}
|
|
3922
|
+
var JSON_ESCAPES = { n: "\n", r: "\r", t: " ", b: "\b", f: "\f", '"': '"', "\\": "\\", "/": "/" };
|
|
3923
|
+
function jsonUnescaped(text2) {
|
|
3924
|
+
return text2.replace(/\\(?:u([0-9a-f]{4})|(.))/gi, (m, hex, ch) => hex ? String.fromCharCode(parseInt(hex, 16)) : JSON_ESCAPES[ch] ?? m);
|
|
3925
|
+
}
|
|
3926
|
+
function percentLayers(text2) {
|
|
3927
|
+
const layers = [text2];
|
|
3928
|
+
for (let i = 0; i < 4; i++) {
|
|
3929
|
+
const next = text2.replace(/(?:%[0-9a-f]{2})+/gi, (run) => {
|
|
3930
|
+
try {
|
|
3931
|
+
return decodeURIComponent(run);
|
|
3932
|
+
} catch {
|
|
3933
|
+
return run;
|
|
3934
|
+
}
|
|
3935
|
+
});
|
|
3936
|
+
if (next === text2) break;
|
|
3937
|
+
layers.push(text2 = next);
|
|
3938
|
+
}
|
|
3939
|
+
return layers;
|
|
3940
|
+
}
|
|
3941
|
+
function bodyForms(raw) {
|
|
3942
|
+
const stripped = raw.replace(/\[\]|%5B%5D/gi, "");
|
|
3943
|
+
const textForms = new Set(percentLayers(stripped).flatMap((layer) => [layer, jsonUnescaped(layer)]));
|
|
3944
|
+
const decoded = [...textForms].flatMap((form) => readings(form)).filter((form) => !textForms.has(form));
|
|
3945
|
+
return { textForms, decoded };
|
|
3946
|
+
}
|
|
3838
3947
|
function isEdgeShift(a, b, bodies) {
|
|
3839
3948
|
const [short, long] = a.length <= b.length ? [a, b] : [b, a];
|
|
3840
3949
|
if (!long.includes(short)) return false;
|
|
3841
3950
|
let sawLong = false;
|
|
3842
|
-
const ok = bodies.every(
|
|
3843
|
-
|
|
3844
|
-
if (
|
|
3845
|
-
|
|
3951
|
+
const ok = bodies.every(({ textForms, decoded }) => {
|
|
3952
|
+
return [...textForms, ...decoded].every((text2) => {
|
|
3953
|
+
if (text2.includes(long)) {
|
|
3954
|
+
if (textForms.has(text2)) sawLong = true;
|
|
3955
|
+
} else if (textForms.has(text2)) return true;
|
|
3846
3956
|
const covered = [];
|
|
3847
3957
|
for (let i = text2.indexOf(long); i >= 0; i = text2.indexOf(long, i + 1)) covered.push([i, i + long.length]);
|
|
3848
3958
|
for (let i = text2.indexOf(short); i >= 0; i = text2.indexOf(short, i + 1)) {
|
|
3849
3959
|
if (!covered.some(([from, to]) => i >= from && i + short.length <= to)) return false;
|
|
3850
3960
|
}
|
|
3851
3961
|
return true;
|
|
3852
|
-
})
|
|
3853
|
-
);
|
|
3854
|
-
return ok && sawLong;
|
|
3855
|
-
}
|
|
3856
|
-
var JSON_ESCAPES = { n: "\n", r: "\r", t: " ", b: "\b", f: "\f", '"': '"', "\\": "\\", "/": "/" };
|
|
3857
|
-
function percentDecoded(text2) {
|
|
3858
|
-
return text2.replace(/(?:%[0-9a-f]{2})+/gi, (run) => {
|
|
3859
|
-
try {
|
|
3860
|
-
return decodeURIComponent(run);
|
|
3861
|
-
} catch {
|
|
3862
|
-
return run;
|
|
3863
|
-
}
|
|
3864
|
-
});
|
|
3865
|
-
}
|
|
3866
|
-
function base64InPlace(text2) {
|
|
3867
|
-
return text2.replace(/[A-Za-z0-9+/_-]{12,}={0,2}/g, (token) => {
|
|
3868
|
-
const decoded = Buffer.from(token, "base64").toString("utf8");
|
|
3869
|
-
return decoded.includes("\uFFFD") ? token : decoded;
|
|
3962
|
+
});
|
|
3870
3963
|
});
|
|
3871
|
-
|
|
3872
|
-
function readingForms(text2) {
|
|
3873
|
-
const forms = /* @__PURE__ */ new Set([text2]);
|
|
3874
|
-
let layer = text2;
|
|
3875
|
-
for (let i = 0; i < 4; i++) {
|
|
3876
|
-
const next = percentDecoded(layer);
|
|
3877
|
-
if (next === layer) break;
|
|
3878
|
-
forms.add(layer = next);
|
|
3879
|
-
}
|
|
3880
|
-
for (const form of [...forms]) {
|
|
3881
|
-
forms.add(form.replace(/\\(?:u([0-9a-f]{4})|(.))/gi, (m, hex, ch) => hex ? String.fromCharCode(parseInt(hex, 16)) : JSON_ESCAPES[ch] ?? m));
|
|
3882
|
-
}
|
|
3883
|
-
for (const form of [...forms]) forms.add(base64InPlace(form));
|
|
3884
|
-
return [...forms];
|
|
3964
|
+
return ok && sawLong;
|
|
3885
3965
|
}
|
|
3886
3966
|
function mergeEdgeReadings(found, bodies) {
|
|
3887
3967
|
const best = (f) => Math.min(...f.where.values());
|
|
3888
|
-
const
|
|
3968
|
+
const valueOf3 = (key, kind) => key.slice(kind.length + 1);
|
|
3889
3969
|
const fields2 = [...found].filter(([, f]) => best(f) < 2);
|
|
3970
|
+
let forms;
|
|
3890
3971
|
for (const [key, f] of [...found]) {
|
|
3891
3972
|
if (best(f) < 2 || [...f.where.keys()].some((w) => w !== "the body")) continue;
|
|
3892
|
-
const value =
|
|
3893
|
-
const twin = fields2.find(([k, other]) => other.kind === f.kind && isEdgeShift(
|
|
3973
|
+
const value = valueOf3(key, f.kind);
|
|
3974
|
+
const twin = fields2.find(([k, other]) => other.kind === f.kind && isEdgeShift(valueOf3(k, other.kind), value, forms ??= bodies.map(bodyForms)));
|
|
3894
3975
|
if (!twin) continue;
|
|
3895
3976
|
for (const [w, tier] of f.where) twin[1].where.set(w, Math.min(tier, twin[1].where.get(w) ?? tier));
|
|
3896
3977
|
found.delete(key);
|
|
3897
3978
|
}
|
|
3898
3979
|
}
|
|
3899
|
-
function findForeignData(requests, hits, identity) {
|
|
3980
|
+
function findForeignData(requests, hits, identity, dataLayerEvents = []) {
|
|
3900
3981
|
const byRequest = /* @__PURE__ */ new Map();
|
|
3901
3982
|
const slot = (key, stepId) => {
|
|
3902
3983
|
let entry = byRequest.get(key);
|
|
3903
3984
|
if (!entry) byRequest.set(key, entry = { texts: [], hitIds: [], stepId });
|
|
3904
3985
|
return entry;
|
|
3905
3986
|
};
|
|
3987
|
+
for (const event of dataLayerEvents) {
|
|
3988
|
+
const entry = slot(event.id, event.stepId);
|
|
3989
|
+
entry.push = true;
|
|
3990
|
+
const body = JSON.stringify(event.args);
|
|
3991
|
+
entry.texts.push({ text: body, where: "the body" }, ...leafTexts(body));
|
|
3992
|
+
}
|
|
3906
3993
|
const hitRequests = new Set(hits.map((h) => h.requestId));
|
|
3907
3994
|
for (const request of requests) {
|
|
3908
3995
|
if (request.resourceType === "script" && isLibraryLoadPath(pathOf(request.url))) continue;
|
|
@@ -3917,15 +4004,15 @@ function findForeignData(requests, hits, identity) {
|
|
|
3917
4004
|
entry.hitIds.push(hit.id);
|
|
3918
4005
|
for (const [key, value] of Object.entries(hit.params)) entry.texts.push({ text: `${key}=${value}`, where: guardFieldName(key) });
|
|
3919
4006
|
}
|
|
3920
|
-
const
|
|
3921
|
-
|
|
3922
|
-
);
|
|
4007
|
+
const stableFrom = (entries) => findStableHashes([...entries].flatMap(([requestId, entry]) => entry.texts.map(({ text: text2 }) => ({ requestId, text: text2 }))));
|
|
4008
|
+
const requestStable = stableFrom([...byRequest].filter(([, entry]) => !entry.push));
|
|
4009
|
+
const pushStable = stableFrom(byRequest);
|
|
3923
4010
|
const out = [];
|
|
3924
4011
|
for (const [requestId, entry] of byRequest) {
|
|
3925
4012
|
const found = /* @__PURE__ */ new Map();
|
|
3926
4013
|
for (const { text: text2, where: where2, leaf, name } of entry.texts) {
|
|
3927
4014
|
const tier = where2 === "the URL" || where2 === "the body" ? 2 : leaf ? 1 : 0;
|
|
3928
|
-
for (const m of scan(text2, identity, { stableHashes })) {
|
|
4015
|
+
for (const m of scan(text2, identity, { stableHashes: entry.push ? pushStable : requestStable })) {
|
|
3929
4016
|
if (name && m.kind === "phone") continue;
|
|
3930
4017
|
const key = `${m.kind}:${m.value}`;
|
|
3931
4018
|
const seen = found.get(key) ?? { kind: m.kind, where: /* @__PURE__ */ new Map() };
|
|
@@ -3944,107 +4031,21 @@ function findForeignData(requests, hits, identity) {
|
|
|
3944
4031
|
const best = Math.min(...where2.values());
|
|
3945
4032
|
for (const [w, tier] of where2) if (tier === best) places.add(w);
|
|
3946
4033
|
}
|
|
3947
|
-
const shown2 = [...places].sort();
|
|
4034
|
+
const shown2 = [...places].map((w) => entry.push && w === "the body" ? "the push" : w).sort();
|
|
3948
4035
|
const in_ = shown2.length > 5 ? `${shown2.slice(0, 5).join(", ")} and ${shown2.length - 5} more` : shown2.join(", ");
|
|
3949
4036
|
const step = entry.stepId ? ` in step ${entry.stepId}` : "";
|
|
3950
4037
|
out.push({
|
|
4038
|
+
source: entry.push ? "push" : "request",
|
|
3951
4039
|
requestId,
|
|
3952
|
-
detail:
|
|
4040
|
+
detail: `${entry.push ? "dataLayer push" : "request"} ${requestId}${step} carries ${found.size} ${kinds} value(s) that are not from the run identity, in ${in_}`,
|
|
3953
4041
|
evidence: [requestId, ...entry.hitIds, ...entry.stepId ? [entry.stepId] : []]
|
|
3954
4042
|
});
|
|
3955
4043
|
}
|
|
3956
4044
|
return out;
|
|
3957
4045
|
}
|
|
3958
4046
|
|
|
3959
|
-
// packages/expect/src/event-map.ts
|
|
3960
|
-
var EVENT_NAME = /^[A-Za-z0-9_.: -]{1,200}$/;
|
|
3961
|
-
var PATH_NAME = /^[A-Za-z0-9_.()[\]*-]{1,200}$/;
|
|
3962
|
-
var ROOT = ".";
|
|
3963
|
-
var TOP_KEYS2 = /* @__PURE__ */ new Set(["events", "paths"]);
|
|
3964
|
-
function isRecord(value) {
|
|
3965
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3966
|
-
}
|
|
3967
|
-
function parseEventMap(text2, file) {
|
|
3968
|
-
let json;
|
|
3969
|
-
try {
|
|
3970
|
-
json = JSON.parse(text2);
|
|
3971
|
-
} catch {
|
|
3972
|
-
throw new Error(`${file}: the event map is not valid JSON.`);
|
|
3973
|
-
}
|
|
3974
|
-
if (!isRecord(json)) throw new Error(`${file}: the event map must be a JSON object.`);
|
|
3975
|
-
for (const key of Object.keys(json)) if (!TOP_KEYS2.has(key)) throw new Error(`${file}: unknown key "${key}". Use "events" and "paths".`);
|
|
3976
|
-
const map = { events: /* @__PURE__ */ Object.create(null), paths: /* @__PURE__ */ Object.create(null) };
|
|
3977
|
-
const events = json.events ?? {};
|
|
3978
|
-
if (!isRecord(events)) throw new Error(`${file}: "events" must be an object.`);
|
|
3979
|
-
for (const [position, [from, to]] of Object.entries(events).map((e, i) => [i + 1, e])) {
|
|
3980
|
-
if (!EVENT_NAME.test(from)) throw new Error(`${file}: "events" key ${position} is not an event name.`);
|
|
3981
|
-
if (typeof to !== "string" || !EVENT_NAME.test(to)) throw new Error(`${file}: events.${from} must be an event name.`);
|
|
3982
|
-
map.events[from] = to;
|
|
3983
|
-
}
|
|
3984
|
-
const paths = json.paths ?? {};
|
|
3985
|
-
if (!isRecord(paths)) throw new Error(`${file}: "paths" must be an object.`);
|
|
3986
|
-
for (const [position, [event, renames]] of Object.entries(paths).map((e, i) => [i + 1, e])) {
|
|
3987
|
-
if (!EVENT_NAME.test(event)) throw new Error(`${file}: "paths" key ${position} is not an event name.`);
|
|
3988
|
-
if (!isRecord(renames)) throw new Error(`${file}: paths.${event} must be an object.`);
|
|
3989
|
-
const out = /* @__PURE__ */ Object.create(null);
|
|
3990
|
-
if (Object.hasOwn(renames, ROOT) && Object.keys(renames).length > 1) throw new Error(`${file}: paths.${event} with the "${ROOT}" source key takes no other key.`);
|
|
3991
|
-
for (const [from, to] of Object.entries(renames)) {
|
|
3992
|
-
if (!PATH_NAME.test(from)) throw new Error(`${file}: paths.${event} has a key that is not a key path.`);
|
|
3993
|
-
if (typeof to !== "string" || to !== ROOT && !PATH_NAME.test(to)) throw new Error(`${file}: paths.${event}.${from} must be a key path.`);
|
|
3994
|
-
if (from === ROOT && to === ROOT) throw new Error(`${file}: paths.${event}.${from} must name a key path to move the root under.`);
|
|
3995
|
-
out[from] = to;
|
|
3996
|
-
}
|
|
3997
|
-
map.paths[event] = out;
|
|
3998
|
-
}
|
|
3999
|
-
return map;
|
|
4000
|
-
}
|
|
4001
|
-
function builtInEventName(event) {
|
|
4002
|
-
return /^(consent|gtag) /.test(event) ? event : ga4EventName(event);
|
|
4003
|
-
}
|
|
4004
|
-
function renamePath(path, renames) {
|
|
4005
|
-
const bySpecificity = Object.entries(renames).sort(([x], [y]) => y.length - x.length);
|
|
4006
|
-
for (const [from, to] of bySpecificity) {
|
|
4007
|
-
if (path === from) return to === ROOT ? void 0 : to;
|
|
4008
|
-
if (path.startsWith(`${from}.`) || path.startsWith(`${from}[`)) {
|
|
4009
|
-
const rest = path.slice(from.length);
|
|
4010
|
-
return to === ROOT ? rest.replace(/^\./, "") : `${to}${rest}`;
|
|
4011
|
-
}
|
|
4012
|
-
}
|
|
4013
|
-
return path;
|
|
4014
|
-
}
|
|
4015
|
-
function mapPushGroups(groups, rename2, paths = {}, pathKeys = (recorded, final) => [final, recorded]) {
|
|
4016
|
-
return groups.map((g) => {
|
|
4017
|
-
const event = rename2(g.event);
|
|
4018
|
-
const key = pathKeys(g.event, event).find((k) => Object.hasOwn(paths, k));
|
|
4019
|
-
const renames = key === void 0 ? void 0 : paths[key];
|
|
4020
|
-
if (!renames) return { ...g, event };
|
|
4021
|
-
const under = Object.hasOwn(renames, ROOT) ? renames[ROOT] : void 0;
|
|
4022
|
-
if (under !== void 0) {
|
|
4023
|
-
const moved = g.paths.map((p) => ({ ...p, path: p.path.startsWith("[") ? `${under}${p.path}` : `${under}.${p.path}` }));
|
|
4024
|
-
return { ...g, event, ...g.kind === void 0 ? {} : { kind: "object" }, paths: g.paths.some((p) => p.path === "event") ? g.paths : [{ path: "event", types: ["string"] }, ...moved] };
|
|
4025
|
-
}
|
|
4026
|
-
const toGtag = Object.values(renames).includes(ROOT);
|
|
4027
|
-
const mapped = [];
|
|
4028
|
-
for (const p of g.paths) {
|
|
4029
|
-
if (toGtag && p.path === "event") continue;
|
|
4030
|
-
const path = renamePath(p.path, renames);
|
|
4031
|
-
if (path !== void 0) mapped.push({ ...p, path });
|
|
4032
|
-
}
|
|
4033
|
-
return { ...g, event, ...toGtag && g.kind !== void 0 ? { kind: "gtag" } : {}, paths: mapped };
|
|
4034
|
-
});
|
|
4035
|
-
}
|
|
4036
|
-
function normalizePushGroups(groups, userMap) {
|
|
4037
|
-
const user = userMap?.events;
|
|
4038
|
-
const userName = (event) => {
|
|
4039
|
-
const named = builtInEventName(event);
|
|
4040
|
-
return user !== void 0 && Object.hasOwn(user, event) ? user[event] : user !== void 0 && Object.hasOwn(user, named) ? user[named] : named;
|
|
4041
|
-
};
|
|
4042
|
-
const rename2 = (event) => builtInEventName(userName(event));
|
|
4043
|
-
const pathKeys = (recorded, final) => [final, recorded, userName(recorded)];
|
|
4044
|
-
return mapPushGroups(groups, rename2, userMap?.paths, pathKeys);
|
|
4045
|
-
}
|
|
4046
|
-
|
|
4047
4047
|
// packages/expect/src/push-shape.ts
|
|
4048
|
+
var PUSH_FRAME_KINDS = ["main", "embedded", "unknown"];
|
|
4048
4049
|
var NO_EVENT = "(no event)";
|
|
4049
4050
|
var NO_STEP = "(no step)";
|
|
4050
4051
|
var EVENT_CHARS = /^[A-Za-z0-9_.:-]+$/;
|
|
@@ -4074,7 +4075,7 @@ function walk(value, path, depth, out) {
|
|
|
4074
4075
|
walk(child, key === "[*]" ? `${path}[*]` : path === "" ? safeKey(key) : `${path}.${safeKey(key)}`, depth + 1, out);
|
|
4075
4076
|
}
|
|
4076
4077
|
}
|
|
4077
|
-
function
|
|
4078
|
+
function startsWithString(args) {
|
|
4078
4079
|
return typeof args[0] === "string";
|
|
4079
4080
|
}
|
|
4080
4081
|
function argumentsLike(args) {
|
|
@@ -4086,14 +4087,18 @@ function argumentsLike(args) {
|
|
|
4086
4087
|
return typeof list3[0] === "string" ? list3 : void 0;
|
|
4087
4088
|
}
|
|
4088
4089
|
function commandOf(e) {
|
|
4089
|
-
if (
|
|
4090
|
+
if (startsWithString(e.args)) return { list: e.args, fromObject: false };
|
|
4090
4091
|
const list3 = argumentsLike(e.args);
|
|
4091
|
-
return list3 !== void 0 &&
|
|
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]);
|
|
4092
4097
|
}
|
|
4093
4098
|
function commandLabel(command) {
|
|
4094
4099
|
const [name, second] = command.list;
|
|
4095
4100
|
if (command.fromObject && typeof second === "string") {
|
|
4096
|
-
if (
|
|
4101
|
+
if (isObjectConsent(command)) return `consent ${second}`;
|
|
4097
4102
|
if (name === "event") return safeName(second);
|
|
4098
4103
|
}
|
|
4099
4104
|
return GTAG_COMMANDS.has(name) ? `gtag ${name}` : GTAG_OTHER;
|
|
@@ -4103,12 +4108,16 @@ function eventLabel(e, command) {
|
|
|
4103
4108
|
if (e.event !== null) return safeName(e.event);
|
|
4104
4109
|
return command === void 0 ? NO_EVENT : commandLabel(command);
|
|
4105
4110
|
}
|
|
4111
|
+
function labelKind(label) {
|
|
4112
|
+
return label.startsWith("consent ") ? "consent" : label.startsWith("gtag ") ? "gtag" : "event";
|
|
4113
|
+
}
|
|
4106
4114
|
function frameKind(e) {
|
|
4107
4115
|
return e.frame === void 0 ? "unknown" : e.frame.main ? "main" : "embedded";
|
|
4108
4116
|
}
|
|
4109
4117
|
function collectPaths(e, command, into) {
|
|
4110
4118
|
if (e.event?.startsWith("gtm.")) return;
|
|
4111
|
-
if (
|
|
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)) {
|
|
4112
4121
|
const signals = (command?.fromObject ? command.list : e.args)[2];
|
|
4113
4122
|
if (typeof signals === "object" && signals !== null) for (const [name, value] of Object.entries(signals)) walk(value, safeKey(name), 0, into);
|
|
4114
4123
|
return;
|
|
@@ -4147,6 +4156,168 @@ function pushShapes(records) {
|
|
|
4147
4156
|
};
|
|
4148
4157
|
}
|
|
4149
4158
|
|
|
4159
|
+
// packages/expect/src/event-map.ts
|
|
4160
|
+
var EVENT_NAME = /^[A-Za-z0-9_.: -]{1,200}$/;
|
|
4161
|
+
var PATH_NAME = /^[A-Za-z0-9_.()[\]*-]{1,200}$/;
|
|
4162
|
+
var ROOT = ".";
|
|
4163
|
+
var TOP_KEYS2 = /* @__PURE__ */ new Set(["events", "paths"]);
|
|
4164
|
+
function isRecord(value) {
|
|
4165
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4166
|
+
}
|
|
4167
|
+
function objectEntries(text2, from) {
|
|
4168
|
+
let i = from;
|
|
4169
|
+
const skipSpace = () => {
|
|
4170
|
+
while (i < text2.length && /\s/.test(text2[i])) i++;
|
|
4171
|
+
};
|
|
4172
|
+
const readString = () => {
|
|
4173
|
+
const begin = i++;
|
|
4174
|
+
while (i < text2.length && text2[i] !== '"') i += text2[i] === "\\" ? 2 : 1;
|
|
4175
|
+
i++;
|
|
4176
|
+
return JSON.parse(text2.slice(begin, i));
|
|
4177
|
+
};
|
|
4178
|
+
const skipValue = () => {
|
|
4179
|
+
skipSpace();
|
|
4180
|
+
const c = text2[i];
|
|
4181
|
+
if (c === '"') {
|
|
4182
|
+
readString();
|
|
4183
|
+
} else if (c === "{" || c === "[") {
|
|
4184
|
+
const close = c === "{" ? "}" : "]";
|
|
4185
|
+
i++;
|
|
4186
|
+
skipSpace();
|
|
4187
|
+
while (text2[i] !== close) {
|
|
4188
|
+
if (c === "{") {
|
|
4189
|
+
readString();
|
|
4190
|
+
skipSpace();
|
|
4191
|
+
i++;
|
|
4192
|
+
}
|
|
4193
|
+
skipValue();
|
|
4194
|
+
skipSpace();
|
|
4195
|
+
if (text2[i] === ",") i++;
|
|
4196
|
+
skipSpace();
|
|
4197
|
+
}
|
|
4198
|
+
i++;
|
|
4199
|
+
} else {
|
|
4200
|
+
while (i < text2.length && !/[\s,}\]]/.test(text2[i])) i++;
|
|
4201
|
+
}
|
|
4202
|
+
};
|
|
4203
|
+
const entries = [];
|
|
4204
|
+
i++;
|
|
4205
|
+
skipSpace();
|
|
4206
|
+
while (text2[i] !== "}") {
|
|
4207
|
+
const key = readString();
|
|
4208
|
+
skipSpace();
|
|
4209
|
+
i++;
|
|
4210
|
+
skipSpace();
|
|
4211
|
+
const start = i;
|
|
4212
|
+
skipValue();
|
|
4213
|
+
entries.push({ key, start, end: i });
|
|
4214
|
+
skipSpace();
|
|
4215
|
+
if (text2[i] === ",") i++;
|
|
4216
|
+
skipSpace();
|
|
4217
|
+
}
|
|
4218
|
+
return entries;
|
|
4219
|
+
}
|
|
4220
|
+
var valueOf = (text2, e) => JSON.parse(text2.slice(e.start, e.end));
|
|
4221
|
+
function parseEventMap(text2, file) {
|
|
4222
|
+
let json;
|
|
4223
|
+
try {
|
|
4224
|
+
json = JSON.parse(text2);
|
|
4225
|
+
} catch {
|
|
4226
|
+
throw new Error(`${file}: the event map is not valid JSON.`);
|
|
4227
|
+
}
|
|
4228
|
+
if (!isRecord(json)) throw new Error(`${file}: the event map must be a JSON object.`);
|
|
4229
|
+
const top = objectEntries(text2, text2.indexOf("{"));
|
|
4230
|
+
top.forEach((e, i) => {
|
|
4231
|
+
if (!TOP_KEYS2.has(e.key)) throw new Error(`${file}: top-level key ${i + 1} is not "events" or "paths".`);
|
|
4232
|
+
});
|
|
4233
|
+
const map = { events: /* @__PURE__ */ Object.create(null), paths: /* @__PURE__ */ Object.create(null) };
|
|
4234
|
+
const events = json.events ?? {};
|
|
4235
|
+
if (!isRecord(events)) throw new Error(`${file}: "events" must be an object.`);
|
|
4236
|
+
const eventsEntry = !isRecord(json.events) ? void 0 : top.findLast((e) => e.key === "events");
|
|
4237
|
+
(eventsEntry === void 0 ? [] : objectEntries(text2, eventsEntry.start)).forEach((e, i) => {
|
|
4238
|
+
const to = valueOf(text2, e);
|
|
4239
|
+
if (!EVENT_NAME.test(e.key)) throw new Error(`${file}: "events" key ${i + 1} is not an event name.`);
|
|
4240
|
+
if (typeof to !== "string" || !EVENT_NAME.test(to)) throw new Error(`${file}: "events" key ${i + 1} must map to an event name.`);
|
|
4241
|
+
map.events[e.key] = to;
|
|
4242
|
+
});
|
|
4243
|
+
const paths = json.paths ?? {};
|
|
4244
|
+
if (!isRecord(paths)) throw new Error(`${file}: "paths" must be an object.`);
|
|
4245
|
+
const pathsEntry = !isRecord(json.paths) ? void 0 : top.findLast((e) => e.key === "paths");
|
|
4246
|
+
(pathsEntry === void 0 ? [] : objectEntries(text2, pathsEntry.start)).forEach((e, i) => {
|
|
4247
|
+
const at = `"paths" key ${i + 1}`;
|
|
4248
|
+
const renames = valueOf(text2, e);
|
|
4249
|
+
if (!EVENT_NAME.test(e.key)) throw new Error(`${file}: ${at} is not an event name.`);
|
|
4250
|
+
if (!isRecord(renames)) throw new Error(`${file}: ${at} must be an object.`);
|
|
4251
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
4252
|
+
const inner = objectEntries(text2, e.start);
|
|
4253
|
+
if (inner.some((p) => p.key === ROOT) && inner.length > 1) throw new Error(`${file}: ${at} with the "${ROOT}" source key takes no other key.`);
|
|
4254
|
+
inner.forEach((p, j) => {
|
|
4255
|
+
const to = valueOf(text2, p);
|
|
4256
|
+
if (!PATH_NAME.test(p.key)) throw new Error(`${file}: ${at}, key ${j + 1} is not a key path.`);
|
|
4257
|
+
if (typeof to !== "string" || to !== ROOT && !PATH_NAME.test(to)) throw new Error(`${file}: ${at}, key ${j + 1} must map to a key path.`);
|
|
4258
|
+
if (p.key === ROOT && to === ROOT) throw new Error(`${file}: ${at}, key ${j + 1} must name a key path to move the root under.`);
|
|
4259
|
+
out[p.key] = to;
|
|
4260
|
+
});
|
|
4261
|
+
map.paths[e.key] = out;
|
|
4262
|
+
});
|
|
4263
|
+
return map;
|
|
4264
|
+
}
|
|
4265
|
+
function builtInEventName(event) {
|
|
4266
|
+
return labelKind(event) === "event" ? ga4EventName(event) : event;
|
|
4267
|
+
}
|
|
4268
|
+
function renamePath(path, renames) {
|
|
4269
|
+
const bySpecificity = Object.entries(renames).sort(([x], [y]) => y.length - x.length);
|
|
4270
|
+
for (const [from, to] of bySpecificity) {
|
|
4271
|
+
if (path === from) return to === ROOT ? void 0 : to;
|
|
4272
|
+
if (path.startsWith(`${from}.`) || path.startsWith(`${from}[`)) {
|
|
4273
|
+
const rest = path.slice(from.length);
|
|
4274
|
+
return to === ROOT ? rest.replace(/^\./, "") : `${to}${rest}`;
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
return path;
|
|
4278
|
+
}
|
|
4279
|
+
function mapPushGroups(groups, rename2, paths, pathKeys) {
|
|
4280
|
+
return groups.map((g) => {
|
|
4281
|
+
const event = rename2(g.event);
|
|
4282
|
+
const key = pathKeys(g.event, event).find((k) => paths !== void 0 && Object.hasOwn(paths, k));
|
|
4283
|
+
const renames = key === void 0 ? void 0 : paths?.[key];
|
|
4284
|
+
if (!renames) return { ...g, event };
|
|
4285
|
+
const under = Object.hasOwn(renames, ROOT) ? renames[ROOT] : void 0;
|
|
4286
|
+
if (under !== void 0) {
|
|
4287
|
+
const moved = g.paths.map((p) => ({ ...p, path: p.path.startsWith("[") ? `${under}${p.path}` : `${under}.${p.path}` }));
|
|
4288
|
+
return { ...g, event, ...g.kind === void 0 ? {} : { kind: "object" }, paths: g.paths.some((p) => p.path === "event") ? g.paths : [{ path: "event", types: ["string"] }, ...moved] };
|
|
4289
|
+
}
|
|
4290
|
+
const toGtag = Object.values(renames).includes(ROOT);
|
|
4291
|
+
const mapped = [];
|
|
4292
|
+
for (const p of g.paths) {
|
|
4293
|
+
if (toGtag && p.path === "event") continue;
|
|
4294
|
+
const path = renamePath(p.path, renames);
|
|
4295
|
+
if (path !== void 0) mapped.push({ ...p, path });
|
|
4296
|
+
}
|
|
4297
|
+
return { ...g, event, ...toGtag && g.kind !== void 0 ? { kind: "gtag" } : {}, paths: mapped };
|
|
4298
|
+
});
|
|
4299
|
+
}
|
|
4300
|
+
function mappedEventName(event, userMap) {
|
|
4301
|
+
return builtInEventName(userEventName(event, userMap?.events));
|
|
4302
|
+
}
|
|
4303
|
+
function userEventName(event, user) {
|
|
4304
|
+
const named = builtInEventName(event);
|
|
4305
|
+
return user !== void 0 && Object.hasOwn(user, event) ? user[event] : user !== void 0 && Object.hasOwn(user, named) ? user[named] : named;
|
|
4306
|
+
}
|
|
4307
|
+
function pathKeysFor(userMap, own, fallback) {
|
|
4308
|
+
const targets = new Set(Object.values(userMap?.events ?? {}));
|
|
4309
|
+
return (recorded, final) => [...own(recorded, final), ...fallback(recorded).filter((k) => !targets.has(k))];
|
|
4310
|
+
}
|
|
4311
|
+
function normalizePushGroups(groups, userMap) {
|
|
4312
|
+
const user = userMap?.events;
|
|
4313
|
+
const pathKeys = pathKeysFor(userMap, (recorded, final) => [final, userEventName(recorded, user)], (recorded) => [recorded]);
|
|
4314
|
+
return mapPushGroups(groups, (event) => mappedEventName(event, userMap), userMap?.paths, pathKeys);
|
|
4315
|
+
}
|
|
4316
|
+
function keepPushGroups(groups, userMap) {
|
|
4317
|
+
const pathKeys = pathKeysFor(userMap, (recorded) => [recorded], (recorded) => [builtInEventName(recorded)]);
|
|
4318
|
+
return mapPushGroups(groups, (event) => event, userMap?.paths, pathKeys);
|
|
4319
|
+
}
|
|
4320
|
+
|
|
4150
4321
|
// packages/expect/src/diff.ts
|
|
4151
4322
|
var NO_EPOCH = "none";
|
|
4152
4323
|
var SERVER_UNLINKED = "server";
|
|
@@ -4189,10 +4360,21 @@ function diffRuns(a, b, options = {}) {
|
|
|
4189
4360
|
const pushesB = pushGroups(b);
|
|
4190
4361
|
if (pushesA.length > 0 || pushesB.length > 0) {
|
|
4191
4362
|
result.dataLayer = diffPushes(pushesA, pushesB, { acrossFrames: options.acrossFrames, epochOrder: epochOrder(b), eventMap: options.eventMap });
|
|
4192
|
-
result.warnings.push(...result.dataLayer.kindChanged.map(
|
|
4363
|
+
result.warnings.push(...result.dataLayer.kindChanged.map(kindChangeWarning));
|
|
4193
4364
|
}
|
|
4194
4365
|
return result;
|
|
4195
4366
|
}
|
|
4367
|
+
function kindChangeWarning(k) {
|
|
4368
|
+
return `push kind changed: ${k.event}${k.renamedFrom === void 0 ? "" : ` (renamed from ${k.renamedFrom})`}`;
|
|
4369
|
+
}
|
|
4370
|
+
function kindsMerged(a, b) {
|
|
4371
|
+
return [...a, ...b].some((g) => g.kind === void 0);
|
|
4372
|
+
}
|
|
4373
|
+
function neighbourEpochs(order, from, to) {
|
|
4374
|
+
const i = order.indexOf(from);
|
|
4375
|
+
const j = order.indexOf(to);
|
|
4376
|
+
return i >= 0 && j >= 0 && Math.abs(i - j) === 1 && order.filter((l) => l === from || l === to).length === 2;
|
|
4377
|
+
}
|
|
4196
4378
|
function epochOrder(run) {
|
|
4197
4379
|
return [...run.consentEpochs].sort((x, y) => x.startT - y.startT).map((e) => e.label);
|
|
4198
4380
|
}
|
|
@@ -4227,31 +4409,85 @@ function pushNodes(groups, acrossFrames, mergeKinds) {
|
|
|
4227
4409
|
const frame = acrossFrames ? "any" : g.frame;
|
|
4228
4410
|
const kind = mergeKinds ? void 0 : g.kind;
|
|
4229
4411
|
const id = JSON.stringify([g.epoch, g.event, kind ?? null, frame]);
|
|
4230
|
-
const node = nodes.get(id) ?? { epoch: g.epoch, event: g.event, ...kind === void 0 ? {} : { kind }, frame, frames: [], types: /* @__PURE__ */ new Map() };
|
|
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 } };
|
|
4231
4413
|
if (!node.frames.includes(g.frame)) node.frames.push(g.frame);
|
|
4232
4414
|
for (const p of g.paths) node.types.set(p.path, [.../* @__PURE__ */ new Set([...node.types.get(p.path) ?? [], ...p.types])].sort());
|
|
4233
4415
|
nodes.set(id, node);
|
|
4234
4416
|
}
|
|
4235
4417
|
return nodes;
|
|
4236
4418
|
}
|
|
4237
|
-
var nodeRef = (n
|
|
4238
|
-
|
|
4419
|
+
var nodeRef = (n, renamedFrom = n.renamedFrom) => ({
|
|
4420
|
+
epoch: n.epoch,
|
|
4421
|
+
event: n.event,
|
|
4422
|
+
...n.kind === void 0 ? {} : { kind: n.kind },
|
|
4423
|
+
frame: n.frame,
|
|
4424
|
+
...renamedFrom === void 0 ? {} : { renamedFrom }
|
|
4425
|
+
});
|
|
4426
|
+
var epochEventId = (g) => JSON.stringify([g.epoch, g.event]);
|
|
4427
|
+
var byEventThenEpoch = (x, y) => x.event < y.event ? -1 : x.event > y.event ? 1 : x.epoch < y.epoch ? -1 : x.epoch > y.epoch ? 1 : 0;
|
|
4428
|
+
function pairNames(a, b, userMap, context = {}) {
|
|
4429
|
+
const inA = new Set(a.map(epochEventId));
|
|
4430
|
+
const inB = new Set(b.map(epochEventId));
|
|
4431
|
+
const unique = (groups) => [...new Map(groups.map((g) => [epochEventId(g), g])).values()];
|
|
4432
|
+
const onlyA = unique(a.filter((g) => !inB.has(epochEventId(g)))).sort(byEventThenEpoch);
|
|
4433
|
+
const onlyB = unique(b.filter((g) => !inA.has(epochEventId(g)))).sort(byEventThenEpoch);
|
|
4434
|
+
const movedNames = new Set(onlyA.map((g) => g.event).filter((n) => onlyB.some((g) => g.event === n)));
|
|
4435
|
+
const normalized = normalizePushGroups(a, userMap);
|
|
4436
|
+
const shapeOf = (groups, from, epoch, event) => JSON.stringify(
|
|
4437
|
+
[...pushNodes(groups.filter((_, i) => from[i].epoch === epoch && from[i].event === event), context.acrossFrames ?? false, context.mergeKinds ?? false).values()].map((n) => JSON.stringify([n.kind ?? null, n.frame, typesId(n)])).sort()
|
|
4438
|
+
);
|
|
4439
|
+
const canMove = (from, to) => neighbourEpochs(context.epochOrder ?? [], from.epoch, to.epoch) && shapeOf(normalized, a, from.epoch, from.event) === shapeOf(b, b, to.epoch, to.event);
|
|
4440
|
+
const taken = new Set(inA);
|
|
4441
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
4442
|
+
const joined = /* @__PURE__ */ new Map();
|
|
4443
|
+
const pair = (sameEpoch) => {
|
|
4444
|
+
for (const from of onlyA) {
|
|
4445
|
+
if (joined.has(epochEventId(from)) || !sameEpoch && movedNames.has(from.event)) continue;
|
|
4446
|
+
const want = mappedEventName(from.event, userMap);
|
|
4447
|
+
const to = onlyB.find(
|
|
4448
|
+
(g) => !claimed.has(epochEventId(g)) && builtInEventName(g.event) === want && !taken.has(JSON.stringify([from.epoch, g.event])) && (sameEpoch ? g.epoch === from.epoch : !movedNames.has(g.event) && canMove(from, g))
|
|
4449
|
+
);
|
|
4450
|
+
if (to === void 0) continue;
|
|
4451
|
+
claimed.add(epochEventId(to));
|
|
4452
|
+
taken.add(JSON.stringify([from.epoch, to.event]));
|
|
4453
|
+
joined.set(epochEventId(from), to.event);
|
|
4454
|
+
}
|
|
4455
|
+
};
|
|
4456
|
+
pair(true);
|
|
4457
|
+
pair(false);
|
|
4458
|
+
const kept = keepPushGroups(a, userMap);
|
|
4459
|
+
return normalized.map((g, i) => {
|
|
4460
|
+
const recorded = a[i];
|
|
4461
|
+
const to = joined.get(epochEventId(recorded));
|
|
4462
|
+
return to === void 0 ? kept[i] : { ...g, event: to, renamedFrom: recorded.event };
|
|
4463
|
+
});
|
|
4464
|
+
}
|
|
4465
|
+
function typesId(n) {
|
|
4466
|
+
return JSON.stringify([...n.types].sort(([x], [y]) => x < y ? -1 : x > y ? 1 : 0));
|
|
4467
|
+
}
|
|
4468
|
+
function withoutEventName(n, other) {
|
|
4469
|
+
if (n.kind !== "object" || !n.types.has("event") || other.types.has("event")) return n;
|
|
4470
|
+
const types = new Map(n.types);
|
|
4471
|
+
types.delete("event");
|
|
4472
|
+
return { ...n, types };
|
|
4473
|
+
}
|
|
4239
4474
|
function diffPushes(a, b, options = {}) {
|
|
4240
4475
|
const result = { eventsAdded: [], eventsRemoved: [], pathsAdded: [], pathsRemoved: [], typeChanges: [], moved: [], kindChanged: [], changed: false };
|
|
4241
|
-
const mergeKinds =
|
|
4242
|
-
const
|
|
4243
|
-
const
|
|
4476
|
+
const mergeKinds = kindsMerged(a, b);
|
|
4477
|
+
const order = options.epochOrder ?? [];
|
|
4478
|
+
const na = pushNodes(pairNames(a, b, options.eventMap, { epochOrder: order, acrossFrames: options.acrossFrames, mergeKinds }), options.acrossFrames ?? false, mergeKinds);
|
|
4479
|
+
const nb = pushNodes(b, options.acrossFrames ?? false, mergeKinds);
|
|
4244
4480
|
const gone = [];
|
|
4245
4481
|
const fresh = [];
|
|
4246
4482
|
const compare = (x, y) => {
|
|
4247
4483
|
for (const [path, types] of y.types) {
|
|
4248
4484
|
const before = x.types.get(path);
|
|
4249
|
-
if (!before) result.pathsAdded.push({ ...nodeRef(y), path, types });
|
|
4250
|
-
else if (before.join() !== types.join()) result.typeChanges.push({ ...nodeRef(y), path, a: before, b: types });
|
|
4485
|
+
if (!before) result.pathsAdded.push({ ...nodeRef(y, x.renamedFrom), path, types });
|
|
4486
|
+
else if (before.join() !== types.join()) result.typeChanges.push({ ...nodeRef(y, x.renamedFrom), path, a: before, b: types });
|
|
4251
4487
|
}
|
|
4252
4488
|
for (const [path, types] of x.types) if (!y.types.has(path)) result.pathsRemoved.push({ ...nodeRef(x), path, types });
|
|
4253
4489
|
if (x.frames.slice().sort().join() !== y.frames.slice().sort().join()) {
|
|
4254
|
-
result.moved.push({ event: y.event, kind: "frame", epoch: y.epoch, from: x.frames.slice().sort().join("+"), to: y.frames.slice().sort().join("+") });
|
|
4490
|
+
result.moved.push({ event: y.event, ...x.renamedFrom === void 0 ? {} : { renamedFrom: x.renamedFrom }, kind: "frame", ...y.kind === void 0 ? {} : { pushKind: y.kind }, epoch: y.epoch, from: x.frames.slice().sort().join("+"), to: y.frames.slice().sort().join("+") });
|
|
4255
4491
|
}
|
|
4256
4492
|
};
|
|
4257
4493
|
for (const id of [.../* @__PURE__ */ new Set([...na.keys(), ...nb.keys()])].sort()) {
|
|
@@ -4267,27 +4503,23 @@ function diffPushes(a, b, options = {}) {
|
|
|
4267
4503
|
if (!f) continue;
|
|
4268
4504
|
gone.splice(gone.indexOf(g), 1);
|
|
4269
4505
|
fresh.splice(fresh.indexOf(f), 1);
|
|
4270
|
-
result.kindChanged.push({ epoch: g.epoch, event: g.event, frame: g.frame, from: g.kind, to: f.kind });
|
|
4271
|
-
compare(g, f);
|
|
4506
|
+
result.kindChanged.push({ epoch: g.epoch, event: g.event, frame: g.frame, from: g.kind, to: f.kind, ...g.renamedFrom === void 0 ? {} : { renamedFrom: g.renamedFrom } });
|
|
4507
|
+
compare(withoutEventName(g, f), withoutEventName(f, g));
|
|
4272
4508
|
}
|
|
4273
|
-
const order = options.epochOrder ?? [];
|
|
4274
4509
|
const taken = /* @__PURE__ */ new Set();
|
|
4275
4510
|
for (const g of gone) {
|
|
4276
|
-
const
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
const j = order.indexOf(f.epoch);
|
|
4280
|
-
return i >= 0 && j >= 0 && Math.abs(i - j) === 1 && order.filter((l) => l === g.epoch || l === f.epoch).length === 2;
|
|
4281
|
-
});
|
|
4511
|
+
const match = fresh.find(
|
|
4512
|
+
(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
|
+
);
|
|
4282
4514
|
if (!match) {
|
|
4283
|
-
result.eventsRemoved.push(nodeRef(g));
|
|
4515
|
+
result.eventsRemoved.push({ ...nodeRef({ ...g, renamedFrom: void 0 }), event: g.renamedFrom ?? g.event });
|
|
4284
4516
|
continue;
|
|
4285
4517
|
}
|
|
4286
4518
|
taken.add(match);
|
|
4287
|
-
result.moved.push({ event: g.event, kind: "epoch", frame: g.frame, from: g.epoch, to: match.epoch });
|
|
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 });
|
|
4288
4520
|
}
|
|
4289
4521
|
for (const f of fresh) if (!taken.has(f)) result.eventsAdded.push(nodeRef(f));
|
|
4290
|
-
result.changed = result.eventsAdded.length + result.eventsRemoved.length + result.pathsAdded.length + result.pathsRemoved.length + result.typeChanges.length > 0;
|
|
4522
|
+
result.changed = result.eventsAdded.length + result.eventsRemoved.length + result.pathsAdded.length + result.pathsRemoved.length + result.typeChanges.length + result.kindChanged.length > 0;
|
|
4291
4523
|
return result;
|
|
4292
4524
|
}
|
|
4293
4525
|
function hitShape(run, options = {}) {
|
|
@@ -4349,10 +4581,7 @@ function findMove(epochs, order) {
|
|
|
4349
4581
|
const d1 = total(v1.b) - total(v1.a);
|
|
4350
4582
|
if (d1 + total(v2.b) - total(v2.a) !== 0) return void 0;
|
|
4351
4583
|
const [from, to] = d1 < 0 ? [[e1, v1], [e2, v2]] : [[e2, v2], [e1, v1]];
|
|
4352
|
-
|
|
4353
|
-
const j = order.indexOf(to[0]);
|
|
4354
|
-
if (i < 0 || j < 0 || Math.abs(i - j) !== 1) return void 0;
|
|
4355
|
-
if (order.filter((l) => l === from[0] || l === to[0]).length !== 2) return void 0;
|
|
4584
|
+
if (!neighbourEpochs(order, from[0], to[0])) return void 0;
|
|
4356
4585
|
if (!contains(tupleCounts(from[1].a), tupleCounts(from[1].b))) return void 0;
|
|
4357
4586
|
if (!contains(tupleCounts(to[1].b), tupleCounts(to[1].a))) return void 0;
|
|
4358
4587
|
if (!sameCounts(surplusByIds(from[1].a, from[1].b), surplusByIds(to[1].b, to[1].a))) return void 0;
|
|
@@ -4921,7 +5150,7 @@ function dataLayerInitScript(names = []) {
|
|
|
4921
5150
|
}
|
|
4922
5151
|
};
|
|
4923
5152
|
let assigned = own && 'value' in own ? own.value : record;
|
|
4924
|
-
const state = { info, sync, schedule };
|
|
5153
|
+
const state = { info, name: layerName, sync, schedule };
|
|
4925
5154
|
hooks.set(layer, state);
|
|
4926
5155
|
// A push accessor the page defined stays in place; the growth check still records.
|
|
4927
5156
|
const foreign = own && !('value' in own);
|
|
@@ -4962,8 +5191,12 @@ function dataLayerInitScript(names = []) {
|
|
|
4962
5191
|
if (!found) return !(name in window);
|
|
4963
5192
|
return found.configurable === true && 'value' in found && Array.isArray(found.value);
|
|
4964
5193
|
};
|
|
5194
|
+
const untrapped = [];
|
|
4965
5195
|
for (const name of names) {
|
|
4966
|
-
if (!trappable(name))
|
|
5196
|
+
if (!trappable(name)) {
|
|
5197
|
+
untrapped.push(name);
|
|
5198
|
+
continue;
|
|
5199
|
+
}
|
|
4967
5200
|
current[name] = window[name];
|
|
4968
5201
|
try {
|
|
4969
5202
|
hook(current[name], name);
|
|
@@ -4992,32 +5225,38 @@ function dataLayerInitScript(names = []) {
|
|
|
4992
5225
|
},
|
|
4993
5226
|
});
|
|
4994
5227
|
}
|
|
5228
|
+
// Text, so page code cannot change the answer by replacing an Array method.
|
|
5229
|
+
const untrappedText = JSON.stringify(untrapped);
|
|
4995
5230
|
Object.defineProperty(window, ${JSON.stringify(DATALAYER_TALLY)}, {
|
|
4996
5231
|
value: () => {
|
|
4997
5232
|
const arrays = [];
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5233
|
+
// Page code can break Set or the array iterator; the untrapped list must still come back.
|
|
5234
|
+
try {
|
|
5235
|
+
const seen = new Set();
|
|
5236
|
+
for (const name of names) {
|
|
5002
5237
|
try {
|
|
5003
|
-
layer
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5238
|
+
let layer;
|
|
5239
|
+
reading = true;
|
|
5240
|
+
try {
|
|
5241
|
+
layer = window[name];
|
|
5242
|
+
} finally {
|
|
5243
|
+
reading = false;
|
|
5244
|
+
}
|
|
5245
|
+
if (!Array.isArray(layer) || seen.has(layer)) continue;
|
|
5246
|
+
seen.add(layer);
|
|
5247
|
+
const state = hooks.get(layer);
|
|
5248
|
+
// Another frame's hook owns it and that frame counts it.
|
|
5249
|
+
if (!state && Object.prototype.hasOwnProperty.call(layer, '__tagreeveHooked')) continue;
|
|
5250
|
+
if (state) state.sync();
|
|
5251
|
+
arrays.push({ layer: state ? state.name : name, a: state ? state.info.a : null, length: layer.length, posted: state ? state.info.posted : 0 });
|
|
5252
|
+
} catch {}
|
|
5253
|
+
}
|
|
5254
|
+
} catch {}
|
|
5255
|
+
return { d: token, arrays, untrapped: untrappedText };
|
|
5014
5256
|
},
|
|
5015
5257
|
});
|
|
5016
5258
|
})();`;
|
|
5017
5259
|
}
|
|
5018
|
-
function isDataLayerName(name) {
|
|
5019
|
-
return typeof name === "string" && DATALAYER_NAME_PATTERN.test(name) && !NEVER_TRAPPED_NAMES.includes(name);
|
|
5020
|
-
}
|
|
5021
5260
|
function isConsentCommand(args) {
|
|
5022
5261
|
return args[0] === "consent" && (args[1] === "default" || args[1] === "update");
|
|
5023
5262
|
}
|
|
@@ -5094,7 +5333,7 @@ function isFirstPartySubdomain(req, scope, trackers = trackerList) {
|
|
|
5094
5333
|
function flag(runId, kind, recordIds, detail) {
|
|
5095
5334
|
return { type: "flag", id: newId("flag"), runId, kind, recordIds, detail };
|
|
5096
5335
|
}
|
|
5097
|
-
function buildFlags({ runId, networkMode, siteUrl, firstPartyHosts, trackers = trackerList, platformHosts: platformHosts2 = true, requests, hits, identity, routedRequestIds, responses = [], handedToChromium = /* @__PURE__ */ new Set(), redirectHeaderWithoutRedirect = /* @__PURE__ */ new Set() }) {
|
|
5336
|
+
function buildFlags({ runId, networkMode, siteUrl, firstPartyHosts, trackers = trackerList, platformHosts: platformHosts2 = true, requests, hits, identity, dataLayerEvents = [], routedRequestIds, responses = [], handedToChromium = /* @__PURE__ */ new Set(), redirectHeaderWithoutRedirect = /* @__PURE__ */ new Set() }) {
|
|
5098
5337
|
const answered = new Set(responses.map((r) => r.requestId));
|
|
5099
5338
|
const scope = { siteHost: parse(siteUrl)?.hostname ?? "", firstPartyHosts };
|
|
5100
5339
|
const flags2 = [];
|
|
@@ -5125,7 +5364,9 @@ function buildFlags({ runId, networkMode, siteUrl, firstPartyHosts, trackers = t
|
|
|
5125
5364
|
}
|
|
5126
5365
|
}
|
|
5127
5366
|
if (identity) {
|
|
5128
|
-
for (const leak of findForeignData(requests, hits, identity
|
|
5367
|
+
for (const leak of findForeignData(requests, hits, identity, dataLayerEvents)) {
|
|
5368
|
+
flags2.push(flag(runId, leak.source === "push" ? "possibleRealDataPush" : "possibleRealData", leak.evidence, leak.detail));
|
|
5369
|
+
}
|
|
5129
5370
|
}
|
|
5130
5371
|
return flags2;
|
|
5131
5372
|
}
|
|
@@ -5381,9 +5622,9 @@ function handoffOverlayScript(nonce) {
|
|
|
5381
5622
|
setText(button, 'Done');
|
|
5382
5623
|
appendChild(pill, label, button);
|
|
5383
5624
|
appendToRoot(root, pill);
|
|
5384
|
-
apply(pill, { display: 'flex', 'align-items': '
|
|
5385
|
-
apply(label, {
|
|
5386
|
-
apply(button, { all: 'unset', 'box-sizing': 'border-box', background: '#2f7d4f', color: '#fff', padding: '4px 14px', 'border-radius': '999px', 'font-weight': '600', cursor: 'pointer', 'flex-shrink': '0' });
|
|
5625
|
+
apply(pill, { display: 'flex', 'align-items': 'flex-start', gap: '10px', padding: '6px 6px 6px 12px', background: '#1d2530', color: '#fff', font: '13px/1.3 system-ui, sans-serif', 'border-radius': '14px', 'box-sizing': 'border-box', 'max-width': '100%', 'box-shadow': '0 2px 10px rgba(0,0,0,.35)', cursor: 'grab', 'user-select': 'none', 'touch-action': 'none' });
|
|
5626
|
+
apply(label, { display: '-webkit-box', '-webkit-box-orient': 'vertical', '-webkit-line-clamp': '4', overflow: 'hidden', 'overflow-wrap': 'anywhere', 'min-width': '0' });
|
|
5627
|
+
apply(button, { all: 'unset', 'box-sizing': 'border-box', background: '#2f7d4f', color: '#fff', padding: '4px 14px', 'align-self': 'stretch', display: 'flex', 'align-items': 'center', 'border-radius': '999px', 'font-weight': '600', cursor: 'pointer', 'flex-shrink': '0' });
|
|
5387
5628
|
addListener(button, 'click', (event) => {
|
|
5388
5629
|
if (!trusted(event)) return;
|
|
5389
5630
|
Promise.resolve(doneFn(NONCE)).catch(() => {});
|
|
@@ -5870,9 +6111,18 @@ var PayloadCounts = class _PayloadCounts {
|
|
|
5870
6111
|
}
|
|
5871
6112
|
};
|
|
5872
6113
|
var isCount = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
6114
|
+
function parseNames(text2) {
|
|
6115
|
+
if (typeof text2 !== "string" || text2.length > 4096) return [];
|
|
6116
|
+
try {
|
|
6117
|
+
const parsed = JSON.parse(text2);
|
|
6118
|
+
return Array.isArray(parsed) ? parsed.filter((n) => typeof n === "string") : [];
|
|
6119
|
+
} catch {
|
|
6120
|
+
return [];
|
|
6121
|
+
}
|
|
6122
|
+
}
|
|
5873
6123
|
function validateTally(frame, value, names) {
|
|
5874
6124
|
if (typeof value !== "object" || value === null) return null;
|
|
5875
|
-
const { d, arrays } = value;
|
|
6125
|
+
const { d, arrays, untrapped } = value;
|
|
5876
6126
|
if (typeof d !== "string" || d.length > 64 || !Array.isArray(arrays)) return null;
|
|
5877
6127
|
const kept = [];
|
|
5878
6128
|
for (const entry of arrays) {
|
|
@@ -5882,7 +6132,8 @@ function validateTally(frame, value, names) {
|
|
|
5882
6132
|
if (!isCount(length) || !isCount(posted) || !(a === null || isCount(a))) continue;
|
|
5883
6133
|
kept.push({ layer, a, length, posted });
|
|
5884
6134
|
}
|
|
5885
|
-
|
|
6135
|
+
const untrappedKept = parseNames(untrapped).filter((n) => n !== DEFAULT_DATALAYER && names.includes(n));
|
|
6136
|
+
return { frame, d, arrays: kept, untrapped: [...new Set(untrappedKept)] };
|
|
5886
6137
|
}
|
|
5887
6138
|
function postedAhead(tallies, counts) {
|
|
5888
6139
|
return tallies.some(
|
|
@@ -6145,6 +6396,15 @@ function gtmFailureMessage(override, applied, fetchError, hint = "") {
|
|
|
6145
6396
|
|
|
6146
6397
|
// packages/recorder/src/datalayer-names.ts
|
|
6147
6398
|
var GOOGLE_TAG_ID = /^(GTM|G|GT|AW|DC)-[A-Z0-9]+$/;
|
|
6399
|
+
var LOADER_PATH = /\/(gtm\.js|gtag\/js)$/;
|
|
6400
|
+
function isGoogleHostLoaderUrl(url) {
|
|
6401
|
+
try {
|
|
6402
|
+
const parsed = new URL(url);
|
|
6403
|
+
return parsed.hostname === "www.googletagmanager.com" && LOADER_PATH.test(parsed.pathname);
|
|
6404
|
+
} catch {
|
|
6405
|
+
return false;
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6148
6408
|
function loaderName(url, googleOnly) {
|
|
6149
6409
|
let parsed;
|
|
6150
6410
|
try {
|
|
@@ -6152,7 +6412,7 @@ function loaderName(url, googleOnly) {
|
|
|
6152
6412
|
} catch {
|
|
6153
6413
|
return void 0;
|
|
6154
6414
|
}
|
|
6155
|
-
if (
|
|
6415
|
+
if (!LOADER_PATH.test(parsed.pathname)) return void 0;
|
|
6156
6416
|
if (googleOnly && !GOOGLE_HOST.test(parsed.hostname) && !GOOGLE_TAG_ID.test(parsed.searchParams.get("id") ?? "")) return void 0;
|
|
6157
6417
|
const name = parsed.searchParams.get("l");
|
|
6158
6418
|
return name === null || name === "" ? void 0 : name;
|
|
@@ -6165,7 +6425,8 @@ function loaderLayerName(req) {
|
|
|
6165
6425
|
}
|
|
6166
6426
|
var MAX_LISTED_NAMES = 5;
|
|
6167
6427
|
function buildDataLayerNotHookedFlag(input) {
|
|
6168
|
-
const
|
|
6428
|
+
const untrapped = new Set(input.untrapped ?? []);
|
|
6429
|
+
const hooked = new Set([DEFAULT_DATALAYER, ...input.hooked].filter((name) => !untrapped.has(name)));
|
|
6169
6430
|
const misses = input.loaders.filter((l) => !hooked.has(l.name));
|
|
6170
6431
|
if (misses.length === 0) return void 0;
|
|
6171
6432
|
const names = [...new Set(misses.map((m) => isDataLayerName(m.name) && !isValueSegment(m.name) ? `"${m.name}"` : "(other)"))];
|
|
@@ -6173,15 +6434,27 @@ function buildDataLayerNotHookedFlag(input) {
|
|
|
6173
6434
|
const rest = names.length - MAX_LISTED_NAMES;
|
|
6174
6435
|
const shown2 = rest > 0 ? `${listed} and ${rest} more` : listed;
|
|
6175
6436
|
const plural2 = names.length > 1;
|
|
6437
|
+
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.";
|
|
6176
6438
|
return {
|
|
6177
6439
|
type: "flag",
|
|
6178
6440
|
id: newId("flag"),
|
|
6179
6441
|
runId: input.runId,
|
|
6180
6442
|
kind: "dataLayerNotHooked",
|
|
6181
6443
|
recordIds: misses.map((m) => m.id),
|
|
6182
|
-
detail: plural2 ? `Google loaders name the data layers ${shown2}, which are not hooked, so pushes to them are not recorded.
|
|
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")}`
|
|
6183
6445
|
};
|
|
6184
6446
|
}
|
|
6447
|
+
function buildDataLayerReassignedFlags(input) {
|
|
6448
|
+
const frames = new Set(input.reassigns.filter((r) => input.loaders.some((l) => l.doc === r.doc && l.t <= r.t)).map((r) => r.n));
|
|
6449
|
+
return [...frames].sort((a, b) => a - b).map((n) => ({
|
|
6450
|
+
type: "flag",
|
|
6451
|
+
id: newId("flag"),
|
|
6452
|
+
runId: input.runId,
|
|
6453
|
+
kind: "dataLayerReassigned",
|
|
6454
|
+
recordIds: [],
|
|
6455
|
+
detail: `Frame ${n} replaced window.dataLayer with a new array after a Google loader request. Pushes to the new array are still recorded.`
|
|
6456
|
+
}));
|
|
6457
|
+
}
|
|
6185
6458
|
|
|
6186
6459
|
// packages/recorder/src/tag-report.ts
|
|
6187
6460
|
var TAG_REPORT_BINDING = "tagreeveTagReport";
|
|
@@ -7324,11 +7597,11 @@ ${lines.join("\n")}` : "";
|
|
|
7324
7597
|
throw new ServerContainerError("notReady", `${PROBE_HOST} could not be resolved here, so the egress check cannot run. The container was not started.`);
|
|
7325
7598
|
}
|
|
7326
7599
|
if (!net.isIPv4(probeAddress)) throw new ServerContainerError("notReady", `${PROBE_HOST} did not resolve to an IPv4 address. The container was not started.`);
|
|
7327
|
-
const
|
|
7600
|
+
const probe2 = await docker(["run", "--rm", "--name", names.probe, "--network", names.network, ...labels, "--entrypoint", NODE_BIN, options.image, "-e", PROBE_SCRIPT, probeAddress], {}, 6e4);
|
|
7328
7601
|
checkAborted();
|
|
7329
7602
|
let outcome;
|
|
7330
7603
|
try {
|
|
7331
|
-
outcome = JSON.parse(
|
|
7604
|
+
outcome = JSON.parse(probe2.stdout.trim().split("\n").pop() ?? "");
|
|
7332
7605
|
} catch {
|
|
7333
7606
|
outcome = void 0;
|
|
7334
7607
|
}
|
|
@@ -7637,6 +7910,14 @@ function linkServerHits({ hits, requests, serverHosts, identity, inFlight }) {
|
|
|
7637
7910
|
onServerHost
|
|
7638
7911
|
};
|
|
7639
7912
|
});
|
|
7913
|
+
const hitRequestIds = new Set(hits.map((h) => h.requestId));
|
|
7914
|
+
const hasConcurrentRequest = (only, from, to, callClientIds) => requests.some((r) => {
|
|
7915
|
+
if (r.captured === "serverContainer" || r.id === only.hit.requestId || r.initiator === "unload" || !isServerContainerRequest(r, serverHosts)) return false;
|
|
7916
|
+
const sentAt = inFlight?.get(r.id)?.sentAt ?? r.t;
|
|
7917
|
+
if (sentAt < from || sentAt > to) return false;
|
|
7918
|
+
if (!hitRequestIds.has(r.id)) return true;
|
|
7919
|
+
return [...clientIdsOf(r)].some((id) => callClientIds.has(id));
|
|
7920
|
+
});
|
|
7640
7921
|
const isServer = (f) => f.request?.captured === "serverContainer";
|
|
7641
7922
|
const browser = facts.filter((f) => !isServer(f));
|
|
7642
7923
|
return facts.map((f) => {
|
|
@@ -7654,10 +7935,12 @@ function linkServerHits({ hits, requests, serverHosts, identity, inFlight }) {
|
|
|
7654
7935
|
});
|
|
7655
7936
|
const only = sameKey.length === 1 ? sameKey[0] : void 0;
|
|
7656
7937
|
const window2 = only && inFlight?.get(only.hit.requestId);
|
|
7657
|
-
|
|
7938
|
+
const inFlightNow = only !== void 0 && window2 && callAt !== void 0 && callAt < window2.answeredAt;
|
|
7939
|
+
const concurrent = inFlightNow && hasConcurrentRequest(only, window2.sentAt, callAt, f.clientIds);
|
|
7940
|
+
if (inFlightNow && !concurrent) {
|
|
7658
7941
|
return { ...f.hit, via: { hitId: only.hit.id, by: "clientId", confidence: "exact" } };
|
|
7659
7942
|
}
|
|
7660
|
-
const clientIdMiss = f.hit.event === null || f.clientIds.size === 0 ? "noClientId" : sameKey.length === 0 ? "noSameKeyHit" : sameKey.length > 1 ? "severalSameKeyHits" : "answeredBefore";
|
|
7943
|
+
const clientIdMiss = f.hit.event === null || f.clientIds.size === 0 ? "noClientId" : sameKey.length === 0 ? "noSameKeyHit" : sameKey.length > 1 ? "severalSameKeyHits" : concurrent ? "concurrentRequest" : "answeredBefore";
|
|
7661
7944
|
const linkMiss = { eventId: eventIdMiss, clientId: clientIdMiss };
|
|
7662
7945
|
const earlier = browser.flatMap((b) => {
|
|
7663
7946
|
const by = b.hit.t <= f.hit.t ? sharedKind(f, b) : void 0;
|
|
@@ -7843,6 +8126,7 @@ var Recorder = class _Recorder {
|
|
|
7843
8126
|
dataLayerEvents = [];
|
|
7844
8127
|
dataLayerReassigns = [];
|
|
7845
8128
|
payloadCounts = new PayloadCounts();
|
|
8129
|
+
untrappedLayerNames = [];
|
|
7846
8130
|
eventFrames = /* @__PURE__ */ new Map();
|
|
7847
8131
|
frameNumbers = /* @__PURE__ */ new WeakMap();
|
|
7848
8132
|
frameNavigations = /* @__PURE__ */ new WeakMap();
|
|
@@ -8576,15 +8860,15 @@ var Recorder = class _Recorder {
|
|
|
8576
8860
|
const tallies = [];
|
|
8577
8861
|
let frames = [];
|
|
8578
8862
|
try {
|
|
8579
|
-
frames = this.context.pages().flatMap((page2) => page2.frames());
|
|
8863
|
+
frames = this.context.pages().flatMap((page2) => page2.frames().map((frame, i) => ({ frame, top: i === 0 })));
|
|
8580
8864
|
} catch {
|
|
8581
8865
|
return tallies;
|
|
8582
8866
|
}
|
|
8583
8867
|
const script = `window.${DATALAYER_TALLY}?.()`;
|
|
8584
|
-
const asking = frames.map(async (frame) => {
|
|
8868
|
+
const asking = frames.map(async ({ frame, top }) => {
|
|
8585
8869
|
try {
|
|
8586
8870
|
const tally = validateTally(this.frameNumber(frame), await frame.evaluate(script), names);
|
|
8587
|
-
if (tally) tallies.push(tally);
|
|
8871
|
+
if (tally) tallies.push(top ? tally : { ...tally, untrapped: [] });
|
|
8588
8872
|
} catch {
|
|
8589
8873
|
}
|
|
8590
8874
|
});
|
|
@@ -8598,24 +8882,14 @@ var Recorder = class _Recorder {
|
|
|
8598
8882
|
}
|
|
8599
8883
|
async tallyDataLayers() {
|
|
8600
8884
|
const tallies = await this.collectTallies();
|
|
8885
|
+
this.untrappedLayerNames = [...new Set(tallies.flatMap((t) => t.untrapped))];
|
|
8601
8886
|
const start = Date.now();
|
|
8602
8887
|
while (postedAhead(tallies, this.payloadCounts) && Date.now() - start < TALLY_POSTED_WAIT_MS) await this.wait(20);
|
|
8603
8888
|
return buildTallyFlags(this.runId, tallies, this.payloadCounts);
|
|
8604
8889
|
}
|
|
8605
8890
|
dataLayerReassignedFlags(requests) {
|
|
8606
|
-
const loaders = requests.filter((r) =>
|
|
8607
|
-
|
|
8608
|
-
const frames = new Set(
|
|
8609
|
-
this.dataLayerReassigns.filter((r) => loaders.some((l) => this.requestFrameIds.get(l.id) === r.doc && l.t <= r.t)).map((r) => r.n)
|
|
8610
|
-
);
|
|
8611
|
-
return [...frames].sort((a, b) => a - b).map((n) => ({
|
|
8612
|
-
type: "flag",
|
|
8613
|
-
id: newId("flag"),
|
|
8614
|
-
runId: this.runId,
|
|
8615
|
-
kind: "dataLayerReassigned",
|
|
8616
|
-
recordIds: [],
|
|
8617
|
-
detail: `Frame ${n} replaced window.dataLayer with a new array after a Google loader request. Pushes to the new array are still recorded.`
|
|
8618
|
-
}));
|
|
8891
|
+
const loaders = requests.filter((r) => isGoogleHostLoaderUrl(r.url)).map((r) => ({ t: r.t, doc: this.requestFrameIds.get(r.id) }));
|
|
8892
|
+
return buildDataLayerReassignedFlags({ runId: this.runId, reassigns: this.dataLayerReassigns, loaders });
|
|
8619
8893
|
}
|
|
8620
8894
|
noteContainerExit() {
|
|
8621
8895
|
if (this.session?.containerExited() && !this.containerFailure) {
|
|
@@ -8670,6 +8944,7 @@ var Recorder = class _Recorder {
|
|
|
8670
8944
|
requests,
|
|
8671
8945
|
hits,
|
|
8672
8946
|
identity: this.run.identity,
|
|
8947
|
+
dataLayerEvents: this.dataLayerEvents,
|
|
8673
8948
|
routedRequestIds: this.routed,
|
|
8674
8949
|
responses: this.responses,
|
|
8675
8950
|
handedToChromium: this.handedToChromium,
|
|
@@ -8682,7 +8957,7 @@ var Recorder = class _Recorder {
|
|
|
8682
8957
|
flags2.push({ type: "flag", id: newId("flag"), runId: this.runId, kind: "netLogUnreadable", recordIds: [], detail: "The net log could not be read, so requests sent while a frame unloads may be missing." });
|
|
8683
8958
|
}
|
|
8684
8959
|
flags2.push(...this.dataLayerReassignedFlags(requests));
|
|
8685
|
-
const notHooked = buildDataLayerNotHookedFlag({ runId: this.runId, loaders: this.loaderLayers, hooked: this.options.dataLayerNames ?? [] });
|
|
8960
|
+
const notHooked = buildDataLayerNotHookedFlag({ runId: this.runId, loaders: this.loaderLayers, hooked: this.options.dataLayerNames ?? [], untrapped: this.untrappedLayerNames });
|
|
8686
8961
|
if (notHooked) flags2.push(notHooked);
|
|
8687
8962
|
flags2.push(...tallyFlags);
|
|
8688
8963
|
this.recordServerContainer(requests, hits, containerCounts, flags2);
|
|
@@ -8741,14 +9016,6 @@ function abortCode(error) {
|
|
|
8741
9016
|
return "failed";
|
|
8742
9017
|
}
|
|
8743
9018
|
var BODY_HEADERS = /* @__PURE__ */ new Set(["content-type", "content-length", "content-encoding", "content-language", "content-location", "origin"]);
|
|
8744
|
-
function isGoogleLoaderUrl(url) {
|
|
8745
|
-
try {
|
|
8746
|
-
const u = new URL(url);
|
|
8747
|
-
return u.hostname === "www.googletagmanager.com" && (u.pathname === "/gtm.js" || u.pathname === "/gtag/js");
|
|
8748
|
-
} catch {
|
|
8749
|
-
return false;
|
|
8750
|
-
}
|
|
8751
|
-
}
|
|
8752
9019
|
function withoutMethodChangeHeaders(headers) {
|
|
8753
9020
|
return Object.fromEntries(Object.entries(headers).filter(([name]) => !BODY_HEADERS.has(name.toLowerCase())));
|
|
8754
9021
|
}
|
|
@@ -8903,12 +9170,14 @@ var BLOCK_REASONS = ["required, not ticked", "invalid", "aria-invalid"];
|
|
|
8903
9170
|
var INPUT_TYPES = ["checkbox", "color", "date", "datetime-local", "email", "file", "month", "number", "password", "radio", "range", "search", "tel", "text", "time", "url", "week"];
|
|
8904
9171
|
var WIDGET_ROLES = ["checkbox", "combobox", "listbox", "radio", "radiogroup", "searchbox", "slider", "spinbutton", "switch", "textbox"];
|
|
8905
9172
|
var KINDS = [...INPUT_TYPES, ...WIDGET_ROLES, "select", "textarea"];
|
|
8906
|
-
function readBlockingControls(max) {
|
|
9173
|
+
function readBlockingControls({ max, form: remembered }) {
|
|
9174
|
+
const form = remembered?.isConnected && remembered.ownerDocument === document ? remembered : null;
|
|
8907
9175
|
const found = [];
|
|
8908
9176
|
const nameOf2 = (el) => el.getAttribute("aria-label")?.trim() || el.getAttribute("name") || el.id;
|
|
8909
9177
|
for (const el of document.querySelectorAll('input, select, textarea, [aria-invalid="true"]')) {
|
|
8910
9178
|
if (el instanceof HTMLInputElement && (el.type === "hidden" || el.type === "submit" || el.type === "button" || el.type === "reset" || el.type === "image")) continue;
|
|
8911
9179
|
const input = el;
|
|
9180
|
+
if (form && el.form !== form) continue;
|
|
8912
9181
|
const checkbox = el instanceof HTMLInputElement && el.type === "checkbox";
|
|
8913
9182
|
let reason;
|
|
8914
9183
|
if (checkbox && !input.checked && input.willValidate && (input.required || el.getAttribute("aria-required") === "true")) reason = "required, not ticked";
|
|
@@ -8929,11 +9198,13 @@ function withDeadline(work, ms) {
|
|
|
8929
9198
|
});
|
|
8930
9199
|
return Promise.race([work, deadline]).finally(() => clearTimeout(timer));
|
|
8931
9200
|
}
|
|
8932
|
-
async function blockingControls(context) {
|
|
9201
|
+
async function blockingControls(context, form = null) {
|
|
8933
9202
|
const listed = [];
|
|
9203
|
+
const live = form ? await withDeadline(form.evaluate((f) => f.isConnected), DIAGNOSTIC_DEADLINE_MS).catch(() => false) : false;
|
|
9204
|
+
const scope = live ? form : null;
|
|
8934
9205
|
for (const page2 of context.pages()) {
|
|
8935
9206
|
try {
|
|
8936
|
-
const controls = await withDeadline(page2.evaluate(readBlockingControls, MAX_LISTED4), DIAGNOSTIC_DEADLINE_MS);
|
|
9207
|
+
const controls = await withDeadline(page2.evaluate(readBlockingControls, { max: MAX_LISTED4, form: scope }), DIAGNOSTIC_DEADLINE_MS);
|
|
8937
9208
|
for (const c of controls) {
|
|
8938
9209
|
if (!BLOCK_REASONS.includes(c.reason)) continue;
|
|
8939
9210
|
const kind = KINDS.includes(c.kind) ? c.kind : "control";
|
|
@@ -8996,6 +9267,19 @@ function pathOf2(url) {
|
|
|
8996
9267
|
return "";
|
|
8997
9268
|
}
|
|
8998
9269
|
}
|
|
9270
|
+
var FILL_TRY_MS = 500;
|
|
9271
|
+
var UNREADABLE_FRAME = "the card frame could not be read";
|
|
9272
|
+
var DEADLINE_GRACE_MS = 500;
|
|
9273
|
+
var Unresponsive = class extends Error {
|
|
9274
|
+
};
|
|
9275
|
+
function withinDeadline(work, deadline) {
|
|
9276
|
+
let timer;
|
|
9277
|
+
const late = new Promise((_, reject) => {
|
|
9278
|
+
timer = setTimeout(() => reject(new Unresponsive()), Math.max(1, deadline + DEADLINE_GRACE_MS - Date.now()));
|
|
9279
|
+
});
|
|
9280
|
+
work.catch(() => void 0);
|
|
9281
|
+
return Promise.race([work, late]).finally(() => clearTimeout(timer));
|
|
9282
|
+
}
|
|
8999
9283
|
async function cardFrameServed(page2, field, cardHost, deadline) {
|
|
9000
9284
|
let reason = "not found";
|
|
9001
9285
|
for (; ; ) {
|
|
@@ -9003,43 +9287,48 @@ async function cardFrameServed(page2, field, cardHost, deadline) {
|
|
|
9003
9287
|
let hidden = false;
|
|
9004
9288
|
let elsewhere = false;
|
|
9005
9289
|
let otherPath;
|
|
9006
|
-
for (const element of await page2.locator(field.frame).elementHandles()) {
|
|
9007
|
-
const frame = await element.contentFrame();
|
|
9290
|
+
for (const element of await withinDeadline(page2.locator(field.frame).elementHandles(), deadline)) {
|
|
9291
|
+
const frame = await withinDeadline(element.contentFrame(), deadline);
|
|
9008
9292
|
if (!frame) continue;
|
|
9009
9293
|
if (hostOf3(frame.url()) !== cardHost) {
|
|
9010
9294
|
elsewhere = true;
|
|
9011
9295
|
} else if (!field.path.test(pathOf2(frame.url()))) {
|
|
9012
9296
|
otherPath = pathOf2(frame.url());
|
|
9013
|
-
} else if (await element.isVisible()) {
|
|
9297
|
+
} else if (await withinDeadline(element.isVisible(), deadline)) {
|
|
9014
9298
|
return { element, frame };
|
|
9015
9299
|
} else {
|
|
9016
9300
|
hidden = true;
|
|
9017
9301
|
}
|
|
9018
9302
|
}
|
|
9019
9303
|
reason = hidden ? "not visible" : otherPath !== void 0 ? `served from another path: ${otherPath}` : elsewhere ? "served from another host" : "not found";
|
|
9020
|
-
} catch {
|
|
9304
|
+
} catch (error) {
|
|
9305
|
+
if (error instanceof Unresponsive) throw error;
|
|
9021
9306
|
return reason;
|
|
9022
9307
|
}
|
|
9023
9308
|
if (Date.now() >= deadline) return reason;
|
|
9024
9309
|
await new Promise((resolve5) => setTimeout(resolve5, 100));
|
|
9025
9310
|
}
|
|
9026
9311
|
}
|
|
9027
|
-
async function markerInCardContainer(frames, marker,
|
|
9312
|
+
async function markerInCardContainer(frames, marker, deadline) {
|
|
9028
9313
|
try {
|
|
9029
|
-
const container = await
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
|
|
9314
|
+
const container = await withinDeadline(
|
|
9315
|
+
frames[0].evaluateHandle((first, all) => {
|
|
9316
|
+
let node = first.parentElement;
|
|
9317
|
+
while (node && !all.every((f) => node.contains(f))) node = node.parentElement;
|
|
9318
|
+
return node;
|
|
9319
|
+
}, frames),
|
|
9320
|
+
deadline
|
|
9321
|
+
);
|
|
9034
9322
|
const element = container.asElement();
|
|
9035
9323
|
if (!element) return false;
|
|
9036
|
-
await element.waitForSelector(marker, { state: "visible", timeout });
|
|
9324
|
+
await element.waitForSelector(marker, { state: "visible", timeout: Math.max(1, deadline + DEADLINE_GRACE_MS - Date.now()) });
|
|
9037
9325
|
return true;
|
|
9038
|
-
} catch {
|
|
9326
|
+
} catch (error) {
|
|
9327
|
+
if (error instanceof Unresponsive) throw error;
|
|
9039
9328
|
return false;
|
|
9040
9329
|
}
|
|
9041
9330
|
}
|
|
9042
|
-
function
|
|
9331
|
+
function valueOf2(kind, provider, card, identity) {
|
|
9043
9332
|
if (kind === "number") return card;
|
|
9044
9333
|
if (kind === "expiry") return provider.expiry;
|
|
9045
9334
|
if (kind === "cvc") return provider.cvc;
|
|
@@ -9059,19 +9348,27 @@ async function runPayment(page2, recorder, value, identity, testPayment, record,
|
|
|
9059
9348
|
}
|
|
9060
9349
|
const declared = testPayment.declaredProviders?.includes(provider.id) === true;
|
|
9061
9350
|
const wait = Math.min(timeout, MARKER_TIMEOUT_MS);
|
|
9351
|
+
const stepDeadline = Date.now() + timeout;
|
|
9062
9352
|
const deadline = Date.now() + wait;
|
|
9063
9353
|
const found = [];
|
|
9064
9354
|
for (const field of runtime.fields) {
|
|
9065
|
-
const result = await cardFrameServed(page2, field, runtime.cardHost, deadline)
|
|
9355
|
+
const result = await cardFrameServed(page2, field, runtime.cardHost, deadline).catch((error) => {
|
|
9356
|
+
throw error instanceof Unresponsive ? new Error(`card field ${field.kind} could not be filled: ${UNREADABLE_FRAME}`) : error;
|
|
9357
|
+
});
|
|
9066
9358
|
if (typeof result === "string") throw new Error(`card frame not found (${field.kind}): ${result}`);
|
|
9067
9359
|
found.push(result);
|
|
9068
9360
|
}
|
|
9069
|
-
if (!declared
|
|
9361
|
+
if (!declared) {
|
|
9362
|
+
const marked = await markerInCardContainer(found.map((f) => f.element), runtime.marker, deadline).catch((error) => {
|
|
9363
|
+
throw error instanceof Unresponsive ? new Error(`test mode could not be checked: ${UNREADABLE_FRAME}`) : error;
|
|
9364
|
+
});
|
|
9365
|
+
if (!marked) throw new Error("test mode not detected");
|
|
9366
|
+
}
|
|
9070
9367
|
recorder.holdRedaction();
|
|
9071
9368
|
const typed = typedValues(provider, card, identity);
|
|
9072
9369
|
for (const [index, field] of runtime.fields.entries()) {
|
|
9073
9370
|
try {
|
|
9074
|
-
await fillVerified(found[index].element, field, runtime.cardHost,
|
|
9371
|
+
await fillVerified(found[index].element, field, runtime.cardHost, valueOf2(field.kind, provider, card, identity), stepDeadline, typed);
|
|
9075
9372
|
} catch (error) {
|
|
9076
9373
|
throw new Error(`card field ${field.kind} could not be filled: ${reasonOf(error, typed)}`);
|
|
9077
9374
|
}
|
|
@@ -9086,38 +9383,51 @@ async function frameStillServed(element, cardHost, field) {
|
|
|
9086
9383
|
}
|
|
9087
9384
|
return frame;
|
|
9088
9385
|
}
|
|
9089
|
-
|
|
9090
|
-
async function fillVerified(element, field, cardHost, value, timeout, typed) {
|
|
9091
|
-
const deadline = Date.now() + timeout;
|
|
9386
|
+
async function fillVerified(element, field, cardHost, value, deadline, typed) {
|
|
9092
9387
|
const tryMs = () => Math.max(1, Math.min(FILL_TRY_MS, deadline - Date.now()));
|
|
9388
|
+
const readable = (work) => withinDeadline(work, deadline).catch((error) => {
|
|
9389
|
+
throw error instanceof Unresponsive ? new OwnReason(UNREADABLE_FRAME) : error;
|
|
9390
|
+
});
|
|
9093
9391
|
for (; ; ) {
|
|
9094
|
-
const frame = await frameStillServed(element, cardHost, field);
|
|
9392
|
+
const frame = await readable(frameStillServed(element, cardHost, field));
|
|
9095
9393
|
const checkedUrl = frame.url();
|
|
9096
9394
|
const inputs = frame.locator(field.input).filter({ visible: true });
|
|
9097
|
-
const count = await inputs.count();
|
|
9395
|
+
const count = await readable(inputs.count());
|
|
9098
9396
|
if (count === 1) {
|
|
9099
9397
|
let handle;
|
|
9100
9398
|
try {
|
|
9101
9399
|
handle = await inputs.elementHandle({ timeout: tryMs() });
|
|
9102
|
-
if ((await frameStillServed(element, cardHost, field)).url() !== checkedUrl) throw new OwnReason(GONE_FRAME);
|
|
9400
|
+
if ((await readable(frameStillServed(element, cardHost, field))).url() !== checkedUrl) throw new OwnReason(GONE_FRAME);
|
|
9103
9401
|
await handle.fill(value, { timeout: tryMs() });
|
|
9104
9402
|
return;
|
|
9105
9403
|
} catch (error) {
|
|
9106
9404
|
const timedOut = error instanceof Error && error.name === "TimeoutError";
|
|
9107
9405
|
if (error instanceof OwnReason) throw error;
|
|
9108
9406
|
if (timedOut && Date.now() < deadline) continue;
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9407
|
+
try {
|
|
9408
|
+
const moved = (await withinDeadline(frameStillServed(element, cardHost, field), deadline)).url() !== checkedUrl;
|
|
9409
|
+
const attached = handle ? await withinDeadline(handle.evaluate((e) => e.isConnected), deadline).catch((e) => {
|
|
9410
|
+
if (e instanceof Unresponsive) throw e;
|
|
9411
|
+
return false;
|
|
9412
|
+
}) : true;
|
|
9413
|
+
if (moved || !attached) throw new OwnReason(GONE_FRAME);
|
|
9414
|
+
} catch (check) {
|
|
9415
|
+
if (check instanceof Unresponsive) throw error;
|
|
9416
|
+
throw check;
|
|
9417
|
+
}
|
|
9112
9418
|
throw error;
|
|
9113
9419
|
}
|
|
9114
9420
|
}
|
|
9115
9421
|
if (Date.now() >= deadline) {
|
|
9116
|
-
const
|
|
9117
|
-
|
|
9118
|
-
|
|
9119
|
-
|
|
9120
|
-
|
|
9422
|
+
const unreadable2 = new OwnReason(`${count} visible inputs match in ${pathOf2(checkedUrl)}: inputs not readable`);
|
|
9423
|
+
const settle = async () => {
|
|
9424
|
+
const current = await frameStillServed(element, cardHost, field).catch(() => void 0);
|
|
9425
|
+
if (!current || current.url() !== checkedUrl) throw new OwnReason(GONE_FRAME);
|
|
9426
|
+
const reason = await countReason(current, pathOf2(checkedUrl), count, typed);
|
|
9427
|
+
if ((await frameStillServed(element, cardHost, field)).url() !== checkedUrl) throw new OwnReason(GONE_FRAME);
|
|
9428
|
+
throw new OwnReason(reason);
|
|
9429
|
+
};
|
|
9430
|
+
throw await withinDeadline(settle(), deadline).catch((error) => error instanceof Unresponsive ? unreadable2 : error);
|
|
9121
9431
|
}
|
|
9122
9432
|
await new Promise((resolve5) => setTimeout(resolve5, 100));
|
|
9123
9433
|
}
|
|
@@ -9388,13 +9698,48 @@ async function evaluateGuarded(page2, script) {
|
|
|
9388
9698
|
if (blocked || changed.length > 0) throw new Error(`the script set a card or password field. ${HANDOFF_REQUIRED}`);
|
|
9389
9699
|
if (scriptError) throw scriptError;
|
|
9390
9700
|
}
|
|
9701
|
+
var clickedForms = /* @__PURE__ */ new WeakMap();
|
|
9702
|
+
var REMEMBER_FORM_MS = 1e3;
|
|
9703
|
+
async function rememberClickedForm(recorder, target) {
|
|
9704
|
+
clickedForms.get(recorder)?.dispose().catch(() => void 0);
|
|
9705
|
+
clickedForms.delete(recorder);
|
|
9706
|
+
let timer;
|
|
9707
|
+
let expired = false;
|
|
9708
|
+
try {
|
|
9709
|
+
const work = target.evaluateHandle(
|
|
9710
|
+
(el) => {
|
|
9711
|
+
const control = el.closest("button, input[type=submit], input[type=image]");
|
|
9712
|
+
const submits = control instanceof HTMLButtonElement && control.type === "submit" || control instanceof HTMLInputElement && (control.type === "submit" || control.type === "image");
|
|
9713
|
+
return submits ? control.form : null;
|
|
9714
|
+
},
|
|
9715
|
+
void 0,
|
|
9716
|
+
{ timeout: REMEMBER_FORM_MS }
|
|
9717
|
+
);
|
|
9718
|
+
work.then(
|
|
9719
|
+
(late) => {
|
|
9720
|
+
if (expired) late.dispose().catch(() => void 0);
|
|
9721
|
+
},
|
|
9722
|
+
() => void 0
|
|
9723
|
+
);
|
|
9724
|
+
const limit = new Promise((_, reject) => {
|
|
9725
|
+
timer = setTimeout(() => reject(new Error("form lookup timed out")), REMEMBER_FORM_MS + 500);
|
|
9726
|
+
});
|
|
9727
|
+
const handle = await Promise.race([work, limit]);
|
|
9728
|
+
if (handle.asElement() !== null) clickedForms.set(recorder, handle);
|
|
9729
|
+
else await handle.dispose();
|
|
9730
|
+
} catch {
|
|
9731
|
+
expired = true;
|
|
9732
|
+
} finally {
|
|
9733
|
+
clearTimeout(timer);
|
|
9734
|
+
}
|
|
9735
|
+
}
|
|
9391
9736
|
async function waitForUrl(recorder, url, timeout) {
|
|
9392
9737
|
const condition = { url };
|
|
9393
9738
|
const deadline = Date.now() + timeout;
|
|
9394
9739
|
while (!await conditionHolds(recorder.context, condition)) {
|
|
9395
9740
|
if (Date.now() >= deadline) {
|
|
9396
9741
|
const message = `page did not reach ${describeCondition(condition)} within ${formatDuration(timeout)}`;
|
|
9397
|
-
const blocking = await blockingControls(recorder.context);
|
|
9742
|
+
const blocking = await blockingControls(recorder.context, clickedForms.get(recorder) ?? null);
|
|
9398
9743
|
throw new Error(blocking.length === 0 ? message : `${message}. Blocking controls: ${blocking.join(", ")}.`);
|
|
9399
9744
|
}
|
|
9400
9745
|
await recorder.wait(100);
|
|
@@ -9418,6 +9763,7 @@ async function runStep(step, recorder, scenario, identity, options, record) {
|
|
|
9418
9763
|
case "click": {
|
|
9419
9764
|
const deadline = Date.now() + timeout;
|
|
9420
9765
|
const target = await locate(page2, recorder, step.value, record, timeout);
|
|
9766
|
+
await rememberClickedForm(recorder, target);
|
|
9421
9767
|
await withControlList(page2, recorder, step.value, () => target.click({ timeout: remaining(deadline) }));
|
|
9422
9768
|
return;
|
|
9423
9769
|
}
|
|
@@ -9564,13 +9910,106 @@ async function recordScenario(options) {
|
|
|
9564
9910
|
return result;
|
|
9565
9911
|
}
|
|
9566
9912
|
|
|
9913
|
+
// packages/recorder/src/gtm-templates/tpl.ts
|
|
9914
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
9915
|
+
var PACKAGE_TEMPLATE_FILE = "tagreeve-tag-reporter.tpl";
|
|
9916
|
+
function readWebTagReporterTemplate() {
|
|
9917
|
+
const places = [
|
|
9918
|
+
new URL(`./templates/${PACKAGE_TEMPLATE_FILE}`, import.meta.url),
|
|
9919
|
+
new URL("./web-tag-reporter.tpl", import.meta.url)
|
|
9920
|
+
];
|
|
9921
|
+
for (const place of places) {
|
|
9922
|
+
try {
|
|
9923
|
+
return readFileSync4(place, "utf8");
|
|
9924
|
+
} catch (error) {
|
|
9925
|
+
if (error.code !== "ENOENT") throw error;
|
|
9926
|
+
}
|
|
9927
|
+
}
|
|
9928
|
+
throw new Error("The web tag reporter template is missing from this install.");
|
|
9929
|
+
}
|
|
9930
|
+
|
|
9567
9931
|
// packages/cli/src/args.ts
|
|
9568
9932
|
import { parseArgs } from "node:util";
|
|
9569
9933
|
|
|
9570
9934
|
// packages/cli/src/out-dir.ts
|
|
9571
|
-
import { readdir } from "node:fs/promises";
|
|
9935
|
+
import { readdir as readdir2 } from "node:fs/promises";
|
|
9572
9936
|
import { join as join6 } from "node:path";
|
|
9573
|
-
|
|
9937
|
+
|
|
9938
|
+
// packages/cli/src/defaults.ts
|
|
9939
|
+
import { readdir, stat } from "node:fs/promises";
|
|
9940
|
+
var DEFAULT_CONFIG = "tagreeve/config.yml";
|
|
9941
|
+
var DEFAULT_RUNS = "tagreeve/runs";
|
|
9942
|
+
var DEFAULT_SCENARIOS = "tagreeve/scenarios";
|
|
9943
|
+
var DEFAULT_TRACKER_LIST = "tagreeve/trackers.json";
|
|
9944
|
+
var DEFAULT_AUTOCONSENT_DIR = "tagreeve/autoconsent";
|
|
9945
|
+
var DEFAULT_STORES = "tagreeve/stores.json";
|
|
9946
|
+
var DEFAULT_BASELINES = "tagreeve/baselines";
|
|
9947
|
+
var SETTING_TEXT = {
|
|
9948
|
+
config: "project config",
|
|
9949
|
+
scenarios: "scenario folder",
|
|
9950
|
+
trackerList: "tracker list",
|
|
9951
|
+
autoconsentRules: "autoconsent rules",
|
|
9952
|
+
stores: "stores",
|
|
9953
|
+
baseline: "baseline"
|
|
9954
|
+
};
|
|
9955
|
+
function isAbsent(error) {
|
|
9956
|
+
const code = error.code;
|
|
9957
|
+
return code === "ENOENT" || code === "ENOTDIR";
|
|
9958
|
+
}
|
|
9959
|
+
function unreadable(path, error) {
|
|
9960
|
+
const code = error.code;
|
|
9961
|
+
return new Error(`Cannot read ${path}${typeof code === "string" ? ` (${code})` : ""}. Fix its permissions or remove it.`);
|
|
9962
|
+
}
|
|
9963
|
+
async function isKind(path, kind) {
|
|
9964
|
+
try {
|
|
9965
|
+
const info = await stat(path);
|
|
9966
|
+
return kind === "file" ? info.isFile() : info.isDirectory();
|
|
9967
|
+
} catch (error) {
|
|
9968
|
+
if (isAbsent(error)) return false;
|
|
9969
|
+
throw unreadable(path, error);
|
|
9970
|
+
}
|
|
9971
|
+
}
|
|
9972
|
+
async function defaultScenarioDir(used) {
|
|
9973
|
+
if (!await isKind(DEFAULT_SCENARIOS, "directory")) return void 0;
|
|
9974
|
+
used.push({ setting: "scenarios", path: DEFAULT_SCENARIOS });
|
|
9975
|
+
return DEFAULT_SCENARIOS;
|
|
9976
|
+
}
|
|
9977
|
+
async function resolveTrackerList(flag2, used) {
|
|
9978
|
+
if (flag2 !== void 0) return flag2;
|
|
9979
|
+
if (!await isKind(DEFAULT_TRACKER_LIST, "file")) return void 0;
|
|
9980
|
+
used.push({ setting: "trackerList", path: DEFAULT_TRACKER_LIST });
|
|
9981
|
+
return DEFAULT_TRACKER_LIST;
|
|
9982
|
+
}
|
|
9983
|
+
async function resolveAutoconsentRules(flags2, used) {
|
|
9984
|
+
if (flags2?.length) return flags2;
|
|
9985
|
+
let names;
|
|
9986
|
+
try {
|
|
9987
|
+
names = (await readdir(DEFAULT_AUTOCONSENT_DIR)).filter((name) => name.endsWith(".json")).sort();
|
|
9988
|
+
} catch (error) {
|
|
9989
|
+
if (isAbsent(error)) return [];
|
|
9990
|
+
throw unreadable(DEFAULT_AUTOCONSENT_DIR, error);
|
|
9991
|
+
}
|
|
9992
|
+
const paths = [];
|
|
9993
|
+
for (const name of names) {
|
|
9994
|
+
const path = `${DEFAULT_AUTOCONSENT_DIR}/${name}`;
|
|
9995
|
+
if (await isKind(path, "file")) paths.push(path);
|
|
9996
|
+
}
|
|
9997
|
+
for (const path of paths) used.push({ setting: "autoconsentRules", path });
|
|
9998
|
+
return paths;
|
|
9999
|
+
}
|
|
10000
|
+
async function defaultStores(used) {
|
|
10001
|
+
if (!await isKind(DEFAULT_STORES, "file")) return void 0;
|
|
10002
|
+
used.push({ setting: "stores", path: DEFAULT_STORES });
|
|
10003
|
+
return DEFAULT_STORES;
|
|
10004
|
+
}
|
|
10005
|
+
function formatDefaultsLine(defaults) {
|
|
10006
|
+
if (!defaults?.length) return void 0;
|
|
10007
|
+
const ordered = [...defaults.filter((d) => d.setting === "config"), ...defaults.filter((d) => d.setting !== "config")];
|
|
10008
|
+
return `Defaults: ${ordered.map((d) => `${d.path} (${SETTING_TEXT[d.setting]})`).join(", ")}`;
|
|
10009
|
+
}
|
|
10010
|
+
|
|
10011
|
+
// packages/cli/src/out-dir.ts
|
|
10012
|
+
function resolveOutDir({ out, now, label, base: base2 = DEFAULT_RUNS }) {
|
|
9574
10013
|
if (out !== void 0) return out;
|
|
9575
10014
|
const pad = (n) => String(n).padStart(2, "0");
|
|
9576
10015
|
const date = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
@@ -9584,12 +10023,18 @@ function oldRunsNoticeText(folder) {
|
|
|
9584
10023
|
async function oldRunsNotice(cwd, folder) {
|
|
9585
10024
|
let names;
|
|
9586
10025
|
try {
|
|
9587
|
-
names = await
|
|
10026
|
+
names = await readdir2(join6(cwd, "runs"));
|
|
9588
10027
|
} catch {
|
|
9589
10028
|
return void 0;
|
|
9590
10029
|
}
|
|
9591
10030
|
return names.some((n) => /^run_.*\.jsonl$/.test(n) || n.startsWith("suite_")) ? oldRunsNoticeText(folder) : void 0;
|
|
9592
10031
|
}
|
|
10032
|
+
async function resolveRunFolder(input, cwd = process.cwd()) {
|
|
10033
|
+
const folder = resolveOutDir(input);
|
|
10034
|
+
const isDefault = input.out === void 0 && input.base === void 0;
|
|
10035
|
+
const notice = isDefault ? await oldRunsNotice(cwd, folder) : void 0;
|
|
10036
|
+
return { folder, isDefault, ...notice && { notice } };
|
|
10037
|
+
}
|
|
9593
10038
|
|
|
9594
10039
|
// packages/cli/src/args.ts
|
|
9595
10040
|
var UsageError = class extends Error {
|
|
@@ -10035,15 +10480,16 @@ function flagChangeLabel(f) {
|
|
|
10035
10480
|
return `${f.host ? `${f.kind} ${f.host}` : f.kind}: ${f.a} -> ${f.b}`;
|
|
10036
10481
|
}
|
|
10037
10482
|
function describePushDiff(d) {
|
|
10483
|
+
const named = (r) => r.renamedFrom === void 0 ? r.event : `${r.event} (renamed from ${r.renamedFrom})`;
|
|
10038
10484
|
const at = (r) => `[epoch ${r.epoch}, frame ${r.frame}${r.kind === void 0 ? "" : `, kind ${r.kind}`}]`;
|
|
10039
10485
|
return [
|
|
10040
10486
|
...d.eventsRemoved.map((r) => `removed event ${r.event} ${at(r)}`),
|
|
10041
10487
|
...d.eventsAdded.map((r) => `new event ${r.event} ${at(r)}`),
|
|
10042
|
-
...d.pathsRemoved.map((p) => `missing path ${p.path} (${p.types.join("|")}) in ${p
|
|
10043
|
-
...d.pathsAdded.map((p) => `new path ${p.path} (${p.types.join("|")}) in ${p
|
|
10044
|
-
...d.typeChanges.map((p) => `type change ${p.path}: ${p.a.join("|")} -> ${p.b.join("|")} in ${p
|
|
10488
|
+
...d.pathsRemoved.map((p) => `missing path ${p.path} (${p.types.join("|")}) in ${named(p)} ${at(p)}`),
|
|
10489
|
+
...d.pathsAdded.map((p) => `new path ${p.path} (${p.types.join("|")}) in ${named(p)} ${at(p)}`),
|
|
10490
|
+
...d.typeChanges.map((p) => `type change ${p.path}: ${p.a.join("|")} -> ${p.b.join("|")} in ${named(p)} ${at(p)}`),
|
|
10045
10491
|
...d.moved.map(
|
|
10046
|
-
(m) => m.kind === "frame" ? `moved event ${m
|
|
10492
|
+
(m) => m.kind === "frame" ? `moved event ${named(m)} from frame ${m.from} to ${m.to} [epoch ${m.epoch}]` : `moved event ${named(m)} from epoch ${m.from} to ${m.to} [frame ${m.frame}]`
|
|
10047
10493
|
)
|
|
10048
10494
|
];
|
|
10049
10495
|
}
|
|
@@ -10113,75 +10559,6 @@ async function diffCommand(args, io) {
|
|
|
10113
10559
|
return 0;
|
|
10114
10560
|
}
|
|
10115
10561
|
|
|
10116
|
-
// packages/cli/src/defaults.ts
|
|
10117
|
-
import { readdir as readdir2, stat } from "node:fs/promises";
|
|
10118
|
-
var DEFAULT_SCENARIOS = "tagreeve/scenarios";
|
|
10119
|
-
var DEFAULT_TRACKER_LIST = "tagreeve/trackers.json";
|
|
10120
|
-
var DEFAULT_AUTOCONSENT_DIR = "tagreeve/autoconsent";
|
|
10121
|
-
var DEFAULT_STORES = "tagreeve/stores.json";
|
|
10122
|
-
var DEFAULT_BASELINES = "tagreeve/baselines";
|
|
10123
|
-
var SETTING_TEXT = {
|
|
10124
|
-
scenarios: "scenario folder",
|
|
10125
|
-
trackerList: "tracker list",
|
|
10126
|
-
autoconsentRules: "autoconsent rules",
|
|
10127
|
-
stores: "stores",
|
|
10128
|
-
baseline: "baseline"
|
|
10129
|
-
};
|
|
10130
|
-
function isAbsent(error) {
|
|
10131
|
-
const code = error.code;
|
|
10132
|
-
return code === "ENOENT" || code === "ENOTDIR";
|
|
10133
|
-
}
|
|
10134
|
-
function unreadable(path, error) {
|
|
10135
|
-
const code = error.code;
|
|
10136
|
-
return new Error(`Cannot read ${path}${typeof code === "string" ? ` (${code})` : ""}. Fix its permissions or remove it.`);
|
|
10137
|
-
}
|
|
10138
|
-
async function isKind(path, kind) {
|
|
10139
|
-
try {
|
|
10140
|
-
const info = await stat(path);
|
|
10141
|
-
return kind === "file" ? info.isFile() : info.isDirectory();
|
|
10142
|
-
} catch (error) {
|
|
10143
|
-
if (isAbsent(error)) return false;
|
|
10144
|
-
throw unreadable(path, error);
|
|
10145
|
-
}
|
|
10146
|
-
}
|
|
10147
|
-
async function defaultScenarioDir(used) {
|
|
10148
|
-
if (!await isKind(DEFAULT_SCENARIOS, "directory")) return void 0;
|
|
10149
|
-
used.push({ setting: "scenarios", path: DEFAULT_SCENARIOS });
|
|
10150
|
-
return DEFAULT_SCENARIOS;
|
|
10151
|
-
}
|
|
10152
|
-
async function resolveTrackerList(flag2, used) {
|
|
10153
|
-
if (flag2 !== void 0) return flag2;
|
|
10154
|
-
if (!await isKind(DEFAULT_TRACKER_LIST, "file")) return void 0;
|
|
10155
|
-
used.push({ setting: "trackerList", path: DEFAULT_TRACKER_LIST });
|
|
10156
|
-
return DEFAULT_TRACKER_LIST;
|
|
10157
|
-
}
|
|
10158
|
-
async function resolveAutoconsentRules(flags2, used) {
|
|
10159
|
-
if (flags2?.length) return flags2;
|
|
10160
|
-
let names;
|
|
10161
|
-
try {
|
|
10162
|
-
names = (await readdir2(DEFAULT_AUTOCONSENT_DIR)).filter((name) => name.endsWith(".json")).sort();
|
|
10163
|
-
} catch (error) {
|
|
10164
|
-
if (isAbsent(error)) return [];
|
|
10165
|
-
throw unreadable(DEFAULT_AUTOCONSENT_DIR, error);
|
|
10166
|
-
}
|
|
10167
|
-
const paths = [];
|
|
10168
|
-
for (const name of names) {
|
|
10169
|
-
const path = `${DEFAULT_AUTOCONSENT_DIR}/${name}`;
|
|
10170
|
-
if (await isKind(path, "file")) paths.push(path);
|
|
10171
|
-
}
|
|
10172
|
-
for (const path of paths) used.push({ setting: "autoconsentRules", path });
|
|
10173
|
-
return paths;
|
|
10174
|
-
}
|
|
10175
|
-
async function defaultStores(used) {
|
|
10176
|
-
if (!await isKind(DEFAULT_STORES, "file")) return void 0;
|
|
10177
|
-
used.push({ setting: "stores", path: DEFAULT_STORES });
|
|
10178
|
-
return DEFAULT_STORES;
|
|
10179
|
-
}
|
|
10180
|
-
function formatDefaultsLine(defaults) {
|
|
10181
|
-
if (!defaults?.length) return void 0;
|
|
10182
|
-
return `Defaults: ${defaults.map((d) => `${d.path} (${SETTING_TEXT[d.setting]})`).join(", ")}`;
|
|
10183
|
-
}
|
|
10184
|
-
|
|
10185
10562
|
// packages/cli/src/stores.ts
|
|
10186
10563
|
import { constants } from "node:fs";
|
|
10187
10564
|
import { access, readFile as readFile3, stat as stat2 } from "node:fs/promises";
|
|
@@ -10300,9 +10677,11 @@ function validKey(k) {
|
|
|
10300
10677
|
(t) => isRecord2(t) && isRecord2(t.consent) && Object.values(t.consent).every((v) => typeof v === "string") && isStringArray(t.ids) && Number.isInteger(t.count) && t.count >= 1
|
|
10301
10678
|
);
|
|
10302
10679
|
}
|
|
10303
|
-
var FRAME_KINDS = /* @__PURE__ */ new Set(["main", "embedded", "unknown"]);
|
|
10304
10680
|
function validPushGroup(g) {
|
|
10305
|
-
return isRecord2(g) && typeof g.epoch === "string" && typeof g.event === "string" && (g.kind === void 0 || g.kind === "gtag" || g.kind === "object") && typeof g.frame === "string" &&
|
|
10681
|
+
return isRecord2(g) && typeof g.epoch === "string" && typeof g.event === "string" && (g.kind === void 0 || g.kind === "gtag" || g.kind === "object") && typeof g.frame === "string" && PUSH_FRAME_KINDS.includes(g.frame) && Array.isArray(g.paths) && g.paths.every((p) => isRecord2(p) && typeof p.path === "string" && isStringArray(p.types));
|
|
10682
|
+
}
|
|
10683
|
+
function uniformKinds(groups) {
|
|
10684
|
+
return groups.every((g) => g.kind === void 0 === (groups[0].kind === void 0));
|
|
10306
10685
|
}
|
|
10307
10686
|
function parseBaseline(text2, label) {
|
|
10308
10687
|
let json;
|
|
@@ -10319,18 +10698,19 @@ function parseBaseline(text2, label) {
|
|
|
10319
10698
|
if (typeof json.scenario !== "string" || typeof json.site !== "string" || typeof json.byPage !== "boolean" || !Array.isArray(json.keys) || !json.keys.every(validKey)) {
|
|
10320
10699
|
throw new BaselineError(`${label} is not a valid baseline file`, "invalid");
|
|
10321
10700
|
}
|
|
10322
|
-
if (json.dataLayer !== void 0 && !(Array.isArray(json.dataLayer) && json.dataLayer.every(validPushGroup))) {
|
|
10701
|
+
if (json.dataLayer !== void 0 && !(Array.isArray(json.dataLayer) && json.dataLayer.every(validPushGroup) && uniformKinds(json.dataLayer))) {
|
|
10323
10702
|
throw new BaselineError(`${label} has an invalid dataLayer section`, "invalid");
|
|
10324
10703
|
}
|
|
10325
10704
|
return json;
|
|
10326
10705
|
}
|
|
10706
|
+
var errnoCode = (error) => error.code ?? "unknown error";
|
|
10327
10707
|
async function readBaseline(path) {
|
|
10328
10708
|
let text2;
|
|
10329
10709
|
try {
|
|
10330
10710
|
text2 = await readFile4(path, "utf8");
|
|
10331
10711
|
} catch (error) {
|
|
10332
|
-
const code = error
|
|
10333
|
-
throw new BaselineError(`Cannot read ${path}: ${code
|
|
10712
|
+
const code = errnoCode(error);
|
|
10713
|
+
throw new BaselineError(`Cannot read ${path}: ${code}`, code === "ENOENT" ? "missing" : "unreadable");
|
|
10334
10714
|
}
|
|
10335
10715
|
return parseBaseline(text2, path);
|
|
10336
10716
|
}
|
|
@@ -10365,11 +10745,10 @@ function defaultBaselineName(run) {
|
|
|
10365
10745
|
}
|
|
10366
10746
|
const unsafe = (part) => /[/\\\0]/.test(part) || part.includes("..") || part.startsWith(".");
|
|
10367
10747
|
const name = scenarioName(run.scenario);
|
|
10368
|
-
const bad2 = !name || unsafe(name) ? "scenario" : unsafe(run.store ?? "") || run.store !== void 0 && !STORE_NAME.test(run.store) ? "store" : unsafe(run.variant ?? "") || run.variant !== void 0 && !
|
|
10748
|
+
const bad2 = !name || unsafe(name) ? "scenario" : unsafe(run.store ?? "") || run.store !== void 0 && !STORE_NAME.test(run.store) ? "store" : unsafe(run.variant ?? "") || run.variant !== void 0 && !VARIANT_NAME.test(run.variant) ? "variant" : void 0;
|
|
10369
10749
|
if (bad2) throw new BaselineError(`The ${bad2} in this record cannot name a baseline file. Give the baseline path.`, "usage");
|
|
10370
10750
|
return baselineFileName(run.scenario, run.store, run.variant);
|
|
10371
10751
|
}
|
|
10372
|
-
var VARIANT_NAME2 = /^[a-z0-9][a-z0-9_-]*$/;
|
|
10373
10752
|
function insideBaselines(path) {
|
|
10374
10753
|
const rel = relative(resolve2(DEFAULT_BASELINES), resolve2(path));
|
|
10375
10754
|
return rel !== "" && !rel.startsWith("..") && !isAbsolute2(rel);
|
|
@@ -10385,12 +10764,13 @@ function compareBaseline(baseline, records) {
|
|
|
10385
10764
|
const diff = diffShapes(baseline.keys, hitShape(records, { byPage: baseline.byPage }), { epochOrder: epochOrder2 });
|
|
10386
10765
|
warnings.push(...diff.moved.map(describeMove));
|
|
10387
10766
|
if (baseline.dataLayer === void 0) {
|
|
10388
|
-
warnings.push("dataLayer pushes not compared: the baseline has no push shapes (saved
|
|
10767
|
+
warnings.push("dataLayer pushes not compared: the baseline has no push shapes (saved before 0.6.0-rc.2). Save it again to compare them.");
|
|
10389
10768
|
} else {
|
|
10390
|
-
const
|
|
10769
|
+
const current = pushGroups(records);
|
|
10770
|
+
const pushes = diffPushes(baseline.dataLayer, current, { epochOrder: epochOrder2 });
|
|
10391
10771
|
warnings.push(...describePushDiff(pushes).map((line) => `dataLayer ${line}`));
|
|
10392
|
-
warnings.push(...pushes.kindChanged.map((k) => `dataLayer
|
|
10393
|
-
if (baseline.dataLayer
|
|
10772
|
+
warnings.push(...pushes.kindChanged.map((k) => `dataLayer ${kindChangeWarning(k)}`));
|
|
10773
|
+
if (kindsMerged(baseline.dataLayer, current)) {
|
|
10394
10774
|
warnings.push("dataLayer push kinds not compared: the baseline was saved by 0.6.0-rc.2. Save it again to compare them.");
|
|
10395
10775
|
}
|
|
10396
10776
|
}
|
|
@@ -10403,7 +10783,6 @@ function compareBaseline(baseline, records) {
|
|
|
10403
10783
|
changes: describeDiff(diff)
|
|
10404
10784
|
};
|
|
10405
10785
|
}
|
|
10406
|
-
var errnoCode = (error) => error.code ?? "unknown error";
|
|
10407
10786
|
async function baselineCommand(args, io) {
|
|
10408
10787
|
let records;
|
|
10409
10788
|
try {
|
|
@@ -10446,8 +10825,8 @@ async function baselineCommand(args, io) {
|
|
|
10446
10825
|
}
|
|
10447
10826
|
|
|
10448
10827
|
// packages/cli/src/init.ts
|
|
10449
|
-
import { appendFile, mkdir as mkdir3, readFile as readFile5, stat as stat4, writeFile as writeFile3 } from "node:fs/promises";
|
|
10450
|
-
import { join as join9 } from "node:path";
|
|
10828
|
+
import { appendFile, lstat, mkdir as mkdir3, readFile as readFile5, stat as stat4, writeFile as writeFile3 } from "node:fs/promises";
|
|
10829
|
+
import { dirname as dirname5, join as join9 } from "node:path";
|
|
10451
10830
|
|
|
10452
10831
|
// packages/cli/src/git-ignore.ts
|
|
10453
10832
|
import { execFile as execFile2 } from "node:child_process";
|
|
@@ -10494,23 +10873,24 @@ async function warnIfNotIgnored(folder, stderr) {
|
|
|
10494
10873
|
}
|
|
10495
10874
|
|
|
10496
10875
|
// packages/cli/src/init.ts
|
|
10497
|
-
var IGNORE_LINE =
|
|
10498
|
-
var FOLDERS = [
|
|
10499
|
-
var CONFIG = "tagreeve/config.yml";
|
|
10876
|
+
var IGNORE_LINE = `/${DEFAULT_RUNS}/`;
|
|
10877
|
+
var FOLDERS = [DEFAULT_SCENARIOS, DEFAULT_BASELINES];
|
|
10500
10878
|
var STARTER_CONFIG = `configSchemaVersion: 1
|
|
10501
10879
|
# Allowed keys: site, out, options. See docs/cli.md, "Project config".
|
|
10502
10880
|
# site:
|
|
10503
10881
|
# out:
|
|
10504
10882
|
# options:
|
|
10505
10883
|
`;
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10509
|
-
return true;
|
|
10510
|
-
} catch {
|
|
10511
|
-
return false;
|
|
10884
|
+
var NotAFolder = class extends Error {
|
|
10885
|
+
constructor() {
|
|
10886
|
+
super("not a folder");
|
|
10512
10887
|
}
|
|
10513
|
-
}
|
|
10888
|
+
};
|
|
10889
|
+
var NotAFile = class extends Error {
|
|
10890
|
+
constructor() {
|
|
10891
|
+
super("not a file");
|
|
10892
|
+
}
|
|
10893
|
+
};
|
|
10514
10894
|
async function ensureIgnoreLine(cwd) {
|
|
10515
10895
|
const file = join9(cwd, ".gitignore");
|
|
10516
10896
|
let current;
|
|
@@ -10520,7 +10900,7 @@ async function ensureIgnoreLine(cwd) {
|
|
|
10520
10900
|
current = void 0;
|
|
10521
10901
|
}
|
|
10522
10902
|
if (current?.split(/\r?\n/).some((line) => line.trim() === IGNORE_LINE)) return { path: ".gitignore", action: "skipped", text: `Skipped .gitignore: it already has ${IGNORE_LINE}` };
|
|
10523
|
-
if (await gitIgnoreStatus(join9(cwd,
|
|
10903
|
+
if (await gitIgnoreStatus(join9(cwd, DEFAULT_RUNS), { probe: "folder" }) === "ignored") return { path: ".gitignore", action: "skipped", text: `Skipped .gitignore: git already ignores ${DEFAULT_RUNS}/` };
|
|
10524
10904
|
const prefix = current === void 0 || current === "" || current.endsWith("\n") ? "" : "\n";
|
|
10525
10905
|
await appendFile(file, `${prefix}${IGNORE_LINE}
|
|
10526
10906
|
`);
|
|
@@ -10528,20 +10908,42 @@ async function ensureIgnoreLine(cwd) {
|
|
|
10528
10908
|
}
|
|
10529
10909
|
async function ensureFolder(cwd, folder) {
|
|
10530
10910
|
const found = await stat4(join9(cwd, folder)).catch(() => void 0);
|
|
10531
|
-
if (found && !found.isDirectory()) throw
|
|
10911
|
+
if (found && !found.isDirectory()) throw new NotAFolder();
|
|
10532
10912
|
if (found) return { path: `${folder}/`, action: "skipped", text: `Skipped ${folder}/: it exists` };
|
|
10533
10913
|
await mkdir3(join9(cwd, folder), { recursive: true });
|
|
10534
10914
|
return { path: `${folder}/`, action: "created", text: `Created ${folder}/` };
|
|
10535
10915
|
}
|
|
10536
10916
|
async function ensureConfig(cwd) {
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
|
|
10540
|
-
|
|
10917
|
+
const found = await stat4(join9(cwd, DEFAULT_CONFIG)).catch(() => void 0);
|
|
10918
|
+
if (found && !found.isFile()) throw new NotAFile();
|
|
10919
|
+
if (found) return { path: DEFAULT_CONFIG, action: "skipped", text: `Skipped ${DEFAULT_CONFIG}: it exists` };
|
|
10920
|
+
await mkdir3(dirname5(join9(cwd, DEFAULT_CONFIG)), { recursive: true });
|
|
10921
|
+
await writeFile3(join9(cwd, DEFAULT_CONFIG), STARTER_CONFIG, { flag: "wx" });
|
|
10922
|
+
return { path: DEFAULT_CONFIG, action: "created", text: `Created ${DEFAULT_CONFIG}` };
|
|
10923
|
+
}
|
|
10924
|
+
async function probe(path) {
|
|
10925
|
+
try {
|
|
10926
|
+
return await stat4(path);
|
|
10927
|
+
} catch {
|
|
10928
|
+
return await lstat(path).then(() => true, () => false) ? "unresolvable" : "absent";
|
|
10929
|
+
}
|
|
10930
|
+
}
|
|
10931
|
+
async function checkTargets(cwd) {
|
|
10932
|
+
for (const folder of FOLDERS) {
|
|
10933
|
+
const found = await probe(join9(cwd, folder));
|
|
10934
|
+
if (found === "unresolvable" || found !== "absent" && !found.isDirectory()) return [`${folder}/`, new NotAFolder()];
|
|
10935
|
+
}
|
|
10936
|
+
const config = await probe(join9(cwd, DEFAULT_CONFIG));
|
|
10937
|
+
if (config === "unresolvable" || config !== "absent" && !config.isFile()) return [DEFAULT_CONFIG, new NotAFile()];
|
|
10938
|
+
const ignore = await probe(join9(cwd, ".gitignore"));
|
|
10939
|
+
if (ignore === "unresolvable" || ignore !== "absent" && !ignore.isFile()) return [".gitignore", Object.assign(new Error("in the way"), { code: "EISDIR" })];
|
|
10940
|
+
return void 0;
|
|
10541
10941
|
}
|
|
10542
10942
|
function failureText(path, error) {
|
|
10543
10943
|
const code = error?.code;
|
|
10544
|
-
if (
|
|
10944
|
+
if (error instanceof NotAFolder) return `${path.replace(/\/$/, "")} is not a folder
|
|
10945
|
+
`;
|
|
10946
|
+
if (error instanceof NotAFile) return `${path} is not a file
|
|
10545
10947
|
`;
|
|
10546
10948
|
const reason = code === "EACCES" || code === "EPERM" ? "permission denied" : code === "EEXIST" ? "it exists" : code === "ENOTDIR" || code === "EISDIR" ? "a file or folder is in the way" : "the write failed";
|
|
10547
10949
|
return `Could not write ${path}: ${reason}
|
|
@@ -10550,10 +10952,17 @@ function failureText(path, error) {
|
|
|
10550
10952
|
async function initCommand(io, json = false, cwd = process.cwd()) {
|
|
10551
10953
|
const steps = [
|
|
10552
10954
|
...FOLDERS.map((folder) => [`${folder}/`, () => ensureFolder(cwd, folder)]),
|
|
10553
|
-
[
|
|
10955
|
+
[DEFAULT_CONFIG, () => ensureConfig(cwd)],
|
|
10554
10956
|
[".gitignore", () => ensureIgnoreLine(cwd)]
|
|
10555
10957
|
];
|
|
10556
10958
|
const items = [];
|
|
10959
|
+
const blocked = await checkTargets(cwd);
|
|
10960
|
+
if (blocked) {
|
|
10961
|
+
if (json) io.stdout(`${JSON.stringify({ items })}
|
|
10962
|
+
`);
|
|
10963
|
+
io.stderr(failureText(blocked[0], blocked[1]));
|
|
10964
|
+
return 2;
|
|
10965
|
+
}
|
|
10557
10966
|
for (const [path, step] of steps) {
|
|
10558
10967
|
try {
|
|
10559
10968
|
const item = await step();
|
|
@@ -10573,22 +10982,6 @@ async function initCommand(io, json = false, cwd = process.cwd()) {
|
|
|
10573
10982
|
}
|
|
10574
10983
|
|
|
10575
10984
|
// packages/cli/src/template.ts
|
|
10576
|
-
import { readFileSync as readFileSync4 } from "node:fs";
|
|
10577
|
-
var WEB_TEMPLATE_FILE_NAME = "tagreeve-tag-reporter.tpl";
|
|
10578
|
-
var WEB_TEMPLATE_PATHS = [
|
|
10579
|
-
new URL(`./templates/${WEB_TEMPLATE_FILE_NAME}`, import.meta.url),
|
|
10580
|
-
new URL("../../recorder/src/gtm-templates/web-tag-reporter.tpl", import.meta.url)
|
|
10581
|
-
];
|
|
10582
|
-
function readWebTemplate() {
|
|
10583
|
-
for (const path of WEB_TEMPLATE_PATHS) {
|
|
10584
|
-
try {
|
|
10585
|
-
return readFileSync4(path, "utf8");
|
|
10586
|
-
} catch {
|
|
10587
|
-
continue;
|
|
10588
|
-
}
|
|
10589
|
-
}
|
|
10590
|
-
throw new Error("The web tag reporter template is missing from this install.");
|
|
10591
|
-
}
|
|
10592
10985
|
var WEB_STEPS = [
|
|
10593
10986
|
'In a GTM workspace, import the text in "template" as a custom tag template.',
|
|
10594
10987
|
'Add one tag of that type with the trigger in "setup.trigger" (a custom event trigger on the event name ".*" with regex matching on) and the consent setting in "setup.consent".',
|
|
@@ -10602,8 +10995,8 @@ function webTemplateJson() {
|
|
|
10602
10995
|
return {
|
|
10603
10996
|
templateVersion: 1,
|
|
10604
10997
|
name: "web",
|
|
10605
|
-
fileName:
|
|
10606
|
-
template:
|
|
10998
|
+
fileName: PACKAGE_TEMPLATE_FILE,
|
|
10999
|
+
template: readWebTagReporterTemplate(),
|
|
10607
11000
|
setup: {
|
|
10608
11001
|
trigger: { type: "customEvent", eventName: ".*", regex: true },
|
|
10609
11002
|
consent: "noAdditionalConsentRequired",
|
|
@@ -10615,16 +11008,16 @@ function webTemplateJson() {
|
|
|
10615
11008
|
}
|
|
10616
11009
|
function templateCommand(io, json) {
|
|
10617
11010
|
io.stdout(json ? `${JSON.stringify(webTemplateJson(), null, 2)}
|
|
10618
|
-
` :
|
|
11011
|
+
` : readWebTagReporterTemplate());
|
|
10619
11012
|
return 0;
|
|
10620
11013
|
}
|
|
10621
11014
|
|
|
10622
11015
|
// packages/cli/src/install-browser.ts
|
|
10623
11016
|
import { spawn as spawn2 } from "node:child_process";
|
|
10624
11017
|
import { createRequire as createRequire2 } from "node:module";
|
|
10625
|
-
import { dirname as
|
|
11018
|
+
import { dirname as dirname6, join as join10 } from "node:path";
|
|
10626
11019
|
function installBrowser() {
|
|
10627
|
-
const cli = join10(
|
|
11020
|
+
const cli = join10(dirname6(createRequire2(import.meta.url).resolve("playwright/package.json")), "cli.js");
|
|
10628
11021
|
return new Promise((resolve5, reject) => {
|
|
10629
11022
|
const child = spawn2(process.execPath, [cli, "install", "chromium"], { stdio: "inherit" });
|
|
10630
11023
|
child.on("error", reject);
|
|
@@ -10634,7 +11027,7 @@ function installBrowser() {
|
|
|
10634
11027
|
|
|
10635
11028
|
// packages/cli/src/report/index.ts
|
|
10636
11029
|
import { mkdir as mkdir5, stat as stat6, writeFile as writeFile6 } from "node:fs/promises";
|
|
10637
|
-
import { dirname as
|
|
11030
|
+
import { dirname as dirname7, join as join15, resolve as resolve4 } from "node:path";
|
|
10638
11031
|
|
|
10639
11032
|
// packages/cli/src/report/model.ts
|
|
10640
11033
|
var NOTE_TEXT = {
|
|
@@ -11176,44 +11569,8 @@ import { basename as basename3, join as join14 } from "node:path";
|
|
|
11176
11569
|
import { mkdir as mkdir4, readdir as readdir3, readFile as readFile9, writeFile as writeFile5 } from "node:fs/promises";
|
|
11177
11570
|
import { basename as basename2, extname, join as join13 } from "node:path";
|
|
11178
11571
|
|
|
11179
|
-
// packages/cli/src/project-config.ts
|
|
11180
|
-
import { readFile as readFile6 } from "node:fs/promises";
|
|
11181
|
-
var DEFAULT_CONFIG = "tagreeve/config.yml";
|
|
11182
|
-
var ProjectConfigLoadError = class extends Error {
|
|
11183
|
-
};
|
|
11184
|
-
async function loadProjectConfig(flag2) {
|
|
11185
|
-
const path = flag2 ?? DEFAULT_CONFIG;
|
|
11186
|
-
let text2;
|
|
11187
|
-
try {
|
|
11188
|
-
text2 = await readFile6(path, "utf8");
|
|
11189
|
-
} catch (error) {
|
|
11190
|
-
const code = error instanceof Error ? error.code : void 0;
|
|
11191
|
-
if (flag2 === void 0 && code === "ENOENT") return void 0;
|
|
11192
|
-
throw new ProjectConfigLoadError(`Cannot read ${path}: ${code ?? "unknown error"}`);
|
|
11193
|
-
}
|
|
11194
|
-
try {
|
|
11195
|
-
const config = parseProjectConfig(text2, path);
|
|
11196
|
-
return { path, config, ...flag2 === void 0 && { defaultUsed: { setting: "config", path: DEFAULT_CONFIG } } };
|
|
11197
|
-
} catch (error) {
|
|
11198
|
-
if (!(error instanceof ProjectConfigError)) throw error;
|
|
11199
|
-
throw new ProjectConfigLoadError(`${path} is not a valid project config:
|
|
11200
|
-
${error.issues.map((i) => ` ${i}`).join("\n")}`);
|
|
11201
|
-
}
|
|
11202
|
-
}
|
|
11203
|
-
function formatDefaults(defaults) {
|
|
11204
|
-
if (!defaults?.length) return void 0;
|
|
11205
|
-
const config = defaults.filter((d) => d.setting === "config");
|
|
11206
|
-
const rest = formatDefaultsLine(defaults.filter((d) => d.setting !== "config"))?.slice("Defaults: ".length);
|
|
11207
|
-
const parts = [...config.map((d) => `${d.path} (project config)`), ...rest ? [rest] : []];
|
|
11208
|
-
return `Defaults: ${parts.join(", ")}`;
|
|
11209
|
-
}
|
|
11210
|
-
function siteMissingMessage(config) {
|
|
11211
|
-
return config ? `--site is required. Give --site or set site in ${config.path}.` : "--site is required";
|
|
11212
|
-
}
|
|
11213
|
-
var ALLOW_TEST_PAYMENT_NEEDS_SITE = "--allow-test-payment needs --site on the command line. A site from the project config never supplies the host a test payment runs on.";
|
|
11214
|
-
|
|
11215
11572
|
// packages/cli/src/test-payment-hosts.ts
|
|
11216
|
-
import { readFile as
|
|
11573
|
+
import { readFile as readFile6, stat as stat5 } from "node:fs/promises";
|
|
11217
11574
|
import { homedir } from "node:os";
|
|
11218
11575
|
import { isAbsolute as isAbsolute3, join as join11 } from "node:path";
|
|
11219
11576
|
var FILE_NAME = "test-payment-hosts.json";
|
|
@@ -11257,7 +11614,7 @@ async function readTestPaymentHosts(path, loopbackHosted = loopbackIsHostedForTe
|
|
|
11257
11614
|
}
|
|
11258
11615
|
let json;
|
|
11259
11616
|
try {
|
|
11260
|
-
json = JSON.parse(await
|
|
11617
|
+
json = JSON.parse(await readFile6(path, "utf8"));
|
|
11261
11618
|
} catch {
|
|
11262
11619
|
throw new Error(`${path} is not valid JSON.`);
|
|
11263
11620
|
}
|
|
@@ -11296,6 +11653,34 @@ async function checkTestPaymentGates(parsed, site, allow, env = process.env) {
|
|
|
11296
11653
|
import { appendFile as appendFile2, readFile as readFile8, rename, writeFile as writeFile4 } from "node:fs/promises";
|
|
11297
11654
|
import { basename, join as join12 } from "node:path";
|
|
11298
11655
|
|
|
11656
|
+
// packages/cli/src/project-config.ts
|
|
11657
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
11658
|
+
var ProjectConfigLoadError = class extends Error {
|
|
11659
|
+
};
|
|
11660
|
+
async function loadProjectConfig(flag2) {
|
|
11661
|
+
const path = flag2 ?? DEFAULT_CONFIG;
|
|
11662
|
+
let text2;
|
|
11663
|
+
try {
|
|
11664
|
+
text2 = await readFile7(path, "utf8");
|
|
11665
|
+
} catch (error) {
|
|
11666
|
+
const code = error instanceof Error ? error.code : void 0;
|
|
11667
|
+
if (flag2 === void 0 && code === "ENOENT") return void 0;
|
|
11668
|
+
throw new ProjectConfigLoadError(`Cannot read ${path}: ${code ?? "unknown error"}`);
|
|
11669
|
+
}
|
|
11670
|
+
try {
|
|
11671
|
+
const config = parseProjectConfig(text2, path);
|
|
11672
|
+
return { path, config, ...flag2 === void 0 && { defaultUsed: { setting: "config", path: DEFAULT_CONFIG } } };
|
|
11673
|
+
} catch (error) {
|
|
11674
|
+
if (!(error instanceof ProjectConfigError)) throw error;
|
|
11675
|
+
throw new ProjectConfigLoadError(`${path} is not a valid project config:
|
|
11676
|
+
${error.issues.map((i) => ` ${i}`).join("\n")}`);
|
|
11677
|
+
}
|
|
11678
|
+
}
|
|
11679
|
+
function siteMissingMessage(config) {
|
|
11680
|
+
return config ? `--site is required. Give --site or set site in ${config.path}.` : "--site is required";
|
|
11681
|
+
}
|
|
11682
|
+
var ALLOW_TEST_PAYMENT_NEEDS_SITE = "--allow-test-payment needs --site on the command line. A site from the project config never supplies the host a test payment runs on.";
|
|
11683
|
+
|
|
11299
11684
|
// packages/cli/src/summary.ts
|
|
11300
11685
|
var EVIDENCE_CAP = 5;
|
|
11301
11686
|
var PATH_EXAMPLES = 3;
|
|
@@ -11323,7 +11708,7 @@ function testPaymentOf(records) {
|
|
|
11323
11708
|
function notExactCounts(hits) {
|
|
11324
11709
|
const out = {
|
|
11325
11710
|
eventId: { none: 0, noMatch: 0, several: 0 },
|
|
11326
|
-
clientId: { noClientId: 0, noSameKeyHit: 0, severalSameKeyHits: 0, answeredBefore: 0 }
|
|
11711
|
+
clientId: { noClientId: 0, noSameKeyHit: 0, severalSameKeyHits: 0, answeredBefore: 0, concurrentRequest: 0 }
|
|
11327
11712
|
};
|
|
11328
11713
|
for (const { linkMiss } of hits) {
|
|
11329
11714
|
if (!linkMiss) continue;
|
|
@@ -11353,8 +11738,7 @@ function buildSummary(records, results, path) {
|
|
|
11353
11738
|
const testPayment = testPaymentOf(records);
|
|
11354
11739
|
const serverContainer = serverContainerOf(records);
|
|
11355
11740
|
const dataLayer = pushShapes({ steps: records.steps, dataLayerEvents: records.dataLayerEvents ?? [] });
|
|
11356
|
-
const
|
|
11357
|
-
const tags = summarizeTags(records.tagReports ?? [], override ? { container: override.container, tags: override.expectedTags } : void 0);
|
|
11741
|
+
const tags = summarizeTags(records.tagReports ?? [], expectedTagsOf(records.run));
|
|
11358
11742
|
return {
|
|
11359
11743
|
runId: records.run.id,
|
|
11360
11744
|
...records.run.label !== void 0 && { label: records.run.label },
|
|
@@ -11390,11 +11774,16 @@ function formatFlags(flags2) {
|
|
|
11390
11774
|
const lines = [];
|
|
11391
11775
|
const groups = /* @__PURE__ */ new Map();
|
|
11392
11776
|
let realData = 0;
|
|
11777
|
+
let realDataPush = 0;
|
|
11393
11778
|
for (const f of flags2) {
|
|
11394
11779
|
if (f.kind === "possibleRealData") {
|
|
11395
11780
|
realData += 1;
|
|
11396
11781
|
continue;
|
|
11397
11782
|
}
|
|
11783
|
+
if (f.kind === "possibleRealDataPush") {
|
|
11784
|
+
realDataPush += 1;
|
|
11785
|
+
continue;
|
|
11786
|
+
}
|
|
11398
11787
|
if (f.kind === "platformHost" && platformOf(f)) continue;
|
|
11399
11788
|
const target = groupTarget(f);
|
|
11400
11789
|
if (!target) {
|
|
@@ -11414,13 +11803,14 @@ function formatFlags(flags2) {
|
|
|
11414
11803
|
lines.push(` ${kind}: ${host} x${count} (${shown2.join(", ")}${more > 0 ? ` and ${more} more` : ""})`);
|
|
11415
11804
|
}
|
|
11416
11805
|
if (realData > 0) lines.push(` possibleRealData: x${realData}`);
|
|
11806
|
+
if (realDataPush > 0) lines.push(` possibleRealDataPush: x${realDataPush}`);
|
|
11417
11807
|
lines.push(...platformHostLines(flags2));
|
|
11418
11808
|
return lines;
|
|
11419
11809
|
}
|
|
11420
11810
|
var URL_TOKEN = /[a-z][a-z0-9+.-]*:\/\/\S+/gi;
|
|
11421
11811
|
var URL_PARTS = /^(?:(?:([a-z][a-z0-9+.-]*:)?\/\/)([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#.*)?$/is;
|
|
11422
11812
|
var RECEIVED_PAGE = /^(\S+ received )(.+)( as the page)$/s;
|
|
11423
|
-
var PROSE_KINDS = /* @__PURE__ */ new Set(["possibleRealData", "unloadGap", "netLogUnreadable", "serverContainerFailed", "dataLayerReassigned", "dataLayerNotHooked", "dataLayerIncomplete"]);
|
|
11813
|
+
var PROSE_KINDS = /* @__PURE__ */ new Set(["possibleRealData", "possibleRealDataPush", "unloadGap", "netLogUnreadable", "serverContainerFailed", "dataLayerReassigned", "dataLayerNotHooked", "dataLayerIncomplete"]);
|
|
11424
11814
|
var URL_AT_END = /^(.*?(?:\b[A-Z]+ |: ))((?:[a-z][a-z0-9+.-]*:)?\/\/.*|\/.*)$/s;
|
|
11425
11815
|
function queryName(pair) {
|
|
11426
11816
|
const eq = pair.indexOf("=");
|
|
@@ -11472,20 +11862,25 @@ function serverContainerLines(summary) {
|
|
|
11472
11862
|
return [`Server container: ${head}${error}; ${calls}; ${c.forwarded} request${c.forwarded === 1 ? "" : "s"} forwarded to Google`, SERVER_CONTAINER_LIMITS];
|
|
11473
11863
|
}
|
|
11474
11864
|
var DATALAYER_EVENTS_SHOWN = 3;
|
|
11475
|
-
function dataLayerLabelRank(
|
|
11476
|
-
|
|
11477
|
-
if (label
|
|
11478
|
-
|
|
11865
|
+
function dataLayerLabelRank({ event, kind }) {
|
|
11866
|
+
const label = kind === "gtag" ? labelKind(event) : "event";
|
|
11867
|
+
if (label === "consent") return 1;
|
|
11868
|
+
if (label === "gtag") return 2;
|
|
11869
|
+
return event.startsWith("gtm.") ? 3 : 0;
|
|
11479
11870
|
}
|
|
11480
11871
|
function dataLayerLine({ pushes, steps }) {
|
|
11481
|
-
const
|
|
11872
|
+
const ranks = /* @__PURE__ */ new Map();
|
|
11873
|
+
for (const shape of steps.flatMap((s) => s.events)) {
|
|
11874
|
+
if (shape.event !== NO_EVENT) ranks.set(shape.event, Math.min(ranks.get(shape.event) ?? Infinity, dataLayerLabelRank(shape)));
|
|
11875
|
+
}
|
|
11876
|
+
const events = [...ranks.keys()].sort((a, b) => ranks.get(a) - ranks.get(b) || (a < b ? -1 : a > b ? 1 : 0));
|
|
11482
11877
|
const shown2 = events.slice(0, DATALAYER_EVENTS_SHOWN).join(", ");
|
|
11483
11878
|
const list3 = events.length > 0 ? ` (${shown2}${events.length > DATALAYER_EVENTS_SHOWN ? ", \u2026" : ""})` : "";
|
|
11484
11879
|
return `dataLayer: ${pushes} push${pushes === 1 ? "" : "es"}, ${events.length} event${events.length === 1 ? "" : "s"}${list3}; shapes in --json`;
|
|
11485
11880
|
}
|
|
11486
11881
|
var TAGS_SHOWN = 5;
|
|
11487
11882
|
function tagList(items) {
|
|
11488
|
-
return items
|
|
11883
|
+
return listWithMore(items, TAGS_SHOWN);
|
|
11489
11884
|
}
|
|
11490
11885
|
function tagsLine(container, entry) {
|
|
11491
11886
|
if (!("fired" in entry)) return `Tags: no reports from ${container}. Install the reporter: ${entry.hint}`;
|
|
@@ -11501,7 +11896,7 @@ function tagsLine(container, entry) {
|
|
|
11501
11896
|
function formatSummary(summary) {
|
|
11502
11897
|
const lines = [];
|
|
11503
11898
|
if (summary.label !== void 0) lines.push(`Label: ${summary.label}`);
|
|
11504
|
-
const defaultsLine =
|
|
11899
|
+
const defaultsLine = formatDefaultsLine(summary.defaults);
|
|
11505
11900
|
if (defaultsLine) lines.push(defaultsLine);
|
|
11506
11901
|
if (summary.testPayment) {
|
|
11507
11902
|
const { provider, host, testMode } = summary.testPayment;
|
|
@@ -11889,11 +12284,8 @@ ${error.issues.map((i) => ` ${i}`).join("\n")}
|
|
|
11889
12284
|
}
|
|
11890
12285
|
warnTestGtmOrigin(io);
|
|
11891
12286
|
warnTestLoopbackHosted(io);
|
|
11892
|
-
const out =
|
|
11893
|
-
if (
|
|
11894
|
-
const notice = await oldRunsNotice(process.cwd(), out);
|
|
11895
|
-
if (notice) io.stderr(notice);
|
|
11896
|
-
}
|
|
12287
|
+
const { folder: out, notice } = await resolveRunFolder({ out: args.out, now: /* @__PURE__ */ new Date(), label: args.label, base: loaded?.config.out });
|
|
12288
|
+
if (notice) io.stderr(notice);
|
|
11897
12289
|
await warnIfNotIgnored(out, io.stderr);
|
|
11898
12290
|
const outcome = await executeRun(
|
|
11899
12291
|
{
|
|
@@ -11991,7 +12383,7 @@ function formatSuiteTable(manifest, dir) {
|
|
|
11991
12383
|
const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i].length)));
|
|
11992
12384
|
const line = (cols) => cols.map((c, i) => i === cols.length - 1 ? c : c.padEnd(widths[i] + 3)).join("").trimEnd();
|
|
11993
12385
|
const out = [line(header), ...rows.map(line)];
|
|
11994
|
-
const defaultsLine =
|
|
12386
|
+
const defaultsLine = formatDefaultsLine(manifest.defaults);
|
|
11995
12387
|
if (defaultsLine) out.push("", defaultsLine);
|
|
11996
12388
|
const records = manifest.cells.filter((c) => c.record);
|
|
11997
12389
|
if (records.length) out.push("", "Records", ...records.map((c) => ` ${cellName(c)}: ${join13(dir, c.record)}`));
|
|
@@ -12119,17 +12511,6 @@ async function loadStores(path, io) {
|
|
|
12119
12511
|
}
|
|
12120
12512
|
}
|
|
12121
12513
|
async function suiteCommand(args, io, deps = { run: executeRun }) {
|
|
12122
|
-
try {
|
|
12123
|
-
return await runSuite(args, io, deps);
|
|
12124
|
-
} catch (error) {
|
|
12125
|
-
if (!(error instanceof UsageError)) throw error;
|
|
12126
|
-
io.stderr(`${error.message}
|
|
12127
|
-
${usageHint(error.command)}
|
|
12128
|
-
`);
|
|
12129
|
-
return 2;
|
|
12130
|
-
}
|
|
12131
|
-
}
|
|
12132
|
-
async function runSuite(args, io, deps) {
|
|
12133
12514
|
if (args.allowTestPayment !== void 0 && args.site === void 0 && args.stores === void 0) {
|
|
12134
12515
|
throw new UsageError("--allow-test-payment needs --site or --stores on the command line. A default file never supplies the host a test payment runs on.", "suite");
|
|
12135
12516
|
}
|
|
@@ -12262,11 +12643,8 @@ ${hints.join(" ")}
|
|
|
12262
12643
|
}
|
|
12263
12644
|
}
|
|
12264
12645
|
const id = `suite_${ulid()}`;
|
|
12265
|
-
const outFolder =
|
|
12266
|
-
if (
|
|
12267
|
-
const notice = await oldRunsNotice(process.cwd(), outFolder);
|
|
12268
|
-
if (notice) io.stderr(notice);
|
|
12269
|
-
}
|
|
12646
|
+
const { folder: outFolder, notice } = await resolveRunFolder({ out: args.out, now: /* @__PURE__ */ new Date(), label: args.label, base: loaded?.config.out });
|
|
12647
|
+
if (notice) io.stderr(notice);
|
|
12270
12648
|
await warnIfNotIgnored(outFolder, io.stderr);
|
|
12271
12649
|
const dir = join13(outFolder, id);
|
|
12272
12650
|
await mkdir4(dir, { recursive: true });
|
|
@@ -12599,7 +12977,7 @@ async function refuseOverwrite(html, inputs) {
|
|
|
12599
12977
|
for (const input of inputs) if (await isSameFile(input, html)) throw new Error(`--html must not be ${input}`);
|
|
12600
12978
|
}
|
|
12601
12979
|
async function write(args, html, io) {
|
|
12602
|
-
await mkdir5(
|
|
12980
|
+
await mkdir5(dirname7(args.html), { recursive: true });
|
|
12603
12981
|
await writeFile6(args.html, html);
|
|
12604
12982
|
io.stdout(`Wrote ${args.html}
|
|
12605
12983
|
`);
|