@simmalugnt-se/payload-consent 0.1.0 → 0.2.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 +14 -0
- package/README.md +11 -3
- package/dist/admin/ServicesPanel.d.ts +11 -0
- package/dist/admin/ServicesPanel.js +136 -0
- package/dist/evidence.js +2 -1
- package/dist/exports/admin.d.ts +1 -0
- package/dist/exports/admin.js +1 -0
- package/dist/exports/client.js +107 -19
- package/dist/global.js +45 -0
- package/dist/records.js +4 -3
- package/dist/scans.js +2 -1
- package/dist/services.js +2 -1
- package/dist/site-config.d.ts +6 -0
- package/dist/site-config.js +14 -0
- package/dist/styles/admin.css +58 -0
- package/dist/styles/consent.css +5 -0
- package/dist/withdrawal.d.ts +19 -0
- package/dist/withdrawal.js +24 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- Withdrawing a category removes the cookies and localStorage keys its Cookie services list on the
|
|
6
|
+
site, such as `_ga` and `_ga_*`, before and once more after c15t reloads the page. Third-party
|
|
7
|
+
storage cannot be reached from the site and stays.
|
|
8
|
+
- A choice is posted to the consent log once per page load: a withdrawal no longer posts it twice.
|
|
9
|
+
|
|
10
|
+
## 0.2.0
|
|
11
|
+
|
|
12
|
+
- Cookies is the one entry in Admin: a Services tab lists the Cookie services with links to edit
|
|
13
|
+
and add them, a Consent log tab links to the records and policy versions, and the Scan tab links
|
|
14
|
+
to every scan. The plugin's collections no longer appear in the navigation or on the dashboard.
|
|
15
|
+
- The settings dialog no longer shows "Reject optional" when the site has only necessary storage.
|
|
16
|
+
|
|
3
17
|
## 0.1.0
|
|
4
18
|
|
|
5
19
|
- A Cookies global with the banner's texts, localized and prefilled with Swedish and English
|
package/README.md
CHANGED
|
@@ -24,13 +24,17 @@ export default buildConfig({
|
|
|
24
24
|
})
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
The plugin adds a `consent` global (Cookies)
|
|
28
|
-
services), `consent-records` and `consent-policies` (the consent log), `consent-scans` and
|
|
29
|
-
`consent-scan-evidence`,
|
|
27
|
+
The plugin adds a `consent` global (Cookies, under Settings), the collections `consent-services`
|
|
28
|
+
(Cookie services), `consent-records` and `consent-policies` (the consent log), `consent-scans` and
|
|
29
|
+
`consent-scan-evidence`, a jobs task (`consentScan`) and a dashboard widget. Cookies is the one
|
|
30
|
+
entry in the navigation and on the dashboard: its tabs list the services and link to the log and
|
|
31
|
+
the scans, whose collections stay out of the navigation (`admin.group: false`). Generate types, then create and apply a migration with the
|
|
30
32
|
project's usual commands.
|
|
31
33
|
|
|
32
34
|
## The Cookies global
|
|
33
35
|
|
|
36
|
+
Five tabs: Banner, Services, Scan, Consent log and Settings.
|
|
37
|
+
|
|
34
38
|
- **Banner**: title, description, buttons, the settings dialog and a title and description per
|
|
35
39
|
category. Every text is localized and prefilled with a suggestion in the language being edited
|
|
36
40
|
(Swedish or English; other languages get English). The description and the accept button have
|
|
@@ -70,6 +74,10 @@ policy version and language also saves what the visitor was shown in `consent-po
|
|
|
70
74
|
categories, services and texts. Records are kept for three years (`records.retentionDays`) and
|
|
71
75
|
readable by signed-in users only; `records: false` turns the log off.
|
|
72
76
|
|
|
77
|
+
When a visitor withdraws a category, c15t reloads the page and the plugin removes the cookies
|
|
78
|
+
and localStorage keys the category's services list as their own (not third-party), so list the
|
|
79
|
+
names a service stores, with `*` for a family such as `_ga_*`.
|
|
80
|
+
|
|
73
81
|
The policy version is a hash of the categories and each service's cookies and storage keys. When
|
|
74
82
|
it changes, for example because a service gains a cookie, visitors are asked again. Rewording a
|
|
75
83
|
text does not change it.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "../styles/admin.css";
|
|
2
|
+
/**
|
|
3
|
+
* The Services tab: the Cookie services as a short table with links into the collection, so the
|
|
4
|
+
* Cookies page is the one place editors start from. A table of our own: Payload's list view is a
|
|
5
|
+
* whole route, not something a field can hold.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ServicesPanel(): import("react").JSX.Element;
|
|
8
|
+
/** The Consent log tab: how many choices are on record, with links to the records and policies. */
|
|
9
|
+
export declare function ConsentLogPanel(): import("react").JSX.Element;
|
|
10
|
+
/** Links under the Scan tab to every scan, since the collection is not in the navigation. */
|
|
11
|
+
export declare function ScanLinks(): import("react").JSX.Element;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button, Pill, useConfig, useLocale, useTranslation } from "@payloadcms/ui";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { INTEGRATIONS } from "../integrations.js";
|
|
6
|
+
import { CONSENT_POLICIES, CONSENT_RECORDS, CONSENT_SCANS, CONSENT_SERVICES } from "../types.js";
|
|
7
|
+
import "../styles/admin.css";
|
|
8
|
+
const COPY = {
|
|
9
|
+
en: {
|
|
10
|
+
loading: "Loading…",
|
|
11
|
+
none: "No services yet. Add the ones the site uses, or let a scan suggest them.",
|
|
12
|
+
add: "Add service",
|
|
13
|
+
all: "Open the list",
|
|
14
|
+
columns: { name: "Service", category: "Category", loading: "Loaded by", storage: "Storage" },
|
|
15
|
+
code: "The site's code",
|
|
16
|
+
storage: (cookies, hosts) => [
|
|
17
|
+
cookies && `${cookies} cookie${cookies === 1 ? "" : "s"} or keys`,
|
|
18
|
+
hosts && `${hosts} host${hosts === 1 ? "" : "s"}`,
|
|
19
|
+
]
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
.join(", ") || "Nothing listed",
|
|
22
|
+
records: (n) => `${n} saved choice${n === 1 ? "" : "s"}`,
|
|
23
|
+
policies: (n) => `${n} policy version${n === 1 ? "" : "s"} shown to visitors`,
|
|
24
|
+
openRecords: "Consent records",
|
|
25
|
+
openPolicies: "Policy versions",
|
|
26
|
+
scans: "All scans",
|
|
27
|
+
categories: {
|
|
28
|
+
necessary: "Necessary",
|
|
29
|
+
functionality: "Functionality",
|
|
30
|
+
experience: "Experience",
|
|
31
|
+
measurement: "Statistics",
|
|
32
|
+
marketing: "Marketing",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
sv: {
|
|
36
|
+
loading: "Hämtar…",
|
|
37
|
+
none: "Inga tjänster än. Lägg till dem webbplatsen använder, eller låt en skanning föreslå dem.",
|
|
38
|
+
add: "Lägg till tjänst",
|
|
39
|
+
all: "Öppna listan",
|
|
40
|
+
columns: { name: "Tjänst", category: "Kategori", loading: "Laddas av", storage: "Lagring" },
|
|
41
|
+
code: "Webbplatsens kod",
|
|
42
|
+
storage: (cookies, hosts) => [
|
|
43
|
+
cookies && `${cookies} cookies eller nycklar`,
|
|
44
|
+
hosts && `${hosts} värd${hosts === 1 ? "" : "ar"}`,
|
|
45
|
+
]
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.join(", ") || "Inget angivet",
|
|
48
|
+
records: (n) => `${n} sparade val`,
|
|
49
|
+
policies: (n) => `${n} policyversion${n === 1 ? "" : "er"} som visats för besökare`,
|
|
50
|
+
openRecords: "Samtyckesloggen",
|
|
51
|
+
openPolicies: "Policyversioner",
|
|
52
|
+
scans: "Alla skanningar",
|
|
53
|
+
categories: {
|
|
54
|
+
necessary: "Nödvändiga",
|
|
55
|
+
functionality: "Funktion",
|
|
56
|
+
experience: "Upplevelse",
|
|
57
|
+
measurement: "Statistik",
|
|
58
|
+
marketing: "Marknadsföring",
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
function useCopy() {
|
|
63
|
+
const { i18n } = useTranslation();
|
|
64
|
+
const language = i18n.language === "sv" ? "sv" : "en";
|
|
65
|
+
return COPY[language];
|
|
66
|
+
}
|
|
67
|
+
function useRoutes() {
|
|
68
|
+
const { config } = useConfig();
|
|
69
|
+
return {
|
|
70
|
+
api: `${config.serverURL ?? ""}${config.routes.api}`,
|
|
71
|
+
admin: `${config.routes.admin}/collections`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The Services tab: the Cookie services as a short table with links into the collection, so the
|
|
76
|
+
* Cookies page is the one place editors start from. A table of our own: Payload's list view is a
|
|
77
|
+
* whole route, not something a field can hold.
|
|
78
|
+
*/
|
|
79
|
+
export function ServicesPanel() {
|
|
80
|
+
const copy = useCopy();
|
|
81
|
+
const { api, admin } = useRoutes();
|
|
82
|
+
const locale = useLocale();
|
|
83
|
+
const [services, setServices] = useState();
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
let stopped = false;
|
|
86
|
+
fetch(`${api}/${CONSENT_SERVICES}?limit=0&depth=0&sort=name&locale=${encodeURIComponent(locale.code)}`, { credentials: "include" })
|
|
87
|
+
.then((response) => response.json())
|
|
88
|
+
.then((body) => {
|
|
89
|
+
if (!stopped)
|
|
90
|
+
setServices(body.docs ?? []);
|
|
91
|
+
})
|
|
92
|
+
.catch(() => {
|
|
93
|
+
if (!stopped)
|
|
94
|
+
setServices([]);
|
|
95
|
+
});
|
|
96
|
+
return () => {
|
|
97
|
+
stopped = true;
|
|
98
|
+
};
|
|
99
|
+
}, [api, locale.code]);
|
|
100
|
+
const integrationLabel = (key) => INTEGRATIONS.find((integration) => integration.key === key)?.label ?? key ?? "";
|
|
101
|
+
return (_jsxs("div", { className: "consent-panel", children: [_jsxs("div", { className: "consent-scan__bar", children: [_jsx(Button, { buttonStyle: "primary", el: "link", margin: false, size: "medium", url: `${admin}/${CONSENT_SERVICES}/create`, children: copy.add }), _jsx("a", { className: "consent-panel__link", href: `${admin}/${CONSENT_SERVICES}`, children: copy.all })] }), services === undefined ? (_jsx("p", { className: "consent-scan__note", children: copy.loading })) : services.length === 0 ? (_jsx("p", { className: "consent-scan__note", children: copy.none })) : (_jsxs("table", { className: "consent-panel__table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: copy.columns.name }), _jsx("th", { children: copy.columns.category }), _jsx("th", { children: copy.columns.loading }), _jsx("th", { children: copy.columns.storage })] }) }), _jsx("tbody", { children: services.map((service) => (_jsxs("tr", { children: [_jsx("td", { children: _jsx("a", { href: `${admin}/${CONSENT_SERVICES}/${service.id}`, children: service.name || String(service.id) }) }), _jsx("td", { children: service.category ? (_jsx(Pill, { pillStyle: service.category === "necessary" ? "light-gray" : "light", children: copy.categories[service.category] })) : null }), _jsx("td", { children: service.loading === "integration"
|
|
102
|
+
? integrationLabel(service.integration)
|
|
103
|
+
: copy.code }), _jsx("td", { children: copy.storage(service.storage?.length ?? 0, service.hosts?.length ?? 0) })] }, service.id))) })] }))] }));
|
|
104
|
+
}
|
|
105
|
+
function useCount(slug) {
|
|
106
|
+
const { api } = useRoutes();
|
|
107
|
+
const [count, setCount] = useState();
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
let stopped = false;
|
|
110
|
+
fetch(`${api}/${slug}?limit=1&depth=0`, { credentials: "include" })
|
|
111
|
+
.then((response) => response.json())
|
|
112
|
+
.then((body) => {
|
|
113
|
+
if (!stopped)
|
|
114
|
+
setCount(body.totalDocs ?? 0);
|
|
115
|
+
})
|
|
116
|
+
.catch(() => undefined);
|
|
117
|
+
return () => {
|
|
118
|
+
stopped = true;
|
|
119
|
+
};
|
|
120
|
+
}, [api, slug]);
|
|
121
|
+
return count;
|
|
122
|
+
}
|
|
123
|
+
/** The Consent log tab: how many choices are on record, with links to the records and policies. */
|
|
124
|
+
export function ConsentLogPanel() {
|
|
125
|
+
const copy = useCopy();
|
|
126
|
+
const { admin } = useRoutes();
|
|
127
|
+
const records = useCount(CONSENT_RECORDS);
|
|
128
|
+
const policies = useCount(CONSENT_POLICIES);
|
|
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
|
+
}
|
|
131
|
+
/** Links under the Scan tab to every scan, since the collection is not in the navigation. */
|
|
132
|
+
export function ScanLinks() {
|
|
133
|
+
const copy = useCopy();
|
|
134
|
+
const { admin } = useRoutes();
|
|
135
|
+
return (_jsx("p", { className: "consent-panel__more", children: _jsx("a", { href: `${admin}/${CONSENT_SCANS}`, children: copy.scans }) }));
|
|
136
|
+
}
|
package/dist/evidence.js
CHANGED
|
@@ -16,7 +16,8 @@ export function evidenceCollection(options) {
|
|
|
16
16
|
},
|
|
17
17
|
admin: {
|
|
18
18
|
useAsTitle: "filename",
|
|
19
|
-
|
|
19
|
+
// Out of the navigation and dashboard: the Cookies global links here.
|
|
20
|
+
group: false,
|
|
20
21
|
defaultColumns: ["filename", "scan", "state", "kind", "createdAt"],
|
|
21
22
|
},
|
|
22
23
|
access: { read: signedIn, create: () => false, update: () => false, delete: signedIn },
|
package/dist/exports/admin.d.ts
CHANGED
package/dist/exports/admin.js
CHANGED
package/dist/exports/client.js
CHANGED
|
@@ -11,6 +11,7 @@ import { microsoftUet } from "@c15t/scripts/microsoft-uet";
|
|
|
11
11
|
import { tiktokPixel } from "@c15t/scripts/tiktok-pixel";
|
|
12
12
|
import { createContext, useContext, useEffect, useRef, } from "react";
|
|
13
13
|
import { POLICY_COOKIE } from "../types.js";
|
|
14
|
+
import { cookieDomains, matchesStorageName, subjectIdFromCookie, withdrawnStorage, } from "../withdrawal.js";
|
|
14
15
|
/** A button that opens the settings dialog, for the site's footer. Render it inside `ConsentProvider`. */
|
|
15
16
|
export { ConsentDialogLink as ConsentSettingsLink } from "@c15t/react";
|
|
16
17
|
/** Class names for c15t's unstyled parts, styled by `styles.css`. */
|
|
@@ -66,6 +67,7 @@ export function ConsentProvider({ config, scripts, children }) {
|
|
|
66
67
|
if (!config.enabled)
|
|
67
68
|
return _jsx(_Fragment, { children: children });
|
|
68
69
|
forgetOutdatedConsent(config.policyVersion);
|
|
70
|
+
clearAfterWithdrawal(config);
|
|
69
71
|
const options = {
|
|
70
72
|
mode: "offline",
|
|
71
73
|
overrides: { country: "SE" },
|
|
@@ -80,11 +82,52 @@ export function ConsentProvider({ config, scripts, children }) {
|
|
|
80
82
|
detectBrowserLanguage: false,
|
|
81
83
|
messages: { [config.locale]: config.messages },
|
|
82
84
|
},
|
|
85
|
+
callbacks: {
|
|
86
|
+
// c15t reloads the page when a category is withdrawn. ConsentRecorder usually records the
|
|
87
|
+
// choice first, but nothing waits for it: record here too (once, see recordChoice) and
|
|
88
|
+
// clear the withdrawn services' storage.
|
|
89
|
+
onBeforeConsentRevocationReload: ({ preferences }) => {
|
|
90
|
+
const consents = preferences;
|
|
91
|
+
writePolicy(config.policyVersion);
|
|
92
|
+
recordChoice(config, subjectIdFromCookie(document.cookie), consents);
|
|
93
|
+
clearWithdrawnStorage(config, consents);
|
|
94
|
+
// A tag still running while the page unloads can write its cookie again: clear once more
|
|
95
|
+
// after the reload (see clearAfterWithdrawal).
|
|
96
|
+
try {
|
|
97
|
+
window.sessionStorage.setItem(WITHDRAWN_KEY, JSON.stringify(consents));
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Without session storage the cleanup above is all there is.
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
},
|
|
83
104
|
};
|
|
84
105
|
// With only necessary storage there is nothing to reject: Settings and the Okay button remain.
|
|
85
106
|
const necessaryOnly = config.categories.length === 1;
|
|
86
107
|
return (_jsx(ConfigContext.Provider, { value: config, children: _jsxs(ConsentManagerProvider, { options: options, children: [children, _jsx(ConsentBanner, { hideBranding: true, layout: necessaryOnly ? [["customize", "accept"]] : undefined }), _jsx(SettingsDialog, {}), _jsx(ConsentRecorder, { config: config })] }) }));
|
|
87
108
|
}
|
|
109
|
+
/** Set by a withdrawal just before c15t reloads the page; read once by the next page load. */
|
|
110
|
+
const WITHDRAWN_KEY = "c15t-withdrawn";
|
|
111
|
+
let checkedWithdrawal = false;
|
|
112
|
+
/**
|
|
113
|
+
* Clears what the withdrawn categories' services stored once more, on the page load that follows a
|
|
114
|
+
* withdrawal. Only then: a fresh visitor, or a scanner, never has the marker.
|
|
115
|
+
*/
|
|
116
|
+
function clearAfterWithdrawal(config) {
|
|
117
|
+
if (typeof window === "undefined" || checkedWithdrawal)
|
|
118
|
+
return;
|
|
119
|
+
checkedWithdrawal = true;
|
|
120
|
+
try {
|
|
121
|
+
const saved = window.sessionStorage.getItem(WITHDRAWN_KEY);
|
|
122
|
+
if (!saved)
|
|
123
|
+
return;
|
|
124
|
+
window.sessionStorage.removeItem(WITHDRAWN_KEY);
|
|
125
|
+
clearWithdrawnStorage(config, JSON.parse(saved));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// Without session storage there is no marker to act on.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
88
131
|
function readPolicy() {
|
|
89
132
|
const match = document.cookie.match(new RegExp(`(?:^|; )${POLICY_COOKIE}=([^;]*)`));
|
|
90
133
|
return match ? decodeURIComponent(match[1] ?? "") : null;
|
|
@@ -113,7 +156,65 @@ function writePolicy(version) {
|
|
|
113
156
|
const secure = window.location.protocol === "https:" ? "; Secure" : "";
|
|
114
157
|
document.cookie = `${POLICY_COOKIE}=${encodeURIComponent(version)}; Path=/; Max-Age=${365 * 24 * 60 * 60}; SameSite=Lax${secure}`;
|
|
115
158
|
}
|
|
116
|
-
/**
|
|
159
|
+
/** The last choice posted from this page: a withdrawal reaches both the callback and the effect. */
|
|
160
|
+
let lastRecorded;
|
|
161
|
+
/** Posts a saved choice to the site's consent records, with its policy version, once. */
|
|
162
|
+
function recordChoice(config, subjectId, consents) {
|
|
163
|
+
if (!config.recordUrl || !subjectId)
|
|
164
|
+
return;
|
|
165
|
+
const choices = Object.fromEntries(config.categories.map((category) => [category, Boolean(consents[category])]));
|
|
166
|
+
const key = JSON.stringify([subjectId, choices]);
|
|
167
|
+
if (key === lastRecorded)
|
|
168
|
+
return;
|
|
169
|
+
lastRecorded = key;
|
|
170
|
+
// keepalive: a withdrawal posts this just before the page reloads.
|
|
171
|
+
fetch(config.recordUrl, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: { "Content-Type": "application/json" },
|
|
174
|
+
keepalive: true,
|
|
175
|
+
body: JSON.stringify({
|
|
176
|
+
subjectId,
|
|
177
|
+
choices,
|
|
178
|
+
policyVersion: config.policyVersion,
|
|
179
|
+
locale: config.locale,
|
|
180
|
+
path: window.location.pathname,
|
|
181
|
+
}),
|
|
182
|
+
}).catch(() => {
|
|
183
|
+
// The choice still applies in the browser; only the record is missing.
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Removes the cookies and localStorage keys the Cookie services list for the categories the
|
|
188
|
+
* visitor withdrew, such as `_ga` and `_ga_*`. Only on a withdrawal, never on an ordinary page
|
|
189
|
+
* load: a scan must still see a service that stores something it should not.
|
|
190
|
+
*/
|
|
191
|
+
function clearWithdrawnStorage(config, consents) {
|
|
192
|
+
const items = withdrawnStorage(config.storage ?? [], consents);
|
|
193
|
+
if (!items.length)
|
|
194
|
+
return;
|
|
195
|
+
const cookieNames = document.cookie
|
|
196
|
+
.split("; ")
|
|
197
|
+
.map((pair) => pair.slice(0, pair.indexOf("=")))
|
|
198
|
+
.filter(Boolean);
|
|
199
|
+
for (const item of items) {
|
|
200
|
+
if (item.type === "cookie") {
|
|
201
|
+
for (const name of cookieNames.filter((cookie) => matchesStorageName(item.name, cookie)))
|
|
202
|
+
for (const domain of cookieDomains(window.location.hostname))
|
|
203
|
+
document.cookie = `${name}=; Path=/; Max-Age=0${domain ? `; Domain=${domain}` : ""}`;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
try {
|
|
207
|
+
for (const key of Object.keys(window.localStorage))
|
|
208
|
+
if (matchesStorageName(item.name, key))
|
|
209
|
+
window.localStorage.removeItem(key);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// Without storage access there is nothing stored to remove.
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** Posts each choice saved on this page to the site's consent records. */
|
|
117
218
|
function ConsentRecorder({ config }) {
|
|
118
219
|
const { consentInfo, consents } = useConsentManager();
|
|
119
220
|
const mountedAt = useRef(Date.now());
|
|
@@ -123,23 +224,7 @@ function ConsentRecorder({ config }) {
|
|
|
123
224
|
if (!savedAt || savedAt < mountedAt.current)
|
|
124
225
|
return;
|
|
125
226
|
writePolicy(config.policyVersion);
|
|
126
|
-
|
|
127
|
-
return;
|
|
128
|
-
const choices = Object.fromEntries(config.categories.map((category) => [category, Boolean(consents[category])]));
|
|
129
|
-
fetch(config.recordUrl, {
|
|
130
|
-
method: "POST",
|
|
131
|
-
headers: { "Content-Type": "application/json" },
|
|
132
|
-
keepalive: true,
|
|
133
|
-
body: JSON.stringify({
|
|
134
|
-
subjectId: consentInfo.subjectId,
|
|
135
|
-
choices,
|
|
136
|
-
policyVersion: config.policyVersion,
|
|
137
|
-
locale: config.locale,
|
|
138
|
-
path: window.location.pathname,
|
|
139
|
-
}),
|
|
140
|
-
}).catch(() => {
|
|
141
|
-
// The choice still applies in the browser; only the record is missing.
|
|
142
|
-
});
|
|
227
|
+
recordChoice(config, consentInfo?.subjectId, consents);
|
|
143
228
|
}, [savedAt]);
|
|
144
229
|
return null;
|
|
145
230
|
}
|
|
@@ -153,7 +238,10 @@ function SettingsDialog() {
|
|
|
153
238
|
setSelectedConsent(name, consents[name] ?? false);
|
|
154
239
|
setActiveUI(hasConsented() ? "none" : "banner");
|
|
155
240
|
}
|
|
156
|
-
|
|
241
|
+
// With only necessary storage there is nothing to reject; c15t's dialog has no option to drop
|
|
242
|
+
// the button, so a class hides it (see consent.css).
|
|
243
|
+
const necessaryOnly = useContext(ConfigContext)?.categories.length === 1;
|
|
244
|
+
return (_jsx(C15tDialog.Root, { className: necessaryOnly ? "sc-dialog--necessary-only" : undefined, onClick: dismiss, children: _jsx(C15tDialog.ConsentCustomizationCard, { hideBranding: true }) }));
|
|
157
245
|
}
|
|
158
246
|
/**
|
|
159
247
|
* Embedded content, such as a video or a map, that is not mounted until the visitor allows its
|
package/dist/global.js
CHANGED
|
@@ -145,6 +145,22 @@ export function consentGlobal(options, { usersSlug, schedule }) {
|
|
|
145
145
|
},
|
|
146
146
|
],
|
|
147
147
|
},
|
|
148
|
+
{
|
|
149
|
+
label: { en: "Services", sv: "Tjänster" },
|
|
150
|
+
description: {
|
|
151
|
+
en: "Every service that stores something in the visitor's browser or that the site contacts. The banner's categories and the cookie table follow this list.",
|
|
152
|
+
sv: "Varje tjänst som sparar något i besökarens webbläsare eller som webbplatsen kontaktar. Bannerns kategorier och cookietabellen följer listan.",
|
|
153
|
+
},
|
|
154
|
+
fields: [
|
|
155
|
+
{
|
|
156
|
+
name: "servicesPanel",
|
|
157
|
+
type: "ui",
|
|
158
|
+
admin: {
|
|
159
|
+
components: { Field: "@simmalugnt-se/payload-consent/admin#ServicesPanel" },
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
},
|
|
148
164
|
{
|
|
149
165
|
label: { en: "Scan", sv: "Skanning" },
|
|
150
166
|
description: {
|
|
@@ -196,8 +212,37 @@ export function consentGlobal(options, { usersSlug, schedule }) {
|
|
|
196
212
|
components: { Field: "@simmalugnt-se/payload-consent/admin#ScanPanel" },
|
|
197
213
|
},
|
|
198
214
|
},
|
|
215
|
+
{
|
|
216
|
+
name: "scanLinks",
|
|
217
|
+
type: "ui",
|
|
218
|
+
admin: {
|
|
219
|
+
components: { Field: "@simmalugnt-se/payload-consent/admin#ScanLinks" },
|
|
220
|
+
},
|
|
221
|
+
},
|
|
199
222
|
],
|
|
200
223
|
},
|
|
224
|
+
...(options.records === false
|
|
225
|
+
? []
|
|
226
|
+
: [
|
|
227
|
+
{
|
|
228
|
+
label: { en: "Consent log", sv: "Samtyckeslogg" },
|
|
229
|
+
description: {
|
|
230
|
+
en: "Every choice a visitor saves, with the policy version they chose under and what it showed them. Nobody can change or delete a record.",
|
|
231
|
+
sv: "Varje val en besökare sparar, med policyversionen valet gjordes under och vad den visade. Ingen kan ändra eller ta bort en post.",
|
|
232
|
+
},
|
|
233
|
+
fields: [
|
|
234
|
+
{
|
|
235
|
+
name: "consentLog",
|
|
236
|
+
type: "ui",
|
|
237
|
+
admin: {
|
|
238
|
+
components: {
|
|
239
|
+
Field: "@simmalugnt-se/payload-consent/admin#ConsentLogPanel",
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
]),
|
|
201
246
|
{
|
|
202
247
|
label: { en: "Settings", sv: "Inställningar" },
|
|
203
248
|
fields: [
|
package/dist/records.js
CHANGED
|
@@ -115,7 +115,6 @@ function recordEndpoint(options) {
|
|
|
115
115
|
},
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
|
-
const group = (options) => options.group ?? { en: "Settings", sv: "Inställningar" };
|
|
119
118
|
export function recordsCollection(options) {
|
|
120
119
|
const retention = (options.records || undefined)?.retentionDays ?? DEFAULT_RETENTION_DAYS;
|
|
121
120
|
return {
|
|
@@ -126,7 +125,8 @@ export function recordsCollection(options) {
|
|
|
126
125
|
},
|
|
127
126
|
admin: {
|
|
128
127
|
useAsTitle: "subjectId",
|
|
129
|
-
|
|
128
|
+
// Out of the navigation and dashboard: the Cookies global links here.
|
|
129
|
+
group: false,
|
|
130
130
|
defaultColumns: ["subjectId", "granted", "policyVersion", "createdAt"],
|
|
131
131
|
description: {
|
|
132
132
|
en: `Every choice a visitor saved, with the policy it was given for. Identified only by the random ID in the visitor's c15t cookie; no IP address or browser details. Kept for ${retention} days.`,
|
|
@@ -173,7 +173,8 @@ export function policiesCollection(options) {
|
|
|
173
173
|
},
|
|
174
174
|
admin: {
|
|
175
175
|
useAsTitle: "version",
|
|
176
|
-
|
|
176
|
+
// Out of the navigation and dashboard: the Cookies global links here.
|
|
177
|
+
group: false,
|
|
177
178
|
defaultColumns: ["version", "locale", "createdAt"],
|
|
178
179
|
description: {
|
|
179
180
|
en: "What visitors were shown, per policy version and language: categories, services and texts. Saved with the first choice for each version.",
|
package/dist/scans.js
CHANGED
|
@@ -354,7 +354,8 @@ export function scansCollection(options) {
|
|
|
354
354
|
},
|
|
355
355
|
admin: {
|
|
356
356
|
useAsTitle: "url",
|
|
357
|
-
|
|
357
|
+
// Out of the navigation and dashboard: the Cookies global links here.
|
|
358
|
+
group: false,
|
|
358
359
|
defaultColumns: ["url", "status", "summary", "createdAt"],
|
|
359
360
|
description: {
|
|
360
361
|
en: "Each scan of the published site. Start one from Cookies → Scan.",
|
package/dist/services.js
CHANGED
|
@@ -51,7 +51,8 @@ export function servicesCollection(options) {
|
|
|
51
51
|
},
|
|
52
52
|
admin: {
|
|
53
53
|
useAsTitle: "name",
|
|
54
|
-
|
|
54
|
+
// Out of the navigation and dashboard: the Cookies global links here.
|
|
55
|
+
group: false,
|
|
55
56
|
defaultColumns: ["name", "provider", "category", "loading"],
|
|
56
57
|
description: {
|
|
57
58
|
en: "Every service that stores something in the visitor's browser or that the site contacts. The banner's categories and the cookie table follow this list.",
|
package/dist/site-config.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ConsentManagerOptions, Translations } from "@c15t/react";
|
|
|
2
2
|
import type { Payload } from "payload";
|
|
3
3
|
import { type Category, defaultTexts } from "./defaults.ts";
|
|
4
4
|
import { type IntegrationKey } from "./integrations.ts";
|
|
5
|
+
import type { StoredItem } from "./withdrawal.ts";
|
|
5
6
|
/** The Cookies global as read in one locale. Every text may be missing in an old document. */
|
|
6
7
|
export type ConsentDocument = {
|
|
7
8
|
enabled?: boolean | null;
|
|
@@ -73,6 +74,11 @@ export type ConsentConfig = {
|
|
|
73
74
|
policyVersion: string;
|
|
74
75
|
/** Where the site posts each saved choice; absent when records are off. */
|
|
75
76
|
recordUrl?: string;
|
|
77
|
+
/**
|
|
78
|
+
* The services' own cookies and localStorage keys by category, removed when the visitor withdraws
|
|
79
|
+
* the category. Third-party storage lives on other sites and cannot be removed from here.
|
|
80
|
+
*/
|
|
81
|
+
storage: StoredItem[];
|
|
76
82
|
};
|
|
77
83
|
type Options = {
|
|
78
84
|
locale: string;
|
package/dist/site-config.js
CHANGED
|
@@ -35,6 +35,19 @@ export function toConsentConfig(doc, services, options) {
|
|
|
35
35
|
isCategory(service.category)
|
|
36
36
|
? [{ key: service.integration, id: service.integrationId.trim(), category: service.category }]
|
|
37
37
|
: []);
|
|
38
|
+
const storage = services.flatMap((service) => isCategory(service.category) && service.category !== "necessary"
|
|
39
|
+
? (service.storage ?? []).flatMap((entry) => entry.name?.trim() &&
|
|
40
|
+
!entry.thirdParty &&
|
|
41
|
+
(entry.type === "cookie" || entry.type === "localStorage")
|
|
42
|
+
? [
|
|
43
|
+
{
|
|
44
|
+
category: service.category,
|
|
45
|
+
type: entry.type,
|
|
46
|
+
name: entry.name.trim(),
|
|
47
|
+
},
|
|
48
|
+
]
|
|
49
|
+
: [])
|
|
50
|
+
: []);
|
|
38
51
|
const optional = categories.length > 1;
|
|
39
52
|
const pick = (value, fallback) => value?.trim() || fallback;
|
|
40
53
|
const buttons = doc.buttons ?? {};
|
|
@@ -52,6 +65,7 @@ export function toConsentConfig(doc, services, options) {
|
|
|
52
65
|
policyVersion: policyVersion(categories, services),
|
|
53
66
|
googleConsentMode: doc.googleConsentMode === "advanced" ? "advanced" : "basic",
|
|
54
67
|
integrations,
|
|
68
|
+
storage,
|
|
55
69
|
embeds: {
|
|
56
70
|
title: pick(doc.embeds?.title, suggested.embeds.title),
|
|
57
71
|
button: pick(doc.embeds?.button, suggested.embeds.button),
|
package/dist/styles/admin.css
CHANGED
|
@@ -142,3 +142,61 @@
|
|
|
142
142
|
margin: 0;
|
|
143
143
|
color: var(--theme-elevation-600);
|
|
144
144
|
}
|
|
145
|
+
|
|
146
|
+
/* The Services and Consent log tabs on the Cookies page. */
|
|
147
|
+
.consent-panel {
|
|
148
|
+
display: flex;
|
|
149
|
+
flex-direction: column;
|
|
150
|
+
gap: var(--base);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.consent-panel__link,
|
|
154
|
+
.consent-panel__more a,
|
|
155
|
+
.consent-panel__links a {
|
|
156
|
+
color: var(--theme-text);
|
|
157
|
+
text-decoration: underline;
|
|
158
|
+
text-underline-offset: 2px;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.consent-panel__more {
|
|
162
|
+
margin: 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.consent-panel__table {
|
|
166
|
+
width: 100%;
|
|
167
|
+
border-collapse: collapse;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.consent-panel__table th,
|
|
171
|
+
.consent-panel__table td {
|
|
172
|
+
padding: calc(var(--base) * 0.5) calc(var(--base) * 0.75);
|
|
173
|
+
border-bottom: 1px solid var(--theme-elevation-100);
|
|
174
|
+
text-align: left;
|
|
175
|
+
vertical-align: middle;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.consent-panel__table th {
|
|
179
|
+
color: var(--theme-elevation-500);
|
|
180
|
+
font-weight: 500;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.consent-panel__table td a {
|
|
184
|
+
color: var(--theme-text);
|
|
185
|
+
font-weight: 500;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.consent-panel__links {
|
|
189
|
+
display: flex;
|
|
190
|
+
flex-direction: column;
|
|
191
|
+
gap: calc(var(--base) * 0.75);
|
|
192
|
+
margin: 0;
|
|
193
|
+
padding: 0;
|
|
194
|
+
list-style: none;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.consent-panel__links li {
|
|
198
|
+
display: flex;
|
|
199
|
+
flex-wrap: wrap;
|
|
200
|
+
gap: calc(var(--base) * 0.75);
|
|
201
|
+
align-items: baseline;
|
|
202
|
+
}
|
package/dist/styles/consent.css
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Category } from "./defaults.ts";
|
|
2
|
+
/** A cookie or localStorage key a service stores on the site itself, in its service's category. */
|
|
3
|
+
export type StoredItem = {
|
|
4
|
+
category: Category;
|
|
5
|
+
type: "cookie" | "localStorage";
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
/** `_ga_*` names a family of cookies by prefix; any other name matches itself. */
|
|
9
|
+
export declare function matchesStorageName(pattern: string, name: string): boolean;
|
|
10
|
+
/** What the services of the categories the visitor no longer allows stored on this site. */
|
|
11
|
+
export declare function withdrawnStorage(storage: StoredItem[], consents: Partial<Record<string, boolean>>): StoredItem[];
|
|
12
|
+
/**
|
|
13
|
+
* The domains a cookie set on `hostname` may live under: none (the host itself), the host and
|
|
14
|
+
* each parent, so `www.kundsajt.se` gives `www.kundsajt.se` and `kundsajt.se`. Analytics cookies
|
|
15
|
+
* are usually set on the highest one the browser allows.
|
|
16
|
+
*/
|
|
17
|
+
export declare function cookieDomains(hostname: string): (string | undefined)[];
|
|
18
|
+
/** The visitor ID in c15t 2.2.1's cookie, `…,i.sid:sub_…,…`. */
|
|
19
|
+
export declare function subjectIdFromCookie(cookie: string): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** `_ga_*` names a family of cookies by prefix; any other name matches itself. */
|
|
2
|
+
export function matchesStorageName(pattern, name) {
|
|
3
|
+
return pattern.endsWith("*") ? name.startsWith(pattern.slice(0, -1)) : name === pattern;
|
|
4
|
+
}
|
|
5
|
+
/** What the services of the categories the visitor no longer allows stored on this site. */
|
|
6
|
+
export function withdrawnStorage(storage, consents) {
|
|
7
|
+
return storage.filter((item) => item.category !== "necessary" && !consents[item.category]);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The domains a cookie set on `hostname` may live under: none (the host itself), the host and
|
|
11
|
+
* each parent, so `www.kundsajt.se` gives `www.kundsajt.se` and `kundsajt.se`. Analytics cookies
|
|
12
|
+
* are usually set on the highest one the browser allows.
|
|
13
|
+
*/
|
|
14
|
+
export function cookieDomains(hostname) {
|
|
15
|
+
const parts = hostname.split(".");
|
|
16
|
+
const domains = [undefined];
|
|
17
|
+
for (let index = 0; index < parts.length - 1; index += 1)
|
|
18
|
+
domains.push(parts.slice(index).join("."));
|
|
19
|
+
return domains;
|
|
20
|
+
}
|
|
21
|
+
/** The visitor ID in c15t 2.2.1's cookie, `…,i.sid:sub_…,…`. */
|
|
22
|
+
export function subjectIdFromCookie(cookie) {
|
|
23
|
+
return /(?:^|; )c15t=[^;]*?i\.sid:([^,;]+)/.exec(cookie)?.[1];
|
|
24
|
+
}
|