@adobe/helix-rum-enhancer 2.17.0 → 2.18.0

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/.husky/pre-commit CHANGED
@@ -1 +1,2 @@
1
+ npx lint-staged
1
2
  npm test
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [2.18.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.17.1...v2.18.0) (2024-08-08)
2
+
3
+
4
+ ### Features
5
+
6
+ * **loadresource:** include API calls in `loadresouce` requests for content request counting ([45449c2](https://github.com/adobe/helix-rum-enhancer/commit/45449c2e6a1602d80321f4ffa8698cbd116f1383))
7
+
8
+ ## [2.17.1](https://github.com/adobe/helix-rum-enhancer/compare/v2.17.0...v2.17.1) (2024-08-02)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **loadresource:** fix closing bracket ([0978b71](https://github.com/adobe/helix-rum-enhancer/commit/0978b7138f16421b5eb22c49b3c757116cb7053b))
14
+ * **loadresource:** include all JSON resources, and GraphQL resources ([8ebaa97](https://github.com/adobe/helix-rum-enhancer/commit/8ebaa97e844ff605ec2e6a458fc43adc3c5a37dd))
15
+
1
16
  # [2.17.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.16.0...v2.17.0) (2024-07-03)
2
17
 
3
18
 
package/modules/fflags.js CHANGED
@@ -10,9 +10,10 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  export const fflags = {
13
- has: (flag) => fflags[flag].indexOf(Array.from(window.origin)
14
- .map((a) => a.charCodeAt(0))
15
- .reduce((a, b) => a + b, 1) % 1371) !== -1,
13
+ has: (flag) => !!window.origin.match(/localhost/)
14
+ || fflags[flag].indexOf(Array.from(window.origin)
15
+ .map((a) => a.charCodeAt(0))
16
+ .reduce((a, b) => a + b, 1) % 1371) !== -1,
16
17
  enabled: (flag, callback) => fflags.has(flag) && callback(),
17
18
  disabled: (flag, callback) => !fflags.has(flag) && callback(),
18
19
  onetrust: [543, 770, 1136],
package/modules/index.js CHANGED
@@ -44,6 +44,7 @@ function trackCheckpoint(checkpoint, data, t) {
44
44
  if (window.location.origin === origin) {
45
45
  const headers = { type: 'application/json' };
46
46
  navigator.sendBeacon(url, new Blob([body], headers));
47
+ /* c8 ignore next 3 */
47
48
  } else {
48
49
  navigator.sendBeacon(url, body);
49
50
  }
@@ -97,6 +98,7 @@ function addCWVTracking() {
97
98
  });
98
99
  };
99
100
  document.head.appendChild(script);
101
+ /* c8 ignore next 3 */
100
102
  } catch (error) {
101
103
  // something went wrong
102
104
  }
@@ -144,7 +146,7 @@ function addLoadResourceTracking() {
144
146
  list.getEntries()
145
147
  .filter((entry) => !entry.responseStatus || entry.responseStatus < 400)
146
148
  .filter((entry) => window.location.hostname === new URL(entry.name).hostname)
147
- .filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html|\\.json)$'))
149
+ .filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html$|\\.json|graphql|api)'))
148
150
  .forEach((entry) => {
149
151
  sampleRUM('loadresource', { source: entry.name, target: Math.round(entry.duration) });
150
152
  });
@@ -153,6 +155,7 @@ function addLoadResourceTracking() {
153
155
  .forEach((entry) => {
154
156
  sampleRUM('missingresource', { source: entry.name, target: entry.hostname });
155
157
  });
158
+ /* c8 ignore next 3 */
156
159
  } catch (error) {
157
160
  // something went wrong
158
161
  }
@@ -187,6 +190,7 @@ function getIntersectionObsever(checkpoint) {
187
190
  const source = sourceSelector(entry.target);
188
191
  sampleRUM(checkpoint, { target, source });
189
192
  });
193
+ /* c8 ignore next 3 */
190
194
  } catch (error) {
191
195
  // something went wrong
192
196
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@adobe/helix-rum-enhancer",
3
- "version": "2.17.0",
3
+ "version": "2.18.0",
4
4
  "description": "Helix RUM Enhancer",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "setup-playwright": "npx playwright install --with-deps chromium firefox webkit",
9
- "test": "npm run setup-playwright && web-test-runner --node-resolve --coverage --playwright --browsers chromium firefox webkit",
10
- "test:ci": "npm run setup-playwright && web-test-runner --node-resolve --coverage --playwright --browsers chromium firefox webkit",
9
+ "test": "npm run build-bundle && npm run setup-playwright && web-test-runner --node-resolve --coverage --playwright --browsers chromium firefox webkit",
10
+ "test:ci": "npm run build-bundle && npm run setup-playwright && web-test-runner --node-resolve --coverage --playwright --browsers chromium firefox webkit",
11
11
  "test:watch": "web-test-runner --node-resolve --playwright --coverage --watch",
12
12
  "lint": "eslint .",
13
13
  "docs": "npx jsdoc2md -c .jsdoc.json --files 'src/*.js' > docs/API.md",
@@ -34,6 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@adobe/eslint-config-helix": "2.0.6",
37
+ "@adobe/helix-rum-js": "2.1.4",
37
38
  "@esm-bundle/chai": "4.3.4-fix.0",
38
39
  "@semantic-release/changelog": "6.0.3",
39
40
  "@semantic-release/git": "10.0.1",
@@ -47,16 +48,17 @@
47
48
  "eslint": "8.57.0",
48
49
  "eslint-plugin-header": "3.1.1",
49
50
  "eslint-plugin-import": "2.29.1",
50
- "husky": "9.0.11",
51
- "jsdoc-to-markdown": "8.0.1",
52
- "junit-report-builder": "3.2.1",
53
- "lint-staged": "15.2.7",
54
- "mocha": "10.5.2",
51
+ "husky": "9.1.4",
52
+ "jsdoc-to-markdown": "8.0.3",
53
+ "junit-report-builder": "4.0.1",
54
+ "lint-staged": "15.2.8",
55
+ "mocha": "10.7.0",
55
56
  "mocha-multi-reporters": "1.5.1",
56
- "rollup": "4.18.0",
57
+ "rollup": "4.20.0",
57
58
  "rollup-plugin-cleanup": "3.2.1",
58
59
  "rollup-plugin-eslint-bundle": "9.0.0",
59
- "semantic-release": "24.0.0"
60
+ "semantic-release": "24.0.0",
61
+ "web-vitals": "4.2.2"
60
62
  },
