@lightdash-tools/client 0.6.0 → 0.8.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 (256) hide show
  1. package/README.md +2 -2
  2. package/dist/agentops/apply-agent-change.d.ts +3 -0
  3. package/dist/agentops/apply-agent-change.js +63 -0
  4. package/dist/agentops/apply-bundle-diff.d.ts +13 -0
  5. package/dist/agentops/apply-bundle-diff.js +44 -0
  6. package/dist/agentops/apply-bundle-diff.test.d.ts +1 -0
  7. package/dist/agentops/apply-bundle-diff.test.js +397 -0
  8. package/dist/agentops/apply-context.d.ts +14 -0
  9. package/dist/agentops/apply-context.js +6 -0
  10. package/dist/agentops/apply-evaluation-change.d.ts +3 -0
  11. package/dist/agentops/apply-evaluation-change.js +78 -0
  12. package/dist/agentops/fetch-bundle-state.d.ts +6 -0
  13. package/dist/agentops/fetch-bundle-state.js +20 -0
  14. package/dist/agentops/fetch-bundle-state.test.d.ts +1 -0
  15. package/dist/agentops/fetch-bundle-state.test.js +44 -0
  16. package/dist/agentops/index.d.ts +3 -0
  17. package/dist/agentops/index.js +9 -0
  18. package/dist/agentops/resolve-evaluation-run.d.ts +15 -0
  19. package/dist/agentops/resolve-evaluation-run.js +48 -0
  20. package/dist/api/v1/ai-agents/admin.d.ts +16 -0
  21. package/dist/api/v1/ai-agents/admin.js +29 -0
  22. package/dist/api/v1/ai-agents/agents.d.ts +18 -0
  23. package/dist/api/v1/ai-agents/agents.js +31 -0
  24. package/dist/api/v1/ai-agents/artifacts.d.ts +26 -0
  25. package/dist/api/v1/ai-agents/artifacts.js +41 -0
  26. package/dist/api/v1/ai-agents/artifacts.test.d.ts +1 -0
  27. package/dist/api/v1/ai-agents/artifacts.test.js +69 -0
  28. package/dist/api/v1/ai-agents/discovery.d.ts +28 -0
  29. package/dist/api/v1/ai-agents/discovery.js +46 -0
  30. package/dist/api/v1/ai-agents/discovery.test.d.ts +1 -0
  31. package/dist/api/v1/ai-agents/discovery.test.js +90 -0
  32. package/dist/api/v1/ai-agents/evaluations.d.ts +39 -0
  33. package/dist/api/v1/ai-agents/evaluations.js +70 -0
  34. package/dist/api/v1/ai-agents/facade.d.ts +79 -0
  35. package/dist/api/v1/ai-agents/facade.js +193 -0
  36. package/dist/api/v1/ai-agents/feedback.d.ts +10 -0
  37. package/dist/api/v1/ai-agents/feedback.js +15 -0
  38. package/dist/api/v1/ai-agents/feedback.test.d.ts +1 -0
  39. package/dist/api/v1/ai-agents/feedback.test.js +23 -0
  40. package/dist/api/v1/ai-agents/index.d.ts +1 -0
  41. package/dist/api/v1/ai-agents/index.js +5 -0
  42. package/dist/api/v1/ai-agents/mcp-servers.d.ts +20 -0
  43. package/dist/api/v1/ai-agents/mcp-servers.js +35 -0
  44. package/dist/api/v1/ai-agents/mcp-servers.test.d.ts +1 -0
  45. package/dist/api/v1/ai-agents/mcp-servers.test.js +66 -0
  46. package/dist/api/v1/ai-agents/request-options.d.ts +12 -0
  47. package/dist/api/v1/ai-agents/request-options.js +20 -0
  48. package/dist/api/v1/ai-agents/sql-approval.d.ts +10 -0
  49. package/dist/api/v1/ai-agents/sql-approval.js +15 -0
  50. package/dist/api/v1/ai-agents/sql-approval.test.d.ts +1 -0
  51. package/dist/api/v1/ai-agents/sql-approval.test.js +25 -0
  52. package/dist/api/v1/ai-agents/threads.d.ts +56 -0
  53. package/dist/api/v1/ai-agents/threads.js +97 -0
  54. package/dist/api/v1/ai-agents/threads.test.d.ts +1 -0
  55. package/dist/api/v1/ai-agents/threads.test.js +39 -0
  56. package/dist/api/v1/ai-agents.test.js +172 -89
  57. package/dist/api/v1/analytics.d.ts +10 -0
  58. package/dist/api/v1/analytics.js +14 -0
  59. package/dist/api/v1/analytics.test.d.ts +4 -0
  60. package/dist/api/v1/analytics.test.js +27 -0
  61. package/dist/api/v1/charts.d.ts +13 -2
  62. package/dist/api/v1/charts.js +26 -30
  63. package/dist/api/v1/charts.test.js +35 -28
  64. package/dist/api/v1/dashboards.d.ts +42 -2
  65. package/dist/api/v1/dashboards.js +39 -14
  66. package/dist/api/v1/dashboards.test.js +126 -12
  67. package/dist/api/v1/explores.d.ts +4 -2
  68. package/dist/api/v1/explores.js +20 -29
  69. package/dist/api/v1/explores.test.js +31 -21
  70. package/dist/api/v1/groups.d.ts +1 -1
  71. package/dist/api/v1/groups.js +25 -51
  72. package/dist/api/v1/groups.test.js +15 -24
  73. package/dist/api/v1/metrics.d.ts +2 -2
  74. package/dist/api/v1/metrics.js +4 -17
  75. package/dist/api/v1/metrics.test.js +6 -15
  76. package/dist/api/v1/organizations.d.ts +1 -1
  77. package/dist/api/v1/organizations.js +2 -13
  78. package/dist/api/v1/organizations.test.js +3 -12
  79. package/dist/api/v1/project-access.d.ts +1 -1
  80. package/dist/api/v1/project-access.js +18 -45
  81. package/dist/api/v1/project-access.test.js +27 -36
  82. package/dist/api/v1/projects.d.ts +1 -1
  83. package/dist/api/v1/projects.js +6 -21
  84. package/dist/api/v1/projects.test.js +9 -18
  85. package/dist/api/v1/query.d.ts +5 -2
  86. package/dist/api/v1/query.js +8 -18
  87. package/dist/api/v1/query.test.js +6 -15
  88. package/dist/api/v1/schedulers.d.ts +2 -2
  89. package/dist/api/v1/schedulers.js +4 -17
  90. package/dist/api/v1/schedulers.test.js +6 -15
  91. package/dist/api/v1/spaces.d.ts +1 -1
  92. package/dist/api/v1/spaces.js +18 -45
  93. package/dist/api/v1/spaces.test.js +27 -36
  94. package/dist/api/v1/tags.d.ts +1 -1
  95. package/dist/api/v1/tags.js +4 -17
  96. package/dist/api/v1/tags.test.js +6 -15
  97. package/dist/api/v1/users.d.ts +3 -1
  98. package/dist/api/v1/users.js +22 -39
  99. package/dist/api/v1/users.test.js +44 -30
  100. package/dist/api/v1/validation.d.ts +9 -2
  101. package/dist/api/v1/validation.js +16 -18
  102. package/dist/api/v1/validation.test.js +22 -15
  103. package/dist/api/v2/charts.d.ts +12 -0
  104. package/dist/api/v2/charts.js +18 -0
  105. package/dist/api/v2/charts.test.d.ts +4 -0
  106. package/dist/api/v2/charts.test.js +45 -0
  107. package/dist/api/v2/content.d.ts +20 -3
  108. package/dist/api/v2/content.js +18 -14
  109. package/dist/api/v2/content.test.js +44 -12
  110. package/dist/api/v2/dashboards.d.ts +16 -0
  111. package/dist/api/v2/dashboards.js +22 -0
  112. package/dist/api/v2/dashboards.test.d.ts +4 -0
  113. package/dist/api/v2/dashboards.test.js +61 -0
  114. package/dist/api/v2/organization-roles.d.ts +1 -1
  115. package/dist/api/v2/organization-roles.js +21 -50
  116. package/dist/api/v2/organization-roles.test.js +33 -42
  117. package/dist/api/v2/parameters.d.ts +20 -0
  118. package/dist/api/v2/parameters.js +22 -0
  119. package/dist/api/v2/parameters.test.d.ts +4 -0
  120. package/dist/api/v2/parameters.test.js +39 -0
  121. package/dist/api/v2/project-role-assignments.d.ts +1 -1
  122. package/dist/api/v2/project-role-assignments.js +12 -33
  123. package/dist/api/v2/project-role-assignments.test.js +18 -27
  124. package/dist/api/v2/query.d.ts +16 -1
  125. package/dist/api/v2/query.js +26 -29
  126. package/dist/api/v2/query.test.js +31 -24
  127. package/dist/api/v2/validation.d.ts +28 -0
  128. package/dist/api/v2/validation.js +23 -0
  129. package/dist/client.d.ts +24 -14
  130. package/dist/client.js +26 -16
  131. package/dist/client.test.js +2 -0
  132. package/dist/config.d.ts +35 -10
  133. package/dist/http/axios-client.d.ts +4 -4
  134. package/dist/http/http-client.d.ts +3 -14
  135. package/dist/http/http-client.js +20 -43
  136. package/dist/http/interceptors.d.ts +3 -3
  137. package/dist/http/interceptors.js +16 -3
  138. package/dist/http/rate-limiter.js +2 -13
  139. package/dist/http/rate-limiter.test.js +15 -24
  140. package/dist/http/unwrap-api-success.d.ts +26 -0
  141. package/dist/http/unwrap-api-success.js +25 -0
  142. package/dist/http/unwrap-api-success.test.d.ts +1 -0
  143. package/dist/http/unwrap-api-success.test.js +19 -0
  144. package/dist/index.d.ts +13 -3
  145. package/dist/index.js +17 -1
  146. package/dist/index.test.js +13 -5
  147. package/dist/pagination/fetch-all-pages.js +18 -29
  148. package/dist/pagination/fetch-all-pages.test.js +15 -24
  149. package/dist/types/api.d.ts +1 -1
  150. package/dist/utils/env.d.ts +11 -2
  151. package/dist/utils/env.js +41 -8
  152. package/dist/utils/env.test.js +14 -4
  153. package/dist/utils/logger.js +5 -4
  154. package/dist/utils/retry.js +17 -28
  155. package/dist/utils/retry.test.js +9 -18
  156. package/dist/utils/secret-string.test.d.ts +1 -0
  157. package/dist/utils/secret-string.test.js +25 -0
  158. package/package.json +12 -4
  159. package/src/agentops/apply-agent-change.ts +82 -0
  160. package/src/agentops/apply-bundle-diff.test.ts +453 -0
  161. package/src/agentops/apply-bundle-diff.ts +63 -0
  162. package/src/agentops/apply-context.ts +23 -0
  163. package/src/agentops/apply-evaluation-change.ts +125 -0
  164. package/src/agentops/fetch-bundle-state.test.ts +51 -0
  165. package/src/agentops/fetch-bundle-state.ts +33 -0
  166. package/src/agentops/index.ts +11 -0
  167. package/src/agentops/resolve-evaluation-run.ts +94 -0
  168. package/src/api/v1/ai-agents/admin.ts +41 -0
  169. package/src/api/v1/ai-agents/agents.ts +40 -0
  170. package/src/api/v1/ai-agents/artifacts.test.ts +84 -0
  171. package/src/api/v1/ai-agents/artifacts.ts +92 -0
  172. package/src/api/v1/ai-agents/discovery.test.ts +102 -0
  173. package/src/api/v1/ai-agents/discovery.ts +79 -0
  174. package/src/api/v1/ai-agents/evaluations.ts +152 -0
  175. package/src/api/v1/ai-agents/facade.ts +489 -0
  176. package/src/api/v1/ai-agents/feedback.test.ts +30 -0
  177. package/src/api/v1/ai-agents/feedback.ts +24 -0
  178. package/src/api/v1/ai-agents/index.ts +1 -0
  179. package/src/api/v1/ai-agents/mcp-servers.test.ts +81 -0
  180. package/src/api/v1/ai-agents/mcp-servers.ts +67 -0
  181. package/src/api/v1/ai-agents/request-options.ts +32 -0
  182. package/src/api/v1/ai-agents/sql-approval.test.ts +32 -0
  183. package/src/api/v1/ai-agents/sql-approval.ts +24 -0
  184. package/src/api/v1/ai-agents/threads.test.ts +55 -0
  185. package/src/api/v1/ai-agents/threads.ts +216 -0
  186. package/src/api/v1/ai-agents.test.ts +189 -13
  187. package/src/api/v1/analytics.test.ts +32 -0
  188. package/src/api/v1/analytics.ts +16 -0
  189. package/src/api/v1/charts.test.ts +26 -6
  190. package/src/api/v1/charts.ts +25 -4
  191. package/src/api/v1/dashboards.test.ts +142 -0
  192. package/src/api/v1/dashboards.ts +127 -2
  193. package/src/api/v1/explores.test.ts +22 -0
  194. package/src/api/v1/explores.ts +13 -2
  195. package/src/api/v1/groups.test.ts +2 -0
  196. package/src/api/v1/groups.ts +9 -7
  197. package/src/api/v1/metrics.test.ts +2 -0
  198. package/src/api/v1/metrics.ts +3 -2
  199. package/src/api/v1/organizations.test.ts +2 -0
  200. package/src/api/v1/organizations.ts +2 -1
  201. package/src/api/v1/project-access.test.ts +3 -1
  202. package/src/api/v1/project-access.ts +2 -1
  203. package/src/api/v1/projects.test.ts +2 -0
  204. package/src/api/v1/projects.ts +2 -1
  205. package/src/api/v1/query.test.ts +2 -0
  206. package/src/api/v1/query.ts +6 -2
  207. package/src/api/v1/schedulers.test.ts +2 -0
  208. package/src/api/v1/schedulers.ts +3 -2
  209. package/src/api/v1/spaces.test.ts +2 -0
  210. package/src/api/v1/spaces.ts +2 -1
  211. package/src/api/v1/tags.test.ts +2 -0
  212. package/src/api/v1/tags.ts +2 -1
  213. package/src/api/v1/users.test.ts +26 -0
  214. package/src/api/v1/users.ts +8 -2
  215. package/src/api/v1/validation.test.ts +20 -0
  216. package/src/api/v1/validation.ts +26 -2
  217. package/src/api/v2/charts.test.ts +53 -0
  218. package/src/api/v2/charts.ts +23 -0
  219. package/src/api/v2/content.test.ts +47 -0
  220. package/src/api/v2/content.ts +37 -3
  221. package/src/api/v2/dashboards.test.ts +71 -0
  222. package/src/api/v2/dashboards.ts +40 -0
  223. package/src/api/v2/organization-roles.test.ts +2 -0
  224. package/src/api/v2/organization-roles.ts +2 -1
  225. package/src/api/v2/parameters.test.ts +45 -0
  226. package/src/api/v2/parameters.ts +38 -0
  227. package/src/api/v2/project-role-assignments.test.ts +2 -0
  228. package/src/api/v2/project-role-assignments.ts +2 -1
  229. package/src/api/v2/query.test.ts +20 -0
  230. package/src/api/v2/query.ts +55 -1
  231. package/src/api/v2/validation.ts +48 -0
  232. package/src/client.test.ts +3 -0
  233. package/src/client.ts +33 -17
  234. package/src/config.ts +38 -10
  235. package/src/errors.test.ts +1 -0
  236. package/src/http/axios-client.ts +8 -5
  237. package/src/http/http-client.ts +8 -21
  238. package/src/http/interceptors.ts +23 -10
  239. package/src/http/rate-limiter.test.ts +1 -0
  240. package/src/http/rate-limiter.ts +3 -1
  241. package/src/http/unwrap-api-success.test.ts +23 -0
  242. package/src/http/unwrap-api-success.ts +40 -0
  243. package/src/index.test.ts +16 -7
  244. package/src/index.ts +37 -2
  245. package/src/pagination/fetch-all-pages.test.ts +2 -0
  246. package/src/types/api.ts +1 -1
  247. package/src/utils/env.test.ts +16 -4
  248. package/src/utils/env.ts +61 -10
  249. package/src/utils/logger.ts +6 -4
  250. package/src/utils/retry.test.ts +1 -0
  251. package/src/utils/retry.ts +2 -1
  252. package/src/utils/secret-string.test.ts +27 -0
  253. package/tsconfig.json +4 -2
  254. package/dist/api/v1/ai-agents.d.ts +0 -63
  255. package/dist/api/v1/ai-agents.js +0 -173
  256. package/src/api/v1/ai-agents.ts +0 -252
package/dist/config.d.ts CHANGED
@@ -49,15 +49,17 @@ export interface ObservabilityHooks {
49
49
  error?: Error;
50
50
  }): void;
51
51
  }
52
- /**
53
- * Full configuration for the Lightdash HTTP client.
54
- * All fields except rateLimit, timeout, retry, and logger can be provided via environment variables.
55
- */
56
- export interface LightdashClientConfig {
52
+ /** Upstream Lightdash authentication scheme. */
53
+ export type LightdashAuthConfig = {
54
+ type: 'api-key';
55
+ token: SecretString;
56
+ } | {
57
+ type: 'bearer';
58
+ token: SecretString;
59
+ };
60
+ interface LightdashClientConfigBase {
57
61
  /** Lightdash server base URL (e.g. https://app.lightdash.cloud). */
58
62
  baseUrl: string;
59
- /** Personal access token for API authentication (without ldpat_ prefix). */
60
- personalAccessToken: SecretString;
61
63
  /** Optional proxy authorization header value for proxied access. */
62
64
  proxyAuthorization?: SecretString;
63
65
  /** Override default rate limits. */
@@ -71,13 +73,35 @@ export interface LightdashClientConfig {
71
73
  /** Optional hooks for metrics/telemetry. */
72
74
  observability?: ObservabilityHooks;
73
75
  }
76
+ /**
77
+ * Resolved client configuration after mergeConfig().
78
+ * Runtime code paths always receive this shape with auth populated.
79
+ */
80
+ export type ResolvedLightdashClientConfig = LightdashClientConfigBase & {
81
+ auth: LightdashAuthConfig;
82
+ /**
83
+ * @deprecated Use `auth: { type: 'api-key', token }`. Retained when auth is api-key.
84
+ */
85
+ personalAccessToken?: SecretString;
86
+ };
87
+ /**
88
+ * Full configuration for the Lightdash HTTP client.
89
+ * Accepts explicit auth or deprecated personalAccessToken-only input.
90
+ */
91
+ export type LightdashClientConfig = ResolvedLightdashClientConfig | (LightdashClientConfigBase & {
92
+ personalAccessToken: SecretString;
93
+ });
74
94
  /**
75
95
  * Partial config for merging with environment variables.
76
96
  * Used when constructing the client with optional explicit overrides.
77
97
  */
78
- export type PartialLightdashClientConfig = Partial<Omit<LightdashClientConfig, 'personalAccessToken' | 'proxyAuthorization'>> & {
79
- personalAccessToken?: string | SecretString;
80
- proxyAuthorization?: string | SecretString;
98
+ export type PartialLightdashClientConfig = Partial<Omit<LightdashClientConfigBase, 'proxyAuthorization'>> & {
99
+ auth?: LightdashAuthConfig | {
100
+ type: 'api-key' | 'bearer';
101
+ token: SecretString | string;
102
+ };
103
+ personalAccessToken?: SecretString | string;
104
+ proxyAuthorization?: SecretString | string;
81
105
  };
82
106
  /** Default rate limit: 10 req/sec, 5 concurrent, token bucket. */
83
107
  export declare const DEFAULT_RATE_LIMIT: Required<RateLimitConfig>;
@@ -85,3 +109,4 @@ export declare const DEFAULT_RATE_LIMIT: Required<RateLimitConfig>;
85
109
  export declare const DEFAULT_TIMEOUT = 30000;
86
110
  /** Default retry config. */
87
111
  export declare const DEFAULT_RETRY: Required<RetryConfig>;
112
+ export {};
@@ -2,7 +2,7 @@
2
2
  * Axios instance setup with base URL, timeout, and interceptors.
3
3
  */
4
4
  import { type AxiosInstance } from 'axios';
5
- import type { LightdashClientConfig } from '../config';
5
+ import type { ResolvedLightdashClientConfig } from '../config';
6
6
  /**
7
7
  * API version type.
8
8
  */
@@ -10,13 +10,13 @@ export type ApiVersion = 'v1' | 'v2';
10
10
  /**
11
11
  * Creates a configured Axios instance for the Lightdash API v1.
12
12
  */
13
- export declare function createAxiosInstanceV1(config: LightdashClientConfig): AxiosInstance;
13
+ export declare function createAxiosInstanceV1(config: ResolvedLightdashClientConfig): AxiosInstance;
14
14
  /**
15
15
  * Creates a configured Axios instance for the Lightdash API v2.
16
16
  */
17
- export declare function createAxiosInstanceV2(config: LightdashClientConfig): AxiosInstance;
17
+ export declare function createAxiosInstanceV2(config: ResolvedLightdashClientConfig): AxiosInstance;
18
18
  /**
19
19
  * Creates a configured Axios instance for the Lightdash API v1.
20
20
  * @deprecated Use `createAxiosInstanceV1` instead. This function is kept for backward compatibility.
21
21
  */
22
- export declare function createAxiosInstance(config: LightdashClientConfig): AxiosInstance;
22
+ export declare function createAxiosInstance(config: ResolvedLightdashClientConfig): AxiosInstance;
@@ -2,20 +2,9 @@
2
2
  * HTTP client wrapper: rate limiter + axios + retry.
3
3
  * All requests go through the rate limiter; retry applies to 5xx and network errors.
4
4
  */
5
- import type { AxiosInstance, AxiosRequestConfig } from 'axios';
6
- import type { LightdashClientConfig } from '../config';
7
- import { type ApiErrorPayload } from '../errors';
8
5
  import { type RateLimiter } from './rate-limiter';
9
- /** Lightdash API success response shape. */
10
- export interface ApiSuccessBody<T = unknown> {
11
- status: 'ok';
12
- results: T;
13
- }
14
- /** Lightdash API error response shape (body). */
15
- export interface ApiErrorBody {
16
- status: 'error';
17
- error: ApiErrorPayload['error'];
18
- }
6
+ import type { ResolvedLightdashClientConfig } from '../config';
7
+ import type { AxiosInstance, AxiosRequestConfig } from 'axios';
19
8
  /**
20
9
  * HTTP client that wraps Axios with rate limiting and retry.
21
10
  */
@@ -23,7 +12,7 @@ export declare class HttpClient {
23
12
  private readonly axiosInstance;
24
13
  private readonly rateLimiter;
25
14
  private readonly config;
26
- constructor(axiosInstance: AxiosInstance, rateLimiter: RateLimiter, config: LightdashClientConfig);
15
+ constructor(axiosInstance: AxiosInstance, rateLimiter: RateLimiter, config: ResolvedLightdashClientConfig);
27
16
  private request;
28
17
  get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
29
18
  post<T>(url: string, body?: unknown, config?: AxiosRequestConfig): Promise<T>;
@@ -3,22 +3,11 @@
3
3
  * HTTP client wrapper: rate limiter + axios + retry.
4
4
  * All requests go through the rate limiter; retry applies to 5xx and network errors.
5
5
  */
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
6
  Object.defineProperty(exports, "__esModule", { value: true });
16
7
  exports.HttpClient = void 0;
17
8
  const errors_1 = require("../errors");
18
9
  const retry_1 = require("../utils/retry");
19
- function assertSuccess(data) {
20
- return data.status === 'ok';
21
- }
10
+ const unwrap_api_success_1 = require("./unwrap-api-success");
22
11
  /**
23
12
  * HTTP client that wraps Axios with rate limiting and retry.
24
13
  */
@@ -28,42 +17,30 @@ class HttpClient {
28
17
  this.rateLimiter = rateLimiter;
29
18
  this.config = config;
30
19
  }
31
- request(method, url, config) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const doRequest = () => this.axiosInstance.request(Object.assign(Object.assign({}, config), { method,
34
- url }));
35
- const response = yield this.rateLimiter.schedule(() => (0, retry_1.withRetry)(doRequest, this.config.retry));
36
- const data = response.data;
37
- if (!assertSuccess(data)) {
38
- throw new errors_1.LightdashApiError(data.error.statusCode, data.error, response.config, response);
39
- }
40
- return data.results;
41
- });
20
+ async request(method, url, config) {
21
+ const doRequest = () => this.axiosInstance.request(Object.assign(Object.assign({}, config), { method,
22
+ url }));
23
+ const response = await this.rateLimiter.schedule(() => (0, retry_1.withRetry)(doRequest, this.config.retry));
24
+ const data = response.data;
25
+ if (!(0, unwrap_api_success_1.isApiSuccessEnvelope)(data)) {
26
+ throw new errors_1.LightdashApiError(data.error.statusCode, data.error, response.config, response);
27
+ }
28
+ return data.results;
42
29
  }
43
- get(url, config) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return this.request('GET', url, config);
46
- });
30
+ async get(url, config) {
31
+ return this.request('GET', url, config);
47
32
  }
