@@ -38,6 +38,7 @@ export enum Format {
3838export enum FormatOption {
3939 NO_LINKS = 'no_links' ,
4040 NO_IMAGES = 'no_images' ,
41+ ONLY_CONTENT = 'only_content'
4142}
4243
4344type ScrapeConfigOptions = {
@@ -58,8 +59,8 @@ type ScrapeConfigOptions = {
5859 proxy_pool ?: string ;
5960 session ?: string ;
6061 tags ?: string [ ] ;
61- format ?: Format ;
62- format_options ?: FormatOption [ ] ;
62+ format ?: 'json' | 'text' | 'markdown' | 'clean_html' | 'raw' | Format ;
63+ format_options ?: ( 'no_links' | 'no_images' | 'only_content' | FormatOption ) [ ] ;
6364 correlation_id ?: string ;
6465 cookies ?: Rec < string > ;
6566 body ?: string ;
@@ -69,7 +70,7 @@ type ScrapeConfigOptions = {
6970 rendering_wait ?: number ;
7071 wait_for_selector ?: string ;
7172 screenshots ?: Rec < any > ;
72- screenshot_flags ?: ScreenshotFlags [ ] ;
73+ screenshot_flags ?: ( 'load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags ) [ ] ;
7374 session_sticky_proxy ?: boolean ;
7475 webhook ?: string ;
7576 timeout ?: number ;
@@ -100,8 +101,8 @@ export class ScrapeConfig {
100101 proxy_pool ?: string ;
101102 session ?: string ;
102103 tags : Set < string > = new Set < string > ( ) ;
103- format ?: Format ; // raw(unchanged)
104- format_options ?: FormatOption [ ] ;
104+ format ?: 'json' | 'text' | 'markdown' | 'clean_html' | ' raw' | Format ;
105+ format_options ?: ( 'no_links' | 'no_images' | 'only_content' | FormatOption ) [ ] ;
105106 correlation_id ?: string ;
106107 cookies ?: Rec < string > ;
107108 body ?: string ;
@@ -112,7 +113,7 @@ export class ScrapeConfig {
112113 wait_for_selector ?: string ;
113114 session_sticky_proxy = false ;
114115 screenshots ?: Rec < any > ;
115- screenshot_flags ?: ScreenshotFlags [ ] ;
116+ screenshot_flags ?: ( 'load_images' | 'dark_mode' | 'block_banners' | 'print_media_format' | 'high_quality' | ScreenshotFlags ) [ ] ;
116117 webhook ?: string ;
117118 timeout ?: number ; // in milliseconds
118119 js_scenario ?: Rec < any > ;
@@ -122,14 +123,21 @@ export class ScrapeConfig {
122123
123124 constructor ( options : ScrapeConfigOptions ) {
124125 this . validateOptions ( options ) ;
125- if ( options . format && ! Object . values ( Format ) . includes ( options . format ) ) {
126- throw new ScrapeConfigError ( `Invalid format param value: ${ options . format } ` ) ;
126+ if ( options . format && ! Object . values ( Format ) . includes ( options . format as Format ) ) {
127+ throw new ScrapeConfigError ( `Invalid Format param value: ${ options . format } ` ) ;
127128 }
128129 this . format = options . format ?? this . format ;
130+ if ( options . format_options ) {
131+ options . format_options . forEach ( ( flag ) => {
132+ if ( ! Object . values ( FormatOption ) . includes ( flag as FormatOption ) ) {
133+ throw new ScrapeConfigError ( `Invalid FormatOption param value: ${ flag } ` ) ;
134+ }
135+ } ) ;
136+ }
129137 if ( options . screenshot_flags ) {
130138 options . screenshot_flags . forEach ( ( flag ) => {
131- if ( ! Object . values ( ScreenshotFlags ) . includes ( flag ) ) {
132- throw new ScrapeConfigError ( `Invalid screenshot_flags param value: ${ flag } ` ) ;
139+ if ( ! Object . values ( ScreenshotFlags ) . includes ( flag as ScreenshotFlags ) ) {
140+ throw new ScrapeConfigError ( `Invalid ScreenshotFlags param value: ${ flag } ` ) ;
133141 }
134142 } ) ;
135143 }
0 commit comments