meodp 0.0.9 → 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.
Files changed (61) hide show
  1. package/README.md +230 -21
  2. package/bin/index.mjs +10 -2
  3. package/dist/check/cli.cjs +257 -0
  4. package/dist/check/cli.d.cts +5 -0
  5. package/dist/check/cli.d.mts +5 -0
  6. package/dist/check/cli.d.ts +5 -0
  7. package/dist/check/cli.mjs +249 -0
  8. package/dist/check/index.cjs +29 -0
  9. package/dist/check/index.d.cts +44 -0
  10. package/dist/check/index.d.mts +44 -0
  11. package/dist/check/index.d.ts +44 -0
  12. package/dist/check/index.mjs +13 -0
  13. package/dist/cli/index.cjs +2 -2
  14. package/dist/cli/index.d.cts +1 -1
  15. package/dist/cli/index.d.mts +1 -1
  16. package/dist/cli/index.d.ts +1 -1
  17. package/dist/cli/index.mjs +2 -2
  18. package/dist/cli/main.cjs +272 -0
  19. package/dist/cli/main.d.cts +4 -0
  20. package/dist/cli/main.d.mts +4 -0
  21. package/dist/cli/main.d.ts +4 -0
  22. package/dist/cli/main.mjs +266 -0
  23. package/dist/config/index.cjs +7 -0
  24. package/dist/config/index.d.cts +47 -0
  25. package/dist/config/index.d.mts +47 -0
  26. package/dist/config/index.d.ts +47 -0
  27. package/dist/config/index.mjs +5 -0
  28. package/dist/notify/cli.cjs +107 -0
  29. package/dist/notify/cli.d.cts +3 -0
  30. package/dist/notify/cli.d.mts +3 -0
  31. package/dist/notify/cli.d.ts +3 -0
  32. package/dist/notify/cli.mjs +101 -0
  33. package/dist/notify/email.cjs +38 -0
  34. package/dist/notify/email.d.cts +29 -0
  35. package/dist/notify/email.d.mts +29 -0
  36. package/dist/notify/email.d.ts +29 -0
  37. package/dist/notify/email.mjs +35 -0
  38. package/dist/notify/feishu.cjs +162 -0
  39. package/dist/notify/feishu.d.cts +74 -0
  40. package/dist/notify/feishu.d.mts +74 -0
  41. package/dist/notify/feishu.d.ts +74 -0
  42. package/dist/notify/feishu.mjs +157 -0
  43. package/dist/notify/index.cjs +64 -0
  44. package/dist/notify/index.d.cts +27 -0
  45. package/dist/notify/index.d.mts +27 -0
  46. package/dist/notify/index.d.ts +27 -0
  47. package/dist/notify/index.mjs +62 -0
  48. package/dist/shared/meodp.2b00b0ae.cjs +228 -0
  49. package/dist/shared/meodp.4f1da070.d.cts +41 -0
  50. package/dist/shared/meodp.63483e20.cjs +30 -0
  51. package/dist/shared/meodp.80ff918d.mjs +465 -0
  52. package/dist/shared/meodp.8369c4c1.d.ts +41 -0
  53. package/dist/shared/meodp.93e06e00.d.cts +64 -0
  54. package/dist/shared/meodp.93e06e00.d.mts +64 -0
  55. package/dist/shared/meodp.93e06e00.d.ts +64 -0
  56. package/dist/shared/meodp.9c706389.mjs +220 -0
  57. package/dist/shared/meodp.a704f8db.d.mts +41 -0
  58. package/dist/shared/meodp.c4c70565.cjs +477 -0
  59. package/dist/shared/meodp.f96d0510.mjs +24 -0
  60. package/package.json +104 -31
  61. package/bin/index.ts +0 -6
