@lightdash-tools/client 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/api/v1/charts.d.ts +9 -1
  2. package/dist/api/v1/charts.js +8 -0
  3. package/dist/api/v1/charts.test.js +16 -0
  4. package/dist/api/v1/dashboards.d.ts +32 -1
  5. package/dist/api/v1/dashboards.js +20 -0
  6. package/dist/api/v1/dashboards.test.js +72 -0
  7. package/dist/api/v1/validation.d.ts +5 -1
  8. package/dist/api/v1/validation.js +8 -0
  9. package/dist/api/v1/validation.test.js +16 -0
  10. package/dist/api/v2/charts.d.ts +12 -0
  11. package/dist/api/v2/charts.js +18 -0
  12. package/dist/api/v2/charts.test.d.ts +4 -0
  13. package/dist/api/v2/charts.test.js +45 -0
  14. package/dist/api/v2/content.d.ts +19 -2
  15. package/dist/api/v2/content.js +15 -0
  16. package/dist/api/v2/content.test.js +41 -0
  17. package/dist/api/v2/dashboards.d.ts +7 -1
  18. package/dist/api/v2/dashboards.js +9 -1
  19. package/dist/api/v2/dashboards.test.js +34 -0
  20. package/dist/api/v2/parameters.d.ts +20 -0
  21. package/dist/api/v2/parameters.js +22 -0
  22. package/dist/api/v2/parameters.test.d.ts +4 -0
  23. package/dist/api/v2/parameters.test.js +39 -0
  24. package/dist/api/v2/query.d.ts +16 -1
  25. package/dist/api/v2/query.js +16 -0
  26. package/dist/api/v2/query.test.js +16 -0
  27. package/dist/client.d.ts +4 -0
  28. package/dist/client.js +4 -0
  29. package/dist/client.test.js +2 -0
  30. package/dist/http/http-client.d.ts +0 -11
  31. package/dist/http/http-client.js +2 -4
  32. package/dist/http/unwrap-api-success.d.ts +26 -0
  33. package/dist/http/unwrap-api-success.js +25 -0
  34. package/dist/http/unwrap-api-success.test.d.ts +1 -0
  35. package/dist/http/unwrap-api-success.test.js +19 -0
  36. package/dist/index.d.ts +6 -1
  37. package/dist/index.js +6 -1
  38. package/package.json +2 -2
  39. package/src/api/v1/charts.test.ts +18 -0
  40. package/src/api/v1/charts.ts +17 -0
  41. package/src/api/v1/dashboards.test.ts +85 -0
  42. package/src/api/v1/dashboards.ts +86 -0
  43. package/src/api/v1/validation.test.ts +18 -0
  44. package/src/api/v1/validation.ts +21 -1
  45. package/src/api/v2/charts.test.ts +53 -0
  46. package/src/api/v2/charts.ts +23 -0
  47. package/src/api/v2/content.test.ts +45 -0
  48. package/src/api/v2/content.ts +35 -2
  49. package/src/api/v2/dashboards.test.ts +39 -0
  50. package/src/api/v2/dashboards.ts +23 -1
  51. package/src/api/v2/parameters.test.ts +45 -0
  52. package/src/api/v2/parameters.ts +38 -0
  53. package/src/api/v2/query.test.ts +18 -0
  54. package/src/api/v2/query.ts +53 -0
  55. package/src/client.test.ts +2 -0
  56. package/src/client.ts +6 -0
  57. package/src/http/http-client.ts +4 -19
  58. package/src/http/unwrap-api-success.test.ts +23 -0
  59. package/src/http/unwrap-api-success.ts +40 -0
  60. package/src/index.ts +21 -1
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { BaseApiClient } from '../base-client';
6
6
 
7
- import type { LightdashApi } from '@lightdash-tools/common';
7
+ import type { components, LightdashApi } from '@lightdash-tools/common';
8
8
 
9
9
  /** Query params for getting validation results. */
10
10
  export interface GetValidationResultsParams {
@@ -44,4 +44,24 @@ export class ValidationClient extends BaseApiClient {
44
44
  body,
45
45
  );
46
46
  }
47
+
48
+ /** Validate a single chart's fields against its underlying explore/table. */
49
+ async validateChart(
50
+ projectUuid: string,
51
+ chartUuid: string,
52
+ ): Promise<components['schemas']['ApiChartValidationResponse']['results']> {
53
+ return this.http.post<components['schemas']['ApiChartValidationResponse']['results']>(
54
+ `/projects/${projectUuid}/validate/chart/${chartUuid}`,
55
+ );
56
+ }
57
+
58
+ /** Validate a single dashboard's fields against its underlying explores/tables. */
59
+ async validateDashboard(
60
+ projectUuid: string,
61
+ dashboardUuid: string,
62
+ ): Promise<components['schemas']['ApiDashboardValidationResponse']['results']> {
63
+ return this.http.post<components['schemas']['ApiDashboardValidationResponse']['results']>(
64
+ `/projects/${projectUuid}/validate/dashboard/${dashboardUuid}`,
65
+ );
66
+ }
47
67
  }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * V2 charts client unit tests.
3
+ */
4
+
5
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
6
+
7
+ import { ChartsClientV2 } from './charts';
8
+
9
+ import type { HttpClient } from '../../http/http-client';
10
+
11
+ describe('ChartsClientV2', () => {
12
+ let mockHttp: HttpClient;
13
+
14
+ beforeEach(() => {
15
+ mockHttp = {
16
+ get: vi.fn(),
17
+ post: vi.fn(),
18
+ put: vi.fn(),
19
+ patch: vi.fn(),
20
+ delete: vi.fn(),
21
+ } as unknown as HttpClient;
22
+ });
23
+
24
+ it('getSavedChart calls GET /projects/{projectUuid}/saved/{id}', async () => {
25
+ const client = new ChartsClientV2(mockHttp);
26
+ const mockResponse = { uuid: 'c1', name: 'Revenue' };
27
+ vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
28
+ const result = await client.getSavedChart('p1', 'c1');
29
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/saved/c1');
30
+ expect(result).toEqual(mockResponse);
31
+ });
32
+
33
+ it('getSavedChart encodes slug path segments', async () => {
34
+ const client = new ChartsClientV2(mockHttp);
35
+ vi.mocked(mockHttp.get).mockResolvedValue({ uuid: 'c1' });
36
+ await client.getSavedChart('p1', 'my/chart');
37
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/saved/my%2Fchart');
38
+ });
39
+
40
+ it('deleteSavedChart calls DELETE /projects/{projectUuid}/saved/{id}', async () => {
41
+ const client = new ChartsClientV2(mockHttp);
42
+ vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
43
+ await client.deleteSavedChart('p1', 'c1');
44
+ expect(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/saved/c1');
45
+ });
46
+
47
+ it('deleteSavedChart encodes slug path segments', async () => {
48
+ const client = new ChartsClientV2(mockHttp);
49
+ vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
50
+ await client.deleteSavedChart('p1', 'my/chart');
51
+ expect(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/saved/my%2Fchart');
52
+ });
53
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Charts API client (v2). Metadata reads and soft-delete (no query execution).
3
+ */
4
+
5
+ import { BaseApiClient } from '../base-client';
6
+
7
+ import type { components } from '@lightdash-tools/common';
8
+
9
+ export type SavedChart = components['schemas']['SavedChart'];
10
+
11
+ export class ChartsClientV2 extends BaseApiClient {
12
+ /** Get saved chart metadata by UUID or slug within a project. Does not run queries. */
13
+ async getSavedChart(projectUuid: string, chartUuidOrSlug: string): Promise<SavedChart> {
14
+ return this.http.get<SavedChart>(
15
+ `/projects/${projectUuid}/saved/${encodeURIComponent(chartUuidOrSlug)}`,
16
+ );
17
+ }
18
+
19
+ /** Soft-delete a saved chart by UUID or slug within a project. */
20
+ async deleteSavedChart(projectUuid: string, chartUuidOrSlug: string): Promise<void> {
21
+ await this.http.delete(`/projects/${projectUuid}/saved/${encodeURIComponent(chartUuidOrSlug)}`);
22
+ }
23
+ }
@@ -27,4 +27,49 @@ describe('ContentClient', () => {
27
27
  });
28
28
  expect(result).toEqual(mockResponse);
29
29
  });
30
+
31
+ it('searchContent passes exact uuids filter', async () => {
32
+ const client = new ContentClient(mockHttp);
33
+ vi.mocked(mockHttp.get).mockResolvedValue({ status: 'ok', results: [] });
34
+ await client.searchContent({
35
+ projectUuids: ['p1'],
36
+ uuids: ['c1'],
37
+ pageSize: 50,
38
+ });
39
+ expect(mockHttp.get).toHaveBeenCalledWith('/content', {
40
+ params: { projectUuids: ['p1'], uuids: ['c1'], pageSize: 50 },
41
+ });
42
+ });
43
+
44
+ it('moveContent should call POST /content/{projectUuid}/move with body', async () => {
45
+ const client = new ContentClient(mockHttp);
46
+ const body = {
47
+ action: { type: 'move' as const, targetSpaceUuid: 's2' },
48
+ item: { source: 'dbt_explore' as const, contentType: 'chart' as const, uuid: 'c1' },
49
+ } as Parameters<ContentClient['moveContent']>[1];
50
+ vi.mocked(mockHttp.post).mockResolvedValue({ status: 'ok' });
51
+ await client.moveContent('p1', body);
52
+ expect(mockHttp.post).toHaveBeenCalledWith('/content/p1/move', body);
53
+ });
54
+
55
+ it('bulkMoveContent should call POST /content/bulk-action/{projectUuid}/move with body', async () => {
56
+ const client = new ContentClient(mockHttp);
57
+ const body = {
58
+ action: { type: 'move' as const, targetSpaceUuid: 's2' },
59
+ content: [{ source: 'dbt_explore' as const, contentType: 'chart' as const, uuid: 'c1' }],
60
+ } as Parameters<ContentClient['bulkMoveContent']>[1];
61
+ vi.mocked(mockHttp.post).mockResolvedValue({ status: 'ok' });
62
+ await client.bulkMoveContent('p1', body);
63
+ expect(mockHttp.post).toHaveBeenCalledWith('/content/bulk-action/p1/move', body);
64
+ });
65
+
66
+ it('permanentlyDeleteContent should call DELETE /content/{projectUuid}/permanent with body', async () => {
67
+ const client = new ContentClient(mockHttp);
68
+ const body = {
69
+ item: { contentType: 'chart' as const, uuid: 'c1', source: 'dbt_explore' as const },
70
+ } as Parameters<ContentClient['permanentlyDeleteContent']>[1];
71
+ vi.mocked(mockHttp.delete).mockResolvedValue({ status: 'ok' });
72
+ await client.permanentlyDeleteContent('p1', body);
73
+ expect(mockHttp.delete).toHaveBeenCalledWith('/content/p1/permanent', { data: body });
74
+ });
30
75
  });
@@ -4,14 +4,16 @@
4
4
 
5
5
  import { BaseApiClient } from '../base-client';
6
6
 
7
- import type { LightdashApi } from '@lightdash-tools/common';
7
+ import type { components, LightdashApi } from '@lightdash-tools/common';
8
8
 
9
9
  /** Query params for searching content. */
10
10
  export interface SearchContentParams {
11
11
  projectUuids?: string[];
12
12
  spaceUuids?: string[];
13
+ /** Exact content UUID filter (OpenAPI List content `uuids`). */
14
+ uuids?: string[];
13
15
  parentSpaceUuid?: string;
14
- contentTypes?: ('chart' | 'dashboard' | 'space')[];
16
+ contentTypes?: ('chart' | 'dashboard' | 'data_app' | 'space')[];
15
17
  pageSize?: number;
16
18
  page?: number;
17
19
  search?: string;
@@ -19,6 +21,16 @@ export interface SearchContentParams {
19
21
  sortDirection?: 'asc' | 'desc';
20
22
  }
21
23
 
24
+ /** Body for moving a single content item (chart, dashboard, or space) to another space. */
25
+ export type MoveContentBody = components['schemas']['ApiContentActionBody_ContentActionMove_'];
26
+
27
+ /** Body for moving multiple content items (charts, dashboards, spaces) to another space. */
28
+ export type BulkMoveContentBody =
29
+ components['schemas']['ApiContentBulkActionBody_ContentActionMove_'];
30
+
31
+ /** Body for permanently deleting soft-deleted content (irrecoverable). */
32
+ export type PermanentlyDeleteContentBody = components['schemas']['ApiPermanentlyDeleteContentBody'];
33
+
22
34
  export class ContentClient extends BaseApiClient {
23
35
  /** Search project content (charts, dashboards, spaces). */
24
36
  async searchContent(
@@ -28,4 +40,25 @@ export class ContentClient extends BaseApiClient {
28
40
  params,
29
41
  });
30
42
  }
43
+
44
+ /** Move a single content item (chart, dashboard, or space) to another space. */
45
+ async moveContent(projectUuid: string, body: MoveContentBody): Promise<void> {
46
+ await this.http.post(`/content/${projectUuid}/move`, body);
47
+ }
48
+
49
+ /** Move multiple content items (charts, dashboards, spaces) to another space in one call. */
50
+ async bulkMoveContent(projectUuid: string, body: BulkMoveContentBody): Promise<void> {
51
+ await this.http.post(`/content/bulk-action/${projectUuid}/move`, body);
52
+ }
53
+
54
+ /**
55
+ * Permanently delete soft-deleted content (irrecoverable).
56
+ * Not exposed on MCP — use typed client only (ADR-0015).
57
+ */
58
+ async permanentlyDeleteContent(
59
+ projectUuid: string,
60
+ body: PermanentlyDeleteContentBody,
61
+ ): Promise<void> {
62
+ await this.http.delete(`/content/${projectUuid}/permanent`, { data: body });
63
+ }
31
64
  }
@@ -29,4 +29,43 @@ describe('DashboardsClientV2', () => {
29
29
  expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/dashboards/d1');
30
30
  expect(result).toEqual(mockResponse);
31
31
  });
32
+
33
+ it('getDashboard encodes slug in path', async () => {
34
+ const client = new DashboardsClientV2(mockHttp);
35
+ vi.mocked(mockHttp.get).mockResolvedValue({});
36
+ await client.getDashboard('p1', 'dash/slug');
37
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/dashboards/dash%2Fslug');
38
+ });
39
+
40
+ it('updateDashboard calls PATCH /projects/{projectUuid}/dashboards/{id} with body', async () => {
41
+ const client = new DashboardsClientV2(mockHttp);
42
+ const body = { name: 'Renamed' } as Parameters<DashboardsClientV2['updateDashboard']>[2];
43
+ const updated = { uuid: 'd1', name: 'Renamed' };
44
+ vi.mocked(mockHttp.patch).mockResolvedValue(updated);
45
+ const result = await client.updateDashboard('p1', 'd1', body);
46
+ expect(mockHttp.patch).toHaveBeenCalledWith('/projects/p1/dashboards/d1', body);
47
+ expect(result).toEqual(updated);
48
+ });
49
+
50
+ it('updateDashboard encodes slug in path', async () => {
51
+ const client = new DashboardsClientV2(mockHttp);
52
+ const body = { name: 'Renamed' } as Parameters<DashboardsClientV2['updateDashboard']>[2];
53
+ vi.mocked(mockHttp.patch).mockResolvedValue({});
54
+ await client.updateDashboard('p1', 'dash/slug', body);
55
+ expect(mockHttp.patch).toHaveBeenCalledWith('/projects/p1/dashboards/dash%2Fslug', body);
56
+ });
57
+
58
+ it('deleteDashboard calls DELETE /projects/{projectUuid}/dashboards/{id}', async () => {
59
+ const client = new DashboardsClientV2(mockHttp);
60
+ vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
61
+ await client.deleteDashboard('p1', 'd1');
62
+ expect(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/dashboards/d1');
63
+ });
64
+
65
+ it('deleteDashboard encodes slug in path', async () => {
66
+ const client = new DashboardsClientV2(mockHttp);
67
+ vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
68
+ await client.deleteDashboard('p1', 'dash/slug');
69
+ expect(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/dashboards/dash%2Fslug');
70
+ });
32
71
  });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Dashboards API client (v2). Metadata reads only (no query execution).
2
+ * Dashboards API client (v2). Metadata reads, updates, and soft-delete (no query execution).
3
3
  */
4
4
 
5
5
  import { BaseApiClient } from '../base-client';
@@ -8,6 +8,9 @@ import type { components } from '@lightdash-tools/common';
8
8
 
9
9
  export type Dashboard = components['schemas']['Dashboard'];
10
10
 
11
+ /** Request body for PATCH projects/{projectUuid}/dashboards/{dashboardUuidOrSlug}. */
12
+ export type UpdateDashboardBody = components['schemas']['UpdateDashboard'];
13
+
11
14
  export class DashboardsClientV2 extends BaseApiClient {
12
15
  /** Get dashboard metadata by UUID or slug within a project. Does not run queries. */
13
16
  async getDashboard(projectUuid: string, dashboardUuidOrSlug: string): Promise<Dashboard> {
@@ -15,4 +18,23 @@ export class DashboardsClientV2 extends BaseApiClient {
15
18
  `/projects/${projectUuid}/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}`,
16
19
  );
17
20
  }
21
+
22
+ /** Update a dashboard by UUID or slug within a project. */
23
+ async updateDashboard(
24
+ projectUuid: string,
25
+ dashboardUuidOrSlug: string,
26
+ body: UpdateDashboardBody,
27
+ ): Promise<Dashboard> {
28
+ return this.http.patch<Dashboard>(
29
+ `/projects/${projectUuid}/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}`,
30
+ body,
31
+ );
32
+ }
33
+
34
+ /** Soft-delete a dashboard by UUID or slug within a project. */
35
+ async deleteDashboard(projectUuid: string, dashboardUuidOrSlug: string): Promise<void> {
36
+ await this.http.delete(
37
+ `/projects/${projectUuid}/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}`,
38
+ );
39
+ }
18
40
  }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * V2 parameters client unit tests.
3
+ */
4
+
5
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
6
+
7
+ import { ParametersClientV2 } from './parameters';
8
+
9
+ import type { HttpClient } from '../../http/http-client';
10
+
11
+ describe('ParametersClientV2', () => {
12
+ let mockHttp: HttpClient;
13
+
14
+ beforeEach(() => {
15
+ mockHttp = {
16
+ get: vi.fn(),
17
+ post: vi.fn(),
18
+ put: vi.fn(),
19
+ patch: vi.fn(),
20
+ delete: vi.fn(),
21
+ } as unknown as HttpClient;
22
+ });
23
+
24
+ it('listParameters calls GET /projects/{projectUuid}/parameters/list', async () => {
25
+ const client = new ParametersClientV2(mockHttp);
26
+ const mockResponse = { data: [], pagination: {} };
27
+ vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
28
+ const result = await client.listParameters('p1', { search: 'region', page: 1 });
29
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/parameters/list', {
30
+ params: { search: 'region', page: 1 },
31
+ });
32
+ expect(result).toEqual(mockResponse);
33
+ });
34
+
35
+ it('getParameters calls GET /projects/{projectUuid}/parameters', async () => {
36
+ const client = new ParametersClientV2(mockHttp);
37
+ const mockResponse = { region: { type: 'string' } };
38
+ vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
39
+ const result = await client.getParameters('p1', ['region']);
40
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/parameters', {
41
+ params: { names: ['region'] },
42
+ });
43
+ expect(result).toEqual(mockResponse);
44
+ });
45
+ });
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Project parameters API client (v2). Read-only.
3
+ */
4
+
5
+ import { BaseApiClient } from '../base-client';
6
+
7
+ import type { components } from '@lightdash-tools/common';
8
+
9
+ export type ProjectParametersListResults =
10
+ components['schemas']['ApiGetProjectParametersListResults'];
11
+ export type ProjectParameterDefinitions = components['schemas']['ApiGetProjectParametersResults'];
12
+
13
+ export type ListProjectParametersParams = {
14
+ search?: string;
15
+ sortBy?: 'name';
16
+ sortOrder?: 'asc' | 'desc';
17
+ page?: number;
18
+ pageSize?: number;
19
+ };
20
+
21
+ export class ParametersClientV2 extends BaseApiClient {
22
+ /** List project parameter definitions (paginated). */
23
+ async listParameters(
24
+ projectUuid: string,
25
+ params?: ListProjectParametersParams,
26
+ ): Promise<ProjectParametersListResults> {
27
+ return this.http.get<ProjectParametersListResults>(`/projects/${projectUuid}/parameters/list`, {
28
+ params,
29
+ });
30
+ }
31
+
32
+ /** Get project parameter definitions by name. */
33
+ async getParameters(projectUuid: string, names?: string[]): Promise<ProjectParameterDefinitions> {
34
+ return this.http.get<ProjectParameterDefinitions>(`/projects/${projectUuid}/parameters`, {
35
+ params: names !== undefined ? { names } : undefined,
36
+ });
37
+ }
38
+ }
@@ -80,4 +80,22 @@ describe('QueryClientV2', () => {
80
80
  expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/underlying-data', body);
81
81
  expect(result).toEqual(results);
82
82
  });
83
+
84
+ it('getAsyncQueryResults should call GET /projects/{projectUuid}/query/{queryUuid}', async () => {
85
+ const client = new QueryClientV2(mockHttp);
86
+ const results = { queryUuid: 'q1', status: 'ready', rows: [] };
87
+ vi.mocked(mockHttp.get).mockResolvedValue(results);
88
+ const result = await client.getAsyncQueryResults('p1', 'q1', { page: 1, pageSize: 100 });
89
+ expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/query/q1', {
90
+ params: { page: 1, pageSize: 100 },
91
+ });
92
+ expect(result).toEqual(results);
93
+ });
94
+
95
+ it('cancelAsyncQuery should call POST /projects/{projectUuid}/query/{queryUuid}/cancel', async () => {
96
+ const client = new QueryClientV2(mockHttp);
97
+ vi.mocked(mockHttp.post).mockResolvedValue(undefined);
98
+ await client.cancelAsyncQuery('p1', 'q1');
99
+ expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/q1/cancel');
100
+ });
83
101
  });
@@ -13,8 +13,20 @@ import type {
13
13
  ExecuteAsyncMetricQueryResults,
14
14
  ExecuteAsyncDashboardChartResults,
15
15
  ExecuteAsyncSqlQueryResults,
16
+ components,
16
17
  } from '@lightdash-tools/common';
17
18
 
19
+ export type AsyncQueryResults = components['schemas']['ApiGetAsyncQueryResults'];
20
+ export type ExecuteAsyncSqlChartRequestParams =
21
+ components['schemas']['ExecuteAsyncSqlChartRequestParams'];
22
+ export type ExecuteAsyncDashboardSqlChartRequestParams =
23
+ components['schemas']['ExecuteAsyncDashboardSqlChartRequestParams'];
24
+
25
+ export type GetAsyncQueryResultsParams = {
26
+ page?: number;
27
+ pageSize?: number;
28
+ };
29
+
18
30
  export class QueryClientV2 extends BaseApiClient {
19
31
  /** Run a metric query (v2 endpoint). */
20
32
  async runMetricQuery(
@@ -67,4 +79,45 @@ export class QueryClientV2 extends BaseApiClient {
67
79
  body,
68
80
  );
69
81
  }
82
+
83
+ /** Run a saved SQL chart query (v2). Present for completeness; MCP content-reader keeps SQL off by default. */
84
+ async runSqlChartQuery(
85
+ projectUuid: string,
86
+ body: ExecuteAsyncSqlChartRequestParams,
87
+ ): Promise<ExecuteAsyncSqlQueryResults> {
88
+ return this.http.post<ExecuteAsyncSqlQueryResults>(
89
+ `/projects/${projectUuid}/query/sql-chart`,
90
+ body,
91
+ );
92
+ }
93
+
94
+ /** Run a dashboard SQL chart query (v2). Present for completeness; MCP content-reader keeps SQL off by default. */
95
+ async runDashboardSqlChartQuery(
96
+ projectUuid: string,
97
+ body: ExecuteAsyncDashboardSqlChartRequestParams,
98
+ ): Promise<ExecuteAsyncSqlQueryResults> {
99
+ return this.http.post<ExecuteAsyncSqlQueryResults>(
100
+ `/projects/${projectUuid}/query/dashboard-sql-chart`,
101
+ body,
102
+ );
103
+ }
104
+
105
+ /** Poll paginated async query results. */
106
+ async getAsyncQueryResults(
107
+ projectUuid: string,
108
+ queryUuid: string,
109
+ params?: GetAsyncQueryResultsParams,
110
+ ): Promise<AsyncQueryResults> {
111
+ return this.http.get<AsyncQueryResults>(
112
+ `/projects/${projectUuid}/query/${encodeURIComponent(queryUuid)}`,
113
+ { params },
114
+ );
115
+ }
116
+
117
+ /** Cancel a running async query. */
118
+ async cancelAsyncQuery(projectUuid: string, queryUuid: string): Promise<void> {
119
+ await this.http.post<unknown>(
120
+ `/projects/${projectUuid}/query/${encodeURIComponent(queryUuid)}/cancel`,
121
+ );
122
+ }
70
123
  }
@@ -42,6 +42,8 @@ describe('LightdashClient', () => {
42
42
  const client = new LightdashClient(config);
43
43
  expect(client.v2).toBeDefined();
44
44
  expect(client.v2.query).toBeDefined();
45
+ expect(client.v2.charts).toBeDefined();
46
+ expect(client.v2.parameters).toBeDefined();
45
47
  });
46
48
 
47
49
  it('v2.query.runMetricQuery should be a function', () => {
package/src/client.ts CHANGED
@@ -18,9 +18,11 @@ import { SpacesClient } from './api/v1/spaces';
18
18
  import { TagsClient } from './api/v1/tags';
19
19
  import { UsersClient } from './api/v1/users';
20
20
  import { ValidationClient } from './api/v1/validation';
21
+ import { ChartsClientV2 } from './api/v2/charts';
21
22
  import { ContentClient } from './api/v2/content';
22
23
  import { DashboardsClientV2 } from './api/v2/dashboards';
23
24
  import { OrganizationRolesClient } from './api/v2/organization-roles';
25
+ import { ParametersClientV2 } from './api/v2/parameters';
24
26
  import { ProjectRoleAssignmentsClient } from './api/v2/project-role-assignments';
25
27
  import { QueryClientV2 } from './api/v2/query';
26
28
  import { ValidationClientV2 } from './api/v2/validation';
@@ -82,6 +84,8 @@ export class V2ApiClients {
82
84
  readonly content: ContentClient;
83
85
  readonly validation: ValidationClientV2;
84
86
  readonly dashboards: DashboardsClientV2;
87
+ readonly charts: ChartsClientV2;
88
+ readonly parameters: ParametersClientV2;
85
89
 
86
90
  constructor(http: HttpClient) {
87
91
  this.query = new QueryClientV2(http);
@@ -90,6 +94,8 @@ export class V2ApiClients {
90
94
  this.content = new ContentClient(http);
91
95
  this.validation = new ValidationClientV2(http);
92
96
  this.dashboards = new DashboardsClientV2(http);
97
+ this.charts = new ChartsClientV2(http);
98
+ this.parameters = new ParametersClientV2(http);
93
99
  }
94
100
  }
95
101
 
@@ -7,26 +7,11 @@ import { type ApiErrorPayload, LightdashApiError } from '../errors';
7
7
  import { withRetry } from '../utils/retry';
8
8
 
9
9
  import { type RateLimiter } from './rate-limiter';
10
+ import { isApiSuccessEnvelope, type ApiEnvelope } from './unwrap-api-success';
10
11
 
11
12
  import type { ResolvedLightdashClientConfig } from '../config';
12
13
  import type { AxiosInstance, AxiosRequestConfig, AxiosResponse, Method } from 'axios';
13
14
 
14
- /** Lightdash API success response shape. */
15
- export interface ApiSuccessBody<T = unknown> {
16
- status: 'ok';
17
- results: T;
18
- }
19
-
20
- /** Lightdash API error response shape (body). */
21
- export interface ApiErrorBody {
22
- status: 'error';
23
- error: ApiErrorPayload['error'];
24
- }
25
-
26
- function assertSuccess<T>(data: ApiErrorBody | ApiSuccessBody<T>): data is ApiSuccessBody<T> {
27
- return data.status === 'ok';
28
- }
29
-
30
15
  /**
31
16
  * HTTP client that wraps Axios with rate limiting and retry.
32
17
  */
@@ -39,7 +24,7 @@ export class HttpClient {
39
24
 
40
25
  private async request<T>(method: Method, url: string, config?: AxiosRequestConfig): Promise<T> {
41
26
  const doRequest = () =>
42
- this.axiosInstance.request<ApiErrorBody | ApiSuccessBody<T>>({
27
+ this.axiosInstance.request<ApiEnvelope<T>>({
43
28
  ...config,
44
29
  method,
45
30
  url,
@@ -48,10 +33,10 @@ export class HttpClient {
48
33
  const response = await this.rateLimiter.schedule(() => withRetry(doRequest, this.config.retry));
49
34
 
50
35
  const data = response.data;
51
- if (!assertSuccess(data)) {
36
+ if (!isApiSuccessEnvelope(data)) {
52
37
  throw new LightdashApiError(
53
38
  data.error.statusCode,
54
- data.error,
39
+ data.error as ApiErrorPayload['error'],
55
40
  response.config,
56
41
  response as AxiosResponse<ApiErrorPayload>,
57
42
  );
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { isApiSuccessEnvelope, unwrapApiSuccessResults } from './unwrap-api-success';
4
+
5
+ describe('unwrapApiSuccessResults', () => {
6
+ it('returns results for ok envelopes', () => {
7
+ expect(unwrapApiSuccessResults({ status: 'ok', results: { id: '1' } })).toEqual({ id: '1' });
8
+ });
9
+
10
+ it('throws for error envelopes', () => {
11
+ expect(() =>
12
+ unwrapApiSuccessResults({
13
+ status: 'error',
14
+ error: { statusCode: 400, message: 'bad request' },
15
+ }),
16
+ ).toThrow(/bad request/);
17
+ });
18
+
19
+ it('narrows success envelopes', () => {
20
+ const body = { status: 'ok' as const, results: [1, 2] };
21
+ expect(isApiSuccessEnvelope(body)).toBe(true);
22
+ });
23
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Pure helpers for Lightdash API success envelopes.
3
+ * HttpClient uses `isApiSuccessEnvelope` then maps failures to `LightdashApiError`.
4
+ */
5
+
6
+ export type ApiSuccessEnvelope<T> = {
7
+ status: 'ok';
8
+ results: T;
9
+ };
10
+
11
+ export type ApiErrorEnvelope = {
12
+ status: 'error';
13
+ error: {
14
+ statusCode: number;
15
+ name?: string;
16
+ message?: string;
17
+ [key: string]: unknown;
18
+ };
19
+ };
20
+
21
+ export type ApiEnvelope<T> = ApiErrorEnvelope | ApiSuccessEnvelope<T>;
22
+
23
+ /** Type guard for Lightdash `{ status: 'ok', results }` responses. */
24
+ export function isApiSuccessEnvelope<T>(data: ApiEnvelope<T>): data is ApiSuccessEnvelope<T> {
25
+ return data.status === 'ok';
26
+ }
27
+
28
+ /**
29
+ * Unwraps a Lightdash success envelope to `results`.
30
+ * Throws a plain `Error` when `status` is not `ok` (message from `error.message` when present).
31
+ * Prefer `HttpClient` in production paths that need `LightdashApiError` + axios context.
32
+ */
33
+ export function unwrapApiSuccessResults<T>(data: ApiEnvelope<T>): T {
34
+ if (!isApiSuccessEnvelope(data)) {
35
+ const message =
36
+ typeof data.error?.message === 'string' ? data.error.message : 'Lightdash API error';
37
+ throw new Error(message);
38
+ }
39
+ return data.results;
40
+ }