@lightdash-tools/client 0.6.0 → 0.7.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 +5 -2
- package/dist/api/v1/charts.js +18 -30
- package/dist/api/v1/charts.test.js +19 -28
- package/dist/api/v1/dashboards.d.ts +11 -2
- package/dist/api/v1/dashboards.js +19 -14
- package/dist/api/v1/dashboards.test.js +54 -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 +5 -2
- package/dist/api/v1/validation.js +8 -18
- package/dist/api/v1/validation.test.js +6 -15
- package/dist/api/v2/content.d.ts +2 -2
- package/dist/api/v2/content.js +3 -14
- package/dist/api/v2/content.test.js +3 -12
- package/dist/api/v2/dashboards.d.ts +10 -0
- package/dist/api/v2/dashboards.js +14 -0
- package/dist/api/v2/dashboards.test.d.ts +4 -0
- package/dist/api/v2/dashboards.test.js +27 -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/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 +1 -1
- package/dist/api/v2/query.js +10 -29
- package/dist/api/v2/query.test.js +15 -24
- package/dist/api/v2/validation.d.ts +28 -0
- package/dist/api/v2/validation.js +23 -0
- package/dist/client.d.ts +20 -14
- package/dist/client.js +22 -16
- package/dist/config.d.ts +35 -10
- package/dist/http/axios-client.d.ts +4 -4
- package/dist/http/http-client.d.ts +3 -3
- package/dist/http/http-client.js +19 -40
- 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/index.d.ts +7 -2
- package/dist/index.js +12 -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 +8 -6
- package/src/api/v1/charts.ts +8 -4
- package/src/api/v1/dashboards.test.ts +57 -0
- package/src/api/v1/dashboards.ts +41 -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 +2 -0
- package/src/api/v1/validation.ts +6 -2
- package/src/api/v2/content.test.ts +2 -0
- package/src/api/v2/content.ts +3 -2
- package/src/api/v2/dashboards.test.ts +32 -0
- package/src/api/v2/dashboards.ts +18 -0
- package/src/api/v2/organization-roles.test.ts +2 -0
- package/src/api/v2/organization-roles.ts +2 -1
- 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 +2 -0
- package/src/api/v2/query.ts +2 -1
- package/src/api/v2/validation.ts +48 -0
- package/src/client.test.ts +1 -0
- package/src/client.ts +27 -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 -6
- 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/index.test.ts +16 -7
- package/src/index.ts +16 -1
- 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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
2
3
|
import { AiAgentsClient } from './ai-agents';
|
|
4
|
+
|
|
3
5
|
import type { HttpClient } from '../../http/http-client';
|
|
4
6
|
|
|
5
7
|
describe('AiAgentsClient', () => {
|
|
@@ -137,7 +139,11 @@ describe('AiAgentsClient', () => {
|
|
|
137
139
|
const thread = { uuid: 't1', title: null };
|
|
138
140
|
vi.mocked(mockHttp.post).mockResolvedValue(thread);
|
|
139
141
|
const result = await client.createAgentThread('proj1', 'a1');
|
|
140
|
-
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
142
|
+
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
143
|
+
'/projects/proj1/aiAgents/a1/threads',
|
|
144
|
+
{},
|
|
145
|
+
undefined,
|
|
146
|
+
);
|
|
141
147
|
expect(result).toEqual(thread);
|
|
142
148
|
});
|
|
143
149
|
|
|
@@ -147,7 +153,11 @@ describe('AiAgentsClient', () => {
|
|
|
147
153
|
const thread = { uuid: 't1', title: null };
|
|
148
154
|
vi.mocked(mockHttp.post).mockResolvedValue(thread);
|
|
149
155
|
await client.createAgentThread('proj1', 'a1', body);
|
|
150
|
-
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
156
|
+
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
157
|
+
'/projects/proj1/aiAgents/a1/threads',
|
|
158
|
+
body,
|
|
159
|
+
undefined,
|
|
160
|
+
);
|
|
151
161
|
});
|
|
152
162
|
|
|
153
163
|
it('getAgentThread should call GET .../threads/{threadUuid}', async () => {
|
|
@@ -155,20 +165,164 @@ describe('AiAgentsClient', () => {
|
|
|
155
165
|
const thread = { uuid: 't1', messages: [] };
|
|
156
166
|
vi.mocked(mockHttp.get).mockResolvedValue(thread);
|
|
157
167
|
const result = await client.getAgentThread('proj1', 'a1', 't1');
|
|
158
|
-
expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/threads/t1');
|
|
168
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/threads/t1', undefined);
|
|
159
169
|
expect(result).toEqual(thread);
|
|
160
170
|
});
|
|
161
171
|
|
|
162
|
-
it('
|
|
172
|
+
it('createAgentThreadMessage should call POST .../threads/{threadUuid}/messages', async () => {
|
|
173
|
+
const client = new AiAgentsClient(mockHttp);
|
|
174
|
+
const message = { uuid: 'm1', message: 'Hello', role: 'user' };
|
|
175
|
+
vi.mocked(mockHttp.post).mockResolvedValue(message);
|
|
176
|
+
const body = { prompt: 'What is the total revenue?' };
|
|
177
|
+
const result = await client.createAgentThreadMessage('proj1', 'a1', 't1', body);
|
|
178
|
+
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
179
|
+
'/projects/proj1/aiAgents/a1/threads/t1/messages',
|
|
180
|
+
body,
|
|
181
|
+
undefined,
|
|
182
|
+
);
|
|
183
|
+
expect(result).toEqual(message);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('createAgentThreadMessage should pass RequestOptions to POST', async () => {
|
|
187
|
+
const client = new AiAgentsClient(mockHttp);
|
|
188
|
+
const controller = new AbortController();
|
|
189
|
+
vi.mocked(mockHttp.post).mockResolvedValue({ uuid: 'm1' });
|
|
190
|
+
await client.createAgentThreadMessage(
|
|
191
|
+
'proj1',
|
|
192
|
+
'a1',
|
|
193
|
+
't1',
|
|
194
|
+
{ prompt: 'Hi' },
|
|
195
|
+
{ signal: controller.signal, timeoutMs: 5000, requestId: 'req-1' },
|
|
196
|
+
);
|
|
197
|
+
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
198
|
+
'/projects/proj1/aiAgents/a1/threads/t1/messages',
|
|
199
|
+
{ prompt: 'Hi' },
|
|
200
|
+
{
|
|
201
|
+
signal: controller.signal,
|
|
202
|
+
timeout: 5000,
|
|
203
|
+
headers: { 'X-Request-Id': 'req-1' },
|
|
204
|
+
},
|
|
205
|
+
);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('generateAgentThreadResponse without body should call POST .../generate with no body', async () => {
|
|
163
209
|
const client = new AiAgentsClient(mockHttp);
|
|
164
210
|
const response = { response: 'Here is your answer.' };
|
|
165
211
|
vi.mocked(mockHttp.post).mockResolvedValue(response);
|
|
212
|
+
const result = await client.generateAgentThreadResponse('proj1', 'a1', 't1');
|
|
213
|
+
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
214
|
+
'/projects/proj1/aiAgents/a1/threads/t1/generate',
|
|
215
|
+
undefined,
|
|
216
|
+
undefined,
|
|
217
|
+
);
|
|
218
|
+
expect(result).toEqual(response);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('generateAgentThreadResponse with prompt body should create message then generate', async () => {
|
|
222
|
+
const client = new AiAgentsClient(mockHttp);
|
|
223
|
+
const message = { uuid: 'm1', message: 'What is the total revenue?', role: 'user' };
|
|
224
|
+
const response = { response: 'Here is your answer.' };
|
|
225
|
+
vi.mocked(mockHttp.post).mockResolvedValueOnce(message).mockResolvedValueOnce(response);
|
|
166
226
|
const result = await client.generateAgentThreadResponse('proj1', 'a1', 't1', {
|
|
167
227
|
prompt: 'What is the total revenue?',
|
|
168
228
|
});
|
|
169
|
-
expect(mockHttp.post).
|
|
170
|
-
|
|
171
|
-
|
|
229
|
+
expect(mockHttp.post).toHaveBeenNthCalledWith(
|
|
230
|
+
1,
|
|
231
|
+
'/projects/proj1/aiAgents/a1/threads/t1/messages',
|
|
232
|
+
{ prompt: 'What is the total revenue?' },
|
|
233
|
+
undefined,
|
|
234
|
+
);
|
|
235
|
+
expect(mockHttp.post).toHaveBeenNthCalledWith(
|
|
236
|
+
2,
|
|
237
|
+
'/projects/proj1/aiAgents/a1/threads/t1/generate',
|
|
238
|
+
undefined,
|
|
239
|
+
undefined,
|
|
240
|
+
);
|
|
241
|
+
expect(result).toEqual(response);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('startConversation should create thread, message, and generate', async () => {
|
|
245
|
+
const client = new AiAgentsClient(mockHttp);
|
|
246
|
+
const thread = { uuid: 't1', title: null };
|
|
247
|
+
const message = { uuid: 'm1', message: 'Hello', role: 'user' };
|
|
248
|
+
const response = { response: 'Hi there.' };
|
|
249
|
+
vi.mocked(mockHttp.post)
|
|
250
|
+
.mockResolvedValueOnce(thread)
|
|
251
|
+
.mockResolvedValueOnce(message)
|
|
252
|
+
.mockResolvedValueOnce(response);
|
|
253
|
+
const result = await client.startConversation('proj1', 'a1', { prompt: 'Hello' });
|
|
254
|
+
expect(mockHttp.post).toHaveBeenNthCalledWith(
|
|
255
|
+
1,
|
|
256
|
+
'/projects/proj1/aiAgents/a1/threads',
|
|
257
|
+
{},
|
|
258
|
+
undefined,
|
|
259
|
+
);
|
|
260
|
+
expect(mockHttp.post).toHaveBeenNthCalledWith(
|
|
261
|
+
2,
|
|
262
|
+
'/projects/proj1/aiAgents/a1/threads/t1/messages',
|
|
263
|
+
{ prompt: 'Hello' },
|
|
264
|
+
undefined,
|
|
265
|
+
);
|
|
266
|
+
expect(mockHttp.post).toHaveBeenNthCalledWith(
|
|
267
|
+
3,
|
|
268
|
+
'/projects/proj1/aiAgents/a1/threads/t1/generate',
|
|
269
|
+
undefined,
|
|
270
|
+
undefined,
|
|
271
|
+
);
|
|
272
|
+
expect(result).toEqual({ thread, result: response });
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('startConversation should strip prompt from threadBody when creating thread', async () => {
|
|
276
|
+
const client = new AiAgentsClient(mockHttp);
|
|
277
|
+
const thread = { uuid: 't1', title: null };
|
|
278
|
+
const message = { uuid: 'm1', message: 'Hello', role: 'user' };
|
|
279
|
+
const response = { response: 'Hi there.' };
|
|
280
|
+
vi.mocked(mockHttp.post)
|
|
281
|
+
.mockResolvedValueOnce(thread)
|
|
282
|
+
.mockResolvedValueOnce(message)
|
|
283
|
+
.mockResolvedValueOnce(response);
|
|
284
|
+
const threadBodyWithPrompt = {
|
|
285
|
+
prompt: 'duplicate',
|
|
286
|
+
modelConfig: { modelProvider: 'openai', modelName: 'gpt-4' },
|
|
287
|
+
};
|
|
288
|
+
await client.startConversation(
|
|
289
|
+
'proj1',
|
|
290
|
+
'a1',
|
|
291
|
+
{ prompt: 'Hello' },
|
|
292
|
+
{
|
|
293
|
+
threadBody: threadBodyWithPrompt as Parameters<typeof client.startConversation>[3] extends {
|
|
294
|
+
threadBody?: infer T;
|
|
295
|
+
}
|
|
296
|
+
? T
|
|
297
|
+
: never,
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
expect(mockHttp.post).toHaveBeenNthCalledWith(
|
|
301
|
+
1,
|
|
302
|
+
'/projects/proj1/aiAgents/a1/threads',
|
|
303
|
+
{ modelConfig: { modelProvider: 'openai', modelName: 'gpt-4' } },
|
|
304
|
+
undefined,
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('continueConversation should create message then generate', async () => {
|
|
309
|
+
const client = new AiAgentsClient(mockHttp);
|
|
310
|
+
const message = { uuid: 'm2', message: 'Follow up', role: 'user' };
|
|
311
|
+
const response = { response: 'Sure.' };
|
|
312
|
+
vi.mocked(mockHttp.post).mockResolvedValueOnce(message).mockResolvedValueOnce(response);
|
|
313
|
+
const result = await client.continueConversation('proj1', 'a1', 't1', { prompt: 'Follow up' });
|
|
314
|
+
expect(mockHttp.post).toHaveBeenNthCalledWith(
|
|
315
|
+
1,
|
|
316
|
+
'/projects/proj1/aiAgents/a1/threads/t1/messages',
|
|
317
|
+
{ prompt: 'Follow up' },
|
|
318
|
+
undefined,
|
|
319
|
+
);
|
|
320
|
+
expect(mockHttp.post).toHaveBeenNthCalledWith(
|
|
321
|
+
2,
|
|
322
|
+
'/projects/proj1/aiAgents/a1/threads/t1/generate',
|
|
323
|
+
undefined,
|
|
324
|
+
undefined,
|
|
325
|
+
);
|
|
172
326
|
expect(result).toEqual(response);
|
|
173
327
|
});
|
|
174
328
|
|
|
@@ -212,15 +366,17 @@ describe('AiAgentsClient', () => {
|
|
|
212
366
|
expect(result).toEqual(updated);
|
|
213
367
|
});
|
|
214
368
|
|
|
215
|
-
it('appendToEvaluation should call POST .../evaluations/{evalUuid}/append', async () => {
|
|
369
|
+
it('appendToEvaluation should call POST .../evaluations/{evalUuid}/append and return evaluation', async () => {
|
|
216
370
|
const client = new AiAgentsClient(mockHttp);
|
|
217
371
|
const body = { prompts: [{ prompt: 'Extra?', expectedResponse: null }] };
|
|
218
|
-
|
|
219
|
-
|
|
372
|
+
const updated = { evalUuid: 'e1', title: 'My Eval', prompts: body.prompts };
|
|
373
|
+
vi.mocked(mockHttp.post).mockResolvedValue(updated);
|
|
374
|
+
const result = await client.appendToEvaluation('proj1', 'a1', 'e1', body);
|
|
220
375
|
expect(mockHttp.post).toHaveBeenCalledWith(
|
|
221
376
|
'/projects/proj1/aiAgents/a1/evaluations/e1/append',
|
|
222
377
|
body,
|
|
223
378
|
);
|
|
379
|
+
expect(result).toEqual(updated);
|
|
224
380
|
});
|
|
225
381
|
|
|
226
382
|
it('deleteEvaluation should call DELETE .../evaluations/{evalUuid}', async () => {
|
|
@@ -244,13 +400,33 @@ describe('AiAgentsClient', () => {
|
|
|
244
400
|
expect(result).toEqual(runSummary);
|
|
245
401
|
});
|
|
246
402
|
|
|
247
|
-
it('listEvaluationRuns should
|
|
403
|
+
it('listEvaluationRuns should return full paginated response', async () => {
|
|
248
404
|
const client = new AiAgentsClient(mockHttp);
|
|
249
405
|
const runs = [{ runUuid: 'r1', evalUuid: 'e1', status: 'completed' }];
|
|
250
|
-
const pagedResponse = {
|
|
406
|
+
const pagedResponse = {
|
|
407
|
+
data: { runs },
|
|
408
|
+
pagination: { totalResults: 1, totalPageCount: 1 },
|
|
409
|
+
};
|
|
251
410
|
vi.mocked(mockHttp.get).mockResolvedValue(pagedResponse);
|
|
252
411
|
const result = await client.listEvaluationRuns('proj1', 'a1', 'e1');
|
|
253
|
-
expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/evaluations/e1/runs'
|
|
412
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/evaluations/e1/runs', {
|
|
413
|
+
params: undefined,
|
|
414
|
+
});
|
|
415
|
+
expect(result).toEqual(pagedResponse);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('listAllEvaluationRuns should unwrap runs array from paginated response', async () => {
|
|
419
|
+
const client = new AiAgentsClient(mockHttp);
|
|
420
|
+
const runs = [{ runUuid: 'r1', evalUuid: 'e1', status: 'completed' }];
|
|
421
|
+
const pagedResponse = {
|
|
422
|
+
data: { runs },
|
|
423
|
+
pagination: { totalResults: 1, totalPageCount: 1 },
|
|
424
|
+
};
|
|
425
|
+
vi.mocked(mockHttp.get).mockResolvedValue(pagedResponse);
|
|
426
|
+
const result = await client.listAllEvaluationRuns('proj1', 'a1', 'e1');
|
|
427
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/proj1/aiAgents/a1/evaluations/e1/runs', {
|
|
428
|
+
params: { page: 1, pageSize: 100 },
|
|
429
|
+
});
|
|
254
430
|
expect(result).toEqual(runs);
|
|
255
431
|
});
|
|
256
432
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics client unit tests.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { AnalyticsClient } from './analytics';
|
|
8
|
+
|
|
9
|
+
import type { HttpClient } from '../../http/http-client';
|
|
10
|
+
|
|
11
|
+
describe('AnalyticsClient', () => {
|
|
12
|
+
let mockHttp: HttpClient;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
mockHttp = {
|
|
16
|
+
get: vi.fn(),
|
|
17
|
+
post: vi.fn(),
|
|
18
|
+
put: vi.fn(),
|
|
19
|
+
patch: vi.fn(),
|
|
20
|
+
delete: vi.fn(),
|
|
21
|
+
} as unknown as HttpClient;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('getUserActivity calls GET /analytics/user-activity/{projectUuid}', async () => {
|
|
25
|
+
const client = new AnalyticsClient(mockHttp);
|
|
26
|
+
const mockResponse = { numberUsers: 1, chartViews: [], dashboardViews: [] };
|
|
27
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
28
|
+
const result = await client.getUserActivity('p1');
|
|
29
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/analytics/user-activity/p1');
|
|
30
|
+
expect(result).toEqual(mockResponse);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics API client (v1). Project user-activity metadata (no CSV download).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { BaseApiClient } from '../base-client';
|
|
6
|
+
|
|
7
|
+
import type { components } from '@lightdash-tools/common';
|
|
8
|
+
|
|
9
|
+
export type UserActivity = components['schemas']['UserActivity'];
|
|
10
|
+
|
|
11
|
+
export class AnalyticsClient extends BaseApiClient {
|
|
12
|
+
/** Get user activity summary for a project (views, role counts, unused-ish tables). */
|
|
13
|
+
async getUserActivity(projectUuid: string): Promise<UserActivity> {
|
|
14
|
+
return this.http.get<UserActivity>(`/analytics/user-activity/${projectUuid}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
2
3
|
import { ChartsClient } from './charts';
|
|
4
|
+
|
|
3
5
|
import type { HttpClient } from '../../http/http-client';
|
|
4
6
|
|
|
5
7
|
describe('ChartsClient', () => {
|
|
@@ -24,12 +26,12 @@ describe('ChartsClient', () => {
|
|
|
24
26
|
expect(result).toEqual(charts);
|
|
25
27
|
});
|
|
26
28
|
|
|
27
|
-
it('getChartsAsCode should call GET /projects/{projectUuid}/charts
|
|
29
|
+
it('getChartsAsCode should call GET /projects/{projectUuid}/code/charts with no params when no options', async () => {
|
|
28
30
|
const client = new ChartsClient(mockHttp);
|
|
29
31
|
const results = { offset: 0, total: 1, missingIds: [], charts: [] };
|
|
30
32
|
vi.mocked(mockHttp.get).mockResolvedValue(results);
|
|
31
33
|
const result = await client.getChartsAsCode('p1');
|
|
32
|
-
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts
|
|
34
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/charts', undefined);
|
|
33
35
|
expect(result).toEqual(results);
|
|
34
36
|
});
|
|
35
37
|
|
|
@@ -42,12 +44,12 @@ describe('ChartsClient', () => {
|
|
|
42
44
|
offset: 10,
|
|
43
45
|
languageMap: true,
|
|
44
46
|
});
|
|
45
|
-
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts
|
|
47
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/charts', {
|
|
46
48
|
params: { ids: ['slug-a', 'slug-b'], offset: 10, languageMap: true },
|
|
47
49
|
});
|
|
48
50
|
});
|
|
49
51
|
|
|
50
|
-
it('upsertChartAsCode should call POST /projects/{projectUuid}/charts/{slug}
|
|
52
|
+
it('upsertChartAsCode should call POST /projects/{projectUuid}/code/charts/{slug} with body', async () => {
|
|
51
53
|
const client = new ChartsClient(mockHttp);
|
|
52
54
|
const body = {
|
|
53
55
|
name: 'My Chart',
|
|
@@ -71,7 +73,7 @@ describe('ChartsClient', () => {
|
|
|
71
73
|
const apiResult = { promoted: [], errors: [] };
|
|
72
74
|
vi.mocked(mockHttp.post).mockResolvedValue(apiResult);
|
|
73
75
|
const result = await client.upsertChartAsCode('p1', 'my-chart', body);
|
|
74
|
-
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/charts/my-chart
|
|
76
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/my-chart', body);
|
|
75
77
|
expect(result).toEqual(apiResult);
|
|
76
78
|
});
|
|
77
79
|
|
|
@@ -98,6 +100,6 @@ describe('ChartsClient', () => {
|
|
|
98
100
|
} as Parameters<ChartsClient['upsertChartAsCode']>[2];
|
|
99
101
|
vi.mocked(mockHttp.post).mockResolvedValue({});
|
|
100
102
|
await client.upsertChartAsCode('p1', 'chart/slug', body);
|
|
101
|
-
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/charts/chart%2Fslug
|
|
103
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/chart%2Fslug', body);
|
|
102
104
|
});
|
|
103
105
|
});
|
package/src/api/v1/charts.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* Charts API client. Endpoints for saved charts and chart-as-code operations.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { BaseApiClient } from '../base-client';
|
|
6
|
+
|
|
5
7
|
import type {
|
|
6
8
|
SpaceQuery,
|
|
7
9
|
ChartAsCodeListResults,
|
|
8
10
|
ChartAsCodeUpsertResults,
|
|
9
11
|
UpsertChartAsCodeBody,
|
|
10
12
|
} from '@lightdash-tools/common';
|
|
11
|
-
import { BaseApiClient } from '../base-client';
|
|
12
13
|
|
|
13
14
|
export interface GetChartsAsCodeOptions {
|
|
14
15
|
ids?: string[];
|
|
@@ -17,7 +18,10 @@ export interface GetChartsAsCodeOptions {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export class ChartsClient extends BaseApiClient {
|
|
20
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* List charts in a project (returns SpaceQuery array).
|
|
23
|
+
* @deprecated This API endpoint is deprecated in Lightdash. Use charts-as-code API instead.
|
|
24
|
+
*/
|
|
21
25
|
async listCharts(projectUuid: string): Promise<SpaceQuery[]> {
|
|
22
26
|
return this.http.get<SpaceQuery[]>(`/projects/${projectUuid}/charts`);
|
|
23
27
|
}
|
|
@@ -32,7 +36,7 @@ export class ChartsClient extends BaseApiClient {
|
|
|
32
36
|
if (options?.offset != null) params.offset = options.offset;
|
|
33
37
|
if (options?.languageMap != null) params.languageMap = options.languageMap;
|
|
34
38
|
return this.http.get<ChartAsCodeListResults>(
|
|
35
|
-
`/projects/${projectUuid}/charts
|
|
39
|
+
`/projects/${projectUuid}/code/charts`,
|
|
36
40
|
Object.keys(params).length ? { params } : undefined,
|
|
37
41
|
);
|
|
38
42
|
}
|
|
@@ -44,7 +48,7 @@ export class ChartsClient extends BaseApiClient {
|
|
|
44
48
|
body: UpsertChartAsCodeBody,
|
|
45
49
|
): Promise<ChartAsCodeUpsertResults> {
|
|
46
50
|
return this.http.post<ChartAsCodeUpsertResults>(
|
|
47
|
-
`/projects/${projectUuid}/charts/${encodeURIComponent(slug)}
|
|
51
|
+
`/projects/${projectUuid}/code/charts/${encodeURIComponent(slug)}`,
|
|
48
52
|
body,
|
|
49
53
|
);
|
|
50
54
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
2
3
|
import { DashboardsClient } from './dashboards';
|
|
4
|
+
|
|
3
5
|
import type { HttpClient } from '../../http/http-client';
|
|
4
6
|
|
|
5
7
|
describe('DashboardsClient', () => {
|
|
@@ -23,4 +25,59 @@ describe('DashboardsClient', () => {
|
|
|
23
25
|
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/dashboards');
|
|
24
26
|
expect(result).toEqual(dashboards);
|
|
25
27
|
});
|
|
28
|
+
|
|
29
|
+
it('getDashboardsAsCode should call GET /projects/{projectUuid}/code/dashboards with no params when no options', async () => {
|
|
30
|
+
const client = new DashboardsClient(mockHttp);
|
|
31
|
+
const results = { offset: 0, total: 1, missingIds: [], dashboards: [] };
|
|
32
|
+
vi.mocked(mockHttp.get).mockResolvedValue(results);
|
|
33
|
+
const result = await client.getDashboardsAsCode('p1');
|
|
34
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/dashboards', undefined);
|
|
35
|
+
expect(result).toEqual(results);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('getDashboardsAsCode should call GET with query params when options provided', async () => {
|
|
39
|
+
const client = new DashboardsClient(mockHttp);
|
|
40
|
+
const results = { offset: 0, total: 0, missingIds: [], dashboards: [] };
|
|
41
|
+
vi.mocked(mockHttp.get).mockResolvedValue(results);
|
|
42
|
+
await client.getDashboardsAsCode('p1', {
|
|
43
|
+
ids: ['slug-a', 'slug-b'],
|
|
44
|
+
offset: 10,
|
|
45
|
+
languageMap: true,
|
|
46
|
+
});
|
|
47
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/dashboards', {
|
|
48
|
+
params: { ids: ['slug-a', 'slug-b'], offset: 10, languageMap: true },
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('upsertDashboardAsCode should call POST /projects/{projectUuid}/code/dashboards/{slug} with body', async () => {
|
|
53
|
+
const client = new DashboardsClient(mockHttp);
|
|
54
|
+
const body = {
|
|
55
|
+
name: 'My Dashboard',
|
|
56
|
+
slug: 'my-dashboard',
|
|
57
|
+
updatedAt: '2024-01-01T00:00:00Z',
|
|
58
|
+
version: 1,
|
|
59
|
+
spaceSlug: 'my-space',
|
|
60
|
+
tiles: [],
|
|
61
|
+
} as Parameters<DashboardsClient['upsertDashboardAsCode']>[2];
|
|
62
|
+
const apiResult = { promoted: [], errors: [] };
|
|
63
|
+
vi.mocked(mockHttp.post).mockResolvedValue(apiResult);
|
|
64
|
+
const result = await client.upsertDashboardAsCode('p1', 'my-dashboard', body);
|
|
65
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/dashboards/my-dashboard', body);
|
|
66
|
+
expect(result).toEqual(apiResult);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('upsertDashboardAsCode should encode slug in path', async () => {
|
|
70
|
+
const client = new DashboardsClient(mockHttp);
|
|
71
|
+
const body = {
|
|
72
|
+
name: 'Dashboard',
|
|
73
|
+
slug: 'dash/slug',
|
|
74
|
+
updatedAt: '2024-01-01T00:00:00Z',
|
|
75
|
+
version: 1,
|
|
76
|
+
spaceSlug: 'space',
|
|
77
|
+
tiles: [],
|
|
78
|
+
} as Parameters<DashboardsClient['upsertDashboardAsCode']>[2];
|
|
79
|
+
vi.mocked(mockHttp.post).mockResolvedValue({});
|
|
80
|
+
await client.upsertDashboardAsCode('p1', 'dash/slug', body);
|
|
81
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/dashboards/dash%2Fslug', body);
|
|
82
|
+
});
|
|
26
83
|
});
|
package/src/api/v1/dashboards.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Dashboards API client.
|
|
2
|
+
* Dashboards API client. Endpoints for project dashboards and dashboard-as-code operations.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { DashboardBasicDetailsWithTileTypes } from '@lightdash-tools/common';
|
|
6
5
|
import { BaseApiClient } from '../base-client';
|
|
7
6
|
|
|
7
|
+
import type {
|
|
8
|
+
DashboardBasicDetailsWithTileTypes,
|
|
9
|
+
DashboardAsCodeListResults,
|
|
10
|
+
DashboardAsCodeUpsertResults,
|
|
11
|
+
UpsertDashboardAsCodeBody,
|
|
12
|
+
} from '@lightdash-tools/common';
|
|
13
|
+
|
|
14
|
+
export interface GetDashboardsAsCodeOptions {
|
|
15
|
+
ids?: string[];
|
|
16
|
+
offset?: number;
|
|
17
|
+
languageMap?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
8
20
|
export class DashboardsClient extends BaseApiClient {
|
|
9
21
|
/** List dashboards in a project. */
|
|
10
22
|
async listDashboards(projectUuid: string): Promise<DashboardBasicDetailsWithTileTypes[]> {
|
|
@@ -12,4 +24,31 @@ export class DashboardsClient extends BaseApiClient {
|
|
|
12
24
|
`/projects/${projectUuid}/dashboards`,
|
|
13
25
|
);
|
|
14
26
|
}
|
|
27
|
+
|
|
28
|
+
/** Get dashboards in code representation (for dashboards-as-code workflows). */
|
|
29
|
+
async getDashboardsAsCode(
|
|
30
|
+
projectUuid: string,
|
|
31
|
+
options?: GetDashboardsAsCodeOptions,
|
|
32
|
+
): Promise<DashboardAsCodeListResults> {
|
|
33
|
+
const params: Record<string, unknown> = {};
|
|
34
|
+
if (options?.ids?.length) params.ids = options.ids;
|
|
35
|
+
if (options?.offset != null) params.offset = options.offset;
|
|
36
|
+
if (options?.languageMap != null) params.languageMap = options.languageMap;
|
|
37
|
+
return this.http.get<DashboardAsCodeListResults>(
|
|
38
|
+
`/projects/${projectUuid}/code/dashboards`,
|
|
39
|
+
Object.keys(params).length ? { params } : undefined,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Upsert a dashboard from code representation (create or update by slug). */
|
|
44
|
+
async upsertDashboardAsCode(
|
|
45
|
+
projectUuid: string,
|
|
46
|
+
slug: string,
|
|
47
|
+
body: UpsertDashboardAsCodeBody,
|
|
48
|
+
): Promise<DashboardAsCodeUpsertResults> {
|
|
49
|
+
return this.http.post<DashboardAsCodeUpsertResults>(
|
|
50
|
+
`/projects/${projectUuid}/code/dashboards/${encodeURIComponent(slug)}`,
|
|
51
|
+
body,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
15
54
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
2
3
|
import { ExploresClient } from './explores';
|
|
4
|
+
|
|
3
5
|
import type { HttpClient } from '../../http/http-client';
|
|
4
6
|
|
|
5
7
|
describe('ExploresClient', () => {
|
|
@@ -59,6 +61,7 @@ describe('ExploresClient', () => {
|
|
|
59
61
|
const explore = {
|
|
60
62
|
tables: {
|
|
61
63
|
t1: {
|
|
64
|
+
name: 't1',
|
|
62
65
|
dimensions: {
|
|
63
66
|
d1: { name: 'd1' },
|
|
64
67
|
},
|
|
@@ -71,4 +74,23 @@ describe('ExploresClient', () => {
|
|
|
71
74
|
const result = await client.getFieldLineage('p1', 'e1', 'd1');
|
|
72
75
|
expect(result).toEqual({ upstream: [] });
|
|
73
76
|
});
|
|
77
|
+
|
|
78
|
+
it('getFieldLineage should resolve {table}_{name} fieldIds', async () => {
|
|
79
|
+
const client = new ExploresClient(mockHttp);
|
|
80
|
+
const explore = {
|
|
81
|
+
tables: {
|
|
82
|
+
t1: {
|
|
83
|
+
name: 't1',
|
|
84
|
+
dimensions: {
|
|
85
|
+
d1: { name: 'd1' },
|
|
86
|
+
},
|
|
87
|
+
metrics: {},
|
|
88
|
+
lineageGraph: { upstream: ['x'] },
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
vi.mocked(mockHttp.get).mockResolvedValue(explore);
|
|
93
|
+
const result = await client.getFieldLineage('p1', 'e1', 't1_d1');
|
|
94
|
+
expect(result).toEqual({ upstream: ['x'] });
|
|
95
|
+
});
|
|
74
96
|
});
|
package/src/api/v1/explores.ts
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
* Explores API client (v1).
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { ApiExploresResults, ApiExploreResults, LightdashApi } from '@lightdash-tools/common';
|
|
6
5
|
import { BaseApiClient } from '../base-client';
|
|
7
6
|
|
|
7
|
+
import type { ApiExploresResults, ApiExploreResults, LightdashApi } from '@lightdash-tools/common';
|
|
8
|
+
|
|
9
|
+
type CompiledDimension = LightdashApi.Explores.CompiledTable['dimensions'][string];
|
|
10
|
+
|
|
8
11
|
export class ExploresClient extends BaseApiClient {
|
|
9
12
|
/** List all explores for a project. */
|
|
10
13
|
async listExplores(projectUuid: string): Promise<ApiExploresResults> {
|
|
@@ -17,7 +20,7 @@ export class ExploresClient extends BaseApiClient {
|
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
/** List dimensions for a specific explore. */
|
|
20
|
-
async listDimensions(projectUuid: string, exploreId: string): Promise<
|
|
23
|
+
async listDimensions(projectUuid: string, exploreId: string): Promise<CompiledDimension[]> {
|
|
21
24
|
const explore = await this.getExplore(projectUuid, exploreId);
|
|
22
25
|
return Object.values(explore.tables).flatMap((table: LightdashApi.Explores.CompiledTable) =>
|
|
23
26
|
Object.values(table.dimensions),
|
|
@@ -28,9 +31,17 @@ export class ExploresClient extends BaseApiClient {
|
|
|
28
31
|
async getFieldLineage(projectUuid: string, exploreId: string, fieldId: string): Promise<unknown> {
|
|
29
32
|
const explore = await this.getExplore(projectUuid, exploreId);
|
|
30
33
|
for (const table of Object.values(explore.tables) as LightdashApi.Explores.CompiledTable[]) {
|
|
34
|
+
// Table maps are keyed by short field name; also accept `{table}_{name}` fieldIds.
|
|
31
35
|
if (table.dimensions[fieldId] || table.metrics[fieldId]) {
|
|
32
36
|
return table.lineageGraph;
|
|
33
37
|
}
|
|
38
|
+
const prefix = `${table.name}_`;
|
|
39
|
+
if (fieldId.startsWith(prefix)) {
|
|
40
|
+
const shortName = fieldId.slice(prefix.length);
|
|
41
|
+
if (table.dimensions[shortName] || table.metrics[shortName]) {
|
|
42
|
+
return table.lineageGraph;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
34
45
|
}
|
|
35
46
|
return null;
|
|
36
47
|
}
|
package/src/api/v1/groups.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Groups API client.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { LightdashApi } from '@lightdash-tools/common';
|
|
6
|
-
import { BaseApiClient } from '../base-client';
|
|
7
5
|
import { fetchAllPages } from '../../pagination/fetch-all-pages';
|
|
6
|
+
import { BaseApiClient } from '../base-client';
|
|
7
|
+
|
|
8
|
+
import type { LightdashApi } from '@lightdash-tools/common';
|
|
8
9
|
|
|
9
10
|
/** Query params for listing organization groups. */
|
|
10
11
|
export interface ListGroupsParams {
|
|
@@ -24,13 +25,14 @@ export interface GetGroupParams {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export type GroupOrGroupWithMembers =
|
|
27
|
-
| LightdashApi.Groups.
|
|
28
|
-
|
|
28
|
+
LightdashApi.Groups.Group | LightdashApi.Groups.GroupWithMembers;
|
|
29
|
+
|
|
30
|
+
const ORG_GROUPS_PATH = '/org/groups';
|
|
29
31
|
|
|
30
32
|
export class GroupsClient extends BaseApiClient {
|
|
31
33
|
/** List one page of groups (use listAllGroups for all pages). */
|
|
32
34
|
async listGroups(params?: ListGroupsParams): Promise<LightdashApi.Groups.GroupListResult> {
|
|
33
|
-
return this.http.get<LightdashApi.Groups.GroupListResult>(
|
|
35
|
+
return this.http.get<LightdashApi.Groups.GroupListResult>(ORG_GROUPS_PATH, {
|
|
34
36
|
params,
|
|
35
37
|
});
|
|
36
38
|
}
|
|
@@ -42,7 +44,7 @@ export class GroupsClient extends BaseApiClient {
|
|
|
42
44
|
): Promise<GroupOrGroupWithMembers[]> {
|
|
43
45
|
return fetchAllPages<GroupOrGroupWithMembers>({
|
|
44
46
|
fetchPage: (page, pageSize) =>
|
|
45
|
-
this.http.get<LightdashApi.Groups.GroupListResult>(
|
|
47
|
+
this.http.get<LightdashApi.Groups.GroupListResult>(ORG_GROUPS_PATH, {
|
|
46
48
|
params: { ...params, page, pageSize },
|
|
47
49
|
}),
|
|
48
50
|
pageSize: options?.pageSize,
|
|
@@ -53,7 +55,7 @@ export class GroupsClient extends BaseApiClient {
|
|
|
53
55
|
async createGroup(
|
|
54
56
|
body: LightdashApi.Groups.CreateGroup,
|
|
55
57
|
): Promise<LightdashApi.Groups.GroupWithMembers> {
|
|
56
|
-
return this.http.post<LightdashApi.Groups.GroupWithMembers>(
|
|
58
|
+
return this.http.post<LightdashApi.Groups.GroupWithMembers>(ORG_GROUPS_PATH, body);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
/** Get a group by UUID. */
|