@simmalugnt-se/payload-consent 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.2
4
+
5
+ - The Scan tab opens with a card for the scan. While it runs, the card follows it page by page
6
+ (`New visitor · page 3 of 10 · state 1 of 3`), with a progress bar, the time taken and a rough
7
+ time left; before, it showed only the state. When it ends, the card says what it means, such as
8
+ "Nothing to fix" or "2 need action", counts the pages visited, states, cookies, localStorage
9
+ keys and other sites, lists the pages, and puts what kept a scan from being complete in words.
10
+ The scan's settings follow the card. Page by page progress needs `consent-scanner` at `1274a32`
11
+ or later; with an older one the card shows the state alone.
12
+
13
+ ## 0.6.1
14
+
15
+ - `scanner.pages` sends a list per collection, and the scanner picks from each as from one sitemap:
16
+ in one list, a large collection such as news took nearly every visited page from the others.
17
+ Needs `consent-scanner` at `fcf4a71` or later: the scanner 0.6.0 was made for (`eef412e`) refuses
18
+ lists, and an older one ignores them and reads the sitemaps.
19
+
3
20
  ## 0.6.0
4
21
 
5
22
  - `scanner.pages` sends the site's published pages from Payload with a scan, in place of its
package/README.md CHANGED
@@ -134,15 +134,21 @@ The scanner picks the pages to visit from the site's sitemaps. A site with searc
134
134
  often serves empty ones, and then only the start page is scanned. With `scanner.pages`, a scan
135
135
  sends the published documents of those collections instead: read as a visitor would, in the
136
136
  default locale, each turned into a path or address by `url` (return nothing to leave one out).
137
- Paths are taken relative to the scanned address, and addresses on another origin are left out;
138
- more than 500 are thinned evenly. The scanner picks from them as from one sitemap. Without the
139
- option, or when no page is left, the scanner reads the sitemaps.
137
+ Paths are taken relative to the scanned address, and addresses on another origin are left out.
138
+ Each collection goes as its own list, and the scanner picks from each as from one sitemap, so a
139
+ thousand news articles do not crowd out the pages; the lists share at most 500 addresses, each
140
+ thinned evenly. Without the option, or when no page is left, the scanner reads the sitemaps.
140
141
 
141
- Scan now scans the site's address (the field above the button, or `serverURL`) as a new visitor,
142
+ Scan now scans the site's address (the Site address field, or `serverURL`) as a new visitor,
142
143
  after rejecting, after accepting and, with several optional categories, with each one alone. The
143
- plugin presets c15t's cookie for each state, so no click is needed. The scanner posts the result
144
- back to `/api/consent-scans/result`, and the tab shows every cookie, localStorage key and
145
- third-party host:
144
+ plugin presets c15t's cookie for each state, so no click is needed. While it runs, the card at the
145
+ top of the Scan tab follows it page by page, with the time it has taken and a rough time left.
146
+
147
+ The scanner posts the result back to `/api/consent-scans/result`. The card then says what it
148
+ means: nothing to fix, how many need action or are not explained, or that the scan could not see
149
+ everything and why, in words rather than the scanner's errors. It counts the pages visited, the
150
+ states, cookies, localStorage keys and other sites, and lists the pages. Below it, the tab shows
151
+ every cookie, localStorage key and third-party host:
146
152
 
147
153
  - **Needs action**: a service seen in a state that does not allow its category, such as analytics
148
154
  before consent.
