@dealcrawl/sdk 2.1.3 → 2.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.js CHANGED
@@ -589,6 +589,203 @@ var AccountResource = class {
589
589
  }
590
590
  };
591
591
 
592
+ // src/resources/agent.ts
593
+ var AgentResource = class {
594
+ constructor(ctx) {
595
+ this.ctx = ctx;
596
+ }
597
+ /**
598
+ * Create a new AI agent job
599
+ *
600
+ * @param options - Agent configuration options
601
+ * @returns Job creation response with jobId and status URL
602
+ *
603
+ * @example
604
+ * ```ts
605
+ * const job = await client.agent.create({
606
+ * url: "https://booking.com",
607
+ * prompt: "Find hotels in Paris for 2 adults, March 15-17, sort by price and extract the 3 cheapest options",
608
+ * maxSteps: 20,
609
+ * takeScreenshots: true
610
+ * });
611
+ * ```
612
+ */
613
+ async create(options) {
614
+ const body = {
615
+ url: options.url,
616
+ urls: options.urls,
617
+ prompt: options.prompt,
618
+ schema: options.schema,
619
+ maxSteps: options.maxSteps ?? 10,
620
+ actions: options.actions,
621
+ model: options.model ?? "openai",
622
+ timeout: options.timeout ?? 3e4,
623
+ onlyMainContent: options.onlyMainContent ?? true,
624
+ takeScreenshots: options.takeScreenshots ?? false,
625
+ headers: options.headers,
626
+ webhook: options.webhook
627
+ };
628
+ const result = await post(this.ctx, "/v1/agent", body);
629
+ return result.data;
630
+ }
631
+ /**
632
+ * Get the status of an agent job
633
+ *
634
+ * @param jobId - The job ID to check
635
+ * @returns Agent status with progress and partial results
636
+ *
637
+ * @example
638
+ * ```ts
639
+ * const status = await client.agent.getStatus(jobId);
640
+ * console.log(`Step ${status.partialResult?.steps.length}/${status.totalSteps}`);
641
+ * ```
642
+ */
643
+ async getStatus(jobId) {
644
+ const result = await get(
645
+ this.ctx,
646
+ `/v1/status/${jobId}`
647
+ );
648
+ return result.data;
649
+ }
650
+ /**
651
+ * Create an agent with preset actions
652
+ * Useful for handling common scenarios like cookie consent, popups, etc.
653
+ *
654
+ * @example
655
+ * ```ts
656
+ * const job = await client.agent.withPresetActions(
657
+ * "https://shop.com",
658
+ * "Find the best discount and extract product details",
659
+ * [
660
+ * { type: "click", selector: "#accept-cookies" },
661
+ * { type: "wait", milliseconds: 1000 }
662
+ * ]
663
+ * );
664
+ * ```
665
+ */
666
+ async withPresetActions(url, prompt, actions, options) {
667
+ return this.create({
668
+ url,
669
+ prompt,
670
+ actions,
671
+ ...options
672
+ });
673
+ }
674
+ /**
675
+ * Create an agent with a JSON schema for structured output
676
+ * The agent will extract data matching the provided schema
677
+ *
678
+ * @example
679
+ * ```ts
680
+ * const job = await client.agent.withSchema(
681
+ * "https://linkedin.com/company/example",
682
+ * "Extract company information",
683
+ * {
684
+ * type: "object",
685
+ * properties: {
686
+ * name: { type: "string" },
687
+ * employees: { type: "number" },
688
+ * description: { type: "string" },
689
+ * website: { type: "string" }
690
+ * },
691
+ * required: ["name"]
692
+ * }
693
+ * );
694
+ * ```
695
+ */
696
+ async withSchema(url, prompt, schema, options) {
697
+ return this.create({
698
+ url,
699
+ prompt,
700
+ schema,
701
+ ...options
702
+ });
703
+ }
704
+ /**
705
+ * Create an agent optimized for deal/product extraction
706
+ * Pre-configured for e-commerce scenarios
707
+ *
708
+ * @example
709
+ * ```ts
710
+ * const job = await client.agent.forDeals(
711
+ * "https://slickdeals.net",
712
+ * "Find the top 10 tech deals posted today"
713
+ * );
714
+ * ```
715
+ */
716
+ async forDeals(url, prompt, options) {
717
+ return this.create({
718
+ url,
719
+ prompt: `${prompt}. Extract deal information including: product name, current price, original price (if available), discount percentage, merchant/store, and any promo codes or coupons.`,
720
+ schema: {
721
+ type: "object",
722
+ properties: {
723
+ deals: {
724
+ type: "array",
725
+ items: {
726
+ type: "object",
727
+ properties: {
728
+ productName: { type: "string" },
729
+ currentPrice: { type: "number" },
730
+ originalPrice: { type: "number" },
731
+ discountPercent: { type: "number" },
732
+ merchant: { type: "string" },
733
+ promoCode: { type: "string" },
734
+ url: { type: "string" },
735
+ expiresAt: { type: "string" }
736
+ },
737
+ required: ["productName", "currentPrice"]
738
+ }
739
+ }
740
+ },
741
+ required: ["deals"]
742
+ },
743
+ maxSteps: options?.maxSteps ?? 15,
744
+ ...options
745
+ });
746
+ }
747
+ /**
748
+ * Create an agent to fill and submit a form
749
+ * Useful for search forms, login forms, etc.
750
+ *
751
+ * @example
752
+ * ```ts
753
+ * const job = await client.agent.fillForm(
754
+ * "https://kayak.com",
755
+ * "Search for flights from Paris to New York on March 20, return March 27",
756
+ * { takeScreenshots: true }
757
+ * );
758
+ * ```
759
+ */
760
+ async fillForm(url, instructions, options) {
761
+ return this.create({
762
+ url,
763
+ prompt: `Navigate to the form and ${instructions}. After submitting, extract the results.`,
764
+ maxSteps: options?.maxSteps ?? 12,
765
+ ...options
766
+ });
767
+ }
768
+ /**
769
+ * Create an agent using Claude (Anthropic) instead of GPT
770
+ *
771
+ * @example
772
+ * ```ts
773
+ * const job = await client.agent.withClaude(
774
+ * "https://complex-site.com",
775
+ * "Navigate through the multi-step checkout process"
776
+ * );
777
+ * ```
778
+ */
779
+ async withClaude(url, prompt, options) {
780
+ return this.create({
781
+ url,
782
+ prompt,
783
+ model: "anthropic",
784
+ ...options
785
+ });
786
+ }
787
+ };
788
+
592
789
  // src/resources/crawl.ts
