@simmalugnt-se/payload-consent 0.7.0 → 0.7.1

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.1
4
+
5
+ - A scan after one that found nothing marks everything it finds as new, and so sends its email.
6
+ Before, it was treated as a site's first scan, where nothing is new, and a site that gained its
7
+ first service after an empty scan got no email.
8
+
3
9
  ## 0.7.0
4
10
 
5
11
  - Built on c15t 3.2.2 (`@c15t/react`, and `@c15t/integrations` in place of `@c15t/scripts`). A project
@@ -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/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;
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.7.1",
4
4
  "description": "Cookie consent for Payload sites: banner texts, services and scans in Admin",
5
5
  "keywords": [
6
6
  "payload",