@simmalugnt-se/payload-consent 0.6.0 → 0.6.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 +7 -0
- package/README.md +4 -3
- package/dist/scans.d.ts +7 -5
- package/dist/scans.js +22 -10
- package/dist/types.d.ts +3 -2
- package/dist/types.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
- `scanner.pages` sends a list per collection, and the scanner picks from each as from one sitemap:
|
|
6
|
+
in one list, a large collection such as news took nearly every visited page from the others.
|
|
7
|
+
Needs `consent-scanner` at `fcf4a71` or later: the scanner 0.6.0 was made for (`eef412e`) refuses
|
|
8
|
+
lists, and an older one ignores them and reads the sitemaps.
|
|
9
|
+
|
|
3
10
|
## 0.6.0
|
|
4
11
|
|
|
5
12
|
- `scanner.pages` sends the site's published pages from Payload with a scan, in place of its
|
package/README.md
CHANGED
|
@@ -134,9 +134,10 @@ The scanner picks the pages to visit from the site's sitemaps. A site with searc
|
|
|
134
134
|
often serves empty ones, and then only the start page is scanned. With `scanner.pages`, a scan
|
|
135
135
|
sends the published documents of those collections instead: read as a visitor would, in the
|
|
136
136
|
default locale, each turned into a path or address by `url` (return nothing to leave one out).
|
|
137
|
-
Paths are taken relative to the scanned address, and addresses on another origin are left out
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
Paths are taken relative to the scanned address, and addresses on another origin are left out.
|
|
138
|
+
Each collection goes as its own list, and the scanner picks from each as from one sitemap, so a
|
|
139
|
+
thousand news articles do not crowd out the pages; the lists share at most 500 addresses, each
|
|
140
|
+
thinned evenly. Without the option, or when no page is left, the scanner reads the sitemaps.
|
|
140
141
|
|
|
141
142
|
Scan now scans the site's address (the field above the button, or `serverURL`) as a new visitor,
|
|
142
143
|
after rejecting, after accepting and, with several optional categories, with each one alone. The
|
package/dist/scans.d.ts
CHANGED
|
@@ -10,12 +10,14 @@ import { type ConsentPluginOptions } from "./types.ts";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function scanStates(config: Pick<ConsentConfig, "categories" | "policyVersion">, now?: number): ScanState[];
|
|
12
12
|
/**
|
|
13
|
-
* The published pages of `scanner.pages
|
|
14
|
-
* (`overrideAccess: false`) in the default locale.
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* The published pages of `scanner.pages`, a list per collection, as addresses on the scanned site,
|
|
14
|
+
* read as a visitor would (`overrideAccess: false`) in the default locale. The scanner picks from
|
|
15
|
+
* each list as from one sitemap, so a large collection does not crowd out a small one. Paths are
|
|
16
|
+
* taken relative to `url`; addresses on another origin are left out, since the scanner refuses
|
|
17
|
+
* them. The lists share `MAX_SCAN_PAGES`, each thinned evenly to its share. `undefined` without
|
|
18
|
+
* any page, so the scanner reads the sitemaps.
|
|
17
19
|
*/
|
|
18
|
-
export declare function scanPages(payload: Payload, options: ConsentPluginOptions, url: string): Promise<string[] | undefined>;
|
|
20
|
+
export declare function scanPages(payload: Payload, options: ConsentPluginOptions, url: string): Promise<string[][] | undefined>;
|
|
19
21
|
type Started = {
|
|
20
22
|
id: number | string;
|
|
21
23
|
} | {
|
package/dist/scans.js
CHANGED
|
@@ -37,17 +37,21 @@ export function scanStates(config, now = Date.now()) {
|
|
|
37
37
|
return states;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* The published pages of `scanner.pages
|
|
41
|
-
* (`overrideAccess: false`) in the default locale.
|
|
42
|
-
*
|
|
43
|
-
*
|
|
40
|
+
* The published pages of `scanner.pages`, a list per collection, as addresses on the scanned site,
|
|
41
|
+
* read as a visitor would (`overrideAccess: false`) in the default locale. The scanner picks from
|
|
42
|
+
* each list as from one sitemap, so a large collection does not crowd out a small one. Paths are
|
|
43
|
+
* taken relative to `url`; addresses on another origin are left out, since the scanner refuses
|
|
44
|
+
* them. The lists share `MAX_SCAN_PAGES`, each thinned evenly to its share. `undefined` without
|
|
45
|
+
* any page, so the scanner reads the sitemaps.
|
|
44
46
|
*/
|
|
45
47
|
export async function scanPages(payload, options, url) {
|
|
46
48
|
const site = new URL(url);
|
|
47
49
|
const localization = payload.config.localization;
|
|
48
50
|
const locale = localization ? localization.defaultLocale : undefined;
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
+
const collections = options.scanner?.pages ?? [];
|
|
52
|
+
const share = Math.floor(MAX_SCAN_PAGES / Math.max(collections.length, 1));
|
|
53
|
+
const lists = [];
|
|
54
|
+
for (const { collection, url: toUrl } of collections) {
|
|
51
55
|
const drafts = Boolean(payload.config.collections.find(({ slug }) => slug === collection)?.versions?.drafts);
|
|
52
56
|
const { docs } = await payload.find({
|
|
53
57
|
collection: collection,
|
|
@@ -57,6 +61,7 @@ export async function scanPages(payload, options, url) {
|
|
|
57
61
|
overrideAccess: false,
|
|
58
62
|
...(drafts ? { where: { _status: { equals: "published" } } } : {}),
|
|
59
63
|
});
|
|
64
|
+
const found = new Set();
|
|
60
65
|
for (const doc of docs) {
|
|
61
66
|
let address;
|
|
62
67
|
try {
|
|
@@ -73,11 +78,18 @@ export async function scanPages(payload, options, url) {
|
|
|
73
78
|
address.hash = "";
|
|
74
79
|
found.add(address.href);
|
|
75
80
|
}
|
|
81
|
+
const pages = [...found].sort();
|
|
82
|
+
if (pages.length)
|
|
83
|
+
lists.push(evenlySpaced(pages, share));
|
|
76
84
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
85
|
+
return lists.length ? lists : undefined;
|
|
86
|
+
}
|
|
87
|
+
function evenlySpaced(values, maximum) {
|
|
88
|
+
if (values.length <= maximum)
|
|
89
|
+
return values;
|
|
90
|
+
if (maximum === 1)
|
|
91
|
+
return values.slice(0, 1);
|
|
92
|
+
return Array.from({ length: maximum }, (_, index) => values[Math.round((index * (values.length - 1)) / (maximum - 1))]);
|
|
81
93
|
}
|
|
82
94
|
function sameToken(given, expected) {
|
|
83
95
|
const a = Buffer.from(given);
|
package/dist/types.d.ts
CHANGED
|
@@ -58,7 +58,8 @@ export type ConsentPluginOptions = {
|
|
|
58
58
|
* Collections whose published documents are the site's pages; `url` turns a document into its
|
|
59
59
|
* path or address, as in `legalPages`, or returns nothing to leave it out. A scan sends these
|
|
60
60
|
* pages to the scanner in place of the site's sitemaps, which a site with search indexing off
|
|
61
|
-
* leaves empty
|
|
61
|
+
* leaves empty, and the scanner picks from each collection as from one sitemap. Without it,
|
|
62
|
+
* the scanner reads the sitemaps.
|
|
62
63
|
*/
|
|
63
64
|
pages?: {
|
|
64
65
|
collection: CollectionSlug;
|
|
@@ -85,5 +86,5 @@ export declare const POLICY_COOKIE = "c15t-policy";
|
|
|
85
86
|
/** Three years, unless the host sets `records.retentionDays`. */
|
|
86
87
|
export declare const DEFAULT_RETENTION_DAYS: number;
|
|
87
88
|
export declare const DEFAULT_KEEP_EVIDENCE = 12;
|
|
88
|
-
/** The most pages a scan sends; the scanner takes up to 500. */
|
|
89
|
+
/** The most pages a scan sends, in all its lists; the scanner takes up to 500. */
|
|
89
90
|
export declare const MAX_SCAN_PAGES = 500;
|
package/dist/types.js
CHANGED
|
@@ -15,5 +15,5 @@ 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; the scanner takes up to 500. */
|
|
18
|
+
/** The most pages a scan sends, in all its lists; the scanner takes up to 500. */
|
|
19
19
|
export const MAX_SCAN_PAGES = 500;
|