@guardian/commercial-core 0.37.0 → 0.37.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.
@@ -57,7 +57,7 @@ export declare class EventTimer {
57
57
  * by EventTimer so they need to be concatenated to EventTimer's private events array.
58
58
  */
59
59
  get events(): Event[];
60
- constructor();
60
+ private constructor();
61
61
  /**
62
62
  * Creates a new performance mark
63
63
  * For slot events also ensures each TYPE of event event is marked only once for 'first'
@@ -96,9 +96,13 @@ class EventTimer {
96
96
  ? [
97
97
  ...this._events,
98
98
  ...EventTimer._externallyDefinedEventNames
99
- .filter((eventName) => window.performance.getEntriesByName(eventName)
100
- .length)
101
- .map((eventName) => new Event(eventName, window.performance.getEntriesByName(eventName)[0])),
99
+ .map((eventName) => {
100
+ const entry = window.performance.getEntriesByName(eventName)[0];
101
+ return entry
102
+ ? new Event(eventName, entry)
103
+ : undefined;
104
+ })
105
+ .filter((entry) => entry instanceof Event),
102
106
  ]
103
107
  : this._events;
104
108
  }
@@ -137,13 +141,11 @@ class EventTimer {
137
141
  mark(name) {
138
142
  const longName = `gu.commercial.${name}`;
139
143
  if (typeof window.performance !== 'undefined' &&
140
- 'mark' in window.performance) {
141
- window.performance.mark(longName);
142
- // Most recent mark with this name is the event we just created.
143
- const mark = window.performance
144
- .getEntriesByName(longName, 'mark')
145
- .slice(-1)[0];
146
- if (typeof mark !== 'undefined') {
144
+ 'mark' in window.performance &&
145
+ typeof window.performance.mark === 'function') {
146
+ const mark = window.performance.mark(longName);
147
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- browser support is patchy
148
+ if (typeof mark?.startTime === 'number') {
147
149
  this._events.push(new Event(name, mark));
148
150
  }
149
151
  }
@@ -57,7 +57,7 @@ export declare class EventTimer {
57
57
  * by EventTimer so they need to be concatenated to EventTimer's private events array.
58
58
  */
59
59
  get events(): Event[];
60
- constructor();
60
+ private constructor();
61
61
  /**
62
62
  * Creates a new performance mark
63
63
  * For slot events also ensures each TYPE of event event is marked only once for 'first'
@@ -93,9 +93,13 @@ export class EventTimer {
93
93
  ? [
94
94
  ...this._events,
95
95
  ...EventTimer._externallyDefinedEventNames
96
- .filter((eventName) => window.performance.getEntriesByName(eventName)
97
- .length)
98
- .map((eventName) => new Event(eventName, window.performance.getEntriesByName(eventName)[0])),
96
+ .map((eventName) => {
97
+ const entry = window.performance.getEntriesByName(eventName)[0];
98
+ return entry
99
+ ? new Event(eventName, entry)
100
+ : undefined;
101
+ })
102
+ .filter((entry) => entry instanceof Event),
99
103
  ]
100
104
  : this._events;
101
105
  }
@@ -134,13 +138,11 @@ export class EventTimer {
134
138
  mark(name) {
135
139
  const longName = `gu.commercial.${name}`;
136
140
  if (typeof window.performance !== 'undefined' &&
137
- 'mark' in window.performance) {
138
- window.performance.mark(longName);
139
- // Most recent mark with this name is the event we just created.
140
- const mark = window.performance
141
- .getEntriesByName(longName, 'mark')
142
- .slice(-1)[0];
143
- if (typeof mark !== 'undefined') {
141
+ 'mark' in window.performance &&
142
+ typeof window.performance.mark === 'function') {
143
+ const mark = window.performance.mark(longName);
144
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- browser support is patchy
145
+ if (typeof mark?.startTime === 'number') {
144
146
  this._events.push(new Event(name, mark));
145
147
  }
146
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/commercial-core",
3
- "version": "0.37.0",
3
+ "version": "0.37.1",
4
4
  "description": "Guardian advertising business logic",
5
5
  "homepage": "https://github.com/guardian/commercial-core#readme",
6
6
  "bugs": {