@simmalugnt-se/payload-consent 0.1.0 → 0.2.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,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - Cookies is the one entry in Admin: a Services tab lists the Cookie services with links to edit
6
+ and add them, a Consent log tab links to the records and policy versions, and the Scan tab links
7
+ to every scan. The plugin's collections no longer appear in the navigation or on the dashboard.
8
+ - The settings dialog no longer shows "Reject optional" when the site has only necessary storage.
9
+
3
10
  ## 0.1.0
4
11
 
5
12
  - 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) and the collections `consent-services` (Cookie
28
- services), `consent-records` and `consent-policies` (the consent log), `consent-scans` and
29
- `consent-scan-evidence`, all under Settings, a jobs task (`consentScan`) and a dashboard widget. Generate types, then create and apply a migration with the
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
@@ -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
- group: options.group ?? { en: "Settings", sv: "Inställningar" },
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 },
@@ -1 +1,2 @@
1
1
  export { ScanPanel } from "../admin/ScanPanel.tsx";
2
+ export { ConsentLogPanel, ScanLinks, ServicesPanel } from "../admin/ServicesPanel.tsx";
@@ -1 +1,2 @@
1
1
  export { ScanPanel } from "../admin/ScanPanel.js";
2
+ export { ConsentLogPanel, ScanLinks, ServicesPanel } from "../admin/ServicesPanel.js";
@@ -153,7 +153,10 @@ function SettingsDialog() {
153
153
  setSelectedConsent(name, consents[name] ?? false);
154
154
  setActiveUI(hasConsented() ? "none" : "banner");
155
155
  }
156
- return (_jsx(C15tDialog.Root, { onClick: dismiss, children: _jsx(C15tDialog.ConsentCustomizationCard, { hideBranding: true }) }));
156
+ // With only necessary storage there is nothing to reject; c15t's dialog has no option to drop
157
+ // the button, so a class hides it (see consent.css).
158
+ const necessaryOnly = useContext(ConfigContext)?.categories.length === 1;
159
+ return (_jsx(C15tDialog.Root, { className: necessaryOnly ? "sc-dialog--necessary-only" : undefined, onClick: dismiss, children: _jsx(C15tDialog.ConsentCustomizationCard, { hideBranding: true }) }));
157
160
  }
158
161
  /**
159
162
  * 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
- group: group(options),
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
- group: group(options),
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
- group: options.group ?? { en: "Settings", sv: "Inställningar" },
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
- group: options.group ?? { en: "Settings", sv: "Inställningar" },
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.",
@@ -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
+ }
@@ -294,3 +294,8 @@
294
294
  .sc-cookie-service:has(table) {
295
295
  overflow-x: auto;
296
296
  }
297
+
298
+ /* With only necessary storage there is nothing to reject. */
299
+ .sc-dialog--necessary-only [data-testid="consent-widget-reject-button"] {
300
+ display: none;
301
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-consent",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Cookie consent for Payload sites: banner texts, services and scans in Admin",
5
5
  "keywords": [
6
6
  "payload",