crawlberg 1.12.0 → 1.12.3

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.
@@ -1,5 +1,5 @@
1
1
  // This file is auto-generated by alef. DO NOT EDIT.
2
- // alef:hash:582ed106e4be9129fdfae3b203c9f9ccb338efae1989ad0fdde9d99890d81bd7
2
+ // alef:hash:5766b3fb05a187f88eec0ae0ee3c5e32d6bede7f1a3bc38b4305587073983bbd
3
3
  // Re-generate with: alef generate
4
4
  #![allow(dead_code, unused_imports, unused_variables)]
5
5
  #![allow(
@@ -845,6 +845,7 @@ pub struct BrowserConfig {
845
845
  chrome_args: Vec<String>,
846
846
  scroll_containers: bool,
847
847
  dom_quiet_window: u64,
848
+ dom_quiet_cap: u64,
848
849
  }
849
850
 
850
851
  unsafe impl IntoValueFromNative for BrowserConfig {}
@@ -896,6 +897,7 @@ impl std::fmt::Debug for BrowserConfig {
896
897
  debug.field("chrome_args", &"<redacted>");
897
898
  debug.field("scroll_containers", &self.scroll_containers);
898
899
  debug.field("dom_quiet_window", &self.dom_quiet_window);
900
+ debug.field("dom_quiet_cap", &self.dom_quiet_cap);
899
901
  debug.finish()
900
902
  }
901
903
  }
@@ -1092,6 +1094,15 @@ impl BrowserConfig {
1092
1094
  })?,
1093
1095
  None => 150,
1094
1096
  },
1097
+ dom_quiet_cap: match kwargs.get(ruby.to_symbol("dom_quiet_cap")) {
1098
+ Some(v) => u64::try_convert(v).map_err(|e| {
1099
+ magnus::Error::new(
1100
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1101
+ format!("invalid value for `dom_quiet_cap`: {}", e),
1102
+ )
1103
+ })?,
1104
+ None => 4000,
1105
+ },
1095
1106
  })
1096
1107
  }
1097
1108
 
@@ -1170,6 +1181,10 @@ impl BrowserConfig {
1170
1181
  fn dom_quiet_window(&self) -> u64 {
1171
1182
  self.dom_quiet_window.clone()
1172
1183
  }
1184
+
1185
+ fn dom_quiet_cap(&self) -> u64 {
1186
+ self.dom_quiet_cap.clone()
1187
+ }
1173
1188
  }
1174
1189
 
1175
1190
  #[derive(Clone, Debug, serde::Serialize)]
@@ -1474,6 +1489,10 @@ pub struct ContentConfig {
1474
1489
  compact_tables: bool,
1475
1490
  keep_inline_images_in: Vec<String>,
1476
1491
  keep_hidden: bool,
1492
+ expand_abbreviations: bool,
1493
+ escape_misc: bool,
1494
+ escape_asterisks: bool,
1495
+ include_icon_labels: bool,
1477
1496
  }
1478
1497
 
1479
1498
  unsafe impl IntoValueFromNative for ContentConfig {}
@@ -1705,6 +1724,42 @@ impl ContentConfig {
1705
1724
  })?,
1706
1725
  None => false,
1707
1726
  },
1727
+ expand_abbreviations: match kwargs.get(ruby.to_symbol("expand_abbreviations")) {
1728
+ Some(v) => bool::try_convert(v).map_err(|e| {
1729
+ magnus::Error::new(
1730
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1731
+ format!("invalid value for `expand_abbreviations`: {}", e),
1732
+ )
1733
+ })?,
1734
+ None => true,
1735
+ },
1736
+ escape_misc: match kwargs.get(ruby.to_symbol("escape_misc")) {
1737
+ Some(v) => bool::try_convert(v).map_err(|e| {
1738
+ magnus::Error::new(
1739
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1740
+ format!("invalid value for `escape_misc`: {}", e),
1741
+ )
1742
+ })?,
1743
+ None => false,
1744
+ },
1745
+ escape_asterisks: match kwargs.get(ruby.to_symbol("escape_asterisks")) {
1746
+ Some(v) => bool::try_convert(v).map_err(|e| {
1747
+ magnus::Error::new(
1748
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1749
+ format!("invalid value for `escape_asterisks`: {}", e),
1750
+ )
1751
+ })?,
1752
+ None => false,
1753
+ },
1754
+ include_icon_labels: match kwargs.get(ruby.to_symbol("include_icon_labels")) {
1755
+ Some(v) => bool::try_convert(v).map_err(|e| {
1756
+ magnus::Error::new(
1757
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
1758
+ format!("invalid value for `include_icon_labels`: {}", e),
1759
+ )
1760
+ })?,
1761
+ None => true,
1762
+ },
1708
1763
  })
