@elliemae/pui-app-bridge 2.0.0-next.26 → 2.0.0-next.28

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 (52) hide show
  1. package/dist/cjs/config/app.js +35 -5
  2. package/dist/cjs/config/microFE.js +8 -3
  3. package/dist/cjs/index.html +1 -1
  4. package/dist/cjs/index.js +2 -2
  5. package/dist/cjs/loaders/script.js +13 -8
  6. package/dist/cjs/loaders/style.js +11 -6
  7. package/dist/cjs/{microAppFactory.js → microfeFactory.js} +99 -46
  8. package/dist/cjs/microfeHost.js +187 -0
  9. package/dist/cjs/tests/scriptingObjects/appraisalServiceModule.js +24 -19
  10. package/dist/cjs/tests/scriptingObjects/global.js +10 -5
  11. package/dist/esm/config/app.js +36 -5
  12. package/dist/esm/config/microFE.js +9 -3
  13. package/dist/esm/index.html +1 -1
  14. package/dist/esm/index.js +1 -1
  15. package/dist/esm/loaders/script.js +14 -8
  16. package/dist/esm/loaders/style.js +12 -6
  17. package/dist/esm/{microAppFactory.js → microfeFactory.js} +97 -43
  18. package/dist/esm/microfeHost.js +168 -0
  19. package/dist/esm/tests/scriptingObjects/appraisalServiceModule.js +25 -19
  20. package/dist/esm/tests/scriptingObjects/global.js +11 -5
  21. package/dist/public/frame.html +1 -1
  22. package/dist/public/index.html +1 -1
  23. package/dist/public/js/emuiAppBridge.0bdd77190acabd48390a.js +24 -0
  24. package/dist/public/js/emuiAppBridge.0bdd77190acabd48390a.js.br +0 -0
  25. package/dist/public/js/emuiAppBridge.0bdd77190acabd48390a.js.gz +0 -0
  26. package/dist/public/js/emuiAppBridge.0bdd77190acabd48390a.js.map +1 -0
  27. package/dist/public/utils.js.map +1 -1
  28. package/dist/types/config/app.d.ts +94 -0
  29. package/dist/types/index.d.ts +4 -3
  30. package/dist/types/microfeFactory.d.ts +87 -0
  31. package/dist/types/microfeHost.d.ts +111 -0
  32. package/dist/types/tests/server.d.ts +1 -1
  33. package/dist/types/tests/utils.d.ts +2 -2
  34. package/dist/types/typings/common.d.ts +26 -0
  35. package/dist/types/typings/guest.d.ts +78 -33
  36. package/dist/types/typings/host.d.ts +72 -46
  37. package/dist/types/window.d.ts +4 -4
  38. package/dist/umd/index.html +1 -1
  39. package/dist/umd/index.js +7 -7
  40. package/dist/umd/index.js.br +0 -0
  41. package/dist/umd/index.js.gz +0 -0
  42. package/dist/umd/index.js.map +1 -1
  43. package/dist/umd/utils.js.map +1 -1
  44. package/package.json +2 -2
  45. package/dist/cjs/microAppHost.js +0 -120
  46. package/dist/esm/microAppHost.js +0 -100
  47. package/dist/public/js/emuiAppBridge.20469d6f81dbac45a9e5.js +0 -24
  48. package/dist/public/js/emuiAppBridge.20469d6f81dbac45a9e5.js.br +0 -0
  49. package/dist/public/js/emuiAppBridge.20469d6f81dbac45a9e5.js.gz +0 -0
  50. package/dist/public/js/emuiAppBridge.20469d6f81dbac45a9e5.js.map +0 -1
  51. package/dist/types/microAppFactory.d.ts +0 -22
  52. package/dist/types/microAppHost.d.ts +0 -38
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
29
34
  var __accessCheck = (obj, member, msg) => {
30
35
  if (!member.has(obj))
31
36
  throw TypeError("Cannot " + msg);
@@ -66,10 +71,35 @@ class CAppConfig {
66
71
  delete data.env;
67
72
  __privateSet(this, _gAppConfig, (0, import_merge.default)(data, activeEnvConfig));
68
73
  });
69
- this.get = (key = "", defaultValue = null) => (0, import_clone.default)((0, import_get.default)(__privateGet(this, _gAppConfig), key, defaultValue));
70
- this.set = (key, value) => (0, import_set.default)(__privateGet(this, _gAppConfig), key, value);
71
- this.has = (key = "") => (0, import_has.default)(__privateGet(this, _gAppConfig), key);
72
- this.load = async (assetPath = "latest/") => {
74
+ /**
75
+ * Get value for the given app config key
76
+ *
77
+ * @param key key to get value for
78
+ * @param defaultValue default value to return if key is not found
79
+ * @returns value for the given key
80
+ */
81
+ __publicField(this, "get", (key = "", defaultValue = null) => (0, import_clone.default)((0, import_get.default)(__privateGet(this, _gAppConfig), key, defaultValue)));
82
+ /**
83
+ * Set value for the given app config key
84
+ *
85
+ * @param key key to set value for
86
+ * @param value value to set
87
+ * @returns app config instance
88
+ */
89
+ __publicField(this, "set", (key, value) => (0, import_set.default)(__privateGet(this, _gAppConfig), key, value));
90
+ /**
91
+ * Check if the given key exists in app config
92
+ *
93
+ * @param key key to check
94
+ * @returns true if key exists
95
+ */
96
+ __publicField(this, "has", (key = "") => (0, import_has.default)(__privateGet(this, _gAppConfig), key));
97
+ /**
98
+ * load application configuration from the given asset path
99
+ *
100
+ * @param assetPath url path to load app config from
101
+ */
102
+ __publicField(this, "load", async (assetPath = "latest/") => {
73
103
  const response = await fetch(
74
104
  `${assetPath.replace(/\/?$/, "/")}app.config.json`
75
105
  );
@@ -83,7 +113,7 @@ class CAppConfig {
83
113
  } else {
84
114
  throw new Error("Failed to load app config");
85
115
  }
86
- };
116
+ });
87
117
  }
88
118
  }
89
119
  _gAppConfig = new WeakMap();
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
29
34
  var __accessCheck = (obj, member, msg) => {
30
35
  if (!member.has(obj))
31
36
  throw TypeError("Cannot " + msg);
@@ -138,7 +143,7 @@ const getConfig = ({
138
143
  class CMicroFEConfig {
139
144
  constructor() {
140
145
  __privateAdd(this, _microFrontendApps, []);
141
- this.init = ({
146
+ __publicField(this, "init", ({
142
147
  version,
143
148
  appConfig
144
149
  }) => {
@@ -155,8 +160,8 @@ class CMicroFEConfig {
155
160
  });
156
161
  }
157
162
  ));
158
- };
159
- this.getConfigById = (id) => __privateGet(this, _microFrontendApps).find((app) => app.id === id);
163
+ });
164
+ __publicField(this, "getConfigById", (id) => __privateGet(this, _microFrontendApps).find((app) => app.id === id));
160
165
  }
161
166
  }
162
167
  _microFrontendApps = new WeakMap();
@@ -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.0.0-next.9/umd/index.js" ></script>
9
+ <script src="https://qa.assets.rd.elliemae.io/pui-diagnostics@3" ></script>
10
10
  </head>
11
11
  <body>
12
12
  <header class="bg-indigo-300 h-10 flex place-items-center">
package/dist/cjs/index.js CHANGED
@@ -18,10 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var lib_exports = {};
20
20
  __export(lib_exports, {
21
- CMicroAppFactory: () => import_microAppFactory.CMicroAppFactory,
21
+ CMicroAppFactory: () => import_microfeFactory.CMicroAppFactory,
22
22
  Event: () => import_em_ssf_common.Event,
23
23
  ScriptingObject: () => import_em_ssf_common.ScriptingObject
24
24
  });
25
25
  module.exports = __toCommonJS(lib_exports);
26
26
  var import_em_ssf_common = require("@elliemae/em-ssf-common");
27
- var import_microAppFactory = require("./microAppFactory.js");
27
+ var import_microfeFactory = require("./microfeFactory.js");
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var __accessCheck = (obj, member, msg) => {
20
25
  if (!member.has(obj))
21
26
  throw TypeError("Cannot " + msg);
@@ -48,7 +53,7 @@ const isDeferEligible = (scriptSrc) => !HEAD_SCRIPTS.test(scriptSrc);
48
53
  class ScriptLoader {
49
54
  constructor(logger) {
50
55
  __privateAdd(this, _logger, void 0);
51
- this.add = ({
56
+ __publicField(this, "add", ({
52
57
  name,
53
58
  hostUrl,
54
59
  documentEle,
@@ -71,8 +76,8 @@ class ScriptLoader {
71
76
  if (!(0, import_utils.isJSDOM)() && isDeferEligible(ele.src))
72
77
  ele.defer = true;
73
78
  documentEle.head.appendChild(ele);
74
- });
75
- this.remove = (elementId = "", documentEle = document) => new Promise((resolve) => {
79
+ }));
80
+ __publicField(this, "remove", (elementId = "", documentEle = document) => new Promise((resolve) => {
76
81
  const ele = documentEle.getElementById(elementId);
77
82
  if (!ele) {
78
83
  __privateGet(this, _logger).warn(`script with id ${elementId} not found`);
@@ -80,8 +85,8 @@ class ScriptLoader {
80
85
  }
81
86
  ele.remove();
82
87
  resolve();
83
- });
84
- this.removeDynamicImportedScripts = (hostUrl, documentEle) => {
88
+ }));
89
+ __publicField(this, "removeDynamicImportedScripts", (hostUrl, documentEle) => {
85
90
  const hostPattern = new RegExp(hostUrl, "i");
86
91
  const scriptElements = documentEle.getElementsByTagName("script");
87
92
  for (let index = scriptElements.length - 1; index >= 0; index -= 1) {
@@ -90,8 +95,8 @@ class ScriptLoader {
90
95
  if (hostPattern.test(src))
91
96
  scriptEle.remove();
92
97
  }
93
- };
94
- this.removePrefetchLinks = (hostUrl, documentEle) => {
98
+ });
99
+ __publicField(this, "removePrefetchLinks", (hostUrl, documentEle) => {
95
100
  const hostPattern = new RegExp(hostUrl, "i");
96
101
  const prefetchElements = documentEle.querySelectorAll('[rel="prefetch"]');
97
102
  for (let index = prefetchElements.length - 1; index >= 0; index -= 1) {
@@ -100,7 +105,7 @@ class ScriptLoader {
100
105
  if (hostPattern.test(href))
101
106
  ele.remove();
102
107
  }
103
- };
108
+ });
104
109
  __privateSet(this, _logger, logger);
105
110
  }
106
111
  }
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var __accessCheck = (obj, member, msg) => {
20
25
  if (!member.has(obj))
21
26
  throw TypeError("Cannot " + msg);
@@ -46,7 +51,7 @@ const APP_STYLE_ID_PREFIX = "ice-style-";
46
51
  class StyleLoader {
47
52
  constructor(logger) {
48
53
  __privateAdd(this, _logger, void 0);
49
- this.add = ({
54
+ __publicField(this, "add", ({
50
55
  name,
51
56
  hostUrl,
52
57
  documentEle,
@@ -67,8 +72,8 @@ class StyleLoader {
67
72
  );
68
73
  };
69
74
  documentEle.head.appendChild(ele);
70
- });
71
- this.remove = (elementId = "", documentEle = document) => new Promise((resolve) => {
75
+ }));
76
+ __publicField(this, "remove", (elementId = "", documentEle = document) => new Promise((resolve) => {
72
77
  const ele = documentEle.getElementById(elementId);
73
78
  if (!ele) {
74
79
  __privateGet(this, _logger).warn(`style with id ${elementId} not found`);
@@ -76,8 +81,8 @@ class StyleLoader {
76
81
  }
77
82
  ele.remove();
78
83
  resolve();
79
- });
80
- this.removeDynamicImportedStyles = (hostUrl, documentEle) => {
84
+ }));
85
+ __publicField(this, "removeDynamicImportedStyles", (hostUrl, documentEle) => {
81
86
  const hostPattern = new RegExp(hostUrl, "i");
82
87
  const prefetchElements = documentEle.querySelectorAll('[rel="stylesheet"]');
83
88
  for (let index = prefetchElements.length - 1; index >= 0; index -= 1) {
@@ -86,7 +91,7 @@ class StyleLoader {
86
91
  if (hostPattern.test(href))
87
92
  ele.remove();
88
93
  }
89
- };
94
+ });
90
95
  __privateSet(this, _logger, logger);
91
96
  }
92
97
  }
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
19
24
  var __accessCheck = (obj, member, msg) => {
20
25
  if (!member.has(obj))
21
26
  throw TypeError("Cannot " + msg);
@@ -34,22 +39,27 @@ var __privateSet = (obj, member, value, setter) => {
34
39
  setter ? setter.call(obj, value) : member.set(obj, value);
35
40
  return value;
36
41
  };
37
- var microAppFactory_exports = {};
38
- __export(microAppFactory_exports, {
42
+ var microfeFactory_exports = {};
43
+ __export(microfeFactory_exports, {
39
44
  CMicroAppFactory: () => CMicroAppFactory
40
45
  });
41
- module.exports = __toCommonJS(microAppFactory_exports);
46
+ module.exports = __toCommonJS(microfeFactory_exports);
42
47
  var import_frame = require("./frame.js");
43
48
  var import_window = require("./window.js");
44
49
  var import_app = require("./config/app.js");
45
50
  var import_microFE = require("./config/microFE.js");
46
51
  var import_loaders = require("./loaders/index.js");
47
- var import_microAppHost = require("./microAppHost.js");
52
+ var import_microfeHost = require("./microfeHost.js");
48
53
  var _logger, _scriptLoader, _styleLoader, _appConfig, _microFEConfig, _host, _activeGuests, _activeApps, _removeAssetsFromDOM, _addAppToActiveAppList, _waitAndInitApplication, _initApplication, _loadApp, _unloadApp, _mountApp, _unmountApp;
49
54
  const APP_CONTAINER_ID_PREFIX = "pui-app-container-";
50
55
  const cssType = /\.css$/;
51
56
  const isCss = (fileName) => cssType.test(fileName);
52
57
  class CMicroAppFactory {
58
+ /**
59
+ * Create a new instance of the MicroAppFactory
60
+ *
61
+ * @param {MicroAppFactoryParams} params - parameter for the constructor
62
+ */
53
63
  constructor(params) {
54
64
  __privateAdd(this, _logger, void 0);
55
65
  __privateAdd(this, _scriptLoader, void 0);
@@ -193,17 +203,81 @@ class CMicroAppFactory {
193
203
  containerId: `${APP_CONTAINER_ID_PREFIX}${id}`
194
204
  });
195
205
  });
196
- this.getGuests = () => Array.from(__privateGet(this, _activeGuests).values());
197
- this.getGuest = (guestId) => __privateGet(this, _activeGuests).get(guestId);
198
- this.init = async () => {
206
+ /**
207
+ * Close all active guest micro frontend applications
208
+ */
209
+ __publicField(this, "closeAllApps", async () => {
210
+ await Promise.all(Object.keys(__privateGet(this, _activeApps)).map(this.closeApp));
211
+ });
212
+ /**
213
+ * Close guest micro frontend application
214
+ *
215
+ * @param id unique id of guest application
216
+ */
217
+ __publicField(this, "closeApp", async (id) => {
218
+ if (!id)
219
+ throw new Error("id is required");
220
+ const appConfig = __privateGet(this, _microFEConfig).getConfigById(id);
221
+ if (!appConfig) {
222
+ throw new Error(`Application with id ${id} is not found`);
223
+ }
224
+ const { name, hostUrl } = appConfig;
225
+ try {
226
+ await __privateGet(this, _unmountApp).call(this, { id, name });
227
+ } finally {
228
+ const frameEle = import_frame.Frame.get(id);
229
+ if (!frameEle?.contentDocument) {
230
+ throw new Error(`Iframe for application with id ${id} is not found`);
231
+ }
232
+ __privateGet(this, _unloadApp).call(this, { id, hostUrl, documentEle: frameEle.contentDocument });
233
+ import_frame.Frame.remove(id);
234
+ }
235
+ });
236
+ /**
237
+ * Get guest by id
238
+ *
239
+ * @param guestId unique id of guest
240
+ * @returns guest instance
241
+ */
242
+ __publicField(this, "getGuest", (guestId) => __privateGet(this, _activeGuests).get(guestId));
243
+ /**
244
+ * Get list of active guests
245
+ *
246
+ * @returns list of active guests
247
+ */
248
+ __publicField(this, "getGuests", () => Array.from(__privateGet(this, _activeGuests).values()));
249
+ /**
250
+ * Initialize factory
251
+ */
252
+ __publicField(this, "init", async () => {
199
253
  await __privateGet(this, _appConfig).load();
200
254
  __privateGet(this, _microFEConfig).init({
201
255
  version: __privateGet(this, _host).version,
202
256
  appConfig: __privateGet(this, _appConfig)
203
257
  });
204
- };
205
- this.openApp = async (options) => {
206
- const { id, frameOptions, history, theme } = options;
258
+ });
259
+ /**
260
+ * Mount guest micro frontend application into DOM
261
+ *
262
+ * @param id unique id of guest micro frontend application
263
+ * @throws Error if application with given id is not found in configuration
264
+ */
265
+ __publicField(this, "mountApp", async (id) => {
266
+ if (!id)
267
+ throw new Error("id is required");
268
+ const appConfig = __privateGet(this, _microFEConfig).getConfigById(id);
269
+ if (!appConfig) {
270
+ throw new Error(`Application with id ${id} is not found`);
271
+ }
272
+ await __privateGet(this, _mountApp).call(this, appConfig);
273
+ });
274
+ /**
275
+ * Open guest micro frontend application
276
+ *
277
+ * @param {OpenAppParams} params - options to open guest application
278
+ */
279
+ __publicField(this, "openApp", async (params) => {
280
+ const { id, frameOptions, history, theme } = params;
207
281
  const appConfig = __privateGet(this, _microFEConfig).getConfigById(id);
208
282
  if (!appConfig) {
209
283
  throw new Error(`Application with id ${id} is not found`);
@@ -233,36 +307,14 @@ class CMicroAppFactory {
233
307
  import_frame.Frame.remove(id);
234
308
  throw err;
235
309
  }
236
- };
237
- this.closeApp = async (id) => {
238
- if (!id)
239
- throw new Error("id is required");
240
- const appConfig = __privateGet(this, _microFEConfig).getConfigById(id);
241
- if (!appConfig) {
242
- throw new Error(`Application with id ${id} is not found`);
243
- }
244
- const { name, hostUrl } = appConfig;
245
- try {
246
- await __privateGet(this, _unmountApp).call(this, { id, name });
247
- } finally {
248
- const frameEle = import_frame.Frame.get(id);
249
- if (!frameEle?.contentDocument) {
250
- throw new Error(`Iframe for application with id ${id} is not found`);
251
- }
252
- __privateGet(this, _unloadApp).call(this, { id, hostUrl, documentEle: frameEle.contentDocument });
253
- import_frame.Frame.remove(id);
254
- }
255
- };
256
- this.mountApp = async (id) => {
257
- if (!id)
258
- throw new Error("id is required");
259
- const appConfig = __privateGet(this, _microFEConfig).getConfigById(id);
260
- if (!appConfig) {
261
- throw new Error(`Application with id ${id} is not found`);
262
- }
263
- await __privateGet(this, _mountApp).call(this, appConfig);
264
- };
265
- this.unmountApp = async (id) => {
310
+ });
311
+ /**
312
+ * Unmount guest micro frontend application from DOM
313
+ *
314
+ * @param id unique id of guest micro frontend application
315
+ * @throws Error if application with given id is not found in configuration
316
+ */
317
+ __publicField(this, "unmountApp", async (id) => {
266
318
  if (!id)
267
319
  throw new Error("id is required");
268
320
  const appConfig = __privateGet(this, _microFEConfig).getConfigById(id);
@@ -270,19 +322,20 @@ class CMicroAppFactory {
270
322
  throw new Error(`Application with id ${id} is not found`);
271
323
  }
272
324
  await __privateGet(this, _unmountApp).call(this, appConfig);
273
- };
274
- this.closeAllApps = async () => {
275
- await Promise.all(Object.keys(__privateGet(this, _activeApps)).map(this.closeApp));
276
- };
325
+ });
277
326
  const { logger } = params;
278
327
  if (!logger)
279
328
  throw new Error("logger is required");
280
329
  __privateSet(this, _logger, params.logger);
281
330
  __privateSet(this, _scriptLoader, new import_loaders.ScriptLoader(logger));
282
331
  __privateSet(this, _styleLoader, new import_loaders.StyleLoader(logger));
283
- __privateSet(this, _host, new import_microAppHost.CMicroAppHost(params));
332
+ __privateSet(this, _host, new import_microfeHost.CMicroFEHost(params));
284
333
  }
285
- // public api
334
+ /**
335
+ * Get instance of host
336
+ *
337
+ * @returns instance of host
338
+ */
286
339
  get host() {
287
340
  return __privateGet(this, _host);
288
341
  }
@@ -0,0 +1,187 @@
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+ var __accessCheck = (obj, member, msg) => {
25
+ if (!member.has(obj))
26
+ throw TypeError("Cannot " + msg);
27
+ };
28
+ var __privateGet = (obj, member, getter) => {
29
+ __accessCheck(obj, member, "read from private field");
30
+ return getter ? getter.call(obj) : member.get(obj);
31
+ };
32
+ var __privateAdd = (obj, member, value) => {
33
+ if (member.has(obj))
34
+ throw TypeError("Cannot add the same private member more than once");
35
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
36
+ };
37
+ var __privateSet = (obj, member, value, setter) => {
38
+ __accessCheck(obj, member, "write to private field");
39
+ setter ? setter.call(obj, value) : member.set(obj, value);
40
+ return value;
41
+ };
42
+ var microfeHost_exports = {};
43
+ __export(microfeHost_exports, {
44
+ CMicroFEHost: () => CMicroFEHost
45
+ });
46
+ module.exports = __toCommonJS(microfeHost_exports);
47
+ var import_pubsub_js = require("pubsub-js");
48
+ var import_em_ssf_common = require("@elliemae/em-ssf-common");
49
+ var import_frame = require("./frame.js");
50
+ var import_constant = require("./constant.js");
51
+ var _logger, _version, _eventManager, _scriptingObjects;
52
+ class CMicroFEHost {
53
+ /**
54
+ * Create new instance of the host frontend application
55
+ *
56
+ * @param {CMicroFEHostParams} params - constructor parameters
57
+ */
58
+ constructor(params) {
59
+ __privateAdd(this, _logger, void 0);
60
+ __privateAdd(this, _version, void 0);
61
+ __privateAdd(this, _eventManager, void 0);
62
+ __privateAdd(this, _scriptingObjects, /* @__PURE__ */ new Map());
63
+ /**
64
+ * add listener to the scripting object event
65
+ *
66
+ * @param {AddEventListenerParams<EventId, EventType>} params - parameters to add event listener
67
+ * @returns subscription id
68
+ */
69
+ __publicField(this, "addEventListener", (params) => __privateGet(this, _eventManager).subscribe(params));
70
+ /**
71
+ * registers scripting object to the host
72
+ *
73
+ * @param so scripting object to publish
74
+ */
75
+ __publicField(this, "addScriptingObject", (so) => {
76
+ if (!so?.id || !so?._toJSON) {
77
+ throw new Error("Object is not derived from ScriptingObject");
78
+ }
79
+ const objectId = so.id.toLowerCase();
80
+ if (objectId === "module")
81
+ throw new Error(
82
+ "Do not publish the module object. Create a concrete object derived from it."
83
+ );
84
+ if (__privateGet(this, _scriptingObjects).has(objectId))
85
+ throw new Error(`Scripting Object ${so.id} already exists`);
86
+ __privateGet(this, _scriptingObjects).set(objectId, so);
87
+ });
88
+ /**
89
+ * dispatch event to guest microfrontend application
90
+ *
91
+ * @param {DispatchEventParams<EventId, Params>} params - event parameters
92
+ */
93
+ __publicField(this, "dispatchEvent", async (params) => __privateGet(this, _eventManager).dispatchEvent(params));
94
+ /**
95
+ * Get reference to the scripting object (or proxy) by name
96
+ *
97
+ * @param name unique name of the scripting object
98
+ * @param objectId
99
+ * @returns scripting object reference
100
+ */
101
+ __publicField(this, "getObject", (objectId) => {
102
+ const id = objectId.toLowerCase();
103
+ const data = __privateGet(this, _scriptingObjects).get(id);
104
+ return Promise.resolve(data || null);
105
+ });
106
+ /**
107
+ * removes listener from the scripting object event
108
+ *
109
+ * @param {RemoveEventListenerParams<EventId>} params - parameters to remove event listener
110
+ */
111
+ __publicField(this, "removeEventListener", (params) => {
112
+ __privateGet(this, _eventManager).unsubscribe(params);
113
+ });
114
+ /**
115
+ * remove all listeners
116
+ */
117
+ __publicField(this, "removeAllEventListeners", () => {
118
+ __privateGet(this, _eventManager).unsubscribeAll();
119
+ });
120
+ /**
121
+ * removes scripting object from the host
122
+ *
123
+ * @param objectId unique id of the scripting object
124
+ */
125
+ __publicField(this, "removeScriptingObject", (objectId) => {
126
+ __privateGet(this, _scriptingObjects).delete(
127
+ objectId.toLowerCase()
128
+ );
129
+ });
130
+ /**
131
+ * set the size of the guest application iframe window
132
+ *
133
+ * @param {AppWindowSize} appSize window size of the application
134
+ */
135
+ __publicField(this, "setAppWindowSize", (appSize) => {
136
+ const { appId, size } = appSize;
137
+ const frameEle = document.getElementById(
138
+ `${import_frame.FRAME_CONTAINER_ID_PREFIX}${appId}`
139
+ );
140
+ if (frameEle) {
141
+ frameEle.style.height = `${size.height}px`;
142
+ }
143
+ });
144
+ // deprecated legacy eventing methods (to be removed)
145
+ /**
146
+ * emit event to all subscribers (deprecated)
147
+ *
148
+ * @param eventId unique id of the event. The format is <scripting object name>.<event name>
149
+ * @param data data to be sent to the subscribers of the event
150
+ * @returns true if event is published successfully
151
+ */
152
+ __publicField(this, "publish", (eventId, data) => (0, import_pubsub_js.publish)(eventId, data));
153
+ /**
154
+ * subscribe to an scripting object event (deprecated)
155
+ *
156
+ * @param eventId unique id of the event. The format is <scripting object name>.<event name>
157
+ * @param listener callback function to be called when the event is fired
158
+ * @returns token to be used to unsubscribe
159
+ */
160
+ // eslint-disable-next-line @typescript-eslint/ban-types
161
+ __publicField(this, "subscribe", (eventId, listener) => (0, import_pubsub_js.subscribe)(eventId, listener));
162
+ /**
163
+ * unsubscribe from an scripting object event (deprecated)
164
+ *
165
+ * @param token unique token returned by subscribe
166
+ * @param eventId unique id of the event. The format is <scripting object name>.<event name>
167
+ */
168
+ __publicField(this, "unsubscribe", (token) => {
169
+ (0, import_pubsub_js.unsubscribe)(token);
170
+ });
171
+ __privateSet(this, _logger, params.logger);
172
+ __privateSet(this, _version, params?.version || import_constant.LATEST_VERSION);
173
+ __privateSet(this, _eventManager, new import_em_ssf_common.EventManager());
174
+ }
175
+ /**
176
+ * application release version
177
+ *
178
+ * @returns release version
179
+ */
180
+ get version() {
181
+ return __privateGet(this, _version);
182
+ }
183
+ }
184
+ _logger = new WeakMap();
185
+ _version = new WeakMap();
186
+ _eventManager = new WeakMap();
187
+ _scriptingObjects = new WeakMap();