File tree Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Expand file tree Collapse file tree 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -36,11 +36,7 @@ class Replicate {
36
36
* @param {string } [options.baseUrl] - Defaults to https://api.replicate.com/v1
37
37
* @param {Function } [options.fetch] - Fetch function to use. Defaults to `globalThis.fetch`
38
38
*/
39
- constructor ( options ) {
40
- if ( ! options . auth ) {
41
- throw new Error ( 'Missing required parameter: auth' ) ;
42
- }
43
-
39
+ constructor ( options = { } ) {
44
40
this . auth = options . auth ;
45
41
this . userAgent =
46
42
options . userAgent || `replicate-javascript/${ packageJSON . version } ` ;
@@ -187,7 +183,9 @@ class Replicate {
187
183
} ) ;
188
184
189
185
const headers = new Headers ( ) ;
190
- headers . append ( 'Authorization' , `Token ${ auth } ` ) ;
186
+ if ( auth ) {
187
+ headers . append ( 'Authorization' , `Token ${ auth } ` ) ;
188
+ }
191
189
headers . append ( 'Content-Type' , 'application/json' ) ;
192
190
headers . append ( 'User-Agent' , userAgent ) ;
193
191
if ( options . headers ) {
Original file line number Diff line number Diff line change @@ -34,12 +34,17 @@ describe('Replicate client', () => {
34
34
expect ( clientWithCustomUserAgent . userAgent ) . toBe ( 'my-app/1.2.3' ) ;
35
35
} ) ;
36
36
37
- test ( 'Throws error if no auth token is provided' , ( ) => {
38
- const expected = 'Missing required parameter: auth'
37
+ test ( 'Does not throw error if auth token is not provided' , ( ) => {
38
+ expect ( ( ) => {
39
+ // @ts -expect-error
40
+ new Replicate ( ) ;
41
+ } ) . not . toThrow ( ) ;
42
+ } ) ;
39
43
44
+ test ( 'Does not throw error if blank auth token is provided' , ( ) => {
40
45
expect ( ( ) => {
41
46
new Replicate ( { auth : "" } ) ;
42
- } ) . toThrow ( expected ) ;
47
+ } ) . not . toThrow ( ) ;
43
48
} ) ;
44
49
} ) ;
45
50
You can’t perform that action at this time.
0 commit comments