@simmalugnt-se/payload-consent 0.6.1 → 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,15 @@
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
+
3
13
  ## 0.6.1
4
14
 
5
15
  - `scanner.pages` sends a list per collection, and the scanner picks from each as from one sitemap:
package/README.md CHANGED
@@ -139,11 +139,16 @@ Each collection goes as its own list, and the scanner picks from each as from on
139
139
  thousand news articles do not crowd out the pages; the lists share at most 500 addresses, each
140
140
  thinned evenly. Without the option, or when no page is left, the scanner reads the sitemaps.
141
141
 
142
- 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,
143
143
  after rejecting, after accepting and, with several optional categories, with each one alone. The
144
- plugin presets c15t's cookie for each state, so no click is needed. The scanner posts the result
145
- back to `/api/consent-scans/result`, and the tab shows every cookie, localStorage key and
146
- 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:
147
152
 
148
153
  - **Needs action**: a service seen in a state that does not allow its category, such as analytics
149
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
@@ -24,6 +24,20 @@ type Started = {
24
24
  error: string;
25
25
  status: number;
26
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
+ };
27
41
  /**
28
42
  * Asks the scanner to scan the site in every consent state and records the scan as queued. The
29
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
@@ -377,6 +377,8 @@ function endpoints(options) {
377
377
  status: live.status,
378
378
  position: live.position,
379
379
  progress: live.progress,
380
+ stage: live.stage,
381
+ startedAt: live.startedAt,
380
382
  });
381
383
  },
382
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-consent",
3
- "version": "0.6.1",
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",