@@ -0,0 +1,477 @@
1
+ 'use strict';
2
+
3
+ const promises = require('node:timers/promises');
4
+ const linkinator = require('linkinator');
5
+ const node_os = require('node:os');
6
+ const report = require('./meodp.2b00b0ae.cjs');
7
+ const promises$1 = require('node:fs/promises');
8
+ const path = require('node:path');
9
+ const process = require('node:process');
10
+ const node_buffer = require('node:buffer');
11
+ const node_util = require('node:util');
12
+ const node_zlib = require('node:zlib');
13
+ const fastXmlParser = require('fast-xml-parser');
14
+
15
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
16
+
17
+ const process__default = /*#__PURE__*/_interopDefaultCompat(process);
18
+
19
+ function normalizeUrl(value) {
20
+ const url = new URL(value);
21
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password)
22
+ throw new Error("Expected an HTTP(S) URL without embedded credentials");
23
+ url.hash = "";
24
+ return url.href;
25
+ }
26
+ function normalizeTargets(input) {
27
+ if (!Array.isArray(input))
28
+ throw new TypeError("Input must be an array of URLs or objects with a url field");
29
+ const seen = /* @__PURE__ */ new Set();
30
+ return input.map((item, index) => {
31
+ const value = typeof item === "string" ? { url: item } : item;
32
+ if (!value || typeof value !== "object" || !("url" in value) || typeof value.url !== "string")
33
+ throw new TypeError(`Invalid link at index ${index}: expected a url string`);
34
+ let url;
35
+ try {
36
+ url = normalizeUrl(value.url.trim());
37
+ } catch {
38
+ throw new TypeError(`Invalid HTTP(S) URL at index ${index}`);
39
+ }
40
+ if ("name" in value && value.name !== void 0 && typeof value.name !== "string")
41
+ throw new TypeError(`Invalid name at index ${index}: expected a string`);
42
+ return { url, ..."name" in value && typeof value.name === "string" ? { name: value.name } : {} };
43
+ }).filter((item) => {
44
+ if (seen.has(item.url))
45
+ return false;
46
+ seen.add(item.url);
47
+ return true;
48
+ });
49
+ }
50
+
51
+ function integerOption(value, fallback, name, minimum, maximum) {
52
+ const result = value ?? fallback;
53
+ if (!Number.isInteger(result) || result < minimum || result > maximum)
54
+ throw new RangeError(`${name} must be an integer between ${minimum} and ${maximum}`);
55
+ return result;
56
+ }
57
+ function normalizeCheckOptions(options) {
58
+ const concurrency = integerOption(options.concurrency, 5, "concurrency", 1, 100);
59
+ const timeoutMs = integerOption(options.timeoutMs, 1e4, "timeoutMs", 1, 3e5);
60
+ const retries = integerOption(options.retries, 1, "retries", 0, 5);
61
+ const maxRedirects = integerOption(options.maxRedirects, 5, "maxRedirects", 0, 20);
62
+ const observer = options.observer ?? node_os.hostname();
63
+ if (!observer.trim())
64
+ throw new TypeError("observer must not be empty");
65
+ if (options.previousReport && options.previousReport.observer !== observer)
66
+ throw new Error("Previous report belongs to another observer; use a separate history file");
67
+ return { concurrency, timeoutMs, retries, maxRedirects, observer };
68
+ }
69
+
70
+ function failureDetail(result) {
71
+ const error = result.failureDetails?.find((item) => item instanceof Error);
72
+ const parts = [];
73
+ let current = error;
74
+ for (let depth = 0; current && typeof current === "object" && depth < 5; depth++) {
75
+ for (const key of ["name", "code", "message"]) {
76
+ const value = Reflect.get(current, key);
77
+ if (typeof value === "string")
78
+ parts.push(value);
79
+ }
80
+ current = "cause" in current ? current.cause : void 0;
81
+ }
82
+ const detail = parts.join(": ") || `HTTP ${result.status ?? 0}`;
83
+ if (/ENOTFOUND|EAI_AGAIN|EAI_FAIL/.test(detail))
84
+ return { reason: "dns", detail };
85
+ if (/CERT|TLS|SSL/i.test(detail))
86
+ return { reason: "tls", detail };
87
+ if (/timeout|timed out|ETIMEDOUT|UND_ERR_.*TIMEOUT/i.test(detail))
88
+ return { reason: "timeout", detail };
89
+ return { reason: result.status ? "http" : "network", detail };
90
+ }
91
+ async function probe(url, timeoutMs, maxRedirects) {
92
+ const redirects = [];
93
+ const visited = /* @__PURE__ */ new Set();
94
+ let current = url;
95
+ for (; ; ) {
96
+ visited.add(current);
97
+ const checker = new linkinator.LinkChecker();
98
+ const { links } = await checker.check({
99
+ path: current,
100
+ recurse: false,
101
+ concurrency: 1,
102
+ timeout: timeoutMs,
103
+ retry: false,
104
+ retryErrors: false,
105
+ redirects: "error",
106
+ linksToSkip: async (candidate) => candidate !== current
107
+ });
108
+ const result = links.find((item) => item.url === current && !item.parent);
109
+ if (!result)
110
+ throw new Error("The HTTP checker returned no result for the requested URL");
111
+ const httpStatus = result.status || void 0;
112
+ const base = { finalUrl: current, httpStatus, redirects };
113
+ if (httpStatus && [301, 302, 303, 307, 308].includes(httpStatus)) {
114
+ const response = result.failureDetails?.find((item) => "headers" in item);
115
+ const location = response && "headers" in response ? response.headers.location : void 0;
116
+ let next;
117
+ try {
118
+ if (!location)
119
+ throw new Error("Missing redirect location");
120
+ next = normalizeUrl(new URL(location, current).href);
121
+ } catch {
122
+ return { ...base, status: "unavailable", reason: "redirect", detail: "Missing or invalid HTTP(S) redirect destination" };
123
+ }
124
+ redirects.push({ url: current, status: httpStatus, location: next });
125
+ if (visited.has(next) || redirects.length > maxRedirects) {
126
+ return {
127
+ ...base,
128
+ status: "unavailable",
129
+ reason: "redirect",
130
+ detail: visited.has(next) ? "Redirect loop" : "Redirect limit exceeded"
131
+ };
132
+ }
133
+ current = next;
134
+ continue;
135
+ }
136
+ if (httpStatus && httpStatus >= 200 && httpStatus < 300)
137
+ return { ...base, status: "reachable" };
138
+ if (httpStatus && [401, 403, 429, 451, 999].includes(httpStatus))
139
+ return { ...base, status: "restricted", reason: "http", detail: `HTTP ${httpStatus}: access requires review` };
140
+ return { ...base, status: "unavailable", ...failureDetail(result) };
141
+ }
142
+ }
143
+ async function checkLinks(input, options = {}) {
144
+ const targets = normalizeTargets(input);
145
+ const { concurrency, timeoutMs, retries, maxRedirects, observer } = normalizeCheckOptions(options);
146
+ const startedAt = (/* @__PURE__ */ new Date()).toISOString();
147
+ const previous = new Map(options.previousReport?.results.map((item) => [item.url, item]));
148
+ const results = [];
149
+ let cursor = 0;
150
+ await Promise.all(Array.from({ length: Math.min(concurrency, targets.length) }, async () => {
151
+ while (cursor < targets.length) {
152
+ const index = cursor++;
153
+ const target = targets[index];
154
+ const start = Date.now();
155
+ let attempts = 0;
156
+ let observation;
157
+ do {
158
+ if (attempts > 0)
159
+ await promises.setTimeout(500 * 2 ** (attempts - 1));
160
+ attempts++;
161
+ observation = await probe(target.url, timeoutMs, maxRedirects);
162
+ } while (attempts <= retries && observation.status === "unavailable" && observation.reason !== "redirect" && (!observation.httpStatus || observation.httpStatus >= 500));
163
+ const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
164
+ const old = previous.get(target.url);
165
+ const failed = observation.status === "unavailable";
166
+ const result = {
167
+ ...target,
168
+ ...observation,
169
+ checkedAt,
170
+ durationMs: Date.now() - start,
171
+ attempts,
172
+ consecutiveFailures: failed ? (old?.status === "unavailable" ? old.consecutiveFailures : 0) + 1 : 0,
173
+ firstFailureAt: failed ? old?.status === "unavailable" ? old.firstFailureAt ?? checkedAt : checkedAt : void 0,
174
+ lastSuccessAt: observation.status === "reachable" ? checkedAt : old?.lastSuccessAt,
175
+ changed: Boolean(old && (old.status !== observation.status || old.finalUrl !== observation.finalUrl)),
176
+ recovered: observation.status === "reachable" && old?.status === "unavailable"
177
+ };
178
+ results[index] = result;
179
+ await options.onResult?.(result);
180
+ }
181
+ }));
182
+ const summary = { total: results.length, reachable: 0, restricted: 0, unavailable: 0, redirected: 0, recovered: 0 };
183
+ for (const result of results) {
184
+ summary[result.status]++;
185
+ summary.redirected += Number(result.redirects.length > 0);
186
+ summary.recovered += Number(result.recovered);
187
+ }
188
+ return { schemaVersion: 1, observer, startedAt, completedAt: (/* @__PURE__ */ new Date()).toISOString(), summary, results };
189
+ }
190
+
191
+ function planReporters(config, options = {}) {
192
+ const entries = typeof config === "string" ? [config] : config;
193
+ if (!Array.isArray(entries))
194
+ throw new TypeError("reporter must be a name or an array of names / [name, options] tuples.");
195
+ const cwd = options.cwd ?? process__default.cwd();
196
+ const output = path.resolve(cwd, options.outputDir ?? "reports/meodp");
197
+ const path$1 = (value) => {
198
+ if (typeof value !== "string" || !value.trim() || value.includes("\0"))
199
+ throw new TypeError("Reporter output paths must be nonempty strings.");
200
+ return path.resolve(cwd, value);
201
+ };
202
+ const planned = entries.map((entry) => {
203
+ if (typeof entry !== "string" && (!Array.isArray(entry) || entry.length < 1 || entry.length > 2))
204
+ throw new TypeError("Each reporter must be a name or [name, options] tuple.");
205
+ const [name, settings = {}] = typeof entry === "string" ? [entry] : entry;
206
+ if (!["json", "markdown", "html"].includes(name))
207
+ throw new TypeError(`Unknown reporter ${JSON.stringify(name)}; use json, markdown, or html.`);
208
+ if (!settings || typeof settings !== "object" || Array.isArray(settings))
209
+ throw new TypeError("Reporter options must be an object.");
210
+ const allowed = name === "html" ? ["outputFile", "outputFolder", "dataUrl"] : ["outputFile"];
211
+ for (const key of Object.keys(settings)) {
212
+ if (!allowed.includes(key))
213
+ throw new TypeError(`Unknown ${name} reporter option: ${key}`);
214
+ }
215
+ const file = "outputFile" in settings && settings.outputFile !== void 0 ? path$1(settings.outputFile) : void 0;
216
+ if (name !== "html")
217
+ return { reporter: name, file: file ?? path.join(output, name === "json" ? "report.json" : "report.md") };
218
+ const folder = "outputFolder" in settings && settings.outputFolder !== void 0 ? path$1(settings.outputFolder) : void 0;
219
+ if (file && folder)
220
+ throw new TypeError("HTML reporter accepts either outputFile or outputFolder, not both.");
221
+ const dataUrl = ("dataUrl" in settings ? settings.dataUrl : void 0) ?? options.dataUrl;
222
+ if (dataUrl !== void 0 && typeof dataUrl !== "string")
223
+ throw new TypeError("HTML reporter dataUrl must be a string.");
224
+ if (dataUrl !== void 0)
225
+ report.createReportHtml(void 0, { dataUrl });
226
+ return { reporter: name, file: file ?? path.join(folder ?? output, "index.html"), json: file ? void 0 : path.join(folder ?? output, "report.json"), dataUrl };
227
+ });
228
+ const outputs = /* @__PURE__ */ new Map();
229
+ for (const item of planned) {
230
+ for (const [file, kind] of [[item.file, item.reporter], [item.json, "json"]]) {
231
+ if (!file)
232
+ continue;
233
+ const existing = outputs.get(file);
234
+ if (existing && (existing !== "json" || kind !== "json"))
235
+ throw new TypeError(`Reporter outputs collide at ${file}`);
236
+ outputs.set(file, kind);
237
+ }
238
+ }
239
+ for (const file of outputs.keys()) {
240
+ let parent = path.dirname(file);
241
+ while (parent !== path.dirname(parent)) {
242
+ if (outputs.has(parent))
243
+ throw new TypeError(`Reporter output is also used as a directory: ${parent}`);
244
+ parent = path.dirname(parent);
245
+ }
246
+ }
247
+ return planned;
248
+ }
249
+ async function writeReporters(report$1, reporter, options = {}) {
250
+ const plan = planReporters(reporter, options);
251
+ if (report$1)
252
+ report$1 = report.parseReport(report$1);
253
+ if (!report$1 && plan.some((item) => item.reporter !== "html"))
254
+ throw new TypeError("JSON and Markdown reporters require an input report.");
255
+ const writes = /* @__PURE__ */ new Map();
256
+ const outputs = plan.map((item) => {
257
+ const files = [item.file];
258
+ if (item.reporter === "html") {
259
+ writes.set(item.file, report.createReportHtml(report$1, { dataUrl: item.dataUrl ?? (report$1 && item.json ? "./report.json" : void 0) }));
260
+ if (report$1 && item.json) {
261
+ writes.set(item.json, report.formatReport(report$1, "json"));
262
+ files.push(item.json);
263
+ }
264
+ } else {
265
+ writes.set(item.file, report.formatReport(report$1, item.reporter));
266
+ }
267
+ return { reporter: item.reporter, files };
268
+ });
269
+ for (const [file, content] of writes) {
270
+ await promises$1.mkdir(path.dirname(file), { recursive: true });
271
+ await promises$1.writeFile(file, content);
272
+ }
273
+ return outputs;
274
+ }
275
+
276
+ const unzip = node_util.promisify(node_zlib.gunzip);
277
+ class DocumentError extends Error {
278
+ constructor(message, retryable = false) {
279
+ super(message);
280
+ this.retryable = retryable;
281
+ }
282
+ }
283
+ function discoveryOptions(options) {
284
+ const normalized = normalizeCheckOptions(options);
285
+ if (options.discover !== void 0 && typeof options.discover !== "boolean")
286
+ throw new TypeError("discover must be a boolean");
287
+ return {
288
+ ...normalized,
289
+ maxUrls: integerOption(options.maxUrls, 1e4, "maxUrls", 1, 5e4),
290
+ maxSitemaps: integerOption(options.maxSitemaps, 100, "maxSitemaps", 1, 1e4),
291
+ maxSitemapBytes: integerOption(options.maxSitemapBytes, 10 * 1024 * 1024, "maxSitemapBytes", 1, 100 * 1024 * 1024)
292
+ };
293
+ }
294
+ async function readDocument(source, options, allowMissing = false) {
295
+ for (let attempt = 0; ; attempt++) {
296
+ try {
297
+ let url = source;
298
+ const visited = /* @__PURE__ */ new Set();
299
+ for (; ; ) {
300
+ visited.add(url);
301
+ const response = await fetch(url, {
302
+ redirect: "manual",
303
+ signal: AbortSignal.timeout(options.timeoutMs)
304
+ });
305
+ if ([301, 302, 303, 307, 308].includes(response.status)) {
306
+ await response.body?.cancel();
307
+ const location = response.headers.get("location");
308
+ let next;
309
+ try {
310
+ if (!location)
311
+ throw new Error("Missing location");
312
+ next = normalizeUrl(new URL(location, url).href);
313
+ } catch {
314
+ throw new DocumentError(`Invalid sitemap/robots redirect from ${url}`);
315
+ }
316
+ if (visited.has(next) || visited.size > options.maxRedirects)
317
+ throw new DocumentError(`Sitemap/robots redirect loop or limit exceeded: ${url}`);
318
+ url = next;
319
+ continue;
320
+ }
321
+ if (!response.ok) {
322
+ await response.body?.cancel();
323
+ if (allowMissing && [404, 410].includes(response.status))
324
+ return void 0;
325
+ throw new DocumentError(`Unable to read ${url}: HTTP ${response.status}`, response.status >= 500);
326
+ }
327
+ const chunks = [];
328
+ let size = 0;
329
+ if (response.body) {
330
+ const reader = response.body.getReader();
331
+ try {
332
+ for (; ; ) {
333
+ const { done, value } = await reader.read();
334
+ if (done)
335
+ break;
336
+ size += value.byteLength;
337
+ if (size > options.maxSitemapBytes)
338
+ throw new DocumentError(`Discovery document exceeds maxSitemapBytes: ${url}`);
339
+ chunks.push(value);
340
+ }
341
+ } finally {
342
+ await reader.cancel().catch(() => {
343
+ });
344
+ reader.releaseLock();
345
+ }
346
+ }
347
+ let body = node_buffer.Buffer.concat(chunks);
348
+ if (body[0] === 31 && body[1] === 139) {
349
+ try {
350
+ body = await unzip(body, { maxOutputLength: options.maxSitemapBytes });
351
+ } catch {
352
+ throw new DocumentError(`Invalid gzip or decompressed document exceeds maxSitemapBytes: ${url}`);
353
+ }
354
+ }
355
+ return { url, text: body.toString("utf8") };
356
+ }
357
+ } catch (error) {
358
+ if (attempt >= options.retries || error instanceof DocumentError && !error.retryable)
359
+ throw new Error(`Sitemap discovery failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
360
+ await promises.setTimeout(500 * 2 ** attempt);
361
+ }
362
+ }
363
+ }
364
+ function parseLocations(text, source) {
365
+ if (/<!DOCTYPE|<!ENTITY/i.test(text) || fastXmlParser.XMLValidator.validate(text) !== true)
366
+ throw new Error(`Invalid sitemap XML: ${source}`);
367
+ const parser = new fastXmlParser.XMLParser({
368
+ ignoreAttributes: true,
369
+ removeNSPrefix: true,
370
+ parseTagValue: false,
371
+ isArray: (name) => name === "url" || name === "sitemap"
372
+ });
373
+ const document = parser.parse(text);
374
+ const roots = Object.keys(document).filter((key) => !key.startsWith("?"));
375
+ if (roots.length !== 1 || !["urlset", "sitemapindex"].includes(roots[0]))
376
+ throw new Error(`Expected a sitemap urlset or sitemapindex: ${source}`);
377
+ const isIndex = roots[0] === "sitemapindex";
378
+ const root = document[roots[0]];
379
+ if (root?.[isIndex ? "url" : "sitemap"])
380
+ throw new Error(`Mixed sitemap index and page entries: ${source}`);
381
+ const entries = root?.[isIndex ? "sitemap" : "url"] ?? [];
382
+ const urls = entries.map((entry) => {
383
+ if (!entry || typeof entry !== "object" || !("loc" in entry) || typeof entry.loc !== "string" || !entry.loc.trim())
384
+ throw new Error(`Missing or invalid sitemap loc: ${source}`);
385
+ try {
386
+ return normalizeUrl(new URL(entry.loc.trim(), source).href);
387
+ } catch {
388
+ throw new Error(`Invalid HTTP(S) URL in sitemap: ${source}`);
389
+ }
390
+ });
391
+ return { isIndex, urls };
392
+ }
393
+ async function readSitemapUrls(source, options = {}) {
394
+ const input = normalizeUrl(source.trim());
395
+ const config = discoveryOptions(options);
396
+ let pending = [input];
397
+ if (options.discover) {
398
+ const robots = await readDocument(new URL("/robots.txt", input).href, config, true);
399
+ const declared = robots?.text.split(/\r?\n/).flatMap((line) => {
400
+ const match = line.match(/^\s*sitemap\s*:\s*(\S+)/i);
401
+ return match ? [normalizeUrl(new URL(match[1], robots.url).href)] : [];
402
+ }) ?? [];
403
+ pending = declared.length ? declared : [new URL("/sitemap.xml", input).href];
404
+ }
405
+ const queued = new Set(pending);
406
+ pending = [...queued];
407
+ const visited = /* @__PURE__ */ new Set();
408
+ const pages = /* @__PURE__ */ new Set();
409
+ let documentCount = 0;
410
+ for (let cursor = 0; cursor < pending.length; cursor++) {
411
+ const url = pending[cursor];
412
+ if (visited.has(url))
413
+ continue;
414
+ if (++documentCount > config.maxSitemaps)
415
+ throw new Error("Sitemap discovery exceeds maxSitemaps; no pages were checked");
416
+ visited.add(url);
417
+ const document = await readDocument(url, config);
418
+ if (!document)
419
+ throw new Error(`Unable to read sitemap: ${url}`);
420
+ visited.add(document.url);
421
+ const { isIndex, urls } = parseLocations(document.text, document.url);
422
+ for (const location of urls) {
423
+ if (isIndex) {
424
+ if (!queued.has(location) && !visited.has(location)) {
425
+ queued.add(location);
426
+ pending.push(location);
427
+ }
428
+ } else {
429
+ pages.add(location);
430
+ if (pages.size > config.maxUrls)
431
+ throw new Error("Sitemap discovery exceeds maxUrls; no pages were checked");
432
+ }
433
+ }
434
+ }
435
+ if (!pages.size)
436
+ throw new Error("Sitemap discovery found no page URLs; no pages were checked");
437
+ return [...pages];
438
+ }
439
+ async function checkSitemap(source, options = {}) {
440
+ const startedAt = (/* @__PURE__ */ new Date()).toISOString();
441
+ const urls = await readSitemapUrls(source, options);
442
+ const report = await checkLinks(urls, options);
443
+ return { ...report, startedAt };
444
+ }
445
+
446
+ async function waitForReport(expected, { url, attempts = 12, delayMs = 15e3 }) {
447
+ if (!Number.isSafeInteger(attempts) || attempts < 1 || attempts > 120 || !Number.isFinite(delayMs) || delayMs < 0 || delayMs > 3e5)
448
+ throw new Error("Invalid report verification retry options.");
449
+ const reportUrl = new URL(url);
450
+ if (!["https:", "http:"].includes(reportUrl.protocol) || reportUrl.username || reportUrl.password)
451
+ throw new Error("Report verification requires an HTTP(S) URL without credentials.");
452
+ reportUrl.searchParams.set("observation", expected.completedAt);
453
+ const expectedJson = JSON.stringify(report.parseReport(expected));
454
+ for (let attempt = 0; attempt < attempts; attempt++) {
455
+ try {
456
+ const options = { cache: "no-store", signal: AbortSignal.timeout(1e4) };
457
+ const response = await fetch(reportUrl, options);
458
+ if (response.ok && JSON.stringify(report.parseReport(await response.json())) === expectedJson) {
459
+ const page = await fetch(new URL("./", url), { cache: "no-store", signal: AbortSignal.timeout(1e4) });
460
+ if (page.ok && (await page.text()).includes('id="meodp-data"'))
461
+ return;
462
+ }
463
+ } catch {
464
+ }
465
+ if (attempt + 1 < attempts)
466
+ await promises.setTimeout(delayMs);
467
+ }
468
+ throw new Error("The public status page did not serve this report in time. Check the hosting deployment; saved report files remain available.");
469
+ }
470
+
471
+ exports.checkLinks = checkLinks;
472
+ exports.checkSitemap = checkSitemap;
473
+ exports.normalizeTargets = normalizeTargets;
474
+ exports.planReporters = planReporters;
475
+ exports.readSitemapUrls = readSitemapUrls;
476
+ exports.waitForReport = waitForReport;
477
+ exports.writeReporters = writeReporters;
@@ -0,0 +1,24 @@
1
+ import { access } from 'node:fs/promises';
2
+ import { resolve, dirname } from 'node:path';
3
+ import process from 'node:process';
4
+ import { loadConfig } from 'c12';
5
+
6
+ async function loadProjectConfig(file) {
7
+ if (file)
8
+ await access(resolve(file));
9
+ const { config, configFile } = await loadConfig({
10
+ name: "meodp",
11
+ cwd: process.cwd(),
12
+ configFile: file ? resolve(file) : void 0,
13
+ rcFile: false,
14
+ globalRc: false,
15
+ dotenv: false,
16
+ packageJson: false,
17
+ extend: false,
18
+ giget: false
19
+ });
20
+ const root = configFile ? dirname(configFile) : process.cwd();
21
+ return { config, path: (value) => resolve(root, value) };
22
+ }
23
+
24
+ export { loadProjectConfig as l };