@deck.gl/carto 8.6.0 → 8.6.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.
Files changed (51) hide show
  1. package/dist/dist.dev.js +85 -20
  2. package/dist/es5/api/index.js +13 -7
  3. package/dist/es5/api/index.js.map +1 -1
  4. package/dist/es5/api/maps-api-common.js +11 -6
  5. package/dist/es5/api/maps-api-common.js.map +1 -1
  6. package/dist/es5/api/maps-client.js +98 -151
  7. package/dist/es5/api/maps-client.js.map +1 -1
  8. package/dist/es5/api/maps-v3-client.js +206 -253
  9. package/dist/es5/api/maps-v3-client.js.map +1 -1
  10. package/dist/es5/basemap.js +1 -1
  11. package/dist/es5/basemap.js.map +1 -1
  12. package/dist/es5/config.js +25 -25
  13. package/dist/es5/config.js.map +1 -1
  14. package/dist/es5/index.js +21 -15
  15. package/dist/es5/index.js.map +1 -1
  16. package/dist/es5/layers/carto-bqtiler-layer.js +6 -39
  17. package/dist/es5/layers/carto-bqtiler-layer.js.map +1 -1
  18. package/dist/es5/layers/carto-layer.js +132 -211
  19. package/dist/es5/layers/carto-layer.js.map +1 -1
  20. package/dist/es5/layers/carto-sql-layer.js +6 -39
  21. package/dist/es5/layers/carto-sql-layer.js.map +1 -1
  22. package/dist/es5/style/color-bins-style.js +10 -11
  23. package/dist/es5/style/color-bins-style.js.map +1 -1
  24. package/dist/es5/style/color-categories-style.js +13 -38
  25. package/dist/es5/style/color-categories-style.js.map +1 -1
  26. package/dist/es5/style/color-continuous-style.js +10 -11
  27. package/dist/es5/style/color-continuous-style.js.map +1 -1
  28. package/dist/es5/style/palette.js +11 -19
  29. package/dist/es5/style/palette.js.map +1 -1
  30. package/dist/es5/style/utils.js +6 -13
  31. package/dist/es5/style/utils.js.map +1 -1
  32. package/dist/esm/api/index.js +1 -1
  33. package/dist/esm/api/index.js.map +1 -1
  34. package/dist/esm/api/maps-api-common.js +4 -0
  35. package/dist/esm/api/maps-api-common.js.map +1 -1
  36. package/dist/esm/api/maps-client.js +11 -6
  37. package/dist/esm/api/maps-client.js.map +1 -1
  38. package/dist/esm/api/maps-v3-client.js +70 -16
  39. package/dist/esm/api/maps-v3-client.js.map +1 -1
  40. package/dist/esm/config.js +4 -4
  41. package/dist/esm/config.js.map +1 -1
  42. package/dist/esm/index.js +1 -1
  43. package/dist/esm/index.js.map +1 -1
  44. package/dist.min.js +1 -1
  45. package/package.json +2 -2
  46. package/src/api/index.js +1 -1
  47. package/src/api/maps-api-common.js +5 -0
  48. package/src/api/maps-client.js +16 -3
  49. package/src/api/maps-v3-client.js +52 -11
  50. package/src/config.js +4 -4
  51. package/src/index.js +1 -0
package/dist/dist.dev.js CHANGED
@@ -10256,7 +10256,7 @@ module.exports = Object.assign(deck, {carto: CartoUtils});
10256
10256
  /*!**************************!*\
10257
10257
  !*** ./src/api/index.js ***!
10258
10258
  \**************************/
10259
- /*! exports provided: FORMATS, MAP_TYPES, API_VERSIONS, getDataV2, CONNECTIONS, getData, mapInstantiation */
10259
+ /*! exports provided: FORMATS, MAP_TYPES, API_VERSIONS, getDataV2, CONNECTIONS, fetchLayerData, getData, mapInstantiation */
10260
10260
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
10261
10261
 
10262
10262
  "use strict";
@@ -10274,6 +10274,8 @@ __webpack_require__.r(__webpack_exports__);
10274
10274
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CONNECTIONS", function() { return _maps_client__WEBPACK_IMPORTED_MODULE_1__["CONNECTIONS"]; });
10275
10275
 
10276
10276
  /* harmony import */ var _maps_v3_client__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./maps-v3-client */ "./src/api/maps-v3-client.js");
10277
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fetchLayerData", function() { return _maps_v3_client__WEBPACK_IMPORTED_MODULE_2__["fetchLayerData"]; });
10278
+
10277
10279
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getData", function() { return _maps_v3_client__WEBPACK_IMPORTED_MODULE_2__["getData"]; });
10278
10280
 
10279
10281
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mapInstantiation", function() { return _maps_v3_client__WEBPACK_IMPORTED_MODULE_2__["mapInstantiation"]; });
@@ -10289,7 +10291,7 @@ __webpack_require__.r(__webpack_exports__);
10289
10291
  /*!************************************!*\
10290
10292
  !*** ./src/api/maps-api-common.js ***!
10291
10293
  \************************************/