1709
1764
  }
1710
1765
 
@@ -1787,6 +1842,22 @@ impl ContentConfig {
1787
1842
  fn keep_hidden(&self) -> bool {
1788
1843
  self.keep_hidden
1789
1844
  }
1845
+
1846
+ fn expand_abbreviations(&self) -> bool {
1847
+ self.expand_abbreviations
1848
+ }
1849
+
1850
+ fn escape_misc(&self) -> bool {
1851
+ self.escape_misc
1852
+ }
1853
+
1854
+ fn escape_asterisks(&self) -> bool {
1855
+ self.escape_asterisks
1856
+ }
1857
+
1858
+ fn include_icon_labels(&self) -> bool {
1859
+ self.include_icon_labels
1860
+ }
1790
1861
  }
1791
1862
 
1792
1863
  #[derive(Clone, serde::Serialize, serde::Deserialize)]
@@ -1967,6 +2038,7 @@ pub struct CrawlConfig {
1967
2038
  ssrf: SsrfPolicy,
1968
2039
  ssrf_deny_private_explicit: Option<bool>,
1969
2040
  danger_accept_invalid_certs: bool,
2041
+ subdomain_header_allowlist: Vec<String>,
1970
2042
  }
1971
2043
 
1972
2044
  unsafe impl IntoValueFromNative for CrawlConfig {}
@@ -2055,6 +2127,7 @@ impl std::fmt::Debug for CrawlConfig {
2055
2127
  debug.field("ssrf", &self.ssrf);
2056
2128
  debug.field("ssrf_deny_private_explicit", &self.ssrf_deny_private_explicit);
2057
2129
  debug.field("danger_accept_invalid_certs", &self.danger_accept_invalid_certs);
2130
+ debug.field("subdomain_header_allowlist", &self.subdomain_header_allowlist);
2058
2131
  debug.finish()
2059
2132
  }
2060
2133
  }
@@ -2590,6 +2663,15 @@ impl CrawlConfig {
2590
2663
  })?,
2591
2664
  None => false,
2592
2665
  },
2666
+ subdomain_header_allowlist: match kwargs.get(ruby.to_symbol("subdomain_header_allowlist")) {
2667
+ Some(v) => <Vec<String>>::try_convert(v).map_err(|e| {
2668
+ magnus::Error::new(
2669
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
2670
+ format!("invalid value for `subdomain_header_allowlist`: {}", e),
2671
+ )
2672
+ })?,
2673
+ None => Default::default(),
2674
+ },
2593
2675
  })
2594
2676
  }
2595
2677
 
@@ -2817,6 +2899,10 @@ impl CrawlConfig {
2817
2899
  self.danger_accept_invalid_certs
2818
2900
  }
2819
2901
 
2902
+ fn subdomain_header_allowlist(&self) -> Vec<String> {
2903
+ self.subdomain_header_allowlist.clone()
2904
+ }
2905
+
2820
2906
  fn validate(&self) -> Result<(), Error> {
2821
2907
  #[allow(clippy::needless_update)]
2822
2908
  let core_self = crawlberg::CrawlConfig {
@@ -2937,14 +3023,11 @@ impl CrawlConfig {
2937
3023
 
2938
3024
  danger_accept_invalid_certs: self.danger_accept_invalid_certs,
2939
3025
 
3026
+ subdomain_header_allowlist: self.subdomain_header_allowlist.clone(),
3027
+
2940
3028
  ..Default::default()
2941
3029
  };
2942
- let result = core_self.validate().map_err(|e| {
2943
- magnus::Error::new(
2944
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
2945
- e.to_string(),
2946
- )
2947
- })?;
3030
+ let result = core_self.validate().map_err(alef_magnus_err)?;
2948
3031
  Ok(result)
2949
3032
  }
2950
3033
  }
@@ -2995,12 +3078,7 @@ impl CrawlEngineHandle {
2995
3078
  );
2996
3079
  let stream = runtime
2997
3080
  .block_on(async { inner.crawl_stream(core_req).await })
