Skip to content

Commit 9a93938

Browse files
authored
Add dashboards to public api (#2905)
1 parent 30cf773 commit 9a93938

File tree

43 files changed

+1012
-382
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1012
-382
lines changed

api/server/components.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export {CacheClient} from '../../src/server/components/cache-client';
22
export {RedisConfig, getRedisConfig} from '../../src/server/utils/redis';
33
export {
44
getLandingLayout,
5-
SDK,
65
Utils,
76
getChartkitLayoutSettings,
87
getPlatform,
@@ -22,9 +21,9 @@ export {renderHTML} from '../../src/server/components/charts-engine/components/m
2221

2322
export {initPublicApiSwagger} from '../../src/server/components/public-api';
2423

25-
export {PUBLIC_API_PROXY_MAP, PUBLIC_API_ROUTE} from '../../src/server/components/public-api';
24+
export {PUBLIC_API_BASE_CONFIG, PUBLIC_API_ROUTE} from '../../src/server/components/public-api';
2625
export type {
27-
PublicApiRpcMap,
26+
PublicApiBaseConfig,
2827
PublicApiConfig,
2928
PublicApiSecuritySchemes,
3029
} from '../../src/server/components/public-api/types';

api/server/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export {SERVICE_NAME_DATALENS} from '../../src/server/constants';
2-
export {IPV6_AXIOS_OPTIONS} from '../../src/server/constants/axios';
2+
export {IPV6_AXIOS_OPTIONS} from '../../src/shared/server/axios';
33
export {PUBLIC_API_ORG_ID_HEADER} from '../../src/server/constants/public-api';

src/server/components/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import Utils from '../utils';
22

3-
import {getAxios} from './axios';
4-
import * as SDK from './sdk';
5-
63
export * from '../constants';
74
export * from './layout';
85

9-
export {getAxios, Utils, SDK};
6+
export {Utils};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {PUBLIC_API_VERSION} from '../constants';
2+
import type {PublicApiBaseConfig} from '../types';
3+
4+
import {PUBLIC_API_V0_CONFIG} from './v0';
5+
6+
export const PUBLIC_API_BASE_CONFIG = {
7+
[PUBLIC_API_VERSION.v0]: PUBLIC_API_V0_CONFIG,
8+
} satisfies PublicApiBaseConfig;
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
import {OpenAPIRegistry} from '@asteasolutions/zod-to-openapi';
2+
3+
import {
4+
deleteConnectionArgsSchema,
5+
deleteConnectionResultSchema,
6+
} from '../../../../shared/schema/bi/schemas/connections';
7+
import {
8+
createDatasetArgsSchema,
9+
createDatasetResultSchema,
10+
deleteDatasetArgsSchema,
11+
deleteDatasetResultSchema,
12+
getDatasetByVersionArgsSchema,
13+
getDatasetByVersionResultSchema,
14+
updateDatasetArgsSchema,
15+
updateDatasetResultSchema,
16+
} from '../../../../shared/schema/bi/schemas/datasets';
17+
import {
18+
createDashArgsSchema,
19+
createDashResultSchema,
20+
deleteDashArgsSchema,
21+
deleteDashResultSchema,
22+
getDashArgsSchema,
23+
getDashResultSchema,
24+
updateDashArgsSchema,
25+
updateDashResultSchema,
26+
} from '../../../../shared/schema/mix/schemas/dash';
27+
import {
28+
deleteEditorChartArgsSchema,
29+
deleteEditorChartResultSchema,
30+
} from '../../../../shared/schema/mix/schemas/editor';
31+
import {
32+
deleteWizardChartArgsSchema,
33+
deleteWizardChartResultSchema,
34+
} from '../../../../shared/schema/mix/schemas/wizard';
35+
import {ApiTag} from '../constants';
36+
import type {PublicApiVersionConfig} from '../types';
37+
import {makeAction} from '../utils/make-action';
38+
39+
export const PUBLIC_API_V0_CONFIG = {
40+
openApi: {
41+
registry: new OpenAPIRegistry(),
42+
},
43+
44+
actions: {
45+
// Connection
46+
deleteConnection: makeAction({
47+
schemas: {
48+
args: deleteConnectionArgsSchema,
49+
result: deleteConnectionResultSchema,
50+
},
51+
resolve: (api) => async (args) => {
52+
const {responseData} = await api.bi.deleteConnection(args);
53+
54+
return responseData;
55+
},
56+
openApi: {
57+
summary: 'Delete connection',
58+
tags: [ApiTag.Connection],
59+
},
60+
}),
61+
62+
// Dataset
63+
getDataset: makeAction({
64+
schemas: {
65+
args: getDatasetByVersionArgsSchema,
66+
result: getDatasetByVersionResultSchema,
67+
},
68+
resolve: (api) => async (args) => {
69+
const {responseData} = await api.bi.getDatasetByVersion(args);
70+
71+
return responseData;
72+
},
73+
openApi: {
74+
summary: 'Get dataset',
75+
tags: [ApiTag.Dataset],
76+
},
77+
}),
78+
updateDataset: makeAction({
79+
schemas: {
80+
args: updateDatasetArgsSchema,
81+
result: updateDatasetResultSchema,
82+
},
83+
resolve: (api) => async (args) => {
84+
const {responseData} = await api.bi.updateDataset(args);
85+
86+
return responseData;
87+
},
88+
openApi: {
89+
summary: 'Update dataset',
90+
tags: [ApiTag.Dataset],
91+
},
92+
}),
93+
createDataset: makeAction({
94+
schemas: {
95+
args: createDatasetArgsSchema,
96+
result: createDatasetResultSchema,
97+
},
98+
resolve: (api) => async (args) => {
99+
const {responseData} = await api.bi.createDataset(args);
100+
101+
return responseData;
102+
},
103+
openApi: {
104+
summary: 'Create dataset',
105+
tags: [ApiTag.Dataset],
106+
},
107+
}),
108+
deleteDataset: makeAction({
109+
schemas: {
110+
args: deleteDatasetArgsSchema,
111+
result: deleteDatasetResultSchema,
112+
},
113+
resolve: (api) => async (args) => {
114+
const {responseData} = await api.bi.deleteDataset(args);
115+
116+
return responseData;
117+
},
118+
openApi: {
119+
summary: 'Delete dataset',
120+
tags: [ApiTag.Dataset],
121+
},
122+
}),
123+
124+
// Wizard
125+
deleteWizardChart: makeAction({
126+
schemas: {
127+
args: deleteWizardChartArgsSchema,
128+
result: deleteWizardChartResultSchema,
129+
},
130+
resolve: (api) => async (args) => {
131+
const {responseData} = await api.mix.__deleteWizardChart__(args);
132+
133+
return responseData;
134+
},
135+
openApi: {
136+
summary: 'Delete wizard chart',
137+
tags: [ApiTag.Wizard],
138+
},
139+
}),
140+
141+
// Editor
142+
deleteEditorChart: makeAction({
143+
schemas: {
144+
args: deleteEditorChartArgsSchema,
145+
result: deleteEditorChartResultSchema,
146+
},
147+
resolve: (api) => async (args) => {
148+
const {responseData} = await api.mix.__deleteEditorChart__(args);
149+
150+
return responseData;
151+
},
152+
openApi: {
153+
summary: 'Delete editor chart',
154+
tags: [ApiTag.Editor],
155+
},
156+
}),
157+
158+
// Dashboard
159+
getDashboard: makeAction({
160+
schemas: {
161+
args: getDashArgsSchema,
162+
result: getDashResultSchema,
163+
},
164+
resolve: (api) => async (args) => {
165+
const {responseData} = await api.mix.__getDashboard__(args);
166+
167+
return responseData;
168+
},
169+
openApi: {
170+
summary: 'Get dashboard',
171+
tags: [ApiTag.Dashboard],
172+
},
173+
}),
174+
updateDashboard: makeAction({
175+
schemas: {
176+
args: updateDashArgsSchema,
177+
result: updateDashResultSchema,
178+
},
179+
resolve: (api) => async (args) => {
180+
const {responseData} = await api.mix.__updateDashboard__(args);
181+
182+
return responseData;
183+
},
184+
openApi: {
185+
summary: 'Update dashboard',
186+
tags: [ApiTag.Dashboard],
187+
},
188+
}),
189+
createDashboard: makeAction({
190+
schemas: {
191+
args: createDashArgsSchema,
192+
result: createDashResultSchema,
193+
},
194+
resolve: (api) => async (args) => {
195+
const {responseData} = await api.mix.__createDashboard__(args);
196+
197+
return responseData;
198+
},
199+
openApi: {
200+
summary: 'Create dashboard',
201+
tags: [ApiTag.Dashboard],
202+
},
203+
}),
204+
deleteDashboard: makeAction({
205+
schemas: {
206+
args: deleteDashArgsSchema,
207+
result: deleteDashResultSchema,
208+
},
209+
resolve: (api) => async (args) => {
210+
const {responseData} = await api.mix.__deleteDashboard__(args);
211+
212+
return responseData;
213+
},
214+
openApi: {
215+
summary: 'Delete dashboard',
216+
tags: [ApiTag.Dashboard],
217+
},
218+
}),
219+
},
220+
} satisfies PublicApiVersionConfig;

src/server/components/public-api/constants.ts

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export enum ApiTag {
2+
Connection = 'Connection',
3+
Dataset = 'Dataset',
4+
Wizard = 'Wizard',
5+
Editor = 'Editor',
6+
Dashboard = 'Dashboard',
7+
}
8+
9+
export const PUBLIC_API_VERSION_HEADER = 'x-dl-api-version';
10+
11+
export const PUBLIC_API_VERSION_HEADER_LATEST_VALUE = 'latest';
12+
13+
export const OPEN_API_VERSION_HEADER_COMPONENT_NAME = 'ApiVersionHeader';
14+
15+
export const PUBLIC_API_HTTP_METHOD = 'POST';
16+
export const PUBLIC_API_URL = '/rpc/:action';
17+
export const PUBLIC_API_ROUTE = `${PUBLIC_API_HTTP_METHOD} ${PUBLIC_API_URL}`;
18+
19+
export const PUBLIC_API_VERSION = {
20+
v0: 'v0',
21+
} as const;
22+
23+
export const PUBLIC_API_LATEST_VERSION = PUBLIC_API_VERSION.v0;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './common';
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
export {
2-
PUBLIC_API_PROXY_MAP,
3-
PUBLIC_API_HTTP_METHOD,
4-
PUBLIC_API_ROUTE,
5-
PUBLIC_API_URL,
6-
} from './constants';
1+
export {PUBLIC_API_HTTP_METHOD, PUBLIC_API_ROUTE, PUBLIC_API_URL} from './constants';
72
export {initPublicApiSwagger, registerActionToOpenApi} from './utils';
3+
4+
export {PUBLIC_API_BASE_CONFIG} from './config';

0 commit comments

Comments
 (0)