@lightdash-tools/client 0.5.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.
Files changed (237) hide show
  1. package/README.md +2 -2
  2. package/dist/agentops/apply-agent-change.d.ts +3 -0
  3. package/dist/agentops/apply-agent-change.js +63 -0
  4. package/dist/agentops/apply-bundle-diff.d.ts +13 -0
  5. package/dist/agentops/apply-bundle-diff.js +44 -0
  6. package/dist/agentops/apply-bundle-diff.test.d.ts +1 -0
  7. package/dist/agentops/apply-bundle-diff.test.js +397 -0
  8. package/dist/agentops/apply-context.d.ts +14 -0
  9. package/dist/agentops/apply-context.js +6 -0
  10. package/dist/agentops/apply-evaluation-change.d.ts +3 -0
  11. package/dist/agentops/apply-evaluation-change.js +78 -0
  12. package/dist/agentops/fetch-bundle-state.d.ts +6 -0
  13. package/dist/agentops/fetch-bundle-state.js +20 -0
  14. package/dist/agentops/fetch-bundle-state.test.d.ts +1 -0
  15. package/dist/agentops/fetch-bundle-state.test.js +44 -0
  16. package/dist/agentops/index.d.ts +3 -0
  17. package/dist/agentops/index.js +9 -0
  18. package/dist/agentops/resolve-evaluation-run.d.ts +15 -0
  19. package/dist/agentops/resolve-evaluation-run.js +48 -0
  20. package/dist/api/v1/ai-agents/admin.d.ts +16 -0
  21. package/dist/api/v1/ai-agents/admin.js +29 -0
  22. package/dist/api/v1/ai-agents/agents.d.ts +18 -0
  23. package/dist/api/v1/ai-agents/agents.js +31 -0
  24. package/dist/api/v1/ai-agents/artifacts.d.ts +26 -0
  25. package/dist/api/v1/ai-agents/artifacts.js +41 -0
  26. package/dist/api/v1/ai-agents/artifacts.test.d.ts +1 -0
  27. package/dist/api/v1/ai-agents/artifacts.test.js +69 -0
  28. package/dist/api/v1/ai-agents/discovery.d.ts +28 -0
  29. package/dist/api/v1/ai-agents/discovery.js +46 -0
  30. package/dist/api/v1/ai-agents/discovery.test.d.ts +1 -0
  31. package/dist/api/v1/ai-agents/discovery.test.js +90 -0
  32. package/dist/api/v1/ai-agents/evaluations.d.ts +39 -0
  33. package/dist/api/v1/ai-agents/evaluations.js +70 -0
  34. package/dist/api/v1/ai-agents/facade.d.ts +79 -0
  35. package/dist/api/v1/ai-agents/facade.js +193 -0
  36. package/dist/api/v1/ai-agents/feedback.d.ts +10 -0
  37. package/dist/api/v1/ai-agents/feedback.js +15 -0
  38. package/dist/api/v1/ai-agents/feedback.test.d.ts +1 -0
  39. package/dist/api/v1/ai-agents/feedback.test.js +23 -0
  40. package/dist/api/v1/ai-agents/index.d.ts +1 -0
  41. package/dist/api/v1/ai-agents/index.js +5 -0
  42. package/dist/api/v1/ai-agents/mcp-servers.d.ts +20 -0
  43. package/dist/api/v1/ai-agents/mcp-servers.js +35 -0
  44. package/dist/api/v1/ai-agents/mcp-servers.test.d.ts +1 -0
  45. package/dist/api/v1/ai-agents/mcp-servers.test.js +66 -0
  46. package/dist/api/v1/ai-agents/request-options.d.ts +12 -0
  47. package/dist/api/v1/ai-agents/request-options.js +20 -0
  48. package/dist/api/v1/ai-agents/sql-approval.d.ts +10 -0
  49. package/dist/api/v1/ai-agents/sql-approval.js +15 -0
  50. package/dist/api/v1/ai-agents/sql-approval.test.d.ts +1 -0
  51. package/dist/api/v1/ai-agents/sql-approval.test.js +25 -0
  52. package/dist/api/v1/ai-agents/threads.d.ts +56 -0
  53. package/dist/api/v1/ai-agents/threads.js +97 -0
  54. package/dist/api/v1/ai-agents/threads.test.d.ts +1 -0
  55. package/dist/api/v1/ai-agents/threads.test.js +39 -0
  56. package/dist/api/v1/ai-agents.test.js +172 -89
  57. package/dist/api/v1/analytics.d.ts +10 -0
  58. package/dist/api/v1/analytics.js +14 -0
  59. package/dist/api/v1/analytics.test.d.ts +4 -0
  60. package/dist/api/v1/analytics.test.js +27 -0
  61. package/dist/api/v1/charts.d.ts +5 -2
  62. package/dist/api/v1/charts.js +18 -30
  63. package/dist/api/v1/charts.test.js +19 -28
  64. package/dist/api/v1/dashboards.d.ts +11 -2
  65. package/dist/api/v1/dashboards.js +19 -14
  66. package/dist/api/v1/dashboards.test.js +54 -12
  67. package/dist/api/v1/explores.d.ts +4 -2
  68. package/dist/api/v1/explores.js +20 -29
  69. package/dist/api/v1/explores.test.js +31 -21
  70. package/dist/api/v1/groups.d.ts +1 -1
  71. package/dist/api/v1/groups.js +25 -51
  72. package/dist/api/v1/groups.test.js +15 -24
  73. package/dist/api/v1/metrics.d.ts +2 -2
  74. package/dist/api/v1/metrics.js +4 -17
  75. package/dist/api/v1/metrics.test.js +6 -15
  76. package/dist/api/v1/organizations.d.ts +1 -1
  77. package/dist/api/v1/organizations.js +2 -13
  78. package/dist/api/v1/organizations.test.js +3 -12
  79. package/dist/api/v1/project-access.d.ts +1 -1
  80. package/dist/api/v1/project-access.js +18 -45
  81. package/dist/api/v1/project-access.test.js +27 -36
  82. package/dist/api/v1/projects.d.ts +1 -1
  83. package/dist/api/v1/projects.js +6 -21
  84. package/dist/api/v1/projects.test.js +9 -18
  85. package/dist/api/v1/query.d.ts +5 -2
  86. package/dist/api/v1/query.js +8 -18
  87. package/dist/api/v1/query.test.js +6 -15
  88. package/dist/api/v1/schedulers.d.ts +2 -2
  89. package/dist/api/v1/schedulers.js +4 -17
  90. package/dist/api/v1/schedulers.test.js +6 -15
  91. package/dist/api/v1/spaces.d.ts +1 -1
  92. package/dist/api/v1/spaces.js +18 -45
  93. package/dist/api/v1/spaces.test.js +27 -36
  94. package/dist/api/v1/tags.d.ts +1 -1
  95. package/dist/api/v1/tags.js +4 -17
  96. package/dist/api/v1/tags.test.js +6 -15
  97. package/dist/api/v1/users.d.ts +3 -1
  98. package/dist/api/v1/users.js +22 -39
  99. package/dist/api/v1/users.test.js +44 -30
  100. package/dist/api/v1/validation.d.ts +5 -2
  101. package/dist/api/v1/validation.js +8 -18
  102. package/dist/api/v1/validation.test.js +6 -15
  103. package/dist/api/v2/content.d.ts +2 -2
  104. package/dist/api/v2/content.js +3 -14
  105. package/dist/api/v2/content.test.js +3 -12
  106. package/dist/api/v2/dashboards.d.ts +10 -0
  107. package/dist/api/v2/dashboards.js +14 -0
  108. package/dist/api/v2/dashboards.test.d.ts +4 -0
  109. package/dist/api/v2/dashboards.test.js +27 -0
  110. package/dist/api/v2/organization-roles.d.ts +1 -1
  111. package/dist/api/v2/organization-roles.js +21 -50
  112. package/dist/api/v2/organization-roles.test.js +33 -42
  113. package/dist/api/v2/project-role-assignments.d.ts +1 -1
  114. package/dist/api/v2/project-role-assignments.js +12 -33
  115. package/dist/api/v2/project-role-assignments.test.js +18 -27
  116. package/dist/api/v2/query.d.ts +1 -1
  117. package/dist/api/v2/query.js +10 -29
  118. package/dist/api/v2/query.test.js +15 -24
  119. package/dist/api/v2/validation.d.ts +28 -0
  120. package/dist/api/v2/validation.js +23 -0
  121. package/dist/client.d.ts +20 -14
  122. package/dist/client.js +22 -16
  123. package/dist/config.d.ts +35 -10
  124. package/dist/http/axios-client.d.ts +4 -4
  125. package/dist/http/http-client.d.ts +3 -3
  126. package/dist/http/http-client.js +19 -40
  127. package/dist/http/interceptors.d.ts +3 -3
  128. package/dist/http/interceptors.js +16 -3
  129. package/dist/http/rate-limiter.js +2 -13
  130. package/dist/http/rate-limiter.test.js +15 -24
  131. package/dist/index.d.ts +7 -2
  132. package/dist/index.js +12 -1
  133. package/dist/index.test.js +13 -5
  134. package/dist/pagination/fetch-all-pages.js +18 -29
  135. package/dist/pagination/fetch-all-pages.test.js +15 -24
  136. package/dist/types/api.d.ts +1 -1
  137. package/dist/utils/env.d.ts +11 -2
  138. package/dist/utils/env.js +41 -8
  139. package/dist/utils/env.test.js +14 -4
  140. package/dist/utils/logger.js +5 -4
  141. package/dist/utils/retry.js +17 -28
  142. package/dist/utils/retry.test.js +9 -18
  143. package/dist/utils/secret-string.test.d.ts +1 -0
  144. package/dist/utils/secret-string.test.js +25 -0
  145. package/package.json +12 -4
  146. package/src/agentops/apply-agent-change.ts +82 -0
  147. package/src/agentops/apply-bundle-diff.test.ts +453 -0
  148. package/src/agentops/apply-bundle-diff.ts +63 -0
  149. package/src/agentops/apply-context.ts +23 -0
  150. package/src/agentops/apply-evaluation-change.ts +125 -0
  151. package/src/agentops/fetch-bundle-state.test.ts +51 -0
  152. package/src/agentops/fetch-bundle-state.ts +33 -0
  153. package/src/agentops/index.ts +11 -0
  154. package/src/agentops/resolve-evaluation-run.ts +94 -0
  155. package/src/api/v1/ai-agents/admin.ts +41 -0
  156. package/src/api/v1/ai-agents/agents.ts +40 -0
  157. package/src/api/v1/ai-agents/artifacts.test.ts +84 -0
  158. package/src/api/v1/ai-agents/artifacts.ts +92 -0
  159. package/src/api/v1/ai-agents/discovery.test.ts +102 -0
  160. package/src/api/v1/ai-agents/discovery.ts +79 -0
  161. package/src/api/v1/ai-agents/evaluations.ts +152 -0
  162. package/src/api/v1/ai-agents/facade.ts +489 -0
  163. package/src/api/v1/ai-agents/feedback.test.ts +30 -0
  164. package/src/api/v1/ai-agents/feedback.ts +24 -0
  165. package/src/api/v1/ai-agents/index.ts +1 -0
  166. package/src/api/v1/ai-agents/mcp-servers.test.ts +81 -0
  167. package/src/api/v1/ai-agents/mcp-servers.ts +67 -0
  168. package/src/api/v1/ai-agents/request-options.ts +32 -0
  169. package/src/api/v1/ai-agents/sql-approval.test.ts +32 -0
  170. package/src/api/v1/ai-agents/sql-approval.ts +24 -0
  171. package/src/api/v1/ai-agents/threads.test.ts +55 -0
  172. package/src/api/v1/ai-agents/threads.ts +216 -0
  173. package/src/api/v1/ai-agents.test.ts +189 -13
  174. package/src/api/v1/analytics.test.ts +32 -0
  175. package/src/api/v1/analytics.ts +16 -0
  176. package/src/api/v1/charts.test.ts +8 -6
  177. package/src/api/v1/charts.ts +8 -4
  178. package/src/api/v1/dashboards.test.ts +57 -0
  179. package/src/api/v1/dashboards.ts +41 -2
  180. package/src/api/v1/explores.test.ts +22 -0
  181. package/src/api/v1/explores.ts +13 -2
  182. package/src/api/v1/groups.test.ts +2 -0
  183. package/src/api/v1/groups.ts +9 -7
  184. package/src/api/v1/metrics.test.ts +2 -0
  185. package/src/api/v1/metrics.ts +3 -2
  186. package/src/api/v1/organizations.test.ts +2 -0
  187. package/src/api/v1/organizations.ts +2 -1
  188. package/src/api/v1/project-access.test.ts +3 -1
  189. package/src/api/v1/project-access.ts +2 -1
  190. package/src/api/v1/projects.test.ts +2 -0
  191. package/src/api/v1/projects.ts +2 -1
  192. package/src/api/v1/query.test.ts +2 -0
  193. package/src/api/v1/query.ts +6 -2
  194. package/src/api/v1/schedulers.test.ts +2 -0
  195. package/src/api/v1/schedulers.ts +3 -2
  196. package/src/api/v1/spaces.test.ts +2 -0
  197. package/src/api/v1/spaces.ts +2 -1
  198. package/src/api/v1/tags.test.ts +2 -0
  199. package/src/api/v1/tags.ts +2 -1
  200. package/src/api/v1/users.test.ts +26 -0
  201. package/src/api/v1/users.ts +8 -2
  202. package/src/api/v1/validation.test.ts +2 -0
  203. package/src/api/v1/validation.ts +6 -2
  204. package/src/api/v2/content.test.ts +2 -0
  205. package/src/api/v2/content.ts +3 -2
  206. package/src/api/v2/dashboards.test.ts +32 -0
  207. package/src/api/v2/dashboards.ts +18 -0
  208. package/src/api/v2/organization-roles.test.ts +2 -0
  209. package/src/api/v2/organization-roles.ts +2 -1
  210. package/src/api/v2/project-role-assignments.test.ts +2 -0
  211. package/src/api/v2/project-role-assignments.ts +2 -1
  212. package/src/api/v2/query.test.ts +2 -0
  213. package/src/api/v2/query.ts +2 -1
  214. package/src/api/v2/validation.ts +48 -0
  215. package/src/client.test.ts +1 -0
  216. package/src/client.ts +27 -17
  217. package/src/config.ts +38 -10
  218. package/src/errors.test.ts +1 -0
  219. package/src/http/axios-client.ts +8 -5
  220. package/src/http/http-client.ts +8 -6
  221. package/src/http/interceptors.ts +23 -10
  222. package/src/http/rate-limiter.test.ts +1 -0
  223. package/src/http/rate-limiter.ts +3 -1
  224. package/src/index.test.ts +16 -7
  225. package/src/index.ts +16 -1
  226. package/src/pagination/fetch-all-pages.test.ts +2 -0
  227. package/src/types/api.ts +1 -1
  228. package/src/utils/env.test.ts +16 -4
  229. package/src/utils/env.ts +61 -10
  230. package/src/utils/logger.ts +6 -4
  231. package/src/utils/retry.test.ts +1 -0
  232. package/src/utils/retry.ts +2 -1
  233. package/src/utils/secret-string.test.ts +27 -0
  234. package/tsconfig.json +4 -2
  235. package/dist/api/v1/ai-agents.d.ts +0 -63
  236. package/dist/api/v1/ai-agents.js +0 -173
  237. package/src/api/v1/ai-agents.ts +0 -252
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Analytics client unit tests.
3
+ */
4
+ export {};
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /**
3
+ * Analytics client unit tests.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const vitest_1 = require("vitest");
7
+ const analytics_1 = require("./analytics");
8
+ (0, vitest_1.describe)('AnalyticsClient', () => {
9
+ let mockHttp;
10
+ (0, vitest_1.beforeEach)(() => {
11
+ mockHttp = {
12
+ get: vitest_1.vi.fn(),
13
+ post: vitest_1.vi.fn(),
14
+ put: vitest_1.vi.fn(),
15
+ patch: vitest_1.vi.fn(),
16
+ delete: vitest_1.vi.fn(),
17
+ };
18
+ });
19
+ (0, vitest_1.it)('getUserActivity calls GET /analytics/user-activity/{projectUuid}', async () => {
20
+ const client = new analytics_1.AnalyticsClient(mockHttp);
21
+ const mockResponse = { numberUsers: 1, chartViews: [], dashboardViews: [] };
22
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
23
+ const result = await client.getUserActivity('p1');
24
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/analytics/user-activity/p1');
25
+ (0, vitest_1.expect)(result).toEqual(mockResponse);
26
+ });
27
+ });
@@ -1,15 +1,18 @@
1
1
  /**
2
2
  * Charts API client. Endpoints for saved charts and chart-as-code operations.
3
3
  */
