@kubohiroya/turbowarp-cloudflare-worker 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.ja.md +105 -0
- package/README.md +51 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +126 -0
- package/dist/cli.js.map +1 -0
- package/dist/extension-manifest.json +149 -0
- package/dist/generator.d.ts +2 -0
- package/dist/generator.js +776 -0
- package/dist/generator.js.map +1 -0
- package/dist/ir.d.ts +50 -0
- package/dist/ir.js +168 -0
- package/dist/ir.js.map +1 -0
- package/dist/jwt.d.ts +23 -0
- package/dist/jwt.js +81 -0
- package/dist/jwt.js.map +1 -0
- package/dist/turbowarp-cloudflare-worker.js +1218 -0
- package/docs/architecture.ja.md +97 -0
- package/docs/architecture.md +7 -0
- package/docs/auth-blocks.ja.md +154 -0
- package/docs/index.html +31 -0
- package/package.json +80 -0
- package/schemas/extension-manifest.schema.json +49 -0
- package/src/block-definitions.json +115 -0
- package/src/cli.ts +146 -0
- package/src/config.ts +12 -0
- package/src/extension-manifest.ts +159 -0
- package/src/extension.ts +197 -0
- package/src/generator.ts +828 -0
- package/src/globals.d.ts +25 -0
- package/src/index.ts +8 -0
- package/src/ir.ts +246 -0
- package/src/jwt.ts +144 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Cloudflare 連携パッケージ設計
|
|
2
|
+
|
|
3
|
+
## 位置づけ
|
|
4
|
+
|
|
5
|
+
`turbowarp-cloudflare-worker` は、`turbowarp-http-server` 本体からCloudflare Workers向けの生成・デプロイ補助を分離するためのパッケージです。
|
|
6
|
+
|
|
7
|
+
本体リポジトリは TurboWarp 上で HTTP ハンドラをブロックとして表現し、ローカル実行や教育用の体験を成立させる責務を持ちます。一方、このリポジトリはそのブロック表現を Cloudflare Workers で動く TypeScript/Hono コードへ変換する責務を持ちます。
|
|
8
|
+
|
|
9
|
+
分離する理由は次の通りです。
|
|
10
|
+
|
|
11
|
+
- Cloudflare Workers、Wrangler、D1/KV/R2/Durable Objects は本体より更新頻度と依存が重い。
|
|
12
|
+
- デプロイや認証は外部環境との結合が強く、教育用 HTTP サーバの中核と同じ release cycle にしないほうがよい。
|
|
13
|
+
- 将来的に Firebase/Vercel など別 target を追加する場合も、target ごとに peer package として分けやすい。
|
|
14
|
+
|
|
15
|
+
## 構成
|
|
16
|
+
|
|
17
|
+
- `src/ir.ts`: ブロック/CLI/生成器で共有する Cloudflare Worker IR。
|
|
18
|
+
- `src/generator.ts`: IR から `GeneratedFile[]` を返す Cloudflare Workers/Hono 生成器。
|
|
19
|
+
- `src/cli.ts`: JSON IR を読み、生成ファイルを out directory に書き出す CLI。
|
|
20
|
+
- `src/extension.ts`: TurboWarp から IR を作る最小ブロック。
|
|
21
|
+
- `tests/generator.test.ts`: 生成器の最小テスト。
|
|
22
|
+
|
|
23
|
+
## IR
|
|
24
|
+
|
|
25
|
+
初期 IR は意図的に小さくしています。
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
interface CloudflareWorkerIr {
|
|
29
|
+
name: string;
|
|
30
|
+
handlers: HttpHandlerIr[];
|
|
31
|
+
compatibilityDate?: string;
|
|
32
|
+
auth?: AuthBindingIr;
|
|
33
|
+
storage?: StorageBindingIr[];
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
HTTP handler は `method`、`path`、`responseText` のみから開始します。これは TurboWarp のブロックと Cloudflare Workers/Hono のコード生成を結びつける最小単位です。
|
|
38
|
+
|
|
39
|
+
## 生成対象
|
|
40
|
+
|
|
41
|
+
MVP の生成対象は次の 4 ファイルです。
|
|
42
|
+
|
|
43
|
+
- `wrangler.jsonc`
|
|
44
|
+
- `package.json`
|
|
45
|
+
- `tsconfig.json`
|
|
46
|
+
- `src/index.ts`
|
|
47
|
+
|
|
48
|
+
`src/index.ts` は Hono を使った Worker として生成します。ブロックから作られた root 以下の HTTP handler は、Hono の `app.get('/path', ...)` などへ対応づけます。
|
|
49
|
+
|
|
50
|
+
## 認証
|
|
51
|
+
|
|
52
|
+
このパッケージが OAuth/OIDC プロバイダになることはありません。MVP では Google、Microsoft、GitHub の外部アカウント連携を想定します。Apple 認証は MVP 外です。
|
|
53
|
+
|
|
54
|
+
Cloudflare Workers 上での選択肢は主に 2 つです。
|
|
55
|
+
|
|
56
|
+
- Worker 内で provider-issued JWT を検証する。
|
|
57
|
+
- Cloudflare Access などを Worker の前段に置き、Worker は認証済み identity を受け取る。
|
|
58
|
+
|
|
59
|
+
教育的には、まず「認証済み前提の handler」と「外部 provider の token を検証する middleware」を分けて説明できるようにするのが重要です。現在の初期実装では、`auth` IR からログイン/コールバック/ログアウトの route、OAuth/OIDC state照合、authorization code exchange、署名付きsession cookie、保護ルート middleware を生成します。
|
|
60
|
+
|
|
61
|
+
ブロック仕様は [auth-blocks.ja.md](auth-blocks.ja.md) にまとめます。ブロックは provider 名、保護ルート、未認証時の動作を宣言し、client secret、cookie署名鍵、issuer/audienceなどの秘密情報は Cloudflare Secrets または環境変数で扱います。
|
|
62
|
+
|
|
63
|
+
## 永続ストレージ
|
|
64
|
+
|
|
65
|
+
Cloudflare のストレージは用途で分けます。
|
|
66
|
+
|
|
67
|
+
| 種類 | 用途 | 注意点 |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| D1 | relational data、ユーザー、投稿、設定、履歴 | SQL schema と migration の扱いが必要 |
|
|
70
|
+
| KV | 設定、feature flag、短命 cache | eventual consistency 前提で使う |
|
|
71
|
+
| R2 | 画像、添付ファイル、生成物、export | metadata と object body を分けて扱う |
|
|
72
|
+
| Durable Objects | session、WebSocket、協調編集、順序制御 | class 設計と migration が必要 |
|
|
73
|
+
|
|
74
|
+
初期実装は `wrangler.jsonc` の binding と Worker `Env` 型への反映までに留めます。実データ操作の API、migration、型付き repository は後続 issue で分けます。
|
|
75
|
+
|
|
76
|
+
## TurboWarp ブロックとの対応
|
|
77
|
+
|
|
78
|
+
TurboWarp 側では、まず JSON IR を作る reporter block を提供します。
|
|
79
|
+
|
|
80
|
+
- handler block: HTTP method、path、response text を `HttpHandlerIr` にする。
|
|
81
|
+
- protected route block: HTTP method、path、未認証時の挙動を `ProtectedRouteIr` にする。
|
|
82
|
+
- auth block: Google/Microsoft/GitHub provider と保護ルート一覧を `AuthBindingIr` にする。
|
|
83
|
+
- Worker IR block: handler 配列を `CloudflareWorkerIr` にまとめる。
|
|
84
|
+
- Worker IR with auth block: handler 配列と `AuthBindingIr` を `CloudflareWorkerIr` にまとめる。
|
|
85
|
+
- generated files block: IR から `GeneratedFile[]` JSON を得る。
|
|
86
|
+
|
|
87
|
+
ブラウザ上の TurboWarp extension から直接 `wrangler deploy` は実行しません。デプロイは CLI またはローカル dev tool 側の責務にします。
|
|
88
|
+
|
|
89
|
+
## 今後の拡張
|
|
90
|
+
|
|
91
|
+
- route parameter、query/body/header の mapping。
|
|
92
|
+
- JSON response、status code、headers。
|
|
93
|
+
- D1 migration と seed generation。
|
|
94
|
+
- OAuth/OIDC middleware generation。
|
|
95
|
+
- Cloudflare Access 前提の identity extraction。
|
|
96
|
+
- `wrangler deploy` を実行するローカル CLI workflow。
|
|
97
|
+
- `turbowarp-http-server` 本体から export される IR との schema alignment。
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
This repository currently keeps the normative architecture note in Japanese:
|
|
4
|
+
|
|
5
|
+
- [Cloudflare integration package architecture](architecture.ja.md)
|
|
6
|
+
|
|
7
|
+
The package separates Cloudflare Workers TypeScript/Hono generation, CLI output, and deployment-facing concerns from the core `turbowarp-http-server` repository.
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# OAuth/OIDC 認証ブロック仕様
|
|
2
|
+
|
|
3
|
+
## 目的
|
|
4
|
+
|
|
5
|
+
この仕様は、TurboWarp のブロックで書いた HTTP ハンドラを Cloudflare Workers へ変換するときに、Google、Microsoft、GitHub などの外部アカウント認証をどう表現するかを定めます。
|
|
6
|
+
|
|
7
|
+
このパッケージ自身は OAuth/OIDC プロバイダにはなりません。ブロックは認証処理の詳細ではなく、次の方針を宣言します。
|
|
8
|
+
|
|
9
|
+
- どの外部プロバイダを使うか。
|
|
10
|
+
- どのルートをログイン必須にするか。
|
|
11
|
+
- 未ログイン時にリダイレクト、401 JSON、403 のどれで応答するか。
|
|
12
|
+
- Worker 側でセッションCookie、Bearer JWT、Cloudflare Access のどれを前提にするか。
|
|
13
|
+
|
|
14
|
+
## MVP ブロック
|
|
15
|
+
|
|
16
|
+
パレット上では、HTTP handler/Worker生成の基本ブロックを先に置き、その後にseparatorを挟んで認証系ブロックを並べます。認証系ブロックには `category: "auth"` を付け、TurboWarpが対応する環境では通常のCloudflareブロックとは異なる小さな鍵アイコンを表示します。対応しない環境ではアイコン指定は無視されます。
|
|
17
|
+
|
|
18
|
+
| ブロック | 生成するIR | 用途 |
|
|
19
|
+
| --- | --- | --- |
|
|
20
|
+
| `protected route [METHOD] [PATH] when unauthenticated [ON_UNAUTHENTICATED]` | `ProtectedRouteIr` | ルート単位のログイン必須設定 |
|
|
21
|
+
| `API route [METHOD] [PATH] requires bearer token` | `ProtectedRouteIr` | APIルートにES256 Bearer JWT認証を要求 |
|
|
22
|
+
| `API route [METHOD] [PATH] requires bearer role [ROLE]` | `ProtectedRouteIr` | `role` claimによる認可を要求 |
|
|
23
|
+
| `API route [METHOD] [PATH] requires bearer scope [SCOPE]` | `ProtectedRouteIr` | `scope` claimによる認可を要求 |
|
|
24
|
+
| `external OAuth/OIDC auth providers [PROVIDERS] protected routes JSON [PROTECTED_ROUTES]` | `AuthBindingIr` | Google/Microsoft/GitHub連携と保護ルート一覧 |
|
|
25
|
+
| `Cloudflare Worker [NAME] with handlers JSON [HANDLERS] and auth JSON [AUTH]` | `CloudflareWorkerIr` | HTTP handler IR と auth IR を統合 |
|
|
26
|
+
| `generated Cloudflare files JSON from IR [IR]` | `GeneratedFile[]` | Worker一式の生成結果 |
|
|
27
|
+
|
|
28
|
+
`PROVIDERS` は `google,github,microsoft` のようなカンマ区切り文字列です。Apple認証はMVP外です。
|
|
29
|
+
|
|
30
|
+
`ON_UNAUTHENTICATED` は次の値を取ります。
|
|
31
|
+
|
|
32
|
+
| 値 | 挙動 |
|
|
33
|
+
| --- | --- |
|
|
34
|
+
| `redirect-login` | ブラウザ画面向け。未ログインならログインURLへリダイレクト |
|
|
35
|
+
| `json-401` | API向け。未ログインなら `{error:"authentication_required"}` を401で返す |
|
|
36
|
+
| `forbid-403` | 認証が必須で、ログイン誘導しない場合に403を返す |
|
|
37
|
+
|
|
38
|
+
## IR
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
type AuthProvider = 'google' | 'microsoft' | 'github';
|
|
42
|
+
type AuthSessionMode = 'signed-cookie' | 'bearer-jwt' | 'cloudflare-access';
|
|
43
|
+
type UnauthenticatedAction = 'redirect-login' | 'json-401' | 'forbid-403';
|
|
44
|
+
|
|
45
|
+
interface ProtectedRouteIr {
|
|
46
|
+
method: HttpMethod | '*';
|
|
47
|
+
path: string;
|
|
48
|
+
onUnauthenticated: UnauthenticatedAction;
|
|
49
|
+
auth?: 'session' | 'bearer-jwt';
|
|
50
|
+
requiredRole?: string;
|
|
51
|
+
requiredScopes?: string[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface AuthBindingIr {
|
|
55
|
+
mode: 'external-oauth-oidc';
|
|
56
|
+
providers: AuthProvider[];
|
|
57
|
+
session?: AuthSessionMode;
|
|
58
|
+
loginPath?: string;
|
|
59
|
+
callbackPath?: string;
|
|
60
|
+
logoutPath?: string;
|
|
61
|
+
protectedRoutes?: ProtectedRouteIr[];
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
例:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"mode": "external-oauth-oidc",
|
|
70
|
+
"providers": ["google", "github"],
|
|
71
|
+
"session": "signed-cookie",
|
|
72
|
+
"loginPath": "/auth/login",
|
|
73
|
+
"callbackPath": "/auth/callback",
|
|
74
|
+
"logoutPath": "/auth/logout",
|
|
75
|
+
"protectedRoutes": [
|
|
76
|
+
{
|
|
77
|
+
"method": "GET",
|
|
78
|
+
"path": "/private",
|
|
79
|
+
"onUnauthenticated": "redirect-login"
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 生成されるWorker側の責務
|
|
86
|
+
|
|
87
|
+
生成器は初期段階で次の処理を生成します。
|
|
88
|
+
|
|
89
|
+
- `/auth/login`
|
|
90
|
+
- `/auth/login/:provider`
|
|
91
|
+
- `/auth/callback/:provider`
|
|
92
|
+
- `/auth/logout`
|
|
93
|
+
- `/auth/me`
|
|
94
|
+
- `protectedRoutes` に基づく Hono middleware
|
|
95
|
+
- Cloudflare Access利用時の `Cf-Access-Jwt-Assertion` 検出
|
|
96
|
+
- OAuth/OIDC `state` cookie の発行とcallback時の照合
|
|
97
|
+
- PKCE `code_verifier` / `code_challenge` の発行と token exchange への反映
|
|
98
|
+
- OIDC `nonce` の発行とID token claim照合
|
|
99
|
+
- provider token endpoint への authorization code exchange
|
|
100
|
+
- OIDC ID token の issuer、audience、expiration、nonce、JWKS署名検証
|
|
101
|
+
- userinfo endpoint からの最小identity抽出
|
|
102
|
+
- GitHub `/user/emails` からの verified primary email 取得
|
|
103
|
+
- HMAC-SHA-256署名付き `tw_session` cookie の発行
|
|
104
|
+
- `tw_session` cookie の署名検証と期限確認
|
|
105
|
+
- 現在の認証状態とユーザー情報を返す `/auth/me`
|
|
106
|
+
- `Authorization: Bearer ...` のES256 JWT検証
|
|
107
|
+
- Bearer JWTの `iss`、`aud`、`exp`、`role`、`scope` 検査
|
|
108
|
+
|
|
109
|
+
## Bearer JWT CLI
|
|
110
|
+
|
|
111
|
+
APIサーバ向けには、ローカルCLIでES256鍵を生成し、APIアクセス用tokenを発行します。
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
turbowarp-cloudflare-worker auth keygen --out .tw-auth
|
|
115
|
+
turbowarp-cloudflare-worker auth issue-token \
|
|
116
|
+
--key .tw-auth/private-key.jwk \
|
|
117
|
+
--worker-name tw-api-app \
|
|
118
|
+
--sub teacher \
|
|
119
|
+
--role admin \
|
|
120
|
+
--scope posts:read \
|
|
121
|
+
--scope posts:write \
|
|
122
|
+
--ttl 1h
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`scope` claimはOAuth慣習に合わせて空白区切り文字列としてJWTへ入れます。IRとブロック側では配列として扱います。
|
|
126
|
+
|
|
127
|
+
`--worker-name` を指定すると、issuer は `https://<worker-name>.workers.dev`、audience は `<worker-name>` になります。生成Worker側も同じ値を既定値として検証するため、`BEARER_JWT_ISSUER` / `BEARER_JWT_AUDIENCE` を設定し忘れても別用途のtokenを受け入れません。カスタムドメインや用途名を使う場合は `--issuer` / `--audience` と Worker側環境変数を合わせて指定します。
|
|
128
|
+
|
|
129
|
+
package改名前から発行済みのtokenとの互換性を保つため、`--worker-name`と`--audience`をどちらも省略した場合の既定audienceは、legacy値`turbowarp-http-server-cloudflare`のまま維持します。新規構成では曖昧な既定値に依存せず、`--worker-name`または`--audience`を明示してください。
|
|
130
|
+
|
|
131
|
+
ただし、MVPの生成器は認証ライブラリ相当の網羅的な検証までは行いません。productionで使う前に、少なくとも provider ごとのscope、Microsoft tenant制約、session cookie rotation、ログアウト後のprovider session、エラー画面、監査ログを確認します。必要に応じて Auth.js、Arctic、OpenID Client、またはCloudflare Accessの検証処理へ置き換えます。
|
|
132
|
+
|
|
133
|
+
## 秘密情報の扱い
|
|
134
|
+
|
|
135
|
+
クライアントID、クライアントシークレット、Cookie署名鍵、JWT issuer/audience などの秘密情報は、TurboWarp ブロックや `.sb3` に保存しません。Cloudflare の Secrets または環境変数に置きます。
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
wrangler secret put GOOGLE_CLIENT_ID
|
|
139
|
+
wrangler secret put GOOGLE_CLIENT_SECRET
|
|
140
|
+
wrangler secret put SESSION_SECRET
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
ブロックが扱うのは、プロバイダ名、保護ルート、未認証時の動作だけです。この分離により、教育用の見通しと実運用時の安全性を両立させます。
|
|
144
|
+
|
|
145
|
+
## 今後の実装候補
|
|
146
|
+
|
|
147
|
+
- providerごとのredirect先制御。
|
|
148
|
+
- Cloudflare KV/D1を使ったsession store。
|
|
149
|
+
- 認証ライブラリの選定と薄いadapter。
|
|
150
|
+
- Microsoft tenant ID 固定オプション。
|
|
151
|
+
- Bearer JWT mode のJWKS検証。
|
|
152
|
+
- `現在のユーザーID`、`現在のユーザー名`、`ログイン済み?` reporter block。
|
|
153
|
+
- `/auth/me` を呼び出す TurboWarp 側 reporter block。
|
|
154
|
+
- `ルート [METHOD] [PATH] はログイン必須` の日本語ブロック表記。
|
package/docs/index.html
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
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">
|
|
6
|
+
<title>turbowarp-cloudflare-worker</title>
|
|
7
|
+
<style>
|
|
8
|
+
body{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;max-width:900px;margin:0 auto;padding:2rem;line-height:1.6;color:#222}
|
|
9
|
+
code{background:#f3f3f3;padding:.1em .3em;border-radius:.25em}
|
|
10
|
+
pre{background:#f6f8fa;padding:1rem;overflow:auto;border-radius:.5rem}
|
|
11
|
+
</style>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<h1>turbowarp-cloudflare-worker</h1>
|
|
15
|
+
<p>Cloudflare Workers TypeScript/Hono generation support for the turbowarp-http-server family.</p>
|
|
16
|
+
|
|
17
|
+
<h2>Blocks</h2>
|
|
18
|
+
<h3><code>Cloudflare handler [METHOD] [PATH] returns [BODY]</code></h3>
|
|
19
|
+
<p>Creates a minimal HTTP handler IR JSON entry.</p>
|
|
20
|
+
<h3><code>Cloudflare Worker [NAME] with handlers JSON [HANDLERS]</code></h3>
|
|
21
|
+
<p>Creates a Worker IR JSON document from handler entries.</p>
|
|
22
|
+
<h3><code>generated Cloudflare files JSON from IR [IR]</code></h3>
|
|
23
|
+
<p>Runs the generator and returns GeneratedFile[] as JSON.</p>
|
|
24
|
+
|
|
25
|
+
<h2>Target</h2>
|
|
26
|
+
<p>The MVP target is Cloudflare Workers with TypeScript and Hono. External OAuth/OIDC providers and Cloudflare storage bindings are represented in the IR, while direct browser-side deploy is out of scope.</p>
|
|
27
|
+
|
|
28
|
+
<h2>Architecture</h2>
|
|
29
|
+
<p>See <a href="architecture.ja.md">architecture.ja.md</a>.</p>
|
|
30
|
+
</body>
|
|
31
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubohiroya/turbowarp-cloudflare-worker",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Cloudflare Workers TypeScript generator and TurboWarp extension bridge for turbowarp-http-server.",
|
|
5
|
+
"author": "Hiroya Kubo <hiroya@cuc.ac.jp>",
|
|
6
|
+
"license": "MPL-2.0",
|
|
7
|
+
"homepage": "https://github.com/kubohiroya/turbowarp-cloudflare-worker#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/kubohiroya/turbowarp-cloudflare-worker.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/kubohiroya/turbowarp-cloudflare-worker/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"turbowarp",
|
|
17
|
+
"scratch",
|
|
18
|
+
"extension",
|
|
19
|
+
"cloudflare-workers",
|
|
20
|
+
"hono",
|
|
21
|
+
"codegen",
|
|
22
|
+
"typescript"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/",
|
|
27
|
+
"docs/",
|
|
28
|
+
"schemas/",
|
|
29
|
+
"src/",
|
|
30
|
+
"README.md",
|
|
31
|
+
"README.ja.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
"./generator": {
|
|
36
|
+
"types": "./dist/generator.d.ts",
|
|
37
|
+
"import": "./dist/generator.js"
|
|
38
|
+
},
|
|
39
|
+
"./ir": {
|
|
40
|
+
"types": "./dist/ir.d.ts",
|
|
41
|
+
"import": "./dist/ir.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
},
|
|
48
|
+
"packageManager": "pnpm@11.11.0",
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=22.18.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"dev": "vite build --watch",
|
|
54
|
+
"typecheck": "tsc --noEmit",
|
|
55
|
+
"build": "vite build && tsc -p tsconfig.cli.json",
|
|
56
|
+
"lint": "eslint src tests vite.config.ts",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"repo:check": "node scripts/check-repo.ts",
|
|
59
|
+
"pack:check": "npm pack --dry-run --ignore-scripts",
|
|
60
|
+
"check": "pnpm run typecheck && pnpm run lint && pnpm run test && pnpm run check:dist && pnpm run repo:check && pnpm run pack:check",
|
|
61
|
+
"check:dist": "pnpm run build"
|
|
62
|
+
},
|
|
63
|
+
"bin": {
|
|
64
|
+
"turbowarp-cloudflare-worker": "./dist/cli.js"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"hono": "^4.10.7"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@cloudflare/workers-types": "^5.20260826.1",
|
|
71
|
+
"@eslint/js": "^9.39.5",
|
|
72
|
+
"@kubohiroya/vite-plugin-turbowarp-extension": "0.4.0",
|
|
73
|
+
"@types/node": "^24.13.3",
|
|
74
|
+
"eslint": "^9.39.5",
|
|
75
|
+
"typescript": "^5.9.3",
|
|
76
|
+
"typescript-eslint": "^8.66.0",
|
|
77
|
+
"vite": "^8.2.2",
|
|
78
|
+
"vitest": "^4.1.10"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://raw.githubusercontent.com/kubohiroya/turbowarp-extension-template/main/schemas/extension-manifest.schema.json",
|
|
4
|
+
"title": "TurboWarp Extension API Manifest",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": ["formatVersion", "id", "blocks", "menus"],
|
|
8
|
+
"properties": {
|
|
9
|
+
"formatVersion": {"const": 1},
|
|
10
|
+
"id": {"type": "string", "pattern": "^[a-z0-9]+$"},
|
|
11
|
+
"blocks": {
|
|
12
|
+
"type": "array",
|
|
13
|
+
"items": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"additionalProperties": false,
|
|
16
|
+
"required": ["opcode", "blockType", "arguments"],
|
|
17
|
+
"properties": {
|
|
18
|
+
"opcode": {"type": "string", "minLength": 1},
|
|
19
|
+
"blockType": {"type": "string", "minLength": 1},
|
|
20
|
+
"arguments": {
|
|
21
|
+
"type": "array",
|
|
22
|
+
"items": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"additionalProperties": false,
|
|
25
|
+
"required": ["id", "type"],
|
|
26
|
+
"properties": {
|
|
27
|
+
"id": {"type": "string", "minLength": 1},
|
|
28
|
+
"type": {"type": "string", "minLength": 1},
|
|
29
|
+
"menu": {"type": "string", "minLength": 1}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"menus": {
|
|
37
|
+
"type": "array",
|
|
38
|
+
"items": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"additionalProperties": false,
|
|
41
|
+
"required": ["id", "acceptReporters"],
|
|
42
|
+
"properties": {
|
|
43
|
+
"id": {"type": "string", "minLength": 1},
|
|
44
|
+
"acceptReporters": {"type": "boolean"}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extensionName": "TurboWarp HTTP Server Cloudflare",
|
|
3
|
+
"blocks": [
|
|
4
|
+
{
|
|
5
|
+
"opcode": "createHandlerIr",
|
|
6
|
+
"category": "core",
|
|
7
|
+
"blockType": "REPORTER",
|
|
8
|
+
"text": "Cloudflare handler [METHOD] [PATH] returns [BODY]",
|
|
9
|
+
"description": "Creates a minimal HTTP handler IR JSON entry for the Cloudflare generator.",
|
|
10
|
+
"arguments": {
|
|
11
|
+
"METHOD": {"type": "STRING", "defaultValue": "GET"},
|
|
12
|
+
"PATH": {"type": "STRING", "defaultValue": "/hello"},
|
|
13
|
+
"BODY": {"type": "STRING", "defaultValue": "Hello from TurboWarp"}
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"opcode": "createWorkerIr",
|
|
18
|
+
"category": "core",
|
|
19
|
+
"blockType": "REPORTER",
|
|
20
|
+
"text": "Cloudflare Worker [NAME] with handlers JSON [HANDLERS]",
|
|
21
|
+
"description": "Creates a deployable Worker IR JSON document from handler entries.",
|
|
22
|
+
"arguments": {
|
|
23
|
+
"NAME": {"type": "STRING", "defaultValue": "tw-http-app"},
|
|
24
|
+
"HANDLERS": {"type": "STRING", "defaultValue": "[]"}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"opcode": "generateFilesJson",
|
|
29
|
+
"category": "core",
|
|
30
|
+
"blockType": "REPORTER",
|
|
31
|
+
"text": "generated Cloudflare files JSON from IR [IR]",
|
|
32
|
+
"description": "Runs the Cloudflare Workers/Hono generator and returns GeneratedFile[] as JSON.",
|
|
33
|
+
"arguments": {
|
|
34
|
+
"IR": {"type": "STRING", "defaultValue": "{\"name\":\"tw-http-app\",\"handlers\":[]}"}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"kind": "separator",
|
|
39
|
+
"category": "auth"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"opcode": "createProtectedRouteIr",
|
|
43
|
+
"category": "auth",
|
|
44
|
+
"blockType": "REPORTER",
|
|
45
|
+
"text": "protected route [METHOD] [PATH] when unauthenticated [ON_UNAUTHENTICATED]",
|
|
46
|
+
"description": "Creates an auth guard IR entry for a route protected by external OAuth/OIDC.",
|
|
47
|
+
"arguments": {
|
|
48
|
+
"METHOD": {"type": "STRING", "defaultValue": "GET"},
|
|
49
|
+
"PATH": {"type": "STRING", "defaultValue": "/private"},
|
|
50
|
+
"ON_UNAUTHENTICATED": {"type": "STRING", "defaultValue": "redirect-login"}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"opcode": "createAuthIr",
|
|
55
|
+
"category": "auth",
|
|
56
|
+
"blockType": "REPORTER",
|
|
57
|
+
"text": "external OAuth/OIDC auth providers [PROVIDERS] protected routes JSON [PROTECTED_ROUTES]",
|
|
58
|
+
"description": "Creates auth IR for Google, Microsoft, and GitHub account sign-in.",
|
|
59
|
+
"arguments": {
|
|
60
|
+
"PROVIDERS": {"type": "STRING", "defaultValue": "google,github"},
|
|
61
|
+
"PROTECTED_ROUTES": {"type": "STRING", "defaultValue": "[]"}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"opcode": "createBearerRouteIr",
|
|
66
|
+
"category": "auth",
|
|
67
|
+
"blockType": "REPORTER",
|
|
68
|
+
"text": "API route [METHOD] [PATH] requires bearer token",
|
|
69
|
+
"description": "Creates a protected route IR entry that requires a valid self-issued ES256 bearer JWT.",
|
|
70
|
+
"arguments": {
|
|
71
|
+
"METHOD": {"type": "STRING", "defaultValue": "GET"},
|
|
72
|
+
"PATH": {"type": "STRING", "defaultValue": "/api/items"}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"opcode": "createBearerRoleRouteIr",
|
|
77
|
+
"category": "auth",
|
|
78
|
+
"blockType": "REPORTER",
|
|
79
|
+
"text": "API route [METHOD] [PATH] requires bearer role [ROLE]",
|
|
80
|
+
"description": "Creates a bearer JWT protected route IR entry that also requires a role claim.",
|
|
81
|
+
"arguments": {
|
|
82
|
+
"METHOD": {"type": "STRING", "defaultValue": "POST"},
|
|
83
|
+
"PATH": {"type": "STRING", "defaultValue": "/api/admin"},
|
|
84
|
+
"ROLE": {"type": "STRING", "defaultValue": "admin"}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"opcode": "createBearerScopeRouteIr",
|
|
89
|
+
"category": "auth",
|
|
90
|
+
"blockType": "REPORTER",
|
|
91
|
+
"text": "API route [METHOD] [PATH] requires bearer scope [SCOPE]",
|
|
92
|
+
"description": "Creates a bearer JWT protected route IR entry that also requires one or more scopes.",
|
|
93
|
+
"arguments": {
|
|
94
|
+
"METHOD": {"type": "STRING", "defaultValue": "POST"},
|
|
95
|
+
"PATH": {"type": "STRING", "defaultValue": "/api/posts"},
|
|
96
|
+
"SCOPE": {"type": "STRING", "defaultValue": "posts:write"}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"opcode": "createWorkerIrWithAuth",
|
|
101
|
+
"category": "auth",
|
|
102
|
+
"blockType": "REPORTER",
|
|
103
|
+
"text": "Cloudflare Worker [NAME] with handlers JSON [HANDLERS] and auth JSON [AUTH]",
|
|
104
|
+
"description": "Creates Worker IR with an external OAuth/OIDC auth policy.",
|
|
105
|
+
"arguments": {
|
|
106
|
+
"NAME": {"type": "STRING", "defaultValue": "tw-http-app"},
|
|
107
|
+
"HANDLERS": {"type": "STRING", "defaultValue": "[]"},
|
|
108
|
+
"AUTH": {
|
|
109
|
+
"type": "STRING",
|
|
110
|
+
"defaultValue": "{\"mode\":\"external-oauth-oidc\",\"providers\":[\"google\"],\"protectedRoutes\":[]}"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|