@carto/api-client 0.5.12 → 0.5.14

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.12",
11
+ "version": "0.5.14",
12
12
  "license": "MIT",
13
13
  "publishConfig": {
14
14
  "access": "public"
@@ -125,8 +125,8 @@
125
125
  "tsup": "^8.3.6",
126
126
  "typescript": "~5.8.2",
127
127
  "typescript-eslint": "^8.26.1",
128
- "vite": "^6.2.2",
129
- "vitest": "3.2.3"
128
+ "vite": "^7.0.0",
129
+ "vitest": "3.2.4"
130
130
  },
131
131
  "resolutions": {
132
132
  "@carto/api-client": "portal:./",
@@ -0,0 +1,8 @@
1
+ export enum RasterBandColorinterp {
2
+ Gray = 'gray',
3
+ Red = 'red',
4
+ Green = 'green',
5
+ Blue = 'blue',
6
+ Alpha = 'alpha',
7
+ Palette = 'palette',
8
+ }
@@ -34,6 +34,7 @@ export const h3TilesetSource = async function (
34
34
  tileFormat: getTileFormat(result),
35
35
  spatialDataColumn,
36
36
  spatialDataType: 'h3',
37
+ spatialDataBounds: result.bounds,
37
38
  }),
38
39
  })
39
40
  ) as Promise<H3TilesetSourceResponse>;
@@ -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';
@@ -34,6 +34,7 @@ export const quadbinTilesetSource = async function (
34
34
  tileFormat: getTileFormat(result),
35
35
  spatialDataColumn,
36
36
  spatialDataType: 'quadbin',
37
+ spatialDataBounds: result.bounds,
37
38
  }),
38
39
  })
39
40
  ) as Promise<QuadbinTilesetSourceResponse>;
@@ -43,6 +43,7 @@ export const rasterSource = async function (
43
43
  tileFormat: getTileFormat(result),
44
44
  spatialDataColumn: 'quadbin',
45
45
  spatialDataType: 'quadbin',
46
+ spatialDataBounds: result.bounds,
46
47
  rasterMetadata: result.raster_metadata!,
47
48
  }),
48
49
  })
@@ -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. */
@@ -360,15 +361,6 @@ export type RasterMetadataBandStats = {
360
361
  version?: string;
361
362
  };
362
363
 
363
- export enum RasterBandColorinterp {
364
- Gray = 'gray',
365
- Red = 'red',
366
- Green = 'green',
367
- Blue = 'blue',
368
- Alpha = 'alpha',
369
- Palette = 'palette',
370
- }
371
-
372
364
  export type RasterBandType =
373
365
  | 'uint8'
374
366
  | 'int8'
@@ -35,6 +35,7 @@ export const vectorTilesetSource = async function (
35
35
  tileFormat: getTileFormat(result),
36
36
  spatialDataColumn,
37
37
  spatialDataType: 'geo',
38
+ spatialDataBounds: result.bounds,
38
39
  }),
39
40
  })
40
41
  ) as Promise<VectorTilesetSourceResponse>;
@@ -1,3 +1,4 @@
1
+ import type {BBox} from 'geojson';
1
2
  import type {
2
3
  SpatialFilterPolyfillMode,
3
4
  TileResolution,
@@ -206,6 +207,9 @@ export interface TimeSeriesRequestOptions extends BaseRequestOptions {
206
207
  splitByCategoryValues?: string[];
207
208
  }
208
209
 
210
+ /** @experimental */
211
+ export type ExtentRequestOptions = BaseRequestOptions;
212
+
209
213
  /******************************************************************************
210
214
  * WIDGET API RESPONSES
211
215
  */
@@ -256,3 +260,6 @@ export type TimeSeriesResponse = {
256
260
 
257
261
  /** Response from {@link WidgetRemoteSource#getHistogram}. */
258
262
  export type HistogramResponse = number[];
263
+
264
+ /** @experimental */
265
+ export type ExtentResponse = {bbox: BBox};
@@ -2,6 +2,8 @@ import {executeModel, type ModelSource} from '../models/index.js';
2
2
  import type {
3
3
  CategoryRequestOptions,
4
4
  CategoryResponse,
5
+ ExtentRequestOptions,
6
+ ExtentResponse,
5
7
  FeaturesRequestOptions,
6
8
  FeaturesResponse,
7
9
  FormulaRequestOptions,
@@ -24,6 +26,8 @@ import type {Filters} from '../types.js';
24
26
  import {AggregationTypes, ApiVersion} from '../constants.js';
25
27
  import {getApplicableFilters} from '../filters.js';
26
28
  import {OTHERS_CATEGORY_NAME} from './constants.js';
29
+ import {requestWithParameters} from '../api/request-with-parameters.js';
30
+ import type {APIErrorContext} from '../api/carto-api-error.js';
27
31
 
28
32
  export type WidgetRemoteSourceProps = WidgetSourceProps;
29
33
 
@@ -389,4 +393,64 @@ export abstract class WidgetRemoteSource<
389
393
  categories: res.metadata?.categories,
390
394
  }));
391
395
  }
