@simmalugnt-se/payload-consent 0.6.10 → 0.6.11

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.11
4
+
5
+ - A scan judges findings by the Cookie services and their categories again, as in 0.6.9. The rules
6
+ added in 0.6.10 are gone: a service in Necessary counts as in order again, whatever it loads, and
7
+ no finding is judged by its kind of request. They were our own reading, not c15t's or the law's.
8
+ - The per-finding instructions and the email's list of them are gone. The Scan tab says per group how
9
+ to handle findings, with c15t's own ways: a known integration, `ConsentFrame`, or `scripts`. The
10
+ email again gives the counts and a link.
11
+ - Add to service starts in Necessary again when the Open Cookie Database has no suggestion.
12
+ - Kept from 0.6.10: unreached pages make a scan incomplete, a finding names a page it was seen on,
13
+ and the README's Google Tag Manager example loads the tag after consent.
14
+
3
15
  ## 0.6.10
4
16
 
5
17
  - A scan says what to do. Each finding that needs handling carries one instruction, in the Scan tab
package/README.md CHANGED
@@ -172,12 +172,10 @@ every cookie, localStorage key and third-party host:
172
172
  `_ga_*` rather than one property's `_ga_G123`), and the scan is judged again.
173
173
  - **In order**: explained and seen only where allowed.
174
174
 
175
- A finding that needs handling says what to do, judged from what the scan measured: code or a frame
176
- from another site before any choice must wait for consent, even in a service marked Necessary; a
177
- font or stylesheet from another site belongs on the site's own domain; a plain file with nothing
178
- stored needs its provider checked; storage no service explains goes in one. The email lists the same,
179
- with a page each was seen on. `docs/research/consent-rules.md` in the repository has the rule and its
180
- sources.
175
+ The Scan tab says how to handle each group, using c15t's own ways: a tool in the list under Loaded
176
+ by is picked there, an embed goes in `ConsentFrame`, and other code goes in `scripts`, so c15t loads
177
+ it after consent. The plugin decides nothing about what is necessary: that is the category you give
178
+ the service, by what it does on the site. A finding names a page it was seen on.
181
179
 
182
180
  Findings new since the previous scan are marked. A scan's raw results stay in `consent-scans`.
183
181
 
@@ -2,7 +2,6 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { Button, Collapsible, Pill, SelectInput, ShimmerEffect, TextInput, useConfig, useFormFields, useLocale, useTranslation, } from "@payloadcms/ui";
4
4
  import { useCallback, useEffect, useRef, useState, } from "react";
5
- import { adviceText } from "../advice.js";
6
5
  import { CATEGORIES } from "../defaults.js";
7
6
  import { CONSENT_SCANS } from "../types.js";
8
7
  import { describeProblem, estimateLeft, findingHeading, finishedPages, formatElapsed, markPace, pagePath, scanVerdict, } from "./scan-view.js";
@@ -86,8 +85,8 @@ const COPY = {
86
85
  ok: "In order",
87
86
  },
88
87
  explain: {
89
- action: "Loads before or without consent. Each one says what to do.",
90
- unknown: "Add each to a service, new or existing, or remove it from the site.",
88
+ action: "Seen where their category is not allowed. A tool in the list under Loaded by: pick “This plugin, after consent” on the service. An embed: wrap it in ConsentFrame. Other code: pass it to ConsentProvider's scripts, so c15t loads it after consent.",
89
+ unknown: "Add each to a service: Necessary if the site cannot work without it, otherwise the category that fits. Or remove it from the site.",
91
90
  ok: "In a Cookie service, and seen only where its category is allowed.",
92
91
  },
93
92
  // What the finding is, leading the sentence of when it was seen.
@@ -205,8 +204,8 @@ const COPY = {
205
204
  ok: "I ordning",
206
205
  },
