@fetchbrain.com/sdk 0.7.0 → 0.7.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/README.md +5 -1
- package/dist/index.js +17 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -1073,6 +1073,13 @@ function isIterableInputRejection(err) {
|
|
|
1073
1073
|
const message = err instanceof Error ? err.message : String(err);
|
|
1074
1074
|
return /iterable|\barray\b/i.test(message);
|
|
1075
1075
|
}
|
|
1076
|
+
function resolveHandlerKey(crawler) {
|
|
1077
|
+
const c = crawler;
|
|
1078
|
+
for (const key of ["userProvidedRequestHandler", "requestHandler", "userDefinedRequestHandler"]) {
|
|
1079
|
+
if (typeof c[key] === "function") return key;
|
|
1080
|
+
}
|
|
1081
|
+
return null;
|
|
1082
|
+
}
|
|
1076
1083
|
function buildRawRequest(request) {
|
|
1077
1084
|
const r = request;
|
|
1078
1085
|
let headers;
|
|
@@ -1183,7 +1190,14 @@ var FetchBrain = class {
|
|
|
1183
1190
|
startTime: 0
|
|
1184
1191
|
};
|
|
1185
1192
|
const pendingLearns = /* @__PURE__ */ new Set();
|
|
1186
|
-
|
|
1193
|
+
if ("adaptiveRequestHandler" in crawler) {
|
|
1194
|
+
logger.warn(
|
|
1195
|
+
"AdaptivePlaywrightCrawler is not supported yet \u2014 FetchBrain left this crawler unmodified"
|
|
1196
|
+
);
|
|
1197
|
+
return Object.assign(crawler, { fetchBrain: client });
|
|
1198
|
+
}
|
|
1199
|
+
const handlerKey = resolveHandlerKey(crawler);
|
|
1200
|
+
const originalHandler = handlerKey ? crawler[handlerKey] : void 0;
|
|
1187
1201
|
if (!originalHandler) {
|
|
1188
1202
|
logger.warn("No request handler found on crawler, returning unmodified");
|
|
1189
1203
|
return Object.assign(crawler, { fetchBrain: client });
|
|
@@ -1430,12 +1444,8 @@ var FetchBrain = class {
|
|
|
1430
1444
|
}
|
|
1431
1445
|
};
|
|
1432
1446
|
const crawlerAny = crawler;
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
}
|
|
1436
|
-
if ("userDefinedRequestHandler" in crawlerAny) {
|
|
1437
|
-
crawlerAny.userDefinedRequestHandler = wrappedHandler;
|
|
1438
|
-
}
|
|
1447
|
+
crawlerAny[handlerKey] = wrappedHandler;
|
|
1448
|
+
logger.debug(`Wrapped ${handlerKey}`);
|
|
1439
1449
|
if (typeof crawlerAny.run === "function") {
|
|
1440
1450
|
const originalRun = crawlerAny.run.bind(crawlerAny);
|
|
1441
1451
|
crawlerAny.run = async (...args) => {
|