@upcrawl/sdk 1.2.2 → 1.3.0

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/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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upcrawl/sdk",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },