@lightdash-tools/client 0.1.1 → 0.2.1
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.
- package/README.md +14 -1
- package/dist/api/v1/explores.d.ts +4 -0
- package/dist/api/v1/explores.js +19 -0
- package/dist/api/v1/explores.test.js +32 -0
- package/dist/api/v1/metrics.d.ts +23 -0
- package/dist/api/v1/metrics.js +31 -0
- package/dist/api/v1/metrics.test.d.ts +1 -0
- package/dist/api/v1/metrics.test.js +43 -0
- package/dist/api/v1/schedulers.d.ts +25 -0
- package/dist/api/v1/schedulers.js +31 -0
- package/dist/api/v1/schedulers.test.d.ts +1 -0
- package/dist/api/v1/schedulers.test.js +43 -0
- package/dist/api/v1/tags.d.ts +11 -0
- package/dist/api/v1/tags.js +31 -0
- package/dist/api/v1/tags.test.d.ts +1 -0
- package/dist/api/v1/tags.test.js +41 -0
- package/dist/api/v1/validation.d.ts +22 -0
- package/dist/api/v1/validation.js +31 -0
- package/dist/api/v1/validation.test.d.ts +1 -0
- package/dist/api/v1/validation.test.js +43 -0
- package/dist/api/v2/content.d.ts +21 -0
- package/dist/api/v2/content.js +27 -0
- package/dist/api/v2/content.test.d.ts +1 -0
- package/dist/api/v2/content.test.js +35 -0
- package/dist/client.d.ts +30 -0
- package/dist/client.js +15 -0
- package/dist/config.d.ts +7 -3
- package/dist/http/interceptors.js +3 -4
- package/dist/index.d.ts +10 -0
- package/dist/index.js +13 -1
- package/dist/index.test.js +21 -3
- package/dist/utils/env.js +6 -4
- package/dist/utils/env.test.js +2 -2
- package/dist/utils/secret-string.d.ts +21 -0
- package/dist/utils/secret-string.js +38 -0
- package/package.json +2 -2
- package/src/api/v1/explores.test.ts +34 -0
- package/src/api/v1/explores.ts +20 -1
- package/src/api/v1/metrics.test.ts +37 -0
- package/src/api/v1/metrics.ts +43 -0
- package/src/api/v1/schedulers.test.ts +37 -0
- package/src/api/v1/schedulers.ts +43 -0
- package/src/api/v1/tags.test.ts +35 -0
- package/src/api/v1/tags.ts +20 -0
- package/src/api/v1/validation.test.ts +37 -0
- package/src/api/v1/validation.ts +43 -0
- package/src/api/v2/content.test.ts +28 -0
- package/src/api/v2/content.ts +30 -0
- package/src/client.ts +40 -0
- package/src/config.ts +9 -14
- package/src/http/interceptors.ts +3 -4
- package/src/index.test.ts +30 -4
- package/src/index.ts +10 -0
- package/src/utils/env.test.ts +2 -2
- package/src/utils/env.ts +6 -4
- package/src/utils/secret-string.ts +36 -0
package/dist/client.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ import { GroupsClient } from './api/v1/groups';
|
|
|
17
17
|
import { AiAgentsClient } from './api/v1/ai-agents';
|
|
18
18
|
import { ProjectAccessClient } from './api/v1/project-access';
|
|
19
19
|
import { ExploresClient } from './api/v1/explores';
|
|
20
|
+
import { ValidationClient } from './api/v1/validation';
|
|
21
|
+
import { MetricsClient } from './api/v1/metrics';
|
|
22
|
+
import { SchedulersClient } from './api/v1/schedulers';
|
|
23
|
+
import { TagsClient } from './api/v1/tags';
|
|
24
|
+
import { ContentClient } from './api/v2/content';
|
|
20
25
|
/**
|
|
21
26
|
* V1 API clients namespace. Contains all v1 API clients.
|
|
22
27
|
*/
|
|
@@ -32,6 +37,10 @@ export declare class V1ApiClients {
|
|
|
32
37
|
readonly aiAgents: AiAgentsClient;
|
|
33
38
|
readonly projectAccess: ProjectAccessClient;
|
|
34
39
|
readonly explores: ExploresClient;
|
|
40
|
+
readonly validation: ValidationClient;
|
|
41
|
+
readonly metrics: MetricsClient;
|
|
42
|
+
readonly schedulers: SchedulersClient;
|
|
43
|
+
readonly tags: TagsClient;
|
|
35
44
|
constructor(http: HttpClient);
|
|
36
45
|
}
|
|
37
46
|
/**
|
|
@@ -41,6 +50,7 @@ export declare class V2ApiClients {
|
|
|
41
50
|
readonly query: QueryClientV2;
|
|
42
51
|
readonly organizationRoles: OrganizationRolesClient;
|
|
43
52
|
readonly projectRoleAssignments: ProjectRoleAssignmentsClient;
|
|
53
|
+
readonly content: ContentClient;
|
|
44
54
|
constructor(http: HttpClient);
|
|
45
55
|
}
|
|
46
56
|
/**
|
|
@@ -101,6 +111,26 @@ export declare class LightdashClient {
|
|
|
101
111
|
* @deprecated Use `client.v1.explores` instead. This alias will be removed in a future major version.
|
|
102
112
|
*/
|
|
103
113
|
readonly explores: ExploresClient;
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated Use `client.v1.validation` instead. This alias will be removed in a future major version.
|
|
116
|
+
*/
|
|
117
|
+
readonly validation: ValidationClient;
|
|
118
|
+
/**
|
|
119
|
+
* @deprecated Use `client.v1.metrics` instead. This alias will be removed in a future major version.
|
|
120
|
+
*/
|
|
121
|
+
readonly metrics: MetricsClient;
|
|
122
|
+
/**
|
|
123
|
+
* @deprecated Use `client.v1.schedulers` instead. This alias will be removed in a future major version.
|
|
124
|
+
*/
|
|
125
|
+
readonly schedulers: SchedulersClient;
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated Use `client.v1.tags` instead. This alias will be removed in a future major version.
|
|
128
|
+
*/
|
|
129
|
+
readonly tags: TagsClient;
|
|
130
|
+
/**
|
|
131
|
+
* @deprecated Use `client.v2.content` instead. This alias will be removed in a future major version.
|
|
132
|
+
*/
|
|
133
|
+
readonly content: ContentClient;
|
|
104
134
|
constructor(config?: PartialLightdashClientConfig);
|
|
105
135
|
/**
|
|
106
136
|
* Low-level HTTP client for custom v1 requests. Prefer domain methods (e.g. v1.projects, v1.charts) when available.
|
package/dist/client.js
CHANGED
|
@@ -22,6 +22,11 @@ const groups_1 = require("./api/v1/groups");
|
|
|
22
22
|
const ai_agents_1 = require("./api/v1/ai-agents");
|
|
23
23
|
const project_access_1 = require("./api/v1/project-access");
|
|
24
24
|
const explores_1 = require("./api/v1/explores");
|
|
25
|
+
const validation_1 = require("./api/v1/validation");
|
|
26
|
+
const metrics_1 = require("./api/v1/metrics");
|
|
27
|
+
const schedulers_1 = require("./api/v1/schedulers");
|
|
28
|
+
const tags_1 = require("./api/v1/tags");
|
|
29
|
+
const content_1 = require("./api/v2/content");
|
|
25
30
|
/**
|
|
26
31
|
* V1 API clients namespace. Contains all v1 API clients.
|
|
27
32
|
*/
|
|
@@ -38,6 +43,10 @@ class V1ApiClients {
|
|
|
38
43
|
this.aiAgents = new ai_agents_1.AiAgentsClient(http);
|
|
39
44
|
this.projectAccess = new project_access_1.ProjectAccessClient(http);
|
|
40
45
|
this.explores = new explores_1.ExploresClient(http);
|
|
46
|
+
this.validation = new validation_1.ValidationClient(http);
|
|
47
|
+
this.metrics = new metrics_1.MetricsClient(http);
|
|
48
|
+
this.schedulers = new schedulers_1.SchedulersClient(http);
|
|
49
|
+
this.tags = new tags_1.TagsClient(http);
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
52
|
exports.V1ApiClients = V1ApiClients;
|
|
@@ -49,6 +58,7 @@ class V2ApiClients {
|
|
|
49
58
|
this.query = new query_2.QueryClientV2(http);
|
|
50
59
|
this.organizationRoles = new organization_roles_1.OrganizationRolesClient(http);
|
|
51
60
|
this.projectRoleAssignments = new project_role_assignments_1.ProjectRoleAssignmentsClient(http);
|
|
61
|
+
this.content = new content_1.ContentClient(http);
|
|
52
62
|
}
|
|
53
63
|
}
|
|
54
64
|
exports.V2ApiClients = V2ApiClients;
|
|
@@ -89,6 +99,11 @@ class LightdashClient {
|
|
|
89
99
|
this.groups = this.v1.groups;
|
|
90
100
|
this.aiAgents = this.v1.aiAgents;
|
|
91
101
|
this.explores = this.v1.explores;
|
|
102
|
+
this.validation = this.v1.validation;
|
|
103
|
+
this.metrics = this.v1.metrics;
|
|
104
|
+
this.schedulers = this.v1.schedulers;
|
|
105
|
+
this.tags = this.v1.tags;
|
|
106
|
+
this.content = this.v2.content;
|
|
92
107
|
}
|
|
93
108
|
/**
|
|
94
109
|
* Low-level HTTP client for custom v1 requests. Prefer domain methods (e.g. v1.projects, v1.charts) when available.
|
package/dist/config.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Configuration types for the Lightdash HTTP client.
|
|
3
3
|
* Supports explicit config and environment variables (LIGHTDASH_API_KEY, LIGHTDASH_URL, LIGHTDASH_PROXY_AUTHORIZATION).
|
|
4
4
|
*/
|
|
5
|
+
import type { SecretString } from './utils/secret-string';
|
|
5
6
|
/**
|
|
6
7
|
* Rate limit configuration for Bottleneck (token bucket algorithm).
|
|
7
8
|
*/
|
|
@@ -56,9 +57,9 @@ export interface LightdashClientConfig {
|
|
|
56
57
|
/** Lightdash server base URL (e.g. https://app.lightdash.cloud). */
|
|
57
58
|
baseUrl: string;
|
|
58
59
|
/** Personal access token for API authentication (without ldpat_ prefix). */
|
|
59
|
-
personalAccessToken:
|
|
60
|
+
personalAccessToken: SecretString;
|
|
60
61
|
/** Optional proxy authorization header value for proxied access. */
|
|
61
|
-
proxyAuthorization?:
|
|
62
|
+
proxyAuthorization?: SecretString;
|
|
62
63
|
/** Override default rate limits. */
|
|
63
64
|
rateLimit?: RateLimitConfig;
|
|
64
65
|
/** Request timeout in milliseconds. Default 30000. */
|
|
@@ -74,7 +75,10 @@ export interface LightdashClientConfig {
|
|
|
74
75
|
* Partial config for merging with environment variables.
|
|
75
76
|
* Used when constructing the client with optional explicit overrides.
|
|
76
77
|
*/
|
|
77
|
-
export type PartialLightdashClientConfig = Partial<
|
|
78
|
+
export type PartialLightdashClientConfig = Partial<Omit<LightdashClientConfig, 'personalAccessToken' | 'proxyAuthorization'>> & {
|
|
79
|
+
personalAccessToken?: string | SecretString;
|
|
80
|
+
proxyAuthorization?: string | SecretString;
|
|
81
|
+
};
|
|
78
82
|
/** Default rate limit: 10 req/sec, 5 concurrent, token bucket. */
|
|
79
83
|
export declare const DEFAULT_RATE_LIMIT: Required<RateLimitConfig>;
|
|
80
84
|
/** Default request timeout in ms. */
|
|
@@ -18,12 +18,11 @@ function getRetryAfterSeconds(value) {
|
|
|
18
18
|
function attachRequestInterceptors(axiosInstance, config) {
|
|
19
19
|
axiosInstance.interceptors.request.use((req) => {
|
|
20
20
|
var _a;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
: `ldpat_${config.personalAccessToken}`;
|
|
21
|
+
const rawToken = config.personalAccessToken.expose();
|
|
22
|
+
const token = rawToken.startsWith('ldpat_') ? rawToken : `ldpat_${rawToken}`;
|
|
24
23
|
req.headers.Authorization = `ApiKey ${token}`;
|
|
25
24
|
if (config.proxyAuthorization) {
|
|
26
|
-
req.headers['Proxy-Authorization'] = config.proxyAuthorization;
|
|
25
|
+
req.headers['Proxy-Authorization'] = config.proxyAuthorization.expose();
|
|
27
26
|
}
|
|
28
27
|
req._lightdashStartTime =
|
|
29
28
|
Date.now();
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,16 @@ export { OrganizationRolesClient } from './api/v2/organization-roles';
|
|
|
5
5
|
export { ProjectRoleAssignmentsClient } from './api/v2/project-role-assignments';
|
|
6
6
|
export { AiAgentsClient } from './api/v1/ai-agents';
|
|
7
7
|
export { ProjectAccessClient } from './api/v1/project-access';
|
|
8
|
+
export { ValidationClient } from './api/v1/validation';
|
|
9
|
+
export { MetricsClient } from './api/v1/metrics';
|
|
10
|
+
export { SchedulersClient } from './api/v1/schedulers';
|
|
11
|
+
export { TagsClient } from './api/v1/tags';
|
|
12
|
+
export { ContentClient } from './api/v2/content';
|
|
8
13
|
export type { ListMembersParams, ListAllMembersParams } from './api/v1/users';
|
|
14
|
+
export type { GetValidationResultsParams, ValidateProjectBody } from './api/v1/validation';
|
|
15
|
+
export type { ListMetricsParams } from './api/v1/metrics';
|
|
16
|
+
export type { ListSchedulersParams } from './api/v1/schedulers';
|
|
17
|
+
export type { SearchContentParams } from './api/v2/content';
|
|
9
18
|
export type { ListGroupsParams, ListAllGroupsParams, GetGroupParams, GroupOrGroupWithMembers, } from './api/v1/groups';
|
|
10
19
|
export type { GetRolesResult, GetRolesParams, AssignOrgRoleToUserBody, } from './api/v2/organization-roles';
|
|
11
20
|
export type { PartialLightdashClientConfig } from './config';
|
|
@@ -18,5 +27,6 @@ export { loadConfigFromEnv, mergeConfig } from './utils/env';
|
|
|
18
27
|
export { ENV_LIGHTDASH_API_KEY, ENV_LIGHTDASH_URL, ENV_LIGHTDASH_PROXY_AUTHORIZATION, } from './utils/env';
|
|
19
28
|
export { HttpClient } from './http/http-client';
|
|
20
29
|
export { RateLimiter } from './http/rate-limiter';
|
|
30
|
+
export { SecretString } from './utils/secret-string';
|
|
21
31
|
export type { ApiResponseOk, ApiResponseError, ApiResponseBody, ApiError } from './types/api';
|
|
22
32
|
export type { paths, components, operations } from './types/api';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.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.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;
|
|
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; } });
|
|
@@ -17,6 +17,16 @@ var ai_agents_1 = require("./api/v1/ai-agents");
|
|
|
17
17
|
Object.defineProperty(exports, "AiAgentsClient", { enumerable: true, get: function () { return ai_agents_1.AiAgentsClient; } });
|
|
18
18
|
var project_access_1 = require("./api/v1/project-access");
|
|
19
19
|
Object.defineProperty(exports, "ProjectAccessClient", { enumerable: true, get: function () { return project_access_1.ProjectAccessClient; } });
|
|
20
|
+
var validation_1 = require("./api/v1/validation");
|
|
21
|
+
Object.defineProperty(exports, "ValidationClient", { enumerable: true, get: function () { return validation_1.ValidationClient; } });
|
|
22
|
+
var metrics_1 = require("./api/v1/metrics");
|
|
23
|
+
Object.defineProperty(exports, "MetricsClient", { enumerable: true, get: function () { return metrics_1.MetricsClient; } });
|
|
24
|
+
var schedulers_1 = require("./api/v1/schedulers");
|
|
25
|
+
Object.defineProperty(exports, "SchedulersClient", { enumerable: true, get: function () { return schedulers_1.SchedulersClient; } });
|
|
26
|
+
var tags_1 = require("./api/v1/tags");
|
|
27
|
+
Object.defineProperty(exports, "TagsClient", { enumerable: true, get: function () { return tags_1.TagsClient; } });
|
|
28
|
+
var content_1 = require("./api/v2/content");
|
|
29
|
+
Object.defineProperty(exports, "ContentClient", { enumerable: true, get: function () { return content_1.ContentClient; } });
|
|
20
30
|
var logger_1 = require("./utils/logger");
|
|
21
31
|
Object.defineProperty(exports, "noopLogger", { enumerable: true, get: function () { return logger_1.noopLogger; } });
|
|
22
32
|
Object.defineProperty(exports, "consoleLogger", { enumerable: true, get: function () { return logger_1.consoleLogger; } });
|
|
@@ -39,3 +49,5 @@ var http_client_1 = require("./http/http-client");
|
|
|
39
49
|
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return http_client_1.HttpClient; } });
|
|
40
50
|
var rate_limiter_1 = require("./http/rate-limiter");
|
|
41
51
|
Object.defineProperty(exports, "RateLimiter", { enumerable: true, get: function () { return rate_limiter_1.RateLimiter; } });
|
|
52
|
+
var secret_string_1 = require("./utils/secret-string");
|
|
53
|
+
Object.defineProperty(exports, "SecretString", { enumerable: true, get: function () { return secret_string_1.SecretString; } });
|
package/dist/index.test.js
CHANGED
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const index_1 = require("./index");
|
|
5
5
|
(0, vitest_1.describe)('LightdashClient', () => {
|
|
6
|
+
(0, vitest_1.beforeEach)(() => {
|
|
7
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_API_KEY, '');
|
|
8
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_URL, '');
|
|
9
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_PROXY_AUTHORIZATION, '');
|
|
10
|
+
});
|
|
6
11
|
(0, vitest_1.it)('should export LightdashClient', () => {
|
|
7
12
|
(0, vitest_1.expect)(index_1.LightdashClient).toBeDefined();
|
|
8
13
|
});
|
|
@@ -16,16 +21,24 @@ const index_1 = require("./index");
|
|
|
16
21
|
(0, vitest_1.it)('should throw when baseUrl and personalAccessToken are missing and not in env', () => {
|
|
17
22
|
(0, vitest_1.expect)(() => new index_1.LightdashClient({})).toThrow(/baseUrl and personalAccessToken|LIGHTDASH_URL and LIGHTDASH_API_KEY/);
|
|
18
23
|
});
|
|
19
|
-
});
|
|
20
|
-
(0, vitest_1.describe)('mergeConfig', () => {
|
|
21
24
|
(0, vitest_1.it)('should merge explicit config with env (explicit wins)', () => {
|
|
25
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_URL, 'https://env.example.com');
|
|
26
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_API_KEY, 'env-token');
|
|
22
27
|
const explicit = {
|
|
23
28
|
baseUrl: 'https://custom.example.com',
|
|
24
29
|
personalAccessToken: 'explicit-token',
|
|
25
30
|
};
|
|
26
31
|
const merged = (0, index_1.mergeConfig)(explicit);
|
|
27
32
|
(0, vitest_1.expect)(merged.baseUrl).toBe('https://custom.example.com');
|
|
28
|
-
(0, vitest_1.expect)(merged.personalAccessToken).
|
|
33
|
+
(0, vitest_1.expect)(merged.personalAccessToken).toBeInstanceOf(index_1.SecretString);
|
|
34
|
+
(0, vitest_1.expect)(merged.personalAccessToken.expose()).toBe('explicit-token');
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.describe)('mergeConfig', () => {
|
|
38
|
+
(0, vitest_1.beforeEach)(() => {
|
|
39
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_API_KEY, '');
|
|
40
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_URL, '');
|
|
41
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_PROXY_AUTHORIZATION, '');
|
|
29
42
|
});
|
|
30
43
|
(0, vitest_1.it)('should require baseUrl and personalAccessToken', () => {
|
|
31
44
|
(0, vitest_1.expect)(() => (0, index_1.mergeConfig)({})).toThrow();
|
|
@@ -34,6 +47,11 @@ const index_1 = require("./index");
|
|
|
34
47
|
});
|
|
35
48
|
});
|
|
36
49
|
(0, vitest_1.describe)('loadConfigFromEnv', () => {
|
|
50
|
+
(0, vitest_1.beforeEach)(() => {
|
|
51
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_API_KEY, '');
|
|
52
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_URL, '');
|
|
53
|
+
vitest_1.vi.stubEnv(index_1.ENV_LIGHTDASH_PROXY_AUTHORIZATION, '');
|
|
54
|
+
});
|
|
37
55
|
(0, vitest_1.it)('should return empty object when env vars are not set', () => {
|
|
38
56
|
const config = (0, index_1.loadConfigFromEnv)();
|
|
39
57
|
(0, vitest_1.expect)(config).toEqual({});
|
package/dist/utils/env.js
CHANGED
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = void 0;
|
|
9
9
|
exports.loadConfigFromEnv = loadConfigFromEnv;
|
|
10
10
|
exports.mergeConfig = mergeConfig;
|
|
11
|
+
const secret_string_1 = require("./secret-string");
|
|
11
12
|
/** Environment variable names (aligned with Lightdash CLI). */
|
|
12
13
|
exports.ENV_LIGHTDASH_API_KEY = 'LIGHTDASH_API_KEY';
|
|
13
14
|
exports.ENV_LIGHTDASH_URL = 'LIGHTDASH_URL';
|
|
@@ -41,15 +42,16 @@ function mergeConfig(explicit) {
|
|
|
41
42
|
var _a, _b, _c, _d, _e;
|
|
42
43
|
const fromEnv = loadConfigFromEnv();
|
|
43
44
|
const baseUrl = (_b = (_a = explicit === null || explicit === void 0 ? void 0 : explicit.baseUrl) !== null && _a !== void 0 ? _a : fromEnv.baseUrl) !== null && _b !== void 0 ? _b : '';
|
|
44
|
-
const
|
|
45
|
-
|
|
45
|
+
const pat = (_d = (_c = explicit === null || explicit === void 0 ? void 0 : explicit.personalAccessToken) !== null && _c !== void 0 ? _c : fromEnv.personalAccessToken) !== null && _d !== void 0 ? _d : '';
|
|
46
|
+
const proxyAuth = (_e = explicit === null || explicit === void 0 ? void 0 : explicit.proxyAuthorization) !== null && _e !== void 0 ? _e : fromEnv.proxyAuthorization;
|
|
47
|
+
if (!baseUrl || !pat) {
|
|
46
48
|
throw new Error('Lightdash client requires baseUrl and personalAccessToken. ' +
|
|
47
49
|
'Set them in config or via LIGHTDASH_URL and LIGHTDASH_API_KEY.');
|
|
48
50
|
}
|
|
49
51
|
return {
|
|
50
52
|
baseUrl,
|
|
51
|
-
personalAccessToken,
|
|
52
|
-
proxyAuthorization:
|
|
53
|
+
personalAccessToken: typeof pat === 'string' ? new secret_string_1.SecretString(pat) : pat,
|
|
54
|
+
proxyAuthorization: typeof proxyAuth === 'string' ? new secret_string_1.SecretString(proxyAuth) : proxyAuth,
|
|
53
55
|
rateLimit: explicit === null || explicit === void 0 ? void 0 : explicit.rateLimit,
|
|
54
56
|
timeout: explicit === null || explicit === void 0 ? void 0 : explicit.timeout,
|
|
55
57
|
retry: explicit === null || explicit === void 0 ? void 0 : explicit.retry,
|
package/dist/utils/env.test.js
CHANGED
|
@@ -47,14 +47,14 @@ const originalEnv = Object.assign({}, process.env);
|
|
|
47
47
|
personalAccessToken: 'explicit-token',
|
|
48
48
|
});
|
|
49
49
|
(0, vitest_1.expect)(merged.baseUrl).toBe('https://explicit.example.com');
|
|
50
|
-
(0, vitest_1.expect)(merged.personalAccessToken).toBe('explicit-token');
|
|
50
|
+
(0, vitest_1.expect)(merged.personalAccessToken.expose()).toBe('explicit-token');
|
|
51
51
|
});
|
|
52
52
|
(0, vitest_1.it)('should use env when explicit config omits a field', () => {
|
|
53
53
|
process.env[env_1.ENV_LIGHTDASH_URL] = 'https://env.example.com';
|
|
54
54
|
process.env[env_1.ENV_LIGHTDASH_API_KEY] = 'env-token';
|
|
55
55
|
const merged = (0, env_1.mergeConfig)({ baseUrl: 'https://explicit.example.com' });
|
|
56
56
|
(0, vitest_1.expect)(merged.baseUrl).toBe('https://explicit.example.com');
|
|
57
|
-
(0, vitest_1.expect)(merged.personalAccessToken).toBe('env-token');
|
|
57
|
+
(0, vitest_1.expect)(merged.personalAccessToken.expose()).toBe('env-token');
|
|
58
58
|
});
|
|
59
59
|
(0, vitest_1.it)('should throw when baseUrl and personalAccessToken cannot be resolved', () => {
|
|
60
60
|
(0, vitest_1.expect)(() => (0, env_1.mergeConfig)(undefined)).toThrow(/baseUrl and personalAccessToken/);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wrapper for sensitive strings that prevents accidental exposure in logs,
|
|
3
|
+
* console output, or JSON serialization.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SecretString {
|
|
6
|
+
private readonly value;
|
|
7
|
+
constructor(value: string);
|
|
8
|
+
/**
|
|
9
|
+
* Prevents the actual value from being shown when converted to a string.
|
|
10
|
+
*/
|
|
11
|
+
toString(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Prevents the actual value from being shown when serialized to JSON.
|
|
14
|
+
*/
|
|
15
|
+
toJSON(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Explicitly expose the underlying sensitive value.
|
|
18
|
+
* Use this only when necessary, e.g., when setting HTTP headers.
|
|
19
|
+
*/
|
|
20
|
+
expose(): string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecretString = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A wrapper for sensitive strings that prevents accidental exposure in logs,
|
|
6
|
+
* console output, or JSON serialization.
|
|
7
|
+
*/
|
|
8
|
+
class SecretString {
|
|
9
|
+
constructor(value) {
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Prevents the actual value from being shown when converted to a string.
|
|
14
|
+
*/
|
|
15
|
+
toString() {
|
|
16
|
+
return '**********';
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Prevents the actual value from being shown when serialized to JSON.
|
|
20
|
+
*/
|
|
21
|
+
toJSON() {
|
|
22
|
+
return '**********';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Node.js custom inspect symbol to prevent exposure in console.log/util.inspect.
|
|
26
|
+
*/
|
|
27
|
+
[Symbol.for('nodejs.util.inspect.custom')]() {
|
|
28
|
+
return 'SecretString(**********)';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Explicitly expose the underlying sensitive value.
|
|
32
|
+
* Use this only when necessary, e.g., when setting HTTP headers.
|
|
33
|
+
*/
|
|
34
|
+
expose() {
|
|
35
|
+
return this.value;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.SecretString = SecretString;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Client library for Lightdash AI.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"axios": "^1.13.5",
|
|
12
12
|
"bottleneck": "^2.19.5",
|
|
13
|
-
"@lightdash-tools/common": "0.
|
|
13
|
+
"@lightdash-tools/common": "0.2.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@types/node": "^25.2.3"
|
|
@@ -37,4 +37,38 @@ describe('ExploresClient', () => {
|
|
|
37
37
|
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/explores/e1');
|
|
38
38
|
expect(result).toEqual(explore);
|
|
39
39
|
});
|
|
40
|
+
|
|
41
|
+
it('listDimensions should extract dimensions from explore', async () => {
|
|
42
|
+
const client = new ExploresClient(mockHttp);
|
|
43
|
+
const explore = {
|
|
44
|
+
tables: {
|
|
45
|
+
t1: {
|
|
46
|
+
dimensions: {
|
|
47
|
+
d1: { name: 'd1' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
vi.mocked(mockHttp.get).mockResolvedValue(explore);
|
|
53
|
+
const result = await client.listDimensions('p1', 'e1');
|
|
54
|
+
expect(result).toEqual([{ name: 'd1' }]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('getFieldLineage should extract lineage from explore', async () => {
|
|
58
|
+
const client = new ExploresClient(mockHttp);
|
|
59
|
+
const explore = {
|
|
60
|
+
tables: {
|
|
61
|
+
t1: {
|
|
62
|
+
dimensions: {
|
|
63
|
+
d1: { name: 'd1' },
|
|
64
|
+
},
|
|
65
|
+
metrics: {},
|
|
66
|
+
lineageGraph: { upstream: [] },
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
vi.mocked(mockHttp.get).mockResolvedValue(explore);
|
|
71
|
+
const result = await client.getFieldLineage('p1', 'e1', 'd1');
|
|
72
|
+
expect(result).toEqual({ upstream: [] });
|
|
73
|
+
});
|
|
40
74
|
});
|
package/src/api/v1/explores.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Explores API client (v1).
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import type { ApiExploresResults, ApiExploreResults } from '@lightdash-tools/common';
|
|
5
|
+
import type { ApiExploresResults, ApiExploreResults, LightdashApi } from '@lightdash-tools/common';
|
|
6
6
|
import { BaseApiClient } from '../base-client';
|
|
7
7
|
|
|
8
8
|
export class ExploresClient extends BaseApiClient {
|
|
@@ -15,4 +15,23 @@ export class ExploresClient extends BaseApiClient {
|
|
|
15
15
|
async getExplore(projectUuid: string, exploreId: string): Promise<ApiExploreResults> {
|
|
16
16
|
return this.http.get<ApiExploreResults>(`/projects/${projectUuid}/explores/${exploreId}`);
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
/** List dimensions for a specific explore. */
|
|
20
|
+
async listDimensions(projectUuid: string, exploreId: string): Promise<unknown[]> {
|
|
21
|
+
const explore = await this.getExplore(projectUuid, exploreId);
|
|
22
|
+
return Object.values(explore.tables).flatMap((table: LightdashApi.Explores.CompiledTable) =>
|
|
23
|
+
Object.values(table.dimensions),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Get lineage for a specific field in an explore. */
|
|
28
|
+
async getFieldLineage(projectUuid: string, exploreId: string, fieldId: string): Promise<unknown> {
|
|
29
|
+
const explore = await this.getExplore(projectUuid, exploreId);
|
|
30
|
+
for (const table of Object.values(explore.tables) as LightdashApi.Explores.CompiledTable[]) {
|
|
31
|
+
if (table.dimensions[fieldId] || table.metrics[fieldId]) {
|
|
32
|
+
return table.lineageGraph;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
18
37
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { MetricsClient } from './metrics';
|
|
3
|
+
import type { HttpClient } from '../../http/http-client';
|
|
4
|
+
|
|
5
|
+
describe('MetricsClient', () => {
|
|
6
|
+
let mockHttp: HttpClient;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockHttp = {
|
|
10
|
+
get: vi.fn(),
|
|
11
|
+
post: vi.fn(),
|
|
12
|
+
put: vi.fn(),
|
|
13
|
+
patch: vi.fn(),
|
|
14
|
+
delete: vi.fn(),
|
|
15
|
+
} as unknown as HttpClient;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('listMetrics should call GET /projects/{projectUuid}/dataCatalog/metrics', async () => {
|
|
19
|
+
const client = new MetricsClient(mockHttp);
|
|
20
|
+
const mockResponse = { status: 'ok', results: [] };
|
|
21
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
22
|
+
const result = await client.listMetrics('p1', { search: 'test' });
|
|
23
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/dataCatalog/metrics', {
|
|
24
|
+
params: { search: 'test' },
|
|
25
|
+
});
|
|
26
|
+
expect(result).toEqual(mockResponse);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('getMetric should call GET /projects/{projectUuid}/dataCatalog/metrics/{tableName}/{metricName}', async () => {
|
|
30
|
+
const client = new MetricsClient(mockHttp);
|
|
31
|
+
const mockResponse = { status: 'ok', results: {} };
|
|
32
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
33
|
+
const result = await client.getMetric('p1', 't1', 'm1');
|
|
34
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/dataCatalog/metrics/t1/m1');
|
|
35
|
+
expect(result).toEqual(mockResponse);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics API client.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { LightdashApi } from '@lightdash-tools/common';
|
|
6
|
+
import { BaseApiClient } from '../base-client';
|
|
7
|
+
|
|
8
|
+
/** Query params for listing metrics in catalog. */
|
|
9
|
+
export interface ListMetricsParams {
|
|
10
|
+
search?: string;
|
|
11
|
+
page?: number;
|
|
12
|
+
pageSize?: number;
|
|
13
|
+
sort?: string;
|
|
14
|
+
order?: 'asc' | 'desc';
|
|
15
|
+
categories?: string[];
|
|
16
|
+
categoriesFilterMode?: 'any' | 'all';
|
|
17
|
+
tables?: string[];
|
|
18
|
+
ownerUserUuids?: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class MetricsClient extends BaseApiClient {
|
|
22
|
+
/** List metrics in a project data catalog. */
|
|
23
|
+
async listMetrics(
|
|
24
|
+
projectUuid: string,
|
|
25
|
+
params?: ListMetricsParams,
|
|
26
|
+
): Promise<LightdashApi.Metrics.ApiMetricsCatalog> {
|
|
27
|
+
return this.http.get<LightdashApi.Metrics.ApiMetricsCatalog>(
|
|
28
|
+
`/projects/${projectUuid}/dataCatalog/metrics`,
|
|
29
|
+
{ params },
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Get a metric by table and name. */
|
|
34
|
+
async getMetric(
|
|
35
|
+
projectUuid: string,
|
|
36
|
+
tableName: string,
|
|
37
|
+
metricName: string,
|
|
38
|
+
): Promise<LightdashApi.Metrics.ApiGetMetricResponse> {
|
|
39
|
+
return this.http.get<LightdashApi.Metrics.ApiGetMetricResponse>(
|
|
40
|
+
`/projects/${projectUuid}/dataCatalog/metrics/${tableName}/${metricName}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { SchedulersClient } from './schedulers';
|
|
3
|
+
import type { HttpClient } from '../../http/http-client';
|
|
4
|
+
|
|
5
|
+
describe('SchedulersClient', () => {
|
|
6
|
+
let mockHttp: HttpClient;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
mockHttp = {
|
|
10
|
+
get: vi.fn(),
|
|
11
|
+
post: vi.fn(),
|
|
12
|
+
put: vi.fn(),
|
|
13
|
+
patch: vi.fn(),
|
|
14
|
+
delete: vi.fn(),
|
|
15
|
+
} as unknown as HttpClient;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('listSchedulers should call GET /schedulers/{projectUuid}/list', async () => {
|
|
19
|
+
const client = new SchedulersClient(mockHttp);
|
|
20
|
+
const mockResponse = { status: 'ok', results: [] };
|
|
21
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
22
|
+
const result = await client.listSchedulers('p1', { page: 1 });
|
|
23
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/schedulers/p1/list', {
|
|
24
|
+
params: { page: 1 },
|
|
25
|
+
});
|
|
26
|
+
expect(result).toEqual(mockResponse);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('getScheduler should call GET /schedulers/{schedulerUuid}', async () => {
|
|
30
|
+
const client = new SchedulersClient(mockHttp);
|
|
31
|
+
const mockResponse = { status: 'ok', results: {} };
|
|
32
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
33
|
+
const result = await client.getScheduler('s1');
|
|
34
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/schedulers/s1');
|
|
35
|
+
expect(result).toEqual(mockResponse);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schedulers API client.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { LightdashApi } from '@lightdash-tools/common';
|
|
6
|
+
import { BaseApiClient } from '../base-client';
|
|
7
|
+
|
|
8
|
+
/** Query params for listing schedulers. */
|
|
9
|
+
export interface ListSchedulersParams {
|
|
10
|
+
pageSize?: number;
|
|
11
|
+
page?: number;
|
|
12
|
+
searchQuery?: string;
|
|
13
|
+
sortBy?: 'name' | 'createdAt';
|
|
14
|
+
sortDirection?: 'asc' | 'desc';
|
|
15
|
+
createdByUserUuids?: string;
|
|
16
|
+
formats?: string;
|
|
17
|
+
resourceType?: 'chart' | 'dashboard';
|
|
18
|
+
resourceUuids?: string;
|
|
19
|
+
destinations?: string;
|
|
20
|
+
includeLatestRun?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class SchedulersClient extends BaseApiClient {
|
|
24
|
+
/** List schedulers in a project. */
|
|
25
|
+
async listSchedulers(
|
|
26
|
+
projectUuid: string,
|
|
27
|
+
params?: ListSchedulersParams,
|
|
28
|
+
): Promise<LightdashApi.Schedulers.ApiSchedulersResponse> {
|
|
29
|
+
return this.http.get<LightdashApi.Schedulers.ApiSchedulersResponse>(
|
|
30
|
+
`/schedulers/${projectUuid}/list`,
|
|
31
|
+
{ params },
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Get a scheduler by UUID. */
|
|
36
|
+
async getScheduler(
|
|
37
|
+
schedulerUuid: string,
|
|
38
|
+
): Promise<LightdashApi.Schedulers.ApiSchedulerAndTargetsResponse> {
|
|
39
|
+
return this.http.get<LightdashApi.Schedulers.ApiSchedulerAndTargetsResponse>(
|
|
40
|
+
`/schedulers/${schedulerUuid}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|