@carto/api-client 0.5.30-alpha.b195e7f.118 → 0.5.30-alpha.bdcd62f.119
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 +1 -2
- 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/CHANGELOG.md
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
- feat(sources): expose `_getPointsAggregationLevel` for maps-api dynamic point-tile aggregation parity (#304)
|
|
7
6
|
- feat(widgetSources): support `featureIds` / `geometryType` request options to filter widget aggregations by a feature selection without relying on the synthetic `_carto_feature_id` column (#294)
|
|
8
7
|
- feat(widgetSources): support `SpatialIndexFilter` (H3/Quadbin cell selection) on `spatialFilter` (#296)
|
|
9
8
|
|
package/build/api-client.cjs
CHANGED
|
@@ -137,6 +137,7 @@ __export(src_exports, {
|
|
|
137
137
|
_fillInTileStats: () => fillInTileStats,
|
|
138
138
|
_getHexagonResolution: () => _getHexagonResolution,
|
|
139
139
|
_getLog10ScaleSteps: () => getLog10ScaleSteps,
|
|
140
|
+
_getPointsAggregationLevel: () => getPointsAggregationLevel,
|
|
140
141
|
_getRasterTileLayerStyleProps: () => getRasterTileLayerStyleProps,
|
|
141
142
|
_validateVecExprSyntax: () => validateVecExprSyntax,
|
|
142
143
|
addFilter: () => addFilter,
|
|
@@ -146,6 +147,7 @@ __export(src_exports, {
|
|
|
146
147
|
applySorting: () => applySorting,
|
|
147
148
|
boundaryQuerySource: () => boundaryQuerySource,
|
|
148
149
|
boundaryTableSource: () => boundaryTableSource,
|
|
150
|
+
buildAuthHeaders: () => buildAuthHeaders,
|
|
149
151
|
buildBinaryFeatureFilter: () => buildBinaryFeatureFilter,
|
|
150
152
|
buildPublicMapUrl: () => buildPublicMapUrl,
|
|
151
153
|
buildStatsUrl: () => buildStatsUrl,
|
|
@@ -164,6 +166,7 @@ __export(src_exports, {
|
|
|
164
166
|
filterFunctions: () => filterFunctions,
|
|
165
167
|
geojsonFeatures: () => geojsonFeatures,
|
|
166
168
|
getApplicableFilters: () => getApplicableFilters,
|
|
169
|
+
getAuthCredentials: () => getAuthCredentials,
|
|
167
170
|
getClient: () => getClient,
|
|
168
171
|
getColorAccessor: () => getColorAccessor,
|
|
169
172
|
getColumnNameFromGeoColumn: () => getColumnNameFromGeoColumn,
|
|
@@ -197,6 +200,7 @@ __export(src_exports, {
|
|
|
197
200
|
rasterSource: () => rasterSource,
|
|
198
201
|
removeFilter: () => removeFilter,
|
|
199
202
|
requestWithParameters: () => requestWithParameters,
|
|
203
|
+
rewriteUrlForSessionMode: () => rewriteUrlForSessionMode,
|
|
200
204
|
scaleAggregationResLevel: () => scaleAggregationResLevel,
|
|
201
205
|
scatterPlot: () => scatterPlot,
|
|
202
206
|
setClient: () => setClient,
|
|
@@ -5803,7 +5807,8 @@ var SchemaFieldType = /* @__PURE__ */ ((SchemaFieldType2) => {
|
|
|
5803
5807
|
return SchemaFieldType2;
|
|
5804
5808
|
})(SchemaFieldType || {});
|
|
5805
5809
|
function isSpatialIndexFilter(spatialFilter) {
|
|
5806
|
-
|
|
5810
|
+
const filter = spatialFilter;
|
|
5811
|
+
return Array.isArray(filter?.indexes) && ["h3", "h3int", "quadbin"].includes(filter?.type);
|
|
5807
5812
|
}
|
|
5808
5813
|
|
|
5809
5814
|
// src/utils.ts
|
|
@@ -5992,6 +5997,42 @@ init_cjs_shims();
|
|
|
5992
5997
|
// src/api/index.ts
|
|
5993
5998
|
init_cjs_shims();
|
|
5994
5999
|
|
|
6000
|
+
// src/api/auth.ts
|
|
6001
|
+
init_cjs_shims();
|
|
6002
|
+
function buildAuthHeaders(options) {
|
|
6003
|
+
if (options.authMode === "session") {
|
|
6004
|
+
if (options.accessToken) {
|
|
6005
|
+
throw new Error(
|
|
6006
|
+
`accessToken must not be provided with authMode: 'session' \u2014 authentication is delegated to the server behind apiBaseUrl`
|
|
6007
|
+
);
|
|
6008
|
+
}
|
|
6009
|
+
return {};
|
|
6010
|
+
}
|
|
6011
|
+
if (!options.accessToken) {
|
|
6012
|
+
throw new Error(
|
|
6013
|
+
`accessToken is required (or pass authMode: 'session' to authenticate via a same-origin session instead)`
|
|
6014
|
+
);
|
|
6015
|
+
}
|
|
6016
|
+
return { Authorization: `Bearer ${options.accessToken}` };
|
|
6017
|
+
}
|
|
6018
|
+
function getAuthCredentials(authMode) {
|
|
6019
|
+
return authMode === "session" ? "same-origin" : void 0;
|
|
6020
|
+
}
|
|
6021
|
+
function rewriteUrlForSessionMode(url, apiBaseUrl) {
|
|
6022
|
+
let origin;
|
|
6023
|
+
try {
|
|
6024
|
+
const parsed = new URL(url);
|
|
6025
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
6026
|
+
return url;
|
|
6027
|
+
}
|
|
6028
|
+
origin = parsed.origin;
|
|
6029
|
+
} catch {
|
|
6030
|
+
return url;
|
|
6031
|
+
}
|
|
6032
|
+
const base = apiBaseUrl.replace(/\/+$/, "");
|
|
6033
|
+
return base + url.slice(origin.length);
|
|
6034
|
+
}
|
|
6035
|
+
|
|
5995
6036
|
// src/api/carto-api-error.ts
|
|
5996
6037
|
init_cjs_shims();
|
|
5997
6038
|
var CartoAPIError = class extends Error {
|
|
@@ -6113,7 +6154,8 @@ async function requestWithParameters({
|
|
|
6113
6154
|
errorContext,
|
|
6114
6155
|
maxLengthURL = DEFAULT_MAX_LENGTH_URL,
|
|
6115
6156
|
localCache,
|
|
6116
|
-
signal
|
|
6157
|
+
signal,
|
|
6158
|
+
credentials
|
|
6117
6159
|
}) {
|
|
6118
6160
|
parameters = {
|
|
6119
6161
|
v: V3_MINOR_VERSION,
|
|
@@ -6137,8 +6179,9 @@ async function requestWithParameters({
|
|
|
6137
6179
|
method: "POST",
|
|
6138
6180
|
body: JSON.stringify(parameters),
|
|
6139
6181
|
headers,
|
|
6140
|
-
signal
|
|
6141
|
-
|
|
6182
|
+
signal,
|
|
6183
|
+
...credentials && { credentials }
|
|
6184
|
+
}) : fetch(url, { headers, signal, ...credentials && { credentials } });
|
|
6142
6185
|
let response;
|
|
6143
6186
|
let responseJson;
|
|
6144
6187
|
const jsonPromise = fetchPromise.then((_response) => {
|
|
@@ -6184,8 +6227,19 @@ function createCacheKey(baseUrl, parameters, headers) {
|
|
|
6184
6227
|
headers: headerEntries
|
|
6185
6228
|
});
|
|
6186
6229
|
}
|
|
6230
|
+
var RELATIVE_ORIGIN = "https://relative.invalid";
|
|
6231
|
+
function parseBaseUrl(baseUrlString) {
|
|
6232
|
+
const isRelative = baseUrlString.startsWith("/") && !baseUrlString.startsWith("//");
|
|
6233
|
+
return {
|
|
6234
|
+
url: new URL(baseUrlString, isRelative ? RELATIVE_ORIGIN : void 0),
|
|
6235
|
+
isRelative
|
|
6236
|
+
};
|
|
6237
|
+
}
|
|
6238
|
+
function serializeBaseUrl(url, isRelative) {
|
|
6239
|
+
return isRelative ? `${url.pathname}${url.search}` : url.toString();
|
|
6240
|
+
}
|
|
6187
6241
|
function createURLWithParameters(baseUrlString, parameters) {
|
|
6188
|
-
const baseUrl =
|
|
6242
|
+
const { url: baseUrl, isRelative } = parseBaseUrl(baseUrlString);
|
|
6189
6243
|
for (const [key, value] of Object.entries(parameters)) {
|
|
6190
6244
|
if (isPureObject(value) || Array.isArray(value)) {
|
|
6191
6245
|
baseUrl.searchParams.set(key, JSON.stringify(value));
|
|
@@ -6198,16 +6252,16 @@ function createURLWithParameters(baseUrlString, parameters) {
|
|
|
6198
6252
|
}
|
|
6199
6253
|
}
|
|
6200
6254
|
}
|
|
6201
|
-
return baseUrl
|
|
6255
|
+
return serializeBaseUrl(baseUrl, isRelative);
|
|
6202
6256
|
}
|
|
6203
6257
|
function excludeURLParameters(baseUrlString, parameters) {
|
|
6204
|
-
const baseUrl =
|
|
6258
|
+
const { url: baseUrl, isRelative } = parseBaseUrl(baseUrlString);
|
|
6205
6259
|
for (const param of parameters) {
|
|
6206
6260
|
if (baseUrl.searchParams.has(param)) {
|
|
6207
6261
|
baseUrl.searchParams.delete(param);
|
|
6208
6262
|
}
|
|
6209
6263
|
}
|
|
6210
|
-
return baseUrl
|
|
6264
|
+
return serializeBaseUrl(baseUrl, isRelative);
|
|
6211
6265
|
}
|
|
6212
6266
|
function clearDefaultRequestCache() {
|
|
6213
6267
|
DEFAULT_REQUEST_CACHE.clear();
|
|
@@ -6235,10 +6289,12 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
6235
6289
|
}
|
|
6236
6290
|
const baseUrl = buildSourceUrl(mergedOptions);
|
|
6237
6291
|
const { clientId, maxLengthURL, localCache } = mergedOptions;
|
|
6292
|
+
const sessionMode = options.authMode === "session";
|
|
6238
6293
|
const headers = {
|
|
6239
|
-
|
|
6294
|
+
...buildAuthHeaders(options),
|
|
6240
6295
|
...options.headers
|
|
6241
6296
|
};
|
|
6297
|
+
const credentials = getAuthCredentials(options.authMode);
|
|
6242
6298
|
const parameters = { client: clientId, ...options.tags, ...urlParameters };
|
|
6243
6299
|
const errorContext = {
|
|
6244
6300
|
requestType: "Map instantiation",
|
|
@@ -6252,15 +6308,19 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
6252
6308
|
headers,
|
|
6253
6309
|
errorContext,
|
|
6254
6310
|
maxLengthURL,
|
|
6255
|
-
localCache
|
|
6311
|
+
localCache,
|
|
6312
|
+
credentials
|
|
6256
6313
|
});
|
|
6257
|
-
|
|
6314
|
+
let dataUrl = tilejson.url[0];
|
|
6258
6315
|
if (cache) {
|
|
6259
6316
|
cache.value = parseInt(
|
|
6260
6317
|
new URL(dataUrl).searchParams.get("cache") || "",
|
|
6261
6318
|
10
|
|
6262
6319
|
);
|
|
6263
6320
|
}
|
|
6321
|
+
if (sessionMode) {
|
|
6322
|
+
dataUrl = rewriteUrlForSessionMode(dataUrl, mergedOptions.apiBaseUrl);
|
|
6323
|
+
}
|
|
6264
6324
|
errorContext.requestType = "Map data";
|
|
6265
6325
|
const json = await requestWithParameters({
|
|
6266
6326
|
baseUrl: dataUrl,
|
|
@@ -6268,9 +6328,14 @@ async function baseSource(endpoint, options, urlParameters) {
|
|
|
6268
6328
|
headers,
|
|
6269
6329
|
errorContext,
|
|
6270
6330
|
maxLengthURL,
|
|
6271
|
-
localCache
|
|
6331
|
+
localCache,
|
|
6332
|
+
credentials
|
|
6272
6333
|
});
|
|
6273
|
-
if (
|
|
6334
|
+
if (sessionMode) {
|
|
6335
|
+
json.tiles = json.tiles?.map(
|
|
6336
|
+
(template) => rewriteUrlForSessionMode(template, mergedOptions.apiBaseUrl)
|
|
6337
|
+
);
|
|
6338
|
+
} else if (accessToken) {
|
|
6274
6339
|
json.accessToken = accessToken;
|
|
6275
6340
|
}
|
|
6276
6341
|
if (schema) {
|
|
@@ -6393,6 +6458,7 @@ function dealWithApiError({
|
|
|
6393
6458
|
async function makeCall({
|
|
6394
6459
|
url,
|
|
6395
6460
|
accessToken,
|
|
6461
|
+
authMode,
|
|
6396
6462
|
opts
|
|
6397
6463
|
}) {
|
|
6398
6464
|
let response;
|
|
@@ -6401,10 +6467,13 @@ async function makeCall({
|
|
|
6401
6467
|
try {
|
|
6402
6468
|
response = await fetch(url.toString(), {
|
|
6403
6469
|
headers: {
|
|
6404
|
-
|
|
6470
|
+
...buildAuthHeaders({ accessToken, authMode }),
|
|
6405
6471
|
...isPost && { "Content-Type": "application/json" },
|
|
6406
6472
|
...opts.headers
|
|
6407
6473
|
},
|
|
6474
|
+
...getAuthCredentials(authMode) && {
|
|
6475
|
+
credentials: getAuthCredentials(authMode)
|
|
6476
|
+
},
|
|
6408
6477
|
...isPost && {
|
|
6409
6478
|
method: opts?.method,
|
|
6410
6479
|
body: opts?.body
|
|
@@ -6448,9 +6517,8 @@ function executeModel(props) {
|
|
|
6448
6517
|
)}`
|
|
6449
6518
|
);
|
|
6450
6519
|
const { model, source, params, opts } = props;
|
|
6451
|
-
const { type, apiVersion, apiBaseUrl,
|
|
6520
|
+
const { type, apiVersion, apiBaseUrl, connectionName, clientId } = source;
|
|
6452
6521
|
assert2(apiBaseUrl, "executeModel: missing apiBaseUrl");
|
|
6453
|
-
assert2(accessToken, "executeModel: missing accessToken");
|
|
6454
6522
|
assert2(apiVersion === V3, "executeModel: SQL Model API requires CARTO 3+");
|
|
6455
6523
|
assert2(type !== "tileset", "executeModel: Tilesets not supported");
|
|
6456
6524
|
let url = `${apiBaseUrl}/v3/sql/${connectionName}/model/${model}`;
|
|
@@ -6489,6 +6557,7 @@ function executeModel(props) {
|
|
|
6489
6557
|
return makeCall({
|
|
6490
6558
|
url,
|
|
6491
6559
|
accessToken: source.accessToken,
|
|
6560
|
+
authMode: source.authMode,
|
|
6492
6561
|
opts: {
|
|
6493
6562
|
...opts,
|
|
6494
6563
|
method: isGet ? "GET" : "POST",
|
|
@@ -6615,6 +6684,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6615
6684
|
apiBaseUrl: props.apiBaseUrl,
|
|
6616
6685
|
clientId: props.clientId,
|
|
6617
6686
|
accessToken: props.accessToken,
|
|
6687
|
+
authMode: props.authMode,
|
|
6618
6688
|
connectionName: props.connectionName,
|
|
6619
6689
|
filters: getApplicableFilters(filterOwner, filters || props.filters),
|
|
6620
6690
|
filtersLogicalOperator: props.filtersLogicalOperator,
|
|
@@ -6944,7 +7014,7 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6944
7014
|
url = `${apiBaseUrl}/${apiVersion}/stats/${connectionName}/${data}/${spatialDataColumn}`;
|
|
6945
7015
|
}
|
|
6946
7016
|
const headers = {
|
|
6947
|
-
|
|
7017
|
+
...buildAuthHeaders(this.props),
|
|
6948
7018
|
...this.props.headers
|
|
6949
7019
|
};
|
|
6950
7020
|
const errorContext = {
|
|
@@ -6957,7 +7027,8 @@ var WidgetRemoteSource = class extends WidgetSource {
|
|
|
6957
7027
|
headers,
|
|
6958
7028
|
signal,
|
|
6959
7029
|
errorContext,
|
|
6960
|
-
parameters
|
|
7030
|
+
parameters,
|
|
7031
|
+
credentials: getAuthCredentials(this.props.authMode)
|
|
6961
7032
|
}).then(({ extent: { xmin, ymin, xmax, ymax } }) => ({
|
|
6962
7033
|
bbox: [xmin, ymin, xmax, ymax]
|
|
6963
7034
|
}));
|
|
@@ -8739,7 +8810,7 @@ var query = async function(options) {
|
|
|
8739
8810
|
}
|
|
8740
8811
|
const baseUrl = buildQueryUrl({ apiBaseUrl, connectionName });
|
|
8741
8812
|
const headers = {
|
|
8742
|
-
|
|
8813
|
+
...buildAuthHeaders(options),
|
|
8743
8814
|
...options.headers
|
|
8744
8815
|
};
|
|
8745
8816
|
const parameters = {
|
|
@@ -8761,7 +8832,8 @@ var query = async function(options) {
|
|
|
8761
8832
|
errorContext,
|
|
8762
8833
|
maxLengthURL,
|
|
8763
8834
|
localCache,
|
|
8764
|
-
signal: options.signal
|
|
8835
|
+
signal: options.signal,
|
|
8836
|
+
credentials: getAuthCredentials(options.authMode)
|
|
8765
8837
|
});
|
|
8766
8838
|
};
|
|
8767
8839
|
|
|
@@ -11118,6 +11190,9 @@ function createChannelProps(id, layerType, config2, visualChannels, data, datase
|
|
|
11118
11190
|
};
|
|
11119
11191
|
}
|
|
11120
11192
|
function createLoadOptions(accessToken) {
|
|
11193
|
+
if (!accessToken) {
|
|
11194
|
+
return { loadOptions: { fetch: { credentials: "same-origin" } } };
|
|
11195
|
+
}
|
|
11121
11196
|
return {
|
|
11122
11197
|
loadOptions: { fetch: { headers: { Authorization: `Bearer ${accessToken}` } } }
|
|
11123
11198
|
};
|
|
@@ -11714,6 +11789,20 @@ function _getHexagonResolution(viewport, tileSize) {
|
|
|
11714
11789
|
Math.floor(hexagonScaleFactor + latitudeScaleFactor - BIAS)
|
|
11715
11790
|
);
|
|
11716
11791
|
}
|
|
11792
|
+
var DYNAMIC_TILES_POINTS_AGGREGATION_LEVEL = 8;
|
|
11793
|
+
var AGG_LEVEL_CORRECTION_BY_TILE_RESOLUTION = {
|
|
11794
|
+
0.25: -1,
|
|
11795
|
+
0.5: 0,
|
|
11796
|
+
1: 1,
|
|
11797
|
+
2: 2,
|
|
11798
|
+
4: 3
|
|
11799
|
+
};
|
|
11800
|
+
function getPointsAggregationLevel({
|
|
11801
|
+
tileResolution,
|
|
11802
|
+
zoomLevel
|
|
11803
|
+
}) {
|
|
11804
|
+
return zoomLevel + DYNAMIC_TILES_POINTS_AGGREGATION_LEVEL + AGG_LEVEL_CORRECTION_BY_TILE_RESOLUTION[tileResolution];
|
|
11805
|
+
}
|
|
11717
11806
|
|
|
11718
11807
|
// src/utils/CellSet.ts
|
|
11719
11808
|
init_cjs_shims();
|
|
@@ -11811,6 +11900,7 @@ function hashBuckets(initialCount) {
|
|
|
11811
11900
|
_fillInTileStats,
|
|
11812
11901
|
_getHexagonResolution,
|
|
11813
11902
|
_getLog10ScaleSteps,
|
|
11903
|
+
_getPointsAggregationLevel,
|
|
11814
11904
|
_getRasterTileLayerStyleProps,
|
|
11815
11905
|
_validateVecExprSyntax,
|
|
11816
11906
|
addFilter,
|
|
@@ -11820,6 +11910,7 @@ function hashBuckets(initialCount) {
|
|
|
11820
11910
|
applySorting,
|
|
11821
11911
|
boundaryQuerySource,
|
|
11822
11912
|
boundaryTableSource,
|
|
11913
|
+
buildAuthHeaders,
|
|
11823
11914
|
buildBinaryFeatureFilter,
|
|
11824
11915
|
buildPublicMapUrl,
|
|
11825
11916
|
buildStatsUrl,
|
|
@@ -11838,6 +11929,7 @@ function hashBuckets(initialCount) {
|
|
|
11838
11929
|
filterFunctions,
|
|
11839
11930
|
geojsonFeatures,
|
|
11840
11931
|
getApplicableFilters,
|
|
11932
|
+
getAuthCredentials,
|
|
11841
11933
|
getClient,
|
|
11842
11934
|
getColorAccessor,
|
|
11843
11935
|
getColumnNameFromGeoColumn,
|
|
@@ -11871,6 +11963,7 @@ function hashBuckets(initialCount) {
|
|
|
11871
11963
|
rasterSource,
|
|
11872
11964
|
removeFilter,
|
|
11873
11965
|
requestWithParameters,
|
|
11966
|
+
rewriteUrlForSessionMode,
|
|
11874
11967
|
scaleAggregationResLevel,
|
|
11875
11968
|
scatterPlot,
|
|
11876
11969
|
setClient,
|