@carto/api-client 0.5.8 → 0.5.9-alpha.PR193.2

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/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.8",
11
+ "version": "0.5.9-alpha.PR193.2",
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 & QuerySourceOptions;
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 = {client: clientId, ...urlParameters};
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
- baseUrl.searchParams.set(
147
- key,
148
- (value as string | boolean | number).toString()
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();
@@ -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',
@@ -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 = {
@@ -61,6 +61,7 @@ export abstract class WidgetRemoteSource<
61
61
  filtersLogicalOperator: props.filtersLogicalOperator,
62
62
  spatialDataType: props.spatialDataType,
63
63
  spatialDataColumn: props.spatialDataColumn,
64
+ tags: props.tags,
64
65
  };
65
66
  }
66
67