@lightdash-tools/client 0.1.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 (154) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +144 -0
  3. package/dist/api/base-client.d.ts +13 -0
  4. package/dist/api/base-client.js +17 -0
  5. package/dist/api/v1/ai-agents.d.ts +17 -0
  6. package/dist/api/v1/ai-agents.js +47 -0
  7. package/dist/api/v1/ai-agents.test.d.ts +1 -0
  8. package/dist/api/v1/ai-agents.test.js +77 -0
  9. package/dist/api/v1/charts.d.ts +18 -0
  10. package/dist/api/v1/charts.js +45 -0
  11. package/dist/api/v1/charts.test.d.ts +1 -0
  12. package/dist/api/v1/charts.test.js +106 -0
  13. package/dist/api/v1/dashboards.d.ts +9 -0
  14. package/dist/api/v1/dashboards.js +25 -0
  15. package/dist/api/v1/dashboards.test.d.ts +1 -0
  16. package/dist/api/v1/dashboards.test.js +33 -0
  17. package/dist/api/v1/explores.d.ts +11 -0
  18. package/dist/api/v1/explores.js +31 -0
  19. package/dist/api/v1/explores.test.d.ts +1 -0
  20. package/dist/api/v1/explores.test.js +46 -0
  21. package/dist/api/v1/groups.d.ts +42 -0
  22. package/dist/api/v1/groups.js +81 -0
  23. package/dist/api/v1/groups.test.d.ts +1 -0
  24. package/dist/api/v1/groups.test.js +107 -0
  25. package/dist/api/v1/organizations.d.ts +9 -0
  26. package/dist/api/v1/organizations.js +25 -0
  27. package/dist/api/v1/organizations.test.d.ts +1 -0
  28. package/dist/api/v1/organizations.test.js +33 -0
  29. package/dist/api/v1/project-access.d.ts +40 -0
  30. package/dist/api/v1/project-access.js +88 -0
  31. package/dist/api/v1/project-access.test.d.ts +1 -0
  32. package/dist/api/v1/project-access.test.js +109 -0
  33. package/dist/api/v1/projects.d.ts +13 -0
  34. package/dist/api/v1/projects.js +37 -0
  35. package/dist/api/v1/projects.test.d.ts +1 -0
  36. package/dist/api/v1/projects.test.js +49 -0
  37. package/dist/api/v1/query.d.ts +11 -0
  38. package/dist/api/v1/query.js +31 -0
  39. package/dist/api/v1/query.test.d.ts +1 -0
  40. package/dist/api/v1/query.test.js +51 -0
  41. package/dist/api/v1/spaces.d.ts +25 -0
  42. package/dist/api/v1/spaces.js +73 -0
  43. package/dist/api/v1/spaces.test.d.ts +1 -0
  44. package/dist/api/v1/spaces.test.js +91 -0
  45. package/dist/api/v1/users.d.ts +35 -0
  46. package/dist/api/v1/users.js +66 -0
  47. package/dist/api/v1/users.test.d.ts +1 -0
  48. package/dist/api/v1/users.test.js +122 -0
  49. package/dist/api/v2/organization-roles.d.ts +45 -0
  50. package/dist/api/v2/organization-roles.js +81 -0
  51. package/dist/api/v2/organization-roles.test.d.ts +1 -0
  52. package/dist/api/v2/organization-roles.test.js +112 -0
  53. package/dist/api/v2/project-role-assignments.d.ts +23 -0
  54. package/dist/api/v2/project-role-assignments.js +55 -0
  55. package/dist/api/v2/project-role-assignments.test.d.ts +1 -0
  56. package/dist/api/v2/project-role-assignments.test.js +66 -0
  57. package/dist/api/v2/query.d.ts +17 -0
  58. package/dist/api/v2/query.js +49 -0
  59. package/dist/api/v2/query.test.d.ts +1 -0
  60. package/dist/api/v2/query.test.js +78 -0
  61. package/dist/client.d.ts +118 -0
  62. package/dist/client.js +113 -0
  63. package/dist/client.test.d.ts +1 -0
  64. package/dist/client.test.js +94 -0
  65. package/dist/config.d.ts +83 -0
  66. package/dist/config.js +22 -0
  67. package/dist/errors.d.ts +39 -0
  68. package/dist/errors.js +46 -0
  69. package/dist/errors.test.d.ts +1 -0
  70. package/dist/errors.test.js +29 -0
  71. package/dist/http/axios-client.d.ts +22 -0
  72. package/dist/http/axios-client.js +51 -0
  73. package/dist/http/http-client.d.ts +33 -0
  74. package/dist/http/http-client.js +69 -0
  75. package/dist/http/interceptors.d.ts +13 -0
  76. package/dist/http/interceptors.js +82 -0
  77. package/dist/http/rate-limiter.d.ts +23 -0
  78. package/dist/http/rate-limiter.js +60 -0
  79. package/dist/http/rate-limiter.test.d.ts +1 -0
  80. package/dist/http/rate-limiter.test.js +40 -0
  81. package/dist/index.d.ts +22 -0
  82. package/dist/index.js +41 -0
  83. package/dist/index.test.d.ts +1 -0
  84. package/dist/index.test.js +65 -0
  85. package/dist/pagination/fetch-all-pages.d.ts +15 -0
  86. package/dist/pagination/fetch-all-pages.js +41 -0
  87. package/dist/pagination/fetch-all-pages.test.d.ts +1 -0
  88. package/dist/pagination/fetch-all-pages.test.js +70 -0
  89. package/dist/pagination/types.d.ts +14 -0
  90. package/dist/pagination/types.js +6 -0
  91. package/dist/types/api.d.ts +22 -0
  92. package/dist/types/api.js +8 -0
  93. package/dist/utils/env.d.ts +20 -0
  94. package/dist/utils/env.js +59 -0
  95. package/dist/utils/env.test.d.ts +1 -0
  96. package/dist/utils/env.test.js +73 -0
  97. package/dist/utils/logger.d.ts +8 -0
  98. package/dist/utils/logger.js +20 -0
  99. package/dist/utils/retry.d.ts +14 -0
  100. package/dist/utils/retry.js +67 -0
  101. package/dist/utils/retry.test.d.ts +1 -0
  102. package/dist/utils/retry.test.js +53 -0
  103. package/package.json +21 -0
  104. package/src/api/base-client.ts +14 -0
  105. package/src/api/v1/ai-agents.test.ts +74 -0
  106. package/src/api/v1/ai-agents.ts +41 -0
  107. package/src/api/v1/charts.test.ts +103 -0
  108. package/src/api/v1/charts.ts +51 -0
  109. package/src/api/v1/dashboards.test.ts +26 -0
  110. package/src/api/v1/dashboards.ts +15 -0
  111. package/src/api/v1/explores.test.ts +40 -0
  112. package/src/api/v1/explores.ts +18 -0
  113. package/src/api/v1/groups.test.ts +108 -0
  114. package/src/api/v1/groups.ts +100 -0
  115. package/src/api/v1/organizations.test.ts +26 -0
  116. package/src/api/v1/organizations.ts +13 -0
  117. package/src/api/v1/project-access.test.ts +110 -0
  118. package/src/api/v1/project-access.ts +102 -0
  119. package/src/api/v1/projects.test.ts +44 -0
  120. package/src/api/v1/projects.ts +23 -0
  121. package/src/api/v1/query.test.ts +46 -0
  122. package/src/api/v1/query.ts +37 -0
  123. package/src/api/v1/spaces.test.ts +92 -0
  124. package/src/api/v1/spaces.ts +83 -0
  125. package/src/api/v1/users.test.ts +125 -0
  126. package/src/api/v1/users.ts +76 -0
  127. package/src/api/v2/organization-roles.test.ts +115 -0
  128. package/src/api/v2/organization-roles.ts +90 -0
  129. package/src/api/v2/project-role-assignments.test.ts +75 -0
  130. package/src/api/v2/project-role-assignments.ts +63 -0
  131. package/src/api/v2/query.test.ts +81 -0
  132. package/src/api/v2/query.ts +69 -0
  133. package/src/client.test.ts +105 -0
  134. package/src/client.ts +182 -0
  135. package/src/config.ts +113 -0
  136. package/src/errors.test.ts +45 -0
  137. package/src/errors.ts +67 -0
  138. package/src/http/axios-client.ts +59 -0
  139. package/src/http/http-client.ts +79 -0
  140. package/src/http/interceptors.ts +110 -0
  141. package/src/http/rate-limiter.test.ts +34 -0
  142. package/src/http/rate-limiter.ts +54 -0
  143. package/src/index.test.ts +91 -0
  144. package/src/index.ts +41 -0
  145. package/src/pagination/fetch-all-pages.test.ts +75 -0
  146. package/src/pagination/fetch-all-pages.ts +39 -0
  147. package/src/pagination/types.ts +16 -0
  148. package/src/types/api.ts +28 -0
  149. package/src/utils/env.test.ts +88 -0
  150. package/src/utils/env.ts +69 -0
  151. package/src/utils/logger.ts +21 -0
  152. package/src/utils/retry.test.ts +49 -0
  153. package/src/utils/retry.ts +60 -0
  154. package/tsconfig.json +13 -0
