@carto/api-client 0.5.10 → 0.5.12
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/CHANGELOG.md +6 -0
- package/build/api-client.cjs +28 -14
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +23 -4
- package/build/api-client.d.ts +23 -4
- package/build/api-client.js +28 -14
- package/build/api-client.js.map +1 -1
- package/package.json +1 -1
- package/src/api/query.ts +19 -2
- package/src/api/request-with-parameters.ts +10 -5
- package/src/models/model.ts +3 -0
- package/src/sources/base-source.ts +1 -1
- package/src/sources/types.ts +13 -2
- package/src/widget-sources/widget-remote-source.ts +1 -0
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"homepage": "https://github.com/CartoDB/carto-api-client#readme",
|
|
9
9
|
"author": "Don McCurdy <donmccurdy@carto.com>",
|
|
10
10
|
"packageManager": "yarn@4.3.1",
|
|
11
|
-
"version": "0.5.
|
|
11
|
+
"version": "0.5.12",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
package/src/api/query.ts
CHANGED
|
@@ -13,7 +13,17 @@ import {requestWithParameters} from './request-with-parameters.js';
|
|
|
13
13
|
import type {APIErrorContext} from './carto-api-error.js';
|
|
14
14
|
import {getClient} from '../client.js';
|
|
15
15
|
|
|
16
|
-
export type QueryOptions = SourceOptions &
|
|
16
|
+
export type QueryOptions = SourceOptions &
|
|
17
|
+
QuerySourceOptions & {
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
* @experimental
|
|
21
|
+
* Used to append additional parameters to the SQL API request for features specific to providers or integrations.
|
|
22
|
+
*/
|
|
23
|
+
internalParameters?: Record<string, string | boolean | number>;
|
|
24
|
+
/** Used to abort the request. */
|
|
25
|
+
signal?: AbortSignal;
|
|
26
|
+
};
|
|
17
27
|
type UrlParameters = {q: string; queryParameters?: string};
|
|
18
28
|
|
|
19
29
|
export const query = async function (
|
|
@@ -27,6 +37,7 @@ export const query = async function (
|
|
|
27
37
|
connectionName,
|
|
28
38
|
sqlQuery,
|
|
29
39
|
queryParameters,
|
|
40
|
+
internalParameters,
|
|
30
41
|
} = options;
|
|
31
42
|
const urlParameters: UrlParameters = {q: sqlQuery};
|
|
32
43
|
|
|
@@ -39,7 +50,12 @@ export const query = async function (
|
|
|
39
50
|
Authorization: `Bearer ${options.accessToken}`,
|
|
40
51
|
...options.headers,
|
|
41
52
|
};
|
|
42
|
-
const parameters = {
|
|
53
|
+
const parameters = {
|
|
54
|
+
client: clientId,
|
|
55
|
+
...options.tags,
|
|
56
|
+
...internalParameters,
|
|
57
|
+
...urlParameters,
|
|
58
|
+
};
|
|
43
59
|
|
|
44
60
|
const errorContext: APIErrorContext = {
|
|
45
61
|
requestType: 'SQL',
|
|
@@ -54,5 +70,6 @@ export const query = async function (
|
|
|
54
70
|
errorContext,
|
|
55
71
|
maxLengthURL,
|
|
56
72
|
localCache,
|
|
73
|
+
signal: options.signal,
|
|
57
74
|
});
|
|
58
75
|
};
|
|
@@ -23,6 +23,7 @@ export async function requestWithParameters<T = any>({
|
|
|
23
23
|
errorContext,
|
|
24
24
|
maxLengthURL = DEFAULT_MAX_LENGTH_URL,
|
|
25
25
|
localCache,
|
|
26
|
+
signal,
|
|
26
27
|
}: {
|
|
27
28
|
baseUrl: string;
|
|
28
29
|
parameters?: Record<string, unknown>;
|
|
@@ -30,6 +31,7 @@ export async function requestWithParameters<T = any>({
|
|
|
30
31
|
errorContext: APIErrorContext;
|
|
31
32
|
maxLengthURL?: number;
|
|
32
33
|
localCache?: LocalCacheOptions;
|
|
34
|
+
signal?: AbortSignal;
|
|
33
35
|
}): Promise<T> {
|
|
34
36
|
// Parameters added to all requests issued with `requestWithParameters()`.
|
|
35
37
|
// These parameters override parameters already in the base URL, but not
|
|
@@ -65,8 +67,9 @@ export async function requestWithParameters<T = any>({
|
|
|
65
67
|
method: 'POST',
|
|
66
68
|
body: JSON.stringify(parameters),
|
|
67
69
|
headers,
|
|
70
|
+
signal,
|
|
68
71
|
})
|
|
69
|
-
: fetch(url, {headers});
|
|
72
|
+
: fetch(url, {headers, signal});
|
|
70
73
|
|
|
71
74
|
let response: Response | undefined;
|
|
72
75
|
let responseJson: unknown;
|
|
@@ -143,10 +146,12 @@ function createURLWithParameters(
|
|
|
143
146
|
if (isPureObject(value) || Array.isArray(value)) {
|
|
144
147
|
baseUrl.searchParams.set(key, JSON.stringify(value));
|
|
145
148
|
} else {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
if (value !== null && value !== undefined) {
|
|
150
|
+
baseUrl.searchParams.set(
|
|
151
|
+
key,
|
|
152
|
+
(value as string | boolean | number).toString()
|
|
153
|
+
);
|
|
154
|
+
}
|
|
150
155
|
}
|
|
151
156
|
}
|
|
152
157
|
return baseUrl.toString();
|
package/src/models/model.ts
CHANGED
|
@@ -43,6 +43,7 @@ export interface ModelSource {
|
|
|
43
43
|
spatialDataColumn?: string;
|
|
44
44
|
spatialDataType?: SpatialDataType;
|
|
45
45
|
spatialFiltersMode?: SpatialFilterPolyfillMode;
|
|
46
|
+
tags?: Record<string, string>;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
const {V3} = ApiVersion;
|
|
@@ -87,6 +88,7 @@ export function executeModel(props: {
|
|
|
87
88
|
spatialDataType = 'geo',
|
|
88
89
|
spatialDataColumn = DEFAULT_GEO_COLUMN,
|
|
89
90
|
spatialFiltersMode = 'intersects',
|
|
91
|
+
tags,
|
|
90
92
|
} = source;
|
|
91
93
|
|
|
92
94
|
const queryParams: Record<string, unknown> = {
|
|
@@ -97,6 +99,7 @@ export function executeModel(props: {
|
|
|
97
99
|
queryParameters: source.queryParameters || '',
|
|
98
100
|
filters,
|
|
99
101
|
filtersLogicalOperator,
|
|
102
|
+
...(tags ?? {}),
|
|
100
103
|
};
|
|
101
104
|
|
|
102
105
|
queryParams.spatialDataType = spatialDataType;
|
|
@@ -47,7 +47,7 @@ export async function baseSource<UrlParameters extends Record<string, unknown>>(
|
|
|
47
47
|
Authorization: `Bearer ${options.accessToken}`,
|
|
48
48
|
...options.headers,
|
|
49
49
|
};
|
|
50
|
-
const parameters = {client: clientId, ...urlParameters};
|
|
50
|
+
const parameters = {client: clientId, ...options.tags, ...urlParameters};
|
|
51
51
|
|
|
52
52
|
const errorContext: APIErrorContext = {
|
|
53
53
|
requestType: 'Map instantiation',
|
package/src/sources/types.ts
CHANGED
|
@@ -75,6 +75,9 @@ export type SourceOptionalOptions = {
|
|
|
75
75
|
* By default, local in-memory caching is enabled.
|
|
76
76
|
*/
|
|
77
77
|
localCache?: LocalCacheOptions;
|
|
78
|
+
|
|
79
|
+
/** Additional tags appended to HTTP requests, available for analytics and audits. */
|
|
80
|
+
tags?: Record<string, string>;
|
|
78
81
|
};
|
|
79
82
|
|
|
80
83
|
export type LocalCacheOptions = {
|
|
@@ -237,7 +240,7 @@ export interface Tilejson {
|
|
|
237
240
|
minzoom: number;
|
|
238
241
|
maxzoom: number;
|
|
239
242
|
bounds: [left: number, bottom: number, right: number, top: number];
|
|
240
|
-
center: [
|
|
243
|
+
center: [longitude: number, latitude: number, zoom: number];
|
|
241
244
|
vector_layers: VectorLayer[];
|
|
242
245
|
|
|
243
246
|
//
|
|
@@ -382,6 +385,13 @@ export type RasterMetadataBand = {
|
|
|
382
385
|
type: RasterBandType;
|
|
383
386
|
name: string;
|
|
384
387
|
stats: RasterMetadataBandStats;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Optional table of mappings from (integer) band values to (string) human
|
|
391
|
+
* readable labels. Values found in tiles are NOT guaranteed to have labels.
|
|
392
|
+
*/
|
|
393
|
+
valuelabels?: Record<string, string>;
|
|
394
|
+
|
|
385
395
|
/**
|
|
386
396
|
* Known values:
|
|
387
397
|
* * `palette`: use unique value and `colortable` ad default mapping
|
|
@@ -408,10 +418,11 @@ export type RasterMetadata = {
|
|
|
408
418
|
block_resolution: number;
|
|
409
419
|
minresolution: number;
|
|
410
420
|
maxresolution: number;
|
|
421
|
+
/** @deprecated Use {@link RasterMetadataBand.nodata} from {@link RasterMetadata.bands}. */
|
|
411
422
|
nodata: number | string;
|
|
412
423
|
bands: RasterMetadataBand[];
|
|
413
424
|
bounds: [left: number, bottom: number, right: number, top: number];
|
|
414
|
-
center: [
|
|
425
|
+
center: [longitude: number, latitude: number, zoom: number];
|
|
415
426
|
width: number;
|
|
416
427
|
height: number;
|
|
417
428
|
block_width: number;
|