@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.
Files changed (77) hide show
  1. package/dist/api/v1/ai-agents/discovery.d.ts +7 -2
  2. package/dist/api/v1/ai-agents/discovery.js +3 -6
  3. package/dist/api/v1/ai-agents/discovery.test.js +17 -1
  4. package/dist/api/v1/ai-agents/facade.d.ts +5 -0
  5. package/dist/api/v1/ai-agents/facade.js +5 -2
  6. package/dist/api/v1/charts.d.ts +28 -1
  7. package/dist/api/v1/charts.js +51 -1
  8. package/dist/api/v1/charts.test.js +59 -6
  9. package/dist/api/v1/dashboards.d.ts +32 -1
  10. package/dist/api/v1/dashboards.js +20 -0
  11. package/dist/api/v1/dashboards.test.js +72 -0
  12. package/dist/api/v1/validation.d.ts +5 -1
  13. package/dist/api/v1/validation.js +8 -0
  14. package/dist/api/v1/validation.test.js +16 -0
  15. package/dist/api/v2/charts.d.ts +12 -0
  16. package/dist/api/v2/charts.js +18 -0
  17. package/dist/api/v2/charts.test.d.ts +4 -0
  18. package/dist/api/v2/charts.test.js +45 -0
  19. package/dist/api/v2/content.d.ts +19 -2
  20. package/dist/api/v2/content.js +15 -0
  21. package/dist/api/v2/content.test.js +41 -0
  22. package/dist/api/v2/dashboards.d.ts +7 -1
  23. package/dist/api/v2/dashboards.js +9 -1
  24. package/dist/api/v2/dashboards.test.js +34 -0
  25. package/dist/api/v2/parameters.d.ts +20 -0
  26. package/dist/api/v2/parameters.js +22 -0
  27. package/dist/api/v2/parameters.test.d.ts +4 -0
  28. package/dist/api/v2/parameters.test.js +39 -0
  29. package/dist/api/v2/query.d.ts +16 -1
  30. package/dist/api/v2/query.js +16 -0
  31. package/dist/api/v2/query.test.js +16 -0
  32. package/dist/client.d.ts +4 -0
  33. package/dist/client.js +4 -0
  34. package/dist/client.test.js +2 -0
  35. package/dist/errors.d.ts +22 -0
  36. package/dist/errors.js +37 -1
  37. package/dist/http/http-client.binary-url.test.d.ts +4 -0
  38. package/dist/http/http-client.binary-url.test.js +61 -0
  39. package/dist/http/http-client.d.ts +23 -11
  40. package/dist/http/http-client.envelope.test.d.ts +4 -0
  41. package/dist/http/http-client.envelope.test.js +59 -0
  42. package/dist/http/http-client.js +155 -6
  43. package/dist/http/unwrap-api-success.d.ts +26 -0
  44. package/dist/http/unwrap-api-success.js +25 -0
  45. package/dist/http/unwrap-api-success.test.d.ts +1 -0
  46. package/dist/http/unwrap-api-success.test.js +19 -0
  47. package/dist/index.d.ts +9 -2
  48. package/dist/index.js +17 -3
  49. package/package.json +2 -2
  50. package/src/api/v1/ai-agents/discovery.test.ts +19 -1
  51. package/src/api/v1/ai-agents/discovery.ts +17 -3
  52. package/src/api/v1/ai-agents/facade.ts +17 -1
  53. package/src/api/v1/charts.test.ts +61 -1
  54. package/src/api/v1/charts.ts +68 -0
  55. package/src/api/v1/dashboards.test.ts +85 -0
  56. package/src/api/v1/dashboards.ts +86 -0
  57. package/src/api/v1/validation.test.ts +18 -0
  58. package/src/api/v1/validation.ts +21 -1
  59. package/src/api/v2/charts.test.ts +53 -0
  60. package/src/api/v2/charts.ts +23 -0
  61. package/src/api/v2/content.test.ts +45 -0
  62. package/src/api/v2/content.ts +35 -2
  63. package/src/api/v2/dashboards.test.ts +39 -0
  64. package/src/api/v2/dashboards.ts +23 -1
  65. package/src/api/v2/parameters.test.ts +45 -0
  66. package/src/api/v2/parameters.ts +38 -0
  67. package/src/api/v2/query.test.ts +18 -0
  68. package/src/api/v2/query.ts +53 -0
  69. package/src/client.test.ts +2 -0
  70. package/src/client.ts +6 -0
  71. package/src/errors.ts +46 -0
  72. package/src/http/http-client.binary-url.test.ts +88 -0
  73. package/src/http/http-client.envelope.test.ts +74 -0
  74. package/src/http/http-client.ts +194 -16
  75. package/src/http/unwrap-api-success.test.ts +23 -0
  76. package/src/http/unwrap-api-success.ts +40 -0
  77. package/src/index.ts +40 -2
