Skip to content

Commit 4ab0130

Browse files
committed
fix(client): enhance discovery response handling in ObjectStackClient
1 parent f7c0ef5 commit 4ab0130

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

packages/client/src/client.hono.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,19 @@ describe('ObjectStackClient (with Hono Server)', () => {
101101
if (kernel) await kernel.shutdown();
102102
});
103103

104-
it('should connect to hono server', async () => {
104+
it('should connect to hono server and discover endpoints', async () => {
105105
const client = new ObjectStackClient({ baseUrl });
106106
await client.connect();
107107

108-
// Client creates URL like ${baseUrl}/api/v1
109-
expect(client).toBeDefined();
108+
// Client should have populated discovery info
109+
expect(client['discoveryInfo']).toBeDefined();
110+
111+
// Verify endpoints from valid discovery response
112+
// Standard: /api/v1/data, /api/v1/meta, etc.
113+
const endpoints = client['discoveryInfo']!.routes;
114+
expect(endpoints.data).toContain('/api/v1/data');
115+
expect(endpoints.metadata).toContain('/api/v1/meta');
116+
expect(endpoints.auth).toContain('/api/v1/auth');
110117
});
111118

112119
it('should create and retrieve data via hono', async () => {

packages/client/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export class ObjectStackClient {
114114
this.logger.debug('Probing .well-known discovery', { url: wellKnownUrl });
115115
const res = await this.fetchImpl(wellKnownUrl);
116116
if (res.ok) {
117-
data = await res.json();
117+
const body = await res.json();
118+
data = body.data || body;
118119
this.logger.debug('Discovered via .well-known');
119120
}
120121
} catch (e) {
@@ -129,7 +130,8 @@ export class ObjectStackClient {
129130
if (!res.ok) {
130131
throw new Error(`Failed to connect to ${fallbackUrl}: ${res.statusText}`);
131132
}
132-
data = await res.json();
133+
const body = await res.json();
134+
data = body.data || body;
133135
}
134136

135137
if (!data) {

0 commit comments

Comments
 (0)