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 {
3636 * @param {string } [options.baseUrl] - Defaults to https://api.replicate.com/v1
3737 * @param {Function } [options.fetch] - Fetch function to use. Defaults to `globalThis.fetch`
3838 */
39- constructor ( options ) {
40- if ( ! options . auth ) {
41- throw new Error ( 'Missing required parameter: auth' ) ;
42- }
43-
39+ constructor ( options = { } ) {
4440 this . auth = options . auth ;
4541 this . userAgent =
4642 options . userAgent || `replicate-javascript/${ packageJSON . version } ` ;
@@ -187,7 +183,9 @@ class Replicate {
187183 } ) ;
188184
189185 const headers = new Headers ( ) ;
190- headers . append ( 'Authorization' , `Token ${ auth } ` ) ;
186+ if ( auth ) {
187+ headers . append ( 'Authorization' , `Token ${ auth } ` ) ;
188+ }
191189 headers . append ( 'Content-Type' , 'application/json' ) ;
192190 headers . append ( 'User-Agent' , userAgent ) ;
193191 if ( options . headers ) {
Original file line number Diff line number Diff line change @@ -34,12 +34,17 @@ describe('Replicate client', () => {
3434 expect ( clientWithCustomUserAgent . userAgent ) . toBe ( 'my-app/1.2.3' ) ;
3535 } ) ;
3636
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+ } ) ;
3943
44+ test ( 'Does not throw error if blank auth token is provided' , ( ) => {
4045 expect ( ( ) => {
4146 new Replicate ( { auth : "" } ) ;
42- } ) . toThrow ( expected ) ;
47+ } ) . not . toThrow ( ) ;
4348 } ) ;
4449 } ) ;
4550
You can’t perform that action at this time.
0 commit comments