@simmalugnt-se/payload-consent 0.6.7 → 0.6.9
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 +22 -0
- package/README.md +7 -2
- package/dist/admin/RowLabels.d.ts +7 -0
- package/dist/admin/RowLabels.js +41 -0
- package/dist/admin/ScanPanel.js +3 -0
- package/dist/exports/admin.d.ts +1 -0
- package/dist/exports/admin.js +1 -0
- package/dist/retention.d.ts +3 -0
- package/dist/retention.js +27 -0
- package/dist/scans.js +44 -9
- package/dist/services.js +5 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.9
|
|
4
|
+
|
|
5
|
+
- A scan visits every page it finds as a new visitor, up to 500 in all, and 30 pages in each other
|
|
6
|
+
consent state, spread over the lists or sitemaps. Before, the scanner's defaults applied: the
|
|
7
|
+
start page and 10 pages from each list or sitemap, and the first 10 of them in the other states,
|
|
8
|
+
whatever `scanner.pages` sent. Needs `consent-scanner` at `8fc560c` or later: an older one refuses
|
|
9
|
+
the scan. Scans take longer on large sites, roughly 3–4 seconds per page.
|
|
10
|
+
|
|
11
|
+
## 0.6.8
|
|
12
|
+
|
|
13
|
+
- Add to service on a scan's finding gives the row the cookie's description from the Open Cookie
|
|
14
|
+
Database. Before, the description only became a new service's purpose, so a cookie added to an
|
|
15
|
+
existing service had none.
|
|
16
|
+
- The finding's texts go in English, the database's language, when the site has English, with the
|
|
17
|
+
duration in Swedish too ("1 år", "13 månader", "Session"); the Swedish description falls back
|
|
18
|
+
to English until someone writes it. Before, they went in Admin's language, so a Swedish Admin
|
|
19
|
+
stored "1 year" as the Swedish duration and left the English empty.
|
|
20
|
+
- A cookie the scan saw on another site's domain is added as third party.
|
|
21
|
+
- A Cookie service's collapsed rows say what they are: "_ga · Cookie · 2 år" for a cookie or key,
|
|
22
|
+
the host for a host, in place of "Cookie or key 01". A project regenerates its import map for
|
|
23
|
+
the two new row label components.
|
|
24
|
+
|
|
3
25
|
## 0.6.7
|
|
4
26
|
|
|
5
27
|
- The help under Site address and Scan every month stays out of the site's generated types. It
|
package/README.md
CHANGED
|
@@ -145,8 +145,13 @@ sends the published documents of those collections instead: read as a visitor wo
|
|
|
145
145
|
default locale, each turned into a path or address by `url` (return nothing to leave one out).
|
|
146
146
|
Paths are taken relative to the scanned address, and addresses on another origin are left out.
|
|
147
147
|
Each collection goes as its own list, and the scanner picks from each as from one sitemap, so a
|
|
148
|
-
thousand news articles do not crowd out the pages
|
|
149
|
-
|
|
148
|
+
thousand news articles do not crowd out the pages. Without the option, or when no page is left,
|
|
149
|
+
the scanner reads the sitemaps.
|
|
150
|
+
|
|
151
|
+
A scan visits every page it finds as a new visitor, up to 500 shared evenly between the lists or
|
|
152
|
+
sitemaps, and a list shorter than its share leaves the rest to the others. Each other state visits
|
|
153
|
+
30 of them: the start page and a spread from every list. This needs `consent-scanner` at
|
|
154
|
+
`8fc560c` or later; an older one refuses the scan.
|
|
150
155
|
|
|
151
156
|
Scan now scans the site's address (the Site address field; with it empty, `callbackBaseUrl`, then
|
|
152
157
|
`serverURL`, as the field's placeholder and help say) as a new visitor, after rejecting, after
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A collapsed cookie or storage row of a Cookie service, by what it is: "_ga · Cookie · 2 år".
|
|
3
|
+
* A row of text, since Payload's row labels take a component and none of its own fits.
|
|
4
|
+
*/
|
|
5
|
+
export declare function StorageRowLabel(): import("react").JSX.Element;
|
|
6
|
+
/** A collapsed host row of a Cookie service, by its host. */
|
|
7
|
+
export declare function HostRowLabel(): import("react").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useRowLabel, useTranslation } from "@payloadcms/ui";
|
|
4
|
+
const COPY = {
|
|
5
|
+
en: { storage: "Cookie or key", host: "Host", thirdParty: "third party" },
|
|
6
|
+
sv: { storage: "Cookie eller nyckel", host: "Värd", thirdParty: "tredje part" },
|
|
7
|
+
};
|
|
8
|
+
const TYPES = {
|
|
9
|
+
cookie: "Cookie",
|
|
10
|
+
localStorage: "localStorage",
|
|
11
|
+
sessionStorage: "sessionStorage",
|
|
12
|
+
};
|
|
13
|
+
function useLanguage() {
|
|
14
|
+
const { i18n } = useTranslation();
|
|
15
|
+
return i18n.language === "sv" ? "sv" : "en";
|
|
16
|
+
}
|
|
17
|
+
/** Payload's own label for a row with nothing in it yet, such as "Host 01". */
|
|
18
|
+
const numbered = (label, rowNumber) => `${label} ${String((rowNumber ?? 0) + 1).padStart(2, "0")}`;
|
|
19
|
+
/**
|
|
20
|
+
* A collapsed cookie or storage row of a Cookie service, by what it is: "_ga · Cookie · 2 år".
|
|
21
|
+
* A row of text, since Payload's row labels take a component and none of its own fits.
|
|
22
|
+
*/
|
|
23
|
+
export function StorageRowLabel() {
|
|
24
|
+
const copy = COPY[useLanguage()];
|
|
25
|
+
const { data, rowNumber } = useRowLabel();
|
|
26
|
+
const name = data?.name?.trim();
|
|
27
|
+
if (!name)
|
|
28
|
+
return _jsx("span", { children: numbered(copy.storage, rowNumber) });
|
|
29
|
+
const details = [
|
|
30
|
+
data?.type ? (TYPES[data.type] ?? data.type) : null,
|
|
31
|
+
data?.duration?.trim() || null,
|
|
32
|
+
data?.thirdParty ? copy.thirdParty : null,
|
|
33
|
+
].filter(Boolean);
|
|
34
|
+
return _jsx("span", { children: [name, ...details].join(" · ") });
|
|
35
|
+
}
|
|
36
|
+
/** A collapsed host row of a Cookie service, by its host. */
|
|
37
|
+
export function HostRowLabel() {
|
|
38
|
+
const copy = COPY[useLanguage()];
|
|
39
|
+
const { data, rowNumber } = useRowLabel();
|
|
40
|
+
return _jsx("span", { children: data?.host?.trim() || numbered(copy.host, rowNumber) });
|
|
41
|
+
}
|
package/dist/admin/ScanPanel.js
CHANGED
|
@@ -507,9 +507,12 @@ function FindingRow({ api, copy, finding, language, locale, onAdded, }) {
|
|
|
507
507
|
service,
|
|
508
508
|
category,
|
|
509
509
|
provider: suggestion?.provider,
|
|
510
|
+
// The finding's own description: the row's text, and a new service's purpose.
|
|
510
511
|
purpose: suggestion?.description,
|
|
512
|
+
description: suggestion?.description,
|
|
511
513
|
duration: suggestion?.retention,
|
|
512
514
|
policyUrl: suggestion?.privacyUrl,
|
|
515
|
+
firstParty: finding.firstParty,
|
|
513
516
|
locale,
|
|
514
517
|
}),
|
|
515
518
|
});
|
package/dist/exports/admin.d.ts
CHANGED
package/dist/exports/admin.js
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A retention from the Open Cookie Database ("1 year", "13 months", "session") in the site's
|
|
3
|
+
* languages. The database writes English; Swedish is worded here. A retention in any other form
|
|
4
|
+
* comes back as it was in English and as nothing in Swedish, which then falls back to English.
|
|
5
|
+
*/
|
|
6
|
+
const UNITS = {
|
|
7
|
+
second: { en: ["second", "seconds"], sv: ["sekund", "sekunder"] },
|
|
8
|
+
minute: { en: ["minute", "minutes"], sv: ["minut", "minuter"] },
|
|
9
|
+
hour: { en: ["hour", "hours"], sv: ["timme", "timmar"] },
|
|
10
|
+
day: { en: ["day", "days"], sv: ["dag", "dagar"] },
|
|
11
|
+
week: { en: ["week", "weeks"], sv: ["vecka", "veckor"] },
|
|
12
|
+
month: { en: ["month", "months"], sv: ["månad", "månader"] },
|
|
13
|
+
year: { en: ["year", "years"], sv: ["år", "år"] },
|
|
14
|
+
};
|
|
15
|
+
export function retentionIn(retention, language) {
|
|
16
|
+
const text = retention?.trim();
|
|
17
|
+
if (!text)
|
|
18
|
+
return undefined;
|
|
19
|
+
if (/^(end of )?session( \(browser\))?$/i.test(text))
|
|
20
|
+
return "Session";
|
|
21
|
+
const match = text.match(/^(\d+)\s*(second|minute|hour|day|week|month|year)s?$/i);
|
|
22
|
+
if (!match)
|
|
23
|
+
return language === "en" ? text : undefined;
|
|
24
|
+
const count = Number(match[1]);
|
|
25
|
+
const [one, many] = UNITS[match[2].toLowerCase()][language];
|
|
26
|
+
return `${count} ${count === 1 ? one : many}`;
|
|
27
|
+
}
|
package/dist/scans.js
CHANGED
|
@@ -4,8 +4,9 @@ import { CATEGORIES } from "./defaults.js";
|
|
|
4
4
|
import { evaluateScan, scanProblems, } from "./evaluate.js";
|
|
5
5
|
import { evidenceEndpoint } from "./evidence.js";
|
|
6
6
|
import { notifyScan } from "./notify.js";
|
|
7
|
+
import { retentionIn } from "./retention.js";
|
|
7
8
|
import { readConsent, toConsentConfig, } from "./site-config.js";
|
|
8
|
-
import { CONSENT_GLOBAL, CONSENT_SCAN_EVIDENCE, CONSENT_SCANS, CONSENT_SERVICES, MAX_SCAN_PAGES, POLICY_COOKIE, SCAN_TASK, } from "./types.js";
|
|
9
|
+
import { CONSENT_GLOBAL, CONSENT_SCAN_EVIDENCE, CONSENT_SCANS, CONSENT_SERVICES, MAX_SCAN_PAGES, POLICY_COOKIE, SCAN_STATE_PAGES, SCAN_TASK, } from "./types.js";
|
|
9
10
|
/**
|
|
10
11
|
* The states a scan runs: a new visitor, rejecting, accepting everything and, with more than one
|
|
11
12
|
* optional category, each category on its own. Each state presets c15t's cookie as c15t 2.2.1
|
|
@@ -162,6 +163,8 @@ export async function startScan({ payload, options, url: given, trigger = "manua
|
|
|
162
163
|
callbackUrl: `${base}/result`,
|
|
163
164
|
...(scanner.keepEvidence === 0 ? {} : { evidenceUrl: `${base}/evidence` }),
|
|
164
165
|
...(pages ? { pages } : {}),
|
|
166
|
+
maxPerSitemap: MAX_SCAN_PAGES,
|
|
167
|
+
statePages: SCAN_STATE_PAGES,
|
|
165
168
|
states: states.map(({ id, cookies }) => ({ id, cookies })),
|
|
166
169
|
}),
|
|
167
170
|
signal: AbortSignal.timeout(20_000),
|
|
@@ -407,13 +410,16 @@ function endpoints(options) {
|
|
|
407
410
|
!serviceName ||
|
|
408
411
|
(kind !== "cookie" && kind !== "localStorage" && kind !== "host"))
|
|
409
412
|
return Response.json({ error: "Name the finding and the service" }, { status: 400 });
|
|
410
|
-
// The
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
localization.localeCodes
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
413
|
+
// The suggestion's texts are the Open Cookie Database's English, so they go in English when
|
|
414
|
+
// the site has it, else in the editor's language of the site, else in the default one.
|
|
415
|
+
const localeCodes = req.payload.config.localization
|
|
416
|
+
? req.payload.config.localization.localeCodes
|
|
417
|
+
: [];
|
|
418
|
+
const locale = localeCodes.includes("en")
|
|
419
|
+
? "en"
|
|
420
|
+
: localeCodes.includes(String(body?.locale)) && typeof body?.locale === "string"
|
|
421
|
+
? body.locale
|
|
422
|
+
: undefined;
|
|
417
423
|
const category = CATEGORIES.includes(body?.category)
|
|
418
424
|
? body?.category
|
|
419
425
|
: "necessary";
|
|
@@ -432,7 +438,13 @@ function endpoints(options) {
|
|
|
432
438
|
: {
|
|
433
439
|
storage: [
|
|
434
440
|
...(existing?.storage ?? []),
|
|
435
|
-
{
|
|
441
|
+
{
|
|
442
|
+
name,
|
|
443
|
+
type: kind,
|
|
444
|
+
duration: retentionIn(body?.duration, "en"),
|
|
445
|
+
description: body?.description?.trim() || undefined,
|
|
446
|
+
thirdParty: body?.firstParty === false,
|
|
447
|
+
},
|
|
436
448
|
],
|
|
437
449
|
};
|
|
438
450
|
const service = existing
|
|
@@ -457,6 +469,29 @@ function endpoints(options) {
|
|
|
457
469
|
locale: locale,
|
|
458
470
|
...asEditor,
|
|
459
471
|
});
|
|
472
|
+
// The duration in Swedish too, on the row just added; its description falls back to English.
|
|
473
|
+
const swedish = retentionIn(body?.duration, "sv");
|
|
474
|
+
if (kind !== "host" && swedish && locale === "en" && localeCodes.includes("sv")) {
|
|
475
|
+
const inSwedish = (await req.payload.findByID({
|
|
476
|
+
collection: CONSENT_SERVICES,
|
|
477
|
+
id: service.id,
|
|
478
|
+
depth: 0,
|
|
479
|
+
locale: "sv",
|
|
480
|
+
...asEditor,
|
|
481
|
+
}));
|
|
482
|
+
const rows = inSwedish.storage ?? [];
|
|
483
|
+
// The last row of that name: the one just added, should the service list it twice.
|
|
484
|
+
const added = rows.reduce((last, row, index) => (row.name === name && row.type === kind ? index : last), -1);
|
|
485
|
+
await req.payload.update({
|
|
486
|
+
collection: CONSENT_SERVICES,
|
|
487
|
+
id: service.id,
|
|
488
|
+
data: {
|
|
489
|
+
storage: rows.map((row, index) => index === added ? { ...row, duration: swedish } : row),
|
|
490
|
+
},
|
|
491
|
+
locale: "sv",
|
|
492
|
+
...asEditor,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
460
495
|
const latest = await latestDone(req);
|
|
461
496
|
if (latest) {
|
|
462
497
|
const previous = await latestDone(req, latest.id);
|
package/dist/services.js
CHANGED
|
@@ -187,6 +187,7 @@ export function servicesCollection(options) {
|
|
|
187
187
|
},
|
|
188
188
|
admin: {
|
|
189
189
|
initCollapsed: true,
|
|
190
|
+
components: { RowLabel: "@simmalugnt-se/payload-consent/admin#StorageRowLabel" },
|
|
190
191
|
description: {
|
|
191
192
|
en: "What the service stores in the browser. A service that stores nothing, such as an embedded font, has none.",
|
|
192
193
|
sv: "Det tjänsten sparar i webbläsaren. En tjänst som inte sparar något, till exempel ett inbäddat typsnitt, har inga.",
|
|
@@ -247,7 +248,10 @@ export function servicesCollection(options) {
|
|
|
247
248
|
singular: { en: "Host", sv: "Värd" },
|
|
248
249
|
plural: { en: "Hosts", sv: "Värdar" },
|
|
249
250
|
},
|
|
250
|
-
admin: {
|
|
251
|
+
admin: {
|
|
252
|
+
initCollapsed: true,
|
|
253
|
+
components: { RowLabel: "@simmalugnt-se/payload-consent/admin#HostRowLabel" },
|
|
254
|
+
},
|
|
251
255
|
fields: [
|
|
252
256
|
{
|
|
253
257
|
name: "host",
|
package/dist/types.d.ts
CHANGED
|
@@ -88,5 +88,7 @@ export declare const POLICY_COOKIE = "c15t-policy";
|
|
|
88
88
|
/** Three years, unless the host sets `records.retentionDays`. */
|
|
89
89
|
export declare const DEFAULT_RETENTION_DAYS: number;
|
|
90
90
|
export declare const DEFAULT_KEEP_EVIDENCE = 12;
|
|
91
|
-
/** The most pages a scan sends, in all its lists; the scanner
|
|
91
|
+
/** The most pages a scan sends and visits as a new visitor, in all its lists; the scanner's limit. */
|
|
92
92
|
export declare const MAX_SCAN_PAGES = 500;
|
|
93
|
+
/** The pages visited in each other consent state: the start page and a spread from every list. */
|
|
94
|
+
export declare const SCAN_STATE_PAGES = 30;
|
package/dist/types.js
CHANGED
|
@@ -15,5 +15,7 @@ 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, in all its lists; the scanner
|
|
18
|
+
/** The most pages a scan sends and visits as a new visitor, in all its lists; the scanner's limit. */
|
|
19
19
|
export const MAX_SCAN_PAGES = 500;
|
|
20
|
+
/** The pages visited in each other consent state: the start page and a spread from every list. */
|
|
21
|
+
export const SCAN_STATE_PAGES = 30;
|