396
+
397
+ /** @experimental */
398
+ async getExtent(options: ExtentRequestOptions = {}): Promise<ExtentResponse> {
399
+ const {signal, filters = this.props.filters, filterOwner} = options;
400
+
401
+ const {
402
+ type,
403
+ data,
404
+ apiBaseUrl,
405
+ apiVersion,
406
+ connectionName,
407
+ spatialDataColumn,
408
+ spatialDataType,
409
+ queryParameters,
410
+ } = this.getModelSource(filters, filterOwner);
411
+
412
+ assert(apiVersion === ApiVersion.V3, 'Stats API requires CARTO 3+');
413
+
414
+ let url: string;
415
+
416
+ const parameters: Record<string, unknown> = {filters, spatialDataType};
417
+
418
+ if (type === 'query') {
419
+ url = `${apiBaseUrl}/${apiVersion}/stats/${connectionName}/${spatialDataColumn}`;
420
+ parameters.q = data;
421
+ parameters.queryParameters = queryParameters;
422
+ } else {
423
+ url = `${apiBaseUrl}/${apiVersion}/stats/${connectionName}/${data}/${spatialDataColumn}`;
424
+ }
425
+
426
+ const headers = {
427
+ Authorization: `Bearer ${this.props.accessToken}`,
428
+ ...this.props.headers,
429
+ };
430
+
431
+ const errorContext: APIErrorContext = {
432
+ requestType: 'Tile stats',
433
+ connection: connectionName,
434
+ type: type,
435
+ };
436
+
437
+ type StatsResponse = {
438
+ extent: {
439
+ xmin: number;
440
+ ymin: number;
441
+ xmax: number;
442
+ ymax: number;
443
+ };
444
+ };
445
+
446
+ return requestWithParameters<StatsResponse>({
447
+ baseUrl: url,
448
+ headers,
449
+ signal,
450
+ errorContext,
451
+ parameters,
452
+ }).then(({extent: {xmin, ymin, xmax, ymax}}) => ({
453
+ bbox: [xmin, ymin, xmax, ymax],
454
+ }));
455
+ }
392
456
  }
@@ -1,6 +1,8 @@
1
1
  import type {
2
2
  CategoryRequestOptions,
3
3
  CategoryResponse,
4
+ ExtentRequestOptions,
5
+ ExtentResponse,
4
6
  FeaturesRequestOptions,
5
7
  FeaturesResponse,
6
8
  FormulaRequestOptions,
@@ -124,4 +126,7 @@ export abstract class WidgetSource<
124
126
  abstract getTimeSeries(
125
127
  options: TimeSeriesRequestOptions
126
128
  ): Promise<TimeSeriesResponse>;
129
+
130
+ /** @experimental */
131
+ abstract getExtent(options?: ExtentRequestOptions): Promise<ExtentResponse>;
127
132
  }
@@ -2,6 +2,7 @@
2
2
  import type {
3
3
  CategoryRequestOptions,
4
4
  CategoryResponse,
5
+ ExtentResponse,
5
6
  FeaturesResponse,
6
7
  FormulaRequestOptions,
7
8
  FormulaResponse,
@@ -390,6 +391,11 @@ export class WidgetTilesetSourceImpl extends WidgetSource<WidgetTilesetSourcePro
390
391
  };
391
392
  }
392
393
 
394
+ /** @experimental */
395
+ async getExtent(): Promise<ExtentResponse> {
396
+ return Promise.reject(new Error('not implemented'));
397
+ }
398
+
393
399
  /****************************************************************************
394
400
  * INTERNAL
395
401
  */
@@ -1,6 +1,7 @@
1
1
  import type {
2
2
  CategoryRequestOptions,
3
3
  CategoryResponse,
4
+ ExtentResponse,
4
5
  FeaturesResponse,
5
6
  FormulaRequestOptions,
6
7
  FormulaResponse,
@@ -17,7 +18,7 @@ import type {
17
18
  } from './types.js';
18
19
  import type {SpatialFilter, Tile} from '../types.js';
19
20
  import type {TileFeatureExtractOptions} from '../filters/index.js';
20
- import type {FeatureCollection} from 'geojson';
21
+ import type {BBox, FeatureCollection} from 'geojson';
21
22
  import {WidgetSource, type WidgetSourceProps} from './widget-source.js';
22
23
  import {Method} from '../workers/constants.js';
23
24
  import type {WorkerRequest, WorkerResponse} from '../workers/types.js';
@@ -29,6 +30,10 @@ export type WidgetTilesetSourceProps = WidgetSourceProps &
29
30
  Omit<TilesetSourceOptions, 'filters'> & {
30
31
  tileFormat: TileFormat;
31
32
  spatialDataType: SpatialDataType;
33
+ /**
34
+ * Extent of spatial data, typically from TileJSON. Does not include filters.
35
+ */
36
+ spatialDataBounds: BBox;
32
37
  };
33
38
 
34
39
  export type WidgetTilesetSourceResult = {widgetSource: WidgetTilesetSource};
@@ -320,4 +325,11 @@ export class WidgetTilesetSource<
320
325
  }: RangeRequestOptions): Promise<RangeResponse> {
321
326
  return this._executeWorkerMethod(Method.GET_RANGE, [options], signal);
322
327
  }
328
+
329
+ /** @experimental */
330
+ async getExtent(): Promise<ExtentResponse> {
331
+ return Promise.resolve({
332
+ bbox: this.props.spatialDataBounds,
333
+ });
334
+ }
323
335
  }