@simmalugnt-se/payload-consent 0.6.2 → 0.6.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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.4
4
+
5
+ - The Scan tab's time left counts down. It grew while a page took its time, since it was worked
6
+ out each second from the scan's start, start-up included, and the pages already done; it now
7
+ takes the pace between pages as the scanner begins them, counts down until the next one and
8
+ says "almost done" once the pace is spent. The card asks every two seconds instead of four.
9
+ - A scan that ends no longer flashes "Waiting for the scanner": while the result is on its way
10
+ from the scanner, the card says it is saving the result, with a full bar. The result then fades
11
+ in with a "Just finished" pill, so it does not look like the scan before it.
12
+ - The README says that `consent-scanner` binds each token to its site's hosts and refuses scans
13
+ and callbacks for other hosts, which hosts to give it, and that it treats a site with and
14
+ without `www.` as one, so a Site address without `www.` still finds the pages on `www.`
15
+ (`consent-scanner` at `0b7aba1` or later).
16
+
17
+ ## 0.6.3
18
+
19
+ - The Scan tab's findings follow the card above them. Each group (Needs action, Not in the Cookie
20
+ services, In order) is a Payload Collapsible with its count in the card's colours; In order
21
+ starts closed. A finding shows its name and where it was seen as a short list, the Open Cookie
22
+ Database's suggestion in a box of its own, and Add to service with Payload's text and select
23
+ fields in place of the browser's. Enter in Service adds the finding instead of saving the
24
+ Cookies form. The groups' explanations say what to do rather than repeat the card.
25
+ - A finding reads in plain words. It leads with its service, or "Looks like Meta Pixel" from the
26
+ Open Cookie Database, and says in one sentence what it is and when it appeared: "Cookie set for
27
+ new visitors before they choose, although Statistics is not allowed then. Also after the visitor
28
+ accepts." The raw name, domain, category, tracker lists and a page it was seen on follow on a
29
+ quieter line. "Stored in the browser" and "Contacts another site" replace "localStorage" and
30
+ "Third-party host", in the card's counts too.
31
+
3
32
  ## 0.6.2
4
33
 
5
34
  - The Scan tab opens with a card for the scan. While it runs, the card follows it page by page
package/README.md CHANGED
@@ -130,6 +130,13 @@ consentPlugin({
130
130
  })
131
131
  ```
132
132
 
133
+ The scanner binds each token to its site's hosts (`token@example.se|example.vercel.app` in its
134
+ `SCANNER_TOKENS`), and refuses a scan whose address or callback is on another host: give it the
135
+ host of the scanned address and, when results come back elsewhere (`serverURL` or
136
+ `callbackBaseUrl`), that host too. A host covers itself with and without `www.`, and the scanner
137
+ treats a site with and without `www.` as one, so a Site address of `https://example.se` still finds
138
+ the pages on `https://www.example.se`. Both need `consent-scanner` at `0b7aba1` or later.
139
+
133
140
  The scanner picks the pages to visit from the site's sitemaps. A site with search indexing off
134
141
  often serves empty ones, and then only the start page is scanned. With `scanner.pages`, a scan
135
142
  sends the published documents of those collections instead: read as a visitor would, in the
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { Button, Collapsible, Pill, useConfig, useFormFields, useLocale, useTranslation, } from "@payloadcms/ui";
4
- import { useCallback, useEffect, useState } from "react";
3
+ import { Button, Collapsible, Pill, SelectInput, TextInput, useConfig, useFormFields, useLocale, useTranslation, } from "@payloadcms/ui";
4
+ import { useCallback, useEffect, useRef, useState, } from "react";
5
5
  import { CATEGORIES } from "../defaults.js";
6
6
  import { CONSENT_SCANS } from "../types.js";
7
- import { describeProblem, estimateLeft, finishedPages, formatElapsed, pagePath, scanVerdict, } from "./scan-view.js";
7
+ import { describeProblem, estimateLeft, findingHeading, finishedPages, formatElapsed, markPace, pagePath, scanVerdict, } from "./scan-view.js";
8
8
  import "../styles/admin.css";
