@simmalugnt-se/payload-consent 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+
5
+ - The consent log's Allowed categories and a scan's Status show English and Swedish names instead
6
+ of their stored values (`necessary`, `queued`), and a scan's start and finish times have labels.
7
+ Stored values are unchanged, so no migration.
8
+ - `access.manage` defaults to users signed in to Admin (the config's `admin.user`). Any signed-in
9
+ user could manage cookies and read the consent log, a site member or customer from another auth
10
+ collection too. A site that passes `access.manage` is unaffected.
11
+
12
+ ## 0.7.1
13
+
14
+ - A scan after one that found nothing marks everything it finds as new, and so sends its email.
15
+ Before, it was treated as a site's first scan, where nothing is new, and a site that gained its
16
+ first service after an empty scan got no email.
17
+
3
18
  ## 0.7.0
4
19
 
5
20
  - Built on c15t 3.2.2 (`@c15t/react`, and `@c15t/integrations` in place of `@c15t/scripts`). A project
package/README.md CHANGED
@@ -304,7 +304,8 @@ banner's own consent storage first: `c15t` (the choice), `c15t-sid` (the visitor
304
304
  The global and the services are public to read by default (`access.read`), since the site shows
305
305
  them to everyone. `access.manage` says who works with cookies in Admin: changing the texts and
306
306
  services, reading the consent log, the policies, the scans and their evidence, starting a scan and
307
- adding its findings, and seeing the dashboard widget. It defaults to signed-in users; with roles,
307
+ adding its findings, and seeing the dashboard widget. It defaults to users signed in to Admin
308
+ (the config's `admin.user`), not users of another auth collection such as site members; with roles,
308
309
  pass the project's:
309
310
 
310
311
  ```ts
package/dist/access.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Access, PayloadRequest } from "payload";
2
2
  import type { ConsentPluginOptions } from "./types.ts";
3
- /** Who works with cookies in Admin (`access.manage`); signed-in users unless the host says. */
3
+ /** Who works with cookies in Admin (`access.manage`); Admin's users unless the host says. */
4
4
  export declare function manageAccess(options: ConsentPluginOptions): Access;
5
5
  /** Whether `manage` lets this request through; a query result counts as yes. */
6
6
  export declare function canManage(options: ConsentPluginOptions, req: PayloadRequest): Promise<boolean>;
package/dist/access.js CHANGED
@@ -1,7 +1,8 @@
1
- const signedIn = ({ req }) => Boolean(req.user);
2
- /** Who works with cookies in Admin (`access.manage`); signed-in users unless the host says. */
1
+ /** Signed in to Admin: a user of the config's `admin.user`, not of another auth collection. */
2
+ const adminUser = ({ req }) => Boolean(req.user && req.user.collection === req.payload.config.admin.user);
3
+ /** Who works with cookies in Admin (`access.manage`); Admin's users unless the host says. */
3
4
  export function manageAccess(options) {
4
- return options.access?.manage ?? signedIn;
5
+ return options.access?.manage ?? adminUser;
5
6
  }
6
7
  /** Whether `manage` lets this request through; a query result counts as yes. */
7
8
  export async function canManage(options, req) {
@@ -115,6 +115,7 @@ export declare function evaluateScan({ states, results, services, previousKeys,
115
115
  states: ScanState[];
116
116
  results: ScanResultState[];
117
117
  services: ServiceDocument[];
118
+ /** The previous finished scan's finding keys; without one, nothing is new. */
118
119
  previousKeys?: string[];
119
120
  }): {
120
121
  findings: Finding[];
package/dist/evaluate.js CHANGED
@@ -44,8 +44,8 @@ function findService(services, kind, name) {
44
44
  * and third-party host, once, with the states it was seen in. First-party hosts are the site itself
45
45
  * and are left out.
46
46
  */
47
- export function evaluateScan({ states, results, services, previousKeys = [], }) {
48
- const previous = new Set(previousKeys);
47
+ export function evaluateScan({ states, results, services, previousKeys, }) {
48
+ const previous = previousKeys ? new Set(previousKeys) : undefined;
49
49
  const allowedIn = new Map(states.map((state) => [state.id, new Set(state.allowed)]));
50
50
  const necessaryOnly = new Set(states.filter((state) => state.allowed.every((c) => c === "necessary")).map((s) => s.id));
51
51
  const found = new Map();
@@ -63,7 +63,8 @@ export function evaluateScan({ states, results, services, previousKeys = [], })
63
63
  withoutConsent: [],
64
64
  status: "unknown",
65
65
  beforeConsent: false,
66
- isNew: previousKeys.length > 0 && !previous.has(key),
66
+ // A scan after one that found nothing has only new findings.
67
+ isNew: previous ? !previous.has(key) : false,
67
68
  ...extra,
68
69
  };
69
70
  found.set(key, finding);
package/dist/records.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { manageAccess } from "./access.js";
2
2
  import { CATEGORIES } from "./defaults.js";
3
+ import { categoryLabels } from "./global.js";
3
4
  import { allowedOrigin, clientKey, createRateLimit, MAX_RECORD_BYTES } from "./record-guard.js";
4
5
  import { readConsent, toConsentConfig } from "./site-config.js";
5
6
  import { CONSENT_POLICIES, CONSENT_RECORDS, DEFAULT_RETENTION_DAYS, } from "./types.js";
@@ -204,7 +205,7 @@ export function recordsCollection(options) {
204
205
  type: "select",
205
206
  hasMany: true,
206
207
  label: { en: "Allowed", sv: "Tillåtna" },
207
- options: CATEGORIES.map((value) => ({ value, label: value })),
208
+ options: CATEGORIES.map((value) => ({ value, label: categoryLabels[value] })),
208
209
  },
209
210
  { name: "choices", type: "json", label: { en: "Choices", sv: "Val" } },
210
211
  {
package/dist/scans.js CHANGED
@@ -110,6 +110,10 @@ async function latestDone(req, before) {
110
110
  });
111
111
  return docs[0];
112
112
  }
113
+ /** A finished scan's finding keys, or none without a finished scan: then nothing counts as new. */
114
+ function findingKeys(scan) {
115
+ return scan ? (scan.findings ?? []).map((f) => f.key) : undefined;
116
+ }
113
117
  async function allServices(req) {
114
118
  const { docs } = await req.payload.find({
115
119
  collection: CONSENT_SERVICES,
@@ -307,7 +311,7 @@ function endpoints(options) {
307
311
  states: scan.states ?? [],
308
312
  results: result.states ?? [],
309
313
  services: await allServices(req),
310
- previousKeys: ((await latestDone(req, scan.id))?.findings ?? []).map((f) => f.key),
314
+ previousKeys: findingKeys(await latestDone(req, scan.id)),
311
315
  })
312
316
  : undefined;
313
317
  const problems = done
@@ -499,7 +503,7 @@ function endpoints(options) {
499
503
  results: (latest.results ??
500
504
  []),
501
505
  services: await allServices(req),
502
- previousKeys: (previous?.findings ?? []).map((f) => f.key),
506
+ previousKeys: findingKeys(previous),
503
507
  });
504
508
  // Judged again against the services; what the scan could not see stays as it was.
505
509
  const problems = latest.summary?.problems;
@@ -564,7 +568,12 @@ export function scansCollection(options) {
564
568
  name: "status",
565
569
  type: "select",
566
570
  label: { en: "Status", sv: "Status" },
567
- options: ["queued", "running", "done", "failed"].map((value) => ({ value, label: value })),
571
+ options: [
572
+ { value: "queued", label: { en: "Queued", sv: "I kö" } },
573
+ { value: "running", label: { en: "Running", sv: "Pågår" } },
574
+ { value: "done", label: { en: "Done", sv: "Klar" } },
575
+ { value: "failed", label: { en: "Failed", sv: "Misslyckades" } },
576
+ ],
568
577
  },
569
578
  {
570
579
  name: "trigger",
@@ -577,8 +586,18 @@ export function scansCollection(options) {
577
586
  },
578
587
  { name: "scanId", type: "text", index: true, admin: { hidden: true } },
579
588
  { name: "error", type: "text", label: { en: "Error", sv: "Fel" } },
580
- { name: "startedAt", type: "date", admin: { date: { pickerAppearance: "dayAndTime" } } },
581
- { name: "finishedAt", type: "date", admin: { date: { pickerAppearance: "dayAndTime" } } },
589
+ {
590
+ name: "startedAt",
591
+ type: "date",
592
+ label: { en: "Start time", sv: "Starttid" },
593
+ admin: { date: { pickerAppearance: "dayAndTime" } },
594
+ },
595
+ {
596
+ name: "finishedAt",
597
+ type: "date",
598
+ label: { en: "Finish time", sv: "Sluttid" },
599
+ admin: { date: { pickerAppearance: "dayAndTime" } },
600
+ },
582
601
  { name: "summary", type: "json", label: { en: "Summary", sv: "Sammanfattning" } },
583
602
  { name: "findings", type: "json", label: { en: "Findings", sv: "Fynd" } },
584
603
  { name: "states", type: "json", label: { en: "States", sv: "Lägen" } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-consent",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Cookie consent for Payload sites: banner texts, services and scans in Admin",
5
5
  "keywords": [
6
6
  "payload",