@@ -13,9 +13,14 @@ export declare class AiAgentsDiscoveryClient extends BaseApiClient {
13
13
  evaluateAgentReadiness(projectUuid: string, agentUuid: string): Promise<ReadinessScore>;
14
14
  /**
15
15
  * Summarize explore access for tag-filtered explores
16
- * (POST …/explore-access-summary).
16
+ * (POST …/explore-access-summary). Project-scoped; no agent path segment.
17
17
  */
18
- getExploreAccessSummary(projectUuid: string, _agentUuid: string, body?: ExploreAccessSummaryBody): Promise<AiAgentExploreAccessSummary[]>;
18
+ getExploreAccessSummary(projectUuid: string, body?: ExploreAccessSummaryBody): Promise<AiAgentExploreAccessSummary[]>;
19
+ /**
20
+ * @deprecated `agentUuid` is ignored; the endpoint is project-scoped.
21
+ * Prefer `getExploreAccessSummary(projectUuid, body?)`.
22
+ */
23
+ getExploreAccessSummary(projectUuid: string, agentUuid: string, body?: ExploreAccessSummaryBody): Promise<AiAgentExploreAccessSummary[]>;
19
24
  /**
20
25
  * Get user default agent preferences (GET …/preferences).
21
26
  * Returns null when the user has not set preferences (`ApiSuccessEmpty`).
@@ -19,12 +19,9 @@ class AiAgentsDiscoveryClient extends base_client_1.BaseApiClient {
19
19
  async evaluateAgentReadiness(projectUuid, agentUuid) {
20
20
  return this.http.post(`/projects/${projectUuid}/aiAgents/${agentUuid}/evaluateReadiness`, {});
21
21
  }
22
- /**
23
- * Summarize explore access for tag-filtered explores
24
- * (POST …/explore-access-summary).
25
- */
26
- async getExploreAccessSummary(projectUuid, _agentUuid, body) {
27
- return this.http.post(`/projects/${projectUuid}/aiAgents/explore-access-summary`, body !== null && body !== void 0 ? body : { tags: null });
22
+ async getExploreAccessSummary(projectUuid, agentUuidOrBody, body) {
23
+ const resolvedBody = typeof agentUuidOrBody === 'string' ? body : agentUuidOrBody;
24
+ return this.http.post(`/projects/${projectUuid}/aiAgents/explore-access-summary`, resolvedBody !== null && resolvedBody !== void 0 ? resolvedBody : { tags: null });
28
25
  }
29
26
  /**
30
27
  * Get user default agent preferences (GET …/preferences).
@@ -46,13 +46,29 @@ const discovery_1 = require("./discovery");
46
46
  const client = new discovery_1.AiAgentsDiscoveryClient(mockHttp);
47
47
  const summary = [{ exploreName: 'orders', metrics: [], dimensions: [], joinedTables: [] }];
48
48
  vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(summary);
49
- const result = await client.getExploreAccessSummary('proj1', 'a1', { tags: ['ai'] });
49
+ const result = await client.getExploreAccessSummary('proj1', { tags: ['ai'] });
50
50
  (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/explore-access-summary', {
51
51
  tags: ['ai'],
52
52
  });
53
53
  (0, vitest_1.expect)(result).toEqual(summary);
54
54
  });
55
55
  (0, vitest_1.it)('getExploreAccessSummary without body should default tags to null', async () => {
56
+ const client = new discovery_1.AiAgentsDiscoveryClient(mockHttp);
57
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue([]);
58
+ await client.getExploreAccessSummary('proj1');
59
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/explore-access-summary', {
60
+ tags: null,
61
+ });
62
+ });
63
+ (0, vitest_1.it)('getExploreAccessSummary legacy (project, agentUuid, body) ignores agentUuid', async () => {
64
+ const client = new discovery_1.AiAgentsDiscoveryClient(mockHttp);
65
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue([]);
66
+ await client.getExploreAccessSummary('proj1', 'a1', { tags: ['ai'] });
67
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/explore-access-summary', {
68
+ tags: ['ai'],
69
+ });
70
+ });
71
+ (0, vitest_1.it)('getExploreAccessSummary legacy (project, agentUuid) defaults tags to null', async () => {
56
72
  const client = new discovery_1.AiAgentsDiscoveryClient(mockHttp);
57
73
  vitest_1.vi.mocked(mockHttp.post).mockResolvedValue([]);
58
74
  await client.getExploreAccessSummary('proj1', 'a1');
@@ -30,6 +30,11 @@ export declare class AiAgentsClient extends BaseApiClient {
30
30
  getAgentModelOptions(projectUuid: string, agentUuid: string): Promise<AiModelOption[]>;
31
31
  getAgentSuggestions(projectUuid: string, agentUuid: string, params?: GetAgentSuggestionsParams): Promise<AgentSuggestions>;
32
32
  evaluateAgentReadiness(projectUuid: string, agentUuid: string): Promise<ReadinessScore>;
33
+ getExploreAccessSummary(projectUuid: string, body?: ExploreAccessSummaryBody): Promise<AiAgentExploreAccessSummary[]>;
34
+ /**
35
+ * @deprecated `agentUuid` is ignored; the endpoint is project-scoped.
36
+ * Prefer `getExploreAccessSummary(projectUuid, body?)`.
37
+ */
33
38
  getExploreAccessSummary(projectUuid: string, agentUuid: string, body?: ExploreAccessSummaryBody): Promise<AiAgentExploreAccessSummary[]>;
34
39
  getUserAgentPreferences(projectUuid: string): Promise<AiAgentUserPreferences | null>;
35
40
  setUserAgentPreferences(projectUuid: string, body: AiAgentUserPreferences): Promise<void>;
@@ -67,8 +67,11 @@ class AiAgentsClient extends base_client_1.BaseApiClient {
67
67
  evaluateAgentReadiness(projectUuid, agentUuid) {
68
68
  return this.discovery.evaluateAgentReadiness(projectUuid, agentUuid);
69
69
  }
70
- getExploreAccessSummary(projectUuid, agentUuid, body) {
71
- return this.discovery.getExploreAccessSummary(projectUuid, agentUuid, body);
70
+ getExploreAccessSummary(projectUuid, agentUuidOrBody, body) {
71
+ if (typeof agentUuidOrBody === 'string') {
72
+ return this.discovery.getExploreAccessSummary(projectUuid, agentUuidOrBody, body);
73
+ }
74
+ return this.discovery.getExploreAccessSummary(projectUuid, agentUuidOrBody);
72
75
  }
73
76
  getUserAgentPreferences(projectUuid) {
74
77
  return this.discovery.getUserAgentPreferences(projectUuid);
@@ -2,12 +2,25 @@
2
2
  * Charts API client. Endpoints for saved charts and chart-as-code operations.
3
3
  */
4
4
  import { BaseApiClient } from '../base-client';
5
- import type { SpaceQuery, ChartAsCodeListResults, ChartAsCodeUpsertResults, UpsertChartAsCodeBody } from '@lightdash-tools/common';
5
+ import type { SpaceQuery, ChartAsCodeListResults, ChartAsCodeUpsertResults, UpsertChartAsCodeBody, components } from '@lightdash-tools/common';
6
6
  export interface GetChartsAsCodeOptions {
7
7
  ids?: string[];
8
8
  offset?: number;
9
9
  languageMap?: boolean;
10
10
  }
11
+ /** Results of GET saved/{chartUuid}/history (chart version history). */
12
+ export type ChartHistoryResults = components['schemas']['ApiGetChartHistoryResponse']['results'];
13
+ /** Results of GET saved/{chartUuid}/version/{versionUuid} (a single chart version). */
14
+ export type ChartVersionResults = components['schemas']['ApiGetChartVersionResponse']['results'];
15
+ /** Headless chart PNG export can take longer than the default HTTP timeout. */
16
+ export declare const CHART_IMAGE_EXPORT_TIMEOUT_MS = 120000;
17
+ /** Hard cap on downloaded PNG size (8 MiB). */
18
+ export declare const CHART_IMAGE_MAX_BYTES: number;
19
+ export type ChartImagePng = {
20
+ imageUrl: string;
21
+ bytes: Buffer;
22
+ mimeType: string;
23
+ };
11
24
  export declare class ChartsClient extends BaseApiClient {
12
25
  /**
13
26
  * List charts in a project (returns SpaceQuery array).
@@ -18,4 +31,18 @@ export declare class ChartsClient extends BaseApiClient {
18
31
  getChartsAsCode(projectUuid: string, options?: GetChartsAsCodeOptions): Promise<ChartAsCodeListResults>;
19
32
  /** Upsert a chart from code representation (create or update by slug). */
20
33
  upsertChartAsCode(projectUuid: string, slug: string, body: UpsertChartAsCodeBody): Promise<ChartAsCodeUpsertResults>;
34
+ /** Get chart version history from the last 30 days. */
35
+ getChartHistory(chartUuid: string): Promise<ChartHistoryResults>;
36
+ /** Get a single chart version by UUID. */
37
+ getChartVersion(chartUuid: string, versionUuid: string): Promise<ChartVersionResults>;
38
+ /**
39
+ * Export a saved chart as a PNG via headless render.
40
+ * @returns Image URL string from `ApiExportChartImageResponse.results`.
41
+ */
42
+ exportChartImage(chartUuid: string, projectUuid?: string): Promise<string>;
43
+ /**
44
+ * Export a saved chart PNG and download the image bytes.
45
+ * Requires Lightdash headless browser support on the instance.
46
+ */
47
+ exportChartImagePng(chartUuid: string, projectUuid?: string): Promise<ChartImagePng>;
21
48
  }
@@ -3,8 +3,14 @@
3
3
  * Charts API client. Endpoints for saved charts and chart-as-code operations.
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ChartsClient = void 0;
6
+ exports.ChartsClient = exports.CHART_IMAGE_MAX_BYTES = exports.CHART_IMAGE_EXPORT_TIMEOUT_MS = void 0;
7
+ const errors_1 = require("../../errors");
8
+ const http_client_1 = require("../../http/http-client");
7
9
  const base_client_1 = require("../base-client");
10
+ /** Headless chart PNG export can take longer than the default HTTP timeout. */
11
+ exports.CHART_IMAGE_EXPORT_TIMEOUT_MS = 120000;
12
+ /** Hard cap on downloaded PNG size (8 MiB). */
13
+ exports.CHART_IMAGE_MAX_BYTES = http_client_1.DEFAULT_BINARY_MAX_BYTES;
8
14
  class ChartsClient extends base_client_1.BaseApiClient {
9
15
  /**
10
16
  * List charts in a project (returns SpaceQuery array).
@@ -29,5 +35,49 @@ class ChartsClient extends base_client_1.BaseApiClient {
29
35
  async upsertChartAsCode(projectUuid, slug, body) {
30
36
  return this.http.post(`/projects/${projectUuid}/code/charts/${encodeURIComponent(slug)}`, body);
31
37
  }
38
+ /** Get chart version history from the last 30 days. */
39
+ async getChartHistory(chartUuid) {
40
+ return this.http.get(`/saved/${chartUuid}/history`);
41
+ }
42
+ /** Get a single chart version by UUID. */
43
+ async getChartVersion(chartUuid, versionUuid) {
44
+ return this.http.get(`/saved/${chartUuid}/version/${versionUuid}`);
45
+ }
46
+ /**
47
+ * Export a saved chart as a PNG via headless render.
48
+ * @returns Image URL string from `ApiExportChartImageResponse.results`.
49
+ */
50
+ async exportChartImage(chartUuid, projectUuid) {
51
+ return this.http.post(`/saved/${encodeURIComponent(chartUuid)}/export`, undefined, {
52
+ params: projectUuid ? { projectUuid } : undefined,
53
+ timeout: exports.CHART_IMAGE_EXPORT_TIMEOUT_MS,
54
+ });
55
+ }
56
+ /**
57
+ * Export a saved chart PNG and download the image bytes.
58
+ * Requires Lightdash headless browser support on the instance.
59
+ */
60
+ async exportChartImagePng(chartUuid, projectUuid) {
61
+ const imageUrl = await this.exportChartImage(chartUuid, projectUuid);
62
+ let bytes;
63
+ let mimeType;
64
+ try {
65
+ ({ bytes, mimeType } = await this.http.getBytes(imageUrl, {
66
+ maxBytes: exports.CHART_IMAGE_MAX_BYTES,
67
+ timeout: exports.CHART_IMAGE_EXPORT_TIMEOUT_MS,
68
+ }));
69
+ }
70
+ catch (err) {
71
+ if (err instanceof errors_1.BinarySizeLimitError) {
72
+ throw new errors_1.ChartImageSizeError(err.maxBytes, err.byteLength);
73
+ }
74
+ throw err;
75
+ }
76
+ return {
77
+ imageUrl,
78
+ bytes,
79
+ mimeType: mimeType === 'application/octet-stream' ? 'image/png' : mimeType,
80
+ };
81
+ }
32
82
  }
33
83
  exports.ChartsClient = ChartsClient;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const vitest_1 = require("vitest");
4
- const charts_1 = require("./charts");
4
+ const errors_js_1 = require("../../errors.js");
5
+ const charts_js_1 = require("./charts.js");
5
6
  (0, vitest_1.describe)('ChartsClient', () => {
6
7
  let mockHttp;
7
8
  (0, vitest_1.beforeEach)(() => {
@@ -11,10 +12,11 @@ const charts_1 = require("./charts");
11
12
  put: vitest_1.vi.fn(),
12
13
  patch: vitest_1.vi.fn(),
13
14
  delete: vitest_1.vi.fn(),
15
+ getBytes: vitest_1.vi.fn(),
14
16
  };
15
17
  });
16
18
  (0, vitest_1.it)('listCharts should call GET /projects/{projectUuid}/charts', async () => {
17
- const client = new charts_1.ChartsClient(mockHttp);
19
+ const client = new charts_js_1.ChartsClient(mockHttp);
18
20
  const charts = [{ uuid: 'c1', name: 'Chart 1', projectUuid: 'p1' }];
19
21
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(charts);
20
22
  const result = await client.listCharts('p1');
@@ -22,7 +24,7 @@ const charts_1 = require("./charts");
22
24
  (0, vitest_1.expect)(result).toEqual(charts);
23
25
  });
24
26
  (0, vitest_1.it)('getChartsAsCode should call GET /projects/{projectUuid}/code/charts with no params when no options', async () => {
25
- const client = new charts_1.ChartsClient(mockHttp);
27
+ const client = new charts_js_1.ChartsClient(mockHttp);
26
28
  const results = { offset: 0, total: 1, missingIds: [], charts: [] };
27
29
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
28
30
  const result = await client.getChartsAsCode('p1');
@@ -30,7 +32,7 @@ const charts_1 = require("./charts");
30
32
  (0, vitest_1.expect)(result).toEqual(results);
31
33
  });
32
34
  (0, vitest_1.it)('getChartsAsCode should call GET with query params when options provided', async () => {
33
- const client = new charts_1.ChartsClient(mockHttp);
35
+ const client = new charts_js_1.ChartsClient(mockHttp);
34
36
  const results = { offset: 0, total: 0, missingIds: [], charts: [] };
35
37
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
36
38
  await client.getChartsAsCode('p1', {
@@ -43,7 +45,7 @@ const charts_1 = require("./charts");
43
45
  });
44
46
  });
45
47
  (0, vitest_1.it)('upsertChartAsCode should call POST /projects/{projectUuid}/code/charts/{slug} with body', async () => {
46
- const client = new charts_1.ChartsClient(mockHttp);
48
+ const client = new charts_js_1.ChartsClient(mockHttp);
47
49
  const body = {
48
50
  name: 'My Chart',
49
51
  slug: 'my-chart',
@@ -70,7 +72,7 @@ const charts_1 = require("./charts");
70
72
  (0, vitest_1.expect)(result).toEqual(apiResult);
71
73
  });
72
74
  (0, vitest_1.it)('upsertChartAsCode should encode slug in path', async () => {
73
- const client = new charts_1.ChartsClient(mockHttp);
75
+ const client = new charts_js_1.ChartsClient(mockHttp);
74
76
  const body = {
75
77
  name: 'Chart',
76
78
  slug: 'chart/slug',
@@ -94,4 +96,55 @@ const charts_1 = require("./charts");
94
96
  await client.upsertChartAsCode('p1', 'chart/slug', body);
95
97
  (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/chart%2Fslug', body);
96
98
  });
99
+ (0, vitest_1.it)('getChartHistory should call GET /saved/{chartUuid}/history', async () => {
100
+ const client = new charts_js_1.ChartsClient(mockHttp);
101
+ const history = { chartUuid: 'c1', history: [] };
102
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(history);
103
+ const result = await client.getChartHistory('c1');
104
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/saved/c1/history');
105
+ (0, vitest_1.expect)(result).toEqual(history);
106
+ });
107
+ (0, vitest_1.it)('getChartVersion should call GET /saved/{chartUuid}/version/{versionUuid}', async () => {
108
+ const client = new charts_js_1.ChartsClient(mockHttp);
109
+ const version = { chartUuid: 'c1', versionUuid: 'v1' };
110
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(version);
111
+ const result = await client.getChartVersion('c1', 'v1');
112
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/saved/c1/version/v1');
113
+ (0, vitest_1.expect)(result).toEqual(version);
114
+ });
115
+ (0, vitest_1.it)('exportChartImage should POST /saved/{chartUuid}/export and return URL', async () => {
116
+ const client = new charts_js_1.ChartsClient(mockHttp);
117
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue('https://cdn.example/chart.png');
118
+ const result = await client.exportChartImage('c1', 'p1');
119
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/saved/c1/export', undefined, {
120
+ params: { projectUuid: 'p1' },
121
+ timeout: 120000,
122
+ });
123
+ (0, vitest_1.expect)(result).toBe('https://cdn.example/chart.png');
124
+ });
125
+ (0, vitest_1.it)('exportChartImagePng should export then download bytes', async () => {
126
+ const client = new charts_js_1.ChartsClient(mockHttp);
127
+ const png = Buffer.from([0x89, 0x50, 0x4e, 0x47]);
128
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue('https://cdn.example/chart.png');
129
+ vitest_1.vi.mocked(mockHttp.getBytes).mockResolvedValue({ bytes: png, mimeType: 'image/png' });
130
+ const result = await client.exportChartImagePng('c1');
131
+ (0, vitest_1.expect)(mockHttp.getBytes).toHaveBeenCalledWith('https://cdn.example/chart.png', {
132
+ maxBytes: 8 * 1024 * 1024,
133
+ timeout: 120000,
134
+ });
135
+ (0, vitest_1.expect)(result).toEqual({
136
+ imageUrl: 'https://cdn.example/chart.png',
137
+ bytes: png,
138
+ mimeType: 'image/png',
139
+ });
140
+ });
141
+ (0, vitest_1.it)('exportChartImagePng maps BinarySizeLimitError to ChartImageSizeError', async () => {
142
+ const client = new charts_js_1.ChartsClient(mockHttp);
143
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue('https://cdn.example/chart.png');
144
+ vitest_1.vi.mocked(mockHttp.getBytes).mockRejectedValue(new errors_js_1.BinarySizeLimitError(8 * 1024 * 1024));
145
+ await (0, vitest_1.expect)(client.exportChartImagePng('c1')).rejects.toMatchObject({
146
+ code: 'IMAGE_TOO_LARGE',
147
+ maxBytes: 8 * 1024 * 1024,
148
+ });
149
+ });
97
150
  });
@@ -2,12 +2,33 @@
2
2
  * Dashboards API client. Endpoints for project dashboards and dashboard-as-code operations.
3
3
  */
4
4
  import { BaseApiClient } from '../base-client';
5
- import type { DashboardBasicDetailsWithTileTypes, DashboardAsCodeListResults, DashboardAsCodeUpsertResults, UpsertDashboardAsCodeBody } from '@lightdash-tools/common';
5
+ import type { DashboardBasicDetailsWithTileTypes, DashboardAsCodeListResults, DashboardAsCodeUpsertResults, UpsertDashboardAsCodeBody, components } from '@lightdash-tools/common';
6
6
  export interface GetDashboardsAsCodeOptions {
7
7
  ids?: string[];
8
8
  offset?: number;
9
9
  languageMap?: boolean;
10
10
  }
11
+ /** Request body for POST projects/{projectUuid}/dashboards (create dashboard, or duplicate via query param). */
12
+ export type CreateDashboardBody = components['schemas']['CreateDashboard'] | components['schemas']['DuplicateDashboardParams'];
13
+ /** Options for createDashboard. */
14
+ export interface CreateDashboardOptions {
15
+ /** UUID of an existing dashboard to duplicate from. When set, body should be DuplicateDashboardParams. */
16
+ duplicateFrom?: string;
17
+ }
18
+ /** Result of POST projects/{projectUuid}/dashboards (create dashboard). */
19
+ export type CreateDashboardResult = components['schemas']['ApiCreateDashboardResponse']['results'];
20
+ /** Results of GET dashboards/{dashboardUuidOrSlug}/history (dashboard version history). */
21
+ export type DashboardHistoryResults = components['schemas']['ApiGetDashboardHistoryResponse']['results'];
22
+ /** Results of GET dashboards/{dashboardUuidOrSlug}/version/{versionUuid} (a single dashboard version). */
23
+ export type DashboardVersionResults = components['schemas']['ApiGetDashboardVersionResponse']['results'];
24
+ /** Results of GET dashboards/{dashboardUuidOrSlug}/promoteDiff. */
25
+ export type DashboardPromoteDiffResults = components['schemas']['PromotionChanges'];
26
+ /** Results of POST dashboards/{dashboardUuidOrSlug}/promote. */
27
+ export type PromoteDashboardResult = components['schemas']['DashboardDAO'];
28
+ /** Optional query for promote / promoteDiff when a slug exists in multiple projects. */
29
+ export interface DashboardPromoteOptions {
30
+ projectUuid?: string;
31
+ }
11
32
  export declare class DashboardsClient extends BaseApiClient {
12
33
  /** List dashboards in a project. */
13
34
  listDashboards(projectUuid: string): Promise<DashboardBasicDetailsWithTileTypes[]>;
@@ -15,4 +36,14 @@ export declare class DashboardsClient extends BaseApiClient {
15
36
  getDashboardsAsCode(projectUuid: string, options?: GetDashboardsAsCodeOptions): Promise<DashboardAsCodeListResults>;
16
37
  /** Upsert a dashboard from code representation (create or update by slug). */
17
38
  upsertDashboardAsCode(projectUuid: string, slug: string, body: UpsertDashboardAsCodeBody): Promise<DashboardAsCodeUpsertResults>;
39
+ /** Create a new dashboard in a project, or duplicate an existing one via `duplicateFrom`. */
40
+ createDashboard(projectUuid: string, body: CreateDashboardBody, options?: CreateDashboardOptions): Promise<CreateDashboardResult>;
41
+ /** Get dashboard version history from the last 30 days. */
42
+ getDashboardHistory(dashboardUuidOrSlug: string): Promise<DashboardHistoryResults>;
43
+ /** Get a single dashboard version by UUID. */
44
+ getDashboardVersion(dashboardUuidOrSlug: string, versionUuid: string): Promise<DashboardVersionResults>;
45
+ /** Get promotion diff for a dashboard against its configured upstream project. */
46
+ getDashboardPromoteDiff(dashboardUuidOrSlug: string, options?: DashboardPromoteOptions): Promise<DashboardPromoteDiffResults>;
47
+ /** Promote a dashboard (and nested charts) to its configured upstream project. */
48
+ promoteDashboard(dashboardUuidOrSlug: string, options?: DashboardPromoteOptions): Promise<PromoteDashboardResult>;
18
49
  }
@@ -26,5 +26,25 @@ class DashboardsClient extends base_client_1.BaseApiClient {
26
26
  async upsertDashboardAsCode(projectUuid, slug, body) {
27
27
  return this.http.post(`/projects/${projectUuid}/code/dashboards/${encodeURIComponent(slug)}`, body);
28
28
  }
29
+ /** Create a new dashboard in a project, or duplicate an existing one via `duplicateFrom`. */
30
+ async createDashboard(projectUuid, body, options) {
31
+ return this.http.post(`/projects/${projectUuid}/dashboards`, body, (options === null || options === void 0 ? void 0 : options.duplicateFrom) ? { params: { duplicateFrom: options.duplicateFrom } } : undefined);
32
+ }
33
+ /** Get dashboard version history from the last 30 days. */
34
+ async getDashboardHistory(dashboardUuidOrSlug) {
35
+ return this.http.get(`/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}/history`);
36
+ }
37
+ /** Get a single dashboard version by UUID. */
38
+ async getDashboardVersion(dashboardUuidOrSlug, versionUuid) {
39
+ return this.http.get(`/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}/version/${versionUuid}`);
40
+ }
41
+ /** Get promotion diff for a dashboard against its configured upstream project. */
42
+ async getDashboardPromoteDiff(dashboardUuidOrSlug, options) {
43
+ return this.http.get(`/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}/promoteDiff`, (options === null || options === void 0 ? void 0 : options.projectUuid) ? { params: { projectUuid: options.projectUuid } } : undefined);
44
+ }
45
+ /** Promote a dashboard (and nested charts) to its configured upstream project. */
46
+ async promoteDashboard(dashboardUuidOrSlug, options) {
47
+ return this.http.post(`/dashboards/${encodeURIComponent(dashboardUuidOrSlug)}/promote`, undefined, (options === null || options === void 0 ? void 0 : options.projectUuid) ? { params: { projectUuid: options.projectUuid } } : undefined);
48
+ }
29
49
  }
30
50
  exports.DashboardsClient = DashboardsClient;
@@ -72,4 +72,76 @@ const dashboards_1 = require("./dashboards");
72
72
  await client.upsertDashboardAsCode('p1', 'dash/slug', body);
73
73
  (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/dashboards/dash%2Fslug', body);
74
74
  });
75
+ (0, vitest_1.it)('createDashboard should call POST /projects/{projectUuid}/dashboards with body and no params by default', async () => {
76
+ const client = new dashboards_1.DashboardsClient(mockHttp);
77
+ const body = { name: 'New Dashboard', tiles: [], tabs: [] };
78
+ const created = { uuid: 'd1', name: 'New Dashboard', projectUuid: 'p1' };
79
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(created);
80
+ const result = await client.createDashboard('p1', body);
81
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/dashboards', body, undefined);
82
+ (0, vitest_1.expect)(result).toEqual(created);
83
+ });
84
+ (0, vitest_1.it)('createDashboard should call POST with duplicateFrom query param when provided', async () => {
85
+ const client = new dashboards_1.DashboardsClient(mockHttp);
86
+ const body = { dashboardDesc: 'Copy', dashboardName: 'Copy of Dashboard' };
87
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({});
88
+ await client.createDashboard('p1', body, { duplicateFrom: 'd0' });
89
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/dashboards', body, {
90
+ params: { duplicateFrom: 'd0' },
91
+ });
92
+ });
93
+ (0, vitest_1.it)('getDashboardHistory should call GET /dashboards/{dashboardUuidOrSlug}/history', async () => {
94
+ const client = new dashboards_1.DashboardsClient(mockHttp);
95
+ const history = { dashboardUuid: 'd1', history: [] };
96
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(history);
97
+ const result = await client.getDashboardHistory('d1');
98
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/history');
99
+ (0, vitest_1.expect)(result).toEqual(history);
100
+ });
101
+ (0, vitest_1.it)('getDashboardHistory should encode slug in path', async () => {
102
+ const client = new dashboards_1.DashboardsClient(mockHttp);
103
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue({});
104
+ await client.getDashboardHistory('dash/slug');
105
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/dashboards/dash%2Fslug/history');
106
+ });
107
+ (0, vitest_1.it)('getDashboardVersion should call GET /dashboards/{dashboardUuidOrSlug}/version/{versionUuid}', async () => {
108
+ const client = new dashboards_1.DashboardsClient(mockHttp);
109
+ const version = { dashboardUuid: 'd1', versionUuid: 'v1' };
110
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(version);
111
+ const result = await client.getDashboardVersion('d1', 'v1');
112
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/version/v1');
113
+ (0, vitest_1.expect)(result).toEqual(version);
114
+ });
115
+ (0, vitest_1.it)('getDashboardPromoteDiff should call GET /dashboards/{id}/promoteDiff', async () => {
116
+ const client = new dashboards_1.DashboardsClient(mockHttp);
117
+ const diff = { charts: [], dashboards: [], spaces: [] };
118
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(diff);
119
+ const result = await client.getDashboardPromoteDiff('d1');
120
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/promoteDiff', undefined);
121
+ (0, vitest_1.expect)(result).toEqual(diff);
122
+ });
123
+ (0, vitest_1.it)('getDashboardPromoteDiff should pass projectUuid query and encode slug', async () => {
124
+ const client = new dashboards_1.DashboardsClient(mockHttp);
125
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue({ charts: [], dashboards: [], spaces: [] });
126
+ await client.getDashboardPromoteDiff('dash/slug', { projectUuid: 'p1' });
127
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/dashboards/dash%2Fslug/promoteDiff', {
128
+ params: { projectUuid: 'p1' },
129
+ });
130
+ });
131
+ (0, vitest_1.it)('promoteDashboard should call POST /dashboards/{id}/promote', async () => {
132
+ const client = new dashboards_1.DashboardsClient(mockHttp);
133
+ const promoted = { uuid: 'd1', name: 'Board', projectUuid: 'upstream' };
134
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(promoted);
135
+ const result = await client.promoteDashboard('d1');
136
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/dashboards/d1/promote', undefined, undefined);
137
+ (0, vitest_1.expect)(result).toEqual(promoted);
138
+ });
139
+ (0, vitest_1.it)('promoteDashboard should pass projectUuid query and encode slug', async () => {
140
+ const client = new dashboards_1.DashboardsClient(mockHttp);
141
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({});
142
+ await client.promoteDashboard('dash/slug', { projectUuid: 'p1' });
143
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/dashboards/dash%2Fslug/promote', undefined, {
144
+ params: { projectUuid: 'p1' },
145
+ });
146
+ });
75
147
  });
