@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,88 @@
1
+ "use strict";
2
+ /**
3
+ * Project access API client (project-level user and group access).
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.ProjectAccessClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class ProjectAccessClient extends base_client_1.BaseApiClient {
18
+ /** List users with explicit project access. */
19
+ listProjectAccess(projectUuid) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.http.get(`/projects/${projectUuid}/access`);
22
+ });
23
+ }
24
+ /** Grant a user access to a project. */
25
+ grantProjectAccessToUser(projectUuid, body) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ yield this.http.post(`/projects/${projectUuid}/access`, body);
28
+ });
29
+ }
30
+ /** Get a project member's access. */
31
+ getProjectMemberAccess(projectUuid, userUuid) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return this.http.get(`/projects/${projectUuid}/user/${userUuid}`);
34
+ });
35
+ }
36
+ /**
37
+ * Update a user's project access (role).
38
+ * @deprecated This API is deprecated in Lightdash.
39
+ */
40
+ updateProjectAccessForUser(projectUuid, userUuid, body) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ yield this.http.patch(`/projects/${projectUuid}/access/${userUuid}`, body);
43
+ });
44
+ }
45
+ /**
46
+ * Revoke a user's project access.
47
+ * @deprecated This API is deprecated in Lightdash.
48
+ */
49
+ revokeProjectAccessForUser(projectUuid, userUuid) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ yield this.http.delete(`/projects/${projectUuid}/access/${userUuid}`);
52
+ });
53
+ }
54
+ /** List group access for a project. */
55
+ listProjectGroupAccesses(projectUuid) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ return this.http.get(`/projects/${projectUuid}/groupAccesses`);
58
+ });
59
+ }
60
+ /**
61
+ * Add project access to a group.
62
+ * @deprecated This API is deprecated in Lightdash.
63
+ */
64
+ addProjectAccessToGroup(groupUuid, projectUuid, body) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ return this.http.post(`/groups/${groupUuid}/projects/${projectUuid}`, body);
67
+ });
68
+ }
69
+ /**
70
+ * Remove project access from a group.
71
+ * @deprecated This API is deprecated in Lightdash.
72
+ */
73
+ removeProjectAccessFromGroup(groupUuid, projectUuid) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ yield this.http.delete(`/groups/${groupUuid}/projects/${projectUuid}`);
76
+ });
77
+ }
78
+ /**
79
+ * Update a group's project access (role).
80
+ * @deprecated This API is deprecated in Lightdash.
81
+ */
82
+ updateProjectAccessForGroup(groupUuid, projectUuid, body) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ return this.http.patch(`/groups/${groupUuid}/projects/${projectUuid}`, body);
85
+ });
86
+ }
87
+ }
88
+ exports.ProjectAccessClient = ProjectAccessClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,109 @@
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 project_access_1 = require("./project-access");
14
+ (0, vitest_1.describe)('ProjectAccessClient', () => {
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)('listProjectAccess should call GET /projects/{projectUuid}/access', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
27
+ const list = [
28
+ {
29
+ userUuid: 'u1',
30
+ email: 'u@example.com',
31
+ firstName: 'U',
32
+ lastName: 'Ser',
33
+ role: 'editor',
34
+ projectUuid: 'p1',
35
+ },
36
+ ];
37
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(list);
38
+ const result = yield client.listProjectAccess('p1');
39
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/access');
40
+ (0, vitest_1.expect)(result).toEqual(list);
41
+ }));
42
+ (0, vitest_1.it)('grantProjectAccessToUser should call POST /projects/{projectUuid}/access with body', () => __awaiter(void 0, void 0, void 0, function* () {
43
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
44
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(undefined);
45
+ const body = { email: 'u@example.com', role: 'viewer', sendEmail: true };
46
+ yield client.grantProjectAccessToUser('p1', body);
47
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/access', body);
48
+ }));
49
+ (0, vitest_1.it)('getProjectMemberAccess should call GET /projects/{projectUuid}/user/{userUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
51
+ const member = {
52
+ userUuid: 'u1',
53
+ email: 'u@example.com',
54
+ firstName: 'U',
55
+ lastName: 'Ser',
56
+ role: 'editor',
57
+ projectUuid: 'p1',
58
+ };
59
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(member);
60
+ const result = yield client.getProjectMemberAccess('p1', 'u1');
61
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/user/u1');
62
+ (0, vitest_1.expect)(result).toEqual(member);
63
+ }));
64
+ (0, vitest_1.it)('updateProjectAccessForUser should call PATCH /projects/{projectUuid}/access/{userUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
65
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
66
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue(undefined);
67
+ const body = { role: 'editor' };
68
+ yield client.updateProjectAccessForUser('p1', 'u1', body);
69
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/projects/p1/access/u1', body);
70
+ }));
71
+ (0, vitest_1.it)('revokeProjectAccessForUser should call DELETE /projects/{projectUuid}/access/{userUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
72
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
73
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
74
+ yield client.revokeProjectAccessForUser('p1', 'u1');
75
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/access/u1');
76
+ }));
77
+ (0, vitest_1.it)('listProjectGroupAccesses should call GET /projects/{projectUuid}/groupAccesses', () => __awaiter(void 0, void 0, void 0, function* () {
78
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
79
+ const list = [{ groupUuid: 'g1', projectUuid: 'p1', role: 'viewer' }];
80
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(list);
81
+ const result = yield client.listProjectGroupAccesses('p1');
82
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/groupAccesses');
83
+ (0, vitest_1.expect)(result).toEqual(list);
84
+ }));
85
+ (0, vitest_1.it)('addProjectAccessToGroup should call POST /groups/{groupUuid}/projects/{projectUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
86
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
87
+ const created = { groupUuid: 'g1', projectUuid: 'p1', role: 'viewer' };
88
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(created);
89
+ const body = { role: 'viewer' };
90
+ const result = yield client.addProjectAccessToGroup('g1', 'p1', body);
91
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/groups/g1/projects/p1', body);
92
+ (0, vitest_1.expect)(result).toEqual(created);
93
+ }));
94
+ (0, vitest_1.it)('removeProjectAccessFromGroup should call DELETE /groups/{groupUuid}/projects/{projectUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
95
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
96
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
97
+ yield client.removeProjectAccessFromGroup('g1', 'p1');
98
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/groups/g1/projects/p1');
99
+ }));
100
+ (0, vitest_1.it)('updateProjectAccessForGroup should call PATCH /groups/{groupUuid}/projects/{projectUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
101
+ const client = new project_access_1.ProjectAccessClient(mockHttp);
102
+ const updated = { groupUuid: 'g1', projectUuid: 'p1', role: 'editor' };
103
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue(updated);
104
+ const body = { role: 'editor' };
105
+ const result = yield client.updateProjectAccessForGroup('g1', 'p1', body);
106
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/groups/g1/projects/p1', body);
107
+ (0, vitest_1.expect)(result).toEqual(updated);
108
+ }));
109
+ });
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Projects API client. Endpoints for project and project-scoped resources.
3
+ */
4
+ import type { Project, OrganizationProject, SpaceQuery } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class ProjectsClient extends BaseApiClient {
7
+ /** Get a project by UUID. */
8
+ getProject(projectUuid: string): Promise<Project>;
9
+ /** List all projects in the current organization. */
10
+ listProjects(): Promise<OrganizationProject[]>;
11
+ /** List charts in a project. */
12
+ listChartsInProject(projectUuid: string): Promise<SpaceQuery[]>;
13
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ /**
3
+ * Projects API client. Endpoints for project and project-scoped resources.
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.ProjectsClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class ProjectsClient extends base_client_1.BaseApiClient {
18
+ /** Get a project by UUID. */
19
+ getProject(projectUuid) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.http.get(`/projects/${projectUuid}`);
22
+ });
23
+ }
24
+ /** List all projects in the current organization. */
25
+ listProjects() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return this.http.get('/org/projects');
28
+ });
29
+ }
30
+ /** List charts in a project. */
31
+ listChartsInProject(projectUuid) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return this.http.get(`/projects/${projectUuid}/charts`);
34
+ });
35
+ }
36
+ }
37
+ exports.ProjectsClient = ProjectsClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
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 projects_1 = require("./projects");
14
+ (0, vitest_1.describe)('ProjectsClient', () => {
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)('getProject should call GET /projects/{projectUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new projects_1.ProjectsClient(mockHttp);
27
+ const project = { projectUuid: 'p1', name: 'Test' };
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(project);
29
+ const result = yield client.getProject('p1');
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1');
31
+ (0, vitest_1.expect)(result).toEqual(project);
32
+ }));
33
+ (0, vitest_1.it)('listProjects should call GET /org/projects', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const client = new projects_1.ProjectsClient(mockHttp);
35
+ const list = [{ projectUuid: 'p1', name: 'P1' }];
36
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(list);
37
+ const result = yield client.listProjects();
38
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/org/projects');
39
+ (0, vitest_1.expect)(result).toEqual(list);
40
+ }));
41
+ (0, vitest_1.it)('listChartsInProject should call GET /projects/{projectUuid}/charts', () => __awaiter(void 0, void 0, void 0, function* () {
42
+ const client = new projects_1.ProjectsClient(mockHttp);
43
+ const charts = [];
44
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(charts);
45
+ const result = yield client.listChartsInProject('p1');
46
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/charts');
47
+ (0, vitest_1.expect)(result).toEqual(charts);
48
+ }));
49
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Query API client. Run metric/SQL/underlying data queries.
3
+ */
4
+ import type { MetricQueryRequest, RunQueryResults, CompileQueryRequest, CompiledQueryResults } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class QueryClient extends BaseApiClient {
7
+ /** Run a metric query for an explore. */
8
+ runQuery(projectUuid: string, exploreId: string, body: MetricQueryRequest): Promise<RunQueryResults>;
9
+ /** Compile a metric query for an explore. */
10
+ compileQuery(projectUuid: string, exploreId: string, body: CompileQueryRequest): Promise<CompiledQueryResults>;
11
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Query API client. Run metric/SQL/underlying data queries.
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.QueryClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class QueryClient extends base_client_1.BaseApiClient {
18
+ /** Run a metric query for an explore. */
19
+ runQuery(projectUuid, exploreId, body) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.http.post(`/projects/${projectUuid}/explores/${exploreId}/runQuery`, body);
22
+ });
23
+ }
24
+ /** Compile a metric query for an explore. */
25
+ compileQuery(projectUuid, exploreId, body) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return this.http.post(`/projects/${projectUuid}/explores/${exploreId}/compileQuery`, body);
28
+ });
29
+ }
30
+ }
31
+ exports.QueryClient = QueryClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
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 query_1 = require("./query");
14
+ (0, vitest_1.describe)('QueryClient', () => {
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)('runQuery should call POST /projects/{projectUuid}/explores/{exploreId}/runQuery with body', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new query_1.QueryClient(mockHttp);
27
+ const body = { dimensions: [], metrics: [], filters: {} };
28
+ const results = { rows: [], metricQuery: {} };
29
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(results);
30
+ const result = yield client.runQuery('p1', 'explore1', body);
31
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/explores/explore1/runQuery', body);
32
+ (0, vitest_1.expect)(result).toEqual(results);
33
+ }));
34
+ (0, vitest_1.it)('compileQuery should call POST /projects/{projectUuid}/explores/{exploreId}/compileQuery with body', () => __awaiter(void 0, void 0, void 0, function* () {
35
+ const client = new query_1.QueryClient(mockHttp);
36
+ const body = {
37
+ dimensions: [],
38
+ metrics: [],
39
+ filters: {},
40
+ exploreName: 'test',
41
+ limit: 100,
42
+ sorts: [],
43
+ tableCalculations: [],
44
+ };
45
+ const results = { query: 'SELECT ...', parameterReferences: [] };
46
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(results);
47
+ const result = yield client.compileQuery('p1', 'explore1', body);
48
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/explores/explore1/compileQuery', body);
49
+ (0, vitest_1.expect)(result).toEqual(results);
50
+ }));
51
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Spaces API client.
3
+ */
4
+ import type { LightdashApi, SpaceSummary, CreateSpace, UpdateSpace, AddSpaceUserAccess, AddSpaceGroupAccess } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class SpacesClient extends BaseApiClient {
7
+ /** List spaces in a project. */
8
+ listSpacesInProject(projectUuid: string): Promise<SpaceSummary[]>;
9
+ /** Get a space by project and space UUID. */
10
+ getSpace(projectUuid: string, spaceUuid: string): Promise<LightdashApi.Spaces.Space>;
11
+ /** Create a space in a project. */
12
+ createSpace(projectUuid: string, body: CreateSpace): Promise<LightdashApi.Spaces.Space>;
13
+ /** Update a space. */
14
+ updateSpace(projectUuid: string, spaceUuid: string, body: UpdateSpace): Promise<LightdashApi.Spaces.Space>;
15
+ /** Delete a space. */
16
+ deleteSpace(projectUuid: string, spaceUuid: string): Promise<void>;
17
+ /** Grant a user access to a space. */
18
+ grantUserAccessToSpace(projectUuid: string, spaceUuid: string, body: AddSpaceUserAccess): Promise<void>;
19
+ /** Revoke a user's access to a space. */
20
+ revokeUserAccessToSpace(projectUuid: string, spaceUuid: string, userUuid: string): Promise<void>;
21
+ /** Grant a group access to a space. */
22
+ grantGroupAccessToSpace(projectUuid: string, spaceUuid: string, body: AddSpaceGroupAccess): Promise<void>;
23
+ /** Revoke a group's access to a space. */
24
+ revokeGroupAccessToSpace(projectUuid: string, spaceUuid: string, groupUuid: string): Promise<void>;
25
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * Spaces 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.SpacesClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class SpacesClient extends base_client_1.BaseApiClient {
18
+ /** List spaces in a project. */
19
+ listSpacesInProject(projectUuid) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.http.get(`/projects/${projectUuid}/spaces`);
22
+ });
23
+ }
24
+ /** Get a space by project and space UUID. */
25
+ getSpace(projectUuid, spaceUuid) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return this.http.get(`/projects/${projectUuid}/spaces/${spaceUuid}`);
28
+ });
29
+ }
30
+ /** Create a space in a project. */
31
+ createSpace(projectUuid, body) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return this.http.post(`/projects/${projectUuid}/spaces`, body);
34
+ });
35
+ }
36
+ /** Update a space. */
37
+ updateSpace(projectUuid, spaceUuid, body) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return this.http.patch(`/projects/${projectUuid}/spaces/${spaceUuid}`, body);
40
+ });
41
+ }
42
+ /** Delete a space. */
43
+ deleteSpace(projectUuid, spaceUuid) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ yield this.http.delete(`/projects/${projectUuid}/spaces/${spaceUuid}`);
46
+ });
47
+ }
48
+ /** Grant a user access to a space. */
49
+ grantUserAccessToSpace(projectUuid, spaceUuid, body) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ yield this.http.post(`/projects/${projectUuid}/spaces/${spaceUuid}/share`, body);
52
+ });
53
+ }
54
+ /** Revoke a user's access to a space. */
55
+ revokeUserAccessToSpace(projectUuid, spaceUuid, userUuid) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ yield this.http.delete(`/projects/${projectUuid}/spaces/${spaceUuid}/share/${userUuid}`);
58
+ });
59
+ }
60
+ /** Grant a group access to a space. */
61
+ grantGroupAccessToSpace(projectUuid, spaceUuid, body) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ yield this.http.post(`/projects/${projectUuid}/spaces/${spaceUuid}/group/share`, body);
64
+ });
65
+ }
66
+ /** Revoke a group's access to a space. */
67
+ revokeGroupAccessToSpace(projectUuid, spaceUuid, groupUuid) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ yield this.http.delete(`/projects/${projectUuid}/spaces/${spaceUuid}/group/share/${groupUuid}`);
70
+ });
71
+ }
72
+ }
73
+ exports.SpacesClient = SpacesClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,91 @@
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 spaces_1 = require("./spaces");
14
+ (0, vitest_1.describe)('SpacesClient', () => {
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)('listSpacesInProject should call GET /projects/{projectUuid}/spaces', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new spaces_1.SpacesClient(mockHttp);
27
+ const spaces = [{ uuid: 's1', name: 'Space 1', projectUuid: 'p1' }];
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(spaces);
29
+ const result = yield client.listSpacesInProject('p1');
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/spaces');
31
+ (0, vitest_1.expect)(result).toEqual(spaces);
32
+ }));
33
+ (0, vitest_1.it)('getSpace should call GET /projects/{projectUuid}/spaces/{spaceUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const client = new spaces_1.SpacesClient(mockHttp);
35
+ const space = { uuid: 's1', name: 'Space 1', projectUuid: 'p1', organizationUuid: 'o1' };
36
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(space);
37
+ const result = yield client.getSpace('p1', 's1');
38
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/spaces/s1');
39
+ (0, vitest_1.expect)(result).toEqual(space);
40
+ }));
41
+ (0, vitest_1.it)('createSpace should call POST /projects/{projectUuid}/spaces with body', () => __awaiter(void 0, void 0, void 0, function* () {
42
+ const client = new spaces_1.SpacesClient(mockHttp);
43
+ const created = { uuid: 's1', name: 'New Space', projectUuid: 'p1' };
44
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(created);
45
+ const body = { name: 'New Space' };
46
+ const result = yield client.createSpace('p1', body);
47
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/spaces', body);
48
+ (0, vitest_1.expect)(result).toEqual(created);
49
+ }));
50
+ (0, vitest_1.it)('updateSpace should call PATCH /projects/{projectUuid}/spaces/{spaceUuid} with body', () => __awaiter(void 0, void 0, void 0, function* () {
51
+ const client = new spaces_1.SpacesClient(mockHttp);
52
+ const updated = { uuid: 's1', name: 'Updated', projectUuid: 'p1' };
53
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue(updated);
54
+ const body = { name: 'Updated' };
55
+ const result = yield client.updateSpace('p1', 's1', body);
56
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/projects/p1/spaces/s1', body);
57
+ (0, vitest_1.expect)(result).toEqual(updated);
58
+ }));
59
+ (0, vitest_1.it)('deleteSpace should call DELETE /projects/{projectUuid}/spaces/{spaceUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
60
+ const client = new spaces_1.SpacesClient(mockHttp);
61
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
62
+ yield client.deleteSpace('p1', 's1');
63
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/spaces/s1');
64
+ }));
65
+ (0, vitest_1.it)('grantUserAccessToSpace should call POST .../share with body', () => __awaiter(void 0, void 0, void 0, function* () {
66
+ const client = new spaces_1.SpacesClient(mockHttp);
67
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(undefined);
68
+ const body = { userUuid: 'u1', spaceRole: 'editor' };
69
+ yield client.grantUserAccessToSpace('p1', 's1', body);
70
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/spaces/s1/share', body);
71
+ }));
72
+ (0, vitest_1.it)('revokeUserAccessToSpace should call DELETE .../share/{userUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
73
+ const client = new spaces_1.SpacesClient(mockHttp);
74
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
75
+ yield client.revokeUserAccessToSpace('p1', 's1', 'u1');
76
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/spaces/s1/share/u1');
77
+ }));
78
+ (0, vitest_1.it)('grantGroupAccessToSpace should call POST .../group/share with body', () => __awaiter(void 0, void 0, void 0, function* () {
79
+ const client = new spaces_1.SpacesClient(mockHttp);
80
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(undefined);
81
+ const body = { groupUuid: 'g1', spaceRole: 'viewer' };
82
+ yield client.grantGroupAccessToSpace('p1', 's1', body);
83
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/spaces/s1/group/share', body);
84
+ }));
85
+ (0, vitest_1.it)('revokeGroupAccessToSpace should call DELETE .../group/share/{groupUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
86
+ const client = new spaces_1.SpacesClient(mockHttp);
87
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
88
+ yield client.revokeGroupAccessToSpace('p1', 's1', 'g1');
89
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/p1/spaces/s1/group/share/g1');
90
+ }));
91
+ });
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Users (organization members) API client.
3
+ */
4
+ import type { LightdashApi } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ /** Query params for listing organization members. */
7
+ export interface ListMembersParams {
8
+ includeGroups?: number;
9
+ pageSize?: number;
10
+ page?: number;
11
+ searchQuery?: string;
12
+ projectUuid?: string;
13
+ googleOidcOnly?: boolean;
14
+ }
15
+ /** Params for listAllMembers (page and pageSize are controlled by the helper). */
16
+ export type ListAllMembersParams = Omit<ListMembersParams, 'page' | 'pageSize'>;
17
+ export declare class UsersClient extends BaseApiClient {
18
+ /** List one page of members (use listAllMembers for all pages). */
19
+ listMembers(params?: ListMembersParams): Promise<LightdashApi.Users.OrganizationMemberProfilesResult>;
20
+ /** List all members of the current organization (fetches all pages). */
21
+ listAllMembers(params?: ListAllMembersParams, options?: {
22
+ pageSize?: number;
23
+ }): Promise<LightdashApi.Users.OrganizationMemberProfile[]>;
24
+ /** Get organization member by UUID. */
25
+ getMemberByUuid(userUuid: string): Promise<LightdashApi.Users.OrganizationMemberProfile>;
26
+ /** Get organization member by email. */
27
+ getMemberByEmail(email: string): Promise<LightdashApi.Users.OrganizationMemberProfile>;
28
+ /**
29
+ * Update organization member (e.g. role).
30
+ * @deprecated This API is deprecated in Lightdash.
31
+ */
32
+ updateMember(userUuid: string, body: LightdashApi.Users.OrganizationMemberProfileUpdate): Promise<LightdashApi.Users.OrganizationMemberProfile>;
33
+ /** Delete (remove) a user from the current organization. */
34
+ deleteMember(userUuid: string): Promise<void>;
35
+ }