@astrale-os/adapter-cloudflare 0.5.0-beta.13 → 0.5.0-beta.131
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 +1515 -0
- package/README.md +46 -2
- package/dist/adapter.d.ts +14 -0
- package/dist/adapter.js +82 -0
- package/dist/build/artifact.d.ts +7 -0
- package/dist/build/artifact.js +165 -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 +12 -3
- package/dist/build/codegen/wrangler.js +26 -18
- 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 +90 -0
- package/dist/build/frontend/files.d.ts +9 -0
- package/dist/build/frontend/files.js +33 -0
- package/dist/build/frontend/readiness.d.ts +10 -0
- package/dist/build/frontend/readiness.js +21 -0
- package/dist/build/frontend/revision.d.ts +5 -0
- package/dist/build/frontend/revision.js +14 -0
- package/dist/build/frontend/vite.d.ts +8 -0
- package/dist/build/frontend/vite.js +32 -0
- package/dist/build/frontend/vite.process.d.ts +7 -0
- package/dist/build/frontend/vite.process.js +65 -0
- package/dist/build/frontend/vite.runner.d.ts +1 -0
- package/dist/build/frontend/vite.runner.js +120 -0
- package/dist/build/index.d.ts +9 -16
- package/dist/build/index.js +8 -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/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 +19 -0
- package/dist/build/worker/codegen/service.js +53 -0
- package/dist/build/worker/execution.prepare.d.ts +19 -0
- package/dist/build/worker/execution.prepare.js +115 -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/cloudflare.d.ts +1 -45
- package/dist/cloudflare.js +1 -202
- package/dist/deploy/deploy.d.ts +17 -0
- package/dist/deploy/deploy.js +221 -0
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/index.js +1 -0
- package/dist/deploy/output.d.ts +2 -0
- package/dist/deploy/output.js +10 -0
- package/dist/deploy/readiness.d.ts +5 -0
- package/dist/deploy/readiness.js +18 -0
- package/dist/identity/binding.d.ts +2 -0
- package/dist/identity/binding.js +2 -0
- package/dist/identity/index.d.ts +3 -0
- package/dist/identity/index.js +3 -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 +127 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.js +10 -9
- package/dist/params.d.ts +40 -36
- 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 +48 -0
- package/dist/worker/entry.js +157 -0
- package/dist/worker/fetch.d.ts +0 -1
- package/dist/worker/fetch.js +0 -1
- package/dist/worker/frontend.d.ts +4 -0
- package/dist/worker/frontend.js +46 -0
- 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 -218
- package/dist/wrangler/bundle.d.ts +10 -0
- package/dist/wrangler/bundle.js +28 -0
- package/dist/wrangler/deploy.d.ts +24 -0
- package/dist/wrangler/deploy.js +44 -0
- package/dist/wrangler/index.d.ts +5 -0
- package/dist/wrangler/index.js +5 -0
- package/dist/wrangler/process.d.ts +15 -0
- package/dist/wrangler/process.js +102 -0
- package/dist/wrangler/rollout.d.ts +27 -0
- package/dist/wrangler/rollout.js +75 -0
- package/dist/wrangler/secrets.d.ts +2 -0
- package/dist/wrangler/secrets.js +24 -0
- package/dist/wrangler/status.d.ts +18 -0
- package/dist/wrangler/status.js +75 -0
- package/dist/wrangler/triggers.d.ts +5 -0
- package/dist/wrangler/triggers.js +12 -0
- package/dist/wrangler/type-generation.d.ts +6 -0
- package/dist/wrangler/type-generation.js +19 -0
- package/dist/wrangler/versions.d.ts +13 -0
- package/dist/wrangler/versions.js +38 -0
- package/package.json +34 -19
- package/template/astrale.config.ts +30 -31
- 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 -27
- package/dist/build/frontend.d.ts.map +0 -1
- package/dist/build/frontend.js +0 -252
- 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 +0 -27
- package/dist/build/parse-output.d.ts.map +0 -1
- package/dist/build/parse-output.js +0 -58
- 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 -138
- 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 +0 -88
- package/dist/build/wrangler-cli.d.ts.map +0 -1
- package/dist/build/wrangler-cli.js +0 -283
- 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 -128
- package/src/build/frontend.ts +0 -298
- package/src/build/index.ts +0 -29
- package/src/build/parse-output.ts +0 -60
- package/src/build/prepare.ts +0 -189
- package/src/build/worker.ts +0 -37
- package/src/build/wrangler-cli.ts +0 -372
- package/src/cloudflare.ts +0 -275
- 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 -332
- package/src/worker/tsconfig.json +0 -10
package/src/cloudflare.ts
DELETED
|
@@ -1,275 +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
|
-
import type { DeployFetch } from '@astrale-os/sdk/deployment'
|
|
14
|
-
|
|
15
|
-
import { defineAdapter } from '@astrale-os/sdk'
|
|
16
|
-
import { deployCheck } from '@astrale-os/sdk/deployment'
|
|
17
|
-
import { resolve } from 'node:path'
|
|
18
|
-
|
|
19
|
-
import type { CloudflareParams } from './params.js'
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
bulkPutSecrets,
|
|
23
|
-
buildCloudflareWorker,
|
|
24
|
-
buildFrontend,
|
|
25
|
-
logTo,
|
|
26
|
-
prepare,
|
|
27
|
-
runWranglerDeploy,
|
|
28
|
-
runWranglerDev,
|
|
29
|
-
runWranglerTypes,
|
|
30
|
-
startFrontendDev,
|
|
31
|
-
} from './build/index.js'
|
|
32
|
-
|
|
33
|
-
export function cloudflare(
|
|
34
|
-
envs: Record<string, CloudflareParams>,
|
|
35
|
-
): DomainAdapter<CloudflareParams> {
|
|
36
|
-
return cloudflareWithDependencies(envs, {
|
|
37
|
-
bulkPutSecrets,
|
|
38
|
-
buildCloudflareWorker,
|
|
39
|
-
buildFrontend,
|
|
40
|
-
logTo,
|
|
41
|
-
prepare,
|
|
42
|
-
runWranglerDeploy,
|
|
43
|
-
runWranglerDev,
|
|
44
|
-
runWranglerTypes,
|
|
45
|
-
startFrontendDev,
|
|
46
|
-
waitUntilLive,
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface CloudflareAdapterDependencies {
|
|
51
|
-
readonly bulkPutSecrets: typeof bulkPutSecrets
|
|
52
|
-
readonly buildCloudflareWorker: typeof buildCloudflareWorker
|
|
53
|
-
readonly buildFrontend: typeof buildFrontend
|
|
54
|
-
readonly logTo: typeof logTo
|
|
55
|
-
readonly prepare: typeof prepare
|
|
56
|
-
readonly runWranglerDeploy: typeof runWranglerDeploy
|
|
57
|
-
readonly runWranglerDev: typeof runWranglerDev
|
|
58
|
-
readonly runWranglerTypes: typeof runWranglerTypes
|
|
59
|
-
readonly startFrontendDev: typeof startFrontendDev
|
|
60
|
-
readonly waitUntilLive: typeof waitUntilLive
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Exact orchestration seam used by adapter-level deployment qualification. */
|
|
64
|
-
export function cloudflareWithDependencies(
|
|
65
|
-
envs: Record<string, CloudflareParams>,
|
|
66
|
-
dependencies: CloudflareAdapterDependencies,
|
|
67
|
-
): DomainAdapter<CloudflareParams> {
|
|
68
|
-
const frontendDevUrls = new Map<string, string>()
|
|
69
|
-
return defineAdapter<CloudflareParams>({
|
|
70
|
-
name: 'cloudflare',
|
|
71
|
-
envs,
|
|
72
|
-
|
|
73
|
-
async build(params, ctx) {
|
|
74
|
-
await dependencies.buildCloudflareWorker({
|
|
75
|
-
params,
|
|
76
|
-
context: ctx,
|
|
77
|
-
onLog: dependencies.logTo(),
|
|
78
|
-
})
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
async watch(params, ctx) {
|
|
82
|
-
const onLog = dependencies.logTo()
|
|
83
|
-
const projectKey = resolve(ctx.projectDir)
|
|
84
|
-
let frontendDev: Awaited<ReturnType<typeof startFrontendDev>>
|
|
85
|
-
let handle: Awaited<ReturnType<typeof runWranglerDev>> | undefined
|
|
86
|
-
try {
|
|
87
|
-
frontendDev = await dependencies.startFrontendDev({
|
|
88
|
-
definition: ctx.definition,
|
|
89
|
-
projectDir: ctx.projectDir,
|
|
90
|
-
onLog,
|
|
91
|
-
})
|
|
92
|
-
if (frontendDev !== undefined) frontendDevUrls.set(projectKey, frontendDev.url)
|
|
93
|
-
const { configPath, port } = await dependencies.prepare(
|
|
94
|
-
params,
|
|
95
|
-
ctx,
|
|
96
|
-
'dev',
|
|
97
|
-
undefined,
|
|
98
|
-
frontendDev?.url,
|
|
99
|
-
)
|
|
100
|
-
handle = await dependencies.runWranglerDev({
|
|
101
|
-
projectDir: ctx.projectDir,
|
|
102
|
-
configPath,
|
|
103
|
-
port,
|
|
104
|
-
remote: Boolean(params.remote),
|
|
105
|
-
autoPickPort: params.port === undefined,
|
|
106
|
-
...(params.host ? { ip: '0.0.0.0' } : {}),
|
|
107
|
-
onReload: ctx.onReload,
|
|
108
|
-
onLog,
|
|
109
|
-
})
|
|
110
|
-
} catch (error) {
|
|
111
|
-
frontendDevUrls.delete(projectKey)
|
|
112
|
-
try {
|
|
113
|
-
await frontendDev?.stop()
|
|
114
|
-
} catch (cleanupError) {
|
|
115
|
-
throw new AggregateError(
|
|
116
|
-
[error, cleanupError],
|
|
117
|
-
'cloudflare development startup failed and Vite cleanup also failed',
|
|
118
|
-
)
|
|
119
|
-
}
|
|
120
|
-
throw error
|
|
121
|
-
}
|
|
122
|
-
if (handle === undefined) throw new Error('cloudflare local Worker failed to start')
|
|
123
|
-
// With --host the actionable URL is the PUBLIC one (the tunnel/proxy
|
|
124
|
-
// front), not the local bind — print and spec-stamp that.
|
|
125
|
-
return {
|
|
126
|
-
url: params.host ?? handle.url,
|
|
127
|
-
localUrl: handle.url,
|
|
128
|
-
async stop() {
|
|
129
|
-
const errors: unknown[] = []
|
|
130
|
-
frontendDevUrls.delete(projectKey)
|
|
131
|
-
try {
|
|
132
|
-
await frontendDev?.stop()
|
|
133
|
-
} catch (error) {
|
|
134
|
-
errors.push(error)
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
await handle.stop()
|
|
138
|
-
} catch (error) {
|
|
139
|
-
errors.push(error)
|
|
140
|
-
}
|
|
141
|
-
if (errors.length === 1) throw errors[0]
|
|
142
|
-
if (errors.length > 1) {
|
|
143
|
-
throw new AggregateError(errors, 'cloudflare development cleanup failed')
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
|
|
149
|
-
// Config hot-regen rewrites generated files only. Wrangler reloads its config and entry;
|
|
150
|
-
// the author-owned Vite process keeps its own source/config watch lifecycle.
|
|
151
|
-
async regenerate(params, ctx) {
|
|
152
|
-
const { configPath } = await dependencies.prepare(
|
|
153
|
-
params,
|
|
154
|
-
ctx,
|
|
155
|
-
'dev',
|
|
156
|
-
undefined,
|
|
157
|
-
frontendDevUrls.get(resolve(ctx.projectDir)),
|
|
158
|
-
)
|
|
159
|
-
await dependencies.runWranglerTypes({
|
|
160
|
-
projectDir: ctx.projectDir,
|
|
161
|
-
configPath,
|
|
162
|
-
onLog: dependencies.logTo(),
|
|
163
|
-
})
|
|
164
|
-
},
|
|
165
|
-
|
|
166
|
-
async deploy(params, ctx) {
|
|
167
|
-
const frontend = await dependencies.buildFrontend({
|
|
168
|
-
definition: ctx.definition,
|
|
169
|
-
projectDir: ctx.projectDir,
|
|
170
|
-
onLog: dependencies.logTo(),
|
|
171
|
-
})
|
|
172
|
-
const {
|
|
173
|
-
configPath,
|
|
174
|
-
fallbackConfigPath,
|
|
175
|
-
workerName: name,
|
|
176
|
-
} = await dependencies.prepare(params, ctx, 'deploy', frontend)
|
|
177
|
-
const { url, deploymentVersion } = await dependencies.runWranglerDeploy({
|
|
178
|
-
projectDir: ctx.projectDir,
|
|
179
|
-
configPath,
|
|
180
|
-
workerName: name,
|
|
181
|
-
...(fallbackConfigPath ? { fallbackConfigPath } : {}),
|
|
182
|
-
...(params.route ? { route: params.route } : {}),
|
|
183
|
-
onLog: dependencies.logTo(),
|
|
184
|
-
})
|
|
185
|
-
if (Object.keys(ctx.secrets).length > 0) {
|
|
186
|
-
await dependencies.bulkPutSecrets({
|
|
187
|
-
projectDir: ctx.projectDir,
|
|
188
|
-
configPath,
|
|
189
|
-
secrets: ctx.secrets,
|
|
190
|
-
onLog: dependencies.logTo(),
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
// A first deploy on a fresh `*.workers.dev` host can take ~30-60s to
|
|
194
|
-
// propagate; an `astrale domain install <url>` issued right away would
|
|
195
|
-
// 404 (Cloudflare 1042). Block until the URL actually serves so the
|
|
196
|
-
// install line we print is immediately actionable.
|
|
197
|
-
await dependencies.waitUntilLive(url, dependencies.logTo(), {
|
|
198
|
-
expectedOrigin: ctx.definition.schema.origin,
|
|
199
|
-
expectedRevision: ctx.definition.domain.$.revision,
|
|
200
|
-
...(deploymentVersion === undefined
|
|
201
|
-
? {}
|
|
202
|
-
: { expectedDeploymentVersion: deploymentVersion }),
|
|
203
|
-
})
|
|
204
|
-
return { url }
|
|
205
|
-
},
|
|
206
|
-
|
|
207
|
-
secretsFile(params) {
|
|
208
|
-
return params.secrets
|
|
209
|
-
},
|
|
210
|
-
})
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Poll until the deployed Worker exposes one complete canonical deployment chain.
|
|
215
|
-
*/
|
|
216
|
-
export async function waitUntilLive(
|
|
217
|
-
url: string,
|
|
218
|
-
onLog: (line: string) => void,
|
|
219
|
-
expectations: {
|
|
220
|
-
readonly expectedOrigin: Parameters<typeof deployCheck>[0]['expectedOrigin']
|
|
221
|
-
readonly expectedRevision: Parameters<typeof deployCheck>[0]['expectedRevision']
|
|
222
|
-
readonly expectedDeploymentVersion?: string
|
|
223
|
-
readonly fetch?: DeployFetch
|
|
224
|
-
readonly timeoutMs?: number
|
|
225
|
-
readonly fetchTimeoutMs?: number
|
|
226
|
-
readonly retryMs?: number
|
|
227
|
-
readonly sleep?: (ms: number) => Promise<void>
|
|
228
|
-
},
|
|
229
|
-
): Promise<void> {
|
|
230
|
-
const timeoutMs = expectations.timeoutMs ?? 90_000
|
|
231
|
-
const fetchTimeoutMs = expectations.fetchTimeoutMs ?? 5_000
|
|
232
|
-
const retryMs = expectations.retryMs ?? 3_000
|
|
233
|
-
const sleep =
|
|
234
|
-
expectations.sleep ?? ((ms: number) => new Promise((resolve) => setTimeout(resolve, ms)))
|
|
235
|
-
const deadline = Date.now() + timeoutMs
|
|
236
|
-
let waited = false
|
|
237
|
-
let lastReason = 'not checked'
|
|
238
|
-
for (;;) {
|
|
239
|
-
try {
|
|
240
|
-
const deployed = await deployCheck({
|
|
241
|
-
url,
|
|
242
|
-
expectedOrigin: expectations.expectedOrigin,
|
|
243
|
-
expectedRevision: expectations.expectedRevision,
|
|
244
|
-
signal: AbortSignal.timeout(fetchTimeoutMs),
|
|
245
|
-
...(expectations.fetch === undefined ? {} : { fetch: expectations.fetch }),
|
|
246
|
-
log: () => undefined,
|
|
247
|
-
})
|
|
248
|
-
const actualDeploymentVersion = new URL(deployed.schema.bundle.href).searchParams.get(
|
|
249
|
-
'deployment',
|
|
250
|
-
)
|
|
251
|
-
if (
|
|
252
|
-
expectations.expectedDeploymentVersion === undefined ||
|
|
253
|
-
actualDeploymentVersion === expectations.expectedDeploymentVersion
|
|
254
|
-
) {
|
|
255
|
-
return
|
|
256
|
-
}
|
|
257
|
-
lastReason =
|
|
258
|
-
`bundle deployment=${JSON.stringify(actualDeploymentVersion)} ` +
|
|
259
|
-
`expected=${JSON.stringify(expectations.expectedDeploymentVersion)}`
|
|
260
|
-
} catch (error) {
|
|
261
|
-
lastReason = error instanceof Error ? error.message : String(error)
|
|
262
|
-
}
|
|
263
|
-
if (Date.now() >= deadline) {
|
|
264
|
-
throw new Error(
|
|
265
|
-
`deployed Worker did not expose a valid Publication chain within ` +
|
|
266
|
-
`${Math.round(timeoutMs / 1000)}s; last check: ${lastReason}`,
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
if (!waited) {
|
|
270
|
-
waited = true
|
|
271
|
-
onLog('waiting for the URL to go live (first deploys can take ~30-60s)…')
|
|
272
|
-
}
|
|
273
|
-
await sleep(Math.min(retryMs, Math.max(0, deadline - Date.now())))
|
|
274
|
-
}
|
|
275
|
-
}
|
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
|
-
}
|