@@ -2,7 +2,7 @@
2
2
  * Validation API client.
3
3
  */
4
4
  import { BaseApiClient } from '../base-client';
5
- import type { LightdashApi } from '@lightdash-tools/common';
5
+ import type { components, LightdashApi } from '@lightdash-tools/common';
6
6
  /** Query params for getting validation results. */
7
7
  export interface GetValidationResultsParams {
8
8
  fromSettings?: boolean;
@@ -22,4 +22,8 @@ export declare class ValidationClient extends BaseApiClient {
22
22
  getValidationResults(projectUuid: string, params?: GetValidationResultsParams): Promise<LightdashApi.Validation.ApiValidateResponse>;
23
23
  /** Validate content inside a project. Starts a validation job and returns the job ID. */
24
24
  validateProject(projectUuid: string, body?: ValidateProjectBody): Promise<LightdashApi.Validation.ApiJobScheduledResponse>;
25
+ /** Validate a single chart's fields against its underlying explore/table. */
26
+ validateChart(projectUuid: string, chartUuid: string): Promise<components['schemas']['ApiChartValidationResponse']['results']>;
27
+ /** Validate a single dashboard's fields against its underlying explores/tables. */
28
+ validateDashboard(projectUuid: string, dashboardUuid: string): Promise<components['schemas']['ApiDashboardValidationResponse']['results']>;
25
29
  }
@@ -17,5 +17,13 @@ class ValidationClient extends base_client_1.BaseApiClient {
17
17
  async validateProject(projectUuid, body) {
18
18
  return this.http.post(`/projects/${projectUuid}/validate`, body);
19
19
  }
20
+ /** Validate a single chart's fields against its underlying explore/table. */
21
+ async validateChart(projectUuid, chartUuid) {
22
+ return this.http.post(`/projects/${projectUuid}/validate/chart/${chartUuid}`);
23
+ }
24
+ /** Validate a single dashboard's fields against its underlying explores/tables. */
25
+ async validateDashboard(projectUuid, dashboardUuid) {
26
+ return this.http.post(`/projects/${projectUuid}/validate/dashboard/${dashboardUuid}`);
27
+ }
20
28
  }
21
29
  exports.ValidationClient = ValidationClient;
@@ -31,4 +31,20 @@ const validation_1 = require("./validation");
31
31
  (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/validate', undefined);
32
32
  (0, vitest_1.expect)(result).toEqual(mockResponse);
33
33
  });
