@adobe/spacecat-shared-rum-api-client 2.31.0 → 2.31.1

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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-rum-api-client-v2.31.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.31.0...@adobe/spacecat-shared-rum-api-client-v2.31.1) (2025-06-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * check status before parsing rum bundles ([#807](https://github.com/adobe/spacecat-shared/issues/807)) ([36566e4](https://github.com/adobe/spacecat-shared/commit/36566e4ab1cb8e72e3e5e0673df3171c7793ab82))
7
+
1
8
  # [@adobe/spacecat-shared-rum-api-client-v2.31.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.30.0...@adobe/spacecat-shared-rum-api-client-v2.31.0) (2025-06-25)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-rum-api-client",
3
- "version": "2.31.0",
3
+ "version": "2.31.1",
4
4
  "description": "Shared modules of the Spacecat Services - Rum API client",
5
5
  "type": "module",
6
6
  "engines": {
@@ -57,6 +57,20 @@ function filterEvents(checkpoints = []) {
57
57
  };
58
58
  }
59
59
 
60
+ function sanitizeURL(url) {
61
+ try {
62
+ const parsedUrl = new URL(url);
63
+ if (parsedUrl.searchParams.has('domainkey')) {
64
+ parsedUrl.searchParams.set('domainkey', 'redacted');
65
+ }
66
+ return parsedUrl.toString();
67
+ /* c8 ignore next 4 */
68
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
69
+ } catch (e) {
70
+ return url;
71
+ }
72
+ }
73
+
60
74
  function constructUrl(domain, date, granularity, domainkey) {
61
75
  const year = date.getUTCFullYear();
62
76
  const month = (date.getUTCMonth() + 1).toString().padStart(2, '0');
@@ -246,6 +260,7 @@ async function fetchBundles(opts, log) {
246
260
  const chunks = getUrlChunks(urls, CHUNK_SIZE);
247
261
 
248
262
  let totalTransferSize = 0;
263
+ const failedUrls = [];
249
264
 
250
265
  const result = [];
251
266
  for (const chunk of chunks) {
@@ -255,7 +270,21 @@ async function fetchBundles(opts, log) {
255
270
  totalTransferSize += parseInt(response.headers.get('content-length'), 10);
256
271
  return response;
257
272
  }));
258
- const bundles = await Promise.all(responses.map((response) => response.json()));
273
+
274
+ const bundlesRaw = await Promise.all(
275
+ responses.map(async (response, index) => {
276
+ if (response.ok) {
277
+ return response.json();
278
+ } else {
279
+ const failedUrl = response.url || chunk[index];
280
+ log.warn(`Skipping response at index ${index}: status ${response.status} - url: ${sanitizeURL(failedUrl)}`);
281
+ failedUrls.push(failedUrl);
282
+ return null;
283
+ }
284
+ }),
285
+ );
286
+
287
+ const bundles = bundlesRaw.filter(Boolean);
259
288
  bundles.forEach((b) => {
260
289
  b.rumBundles
261
290
  .filter((bundle) => !filterBotTraffic || !isBotTraffic(bundle))
@@ -264,6 +293,13 @@ async function fetchBundles(opts, log) {
264
293
  });
265
294
  }
266
295
  log.info(`Retrieved RUM bundles. Total transfer size (in KB): ${(totalTransferSize / 1024).toFixed(2)}`);
296
+
297
+ // Add failedUrls to opts object for access by callers
298
+ if (failedUrls.length > 0) {
299
+ // eslint-disable-next-line no-param-reassign
300
+ opts.failedUrls = failedUrls;
301
+ }
302
+
267
303
  return mergeBundlesWithSameId(result);
268
304
  }
269
305
 
package/src/index.js CHANGED
@@ -122,7 +122,6 @@ export default class RUMAPIClient {
122
122
 
123
123
  try {
124
124
  const domainkey = await this._getDomainkey(opts);
125
-
126
125
  const bundles = await fetchBundles({
127
126
  ...opts,
128
127
  domainkey,
@@ -130,7 +129,6 @@ export default class RUMAPIClient {
130
129
  }, this.log);
131
130
 
132
131
  this.log.info(`Query "${query}" fetched ${bundles.length} bundles`);
133
-
134
132
  return handler(bundles, opts);
135
133
  } catch (e) {
136
134
  throw new Error(`Query '${query}' failed. Opts: ${JSON.stringify(sanitize(opts))}. Reason: ${e.message}`);
@@ -164,7 +162,6 @@ export default class RUMAPIClient {
164
162
  }, this.log);
165
163
 
166
164
  const results = {};
167
-
168
165
  this.log.info(`Multi query ${JSON.stringify(queries.join(', '))} fetched ${bundles.length} bundles`);
169
166
 
170
167
  // Execute each query handler sequentially