@astrale-os/adapter-cloudflare 0.5.0-beta.7 → 0.5.0-beta.70
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/CHANGELOG.md +878 -0
- package/README.md +25 -0
- package/dist/adapter.d.ts +17 -0
- package/dist/adapter.js +177 -0
- package/dist/build/artifact.d.ts +7 -0
- package/dist/build/artifact.js +163 -0
- package/dist/build/bundle/admit.d.ts +1 -0
- package/dist/build/bundle/admit.js +9 -0
- package/dist/build/closure.d.ts +2 -0
- package/dist/build/closure.js +22 -0
- package/dist/build/codegen/execution.d.ts +3 -0
- package/dist/build/codegen/execution.js +2 -0
- package/dist/build/codegen/merge.d.ts +0 -1
- package/dist/build/codegen/merge.js +0 -1
- package/dist/build/codegen/wrangler.d.ts +13 -1
- package/dist/build/codegen/wrangler.js +32 -17
- package/dist/build/configuration/addressing.d.ts +2 -0
- package/dist/build/configuration/addressing.js +11 -0
- package/dist/build/configuration/invocation-timeout.d.ts +2 -0
- package/dist/build/configuration/invocation-timeout.js +9 -0
- package/dist/build/configuration/request-limit.d.ts +2 -0
- package/dist/build/configuration/request-limit.js +9 -0
- package/dist/build/configuration/router.d.ts +7 -0
- package/dist/build/configuration/router.js +11 -0
- package/dist/build/configuration/worker-name.d.ts +2 -0
- package/dist/build/configuration/worker-name.js +18 -0
- package/dist/build/configuration.d.ts +5 -0
- package/dist/build/configuration.js +5 -0
- package/dist/build/direct.d.ts +4 -0
- package/dist/build/direct.js +93 -0
- package/dist/build/frontend/routes.d.ts +2 -0
- package/dist/build/frontend/routes.js +11 -0
- package/dist/build/frontend-v1.d.ts +16 -0
- package/dist/build/frontend-v1.js +133 -0
- package/dist/build/index.d.ts +10 -16
- package/dist/build/index.js +9 -16
- package/dist/build/materialize.d.ts +4 -0
- package/dist/build/materialize.js +10 -0
- package/dist/build/metafile.d.ts +5 -0
- package/dist/build/metafile.js +14 -0
- package/dist/build/parse-output.d.ts +0 -1
- package/dist/build/parse-output.js +0 -1
- package/dist/build/qualification.d.ts +5 -0
- package/dist/build/qualification.js +7 -0
- package/dist/build/roots.d.ts +2 -0
- package/dist/build/roots.js +34 -0
- package/dist/build/worker/artifact.d.ts +40 -0
- package/dist/build/worker/artifact.js +1 -0
- package/dist/build/worker/artifact.load.d.ts +3 -0
- package/dist/build/worker/artifact.load.js +308 -0
- package/dist/build/worker/artifact.manifest.d.ts +48 -0
- package/dist/build/worker/artifact.manifest.js +87 -0
- package/dist/build/worker/artifact.paths.d.ts +4 -0
- package/dist/build/worker/artifact.paths.js +25 -0
- package/dist/build/worker/codegen/entry.d.ts +2 -0
- package/dist/build/worker/codegen/entry.js +28 -0
- package/dist/build/worker/codegen/service.d.ts +16 -0
- package/dist/build/worker/codegen/service.js +52 -0
- package/dist/build/worker/execution.prepare.d.ts +18 -0
- package/dist/build/worker/execution.prepare.js +109 -0
- package/dist/build/worker/index.d.ts +2 -0
- package/dist/build/worker/index.js +1 -0
- package/dist/build/worker/modules.d.ts +11 -0
- package/dist/build/worker/modules.js +26 -0
- package/dist/build/worker/runtime.d.ts +10 -0
- package/dist/build/worker/runtime.js +35 -0
- package/dist/build/worker/specifier.d.ts +1 -0
- package/dist/build/worker/specifier.js +5 -0
- package/dist/build/wrangler/bundle.d.ts +10 -0
- package/dist/build/wrangler/bundle.js +29 -0
- package/dist/build/wrangler/deploy.d.ts +24 -0
- package/dist/build/wrangler/deploy.js +44 -0
- package/dist/build/wrangler/development.d.ts +17 -0
- package/dist/build/wrangler/development.js +136 -0
- package/dist/build/wrangler/process.d.ts +17 -0
- package/dist/build/wrangler/process.js +115 -0
- package/dist/build/wrangler/secrets.d.ts +6 -0
- package/dist/build/wrangler/secrets.js +58 -0
- package/dist/build/wrangler/status.d.ts +14 -0
- package/dist/build/wrangler/status.js +56 -0
- package/dist/build/wrangler/type-generation.d.ts +6 -0
- package/dist/build/wrangler/type-generation.js +19 -0
- package/dist/build/wrangler-cli.d.ts +6 -86
- package/dist/build/wrangler-cli.js +6 -275
- package/dist/cloudflare.d.ts +1 -34
- package/dist/cloudflare.js +1 -205
- package/dist/deploy/deploy.d.ts +15 -0
- package/dist/deploy/deploy.js +204 -0
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/index.js +1 -0
- package/dist/identity/binding.d.ts +2 -0
- package/dist/identity/binding.js +2 -0
- package/dist/identity/material.d.ts +7 -0
- package/dist/identity/material.js +42 -0
- package/dist/identity/secret.d.ts +3 -0
- package/dist/identity/secret.js +7 -0
- package/dist/identity/source.d.ts +26 -0
- package/dist/identity/source.js +98 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +3 -4
- package/dist/params.d.ts +30 -5
- package/dist/params.js +0 -1
- package/dist/release/deployment.d.ts +44 -0
- package/dist/release/deployment.js +141 -0
- package/dist/release/index.d.ts +2 -0
- package/dist/release/index.js +2 -0
- package/dist/release/staged-worker-name.d.ts +3 -0
- package/dist/release/staged-worker-name.js +10 -0
- package/dist/worker/entry.d.ts +43 -0
- package/dist/worker/entry.js +181 -0
- package/dist/worker/fetch.d.ts +0 -1
- package/dist/worker/fetch.js +0 -1
- package/dist/worker/identity.d.ts +7 -0
- package/dist/worker/identity.js +23 -0
- package/dist/worker/index.d.ts +2 -61
- package/dist/worker/index.js +2 -216
- package/package.json +30 -19
- package/template/astrale.config.ts +19 -11
- package/dist/build/codegen/identity.d.ts +0 -10
- package/dist/build/codegen/identity.d.ts.map +0 -1
- package/dist/build/codegen/identity.js +0 -32
- package/dist/build/codegen/identity.js.map +0 -1
- package/dist/build/codegen/merge.d.ts.map +0 -1
- package/dist/build/codegen/merge.js.map +0 -1
- package/dist/build/codegen/worker.d.ts +0 -12
- package/dist/build/codegen/worker.d.ts.map +0 -1
- package/dist/build/codegen/worker.js +0 -40
- package/dist/build/codegen/worker.js.map +0 -1
- package/dist/build/codegen/wrangler.d.ts.map +0 -1
- package/dist/build/codegen/wrangler.js.map +0 -1
- package/dist/build/frontend.d.ts +0 -26
- package/dist/build/frontend.d.ts.map +0 -1
- package/dist/build/frontend.js +0 -263
- package/dist/build/frontend.js.map +0 -1
- package/dist/build/index.d.ts.map +0 -1
- package/dist/build/index.js.map +0 -1
- package/dist/build/parse-output.d.ts.map +0 -1
- package/dist/build/parse-output.js.map +0 -1
- package/dist/build/prepare.d.ts +0 -18
- package/dist/build/prepare.d.ts.map +0 -1
- package/dist/build/prepare.js +0 -117
- package/dist/build/prepare.js.map +0 -1
- package/dist/build/worker.d.ts +0 -15
- package/dist/build/worker.d.ts.map +0 -1
- package/dist/build/worker.js +0 -21
- package/dist/build/worker.js.map +0 -1
- package/dist/build/wrangler-cli.d.ts.map +0 -1
- package/dist/build/wrangler-cli.js.map +0 -1
- package/dist/cloudflare.d.ts.map +0 -1
- package/dist/cloudflare.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/params.d.ts.map +0 -1
- package/dist/params.js.map +0 -1
- package/dist/worker/fetch.d.ts.map +0 -1
- package/dist/worker/fetch.js.map +0 -1
- package/dist/worker/index.d.ts.map +0 -1
- package/dist/worker/index.js.map +0 -1
- package/src/build/codegen/identity.ts +0 -40
- package/src/build/codegen/merge.ts +0 -92
- package/src/build/codegen/worker.ts +0 -53
- package/src/build/codegen/wrangler.ts +0 -127
- package/src/build/frontend.ts +0 -324
- package/src/build/index.ts +0 -29
- package/src/build/parse-output.ts +0 -60
- package/src/build/prepare.ts +0 -161
- package/src/build/worker.ts +0 -37
- package/src/build/wrangler-cli.ts +0 -362
- package/src/cloudflare.ts +0 -251
- package/src/index.ts +0 -21
- package/src/params.ts +0 -92
- package/src/worker/fetch.ts +0 -46
- package/src/worker/index.ts +0 -329
- package/src/worker/tsconfig.json +0 -10
package/src/cloudflare.ts
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `cloudflare(envs)` — the Cloudflare deployment adapter.
|
|
3
|
-
*
|
|
4
|
-
* Owns everything target-specific: it codegens the Worker entry + wrangler
|
|
5
|
-
* config (the dev never sees a `wrangler.jsonc`), materializes the optional frontend
|
|
6
|
-
* SPA, and shells out to `wrangler`. `watch` → `wrangler dev` (local URL);
|
|
7
|
-
* `deploy` → `wrangler deploy` (workers.dev or a custom-domain URL); secrets →
|
|
8
|
-
* `wrangler secret bulk`. Both `watch` and `deploy` return the URL the CLI
|
|
9
|
-
* prints and `astrale domain install <url>` consumes.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { DomainAdapter } from '@astrale-os/sdk'
|
|
13
|
-
|
|
14
|
-
import { defineAdapter } from '@astrale-os/sdk'
|
|
15
|
-
|
|
16
|
-
import type { CloudflareParams } from './params.js'
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
bulkPutSecrets,
|
|
20
|
-
buildCloudflareWorker,
|
|
21
|
-
buildFrontend,
|
|
22
|
-
logTo,
|
|
23
|
-
prepare,
|
|
24
|
-
runWranglerDeploy,
|
|
25
|
-
runWranglerDev,
|
|
26
|
-
runWranglerTypes,
|
|
27
|
-
watchFrontend,
|
|
28
|
-
} from './build/index.js'
|
|
29
|
-
|
|
30
|
-
export function cloudflare(
|
|
31
|
-
envs: Record<string, CloudflareParams>,
|
|
32
|
-
): DomainAdapter<CloudflareParams> {
|
|
33
|
-
return cloudflareWithDependencies(envs, {
|
|
34
|
-
bulkPutSecrets,
|
|
35
|
-
buildCloudflareWorker,
|
|
36
|
-
buildFrontend,
|
|
37
|
-
logTo,
|
|
38
|
-
prepare,
|
|
39
|
-
runWranglerDeploy,
|
|
40
|
-
runWranglerDev,
|
|
41
|
-
runWranglerTypes,
|
|
42
|
-
watchFrontend,
|
|
43
|
-
waitUntilLive,
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface CloudflareAdapterDependencies {
|
|
48
|
-
readonly bulkPutSecrets: typeof bulkPutSecrets
|
|
49
|
-
readonly buildCloudflareWorker: typeof buildCloudflareWorker
|
|
50
|
-
readonly buildFrontend: typeof buildFrontend
|
|
51
|
-
readonly logTo: typeof logTo
|
|
52
|
-
readonly prepare: typeof prepare
|
|
53
|
-
readonly runWranglerDeploy: typeof runWranglerDeploy
|
|
54
|
-
readonly runWranglerDev: typeof runWranglerDev
|
|
55
|
-
readonly runWranglerTypes: typeof runWranglerTypes
|
|
56
|
-
readonly watchFrontend: typeof watchFrontend
|
|
57
|
-
readonly waitUntilLive: typeof waitUntilLive
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Exact orchestration seam used by adapter-level deployment qualification. */
|
|
61
|
-
export function cloudflareWithDependencies(
|
|
62
|
-
envs: Record<string, CloudflareParams>,
|
|
63
|
-
dependencies: CloudflareAdapterDependencies,
|
|
64
|
-
): DomainAdapter<CloudflareParams> {
|
|
65
|
-
return defineAdapter<CloudflareParams>({
|
|
66
|
-
name: 'cloudflare',
|
|
67
|
-
envs,
|
|
68
|
-
|
|
69
|
-
async build(params, ctx) {
|
|
70
|
-
await dependencies.buildCloudflareWorker({
|
|
71
|
-
params,
|
|
72
|
-
context: ctx,
|
|
73
|
-
onLog: dependencies.logTo(),
|
|
74
|
-
})
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
async watch(params, ctx) {
|
|
78
|
-
const onLog = dependencies.logTo()
|
|
79
|
-
const frontend = await dependencies.buildFrontend({
|
|
80
|
-
definition: ctx.definition,
|
|
81
|
-
projectDir: ctx.projectDir,
|
|
82
|
-
onLog,
|
|
83
|
-
})
|
|
84
|
-
const { configPath, port } = await dependencies.prepare(params, ctx, 'dev', frontend)
|
|
85
|
-
const handle = await dependencies.runWranglerDev({
|
|
86
|
-
projectDir: ctx.projectDir,
|
|
87
|
-
configPath,
|
|
88
|
-
port,
|
|
89
|
-
remote: Boolean(params.remote),
|
|
90
|
-
autoPickPort: params.port === undefined,
|
|
91
|
-
...(params.host ? { ip: '0.0.0.0' } : {}),
|
|
92
|
-
onReload: ctx.onReload,
|
|
93
|
-
onLog,
|
|
94
|
-
})
|
|
95
|
-
let frontendWatch: ReturnType<typeof watchFrontend>
|
|
96
|
-
try {
|
|
97
|
-
frontendWatch = dependencies.watchFrontend({
|
|
98
|
-
definition: ctx.definition,
|
|
99
|
-
projectDir: ctx.projectDir,
|
|
100
|
-
onLog,
|
|
101
|
-
// Routes and source recipes are immutable for this watch generation.
|
|
102
|
-
// Wrangler already observes the atomically swapped asset stage, so a
|
|
103
|
-
// source rebuild needs no config regeneration.
|
|
104
|
-
onRebuild: ctx.onReload,
|
|
105
|
-
})
|
|
106
|
-
} catch (error) {
|
|
107
|
-
try {
|
|
108
|
-
await handle.stop()
|
|
109
|
-
} catch (cleanupError) {
|
|
110
|
-
throw new AggregateError(
|
|
111
|
-
[error, cleanupError],
|
|
112
|
-
'cloudflare frontend watcher startup failed and Wrangler cleanup also failed',
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
throw error
|
|
116
|
-
}
|
|
117
|
-
// With --host the actionable URL is the PUBLIC one (the tunnel/proxy
|
|
118
|
-
// front), not the local bind — print and spec-stamp that.
|
|
119
|
-
return {
|
|
120
|
-
url: params.host ?? handle.url,
|
|
121
|
-
async stop() {
|
|
122
|
-
const errors: unknown[] = []
|
|
123
|
-
try {
|
|
124
|
-
await frontendWatch?.stop()
|
|
125
|
-
} catch (error) {
|
|
126
|
-
errors.push(error)
|
|
127
|
-
}
|
|
128
|
-
try {
|
|
129
|
-
await handle.stop()
|
|
130
|
-
} catch (error) {
|
|
131
|
-
errors.push(error)
|
|
132
|
-
}
|
|
133
|
-
if (errors.length === 1) throw errors[0]
|
|
134
|
-
if (errors.length > 1) {
|
|
135
|
-
throw new AggregateError(errors, 'cloudflare development cleanup failed')
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
|
|
141
|
-
// Config hot-regen: rewrite the generated files only — the running
|
|
142
|
-
// `wrangler dev` watches its `--config` (and the worker entry) and reloads
|
|
143
|
-
// them itself, so a `astrale.config.ts` edit lands without a restart.
|
|
144
|
-
// Mirrors `watch`'s prep exactly (codegen + frontend build), minus the spawn.
|
|
145
|
-
async regenerate(params, ctx) {
|
|
146
|
-
const frontend = await dependencies.buildFrontend({
|
|
147
|
-
definition: ctx.definition,
|
|
148
|
-
projectDir: ctx.projectDir,
|
|
149
|
-
onLog: dependencies.logTo(),
|
|
150
|
-
})
|
|
151
|
-
const { configPath } = await dependencies.prepare(params, ctx, 'dev', frontend)
|
|
152
|
-
await dependencies.runWranglerTypes({
|
|
153
|
-
projectDir: ctx.projectDir,
|
|
154
|
-
configPath,
|
|
155
|
-
onLog: dependencies.logTo(),
|
|
156
|
-
})
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
async deploy(params, ctx) {
|
|
160
|
-
const frontend = await dependencies.buildFrontend({
|
|
161
|
-
definition: ctx.definition,
|
|
162
|
-
projectDir: ctx.projectDir,
|
|
163
|
-
onLog: dependencies.logTo(),
|
|
164
|
-
})
|
|
165
|
-
const {
|
|
166
|
-
configPath,
|
|
167
|
-
fallbackConfigPath,
|
|
168
|
-
workerName: name,
|
|
169
|
-
} = await dependencies.prepare(params, ctx, 'deploy', frontend)
|
|
170
|
-
const { url, deploymentVersion } = await dependencies.runWranglerDeploy({
|
|
171
|
-
projectDir: ctx.projectDir,
|
|
172
|
-
configPath,
|
|
173
|
-
workerName: name,
|
|
174
|
-
...(fallbackConfigPath ? { fallbackConfigPath } : {}),
|
|
175
|
-
...(params.route ? { route: params.route } : {}),
|
|
176
|
-
onLog: dependencies.logTo(),
|
|
177
|
-
})
|
|
178
|
-
if (Object.keys(ctx.secrets).length > 0) {
|
|
179
|
-
await dependencies.bulkPutSecrets({
|
|
180
|
-
projectDir: ctx.projectDir,
|
|
181
|
-
configPath,
|
|
182
|
-
secrets: ctx.secrets,
|
|
183
|
-
onLog: dependencies.logTo(),
|
|
184
|
-
})
|
|
185
|
-
}
|
|
186
|
-
// A first deploy on a fresh `*.workers.dev` host can take ~30-60s to
|
|
187
|
-
// propagate; an `astrale domain install <url>` issued right away would
|
|
188
|
-
// 404 (Cloudflare 1042). Block until the URL actually serves so the
|
|
189
|
-
// install line we print is immediately actionable.
|
|
190
|
-
await dependencies.waitUntilLive(url, dependencies.logTo(), deploymentVersion)
|
|
191
|
-
return { url }
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
secretsFile(params) {
|
|
195
|
-
return params.secrets
|
|
196
|
-
},
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Poll until the deployed Worker health endpoint returns exactly 200.
|
|
202
|
-
*/
|
|
203
|
-
async function waitUntilLive(
|
|
204
|
-
url: string,
|
|
205
|
-
onLog: (line: string) => void,
|
|
206
|
-
expectedDeploymentVersion?: string,
|
|
207
|
-
timeoutMs = 90_000,
|
|
208
|
-
): Promise<void> {
|
|
209
|
-
const probe = new URL('/health', url)
|
|
210
|
-
const metadata = new URL('/meta', url)
|
|
211
|
-
const deadline = Date.now() + timeoutMs
|
|
212
|
-
let waited = false
|
|
213
|
-
let lastStatus: number | undefined
|
|
214
|
-
let lastDeploymentVersion: string | undefined
|
|
215
|
-
for (;;) {
|
|
216
|
-
try {
|
|
217
|
-
const res = await fetch(probe, { redirect: 'manual' })
|
|
218
|
-
lastStatus = res.status
|
|
219
|
-
await res.body?.cancel()
|
|
220
|
-
if (res.status === 200) {
|
|
221
|
-
if (expectedDeploymentVersion === undefined) return
|
|
222
|
-
const meta = await fetch(metadata, { redirect: 'manual' })
|
|
223
|
-
if (meta.status === 200) {
|
|
224
|
-
const body = (await meta.json()) as { deploymentVersion?: unknown }
|
|
225
|
-
lastDeploymentVersion =
|
|
226
|
-
typeof body.deploymentVersion === 'string' ? body.deploymentVersion : undefined
|
|
227
|
-
if (lastDeploymentVersion === expectedDeploymentVersion) return
|
|
228
|
-
} else {
|
|
229
|
-
await meta.body?.cancel()
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} catch {
|
|
233
|
-
// Network hiccup — treat like "not live yet" and keep polling.
|
|
234
|
-
}
|
|
235
|
-
if (Date.now() >= deadline) {
|
|
236
|
-
throw new Error(
|
|
237
|
-
`deployed Worker health did not reach HTTP 200 within ${Math.round(timeoutMs / 1000)}s` +
|
|
238
|
-
(lastStatus === undefined ? '' : ` (last status ${lastStatus})`) +
|
|
239
|
-
(expectedDeploymentVersion === undefined
|
|
240
|
-
? ''
|
|
241
|
-
: `; deployment version ${JSON.stringify(lastDeploymentVersion)} ` +
|
|
242
|
-
`did not reach ${JSON.stringify(expectedDeploymentVersion)}`),
|
|
243
|
-
)
|
|
244
|
-
}
|
|
245
|
-
if (!waited) {
|
|
246
|
-
waited = true
|
|
247
|
-
onLog('waiting for the URL to go live (first deploys can take ~30-60s)…')
|
|
248
|
-
}
|
|
249
|
-
await new Promise((r) => setTimeout(r, 3000))
|
|
250
|
-
}
|
|
251
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@astrale-os/adapter-cloudflare` — deploy an Astrale domain as a standalone
|
|
3
|
-
* Cloudflare Worker on YOUR OWN Cloudflare account.
|
|
4
|
-
*
|
|
5
|
-
* import { cloudflare } from '@astrale-os/adapter-cloudflare'
|
|
6
|
-
*
|
|
7
|
-
* adapter: cloudflare({
|
|
8
|
-
* dev: { secrets: '.env.dev' },
|
|
9
|
-
* prod: { route: 'crm.acme.dev', secrets: '.env.prod' },
|
|
10
|
-
* })
|
|
11
|
-
*
|
|
12
|
-
* `dev` runs `wrangler dev` locally; an env with no `route` ships to
|
|
13
|
-
* `*.workers.dev`; an env with a `route` ships to that custom domain.
|
|
14
|
-
*
|
|
15
|
-
* Prefer a managed deploy (no Cloudflare account)? Use
|
|
16
|
-
* `@astrale-os/adapter-astrale`, which builds the same bundle via this package's
|
|
17
|
-
* `/build` toolkit and ships it through the Astrale platform.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
export { cloudflare } from './cloudflare.js'
|
|
21
|
-
export type { CloudflareParams } from './params.js'
|
package/src/params.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `CloudflareParams` — the provider-typed config for the Cloudflare adapter.
|
|
3
|
-
*
|
|
4
|
-
* One type covers every env; per-env differences are just optional fields. The
|
|
5
|
-
* same `{ dev, prod, canary, … }` map a developer writes in `astrale.config.ts`
|
|
6
|
-
* is `Record<string, CloudflareParams>`.
|
|
7
|
-
*
|
|
8
|
-
* Three deployment shapes fall out of which fields are set:
|
|
9
|
-
* • dev (local) — `watch()` runs `wrangler dev`; URL = http://localhost:<port>
|
|
10
|
-
* • dev-remote — `deploy()` with no `route`; URL = https://<name>.<sub>.workers.dev
|
|
11
|
-
* • remote (custom) — `deploy()` with `route`; URL = https://<route>
|
|
12
|
-
*/
|
|
13
|
-
export interface CloudflareParams {
|
|
14
|
-
/**
|
|
15
|
-
* Custom route / hostname for a routed deploy, e.g. `'crm.acme.dev'`. Omit to
|
|
16
|
-
* deploy to `*.workers.dev`. Ignored by local `wrangler dev` (URL is
|
|
17
|
-
* localhost) but still used as the placeholder base domain there.
|
|
18
|
-
*/
|
|
19
|
-
readonly route?: string
|
|
20
|
-
/** Gitignored secrets file (whole contents = secrets), e.g. `'.env.dev'`. */
|
|
21
|
-
readonly secrets?: string
|
|
22
|
-
/** Local dev port for `wrangler dev`. Default 8787. */
|
|
23
|
-
readonly port?: number
|
|
24
|
-
/**
|
|
25
|
-
* Public URL the dev server is reached through (tunnel / sandbox preview /
|
|
26
|
-
* reverse proxy), e.g. `'https://my-box.preview.dev'`. Sets BOTH effects an
|
|
27
|
-
* off-localhost dev needs: wrangler binds 0.0.0.0 (reachable from outside)
|
|
28
|
-
* and `WORKER_URL` is pinned to this URL so the worker's per-request-Host
|
|
29
|
-
* identity (`iss`) doesn't drift to the proxy's internal hostname.
|
|
30
|
-
* Usually injected by `pnpm dev --host <url>` rather than written here.
|
|
31
|
-
*/
|
|
32
|
-
readonly host?: string
|
|
33
|
-
/** Override the Worker name. Default: derived from the domain origin. */
|
|
34
|
-
readonly workerName?: string
|
|
35
|
-
/** Run `wrangler dev --remote` (edge isolate) instead of local workerd. */
|
|
36
|
-
readonly remote?: boolean
|
|
37
|
-
/** Extra plain (non-secret) vars to inject as Worker vars. */
|
|
38
|
-
readonly vars?: Record<string, string>
|
|
39
|
-
/**
|
|
40
|
-
* Escape hatch: raw wrangler config deep-merged over the generated base. Use
|
|
41
|
-
* it to declare extra bindings the adapter has no typed field for — KV, R2,
|
|
42
|
-
* D1, queues, service bindings, extra `compatibility_flags`, cron `triggers`,
|
|
43
|
-
* Hyperdrive, etc.
|
|
44
|
-
*
|
|
45
|
-
* wrangler: {
|
|
46
|
-
* kv_namespaces: [{ binding: 'CACHE', id: '<kv-id>' }],
|
|
47
|
-
* r2_buckets: [{ binding: 'FILES', bucket_name: 'my-bucket' }],
|
|
48
|
-
* }
|
|
49
|
-
*
|
|
50
|
-
* The merge is additive: arrays concat (so your `services` keep the adapter's
|
|
51
|
-
* `SELF` binding and your `compatibility_flags` keep `nodejs_compat`); new
|
|
52
|
-
* keys are added as-is. The adapter-owned keys `name`, `main`, `assets`,
|
|
53
|
-
* `routes` are rejected — use `workerName` and `route` instead. Avoid
|
|
54
|
-
* the reserved binding names `SELF` and `ASSETS`. Durable Objects need extra
|
|
55
|
-
* worker-entry codegen and aren't supported through this field yet.
|
|
56
|
-
*/
|
|
57
|
-
readonly wrangler?: Record<string, unknown>
|
|
58
|
-
/**
|
|
59
|
-
* Route subrequests to platform INSTANCE hostnames through a service binding
|
|
60
|
-
* instead of the public edge. A Cloudflare Worker can't fetch a same-zone
|
|
61
|
-
* hostname served by another Worker — Cloudflare 522s it — so without this the
|
|
62
|
-
* worker can't fetch an instance kernel's JWKS to verify an inbound credential
|
|
63
|
-
* from that instance, and every cross-instance call (install hooks, the GUI's
|
|
64
|
-
* delegated calls, authed views) fails with `2002 Credential verification
|
|
65
|
-
* failed`. Point it at a router Worker that reaches those hosts internally
|
|
66
|
-
* (Astrale: `admin-router`).
|
|
67
|
-
*
|
|
68
|
-
* Wires BOTH halves the SDK needs: the `<binding>` service binding in the
|
|
69
|
-
* generated wrangler config, and a `routeSubrequest` predicate in the worker
|
|
70
|
-
* entry that diverts matching hosts through it.
|
|
71
|
-
*
|
|
72
|
-
* ON BY DEFAULT (targets `admin-router`) so every adapter-deployed worker can
|
|
73
|
-
* verify cross-instance credentials out of the box. Pass `false` to disable
|
|
74
|
-
* (a domain that never talks to another instance, or an account without a
|
|
75
|
-
* router), or an object to override the target / binding name / host match.
|
|
76
|
-
*
|
|
77
|
-
* router: false // opt out
|
|
78
|
-
* router: { service: 'my-router' } // override target
|
|
79
|
-
*/
|
|
80
|
-
readonly router?:
|
|
81
|
-
| false
|
|
82
|
-
| {
|
|
83
|
-
/** Router Worker the binding targets. Default `'admin-router'`. */
|
|
84
|
-
readonly service?: string
|
|
85
|
-
/** Service-binding name the worker reads. Default `'ROUTER'`. */
|
|
86
|
-
readonly binding?: string
|
|
87
|
-
/** Host suffix that marks an instance host. Default `'.astrale.ai'`. */
|
|
88
|
-
readonly hostSuffix?: string
|
|
89
|
-
/** Min dot-separated label count for an instance host. Default `4` (`<slug>.<region>.astrale.ai`). */
|
|
90
|
-
readonly minLabels?: number
|
|
91
|
-
}
|
|
92
|
-
}
|
package/src/worker/fetch.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308])
|
|
2
|
-
|
|
3
|
-
export type RequestDispatcher = (request: Request) => Response | Promise<Response>
|
|
4
|
-
|
|
5
|
-
export interface CloudflareRequest {
|
|
6
|
-
readonly request: Request
|
|
7
|
-
readonly rejectRedirect: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/** Construct a Cloudflare-compatible transport request without weakening redirect:error. */
|
|
11
|
-
export function prepareCloudflareRequest(
|
|
12
|
-
input: Parameters<typeof fetch>[0],
|
|
13
|
-
init?: Parameters<typeof fetch>[1],
|
|
14
|
-
): CloudflareRequest {
|
|
15
|
-
const rejectRedirect =
|
|
16
|
-
init?.redirect === 'error' ||
|
|
17
|
-
(init?.redirect === undefined && input instanceof Request && input.redirect === 'error')
|
|
18
|
-
const request = new Request(input, rejectRedirect ? { ...init, redirect: 'manual' } : init)
|
|
19
|
-
return Object.freeze({ request, rejectRedirect })
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Preserve Fetch redirect:error semantics on Cloudflare, whose transport rejects that mode. */
|
|
23
|
-
export async function dispatchCloudflareRequest(
|
|
24
|
-
request: Request,
|
|
25
|
-
rejectRedirect: boolean,
|
|
26
|
-
dispatch: RequestDispatcher,
|
|
27
|
-
): Promise<Response> {
|
|
28
|
-
const response = adaptCloudflareResponse(request, await dispatch(request))
|
|
29
|
-
if (!rejectRedirect) return response
|
|
30
|
-
if (!response.redirected && !REDIRECT_STATUSES.has(response.status)) return response
|
|
31
|
-
|
|
32
|
-
await response.body?.cancel()
|
|
33
|
-
throw new TypeError('Redirects are not allowed for this request.')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Restore the requested URL omitted by Cloudflare service-binding Responses. */
|
|
37
|
-
export function adaptCloudflareResponse(request: Request, response: Response): Response {
|
|
38
|
-
if (response.url !== '') return response
|
|
39
|
-
return new Proxy(response, {
|
|
40
|
-
get(target, property) {
|
|
41
|
-
if (property === 'url') return request.url
|
|
42
|
-
const value = Reflect.get(target, property, target) as unknown
|
|
43
|
-
return typeof value === 'function' ? value.bind(target) : value
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
}
|