@esri/telemetry-amazon 6.0.0-beta.8 → 6.0.0-beta.9
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.
|
@@ -1252,6 +1252,26 @@
|
|
|
1252
1252
|
function bboxToString(extent) {
|
|
1253
1253
|
return extent.join(",");
|
|
1254
1254
|
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Returns the full thumbnail URL for an item.
|
|
1257
|
+
*
|
|
1258
|
+
* @param item - The item to decorate
|
|
1259
|
+
* @param portal - The portal URL
|
|
1260
|
+
* @param token - Optional token to append if the item is private
|
|
1261
|
+
* @returns The item with decorated thumbnail
|
|
1262
|
+
*/
|
|
1263
|
+
function decorateThumbnail(item, portal, token) {
|
|
1264
|
+
if (!item)
|
|
1265
|
+
return item;
|
|
1266
|
+
let thumbnailUrl = null;
|
|
1267
|
+
if (typeof item.thumbnail === "string") {
|
|
1268
|
+
thumbnailUrl = `${portal}/content/items/${item.id}/info/${item.thumbnail}`;
|
|
1269
|
+
if (thumbnailUrl && item.access !== "public" && token) {
|
|
1270
|
+
thumbnailUrl += `?${token}`;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
return Object.assign(Object.assign({}, item), (thumbnailUrl ? { thumbnailUrl } : {}));
|
|
1274
|
+
}
|
|
1255
1275
|
|
|
1256
1276
|
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
|
|
1257
1277
|
* Apache-2.0 */
|
|
@@ -1288,6 +1308,16 @@
|
|
|
1288
1308
|
if (requestOptions.params.extent && isBBox(requestOptions.params.extent)) {
|
|
1289
1309
|
requestOptions.params.extent = bboxToString(requestOptions.params.extent);
|
|
1290
1310
|
}
|
|
1311
|
+
const portal = getPortalUrl(requestOptions);
|
|
1312
|
+
const decoratedThumbnail = decorateThumbnail(Object.assign(Object.assign({}, requestOptions.item), { access: requestOptions.item.access }), portal);
|
|
1313
|
+
const paramsThumbnailUrl = requestOptions.params.thumbnailUrl;
|
|
1314
|
+
if (typeof decoratedThumbnail.thumbnailUrl === "string" &&
|
|
1315
|
+
typeof paramsThumbnailUrl === "string") {
|
|
1316
|
+
if (decoratedThumbnail.thumbnailUrl.split("?")[0] ===
|
|
1317
|
+
paramsThumbnailUrl.split("?")[0]) {
|
|
1318
|
+
delete requestOptions.params.thumbnailUrl;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1291
1321
|
return request(url, requestOptions);
|
|
1292
1322
|
});
|
|
1293
1323
|
}
|
|
@@ -1314,7 +1344,22 @@
|
|
|
1314
1344
|
const url = getItemBaseUrl(id, requestOptions);
|
|
1315
1345
|
// default to a GET request
|
|
1316
1346
|
const options = Object.assign({ httpMethod: "GET" }, requestOptions);
|
|
1317
|
-
return request(url, options)
|
|
1347
|
+
return request(url, options).then(async (item) => {
|
|
1348
|
+
const portal = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.portal) || getPortalUrl(requestOptions);
|
|
1349
|
+
let token;
|
|
1350
|
+
// if authentication is provided and it’s an authentication manager and the item is not public then request a token for secure access
|
|
1351
|
+
if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.authentication) &&
|
|
1352
|
+
typeof requestOptions.authentication !== "string" &&
|
|
1353
|
+
item.access !== "public") {
|
|
1354
|
+
try {
|
|
1355
|
+
token = await requestOptions.authentication.getToken(url);
|
|
1356
|
+
}
|
|
1357
|
+
catch (e) {
|
|
1358
|
+
// Ignore token acquisition errors because `getToken()` can fail for some authentication types, but we still want to return the item info when possible since the browser may still provide thumbnail access via an auth cookie.
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return decorateThumbnail(item, portal, token);
|
|
1362
|
+
});
|
|
1318
1363
|
}
|
|
1319
1364
|
/**
|
|
1320
1365
|
* Get the fully qualified base URL to the REST end point for an item.
|