@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,66 @@
1
+ "use strict";
2
+ /**
3
+ * Users (organization members) 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.UsersClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ const fetch_all_pages_1 = require("../../pagination/fetch-all-pages");
18
+ class UsersClient extends base_client_1.BaseApiClient {
19
+ /** List one page of members (use listAllMembers for all pages). */
20
+ listMembers(params) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return this.http.get('/org/users', {
23
+ params,
24
+ });
25
+ });
26
+ }
27
+ /** List all members of the current organization (fetches all pages). */
28
+ listAllMembers(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/users', {
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
+ /** Get organization member by UUID. */
39
+ getMemberByUuid(userUuid) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return this.http.get(`/org/users/${userUuid}`);
42
+ });
43
+ }
44
+ /** Get organization member by email. */
45
+ getMemberByEmail(email) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ return this.http.get(`/org/users/email/${encodeURIComponent(email)}`);
48
+ });
49
+ }
50
+ /**
51
+ * Update organization member (e.g. role).
52
+ * @deprecated This API is deprecated in Lightdash.
53
+ */
54
+ updateMember(userUuid, body) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ return this.http.patch(`/org/users/${userUuid}`, body);
57
+ });
58
+ }
59
+ /** Delete (remove) a user from the current organization. */
60
+ deleteMember(userUuid) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ yield this.http.delete(`/org/user/${userUuid}`);
63
+ });
64
+ }
65
+ }
66
+ exports.UsersClient = UsersClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,122 @@
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 users_1 = require("./users");
14
+ (0, vitest_1.describe)('UsersClient', () => {
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)('listMembers should call GET /org/users with optional params', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new users_1.UsersClient(mockHttp);
27
+ const results = { data: [], pagination: { totalResults: 0, totalPageCount: 0 } };
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
29
+ const result = yield client.listMembers({ pageSize: 10, page: 1 });
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/org/users', {
31
+ params: { pageSize: 10, page: 1 },
32
+ });
33
+ (0, vitest_1.expect)(result).toEqual(results);
34
+ }));
35
+ (0, vitest_1.it)('getMemberByUuid should call GET /org/users/{userUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
36
+ const client = new users_1.UsersClient(mockHttp);
37
+ const member = {
38
+ userUuid: 'u1',
39
+ email: 'u@example.com',
40
+ firstName: 'U',
41
+ lastName: 'Ser',
42
+ role: 'editor',
43
+ };
44
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(member);
45
+ const result = yield client.getMemberByUuid('u1');
46
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/org/users/u1');
47
+ (0, vitest_1.expect)(result).toEqual(member);
48
+ }));
49
+ (0, vitest_1.it)('getMemberByEmail should call GET /org/users/email/{encodedEmail}', () => __awaiter(void 0, void 0, void 0, function* () {
50
+ const client = new users_1.UsersClient(mockHttp);
51
+ const member = {
52
+ userUuid: 'u1',
53
+ email: 'user+test@example.com',
54
+ firstName: 'U',
55
+ lastName: 'Ser',
56
+ role: 'editor',
57
+ };
58
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(member);
59
+ const result = yield client.getMemberByEmail('user+test@example.com');
60
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/org/users/email/user%2Btest%40example.com');
61
+ (0, vitest_1.expect)(result).toEqual(member);
62
+ }));
63
+ (0, vitest_1.it)('updateMember should call PATCH /org/users/{userUuid} with body', () => __awaiter(void 0, void 0, void 0, function* () {
64
+ const client = new users_1.UsersClient(mockHttp);
65
+ const body = { role: 'admin' };
66
+ const updated = {
67
+ userUuid: 'u1',
68
+ email: 'u@example.com',
69
+ firstName: 'U',
70
+ lastName: 'Ser',
71
+ role: 'admin',
72
+ };
73
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue(updated);
74
+ const result = yield client.updateMember('u1', body);
75
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/org/users/u1', body);
76
+ (0, vitest_1.expect)(result).toEqual(updated);
77
+ }));
78
+ (0, vitest_1.it)('deleteMember should call DELETE /org/user/{userUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
79
+ const client = new users_1.UsersClient(mockHttp);
80
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
81
+ yield client.deleteMember('u1');
82
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/org/user/u1');
83
+ }));
84
+ (0, vitest_1.it)('listAllMembers should fetch all pages and return concatenated array', () => __awaiter(void 0, void 0, void 0, function* () {
85
+ const client = new users_1.UsersClient(mockHttp);
86
+ const page1 = {
87
+ data: [
88
+ { userUuid: 'u1', email: 'a@example.com', firstName: 'A', lastName: 'One', role: 'editor' },
89
+ ],
90
+ pagination: { page: 1, pageSize: 1, totalResults: 2, totalPageCount: 2 },
91
+ };
92
+ const page2 = {
93
+ data: [
94
+ { userUuid: 'u2', email: 'b@example.com', firstName: 'B', lastName: 'Two', role: 'viewer' },
95
+ ],
96
+ pagination: { page: 2, pageSize: 1, totalResults: 2, totalPageCount: 2 },
97
+ };
98
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValueOnce(page1).mockResolvedValueOnce(page2);
99
+ const result = yield client.listAllMembers(undefined, { pageSize: 1 });
100
+ (0, vitest_1.expect)(result).toHaveLength(2);
101
+ (0, vitest_1.expect)(result[0]).toMatchObject({ userUuid: 'u1', email: 'a@example.com' });
102
+ (0, vitest_1.expect)(result[1]).toMatchObject({ userUuid: 'u2', email: 'b@example.com' });
103
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledTimes(2);
104
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenNthCalledWith(1, '/org/users', {
105
+ params: { page: 1, pageSize: 1 },
106
+ });
107
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenNthCalledWith(2, '/org/users', {
108
+ params: { page: 2, pageSize: 1 },
109
+ });
110
+ }));
111
+ (0, vitest_1.it)('listAllMembers should pass through list params (e.g. searchQuery)', () => __awaiter(void 0, void 0, void 0, function* () {
112
+ const client = new users_1.UsersClient(mockHttp);
113
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValueOnce({
114
+ data: [],
115
+ pagination: { page: 1, pageSize: 100, totalResults: 0, totalPageCount: 1 },
116
+ });
117
+ yield client.listAllMembers({ searchQuery: 'foo' });
118
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/org/users', {
119
+ params: { searchQuery: 'foo', page: 1, pageSize: 100 },
120
+ });
121
+ }));
122
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Organization roles API client (v2). Manage org-level roles and role assignments.
3
+ */
4
+ import type { components } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ type CreateRole = components['schemas']['CreateRole'];
7
+ type UpdateRole = components['schemas']['UpdateRole'];
8
+ type AddScopesToRole = components['schemas']['AddScopesToRole'];
9
+ type Role = components['schemas']['Role'];
10
+ type RoleWithScopes = components['schemas']['RoleWithScopes'];
11
+ type RoleAssignment = components['schemas']['RoleAssignment'];
12
+ /** Response shape for getRoles (array of Role or RoleWithScopes). */
13
+ export type GetRolesResult = Role[] | RoleWithScopes[];
14
+ /** Query params for getRoles. */
15
+ export interface GetRolesParams {
16
+ load?: string;
17
+ roleTypeFilter?: string;
18
+ }
19
+ /** Request body for assigning an org role to a user. */
20
+ export interface AssignOrgRoleToUserBody {
21
+ roleId: string;
22
+ }
23
+ export declare class OrganizationRolesClient extends BaseApiClient {
24
+ /** Get roles for an organization. */
25
+ getRoles(orgUuid: string, params?: GetRolesParams): Promise<GetRolesResult>;
26
+ /** Create a custom role in the organization. */
27
+ createRole(orgUuid: string, body: CreateRole): Promise<Role>;
28
+ /** Get a custom role by UUID. */
29
+ getRole(orgUuid: string, roleUuid: string): Promise<RoleWithScopes>;
30
+ /** Update a custom role. */
31
+ updateRole(orgUuid: string, roleUuid: string, body: UpdateRole): Promise<Role>;
32
+ /** Delete a custom role from the organization. */
33
+ deleteRole(orgUuid: string, roleUuid: string): Promise<void>;
34
+ /** Add scopes to a role. */
35
+ addScopesToRole(orgUuid: string, roleUuid: string, body: AddScopesToRole): Promise<void>;
36
+ /** Remove a scope from a role. */
37
+ removeScopeFromRole(orgUuid: string, roleUuid: string, scopeName: string): Promise<void>;
38
+ /** Duplicate a role. */
39
+ duplicateRole(orgUuid: string, roleId: string, body: CreateRole): Promise<RoleWithScopes>;
40
+ /** List organization role assignments (system roles only). */
41
+ listRoleAssignments(orgUuid: string): Promise<RoleAssignment[]>;
42
+ /** Assign an organization role to a user. */
43
+ assignRoleToUser(orgUuid: string, userId: string, body: AssignOrgRoleToUserBody): Promise<RoleAssignment>;
44
+ }
45
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Organization roles API client (v2). Manage org-level roles and role assignments.
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.OrganizationRolesClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class OrganizationRolesClient extends base_client_1.BaseApiClient {
18
+ /** Get roles for an organization. */
19
+ getRoles(orgUuid, params) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.http.get(`/orgs/${orgUuid}/roles`, {
22
+ params,
23
+ });
24
+ });
25
+ }
26
+ /** Create a custom role in the organization. */
27
+ createRole(orgUuid, body) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ return this.http.post(`/orgs/${orgUuid}/roles`, body);
30
+ });
31
+ }
32
+ /** Get a custom role by UUID. */
33
+ getRole(orgUuid, roleUuid) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return this.http.get(`/orgs/${orgUuid}/roles/${roleUuid}`);
36
+ });
37
+ }
38
+ /** Update a custom role. */
39
+ updateRole(orgUuid, roleUuid, body) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return this.http.patch(`/orgs/${orgUuid}/roles/${roleUuid}`, body);
42
+ });
43
+ }
44
+ /** Delete a custom role from the organization. */
45
+ deleteRole(orgUuid, roleUuid) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ yield this.http.delete(`/orgs/${orgUuid}/roles/${roleUuid}`);
48
+ });
49
+ }
50
+ /** Add scopes to a role. */
51
+ addScopesToRole(orgUuid, roleUuid, body) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ yield this.http.post(`/orgs/${orgUuid}/roles/${roleUuid}/scopes`, body);
54
+ });
55
+ }
56
+ /** Remove a scope from a role. */
57
+ removeScopeFromRole(orgUuid, roleUuid, scopeName) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ yield this.http.delete(`/orgs/${orgUuid}/roles/${roleUuid}/scopes/${encodeURIComponent(scopeName)}`);
60
+ });
61
+ }
62
+ /** Duplicate a role. */
63
+ duplicateRole(orgUuid, roleId, body) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ return this.http.post(`/orgs/${orgUuid}/roles/${roleId}/duplicate`, body);
66
+ });
67
+ }
68
+ /** List organization role assignments (system roles only). */
69
+ listRoleAssignments(orgUuid) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ return this.http.get(`/orgs/${orgUuid}/roles/assignments`);
72
+ });
73
+ }
74
+ /** Assign an organization role to a user. */
75
+ assignRoleToUser(orgUuid, userId, body) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ return this.http.post(`/orgs/${orgUuid}/roles/assignments/user/${userId}`, body);
78
+ });
79
+ }
80
+ }
81
+ exports.OrganizationRolesClient = OrganizationRolesClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,112 @@
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 organization_roles_1 = require("./organization-roles");
14
+ (0, vitest_1.describe)('OrganizationRolesClient', () => {
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)('getRoles should call GET /orgs/{orgUuid}/roles with optional params', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
27
+ const results = [{ roleUuid: 'r1', name: 'Role 1' }];
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
29
+ const result = yield client.getRoles('org-1');
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/orgs/org-1/roles', {
31
+ params: undefined,
32
+ });
33
+ (0, vitest_1.expect)(result).toEqual(results);
34
+ }));
35
+ (0, vitest_1.it)('getRoles with params should pass query params', () => __awaiter(void 0, void 0, void 0, function* () {
36
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
37
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue([]);
38
+ yield client.getRoles('org-1', { load: 'scopes', roleTypeFilter: 'custom' });
39
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/orgs/org-1/roles', {
40
+ params: { load: 'scopes', roleTypeFilter: 'custom' },
41
+ });
42
+ }));
43
+ (0, vitest_1.it)('createRole should call POST /orgs/{orgUuid}/roles with body', () => __awaiter(void 0, void 0, void 0, function* () {
44
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
45
+ const body = { name: 'Editor', description: 'Can edit' };
46
+ const role = { roleUuid: 'r1', name: 'Editor' };
47
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(role);
48
+ const result = yield client.createRole('org-1', body);
49
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/orgs/org-1/roles', body);
50
+ (0, vitest_1.expect)(result).toEqual(role);
51
+ }));
52
+ (0, vitest_1.it)('getRole should call GET /orgs/{orgUuid}/roles/{roleUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
53
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
54
+ const role = { roleUuid: 'r1', name: 'Editor', scopes: [] };
55
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(role);
56
+ const result = yield client.getRole('org-1', 'r1');
57
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/orgs/org-1/roles/r1');
58
+ (0, vitest_1.expect)(result).toEqual(role);
59
+ }));
60
+ (0, vitest_1.it)('updateRole should call PATCH /orgs/{orgUuid}/roles/{roleUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
61
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
62
+ const body = { name: 'Updated' };
63
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue({ roleUuid: 'r1', name: 'Updated' });
64
+ yield client.updateRole('org-1', 'r1', body);
65
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/orgs/org-1/roles/r1', body);
66
+ }));
67
+ (0, vitest_1.it)('deleteRole should call DELETE /orgs/{orgUuid}/roles/{roleUuid}', () => __awaiter(void 0, void 0, void 0, function* () {
68
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
69
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
70
+ yield client.deleteRole('org-1', 'r1');
71
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/orgs/org-1/roles/r1');
72
+ }));
73
+ (0, vitest_1.it)('addScopesToRole should call POST .../scopes with body', () => __awaiter(void 0, void 0, void 0, function* () {
74
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
75
+ const body = { scopeNames: ['project:read'] };
76
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(undefined);
77
+ yield client.addScopesToRole('org-1', 'r1', body);
78
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/orgs/org-1/roles/r1/scopes', body);
79
+ }));
80
+ (0, vitest_1.it)('removeScopeFromRole should call DELETE .../scopes/{scopeName}', () => __awaiter(void 0, void 0, void 0, function* () {
81
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
82
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
83
+ yield client.removeScopeFromRole('org-1', 'r1', 'project:read');
84
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/orgs/org-1/roles/r1/scopes/project%3Aread');
85
+ }));
86
+ (0, vitest_1.it)('duplicateRole should call POST .../duplicate with body', () => __awaiter(void 0, void 0, void 0, function* () {
87
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
88
+ const body = { name: 'Copy of Role' };
89
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({
90
+ roleUuid: 'r2',
91
+ name: 'Copy of Role',
92
+ scopes: [],
93
+ });
94
+ yield client.duplicateRole('org-1', 'r1', body);
95
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/orgs/org-1/roles/r1/duplicate', body);
96
+ }));
97
+ (0, vitest_1.it)('listRoleAssignments should call GET /orgs/{orgUuid}/roles/assignments', () => __awaiter(void 0, void 0, void 0, function* () {
98
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
99
+ const assignments = [{ roleId: 'r1', roleName: 'Admin' }];
100
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(assignments);
101
+ const result = yield client.listRoleAssignments('org-1');
102
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/orgs/org-1/roles/assignments');
103
+ (0, vitest_1.expect)(result).toEqual(assignments);
104
+ }));
105
+ (0, vitest_1.it)('assignRoleToUser should call POST .../assignments/user/{userId}', () => __awaiter(void 0, void 0, void 0, function* () {
106
+ const client = new organization_roles_1.OrganizationRolesClient(mockHttp);
107
+ const body = { roleId: 'r1' };
108
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({ roleId: 'r1' });
109
+ yield client.assignRoleToUser('org-1', 'user-1', body);
110
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/orgs/org-1/roles/assignments/user/user-1', body);
111
+ }));
112
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Project role assignments API client (v2). Manage project-level role assignments for users and groups.
3
+ */
4
+ import type { components } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ type RoleAssignment = components['schemas']['RoleAssignment'];
7
+ type UpsertUserRoleAssignmentRequest = components['schemas']['UpsertUserRoleAssignmentRequest'];
8
+ type UpdateRoleAssignmentRequest = components['schemas']['UpdateRoleAssignmentRequest'];
9
+ export declare class ProjectRoleAssignmentsClient extends BaseApiClient {
10
+ /** List project role assignments. */
11
+ listAssignments(projectId: string): Promise<RoleAssignment[]>;
12
+ /** Create or update project role assignment for a user (upsert). */
13
+ upsertUserAssignment(projectId: string, userId: string, body: UpsertUserRoleAssignmentRequest): Promise<RoleAssignment>;
14
+ /** Delete project role assignment for a user. */
15
+ deleteUserAssignment(projectId: string, userId: string): Promise<void>;
16
+ /** Create or update project role assignment for a group (upsert). */
17
+ upsertGroupAssignment(projectId: string, groupId: string, body: UpsertUserRoleAssignmentRequest): Promise<RoleAssignment>;
18
+ /** Delete project role assignment for a group. */
19
+ deleteGroupAssignment(projectId: string, groupId: string): Promise<void>;
20
+ /** Update project role assignment for a group. */
21
+ updateGroupAssignment(projectId: string, groupId: string, body: UpdateRoleAssignmentRequest): Promise<RoleAssignment>;
22
+ }
23
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * Project role assignments API client (v2). Manage project-level role assignments for users and groups.
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.ProjectRoleAssignmentsClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class ProjectRoleAssignmentsClient extends base_client_1.BaseApiClient {
18
+ /** List project role assignments. */
19
+ listAssignments(projectId) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.http.get(`/projects/${projectId}/roles/assignments`);
22
+ });
23
+ }
24
+ /** Create or update project role assignment for a user (upsert). */
25
+ upsertUserAssignment(projectId, userId, body) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return this.http.post(`/projects/${projectId}/roles/assignments/user/${userId}`, body);
28
+ });
29
+ }
30
+ /** Delete project role assignment for a user. */
31
+ deleteUserAssignment(projectId, userId) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ yield this.http.delete(`/projects/${projectId}/roles/assignments/user/${userId}`);
34
+ });
35
+ }
36
+ /** Create or update project role assignment for a group (upsert). */
37
+ upsertGroupAssignment(projectId, groupId, body) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return this.http.post(`/projects/${projectId}/roles/assignments/group/${groupId}`, body);
40
+ });
41
+ }
42
+ /** Delete project role assignment for a group. */
43
+ deleteGroupAssignment(projectId, groupId) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ yield this.http.delete(`/projects/${projectId}/roles/assignments/group/${groupId}`);
46
+ });
47
+ }
48
+ /** Update project role assignment for a group. */
49
+ updateGroupAssignment(projectId, groupId, body) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ return this.http.patch(`/projects/${projectId}/roles/assignments/group/${groupId}`, body);
52
+ });
53
+ }
54
+ }
55
+ exports.ProjectRoleAssignmentsClient = ProjectRoleAssignmentsClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,66 @@
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_role_assignments_1 = require("./project-role-assignments");
14
+ (0, vitest_1.describe)('ProjectRoleAssignmentsClient', () => {
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)('listAssignments should call GET /projects/{projectId}/roles/assignments', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new project_role_assignments_1.ProjectRoleAssignmentsClient(mockHttp);
27
+ const assignments = [{ roleId: 'r1', roleName: 'Editor' }];
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(assignments);
29
+ const result = yield client.listAssignments('proj-1');
30
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/proj-1/roles/assignments');
31
+ (0, vitest_1.expect)(result).toEqual(assignments);
32
+ }));
33
+ (0, vitest_1.it)('upsertUserAssignment should call POST .../user/{userId} with body', () => __awaiter(void 0, void 0, void 0, function* () {
34
+ const client = new project_role_assignments_1.ProjectRoleAssignmentsClient(mockHttp);
35
+ const body = { roleId: 'r1' };
36
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({ roleId: 'r1' });
37
+ yield client.upsertUserAssignment('proj-1', 'user-1', body);
38
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/proj-1/roles/assignments/user/user-1', body);
39
+ }));
40
+ (0, vitest_1.it)('deleteUserAssignment should call DELETE .../user/{userId}', () => __awaiter(void 0, void 0, void 0, function* () {
41
+ const client = new project_role_assignments_1.ProjectRoleAssignmentsClient(mockHttp);
42
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
43
+ yield client.deleteUserAssignment('proj-1', 'user-1');
44
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/proj-1/roles/assignments/user/user-1');
45
+ }));
46
+ (0, vitest_1.it)('upsertGroupAssignment should call POST .../group/{groupId} with body', () => __awaiter(void 0, void 0, void 0, function* () {
47
+ const client = new project_role_assignments_1.ProjectRoleAssignmentsClient(mockHttp);
48
+ const body = { roleId: 'r1' };
49
+ vitest_1.vi.mocked(mockHttp.post).mockResolvedValue({ roleId: 'r1' });
50
+ yield client.upsertGroupAssignment('proj-1', 'group-1', body);
51
+ (0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/proj-1/roles/assignments/group/group-1', body);
52
+ }));
53
+ (0, vitest_1.it)('deleteGroupAssignment should call DELETE .../group/{groupId}', () => __awaiter(void 0, void 0, void 0, function* () {
54
+ const client = new project_role_assignments_1.ProjectRoleAssignmentsClient(mockHttp);
55
+ vitest_1.vi.mocked(mockHttp.delete).mockResolvedValue(undefined);
56
+ yield client.deleteGroupAssignment('proj-1', 'group-1');
57
+ (0, vitest_1.expect)(mockHttp.delete).toHaveBeenCalledWith('/projects/proj-1/roles/assignments/group/group-1');
58
+ }));
59
+ (0, vitest_1.it)('updateGroupAssignment should call PATCH .../group/{groupId}', () => __awaiter(void 0, void 0, void 0, function* () {
60
+ const client = new project_role_assignments_1.ProjectRoleAssignmentsClient(mockHttp);
61
+ const body = { roleId: 'r2' };
62
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue({ roleId: 'r2' });
63
+ yield client.updateGroupAssignment('proj-1', 'group-1', body);
64
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/projects/proj-1/roles/assignments/group/group-1', body);
65
+ }));
66
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Query API client for v2 endpoints. Run metric/SQL/underlying data queries using v2 API.
3
+ */
4
+ import type { ExecuteAsyncMetricQueryRequestParams, ExecuteAsyncSqlQueryRequestParams, ExecuteAsyncSavedChartRequestParams, ExecuteAsyncDashboardChartRequestParams, ExecuteAsyncUnderlyingDataRequestParams, ExecuteAsyncMetricQueryResults, ExecuteAsyncDashboardChartResults, ExecuteAsyncSqlQueryResults } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class QueryClientV2 extends BaseApiClient {
7
+ /** Run a metric query (v2 endpoint). */
8
+ runMetricQuery(projectUuid: string, body: ExecuteAsyncMetricQueryRequestParams): Promise<ExecuteAsyncMetricQueryResults>;
9
+ /** Run a SQL query (v2 endpoint). */
10
+ runSqlQuery(projectUuid: string, body: ExecuteAsyncSqlQueryRequestParams): Promise<ExecuteAsyncSqlQueryResults>;
11
+ /** Run a chart query (v2 endpoint). */
12
+ runChartQuery(projectUuid: string, body: ExecuteAsyncSavedChartRequestParams): Promise<ExecuteAsyncMetricQueryResults>;
13
+ /** Run a dashboard chart query (v2 endpoint). */
14
+ runDashboardChartQuery(projectUuid: string, body: ExecuteAsyncDashboardChartRequestParams): Promise<ExecuteAsyncDashboardChartResults>;
15
+ /** Run an underlying data query (v2 endpoint). */
16
+ runUnderlyingDataQuery(projectUuid: string, body: ExecuteAsyncUnderlyingDataRequestParams): Promise<ExecuteAsyncMetricQueryResults>;
17
+ }