@mendable/firecrawl 4.11.0 → 4.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-X3D7QXG6.js → chunk-SHZTLDEM.js} +1 -1
- package/dist/index.cjs +15 -1
- package/dist/index.js +16 -2
- package/dist/{package-A5RBY34U.js → package-LM7L2L66.js} +1 -1
- package/package.json +1 -1
- package/src/__tests__/unit/v2/validation.test.ts +18 -0
- package/src/v2/utils/validation.ts +26 -0
|
@@ -8,7 +8,7 @@ var require_package = __commonJS({
|
|
|
8
8
|
"package.json"(exports, module) {
|
|
9
9
|
module.exports = {
|
|
10
10
|
name: "@mendable/firecrawl-js",
|
|
11
|
-
version: "4.11.
|
|
11
|
+
version: "4.11.1",
|
|
12
12
|
description: "JavaScript SDK for Firecrawl API",
|
|
13
13
|
main: "dist/index.js",
|
|
14
14
|
types: "dist/index.d.ts",
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var require_package = __commonJS({
|
|
|
35
35
|
"package.json"(exports2, module2) {
|
|
36
36
|
module2.exports = {
|
|
37
37
|
name: "@mendable/firecrawl-js",
|
|
38
|
-
version: "4.11.
|
|
38
|
+
version: "4.11.1",
|
|
39
39
|
description: "JavaScript SDK for Firecrawl API",
|
|
40
40
|
main: "dist/index.js",
|
|
41
41
|
types: "dist/index.d.ts",
|
|
@@ -251,6 +251,12 @@ var JobTimeoutError = class extends SdkError {
|
|
|
251
251
|
|
|
252
252
|
// src/v2/utils/validation.ts
|
|
253
253
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
254
|
+
function looksLikeZodShape(obj) {
|
|
255
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
|
|
256
|
+
const values = Object.values(obj);
|
|
257
|
+
if (values.length === 0) return false;
|
|
258
|
+
return values.some((v) => v && typeof v === "object" && v._def && typeof v.safeParse === "function");
|
|
259
|
+
}
|
|
254
260
|
function ensureValidFormats(formats) {
|
|
255
261
|
if (!formats) return;
|
|
256
262
|
for (const fmt of formats) {
|
|
@@ -272,6 +278,10 @@ function ensureValidFormats(formats) {
|
|
|
272
278
|
j.schema = (0, import_zod_to_json_schema.zodToJsonSchema)(maybeSchema);
|
|
273
279
|
} catch {
|
|
274
280
|
}
|
|
281
|
+
} else if (looksLikeZodShape(maybeSchema)) {
|
|
282
|
+
throw new Error(
|
|
283
|
+
"json format schema appears to be a Zod schema's .shape property. Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. The SDK will automatically convert Zod schemas to JSON Schema format."
|
|
284
|
+
);
|
|
275
285
|
}
|
|
276
286
|
continue;
|
|
277
287
|
}
|
|
@@ -284,6 +294,10 @@ function ensureValidFormats(formats) {
|
|
|
284
294
|
ct.schema = (0, import_zod_to_json_schema.zodToJsonSchema)(maybeSchema);
|
|
285
295
|
} catch {
|
|
286
296
|
}
|
|
297
|
+
} else if (looksLikeZodShape(maybeSchema)) {
|
|
298
|
+
throw new Error(
|
|
299
|
+
"changeTracking format schema appears to be a Zod schema's .shape property. Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. The SDK will automatically convert Zod schemas to JSON Schema format."
|
|
300
|
+
);
|
|
287
301
|
}
|
|
288
302
|
continue;
|
|
289
303
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
require_package
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SHZTLDEM.js";
|
|
4
4
|
|
|
5
5
|
// src/v2/utils/httpClient.ts
|
|
6
6
|
import axios from "axios";
|
|
@@ -132,6 +132,12 @@ var JobTimeoutError = class extends SdkError {
|
|
|
132
132
|
|
|
133
133
|
// src/v2/utils/validation.ts
|
|
134
134
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
135
|
+
function looksLikeZodShape(obj) {
|
|
136
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
|
|
137
|
+
const values = Object.values(obj);
|
|
138
|
+
if (values.length === 0) return false;
|
|
139
|
+
return values.some((v) => v && typeof v === "object" && v._def && typeof v.safeParse === "function");
|
|
140
|
+
}
|
|
135
141
|
function ensureValidFormats(formats) {
|
|
136
142
|
if (!formats) return;
|
|
137
143
|
for (const fmt of formats) {
|
|
@@ -153,6 +159,10 @@ function ensureValidFormats(formats) {
|
|
|
153
159
|
j.schema = zodToJsonSchema(maybeSchema);
|
|
154
160
|
} catch {
|
|
155
161
|
}
|
|
162
|
+
} else if (looksLikeZodShape(maybeSchema)) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
"json format schema appears to be a Zod schema's .shape property. Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. The SDK will automatically convert Zod schemas to JSON Schema format."
|
|
165
|
+
);
|
|
156
166
|
}
|
|
157
167
|
continue;
|
|
158
168
|
}
|
|
@@ -165,6 +175,10 @@ function ensureValidFormats(formats) {
|
|
|
165
175
|
ct.schema = zodToJsonSchema(maybeSchema);
|
|
166
176
|
} catch {
|
|
167
177
|
}
|
|
178
|
+
} else if (looksLikeZodShape(maybeSchema)) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
"changeTracking format schema appears to be a Zod schema's .shape property. Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. The SDK will automatically convert Zod schemas to JSON Schema format."
|
|
181
|
+
);
|
|
168
182
|
}
|
|
169
183
|
continue;
|
|
170
184
|
}
|
|
@@ -1334,7 +1348,7 @@ var FirecrawlApp = class {
|
|
|
1334
1348
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
1335
1349
|
return process.env.npm_package_version;
|
|
1336
1350
|
}
|
|
1337
|
-
const packageJson = await import("./package-
|
|
1351
|
+
const packageJson = await import("./package-LM7L2L66.js");
|
|
1338
1352
|
return packageJson.default.version;
|
|
1339
1353
|
} catch (error) {
|
|
1340
1354
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
package/package.json
CHANGED
|
@@ -62,5 +62,23 @@ describe("v2 utils: validation", () => {
|
|
|
62
62
|
expect(() => ensureValidScrapeOptions(options)).not.toThrow();
|
|
63
63
|
expect(options.parsers).toEqual(before);
|
|
64
64
|
});
|
|
65
|
+
|
|
66
|
+
test("ensureValidFormats: detects mistaken use of zod schema.shape", () => {
|
|
67
|
+
const schema = z.object({ title: z.string(), count: z.number() });
|
|
68
|
+
// User mistakenly passes schema.shape instead of schema
|
|
69
|
+
const formats: FormatOption[] = [
|
|
70
|
+
{ type: "json", prompt: "extract", schema: schema.shape } as any,
|
|
71
|
+
];
|
|
72
|
+
expect(() => ensureValidFormats(formats)).toThrow(/\.shape property/i);
|
|
73
|
+
expect(() => ensureValidFormats(formats)).toThrow(/Pass the Zod schema directly/i);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("ensureValidFormats: detects mistaken use of zod schema.shape in changeTracking", () => {
|
|
77
|
+
const schema = z.object({ title: z.string() });
|
|
78
|
+
const formats: FormatOption[] = [
|
|
79
|
+
{ type: "changeTracking", modes: ["json"], schema: schema.shape } as any,
|
|
80
|
+
];
|
|
81
|
+
expect(() => ensureValidFormats(formats)).toThrow(/\.shape property/i);
|
|
82
|
+
});
|
|
65
83
|
});
|
|
66
84
|
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { type FormatOption, type JsonFormat, type ScrapeOptions, type ScreenshotFormat, type ChangeTrackingFormat } from "../types";
|
|
2
2
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Detects if an object looks like a Zod schema's `.shape` property.
|
|
6
|
+
* When users mistakenly pass `schema.shape` instead of `schema`, the object
|
|
7
|
+
* will have Zod types as values but won't be a Zod schema itself.
|
|
8
|
+
*/
|
|
9
|
+
function looksLikeZodShape(obj: unknown): boolean {
|
|
10
|
+
if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
|
|
11
|
+
const values = Object.values(obj);
|
|
12
|
+
if (values.length === 0) return false;
|
|
13
|
+
// Check if at least one value looks like a Zod type
|
|
14
|
+
return values.some((v: any) => v && typeof v === "object" && v._def && typeof v.safeParse === "function");
|
|
15
|
+
}
|
|
16
|
+
|
|
4
17
|
export function ensureValidFormats(formats?: FormatOption[]): void {
|
|
5
18
|
if (!formats) return;
|
|
6
19
|
for (const fmt of formats) {
|
|
@@ -24,6 +37,13 @@ export function ensureValidFormats(formats?: FormatOption[]): void {
|
|
|
24
37
|
} catch {
|
|
25
38
|
// If conversion fails, leave as-is; server-side may still handle, or request will fail explicitly
|
|
26
39
|
}
|
|
40
|
+
} else if (looksLikeZodShape(maybeSchema)) {
|
|
41
|
+
// User likely passed schema.shape instead of the schema itself
|
|
42
|
+
throw new Error(
|
|
43
|
+
"json format schema appears to be a Zod schema's .shape property. " +
|
|
44
|
+
"Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. " +
|
|
45
|
+
"The SDK will automatically convert Zod schemas to JSON Schema format."
|
|
46
|
+
);
|
|
27
47
|
}
|
|
28
48
|
continue;
|
|
29
49
|
}
|
|
@@ -37,6 +57,12 @@ export function ensureValidFormats(formats?: FormatOption[]): void {
|
|
|
37
57
|
} catch {
|
|
38
58
|
// Best-effort conversion; if it fails, leave original value
|
|
39
59
|
}
|
|
60
|
+
} else if (looksLikeZodShape(maybeSchema)) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"changeTracking format schema appears to be a Zod schema's .shape property. " +
|
|
63
|
+
"Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. " +
|
|
64
|
+
"The SDK will automatically convert Zod schemas to JSON Schema format."
|
|
65
|
+
);
|
|
40
66
|
}
|
|
41
67
|
continue;
|
|
42
68
|
}
|