@lightdash-tools/client 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/v1/ai-agents/discovery.d.ts +7 -2
- package/dist/api/v1/ai-agents/discovery.js +3 -6
- package/dist/api/v1/ai-agents/discovery.test.js +17 -1
- package/dist/api/v1/ai-agents/facade.d.ts +5 -0
- package/dist/api/v1/ai-agents/facade.js +5 -2
- package/dist/api/v1/charts.d.ts +28 -1
- package/dist/api/v1/charts.js +51 -1
- package/dist/api/v1/charts.test.js +59 -6
- package/dist/api/v1/dashboards.d.ts +32 -1
- package/dist/api/v1/dashboards.js +20 -0
- package/dist/api/v1/dashboards.test.js +72 -0
- package/dist/api/v1/validation.d.ts +5 -1
- package/dist/api/v1/validation.js +8 -0
- package/dist/api/v1/validation.test.js +16 -0
- package/dist/api/v2/charts.d.ts +12 -0
- package/dist/api/v2/charts.js +18 -0
- package/dist/api/v2/charts.test.d.ts +4 -0
- package/dist/api/v2/charts.test.js +45 -0
- package/dist/api/v2/content.d.ts +19 -2
- package/dist/api/v2/content.js +15 -0
- package/dist/api/v2/content.test.js +41 -0
- package/dist/api/v2/dashboards.d.ts +7 -1
- package/dist/api/v2/dashboards.js +9 -1
- package/dist/api/v2/dashboards.test.js +34 -0
- package/dist/api/v2/parameters.d.ts +20 -0
- package/dist/api/v2/parameters.js +22 -0
- package/dist/api/v2/parameters.test.d.ts +4 -0
- package/dist/api/v2/parameters.test.js +39 -0
- package/dist/api/v2/query.d.ts +16 -1
- package/dist/api/v2/query.js +16 -0
- package/dist/api/v2/query.test.js +16 -0
- package/dist/client.d.ts +4 -0
- package/dist/client.js +4 -0
- package/dist/client.test.js +2 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +37 -1
- package/dist/http/http-client.binary-url.test.d.ts +4 -0
- package/dist/http/http-client.binary-url.test.js +61 -0
- package/dist/http/http-client.d.ts +23 -11
- package/dist/http/http-client.envelope.test.d.ts +4 -0
- package/dist/http/http-client.envelope.test.js +59 -0
- package/dist/http/http-client.js +155 -6
- package/dist/http/unwrap-api-success.d.ts +26 -0
- package/dist/http/unwrap-api-success.js +25 -0
- package/dist/http/unwrap-api-success.test.d.ts +1 -0
- package/dist/http/unwrap-api-success.test.js +19 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.js +17 -3
- package/package.json +2 -2
- package/src/api/v1/ai-agents/discovery.test.ts +19 -1
- package/src/api/v1/ai-agents/discovery.ts +17 -3
- package/src/api/v1/ai-agents/facade.ts +17 -1
- package/src/api/v1/charts.test.ts +61 -1
- package/src/api/v1/charts.ts +68 -0
- package/src/api/v1/dashboards.test.ts +85 -0
- package/src/api/v1/dashboards.ts +86 -0
- package/src/api/v1/validation.test.ts +18 -0
- package/src/api/v1/validation.ts +21 -1
- package/src/api/v2/charts.test.ts +53 -0
- package/src/api/v2/charts.ts +23 -0
- package/src/api/v2/content.test.ts +45 -0
- package/src/api/v2/content.ts +35 -2
- package/src/api/v2/dashboards.test.ts +39 -0
- package/src/api/v2/dashboards.ts +23 -1
- package/src/api/v2/parameters.test.ts +45 -0
- package/src/api/v2/parameters.ts +38 -0
- package/src/api/v2/query.test.ts +18 -0
- package/src/api/v2/query.ts +53 -0
- package/src/client.test.ts +2 -0
- package/src/client.ts +6 -0
- package/src/errors.ts +46 -0
- package/src/http/http-client.binary-url.test.ts +88 -0
- package/src/http/http-client.envelope.test.ts +74 -0
- package/src/http/http-client.ts +194 -16
- package/src/http/unwrap-api-success.test.ts +23 -0
- package/src/http/unwrap-api-success.ts +40 -0
- package/src/index.ts +40 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unit tests for HttpClient success-envelope harden.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const errors_js_1 = require("../errors.js");
|
|
8
|
+
const http_client_js_1 = require("./http-client.js");
|
|
9
|
+
(0, vitest_1.describe)('HttpClient envelope harden', () => {
|
|
10
|
+
function makeClient(requestImpl) {
|
|
11
|
+
const axiosInstance = { request: requestImpl };
|
|
12
|
+
const rateLimiter = {
|
|
13
|
+
schedule: (fn) => fn(),
|
|
14
|
+
};
|
|
15
|
+
const config = {
|
|
16
|
+
baseUrl: 'https://app.lightdash.com',
|
|
17
|
+
timeout: 30000,
|
|
18
|
+
retry: { maxRetries: 0 },
|
|
19
|
+
};
|
|
20
|
+
return new http_client_js_1.HttpClient(axiosInstance, rateLimiter, config);
|
|
21
|
+
}
|
|
22
|
+
(0, vitest_1.it)('returns results for ok envelopes', async () => {
|
|
23
|
+
const client = makeClient(vitest_1.vi.fn().mockResolvedValue({
|
|
24
|
+
status: 200,
|
|
25
|
+
data: { status: 'ok', results: { id: '1' } },
|
|
26
|
+
config: {},
|
|
27
|
+
}));
|
|
28
|
+
await (0, vitest_1.expect)(client.get('/x')).resolves.toEqual({ id: '1' });
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)('throws LightdashApiError for error envelopes', async () => {
|
|
31
|
+
const client = makeClient(vitest_1.vi.fn().mockResolvedValue({
|
|
32
|
+
status: 200,
|
|
33
|
+
data: {
|
|
34
|
+
status: 'error',
|
|
35
|
+
error: { name: 'Bad', statusCode: 400, message: 'nope' },
|
|
36
|
+
},
|
|
37
|
+
config: {},
|
|
38
|
+
}));
|
|
39
|
+
await (0, vitest_1.expect)(client.get('/x')).rejects.toMatchObject({
|
|
40
|
+
statusCode: 400,
|
|
41
|
+
error: { message: 'nope' },
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
(0, vitest_1.it)('throws ContractError for malformed 200 bodies', async () => {
|
|
45
|
+
const client = makeClient(vitest_1.vi.fn().mockResolvedValue({
|
|
46
|
+
status: 200,
|
|
47
|
+
data: { foo: 1 },
|
|
48
|
+
config: {},
|
|
49
|
+
}));
|
|
50
|
+
await (0, vitest_1.expect)(client.get('/x')).rejects.toSatisfy((err) => {
|
|
51
|
+
(0, vitest_1.expect)(err).toBeInstanceOf(errors_js_1.LightdashApiError);
|
|
52
|
+
const apiErr = err;
|
|
53
|
+
(0, vitest_1.expect)(apiErr.statusCode).toBe(502);
|
|
54
|
+
(0, vitest_1.expect)(apiErr.error.name).toBe(errors_js_1.CONTRACT_ERROR_NAME);
|
|
55
|
+
(0, vitest_1.expect)(apiErr.error.message).toBe(errors_js_1.CONTRACT_ERROR_MESSAGE);
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
package/dist/http/http-client.js
CHANGED
|
@@ -3,12 +3,99 @@
|
|
|
3
3
|
* HTTP client wrapper: rate limiter + axios + retry.
|
|
4
4
|
* All requests go through the rate limiter; retry applies to 5xx and network errors.
|
|
5
5
|
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.HttpClient = void 0;
|
|
10
|
+
exports.HttpClient = exports.DEFAULT_BINARY_MAX_BYTES = void 0;
|
|
11
|
+
exports.isBlockedBinaryHostname = isBlockedBinaryHostname;
|
|
12
|
+
exports.assertSafeBinaryFetchUrl = assertSafeBinaryFetchUrl;
|
|
13
|
+
const axios_1 = __importDefault(require("axios"));
|
|
14
|
+
const config_1 = require("../config");
|
|
8
15
|
const errors_1 = require("../errors");
|
|
9
16
|
const retry_1 = require("../utils/retry");
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
const unwrap_api_success_1 = require("./unwrap-api-success");
|
|
18
|
+
/** Default max raw bytes for chart PNG downloads (8 MiB). */
|
|
19
|
+
exports.DEFAULT_BINARY_MAX_BYTES = 8 * 1024 * 1024;
|
|
20
|
+
function isPrivateIpv4Octets(a, b) {
|
|
21
|
+
if (a === 0 || a === 10 || a === 127) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (a === 169 && b === 254) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (a === 192 && b === 168) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return a === 172 && b >= 16 && b <= 31;
|
|
31
|
+
}
|
|
32
|
+
function isBlockedIpv6Host(host) {
|
|
33
|
+
if (host === '::1' || host.startsWith('fe80:')) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
// Unique-local IPv6 (fc00::/7)
|
|
37
|
+
return host.startsWith('fc') || host.startsWith('fd');
|
|
38
|
+
}
|
|
39
|
+
function isAxiosMaxContentLengthError(err) {
|
|
40
|
+
if (!axios_1.default.isAxiosError(err)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (typeof err.message !== 'string') {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return err.message.includes('maxContentLength') || err.message.includes('maxBodyLength');
|
|
47
|
+
}
|
|
48
|
+
/** True when hostname is loopback, link-local, or RFC1918 (cross-host SSRF guard). */
|
|
49
|
+
function isBlockedBinaryHostname(hostname) {
|
|
50
|
+
const host = hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
51
|
+
if (host === 'localhost' || host === 'metadata.google.internal') {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
const ipv4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(host);
|
|
55
|
+
if (ipv4 && isPrivateIpv4Octets(Number(ipv4[1]), Number(ipv4[2]))) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return isBlockedIpv6Host(host);
|
|
59
|
+
}
|
|
60
|
+
/** Reject unsafe absolute binary download URLs (exported for unit tests). */
|
|
61
|
+
function assertSafeBinaryFetchUrl(url, baseUrl) {
|
|
62
|
+
if (!/^https?:\/\//i.test(url)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = new URL(url);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
throw new errors_1.NetworkError('Invalid binary download URL', err instanceof Error ? err : new Error(String(err)));
|
|
71
|
+
}
|
|
72
|
+
const base = new URL(baseUrl);
|
|
73
|
+
if (parsed.host === base.host && parsed.protocol === 'http:' && base.protocol === 'https:') {
|
|
74
|
+
throw new errors_1.NetworkError('Binary download URL must not downgrade HTTPS to HTTP', new Error(`${base.protocol} -> ${parsed.protocol}`));
|
|
75
|
+
}
|
|
76
|
+
const crossHost = parsed.host !== base.host;
|
|
77
|
+
if (!crossHost) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (parsed.protocol !== 'https:') {
|
|
81
|
+
throw new errors_1.NetworkError('Cross-host binary download URL must use https', new Error(parsed.protocol));
|
|
82
|
+
}
|
|
83
|
+
if (isBlockedBinaryHostname(parsed.hostname)) {
|
|
84
|
+
throw new errors_1.NetworkError(`Binary download host is not allowed: ${parsed.hostname}`, new Error(parsed.hostname));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function readApiErrorPayload(data) {
|
|
88
|
+
if (data === null || typeof data !== 'object' || !('error' in data)) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
const error = data.error;
|
|
92
|
+
if (error === null || typeof error !== 'object') {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
if (typeof error.statusCode !== 'number') {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return error;
|
|
12
99
|
}
|
|
13
100
|
/**
|
|
14
101
|
* HTTP client that wraps Axios with rate limiting and retry.
|
|
@@ -24,10 +111,23 @@ class HttpClient {
|
|
|
24
111
|
url }));
|
|
25
112
|
const response = await this.rateLimiter.schedule(() => (0, retry_1.withRetry)(doRequest, this.config.retry));
|
|
26
113
|
const data = response.data;
|
|
27
|
-
if (
|
|
28
|
-
|
|
114
|
+
if (data !== null && typeof data === 'object') {
|
|
115
|
+
const envelope = data;
|
|
116
|
+
if ((0, unwrap_api_success_1.isApiSuccessEnvelope)(envelope)) {
|
|
117
|
+
return envelope.results;
|
|
118
|
+
}
|
|
29
119
|
}
|
|
30
|
-
|
|
120
|
+
const apiError = readApiErrorPayload(data);
|
|
121
|
+
if (apiError !== undefined) {
|
|
122
|
+
throw new errors_1.LightdashApiError(apiError.statusCode, apiError, response.config, response);
|
|
123
|
+
}
|
|
124
|
+
const httpStatus = response.status;
|
|
125
|
+
const contractStatus = typeof httpStatus === 'number' && httpStatus >= 400 ? httpStatus : 502;
|
|
126
|
+
throw new errors_1.LightdashApiError(contractStatus, {
|
|
127
|
+
name: errors_1.CONTRACT_ERROR_NAME,
|
|
128
|
+
statusCode: contractStatus,
|
|
129
|
+
message: errors_1.CONTRACT_ERROR_MESSAGE,
|
|
130
|
+
}, response.config, response);
|
|
31
131
|
}
|
|
32
132
|
async get(url, config) {
|
|
33
133
|
return this.request('GET', url, config);
|
|
@@ -44,5 +144,54 @@ class HttpClient {
|
|
|
44
144
|
async delete(url, config) {
|
|
45
145
|
return this.request('DELETE', url, config);
|
|
46
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Fetch raw bytes (no ApiSuccess envelope unwrap). Relative URLs use the
|
|
149
|
+
* authenticated API client; absolute URLs on a different host (e.g. signed S3)
|
|
150
|
+
* are fetched without Lightdash Authorization. Cross-host fetches require https,
|
|
151
|
+
* disallow private/link-local hosts, and follow no redirects.
|
|
152
|
+
*/
|
|
153
|
+
async getBytes(url, options) {
|
|
154
|
+
var _a, _b, _c, _d, _e;
|
|
155
|
+
const maxBytes = (_a = options === null || options === void 0 ? void 0 : options.maxBytes) !== null && _a !== void 0 ? _a : exports.DEFAULT_BINARY_MAX_BYTES;
|
|
156
|
+
const timeout = (_c = (_b = options === null || options === void 0 ? void 0 : options.timeout) !== null && _b !== void 0 ? _b : this.config.timeout) !== null && _c !== void 0 ? _c : config_1.DEFAULT_TIMEOUT;
|
|
157
|
+
assertSafeBinaryFetchUrl(url, this.config.baseUrl);
|
|
158
|
+
const binaryConfig = {
|
|
159
|
+
responseType: 'arraybuffer',
|
|
160
|
+
timeout,
|
|
161
|
+
maxContentLength: maxBytes,
|
|
162
|
+
maxBodyLength: maxBytes,
|
|
163
|
+
maxRedirects: 0,
|
|
164
|
+
};
|
|
165
|
+
const doRequest = () => {
|
|
166
|
+
if (/^https?:\/\//i.test(url)) {
|
|
167
|
+
const targetHost = new URL(url).host;
|
|
168
|
+
const baseHost = new URL(this.config.baseUrl).host;
|
|
169
|
+
if (targetHost !== baseHost) {
|
|
170
|
+
return axios_1.default.get(url, binaryConfig);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return this.axiosInstance.get(url, binaryConfig);
|
|
174
|
+
};
|
|
175
|
+
let response;
|
|
176
|
+
try {
|
|
177
|
+
// No retries: binary bodies can be multi-MiB; a 5xx would re-download the payload.
|
|
178
|
+
response = await this.rateLimiter.schedule(doRequest);
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
if (isAxiosMaxContentLengthError(err)) {
|
|
182
|
+
throw new errors_1.BinarySizeLimitError(maxBytes);
|
|
183
|
+
}
|
|
184
|
+
throw err;
|
|
185
|
+
}
|
|
186
|
+
const bytes = Buffer.from(response.data);
|
|
187
|
+
if (bytes.byteLength > maxBytes) {
|
|
188
|
+
throw new errors_1.BinarySizeLimitError(maxBytes, bytes.byteLength);
|
|
189
|
+
}
|
|
190
|
+
const rawType = response.headers['content-type'];
|
|
191
|
+
const mimeType = typeof rawType === 'string'
|
|
192
|
+
? ((_e = (_d = rawType.split(';')[0]) === null || _d === void 0 ? void 0 : _d.trim()) !== null && _e !== void 0 ? _e : 'application/octet-stream')
|
|
193
|
+
: 'application/octet-stream';
|
|
194
|
+
return { bytes, mimeType };
|
|
195
|
+
}
|
|
47
196
|
}
|
|
48
197
|
exports.HttpClient = HttpClient;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for Lightdash API success envelopes.
|
|
3
|
+
* HttpClient uses `isApiSuccessEnvelope` then maps failures to `LightdashApiError`.
|
|
4
|
+
*/
|
|
5
|
+
export type ApiSuccessEnvelope<T> = {
|
|
6
|
+
status: 'ok';
|
|
7
|
+
results: T;
|
|
8
|
+
};
|
|
9
|
+
export type ApiErrorEnvelope = {
|
|
10
|
+
status: 'error';
|
|
11
|
+
error: {
|
|
12
|
+
statusCode: number;
|
|
13
|
+
name?: string;
|
|
14
|
+
message?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type ApiEnvelope<T> = ApiErrorEnvelope | ApiSuccessEnvelope<T>;
|
|
19
|
+
/** Type guard for Lightdash `{ status: 'ok', results }` responses. */
|
|
20
|
+
export declare function isApiSuccessEnvelope<T>(data: ApiEnvelope<T>): data is ApiSuccessEnvelope<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Unwraps a Lightdash success envelope to `results`.
|
|
23
|
+
* Throws a plain `Error` when `status` is not `ok` (message from `error.message` when present).
|
|
24
|
+
* Prefer `HttpClient` in production paths that need `LightdashApiError` + axios context.
|
|
25
|
+
*/
|
|
26
|
+
export declare function unwrapApiSuccessResults<T>(data: ApiEnvelope<T>): T;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Pure helpers for Lightdash API success envelopes.
|
|
4
|
+
* HttpClient uses `isApiSuccessEnvelope` then maps failures to `LightdashApiError`.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isApiSuccessEnvelope = isApiSuccessEnvelope;
|
|
8
|
+
exports.unwrapApiSuccessResults = unwrapApiSuccessResults;
|
|
9
|
+
/** Type guard for Lightdash `{ status: 'ok', results }` responses. */
|
|
10
|
+
function isApiSuccessEnvelope(data) {
|
|
11
|
+
return data.status === 'ok';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Unwraps a Lightdash success envelope to `results`.
|
|
15
|
+
* Throws a plain `Error` when `status` is not `ok` (message from `error.message` when present).
|
|
16
|
+
* Prefer `HttpClient` in production paths that need `LightdashApiError` + axios context.
|
|
17
|
+
*/
|
|
18
|
+
function unwrapApiSuccessResults(data) {
|
|
19
|
+
var _a;
|
|
20
|
+
if (!isApiSuccessEnvelope(data)) {
|
|
21
|
+
const message = typeof ((_a = data.error) === null || _a === void 0 ? void 0 : _a.message) === 'string' ? data.error.message : 'Lightdash API error';
|
|
22
|
+
throw new Error(message);
|
|
23
|
+
}
|
|
24
|
+
return data.results;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const unwrap_api_success_1 = require("./unwrap-api-success");
|
|
5
|
+
(0, vitest_1.describe)('unwrapApiSuccessResults', () => {
|
|
6
|
+
(0, vitest_1.it)('returns results for ok envelopes', () => {
|
|
7
|
+
(0, vitest_1.expect)((0, unwrap_api_success_1.unwrapApiSuccessResults)({ status: 'ok', results: { id: '1' } })).toEqual({ id: '1' });
|
|
8
|
+
});
|
|
9
|
+
(0, vitest_1.it)('throws for error envelopes', () => {
|
|
10
|
+
(0, vitest_1.expect)(() => (0, unwrap_api_success_1.unwrapApiSuccessResults)({
|
|
11
|
+
status: 'error',
|
|
12
|
+
error: { statusCode: 400, message: 'bad request' },
|
|
13
|
+
})).toThrow(/bad request/);
|
|
14
|
+
});
|
|
15
|
+
(0, vitest_1.it)('narrows success envelopes', () => {
|
|
16
|
+
const body = { status: 'ok', results: [1, 2] };
|
|
17
|
+
(0, vitest_1.expect)((0, unwrap_api_success_1.isApiSuccessEnvelope)(body)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -13,24 +13,31 @@ export { SchedulersClient } from './api/v1/schedulers';
|
|
|
13
13
|
export { TagsClient } from './api/v1/tags';
|
|
14
14
|
export { AnalyticsClient } from './api/v1/analytics';
|
|
15
15
|
export { ContentClient } from './api/v2/content';
|
|
16
|
+
export { ChartsClientV2 } from './api/v2/charts';
|
|
16
17
|
export { DashboardsClientV2 } from './api/v2/dashboards';
|
|
17
18
|
export type { ListMembersParams, ListAllMembersParams } from './api/v1/users';
|
|
18
19
|
export type { GetValidationResultsParams, ValidateProjectBody } from './api/v1/validation';
|
|
19
20
|
export type { ListValidationResultsParams } from './api/v2/validation';
|
|
20
21
|
export type { ListMetricsParams } from './api/v1/metrics';
|
|
21
22
|
export type { ListSchedulersParams } from './api/v1/schedulers';
|
|
22
|
-
export type { SearchContentParams } from './api/v2/content';
|
|
23
|
+
export type { BulkMoveContentBody, MoveContentBody, PermanentlyDeleteContentBody, SearchContentParams, } from './api/v2/content';
|
|
24
|
+
export type { SavedChart } from './api/v2/charts';
|
|
25
|
+
export type { Dashboard, UpdateDashboardBody } from './api/v2/dashboards';
|
|
26
|
+
export type { DashboardPromoteDiffResults, DashboardPromoteOptions, PromoteDashboardResult, } from './api/v1/dashboards';
|
|
23
27
|
export type { ListGroupsParams, ListAllGroupsParams, GetGroupParams, GroupOrGroupWithMembers, } from './api/v1/groups';
|
|
24
28
|
export type { GetRolesResult, GetRolesParams, AssignOrgRoleToUserBody, } from './api/v2/organization-roles';
|
|
25
29
|
export type { PartialLightdashClientConfig } from './config';
|
|
26
30
|
export type { LightdashClientConfig, LightdashAuthConfig, ResolvedLightdashClientConfig, RateLimitConfig, RetryConfig, Logger, ObservabilityHooks, } from './config';
|
|
27
31
|
export { noopLogger, consoleLogger } from './utils/logger';
|
|
28
32
|
export { DEFAULT_RATE_LIMIT, DEFAULT_TIMEOUT, DEFAULT_RETRY } from './config';
|
|
29
|
-
export { LightdashApiError, RateLimitError, NetworkError } from './errors';
|
|
33
|
+
export { LightdashApiError, RateLimitError, NetworkError, ChartImageSizeError, CONTRACT_ERROR_NAME, CONTRACT_ERROR_MESSAGE, } from './errors';
|
|
30
34
|
export type { ApiErrorPayload } from './errors';
|
|
35
|
+
export { CHART_IMAGE_EXPORT_TIMEOUT_MS, CHART_IMAGE_MAX_BYTES, type ChartImagePng, } from './api/v1/charts';
|
|
36
|
+
export { DEFAULT_BINARY_MAX_BYTES, isBlockedBinaryHostname, type GetBytesOptions, type GetBytesResult, } from './http/http-client';
|
|
31
37
|
export { loadConfigFromEnv, mergeConfig, createBearerConfig } from './utils/env';
|
|
32
38
|
export { ENV_LIGHTDASH_API_KEY, ENV_LIGHTDASH_URL, ENV_LIGHTDASH_PROXY_AUTHORIZATION, } from './utils/env';
|
|
33
39
|
export { HttpClient } from './http/http-client';
|
|
40
|
+
export { isApiSuccessEnvelope, unwrapApiSuccessResults, type ApiEnvelope, type ApiErrorEnvelope, type ApiSuccessEnvelope, } from './http/unwrap-api-success';
|
|
34
41
|
export { RateLimiter } from './http/rate-limiter';
|
|
35
42
|
export { SecretString } from './utils/secret-string';
|
|
36
43
|
export type { ApiResponseOk, ApiResponseError, ApiResponseBody, ApiError } from './types/api';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SecretString = exports.RateLimiter = exports.HttpClient = exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = exports.createBearerConfig = 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.DashboardsClientV2 = exports.ContentClient = exports.AnalyticsClient = exports.TagsClient = exports.SchedulersClient = exports.MetricsClient = exports.ValidationClientV2 = exports.ValidationClient = exports.ProjectAccessClient = exports.AiAgentsClient = exports.ProjectRoleAssignmentsClient = exports.OrganizationRolesClient = exports.GroupsClient = exports.UsersClient = exports.resolveEvaluationRun = exports.applyBundleDiff = exports.fetchBundleCurrentState = exports.V2ApiClients = exports.V1ApiClients = exports.LightdashClient = void 0;
|
|
3
|
+
exports.SecretString = exports.RateLimiter = exports.unwrapApiSuccessResults = exports.isApiSuccessEnvelope = exports.HttpClient = exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = exports.createBearerConfig = exports.mergeConfig = exports.loadConfigFromEnv = exports.isBlockedBinaryHostname = exports.DEFAULT_BINARY_MAX_BYTES = exports.CHART_IMAGE_MAX_BYTES = exports.CHART_IMAGE_EXPORT_TIMEOUT_MS = exports.CONTRACT_ERROR_MESSAGE = exports.CONTRACT_ERROR_NAME = exports.ChartImageSizeError = exports.NetworkError = exports.RateLimitError = exports.LightdashApiError = exports.DEFAULT_RETRY = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RATE_LIMIT = exports.consoleLogger = exports.noopLogger = exports.DashboardsClientV2 = exports.ChartsClientV2 = exports.ContentClient = exports.AnalyticsClient = exports.TagsClient = exports.SchedulersClient = exports.MetricsClient = exports.ValidationClientV2 = exports.ValidationClient = exports.ProjectAccessClient = exports.AiAgentsClient = exports.ProjectRoleAssignmentsClient = exports.OrganizationRolesClient = exports.GroupsClient = exports.UsersClient = exports.resolveEvaluationRun = exports.applyBundleDiff = exports.fetchBundleCurrentState = 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; } });
|
|
@@ -35,6 +35,8 @@ var analytics_1 = require("./api/v1/analytics");
|
|
|
35
35
|
Object.defineProperty(exports, "AnalyticsClient", { enumerable: true, get: function () { return analytics_1.AnalyticsClient; } });
|
|
36
36
|
var content_1 = require("./api/v2/content");
|
|
37
37
|
Object.defineProperty(exports, "ContentClient", { enumerable: true, get: function () { return content_1.ContentClient; } });
|
|
38
|
+
var charts_1 = require("./api/v2/charts");
|
|
39
|
+
Object.defineProperty(exports, "ChartsClientV2", { enumerable: true, get: function () { return charts_1.ChartsClientV2; } });
|
|
38
40
|
var dashboards_1 = require("./api/v2/dashboards");
|
|
39
41
|
Object.defineProperty(exports, "DashboardsClientV2", { enumerable: true, get: function () { return dashboards_1.DashboardsClientV2; } });
|
|
40
42
|
var logger_1 = require("./utils/logger");
|
|
@@ -48,6 +50,15 @@ var errors_1 = require("./errors");
|
|
|
48
50
|
Object.defineProperty(exports, "LightdashApiError", { enumerable: true, get: function () { return errors_1.LightdashApiError; } });
|
|
49
51
|
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
|
|
50
52
|
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_1.NetworkError; } });
|
|
53
|
+
Object.defineProperty(exports, "ChartImageSizeError", { enumerable: true, get: function () { return errors_1.ChartImageSizeError; } });
|
|
54
|
+
Object.defineProperty(exports, "CONTRACT_ERROR_NAME", { enumerable: true, get: function () { return errors_1.CONTRACT_ERROR_NAME; } });
|
|
55
|
+
Object.defineProperty(exports, "CONTRACT_ERROR_MESSAGE", { enumerable: true, get: function () { return errors_1.CONTRACT_ERROR_MESSAGE; } });
|
|
56
|
+
var charts_2 = require("./api/v1/charts");
|
|
57
|
+
Object.defineProperty(exports, "CHART_IMAGE_EXPORT_TIMEOUT_MS", { enumerable: true, get: function () { return charts_2.CHART_IMAGE_EXPORT_TIMEOUT_MS; } });
|
|
58
|
+
Object.defineProperty(exports, "CHART_IMAGE_MAX_BYTES", { enumerable: true, get: function () { return charts_2.CHART_IMAGE_MAX_BYTES; } });
|
|
59
|
+
var http_client_1 = require("./http/http-client");
|
|
60
|
+
Object.defineProperty(exports, "DEFAULT_BINARY_MAX_BYTES", { enumerable: true, get: function () { return http_client_1.DEFAULT_BINARY_MAX_BYTES; } });
|
|
61
|
+
Object.defineProperty(exports, "isBlockedBinaryHostname", { enumerable: true, get: function () { return http_client_1.isBlockedBinaryHostname; } });
|
|
51
62
|
var env_1 = require("./utils/env");
|
|
52
63
|
Object.defineProperty(exports, "loadConfigFromEnv", { enumerable: true, get: function () { return env_1.loadConfigFromEnv; } });
|
|
53
64
|
Object.defineProperty(exports, "mergeConfig", { enumerable: true, get: function () { return env_1.mergeConfig; } });
|
|
@@ -56,8 +67,11 @@ var env_2 = require("./utils/env");
|
|
|
56
67
|
Object.defineProperty(exports, "ENV_LIGHTDASH_API_KEY", { enumerable: true, get: function () { return env_2.ENV_LIGHTDASH_API_KEY; } });
|
|
57
68
|
Object.defineProperty(exports, "ENV_LIGHTDASH_URL", { enumerable: true, get: function () { return env_2.ENV_LIGHTDASH_URL; } });
|
|
58
69
|
Object.defineProperty(exports, "ENV_LIGHTDASH_PROXY_AUTHORIZATION", { enumerable: true, get: function () { return env_2.ENV_LIGHTDASH_PROXY_AUTHORIZATION; } });
|
|
59
|
-
var
|
|
60
|
-
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return
|
|
70
|
+
var http_client_2 = require("./http/http-client");
|
|
71
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return http_client_2.HttpClient; } });
|
|
72
|
+
var unwrap_api_success_1 = require("./http/unwrap-api-success");
|
|
73
|
+
Object.defineProperty(exports, "isApiSuccessEnvelope", { enumerable: true, get: function () { return unwrap_api_success_1.isApiSuccessEnvelope; } });
|
|
74
|
+
Object.defineProperty(exports, "unwrapApiSuccessResults", { enumerable: true, get: function () { return unwrap_api_success_1.unwrapApiSuccessResults; } });
|
|
61
75
|
var rate_limiter_1 = require("./http/rate-limiter");
|
|
62
76
|
Object.defineProperty(exports, "RateLimiter", { enumerable: true, get: function () { return rate_limiter_1.RateLimiter; } });
|
|
63
77
|
var secret_string_1 = require("./utils/secret-string");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Client library for Lightdash AI.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"axios": "^1.19.0",
|
|
17
17
|
"bottleneck": "^2.19.5",
|
|
18
|
-
"@lightdash-tools/common": "0.
|
|
18
|
+
"@lightdash-tools/common": "0.9.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^25.9.3"
|
|
@@ -53,7 +53,7 @@ describe('AiAgentsDiscoveryClient', () => {
|
|
|
53
53
|
const client = new AiAgentsDiscoveryClient(mockHttp);
|
|
54
54
|
const summary = [{ exploreName: 'orders', metrics: [], dimensions: [], joinedTables: [] }];
|
|
55
55
|
vi.mocked(mockHttp.post).mockResolvedValue(summary);
|
|
56
|
-
const result = await client.getExploreAccessSummary('proj1',
|
|
56
|
+
const result = await client.getExploreAccessSummary('proj1', { tags: ['ai'] });
|
|
57
57
|
expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/explore-access-summary', {
|
|
58
58
|
tags: ['ai'],
|
|
59
59
|
});
|
|
@@ -61,6 +61,24 @@ describe('AiAgentsDiscoveryClient', () => {
|
|
|
61
61
|
});
|
|
62
62
|
|
|
63
63
|
it('getExploreAccessSummary without body should default tags to null', async () => {
|
|
64
|
+
const client = new AiAgentsDiscoveryClient(mockHttp);
|
|
65
|
+
vi.mocked(mockHttp.post).mockResolvedValue([]);
|
|
66
|
+
await client.getExploreAccessSummary('proj1');
|
|
67
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/explore-access-summary', {
|
|
68
|
+
tags: null,
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('getExploreAccessSummary legacy (project, agentUuid, body) ignores agentUuid', async () => {
|
|
73
|
+
const client = new AiAgentsDiscoveryClient(mockHttp);
|
|
74
|
+
vi.mocked(mockHttp.post).mockResolvedValue([]);
|
|
75
|
+
await client.getExploreAccessSummary('proj1', 'a1', { tags: ['ai'] });
|
|
76
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/projects/proj1/aiAgents/explore-access-summary', {
|
|
77
|
+
tags: ['ai'],
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('getExploreAccessSummary legacy (project, agentUuid) defaults tags to null', async () => {
|
|
64
82
|
const client = new AiAgentsDiscoveryClient(mockHttp);
|
|
65
83
|
vi.mocked(mockHttp.post).mockResolvedValue([]);
|
|
66
84
|
await client.getExploreAccessSummary('proj1', 'a1');
|
|
@@ -43,16 +43,30 @@ export class AiAgentsDiscoveryClient extends BaseApiClient {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Summarize explore access for tag-filtered explores
|
|
46
|
-
* (POST …/explore-access-summary).
|
|
46
|
+
* (POST …/explore-access-summary). Project-scoped; no agent path segment.
|
|
47
47
|
*/
|
|
48
|
+
getExploreAccessSummary(
|
|
49
|
+
projectUuid: string,
|
|
50
|
+
body?: ExploreAccessSummaryBody,
|
|
51
|
+
): Promise<AiAgentExploreAccessSummary[]>;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated `agentUuid` is ignored; the endpoint is project-scoped.
|
|
54
|
+
* Prefer `getExploreAccessSummary(projectUuid, body?)`.
|
|
55
|
+
*/
|
|
56
|
+
getExploreAccessSummary(
|
|
57
|
+
projectUuid: string,
|
|
58
|
+
agentUuid: string,
|
|
59
|
+
body?: ExploreAccessSummaryBody,
|
|
60
|
+
): Promise<AiAgentExploreAccessSummary[]>;
|
|
48
61
|
async getExploreAccessSummary(
|
|
49
62
|
projectUuid: string,
|
|
50
|
-
|
|
63
|
+
agentUuidOrBody?: ExploreAccessSummaryBody | string,
|
|
51
64
|
body?: ExploreAccessSummaryBody,
|
|
52
65
|
): Promise<AiAgentExploreAccessSummary[]> {
|
|
66
|
+
const resolvedBody = typeof agentUuidOrBody === 'string' ? body : agentUuidOrBody;
|
|
53
67
|
return this.http.post<AiAgentExploreAccessSummary[]>(
|
|
54
68
|
`/projects/${projectUuid}/aiAgents/explore-access-summary`,
|
|
55
|
-
|
|
69
|
+
resolvedBody ?? { tags: null },
|
|
56
70
|
);
|
|
57
71
|
}
|
|
58
72
|
|
|
@@ -150,12 +150,28 @@ export class AiAgentsClient extends BaseApiClient {
|
|
|
150
150
|
return this.discovery.evaluateAgentReadiness(projectUuid, agentUuid);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
getExploreAccessSummary(
|
|
154
|
+
projectUuid: string,
|
|
155
|
+
body?: ExploreAccessSummaryBody,
|
|
156
|
+
): Promise<AiAgentExploreAccessSummary[]>;
|
|
157
|
+
/**
|
|
158
|
+
* @deprecated `agentUuid` is ignored; the endpoint is project-scoped.
|
|
159
|
+
* Prefer `getExploreAccessSummary(projectUuid, body?)`.
|
|
160
|
+
*/
|
|
153
161
|
getExploreAccessSummary(
|
|
154
162
|
projectUuid: string,
|
|
155
163
|
agentUuid: string,
|
|
156
164
|
body?: ExploreAccessSummaryBody,
|
|
165
|
+
): Promise<AiAgentExploreAccessSummary[]>;
|
|
166
|
+
getExploreAccessSummary(
|
|
167
|
+
projectUuid: string,
|
|
168
|
+
agentUuidOrBody?: ExploreAccessSummaryBody | string,
|
|
169
|
+
body?: ExploreAccessSummaryBody,
|
|
157
170
|
): Promise<AiAgentExploreAccessSummary[]> {
|
|
158
|
-
|
|
171
|
+
if (typeof agentUuidOrBody === 'string') {
|
|
172
|
+
return this.discovery.getExploreAccessSummary(projectUuid, agentUuidOrBody, body);
|
|
173
|
+
}
|
|
174
|
+
return this.discovery.getExploreAccessSummary(projectUuid, agentUuidOrBody);
|
|
159
175
|
}
|
|
160
176
|
|
|
161
177
|
getUserAgentPreferences(projectUuid: string): Promise<AiAgentUserPreferences | null> {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { BinarySizeLimitError } from '../../errors.js';
|
|
4
|
+
|
|
5
|
+
import { ChartsClient } from './charts.js';
|
|
4
6
|
|
|
5
7
|
import type { HttpClient } from '../../http/http-client';
|
|
6
8
|
|
|
@@ -14,6 +16,7 @@ describe('ChartsClient', () => {
|
|
|
14
16
|
put: vi.fn(),
|
|
15
17
|
patch: vi.fn(),
|
|
16
18
|
delete: vi.fn(),
|
|
19
|
+
getBytes: vi.fn(),
|
|
17
20
|
} as unknown as HttpClient;
|
|
18
21
|
});
|
|
19
22
|
|
|
@@ -102,4 +105,61 @@ describe('ChartsClient', () => {
|
|
|
102
105
|
await client.upsertChartAsCode('p1', 'chart/slug', body);
|
|
103
106
|
expect(mockHttp.post).toHaveBeenCalledWith('/projects/p1/code/charts/chart%2Fslug', body);
|
|
104
107
|
});
|
|
108
|
+
|
|
109
|
+
it('getChartHistory should call GET /saved/{chartUuid}/history', async () => {
|
|
110
|
+
const client = new ChartsClient(mockHttp);
|
|
111
|
+
const history = { chartUuid: 'c1', history: [] };
|
|
112
|
+
vi.mocked(mockHttp.get).mockResolvedValue(history);
|
|
113
|
+
const result = await client.getChartHistory('c1');
|
|
114
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/saved/c1/history');
|
|
115
|
+
expect(result).toEqual(history);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('getChartVersion should call GET /saved/{chartUuid}/version/{versionUuid}', async () => {
|
|
119
|
+
const client = new ChartsClient(mockHttp);
|
|
120
|
+
const version = { chartUuid: 'c1', versionUuid: 'v1' };
|
|
121
|
+
vi.mocked(mockHttp.get).mockResolvedValue(version);
|
|
122
|
+
const result = await client.getChartVersion('c1', 'v1');
|
|
123
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/saved/c1/version/v1');
|
|
124
|
+
expect(result).toEqual(version);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('exportChartImage should POST /saved/{chartUuid}/export and return URL', async () => {
|
|
128
|
+
const client = new ChartsClient(mockHttp);
|
|
129
|
+
vi.mocked(mockHttp.post).mockResolvedValue('https://cdn.example/chart.png');
|
|
130
|
+
const result = await client.exportChartImage('c1', 'p1');
|
|
131
|
+
expect(mockHttp.post).toHaveBeenCalledWith('/saved/c1/export', undefined, {
|
|
132
|
+
params: { projectUuid: 'p1' },
|
|
133
|
+
timeout: 120_000,
|
|
134
|
+
});
|
|
135
|
+
expect(result).toBe('https://cdn.example/chart.png');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('exportChartImagePng should export then download bytes', async () => {
|
|
139
|
+
const client = new ChartsClient(mockHttp);
|
|
140
|
+
const png = Buffer.from([0x89, 0x50, 0x4e, 0x47]);
|
|
141
|
+
vi.mocked(mockHttp.post).mockResolvedValue('https://cdn.example/chart.png');
|
|
142
|
+
vi.mocked(mockHttp.getBytes).mockResolvedValue({ bytes: png, mimeType: 'image/png' });
|
|
143
|
+
const result = await client.exportChartImagePng('c1');
|
|
144
|
+
expect(mockHttp.getBytes).toHaveBeenCalledWith('https://cdn.example/chart.png', {
|
|
145
|
+
maxBytes: 8 * 1024 * 1024,
|
|
146
|
+
timeout: 120_000,
|
|
147
|
+
});
|
|
148
|
+
expect(result).toEqual({
|
|
149
|
+
imageUrl: 'https://cdn.example/chart.png',
|
|
150
|
+
bytes: png,
|
|
151
|
+
mimeType: 'image/png',
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('exportChartImagePng maps BinarySizeLimitError to ChartImageSizeError', async () => {
|
|
156
|
+
const client = new ChartsClient(mockHttp);
|
|
157
|
+
vi.mocked(mockHttp.post).mockResolvedValue('https://cdn.example/chart.png');
|
|
158
|
+
vi.mocked(mockHttp.getBytes).mockRejectedValue(new BinarySizeLimitError(8 * 1024 * 1024));
|
|
159
|
+
|
|
160
|
+
await expect(client.exportChartImagePng('c1')).rejects.toMatchObject({
|
|
161
|
+
code: 'IMAGE_TOO_LARGE',
|
|
162
|
+
maxBytes: 8 * 1024 * 1024,
|
|
163
|
+
});
|
|
164
|
+
});
|
|
105
165
|
});
|