10292
- /*! exports provided: DEFAULT_USER_COMPONENT_IN_URL, DEFAULT_REGION_COMPONENT_IN_URL, API_VERSIONS, MAP_TYPES, FORMATS, encodeParameter */
10294
+ /*! exports provided: DEFAULT_USER_COMPONENT_IN_URL, DEFAULT_REGION_COMPONENT_IN_URL, API_VERSIONS, DEFAULT_MAPS_URL_FORMAT, MAP_TYPES, FORMATS, encodeParameter */
10293
10295
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
10294
10296
 
10295
10297
  "use strict";
@@ -10297,6 +10299,7 @@ __webpack_require__.r(__webpack_exports__);
10297
10299
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_USER_COMPONENT_IN_URL", function() { return DEFAULT_USER_COMPONENT_IN_URL; });
10298
10300
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_REGION_COMPONENT_IN_URL", function() { return DEFAULT_REGION_COMPONENT_IN_URL; });
10299
10301
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "API_VERSIONS", function() { return API_VERSIONS; });
10302
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_MAPS_URL_FORMAT", function() { return DEFAULT_MAPS_URL_FORMAT; });
10300
10303
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MAP_TYPES", function() { return MAP_TYPES; });
10301
10304
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "FORMATS", function() { return FORMATS; });
10302
10305
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "encodeParameter", function() { return encodeParameter; });
@@ -10309,6 +10312,11 @@ const API_VERSIONS = {
10309
10312
  V3: 'v3'
10310
10313
  };
10311
10314
 
10315
+ const DEFAULT_MAPS_URL_FORMAT = {
10316
+ [API_VERSIONS.V1]: `https://${DEFAULT_USER_COMPONENT_IN_URL}.carto.com/api/v1/map`,
10317
+ [API_VERSIONS.V2]: `https://maps-api-v2.${DEFAULT_REGION_COMPONENT_IN_URL}.carto.com/user/${DEFAULT_USER_COMPONENT_IN_URL}`
10318
+ };
10319
+
10312
10320
  const MAP_TYPES = {
10313
10321
  QUERY: 'query',
10314
10322
  TABLE: 'table',
@@ -10364,8 +10372,20 @@ const TILE_EXTENT = 4096;
10364
10372
  * Obtain a TileJson from Maps API v1 and v2
10365
10373
  */
10366
10374
  async function getDataV2({type, source, credentials}) {
10367
- const localCreds = {...Object(_config__WEBPACK_IMPORTED_MODULE_0__["getDefaultCredentials"])(), ...credentials};
10368
- const {apiVersion} = localCreds;
10375
+ const defaultCredentials = Object(_config__WEBPACK_IMPORTED_MODULE_0__["getDefaultCredentials"])();
10376
+ const apiVersion = (credentials && credentials.apiVersion) || defaultCredentials.apiVersion;
10377
+ // Only pick up default credentials if they have been defined for
10378
+ // correct API version
10379
+ const localCreds = {
10380
+ ..._config__WEBPACK_IMPORTED_MODULE_0__["defaultClassicCredentials"],
10381
+ ...(defaultCredentials.apiVersion === apiVersion && defaultCredentials),
10382
+ ...credentials
10383
+ };
10384
+
10385
+ if (!localCreds.mapsUrl) {
10386
+ localCreds.mapsUrl = _maps_api_common__WEBPACK_IMPORTED_MODULE_1__["DEFAULT_MAPS_URL_FORMAT"][apiVersion];
10387
+ }
10388
+
10369
10389
  let url;
10370
10390
 
10371
10391
  const connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;
@@ -10500,12 +10520,13 @@ function createMapConfig(sql) {
10500
10520
  /*!***********************************!*\
10501
10521
  !*** ./src/api/maps-v3-client.js ***!
10502
10522
  \***********************************/
10503
- /*! exports provided: mapInstantiation, getData */
10523
+ /*! exports provided: mapInstantiation, fetchLayerData, getData */
10504
10524
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
10505
10525
 
10506
10526
  "use strict";
10507
10527
  __webpack_require__.r(__webpack_exports__);
10508
10528
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "mapInstantiation", function() { return mapInstantiation; });
10529
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "fetchLayerData", function() { return fetchLayerData; });
10509
10530
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getData", function() { return getData; });
10510
10531
  /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../config */ "./src/config.js");
10511
10532
  /* harmony import */ var _maps_api_common__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./maps-api-common */ "./src/api/maps-api-common.js");
