@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
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * V2 parameters client unit tests.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const vitest_1 = require("vitest");
7
+ const parameters_1 = require("./parameters");
8
+ (0, vitest_1.describe)('ParametersClientV2', () => {
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)('listParameters calls GET /projects/{projectUuid}/parameters/list', async () => {
20
+ const client = new parameters_1.ParametersClientV2(mockHttp);
21
+ const mockResponse = { data: [], pagination: {} };
22
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
23
+ const result = await client.listParameters('p1', { search: 'region', page: 1 });
24
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/parameters/list', {
25
+ params: { search: 'region', page: 1 },
26
+ });
27
+ (0, vitest_1.expect)(result).toEqual(mockResponse);
28
+ });
29
+ (0, vitest_1.it)('getParameters calls GET /projects/{projectUuid}/parameters', async () => {
30
+ const client = new parameters_1.ParametersClientV2(mockHttp);
31
+ const mockResponse = { region: { type: 'string' } };
32
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
33
+ const result = await client.getParameters('p1', ['region']);
34
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/parameters', {
35
+ params: { names: ['region'] },
36
+ });
37
+ (0, vitest_1.expect)(result).toEqual(mockResponse);
38
+ });
39
+ });
@@ -2,7 +2,14 @@
2
2
  * Query API client for v2 endpoints. Run metric/SQL/underlying data queries using v2 API.
3
3
  */
4
4
  import { BaseApiClient } from '../base-client';
5
- import type { ExecuteAsyncMetricQueryRequestParams, ExecuteAsyncSqlQueryRequestParams, ExecuteAsyncSavedChartRequestParams, ExecuteAsyncDashboardChartRequestParams, ExecuteAsyncUnderlyingDataRequestParams, ExecuteAsyncMetricQueryResults, ExecuteAsyncDashboardChartResults, ExecuteAsyncSqlQueryResults } from '@lightdash-tools/common';
5
+ import type { ExecuteAsyncMetricQueryRequestParams, ExecuteAsyncSqlQueryRequestParams, ExecuteAsyncSavedChartRequestParams, ExecuteAsyncDashboardChartRequestParams, ExecuteAsyncUnderlyingDataRequestParams, ExecuteAsyncMetricQueryResults, ExecuteAsyncDashboardChartResults, ExecuteAsyncSqlQueryResults, components } from '@lightdash-tools/common';
6
+ export type AsyncQueryResults = components['schemas']['ApiGetAsyncQueryResults'];
7
+ export type ExecuteAsyncSqlChartRequestParams = components['schemas']['ExecuteAsyncSqlChartRequestParams'];
8
+ export type ExecuteAsyncDashboardSqlChartRequestParams = components['schemas']['ExecuteAsyncDashboardSqlChartRequestParams'];
9
+ export type GetAsyncQueryResultsParams = {
10
+ page?: number;
11
+ pageSize?: number;
12
+ };
6
13
  export declare class QueryClientV2 extends BaseApiClient {
7
14
  /** Run a metric query (v2 endpoint). */
8
15
  runMetricQuery(projectUuid: string, body: ExecuteAsyncMetricQueryRequestParams): Promise<ExecuteAsyncMetricQueryResults>;
@@ -14,4 +21,12 @@ export declare class QueryClientV2 extends BaseApiClient {
14
21
  runDashboardChartQuery(projectUuid: string, body: ExecuteAsyncDashboardChartRequestParams): Promise<ExecuteAsyncDashboardChartResults>;
15
22
  /** Run an underlying data query (v2 endpoint). */
16
23
  runUnderlyingDataQuery(projectUuid: string, body: ExecuteAsyncUnderlyingDataRequestParams): Promise<ExecuteAsyncMetricQueryResults>;
24
+ /** Run a saved SQL chart query (v2). Present for completeness; MCP content-reader keeps SQL off by default. */
25
+ runSqlChartQuery(projectUuid: string, body: ExecuteAsyncSqlChartRequestParams): Promise<ExecuteAsyncSqlQueryResults>;
26
+ /** Run a dashboard SQL chart query (v2). Present for completeness; MCP content-reader keeps SQL off by default. */
27
+ runDashboardSqlChartQuery(projectUuid: string, body: ExecuteAsyncDashboardSqlChartRequestParams): Promise<ExecuteAsyncSqlQueryResults>;
28
+ /** Poll paginated async query results. */
29
+ getAsyncQueryResults(projectUuid: string, queryUuid: string, params?: GetAsyncQueryResultsParams): Promise<AsyncQueryResults>;
30
+ /** Cancel a running async query. */
31
+ cancelAsyncQuery(projectUuid: string, queryUuid: string): Promise<void>;
17
32
  }
@@ -26,5 +26,21 @@ class QueryClientV2 extends base_client_1.BaseApiClient {
26
26
  async runUnderlyingDataQuery(projectUuid, body) {
27
27
  return this.http.post(`/projects/${projectUuid}/query/underlying-data`, body);
28
28
  }
29
+ /** Run a saved SQL chart query (v2). Present for completeness; MCP content-reader keeps SQL off by default. */
30
+ async runSqlChartQuery(projectUuid, body) {
31
+ return this.http.post(`/projects/${projectUuid}/query/sql-chart`, body);
32
+ }
33
+ /** Run a dashboard SQL chart query (v2). Present for completeness; MCP content-reader keeps SQL off by default. */
34
+ async runDashboardSqlChartQuery(projectUuid, body) {
35
+ return this.http.post(`/projects/${projectUuid}/query/dashboard-sql-chart`, body);
36
+ }
37
+ /** Poll paginated async query results. */
38
+ async getAsyncQueryResults(projectUuid, queryUuid, params) {
39
+ return this.http.get(`/projects/${projectUuid}/query/${encodeURIComponent(queryUuid)}`, { params });
40
+ }
41
+ /** Cancel a running async query. */
42
+ async cancelAsyncQuery(projectUuid, queryUuid) {
43
+ await this.http.post(`/projects/${projectUuid}/query/${encodeURIComponent(queryUuid)}/cancel`);
44
+ }
29
45
  }
30
46
  exports.QueryClientV2 = QueryClientV2;
@@ -66,4 +66,20 @@ const query_1 = require("./query");
66
66
  (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/underlying-data', body);
67
67
  (0, vitest_1.expect)(result).toEqual(results);
68
68
  });
