@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.
- 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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cf-workers-status-page contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @naosystem/cf-workers-status-page
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Cloudflare Workers と Durable Objects で動く、セルフホストの死活監視とステータスページです。この npm パッケージを使うと、自分のリポジトリには設定(`status.config.ts` と `wrangler.jsonc`)だけを置き、本体はパッケージの版を上げて更新できます。
|
|
4
|
+
|
|
5
|
+
Self-hosted uptime monitoring and status pages on Cloudflare Workers and Durable Objects. With
|
|
6
|
+
this npm package, your repository holds only your configuration (`status.config.ts` and
|
|
7
|
+
`wrangler.jsonc`), and you update by raising the package's version.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
git clone --depth 1 https://github.com/naosystem-jp/cf-workers-status-page.git
|
|
11
|
+
cp -r cf-workers-status-page/templates/starter my-status-page
|
|
12
|
+
cd my-status-page
|
|
13
|
+
npm install
|
|
14
|
+
npx wrangler login
|
|
15
|
+
npm run deploy
|
|
16
|
+
echo "k1:$(openssl rand -base64 32)" | npx wrangler secret put NOTIFICATION_KEYS
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
使い方、設定、運用のすべては、リポジトリの README にあります(日本語と英語)。
|
|
20
|
+
|
|
21
|
+
Everything else (setup, configuration, operation) is in the repository's README, in Japanese and
|
|
22
|
+
English: [Use the npm package](https://github.com/naosystem-jp/cf-workers-status-page#use-the-npm-package).
|
|
23
|
+
|
|
24
|
+
| Import | Contents |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| `@naosystem/cf-workers-status-page` | `defineConfig`, `component`, `secret`, `http` and the configuration's types |
|
|
27
|
+
| `@naosystem/cf-workers-status-page/notifier-slack`, `/notifier-discord`, `/notifier-webhook` | Notifier kinds |
|
|
28
|
+
| `@naosystem/cf-workers-status-page/auth-cloudflare-access` | Admin authentication with Cloudflare Access |
|
|
29
|
+
| `@naosystem/cf-workers-status-page/vite` | The Vite plugin (`statusPage()`) that builds the Worker |
|
|
30
|
+
|
|
31
|
+
1.0 までは、マイナーバージョンの更新でも互換性のない変更が入ることがあります。
|
|
32
|
+
|
|
33
|
+
Until 1.0, a minor version may bring incompatible changes.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT. The status page and the admin UI include code from other packages, each under its own
|
|
38
|
+
license: see `dist/client/licenses/third-party.txt`. The bundled fonts (Inter and Noto Sans JP)
|
|
39
|
+
are under the SIL Open Font License 1.1: see `dist/client/licenses/fonts.txt`.
|
package/dist/admin.html
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta name="robots" content="noindex" />
|
|
7
|
+
<title>Status admin</title>
|
|
8
|
+
<script type="module" crossorigin src="/assets/admin-BBJxKTF6.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/assets/src-BDi4qpij.js">
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/assets/src-C6ZFz-Gu.css">
|
|
11
|
+
<link rel="stylesheet" crossorigin href="/assets/admin-Be4X0WFj.css">
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<!-- The admin UI. Served only by the Worker, after authentication. -->
|
|
15
|
+
<div id="admin-root"></div>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
// ../auth-cloudflare-access/src/jwt.ts
|
|
2
|
+
/**
|
|
3
|
+
* Just enough JSON Web Token handling for Cloudflare Access application tokens: RS256
|
|
4
|
+
* signatures (RSASSA-PKCS1-v1_5 with SHA-256) over WebCrypto, keys from a JWKS document.
|
|
5
|
+
* Standard web APIs only, so the package runs on any runtime.
|
|
6
|
+
*/
|
|
7
|
+
/** The only algorithm Access signs application tokens with. Pinned: the token's `alg` must match. */
|
|
8
|
+
var ALGORITHM = "RS256";
|
|
9
|
+
var IMPORT_PARAMS = {
|
|
10
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
11
|
+
hash: "SHA-256"
|
|
12
|
+
};
|
|
13
|
+
var BASE64URL = /^[A-Za-z0-9_-]*$/;
|
|
14
|
+
var TokenError = class extends Error {
|
|
15
|
+
name = "TokenError";
|
|
16
|
+
};
|
|
17
|
+
function base64UrlDecode(part) {
|
|
18
|
+
if (!BASE64URL.test(part) || part.length % 4 === 1) throw new TokenError("malformed base64url");
|
|
19
|
+
const base64 = part.replaceAll("-", "+").replaceAll("_", "/") + "=".repeat((4 - part.length % 4) % 4);
|
|
20
|
+
const binary = atob(base64);
|
|
21
|
+
const bytes = new Uint8Array(binary.length);
|
|
22
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
23
|
+
return bytes;
|
|
24
|
+
}
|
|
25
|
+
function decodeJsonObject(part, what) {
|
|
26
|
+
let value;
|
|
27
|
+
try {
|
|
28
|
+
value = JSON.parse(new TextDecoder("utf-8", {
|
|
29
|
+
fatal: true,
|
|
30
|
+
ignoreBOM: false
|
|
31
|
+
}).decode(base64UrlDecode(part)));
|
|
32
|
+
} catch {
|
|
33
|
+
throw new TokenError(`malformed ${what}`);
|
|
34
|
+
}
|
|
35
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TokenError(`malformed ${what}`);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
/** Splits and decodes a compact JWS. Checks the format only, not the signature or claims. */
|
|
39
|
+
function decodeToken(token) {
|
|
40
|
+
const parts = token.split(".");
|
|
41
|
+
if (parts.length !== 3) throw new TokenError("not a compact JWT");
|
|
42
|
+
const [header, payload, signature] = parts;
|
|
43
|
+
if (header === "" || payload === "" || signature === "") throw new TokenError("not a compact JWT");
|
|
44
|
+
return {
|
|
45
|
+
header: decodeJsonObject(header, "header"),
|
|
46
|
+
payload: decodeJsonObject(payload, "payload"),
|
|
47
|
+
signingInput: `${header}.${payload}`,
|
|
48
|
+
signature: base64UrlDecode(signature)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Verifies the token's RS256 signature with `key`. */
|
|
52
|
+
function verifySignature(token, key) {
|
|
53
|
+
return crypto.subtle.verify(IMPORT_PARAMS.name, key, token.signature, new TextEncoder().encode(token.signingInput));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Imports the RSA signing keys of a JWKS document (`{ keys: [...] }`). Keys that are not
|
|
57
|
+
* RSA, declare another algorithm or use, or fail to import are skipped.
|
|
58
|
+
* @throws TokenError when the document has no usable key.
|
|
59
|
+
*/
|
|
60
|
+
async function importKeySet(document) {
|
|
61
|
+
const entries = typeof document === "object" && document !== null && Array.isArray(document.keys) ? document.keys : [];
|
|
62
|
+
const keys = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
65
|
+
const { kid, kty, alg, use, n, e } = entry;
|
|
66
|
+
if (typeof kid !== "string" || kid === "" || kty !== "RSA") continue;
|
|
67
|
+
if (alg !== void 0 && alg !== "RS256") continue;
|
|
68
|
+
if (use !== void 0 && use !== "sig") continue;
|
|
69
|
+
if (typeof n !== "string" || typeof e !== "string") continue;
|
|
70
|
+
try {
|
|
71
|
+
const key = await crypto.subtle.importKey("jwk", {
|
|
72
|
+
kty: "RSA",
|
|
73
|
+
n,
|
|
74
|
+
e,
|
|
75
|
+
alg: ALGORITHM,
|
|
76
|
+
ext: true
|
|
77
|
+
}, IMPORT_PARAMS, false, ["verify"]);
|
|
78
|
+
keys.set(kid, key);
|
|
79
|
+
} catch {}
|
|
80
|
+
}
|
|
81
|
+
if (keys.size === 0) throw new TokenError("the key set has no usable RS256 key");
|
|
82
|
+
return keys;
|
|
83
|
+
}
|
|
84
|
+
// ../auth-cloudflare-access/src/index.ts
|
|
85
|
+
/** The header Access adds to requests it lets through. Validated instead of the `CF_Authorization` cookie, as Cloudflare recommends. */
|
|
86
|
+
var ACCESS_JWT_HEADER = "Cf-Access-Jwt-Assertion";
|
|
87
|
+
/** Clock skew tolerated when checking `exp` and `nbf`. */
|
|
88
|
+
var CLOCK_TOLERANCE_MS = 3e4;
|
|
89
|
+
/** Cached keys older than this are refreshed in the background. */
|
|
90
|
+
var KEYS_FRESH_MS = 3e5;
|
|
91
|
+
/** Cached keys older than this are not used: a request waits for fresh keys, or is rejected. */
|
|
92
|
+
var KEYS_MAX_AGE_MS = 36e5;
|
|
93
|
+
/** A token whose key ID is not cached refetches the keys at most this often. */
|
|
94
|
+
var UNKNOWN_KEY_REFETCH_MS = 3e4;
|
|
95
|
+
/** After a failed fetch of the keys, no new attempt for this long. */
|
|
96
|
+
var KEY_FETCH_BACKOFF_MS = 3e4;
|
|
97
|
+
/** How long fetching the keys may take. */
|
|
98
|
+
var FETCH_TIMEOUT_MS = 5e3;
|
|
99
|
+
var HOSTNAME = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;
|
|
100
|
+
function normalizeTeamDomain(value) {
|
|
101
|
+
if (typeof value !== "string") throw new TypeError("cloudflareAccess(): `teamDomain` must be a string");
|
|
102
|
+
const host = value.trim().toLowerCase().replace(/^https:\/\//, "").replace(/\/$/, "");
|
|
103
|
+
if (!HOSTNAME.test(host)) throw new TypeError(`cloudflareAccess(): \`teamDomain\` must be a host name such as "myteam.cloudflareaccess.com", not ${JSON.stringify(value)}`);
|
|
104
|
+
return host;
|
|
105
|
+
}
|
|
106
|
+
/** A list option as a set of trimmed values, after checking each with `valid`. */
|
|
107
|
+
function normalizeList(name, value, valid, normalize = (item) => item) {
|
|
108
|
+
const list = typeof value === "string" ? [value] : Array.isArray(value) ? value : [];
|
|
109
|
+
if (list.length === 0) throw new TypeError(`cloudflareAccess(): \`${name}\` must not be empty`);
|
|
110
|
+
for (const item of list) if (typeof item !== "string" || item.trim() !== item || !valid(item)) throw new TypeError(`cloudflareAccess(): invalid \`${name}\` entry ${JSON.stringify(item)}`);
|
|
111
|
+
return new Set(list.map(normalize));
|
|
112
|
+
}
|
|
113
|
+
function normalizeAllowList(options) {
|
|
114
|
+
const { allowedEmails, allowedDomains, allowedServiceTokens } = options;
|
|
115
|
+
if (allowedEmails === void 0 && allowedDomains === void 0 && allowedServiceTokens === void 0) return;
|
|
116
|
+
const lower = (item) => item.toLowerCase();
|
|
117
|
+
return {
|
|
118
|
+
emails: allowedEmails === void 0 ? /* @__PURE__ */ new Set() : normalizeList("allowedEmails", allowedEmails, (item) => /^[^@\s]+@[^@\s]+$/.test(item), lower),
|
|
119
|
+
domains: allowedDomains === void 0 ? /* @__PURE__ */ new Set() : normalizeList("allowedDomains", allowedDomains, (item) => HOSTNAME.test(item.toLowerCase()), lower),
|
|
120
|
+
serviceTokens: allowedServiceTokens === void 0 ? /* @__PURE__ */ new Set() : normalizeList("allowedServiceTokens", allowedServiceTokens, (item) => item !== "")
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/** The signing keys could not be fetched (or a failed fetch is too recent to try again). */
|
|
124
|
+
var KeyFetchError = class extends Error {
|
|
125
|
+
name = "KeyFetchError";
|
|
126
|
+
};
|
|
127
|
+
/** Waits for `promise` at most `ms`, with a timer of the caller's own. */
|
|
128
|
+
function withTimeout(promise, ms) {
|
|
129
|
+
let timer;
|
|
130
|
+
const timeout = new Promise((_, reject) => {
|
|
131
|
+
timer = setTimeout(() => reject(new KeyFetchError("timed out waiting for the signing keys")), ms);
|
|
132
|
+
});
|
|
133
|
+
return Promise.race([promise, timeout]).finally(() => {
|
|
134
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** The team's signing keys, cached per isolate. */
|
|
138
|
+
var KeyCache = class {
|
|
139
|
+
cached;
|
|
140
|
+
/** The fetch in progress, which other requests join. */
|
|
141
|
+
inFlight;
|
|
142
|
+
lastAttemptAt = Number.NEGATIVE_INFINITY;
|
|
143
|
+
failedAt = Number.NEGATIVE_INFINITY;
|
|
144
|
+
url;
|
|
145
|
+
constructor(url) {
|
|
146
|
+
this.url = url;
|
|
147
|
+
}
|
|
148
|
+
/** The key with ID `kid`, or `undefined` when the team does not publish it. @throws KeyFetchError */
|
|
149
|
+
async get(kid, ctx) {
|
|
150
|
+
const now = Date.now();
|
|
151
|
+
let cached = this.cached;
|
|
152
|
+
if (cached === void 0 || now - cached.fetchedAt >= 36e5) cached = await this.refresh(ctx);
|
|
153
|
+
else if (now - cached.fetchedAt >= 3e5 && this.inFlight === void 0) this.refresh(ctx).catch(() => {});
|
|
154
|
+
const key = cached.keys.get(kid);
|
|
155
|
+
if (key !== void 0 || Date.now() - this.lastAttemptAt < 3e4) return key;
|
|
156
|
+
return (await this.refresh(ctx)).keys.get(kid);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Fetches the keys, or joins the fetch in progress. Within {@link KEY_FETCH_BACKOFF_MS} of a
|
|
160
|
+
* failed fetch, rejects without fetching.
|
|
161
|
+
*/
|
|
162
|
+
refresh(ctx) {
|
|
163
|
+
if (this.inFlight !== void 0) return withTimeout(this.inFlight, 6e3);
|
|
164
|
+
if (Date.now() - this.failedAt < 3e4) return Promise.reject(new KeyFetchError("the last attempt to fetch the signing keys failed; retrying later"));
|
|
165
|
+
const startedAt = Date.now();
|
|
166
|
+
this.lastAttemptAt = startedAt;
|
|
167
|
+
const run = this.fetchKeys(ctx).then((keys) => {
|
|
168
|
+
this.failedAt = Number.NEGATIVE_INFINITY;
|
|
169
|
+
const fresh = {
|
|
170
|
+
keys,
|
|
171
|
+
fetchedAt: startedAt
|
|
172
|
+
};
|
|
173
|
+
if (this.cached === void 0 || this.cached.fetchedAt <= startedAt) this.cached = fresh;
|
|
174
|
+
return fresh;
|
|
175
|
+
}, (error) => {
|
|
176
|
+
this.failedAt = Date.now();
|
|
177
|
+
const message = `could not fetch the signing keys from ${this.url}: ${String(error)}`;
|
|
178
|
+
console.error(`Cloudflare Access: ${message}`);
|
|
179
|
+
throw new KeyFetchError(message);
|
|
180
|
+
}).finally(() => {
|
|
181
|
+
this.inFlight = void 0;
|
|
182
|
+
});
|
|
183
|
+
this.inFlight = run;
|
|
184
|
+
ctx.waitUntil(run.catch(() => {}));
|
|
185
|
+
return run;
|
|
186
|
+
}
|
|
187
|
+
async fetchKeys(ctx) {
|
|
188
|
+
const response = await ctx.fetch(this.url, {
|
|
189
|
+
headers: { Accept: "application/json" },
|
|
190
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
191
|
+
});
|
|
192
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
193
|
+
return importKeySet(await response.json());
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
/** The Access JWT verifier behind {@link cloudflareAccess}. Exported for tests and other hosts. */
|
|
197
|
+
var AccessVerifier = class {
|
|
198
|
+
issuer;
|
|
199
|
+
audiences;
|
|
200
|
+
allowList;
|
|
201
|
+
keys;
|
|
202
|
+
constructor(options) {
|
|
203
|
+
const teamDomain = normalizeTeamDomain(options.teamDomain);
|
|
204
|
+
this.issuer = `https://${teamDomain}`;
|
|
205
|
+
this.audiences = normalizeList("aud", options.aud, (tag) => tag !== "");
|
|
206
|
+
this.allowList = normalizeAllowList(options);
|
|
207
|
+
this.keys = new KeyCache(`${this.issuer}/cdn-cgi/access/certs`);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Verifies an Access application token and returns who it identifies, or why it was
|
|
211
|
+
* rejected. @throws KeyFetchError when the signing keys cannot be fetched.
|
|
212
|
+
*/
|
|
213
|
+
async verify(token, ctx) {
|
|
214
|
+
let decoded;
|
|
215
|
+
try {
|
|
216
|
+
decoded = decodeToken(token);
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error instanceof TokenError) return { rejected: error.message };
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
const { header, payload } = decoded;
|
|
222
|
+
if (header["alg"] !== "RS256") return { rejected: `algorithm ${JSON.stringify(header["alg"])} is not ${ALGORITHM}` };
|
|
223
|
+
if (header["crit"] !== void 0) return { rejected: "unsupported critical header parameters" };
|
|
224
|
+
const kid = header["kid"];
|
|
225
|
+
if (typeof kid !== "string" || kid === "") return { rejected: "no key ID" };
|
|
226
|
+
const claims = this.checkClaims(payload, Date.now());
|
|
227
|
+
if ("rejected" in claims) return claims;
|
|
228
|
+
const key = await this.keys.get(kid, ctx);
|
|
229
|
+
if (key === void 0) return { rejected: `unknown key ID ${JSON.stringify(kid)}` };
|
|
230
|
+
if (!await verifySignature(decoded, key)) return { rejected: "invalid signature" };
|
|
231
|
+
return claims;
|
|
232
|
+
}
|
|
233
|
+
checkClaims(payload, now) {
|
|
234
|
+
if (payload["iss"] !== this.issuer) return { rejected: `issuer ${JSON.stringify(payload["iss"])} is not ${this.issuer}` };
|
|
235
|
+
const aud = payload["aud"];
|
|
236
|
+
if (!(typeof aud === "string" ? [aud] : Array.isArray(aud) ? aud : []).some((tag) => typeof tag === "string" && this.audiences.has(tag))) return { rejected: "audience does not match" };
|
|
237
|
+
const exp = payload["exp"];
|
|
238
|
+
if (typeof exp !== "number" || !Number.isFinite(exp)) return { rejected: "no expiry" };
|
|
239
|
+
if (now >= exp * 1e3 + 3e4) return { rejected: "expired" };
|
|
240
|
+
const nbf = payload["nbf"];
|
|
241
|
+
if (nbf !== void 0) {
|
|
242
|
+
if (typeof nbf !== "number" || !Number.isFinite(nbf)) return { rejected: "invalid nbf" };
|
|
243
|
+
if (now < nbf * 1e3 - 3e4) return { rejected: "not valid yet" };
|
|
244
|
+
}
|
|
245
|
+
const sub = payload["sub"];
|
|
246
|
+
const commonName = payload["common_name"];
|
|
247
|
+
const email = typeof payload["email"] === "string" && payload["email"] !== "" ? payload["email"] : void 0;
|
|
248
|
+
if (typeof sub === "string" && sub !== "") {
|
|
249
|
+
if (this.allowList !== void 0 && !this.allowsUser(email)) return { rejected: "user is not on the allow list" };
|
|
250
|
+
return { identity: email === void 0 ? { id: sub } : {
|
|
251
|
+
id: sub,
|
|
252
|
+
email
|
|
253
|
+
} };
|
|
254
|
+
}
|
|
255
|
+
if (typeof commonName === "string" && commonName !== "") {
|
|
256
|
+
if (this.allowList !== void 0 && !this.allowList.serviceTokens.has(commonName)) return { rejected: "service token is not on the allow list" };
|
|
257
|
+
return { identity: { id: commonName } };
|
|
258
|
+
}
|
|
259
|
+
return { rejected: "no subject" };
|
|
260
|
+
}
|
|
261
|
+
allowsUser(email) {
|
|
262
|
+
if (email === void 0 || this.allowList === void 0) return false;
|
|
263
|
+
const address = email.toLowerCase();
|
|
264
|
+
const domain = address.slice(address.lastIndexOf("@") + 1);
|
|
265
|
+
return this.allowList.emails.has(address) || this.allowList.domains.has(domain);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Authenticates administrators with Cloudflare Access. See the module documentation
|
|
270
|
+
* for what is verified.
|
|
271
|
+
* @throws TypeError when the options are invalid, so that a typo fails the deployment.
|
|
272
|
+
*/
|
|
273
|
+
function cloudflareAccess(options) {
|
|
274
|
+
const verifier = new AccessVerifier(options);
|
|
275
|
+
let warnedMissingHeader = false;
|
|
276
|
+
return {
|
|
277
|
+
type: "cloudflare-access",
|
|
278
|
+
async authenticate(request, ctx) {
|
|
279
|
+
const token = request.headers.get(ACCESS_JWT_HEADER);
|
|
280
|
+
if (token === null || token === "") {
|
|
281
|
+
if (!warnedMissingHeader) {
|
|
282
|
+
warnedMissingHeader = true;
|
|
283
|
+
console.warn(`Cloudflare Access: an admin request has no ${ACCESS_JWT_HEADER} header. Check that an Access application protects /admin and /api/admin on this host name.`);
|
|
284
|
+
}
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
let verdict;
|
|
288
|
+
try {
|
|
289
|
+
verdict = await verifier.verify(token, ctx);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
if (!(error instanceof KeyFetchError)) console.error("Cloudflare Access: could not verify a token", error);
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
if ("rejected" in verdict) {
|
|
295
|
+
console.warn(`Cloudflare Access: rejected a token (${verdict.rejected})`);
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
return verdict.identity;
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
export { ACCESS_JWT_HEADER, AccessVerifier, CLOCK_TOLERANCE_MS, KEYS_FRESH_MS, KEYS_MAX_AGE_MS, KEY_FETCH_BACKOFF_MS, KeyFetchError, UNKNOWN_KEY_REFETCH_MS, cloudflareAccess };
|
|
303
|
+
|
|
304
|
+
//# sourceMappingURL=auth-cloudflare-access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-cloudflare-access.js","names":["jwk"],"sources":["../../auth-cloudflare-access/src/jwt.ts","../../auth-cloudflare-access/src/index.ts"],"sourcesContent":["/**\n * Just enough JSON Web Token handling for Cloudflare Access application tokens: RS256\n * signatures (RSASSA-PKCS1-v1_5 with SHA-256) over WebCrypto, keys from a JWKS document.\n * Standard web APIs only, so the package runs on any runtime.\n */\n\n/** The only algorithm Access signs application tokens with. Pinned: the token's `alg` must match. */\nexport const ALGORITHM = \"RS256\";\nconst IMPORT_PARAMS = { name: \"RSASSA-PKCS1-v1_5\", hash: \"SHA-256\" } as const;\n\nconst BASE64URL = /^[A-Za-z0-9_-]*$/;\n\nexport class TokenError extends Error {\n\toverride readonly name = \"TokenError\";\n}\n\nexport interface DecodedToken {\n\treadonly header: Readonly<Record<string, unknown>>;\n\treadonly payload: Readonly<Record<string, unknown>>;\n\t/** `base64url(header) \".\" base64url(payload)`: the bytes the signature covers. */\n\treadonly signingInput: string;\n\treadonly signature: Uint8Array<ArrayBuffer>;\n}\n\nfunction base64UrlDecode(part: string): Uint8Array<ArrayBuffer> {\n\tif (!BASE64URL.test(part) || part.length % 4 === 1) throw new TokenError(\"malformed base64url\");\n\tconst base64 = part.replaceAll(\"-\", \"+\").replaceAll(\"_\", \"/\") + \"=\".repeat((4 - (part.length % 4)) % 4);\n\tconst binary = atob(base64);\n\tconst bytes = new Uint8Array(binary.length);\n\tfor (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);\n\treturn bytes;\n}\n\nfunction decodeJsonObject(part: string, what: string): Record<string, unknown> {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(new TextDecoder(\"utf-8\", { fatal: true, ignoreBOM: false }).decode(base64UrlDecode(part)));\n\t} catch {\n\t\tthrow new TokenError(`malformed ${what}`);\n\t}\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\tthrow new TokenError(`malformed ${what}`);\n\t}\n\treturn value as Record<string, unknown>;\n}\n\n/** Splits and decodes a compact JWS. Checks the format only, not the signature or claims. */\nexport function decodeToken(token: string): DecodedToken {\n\tconst parts = token.split(\".\");\n\tif (parts.length !== 3) throw new TokenError(\"not a compact JWT\");\n\tconst [header, payload, signature] = parts as [string, string, string];\n\tif (header === \"\" || payload === \"\" || signature === \"\") throw new TokenError(\"not a compact JWT\");\n\treturn {\n\t\theader: decodeJsonObject(header, \"header\"),\n\t\tpayload: decodeJsonObject(payload, \"payload\"),\n\t\tsigningInput: `${header}.${payload}`,\n\t\tsignature: base64UrlDecode(signature),\n\t};\n}\n\n/** Verifies the token's RS256 signature with `key`. */\nexport function verifySignature(token: DecodedToken, key: CryptoKey): Promise<boolean> {\n\treturn crypto.subtle.verify(\n\t\tIMPORT_PARAMS.name,\n\t\tkey,\n\t\ttoken.signature,\n\t\tnew TextEncoder().encode(token.signingInput),\n\t);\n}\n\n/** Signing keys by key ID. */\nexport type KeyMap = ReadonlyMap<string, CryptoKey>;\n\n/**\n * Imports the RSA signing keys of a JWKS document (`{ keys: [...] }`). Keys that are not\n * RSA, declare another algorithm or use, or fail to import are skipped.\n * @throws TokenError when the document has no usable key.\n */\nexport async function importKeySet(document: unknown): Promise<KeyMap> {\n\tconst entries =\n\t\ttypeof document === \"object\" && document !== null && Array.isArray((document as { keys?: unknown }).keys)\n\t\t\t? ((document as { keys: unknown[] }).keys)\n\t\t\t: [];\n\tconst keys = new Map<string, CryptoKey>();\n\tfor (const entry of entries) {\n\t\tif (typeof entry !== \"object\" || entry === null) continue;\n\t\tconst jwk = entry as Record<string, unknown>;\n\t\tconst { kid, kty, alg, use, n, e } = jwk;\n\t\tif (typeof kid !== \"string\" || kid === \"\" || kty !== \"RSA\") continue;\n\t\tif (alg !== undefined && alg !== ALGORITHM) continue;\n\t\tif (use !== undefined && use !== \"sig\") continue;\n\t\tif (typeof n !== \"string\" || typeof e !== \"string\") continue;\n\t\ttry {\n\t\t\tconst key = await crypto.subtle.importKey(\n\t\t\t\t\"jwk\",\n\t\t\t\t{ kty: \"RSA\", n, e, alg: ALGORITHM, ext: true },\n\t\t\t\tIMPORT_PARAMS,\n\t\t\t\tfalse,\n\t\t\t\t[\"verify\"],\n\t\t\t);\n\t\t\tkeys.set(kid, key);\n\t\t} catch {\n\t\t\t// Not a valid RSA public key: skip it.\n\t\t}\n\t}\n\tif (keys.size === 0) throw new TokenError(\"the key set has no usable RS256 key\");\n\treturn keys;\n}\n","/**\n * Cloudflare Access authentication for the admin UI and admin API.\n *\n * Put a Cloudflare Access application in front of `/admin` and `/api/admin` (path-scoped,\n * so the public status page stays open), then configure it here:\n *\n * ```ts\n * auth: cloudflareAccess({\n * teamDomain: \"myteam.cloudflareaccess.com\",\n * aud: \"<Application Audience (AUD) tag>\",\n * allowedDomains: [\"example.com\"], // optional second check, see below\n * })\n * ```\n *\n * None of these values is secret. Access passes the signed-in user's token to the Worker in\n * the `Cf-Access-Jwt-Assertion` header, and this provider verifies it itself, because a\n * Worker that serves static assets does not get `ctx.access`, and so that a mistake in the\n * Access configuration cannot open the admin API:\n *\n * - the signature, with RS256 only (the token's `alg` is not trusted to choose), against\n * the team's public keys from `https://<teamDomain>/cdn-cgi/access/certs`, matched by `kid`;\n * - `iss` is `https://<teamDomain>`, `aud` contains one of the configured tags;\n * - `exp` has not passed and `nbf` has, with {@link CLOCK_TOLERANCE_MS} of tolerance;\n * - with any of `allowedEmails`, `allowedDomains` or `allowedServiceTokens` set, the identity\n * must be on one of them: a user by email address or its domain, an Access service token\n * by its client ID. This guards against an Access policy that admits too many people.\n * Without them, everyone the Access application admits is an administrator, service\n * tokens included.\n *\n * The identity is the token's `sub` and `email`; for an Access service token, which has\n * neither, its `common_name` (the client ID).\n *\n * Signing keys are cached in memory. Access publishes the current and the previous key and\n * rotates every 6 weeks, keeping the previous key valid for 7 days, so the cache is\n * refreshed in the background every {@link KEYS_FRESH_MS}; a token with a key ID the cache\n * does not have triggers a refresh at most every {@link UNKNOWN_KEY_REFETCH_MS}. Requests\n * that need keys while a fetch is in progress wait for it rather than start another, and\n * after a failed fetch there is no new attempt for {@link KEY_FETCH_BACKOFF_MS}, so tokens\n * crafted to pass the claim checks cannot make every request fetch. When keys cannot be\n * fetched, cached keys are used for at most {@link KEYS_MAX_AGE_MS}, then every request is\n * rejected until the keys can be fetched again (fail closed).\n */\nimport type { AdminIdentity, AuthContext, AuthProvider } from \"@naosystem/cf-workers-status-page-core\";\nimport { ALGORITHM, type DecodedToken, decodeToken, importKeySet, type KeyMap, TokenError, verifySignature } from \"./jwt\";\n\n/** The header Access adds to requests it lets through. Validated instead of the `CF_Authorization` cookie, as Cloudflare recommends. */\nexport const ACCESS_JWT_HEADER = \"Cf-Access-Jwt-Assertion\";\n\n/** Clock skew tolerated when checking `exp` and `nbf`. */\nexport const CLOCK_TOLERANCE_MS = 30_000;\n/** Cached keys older than this are refreshed in the background. */\nexport const KEYS_FRESH_MS = 5 * 60_000;\n/** Cached keys older than this are not used: a request waits for fresh keys, or is rejected. */\nexport const KEYS_MAX_AGE_MS = 60 * 60_000;\n/** A token whose key ID is not cached refetches the keys at most this often. */\nexport const UNKNOWN_KEY_REFETCH_MS = 30_000;\n/** After a failed fetch of the keys, no new attempt for this long. */\nexport const KEY_FETCH_BACKOFF_MS = 30_000;\n/** How long fetching the keys may take. */\nconst FETCH_TIMEOUT_MS = 5_000;\n\nexport interface CloudflareAccessOptions {\n\t/**\n\t * Your Zero Trust team domain, such as `\"myteam.cloudflareaccess.com\"` (Zero Trust →\n\t * Settings → Team name and domain). A leading `https://` is accepted.\n\t */\n\treadonly teamDomain: string;\n\t/**\n\t * The Application Audience (AUD) tag of the Access application that protects `/admin`\n\t * and `/api/admin` (Access → Applications → the application → Additional settings).\n\t * A list when several applications protect them.\n\t */\n\treadonly aud: string | readonly string[];\n\t/** Users allowed in, by email address (case-insensitive). See the module documentation. */\n\treadonly allowedEmails?: readonly string[];\n\t/** Users allowed in, by the domain of their email address, such as `\"example.com\"` (exact, not subdomains). */\n\treadonly allowedDomains?: readonly string[];\n\t/** Access service tokens allowed in, by client ID (`\"<id>.access\"`, the token's `CF-Access-Client-Id`). */\n\treadonly allowedServiceTokens?: readonly string[];\n}\n\nconst HOSTNAME = /^(?=.{1,253}$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$/;\n\nfunction normalizeTeamDomain(value: unknown): string {\n\tif (typeof value !== \"string\") throw new TypeError(\"cloudflareAccess(): `teamDomain` must be a string\");\n\tconst host = value\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.replace(/^https:\\/\\//, \"\")\n\t\t.replace(/\\/$/, \"\");\n\tif (!HOSTNAME.test(host)) {\n\t\tthrow new TypeError(\n\t\t\t`cloudflareAccess(): \\`teamDomain\\` must be a host name such as \"myteam.cloudflareaccess.com\", not ${JSON.stringify(value)}`,\n\t\t);\n\t}\n\treturn host;\n}\n\n/** A list option as a set of trimmed values, after checking each with `valid`. */\nfunction normalizeList(\n\tname: string,\n\tvalue: unknown,\n\tvalid: (item: string) => boolean,\n\tnormalize: (item: string) => string = (item) => item,\n): ReadonlySet<string> {\n\tconst list: unknown[] = typeof value === \"string\" ? [value] : Array.isArray(value) ? value : [];\n\tif (list.length === 0) throw new TypeError(`cloudflareAccess(): \\`${name}\\` must not be empty`);\n\tfor (const item of list) {\n\t\tif (typeof item !== \"string\" || item.trim() !== item || !valid(item)) {\n\t\t\tthrow new TypeError(`cloudflareAccess(): invalid \\`${name}\\` entry ${JSON.stringify(item)}`);\n\t\t}\n\t}\n\treturn new Set((list as string[]).map(normalize));\n}\n\ninterface AllowList {\n\treadonly emails: ReadonlySet<string>;\n\treadonly domains: ReadonlySet<string>;\n\treadonly serviceTokens: ReadonlySet<string>;\n}\n\nfunction normalizeAllowList(options: CloudflareAccessOptions): AllowList | undefined {\n\tconst { allowedEmails, allowedDomains, allowedServiceTokens } = options;\n\tif (allowedEmails === undefined && allowedDomains === undefined && allowedServiceTokens === undefined) {\n\t\treturn undefined;\n\t}\n\tconst lower = (item: string) => item.toLowerCase();\n\treturn {\n\t\temails:\n\t\t\tallowedEmails === undefined\n\t\t\t\t? new Set()\n\t\t\t\t: normalizeList(\"allowedEmails\", allowedEmails, (item) => /^[^@\\s]+@[^@\\s]+$/.test(item), lower),\n\t\tdomains:\n\t\t\tallowedDomains === undefined\n\t\t\t\t? new Set()\n\t\t\t\t: normalizeList(\"allowedDomains\", allowedDomains, (item) => HOSTNAME.test(item.toLowerCase()), lower),\n\t\tserviceTokens:\n\t\t\tallowedServiceTokens === undefined\n\t\t\t\t? new Set()\n\t\t\t\t: normalizeList(\"allowedServiceTokens\", allowedServiceTokens, (item) => item !== \"\"),\n\t};\n}\n\n/** The signing keys could not be fetched (or a failed fetch is too recent to try again). */\nexport class KeyFetchError extends Error {\n\toverride readonly name = \"KeyFetchError\";\n}\n\ninterface CachedKeys {\n\treadonly keys: KeyMap;\n\treadonly fetchedAt: number;\n}\n\n/** Waits for `promise` at most `ms`, with a timer of the caller's own. */\nfunction withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst timeout = new Promise<never>((_, reject) => {\n\t\ttimer = setTimeout(() => reject(new KeyFetchError(\"timed out waiting for the signing keys\")), ms);\n\t});\n\treturn Promise.race([promise, timeout]).finally(() => {\n\t\tif (timer !== undefined) clearTimeout(timer);\n\t});\n}\n\n/** The team's signing keys, cached per isolate. */\nclass KeyCache {\n\tprivate cached: CachedKeys | undefined;\n\t/** The fetch in progress, which other requests join. */\n\tprivate inFlight: Promise<CachedKeys> | undefined;\n\tprivate lastAttemptAt = Number.NEGATIVE_INFINITY;\n\tprivate failedAt = Number.NEGATIVE_INFINITY;\n\tprivate readonly url: string;\n\n\tconstructor(url: string) {\n\t\tthis.url = url;\n\t}\n\n\t/** The key with ID `kid`, or `undefined` when the team does not publish it. @throws KeyFetchError */\n\tasync get(kid: string, ctx: AuthContext): Promise<CryptoKey | undefined> {\n\t\tconst now = Date.now();\n\t\tlet cached = this.cached;\n\t\tif (cached === undefined || now - cached.fetchedAt >= KEYS_MAX_AGE_MS) {\n\t\t\tcached = await this.refresh(ctx);\n\t\t} else if (now - cached.fetchedAt >= KEYS_FRESH_MS && this.inFlight === undefined) {\n\t\t\t// In the background: this request uses the cached keys. Failures are logged by `refresh`.\n\t\t\tthis.refresh(ctx).catch(() => {});\n\t\t}\n\t\tconst key = cached.keys.get(kid);\n\t\tif (key !== undefined || Date.now() - this.lastAttemptAt < UNKNOWN_KEY_REFETCH_MS) return key;\n\t\t// Perhaps the keys were rotated since they were cached.\n\t\treturn (await this.refresh(ctx)).keys.get(kid);\n\t}\n\n\t/**\n\t * Fetches the keys, or joins the fetch in progress. Within {@link KEY_FETCH_BACKOFF_MS} of a\n\t * failed fetch, rejects without fetching.\n\t */\n\tprivate refresh(ctx: AuthContext): Promise<CachedKeys> {\n\t\tif (this.inFlight !== undefined) return withTimeout(this.inFlight, FETCH_TIMEOUT_MS + 1_000);\n\t\tif (Date.now() - this.failedAt < KEY_FETCH_BACKOFF_MS) {\n\t\t\treturn Promise.reject(new KeyFetchError(\"the last attempt to fetch the signing keys failed; retrying later\"));\n\t\t}\n\t\tconst startedAt = Date.now();\n\t\tthis.lastAttemptAt = startedAt;\n\t\tconst run = this.fetchKeys(ctx)\n\t\t\t.then(\n\t\t\t\t(keys) => {\n\t\t\t\t\tthis.failedAt = Number.NEGATIVE_INFINITY;\n\t\t\t\t\tconst fresh = { keys, fetchedAt: startedAt };\n\t\t\t\t\t// A fetch that started earlier but finished later does not replace a newer one.\n\t\t\t\t\tif (this.cached === undefined || this.cached.fetchedAt <= startedAt) this.cached = fresh;\n\t\t\t\t\treturn fresh;\n\t\t\t\t},\n\t\t\t\t(error: unknown) => {\n\t\t\t\t\tthis.failedAt = Date.now();\n\t\t\t\t\tconst message = `could not fetch the signing keys from ${this.url}: ${String(error)}`;\n\t\t\t\t\tconsole.error(`Cloudflare Access: ${message}`);\n\t\t\t\t\tthrow new KeyFetchError(message);\n\t\t\t\t},\n\t\t\t)\n\t\t\t.finally(() => {\n\t\t\t\tthis.inFlight = undefined;\n\t\t\t});\n\t\tthis.inFlight = run;\n\t\t// Let it finish even if this request ends first: other requests may be waiting for it.\n\t\tctx.waitUntil(run.catch(() => {}));\n\t\treturn run;\n\t}\n\n\tprivate async fetchKeys(ctx: AuthContext): Promise<KeyMap> {\n\t\tconst response = await ctx.fetch(this.url, {\n\t\t\theaders: { Accept: \"application/json\" },\n\t\t\tsignal: AbortSignal.timeout(FETCH_TIMEOUT_MS),\n\t\t});\n\t\tif (!response.ok) throw new Error(`HTTP ${response.status}`);\n\t\treturn importKeySet(await response.json());\n\t}\n}\n\ntype Verdict = { readonly identity: AdminIdentity } | { readonly rejected: string };\n\n/** The Access JWT verifier behind {@link cloudflareAccess}. Exported for tests and other hosts. */\nexport class AccessVerifier {\n\treadonly issuer: string;\n\treadonly audiences: ReadonlySet<string>;\n\tprivate readonly allowList: AllowList | undefined;\n\tprivate readonly keys: KeyCache;\n\n\tconstructor(options: CloudflareAccessOptions) {\n\t\tconst teamDomain = normalizeTeamDomain(options.teamDomain);\n\t\tthis.issuer = `https://${teamDomain}`;\n\t\tthis.audiences = normalizeList(\"aud\", options.aud, (tag) => tag !== \"\");\n\t\tthis.allowList = normalizeAllowList(options);\n\t\tthis.keys = new KeyCache(`${this.issuer}/cdn-cgi/access/certs`);\n\t}\n\n\t/**\n\t * Verifies an Access application token and returns who it identifies, or why it was\n\t * rejected. @throws KeyFetchError when the signing keys cannot be fetched.\n\t */\n\tasync verify(token: string, ctx: AuthContext): Promise<Verdict> {\n\t\tlet decoded: DecodedToken;\n\t\ttry {\n\t\t\tdecoded = decodeToken(token);\n\t\t} catch (error) {\n\t\t\tif (error instanceof TokenError) return { rejected: error.message };\n\t\t\tthrow error;\n\t\t}\n\t\tconst { header, payload } = decoded;\n\t\tif (header[\"alg\"] !== ALGORITHM) return { rejected: `algorithm ${JSON.stringify(header[\"alg\"])} is not ${ALGORITHM}` };\n\t\tif (header[\"crit\"] !== undefined) return { rejected: \"unsupported critical header parameters\" };\n\t\tconst kid = header[\"kid\"];\n\t\tif (typeof kid !== \"string\" || kid === \"\") return { rejected: \"no key ID\" };\n\n\t\t// Claims first: an expired, foreign or unlisted token does not cost a key fetch.\n\t\tconst claims = this.checkClaims(payload, Date.now());\n\t\tif (\"rejected\" in claims) return claims;\n\n\t\tconst key = await this.keys.get(kid, ctx);\n\t\tif (key === undefined) return { rejected: `unknown key ID ${JSON.stringify(kid)}` };\n\t\tif (!(await verifySignature(decoded, key))) return { rejected: \"invalid signature\" };\n\t\treturn claims;\n\t}\n\n\tprivate checkClaims(payload: Readonly<Record<string, unknown>>, now: number): Verdict {\n\t\tif (payload[\"iss\"] !== this.issuer) return { rejected: `issuer ${JSON.stringify(payload[\"iss\"])} is not ${this.issuer}` };\n\n\t\tconst aud = payload[\"aud\"];\n\t\tconst audiences = typeof aud === \"string\" ? [aud] : Array.isArray(aud) ? aud : [];\n\t\tif (!audiences.some((tag) => typeof tag === \"string\" && this.audiences.has(tag))) {\n\t\t\treturn { rejected: \"audience does not match\" };\n\t\t}\n\n\t\tconst exp = payload[\"exp\"];\n\t\tif (typeof exp !== \"number\" || !Number.isFinite(exp)) return { rejected: \"no expiry\" };\n\t\tif (now >= exp * 1000 + CLOCK_TOLERANCE_MS) return { rejected: \"expired\" };\n\t\tconst nbf = payload[\"nbf\"];\n\t\tif (nbf !== undefined) {\n\t\t\tif (typeof nbf !== \"number\" || !Number.isFinite(nbf)) return { rejected: \"invalid nbf\" };\n\t\t\tif (now < nbf * 1000 - CLOCK_TOLERANCE_MS) return { rejected: \"not valid yet\" };\n\t\t}\n\n\t\tconst sub = payload[\"sub\"];\n\t\tconst commonName = payload[\"common_name\"];\n\t\tconst email = typeof payload[\"email\"] === \"string\" && payload[\"email\"] !== \"\" ? payload[\"email\"] : undefined;\n\t\tif (typeof sub === \"string\" && sub !== \"\") {\n\t\t\tif (this.allowList !== undefined && !this.allowsUser(email)) return { rejected: \"user is not on the allow list\" };\n\t\t\treturn { identity: email === undefined ? { id: sub } : { id: sub, email } };\n\t\t}\n\t\t// An Access service token: no user, its client ID instead.\n\t\tif (typeof commonName === \"string\" && commonName !== \"\") {\n\t\t\tif (this.allowList !== undefined && !this.allowList.serviceTokens.has(commonName)) {\n\t\t\t\treturn { rejected: \"service token is not on the allow list\" };\n\t\t\t}\n\t\t\treturn { identity: { id: commonName } };\n\t\t}\n\t\treturn { rejected: \"no subject\" };\n\t}\n\n\tprivate allowsUser(email: string | undefined): boolean {\n\t\tif (email === undefined || this.allowList === undefined) return false;\n\t\tconst address = email.toLowerCase();\n\t\tconst domain = address.slice(address.lastIndexOf(\"@\") + 1);\n\t\treturn this.allowList.emails.has(address) || this.allowList.domains.has(domain);\n\t}\n}\n\n/**\n * Authenticates administrators with Cloudflare Access. See the module documentation\n * for what is verified.\n * @throws TypeError when the options are invalid, so that a typo fails the deployment.\n */\nexport function cloudflareAccess(options: CloudflareAccessOptions): AuthProvider {\n\tconst verifier = new AccessVerifier(options);\n\tlet warnedMissingHeader = false;\n\treturn {\n\t\ttype: \"cloudflare-access\",\n\t\tasync authenticate(request, ctx) {\n\t\t\tconst token = request.headers.get(ACCESS_JWT_HEADER);\n\t\t\tif (token === null || token === \"\") {\n\t\t\t\tif (!warnedMissingHeader) {\n\t\t\t\t\twarnedMissingHeader = true;\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`Cloudflare Access: an admin request has no ${ACCESS_JWT_HEADER} header. ` +\n\t\t\t\t\t\t\t\"Check that an Access application protects /admin and /api/admin on this host name.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet verdict: Verdict;\n\t\t\ttry {\n\t\t\t\tverdict = await verifier.verify(token, ctx);\n\t\t\t} catch (error) {\n\t\t\t\t// Fetch failures are logged where they happen, once per attempt.\n\t\t\t\tif (!(error instanceof KeyFetchError)) console.error(\"Cloudflare Access: could not verify a token\", error);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (\"rejected\" in verdict) {\n\t\t\t\tconsole.warn(`Cloudflare Access: rejected a token (${verdict.rejected})`);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn verdict.identity;\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAOA,IAAa,YAAY;AACzB,IAAM,gBAAgB;CAAE,MAAM;CAAqB,MAAM;AAAU;AAEnE,IAAM,YAAY;AAElB,IAAa,aAAb,cAAgC,MAAM;CACrC,OAAyB;AAC1B;AAUA,SAAS,gBAAgB,MAAuC;CAC/D,IAAI,CAAC,UAAU,KAAK,IAAI,KAAK,KAAK,SAAS,MAAM,GAAG,MAAM,IAAI,WAAW,qBAAqB;CAC9F,MAAM,SAAS,KAAK,WAAW,KAAK,GAAG,CAAC,CAAC,WAAW,KAAK,GAAG,IAAI,IAAI,QAAQ,IAAK,KAAK,SAAS,KAAM,CAAC;CACtG,MAAM,SAAS,KAAK,MAAM;CAC1B,MAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;CAC1C,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,MAAM,KAAK,OAAO,WAAW,CAAC;CACtE,OAAO;AACR;AAEA,SAAS,iBAAiB,MAAc,MAAuC;CAC9E,IAAI;CACJ,IAAI;EACH,QAAQ,KAAK,MAAM,IAAI,YAAY,SAAS;GAAE,OAAO;GAAM,WAAW;EAAM,CAAC,CAAC,CAAC,OAAO,gB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,OAAoC;EACtD,IAAI,UAAU,KAAA,KAAa,KAAK,cAAc,KAAA,GAAW,OAAO;EAChE,MAAM,UAAU,MAAM,YAAY;EAClC,MAAM,SAAS,QAAQ,MAAM,QAAQ,YAAY,GAAG,IAAI,CAAC;EACzD,OAAO,KAAK,UAAU,OAAO,IAAI,OAAO,KAAK,KAAK,UAAU,QAAQ,IAAI,MAAM;CAC/E;AACD;;;;;;AAOA,SAAgB,iBAAiB,SAAgD;CAChF,MAAM,WAAW,IAAI,eAAe,OAAO;CAC3C,IAAI,sBAAsB;CAC1B,OAAO;EACN,MAAM;EACN,MAAM,aAAa,SAAS,KAAK;GAChC,MAAM,QAAQ,QAAQ,QAAQ,IAAI,iBAAiB;GACnD,IAAI,UAAU,QAAQ,UAAU,IAAI;IACnC,IAAI,CAAC,qBAAqB;KACzB,sBAAsB;KACtB,QAAQ,KACP,8CAA8C,kBAAkB,4FAEjE;IACD;IACA,OAAO;GACR;GACA,IAAI;GACJ,IAAI;IACH,UAAU,MAAM,SAAS,OAAO,OAAO,GAAG;GAC3C,SAAS,OAAO;IAEf,IAAI,EAAE,iBAAiB,gBAAgB,QAAQ,MAAM,+CAA+C,KAAK;IACzG,OAAO;GACR;GACA,IAAI,cAAc,SAAS;IAC1B,QAAQ,KAAK,wCAAwC,QAAQ,SAAS,EAAE;IACxE,OAAO;GACR;GACA,OAAO,QAAQ;EAChB;CACD;AACD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// ../core/src/monitor.ts
|
|
2
|
+
/** Keys of {@link MonitorSettings}. */
|
|
3
|
+
var MONITOR_SETTING_KEYS = [
|
|
4
|
+
"id",
|
|
5
|
+
"name",
|
|
6
|
+
"interval",
|
|
7
|
+
"timeout",
|
|
8
|
+
"location",
|
|
9
|
+
"confirmation"
|
|
10
|
+
];
|
|
11
|
+
/** Keys kept free for monitor settings that may be added later (for example, choosing runners). */
|
|
12
|
+
var RESERVED_MONITOR_KEYS = [
|
|
13
|
+
"runner",
|
|
14
|
+
"runners",
|
|
15
|
+
"enabled",
|
|
16
|
+
"description",
|
|
17
|
+
"tags"
|
|
18
|
+
];
|
|
19
|
+
/** Provider option schemas must not use these keys: in `http({ … })` they belong to the monitor. */
|
|
20
|
+
var RESERVED_OPTION_KEYS = /* @__PURE__ */ new Set([...MONITOR_SETTING_KEYS, ...RESERVED_MONITOR_KEYS]);
|
|
21
|
+
/**
|
|
22
|
+
* Top-level keys an options schema accepts, read from Zod's schema definition.
|
|
23
|
+
* `undefined` when the schema is not (a wrapper around) an object schema.
|
|
24
|
+
*/
|
|
25
|
+
function optionKeys(schema) {
|
|
26
|
+
const def = schema?._zod?.def;
|
|
27
|
+
switch (def?.type) {
|
|
28
|
+
case "object": return Object.keys(def.shape ?? {});
|
|
29
|
+
case "pipe": return optionKeys(def.in);
|
|
30
|
+
case "optional":
|
|
31
|
+
case "nonoptional":
|
|
32
|
+
case "default":
|
|
33
|
+
case "prefault":
|
|
34
|
+
case "readonly":
|
|
35
|
+
case "catch": return optionKeys(def.innerType);
|
|
36
|
+
case "union": {
|
|
37
|
+
const keys = def.options?.map(optionKeys);
|
|
38
|
+
if (!keys || keys.some((k) => k === void 0)) return void 0;
|
|
39
|
+
return [...new Set(keys.flat())];
|
|
40
|
+
}
|
|
41
|
+
case "intersection": {
|
|
42
|
+
const left = optionKeys(def.left);
|
|
43
|
+
const right = optionKeys(def.right);
|
|
44
|
+
return left && right ? [.../* @__PURE__ */ new Set([...left, ...right])] : void 0;
|
|
45
|
+
}
|
|
46
|
+
default: return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Declares a check provider and returns the monitor factory for it.
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* export const http = defineProvider({ type: "http", options, requires: ["fetch"], check });
|
|
54
|
+
* // status.config.ts: monitors: [http({ id: "api", interval: "1m", url: "https://…" })]
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @throws TypeError if the options schema is not an object schema, or uses a key that
|
|
58
|
+
* belongs to monitor settings (see {@link RESERVED_OPTION_KEYS}).
|
|
59
|
+
*/
|
|
60
|
+
function defineProvider(provider) {
|
|
61
|
+
const keys = optionKeys(provider.options);
|
|
62
|
+
if (keys === void 0) throw new TypeError(`Provider "${provider.type}": options must be an object schema`);
|
|
63
|
+
const clashes = keys.filter((key) => RESERVED_OPTION_KEYS.has(key));
|
|
64
|
+
if (clashes.length > 0) throw new TypeError(`Provider "${provider.type}": option ${clashes.map((k) => `"${k}"`).join(", ")} clashes with monitor settings; reserved keys are ${[...RESERVED_OPTION_KEYS].join(", ")}`);
|
|
65
|
+
const factory = (input) => {
|
|
66
|
+
const settings = {};
|
|
67
|
+
const options = {};
|
|
68
|
+
for (const [key, value] of Object.entries(input)) (RESERVED_OPTION_KEYS.has(key) ? settings : options)[key] = value;
|
|
69
|
+
return {
|
|
70
|
+
provider,
|
|
71
|
+
settings,
|
|
72
|
+
options
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
return Object.assign(factory, { provider });
|
|
76
|
+
}
|
|
77
|
+
export { optionKeys as a, defineProvider as i, RESERVED_MONITOR_KEYS as n, RESERVED_OPTION_KEYS as r, MONITOR_SETTING_KEYS as t };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=monitor-B2u42off.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor-B2u42off.js","names":[],"sources":["../../../core/src/monitor.ts"],"sourcesContent":["import type { Duration } from \"./duration\";\nimport type { LocationHint } from \"./location\";\nimport type { CheckProvider } from \"./provider\";\n\n/** How a monitor's state is confirmed from consecutive results. */\nexport interface ConfirmationSettings {\n\t/** Consecutive failed checks needed to confirm `down`. Default: 2. */\n\tfailureThreshold?: number;\n\t/** Consecutive successful checks needed to return to `up`. Default: 1. */\n\tsuccessThreshold?: number;\n\t/**\n\t * How soon to re-check after a failure, instead of waiting for the next interval.\n\t * Default: `\"15s\"`. Must not be longer than `interval`.\n\t */\n\trecheckInterval?: Duration;\n}\n\n/** Settings every monitor has, whatever its provider. */\nexport interface MonitorSettings {\n\t/**\n\t * Unique, stable identifier: 1–64 characters of lowercase letters, digits, `-` and `_`,\n\t * starting with a letter or digit. Changing it starts a new monitor with an empty history.\n\t */\n\tid: string;\n\t/** Display name. Defaults to `id`. */\n\tname?: string;\n\t/** Time between scheduled checks, such as `\"1m\"`. */\n\tinterval: Duration;\n\t/**\n\t * How long one check may take before it counts as `down`. Default: `\"10s\"`. Must be shorter\n\t * than `interval`, and no longer than the runner allows (5 minutes for the built-in runner).\n\t */\n\ttimeout?: Duration;\n\t/**\n\t * Overrides the configuration-wide `location`. A monitor never moves after it is\n\t * created, so changing this requires a new `id`.\n\t */\n\tlocation?: LocationHint;\n\tconfirmation?: ConfirmationSettings;\n}\n\n/** Keys of {@link MonitorSettings}. */\nexport const MONITOR_SETTING_KEYS = [\n\t\"id\",\n\t\"name\",\n\t\"interval\",\n\t\"timeout\",\n\t\"location\",\n\t\"confirmation\",\n] as const satisfies readonly (keyof MonitorSettings)[];\n\n/** Keys kept free for monitor settings that may be added later (for example, choosing runners). */\nexport const RESERVED_MONITOR_KEYS = [\"runner\", \"runners\", \"enabled\", \"description\", \"tags\"] as const;\n\n/** Provider option schemas must not use these keys: in `http({ … })` they belong to the monitor. */\nexport const RESERVED_OPTION_KEYS: ReadonlySet<string> = new Set([\n\t...MONITOR_SETTING_KEYS,\n\t...RESERVED_MONITOR_KEYS,\n]);\n\n/**\n * One monitor in `status.config.ts`, as returned by a provider's factory such as `http({ … })`.\n * Nothing here is validated yet; `resolveConfig` validates it when the configuration is loaded.\n */\nexport interface MonitorDefinition {\n\treadonly provider: CheckProvider;\n\t/** Monitor settings, plus any reserved keys that were given (rejected by `resolveConfig`). */\n\treadonly settings: MonitorSettings;\n\t/** The provider's options as written, before validation and defaults. */\n\treadonly options: Readonly<Record<string, unknown>>;\n}\n\n/**\n * The function users call in `status.config.ts`. It takes the monitor settings and the\n * provider's options in one flat object, e.g. `http({ id, interval, url })`.\n */\nexport interface MonitorFactory<Options, Input> {\n\t(input: MonitorSettings & Input): MonitorDefinition;\n\treadonly provider: CheckProvider<Options, Input>;\n}\n\ninterface SchemaDef {\n\ttype?: string;\n\tshape?: Record<string, unknown>;\n\tin?: SchemaLike;\n\tinnerType?: SchemaLike;\n\toptions?: readonly SchemaLike[];\n\tleft?: SchemaLike;\n\tright?: SchemaLike;\n}\n/** A Zod schema, as far as {@link optionKeys} looks into it. */\nexport interface SchemaLike {\n\t_zod?: { def?: SchemaDef };\n}\n\n/**\n * Top-level keys an options schema accepts, read from Zod's schema definition.\n * `undefined` when the schema is not (a wrapper around) an object schema.\n */\nexport function optionKeys(schema: SchemaLike | undefined): string[] | undefined {\n\tconst def = schema?._zod?.def;\n\tswitch (def?.type) {\n\t\tcase \"object\":\n\t\t\treturn Object.keys(def.shape ?? {});\n\t\tcase \"pipe\":\n\t\t\treturn optionKeys(def.in);\n\t\tcase \"optional\":\n\t\tcase \"nonoptional\":\n\t\tcase \"default\":\n\t\tcase \"prefault\":\n\t\tcase \"readonly\":\n\t\tcase \"catch\":\n\t\t\treturn optionKeys(def.innerType);\n\t\tcase \"union\": {\n\t\t\tconst keys = def.options?.map(optionKeys);\n\t\t\tif (!keys || keys.some((k) => k === undefined)) return undefined;\n\t\t\treturn [...new Set(keys.flat() as string[])];\n\t\t}\n\t\tcase \"intersection\": {\n\t\t\tconst left = optionKeys(def.left);\n\t\t\tconst right = optionKeys(def.right);\n\t\t\treturn left && right ? [...new Set([...left, ...right])] : undefined;\n\t\t}\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\n/**\n * Declares a check provider and returns the monitor factory for it.\n *\n * ```ts\n * export const http = defineProvider({ type: \"http\", options, requires: [\"fetch\"], check });\n * // status.config.ts: monitors: [http({ id: \"api\", interval: \"1m\", url: \"https://…\" })]\n * ```\n *\n * @throws TypeError if the options schema is not an object schema, or uses a key that\n * belongs to monitor settings (see {@link RESERVED_OPTION_KEYS}).\n */\nexport function defineProvider<Options, Input extends object>(\n\tprovider: CheckProvider<Options, Input>,\n): MonitorFactory<Options, Input> {\n\tconst keys = optionKeys(provider.options as SchemaLike);\n\tif (keys === undefined) {\n\t\tthrow new TypeError(`Provider \"${provider.type}\": options must be an object schema`);\n\t}\n\tconst clashes = keys.filter((key) => RESERVED_OPTION_KEYS.has(key));\n\tif (clashes.length > 0) {\n\t\tthrow new TypeError(\n\t\t\t`Provider \"${provider.type}\": option ${clashes.map((k) => `\"${k}\"`).join(\", \")} ` +\n\t\t\t\t`clashes with monitor settings; reserved keys are ${[...RESERVED_OPTION_KEYS].join(\", \")}`,\n\t\t);\n\t}\n\n\tconst factory = (input: MonitorSettings & Input): MonitorDefinition => {\n\t\tconst settings: Record<string, unknown> = {};\n\t\tconst options: Record<string, unknown> = {};\n\t\tfor (const [key, value] of Object.entries(input)) {\n\t\t\t(RESERVED_OPTION_KEYS.has(key) ? settings : options)[key] = value;\n\t\t}\n\t\treturn { provider, settings: settings as unknown as MonitorSettings, options };\n\t};\n\treturn Object.assign(factory, { provider });\n}\n"],"mappings":";;AA0CA,IAAa,uBAAuB;CACnC;CACA;CACA;CACA;CACA;CACA;AACD;;AAGA,IAAa,wBAAwB;CAAC;CAAU;CAAW;CAAW;CAAe;AAAM;;AAG3F,IAAa,uCAA4C,IAAI,IAAI,CAChE,GAAG,sBACH,GAAG,qBACJ,CAAC;;;;;AAyCD,SAAgB,WAAW,QAAsD;CAChF,MAAM,MAAM,QAAQ,MAAM;CAC1B,QAAQ,KAAK,MAAb;EACC,KAAK,UACJ,OAAO,OAAO,KAAK,IAAI,SAAS,CAAC,CAAC;EACnC,KAAK,QACJ,OAAO,WAAW,IAAI,EAAE;EACzB,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACJ,OAAO,WAAW,IAAI,SAAS;EAChC,KAAK,SAAS;GACb,MAAM,OAAO,IAAI,SAAS,IAAI,UAAU;GACxC,IA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