2998
- .map_err(|e| {
2999
- magnus::Error::new(
3000
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
3001
- e.to_string(),
3002
- )
3003
- })?;
3081
+ .map_err(alef_magnus_err)?;
3004
3082
  let iterator = CrawlStreamIterator {
3005
3083
  inner: Arc::new(tokio::sync::Mutex::new(Some(stream))),
3006
3084
  runtime,
@@ -3040,12 +3118,7 @@ impl CrawlEngineHandle {
3040
3118
  );
3041
3119
  let stream = runtime
3042
3120
  .block_on(async { inner.batch_crawl_stream(core_req).await })
3043
- .map_err(|e| {
3044
- magnus::Error::new(
3045
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
3046
- e.to_string(),
3047
- )
3048
- })?;
3121
+ .map_err(alef_magnus_err)?;
3049
3122
  let iterator = BatchCrawlStreamIterator {
3050
3123
  inner: Arc::new(tokio::sync::Mutex::new(Some(stream))),
3051
3124
  runtime,
@@ -7776,6 +7849,8 @@ pub enum PageAction {
7776
7849
  selector: Option<String>,
7777
7850
  },
7778
7851
  Screenshot {
7852
+ #[serde(rename = "fullPage")]
7853
+ #[serde(alias = "full_page")]
7779
7854
  full_page: Option<bool>,
7780
7855
  },
7781
7856
  #[serde(rename = "executeJs")]
@@ -7899,11 +7974,11 @@ fn batch_crawl(engine: CrawlEngineHandle, urls: Vec<String>) -> Result<BatchCraw
7899
7974
  .enable_all()
7900
7975
  .build()
7901
7976
  .map_err(|e| e.to_string())?;
7902
- rt.block_on(async { crawlberg::batch_crawl(&engine.inner, urls).await })
7903
- .map_err(|e| e.to_string())
7977
+ Ok(rt.block_on(async { crawlberg::batch_crawl(&engine.inner, urls).await }))
7904
7978
  });
7905
7979
  let result = async_result
7906
7980
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
7981
+ let result = result.map_err(alef_magnus_err)?;
7907
7982
  Ok(result.into())
7908
7983
  }
7909
7984
 
@@ -7913,11 +7988,11 @@ fn batch_crawl_async(engine: CrawlEngineHandle, urls: Vec<String>) -> Result<Bat
7913
7988
  .enable_all()
7914
7989
  .build()
7915
7990
  .map_err(|e| e.to_string())?;
7916
- rt.block_on(async { crawlberg::batch_crawl(&engine.inner, urls).await })
7917
- .map_err(|e| e.to_string())
7991
+ Ok(rt.block_on(async { crawlberg::batch_crawl(&engine.inner, urls).await }))
7918
7992
  });
7919
7993
  let result = async_result
7920
7994
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
7995
+ let result = result.map_err(alef_magnus_err)?;
7921
7996
  Ok(result.into())
7922
7997
  }
7923
7998
 
@@ -7927,11 +8002,11 @@ fn batch_scrape(engine: CrawlEngineHandle, urls: Vec<String>) -> Result<BatchScr
7927
8002
  .enable_all()
7928
8003
  .build()
7929
8004
  .map_err(|e| e.to_string())?;
7930
- rt.block_on(async { crawlberg::batch_scrape(&engine.inner, urls).await })
7931
- .map_err(|e| e.to_string())
8005
+ Ok(rt.block_on(async { crawlberg::batch_scrape(&engine.inner, urls).await }))
7932
8006
  });
7933
8007
  let result = async_result
7934
8008
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8009
+ let result = result.map_err(alef_magnus_err)?;
7935
8010
  Ok(result.into())
7936
8011
  }
7937
8012
 
@@ -7941,11 +8016,11 @@ fn batch_scrape_async(engine: CrawlEngineHandle, urls: Vec<String>) -> Result<Ba
7941
8016
  .enable_all()
7942
8017
  .build()
7943
8018
  .map_err(|e| e.to_string())?;
7944
- rt.block_on(async { crawlberg::batch_scrape(&engine.inner, urls).await })
7945
- .map_err(|e| e.to_string())
8019
+ Ok(rt.block_on(async { crawlberg::batch_scrape(&engine.inner, urls).await }))
7946
8020
  });
7947
8021
  let result = async_result
7948
8022
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8023
+ let result = result.map_err(alef_magnus_err)?;
7949
8024
  Ok(result.into())
7950
8025
  }
7951
8026
 
@@ -7955,11 +8030,11 @@ fn crawl(engine: CrawlEngineHandle, url: String) -> Result<CrawlResult, Error> {
7955
8030
  .enable_all()
7956
8031
  .build()
7957
8032
  .map_err(|e| e.to_string())?;
7958
- rt.block_on(async { crawlberg::crawl(&engine.inner, &url).await })
7959
- .map_err(|e| e.to_string())
8033
+ Ok(rt.block_on(async { crawlberg::crawl(&engine.inner, &url).await }))
7960
8034
  });
7961
8035
  let result = async_result
7962
8036
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8037
+ let result = result.map_err(alef_magnus_err)?;
7963
8038
  Ok(result.into())
7964
8039
  }