48
- post(url, body, config) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- return this.request('POST', url, Object.assign(Object.assign({}, config), { data: body }));
51
- });
33
+ async post(url, body, config) {
34
+ return this.request('POST', url, Object.assign(Object.assign({}, config), { data: body }));
52
35
  }
53
- put(url, body, config) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- return this.request('PUT', url, Object.assign(Object.assign({}, config), { data: body }));
56
- });
36
+ async put(url, body, config) {
37
+ return this.request('PUT', url, Object.assign(Object.assign({}, config), { data: body }));
57
38
  }
58
- patch(url, body, config) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- return this.request('PATCH', url, Object.assign(Object.assign({}, config), { data: body }));
61
- });
39
+ async patch(url, body, config) {
40
+ return this.request('PATCH', url, Object.assign(Object.assign({}, config), { data: body }));
62
41
  }
63
- delete(url, config) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- return this.request('DELETE', url, config);
66
- });
42
+ async delete(url, config) {
43
+ return this.request('DELETE', url, config);
67
44
  }
68
45
  }
69
46
  exports.HttpClient = HttpClient;
@@ -1,13 +1,13 @@
1
1
  /**
2
2
  * Request and response interceptors for auth, proxy, and error handling.
3
3
  */
4
+ import type { ResolvedLightdashClientConfig } from '../config';
4
5
  import type { AxiosInstance } from 'axios';