593
790
  var CRAWL_TEMPLATES = {
594
791
  ecommerce: {
@@ -1544,11 +1741,21 @@ var KeysResource = class {
1544
1741
  *
1545
1742
  * @example
1546
1743
  * ```ts
1744
+ * // Simple revoke
1547
1745
  * await client.keys.revoke("key_abc123");
1746
+ *
1747
+ * // With reason
1748
+ * await client.keys.revoke("key_abc123", {
1749
+ * reason: "Key compromised"
1750
+ * });
1548
1751
  * ```
1549
1752
  */
1550
- async revoke(keyId) {
1551
- const result = await del(this.ctx, `/v1/keys/${keyId}`);
1753
+ async revoke(keyId, options = {}) {
1754
+ const result = await del(
1755
+ this.ctx,
1756
+ `/v1/keys/${keyId}`,
1757
+ options.reason ? { reason: options.reason } : void 0
1758
+ );
1552
1759
  return result.data;
1553
1760
  }
1554
1761
  /**
@@ -1624,6 +1831,8 @@ var ScrapeResource = class {
1624
1831
  detectSignals: options.detectSignals ?? true,
1625
1832
  extractWithAI: options.extractWithAI,
1626
1833
  extractDeal: options.extractDeal,
1834
+ extractMultipleDeals: options.extractMultipleDeals,
1835
+ maxDeals: options.maxDeals,
1627
1836
  useAdvancedModel: options.useAdvancedModel,
1628
1837
  minDealScore: options.minDealScore,
1629
1838
  screenshot: options.screenshot,
@@ -1652,6 +1861,25 @@ var ScrapeResource = class {
1652
1861
  ...options
1653
1862
  });
1654
1863
  }
1864
+ /**
1865
+ * Scrape a list page and extract multiple deals
1866
+ * Use for category pages, deal lists, search results
1867
+ *
1868
+ * @example
1869
+ * ```ts
1870
+ * const job = await client.scrape.extractDeals(
1871
+ * "https://amazon.fr/deals",
1872
+ * { maxDeals: 30, useAdvancedModel: true }
1873
+ * );
1874
+ * ```
1875
+ */
1876
+ async extractDeals(url, options) {
1877
+ return this.create({
1878
+ url,
1879
+ extractMultipleDeals: true,
1880
+ ...options
1881
+ });
1882
+ }
1655
1883
  /**
1656
1884
  * Scrape a URL with screenshot capture
1657
1885
  * Convenience method for screenshot capture
@@ -1674,6 +1902,185 @@ var ScrapeResource = class {
1674
1902
  ...options
1675
1903
  });
1676
1904
  }
1905
+ // ============================================
1906
+ // BATCH SCRAPING METHODS
1907
+ // ============================================
1908
+ /**
1909
+ * Create a batch scrape job for multiple URLs
1910
+ * Scrapes 1-100 URLs in a single request
1911
+ *
1912
+ * @example
1913
+ * ```ts
1914
+ * const batch = await client.scrape.batch({
1915
+ * urls: [
1916
+ * { url: "https://shop1.com/product1" },
1917
+ * { url: "https://shop2.com/deal", extractDeal: true }
1918
+ * ],
1919
+ * defaults: { detectSignals: true }
1920
+ * });
1921
+ * console.log(batch.batchId, batch.results);
1922
+ * ```
1923
+ */
1924
+ async batch(options) {
1925
+ const body = {
1926
+ urls: options.urls,
1927
+ defaults: options.defaults,
1928
+ webhookUrl: options.webhookUrl,
1929
+ priority: options.priority,
1930
+ delayMs: options.delay
1931
+ };
1932
+ const result = await post(
1933
+ this.ctx,
1934
+ "/v1/scrape/batch",
1935
+ body
1936
+ );
1937
+ return result.data;
1938
+ }
1939
+ /**
1940
+ * Get status of a batch scrape operation
1941
+ *
1942
+ * @example
1943
+ * ```ts
1944
+ * const status = await client.scrape.getBatchStatus(batchId);
1945
+ * console.log(`Completed: ${status.completed}/${status.total}`);
1946
+ * ```
1947
+ */
1948
+ async getBatchStatus(batchId) {
1949
+ const result = await get(
1950
+ this.ctx,
1951
+ `/v1/scrape/batch/${batchId}`
1952
+ );
1953
+ return result.data;
1954
+ }
1955
+ /**
1956
+ * Batch scrape with deal extraction enabled for all URLs
1957
+ * Convenience method for deal-focused batch scraping
1958
+ *
1959
+ * @example
1960
+ * ```ts
1961
+ * const batch = await client.scrape.batchForDeals([
1962
+ * "https://shop1.com/sale",
1963
+ * "https://shop2.com/deals"
1964
+ * ]);
1965
+ * ```
1966
+ */
1967
+ async batchForDeals(urls, options) {
1968
+ return this.batch({
1969
+ urls: urls.map((url) => ({ url })),
1970
+ defaults: {
1971
+ extractDeal: true,
1972
+ detectSignals: true,
1973
+ ...options?.defaults
1974
+ },
1975
+ ...options
1976
+ });
1977
+ }
1978
+ };
1979
+
1980
+ // src/resources/search.ts
1981
+ var SearchResource = class {
1982
+ constructor(ctx) {
1983
+ this.ctx = ctx;
1984
+ }
1985
+ /**
1986
+ * Create a new search job
1987
+ *
1988
+ * @example
1989
+ * ```ts
1990
+ * const result = await client.search.create({
1991
+ * query: "laptop deals black friday",
1992
+ * maxResults: 20,
1993
+ * useDealScoring: true
1994
+ * });
1995
+ * ```
1996
+ */
1997
+ async create(options) {
1998
+ const body = {
1999
+ query: options.query,
2000
+ limit: options.maxResults,
2001
+ scrapeResults: options.autoScrape,
2002
+ maxScrapeResults: options.autoScrapeLimit,
2003
+ useAiOptimization: options.useAiOptimization,
2004
+ aiProvider: options.aiProvider,
2005
+ aiModel: options.aiModel,
2006
+ useDealScoring: options.useDealScoring,
2007
+ skipCache: options.skipCache,
2008
+ filters: options.filters,
2009
+ webhook: options.webhook
2010
+ };
2011
+ const result = await post(this.ctx, "/v1/search", body);
2012
+ return result.data;
2013
+ }
2014
+ /**
2015
+ * Search with AI query optimization
2016
+ * Convenience method for AI-enhanced searches
2017
+ *
2018
+ * @example
2019
+ * ```ts
2020
+ * const result = await client.search.withAI("iphone discount", {
2021
+ * aiProvider: "openai",
2022
+ * aiModel: "gpt-4o-mini"
2023
+ * });
2024
+ * ```
2025
+ */
2026
+ async withAI(query, options) {
2027
+ return this.create({
2028
+ query,
2029
+ useAiOptimization: true,
2030
+ ...options
2031
+ });
2032
+ }
2033
+ /**
2034
+ * Search with deal scoring enabled
2035
+ * Scores each result for deal relevance (0-100)
2036
+ *
2037
+ * @example
2038
+ * ```ts
2039
+ * const result = await client.search.forDeals("gaming laptop");
2040
+ * ```
2041
+ */
2042
+ async forDeals(query, options) {
2043
+ return this.create({
2044
+ query,
2045
+ useDealScoring: true,
2046
+ ...options
2047
+ });
2048
+ }
2049
+ /**
2050
+ * Search and auto-scrape top results
2051
+ * Creates scrape jobs for the best matching URLs
2052
+ *
2053
+ * @example
2054
+ * ```ts
2055
+ * const result = await client.search.andScrape("promo codes", {
2056
+ * autoScrapeLimit: 5
2057
+ * });
2058
+ * console.log(result.data.scrapedJobIds);
2059
+ * ```
2060
+ */
2061
+ async andScrape(query, options) {
2062
+ return this.create({
2063
+ query,
2064
+ autoScrape: true,
2065
+ ...options
2066
+ });
2067
+ }
2068
+ /**
2069
+ * Check search API status
2070
+ * Returns availability and features info
2071
+ *
2072
+ * @example
2073
+ * ```ts
2074
+ * const status = await client.search.getStatus();
2075
+ * if (status.available) {
2076
+ * console.log(`Provider: ${status.provider}`);
2077
+ * }
2078
+ * ```
2079
+ */
2080
+ async getStatus() {
2081
+ const result = await get(this.ctx, "/v1/search/status");
2082
+ return result.data;
2083
+ }
1677
2084
  };
1678
2085
 
1679
2086
  // src/resources/status.ts
@@ -1995,17 +2402,38 @@ var DealCrawl = class {
1995
2402
  // RESOURCES
1996
2403
  // ============================================
1997
2404
  /**
1998
- * Scrape resource - Single page scraping
2405
+ * Scrape resource - Single page and batch scraping
1999
2406
  *
2000
2407
  * @example
2001
2408
  * ```ts
2409
+ * // Single page
2002
2410
  * const job = await client.scrape.create({
2003
2411
  * url: "https://example.com",
2004
2412
  * extractDeal: true
2005
2413
  * });
2414
+ *
2415
+ * // Batch scraping
2416
+ * const batch = await client.scrape.batch({
2417
+ * urls: [{ url: "https://shop1.com" }, { url: "https://shop2.com" }]
2418
+ * });
2006
2419
  * ```
2007
2420
  */
2008
2421
  scrape;
2422
+ /**
2423
+ * Search resource - Web search with AI optimization
2424
+ *
2425
+ * @example
2426
+ * ```ts
2427
+ * const result = await client.search.create({
2428
+ * query: "laptop deals",
2429
+ * useDealScoring: true
2430
+ * });
2431
+ *
2432
+ * // With AI optimization
2433
+ * const result = await client.search.withAI("iphone discount");
2434
+ * ```
2435
+ */
2436
+ search;
2009
2437
  /**
2010
2438
  * Crawl resource - Website crawling
2011
2439
  *
@@ -2047,6 +2475,29 @@ var DealCrawl = class {
2047
2475
  * ```
2048
2476
  */
2049
2477
  dork;
2478
+ /**
2479
+ * Agent resource - AI-powered autonomous web navigation
2480
+ *
2481
+ * The agent uses ReAct pattern (Observation → Thought → Action → Evaluation)
2482
+ * to navigate web pages and extract structured data based on natural language.
2483
+ *
2484
+ * @example
2485
+ * ```ts
2486
+ * const job = await client.agent.create({
2487
+ * url: "https://amazon.com",
2488
+ * prompt: "Search for wireless headphones under $50 and extract top 5 results",
2489
+ * maxSteps: 15
2490
+ * });
2491
+ *
2492
+ * // With schema for structured output
2493
+ * const job = await client.agent.withSchema(
2494
+ * "https://example.com",
2495
+ * "Extract product info",
2496
+ * { type: "object", properties: {...} }
2497
+ * );
2498
+ * ```
2499
+ */
2500
+ agent;
2050
2501
  /**
2051
2502
  * Status resource - Job status management
2052
2503
  *
@@ -2142,9 +2593,11 @@ var DealCrawl = class {
2142
2593
  onRateLimit: config.onRateLimit
2143
2594
  };
2144
2595
  this.scrape = new ScrapeResource(this.ctx);
2596
+ this.search = new SearchResource(this.ctx);
2145
2597
  this.crawl = new CrawlResource(this.ctx);
2146
2598
  this.extract = new ExtractResource(this.ctx);
2147
2599
  this.dork = new DorkResource(this.ctx);
2600
+ this.agent = new AgentResource(this.ctx);
2148
2601
  this.status = new StatusResource(this.ctx);
2149
2602
  this.data = new DataResource(this.ctx);
2150
2603
  this.webhooks = new WebhooksResource(this.ctx);
@@ -2257,9 +2710,44 @@ var DealCrawl = class {
2257
2710
  const job = await this.extract.create(options);
2258
2711
  return this.waitForResult(job.jobId, waitOptions);
2259
2712
  }
2713
+ /**
2714
+ * Search and return results directly
2715
+ * Note: Search is synchronous, no waiting needed
2716
+ *
2717
+ * @example
2718
+ * ```ts
2719
+ * const result = await client.searchAndWait({
2720
+ * query: "gaming laptop deals",
2721
+ * useDealScoring: true
2722
+ * });
2723
+ * console.log(result.data.results);
2724
+ * ```
2725
+ */
2726
+ async searchAndWait(options) {
2727
+ return this.search.create(options);
2728
+ }
2729
+ /**
2730
+ * Create an agent job and wait for result
2731
+ * Combines create and waitForResult
2732
+ *
2733
+ * @example
2734
+ * ```ts
2735
+ * const result = await client.agentAndWait({
2736
+ * url: "https://booking.com",
2737
+ * prompt: "Find hotels in Paris for March 15-17",
2738
+ * maxSteps: 20
2739
+ * });
2740
+ * console.log(result.data);
2741
+ * ```
2742
+ */
2743
+ async agentAndWait(options, waitOptions) {
2744
+ const job = await this.agent.create(options);
2745
+ return this.waitForResult(job.jobId, waitOptions);
2746
+ }
2260
2747
  };
2261
2748
 
2262
2749
  exports.AccountResource = AccountResource;
2750
+ exports.AgentResource = AgentResource;
2263
2751
  exports.CrawlResource = CrawlResource;
2264
2752
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
2265
2753
  exports.DataResource = DataResource;
@@ -2270,6 +2758,7 @@ exports.ERROR_CODES = ERROR_CODES;
2270
2758
  exports.ExtractResource = ExtractResource;
2271
2759
  exports.KeysResource = KeysResource;
2272
2760
  exports.ScrapeResource = ScrapeResource;
2761
+ exports.SearchResource = SearchResource;
2273
2762
  exports.StatusResource = StatusResource;
2274
2763
  exports.WebhooksResource = WebhooksResource;
2275
2764
  exports.default = DealCrawl;