4
- import type { SpaceQuery, ChartAsCodeListResults, ChartAsCodeUpsertResults, UpsertChartAsCodeBody } from '@lightdash-tools/common';
5
4
  import { BaseApiClient } from '../base-client';
5
+ import type { SpaceQuery, ChartAsCodeListResults, ChartAsCodeUpsertResults, UpsertChartAsCodeBody } from '@lightdash-tools/common';
6
6
  export interface GetChartsAsCodeOptions {
7
7
  ids?: string[];
8
8
  offset?: number;
9
9
  languageMap?: boolean;
10
10
  }
11
11
  export declare class ChartsClient extends BaseApiClient {
12
- /** List charts in a project (returns SpaceQuery array). */
12
+ /**
13
+ * List charts in a project (returns SpaceQuery array).
14
+ * @deprecated This API endpoint is deprecated in Lightdash. Use charts-as-code API instead.
15
+ */
13
16
  listCharts(projectUuid: string): Promise<SpaceQuery[]>;
14
17
  /** Get charts in code representation (for charts-as-code workflows). */
15
18
  getChartsAsCode(projectUuid: string, options?: GetChartsAsCodeOptions): Promise<ChartAsCodeListResults>;
@@ -2,44 +2,32 @@
2
2
  /**
3
3
  * Charts API client. Endpoints for saved charts and chart-as-code operations.
4
4
  */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.ChartsClient = void 0;
16
7
  const base_client_1 = require("../base-client");
17
8
  class ChartsClient extends base_client_1.BaseApiClient {
18
- /** List charts in a project (returns SpaceQuery array). */
19
- listCharts(projectUuid) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- return this.http.get(`/projects/${projectUuid}/charts`);
22
- });
9
+ /**
10
+ * List charts in a project (returns SpaceQuery array).
11
+ * @deprecated This API endpoint is deprecated in Lightdash. Use charts-as-code API instead.
12
+ */
13
+ async listCharts(projectUuid) {
14
+ return this.http.get(`/projects/${projectUuid}/charts`);
23
15
  }
