@simmalugnt-se/payload-consent 0.6.5 → 0.6.7
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 +21 -0
- package/README.md +12 -9
- package/dist/global.js +20 -7
- package/dist/notify.js +11 -1
- package/dist/scans.d.ts +6 -0
- package/dist/scans.js +10 -2
- package/dist/types.d.ts +4 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.7
|
|
4
|
+
|
|
5
|
+
- The help under Site address and Scan every month stays out of the site's generated types. It
|
|
6
|
+
names the site's own address and scan day, so `payload-types.ts` differed by environment and
|
|
7
|
+
site, and changed when the types were generated elsewhere. The help is now a function, which
|
|
8
|
+
Payload renders in Admin but leaves out of the types; Admin shows the same text.
|
|
9
|
+
|
|
10
|
+
## 0.6.6
|
|
11
|
+
|
|
12
|
+
- A scan without a Site address scans `scanner.callbackBaseUrl`, then `serverURL`. Before, it took
|
|
13
|
+
`serverURL` only, so on a site without one (the boilerplate leaves it unset, so Admin calls its
|
|
14
|
+
own origin from every deployment) Scan now asked for an address and the monthly scan failed,
|
|
15
|
+
although the field's help promised the site's own address. The field now shows the address it
|
|
16
|
+
falls back to, in its placeholder and help.
|
|
17
|
+
- The result email's link to Admin works without `serverURL`: it is on the scanned site's origin.
|
|
18
|
+
Before, it began with `undefined`.
|
|
19
|
+
- The callback address is trimmed like the scanned one, so a `callbackBaseUrl` with spaces around
|
|
20
|
+
it no longer breaks the result's way back.
|
|
21
|
+
- The README shows `consent-scanner`'s `config/sites` (at `fa39703` or later) for binding a token
|
|
22
|
+
to its hosts.
|
|
23
|
+
|
|
3
24
|
## 0.6.5
|
|
4
25
|
|
|
5
26
|
- The Scan tab shows the card's shape with Payload's shimmer while the latest scan loads. Before,
|
package/README.md
CHANGED
|
@@ -122,20 +122,22 @@ consentPlugin({
|
|
|
122
122
|
scanner: {
|
|
123
123
|
url: process.env.CONSENT_SCANNER_URL,
|
|
124
124
|
token: process.env.CONSENT_SCANNER_TOKEN,
|
|
125
|
-
//
|
|
126
|
-
//
|
|
125
|
+
// The site's address as the scanner reaches it, when Payload has no serverURL or the
|
|
126
|
+
// scanner cannot reach it (Docker beside a dev server: 'http://host.docker.internal:3000'):
|
|
127
|
+
// callbackBaseUrl: process.env.NEXT_PUBLIC_SITE_URL,
|
|
127
128
|
// Optional: the pages to scan, in place of the site's sitemaps.
|
|
128
129
|
pages: [{ collection: 'pages', url: (doc) => (doc.slug === 'home' ? '/' : `/${doc.slug}`) }],
|
|
129
130
|
},
|
|
130
131
|
})
|
|
131
132
|
```
|
|
132
133
|
|
|
133
|
-
The scanner binds each token to its site's hosts (`
|
|
134
|
-
`
|
|
134
|
+
The scanner binds each token to its site's hosts (`example 3f9c… example.se example.vercel.app` in
|
|
135
|
+
its `config/sites`), and refuses a scan whose address or callback is on another host: give it the
|
|
135
136
|
host of the scanned address and, when results come back elsewhere (`serverURL` or
|
|
136
137
|
`callbackBaseUrl`), that host too. A host covers itself with and without `www.`, and the scanner
|
|
137
138
|
treats a site with and without `www.` as one, so a Site address of `https://example.se` still finds
|
|
138
|
-
the pages on `https://www.example.se`. Both need `consent-scanner` at `0b7aba1` or later
|
|
139
|
+
the pages on `https://www.example.se`. Both need `consent-scanner` at `0b7aba1` or later;
|
|
140
|
+
`config/sites` needs `fa39703` or later (before it, `SCANNER_TOKENS` in its `.env`).
|
|
139
141
|
|
|
140
142
|
The scanner picks the pages to visit from the site's sitemaps. A site with search indexing off
|
|
141
143
|
often serves empty ones, and then only the start page is scanned. With `scanner.pages`, a scan
|
|
@@ -146,10 +148,11 @@ Each collection goes as its own list, and the scanner picks from each as from on
|
|
|
146
148
|
thousand news articles do not crowd out the pages; the lists share at most 500 addresses, each
|
|
147
149
|
thinned evenly. Without the option, or when no page is left, the scanner reads the sitemaps.
|
|
148
150
|
|
|
149
|
-
Scan now scans the site's address (the Site address field
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
Scan now scans the site's address (the Site address field; with it empty, `callbackBaseUrl`, then
|
|
152
|
+
`serverURL`, as the field's placeholder and help say) as a new visitor, after rejecting, after
|
|
153
|
+
accepting and, with several optional categories, with each one alone. The plugin presets c15t's
|
|
154
|
+
cookie for each state, so no click is needed. While it runs, the card at the top of the Scan tab
|
|
155
|
+
follows it page by page, with the time it has taken and a rough time left.
|
|
153
156
|
|
|
154
157
|
The scanner posts the result back to `/api/consent-scans/result`. The card then says what it
|
|
155
158
|
means: nothing to fix, how many need action or are not explained, or that the scan could not see
|
package/dist/global.js
CHANGED
|
@@ -48,9 +48,17 @@ const necessaryOnly = {
|
|
|
48
48
|
},
|
|
49
49
|
condition: (data) => !hasOptional(data),
|
|
50
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* A help text that depends on the site, such as its address or its scan day, as a function:
|
|
53
|
+
* Payload leaves functions out of the generated types, so `payload-types.ts` stays the same in
|
|
54
|
+
* every environment and on every site.
|
|
55
|
+
*/
|
|
56
|
+
const siteDescription = (texts) => ({ i18n }) => i18n.language === "sv" ? texts.sv : texts.en;
|
|
51
57
|
export function consentGlobal(options, { usersSlug, schedule }) {
|
|
52
58
|
const time = `${String(schedule.hour).padStart(2, "0")}:${String(schedule.minute).padStart(2, "0")}`;
|
|
53
59
|
const legal = options.legalPages;
|
|
60
|
+
// What a scan scans without an address here (`siteAddress`), when known before Payload starts.
|
|
61
|
+
const fallbackAddress = options.scanner?.callbackBaseUrl?.trim() || undefined;
|
|
54
62
|
const global = {
|
|
55
63
|
slug: CONSENT_GLOBAL,
|
|
56
64
|
label: { en: "Cookies", sv: "Cookies" },
|
|
@@ -199,11 +207,16 @@ export function consentGlobal(options, { usersSlug, schedule }) {
|
|
|
199
207
|
type: "text",
|
|
200
208
|
label: { en: "Site address", sv: "Webbplatsens adress" },
|
|
201
209
|
admin: {
|
|
202
|
-
placeholder: "https://",
|
|
203
|
-
description:
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
210
|
+
placeholder: fallbackAddress ?? "https://",
|
|
211
|
+
description: siteDescription(fallbackAddress
|
|
212
|
+
? {
|
|
213
|
+
en: `The published site's start page. Empty: ${fallbackAddress}, where the scanner sends its results.`,
|
|
214
|
+
sv: `Den publicerade webbplatsens startsida. Tom: ${fallbackAddress}, dit scannern skickar resultaten.`,
|
|
215
|
+
}
|
|
216
|
+
: {
|
|
217
|
+
en: "The published site's start page. Empty: Payload's serverURL.",
|
|
218
|
+
sv: "Den publicerade webbplatsens startsida. Tom: Payloads serverURL.",
|
|
219
|
+
}),
|
|
207
220
|
},
|
|
208
221
|
},
|
|
209
222
|
{
|
|
@@ -212,10 +225,10 @@ export function consentGlobal(options, { usersSlug, schedule }) {
|
|
|
212
225
|
defaultValue: true,
|
|
213
226
|
label: { en: "Scan every month", sv: "Skanna varje månad" },
|
|
214
227
|
admin: {
|
|
215
|
-
description: {
|
|
228
|
+
description: siteDescription({
|
|
216
229
|
en: `On day ${schedule.day} of each month, the first time the host's cron runs Payload's jobs after ${time} server time.`,
|
|
217
230
|
sv: `Den ${schedule.day}:e varje månad, första gången värdens cron kör Payloads jobb efter kl. ${time} servertid.`,
|
|
218
|
-
},
|
|
231
|
+
}),
|
|
219
232
|
},
|
|
220
233
|
},
|
|
221
234
|
{
|
package/dist/notify.js
CHANGED
|
@@ -51,6 +51,14 @@ function count(summary, language) {
|
|
|
51
51
|
(language === "sv" ? "inget att åtgärda" : "nothing to handle"));
|
|
52
52
|
}
|
|
53
53
|
const escape = (value) => value.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c] ?? c);
|
|
54
|
+
const origin = (url) => {
|
|
55
|
+
try {
|
|
56
|
+
return new URL(url).origin;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
};
|
|
54
62
|
/**
|
|
55
63
|
* Emails the users picked under Cookies → Scan about a finished scan, through the host's
|
|
56
64
|
* email adapter, when it needs a look. Admin's default language picks the text.
|
|
@@ -79,7 +87,9 @@ export async function notifyScan(payload, outcome) {
|
|
|
79
87
|
}
|
|
80
88
|
})();
|
|
81
89
|
const text = outcome.status === "failed" ? copy.failed(outcome) : copy.done(outcome);
|
|
82
|
-
|
|
90
|
+
// Admin is on the scanned site's origin when Payload has no serverURL.
|
|
91
|
+
const base = payload.config.serverURL || origin(outcome.url);
|
|
92
|
+
const link = `${base}${payload.config.routes.admin}/globals/${CONSENT_GLOBAL}`;
|
|
83
93
|
try {
|
|
84
94
|
await payload.sendEmail({
|
|
85
95
|
to,
|
package/dist/scans.d.ts
CHANGED
|
@@ -38,6 +38,12 @@ export type ScanStage = {
|
|
|
38
38
|
visited: number;
|
|
39
39
|
total: number;
|
|
40
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* The site's own address, scanned when the Scan tab has none: where the scanner reaches the site
|
|
43
|
+
* (`scanner.callbackBaseUrl`), else Payload's `serverURL`. Many sites leave `serverURL` unset, so
|
|
44
|
+
* Admin calls its own origin from every deployment.
|
|
45
|
+
*/
|
|
46
|
+
export declare function siteAddress(payload: Payload, options: ConsentPluginOptions): string | undefined;
|
|
41
47
|
/**
|
|
42
48
|
* Asks the scanner to scan the site in every consent state and records the scan as queued. The
|
|
43
49
|
* address is the one given (the Scan tab's field, saved or not), then the saved one, then the
|
package/dist/scans.js
CHANGED
|
@@ -121,6 +121,14 @@ async function allServices(req) {
|
|
|
121
121
|
});
|
|
122
122
|
return docs;
|
|
123
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* The site's own address, scanned when the Scan tab has none: where the scanner reaches the site
|
|
126
|
+
* (`scanner.callbackBaseUrl`), else Payload's `serverURL`. Many sites leave `serverURL` unset, so
|
|
127
|
+
* Admin calls its own origin from every deployment.
|
|
128
|
+
*/
|
|
129
|
+
export function siteAddress(payload, options) {
|
|
130
|
+
return options.scanner?.callbackBaseUrl?.trim() || payload.config.serverURL || undefined;
|
|
131
|
+
}
|
|
124
132
|
/**
|
|
125
133
|
* Asks the scanner to scan the site in every consent state and records the scan as queued. The
|
|
126
134
|
* address is the one given (the Scan tab's field, saved or not), then the saved one, then the
|
|
@@ -135,7 +143,7 @@ export async function startScan({ payload, options, url: given, trigger = "manua
|
|
|
135
143
|
depth: 0,
|
|
136
144
|
overrideAccess: true,
|
|
137
145
|
}));
|
|
138
|
-
const url = given?.trim() || global.scanUrl?.trim() || payload
|
|
146
|
+
const url = given?.trim() || global.scanUrl?.trim() || siteAddress(payload, options);
|
|
139
147
|
if (!url || !/^https?:\/\//.test(url))
|
|
140
148
|
return { error: "Enter the site's address, starting with https://", status: 400 };
|
|
141
149
|
const { doc, services } = await readConsent({ payload });
|
|
@@ -145,7 +153,7 @@ export async function startScan({ payload, options, url: given, trigger = "manua
|
|
|
145
153
|
payload.logger.error({ err: error, msg: "payload-consent: could not list the pages to scan" });
|
|
146
154
|
return undefined;
|
|
147
155
|
});
|
|
148
|
-
const base = `${
|
|
156
|
+
const base = `${siteAddress(payload, options) ?? ""}${payload.config.routes.api}/${CONSENT_SCANS}`;
|
|
149
157
|
const response = await fetch(new URL("/scans", scanner.url), {
|
|
150
158
|
method: "POST",
|
|
151
159
|
headers: { "content-type": "application/json", authorization: `Bearer ${scanner.token}` },
|
package/dist/types.d.ts
CHANGED
|
@@ -45,8 +45,10 @@ export type ConsentPluginOptions = {
|
|
|
45
45
|
url: string;
|
|
46
46
|
token: string;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
48
|
+
* The site's address as the scanner reaches it: where it posts results, and what Scan now and
|
|
49
|
+
* the monthly scan scan when the Scan tab has no address. Defaults to `serverURL`. Set it when
|
|
50
|
+
* Payload has no `serverURL` (the site's public address), or when the scanner cannot reach
|
|
51
|
+
* `serverURL`, such as `http://host.docker.internal:3000` beside a local dev server.
|
|
50
52
|
*/
|
|
51
53
|
callbackBaseUrl?: string;
|
|
52
54
|
/**
|