@@ -1,23 +1,77 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { Button, Pill, useConfig, useFormFields, useLocale, useTranslation } from "@payloadcms/ui";
3
+ import { Button, Collapsible, Pill, useConfig, useFormFields, useLocale, useTranslation, } from "@payloadcms/ui";
4
4
  import { useCallback, useEffect, 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
8
  import "../styles/admin.css";
8
9
  const COPY = {
9
10
  en: {
10
11
  noScanner: "No scanner is set up. Give the plugin `scanner: { url, token }` (see the README), then scan from here.",
11
12
  scan: "Scan now",
12
13
  starting: "Starting…",
13
- none: "The site has not been scanned yet.",
14
- queued: (position) => position
15
- ? `Waiting for the scanner, number ${position} in line.`
16
- : "Waiting for the scanner.",
17
- running: (progress) => `Scanning${progress ? `: ${progress}` : "…"}`,
18
- failed: "The scan failed:",
19
- incomplete: "The scan is incomplete, so it may have missed something. Fix what is listed and scan again:",
20
- done: (date, pages) => `Scanned ${date}, ${pages} pages.`,
14
+ card: {
15
+ pills: {
16
+ none: "Not scanned",
17
+ queued: "Waiting",
18
+ running: "Scanning",
19
+ failed: "Failed",
20
+ action: "Needs action",
21
+ unknown: "Not explained",
22
+ incomplete: "Incomplete",
23
+ ok: "In order",
24
+ clean: "In order",
25
+ },
26
+ newPill: (n) => `${n} new`,
27
+ title: {
28
+ none: "The site has not been scanned yet",
29
+ queued: "Waiting for the scanner",
30
+ running: "Scanning the site",
31
+ failed: "The scan failed",
32
+ action: (n) => `${n} ${n === 1 ? "needs" : "need"} action`,
33
+ unknown: (n) => `${n} not in the Cookie services`,
34
+ incomplete: "The scan could not see everything",
35
+ ok: "Nothing to fix",
36
+ clean: "Nothing to fix",
37
+ },
38
+ text: {
39
+ none: "Scan now to see which cookies, storage and other sites the published site uses, before and after the visitor's choice.",
40
+ queued: (position) => position ? `Number ${position} in line.` : "It starts when the scanner is free.",
41
+ choosing: "Choosing the pages to visit…",
42
+ action: "Services load where the visitor has not allowed their category.",
43
+ unknown: "The scan found storage or other sites that no Cookie service explains.",
44
+ incomplete: "It may have missed something. Scan again once this is fixed:",
45
+ ok: "Everything the scan found is in the Cookie services and loads only where its category is allowed.",
46
+ clean: "The scan found no cookies, no storage and no requests to other sites.",
47
+ },
48
+ stage: (state, stage) => [
49
+ state,
50
+ stage.page ? `page ${stage.page} of ${stage.pages}` : "starting",
51
+ ...(stage.states > 1 ? [`state ${stage.stateNumber} of ${stage.states}`] : []),
52
+ ].join(" · "),
53
+ elapsed: (time, left) => (left ? `${time} · about ${left} left` : time),
54
+ progress: (finished, total) => `${finished} of ${total} page visits done`,
55
+ stats: {
56
+ pages: (n, of) => n === of ? (n === 1 ? "page" : "pages") : `of ${of} ${of === 1 ? "page" : "pages"}`,
57
+ states: (n) => (n === 1 ? "state" : "states"),
58
+ cookies: (n) => (n === 1 ? "cookie" : "cookies"),
59
+ storage: () => "localStorage",
60
+ hosts: (n) => (n === 1 ? "other site" : "other sites"),
61
+ },
62
+ scanned: (date, took) => `Scanned ${date}${took ? ` · took ${took}` : ""}`,
63
+ states: (count, states) => `${count === 1 ? "State" : "States"}: ${states}`,
64
+ pages: (n) => `Scanned pages (${n})`,
65
+ all: "All scans",
66
+ problems: {
67
+ notScanned: (state) => `${state}: not scanned`,
68
+ noPages: (state) => `${state}: no page could be visited`,
69
+ outOfTime: (state) => `${state}: the scan ran out of time`,
70
+ pagesFailed: (state) => `${state}: some pages could not be scanned`,
71
+ sitemap: (sitemap) => `The sitemap ${sitemap} could not be read`,
72
+ other: () => "The scanner reported a problem",
73
+ },
74
+ },
21
75
  groups: {
22
76
  action: "Needs action",
23
77
  unknown: "Not in the Cookie services",
@@ -51,18 +105,72 @@ const COPY = {
51
105
  measurement: "Statistics",
52
106
  marketing: "Marketing",
53
107
  },
54
- summary: (s) => `${s.action} need action · ${s.unknown} unknown · ${s.ok} in order${s.new ? ` · ${s.new} new` : ""}`,
55
108
  },
56
109
  sv: {
57
110
  noScanner: "Ingen skanner är inställd. Ge pluginet `scanner: { url, token }` (se README), och skanna sedan härifrån.",
58
111
  scan: "Skanna nu",
59
112
  starting: "Startar…",
60
- none: "Webbplatsen har inte skannats än.",
61
- queued: (position) => position ? `Väntar på skannern, nummer ${position} i kön.` : "Väntar på skannern.",
62
- running: (progress) => `Skannar${progress ? `: ${progress}` : "…"}`,
63
- incomplete: "Skanningen är ofullständig och kan ha missat något. Åtgärda det som står här och skanna igen:",
64
- failed: "Skanningen misslyckades:",
65
- done: (date, pages) => `Skannad ${date}, ${pages} sidor.`,
113
+ card: {
114
+ pills: {
115
+ none: "Inte skannad",
116
+ queued: "Väntar",
117
+ running: "Skannar",
118
+ failed: "Misslyckades",
119
+ action: "Åtgärd krävs",
120
+ unknown: "Okänt",
121
+ incomplete: "Ofullständig",
122
+ ok: "I ordning",
123
+ clean: "I ordning",
124
+ },
125
+ newPill: (n) => `${n} nya`,
126
+ title: {
127
+ none: "Webbplatsen har inte skannats än",
128
+ queued: "Väntar på skannern",
129
+ running: "Skannar webbplatsen",
130
+ failed: "Skanningen misslyckades",
131
+ action: (n) => `${n} kräver åtgärd`,
132
+ unknown: (n) => `${n} finns inte bland Cookietjänsterna`,
133
+ incomplete: "Skanningen kunde inte se allt",
134
+ ok: "Inget att åtgärda",
135
+ clean: "Inget att åtgärda",
136
+ },
137
+ text: {
138
+ 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
+ queued: (position) => position ? `Nummer ${position} i kön.` : "Den startar när skannern är ledig.",
140
+ choosing: "Väljer vilka sidor som ska besökas…",
141
+ action: "Tjänster laddas där besökaren inte har tillåtit kategorin.",
142
+ unknown: "Skanningen hittade lagring eller andra webbplatser som ingen Cookietjänst förklarar.",
143
+ incomplete: "Den kan ha missat något. Skanna igen när det här är åtgärdat:",
144
+ ok: "Allt skanningen hittade finns bland Cookietjänsterna och laddas bara där kategorin är tillåten.",
145
+ clean: "Skanningen hittade inga cookies, ingen lagring och inga anrop till andra webbplatser.",
146
+ },
147
+ stage: (state, stage) => [
148
+ state,
149
+ stage.page ? `sida ${stage.page} av ${stage.pages}` : "startar",
150
+ ...(stage.states > 1 ? [`läge ${stage.stateNumber} av ${stage.states}`] : []),
151
+ ].join(" · "),
152
+ elapsed: (time, left) => (left ? `${time} · ungefär ${left} kvar` : time),
153
+ progress: (finished, total) => `${finished} av ${total} sidbesök klara`,
154
+ stats: {
155
+ pages: (n, of) => n === of ? (n === 1 ? "sida" : "sidor") : `av ${of} ${of === 1 ? "sida" : "sidor"}`,
156
+ states: (n) => (n === 1 ? "läge" : "lägen"),
157
+ cookies: (n) => (n === 1 ? "cookie" : "cookies"),
158
+ storage: () => "localStorage",
159
+ hosts: (n) => (n === 1 ? "annan webbplats" : "andra webbplatser"),
160
+ },
161
+ scanned: (date, took) => `Skannad ${date}${took ? ` · tog ${took}` : ""}`,
162
+ states: (count, states) => `${count === 1 ? "Läge" : "Lägen"}: ${states}`,
163
+ pages: (n) => `Skannade sidor (${n})`,
164
+ all: "Alla skanningar",
165
+ problems: {
166
+ notScanned: (state) => `${state}: skannades inte`,
167
+ noPages: (state) => `${state}: ingen sida kunde besökas`,
168
+ outOfTime: (state) => `${state}: skanningen hann inte klart`,
169
+ pagesFailed: (state) => `${state}: några sidor kunde inte skannas`,
170
+ sitemap: (sitemap) => `Sitemapen ${sitemap} kunde inte läsas`,
171
+ other: () => "Skannern rapporterade ett problem",
172
+ },
173
+ },
66
174
  groups: {
67
175
  action: "Åtgärd krävs",
68
176
  unknown: "Finns inte bland Cookietjänsterna",
@@ -96,15 +204,104 @@ const COPY = {
96
204
  measurement: "Statistik",
97
205
  marketing: "Marknadsföring",
98
206
  },
99
- summary: (s) => `${s.action} kräver åtgärd · ${s.unknown} okända · ${s.ok} i ordning${s.new ? ` · ${s.new} nya` : ""}`,
100
207
  },
101
208
  };
209
+ /** `new visitor, after rejecting and after accepting`. */
210
+ function statesLabel(copy, ids, language) {
211
+ const labels = ids.map((id) => stateLabel(copy, id));
212
+ return new Intl.ListFormat(language === "sv" ? "sv-SE" : "en-GB", { type: "conjunction" }).format(labels);
213
+ }
102
214
  function stateLabel(copy, id) {
103
215
  if (copy.states[id])
104
216
  return copy.states[id];
105
217
  const category = id.replace(/^only-/, "");
106
218
  return copy.categories[category] ? `${copy.categories[category]}` : id;
107
219
  }
220
+ function dateLabel(value, language) {
221
+ return new Date(value ?? "").toLocaleString(language === "sv" ? "sv-SE" : "en-GB");
222
+ }
223
+ /** The card's pill: Payload's pill styles. */
224
+ const CARD_PILL = {
225
+ none: "light-gray",
226
+ queued: "light-gray",
227
+ running: "light-gray",
228
+ failed: "error",
229
+ action: "error",
230
+ unknown: "warning",
231
+ incomplete: "warning",
232
+ ok: "success",
233
+ clean: "success",
234
+ };
235
+ /**
236
+ * The scan at a glance: where it stands or what it found, with Scan now. A panel of our own like
237
+ * the dashboard widget's: Payload's `Card` is a link, not a status.
238
+ */
239
+ function ScanCard({ active, busy, copy, current, error, language, live, now, onStart, scan, scansUrl, }) {
240
+ const card = copy.card;
241
+ const summary = scan?.status === "done" ? scan.summary : undefined;
242
+ const state = active
243
+ ? current === "running"
244
+ ? "running"
245
+ : "queued"
246
+ : !scan
247
+ ? "none"
248
+ : scan.status === "failed"
249
+ ? "failed"
250
+ : summary
251
+ ? scanVerdict(summary)
252
+ : "clean";
253
+ const title = state === "action"
254
+ ? card.title.action(summary?.action ?? 0)
255
+ : state === "unknown"
256
+ ? card.title.unknown(summary?.unknown ?? 0)
257
+ : card.title[state];
258
+ const elapsed = live.startedAt ? now - Date.parse(live.startedAt) : undefined;
259
+ const left = live.stage && elapsed !== undefined ? estimateLeft(elapsed, live.stage) : undefined;
260
+ const findings = scan?.findings ?? [];
261
+ const count = (kind) => findings.filter((f) => f.kind === kind).length;
262
+ const pages = scan?.pages?.selected ?? [];
263
+ const stateIds = (scan?.states ?? []).map((entry) => entry.id);
264
+ // Pages visited in any state; fewer than were picked when the scan could not reach some. WEC
265
+ // lists a page at the address it ended on, so a redirect must not count as one more.
266
+ const visited = Math.min(pages.length, new Set((scan?.results ?? []).flatMap((result) => result.visited ?? [])).size);
267
+ const stats = summary
268
+ ? [
269
+ [visited, card.stats.pages(visited, pages.length)],
270
+ [stateIds.length, card.stats.states(stateIds.length)],
271
+ [count("cookie"), card.stats.cookies(count("cookie"))],
272
+ [count("localStorage"), card.stats.storage()],
273
+ [count("host"), card.stats.hosts(count("host"))],
274
+ ]
275
+ : [];
276
+ const took = scan?.startedAt && scan.finishedAt
277
+ ? formatElapsed(Date.parse(scan.finishedAt) - Date.parse(scan.startedAt))
278
+ : 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
280
+ ? card.stage(capitalize(stateLabel(copy, live.stage.state)), live.stage)
281
+ : live.progress
282
+ ? progressLabel(copy, live.progress)
283
+ : card.text.choosing })) : null, state === "failed" ? _jsx("p", { children: scan?.error }) : null, state === "action" ||
284
+ state === "unknown" ||
285
+ state === "incomplete" ||
286
+ state === "ok" ||
287
+ state === "clean" ? (_jsx("p", { children: card.text[state] })) : null] }), state === "running" && live.stage ? (
288
+ // 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) => {
290
+ const problem = describeProblem(raw, stateIds);
291
+ const label = problem.state ? stateLabel(copy, problem.state) : "";
292
+ const text = problem.kind === "sitemap"
293
+ ? card.problems.sitemap(problem.sitemap ?? "")
294
+ : problem.kind === "other"
295
+ ? card.problems.other()
296
+ : card.problems[problem.kind](capitalize(label));
297
+ return (_jsxs("li", { children: [text, problem.kind === "notScanned" || problem.kind === "noPages" ? null : (_jsx("span", { className: "consent-scan__detail", children: problem.detail }))] }, raw));
298
+ }) })) : null, error ? _jsx("p", { className: "consent-scan__error", children: error }) : null, stats.length ? (_jsx("dl", { className: "consent-scan__stats", children: stats.map(([value, label]) => (_jsxs("div", { children: [_jsx("dt", { children: label }), _jsx("dd", { children: value })] }, String(label)))) })) : null, summary ? (_jsxs("div", { className: "consent-scan__foot", children: [_jsxs("p", { className: "consent-scan__meta", children: [card.scanned(dateLabel(scan?.finishedAt, language), took), stateIds.length
299
+ ? ` · ${card.states(stateIds.length, statesLabel(copy, stateIds, language))}`
300
+ : "", " · ", _jsx("a", { href: scansUrl, children: card.all })] }), pages.length ? (_jsx(Collapsible, { className: "consent-scan__pages", header: card.pages(pages.length), initCollapsed: true, children: _jsx("ul", { children: pages.map((page) => (_jsx("li", { children: _jsx("a", { href: page, rel: "noopener noreferrer", target: "_blank", title: page, children: pagePath(page) }) }, page))) }) })) : null] })) : scan ? (_jsx("p", { className: "consent-scan__meta", children: _jsx("a", { href: scansUrl, children: card.all }) })) : null] }));
301
+ }
302
+ function capitalize(value) {
303
+ return value ? `${value[0]?.toUpperCase()}${value.slice(1)}` : value;
304
+ }
108
305
  /** `accept-all (3/3)` from the scanner, in the editor's words. */
109
306
  function progressLabel(copy, progress) {
110
307
  const match = progress?.match(/^(\S+) \((\d+\/\d+)\)$/);
@@ -124,6 +321,7 @@ export function ScanPanel() {
124
321
  const [live, setLive] = useState({});
125
322
  const [busy, setBusy] = useState(false);
126
323
  const [error, setError] = useState();
324
+ const [now, setNow] = useState(() => Date.now());
127
325
  const load = useCallback(async () => {
128
326
  const response = await fetch(`${api}?sort=-createdAt&limit=1&depth=0`, {
129
327
  credentials: "include",
@@ -155,6 +353,14 @@ export function ScanPanel() {
155
353
  clearInterval(timer);
156
354
  };
157
355
  }, [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";
358
+ useEffect(() => {
359
+ if (!running)
360
+ return;
361
+ const timer = setInterval(() => setNow(Date.now()), 1000);
362
+ return () => clearInterval(timer);
363
+ }, [running]);
158
364
  async function start() {
159
365
  setBusy(true);
160
366
  setError(undefined);
@@ -179,9 +385,7 @@ export function ScanPanel() {
179
385
  // The scanner knows first when a queued scan starts running.
180
386
  const current = active ? (live.status ?? scan?.status) : scan?.status;
181
387
  const findings = scan?.findings ?? [];
182
- return (_jsxs("div", { className: "consent-scan", children: [_jsxs("div", { className: "consent-scan__bar", children: [_jsx(Button, { buttonStyle: "primary", disabled: busy || active, margin: false, onClick: start, size: "medium", children: busy ? copy.starting : copy.scan }), _jsxs("span", { "aria-live": "polite", className: "consent-scan__status", children: [scan === null ? copy.none : null, current === "queued" ? copy.queued(live.position) : null, current === "running" ? copy.running(progressLabel(copy, live.progress)) : null, scan?.status === "failed" ? `${copy.failed} ${scan.error ?? ""}` : null, scan?.status === "done"
183
- ? copy.done(new Date(scan.finishedAt ?? "").toLocaleString(language === "sv" ? "sv-SE" : "en-GB"), scan.pages?.selected?.length ?? 0)
184
- : null] })] }), error ? _jsx("p", { className: "consent-scan__error", children: error }) : null, scan?.status === "done" && scan.summary ? (_jsx("p", { className: "consent-scan__summary", children: copy.summary(scan.summary) })) : null, scan?.status === "done" && scan.summary?.problems?.length ? (_jsxs("div", { className: "consent-scan__error", children: [_jsx("p", { children: copy.incomplete }), _jsx("ul", { children: scan.summary.problems.map((problem) => (_jsx("li", { children: problem }, problem))) })] })) : null, scan?.status === "done"
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"
185
389
  ? ["action", "unknown", "ok"].map((status) => {
186
390
  const rows = findings.filter((finding) => finding.status === status);
187
391
  if (!rows.length)
@@ -8,4 +8,5 @@ export declare function ServicesPanel(): import("react").JSX.Element;
8
8
  /** The Consent log tab: how many choices are on record, with links to the records and policies. */
9
9
  export declare function ConsentLogPanel(): import("react").JSX.Element;
10
10
  /** Links under the Scan tab to every scan, since the collection is not in the navigation. */
11
+ /** No longer placed by the plugin (the scan card links to the scans); kept for import maps. */
11
12
  export declare function ScanLinks(): import("react").JSX.Element;
@@ -129,6 +129,7 @@ export function ConsentLogPanel() {
129
129
  return (_jsxs("ul", { className: "consent-panel__links", children: [_jsxs("li", { children: [_jsx("a", { href: `${admin}/${CONSENT_RECORDS}`, children: copy.openRecords }), _jsx("span", { className: "consent-scan__note", children: records === undefined ? copy.loading : copy.records(records) })] }), _jsxs("li", { children: [_jsx("a", { href: `${admin}/${CONSENT_POLICIES}`, children: copy.openPolicies }), _jsx("span", { className: "consent-scan__note", children: policies === undefined ? copy.loading : copy.policies(policies) })] })] }));
130
130
  }
131
131
  /** Links under the Scan tab to every scan, since the collection is not in the navigation. */
132
+ /** No longer placed by the plugin (the scan card links to the scans); kept for import maps. */
132
133
  export function ScanLinks() {
133
134
  const copy = useCopy();
134
135
  const { admin } = useRoutes();
@@ -0,0 +1,28 @@
1
+ import type { ScanSummary } from "../evaluate.ts";
2
+ import type { ScanStage } from "../scans.ts";
3
+ /**
4
+ * What a finished scan means for the editor, most urgent first: services loading without consent,
5
+ * findings no service explains, a scan that could not see everything, then nothing to fix, with
6
+ * (`ok`) or without (`clean`) anything found.
7
+ */
8
+ export type ScanVerdict = "action" | "unknown" | "incomplete" | "ok" | "clean";
9
+ export declare function scanVerdict(summary: ScanSummary): ScanVerdict;
10
+ /** Pages finished in all states, for the progress bar: the page being visited is not yet. */
11
+ export declare function finishedPages(stage: ScanStage): number;
12
+ /** `0:07`, `12:30`, `1:02:03`. */
13
+ export declare function formatElapsed(ms: number): string;
14
+ /** A problem from `scanProblems` sorted into what an editor can read; `detail` is the raw text. */
15
+ export type ScanProblem = {
16
+ kind: "notScanned" | "noPages" | "outOfTime" | "pagesFailed" | "sitemap" | "other";
17
+ state?: string;
18
+ sitemap?: string;
19
+ detail: string;
20
+ };
21
+ export declare function describeProblem(problem: string, stateIds: string[]): ScanProblem;
22
+ /**
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.
25
+ */
26
+ export declare function estimateLeft(elapsedMs: number, stage: ScanStage): number | undefined;
27
+ /** `/about?x=1` for a page on the scanned site: the address without its origin. */
28
+ export declare function pagePath(url: string): string;
@@ -0,0 +1,58 @@
1
+ export function scanVerdict(summary) {
2
+ if (summary.action)
3
+ return "action";
4
+ if (summary.unknown)
5
+ return "unknown";
6
+ if (summary.problems?.length)
7
+ return "incomplete";
8
+ return summary.ok ? "ok" : "clean";
9
+ }
10
+ /** Pages finished in all states, for the progress bar: the page being visited is not yet. */
11
+ export function finishedPages(stage) {
12
+ return Math.max(0, stage.page > 0 ? stage.visited - 1 : stage.visited);
13
+ }
14
+ /** `0:07`, `12:30`, `1:02:03`. */
15
+ export function formatElapsed(ms) {
16
+ const seconds = Math.max(0, Math.floor(ms / 1000));
17
+ const h = Math.floor(seconds / 3600);
18
+ const m = Math.floor((seconds % 3600) / 60);
19
+ const s = String(seconds % 60).padStart(2, "0");
20
+ return h ? `${h}:${String(m).padStart(2, "0")}:${s}` : `${m}:${s}`;
21
+ }
22
+ export function describeProblem(problem, stateIds) {
23
+ const sitemap = problem.match(/^Sitemap (\S+): (.*)$/s);
24
+ if (sitemap)
25
+ return { kind: "sitemap", sitemap: sitemap[1], detail: sitemap[2] ?? "" };
26
+ const prefixed = problem.match(/^([a-z0-9-]+): (.*)$/s);
27
+ const state = prefixed?.[1];
28
+ if (!prefixed || !state || !stateIds.includes(state))
29
+ return { kind: "other", detail: problem };
30
+ const detail = prefixed[2] ?? "";
31
+ if (detail === "not scanned")
32
+ return { kind: "notScanned", state, detail };
33
+ if (detail === "no page could be visited")
34
+ return { kind: "noPages", state, detail };
35
+ if (/ran out of time/.test(detail))
36
+ return { kind: "outOfTime", state, detail };
37
+ return { kind: "pagesFailed", state, detail };
38
+ }
39
+ /**
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.
42
+ */
43
+ export function estimateLeft(elapsedMs, stage) {
44
+ const finished = finishedPages(stage);
45
+ if (finished < 1 || elapsedMs <= 0)
46
+ return undefined;
47
+ return (elapsedMs / finished) * Math.max(0, stage.total - finished);
48
+ }
49
+ /** `/about?x=1` for a page on the scanned site: the address without its origin. */
50
+ export function pagePath(url) {
51
+ try {
52
+ const { pathname, search } = new URL(url);
53
+ return `${pathname}${search}`;
54
+ }
55
+ catch {
56
+ return url;
57
+ }
58
+ }
package/dist/global.js CHANGED
@@ -186,6 +186,14 @@ export function consentGlobal(options, { usersSlug, schedule }) {
186
186
  sv: "Skannar den publicerade webbplatsen som ny besökare, efter avvisa och efter godkänn, och jämför det som hittas med Cookietjänsterna.",
187
187
  },
188
188
  fields: [
189
+ // The scan first: its settings follow.
190
+ {
191
+ name: "scanPanel",
192
+ type: "ui",
193
+ admin: {
194
+ components: { Field: "@simmalugnt-se/payload-consent/admin#ScanPanel" },
195
+ },
196
+ },
189
197
  {
190
198
  name: "scanUrl",
191
199
  type: "text",
@@ -223,20 +231,6 @@ export function consentGlobal(options, { usersSlug, schedule }) {
223
231
  },
224
232
  },
225
233
  },
226
- {
227
- name: "scanPanel",
228
- type: "ui",
229
- admin: {
230
- components: { Field: "@simmalugnt-se/payload-consent/admin#ScanPanel" },
231
- },
232
- },
233
- {
234
- name: "scanLinks",
235
- type: "ui",
236
- admin: {
237
- components: { Field: "@simmalugnt-se/payload-consent/admin#ScanLinks" },
238
- },
239
- },
240
234
  ],
241
235
  },
242
236
  ...(options.records === false
package/dist/scans.d.ts CHANGED
@@ -10,18 +10,34 @@ import { type ConsentPluginOptions } from "./types.ts";
10
10
  */
11
11
  export declare function scanStates(config: Pick<ConsentConfig, "categories" | "policyVersion">, now?: number): ScanState[];
12
12
  /**
13
- * The published pages of `scanner.pages` as addresses on the scanned site, read as a visitor would
14
- * (`overrideAccess: false`) in the default locale. Paths are taken relative to `url`; addresses on
15
- * another origin are left out, since the scanner refuses them. More than `MAX_SCAN_PAGES` are
16
- * thinned evenly. `undefined` without any, so the scanner reads the sitemaps.
13
+ * The published pages of `scanner.pages`, a list per collection, as addresses on the scanned site,
14
+ * read as a visitor would (`overrideAccess: false`) in the default locale. The scanner picks from
15
+ * each list as from one sitemap, so a large collection does not crowd out a small one. Paths are
16
+ * taken relative to `url`; addresses on another origin are left out, since the scanner refuses
17
+ * them. The lists share `MAX_SCAN_PAGES`, each thinned evenly to its share. `undefined` without
18
+ * any page, so the scanner reads the sitemaps.
17
19
  */
18
- export declare function scanPages(payload: Payload, options: ConsentPluginOptions, url: string): Promise<string[] | undefined>;
20
+ export declare function scanPages(payload: Payload, options: ConsentPluginOptions, url: string): Promise<string[][] | undefined>;
19
21
  type Started = {
20
22
  id: number | string;
21
23
  } | {
22
24
  error: string;
23
25
  status: number;
24
26
  };
27
+ /**
28
+ * Where a running scan is, from the scanner: the state (`stateNumber` of `states`), the page it is
29
+ * on in that state (`page` of `pages`, 0 before the first), and pages begun in all states
30
+ * (`visited` of `total`).
31
+ */
32
+ export type ScanStage = {
33
+ state: string;
34
+ stateNumber: number;
35
+ states: number;
36
+ page: number;
37
+ pages: number;
38
+ visited: number;
39
+ total: number;
40
+ };
25
41
  /**
26
42
  * Asks the scanner to scan the site in every consent state and records the scan as queued. The
27
43
  * address is the one given (the Scan tab's field, saved or not), then the saved one, then the
package/dist/scans.js CHANGED
@@ -37,17 +37,21 @@ export function scanStates(config, now = Date.now()) {
37
37
  return states;
38
38
  }
39
39
  /**
40
- * The published pages of `scanner.pages` as addresses on the scanned site, read as a visitor would
41
- * (`overrideAccess: false`) in the default locale. Paths are taken relative to `url`; addresses on
42
- * another origin are left out, since the scanner refuses them. More than `MAX_SCAN_PAGES` are
43
- * thinned evenly. `undefined` without any, so the scanner reads the sitemaps.
40
+ * The published pages of `scanner.pages`, a list per collection, as addresses on the scanned site,
41
+ * read as a visitor would (`overrideAccess: false`) in the default locale. The scanner picks from
42
+ * each list as from one sitemap, so a large collection does not crowd out a small one. Paths are
43
+ * taken relative to `url`; addresses on another origin are left out, since the scanner refuses
44
+ * them. The lists share `MAX_SCAN_PAGES`, each thinned evenly to its share. `undefined` without
45
+ * any page, so the scanner reads the sitemaps.
44
46
  */
45
47
  export async function scanPages(payload, options, url) {
46
48
  const site = new URL(url);
47
49
  const localization = payload.config.localization;
48
50
  const locale = localization ? localization.defaultLocale : undefined;
49
- const found = new Set();
50
- for (const { collection, url: toUrl } of options.scanner?.pages ?? []) {
51
+ const collections = options.scanner?.pages ?? [];
52
+ const share = Math.floor(MAX_SCAN_PAGES / Math.max(collections.length, 1));
53
+ const lists = [];
54
+ for (const { collection, url: toUrl } of collections) {
51
55
  const drafts = Boolean(payload.config.collections.find(({ slug }) => slug === collection)?.versions?.drafts);
52
56
  const { docs } = await payload.find({
53
57
  collection: collection,
@@ -57,6 +61,7 @@ export async function scanPages(payload, options, url) {
57
61
  overrideAccess: false,
58
62
  ...(drafts ? { where: { _status: { equals: "published" } } } : {}),
59
63
  });
64
+ const found = new Set();
60
65
  for (const doc of docs) {
61
66
  let address;
62
67
  try {
@@ -73,11 +78,18 @@ export async function scanPages(payload, options, url) {
73
78
  address.hash = "";
74
79
  found.add(address.href);
75
80
  }
81
+ const pages = [...found].sort();
82
+ if (pages.length)
83
+ lists.push(evenlySpaced(pages, share));
76
84
  }
77
- const pages = [...found].sort();
78
- if (pages.length <= MAX_SCAN_PAGES)
79
- return pages.length ? pages : undefined;
80
- return Array.from({ length: MAX_SCAN_PAGES }, (_, index) => pages[Math.round((index * (pages.length - 1)) / (MAX_SCAN_PAGES - 1))]);
85
+ return lists.length ? lists : undefined;
86
+ }
87
+ function evenlySpaced(values, maximum) {
88
+ if (values.length <= maximum)
89
+ return values;
90
+ if (maximum === 1)
91
+ return values.slice(0, 1);
92
+ return Array.from({ length: maximum }, (_, index) => values[Math.round((index * (values.length - 1)) / (maximum - 1))]);
81
93
  }
82
94
  function sameToken(given, expected) {
83
95
  const a = Buffer.from(given);
@@ -365,6 +377,8 @@ function endpoints(options) {
365
377
  status: live.status,
366
378
  position: live.position,
367
379
  progress: live.progress,
380
+ stage: live.stage,
381
+ startedAt: live.startedAt,
368
382
  });
369
383
  },
370
384
  },
@@ -10,13 +10,118 @@
10
10
  align-items: center;
11
11
  gap: calc(var(--base) * 0.75);
12
12
  }
13
- .consent-scan__status,
14
- .consent-scan__summary {
13
+ .consent-scan__card {
14
+ display: grid;
15
+ gap: calc(var(--base) * 0.75);
16
+ padding: calc(var(--base) * 1.25);
17
+ border: 1px solid var(--theme-elevation-150);
18
+ border-radius: var(--style-radius-m);
19
+ background: var(--theme-elevation-0);
20
+ }
21
+ .consent-scan__card--error {
22
+ border-color: var(--theme-error-500);
23
+ }
24
+ .consent-scan__card--warning {
25
+ border-color: var(--theme-warning-500);
26
+ }
27
+ .consent-scan__head {
28
+ display: flex;
29
+ align-items: center;
30
+ justify-content: space-between;
31
+ gap: var(--base);
32
+ }
33
+ .consent-scan__pills {
34
+ display: flex;
35
+ flex-wrap: wrap;
36
+ gap: calc(var(--base) * 0.25);
37
+ }
38
+ .consent-scan__body {
39
+ display: grid;
40
+ gap: calc(var(--base) * 0.25);
41
+ }
42
+ .consent-scan__title {
43
+ margin: 0;
44
+ }
45
+ .consent-scan__body p {
46
+ margin: 0;
15
47
  color: var(--theme-elevation-800);
16
48
  }
17
- .consent-scan__summary {
49
+ .consent-scan__meta {
50
+ margin: 0;
51
+ color: var(--theme-elevation-500);
52
+ }
53
+ .consent-scan__progress {
54
+ width: 100%;
55
+ height: calc(var(--base) * 0.4);
56
+ appearance: none;
57
+ border: 0;
58
+ border-radius: var(--style-radius-s);
59
+ background: var(--theme-elevation-100);
60
+ overflow: hidden;
61
+ }
62
+ .consent-scan__progress::-webkit-progress-bar {
63
+ background: var(--theme-elevation-100);
64
+ }
65
+ .consent-scan__progress::-webkit-progress-value {
66
+ background: var(--theme-success-500);
67
+ transition: width 0.4s ease;
68
+ }
69
+ .consent-scan__progress::-moz-progress-bar {
70
+ background: var(--theme-success-500);
71
+ }
72
+ .consent-scan__problems {
73
+ display: grid;
74
+ gap: calc(var(--base) * 0.25);
75
+ margin: 0;
76
+ padding-left: var(--base);
77
+ }
78
+ .consent-scan__detail {
79
+ display: block;
80
+ color: var(--theme-elevation-500);
81
+ font-size: 0.9em;
82
+ word-break: break-word;
83
+ }
84
+ .consent-scan__stats {
85
+ display: grid;
86
+ grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
87
+ gap: calc(var(--base) * 0.5);
88
+ margin: 0;
89
+ padding-block: calc(var(--base) * 0.75);
90
+ border-block: 1px solid var(--theme-elevation-100);
91
+ }
92
+ .consent-scan__stats div {
93
+ display: flex;
94
+ flex-direction: column-reverse;
95
+ }
96
+ .consent-scan__stats dd {
18
97
  margin: 0;
98
+ font-size: 1.5rem;
19
99
  font-weight: 600;
100
+ line-height: 1.2;
101
+ }
102
+ .consent-scan__stats dt {
103
+ color: var(--theme-elevation-500);
104
+ }
105
+ .consent-scan__foot {
106
+ display: grid;
107
+ gap: calc(var(--base) * 0.5);
108
+ }
109
+ .consent-scan__meta a {
110
+ color: inherit;
111
+ }
112
+ .consent-scan__pages {
113
+ margin: 0;
114
+ }
115
+ .consent-scan__pages ul {
116
+ display: grid;
117
+ gap: calc(var(--base) * 0.25);
118
+ margin: 0;
119
+ padding: 0;
120
+ list-style: none;
121
+ }
122
+ .consent-scan__pages a {
123
+ color: var(--theme-elevation-800);
124
+ word-break: break-all;
20
125
  }
21
126
  .consent-scan__note {
22
127
  margin: 0;
package/dist/types.d.ts CHANGED
@@ -58,7 +58,8 @@ export type ConsentPluginOptions = {
58
58
  * Collections whose published documents are the site's pages; `url` turns a document into its
59
59
  * path or address, as in `legalPages`, or returns nothing to leave it out. A scan sends these
60
60
  * pages to the scanner in place of the site's sitemaps, which a site with search indexing off
61
- * leaves empty. Without it, the scanner reads the sitemaps.
61
+ * leaves empty, and the scanner picks from each collection as from one sitemap. Without it,
62
+ * the scanner reads the sitemaps.
62
63
  */
63
64
  pages?: {
64
65
  collection: CollectionSlug;
@@ -85,5 +86,5 @@ export declare const POLICY_COOKIE = "c15t-policy";
85
86
  /** Three years, unless the host sets `records.retentionDays`. */
86
87
  export declare const DEFAULT_RETENTION_DAYS: number;
87
88
  export declare const DEFAULT_KEEP_EVIDENCE = 12;
88
- /** The most pages a scan sends; the scanner takes up to 500. */
89
+ /** The most pages a scan sends, in all its lists; the scanner takes up to 500. */
89
90
  export declare const MAX_SCAN_PAGES = 500;
package/dist/types.js CHANGED
@@ -15,5 +15,5 @@ export const POLICY_COOKIE = "c15t-policy";
15
15
  /** Three years, unless the host sets `records.retentionDays`. */
16
16
  export const DEFAULT_RETENTION_DAYS = 3 * 365;
17
17
  export const DEFAULT_KEEP_EVIDENCE = 12;
18
- /** The most pages a scan sends; the scanner takes up to 500. */
18
+ /** The most pages a scan sends, in all its lists; the scanner takes up to 500. */
19
19
  export const MAX_SCAN_PAGES = 500;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-consent",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Cookie consent for Payload sites: banner texts, services and scans in Admin",
5
5
  "keywords": [
6
6
  "payload",