24
16
  /** Get charts in code representation (for charts-as-code workflows). */
25
- getChartsAsCode(projectUuid, options) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- var _a;
28
- const params = {};
29
- if ((_a = options === null || options === void 0 ? void 0 : options.ids) === null || _a === void 0 ? void 0 : _a.length)
30
- params.ids = options.ids;
31
- if ((options === null || options === void 0 ? void 0 : options.offset) != null)
32
- params.offset = options.offset;
33
- if ((options === null || options === void 0 ? void 0 : options.languageMap) != null)
34
- params.languageMap = options.languageMap;
35
- return this.http.get(`/projects/${projectUuid}/charts/code`, Object.keys(params).length ? { params } : undefined);
36
- });
17
+ async getChartsAsCode(projectUuid, options) {
18
+ var _a;
19
+ const params = {};
20
+ if ((_a = options === null || options === void 0 ? void 0 : options.ids) === null || _a === void 0 ? void 0 : _a.length)
21
+ params.ids = options.ids;
22
+ if ((options === null || options === void 0 ? void 0 : options.offset) != null)
23
+ params.offset = options.offset;
24
+ if ((options === null || options === void 0 ? void 0 : options.languageMap) != null)
25
+ params.languageMap = options.languageMap;
26
+ return this.http.get(`/projects/${projectUuid}/code/charts`, Object.keys(params).length ? { params } : undefined);
37
27
  }
