fix(cloudflare/rulesets): support phase entrypoint paths#257
Conversation
|
Verification update:
This fixes the generated Rulesets phase-entrypoint path used by alchemy-run/alchemy-effect#240. Without this fix, the Alchemy live test calls |
| 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)), | ||
| ), | ||
| }; | ||
| } |
There was a problem hiding this comment.
@Mkassabov is this something we can handle with traits? Looks to be getting a bit unwieldy?
There was a problem hiding this comment.
I think so? I'd rather not ship logic like this in the api layer if we can avoid it.
There was a problem hiding this comment.
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.
6bd0c94 to
b95911d
Compare
|
@Mkassabov yes i believe it does, will close this PR and adapt the alchemy-effect one based on 282 |
|
@Mkassabov can test once distilled is released again |
Fixes generated Cloudflare Rulesets phase-entrypoint requests so the SDK can call endpoints such as
/zones/{zone_id}/rulesets/phases/{rulesetPhase}/entrypoint.rulesetPhaseduring generation{accountOrZone}/{accountOrZoneId}paths from exactly one ofaccountIdorzoneIdVerification run:
bun --filter '@distilled.cloud/cloudflare' test --run test/client-api.test.tsbun --filter '@distilled.cloud/cloudflare' typecheckbun --filter '@distilled.cloud/cloudflare' checkgit diff --check