207
206
  explain: {
208
- action: "Laddas före eller utan samtycke. Varje rad säger vad du ska göra.",
209
- unknown: "Lägg till var och en i en tjänst, ny eller befintlig, eller ta bort den från webbplatsen.",
207
+ action: "Syns där kategorin inte är tillåten. Ett verktyg i listan under Laddas av: välj ”Det här pluginet, efter samtycke” i tjänsten. En inbäddning: lägg den i ConsentFrame. Annan kod: skicka den till ConsentProviders scripts, så laddar c15t den efter samtycke.",
208
+ unknown: "Lägg var och en i en tjänst: Nödvändig om webbplatsen inte fungerar utan den, annars den kategori som passar. Eller ta bort den från webbplatsen.",
210
209
  ok: "Finns i en Cookietjänst och syns bara där kategorin är tillåten.",
211
210
  },
212
211
  seen: {
@@ -491,8 +490,7 @@ export function ScanPanel() {
491
490
  function FindingRow({ api, copy, finding, language, locale, onAdded, }) {
492
491
  const suggestion = finding.suggestion;
493
492
  const [service, setService] = useState(suggestion?.platform ?? (finding.kind === "host" ? finding.name : ""));
494
- // What must wait for consent starts in a category that does, not in Necessary.
495
- const [category, setCategory] = useState(suggestion?.category ?? (finding.advice === "waitForConsent" ? "functionality" : "necessary"));
493
+ const [category, setCategory] = useState(suggestion?.category ?? "necessary");
496
494
  const [busy, setBusy] = useState(false);
497
495
  const [error, setError] = useState();
498
496
  async function add() {
@@ -547,7 +545,7 @@ function FindingRow({ api, copy, finding, language, locale, onAdded, }) {
547
545
  const without = serviceCategory ? finding.withoutConsent : [];
548
546
  const rest = finding.states.filter((id) => !without.includes(id));
549
547
  const path = `consent-scan-${finding.key}`;
550
- return (_jsxs("li", { className: "consent-scan__row", children: [_jsxs("div", { className: "consent-scan__row-head", children: [_jsx("h4", { className: "consent-scan__name", children: heading.from === "name" ? (_jsx("code", { children: heading.text })) : heading.from === "suggestion" ? (copy.looksLike(heading.text)) : (heading.text) }), (finding.beforeConsent && finding.status !== "ok") || finding.isNew ? (_jsxs("div", { className: "consent-scan__pills", children: [finding.beforeConsent && finding.status !== "ok" ? (_jsx(Pill, { pillStyle: "error", size: "small", children: copy.beforeConsent })) : null, finding.isNew ? (_jsx(Pill, { pillStyle: "light", size: "small", children: copy.isNew })) : null] })) : null] }), _jsx("p", { className: "consent-scan__seen", children: without.length ? (_jsxs(_Fragment, { children: [`${copy.seen[finding.kind]} ${whenLabel(copy, without, language)}`, _jsx("strong", { children: copy.notAllowed(serviceCategory) }), ".", rest.length ? ` ${copy.also(whenLabel(copy, rest, language))}` : null] })) : (`${copy.seen[finding.kind]} ${whenLabel(copy, finding.states, language)}.`) }), finding.advice && finding.status !== "ok" ? (_jsx("p", { className: "consent-scan__advice", children: adviceText(finding.advice, language) })) : null, suggestion?.description && heading.from === "suggestion" ? (_jsx("p", { className: "consent-scan__note", children: suggestion.description })) : null, details.length ? (_jsx("p", { className: "consent-scan__details", children: details.map((detail, index) => (_jsx("span", { children: detail }, typeof detail === "string" ? detail : index))) })) : null, finding.status === "unknown" ? (_jsxs("div", { className: "consent-scan__classify", children: [_jsx(TextInput, { label: copy.service, onChange: (event) => setService(event.target.value), onKeyDown: (event) => {
548
+ return (_jsxs("li", { className: "consent-scan__row", children: [_jsxs("div", { className: "consent-scan__row-head", children: [_jsx("h4", { className: "consent-scan__name", children: heading.from === "name" ? (_jsx("code", { children: heading.text })) : heading.from === "suggestion" ? (copy.looksLike(heading.text)) : (heading.text) }), (finding.beforeConsent && finding.status !== "ok") || finding.isNew ? (_jsxs("div", { className: "consent-scan__pills", children: [finding.beforeConsent && finding.status !== "ok" ? (_jsx(Pill, { pillStyle: "error", size: "small", children: copy.beforeConsent })) : null, finding.isNew ? (_jsx(Pill, { pillStyle: "light", size: "small", children: copy.isNew })) : null] })) : null] }), _jsx("p", { className: "consent-scan__seen", children: without.length ? (_jsxs(_Fragment, { children: [`${copy.seen[finding.kind]} ${whenLabel(copy, without, language)}`, _jsx("strong", { children: copy.notAllowed(serviceCategory) }), ".", rest.length ? ` ${copy.also(whenLabel(copy, rest, language))}` : null] })) : (`${copy.seen[finding.kind]} ${whenLabel(copy, finding.states, language)}.`) }), suggestion?.description && heading.from === "suggestion" ? (_jsx("p", { className: "consent-scan__note", children: suggestion.description })) : null, details.length ? (_jsx("p", { className: "consent-scan__details", children: details.map((detail, index) => (_jsx("span", { children: detail }, typeof detail === "string" ? detail : index))) })) : null, finding.status === "unknown" ? (_jsxs("div", { className: "consent-scan__classify", children: [_jsx(TextInput, { label: copy.service, onChange: (event) => setService(event.target.value), onKeyDown: (event) => {
551
549
  // Enter adds the finding; it would otherwise submit the Cookies form around the tab.
552
550
  if (event.key !== "Enter")
553
551
  return;
@@ -1,4 +1,3 @@
1
- import { type Advice } from "./advice.ts";
2
1
  import type { Category } from "./defaults.ts";
3
2
  import type { ServiceDocument } from "./site-config.ts";
4
3
  /** A consent state the scanner runs, and the categories the visitor allowed in it. */
@@ -88,10 +87,6 @@ export type Finding = {
88
87
  suggestion?: Suggestion;
89
88
  /** For hosts: the tracker lists that flagged it (EasyPrivacy and others). */
90
89
  trackerLists?: string[];
91
- /** For hosts: requests by kind in the states with only necessary storage, to judge by. */
92
- kinds?: Record<string, number>;
93
- /** What to do about it. */
94
- advice?: Advice;
95
90
  };
96
91
  export type ScanSummary = Record<FindingStatus, number> & {
97
92
  new: number;
package/dist/evaluate.js CHANGED
@@ -1,4 +1,3 @@
1
- import { hostAdvice } from "./advice.js";
2
1
  /**
3
2
  * Why a finished scan may not show everything: a state the scanner did not return or that
4
3
  * visited no pages, its errors, and sitemaps it could not read. Empty when the scan is complete.
@@ -99,12 +98,6 @@ export function evaluateScan({ states, results, services, previousKeys = [], })
99
98
  trackerLists: lists.get(host.host),
100
99
  page: host.pages?.[0],
101
100
  });
102
- const finding = found.get(`host::${host.host}`);
103
- if (finding && host.kinds && necessaryOnly.has(state.id)) {
104
- finding.kinds ??= {};
105
- for (const [kind, count] of Object.entries(host.kinds))
106
- finding.kinds[kind] = (finding.kinds[kind] ?? 0) + count;
107
- }
108
101
  }
109
102
  }
110
103
  for (const finding of found.values()) {
@@ -123,38 +116,6 @@ export function evaluateScan({ states, results, services, previousKeys = [], })
123
116
  finding.withoutConsent = finding.states.filter((stateId) => category !== "necessary" && !allowedIn.get(stateId)?.has(category));
124
117
  finding.status = finding.withoutConsent.length ? "action" : "ok";
125
118
  }
126
- for (const finding of found.values()) {
127
- if (finding.service === "c15t")
128
- continue;
129
- if (finding.kind === "host") {
130
- if (!finding.beforeConsent) {
131
- if (finding.status === "action")
132
- finding.advice = "waitForConsent";
133
- continue;
134
- }
135
- finding.advice = hostAdvice(finding.kinds, Boolean(finding.trackerLists?.length));
136
- // A service marked necessary does not excuse code from another site before any choice.
137
- if (finding.status !== "unknown" && finding.advice !== "checkProvider" && finding.advice)
138
- finding.status = "action";
139
- // A category seen where it is not allowed must wait, whatever kind of request it is.
140
- if (finding.status === "action" && finding.withoutConsent.length)
141
- finding.advice = "waitForConsent";
142
- if (finding.status === "action")
143
- finding.advice ??= "waitForConsent";
144
- }
145
- else if (finding.status === "action") {
146
- finding.advice = "waitForConsent";
147
- }
148
- else if (finding.status === "unknown" && finding.beforeConsent) {
149
- finding.advice = "classifyStorage";
150
- }
151
- else if (finding.category === "necessary" &&
152
- finding.suggestion?.category &&
153
- finding.suggestion.category !== "necessary") {
154
- finding.status = "action";
155
- finding.advice = "reviewNecessary";
156
- }
157
- }
158
119
  const order = { action: 0, unknown: 1, ok: 2 };
159
120
  const findings = [...found.values()].sort((a, b) => order[a.status] - order[b.status] ||
160
121
  Number(b.beforeConsent) - Number(a.beforeConsent) ||
package/dist/notify.d.ts CHANGED
@@ -1,18 +1,10 @@
1
1
  import type { Payload } from "payload";
2
- import type { Finding, ScanSummary } from "./evaluate.ts";
3
- type Language = "en" | "sv";
2
+ import type { ScanSummary } from "./evaluate.ts";
4
3
  export type ScanOutcome = {
5
4
  url: string;
6
5
  status: "done" | "failed";
7
6
  error?: string | null;
8
7
  summary?: ScanSummary | null;
9
- /** What the scan found; the email lists what needs handling and how. */
10
- findings?: Finding[] | null;
11
- };
12
- /** `name (page): what to do`, for each finding with advice that is not in order. */
13
- export declare function listedActions(findings: Finding[] | null | undefined, language: Language): {
14
- lines: string[];
15
- more: number;
16
8
  };
17
9
  /**
18
10
  * A scan worth an email: it failed, could not see everything, found something to handle, or found
@@ -24,4 +16,3 @@ export declare function needsNotice(outcome: ScanOutcome): boolean;
24
16
  * email adapter, when it needs a look. Admin's default language picks the text.
25
17
  */
26
18
  export declare function notifyScan(payload: Payload, outcome: ScanOutcome): Promise<void>;
27
- export {};
package/dist/notify.js CHANGED
@@ -1,27 +1,4 @@
1
- import { adviceText } from "./advice.js";
2
1
  import { CONSENT_GLOBAL } from "./types.js";
3
- /** The most an email lists: the Scan tab has the rest. */
4
- const MAX_LISTED = 10;
5
- /** `name (page): what to do`, for each finding with advice that is not in order. */
6
- export function listedActions(findings, language) {
7
- const open = (findings ?? []).filter((finding) => finding.advice && finding.status !== "ok");
8
- const page = (url) => {
9
- if (!url)
10
- return "";
11
- try {
12
- return ` (${new URL(url).pathname})`;
13
- }
14
- catch {
15
- return "";
16
- }
17
- };
18
- return {
19
- lines: open
20
- .slice(0, MAX_LISTED)
21
- .map((finding) => `${finding.name}${page(finding.page)}: ${adviceText(finding.advice, language)}`),
22
- more: Math.max(0, open.length - MAX_LISTED),
23
- };
24
- }
25
2
  /**
26
3
  * A scan worth an email: it failed, could not see everything, found something to handle, or found
27
4
  * something new.
@@ -42,7 +19,6 @@ const COPY = {
42
19
  done: (o) => `The cookie scan of ${o.url} found ${count(o.summary, "en")}.${problems(o).length
43
20
  ? ` It is incomplete, so it may have missed something: ${problems(o).slice(0, 3).join("; ")}.`
44
21
  : ""}`,
45
- more: (n) => `And ${n} more in the Scan tab.`,
46
22
  open: "Open Cookies in Admin",
47
23
  why: "You get this because you are chosen under Cookies → Scan.",
48
24
  },
@@ -54,7 +30,6 @@ const COPY = {
54
30
  done: (o) => `Cookieskanningen av ${o.url} hittade ${count(o.summary, "sv")}.${problems(o).length
55
31
  ? ` Den är ofullständig och kan ha missat något: ${problems(o).slice(0, 3).join("; ")}.`
56
32
  : ""}`,
57
- more: (n) => `Och ${n} till under fliken Skanning.`,
58
33
  open: "Öppna Cookies i Admin",
59
34
  why: "Du får det här för att du är vald under Cookies → Skanning.",
60
35
  },
@@ -112,8 +87,6 @@ export async function notifyScan(payload, outcome) {
112
87
  }
113
88
  })();
114
89
  const text = outcome.status === "failed" ? copy.failed(outcome) : copy.done(outcome);
115
- const { lines, more } = listedActions(outcome.findings, language);
116
- const andMore = more ? copy.more(more) : "";
117
90
  // Admin is on the scanned site's origin when Payload has no serverURL.
118
91
  const base = payload.config.serverURL || origin(outcome.url);
119
92
  const link = `${base}${payload.config.routes.admin}/globals/${CONSENT_GLOBAL}`;
@@ -121,8 +94,8 @@ export async function notifyScan(payload, outcome) {
121
94
  await payload.sendEmail({
122
95
  to,
123
96
  subject: copy.subject(outcome, host),
124
- text: `${text}\n\n${lines.map((line) => `- ${line}`).join("\n")}${andMore ? `\n${andMore}` : ""}${lines.length ? "\n\n" : ""}${copy.open}: ${link}\n\n${copy.why}`,
125
- html: `<p>${escape(text)}</p>${lines.length ? `<ul>${lines.map((line) => `<li>${escape(line)}</li>`).join("")}</ul>` : ""}${andMore ? `<p>${escape(andMore)}</p>` : ""}<p><a href="${escape(link)}">${copy.open}</a></p><p><small>${copy.why}</small></p>`,
97
+ text: `${text}\n\n${copy.open}: ${link}\n\n${copy.why}`,
98
+ html: `<p>${escape(text)}</p><p><a href="${escape(link)}">${copy.open}</a></p><p><small>${copy.why}</small></p>`,
126
99
  });
127
100
  }
128
101
  catch (error) {
package/dist/scans.js CHANGED
@@ -342,7 +342,6 @@ function endpoints(options) {
342
342
  status: done ? "done" : "failed",
343
343
  error: done ? null : (result.error ?? "The scan failed"),
344
344
  summary: (summary ?? undefined),
345
- findings: evaluated?.findings,
346
345
  });
347
346
  return Response.json({ ok: true });
348
347
  },
@@ -138,10 +138,6 @@
138
138
  color: var(--theme-elevation-800);
139
139
  word-break: break-all;
140
140
  }
141
- .consent-scan__advice {
142
- margin: 0;
143
- font-weight: 500;
144
- }
145
141
  .consent-scan__note {
146
142
  margin: 0;
147
143
  color: var(--theme-elevation-500);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-consent",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
4
4
  "description": "Cookie consent for Payload sites: banner texts, services and scans in Admin",
5
5
  "keywords": [
6
6
  "payload",
package/dist/advice.d.ts DELETED
@@ -1,24 +0,0 @@
1
- /**
2
- * What to do about a finding, from what a scan measured. The rule behind it and its sources are in
3
- * `docs/research/consent-rules.md` in the repository.
4
- */
5
- export type Advice =
6
- /** Third-party code, a frame, a tracking pixel, or a category seen where it is not allowed. */
7
- "waitForConsent"
8
- /** A font or stylesheet from another site gives that site the visitor's IP address. */
9
- | "selfHost"
10
- /** A plain file from another site, with nothing stored: fine if the provider only delivers it. */
11
- | "checkProvider"
12
- /** Storage no service explains. */
13
- | "classifyStorage"
14
- /** Registered as necessary, but the Open Cookie Database puts it in another category. */
15
- | "reviewNecessary";
16
- type Language = "en" | "sv";
17
- export declare function adviceText(advice: Advice, language: Language): string;
18
- /**
19
- * What a host's requests before consent call for. No kinds at all means the scanner saw the host
20
- * only inside a frame, so it is treated as code; `undefined` kinds come from an older scanner, which
21
- * did not report them.
22
- */
23
- export declare function hostAdvice(kinds: Record<string, number> | undefined, onTrackerList: boolean): Advice | undefined;
24
- export {};
package/dist/advice.js DELETED
@@ -1,37 +0,0 @@
1
- const TEXTS = {
2
- en: {
3
- waitForConsent: "Must wait for consent. Put it in the category that fits. If a c15t integration loads it, pick that integration on the service; if your code loads it, wrap it in ConsentFrame.",
4
- selfHost: "Serve it from the site's own domain, for example fonts with next/font, so the visitor's IP address does not go to another site.",
5
- checkProvider: "Only a file, and nothing is stored, so it can load before consent if the provider just delivers it for the site. Add the provider to a service and check its terms.",
6
- classifyStorage: "Add it to a service. Unless the site cannot work without it for something the visitor asked for, it must wait for consent.",
7
- reviewNecessary: "Registered as necessary, but the Open Cookie Database says otherwise. Move it to the category that fits and make it wait for consent, or remove the service from Necessary only if the site cannot work without it.",
8
- },
9
- sv: {
10
- waitForConsent: "Måste vänta på samtycke. Lägg den i rätt kategori. Laddas den av en c15t-integration, välj integrationen i tjänsten. Laddas den av din kod, lägg den i ConsentFrame.",
11
- selfHost: "Lägg filen på webbplatsens egen domän, till exempel typsnitt med next/font, så att besökarens IP-adress inte går till en annan webbplats.",
12
- checkProvider: "Bara en fil, och inget lagras, så den får laddas före samtycke om leverantören enbart levererar den åt webbplatsen. Lägg leverantören i en tjänst och kontrollera dess villkor.",
13
- classifyStorage: "Lägg den i en tjänst. Om inte webbplatsen behöver den för något besökaren har bett om måste den vänta på samtycke.",
14
- reviewNecessary: "Står som nödvändig, men Open Cookie Database säger något annat. Flytta den till rätt kategori och låt den vänta på samtycke, eller behåll den bara om webbplatsen inte fungerar utan den.",
15
- },
16
- };
17
- export function adviceText(advice, language) {
18
- return TEXTS[language][advice];
19
- }
20
- /** Request kinds that only deliver a file: they run no code on the visitor's device. */
21
- const PASSIVE = new Set(["image", "media", "manifest", "other"]);
22
- const STYLING = new Set(["font", "stylesheet"]);
23
- /**
24
- * What a host's requests before consent call for. No kinds at all means the scanner saw the host
25
- * only inside a frame, so it is treated as code; `undefined` kinds come from an older scanner, which
26
- * did not report them.
27
- */
28
- export function hostAdvice(kinds, onTrackerList) {
29
- if (!kinds)
30
- return undefined;
31
- const seen = Object.keys(kinds);
32
- if (!seen.length || onTrackerList)
33
- return "waitForConsent";
34
- if (seen.some((kind) => !PASSIVE.has(kind) && !STYLING.has(kind)))
35
- return "waitForConsent";
36
- return seen.some((kind) => STYLING.has(kind)) ? "selfHost" : "checkProvider";
37
- }