@adobe/spacecat-shared-rum-api-client 2.18.7 → 2.18.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-rum-api-client-v2.18.9](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.18.8...@adobe/spacecat-shared-rum-api-client-v2.18.9) (2025-01-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **rum-api-client:** only consider earned traffic in hi-org-lo-ctr ([#565](https://github.com/adobe/spacecat-shared/issues/565)) ([f7a2019](https://github.com/adobe/spacecat-shared/commit/f7a20193844f40938032a4236f55241fcdefb8d4))
7
+
8
+ # [@adobe/spacecat-shared-rum-api-client-v2.18.8](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.18.7...@adobe/spacecat-shared-rum-api-client-v2.18.8) (2025-01-24)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **rum-api-client:** extra RUM Bundler requests logging ([#558](https://github.com/adobe/spacecat-shared/issues/558)) ([b80160a](https://github.com/adobe/spacecat-shared/commit/b80160a84feea4247db25172f023e3f8132b4d13))
14
+
1
15
  # [@adobe/spacecat-shared-rum-api-client-v2.18.7](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.18.6...@adobe/spacecat-shared-rum-api-client-v2.18.7) (2025-01-23)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-rum-api-client",
3
- "version": "2.18.7",
3
+ "version": "2.18.9",
4
4
  "description": "Shared modules of the Spacecat Services - Rum API client",
5
5
  "type": "module",
6
6
  "engines": {
@@ -186,11 +186,17 @@ async function fetchBundles(opts, log) {
186
186
 
187
187
  const chunks = getUrlChunks(urls, CHUNK_SIZE);
188
188
 
189
+ let totalTransferSize = 0;
190
+
189
191
  const result = [];
190
192
  for (const chunk of chunks) {
191
- const responses = await Promise.all(chunk.map((url) => {
192
- log.info(`Retrieving RUM bundles. Granularity: ${granularity}. Domain: ${domain}`);
193
- return fetch(url);
193
+ // eslint-disable-next-line no-loop-func
194
+ const responses = await Promise.all(chunk.map(async (url) => {
195
+ const response = await fetch(url);
196
+ const xCache = response.headers.get('x-cache')?.toLowerCase().includes('hit');
197
+ log.info(`Retrieving RUM bundles. Source: ${xCache ? 'CDN' : 'ORIGIN'}. Granularity: ${granularity}. Domain: ${domain}`);
198
+ totalTransferSize += parseInt(response.headers.get('content-length'), 10);
199
+ return response;
194
200
  }));
195
201
  const bundles = await Promise.all(responses.map((response) => response.json()));
196
202
 
@@ -201,6 +207,7 @@ async function fetchBundles(opts, log) {
201
207
  .forEach((bundle) => result.push(bundle));
202
208
  });
203
209
  }
210
+ log.info(`Retrieved RUM bundles. Total transfer size (in KB): ${(totalTransferSize / 1024).toFixed(2)}`);
204
211
  return mergeBundlesWithSameId(result);
205
212
  }
206
213
 
@@ -13,7 +13,7 @@
13
13
  import trafficAcquisition from '../traffic-acquisition.js';
14
14
  import { getCTRByUrlAndVendor, getSiteAvgCTR } from '../../common/aggregateFns.js';
15
15
 
16
- const DAILY_EARNED_THRESHOLD = 5000;
16
+ const DAILY_EARNED_THRESHOLD = 3000;
17
17
  const CTR_THRESHOLD_RATIO = 0.95;
18
18
  const DAILY_PAGEVIEW_THRESHOLD = 1000;
19
19
  const VENDORS_TO_CONSIDER = 5;
@@ -94,8 +94,8 @@ function convertToOpportunity(traffic) {
94
94
  }
95
95
 
96
96
  function hasHighOrganicTraffic(interval, traffic) {
97
- const { earned, owned } = traffic;
98
- return earned + owned > DAILY_EARNED_THRESHOLD * interval;
97
+ const { earned } = traffic;
98
+ return earned >= DAILY_EARNED_THRESHOLD * interval;
99
99
  }
100
100
 
101
101
  function hasLowerCTR(ctr, siteAvgCTR) {
package/src/index.js CHANGED
@@ -9,6 +9,7 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
+ import { hasText } from '@adobe/spacecat-shared-utils';
12
13
  import { fetchBundles } from './common/rum-bundler-client.js';
13
14
  import notfound from './functions/404.js';
14
15
  import notfoundInternalLinks from './functions/404-internal-links.js';
@@ -36,6 +37,14 @@ const HANDLERS = {
36
37
  'high-organic-low-ctr': highOrganicLowCtr,
37
38
  };
38
39
 
40
+ function sanitize(opts) {
41
+ return {
42
+ ...opts,
43
+ /* c8 ignore next 1 */
44
+ ...(hasText(opts.domainkey) && { domainkey: `${opts.domainkey.slice(0, 3)}***` }),
45
+ };
46
+ }
47
+
39
48
  export default class RUMAPIClient {
40
49
  static createFrom(context) {
41
50
  const { log = console } = context;
@@ -66,7 +75,7 @@ export default class RUMAPIClient {
66
75
 
67
76
  return handler(bundles, opts);
68
77
  } catch (e) {
69
- throw new Error(`Query '${query}' failed. Opts: ${JSON.stringify(opts)}. Reason: ${e.message}`);
78
+ throw new Error(`Query '${query}' failed. Opts: ${JSON.stringify(sanitize(opts))}. Reason: ${e.message}`);
70
79
  }
71
80
  }
72
81
 
@@ -105,7 +114,7 @@ export default class RUMAPIClient {
105
114
 
106
115
  return results;
107
116
  } catch (e) {
108
- throw new Error(`Multi query failed. Queries: ${JSON.stringify(queries)}, Opts: ${JSON.stringify(opts)}. Reason: ${e.message}`);
117
+ throw new Error(`Multi query failed. Queries: ${JSON.stringify(queries)}, Opts: ${JSON.stringify(sanitize(opts))}. Reason: ${e.message}`);
109
118
  }
110
119
  }
111
120
  }