38
28
  /** Upsert a chart from code representation (create or update by slug). */
39
- upsertChartAsCode(projectUuid, slug, body) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return this.http.post(`/projects/${projectUuid}/charts/${encodeURIComponent(slug)}/code`, body);
42
- });
29
+ async upsertChartAsCode(projectUuid, slug, body) {
30
+ return this.http.post(`/projects/${projectUuid}/code/charts/${encodeURIComponent(slug)}`, body);
43
31
  }
44
32
  }
45
33
  exports.ChartsClient = ChartsClient;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const vitest_1 = require("vitest");
13
4
  const charts_1 = require("./charts");
@@ -22,36 +13,36 @@ const charts_1 = require("./charts");
22
13
  delete: vitest_1.vi.fn(),
23
14
  };
24
15
  });
25
- (0, vitest_1.it)('listCharts should call GET /projects/{projectUuid}/charts', () => __awaiter(void 0, void 0, void 0, function* () {
16
+ (0, vitest_1.it)('listCharts should call GET /projects/{projectUuid}/charts', async () => {
26
17
  const client = new charts_1.ChartsClient(mockHttp);
27
18
  const charts = [{ uuid: 'c1', name: 'Chart 1', projectUuid: 'p1' }];
28
19
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(charts);
29
- const result = yield client.listCharts('p1');
20
+ const result = await client.listCharts('p1');
30
21
  (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts');
31
22
  (0, vitest_1.expect)(result).toEqual(charts);
32
- }));
33
- (0, vitest_1.it)('getChartsAsCode should call GET /projects/{projectUuid}/charts/code with no params when no options', () => __awaiter(void 0, void 0, void 0, function* () {
23
+ });
24
+ (0, vitest_1.it)('getChartsAsCode should call GET /projects/{projectUuid}/code/charts with no params when no options', async () => {
34
25
  const client = new charts_1.ChartsClient(mockHttp);
35
26
  const results = { offset: 0, total: 1, missingIds: [], charts: [] };
36
27
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
37
- const result = yield client.getChartsAsCode('p1');
38
- (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts/code', undefined);
28
+ const result = await client.getChartsAsCode('p1');
29
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/charts', undefined);
39
30
  (0, vitest_1.expect)(result).toEqual(results);
40
- }));
41
- (0, vitest_1.it)('getChartsAsCode should call GET with query params when options provided', () => __awaiter(void 0, void 0, void 0, function* () {
31
+ });
32
+ (0, vitest_1.it)('getChartsAsCode should call GET with query params when options provided', async () => {
42
33
  const client = new charts_1.ChartsClient(mockHttp);
43
34
  const results = { offset: 0, total: 0, missingIds: [], charts: [] };
44
35
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
45
- yield client.getChartsAsCode('p1', {
36
+ await client.getChartsAsCode('p1', {
46
37
  ids: ['slug-a', 'slug-b'],
47
38
  offset: 10,
48
39
  languageMap: true,
49
40
  });
50
- (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts/code', {
41
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/charts', {
51
42
  params: { ids: ['slug-a', 'slug-b'], offset: 10, languageMap: true },
52
43
  });
53
- }));
54
- (0, vitest_1.it)('upsertChartAsCode should call POST /projects/{projectUuid}/charts/{slug}/code with body', () => __awaiter(void 0, void 0, void 0, function* () {
44
+ });
45
+ (0, vitest_1.it)('upsertChartAsCode should call POST /projects/{projectUuid}/code/charts/{slug} with body', async () => {
55
46
  const client = new charts_1.ChartsClient(mockHttp);
56
47
  const body = {
57
48
  name: 'My Chart',
@@ -74,11 +65,11 @@ const charts_1 = require("./charts");
74
65
  };
75
66
  const apiResult = { promoted: [], errors: [] };
76
67
  vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(apiResult);
77
- const result = yield client.upsertChartAsCode('p1', 'my-chart', body);
78
- (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/charts/my-chart/code', body);
68
+ const result = await client.upsertChartAsCode('p1', 'my-chart', body);
69
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/my-chart', body);
79
70
  (0, vitest_1.expect)(result).toEqual(apiResult);
80
- }));
81
- (0, vitest_1.it)('upsertChartAsCode should encode slug in path', () => __awaiter(void 0, void 0, void 0, function* () {
71
+ });
72
+ (0, vitest_1.it)('upsertChartAsCode should encode slug in path', async () => {
82
73
  const client = new charts_1.ChartsClient(mockHttp);
83
74
  const body = {
84
75
  name: 'Chart',
@@ -100,7 +91,7 @@ const charts_1 = require("./charts");
100
91
  chartConfig: {},
101
92
  };
102
93
  vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({});
103
- yield client.upsertChartAsCode('p1', 'chart/slug', body);
104
- (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/charts/chart%2Fslug/code', body);
105
- }));
94
+ await client.upsertChartAsCode('p1', 'chart/slug', body);
95
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/chart%2Fslug', body);
96
+ });
106
97
  });
@@ -1,9 +1,18 @@
1
1
  /**
2
- * Dashboards API client.
2
+ * Dashboards API client. Endpoints for project dashboards and dashboard-as-code operations.
3
3
  */
4
- import type { DashboardBasicDetailsWithTileTypes } from '@lightdash-tools/common';
5
4
  import { BaseApiClient } from '../base-client';
5
+ import type { DashboardBasicDetailsWithTileTypes, DashboardAsCodeListResults, DashboardAsCodeUpsertResults, UpsertDashboardAsCodeBody } from '@lightdash-tools/common';
6
+ export interface GetDashboardsAsCodeOptions {
7
+ ids?: string[];
8
+ offset?: number;
9
+ languageMap?: boolean;
10
+ }
6
11
  export declare class DashboardsClient extends BaseApiClient {
7
12
  /** List dashboards in a project. */
8
13
  listDashboards(projectUuid: string): Promise<DashboardBasicDetailsWithTileTypes[]>;
14
+ /** Get dashboards in code representation (for dashboards-as-code workflows). */
15
+ getDashboardsAsCode(projectUuid: string, options?: GetDashboardsAsCodeOptions): Promise<DashboardAsCodeListResults>;
16
+ /** Upsert a dashboard from code representation (create or update by slug). */
17
+ upsertDashboardAsCode(projectUuid: string, slug: string, body: UpsertDashboardAsCodeBody): Promise<DashboardAsCodeUpsertResults>;
9
18
  }
@@ -1,25 +1,30 @@
1
1
  "use strict";
2
2
  /**
3
- * Dashboards API client.
3
+ * Dashboards API client. Endpoints for project dashboards and dashboard-as-code operations.
4
4
  */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.DashboardsClient = void 0;
16
7
  const base_client_1 = require("../base-client");
17
8
  class DashboardsClient extends base_client_1.BaseApiClient {
18
9
  /** List dashboards in a project. */
19
- listDashboards(projectUuid) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- return this.http.get(`/projects/${projectUuid}/dashboards`);
22
- });
10
+ async listDashboards(projectUuid) {
11
+ return this.http.get(`/projects/${projectUuid}/dashboards`);
12
+ }
13
+ /** Get dashboards in code representation (for dashboards-as-code workflows). */
14
+ async getDashboardsAsCode(projectUuid, options) {
15
+ var _a;
16
+ const params = {};
17
+ if ((_a = options === null || options === void 0 ? void 0 : options.ids) === null || _a === void 0 ? void 0 : _a.length)
18
+ params.ids = options.ids;
19
+ if ((options === null || options === void 0 ? void 0 : options.offset) != null)
20
+ params.offset = options.offset;
21
+ if ((options === null || options === void 0 ? void 0 : options.languageMap) != null)
22
+ params.languageMap = options.languageMap;
23
+ return this.http.get(`/projects/${projectUuid}/code/dashboards`, Object.keys(params).length ? { params } : undefined);
24
+ }
25
+ /** Upsert a dashboard from code representation (create or update by slug). */
26
+ async upsertDashboardAsCode(projectUuid, slug, body) {
27
+ return this.http.post(`/projects/${projectUuid}/code/dashboards/${encodeURIComponent(slug)}`, body);
23
28
  }
24
29
  }
25
30
  exports.DashboardsClient = DashboardsClient;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const vitest_1 = require("vitest");
13
4
  const dashboards_1 = require("./dashboards");
@@ -22,12 +13,63 @@ const dashboards_1 = require("./dashboards");
22
13
  delete: vitest_1.vi.fn(),
23
14
  };
