@stack0/sdk 0.5.11 → 0.5.12

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.mjs CHANGED
@@ -3665,6 +3665,232 @@ var Webdata = class {
3665
3665
  }
3666
3666
  };
3667
3667
 
3668
+ // src/crawl/client.ts
3669
+ var Crawl$ = class {
3670
+ http;
3671
+ constructor(config) {
3672
+ this.http = new HttpClient(config);
3673
+ }
3674
+ /**
3675
+ * Start a crawl.
3676
+ *
3677
+ * @example
3678
+ * ```typescript
3679
+ * const { id } = await stack0.crawl.start({
3680
+ * url: 'https://docs.example.com',
3681
+ * maxDepth: 3,
3682
+ * maxPages: 200,
3683
+ * formats: ['markdown', 'links'],
3684
+ * });
3685
+ * ```
3686
+ */
3687
+ async start(request) {
3688
+ return this.http.post("/webdata/crawl", request);
3689
+ }
3690
+ /**
3691
+ * Get a crawl by ID. Pass `includePages: true` to include the scraped pages.
3692
+ */
3693
+ async get(request) {
3694
+ const params = new URLSearchParams();
3695
+ if (request.environment) params.set("environment", request.environment);
3696
+ if (request.projectId) params.set("projectId", request.projectId);
3697
+ if (request.includePages) params.set("includePages", "true");
3698
+ const query = params.toString();
3699
+ return this.http.get(`/webdata/crawl/${request.id}${query ? `?${query}` : ""}`);
3700
+ }
3701
+ async list(request = {}) {
3702
+ const params = new URLSearchParams();
3703
+ if (request.environment) params.set("environment", request.environment);
3704
+ if (request.projectId) params.set("projectId", request.projectId);
3705
+ if (request.status) params.set("status", request.status);
3706
+ if (request.url) params.set("url", request.url);
3707
+ if (request.limit) params.set("limit", String(request.limit));
3708
+ if (request.cursor) params.set("cursor", request.cursor);
3709
+ const query = params.toString();
3710
+ return this.http.get(`/webdata/crawl${query ? `?${query}` : ""}`);
3711
+ }
3712
+ async listPages(request) {
3713
+ const params = new URLSearchParams();
3714
+ if (request.environment) params.set("environment", request.environment);
3715
+ if (request.projectId) params.set("projectId", request.projectId);
3716
+ if (request.limit) params.set("limit", String(request.limit));
3717
+ if (request.cursor) params.set("cursor", request.cursor);
3718
+ const query = params.toString();
3719
+ return this.http.get(
3720
+ `/webdata/crawl/${request.crawlId}/pages${query ? `?${query}` : ""}`
3721
+ );
3722
+ }
3723
+ async cancel(request) {
3724
+ return this.http.post(`/webdata/crawl/${request.id}/cancel`, {
3725
+ environment: request.environment,
3726
+ projectId: request.projectId
3727
+ });
3728
+ }
3729
+ async delete(request) {
3730
+ const params = new URLSearchParams();
3731
+ if (request.environment) params.set("environment", request.environment);
3732
+ if (request.projectId) params.set("projectId", request.projectId);
3733
+ const query = params.toString();
3734
+ return this.http.deleteWithBody(
3735
+ `/webdata/crawl/${request.id}${query ? `?${query}` : ""}`,
3736
+ request
3737
+ );
3738
+ }
3739
+ /**
3740
+ * Start a crawl and poll until it completes. Returns the full Crawl record
3741
+ * with pages included.
3742
+ */
3743
+ async startAndWait(request, options = {}) {
3744
+ const { pollInterval = 2e3, timeout = 6e5, includePages = true } = options;
3745
+ const { id } = await this.start(request);
3746
+ const start = Date.now();
3747
+ while (Date.now() - start < timeout) {
3748
+ const crawl = await this.get({
3749
+ id,
3750
+ environment: request.environment,
3751
+ projectId: request.projectId,
3752
+ includePages
3753
+ });
3754
+ if (crawl.status === "completed" || crawl.status === "failed" || crawl.status === "cancelled") {
3755
+ if (crawl.status === "failed") throw new Error(crawl.error || "Crawl failed");
3756
+ return crawl;
3757
+ }
3758
+ await new Promise((r) => setTimeout(r, pollInterval));
3759
+ }
3760
+ throw new Error("Crawl timed out");
3761
+ }
3762
+ };
3763
+
3764
+ // src/map/client.ts
3765
+ var Map$ = class {
3766
+ http;
3767
+ constructor(config) {
3768
+ this.http = new HttpClient(config);
3769
+ }
3770
+ /**
3771
+ * Start a map job.
3772
+ *
3773
+ * @example
3774
+ * ```typescript
3775
+ * const { id } = await stack0.map.create({
3776
+ * url: 'https://docs.example.com',
3777
+ * search: 'api',
3778
+ * limit: 1000,
3779
+ * });
3780
+ * ```
3781
+ */
3782
+ async create(request) {
3783
+ return this.http.post("/webdata/map", request);
3784
+ }
3785
+ async get(request) {
3786
+ const params = new URLSearchParams();
3787
+ if (request.environment) params.set("environment", request.environment);
3788
+ if (request.projectId) params.set("projectId", request.projectId);
3789
+ const query = params.toString();
3790
+ return this.http.get(`/webdata/map/${request.id}${query ? `?${query}` : ""}`);
3791
+ }
3792
+ async list(request = {}) {
3793
+ const params = new URLSearchParams();
3794
+ if (request.environment) params.set("environment", request.environment);
3795
+ if (request.projectId) params.set("projectId", request.projectId);
3796
+ if (request.status) params.set("status", request.status);
3797
+ if (request.limit) params.set("limit", String(request.limit));
3798
+ if (request.cursor) params.set("cursor", request.cursor);
3799
+ const query = params.toString();
3800
+ return this.http.get(`/webdata/map${query ? `?${query}` : ""}`);
3801
+ }
3802
+ async delete(request) {
3803
+ const params = new URLSearchParams();
3804
+ if (request.environment) params.set("environment", request.environment);
3805
+ if (request.projectId) params.set("projectId", request.projectId);
3806
+ const query = params.toString();
3807
+ return this.http.deleteWithBody(
3808
+ `/webdata/map/${request.id}${query ? `?${query}` : ""}`,
3809
+ request
3810
+ );
3811
+ }
3812
+ /**
3813
+ * Create a map job and poll until it completes. Maps usually finish in
3814
+ * seconds, so default timeout is generous.
3815
+ */
3816
+ async createAndWait(request, options = {}) {
3817
+ const { pollInterval = 1e3, timeout = 12e4 } = options;
3818
+ const { id } = await this.create(request);
3819
+ const start = Date.now();
3820
+ while (Date.now() - start < timeout) {
3821
+ const result = await this.get({ id, environment: request.environment, projectId: request.projectId });
3822
+ if (result.status === "completed" || result.status === "failed") {
3823
+ if (result.status === "failed") throw new Error(result.error || "Map failed");
3824
+ return result;
3825
+ }
3826
+ await new Promise((r) => setTimeout(r, pollInterval));
3827
+ }
3828
+ throw new Error("Map timed out");
3829
+ }
3830
+ };
3831
+
3832
+ // src/documents/client.ts
3833
+ var Documents = class {
3834
+ http;
3835
+ constructor(config) {
3836
+ this.http = new HttpClient(config);
3837
+ }
3838
+ /**
3839
+ * Parse a document from a URL or a previously-uploaded file URL.
3840
+ *
3841
+ * @example
3842
+ * ```typescript
3843
+ * const { id } = await stack0.documents.parse({
3844
+ * url: 'https://example.com/whitepaper.pdf',
3845
+ * });
3846
+ * ```
3847
+ */
3848
+ async parse(request) {
3849
+ return this.http.post("/webdata/documents", request);
3850
+ }
3851
+ async get(request) {
3852
+ const params = new URLSearchParams();
3853
+ if (request.environment) params.set("environment", request.environment);
3854
+ if (request.projectId) params.set("projectId", request.projectId);
3855
+ const q = params.toString();
3856
+ return this.http.get(`/webdata/documents/${request.id}${q ? `?${q}` : ""}`);
3857
+ }
3858
+ async list(request = {}) {
3859
+ const params = new URLSearchParams();
3860
+ if (request.environment) params.set("environment", request.environment);
3861
+ if (request.projectId) params.set("projectId", request.projectId);
3862
+ if (request.status) params.set("status", request.status);
3863
+ if (request.limit) params.set("limit", String(request.limit));
3864
+ if (request.cursor) params.set("cursor", request.cursor);
3865
+ const q = params.toString();
3866
+ return this.http.get(`/webdata/documents${q ? `?${q}` : ""}`);
3867
+ }
3868
+ async delete(request) {
3869
+ const params = new URLSearchParams();
3870
+ if (request.environment) params.set("environment", request.environment);
3871
+ if (request.projectId) params.set("projectId", request.projectId);
3872
+ const q = params.toString();
3873
+ return this.http.deleteWithBody(
3874
+ `/webdata/documents/${request.id}${q ? `?${q}` : ""}`,
3875
+ request
3876
+ );
3877
+ }
3878
+ async parseAndWait(request, options = {}) {
3879
+ const { pollInterval = 2e3, timeout = 18e4 } = options;
3880
+ const { id } = await this.parse(request);
3881
+ const start = Date.now();
3882
+ while (Date.now() - start < timeout) {
3883
+ const doc = await this.get({ id, environment: request.environment, projectId: request.projectId });
3884
+ if (doc.status === "completed" || doc.status === "failed") {
3885
+ if (doc.status === "failed") throw new Error(doc.error || "Document parsing failed");
3886
+ return doc;
3887
+ }
3888
+ await new Promise((r) => setTimeout(r, pollInterval));
3889
+ }
3890
+ throw new Error("Document parsing timed out");
3891
+ }
3892
+ };
3893
+
3668
3894
  // src/integrations/client.ts
