[wrangler] Extract remote bindings into @cloudflare/remote-bindings#14443
[wrangler] Extract remote bindings into @cloudflare/remote-bindings#14443penalosa wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 2e5ac72 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
✅ All changesets look good |
There was a problem hiding this comment.
I'm Bonk, and I've done a quick review of your PR.
Extracts remote bindings into a standalone @cloudflare/remote-bindings package (wrangler-free, env-driven auth) and rewires wrangler + the Vite plugin to use it.
One correctness issue worth fixing before merge, plus a couple of smaller robustness notes:
-
(high) Compliance-region API base URL is wrong.
getApiBaseUrlinpackages/remote-bindings/src/api/fetch.tsspecial-cases"eu"(whichcompliance_regionnever is — its type is"public" | "fedramp_high" | undefined) with aeu-clientURL that exists nowhere else in the repo, and it does not handle"fedramp_high". So a worker in the FedRAMP compliance region would have its remote-binding edge-preview calls routed to the publicapi.cloudflare.comendpoint instead ofapi.fed.cloudflare.com. wrangler's canonicalgetCloudflareApiBaseUrlmapsfedramp_high→.fedsubdomain. -
(low)
fetchResultassumesjson.errorsis always an array. If the API returnssuccess: falsewithout anerrorsarray,json.errors.map(...)throws aTypeError, masking the real status. Guard with(json.errors ?? []). -
(low)
getApiBaseUrlignoresCLOUDFLARE_API_BASE_URLfor non-public regions. Once the region branch is taken, the env override is skipped. wrangler's resolver checks the env override first regardless of region. Worth preserving that precedence.
| /** | ||
| * Get the Cloudflare API base URL, respecting compliance region settings. | ||
| */ | ||
| function getApiBaseUrl(complianceRegion?: string): string { |
There was a problem hiding this comment.
compliance_region is typed "public" | "fedramp_high" | undefined (see packages/workers-utils/src/config/environment.ts:680), so the "eu" branch is dead code and the eu-client host appears nowhere else in the repo. More importantly, "fedramp_high" is unhandled, so FedRAMP-region remote bindings hit the public API. Mirror wrangler's getCloudflareApiBaseUrl (fedramp_high → .fed subdomain) and keep the env override first:
| function getApiBaseUrl(complianceRegion?: string): string { | |
| function getApiBaseUrl(complianceRegion?: string): string { | |
| // eslint-disable-next-line turbo/no-undeclared-env-vars -- Matches wrangler's API base URL override | |
| const override = process.env.CLOUDFLARE_API_BASE_URL; | |
| if (override) { | |
| return override; | |
| } | |
| const sub = complianceRegion === "fedramp_high" ? ".fed" : ""; | |
| return `https://api${sub}.cloudflare.com/client/v4`; | |
| } |
| } | ||
|
|
||
| if (!json.success) { | ||
| const errors = json.errors.map((e) => `${e.code}: ${e.message}`).join("\n"); |
There was a problem hiding this comment.
If the API returns success: false without an errors array, this throws a TypeError and hides the real status. Guard against a missing array:
| const errors = json.errors.map((e) => `${e.code}: ${e.message}`).join("\n"); | |
| const errors = (json.errors ?? []) | |
| .map((e) => `${e.code}: ${e.message}`) | |
| .join("\n"); |
|
Review submitted successfully to PR #14443. Summary of findings posted:
|
e6dd08b to
83ceccf
Compare
0540500 to
c8616c1
Compare
Add the standalone @cloudflare/remote-bindings package: a lightweight, wrangler-free implementation of remote binding proxy sessions (direct edge-preview API calls + a minimal Node HTTP/WS proxy and a pre-bundled ProxyServerWorker), replacing the previous DevEnv-based approach. Auth is customisable and environment-driven: createEnvAuthResolver reads CLOUDFLARE_* credentials or refreshes the stored OAuth token discovered via CLOUDFLARE_CONFIG_DIR / CLOUDFLARE_AUTH_CONFIG_FILE (TOML/JSON/JSONC), using CLOUDFLARE_OAUTH_CLIENT_ID and honouring CLOUDFLARE_ALLOW_GLOBAL_API_KEY. It is refresh-only and never starts an interactive login, failing with an actionable CLOUDFLARE_LOGIN_COMMAND hint instead. wrangler now delegates startRemoteProxySession to the package while preserving its own auth resolution (interactive requireAuth login + account selection) and error reporting.
Establish remote binding proxy sessions via @cloudflare/remote-bindings directly instead of through wrangler, removing that coupling and enabling environment-variable-driven auth discovery and mid-run OAuth token refresh.
83ceccf to
2e5ac72
Compare
Extracts a standalone
@cloudflare/remote-bindingspackage so remote bindings can be established without depending onwrangler(notably from@cloudflare/vite-plugin), and switches bothwranglerand the Vite plugin onto it.PR 2 of a 2-PR stack — builds on the auth/storage foundation in #14444 (this PR is based on that branch; review/merge #14444 first).
This unblocks decoupling the Vite plugin from
wrangler— remote bindings were the main blocker — and enables acf dev → vite dev → @cloudflare/remote-bindingsdelegation chain.What changed
@cloudflare/remote-bindings(new): lightweight, wrangler-free remote binding proxy sessions — direct edge-preview API calls + a minimal Node HTTP/WS proxy + a pre-bundledProxyServerWorker— replacing the previousstartWorker()/DevEnv approach. ExposesstartRemoteProxySession,maybeStartOrUpdateRemoteProxySession,pickRemoteBindings, andcreateEnvAuthResolver. ReusescreateWorkerUploadFormfrom@cloudflare/deploy-helpers.wrangler:start-remote-proxy-sessionnow delegates to the package, preserving wrangler's own auth resolution (interactiverequireAuthlogin + account selection) and error reporting.auth-config-file/auth-variablesre-export the shared helpers from the foundation PR (no behaviour change).@cloudflare/vite-plugin: establishes remote binding sessions via@cloudflare/remote-bindingsdirectly instead of throughwrangler.Auth model
The package's default resolver is fully environment-driven (using the foundation PR's storage + env vars), so a top-level CLI can delegate remote bindings and have the OAuth token discovered and refreshed mid-run:
CLOUDFLARE_CONFIG_DIRCLOUDFLARE_AUTH_CONFIG_FILECLOUDFLARE_OAUTH_CLIENT_IDWRANGLER_CLIENT_ID)CLOUDFLARE_ACCOUNT_IDCLOUDFLARE_ALLOW_GLOBAL_API_KEYtrue)CLOUDFLARE_LOGIN_COMMANDBehaviour notes:
wrangler devis unchanged: it injects arequireAuth-backed auth hook, so requesting remote bindings while unauthorised starts wrangler's interactive login (and account selection) as before — or fails with a clear error in CI.CLOUDFLARE_LOGIN_COMMANDhint.wrangler dev's remote-bindings behaviour and configuration are unchanged.