@elliemae/pui-app-sdk 5.10.10 → 5.11.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.
@@ -22,7 +22,7 @@ __export(analytics_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(analytics_exports);
24
24
  var import_guest = require("../utils/micro-frontend/guest.js");
25
- var import_web_analytics = require("./web-analytics.js");
25
+ var import_web_analytics = require("../utils/micro-frontend/scripting-objects/web-analytics.js");
26
26
  var import_redact_pii = require("../utils/redact-pii.js");
27
27
  const sendBAEventToSelf = (data) => {
28
28
  const redactedData = (0, import_redact_pii.redactPii)(data);
@@ -23,7 +23,7 @@ __export(user_session_event_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(user_session_event_exports);
25
25
  var import_index = require("./index.js");
26
- var import_web_analytics = require("./web-analytics.js");
26
+ var import_web_analytics = require("../utils/micro-frontend/scripting-objects/web-analytics.js");
27
27
  const loginEvent = ({
28
28
  instanceId,
29
29
  userId
package/dist/cjs/index.js CHANGED
@@ -233,5 +233,5 @@ var import_store3 = require("./data/store.js");
233
233
  var import_guest_with_service = require("./utils/guest-with-service.js");
234
234
  var import_appdynamics = require("./analytics/appdynamics.js");
235
235
  var import_analytics = require("./analytics/index.js");
236
- var import_web_analytics = require("./analytics/web-analytics.js");
236
+ var import_web_analytics = require("./utils/micro-frontend/scripting-objects/web-analytics.js");
237
237
  var import_redact_pii = require("./utils/redact-pii.js");
@@ -35,7 +35,7 @@ module.exports = __toCommonJS(app_config_exports);
35
35
  var import_lodash = __toESM(require("lodash"));
36
36
  var import_config = require("./config.js");
37
37
  var import_appdynamics = require("../../analytics/appdynamics.js");
38
- var import_web_analytics = require("../../analytics/web-analytics.js");
38
+ var import_web_analytics = require("../micro-frontend/scripting-objects/web-analytics.js");
39
39
  var import_window = require("../window.js");
40
40
  var import_config2 = require("./config.js");
41
41
  const parseAppConfig = (data) => {
@@ -40,7 +40,7 @@ var import_history2 = require("../history.js");
40
40
  var import_console_logger = require("../console-logger.js");
41
41
  var import_logger = require("../logger.js");
42
42
  var import_web_storage = require("../web-storage.js");
43
- var import_web_analytics = require("../../analytics/web-analytics.js");
43
+ var import_web_analytics = require("./scripting-objects/web-analytics.js");
44
44
  var import_appdynamics = require("../../analytics/appdynamics.js");
45
45
  var import_ssfguest_adapter = require("./ssfguest-adapter.js");
46
46
  const isCrossDomain = () => {
@@ -34,9 +34,9 @@ var import_console_logger = require("../console-logger.js");
34
34
  var import_logger = require("../logger.js");
35
35
  var import_constants = require("../constants.js");
36
36
  var import_window = require("../window.js");
37
- var import_analytics = require("../../analytics/index.js");
38
37
  var import_appdynamics = require("../../analytics/appdynamics.js");
39
- var import_web_analytics = require("../../analytics/web-analytics.js");
38
+ var import_analytics = require("./scripting-objects/analytics.js");
39
+ var import_web_analytics = require("./scripting-objects/web-analytics.js");
40
40
  var import_session = require("../session.js");
41
41
  class CMicroAppHost {
42
42
  static instance;
@@ -47,6 +47,8 @@ class CMicroAppHost {
47
47
  onInit;
48
48
  onRenewSessionTimer;
49
49
  scriptingObjects;
50
+ #ssfHostRef;
51
+ // eslint-disable-next-line max-statements
50
52
  constructor(params) {
51
53
  this.appId = (0, import_config.getAppConfigValue)("appId");
52
54
  this.onInit = params?.onInit;
@@ -59,7 +61,13 @@ class CMicroAppHost {
59
61
  theme: params?.theme ?? (0, import_pui_theme.getDefaultTheme)()
60
62
  };
61
63
  this.activeGuests = {};
62
- this.scriptingObjects = params?.scriptingObjects ?? {};
64
+ this.#ssfHostRef = params?.ssfHostRef || null;
65
+ const analyticsObj = new import_analytics.Analytics(this.logger);
66
+ this.scriptingObjects = {
67
+ analytics: analyticsObj,
68
+ ...params?.scriptingObjects ?? {}
69
+ };
70
+ this.#ssfHostRef?.publish(analyticsObj);
63
71
  this.getProps = this.getProps.bind(this);
64
72
  this.getLogger = this.getLogger.bind(this);
65
73
  this.getGuests = this.getGuests.bind(this);
@@ -165,7 +173,8 @@ class CMicroAppHost {
165
173
  this.props.systemVersion = version;
166
174
  }
167
175
  sendBAEvent(data) {
168
- (0, import_analytics.sendBAEvent)({ data, self: true });
176
+ this.scriptingObjects.analytics.sendBAEvent(data).catch(() => {
177
+ });
169
178
  }
170
179
  // eslint-disable-next-line @typescript-eslint/require-await
171
180
  async getObject(name) {
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var analytics_exports = {};
30
+ __export(analytics_exports, {
31
+ Analytics: () => Analytics
32
+ });
33
+ module.exports = __toCommonJS(analytics_exports);
34
+ var import_em_ssf_host = __toESM(require("@elliemae/em-ssf-host"));
35
+ var import_redact_pii = require("../../redact-pii.js");
36
+ var import_web_analytics = require("./web-analytics.js");
37
+ class Analytics extends import_em_ssf_host.default.ScriptingObject {
38
+ #logger;
39
+ constructor(logger) {
40
+ super("analytics");
41
+ this.#logger = logger;
42
+ this.#monitorPerformance();
43
+ }
44
+ /**
45
+ * monitor performance and report to GTM
46
+ */
47
+ #monitorPerformance = () => {
48
+ try {
49
+ const po = new PerformanceObserver((list) => {
50
+ for (const entry of list.getEntries()) {
51
+ switch (entry.entryType) {
52
+ case "measure":
53
+ this.sendBAEvent({
54
+ event: "performance",
55
+ name: entry.name,
56
+ duration: entry.duration.toString(),
57
+ startTime: new Date(
58
+ performance.timeOrigin + entry.startTime
59
+ ).toISOString()
60
+ }).catch(() => {
61
+ });
62
+ break;
63
+ default:
64
+ break;
65
+ }
66
+ }
67
+ });
68
+ po.observe({ type: "measure", buffered: true });
69
+ } catch (e) {
70
+ this.#logger.error({
71
+ message: "Error while recording performance",
72
+ exception: e
73
+ });
74
+ }
75
+ };
76
+ /**
77
+ * send business analytics event
78
+ * @param event business analytics event
79
+ * @returns promise
80
+ */
81
+ sendBAEvent = (event) => {
82
+ const eventEx = { ...(0, import_web_analytics.getBAEventParameters)(), ...event };
83
+ const redactedData = (0, import_redact_pii.redactPii)(eventEx);
84
+ window.gtmDataLayer = window.gtmDataLayer || [];
85
+ window.gtmDataLayer.push(redactedData);
86
+ return Promise.resolve();
87
+ };
88
+ /**
89
+ * start a performance mark
90
+ * @param name name of the performance mark
91
+ * @returns start performance mark
92
+ */
93
+ perfMarkStart = (name) => {
94
+ if (!name) throw new Error("name is required");
95
+ return Promise.resolve(performance.mark(name));
96
+ };
97
+ /**
98
+ * end a performance mark
99
+ * @param startMark start mark
100
+ * @returns promise
101
+ */
102
+ perfMarkEnd = (startMark) => {
103
+ if (!startMark) throw new Error("startMark is required");
104
+ performance.measure(startMark.name, { start: startMark.startTime });
105
+ return Promise.resolve();
106
+ };
107
+ }
@@ -1,5 +1,5 @@
1
1
  import { CMicroAppGuest } from "../utils/micro-frontend/guest.js";
2
- import { getBAEventParameters } from "./web-analytics.js";
2
+ import { getBAEventParameters } from "../utils/micro-frontend/scripting-objects/web-analytics.js";
3
3
  import { redactPii } from "../utils/redact-pii.js";
4
4
  const sendBAEventToSelf = (data) => {
5
5
  const redactedData = redactPii(data);
@@ -1,5 +1,5 @@
1
1
  import { sendBAEvent } from "./index.js";
2
- import { updateBAEventParameters } from "./web-analytics.js";
2
+ import { updateBAEventParameters } from "../utils/micro-frontend/scripting-objects/web-analytics.js";
3
3
  const loginEvent = ({
4
4
  instanceId,
5
5
  userId
package/dist/esm/index.js CHANGED
@@ -131,7 +131,7 @@ import { getStore } from "./data/store.js";
131
131
  import { RegisterService } from "./utils/guest-with-service.js";
132
132
  import { setAppDynamicsUserData } from "./analytics/appdynamics.js";
133
133
  import { sendBAEvent } from "./analytics/index.js";
134
- import { updateBAEventParameters } from "./analytics/web-analytics.js";
134
+ import { updateBAEventParameters } from "./utils/micro-frontend/scripting-objects/web-analytics.js";
135
135
  import { redactPii } from "./utils/redact-pii.js";
136
136
  export {
137
137
  AppRoot,
@@ -1,7 +1,7 @@
1
1
  import _ from "lodash";
2
2
  import { setAppConfig } from "./config.js";
3
3
  import { setAppDynamicsUserData } from "../../analytics/appdynamics.js";
4
- import { updateBAEventParameters } from "../../analytics/web-analytics.js";
4
+ import { updateBAEventParameters } from "../micro-frontend/scripting-objects/web-analytics.js";
5
5
  import { getAssetPath } from "../window.js";
6
6
  import { getAppConfigValue } from "./config.js";
7
7
  const parseAppConfig = (data) => {
@@ -7,7 +7,7 @@ import { browserHistory } from "../history.js";
7
7
  import { consoleLogger } from "../console-logger.js";
8
8
  import { setLogger } from "../logger.js";
9
9
  import { removeStorageEvents } from "../web-storage.js";
10
- import { updateBAEventParameters } from "../../analytics/web-analytics.js";
10
+ import { updateBAEventParameters } from "./scripting-objects/web-analytics.js";
11
11
  import { setAppDynamicsUserData } from "../../analytics/appdynamics.js";
12
12
  import { SSFGuestAdapter } from "./ssfguest-adapter.js";
13
13
  const isCrossDomain = () => {
@@ -18,9 +18,9 @@ import {
18
18
  getCurrentBreakpoint,
19
19
  getViewportSize as getWindowViewportSize
20
20
  } from "../window.js";
21
- import { sendBAEvent } from "../../analytics/index.js";
22
21
  import { setAppDynamicsUserData } from "../../analytics/appdynamics.js";
23
- import { updateBAEventParameters } from "../../analytics/web-analytics.js";
22
+ import { Analytics } from "./scripting-objects/analytics.js";
23
+ import { updateBAEventParameters } from "./scripting-objects/web-analytics.js";
24
24
  import { renewSession } from "../session.js";
25
25
  class CMicroAppHost {
26
26
  static instance;
@@ -31,6 +31,8 @@ class CMicroAppHost {
31
31
  onInit;
32
32
  onRenewSessionTimer;
33
33
  scriptingObjects;
34
+ #ssfHostRef;
35
+ // eslint-disable-next-line max-statements
34
36
  constructor(params) {
35
37
  this.appId = getAppConfigValue("appId");
36
38
  this.onInit = params?.onInit;
@@ -43,7 +45,13 @@ class CMicroAppHost {
43
45
  theme: params?.theme ?? getDefaultTheme()
44
46
  };
45
47
  this.activeGuests = {};
46
- this.scriptingObjects = params?.scriptingObjects ?? {};
48
+ this.#ssfHostRef = params?.ssfHostRef || null;
49
+ const analyticsObj = new Analytics(this.logger);
50
+ this.scriptingObjects = {
51
+ analytics: analyticsObj,
52
+ ...params?.scriptingObjects ?? {}
53
+ };
54
+ this.#ssfHostRef?.publish(analyticsObj);
47
55
  this.getProps = this.getProps.bind(this);
48
56
  this.getLogger = this.getLogger.bind(this);
49
57
  this.getGuests = this.getGuests.bind(this);
@@ -149,7 +157,8 @@ class CMicroAppHost {
149
157
  this.props.systemVersion = version;
150
158
  }
151
159
  sendBAEvent(data) {
152
- sendBAEvent({ data, self: true });
160
+ this.scriptingObjects.analytics.sendBAEvent(data).catch(() => {
161
+ });
153
162
  }
154
163
  // eslint-disable-next-line @typescript-eslint/require-await
155
164
  async getObject(name) {
@@ -0,0 +1,77 @@
1
+ import ssfHost from "@elliemae/em-ssf-host";
2
+ import { redactPii } from "../../redact-pii.js";
3
+ import { getBAEventParameters } from "./web-analytics.js";
4
+ class Analytics extends ssfHost.ScriptingObject {
5
+ #logger;
6
+ constructor(logger) {
7
+ super("analytics");
8
+ this.#logger = logger;
9
+ this.#monitorPerformance();
10
+ }
11
+ /**
12
+ * monitor performance and report to GTM
13
+ */
14
+ #monitorPerformance = () => {
15
+ try {
16
+ const po = new PerformanceObserver((list) => {
17
+ for (const entry of list.getEntries()) {
18
+ switch (entry.entryType) {
19
+ case "measure":
20
+ this.sendBAEvent({
21
+ event: "performance",
22
+ name: entry.name,
23
+ duration: entry.duration.toString(),
24
+ startTime: new Date(
25
+ performance.timeOrigin + entry.startTime
26
+ ).toISOString()
27
+ }).catch(() => {
28
+ });
29
+ break;
30
+ default:
31
+ break;
32
+ }
33
+ }
34
+ });
35
+ po.observe({ type: "measure", buffered: true });
36
+ } catch (e) {
37
+ this.#logger.error({
38
+ message: "Error while recording performance",
39
+ exception: e
40
+ });
41
+ }
42
+ };
43
+ /**
44
+ * send business analytics event
45
+ * @param event business analytics event
46
+ * @returns promise
47
+ */
48
+ sendBAEvent = (event) => {
49
+ const eventEx = { ...getBAEventParameters(), ...event };
50
+ const redactedData = redactPii(eventEx);
51
+ window.gtmDataLayer = window.gtmDataLayer || [];
52
+ window.gtmDataLayer.push(redactedData);
53
+ return Promise.resolve();
54
+ };
55
+ /**
56
+ * start a performance mark
57
+ * @param name name of the performance mark
58
+ * @returns start performance mark
59
+ */
60
+ perfMarkStart = (name) => {
61
+ if (!name) throw new Error("name is required");
62
+ return Promise.resolve(performance.mark(name));
63
+ };
64
+ /**
65
+ * end a performance mark
66
+ * @param startMark start mark
67
+ * @returns promise
68
+ */
69
+ perfMarkEnd = (startMark) => {
70
+ if (!startMark) throw new Error("startMark is required");
71
+ performance.measure(startMark.name, { start: startMark.startTime });
72
+ return Promise.resolve();
73
+ };
74
+ }
75
+ export {
76
+ Analytics
77
+ };
@@ -85,7 +85,7 @@ export { getStore } from './data/store.js';
85
85
  export { RegisterService } from './utils/guest-with-service.js';
86
86
  export { setAppDynamicsUserData } from './analytics/appdynamics.js';
87
87
  export { sendBAEvent } from './analytics/index.js';
88
- export { updateBAEventParameters } from './analytics/web-analytics.js';
88
+ export { updateBAEventParameters } from './utils/micro-frontend/scripting-objects/web-analytics.js';
89
89
  export { redactPii } from './utils/redact-pii.js';
90
90
  export type { EMUI } from './utils/window.js';
91
91
  export type { Await } from './utils/await.js';
@@ -1,6 +1,9 @@
1
+ /// <reference types="lib/typings/elliemae.js" />
1
2
  import { History, To } from 'history';
2
3
  import { DefaultTheme } from 'styled-components';
3
- import { IMicroAppHost, ResizeEventHandler, BreakpointChangeEventHandler, SubscriptionListener, BAEvent } from '@elliemae/pui-micro-frontend-base';
4
+ import { IMicroAppHost, ResizeEventHandler, BreakpointChangeEventHandler, SubscriptionListener } from '@elliemae/pui-micro-frontend-base';
5
+ import ssfHost from '@elliemae/em-ssf-host';
6
+ import { BAEvent } from '@elliemae/pui-scripting-object';
4
7
  import { MicroFrontEndLogger } from '../types.js';
5
8
  type HostOptions = {
6
9
  systemVersion: string;
@@ -16,8 +19,10 @@ type ConstructorParams = {
16
19
  scriptingObjects?: Record<string, any>;
17
20
  onRenewSessionTimer?: () => void;
18
21
  onInit?: OnInitCallback;
22
+ ssfHostRef?: typeof ssfHost.Host;
19
23
  };
20
24
  export declare class CMicroAppHost implements IMicroAppHost {
25
+ #private;
21
26
  private static instance;
22
27
  private readonly logger;
23
28
  private readonly appId;
@@ -54,7 +59,7 @@ export declare class CMicroAppHost implements IMicroAppHost {
54
59
  onResizeEvent(eventHandler: ResizeEventHandler): string;
55
60
  onBreakpointChangeEvent(eventHandler: BreakpointChangeEventHandler): string;
56
61
  setSystemVersion(version?: string): void;
57
- sendBAEvent(this: void, data: BAEvent): void;
62
+ sendBAEvent(data: BAEvent): void;
58
63
  getObject<T>(name: string): Promise<T>;
59
64
  }
60
65
  export {};
@@ -0,0 +1,29 @@
1
+ /// <reference types="lib/typings/elliemae.js" />
2
+ import ssfHost from '@elliemae/em-ssf-host';
3
+ import { IAnalytics, BAEvent } from '@elliemae/pui-scripting-object';
4
+ import { MicroFrontEndLogger } from '../../types.js';
5
+ /**
6
+ * Analytics scripting object
7
+ */
8
+ export declare class Analytics extends ssfHost.ScriptingObject implements IAnalytics {
9
+ #private;
10
+ constructor(logger: MicroFrontEndLogger);
11
+ /**
12
+ * send business analytics event
13
+ * @param event business analytics event
14
+ * @returns promise
15
+ */
16
+ sendBAEvent: (event: BAEvent) => Promise<void>;
17
+ /**
18
+ * start a performance mark
19
+ * @param name name of the performance mark
20
+ * @returns start performance mark
21
+ */
22
+ perfMarkStart: (name: string) => Promise<PerformanceMark>;
23
+ /**
24
+ * end a performance mark
25
+ * @param startMark start mark
26
+ * @returns promise
27
+ */
28
+ perfMarkEnd: (startMark: PerformanceMeasure) => Promise<void>;
29
+ }