@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
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # @lightdash-tools/client
2
+
3
+ HTTP client for the [Lightdash API](https://docs.lightdash.com/api-reference/v1/introduction) with centralized rate limiting, async calls, and TypeScript types generated from the OpenAPI spec.
4
+
5
+ ## Features
6
+
7
+ - **Rate limiting**: Token bucket (Bottleneck) to avoid hitting API limits
8
+ - **Async**: All methods return Promises
9
+ - **Type-safe**: Types generated from Lightdash OpenAPI spec
10
+ - **Environment variables**: Zero-config in CI using `LIGHTDASH_URL` and `LIGHTDASH_API_KEY`
11
+ - **Retries**: Exponential backoff for 5xx and network errors
12
+ - **Errors**: Typed `LightdashApiError`, `RateLimitError`, `NetworkError`
13
+ - **Shared models**: Domain models available from `@lightdash-tools/common` for cross-package reuse
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ pnpm add @lightdash-tools/client
19
+ ```
20
+
21
+ ## Configuration
22
+
23
+ You can pass options when creating the client or use environment variables (aligned with the [Lightdash CLI](https://docs.lightdash.com/references/lightdash-cli#core-lightdash-configuration)).
24
+
25
+ | Option | Env var | Description |
26
+ | --------------------- | ------------------------------- | ---------------------------- |
27
+ | `baseUrl` | `LIGHTDASH_URL` | Lightdash server URL |
28
+ | `personalAccessToken` | `LIGHTDASH_API_KEY` | API key (PAT) |
29
+ | `proxyAuthorization` | `LIGHTDASH_PROXY_AUTHORIZATION` | Proxy auth header (optional) |
30
+
31
+ Explicit config overrides environment variables.
32
+
33
+ ## Usage
34
+
35
+ ### With explicit config
36
+
37
+ ```typescript
38
+ import { LightdashClient } from '@lightdash-tools/client';
39
+
40
+ const client = new LightdashClient({
41
+ baseUrl: 'https://app.lightdash.cloud',
42
+ personalAccessToken: 'your-pat-token',
43
+ });
44
+
45
+ const project = await client.projects.getProject('project-uuid');
46
+ const org = await client.organizations.getCurrentOrganization();
47
+ const dashboards = await client.dashboards.listDashboards('project-uuid');
48
+ ```
49
+
50
+ ### With environment variables (e.g. CI)
51
+
52
+ ```bash
53
+ export LIGHTDASH_URL=https://app.lightdash.cloud
54
+ export LIGHTDASH_API_KEY=your-pat-token
55
+ ```
56
+
57
+ ```typescript
58
+ const client = new LightdashClient();
59
+ const project = await client.projects.getProject('project-uuid');
60
+ ```
61
+
62
+ ### Request cancellation (AbortController)
63
+
64
+ Pass `signal` when calling the low-level HTTP client:
65
+
66
+ ```typescript
67
+ const controller = new AbortController();
68
+ const http = client.getHttpClient();
69
+ const result = await http.get('/projects/p1', { signal: controller.signal });
70
+ controller.abort(); // cancels the request
71
+ ```
72
+
73
+ ### Logging and observability
74
+
75
+ ```typescript
76
+ import { LightdashClient, consoleLogger } from '@lightdash-tools/client';
77
+
78
+ const client = new LightdashClient({
79
+ baseUrl: 'https://app.lightdash.cloud',
80
+ personalAccessToken: 'token',
81
+ logger: consoleLogger,
82
+ observability: {
83
+ onRequestComplete: (info) => {
84
+ console.log(`${info.method} ${info.url} ${info.statusCode} ${info.durationMs}ms`);
85
+ },
86
+ },
87
+ });
88
+ ```
89
+
90
+ ## API areas
91
+
92
+ - `client.v1.projects` – get project, list projects, list charts
93
+ - `client.v1.organizations` – get current organization
94
+ - `client.v1.charts` – list charts
95
+ - `client.v1.dashboards` – list dashboards
96
+ - `client.v1.spaces` – list/get/create/update/delete spaces; grant/revoke user and group access to spaces
97
+ - `client.v1.projectAccess` – list/grant/get/update/revoke project access for users; list/add/remove/update project access for groups (see [Assign or update project access for a list of users](https://docs.lightdash.com/api-reference/v1/recipes))
98
+ - `client.v1.query` – run metric queries
99
+ - `client.v1.users` – list/get/update organization members
100
+ - `client.v1.groups` – list/create/update groups
101
+ - `client.v1.aiAgents` – list AI agents (admin), list threads (admin), get/update AI organization settings
102
+
103
+ Deprecated top-level aliases (`client.projects`, `client.organizations`, etc.) are still available but will be removed in a future major version.
104
+
105
+ For custom endpoints use `client.getHttpClientV1()` and call `get`, `post`, `put`, `patch`, `delete` with the path (relative to `/api/v1`).
106
+
107
+ ## Package dependency
108
+
109
+ - Commander.js: <https://www.npmjs.com/package/commander> <!-- markdown-link-check-disable-line -->
110
+
111
+ This package depends on `@lightdash-tools/common` only (one-way: client → common). Types and API models are consumed from common; see [ADR 0004](../../docs/adr/0004-shared-api-models-in-common-package.md) for the architecture.
112
+
113
+ ## Type Imports
114
+
115
+ Domain models (Project, Organization, etc.) are available from `@lightdash-tools/common`:
116
+
117
+ ```typescript
118
+ import type { Project, Organization } from '@lightdash-tools/common';
119
+ ```
120
+
121
+ Advanced types (`paths`, `components`, `operations`) are available from the client package:
122
+
123
+ ```typescript
124
+ import type { paths, components, operations } from '@lightdash-tools/client';
125
+ ```
126
+
127
+ ## Regenerating types
128
+
129
+ OpenAPI types are generated in the `@lightdash-tools/common` package. To regenerate:
130
+
131
+ ```bash
132
+ pnpm --filter @lightdash-tools/common generate:types
133
+ ```
134
+
135
+ After regenerating types, rebuild both common and client packages:
136
+
137
+ ```bash
138
+ pnpm build --filter @lightdash-tools/common
139
+ pnpm build --filter @lightdash-tools/client
140
+ ```
141
+
142
+ ## License
143
+
144
+ ISC
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Base pattern for API area clients. Each area (projects, organizations, charts, etc.)
3
+ * receives the shared HttpClient and implements typed methods for its endpoints.
4
+ */
5
+ import type { HttpClient } from '../http/http-client';
6
+ /**
7
+ * Base for API area clients. Subclasses receive the shared HTTP client
8
+ * and implement methods that call this.http.get/post/put/patch/delete with typed paths and responses.
9
+ */
10
+ export declare abstract class BaseApiClient {
11
+ protected readonly http: HttpClient;
12
+ constructor(http: HttpClient);
13
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * Base pattern for API area clients. Each area (projects, organizations, charts, etc.)
4
+ * receives the shared HttpClient and implements typed methods for its endpoints.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.BaseApiClient = void 0;
8
+ /**
9
+ * Base for API area clients. Subclasses receive the shared HTTP client
10
+ * and implement methods that call this.http.get/post/put/patch/delete with typed paths and responses.
11
+ */
12
+ class BaseApiClient {
13
+ constructor(http) {
14
+ this.http = http;
15
+ }
16
+ }
17
+ exports.BaseApiClient = BaseApiClient;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * AI agents API client. Admin endpoints for listing agents, threads, and managing org AI settings.
3
+ */
4
+ import type { AiAgentSummary, AiAgentsAdminThreadsResult, GetAdminThreadsParams, GetAiOrganizationSettingsResult, UpdateAiOrganizationSettings, UpdateAiOrganizationSettingsResult } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export declare class AiAgentsClient extends BaseApiClient {
7
+ /**
8
+ * List all AI agent threads (admin). Supports pagination and filters.
9
+ */
10
+ getAdminThreads(params?: GetAdminThreadsParams): Promise<AiAgentsAdminThreadsResult>;
11
+ /** List all AI agents (admin). */
12
+ listAdminAgents(): Promise<AiAgentSummary[]>;
13
+ /** Get AI organization settings. */
14
+ getAiOrganizationSettings(): Promise<GetAiOrganizationSettingsResult>;
15
+ /** Update AI organization settings. */
16
+ updateAiOrganizationSettings(body: UpdateAiOrganizationSettings): Promise<UpdateAiOrganizationSettingsResult>;
17
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * AI agents API client. Admin endpoints for listing agents, threads, and managing org AI settings.
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.AiAgentsClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class AiAgentsClient extends base_client_1.BaseApiClient {
18
+ /**
19
+ * List all AI agent threads (admin). Supports pagination and filters.
20
+ */
21
+ getAdminThreads(params) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ return this.http.get('/aiAgents/admin/threads', {
24
+ params,
25
+ });
26
+ });
27
+ }
28
+ /** List all AI agents (admin). */
29
+ listAdminAgents() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return this.http.get('/aiAgents/admin/agents');
32
+ });
33
+ }
34
+ /** Get AI organization settings. */
35
+ getAiOrganizationSettings() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return this.http.get('/aiAgents/admin/settings');
38
+ });
39
+ }
40
+ /** Update AI organization settings. */
41
+ updateAiOrganizationSettings(body) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ return this.http.patch('/aiAgents/admin/settings', body);
44
+ });
45
+ }
46
+ }
47
+ exports.AiAgentsClient = AiAgentsClient;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
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 ai_agents_1 = require("./ai-agents");
14
+ (0, vitest_1.describe)('AiAgentsClient', () => {
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)('getAdminThreads should call GET /aiAgents/admin/threads with optional params', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const client = new ai_agents_1.AiAgentsClient(mockHttp);
27
+ const results = { data: [], pagination: { totalResults: 0, totalPageCount: 0 } };
28
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
29
+ const result = yield client.getAdminThreads({
30
+ page: 1,
31
+ pageSize: 20,
32
+ sortField: 'createdAt',
33
+ sortDirection: 'desc',
34
+ });
35
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/aiAgents/admin/threads', {
36
+ params: { page: 1, pageSize: 20, sortField: 'createdAt', sortDirection: 'desc' },
37
+ });
38
+ (0, vitest_1.expect)(result).toEqual(results);
39
+ }));
40
+ (0, vitest_1.it)('getAdminThreads without params should call GET with no params', () => __awaiter(void 0, void 0, void 0, function* () {
41
+ const client = new ai_agents_1.AiAgentsClient(mockHttp);
42
+ const results = { data: [], pagination: { totalResults: 0, totalPageCount: 0 } };
43
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(results);
44
+ yield client.getAdminThreads();
45
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/aiAgents/admin/threads', { params: undefined });
46
+ }));
47
+ (0, vitest_1.it)('listAdminAgents should call GET /aiAgents/admin/agents', () => __awaiter(void 0, void 0, void 0, function* () {
48
+ const client = new ai_agents_1.AiAgentsClient(mockHttp);
49
+ const list = [{ uuid: 'a1', name: 'Agent 1', description: null }];
50
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(list);
51
+ const result = yield client.listAdminAgents();
52
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/aiAgents/admin/agents');
53
+ (0, vitest_1.expect)(result).toEqual(list);
54
+ }));
55
+ (0, vitest_1.it)('getAiOrganizationSettings should call GET /aiAgents/admin/settings', () => __awaiter(void 0, void 0, void 0, function* () {
56
+ const client = new ai_agents_1.AiAgentsClient(mockHttp);
57
+ const settings = {
58
+ aiAgentsVisible: true,
59
+ organizationUuid: 'org1',
60
+ isTrial: false,
61
+ isCopilotEnabled: false,
62
+ };
63
+ vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(settings);
64
+ const result = yield client.getAiOrganizationSettings();
65
+ (0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/aiAgents/admin/settings');
66
+ (0, vitest_1.expect)(result).toEqual(settings);
67
+ }));
68
+ (0, vitest_1.it)('updateAiOrganizationSettings should call PATCH /aiAgents/admin/settings with body', () => __awaiter(void 0, void 0, void 0, function* () {
69
+ const client = new ai_agents_1.AiAgentsClient(mockHttp);
70
+ const body = { aiAgentsVisible: false };
71
+ const updated = { aiAgentsVisible: false, organizationUuid: 'org1' };
72
+ vitest_1.vi.mocked(mockHttp.patch).mockResolvedValue(updated);
73
+ const result = yield client.updateAiOrganizationSettings(body);
74
+ (0, vitest_1.expect)(mockHttp.patch).toHaveBeenCalledWith('/aiAgents/admin/settings', body);
75
+ (0, vitest_1.expect)(result).toEqual(updated);
76
+ }));
77
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Charts API client. Endpoints for saved charts and chart-as-code operations.
3
+ */
4
+ import type { SpaceQuery, ChartAsCodeListResults, ChartAsCodeUpsertResults, UpsertChartAsCodeBody } from '@lightdash-tools/common';
5
+ import { BaseApiClient } from '../base-client';
6
+ export interface GetChartsAsCodeOptions {
7
+ ids?: string[];
8
+ offset?: number;
9
+ languageMap?: boolean;
10
+ }
11
+ export declare class ChartsClient extends BaseApiClient {
12
+ /** List charts in a project (returns SpaceQuery array). */
13
+ listCharts(projectUuid: string): Promise<SpaceQuery[]>;
14
+ /** Get charts in code representation (for charts-as-code workflows). */
15
+ getChartsAsCode(projectUuid: string, options?: GetChartsAsCodeOptions): Promise<ChartAsCodeListResults>;
16
+ /** Upsert a chart from code representation (create or update by slug). */
17
+ upsertChartAsCode(projectUuid: string, slug: string, body: UpsertChartAsCodeBody): Promise<ChartAsCodeUpsertResults>;
18
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /**
3
+ * Charts API client. Endpoints for saved charts and chart-as-code operations.
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.ChartsClient = void 0;
16
+ const base_client_1 = require("../base-client");
17
+ class ChartsClient extends base_client_1.BaseApiClient {
18
+ /** List charts in a project (returns SpaceQuery array). */
19
+ listCharts(projectUuid) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ return this.http.get(`/projects/${projectUuid}/charts`);
22
+ });
23
+ }
24
+ /** Get charts in code representation (for charts-as-code workflows). */
25
+ getChartsAsCode(projectUuid, options) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ var _a;
28
+ const params = {};
29
+ if ((_a = options === null || options === void 0 ? void 0 : options.ids) === null || _a === void 0 ? void 0 : _a.length)
30
+ params.ids = options.ids;
31
+ if ((options === null || options === void 0 ? void 0 : options.offset) != null)
32
+ params.offset = options.offset;
33
+ if ((options === null || options === void 0 ? void 0 : options.languageMap) != null)
34
+ params.languageMap = options.languageMap;
35
+ return this.http.get(`/projects/${projectUuid}/charts/code`, Object.keys(params).length ? { params } : undefined);
36
+ });
37
+ }
38
+ /** Upsert a chart from code representation (create or update by slug). */
39
+ upsertChartAsCode(projectUuid, slug, body) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return this.http.post(`/projects/${projectUuid}/charts/${encodeURIComponent(slug)}/code`, body);
42
+ });
43
+ }
44
+ }
45
+ exports.ChartsClient = ChartsClient;
@@ -0,0 +1 @@
1
+ export {};