7965
8040
 
@@ -7969,11 +8044,11 @@ fn crawl_async(engine: CrawlEngineHandle, url: String) -> Result<CrawlResult, Er
7969
8044
  .enable_all()
7970
8045
  .build()
7971
8046
  .map_err(|e| e.to_string())?;
7972
- rt.block_on(async { crawlberg::crawl(&engine.inner, &url).await })
7973
- .map_err(|e| e.to_string())
8047
+ Ok(rt.block_on(async { crawlberg::crawl(&engine.inner, &url).await }))
7974
8048
  });
7975
8049
  let result = async_result
7976
8050
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8051
+ let result = result.map_err(alef_magnus_err)?;
7977
8052
  Ok(result.into())
7978
8053
  }
7979
8054
 
@@ -7990,12 +8065,7 @@ fn create_engine(args: &[magnus::Value]) -> Result<CrawlEngineHandle, Error> {
7990
8065
  }
7991
8066
  _ => None,
7992
8067
  };
7993
- let result = crawlberg::create_engine(config.map(Into::into)).map_err(|e| {
7994
- magnus::Error::new(
7995
- unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
7996
- e.to_string(),
7997
- )
7998
- })?;
8068
+ let result = crawlberg::create_engine(config.map(Into::into)).map_err(alef_magnus_err)?;
7999
8069
  Ok(CrawlEngineHandle {
8000
8070
  inner: Arc::new(result),
8001
8071
  })
@@ -8012,11 +8082,11 @@ fn interact(engine: CrawlEngineHandle, url: String, actions: Vec<PageAction>) ->
8012
8082
  .enable_all()
8013
8083
  .build()
8014
8084
  .map_err(|e| e.to_string())?;
8015
- rt.block_on(async { crawlberg::interact(&engine.inner, &url, actions_core).await })
8016
- .map_err(|e| e.to_string())
8085
+ Ok(rt.block_on(async { crawlberg::interact(&engine.inner, &url, actions_core).await }))
8017
8086
  });
8018
8087
  let result = async_result
8019
8088
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8089
+ let result = result.map_err(alef_magnus_err)?;
8020
8090
  Ok(result.into())
8021
8091
  }
8022
8092
 
@@ -8031,11 +8101,11 @@ fn interact_async(
8031
8101
  .enable_all()
8032
8102
  .build()
8033
8103
  .map_err(|e| e.to_string())?;
8034
- rt.block_on(async { crawlberg::interact(&engine.inner, &url, actions_core).await })
8035
- .map_err(|e| e.to_string())
8104
+ Ok(rt.block_on(async { crawlberg::interact(&engine.inner, &url, actions_core).await }))
8036
8105
  });
8037
8106
  let result = async_result
8038
8107
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8108
+ let result = result.map_err(alef_magnus_err)?;
8039
8109
  Ok(result.into())
8040
8110
  }
8041
8111
 
@@ -8045,11 +8115,11 @@ fn map_urls(engine: CrawlEngineHandle, url: String) -> Result<MapResult, Error>
8045
8115
  .enable_all()
8046
8116
  .build()
8047
8117
  .map_err(|e| e.to_string())?;
8048
- rt.block_on(async { crawlberg::map_urls(&engine.inner, &url).await })
8049
- .map_err(|e| e.to_string())
8118
+ Ok(rt.block_on(async { crawlberg::map_urls(&engine.inner, &url).await }))
8050
8119
  });
8051
8120
  let result = async_result
8052
8121
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8122
+ let result = result.map_err(alef_magnus_err)?;
8053
8123
  Ok(result.into())
8054
8124
  }
8055
8125
 
@@ -8059,11 +8129,11 @@ fn map_urls_async(engine: CrawlEngineHandle, url: String) -> Result<MapResult, E
8059
8129
  .enable_all()
8060
8130
  .build()
8061
8131
  .map_err(|e| e.to_string())?;
8062
- rt.block_on(async { crawlberg::map_urls(&engine.inner, &url).await })
8063
- .map_err(|e| e.to_string())
8132
+ Ok(rt.block_on(async { crawlberg::map_urls(&engine.inner, &url).await }))
8064
8133
  });
8065
8134
  let result = async_result
8066
8135
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8136
+ let result = result.map_err(alef_magnus_err)?;
8067
8137
  Ok(result.into())
8068
8138
  }
8069
8139
 
@@ -8073,11 +8143,11 @@ fn scrape(engine: CrawlEngineHandle, url: String) -> Result<ScrapeResult, Error>
8073
8143
  .enable_all()
8074
8144
  .build()
8075
8145
  .map_err(|e| e.to_string())?;
