Skip to content
Merged
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
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Replicate {
* @param {Function} [options.fetch] - Fetch function to use. Defaults to `globalThis.fetch`
*/
constructor(options) {
if (!options.auth) {
throw new Error('Missing required parameter: auth');
}

this.auth = options.auth;
this.userAgent =
options.userAgent || `replicate-javascript/${packageJSON.version}`;
Expand Down
16 changes: 16 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ describe('Replicate client', () => {
});
expect(clientWithCustomUserAgent.userAgent).toBe('my-app/1.2.3');
});

test('Throws error if no auth token is provided', () => {
const expected = 'Missing required parameter: auth'

expect(() => {
new Replicate({ auth: undefined });
}).toThrow(expected);

expect(() => {
new Replicate({ auth: null });
}).toThrow(expected);

expect(() => {
new Replicate({ auth: "" });
}).toThrow(expected);
});
});

describe('collections.list', () => {
Expand Down