@carto/api-client 0.4.0-alpha.3 → 0.4.0-alpha.4

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.
@@ -1,4 +1,3 @@
1
- import { $TODO } from '../types-internal.js';
2
1
  /** @internalRemarks Source: @carto/react-api */
3
2
  export interface ModelRequestOptions {
4
3
  method: 'GET' | 'POST';
@@ -6,13 +5,18 @@ export interface ModelRequestOptions {
6
5
  otherOptions?: Record<string, unknown>;
7
6
  body?: string;
8
7
  }
8
+ interface ModelErrorResponse {
9
+ error?: string | string[];
10
+ hint?: string;
11
+ column_name?: string;
12
+ }
9
13
  /**
10
14
  * Return more descriptive error from API
11
15
  * @internalRemarks Source: @carto/react-api
12
16
  */
13
17
  export declare function dealWithApiError({ response, data, }: {
14
18
  response: Response;
15
- data: $TODO;
19
+ data: ModelErrorResponse;
16
20
  }): void;
17
21
  /** @internalRemarks Source: @carto/react-api */
18
22
  export declare function makeCall({ url, accessToken, opts, }: {
@@ -20,3 +24,4 @@ export declare function makeCall({ url, accessToken, opts, }: {
20
24
  accessToken: string;
21
25
  opts: ModelRequestOptions;
22
26
  }): Promise<any>;
27
+ export {};
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "repository": "github:CartoDB/carto-api-client",
5
5
  "author": "Don McCurdy <donmccurdy@carto.com>",
6
6
  "packageManager": "yarn@4.3.1",
7
- "version": "0.4.0-alpha.3",
7
+ "version": "0.4.0-alpha.4",
8
8
  "license": "MIT",
9
9
  "publishConfig": {
10
10
  "access": "public",
@@ -34,7 +34,7 @@
34
34
  "dev": "concurrently \"yarn build:watch\" \"vite --config examples/vite.config.ts --open\"",
35
35
  "test": "vitest run --typecheck",
36
36
  "test:watch": "vitest watch --typecheck",
37
- "coverage": "vitest run --coverage.enabled --coverage.all false",
37
+ "coverage": "vitest run --coverage",
38
38
  "lint": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --check",
39
39
  "format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --write",
40
40
  "clean": "rimraf build/*",
@@ -5,7 +5,8 @@
5
5
  import {isPureObject} from '../utils';
6
6
  import {CartoAPIError, APIErrorContext} from './carto-api-error';
7
7
  import {V3_MINOR_VERSION} from '../constants-internal';
8
- import {DEFAULT_CLIENT, DEFAULT_MAX_LENGTH_URL} from '../constants';
8
+ import {DEFAULT_MAX_LENGTH_URL} from '../constants-internal';
9
+ import {getClient} from '../client';
9
10
 
10
11
  const DEFAULT_HEADERS = {
11
12
  Accept: 'application/json',
@@ -32,7 +33,7 @@ export async function requestWithParameters<T = any>({
32
33
  // user-provided parameters.
33
34
  parameters = {
34
35
  v: V3_MINOR_VERSION,
35
- client: DEFAULT_CLIENT,
36
+ client: getClient(),
36
37
  ...(typeof deck !== 'undefined' &&
37
38
  deck.VERSION && {deckglVersion: deck.VERSION}),
38
39
  ...parameters,
package/src/client.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @internal
3
- * @internalRemarks Source: @carto/react-core
3
+ * @internalRemarks Source: @carto/react-core, @carto/constants, @deck.gl/carto
4
4
  */
5
- let client = 'carto-api-client';
5
+ let client = 'deck-gl-carto';
6
6
 
7
7
  /**
8
8
  * Returns current client ID, used to categorize API requests. For internal use only.
@@ -1,6 +1,5 @@
1
- /******************************************************************************
2
- * VERSIONS
3
- */
1
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
2
+ export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
4
3
 
5
4
  /**
6
5
  * Current version of @carto/api-client.
@@ -11,6 +10,18 @@ export const API_CLIENT_VERSION = __CARTO_API_CLIENT_VERSION;
11
10
  /** @internal */
12
11
  export const V3_MINOR_VERSION = '3.4';
13
12
 
13
+ /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
14
+ export const DEFAULT_GEO_COLUMN = 'geom';
15
+
16
+ /**
17
+ * Fastly default limit is 8192; leave some padding.
18
+ * @internalRemarks Source: @deck.gl/carto
19
+ */
20
+ export const DEFAULT_MAX_LENGTH_URL = 7000;
21
+
22
+ /** @internalRemarks Source: @deck.gl/carto */
23
+ export const DEFAULT_TILE_RESOLUTION = 0.5;
24
+
14
25
  /**
15
26
  * @internalRemarks Source: @deck.gl/carto
16
27
  * @internal
package/src/constants.ts CHANGED
@@ -28,28 +28,3 @@ export enum ApiVersion {
28
28
  V2 = 'v2',
29
29
  V3 = 'v3',
30
30
  }
31
-
32
- /******************************************************************************
33
- * DEFAULTS
34
- */
35
-
36
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
37
- export const DEFAULT_API_BASE_URL = 'https://gcp-us-east1.api.carto.com';
38
-
39
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
40
- export const DEFAULT_CLIENT = 'deck-gl-carto';
41
-
42
- /** @internalRemarks Source: @carto/constants, @deck.gl/carto */
43
- export const DEFAULT_GEO_COLUMN = 'geom';
44
-
45
- /**
46
- * Fastly default limit is 8192; leave some padding.
47
- * @internalRemarks Source: @deck.gl/carto
48
- */
49
- export const DEFAULT_MAX_LENGTH_URL = 7000;
50
-
51
- /** @internalRemarks Source: @deck.gl/carto */
52
- export const DEFAULT_TILE_SIZE = 512;
53
-
54
- /** @internalRemarks Source: @deck.gl/carto */
55
- export const DEFAULT_TILE_RESOLUTION = 0.5;
@@ -1,4 +1,3 @@
1
- import {$TODO} from '../types-internal.js';
2
1
  import {InvalidColumnError} from '../utils.js';
3
2
 
4
3
  /** @internalRemarks Source: @carto/react-api */
@@ -9,6 +8,12 @@ export interface ModelRequestOptions {
9
8
  body?: string;
10
9
  }
11
10
 
11
+ interface ModelErrorResponse {
12
+ error?: string | string[];
13
+ hint?: string;
14
+ column_name?: string;
15
+ }
16
+
12
17
  /**
13
18
  * Return more descriptive error from API
14
19
  * @internalRemarks Source: @carto/react-api
@@ -18,13 +23,16 @@ export function dealWithApiError({
18
23
  data,
19
24
  }: {
20
25
  response: Response;
21
- data: $TODO;
26
+ data: ModelErrorResponse;
22
27
  }) {
23
28
  if (data.error === 'Column not found') {
24
29
  throw new InvalidColumnError(`${data.error} ${data.column_name}`);
25
30
  }
26
31
 
27
- if (data.error?.includes('Missing columns')) {
32
+ if (
33
+ typeof data.error === 'string' &&
34
+ data.error?.includes('Missing columns')
35
+ ) {
28
36
  throw new InvalidColumnError(data.error);
29
37
  }
30
38
 
@@ -1,4 +1,4 @@
1
- import {DEFAULT_GEO_COLUMN} from '../constants.js';
1
+ import {DEFAULT_GEO_COLUMN} from '../constants-internal.js';
2
2
  import {
3
3
  Filter,
4
4
  FilterLogicalOperator,
@@ -5,9 +5,8 @@
5
5
  /* eslint-disable camelcase */
6
6
  import {
7
7
  DEFAULT_API_BASE_URL,
8
- DEFAULT_CLIENT,
9
8
  DEFAULT_MAX_LENGTH_URL,
10
- } from '../constants';
9
+ } from '../constants-internal';
11
10
  import {buildSourceUrl} from '../api/endpoints';
12
11
  import {requestWithParameters} from '../api/request-with-parameters';
13
12
  import type {
@@ -20,10 +19,11 @@ import type {
20
19
  } from './types';
21
20
  import {MapType} from '../types';
22
21
  import {APIErrorContext} from '../api';
22
+ import {getClient} from '../client';
23
23
 
24
24
  export const SOURCE_DEFAULTS: SourceOptionalOptions = {
25
25
  apiBaseUrl: DEFAULT_API_BASE_URL,
26
- clientId: DEFAULT_CLIENT,
26
+ clientId: getClient(),
27
27
  format: 'tilejson',
28
28
  headers: {},
29
29
  maxLengthURL: DEFAULT_MAX_LENGTH_URL,
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  /* eslint-disable camelcase */
6
- import {DEFAULT_TILE_RESOLUTION} from '../constants.js';
6
+ import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
7
7
  import {
8
8
  WidgetQuerySource,
9
9
  WidgetQuerySourceResult,
@@ -3,7 +3,7 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
5
  /* eslint-disable camelcase */
6
- import {DEFAULT_TILE_RESOLUTION} from '../constants.js';
6
+ import {DEFAULT_TILE_RESOLUTION} from '../constants-internal.js';
7
7
  import {
8
8
  WidgetTableSource,
9
9
  WidgetTableSourceResult,
package/src/types.ts CHANGED
@@ -41,7 +41,6 @@ export interface Filters {
41
41
  [column: string]: Filter;
42
42
  }
43
43
 
44
- // TODO: Would `{[FilterType.IN]?: number[] | string[]}` also be valid?
45
44
  /** @internalRemarks Source: @carto/react-api, @deck.gl/carto */
46
45
  export interface Filter {
47
46
  [FilterType.IN]?: {owner?: string; values: number[] | string[]};
package/src/utils.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import {Filter} from './types.js';
2
2
  import {FilterType} from './constants.js';
3
- import {$TODO} from './types-internal.js';
4
3
 
5
4
  const FILTER_TYPES = new Set(Object.values(FilterType));
6
5
  const isFilterType = (type: string): type is FilterType =>
@@ -26,7 +25,7 @@ export function getApplicableFilters(
26
25
  const isApplicable = !owner || !filter?.owner || filter?.owner !== owner;
27
26
  if (filter && isApplicable) {
28
27
  applicableFilters[column] ||= {};
29
- applicableFilters[column][type] = filter as $TODO;
28
+ (applicableFilters[column][type] as typeof filter) = filter;
30
29
  }
31
30
  }
32
31
  }
@@ -20,11 +20,11 @@ import {getApplicableFilters, normalizeObjectKeys} from '../utils.js';
20
20
  import {getClient} from '../client.js';
21
21
  import {ModelSource} from '../models/model.js';
22
22
  import {SourceOptions} from '../sources/index.js';
23
+ import {ApiVersion} from '../constants.js';
23
24
  import {
24
- ApiVersion,
25
25
  DEFAULT_API_BASE_URL,
26
26
  DEFAULT_GEO_COLUMN,
27
- } from '../constants.js';
27
+ } from '../constants-internal.js';
28
28
 
29
29
  export interface WidgetBaseSourceProps extends Omit<SourceOptions, 'filters'> {
30
30
  apiVersion?: ApiVersion;