8076
- rt.block_on(async { crawlberg::scrape(&engine.inner, &url).await })
8077
- .map_err(|e| e.to_string())
8146
+ Ok(rt.block_on(async { crawlberg::scrape(&engine.inner, &url).await }))
8078
8147
  });
8079
8148
  let result = async_result
8080
8149
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8150
+ let result = result.map_err(alef_magnus_err)?;
8081
8151
  Ok(result.into())
8082
8152
  }
8083
8153
 
@@ -8087,11 +8157,11 @@ fn scrape_async(engine: CrawlEngineHandle, url: String) -> Result<ScrapeResult,
8087
8157
  .enable_all()
8088
8158
  .build()
8089
8159
  .map_err(|e| e.to_string())?;
8090
- rt.block_on(async { crawlberg::scrape(&engine.inner, &url).await })
8091
- .map_err(|e| e.to_string())
8160
+ Ok(rt.block_on(async { crawlberg::scrape(&engine.inner, &url).await }))
8092
8161
  });
8093
8162
  let result = async_result
8094
8163
  .map_err(|message| magnus::Error::new(unsafe { Ruby::get_unchecked() }.exception_runtime_error(), message))?;
8164
+ let result = result.map_err(alef_magnus_err)?;
8095
8165
  Ok(result.into())
8096
8166
  }
8097
8167
 
@@ -8302,6 +8372,7 @@ impl From<BrowserConfig> for crawlberg::BrowserConfig {
8302
8372
  chrome_args: val.chrome_args.into_iter().collect(),
8303
8373
  scroll_containers: val.scroll_containers,
8304
8374
  dom_quiet_window: std::time::Duration::from_millis(val.dom_quiet_window),
8375
+ dom_quiet_cap: std::time::Duration::from_millis(val.dom_quiet_cap),
8305
8376
  ..Default::default()
8306
8377
  }
8307
8378
  }
@@ -8330,6 +8401,7 @@ impl From<crawlberg::BrowserConfig> for BrowserConfig {
8330
8401
  chrome_args: val.chrome_args.into_iter().collect(),
8331
8402
  scroll_containers: val.scroll_containers,
8332
8403
  dom_quiet_window: val.dom_quiet_window.as_millis() as u64,
8404
+ dom_quiet_cap: val.dom_quiet_cap.as_millis() as u64,
8333
8405
  }
8334
8406
  }
8335
8407
  }
@@ -8426,6 +8498,10 @@ impl From<ContentConfig> for crawlberg::ContentConfig {
8426
8498
  compact_tables: val.compact_tables,
8427
8499
  keep_inline_images_in: val.keep_inline_images_in.into_iter().collect(),
8428
8500
  keep_hidden: val.keep_hidden,
8501
+ expand_abbreviations: val.expand_abbreviations,
8502
+ escape_misc: val.escape_misc,
8503
+ escape_asterisks: val.escape_asterisks,
8504
+ include_icon_labels: val.include_icon_labels,
8429
8505
  ..Default::default()
8430
8506
  }
8431
8507
  }
@@ -8454,6 +8530,10 @@ impl From<crawlberg::ContentConfig> for ContentConfig {
8454
8530
  compact_tables: val.compact_tables,
8455
8531
  keep_inline_images_in: val.keep_inline_images_in.into_iter().collect(),
8456
8532
  keep_hidden: val.keep_hidden,
8533
+ expand_abbreviations: val.expand_abbreviations,
8534
+ escape_misc: val.escape_misc,
8535
+ escape_asterisks: val.escape_asterisks,
8536
+ include_icon_labels: val.include_icon_labels,
8457
8537
  }
8458
8538
  }
8459
8539
  }
@@ -8548,6 +8628,7 @@ impl From<CrawlConfig> for crawlberg::CrawlConfig {
8548
8628
  ssrf: val.ssrf.into(),
8549
8629
  ssrf_deny_private_explicit: val.ssrf_deny_private_explicit,
8550
8630
  danger_accept_invalid_certs: val.danger_accept_invalid_certs,
8631
+ subdomain_header_allowlist: val.subdomain_header_allowlist.into_iter().collect(),
8551
8632
  ..Default::default()
8552
8633
  }
8553
8634
  }
@@ -8617,6 +8698,7 @@ impl From<crawlberg::CrawlConfig> for CrawlConfig {
8617
8698
  ssrf: val.ssrf.into(),
8618
8699
  ssrf_deny_private_explicit: val.ssrf_deny_private_explicit,
8619
8700
  danger_accept_invalid_certs: val.danger_accept_invalid_certs,
8701
+ subdomain_header_allowlist: val.subdomain_header_allowlist.into_iter().collect(),
8620
8702
  }
