fix(js-sdk/extract): use same zod fallback logic (#1711)

This commit is contained in:
Gergő Móricz 2025-06-25 19:59:58 +02:00 committed by GitHub
parent 3d04c2087e
commit f4714f4849
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 14 deletions

View File

@ -4,9 +4,6 @@ on:
pull_request: pull_request:
branches: branches:
- main - main
paths:
- apps/api/**
- apps/playwright-service-ts/**
env: env:
PORT: 3002 PORT: 3002

View File

@ -4,10 +4,6 @@ on:
pull_request: pull_request:
branches: branches:
- main - main
paths:
- apps/api/**
# schedule:
# - cron: '0 */4 * * *'
env: env:
BULL_AUTH_KEY: ${{ secrets.BULL_AUTH_KEY }} BULL_AUTH_KEY: ${{ secrets.BULL_AUTH_KEY }}

View File

@ -1,6 +1,6 @@
{ {
"name": "@mendable/firecrawl-js", "name": "@mendable/firecrawl-js",
"version": "1.26.0", "version": "1.27.0",
"description": "JavaScript SDK for Firecrawl API", "description": "JavaScript SDK for Firecrawl API",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@ -1244,10 +1244,12 @@ export default class FirecrawlApp {
try { try {
if (!params?.schema) { if (!params?.schema) {
jsonSchema = undefined; jsonSchema = undefined;
} else if (typeof params.schema === "object" && params.schema !== null && Object.getPrototypeOf(params.schema)?.constructor?.name?.startsWith("Zod")) {
jsonSchema = zodToJsonSchema(params.schema as zt.ZodType);
} else { } else {
jsonSchema = params.schema; try {
jsonSchema = zodToJsonSchema(params.schema as zt.ZodType);
} catch (_) {
jsonSchema = params.schema;
}
} }
} catch (error: any) { } catch (error: any) {
throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400); throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400);
@ -1312,10 +1314,14 @@ export default class FirecrawlApp {
let jsonSchema: any; let jsonSchema: any;
try { try {
if (params?.schema instanceof zt.ZodType) { if (!params?.schema) {
jsonSchema = zodToJsonSchema(params.schema); jsonSchema = undefined;
} else { } else {
jsonSchema = params?.schema; try {
jsonSchema = zodToJsonSchema(params.schema as zt.ZodType);
} catch (_) {
jsonSchema = params.schema;
}
} }
} catch (error: any) { } catch (error: any) {
throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400); throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400);