Skip to content

fix(cloudflare/rulesets): support phase entrypoint paths#257

Closed
agcty wants to merge 2 commits into
alchemy-run:mainfrom
agcty:codex/cloudflare-rulesets-phase-path
Closed

fix(cloudflare/rulesets): support phase entrypoint paths#257
agcty wants to merge 2 commits into
alchemy-run:mainfrom
agcty:codex/cloudflare-rulesets-phase-path

Conversation

@agcty
Copy link
Copy Markdown
Contributor

@agcty agcty commented May 5, 2026

Fixes generated Cloudflare Rulesets phase-entrypoint requests so the SDK can call endpoints such as /zones/{zone_id}/rulesets/phases/{rulesetPhase}/entrypoint.

  • synthesizes missing URL path params such as rulesetPhase during generation
  • keeps optional generated path params optional in request schemas
  • maps Cloudflare {accountOrZone}/{accountOrZoneId} paths from exactly one of accountId or zoneId
  • adds request-building coverage for zone-scoped Rulesets entrypoint updates

Verification run:

  • bun --filter '@distilled.cloud/cloudflare' test --run test/client-api.test.ts
  • bun --filter '@distilled.cloud/cloudflare' typecheck
  • bun --filter '@distilled.cloud/cloudflare' check
  • git diff --check

@agcty
Copy link
Copy Markdown
Contributor Author

agcty commented May 5, 2026

Verification update:

  • Focused test passed: bun --filter @distilled.cloud/cloudflare test --run test/client-api.test.ts.
  • Typecheck passed: bun --filter @distilled.cloud/cloudflare typecheck.
  • Check passed: bun --filter @distilled.cloud/cloudflare check.

This fixes the generated Rulesets phase-entrypoint path used by alchemy-run/alchemy-effect#240. Without this fix, the Alchemy live test calls /{accountOrZone}/{accountOrZoneId}/rulesets/phases/... through the generated client and Cloudflare returns No route for that URI.

@agcty agcty marked this pull request as ready for review May 5, 2026 13:56
Comment thread packages/cloudflare/src/client/api.ts Outdated
Comment on lines +415 to +440
if (
pathTemplate.includes("/{accountOrZone}/{accountOrZoneId}/") &&
next.path.includes("{accountOrZone}") &&
next.path.includes("{accountOrZoneId}")
) {
const accountId = input?.accountId;
const zoneId = input?.zoneId;
const hasAccountId = accountId !== undefined && accountId !== null;
const hasZoneId = zoneId !== undefined && zoneId !== null;

if (hasAccountId === hasZoneId) {
throw new Error(
"Cloudflare account-or-zone scoped requests require exactly one of accountId or zoneId",
);
}

next = {
...next,
path: next.path
.replace("{accountOrZone}", hasAccountId ? "accounts" : "zones")
.replace(
"{accountOrZoneId}",
encodeURIComponent(String(hasAccountId ? accountId : zoneId)),
),
};
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mkassabov is this something we can handle with traits? Looks to be getting a bit unwieldy?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so? I'd rather not ship logic like this in the api layer if we can avoid it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated this to use a Cloudflare-specific T.AccountOrZoneScope() trait instead of inferring it from the path in the api layer. core now passes the input schema to request transforms, the generator emits the trait for account-or-zone scoped operations, and the focused client-api test covers the rulesets path mapping. checks passed: bun test packages/cloudflare/test/client-api.test.ts, bun --filter @distilled.cloud/core typecheck, bun --filter @distilled.cloud/cloudflare typecheck, bun --filter @distilled.cloud/core lint, bun --filter @distilled.cloud/cloudflare lint.

@agcty agcty force-pushed the codex/cloudflare-rulesets-phase-path branch from 6bd0c94 to b95911d Compare May 6, 2026 07:26
@Mkassabov
Copy link
Copy Markdown
Contributor

@agcty can you take a look at PR #282 does that solve your issues?

@agcty
Copy link
Copy Markdown
Contributor Author

agcty commented May 8, 2026

@Mkassabov yes i believe it does, will close this PR and adapt the alchemy-effect one based on 282

@agcty agcty closed this May 8, 2026
@agcty
Copy link
Copy Markdown
Contributor Author

agcty commented May 8, 2026

@Mkassabov can test once distilled is released again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants