@naosystem/cf-workers-status-page 0.0.0-stage → 0.1.2

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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -2
  3. package/dist/admin.html +17 -0
  4. package/dist/auth-cloudflare-access.js +304 -0
  5. package/dist/auth-cloudflare-access.js.map +1 -0
  6. package/dist/chunks/monitor-B2u42off.js +79 -0
  7. package/dist/chunks/monitor-B2u42off.js.map +1 -0
  8. package/dist/chunks/notifier-DODVuFhr.js +158 -0
  9. package/dist/chunks/notifier-DODVuFhr.js.map +1 -0
  10. package/dist/chunks/page-templates-DPZcMlic.js +71 -0
  11. package/dist/chunks/page-templates-DPZcMlic.js.map +1 -0
  12. package/dist/chunks/run-check-bbo3LqI7.js +235 -0
  13. package/dist/chunks/run-check-bbo3LqI7.js.map +1 -0
  14. package/dist/chunks/timeline-YJXjehRf.js +1081 -0
  15. package/dist/chunks/timeline-YJXjehRf.js.map +1 -0
  16. package/dist/client/_headers +10 -0
  17. package/dist/client/assets/admin-BBJxKTF6.js +1 -0
  18. package/dist/client/assets/admin-Be4X0WFj.css +1 -0
  19. package/dist/client/assets/index-BgOspfsy.js +2 -0
  20. package/dist/client/assets/index-xpKyzvog.css +1 -0
  21. package/dist/client/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  22. package/dist/client/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  23. package/dist/client/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  24. package/dist/client/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  25. package/dist/client/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  26. package/dist/client/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  27. package/dist/client/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  28. package/dist/client/assets/ja-BT5brvxP.js +1 -0
  29. package/dist/client/assets/ja-DSSblLff.js +1 -0
  30. package/dist/client/assets/noto-sans-jp-0-wght-normal-vN5ykBQF.woff2 +0 -0
  31. package/dist/client/assets/noto-sans-jp-1-wght-normal-N_EDDt8j.woff2 +0 -0
  32. package/dist/client/assets/noto-sans-jp-10-wght-normal-ChuiXes4.woff2 +0 -0
  33. package/dist/client/assets/noto-sans-jp-100-wght-normal-CrE4HD6k.woff2 +0 -0
  34. package/dist/client/assets/noto-sans-jp-101-wght-normal-DOqEZFXR.woff2 +0 -0
  35. package/dist/client/assets/noto-sans-jp-102-wght-normal-2gFz4V6e.woff2 +0 -0
  36. package/dist/client/assets/noto-sans-jp-103-wght-normal-D9RhXU-z.woff2 +0 -0
  37. package/dist/client/assets/noto-sans-jp-104-wght-normal-OIyZ9iQD.woff2 +0 -0
  38. package/dist/client/assets/noto-sans-jp-105-wght-normal-CqRQAfnb.woff2 +0 -0
  39. package/dist/client/assets/noto-sans-jp-106-wght-normal-D-PO3jqS.woff2 +0 -0
  40. package/dist/client/assets/noto-sans-jp-107-wght-normal-DrykTIAp.woff2 +0 -0
  41. package/dist/client/assets/noto-sans-jp-108-wght-normal-DijBe27A.woff2 +0 -0
  42. package/dist/client/assets/noto-sans-jp-109-wght-normal-DaJwqT__.woff2 +0 -0
  43. package/dist/client/assets/noto-sans-jp-11-wght-normal-DdkFqF_o.woff2 +0 -0
  44. package/dist/client/assets/noto-sans-jp-110-wght-normal-bhh2FQQH.woff2 +0 -0
  45. package/dist/client/assets/noto-sans-jp-111-wght-normal-CuGzYIdC.woff2 +0 -0
  46. package/dist/client/assets/noto-sans-jp-112-wght-normal-DdhK_1vk.woff2 +0 -0
  47. package/dist/client/assets/noto-sans-jp-113-wght-normal-hxVHS2d4.woff2 +0 -0
  48. package/dist/client/assets/noto-sans-jp-114-wght-normal-DUzjAsrP.woff2 +0 -0
  49. package/dist/client/assets/noto-sans-jp-115-wght-normal-BiZ4-5rz.woff2 +0 -0
  50. package/dist/client/assets/noto-sans-jp-116-wght-normal-DkZAcxAY.woff2 +0 -0
  51. package/dist/client/assets/noto-sans-jp-117-wght-normal-CLJPD2y0.woff2 +0 -0
  52. package/dist/client/assets/noto-sans-jp-118-wght-normal-D8DI_HXJ.woff2 +0 -0
  53. package/dist/client/assets/noto-sans-jp-119-wght-normal-BAB3pFaH.woff2 +0 -0
  54. package/dist/client/assets/noto-sans-jp-12-wght-normal-K36fA5_o.woff2 +0 -0
  55. package/dist/client/assets/noto-sans-jp-13-wght-normal-BnYizWno.woff2 +0 -0
  56. package/dist/client/assets/noto-sans-jp-14-wght-normal-BP4IgVC-.woff2 +0 -0
  57. package/dist/client/assets/noto-sans-jp-15-wght-normal-DyhWcoYF.woff2 +0 -0
  58. package/dist/client/assets/noto-sans-jp-16-wght-normal-CXsQLI2j.woff2 +0 -0
  59. package/dist/client/assets/noto-sans-jp-17-wght-normal-C8FU1ZJ4.woff2 +0 -0
  60. package/dist/client/assets/noto-sans-jp-18-wght-normal-Cl0IKBVh.woff2 +0 -0
  61. package/dist/client/assets/noto-sans-jp-19-wght-normal-D3D3JUJm.woff2 +0 -0
  62. package/dist/client/assets/noto-sans-jp-2-wght-normal-CGu8NhtQ.woff2 +0 -0
  63. package/dist/client/assets/noto-sans-jp-20-wght-normal-DxsoeWSt.woff2 +0 -0
  64. package/dist/client/assets/noto-sans-jp-21-wght-normal-CuNsexW5.woff2 +0 -0
  65. package/dist/client/assets/noto-sans-jp-22-wght-normal-DVX3OFQM.woff2 +0 -0
  66. package/dist/client/assets/noto-sans-jp-23-wght-normal-BPFuo_yH.woff2 +0 -0
  67. package/dist/client/assets/noto-sans-jp-24-wght-normal-D85Fj66x.woff2 +0 -0
  68. package/dist/client/assets/noto-sans-jp-25-wght-normal-DdOOVuSz.woff2 +0 -0
  69. package/dist/client/assets/noto-sans-jp-26-wght-normal-BRB1GnUq.woff2 +0 -0
  70. package/dist/client/assets/noto-sans-jp-27-wght-normal-BxZFF8JU.woff2 +0 -0
  71. package/dist/client/assets/noto-sans-jp-28-wght-normal-VUlviaYI.woff2 +0 -0
  72. package/dist/client/assets/noto-sans-jp-29-wght-normal-CalQqRwB.woff2 +0 -0
  73. package/dist/client/assets/noto-sans-jp-3-wght-normal-cncaCaM8.woff2 +0 -0
  74. package/dist/client/assets/noto-sans-jp-30-wght-normal-CHLg85G9.woff2 +0 -0
  75. package/dist/client/assets/noto-sans-jp-31-wght-normal-BUoF9dl9.woff2 +0 -0
  76. package/dist/client/assets/noto-sans-jp-32-wght-normal-C5ZTiBNw.woff2 +0 -0
  77. package/dist/client/assets/noto-sans-jp-33-wght-normal-C6XNJsfA.woff2 +0 -0
  78. package/dist/client/assets/noto-sans-jp-34-wght-normal-DHkM837w.woff2 +0 -0
  79. package/dist/client/assets/noto-sans-jp-35-wght-normal-QMtEjDIl.woff2 +0 -0
  80. package/dist/client/assets/noto-sans-jp-36-wght-normal-CUyF0GqZ.woff2 +0 -0
  81. package/dist/client/assets/noto-sans-jp-37-wght-normal-EORmNjxA.woff2 +0 -0
  82. package/dist/client/assets/noto-sans-jp-38-wght-normal-C8ERbMNG.woff2 +0 -0
  83. package/dist/client/assets/noto-sans-jp-39-wght-normal-ChUfpJbl.woff2 +0 -0
  84. package/dist/client/assets/noto-sans-jp-4-wght-normal-DtWqs3EP.woff2 +0 -0
  85. package/dist/client/assets/noto-sans-jp-40-wght-normal-MgP8JEEE.woff2 +0 -0
  86. package/dist/client/assets/noto-sans-jp-41-wght-normal-3ctF9abM.woff2 +0 -0
  87. package/dist/client/assets/noto-sans-jp-42-wght-normal-CQtg6UZe.woff2 +0 -0
  88. package/dist/client/assets/noto-sans-jp-43-wght-normal-D1Pmm9aG.woff2 +0 -0
  89. package/dist/client/assets/noto-sans-jp-44-wght-normal-Cp9dHeXI.woff2 +0 -0
  90. package/dist/client/assets/noto-sans-jp-45-wght-normal-D2b1osBj.woff2 +0 -0
  91. package/dist/client/assets/noto-sans-jp-46-wght-normal-CGIA-Vlo.woff2 +0 -0
  92. package/dist/client/assets/noto-sans-jp-47-wght-normal-C4EEGqDS.woff2 +0 -0
  93. package/dist/client/assets/noto-sans-jp-48-wght-normal-D2iBztXa.woff2 +0 -0
  94. package/dist/client/assets/noto-sans-jp-49-wght-normal-DxqRVik_.woff2 +0 -0
  95. package/dist/client/assets/noto-sans-jp-5-wght-normal-CFiyVtll.woff2 +0 -0
  96. package/dist/client/assets/noto-sans-jp-50-wght-normal-CMseszwo.woff2 +0 -0
  97. package/dist/client/assets/noto-sans-jp-51-wght-normal-Cqc-9wfi.woff2 +0 -0
  98. package/dist/client/assets/noto-sans-jp-52-wght-normal-BVLZTbqC.woff2 +0 -0
  99. package/dist/client/assets/noto-sans-jp-53-wght-normal-DTyNOJaY.woff2 +0 -0
  100. package/dist/client/assets/noto-sans-jp-54-wght-normal-_mxGq_et.woff2 +0 -0
  101. package/dist/client/assets/noto-sans-jp-55-wght-normal-Bvndync8.woff2 +0 -0
  102. package/dist/client/assets/noto-sans-jp-56-wght-normal-0MmMqroR.woff2 +0 -0
  103. package/dist/client/assets/noto-sans-jp-57-wght-normal-BdRnjDYs.woff2 +0 -0
  104. package/dist/client/assets/noto-sans-jp-58-wght-normal-BYGgVeN_.woff2 +0 -0
  105. package/dist/client/assets/noto-sans-jp-59-wght-normal-Bdv8mdje.woff2 +0 -0
  106. package/dist/client/assets/noto-sans-jp-6-wght-normal-M-pWkj3J.woff2 +0 -0
  107. package/dist/client/assets/noto-sans-jp-60-wght-normal-DC6FEqsM.woff2 +0 -0
  108. package/dist/client/assets/noto-sans-jp-61-wght-normal-CYIuK5Lr.woff2 +0 -0
  109. package/dist/client/assets/noto-sans-jp-62-wght-normal-DeHy8p7w.woff2 +0 -0
  110. package/dist/client/assets/noto-sans-jp-63-wght-normal-B4M6eMmD.woff2 +0 -0
  111. package/dist/client/assets/noto-sans-jp-64-wght-normal-DLyOXBrC.woff2 +0 -0
  112. package/dist/client/assets/noto-sans-jp-65-wght-normal-X7SsA1bs.woff2 +0 -0
  113. package/dist/client/assets/noto-sans-jp-66-wght-normal-VScDM-_N.woff2 +0 -0
  114. package/dist/client/assets/noto-sans-jp-67-wght-normal-Dg2D3DZB.woff2 +0 -0
  115. package/dist/client/assets/noto-sans-jp-68-wght-normal-BB0AR8UN.woff2 +0 -0
  116. package/dist/client/assets/noto-sans-jp-69-wght-normal-CucwpUnQ.woff2 +0 -0
  117. package/dist/client/assets/noto-sans-jp-7-wght-normal-DzOz8Ryd.woff2 +0 -0
  118. package/dist/client/assets/noto-sans-jp-70-wght-normal-BZId6-Tb.woff2 +0 -0
  119. package/dist/client/assets/noto-sans-jp-71-wght-normal-CzPU0NF7.woff2 +0 -0
  120. package/dist/client/assets/noto-sans-jp-72-wght-normal-DrNRYXnT.woff2 +0 -0
  121. package/dist/client/assets/noto-sans-jp-73-wght-normal-DF2BdR6a.woff2 +0 -0
  122. package/dist/client/assets/noto-sans-jp-74-wght-normal-BMlOw_5y.woff2 +0 -0
  123. package/dist/client/assets/noto-sans-jp-75-wght-normal-DKq84hLG.woff2 +0 -0
  124. package/dist/client/assets/noto-sans-jp-76-wght-normal-CTb-2MFr.woff2 +0 -0
  125. package/dist/client/assets/noto-sans-jp-77-wght-normal-DfIVi-wf.woff2 +0 -0
  126. package/dist/client/assets/noto-sans-jp-78-wght-normal-_-z1Vrir.woff2 +0 -0
  127. package/dist/client/assets/noto-sans-jp-79-wght-normal-D8kGlXda.woff2 +0 -0
  128. package/dist/client/assets/noto-sans-jp-8-wght-normal-BfWoBb3q.woff2 +0 -0
  129. package/dist/client/assets/noto-sans-jp-80-wght-normal-BOEztZwY.woff2 +0 -0
  130. package/dist/client/assets/noto-sans-jp-81-wght-normal-h5VC8QpU.woff2 +0 -0
  131. package/dist/client/assets/noto-sans-jp-82-wght-normal-DJ4QkvX0.woff2 +0 -0
  132. package/dist/client/assets/noto-sans-jp-83-wght-normal-DANtuAZG.woff2 +0 -0
  133. package/dist/client/assets/noto-sans-jp-84-wght-normal-DjZ8Sp6m.woff2 +0 -0
  134. package/dist/client/assets/noto-sans-jp-85-wght-normal-kpU7kbMF.woff2 +0 -0
  135. package/dist/client/assets/noto-sans-jp-86-wght-normal-DRPTa-bf.woff2 +0 -0
  136. package/dist/client/assets/noto-sans-jp-87-wght-normal-CFM472wD.woff2 +0 -0
  137. package/dist/client/assets/noto-sans-jp-88-wght-normal-2rLLwelj.woff2 +0 -0
  138. package/dist/client/assets/noto-sans-jp-89-wght-normal-DUIF9ybW.woff2 +0 -0
  139. package/dist/client/assets/noto-sans-jp-9-wght-normal-WLs1HgG6.woff2 +0 -0
  140. package/dist/client/assets/noto-sans-jp-90-wght-normal-B0n_tL-y.woff2 +0 -0
  141. package/dist/client/assets/noto-sans-jp-91-wght-normal-BishDeFy.woff2 +0 -0
  142. package/dist/client/assets/noto-sans-jp-92-wght-normal-DoIdukLp.woff2 +0 -0
  143. package/dist/client/assets/noto-sans-jp-93-wght-normal-DMCycan_.woff2 +0 -0
  144. package/dist/client/assets/noto-sans-jp-94-wght-normal-DlyoTk-A.woff2 +0 -0
  145. package/dist/client/assets/noto-sans-jp-95-wght-normal-D0L1aiGf.woff2 +0 -0
  146. package/dist/client/assets/noto-sans-jp-96-wght-normal-CjJ0kYkQ.woff2 +0 -0
  147. package/dist/client/assets/noto-sans-jp-97-wght-normal-CJ8uP04H.woff2 +0 -0
  148. package/dist/client/assets/noto-sans-jp-98-wght-normal-CjEDrQIY.woff2 +0 -0
  149. package/dist/client/assets/noto-sans-jp-99-wght-normal-DaQ3GEVf.woff2 +0 -0
  150. package/dist/client/assets/noto-sans-jp-cyrillic-wght-normal-BbS1Q_ZO.woff2 +0 -0
  151. package/dist/client/assets/noto-sans-jp-latin-ext-wght-normal-IaSo_s9d.woff2 +0 -0
  152. package/dist/client/assets/noto-sans-jp-latin-wght-normal-Bnnzbixe.woff2 +0 -0
  153. package/dist/client/assets/noto-sans-jp-vietnamese-wght-normal-CjvP4Ahz.woff2 +0 -0
  154. package/dist/client/assets/src-BDi4qpij.js +9 -0
  155. package/dist/client/assets/src-C6ZFz-Gu.css +1 -0
  156. package/dist/client/assets/views-CSeX_2-u.css +1 -0
  157. package/dist/client/assets/views-DHTTEaNV.js +1 -0
  158. package/dist/client/index.html +15 -0
  159. package/dist/client/licenses/fonts.txt +104 -0
  160. package/dist/client/licenses/third-party.txt +349 -0
  161. package/dist/index.js +18 -0
  162. package/dist/index.js.map +1 -0
  163. package/dist/notifier-discord.js +153 -0
  164. package/dist/notifier-discord.js.map +1 -0
  165. package/dist/notifier-slack.js +98 -0
  166. package/dist/notifier-slack.js.map +1 -0
  167. package/dist/notifier-webhook.js +215 -0
  168. package/dist/notifier-webhook.js.map +1 -0
  169. package/dist/provider-http.js +177 -0
  170. package/dist/provider-http.js.map +1 -0
  171. package/dist/vite.js +224 -0
  172. package/dist/vite.js.map +1 -0
  173. package/dist/worker.js +8616 -0
  174. package/dist/worker.js.map +1 -0
  175. package/package.json +58 -5
