@esri/telemetry-amazon 5.1.4 → 5.1.5

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.
@@ -1259,6 +1259,26 @@
1259
1259
  function bboxToString(extent) {
1260
1260
  return extent.join(",");
1261
1261
  }
1262
+ /**
1263
+ * Returns the full thumbnail URL for an item.
1264
+ *
1265
+ * @param item - The item to decorate
1266
+ * @param portal - The portal URL
1267
+ * @param token - Optional token to append if the item is private
1268
+ * @returns The item with decorated thumbnail
1269
+ */
1270
+ function decorateThumbnail(item, portal, token) {
1271
+ if (!item)
1272
+ return item;
1273
+ let thumbnailUrl = null;
1274
+ if (typeof item.thumbnail === "string") {
1275
+ thumbnailUrl = `${portal}/content/items/${item.id}/info/${item.thumbnail}`;
1276
+ if (thumbnailUrl && item.access !== "public" && token) {
1277
+ thumbnailUrl += `?${token}`;
1278
+ }
1279
+ }
1280
+ return Object.assign(Object.assign({}, item), (thumbnailUrl ? { thumbnailUrl } : {}));
1281
+ }
1262
1282
 
1263
1283
  /* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
1264
1284
  * Apache-2.0 */
@@ -1295,6 +1315,16 @@
1295
1315
  if (requestOptions.params.extent && isBBox(requestOptions.params.extent)) {
1296
1316
  requestOptions.params.extent = bboxToString(requestOptions.params.extent);
1297
1317
  }
1318
+ const portal = getPortalUrl(requestOptions);
1319
+ const decoratedThumbnail = decorateThumbnail(Object.assign(Object.assign({}, requestOptions.item), { access: requestOptions.item.access }), portal);
1320
+ const paramsThumbnailUrl = requestOptions.params.thumbnailUrl;
1321
+ if (typeof decoratedThumbnail.thumbnailUrl === "string" &&
1322
+ typeof paramsThumbnailUrl === "string") {
1323
+ if (decoratedThumbnail.thumbnailUrl.split("?")[0] ===
1324
+ paramsThumbnailUrl.split("?")[0]) {
1325
+ delete requestOptions.params.thumbnailUrl;
1326
+ }
1327
+ }
1298
1328
  return request(url, requestOptions);
1299
1329
  });
1300
1330
  }
@@ -1321,7 +1351,22 @@
1321
1351
  const url = getItemBaseUrl(id, requestOptions);
1322
1352
  // default to a GET request
1323
1353
  const options = Object.assign({ httpMethod: "GET" }, requestOptions);
1324
- return request(url, options);
1354
+ return request(url, options).then(async (item) => {
1355
+ const portal = (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.portal) || getPortalUrl(requestOptions);
1356
+ let token;
1357
+ // if authentication is provided and it’s an authentication manager and the item is not public then request a token for secure access
1358
+ if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.authentication) &&
1359
+ typeof requestOptions.authentication !== "string" &&
1360
+ item.access !== "public") {
1361
+ try {
1362
+ token = await requestOptions.authentication.getToken(url);
1363
+ }
1364
+ catch (e) {
1365
+ // 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.
1366
+ }
1367
+ }
1368
+ return decorateThumbnail(item, portal, token);
1369
+ });
1325
1370
  }
1326
1371
  /**
1327
1372
  * Get the fully qualified base URL to the REST end point for an item.