69
+ (0, vitest_1.it)('getAsyncQueryResults should call GET /projects/{projectUuid}/query/{queryUuid}', async () => {
70
+ const client = new query_1.QueryClientV2(mockHttp);
71
+ const results = { queryUuid: 'q1', status: 'ready', rows: [] };
72
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
73
+ const result = await client.getAsyncQueryResults('p1', 'q1', { page: 1, pageSize: 100 });
74
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/query/q1', {
75
+ params: { page: 1, pageSize: 100 },
76
+ });
77
+ (0, vitest_1.expect)(result).toEqual(results);
78
+ });
79
+ (0, vitest_1.it)('cancelAsyncQuery should call POST /projects/{projectUuid}/query/{queryUuid}/cancel', async () => {
80
+ const client = new query_1.QueryClientV2(mockHttp);
81
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(undefined);
82
+ await client.cancelAsyncQuery('p1', 'q1');
83
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/q1/cancel');
84
+ });
69
85
  });
package/dist/client.d.ts CHANGED
@@ -17,9 +17,11 @@ import { SpacesClient } from './api/v1/spaces';
17
17
  import { TagsClient } from './api/v1/tags';
18
18
  import { UsersClient } from './api/v1/users';
19
19
  import { ValidationClient } from './api/v1/validation';
20
+ import { ChartsClientV2 } from './api/v2/charts';
20
21
  import { ContentClient } from './api/v2/content';
21
22
  import { DashboardsClientV2 } from './api/v2/dashboards';
22
23
  import { OrganizationRolesClient } from './api/v2/organization-roles';
24
+ import { ParametersClientV2 } from './api/v2/parameters';
23
25
  import { ProjectRoleAssignmentsClient } from './api/v2/project-role-assignments';
24
26
  import { QueryClientV2 } from './api/v2/query';
25
27
  import { ValidationClientV2 } from './api/v2/validation';
@@ -57,6 +59,8 @@ export declare class V2ApiClients {
57
59
  readonly content: ContentClient;
58
60
  readonly validation: ValidationClientV2;
59
61
  readonly dashboards: DashboardsClientV2;
62
+ readonly charts: ChartsClientV2;
63
+ readonly parameters: ParametersClientV2;
60
64
  constructor(http: HttpClient);
61
65
  }
62
66
  /**
package/dist/client.js CHANGED
@@ -20,9 +20,11 @@ const spaces_1 = require("./api/v1/spaces");
20
20
  const tags_1 = require("./api/v1/tags");
21
21
  const users_1 = require("./api/v1/users");
22
22
  const validation_1 = require("./api/v1/validation");
23
+ const charts_2 = require("./api/v2/charts");
23
24
  const content_1 = require("./api/v2/content");
24
25
  const dashboards_2 = require("./api/v2/dashboards");
25
26
  const organization_roles_1 = require("./api/v2/organization-roles");
27
+ const parameters_1 = require("./api/v2/parameters");
26
28
  const project_role_assignments_1 = require("./api/v2/project-role-assignments");
27
29
  const query_2 = require("./api/v2/query");
28
30
  const validation_2 = require("./api/v2/validation");
@@ -65,6 +67,8 @@ class V2ApiClients {
65
67
  this.content = new content_1.ContentClient(http);
66
68
  this.validation = new validation_2.ValidationClientV2(http);
67
69
  this.dashboards = new dashboards_2.DashboardsClientV2(http);
70
+ this.charts = new charts_2.ChartsClientV2(http);
71
+ this.parameters = new parameters_1.ParametersClientV2(http);
68
72
  }
69
73
  }
70
74
  exports.V2ApiClients = V2ApiClients;
@@ -37,6 +37,8 @@ const client_1 = require("./client");
37
37
  const client = new client_1.LightdashClient(config);
38
38
  (0, vitest_1.expect)(client.v2).toBeDefined();
39
39
  (0, vitest_1.expect)(client.v2.query).toBeDefined();
40
+ (0, vitest_1.expect)(client.v2.charts).toBeDefined();
41
+ (0, vitest_1.expect)(client.v2.parameters).toBeDefined();
40
42
  });
41
43
  (0, vitest_1.it)('v2.query.runMetricQuery should be a function', () => {
42
44
  const client = new client_1.LightdashClient(config);
@@ -2,20 +2,9 @@
2
2
  * HTTP client wrapper: rate limiter + axios + retry.
3
3
  * All requests go through the rate limiter; retry applies to 5xx and network errors.
4
4
  */
5
- import { type ApiErrorPayload } from '../errors';
6
5
  import { type RateLimiter } from './rate-limiter';
7
6
  import type { ResolvedLightdashClientConfig } from '../config';
8
7
  import type { AxiosInstance, AxiosRequestConfig } from 'axios';
9
- /** Lightdash API success response shape. */
10
- export interface ApiSuccessBody<T = unknown> {
11
- status: 'ok';
12
- results: T;
13
- }
14
- /** Lightdash API error response shape (body). */
15
- export interface ApiErrorBody {
16
- status: 'error';
17
- error: ApiErrorPayload['error'];
18
- }
19
8
  /**
20
9
  * HTTP client that wraps Axios with rate limiting and retry.
21
10
  */
@@ -7,9 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.HttpClient = void 0;
8
8
  const errors_1 = require("../errors");
9
9
  const retry_1 = require("../utils/retry");
10
- function assertSuccess(data) {
11
- return data.status === 'ok';
12
- }
10
+ const unwrap_api_success_1 = require("./unwrap-api-success");
13
11
  /**
14
12
  * HTTP client that wraps Axios with rate limiting and retry.
15
13
  */
@@ -24,7 +22,7 @@ class HttpClient {
24
22
  url }));
25
23
  const response = await this.rateLimiter.schedule(() => (0, retry_1.withRetry)(doRequest, this.config.retry));
26
24
  const data = response.data;
