@carto/api-client 0.5.11 → 0.5.13
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 +42 -14
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +24 -10
- package/build/api-client.d.ts +24 -10
- package/build/api-client.js +40 -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/constants.ts +8 -0
- package/src/sources/index.ts +1 -1
- package/src/sources/types.ts +4 -9
- 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.13",
|
|
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/index.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
export {SOURCE_DEFAULTS} from './base-source.js';
|
|
6
|
+
export {RasterBandColorinterp} from './constants.js';
|
|
6
7
|
export type {
|
|
7
8
|
SourceOptions,
|
|
8
9
|
SourceRequiredOptions,
|
|
@@ -26,7 +27,6 @@ export type {
|
|
|
26
27
|
RasterMetadataBand,
|
|
27
28
|
RasterMetadataBandStats,
|
|
28
29
|
RasterBandType,
|
|
29
|
-
RasterBandColorinterp,
|
|
30
30
|
} from './types.js';
|
|
31
31
|
|
|
32
32
|
export {boundaryQuerySource} from './boundary-query-source.js';
|
package/src/sources/types.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {Filters, SchemaField, QueryParameters} from '../types.js';
|
|
6
|
+
import type {RasterBandColorinterp} from './constants.js';
|
|
6
7
|
|
|
7
8
|
export type SourceRequiredOptions = {
|
|
8
9
|
/** Carto platform access token. */
|
|
@@ -75,6 +76,9 @@ export type SourceOptionalOptions = {
|
|
|
75
76
|
* By default, local in-memory caching is enabled.
|
|
76
77
|
*/
|
|
77
78
|
localCache?: LocalCacheOptions;
|
|
79
|
+
|
|
80
|
+
/** Additional tags appended to HTTP requests, available for analytics and audits. */
|
|
81
|
+
tags?: Record<string, string>;
|
|
78
82
|
};
|
|
79
83
|
|
|
80
84
|
export type LocalCacheOptions = {
|
|
@@ -357,15 +361,6 @@ export type RasterMetadataBandStats = {
|
|
|
357
361
|
version?: string;
|
|
358
362
|
};
|
|
359
363
|
|
|
360
|
-
export enum RasterBandColorinterp {
|
|
361
|
-
Gray = 'gray',
|
|
362
|
-
Red = 'red',
|
|
363
|
-
Green = 'green',
|
|
364
|
-
Blue = 'blue',
|
|
365
|
-
Alpha = 'alpha',
|
|
366
|
-
Palette = 'palette',
|
|
367
|
-
}
|
|
368
|
-
|
|
369
364
|
export type RasterBandType =
|
|
370
365
|
| 'uint8'
|
|
371
366
|
| 'int8'
|