@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
|
@@ -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,24 @@ 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);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('getChartHistory should call GET /saved/{chartUuid}/history', async () => {
|
|
107
|
+
const client = new ChartsClient(mockHttp);
|
|
108
|
+
const history = { chartUuid: 'c1', history: [] };
|
|
109
|
+
vi.mocked(mockHttp.get).mockResolvedValue(history);
|
|
110
|
+
const result = await client.getChartHistory('c1');
|
|
111
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/saved/c1/history');
|
|
112
|
+
expect(result).toEqual(history);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('getChartVersion should call GET /saved/{chartUuid}/version/{versionUuid}', async () => {
|
|
116
|
+
const client = new ChartsClient(mockHttp);
|
|
117
|
+
const version = { chartUuid: 'c1', versionUuid: 'v1' };
|
|
118
|
+
vi.mocked(mockHttp.get).mockResolvedValue(version);
|
|
119
|
+
const result = await client.getChartVersion('c1', 'v1');
|
|
120
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/saved/c1/version/v1');
|
|
121
|
+
expect(result).toEqual(version);
|
|
102
122
|
});
|
|
103
123
|
});
|
package/src/api/v1/charts.ts
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
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,
|
|
12
|
+
components,
|
|
10
13
|
} from '@lightdash-tools/common';
|
|
11
|
-
import { BaseApiClient } from '../base-client';
|
|
12
14
|
|
|
13
15
|
export interface GetChartsAsCodeOptions {
|
|
14
16
|
ids?: string[];
|
|
@@ -16,8 +18,17 @@ export interface GetChartsAsCodeOptions {
|
|
|
16
18
|
languageMap?: boolean;
|
|
17
19
|
}
|
|
18
20
|
|
|
21
|
+
/** Results of GET saved/{chartUuid}/history (chart version history). */
|
|
22
|
+
export type ChartHistoryResults = components['schemas']['ApiGetChartHistoryResponse']['results'];
|
|
23
|
+
|
|
24
|
+
/** Results of GET saved/{chartUuid}/version/{versionUuid} (a single chart version). */
|
|
25
|
+
export type ChartVersionResults = components['schemas']['ApiGetChartVersionResponse']['results'];
|
|
26
|
+
|
|
19
27
|
export class ChartsClient extends BaseApiClient {
|
|
20
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* List charts in a project (returns SpaceQuery array).
|
|
30
|
+
* @deprecated This API endpoint is deprecated in Lightdash. Use charts-as-code API instead.
|
|
31
|
+
*/
|
|
21
32
|
async listCharts(projectUuid: string): Promise<SpaceQuery[]> {
|
|
22
33
|
return this.http.get<SpaceQuery[]>(`/projects/${projectUuid}/charts`);
|
|
23
34
|
}
|
|
@@ -32,7 +43,7 @@ export class ChartsClient extends BaseApiClient {
|
|
|
32
43
|
if (options?.offset != null) params.offset = options.offset;
|
|
33
44
|
if (options?.languageMap != null) params.languageMap = options.languageMap;
|
|
34
45
|
return this.http.get<ChartAsCodeListResults>(
|
|
35
|
-
`/projects/${projectUuid}/charts
|
|
46
|
+
`/projects/${projectUuid}/code/charts`,
|
|
36
47
|
Object.keys(params).length ? { params } : undefined,
|
|
37
48
|
);
|
|
38
49
|
}
|
|
@@ -44,8 +55,18 @@ export class ChartsClient extends BaseApiClient {
|
|
|
44
55
|
body: UpsertChartAsCodeBody,
|
|
45
56
|
): Promise<ChartAsCodeUpsertResults> {
|
|
46
57
|
return this.http.post<ChartAsCodeUpsertResults>(
|
|
47
|
-
`/projects/${projectUuid}/charts/${encodeURIComponent(slug)}
|
|
58
|
+
`/projects/${projectUuid}/code/charts/${encodeURIComponent(slug)}`,
|
|
48
59
|
body,
|
|
49
60
|
);
|
|
50
61
|
}
|
|
62
|
+
|
|
63
|
+
/** Get chart version history from the last 30 days. */
|
|
64
|
+
async getChartHistory(chartUuid: string): Promise<ChartHistoryResults> {
|
|
65
|
+
return this.http.get<ChartHistoryResults>(`/saved/${chartUuid}/history`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Get a single chart version by UUID. */
|
|
69
|
+
async getChartVersion(chartUuid: string, versionUuid: string): Promise<ChartVersionResults> {
|
|
70
|
+
return this.http.get<ChartVersionResults>(`/saved/${chartUuid}/version/${versionUuid}`);
|
|
71
|
+
}
|
|
51
72
|
}
|
|
@@ -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,144 @@ 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
|
+
});
|
|
83
|
+
|
|
84
|
+
it('createDashboard should call POST /projects/{projectUuid}/dashboards with body and no params by default', async () => {
|
|
85
|
+
const client = new DashboardsClient(mockHttp);
|
|
86
|
+
const body = { name: 'New Dashboard', tiles: [], tabs: [] } as Parameters<
|
|
87
|
+
DashboardsClient['createDashboard']
|
|
88
|
+
>[1];
|
|
89
|
+
const created = { uuid: 'd1', name: 'New Dashboard', projectUuid: 'p1' };
|
|
90
|
+
vi.mocked(mockHttp.post).mockResolvedValue(created);
|
|
91
|
+
const result = await client.createDashboard('p1', body);
|
|
92
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/dashboards', body, undefined);
|
|
93
|
+
expect(result).toEqual(created);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('createDashboard should call POST with duplicateFrom query param when provided', async () => {
|
|
97
|
+
const client = new DashboardsClient(mockHttp);
|
|
98
|
+
const body = { dashboardDesc: 'Copy', dashboardName: 'Copy of Dashboard' } as Parameters<
|
|
99
|
+
DashboardsClient['createDashboard']
|
|
100
|
+
>[1];
|
|
101
|
+
vi.mocked(mockHttp.post).mockResolvedValue({});
|
|
102
|
+
await client.createDashboard('p1', body, { duplicateFrom: 'd0' });
|
|
103
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/dashboards', body, {
|
|
104
|
+
params: { duplicateFrom: 'd0' },
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('getDashboardHistory should call GET /dashboards/{dashboardUuidOrSlug}/history', async () => {
|
|
109
|
+
const client = new DashboardsClient(mockHttp);
|
|
110
|
+
const history = { dashboardUuid: 'd1', history: [] };
|
|
111
|
+
vi.mocked(mockHttp.get).mockResolvedValue(history);
|
|
112
|
+
const result = await client.getDashboardHistory('d1');
|
|
113
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/history');
|
|
114
|
+
expect(result).toEqual(history);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('getDashboardHistory should encode slug in path', async () => {
|
|
118
|
+
const client = new DashboardsClient(mockHttp);
|
|
119
|
+
vi.mocked(mockHttp.get).mockResolvedValue({});
|
|
120
|
+
await client.getDashboardHistory('dash/slug');
|
|
121
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/dash%2Fslug/history');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('getDashboardVersion should call GET /dashboards/{dashboardUuidOrSlug}/version/{versionUuid}', async () => {
|
|
125
|
+
const client = new DashboardsClient(mockHttp);
|
|
126
|
+
const version = { dashboardUuid: 'd1', versionUuid: 'v1' };
|
|
127
|
+
vi.mocked(mockHttp.get).mockResolvedValue(version);
|
|
128
|
+
const result = await client.getDashboardVersion('d1', 'v1');
|
|
129
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/version/v1');
|
|
130
|
+
expect(result).toEqual(version);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('getDashboardPromoteDiff should call GET /dashboards/{id}/promoteDiff', async () => {
|
|
134
|
+
const client = new DashboardsClient(mockHttp);
|
|
135
|
+
const diff = { charts: [], dashboards: [], spaces: [] };
|
|
136
|
+
vi.mocked(mockHttp.get).mockResolvedValue(diff);
|
|
137
|
+
const result = await client.getDashboardPromoteDiff('d1');
|
|
138
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/d1/promoteDiff', undefined);
|
|
139
|
+
expect(result).toEqual(diff);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('getDashboardPromoteDiff should pass projectUuid query and encode slug', async () => {
|
|
143
|
+
const client = new DashboardsClient(mockHttp);
|
|
144
|
+
vi.mocked(mockHttp.get).mockResolvedValue({ charts: [], dashboards: [], spaces: [] });
|
|
145
|
+
await client.getDashboardPromoteDiff('dash/slug', { projectUuid: 'p1' });
|
|
146
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/dashboards/dash%2Fslug/promoteDiff', {
|
|
147
|
+
params: { projectUuid: 'p1' },
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('promoteDashboard should call POST /dashboards/{id}/promote', async () => {
|
|
152
|
+
const client = new DashboardsClient(mockHttp);
|
|
153
|
+
const promoted = { uuid: 'd1', name: 'Board', projectUuid: 'upstream' };
|
|
154
|
+
vi.mocked(mockHttp.post).mockResolvedValue(promoted);
|
|
155
|
+
const result = await client.promoteDashboard('d1');
|
|
156
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/dashboards/d1/promote', undefined, undefined);
|
|
157
|
+
expect(result).toEqual(promoted);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('promoteDashboard should pass projectUuid query and encode slug', async () => {
|
|
161
|
+
const client = new DashboardsClient(mockHttp);
|
|
162
|
+
vi.mocked(mockHttp.post).mockResolvedValue({});
|
|
163
|
+
await client.promoteDashboard('dash/slug', { projectUuid: 'p1' });
|
|
164
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/dashboards/dash%2Fslug/promote', undefined, {
|
|
165
|
+
params: { projectUuid: 'p1' },
|
|
166
|
+
});
|
|
167
|
+
});
|
|
26
168
|
});
|