@lightdash-tools/client 0.5.0 → 0.7.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.
- package/README.md +2 -2
- package/dist/agentops/apply-agent-change.d.ts +3 -0
- package/dist/agentops/apply-agent-change.js +63 -0
- package/dist/agentops/apply-bundle-diff.d.ts +13 -0
- package/dist/agentops/apply-bundle-diff.js +44 -0
- package/dist/agentops/apply-bundle-diff.test.d.ts +1 -0
- package/dist/agentops/apply-bundle-diff.test.js +397 -0
- package/dist/agentops/apply-context.d.ts +14 -0
- package/dist/agentops/apply-context.js +6 -0
- package/dist/agentops/apply-evaluation-change.d.ts +3 -0
- package/dist/agentops/apply-evaluation-change.js +78 -0
- package/dist/agentops/fetch-bundle-state.d.ts +6 -0
- package/dist/agentops/fetch-bundle-state.js +20 -0
- package/dist/agentops/fetch-bundle-state.test.d.ts +1 -0
- package/dist/agentops/fetch-bundle-state.test.js +44 -0
- package/dist/agentops/index.d.ts +3 -0
- package/dist/agentops/index.js +9 -0
- package/dist/agentops/resolve-evaluation-run.d.ts +15 -0
- package/dist/agentops/resolve-evaluation-run.js +48 -0
- package/dist/api/v1/ai-agents/admin.d.ts +16 -0
- package/dist/api/v1/ai-agents/admin.js +29 -0
- package/dist/api/v1/ai-agents/agents.d.ts +18 -0
- package/dist/api/v1/ai-agents/agents.js +31 -0
- package/dist/api/v1/ai-agents/artifacts.d.ts +26 -0
- package/dist/api/v1/ai-agents/artifacts.js +41 -0
- package/dist/api/v1/ai-agents/artifacts.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/artifacts.test.js +69 -0
- package/dist/api/v1/ai-agents/discovery.d.ts +28 -0
- package/dist/api/v1/ai-agents/discovery.js +46 -0
- package/dist/api/v1/ai-agents/discovery.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/discovery.test.js +90 -0
- package/dist/api/v1/ai-agents/evaluations.d.ts +39 -0
- package/dist/api/v1/ai-agents/evaluations.js +70 -0
- package/dist/api/v1/ai-agents/facade.d.ts +79 -0
- package/dist/api/v1/ai-agents/facade.js +193 -0
- package/dist/api/v1/ai-agents/feedback.d.ts +10 -0
- package/dist/api/v1/ai-agents/feedback.js +15 -0
- package/dist/api/v1/ai-agents/feedback.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/feedback.test.js +23 -0
- package/dist/api/v1/ai-agents/index.d.ts +1 -0
- package/dist/api/v1/ai-agents/index.js +5 -0
- package/dist/api/v1/ai-agents/mcp-servers.d.ts +20 -0
- package/dist/api/v1/ai-agents/mcp-servers.js +35 -0
- package/dist/api/v1/ai-agents/mcp-servers.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/mcp-servers.test.js +66 -0
- package/dist/api/v1/ai-agents/request-options.d.ts +12 -0
- package/dist/api/v1/ai-agents/request-options.js +20 -0
- package/dist/api/v1/ai-agents/sql-approval.d.ts +10 -0
- package/dist/api/v1/ai-agents/sql-approval.js +15 -0
- package/dist/api/v1/ai-agents/sql-approval.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/sql-approval.test.js +25 -0
- package/dist/api/v1/ai-agents/threads.d.ts +56 -0
- package/dist/api/v1/ai-agents/threads.js +97 -0
- package/dist/api/v1/ai-agents/threads.test.d.ts +1 -0
- package/dist/api/v1/ai-agents/threads.test.js +39 -0
- package/dist/api/v1/ai-agents.test.js +172 -89
- package/dist/api/v1/analytics.d.ts +10 -0
- package/dist/api/v1/analytics.js +14 -0
- package/dist/api/v1/analytics.test.d.ts +4 -0
- package/dist/api/v1/analytics.test.js +27 -0
- package/dist/api/v1/charts.d.ts +5 -2
- package/dist/api/v1/charts.js +18 -30
- package/dist/api/v1/charts.test.js +19 -28
- package/dist/api/v1/dashboards.d.ts +11 -2
- package/dist/api/v1/dashboards.js +19 -14
- package/dist/api/v1/dashboards.test.js +54 -12
- package/dist/api/v1/explores.d.ts +4 -2
- package/dist/api/v1/explores.js +20 -29
- package/dist/api/v1/explores.test.js +31 -21
- package/dist/api/v1/groups.d.ts +1 -1
- package/dist/api/v1/groups.js +25 -51
- package/dist/api/v1/groups.test.js +15 -24
- package/dist/api/v1/metrics.d.ts +2 -2
- package/dist/api/v1/metrics.js +4 -17
- package/dist/api/v1/metrics.test.js +6 -15
- package/dist/api/v1/organizations.d.ts +1 -1
- package/dist/api/v1/organizations.js +2 -13
- package/dist/api/v1/organizations.test.js +3 -12
- package/dist/api/v1/project-access.d.ts +1 -1
- package/dist/api/v1/project-access.js +18 -45
- package/dist/api/v1/project-access.test.js +27 -36
- package/dist/api/v1/projects.d.ts +1 -1
- package/dist/api/v1/projects.js +6 -21
- package/dist/api/v1/projects.test.js +9 -18
- package/dist/api/v1/query.d.ts +5 -2
- package/dist/api/v1/query.js +8 -18
- package/dist/api/v1/query.test.js +6 -15
- package/dist/api/v1/schedulers.d.ts +2 -2
- package/dist/api/v1/schedulers.js +4 -17
- package/dist/api/v1/schedulers.test.js +6 -15
- package/dist/api/v1/spaces.d.ts +1 -1
- package/dist/api/v1/spaces.js +18 -45
- package/dist/api/v1/spaces.test.js +27 -36
- package/dist/api/v1/tags.d.ts +1 -1
- package/dist/api/v1/tags.js +4 -17
- package/dist/api/v1/tags.test.js +6 -15
- package/dist/api/v1/users.d.ts +3 -1
- package/dist/api/v1/users.js +22 -39
- package/dist/api/v1/users.test.js +44 -30
- package/dist/api/v1/validation.d.ts +5 -2
- package/dist/api/v1/validation.js +8 -18
- package/dist/api/v1/validation.test.js +6 -15
- package/dist/api/v2/content.d.ts +2 -2
- package/dist/api/v2/content.js +3 -14
- package/dist/api/v2/content.test.js +3 -12
- package/dist/api/v2/dashboards.d.ts +10 -0
- package/dist/api/v2/dashboards.js +14 -0
- package/dist/api/v2/dashboards.test.d.ts +4 -0
- package/dist/api/v2/dashboards.test.js +27 -0
- package/dist/api/v2/organization-roles.d.ts +1 -1
- package/dist/api/v2/organization-roles.js +21 -50
- package/dist/api/v2/organization-roles.test.js +33 -42
- package/dist/api/v2/project-role-assignments.d.ts +1 -1
- package/dist/api/v2/project-role-assignments.js +12 -33
- package/dist/api/v2/project-role-assignments.test.js +18 -27
- package/dist/api/v2/query.d.ts +1 -1
- package/dist/api/v2/query.js +10 -29
- package/dist/api/v2/query.test.js +15 -24
- package/dist/api/v2/validation.d.ts +28 -0
- package/dist/api/v2/validation.js +23 -0
- package/dist/client.d.ts +20 -14
- package/dist/client.js +22 -16
- package/dist/config.d.ts +35 -10
- package/dist/http/axios-client.d.ts +4 -4
- package/dist/http/http-client.d.ts +3 -3
- package/dist/http/http-client.js +19 -40
- package/dist/http/interceptors.d.ts +3 -3
- package/dist/http/interceptors.js +16 -3
- package/dist/http/rate-limiter.js +2 -13
- package/dist/http/rate-limiter.test.js +15 -24
- package/dist/index.d.ts +7 -2
- package/dist/index.js +12 -1
- package/dist/index.test.js +13 -5
- package/dist/pagination/fetch-all-pages.js +18 -29
- package/dist/pagination/fetch-all-pages.test.js +15 -24
- package/dist/types/api.d.ts +1 -1
- package/dist/utils/env.d.ts +11 -2
- package/dist/utils/env.js +41 -8
- package/dist/utils/env.test.js +14 -4
- package/dist/utils/logger.js +5 -4
- package/dist/utils/retry.js +17 -28
- package/dist/utils/retry.test.js +9 -18
- package/dist/utils/secret-string.test.d.ts +1 -0
- package/dist/utils/secret-string.test.js +25 -0
- package/package.json +12 -4
- package/src/agentops/apply-agent-change.ts +82 -0
- package/src/agentops/apply-bundle-diff.test.ts +453 -0
- package/src/agentops/apply-bundle-diff.ts +63 -0
- package/src/agentops/apply-context.ts +23 -0
- package/src/agentops/apply-evaluation-change.ts +125 -0
- package/src/agentops/fetch-bundle-state.test.ts +51 -0
- package/src/agentops/fetch-bundle-state.ts +33 -0
- package/src/agentops/index.ts +11 -0
- package/src/agentops/resolve-evaluation-run.ts +94 -0
- package/src/api/v1/ai-agents/admin.ts +41 -0
- package/src/api/v1/ai-agents/agents.ts +40 -0
- package/src/api/v1/ai-agents/artifacts.test.ts +84 -0
- package/src/api/v1/ai-agents/artifacts.ts +92 -0
- package/src/api/v1/ai-agents/discovery.test.ts +102 -0
- package/src/api/v1/ai-agents/discovery.ts +79 -0
- package/src/api/v1/ai-agents/evaluations.ts +152 -0
- package/src/api/v1/ai-agents/facade.ts +489 -0
- package/src/api/v1/ai-agents/feedback.test.ts +30 -0
- package/src/api/v1/ai-agents/feedback.ts +24 -0
- package/src/api/v1/ai-agents/index.ts +1 -0
- package/src/api/v1/ai-agents/mcp-servers.test.ts +81 -0
- package/src/api/v1/ai-agents/mcp-servers.ts +67 -0
- package/src/api/v1/ai-agents/request-options.ts +32 -0
- package/src/api/v1/ai-agents/sql-approval.test.ts +32 -0
- package/src/api/v1/ai-agents/sql-approval.ts +24 -0
- package/src/api/v1/ai-agents/threads.test.ts +55 -0
- package/src/api/v1/ai-agents/threads.ts +216 -0
- package/src/api/v1/ai-agents.test.ts +189 -13
- package/src/api/v1/analytics.test.ts +32 -0
- package/src/api/v1/analytics.ts +16 -0
- package/src/api/v1/charts.test.ts +8 -6
- package/src/api/v1/charts.ts +8 -4
- package/src/api/v1/dashboards.test.ts +57 -0
- package/src/api/v1/dashboards.ts +41 -2
- package/src/api/v1/explores.test.ts +22 -0
- package/src/api/v1/explores.ts +13 -2
- package/src/api/v1/groups.test.ts +2 -0
- package/src/api/v1/groups.ts +9 -7
- package/src/api/v1/metrics.test.ts +2 -0
- package/src/api/v1/metrics.ts +3 -2
- package/src/api/v1/organizations.test.ts +2 -0
- package/src/api/v1/organizations.ts +2 -1
- package/src/api/v1/project-access.test.ts +3 -1
- package/src/api/v1/project-access.ts +2 -1
- package/src/api/v1/projects.test.ts +2 -0
- package/src/api/v1/projects.ts +2 -1
- package/src/api/v1/query.test.ts +2 -0
- package/src/api/v1/query.ts +6 -2
- package/src/api/v1/schedulers.test.ts +2 -0
- package/src/api/v1/schedulers.ts +3 -2
- package/src/api/v1/spaces.test.ts +2 -0
- package/src/api/v1/spaces.ts +2 -1
- package/src/api/v1/tags.test.ts +2 -0
- package/src/api/v1/tags.ts +2 -1
- package/src/api/v1/users.test.ts +26 -0
- package/src/api/v1/users.ts +8 -2
- package/src/api/v1/validation.test.ts +2 -0
- package/src/api/v1/validation.ts +6 -2
- package/src/api/v2/content.test.ts +2 -0
- package/src/api/v2/content.ts +3 -2
- package/src/api/v2/dashboards.test.ts +32 -0
- package/src/api/v2/dashboards.ts +18 -0
- package/src/api/v2/organization-roles.test.ts +2 -0
- package/src/api/v2/organization-roles.ts +2 -1
- package/src/api/v2/project-role-assignments.test.ts +2 -0
- package/src/api/v2/project-role-assignments.ts +2 -1
- package/src/api/v2/query.test.ts +2 -0
- package/src/api/v2/query.ts +2 -1
- package/src/api/v2/validation.ts +48 -0
- package/src/client.test.ts +1 -0
- package/src/client.ts +27 -17
- package/src/config.ts +38 -10
- package/src/errors.test.ts +1 -0
- package/src/http/axios-client.ts +8 -5
- package/src/http/http-client.ts +8 -6
- package/src/http/interceptors.ts +23 -10
- package/src/http/rate-limiter.test.ts +1 -0
- package/src/http/rate-limiter.ts +3 -1
- package/src/index.test.ts +16 -7
- package/src/index.ts +16 -1
- package/src/pagination/fetch-all-pages.test.ts +2 -0
- package/src/types/api.ts +1 -1
- package/src/utils/env.test.ts +16 -4
- package/src/utils/env.ts +61 -10
- package/src/utils/logger.ts +6 -4
- package/src/utils/retry.test.ts +1 -0
- package/src/utils/retry.ts +2 -1
- package/src/utils/secret-string.test.ts +27 -0
- package/tsconfig.json +4 -2
- package/dist/api/v1/ai-agents.d.ts +0 -63
- package/dist/api/v1/ai-agents.js +0 -173
- package/src/api/v1/ai-agents.ts +0 -252
|
@@ -1,18 +1,9 @@
|
|
|
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 fetch_all_pages_1 = require("./fetch-all-pages");
|
|
14
5
|
(0, vitest_1.describe)('fetchAllPages', () => {
|
|
15
|
-
(0, vitest_1.it)('returns concatenated data from multiple pages', () =>
|
|
6
|
+
(0, vitest_1.it)('returns concatenated data from multiple pages', async () => {
|
|
16
7
|
const fetchPage = vitest_1.vi
|
|
17
8
|
.fn()
|
|
18
9
|
.mockResolvedValueOnce({
|
|
@@ -27,44 +18,44 @@ const fetch_all_pages_1 = require("./fetch-all-pages");
|
|
|
27
18
|
data: [{ id: 5 }, { id: 6 }],
|
|
28
19
|
pagination: { page: 3, pageSize: 2, totalResults: 6, totalPageCount: 3 },
|
|
29
20
|
});
|
|
30
|
-
const result =
|
|
21
|
+
const result = await (0, fetch_all_pages_1.fetchAllPages)({ fetchPage, pageSize: 2 });
|
|
31
22
|
(0, vitest_1.expect)(result).toHaveLength(6);
|
|
32
23
|
(0, vitest_1.expect)(result).toEqual([{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }]);
|
|
33
24
|
(0, vitest_1.expect)(fetchPage).toHaveBeenCalledTimes(3);
|
|
34
25
|
(0, vitest_1.expect)(fetchPage).toHaveBeenNthCalledWith(1, 1, 2);
|
|
35
26
|
(0, vitest_1.expect)(fetchPage).toHaveBeenNthCalledWith(2, 2, 2);
|
|
36
27
|
(0, vitest_1.expect)(fetchPage).toHaveBeenNthCalledWith(3, 3, 2);
|
|
37
|
-
})
|
|
38
|
-
(0, vitest_1.it)('returns single page when no pagination', () =>
|
|
28
|
+
});
|
|
29
|
+
(0, vitest_1.it)('returns single page when no pagination', async () => {
|
|
39
30
|
const fetchPage = vitest_1.vi.fn().mockResolvedValueOnce({
|
|
40
31
|
data: [{ x: 'a' }],
|
|
41
32
|
});
|
|
42
|
-
const result =
|
|
33
|
+
const result = await (0, fetch_all_pages_1.fetchAllPages)({ fetchPage });
|
|
43
34
|
(0, vitest_1.expect)(result).toEqual([{ x: 'a' }]);
|
|
44
35
|
(0, vitest_1.expect)(fetchPage).toHaveBeenCalledTimes(1);
|
|
45
36
|
(0, vitest_1.expect)(fetchPage).toHaveBeenCalledWith(1, 100);
|
|
46
|
-
})
|
|
47
|
-
(0, vitest_1.it)('returns single page when totalPageCount is 1', () =>
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.it)('returns single page when totalPageCount is 1', async () => {
|
|
48
39
|
const fetchPage = vitest_1.vi.fn().mockResolvedValueOnce({
|
|
49
40
|
data: [{ a: 1 }],
|
|
50
41
|
pagination: { page: 1, pageSize: 10, totalResults: 1, totalPageCount: 1 },
|
|
51
42
|
});
|
|
52
|
-
const result =
|
|
43
|
+
const result = await (0, fetch_all_pages_1.fetchAllPages)({ fetchPage, pageSize: 10 });
|
|
53
44
|
(0, vitest_1.expect)(result).toEqual([{ a: 1 }]);
|
|
54
45
|
(0, vitest_1.expect)(fetchPage).toHaveBeenCalledTimes(1);
|
|
55
|
-
})
|
|
56
|
-
(0, vitest_1.it)('returns empty array when first page has no data and no pagination', () =>
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.it)('returns empty array when first page has no data and no pagination', async () => {
|
|
57
48
|
const fetchPage = vitest_1.vi.fn().mockResolvedValueOnce({ data: [] });
|
|
58
|
-
const result =
|
|
49
|
+
const result = await (0, fetch_all_pages_1.fetchAllPages)({ fetchPage });
|
|
59
50
|
(0, vitest_1.expect)(result).toEqual([]);
|
|
60
51
|
(0, vitest_1.expect)(fetchPage).toHaveBeenCalledTimes(1);
|
|
61
|
-
})
|
|
62
|
-
(0, vitest_1.it)('uses default page size when not provided', () =>
|
|
52
|
+
});
|
|
53
|
+
(0, vitest_1.it)('uses default page size when not provided', async () => {
|
|
63
54
|
const fetchPage = vitest_1.vi.fn().mockResolvedValueOnce({
|
|
64
55
|
data: [],
|
|
65
56
|
pagination: { page: 1, pageSize: 100, totalResults: 0, totalPageCount: 1 },
|
|
66
57
|
});
|
|
67
|
-
|
|
58
|
+
await (0, fetch_all_pages_1.fetchAllPages)({ fetchPage });
|
|
68
59
|
(0, vitest_1.expect)(fetchPage).toHaveBeenCalledWith(1, 100);
|
|
69
|
-
})
|
|
60
|
+
});
|
|
70
61
|
});
|
package/dist/types/api.d.ts
CHANGED
package/dist/utils/env.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Supports LIGHTDASH_API_KEY, LIGHTDASH_URL, LIGHTDASH_PROXY_AUTHORIZATION.
|
|
4
4
|
* Priority: explicit config > environment variables > no default for required fields.
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
6
|
+
import { SecretString } from './secret-string';
|
|
7
|
+
import type { PartialLightdashClientConfig, ResolvedLightdashClientConfig } from '../config';
|
|
7
8
|
/** Environment variable names (aligned with Lightdash CLI). */
|
|
8
9
|
export declare const ENV_LIGHTDASH_API_KEY = "LIGHTDASH_API_KEY";
|
|
9
10
|
export declare const ENV_LIGHTDASH_URL = "LIGHTDASH_URL";
|
|
@@ -13,8 +14,16 @@ export declare const ENV_LIGHTDASH_PROXY_AUTHORIZATION = "LIGHTDASH_PROXY_AUTHOR
|
|
|
13
14
|
* Returns only the fields that are set in the environment.
|
|
14
15
|
*/
|
|
15
16
|
export declare function loadConfigFromEnv(): PartialLightdashClientConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Builds a bearer-token client config for OAuth access tokens.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createBearerConfig(options: {
|
|
21
|
+
baseUrl: string;
|
|
22
|
+
accessToken: SecretString | string;
|
|
23
|
+
proxyAuthorization?: SecretString | string;
|
|
24
|
+
}): PartialLightdashClientConfig;
|
|
16
25
|
/**
|
|
17
26
|
* Merges explicit config with environment-derived config.
|
|
18
27
|
* Explicit config takes priority over environment variables.
|
|
19
28
|
*/
|
|
20
|
-
export declare function mergeConfig(explicit: PartialLightdashClientConfig | undefined):
|
|
29
|
+
export declare function mergeConfig(explicit: PartialLightdashClientConfig | undefined): ResolvedLightdashClientConfig;
|
package/dist/utils/env.js
CHANGED
|
@@ -7,12 +7,34 @@
|
|
|
7
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
|
+
exports.createBearerConfig = createBearerConfig;
|
|
10
11
|
exports.mergeConfig = mergeConfig;
|
|
11
12
|
const secret_string_1 = require("./secret-string");
|
|
12
13
|
/** Environment variable names (aligned with Lightdash CLI). */
|
|
13
14
|
exports.ENV_LIGHTDASH_API_KEY = 'LIGHTDASH_API_KEY';
|
|
14
15
|
exports.ENV_LIGHTDASH_URL = 'LIGHTDASH_URL';
|
|
15
16
|
exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = 'LIGHTDASH_PROXY_AUTHORIZATION';
|
|
17
|
+
function toSecretString(value) {
|
|
18
|
+
return typeof value === 'string' ? new secret_string_1.SecretString(value) : value;
|
|
19
|
+
}
|
|
20
|
+
function normalizeAuthConfig(auth) {
|
|
21
|
+
const token = toSecretString(auth.token);
|
|
22
|
+
if (auth.type === 'bearer') {
|
|
23
|
+
return { type: 'bearer', token };
|
|
24
|
+
}
|
|
25
|
+
return { type: 'api-key', token };
|
|
26
|
+
}
|
|
27
|
+
function resolveAuthConfig(explicit, fromEnv) {
|
|
28
|
+
var _a;
|
|
29
|
+
if (explicit === null || explicit === void 0 ? void 0 : explicit.auth) {
|
|
30
|
+
return normalizeAuthConfig(explicit.auth);
|
|
31
|
+
}
|
|
32
|
+
const pat = (_a = explicit === null || explicit === void 0 ? void 0 : explicit.personalAccessToken) !== null && _a !== void 0 ? _a : fromEnv.personalAccessToken;
|
|
33
|
+
if (pat) {
|
|
34
|
+
return { type: 'api-key', token: toSecretString(pat) };
|
|
35
|
+
}
|
|
36
|
+
throw new Error('Lightdash client requires auth credentials. Set auth, personalAccessToken, or LIGHTDASH_API_KEY.');
|
|
37
|
+
}
|
|
16
38
|
/**
|
|
17
39
|
* Reads configuration from environment variables.
|
|
18
40
|
* Returns only the fields that are set in the environment.
|
|
@@ -34,24 +56,35 @@ function loadConfigFromEnv() {
|
|
|
34
56
|
}
|
|
35
57
|
return out;
|
|
36
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Builds a bearer-token client config for OAuth access tokens.
|
|
61
|
+
*/
|
|
62
|
+
function createBearerConfig(options) {
|
|
63
|
+
return {
|
|
64
|
+
baseUrl: options.baseUrl.replace(/\/$/, ''),
|
|
65
|
+
auth: { type: 'bearer', token: options.accessToken },
|
|
66
|
+
proxyAuthorization: options.proxyAuthorization,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
37
69
|
/**
|
|
38
70
|
* Merges explicit config with environment-derived config.
|
|
39
71
|
* Explicit config takes priority over environment variables.
|
|
40
72
|
*/
|
|
41
73
|
function mergeConfig(explicit) {
|
|
42
|
-
var _a, _b, _c
|
|
74
|
+
var _a, _b, _c;
|
|
43
75
|
const fromEnv = loadConfigFromEnv();
|
|
44
76
|
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 : '';
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
throw new Error('Lightdash client requires baseUrl and personalAccessToken. ' +
|
|
49
|
-
'Set them in config or via LIGHTDASH_URL and LIGHTDASH_API_KEY.');
|
|
77
|
+
const proxyAuth = (_c = explicit === null || explicit === void 0 ? void 0 : explicit.proxyAuthorization) !== null && _c !== void 0 ? _c : fromEnv.proxyAuthorization;
|
|
78
|
+
if (!baseUrl) {
|
|
79
|
+
throw new Error('Lightdash client requires baseUrl. Set it in config or via LIGHTDASH_URL.');
|
|
50
80
|
}
|
|
81
|
+
const auth = resolveAuthConfig(explicit, fromEnv);
|
|
82
|
+
const personalAccessToken = auth.type === 'api-key' ? auth.token : explicit === null || explicit === void 0 ? void 0 : explicit.personalAccessToken;
|
|
51
83
|
return {
|
|
52
84
|
baseUrl,
|
|
53
|
-
|
|
54
|
-
|
|
85
|
+
auth,
|
|
86
|
+
personalAccessToken: personalAccessToken !== undefined ? toSecretString(personalAccessToken) : undefined,
|
|
87
|
+
proxyAuthorization: proxyAuth !== undefined ? toSecretString(proxyAuth) : undefined,
|
|
55
88
|
rateLimit: explicit === null || explicit === void 0 ? void 0 : explicit.rateLimit,
|
|
56
89
|
timeout: explicit === null || explicit === void 0 ? void 0 : explicit.timeout,
|
|
57
90
|
retry: explicit === null || explicit === void 0 ? void 0 : explicit.retry,
|
package/dist/utils/env.test.js
CHANGED
|
@@ -47,17 +47,18 @@ 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.
|
|
50
|
+
(0, vitest_1.expect)(merged.auth.type).toBe('api-key');
|
|
51
|
+
(0, vitest_1.expect)(merged.auth.token.expose()).toBe('explicit-token');
|
|
51
52
|
});
|
|
52
53
|
(0, vitest_1.it)('should use env when explicit config omits a field', () => {
|
|
53
54
|
process.env[env_1.ENV_LIGHTDASH_URL] = 'https://env.example.com';
|
|
54
55
|
process.env[env_1.ENV_LIGHTDASH_API_KEY] = 'env-token';
|
|
55
56
|
const merged = (0, env_1.mergeConfig)({ baseUrl: 'https://explicit.example.com' });
|
|
56
57
|
(0, vitest_1.expect)(merged.baseUrl).toBe('https://explicit.example.com');
|
|
57
|
-
(0, vitest_1.expect)(merged.
|
|
58
|
+
(0, vitest_1.expect)(merged.auth.token.expose()).toBe('env-token');
|
|
58
59
|
});
|
|
59
|
-
(0, vitest_1.it)('should throw when baseUrl and
|
|
60
|
-
(0, vitest_1.expect)(() => (0, env_1.mergeConfig)(undefined)).toThrow(/baseUrl
|
|
60
|
+
(0, vitest_1.it)('should throw when baseUrl and auth credentials cannot be resolved', () => {
|
|
61
|
+
(0, vitest_1.expect)(() => (0, env_1.mergeConfig)(undefined)).toThrow(/baseUrl|auth credentials/);
|
|
61
62
|
(0, vitest_1.expect)(() => (0, env_1.mergeConfig)({})).toThrow();
|
|
62
63
|
});
|
|
63
64
|
(0, vitest_1.it)('should preserve observability when provided in explicit config', () => {
|
|
@@ -69,5 +70,14 @@ const originalEnv = Object.assign({}, process.env);
|
|
|
69
70
|
observability: { onRequestComplete },
|
|
70
71
|
});
|
|
71
72
|
(0, vitest_1.expect)((_a = merged.observability) === null || _a === void 0 ? void 0 : _a.onRequestComplete).toBe(onRequestComplete);
|
|
73
|
+
(0, vitest_1.expect)(merged.auth).toEqual({ type: 'api-key', token: vitest_1.expect.objectContaining({}) });
|
|
74
|
+
});
|
|
75
|
+
(0, vitest_1.it)('should normalize bearer auth config', () => {
|
|
76
|
+
const merged = (0, env_1.mergeConfig)({
|
|
77
|
+
baseUrl: 'https://app.lightdash.cloud',
|
|
78
|
+
auth: { type: 'bearer', token: 'oauth-token' },
|
|
79
|
+
});
|
|
80
|
+
(0, vitest_1.expect)(merged.auth.type).toBe('bearer');
|
|
81
|
+
(0, vitest_1.expect)(merged.auth.token.expose()).toBe('oauth-token');
|
|
72
82
|
});
|
|
73
83
|
});
|
package/dist/utils/logger.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.consoleLogger = exports.noopLogger = void 0;
|
|
7
|
+
const LOG_PREFIX = '[Lightdash]';
|
|
7
8
|
/** No-op logger for when logging is disabled. */
|
|
8
9
|
exports.noopLogger = {
|
|
9
10
|
debug: () => { },
|
|
@@ -13,8 +14,8 @@ exports.noopLogger = {
|
|
|
13
14
|
};
|
|
14
15
|
/** Console-based logger. */
|
|
15
16
|
exports.consoleLogger = {
|
|
16
|
-
debug: (...args) => console.debug(
|
|
17
|
-
info: (...args) => console.info(
|
|
18
|
-
warn: (...args) => console.warn(
|
|
19
|
-
error: (...args) => console.error(
|
|
17
|
+
debug: (...args) => console.debug(LOG_PREFIX, ...args),
|
|
18
|
+
info: (...args) => console.info(LOG_PREFIX, ...args),
|
|
19
|
+
warn: (...args) => console.warn(LOG_PREFIX, ...args),
|
|
20
|
+
error: (...args) => console.error(LOG_PREFIX, ...args),
|
|
20
21
|
};
|
package/dist/utils/retry.js
CHANGED
|
@@ -3,15 +3,6 @@
|
|
|
3
3
|
* Retry logic with exponential backoff for transient failures.
|
|
4
4
|
* Retries on 5xx and network errors; no retry for 4xx (except 429 handled by rate limiter).
|
|
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.isRetryableError = isRetryableError;
|
|
17
8
|
exports.withRetry = withRetry;
|
|
@@ -43,25 +34,23 @@ function isRetryableError(error) {
|
|
|
43
34
|
/**
|
|
44
35
|
* Executes an async function with exponential backoff retries.
|
|
45
36
|
*/
|
|
46
|
-
function withRetry(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
throw err;
|
|
60
|
-
}
|
|
61
|
-
const wait = retryDelay * Math.pow(2, attempt);
|
|
62
|
-
yield delay(wait);
|
|
37
|
+
async function withRetry(fn, options = {}) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const maxRetries = (_a = options.maxRetries) !== null && _a !== void 0 ? _a : config_1.DEFAULT_RETRY.maxRetries;
|
|
40
|
+
const retryDelay = (_b = options.retryDelay) !== null && _b !== void 0 ? _b : config_1.DEFAULT_RETRY.retryDelay;
|
|
41
|
+
let lastError;
|
|
42
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
43
|
+
try {
|
|
44
|
+
return await fn();
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
lastError = err;
|
|
48
|
+
if (attempt === maxRetries || !isRetryableError(err)) {
|
|
49
|
+
throw err;
|
|
63
50
|
}
|
|
51
|
+
const wait = retryDelay * Math.pow(2, attempt);
|
|
52
|
+
await delay(wait);
|
|
64
53
|
}
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
}
|
|
55
|
+
throw lastError;
|
|
67
56
|
}
|
package/dist/utils/retry.test.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
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 retry_1 = require("./retry");
|
|
@@ -30,24 +21,24 @@ const retry_1 = require("./retry");
|
|
|
30
21
|
});
|
|
31
22
|
});
|
|
32
23
|
(0, vitest_1.describe)('withRetry', () => {
|
|
33
|
-
(0, vitest_1.it)('should return result on first success', () =>
|
|
24
|
+
(0, vitest_1.it)('should return result on first success', async () => {
|
|
34
25
|
const fn = vitest_1.vi.fn().mockResolvedValue(42);
|
|
35
|
-
const result =
|
|
26
|
+
const result = await (0, retry_1.withRetry)(fn);
|
|
36
27
|
(0, vitest_1.expect)(result).toBe(42);
|
|
37
28
|
(0, vitest_1.expect)(fn).toHaveBeenCalledTimes(1);
|
|
38
|
-
})
|
|
39
|
-
(0, vitest_1.it)('should retry on retryable error then succeed', () =>
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)('should retry on retryable error then succeed', async () => {
|
|
40
31
|
const fn = vitest_1.vi
|
|
41
32
|
.fn()
|
|
42
33
|
.mockRejectedValueOnce(Object.assign(new Error('ECONNRESET'), { code: 'ECONNRESET' }))
|
|
43
34
|
.mockResolvedValueOnce('ok');
|
|
44
|
-
const result =
|
|
35
|
+
const result = await (0, retry_1.withRetry)(fn, { maxRetries: 2, retryDelay: 1 });
|
|
45
36
|
(0, vitest_1.expect)(result).toBe('ok');
|
|
46
37
|
(0, vitest_1.expect)(fn).toHaveBeenCalledTimes(2);
|
|
47
|
-
})
|
|
48
|
-
(0, vitest_1.it)('should not retry on non-retryable error', () =>
|
|
38
|
+
});
|
|
39
|
+
(0, vitest_1.it)('should not retry on non-retryable error', async () => {
|
|
49
40
|
const fn = vitest_1.vi.fn().mockRejectedValue({ response: { status: 400 } });
|
|
50
|
-
|
|
41
|
+
await (0, vitest_1.expect)((0, retry_1.withRetry)(fn)).rejects.toMatchObject({ response: { status: 400 } });
|
|
51
42
|
(0, vitest_1.expect)(fn).toHaveBeenCalledTimes(1);
|
|
52
|
-
})
|
|
43
|
+
});
|
|
53
44
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const secret_string_1 = require("./secret-string");
|
|
9
|
+
(0, vitest_1.describe)('SecretString', () => {
|
|
10
|
+
const secret = new secret_string_1.SecretString('my-secret-token');
|
|
11
|
+
(0, vitest_1.it)('toString() masks the value', () => {
|
|
12
|
+
(0, vitest_1.expect)(secret.toString()).toBe('**********');
|
|
13
|
+
(0, vitest_1.expect)(String(secret)).toBe('**********');
|
|
14
|
+
});
|
|
15
|
+
(0, vitest_1.it)('toJSON() masks the value', () => {
|
|
16
|
+
(0, vitest_1.expect)(secret.toJSON()).toBe('**********');
|
|
17
|
+
(0, vitest_1.expect)(JSON.stringify({ token: secret })).toBe('{"token":"**********"}');
|
|
18
|
+
});
|
|
19
|
+
(0, vitest_1.it)('custom inspect masks the value', () => {
|
|
20
|
+
(0, vitest_1.expect)(node_util_1.default.inspect(secret)).toBe('SecretString(**********)');
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)('expose() returns the underlying value', () => {
|
|
23
|
+
(0, vitest_1.expect)(secret.expose()).toBe('my-secret-token');
|
|
24
|
+
});
|
|
25
|
+
});
|
package/package.json
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Client library for Lightdash AI.",
|
|
5
5
|
"keywords": [],
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/yu-iskw/lightdash-tools.git",
|
|
9
|
+
"directory": "packages/client"
|
|
10
|
+
},
|
|
6
11
|
"license": "Apache-2.0",
|
|
7
12
|
"author": "",
|
|
8
13
|
"main": "dist/index.js",
|
|
9
14
|
"types": "dist/index.d.ts",
|
|
10
15
|
"dependencies": {
|
|
11
|
-
"axios": "^1.
|
|
16
|
+
"axios": "^1.19.0",
|
|
12
17
|
"bottleneck": "^2.19.5",
|
|
13
|
-
"@lightdash-tools/common": "0.
|
|
18
|
+
"@lightdash-tools/common": "0.7.0"
|
|
14
19
|
},
|
|
15
20
|
"devDependencies": {
|
|
16
|
-
"@types/node": "^25.3
|
|
21
|
+
"@types/node": "^25.9.3"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
17
25
|
},
|
|
18
26
|
"scripts": {
|
|
19
27
|
"build": "tsc"
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { recordApplyFailure } from './apply-context';
|
|
2
|
+
|
|
3
|
+
import type { ApplyBundleContext } from './apply-context';
|
|
4
|
+
import type { BundleAgentSpec, BundleDiffChange, CreateAiAgent } from '@lightdash-tools/common';
|
|
5
|
+
|
|
6
|
+
function findDesiredAgent(ctx: ApplyBundleContext, key: string): BundleAgentSpec | undefined {
|
|
7
|
+
return ctx.bundle.spec.agents.find((a) => a.key === key);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function buildCreateAgentBody(desired: BundleAgentSpec, projectUuid: string): CreateAiAgent {
|
|
11
|
+
return {
|
|
12
|
+
name: desired.name,
|
|
13
|
+
projectUuid,
|
|
14
|
+
description: desired.description ?? null,
|
|
15
|
+
instruction: desired.instruction ?? null,
|
|
16
|
+
tags: desired.tags ?? null,
|
|
17
|
+
integrations: [],
|
|
18
|
+
imageUrl: null,
|
|
19
|
+
groupAccess: [],
|
|
20
|
+
userAccess: [],
|
|
21
|
+
spaceAccess: [],
|
|
22
|
+
enableDataAccess: desired.enableDataAccess ?? false,
|
|
23
|
+
enableSelfImprovement: desired.enableSelfImprovement ?? false,
|
|
24
|
+
version: 1,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function applyAgentChange(
|
|
29
|
+
ctx: ApplyBundleContext,
|
|
30
|
+
change: BundleDiffChange,
|
|
31
|
+
): Promise<boolean> {
|
|
32
|
+
const { client, projectUuid, agentUuidByKey } = ctx;
|
|
33
|
+
|
|
34
|
+
if (change.operation === 'create') {
|
|
35
|
+
const desired = findDesiredAgent(ctx, change.key);
|
|
36
|
+
if (!desired) {
|
|
37
|
+
recordApplyFailure(ctx, change, `Agent spec not found for key '${change.key}'`);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const created = await client.v1.aiAgents.createAgent(
|
|
41
|
+
projectUuid,
|
|
42
|
+
buildCreateAgentBody(desired, projectUuid),
|
|
43
|
+
);
|
|
44
|
+
agentUuidByKey.set(desired.key, created.uuid);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (change.operation === 'update') {
|
|
49
|
+
const desired = findDesiredAgent(ctx, change.key);
|
|
50
|
+
if (!desired) {
|
|
51
|
+
recordApplyFailure(ctx, change, `Agent spec not found for key '${change.key}'`);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
const agentUuid = change.agentUuid ?? desired.uuid ?? agentUuidByKey.get(desired.key);
|
|
55
|
+
if (!agentUuid) {
|
|
56
|
+
recordApplyFailure(ctx, change, `Could not resolve agent UUID for key '${change.key}'`);
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
await client.v1.aiAgents.updateAgent(projectUuid, agentUuid, {
|
|
60
|
+
uuid: agentUuid,
|
|
61
|
+
name: desired.name,
|
|
62
|
+
description: desired.description ?? null,
|
|
63
|
+
instruction: desired.instruction ?? null,
|
|
64
|
+
tags: desired.tags ?? null,
|
|
65
|
+
...(desired.enableDataAccess !== undefined
|
|
66
|
+
? { enableDataAccess: desired.enableDataAccess }
|
|
67
|
+
: {}),
|
|
68
|
+
...(desired.enableSelfImprovement !== undefined
|
|
69
|
+
? { enableSelfImprovement: desired.enableSelfImprovement }
|
|
70
|
+
: {}),
|
|
71
|
+
});
|
|
72
|
+
agentUuidByKey.set(desired.key, agentUuid);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (change.operation === 'delete') {
|
|
77
|
+
await client.v1.aiAgents.deleteAgent(projectUuid, change.key);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return false;
|
|
82
|
+
}
|