24
15
  });
25
- (0, vitest_1.it)('listDashboards should call GET /projects/{projectUuid}/dashboards', () => __awaiter(void 0, void 0, void 0, function* () {
16
+ (0, vitest_1.it)('listDashboards should call GET /projects/{projectUuid}/dashboards', async () => {
26
17
  const client = new dashboards_1.DashboardsClient(mockHttp);
27
18
  const dashboards = [{ uuid: 'd1', name: 'Dashboard 1', projectUuid: 'p1' }];
28
19
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(dashboards);
29
- const result = yield client.listDashboards('p1');
20
+ const result = await client.listDashboards('p1');
30
21
  (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/dashboards');
31
22
  (0, vitest_1.expect)(result).toEqual(dashboards);
32
- }));
23
+ });
24
+ (0, vitest_1.it)('getDashboardsAsCode should call GET /projects/{projectUuid}/code/dashboards with no params when no options', async () => {
25
+ const client = new dashboards_1.DashboardsClient(mockHttp);
26
+ const results = { offset: 0, total: 1, missingIds: [], dashboards: [] };
27
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
28
+ const result = await client.getDashboardsAsCode('p1');
29
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/dashboards', undefined);
30
+ (0, vitest_1.expect)(result).toEqual(results);
31
+ });
32
+ (0, vitest_1.it)('getDashboardsAsCode should call GET with query params when options provided', async () => {
33
+ const client = new dashboards_1.DashboardsClient(mockHttp);
34
+ const results = { offset: 0, total: 0, missingIds: [], dashboards: [] };
35
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
36
+ await client.getDashboardsAsCode('p1', {
37
+ ids: ['slug-a', 'slug-b'],
38
+ offset: 10,
39
+ languageMap: true,
40
+ });
41
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/code/dashboards', {
42
+ params: { ids: ['slug-a', 'slug-b'], offset: 10, languageMap: true },
43
+ });
44
+ });
45
+ (0, vitest_1.it)('upsertDashboardAsCode should call POST /projects/{projectUuid}/code/dashboards/{slug} with body', async () => {
46
+ const client = new dashboards_1.DashboardsClient(mockHttp);
47
+ const body = {
48
+ name: 'My Dashboard',
49
+ slug: 'my-dashboard',
50
+ updatedAt: '2024-01-01T00:00:00Z',
51
+ version: 1,
52
+ spaceSlug: 'my-space',
53
+ tiles: [],
54
+ };
55
+ const apiResult = { promoted: [], errors: [] };
56
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(apiResult);
57
+ const result = await client.upsertDashboardAsCode('p1', 'my-dashboard', body);
58
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/dashboards/my-dashboard', body);
59
+ (0, vitest_1.expect)(result).toEqual(apiResult);
60
+ });
61
+ (0, vitest_1.it)('upsertDashboardAsCode should encode slug in path', async () => {
62
+ const client = new dashboards_1.DashboardsClient(mockHttp);
63
+ const body = {
64
+ name: 'Dashboard',
65
+ slug: 'dash/slug',
66
+ updatedAt: '2024-01-01T00:00:00Z',
67
+ version: 1,
68
+ spaceSlug: 'space',
69
+ tiles: [],
70
+ };
71
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({});
72
+ await client.upsertDashboardAsCode('p1', 'dash/slug', body);
73
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/dashboards/dash%2Fslug', body);
74
+ });
33
75
  });