9
9
  const COPY = {
10
10
  en: {
@@ -16,6 +16,7 @@ const COPY = {
16
16
  none: "Not scanned",
17
17
  queued: "Waiting",
18
18
  running: "Scanning",
19
+ finishing: "Saving",
19
20
  failed: "Failed",
20
21
  action: "Needs action",
21
22
  unknown: "Not explained",
@@ -24,10 +25,12 @@ const COPY = {
24
25
  clean: "In order",
25
26
  },
26
27
  newPill: (n) => `${n} new`,
28
+ justFinished: "Just finished",
27
29
  title: {
28
30
  none: "The site has not been scanned yet",
29
31
  queued: "Waiting for the scanner",
30
32
  running: "Scanning the site",
33
+ finishing: "Saving the result",
31
34
  failed: "The scan failed",
32
35
  action: (n) => `${n} ${n === 1 ? "needs" : "need"} action`,
33
36
  unknown: (n) => `${n} not in the Cookie services`,
@@ -39,6 +42,8 @@ const COPY = {
39
42
  none: "Scan now to see which cookies, storage and other sites the published site uses, before and after the visitor's choice.",
40
43
  queued: (position) => position ? `Number ${position} in line.` : "It starts when the scanner is free.",
41
44
  choosing: "Choosing the pages to visit…",
45
+ finishing: "The scan is done. Its result is on its way to this site.",
46
+ late: "The result has not arrived. If the scanner could not reach this site, the scan is marked as failed within a day.",
42
47
  action: "Services load where the visitor has not allowed their category.",
43
48
  unknown: "The scan found storage or other sites that no Cookie service explains.",
44
49
  incomplete: "It may have missed something. Scan again once this is fixed:",
@@ -51,12 +56,13 @@ const COPY = {
51
56
  ...(stage.states > 1 ? [`state ${stage.stateNumber} of ${stage.states}`] : []),
52
57
  ].join(" · "),
53
58
  elapsed: (time, left) => (left ? `${time} · about ${left} left` : time),
59
+ almostDone: (time) => `${time} · almost done`,
54
60
  progress: (finished, total) => `${finished} of ${total} page visits done`,
55
61
  stats: {
56
62
  pages: (n, of) => n === of ? (n === 1 ? "page" : "pages") : `of ${of} ${of === 1 ? "page" : "pages"}`,
57
63
  states: (n) => (n === 1 ? "state" : "states"),
58
64
  cookies: (n) => (n === 1 ? "cookie" : "cookies"),
59
- storage: () => "localStorage",
65
+ storage: () => "stored in the browser",
60
66
  hosts: (n) => (n === 1 ? "other site" : "other sites"),
61
67
  },
62
68
  scanned: (date, took) => `Scanned ${date}${took ? ` · took ${took}` : ""}`,
@@ -78,21 +84,34 @@ const COPY = {
78
84
  ok: "In order",
79
85
  },
80
86
  explain: {
81
- action: "These services load in a state where their category is not allowed. Load them through the plugin (Loaded by: this plugin) or make the site's code wait for consent.",
82
- unknown: "Nothing in the Cookie services explains these. Add each to a service, or remove it from the site.",
83
- ok: "Explained by the Cookie services and seen only where their category is allowed.",
87
+ action: "Seen where their category is not allowed. Set Loaded by on the service to “This plugin, after consent”, or make the site's code wait for consent.",
88
+ unknown: "Add each to a service, new or existing, or remove it from the site.",
89
+ ok: "In a Cookie service, and seen only where its category is allowed.",
84
90
  },
85
- kinds: { cookie: "Cookie", localStorage: "localStorage", host: "Third-party host" },
91
+ // What the finding is, leading the sentence of when it was seen.
92
+ seen: {
93
+ cookie: "Cookie set",
94
+ localStorage: "Stored in the browser",
95
+ host: "Contacts another site",
96
+ },
97
+ when: {
98
+ "no-choice": "for new visitors before they choose",
99
+ "reject-all": "after the visitor rejects",
100
+ "accept-all": "after the visitor accepts",
101
+ },
102
+ whenOnly: (category) => `when only ${category} is allowed`,
103
+ notAllowed: (category) => `, although ${category} is not allowed then`,
104
+ also: (when) => `Also ${when}.`,
105
+ looksLike: (platform) => `Looks like ${platform}`,
106
+ database: "Open Cookie Database",
107
+ trackerLists: (lists) => `On tracker lists: ${lists}`,
108
+ seenOn: "A page it was seen on",
86
109
  beforeConsent: "Before consent",
87
110
  isNew: "New",
88
- seenIn: "Seen in",
89
- withoutConsent: "without consent in",
90
111
  service: "Service",
91
112
  category: "Category",
92
113
  add: "Add to service",
93
114
  adding: "Adding…",
94
- suggestion: "Suggestion",
95
- trackerList: "On tracker list",
96
115
  states: {
97
116
  "no-choice": "new visitor",
98
117
  "reject-all": "after rejecting",
@@ -115,6 +134,7 @@ const COPY = {
115
134
  none: "Inte skannad",
116
135
  queued: "Väntar",
117
136
  running: "Skannar",
137
+ finishing: "Sparar",
118
138
  failed: "Misslyckades",
119
139
  action: "Åtgärd krävs",
120
140
  unknown: "Okänt",
@@ -123,10 +143,12 @@ const COPY = {
123
143
  clean: "I ordning",
124
144
  },
125
145
  newPill: (n) => `${n} nya`,
146
+ justFinished: "Nyss klar",
126
147
  title: {
127
148
  none: "Webbplatsen har inte skannats än",
128
149
  queued: "Väntar på skannern",
129
150
  running: "Skannar webbplatsen",
151
+ finishing: "Sparar resultatet",
130
152
  failed: "Skanningen misslyckades",
131
153
  action: (n) => `${n} kräver åtgärd`,
132
154
  unknown: (n) => `${n} finns inte bland Cookietjänsterna`,
@@ -138,6 +160,8 @@ const COPY = {
138
160
  none: "Skanna nu för att se vilka cookies, vilken lagring och vilka andra webbplatser den publicerade webbplatsen använder, före och efter besökarens val.",
139
161
  queued: (position) => position ? `Nummer ${position} i kön.` : "Den startar när skannern är ledig.",
140
162
  choosing: "Väljer vilka sidor som ska besökas…",
163
+ finishing: "Skanningen är klar. Resultatet är på väg till webbplatsen.",
164
+ late: "Resultatet har inte kommit. Om skannern inte nådde webbplatsen markeras skanningen som misslyckad inom ett dygn.",
141
165
  action: "Tjänster laddas där besökaren inte har tillåtit kategorin.",
142
166
  unknown: "Skanningen hittade lagring eller andra webbplatser som ingen Cookietjänst förklarar.",
143
167
  incomplete: "Den kan ha missat något. Skanna igen när det här är åtgärdat:",
@@ -150,12 +174,13 @@ const COPY = {
150
174
  ...(stage.states > 1 ? [`läge ${stage.stateNumber} av ${stage.states}`] : []),
151
175
  ].join(" · "),
152
176
  elapsed: (time, left) => (left ? `${time} · ungefär ${left} kvar` : time),
177
+ almostDone: (time) => `${time} · snart klar`,
153
178
  progress: (finished, total) => `${finished} av ${total} sidbesök klara`,
154
179
  stats: {
155
180
  pages: (n, of) => n === of ? (n === 1 ? "sida" : "sidor") : `av ${of} ${of === 1 ? "sida" : "sidor"}`,
156
181
  states: (n) => (n === 1 ? "läge" : "lägen"),
157
182
  cookies: (n) => (n === 1 ? "cookie" : "cookies"),
158
- storage: () => "localStorage",
183
+ storage: () => "sparat i webbläsaren",
159
184
  hosts: (n) => (n === 1 ? "annan webbplats" : "andra webbplatser"),
160
185
  },
161
186
  scanned: (date, took) => `Skannad ${date}${took ? ` · tog ${took}` : ""}`,
@@ -177,21 +202,33 @@ const COPY = {
177
202
  ok: "I ordning",
178
203
  },
179
204
  explain: {
180
- action: "De här tjänsterna laddas i ett läge där deras kategori inte är tillåten. Ladda dem via pluginet (Laddas av: det här pluginet) eller låt webbplatsens kod vänta på samtycke.",
181
- unknown: "Inget bland Cookietjänsterna förklarar de här. Lägg till var och en i en tjänst, eller ta bort den från webbplatsen.",
182
- ok: "Förklaras av Cookietjänsterna och syns bara där deras kategori är tillåten.",
205
+ action: "Syns där kategorin inte är tillåten. Välj ”Det här pluginet, efter samtycke” under Laddas av i tjänsten, eller låt webbplatsens kod vänta på samtycke.",
206
+ unknown: "Lägg till var och en i en tjänst, ny eller befintlig, eller ta bort den från webbplatsen.",
207
+ ok: "Finns i en Cookietjänst och syns bara där kategorin är tillåten.",
208
+ },
209
+ seen: {
210
+ cookie: "Cookie som sätts",
211
+ localStorage: "Sparas i webbläsaren",
212
+ host: "Kontaktar en annan webbplats",
183
213
  },
184
- kinds: { cookie: "Cookie", localStorage: "localStorage", host: "Tredjepartsvärd" },
214
+ when: {
215
+ "no-choice": "för nya besökare innan de valt",
216
+ "reject-all": "när besökaren avvisat",
217
+ "accept-all": "när besökaren godkänt",
218
+ },
219
+ whenOnly: (category) => `när bara ${category.toLowerCase()} är tillåten`,
220
+ notAllowed: (category) => `, fast ${category.toLowerCase()} inte är tillåten då`,
221
+ also: (when) => `Även ${when}.`,
222
+ looksLike: (platform) => `Ser ut som ${platform}`,
223
+ database: "Open Cookie Database",
224
+ trackerLists: (lists) => `På spårningslistor: ${lists}`,
225
+ seenOn: "En sida där den syns",
185
226
  beforeConsent: "Före samtycke",
186
227
  isNew: "Ny",
187
- seenIn: "Sågs",
188
- withoutConsent: "utan samtycke",
189
228
  service: "Tjänst",
190
229
  category: "Kategori",
191
230
  add: "Lägg till i tjänst",
192
231
  adding: "Lägger till…",
193
- suggestion: "Förslag",
194
- trackerList: "På spårningslista",
195
232
  states: {
196
233
  "no-choice": "ny besökare",
197
234
  "reject-all": "efter avvisa",
@@ -217,6 +254,16 @@ function stateLabel(copy, id) {
217
254
  const category = id.replace(/^only-/, "");
218
255
  return copy.categories[category] ? `${copy.categories[category]}` : id;
219
256
  }
257
+ /** `for new visitors before they choose and after the visitor accepts`. */
258
+ function whenLabel(copy, ids, language) {
259
+ const labels = ids.map((id) => {
260
+ if (copy.when[id])
261
+ return copy.when[id];
262
+ const category = id.replace(/^only-/, "");
263
+ return copy.categories[category] ? copy.whenOnly(copy.categories[category]) : id;
264
+ });
265
+ return new Intl.ListFormat(language === "sv" ? "sv-SE" : "en-GB", { type: "conjunction" }).format(labels);
266
+ }
220
267
  function dateLabel(value, language) {
221
268
  return new Date(value ?? "").toLocaleString(language === "sv" ? "sv-SE" : "en-GB");
222
269
  }
@@ -225,6 +272,7 @@ const CARD_PILL = {
225
272
  none: "light-gray",
226
273
  queued: "light-gray",
227
274
  running: "light-gray",
275
+ finishing: "light-gray",
228
276
  failed: "error",
229
277
  action: "error",
230
278
  unknown: "warning",
@@ -232,17 +280,27 @@ const CARD_PILL = {
232
280
  ok: "success",
233
281
  clean: "success",
234
282
  };
283
+ /** A group's count, in the colour the card gives the same verdict. */
284
+ const GROUP_PILL = {
285
+ action: CARD_PILL.action,
286
+ unknown: CARD_PILL.unknown,
287
+ ok: CARD_PILL.ok,
288
+ };
235
289
  /**
236
290
  * The scan at a glance: where it stands or what it found, with Scan now. A panel of our own like
237
291
  * the dashboard widget's: Payload's `Card` is a link, not a status.
238
292
  */
239
- function ScanCard({ active, busy, copy, current, error, language, live, now, onStart, scan, scansUrl, }) {
293
+ function ScanCard({ active, busy, copy, current, error, finishingSince, fresh, language, live, now, onStart, pace, scan, scansUrl, }) {
240
294
  const card = copy.card;
241
295
  const summary = scan?.status === "done" ? scan.summary : undefined;
296
+ // The scanner says a scan is done before the site has saved its result: until then the scan is
297
+ // finishing, not back in the queue.
242
298
  const state = active
243
299
  ? current === "running"
244
300
  ? "running"
245
- : "queued"
301
+ : current === "done" || current === "failed"
302
+ ? "finishing"
303
+ : "queued"
246
304
  : !scan
247
305
  ? "none"
248
306
  : scan.status === "failed"
@@ -256,7 +314,7 @@ function ScanCard({ active, busy, copy, current, error, language, live, now, onS
256
314
  ? card.title.unknown(summary?.unknown ?? 0)
257
315
  : card.title[state];
258
316
  const elapsed = live.startedAt ? now - Date.parse(live.startedAt) : undefined;
259
- const left = live.stage && elapsed !== undefined ? estimateLeft(elapsed, live.stage) : undefined;
317
+ const left = live.stage ? estimateLeft(pace, live.stage.total, now) : undefined;
260
318
  const findings = scan?.findings ?? [];
261
319
  const count = (kind) => findings.filter((f) => f.kind === kind).length;
262
320
  const pages = scan?.pages?.selected ?? [];
@@ -276,17 +334,21 @@ function ScanCard({ active, busy, copy, current, error, language, live, now, onS
276
334
  const took = scan?.startedAt && scan.finishedAt
277
335
  ? formatElapsed(Date.parse(scan.finishedAt) - Date.parse(scan.startedAt))
278
336
  : undefined;
279
- return (_jsxs("section", { className: `consent-scan__card consent-scan__card--${CARD_PILL[state]}`, children: [_jsxs("div", { className: "consent-scan__head", children: [_jsxs("div", { className: "consent-scan__pills", children: [_jsx(Pill, { pillStyle: CARD_PILL[state], size: "small", children: card.pills[state] }), summary?.new ? (_jsx(Pill, { pillStyle: "light", size: "small", children: card.newPill(summary.new) })) : null] }), _jsx(Button, { buttonStyle: state === "none" ? "primary" : "secondary", disabled: busy || active, margin: false, onClick: onStart, size: "small", children: busy ? copy.starting : copy.scan })] }), _jsxs("div", { "aria-live": "polite", className: "consent-scan__body", children: [_jsx("h3", { className: "consent-scan__title", children: title }), state === "none" ? _jsx("p", { children: card.text.none }) : null, state === "queued" ? _jsx("p", { children: card.text.queued(live.position) }) : null, state === "running" ? (_jsx("p", { children: live.stage
337
+ return (_jsxs("section", { className: `consent-scan__card consent-scan__card--${CARD_PILL[state]}${summary && fresh ? " consent-scan__card--fresh" : ""}`, children: [_jsxs("div", { className: "consent-scan__head", children: [_jsxs("div", { className: "consent-scan__pills", children: [_jsx(Pill, { pillStyle: CARD_PILL[state], size: "small", children: card.pills[state] }), summary && fresh ? (_jsx(Pill, { pillStyle: "light", size: "small", children: card.justFinished })) : null, summary?.new ? (_jsx(Pill, { pillStyle: "light", size: "small", children: card.newPill(summary.new) })) : null] }), _jsx(Button, { buttonStyle: state === "none" ? "primary" : "secondary", disabled: busy || active, margin: false, onClick: onStart, size: "small", children: busy ? copy.starting : copy.scan })] }), _jsxs("div", { "aria-live": "polite", className: "consent-scan__body", children: [_jsx("h3", { className: "consent-scan__title", children: title }), state === "none" ? _jsx("p", { children: card.text.none }) : null, state === "queued" ? _jsx("p", { children: card.text.queued(live.position) }) : null, state === "running" ? (_jsx("p", { children: live.stage
280
338
  ? card.stage(capitalize(stateLabel(copy, live.stage.state)), live.stage)
281
339
  : live.progress
282
340
  ? progressLabel(copy, live.progress)
283
- : card.text.choosing })) : null, state === "failed" ? _jsx("p", { children: scan?.error }) : null, state === "action" ||
341
+ : card.text.choosing })) : null, state === "finishing" ? (_jsx("p", { children: finishingSince !== undefined && now - finishingSince > 60_000
342
+ ? card.text.late
343
+ : card.text.finishing })) : null, state === "failed" ? _jsx("p", { children: scan?.error }) : null, state === "action" ||
284
344
  state === "unknown" ||
285
345
  state === "incomplete" ||
286
346
  state === "ok" ||
287
- state === "clean" ? (_jsx("p", { children: card.text[state] })) : null] }), state === "running" && live.stage ? (
347
+ state === "clean" ? (_jsx("p", { children: card.text[state] })) : null] }), (state === "running" || state === "finishing") && live.stage ? (
288
348
  // Payload has no progress bar for content (its ProgressBar follows route changes).
289
- _jsx("progress", { "aria-label": card.progress(finishedPages(live.stage), live.stage.total), className: "consent-scan__progress", max: live.stage.total, value: finishedPages(live.stage) })) : null, state === "running" && elapsed !== undefined ? (_jsx("p", { className: "consent-scan__meta", children: card.elapsed(formatElapsed(elapsed), left === undefined ? undefined : formatElapsed(left)) })) : null, summary?.problems?.length ? (_jsx("ul", { className: "consent-scan__problems", children: summary.problems.map((raw) => {
349
+ _jsx("progress", { "aria-label": card.progress(state === "finishing" ? live.stage.total : finishedPages(live.stage), live.stage.total), className: "consent-scan__progress", max: live.stage.total, value: state === "finishing" ? live.stage.total : finishedPages(live.stage) })) : null, state === "running" && elapsed !== undefined ? (_jsx("p", { className: "consent-scan__meta", children: left !== undefined && left < 1000
350
+ ? card.almostDone(formatElapsed(elapsed))
351
+ : card.elapsed(formatElapsed(elapsed), left === undefined ? undefined : formatElapsed(left)) })) : null, summary?.problems?.length ? (_jsx("ul", { className: "consent-scan__problems", children: summary.problems.map((raw) => {
290
352
  const problem = describeProblem(raw, stateIds);
291
353
  const label = problem.state ? stateLabel(copy, problem.state) : "";
292
354
  const text = problem.kind === "sitemap"
@@ -322,6 +384,10 @@ export function ScanPanel() {
322
384
  const [busy, setBusy] = useState(false);
323
385
  const [error, setError] = useState();
324
386
  const [now, setNow] = useState(() => Date.now());
387
+ // The pace of the scan being watched, from when each page was first seen begun.
388
+ const [pace, setPace] = useState({ marks: [] });
389
+ // The scan the card has seen running or waiting, so its result shows as just finished.
390
+ const watched = useRef(undefined);
325
391
  const load = useCallback(async () => {
326
392
  const response = await fetch(`${api}?sort=-createdAt&limit=1&depth=0`, {
327
393
  credentials: "include",
@@ -332,35 +398,54 @@ export function ScanPanel() {
332
398
  useEffect(() => {
333
399
  load();
334
400
  }, [load]);
335
- // While a scan waits or runs, ask for its progress; reload it when it ends.
401
+ // While a scan waits or runs, ask for its progress; reload it until its result has arrived.
336
402
  useEffect(() => {
337
403
  if (!scan || (scan.status !== "queued" && scan.status !== "running"))
338
404
  return;
405
+ watched.current = scan.id;
339
406
  let stopped = false;
340
407
  const poll = async () => {
341
408
  const response = await fetch(`${api}/${scan.id}/status`, { credentials: "include" });
342
409
  const next = (await response.json().catch(() => ({})));
343
410
  if (stopped)
344
411
  return;
345
- setLive(next);
412
+ const at = Date.now();
413
+ // A finished scan no longer reports its stage: keep the last one for the full bar.
414
+ setLive((previous) => ({
415
+ ...next,
416
+ stage: next.stage ?? previous.stage,
417
+ startedAt: next.startedAt ?? previous.startedAt,
418
+ }));
419
+ setPace((previous) => ({
420
+ id: scan.id,
421
+ marks: markPace(previous.id === scan.id ? previous.marks : [], next.stage, at),
422
+ }));
346
423
  if (next.status === "done" || next.status === "failed")
347
424
  await load();
348
425
  };
349
426
  poll();
350
- const timer = setInterval(poll, 4000);
427
+ const timer = setInterval(poll, 2000);
351
428
  return () => {
352
429
  stopped = true;
353
430
  clearInterval(timer);
354
431
  };
355
432
  }, [api, load, scan]);
356
- // A running scan's clock ticks each second between the scanner's answers.
357
- const running = scan?.status === "running" || live.status === "running";
433
+ const active = scan?.status === "queued" || scan?.status === "running";
434
+ // The scanner knows first when a queued scan starts running, and when it is done.
435
+ const current = active ? (live.status ?? scan?.status) : scan?.status;
436
+ const finishing = active && (current === "done" || current === "failed");
437
+ const [finishingSince, setFinishingSince] = useState();
358
438
  useEffect(() => {
359
- if (!running)
439
+ setFinishingSince((since) => (finishing ? (since ?? Date.now()) : undefined));
440
+ }, [finishing]);
441
+ // A waiting or running scan's clock ticks each second between the scanner's answers.
442
+ const ticking = scan?.status === "queued" || scan?.status === "running";
443
+ useEffect(() => {
444
+ if (!ticking)
360
445
  return;
361
446
  const timer = setInterval(() => setNow(Date.now()), 1000);
362
447
  return () => clearInterval(timer);
363
- }, [running]);
448
+ }, [ticking]);
364
449
  async function start() {
365
450
  setBusy(true);
366
451
  setError(undefined);
@@ -381,21 +466,19 @@ export function ScanPanel() {
381
466
  }
382
467
  if (!hasScanner)
383
468
  return _jsx("p", { className: "consent-scan__note", children: copy.noScanner });
384
- const active = scan?.status === "queued" || scan?.status === "running";
385
- // The scanner knows first when a queued scan starts running.
386
- const current = active ? (live.status ?? scan?.status) : scan?.status;
387
469
  const findings = scan?.findings ?? [];
388
- return (_jsxs("div", { className: "consent-scan", children: [_jsx(ScanCard, { active: active, busy: busy, copy: copy, current: current, error: error, language: language, live: live, now: now, onStart: start, scan: scan ?? null, scansUrl: `${config.routes.admin}/collections/${CONSENT_SCANS}` }), scan?.status === "done"
470
+ return (_jsxs("div", { className: "consent-scan", children: [_jsx(ScanCard, { active: active, busy: busy, copy: copy, current: current, error: error, finishingSince: finishingSince, fresh: Boolean(scan) && watched.current === scan?.id, language: language, live: live, now: now, onStart: start, pace: pace.id === scan?.id ? pace.marks : [], scan: scan ?? null, scansUrl: `${config.routes.admin}/collections/${CONSENT_SCANS}` }), scan?.status === "done"
389
471
  ? ["action", "unknown", "ok"].map((status) => {
390
472
  const rows = findings.filter((finding) => finding.status === status);
391
473
  if (!rows.length)
392
474
  return null;
393
- const list = (_jsx("ul", { className: "consent-scan__list", children: rows.map((finding) => (_jsx(FindingRow, { copy: copy, finding: finding, locale: locale.code, onAdded: load, api: api }, finding.key))) }));
394
- return (_jsx("section", { className: `consent-scan__group consent-scan__group--${status}`, children: status === "ok" ? (_jsxs("details", { children: [_jsx("summary", { children: _jsxs("h4", { children: [copy.groups[status], " (", rows.length, ")"] }) }), _jsx("p", { className: "consent-scan__note", children: copy.explain[status] }), list] })) : (_jsxs(_Fragment, { children: [_jsxs("h4", { children: [copy.groups[status], " (", rows.length, ")"] }), _jsx("p", { className: "consent-scan__note", children: copy.explain[status] }), list] })) }, status));
475
+ return (_jsxs(Collapsible, { className: `consent-scan__group consent-scan__group--${status}`, header: _jsxs("span", { className: "consent-scan__group-head", children: [_jsx("span", { className: "consent-scan__group-title", children: copy.groups[status] }), _jsx(Pill, { pillStyle: GROUP_PILL[status], size: "small", children: rows.length })] }),
476
+ // What is in order is there to look up, not to act on.
477
+ initCollapsed: status === "ok", children: [_jsx("p", { className: "consent-scan__note", children: copy.explain[status] }), _jsx("ul", { className: "consent-scan__list", children: rows.map((finding) => (_jsx(FindingRow, { api: api, copy: copy, finding: finding, language: language, locale: locale.code, onAdded: load }, finding.key))) })] }, status));
395
478
  })
396
479
  : null] }));
397
480
  }
398
- function FindingRow({ api, copy, finding, locale, onAdded, }) {
481
+ function FindingRow({ api, copy, finding, language, locale, onAdded, }) {
399
482
  const suggestion = finding.suggestion;
400
483
  const [service, setService] = useState(suggestion?.platform ?? (finding.kind === "host" ? finding.name : ""));
401
484
  const [category, setCategory] = useState(suggestion?.category ?? "necessary");
@@ -428,9 +511,38 @@ function FindingRow({ api, copy, finding, locale, onAdded, }) {
428
511
  else
429
512
  await onAdded();
430
513
  }
431
- const seen = finding.states.map((id) => stateLabel(copy, id)).join(", ");
432
- const without = finding.withoutConsent.map((id) => stateLabel(copy, id)).join(", ");
433
- return (_jsxs("li", { className: "consent-scan__row", children: [_jsxs("div", { className: "consent-scan__name", children: [_jsx("span", { className: "consent-scan__kind", children: copy.kinds[finding.kind] }), _jsx("code", { children: finding.name }), finding.where ? _jsx("span", { className: "consent-scan__where", children: finding.where }) : null, finding.beforeConsent && finding.status !== "ok" ? (_jsx(Pill, { pillStyle: "error", size: "small", children: copy.beforeConsent })) : null, finding.isNew ? (_jsx(Pill, { pillStyle: "warning", size: "small", children: copy.isNew })) : null] }), _jsxs("p", { className: "consent-scan__detail", children: [copy.seenIn, ": ", seen, without ? ` · ${copy.withoutConsent}: ${without}` : "", finding.service ? ` · ${copy.service}: ${finding.service}` : "", finding.category ? ` (${copy.categories[finding.category]})` : "", finding.trackerLists?.length
434
- ? ` · ${copy.trackerList}: ${finding.trackerLists.join(", ")}`
435
- : ""] }), suggestion?.platform ? (_jsxs("p", { className: "consent-scan__detail", children: [copy.suggestion, ": ", suggestion.platform, suggestion.category ? `, ${copy.categories[suggestion.category]}` : "", suggestion.retention ? `, ${suggestion.retention}` : "", suggestion.description ? ` · ${suggestion.description}` : ""] })) : null, finding.status === "unknown" ? (_jsxs("div", { className: "consent-scan__classify", children: [_jsxs("label", { children: [_jsx("span", { children: copy.service }), _jsx("input", { onChange: (event) => setService(event.target.value), type: "text", value: service })] }), _jsxs("label", { children: [_jsx("span", { children: copy.category }), _jsx("select", { onChange: (event) => setCategory(event.target.value), value: category, children: CATEGORIES.map((value) => (_jsx("option", { value: value, children: copy.categories[value] }, value))) })] }), _jsx(Button, { buttonStyle: "secondary", disabled: busy || !service.trim(), margin: false, onClick: add, size: "small", children: busy ? copy.adding : copy.add }), error ? _jsx("span", { className: "consent-scan__error", children: error }) : null] })) : null] }));
514
+ const heading = findingHeading(finding);
515
+ const serviceCategory = finding.category ? copy.categories[finding.category] : "";
516
+ const suggested = [
517
+ suggestion?.category ? copy.categories[suggestion.category] : "",
518
+ suggestion?.retention,
519
+ ].filter(Boolean);
520
+ // The raw facts a developer looks for, after what the editor reads.
521
+ const details = [
522
+ heading.from === "name" ? null : _jsx("code", { children: finding.name }, "name"),
523
+ finding.where || null,
524
+ heading.from === "service"
525
+ ? serviceCategory || null
526
+ : heading.from === "suggestion" && suggested.length
527
+ ? `${copy.database}: ${suggested.join(", ")}`
528
+ : null,
529
+ finding.trackerLists?.length ? copy.trackerLists(finding.trackerLists.join(", ")) : null,
530
+ finding.page ? (_jsx("a", { href: finding.page, rel: "noopener noreferrer", target: "_blank", children: copy.seenOn }, "page")) : null,
531
+ ].filter(Boolean);
532
+ // Where it loaded without consent comes first, in the error colour; the rest after it.
533
+ const without = serviceCategory ? finding.withoutConsent : [];
534
+ const rest = finding.states.filter((id) => !without.includes(id));
535
+ const path = `consent-scan-${finding.key}`;
536
+ 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) => {
537
+ // Enter adds the finding; it would otherwise submit the Cookies form around the tab.
538
+ if (event.key !== "Enter")
539
+ return;
540
+ event.preventDefault();
541
+ if (!busy && service.trim())
542
+ add();
543
+ }, path: `${path}-service`, readOnly: busy, value: service }), _jsx(SelectInput, { isClearable: false, label: copy.category, name: `${path}-category`, onChange: (selected) => {
544
+ const option = Array.isArray(selected) ? selected[0] : selected;
545
+ if (option && typeof option === "object" && "value" in option)
546
+ setCategory(option.value);
547
+ }, options: CATEGORIES.map((value) => ({ label: copy.categories[value], value })), path: `${path}-category`, readOnly: busy, value: category }), _jsx(Button, { buttonStyle: "secondary", disabled: busy || !service.trim(), margin: false, onClick: add, size: "large", children: busy ? copy.adding : copy.add }), error ? (_jsx("p", { className: "consent-scan__error", role: "alert", children: error })) : null] })) : null] }));
436
548
  }
@@ -1,4 +1,4 @@
1
- import type { ScanSummary } from "../evaluate.ts";
1
+ import type { Finding, ScanSummary } from "../evaluate.ts";
2
2
  import type { ScanStage } from "../scans.ts";
3
3
  /**
4
4
  * What a finished scan means for the editor, most urgent first: services loading without consent,
@@ -7,6 +7,15 @@ import type { ScanStage } from "../scans.ts";
7
7
  */
8
8
  export type ScanVerdict = "action" | "unknown" | "incomplete" | "ok" | "clean";
9
9
  export declare function scanVerdict(summary: ScanSummary): ScanVerdict;
10
+ /**
11
+ * What a finding's row leads with, in the editor's words: the Cookie service that explains it, the
12
+ * platform the Open Cookie Database suggests, or only its raw name when neither knows it.
13
+ */
14
+ export type FindingHeading = {
15
+ from: "service" | "suggestion" | "name";
16
+ text: string;
17
+ };
18
+ export declare function findingHeading(finding: Finding): FindingHeading;
10
19
  /** Pages finished in all states, for the progress bar: the page being visited is not yet. */
11
20
  export declare function finishedPages(stage: ScanStage): number;
12
21
  /** `0:07`, `12:30`, `1:02:03`. */
@@ -19,10 +28,19 @@ export type ScanProblem = {
19
28
  detail: string;
20
29
  };
21
30
  export declare function describeProblem(problem: string, stateIds: string[]): ScanProblem;
31
+ /** When the card first saw each count of pages begun (`stage.visited`), for the pace. */
32
+ export type PaceMark = {
33
+ visited: number;
34
+ at: number;
35
+ };
36
+ /** The marks with the scanner's latest answer, when it has begun a page the card had not seen. */
37
+ export declare function markPace(marks: PaceMark[], stage: ScanStage | undefined, now: number): PaceMark[];
22
38
  /**
23
- * Roughly how long a running scan has left, from the pace so far; `undefined` until a page is
24
- * done, when there is no pace to go by.
39
+ * Roughly how long a running scan has left. The pace is the time between the first and the latest
40
+ * page begun, so the scan's start-up is left out, and the estimate made when the latest page began
41
+ * counts down until the next one rather than grow while a page takes its time. Undefined until two
42
+ * pages have begun; 0 once the pace says the scan should be done, as it ends with WEC's report.
25
43
  */
26
- export declare function estimateLeft(elapsedMs: number, stage: ScanStage): number | undefined;
44
+ export declare function estimateLeft(marks: PaceMark[], total: number, now: number): number | undefined;
27
45
  /** `/about?x=1` for a page on the scanned site: the address without its origin. */
28
46
  export declare function pagePath(url: string): string;
@@ -7,6 +7,14 @@ export function scanVerdict(summary) {
7
7
  return "incomplete";
8
8
  return summary.ok ? "ok" : "clean";
9
9
  }
10
+ export function findingHeading(finding) {
11
+ if (finding.service)
12
+ return { from: "service", text: finding.service };
13
+ const platform = finding.suggestion?.platform;
14
+ if (platform && finding.status === "unknown")
15
+ return { from: "suggestion", text: platform };
16
+ return { from: "name", text: finding.name };
17
+ }
10
18
  /** Pages finished in all states, for the progress bar: the page being visited is not yet. */
11
19
  export function finishedPages(stage) {
12
20
  return Math.max(0, stage.page > 0 ? stage.visited - 1 : stage.visited);
@@ -36,15 +44,27 @@ export function describeProblem(problem, stateIds) {
36
44
  return { kind: "outOfTime", state, detail };
37
45
  return { kind: "pagesFailed", state, detail };
38
46
  }
47
+ /** The marks with the scanner's latest answer, when it has begun a page the card had not seen. */
48
+ export function markPace(marks, stage, now) {
49
+ const last = marks.at(-1);
50
+ if (!stage || stage.visited < 1 || (last && last.visited >= stage.visited))
51
+ return marks;
52
+ return [...marks, { visited: stage.visited, at: now }];
53
+ }
39
54
  /**
40
- * Roughly how long a running scan has left, from the pace so far; `undefined` until a page is
41
- * done, when there is no pace to go by.
55
+ * Roughly how long a running scan has left. The pace is the time between the first and the latest
56
+ * page begun, so the scan's start-up is left out, and the estimate made when the latest page began
57
+ * counts down until the next one rather than grow while a page takes its time. Undefined until two
58
+ * pages have begun; 0 once the pace says the scan should be done, as it ends with WEC's report.
42
59
  */
43
- export function estimateLeft(elapsedMs, stage) {
44
- const finished = finishedPages(stage);
45
- if (finished < 1 || elapsedMs <= 0)
60
+ export function estimateLeft(marks, total, now) {
61
+ const first = marks[0];
62
+ const last = marks.at(-1);
63
+ if (!first || !last || last.visited <= first.visited)
46
64
  return undefined;
47
- return (elapsedMs / finished) * Math.max(0, stage.total - finished);
65
+ const pace = (last.at - first.at) / (last.visited - first.visited);
66
+ // The latest page has only begun: it is left too, with every page after it.
67
+ return Math.max(0, pace * (total - last.visited + 1) - (now - last.at));
48
68
  }
49
69
  /** `/about?x=1` for a page on the scanned site: the address without its origin. */
50
70
  export function pagePath(url) {
@@ -24,6 +24,21 @@
24
24
  .consent-scan__card--warning {
25
25
  border-color: var(--theme-warning-500);
26
26
  }
27
+ /* A result that arrived while the card watched the scan: it fades in rather than swap in place. */
28
+ .consent-scan__card--fresh {
29
+ animation: consent-scan-fresh 400ms ease-out;
30
+ }
31
+ @keyframes consent-scan-fresh {
32
+ from {
33
+ opacity: 0.35;
34
+ transform: translateY(4px);
35
+ }
36
+ }
37
+ @media (prefers-reduced-motion: reduce) {
38
+ .consent-scan__card--fresh {
39
+ animation: none;
40
+ }
41
+ }
27
42
  .consent-scan__head {
28
43
  display: flex;
29
44
  align-items: center;
@@ -131,75 +146,99 @@
131
146
  margin: 0;
132
147
  color: var(--theme-error-500);
133
148
  }
149
+ /* A group of findings: Payload's Collapsible, its count in the card's pill colours. */
134
150
  .consent-scan__group {
135
- border-top: 1px solid var(--theme-elevation-100);
136
- padding-top: calc(var(--base) * 0.75);
151
+ margin: 0;
137
152
  }
138
- .consent-scan__group h4 {
139
- margin: 0 0 calc(var(--base) * 0.25);
140
- display: inline;
153
+ .consent-scan__group-head {
154
+ display: flex;
155
+ align-items: center;
156
+ gap: calc(var(--base) * 0.5);
157
+ color: var(--theme-text);
141
158
  }
142
- .consent-scan__group--action h4 {
143
- color: var(--theme-error-500);
159
+ .consent-scan__group-title {
160
+ font-weight: 600;
144
161
  }
145
- .consent-scan__group summary {
146
- cursor: pointer;
162
+ .consent-scan__group .collapsible__content {
163
+ display: grid;
164
+ gap: calc(var(--base) * 0.5);
147
165
  }
148
166
  .consent-scan__list {
149
- list-style: none;
150
- margin: calc(var(--base) * 0.5) 0 0;
151
- padding: 0;
152
167
  display: grid;
153
- gap: calc(var(--base) * 0.5);
168
+ margin: 0;
169
+ padding: 0;
170
+ list-style: none;
154
171
  }
155
172
  .consent-scan__row {
156
173
  display: grid;
157
- gap: 4px;
158
- padding: calc(var(--base) * 0.5);
159
- border: 1px solid var(--theme-elevation-100);
160
- border-radius: var(--style-radius-s);
174
+ gap: calc(var(--base) * 0.5);
175
+ padding-block: calc(var(--base) * 0.75);
176
+ border-top: 1px solid var(--theme-elevation-100);
161
177
  }
162
- .consent-scan__name {
178
+ .consent-scan__row:last-child {
179
+ padding-bottom: 0;
180
+ }
181
+ .consent-scan__row-head {
163
182
  display: flex;
164
183
  flex-wrap: wrap;
165
184
  align-items: center;
166
- gap: 8px;
185
+ justify-content: space-between;
186
+ gap: calc(var(--base) * 0.5);
167
187
  }
168
- .consent-scan__kind {
169
- color: var(--theme-elevation-500);
170
- font-size: 0.85em;
188
+ /* A finding leads with its service in plain words; its raw name and domain follow, quieter. */
189
+ .consent-scan__name {
190
+ margin: 0;
191
+ font-size: 1.15rem;
192
+ line-height: 1.3;
193
+ font-weight: 600;
194
+ overflow-wrap: anywhere;
171
195
  }
172
- .consent-scan__where {
173
- color: var(--theme-elevation-500);
196
+ .consent-scan__name code {
197
+ font-size: 0.95rem;
174
198
  }
175
- .consent-scan__detail {
199
+ .consent-scan__seen {
176
200
  margin: 0;
177
- color: var(--theme-elevation-600);
178
- font-size: 0.9em;
179
- overflow-wrap: anywhere;
180
201
  }
181
- .consent-scan__classify {
202
+ .consent-scan__seen strong {
203
+ font-weight: 500;
204
+ color: var(--theme-error-500);
205
+ }
206
+ .consent-scan__details {
182
207
  display: flex;
183
208
  flex-wrap: wrap;
184
- align-items: flex-end;
185
- gap: 8px;
186
- margin-top: 4px;
209
+ gap: 0 calc(var(--base) * 0.5);
210
+ margin: 0;
211
+ color: var(--theme-elevation-500);
212
+ font-size: 0.85rem;
213
+ overflow-wrap: anywhere;
187
214
  }
188
- .consent-scan__classify label {
215
+ .consent-scan__details span:not(:last-child)::after {
216
+ content: "·";
217
+ margin-left: calc(var(--base) * 0.5);
218
+ }
219
+ .consent-scan__details a {
220
+ color: inherit;
221
+ text-decoration: underline;
222
+ text-underline-offset: 2px;
223
+ }
224
+ /* Service and Category side by side, with Add to service on their inputs' line. */
225
+ .consent-scan__classify {
189
226
  display: grid;
190
- gap: 2px;
191
- font-size: 0.85em;
192
- color: var(--theme-elevation-600);
227
+ grid-template-columns: minmax(10rem, 22rem) minmax(10rem, 14rem) auto;
228
+ justify-content: start;
229
+ align-items: end;
230
+ gap: calc(var(--base) * 0.5);
193
231
  }
194
- .consent-scan__classify input,
195
- .consent-scan__classify select {
196
- font: inherit;
197
- color: var(--theme-text);
198
- background: var(--theme-input-bg);
199
- border: 1px solid var(--theme-elevation-150);
200
- border-radius: var(--style-radius-s);
201
- padding: 6px 8px;
202
- min-height: 32px;
232
+ .consent-scan__classify .field-type {
233
+ margin: 0;
234
+ }
235
+ .consent-scan__classify .consent-scan__error {
236
+ grid-column: 1 / -1;
237
+ }
238
+ @media (max-width: 768px) {
239
+ .consent-scan__classify {
240
+ grid-template-columns: 1fr;
241
+ }
203
242
  }
204
243
 
205
244
  /* The dashboard widget, laid out like Payload's collection cards and content health's widget. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-consent",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Cookie consent for Payload sites: banner texts, services and scans in Admin",
5
5
  "keywords": [
6
6
  "payload",