27
- if (!assertSuccess(data)) {
25
+ if (!(0, unwrap_api_success_1.isApiSuccessEnvelope)(data)) {
28
26
  throw new errors_1.LightdashApiError(data.error.statusCode, data.error, response.config, response);
29
27
  }
30
28
  return data.results;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Pure helpers for Lightdash API success envelopes.
3
+ * HttpClient uses `isApiSuccessEnvelope` then maps failures to `LightdashApiError`.
4
+ */
5
+ export type ApiSuccessEnvelope<T> = {
6
+ status: 'ok';
7
+ results: T;
8
+ };
9
+ export type ApiErrorEnvelope = {
10
+ status: 'error';
11
+ error: {
12
+ statusCode: number;
13
+ name?: string;
14
+ message?: string;
15
+ [key: string]: unknown;
16
+ };
17
+ };
18
+ export type ApiEnvelope<T> = ApiErrorEnvelope | ApiSuccessEnvelope<T>;
19
+ /** Type guard for Lightdash `{ status: 'ok', results }` responses. */
20
+ export declare function isApiSuccessEnvelope<T>(data: ApiEnvelope<T>): data is ApiSuccessEnvelope<T>;
21
+ /**
22
+ * Unwraps a Lightdash success envelope to `results`.
23
+ * Throws a plain `Error` when `status` is not `ok` (message from `error.message` when present).
24
+ * Prefer `HttpClient` in production paths that need `LightdashApiError` + axios context.
25
+ */
26
+ export declare function unwrapApiSuccessResults<T>(data: ApiEnvelope<T>): T;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Pure helpers for Lightdash API success envelopes.
4
+ * HttpClient uses `isApiSuccessEnvelope` then maps failures to `LightdashApiError`.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isApiSuccessEnvelope = isApiSuccessEnvelope;
8
+ exports.unwrapApiSuccessResults = unwrapApiSuccessResults;
9
+ /** Type guard for Lightdash `{ status: 'ok', results }` responses. */
10
+ function isApiSuccessEnvelope(data) {
11
+ return data.status === 'ok';
12
+ }
13
+ /**
14
+ * Unwraps a Lightdash success envelope to `results`.
15
+ * Throws a plain `Error` when `status` is not `ok` (message from `error.message` when present).
16
+ * Prefer `HttpClient` in production paths that need `LightdashApiError` + axios context.
17
+ */
18
+ function unwrapApiSuccessResults(data) {
19
+ var _a;
20
+ if (!isApiSuccessEnvelope(data)) {
21
+ const message = typeof ((_a = data.error) === null || _a === void 0 ? void 0 : _a.message) === 'string' ? data.error.message : 'Lightdash API error';
22
+ throw new Error(message);
23
+ }
24
+ return data.results;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const unwrap_api_success_1 = require("./unwrap-api-success");
5
+ (0, vitest_1.describe)('unwrapApiSuccessResults', () => {
6
+ (0, vitest_1.it)('returns results for ok envelopes', () => {
7
+ (0, vitest_1.expect)((0, unwrap_api_success_1.unwrapApiSuccessResults)({ status: 'ok', results: { id: '1' } })).toEqual({ id: '1' });
8
+ });
9
+ (0, vitest_1.it)('throws for error envelopes', () => {
10
+ (0, vitest_1.expect)(() => (0, unwrap_api_success_1.unwrapApiSuccessResults)({
11
+ status: 'error',
12
+ error: { statusCode: 400, message: 'bad request' },
13
+ })).toThrow(/bad request/);
14
+ });
15
+ (0, vitest_1.it)('narrows success envelopes', () => {
16
+ const body = { status: 'ok', results: [1, 2] };
17
+ (0, vitest_1.expect)((0, unwrap_api_success_1.isApiSuccessEnvelope)(body)).toBe(true);
18
+ });
19
+ });
package/dist/index.d.ts CHANGED
@@ -13,13 +13,17 @@ export { SchedulersClient } from './api/v1/schedulers';
13
13
  export { TagsClient } from './api/v1/tags';
14
14
  export { AnalyticsClient } from './api/v1/analytics';
15
15
  export { ContentClient } from './api/v2/content';
16
+ export { ChartsClientV2 } from './api/v2/charts';
16
17
  export { DashboardsClientV2 } from './api/v2/dashboards';
17
18
  export type { ListMembersParams, ListAllMembersParams } from './api/v1/users';
18
19
  export type { GetValidationResultsParams, ValidateProjectBody } from './api/v1/validation';
19
20
  export type { ListValidationResultsParams } from './api/v2/validation';
20
21
  export type { ListMetricsParams } from './api/v1/metrics';
21
22
  export type { ListSchedulersParams } from './api/v1/schedulers';
22
- export type { SearchContentParams } from './api/v2/content';
23
+ export type { BulkMoveContentBody, MoveContentBody, PermanentlyDeleteContentBody, SearchContentParams, } from './api/v2/content';
24
+ export type { SavedChart } from './api/v2/charts';
25
+ export type { Dashboard, UpdateDashboardBody } from './api/v2/dashboards';
26
+ export type { DashboardPromoteDiffResults, DashboardPromoteOptions, PromoteDashboardResult, } from './api/v1/dashboards';
23
27
  export type { ListGroupsParams, ListAllGroupsParams, GetGroupParams, GroupOrGroupWithMembers, } from './api/v1/groups';
24
28
  export type { GetRolesResult, GetRolesParams, AssignOrgRoleToUserBody, } from './api/v2/organization-roles';
25
29
  export type { PartialLightdashClientConfig } from './config';
@@ -31,6 +35,7 @@ export type { ApiErrorPayload } from './errors';
31
35
  export { loadConfigFromEnv, mergeConfig, createBearerConfig } from './utils/env';
32
36
  export { ENV_LIGHTDASH_API_KEY, ENV_LIGHTDASH_URL, ENV_LIGHTDASH_PROXY_AUTHORIZATION, } from './utils/env';
33
37
  export { HttpClient } from './http/http-client';
38
+ export { isApiSuccessEnvelope, unwrapApiSuccessResults, type ApiEnvelope, type ApiErrorEnvelope, type ApiSuccessEnvelope, } from './http/unwrap-api-success';
34
39
  export { RateLimiter } from './http/rate-limiter';
35
40
  export { SecretString } from './utils/secret-string';
36
41
  export type { ApiResponseOk, ApiResponseError, ApiResponseBody, ApiError } from './types/api';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SecretString = exports.RateLimiter = exports.HttpClient = exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = exports.createBearerConfig = exports.mergeConfig = exports.loadConfigFromEnv = exports.NetworkError = exports.RateLimitError = exports.LightdashApiError = exports.DEFAULT_RETRY = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RATE_LIMIT = exports.consoleLogger = exports.noopLogger = exports.DashboardsClientV2 = exports.ContentClient = exports.AnalyticsClient = exports.TagsClient = exports.SchedulersClient = exports.MetricsClient = exports.ValidationClientV2 = exports.ValidationClient = exports.ProjectAccessClient = exports.AiAgentsClient = exports.ProjectRoleAssignmentsClient = exports.OrganizationRolesClient = exports.GroupsClient = exports.UsersClient = exports.resolveEvaluationRun = exports.applyBundleDiff = exports.fetchBundleCurrentState = exports.V2ApiClients = exports.V1ApiClients = exports.LightdashClient = void 0;
3
+ exports.SecretString = exports.RateLimiter = exports.unwrapApiSuccessResults = exports.isApiSuccessEnvelope = exports.HttpClient = exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = exports.createBearerConfig = exports.mergeConfig = exports.loadConfigFromEnv = exports.NetworkError = exports.RateLimitError = exports.LightdashApiError = exports.DEFAULT_RETRY = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RATE_LIMIT = exports.consoleLogger = exports.noopLogger = exports.DashboardsClientV2 = exports.ChartsClientV2 = exports.ContentClient = exports.AnalyticsClient = exports.TagsClient = exports.SchedulersClient = exports.MetricsClient = exports.ValidationClientV2 = exports.ValidationClient = exports.ProjectAccessClient = exports.AiAgentsClient = exports.ProjectRoleAssignmentsClient = exports.OrganizationRolesClient = exports.GroupsClient = exports.UsersClient = exports.resolveEvaluationRun = exports.applyBundleDiff = exports.fetchBundleCurrentState = exports.V2ApiClients = exports.V1ApiClients = exports.LightdashClient = void 0;
4
4
  var client_1 = require("./client");
5
5
  Object.defineProperty(exports, "LightdashClient", { enumerable: true, get: function () { return client_1.LightdashClient; } });
6
6
  Object.defineProperty(exports, "V1ApiClients", { enumerable: true, get: function () { return client_1.V1ApiClients; } });
@@ -35,6 +35,8 @@ var analytics_1 = require("./api/v1/analytics");
35
35
  Object.defineProperty(exports, "AnalyticsClient", { enumerable: true, get: function () { return analytics_1.AnalyticsClient; } });
36
36
  var content_1 = require("./api/v2/content");
37
37
  Object.defineProperty(exports, "ContentClient", { enumerable: true, get: function () { return content_1.ContentClient; } });
38
+ var charts_1 = require("./api/v2/charts");
39
+ Object.defineProperty(exports, "ChartsClientV2", { enumerable: true, get: function () { return charts_1.ChartsClientV2; } });
38
40
  var dashboards_1 = require("./api/v2/dashboards");
39
41
  Object.defineProperty(exports, "DashboardsClientV2", { enumerable: true, get: function () { return dashboards_1.DashboardsClientV2; } });
40
42
  var logger_1 = require("./utils/logger");
@@ -58,6 +60,9 @@ Object.defineProperty(exports, "ENV_LIGHTDASH_URL", { enumerable: true, get: fun
58
60
  Object.defineProperty(exports, "ENV_LIGHTDASH_PROXY_AUTHORIZATION", { enumerable: true, get: function () { return env_2.ENV_LIGHTDASH_PROXY_AUTHORIZATION; } });
59
61
  var http_client_1 = require("./http/http-client");
60
62
  Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return http_client_1.HttpClient; } });
63
+ var unwrap_api_success_1 = require("./http/unwrap-api-success");
64
+ Object.defineProperty(exports, "isApiSuccessEnvelope", { enumerable: true, get: function () { return unwrap_api_success_1.isApiSuccessEnvelope; } });
65
+ Object.defineProperty(exports, "unwrapApiSuccessResults", { enumerable: true, get: function () { return unwrap_api_success_1.unwrapApiSuccessResults; } });
61
66
  var rate_limiter_1 = require("./http/rate-limiter");
62
67
  Object.defineProperty(exports, "RateLimiter", { enumerable: true, get: function () { return rate_limiter_1.RateLimiter; } });
63
68
  var secret_string_1 = require("./utils/secret-string");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/client",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Client library for Lightdash AI.",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "axios": "^1.19.0",
17
17
  "bottleneck": "^2.19.5",
18
- "@lightdash-tools/common": "0.7.0"
18
+ "@lightdash-tools/common": "0.8.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^25.9.3"
@@ -102,4 +102,22 @@ describe('ChartsClient', () => {
102
102
  await client.upsertChartAsCode('p1', 'chart/slug', body);
103
103
  expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/chart%2Fslug', body);
104
104
  });
105
+
106
+ it('getChartHistory should call GET /saved/{chartUuid}/history', async () => {
107
+ const client = new ChartsClient(mockHttp);
108
+ const history = { chartUuid: 'c1', history: [] };
109
+ vi.mocked(mockHttp.get).mockResolvedValue(history);
110
+ const result = await client.getChartHistory('c1');
111
+ expect(mockHttp.get).toHaveBeenCalledWith('/saved/c1/history');
112
+ expect(result).toEqual(history);
113
+ });
114
+
115
+ it('getChartVersion should call GET /saved/{chartUuid}/version/{versionUuid}', async () => {
116
+ const client = new ChartsClient(mockHttp);
117
+ const version = { chartUuid: 'c1', versionUuid: 'v1' };
118
+ vi.mocked(mockHttp.get).mockResolvedValue(version);
119
+ const result = await client.getChartVersion('c1', 'v1');
120
+ expect(mockHttp.get).toHaveBeenCalledWith('/saved/c1/version/v1');
121
+ expect(result).toEqual(version);
122
+ });
105
123
  });
