[wrangler] Add hyperdrive planetscale integrations commands - #15065
[wrangler] Add hyperdrive planetscale integrations commands#15065mtlemilio wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: db698fc The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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 |
| export async function createDatabaseSignature( | ||
| config: Config, | ||
| integration: string | ||
| ): Promise<CreateDatabaseSignature> { | ||
| const accountId = await requireAuth(config); | ||
| return await fetchResult( | ||
| config, | ||
| `/accounts/${accountId}/hyperdrive/integrationsOperations/${integration}/createDatabaseSignature`, | ||
| { | ||
| method: "POST", | ||
| } | ||
| ); | ||
| } |
There was a problem hiding this comment.
🟡 New Hyperdrive API call bypasses the required Cloudflare SDK
The new signing request talks to the Cloudflare API by hand-building a URL and calling the raw REST endpoint (fetchResult at packages/wrangler/src/hyperdrive/client.ts:195-201) instead of the official Cloudflare TypeScript SDK that the repository requires for all API access, so the call is untyped and can rely on undocumented endpoints.
Impact: Contributors reading the code get an unsupported pattern, and API changes will not be caught by types.
Repository rule and current code path
The root AGENTS.md anti-patterns list states: "Direct Cloudflare REST API calls → use the Cloudflare TypeScript SDK", and packages/wrangler/CONTRIBUTING.md ("Integration with Cloudflare REST API") repeats that the SDK, set up for every command handler, should be preferred. The new createDatabaseSignature() builds /accounts/${accountId}/hyperdrive/integrationsOperations/${integration}/createDatabaseSignature and posts via fetchResult. Note the rest of packages/wrangler/src/hyperdrive/client.ts predates the rule and uses the same pattern, so this may be an accepted deviation if the endpoint is not exposed by the SDK.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
The underlying API endpoint hasn't been released yet. But when it is, we will update this code to use the generated Typescript SDK.
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
57644b4 to
9ff71ef
Compare
9ff71ef to
9a061c5
Compare
9a061c5 to
1580278
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
1580278 to
380a64f
Compare
380a64f to
db698fc
Compare
| async handler(_args, { config }) { | ||
| const signature = await createDatabaseSignature(config, "planetScale"); | ||
| logger.log(JSON.stringify(signature, null, 2)); | ||
| }, |
There was a problem hiding this comment.
🟡 Standalone authorization output can include extra fields that the PlanetScale tool rejects
The whole server response is printed verbatim (JSON.stringify(signature, null, 2) at packages/wrangler/src/hyperdrive/planetscale.ts:115) instead of only the three fields the PlanetScale tool accepts, so the documented pipe workflow breaks the moment the server returns any additional field.
Impact: Users following the documented piping instructions can hit a hard failure and be unable to create a database.
Inconsistency with the create path's defensive serialization
The create path deliberately rebuilds the payload field-by-field (packages/wrangler/src/hyperdrive/planetscale.ts:135-142) with the comment that "the PlanetScale CLI rejects unknown fields, so an added response field would otherwise break database creation". The signature command, whose documented purpose is exactly wrangler hyperdrive planetscale signature | pscale database create <name> --cloudflare-billing @- (see .changeset/hyperdrive-planetscale.md:26-29), dumps whatever createDatabaseSignature (packages/wrangler/src/hyperdrive/client.ts:190-201) returned, including any future/extra fields. The two paths should serialize identically.
| async handler(_args, { config }) { | |
| const signature = await createDatabaseSignature(config, "planetScale"); | |
| logger.log(JSON.stringify(signature, null, 2)); | |
| }, | |
| async handler(_args, { config }) { | |
| const signature = await createDatabaseSignature(config, "planetScale"); | |
| logger.log( | |
| JSON.stringify( | |
| { | |
| account_id: signature.account_id, | |
| timestamp: signature.timestamp, | |
| signature: signature.signature, | |
| }, | |
| null, | |
| 2 | |
| ) | |
| ); | |
| }, |
Was this helpful? React with 👍 or 👎 to provide feedback.
Fixes #SQC-896.
In June we released an evolution to our partnership with PlanetScale: https://developers.cloudflare.com/changelog/post/2026-06-18-planetscale-databases-cloudflare-billing/
From the UI customers can create PlanetScale databases that are billed to their Cloudflare account. This change in Wrangler allows us to integrate the Wrangler CLI with the PlanetScale CLI by passing the relevant credentials. This supports an agentic/CLI workflow, in addition to the UI based flow that is currently available.
A picture of a cute animal (not mandatory, but encouraged)