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