@adobe/spacecat-shared-rum-api-client 2.18.6 → 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 +14 -0
- package/package.json +1 -1
- package/src/common/rum-bundler-client.js +12 -2
- package/src/index.js +13 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
|
|
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)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **rum-api-client:** log RUM Bundler requests ([#555](https://github.com/adobe/spacecat-shared/issues/555)) ([9b3ed87](https://github.com/adobe/spacecat-shared/commit/9b3ed87d12d0838ef922d6f373a287b4782dd197))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-rum-api-client-v2.18.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.18.5...@adobe/spacecat-shared-rum-api-client-v2.18.6) (2025-01-20)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -157,7 +157,7 @@ async function mergeBundlesWithSameId(bundles) {
|
|
|
157
157
|
}
|
|
158
158
|
/* c8 ignore end */
|
|
159
159
|
|
|
160
|
-
async function fetchBundles(opts
|
|
160
|
+
async function fetchBundles(opts, log) {
|
|
161
161
|
const {
|
|
162
162
|
domain,
|
|
163
163
|
domainkey,
|
|
@@ -186,9 +186,18 @@ async function fetchBundles(opts = {}) {
|
|
|
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
|
-
|
|
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;
|
|
200
|
+
}));
|
|
192
201
|
const bundles = await Promise.all(responses.map((response) => response.json()));
|
|
193
202
|
|
|
194
203
|
bundles.forEach((b) => {
|
|
@@ -198,6 +207,7 @@ async function fetchBundles(opts = {}) {
|
|
|
198
207
|
.forEach((bundle) => result.push(bundle));
|
|
199
208
|
});
|
|
200
209
|
}
|
|
210
|
+
log.info(`Retrieved RUM bundles. Total transfer size (in KB): ${(totalTransferSize / 1024).toFixed(2)}`);
|
|
201
211
|
return mergeBundlesWithSameId(result);
|
|
202
212
|
}
|
|
203
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;
|
|
@@ -60,13 +69,13 @@ export default class RUMAPIClient {
|
|
|
60
69
|
const bundles = await fetchBundles({
|
|
61
70
|
...opts,
|
|
62
71
|
checkpoints,
|
|
63
|
-
});
|
|
72
|
+
}, this.log);
|
|
64
73
|
|
|
65
74
|
this.log.info(`Query "${query}" fetched ${bundles.length} bundles`);
|
|
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
|
|
|
@@ -91,7 +100,7 @@ export default class RUMAPIClient {
|
|
|
91
100
|
const bundles = await fetchBundles({
|
|
92
101
|
...opts,
|
|
93
102
|
checkpoints: [...allCheckpoints],
|
|
94
|
-
});
|
|
103
|
+
}, this.log);
|
|
95
104
|
|
|
96
105
|
const results = {};
|
|
97
106
|
|
|
@@ -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
|
}
|