5
- import type { LightdashClientConfig } from '../config';
6
6
  /**
7
7
  * Attaches request interceptors: Authorization, Proxy-Authorization, optional request ID and logging.
8
8
  */
9
- export declare function attachRequestInterceptors(axiosInstance: AxiosInstance, config: LightdashClientConfig): void;
9
+ export declare function attachRequestInterceptors(axiosInstance: AxiosInstance, config: ResolvedLightdashClientConfig): void;
10
10
  /**
11
11
  * Attaches response interceptors: parse API responses, transform errors to LightdashApiError / RateLimitError.
12
12
  */
13
- export declare function attachResponseInterceptors(axiosInstance: AxiosInstance, config?: Pick<LightdashClientConfig, 'logger' | 'observability'>): void;
13
+ export declare function attachResponseInterceptors(axiosInstance: AxiosInstance, config?: Pick<ResolvedLightdashClientConfig, 'logger' | 'observability'>): void;
@@ -18,9 +18,22 @@ function getRetryAfterSeconds(value) {
18
18
  function attachRequestInterceptors(axiosInstance, config) {
19
19
  axiosInstance.interceptors.request.use((req) => {
20
20
  var _a;
21
- const rawToken = config.personalAccessToken.expose();
22
- const token = rawToken.startsWith('ldpat_') ? rawToken : `ldpat_${rawToken}`;
23
- req.headers.Authorization = `ApiKey ${token}`;
21
+ switch (config.auth.type) {
22
+ case 'api-key': {
23
+ const rawToken = config.auth.token.expose();
24
+ const token = rawToken.startsWith('ldpat_') ? rawToken : `ldpat_${rawToken}`;
25
+ req.headers.Authorization = `ApiKey ${token}`;
26
+ break;
27
+ }
28
+ case 'bearer': {
29
+ req.headers.Authorization = `Bearer ${config.auth.token.expose()}`;
30
+ break;
31
+ }
32
+ default: {
33
+ const _exhaustive = config.auth;
34
+ throw new Error(`Unsupported auth type: ${_exhaustive.type}`);
35
+ }
36
+ }
24
37
  if (config.proxyAuthorization) {
25
38
  req.headers['Proxy-Authorization'] = config.proxyAuthorization.expose();
26
39
  }
@@ -3,15 +3,6 @@
3
3
  * Rate limiter wrapping Bottleneck for centralized request throttling.
4
4
  * Uses token bucket algorithm; handles 429 retries via Bottleneck options.
5
5
  */
6
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
7
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8
- return new (P || (P = Promise))(function (resolve, reject) {
9
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
10
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
12
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13
- });
14
- };
15
6
  var __importDefault = (this && this.__importDefault) || function (mod) {
16
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
17
8
  };
@@ -51,10 +42,8 @@ class RateLimiter {
51
42
  return (...args) => this.limiter.schedule(() => fn(...args));
52
43
  }
53
44
  /** Stops the limiter and drains remaining jobs. */
54
- disconnect() {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- return this.limiter.disconnect(true);
57
- });
45
+ async disconnect() {
46
+ return this.limiter.disconnect(true);
58
47
  }
59
48
  }
60
49
  exports.RateLimiter = RateLimiter;
@@ -1,40 +1,31 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const vitest_1 = require("vitest");
13
4
  const rate_limiter_1 = require("./rate-limiter");
14
5
  (0, vitest_1.describe)('RateLimiter', () => {
15
- (0, vitest_1.it)('should schedule and run a single task', () => __awaiter(void 0, void 0, void 0, function* () {
6
+ (0, vitest_1.it)('should schedule and run a single task', async () => {
16
7
  const limiter = new rate_limiter_1.RateLimiter({ minTime: 0, maxConcurrent: 1 });
17
- const result = yield limiter.schedule(() => __awaiter(void 0, void 0, void 0, function* () { return 42; }));
8
+ const result = await limiter.schedule(async () => 42);
18
9
  (0, vitest_1.expect)(result).toBe(42);
19
- yield limiter.disconnect();
20
- }));
21
- (0, vitest_1.it)('should run tasks sequentially when maxConcurrent is 1', () => __awaiter(void 0, void 0, void 0, function* () {
10
+ await limiter.disconnect();
11
+ });
12
+ (0, vitest_1.it)('should run tasks sequentially when maxConcurrent is 1', async () => {
22
13
  const limiter = new rate_limiter_1.RateLimiter({ minTime: 10, maxConcurrent: 1 });
23
14
  const order = [];
24
- const promises = [1, 2, 3].map((n) => limiter.schedule(() => __awaiter(void 0, void 0, void 0, function* () {
15
+ const promises = [1, 2, 3].map((n) => limiter.schedule(async () => {
25
16
  order.push(n);
26
17
  return n;
27
- })));
28
- const results = yield Promise.all(promises);
18
+ }));
19
+ const results = await Promise.all(promises);
29
20
  (0, vitest_1.expect)(results).toEqual([1, 2, 3]);
30
21
  (0, vitest_1.expect)(order).toEqual([1, 2, 3]);
31
- yield limiter.disconnect();
32
- }));
33
- (0, vitest_1.it)('should wrap a function', () => __awaiter(void 0, void 0, void 0, function* () {
22
+ await limiter.disconnect();
23
+ });
24
+ (0, vitest_1.it)('should wrap a function', async () => {
34
25
  const limiter = new rate_limiter_1.RateLimiter({ minTime: 0 });
35
- const wrapped = limiter.wrap((a, b) => __awaiter(void 0, void 0, void 0, function* () { return a + b; }));
36
- const result = yield wrapped(1, 2);
26
+ const wrapped = limiter.wrap(async (a, b) => a + b);
27
+ const result = await wrapped(1, 2);
37
28
  (0, vitest_1.expect)(result).toBe(3);
38
- yield limiter.disconnect();
39
- }));
29
+ await limiter.disconnect();
30
+ });
40
31
  });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Pure helpers for Lightdash API success envelopes.
3
+ * HttpClient uses `isApiSuccessEnvelope` then maps failures to `LightdashApiError`.
4
+ */
5
+ export type ApiSuccessEnvelope<T> = {
6
+ status: 'ok';
7
+ results: T;
8
+ };
9
+ export type ApiErrorEnvelope = {
10
+ status: 'error';
11
+ error: {
12
+ statusCode: number;
13
+ name?: string;
14
+ message?: string;
15
+ [key: string]: unknown;
16
+ };
17
+ };
18
+ export type ApiEnvelope<T> = ApiErrorEnvelope | ApiSuccessEnvelope<T>;
19
+ /** Type guard for Lightdash `{ status: 'ok', results }` responses. */
20
+ export declare function isApiSuccessEnvelope<T>(data: ApiEnvelope<T>): data is ApiSuccessEnvelope<T>;
21
+ /**
22
+ * Unwraps a Lightdash success envelope to `results`.
23
+ * Throws a plain `Error` when `status` is not `ok` (message from `error.message` when present).
24
+ * Prefer `HttpClient` in production paths that need `LightdashApiError` + axios context.
25
+ */
26
+ export declare function unwrapApiSuccessResults<T>(data: ApiEnvelope<T>): T;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * Pure helpers for Lightdash API success envelopes.
4
+ * HttpClient uses `isApiSuccessEnvelope` then maps failures to `LightdashApiError`.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.isApiSuccessEnvelope = isApiSuccessEnvelope;
8
+ exports.unwrapApiSuccessResults = unwrapApiSuccessResults;
9
+ /** Type guard for Lightdash `{ status: 'ok', results }` responses. */
10
+ function isApiSuccessEnvelope(data) {
11
+ return data.status === 'ok';
12
+ }
13
+ /**
14
+ * Unwraps a Lightdash success envelope to `results`.
15
+ * Throws a plain `Error` when `status` is not `ok` (message from `error.message` when present).
16
+ * Prefer `HttpClient` in production paths that need `LightdashApiError` + axios context.
17
+ */
18
+ function unwrapApiSuccessResults(data) {
19
+ var _a;
20
+ if (!isApiSuccessEnvelope(data)) {
21
+ const message = typeof ((_a = data.error) === null || _a === void 0 ? void 0 : _a.message) === 'string' ? data.error.message : 'Lightdash API error';
22
+ throw new Error(message);
23
+ }
24
+ return data.results;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const vitest_1 = require("vitest");
4
+ const unwrap_api_success_1 = require("./unwrap-api-success");
5
+ (0, vitest_1.describe)('unwrapApiSuccessResults', () => {
6
+ (0, vitest_1.it)('returns results for ok envelopes', () => {
7
+ (0, vitest_1.expect)((0, unwrap_api_success_1.unwrapApiSuccessResults)({ status: 'ok', results: { id: '1' } })).toEqual({ id: '1' });
8
+ });
9
+ (0, vitest_1.it)('throws for error envelopes', () => {
10
+ (0, vitest_1.expect)(() => (0, unwrap_api_success_1.unwrapApiSuccessResults)({
11
+ status: 'error',
12
+ error: { statusCode: 400, message: 'bad request' },
13
+ })).toThrow(/bad request/);
14
+ });
15
+ (0, vitest_1.it)('narrows success envelopes', () => {
16
+ const body = { status: 'ok', results: [1, 2] };
17
+ (0, vitest_1.expect)((0, unwrap_api_success_1.isApiSuccessEnvelope)(body)).toBe(true);
18
+ });
19
+ });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { LightdashClient, V1ApiClients, V2ApiClients } from './client';
2
+ export { fetchBundleCurrentState, applyBundleDiff, resolveEvaluationRun, type ApplyBundleDiffFailure, type ApplyBundleDiffResult, type ResolveEvaluationRunOptions, type ResolveEvaluationRunResult, } from './agentops';
2
3
  export { UsersClient } from './api/v1/users';
3
4
  export { GroupsClient } from './api/v1/groups';
4
5
  export { OrganizationRolesClient } from './api/v2/organization-roles';
@@ -6,26 +7,35 @@ export { ProjectRoleAssignmentsClient } from './api/v2/project-role-assignments'
6
7
  export { AiAgentsClient } from './api/v1/ai-agents';
7
8
  export { ProjectAccessClient } from './api/v1/project-access';
8
9
  export { ValidationClient } from './api/v1/validation';
10
+ export { ValidationClientV2 } from './api/v2/validation';
9
11
  export { MetricsClient } from './api/v1/metrics';
10
12
  export { SchedulersClient } from './api/v1/schedulers';
11
13
  export { TagsClient } from './api/v1/tags';
14
+ export { AnalyticsClient } from './api/v1/analytics';
12
15
  export { ContentClient } from './api/v2/content';
16
+ export { ChartsClientV2 } from './api/v2/charts';
17
+ export { DashboardsClientV2 } from './api/v2/dashboards';
13
18
  export type { ListMembersParams, ListAllMembersParams } from './api/v1/users';
14
19
  export type { GetValidationResultsParams, ValidateProjectBody } from './api/v1/validation';
20
+ export type { ListValidationResultsParams } from './api/v2/validation';
15
21
  export type { ListMetricsParams } from './api/v1/metrics';
16
22
  export type { ListSchedulersParams } from './api/v1/schedulers';
17
- export type { SearchContentParams } from './api/v2/content';
23
+ export type { BulkMoveContentBody, MoveContentBody, PermanentlyDeleteContentBody, SearchContentParams, } from './api/v2/content';
24
+ export type { SavedChart } from './api/v2/charts';
25
+ export type { Dashboard, UpdateDashboardBody } from './api/v2/dashboards';
26
+ export type { DashboardPromoteDiffResults, DashboardPromoteOptions, PromoteDashboardResult, } from './api/v1/dashboards';
18
27
  export type { ListGroupsParams, ListAllGroupsParams, GetGroupParams, GroupOrGroupWithMembers, } from './api/v1/groups';
19
28
  export type { GetRolesResult, GetRolesParams, AssignOrgRoleToUserBody, } from './api/v2/organization-roles';
20
29
  export type { PartialLightdashClientConfig } from './config';
21
- export type { LightdashClientConfig, RateLimitConfig, RetryConfig, Logger, ObservabilityHooks, } from './config';
30
+ export type { LightdashClientConfig, LightdashAuthConfig, ResolvedLightdashClientConfig, RateLimitConfig, RetryConfig, Logger, ObservabilityHooks, } from './config';
22
31
  export { noopLogger, consoleLogger } from './utils/logger';
23
32
  export { DEFAULT_RATE_LIMIT, DEFAULT_TIMEOUT, DEFAULT_RETRY } from './config';
24
33
  export { LightdashApiError, RateLimitError, NetworkError } from './errors';
25
34
  export type { ApiErrorPayload } from './errors';
26
- export { loadConfigFromEnv, mergeConfig } from './utils/env';
35
+ export { loadConfigFromEnv, mergeConfig, createBearerConfig } from './utils/env';
27
36
  export { ENV_LIGHTDASH_API_KEY, ENV_LIGHTDASH_URL, ENV_LIGHTDASH_PROXY_AUTHORIZATION, } from './utils/env';
28
37
  export { HttpClient } from './http/http-client';
38
+ export { isApiSuccessEnvelope, unwrapApiSuccessResults, type ApiEnvelope, type ApiErrorEnvelope, type ApiSuccessEnvelope, } from './http/unwrap-api-success';
29
39
  export { RateLimiter } from './http/rate-limiter';
30
40
  export { SecretString } from './utils/secret-string';
31
41
  export type { ApiResponseOk, ApiResponseError, ApiResponseBody, ApiError } from './types/api';
package/dist/index.js CHANGED
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SecretString = exports.RateLimiter = exports.HttpClient = exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = exports.mergeConfig = exports.loadConfigFromEnv = exports.NetworkError = exports.RateLimitError = exports.LightdashApiError = exports.DEFAULT_RETRY = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RATE_LIMIT = exports.consoleLogger = exports.noopLogger = exports.ContentClient = exports.TagsClient = exports.SchedulersClient = exports.MetricsClient = exports.ValidationClient = exports.ProjectAccessClient = exports.AiAgentsClient = exports.ProjectRoleAssignmentsClient = exports.OrganizationRolesClient = exports.GroupsClient = exports.UsersClient = exports.V2ApiClients = exports.V1ApiClients = exports.LightdashClient = void 0;
3
+ exports.SecretString = exports.RateLimiter = exports.unwrapApiSuccessResults = exports.isApiSuccessEnvelope = exports.HttpClient = exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = exports.createBearerConfig = exports.mergeConfig = exports.loadConfigFromEnv = exports.NetworkError = exports.RateLimitError = exports.LightdashApiError = exports.DEFAULT_RETRY = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RATE_LIMIT = exports.consoleLogger = exports.noopLogger = exports.DashboardsClientV2 = exports.ChartsClientV2 = exports.ContentClient = exports.AnalyticsClient = exports.TagsClient = exports.SchedulersClient = exports.MetricsClient = exports.ValidationClientV2 = exports.ValidationClient = exports.ProjectAccessClient = exports.AiAgentsClient = exports.ProjectRoleAssignmentsClient = exports.OrganizationRolesClient = exports.GroupsClient = exports.UsersClient = exports.resolveEvaluationRun = exports.applyBundleDiff = exports.fetchBundleCurrentState = exports.V2ApiClients = exports.V1ApiClients = exports.LightdashClient = void 0;
4
4
  var client_1 = require("./client");
5
5
  Object.defineProperty(exports, "LightdashClient", { enumerable: true, get: function () { return client_1.LightdashClient; } });
6
6
  Object.defineProperty(exports, "V1ApiClients", { enumerable: true, get: function () { return client_1.V1ApiClients; } });
7
7
  Object.defineProperty(exports, "V2ApiClients", { enumerable: true, get: function () { return client_1.V2ApiClients; } });
8
+ var agentops_1 = require("./agentops");
9
+ Object.defineProperty(exports, "fetchBundleCurrentState", { enumerable: true, get: function () { return agentops_1.fetchBundleCurrentState; } });
10
+ Object.defineProperty(exports, "applyBundleDiff", { enumerable: true, get: function () { return agentops_1.applyBundleDiff; } });
11
+ Object.defineProperty(exports, "resolveEvaluationRun", { enumerable: true, get: function () { return agentops_1.resolveEvaluationRun; } });
8
12
  var users_1 = require("./api/v1/users");
9
13
  Object.defineProperty(exports, "UsersClient", { enumerable: true, get: function () { return users_1.UsersClient; } });
10
14
  var groups_1 = require("./api/v1/groups");
@@ -19,14 +23,22 @@ var project_access_1 = require("./api/v1/project-access");
19
23
  Object.defineProperty(exports, "ProjectAccessClient", { enumerable: true, get: function () { return project_access_1.ProjectAccessClient; } });
20
24
  var validation_1 = require("./api/v1/validation");
21
25
  Object.defineProperty(exports, "ValidationClient", { enumerable: true, get: function () { return validation_1.ValidationClient; } });
26
+ var validation_2 = require("./api/v2/validation");
27
+ Object.defineProperty(exports, "ValidationClientV2", { enumerable: true, get: function () { return validation_2.ValidationClientV2; } });
22
28
  var metrics_1 = require("./api/v1/metrics");
23
29
  Object.defineProperty(exports, "MetricsClient", { enumerable: true, get: function () { return metrics_1.MetricsClient; } });
24
30
  var schedulers_1 = require("./api/v1/schedulers");
25
31
  Object.defineProperty(exports, "SchedulersClient", { enumerable: true, get: function () { return schedulers_1.SchedulersClient; } });
26
32
  var tags_1 = require("./api/v1/tags");
27
33
  Object.defineProperty(exports, "TagsClient", { enumerable: true, get: function () { return tags_1.TagsClient; } });
34
+ var analytics_1 = require("./api/v1/analytics");
35
+ Object.defineProperty(exports, "AnalyticsClient", { enumerable: true, get: function () { return analytics_1.AnalyticsClient; } });
28
36
  var content_1 = require("./api/v2/content");
29
37
  Object.defineProperty(exports, "ContentClient", { enumerable: true, get: function () { return content_1.ContentClient; } });
38
+ var charts_1 = require("./api/v2/charts");
39
+ Object.defineProperty(exports, "ChartsClientV2", { enumerable: true, get: function () { return charts_1.ChartsClientV2; } });
40
+ var dashboards_1 = require("./api/v2/dashboards");
41
+ Object.defineProperty(exports, "DashboardsClientV2", { enumerable: true, get: function () { return dashboards_1.DashboardsClientV2; } });
30
42
  var logger_1 = require("./utils/logger");
31
43
  Object.defineProperty(exports, "noopLogger", { enumerable: true, get: function () { return logger_1.noopLogger; } });
32
44
  Object.defineProperty(exports, "consoleLogger", { enumerable: true, get: function () { return logger_1.consoleLogger; } });
@@ -41,12 +53,16 @@ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function
41
53
  var env_1 = require("./utils/env");
42
54
  Object.defineProperty(exports, "loadConfigFromEnv", { enumerable: true, get: function () { return env_1.loadConfigFromEnv; } });
43
55
  Object.defineProperty(exports, "mergeConfig", { enumerable: true, get: function () { return env_1.mergeConfig; } });
56
+ Object.defineProperty(exports, "createBearerConfig", { enumerable: true, get: function () { return env_1.createBearerConfig; } });
44
57
  var env_2 = require("./utils/env");
45
58
  Object.defineProperty(exports, "ENV_LIGHTDASH_API_KEY", { enumerable: true, get: function () { return env_2.ENV_LIGHTDASH_API_KEY; } });
46
59
  Object.defineProperty(exports, "ENV_LIGHTDASH_URL", { enumerable: true, get: function () { return env_2.ENV_LIGHTDASH_URL; } });
47
60
  Object.defineProperty(exports, "ENV_LIGHTDASH_PROXY_AUTHORIZATION", { enumerable: true, get: function () { return env_2.ENV_LIGHTDASH_PROXY_AUTHORIZATION; } });
48
61
  var http_client_1 = require("./http/http-client");
49
62
  Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return http_client_1.HttpClient; } });
