@stack0/sdk 0.2.0 → 0.2.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/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +626 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +626 -9
- package/dist/index.mjs.map +1 -1
- package/dist/mail/index.js +1 -8
- package/dist/mail/index.js.map +1 -1
- package/dist/mail/index.mjs +1 -8
- package/dist/mail/index.mjs.map +1 -1
- package/dist/webdata/index.d.mts +696 -0
- package/dist/webdata/index.d.ts +696 -0
- package/dist/webdata/index.js +693 -0
- package/dist/webdata/index.js.map +1 -0
- package/dist/webdata/index.mjs +691 -0
- package/dist/webdata/index.mjs.map +1 -0
- package/package.json +7 -2
package/dist/index.mjs
CHANGED
|
@@ -101,14 +101,7 @@ var Mail = class {
|
|
|
101
101
|
*/
|
|
102
102
|
async get(id) {
|
|
103
103
|
const response = await this.http.get(`/mail/${id}`);
|
|
104
|
-
const dateFields = [
|
|
105
|
-
"createdAt",
|
|
106
|
-
"sentAt",
|
|
107
|
-
"deliveredAt",
|
|
108
|
-
"openedAt",
|
|
109
|
-
"clickedAt",
|
|
110
|
-
"bouncedAt"
|
|
111
|
-
];
|
|
104
|
+
const dateFields = ["createdAt", "sentAt", "deliveredAt", "openedAt", "clickedAt", "bouncedAt"];
|
|
112
105
|
for (const field of dateFields) {
|
|
113
106
|
if (response[field] && typeof response[field] === "string") {
|
|
114
107
|
response[field] = new Date(response[field]);
|
|
@@ -394,10 +387,633 @@ var CDN = class {
|
|
|
394
387
|
}
|
|
395
388
|
};
|
|
396
389
|
|
|
390
|
+
// src/webdata/client.ts
|
|
391
|
+
var Webdata = class {
|
|
392
|
+
http;
|
|
393
|
+
constructor(config) {
|
|
394
|
+
this.http = new HttpClient(config);
|
|
395
|
+
}
|
|
396
|
+
// ==========================================================================
|
|
397
|
+
// SCREENSHOTS
|
|
398
|
+
// ==========================================================================
|
|
399
|
+
/**
|
|
400
|
+
* Capture a screenshot of a URL
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* const { id, status } = await webdata.screenshot({
|
|
405
|
+
* url: 'https://example.com',
|
|
406
|
+
* format: 'png',
|
|
407
|
+
* fullPage: true,
|
|
408
|
+
* deviceType: 'desktop',
|
|
409
|
+
* });
|
|
410
|
+
*
|
|
411
|
+
* // Poll for completion
|
|
412
|
+
* const screenshot = await webdata.getScreenshot({ id });
|
|
413
|
+
* console.log(screenshot.imageUrl);
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
async screenshot(request) {
|
|
417
|
+
return this.http.post("/webdata/screenshots", request);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Get a screenshot by ID
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```typescript
|
|
424
|
+
* const screenshot = await webdata.getScreenshot({ id: 'screenshot-id' });
|
|
425
|
+
* if (screenshot.status === 'completed') {
|
|
426
|
+
* console.log(screenshot.imageUrl);
|
|
427
|
+
* }
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
async getScreenshot(request) {
|
|
431
|
+
const params = new URLSearchParams();
|
|
432
|
+
if (request.environment) params.set("environment", request.environment);
|
|
433
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
434
|
+
const query = params.toString();
|
|
435
|
+
const path = `/webdata/screenshots/${request.id}${query ? `?${query}` : ""}`;
|
|
436
|
+
const response = await this.http.get(path);
|
|
437
|
+
return this.convertScreenshotDates(response);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* List screenshots with pagination and filters
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* const { items, nextCursor } = await webdata.listScreenshots({
|
|
445
|
+
* status: 'completed',
|
|
446
|
+
* limit: 20,
|
|
447
|
+
* });
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
450
|
+
async listScreenshots(request = {}) {
|
|
451
|
+
const params = new URLSearchParams();
|
|
452
|
+
if (request.environment) params.set("environment", request.environment);
|
|
453
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
454
|
+
if (request.status) params.set("status", request.status);
|
|
455
|
+
if (request.url) params.set("url", request.url);
|
|
456
|
+
if (request.limit) params.set("limit", request.limit.toString());
|
|
457
|
+
if (request.cursor) params.set("cursor", request.cursor);
|
|
458
|
+
const query = params.toString();
|
|
459
|
+
const response = await this.http.get(
|
|
460
|
+
`/webdata/screenshots${query ? `?${query}` : ""}`
|
|
461
|
+
);
|
|
462
|
+
return {
|
|
463
|
+
...response,
|
|
464
|
+
items: response.items.map((item) => this.convertScreenshotDates(item))
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Delete a screenshot
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```typescript
|
|
472
|
+
* await webdata.deleteScreenshot({ id: 'screenshot-id' });
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
async deleteScreenshot(request) {
|
|
476
|
+
const params = new URLSearchParams();
|
|
477
|
+
if (request.environment) params.set("environment", request.environment);
|
|
478
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
479
|
+
const query = params.toString();
|
|
480
|
+
return this.http.delete(
|
|
481
|
+
`/webdata/screenshots/${request.id}${query ? `?${query}` : ""}`
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Capture a screenshot and wait for completion
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* ```typescript
|
|
489
|
+
* const screenshot = await webdata.screenshotAndWait({
|
|
490
|
+
* url: 'https://example.com',
|
|
491
|
+
* format: 'png',
|
|
492
|
+
* });
|
|
493
|
+
* console.log(screenshot.imageUrl);
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
async screenshotAndWait(request, options = {}) {
|
|
497
|
+
const { pollInterval = 1e3, timeout = 6e4 } = options;
|
|
498
|
+
const startTime = Date.now();
|
|
499
|
+
const { id } = await this.screenshot(request);
|
|
500
|
+
while (Date.now() - startTime < timeout) {
|
|
501
|
+
const screenshot = await this.getScreenshot({
|
|
502
|
+
id,
|
|
503
|
+
environment: request.environment,
|
|
504
|
+
projectId: request.projectId
|
|
505
|
+
});
|
|
506
|
+
if (screenshot.status === "completed" || screenshot.status === "failed") {
|
|
507
|
+
if (screenshot.status === "failed") {
|
|
508
|
+
throw new Error(screenshot.error || "Screenshot failed");
|
|
509
|
+
}
|
|
510
|
+
return screenshot;
|
|
511
|
+
}
|
|
512
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
513
|
+
}
|
|
514
|
+
throw new Error("Screenshot timed out");
|
|
515
|
+
}
|
|
516
|
+
// ==========================================================================
|
|
517
|
+
// EXTRACTIONS
|
|
518
|
+
// ==========================================================================
|
|
519
|
+
/**
|
|
520
|
+
* Extract content from a URL
|
|
521
|
+
*
|
|
522
|
+
* @example
|
|
523
|
+
* ```typescript
|
|
524
|
+
* const { id, status } = await webdata.extract({
|
|
525
|
+
* url: 'https://example.com/article',
|
|
526
|
+
* mode: 'markdown',
|
|
527
|
+
* includeMetadata: true,
|
|
528
|
+
* });
|
|
529
|
+
*
|
|
530
|
+
* // Poll for completion
|
|
531
|
+
* const extraction = await webdata.getExtraction({ id });
|
|
532
|
+
* console.log(extraction.markdown);
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
async extract(request) {
|
|
536
|
+
return this.http.post("/webdata/extractions", request);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Get an extraction by ID
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```typescript
|
|
543
|
+
* const extraction = await webdata.getExtraction({ id: 'extraction-id' });
|
|
544
|
+
* if (extraction.status === 'completed') {
|
|
545
|
+
* console.log(extraction.markdown);
|
|
546
|
+
* console.log(extraction.pageMetadata);
|
|
547
|
+
* }
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
async getExtraction(request) {
|
|
551
|
+
const params = new URLSearchParams();
|
|
552
|
+
if (request.environment) params.set("environment", request.environment);
|
|
553
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
554
|
+
const query = params.toString();
|
|
555
|
+
const path = `/webdata/extractions/${request.id}${query ? `?${query}` : ""}`;
|
|
556
|
+
const response = await this.http.get(path);
|
|
557
|
+
return this.convertExtractionDates(response);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* List extractions with pagination and filters
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```typescript
|
|
564
|
+
* const { items, nextCursor } = await webdata.listExtractions({
|
|
565
|
+
* status: 'completed',
|
|
566
|
+
* limit: 20,
|
|
567
|
+
* });
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
async listExtractions(request = {}) {
|
|
571
|
+
const params = new URLSearchParams();
|
|
572
|
+
if (request.environment) params.set("environment", request.environment);
|
|
573
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
574
|
+
if (request.status) params.set("status", request.status);
|
|
575
|
+
if (request.url) params.set("url", request.url);
|
|
576
|
+
if (request.limit) params.set("limit", request.limit.toString());
|
|
577
|
+
if (request.cursor) params.set("cursor", request.cursor);
|
|
578
|
+
const query = params.toString();
|
|
579
|
+
const response = await this.http.get(
|
|
580
|
+
`/webdata/extractions${query ? `?${query}` : ""}`
|
|
581
|
+
);
|
|
582
|
+
return {
|
|
583
|
+
...response,
|
|
584
|
+
items: response.items.map((item) => this.convertExtractionDates(item))
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Delete an extraction
|
|
589
|
+
*
|
|
590
|
+
* @example
|
|
591
|
+
* ```typescript
|
|
592
|
+
* await webdata.deleteExtraction({ id: 'extraction-id' });
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
async deleteExtraction(request) {
|
|
596
|
+
const params = new URLSearchParams();
|
|
597
|
+
if (request.environment) params.set("environment", request.environment);
|
|
598
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
599
|
+
const query = params.toString();
|
|
600
|
+
return this.http.delete(
|
|
601
|
+
`/webdata/extractions/${request.id}${query ? `?${query}` : ""}`
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Extract content and wait for completion
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```typescript
|
|
609
|
+
* const extraction = await webdata.extractAndWait({
|
|
610
|
+
* url: 'https://example.com/article',
|
|
611
|
+
* mode: 'markdown',
|
|
612
|
+
* });
|
|
613
|
+
* console.log(extraction.markdown);
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
async extractAndWait(request, options = {}) {
|
|
617
|
+
const { pollInterval = 1e3, timeout = 6e4 } = options;
|
|
618
|
+
const startTime = Date.now();
|
|
619
|
+
const { id } = await this.extract(request);
|
|
620
|
+
while (Date.now() - startTime < timeout) {
|
|
621
|
+
const extraction = await this.getExtraction({
|
|
622
|
+
id,
|
|
623
|
+
environment: request.environment,
|
|
624
|
+
projectId: request.projectId
|
|
625
|
+
});
|
|
626
|
+
if (extraction.status === "completed" || extraction.status === "failed") {
|
|
627
|
+
if (extraction.status === "failed") {
|
|
628
|
+
throw new Error(extraction.error || "Extraction failed");
|
|
629
|
+
}
|
|
630
|
+
return extraction;
|
|
631
|
+
}
|
|
632
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
633
|
+
}
|
|
634
|
+
throw new Error("Extraction timed out");
|
|
635
|
+
}
|
|
636
|
+
// ==========================================================================
|
|
637
|
+
// SCHEDULES
|
|
638
|
+
// ==========================================================================
|
|
639
|
+
/**
|
|
640
|
+
* Create a scheduled screenshot or extraction job
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```typescript
|
|
644
|
+
* const { id } = await webdata.createSchedule({
|
|
645
|
+
* name: 'Daily homepage screenshot',
|
|
646
|
+
* url: 'https://example.com',
|
|
647
|
+
* type: 'screenshot',
|
|
648
|
+
* frequency: 'daily',
|
|
649
|
+
* config: { format: 'png', fullPage: true },
|
|
650
|
+
* });
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
async createSchedule(request) {
|
|
654
|
+
return this.http.post("/webdata/schedules", request);
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Update a schedule
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```typescript
|
|
661
|
+
* await webdata.updateSchedule({
|
|
662
|
+
* id: 'schedule-id',
|
|
663
|
+
* frequency: 'weekly',
|
|
664
|
+
* isActive: false,
|
|
665
|
+
* });
|
|
666
|
+
* ```
|
|
667
|
+
*/
|
|
668
|
+
async updateSchedule(request) {
|
|
669
|
+
const { id, environment, projectId, ...data } = request;
|
|
670
|
+
const params = new URLSearchParams();
|
|
671
|
+
if (environment) params.set("environment", environment);
|
|
672
|
+
if (projectId) params.set("projectId", projectId);
|
|
673
|
+
const query = params.toString();
|
|
674
|
+
return this.http.post(
|
|
675
|
+
`/webdata/schedules/${id}${query ? `?${query}` : ""}`,
|
|
676
|
+
data
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Get a schedule by ID
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```typescript
|
|
684
|
+
* const schedule = await webdata.getSchedule({ id: 'schedule-id' });
|
|
685
|
+
* console.log(schedule.nextRunAt);
|
|
686
|
+
* ```
|
|
687
|
+
*/
|
|
688
|
+
async getSchedule(request) {
|
|
689
|
+
const params = new URLSearchParams();
|
|
690
|
+
if (request.environment) params.set("environment", request.environment);
|
|
691
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
692
|
+
const query = params.toString();
|
|
693
|
+
const path = `/webdata/schedules/${request.id}${query ? `?${query}` : ""}`;
|
|
694
|
+
const response = await this.http.get(path);
|
|
695
|
+
return this.convertScheduleDates(response);
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* List schedules with pagination and filters
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* ```typescript
|
|
702
|
+
* const { items, nextCursor } = await webdata.listSchedules({
|
|
703
|
+
* type: 'screenshot',
|
|
704
|
+
* isActive: true,
|
|
705
|
+
* });
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
async listSchedules(request = {}) {
|
|
709
|
+
const params = new URLSearchParams();
|
|
710
|
+
if (request.environment) params.set("environment", request.environment);
|
|
711
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
712
|
+
if (request.type) params.set("type", request.type);
|
|
713
|
+
if (request.isActive !== void 0) params.set("isActive", request.isActive.toString());
|
|
714
|
+
if (request.limit) params.set("limit", request.limit.toString());
|
|
715
|
+
if (request.cursor) params.set("cursor", request.cursor);
|
|
716
|
+
const query = params.toString();
|
|
717
|
+
const response = await this.http.get(
|
|
718
|
+
`/webdata/schedules${query ? `?${query}` : ""}`
|
|
719
|
+
);
|
|
720
|
+
return {
|
|
721
|
+
...response,
|
|
722
|
+
items: response.items.map((item) => this.convertScheduleDates(item))
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Delete a schedule
|
|
727
|
+
*
|
|
728
|
+
* @example
|
|
729
|
+
* ```typescript
|
|
730
|
+
* await webdata.deleteSchedule({ id: 'schedule-id' });
|
|
731
|
+
* ```
|
|
732
|
+
*/
|
|
733
|
+
async deleteSchedule(request) {
|
|
734
|
+
const params = new URLSearchParams();
|
|
735
|
+
if (request.environment) params.set("environment", request.environment);
|
|
736
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
737
|
+
const query = params.toString();
|
|
738
|
+
return this.http.delete(
|
|
739
|
+
`/webdata/schedules/${request.id}${query ? `?${query}` : ""}`
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Toggle a schedule on or off
|
|
744
|
+
*
|
|
745
|
+
* @example
|
|
746
|
+
* ```typescript
|
|
747
|
+
* const { isActive } = await webdata.toggleSchedule({ id: 'schedule-id' });
|
|
748
|
+
* console.log(`Schedule is now ${isActive ? 'active' : 'paused'}`);
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
async toggleSchedule(request) {
|
|
752
|
+
const params = new URLSearchParams();
|
|
753
|
+
if (request.environment) params.set("environment", request.environment);
|
|
754
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
755
|
+
const query = params.toString();
|
|
756
|
+
return this.http.post(
|
|
757
|
+
`/webdata/schedules/${request.id}/toggle${query ? `?${query}` : ""}`,
|
|
758
|
+
{}
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
// ==========================================================================
|
|
762
|
+
// USAGE
|
|
763
|
+
// ==========================================================================
|
|
764
|
+
/**
|
|
765
|
+
* Get usage statistics
|
|
766
|
+
*
|
|
767
|
+
* @example
|
|
768
|
+
* ```typescript
|
|
769
|
+
* const usage = await webdata.getUsage({
|
|
770
|
+
* periodStart: '2024-01-01T00:00:00Z',
|
|
771
|
+
* periodEnd: '2024-01-31T23:59:59Z',
|
|
772
|
+
* });
|
|
773
|
+
* console.log(`Screenshots: ${usage.screenshotsTotal}`);
|
|
774
|
+
* console.log(`Extractions: ${usage.extractionsTotal}`);
|
|
775
|
+
* ```
|
|
776
|
+
*/
|
|
777
|
+
async getUsage(request = {}) {
|
|
778
|
+
const params = new URLSearchParams();
|
|
779
|
+
if (request.environment) params.set("environment", request.environment);
|
|
780
|
+
if (request.periodStart) params.set("periodStart", request.periodStart);
|
|
781
|
+
if (request.periodEnd) params.set("periodEnd", request.periodEnd);
|
|
782
|
+
const query = params.toString();
|
|
783
|
+
const response = await this.http.get(
|
|
784
|
+
`/webdata/usage${query ? `?${query}` : ""}`
|
|
785
|
+
);
|
|
786
|
+
return this.convertUsageDates(response);
|
|
787
|
+
}
|
|
788
|
+
// ==========================================================================
|
|
789
|
+
// BATCH JOBS
|
|
790
|
+
// ==========================================================================
|
|
791
|
+
/**
|
|
792
|
+
* Create a batch screenshot job for multiple URLs
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```typescript
|
|
796
|
+
* const { id, totalUrls } = await webdata.batchScreenshots({
|
|
797
|
+
* urls: [
|
|
798
|
+
* 'https://example.com',
|
|
799
|
+
* 'https://example.org',
|
|
800
|
+
* ],
|
|
801
|
+
* config: { format: 'png', fullPage: true },
|
|
802
|
+
* });
|
|
803
|
+
*
|
|
804
|
+
* // Poll for completion
|
|
805
|
+
* const job = await webdata.getBatchJob({ id });
|
|
806
|
+
* console.log(`Progress: ${job.processedUrls}/${job.totalUrls}`);
|
|
807
|
+
* ```
|
|
808
|
+
*/
|
|
809
|
+
async batchScreenshots(request) {
|
|
810
|
+
return this.http.post("/webdata/batch/screenshots", request);
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Create a batch extraction job for multiple URLs
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```typescript
|
|
817
|
+
* const { id, totalUrls } = await webdata.batchExtractions({
|
|
818
|
+
* urls: [
|
|
819
|
+
* 'https://example.com/article1',
|
|
820
|
+
* 'https://example.com/article2',
|
|
821
|
+
* ],
|
|
822
|
+
* config: { mode: 'markdown' },
|
|
823
|
+
* });
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
async batchExtractions(request) {
|
|
827
|
+
return this.http.post("/webdata/batch/extractions", request);
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Get a batch job by ID
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* ```typescript
|
|
834
|
+
* const job = await webdata.getBatchJob({ id: 'batch-id' });
|
|
835
|
+
* console.log(`Status: ${job.status}`);
|
|
836
|
+
* console.log(`Progress: ${job.processedUrls}/${job.totalUrls}`);
|
|
837
|
+
* ```
|
|
838
|
+
*/
|
|
839
|
+
async getBatchJob(request) {
|
|
840
|
+
const params = new URLSearchParams();
|
|
841
|
+
if (request.environment) params.set("environment", request.environment);
|
|
842
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
843
|
+
const query = params.toString();
|
|
844
|
+
const path = `/webdata/batch/${request.id}${query ? `?${query}` : ""}`;
|
|
845
|
+
const response = await this.http.get(path);
|
|
846
|
+
return this.convertBatchJobDates(response);
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* List batch jobs with pagination and filters
|
|
850
|
+
*
|
|
851
|
+
* @example
|
|
852
|
+
* ```typescript
|
|
853
|
+
* const { items, nextCursor } = await webdata.listBatchJobs({
|
|
854
|
+
* status: 'completed',
|
|
855
|
+
* type: 'screenshot',
|
|
856
|
+
* limit: 20,
|
|
857
|
+
* });
|
|
858
|
+
* ```
|
|
859
|
+
*/
|
|
860
|
+
async listBatchJobs(request = {}) {
|
|
861
|
+
const params = new URLSearchParams();
|
|
862
|
+
if (request.environment) params.set("environment", request.environment);
|
|
863
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
864
|
+
if (request.status) params.set("status", request.status);
|
|
865
|
+
if (request.type) params.set("type", request.type);
|
|
866
|
+
if (request.limit) params.set("limit", request.limit.toString());
|
|
867
|
+
if (request.cursor) params.set("cursor", request.cursor);
|
|
868
|
+
const query = params.toString();
|
|
869
|
+
const response = await this.http.get(
|
|
870
|
+
`/webdata/batch${query ? `?${query}` : ""}`
|
|
871
|
+
);
|
|
872
|
+
return {
|
|
873
|
+
...response,
|
|
874
|
+
items: response.items.map((item) => this.convertBatchJobDates(item))
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Cancel a batch job
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* ```typescript
|
|
882
|
+
* await webdata.cancelBatchJob({ id: 'batch-id' });
|
|
883
|
+
* ```
|
|
884
|
+
*/
|
|
885
|
+
async cancelBatchJob(request) {
|
|
886
|
+
const params = new URLSearchParams();
|
|
887
|
+
if (request.environment) params.set("environment", request.environment);
|
|
888
|
+
if (request.projectId) params.set("projectId", request.projectId);
|
|
889
|
+
const query = params.toString();
|
|
890
|
+
return this.http.post(
|
|
891
|
+
`/webdata/batch/${request.id}/cancel${query ? `?${query}` : ""}`,
|
|
892
|
+
{}
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Create a batch screenshot job and wait for completion
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* ```typescript
|
|
900
|
+
* const job = await webdata.batchScreenshotsAndWait({
|
|
901
|
+
* urls: ['https://example.com', 'https://example.org'],
|
|
902
|
+
* config: { format: 'png' },
|
|
903
|
+
* });
|
|
904
|
+
* console.log(`Completed: ${job.successfulUrls} successful, ${job.failedUrls} failed`);
|
|
905
|
+
* ```
|
|
906
|
+
*/
|
|
907
|
+
async batchScreenshotsAndWait(request, options = {}) {
|
|
908
|
+
const { pollInterval = 2e3, timeout = 3e5 } = options;
|
|
909
|
+
const startTime = Date.now();
|
|
910
|
+
const { id } = await this.batchScreenshots(request);
|
|
911
|
+
while (Date.now() - startTime < timeout) {
|
|
912
|
+
const job = await this.getBatchJob({
|
|
913
|
+
id,
|
|
914
|
+
environment: request.environment,
|
|
915
|
+
projectId: request.projectId
|
|
916
|
+
});
|
|
917
|
+
if (job.status === "completed" || job.status === "failed" || job.status === "cancelled") {
|
|
918
|
+
return job;
|
|
919
|
+
}
|
|
920
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
921
|
+
}
|
|
922
|
+
throw new Error("Batch job timed out");
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Create a batch extraction job and wait for completion
|
|
926
|
+
*
|
|
927
|
+
* @example
|
|
928
|
+
* ```typescript
|
|
929
|
+
* const job = await webdata.batchExtractionsAndWait({
|
|
930
|
+
* urls: ['https://example.com/article1', 'https://example.com/article2'],
|
|
931
|
+
* config: { mode: 'markdown' },
|
|
932
|
+
* });
|
|
933
|
+
* console.log(`Completed: ${job.successfulUrls} successful`);
|
|
934
|
+
* ```
|
|
935
|
+
*/
|
|
936
|
+
async batchExtractionsAndWait(request, options = {}) {
|
|
937
|
+
const { pollInterval = 2e3, timeout = 3e5 } = options;
|
|
938
|
+
const startTime = Date.now();
|
|
939
|
+
const { id } = await this.batchExtractions(request);
|
|
940
|
+
while (Date.now() - startTime < timeout) {
|
|
941
|
+
const job = await this.getBatchJob({
|
|
942
|
+
id,
|
|
943
|
+
environment: request.environment,
|
|
944
|
+
projectId: request.projectId
|
|
945
|
+
});
|
|
946
|
+
if (job.status === "completed" || job.status === "failed" || job.status === "cancelled") {
|
|
947
|
+
return job;
|
|
948
|
+
}
|
|
949
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
950
|
+
}
|
|
951
|
+
throw new Error("Batch job timed out");
|
|
952
|
+
}
|
|
953
|
+
// ==========================================================================
|
|
954
|
+
// HELPERS
|
|
955
|
+
// ==========================================================================
|
|
956
|
+
convertScreenshotDates(screenshot) {
|
|
957
|
+
if (typeof screenshot.createdAt === "string") {
|
|
958
|
+
screenshot.createdAt = new Date(screenshot.createdAt);
|
|
959
|
+
}
|
|
960
|
+
if (screenshot.completedAt && typeof screenshot.completedAt === "string") {
|
|
961
|
+
screenshot.completedAt = new Date(screenshot.completedAt);
|
|
962
|
+
}
|
|
963
|
+
return screenshot;
|
|
964
|
+
}
|
|
965
|
+
convertExtractionDates(extraction) {
|
|
966
|
+
if (typeof extraction.createdAt === "string") {
|
|
967
|
+
extraction.createdAt = new Date(extraction.createdAt);
|
|
968
|
+
}
|
|
969
|
+
if (extraction.completedAt && typeof extraction.completedAt === "string") {
|
|
970
|
+
extraction.completedAt = new Date(extraction.completedAt);
|
|
971
|
+
}
|
|
972
|
+
return extraction;
|
|
973
|
+
}
|
|
974
|
+
convertScheduleDates(schedule) {
|
|
975
|
+
if (typeof schedule.createdAt === "string") {
|
|
976
|
+
schedule.createdAt = new Date(schedule.createdAt);
|
|
977
|
+
}
|
|
978
|
+
if (typeof schedule.updatedAt === "string") {
|
|
979
|
+
schedule.updatedAt = new Date(schedule.updatedAt);
|
|
980
|
+
}
|
|
981
|
+
if (schedule.lastRunAt && typeof schedule.lastRunAt === "string") {
|
|
982
|
+
schedule.lastRunAt = new Date(schedule.lastRunAt);
|
|
983
|
+
}
|
|
984
|
+
if (schedule.nextRunAt && typeof schedule.nextRunAt === "string") {
|
|
985
|
+
schedule.nextRunAt = new Date(schedule.nextRunAt);
|
|
986
|
+
}
|
|
987
|
+
return schedule;
|
|
988
|
+
}
|
|
989
|
+
convertUsageDates(usage) {
|
|
990
|
+
if (typeof usage.periodStart === "string") {
|
|
991
|
+
usage.periodStart = new Date(usage.periodStart);
|
|
992
|
+
}
|
|
993
|
+
if (typeof usage.periodEnd === "string") {
|
|
994
|
+
usage.periodEnd = new Date(usage.periodEnd);
|
|
995
|
+
}
|
|
996
|
+
return usage;
|
|
997
|
+
}
|
|
998
|
+
convertBatchJobDates(job) {
|
|
999
|
+
if (typeof job.createdAt === "string") {
|
|
1000
|
+
job.createdAt = new Date(job.createdAt);
|
|
1001
|
+
}
|
|
1002
|
+
if (job.startedAt && typeof job.startedAt === "string") {
|
|
1003
|
+
job.startedAt = new Date(job.startedAt);
|
|
1004
|
+
}
|
|
1005
|
+
if (job.completedAt && typeof job.completedAt === "string") {
|
|
1006
|
+
job.completedAt = new Date(job.completedAt);
|
|
1007
|
+
}
|
|
1008
|
+
return job;
|
|
1009
|
+
}
|
|
1010
|
+
};
|
|
1011
|
+
|
|
397
1012
|
// src/index.ts
|
|
398
1013
|
var Stack0 = class {
|
|
399
1014
|
mail;
|
|
400
1015
|
cdn;
|
|
1016
|
+
webdata;
|
|
401
1017
|
constructor(config) {
|
|
402
1018
|
const clientConfig = {
|
|
403
1019
|
apiKey: config.apiKey,
|
|
@@ -405,10 +1021,11 @@ var Stack0 = class {
|
|
|
405
1021
|
};
|
|
406
1022
|
this.mail = new Mail(clientConfig);
|
|
407
1023
|
this.cdn = new CDN(clientConfig);
|
|
1024
|
+
this.webdata = new Webdata(clientConfig);
|
|
408
1025
|
}
|
|
409
1026
|
};
|
|
410
1027
|
var src_default = Stack0;
|
|
411
1028
|
|
|
412
|
-
export { CDN, Mail, Stack0, src_default as default };
|
|
1029
|
+
export { CDN, Mail, Stack0, Webdata, src_default as default };
|
|
413
1030
|
//# sourceMappingURL=index.mjs.map
|
|
414
1031
|
//# sourceMappingURL=index.mjs.map
|