@lightdash-tools/client 0.7.0 → 0.9.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.
- package/dist/api/v1/ai-agents/discovery.d.ts +7 -2
- package/dist/api/v1/ai-agents/discovery.js +3 -6
- package/dist/api/v1/ai-agents/discovery.test.js +17 -1
- package/dist/api/v1/ai-agents/facade.d.ts +5 -0
- package/dist/api/v1/ai-agents/facade.js +5 -2
- package/dist/api/v1/charts.d.ts +28 -1
- package/dist/api/v1/charts.js +51 -1
- package/dist/api/v1/charts.test.js +59 -6
- package/dist/api/v1/dashboards.d.ts +32 -1
- package/dist/api/v1/dashboards.js +20 -0
- package/dist/api/v1/dashboards.test.js +72 -0
- package/dist/api/v1/validation.d.ts +5 -1
- package/dist/api/v1/validation.js +8 -0
- package/dist/api/v1/validation.test.js +16 -0
- package/dist/api/v2/charts.d.ts +12 -0
- package/dist/api/v2/charts.js +18 -0
- package/dist/api/v2/charts.test.d.ts +4 -0
- package/dist/api/v2/charts.test.js +45 -0
- package/dist/api/v2/content.d.ts +19 -2
- package/dist/api/v2/content.js +15 -0
- package/dist/api/v2/content.test.js +41 -0
- package/dist/api/v2/dashboards.d.ts +7 -1
- package/dist/api/v2/dashboards.js +9 -1
- package/dist/api/v2/dashboards.test.js +34 -0
- package/dist/api/v2/parameters.d.ts +20 -0
- package/dist/api/v2/parameters.js +22 -0
- package/dist/api/v2/parameters.test.d.ts +4 -0
- package/dist/api/v2/parameters.test.js +39 -0
- package/dist/api/v2/query.d.ts +16 -1
- package/dist/api/v2/query.js +16 -0
- package/dist/api/v2/query.test.js +16 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.js +4 -0
- package/dist/client.test.js +2 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +37 -1
- package/dist/http/http-client.binary-url.test.d.ts +4 -0
- package/dist/http/http-client.binary-url.test.js +61 -0
- package/dist/http/http-client.d.ts +23 -11
- package/dist/http/http-client.envelope.test.d.ts +4 -0
- package/dist/http/http-client.envelope.test.js +59 -0
- package/dist/http/http-client.js +155 -6
- package/dist/http/unwrap-api-success.d.ts +26 -0
- package/dist/http/unwrap-api-success.js +25 -0
- package/dist/http/unwrap-api-success.test.d.ts +1 -0
- package/dist/http/unwrap-api-success.test.js +19 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +17 -3
- package/package.json +2 -2
- package/src/api/v1/ai-agents/discovery.test.ts +19 -1
- package/src/api/v1/ai-agents/discovery.ts +17 -3
- package/src/api/v1/ai-agents/facade.ts +17 -1
- package/src/api/v1/charts.test.ts +61 -1
- package/src/api/v1/charts.ts +68 -0
- package/src/api/v1/dashboards.test.ts +85 -0
- package/src/api/v1/dashboards.ts +86 -0
- package/src/api/v1/validation.test.ts +18 -0
- package/src/api/v1/validation.ts +21 -1
- package/src/api/v2/charts.test.ts +53 -0
- package/src/api/v2/charts.ts +23 -0
- package/src/api/v2/content.test.ts +45 -0
- package/src/api/v2/content.ts +35 -2
- package/src/api/v2/dashboards.test.ts +39 -0
- package/src/api/v2/dashboards.ts +23 -1
- package/src/api/v2/parameters.test.ts +45 -0
- package/src/api/v2/parameters.ts +38 -0
- package/src/api/v2/query.test.ts +18 -0
- package/src/api/v2/query.ts +53 -0
- package/src/client.test.ts +2 -0
- package/src/client.ts +6 -0
- package/src/errors.ts +46 -0
- package/src/http/http-client.binary-url.test.ts +88 -0
- package/src/http/http-client.envelope.test.ts +74 -0
- package/src/http/http-client.ts +194 -16
- package/src/http/unwrap-api-success.test.ts +23 -0
- package/src/http/unwrap-api-success.ts +40 -0
- package/src/index.ts +40 -2
package/src/api/v1/charts.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Charts API client. Endpoints for saved charts and chart-as-code operations.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { BinarySizeLimitError, ChartImageSizeError } from '../../errors';
|
|
6
|
+
import { DEFAULT_BINARY_MAX_BYTES } from '../../http/http-client';
|
|
5
7
|
import { BaseApiClient } from '../base-client';
|
|
6
8
|
|
|
7
9
|
import type {
|
|
@@ -9,6 +11,7 @@ import type {
|
|
|
9
11
|
ChartAsCodeListResults,
|
|
10
12
|
ChartAsCodeUpsertResults,
|
|
11
13
|
UpsertChartAsCodeBody,
|
|
14
|
+
components,
|
|
12
15
|
} from '@lightdash-tools/common';
|
|
13
16
|
|
|
14
17
|
export interface GetChartsAsCodeOptions {
|
|
@@ -17,6 +20,24 @@ export interface GetChartsAsCodeOptions {
|
|
|
17
20
|
languageMap?: boolean;
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
/** Results of GET saved/{chartUuid}/history (chart version history). */
|
|
24
|
+
export type ChartHistoryResults = components['schemas']['ApiGetChartHistoryResponse']['results'];
|
|
25
|
+
|
|
26
|
+
/** Results of GET saved/{chartUuid}/version/{versionUuid} (a single chart version). */
|
|
27
|
+
export type ChartVersionResults = components['schemas']['ApiGetChartVersionResponse']['results'];
|
|
28
|
+
|
|
29
|
+
/** Headless chart PNG export can take longer than the default HTTP timeout. */
|
|
30
|
+
export const CHART_IMAGE_EXPORT_TIMEOUT_MS = 120_000;
|
|
31
|
+
|
|
32
|
+
/** Hard cap on downloaded PNG size (8 MiB). */
|
|
33
|
+
export const CHART_IMAGE_MAX_BYTES = DEFAULT_BINARY_MAX_BYTES;
|
|
34
|
+
|
|
35
|
+
export type ChartImagePng = {
|
|
36
|
+
imageUrl: string;
|
|
37
|
+
bytes: Buffer;
|
|
38
|
+
mimeType: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
20
41
|
export class ChartsClient extends BaseApiClient {
|
|
21
42
|
/**
|
|
22
43
|
* List charts in a project (returns SpaceQuery array).
|
|
@@ -52,4 +73,51 @@ export class ChartsClient extends BaseApiClient {
|
|
|
52
73
|
body,
|
|
53
74
|
);
|
|
54
75
|
}
|
|
76
|
+
|
|
77
|
+
/** Get chart version history from the last 30 days. */
|
|
78
|
+
async getChartHistory(chartUuid: string): Promise<ChartHistoryResults> {
|
|
79
|
+
return this.http.get<ChartHistoryResults>(`/saved/${chartUuid}/history`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Get a single chart version by UUID. */
|
|
83
|
+
async getChartVersion(chartUuid: string, versionUuid: string): Promise<ChartVersionResults> {
|
|
84
|
+
return this.http.get<ChartVersionResults>(`/saved/${chartUuid}/version/${versionUuid}`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Export a saved chart as a PNG via headless render.
|
|
89
|
+
* @returns Image URL string from `ApiExportChartImageResponse.results`.
|
|
90
|
+
*/
|
|
91
|
+
async exportChartImage(chartUuid: string, projectUuid?: string): Promise<string> {
|
|
92
|
+
return this.http.post<string>(`/saved/${encodeURIComponent(chartUuid)}/export`, undefined, {
|
|
93
|
+
params: projectUuid ? { projectUuid } : undefined,
|
|
94
|
+
timeout: CHART_IMAGE_EXPORT_TIMEOUT_MS,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Export a saved chart PNG and download the image bytes.
|
|
100
|
+
* Requires Lightdash headless browser support on the instance.
|
|
101
|
+
*/
|
|
102
|
+
async exportChartImagePng(chartUuid: string, projectUuid?: string): Promise<ChartImagePng> {
|
|
103
|
+
const imageUrl = await this.exportChartImage(chartUuid, projectUuid);
|
|
104
|
+
let bytes: Buffer;
|
|
105
|
+
let mimeType: string;
|
|
106
|
+
try {
|
|
107
|
+
({ bytes, mimeType } = await this.http.getBytes(imageUrl, {
|
|
108
|
+
maxBytes: CHART_IMAGE_MAX_BYTES,
|
|
109
|
+
timeout: CHART_IMAGE_EXPORT_TIMEOUT_MS,
|
|
110
|
+
}));
|
|
111
|
+
} catch (err) {
|
|
112
|
+
if (err instanceof BinarySizeLimitError) {
|
|
113
|
+
throw new ChartImageSizeError(err.maxBytes, err.byteLength);
|
|
114
|
+
}
|
|
115
|
+
throw err;
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
imageUrl,
|
|
119
|
+
bytes,
|
|
120
|
+
mimeType: mimeType === 'application/octet-stream' ? 'image/png' : mimeType,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
55
123
|
}
|
|
@@ -80,4 +80,89 @@ describe('DashboardsClient', () => {
|
|
|
80
80
|
await client.upsertDashboardAsCode('p1', 'dash/slug', body);
|
|
81
81
|
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/dashboards/dash%2Fslug', body);
|
|
82
82
|
});
|
|
83
|
+
|
|
84
|
+
it('createDashboard should call POST /projects/{projectUuid}/dashboards with body and no params by default', async () => {
|
|
85
|
+
const client = new DashboardsClient(mockHttp);
|
|
86
|
+
const body = { name: 'New Dashboard', tiles: [], tabs: [] } as Parameters<
|
|
87
|
+
DashboardsClient['createDashboard']
|
|
88
|
+
>[1];
|
|
89
|
+
const created = { uuid: 'd1', name: 'New Dashboard', projectUuid: 'p1' };
|
|
90
|
+
vi.mocked(mockHttp.post).mockResolvedValue(created);
|
|
91
|
+
const result = await client.createDashboard('p1', body);
|
|
92
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/dashboards', body, undefined);
|
|
93
|
+
expect(result).toEqual(created);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('createDashboard should call POST with duplicateFrom query param when provided', async () => {
|
|
97
|
+
const client = new DashboardsClient(mockHttp);
|
|
98
|
+
const body = { dashboardDesc: 'Copy', dashboardName: 'Copy of Dashboard' } as Parameters<
|
|
99
|
+
DashboardsClient['createDashboard']
|
|
100
|
+
>[1];
|
|
101
|
+
vi.mocked(mockHttp.post).mockResolvedValue({});
|
|
102
|
+
await client.createDashboard('p1', body, { duplicateFrom: 'd0' });
|
|
103
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/dashboards', body, {
|
|
104
|
+
params: { duplicateFrom: 'd0' },
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('getDashboardHistory should call GET /dashboards/{dashboardUuidOrSlug}/history', async () => {
|
|
109
|
+
const client = new DashboardsClient(mockHttp);
|
|
110
|
+
const history = { dashboardUuid: 'd1', history: [] };
|
|
111
|
+
vi.mocked(mockHttp.get).mockResolvedValue(history);
|
|
112
|
+
const result = await client.getDashboardHistory('d1');
|
|
113
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/history');
|
|
114
|
+
expect(result).toEqual(history);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('getDashboardHistory should encode slug in path', async () => {
|
|
118
|
+
const client = new DashboardsClient(mockHttp);
|
|
119
|
+
vi.mocked(mockHttp.get).mockResolvedValue({});
|
|
120
|
+
await client.getDashboardHistory('dash/slug');
|
|
121
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/dash%2Fslug/history');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('getDashboardVersion should call GET /dashboards/{dashboardUuidOrSlug}/version/{versionUuid}', async () => {
|
|
125
|
+
const client = new DashboardsClient(mockHttp);
|
|
126
|
+
const version = { dashboardUuid: 'd1', versionUuid: 'v1' };
|
|
127
|
+
vi.mocked(mockHttp.get).mockResolvedValue(version);
|
|
128
|
+
const result = await client.getDashboardVersion('d1', 'v1');
|
|
129
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/version/v1');
|
|
130
|
+
expect(result).toEqual(version);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('getDashboardPromoteDiff should call GET /dashboards/{id}/promoteDiff', async () => {
|
|
134
|
+
const client = new DashboardsClient(mockHttp);
|
|
135
|
+
const diff = { charts: [], dashboards: [], spaces: [] };
|
|
136
|
+
vi.mocked(mockHttp.get).mockResolvedValue(diff);
|
|
137
|
+
const result = await client.getDashboardPromoteDiff('d1');
|
|
138
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/promoteDiff', undefined);
|
|
139
|
+
expect(result).toEqual(diff);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('getDashboardPromoteDiff should pass projectUuid query and encode slug', async () => {
|
|
143
|
+
const client = new DashboardsClient(mockHttp);
|
|
144
|
+
vi.mocked(mockHttp.get).mockResolvedValue({ charts: [], dashboards: [], spaces: [] });
|
|
145
|
+
await client.getDashboardPromoteDiff('dash/slug', { projectUuid: 'p1' });
|
|
146
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/dash%2Fslug/promoteDiff', {
|
|
147
|
+
params: { projectUuid: 'p1' },
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('promoteDashboard should call POST /dashboards/{id}/promote', async () => {
|
|
152
|
+
const client = new DashboardsClient(mockHttp);
|
|
153
|
+
const promoted = { uuid: 'd1', name: 'Board', projectUuid: 'upstream' };
|
|
154
|
+
vi.mocked(mockHttp.post).mockResolvedValue(promoted);
|
|
155
|
+
const result = await client.promoteDashboard('d1');
|
|
156
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/dashboards/d1/promote', undefined, undefined);
|
|
157
|
+
expect(result).toEqual(promoted);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('promoteDashboard should pass projectUuid query and encode slug', async () => {
|
|
161
|
+
const client = new DashboardsClient(mockHttp);
|
|
162
|
+
vi.mocked(mockHttp.post).mockResolvedValue({});
|
|
163
|
+
await client.promoteDashboard('dash/slug', { projectUuid: 'p1' });
|
|
164
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/dashboards/dash%2Fslug/promote', undefined, {
|
|
165
|
+
params: { projectUuid: 'p1' },
|
|
166
|
+
});
|
|
167
|
+
});
|
|
83
168
|
});
|
package/src/api/v1/dashboards.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
DashboardAsCodeListResults,
|
|
10
10
|
DashboardAsCodeUpsertResults,
|
|
11
11
|
UpsertDashboardAsCodeBody,
|
|
12
|
+
components,
|
|
12
13
|
} from '@lightdash-tools/common';
|
|
13
14
|
|
|
14
15
|
export interface GetDashboardsAsCodeOptions {
|
|
@@ -17,6 +18,38 @@ export interface GetDashboardsAsCodeOptions {
|
|
|
17
18
|
languageMap?: boolean;
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
/** Request body for POST projects/{projectUuid}/dashboards (create dashboard, or duplicate via query param). */
|
|
22
|
+
export type CreateDashboardBody =
|
|
23
|
+
components['schemas']['CreateDashboard'] | components['schemas']['DuplicateDashboardParams'];
|
|
24
|
+
|
|
25
|
+
/** Options for createDashboard. */
|
|
26
|
+
export interface CreateDashboardOptions {
|
|
27
|
+
/** UUID of an existing dashboard to duplicate from. When set, body should be DuplicateDashboardParams. */
|
|
28
|
+
duplicateFrom?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Result of POST projects/{projectUuid}/dashboards (create dashboard). */
|
|
32
|
+
export type CreateDashboardResult = components['schemas']['ApiCreateDashboardResponse']['results'];
|
|
33
|
+
|
|
34
|
+
/** Results of GET dashboards/{dashboardUuidOrSlug}/history (dashboard version history). */
|
|
35
|
+
export type DashboardHistoryResults =
|
|
36
|
+
components['schemas']['ApiGetDashboardHistoryResponse']['results'];
|
|
37
|
+
|
|
38
|
+
/** Results of GET dashboards/{dashboardUuidOrSlug}/version/{versionUuid} (a single dashboard version). */
|
|
39
|
+
export type DashboardVersionResults =
|
|
40
|
+
components['schemas']['ApiGetDashboardVersionResponse']['results'];
|
|
41
|
+
|
|
42
|
+
/** Results of GET dashboards/{dashboardUuidOrSlug}/promoteDiff. */
|
|
43
|
+
export type DashboardPromoteDiffResults = components['schemas']['PromotionChanges'];
|
|
44
|
+
|
|
45
|
+
/** Results of POST dashboards/{dashboardUuidOrSlug}/promote. */
|
|
46
|
+
export type PromoteDashboardResult = components['schemas']['DashboardDAO'];
|
|
47
|
+
|
|
48
|
+
/** Optional query for promote / promoteDiff when a slug exists in multiple projects. */
|
|
49
|
+
export interface DashboardPromoteOptions {
|
|
50
|
+
projectUuid?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
20
53
|
export class DashboardsClient extends BaseApiClient {
|
|
21
54
|
/** List dashboards in a project. */
|
|
22
55
|
async listDashboards(projectUuid: string): Promise<DashboardBasicDetailsWithTileTypes[]> {
|
|
@@ -51,4 +84,57 @@ export class DashboardsClient extends BaseApiClient {
|
|
|
51
84
|
body,
|
|
52
85
|
);
|
|
53
86
|
}
|
|
87
|
+
|
|
88
|
+
/** Create a new dashboard in a project, or duplicate an existing one via `duplicateFrom`. */
|
|
89
|
+
async createDashboard(
|
|
90
|
+
projectUuid: string,
|
|
91
|
+
body: CreateDashboardBody,
|
|
92
|
+
options?: CreateDashboardOptions,
|
|
93
|
+
): Promise<CreateDashboardResult> {
|
|
94
|
+
return this.http.post<CreateDashboardResult>(
|
|
95
|
+
`/projects/${projectUuid}/dashboards`,
|
|
96
|
+
body,
|
|
97
|
+
options?.duplicateFrom ? { params: { duplicateFrom: options.duplicateFrom } } : undefined,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Get dashboard version history from the last 30 days. */
|
|
102
|
+
async getDashboardHistory(dashboardUuidOrSlug: string): Promise<DashboardHistoryResults> {
|
|
103
|
+
return this.http.get<DashboardHistoryResults>(
|
|
104
|
+
`/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}/history`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Get a single dashboard version by UUID. */
|
|
109
|
+
async getDashboardVersion(
|
|
110
|
+
dashboardUuidOrSlug: string,
|
|
111
|
+
versionUuid: string,
|
|
112
|
+
): Promise<DashboardVersionResults> {
|
|
113
|
+
return this.http.get<DashboardVersionResults>(
|
|
114
|
+
`/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}/version/${versionUuid}`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Get promotion diff for a dashboard against its configured upstream project. */
|
|
119
|
+
async getDashboardPromoteDiff(
|
|
120
|
+
dashboardUuidOrSlug: string,
|
|
121
|
+
options?: DashboardPromoteOptions,
|
|
122
|
+
): Promise<DashboardPromoteDiffResults> {
|
|
123
|
+
return this.http.get<DashboardPromoteDiffResults>(
|
|
124
|
+
`/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}/promoteDiff`,
|
|
125
|
+
options?.projectUuid ? { params: { projectUuid: options.projectUuid } } : undefined,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Promote a dashboard (and nested charts) to its configured upstream project. */
|
|
130
|
+
async promoteDashboard(
|
|
131
|
+
dashboardUuidOrSlug: string,
|
|
132
|
+
options?: DashboardPromoteOptions,
|
|
133
|
+
): Promise<PromoteDashboardResult> {
|
|
134
|
+
return this.http.post<PromoteDashboardResult>(
|
|
135
|
+
`/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}/promote`,
|
|
136
|
+
undefined,
|
|
137
|
+
options?.projectUuid ? { params: { projectUuid: options.projectUuid } } : undefined,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
54
140
|
}
|
|
@@ -36,4 +36,22 @@ describe('ValidationClient', () => {
|
|
|
36
36
|
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/validate', undefined);
|
|
37
37
|
expect(result).toEqual(mockResponse);
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
it('validateChart should call POST /projects/{projectUuid}/validate/chart/{chartUuid}', async () => {
|
|
41
|
+
const client = new ValidationClient(mockHttp);
|
|
42
|
+
const mockResponse = { errors: [] };
|
|
43
|
+
vi.mocked(mockHttp.post).mockResolvedValue(mockResponse);
|
|
44
|
+
const result = await client.validateChart('p1', 'c1');
|
|
45
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/validate/chart/c1');
|
|
46
|
+
expect(result).toEqual(mockResponse);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('validateDashboard should call POST /projects/{projectUuid}/validate/dashboard/{dashboardUuid}', async () => {
|
|
50
|
+
const client = new ValidationClient(mockHttp);
|
|
51
|
+
const mockResponse = { errors: [] };
|
|
52
|
+
vi.mocked(mockHttp.post).mockResolvedValue(mockResponse);
|
|
53
|
+
const result = await client.validateDashboard('p1', 'd1');
|
|
54
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/validate/dashboard/d1');
|
|
55
|
+
expect(result).toEqual(mockResponse);
|
|
56
|
+
});
|
|
39
57
|
});
|
package/src/api/v1/validation.ts
CHANGED
|
@@ -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
|
});
|
package/src/api/v2/content.ts
CHANGED
|
@@ -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
|
});
|
package/src/api/v2/dashboards.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Dashboards API client (v2). Metadata reads
|
|
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
|
+
});
|