patchGlobalRequestObject
@atiproto/edge-oauth-client
Patches globalThis.Request to strip the cache property from request init objects before construction. Required in Cloudflare Workers, where passing cache to new Request() throws a TypeError.
Signature
typescript
function patchGlobalRequestObject(): void
Call once at the top of your Worker entry point, before constructing any EdgeOAuthClient instance. Subsequent calls are no-ops.
Example
typescript
// worker.ts (entry point)import { patchGlobalRequestObject, EdgeOAuthClient } from "@atiproto/edge-oauth-client";patchGlobalRequestObject();const client = new EdgeOAuthClient({ ... });export default {async fetch(request: Request, env: Env) {// ...},};
Why This Is Needed
The underlying @atproto/oauth-client package constructs Request objects with a cache property set to "no-store". Cloudflare Workers does not support this property and throws synchronously when it is present. The patch intercepts new Request() calls and removes the offending key before delegating to the original constructor.