@@ -0,0 +1,106 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const vitest_1 = require("vitest");
13
+ const charts_1 = require("./charts");
14
+ (0, vitest_1.describe)('ChartsClient', () => {
15
+ let mockHttp;
16
+ (0, vitest_1.beforeEach)(() => {
17
+ mockHttp = {
18
+ get: vitest_1.vi.fn(),
19
+ post: vitest_1.vi.fn(),
20
+ put: vitest_1.vi.fn(),
21
+ patch: vitest_1.vi.fn(),
22
+ delete: vitest_1.vi.fn(),
23
+ };
24
+ });
25
+ (0, vitest_1.it)('listCharts should call GET /projects/{projectUuid}/charts', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new charts_1.ChartsClient(mockHttp);
27
+ const charts = [{ uuid: 'c1', name: 'Chart 1', projectUuid: 'p1' }];
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(charts);
29
+ const result = yield client.listCharts('p1');
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts');
31
+ (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* () {
34
+ const client = new charts_1.ChartsClient(mockHttp);
35
+ const results = { offset: 0, total: 1, missingIds: [], charts: [] };
36
+ 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);
39
+ (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* () {
42
+ const client = new charts_1.ChartsClient(mockHttp);
43
+ const results = { offset: 0, total: 0, missingIds: [], charts: [] };
44
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
45
+ yield client.getChartsAsCode('p1', {
46
+ ids: ['slug-a', 'slug-b'],
47
+ offset: 10,
48
+ languageMap: true,
49
+ });
50
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts/code', {
51
+ params: { ids: ['slug-a', 'slug-b'], offset: 10, languageMap: true },
52
+ });
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* () {
55
+ const client = new charts_1.ChartsClient(mockHttp);
56
+ const body = {
57
+ name: 'My Chart',
58
+ slug: 'my-chart',
59
+ tableName: 'orders',
60
+ metricQuery: {
61
+ dimensions: [],
62
+ metrics: [],
63
+ filters: {},
64
+ exploreName: 'orders',
65
+ sorts: [],
66
+ limit: 500,
67
+ tableCalculations: [],
68
+ },
69
+ tableConfig: { columnOrder: [] },
70
+ updatedAt: '2024-01-01T00:00:00Z',
71
+ version: 1,
72
+ spaceSlug: 'my-space',
73
+ chartConfig: { type: 'cartesian', config: {} },
74
+ };
75
+ const apiResult = { promoted: [], errors: [] };
76
+ 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);
79
+ (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* () {
82
+ const client = new charts_1.ChartsClient(mockHttp);
83
+ const body = {
84
+ name: 'Chart',
85
+ slug: 'chart/slug',
86
+ tableName: 't',
87
+ metricQuery: {
88
+ dimensions: [],
89
+ metrics: [],
90
+ filters: {},
91
+ exploreName: 't',
92
+ sorts: [],
93
+ limit: 500,
94
+ tableCalculations: [],
95
+ },
96
+ tableConfig: { columnOrder: [] },
97
+ updatedAt: '2024-01-01T00:00:00Z',
98
+ version: 1,
99
+ spaceSlug: 'space',
100
+ chartConfig: {},
101
+ };
102
+ 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
+ }));
106
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Dashboards API client.
3
+ */
4
+ import type { DashboardBasicDetailsWithTileTypes } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class DashboardsClient extends BaseApiClient {
7
+ /** List dashboards in a project. */
8
+ listDashboards(projectUuid: string): Promise<DashboardBasicDetailsWithTileTypes[]>;
9
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Dashboards API client.
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DashboardsClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class DashboardsClient extends base_client_1.BaseApiClient {
18
+ /** 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
+ });
23
+ }
24
+ }
25
+ exports.DashboardsClient = DashboardsClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const vitest_1 = require("vitest");
13
+ const dashboards_1 = require("./dashboards");
14
+ (0, vitest_1.describe)('DashboardsClient', () => {
15
+ let mockHttp;
16
+ (0, vitest_1.beforeEach)(() => {
17
+ mockHttp = {
18
+ get: vitest_1.vi.fn(),
19
+ post: vitest_1.vi.fn(),
20
+ put: vitest_1.vi.fn(),
21
+ patch: vitest_1.vi.fn(),
22
+ delete: vitest_1.vi.fn(),
23
+ };
24
+ });
25
+ (0, vitest_1.it)('listDashboards should call GET /projects/{projectUuid}/dashboards', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new dashboards_1.DashboardsClient(mockHttp);
27
+ const dashboards = [{ uuid: 'd1', name: 'Dashboard 1', projectUuid: 'p1' }];
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(dashboards);
29
+ const result = yield client.listDashboards('p1');
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/dashboards');
31
+ (0, vitest_1.expect)(result).toEqual(dashboards);
32
+ }));
33
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Explores API client (v1).
3
+ */
4
+ import type { ApiExploresResults, ApiExploreResults } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class ExploresClient extends BaseApiClient {
7
+ /** List all explores for a project. */
8
+ listExplores(projectUuid: string): Promise<ApiExploresResults>;
9
+ /** Get a specific explore by ID. */
10
+ getExplore(projectUuid: string, exploreId: string): Promise<ApiExploreResults>;
11
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Explores API client (v1).
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ExploresClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class ExploresClient extends base_client_1.BaseApiClient {
18
+ /** 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
+ });
23
+ }
24
+ /** 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
+ });
29
+ }
30
+ }
31
+ exports.ExploresClient = ExploresClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const vitest_1 = require("vitest");
13
+ const explores_1 = require("./explores");
14
+ (0, vitest_1.describe)('ExploresClient', () => {
15
+ let mockHttp;
16
+ (0, vitest_1.beforeEach)(() => {
17
+ mockHttp = {
18
+ get: vitest_1.vi.fn(),
19
+ post: vitest_1.vi.fn(),
20
+ put: vitest_1.vi.fn(),
21
+ patch: vitest_1.vi.fn(),
22
+ delete: vitest_1.vi.fn(),
23
+ };
24
+ });
25
+ (0, vitest_1.it)('listExplores should call GET /projects/{projectUuid}/explores', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new explores_1.ExploresClient(mockHttp);
27
+ const explores = [{ name: 'e1', label: 'Explore 1', databaseName: 'db1' }];
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(explores);
29
+ const result = yield client.listExplores('p1');
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/explores');
31
+ (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* () {
34
+ const client = new explores_1.ExploresClient(mockHttp);
35
+ const explore = {
36
+ name: 'e1',
37
+ label: 'Explore 1',
38
+ baseTable: 't1',
39
+ joinedTables: [],
40
+ };
41
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(explore);
42
+ const result = yield client.getExplore('p1', 'e1');
43
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/explores/e1');
44
+ (0, vitest_1.expect)(result).toEqual(explore);
45
+ }));
46
+ });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Groups API client.
3
+ */
4
+ import type { LightdashApi } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ /** Query params for listing organization groups. */
7
+ export interface ListGroupsParams {
8
+ page?: number;
9
+ pageSize?: number;
10
+ includeMembers?: number;
11
+ searchQuery?: string;
12
+ }
13
+ /** Params for listAllGroups (page and pageSize are controlled by the helper). */
14
+ export type ListAllGroupsParams = Omit<ListGroupsParams, 'page' | 'pageSize'>;
15
+ /** Query params for getGroup. */
16
+ export interface GetGroupParams {
17
+ includeMembers?: number;
18
+ offset?: number;
19
+ }
20
+ export type GroupOrGroupWithMembers = LightdashApi.Groups.Group | LightdashApi.Groups.GroupWithMembers;
21
+ export declare class GroupsClient extends BaseApiClient {
22
+ /** List one page of groups (use listAllGroups for all pages). */
23
+ listGroups(params?: ListGroupsParams): Promise<LightdashApi.Groups.GroupListResult>;
24
+ /** List all groups in the current organization (fetches all pages). */
25
+ listAllGroups(params?: ListAllGroupsParams, options?: {
26
+ pageSize?: number;
27
+ }): Promise<GroupOrGroupWithMembers[]>;
28
+ /** Create a new group in the current organization. */
29
+ createGroup(body: LightdashApi.Groups.CreateGroup): Promise<LightdashApi.Groups.GroupWithMembers>;
30
+ /** Get a group by UUID. */
31
+ getGroup(groupUuid: string, params?: GetGroupParams): Promise<LightdashApi.Groups.Group | LightdashApi.Groups.GroupWithMembers>;
32
+ /** Update a group (name and/or members). */
33
+ updateGroup(groupUuid: string, body: LightdashApi.Groups.UpdateGroupWithMembers): Promise<LightdashApi.Groups.Group | LightdashApi.Groups.GroupWithMembers>;
34
+ /** Delete a group. */
35
+ deleteGroup(groupUuid: string): Promise<void>;
36
+ /** Get members of a group. */
37
+ getGroupMembers(groupUuid: string): Promise<LightdashApi.Groups.GroupMember[]>;
38
+ /** Add a user to a group. */
39
+ addUserToGroup(groupUuid: string, userUuid: string): Promise<void>;
40
+ /** Remove a user from a group. */
41
+ removeUserFromGroup(groupUuid: string, userUuid: string): Promise<void>;
42
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Groups API client.
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.GroupsClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ const fetch_all_pages_1 = require("../../pagination/fetch-all-pages");
18
+ class GroupsClient extends base_client_1.BaseApiClient {
19
+ /** List one page of groups (use listAllGroups for all pages). */
20
+ listGroups(params) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return this.http.get('/org/groups', {
23
+ params,
24
+ });
25
+ });
26
+ }
27
+ /** List all groups in the current organization (fetches all pages). */
28
+ listAllGroups(params, options) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return (0, fetch_all_pages_1.fetchAllPages)({
31
+ fetchPage: (page, pageSize) => this.http.get('/org/groups', {
32
+ params: Object.assign(Object.assign({}, params), { page, pageSize }),
33
+ }),
34
+ pageSize: options === null || options === void 0 ? void 0 : options.pageSize,
35
+ });
36
+ });
37
+ }
38
+ /** Create a new group in the current organization. */
39
+ createGroup(body) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return this.http.post('/org/groups', body);
42
+ });
43
+ }
44
+ /** Get a group by UUID. */
45
+ getGroup(groupUuid, params) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ return this.http.get(`/groups/${groupUuid}`, { params });
48
+ });
49
+ }
50
+ /** Update a group (name and/or members). */
51
+ updateGroup(groupUuid, body) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ return this.http.patch(`/groups/${groupUuid}`, body);
54
+ });
55
+ }
56
+ /** Delete a group. */
57
+ deleteGroup(groupUuid) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ yield this.http.delete(`/groups/${groupUuid}`);
60
+ });
61
+ }
62
+ /** Get members of a group. */
63
+ getGroupMembers(groupUuid) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ return this.http.get(`/groups/${groupUuid}/members`);
66
+ });
67
+ }
68
+ /** Add a user to a group. */
69
+ addUserToGroup(groupUuid, userUuid) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ yield this.http.put(`/groups/${groupUuid}/members/${userUuid}`);
72
+ });
73
+ }
74
+ /** Remove a user from a group. */
75
+ removeUserFromGroup(groupUuid, userUuid) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ yield this.http.delete(`/groups/${groupUuid}/members/${userUuid}`);
78
+ });
79
+ }
80
+ }
81
+ exports.GroupsClient = GroupsClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,107 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const vitest_1 = require("vitest");
13
+ const groups_1 = require("./groups");
14
+ (0, vitest_1.describe)('GroupsClient', () => {
15
+ let mockHttp;
16
+ (0, vitest_1.beforeEach)(() => {
17
+ mockHttp = {
18
+ get: vitest_1.vi.fn(),
19
+ post: vitest_1.vi.fn(),
20
+ put: vitest_1.vi.fn(),
21
+ patch: vitest_1.vi.fn(),
22
+ delete: vitest_1.vi.fn(),
23
+ };
24
+ });
25
+ (0, vitest_1.it)('listGroups should call GET /org/groups with optional params', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new groups_1.GroupsClient(mockHttp);
27
+ const results = { data: [], pagination: { totalResults: 0, totalPageCount: 0 } };
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
29
+ const result = yield client.listGroups({ pageSize: 10 });
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/org/groups', {
31
+ params: { pageSize: 10 },
32
+ });
33
+ (0, vitest_1.expect)(result).toEqual(results);
34
+ }));
35
+ (0, vitest_1.it)('createGroup should call POST /org/groups with body', () => __awaiter(void 0, void 0, void 0, function* () {
36
+ const client = new groups_1.GroupsClient(mockHttp);
37
+ const group = {
38
+ name: 'Admins',
39
+ groupUuid: 'g1',
40
+ organizationUuid: 'o1',
41
+ memberUuids: [],
42
+ members: [],
43
+ };
44
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(group);
45
+ const result = yield client.createGroup({ name: 'Admins' });
46
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/org/groups', { name: 'Admins' });
47
+ (0, vitest_1.expect)(result).toEqual(group);
48
+ }));
49
+ (0, vitest_1.it)('getGroupMembers should call GET /groups/{groupUuid}/members', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ const client = new groups_1.GroupsClient(mockHttp);
51
+ const members = [{ userUuid: 'u1', email: 'u@example.com', firstName: 'U', lastName: 'Ser' }];
52
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(members);
53
+ const result = yield client.getGroupMembers('g1');
54
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/groups/g1/members');
55
+ (0, vitest_1.expect)(result).toEqual(members);
56
+ }));
57
+ (0, vitest_1.it)('listAllGroups should fetch all pages and return concatenated array', () => __awaiter(void 0, void 0, void 0, function* () {
58
+ const client = new groups_1.GroupsClient(mockHttp);
59
+ const page1 = {
60
+ data: [
61
+ {
62
+ name: 'G1',
63
+ groupUuid: 'g1',
64
+ organizationUuid: 'o1',
65
+ memberUuids: [],
66
+ members: [],
67
+ },
68
+ ],
69
+ pagination: { page: 1, pageSize: 1, totalResults: 2, totalPageCount: 2 },
70
+ };
71
+ const page2 = {
72
+ data: [
73
+ {
74
+ name: 'G2',
75
+ groupUuid: 'g2',
76
+ organizationUuid: 'o1',
77
+ memberUuids: [],
78
+ members: [],
79
+ },
80
+ ],
81
+ pagination: { page: 2, pageSize: 1, totalResults: 2, totalPageCount: 2 },
82
+ };
83
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValueOnce(page1).mockResolvedValueOnce(page2);
84
+ const result = yield client.listAllGroups(undefined, { pageSize: 1 });
85
+ (0, vitest_1.expect)(result).toHaveLength(2);
86
+ (0, vitest_1.expect)(result[0]).toMatchObject({ groupUuid: 'g1', name: 'G1' });
87
+ (0, vitest_1.expect)(result[1]).toMatchObject({ groupUuid: 'g2', name: 'G2' });
88
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledTimes(2);
89
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenNthCalledWith(1, '/org/groups', {
90
+ params: { page: 1, pageSize: 1 },
91
+ });
92
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenNthCalledWith(2, '/org/groups', {
93
+ params: { page: 2, pageSize: 1 },
94
+ });
95
+ }));
96
+ (0, vitest_1.it)('listAllGroups should pass through list params (e.g. searchQuery, includeMembers)', () => __awaiter(void 0, void 0, void 0, function* () {
97
+ const client = new groups_1.GroupsClient(mockHttp);
98
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValueOnce({
99
+ data: [],
100
+ pagination: { page: 1, pageSize: 100, totalResults: 0, totalPageCount: 1 },
101
+ });
102
+ yield client.listAllGroups({ searchQuery: 'admins', includeMembers: 1 });
103
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/org/groups', {
104
+ params: { searchQuery: 'admins', includeMembers: 1, page: 1, pageSize: 100 },
105
+ });
106
+ }));
107
+ });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Organizations API client.
3
+ */
4
+ import type { Organization } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class OrganizationsClient extends BaseApiClient {
7
+ /** Get the current user's organization. */
8
+ getCurrentOrganization(): Promise<Organization>;
9
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Organizations API client.
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
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OrganizationsClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class OrganizationsClient extends base_client_1.BaseApiClient {
18
+ /** Get the current user's organization. */
19
+ getCurrentOrganization() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.http.get('/org');
22
+ });
23
+ }
24
+ }
25
+ exports.OrganizationsClient = OrganizationsClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const vitest_1 = require("vitest");
13
+ const organizations_1 = require("./organizations");
14
+ (0, vitest_1.describe)('OrganizationsClient', () => {
15
+ let mockHttp;
16
+ (0, vitest_1.beforeEach)(() => {
17
+ mockHttp = {
18
+ get: vitest_1.vi.fn(),
19
+ post: vitest_1.vi.fn(),
20
+ put: vitest_1.vi.fn(),
21
+ patch: vitest_1.vi.fn(),
22
+ delete: vitest_1.vi.fn(),
23
+ };
24
+ });
25
+ (0, vitest_1.it)('getCurrentOrganization should call GET /org', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new organizations_1.OrganizationsClient(mockHttp);
27
+ const org = { organizationUuid: 'o1', name: 'My Org' };
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(org);
29
+ const result = yield client.getCurrentOrganization();
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/org');
31
+ (0, vitest_1.expect)(result).toEqual(org);
32
+ }));
33
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Project access API client (project-level user and group access).
3
+ */
4
+ import type { LightdashApi } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class ProjectAccessClient extends BaseApiClient {
7
+ /** List users with explicit project access. */
8
+ listProjectAccess(projectUuid: string): Promise<LightdashApi.ProjectAccess.ProjectMemberProfile[]>;
9
+ /** Grant a user access to a project. */
10
+ grantProjectAccessToUser(projectUuid: string, body: LightdashApi.ProjectAccess.CreateProjectMember): Promise<void>;
11
+ /** Get a project member's access. */
12
+ getProjectMemberAccess(projectUuid: string, userUuid: string): Promise<LightdashApi.ProjectAccess.ProjectMemberProfile>;
13
+ /**
14
+ * Update a user's project access (role).
15
+ * @deprecated This API is deprecated in Lightdash.
16
+ */
17
+ updateProjectAccessForUser(projectUuid: string, userUuid: string, body: LightdashApi.ProjectAccess.UpdateProjectMember): Promise<void>;
18
+ /**
19
+ * Revoke a user's project access.
20
+ * @deprecated This API is deprecated in Lightdash.
21
+ */
22
+ revokeProjectAccessForUser(projectUuid: string, userUuid: string): Promise<void>;
23
+ /** List group access for a project. */
24
+ listProjectGroupAccesses(projectUuid: string): Promise<LightdashApi.ProjectAccess.ProjectGroupAccess[]>;
25
+ /**
26
+ * Add project access to a group.
27
+ * @deprecated This API is deprecated in Lightdash.
28
+ */
29
+ addProjectAccessToGroup(groupUuid: string, projectUuid: string, body: LightdashApi.ProjectAccess.CreateProjectGroupAccessBody): Promise<LightdashApi.ProjectAccess.ProjectGroupAccess>;
30
+ /**
31
+ * Remove project access from a group.
32
+ * @deprecated This API is deprecated in Lightdash.
33
+ */
34
+ removeProjectAccessFromGroup(groupUuid: string, projectUuid: string): Promise<void>;
35
+ /**
36
+ * Update a group's project access (role).
37
+ * @deprecated This API is deprecated in Lightdash.
38
+ */
39
+ updateProjectAccessForGroup(groupUuid: string, projectUuid: string, body: LightdashApi.ProjectAccess.UpdateProjectGroupAccess): Promise<LightdashApi.ProjectAccess.ProjectGroupAccess>;
40
+ }