@lightdash-tools/client 0.1.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/LICENSE +201 -0
- package/README.md +144 -0
- package/dist/api/base-client.d.ts +13 -0
- package/dist/api/base-client.js +17 -0
- package/dist/api/v1/ai-agents.d.ts +17 -0
- package/dist/api/v1/ai-agents.js +47 -0
- package/dist/api/v1/ai-agents.test.d.ts +1 -0
- package/dist/api/v1/ai-agents.test.js +77 -0
- package/dist/api/v1/charts.d.ts +18 -0
- package/dist/api/v1/charts.js +45 -0
- package/dist/api/v1/charts.test.d.ts +1 -0
- package/dist/api/v1/charts.test.js +106 -0
- package/dist/api/v1/dashboards.d.ts +9 -0
- package/dist/api/v1/dashboards.js +25 -0
- package/dist/api/v1/dashboards.test.d.ts +1 -0
- package/dist/api/v1/dashboards.test.js +33 -0
- package/dist/api/v1/explores.d.ts +11 -0
- package/dist/api/v1/explores.js +31 -0
- package/dist/api/v1/explores.test.d.ts +1 -0
- package/dist/api/v1/explores.test.js +46 -0
- package/dist/api/v1/groups.d.ts +42 -0
- package/dist/api/v1/groups.js +81 -0
- package/dist/api/v1/groups.test.d.ts +1 -0
- package/dist/api/v1/groups.test.js +107 -0
- package/dist/api/v1/organizations.d.ts +9 -0
- package/dist/api/v1/organizations.js +25 -0
- package/dist/api/v1/organizations.test.d.ts +1 -0
- package/dist/api/v1/organizations.test.js +33 -0
- package/dist/api/v1/project-access.d.ts +40 -0
- package/dist/api/v1/project-access.js +88 -0
- package/dist/api/v1/project-access.test.d.ts +1 -0
- package/dist/api/v1/project-access.test.js +109 -0
- package/dist/api/v1/projects.d.ts +13 -0
- package/dist/api/v1/projects.js +37 -0
- package/dist/api/v1/projects.test.d.ts +1 -0
- package/dist/api/v1/projects.test.js +49 -0
- package/dist/api/v1/query.d.ts +11 -0
- package/dist/api/v1/query.js +31 -0
- package/dist/api/v1/query.test.d.ts +1 -0
- package/dist/api/v1/query.test.js +51 -0
- package/dist/api/v1/spaces.d.ts +25 -0
- package/dist/api/v1/spaces.js +73 -0
- package/dist/api/v1/spaces.test.d.ts +1 -0
- package/dist/api/v1/spaces.test.js +91 -0
- package/dist/api/v1/users.d.ts +35 -0
- package/dist/api/v1/users.js +66 -0
- package/dist/api/v1/users.test.d.ts +1 -0
- package/dist/api/v1/users.test.js +122 -0
- package/dist/api/v2/organization-roles.d.ts +45 -0
- package/dist/api/v2/organization-roles.js +81 -0
- package/dist/api/v2/organization-roles.test.d.ts +1 -0
- package/dist/api/v2/organization-roles.test.js +112 -0
- package/dist/api/v2/project-role-assignments.d.ts +23 -0
- package/dist/api/v2/project-role-assignments.js +55 -0
- package/dist/api/v2/project-role-assignments.test.d.ts +1 -0
- package/dist/api/v2/project-role-assignments.test.js +66 -0
- package/dist/api/v2/query.d.ts +17 -0
- package/dist/api/v2/query.js +49 -0
- package/dist/api/v2/query.test.d.ts +1 -0
- package/dist/api/v2/query.test.js +78 -0
- package/dist/client.d.ts +118 -0
- package/dist/client.js +113 -0
- package/dist/client.test.d.ts +1 -0
- package/dist/client.test.js +94 -0
- package/dist/config.d.ts +83 -0
- package/dist/config.js +22 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.js +46 -0
- package/dist/errors.test.d.ts +1 -0
- package/dist/errors.test.js +29 -0
- package/dist/http/axios-client.d.ts +22 -0
- package/dist/http/axios-client.js +51 -0
- package/dist/http/http-client.d.ts +33 -0
- package/dist/http/http-client.js +69 -0
- package/dist/http/interceptors.d.ts +13 -0
- package/dist/http/interceptors.js +82 -0
- package/dist/http/rate-limiter.d.ts +23 -0
- package/dist/http/rate-limiter.js +60 -0
- package/dist/http/rate-limiter.test.d.ts +1 -0
- package/dist/http/rate-limiter.test.js +40 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +41 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +65 -0
- package/dist/pagination/fetch-all-pages.d.ts +15 -0
- package/dist/pagination/fetch-all-pages.js +41 -0
- package/dist/pagination/fetch-all-pages.test.d.ts +1 -0
- package/dist/pagination/fetch-all-pages.test.js +70 -0
- package/dist/pagination/types.d.ts +14 -0
- package/dist/pagination/types.js +6 -0
- package/dist/types/api.d.ts +22 -0
- package/dist/types/api.js +8 -0
- package/dist/utils/env.d.ts +20 -0
- package/dist/utils/env.js +59 -0
- package/dist/utils/env.test.d.ts +1 -0
- package/dist/utils/env.test.js +73 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.js +20 -0
- package/dist/utils/retry.d.ts +14 -0
- package/dist/utils/retry.js +67 -0
- package/dist/utils/retry.test.d.ts +1 -0
- package/dist/utils/retry.test.js +53 -0
- package/package.json +21 -0
- package/src/api/base-client.ts +14 -0
- package/src/api/v1/ai-agents.test.ts +74 -0
- package/src/api/v1/ai-agents.ts +41 -0
- package/src/api/v1/charts.test.ts +103 -0
- package/src/api/v1/charts.ts +51 -0
- package/src/api/v1/dashboards.test.ts +26 -0
- package/src/api/v1/dashboards.ts +15 -0
- package/src/api/v1/explores.test.ts +40 -0
- package/src/api/v1/explores.ts +18 -0
- package/src/api/v1/groups.test.ts +108 -0
- package/src/api/v1/groups.ts +100 -0
- package/src/api/v1/organizations.test.ts +26 -0
- package/src/api/v1/organizations.ts +13 -0
- package/src/api/v1/project-access.test.ts +110 -0
- package/src/api/v1/project-access.ts +102 -0
- package/src/api/v1/projects.test.ts +44 -0
- package/src/api/v1/projects.ts +23 -0
- package/src/api/v1/query.test.ts +46 -0
- package/src/api/v1/query.ts +37 -0
- package/src/api/v1/spaces.test.ts +92 -0
- package/src/api/v1/spaces.ts +83 -0
- package/src/api/v1/users.test.ts +125 -0
- package/src/api/v1/users.ts +76 -0
- package/src/api/v2/organization-roles.test.ts +115 -0
- package/src/api/v2/organization-roles.ts +90 -0
- package/src/api/v2/project-role-assignments.test.ts +75 -0
- package/src/api/v2/project-role-assignments.ts +63 -0
- package/src/api/v2/query.test.ts +81 -0
- package/src/api/v2/query.ts +69 -0
- package/src/client.test.ts +105 -0
- package/src/client.ts +182 -0
- package/src/config.ts +113 -0
- package/src/errors.test.ts +45 -0
- package/src/errors.ts +67 -0
- package/src/http/axios-client.ts +59 -0
- package/src/http/http-client.ts +79 -0
- package/src/http/interceptors.ts +110 -0
- package/src/http/rate-limiter.test.ts +34 -0
- package/src/http/rate-limiter.ts +54 -0
- package/src/index.test.ts +91 -0
- package/src/index.ts +41 -0
- package/src/pagination/fetch-all-pages.test.ts +75 -0
- package/src/pagination/fetch-all-pages.ts +39 -0
- package/src/pagination/types.ts +16 -0
- package/src/types/api.ts +28 -0
- package/src/utils/env.test.ts +88 -0
- package/src/utils/env.ts +69 -0
- package/src/utils/logger.ts +21 -0
- package/src/utils/retry.test.ts +49 -0
- package/src/utils/retry.ts +60 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query API client for v2 endpoints. Run metric/SQL/underlying data queries using v2 API.
|
|
4
|
+
*/
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.QueryClientV2 = void 0;
|
|
16
|
+
const base_client_1 = require("../base-client");
|
|
17
|
+
class QueryClientV2 extends base_client_1.BaseApiClient {
|
|
18
|
+
/** Run a metric query (v2 endpoint). */
|
|
19
|
+
runMetricQuery(projectUuid, body) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
return this.http.post(`/projects/${projectUuid}/query/metric-query`, body);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** Run a SQL query (v2 endpoint). */
|
|
25
|
+
runSqlQuery(projectUuid, body) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
return this.http.post(`/projects/${projectUuid}/query/sql`, body);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/** Run a chart query (v2 endpoint). */
|
|
31
|
+
runChartQuery(projectUuid, body) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return this.http.post(`/projects/${projectUuid}/query/chart`, body);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Run a dashboard chart query (v2 endpoint). */
|
|
37
|
+
runDashboardChartQuery(projectUuid, body) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return this.http.post(`/projects/${projectUuid}/query/dashboard-chart`, body);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** Run an underlying data query (v2 endpoint). */
|
|
43
|
+
runUnderlyingDataQuery(projectUuid, body) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
return this.http.post(`/projects/${projectUuid}/query/underlying-data`, body);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.QueryClientV2 = QueryClientV2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const vitest_1 = require("vitest");
|
|
13
|
+
const query_1 = require("./query");
|
|
14
|
+
(0, vitest_1.describe)('QueryClientV2', () => {
|
|
15
|
+
let mockHttp;
|
|
16
|
+
(0, vitest_1.beforeEach)(() => {
|
|
17
|
+
mockHttp = {
|
|
18
|
+
get: vitest_1.vi.fn(),
|
|
19
|
+
post: vitest_1.vi.fn(),
|
|
20
|
+
put: vitest_1.vi.fn(),
|
|
21
|
+
patch: vitest_1.vi.fn(),
|
|
22
|
+
delete: vitest_1.vi.fn(),
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)('runMetricQuery should call POST /projects/{projectUuid}/query/metric-query with body', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
const client = new query_1.QueryClientV2(mockHttp);
|
|
27
|
+
const body = {
|
|
28
|
+
exploreName: 'e1',
|
|
29
|
+
metricQuery: {},
|
|
30
|
+
};
|
|
31
|
+
const results = { queryId: 'q1', status: 'running' };
|
|
32
|
+
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(results);
|
|
33
|
+
const result = yield client.runMetricQuery('p1', body);
|
|
34
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/metric-query', body);
|
|
35
|
+
(0, vitest_1.expect)(result).toEqual(results);
|
|
36
|
+
}));
|
|
37
|
+
(0, vitest_1.it)('runSqlQuery should call POST /projects/{projectUuid}/query/sql with body', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const client = new query_1.QueryClientV2(mockHttp);
|
|
39
|
+
const body = { sql: 'SELECT 1' };
|
|
40
|
+
const results = { queryId: 'q1', status: 'running' };
|
|
41
|
+
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(results);
|
|
42
|
+
const result = yield client.runSqlQuery('p1', body);
|
|
43
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/sql', body);
|
|
44
|
+
(0, vitest_1.expect)(result).toEqual(results);
|
|
45
|
+
}));
|
|
46
|
+
(0, vitest_1.it)('runChartQuery should call POST /projects/{projectUuid}/query/chart with body', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const client = new query_1.QueryClientV2(mockHttp);
|
|
48
|
+
const body = { chartUuid: 'c1' };
|
|
49
|
+
const results = { queryId: 'q1', status: 'running' };
|
|
50
|
+
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(results);
|
|
51
|
+
const result = yield client.runChartQuery('p1', body);
|
|
52
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/chart', body);
|
|
53
|
+
(0, vitest_1.expect)(result).toEqual(results);
|
|
54
|
+
}));
|
|
55
|
+
(0, vitest_1.it)('runDashboardChartQuery should call POST /projects/{projectUuid}/query/dashboard-chart with body', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
const client = new query_1.QueryClientV2(mockHttp);
|
|
57
|
+
const body = {
|
|
58
|
+
dashboardChartUuid: 'dc1',
|
|
59
|
+
};
|
|
60
|
+
const results = { queryId: 'q1', status: 'running' };
|
|
61
|
+
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(results);
|
|
62
|
+
const result = yield client.runDashboardChartQuery('p1', body);
|
|
63
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/dashboard-chart', body);
|
|
64
|
+
(0, vitest_1.expect)(result).toEqual(results);
|
|
65
|
+
}));
|
|
66
|
+
(0, vitest_1.it)('runUnderlyingDataQuery should call POST /projects/{projectUuid}/query/underlying-data with body', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
const client = new query_1.QueryClientV2(mockHttp);
|
|
68
|
+
const body = {
|
|
69
|
+
exploreName: 'e1',
|
|
70
|
+
metricQuery: {},
|
|
71
|
+
};
|
|
72
|
+
const results = { queryId: 'q1', status: 'running' };
|
|
73
|
+
vitest_1.vi.mocked(mockHttp.post).mockResolvedValue(results);
|
|
74
|
+
const result = yield client.runUnderlyingDataQuery('p1', body);
|
|
75
|
+
(0, vitest_1.expect)(mockHttp.post).toHaveBeenCalledWith('/projects/p1/query/underlying-data', body);
|
|
76
|
+
(0, vitest_1.expect)(result).toEqual(results);
|
|
77
|
+
}));
|
|
78
|
+
});
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main Lightdash API client. Configuration can be explicit or loaded from environment variables.
|
|
3
|
+
*/
|
|
4
|
+
import type { PartialLightdashClientConfig } from './config';
|
|
5
|
+
import { HttpClient } from './http/http-client';
|
|
6
|
+
import { ProjectsClient } from './api/v1/projects';
|
|
7
|
+
import { OrganizationsClient } from './api/v1/organizations';
|
|
8
|
+
import { ChartsClient } from './api/v1/charts';
|
|
9
|
+
import { DashboardsClient } from './api/v1/dashboards';
|
|
10
|
+
import { SpacesClient } from './api/v1/spaces';
|
|
11
|
+
import { QueryClient } from './api/v1/query';
|
|
12
|
+
import { QueryClientV2 } from './api/v2/query';
|
|
13
|
+
import { OrganizationRolesClient } from './api/v2/organization-roles';
|
|
14
|
+
import { ProjectRoleAssignmentsClient } from './api/v2/project-role-assignments';
|
|
15
|
+
import { UsersClient } from './api/v1/users';
|
|
16
|
+
import { GroupsClient } from './api/v1/groups';
|
|
17
|
+
import { AiAgentsClient } from './api/v1/ai-agents';
|
|
18
|
+
import { ProjectAccessClient } from './api/v1/project-access';
|
|
19
|
+
import { ExploresClient } from './api/v1/explores';
|
|
20
|
+
/**
|
|
21
|
+
* V1 API clients namespace. Contains all v1 API clients.
|
|
22
|
+
*/
|
|
23
|
+
export declare class V1ApiClients {
|
|
24
|
+
readonly projects: ProjectsClient;
|
|
25
|
+
readonly organizations: OrganizationsClient;
|
|
26
|
+
readonly charts: ChartsClient;
|
|
27
|
+
readonly dashboards: DashboardsClient;
|
|
28
|
+
readonly spaces: SpacesClient;
|
|
29
|
+
readonly query: QueryClient;
|
|
30
|
+
readonly users: UsersClient;
|
|
31
|
+
readonly groups: GroupsClient;
|
|
32
|
+
readonly aiAgents: AiAgentsClient;
|
|
33
|
+
readonly projectAccess: ProjectAccessClient;
|
|
34
|
+
readonly explores: ExploresClient;
|
|
35
|
+
constructor(http: HttpClient);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* V2 API clients namespace. Contains v2-specific API clients.
|
|
39
|
+
*/
|
|
40
|
+
export declare class V2ApiClients {
|
|
41
|
+
readonly query: QueryClientV2;
|
|
42
|
+
readonly organizationRoles: OrganizationRolesClient;
|
|
43
|
+
readonly projectRoleAssignments: ProjectRoleAssignmentsClient;
|
|
44
|
+
constructor(http: HttpClient);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Lightdash HTTP client. Use environment variables (LIGHTDASH_URL, LIGHTDASH_API_KEY)
|
|
48
|
+
* or pass a config object. Explicit config takes priority over env vars.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const client = new LightdashClient({ baseUrl: 'https://app.lightdash.cloud', personalAccessToken: 'token' });
|
|
53
|
+
* // Use v1 namespace
|
|
54
|
+
* const project = await client.v1.projects.getProject('project-uuid');
|
|
55
|
+
* // Use v2 namespace (when available)
|
|
56
|
+
* // const result = await client.v2.query.runMetricQuery(projectUuid, body);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare class LightdashClient {
|
|
60
|
+
private readonly httpV1;
|
|
61
|
+
private readonly httpV2;
|
|
62
|
+
readonly v1: V1ApiClients;
|
|
63
|
+
readonly v2: V2ApiClients;
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Use `client.v1.projects` instead. This alias will be removed in a future major version.
|
|
66
|
+
*/
|
|
67
|
+
readonly projects: ProjectsClient;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Use `client.v1.organizations` instead. This alias will be removed in a future major version.
|
|
70
|
+
*/
|
|
71
|
+
readonly organizations: OrganizationsClient;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Use `client.v1.charts` instead. This alias will be removed in a future major version.
|
|
74
|
+
*/
|
|
75
|
+
readonly charts: ChartsClient;
|
|
76
|
+
/**
|
|
77
|
+
* @deprecated Use `client.v1.dashboards` instead. This alias will be removed in a future major version.
|
|
78
|
+
*/
|
|
79
|
+
readonly dashboards: DashboardsClient;
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated Use `client.v1.spaces` instead. This alias will be removed in a future major version.
|
|
82
|
+
*/
|
|
83
|
+
readonly spaces: SpacesClient;
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Use `client.v1.query` instead. This alias will be removed in a future major version.
|
|
86
|
+
*/
|
|
87
|
+
readonly query: QueryClient;
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use `client.v1.users` instead. This alias will be removed in a future major version.
|
|
90
|
+
*/
|
|
91
|
+
readonly users: UsersClient;
|
|
92
|
+
/**
|
|
93
|
+
* @deprecated Use `client.v1.groups` instead. This alias will be removed in a future major version.
|
|
94
|
+
*/
|
|
95
|
+
readonly groups: GroupsClient;
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use `client.v1.aiAgents` instead. This alias will be removed in a future major version.
|
|
98
|
+
*/
|
|
99
|
+
readonly aiAgents: AiAgentsClient;
|
|
100
|
+
/**
|
|
101
|
+
* @deprecated Use `client.v1.explores` instead. This alias will be removed in a future major version.
|
|
102
|
+
*/
|
|
103
|
+
readonly explores: ExploresClient;
|
|
104
|
+
constructor(config?: PartialLightdashClientConfig);
|
|
105
|
+
/**
|
|
106
|
+
* Low-level HTTP client for custom v1 requests. Prefer domain methods (e.g. v1.projects, v1.charts) when available.
|
|
107
|
+
* @deprecated Use `getHttpClientV1()` instead. This method will be removed in a future major version.
|
|
108
|
+
*/
|
|
109
|
+
getHttpClient(): HttpClient;
|
|
110
|
+
/**
|
|
111
|
+
* Low-level HTTP client for custom v1 requests. Prefer domain methods (e.g. v1.projects, v1.charts) when available.
|
|
112
|
+
*/
|
|
113
|
+
getHttpClientV1(): HttpClient;
|
|
114
|
+
/**
|
|
115
|
+
* Low-level HTTP client for custom v2 requests. Prefer domain methods (e.g. v2.query) when available.
|
|
116
|
+
*/
|
|
117
|
+
getHttpClientV2(): HttpClient;
|
|
118
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Main Lightdash API client. Configuration can be explicit or loaded from environment variables.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LightdashClient = exports.V2ApiClients = exports.V1ApiClients = void 0;
|
|
7
|
+
const env_1 = require("./utils/env");
|
|
8
|
+
const axios_client_1 = require("./http/axios-client");
|
|
9
|
+
const rate_limiter_1 = require("./http/rate-limiter");
|
|
10
|
+
const http_client_1 = require("./http/http-client");
|
|
11
|
+
const projects_1 = require("./api/v1/projects");
|
|
12
|
+
const organizations_1 = require("./api/v1/organizations");
|
|
13
|
+
const charts_1 = require("./api/v1/charts");
|
|
14
|
+
const dashboards_1 = require("./api/v1/dashboards");
|
|
15
|
+
const spaces_1 = require("./api/v1/spaces");
|
|
16
|
+
const query_1 = require("./api/v1/query");
|
|
17
|
+
const query_2 = require("./api/v2/query");
|
|
18
|
+
const organization_roles_1 = require("./api/v2/organization-roles");
|
|
19
|
+
const project_role_assignments_1 = require("./api/v2/project-role-assignments");
|
|
20
|
+
const users_1 = require("./api/v1/users");
|
|
21
|
+
const groups_1 = require("./api/v1/groups");
|
|
22
|
+
const ai_agents_1 = require("./api/v1/ai-agents");
|
|
23
|
+
const project_access_1 = require("./api/v1/project-access");
|
|
24
|
+
const explores_1 = require("./api/v1/explores");
|
|
25
|
+
/**
|
|
26
|
+
* V1 API clients namespace. Contains all v1 API clients.
|
|
27
|
+
*/
|
|
28
|
+
class V1ApiClients {
|
|
29
|
+
constructor(http) {
|
|
30
|
+
this.projects = new projects_1.ProjectsClient(http);
|
|
31
|
+
this.organizations = new organizations_1.OrganizationsClient(http);
|
|
32
|
+
this.charts = new charts_1.ChartsClient(http);
|
|
33
|
+
this.dashboards = new dashboards_1.DashboardsClient(http);
|
|
34
|
+
this.spaces = new spaces_1.SpacesClient(http);
|
|
35
|
+
this.query = new query_1.QueryClient(http);
|
|
36
|
+
this.users = new users_1.UsersClient(http);
|
|
37
|
+
this.groups = new groups_1.GroupsClient(http);
|
|
38
|
+
this.aiAgents = new ai_agents_1.AiAgentsClient(http);
|
|
39
|
+
this.projectAccess = new project_access_1.ProjectAccessClient(http);
|
|
40
|
+
this.explores = new explores_1.ExploresClient(http);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.V1ApiClients = V1ApiClients;
|
|
44
|
+
/**
|
|
45
|
+
* V2 API clients namespace. Contains v2-specific API clients.
|
|
46
|
+
*/
|
|
47
|
+
class V2ApiClients {
|
|
48
|
+
constructor(http) {
|
|
49
|
+
this.query = new query_2.QueryClientV2(http);
|
|
50
|
+
this.organizationRoles = new organization_roles_1.OrganizationRolesClient(http);
|
|
51
|
+
this.projectRoleAssignments = new project_role_assignments_1.ProjectRoleAssignmentsClient(http);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.V2ApiClients = V2ApiClients;
|
|
55
|
+
/**
|
|
56
|
+
* Lightdash HTTP client. Use environment variables (LIGHTDASH_URL, LIGHTDASH_API_KEY)
|
|
57
|
+
* or pass a config object. Explicit config takes priority over env vars.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const client = new LightdashClient({ baseUrl: 'https://app.lightdash.cloud', personalAccessToken: 'token' });
|
|
62
|
+
* // Use v1 namespace
|
|
63
|
+
* const project = await client.v1.projects.getProject('project-uuid');
|
|
64
|
+
* // Use v2 namespace (when available)
|
|
65
|
+
* // const result = await client.v2.query.runMetricQuery(projectUuid, body);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
class LightdashClient {
|
|
69
|
+
constructor(config) {
|
|
70
|
+
const merged = (0, env_1.mergeConfig)(config);
|
|
71
|
+
const rateLimiter = new rate_limiter_1.RateLimiter(merged.rateLimit);
|
|
72
|
+
// Create v1 HTTP client
|
|
73
|
+
const axiosInstanceV1 = (0, axios_client_1.createAxiosInstanceV1)(merged);
|
|
74
|
+
this.httpV1 = new http_client_1.HttpClient(axiosInstanceV1, rateLimiter, merged);
|
|
75
|
+
// Create v2 HTTP client
|
|
76
|
+
const axiosInstanceV2 = (0, axios_client_1.createAxiosInstanceV2)(merged);
|
|
77
|
+
this.httpV2 = new http_client_1.HttpClient(axiosInstanceV2, rateLimiter, merged);
|
|
78
|
+
// Create versioned namespaces
|
|
79
|
+
this.v1 = new V1ApiClients(this.httpV1);
|
|
80
|
+
this.v2 = new V2ApiClients(this.httpV2);
|
|
81
|
+
// Backward compatibility: deprecated aliases delegate to v1
|
|
82
|
+
this.projects = this.v1.projects;
|
|
83
|
+
this.organizations = this.v1.organizations;
|
|
84
|
+
this.charts = this.v1.charts;
|
|
85
|
+
this.dashboards = this.v1.dashboards;
|
|
86
|
+
this.spaces = this.v1.spaces;
|
|
87
|
+
this.query = this.v1.query;
|
|
88
|
+
this.users = this.v1.users;
|
|
89
|
+
this.groups = this.v1.groups;
|
|
90
|
+
this.aiAgents = this.v1.aiAgents;
|
|
91
|
+
this.explores = this.v1.explores;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Low-level HTTP client for custom v1 requests. Prefer domain methods (e.g. v1.projects, v1.charts) when available.
|
|
95
|
+
* @deprecated Use `getHttpClientV1()` instead. This method will be removed in a future major version.
|
|
96
|
+
*/
|
|
97
|
+
getHttpClient() {
|
|
98
|
+
return this.httpV1;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Low-level HTTP client for custom v1 requests. Prefer domain methods (e.g. v1.projects, v1.charts) when available.
|
|
102
|
+
*/
|
|
103
|
+
getHttpClientV1() {
|
|
104
|
+
return this.httpV1;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Low-level HTTP client for custom v2 requests. Prefer domain methods (e.g. v2.query) when available.
|
|
108
|
+
*/
|
|
109
|
+
getHttpClientV2() {
|
|
110
|
+
return this.httpV2;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.LightdashClient = LightdashClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
(0, vitest_1.describe)('LightdashClient', () => {
|
|
6
|
+
const config = {
|
|
7
|
+
baseUrl: 'https://app.lightdash.cloud',
|
|
8
|
+
personalAccessToken: 'test-token',
|
|
9
|
+
};
|
|
10
|
+
(0, vitest_1.beforeEach)(() => {
|
|
11
|
+
vitest_1.vi.resetModules();
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.describe)('V1 namespace', () => {
|
|
14
|
+
(0, vitest_1.it)('should expose v1 namespace with all API clients', () => {
|
|
15
|
+
const client = new client_1.LightdashClient(config);
|
|
16
|
+
(0, vitest_1.expect)(client.v1).toBeDefined();
|
|
17
|
+
(0, vitest_1.expect)(client.v1.projects).toBeDefined();
|
|
18
|
+
(0, vitest_1.expect)(client.v1.organizations).toBeDefined();
|
|
19
|
+
(0, vitest_1.expect)(client.v1.charts).toBeDefined();
|
|
20
|
+
(0, vitest_1.expect)(client.v1.dashboards).toBeDefined();
|
|
21
|
+
(0, vitest_1.expect)(client.v1.spaces).toBeDefined();
|
|
22
|
+
(0, vitest_1.expect)(client.v1.query).toBeDefined();
|
|
23
|
+
(0, vitest_1.expect)(client.v1.users).toBeDefined();
|
|
24
|
+
(0, vitest_1.expect)(client.v1.groups).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
(0, vitest_1.it)('v1.projects.getProject should be a function', () => {
|
|
27
|
+
const client = new client_1.LightdashClient(config);
|
|
28
|
+
(0, vitest_1.expect)(typeof client.v1.projects.getProject).toBe('function');
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)('v1.organizations.getCurrentOrganization should be a function', () => {
|
|
31
|
+
const client = new client_1.LightdashClient(config);
|
|
32
|
+
(0, vitest_1.expect)(typeof client.v1.organizations.getCurrentOrganization).toBe('function');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.describe)('V2 namespace', () => {
|
|
36
|
+
(0, vitest_1.it)('should expose v2 namespace', () => {
|
|
37
|
+
const client = new client_1.LightdashClient(config);
|
|
38
|
+
(0, vitest_1.expect)(client.v2).toBeDefined();
|
|
39
|
+
(0, vitest_1.expect)(client.v2.query).toBeDefined();
|
|
40
|
+
});
|
|
41
|
+
(0, vitest_1.it)('v2.query.runMetricQuery should be a function', () => {
|
|
42
|
+
const client = new client_1.LightdashClient(config);
|
|
43
|
+
(0, vitest_1.expect)(typeof client.v2.query.runMetricQuery).toBe('function');
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('v2.query.runSqlQuery should be a function', () => {
|
|
46
|
+
const client = new client_1.LightdashClient(config);
|
|
47
|
+
(0, vitest_1.expect)(typeof client.v2.query.runSqlQuery).toBe('function');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
(0, vitest_1.describe)('Backward compatibility (deprecated aliases)', () => {
|
|
51
|
+
(0, vitest_1.it)('should expose deprecated top-level aliases that delegate to v1', () => {
|
|
52
|
+
const client = new client_1.LightdashClient(config);
|
|
53
|
+
(0, vitest_1.expect)(client.projects).toBeDefined();
|
|
54
|
+
(0, vitest_1.expect)(client.organizations).toBeDefined();
|
|
55
|
+
(0, vitest_1.expect)(client.charts).toBeDefined();
|
|
56
|
+
(0, vitest_1.expect)(client.dashboards).toBeDefined();
|
|
57
|
+
(0, vitest_1.expect)(client.spaces).toBeDefined();
|
|
58
|
+
(0, vitest_1.expect)(client.query).toBeDefined();
|
|
59
|
+
(0, vitest_1.expect)(client.users).toBeDefined();
|
|
60
|
+
(0, vitest_1.expect)(client.groups).toBeDefined();
|
|
61
|
+
});
|
|
62
|
+
(0, vitest_1.it)('deprecated aliases should reference v1 clients', () => {
|
|
63
|
+
const client = new client_1.LightdashClient(config);
|
|
64
|
+
(0, vitest_1.expect)(client.projects).toBe(client.v1.projects);
|
|
65
|
+
(0, vitest_1.expect)(client.organizations).toBe(client.v1.organizations);
|
|
66
|
+
(0, vitest_1.expect)(client.charts).toBe(client.v1.charts);
|
|
67
|
+
(0, vitest_1.expect)(client.dashboards).toBe(client.v1.dashboards);
|
|
68
|
+
(0, vitest_1.expect)(client.spaces).toBe(client.v1.spaces);
|
|
69
|
+
(0, vitest_1.expect)(client.query).toBe(client.v1.query);
|
|
70
|
+
(0, vitest_1.expect)(client.users).toBe(client.v1.users);
|
|
71
|
+
(0, vitest_1.expect)(client.groups).toBe(client.v1.groups);
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.it)('deprecated projects.getProject should work', () => {
|
|
74
|
+
const client = new client_1.LightdashClient(config);
|
|
75
|
+
(0, vitest_1.expect)(typeof client.projects.getProject).toBe('function');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
(0, vitest_1.describe)('HTTP clients', () => {
|
|
79
|
+
(0, vitest_1.it)('should provide separate HTTP clients for v1 and v2', () => {
|
|
80
|
+
const client = new client_1.LightdashClient(config);
|
|
81
|
+
const httpV1 = client.getHttpClientV1();
|
|
82
|
+
const httpV2 = client.getHttpClientV2();
|
|
83
|
+
(0, vitest_1.expect)(httpV1).toBeDefined();
|
|
84
|
+
(0, vitest_1.expect)(httpV2).toBeDefined();
|
|
85
|
+
(0, vitest_1.expect)(httpV1).not.toBe(httpV2);
|
|
86
|
+
});
|
|
87
|
+
(0, vitest_1.it)('getHttpClient should return v1 client (deprecated)', () => {
|
|
88
|
+
const client = new client_1.LightdashClient(config);
|
|
89
|
+
const http = client.getHttpClient();
|
|
90
|
+
const httpV1 = client.getHttpClientV1();
|
|
91
|
+
(0, vitest_1.expect)(http).toBe(httpV1);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration types for the Lightdash HTTP client.
|
|
3
|
+
* Supports explicit config and environment variables (LIGHTDASH_API_KEY, LIGHTDASH_URL, LIGHTDASH_PROXY_AUTHORIZATION).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Rate limit configuration for Bottleneck (token bucket algorithm).
|
|
7
|
+
*/
|
|
8
|
+
export interface RateLimitConfig {
|
|
9
|
+
/** Minimum time between requests in milliseconds (e.g. 100 = 10 req/sec max). */
|
|
10
|
+
minTime?: number;
|
|
11
|
+
/** Maximum concurrent requests. */
|
|
12
|
+
maxConcurrent?: number;
|
|
13
|
+
/** Token bucket size (burst capacity). */
|
|
14
|
+
reservoir?: number;
|
|
15
|
+
/** Token refresh interval in milliseconds. */
|
|
16
|
+
reservoirRefreshInterval?: number;
|
|
17
|
+
/** Number of tokens added per refresh. */
|
|
18
|
+
reservoirRefreshAmount?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Retry configuration for transient failures.
|
|
22
|
+
*/
|
|
23
|
+
export interface RetryConfig {
|
|
24
|
+
/** Maximum number of retries for 5xx and network errors. */
|
|
25
|
+
maxRetries?: number;
|
|
26
|
+
/** Base delay in ms for exponential backoff. */
|
|
27
|
+
retryDelay?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Logger interface for optional request/response logging.
|
|
31
|
+
*/
|
|
32
|
+
export interface Logger {
|
|
33
|
+
debug?(message: string, ...args: unknown[]): void;
|
|
34
|
+
info?(message: string, ...args: unknown[]): void;
|
|
35
|
+
warn?(message: string, ...args: unknown[]): void;
|
|
36
|
+
error?(message: string, ...args: unknown[]): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Optional hooks for metrics/telemetry. Called after each request completes.
|
|
40
|
+
*/
|
|
41
|
+
export interface ObservabilityHooks {
|
|
42
|
+
/** Called when a request completes (success or error). */
|
|
43
|
+
onRequestComplete?(info: {
|
|
44
|
+
method: string;
|
|
45
|
+
url: string;
|
|
46
|
+
statusCode?: number;
|
|
47
|
+
durationMs: number;
|
|
48
|
+
error?: Error;
|
|
49
|
+
}): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Full configuration for the Lightdash HTTP client.
|
|
53
|
+
* All fields except rateLimit, timeout, retry, and logger can be provided via environment variables.
|
|
54
|
+
*/
|
|
55
|
+
export interface LightdashClientConfig {
|
|
56
|
+
/** Lightdash server base URL (e.g. https://app.lightdash.cloud). */
|
|
57
|
+
baseUrl: string;
|
|
58
|
+
/** Personal access token for API authentication (without ldpat_ prefix). */
|
|
59
|
+
personalAccessToken: string;
|
|
60
|
+
/** Optional proxy authorization header value for proxied access. */
|
|
61
|
+
proxyAuthorization?: string;
|
|
62
|
+
/** Override default rate limits. */
|
|
63
|
+
rateLimit?: RateLimitConfig;
|
|
64
|
+
/** Request timeout in milliseconds. Default 30000. */
|
|
65
|
+
timeout?: number;
|
|
66
|
+
/** Retry behavior for transient failures. */
|
|
67
|
+
retry?: RetryConfig;
|
|
68
|
+
/** Optional logger for request/response logging. */
|
|
69
|
+
logger?: Logger;
|
|
70
|
+
/** Optional hooks for metrics/telemetry. */
|
|
71
|
+
observability?: ObservabilityHooks;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Partial config for merging with environment variables.
|
|
75
|
+
* Used when constructing the client with optional explicit overrides.
|
|
76
|
+
*/
|
|
77
|
+
export type PartialLightdashClientConfig = Partial<Pick<LightdashClientConfig, 'baseUrl' | 'personalAccessToken' | 'proxyAuthorization' | 'rateLimit' | 'timeout' | 'retry' | 'logger' | 'observability'>>;
|
|
78
|
+
/** Default rate limit: 10 req/sec, 5 concurrent, token bucket. */
|
|
79
|
+
export declare const DEFAULT_RATE_LIMIT: Required<RateLimitConfig>;
|
|
80
|
+
/** Default request timeout in ms. */
|
|
81
|
+
export declare const DEFAULT_TIMEOUT = 30000;
|
|
82
|
+
/** Default retry config. */
|
|
83
|
+
export declare const DEFAULT_RETRY: Required<RetryConfig>;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration types for the Lightdash HTTP client.
|
|
4
|
+
* Supports explicit config and environment variables (LIGHTDASH_API_KEY, LIGHTDASH_URL, LIGHTDASH_PROXY_AUTHORIZATION).
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DEFAULT_RETRY = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RATE_LIMIT = void 0;
|
|
8
|
+
/** Default rate limit: 10 req/sec, 5 concurrent, token bucket. */
|
|
9
|
+
exports.DEFAULT_RATE_LIMIT = {
|
|
10
|
+
minTime: 100,
|
|
11
|
+
maxConcurrent: 5,
|
|
12
|
+
reservoir: 100,
|
|
13
|
+
reservoirRefreshInterval: 1000,
|
|
14
|
+
reservoirRefreshAmount: 10,
|
|
15
|
+
};
|
|
16
|
+
/** Default request timeout in ms. */
|
|
17
|
+
exports.DEFAULT_TIMEOUT = 30000;
|
|
18
|
+
/** Default retry config. */
|
|
19
|
+
exports.DEFAULT_RETRY = {
|
|
20
|
+
maxRetries: 3,
|
|
21
|
+
retryDelay: 1000,
|
|
22
|
+
};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error types for the Lightdash HTTP client.
|
|
3
|
+
*/
|
|
4
|
+
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
5
|
+
/** API error payload shape (from Lightdash ApiErrorPayload). */
|
|
6
|
+
export interface ApiErrorPayload {
|
|
7
|
+
error: {
|
|
8
|
+
name: string;
|
|
9
|
+
statusCode: number;
|
|
10
|
+
message?: string;
|
|
11
|
+
data?: unknown;
|
|
12
|
+
};
|
|
13
|
+
status: 'error';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Base error for Lightdash API failures.
|
|
17
|
+
*/
|
|
18
|
+
export declare class LightdashApiError extends Error {
|
|
19
|
+
readonly statusCode: number;
|
|
20
|
+
readonly error: ApiErrorPayload['error'];
|
|
21
|
+
readonly request: AxiosRequestConfig;
|
|
22
|
+
readonly response?: AxiosResponse<ApiErrorPayload> | undefined;
|
|
23
|
+
constructor(statusCode: number, error: ApiErrorPayload['error'], request: AxiosRequestConfig, response?: AxiosResponse<ApiErrorPayload> | undefined);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error when the API returns 429 Too Many Requests.
|
|
27
|
+
*/
|
|
28
|
+
export declare class RateLimitError extends LightdashApiError {
|
|
29
|
+
/** Seconds to wait before retrying (from Retry-After header if present). */
|
|
30
|
+
readonly retryAfter?: number;
|
|
31
|
+
constructor(statusCode: number, error: ApiErrorPayload['error'], request: AxiosRequestConfig, response?: AxiosResponse<ApiErrorPayload>, retryAfter?: number);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Wrapper for network/connection errors.
|
|
35
|
+
*/
|
|
36
|
+
export declare class NetworkError extends Error {
|
|
37
|
+
readonly originalError: Error;
|
|
38
|
+
constructor(message: string, originalError: Error);
|
|
39
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error types for the Lightdash HTTP client.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NetworkError = exports.RateLimitError = exports.LightdashApiError = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Base error for Lightdash API failures.
|
|
9
|
+
*/
|
|
10
|
+
class LightdashApiError extends Error {
|
|
11
|
+
constructor(statusCode, error, request, response) {
|
|
12
|
+
var _a;
|
|
13
|
+
super((_a = error.message) !== null && _a !== void 0 ? _a : `Lightdash API error: ${statusCode}`);
|
|
14
|
+
this.statusCode = statusCode;
|
|
15
|
+
this.error = error;
|
|
16
|
+
this.request = request;
|
|
17
|
+
this.response = response;
|
|
18
|
+
this.name = 'LightdashApiError';
|
|
19
|
+
Object.setPrototypeOf(this, LightdashApiError.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.LightdashApiError = LightdashApiError;
|
|
23
|
+
/**
|
|
24
|
+
* Error when the API returns 429 Too Many Requests.
|
|
25
|
+
*/
|
|
26
|
+
class RateLimitError extends LightdashApiError {
|
|
27
|
+
constructor(statusCode, error, request, response, retryAfter) {
|
|
28
|
+
super(statusCode, error, request, response);
|
|
29
|
+
this.name = 'RateLimitError';
|
|
30
|
+
this.retryAfter = retryAfter;
|
|
31
|
+
Object.setPrototypeOf(this, RateLimitError.prototype);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.RateLimitError = RateLimitError;
|
|
35
|
+
/**
|
|
36
|
+
* Wrapper for network/connection errors.
|
|
37
|
+
*/
|
|
38
|
+
class NetworkError extends Error {
|
|
39
|
+
constructor(message, originalError) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.originalError = originalError;
|
|
42
|
+
this.name = 'NetworkError';
|
|
43
|
+
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.NetworkError = NetworkError;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|