@@ -1,15 +1,17 @@
1
1
  /**
2
2
  * Explores API client (v1).
3
3
  */
4
- import type { ApiExploresResults, ApiExploreResults } from '@lightdash-tools/common';
5
4
  import { BaseApiClient } from '../base-client';
5
+ import type { ApiExploresResults, ApiExploreResults, LightdashApi } from '@lightdash-tools/common';
6
+ type CompiledDimension = LightdashApi.Explores.CompiledTable['dimensions'][string];
6
7
  export declare class ExploresClient extends BaseApiClient {
7
8
  /** List all explores for a project. */
8
9
  listExplores(projectUuid: string): Promise<ApiExploresResults>;
9
10
  /** Get a specific explore by ID. */
10
11
  getExplore(projectUuid: string, exploreId: string): Promise<ApiExploreResults>;
11
12
  /** List dimensions for a specific explore. */
12
- listDimensions(projectUuid: string, exploreId: string): Promise<unknown[]>;
13
+ listDimensions(projectUuid: string, exploreId: string): Promise<CompiledDimension[]>;
13
14
  /** Get lineage for a specific field in an explore. */
14
15
  getFieldLineage(projectUuid: string, exploreId: string, fieldId: string): Promise<unknown>;
15
16
  }
17
+ export {};
@@ -2,49 +2,40 @@
2
2
  /**
3
3
  * Explores API client (v1).
4
4
  */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.ExploresClient = void 0;
