Skip to content

Commit a0a4b8c

Browse files
authored
Merge pull request #1151 from objectstack-ai/claude/update-client-discovery-url
Prioritize /api/v1/discovery over .well-known/objectstack per protocol
2 parents 3b36a95 + e81face commit a0a4b8c

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

packages/client/src/index.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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 });

packages/client/tests/integration/01-discovery.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import { ObjectStackClient } from '../../src/index';
1313
const TEST_SERVER_URL = process.env.TEST_SERVER_URL || 'http://localhost:3000';
1414

1515
describe('Discovery & Connection', () => {
16-
describe('TC-DISC-001: Standard Discovery via .well-known', () => {
17-
test('should discover API from .well-known/objectstack', async () => {
18-
const client = new ObjectStackClient({
16+
describe('TC-DISC-001: Protocol-standard Discovery via /api/v1/discovery', () => {
17+
test('should discover API from /api/v1/discovery', async () => {
18+
const client = new ObjectStackClient({
1919
baseUrl: TEST_SERVER_URL,
2020
debug: true
2121
});
22-
22+
2323
const discovery = await client.connect();
24-
24+
2525
expect(discovery.version).toBeDefined();
2626
expect(discovery.apiName).toBeDefined();
2727
expect(discovery.routes).toBeDefined();

0 commit comments

Comments
 (0)