@cloudhal/schedules 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +103 -2
- package/dist/src/automation.d.ts +82 -0
- package/dist/src/automation.js +199 -0
- package/dist/src/budget-meter.d.ts +58 -0
- package/dist/src/budget-meter.js +130 -0
- package/dist/src/budget.d.ts +41 -0
- package/dist/src/budget.js +76 -0
- package/dist/src/builtins.d.ts +132 -0
- package/dist/src/builtins.js +473 -0
- package/dist/src/engine.d.ts +16 -0
- package/dist/src/engine.js +30 -0
- package/dist/src/errors.d.ts +22 -0
- package/dist/src/errors.js +56 -0
- package/dist/src/feed-check.d.ts +56 -0
- package/dist/src/feed-check.js +365 -0
- package/dist/src/findings.d.ts +185 -0
- package/dist/src/findings.js +287 -0
- package/dist/src/ids.d.ts +24 -0
- package/dist/src/ids.js +96 -0
- package/dist/src/index.d.ts +24 -0
- package/dist/src/index.js +24 -0
- package/dist/src/instant.d.ts +19 -0
- package/dist/src/instant.js +50 -0
- package/dist/src/notify.d.ts +50 -0
- package/dist/src/notify.js +60 -0
- package/dist/src/recurrence.d.ts +155 -0
- package/dist/src/recurrence.js +939 -0
- package/dist/src/release-when.d.ts +23 -0
- package/dist/src/release-when.js +55 -0
- package/dist/src/release.d.ts +198 -0
- package/dist/src/release.js +552 -0
- package/dist/src/scheduler.d.ts +490 -0
- package/dist/src/scheduler.js +1343 -0
- package/dist/src/sql/finish.d.ts +32 -0
- package/dist/src/sql/finish.js +103 -0
- package/dist/src/sql/index.d.ts +6 -0
- package/dist/src/sql/index.js +15 -0
- package/dist/src/sql/rows.d.ts +125 -0
- package/dist/src/sql/rows.js +297 -0
- package/dist/src/sql/store.d.ts +467 -0
- package/dist/src/sql/store.js +2166 -0
- package/dist/src/taint.d.ts +65 -0
- package/dist/src/taint.js +138 -0
- package/dist/src/text.d.ts +6 -0
- package/dist/src/text.js +25 -0
- package/dist/src/time-entry.d.ts +6 -0
- package/dist/src/time-entry.js +6 -0
- package/dist/src/time.d.ts +61 -0
- package/dist/src/time.js +140 -0
- package/package.json +69 -3
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `feed-check` built-in's checks (RFC-0008 §11.1, §7.2), pure over the fetched text. The
|
|
3
|
+
* site's own RSS feed and sitemap are fetched through the `SITE` binding (or the local renderer on
|
|
4
|
+
* Node) and checked for: well-formed XML of the right kind; items with a title and a link; no date
|
|
5
|
+
* in the future; the newest published entries present; media URLs that are live assets; and the
|
|
6
|
+
* **gate self-check** — no embargoed or expired node appears, the time-gate helper verified in
|
|
7
|
+
* production.
|
|
8
|
+
*
|
|
9
|
+
* The fetched text is untrusted (§11.4): it is parsed with bounded scans, never evaluated, and
|
|
10
|
+
* whatever of it a finding quotes is one plain line, marked `untrusted`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { instantMs, MINUTE_MS } from "./instant.js";
|
|
14
|
+
import { plainLine } from "./text.js";
|
|
15
|
+
|
|
16
|
+
/** Documents larger than this are not parsed (`feed-invalid`). */
|
|
17
|
+
export const MAX_DOCUMENT_CHARS = 5_000_000;
|
|
18
|
+
/** How many of the newest published entries must appear in the feed and the sitemap. */
|
|
19
|
+
export const FEED_NEWEST = 5;
|
|
20
|
+
/** Clock skew tolerated before a date counts as "in the future". */
|
|
21
|
+
export const FUTURE_TOLERANCE_MS = 5 * MINUTE_MS;
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export const FEED_PATHS = {
|
|
26
|
+
rss: "/rss.xml",
|
|
27
|
+
sitemap: "/sitemap.xml",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** What the live snapshot says the documents must (and must not) contain. */
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
const finding = (
|
|
56
|
+
document ,
|
|
57
|
+
code ,
|
|
58
|
+
severity ,
|
|
59
|
+
o = {},
|
|
60
|
+
) => ({
|
|
61
|
+
code,
|
|
62
|
+
severity,
|
|
63
|
+
document,
|
|
64
|
+
...(o.detail !== undefined ? { detail: plainLine(o.detail, 200) } : {}),
|
|
65
|
+
...(o.nodeId ? { nodeId: o.nodeId } : {}),
|
|
66
|
+
...(o.url ? { url: plainLine(o.url, 500) } : {}),
|
|
67
|
+
untrusted: true,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/** The end of a tag starting after `<` at `from` (quotes respected), or -1. */
|
|
71
|
+
function tagEnd(text , from ) {
|
|
72
|
+
let quote = "";
|
|
73
|
+
for (let i = from; i < text.length; i++) {
|
|
74
|
+
const c = text[i];
|
|
75
|
+
if (quote) {
|
|
76
|
+
if (c === quote) quote = "";
|
|
77
|
+
} else if (c === '"' || c === "'") quote = c;
|
|
78
|
+
else if (c === ">") return i;
|
|
79
|
+
}
|
|
80
|
+
return -1;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const ENTITY = /&(?!(?:[A-Za-z][A-Za-z0-9]*|#[0-9]+|#x[0-9A-Fa-f]+);)/;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Why `text` is not well-formed XML (a bounded, linear scan: elements nest and close, one root,
|
|
87
|
+
* no stray text or `&`), or undefined. Not a validating parser; enough to catch a broken feed.
|
|
88
|
+
*/
|
|
89
|
+
export function xmlProblem(text ) {
|
|
90
|
+
const stack = [];
|
|
91
|
+
let rootSeen = false;
|
|
92
|
+
let i = 0;
|
|
93
|
+
while (i < text.length) {
|
|
94
|
+
const lt = text.indexOf("<", i);
|
|
95
|
+
const chunk = lt < 0 ? text.slice(i) : text.slice(i, lt);
|
|
96
|
+
if (ENTITY.test(chunk)) return "an unescaped & in text";
|
|
97
|
+
if (stack.length === 0 && chunk.trim() !== "") return "text outside the root element";
|
|
98
|
+
if (lt < 0) break;
|
|
99
|
+
if (text.startsWith("<!--", lt)) {
|
|
100
|
+
const e = text.indexOf("-->", lt + 4);
|
|
101
|
+
if (e < 0) return "an unclosed comment";
|
|
102
|
+
i = e + 3;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (text.startsWith("<![CDATA[", lt)) {
|
|
106
|
+
if (stack.length === 0) return "CDATA outside the root element";
|
|
107
|
+
const e = text.indexOf("]]>", lt + 9);
|
|
108
|
+
if (e < 0) return "an unclosed CDATA section";
|
|
109
|
+
i = e + 3;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (text.startsWith("<?", lt)) {
|
|
113
|
+
const e = text.indexOf("?>", lt + 2);
|
|
114
|
+
if (e < 0) return "an unclosed processing instruction";
|
|
115
|
+
i = e + 2;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (text.startsWith("<!", lt)) {
|
|
119
|
+
if (rootSeen || stack.length > 0) return "a declaration inside the document";
|
|
120
|
+
const e = text.indexOf(">", lt + 2);
|
|
121
|
+
if (e < 0) return "an unclosed declaration";
|
|
122
|
+
i = e + 1;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const gt = tagEnd(text, lt + 1);
|
|
126
|
+
if (gt < 0) return "an unclosed tag";
|
|
127
|
+
const raw = text.slice(lt + 1, gt);
|
|
128
|
+
if (raw.startsWith("/")) {
|
|
129
|
+
const name = raw.slice(1).trim();
|
|
130
|
+
const open = stack.pop();
|
|
131
|
+
if (open !== name) return open ? `</${name}> closes <${open}>` : `</${name}> closes nothing`;
|
|
132
|
+
i = gt + 1;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const m = /^([A-Za-z_][\w.:-]*)/.exec(raw);
|
|
136
|
+
if (!m) return "a malformed tag";
|
|
137
|
+
if (stack.length === 0 && rootSeen) return "more than one root element";
|
|
138
|
+
if (stack.length === 0) rootSeen = true;
|
|
139
|
+
if (!raw.endsWith("/")) stack.push(m[1] );
|
|
140
|
+
i = gt + 1;
|
|
141
|
+
}
|
|
142
|
+
if (stack.length > 0) return `<${stack[stack.length - 1]}> is not closed`;
|
|
143
|
+
return rootSeen ? undefined : "no root element";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const ENTITIES = {
|
|
147
|
+
amp: "&",
|
|
148
|
+
lt: "<",
|
|
149
|
+
gt: ">",
|
|
150
|
+
quot: '"',
|
|
151
|
+
apos: "'",
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/** Element text: CDATA unwrapped, the five XML entities and numeric references decoded. */
|
|
155
|
+
export function xmlText(raw ) {
|
|
156
|
+
const parts = [];
|
|
157
|
+
const re = /<!\[CDATA\[([\s\S]*?)\]\]>/g;
|
|
158
|
+
let last = 0;
|
|
159
|
+
for (const m of raw.matchAll(re)) {
|
|
160
|
+
parts.push(decode(raw.slice(last, m.index)), m[1] );
|
|
161
|
+
last = (m.index ?? 0) + m[0].length;
|
|
162
|
+
}
|
|
163
|
+
parts.push(decode(raw.slice(last)));
|
|
164
|
+
return parts.join("").trim();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function decode(s ) {
|
|
168
|
+
return s.replace(/&(#x[0-9A-Fa-f]+|#[0-9]+|[A-Za-z]+);/g, (all, e ) => {
|
|
169
|
+
if (e.startsWith("#x")) return safeChar(Number.parseInt(e.slice(2), 16)) ?? all;
|
|
170
|
+
if (e.startsWith("#")) return safeChar(Number.parseInt(e.slice(1), 10)) ?? all;
|
|
171
|
+
return ENTITIES[e] ?? all;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function safeChar(code ) {
|
|
176
|
+
return Number.isInteger(code) && code > 0 && code <= 0x10ffff
|
|
177
|
+
? String.fromCodePoint(code)
|
|
178
|
+
: undefined;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function escapeName(name ) {
|
|
182
|
+
return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Every `<name>…</name>` block (non-nesting elements such as `item`, `url`). */
|
|
186
|
+
function blocks(text , name ) {
|
|
187
|
+
const n = escapeName(name);
|
|
188
|
+
return [...text.matchAll(new RegExp(`<${n}(?:\\s[^>]*)?>([\\s\\S]*?)</${n}\\s*>`, "g"))].map(
|
|
189
|
+
(m) => m[1] ,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The text of the first `<name>` child, or undefined. */
|
|
194
|
+
function child(block , name ) {
|
|
195
|
+
const n = escapeName(name);
|
|
196
|
+
const m = new RegExp(`<${n}(?:\\s[^>]*)?>([\\s\\S]*?)</${n}\\s*>`).exec(block);
|
|
197
|
+
return m ? xmlText(m[1] ) : undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** `url="…"` attributes of `<enclosure>` and `<media:content>`. */
|
|
201
|
+
function mediaAttributes(block ) {
|
|
202
|
+
return [...block.matchAll(/<(?:enclosure|media:content)\b[^>]*?\burl\s*=\s*(["'])(.*?)\1/g)].map(
|
|
203
|
+
(m) => decode(m[2] ),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** A URL's path as the site routes it (no query, fragment or trailing slash), or undefined. */
|
|
208
|
+
export function urlPath(url ) {
|
|
209
|
+
try {
|
|
210
|
+
const u = new URL(url.trim(), "https://site.invalid");
|
|
211
|
+
let p = u.pathname;
|
|
212
|
+
try {
|
|
213
|
+
p = decodeURI(p);
|
|
214
|
+
} catch {
|
|
215
|
+
// keep the encoded form
|
|
216
|
+
}
|
|
217
|
+
return p.length > 1 ? p.replace(/\/+$/, "") || "/" : p || "/";
|
|
218
|
+
} catch {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function future(at , now ) {
|
|
224
|
+
if (!at) return false;
|
|
225
|
+
const t = Date.parse(at);
|
|
226
|
+
return Number.isFinite(t) && t > instantMs(now) + FUTURE_TOLERANCE_MS;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Checks shared by both documents: reachability and well-formedness. */
|
|
230
|
+
function documentProblems(
|
|
231
|
+
kind ,
|
|
232
|
+
doc ,
|
|
233
|
+
root ,
|
|
234
|
+
) {
|
|
235
|
+
if (doc?.status !== 200)
|
|
236
|
+
return [
|
|
237
|
+
finding(kind, "feed-unreachable", "error", {
|
|
238
|
+
detail: doc ? `HTTP ${doc.status}` : "no answer",
|
|
239
|
+
}),
|
|
240
|
+
];
|
|
241
|
+
if (doc.body.length > MAX_DOCUMENT_CHARS)
|
|
242
|
+
return [finding(kind, "feed-invalid", "error", { detail: "the document is too large" })];
|
|
243
|
+
const problem = xmlProblem(doc.body);
|
|
244
|
+
if (problem) return [finding(kind, "feed-invalid", "error", { detail: problem })];
|
|
245
|
+
if (!root.test(doc.body))
|
|
246
|
+
return [
|
|
247
|
+
finding(kind, "feed-invalid", "error", {
|
|
248
|
+
detail: kind === "rss" ? "not an RSS 2.0 channel" : "not a sitemap urlset",
|
|
249
|
+
}),
|
|
250
|
+
];
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** The gate self-check and the asset check over every URL and the raw text. */
|
|
255
|
+
function exposure(
|
|
256
|
+
kind ,
|
|
257
|
+
body ,
|
|
258
|
+
paths ,
|
|
259
|
+
exp ,
|
|
260
|
+
) {
|
|
261
|
+
const out = [];
|
|
262
|
+
for (const g of exp.gated)
|
|
263
|
+
if (paths.has(g.path) || body.includes(g.nodeId))
|
|
264
|
+
out.push(
|
|
265
|
+
finding(kind, "feed-gated-node", "error", {
|
|
266
|
+
nodeId: g.nodeId,
|
|
267
|
+
url: g.path,
|
|
268
|
+
detail: `${g.state} content appears in the ${kind === "rss" ? "feed" : "sitemap"}`,
|
|
269
|
+
}),
|
|
270
|
+
);
|
|
271
|
+
const live = new Set(exp.mediaPrefixes);
|
|
272
|
+
const seen = new Set ();
|
|
273
|
+
for (const m of body.matchAll(/\/media\/([0-9a-f]{16})\/[^\s"'<>]*/g)) {
|
|
274
|
+
const prefix = m[1] ;
|
|
275
|
+
if (live.has(prefix) || seen.has(prefix)) continue;
|
|
276
|
+
seen.add(prefix);
|
|
277
|
+
out.push(finding(kind, "feed-asset-not-live", "warning", { url: m[0] }));
|
|
278
|
+
}
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function missingNewest(
|
|
283
|
+
kind ,
|
|
284
|
+
paths ,
|
|
285
|
+
exp ,
|
|
286
|
+
) {
|
|
287
|
+
return exp.newest
|
|
288
|
+
.slice(0, FEED_NEWEST)
|
|
289
|
+
.filter((e) => !paths.has(e.path))
|
|
290
|
+
.map((e) =>
|
|
291
|
+
finding(kind, "feed-missing-entry", "warning", {
|
|
292
|
+
nodeId: e.nodeId,
|
|
293
|
+
url: e.path,
|
|
294
|
+
detail: `the newest entry "${e.title}" is missing`,
|
|
295
|
+
}),
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Checks the site's RSS 2.0 feed. */
|
|
300
|
+
export function checkRss(doc , exp ) {
|
|
301
|
+
const bad = documentProblems("rss", doc, /<rss\b[\s\S]*<channel\b/);
|
|
302
|
+
if (bad || !doc) return bad ?? [];
|
|
303
|
+
const out = [];
|
|
304
|
+
const paths = new Set ();
|
|
305
|
+
blocks(doc.body, "item").forEach((item, n) => {
|
|
306
|
+
const title = child(item, "title");
|
|
307
|
+
const link = child(item, "link");
|
|
308
|
+
const guid = child(item, "guid");
|
|
309
|
+
if (!title || !link)
|
|
310
|
+
out.push(
|
|
311
|
+
finding("rss", "feed-item-incomplete", "warning", {
|
|
312
|
+
detail: `item ${n + 1} has no ${title ? "link" : "title"}`,
|
|
313
|
+
...(link ? { url: link } : {}),
|
|
314
|
+
}),
|
|
315
|
+
);
|
|
316
|
+
for (const u of [link, guid, ...mediaAttributes(item)]) {
|
|
317
|
+
const p = u ? urlPath(u) : undefined;
|
|
318
|
+
if (p) paths.add(p);
|
|
319
|
+
}
|
|
320
|
+
const date = child(item, "pubDate");
|
|
321
|
+
if (future(date, exp.now))
|
|
322
|
+
out.push(
|
|
323
|
+
finding("rss", "feed-future-date", "warning", {
|
|
324
|
+
detail: `pubDate ${date} is in the future`,
|
|
325
|
+
...(link ? { url: link } : {}),
|
|
326
|
+
}),
|
|
327
|
+
);
|
|
328
|
+
});
|
|
329
|
+
out.push(...missingNewest("rss", paths, exp), ...exposure("rss", doc.body, paths, exp));
|
|
330
|
+
return out;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** Checks the site's sitemap. */
|
|
334
|
+
export function checkSitemap(
|
|
335
|
+
doc ,
|
|
336
|
+
exp ,
|
|
337
|
+
) {
|
|
338
|
+
const bad = documentProblems("sitemap", doc, /<urlset\b/);
|
|
339
|
+
if (bad || !doc) return bad ?? [];
|
|
340
|
+
const out = [];
|
|
341
|
+
const paths = new Set ();
|
|
342
|
+
blocks(doc.body, "url").forEach((url, n) => {
|
|
343
|
+
const loc = child(url, "loc");
|
|
344
|
+
if (!loc) {
|
|
345
|
+
out.push(
|
|
346
|
+
finding("sitemap", "feed-item-incomplete", "warning", {
|
|
347
|
+
detail: `url ${n + 1} has no loc`,
|
|
348
|
+
}),
|
|
349
|
+
);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const p = urlPath(loc);
|
|
353
|
+
if (p) paths.add(p);
|
|
354
|
+
const lastmod = child(url, "lastmod");
|
|
355
|
+
if (future(lastmod, exp.now))
|
|
356
|
+
out.push(
|
|
357
|
+
finding("sitemap", "feed-future-date", "warning", {
|
|
358
|
+
detail: `lastmod ${lastmod} is in the future`,
|
|
359
|
+
url: loc,
|
|
360
|
+
}),
|
|
361
|
+
);
|
|
362
|
+
});
|
|
363
|
+
out.push(...missingNewest("sitemap", paths, exp), ...exposure("sitemap", doc.body, paths, exp));
|
|
364
|
+
return out;
|
|
365
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Findings of the built-in jobs (RFC-0008 §4.5, §11.1): Studio-only JSON on the run row
|
|
3
|
+
* (`schedule_runs.findings`), at most 200 per run, each with a stable `code`. They are not a
|
|
4
|
+
* contract (no schema, no Rust mirror); the codes are, in the sense that Studio, the digest and
|
|
5
|
+
* the counts key on them, so a code is never renamed — a new meaning gets a new code.
|
|
6
|
+
*
|
|
7
|
+
* Text that came from visitors or from a fetched document (404 paths, feed contents) is marked
|
|
8
|
+
* `untrusted: true`: Studio renders it as plain text and agents receive it quoted (§11.4).
|
|
9
|
+
*/
|
|
10
|
+
/** At most this many findings are stored per run; `counts` stay exact (§4.5). */
|
|
11
|
+
export declare const MAX_FINDINGS_PER_RUN = 200;
|
|
12
|
+
/** `staleAfterDays` when the automation does not set one (§11.1). */
|
|
13
|
+
export declare const DEFAULT_STALE_AFTER_DAYS = 365;
|
|
14
|
+
/** How long runs (and with them their findings) are kept (§11.1 `cleanup`, §4.4). */
|
|
15
|
+
export declare const RUN_RETENTION_DAYS = 90;
|
|
16
|
+
/** How long terminal releases are kept (§5.2). */
|
|
17
|
+
export declare const RELEASE_RETENTION_DAYS = 400;
|
|
18
|
+
/** Drafts untouched this long get a reminder from `cleanup` (§11.1). */
|
|
19
|
+
export declare const STALE_DRAFT_DAYS = 90;
|
|
20
|
+
export type FindingSeverity = "error" | "warning" | "info";
|
|
21
|
+
/** Where in a node a reference was found: `body`, `coverImage`, `sections.<id>.body`, `items.<id>`… */
|
|
22
|
+
export type FindingField = string;
|
|
23
|
+
export declare const BROKEN_LINK_CODES: readonly [
|
|
24
|
+
/** An internal link in live content to a path nothing answers (page, entry, archive, redirect). */
|
|
25
|
+
"broken-internal-link",
|
|
26
|
+
/** `asset:<id>`, an image's `assetId` or a `/media/…` URL that is not a live asset. */
|
|
27
|
+
"broken-media-reference",
|
|
28
|
+
/** A live menu item whose page, entry or term is not live. */
|
|
29
|
+
"broken-menu-target",
|
|
30
|
+
/** A link to live content that is embargoed or expired right now (a 404 until its gate). */
|
|
31
|
+
"link-to-gated-content",
|
|
32
|
+
/** A top 404 path from analytics (visitor-supplied), with a redirect proposal when one fits. */
|
|
33
|
+
"not-found-path"];
|
|
34
|
+
export declare const STALE_CONTENT_CODES: readonly [
|
|
35
|
+
/** A live, published entry not updated for `staleAfterDays`. */
|
|
36
|
+
"stale-entry"];
|
|
37
|
+
export declare const FEED_CHECK_CODES: readonly [
|
|
38
|
+
/** The document could not be fetched or did not answer 200. */
|
|
39
|
+
"feed-unreachable",
|
|
40
|
+
/** Not well-formed XML, or not an RSS 2.0 channel / a sitemap `urlset`. */
|
|
41
|
+
"feed-invalid",
|
|
42
|
+
/** An RSS item without a title or a link, a sitemap URL without `loc`. */
|
|
43
|
+
"feed-item-incomplete",
|
|
44
|
+
/** A `pubDate` or `lastmod` in the future. */
|
|
45
|
+
"feed-future-date",
|
|
46
|
+
/** One of the newest published entries is missing. */
|
|
47
|
+
"feed-missing-entry",
|
|
48
|
+
/** The gate self-check (§7.2): an embargoed or expired node appears. Never expected. */
|
|
49
|
+
"feed-gated-node",
|
|
50
|
+
/** A `/media/…` URL in the feed that is not a live asset. */
|
|
51
|
+
"feed-asset-not-live"];
|
|
52
|
+
export declare const DIGEST_CODES: readonly ["digest-published", "digest-scheduled", "digest-attention", "digest-open-findings"];
|
|
53
|
+
export declare const CLEANUP_CODES: readonly [
|
|
54
|
+
/** A draft untouched for 90 days: a reminder, nothing is deleted (§11.1). */
|
|
55
|
+
"stale-draft"];
|
|
56
|
+
export type BrokenLinkCode = (typeof BROKEN_LINK_CODES)[number];
|
|
57
|
+
export type FeedCheckCode = (typeof FEED_CHECK_CODES)[number];
|
|
58
|
+
export type DigestCode = (typeof DIGEST_CODES)[number];
|
|
59
|
+
export type FindingCode = BrokenLinkCode | (typeof STALE_CONTENT_CODES)[number] | FeedCheckCode | DigestCode | (typeof CLEANUP_CODES)[number];
|
|
60
|
+
/** Every finding code, for Studio's word lists and tests. */
|
|
61
|
+
export declare const FINDING_CODES: readonly FindingCode[];
|
|
62
|
+
export type GateStateName = "embargoed" | "expired";
|
|
63
|
+
export type NodeKindName = "page" | "contentEntry" | "menu" | "term" | "taxonomy" | "redirect";
|
|
64
|
+
/** A reference in live content that resolves to nothing (or to gated content). */
|
|
65
|
+
export interface LinkFinding {
|
|
66
|
+
readonly code: "broken-internal-link" | "broken-media-reference" | "broken-menu-target" | "link-to-gated-content";
|
|
67
|
+
readonly severity: FindingSeverity;
|
|
68
|
+
/** The live node that holds the reference. */
|
|
69
|
+
readonly nodeId: string;
|
|
70
|
+
readonly nodeKind: NodeKindName;
|
|
71
|
+
readonly field: FindingField;
|
|
72
|
+
/** The reference as written (`/posts/x`, `asset:asset_…`, `/media/…`), or the menu target id. */
|
|
73
|
+
readonly href: string;
|
|
74
|
+
/** The node it points at, when known (gated content, a menu target). */
|
|
75
|
+
readonly targetId?: string;
|
|
76
|
+
readonly gate?: GateStateName;
|
|
77
|
+
}
|
|
78
|
+
/** A redirect a person can create with one click (RFC-0002), never created by the job. */
|
|
79
|
+
export interface RedirectProposal {
|
|
80
|
+
readonly path: string;
|
|
81
|
+
readonly nodeId?: string;
|
|
82
|
+
readonly reason: "redirect" | "similar";
|
|
83
|
+
}
|
|
84
|
+
export interface NotFoundFinding {
|
|
85
|
+
readonly code: "not-found-path";
|
|
86
|
+
readonly severity: FindingSeverity;
|
|
87
|
+
/** As requested: percent-encoded, visitor-controlled. */
|
|
88
|
+
readonly path: string;
|
|
89
|
+
readonly status: number;
|
|
90
|
+
readonly hits: number;
|
|
91
|
+
/** Same-site pages that linked here. */
|
|
92
|
+
readonly linkedFrom: readonly string[];
|
|
93
|
+
readonly lastSeen: string | null;
|
|
94
|
+
readonly proposal?: RedirectProposal;
|
|
95
|
+
readonly untrusted: true;
|
|
96
|
+
}
|
|
97
|
+
export interface StaleEntryFinding {
|
|
98
|
+
readonly code: "stale-entry";
|
|
99
|
+
readonly severity: FindingSeverity;
|
|
100
|
+
readonly nodeId: string;
|
|
101
|
+
readonly title: string;
|
|
102
|
+
readonly path: string;
|
|
103
|
+
readonly updatedAt: string;
|
|
104
|
+
readonly ageDays: number;
|
|
105
|
+
}
|
|
106
|
+
export interface FeedFinding {
|
|
107
|
+
readonly code: FeedCheckCode;
|
|
108
|
+
readonly severity: FindingSeverity;
|
|
109
|
+
readonly document: "rss" | "sitemap";
|
|
110
|
+
/** Short plain-text detail (may quote the fetched document: untrusted). */
|
|
111
|
+
readonly detail?: string;
|
|
112
|
+
readonly nodeId?: string;
|
|
113
|
+
readonly url?: string;
|
|
114
|
+
readonly untrusted: true;
|
|
115
|
+
}
|
|
116
|
+
export interface DigestFinding {
|
|
117
|
+
readonly code: DigestCode;
|
|
118
|
+
readonly severity: FindingSeverity;
|
|
119
|
+
readonly count: number;
|
|
120
|
+
readonly items: readonly DigestItem[];
|
|
121
|
+
}
|
|
122
|
+
export interface StaleDraftFinding {
|
|
123
|
+
readonly code: "stale-draft";
|
|
124
|
+
readonly severity: FindingSeverity;
|
|
125
|
+
readonly nodeId: string;
|
|
126
|
+
readonly nodeKind: "page" | "contentEntry";
|
|
127
|
+
readonly title: string;
|
|
128
|
+
readonly updatedAt: string;
|
|
129
|
+
readonly ageDays: number;
|
|
130
|
+
}
|
|
131
|
+
export type BuiltinFinding = LinkFinding | NotFoundFinding | StaleEntryFinding | FeedFinding | DigestFinding | StaleDraftFinding;
|
|
132
|
+
/** One line of a digest section: a release, an entry, an automation's open findings. */
|
|
133
|
+
export interface DigestItem {
|
|
134
|
+
/** `rel_…`, an entry or page id, or `aut_…`. */
|
|
135
|
+
readonly id: string;
|
|
136
|
+
readonly title: string;
|
|
137
|
+
/** The instant it happened or will happen. */
|
|
138
|
+
readonly at?: string;
|
|
139
|
+
/** Release state, gate (`embargo`), or the automation's job. */
|
|
140
|
+
readonly state?: string;
|
|
141
|
+
/** Open findings of an automation's latest run, by name. */
|
|
142
|
+
readonly counts?: Readonly<Record<string, number>>;
|
|
143
|
+
}
|
|
144
|
+
/** What the weekly digest reports (§11.1): templated, no language model. */
|
|
145
|
+
export interface WeeklyDigest {
|
|
146
|
+
readonly siteId: string;
|
|
147
|
+
/** The week reported: `[from, now)` back, `[now, to)` ahead. */
|
|
148
|
+
readonly from: string;
|
|
149
|
+
readonly now: string;
|
|
150
|
+
readonly to: string;
|
|
151
|
+
/** Entries first published in the week and releases that went live. */
|
|
152
|
+
readonly published: {
|
|
153
|
+
readonly count: number;
|
|
154
|
+
readonly items: readonly DigestItem[];
|
|
155
|
+
};
|
|
156
|
+
/** Releases due next week (scheduled or waiting for approval) and embargoes that lift. */
|
|
157
|
+
readonly scheduled: {
|
|
158
|
+
readonly count: number;
|
|
159
|
+
readonly items: readonly DigestItem[];
|
|
160
|
+
};
|
|
161
|
+
/** Releases missed, in conflict, failed or expired in the week, and nodes in two releases. */
|
|
162
|
+
readonly attention: {
|
|
163
|
+
readonly count: number;
|
|
164
|
+
readonly items: readonly DigestItem[];
|
|
165
|
+
};
|
|
166
|
+
/** The latest findings of the site's other built-in automations. */
|
|
167
|
+
readonly openFindings: {
|
|
168
|
+
readonly count: number;
|
|
169
|
+
readonly items: readonly DigestItem[];
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/** Items per digest section kept on the run (counts stay exact). */
|
|
173
|
+
export declare const DIGEST_ITEMS = 10;
|
|
174
|
+
/** Appends findings up to the cap; returns how many were dropped. */
|
|
175
|
+
export declare function addFindings(into: BuiltinFinding[], more: readonly BuiltinFinding[], max?: number): number;
|
|
176
|
+
/** Adds `n` to `counts[key]` (creating it), for exact counts beside capped findings. */
|
|
177
|
+
export declare function bump(counts: Record<string, number>, key: string, n?: number): void;
|
|
178
|
+
/** Counts of findings by code. */
|
|
179
|
+
export declare function countByCode(findings: readonly BuiltinFinding[]): Record<string, number>;
|
|
180
|
+
/** The counts keys that total a run's open findings (one per kind, no double counting). */
|
|
181
|
+
export declare const OPEN_FINDING_KEYS: readonly ["broken-links", "link-to-gated-content", "not-found-path", "stale-entries", "feed-problems", "stale-drafts"];
|
|
182
|
+
/** The open findings a built-in run's counts report, by the keys above (0 when none). */
|
|
183
|
+
export declare function openFindings(counts: Readonly<Record<string, number>>): Record<string, number>;
|
|
184
|
+
/** The digest as a plain-text report (the run's `summary` and the notification's text). */
|
|
185
|
+
export declare function digestSummary(d: WeeklyDigest): string;
|