diff --git a/src/__tests__/commands/scrape.test.ts b/src/__tests__/commands/scrape.test.ts index 865cad186b..bf3c13b4b2 100644 --- a/src/__tests__/commands/scrape.test.ts +++ b/src/__tests__/commands/scrape.test.ts @@ -219,6 +219,21 @@ describe('executeScrape', () => { excludeTags: ['nav'], }); }); + + it('should include maxAge parameter when provided', async () => { + const mockResponse = { markdown: '# Test' }; + mockClient.scrape.mockResolvedValue(mockResponse); + + await executeScrape({ + url: 'https://example.com', + maxAge: 3600, + }); + + expect(mockClient.scrape).toHaveBeenCalledWith('https://example.com', { + formats: ['markdown'], + maxAge: 3600, + }); + }); }); describe('Response handling', () => { diff --git a/src/commands/scrape.ts b/src/commands/scrape.ts index 66314cc2aa..e6192831a2 100644 --- a/src/commands/scrape.ts +++ b/src/commands/scrape.ts @@ -76,6 +76,7 @@ export async function executeScrape( waitFor?: number; includeTags?: string[]; excludeTags?: string[]; + maxAge?: number; } = { formats, }; @@ -96,6 +97,10 @@ export async function executeScrape( scrapeParams.excludeTags = options.excludeTags; } + if (options.maxAge !== undefined) { + scrapeParams.maxAge = options.maxAge; + } + // Execute scrape with timing - only wrap the scrape call in try-catch const requestStartTime = Date.now(); diff --git a/src/index.ts b/src/index.ts index b427ecda1f..f3a571c45f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -120,6 +120,11 @@ function createScrapeCommand(): Command { 'Show request timing and other useful information', false ) + .option( + '--max-age ', + 'Maximum age of cached content in milliseconds', + parseInt + ) .action(async (positionalUrl, positionalFormats, options) => { // Use positional URL if provided, otherwise use --url option const url = positionalUrl || options.url; diff --git a/src/types/scrape.ts b/src/types/scrape.ts index aaff2e1f9d..76411541fb 100644 --- a/src/types/scrape.ts +++ b/src/types/scrape.ts @@ -42,6 +42,8 @@ export interface ScrapeOptions { json?: boolean; /** Show request timing and other useful information */ timing?: boolean; + /** Maximum age of cached content in milliseconds (API-level caching) */ + maxAge?: number; } export interface ScrapeResult { diff --git a/src/utils/options.ts b/src/utils/options.ts index e4bc869679..efed091e27 100644 --- a/src/utils/options.ts +++ b/src/utils/options.ts @@ -90,5 +90,6 @@ export function parseScrapeOptions(options: any): ScrapeOptions { pretty: options.pretty, json: options.json, timing: options.timing, + maxAge: options.maxAge, }; }