Skip to content

Commit 29997e0

Browse files
amirai21asafgardin
authored andcommitted
feat: node fetch casting
1 parent e3b0810 commit 29997e0

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/APIClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,19 @@ export abstract class APIClient {
8686
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8787
appendBodyToFormData(formDataRequest.formData, opts.body as Record<string, any>);
8888
}
89-
89+
9090
const headers = {
9191
...opts?.headers,
9292
...formDataRequest.headers,
9393
};
94-
94+
9595
const options: FinalRequestOptions = {
9696
method: 'post',
9797
path: path,
9898
body: formDataRequest.formData,
9999
headers,
100100
};
101-
101+
102102
return this.performRequest(options).then((response) => this.fetch.handleResponse<Rsp>(response) as Rsp);
103103
});
104104
}

src/fetch/NodeFetch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FinalRequestOptions, CrossPlatformResponse } from 'types';
22
import { BaseFetch } from './BaseFetch';
33
import { Stream, NodeSSEDecoder } from '../streaming';
4+
import { NodeHTTPBody } from 'types/API';
45

56
export class NodeFetch extends BaseFetch {
67
async call(url: string, options: FinalRequestOptions): Promise<CrossPlatformResponse> {
@@ -10,7 +11,7 @@ export class NodeFetch extends BaseFetch {
1011
return nodeFetch(url, {
1112
method: options.method,
1213
headers: options?.headers ? (options.headers as Record<string, string>) : undefined,
13-
body: options?.body ? (options.body as import('form-data') | string) : undefined,
14+
body: options?.body ? (options.body as NodeHTTPBody) : undefined,
1415
});
1516
}
1617

src/types/API.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ export type CrossPlatformReadableStream = ReadableStream<Uint8Array> | import('s
3333
export type UnifiedFormData = FormData | import('form-data');
3434

3535
export type FormDataRequest = { formData: UnifiedFormData; headers: Headers };
36+
37+
export type NodeHTTPBody = string | import('form-data');

0 commit comments

Comments
 (0)