Skip to content

Commit afa9d34

Browse files
committed
fix: CR
1 parent ddf1f02 commit afa9d34

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

src/fetch/BaseFetch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { AI21Error } from '../errors';
2-
import { Stream } from '../Streaming';
2+
import { Stream } from '../streaming';
33
import { FinalRequestOptions, CrossPlatformResponse } from '../types';
44
import { APIResponseProps } from '../types/API';
55

66
export type APIResponse<T> = {
77
data?: T;
88
response: CrossPlatformResponse;
99
};
10-
export abstract class Fetch {
10+
export abstract class BaseFetch {
1111
abstract call(url: string, options: FinalRequestOptions): Promise<CrossPlatformResponse>;
1212
async handleResponse<T>({ response, options }: APIResponseProps) {
1313
if (options.stream) {

src/fetch/BrowserFetch.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { FinalRequestOptions, CrossPlatformResponse } from 'types';
2-
import { Fetch } from './BaseFetch';
3-
import { Stream, BrowserSSEDecoder } from '../Streaming';
2+
import { BaseFetch } from './BaseFetch';
3+
import { Stream, BrowserSSEDecoder } from '../streaming';
44

5-
export class BrowserFetch extends Fetch {
5+
export class BrowserFetch extends BaseFetch {
66
call(url: string, options: FinalRequestOptions): Promise<CrossPlatformResponse> {
77
const controller = new AbortController();
88

99
return fetch(url, {
10-
method: options?.method,
11-
headers: options?.headers as HeadersInit,
12-
body: options.body ? JSON.stringify(options.body) : undefined,
10+
method: options.method,
11+
headers: options?.headers ? options.headers as HeadersInit : undefined,
12+
body: options?.body ? JSON.stringify(options.body) : undefined,
1313
signal: controller.signal,
1414
});
1515
}

src/fetch/NodeFetch.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { FinalRequestOptions, CrossPlatformResponse } from 'types';
2-
import { Fetch } from './BaseFetch';
3-
import { Stream, NodeSSEDecoder } from '../Streaming';
2+
import { BaseFetch } from './BaseFetch';
3+
import { Stream, NodeSSEDecoder } from '../streaming';
44

5-
export class NodeFetch extends Fetch {
5+
export class NodeFetch extends BaseFetch {
66
async call(url: string, options: FinalRequestOptions): Promise<CrossPlatformResponse> {
77
const nodeFetchModule = await import('node-fetch');
88
const nodeFetch = nodeFetchModule.default;
99

1010
return nodeFetch(url, {
11-
method: options?.method,
12-
headers: options.headers as Record<string, string>,
11+
method: options.method,
12+
headers: options?.headers ? options.headers as Record<string, string> : undefined,
1313
body: options?.body ? JSON.stringify(options.body) : undefined,
1414
});
1515
}

src/fetch/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { Fetch } from './BaseFetch';
1+
export { BaseFetch as Fetch } from './BaseFetch';
22
export { BrowserFetch } from './BrowserFetch';
33
export { NodeFetch } from './NodeFetch';

src/types/API.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ export type FinalRequestOptions = RequestOptions & {
2525

2626
export type DefaultQuery = Record<string, unknown>;
2727
export type Headers = Record<string, string | null | undefined>;
28+
29+
// Platforms specific types for NodeJS and Browser
2830
export type CrossPlatformResponse = Response | import('node-fetch').Response;
2931
export type CrossPlatformReadableStream = ReadableStream<Uint8Array> | import('stream/web').ReadableStream;

0 commit comments

Comments
 (0)