@lightdash-tools/client 0.1.2 → 0.2.4
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/index.d.ts +9 -0
- package/dist/index.js +11 -1
- 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/index.ts +9 -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/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';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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.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; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.4",
|
|
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.4"
|
|
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
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { TagsClient } from './tags';
|
|
3
|
+
import type { HttpClient } from '../../http/http-client';
|
|
4
|
+
|
|
5
|
+
describe('TagsClient', () => {
|
|
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('listTags should call GET /projects/{projectUuid}/tags', async () => {
|
|
19
|
+
const client = new TagsClient(mockHttp);
|
|
20
|
+
const mockResponse = { status: 'ok', results: [] };
|
|
21
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
22
|
+
const result = await client.listTags('p1');
|
|
23
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/tags');
|
|
24
|
+
expect(result).toEqual(mockResponse);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('getTag should call GET /projects/{projectUuid}/tags/{tagUuid}', async () => {
|
|
28
|
+
const client = new TagsClient(mockHttp);
|
|
29
|
+
const mockResponse = { status: 'ok', results: {} };
|
|
30
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
31
|
+
const result = await client.getTag('p1', 't1');
|
|
32
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/tags/t1');
|
|
33
|
+
expect(result).toEqual(mockResponse);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tags API client.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { LightdashApi } from '@lightdash-tools/common';
|
|
6
|
+
import { BaseApiClient } from '../base-client';
|
|
7
|
+
|
|
8
|
+
export class TagsClient extends BaseApiClient {
|
|
9
|
+
/** List tags in a project. */
|
|
10
|
+
async listTags(projectUuid: string): Promise<LightdashApi.Tags.ApiGetTagsResponse> {
|
|
11
|
+
return this.http.get<LightdashApi.Tags.ApiGetTagsResponse>(`/projects/${projectUuid}/tags`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Get a tag by UUID. */
|
|
15
|
+
async getTag(projectUuid: string, tagUuid: string): Promise<LightdashApi.Tags.ApiGetTagResponse> {
|
|
16
|
+
return this.http.get<LightdashApi.Tags.ApiGetTagResponse>(
|
|
17
|
+
`/projects/${projectUuid}/tags/${tagUuid}`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { ValidationClient } from './validation';
|
|
3
|
+
import type { HttpClient } from '../../http/http-client';
|
|
4
|
+
|
|
5
|
+
describe('ValidationClient', () => {
|
|
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('getValidationResults should call GET /projects/{projectUuid}/validate', async () => {
|
|
19
|
+
const client = new ValidationClient(mockHttp);
|
|
20
|
+
const mockResponse = { status: 'ok', results: [] };
|
|
21
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
22
|
+
const result = await client.getValidationResults('p1', { jobId: 'j1' });
|
|
23
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/validate', {
|
|
24
|
+
params: { jobId: 'j1' },
|
|
25
|
+
});
|
|
26
|
+
expect(result).toEqual(mockResponse);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('validateProject should call POST /projects/{projectUuid}/validate', async () => {
|
|
30
|
+
const client = new ValidationClient(mockHttp);
|
|
31
|
+
const mockResponse = { status: 'ok', results: { jobId: 'j1' } };
|
|
32
|
+
vi.mocked(mockHttp.post).mockResolvedValue(mockResponse);
|
|
33
|
+
const result = await client.validateProject('p1');
|
|
34
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/validate', undefined);
|
|
35
|
+
expect(result).toEqual(mockResponse);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation API client.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { LightdashApi } from '@lightdash-tools/common';
|
|
6
|
+
import { BaseApiClient } from '../base-client';
|
|
7
|
+
|
|
8
|
+
/** Query params for getting validation results. */
|
|
9
|
+
export interface GetValidationResultsParams {
|
|
10
|
+
fromSettings?: boolean;
|
|
11
|
+
jobId?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Body for triggering project validation. */
|
|
15
|
+
export interface ValidateProjectBody {
|
|
16
|
+
validationTargets?: LightdashApi.Validation.ValidationTarget[];
|
|
17
|
+
explores?: unknown[];
|
|
18
|
+
onlyValidateExploresInArgs?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class ValidationClient extends BaseApiClient {
|
|
22
|
+
/** Get validation results for a project. */
|
|
23
|
+
async getValidationResults(
|
|
24
|
+
projectUuid: string,
|
|
25
|
+
params?: GetValidationResultsParams,
|
|
26
|
+
): Promise<LightdashApi.Validation.ApiValidateResponse> {
|
|
27
|
+
return this.http.get<LightdashApi.Validation.ApiValidateResponse>(
|
|
28
|
+
`/projects/${projectUuid}/validate`,
|
|
29
|
+
{ params },
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Validate content inside a project. Starts a validation job and returns the job ID. */
|
|
34
|
+
async validateProject(
|
|
35
|
+
projectUuid: string,
|
|
36
|
+
body?: ValidateProjectBody,
|
|
37
|
+
): Promise<LightdashApi.Validation.ApiJobScheduledResponse> {
|
|
38
|
+
return this.http.post<LightdashApi.Validation.ApiJobScheduledResponse>(
|
|
39
|
+
`/projects/${projectUuid}/validate`,
|
|
40
|
+
body,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { ContentClient } from './content';
|
|
3
|
+
import type { HttpClient } from '../../http/http-client';
|
|
4
|
+
|
|
5
|
+
describe('ContentClient', () => {
|
|
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('searchContent should call GET /content', async () => {
|
|
19
|
+
const client = new ContentClient(mockHttp);
|
|
20
|
+
const mockResponse = { status: 'ok', results: [] };
|
|
21
|
+
vi.mocked(mockHttp.get).mockResolvedValue(mockResponse);
|
|
22
|
+
const result = await client.searchContent({ search: 'test' });
|
|
23
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/content', {
|
|
24
|
+
params: { search: 'test' },
|
|
25
|
+
});
|
|
26
|
+
expect(result).toEqual(mockResponse);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content API client (v2).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { LightdashApi } from '@lightdash-tools/common';
|
|
6
|
+
import { BaseApiClient } from '../base-client';
|
|
7
|
+
|
|
8
|
+
/** Query params for searching content. */
|
|
9
|
+
export interface SearchContentParams {
|
|
10
|
+
projectUuids?: string[];
|
|
11
|
+
spaceUuids?: string[];
|
|
12
|
+
parentSpaceUuid?: string;
|
|
13
|
+
contentTypes?: ('chart' | 'dashboard' | 'space')[];
|
|
14
|
+
pageSize?: number;
|
|
15
|
+
page?: number;
|
|
16
|
+
search?: string;
|
|
17
|
+
sortBy?: 'name' | 'createdAt' | 'updatedAt' | 'lastViewedAt' | 'views';
|
|
18
|
+
sortDirection?: 'asc' | 'desc';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class ContentClient extends BaseApiClient {
|
|
22
|
+
/** Search project content (charts, dashboards, spaces). */
|
|
23
|
+
async searchContent(
|
|
24
|
+
params?: SearchContentParams,
|
|
25
|
+
): Promise<LightdashApi.Content.ApiContentResponse> {
|
|
26
|
+
return this.http.get<LightdashApi.Content.ApiContentResponse>('/content', {
|
|
27
|
+
params,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|