tagreeve 0.7.0-rc.3 → 0.7.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +3 -2
- package/dist/cli.js +195 -146
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0-rc.4
|
|
4
|
+
|
|
5
|
+
The fourth release candidate, after the rc.3 field test. Install it with `npm i -g tagreeve@next`.
|
|
6
|
+
|
|
7
|
+
- New built-in check `serverContainerRejected`: with `--server-container`, it warns when more than half of the browser requests to the local server container, and at least 2, get status 400 or higher or no response. The message gives counts and status codes only, for example `22 of 27 requests to the server container were rejected (400: 22).` The `Server container` line then ends with `; <n> of <m> requests rejected`. It is `warn` by default and can be set to `fail`. Runs without a server container keep their results (#1570).
|
|
8
|
+
- The package is published from CI with npm provenance. A merged version bump on main tags, checks and publishes the release, and `scripts/bump-version.sh` sets the version in `package.json` and the docs (#1573).
|
|
9
|
+
- The Public Suffix List in `tldts` is updated to 7.4.19.
|
|
10
|
+
|
|
3
11
|
## 0.7.0-rc.3
|
|
4
12
|
|
|
5
13
|
The third release candidate, after the rc.2 field test. Install it with `npm i -g tagreeve@next`.
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
Agent-first testing for tags and consent. Tagreeve plays a visitor in a real browser, records every tracking hit the site sends, and checks the result against what you expect. Web tag reports (which GTM web tags fired) come from a GTM template you install. Server tag reports are planned.
|
|
11
11
|
|
|
12
|
-
> **Status: 0.7 (`0.7.0-rc.
|
|
12
|
+
> **Status: 0.7 (`0.7.0-rc.4`).** Tagreeve plays a visitor in Chromium, records and decodes hits, answers the consent banner, checks YAML expectations and writes a JSONL record. 0.3 adds rules on payload fields and cookies, a `deniedIdentifiers` check, `tagreeve suite`, an HTML report, a Done control for handoff steps, role-based locators and a `select` step. 0.4 adds handoffs that end by themselves, an opt-in test payment step, baselines, a viewport option and fake identities by country. 0.5 adds `--server-container`, which runs your own server container in Docker and records what it sends to each vendor, a Conversions API decoder, several stores in one suite and platform hosts for Shopify. 0.6.0-rc.1 adds path defaults, `tagreeve init`, `tagreeve/config.yml`, `--label`, default baseline paths and `suite --baseline`, exact links between server container calls and browser hits by client ID, and the frame of each `dataLayer` push. 0.6.0-rc.2 adds web tag reports, `tagreeve template web`, `tag` rules, `expectedTags`, masked `dataLayer` push shapes in `diff` and baselines, and the `consentModeSetup` check. 0.6.0-rc.3 fixes the reporter in real GTM, keeps the `dataLayer` hook working when a page replaces `push`, adds push kinds and a `dataLayerIncomplete` flag, and sends handoff text to stderr. 0.6.0 is rc.3 with the release prep and no code change; it was field-tested on a real store with a real GTM web container in a workspace preview (rc.2 and rc.3). The rest of this README describes where Tagreeve is going, and marks what is not built yet. The design is in [docs/design.md](docs/design.md). Feedback is welcome in issues.
|
|
13
13
|
>
|
|
14
14
|
> **In 0.1:** `tagreeve run` with `stub` and `live` network modes; consent epochs, with withdrawals labelled apart from first rejects; seeded fake identities, hash checks and leak detection; decoders for GA4, Google Ads, Meta, Stape custom loader and a minimal server-container data client; banner handling through autoconsent; expectations; JSONL output.
|
|
15
15
|
>
|
|
@@ -17,7 +17,7 @@ Agent-first testing for tags and consent. Tagreeve plays a visitor in a real bro
|
|
|
17
17
|
>
|
|
18
18
|
> **In 0.3:** `body.has` and `body.only` rules on the field names of a hit; `cookie` rules; a `deniedIdentifiers` check that fails when an identifier goes out on a denied hit; `tagreeve suite` runs a folder of scenarios against several GTM builds; `tagreeve report` writes an HTML report of one run or a suite; a Done button in the handoff window; `click` and `wait` by role and name or from a list of selectors; a `select` step; the `server` network mode; record schema version 2. `deniedIdentifiers` fails by default, so a run that passed in 0.2 can exit 1. See [CHANGELOG.md](CHANGELOG.md).
|
|
19
19
|
>
|
|
20
|
-
> **In 0.7.0-rc.
|
|
20
|
+
> **In 0.7.0-rc.4:** rc.4 adds the built-in check `serverContainerRejected`. With `--server-container`, it warns when the local server container rejects more than half of the browser requests it gets, and at least 2, and the `Server container` line then says how many were rejected. It is `warn` by default and can be set to `fail`. rc.4 is the first release published from CI, with npm provenance. 0.7.0-rc.3 fixed the `earlyIdentityPush` masking of keys that hold the email local part, the `idHandover` message for one context, the `CHANGELOG.md` in the npm package and the CA certificates of the server container runner. 0.7.0 has three new built-in checks and a rule kind for `dataLayer` pushes. `earlyIdentityPush` warns when a push carries the run's own test identity before consent. `idHandover` warns when the GA4 client or session ID differs between two contexts. All three warn by default and can be set to `fail`. `dataLayer:` rules check which pushes a page makes. A `consent default` pushed as a plain object now counts for `consentModeSetup`. `diff` keeps a cross-epoch join. The fixture site has a plain GTM demo shop. The record stays at schema version 5. `npm i -g tagreeve@next` installs it. To upgrade from 0.6.2, read "Upgrading from 0.6.2" in [CHANGELOG.md](CHANGELOG.md). What is still open is in the same file under "Known in 0.7.0-rc.1".
|
|
21
21
|
>
|
|
22
22
|
> **In 0.6.2:** fixes after 0.6.1, with no new command and no new option. A test payment ends by its deadline when a card frame stops answering. A scoped `must` rule can now warn where 0.6.1 failed, so a run can exit 0. `diff --json` has `renamedFrom` and `pushKind`. `tagreeve init` creates nothing when a target is refused. The record stays at schema version 5. `npm i -g tagreeve` installs it. To upgrade from 0.6.1, read "Upgrading from 0.6.1" in [CHANGELOG.md](CHANGELOG.md). What is still open is in the same file under "Known in 0.6.2".
|
|
23
23
|
>
|
|
@@ -194,6 +194,7 @@ options:
|
|
|
194
194
|
- `earlyIdentifiers` is a built-in check. It warns when a hit sent before the first consent answer carries an identifier and its consent signal is unknown, for example a hashed email on a page with no Consent Mode default. It is `warn` by default, so the exit code stays the same. Set it to `fail` to fail the run.
|
|
195
195
|
- `consentModeSetup` is a built-in check. It warns when a Google hit shows a Consent Mode signal that was never set, for example a default without `ad_user_data` and `ad_personalization`. It reads the `gcd` value of each hit. It is `warn` by default. Set it to `fail` to fail the run.
|
|
196
196
|
- `idHandover` is a built-in check. It warns when the GA4 client ID or session ID does not carry over between contexts, such as a checkout on another host or in a frame. It names the measurement ID and the contexts and never prints an ID. It is `warn` by default. Set it to `fail` to fail the run.
|
|
197
|
+
- `serverContainerRejected` is a built-in check for runs with `--server-container`. It warns when more than half of the browser requests to the container, and at least 2, get status 400 or higher or no answer. Its message gives counts and status codes and never a path or ID. It is `warn` by default. Set it to `fail` to fail the run.
|
|
197
198
|
- `earlyIdentityPush` is a built-in check. It warns when a `dataLayer` push carries the run's own test email or phone, or a hash of either, while consent is not given. It never prints the value. It is `warn` by default. Set it to `fail` to fail the run.
|
|
198
199
|
- `click` and `wait` take `{ role, name }` or `{ any: [selectors] }`, so a theme change does not break every scenario. `select` chooses an option of a `<select>` by value, then by label, and reads it back.
|
|
199
200
|
|
package/dist/cli.js
CHANGED
|
@@ -695,6 +695,34 @@ function consentCommandOf(args) {
|
|
|
695
695
|
return { command: list3[1], signals: list3[2] };
|
|
696
696
|
}
|
|
697
697
|
|
|
698
|
+
// packages/core/src/server-hosts.ts
|
|
699
|
+
function hostMatches(host, patterns) {
|
|
700
|
+
const h = host.toLowerCase();
|
|
701
|
+
return patterns.some((pattern) => {
|
|
702
|
+
const p = pattern.toLowerCase();
|
|
703
|
+
return p.startsWith("*.") ? h.endsWith(p.slice(1)) : h === p;
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
var LOAD_RESOURCE_TYPES = /* @__PURE__ */ new Set(["script", "stylesheet", "font", "document"]);
|
|
707
|
+
var bareHost = (h) => h.replace(/^\[|\]$/g, "");
|
|
708
|
+
function isServerHostUrl(url, serverHosts) {
|
|
709
|
+
try {
|
|
710
|
+
return hostMatches(bareHost(new URL(url).hostname), serverHosts.map(bareHost));
|
|
711
|
+
} catch {
|
|
712
|
+
return false;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
function isServerContainerRequest(req, serverHosts) {
|
|
716
|
+
let url;
|
|
717
|
+
try {
|
|
718
|
+
url = new URL(req.url);
|
|
719
|
+
} catch {
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
if (!/^https?:$/.test(url.protocol) || !isServerHostUrl(req.url, serverHosts)) return false;
|
|
723
|
+
return !isLibraryLoadPath(url.pathname) && !LOAD_RESOURCE_TYPES.has(req.resourceType);
|
|
724
|
+
}
|
|
725
|
+
|
|
698
726
|
// packages/decoders/src/decoder.ts
|
|
699
727
|
var defaultHitId = () => newId("hit");
|
|
700
728
|
var vendorKeys = ["ga4", "google-ads", "meta", "meta-capi", "pinterest", "sgtm"];
|
|
@@ -1422,7 +1450,7 @@ var PINGS = [
|
|
|
1422
1450
|
];
|
|
1423
1451
|
var REMARKETING = /^\/(?:pagead\/(?:viewthroughconversion|1p-user-list)|rmkt\/collect|ccm\/(?:s\/)?collect)(?:\/|$)/;
|
|
1424
1452
|
var GOOGLE_REGIONAL = /^(?:[a-z0-9-]+\.)*google\.(?:com?\.)?[a-z]{2}$/;
|
|
1425
|
-
function
|
|
1453
|
+
function hostMatches2(host) {
|
|
1426
1454
|
return GOOGLE_REGIONAL.test(host) || ADS_HOSTS.some((h) => host === h || host.endsWith(`.${h}`));
|
|
1427
1455
|
}
|
|
1428
1456
|
function pingPath(req) {
|
|
@@ -1432,7 +1460,7 @@ function pingPath(req) {
|
|
|
1432
1460
|
} catch {
|
|
1433
1461
|
return void 0;
|
|
1434
1462
|
}
|
|
1435
|
-
if (!
|
|
1463
|
+
if (!hostMatches2(url.hostname)) return void 0;
|
|
1436
1464
|
for (const re of PINGS) {
|
|
1437
1465
|
const m = re.exec(url.pathname);
|
|
1438
1466
|
if (m) return { url, id: m[1] };
|
|
@@ -1621,7 +1649,7 @@ var trackerList = [
|
|
|
1621
1649
|
}
|
|
1622
1650
|
];
|
|
1623
1651
|
var trackerVendorKeys = [...new Set(trackerList.map((e) => e.vendor))];
|
|
1624
|
-
function
|
|
1652
|
+
function hostMatches3(pattern, hostname2) {
|
|
1625
1653
|
if (pattern.startsWith("*.")) return hostname2.endsWith(pattern.slice(1));
|
|
1626
1654
|
return hostname2 === pattern;
|
|
1627
1655
|
}
|
|
@@ -1637,7 +1665,7 @@ function trackerFor(req, list3 = trackerList) {
|
|
|
1637
1665
|
return void 0;
|
|
1638
1666
|
}
|
|
1639
1667
|
return list3.find(
|
|
1640
|
-
(e) =>
|
|
1668
|
+
(e) => hostMatches3(e.host, url.hostname) && (!e.paths || e.paths.some((p) => pathMatches(p, url.pathname)))
|
|
1641
1669
|
);
|
|
1642
1670
|
}
|
|
1643
1671
|
var HOST = /^(\*\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+$/;
|
|
@@ -1775,7 +1803,7 @@ var platformHosts = [
|
|
|
1775
1803
|
source: "https://shopify.dev/docs/api/commerce-components/pay"
|
|
1776
1804
|
}
|
|
1777
1805
|
];
|
|
1778
|
-
function
|
|
1806
|
+
function hostMatches4(pattern, hostname2) {
|
|
1779
1807
|
return pattern.startsWith("*.") ? hostname2.endsWith(pattern.slice(1)) : hostname2 === pattern;
|
|
1780
1808
|
}
|
|
1781
1809
|
function pathMatches2(prefix, pathname) {
|
|
@@ -1789,7 +1817,7 @@ function platformHostFor(req, list3 = platformHosts) {
|
|
|
1789
1817
|
} catch {
|
|
1790
1818
|
return void 0;
|
|
1791
1819
|
}
|
|
1792
|
-
return list3.find((e) =>
|
|
1820
|
+
return list3.find((e) => hostMatches4(e.host, url.hostname) && (!e.paths || e.paths.some((p) => pathMatches2(p, url.pathname))));
|
|
1793
1821
|
}
|
|
1794
1822
|
|
|
1795
1823
|
// packages/decoders/src/event-names.ts
|
|
@@ -1809,6 +1837,104 @@ function ga4EventName(name) {
|
|
|
1809
1837
|
return Object.hasOwn(SHOPIFY_TO_GA4, name) ? SHOPIFY_TO_GA4[name] : name;
|
|
1810
1838
|
}
|
|
1811
1839
|
|
|
1840
|
+
// packages/recorder/src/stub.ts
|
|
1841
|
+
var GIF = Buffer.from("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", "base64");
|
|
1842
|
+
function corsHeaders(headers) {
|
|
1843
|
+
const out = {
|
|
1844
|
+
"access-control-allow-origin": headers.origin ?? "*",
|
|
1845
|
+
"access-control-allow-credentials": "true",
|
|
1846
|
+
"access-control-allow-methods": "GET, POST, OPTIONS",
|
|
1847
|
+
vary: "Origin"
|
|
1848
|
+
};
|
|
1849
|
+
const requested = headers["access-control-request-headers"];
|
|
1850
|
+
if (requested) out["access-control-allow-headers"] = requested;
|
|
1851
|
+
return out;
|
|
1852
|
+
}
|
|
1853
|
+
var CAPI_ANSWER = Buffer.from('{"events_received":1,"messages":[],"fbtrace_id":"pw-fixture"}');
|
|
1854
|
+
function stubResponse(req) {
|
|
1855
|
+
const cors = corsHeaders(req.headers);
|
|
1856
|
+
if (req.url !== void 0 && isMetaCapiEndpoint({ url: req.url })) {
|
|
1857
|
+
return { status: 200, headers: { ...cors, "content-type": "application/json", "cache-control": "no-store" }, body: CAPI_ANSWER };
|
|
1858
|
+
}
|
|
1859
|
+
switch (req.resourceType) {
|
|
1860
|
+
case "image":
|
|
1861
|
+
return { status: 200, headers: { ...cors, "content-type": "image/gif", "cache-control": "no-store" }, body: GIF };
|
|
1862
|
+
case "script":
|
|
1863
|
+
return { status: 200, headers: { ...cors, "content-type": "application/javascript", "cache-control": "no-store" }, body: Buffer.alloc(0) };
|
|
1864
|
+
case "document":
|
|
1865
|
+
return { status: 200, headers: { ...cors, "content-type": "text/html", "cache-control": "no-store" }, body: Buffer.alloc(0) };
|
|
1866
|
+
default:
|
|
1867
|
+
return { status: 204, headers: cors };
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
var VENDOR_HOST = /(^|\.)(facebook\.com|facebook\.net|doubleclick\.net|googleadservices\.com|googlesyndication\.com|googletagmanager\.com)$|^(www\.)?google\.com$/;
|
|
1871
|
+
var COLLECTION_PATH = /^\/(?:tr|pagead\/(?:viewthroughconversion|conversion|1p-[\w-]+)|rmkt|ccm|td)(?:\/|$)/;
|
|
1872
|
+
var SITE_FUNCTION_PATH = /^\/(?:recaptcha|maps|plugins|dialog|login)(?:\/|$)/;
|
|
1873
|
+
function isKnownVendorCollection(req) {
|
|
1874
|
+
let url;
|
|
1875
|
+
try {
|
|
1876
|
+
url = new URL(req.url);
|
|
1877
|
+
} catch {
|
|
1878
|
+
return false;
|
|
1879
|
+
}
|
|
1880
|
+
if (!VENDOR_HOST.test(url.hostname)) return false;
|
|
1881
|
+
if (isLibraryLoadPath(url.pathname)) return false;
|
|
1882
|
+
if (COLLECTION_PATH.test(url.pathname)) return true;
|
|
1883
|
+
if (SITE_FUNCTION_PATH.test(url.pathname)) return false;
|
|
1884
|
+
return !LOAD_RESOURCE_TYPES.has(req.resourceType);
|
|
1885
|
+
}
|
|
1886
|
+
function isStubbedCollection(req, options) {
|
|
1887
|
+
if (!isCollectionEndpoint(req, options.trackers) && !isKnownVendorCollection(req)) return false;
|
|
1888
|
+
if (options.networkMode !== "server") return true;
|
|
1889
|
+
return !isServerHostUrl(req.url, options.serverHosts ?? []);
|
|
1890
|
+
}
|
|
1891
|
+
function setCookieNamesOf(headers) {
|
|
1892
|
+
return Object.entries(headers).filter(([name]) => name.toLowerCase() === "set-cookie").flatMap(([, value]) => value.split("\n")).flatMap((c) => setCookieNameOf(c));
|
|
1893
|
+
}
|
|
1894
|
+
function setCookieNameOf(line) {
|
|
1895
|
+
const pair = line.split(";")[0];
|
|
1896
|
+
const eq = pair.indexOf("=");
|
|
1897
|
+
const name = eq > 0 ? pair.slice(0, eq).trim() : "";
|
|
1898
|
+
return name ? [name] : [];
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// packages/recorder/src/collector.ts
|
|
1902
|
+
var MAX_BODY_BYTES = 64 * 1024;
|
|
1903
|
+
var MAX_SOURCE_LENGTH = 64;
|
|
1904
|
+
function parseCollectorBody(body) {
|
|
1905
|
+
if (!body) return { ok: false, error: "empty body" };
|
|
1906
|
+
if (Buffer.byteLength(body) > MAX_BODY_BYTES) return { ok: false, error: `body over ${MAX_BODY_BYTES} bytes` };
|
|
1907
|
+
let json;
|
|
1908
|
+
try {
|
|
1909
|
+
json = JSON.parse(body);
|
|
1910
|
+
} catch {
|
|
1911
|
+
return { ok: false, error: "body is not JSON" };
|
|
1912
|
+
}
|
|
1913
|
+
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
1914
|
+
return { ok: false, error: "body must be a JSON object" };
|
|
1915
|
+
}
|
|
1916
|
+
const payload = json;
|
|
1917
|
+
const source = payload.source;
|
|
1918
|
+
if (typeof source !== "string" || source === "" || source.length > MAX_SOURCE_LENGTH) {
|
|
1919
|
+
return { ok: false, error: `"source" must be a string of 1 to ${MAX_SOURCE_LENGTH} characters` };
|
|
1920
|
+
}
|
|
1921
|
+
return { ok: true, source, payload };
|
|
1922
|
+
}
|
|
1923
|
+
function parseCollectorRequest(method, url, body) {
|
|
1924
|
+
if (method === "POST") return { parsed: parseCollectorBody(body), body: body ?? "" };
|
|
1925
|
+
return { parsed: { ok: false, error: `${method} request, reports must be POST` }, body: url };
|
|
1926
|
+
}
|
|
1927
|
+
async function routeCollector(context, handler, now) {
|
|
1928
|
+
await context.route(`${COLLECTOR_ORIGIN}/**`, async (route) => {
|
|
1929
|
+
const request = route.request();
|
|
1930
|
+
if (request.method() !== "OPTIONS") {
|
|
1931
|
+
const { parsed, body } = parseCollectorRequest(request.method(), request.url(), request.postData());
|
|
1932
|
+
handler()(parsed, body, now());
|
|
1933
|
+
}
|
|
1934
|
+
await route.fulfill({ status: 204, headers: corsHeaders(request.headers()) });
|
|
1935
|
+
});
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1812
1938
|
// packages/expect/src/scenario.ts
|
|
1813
1939
|
import { LineCounter, parseDocument } from "yaml";
|
|
1814
1940
|
|
|
@@ -1818,13 +1944,6 @@ var HOST_PATTERN = /^(\*\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[
|
|
|
1818
1944
|
function isHostPattern(value) {
|
|
1819
1945
|
return typeof value === "string" && HOST_PATTERN.test(value);
|
|
1820
1946
|
}
|
|
1821
|
-
function hostMatches4(host, patterns) {
|
|
1822
|
-
const h = host.toLowerCase();
|
|
1823
|
-
return patterns.some((pattern) => {
|
|
1824
|
-
const p = pattern.toLowerCase();
|
|
1825
|
-
return p.startsWith("*.") ? h.endsWith(p.slice(1)) : h === p;
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
1947
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "::1", "[::1]"]);
|
|
1829
1948
|
var EXTRA_SHARED_SUFFIXES = /* @__PURE__ */ new Set(["wordpress.com"]);
|
|
1830
1949
|
function isPublicSuffix(domain) {
|
|
@@ -2039,7 +2158,7 @@ function parseViewportText(text2) {
|
|
|
2039
2158
|
return isViewportSide(viewport.width) && isViewportSide(viewport.height) ? viewport : void 0;
|
|
2040
2159
|
}
|
|
2041
2160
|
var VIEWPORT_HINT = `a size such as 390x844, with each side from ${VIEWPORT_MIN} to ${VIEWPORT_MAX}`;
|
|
2042
|
-
var BUILTIN_NAMES = ["unknownDestination", "sandboxPageUrl", "possibleRealData", "deniedIdentifiers", "earlyIdentifiers", "consentModeSetup", "earlyIdentityPush", "idHandover"];
|
|
2161
|
+
var BUILTIN_NAMES = ["unknownDestination", "sandboxPageUrl", "possibleRealData", "deniedIdentifiers", "earlyIdentifiers", "consentModeSetup", "earlyIdentityPush", "idHandover", "serverContainerRejected"];
|
|
2043
2162
|
var SEVERITIES = ["fail", "warn"];
|
|
2044
2163
|
var IDENTITY_FIELDS = ["firstName", "lastName", "email", "phone", "address1", "city", "zip", "country"];
|
|
2045
2164
|
var ScenarioError = class extends Error {
|
|
@@ -3005,6 +3124,43 @@ function idHandover(hits, requests) {
|
|
|
3005
3124
|
};
|
|
3006
3125
|
}
|
|
3007
3126
|
|
|
3127
|
+
// packages/expect/src/server-container-rejected.ts
|
|
3128
|
+
var NO_ANSWER = "no answer";
|
|
3129
|
+
var COUNTS = /^(\d+) of (\d+) requests to the server container were rejected/;
|
|
3130
|
+
function rejectedCounts(message) {
|
|
3131
|
+
const m = COUNTS.exec(message ?? "");
|
|
3132
|
+
return m ? { rejected: Number(m[1]), counted: Number(m[2]) } : null;
|
|
3133
|
+
}
|
|
3134
|
+
function serverContainerRejected(requests, responses, serverHosts) {
|
|
3135
|
+
const statusOf2 = new Map(responses.map((r) => [r.requestId, r.status]));
|
|
3136
|
+
const counted = requests.filter(
|
|
3137
|
+
(r) => !r.captured && r.outcome !== "passed" && r.initiator !== "unload" && r.initiator !== "redirect" && isServerContainerRequest(r, serverHosts)
|
|
3138
|
+
);
|
|
3139
|
+
if (counted.length === 0) return { pass: true, evidence: [], message: "No requests to the server container to check." };
|
|
3140
|
+
const rejected = counted.filter((r) => {
|
|
3141
|
+
const status = statusOf2.get(r.id);
|
|
3142
|
+
return status === void 0 || status >= 400;
|
|
3143
|
+
});
|
|
3144
|
+
const warn = rejected.length >= 2 && rejected.length * 2 > counted.length;
|
|
3145
|
+
if (!warn) {
|
|
3146
|
+
return { pass: true, evidence: [], message: `${rejected.length} of ${counted.length} requests to the server container were rejected.` };
|
|
3147
|
+
}
|
|
3148
|
+
const byStatus = /* @__PURE__ */ new Map();
|
|
3149
|
+
let unanswered = 0;
|
|
3150
|
+
for (const r of rejected) {
|
|
3151
|
+
const status = statusOf2.get(r.id);
|
|
3152
|
+
if (status === void 0) unanswered++;
|
|
3153
|
+
else byStatus.set(status, (byStatus.get(status) ?? 0) + 1);
|
|
3154
|
+
}
|
|
3155
|
+
const parts = [...byStatus].sort((a, b) => a[0] - b[0]).map(([status, n]) => `${status}: ${n}`);
|
|
3156
|
+
if (unanswered > 0) parts.push(`${NO_ANSWER}: ${unanswered}`);
|
|
3157
|
+
return {
|
|
3158
|
+
pass: false,
|
|
3159
|
+
evidence: rejected.map((r) => r.id),
|
|
3160
|
+
message: `${rejected.length} of ${counted.length} requests to the server container were rejected (${parts.join(", ")}).`
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3008
3164
|
// packages/expect/src/push-rules.ts
|
|
3009
3165
|
function fieldGlob(pattern) {
|
|
3010
3166
|
if (!pattern.startsWith("**.")) return globToRegExp(pattern);
|
|
@@ -3276,7 +3432,8 @@ function evaluate(records, scenario, options = {}) {
|
|
|
3276
3432
|
const countRests = kind === "must" && failureRests && !ownNote;
|
|
3277
3433
|
add2(`${kind}: ${rule.description}`, pass, evidence, message, countRests ? "warn" : outcome.severity, countRests ? "serverSendProbableLink" : note, scoped && (pass || failureRests));
|
|
3278
3434
|
}
|
|
3279
|
-
|
|
3435
|
+
const containerRan = Boolean(runRecord && (runRecord.serverContainer || runRecord.testServerContainer) && !runRecord.serverContainer?.error);
|
|
3436
|
+
builtInChecks(records, scenario, ctx, add2, containerRan);
|
|
3280
3437
|
return results;
|
|
3281
3438
|
}
|
|
3282
3439
|
var isScoped = (rule) => Boolean(rule.before || rule.inEpoch || rule.after || rule.from || consentFields.some((f) => rule.filter.consent[f]));
|
|
@@ -4057,8 +4214,8 @@ function countByHost(flags2, ctx) {
|
|
|
4057
4214
|
}
|
|
4058
4215
|
return [...counts].map(([host, n]) => `${host} x${n}`).join(", ");
|
|
4059
4216
|
}
|
|
4060
|
-
var DEFAULT_SEVERITY = { earlyIdentifiers: "warn", consentModeSetup: "warn", earlyIdentityPush: "warn", idHandover: "warn" };
|
|
4061
|
-
function builtInChecks(records, scenario, ctx, addResult) {
|
|
4217
|
+
var DEFAULT_SEVERITY = { earlyIdentifiers: "warn", consentModeSetup: "warn", earlyIdentityPush: "warn", idHandover: "warn", serverContainerRejected: "warn" };
|
|
4218
|
+
function builtInChecks(records, scenario, ctx, addResult, containerRan) {
|
|
4062
4219
|
const add2 = (name, pass, evidence2, message, note, timeJudged = false) => addResult(
|
|
4063
4220
|
`builtin: ${name}`,
|
|
4064
4221
|
pass,
|
|
@@ -4072,7 +4229,7 @@ function builtInChecks(records, scenario, ctx, addResult) {
|
|
|
4072
4229
|
const unknown = flags2.filter((f) => f.kind === "unknownDestination");
|
|
4073
4230
|
const allow = scenario.options.allowUnknownDestination;
|
|
4074
4231
|
const allowedHosts = Array.isArray(allow) ? allow : [];
|
|
4075
|
-
const isAllowed = (f) => allow === true ||
|
|
4232
|
+
const isAllowed = (f) => allow === true || hostMatches(flagHost(f, ctx), allowedHosts);
|
|
4076
4233
|
const blocked = unknown.filter((f) => !isAllowed(f));
|
|
4077
4234
|
const allowedCount = unknown.length - blocked.length;
|
|
4078
4235
|
add2(
|
|
@@ -4127,14 +4284,18 @@ function builtInChecks(records, scenario, ctx, addResult) {
|
|
|
4127
4284
|
[],
|
|
4128
4285
|
"Cannot check for data that is not from the run identity: no identity was given and no possibleRealData flags exist."
|
|
4129
4286
|
);
|
|
4130
|
-
|
|
4287
|
+
} else {
|
|
4288
|
+
add2(
|
|
4289
|
+
"possibleRealData",
|
|
4290
|
+
problems.length === 0,
|
|
4291
|
+
evidence,
|
|
4292
|
+
problems.length === 0 ? "Expected no data that is not from the run identity, found none." : `Expected no data that is not from the run identity, found ${problems.length}: ${shown2}${more}.`
|
|
4293
|
+
);
|
|
4294
|
+
}
|
|
4295
|
+
if (containerRan) {
|
|
4296
|
+
const rejected = serverContainerRejected([...ctx.requests.values()], ctx.responses, scenario.options.serverHosts ?? []);
|
|
4297
|
+
add2("serverContainerRejected", rejected.pass, rejected.evidence, rejected.message);
|
|
4131
4298
|
}
|
|
4132
|
-
add2(
|
|
4133
|
-
"possibleRealData",
|
|
4134
|
-
problems.length === 0,
|
|
4135
|
-
evidence,
|
|
4136
|
-
problems.length === 0 ? "Expected no data that is not from the run identity, found none." : `Expected no data that is not from the run identity, found ${problems.length}: ${shown2}${more}.`
|
|
4137
|
-
);
|
|
4138
4299
|
}
|
|
4139
4300
|
var DENIABLE = ["analytics", "ads", "adUserData"];
|
|
4140
4301
|
function unjudgedIdentifiers(ctx) {
|
|
@@ -5278,123 +5439,6 @@ function mergeOptions(config, scenario) {
|
|
|
5278
5439
|
return merged;
|
|
5279
5440
|
}
|
|
5280
5441
|
|
|
5281
|
-
// packages/recorder/src/stub.ts
|
|
5282
|
-
var GIF = Buffer.from("R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7", "base64");
|
|
5283
|
-
function corsHeaders(headers) {
|
|
5284
|
-
const out = {
|
|
5285
|
-
"access-control-allow-origin": headers.origin ?? "*",
|
|
5286
|
-
"access-control-allow-credentials": "true",
|
|
5287
|
-
"access-control-allow-methods": "GET, POST, OPTIONS",
|
|
5288
|
-
vary: "Origin"
|
|
5289
|
-
};
|
|
5290
|
-
const requested = headers["access-control-request-headers"];
|
|
5291
|
-
if (requested) out["access-control-allow-headers"] = requested;
|
|
5292
|
-
return out;
|
|
5293
|
-
}
|
|
5294
|
-
var CAPI_ANSWER = Buffer.from('{"events_received":1,"messages":[],"fbtrace_id":"pw-fixture"}');
|
|
5295
|
-
function stubResponse(req) {
|
|
5296
|
-
const cors = corsHeaders(req.headers);
|
|
5297
|
-
if (req.url !== void 0 && isMetaCapiEndpoint({ url: req.url })) {
|
|
5298
|
-
return { status: 200, headers: { ...cors, "content-type": "application/json", "cache-control": "no-store" }, body: CAPI_ANSWER };
|
|
5299
|
-
}
|
|
5300
|
-
switch (req.resourceType) {
|
|
5301
|
-
case "image":
|
|
5302
|
-
return { status: 200, headers: { ...cors, "content-type": "image/gif", "cache-control": "no-store" }, body: GIF };
|
|
5303
|
-
case "script":
|
|
5304
|
-
return { status: 200, headers: { ...cors, "content-type": "application/javascript", "cache-control": "no-store" }, body: Buffer.alloc(0) };
|
|
5305
|
-
case "document":
|
|
5306
|
-
return { status: 200, headers: { ...cors, "content-type": "text/html", "cache-control": "no-store" }, body: Buffer.alloc(0) };
|
|
5307
|
-
default:
|
|
5308
|
-
return { status: 204, headers: cors };
|
|
5309
|
-
}
|
|
5310
|
-
}
|
|
5311
|
-
var LOADS2 = /* @__PURE__ */ new Set(["script", "stylesheet", "font", "document"]);
|
|
5312
|
-
var VENDOR_HOST = /(^|\.)(facebook\.com|facebook\.net|doubleclick\.net|googleadservices\.com|googlesyndication\.com|googletagmanager\.com)$|^(www\.)?google\.com$/;
|
|
5313
|
-
var COLLECTION_PATH = /^\/(?:tr|pagead\/(?:viewthroughconversion|conversion|1p-[\w-]+)|rmkt|ccm|td)(?:\/|$)/;
|
|
5314
|
-
var SITE_FUNCTION_PATH = /^\/(?:recaptcha|maps|plugins|dialog|login)(?:\/|$)/;
|
|
5315
|
-
function isKnownVendorCollection(req) {
|
|
5316
|
-
let url;
|
|
5317
|
-
try {
|
|
5318
|
-
url = new URL(req.url);
|
|
5319
|
-
} catch {
|
|
5320
|
-
return false;
|
|
5321
|
-
}
|
|
5322
|
-
if (!VENDOR_HOST.test(url.hostname)) return false;
|
|
5323
|
-
if (isLibraryLoadPath(url.pathname)) return false;
|
|
5324
|
-
if (COLLECTION_PATH.test(url.pathname)) return true;
|
|
5325
|
-
if (SITE_FUNCTION_PATH.test(url.pathname)) return false;
|
|
5326
|
-
return !LOADS2.has(req.resourceType);
|
|
5327
|
-
}
|
|
5328
|
-
var bareHost = (h) => h.replace(/^\[|\]$/g, "");
|
|
5329
|
-
function isServerHostUrl(url, serverHosts) {
|
|
5330
|
-
try {
|
|
5331
|
-
return hostMatches4(bareHost(new URL(url).hostname), serverHosts.map(bareHost));
|
|
5332
|
-
} catch {
|
|
5333
|
-
return false;
|
|
5334
|
-
}
|
|
5335
|
-
}
|
|
5336
|
-
function isServerContainerRequest(req, serverHosts) {
|
|
5337
|
-
let url;
|
|
5338
|
-
try {
|
|
5339
|
-
url = new URL(req.url);
|
|
5340
|
-
} catch {
|
|
5341
|
-
return false;
|
|
5342
|
-
}
|
|
5343
|
-
if (!/^https?:$/.test(url.protocol) || !isServerHostUrl(req.url, serverHosts)) return false;
|
|
5344
|
-
return !isLibraryLoadPath(url.pathname) && !LOADS2.has(req.resourceType);
|
|
5345
|
-
}
|
|
5346
|
-
function isStubbedCollection(req, options) {
|
|
5347
|
-
if (!isCollectionEndpoint(req, options.trackers) && !isKnownVendorCollection(req)) return false;
|
|
5348
|
-
if (options.networkMode !== "server") return true;
|
|
5349
|
-
return !isServerHostUrl(req.url, options.serverHosts ?? []);
|
|
5350
|
-
}
|
|
5351
|
-
function setCookieNamesOf(headers) {
|
|
5352
|
-
return Object.entries(headers).filter(([name]) => name.toLowerCase() === "set-cookie").flatMap(([, value]) => value.split("\n")).flatMap((c) => setCookieNameOf(c));
|
|
5353
|
-
}
|
|
5354
|
-
function setCookieNameOf(line) {
|
|
5355
|
-
const pair = line.split(";")[0];
|
|
5356
|
-
const eq = pair.indexOf("=");
|
|
5357
|
-
const name = eq > 0 ? pair.slice(0, eq).trim() : "";
|
|
5358
|
-
return name ? [name] : [];
|
|
5359
|
-
}
|
|
5360
|
-
|
|
5361
|
-
// packages/recorder/src/collector.ts
|
|
5362
|
-
var MAX_BODY_BYTES = 64 * 1024;
|
|
5363
|
-
var MAX_SOURCE_LENGTH = 64;
|
|
5364
|
-
function parseCollectorBody(body) {
|
|
5365
|
-
if (!body) return { ok: false, error: "empty body" };
|
|
5366
|
-
if (Buffer.byteLength(body) > MAX_BODY_BYTES) return { ok: false, error: `body over ${MAX_BODY_BYTES} bytes` };
|
|
5367
|
-
let json;
|
|
5368
|
-
try {
|
|
5369
|
-
json = JSON.parse(body);
|
|
5370
|
-
} catch {
|
|
5371
|
-
return { ok: false, error: "body is not JSON" };
|
|
5372
|
-
}
|
|
5373
|
-
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
5374
|
-
return { ok: false, error: "body must be a JSON object" };
|
|
5375
|
-
}
|
|
5376
|
-
const payload = json;
|
|
5377
|
-
const source = payload.source;
|
|
5378
|
-
if (typeof source !== "string" || source === "" || source.length > MAX_SOURCE_LENGTH) {
|
|
5379
|
-
return { ok: false, error: `"source" must be a string of 1 to ${MAX_SOURCE_LENGTH} characters` };
|
|
5380
|
-
}
|
|
5381
|
-
return { ok: true, source, payload };
|
|
5382
|
-
}
|
|
5383
|
-
function parseCollectorRequest(method, url, body) {
|
|
5384
|
-
if (method === "POST") return { parsed: parseCollectorBody(body), body: body ?? "" };
|
|
5385
|
-
return { parsed: { ok: false, error: `${method} request, reports must be POST` }, body: url };
|
|
5386
|
-
}
|
|
5387
|
-
async function routeCollector(context, handler, now) {
|
|
5388
|
-
await context.route(`${COLLECTOR_ORIGIN}/**`, async (route) => {
|
|
5389
|
-
const request = route.request();
|
|
5390
|
-
if (request.method() !== "OPTIONS") {
|
|
5391
|
-
const { parsed, body } = parseCollectorRequest(request.method(), request.url(), request.postData());
|
|
5392
|
-
handler()(parsed, body, now());
|
|
5393
|
-
}
|
|
5394
|
-
await route.fulfill({ status: 204, headers: corsHeaders(request.headers()) });
|
|
5395
|
-
});
|
|
5396
|
-
}
|
|
5397
|
-
|
|
5398
5442
|
// packages/recorder/src/datalayer.ts
|
|
5399
5443
|
var DATALAYER_BINDING = "__tagreeveDataLayer";
|
|
5400
5444
|
var DEFAULT_DATALAYER = "dataLayer";
|
|
@@ -5734,7 +5778,7 @@ function parse(url) {
|
|
|
5734
5778
|
}
|
|
5735
5779
|
}
|
|
5736
5780
|
function isFirstPartyHost(host, { siteHost, firstPartyHosts = [] }) {
|
|
5737
|
-
if (host === siteHost ||
|
|
5781
|
+
if (host === siteHost || hostMatches(host, firstPartyHosts)) return true;
|
|
5738
5782
|
const domain = getDomain(siteHost, { allowPrivateDomains: true });
|
|
5739
5783
|
return domain !== null && getDomain(host, { allowPrivateDomains: true }) === domain;
|
|
5740
5784
|
}
|
|
@@ -6771,7 +6815,7 @@ function isLoaderHost(url, site, firstPartyHosts = []) {
|
|
|
6771
6815
|
const host = new URL(url).hostname;
|
|
6772
6816
|
const loopback = (h) => ["localhost", "127.0.0.1", "[::1]"].includes(h);
|
|
6773
6817
|
if (loopback(siteHost)) return loopback(host);
|
|
6774
|
-
if (
|
|
6818
|
+
if (hostMatches(host, firstPartyHosts)) return true;
|
|
6775
6819
|
const domain = getDomain2(siteHost, { allowPrivateDomains: true });
|
|
6776
6820
|
return domain !== null && getDomain2(host, { allowPrivateDomains: true }) === domain;
|
|
6777
6821
|
} catch {
|
|
@@ -12276,13 +12320,18 @@ function formatDuration2(ms) {
|
|
|
12276
12320
|
return rounded < 1e3 ? `${rounded} ms` : `${(ms / 1e3).toFixed(1)} s`;
|
|
12277
12321
|
}
|
|
12278
12322
|
var SERVER_CONTAINER_LIMITS = " Not shown: Stape-only features, tags that need the hosting layer, unpublished workspaces, calls no decoder matched (flagged unknown)";
|
|
12323
|
+
function rejectedSuffix(summary) {
|
|
12324
|
+
const result = summary.results.find((r) => r.expectation === "builtin: serverContainerRejected");
|
|
12325
|
+
const counts = result && !result.pass ? rejectedCounts(result.message) : null;
|
|
12326
|
+
return counts ? `; ${counts.rejected} of ${counts.counted} requests rejected` : "";
|
|
12327
|
+
}
|
|
12279
12328
|
function serverContainerLines(summary) {
|
|
12280
12329
|
const { serverContainer: c, testServerContainer } = summary;
|
|
12281
12330
|
const head = testServerContainer ? "stand-in container (test seam)" : c?.error ? `failed (${c.error})` : "image ok";
|
|
12282
|
-
if (!c) return testServerContainer ? [`Server container: ${head}`] : [];
|
|
12331
|
+
if (!c) return testServerContainer ? [`Server container: ${head}${rejectedSuffix(summary)}`] : [];
|
|
12283
12332
|
const error = testServerContainer && c.error ? `, failed (${c.error})` : "";
|
|
12284
12333
|
const calls = `${c.calls} vendor call${c.calls === 1 ? "" : "s"}, ${c.exact} linked exactly, ${c.probable} probable, ${c.unlinked} unlinked`;
|
|
12285
|
-
return [`Server container: ${head}${error}; ${calls}; ${c.forwarded} request${c.forwarded === 1 ? "" : "s"} forwarded to Google`, SERVER_CONTAINER_LIMITS];
|
|
12334
|
+
return [`Server container: ${head}${error}; ${calls}; ${c.forwarded} request${c.forwarded === 1 ? "" : "s"} forwarded to Google${c.error ? "" : rejectedSuffix(summary)}`, SERVER_CONTAINER_LIMITS];
|
|
12286
12335
|
}
|
|
12287
12336
|
var DATALAYER_EVENTS_SHOWN = 3;
|
|
12288
12337
|
function dataLayerLabelRank({ event, kind }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tagreeve",
|
|
3
|
-
"version": "0.7.0-rc.
|
|
3
|
+
"version": "0.7.0-rc.4",
|
|
4
4
|
"description": "Agent-first testing for website tracking and consent.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@faker-js/faker": "10.6.0",
|
|
40
40
|
"node-forge": "1.4.2",
|
|
41
41
|
"playwright": "1.64.1",
|
|
42
|
-
"tldts": "7.4.
|
|
42
|
+
"tldts": "7.4.19",
|
|
43
43
|
"yaml": "2.9.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|