@naosystem/cf-workers-status-page 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 +21 -0
- package/README.md +38 -2
- package/dist/admin.html +17 -0
- package/dist/auth-cloudflare-access.js +304 -0
- package/dist/auth-cloudflare-access.js.map +1 -0
- package/dist/chunks/monitor-B2u42off.js +79 -0
- package/dist/chunks/monitor-B2u42off.js.map +1 -0
- package/dist/chunks/notifier-DODVuFhr.js +158 -0
- package/dist/chunks/notifier-DODVuFhr.js.map +1 -0
- package/dist/chunks/page-templates-DPZcMlic.js +71 -0
- package/dist/chunks/page-templates-DPZcMlic.js.map +1 -0
- package/dist/chunks/run-check-bbo3LqI7.js +235 -0
- package/dist/chunks/run-check-bbo3LqI7.js.map +1 -0
- package/dist/chunks/timeline-YJXjehRf.js +1081 -0
- package/dist/chunks/timeline-YJXjehRf.js.map +1 -0
- package/dist/client/_headers +10 -0
- package/dist/client/assets/admin-BBJxKTF6.js +1 -0
- package/dist/client/assets/admin-Be4X0WFj.css +1 -0
- package/dist/client/assets/index-BgOspfsy.js +2 -0
- package/dist/client/assets/index-xpKyzvog.css +1 -0
- package/dist/client/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
- package/dist/client/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
- package/dist/client/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
- package/dist/client/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
- package/dist/client/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
- package/dist/client/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
- package/dist/client/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
- package/dist/client/assets/ja-BT5brvxP.js +1 -0
- package/dist/client/assets/ja-DSSblLff.js +1 -0
- package/dist/client/assets/noto-sans-jp-0-wght-normal-vN5ykBQF.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-1-wght-normal-N_EDDt8j.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-10-wght-normal-ChuiXes4.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-100-wght-normal-CrE4HD6k.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-101-wght-normal-DOqEZFXR.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-102-wght-normal-2gFz4V6e.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-103-wght-normal-D9RhXU-z.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-104-wght-normal-OIyZ9iQD.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-105-wght-normal-CqRQAfnb.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-106-wght-normal-D-PO3jqS.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-107-wght-normal-DrykTIAp.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-108-wght-normal-DijBe27A.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-109-wght-normal-DaJwqT__.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-11-wght-normal-DdkFqF_o.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-110-wght-normal-bhh2FQQH.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-111-wght-normal-CuGzYIdC.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-112-wght-normal-DdhK_1vk.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-113-wght-normal-hxVHS2d4.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-114-wght-normal-DUzjAsrP.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-115-wght-normal-BiZ4-5rz.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-116-wght-normal-DkZAcxAY.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-117-wght-normal-CLJPD2y0.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-118-wght-normal-D8DI_HXJ.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-119-wght-normal-BAB3pFaH.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-12-wght-normal-K36fA5_o.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-13-wght-normal-BnYizWno.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-14-wght-normal-BP4IgVC-.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-15-wght-normal-DyhWcoYF.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-16-wght-normal-CXsQLI2j.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-17-wght-normal-C8FU1ZJ4.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-18-wght-normal-Cl0IKBVh.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-19-wght-normal-D3D3JUJm.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-2-wght-normal-CGu8NhtQ.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-20-wght-normal-DxsoeWSt.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-21-wght-normal-CuNsexW5.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-22-wght-normal-DVX3OFQM.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-23-wght-normal-BPFuo_yH.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-24-wght-normal-D85Fj66x.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-25-wght-normal-DdOOVuSz.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-26-wght-normal-BRB1GnUq.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-27-wght-normal-BxZFF8JU.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-28-wght-normal-VUlviaYI.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-29-wght-normal-CalQqRwB.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-3-wght-normal-cncaCaM8.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-30-wght-normal-CHLg85G9.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-31-wght-normal-BUoF9dl9.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-32-wght-normal-C5ZTiBNw.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-33-wght-normal-C6XNJsfA.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-34-wght-normal-DHkM837w.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-35-wght-normal-QMtEjDIl.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-36-wght-normal-CUyF0GqZ.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-37-wght-normal-EORmNjxA.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-38-wght-normal-C8ERbMNG.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-39-wght-normal-ChUfpJbl.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-4-wght-normal-DtWqs3EP.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-40-wght-normal-MgP8JEEE.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-41-wght-normal-3ctF9abM.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-42-wght-normal-CQtg6UZe.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-43-wght-normal-D1Pmm9aG.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-44-wght-normal-Cp9dHeXI.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-45-wght-normal-D2b1osBj.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-46-wght-normal-CGIA-Vlo.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-47-wght-normal-C4EEGqDS.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-48-wght-normal-D2iBztXa.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-49-wght-normal-DxqRVik_.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-5-wght-normal-CFiyVtll.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-50-wght-normal-CMseszwo.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-51-wght-normal-Cqc-9wfi.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-52-wght-normal-BVLZTbqC.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-53-wght-normal-DTyNOJaY.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-54-wght-normal-_mxGq_et.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-55-wght-normal-Bvndync8.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-56-wght-normal-0MmMqroR.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-57-wght-normal-BdRnjDYs.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-58-wght-normal-BYGgVeN_.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-59-wght-normal-Bdv8mdje.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-6-wght-normal-M-pWkj3J.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-60-wght-normal-DC6FEqsM.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-61-wght-normal-CYIuK5Lr.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-62-wght-normal-DeHy8p7w.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-63-wght-normal-B4M6eMmD.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-64-wght-normal-DLyOXBrC.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-65-wght-normal-X7SsA1bs.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-66-wght-normal-VScDM-_N.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-67-wght-normal-Dg2D3DZB.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-68-wght-normal-BB0AR8UN.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-69-wght-normal-CucwpUnQ.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-7-wght-normal-DzOz8Ryd.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-70-wght-normal-BZId6-Tb.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-71-wght-normal-CzPU0NF7.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-72-wght-normal-DrNRYXnT.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-73-wght-normal-DF2BdR6a.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-74-wght-normal-BMlOw_5y.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-75-wght-normal-DKq84hLG.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-76-wght-normal-CTb-2MFr.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-77-wght-normal-DfIVi-wf.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-78-wght-normal-_-z1Vrir.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-79-wght-normal-D8kGlXda.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-8-wght-normal-BfWoBb3q.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-80-wght-normal-BOEztZwY.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-81-wght-normal-h5VC8QpU.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-82-wght-normal-DJ4QkvX0.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-83-wght-normal-DANtuAZG.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-84-wght-normal-DjZ8Sp6m.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-85-wght-normal-kpU7kbMF.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-86-wght-normal-DRPTa-bf.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-87-wght-normal-CFM472wD.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-88-wght-normal-2rLLwelj.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-89-wght-normal-DUIF9ybW.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-9-wght-normal-WLs1HgG6.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-90-wght-normal-B0n_tL-y.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-91-wght-normal-BishDeFy.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-92-wght-normal-DoIdukLp.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-93-wght-normal-DMCycan_.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-94-wght-normal-DlyoTk-A.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-95-wght-normal-D0L1aiGf.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-96-wght-normal-CjJ0kYkQ.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-97-wght-normal-CJ8uP04H.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-98-wght-normal-CjEDrQIY.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-99-wght-normal-DaQ3GEVf.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-cyrillic-wght-normal-BbS1Q_ZO.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-latin-ext-wght-normal-IaSo_s9d.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-latin-wght-normal-Bnnzbixe.woff2 +0 -0
- package/dist/client/assets/noto-sans-jp-vietnamese-wght-normal-CjvP4Ahz.woff2 +0 -0
- package/dist/client/assets/src-BDi4qpij.js +9 -0
- package/dist/client/assets/src-C6ZFz-Gu.css +1 -0
- package/dist/client/assets/views-CSeX_2-u.css +1 -0
- package/dist/client/assets/views-DHTTEaNV.js +1 -0
- package/dist/client/index.html +15 -0
- package/dist/client/licenses/fonts.txt +104 -0
- package/dist/client/licenses/third-party.txt +349 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/notifier-discord.js +153 -0
- package/dist/notifier-discord.js.map +1 -0
- package/dist/notifier-slack.js +98 -0
- package/dist/notifier-slack.js.map +1 -0
- package/dist/notifier-webhook.js +215 -0
- package/dist/notifier-webhook.js.map +1 -0
- package/dist/provider-http.js +177 -0
- package/dist/provider-http.js.map +1 -0
- package/dist/vite.js +224 -0
- package/dist/vite.js.map +1 -0
- package/dist/worker.js +8616 -0
- package/dist/worker.js.map +1 -0
- package/package.json +58 -5
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { a as optionKeys } from "./monitor-B2u42off.js";
|
|
2
|
+
// ../core/src/notifier.ts
|
|
3
|
+
/**
|
|
4
|
+
* What a notification is about. Targets choose which of these they receive:
|
|
5
|
+
* - `down`: `down` was confirmed (on by default);
|
|
6
|
+
* - `recovered`: the monitor left `down` (on by default);
|
|
7
|
+
* - `degraded`: `degraded` was confirmed, from `up` or before any state (off by default);
|
|
8
|
+
* - `degraded_recovered`: the monitor went from `degraded` back to `up` (off by default);
|
|
9
|
+
* - `unknown`: results stopped arriving; only targets marked as administrators' get it.
|
|
10
|
+
*/
|
|
11
|
+
var NOTIFICATION_EVENTS = [
|
|
12
|
+
"down",
|
|
13
|
+
"recovered",
|
|
14
|
+
"degraded",
|
|
15
|
+
"degraded_recovered",
|
|
16
|
+
"unknown"
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* A delivery failed. `retryable` says whether trying again later may help (a timeout, a rate
|
|
20
|
+
* limit, a server error) or not (the webhook was deleted, the payload was refused): the hub
|
|
21
|
+
* then retries with backoff or records the failure at once.
|
|
22
|
+
*
|
|
23
|
+
* Messages must never contain secret options (a webhook URL, a signing secret); the hub also
|
|
24
|
+
* redacts them before it logs or stores a message.
|
|
25
|
+
*/
|
|
26
|
+
var NotifierError = class extends Error {
|
|
27
|
+
name = "NotifierError";
|
|
28
|
+
retryable;
|
|
29
|
+
/** How long the service asked to wait (`Retry-After`), if it did. */
|
|
30
|
+
retryAfterMs;
|
|
31
|
+
/** The HTTP status, when the service answered. */
|
|
32
|
+
status;
|
|
33
|
+
constructor(message, options) {
|
|
34
|
+
super(message);
|
|
35
|
+
this.retryable = options.retryable;
|
|
36
|
+
this.retryAfterMs = options.retryAfterMs;
|
|
37
|
+
this.status = options.status;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/** Longest part of a service's error response kept in a {@link NotifierError} message. */
|
|
41
|
+
var ERROR_BODY_CHARS = 200;
|
|
42
|
+
/** Bytes of an error response read at most (a little more than the characters kept, for multi-byte text). */
|
|
43
|
+
var ERROR_BODY_BYTES = 1024;
|
|
44
|
+
/** The start of `response`'s body as text, reading at most {@link ERROR_BODY_BYTES} bytes, then cancelling the rest. */
|
|
45
|
+
async function bodyStart(response) {
|
|
46
|
+
const reader = response.body?.getReader();
|
|
47
|
+
if (reader === void 0) return "";
|
|
48
|
+
const chunks = [];
|
|
49
|
+
let size = 0;
|
|
50
|
+
try {
|
|
51
|
+
while (size < ERROR_BODY_BYTES) {
|
|
52
|
+
const { done, value } = await reader.read();
|
|
53
|
+
if (done) break;
|
|
54
|
+
chunks.push(value);
|
|
55
|
+
size += value.byteLength;
|
|
56
|
+
}
|
|
57
|
+
} finally {
|
|
58
|
+
await reader.cancel().catch(() => {});
|
|
59
|
+
}
|
|
60
|
+
const bytes = new Uint8Array(Math.min(size, ERROR_BODY_BYTES));
|
|
61
|
+
let offset = 0;
|
|
62
|
+
for (const chunk of chunks) {
|
|
63
|
+
const part = chunk.subarray(0, bytes.length - offset);
|
|
64
|
+
bytes.set(part, offset);
|
|
65
|
+
offset += part.length;
|
|
66
|
+
if (offset >= bytes.length) break;
|
|
67
|
+
}
|
|
68
|
+
return new TextDecoder().decode(bytes).replace(/\uFFFD+$/, "");
|
|
69
|
+
}
|
|
70
|
+
/** Milliseconds from a `Retry-After` header (seconds or an HTTP date), if it has one. */
|
|
71
|
+
function retryAfterMs(response, now = Date.now()) {
|
|
72
|
+
const value = response.headers.get("Retry-After");
|
|
73
|
+
if (value === null) return void 0;
|
|
74
|
+
const seconds = Number(value);
|
|
75
|
+
if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
|
|
76
|
+
const date = Date.parse(value);
|
|
77
|
+
return Number.isNaN(date) ? void 0 : Math.max(0, date - now);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Throws a {@link NotifierError} unless `response` is successful (2xx). 408, 429 and 5xx are
|
|
81
|
+
* retryable; other statuses are not (the request itself is wrong, or the webhook is gone).
|
|
82
|
+
* The message names `service`, the status and the start of the response body (services such
|
|
83
|
+
* as Slack explain the error there); it never includes the request URL.
|
|
84
|
+
*/
|
|
85
|
+
async function expectSuccess(response, service) {
|
|
86
|
+
if (response.ok) {
|
|
87
|
+
await response.body?.cancel();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
let body = "";
|
|
91
|
+
try {
|
|
92
|
+
body = (await bodyStart(response)).trim().slice(0, ERROR_BODY_CHARS);
|
|
93
|
+
} catch {}
|
|
94
|
+
const { status } = response;
|
|
95
|
+
throw new NotifierError(`${service} answered HTTP ${status}${body === "" ? "" : `: ${body}`}`, {
|
|
96
|
+
retryable: status === 408 || status === 429 || status >= 500,
|
|
97
|
+
retryAfterMs: retryAfterMs(response),
|
|
98
|
+
status
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
var NOTIFIER_TYPE = /^[a-z][a-z0-9-]{0,31}$/;
|
|
102
|
+
var MESSAGE_KEY = /^(?:\$kind|(.+)\.(?:title|description))$/;
|
|
103
|
+
/**
|
|
104
|
+
* Declares a notifier kind, checking that its options are an object schema and that every
|
|
105
|
+
* key in `secretOptions` is one of its options.
|
|
106
|
+
* @throws TypeError otherwise.
|
|
107
|
+
*/
|
|
108
|
+
function defineNotifier(kind) {
|
|
109
|
+
if (!NOTIFIER_TYPE.test(kind.type)) throw new TypeError(`Notifier "${kind.type}": type must be lowercase letters, digits and "-", starting with a letter`);
|
|
110
|
+
const keys = optionKeys(kind.options);
|
|
111
|
+
if (keys === void 0) throw new TypeError(`Notifier "${kind.type}": options must be an object schema`);
|
|
112
|
+
if (kind.destinationOption !== void 0 && !keys.includes(kind.destinationOption)) throw new TypeError(`Notifier "${kind.type}": destinationOption "${kind.destinationOption}" is not an option`);
|
|
113
|
+
const unknown = kind.secretOptions.filter((key) => !keys.includes(key));
|
|
114
|
+
if (unknown.length > 0) throw new TypeError(`Notifier "${kind.type}": secretOptions ${unknown.map((key) => `"${key}"`).join(", ")} are not options`);
|
|
115
|
+
for (const [language, messages] of Object.entries(kind.messages ?? {})) for (const key of Object.keys(messages)) {
|
|
116
|
+
const match = MESSAGE_KEY.exec(key);
|
|
117
|
+
if (match === null || match[1] !== void 0 && !keys.includes(match[1])) throw new TypeError(`Notifier "${kind.type}": message "${key}" (${language}) is not "$kind" or "<option>.title|description"`);
|
|
118
|
+
}
|
|
119
|
+
return kind;
|
|
120
|
+
}
|
|
121
|
+
/** The option of `kind` that holds where it sends notifications (see {@link NotifierKind.destinationOption}), if any. */
|
|
122
|
+
function destinationOptionOf(kind) {
|
|
123
|
+
if (kind.destinationOption !== void 0) return kind.destinationOption;
|
|
124
|
+
return optionKeys(kind.options)?.includes("url") ? "url" : void 0;
|
|
125
|
+
}
|
|
126
|
+
var IPV4 = /^\d{1,3}(?:\.\d{1,3}){3}$/;
|
|
127
|
+
/** Suffixes of names that only resolve inside a network (RFC 6761, 6762, 8375 and common practice). */
|
|
128
|
+
var INTERNAL_SUFFIXES = [
|
|
129
|
+
".localhost",
|
|
130
|
+
".local",
|
|
131
|
+
".internal",
|
|
132
|
+
".intranet",
|
|
133
|
+
".lan",
|
|
134
|
+
".home",
|
|
135
|
+
".corp",
|
|
136
|
+
".private",
|
|
137
|
+
".home.arpa",
|
|
138
|
+
".localdomain",
|
|
139
|
+
".test",
|
|
140
|
+
".invalid",
|
|
141
|
+
".example",
|
|
142
|
+
".onion"
|
|
143
|
+
];
|
|
144
|
+
/**
|
|
145
|
+
* Whether `hostname` (as `URL.hostname` gives it) names a host on the public internet: not an
|
|
146
|
+
* IP address literal (which the WHATWG URL parser also makes of forms such as `0x7f.1`), not a
|
|
147
|
+
* single label such as `localhost` or `intranet`, and not under a suffix that only resolves
|
|
148
|
+
* inside a network (`.local`, `.internal`, `.home.arpa`, …). Notification targets must name one,
|
|
149
|
+
* so that an administrator cannot point the hub at addresses it should not reach.
|
|
150
|
+
*/
|
|
151
|
+
function isPublicHostname(hostname) {
|
|
152
|
+
const name = hostname.toLowerCase().replace(/\.$/, "");
|
|
153
|
+
if (name === "" || name.startsWith("[") || IPV4.test(name) || !name.includes(".")) return false;
|
|
154
|
+
return !INTERNAL_SUFFIXES.some((suffix) => name.endsWith(suffix));
|
|
155
|
+
}
|
|
156
|
+
export { expectSuccess as a, destinationOptionOf as i, NotifierError as n, isPublicHostname as o, defineNotifier as r, retryAfterMs as s, NOTIFICATION_EVENTS as t };
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=notifier-DODVuFhr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notifier-DODVuFhr.js","names":[],"sources":["../../../core/src/notifier.ts"],"sourcesContent":["import type { ZodType } from \"zod\";\nimport { optionKeys, type SchemaLike } from \"./monitor\";\n\n/**\n * What a notification is about. Targets choose which of these they receive:\n * - `down`: `down` was confirmed (on by default);\n * - `recovered`: the monitor left `down` (on by default);\n * - `degraded`: `degraded` was confirmed, from `up` or before any state (off by default);\n * - `degraded_recovered`: the monitor went from `degraded` back to `up` (off by default);\n * - `unknown`: results stopped arriving; only targets marked as administrators' get it.\n */\nexport const NOTIFICATION_EVENTS = [\"down\", \"recovered\", \"degraded\", \"degraded_recovered\", \"unknown\"] as const;\nexport type NotificationEvent = (typeof NOTIFICATION_EVENTS)[number];\n\n/** For colours and icons: `critical` for `down`, `warning` for `degraded` and `unknown`, `ok` for recoveries, `info` for tests. */\nexport type NotificationSeverity = \"critical\" | \"warning\" | \"ok\" | \"info\";\n\n/** A state as notifications name it. */\nexport type NotificationState = \"up\" | \"degraded\" | \"down\" | \"unknown\";\n\nexport interface NotificationLink {\n\treadonly label: string;\n\treadonly url: string;\n}\n\n/**\n * One notification, already written in the hub's language (`locale` in status.config.ts).\n * A notifier kind only lays it out for its service: it never translates or decides anything.\n */\nexport interface Notification {\n\t/**\n\t * Stable identifier: the same for every retry and duplicate delivery of this notification,\n\t * so that a receiver can drop duplicates. Queues deliver at least once.\n\t */\n\treadonly id: string;\n\t/** `test` for a test notification sent from the admin UI. */\n\treadonly event: NotificationEvent | \"test\";\n\treadonly severity: NotificationSeverity;\n\t/** One line of plain text. */\n\treadonly title: string;\n\t/** Plain text, possibly several lines. Always says when it happened (deliveries may arrive late or out of order). */\n\treadonly text: string;\n\t/** When it happened, epoch milliseconds. */\n\treadonly occurredAt: number;\n\t/** `null` for a test notification. */\n\treadonly monitor: { readonly id: string; readonly name: string } | null;\n\t/** The monitor's state after the event; `null` for a test notification. */\n\treadonly state: NotificationState | null;\n\t/** The state before it, when known. */\n\treadonly previousState: NotificationState | null;\n\t/** Links to show with the notification, such as \"Create an incident\". */\n\treadonly links: readonly NotificationLink[];\n\t/** BCP 47 language tag of `title`, `text` and link labels. */\n\treadonly locale: string;\n}\n\n/** What the hub hands a notifier kind for one delivery. */\nexport interface NotifierContext {\n\t/** For the request to the service. Use this, never the global `fetch` (enforced by lint). */\n\treadonly fetch: typeof fetch;\n\t/** Aborted when the delivery takes too long. Pass it to `fetch`. */\n\treadonly signal: AbortSignal;\n}\n\n/**\n * A delivery failed. `retryable` says whether trying again later may help (a timeout, a rate\n * limit, a server error) or not (the webhook was deleted, the payload was refused): the hub\n * then retries with backoff or records the failure at once.\n *\n * Messages must never contain secret options (a webhook URL, a signing secret); the hub also\n * redacts them before it logs or stores a message.\n */\nexport class NotifierError extends Error {\n\toverride readonly name = \"NotifierError\";\n\treadonly retryable: boolean;\n\t/** How long the service asked to wait (`Retry-After`), if it did. */\n\treadonly retryAfterMs: number | undefined;\n\t/** The HTTP status, when the service answered. */\n\treadonly status: number | undefined;\n\n\tconstructor(\n\t\tmessage: string,\n\t\toptions: { readonly retryable: boolean; readonly retryAfterMs?: number | undefined; readonly status?: number | undefined },\n\t) {\n\t\tsuper(message);\n\t\tthis.retryable = options.retryable;\n\t\tthis.retryAfterMs = options.retryAfterMs;\n\t\tthis.status = options.status;\n\t}\n}\n\n/** Longest part of a service's error response kept in a {@link NotifierError} message. */\nconst ERROR_BODY_CHARS = 200;\n/** Bytes of an error response read at most (a little more than the characters kept, for multi-byte text). */\nconst ERROR_BODY_BYTES = 1_024;\n\n/** The start of `response`'s body as text, reading at most {@link ERROR_BODY_BYTES} bytes, then cancelling the rest. */\nasync function bodyStart(response: Response): Promise<string> {\n\tconst reader = response.body?.getReader();\n\tif (reader === undefined) return \"\";\n\tconst chunks: Uint8Array[] = [];\n\tlet size = 0;\n\ttry {\n\t\twhile (size < ERROR_BODY_BYTES) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tchunks.push(value);\n\t\t\tsize += value.byteLength;\n\t\t}\n\t} finally {\n\t\tawait reader.cancel().catch(() => {});\n\t}\n\tconst bytes = new Uint8Array(Math.min(size, ERROR_BODY_BYTES));\n\tlet offset = 0;\n\tfor (const chunk of chunks) {\n\t\tconst part = chunk.subarray(0, bytes.length - offset);\n\t\tbytes.set(part, offset);\n\t\toffset += part.length;\n\t\tif (offset >= bytes.length) break;\n\t}\n\t// A character cut at the end decodes as a replacement character, which is dropped.\n\treturn new TextDecoder().decode(bytes).replace(/\\uFFFD+$/, \"\");\n}\n\n/** Milliseconds from a `Retry-After` header (seconds or an HTTP date), if it has one. */\nexport function retryAfterMs(response: Response, now = Date.now()): number | undefined {\n\tconst value = response.headers.get(\"Retry-After\");\n\tif (value === null) return undefined;\n\tconst seconds = Number(value);\n\tif (Number.isFinite(seconds) && seconds >= 0) return seconds * 1_000;\n\tconst date = Date.parse(value);\n\treturn Number.isNaN(date) ? undefined : Math.max(0, date - now);\n}\n\n/**\n * Throws a {@link NotifierError} unless `response` is successful (2xx). 408, 429 and 5xx are\n * retryable; other statuses are not (the request itself is wrong, or the webhook is gone).\n * The message names `service`, the status and the start of the response body (services such\n * as Slack explain the error there); it never includes the request URL.\n */\nexport async function expectSuccess(response: Response, service: string): Promise<void> {\n\tif (response.ok) {\n\t\t// Release the connection.\n\t\tawait response.body?.cancel();\n\t\treturn;\n\t}\n\tlet body = \"\";\n\ttry {\n\t\tbody = (await bodyStart(response)).trim().slice(0, ERROR_BODY_CHARS);\n\t} catch {\n\t\t// The status is enough.\n\t}\n\tconst { status } = response;\n\tthrow new NotifierError(`${service} answered HTTP ${status}${body === \"\" ? \"\" : `: ${body}`}`, {\n\t\tretryable: status === 408 || status === 429 || status >= 500,\n\t\tretryAfterMs: retryAfterMs(response),\n\t\tstatus,\n\t});\n}\n\n/**\n * A kind of notification channel, such as Slack, Discord or a generic webhook.\n *\n * Only kinds are registered in code (`notifiers` in status.config.ts). Targets, such as \"the\n * #ops channel\", are created in the admin UI and stored in D1 with their options, which the\n * hub validates with `options`; the admin UI builds its form from the same schema (as JSON\n * Schema). Options named in `secretOptions` are encrypted at rest and never shown again.\n *\n * `Options` is the validated option type; `Input` is what an administrator enters.\n */\nexport interface NotifierKind<Options = unknown, Input = Options> {\n\t/** Identifier such as `\"slack\"`: lowercase letters, digits and `-`. Unique within a configuration. Stored with targets: never change it. */\n\treadonly type: string;\n\t/** Display name, such as `\"Slack\"`. */\n\treadonly name: string;\n\t/** Defines and validates the options. Must be an object schema. */\n\treadonly options: ZodType<Options, Input>;\n\t/**\n\t * Top-level option keys whose values are secret (a webhook URL with its token, a signing\n\t * secret): encrypted in D1, write-only through the admin API, never logged.\n\t */\n\treadonly secretOptions: readonly string[];\n\t/**\n\t * The option that holds the URL notifications are sent to, for a kind that sends wherever an\n\t * administrator says (a webhook). The hub binds the other secret options to that URL's origin: an edit that moves the target to another origin must enter them again or clear\n\t * them, and stored values do not decrypt for another origin, so that a secret can never be\n\t * redirected to a host an administrator chose to read it back. The URL must also name a\n\t * public host (see {@link isPublicHostname}). Default: `\"url\"` when the kind has a `url`\n\t * option; kinds that send to a fixed service can leave it out.\n\t */\n\treadonly destinationOption?: string;\n\t/**\n\t * Texts for the admin UI's form, by language (BCP 47 tag): `\"$kind\"` the kind's name,\n\t * `\"<option>.title\"` and `\"<option>.description\"` an option's label and help. What a\n\t * language leaves out falls back to `en`, then to the options' schema (Zod's\n\t * `.meta({ title, description })`), then to the option's name. Optional.\n\t */\n\treadonly messages?: NotifierMessages;\n\t/**\n\t * Delivers one notification. Throw a {@link NotifierError} on failure (any other error\n\t * counts as retryable). Use `ctx.fetch` and `ctx.signal`.\n\t */\n\tsend(notification: Notification, options: Options, ctx: NotifierContext): Promise<void>;\n}\n\n/** A notifier kind's texts for the admin UI, by language (see {@link NotifierKind.messages}). */\nexport type NotifierMessages = Readonly<Record<string, Readonly<Record<string, string>>>>;\n\nconst NOTIFIER_TYPE = /^[a-z][a-z0-9-]{0,31}$/;\nconst MESSAGE_KEY = /^(?:\\$kind|(.+)\\.(?:title|description))$/;\n\n/**\n * Declares a notifier kind, checking that its options are an object schema and that every\n * key in `secretOptions` is one of its options.\n * @throws TypeError otherwise.\n */\nexport function defineNotifier<Options, Input extends object>(\n\tkind: NotifierKind<Options, Input>,\n): NotifierKind<Options, Input> {\n\tif (!NOTIFIER_TYPE.test(kind.type)) {\n\t\tthrow new TypeError(`Notifier \"${kind.type}\": type must be lowercase letters, digits and \"-\", starting with a letter`);\n\t}\n\tconst keys = optionKeys(kind.options as SchemaLike);\n\tif (keys === undefined) throw new TypeError(`Notifier \"${kind.type}\": options must be an object schema`);\n\tif (kind.destinationOption !== undefined && !keys.includes(kind.destinationOption)) {\n\t\tthrow new TypeError(`Notifier \"${kind.type}\": destinationOption \"${kind.destinationOption}\" is not an option`);\n\t}\n\tconst unknown = kind.secretOptions.filter((key) => !keys.includes(key));\n\tif (unknown.length > 0) {\n\t\tthrow new TypeError(\n\t\t\t`Notifier \"${kind.type}\": secretOptions ${unknown.map((key) => `\"${key}\"`).join(\", \")} are not options`,\n\t\t);\n\t}\n\tfor (const [language, messages] of Object.entries(kind.messages ?? {})) {\n\t\tfor (const key of Object.keys(messages)) {\n\t\t\tconst match = MESSAGE_KEY.exec(key);\n\t\t\tif (match === null || (match[1] !== undefined && !keys.includes(match[1]))) {\n\t\t\t\tthrow new TypeError(`Notifier \"${kind.type}\": message \"${key}\" (${language}) is not \"$kind\" or \"<option>.title|description\"`);\n\t\t\t}\n\t\t}\n\t}\n\treturn kind;\n}\n\n/** The option of `kind` that holds where it sends notifications (see {@link NotifierKind.destinationOption}), if any. */\nexport function destinationOptionOf(kind: Pick<NotifierKind, \"destinationOption\" | \"options\">): string | undefined {\n\tif (kind.destinationOption !== undefined) return kind.destinationOption;\n\treturn optionKeys(kind.options as SchemaLike)?.includes(\"url\") ? \"url\" : undefined;\n}\n\nconst IPV4 = /^\\d{1,3}(?:\\.\\d{1,3}){3}$/;\n/** Suffixes of names that only resolve inside a network (RFC 6761, 6762, 8375 and common practice). */\nconst INTERNAL_SUFFIXES = [\".localhost\", \".local\", \".internal\", \".intranet\", \".lan\", \".home\", \".corp\", \".private\", \".home.arpa\", \".localdomain\", \".test\", \".invalid\", \".example\", \".onion\"];\n\n/**\n * Whether `hostname` (as `URL.hostname` gives it) names a host on the public internet: not an\n * IP address literal (which the WHATWG URL parser also makes of forms such as `0x7f.1`), not a\n * single label such as `localhost` or `intranet`, and not under a suffix that only resolves\n * inside a network (`.local`, `.internal`, `.home.arpa`, …). Notification targets must name one,\n * so that an administrator cannot point the hub at addresses it should not reach.\n */\nexport function isPublicHostname(hostname: string): boolean {\n\tconst name = hostname.toLowerCase().replace(/\\.$/, \"\");\n\tif (name === \"\" || name.startsWith(\"[\") || IPV4.test(name) || !name.includes(\".\")) return false;\n\treturn !INTERNAL_SUFFIXES.some((suffix) => name.endsWith(suffix));\n}\n"],"mappings":";;;;;;;;;;AAWA,IAAa,sBAAsB;CAAC;CAAQ;CAAa;CAAY;CAAsB;AAAS;;;;;;;;;AA6DpG,IAAa,gBAAb,cAAmC,MAAM;CACxC,OAAyB;CACzB;;CAEA;;CAEA;CAEA,YACC,SACA,SACC;EACD,MAAM,OAAO;EACb,KAAK,Y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AAC,KAAK,SAAS,MAAM,EAAE,GACvE,MAAM,IAAI,UAAU,aAAa,KAAK,KAAK,cAAc,IAAI,KAAK,SAAS,iDAAiD;CAE9H;CAED,OAAO;AACR;;AAGA,SAAgB,oBAAoB,MAA+E;CAClH,IAAI,KAAK,sBAAsB,KAAA,GAAW,OAAO,KAAK;CACtD,OAAO,WAAW,KAAK,OAAqB,CAAC,EAAE,SAAS,KAAK,IAAI,QAAQ,KAAA;AAC1E;AAEA,IAAM,OAAO;;AAEb,IAAM,oBAAoB;CAAC;CAAc;CAAU;CAAa;CAAa;CAAQ;CAAS;CAAS;CAAY;CAAc;CAAgB;CAAS;CAAY;CAAY;AAAQ;;;;;;;;AAS1L,SAAgB,iBAAiB,UAA2B;CAC3D,MAAM,OAAO,SAAS,YAAY,CAAC,CAAC,QAAQ,OAAO,EAAE;CACrD,IAAI,SAAS,MAAM,KAAK,WAAW,GAAG,KAAK,KAAK,KAAK,IAAI,KAAK,CAAC,KAAK,SAAS,GAAG,GAAG,OAAO;CAC1F,OAAO,CAAC,kBAAkB,MAAM,WAAW,KAAK,SAAS,MAAM,CAAC;AACjE"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// ../core/src/page-templates.ts
|
|
2
|
+
/** How a status page looks. */
|
|
3
|
+
var PAGE_TEMPLATES = ["default", "modern"];
|
|
4
|
+
/** The template of a page that names none. */
|
|
5
|
+
var DEFAULT_PAGE_TEMPLATE = "default";
|
|
6
|
+
/** The `name` of the meta element that lists the pages' templates. */
|
|
7
|
+
var PAGE_TEMPLATES_META = "cf-workers-status-page:templates";
|
|
8
|
+
function isPageTemplate(value) {
|
|
9
|
+
return PAGE_TEMPLATES.includes(value);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A page ID (the rule of config.ts): lowercase letters, digits, `-` and `_`, which never need
|
|
13
|
+
* escaping, in the list or in an HTML attribute.
|
|
14
|
+
*/
|
|
15
|
+
var PAGE_ID = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
16
|
+
/**
|
|
17
|
+
* Each page's ID and template, in order, as the Worker will read them (a page that names no
|
|
18
|
+
* template has the default one); `null` when a page is not valid, which the Worker reports
|
|
19
|
+
* itself when it loads the configuration.
|
|
20
|
+
*/
|
|
21
|
+
function pageTemplatesOf(config) {
|
|
22
|
+
const pages = config.pages ?? [];
|
|
23
|
+
if (!Array.isArray(pages)) return null;
|
|
24
|
+
const entries = [];
|
|
25
|
+
for (const page of pages) {
|
|
26
|
+
if (typeof page !== "object" || page === null) return null;
|
|
27
|
+
const { id, template = DEFAULT_PAGE_TEMPLATE } = page;
|
|
28
|
+
if (typeof id !== "string" || !PAGE_ID.test(id) || !isPageTemplate(template)) return null;
|
|
29
|
+
entries.push({
|
|
30
|
+
id,
|
|
31
|
+
template
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return entries;
|
|
35
|
+
}
|
|
36
|
+
/** The meta element's `content`. Throws on what cannot be a page's ID and template (a bug). */
|
|
37
|
+
function formatPageTemplates(entries) {
|
|
38
|
+
return entries.map(({ id, template }) => {
|
|
39
|
+
if (!PAGE_ID.test(id) || !isPageTemplate(template)) throw new Error(`Not a page ID and template: ${JSON.stringify([id, template])}`);
|
|
40
|
+
return `${id}:${template}`;
|
|
41
|
+
}).join(",");
|
|
42
|
+
}
|
|
43
|
+
/** The pages in a meta element's `content`; none if any part is not a page (the site's root could not be told then). */
|
|
44
|
+
function parsePageTemplates(content) {
|
|
45
|
+
if (content === "") return [];
|
|
46
|
+
const entries = [];
|
|
47
|
+
for (const part of content.split(",")) {
|
|
48
|
+
const [id, template, ...rest] = part.split(":");
|
|
49
|
+
if (id === void 0 || !PAGE_ID.test(id) || !isPageTemplate(template) || rest.length > 0) return [];
|
|
50
|
+
entries.push({
|
|
51
|
+
id,
|
|
52
|
+
template
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return entries;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `html` with the meta element listing `entries`, in its <head> (replacing one that is there
|
|
59
|
+
* already). Throws if `html` has no `</head>`.
|
|
60
|
+
*/
|
|
61
|
+
function withPageTemplates(html, entries) {
|
|
62
|
+
const element = `<meta name="${PAGE_TEMPLATES_META}" content="${formatPageTemplates(entries)}">`;
|
|
63
|
+
const without = html.replace(new RegExp(`[ \\t]*<meta name="${PAGE_TEMPLATES_META}" content="[^"]*">\\r?\\n?`, "g"), "");
|
|
64
|
+
const head = /([ \t]*)<\/head>/i.exec(without);
|
|
65
|
+
if (head === null) throw new Error("The HTML has no </head>");
|
|
66
|
+
const indent = head[1] ?? "";
|
|
67
|
+
return `${without.slice(0, head.index)}${indent}\t${element}\n${without.slice(head.index)}`;
|
|
68
|
+
}
|
|
69
|
+
export { pageTemplatesOf as a, formatPageTemplates as i, PAGE_TEMPLATES as n, parsePageTemplates as o, PAGE_TEMPLATES_META as r, withPageTemplates as s, DEFAULT_PAGE_TEMPLATE as t };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=page-templates-DPZcMlic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-templates-DPZcMlic.js","names":[],"sources":["../../../core/src/page-templates.ts"],"sourcesContent":["/**\n * The templates of status pages, and which one each page uses, as the status page's HTML\n * carries it: a build writes it into the page's <head> (vite.pages.ts, and the package's Vite\n * plugin), so that a page shows its loading screen in its own template before the public API\n * answers (src/public/templates.ts). Once the API has answered, the page is shown in the\n * template the API names.\n *\n * `<meta name=\"cf-workers-status-page:templates\" content=\"default:modern,internal:default\">`:\n * the pages in the order of status.config.ts (the first one is the site's root), each as\n * `id:template`. Every page's ID is public already (`GET /api/pages`).\n *\n * Without Zod, so that the status page's bundle can read it.\n */\nimport type { StatusConfig } from \"./config\";\n\n/** How a status page looks. */\nexport const PAGE_TEMPLATES = [\"default\", \"modern\"] as const;\nexport type PageTemplate = (typeof PAGE_TEMPLATES)[number];\n/** The template of a page that names none. */\nexport const DEFAULT_PAGE_TEMPLATE: PageTemplate = \"default\";\n\n/** The `name` of the meta element that lists the pages' templates. */\nexport const PAGE_TEMPLATES_META = \"cf-workers-status-page:templates\";\n\nexport interface PageTemplateEntry {\n\treadonly id: string;\n\treadonly template: PageTemplate;\n}\n\nfunction isPageTemplate(value: unknown): value is PageTemplate {\n\treturn (PAGE_TEMPLATES as readonly unknown[]).includes(value);\n}\n\n/**\n * A page ID (the rule of config.ts): lowercase letters, digits, `-` and `_`, which never need\n * escaping, in the list or in an HTML attribute.\n */\nconst PAGE_ID = /^[a-z0-9][a-z0-9_-]{0,63}$/;\n\n/**\n * Each page's ID and template, in order, as the Worker will read them (a page that names no\n * template has the default one); `null` when a page is not valid, which the Worker reports\n * itself when it loads the configuration.\n */\nexport function pageTemplatesOf(config: StatusConfig): PageTemplateEntry[] | null {\n\tconst pages: unknown = config.pages ?? [];\n\tif (!Array.isArray(pages)) return null;\n\tconst entries: PageTemplateEntry[] = [];\n\tfor (const page of pages) {\n\t\tif (typeof page !== \"object\" || page === null) return null;\n\t\tconst { id, template = DEFAULT_PAGE_TEMPLATE } = page as { readonly id?: unknown; readonly template?: unknown };\n\t\tif (typeof id !== \"string\" || !PAGE_ID.test(id) || !isPageTemplate(template)) return null;\n\t\tentries.push({ id, template });\n\t}\n\treturn entries;\n}\n\n/** The meta element's `content`. Throws on what cannot be a page's ID and template (a bug). */\nexport function formatPageTemplates(entries: readonly PageTemplateEntry[]): string {\n\treturn entries\n\t\t.map(({ id, template }) => {\n\t\t\tif (!PAGE_ID.test(id) || !isPageTemplate(template)) throw new Error(`Not a page ID and template: ${JSON.stringify([id, template])}`);\n\t\t\treturn `${id}:${template}`;\n\t\t})\n\t\t.join(\",\");\n}\n\n/** The pages in a meta element's `content`; none if any part is not a page (the site's root could not be told then). */\nexport function parsePageTemplates(content: string): PageTemplateEntry[] {\n\tif (content === \"\") return [];\n\tconst entries: PageTemplateEntry[] = [];\n\tfor (const part of content.split(\",\")) {\n\t\tconst [id, template, ...rest] = part.split(\":\");\n\t\tif (id === undefined || !PAGE_ID.test(id) || !isPageTemplate(template) || rest.length > 0) return [];\n\t\tentries.push({ id, template });\n\t}\n\treturn entries;\n}\n\n/**\n * `html` with the meta element listing `entries`, in its <head> (replacing one that is there\n * already). Throws if `html` has no `</head>`.\n */\nexport function withPageTemplates(html: string, entries: readonly PageTemplateEntry[]): string {\n\tconst element = `<meta name=\"${PAGE_TEMPLATES_META}\" content=\"${formatPageTemplates(entries)}\">`;\n\tconst without = html.replace(new RegExp(`[ \\\\t]*<meta name=\"${PAGE_TEMPLATES_META}\" content=\"[^\"]*\">\\\\r?\\\\n?`, \"g\"), \"\");\n\tconst head = /([ \\t]*)<\\/head>/i.exec(without);\n\tif (head === null) throw new Error(\"The HTML has no </head>\");\n\tconst indent = head[1] ?? \"\";\n\treturn `${without.slice(0, head.index)}${indent}\\t${element}\\n${without.slice(head.index)}`;\n}\n"],"mappings":";;AAgBA,IAAa,iBAAiB,CAAC,WAAW,QAAQ;;AAGlD,IAAa,wBAAsC;;AAGnD,IAAa,sBAAsB;AAOnC,SAAS,eAAe,OAAuC;CAC9D,OAAQ,eAAsC,SAAS,KAAK;AAC7D;;;;;AAMA,IAAM,UAAU;;;;;;AAOhB,SAAgB,gBAAgB,QAAkD;CACjF,MAAM,QAAiB,OAAO,SAAS,CAAC;CACxC,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO;CAClC,MAAM,UAA+B,CAAC;CACtC,KAAK,MAAM,QAAQ,OAAO;EACzB,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM,OAAO;EACtD,MAAM,EAAE,IAAI,WAAW,0BAA0B;EACjD,IAAI,OAAO,OAAO,YAAY,CAAC,QAAQ,KAAK,EAAE,KAAK,CAAC,eAAe,QAAQ,GAAG,OAAO;EACrF,QAAQ,KAAK;GAAE;GAAI;EAAS,CAAC;CAC9B;CACA,OAAO;AACR;;AAGA,SAAgB,oBAAoB,SAA+C;CAClF,OAAO,QACL,KAAK,EAAE,IAAI,eAAe;EAC1B,IAAI,CAAC,QAAQ,KAAK,EAAE,KAAK,CAAC,eAAe,QAAQ,GAAG,MAAM,IAAI,MAAM,+BAA+B,KAAK,UAAU,CAAC,IAAI,QAAQ,CAAC,GAAG;EACnI,OAAO,GAAG,GAAG,GAAG;CACjB,CAAC,CAAC,CACD,KAAK,GAAG;AACX;;AAGA,SAAgB,mBAAmB,SAAsC;CACxE,IAAI,YAAY,IAAI,OAAO,CAAC;CAC5B,MAAM,UAA+B,CAAC;CACtC,KAAK,MAAM,QAAQ,QAAQ,MAAM,GAAG,GAAG;EACtC,MAAM,CAAC,IAAI,UAAU,GAAG,QAAQ,KAAK,MAAM,GAAG;EAC9C,IAAI,OAAO,KAAA,KAAa,CAAC,QAAQ,KAAK,EAAE,KAAK,CAAC,eAAe,QAAQ,KAAK,KAAK,SAAS,GAAG,OAAO,CAAC;EACnG,QAAQ,KAAK;GAAE;GAAI;EAAS,CAAC;CAC9B;CACA,OAAO;AACR;;;;;AAMA,SAAgB,kBAAkB,MAAc,SAA+C;CAC9F,MAAM,UAAU,eAAe,oBAAoB,aAAa,oBAAoB,OAAO,EAAE;CAC7F,MAAM,UAAU,KAAK,QAAQ,IAAI,OAAO,sBAAsB,oBAAoB,6BAA6B,GAAG,GAAG,EAAE;CACvH,MAAM,OAAO,oBAAoB,KAAK,OAAO;CAC7C,IAAI,SAAS,MAAM,MAAM,IAAI,MAAM,yBAAyB;CAC5D,MAAM,SAAS,KAAK,MAAM;CAC1B,OAAO,GAAG,QAAQ,MAAM,GAAG,KAAK,KAAK,IAAI,OAAO,IAAI,QAAQ,IAAI,QAAQ,MAAM,KAAK,KAAK;AACzF"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
// ../core/src/secret.ts
|
|
3
|
+
/** Secret names: letters, digits and `_`, not starting with a digit (like environment variables). */
|
|
4
|
+
var SECRET_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
5
|
+
/** References a secret by name, e.g. `headers: { Authorization: secret("API_TOKEN") }`. */
|
|
6
|
+
function secret(name) {
|
|
7
|
+
return Object.freeze({ $secret: name });
|
|
8
|
+
}
|
|
9
|
+
function isSecretRef(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 1 && typeof value.$secret === "string";
|
|
11
|
+
}
|
|
12
|
+
/** Zod schema for a {@link SecretRef}. Providers use it, usually through {@link secretOr}, where a value may be secret. */
|
|
13
|
+
function secretRefSchema() {
|
|
14
|
+
return z.strictObject({ $secret: z.string().regex(SECRET_NAME_PATTERN, "secret name must be letters, digits or \"_\", not starting with a digit") });
|
|
15
|
+
}
|
|
16
|
+
/** Accepts either a value matching `schema` or a `secret("NAME")` reference. */
|
|
17
|
+
function secretOr(schema) {
|
|
18
|
+
return z.union([secretRefSchema(), schema]);
|
|
19
|
+
}
|
|
20
|
+
/** A referenced secret is not set. The message names the secrets, never their values. */
|
|
21
|
+
var MissingSecretError = class extends Error {
|
|
22
|
+
name = "MissingSecretError";
|
|
23
|
+
secrets;
|
|
24
|
+
constructor(secrets) {
|
|
25
|
+
const list = secrets.map((name) => `"${name}"`).join(", ");
|
|
26
|
+
super(secrets.length === 1 ? `Secret ${list} is not set or is empty` : `Secrets ${list} are not set or are empty`);
|
|
27
|
+
this.secrets = secrets;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function isPlainObject(value) {
|
|
31
|
+
if (typeof value !== "object" || value === null) return false;
|
|
32
|
+
const prototype = Object.getPrototypeOf(value);
|
|
33
|
+
return prototype === Object.prototype || prototype === null;
|
|
34
|
+
}
|
|
35
|
+
/** Names of all secrets referenced in `value`, without duplicates. */
|
|
36
|
+
function secretNames(value) {
|
|
37
|
+
const names = /* @__PURE__ */ new Set();
|
|
38
|
+
const visit = (node) => {
|
|
39
|
+
if (isSecretRef(node)) names.add(node.$secret);
|
|
40
|
+
else if (Array.isArray(node)) node.forEach(visit);
|
|
41
|
+
else if (isPlainObject(node)) Object.values(node).forEach(visit);
|
|
42
|
+
};
|
|
43
|
+
visit(value);
|
|
44
|
+
return [...names];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Replaces every {@link SecretRef} in `value` with the secret's value.
|
|
48
|
+
* Returns the values too, so that they can be redacted from anything the check produces.
|
|
49
|
+
* @throws MissingSecretError if any referenced secret is not set or is empty.
|
|
50
|
+
*/
|
|
51
|
+
async function resolveSecrets(value, lookup) {
|
|
52
|
+
const found = /* @__PURE__ */ new Map();
|
|
53
|
+
const missing = [];
|
|
54
|
+
for (const name of secretNames(value)) {
|
|
55
|
+
const secretValue = await lookup(name);
|
|
56
|
+
if (secretValue === void 0 || secretValue === "") missing.push(name);
|
|
57
|
+
else found.set(name, secretValue);
|
|
58
|
+
}
|
|
59
|
+
if (missing.length > 0) throw new MissingSecretError(missing);
|
|
60
|
+
const replace = (node) => {
|
|
61
|
+
if (isSecretRef(node)) return found.get(node.$secret);
|
|
62
|
+
if (Array.isArray(node)) return node.map(replace);
|
|
63
|
+
if (isPlainObject(node)) return Object.fromEntries(Object.entries(node).map(([key, item]) => [key, replace(item)]));
|
|
64
|
+
return node;
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
value: replace(value),
|
|
68
|
+
secrets: [...found.values()]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
var REDACTED = "[redacted]";
|
|
72
|
+
/** Replaces every occurrence of the given secret values in strings within `value`. */
|
|
73
|
+
function redactSecrets(value, secrets) {
|
|
74
|
+
const values = [...new Set(secrets)].filter((s) => s !== "").sort((a, b) => b.length - a.length);
|
|
75
|
+
if (values.length === 0) return value;
|
|
76
|
+
const redactString = (text) => values.reduce((result, secretValue) => result.split(secretValue).join(REDACTED), text);
|
|
77
|
+
const visit = (node) => {
|
|
78
|
+
if (typeof node === "string") return redactString(node);
|
|
79
|
+
if (Array.isArray(node)) return node.map(visit);
|
|
80
|
+
if (isPlainObject(node)) return Object.fromEntries(Object.entries(node).map(([key, item]) => [key, visit(item)]));
|
|
81
|
+
return node;
|
|
82
|
+
};
|
|
83
|
+
return visit(value);
|
|
84
|
+
}
|
|
85
|
+
// ../core/src/run-check.ts
|
|
86
|
+
function errorMessage(error) {
|
|
87
|
+
return error instanceof Error ? error.message : String(error);
|
|
88
|
+
}
|
|
89
|
+
/** Redirects followed at most, as browsers and the Fetch standard do. */
|
|
90
|
+
var MAX_REDIRECTS = 20;
|
|
91
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([
|
|
92
|
+
301,
|
|
93
|
+
302,
|
|
94
|
+
303,
|
|
95
|
+
307,
|
|
96
|
+
308
|
|
97
|
+
]);
|
|
98
|
+
/** Headers that describe a request body, dropped when a redirect turns the request into a GET (Fetch standard). */
|
|
99
|
+
var BODY_HEADERS = [
|
|
100
|
+
"content-encoding",
|
|
101
|
+
"content-language",
|
|
102
|
+
"content-location",
|
|
103
|
+
"content-type"
|
|
104
|
+
];
|
|
105
|
+
/** A request would have carried a `secret()` value over plain http. Nothing was sent. */
|
|
106
|
+
var InsecureSecretError = class extends Error {
|
|
107
|
+
name = "InsecureSecretError";
|
|
108
|
+
constructor() {
|
|
109
|
+
super("Refusing to send secret() values over plain http: use an https URL");
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var withheld = /* @__PURE__ */ new WeakMap();
|
|
113
|
+
/**
|
|
114
|
+
* Whether `response` is a redirect that `ctx.fetch` did not follow, although the request asked
|
|
115
|
+
* to follow redirects, because the request carried `secret()` values (and why). Providers use
|
|
116
|
+
* it to report the redirect itself as the result, with a clear message.
|
|
117
|
+
*/
|
|
118
|
+
function withheldRedirect(response) {
|
|
119
|
+
return withheld.get(response);
|
|
120
|
+
}
|
|
121
|
+
/** Whether the request made from `input` and `init` contains one of `secrets` (URL, headers, or a text body). */
|
|
122
|
+
function carriesSecret(input, init, secrets) {
|
|
123
|
+
if (secrets.length === 0) return false;
|
|
124
|
+
const request = input instanceof Request ? input : void 0;
|
|
125
|
+
const headers = new Headers(init?.headers ?? request?.headers);
|
|
126
|
+
const texts = [request?.url ?? String(input), ...[...headers].map(([, value]) => value)];
|
|
127
|
+
if (typeof init?.body === "string") texts.push(init.body);
|
|
128
|
+
const values = secrets.flatMap((value) => [value, value.trim()]).filter((value) => value !== "");
|
|
129
|
+
return texts.some((text) => values.some((value) => text.includes(value)));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* `fetch` for a request that carries secrets: never over plain http, and redirects
|
|
133
|
+
* followed by hand, at most {@link MAX_REDIRECTS}, only to the same origin over https. A
|
|
134
|
+
* redirect anywhere else is returned as the response, unfollowed, and marked for
|
|
135
|
+
* {@link withheldRedirect}. (`fetch` itself would forward every header except `Authorization`
|
|
136
|
+
* to another origin, `Cookie` and API-key headers included.)
|
|
137
|
+
*/
|
|
138
|
+
async function fetchWithSecrets(send, input, init) {
|
|
139
|
+
const first = new URL(input instanceof Request ? input.url : String(input));
|
|
140
|
+
if (first.protocol !== "https:") throw new InsecureSecretError();
|
|
141
|
+
if ((init?.redirect ?? (input instanceof Request ? input.redirect : "follow")) !== "follow") return send(input, init);
|
|
142
|
+
let url = first;
|
|
143
|
+
let method = (init?.method ?? (input instanceof Request ? input.method : "GET")).toUpperCase();
|
|
144
|
+
let headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
|
|
145
|
+
let body = init?.body ?? (input instanceof Request ? input.body : void 0);
|
|
146
|
+
let next = [input, {
|
|
147
|
+
...init,
|
|
148
|
+
redirect: "manual"
|
|
149
|
+
}];
|
|
150
|
+
for (let hop = 0;; hop++) {
|
|
151
|
+
const response = await send(...next);
|
|
152
|
+
const location = response.headers.get("Location");
|
|
153
|
+
if (!REDIRECT_STATUSES.has(response.status) || location === null) return response;
|
|
154
|
+
if (hop === 20) {
|
|
155
|
+
await response.body?.cancel().catch(() => {});
|
|
156
|
+
throw new TypeError(`More than 20 redirects`);
|
|
157
|
+
}
|
|
158
|
+
const target = new URL(location, url);
|
|
159
|
+
const changesToGet = response.status === 303 ? method !== "HEAD" : (response.status === 301 || response.status === 302) && method === "POST";
|
|
160
|
+
const reason = target.host !== first.host ? "cross-origin" : target.protocol !== "https:" ? "insecure" : target.origin !== first.origin ? "cross-origin" : !changesToGet && body !== void 0 && body !== null && typeof body !== "string" ? "body" : void 0;
|
|
161
|
+
if (reason !== void 0) {
|
|
162
|
+
withheld.set(response, {
|
|
163
|
+
location: target.href,
|
|
164
|
+
reason
|
|
165
|
+
});
|
|
166
|
+
return response;
|
|
167
|
+
}
|
|
168
|
+
await response.body?.cancel().catch(() => {});
|
|
169
|
+
if (changesToGet) {
|
|
170
|
+
method = "GET";
|
|
171
|
+
body = void 0;
|
|
172
|
+
headers = new Headers(headers);
|
|
173
|
+
for (const name of BODY_HEADERS) headers.delete(name);
|
|
174
|
+
}
|
|
175
|
+
url = target;
|
|
176
|
+
next = [target.href, {
|
|
177
|
+
...init,
|
|
178
|
+
method,
|
|
179
|
+
headers,
|
|
180
|
+
body: body ?? null,
|
|
181
|
+
redirect: "manual"
|
|
182
|
+
}];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Runs one check the way every runner must:
|
|
187
|
+
*
|
|
188
|
+
* 1. Resolves `secret()` references. If one is missing, throws `MissingSecretError`
|
|
189
|
+
* (naming the secret, not its value) without calling the provider, so nothing is sent
|
|
190
|
+
* with an empty credential. The runner records this as a failed check without a
|
|
191
|
+
* state, so the monitor becomes `unknown` rather than `down`.
|
|
192
|
+
* 2. Calls the provider with a context whose `signal` aborts at the monitor's timeout
|
|
193
|
+
* and whose `fetch` follows that signal. A check still running at the timeout is `down`.
|
|
194
|
+
* A request that carries a secret value is never sent over plain http
|
|
195
|
+
* ({@link InsecureSecretError}), and its redirects are followed only to the same origin
|
|
196
|
+
* over https; others are returned unfollowed ({@link withheldRedirect}).
|
|
197
|
+
* 3. Redacts secret values from the result, and from the message of anything thrown.
|
|
198
|
+
*
|
|
199
|
+
* If the runner aborts `runner.signal`, its reason is rethrown and no result is recorded.
|
|
200
|
+
*/
|
|
201
|
+
async function runCheck(target, runner) {
|
|
202
|
+
const { value: options, secrets } = await resolveSecrets(target.options, runner.secret);
|
|
203
|
+
const runnerSignal = runner.signal ?? new AbortController().signal;
|
|
204
|
+
const timeout = AbortSignal.timeout(target.timeoutMs);
|
|
205
|
+
const signal = AbortSignal.any([runnerSignal, timeout]);
|
|
206
|
+
const send = ((input, init) => runner.fetch(input, {
|
|
207
|
+
...init,
|
|
208
|
+
signal: init?.signal ? AbortSignal.any([init.signal, signal]) : signal
|
|
209
|
+
}));
|
|
210
|
+
const ctx = {
|
|
211
|
+
fetch: (input, init) => carriesSecret(input, init, secrets) ? fetchWithSecrets(send, input, init) : send(input, init),
|
|
212
|
+
signal
|
|
213
|
+
};
|
|
214
|
+
if (runner.connect) ctx.connect = runner.connect;
|
|
215
|
+
const aborted = new Promise((_, reject) => {
|
|
216
|
+
if (signal.aborted) reject(signal.reason);
|
|
217
|
+
else signal.addEventListener("abort", () => reject(signal.reason), { once: true });
|
|
218
|
+
});
|
|
219
|
+
try {
|
|
220
|
+
return redactSecrets(await Promise.race([target.provider.check(options, ctx), aborted]), secrets);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (runnerSignal.aborted) throw runnerSignal.reason;
|
|
223
|
+
if (timeout.aborted) return {
|
|
224
|
+
state: "down",
|
|
225
|
+
message: `No response within ${target.timeoutMs} ms`,
|
|
226
|
+
details: { error: "timeout" }
|
|
227
|
+
};
|
|
228
|
+
const redacted = new Error(redactSecrets(errorMessage(error), secrets));
|
|
229
|
+
if (error instanceof Error) redacted.name = error.name;
|
|
230
|
+
throw redacted;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export { MissingSecretError as a, resolveSecrets as c, secretOr as d, secretRefSchema as f, withheldRedirect as i, secret as l, MAX_REDIRECTS as n, isSecretRef as o, runCheck as r, redactSecrets as s, InsecureSecretError as t, secretNames as u };
|
|
234
|
+
|
|
235
|
+
//# sourceMappingURL=run-check-bbo3LqI7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-check-bbo3LqI7.js","names":[],"sources":["../../../core/src/secret.ts","../../../core/src/run-check.ts"],"sourcesContent":["import * as z from \"zod\";\n\n/**\n * A reference to a secret by name, written in `status.config.ts` in place of the secret\n * itself. The runner looks the value up when a check runs; on Cloudflare that is\n * a Worker secret (`wrangler secret put API_TOKEN`).\n *\n * It is plain data so that it survives structured cloning (RPC) and JSON.\n */\nexport interface SecretRef {\n\treadonly $secret: string;\n}\n\n/** Secret names: letters, digits and `_`, not starting with a digit (like environment variables). */\nconst SECRET_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** References a secret by name, e.g. `headers: { Authorization: secret(\"API_TOKEN\") }`. */\nexport function secret(name: string): SecretRef {\n\treturn Object.freeze({ $secret: name });\n}\n\nexport function isSecretRef(value: unknown): value is SecretRef {\n\treturn (\n\t\ttypeof value === \"object\" &&\n\t\tvalue !== null &&\n\t\t!Array.isArray(value) &&\n\t\tObject.keys(value).length === 1 &&\n\t\ttypeof (value as { $secret?: unknown }).$secret === \"string\"\n\t);\n}\n\n/** Zod schema for a {@link SecretRef}. Providers use it, usually through {@link secretOr}, where a value may be secret. */\nexport function secretRefSchema(): z.ZodType<SecretRef, SecretRef> {\n\treturn z.strictObject({\n\t\t$secret: z\n\t\t\t.string()\n\t\t\t.regex(\n\t\t\t\tSECRET_NAME_PATTERN,\n\t\t\t\t'secret name must be letters, digits or \"_\", not starting with a digit',\n\t\t\t),\n\t});\n}\n\n/** Accepts either a value matching `schema` or a `secret(\"NAME\")` reference. */\nexport function secretOr<Output, Input>(\n\tschema: z.ZodType<Output, Input>,\n): z.ZodType<Output | SecretRef, Input | SecretRef> {\n\treturn z.union([secretRefSchema(), schema]);\n}\n\n/** `T` with every {@link SecretRef} replaced by the secret's value, as providers receive it. */\nexport type SecretsResolved<T> = T extends SecretRef\n\t? string\n\t: T extends readonly (infer Item)[]\n\t\t? SecretsResolved<Item>[]\n\t\t: T extends object\n\t\t\t? { [K in keyof T]: SecretsResolved<T[K]> }\n\t\t\t: T;\n\n/** Looks a secret up by name. `undefined` (or an empty string) means it is not set. */\nexport type SecretLookup = (name: string) => string | undefined | Promise<string | undefined>;\n\n/** A referenced secret is not set. The message names the secrets, never their values. */\nexport class MissingSecretError extends Error {\n\toverride readonly name = \"MissingSecretError\";\n\treadonly secrets: readonly string[];\n\n\tconstructor(secrets: readonly string[]) {\n\t\tconst list = secrets.map((name) => `\"${name}\"`).join(\", \");\n\t\tsuper(\n\t\t\tsecrets.length === 1\n\t\t\t\t? `Secret ${list} is not set or is empty`\n\t\t\t\t: `Secrets ${list} are not set or are empty`,\n\t\t);\n\t\tthis.secrets = secrets;\n\t}\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst prototype = Object.getPrototypeOf(value) as unknown;\n\treturn prototype === Object.prototype || prototype === null;\n}\n\n/** Names of all secrets referenced in `value`, without duplicates. */\nexport function secretNames(value: unknown): string[] {\n\tconst names = new Set<string>();\n\tconst visit = (node: unknown): void => {\n\t\tif (isSecretRef(node)) names.add(node.$secret);\n\t\telse if (Array.isArray(node)) node.forEach(visit);\n\t\telse if (isPlainObject(node)) Object.values(node).forEach(visit);\n\t};\n\tvisit(value);\n\treturn [...names];\n}\n\n/**\n * Replaces every {@link SecretRef} in `value` with the secret's value.\n * Returns the values too, so that they can be redacted from anything the check produces.\n * @throws MissingSecretError if any referenced secret is not set or is empty.\n */\nexport async function resolveSecrets<T>(\n\tvalue: T,\n\tlookup: SecretLookup,\n): Promise<{ value: SecretsResolved<T>; secrets: string[] }> {\n\tconst found = new Map<string, string>();\n\tconst missing: string[] = [];\n\tfor (const name of secretNames(value)) {\n\t\tconst secretValue = await lookup(name);\n\t\tif (secretValue === undefined || secretValue === \"\") missing.push(name);\n\t\telse found.set(name, secretValue);\n\t}\n\tif (missing.length > 0) throw new MissingSecretError(missing);\n\n\tconst replace = (node: unknown): unknown => {\n\t\tif (isSecretRef(node)) return found.get(node.$secret);\n\t\tif (Array.isArray(node)) return node.map(replace);\n\t\tif (isPlainObject(node)) {\n\t\t\treturn Object.fromEntries(Object.entries(node).map(([key, item]) => [key, replace(item)]));\n\t\t}\n\t\treturn node;\n\t};\n\treturn { value: replace(value) as SecretsResolved<T>, secrets: [...found.values()] };\n}\n\nconst REDACTED = \"[redacted]\";\n\n/** Replaces every occurrence of the given secret values in strings within `value`. */\nexport function redactSecrets<T>(value: T, secrets: readonly string[]): T {\n\t// Longest first, so that a secret containing another is redacted whole.\n\tconst values = [...new Set(secrets)].filter((s) => s !== \"\").sort((a, b) => b.length - a.length);\n\tif (values.length === 0) return value;\n\tconst redactString = (text: string) =>\n\t\tvalues.reduce((result, secretValue) => result.split(secretValue).join(REDACTED), text);\n\tconst visit = (node: unknown): unknown => {\n\t\tif (typeof node === \"string\") return redactString(node);\n\t\tif (Array.isArray(node)) return node.map(visit);\n\t\tif (isPlainObject(node)) {\n\t\t\treturn Object.fromEntries(Object.entries(node).map(([key, item]) => [key, visit(item)]));\n\t\t}\n\t\treturn node;\n\t};\n\treturn visit(value) as T;\n}\n","import type { CheckContext, CheckProvider, CheckResult, TcpConnect } from \"./provider\";\nimport { redactSecrets, resolveSecrets, type SecretLookup } from \"./secret\";\n\n/** What `runCheck` needs from a resolved monitor. */\nexport interface CheckTarget {\n\treadonly provider: CheckProvider;\n\t/** Validated provider options, possibly containing `secret()` references. */\n\treadonly options: unknown;\n\treadonly timeoutMs: number;\n}\n\n/** What the runner supplies. Runtime-specific parts are passed in, so this stays runtime-agnostic. */\nexport interface RunnerContext {\n\t/** The runner's fetch, with its User-Agent applied. */\n\treadonly fetch: typeof fetch;\n\t/** Only when the runner provides the `tcp` capability. */\n\treadonly connect?: TcpConnect;\n\t/** Aborted when the runner gives up on the check (for example, shutting down). */\n\treadonly signal?: AbortSignal;\n\t/** Looks up secrets referenced with `secret()`; on Cloudflare, Worker secrets in `env`. */\n\treadonly secret: SecretLookup;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\n/** Redirects followed at most, as browsers and the Fetch standard do. */\nexport const MAX_REDIRECTS = 20;\n\nconst REDIRECT_STATUSES: ReadonlySet<number> = new Set([301, 302, 303, 307, 308]);\n\n/** Headers that describe a request body, dropped when a redirect turns the request into a GET (Fetch standard). */\nconst BODY_HEADERS = [\"content-encoding\", \"content-language\", \"content-location\", \"content-type\"] as const;\n\n/** A request would have carried a `secret()` value over plain http. Nothing was sent. */\nexport class InsecureSecretError extends Error {\n\toverride readonly name = \"InsecureSecretError\";\n\tconstructor() {\n\t\tsuper(\"Refusing to send secret() values over plain http: use an https URL\");\n\t}\n}\n\n/** Why a redirect of a request carrying secrets was not followed (see {@link withheldRedirect}). */\nexport interface WithheldRedirect {\n\t/** Where the response pointed, resolved against the request's URL. */\n\treadonly location: string;\n\t/**\n\t * - `cross-origin`: to another origin, which must never receive the secrets;\n\t * - `insecure`: to plain http;\n\t * - `body`: the request body cannot be sent again (a stream).\n\t */\n\treadonly reason: \"cross-origin\" | \"insecure\" | \"body\";\n}\n\nconst withheld = new WeakMap<Response, WithheldRedirect>();\n\n/**\n * Whether `response` is a redirect that `ctx.fetch` did not follow, although the request asked\n * to follow redirects, because the request carried `secret()` values (and why). Providers use\n * it to report the redirect itself as the result, with a clear message.\n */\nexport function withheldRedirect(response: Response): WithheldRedirect | undefined {\n\treturn withheld.get(response);\n}\n\n/** Whether the request made from `input` and `init` contains one of `secrets` (URL, headers, or a text body). */\nfunction carriesSecret(input: RequestInfo | URL, init: RequestInit | undefined, secrets: readonly string[]): boolean {\n\tif (secrets.length === 0) return false;\n\tconst request = input instanceof Request ? input : undefined;\n\tconst headers = new Headers(init?.headers ?? request?.headers);\n\tconst texts = [request?.url ?? String(input), ...[...headers].map(([, value]) => value)];\n\tif (typeof init?.body === \"string\") texts.push(init.body);\n\tconst values = secrets.flatMap((value) => [value, value.trim()]).filter((value) => value !== \"\");\n\treturn texts.some((text) => values.some((value) => text.includes(value)));\n}\n\n/**\n * `fetch` for a request that carries secrets: never over plain http, and redirects\n * followed by hand, at most {@link MAX_REDIRECTS}, only to the same origin over https. A\n * redirect anywhere else is returned as the response, unfollowed, and marked for\n * {@link withheldRedirect}. (`fetch` itself would forward every header except `Authorization`\n * to another origin, `Cookie` and API-key headers included.)\n */\nasync function fetchWithSecrets(\n\tsend: typeof fetch,\n\tinput: RequestInfo | URL,\n\tinit: RequestInit | undefined,\n): Promise<Response> {\n\tconst first = new URL(input instanceof Request ? input.url : String(input));\n\tif (first.protocol !== \"https:\") throw new InsecureSecretError();\n\tconst mode = init?.redirect ?? (input instanceof Request ? input.redirect : \"follow\");\n\t// \"manual\" and \"error\" never send the request anywhere else.\n\tif (mode !== \"follow\") return send(input, init);\n\n\tlet url = first;\n\tlet method = (init?.method ?? (input instanceof Request ? input.method : \"GET\")).toUpperCase();\n\tlet headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : undefined));\n\tlet body = init?.body ?? (input instanceof Request ? input.body : undefined);\n\tlet next: [RequestInfo | URL, RequestInit] = [input, { ...init, redirect: \"manual\" }];\n\tfor (let hop = 0; ; hop++) {\n\t\tconst response = await send(...next);\n\t\tconst location = response.headers.get(\"Location\");\n\t\tif (!REDIRECT_STATUSES.has(response.status) || location === null) return response;\n\t\tif (hop === MAX_REDIRECTS) {\n\t\t\tawait response.body?.cancel().catch(() => {});\n\t\t\tthrow new TypeError(`More than ${MAX_REDIRECTS} redirects`);\n\t\t}\n\t\tconst target = new URL(location, url);\n\t\tconst changesToGet = response.status === 303 ? method !== \"HEAD\" : (response.status === 301 || response.status === 302) && method === \"POST\";\n\t\tconst reason: WithheldRedirect[\"reason\"] | undefined =\n\t\t\ttarget.host !== first.host\n\t\t\t\t? \"cross-origin\"\n\t\t\t\t: target.protocol !== \"https:\"\n\t\t\t\t\t? \"insecure\"\n\t\t\t\t\t: target.origin !== first.origin\n\t\t\t\t\t\t? \"cross-origin\"\n\t\t\t\t\t\t: !changesToGet && body !== undefined && body !== null && typeof body !== \"string\"\n\t\t\t\t\t\t\t? \"body\"\n\t\t\t\t\t\t\t: undefined;\n\t\tif (reason !== undefined) {\n\t\t\twithheld.set(response, { location: target.href, reason });\n\t\t\treturn response;\n\t\t}\n\t\tawait response.body?.cancel().catch(() => {});\n\t\tif (changesToGet) {\n\t\t\tmethod = \"GET\";\n\t\t\tbody = undefined;\n\t\t\theaders = new Headers(headers);\n\t\t\tfor (const name of BODY_HEADERS) headers.delete(name);\n\t\t}\n\t\turl = target;\n\t\tnext = [target.href, { ...init, method, headers, body: body ?? null, redirect: \"manual\" }];\n\t}\n}\n\n/**\n * Runs one check the way every runner must:\n *\n * 1. Resolves `secret()` references. If one is missing, throws `MissingSecretError`\n * (naming the secret, not its value) without calling the provider, so nothing is sent\n * with an empty credential. The runner records this as a failed check without a\n * state, so the monitor becomes `unknown` rather than `down`.\n * 2. Calls the provider with a context whose `signal` aborts at the monitor's timeout\n * and whose `fetch` follows that signal. A check still running at the timeout is `down`.\n * A request that carries a secret value is never sent over plain http\n * ({@link InsecureSecretError}), and its redirects are followed only to the same origin\n * over https; others are returned unfollowed ({@link withheldRedirect}).\n * 3. Redacts secret values from the result, and from the message of anything thrown.\n *\n * If the runner aborts `runner.signal`, its reason is rethrown and no result is recorded.\n */\nexport async function runCheck(target: CheckTarget, runner: RunnerContext): Promise<CheckResult> {\n\tconst { value: options, secrets } = await resolveSecrets(target.options, runner.secret);\n\n\tconst runnerSignal = runner.signal ?? new AbortController().signal;\n\tconst timeout = AbortSignal.timeout(target.timeoutMs);\n\tconst signal = AbortSignal.any([runnerSignal, timeout]);\n\tconst send = ((input: RequestInfo | URL, init?: RequestInit) =>\n\t\trunner.fetch(input, {\n\t\t\t...init,\n\t\t\tsignal: init?.signal ? AbortSignal.any([init.signal, signal]) : signal,\n\t\t})) as typeof fetch;\n\tconst ctx: CheckContext = {\n\t\t// Requests that carry secrets never go over http or to another origin (see fetchWithSecrets).\n\t\tfetch: (input, init) => (carriesSecret(input, init, secrets) ? fetchWithSecrets(send, input, init) : send(input, init)),\n\t\tsignal,\n\t};\n\tif (runner.connect) ctx.connect = runner.connect;\n\n\t// Settles when `signal` aborts, in case the provider ignores it.\n\tconst aborted = new Promise<never>((_, reject) => {\n\t\tif (signal.aborted) reject(signal.reason);\n\t\telse signal.addEventListener(\"abort\", () => reject(signal.reason), { once: true });\n\t});\n\n\ttry {\n\t\tconst result = await Promise.race([target.provider.check(options, ctx), aborted]);\n\t\treturn redactSecrets(result, secrets);\n\t} catch (error) {\n\t\tif (runnerSignal.aborted) throw runnerSignal.reason;\n\t\tif (timeout.aborted) {\n\t\t\treturn {\n\t\t\t\tstate: \"down\",\n\t\t\t\tmessage: `No response within ${target.timeoutMs} ms`,\n\t\t\t\tdetails: { error: \"timeout\" },\n\t\t\t};\n\t\t}\n\t\tconst redacted = new Error(redactSecrets(errorMessage(error), secrets));\n\t\tif (error instanceof Error) redacted.name = error.name;\n\t\tthrow redacted;\n\t}\n}\n"],"mappings":";;;AAcA,IAAM,sBAAsB;;AAG5B,SAAgB,OAAO,MAAyB;CAC/C,OAAO,OAAO,OAAO,EAAE,SAAS,KAAK,CAAC;AACvC;AAEA,SAAgB,YAAY,OAAoC;CAC/D,OACC,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACpB,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAC9B,OAAQ,MAAgC,YAAY;AAEtD;;AAGA,SAAgB,kBAAmD;CAClE,OAAO,EAAE,aAAa,EACrB,SAAS,EACP,OAAO,CAAC,CACR,MACA,qBACA,yEACD,EACF,CAAC;AACF;;AAGA,SAAgB,SACf,QACmD;CACnD,OAAO,EAAE,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC;AAC3C;;AAeA,IAAa,qBAAb,cAAwC,MAAM;CAC7C,OAAyB;CACzB;CAEA,YAAY,SA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