8621
8703
  }
8622
8704
  }
@@ -9765,18 +9847,92 @@ impl From<crawlberg::ScrollDirection> for ScrollDirection {
9765
9847
  }
9766
9848
  }
9767
9849
 
9768
- /// Convert a `crawlberg::CrawlError` error to a Magnus runtime error.
9850
+ /// Convert the error a core call returned into the typed Ruby exception of its family. An error
9851
+ /// of a type with no converter becomes a `RuntimeError` with the message.
9852
+ #[allow(dead_code)]
9853
+ fn alef_magnus_err<E: std::fmt::Display + 'static>(e: E) -> magnus::Error {
9854
+ let message = e.to_string();
9855
+ #[allow(unused_variables)]
9856
+ let any: Box<dyn std::any::Any> = Box::new(e);
9857
+ let any = match any.downcast::<crawlberg::CrawlError>() {
9858
+ Ok(typed) => return crawl_error_to_magnus_err(*typed),
9859
+ Err(any) => any,
9860
+ };
9861
+ let any = match any.downcast::<crawlberg::SsrfError>() {
9862
+ Ok(typed) => return ssrf_error_to_magnus_err(*typed),
9863
+ Err(any) => any,
9864
+ };
9865
+ let _ = any;
9866
+ magnus::Error::new(
9867
+ unsafe { magnus::Ruby::get_unchecked() }.exception_runtime_error(),
9868
+ message,
9869
+ )
9870
+ }
9871
+
9872
+ /// Convert a `crawlberg::CrawlError` error to a typed Ruby exception.
9769
9873
  #[allow(dead_code)]
9770
9874
  fn crawl_error_to_magnus_err(e: crawlberg::CrawlError) -> magnus::Error {
9771
- let msg = e.to_string();
9772
- magnus::Error::new(unsafe { magnus::Ruby::get_unchecked() }.exception_runtime_error(), msg)
9875
+ use magnus::prelude::*;
9876
+ let message = e.to_string();
9877
+ let ruby = unsafe { magnus::Ruby::get_unchecked() };
9878
+ #[allow(unreachable_patterns)]
9879
+ let class_name = match &e {
9880
+ crawlberg::CrawlError::NotFound { .. } => "NotFoundError",
9881
+ crawlberg::CrawlError::Unauthorized { .. } => "UnauthorizedError",
9882
+ crawlberg::CrawlError::Forbidden { .. } => "ForbiddenError",
9883
+ crawlberg::CrawlError::WafBlocked { .. } => "WafBlockedError",
9884
+ crawlberg::CrawlError::Timeout { .. } => "CrawlTimeoutError",
9885
+ crawlberg::CrawlError::RateLimited { .. } => "RateLimitedError",
9886
+ crawlberg::CrawlError::ServerError { .. } => "ServerError",
9887
+ crawlberg::CrawlError::BadGateway { .. } => "BadGatewayError",
9888
+ crawlberg::CrawlError::Gone { .. } => "GoneError",
9889
+ crawlberg::CrawlError::Connection { .. } => "CrawlConnectionError",
9890
+ crawlberg::CrawlError::Dns { .. } => "DnsError",
9891
+ crawlberg::CrawlError::Ssl { .. } => "SslError",
9892
+ crawlberg::CrawlError::DataLoss { .. } => "DataLossError",
9893
+ crawlberg::CrawlError::ConversionFailed { .. } => "ConversionFailedError",
9894
+ crawlberg::CrawlError::BrowserError { .. } => "BrowserError",
9895
+ crawlberg::CrawlError::BrowserTimeout { .. } => "BrowserTimeoutError",
9896
+ crawlberg::CrawlError::InvalidConfig { .. } => "InvalidConfigError",
9897
+ crawlberg::CrawlError::Unsupported { .. } => "UnsupportedError",
9898
+ crawlberg::CrawlError::TooManyRedirects { .. } => "TooManyRedirectsError",
9899
+ crawlberg::CrawlError::SsrfPolicyViolation { .. } => "SsrfPolicyViolationError",
9900
+ crawlberg::CrawlError::Other { .. } => "OtherError",
9901
+ _ => "CrawlError",
9902
+ };
9903
+ let build = || -> Result<magnus::Error, magnus::Error> {
9904
+ let module = ruby.define_module("Crawlberg")?;
9905
+ let class: magnus::ExceptionClass = module.const_get(class_name)?;
9906
+ let exception = class.new_instance((message.as_str(),))?;
9907
+ Ok(magnus::Error::from(exception))
9908
+ };
9909
+ build().unwrap_or_else(|_| magnus::Error::new(ruby.exception_runtime_error(), message))
9773
9910
  }