3669
3895
  var CRM = class {
3670
3896
  http;
@@ -5536,10 +5762,14 @@ var Memory = class {
5536
5762
 
5537
5763
  // src/index.ts
5538
5764
  var Stack0 = class {
5765
+ http;
5539
5766
  mail;
5540
5767
  cdn;
5541
5768
  screenshots;
5542
5769
  extraction;
5770
+ crawl;
5771
+ map;
5772
+ documents;
5543
5773
  integrations;
5544
5774
  marketing;
5545
5775
  workflows;
@@ -5553,19 +5783,45 @@ var Stack0 = class {
5553
5783
  apiKey: config.apiKey,
5554
5784
  baseUrl: config.baseUrl
5555
5785
  };
5786
+ this.http = new HttpClient(clientConfig);
5556
5787
  this.mail = new Mail(clientConfig);
5557
5788
  this.cdn = new CDN(clientConfig, config.cdnUrl);
5558
5789
  this.screenshots = new Screenshots(clientConfig);
5559
5790
  this.extraction = new Extraction(clientConfig);
5791
+ this.crawl = new Crawl$(clientConfig);
5792
+ this.map = new Map$(clientConfig);
5793
+ this.documents = new Documents(clientConfig);
5560
5794
  this.integrations = new Integrations(clientConfig);
5561
5795
  this.marketing = new Marketing(clientConfig);
5562
5796
  this.workflows = new Workflows(clientConfig);
5563
5797
  this.memory = new Memory(clientConfig);
5564
5798
  this.webdata = new Webdata(clientConfig);
5565
5799
  }
5800
+ // ============================================================================
5801
+ // PROJECTS
5802
+ // ============================================================================
5803
+ async listProjects() {
5804
+ return this.http.get("/projects");
5805
+ }
5806
+ async getProject(id) {
5807
+ return this.http.get(`/projects/${id}`);
5808
+ }
5809
+ async getProjectBySlug(slug) {
5810
+ return this.http.get(`/projects/by-slug/${slug}`);
5811
+ }
5812
+ async createProject(request) {
5813
+ return this.http.post("/projects", request);
5814
+ }
5815
+ async updateProject(request) {
5816
+ const { id, ...data } = request;
5817
+ return this.http.patch(`/projects/${id}`, data);
5818
+ }
5819
+ async deleteProject(id) {
5820
+ return this.http.delete(`/projects/${id}`);
5821
+ }
5566
5822
  };
5567
5823
  var src_default = Stack0;
5568
5824
 
5569
- export { Audiences, CDN, Campaigns, Contacts, Domains, Events, Extraction, Integrations, Mail, Mailboxes, Marketing, Memory, MemoryAgents, MemoryCollections, MemoryEntities, Screenshots, Sequences, Stack0, Templates, Webdata, Workflows, src_default as default };
5825
+ export { Audiences, CDN, Campaigns, Contacts, Crawl$ as Crawl, Crawl$, Documents, Domains, Events, Extraction, Integrations, Mail, Mailboxes, Map$ as Map, Map$, Marketing, Memory, MemoryAgents, MemoryCollections, MemoryEntities, Screenshots, Sequences, Stack0, Templates, Webdata, Workflows, src_default as default };
5570
5826
  //# sourceMappingURL=index.mjs.map
5571
5827
  //# sourceMappingURL=index.mjs.map