From e81face65d53ae56fa313a2726fd50db005b6e35 Mon Sep 17 00:00:00 2001 From: "anthropic-code-agent[bot]" <242468646+Claude@users.noreply.github.com> Date: Wed, 15 Apr 2026 09:13:14 +0000 Subject: [PATCH] Prioritize /api/v1/discovery over .well-known/objectstack per protocol - Updated client to try /api/v1/discovery first - Fall back to .well-known/objectstack as secondary option - Updated integration test description to reflect new priority - Updated log messages to reflect primary vs fallback status Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/55becaf7-61f2-4a6a-bee3-0a27d1c16e03 Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com> --- packages/client/src/index.ts | 44 +++++++++---------- .../tests/integration/01-discovery.test.ts | 10 ++--- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index bf5eb1292..b2f2e47f6 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -253,12 +253,26 @@ export class ObjectStackClient { */ async connect() { this.logger.debug('Connecting to ObjectStack server', { baseUrl: this.baseUrl }); - + try { let data: DiscoveryResult | undefined; - // 1. Try Standard Discovery (.well-known) + // 1. Try Protocol-standard Discovery Path /api/v1/discovery (primary) try { + const discoveryUrl = `${this.baseUrl}/api/v1/discovery`; + this.logger.debug('Probing protocol-standard discovery endpoint', { url: discoveryUrl }); + const res = await this.fetchImpl(discoveryUrl); + if (res.ok) { + const body = await res.json(); + data = body.data || body; + this.logger.debug('Discovered via /api/v1/discovery'); + } + } catch (e) { + this.logger.debug('Protocol-standard discovery probe failed', { error: (e as Error).message }); + } + + // 2. Fallback to Standard Discovery (.well-known) + if (!data) { let wellKnownUrl: string; try { // If baseUrl is absolute, get origin @@ -269,24 +283,10 @@ export class ObjectStackClient { wellKnownUrl = '/.well-known/objectstack'; } - this.logger.debug('Probing .well-known discovery', { url: wellKnownUrl }); + this.logger.debug('Falling back to .well-known discovery', { url: wellKnownUrl }); const res = await this.fetchImpl(wellKnownUrl); - if (res.ok) { - const body = await res.json(); - data = body.data || body; - this.logger.debug('Discovered via .well-known'); - } - } catch (e) { - this.logger.debug('Standard discovery probe failed', { error: (e as Error).message }); - } - - // 2. Fallback to Protocol-standard Discovery Path /api/v1/discovery - if (!data) { - const fallbackUrl = `${this.baseUrl}/api/v1/discovery`; - this.logger.debug('Falling back to standard discovery endpoint', { url: fallbackUrl }); - const res = await this.fetchImpl(fallbackUrl); if (!res.ok) { - throw new Error(`Failed to connect to ${fallbackUrl}: ${res.statusText}`); + throw new Error(`Failed to connect to ${wellKnownUrl}: ${res.statusText}`); } const body = await res.json(); data = body.data || body; @@ -297,13 +297,13 @@ export class ObjectStackClient { } this.discoveryInfo = data; - - this.logger.info('Connected to ObjectStack server', { + + this.logger.info('Connected to ObjectStack server', { version: data.version, apiName: data.apiName, - services: data.services + services: data.services }); - + return data as DiscoveryResult; } catch (e) { this.logger.error('Failed to connect to ObjectStack server', e as Error, { baseUrl: this.baseUrl }); diff --git a/packages/client/tests/integration/01-discovery.test.ts b/packages/client/tests/integration/01-discovery.test.ts index 875467dda..699784287 100644 --- a/packages/client/tests/integration/01-discovery.test.ts +++ b/packages/client/tests/integration/01-discovery.test.ts @@ -13,15 +13,15 @@ import { ObjectStackClient } from '../../src/index'; const TEST_SERVER_URL = process.env.TEST_SERVER_URL || 'http://localhost:3000'; describe('Discovery & Connection', () => { - describe('TC-DISC-001: Standard Discovery via .well-known', () => { - test('should discover API from .well-known/objectstack', async () => { - const client = new ObjectStackClient({ + describe('TC-DISC-001: Protocol-standard Discovery via /api/v1/discovery', () => { + test('should discover API from /api/v1/discovery', async () => { + const client = new ObjectStackClient({ baseUrl: TEST_SERVER_URL, debug: true }); - + const discovery = await client.connect(); - + expect(discovery.version).toBeDefined(); expect(discovery.apiName).toBeDefined(); expect(discovery.routes).toBeDefined();