@@ -0,0 +1,1081 @@
1
+ import { n as RESERVED_MONITOR_KEYS } from "./monitor-B2u42off.js";
2
+ import { n as PAGE_TEMPLATES, t as DEFAULT_PAGE_TEMPLATE } from "./page-templates-DPZcMlic.js";
3
+ import { u as secretNames } from "./run-check-bbo3LqI7.js";
4
+ import * as z from "zod";
5
+ // ../core/src/calendar.ts
6
+ var formatters = /* @__PURE__ */ new Map();
7
+ function formatter(timeZone) {
8
+ let found = formatters.get(timeZone);
9
+ if (found === void 0) {
10
+ found = new Intl.DateTimeFormat("en-US", {
11
+ timeZone,
12
+ hourCycle: "h23",
13
+ year: "numeric",
14
+ month: "2-digit",
15
+ day: "2-digit",
16
+ hour: "2-digit",
17
+ minute: "2-digit",
18
+ second: "2-digit"
19
+ });
20
+ formatters.set(timeZone, found);
21
+ }
22
+ return found;
23
+ }
24
+ function wallClock(at, timeZone) {
25
+ const parts = {};
26
+ for (const part of formatter(timeZone).formatToParts(at)) if (part.type !== "literal") parts[part.type] = Number(part.value);
27
+ return {
28
+ year: parts["year"] ?? 0,
29
+ month: parts["month"] ?? 1,
30
+ day: parts["day"] ?? 1,
31
+ hour: parts["hour"] ?? 0,
32
+ minute: parts["minute"] ?? 0,
33
+ second: parts["second"] ?? 0
34
+ };
35
+ }
36
+ function pad(value, length = 2) {
37
+ return String(value).padStart(length, "0");
38
+ }
39
+ function formatDate(year, month, day) {
40
+ return `${pad(year, 4)}-${pad(month)}-${pad(day)}`;
41
+ }
42
+ function parseDate(date) {
43
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date);
44
+ if (match === null) throw new RangeError(`Not a YYYY-MM-DD date: ${date}`);
45
+ return [
46
+ Number(match[1]),
47
+ Number(match[2]),
48
+ Number(match[3])
49
+ ];
50
+ }
51
+ /** The date `days` after `date` (negative: before), in the proleptic Gregorian calendar. */
52
+ function addDays(date, days) {
53
+ const [year, month, day] = parseDate(date);
54
+ const shifted = new Date(Date.UTC(year, month - 1, day + days));
55
+ return formatDate(shifted.getUTCFullYear(), shifted.getUTCMonth() + 1, shifted.getUTCDate());
56
+ }
57
+ /** The local date (`YYYY-MM-DD`) at instant `at` in `timeZone`. */
58
+ function localDate(at, timeZone) {
59
+ const clock = wallClock(at, timeZone);
60
+ return formatDate(clock.year, clock.month, clock.day);
61
+ }
62
+ /** Local wall-clock time minus UTC at `at`, in milliseconds (whole seconds). */
63
+ function offsetAt(at, timeZone) {
64
+ const seconds = Math.floor(at / 1e3) * 1e3;
65
+ const clock = wallClock(seconds, timeZone);
66
+ return Date.UTC(clock.year, clock.month - 1, clock.day, clock.hour, clock.minute, clock.second) - seconds;
67
+ }
68
+ var starts = /* @__PURE__ */ new Map();
69
+ var MAX_MEMO = 4096;
70
+ var HOUR_MS = 36e5;
71
+ /**
72
+ * The first instant of local date `date` in `timeZone`: local midnight, or the first
73
+ * instant after a transition that skips midnight, or the earlier of two midnights when the
74
+ * clock goes back across it.
75
+ */
76
+ function startOfLocalDay(date, timeZone) {
77
+ const key = `${timeZone} ${date}`;
78
+ const memo = starts.get(key);
79
+ if (memo !== void 0) return memo;
80
+ const [year, month, day] = parseDate(date);
81
+ const midnightUtc = Date.UTC(year, month - 1, day);
82
+ let start = midnightUtc - offsetAt(midnightUtc, timeZone);
83
+ start = midnightUtc - offsetAt(start, timeZone);
84
+ if (localDate(start, timeZone) !== date || localDate(start - 1, timeZone) >= date) {
85
+ let low = midnightUtc - 15 * HOUR_MS;
86
+ let high = midnightUtc + 15 * HOUR_MS;
87
+ while (high - low > 1e3) {
88
+ const middle = low + Math.floor((high - low) / 2e3) * 1e3;
89
+ if (localDate(middle, timeZone) >= date) high = middle;
90
+ else low = middle;
91
+ }
92
+ start = high;
93
+ }
94
+ if (starts.size >= MAX_MEMO) starts.clear();
95
+ starts.set(key, start);
96
+ return start;
97
+ }
98
+ /** The local day of `date`. */
99
+ function calendarDay(date, timeZone) {
100
+ return {
101
+ date,
102
+ from: startOfLocalDay(date, timeZone),
103
+ to: startOfLocalDay(addDays(date, 1), timeZone)
104
+ };
105
+ }
106
+ /** The last `count` local days up to and including the one containing `now`, oldest first. */
107
+ function recentDays(now, timeZone, count) {
108
+ const today = localDate(now, timeZone);
109
+ const days = [];
110
+ for (let offset = count - 1; offset >= 0; offset--) days.push(calendarDay(addDays(today, -offset), timeZone));
111
+ return days;
112
+ }
113
+ // ../core/src/confirmation.ts
114
+ /** Lower is less severe. */
115
+ var SEVERITY = {
116
+ up: 0,
117
+ degraded: 1,
118
+ down: 2
119
+ };
120
+ /**
121
+ * How many of the latest observations {@link confirmState} needs to see: enough for the
122
+ * longer threshold, plus one to see where the run started.
123
+ */
124
+ function observationsNeeded(thresholds) {
125
+ return Math.max(thresholds.failureThreshold, thresholds.successThreshold) + 1;
126
+ }
127
+ /** The trailing observations that satisfy `matches`, oldest first. */
128
+ function trailingRun(recent, matches) {
129
+ let start = recent.length;
130
+ while (start > 0 && matches(recent[start - 1].state)) start--;
131
+ return recent.slice(start);
132
+ }
133
+ function leastSevere(run) {
134
+ return run.reduce((least, { state }) => SEVERITY[state] < SEVERITY[least] ? state : least, "down");
135
+ }
136
+ /**
137
+ * The confirmation rule, as a pure function of the confirmed state before the
138
+ * latest observation and the latest observations.
139
+ *
140
+ * - `successThreshold` consecutive `up` results confirm `up`.
141
+ * - From `up` (or before anything is confirmed), `failureThreshold` consecutive non-`up`
142
+ * results confirm a non-`up` state: the least severe state in that run, so
143
+ * `[down, degraded]` confirms `degraded`.
144
+ * - While a non-`up` state is confirmed, moving between `degraded` and `down` needs
145
+ * `failureThreshold` consecutive results of the new state.
146
+ *
147
+ * `since` is the start of the run that confirmed the state, as far back as `recent` reaches,
148
+ * and is kept strictly after the previous state's `since`.
149
+ *
150
+ * @param previous The confirmed state before the latest observation, or `null`.
151
+ * @param recent The latest observations, oldest first, ending with the newest one. Pass at
152
+ * least {@link observationsNeeded} of them when that many exist.
153
+ */
154
+ function confirmState(previous, recent, thresholds) {
155
+ const latest = recent.at(-1);
156
+ const unchanged = (pending) => ({
157
+ current: previous,
158
+ changed: false,
159
+ pending
160
+ });
161
+ if (latest === void 0) return unchanged(null);
162
+ let target;
163
+ let run;
164
+ let threshold;
165
+ if (latest.state === "up") {
166
+ if (previous?.state === "up") return unchanged(null);
167
+ run = trailingRun(recent, (state) => state === "up");
168
+ target = "up";
169
+ threshold = thresholds.successThreshold;
170
+ } else if (previous === null || previous.state === "up") {
171
+ run = trailingRun(recent, (state) => state !== "up");
172
+ target = leastSevere(run);
173
+ threshold = thresholds.failureThreshold;
174
+ } else {
175
+ if (latest.state === previous.state) return unchanged(null);
176
+ run = trailingRun(recent, (state) => state === latest.state);
177
+ target = latest.state;
178
+ threshold = thresholds.failureThreshold;
179
+ }
180
+ if (run.length < threshold) return unchanged(target);
181
+ const runStart = run[0].at;
182
+ const since = previous === null ? runStart : Math.max(runStart, previous.since + 1);
183
+ return {
184
+ current: {
185
+ state: target,
186
+ since,
187
+ confirmedAt: latest.at
188
+ },
189
+ changed: true,
190
+ pending: latest.state === target ? null : latest.state
191
+ };
192
+ }
193
+ // ../core/src/duration.ts
194
+ var UNIT_MS = {
195
+ ms: 1,
196
+ s: 1e3,
197
+ m: 6e4,
198
+ h: 36e5,
199
+ d: 864e5
200
+ };
201
+ var DURATION_PATTERN = /^(\d+)(ms|s|m|h|d)$/;
202
+ var FORMAT_HINT = "expected an integer followed by ms, s, m, h or d (for example \"15s\", \"1m\" or \"180d\")";
203
+ /**
204
+ * Converts a duration string to milliseconds.
205
+ * @throws RangeError if the string is not a valid {@link Duration}.
206
+ */
207
+ function parseDuration(value) {
208
+ const match = DURATION_PATTERN.exec(value);
209
+ const amount = match?.[1];
210
+ const unit = match?.[2];
211
+ if (amount === void 0 || unit === void 0) throw new RangeError(`Invalid duration "${value}": ${FORMAT_HINT}`);
212
+ const ms = Number(amount) * UNIT_MS[unit];
213
+ if (!Number.isSafeInteger(ms)) throw new RangeError(`Invalid duration "${value}": too large`);
214
+ return ms;
215
+ }
216
+ /**
217
+ * Zod schema that accepts a {@link Duration} string and outputs milliseconds.
218
+ * Use `.prefault("10s")` (not `.default()`) to give a default written as a duration string.
219
+ */
220
+ function durationSchema() {
221
+ return z.string().transform((value, ctx) => {
222
+ try {
223
+ return parseDuration(value);
224
+ } catch (error) {
225
+ ctx.addIssue(error.message);
226
+ return z.NEVER;
227
+ }
228
+ });
229
+ }
230
+ // ../core/src/location.ts
231
+ /**
232
+ * Where the hub places a monitor's Durable Object, and so where the built-in runner
233
+ * checks from. Values are Durable Object location hints.
234
+ *
235
+ * The Worker verifies at type-check time that this list matches the runtime's
236
+ * `DurableObjectLocationHint`, so core stays free of Cloudflare runtime types.
237
+ */
238
+ var LOCATION_HINTS = [
239
+ "wnam",
240
+ "enam",
241
+ "sam",
242
+ "weur",
243
+ "eeur",
244
+ "apac",
245
+ "apac-ne",
246
+ "apac-se",
247
+ "oc",
248
+ "afr",
249
+ "me"
250
+ ];
251
+ // ../core/src/runner.ts
252
+ /** Returns the capabilities in `required` that `runner` does not provide. */
253
+ function missingCapabilities(required, runner) {
254
+ return required.filter((capability) => !runner.capabilities.includes(capability));
255
+ }
256
+ // ../core/src/config.ts
257
+ /** Placeholders the texts of automatic incidents may use. */
258
+ var INCIDENT_TEMPLATE_PLACEHOLDERS = [
259
+ "components",
260
+ "monitor",
261
+ "time"
262
+ ];
263
+ /** Gives `status.config.ts` type checking and completion. Validation happens when the Worker loads it. */
264
+ function defineConfig(config) {
265
+ return config;
266
+ }
267
+ /**
268
+ * Shorthand for a component made of a single monitor. Its ID is the monitor ID and its
269
+ * name is the monitor's name unless `name` is given.
270
+ */
271
+ function component(monitorId, options = {}) {
272
+ return {
273
+ id: monitorId,
274
+ ...options,
275
+ monitors: [monitorId]
276
+ };
277
+ }
278
+ /** Thrown by {@link resolveConfig} with every problem found, not just the first. */
279
+ var ConfigError = class extends Error {
280
+ name = "ConfigError";
281
+ issues;
282
+ constructor(issues) {
283
+ const lines = issues.map((issue) => issue.path === "" ? ` - ${issue.message}` : ` - ${issue.path}: ${issue.message}`);
284
+ super(["Invalid status.config.ts:", ...lines].join("\n"));
285
+ this.issues = issues;
286
+ }
287
+ };
288
+ var ID_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
289
+ var DAY_MS = 864e5;
290
+ var DEFAULT_TIMEOUT = "10s";
291
+ /** `retention` must cover at least this many intervals of every monitor. */
292
+ var MIN_INTERVALS_RETAINED = 10;
293
+ var idSchema = z.string().regex(ID_PATTERN, "must be 1-64 characters of lowercase letters, digits, \"-\" or \"_\", starting with a letter or digit");
294
+ function positiveDuration() {
295
+ return durationSchema().refine((ms) => ms > 0, "must be longer than 0");
296
+ }
297
+ var UNITS = [
298
+ ["d", DAY_MS],
299
+ ["h", 36e5],
300
+ ["m", 6e4],
301
+ ["s", 1e3]
302
+ ];
303
+ /** Milliseconds back to the largest exact unit, for messages: 90000 -> "90s". */
304
+ function formatDuration(ms) {
305
+ const unit = UNITS.find(([, size]) => ms % size === 0);
306
+ return unit ? `${ms / unit[1]}${unit[0]}` : `${ms}ms`;
307
+ }
308
+ var timezoneSchema = z.string().transform((value, ctx) => {
309
+ try {
310
+ return new Intl.DateTimeFormat("en-US", { timeZone: value }).resolvedOptions().timeZone;
311
+ } catch {
312
+ ctx.addIssue(`unknown time zone "${value}"; use an IANA name such as "Asia/Tokyo"`);
313
+ return z.NEVER;
314
+ }
315
+ });
316
+ var confirmationSchema = z.strictObject({
317
+ failureThreshold: z.int().min(1).default(2),
318
+ successThreshold: z.int().min(1).default(1),
319
+ recheckInterval: positiveDuration().prefault("15s")
320
+ });
321
+ var monitorSettingsSchema = z.strictObject({
322
+ id: idSchema,
323
+ name: z.string().min(1).optional(),
324
+ interval: positiveDuration(),
325
+ timeout: positiveDuration().prefault(DEFAULT_TIMEOUT),
326
+ location: z.enum(LOCATION_HINTS).optional(),
327
+ confirmation: confirmationSchema.prefault({})
328
+ });
329
+ var componentSchema = z.strictObject({
330
+ id: idSchema,
331
+ name: z.string().min(1).optional(),
332
+ monitors: z.array(z.string()).default([]),
333
+ latency: z.boolean().default(false)
334
+ });
335
+ var groupSchema = z.strictObject({
336
+ id: idSchema,
337
+ name: z.string().trim().min(1),
338
+ components: z.array(z.unknown()).min(1, "must list at least one component")
339
+ });
340
+ /** An entry of `components` that is a group (it has `components` of its own). */
341
+ function isGroupEntry(value) {
342
+ return isObject(value) && "components" in value;
343
+ }
344
+ var reportUrlSchema = z.string().max(2e3).transform((value, ctx) => {
345
+ let url;
346
+ try {
347
+ url = new URL(value);
348
+ } catch {
349
+ ctx.addIssue("must be a URL such as \"https://example.com/support\" or \"mailto:support@example.com\"");
350
+ return z.NEVER;
351
+ }
352
+ if (url.protocol !== "https:" && url.protocol !== "http:" && url.protocol !== "mailto:") {
353
+ ctx.addIssue("must be an https, http or mailto URL");
354
+ return z.NEVER;
355
+ }
356
+ if (url.username !== "" || url.password !== "") {
357
+ ctx.addIssue("must not contain credentials");
358
+ return z.NEVER;
359
+ }
360
+ return url.href;
361
+ });
362
+ var PLACEHOLDER = /\{([^{}]*)\}/g;
363
+ var KNOWN_PLACEHOLDERS = new Set(INCIDENT_TEMPLATE_PLACEHOLDERS);
364
+ function templateSchema(maxLength) {
365
+ return z.string().trim().min(1).max(maxLength).superRefine((text, ctx) => {
366
+ for (const match of text.matchAll(PLACEHOLDER)) if (!KNOWN_PLACEHOLDERS.has(match[1])) ctx.addIssue(`unknown placeholder ${match[0]}; use ${INCIDENT_TEMPLATE_PLACEHOLDERS.map((name) => `{${name}}`).join(", ")}`);
367
+ });
368
+ }
369
+ var templatesSchema = z.strictObject({
370
+ title: templateSchema(200).optional(),
371
+ investigating: templateSchema(2e3).optional(),
372
+ update: templateSchema(2e3).optional(),
373
+ resolved: templateSchema(2e3).optional(),
374
+ stopped: templateSchema(2e3).optional(),
375
+ reopened: templateSchema(2e3).optional(),
376
+ partial: templateSchema(2e3).optional()
377
+ });
378
+ var pageSchema = z.strictObject({
379
+ id: idSchema,
380
+ template: z.enum(PAGE_TEMPLATES).default(DEFAULT_PAGE_TEMPLATE),
381
+ reportUrl: reportUrlSchema.optional(),
382
+ incidents: z.strictObject({
383
+ auto: z.boolean().default(false),
384
+ templates: templatesSchema.default({}),
385
+ reopenWithin: durationSchema().refine((ms) => ms <= DAY_MS, "must be at most 1d").prefault("30m")
386
+ }).prefault({}),
387
+ components: z.array(z.unknown()).default([])
388
+ });
389
+ /** An origin as browsers send it in `Origin`: scheme, host and port if not the default, lowercase. */
390
+ var originSchema = z.string().refine((value) => {
391
+ try {
392
+ const url = new URL(value);
393
+ return (url.protocol === "https:" || url.protocol === "http:") && url.origin === value;
394
+ } catch {
395
+ return false;
396
+ }
397
+ }, "must be an origin such as \"https://www.example.com\": lowercase, with no path, query or trailing slash, and no default port");
398
+ var publicApiSchema = z.strictObject({
399
+ cache: z.enum(["durable-object", "workers-cache"]).default("durable-object"),
400
+ allowedOrigins: z.union([z.literal("*"), z.array(originSchema).superRefine((origins, ctx) => {
401
+ origins.forEach((origin, index) => {
402
+ if (origins.indexOf(origin) !== index) ctx.addIssue({
403
+ code: "custom",
404
+ message: `"${origin}" is listed twice`,
405
+ path: [index]
406
+ });
407
+ });
408
+ })]).default([])
409
+ }).prefault({});
410
+ var localeSchema = z.string().transform((value, ctx) => {
411
+ try {
412
+ const [canonical] = Intl.getCanonicalLocales(value);
413
+ if (canonical !== void 0) return canonical;
414
+ } catch {}
415
+ ctx.addIssue(`"${value}" is not a language tag; use one such as "en" or "ja"`);
416
+ return z.NEVER;
417
+ });
418
+ var baseUrlSchema = z.string().transform((value, ctx) => {
419
+ let url;
420
+ try {
421
+ url = new URL(value);
422
+ } catch {
423
+ ctx.addIssue("must be a URL such as \"https://status.example.com\"");
424
+ return z.NEVER;
425
+ }
426
+ if (url.protocol !== "https:" && url.protocol !== "http:") ctx.addIssue("must be an http or https URL");
427
+ if (url.username !== "" || url.password !== "") ctx.addIssue("must not contain credentials");
428
+ if (url.search !== "" || url.hash !== "") ctx.addIssue("must not have a query or fragment");
429
+ return `${url.origin}${url.pathname}`.replace(/\/+$/, "");
430
+ });
431
+ var MINUTE_MS = 6e4;
432
+ /** A host as `URL.host` gives it: lowercase name (or bracketed IPv6) and a port if not the default. */
433
+ var hostSchema = z.string().refine((value) => {
434
+ try {
435
+ const url = new URL(`https://${value}`);
436
+ return url.host === value && url.pathname === "/" && url.username === "" && url.password === "";
437
+ } catch {
438
+ return false;
439
+ }
440
+ }, "must be a host name such as \"status.example.com\" (lowercase, with a port only if it is not 443), without a scheme or path");
441
+ var adminHostsSchema = z.union([z.literal("baseUrl"), z.array(hostSchema).min(1, "must list at least one host name, or be \"baseUrl\"").superRefine((hosts, ctx) => {
442
+ hosts.forEach((host, index) => {
443
+ if (hosts.indexOf(host) !== index) ctx.addIssue({
444
+ code: "custom",
445
+ message: `"${host}" is listed twice`,
446
+ path: [index]
447
+ });
448
+ });
449
+ })]);
450
+ var notificationsSchema = z.strictObject({ unknownCheckInterval: durationSchema().refine((ms) => ms % MINUTE_MS === 0 && ms >= MINUTE_MS && ms <= 60 * MINUTE_MS, { message: "must be whole minutes from \"1m\" to \"1h\" (the Cron runs every minute)" }).prefault("1m") }).prefault({});
451
+ var authSchema = z.custom((value) => isObject(value) && typeof value["type"] === "string" && typeof value["authenticate"] === "function", "must be an auth provider (an object with `type` and `authenticate()`)");
452
+ var TOP_LEVEL_KEYS = /* @__PURE__ */ new Set([
453
+ "timezone",
454
+ "location",
455
+ "retention",
456
+ "auth",
457
+ "notifiers",
458
+ "locale",
459
+ "baseUrl",
460
+ "notifications",
461
+ "monitors",
462
+ "pages",
463
+ "publicApi",
464
+ "adminHosts"
465
+ ]);
466
+ var RESERVED_SETTING_KEYS = new Set(RESERVED_MONITOR_KEYS);
467
+ /** `value` without its `undefined` properties, so that resolved objects compare equal to what was written. */
468
+ function stripUndefined(value) {
469
+ return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
470
+ }
471
+ function isObject(value) {
472
+ return typeof value === "object" && value !== null;
473
+ }
474
+ function isSchema(value) {
475
+ return isObject(value) && typeof value["safeParse"] === "function";
476
+ }
477
+ function isNotifierKind(value) {
478
+ return isObject(value) && typeof value["type"] === "string" && isSchema(value["options"]) && Array.isArray(value["secretOptions"]) && typeof value["send"] === "function";
479
+ }
480
+ function isMonitorDefinition(value) {
481
+ if (!isObject(value)) return false;
482
+ const provider = value["provider"];
483
+ return isObject(provider) && typeof provider["type"] === "string" && typeof provider["check"] === "function" && Array.isArray(provider["requires"]) && isSchema(provider["options"]) && isObject(value["settings"]) && isObject(value["options"]);
484
+ }
485
+ function joinPath(base, segments) {
486
+ let path = base;
487
+ for (const segment of segments) if (typeof segment === "number") path += `[${segment}]`;
488
+ else path += path === "" ? String(segment) : `.${String(segment)}`;
489
+ return path;
490
+ }
491
+ /**
492
+ * Validates a configuration and applies defaults. Call it when the Worker loads, so that a
493
+ * broken configuration fails the deployment instead of failing at run time.
494
+ * @throws ConfigError listing every problem found.
495
+ */
496
+ function resolveConfig(config, { runners, reservedSecrets = [] }) {
497
+ const issues = [];
498
+ const report = (path, message) => issues.push({
499
+ path,
500
+ message
501
+ });
502
+ const collect = (base, found) => {
503
+ for (const issue of found) report(joinPath(base, issue.path), issue.message);
504
+ };
505
+ const parse = (schema, value, path) => {
506
+ const result = schema.safeParse(value);
507
+ if (result.success) return result.data;
508
+ collect(path, result.error.issues);
509
+ };
510
+ if (!isObject(config)) throw new ConfigError([{
511
+ path: "",
512
+ message: "must be an object passed to defineConfig()"
513
+ }]);
514
+ const input = config;
515
+ for (const key of Object.keys(input)) if (!TOP_LEVEL_KEYS.has(key)) report("", `Unrecognized key: "${key}"`);
516
+ const timezone = parse(timezoneSchema.prefault("UTC"), input["timezone"], "timezone");
517
+ const location = parse(z.enum(LOCATION_HINTS).optional(), input["location"], "location");
518
+ const retention = parse(durationSchema().refine((ms) => ms >= DAY_MS, "must be at least 1d").optional(), input["retention"], "retention");
519
+ const auth = parse(authSchema.optional(), input["auth"], "auth");
520
+ const notifierEntries = parse(z.array(z.unknown()).default([]), input["notifiers"], "notifiers") ?? [];
521
+ const monitorEntries = parse(z.array(z.unknown()).default([]), input["monitors"], "monitors") ?? [];
522
+ const pageEntries = parse(z.array(z.unknown()).default([]), input["pages"], "pages") ?? [];
523
+ const publicApi = parse(publicApiSchema, input["publicApi"], "publicApi");
524
+ const locale = parse(localeSchema.prefault("en"), input["locale"], "locale");
525
+ const baseUrl = parse(baseUrlSchema.optional(), input["baseUrl"], "baseUrl");
526
+ const notifications = parse(notificationsSchema, input["notifications"], "notifications");
527
+ const adminHostsInput = parse(adminHostsSchema.optional(), input["adminHosts"], "adminHosts");
528
+ let adminHosts = null;
529
+ if (adminHostsInput === "baseUrl") {
530
+ if (baseUrl === void 0) {
531
+ if (input["baseUrl"] === void 0) report("adminHosts", "\"baseUrl\" needs `baseUrl` to be set");
532
+ } else adminHosts = [new URL(baseUrl).host];
533
+ } else if (adminHostsInput !== void 0) adminHosts = adminHostsInput;
534
+ const runnerIds = /* @__PURE__ */ new Set();
535
+ for (const runner of runners) {
536
+ if (runnerIds.has(runner.id)) report("", `duplicate runner ID "${runner.id}"`);
537
+ runnerIds.add(runner.id);
538
+ }
539
+ const defaultRunner = runners[0];
540
+ if (defaultRunner === void 0 && monitorEntries.length > 0) report("", "no runner is available to run monitors");
541
+ const notifiers = [];
542
+ const firstIndexOfNotifier = /* @__PURE__ */ new Map();
543
+ notifierEntries.forEach((notifier, index) => {
544
+ const path = `notifiers[${index}]`;
545
+ if (!isNotifierKind(notifier)) {
546
+ report(path, "must be a notifier kind (an object with `type`, an `options` schema, `secretOptions` and `send()`)");
547
+ return;
548
+ }
549
+ const first = firstIndexOfNotifier.get(notifier.type);
550
+ if (first !== void 0) {
551
+ report(path, `duplicate notifier type "${notifier.type}" (also used by notifiers[${first}])`);
552
+ return;
553
+ }
554
+ firstIndexOfNotifier.set(notifier.type, index);
555
+ notifiers.push(notifier);
556
+ });
557
+ const definitions = monitorEntries.filter(isMonitorDefinition);
558
+ const declaredMonitorIds = new Set(definitions.flatMap((definition) => typeof definition.settings.id === "string" ? [definition.settings.id] : []));
559
+ const firstIndexOfMonitor = /* @__PURE__ */ new Map();
560
+ const monitors = [];
561
+ monitorEntries.forEach((entry, index) => {
562
+ if (!isMonitorDefinition(entry)) {
563
+ report(`monitors[${index}]`, "must be created by a provider factory such as http({ … })");
564
+ return;
565
+ }
566
+ const rawSettings = { ...entry.settings };
567
+ const rawId = rawSettings["id"];
568
+ const base = typeof rawId === "string" ? `monitors[${index}] ("${rawId}")` : `monitors[${index}]`;
569
+ const { provider } = entry;
570
+ for (const key of Object.keys(rawSettings)) if (RESERVED_SETTING_KEYS.has(key)) report(`${base}.${key}`, `"${key}" is reserved for a future monitor setting`);
571
+ const settings = parse(monitorSettingsSchema, Object.fromEntries(Object.entries(rawSettings).filter(([key]) => !RESERVED_SETTING_KEYS.has(key))), base);
572
+ const options = parse(provider.options, entry.options, base);
573
+ const assigned = defaultRunner === void 0 ? [] : [defaultRunner];
574
+ for (const runner of assigned) {
575
+ const missing = missingCapabilities(provider.requires, runner);
576
+ if (missing.length > 0) report(base, `provider "${provider.type}" requires ${missing.map((c) => `"${c}"`).join(", ")}, which runner "${runner.id}" does not provide`);
577
+ }
578
+ if (settings === void 0) return;
579
+ const { id, interval, timeout, confirmation } = settings;
580
+ const first = firstIndexOfMonitor.get(id);
581
+ if (first !== void 0) {
582
+ report(`${base}.id`, `duplicate monitor ID (also used by monitors[${first}])`);
583
+ return;
584
+ }
585
+ firstIndexOfMonitor.set(id, index);
586
+ if (confirmation.recheckInterval > interval) report(`${base}.confirmation.recheckInterval`, `must not be longer than interval (${formatDuration(interval)})`);
587
+ if (timeout >= interval) report(`${base}.timeout`, rawSettings["timeout"] === void 0 ? `the default timeout (${DEFAULT_TIMEOUT}) must be shorter than interval (${formatDuration(interval)}); set a shorter timeout` : `must be shorter than interval (${formatDuration(interval)})`);
588
+ if (retention !== void 0 && interval * MIN_INTERVALS_RETAINED > retention) report(`${base}.interval`, `must be at most 1/${MIN_INTERVALS_RETAINED} of retention (${formatDuration(retention)}), so that retention keeps enough results`);
589
+ for (const runner of assigned) if (runner.maxTimeoutMs !== void 0 && timeout > runner.maxTimeoutMs) report(`${base}.timeout`, `must not be longer than ${formatDuration(runner.maxTimeoutMs)}, the limit of runner "${runner.id}"`);
590
+ if (options === void 0) return;
591
+ for (const name of secretNames(options)) if (reservedSecrets.includes(name)) report(base, `must not use secret("${name}"): it is the hub's own secret and must never be sent to a monitored endpoint`);
592
+ monitors.push({
593
+ id,
594
+ name: settings.name ?? id,
595
+ provider,
596
+ options,
597
+ secrets: secretNames(options),
598
+ intervalMs: interval,
599
+ timeoutMs: timeout,
600
+ location: settings.location ?? location,
601
+ confirmation: {
602
+ failureThreshold: confirmation.failureThreshold,
603
+ successThreshold: confirmation.successThreshold,
604
+ recheckIntervalMs: confirmation.recheckInterval
605
+ },
606
+ runners: assigned.map((runner) => runner.id)
607
+ });
608
+ });
609
+ const monitorNames = new Map(monitors.map((monitor) => [monitor.id, monitor.name]));
610
+ const firstIndexOfPage = /* @__PURE__ */ new Map();
611
+ const pages = [];
612
+ pageEntries.forEach((entry, pageIndex) => {
613
+ const pageBase = `pages[${pageIndex}]`;
614
+ const page = parse(pageSchema, entry, pageBase);
615
+ if (page !== void 0) {
616
+ const firstPage = firstIndexOfPage.get(page.id);
617
+ if (firstPage === void 0) firstIndexOfPage.set(page.id, pageIndex);
618
+ else report(`${pageBase}.id`, `duplicate page ID "${page.id}" (also used by pages[${firstPage}])`);
619
+ }
620
+ const componentEntries = page?.components ?? (isObject(entry) && Array.isArray(entry["components"]) ? entry["components"] : []);
621
+ const firstUseOfId = /* @__PURE__ */ new Map();
622
+ const components = [];
623
+ const groups = [];
624
+ const claimId = (id, path, where, group) => {
625
+ const first = firstUseOfId.get(id);
626
+ if (first === void 0) {
627
+ firstUseOfId.set(id, {
628
+ where,
629
+ group
630
+ });
631
+ return true;
632
+ }
633
+ report(`${path}.id`, !group && !first.group ? `duplicate component ID "${id}" (also used by ${first.where})` : `duplicate ID "${id}" (also used by ${first.where}): components and groups need different IDs`);
634
+ return false;
635
+ };
636
+ const resolveComponent = (componentEntry, where) => {
637
+ const base = `${pageBase}.${where}`;
638
+ if (isGroupEntry(componentEntry)) {
639
+ report(base, "groups cannot contain groups");
640
+ return;
641
+ }
642
+ const parsed = parse(componentSchema, componentEntry, base);
643
+ if (parsed === void 0) return void 0;
644
+ const { id, monitors: monitorIds } = parsed;
645
+ monitorIds.forEach((monitorId, monitorIndex) => {
646
+ if (!declaredMonitorIds.has(monitorId)) report(`${base}.monitors[${monitorIndex}]`, `unknown monitor "${monitorId}"`);
647
+ else if (monitorIds.indexOf(monitorId) !== monitorIndex) report(`${base}.monitors[${monitorIndex}]`, `monitor "${monitorId}" is listed twice`);
648
+ });
649
+ if (parsed.latency && monitorIds.length === 0) report(`${base}.latency`, "needs at least one monitor: response times come from the component's monitors");
650
+ const only = monitorIds.length === 1 ? monitorIds[0] : void 0;
651
+ const name = parsed.name ?? (only === void 0 ? void 0 : monitorNames.get(only) ?? only);
652
+ if (name === void 0) report(`${base}.name`, "is required unless the component has exactly one monitor");
653
+ if (!claimId(id, base, where, false)) return void 0;
654
+ return {
655
+ id,
656
+ name: name ?? id,
657
+ monitors: monitorIds,
658
+ latency: parsed.latency
659
+ };
660
+ };
661
+ componentEntries.forEach((componentEntry, componentIndex) => {
662
+ const where = `components[${componentIndex}]`;
663
+ if (!isGroupEntry(componentEntry)) {
664
+ const resolved = resolveComponent(componentEntry, where);
665
+ if (resolved !== void 0) components.push(resolved);
666
+ return;
667
+ }
668
+ const base = `${pageBase}.${where}`;
669
+ const group = parse(groupSchema, componentEntry, base);
670
+ const memberEntries = group?.components ?? (isObject(componentEntry) && Array.isArray(componentEntry["components"]) ? componentEntry["components"] : []);
671
+ const claimed = group !== void 0 && claimId(group.id, base, where, true);
672
+ const members = [];
673
+ memberEntries.forEach((memberEntry, memberIndex) => {
674
+ const resolved = resolveComponent(memberEntry, `${where}.components[${memberIndex}]`);
675
+ if (resolved === void 0) return;
676
+ components.push(resolved);
677
+ members.push(resolved.id);
678
+ });
679
+ if (group !== void 0 && claimed && members.length > 0) groups.push({
680
+ id: group.id,
681
+ name: group.name,
682
+ components: members
683
+ });
684
+ });
685
+ if (page !== void 0) pages.push({
686
+ id: page.id,
687
+ template: page.template,
688
+ reportUrl: page.reportUrl ?? null,
689
+ incidents: {
690
+ auto: page.incidents.auto,
691
+ templates: stripUndefined(page.incidents.templates),
692
+ reopenWithinMs: page.incidents.reopenWithin
693
+ },
694
+ components,
695
+ groups
696
+ });
697
+ });
698
+ if (issues.length > 0 || timezone === void 0 || publicApi === void 0 || locale === void 0 || notifications === void 0) throw new ConfigError(issues);
699
+ return {
700
+ timezone,
701
+ retentionMs: retention ?? null,
702
+ auth,
703
+ notifiers,
704
+ locale,
705
+ baseUrl: baseUrl ?? null,
706
+ notifications: { unknownCheckIntervalMs: notifications.unknownCheckInterval },
707
+ monitors,
708
+ pages,
709
+ publicApi: {
710
+ cache: publicApi.cache,
711
+ allowedOrigins: publicApi.allowedOrigins
712
+ },
713
+ adminHosts
714
+ };
715
+ }
716
+ // ../core/src/display.ts
717
+ /**
718
+ * Severity for "the worst state": `down` > `degraded` > `unknown` > `up`. `unknown`
719
+ * means results are missing, which is not necessarily an outage, so a known problem
720
+ * (`degraded`) outranks it.
721
+ */
722
+ var RANK = {
723
+ up: 0,
724
+ unknown: 1,
725
+ degraded: 2,
726
+ down: 3
727
+ };
728
+ function isCheckState(state) {
729
+ return state === "up" || state === "degraded" || state === "down";
730
+ }
731
+ /** The worse of two states. */
732
+ function worseOf(a, b) {
733
+ return RANK[b] > RANK[a] ? b : a;
734
+ }
735
+ /** The worst of `states`, or `empty` when there are none. */
736
+ function worstState(states, empty) {
737
+ let worst;
738
+ for (const state of states) worst = worst === void 0 ? state : worseOf(worst, state);
739
+ return worst ?? empty;
740
+ }
741
+ /**
742
+ * Slack on top of the schedule before a monitor counts as late: the runner's and the Monitor
743
+ * DO's grace periods after a check's timeout (10 seconds), alarms that fire late, and clock
744
+ * differences between Durable Objects.
745
+ */
746
+ var LATE_GRACE_MS = 6e4;
747
+ /**
748
+ * How long a monitor may go without a check that produced a state before it is `unknown`: two intervals, plus the check's timeout and {@link LATE_GRACE_MS}.
749
+ *
750
+ * A check's result is recorded when the check ends, up to its timeout (plus grace) after the
751
+ * slot it ran for. Two intervals tolerate one missed result (a transient runner error, a
752
+ * check that produced no result) without flapping to `unknown`; the second missed result in
753
+ * a row makes the monitor `unknown`, before the third slot is due. With a 1-minute interval
754
+ * and a 10-second timeout that is 3 minutes 10 seconds.
755
+ *
756
+ * The status page uses this for the live state and for every past moment of the history,
757
+ * and the every-minute Cron uses it to notify `unknown`, so the three agree.
758
+ */
759
+ function staleAfterMs(intervalMs, timeoutMs) {
760
+ return 2 * intervalMs + timeoutMs + LATE_GRACE_MS;
761
+ }
762
+ /**
763
+ * A monitor's state at display time: its confirmed state, unless its latest result
764
+ * is late for its schedule or it has no confirmed state (including `unconfirmed` after
765
+ * resuming). Lateness counts from the later of the latest result and the start of the
766
+ * current schedule period, so a new interval gets a fresh allowance, and it is checked
767
+ * before the confirmed state, so that a monitor that never produces a result is `late`.
768
+ */
769
+ function displayState(reading, timeoutMs, now) {
770
+ const { current, period } = reading;
771
+ if (period === null || period.status !== "active" || period.intervalMs === null || current?.state === "stopped") return {
772
+ state: "unknown",
773
+ unknownReason: "stopped"
774
+ };
775
+ if (now - Math.max(reading.lastResultAt ?? Number.NEGATIVE_INFINITY, period.from) > staleAfterMs(period.intervalMs, timeoutMs)) return {
776
+ state: "unknown",
777
+ unknownReason: "late"
778
+ };
779
+ if (current === null || !isCheckState(current.state)) return {
780
+ state: "unknown",
781
+ unknownReason: "unconfirmed"
782
+ };
783
+ return {
784
+ state: current.state,
785
+ unknownReason: null
786
+ };
787
+ }
788
+ /**
789
+ * A component's current state: the worst of its monitors' display states and the
790
+ * impacts of the unresolved incidents that affect it, so that a person's judgement can
791
+ * override the automatic one. A component without monitors takes its state from incidents
792
+ * alone, and is `up` without any. Maintenance is not a state: it is shown next to it.
793
+ */
794
+ function componentState(monitorStates, openIncidentImpacts) {
795
+ const states = [...monitorStates];
796
+ for (const impact of openIncidentImpacts) if (impact !== "none") states.push(impact);
797
+ return worstState(states, "up");
798
+ }
799
+ // ../core/src/timeline.ts
800
+ /**
801
+ * Timelines of states for history and uptime: what a monitor's confirmed states,
802
+ * schedule and results say about each moment, combined per component. Pure functions, so
803
+ * that the Worker, the status pages and tests share one definition.
804
+ */
805
+ /** Index of the first value `>= target` in a sorted array. */
806
+ function lowerBound(values, target) {
807
+ let low = 0;
808
+ let high = values.length;
809
+ while (low < high) {
810
+ const middle = low + high >>> 1;
811
+ if (values[middle] < target) low = middle + 1;
812
+ else high = middle;
813
+ }
814
+ return low;
815
+ }
816
+ /** Appends a segment, merging it into the previous one when they touch and have the same state. */
817
+ function append(segments, from, to, state) {
818
+ if (to <= from) return;
819
+ const last = segments.at(-1);
820
+ if (last !== void 0 && last.to === from && last.state === state) segments[segments.length - 1] = {
821
+ from: last.from,
822
+ to,
823
+ state
824
+ };
825
+ else segments.push({
826
+ from,
827
+ to,
828
+ state
829
+ });
830
+ }
831
+ /** `a` followed by `b` (which starts where `a` ends, or later), merging at the seam. */
832
+ function concatSegments(a, b) {
833
+ const result = [...a];
834
+ for (const segment of b) append(result, segment.from, segment.to, segment.state);
835
+ return result;
836
+ }
837
+ /**
838
+ * Where a monitor is late inside one active schedule period and `range`: from
839
+ * `staleAfterMs` after the latest anchor until the next one, where an anchor is the start of
840
+ * the period or a check that produced a state. This is the display-time rule (see
841
+ * `displayState`) applied to every past moment, so the history shows `unknown` exactly when
842
+ * the live page did.
843
+ *
844
+ * Results from before the range are needed to judge its start: with none in the
845
+ * `staleAfterMs` before it, the monitor is late from the range's start on.
846
+ */
847
+ function lateSpans(period, range, resultTimes, staleAfterMs) {
848
+ const low = Math.max(period.from, range.from);
849
+ const high = Math.min(period.to ?? Number.POSITIVE_INFINITY, range.to);
850
+ if (low >= high) return [];
851
+ const spans = [];
852
+ const push = (from, to) => {
853
+ const clippedFrom = Math.max(from, low);
854
+ const clippedTo = Math.min(to, high);
855
+ if (clippedFrom < clippedTo) spans.push({
856
+ from: clippedFrom,
857
+ to: clippedTo
858
+ });
859
+ };
860
+ let anchor = Math.max(period.from, range.from - staleAfterMs);
861
+ for (let index = lowerBound(resultTimes, anchor); index < resultTimes.length; index++) {
862
+ const at = resultTimes[index];
863
+ if (at >= high) break;
864
+ if (at - anchor > staleAfterMs) push(anchor + staleAfterMs, at);
865
+ anchor = at;
866
+ }
867
+ if (high - anchor > staleAfterMs) push(anchor + staleAfterMs, high);
868
+ return spans;
869
+ }
870
+ /**
871
+ * The display state of a monitor at every moment of `range`:
872
+ *
873
+ * - outside active schedule periods (before it started, or `stopped`): no segment, which is
874
+ * neither uptime nor downtime;
875
+ * - while late (see {@link lateSpans}): `unknown`;
876
+ * - otherwise the confirmed state in effect, or `unknown` before any is confirmed and while
877
+ * `unconfirmed` after resuming.
878
+ *
879
+ * `staleAfter` gives the lateness threshold for a period's interval (see `staleAfterMs`).
880
+ */
881
+ function monitorTimeline(range, source, staleAfter) {
882
+ const active = [];
883
+ const late = [];
884
+ for (const period of source.periods) {
885
+ if (period.status !== "active" || period.intervalMs === null) continue;
886
+ const from = Math.max(range.from, period.from);
887
+ const to = Math.min(range.to, period.to ?? Number.POSITIVE_INFINITY);
888
+ if (from >= to) continue;
889
+ active.push({
890
+ from,
891
+ to
892
+ });
893
+ late.push(...lateSpans(period, range, source.resultTimes, staleAfter(period.intervalMs)));
894
+ }
895
+ if (active.length === 0) return [];
896
+ const records = [...source.atStart === null ? [] : [source.atStart], ...source.changes];
897
+ const points = /* @__PURE__ */ new Set();
898
+ for (const list of [active, late]) for (const part of list) {
899
+ points.add(part.from);
900
+ points.add(part.to);
901
+ }
902
+ for (const record of records) if (record.since > range.from && record.since < range.to) points.add(record.since);
903
+ const sorted = [...points].sort((a, b) => a - b);
904
+ const segments = [];
905
+ let activeIndex = 0;
906
+ let lateIndex = 0;
907
+ let recordIndex = -1;
908
+ for (let index = 0; index + 1 < sorted.length; index++) {
909
+ const from = sorted[index];
910
+ const to = sorted[index + 1];
911
+ while (activeIndex < active.length && active[activeIndex].to <= from) activeIndex++;
912
+ const part = active[activeIndex];
913
+ if (part === void 0 || part.from > from) continue;
914
+ while (lateIndex < late.length && late[lateIndex].to <= from) lateIndex++;
915
+ const span = late[lateIndex];
916
+ if (span !== void 0 && span.from <= from) {
917
+ append(segments, from, to, "unknown");
918
+ continue;
919
+ }
920
+ while (recordIndex + 1 < records.length && records[recordIndex + 1].since <= from) recordIndex++;
921
+ const state = records[recordIndex]?.state;
922
+ append(segments, from, to, state !== void 0 && isCheckState(state) ? state : "unknown");
923
+ }
924
+ return segments;
925
+ }
926
+ /**
927
+ * A component's timeline from its monitors': at each moment, the worst state of
928
+ * the monitors that have data then (`down` > `degraded` > `unknown` > `up`). Moments where
929
+ * none of them has data have no segment.
930
+ */
931
+ function combineTimelines(timelines) {
932
+ if (timelines.length === 1) return [...timelines[0]];
933
+ const points = /* @__PURE__ */ new Set();
934
+ for (const timeline of timelines) for (const segment of timeline) {
935
+ points.add(segment.from);
936
+ points.add(segment.to);
937
+ }
938
+ const sorted = [...points].sort((a, b) => a - b);
939
+ const cursors = timelines.map(() => 0);
940
+ const result = [];
941
+ for (let index = 0; index + 1 < sorted.length; index++) {
942
+ const from = sorted[index];
943
+ const to = sorted[index + 1];
944
+ let worst;
945
+ timelines.forEach((timeline, which) => {
946
+ let cursor = cursors[which];
947
+ while (cursor < timeline.length && timeline[cursor].to <= from) cursor++;
948
+ cursors[which] = cursor;
949
+ const segment = timeline[cursor];
950
+ if (segment !== void 0 && segment.from <= from) worst = worst === void 0 ? segment.state : worseOf(worst, segment.state);
951
+ });
952
+ if (worst !== void 0) append(result, from, to, worst);
953
+ }
954
+ return result;
955
+ }
956
+ /** Sorted, non-overlapping ranges covering the same time as `ranges`. */
957
+ function mergeRanges(ranges) {
958
+ const sorted = ranges.filter((range) => range.from < range.to).sort((a, b) => a.from - b.from);
959
+ const merged = [];
960
+ for (const range of sorted) {
961
+ const last = merged.at(-1);
962
+ if (last !== void 0 && range.from <= last.to) merged[merged.length - 1] = {
963
+ from: last.from,
964
+ to: Math.max(last.to, range.to)
965
+ };
966
+ else merged.push(range);
967
+ }
968
+ return merged;
969
+ }
970
+ /** `segments` without the time inside `windows` (maintenance: excluded from uptime). */
971
+ function excludeWindows(segments, windows) {
972
+ const cuts = mergeRanges(windows);
973
+ if (cuts.length === 0) return [...segments];
974
+ const result = [];
975
+ for (const segment of segments) {
976
+ let from = segment.from;
977
+ for (const cut of cuts) {
978
+ if (cut.to <= from) continue;
979
+ if (cut.from >= segment.to) break;
980
+ if (cut.from > from) result.push({
981
+ from,
982
+ to: cut.from,
983
+ state: segment.state
984
+ });
985
+ from = Math.max(from, cut.to);
986
+ if (from >= segment.to) break;
987
+ }
988
+ if (from < segment.to) result.push({
989
+ from,
990
+ to: segment.to,
991
+ state: segment.state
992
+ });
993
+ }
994
+ return result;
995
+ }
996
+ var CONFIRMED_RANK = {
997
+ up: 0,
998
+ degraded: 1,
999
+ down: 2
1000
+ };
1001
+ function summarize(segments) {
1002
+ let upMs = 0;
1003
+ let downMs = 0;
1004
+ let degradedMs = 0;
1005
+ let unknownMs = 0;
1006
+ let worst = null;
1007
+ for (const segment of segments) {
1008
+ const length = segment.to - segment.from;
1009
+ if (segment.state === "unknown") {
1010
+ unknownMs += length;
1011
+ continue;
1012
+ }
1013
+ if (segment.state === "down") downMs += length;
1014
+ else upMs += length;
1015
+ if (segment.state === "degraded") degradedMs += length;
1016
+ if (worst === null || CONFIRMED_RANK[segment.state] > CONFIRMED_RANK[worst]) worst = segment.state;
1017
+ }
1018
+ return {
1019
+ upMs,
1020
+ downMs,
1021
+ degradedMs,
1022
+ unknownMs,
1023
+ worst
1024
+ };
1025
+ }
1026
+ /**
1027
+ * Uptime as a ratio: time `up` or `degraded` over time with a confirmed state. `null`
1028
+ * when no time had a confirmed state (everything unknown, stopped or under maintenance).
1029
+ */
1030
+ function uptimeRatio(upMs, downMs) {
1031
+ const known = upMs + downMs;
1032
+ return known > 0 ? upMs / known : null;
1033
+ }
1034
+ /**
1035
+ * Coverage: scheduled checks that produced a state over the checks the schedule
1036
+ * expected. At most 1 (a check near a range boundary can land in the next range). `null`
1037
+ * when nothing was expected.
1038
+ */
1039
+ function coverageRatio(obtained, expected) {
1040
+ return expected > 0 ? Math.min(1, obtained / expected) : null;
1041
+ }
1042
+ /**
1043
+ * The confirmed `down` periods in a state history (records oldest first): each lasts from its
1044
+ * record's `since` until the next record, whatever that is (recovery, `degraded`, a stop).
1045
+ */
1046
+ function downPeriods(records) {
1047
+ const periods = [];
1048
+ records.forEach((record, index) => {
1049
+ if (record.state !== "down") return;
1050
+ const next = records[index + 1];
1051
+ const last = periods.at(-1);
1052
+ if (last !== void 0 && last.to === record.since) periods[periods.length - 1] = {
1053
+ from: last.from,
1054
+ to: next?.since ?? null
1055
+ };
1056
+ else periods.push({
1057
+ from: record.since,
1058
+ to: next?.since ?? null
1059
+ });
1060
+ });
1061
+ return periods;
1062
+ }
1063
+ /** The union of `periods` (from several monitors), oldest first; an open period absorbs what follows it. */
1064
+ function mergeDownPeriods(periods) {
1065
+ const sorted = [...periods].sort((a, b) => a.from - b.from);
1066
+ const merged = [];
1067
+ for (const period of sorted) {
1068
+ const last = merged.at(-1);
1069
+ if (last !== void 0 && (last.to === null || period.from <= last.to)) {
1070
+ const to = last.to === null || period.to === null ? null : Math.max(last.to, period.to);
1071
+ merged[merged.length - 1] = {
1072
+ from: last.from,
1073
+ to
1074
+ };
1075
+ } else merged.push(period);
1076
+ }
1077
+ return merged;
1078
+ }
1079
+ export { addDays as A, resolveConfig as C, parseDuration as D, durationSchema as E, localDate as M, recentDays as N, confirmState as O, startOfLocalDay as P, defineConfig as S, LOCATION_HINTS as T, worseOf as _, excludeWindows as a, INCIDENT_TEMPLATE_PLACEHOLDERS as b, mergeRanges as c, uptimeRatio as d, LATE_GRACE_MS as f, staleAfterMs as g, isCheckState as h, downPeriods as i, calendarDay as j, observationsNeeded as k, monitorTimeline as l, displayState as m, concatSegments as n, lateSpans as o, componentState as p, coverageRatio as r, mergeDownPeriods as s, combineTimelines as t, summarize as u, worstState as v, missingCapabilities as w, component as x, ConfigError as y };
1080
+
1081
+ //# sourceMappingURL=timeline-YJXjehRf.js.map