@@ -253,12 +253,26 @@ export class ObjectStackClient {
253253 */
254254 async connect ( ) {
255255 this . logger . debug ( 'Connecting to ObjectStack server' , { baseUrl : this . baseUrl } ) ;
256-
256+
257257 try {
258258 let data : DiscoveryResult | undefined ;
259259
260- // 1. Try Standard Discovery (.well-known )
260+ // 1. Try Protocol-standard Discovery Path /api/v1/discovery (primary )
261261 try {
262+ const discoveryUrl = `${ this . baseUrl } /api/v1/discovery` ;
263+ this . logger . debug ( 'Probing protocol-standard discovery endpoint' , { url : discoveryUrl } ) ;
264+ const res = await this . fetchImpl ( discoveryUrl ) ;
265+ if ( res . ok ) {
266+ const body = await res . json ( ) ;
267+ data = body . data || body ;
268+ this . logger . debug ( 'Discovered via /api/v1/discovery' ) ;
269+ }
270+ } catch ( e ) {
271+ this . logger . debug ( 'Protocol-standard discovery probe failed' , { error : ( e as Error ) . message } ) ;
272+ }
273+
274+ // 2. Fallback to Standard Discovery (.well-known)
275+ if ( ! data ) {
262276 let wellKnownUrl : string ;
263277 try {
264278 // If baseUrl is absolute, get origin
@@ -269,24 +283,10 @@ export class ObjectStackClient {
269283 wellKnownUrl = '/.well-known/objectstack' ;
270284 }
271285
272- this . logger . debug ( 'Probing .well-known discovery' , { url : wellKnownUrl } ) ;
286+ this . logger . debug ( 'Falling back to .well-known discovery' , { url : wellKnownUrl } ) ;
273287 const res = await this . fetchImpl ( wellKnownUrl ) ;
274- if ( res . ok ) {
275- const body = await res . json ( ) ;
276- data = body . data || body ;
277- this . logger . debug ( 'Discovered via .well-known' ) ;
278- }
279- } catch ( e ) {
280- this . logger . debug ( 'Standard discovery probe failed' , { error : ( e as Error ) . message } ) ;
281- }
282-
283- // 2. Fallback to Protocol-standard Discovery Path /api/v1/discovery
284- if ( ! data ) {
285- const fallbackUrl = `${ this . baseUrl } /api/v1/discovery` ;
286- this . logger . debug ( 'Falling back to standard discovery endpoint' , { url : fallbackUrl } ) ;
287- const res = await this . fetchImpl ( fallbackUrl ) ;
288288 if ( ! res . ok ) {
289- throw new Error ( `Failed to connect to ${ fallbackUrl } : ${ res . statusText } ` ) ;
289+ throw new Error ( `Failed to connect to ${ wellKnownUrl } : ${ res . statusText } ` ) ;
290290 }
291291 const body = await res . json ( ) ;
292292 data = body . data || body ;
@@ -297,13 +297,13 @@ export class ObjectStackClient {
297297 }
298298
299299 this . discoveryInfo = data ;
300-
301- this . logger . info ( 'Connected to ObjectStack server' , {
300+
301+ this . logger . info ( 'Connected to ObjectStack server' , {
302302 version : data . version ,
303303 apiName : data . apiName ,
304- services : data . services
304+ services : data . services
305305 } ) ;
306-
306+
307307 return data as DiscoveryResult ;
308308 } catch ( e ) {
309309 this . logger . error ( 'Failed to connect to ObjectStack server' , e as Error , { baseUrl : this . baseUrl } ) ;
0 commit comments