-
Notifications
You must be signed in to change notification settings - Fork 384
feat(diffbot): add Diffbot plugin with extract and search endpoints #1009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
devjain32
merged 14 commits into
corsairdev:main
from
Shivashankar15:feat/diffbot-plugin
Aug 24, 2026
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aecf8f5
feat(diffbot): add Diffbot plugin with extract and search endpoints
Shivashankar15 e5f5b5a
test(diffbot): add endpoint schema tests for all 5 endpoints (22 asse…
Shivashankar15 51257d5
fix(diffbot): address P1 review findings from gate bot
Shivashankar15 212e0c4
chore: revert demo/testing and pnpm-lock out-of-scope changes
Shivashankar15 e5503ae
fix(diffbot): fix unused import lint error and restore updated pnpm-l…
Shivashankar15 92f45e0
fix(diffbot): address review findings
Shivashankar15 443ec84
fix(diffbot): preserve API error metadata
Shivashankar15 ec8af0b
test(diffbot): type endpoint test context
Shivashankar15 56d5a29
fix(diffbot): validate DQL collection mode
Shivashankar15 a81fa17
fix(diffbot): protect authenticated token
Shivashankar15 dac52e1
feat(diffbot): implement all 35 Diffbot operations with database sche…
Dhirenderchoudhary a38e3fe
test(diffbot): add request-mapping tests for all 35 callable endpoints
Dhirenderchoudhary 78ba94a
test(diffbot): clean database mock in tests and compact query parameters
Dhirenderchoudhary 828ddd2
chore: merge upstream main and resolve conflicts in constants and loc…
Dhirenderchoudhary File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,242 @@ | ||
| import { | ||
| AnalyzeInputSchema, | ||
| AnalyzeResponseSchema, | ||
| DqlSearchInputSchema, | ||
| DqlSearchResponseSchema, | ||
| ExtractArticleInputSchema, | ||
| ExtractArticleResponseSchema, | ||
| ExtractProductInputSchema, | ||
| ExtractProductResponseSchema, | ||
| WebSearchInputSchema, | ||
| WebSearchResponseSchema, | ||
| } from './endpoints/types'; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Extract Article | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('extract.article — input schema', () => { | ||
| it('accepts a valid URL', () => { | ||
| const result = ExtractArticleInputSchema.safeParse({ | ||
| url: 'https://techcrunch.com/2024/01/01/example-article', | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts optional fields param', () => { | ||
| const result = ExtractArticleInputSchema.safeParse({ | ||
| url: 'https://example.com', | ||
| fields: 'links,meta,tags', | ||
| timeout: 30000, | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects missing url', () => { | ||
| const result = ExtractArticleInputSchema.safeParse({}); | ||
| expect(result.success).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extract.article — response schema', () => { | ||
| it('parses a valid article response', () => { | ||
| const payload = { | ||
| request: { pageUrl: 'https://example.com', api: 'article', version: 3 }, | ||
| objects: [ | ||
| { | ||
| type: 'article' as const, | ||
| title: 'Test Article', | ||
| text: 'Article body text', | ||
| author: 'John Doe', | ||
| date: '2024-01-01T00:00:00.000Z', | ||
| pageUrl: 'https://example.com', | ||
| humanLanguage: 'en', | ||
| }, | ||
| ], | ||
| }; | ||
| const result = ExtractArticleResponseSchema.safeParse(payload); | ||
| expect(result.success).toBe(true); | ||
| if (result.success) { | ||
| expect(result.data.objects[0]?.title).toBe('Test Article'); | ||
| expect(result.data.objects[0]?.author).toBe('John Doe'); | ||
| } | ||
| }); | ||
|
|
||
| it('parses response with optional fields missing', () => { | ||
| const result = ExtractArticleResponseSchema.safeParse({ | ||
| objects: [{ type: 'article' }], | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Extract Product | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('extract.product — input schema', () => { | ||
| it('accepts a valid product URL', () => { | ||
| const result = ExtractProductInputSchema.safeParse({ | ||
| url: 'https://www.amazon.com/dp/B08N5WRWNW', | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects missing url', () => { | ||
| const result = ExtractProductInputSchema.safeParse({ timeout: 5000 }); | ||
| expect(result.success).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extract.product — response schema', () => { | ||
| it('parses a valid product response', () => { | ||
| const payload = { | ||
| objects: [ | ||
| { | ||
| type: 'product' as const, | ||
| title: 'Example Product', | ||
| offerPrice: '$29.99', | ||
| availability: true, | ||
| brand: 'Acme', | ||
| pageUrl: 'https://example.com/product', | ||
| }, | ||
| ], | ||
| }; | ||
| const result = ExtractProductResponseSchema.safeParse(payload); | ||
| expect(result.success).toBe(true); | ||
| if (result.success) { | ||
| expect(result.data.objects[0]?.offerPrice).toBe('$29.99'); | ||
| expect(result.data.objects[0]?.availability).toBe(true); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Analyze (auto-detect) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('extract.analyze — input schema', () => { | ||
| it('accepts a URL with fallback option', () => { | ||
| const result = AnalyzeInputSchema.safeParse({ | ||
| url: 'https://example.com', | ||
| fallback: 'article', | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects empty object', () => { | ||
| const result = AnalyzeInputSchema.safeParse({}); | ||
| expect(result.success).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('extract.analyze — response schema', () => { | ||
| it('parses an analyze response with detected type', () => { | ||
| const result = AnalyzeResponseSchema.safeParse({ | ||
| type: 'article', | ||
| humanLanguage: 'en', | ||
| objects: [{ type: 'article', title: 'Detected Article' }], | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| if (result.success) { | ||
| expect(result.data.type).toBe('article'); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Web Search | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('search.web — input schema', () => { | ||
| it('accepts a valid search query', () => { | ||
| const result = WebSearchInputSchema.safeParse({ | ||
| query: 'artificial intelligence trends 2024', | ||
| num: 10, | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects num > 25 (Diffbot max)', () => { | ||
| const result = WebSearchInputSchema.safeParse({ | ||
| query: 'test', | ||
| num: 100, | ||
| }); | ||
| expect(result.success).toBe(false); | ||
| }); | ||
|
|
||
| it('rejects missing query', () => { | ||
| const result = WebSearchInputSchema.safeParse({ num: 5 }); | ||
| expect(result.success).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('search.web — response schema', () => { | ||
| it('parses a valid search response', () => { | ||
| const payload = { | ||
| results: [ | ||
| { | ||
| title: 'AI in 2024', | ||
| pageUrl: 'https://example.com/ai-2024', | ||
| text: 'Article summary...', | ||
| humanLanguage: 'en', | ||
| }, | ||
| ], | ||
| numResults: 1, | ||
| hits: 1, | ||
| }; | ||
| const result = WebSearchResponseSchema.safeParse(payload); | ||
| expect(result.success).toBe(true); | ||
| if (result.success) { | ||
| expect(result.data.results?.[0]?.title).toBe('AI in 2024'); | ||
| expect(result.data.numResults).toBe(1); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // DQL (Knowledge Graph Search) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('search.dql — input schema', () => { | ||
| it('accepts a DQL query', () => { | ||
| const result = DqlSearchInputSchema.safeParse({ | ||
| query: 'name:"OpenAI"', | ||
| type: 'Organization', | ||
| size: 5, | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('accepts a query without optional type', () => { | ||
| const result = DqlSearchInputSchema.safeParse({ | ||
| query: 'diffbot', | ||
| }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
|
|
||
| it('rejects missing query', () => { | ||
| const result = DqlSearchInputSchema.safeParse({ size: 5 }); | ||
| expect(result.success).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('search.dql — response schema', () => { | ||
| it('parses a valid DQL response', () => { | ||
| const payload = { | ||
| data: [{ id: 'org-123', name: 'OpenAI', type: 'Organization' }], | ||
| hits: 1, | ||
| }; | ||
| const result = DqlSearchResponseSchema.safeParse(payload); | ||
| expect(result.success).toBe(true); | ||
| if (result.success) { | ||
| expect(result.data.hits).toBe(1); | ||
| expect(result.data.data).toHaveLength(1); | ||
| } | ||
| }); | ||
|
|
||
| it('parses an empty result set', () => { | ||
| const result = DqlSearchResponseSchema.safeParse({ data: [], hits: 0 }); | ||
| expect(result.success).toBe(true); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import type { ApiRequestOptions, OpenAPIConfig } from 'corsair/http'; | ||
| import { request } from 'corsair/http'; | ||
|
|
||
| export class DiffbotAPIError extends Error { | ||
| constructor( | ||
| message: string, | ||
| public readonly code?: string, | ||
| ) { | ||
| super(message); | ||
| this.name = 'DiffbotAPIError'; | ||
| } | ||
| } | ||
|
|
||
| // Diffbot API v3 base URL | ||
| const DIFFBOT_API_BASE = 'https://api.diffbot.com/v3'; | ||
|
|
||
| /** | ||
| * Make a request to the Diffbot API. | ||
| * | ||
| * Diffbot authenticates via `?token=<api-key>` as a query parameter — | ||
| * NOT via an Authorization header. The token is injected automatically here. | ||
| */ | ||
| export async function makeDiffbotRequest<T>( | ||
| endpoint: string, | ||
| token: string, | ||
| options: { | ||
| method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'; | ||
| body?: Record<string, unknown>; | ||
| query?: Record<string, string | number | boolean | undefined>; | ||
| } = {}, | ||
| ): Promise<T> { | ||
| const { method = 'GET', body, query } = options; | ||
|
|
||
| const config: OpenAPIConfig = { | ||
| BASE: DIFFBOT_API_BASE, | ||
| VERSION: '3', | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| WITH_CREDENTIALS: false, | ||
| CREDENTIALS: 'omit', | ||
| TOKEN: undefined, | ||
| HEADERS: { | ||
| Accept: 'application/json', | ||
| }, | ||
| }; | ||
|
|
||
| // Diffbot auth: token is a query parameter, not a header | ||
| const queryWithToken: Record<string, string | number | boolean | undefined> = | ||
| { | ||
| token, | ||
| ...query, | ||
| }; | ||
|
|
||
| const requestOptions: ApiRequestOptions = { | ||
| method, | ||
| url: endpoint, | ||
| body: | ||
| method === 'POST' || method === 'PUT' || method === 'PATCH' | ||
| ? body | ||
| : undefined, | ||
| mediaType: 'application/json', | ||
| query: queryWithToken, | ||
| }; | ||
|
|
||
| try { | ||
| return await request<T>(config, requestOptions); | ||
| } catch (error) { | ||
| if (error instanceof Error) { | ||
| throw new DiffbotAPIError(error.message); | ||
| } | ||
|
greptile-apps[bot] marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||
| throw new DiffbotAPIError('Unknown error occurred'); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.