Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { AxiosRequestConfig } from "axios";

type Identifier = `${string}/${string}:${string}`;

declare module "replicate" {
export interface ReplicateOptions {
auth: string;
userAgent: string;
baseUrl?: string;
axiosConfig?: Partial<Omit<AxiosRequestConfig, "url" | "method">>;
}

export interface Collection {
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Replicate {
options.userAgent || `replicate-javascript/${packageJSON.version}`;
this.baseUrl = options.baseUrl || 'https://api.replicate.com/v1';
this.instance = axios.create({
...options.axiosConfig,
baseURL: this.baseUrl,
headers: {
Authorization: `Token ${this.auth}`,
Expand Down
10 changes: 10 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ describe('Replicate client', () => {
expect(clientWithoutBaseUrl.baseUrl).toBe('https://api.replicate.com/v1');
});

test('Constructor passes through axios options', async () => {
const adapter = jest.fn(() => Promise.resolve({}));
const clientWithAxiosOptions = new Replicate({
axiosConfig: { adapter },
});

await clientWithAxiosOptions.collections.get('text-to-image');
expect(adapter).toHaveBeenCalled();
});

describe('collections.get', () => {
test('Calls the correct API route', async () => {
client.request = jest.fn();
Expand Down