@v-office/site-checks 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -230,6 +230,7 @@ unrelated findings, `match` picks one.
230
230
  | `view-source` | error | A developer's note a visitor can read with View Source: an HTML comment in a built page, before or after `<html>` (exact framework markers and wordless ones allowed); a comment in an inline script, style, `style` attribute or handler, or in shipped JS or CSS (`_astro/`, `public/`), whose text is in a project file (not `node_modules`, `dist/`); a source map. Licence banners are allowed, and a library shipped from `public/` as it comes (`*.min.js`/`*.min.css`, a `vendor/` folder, or a licence banner on top) is not read. | Remove the comment or move it where the build drops it (`//` in frontmatter); turn source maps off. |
231
231
  | `donor-terms` | warning | A `donorTerms` term (whole word) or `donorPatterns` match in the visible text, the title, inline scripts and styles (JSON-LD) or an attribute of a built page, in a built file name, or in the shipped JS and CSS. A warning: pages carry the PMS feed's text; the site's own source is `donor-terms-source`. Skipped without terms and patterns. | Replace the term; list the template site's terms in `donorTerms`. |
232
232
  | `consent-gate` | error | A third-party `<script src>` or `<iframe src>` outside the consent kit's `ConsentEmbed` frame, loading before consent (needs the site's host); an enabled vendor not `approved` in `consent-registry.snapshot.json`; an `ENABLED_VENDOR_IDS` that is not a literal of quoted ids, or a snapshot that does not parse. Skipped without `src/lib/consent/`. | Frame it with `ConsentEmbed`, or register the vendor so the kit injects it after consent; list a consent-free host in `consentAllowedHosts`. |
233
+ | `consent-manager` | warning | On a site that imports the consent manager from website-components (and has no `src/lib/consent/`): a third-party `<script src>` or `<iframe src>` outside a gate's template or a `ConsentScript` (needs the site's host; `consentAllowedHosts` allowed); a pasted Google Tag Manager or Google tag snippet, and `gtm.js` anywhere, in a gate too; a gate rendered inside an island; a page with gated content but no `ConsentBanner` island; a service id that is not a catalog id. | Gate it with `ConsentGate`, `ConsentScript` or `GoogleTagManager`; put the banner in the layout; name the service by its catalog id. |
233
234
  | `feed-image-formats` | warning | A feed photo from the vOffice image hosts requested as JPEG or PNG: in `src`, `srcset` or `poster`, any other attribute (island props, `style`), inline scripts (JSON) and styles (`background-image`); a warning because the photos come from the PMS feed. | Pass feed photos through `webpUrl()`; end an imgproxy URL in `.webp`. |
234
235
  | `listing-noindex` | error | A page that lists rentals (the search page's `data-prerendered-results` container, the `SearchResults` island, or `listingPages`) that is noindex. Not a listing: a rental page (`data-rental-stats`), the favourites grid, a `listingClientOnly` page. Waits while no page but the 404 page and redirect stubs is indexable. | Take the page out of the noindex routes. |
235
236
  | `listing-links` | warning | A page that lists rentals whose list carries no link to a rental page (a page with `data-rental-stats`) in its HTML, so a crawler without JavaScript sees an empty list. Runs once the build has a rental page; a warning because the links come from the PMS feed. | Render the list server-side, or list the page in `listingClientOnly` with the reason. |
package/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as cli } from "./cli-BZoXqFrK.mjs";
2
+ import { n as cli } from "./cli-CZHXyJcd.mjs";
3
3
  // src/bin.ts
