Skip to content
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

feat: add fetch override #245

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isBrowser } from "./helpers";
import { DeepgramClientOptions } from "./types/DeepgramClientOptions";
import { FetchOptions } from "./types/Fetch";
import { version } from "./version";

Expand All @@ -18,7 +19,7 @@ export const DEFAULT_FETCH_OPTIONS: FetchOptions = {
headers: DEFAULT_HEADERS,
};

export const DEFAULT_OPTIONS = {
export const DEFAULT_OPTIONS: DeepgramClientOptions = {
global: DEFAULT_GLOBAL_OPTIONS,
fetch: DEFAULT_FETCH_OPTIONS,
fetchOptions: DEFAULT_FETCH_OPTIONS,
};
5 changes: 3 additions & 2 deletions src/lib/types/DeepgramClientOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FetchOptions } from "./Fetch";
import { Fetch, FetchOptions } from "./Fetch";

export interface DeepgramClientOptions {
global?: {
Expand All @@ -12,7 +12,8 @@ export interface DeepgramClientOptions {
*/
url?: string;
};
fetch?: FetchOptions;
fetchOptions?: FetchOptions;
fetch?: Fetch;
restProxy?: {
url: null | string;
};
Expand Down
6 changes: 3 additions & 3 deletions src/packages/AbstractRestfulClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class AbstractRestfulClient extends AbstractClient {
);
}

this.fetch = fetchWithAuth(this.key);
this.fetch = options.fetch ? options.fetch : fetchWithAuth(this.key);
}

protected _getErrorMessage(err: any): string {
Expand Down Expand Up @@ -49,9 +49,9 @@ export abstract class AbstractRestfulClient extends AbstractClient {
body?: string | Buffer | Readable
) {
const params: { [k: string]: any } = {
...this.options?.fetch,
...this.options?.fetchOptions,
method,
headers: { ...this.options?.fetch?.headers, ...headers } || {},
headers: { ...this.options?.fetchOptions?.headers, ...headers } || {},
};

if (method === "GET") {
Expand Down
Loading