webpeel 0.21.62 → 0.21.64
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 +6 -7
- package/dist/cli/utils.js +1 -1
- package/dist/core/http-fetch.js +6 -2
- package/dist/server/routes/fetch-queue.js +88 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
<a href="https://github.com/webpeel/webpeel/actions/workflows/ci.yml"><img src="https://github.com/webpeel/webpeel/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
9
9
|
<a href="https://www.npmjs.com/package/webpeel"><img src="https://img.shields.io/npm/v/webpeel.svg?style=flat-square" alt="npm version"></a>
|
|
10
10
|
<a href="https://pypi.org/project/webpeel/"><img src="https://img.shields.io/pypi/v/webpeel.svg?style=flat-square" alt="PyPI version"></a>
|
|
11
|
-
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square" alt="License: MIT"></a>
|
|
12
11
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-WebPeel%20SDK-blue.svg?style=flat-square" alt="License"></a>
|
|
13
12
|
<a href="https://webpeel.dev/status"><img src="https://img.shields.io/badge/status-operational-brightgreen.svg?style=flat-square" alt="Status"></a>
|
|
14
13
|
</p>
|
|
@@ -305,20 +304,20 @@ webpeel "https://news.ycombinator.com"
|
|
|
305
304
|
# Search the web
|
|
306
305
|
webpeel search "typescript orm comparison 2025"
|
|
307
306
|
|
|
308
|
-
# Extract structured data
|
|
309
|
-
webpeel
|
|
307
|
+
# Extract structured data with a JSON schema
|
|
308
|
+
webpeel "https://stripe.com/pricing" --extract-schema pricing-schema.json
|
|
310
309
|
|
|
311
|
-
# Crawl a site
|
|
312
|
-
webpeel crawl "https://docs.example.com" --
|
|
310
|
+
# Crawl a site
|
|
311
|
+
webpeel crawl "https://docs.example.com" --max-pages 100
|
|
313
312
|
|
|
314
313
|
# Screenshot
|
|
315
314
|
webpeel screenshot "https://webpeel.dev" --full-page --output screenshot.png
|
|
316
315
|
|
|
317
316
|
# YouTube transcript
|
|
318
|
-
webpeel
|
|
317
|
+
webpeel "https://youtube.com/watch?v=dQw4w9WgXcQ" --json
|
|
319
318
|
|
|
320
319
|
# Ask a question about a page
|
|
321
|
-
webpeel
|
|
320
|
+
webpeel ask "https://openai.com/pricing" "How much does GPT-4o cost per million tokens?"
|
|
322
321
|
|
|
323
322
|
# Output as JSON
|
|
324
323
|
webpeel "https://example.com" --json
|
package/dist/cli/utils.js
CHANGED
|
@@ -398,7 +398,7 @@ export function buildCondensedHelp() {
|
|
|
398
398
|
` --raw Full page (disable auto reader mode)`,
|
|
399
399
|
` --full Full page, no budget limit`,
|
|
400
400
|
` --json JSON output with metadata`,
|
|
401
|
-
` --budget: 4000)`,
|
|
401
|
+
` --budget <n> Token budget (default: 4000 in pipe mode)`,
|
|
402
402
|
` -q, --question <q> Ask about the content`,
|
|
403
403
|
` -s, --silent No spinner output`,
|
|
404
404
|
'',
|
package/dist/core/http-fetch.js
CHANGED
|
@@ -559,10 +559,14 @@ export async function simpleFetch(url, userAgent, timeoutMs = 30000, customHeade
|
|
|
559
559
|
try {
|
|
560
560
|
const requestHeaders = { ...mergedHeaders };
|
|
561
561
|
const validators = getConditionalValidators(currentUrl);
|
|
562
|
-
|
|
562
|
+
// Only send conditional headers if we actually have the cached body
|
|
563
|
+
// In server/worker mode, the in-memory cache may have been cleared (pod restart)
|
|
564
|
+
// and sending If-None-Match without a cached body would cause a 304 crash
|
|
565
|
+
const cachedBody = getCachedResultFor304(currentUrl, url);
|
|
566
|
+
if (validators?.etag && cachedBody && !hasHeader(requestHeaders, 'if-none-match')) {
|
|
563
567
|
requestHeaders['If-None-Match'] = validators.etag;
|
|
564
568
|
}
|
|
565
|
-
if (validators?.lastModified && !hasHeader(requestHeaders, 'if-modified-since')) {
|
|
569
|
+
if (validators?.lastModified && cachedBody && !hasHeader(requestHeaders, 'if-modified-since')) {
|
|
566
570
|
requestHeaders['If-Modified-Since'] = validators.lastModified;
|
|
567
571
|
}
|
|
568
572
|
// Use proxy if provided or auto-selected, otherwise use shared connection pool
|
|
@@ -176,6 +176,81 @@ export function createQueueFetchRouter() {
|
|
|
176
176
|
pollUrl: `/v1/jobs/${jobId}`,
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* GET/POST /v1/fetch/sync — Synchronous fetch, no queue
|
|
181
|
+
* Returns content inline (no jobId/polling). Much faster for simple pages.
|
|
182
|
+
* Timeout: 25s max. No fallback to queue — fails fast if timeout exceeded.
|
|
183
|
+
*/
|
|
184
|
+
async function handleSyncFetch(req, res) {
|
|
185
|
+
const requestId = req.requestId || randomUUID();
|
|
186
|
+
const url = validateUrl(req.body?.url || req.query?.url, res, requestId);
|
|
187
|
+
if (!url)
|
|
188
|
+
return;
|
|
189
|
+
const userId = req.auth?.keyInfo?.accountId || req.user?.userId;
|
|
190
|
+
if (!userId) {
|
|
191
|
+
res.status(401).json({
|
|
192
|
+
success: false,
|
|
193
|
+
error: { type: 'unauthorized', message: 'API key required.' },
|
|
194
|
+
requestId,
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
// Import peel dynamically to avoid circular deps
|
|
200
|
+
const { peel } = await import('../../index.js');
|
|
201
|
+
const options = {
|
|
202
|
+
format: req.body?.format || req.query?.format || 'markdown',
|
|
203
|
+
render: req.body?.render === true || req.query?.render === 'true',
|
|
204
|
+
stealth: req.body?.stealth === true || req.query?.stealth === 'true',
|
|
205
|
+
budget: req.body?.budget ? Number(req.body.budget) : (req.query?.budget ? Number(req.query.budget) : undefined),
|
|
206
|
+
selector: req.body?.selector || req.query?.selector,
|
|
207
|
+
readable: req.body?.readable === true || req.query?.readable === 'true',
|
|
208
|
+
wait: req.body?.wait ? Number(req.body.wait) : (req.query?.wait ? Number(req.query.wait) : undefined),
|
|
209
|
+
question: req.body?.question || req.query?.question,
|
|
210
|
+
timeout: 25000, // 25s max (leave 5s buffer for response)
|
|
211
|
+
};
|
|
212
|
+
const result = await peel(url, options);
|
|
213
|
+
res.json({
|
|
214
|
+
success: true,
|
|
215
|
+
...result,
|
|
216
|
+
requestId,
|
|
217
|
+
mode: 'sync',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
const statusCode = err.statusCode || 500;
|
|
222
|
+
res.status(statusCode >= 400 && statusCode < 600 ? statusCode : 500).json({
|
|
223
|
+
success: false,
|
|
224
|
+
error: {
|
|
225
|
+
type: err.errorType || 'fetch_error',
|
|
226
|
+
message: err.message || 'Fetch failed',
|
|
227
|
+
},
|
|
228
|
+
requestId,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
router.get('/v1/fetch/sync', (req, res) => {
|
|
233
|
+
// Map query params to body
|
|
234
|
+
req.body = req.body || {};
|
|
235
|
+
if (req.query.url)
|
|
236
|
+
req.body.url = req.query.url;
|
|
237
|
+
if (req.query.format)
|
|
238
|
+
req.body.format = req.query.format;
|
|
239
|
+
if (req.query.render)
|
|
240
|
+
req.body.render = req.query.render === 'true';
|
|
241
|
+
if (req.query.stealth)
|
|
242
|
+
req.body.stealth = req.query.stealth === 'true';
|
|
243
|
+
if (req.query.budget)
|
|
244
|
+
req.body.budget = Number(req.query.budget);
|
|
245
|
+
if (req.query.selector)
|
|
246
|
+
req.body.selector = req.query.selector;
|
|
247
|
+
if (req.query.readable)
|
|
248
|
+
req.body.readable = req.query.readable === 'true';
|
|
249
|
+
if (req.query.question)
|
|
250
|
+
req.body.question = req.query.question;
|
|
251
|
+
void handleSyncFetch(req, res);
|
|
252
|
+
});
|
|
253
|
+
router.post('/v1/fetch/sync', (req, res) => void handleSyncFetch(req, res));
|
|
179
254
|
// GET /v1/fetch?url=... — CLI and backward-compatible GET requests
|
|
180
255
|
// Maps query params into req.body so handleEnqueue works uniformly
|
|
181
256
|
router.get('/v1/fetch', (req, res) => {
|
|
@@ -213,6 +288,19 @@ export function createQueueFetchRouter() {
|
|
|
213
288
|
router.get('/v1/jobs/:id', async (req, res) => {
|
|
214
289
|
const { id } = req.params;
|
|
215
290
|
const requestId = req.requestId || randomUUID();
|
|
291
|
+
// Auth required — prevent IDOR (unauthenticated access to job results)
|
|
292
|
+
if (!req.auth?.keyInfo) {
|
|
293
|
+
res.status(401).json({
|
|
294
|
+
success: false,
|
|
295
|
+
error: {
|
|
296
|
+
type: 'unauthorized',
|
|
297
|
+
message: 'API key required to poll job results.',
|
|
298
|
+
docs: 'https://webpeel.dev/docs/errors#unauthorized',
|
|
299
|
+
},
|
|
300
|
+
requestId,
|
|
301
|
+
});
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
216
304
|
if (!id || typeof id !== 'string') {
|
|
217
305
|
res.status(400).json({
|
|
218
306
|
success: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpeel",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.64",
|
|
4
4
|
"description": "Fast web fetcher for AI agents - stealth mode, crawl mode, page actions, structured extraction, PDF parsing, smart escalation from simple HTTP to headless browser",
|
|
5
5
|
"author": "Jake Liu",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"prepublishOnly": "bash scripts/pre-publish.sh",
|
|
60
60
|
"serve": "node dist/server/app.js",
|
|
61
61
|
"mcp": "node dist/mcp/server.js",
|
|
62
|
+
"preversion": "npm run build && npm test && bash scripts/pre-publish-gate.sh",
|
|
62
63
|
"version": "bash scripts/postversion.sh"
|
|
63
64
|
},
|
|
64
65
|
"repository": {
|