@carto/api-client 0.5.30-alpha.b195e7f.118 → 0.5.30
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 +2 -0
- package/build/api-client.cjs +113 -20
- package/build/api-client.cjs.map +1 -1
- package/build/api-client.d.cts +82 -19
- package/build/api-client.d.ts +82 -19
- package/build/api-client.js +108 -20
- package/build/api-client.js.map +1 -1
- package/build/worker-compat.js +2 -1
- package/build/worker-compat.js.map +1 -1
- package/build/worker.js +2 -1
- package/build/worker.js.map +1 -1
- package/package.json +1 -1
- package/src/api/auth.ts +92 -0
- package/src/api/index.ts +7 -0
- package/src/api/query.ts +3 -1
- package/src/api/request-with-parameters.ts +32 -5
- package/src/fetch-map/parse-map.ts +7 -1
- package/src/index.ts +6 -0
- package/src/models/common.ts +12 -2
- package/src/models/model.ts +8 -4
- package/src/sources/base-source.ts +26 -3
- package/src/sources/types.ts +9 -5
- package/src/spatial-index.ts +41 -0
- package/src/types.ts +12 -13
- package/src/widget-sources/widget-remote-source.ts +4 -1
package/build/api-client.js
CHANGED
|
@@ -5560,7 +5560,8 @@ var SchemaFieldType = /* @__PURE__ */ ((SchemaFieldType2) => {
|
|
|
5560
5560
|
return SchemaFieldType2;
|
|
5561
5561
|
})(SchemaFieldType || {});
|
|
5562
5562
|
function isSpatialIndexFilter(spatialFilter) {
|
|
5563
|
-
|
|
5563
|
+
const filter = spatialFilter;
|
|
5564
|
+
return Array.isArray(filter?.indexes) && ["h3", "h3int", "quadbin"].includes(filter?.type);
|
|
5564
5565
|
}
|
|
5565
5566
|
|
|
5566
5567
|
// src/utils.ts
|
|
@@ -5740,6 +5741,41 @@ function getFilterValue(filtersWithoutTimeType, timeColumn, timeFilter, filterSi
|
|
|
5740
5741
|
};
|
|
5741
5742
|
}
|
|
5742
5743
|
|
|
5744
|
+
// src/api/auth.ts
|
|
5745
|
+
function buildAuthHeaders(options) {
|
|
5746
|
+
if (options.authMode === "session") {
|
|
5747
|
+
if (options.accessToken) {
|
|
5748
|
+
throw new Error(
|
|
5749
|
+
`accessToken must not be provided with authMode: 'session' \u2014 authentication is delegated to the server behind apiBaseUrl`
|
|
5750
|
+
);
|
|
5751
|
+
}
|
|
5752
|
+
return {};
|
|
5753
|
+
}
|
|
5754
|
+
if (!options.accessToken) {
|
|
5755
|
+
throw new Error(
|
|
5756
|
+
`accessToken is required (or pass authMode: 'session' to authenticate via a same-origin session instead)`
|
|
5757
|
+
);
|
|
5758
|
+
}
|
|
5759
|
+
return { Authorization: `Bearer ${options.accessToken}` };
|
|
5760
|
+
}
|
|
5761
|
+
function getAuthCredentials(authMode) {
|
|
5762
|
+
return authMode === "session" ? "same-origin" : void 0;
|
|
5763
|
+
}
|
|
5764
|
+
function rewriteUrlForSessionMode(url, apiBaseUrl) {
|
|
5765
|
+
let origin;
|
|
5766
|
+
try {
|
|
5767
|
+
const parsed = new URL(url);
|
|
5768
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
5769
|
+
return url;
|
|
5770
|
+
}
|
|
5771
|
+
origin = parsed.origin;
|
|
5772
|
+
} catch {
|
|
5773
|
+
return url;
|
|
5774
|
+
}
|
|
5775
|
+
const base = apiBaseUrl.replace(/\/+$/, "");
|
|
5776
|
+
return base + url.slice(origin.length);
|
|
5777
|
+
}
|
|
5778
|
+
|
|
5743
5779
|
// src/api/carto-api-error.ts
|
|
5744
5780
|
var CartoAPIError = class extends Error {
|
|
5745
5781
|
constructor(error, errorContext, response, responseJson) {
|
|
@@ -5846,7 +5882,8 @@ async function requestWithParameters({
|
|
|
5846
5882
|
errorContext,
|
|
5847
5883
|
maxLengthURL = DEFAULT_MAX_LENGTH_URL,
|
|
5848
5884
|
localCache,
|
|
5849
|
-
signal
|
|
5885
|
+
signal,
|
|
5886
|
+
credentials
|
|
5850
5887
|
}) {
|
|
5851
5888
|
parameters = {
|
|
5852
5889
|
v: V3_MINOR_VERSION,
|
|
@@ -5870,8 +5907,9 @@ async function requestWithParameters({
|
|
|
5870
5907
|
method: "POST",
|
|
5871
5908
|
body: JSON.stringify(parameters),
|
|
5872
5909
|
headers,
|
|
5873
|
-
signal
|
|
5874
|
-
|
|
5910
|
+
signal,
|
|
5911
|
+
...credentials && { credentials }
|
|
5912
|
+
}) : fetch(url, { headers, signal, ...credentials && { credentials } });
|
|
5875
5913
|
let response;
|
|
5876
5914
|
let responseJson;
|
|
5877
5915
|
const jsonPromise = fetchPromise.then((_response) => {
|
|
@@ -5917,8 +5955,19 @@ function createCacheKey(baseUrl, parameters, headers) {
|
|
|
5917
5955
|
headers: headerEntries
|
|
5918
5956
|
});
|
|
5919
5957
|
}
|
|
5958
|
+
var RELATIVE_ORIGIN = "https://relative.invalid";
|
|
5959
|
+
function parseBaseUrl(baseUrlString) {
|
|
5960
|
+
const isRelative = baseUrlString.startsWith("/") && !baseUrlString.startsWith("//");
|
|
5961
|
+
return {
|
|
5962
|
+
url: new URL(baseUrlString, isRelative ? RELATIVE_ORIGIN : void 0),
|
|
5963
|
+
isRelative
|
|
5964
|
+
};
|
|
5965
|
+
}
|
|
5966
|
+
function serializeBaseUrl(url, isRelative) {
|
|
5967
|
+
return isRelative ? `${url.pathname}${url.search}` : url.toString();
|
|
5968
|
+
}
|
|
5920
5969
|
function createURLWithParameters(baseUrlString, parameters) {
|
|
5921
|
-
const baseUrl =
|
|
5970
|
+
const { url: baseUrl, isRelative } = parseBaseUrl(baseUrlString);
|
|
5922
5971
|
for (const [key, value] of Object.entries(parameters)) {
|
|
5923
5972
|
if (isPureObject(value) || Array.isArray(value)) {
|
|
5924
5973
|
baseUrl.searchParams.set(key, JSON.stringify(value));
|
|
@@ -5931,16 +5980,16 @@ function createURLWithParameters(baseUrlString, parameters) {
|
|
|
5931
5980
|
}
|
|
5932
5981
|
}
|
|
5933
5982
|
}
|
|
5934
|
-
return baseUrl
|
|
5983
|
+
return serializeBaseUrl(baseUrl, isRelative);
|
|
5935
5984
|
}
|
|
5936
5985
|
function excludeURLParameters(baseUrlString, parameters) {
|
|
5937
|
-
const baseUrl =
|
|
5986
|
+
const { url: baseUrl, isRelative } = parseBaseUrl(baseUrlString);
|
|
5938
5987
|
for (const param of parameters) {
|
|
5939
5988
|
if (baseUrl.searchParams.has(param)) {
|
|
5940
5989
|
baseUrl.searchParams.delete(param);
|
|
5941
5990
|
}
|
|
5942
5991
|
}
|
|
5943
|
-
return baseUrl
|
|
5992
|
+
return serializeBaseUrl(baseUrl, isRelative);
|
|
5944
5993
|
}
|
|
5945
5994
|
function clearDefaultRequestCache() {
|
|
5946
5995
|
DEFAULT_REQUEST_CACHE.clear();
|
|
@@ -5968,10 +6017,12 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
5968
6017
|
}
|
|
5969
6018
|
const baseUrl = buildSourceUrl(mergedOptions);
|
|
5970
6019
|
const { clientId, maxLengthURL, localCache } = mergedOptions;
|
|
6020
|
+
const sessionMode = options.authMode === "session";
|
|
5971
6021
|
const headers = {
|
|
5972
|
-
|
|
6022
|
+
...buildAuthHeaders(options),
|
|
5973
6023
|
...options.headers
|
|
5974
6024
|
};
|
|
6025
|
+
const credentials = getAuthCredentials(options.authMode);
|
|
5975
6026
|
const parameters = { client: clientId, ...options.tags, ...urlParameters };
|
|
5976
6027
|
const errorContext = {
|
|
5977
6028
|
requestType: "Map instantiation",
|
|
@@ -5985,15 +6036,19 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
5985
6036
|
headers,
|
|
5986
6037
|
errorContext,
|
|
5987
6038
|
maxLengthURL,
|
|
5988
|
-
localCache
|
|
6039
|
+
localCache,
|
|
6040
|
+
credentials
|
|
5989
6041
|
});
|
|
5990
|
-
|
|
6042
|
+
let dataUrl = tilejson.url[0];
|
|
5991
6043
|
if (cache) {
|
|
5992
6044
|
cache.value = parseInt(
|
|
5993
6045
|
new URL(dataUrl).searchParams.get("cache") || "",
|
|
5994
6046
|
10
|
|
5995
6047
|
);
|
|
5996
6048
|
}
|
|
6049
|
+
if (sessionMode) {
|
|
6050
|
+
dataUrl = rewriteUrlForSessionMode(dataUrl, mergedOptions.apiBaseUrl);
|
|
6051
|
+
}
|
|
5997
6052
|
errorContext.requestType = "Map data";
|
|
5998
6053
|
const json = await requestWithParameters({
|
|
5999
6054
|
baseUrl: dataUrl,
|
|
@@ -6001,9 +6056,14 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
6001
6056
|
headers,
|
|
6002
6057
|
errorContext,
|
|
6003
6058
|
maxLengthURL,
|
|
6004
|
-
localCache
|
|
6059
|
+
localCache,
|
|
6060
|
+
credentials
|
|
6005
6061
|
});
|
|
6006
|
-
if (
|
|
6062
|
+
if (sessionMode) {
|
|
6063
|
+
json.tiles = json.tiles?.map(
|
|
6064
|
+
(template) => rewriteUrlForSessionMode(template, mergedOptions.apiBaseUrl)
|
|
6065
|
+
);
|
|
6066
|
+
} else if (accessToken) {
|
|
6007
6067
|
json.accessToken = accessToken;
|
|
6008
6068
|
}
|
|
6009
6069
|
if (schema) {
|
|
@@ -6108,6 +6168,7 @@ function dealWithApiError({
|
|
|
6108
6168
|
async function makeCall({
|
|
6109
6169
|
url,
|
|
6110
6170
|
accessToken,
|
|
6171
|
+
authMode,
|
|
6111
6172
|
opts
|
|
6112
6173
|
}) {
|
|
6113
6174
|
let response;
|
|
@@ -6116,10 +6177,13 @@ async function makeCall({
|
|
|
6116
6177
|
try {
|
|
6117
6178
|
response = await fetch(url.toString(), {
|
|
6118
6179
|
headers: {
|
|
6119
|
-
|
|
6180
|
+
...buildAuthHeaders({ accessToken, authMode }),
|
|
6120
6181
|
...isPost && { "Content-Type": "application/json" },
|
|
6121
6182
|
...opts.headers
|
|
6122
6183
|
},
|
|
6184
|
+
...getAuthCredentials(authMode) && {
|
|
6185
|
+
credentials: getAuthCredentials(authMode)
|
|
6186
|
+
},
|
|
6123
6187
|
...isPost && {
|
|
6124
6188
|
method: opts?.method,
|
|
6125
6189
|
body: opts?.body
|
|
@@ -6163,9 +6227,8 @@ function executeModel(props) {
|
|
|
6163
6227
|
)}`
|
|
6164
6228
|
);
|
|
6165
6229
|
const { model, source, params, opts } = props;
|
|
6166
|
-
const { type, apiVersion, apiBaseUrl,
|
|
6230
|
+
const { type, apiVersion, apiBaseUrl, connectionName, clientId } = source;
|
|
6167
6231
|
assert2(apiBaseUrl, "executeModel: missing apiBaseUrl");
|
|
6168
|
-
assert2(accessToken, "executeModel: missing accessToken");
|
|
6169
6232
|
assert2(apiVersion === V3, "executeModel: SQL Model API requires CARTO 3+");
|
|
6170
6233
|
assert2(type !== "tileset", "executeModel: Tilesets not supported");
|
|
6171
6234
|
let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
|
|
@@ -6204,6 +6267,7 @@ function executeModel(props) {
|
|
|
6204
6267
|
return makeCall({
|
|
6205
6268
|
url,
|
|
6206
6269
|
accessToken: source.accessToken,
|
|
6270
|
+
authMode: source.authMode,
|
|
6207
6271
|
opts: {
|
|
6208
6272
|
...opts,
|
|
6209
6273
|
method: isGet ? "GET" : "POST",
|
|
@@ -6328,6 +6392,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6328
6392
|
apiBaseUrl: props.apiBaseUrl,
|
|
6329
6393
|
clientId: props.clientId,
|
|
6330
6394
|
accessToken: props.accessToken,
|
|
6395
|
+
authMode: props.authMode,
|
|
6331
6396
|
connectionName: props.connectionName,
|
|
6332
6397
|
filters: getApplicableFilters(filterOwner, filters || props.filters),
|
|
6333
6398
|
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
@@ -6657,7 +6722,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6657
6722
|
url = `${apiBaseUrl}/${apiVersion}/stats/${connectionName}/${data}/${spatialDataColumn}`;
|
|
6658
6723
|
}
|
|
6659
6724
|
const headers = {
|
|
6660
|
-
|
|
6725
|
+
...buildAuthHeaders(this.props),
|
|
6661
6726
|
...this.props.headers
|
|
6662
6727
|
};
|
|
6663
6728
|
const errorContext = {
|
|
@@ -6670,7 +6735,8 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6670
6735
|
headers,
|
|
6671
6736
|
signal,
|
|
6672
6737
|
errorContext,
|
|
6673
|
-
parameters
|
|
6738
|
+
parameters,
|
|
6739
|
+
credentials: getAuthCredentials(this.props.authMode)
|
|
6674
6740
|
}).then(({ extent: { xmin, ymin, xmax, ymax } }) => ({
|
|
6675
6741
|
bbox: [xmin, ymin, xmax, ymax]
|
|
6676
6742
|
}));
|
|
@@ -8413,7 +8479,7 @@ var query = async function(options) {
|
|
|
8413
8479
|
}
|
|
8414
8480
|
const baseUrl = buildQueryUrl({ apiBaseUrl, connectionName });
|
|
8415
8481
|
const headers = {
|
|
8416
|
-
|
|
8482
|
+
...buildAuthHeaders(options),
|
|
8417
8483
|
...options.headers
|
|
8418
8484
|
};
|
|
8419
8485
|
const parameters = {
|
|
@@ -8435,7 +8501,8 @@ var query = async function(options) {
|
|
|
8435
8501
|
errorContext,
|
|
8436
8502
|
maxLengthURL,
|
|
8437
8503
|
localCache,
|
|
8438
|
-
signal: options.signal
|
|
8504
|
+
signal: options.signal,
|
|
8505
|
+
credentials: getAuthCredentials(options.authMode)
|
|
8439
8506
|
});
|
|
8440
8507
|
};
|
|
8441
8508
|
|
|
@@ -10765,6 +10832,9 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
|
|
|
10765
10832
|
};
|
|
10766
10833
|
}
|
|
10767
10834
|
function createLoadOptions(accessToken) {
|
|
10835
|
+
if (!accessToken) {
|
|
10836
|
+
return { loadOptions: { fetch: { credentials: "same-origin" } } };
|
|
10837
|
+
}
|
|
10768
10838
|
return {
|
|
10769
10839
|
loadOptions: { fetch: { headers: { Authorization: `Bearer ${accessToken}` } } }
|
|
10770
10840
|
};
|
|
@@ -11354,6 +11424,20 @@ function _getHexagonResolution(viewport, tileSize) {
|
|
|
11354
11424
|
Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
|
|
11355
11425
|
);
|
|
11356
11426
|
}
|
|
11427
|
+
var DYNAMIC_TILES_POINTS_AGGREGATION_LEVEL = 8;
|
|
11428
|
+
var AGG_LEVEL_CORRECTION_BY_TILE_RESOLUTION = {
|
|
11429
|
+
0.25: -1,
|
|
11430
|
+
0.5: 0,
|
|
11431
|
+
1: 1,
|
|
11432
|
+
2: 2,
|
|
11433
|
+
4: 3
|
|
11434
|
+
};
|
|
11435
|
+
function getPointsAggregationLevel({
|
|
11436
|
+
tileResolution,
|
|
11437
|
+
zoomLevel
|
|
11438
|
+
}) {
|
|
11439
|
+
return zoomLevel + DYNAMIC_TILES_POINTS_AGGREGATION_LEVEL + AGG_LEVEL_CORRECTION_BY_TILE_RESOLUTION[tileResolution];
|
|
11440
|
+
}
|
|
11357
11441
|
|
|
11358
11442
|
// src/utils/CellSet.ts
|
|
11359
11443
|
var EMPTY_U32 = 2 ** 32 - 1;
|
|
@@ -11449,6 +11533,7 @@ export {
|
|
|
11449
11533
|
fillInTileStats as _fillInTileStats,
|
|
11450
11534
|
_getHexagonResolution,
|
|
11451
11535
|
getLog10ScaleSteps as _getLog10ScaleSteps,
|
|
11536
|
+
getPointsAggregationLevel as _getPointsAggregationLevel,
|
|
11452
11537
|
getRasterTileLayerStyleProps as _getRasterTileLayerStyleProps,
|
|
11453
11538
|
validateVecExprSyntax as _validateVecExprSyntax,
|
|
11454
11539
|
addFilter,
|
|
@@ -11458,6 +11543,7 @@ export {
|
|
|
11458
11543
|
applySorting,
|
|
11459
11544
|
boundaryQuerySource,
|
|
11460
11545
|
boundaryTableSource,
|
|
11546
|
+
buildAuthHeaders,
|
|
11461
11547
|
buildBinaryFeatureFilter,
|
|
11462
11548
|
buildPublicMapUrl,
|
|
11463
11549
|
buildStatsUrl,
|
|
@@ -11476,6 +11562,7 @@ export {
|
|
|
11476
11562
|
filterFunctions,
|
|
11477
11563
|
geojsonFeatures,
|
|
11478
11564
|
getApplicableFilters,
|
|
11565
|
+
getAuthCredentials,
|
|
11479
11566
|
getClient,
|
|
11480
11567
|
getColorAccessor,
|
|
11481
11568
|
getColumnNameFromGeoColumn,
|
|
@@ -11509,6 +11596,7 @@ export {
|
|
|
11509
11596
|
rasterSource,
|
|
11510
11597
|
removeFilter,
|
|
11511
11598
|
requestWithParameters,
|
|
11599
|
+
rewriteUrlForSessionMode,
|
|
11512
11600
|
scaleAggregationResLevel,
|
|
11513
11601
|
scatterPlot,
|
|
11514
11602
|
setClient,
|