16
7
  const base_client_1 = require("../base-client");
17
8
  class ExploresClient extends base_client_1.BaseApiClient {
18
9
  /** List all explores for a project. */
19
- listExplores(projectUuid) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- return this.http.get(`/projects/${projectUuid}/explores`);
22
- });
10
+ async listExplores(projectUuid) {
11
+ return this.http.get(`/projects/${projectUuid}/explores`);
23
12
  }
24
13
  /** Get a specific explore by ID. */
25
- getExplore(projectUuid, exploreId) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- return this.http.get(`/projects/${projectUuid}/explores/${exploreId}`);
28
- });
14
+ async getExplore(projectUuid, exploreId) {
15
+ return this.http.get(`/projects/${projectUuid}/explores/${exploreId}`);
29
16
  }
30
17
  /** List dimensions for a specific explore. */
31
- listDimensions(projectUuid, exploreId) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const explore = yield this.getExplore(projectUuid, exploreId);
34
- return Object.values(explore.tables).flatMap((table) => Object.values(table.dimensions));
35
- });
18
+ async listDimensions(projectUuid, exploreId) {
19
+ const explore = await this.getExplore(projectUuid, exploreId);
20
+ return Object.values(explore.tables).flatMap((table) => Object.values(table.dimensions));
36
21
  }
37
22
  /** Get lineage for a specific field in an explore. */
38
- getFieldLineage(projectUuid, exploreId, fieldId) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const explore = yield this.getExplore(projectUuid, exploreId);
41
- for (const table of Object.values(explore.tables)) {
42
- if (table.dimensions[fieldId] || table.metrics[fieldId]) {
23
+ async getFieldLineage(projectUuid, exploreId, fieldId) {
24
+ const explore = await this.getExplore(projectUuid, exploreId);
25
+ for (const table of Object.values(explore.tables)) {
26
+ // Table maps are keyed by short field name; also accept `{table}_{name}` fieldIds.
27
+ if (table.dimensions[fieldId] || table.metrics[fieldId]) {
28
+ return table.lineageGraph;
29
+ }
30
+ const prefix = `${table.name}_`;
31
+ if (fieldId.startsWith(prefix)) {
32
+ const shortName = fieldId.slice(prefix.length);
33
+ if (table.dimensions[shortName] || table.metrics[shortName]) {
43
34
  return table.lineageGraph;
44
35
  }
45
36
  }
46
- return null;
47
- });
37
+ }
38
+ return null;
48
39
  }