34
+ (0, vitest_1.it)('validateChart should call POST /projects/{projectUuid}/validate/chart/{chartUuid}', async () => {
35
+ const client = new validation_1.ValidationClient(mockHttp);
36
+ const mockResponse = { errors: [] };
37
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(mockResponse);
38
+ const result = await client.validateChart('p1', 'c1');
39
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/validate/chart/c1');
40
+ (0, vitest_1.expect)(result).toEqual(mockResponse);
41
+ });
42
+ (0, vitest_1.it)('validateDashboard should call POST /projects/{projectUuid}/validate/dashboard/{dashboardUuid}', async () => {
43
+ const client = new validation_1.ValidationClient(mockHttp);
44
+ const mockResponse = { errors: [] };
45
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(mockResponse);
46
+ const result = await client.validateDashboard('p1', 'd1');
47
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/validate/dashboard/d1');
48
+ (0, vitest_1.expect)(result).toEqual(mockResponse);
49
+ });
34
50
  });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Charts API client (v2). Metadata reads and soft-delete (no query execution).
3
+ */
4
+ import { BaseApiClient } from '../base-client';
5
+ import type { components } from '@lightdash-tools/common';
6
+ export type SavedChart = components['schemas']['SavedChart'];
7
+ export declare class ChartsClientV2 extends BaseApiClient {
8
+ /** Get saved chart metadata by UUID or slug within a project. Does not run queries. */
9
+ getSavedChart(projectUuid: string, chartUuidOrSlug: string): Promise<SavedChart>;
10
+ /** Soft-delete a saved chart by UUID or slug within a project. */
11
+ deleteSavedChart(projectUuid: string, chartUuidOrSlug: string): Promise<void>;
12
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ /**
3
+ * Charts API client (v2). Metadata reads and soft-delete (no query execution).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ChartsClientV2 = void 0;
7
+ const base_client_1 = require("../base-client");
8
+ class ChartsClientV2 extends base_client_1.BaseApiClient {
9
+ /** Get saved chart metadata by UUID or slug within a project. Does not run queries. */
10
+ async getSavedChart(projectUuid, chartUuidOrSlug) {
11
+ return this.http.get(`/projects/${projectUuid}/saved/${encodeURIComponent(chartUuidOrSlug)}`);
12
+ }
13
+ /** Soft-delete a saved chart by UUID or slug within a project. */
14
+ async deleteSavedChart(projectUuid, chartUuidOrSlug) {
15
+ await this.http.delete(`/projects/${projectUuid}/saved/${encodeURIComponent(chartUuidOrSlug)}`);
16
+ }
17
+ }
18
+ exports.ChartsClientV2 = ChartsClientV2;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * V2 charts client unit tests.
3
+ */
4
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /**
3
+ * V2 charts client unit tests.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const vitest_1 = require("vitest");
7
+ const charts_1 = require("./charts");
8
+ (0, vitest_1.describe)('ChartsClientV2', () => {
9
+ let mockHttp;
10
+ (0, vitest_1.beforeEach)(() => {
11
+ mockHttp = {
12
+ get: vitest_1.vi.fn(),
13
+ post: vitest_1.vi.fn(),
14
+ put: vitest_1.vi.fn(),
15
+ patch: vitest_1.vi.fn(),
16
+ delete: vitest_1.vi.fn(),
17
+ };
18
+ });
19
+ (0, vitest_1.it)('getSavedChart calls GET /projects/{projectUuid}/saved/{id}', async () => {
20
+ const client = new charts_1.ChartsClientV2(mockHttp);
21
+ const mockResponse = { uuid: 'c1', name: 'Revenue' };
22
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
23
+ const result = await client.getSavedChart('p1', 'c1');
24
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/saved/c1');
25
+ (0, vitest_1.expect)(result).toEqual(mockResponse);
26
+ });
27
+ (0, vitest_1.it)('getSavedChart encodes slug path segments', async () => {
28
+ const client = new charts_1.ChartsClientV2(mockHttp);
29
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue({ uuid: 'c1' });
30
+ await client.getSavedChart('p1', 'my/chart');
31
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/saved/my%2Fchart');
32
+ });
33
+ (0, vitest_1.it)('deleteSavedChart calls DELETE /projects/{projectUuid}/saved/{id}', async () => {
34
+ const client = new charts_1.ChartsClientV2(mockHttp);
35
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
36
+ await client.deleteSavedChart('p1', 'c1');
37
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/saved/c1');
38
+ });
39
+ (0, vitest_1.it)('deleteSavedChart encodes slug path segments', async () => {
40
+ const client = new charts_1.ChartsClientV2(mockHttp);
41
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
42
+ await client.deleteSavedChart('p1', 'my/chart');
43
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/saved/my%2Fchart');
44
+ });
45
+ });