Skip to content

Commit 8c2c94a

Browse files
committed
fix: fix types and user agent version
1 parent d4d9388 commit 8c2c94a

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

src/__tests__/linkup-client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('LinkupClient', () => {
9292
baseURL: 'http://foo.bar/baz',
9393
headers: {
9494
Authorization: 'Bearer 1234',
95-
'User-Agent': 'Linkup-JS-SDK/2.0.0',
95+
'User-Agent': 'Linkup-JS-SDK/2.1.1',
9696
},
9797
});
9898
});

src/linkup-client.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import {
1010
SearchParams,
1111
SearchResults,
1212
SourcedAnswer,
13-
StructuredOutputSchema,
1413
} from './types';
1514
import { refineError } from './utils/refine-error.utils';
1615
import { isZodObject } from './utils/schema.utils';
1716

1817
export class LinkupClient {
19-
private readonly USER_AGENT = 'Linkup-JS-SDK/2.0.0';
18+
private readonly USER_AGENT = 'Linkup-JS-SDK/2.1.1';
2019
private readonly client: AxiosInstance;
2120

2221
constructor(config: ApiConfig) {
@@ -41,24 +40,16 @@ export class LinkupClient {
4140
);
4241
}
4342

44-
async search<T extends 'sourcedAnswer' | 'searchResults' | 'structured'>(
43+
async search<T extends SearchOutputType>(
4544
params: SearchParams<T>,
46-
): Promise<
47-
T extends 'sourcedAnswer'
48-
? SourcedAnswer
49-
: T extends 'searchResults'
50-
? SearchResults
51-
: T extends 'structured'
52-
? StructuredOutputSchema
53-
: never
54-
> {
45+
): Promise<LinkupSearchResponse<T>> {
5546
return this.client
5647
.post('/search', this.sanitizeParams(params))
57-
.then(response => this.formatResponse<T>(response.data, params.outputType));
48+
.then(response => this.formatResponse(response.data, params.outputType));
5849
}
5950

60-
async fetch(params: FetchParams): Promise<LinkupFetchResponse> {
61-
return this.client.post<LinkupFetchResponse>('/fetch', params).then(response => response.data);
51+
async fetch<T extends FetchParams>(params: T): Promise<LinkupFetchResponse<T>> {
52+
return this.client.post('/fetch', params).then(response => response.data);
6253
}
6354

6455
private sanitizeParams<T extends SearchOutputType>({
@@ -91,9 +82,9 @@ export class LinkupClient {
9182
};
9283
}
9384

94-
private formatResponse<T>(
85+
private formatResponse<T extends SearchOutputType>(
9586
searchResponse: unknown,
96-
outputType: SearchOutputType,
87+
outputType: T,
9788
): LinkupSearchResponse<T> {
9889
switch (outputType) {
9990
case 'sourcedAnswer':

src/types.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ export interface ApiConfig {
99
baseUrl?: string;
1010
}
1111

12-
export type StructuredOutputSchema = Record<string, unknown> | ZodObject<ZodRawShape>;
12+
export type StructuredOutputSchema = Record<string, unknown>;
13+
14+
export type StructuredOutputInputSchema = StructuredOutputSchema | ZodObject<ZodRawShape>;
1315

1416
export interface SearchParams<T extends SearchOutputType> {
1517
query: string;
1618
depth: SearchDepth;
1719
outputType: T;
1820
includeImages?: boolean;
19-
structuredOutputSchema?: StructuredOutputSchema;
21+
structuredOutputSchema?: StructuredOutputInputSchema;
2022
includeDomains?: string[];
2123
excludeDomains?: string[];
2224
fromDate?: Date;
@@ -77,7 +79,6 @@ export interface FetchParams {
7779
includeRawHtml?: boolean;
7880
}
7981

80-
export interface LinkupFetchResponse {
82+
export type LinkupFetchResponse<T extends FetchParams = FetchParams> = {
8183
markdown: string;
82-
rawHtml?: string;
83-
}
84+
} & (T['includeRawHtml'] extends true ? { rawHtml: string } : Record<string, never>);

0 commit comments

Comments
 (0)