@elliemae/pui-app-sdk 5.12.0 → 5.13.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.
@@ -64,6 +64,7 @@ class Analytics extends import_em_ssf_host.default.ScriptingObject {
64
64
  startTime: new Date(
65
65
  performance.timeOrigin + entry.startTime
66
66
  ).toISOString(),
67
+ ...(0, import_web_analytics.getBAEventParameters)(),
67
68
  ...detail
68
69
  }).catch(() => {
69
70
  });
@@ -94,51 +95,64 @@ class Analytics extends import_em_ssf_host.default.ScriptingObject {
94
95
  return Promise.resolve();
95
96
  };
96
97
  /**
97
- * start a performance mark
98
- * @param markName name of the performance mark
99
- * @param markOptions
98
+ * start timing measure
99
+ * @param name unique name for the timing measurement. If a measurement with the same name is already running, it will be replaced
100
+ * @param options additional details related to the measurement
100
101
  * @returns a promise that resolves to a PerformanceMeasure object
101
102
  */
102
- perfMarkStart = (markName, markOptions) => {
103
- if (!markName) throw new Error("markName is required");
104
- const startMark = performance.mark(markName, markOptions);
103
+ startTiming = (name, options) => {
104
+ if (!name) throw new Error("parameter mark is required");
105
+ if (!options || !options?.appId || !options?.appUrl)
106
+ throw new Error("parameter options is required");
107
+ const startMark = performance.mark(name, { detail: options });
105
108
  return Promise.resolve(startMark);
106
109
  };
107
110
  /**
108
- * end a performance mark
109
- * @param startMarkNameorMark start mark name or start PerformanceMeasure object
110
- * @param detail
111
- * @returns a promise that resolves when the mark is ended
111
+ * end timing measure
112
+ * @param start name used to start timing measure or return value of the startTiming method
113
+ * @param options additional details related to the measurement
114
+ * @returns a promise that resolves when the timing measurement is ended
112
115
  * @example
113
116
  * ```typescript
114
- * const startMark = await analytics.perfMarkStart('LongTask');
117
+ * const longTaskMeasurement = await analytics.startTiming('LongTask', { appId: 'myApp', appUrl: 'https://myapp.com' });
115
118
  * // do some work
116
- * await analytics.perfMarkEnd(startMark);
119
+ * await analytics.endTiming(longTaskMeasurement, { appId: 'myApp', appUrl: 'https://myapp.com' });
117
120
  * ```
118
121
  * ```typescript
119
- * await analytics.perfMarkStart('LongTask');
122
+ * const longTaskMeasurement = await analytics.startTiming('LongTask', { appId: 'myApp', appUrl: 'https://myapp.com' });
120
123
  * // do some work
121
- * await analytics.perfMarkEnd('LongTask');
124
+ * await analytics.endTiming('LongTask', { appId: 'loanApp', appUrl: 'https://loanApp.com' });
122
125
  * ```
123
126
  */
124
- perfMarkEnd = (startMarkNameorMark, detail) => {
125
- if (!startMarkNameorMark)
126
- throw new Error("startMarkNameorMark is required");
127
- const markName = startMarkNameorMark.name ?? startMarkNameorMark;
128
- if (performance.getEntriesByName(markName, "mark").length) {
129
- if (typeof startMarkNameorMark === "string")
130
- performance.measure(markName, {
127
+ endTiming = (start, options) => {
128
+ if (!start) throw new Error("parameter start is required");
129
+ if (!options || !options?.appId || !options?.appUrl)
130
+ throw new Error("parameter options is required");
131
+ const measurementName = start.name ?? start;
132
+ const startMark = performance.getEntriesByName(
133
+ measurementName,
134
+ "mark"
135
+ )?.[0];
136
+ const detail = {
137
+ startAppId: startMark?.detail?.appId ?? options.appId,
138
+ startAppUrl: startMark?.detail?.appUrl ?? options.appUrl,
139
+ endAppId: options.appId,
140
+ endAppUrl: options.appUrl
141
+ };
142
+ if (startMark) {
143
+ if (typeof start === "string")
144
+ performance.measure(measurementName, {
131
145
  detail,
132
- start: markName
146
+ start: measurementName
133
147
  });
134
148
  else
135
- performance.measure(markName, {
149
+ performance.measure(measurementName, {
136
150
  detail,
137
- start: startMarkNameorMark.startTime
151
+ start: start.startTime
138
152
  });
139
- performance.clearMarks(markName);
153
+ performance.clearMarks(measurementName);
140
154
  } else {
141
- performance.measure(markName, { detail });
155
+ performance.measure(measurementName, { detail });
142
156
  }
143
157
  return Promise.resolve();
144
158
  };
@@ -31,6 +31,7 @@ class Analytics extends ssfHost.ScriptingObject {
31
31
  startTime: new Date(
32
32
  performance.timeOrigin + entry.startTime
33
33
  ).toISOString(),
34
+ ...getBAEventParameters(),
34
35
  ...detail
35
36
  }).catch(() => {
36
37
  });
@@ -61,51 +62,64 @@ class Analytics extends ssfHost.ScriptingObject {
61
62
  return Promise.resolve();
62
63
  };
63
64
  /**
64
- * start a performance mark
65
- * @param markName name of the performance mark
66
- * @param markOptions
65
+ * start timing measure
66
+ * @param name unique name for the timing measurement. If a measurement with the same name is already running, it will be replaced
67
+ * @param options additional details related to the measurement
67
68
  * @returns a promise that resolves to a PerformanceMeasure object
68
69
  */
69
- perfMarkStart = (markName, markOptions) => {
70
- if (!markName) throw new Error("markName is required");
71
- const startMark = performance.mark(markName, markOptions);
70
+ startTiming = (name, options) => {
71
+ if (!name) throw new Error("parameter mark is required");
72
+ if (!options || !options?.appId || !options?.appUrl)
73
+ throw new Error("parameter options is required");
74
+ const startMark = performance.mark(name, { detail: options });
72
75
  return Promise.resolve(startMark);
73
76
  };
74
77
  /**
75
- * end a performance mark
76
- * @param startMarkNameorMark start mark name or start PerformanceMeasure object
77
- * @param detail
78
- * @returns a promise that resolves when the mark is ended
78
+ * end timing measure
79
+ * @param start name used to start timing measure or return value of the startTiming method
80
+ * @param options additional details related to the measurement
81
+ * @returns a promise that resolves when the timing measurement is ended
79
82
  * @example
80
83
  * ```typescript
81
- * const startMark = await analytics.perfMarkStart('LongTask');
84
+ * const longTaskMeasurement = await analytics.startTiming('LongTask', { appId: 'myApp', appUrl: 'https://myapp.com' });
82
85
  * // do some work
83
- * await analytics.perfMarkEnd(startMark);
86
+ * await analytics.endTiming(longTaskMeasurement, { appId: 'myApp', appUrl: 'https://myapp.com' });
84
87
  * ```
85
88
  * ```typescript
86
- * await analytics.perfMarkStart('LongTask');
89
+ * const longTaskMeasurement = await analytics.startTiming('LongTask', { appId: 'myApp', appUrl: 'https://myapp.com' });
87
90
  * // do some work
88
- * await analytics.perfMarkEnd('LongTask');
91
+ * await analytics.endTiming('LongTask', { appId: 'loanApp', appUrl: 'https://loanApp.com' });
89
92
  * ```
90
93
  */
91
- perfMarkEnd = (startMarkNameorMark, detail) => {
92
- if (!startMarkNameorMark)
93
- throw new Error("startMarkNameorMark is required");
94
- const markName = startMarkNameorMark.name ?? startMarkNameorMark;
95
- if (performance.getEntriesByName(markName, "mark").length) {
96
- if (typeof startMarkNameorMark === "string")
97
- performance.measure(markName, {
94
+ endTiming = (start, options) => {
95
+ if (!start) throw new Error("parameter start is required");
96
+ if (!options || !options?.appId || !options?.appUrl)
97
+ throw new Error("parameter options is required");
98
+ const measurementName = start.name ?? start;
99
+ const startMark = performance.getEntriesByName(
100
+ measurementName,
101
+ "mark"
102
+ )?.[0];
103
+ const detail = {
104
+ startAppId: startMark?.detail?.appId ?? options.appId,
105
+ startAppUrl: startMark?.detail?.appUrl ?? options.appUrl,
106
+ endAppId: options.appId,
107
+ endAppUrl: options.appUrl
108
+ };
109
+ if (startMark) {
110
+ if (typeof start === "string")
111
+ performance.measure(measurementName, {
98
112
  detail,
99
- start: markName
113
+ start: measurementName
100
114
  });
101
115
  else
102
- performance.measure(markName, {
116
+ performance.measure(measurementName, {
103
117
  detail,
104
- start: startMarkNameorMark.startTime
118
+ start: start.startTime
105
119
  });
106
- performance.clearMarks(markName);
120
+ performance.clearMarks(measurementName);
107
121
  } else {
108
- performance.measure(markName, { detail });
122
+ performance.measure(measurementName, { detail });
109
123
  }
110
124
  return Promise.resolve();
111
125
  };
@@ -1,5 +1,5 @@
1
1
  import ssfHost from '@elliemae/em-ssf-host';
2
- import { IAnalytics, BAEvent } from '@elliemae/pui-scripting-object';
2
+ import { IAnalytics, BAEvent, TimingOptions } from '@elliemae/pui-scripting-object';
3
3
  import { MicroFrontEndLogger } from '../../types.js';
4
4
  /**
5
5
  * Analytics scripting object
@@ -18,28 +18,28 @@ export declare class Analytics extends ssfHost.ScriptingObject implements IAnaly
18
18
  */
19
19
  sendBAEvent: (event: BAEvent) => Promise<void>;
20
20
  /**
21
- * start a performance mark
22
- * @param markName name of the performance mark
23
- * @param markOptions
21
+ * start timing measure
22
+ * @param name unique name for the timing measurement. If a measurement with the same name is already running, it will be replaced
23
+ * @param options additional details related to the measurement
24
24
  * @returns a promise that resolves to a PerformanceMeasure object
25
25
  */
26
- perfMarkStart: (markName: string, markOptions?: PerformanceMarkOptions) => Promise<PerformanceMark>;
26
+ startTiming: (name: string, options: TimingOptions) => Promise<PerformanceMark>;
27
27
  /**
28
- * end a performance mark
29
- * @param startMarkNameorMark start mark name or start PerformanceMeasure object
30
- * @param detail
31
- * @returns a promise that resolves when the mark is ended
28
+ * end timing measure
29
+ * @param start name used to start timing measure or return value of the startTiming method
30
+ * @param options additional details related to the measurement
31
+ * @returns a promise that resolves when the timing measurement is ended
32
32
  * @example
33
33
  * ```typescript
34
- * const startMark = await analytics.perfMarkStart('LongTask');
34
+ * const longTaskMeasurement = await analytics.startTiming('LongTask', { appId: 'myApp', appUrl: 'https://myapp.com' });
35
35
  * // do some work
36
- * await analytics.perfMarkEnd(startMark);
36
+ * await analytics.endTiming(longTaskMeasurement, { appId: 'myApp', appUrl: 'https://myapp.com' });
37
37
  * ```
38
38
  * ```typescript
39
- * await analytics.perfMarkStart('LongTask');
39
+ * const longTaskMeasurement = await analytics.startTiming('LongTask', { appId: 'myApp', appUrl: 'https://myapp.com' });
40
40
  * // do some work
41
- * await analytics.perfMarkEnd('LongTask');
41
+ * await analytics.endTiming('LongTask', { appId: 'loanApp', appUrl: 'https://loanApp.com' });
42
42
  * ```
43
43
  */
44
- perfMarkEnd: (startMarkNameorMark: string | PerformanceMeasure, detail?: Record<string, unknown>) => Promise<void>;
44
+ endTiming: (start: string | PerformanceMeasure, options: TimingOptions) => Promise<void>;
45
45
  }