9774
9911
 
9775
- /// Convert a `crawlberg::SsrfError` error to a Magnus runtime error.
9912
+ /// Convert a `crawlberg::SsrfError` error to a typed Ruby exception.
9776
9913
  #[allow(dead_code)]
9777
9914
  fn ssrf_error_to_magnus_err(e: crawlberg::SsrfError) -> magnus::Error {
9778
- let msg = e.to_string();
9779
- magnus::Error::new(unsafe { magnus::Ruby::get_unchecked() }.exception_runtime_error(), msg)
9915
+ use magnus::prelude::*;
9916
+ let message = e.to_string();
9917
+ let ruby = unsafe { magnus::Ruby::get_unchecked() };
9918
+ #[allow(unreachable_patterns)]
9919
+ let class_name = match &e {
9920
+ crawlberg::SsrfError::DeniedByPolicy { .. } => "DeniedByPolicyError",
9921
+ crawlberg::SsrfError::NotOnAllowlist => "NotOnAllowlistError",
9922
+ crawlberg::SsrfError::InvalidCidr(..) => "InvalidCidrError",
9923
+ crawlberg::SsrfError::DnsResolutionFailed(..) => "DnsResolutionFailedError",
9924
+ crawlberg::SsrfError::InvalidUrl(..) => "InvalidUrlError",
9925
+ crawlberg::SsrfError::DisallowedScheme(..) => "DisallowedSchemeError",
9926
+ crawlberg::SsrfError::TooManyRedirects => "TooManyRedirectsError",
9927
+ _ => "SsrfError",
9928
+ };
9929
+ let build = || -> Result<magnus::Error, magnus::Error> {
9930
+ let module = ruby.define_module("Crawlberg")?;
9931
+ let class: magnus::ExceptionClass = module.const_get(class_name)?;
9932
+ let exception = class.new_instance((message.as_str(),))?;
9933
+ Ok(magnus::Error::from(exception))
9934
+ };
9935
+ build().unwrap_or_else(|_| magnus::Error::new(ruby.exception_runtime_error(), message))
9780
9936
  }
9781
9937
 
9782
9938
  #[derive(Clone)]
@@ -9824,7 +9980,7 @@ impl CrawlStreamIterator {
9824
9980
  let binding: CrawlEvent = chunk.into();
9825
9981
  Ok(binding.into_value_with(&ruby))
9826
9982
  }