63
+ var unwrap_api_success_1 = require("./http/unwrap-api-success");
64
+ Object.defineProperty(exports, "isApiSuccessEnvelope", { enumerable: true, get: function () { return unwrap_api_success_1.isApiSuccessEnvelope; } });
65
+ Object.defineProperty(exports, "unwrapApiSuccessResults", { enumerable: true, get: function () { return unwrap_api_success_1.unwrapApiSuccessResults; } });
50
66
  var rate_limiter_1 = require("./http/rate-limiter");
51
67
  Object.defineProperty(exports, "RateLimiter", { enumerable: true, get: function () { return rate_limiter_1.RateLimiter; } });
52
68
  var secret_string_1 = require("./utils/secret-string");
@@ -18,8 +18,16 @@ const index_1 = require("./index");
18
18
  });
19
19
  (0, vitest_1.expect)(client.getHttpClientV1()).toBeDefined();
20
20
  });
21
- (0, vitest_1.it)('should throw when baseUrl and personalAccessToken are missing and not in env', () => {
22
- (0, vitest_1.expect)(() => new index_1.LightdashClient({})).toThrow(/baseUrl and personalAccessToken|LIGHTDASH_URL and LIGHTDASH_API_KEY/);
21
+ (0, vitest_1.it)('allows deprecated personalAccessToken-only exported config shape', () => {
22
+ var _a;
23
+ const cfg = {
24
+ baseUrl: 'https://app.lightdash.cloud',
25
+ personalAccessToken: new index_1.SecretString('pat'),
26
+ };
27
+ (0, vitest_1.expect)((_a = cfg.personalAccessToken) === null || _a === void 0 ? void 0 : _a.expose()).toBe('pat');
28
+ });
29
+ (0, vitest_1.it)('should throw when baseUrl and auth credentials are missing and not in env', () => {
30
+ (0, vitest_1.expect)(() => new index_1.LightdashClient({})).toThrow(/baseUrl|auth credentials|LIGHTDASH_URL/);
23
31
  });
24
32
  (0, vitest_1.it)('should merge explicit config with env (explicit wins)', () => {
25
33
  vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_URL, 'https://env.example.com');
@@ -30,8 +38,8 @@ const index_1 = require("./index");
30
38
  };
31
39
  const merged = (0, index_1.mergeConfig)(explicit);
32
40
  (0, vitest_1.expect)(merged.baseUrl).toBe('https://custom.example.com');
33
- (0, vitest_1.expect)(merged.personalAccessToken).toBeInstanceOf(index_1.SecretString);
34
- (0, vitest_1.expect)(merged.personalAccessToken.expose()).toBe('explicit-token');
41
+ (0, vitest_1.expect)(merged.auth.token).toBeInstanceOf(index_1.SecretString);
42
+ (0, vitest_1.expect)(merged.auth.token.expose()).toBe('explicit-token');
35
43
  });