4
4
  process.exitCode = await cli(process.argv.slice(2), {
5
5
  out: (line) => console.log(line),
@@ -303,13 +303,13 @@ const blankSourceComments = (raw, extension) => {
303
303
  // src/checks/consentGate.ts
304
304
  /** The consent kit's files in a site: its presence under `src/lib/consent/` is what makes the
305
305
  * check apply; the vendors the site enables and the fleet registry's review of them. */
306
- const KIT_DIR = "src/lib/consent/";
306
+ const KIT_DIR$1 = "src/lib/consent/";
307
307
  const ENABLED_FILE = "src/data/consent.ts";
308
308
  const REGISTRY_FILE = "src/data/consent-registry.snapshot.json";
309
309
  /** The kit's click-to-load frame (`ConsentEmbed.astro`): a third-party frame inside it loads after
310
310
  * consent, so it is not a leak. */
311
311
  const EMBED_TEMPLATE = "template[data-embed-content]";
312
- const hostOf = (url) => {
312
+ const hostOf$1 = (url) => {
313
313
  try {
314
314
  return new URL(url).host;
315
315
  } catch {
@@ -321,7 +321,7 @@ const LEAK_FIX = "Frame it with ConsentEmbed, or register the vendor so the kit
321
321
  const kitSources = (ctx) => {
322
322
  const sources = ctx.sourceFiles(/* @__PURE__ */ new Set([".ts", ".json"]));
323
323
  const byRel = new Map(sources.map((file) => [ctx.rel(file), file]));
324
- return [...byRel.keys()].some((rel) => rel.startsWith(KIT_DIR)) ? byRel : null;
324
+ return [...byRel.keys()].some((rel) => rel.startsWith(KIT_DIR$1)) ? byRel : null;
325
325
  };
326
326
  /** Each vendor the site enables, against the fleet registry's review. What cannot be read is a
327
327
  * finding, never a pass: a list the check cannot read, or a registry that does not parse, would
@@ -376,7 +376,7 @@ const consentGate = {
376
376
  begin: (ctx) => {
377
377
  const byRel = kitSources(ctx);
378
378
  if (!byRel) return null;
379
- const siteHost = ctx.config.site ? hostOf(ctx.config.site) : void 0;
379
+ const siteHost = ctx.config.site ? hostOf$1(ctx.config.site) : void 0;
380
380
  const allowed = new Set(ctx.options.consentAllowedHosts);
381
381
  const findings = [];
382
382
  return {
@@ -386,7 +386,7 @@ const consentGate = {
386
386
  const raw = (el.getAttribute("src") ?? "").trim();
387
387
  const src = raw.startsWith("//") ? `https:${raw}` : raw;
388
388
  if (!/^https?:\/\//i.test(src)) continue;
389
- const host = hostOf(src);
389
+ const host = hostOf$1(src);
390
390
  if (!host || host === siteHost || allowed.has(host)) continue;
391
391
  if (el.closest(EMBED_TEMPLATE)) continue;
392
392
  findings.push({
@@ -410,7 +410,7 @@ const MARKUP = /* @__PURE__ */ new Set([
410
410
  ]);
411
411
  /** The consent layer: the kit's components (ConsentEmbed's template frame, the gated loaders) and
412
412
  * its library inject vendors after consent. */
413
- const CONSENT_LAYER = ["src/components/consent/", KIT_DIR];
413
+ const CONSENT_LAYER = ["src/components/consent/", KIT_DIR$1];
414
414
  /** ConsentEmbed's click-to-load frame written out in a page: loaded after consent. */
415
415
  const EMBED_TEMPLATE_SOURCE = /<template\b[^>]*\bdata-embed-content\b[^>]*>[\s\S]*?<\/template\s*>/gi;
416
416
  /** A `<script>` or `<iframe>` whose `src` is an absolute or protocol-relative URL: quoted, or a
@@ -428,7 +428,7 @@ const consentGateSource = {
428
428
  severity: "error",
429
429
  stage: "src",
430
430
  begin: (ctx) => {
431
- const siteHost = ctx.config.site ? hostOf(ctx.config.site) : void 0;
431
+ const siteHost = ctx.config.site ? hostOf$1(ctx.config.site) : void 0;
432
432
  if (!kitSources(ctx) || !siteHost) return null;
433
433
  const allowed = new Set(ctx.options.consentAllowedHosts);
434
434
  return { finish: () => {
@@ -441,7 +441,7 @@ const consentGateSource = {
441
441
  for (const match of text.matchAll(VENDOR_TAG)) {
442
442
  const url = match[3];
443
443
  const absolute = url.startsWith("//") ? `https:${url}` : url;
444
- const host = hostOf(absolute) ?? absolute.replace(/^https?:\/\//i, "").split("/")[0];
444
+ const host = hostOf$1(absolute) ?? absolute.replace(/^https?:\/\//i, "").split("/")[0];
445
445
  if (host === siteHost || allowed.has(host)) continue;
446
446
  const line = text.slice(0, match.index).split("\n").length;
447
447
  findings.push({
@@ -454,6 +454,132 @@ const consentGateSource = {
454
454
  } };
455
455
  }
456
456
  };
457
+ // src/checks/consentManager.ts
458
+ /** The consent kit sites copied before the platform's consent manager: `consent-gate` checks a
459
+ * site that still has it. */
460
+ const KIT_DIR = "src/lib/consent/";
461
+ const SOURCES = /* @__PURE__ */ new Set([
462
+ ".astro",
463
+ ".tsx",
464
+ ".jsx",
465
+ ".ts",
466
+ ".js",
467
+ ".mjs",
468
+ ".mdx"
469
+ ]);
470
+ /** An import of the consent manager's components or hook from website-components, or a local
471
+ * barrel's re-export of them (as site-manifest reads imports): what makes a site one on the new
472
+ * manager. Its own components of the same names (the kit's) do not count. */
473
+ const MANAGER_IMPORT = /(?:import|export)(?:\s+[\w$]+\s*,)?\s*\{[^}]*\b(?:ConsentBanner|ConsentGate|ConsentScript|GoogleTagManager|useServiceConsent|ConsentServiceTable|ConsentSettingsLink)\b[^}]*\}\s*from\s*["']@v-office\/website-components(?:\/consent)?["']/;
474
+ /** A catalog service id, as site-manifest reads it (CONSENT_ID_RE there). */
475
+ const CATALOG_ID = /^(?=.{1,64}$)[a-z0-9]+(?:-[a-z0-9]+)*$/;
476
+ /** Google's own loaders, written into an inline snippet. */
477
+ const GOOGLE_LOADER = /googletagmanager\.com\/(?:gtm|gtag\/js)/;
478
+ /** The GTM container's loader: only the gate's runtime may load it, behind its lists and policy. A
479
+ * copy anywhere in the HTML, in a gate or a gated script too, loads it around them. */
480
+ const GTM_LOADER = /googletagmanager\.com\/gtm\.js/;
481
+ /** The markers website-components' consent components render (website-headless `CONSENT_MARKERS`). */
482
+ const GATE = "[data-consent-gate]";
483
+ const GATED_SCRIPT = "script[data-consent-service]";
484
+ const GTM_GATE = "template[data-consent-gtm]";
485
+ /** Where the consent runtime defers content: a gate's template. Any other template is put in the
486
+ * page by the site's own code, without asking. */
487
+ const GATE_CONTENT = "template[data-consent-content]";
488
+ const BANNER = "astro-island[component-export=\"ConsentBanner\"]";
489
+ const hostOf = (url) => {
490
+ try {
491
+ return new URL(url).host;
492
+ } catch {
493
+ return;
494
+ }
495
+ };
496
+ const usesManager = (ctx) => {
497
+ const files = ctx.sourceFiles(SOURCES);
498
+ if (files.some((file) => ctx.rel(file).startsWith(KIT_DIR))) return false;
499
+ return files.some((file) => MANAGER_IMPORT.test(blankSourceComments(ctx.readSource(file), file.slice(file.lastIndexOf(".")))));
500
+ };
501
+ /** Every template's content in the page, nested ones too (a query does not reach into a
502
+ * template's content), and whether a gate defers it: its own template, or one around it. */
503
+ const templateContents = (root, deferred = false) => [...root.querySelectorAll("template")].flatMap((template) => {
504
+ const content = template.content;
505
+ const inGate = deferred || template.matches(GATE_CONTENT);
506
+ return [{
507
+ content,
508
+ deferred: inGate
509
+ }, ...templateContents(content, inGate)];
510
+ });
511
+ /** A `<script>` the browser runs: no type, or a JavaScript one. A gated script is `text/plain`. */
512
+ const executable = (script) => {
513
+ const type = (script.getAttribute("type") ?? "").trim().toLowerCase();
514
+ return type === "" || type === "module" || type.includes("javascript");
515
+ };
516
+ /** The service ids a page's consent markup names: gates, gated scripts and the GTM gate's list,
517
+ * nested in a gate's template too. */
518
+ const idsOf = (elements) => [
519
+ ...elements(GATE).map(({ el }) => el.getAttribute("data-consent-gate") ?? ""),
520
+ ...elements(GATED_SCRIPT).map(({ el }) => el.getAttribute("data-consent-service") ?? ""),
521
+ ...elements(GTM_GATE).flatMap(({ el }) => (el.getAttribute("data-consent-services") ?? "").split(/\s+/).filter(Boolean))
522
+ ];
523
+ /**
524
+ * For a site on the consent manager (it imports its components from website-components): nothing
525
+ * third-party loads outside a gate, Google's snippet is not pasted, a gate is not rendered inside an
526
+ * island (React would put its content in the page at once), a page with gated content has the
527
+ * banner that grants it, and every service is named by a catalog id. A warning: the platform's
528
+ * decision is that consent findings never fail a build (docs/internal/websites/consent.md). The
529
+ * third-party scan waits while the site's own host is unknown, as `consent-gate` does.
530
+ */
531
+ const consentManager = {
532
+ id: "consent-manager",
533
+ title: "Third-party content waits for the consent manager",
534
+ severity: "warning",
535
+ stage: "dist",
536
+ begin: (ctx) => {
537
+ if (!usesManager(ctx)) return null;
538
+ const siteHost = ctx.config.site ? hostOf(ctx.config.site) : void 0;
539
+ const allowed = new Set(ctx.options.consentAllowedHosts);
540
+ const findings = [];
541
+ const badIds = /* @__PURE__ */ new Set();
542
+ return {
543
+ visit: (page) => {
544
+ const { document } = page;
545
+ const note = (message) => findings.push({
546
+ path: page.path,
547
+ message
548
+ });
549
+ const templates = templateContents(document);
550
+ const elements = (selector) => [...[...document.querySelectorAll(selector)].map((el) => ({
551
+ el,
552
+ deferred: false
553
+ })), ...templates.flatMap(({ content, deferred }) => [...content.querySelectorAll(selector)].map((el) => ({
554
+ el,
555
+ deferred
556
+ })))];
557
+ for (const { el, deferred } of elements("script[src], iframe[src]")) {
558
+ const raw = (el.getAttribute("src") ?? "").trim();
559
+ if (el.tagName.toLowerCase() === "script" && GTM_LOADER.test(raw)) {
560
+ note("A copy of Google Tag Manager's loader (gtm.js) loads the container around the consent gate's lists and policy. Use <GoogleTagManager containerId services>, listing the services the container runs.");
561
+ continue;
562
+ }
563
+ if (!siteHost || deferred || el.matches(GATED_SCRIPT) && !executable(el)) continue;
564
+ const src = raw.startsWith("//") ? `https:${raw}` : raw;
565
+ if (!/^https?:\/\//i.test(src)) continue;
566
+ const host = hostOf(src);
567
+ if (!host || host === siteHost || allowed.has(host)) continue;
568
+ note(el.tagName.toLowerCase() === "iframe" ? `A third-party <iframe> from ${host} loads before consent. Put it in <ConsentGate service="…">, or list a consent-free host in consentAllowedHosts.` : `A third-party <script> from ${host} loads before consent. Make it <ConsentScript service="…" src="…" />, or list a consent-free host in consentAllowedHosts.`);
569
+ }
570
+ for (const { el: script, deferred } of elements("script:not([src])")) {
571
+ const text = script.textContent ?? "";
572
+ const gated = deferred || script.matches(GATED_SCRIPT) && !executable(script);
573
+ if (GTM_LOADER.test(text) || !gated && executable(script) && GOOGLE_LOADER.test(text)) note("A pasted Google Tag Manager or Google tag snippet loads around the consent gate. Use <GoogleTagManager containerId services>, listing the services the container runs.");
574
+ }
575
+ if (document.querySelector(`astro-island ${GATE}, astro-island ${GATED_SCRIPT}`)) note("A consent gate is rendered inside an island, where React puts its content in the page at once. Render the gate from Astro, or use useServiceConsent in the island.");
576
+ if (document.querySelector(`${GATE}, ${GATED_SCRIPT}, ${GTM_GATE}`) && !document.querySelector(BANNER)) note("The page gates services but has no ConsentBanner island, so visitors cannot grant them. Put <ConsentBanner client:load> in the layout as an island of its own; inside another island it is not found.");
577
+ for (const id of idsOf(elements)) if (!CATALOG_ID.test(id)) badIds.add(id);
578
+ },
579
+ finish: () => [...findings, ...[...badIds].map((id) => ({ message: `"${id}" is not a consent catalog id (lowercase words joined by hyphens, at most 64 characters), so it can never be granted. Name the service by its id in AI Studio's consent catalog.` }))]
580
+ };
581
+ }
582
+ };
457
583
  // src/context.ts
458
584
  const SKIPPED_TEXT_TAGS = /* @__PURE__ */ new Set([
459
585
  "SCRIPT",
@@ -3518,6 +3644,7 @@ const checks = [
3518
3644
  viewSource,
3519
3645
  donorTerms,
3520
3646
  consentGate,
3647
+ consentManager,
3521
3648
  feedImageFormats,
3522
3649
  listingNoindex,
3523
3650
  listingLinks,
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { g as CONFIG_FILE, d as MAX_FINDINGS_PER_CHECK, f as MAX_MESSAGE_CHARS, p as MAX_PATH_CHARS, o as SITE_CHECKS_FILE, t as USAGE, m as blockingResults, v as checks, y as checksOf, n as cli, i as distChecks, s as findingLine, _ as loadOptions, b as readAstroConfig, c as refusalMessage, a as runDistChecks, h as runSiteChecks, r as runStage, l as summarizeBlocking, u as summaryLines } from "./cli-BZoXqFrK.mjs";
1
+ export { g as CONFIG_FILE, d as MAX_FINDINGS_PER_CHECK, f as MAX_MESSAGE_CHARS, p as MAX_PATH_CHARS, o as SITE_CHECKS_FILE, t as USAGE, m as blockingResults, v as checks, y as checksOf, n as cli, i as distChecks, s as findingLine, _ as loadOptions, b as readAstroConfig, c as refusalMessage, a as runDistChecks, h as runSiteChecks, r as runStage, l as summarizeBlocking, u as summaryLines } from "./cli-CZHXyJcd.mjs";
@@ -4,6 +4,7 @@
4
4
 
5
5
  Release notes of `@v-office/site-checks`, newest first. Each version has its own directory.
6
6
 
7
+ - `versions/0.6.0/CHANGELOG.md`: release notes for 0.6.0
7
8
  - `versions/0.5.4/CHANGELOG.md`: release notes for 0.5.4
8
9
  - `versions/0.5.3/CHANGELOG.md`: release notes for 0.5.3
9
10
  - `versions/0.5.2/CHANGELOG.md`: release notes for 0.5.2
@@ -4,6 +4,7 @@
4
4
 
5
5
  Migration guides of `@v-office/site-checks`, newest first. Apply them in order when skipping versions.
6
6
 
7
+ - `versions/0.6.0/MIGRATION.md`: Migration: 0.5.4 to 0.6.0
7
8
  - `versions/0.5.4/MIGRATION.md`: Migration: 0.5.3 to 0.5.4
8
9
  - `versions/0.5.3/MIGRATION.md`: Migration: 0.5.2 to 0.5.3
9
10
  - `versions/0.5.2/MIGRATION.md`: Migration: 0.5.1 to 0.5.2
@@ -0,0 +1,24 @@
1
+ # Changelog: 0.6.0
2
+
3
+ A check for sites on the platform's consent manager (website-components `./consent`): third-party
4
+ content waits for the visitor's consent, and the banner that grants it is on the page.
5
+
6
+ ## Added
7
+
8
+ - `consent-manager` (`dist`, warning), for a site that imports the consent manager's components
9
+ from `@v-office/website-components` and has no `src/lib/consent/` (the old kit, which
10
+ `consent-gate` keeps checking). It reports:
11
+ - a third-party `<script src>` or `<iframe src>` outside a `ConsentGate` or a `ConsentScript`,
12
+ which loads before consent (the site's own host and `consentAllowedHosts` are allowed; it
13
+ waits while the site's host is unknown, as `consent-gate` does);
14
+ - a pasted Google Tag Manager or Google tag snippet, and Google Tag Manager's loader (`gtm.js`)
15
+ anywhere in the page, in a gate too: use `GoogleTagManager`;
16
+ - a `ConsentGate` or `ConsentScript` rendered inside an island, where React puts its content in
17
+ the page at once;
18
+ - a page with gated content but no `ConsentBanner` island, where nothing can be granted;
19
+ - a service id that is not a catalog id (lowercase words joined by hyphens, at most 64
20
+ characters).
21
+
22
+ Every finding is a warning: consent findings never fail a build.
23
+
24
+ Every other check, the configuration keys, the exit codes and the report's shape stay the same.
@@ -0,0 +1,12 @@
1
+ # Migration: 0.5.4 to 0.6.0
2
+
3
+ No changes required. A site on the consent manager may see new `consent-manager` warnings: gate
4
+ what each one names with `ConsentGate`, `ConsentScript` or `GoogleTagManager`, put
5
+ `<ConsentBanner client:load locale={locale} />` in the layout, and name every service by its id
6
+ in AI Studio's consent catalog. A consent-free third-party host goes in `consentAllowedHosts`.
7
+
8
+ ## 1. Upgrade
9
+
10
+ ```sh
11
+ pnpm add @v-office/site-checks@0.6.0
12
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v-office/site-checks",
3
- "version": "0.5.4",
3
+ "version": "0.6.0",
4
4
  "description": "The checks over a v-office website in two stages, `site-checks src` before the build and `site-checks dist` after it, which AI Studio's build worker runs on every build from its own pinned copy; the report has the shape of the build worker's dist-check report, and a site excludes the findings it accepts in site-checks.config.json",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {