@lightdash-tools/client 0.7.0 → 0.9.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 (77) hide show
  1. package/dist/api/v1/ai-agents/discovery.d.ts +7 -2
  2. package/dist/api/v1/ai-agents/discovery.js +3 -6
  3. package/dist/api/v1/ai-agents/discovery.test.js +17 -1
  4. package/dist/api/v1/ai-agents/facade.d.ts +5 -0
  5. package/dist/api/v1/ai-agents/facade.js +5 -2
  6. package/dist/api/v1/charts.d.ts +28 -1
  7. package/dist/api/v1/charts.js +51 -1
  8. package/dist/api/v1/charts.test.js +59 -6
  9. package/dist/api/v1/dashboards.d.ts +32 -1
  10. package/dist/api/v1/dashboards.js +20 -0
  11. package/dist/api/v1/dashboards.test.js +72 -0
  12. package/dist/api/v1/validation.d.ts +5 -1
  13. package/dist/api/v1/validation.js +8 -0
  14. package/dist/api/v1/validation.test.js +16 -0
  15. package/dist/api/v2/charts.d.ts +12 -0
  16. package/dist/api/v2/charts.js +18 -0
  17. package/dist/api/v2/charts.test.d.ts +4 -0
  18. package/dist/api/v2/charts.test.js +45 -0
  19. package/dist/api/v2/content.d.ts +19 -2
  20. package/dist/api/v2/content.js +15 -0
  21. package/dist/api/v2/content.test.js +41 -0
  22. package/dist/api/v2/dashboards.d.ts +7 -1
  23. package/dist/api/v2/dashboards.js +9 -1
  24. package/dist/api/v2/dashboards.test.js +34 -0
  25. package/dist/api/v2/parameters.d.ts +20 -0
  26. package/dist/api/v2/parameters.js +22 -0
  27. package/dist/api/v2/parameters.test.d.ts +4 -0
  28. package/dist/api/v2/parameters.test.js +39 -0
  29. package/dist/api/v2/query.d.ts +16 -1
  30. package/dist/api/v2/query.js +16 -0
  31. package/dist/api/v2/query.test.js +16 -0
  32. package/dist/client.d.ts +4 -0
  33. package/dist/client.js +4 -0
  34. package/dist/client.test.js +2 -0
  35. package/dist/errors.d.ts +22 -0
  36. package/dist/errors.js +37 -1
  37. package/dist/http/http-client.binary-url.test.d.ts +4 -0
  38. package/dist/http/http-client.binary-url.test.js +61 -0
  39. package/dist/http/http-client.d.ts +23 -11
  40. package/dist/http/http-client.envelope.test.d.ts +4 -0
  41. package/dist/http/http-client.envelope.test.js +59 -0
  42. package/dist/http/http-client.js +155 -6
  43. package/dist/http/unwrap-api-success.d.ts +26 -0
  44. package/dist/http/unwrap-api-success.js +25 -0
  45. package/dist/http/unwrap-api-success.test.d.ts +1 -0
  46. package/dist/http/unwrap-api-success.test.js +19 -0
  47. package/dist/index.d.ts +9 -2
  48. package/dist/index.js +17 -3
  49. package/package.json +2 -2
  50. package/src/api/v1/ai-agents/discovery.test.ts +19 -1
  51. package/src/api/v1/ai-agents/discovery.ts +17 -3
  52. package/src/api/v1/ai-agents/facade.ts +17 -1
  53. package/src/api/v1/charts.test.ts +61 -1
  54. package/src/api/v1/charts.ts +68 -0
  55. package/src/api/v1/dashboards.test.ts +85 -0
  56. package/src/api/v1/dashboards.ts +86 -0
  57. package/src/api/v1/validation.test.ts +18 -0
  58. package/src/api/v1/validation.ts +21 -1
  59. package/src/api/v2/charts.test.ts +53 -0
  60. package/src/api/v2/charts.ts +23 -0
  61. package/src/api/v2/content.test.ts +45 -0
  62. package/src/api/v2/content.ts +35 -2
  63. package/src/api/v2/dashboards.test.ts +39 -0
  64. package/src/api/v2/dashboards.ts +23 -1
  65. package/src/api/v2/parameters.test.ts +45 -0
  66. package/src/api/v2/parameters.ts +38 -0
  67. package/src/api/v2/query.test.ts +18 -0
  68. package/src/api/v2/query.ts +53 -0
  69. package/src/client.test.ts +2 -0
  70. package/src/client.ts +6 -0
  71. package/src/errors.ts +46 -0
  72. package/src/http/http-client.binary-url.test.ts +88 -0
  73. package/src/http/http-client.envelope.test.ts +74 -0
  74. package/src/http/http-client.ts +194 -16
  75. package/src/http/unwrap-api-success.test.ts +23 -0
  76. package/src/http/unwrap-api-success.ts +40 -0
  77. package/src/index.ts +40 -2
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Pure helpers for Lightdash API success envelopes.
3
+ * HttpClient uses `isApiSuccessEnvelope` then maps failures to `LightdashApiError`.
4
+ */
5
+
6
+ export type ApiSuccessEnvelope<T> = {
7
+ status: 'ok';
8
+ results: T;
9
+ };
10
+
11
+ export type ApiErrorEnvelope = {
12
+ status: 'error';
13
+ error: {
14
+ statusCode: number;
15
+ name?: string;
16
+ message?: string;
17
+ [key: string]: unknown;
18
+ };
19
+ };
20
+
21
+ export type ApiEnvelope<T> = ApiErrorEnvelope | ApiSuccessEnvelope<T>;
22
+
23
+ /** Type guard for Lightdash `{ status: 'ok', results }` responses. */
24
+ export function isApiSuccessEnvelope<T>(data: ApiEnvelope<T>): data is ApiSuccessEnvelope<T> {
25
+ return data.status === 'ok';
26
+ }
27
+
28
+ /**
29
+ * Unwraps a Lightdash success envelope to `results`.
30
+ * Throws a plain `Error` when `status` is not `ok` (message from `error.message` when present).
31
+ * Prefer `HttpClient` in production paths that need `LightdashApiError` + axios context.
32
+ */
33
+ export function unwrapApiSuccessResults<T>(data: ApiEnvelope<T>): T {
34
+ if (!isApiSuccessEnvelope(data)) {
35
+ const message =
36
+ typeof data.error?.message === 'string' ? data.error.message : 'Lightdash API error';
37
+ throw new Error(message);
38
+ }
39
+ return data.results;
40
+ }
package/src/index.ts CHANGED
@@ -21,13 +21,26 @@ export { SchedulersClient } from './api/v1/schedulers';
21
21
  export { TagsClient } from './api/v1/tags';
22
22
  export { AnalyticsClient } from './api/v1/analytics';
23
23
  export { ContentClient } from './api/v2/content';
24
+ export { ChartsClientV2 } from './api/v2/charts';
24
25
  export { DashboardsClientV2 } from './api/v2/dashboards';
25
26
  export type { ListMembersParams, ListAllMembersParams } from './api/v1/users';
26
27
  export type { GetValidationResultsParams, ValidateProjectBody } from './api/v1/validation';
27
28
  export type { ListValidationResultsParams } from './api/v2/validation';
28
29
  export type { ListMetricsParams } from './api/v1/metrics';
29
30
  export type { ListSchedulersParams } from './api/v1/schedulers';
30
- export type { SearchContentParams } from './api/v2/content';
31
+ export type {
32
+ BulkMoveContentBody,
33
+ MoveContentBody,
34
+ PermanentlyDeleteContentBody,
35
+ SearchContentParams,
36
+ } from './api/v2/content';
37
+ export type { SavedChart } from './api/v2/charts';
38
+ export type { Dashboard, UpdateDashboardBody } from './api/v2/dashboards';
39
+ export type {
40
+ DashboardPromoteDiffResults,
41
+ DashboardPromoteOptions,
42
+ PromoteDashboardResult,
43
+ } from './api/v1/dashboards';
31
44
  export type {
32
45
  ListGroupsParams,
33
46
  ListAllGroupsParams,
@@ -51,8 +64,26 @@ export type {
51
64
  } from './config';
52
65
  export { noopLogger, consoleLogger } from './utils/logger';
53
66
  export { DEFAULT_RATE_LIMIT, DEFAULT_TIMEOUT, DEFAULT_RETRY } from './config';
54
- export { LightdashApiError, RateLimitError, NetworkError } from './errors';
67
+ export {
68
+ LightdashApiError,
69
+ RateLimitError,
70
+ NetworkError,
71
+ ChartImageSizeError,
72
+ CONTRACT_ERROR_NAME,
73
+ CONTRACT_ERROR_MESSAGE,
74
+ } from './errors';
55
75
  export type { ApiErrorPayload } from './errors';
76
+ export {
77
+ CHART_IMAGE_EXPORT_TIMEOUT_MS,
78
+ CHART_IMAGE_MAX_BYTES,
79
+ type ChartImagePng,
80
+ } from './api/v1/charts';
81
+ export {
82
+ DEFAULT_BINARY_MAX_BYTES,
83
+ isBlockedBinaryHostname,
84
+ type GetBytesOptions,
85
+ type GetBytesResult,
86
+ } from './http/http-client';
56
87
  export { loadConfigFromEnv, mergeConfig, createBearerConfig } from './utils/env';
57
88
  export {
58
89
  ENV_LIGHTDASH_API_KEY,
@@ -60,6 +91,13 @@ export {
60
91
  ENV_LIGHTDASH_PROXY_AUTHORIZATION,
61
92
  } from './utils/env';
62
93
  export { HttpClient } from './http/http-client';
94
+ export {
95
+ isApiSuccessEnvelope,
96
+ unwrapApiSuccessResults,
97
+ type ApiEnvelope,
98
+ type ApiErrorEnvelope,
99
+ type ApiSuccessEnvelope,
100
+ } from './http/unwrap-api-success';
63
101
  export { RateLimiter } from './http/rate-limiter';
64
102
  export { SecretString } from './utils/secret-string';
65
103
  export type { ApiResponseOk, ApiResponseError, ApiResponseBody, ApiError } from './types/api';