36
44
  });
37
45
  (0, vitest_1.describe)('mergeConfig', () => {
@@ -40,7 +48,7 @@ const index_1 = require("./index");
40
48
  vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_URL, '');
41
49
  vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_PROXY_AUTHORIZATION, '');
42
50
  });
43
- (0, vitest_1.it)('should require baseUrl and personalAccessToken', () => {
51
+ (0, vitest_1.it)('should require baseUrl and auth credentials', () => {
44
52
  (0, vitest_1.expect)(() => (0, index_1.mergeConfig)({})).toThrow();
45
53
  (0, vitest_1.expect)(() => (0, index_1.mergeConfig)({ baseUrl: 'https://x.com' })).toThrow();
46
54
  (0, vitest_1.expect)(() => (0, index_1.mergeConfig)({ personalAccessToken: 't' })).toThrow();
@@ -2,15 +2,6 @@
2
2
  /**
3
3
  * Generic helper to fetch all pages of a Knex-paginated API and return a single array.
4
4
  */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.fetchAllPages = fetchAllPages;
16
7
  const DEFAULT_PAGE_SIZE = 100;
@@ -18,24 +9,22 @@ const DEFAULT_PAGE_SIZE = 100;
18
9
  * Fetches all pages by repeatedly calling fetchPage until no more pages, then returns
19
10
  * the concatenated data array.
20
11
  */
21
- function fetchAllPages(options) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- var _a;
24
- const pageSize = (_a = options.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
25
- const all = [];
26
- let page = 1;
27
- let totalPageCount;
28
- do {
29
- const result = yield options.fetchPage(page, pageSize);
30
- all.push(...result.data);
31
- if (result.pagination) {
32
- totalPageCount = result.pagination.totalPageCount;
33
- page += 1;
34
- }
35
- else {
36
- totalPageCount = undefined;
37
- }
38
- } while (totalPageCount !== undefined && page <= totalPageCount);
39
- return all;
40
- });
12
+ async function fetchAllPages(options) {
13
+ var _a;
14
+ const pageSize = (_a = options.pageSize) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_SIZE;
15
+ const all = [];
16
+ let page = 1;
17
+ let totalPageCount;
18
+ do {
19
+ const result = await options.fetchPage(page, pageSize);
20
+ all.push(...result.data);
21
+ if (result.pagination) {
22
+ totalPageCount = result.pagination.totalPageCount;
23
+ page += 1;
24
+ }
25
+ else {
26
+ totalPageCount = undefined;
27
+ }
28
+ } while (totalPageCount !== undefined && page <= totalPageCount);
29
+ return all;
41
30
  }