@elliemae/pui-app-bridge 2.9.9 → 2.17.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.
Files changed (115) hide show
  1. package/dist/cjs/appBridge.js +380 -93
  2. package/dist/cjs/appRegistry.js +136 -0
  3. package/dist/cjs/config/app.js +15 -2
  4. package/dist/cjs/config/microFE.js +3 -3
  5. package/dist/cjs/eventManager.js +16 -16
  6. package/dist/cjs/frame.html +2 -2
  7. package/dist/cjs/frame.js +39 -14
  8. package/dist/cjs/index.html +1 -1
  9. package/dist/cjs/loaders/script.js +5 -5
  10. package/dist/cjs/loaders/style.js +1 -0
  11. package/dist/cjs/microfeHost.js +51 -31
  12. package/dist/cjs/tests/flights/23.1/app.checksum1.js +25 -24
  13. package/dist/cjs/tests/flights/latest/app.checksum.js +25 -24
  14. package/dist/cjs/tests/hotels/23.1/app.checksum.js +27 -24
  15. package/dist/cjs/tests/hotels/latest/app.checksum.js +27 -24
  16. package/dist/cjs/tests/loan/latest/index.js +49 -57
  17. package/dist/cjs/tests/scriptingObjects/analytics.js +7 -7
  18. package/dist/cjs/tests/scriptingObjects/appraisalServiceModule.js +8 -8
  19. package/dist/cjs/tests/scriptingObjects/global.js +1 -2
  20. package/dist/cjs/tests/task/latest/index.dev.js +29 -28
  21. package/dist/cjs/tests/task/latest/index.js +29 -28
  22. package/dist/cjs/tests/travelhub/23.1/app.checksum.js +24 -26
  23. package/dist/cjs/tests/travelhub/23.1/landing.checksum1.js +5 -7
  24. package/dist/cjs/utils.js +31 -1
  25. package/dist/esm/appBridge.js +390 -95
  26. package/dist/esm/appRegistry.js +116 -0
  27. package/dist/esm/config/app.js +15 -2
  28. package/dist/esm/config/microFE.js +3 -3
  29. package/dist/esm/eventManager.js +16 -16
  30. package/dist/esm/frame.html +2 -2
  31. package/dist/esm/frame.js +29 -14
  32. package/dist/esm/index.html +1 -1
  33. package/dist/esm/loaders/script.js +5 -5
  34. package/dist/esm/loaders/style.js +1 -0
  35. package/dist/esm/microfeHost.js +55 -31
  36. package/dist/esm/tests/flights/23.1/app.checksum1.js +25 -24
  37. package/dist/esm/tests/flights/latest/app.checksum.js +25 -24
  38. package/dist/esm/tests/hotels/23.1/app.checksum.js +27 -24
  39. package/dist/esm/tests/hotels/latest/app.checksum.js +27 -24
  40. package/dist/esm/tests/loan/latest/index.js +49 -57
  41. package/dist/esm/tests/scriptingObjects/analytics.js +7 -7
  42. package/dist/esm/tests/scriptingObjects/appraisalServiceModule.js +8 -8
  43. package/dist/esm/tests/scriptingObjects/global.js +1 -2
  44. package/dist/esm/tests/task/latest/index.dev.js +29 -28
  45. package/dist/esm/tests/task/latest/index.js +29 -28
  46. package/dist/esm/tests/travelhub/23.1/app.checksum.js +24 -26
  47. package/dist/esm/tests/travelhub/23.1/landing.checksum1.js +5 -7
  48. package/dist/esm/utils.js +31 -1
  49. package/dist/public/assets/frame.671d9de68be598da64ca.html +47 -0
  50. package/dist/public/creditService/latest/creditService.checksum.js.gz +0 -0
  51. package/dist/public/frame.html +1 -1
  52. package/dist/public/guest/businessObjects.js.gz +0 -0
  53. package/dist/public/guest/util.js.gz +0 -0
  54. package/dist/public/index.html +1 -1
  55. package/dist/public/init.js.gz +0 -0
  56. package/dist/public/js/emuiAppBridge.2993b666256d6dd7148d.js +51 -0
  57. package/dist/public/js/emuiAppBridge.2993b666256d6dd7148d.js.br +0 -0
  58. package/dist/public/js/emuiAppBridge.2993b666256d6dd7148d.js.gz +0 -0
  59. package/dist/public/js/emuiAppBridge.2993b666256d6dd7148d.js.map +1 -0
  60. package/dist/public/loan-object.js +1 -1
  61. package/dist/public/loan-object.js.br +0 -0
  62. package/dist/public/loan-object.js.gz +0 -0
  63. package/dist/public/loan-object.js.map +1 -1
  64. package/dist/public/loanValidation/latest/loanValidation.checksum.js.gz +0 -0
  65. package/dist/public/pricingService/latest/pricingService.checksum.js.gz +0 -0
  66. package/dist/public/utils.js.gz +0 -0
  67. package/dist/types/lib/appBridge.d.ts +38 -28
  68. package/dist/types/lib/appRegistry.d.ts +41 -0
  69. package/dist/types/lib/eventManager.d.ts +4 -4
  70. package/dist/types/lib/frame.d.ts +45 -4
  71. package/dist/types/lib/index.d.ts +3 -3
  72. package/dist/types/lib/loaders/script.d.ts +2 -1
  73. package/dist/types/lib/microfeHost.d.ts +15 -25
  74. package/dist/types/lib/tests/flights/23.1/app.checksum1.d.ts +7 -0
  75. package/dist/types/lib/tests/flights/latest/app.checksum.d.ts +7 -0
  76. package/dist/types/lib/tests/hotels/23.1/app.checksum.d.ts +7 -0
  77. package/dist/types/lib/tests/hotels/latest/app.checksum.d.ts +7 -0
  78. package/dist/types/lib/tests/loan/latest/index.d.ts +11 -0
  79. package/dist/types/lib/tests/scriptingObjects/analytics.d.ts +3 -3
  80. package/dist/types/lib/tests/scriptingObjects/appraisalServiceModule.d.ts +2 -1
  81. package/dist/types/lib/tests/task/latest/index.d.ts +10 -0
  82. package/dist/types/lib/tests/task/latest/index.dev.d.ts +10 -0
  83. package/dist/types/lib/tests/travelhub/23.1/app.checksum.d.ts +7 -0
  84. package/dist/types/lib/tests/travelhub/23.1/landing.checksum1.d.ts +2 -0
  85. package/dist/types/lib/typings/appInfo.d.ts +1 -0
  86. package/dist/types/lib/typings/common.d.ts +0 -66
  87. package/dist/types/lib/typings/guest.d.ts +10 -3
  88. package/dist/types/lib/typings/host.d.ts +32 -32
  89. package/dist/types/lib/typings/window.d.ts +6 -1
  90. package/dist/types/lib/utils.d.ts +7 -0
  91. package/dist/types/tsconfig.tsbuildinfo +1 -1
  92. package/dist/umd/671d9de68be598da64ca.html +47 -0
  93. package/dist/umd/creditService/latest/creditService.checksum.js.gz +0 -0
  94. package/dist/umd/frame.html +1 -1
  95. package/dist/umd/guest/businessObjects.js.gz +0 -0
  96. package/dist/umd/guest/util.js.gz +0 -0
  97. package/dist/umd/index.html +1 -1
  98. package/dist/umd/index.js +35 -9
  99. package/dist/umd/index.js.br +0 -0
  100. package/dist/umd/index.js.gz +0 -0
  101. package/dist/umd/index.js.map +1 -1
  102. package/dist/umd/init.js.gz +0 -0
  103. package/dist/umd/loan-object.js +1 -1
  104. package/dist/umd/loan-object.js.br +0 -0
  105. package/dist/umd/loan-object.js.gz +0 -0
  106. package/dist/umd/loan-object.js.map +1 -1
  107. package/dist/umd/loanValidation/latest/loanValidation.checksum.js.gz +0 -0
  108. package/dist/umd/pricingService/latest/pricingService.checksum.js.gz +0 -0
  109. package/dist/umd/utils.js.gz +0 -0
  110. package/package.json +9 -12
  111. package/dist/public/js/emuiAppBridge.530390c3bb03f32357f7.js +0 -25
  112. package/dist/public/js/emuiAppBridge.530390c3bb03f32357f7.js.br +0 -0
  113. package/dist/public/js/emuiAppBridge.530390c3bb03f32357f7.js.gz +0 -0
  114. package/dist/public/js/emuiAppBridge.530390c3bb03f32357f7.js.map +0 -1
  115. package/dist/types/lib/tests/pubsubAPI.test.d.ts +0 -1
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var appRegistry_exports = {};
20
+ __export(appRegistry_exports, {
21
+ CAppRegistry: () => CAppRegistry
22
+ });
23
+ module.exports = __toCommonJS(appRegistry_exports);
24
+ class CAppRegistry {
25
+ constructor() {
26
+ if (!window.emui) {
27
+ window.emui = {};
28
+ }
29
+ window.emui.registerApp = this.#registerApp;
30
+ }
31
+ /**
32
+ * global method for guest apps to register themselves with parent
33
+ * @param param0
34
+ * @param param0.appId
35
+ * @param param0.app
36
+ */
37
+ #registerApp = ({ appId, app }) => {
38
+ if (!app?.uuid) throw new Error("application uuid is required");
39
+ window.emui[appId] = window.emui[appId] || [];
40
+ if (Array.isArray(window.emui[appId])) {
41
+ const appIndex = window.emui[appId].findIndex(
42
+ (eApp) => eApp.uuid === app.uuid
43
+ );
44
+ if (appIndex > -1) {
45
+ window.emui[appId][appIndex] = app;
46
+ } else {
47
+ window.emui[appId].push(app);
48
+ }
49
+ } else {
50
+ let existingApp = window.emui[appId];
51
+ if (existingApp?.uuid === app.uuid) {
52
+ existingApp = { ...existingApp, ...app };
53
+ window.emui[appId] = [existingApp];
54
+ } else if (typeof existingApp.init === void 0) {
55
+ window.emui[appId] = [{ ...existingApp, ...app }];
56
+ } else {
57
+ window.emui[appId] = [window.emui[appId], app];
58
+ }
59
+ }
60
+ };
61
+ /**
62
+ * get micro app guest from window object
63
+ * @param param0 id and uuid
64
+ * @param param0.id app id
65
+ * @param param0.uuid unique instance id
66
+ * @param param0.instanceId
67
+ * @returns micro app guest
68
+ */
69
+ get = ({ id, instanceId }) => {
70
+ const apps = window.emui?.[id];
71
+ if (Array.isArray(apps)) {
72
+ const app = apps.find((eApp) => eApp.uuid === instanceId);
73
+ return app ?? null;
74
+ }
75
+ if (apps?.uuid === instanceId) {
76
+ return apps;
77
+ }
78
+ return null;
79
+ };
80
+ /**
81
+ * add app to global emui window variable
82
+ * @param id.id
83
+ * @param id app id
84
+ * @param instanceId unique instance id
85
+ * @param id.instanceId
86
+ * @param id.documentEle
87
+ */
88
+ add = ({
89
+ id,
90
+ instanceId,
91
+ documentEle
92
+ }) => {
93
+ const newAppInstance = {
94
+ uuid: instanceId,
95
+ init: null,
96
+ mount: null,
97
+ unmount: null
98
+ };
99
+ const appInstances = window.emui[id];
100
+ if (appInstances) {
101
+ if (!instanceId) {
102
+ throw new Error(
103
+ `Application ${id} is already loaded. uuid is required to load multiple instances of the same app`
104
+ );
105
+ }
106
+ if (Array.isArray(appInstances)) {
107
+ appInstances.push(newAppInstance);
108
+ } else {
109
+ window.emui[id] = [appInstances, newAppInstance];
110
+ }
111
+ } else {
112
+ window.emui[id] = [newAppInstance];
113
+ }
114
+ if (documentEle.defaultView) {
115
+ documentEle.defaultView.emui = documentEle.defaultView.emui ?? {};
116
+ documentEle.defaultView.emui.uuid = instanceId;
117
+ }
118
+ };
119
+ /**
120
+ * delete app from global emui window variable
121
+ * @param id.id app id
122
+ * @param id.instanceId unique instance id
123
+ * @param id.id.id
124
+ * @param id.id.instanceId
125
+ */
126
+ delete = ({ id, instanceId }) => {
127
+ if (Array.isArray(window.emui[id])) {
128
+ const index = window.emui[id].findIndex(
129
+ (app) => app.uuid === instanceId
130
+ );
131
+ if (index > -1) window.emui[id].splice(index, 1);
132
+ } else {
133
+ delete window.emui[id];
134
+ }
135
+ };
136
+ }
@@ -73,14 +73,27 @@ class CAppConfig {
73
73
  * @returns true if key exists
74
74
  */
75
75
  has = (key = "") => (0, import_has.default)(this.#gAppConfig, key);
76
+ /**
77
+ * add version to the base url
78
+ * @returns versioned base url
79
+ */
80
+ #getVersionedBaseUrl = () => {
81
+ const regex = /(?:\/)(\d+\.\d+|latest)(?:\/?)?$/;
82
+ if (!regex.test(this.#baseUrl)) {
83
+ const majorMinorVersion = this.#version.match(/^(?:\d+\.\d+)*/g);
84
+ return (0, import_utils.appendTrailingSlash)(
85
+ `${this.#baseUrl}${majorMinorVersion?.[0] || import_constant.LATEST_VERSION}`
86
+ );
87
+ }
88
+ return this.#baseUrl;
89
+ };
76
90
  /**
77
91
  * load application configuration from the given asset path
78
92
  * @param assetPath url path to load app config from
79
93
  * @param configUrl
80
94
  */
81
95
  load = async (configUrl) => {
82
- const majorMinorVersion = this.#version.match(/^(?:\d+\.\d+)*/g);
83
- const appConfigUrl = configUrl ?? `${this.#baseUrl}${majorMinorVersion && majorMinorVersion[0] || import_constant.LATEST_VERSION}/app.config.json`;
96
+ const appConfigUrl = configUrl ?? `${this.#getVersionedBaseUrl()}app.config.json`;
84
97
  const response = await fetch(appConfigUrl);
85
98
  if (response.ok) {
86
99
  try {
@@ -102,7 +102,8 @@ const getConfig = ({
102
102
  name: id,
103
103
  mode: "production",
104
104
  manifestPath: "./{SYSTEM_VERSION}/",
105
- securityContext: import_common.SecurityContext.USER
105
+ securityContext: import_common.SecurityContext.USER,
106
+ isJsModule: true
106
107
  },
107
108
  config,
108
109
  envConfig
@@ -123,8 +124,7 @@ class CMicroFEConfig {
123
124
  appConfig
124
125
  }) => {
125
126
  const mfeAppsFromConfig = appConfig.get(CONFIG_KEY);
126
- if (!mfeAppsFromConfig)
127
- throw new Error("app.config.json is missing microFrontendApps section");
127
+ if (!mfeAppsFromConfig) return;
128
128
  this.#microFrontendApps = Object.keys(mfeAppsFromConfig).map(
129
129
  (appId) => {
130
130
  validate(appId, mfeAppsFromConfig[appId]);
@@ -93,17 +93,19 @@ class EventManager {
93
93
  };
94
94
  /**
95
95
  * dispatch an event
96
+ * @param scriptingObject
96
97
  * @param {DispatchEventParam<EventId, Params>} param - parameters for dispatching an event
97
98
  */
98
- dispatchEvent = async (param) => {
99
+ dispatchEvent = async (scriptingObject, param) => {
99
100
  const {
100
- event: { id, name, requiresFeedback, scriptingObject },
101
+ event: { id, name },
101
102
  eventParams,
102
- feedbackWaitTime = 1e3
103
+ eventOptions
103
104
  } = param;
105
+ const { timeout } = eventOptions ?? {};
104
106
  if (!id) throw new Error("Event Id is required");
105
107
  const listeners = this.#listeners.get(id) || [];
106
- if (!requiresFeedback) {
108
+ if (!timeout || timeout <= 0) {
107
109
  this.#emitEvent({
108
110
  eventName: name,
109
111
  scriptingObject,
@@ -117,7 +119,7 @@ class EventManager {
117
119
  eventName: name,
118
120
  scriptingObject,
119
121
  eventParams,
120
- feedbackWaitTime
122
+ feedbackWaitTime: timeout
121
123
  });
122
124
  };
123
125
  /**
@@ -125,30 +127,28 @@ class EventManager {
125
127
  * @param {SubscribeParam<EventId, AppEvents[EventId]>} param - parameters for subscribing to an event
126
128
  */
127
129
  subscribe = (param) => {
128
- const { eventId, listener } = param;
130
+ const { eventId, callback } = param;
129
131
  if (!eventId) throw new Error("eventId is required");
130
- if (!listener) throw new Error("Listener is required");
132
+ if (!callback) throw new Error("Callback is required");
131
133
  const listeners = this.#listeners.get(eventId) || [];
132
- const subscriptionId = (0, import_uuid.v4)();
134
+ const token = (0, import_uuid.v4)();
133
135
  listeners.push({
134
- subscriptionId,
135
- callback: listener
136
+ token,
137
+ callback
136
138
  });
137
139
  this.#listeners.set(eventId, listeners);
138
- return subscriptionId;
140
+ return token;
139
141
  };
140
142
  /**
141
143
  * Unsubscribe from an event
142
144
  * @param {UnsubscribeParam<EventId>} param - parameters for unsubscribing from an event
143
145
  */
144
146
  unsubscribe = (param) => {
145
- const { eventId, subscriptionId } = param;
147
+ const { eventId, token } = param;
146
148
  if (!eventId) throw new Error("eventId id is required");
147
- if (subscriptionId) {
149
+ if (token) {
148
150
  const listeners = this.#listeners.get(eventId) || [];
149
- const index = listeners.findIndex(
150
- (listener) => listener.subscriptionId === subscriptionId
151
- );
151
+ const index = listeners.findIndex((listener) => listener.token === token);
152
152
  if (index > -1) {
153
153
  listeners.splice(index, 1);
154
154
  this.#listeners.set(eventId, listeners);
@@ -6,7 +6,7 @@
6
6
  <meta name="mobile-web-app-capable" content="yes" />
7
7
  <link rel="icon" href="/favicon.ico" />
8
8
  <title>Application</title>
9
- <script>
9
+ <script nonce="__CSP_NONCE__">
10
10
  (function (i, s, o, g, r, a, m) {
11
11
  i['GoogleAnalyticsObject'] = r;
12
12
  (i[r] =
@@ -27,7 +27,7 @@
27
27
  'ga',
28
28
  );
29
29
  </script>
30
- <style>
30
+ <style nonce="__CSP_NONCE__">
31
31
  .full-width {
32
32
  width: 100%;
33
33
  }
package/dist/cjs/frame.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,34 +17,53 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
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
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var frame_exports = {};
20
30
  __export(frame_exports, {
21
31
  FRAME_APP_CONTAINER_ID_PREFIX: () => FRAME_APP_CONTAINER_ID_PREFIX,
22
- FRAME_CONTAINER_ID_PREFIX: () => FRAME_CONTAINER_ID_PREFIX,
23
32
  Frame: () => Frame
24
33
  });
25
34
  module.exports = __toCommonJS(frame_exports);
26
- const FRAME_CONTAINER_ID_PREFIX = "pui-iframe-container-";
35
+ var import_frame = __toESM(require("./frame.html?resource"), 1);
27
36
  const FRAME_APP_CONTAINER_ID_PREFIX = "pui-app-container-";
28
- const create = (appId, options) => new Promise((resolve, reject) => {
37
+ const create = ({
38
+ id,
39
+ instanceId,
40
+ manifestPath,
41
+ hostUrl,
42
+ options
43
+ }) => new Promise((resolve, reject) => {
29
44
  const iframeContainer = document.createElement("div");
30
45
  iframeContainer.setAttribute(
31
46
  "style",
32
47
  "display: flex;width: 100%;height: 100%;flex-direction: column;overflow: hidden;"
33
48
  );
34
49
  const frame = document.createElement("iframe");
35
- frame.setAttribute("id", `${FRAME_CONTAINER_ID_PREFIX}${appId}`);
50
+ frame.setAttribute("id", instanceId);
51
+ frame.setAttribute("data-testid", id);
36
52
  frame.setAttribute("title", options.title);
37
53
  frame.setAttribute("allowfullscreen", "true");
38
54
  frame.setAttribute("allowtransparency", "true");
39
- frame.setAttribute("allow", "microphone; camera");
55
+ if (options.permissionPolicy)
56
+ frame.setAttribute("allow", options.permissionPolicy);
40
57
  if (options.sandbox) frame.setAttribute("sandbox", options.sandbox);
41
58
  frame.setAttribute(
42
59
  "style",
43
60
  options.style ?? "flex-grow: 1;border: none;margin: 0;padding: 0;display: block;min-width: 100%;height: 100%;"
44
61
  );
45
- frame.setAttribute("src", options.src ?? "./frame.html");
62
+ frame.setAttribute(
63
+ "src",
64
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
65
+ options.src ?? (import_frame.default.default ?? import_frame.default)
66
+ );
46
67
  frame.addEventListener("load", () => {
47
68
  if (!frame.contentDocument) {
48
69
  reject(new Error("Frame content window is null"));
@@ -51,7 +72,15 @@ const create = (appId, options) => new Promise((resolve, reject) => {
51
72
  const documentEle = frame.contentDocument;
52
73
  const ele = documentEle.getElementById(FRAME_APP_CONTAINER_ID_PREFIX);
53
74
  if (ele) {
54
- ele.id = `${ele.id}${appId}`;
75
+ ele.id = `${ele.id}${id}`;
76
+ }
77
+ let baseTag = documentEle.getElementsByTagName("base")?.[0];
78
+ if (baseTag) {
79
+ baseTag.href = new URL(manifestPath, hostUrl).href;
80
+ } else {
81
+ baseTag = documentEle.createElement("base");
82
+ baseTag.href = new URL(manifestPath, hostUrl).href;
83
+ documentEle.getElementsByTagName("head")[0].appendChild(baseTag);
55
84
  }
56
85
  resolve(frame);
57
86
  });
@@ -60,13 +89,9 @@ const create = (appId, options) => new Promise((resolve, reject) => {
60
89
  const parentElement = document.getElementById(containerId ?? "") ?? document.body;
61
90
  parentElement.appendChild(iframeContainer);
62
91
  });
63
- const get = (appId) => document.getElementById(
64
- `${FRAME_CONTAINER_ID_PREFIX}${appId}`
65
- );
66
- const remove = (appId) => {
67
- const frameEle = document.getElementById(
68
- `${FRAME_CONTAINER_ID_PREFIX}${appId}`
69
- );
92
+ const get = (instanceId) => document.getElementById(instanceId);
93
+ const remove = (instanceId) => {
94
+ const frameEle = get(instanceId);
70
95
  if (frameEle) {
71
96
  frameEle.remove();
72
97
  }
@@ -6,7 +6,7 @@
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Host</title>
8
8
  <script src="https://cdn.tailwindcss.com?plugins=forms"></script>
9
- <script src="https://qa.assets.rd.elliemae.io/pui-diagnostics@3" ></script>
9
+ <script src="https://cdn.qa1.ice.com/pui-diagnostics@3" ></script>
10
10
  </head>
11
11
  <body>
12
12
  <header class="bg-indigo-300 h-10 flex place-items-center">
@@ -24,8 +24,6 @@ __export(script_exports, {
24
24
  module.exports = __toCommonJS(script_exports);
25
25
  var import_utils = require("../utils.js");
26
26
  const APP_SCRIPT_ID_PREFIX = "ice-script-";
27
- const HEAD_SCRIPTS = /(?:emuiDiagnostics|global|global-prod|emuiUserMonitoring)(?:..*)?.js/;
28
- const isDeferEligible = (scriptSrc) => !HEAD_SCRIPTS.test(scriptSrc);
29
27
  class ScriptLoader {
30
28
  #logger;
31
29
  constructor(logger) {
@@ -36,12 +34,16 @@ class ScriptLoader {
36
34
  hostUrl,
37
35
  documentEle,
38
36
  fileName,
39
- index
37
+ index,
38
+ isJsModule = true
40
39
  }) => new Promise((resolve, reject) => {
41
40
  const url = new URL(fileName, hostUrl);
42
41
  const ele = documentEle.createElement("script");
43
42
  ele.id = `${APP_SCRIPT_ID_PREFIX}${name.toLowerCase()}-${index}`;
44
43
  ele.src = (0, import_utils.removeDoubleSlash)(url.href);
44
+ ele.nonce = "__CSP_NONCE__";
45
+ if (!(0, import_utils.isJSDOM)() && isJsModule) ele.type = "module";
46
+ else ele.async = false;
45
47
  ele.onload = resolve.bind(null, ele.id);
46
48
  ele.onerror = (err) => {
47
49
  reject(
@@ -50,8 +52,6 @@ class ScriptLoader {
50
52
  })
51
53
  );
52
54
  };
53
- ele.async = false;
54
- if (!(0, import_utils.isJSDOM)() && isDeferEligible(ele.src)) ele.defer = true;
55
55
  documentEle.head.appendChild(ele);
56
56
  });
57
57
  remove = (elementId = "", documentEle = document) => new Promise((resolve) => {
@@ -38,6 +38,7 @@ class StyleLoader {
38
38
  }) => new Promise((resolve, reject) => {
39
39
  const ele = documentEle.createElement("link");
40
40
  ele.id = `${APP_STYLE_ID_PREFIX}${name.toLowerCase()}-${index}`;
41
+ ele.nonce = "__CSP_NONCE__";
41
42
  ele.rel = "stylesheet";
42
43
  const url = new URL(fileName, hostUrl);
43
44
  ele.href = (0, import_utils.removeDoubleSlash)(url.href);
@@ -21,11 +21,14 @@ __export(microfeHost_exports, {
21
21
  CMicroFEHost: () => CMicroFEHost
22
22
  });
23
23
  module.exports = __toCommonJS(microfeHost_exports);
24
- var import_pubsub_js = require("pubsub-js");
25
- var import_frame = require("./frame.js");
24
+ var import_microfe_common = require("@elliemae/microfe-common");
26
25
  var import_constant = require("./constant.js");
27
26
  class CMicroFEHost {
28
27
  #logger;
28
+ /**
29
+ * unique id of the iframe container
30
+ */
31
+ #containerId;
29
32
  #guest;
30
33
  #version;
31
34
  #soManager;
@@ -37,16 +40,11 @@ class CMicroFEHost {
37
40
  constructor(params) {
38
41
  this.#guest = params.guest;
39
42
  this.#logger = params.logger;
43
+ this.#containerId = params.containerId;
40
44
  this.#version = params?.version || import_constant.LATEST_VERSION;
41
45
  this.#soManager = params.soManager;
42
46
  this.#eventManager = params.eventManager;
43
47
  }
44
- /**
45
- * add listener to the scripting object event
46
- * @param {SubscribeParam<EventId, EventListener>} params - parameters to add event listener
47
- * @returns subscription id
48
- */
49
- addEventListener = (params) => this.#eventManager.subscribe(params);
50
48
  /**
51
49
  * application release version
52
50
  * @returns release version
@@ -60,42 +58,64 @@ class CMicroFEHost {
60
58
  * @param objectId
61
59
  * @returns scripting object reference
62
60
  */
63
- getObject = (objectId) => Promise.resolve(this.#soManager.getObject(objectId, this.#guest));
64
- /**
65
- * removes listener from the scripting object event
66
- * @param {UnsubscribeParam<EventId>} params - parameters to remove event listener
67
- */
68
- removeEventListener = (params) => {
69
- this.#eventManager.unsubscribe(params);
61
+ getObject = (objectId) => {
62
+ const so = this.#soManager.getObject(objectId, this.#guest);
63
+ if (so) {
64
+ const proxy = new import_microfe_common.ScriptingObjectProxy(so.id, so.objectType);
65
+ Object.keys(so).forEach((propName) => {
66
+ const propValue = so[propName];
67
+ if (propValue instanceof import_microfe_common.Event) {
68
+ Object.defineProperty(proxy, propName, {
69
+ value: new import_microfe_common.Event({
70
+ name: propName,
71
+ objectId: so.id
72
+ }),
73
+ enumerable: true
74
+ });
75
+ } else if ((0, import_microfe_common.isPublicFunction)(propValue, propName)) {
76
+ Object.defineProperty(proxy, propName, {
77
+ value: (...args) => {
78
+ Object.defineProperty(propValue, "callContext", {
79
+ value: { guest: this.#guest },
80
+ configurable: true,
81
+ enumerable: true,
82
+ writable: true
83
+ });
84
+ return so[propName](
85
+ ...args
86
+ );
87
+ },
88
+ enumerable: true
89
+ });
90
+ }
91
+ });
92
+ return Promise.resolve(proxy);
93
+ }
94
+ return Promise.resolve(null);
70
95
  };
71
96
  /**
72
97
  * set the size of the guest application iframe window
73
98
  * @param {AppWindowSize} appSize window size of the application
74
99
  */
75
100
  setAppWindowSize = (appSize) => {
76
- const { appId, size } = appSize;
77
- const frameEle = document.getElementById(
78
- `${import_frame.FRAME_CONTAINER_ID_PREFIX}${appId}`
79
- );
101
+ if (!this.#containerId) return;
102
+ const { size } = appSize;
103
+ const frameEle = document.getElementById(this.#containerId);
80
104
  if (frameEle) {
81
105
  frameEle.style.height = `${size.height}px`;
82
106
  }
83
107
  };
84
- // deprecated legacy eventing methods (to be removed)
85
108
  /**
86
- * subscribe to an scripting object event (deprecated)
87
- * @param eventId unique id of the event. The format is [scripting object name].[event name]
88
- * @param listener callback function to be called when the event is fired
89
- * @returns token to be used to unsubscribe
109
+ * add listener to the scripting object event
110
+ * @param {SubscribeParam<EventId, EventListener>} params - parameters to add event listener
111
+ * @returns subscription id
90
112
  */
91
- // eslint-disable-next-line @typescript-eslint/ban-types
92
- subscribe = (eventId, listener) => (0, import_pubsub_js.subscribe)(eventId, listener);
113
+ subscribe = (params) => this.#eventManager.subscribe(params);
93
114
  /**
94
- * unsubscribe from an scripting object event (deprecated)
95
- * @param token unique token returned by subscribe
96
- * @param eventId unique id of the event. The format is [scripting object name].[event name]
115
+ * removes listener from the scripting object event
116
+ * @param {UnsubscribeParam<EventId>} params - parameters to remove event listener
97
117
  */
98
- unsubscribe = (token) => {
99
- (0, import_pubsub_js.unsubscribe)(token);
118
+ unsubscribe = (params) => {
119
+ this.#eventManager.unsubscribe(params);
100
120
  };
101
121
  }
@@ -1,28 +1,27 @@
1
1
  "use strict";
2
- (function() {
3
- const appId = "flights";
4
- const appName = "Flights App";
5
- const getWindow = () => {
6
- try {
7
- window.parent.document;
8
- return window.parent;
9
- } catch (err) {
10
- return window;
11
- }
12
- };
13
- let host = null;
14
- let parentHistory = null;
15
- let logger = null;
16
- const browserWindow = getWindow();
17
- browserWindow.emui = browserWindow.emui || {};
18
- browserWindow.emui[appId] = browserWindow.emui[appId] || {};
19
- browserWindow.emui[appId].init = async (options) => {
2
+ const appId = "flights";
3
+ const appName = "Flights App";
4
+ const getWindow = () => {
5
+ try {
6
+ window.parent.document;
7
+ return window.parent;
8
+ } catch (err) {
9
+ return window;
10
+ }
11
+ };
12
+ let host = null;
13
+ let parentHistory = null;
14
+ let logger = null;
15
+ window.emui = window.emui || { uuid: crypto.randomUUID() };
16
+ window.emui.app = {
17
+ uuid: window.emui.uuid,
18
+ init: async (options) => {
20
19
  host = options.host;
21
20
  parentHistory = options.history;
22
21
  logger = options.logger;
23
22
  return Promise.resolve();
24
- };
25
- browserWindow.emui[appId].mount = async () => {
23
+ },
24
+ mount: async () => {
26
25
  const mainElement = document.createElement("main");
27
26
  const pageHeaderEle = document.createElement("h1");
28
27
  pageHeaderEle.textContent = appName;
@@ -34,10 +33,12 @@
34
33
  mainElement.appendChild(versionEle);
35
34
  document.body.appendChild(mainElement);
36
35
  return Promise.resolve();
37
- };
38
- browserWindow.emui[appId].unmount = () => {
36
+ },
37
+ unmount: () => {
39
38
  const mainEle = document.getElementsByTagName("main")[0];
40
39
  if (mainEle) mainEle.remove();
41
40
  return Promise.resolve();
42
- };
43
- })();
41
+ }
42
+ };
43
+ const browserWindow = getWindow();
44
+ browserWindow.emui?.registerApp?.({ appId, app: window.emui.app });