@esri/telemetry-amazon 6.0.0-beta.7 → 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.
@@ -2260,6 +2305,8 @@
2260
2305
  };
2261
2306
  }
2262
2307
 
2308
+ // October 31, 2026
2309
+ const PINPOINT_RETIREMENT_CUTOFF_UTC_MS = Date.parse('2026-10-31T00:00:00.000Z');
2263
2310
  /**
2264
2311
  * Amazon Telemetry
2265
2312
  * Supports Pinpoint and Esri endpoint modes
@@ -2269,10 +2316,17 @@
2269
2316
  this.name = 'amazon';
2270
2317
  this.previousPage = {};
2271
2318
  this.isInitialized = false;
2319
+ this.appConfig = {};
2320
+ this.isPinpointRetired = (nowMs = Date.now()) => nowMs >= PINPOINT_RETIREMENT_CUTOFF_UTC_MS;
2272
2321
  // default to `esri` mode if not specified
2273
2322
  const { app = {}, fips, userPoolID, mode = 'esri' } = options;
2274
- this.mode = mode;
2275
- if (this.mode === 'pinpoint') {
2323
+ Object.assign(this, options);
2324
+ this.appConfig = app;
2325
+ this.userPoolIDConfig = userPoolID;
2326
+ this.fipsConfig = fips;
2327
+ /** @deprecated Pinpoint is retiring on October 31, 2026. After this point all traffic will be routed to the in-house endpoint */
2328
+ if (mode === 'pinpoint' && !this.isPinpointRetired()) {
2329
+ this.mode = 'pinpoint';
2276
2330
  this.analytics = analyticsLib({
2277
2331
  app: app.name,
2278
2332
  version: app.version,
@@ -2284,18 +2338,17 @@
2284
2338
  }),
2285
2339
  ],
2286
2340
  });
2341
+ return;
2287
2342
  }
2288
- else {
2289
- this.analytics = createEsriPlugin({
2290
- trackerName: this.name,
2291
- appName: app.name,
2292
- appVersion: app.version,
2293
- appId: app.id,
2294
- userPoolID,
2295
- fips,
2296
- });
2297
- }
2298
- Object.assign(this, options);
2343
+ this.mode = 'esri';
2344
+ this.analytics = createEsriPlugin({
2345
+ trackerName: this.name,
2346
+ appName: this.appConfig.name,
2347
+ appVersion: this.appConfig.version,
2348
+ appId: this.appConfig.id,
2349
+ userPoolID: this.userPoolIDConfig,
2350
+ fips: this.fipsConfig,
2351
+ });
2299
2352
  }
2300
2353
  init() {
2301
2354
  // if already initialized, return