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