@@ -10581,9 +10602,11 @@ function dealWithError({response, error}) {
10581
10602
  /**
10582
10603
  * Build a URL with all required parameters
10583
10604
  */
10584
- function getParameters({type, source, geoColumn, columns}) {
10585
- const encodedClient = Object(_maps_api_common__WEBPACK_IMPORTED_MODULE_1__["encodeParameter"])('client', 'deck-gl-carto');
10586
- const parameters = [encodedClient];
10605
+ function getParameters({type, source, geoColumn, columns, schema}) {
10606
+ const parameters = [Object(_maps_api_common__WEBPACK_IMPORTED_MODULE_1__["encodeParameter"])('client', 'deck-gl-carto')];
10607
+ if (schema) {
10608
+ parameters.push(Object(_maps_api_common__WEBPACK_IMPORTED_MODULE_1__["encodeParameter"])('schema', true));
10609
+ }
10587
10610
 
10588
10611
  const sourceName = type === _maps_api_common__WEBPACK_IMPORTED_MODULE_1__["MAP_TYPES"].QUERY ? 'q' : 'name';
10589
10612
  parameters.push(Object(_maps_api_common__WEBPACK_IMPORTED_MODULE_1__["encodeParameter"])(sourceName, source));
@@ -10606,10 +10629,11 @@ async function mapInstantiation({
10606
10629
  connection,
10607
10630
  credentials,
10608
10631
  geoColumn,
10609
- columns
10632
+ columns,
10633
+ schema
10610
10634
  }) {
10611
10635
  const baseUrl = `${credentials.mapsUrl}/${connection}/${type}`;
10612
- const url = `${baseUrl}?${getParameters({type, source, geoColumn, columns})}`;
10636
+ const url = `${baseUrl}?${getParameters({type, source, geoColumn, columns, schema})}`;
10613
10637
  const {accessToken} = credentials;
10614
10638
 
10615
10639
  const format = 'json';
@@ -10636,9 +10660,7 @@ function getUrlFromMetadata(metadata, format) {
10636
10660
  return null;
10637
10661
  }
10638
10662
 
10639
- async function getData({type, source, connection, credentials, geoColumn, columns, format}) {
10640
- const localCreds = {...Object(_config__WEBPACK_IMPORTED_MODULE_0__["getDefaultCredentials"])(), ...credentials};
10641
-
10663
+ function checkGetLayerDataParameters({type, source, connection, localCreds}) {
10642
10664
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_2__["log"].assert(connection, 'Must define connection');
10643
10665
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_2__["log"].assert(type, 'Must define a type');
10644
10666
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_2__["log"].assert(source, 'Must define a source');
@@ -10646,7 +10668,26 @@ async function getData({type, source, connection, credentials, geoColumn, column
10646
10668
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_2__["log"].assert(localCreds.apiVersion === _maps_api_common__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V3, 'Method only available for v3');
10647
10669
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_2__["log"].assert(localCreds.apiBaseUrl, 'Must define apiBaseUrl');
10648
10670
  _deck_gl_core__WEBPACK_IMPORTED_MODULE_2__["log"].assert(localCreds.accessToken, 'Must define an accessToken');
10649
- _deck_gl_core__WEBPACK_IMPORTED_MODULE_2__["log"].assert(localCreds.mapsUrl, 'mapsUrl cannot be undefined');
10671
+ }
10672
+
10673
+ async function fetchLayerData({
10674
+ type,
10675
+ source,
10676
+ connection,
10677
+ credentials,
10678
+ geoColumn,
10679
+ columns,
10680
+ format,
10681
+ schema
10682
+ }) {
10683
+ const defaultCredentials = Object(_config__WEBPACK_IMPORTED_MODULE_0__["getDefaultCredentials"])();
10684
+ // Only pick up default credentials if they have been defined for
10685
+ // correct API version
10686
+ const localCreds = {
10687
+ ...(defaultCredentials.apiVersion === _maps_api_common__WEBPACK_IMPORTED_MODULE_1__["API_VERSIONS"].V3 && defaultCredentials),
10688
+ ...credentials
10689
+ };
10690
+ checkGetLayerDataParameters({type, source, connection, localCreds});
10650
10691
 
10651
10692
  if (!localCreds.mapsUrl) {
10652
10693
  localCreds.mapsUrl = Object(_config__WEBPACK_IMPORTED_MODULE_0__["buildMapsUrlFromBase"])(localCreds.apiBaseUrl);
@@ -10658,7 +10699,8 @@ async function getData({type, source, connection, credentials, geoColumn, column
10658
10699
  connection,
10659
10700
  credentials: localCreds,
10660
10701
  geoColumn,
10661
- columns
10702
+ columns,
10703
+ schema
10662
10704
  });
10663
10705
  let url;
10664
10706
  let mapFormat;
@@ -10681,7 +10723,27 @@ async function getData({type, source, connection, credentials, geoColumn, column
10681
10723
 
10682
10724
  const {accessToken} = localCreds;
10683
10725
 
10684
- return await request({url, format: mapFormat, accessToken});
10726
+ const data = await request({url, format: mapFormat, accessToken});
10727
+ const result = {data, format: mapFormat};
10728
+ if (schema) {
10729
+ result.schema = metadata.schema;
10730
+ }
10731
+
10732
+ return result;
10733
+ }
10734
+
10735
+ async function getData({type, source, connection, credentials, geoColumn, columns, format}) {
10736
+ const layerData = await fetchLayerData({
10737
+ type,
10738
+ source,
10739
+ connection,
10740
+ credentials,
10741
+ geoColumn,
10742
+ columns,
10743
+ format,
10744
+ schema: false
10745
+ });
10746
+ return layerData.data;
10685
10747
  }
10686
10748
 
10687
10749
 
@@ -10714,11 +10776,12 @@ const base_url = 'https://basemaps.cartocdn.com/gl/{basemap}-gl-style/style.json
10714
10776
  /*!***********************!*\
10715
10777
  !*** ./src/config.js ***!
10716
10778
  \***********************/
10717
- /*! exports provided: setDefaultCredentials, getDefaultCredentials, buildMapsUrlFromBase */
10779
+ /*! exports provided: defaultClassicCredentials, setDefaultCredentials, getDefaultCredentials, buildMapsUrlFromBase */
10718
10780
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
10719
10781
 
10720
10782
  "use strict";
10721
10783
  __webpack_require__.r(__webpack_exports__);
10784
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "defaultClassicCredentials", function() { return defaultClassicCredentials; });
10722
10785
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setDefaultCredentials", function() { return setDefaultCredentials; });
10723
10786
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getDefaultCredentials", function() { return getDefaultCredentials; });
10724
10787
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "buildMapsUrlFromBase", function() { return buildMapsUrlFromBase; });
@@ -10747,7 +10810,7 @@ function setDefaultCredentials(opts) {
10747
10810
 
10748
10811
  switch (apiVersion) {
10749
10812
  case _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["API_VERSIONS"].V1:
10750
- opts.mapsUrl = opts.mapsUrl || 'https://{user}.carto.com/api/v1/map';
10813
+ opts.mapsUrl = opts.mapsUrl || _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_MAPS_URL_FORMAT"][apiVersion];
10751
10814
  credentials = {
10752
10815
  apiVersion,
10753
10816
  ...defaultClassicCredentials,
@@ -10756,7 +10819,7 @@ function setDefaultCredentials(opts) {
10756
10819
  break;
10757
10820
 
10758
10821
  case _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["API_VERSIONS"].V2:
10759
- opts.mapsUrl = opts.mapsUrl || 'https://maps-api-v2.{region}.carto.com/user/{user}';
10822
+ opts.mapsUrl = opts.mapsUrl || _api_maps_api_common__WEBPACK_IMPORTED_MODULE_0__["DEFAULT_MAPS_URL_FORMAT"][apiVersion];
10760
10823
  credentials = {
10761
10824
  apiVersion,
10762
10825
  ...defaultClassicCredentials,
@@ -10806,7 +10869,7 @@ function buildMapsUrlFromBase(apiBaseUrl) {
10806
10869
  /*!**********************!*\
10807
10870
  !*** ./src/index.js ***!
10808
10871
  \**********************/
10809
- /*! exports provided: getDefaultCredentials, setDefaultCredentials, CartoSQLLayer, CartoBQTilerLayer, CartoLayer, BASEMAP, colorBins, colorCategories, colorContinuous, FORMATS, MAP_TYPES, API_VERSIONS, _getDataV2, getData, _mapInstantiation */
10872
+ /*! exports provided: getDefaultCredentials, setDefaultCredentials, CartoSQLLayer, CartoBQTilerLayer, CartoLayer, BASEMAP, colorBins, colorCategories, colorContinuous, FORMATS, MAP_TYPES, API_VERSIONS, fetchLayerData, _getDataV2, getData, _mapInstantiation */
10810
10873
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
10811
10874
 
10812
10875
  "use strict";
@@ -10844,6 +10907,8 @@ __webpack_require__.r(__webpack_exports__);
10844
10907
 
10845
10908
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "API_VERSIONS", function() { return _api__WEBPACK_IMPORTED_MODULE_8__["API_VERSIONS"]; });
10846
10909
 
10910
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fetchLayerData", function() { return _api__WEBPACK_IMPORTED_MODULE_8__["fetchLayerData"]; });
10911
+
10847
10912
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "_getDataV2", function() { return _api__WEBPACK_IMPORTED_MODULE_8__["getDataV2"]; });
10848
10913
 
10849
10914
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getData", function() { return _api__WEBPACK_IMPORTED_MODULE_8__["getData"]; });
@@ -5,43 +5,49 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  Object.defineProperty(exports, "FORMATS", {
7
7
  enumerable: true,
8
- get: function get() {
8
+ get: function () {
9
9
  return _mapsApiCommon.FORMATS;
10
10
  }
11
11
  });
12
12
  Object.defineProperty(exports, "MAP_TYPES", {
13
13
  enumerable: true,
14
- get: function get() {
14
+ get: function () {
15
15
  return _mapsApiCommon.MAP_TYPES;
16
16
  }
17
17
  });
18
18
  Object.defineProperty(exports, "API_VERSIONS", {
19
19
  enumerable: true,
20
- get: function get() {
20
+ get: function () {
21
21
  return _mapsApiCommon.API_VERSIONS;
22
22
  }
23
23
  });
24
24
  Object.defineProperty(exports, "getDataV2", {
25
25
  enumerable: true,
26
- get: function get() {
26
+ get: function () {
27
27
  return _mapsClient.getDataV2;
28
28
  }
29
29
  });
30
30
  Object.defineProperty(exports, "CONNECTIONS", {
31
31
  enumerable: true,
32
- get: function get() {
32
+ get: function () {
33
33
  return _mapsClient.CONNECTIONS;
34
34
  }
35
35
  });
36
+ Object.defineProperty(exports, "fetchLayerData", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _mapsV3Client.fetchLayerData;
40
+ }
41
+ });
36
42
  Object.defineProperty(exports, "getData", {
37
43
  enumerable: true,
38
- get: function get() {
44
+ get: function () {
39
45
  return _mapsV3Client.getData;
40
46
  }
41
47
  });
42
48
  Object.defineProperty(exports, "mapInstantiation", {
43
49
  enumerable: true,
44
- get: function get() {
50
+ get: function () {
45
51
  return _mapsV3Client.mapInstantiation;
46
52
  }
47
53
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/api/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["export {FORMATS, MAP_TYPES, API_VERSIONS} from './maps-api-common';\nexport {getDataV2, CONNECTIONS} from './maps-client';\nexport {getData, mapInstantiation} from './maps-v3-client';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../../src/api/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["export {FORMATS, MAP_TYPES, API_VERSIONS} from './maps-api-common';\nexport {getDataV2, CONNECTIONS} from './maps-client';\nexport {fetchLayerData, getData, mapInstantiation} from './maps-v3-client';\n"],"file":"index.js"}
@@ -4,24 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.encodeParameter = encodeParameter;
7
- exports.FORMATS = exports.MAP_TYPES = exports.API_VERSIONS = exports.DEFAULT_REGION_COMPONENT_IN_URL = exports.DEFAULT_USER_COMPONENT_IN_URL = void 0;
8
- var DEFAULT_USER_COMPONENT_IN_URL = '{user}';
7
+ exports.FORMATS = exports.MAP_TYPES = exports.DEFAULT_MAPS_URL_FORMAT = exports.API_VERSIONS = exports.DEFAULT_REGION_COMPONENT_IN_URL = exports.DEFAULT_USER_COMPONENT_IN_URL = void 0;
8
+ const DEFAULT_USER_COMPONENT_IN_URL = '{user}';
9
9
  exports.DEFAULT_USER_COMPONENT_IN_URL = DEFAULT_USER_COMPONENT_IN_URL;
10
- var DEFAULT_REGION_COMPONENT_IN_URL = '{region}';
10
+ const DEFAULT_REGION_COMPONENT_IN_URL = '{region}';
11
11
  exports.DEFAULT_REGION_COMPONENT_IN_URL = DEFAULT_REGION_COMPONENT_IN_URL;
12
- var API_VERSIONS = {
12
+ const API_VERSIONS = {
13
13
  V1: 'v1',
14
14
  V2: 'v2',
15
15
  V3: 'v3'
16
16
  };
17
17
  exports.API_VERSIONS = API_VERSIONS;
18
- var MAP_TYPES = {
18
+ const DEFAULT_MAPS_URL_FORMAT = {
19
+ [API_VERSIONS.V1]: "https://".concat(DEFAULT_USER_COMPONENT_IN_URL, ".carto.com/api/v1/map"),
20
+ [API_VERSIONS.V2]: "https://maps-api-v2.".concat(DEFAULT_REGION_COMPONENT_IN_URL, ".carto.com/user/").concat(DEFAULT_USER_COMPONENT_IN_URL)
21
+ };
22
+ exports.DEFAULT_MAPS_URL_FORMAT = DEFAULT_MAPS_URL_FORMAT;
23
+ const MAP_TYPES = {
19
24
  QUERY: 'query',
20
25
  TABLE: 'table',
21
26
  TILESET: 'tileset'
22
27
  };
23
28
  exports.MAP_TYPES = MAP_TYPES;
24
- var FORMATS = {
29
+ const FORMATS = {
25
30
  GEOJSON: 'geojson',
26
31
  NDJSON: 'ndjson',
27
32
  TILEJSON: 'tilejson',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/api/maps-api-common.js"],"names":["DEFAULT_USER_COMPONENT_IN_URL","DEFAULT_REGION_COMPONENT_IN_URL","API_VERSIONS","V1","V2","V3","MAP_TYPES","QUERY","TABLE","TILESET","FORMATS","GEOJSON","NDJSON","TILEJSON","JSON","encodeParameter","name","value","encodeURIComponent"],"mappings":";;;;;;;AAAO,IAAMA,6BAA6B,GAAG,QAAtC;;AACA,IAAMC,+BAA+B,GAAG,UAAxC;;AAEA,IAAMC,YAAY,GAAG;AAC1BC,EAAAA,EAAE,EAAE,IADsB;AAE1BC,EAAAA,EAAE,EAAE,IAFsB;AAG1BC,EAAAA,EAAE,EAAE;AAHsB,CAArB;;AAMA,IAAMC,SAAS,GAAG;AACvBC,EAAAA,KAAK,EAAE,OADgB;AAEvBC,EAAAA,KAAK,EAAE,OAFgB;AAGvBC,EAAAA,OAAO,EAAE;AAHc,CAAlB;;AAOA,IAAMC,OAAO,GAAG;AACrBC,EAAAA,OAAO,EAAE,SADY;AAErBC,EAAAA,MAAM,EAAE,QAFa;AAGrBC,EAAAA,QAAQ,EAAE,UAHW;AAIrBC,EAAAA,IAAI,EAAE;AAJe,CAAhB;;;AAUA,SAASC,eAAT,CAAyBC,IAAzB,EAA+BC,KAA/B,EAAsC;AAC3C,mBAAUD,IAAV,cAAkBE,kBAAkB,CAACD,KAAD,CAApC;AACD","sourcesContent":["export const DEFAULT_USER_COMPONENT_IN_URL = '{user}';\nexport const DEFAULT_REGION_COMPONENT_IN_URL = '{region}';\n\nexport const API_VERSIONS = {\n V1: 'v1',\n V2: 'v2',\n V3: 'v3'\n};\n\nexport const MAP_TYPES = {\n QUERY: 'query',\n TABLE: 'table',\n TILESET: 'tileset'\n};\n\n// AVAILABLE FORMATS\nexport const FORMATS = {\n GEOJSON: 'geojson',\n NDJSON: 'ndjson',\n TILEJSON: 'tilejson',\n JSON: 'json'\n};\n\n/**\n * Simple encode parameter\n */\nexport function encodeParameter(name, value) {\n return `${name}=${encodeURIComponent(value)}`;\n}\n"],"file":"maps-api-common.js"}
1
+ {"version":3,"sources":["../../../src/api/maps-api-common.js"],"names":["DEFAULT_USER_COMPONENT_IN_URL","DEFAULT_REGION_COMPONENT_IN_URL","API_VERSIONS","V1","V2","V3","DEFAULT_MAPS_URL_FORMAT","MAP_TYPES","QUERY","TABLE","TILESET","FORMATS","GEOJSON","NDJSON","TILEJSON","JSON","encodeParameter","name","value","encodeURIComponent"],"mappings":";;;;;;;AAAO,MAAMA,6BAA6B,GAAG,QAAtC;;AACA,MAAMC,+BAA+B,GAAG,UAAxC;;AAEA,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,EAAE,EAAE,IADsB;AAE1BC,EAAAA,EAAE,EAAE,IAFsB;AAG1BC,EAAAA,EAAE,EAAE;AAHsB,CAArB;;AAMA,MAAMC,uBAAuB,GAAG;AACrC,GAACJ,YAAY,CAACC,EAAd,qBAA8BH,6BAA9B,0BADqC;AAErC,GAACE,YAAY,CAACE,EAAd,iCAA0CH,+BAA1C,6BAA4FD,6BAA5F;AAFqC,CAAhC;;AAKA,MAAMO,SAAS,GAAG;AACvBC,EAAAA,KAAK,EAAE,OADgB;AAEvBC,EAAAA,KAAK,EAAE,OAFgB;AAGvBC,EAAAA,OAAO,EAAE;AAHc,CAAlB;;AAOA,MAAMC,OAAO,GAAG;AACrBC,EAAAA,OAAO,EAAE,SADY;AAErBC,EAAAA,MAAM,EAAE,QAFa;AAGrBC,EAAAA,QAAQ,EAAE,UAHW;AAIrBC,EAAAA,IAAI,EAAE;AAJe,CAAhB;;;AAUA,SAASC,eAAT,CAAyBC,IAAzB,EAA+BC,KAA/B,EAAsC;AAC3C,mBAAUD,IAAV,cAAkBE,kBAAkB,CAACD,KAAD,CAApC;AACD","sourcesContent":["export const DEFAULT_USER_COMPONENT_IN_URL = '{user}';\nexport const DEFAULT_REGION_COMPONENT_IN_URL = '{region}';\n\nexport const API_VERSIONS = {\n V1: 'v1',\n V2: 'v2',\n V3: 'v3'\n};\n\nexport const DEFAULT_MAPS_URL_FORMAT = {\n [API_VERSIONS.V1]: `https://${DEFAULT_USER_COMPONENT_IN_URL}.carto.com/api/v1/map`,\n [API_VERSIONS.V2]: `https://maps-api-v2.${DEFAULT_REGION_COMPONENT_IN_URL}.carto.com/user/${DEFAULT_USER_COMPONENT_IN_URL}`\n};\n\nexport const MAP_TYPES = {\n QUERY: 'query',\n TABLE: 'table',\n TILESET: 'tileset'\n};\n\n// AVAILABLE FORMATS\nexport const FORMATS = {\n GEOJSON: 'geojson',\n NDJSON: 'ndjson',\n TILEJSON: 'tilejson',\n JSON: 'json'\n};\n\n/**\n * Simple encode parameter\n */\nexport function encodeParameter(name, value) {\n return `${name}=${encodeURIComponent(value)}`;\n}\n"],"file":"maps-api-common.js"}
@@ -1,161 +1,106 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.getDataV2 = getDataV2;
9
7
  exports.CONNECTIONS = void 0;
10
8
 
11
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
12
-
13
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
-
15
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
16
-
17
9
  var _config = require("../config");
18
10
 
19
11
  var _mapsApiCommon = require("./maps-api-common");
20
12
 
21
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
22
-
23
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
24
-
25
- var CONNECTIONS = {
13
+ const CONNECTIONS = {
26
14
  BIGQUERY: 'bigquery',
27
15
  CARTO: 'carto'
28
16
  };
29
17
  exports.CONNECTIONS = CONNECTIONS;
30
- var BUFFER_SIZE = 16;
31
- var TILE_EXTENT = 4096;
18
+ const BUFFER_SIZE = 16;
19
+ const TILE_EXTENT = 4096;
20
+
21
+ async function getDataV2({
22
+ type,
23
+ source,
24
+ credentials
25
+ }) {
26
+ const defaultCredentials = (0, _config.getDefaultCredentials)();
27
+ const apiVersion = credentials && credentials.apiVersion || defaultCredentials.apiVersion;
28
+ const localCreds = { ..._config.defaultClassicCredentials,
29
+ ...(defaultCredentials.apiVersion === apiVersion && defaultCredentials),
30
+ ...credentials
31
+ };
32
32
 
33
- function getDataV2(_x) {
34
- return _getDataV.apply(this, arguments);
35
- }
33
+ if (!localCreds.mapsUrl) {
34
+ localCreds.mapsUrl = _mapsApiCommon.DEFAULT_MAPS_URL_FORMAT[apiVersion];
35
+ }
36
36
 
37
- function _getDataV() {
38
- _getDataV = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(_ref) {
39
- var type, source, credentials, localCreds, apiVersion, url, connection, mapConfig, layergroup;
40
- return _regenerator.default.wrap(function _callee$(_context) {
41
- while (1) {
42
- switch (_context.prev = _context.next) {
43
- case 0:
44
- type = _ref.type, source = _ref.source, credentials = _ref.credentials;
45
- localCreds = _objectSpread(_objectSpread({}, (0, _config.getDefaultCredentials)()), credentials);
46
- apiVersion = localCreds.apiVersion;
47
- connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;
48
- _context.t0 = apiVersion;
49
- _context.next = _context.t0 === _mapsApiCommon.API_VERSIONS.V1 ? 7 : _context.t0 === _mapsApiCommon.API_VERSIONS.V2 ? 13 : 17;
50
- break;
51
-
52
- case 7:
53
- mapConfig = createMapConfig(source);
54
- url = buildURLMapsAPIv1({
55
- mapConfig: mapConfig,
56
- credentials: localCreds
57
- });
58
- _context.next = 11;
59
- return request({
60
- url: url,
61
- credentials: localCreds
62
- });
63
-
64
- case 11:
65
- layergroup = _context.sent;
66
- return _context.abrupt("return", layergroup.metadata.tilejson.vector);
67
-
68
- case 13:
69
- url = buildURLMapsAPIv2({
70
- connection: connection,
71
- type: type,
72
- source: source,
73
- credentials: localCreds
74
- });
75
- _context.next = 16;
76
- return request({
77
- url: url,
78
- credentials: localCreds
79
- });
80
-
81
- case 16:
82
- return _context.abrupt("return", _context.sent);
83
-
84
- case 17:
85
- throw new Error("Invalid maps API version. It shoud be ".concat(_mapsApiCommon.API_VERSIONS.V1, " or ").concat(_mapsApiCommon.API_VERSIONS.V2));
86
-
87
- case 18:
88
- case "end":
89
- return _context.stop();
90
- }
91
- }
92
- }, _callee);
93
- }));
94
- return _getDataV.apply(this, arguments);
95
- }
37
+ let url;
38
+ const connection = type === 'tileset' ? CONNECTIONS.BIGQUERY : CONNECTIONS.CARTO;
39
+
40
+ switch (apiVersion) {
41
+ case _mapsApiCommon.API_VERSIONS.V1:
42
+ const mapConfig = createMapConfig(source);
43
+ url = buildURLMapsAPIv1({
44
+ mapConfig,
45
+ credentials: localCreds
46
+ });
47
+ const layergroup = await request({
48
+ url,
49
+ credentials: localCreds
50
+ });
51
+ return layergroup.metadata.tilejson.vector;
52
+
53
+ case _mapsApiCommon.API_VERSIONS.V2:
54
+ url = buildURLMapsAPIv2({
55
+ connection,
56
+ type,
57
+ source,
58
+ credentials: localCreds
59
+ });
60
+ return await request({
61
+ url,
62
+ credentials: localCreds
63
+ });
96
64
 
97
- function request(_x2) {
98
- return _request.apply(this, arguments);
65
+ default:
66
+ throw new Error("Invalid maps API version. It shoud be ".concat(_mapsApiCommon.API_VERSIONS.V1, " or ").concat(_mapsApiCommon.API_VERSIONS.V2));
67
+ }
99
68
  }
100
69
 
101
- function _request() {
102
- _request = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(_ref2) {
103
- var url, credentials, response, json;
104
- return _regenerator.default.wrap(function _callee2$(_context2) {
105
- while (1) {
106
- switch (_context2.prev = _context2.next) {
107
- case 0:
108
- url = _ref2.url, credentials = _ref2.credentials;
109
- _context2.prev = 1;
110
- _context2.next = 4;
111
- return fetch(url, {
112
- headers: {
113
- Accept: 'application/json'
114
- }
115
- });
116
-
117
- case 4:
118
- response = _context2.sent;
119
- _context2.next = 10;
120
- break;
121
-
122
- case 7:
123
- _context2.prev = 7;
124
- _context2.t0 = _context2["catch"](1);
125
- throw new Error("Failed to connect to Maps API: ".concat(_context2.t0));
126
-
127
- case 10:
128
- _context2.next = 12;
129
- return response.json();
130
-
131
- case 12:
132
- json = _context2.sent;
133
-
134
- if (!response.ok) {
135
- dealWithError({
136
- response: response,
137
- json: json,
138
- credentials: credentials
139
- });
140
- }
141
-
142
- return _context2.abrupt("return", json);
143
-
144
- case 15:
145
- case "end":
146
- return _context2.stop();
147
- }
70
+ async function request({
71
+ url,
72
+ credentials
73
+ }) {
74
+ let response;
75
+
76
+ try {
77
+ response = await fetch(url, {
78
+ headers: {
79
+ Accept: 'application/json'
148
80
  }
149
- }, _callee2, null, [[1, 7]]);
150
- }));
151
- return _request.apply(this, arguments);
152
- }
81
+ });
82
+ } catch (error) {
83
+ throw new Error("Failed to connect to Maps API: ".concat(error));
84
+ }
85
+
86
+ const json = await response.json();
153
87
 
154
- function dealWithError(_ref3) {
155
- var response = _ref3.response,
156
- json = _ref3.json,
157
- credentials = _ref3.credentials;
88
+ if (!response.ok) {
89
+ dealWithError({
90
+ response,
91
+ json,
92
+ credentials
93
+ });
94
+ }
95
+
96
+ return json;
97
+ }
158
98
 
99
+ function dealWithError({
100
+ response,
101
+ json,
102
+ credentials
103
+ }) {
159
104
  switch (response.status) {
160
105
  case 401:
161
106
  throw new Error("Unauthorized access to Maps API: invalid combination of user ('".concat(credentials.username, "') and apiKey ('").concat(credentials.apiKey, "')"));
@@ -164,33 +109,35 @@ function dealWithError(_ref3) {
164
109
  throw new Error("Unauthorized access to dataset: the provided apiKey('".concat(credentials.apiKey, "') doesn't provide access to the requested data"));
165
110
 
166
111
  default:
167
- var e = credentials.apiVersion === _mapsApiCommon.API_VERSIONS.V1 ? JSON.stringify(json.errors) : json.error;
112
+ const e = credentials.apiVersion === _mapsApiCommon.API_VERSIONS.V1 ? JSON.stringify(json.errors) : json.error;
168
113
  throw new Error(e);
169
114
  }
170
115
  }
171
116
 
172
117
  function initURLParameters(credentials) {
173
- var encodedApiKey = (0, _mapsApiCommon.encodeParameter)('api_key', credentials.apiKey);
174
- var encodedClient = (0, _mapsApiCommon.encodeParameter)('client', "deck-gl-carto");
118
+ const encodedApiKey = (0, _mapsApiCommon.encodeParameter)('api_key', credentials.apiKey);
119
+ const encodedClient = (0, _mapsApiCommon.encodeParameter)('client', "deck-gl-carto");
175
120
  return [encodedApiKey, encodedClient];
176
121
  }
177
122
 
178
- function buildURLMapsAPIv1(_ref4) {
179
- var mapConfig = _ref4.mapConfig,
180
- credentials = _ref4.credentials;
181
- var parameters = initURLParameters(credentials);
182
- var cfg = JSON.stringify(mapConfig);
123
+ function buildURLMapsAPIv1({
124
+ mapConfig,
125
+ credentials
126
+ }) {
127
+ const parameters = initURLParameters(credentials);
128
+ const cfg = JSON.stringify(mapConfig);
183
129
  return "".concat(mapsUrl(credentials), "?").concat(parameters.join('&'), "&").concat((0, _mapsApiCommon.encodeParameter)('config', cfg));
184
130
  }
185
131
 
186
- function buildURLMapsAPIv2(_ref5) {
187
- var connection = _ref5.connection,
188
- type = _ref5.type,
189
- source = _ref5.source,
190
- credentials = _ref5.credentials;
191
- var parameters = initURLParameters(credentials);
192
- var mapsApiType = type === _mapsApiCommon.MAP_TYPES.QUERY ? 'sql' : type;
193
- var url = "".concat(mapsUrl(credentials), "/").concat(connection, "/").concat(mapsApiType, "?");
132
+ function buildURLMapsAPIv2({
133
+ connection,
134
+ type,
135
+ source,
136
+ credentials
137
+ }) {
138
+ const parameters = initURLParameters(credentials);
139
+ const mapsApiType = type === _mapsApiCommon.MAP_TYPES.QUERY ? 'sql' : type;
140
+ let url = "".concat(mapsUrl(credentials), "/").concat(connection, "/").concat(mapsApiType, "?");
194
141
  url += "".concat((0, _mapsApiCommon.encodeParameter)('source', source), "&format=tilejson&").concat(parameters.join('&'));
195
142
  return url;
196
143
  }
@@ -208,7 +155,7 @@ function createMapConfig(sql) {
208
155
  layers: [{
209
156
  type: 'mapnik',
210
157
  options: {
211
- sql: sql,
158
+ sql,
212
159
  vector_extent: TILE_EXTENT
213
160
  }
214
161
  }]