@lightdash-tools/client 0.6.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.
- package/README.md +2 -2
- package/dist/agentops/apply-agent-change.d.ts +3 -0
- package/dist/agentops/apply-agent-change.js +63 -0
- package/dist/agentops/apply-bundle-diff.d.ts +13 -0
- package/dist/agentops/apply-bundle-diff.js +44 -0
- package/dist/agentops/apply-bundle-diff.test.d.ts +1 -0
- package/dist/agentops/apply-bundle-diff.test.js +397 -0
- package/dist/agentops/apply-context.d.ts +14 -0
- package/dist/agentops/apply-context.js +6 -0
- package/dist/agentops/apply-evaluation-change.d.ts +3 -0
- package/dist/agentops/apply-evaluation-change.js +78 -0
- package/dist/agentops/fetch-bundle-state.d.ts +6 -0
- package/dist/agentops/fetch-bundle-state.js +20 -0
- package/dist/agentops/fetch-bundle-state.test.d.ts +1 -0
- package/dist/agentops/fetch-bundle-state.test.js +44 -0
- package/dist/agentops/index.d.ts +3 -0
- package/dist/agentops/index.js +9 -0
- package/dist/agentops/resolve-evaluation-run.d.ts +15 -0
- package/dist/agentops/resolve-evaluation-run.js +48 -0
- package/dist/api/v1/ai-agents/admin.d.ts +16 -0
- package/dist/api/v1/ai-agents/admin.js +29 -0
- package/dist/api/v1/ai-agents/agents.d.ts +18 -0
- package/dist/api/v1/ai-agents/agents.js +31 -0
- package/dist/api/v1/ai-agents/artifacts.d.ts +26 -0
- package/dist/api/v1/ai-agents/artifacts.js +41 -0
- package/dist/api/v1/ai-agents/artifacts.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/artifacts.test.js +69 -0
- package/dist/api/v1/ai-agents/discovery.d.ts +28 -0
- package/dist/api/v1/ai-agents/discovery.js +46 -0
- package/dist/api/v1/ai-agents/discovery.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/discovery.test.js +90 -0
- package/dist/api/v1/ai-agents/evaluations.d.ts +39 -0
- package/dist/api/v1/ai-agents/evaluations.js +70 -0
- package/dist/api/v1/ai-agents/facade.d.ts +79 -0
- package/dist/api/v1/ai-agents/facade.js +193 -0
- package/dist/api/v1/ai-agents/feedback.d.ts +10 -0
- package/dist/api/v1/ai-agents/feedback.js +15 -0
- package/dist/api/v1/ai-agents/feedback.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/feedback.test.js +23 -0
- package/dist/api/v1/ai-agents/index.d.ts +1 -0
- package/dist/api/v1/ai-agents/index.js +5 -0
- package/dist/api/v1/ai-agents/mcp-servers.d.ts +20 -0
- package/dist/api/v1/ai-agents/mcp-servers.js +35 -0
- package/dist/api/v1/ai-agents/mcp-servers.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/mcp-servers.test.js +66 -0
- package/dist/api/v1/ai-agents/request-options.d.ts +12 -0
- package/dist/api/v1/ai-agents/request-options.js +20 -0
- package/dist/api/v1/ai-agents/sql-approval.d.ts +10 -0
- package/dist/api/v1/ai-agents/sql-approval.js +15 -0
- package/dist/api/v1/ai-agents/sql-approval.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/sql-approval.test.js +25 -0
- package/dist/api/v1/ai-agents/threads.d.ts +56 -0
- package/dist/api/v1/ai-agents/threads.js +97 -0
- package/dist/api/v1/ai-agents/threads.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/threads.test.js +39 -0
- package/dist/api/v1/ai-agents.test.js +172 -89
- package/dist/api/v1/analytics.d.ts +10 -0
- package/dist/api/v1/analytics.js +14 -0
- package/dist/api/v1/analytics.test.d.ts +4 -0
- package/dist/api/v1/analytics.test.js +27 -0
- package/dist/api/v1/charts.d.ts +13 -2
- package/dist/api/v1/charts.js +26 -30
- package/dist/api/v1/charts.test.js +35 -28
- package/dist/api/v1/dashboards.d.ts +42 -2
- package/dist/api/v1/dashboards.js +39 -14
- package/dist/api/v1/dashboards.test.js +126 -12
- package/dist/api/v1/explores.d.ts +4 -2
- package/dist/api/v1/explores.js +20 -29
- package/dist/api/v1/explores.test.js +31 -21
- package/dist/api/v1/groups.d.ts +1 -1
- package/dist/api/v1/groups.js +25 -51
- package/dist/api/v1/groups.test.js +15 -24
- package/dist/api/v1/metrics.d.ts +2 -2
- package/dist/api/v1/metrics.js +4 -17
- package/dist/api/v1/metrics.test.js +6 -15
- package/dist/api/v1/organizations.d.ts +1 -1
- package/dist/api/v1/organizations.js +2 -13
- package/dist/api/v1/organizations.test.js +3 -12
- package/dist/api/v1/project-access.d.ts +1 -1
- package/dist/api/v1/project-access.js +18 -45
- package/dist/api/v1/project-access.test.js +27 -36
- package/dist/api/v1/projects.d.ts +1 -1
- package/dist/api/v1/projects.js +6 -21
- package/dist/api/v1/projects.test.js +9 -18
- package/dist/api/v1/query.d.ts +5 -2
- package/dist/api/v1/query.js +8 -18
- package/dist/api/v1/query.test.js +6 -15
- package/dist/api/v1/schedulers.d.ts +2 -2
- package/dist/api/v1/schedulers.js +4 -17
- package/dist/api/v1/schedulers.test.js +6 -15
- package/dist/api/v1/spaces.d.ts +1 -1
- package/dist/api/v1/spaces.js +18 -45
- package/dist/api/v1/spaces.test.js +27 -36
- package/dist/api/v1/tags.d.ts +1 -1
- package/dist/api/v1/tags.js +4 -17
- package/dist/api/v1/tags.test.js +6 -15
- package/dist/api/v1/users.d.ts +3 -1
- package/dist/api/v1/users.js +22 -39
- package/dist/api/v1/users.test.js +44 -30
- package/dist/api/v1/validation.d.ts +9 -2
- package/dist/api/v1/validation.js +16 -18
- package/dist/api/v1/validation.test.js +22 -15
- 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 +20 -3
- package/dist/api/v2/content.js +18 -14
- package/dist/api/v2/content.test.js +44 -12
- package/dist/api/v2/dashboards.d.ts +16 -0
- package/dist/api/v2/dashboards.js +22 -0
- package/dist/api/v2/dashboards.test.d.ts +4 -0
- package/dist/api/v2/dashboards.test.js +61 -0
- package/dist/api/v2/organization-roles.d.ts +1 -1
- package/dist/api/v2/organization-roles.js +21 -50
- package/dist/api/v2/organization-roles.test.js +33 -42
- 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/project-role-assignments.d.ts +1 -1
- package/dist/api/v2/project-role-assignments.js +12 -33
- package/dist/api/v2/project-role-assignments.test.js +18 -27
- package/dist/api/v2/query.d.ts +16 -1
- package/dist/api/v2/query.js +26 -29
- package/dist/api/v2/query.test.js +31 -24
- package/dist/api/v2/validation.d.ts +28 -0
- package/dist/api/v2/validation.js +23 -0
- package/dist/client.d.ts +24 -14
- package/dist/client.js +26 -16
- package/dist/client.test.js +2 -0
- package/dist/config.d.ts +35 -10
- package/dist/http/axios-client.d.ts +4 -4
- package/dist/http/http-client.d.ts +3 -14
- package/dist/http/http-client.js +20 -43
- package/dist/http/interceptors.d.ts +3 -3
- package/dist/http/interceptors.js +16 -3
- package/dist/http/rate-limiter.js +2 -13
- package/dist/http/rate-limiter.test.js +15 -24
- 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 +13 -3
- package/dist/index.js +17 -1
- package/dist/index.test.js +13 -5
- package/dist/pagination/fetch-all-pages.js +18 -29
- package/dist/pagination/fetch-all-pages.test.js +15 -24
- package/dist/types/api.d.ts +1 -1
- package/dist/utils/env.d.ts +11 -2
- package/dist/utils/env.js +41 -8
- package/dist/utils/env.test.js +14 -4
- package/dist/utils/logger.js +5 -4
- package/dist/utils/retry.js +17 -28
- package/dist/utils/retry.test.js +9 -18
- package/dist/utils/secret-string.test.d.ts +1 -0
- package/dist/utils/secret-string.test.js +25 -0
- package/package.json +12 -4
- package/src/agentops/apply-agent-change.ts +82 -0
- package/src/agentops/apply-bundle-diff.test.ts +453 -0
- package/src/agentops/apply-bundle-diff.ts +63 -0
- package/src/agentops/apply-context.ts +23 -0
- package/src/agentops/apply-evaluation-change.ts +125 -0
- package/src/agentops/fetch-bundle-state.test.ts +51 -0
- package/src/agentops/fetch-bundle-state.ts +33 -0
- package/src/agentops/index.ts +11 -0
- package/src/agentops/resolve-evaluation-run.ts +94 -0
- package/src/api/v1/ai-agents/admin.ts +41 -0
- package/src/api/v1/ai-agents/agents.ts +40 -0
- package/src/api/v1/ai-agents/artifacts.test.ts +84 -0
- package/src/api/v1/ai-agents/artifacts.ts +92 -0
- package/src/api/v1/ai-agents/discovery.test.ts +102 -0
- package/src/api/v1/ai-agents/discovery.ts +79 -0
- package/src/api/v1/ai-agents/evaluations.ts +152 -0
- package/src/api/v1/ai-agents/facade.ts +489 -0
- package/src/api/v1/ai-agents/feedback.test.ts +30 -0
- package/src/api/v1/ai-agents/feedback.ts +24 -0
- package/src/api/v1/ai-agents/index.ts +1 -0
- package/src/api/v1/ai-agents/mcp-servers.test.ts +81 -0
- package/src/api/v1/ai-agents/mcp-servers.ts +67 -0
- package/src/api/v1/ai-agents/request-options.ts +32 -0
- package/src/api/v1/ai-agents/sql-approval.test.ts +32 -0
- package/src/api/v1/ai-agents/sql-approval.ts +24 -0
- package/src/api/v1/ai-agents/threads.test.ts +55 -0
- package/src/api/v1/ai-agents/threads.ts +216 -0
- package/src/api/v1/ai-agents.test.ts +189 -13
- package/src/api/v1/analytics.test.ts +32 -0
- package/src/api/v1/analytics.ts +16 -0
- package/src/api/v1/charts.test.ts +26 -6
- package/src/api/v1/charts.ts +25 -4
- package/src/api/v1/dashboards.test.ts +142 -0
- package/src/api/v1/dashboards.ts +127 -2
- package/src/api/v1/explores.test.ts +22 -0
- package/src/api/v1/explores.ts +13 -2
- package/src/api/v1/groups.test.ts +2 -0
- package/src/api/v1/groups.ts +9 -7
- package/src/api/v1/metrics.test.ts +2 -0
- package/src/api/v1/metrics.ts +3 -2
- package/src/api/v1/organizations.test.ts +2 -0
- package/src/api/v1/organizations.ts +2 -1
- package/src/api/v1/project-access.test.ts +3 -1
- package/src/api/v1/project-access.ts +2 -1
- package/src/api/v1/projects.test.ts +2 -0
- package/src/api/v1/projects.ts +2 -1
- package/src/api/v1/query.test.ts +2 -0
- package/src/api/v1/query.ts +6 -2
- package/src/api/v1/schedulers.test.ts +2 -0
- package/src/api/v1/schedulers.ts +3 -2
- package/src/api/v1/spaces.test.ts +2 -0
- package/src/api/v1/spaces.ts +2 -1
- package/src/api/v1/tags.test.ts +2 -0
- package/src/api/v1/tags.ts +2 -1
- package/src/api/v1/users.test.ts +26 -0
- package/src/api/v1/users.ts +8 -2
- package/src/api/v1/validation.test.ts +20 -0
- package/src/api/v1/validation.ts +26 -2
- package/src/api/v2/charts.test.ts +53 -0
- package/src/api/v2/charts.ts +23 -0
- package/src/api/v2/content.test.ts +47 -0
- package/src/api/v2/content.ts +37 -3
- package/src/api/v2/dashboards.test.ts +71 -0
- package/src/api/v2/dashboards.ts +40 -0
- package/src/api/v2/organization-roles.test.ts +2 -0
- package/src/api/v2/organization-roles.ts +2 -1
- package/src/api/v2/parameters.test.ts +45 -0
- package/src/api/v2/parameters.ts +38 -0
- package/src/api/v2/project-role-assignments.test.ts +2 -0
- package/src/api/v2/project-role-assignments.ts +2 -1
- package/src/api/v2/query.test.ts +20 -0
- package/src/api/v2/query.ts +55 -1
- package/src/api/v2/validation.ts +48 -0
- package/src/client.test.ts +3 -0
- package/src/client.ts +33 -17
- package/src/config.ts +38 -10
- package/src/errors.test.ts +1 -0
- package/src/http/axios-client.ts +8 -5
- package/src/http/http-client.ts +8 -21
- package/src/http/interceptors.ts +23 -10
- package/src/http/rate-limiter.test.ts +1 -0
- package/src/http/rate-limiter.ts +3 -1
- package/src/http/unwrap-api-success.test.ts +23 -0
- package/src/http/unwrap-api-success.ts +40 -0
- package/src/index.test.ts +16 -7
- package/src/index.ts +37 -2
- package/src/pagination/fetch-all-pages.test.ts +2 -0
- package/src/types/api.ts +1 -1
- package/src/utils/env.test.ts +16 -4
- package/src/utils/env.ts +61 -10
- package/src/utils/logger.ts +6 -4
- package/src/utils/retry.test.ts +1 -0
- package/src/utils/retry.ts +2 -1
- package/src/utils/secret-string.test.ts +27 -0
- package/tsconfig.json +4 -2
- package/dist/api/v1/ai-agents.d.ts +0 -63
- package/dist/api/v1/ai-agents.js +0 -173
- package/src/api/v1/ai-agents.ts +0 -252
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Analytics client unit tests.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const analytics_1 = require("./analytics");
|
|
8
|
+
(0, vitest_1.describe)('AnalyticsClient', () => {
|
|
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)('getUserActivity calls GET /analytics/user-activity/{projectUuid}', async () => {
|
|
20
|
+
const client = new analytics_1.AnalyticsClient(mockHttp);
|
|
21
|
+
const mockResponse = { numberUsers: 1, chartViews: [], dashboardViews: [] };
|
|
22
|
+
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
23
|
+
const result = await client.getUserActivity('p1');
|
|
24
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/analytics/user-activity/p1');
|
|
25
|
+
(0, vitest_1.expect)(result).toEqual(mockResponse);
|
|
26
|
+
});
|
|
27
|
+
});
|
package/dist/api/v1/charts.d.ts
CHANGED
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Charts API client. Endpoints for saved charts and chart-as-code operations.
|
|
3
3
|
*/
|
|
4
|
-
import type { SpaceQuery, ChartAsCodeListResults, ChartAsCodeUpsertResults, UpsertChartAsCodeBody } from '@lightdash-tools/common';
|
|
5
4
|
import { BaseApiClient } from '../base-client';
|
|
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'];
|
|
11
15
|
export declare class ChartsClient extends BaseApiClient {
|
|
12
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* List charts in a project (returns SpaceQuery array).
|
|
18
|
+
* @deprecated This API endpoint is deprecated in Lightdash. Use charts-as-code API instead.
|
|
19
|
+
*/
|
|
13
20
|
listCharts(projectUuid: string): Promise<SpaceQuery[]>;
|
|
14
21
|
/** Get charts in code representation (for charts-as-code workflows). */
|
|
15
22
|
getChartsAsCode(projectUuid: string, options?: GetChartsAsCodeOptions): Promise<ChartAsCodeListResults>;
|
|
16
23
|
/** Upsert a chart from code representation (create or update by slug). */
|
|
17
24
|
upsertChartAsCode(projectUuid: string, slug: string, body: UpsertChartAsCodeBody): Promise<ChartAsCodeUpsertResults>;
|
|
25
|
+
/** Get chart version history from the last 30 days. */
|
|
26
|
+
getChartHistory(chartUuid: string): Promise<ChartHistoryResults>;
|
|
27
|
+
/** Get a single chart version by UUID. */
|
|
28
|
+
getChartVersion(chartUuid: string, versionUuid: string): Promise<ChartVersionResults>;
|
|
18
29
|
}
|
package/dist/api/v1/charts.js
CHANGED
|
@@ -2,44 +2,40 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Charts API client. Endpoints for saved charts and chart-as-code operations.
|
|
4
4
|
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.ChartsClient = void 0;
|
|
16
7
|
const base_client_1 = require("../base-client");
|
|
17
8
|
class ChartsClient extends base_client_1.BaseApiClient {
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
/**
|
|
10
|
+
* List charts in a project (returns SpaceQuery array).
|
|
11
|
+
* @deprecated This API endpoint is deprecated in Lightdash. Use charts-as-code API instead.
|
|
12
|
+
*/
|
|
13
|
+
async listCharts(projectUuid) {
|
|
14
|
+
return this.http.get(`/projects/${projectUuid}/charts`);
|
|
23
15
|
}
|
|
24
16
|
/** Get charts in code representation (for charts-as-code workflows). */
|
|
25
|
-
getChartsAsCode(projectUuid, options) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return this.http.get(`/projects/${projectUuid}/charts/code`, Object.keys(params).length ? { params } : undefined);
|
|
36
|
-
});
|
|
17
|
+
async getChartsAsCode(projectUuid, options) {
|
|
18
|
+
var _a;
|
|
19
|
+
const params = {};
|
|
20
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.ids) === null || _a === void 0 ? void 0 : _a.length)
|
|
21
|
+
params.ids = options.ids;
|
|
22
|
+
if ((options === null || options === void 0 ? void 0 : options.offset) != null)
|
|
23
|
+
params.offset = options.offset;
|
|
24
|
+
if ((options === null || options === void 0 ? void 0 : options.languageMap) != null)
|
|
25
|
+
params.languageMap = options.languageMap;
|
|
26
|
+
return this.http.get(`/projects/${projectUuid}/code/charts`, Object.keys(params).length ? { params } : undefined);
|
|
37
27
|
}
|
|
38
28
|
/** Upsert a chart from code representation (create or update by slug). */
|
|
39
|
-
upsertChartAsCode(projectUuid, slug, body) {
|
|
40
|
-
return
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
async upsertChartAsCode(projectUuid, slug, body) {
|
|
30
|
+
return this.http.post(`/projects/${projectUuid}/code/charts/${encodeURIComponent(slug)}`, body);
|
|
31
|
+
}
|
|
32
|
+
/** Get chart version history from the last 30 days. */
|
|
33
|
+
async getChartHistory(chartUuid) {
|
|
34
|
+
return this.http.get(`/saved/${chartUuid}/history`);
|
|
35
|
+
}
|
|
36
|
+
/** Get a single chart version by UUID. */
|
|
37
|
+
async getChartVersion(chartUuid, versionUuid) {
|
|
38
|
+
return this.http.get(`/saved/${chartUuid}/version/${versionUuid}`);
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
exports.ChartsClient = ChartsClient;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const vitest_1 = require("vitest");
|
|
13
4
|
const charts_1 = require("./charts");
|
|
@@ -22,36 +13,36 @@ const charts_1 = require("./charts");
|
|
|
22
13
|
delete: vitest_1.vi.fn(),
|
|
23
14
|
};
|
|
24
15
|
});
|
|
25
|
-
(0, vitest_1.it)('listCharts should call GET /projects/{projectUuid}/charts', () =>
|
|
16
|
+
(0, vitest_1.it)('listCharts should call GET /projects/{projectUuid}/charts', async () => {
|
|
26
17
|
const client = new charts_1.ChartsClient(mockHttp);
|
|
27
18
|
const charts = [{ uuid: 'c1', name: 'Chart 1', projectUuid: 'p1' }];
|
|
28
19
|
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(charts);
|
|
29
|
-
const result =
|
|
20
|
+
const result = await client.listCharts('p1');
|
|
30
21
|
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts');
|
|
31
22
|
(0, vitest_1.expect)(result).toEqual(charts);
|
|
32
|
-
})
|
|
33
|
-
(0, vitest_1.it)('getChartsAsCode should call GET /projects/{projectUuid}/charts
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.it)('getChartsAsCode should call GET /projects/{projectUuid}/code/charts with no params when no options', async () => {
|
|
34
25
|
const client = new charts_1.ChartsClient(mockHttp);
|
|
35
26
|
const results = { offset: 0, total: 1, missingIds: [], charts: [] };
|
|
36
27
|
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
|
|
37
|
-
const result =
|
|
38
|
-
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts
|
|
28
|
+
const result = await client.getChartsAsCode('p1');
|
|
29
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/charts', undefined);
|
|
39
30
|
(0, vitest_1.expect)(result).toEqual(results);
|
|
40
|
-
})
|
|
41
|
-
(0, vitest_1.it)('getChartsAsCode should call GET with query params when options provided', () =>
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.it)('getChartsAsCode should call GET with query params when options provided', async () => {
|
|
42
33
|
const client = new charts_1.ChartsClient(mockHttp);
|
|
43
34
|
const results = { offset: 0, total: 0, missingIds: [], charts: [] };
|
|
44
35
|
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
|
|
45
|
-
|
|
36
|
+
await client.getChartsAsCode('p1', {
|
|
46
37
|
ids: ['slug-a', 'slug-b'],
|
|
47
38
|
offset: 10,
|
|
48
39
|
languageMap: true,
|
|
49
40
|
});
|
|
50
|
-
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts
|
|
41
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/charts', {
|
|
51
42
|
params: { ids: ['slug-a', 'slug-b'], offset: 10, languageMap: true },
|
|
52
43
|
});
|
|
53
|
-
})
|
|
54
|
-
(0, vitest_1.it)('upsertChartAsCode should call POST /projects/{projectUuid}/charts/{slug}
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('upsertChartAsCode should call POST /projects/{projectUuid}/code/charts/{slug} with body', async () => {
|
|
55
46
|
const client = new charts_1.ChartsClient(mockHttp);
|
|
56
47
|
const body = {
|
|
57
48
|
name: 'My Chart',
|
|
@@ -74,11 +65,11 @@ const charts_1 = require("./charts");
|
|
|
74
65
|
};
|
|
75
66
|
const apiResult = { promoted: [], errors: [] };
|
|
76
67
|
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(apiResult);
|
|
77
|
-
const result =
|
|
78
|
-
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/charts/my-chart
|
|
68
|
+
const result = await client.upsertChartAsCode('p1', 'my-chart', body);
|
|
69
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/my-chart', body);
|
|
79
70
|
(0, vitest_1.expect)(result).toEqual(apiResult);
|
|
80
|
-
})
|
|
81
|
-
(0, vitest_1.it)('upsertChartAsCode should encode slug in path', () =>
|
|
71
|
+
});
|
|
72
|
+
(0, vitest_1.it)('upsertChartAsCode should encode slug in path', async () => {
|
|
82
73
|
const client = new charts_1.ChartsClient(mockHttp);
|
|
83
74
|
const body = {
|
|
84
75
|
name: 'Chart',
|
|
@@ -100,7 +91,23 @@ const charts_1 = require("./charts");
|
|
|
100
91
|
chartConfig: {},
|
|
101
92
|
};
|
|
102
93
|
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({});
|
|
103
|
-
|
|
104
|
-
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/charts/chart%2Fslug
|
|
105
|
-
})
|
|
94
|
+
await client.upsertChartAsCode('p1', 'chart/slug', body);
|
|
95
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/chart%2Fslug', body);
|
|
96
|
+
});
|
|
97
|
+
(0, vitest_1.it)('getChartHistory should call GET /saved/{chartUuid}/history', async () => {
|
|
98
|
+
const client = new charts_1.ChartsClient(mockHttp);
|
|
99
|
+
const history = { chartUuid: 'c1', history: [] };
|
|
100
|
+
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(history);
|
|
101
|
+
const result = await client.getChartHistory('c1');
|
|
102
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/saved/c1/history');
|
|
103
|
+
(0, vitest_1.expect)(result).toEqual(history);
|
|
104
|
+
});
|
|
105
|
+
(0, vitest_1.it)('getChartVersion should call GET /saved/{chartUuid}/version/{versionUuid}', async () => {
|
|
106
|
+
const client = new charts_1.ChartsClient(mockHttp);
|
|
107
|
+
const version = { chartUuid: 'c1', versionUuid: 'v1' };
|
|
108
|
+
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(version);
|
|
109
|
+
const result = await client.getChartVersion('c1', 'v1');
|
|
110
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/saved/c1/version/v1');
|
|
111
|
+
(0, vitest_1.expect)(result).toEqual(version);
|
|
112
|
+
});
|
|
106
113
|
});
|
|
@@ -1,9 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Dashboards API client.
|
|
2
|
+
* Dashboards API client. Endpoints for project dashboards and dashboard-as-code operations.
|
|
3
3
|
*/
|
|
4
|
-
import type { DashboardBasicDetailsWithTileTypes } from '@lightdash-tools/common';
|
|
5
4
|
import { BaseApiClient } from '../base-client';
|
|
5
|
+
import type { DashboardBasicDetailsWithTileTypes, DashboardAsCodeListResults, DashboardAsCodeUpsertResults, UpsertDashboardAsCodeBody, components } from '@lightdash-tools/common';
|
|
6
|
+
export interface GetDashboardsAsCodeOptions {
|
|
7
|
+
ids?: string[];
|
|
8
|
+
offset?: number;
|
|
9
|
+
languageMap?: boolean;
|
|
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
|
+
}
|
|
6
32
|
export declare class DashboardsClient extends BaseApiClient {
|
|
7
33
|
/** List dashboards in a project. */
|
|
8
34
|
listDashboards(projectUuid: string): Promise<DashboardBasicDetailsWithTileTypes[]>;
|
|
35
|
+
/** Get dashboards in code representation (for dashboards-as-code workflows). */
|
|
36
|
+
getDashboardsAsCode(projectUuid: string, options?: GetDashboardsAsCodeOptions): Promise<DashboardAsCodeListResults>;
|
|
37
|
+
/** Upsert a dashboard from code representation (create or update by slug). */
|
|
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>;
|
|
9
49
|
}
|
|
@@ -1,25 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Dashboards API client.
|
|
3
|
+
* Dashboards API client. Endpoints for project dashboards and dashboard-as-code operations.
|
|
4
4
|
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.DashboardsClient = void 0;
|
|
16
7
|
const base_client_1 = require("../base-client");
|
|
17
8
|
class DashboardsClient extends base_client_1.BaseApiClient {
|
|
18
9
|
/** List dashboards in a project. */
|
|
19
|
-
listDashboards(projectUuid) {
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
async listDashboards(projectUuid) {
|
|
11
|
+
return this.http.get(`/projects/${projectUuid}/dashboards`);
|
|
12
|
+
}
|
|
13
|
+
/** Get dashboards in code representation (for dashboards-as-code workflows). */
|
|
14
|
+
async getDashboardsAsCode(projectUuid, options) {
|
|
15
|
+
var _a;
|
|
16
|
+
const params = {};
|
|
17
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.ids) === null || _a === void 0 ? void 0 : _a.length)
|
|
18
|
+
params.ids = options.ids;
|
|
19
|
+
if ((options === null || options === void 0 ? void 0 : options.offset) != null)
|
|
20
|
+
params.offset = options.offset;
|
|
21
|
+
if ((options === null || options === void 0 ? void 0 : options.languageMap) != null)
|
|
22
|
+
params.languageMap = options.languageMap;
|
|
23
|
+
return this.http.get(`/projects/${projectUuid}/code/dashboards`, Object.keys(params).length ? { params } : undefined);
|
|
24
|
+
}
|
|
25
|
+
/** Upsert a dashboard from code representation (create or update by slug). */
|
|
26
|
+
async upsertDashboardAsCode(projectUuid, slug, body) {
|
|
27
|
+
return this.http.post(`/projects/${projectUuid}/code/dashboards/${encodeURIComponent(slug)}`, body);
|
|
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);
|
|
23
48
|
}
|
|
24
49
|
}
|
|
25
50
|
exports.DashboardsClient = DashboardsClient;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
const vitest_1 = require("vitest");
|
|
13
4
|
const dashboards_1 = require("./dashboards");
|
|
@@ -22,12 +13,135 @@ const dashboards_1 = require("./dashboards");
|
|
|
22
13
|
delete: vitest_1.vi.fn(),
|
|
23
14
|
};
|
|
24
15
|
});
|
|
25
|
-
(0, vitest_1.it)('listDashboards should call GET /projects/{projectUuid}/dashboards', () =>
|
|
16
|
+
(0, vitest_1.it)('listDashboards should call GET /projects/{projectUuid}/dashboards', async () => {
|
|
26
17
|
const client = new dashboards_1.DashboardsClient(mockHttp);
|
|
27
18
|
const dashboards = [{ uuid: 'd1', name: 'Dashboard 1', projectUuid: 'p1' }];
|
|
28
19
|
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(dashboards);
|
|
29
|
-
const result =
|
|
20
|
+
const result = await client.listDashboards('p1');
|
|
30
21
|
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/dashboards');
|
|
31
22
|
(0, vitest_1.expect)(result).toEqual(dashboards);
|
|
32
|
-
})
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.it)('getDashboardsAsCode should call GET /projects/{projectUuid}/code/dashboards with no params when no options', async () => {
|
|
25
|
+
const client = new dashboards_1.DashboardsClient(mockHttp);
|
|
26
|
+
const results = { offset: 0, total: 1, missingIds: [], dashboards: [] };
|
|
27
|
+
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
|
|
28
|
+
const result = await client.getDashboardsAsCode('p1');
|
|
29
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/dashboards', undefined);
|
|
30
|
+
(0, vitest_1.expect)(result).toEqual(results);
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.it)('getDashboardsAsCode should call GET with query params when options provided', async () => {
|
|
33
|
+
const client = new dashboards_1.DashboardsClient(mockHttp);
|
|
34
|
+
const results = { offset: 0, total: 0, missingIds: [], dashboards: [] };
|
|
35
|
+
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
|
|
36
|
+
await client.getDashboardsAsCode('p1', {
|
|
37
|
+
ids: ['slug-a', 'slug-b'],
|
|
38
|
+
offset: 10,
|
|
39
|
+
languageMap: true,
|
|
40
|
+
});
|
|
41
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/dashboards', {
|
|
42
|
+
params: { ids: ['slug-a', 'slug-b'], offset: 10, languageMap: true },
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('upsertDashboardAsCode should call POST /projects/{projectUuid}/code/dashboards/{slug} with body', async () => {
|
|
46
|
+
const client = new dashboards_1.DashboardsClient(mockHttp);
|
|
47
|
+
const body = {
|
|
48
|
+
name: 'My Dashboard',
|
|
49
|
+
slug: 'my-dashboard',
|
|
50
|
+
updatedAt: '2024-01-01T00:00:00Z',
|
|
51
|
+
version: 1,
|
|
52
|
+
spaceSlug: 'my-space',
|
|
53
|
+
tiles: [],
|
|
54
|
+
};
|
|
55
|
+
const apiResult = { promoted: [], errors: [] };
|
|
56
|
+
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(apiResult);
|
|
57
|
+
const result = await client.upsertDashboardAsCode('p1', 'my-dashboard', body);
|
|
58
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/dashboards/my-dashboard', body);
|
|
59
|
+
(0, vitest_1.expect)(result).toEqual(apiResult);
|
|
60
|
+
});
|
|
61
|
+
(0, vitest_1.it)('upsertDashboardAsCode should encode slug in path', async () => {
|
|
62
|
+
const client = new dashboards_1.DashboardsClient(mockHttp);
|
|
63
|
+
const body = {
|
|
64
|
+
name: 'Dashboard',
|
|
65
|
+
slug: 'dash/slug',
|
|
66
|
+
updatedAt: '2024-01-01T00:00:00Z',
|
|
67
|
+
version: 1,
|
|
68
|
+
spaceSlug: 'space',
|
|
69
|
+
tiles: [],
|
|
70
|
+
};
|
|
71
|
+
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({});
|
|
72
|
+
await client.upsertDashboardAsCode('p1', 'dash/slug', body);
|
|
73
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/dashboards/dash%2Fslug', body);
|
|
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
|
+
});
|
|
33
147
|
});
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Explores API client (v1).
|
|
3
3
|
*/
|
|
4
|
-
import type { ApiExploresResults, ApiExploreResults } from '@lightdash-tools/common';
|
|
5
4
|
import { BaseApiClient } from '../base-client';
|
|
5
|
+
import type { ApiExploresResults, ApiExploreResults, LightdashApi } from '@lightdash-tools/common';
|
|
6
|
+
type CompiledDimension = LightdashApi.Explores.CompiledTable['dimensions'][string];
|
|
6
7
|
export declare class ExploresClient extends BaseApiClient {
|
|
7
8
|
/** List all explores for a project. */
|
|
8
9
|
listExplores(projectUuid: string): Promise<ApiExploresResults>;
|
|
9
10
|
/** Get a specific explore by ID. */
|
|
10
11
|
getExplore(projectUuid: string, exploreId: string): Promise<ApiExploreResults>;
|
|
11
12
|
/** List dimensions for a specific explore. */
|
|
12
|
-
listDimensions(projectUuid: string, exploreId: string): Promise<
|
|
13
|
+
listDimensions(projectUuid: string, exploreId: string): Promise<CompiledDimension[]>;
|
|
13
14
|
/** Get lineage for a specific field in an explore. */
|
|
14
15
|
getFieldLineage(projectUuid: string, exploreId: string, fieldId: string): Promise<unknown>;
|
|
15
16
|
}
|
|
17
|
+
export {};
|
package/dist/api/v1/explores.js
CHANGED
|
@@ -2,49 +2,40 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Explores API client (v1).
|
|
4
4
|
*/
|
|
5
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.ExploresClient = void 0;
|
|
16
7
|
const base_client_1 = require("../base-client");
|
|
17
8
|
class ExploresClient extends base_client_1.BaseApiClient {
|
|
18
9
|
/** List all explores for a project. */
|
|
19
|
-
listExplores(projectUuid) {
|
|
20
|
-
return
|
|
21
|
-
return this.http.get(`/projects/${projectUuid}/explores`);
|
|
22
|
-
});
|
|
10
|
+
async listExplores(projectUuid) {
|
|
11
|
+
return this.http.get(`/projects/${projectUuid}/explores`);
|
|
23
12
|
}
|
|
24
13
|
/** Get a specific explore by ID. */
|
|
25
|
-
getExplore(projectUuid, exploreId) {
|
|
26
|
-
return
|
|
27
|
-
return this.http.get(`/projects/${projectUuid}/explores/${exploreId}`);
|
|
28
|
-
});
|
|
14
|
+
async getExplore(projectUuid, exploreId) {
|
|
15
|
+
return this.http.get(`/projects/${projectUuid}/explores/${exploreId}`);
|
|
29
16
|
}
|
|
30
17
|
/** List dimensions for a specific explore. */
|
|
31
|
-
listDimensions(projectUuid, exploreId) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return Object.values(explore.tables).flatMap((table) => Object.values(table.dimensions));
|
|
35
|
-
});
|
|
18
|
+
async listDimensions(projectUuid, exploreId) {
|
|
19
|
+
const explore = await this.getExplore(projectUuid, exploreId);
|
|
20
|
+
return Object.values(explore.tables).flatMap((table) => Object.values(table.dimensions));
|
|
36
21
|
}
|
|
37
22
|
/** Get lineage for a specific field in an explore. */
|
|
38
|
-
getFieldLineage(projectUuid, exploreId, fieldId) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
async getFieldLineage(projectUuid, exploreId, fieldId) {
|
|
24
|
+
const explore = await this.getExplore(projectUuid, exploreId);
|
|
25
|
+
for (const table of Object.values(explore.tables)) {
|
|
26
|
+
// Table maps are keyed by short field name; also accept `{table}_{name}` fieldIds.
|
|
27
|
+
if (table.dimensions[fieldId] || table.metrics[fieldId]) {
|
|
28
|
+
return table.lineageGraph;
|
|
29
|
+
}
|
|
30
|
+
const prefix = `${table.name}_`;
|
|
31
|
+
if (fieldId.startsWith(prefix)) {
|
|
32
|
+
const shortName = fieldId.slice(prefix.length);
|
|
33
|
+
if (table.dimensions[shortName] || table.metrics[shortName]) {
|
|
43
34
|
return table.lineageGraph;
|
|
44
35
|
}
|
|
45
36
|
}
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
48
39
|
}
|
|
49
40
|
}
|
|
50
41
|
exports.ExploresClient = ExploresClient;
|