@simmalugnt-se/payload-consent 0.6.7 → 0.6.8
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 +14 -0
- 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 +41 -8
- package/dist/services.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.8
|
|
4
|
+
|
|
5
|
+
- Add to service on a scan's finding gives the row the cookie's description from the Open Cookie
|
|
6
|
+
Database. Before, the description only became a new service's purpose, so a cookie added to an
|
|
7
|
+
existing service had none.
|
|
8
|
+
- The finding's texts go in English, the database's language, when the site has English, with the
|
|
9
|
+
duration in Swedish too ("1 år", "13 månader", "Session"); the Swedish description falls back
|
|
10
|
+
to English until someone writes it. Before, they went in Admin's language, so a Swedish Admin
|
|
11
|
+
stored "1 year" as the Swedish duration and left the English empty.
|
|
12
|
+
- A cookie the scan saw on another site's domain is added as third party.
|
|
13
|
+
- A Cookie service's collapsed rows say what they are: "_ga · Cookie · 2 år" for a cookie or key,
|
|
14
|
+
the host for a host, in place of "Cookie or key 01". A project regenerates its import map for
|
|
15
|
+
the two new row label components.
|
|
16
|
+
|
|
3
17
|
## 0.6.7
|
|
4
18
|
|
|
5
19
|
- The help under Site address and Scan every month stays out of the site's generated types. It
|
|
@@ -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,6 +4,7 @@ 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
9
|
import { CONSENT_GLOBAL, CONSENT_SCAN_EVIDENCE, CONSENT_SCANS, CONSENT_SERVICES, MAX_SCAN_PAGES, POLICY_COOKIE, SCAN_TASK, } from "./types.js";
|
|
9
10
|
/**
|
|
@@ -407,13 +408,16 @@ function endpoints(options) {
|
|
|
407
408
|
!serviceName ||
|
|
408
409
|
(kind !== "cookie" && kind !== "localStorage" && kind !== "host"))
|
|
409
410
|
return Response.json({ error: "Name the finding and the service" }, { status: 400 });
|
|
410
|
-
// The
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
localization.localeCodes
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
411
|
+
// The suggestion's texts are the Open Cookie Database's English, so they go in English when
|
|
412
|
+
// the site has it, else in the editor's language of the site, else in the default one.
|
|
413
|
+
const localeCodes = req.payload.config.localization
|
|
414
|
+
? req.payload.config.localization.localeCodes
|
|
415
|
+
: [];
|
|
416
|
+
const locale = localeCodes.includes("en")
|
|
417
|
+
? "en"
|
|
418
|
+
: localeCodes.includes(String(body?.locale)) && typeof body?.locale === "string"
|
|
419
|
+
? body.locale
|
|
420
|
+
: undefined;
|
|
417
421
|
const category = CATEGORIES.includes(body?.category)
|
|
418
422
|
? body?.category
|
|
419
423
|
: "necessary";
|
|
@@ -432,7 +436,13 @@ function endpoints(options) {
|
|
|
432
436
|
: {
|
|
433
437
|
storage: [
|
|
434
438
|
...(existing?.storage ?? []),
|
|
435
|
-
{
|
|
439
|
+
{
|
|
440
|
+
name,
|
|
441
|
+
type: kind,
|
|
442
|
+
duration: retentionIn(body?.duration, "en"),
|
|
443
|
+
description: body?.description?.trim() || undefined,
|
|
444
|
+
thirdParty: body?.firstParty === false,
|
|
445
|
+
},
|
|
436
446
|
],
|
|
437
447
|
};
|
|
438
448
|
const service = existing
|
|
@@ -457,6 +467,29 @@ function endpoints(options) {
|
|
|
457
467
|
locale: locale,
|
|
458
468
|
...asEditor,
|
|
459
469
|
});
|
|
470
|
+
// The duration in Swedish too, on the row just added; its description falls back to English.
|
|
471
|
+
const swedish = retentionIn(body?.duration, "sv");
|
|
472
|
+
if (kind !== "host" && swedish && locale === "en" && localeCodes.includes("sv")) {
|
|
473
|
+
const inSwedish = (await req.payload.findByID({
|
|
474
|
+
collection: CONSENT_SERVICES,
|
|
475
|
+
id: service.id,
|
|
476
|
+
depth: 0,
|
|
477
|
+
locale: "sv",
|
|
478
|
+
...asEditor,
|
|
479
|
+
}));
|
|
480
|
+
const rows = inSwedish.storage ?? [];
|
|
481
|
+
// The last row of that name: the one just added, should the service list it twice.
|
|
482
|
+
const added = rows.reduce((last, row, index) => (row.name === name && row.type === kind ? index : last), -1);
|
|
483
|
+
await req.payload.update({
|
|
484
|
+
collection: CONSENT_SERVICES,
|
|
485
|
+
id: service.id,
|
|
486
|
+
data: {
|
|
487
|
+
storage: rows.map((row, index) => index === added ? { ...row, duration: swedish } : row),
|
|
488
|
+
},
|
|
489
|
+
locale: "sv",
|
|
490
|
+
...asEditor,
|
|
491
|
+
});
|
|
492
|
+
}
|
|
460
493
|
const latest = await latestDone(req);
|
|
461
494
|
if (latest) {
|
|
462
495
|
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",
|