Skip to content

fix(cloudflare/workers-for-platforms): type getDispatchNamespaceScriptSetting errors + loosen placement#361

Merged
sam-goodwin merged 4 commits into
mainfrom
claude/wfp-dispatch-script-setting-typed-errors
Jun 30, 2026
Merged

fix(cloudflare/workers-for-platforms): type getDispatchNamespaceScriptSetting errors + loosen placement#361
sam-goodwin merged 4 commits into
mainfrom
claude/wfp-dispatch-script-setting-typed-errors

Conversation

@sam-goodwin

@sam-goodwin sam-goodwin commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Make the Workers for Platforms script-settings endpoint usable from typed consumers.

getDispatchNamespaceScriptSetting:

  • Type its error union (it previously carried only the generic HTTP catch-alls):
{ "errors": {
  "DispatchNamespaceNotFound": [{ "code": 100119 }],
  "DispatchNamespaceScriptNotFound": [{ "code": 10007 }],
  "Forbidden": [{ "status": 403 }]
} }
  • Fix placement decoding. The vendor SDK models the response placement with the request union — every variant requires mode/region/hostname/host — so the real response ({} when unset, or { mode, status, last_analyzed_at }) matches no variant and fails to decode. The vendor SDK only gets away with it because it never validates the response at runtime.

    We keep the upstream union verbatim and append the one variant it omits for the response — the all-optional placement-status object:

    placement?:
      | { mode: "smart" }
      | { region: string }
      | /* …upstream's targeted / hostname / host variants… */
      | {                                  // appended
          mode?: "smart" | null;
          status?: "SUCCESS" | "UNSUPPORTED_APPLICATION" | "INSUFFICIENT_INVOCATIONS" | (string & {}) | null;
          lastAnalyzedAt?: string | null;  // wire: last_analyzed_at
        }
      | null;

    Uses the existing appendUnion patch op — no parser/model/codegen change. (This is a semantic gap in the vendor spec, not a representation gap on our side; the generator already reproduces upstream's union faithfully — which is exactly why it failed.)

Found while wiring the alchemy Cloudflare Worker resource to deploy into a dispatch namespace: the post-upload settings read needed both the typed not-found tags and a response that actually decodes.

🤖 Generated with Claude Code

…tSetting errors + loosen placement

Add a patch for `getDispatchNamespaceScriptSetting`:

- type the `DispatchNamespaceNotFound` (100119) / `DispatchNamespaceScriptNotFound` (10007) / `Forbidden` (403) errors into its union
- loosen `placement` to `unknown` — the live endpoint 200s with `placement: {}`, which the strict union rejected (matches the account-level `getScriptScriptAndVersionSetting`)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alchemy-version-bot

alchemy-version-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

@distilled.cloud/core

bun add @distilled.cloud/core@https://pkg.distilled.cloud/core/e824e87

@distilled.cloud/aws

bun add @distilled.cloud/aws@https://pkg.distilled.cloud/aws/e824e87

@distilled.cloud/cloudflare

bun add @distilled.cloud/cloudflare@https://pkg.distilled.cloud/cloudflare/e824e87

sam-goodwin and others added 3 commits June 30, 2026 01:59
…ptSetting placement properly

The script-settings response reused the *request* placement union (every
variant requires mode/region/hostname/host), so the real response — `{}` when
unset, or `{ mode, status, last_analyzed_at }` — failed to decode. Replace it
with the actual all-optional placement-status object instead of falling back to
`unknown`.

Also teach the generator's response/request patch DSL to honour `definition` as
a type *replacement* for an existing property (previously it only added missing
properties), which is what this fix — and existing patches like
connectivity/getDirectoryService — rely on.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…stead of replacing it

Keep the upstream placement union verbatim and append the one variant upstream
omits for the *response*: the all-optional placement-status object
(`{ mode?, status?, last_analyzed_at? }`) that the real API returns (or `{}`
when unset). This decodes every real response without dropping the targeted /
region / hostname / host variants, and uses the existing `appendUnion` patch op
— so the earlier generator change (definition-as-replace) is reverted; no
codegen change is needed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The placement fix needs no codegen change; restore generate.ts to pristine.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sam-goodwin sam-goodwin merged commit 645c714 into main Jun 30, 2026
26 of 27 checks passed
@sam-goodwin sam-goodwin deleted the claude/wfp-dispatch-script-setting-typed-errors branch June 30, 2026 18:06
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.

1 participant