@adobe/spacecat-shared-rum-api-client 2.18.7 → 2.18.8
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 +7 -0
- package/package.json +1 -1
- package/src/common/rum-bundler-client.js +10 -3
- package/src/index.js +11 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@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)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **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))
|
|
7
|
+
|
|
1
8
|
# [@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
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
|
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
|
}
|