@lightdash/cli 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/handlers/exportChartImage.d.ts +1 -0
- package/dist/handlers/exportChartImage.d.ts.map +1 -1
- package/dist/handlers/exportChartImage.js +12 -1
- package/dist/handlers/exportChartImage.test.d.ts +2 -0
- package/dist/handlers/exportChartImage.test.d.ts.map +1 -0
- package/dist/handlers/exportChartImage.test.js +55 -0
- package/dist/index.js +2 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exportChartImage.d.ts","sourceRoot":"","sources":["../../src/handlers/exportChartImage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"exportChartImage.d.ts","sourceRoot":"","sources":["../../src/handlers/exportChartImage.ts"],"names":[],"mappings":"AAQA,KAAK,uBAAuB,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAChC,iBAAiB,MAAM,EACvB,SAAS,uBAAuB,KACjC,OAAO,CAAC,IAAI,CA+Cd,CAAC"}
|
|
@@ -4,15 +4,26 @@ exports.exportChartImageHandler = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
7
|
+
const uuid_1 = require("uuid");
|
|
8
|
+
const config_1 = require("../config");
|
|
7
9
|
const globalState_1 = tslib_1.__importDefault(require("../globalState"));
|
|
8
10
|
const styles = tslib_1.__importStar(require("../styles"));
|
|
9
11
|
const apiClient_1 = require("./dbt/apiClient");
|
|
10
12
|
const exportChartImageHandler = async (chartUuidOrSlug, options) => {
|
|
11
13
|
globalState_1.default.setVerbose(options.verbose ?? false);
|
|
12
14
|
const spinner = globalState_1.default.startSpinner(`Exporting chart image for '${chartUuidOrSlug}'...`);
|
|
15
|
+
const isChartUuid = (0, uuid_1.validate)(chartUuidOrSlug);
|
|
16
|
+
const projectUuid = options.project ??
|
|
17
|
+
(!isChartUuid ? (await (0, config_1.getConfig)()).context?.project : undefined);
|
|
18
|
+
if (!projectUuid && !isChartUuid) {
|
|
19
|
+
throw new Error('A project is required when exporting by slug. Pass --project <uuid> or select a project first.');
|
|
20
|
+
}
|
|
21
|
+
const projectQuery = projectUuid
|
|
22
|
+
? `?projectUuid=${encodeURIComponent(projectUuid)}`
|
|
23
|
+
: '';
|
|
13
24
|
const imageUrl = await (0, apiClient_1.lightdashApi)({
|
|
14
25
|
method: 'POST',
|
|
15
|
-
url: `/api/v1/saved/${chartUuidOrSlug}/export`,
|
|
26
|
+
url: `/api/v1/saved/${chartUuidOrSlug}/export${projectQuery}`,
|
|
16
27
|
body: undefined,
|
|
17
28
|
});
|
|
18
29
|
if (!imageUrl) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exportChartImage.test.d.ts","sourceRoot":"","sources":["../../src/handlers/exportChartImage.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("../config");
|
|
4
|
+
const apiClient_1 = require("./dbt/apiClient");
|
|
5
|
+
const exportChartImage_1 = require("./exportChartImage");
|
|
6
|
+
vi.mock('../config', () => ({ getConfig: vi.fn() }));
|
|
7
|
+
vi.mock('./dbt/apiClient', () => ({ lightdashApi: vi.fn() }));
|
|
8
|
+
vi.mock('../globalState', () => ({
|
|
9
|
+
default: {
|
|
10
|
+
setVerbose: vi.fn(),
|
|
11
|
+
startSpinner: vi.fn(() => ({ warn: vi.fn() })),
|
|
12
|
+
},
|
|
13
|
+
}));
|
|
14
|
+
describe('exportChartImageHandler', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
vi.mocked(apiClient_1.lightdashApi).mockResolvedValue(undefined);
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.clearAllMocks();
|
|
20
|
+
});
|
|
21
|
+
it('scopes a slug to the selected project', async () => {
|
|
22
|
+
vi.mocked(config_1.getConfig).mockResolvedValue({
|
|
23
|
+
context: {
|
|
24
|
+
project: '22222222-2222-4222-8222-222222222222',
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
await (0, exportChartImage_1.exportChartImageHandler)('shared-slug', { output: 'chart.png' });
|
|
28
|
+
expect(apiClient_1.lightdashApi).toHaveBeenCalledWith({
|
|
29
|
+
method: 'POST',
|
|
30
|
+
url: '/api/v1/saved/shared-slug/export?projectUuid=22222222-2222-4222-8222-222222222222',
|
|
31
|
+
body: undefined,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
it('does not scope UUID exports to the selected project', async () => {
|
|
35
|
+
vi.mocked(config_1.getConfig).mockResolvedValue({
|
|
36
|
+
context: {
|
|
37
|
+
project: '22222222-2222-4222-8222-222222222222',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
await (0, exportChartImage_1.exportChartImageHandler)('11111111-1111-4111-8111-111111111111', {
|
|
41
|
+
output: 'chart.png',
|
|
42
|
+
});
|
|
43
|
+
expect(apiClient_1.lightdashApi).toHaveBeenCalledWith({
|
|
44
|
+
method: 'POST',
|
|
45
|
+
url: '/api/v1/saved/11111111-1111-4111-8111-111111111111/export',
|
|
46
|
+
body: undefined,
|
|
47
|
+
});
|
|
48
|
+
expect(config_1.getConfig).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
it('rejects a slug without project context', async () => {
|
|
51
|
+
vi.mocked(config_1.getConfig).mockResolvedValue({});
|
|
52
|
+
await expect((0, exportChartImage_1.exportChartImageHandler)('shared-slug', { output: 'chart.png' })).rejects.toThrow('A project is required when exporting by slug');
|
|
53
|
+
expect(apiClient_1.lightdashApi).not.toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -643,8 +643,9 @@ commander_1.program
|
|
|
643
643
|
commander_1.program
|
|
644
644
|
.command('export-chart-image')
|
|
645
645
|
.description('Export a deployed chart as a PNG image. The chart must already exist on the server.')
|
|
646
|
-
.argument('<chart>', 'Chart slug')
|
|
646
|
+
.argument('<chart>', 'Chart UUID or slug')
|
|
647
647
|
.requiredOption('-o, --output <file>', 'Output file path for the PNG image')
|
|
648
|
+
.option('--project <uuid>', 'Lightdash project UUID (defaults to the currently selected project)')
|
|
648
649
|
.option('--verbose', 'Show detailed output', false)
|
|
649
650
|
.action(exportChartImage_1.exportChartImageHandler);
|
|
650
651
|
commander_1.program
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "Lightdash CLI tool",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"unique-names-generator": "4.7.1",
|
|
42
42
|
"uuid": "11.1.1",
|
|
43
43
|
"yaml": "2.8.3",
|
|
44
|
-
"@lightdash/common": "1.
|
|
45
|
-
"@lightdash/warehouses": "1.
|
|
44
|
+
"@lightdash/common": "1.4.1",
|
|
45
|
+
"@lightdash/warehouses": "1.4.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/inquirer": "8.2.4",
|