@upcrawl/sdk 1.2.2 → 1.3.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 +58 -1
- package/dist/index.d.mts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +17 -0
- package/dist/index.mjs +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,6 +148,41 @@ const result = await Upcrawl.generatePdfFromUrl({
|
|
|
148
148
|
console.log(result.url); // Download URL for the PDF
|
|
149
149
|
```
|
|
150
150
|
|
|
151
|
+
### Execute Code
|
|
152
|
+
|
|
153
|
+
Run code in an isolated sandbox environment:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
const result = await Upcrawl.executeCode({
|
|
157
|
+
code: 'print("Hello, World!")',
|
|
158
|
+
language: 'python'
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
console.log(result.stdout); // "Hello, World!\n"
|
|
162
|
+
console.log(result.exitCode); // 0
|
|
163
|
+
console.log(result.executionTimeMs); // 95.23
|
|
164
|
+
console.log(result.memoryUsageMb); // 8.45
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Each execution runs in its own isolated subprocess inside a Kata micro-VM with no network access. Code is cleaned up immediately after execution.
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
// Multi-line code with imports
|
|
171
|
+
const result = await Upcrawl.executeCode({
|
|
172
|
+
code: `
|
|
173
|
+
import json
|
|
174
|
+
data = {"name": "Upcrawl", "version": 1}
|
|
175
|
+
print(json.dumps(data, indent=2))
|
|
176
|
+
`
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
console.log(result.stdout);
|
|
180
|
+
// {
|
|
181
|
+
// "name": "Upcrawl",
|
|
182
|
+
// "version": 1
|
|
183
|
+
// }
|
|
184
|
+
```
|
|
185
|
+
|
|
151
186
|
### Domain Filtering
|
|
152
187
|
|
|
153
188
|
Filter search results by domain:
|
|
@@ -249,7 +284,9 @@ import Upcrawl, {
|
|
|
249
284
|
BatchScrapeOptions,
|
|
250
285
|
BatchScrapeResponse,
|
|
251
286
|
GeneratePdfOptions,
|
|
252
|
-
PdfResponse
|
|
287
|
+
PdfResponse,
|
|
288
|
+
ExecuteCodeOptions,
|
|
289
|
+
ExecuteCodeResponse
|
|
253
290
|
} from '@upcrawl/sdk';
|
|
254
291
|
|
|
255
292
|
const options: ScrapeOptions = {
|
|
@@ -275,6 +312,7 @@ const result: ScrapeResponse = await Upcrawl.scrape(options);
|
|
|
275
312
|
| `Upcrawl.search(options)` | Search the web |
|
|
276
313
|
| `Upcrawl.generatePdf(options)` | Generate PDF from HTML |
|
|
277
314
|
| `Upcrawl.generatePdfFromUrl(options)` | Generate PDF from a URL |
|
|
315
|
+
| `Upcrawl.executeCode(options)` | Execute code in an isolated sandbox |
|
|
278
316
|
|
|
279
317
|
### Scrape Options
|
|
280
318
|
|
|
@@ -323,6 +361,25 @@ const result: ScrapeResponse = await Upcrawl.scrape(options);
|
|
|
323
361
|
| `printBackground` | `boolean` | Print background graphics |
|
|
324
362
|
| `timeoutMs` | `number` | Timeout (5000-120000) |
|
|
325
363
|
|
|
364
|
+
### Execute Code Options
|
|
365
|
+
|
|
366
|
+
| Option | Type | Description |
|
|
367
|
+
|--------|------|-------------|
|
|
368
|
+
| `code` | `string` | Code to execute (required) |
|
|
369
|
+
| `language` | `'python'` | Language runtime (default: python) |
|
|
370
|
+
|
|
371
|
+
### Execute Code Response
|
|
372
|
+
|
|
373
|
+
| Field | Type | Description |
|
|
374
|
+
|-------|------|-------------|
|
|
375
|
+
| `stdout` | `string` | Standard output |
|
|
376
|
+
| `stderr` | `string` | Standard error |
|
|
377
|
+
| `exitCode` | `number` | Exit code (0 = success, 124 = timeout) |
|
|
378
|
+
| `executionTimeMs` | `number` | Execution time in milliseconds |
|
|
379
|
+
| `timedOut` | `boolean` | Whether execution timed out |
|
|
380
|
+
| `memoryUsageMb` | `number` | Peak memory usage in MB |
|
|
381
|
+
| `cost` | `number` | Cost in USD |
|
|
382
|
+
|
|
326
383
|
## License
|
|
327
384
|
|
|
328
385
|
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -195,6 +195,30 @@ interface PdfResponse {
|
|
|
195
195
|
/** Total time taken in milliseconds */
|
|
196
196
|
durationMs: number;
|
|
197
197
|
}
|
|
198
|
+
interface ExecuteCodeOptions {
|
|
199
|
+
/** Code to execute (required) */
|
|
200
|
+
code: string;
|
|
201
|
+
/** Language runtime. Defaults to "python" */
|
|
202
|
+
language?: 'python';
|
|
203
|
+
}
|
|
204
|
+
interface ExecuteCodeResponse {
|
|
205
|
+
/** Standard output from the executed code */
|
|
206
|
+
stdout: string;
|
|
207
|
+
/** Standard error from the executed code */
|
|
208
|
+
stderr: string;
|
|
209
|
+
/** Process exit code (0 = success, 124 = timeout) */
|
|
210
|
+
exitCode: number;
|
|
211
|
+
/** Execution time in milliseconds */
|
|
212
|
+
executionTimeMs: number;
|
|
213
|
+
/** Whether execution was killed due to timeout */
|
|
214
|
+
timedOut: boolean;
|
|
215
|
+
/** Peak memory usage in megabytes */
|
|
216
|
+
memoryUsageMb?: number;
|
|
217
|
+
/** Error message if execution infrastructure failed */
|
|
218
|
+
error?: string;
|
|
219
|
+
/** Cost in USD for this execution */
|
|
220
|
+
cost?: number;
|
|
221
|
+
}
|
|
198
222
|
interface UpcrawlErrorResponse {
|
|
199
223
|
error: {
|
|
200
224
|
code: string;
|
|
@@ -357,6 +381,28 @@ declare function generatePdf(options: GeneratePdfOptions): Promise<PdfResponse>;
|
|
|
357
381
|
* ```
|
|
358
382
|
*/
|
|
359
383
|
declare function generatePdfFromUrl(options: GeneratePdfFromUrlOptions): Promise<PdfResponse>;
|
|
384
|
+
/**
|
|
385
|
+
* Execute code in an isolated sandbox
|
|
386
|
+
* @param options - Code execution options including the code to run
|
|
387
|
+
* @returns Promise with execution response (stdout, stderr, exit code, memory usage)
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* import Upcrawl from '@upcrawl/sdk';
|
|
392
|
+
*
|
|
393
|
+
* Upcrawl.setApiKey('uc-your-api-key');
|
|
394
|
+
*
|
|
395
|
+
* const result = await Upcrawl.executeCode({
|
|
396
|
+
* code: 'print("Hello, World!")',
|
|
397
|
+
* language: 'python'
|
|
398
|
+
* });
|
|
399
|
+
*
|
|
400
|
+
* console.log(result.stdout); // "Hello, World!\n"
|
|
401
|
+
* console.log(result.executionTimeMs); // 95.23
|
|
402
|
+
* console.log(result.memoryUsageMb); // 8.45
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
declare function executeCode(options: ExecuteCodeOptions): Promise<ExecuteCodeResponse>;
|
|
360
406
|
|
|
361
407
|
/**
|
|
362
408
|
* Upcrawl SDK
|
|
@@ -473,10 +519,16 @@ declare const Upcrawl: {
|
|
|
473
519
|
* @returns Promise with PDF response containing the download URL
|
|
474
520
|
*/
|
|
475
521
|
readonly generatePdfFromUrl: typeof generatePdfFromUrl;
|
|
522
|
+
/**
|
|
523
|
+
* Execute code in an isolated sandbox
|
|
524
|
+
* @param options - Code execution options including the code to run
|
|
525
|
+
* @returns Promise with execution response (stdout, stderr, exit code, memory usage)
|
|
526
|
+
*/
|
|
527
|
+
readonly executeCode: typeof executeCode;
|
|
476
528
|
/**
|
|
477
529
|
* Error class for Upcrawl API errors
|
|
478
530
|
*/
|
|
479
531
|
readonly UpcrawlError: typeof UpcrawlError;
|
|
480
532
|
};
|
|
481
533
|
|
|
482
|
-
export { type BatchScrapeOptions, type BatchScrapeResponse, type GeneratePdfFromUrlOptions, type GeneratePdfOptions, type PdfMargin, type PdfResponse, type ScrapeMetadata, type ScrapeOptions, type ScrapeResponse, type SearchOptions, type SearchResponse, type SearchResultItem, type SearchResultWeb, type SummaryQuery, type UpcrawlConfig, UpcrawlError, type UpcrawlErrorResponse, batchScrape, configure, Upcrawl as default, generatePdf, generatePdfFromUrl, getConfig, resetConfig, scrape, search, setApiKey, setBaseUrl, setTimeout };
|
|
534
|
+
export { type BatchScrapeOptions, type BatchScrapeResponse, type ExecuteCodeOptions, type ExecuteCodeResponse, type GeneratePdfFromUrlOptions, type GeneratePdfOptions, type PdfMargin, type PdfResponse, type ScrapeMetadata, type ScrapeOptions, type ScrapeResponse, type SearchOptions, type SearchResponse, type SearchResultItem, type SearchResultWeb, type SummaryQuery, type UpcrawlConfig, UpcrawlError, type UpcrawlErrorResponse, batchScrape, configure, Upcrawl as default, executeCode, generatePdf, generatePdfFromUrl, getConfig, resetConfig, scrape, search, setApiKey, setBaseUrl, setTimeout };
|
package/dist/index.d.ts
CHANGED
|
@@ -195,6 +195,30 @@ interface PdfResponse {
|
|
|
195
195
|
/** Total time taken in milliseconds */
|
|
196
196
|
durationMs: number;
|
|
197
197
|
}
|
|
198
|
+
interface ExecuteCodeOptions {
|
|
199
|
+
/** Code to execute (required) */
|
|
200
|
+
code: string;
|
|
201
|
+
/** Language runtime. Defaults to "python" */
|
|
202
|
+
language?: 'python';
|
|
203
|
+
}
|
|
204
|
+
interface ExecuteCodeResponse {
|
|
205
|
+
/** Standard output from the executed code */
|
|
206
|
+
stdout: string;
|
|
207
|
+
/** Standard error from the executed code */
|
|
208
|
+
stderr: string;
|
|
209
|
+
/** Process exit code (0 = success, 124 = timeout) */
|
|
210
|
+
exitCode: number;
|
|
211
|
+
/** Execution time in milliseconds */
|
|
212
|
+
executionTimeMs: number;
|
|
213
|
+
/** Whether execution was killed due to timeout */
|
|
214
|
+
timedOut: boolean;
|
|
215
|
+
/** Peak memory usage in megabytes */
|
|
216
|
+
memoryUsageMb?: number;
|
|
217
|
+
/** Error message if execution infrastructure failed */
|
|
218
|
+
error?: string;
|
|
219
|
+
/** Cost in USD for this execution */
|
|
220
|
+
cost?: number;
|
|
221
|
+
}
|
|
198
222
|
interface UpcrawlErrorResponse {
|
|
199
223
|
error: {
|
|
200
224
|
code: string;
|
|
@@ -357,6 +381,28 @@ declare function generatePdf(options: GeneratePdfOptions): Promise<PdfResponse>;
|
|
|
357
381
|
* ```
|
|
358
382
|
*/
|
|
359
383
|
declare function generatePdfFromUrl(options: GeneratePdfFromUrlOptions): Promise<PdfResponse>;
|
|
384
|
+
/**
|
|
385
|
+
* Execute code in an isolated sandbox
|
|
386
|
+
* @param options - Code execution options including the code to run
|
|
387
|
+
* @returns Promise with execution response (stdout, stderr, exit code, memory usage)
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* import Upcrawl from '@upcrawl/sdk';
|
|
392
|
+
*
|
|
393
|
+
* Upcrawl.setApiKey('uc-your-api-key');
|
|
394
|
+
*
|
|
395
|
+
* const result = await Upcrawl.executeCode({
|
|
396
|
+
* code: 'print("Hello, World!")',
|
|
397
|
+
* language: 'python'
|
|
398
|
+
* });
|
|
399
|
+
*
|
|
400
|
+
* console.log(result.stdout); // "Hello, World!\n"
|
|
401
|
+
* console.log(result.executionTimeMs); // 95.23
|
|
402
|
+
* console.log(result.memoryUsageMb); // 8.45
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
declare function executeCode(options: ExecuteCodeOptions): Promise<ExecuteCodeResponse>;
|
|
360
406
|
|
|
361
407
|
/**
|
|
362
408
|
* Upcrawl SDK
|
|
@@ -473,10 +519,16 @@ declare const Upcrawl: {
|
|
|
473
519
|
* @returns Promise with PDF response containing the download URL
|
|
474
520
|
*/
|
|
475
521
|
readonly generatePdfFromUrl: typeof generatePdfFromUrl;
|
|
522
|
+
/**
|
|
523
|
+
* Execute code in an isolated sandbox
|
|
524
|
+
* @param options - Code execution options including the code to run
|
|
525
|
+
* @returns Promise with execution response (stdout, stderr, exit code, memory usage)
|
|
526
|
+
*/
|
|
527
|
+
readonly executeCode: typeof executeCode;
|
|
476
528
|
/**
|
|
477
529
|
* Error class for Upcrawl API errors
|
|
478
530
|
*/
|
|
479
531
|
readonly UpcrawlError: typeof UpcrawlError;
|
|
480
532
|
};
|
|
481
533
|
|
|
482
|
-
export { type BatchScrapeOptions, type BatchScrapeResponse, type GeneratePdfFromUrlOptions, type GeneratePdfOptions, type PdfMargin, type PdfResponse, type ScrapeMetadata, type ScrapeOptions, type ScrapeResponse, type SearchOptions, type SearchResponse, type SearchResultItem, type SearchResultWeb, type SummaryQuery, type UpcrawlConfig, UpcrawlError, type UpcrawlErrorResponse, batchScrape, configure, Upcrawl as default, generatePdf, generatePdfFromUrl, getConfig, resetConfig, scrape, search, setApiKey, setBaseUrl, setTimeout };
|
|
534
|
+
export { type BatchScrapeOptions, type BatchScrapeResponse, type ExecuteCodeOptions, type ExecuteCodeResponse, type GeneratePdfFromUrlOptions, type GeneratePdfOptions, type PdfMargin, type PdfResponse, type ScrapeMetadata, type ScrapeOptions, type ScrapeResponse, type SearchOptions, type SearchResponse, type SearchResultItem, type SearchResultWeb, type SummaryQuery, type UpcrawlConfig, UpcrawlError, type UpcrawlErrorResponse, batchScrape, configure, Upcrawl as default, executeCode, generatePdf, generatePdfFromUrl, getConfig, resetConfig, scrape, search, setApiKey, setBaseUrl, setTimeout };
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(index_exports, {
|
|
|
34
34
|
batchScrape: () => batchScrape,
|
|
35
35
|
configure: () => configure,
|
|
36
36
|
default: () => index_default,
|
|
37
|
+
executeCode: () => executeCode,
|
|
37
38
|
generatePdf: () => generatePdf,
|
|
38
39
|
generatePdfFromUrl: () => generatePdfFromUrl,
|
|
39
40
|
getConfig: () => getConfig,
|
|
@@ -202,6 +203,15 @@ async function generatePdfFromUrl(options) {
|
|
|
202
203
|
handleError(error);
|
|
203
204
|
}
|
|
204
205
|
}
|
|
206
|
+
async function executeCode(options) {
|
|
207
|
+
try {
|
|
208
|
+
const client = createClient();
|
|
209
|
+
const response = await client.post("/sandbox/execute", options);
|
|
210
|
+
return response.data;
|
|
211
|
+
} catch (error) {
|
|
212
|
+
handleError(error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
205
215
|
|
|
206
216
|
// src/index.ts
|
|
207
217
|
var Upcrawl = {
|
|
@@ -263,6 +273,12 @@ var Upcrawl = {
|
|
|
263
273
|
* @returns Promise with PDF response containing the download URL
|
|
264
274
|
*/
|
|
265
275
|
generatePdfFromUrl,
|
|
276
|
+
/**
|
|
277
|
+
* Execute code in an isolated sandbox
|
|
278
|
+
* @param options - Code execution options including the code to run
|
|
279
|
+
* @returns Promise with execution response (stdout, stderr, exit code, memory usage)
|
|
280
|
+
*/
|
|
281
|
+
executeCode,
|
|
266
282
|
/**
|
|
267
283
|
* Error class for Upcrawl API errors
|
|
268
284
|
*/
|
|
@@ -274,6 +290,7 @@ var index_default = Upcrawl;
|
|
|
274
290
|
UpcrawlError,
|
|
275
291
|
batchScrape,
|
|
276
292
|
configure,
|
|
293
|
+
executeCode,
|
|
277
294
|
generatePdf,
|
|
278
295
|
generatePdfFromUrl,
|
|
279
296
|
getConfig,
|
package/dist/index.mjs
CHANGED
|
@@ -154,6 +154,15 @@ async function generatePdfFromUrl(options) {
|
|
|
154
154
|
handleError(error);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
+
async function executeCode(options) {
|
|
158
|
+
try {
|
|
159
|
+
const client = createClient();
|
|
160
|
+
const response = await client.post("/sandbox/execute", options);
|
|
161
|
+
return response.data;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
handleError(error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
157
166
|
|
|
158
167
|
// src/index.ts
|
|
159
168
|
var Upcrawl = {
|
|
@@ -215,6 +224,12 @@ var Upcrawl = {
|
|
|
215
224
|
* @returns Promise with PDF response containing the download URL
|
|
216
225
|
*/
|
|
217
226
|
generatePdfFromUrl,
|
|
227
|
+
/**
|
|
228
|
+
* Execute code in an isolated sandbox
|
|
229
|
+
* @param options - Code execution options including the code to run
|
|
230
|
+
* @returns Promise with execution response (stdout, stderr, exit code, memory usage)
|
|
231
|
+
*/
|
|
232
|
+
executeCode,
|
|
218
233
|
/**
|
|
219
234
|
* Error class for Upcrawl API errors
|
|
220
235
|
*/
|
|
@@ -226,6 +241,7 @@ export {
|
|
|
226
241
|
batchScrape,
|
|
227
242
|
configure,
|
|
228
243
|
index_default as default,
|
|
244
|
+
executeCode,
|
|
229
245
|
generatePdf,
|
|
230
246
|
generatePdfFromUrl,
|
|
231
247
|
getConfig,
|