61
63
  "lint-staged": {
62
64
  "*.js": "eslint",
package/rollup.config.js CHANGED
@@ -45,6 +45,13 @@ export default [...bundles.map(({ outputFile, source }) => ({
45
45
  exports: 'auto',
46
46
  banner,
47
47
  },
48
+ {
49
+ file: `${outputFile}.map.js`,
50
+ format: 'iife',
51
+ sourcemap: 'inline',
52
+ exports: 'auto',
53
+ banner,
54
+ },
48
55
  ],
49
56
  plugins: [
50
57
  cleanup({
package/src/index.js CHANGED
@@ -19,9 +19,10 @@
19
19
  const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email'];
20
20
 
21
21
  const fflags = {
22
- has: (flag) => fflags[flag].indexOf(Array.from(window.origin)
23
- .map((a) => a.charCodeAt(0))
24
- .reduce((a, b) => a + b, 1) % 1371) !== -1,
22
+ has: (flag) => !!window.origin.match(/localhost/)
23
+ || fflags[flag].indexOf(Array.from(window.origin)
24
+ .map((a) => a.charCodeAt(0))
25
+ .reduce((a, b) => a + b, 1) % 1371) !== -1,
25
26
  enabled: (flag, callback) => fflags.has(flag) && callback(),
26
27
  disabled: (flag, callback) => !fflags.has(flag) && callback(),
27
28
  onetrust: [543, 770, 1136],
@@ -244,7 +245,7 @@
244
245
  list.getEntries()
245
246
  .filter((entry) => !entry.responseStatus || entry.responseStatus < 400)
246
247
  .filter((entry) => window.location.hostname === new URL(entry.name).hostname)
247
- .filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html|\\.json)$'))
248
+ .filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html$|\\.json|graphql|api)'))
248
249
  .forEach((entry) => {
249
250
  sampleRUM('loadresource', { source: entry.name, target: Math.round(entry.duration) });
250
251
  });
@@ -10,16 +10,54 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  export default {
13
+ testFramework: {
14
+ type: 'mocha',
15
+ config: {
16
+ timeout: 10000,
17
+ },
18
+ },
13
19
  coverageConfig: {
14
20
  report: true,
15
21
  reportDir: 'coverage',
16
22
  exclude: [
17
23
  'test/fixtures/**',
18
24
  'node_modules/**',
25
+ '.rum/**',
19
26
  ],
20
27
  },
21
28
  files: [
22
29
  'test/**/*.test.{html,js}',
23
30
  'test/*.test.{html,js}',
24
31
  ],
32
+ middleware: [
33
+ async function emulateRUM(context, next) {
34
+ if (context.url.startsWith('/src/index.map.js')) {
35
+ await next();
36
+ context.body = context.body
37
+ .replace(/navigator\.sendBeacon/g, 'fakeSendBeacon');
38
+ return true;
39
+ } else if (context.url.startsWith('/.rum')) {
40
+ if (context.url.startsWith('/.rum/@adobe/helix-rum-js@%5E2/dist/')
41
+ || context.url.startsWith('/.rum/@adobe/helix-rum-js@^2/dist/')
42
+ ) {
43
+ context.url = '/node_modules/@adobe/helix-rum-js/dist/rum-standalone.js';
44
+ await next();
45
+ context.body = context.body
46
+ .replace(/const weight.*/, 'const weight = 1;')
47
+ .replace(/navigator\.sendBeacon/g, 'fakeSendBeacon')
48
+ .replace('.rum/@adobe/helix-rum-enhancer@^2/src/index.js', 'src/index.map.js');
49
+ return true;
50
+ } else if (context.url.startsWith('/.rum/web-vitals')) {
51
+ context.url = '/node_modules/web-vitals/dist/web-vitals.iife.js';
52
+ await next();
53
+ return true;
54
+ } else if (context.url === '/.rum/1') {
55
+ // return a 201 response and do nothing
56
+ context.status = 201;
57
+ return true;
58
+ }
59
+ }
60
+ return next();
61
+ },
62
+ ],
25
63
  };