Skip to content

Commit 5f397fd

Browse files
committed
docs(client): the SDK examples read the resolved payload
`analytics.query` / `analytics.meta` / `analytics.explain` and `automation.trigger` resolve to the payload rather than the dispatcher's `{ success, data }` envelope, but the three places a reader first meets the SDK showed the calls with nothing reading the resolved value: the page was neither wrong nor instructive about the shape. One payload read per example, on all three sites together — the docs site's Client SDK page, the Data API page's `GET /analytics/meta` prose, and the `@objectstack/client` README — using the members the contracts declare (`AnalyticsResult.rows` / `.fields[].name`, the bare `CubeMeta[]`, `{ sql, params }`, `AutomationResult.status`). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AhooRxUmvwYwcnQ5LATTB7
1 parent 1f2a02b commit 5f397fd

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@objectstack/client": patch
3+
---
4+
5+
The README's analytics and automation examples read the resolved payload.
6+
7+
`client.analytics.query` / `analytics.meta` and `client.automation.trigger` stopped handing back the dispatcher's `{ success, data }` envelope in 17.0.0: each resolves to the payload itself. The README's namespace tour still showed all three as bare `await` calls with nothing reading the resolved value, so the package's own front page taught nothing about which shape comes back — neither wrong nor useful. Each of the three now assigns its result and reads one member of it: `report.rows` / `report.fields[0].name` (`AnalyticsResult`), `cubes[0].name` (the bare `CubeMeta[]`), `run.status` (`AutomationResult`) — the members those contracts actually declare, read off the payload rather than off a `data` wrapper.
8+
9+
No behaviour changes; this is the README that ships inside the package. The docs site's Client SDK and Data API pages take the same treatment in the same PR.

content/docs/api/client-sdk.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,18 @@ const result = await client.analytics.query({
316316
where: { status: 'active' },
317317
limit: 100,
318318
});
319+
console.log(result.rows.length, result.fields[0].name); // AnalyticsResult, unwrapped
319320

320321
// Get cube metadata — all cubes, or one with meta('account')
321322
const meta = await client.analytics.meta('account');
323+
console.log(meta[0].name, meta[0].measures.length); // the bare cube list
322324

323325
// Dry-run a query to its generated SQL (POST /analytics/sql)
324326
const explained = await client.analytics.explain({
325327
cube: 'account',
326328
measures: ['revenue_sum'],
327329
});
330+
console.log(explained.sql, explained.params); // { sql, params }
328331
```
329332

330333
### `client.packages` — Package Management
@@ -430,7 +433,8 @@ await client.i18n.getTranslations('zh-CN');
430433
await client.i18n.getFieldLabels('account', 'zh-CN');
431434

432435
// Automation — Trigger workflows and automations
433-
await client.automation.trigger('send_welcome_email', { userId });
436+
const welcome = await client.automation.trigger('send_welcome_email', { userId });
437+
console.log(welcome.status); // AutomationResult — the run's own outcome, unwrapped
434438

435439
// A flow that does not run REJECTS — it does not resolve with an inner
436440
// `{ success: false }`. Branch on the thrown error's `code`, not on the

content/docs/api/data-api.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ Pass `?cube=<name>` to filter the listing to a single cube (this is what
444444

445445
**Response**: `{ success: true, data: [...] }` where `data` is an array of cube
446446
definitions with measures and dimensions (time-based dimensions are `dimensions`
447-
entries with `type: "time"`).
447+
entries with `type: "time"`). That envelope is the wire shape only — the SDK
448+
unwraps it, so `client.analytics.meta(cube)` resolves to the cube array itself
449+
and a caller reads `cubes[0].name`. The same holds for the other analytics and
450+
automation calls; see the [Client SDK](/docs/api/client-sdk) page.
448451

449452
### `POST /analytics/sql`
450453

packages/client/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,15 @@ await client.i18n.getLocales();
269269
await client.i18n.getTranslations('zh-CN');
270270
await client.i18n.getFieldLabels('contact', 'zh-CN');
271271

272-
// Analytics
273-
await client.analytics.query({ object: 'sales', aggregations: ['sum:amount'] });
274-
await client.analytics.meta('sales');
272+
// Analytics — every method resolves to the payload itself
273+
const report = await client.analytics.query({ object: 'sales', aggregations: ['sum:amount'] });
274+
console.log(report.rows.length, report.fields[0].name);
275+
const cubes = await client.analytics.meta('sales');
276+
console.log(cubes[0].name);
275277

276278
// Automation
277-
await client.automation.trigger('send_welcome_email', { userId });
279+
const run = await client.automation.trigger('send_welcome_email', { userId });
280+
console.log(run.status);
278281

279282
// File Storage
280283
await client.storage.upload(fileData, 'user');

0 commit comments

Comments
 (0)