@crawlee/core 4.0.0-beta.241 → 4.0.0-beta.243

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/configuration.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
+ import JSON5 from 'json5';
3
4
  import { z } from 'zod';
4
5
  import { log, LogLevel } from './log.js';
5
6
  import { serviceLocator } from './service-locator.js';
@@ -222,8 +223,9 @@ export class Configuration {
222
223
  */
223
224
  static #loadFileOptions() {
224
225
  try {
225
- const file = readFileSync(join(process.cwd(), 'crawlee.json'));
226
- return JSON.parse(file.toString());
226
+ const file = readFileSync(join(process.cwd(), 'crawlee.json'), 'utf8');
227
+ // JSON5 also handles a leading UTF-8 byte order mark, which some Windows tools write
228
+ return JSON5.parse(file);
227
229
  }
228
230
  catch {
229
231
  return {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/core",
3
- "version": "4.0.0-beta.241",
3
+ "version": "4.0.0-beta.243",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
6
  "node": ">=22.13.0"
@@ -53,10 +53,10 @@
53
53
  "@apify/log": "^3.0.1",
54
54
  "@apify/timeout": "^1.0.1",
55
55
  "@apify/utilities": "^3.0.1",
56
- "@crawlee/fs-storage": "4.0.0-beta.241",
57
- "@crawlee/http-client": "4.0.0-beta.241",
58
- "@crawlee/types": "4.0.0-beta.241",
59
- "@crawlee/utils": "4.0.0-beta.241",
56
+ "@crawlee/fs-storage": "4.0.0-beta.243",
57
+ "@crawlee/http-client": "4.0.0-beta.243",
58
+ "@crawlee/types": "4.0.0-beta.243",
59
+ "@crawlee/utils": "4.0.0-beta.243",
60
60
  "@sapphire/async-queue": "^1.5.5",
61
61
  "@standard-schema/spec": "^1.0.0",
62
62
  "@vladfrangu/async_event_emitter": "^2.4.6",
@@ -76,5 +76,5 @@
76
76
  }
77
77
  }
78
78
  },
79
- "gitHead": "1c337d1ef50c3e28e25e2ae40bc38bb6de67c37e"
79
+ "gitHead": "280080128539955207a5b4317cc1fba868d3ec82"
80
80
  }
package/request.js CHANGED
@@ -24,6 +24,27 @@ const requestOptionsSchema = z.compile(z.looseObject({
24
24
  .refine((value) => value >= 0, 'Expected a number greater than or equal to 0')
25
25
  .optional(),
26
26
  }));
27
+ /** Storages return `null` for fields left unset by other clients, e.g. the Python SDK. */
28
+ const unset = (schema) => schema.nullish().transform((value) => value ?? undefined);
29
+ /** A request as storages return it. Accepts no less than the constructor does for the same fields. */
30
+ const storedRequestSchema = z.compile(z.object({
31
+ id: z.string().optional(),
32
+ url: z.string(),
33
+ uniqueKey: z.string(),
34
+ method: z.custom((value) => typeof value === 'string').optional(),
35
+ payload: unset(z.custom((value) => typeof value === 'string' || value instanceof Uint8Array)),
36
+ noRetry: unset(z.boolean()),
37
+ retryCount: z.number().optional(),
38
+ // Entries are not checked, persisted requests can hold `null`s there (#4087).
39
+ errorMessages: unset(z.custom(Array.isArray)),
40
+ headers: unset(z.custom((value) => typeof value === 'object' && value !== null)),
41
+ userData: schemas.anyObject.optional(),
42
+ // `apify-client` parses `*At` fields into `Date`s, whatever the schema says.
43
+ handledAt: unset(z.custom((value) => typeof value === 'string' || value instanceof Date)),
44
+ loadedUrl: unset(z.string()),
45
+ }));
46
+ // `@crawlee/types` cannot depend on `zod`, so this keeps `RequestSchema` in sync with the schema above.
47
+ true;
27
48
  /**
28
49
  * Represents a URL to be crawled, optionally including HTTP method, headers, payload and other metadata, together
29
50
  * with the processing state a request queue keeps about it (`retryCount`, `errorMessages`, `handledAt`, ...).
@@ -191,13 +212,13 @@ class CrawleeRequest {
191
212
  * {@link RequestOptions} object cannot carry. Subclasses get instances of themselves.
192
213
  */
193
214
  static fromSchema(schema) {
194
- const { id, retryCount = 0, errorMessages = [], handledAt, loadedUrl, ...options } = schema;
215
+ const stored = parseArgument(schema, storedRequestSchema, 'RequestSchema');
216
+ const { id, retryCount = 0, errorMessages = [], handledAt, loadedUrl, ...options } = stored;
195
217
  const request = new this(options);
196
218
  request.id = id;
197
219
  request.retryCount = retryCount;
198
220
  request.errorMessages = [...errorMessages];
199
221
  request.loadedUrl = loadedUrl;
200
- // `apify-client` parses `*At` fields into `Date`s, whatever the schema says.
201
222
  request.handledAt =
202
223
  handledAt instanceof Date ? handledAt.toISOString() : handledAt;
203
224
  return request;