49
40
  }
50
41
  exports.ExploresClient = ExploresClient;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const vitest_1 = require("vitest");
13
4
  const explores_1 = require("./explores");
@@ -22,15 +13,15 @@ const explores_1 = require("./explores");
22
13
  delete: vitest_1.vi.fn(),
23
14
  };
24
15
  });
25
- (0, vitest_1.it)('listExplores should call GET /projects/{projectUuid}/explores', () => __awaiter(void 0, void 0, void 0, function* () {
16
+ (0, vitest_1.it)('listExplores should call GET /projects/{projectUuid}/explores', async () => {
26
17
  const client = new explores_1.ExploresClient(mockHttp);
27
18
  const explores = [{ name: 'e1', label: 'Explore 1', databaseName: 'db1' }];
28
19
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(explores);
29
- const result = yield client.listExplores('p1');
20
+ const result = await client.listExplores('p1');
30
21
  (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/explores');
31
22
  (0, vitest_1.expect)(result).toEqual(explores);
32
- }));
33
- (0, vitest_1.it)('getExplore should call GET /projects/{projectUuid}/explores/{exploreId}', () => __awaiter(void 0, void 0, void 0, function* () {
23
+ });
24
+ (0, vitest_1.it)('getExplore should call GET /projects/{projectUuid}/explores/{exploreId}', async () => {
34
25
  const client = new explores_1.ExploresClient(mockHttp);
35
26
  const explore = {
36
27
  name: 'e1',
@@ -39,11 +30,11 @@ const explores_1 = require("./explores");
39
30
  joinedTables: [],
40
31
  };
41
32
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(explore);
42
- const result = yield client.getExplore('p1', 'e1');
33
+ const result = await client.getExplore('p1', 'e1');
43
34
  (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/explores/e1');
44
35
  (0, vitest_1.expect)(result).toEqual(explore);
45
- }));
46
- (0, vitest_1.it)('listDimensions should extract dimensions from explore', () => __awaiter(void 0, void 0, void 0, function* () {
36
+ });
37
+ (0, vitest_1.it)('listDimensions should extract dimensions from explore', async () => {
47
38
  const client = new explores_1.ExploresClient(mockHttp);
48
39
  const explore = {
49
40
  tables: {
@@ -55,14 +46,15 @@ const explores_1 = require("./explores");
55
46
  },
56
47
  };
57
48
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(explore);
58
- const result = yield client.listDimensions('p1', 'e1');
49
+ const result = await client.listDimensions('p1', 'e1');
59
50
  (0, vitest_1.expect)(result).toEqual([{ name: 'd1' }]);
60
- }));
61
- (0, vitest_1.it)('getFieldLineage should extract lineage from explore', () => __awaiter(void 0, void 0, void 0, function* () {
51
+ });
52
+ (0, vitest_1.it)('getFieldLineage should extract lineage from explore', async () => {
62
53
  const client = new explores_1.ExploresClient(mockHttp);
63
54
  const explore = {
64
55
  tables: {
65
56
  t1: {
57
+ name: 't1',
66
58
  dimensions: {
67
59
  d1: { name: 'd1' },
68
60
  },
@@ -72,7 +64,25 @@ const explores_1 = require("./explores");
72
64
  },
73
65
  };
74
66
  vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(explore);
75
- const result = yield client.getFieldLineage('p1', 'e1', 'd1');
67
+ const result = await client.getFieldLineage('p1', 'e1', 'd1');
76
68
  (0, vitest_1.expect)(result).toEqual({ upstream: [] });
77
- }));
69
+ });
70
+ (0, vitest_1.it)('getFieldLineage should resolve {table}_{name} fieldIds', async () => {
71
+ const client = new explores_1.ExploresClient(mockHttp);
72
+ const explore = {
73
+ tables: {
74
+ t1: {
75
+ name: 't1',
76
+ dimensions: {
77
+ d1: { name: 'd1' },
78
+ },
79
+ metrics: {},
80
+ lineageGraph: { upstream: ['x'] },
81
+ },
82
+ },
83
+ };
84
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(explore);
85
+ const result = await client.getFieldLineage('p1', 'e1', 't1_d1');
86
+ (0, vitest_1.expect)(result).toEqual({ upstream: ['x'] });
87
+ });
78
88
  });
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Groups API client.
3
3
  */
4
- import type { LightdashApi } from '@lightdash-tools/common';
5
4
  import { BaseApiClient } from '../base-client';
5
+ import type { LightdashApi } from '@lightdash-tools/common';
6
6
  /** Query params for listing organization groups. */
7
7
  export interface ListGroupsParams {
8
8
  page?: number;