From e74f478f44d2eead84882450d1b03a5da1d7ac65 Mon Sep 17 00:00:00 2001 From: kedom Date: Wed, 10 Jun 2026 15:19:24 +0200 Subject: [PATCH] fix(cloudflare): correct browser-rendering getCrawl response schema The upstream Cloudflare TypeScript SDK types for the getCrawl operation do not match what the API actually returns: - `records[].metadata` is typed as required, but Cloudflare omits it for records that have not completed (queued/skipped/cancelled/...), causing decode failures while polling an in-progress crawl. - `cursor` is typed as a string, but the API returns a number (the next record index). It is absent on the last page. Adds a patch file for the operation and regenerates the service. Co-Authored-By: Claude Fable 5 --- .../patches/browser-rendering/getCrawl.json | 8 +++++++ .../cloudflare/browser-rendering.openapi.yml | 5 +++-- .../src/services/browser-rendering.ts | 21 ++++++++++++------- 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 packages/cloudflare/patches/browser-rendering/getCrawl.json diff --git a/packages/cloudflare/patches/browser-rendering/getCrawl.json b/packages/cloudflare/patches/browser-rendering/getCrawl.json new file mode 100644 index 000000000..f8ee0f111 --- /dev/null +++ b/packages/cloudflare/patches/browser-rendering/getCrawl.json @@ -0,0 +1,8 @@ +{ + "response": { + "properties": { + "records[].metadata": { "optional": true }, + "cursor": { "type": "number", "nullable": true } + } + } +} diff --git a/packages/cloudflare/specs/cloudflare/browser-rendering.openapi.yml b/packages/cloudflare/specs/cloudflare/browser-rendering.openapi.yml index 7f0aaebc6..2829b66b4 100644 --- a/packages/cloudflare/specs/cloudflare/browser-rendering.openapi.yml +++ b/packages/cloudflare/specs/cloudflare/browser-rendering.openapi.yml @@ -410,7 +410,6 @@ paths: type: string description: Markdown of the content of the crawled URL. required: - - metadata - status - url description: List of crawl job records. @@ -427,7 +426,9 @@ paths: type: number description: Total current number of URLs in the crawl job. cursor: - type: string + oneOf: + - type: number + nullable: true description: Cursor for pagination. required: - id diff --git a/packages/cloudflare/src/services/browser-rendering.ts b/packages/cloudflare/src/services/browser-rendering.ts index 4bf1e384a..767f894b3 100644 --- a/packages/cloudflare/src/services/browser-rendering.ts +++ b/packages/cloudflare/src/services/browser-rendering.ts @@ -412,7 +412,7 @@ export interface GetCrawlResponse { finished: number; /** List of crawl job records. */ records: { - metadata: { status: number; url: string; title?: string | null }; + metadata?: { status: number; url: string; title?: string | null } | null; status: | "queued" | "errored" @@ -433,7 +433,7 @@ export interface GetCrawlResponse { /** Total current number of URLs in the crawl job. */ total: number; /** Cursor for pagination. */ - cursor?: string | null; + cursor?: number | null; } export const GetCrawlResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({ @@ -442,11 +442,16 @@ export const GetCrawlResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({ finished: Schema.Number, records: Schema.Array( Schema.Struct({ - metadata: Schema.Struct({ - status: Schema.Number, - url: Schema.String, - title: Schema.optional(Schema.Union([Schema.String, Schema.Null])), - }), + metadata: Schema.optional( + Schema.Union([ + Schema.Struct({ + status: Schema.Number, + url: Schema.String, + title: Schema.optional(Schema.Union([Schema.String, Schema.Null])), + }), + Schema.Null, + ]), + ), status: Schema.Union([ Schema.Literals([ "queued", @@ -472,7 +477,7 @@ export const GetCrawlResponse = /*@__PURE__*/ /*#__PURE__*/ Schema.Struct({ skipped: Schema.Number, status: Schema.String, total: Schema.Number, - cursor: Schema.optional(Schema.Union([Schema.String, Schema.Null])), + cursor: Schema.optional(Schema.Union([Schema.Number, Schema.Null])), }).pipe(T.ResponsePath("result")) as unknown as Schema.Schema; export type GetCrawlError = DefaultErrors;