9827
- Some(Err(e)) => Err(Error::new(ruby.exception_runtime_error(), e.to_string())),
9983
+ Some(Err(e)) => Err(alef_magnus_err(e)),
9828
9984
  None => {
9829
9985
  // Drop the stream to release any resources.
9830
9986
  let inner = self.inner.clone();
@@ -9906,7 +10062,7 @@ impl BatchCrawlStreamIterator {
9906
10062
  let binding: CrawlEvent = chunk.into();
9907
10063
  Ok(binding.into_value_with(&ruby))
9908
10064
  }
9909
- Some(Err(e)) => Err(Error::new(ruby.exception_runtime_error(), e.to_string())),
10065
+ Some(Err(e)) => Err(alef_magnus_err(e)),
9910
10066
  None => {
9911
10067
  // Drop the stream to release any resources.
9912
10068
  let inner = self.inner.clone();
@@ -10075,6 +10231,8 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
10075
10231
 
10076
10232
  class.define_method("dom_quiet_window", method!(BrowserConfig::dom_quiet_window, 0))?;
10077
10233
 
10234
+ class.define_method("dom_quiet_cap", method!(BrowserConfig::dom_quiet_cap, 0))?;
10235
+
10078
10236
  let class = module.define_class("BrowserExtras", ruby.class_object())?;
10079
10237
 
10080
10238
  class.define_singleton_method("new", function!(BrowserExtras::new, -1))?;
@@ -10155,6 +10313,14 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
10155
10313
 
10156
10314
  class.define_method("keep_hidden", method!(ContentConfig::keep_hidden, 0))?;
10157
10315
 
10316
+ class.define_method("expand_abbreviations", method!(ContentConfig::expand_abbreviations, 0))?;
10317
+
10318
+ class.define_method("escape_misc", method!(ContentConfig::escape_misc, 0))?;
10319
+
10320
+ class.define_method("escape_asterisks", method!(ContentConfig::escape_asterisks, 0))?;
10321
+
10322
+ class.define_method("include_icon_labels", method!(ContentConfig::include_icon_labels, 0))?;
10323
+
10158
10324
  let class = module.define_class("CookieInfo", ruby.class_object())?;
10159
10325
 
10160
10326
  class.define_singleton_method("new", function!(CookieInfo::new, -1))?;
@@ -10304,6 +10470,11 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
10304
10470
  method!(CrawlConfig::danger_accept_invalid_certs, 0),
10305
10471
  )?;
10306
10472
 
10473
+ class.define_method(
10474
+ "subdomain_header_allowlist",
10475
+ method!(CrawlConfig::subdomain_header_allowlist, 0),
10476
+ )?;
10477
+
10307
10478
  class.define_method("validate", method!(CrawlConfig::validate, 0))?;
10308
10479
 
10309
10480
  let class = module.define_class("CrawlEngineHandle", ruby.class_object())?;
@@ -10819,5 +10990,35 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
10819
10990
 
10820
10991
  module.define_module_function("batch_crawl_stream", function!(batch_crawl_stream, 2))?;
10821
10992
 
10993
+ let crawl_error_class = module.define_error("CrawlError", ruby.exception_standard_error())?;
10994
+ let not_found_error_class = module.define_error("NotFoundError", crawl_error_class)?;
10995
+ let unauthorized_error_class = module.define_error("UnauthorizedError", crawl_error_class)?;
10996
+ let forbidden_error_class = module.define_error("ForbiddenError", crawl_error_class)?;
10997
+ let waf_blocked_error_class = module.define_error("WafBlockedError", crawl_error_class)?;
10998
+ let crawl_timeout_error_class = module.define_error("CrawlTimeoutError", crawl_error_class)?;
10999
+ let rate_limited_error_class = module.define_error("RateLimitedError", crawl_error_class)?;
11000
+ let server_error_class = module.define_error("ServerError", crawl_error_class)?;
11001
+ let bad_gateway_error_class = module.define_error("BadGatewayError", crawl_error_class)?;
11002
+ let gone_error_class = module.define_error("GoneError", crawl_error_class)?;
11003
+ let crawl_connection_error_class = module.define_error("CrawlConnectionError", crawl_error_class)?;
11004
+ let dns_error_class = module.define_error("DnsError", crawl_error_class)?;
11005
+ let ssl_error_class = module.define_error("SslError", crawl_error_class)?;
11006
+ let data_loss_error_class = module.define_error("DataLossError", crawl_error_class)?;
11007
+ let conversion_failed_error_class = module.define_error("ConversionFailedError", crawl_error_class)?;
11008
+ let browser_error_class = module.define_error("BrowserError", crawl_error_class)?;
11009
+ let browser_timeout_error_class = module.define_error("BrowserTimeoutError", crawl_error_class)?;
11010
+ let invalid_config_error_class = module.define_error("InvalidConfigError", crawl_error_class)?;
11011
+ let unsupported_error_class = module.define_error("UnsupportedError", crawl_error_class)?;
11012
+ let ssrf_policy_violation_error_class = module.define_error("SsrfPolicyViolationError", crawl_error_class)?;
11013
+ let other_error_class = module.define_error("OtherError", crawl_error_class)?;
11014
+ let ssrf_error_class = module.define_error("SsrfError", crawl_error_class)?;
11015
+ let denied_by_policy_error_class = module.define_error("DeniedByPolicyError", ssrf_error_class)?;
11016
+ let not_on_allowlist_error_class = module.define_error("NotOnAllowlistError", ssrf_error_class)?;
11017
+ let invalid_cidr_error_class = module.define_error("InvalidCidrError", ssrf_error_class)?;
11018
+ let dns_resolution_failed_error_class = module.define_error("DnsResolutionFailedError", ssrf_error_class)?;
11019
+ let invalid_url_error_class = module.define_error("InvalidUrlError", ssrf_error_class)?;
11020
+ let disallowed_scheme_error_class = module.define_error("DisallowedSchemeError", ssrf_error_class)?;
11021
+ let too_many_redirects_error_class = module.define_error("TooManyRedirectsError", ssrf_error_class)?;
11022
+
10822
11023
  Ok(())
10823
11024
  }
@@ -1,10 +1,10 @@
1
1
  # This file is auto-generated by alef — DO NOT EDIT.
2
- # alef:hash:ed92ed554ddf1dcb4d5a619d4a13d01d9287c96310437df1c7a4c484d27b969c
2
+ # alef:hash:4b49e60e4c3bdd958dfccc4aee6deec2a78c41bafced6ee25ec8b66aa0b049ca
3
3
  # To regenerate: alef generate
4
4
  # To verify freshness: alef verify
5
5
  # frozen_string_literal: true
6
6
 
7
7
  module Crawlberg
8
8
  ## The version string for this package.
9
- VERSION = "1.12.0"
9
+ VERSION = "1.12.3"
10
10
  end