@@ -9,6 +9,7 @@ import type {
9
9
  ChartAsCodeListResults,
10
10
  ChartAsCodeUpsertResults,
11
11
  UpsertChartAsCodeBody,
12
+ components,
12
13
  } from '@lightdash-tools/common';
13
14
 
14
15
  export interface GetChartsAsCodeOptions {
@@ -17,6 +18,12 @@ export interface GetChartsAsCodeOptions {
17
18
  languageMap?: boolean;
18
19
  }
19
20
 
21
+ /** Results of GET saved/{chartUuid}/history (chart version history). */
22
+ export type ChartHistoryResults = components['schemas']['ApiGetChartHistoryResponse']['results'];
23
+
24
+ /** Results of GET saved/{chartUuid}/version/{versionUuid} (a single chart version). */
25
+ export type ChartVersionResults = components['schemas']['ApiGetChartVersionResponse']['results'];
26
+
20
27
  export class ChartsClient extends BaseApiClient {
21
28
  /**
22
29
  * List charts in a project (returns SpaceQuery array).
@@ -52,4 +59,14 @@ export class ChartsClient extends BaseApiClient {
52
59
  body,
53
60
  );
54
61
  }
62
+
63
+ /** Get chart version history from the last 30 days. */
64
+ async getChartHistory(chartUuid: string): Promise<ChartHistoryResults> {
65
+ return this.http.get<ChartHistoryResults>(`/saved/${chartUuid}/history`);
66
+ }
67
+
68
+ /** Get a single chart version by UUID. */
69
+ async getChartVersion(chartUuid: string, versionUuid: string): Promise<ChartVersionResults> {
70
+ return this.http.get<ChartVersionResults>(`/saved/${chartUuid}/version/${versionUuid}`);
71
+ }
55
72
  }
@@ -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
  });
@@ -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
  });