@elliemae/microfe-common 2.24.0 → 2.26.0-alpha.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 (79) hide show
  1. package/dist/cjs/app.js +33 -0
  2. package/dist/cjs/auditThrottler.js +60 -0
  3. package/dist/cjs/config.js +65 -0
  4. package/dist/cjs/frame.html +47 -0
  5. package/dist/cjs/frame.js +61 -0
  6. package/dist/cjs/history.js +27 -0
  7. package/dist/cjs/host.js +105 -0
  8. package/dist/cjs/index.js +2 -0
  9. package/dist/cjs/loader.js +158 -0
  10. package/dist/cjs/logRecords.js +57 -0
  11. package/dist/cjs/logger.js +34 -0
  12. package/dist/cjs/manifestLoader.js +66 -0
  13. package/dist/cjs/scriptLoader.js +71 -0
  14. package/dist/cjs/styleLoader.js +57 -0
  15. package/dist/cjs/tests/loan/latest/index.js +80 -0
  16. package/dist/cjs/tests/loan/latest/manifest.json +3 -0
  17. package/dist/cjs/tests/server.js +29 -0
  18. package/dist/cjs/tests/serverHandlers.js +81 -0
  19. package/dist/cjs/tests/task/latest/index.js +58 -0
  20. package/dist/cjs/tests/task/latest/manifest.json +3 -0
  21. package/dist/cjs/typings/guest.js +16 -0
  22. package/dist/cjs/typings/host.js +16 -0
  23. package/dist/cjs/typings/index.js +16 -0
  24. package/dist/cjs/typings/microapp.js +16 -0
  25. package/dist/cjs/utils.js +33 -0
  26. package/dist/cjs/window.js +63 -0
  27. package/dist/esm/app.js +13 -0
  28. package/dist/esm/auditThrottler.js +40 -0
  29. package/dist/esm/config.js +35 -0
  30. package/dist/esm/frame.html +47 -0
  31. package/dist/esm/frame.js +41 -0
  32. package/dist/esm/history.js +7 -0
  33. package/dist/esm/host.js +85 -0
  34. package/dist/esm/index.js +2 -0
  35. package/dist/esm/loader.js +145 -0
  36. package/dist/esm/logRecords.js +37 -0
  37. package/dist/esm/logger.js +17 -0
  38. package/dist/esm/manifestLoader.js +46 -0
  39. package/dist/esm/scriptLoader.js +51 -0
  40. package/dist/esm/styleLoader.js +37 -0
  41. package/dist/esm/tests/loan/latest/index.js +79 -0
  42. package/dist/esm/tests/loan/latest/manifest.json +3 -0
  43. package/dist/esm/tests/server.js +9 -0
  44. package/dist/esm/tests/serverHandlers.js +51 -0
  45. package/dist/esm/tests/task/latest/index.js +57 -0
  46. package/dist/esm/tests/task/latest/manifest.json +3 -0
  47. package/dist/esm/typings/guest.js +0 -0
  48. package/dist/esm/typings/host.js +0 -0
  49. package/dist/esm/typings/index.js +0 -0
  50. package/dist/esm/typings/microapp.js +0 -0
  51. package/dist/esm/utils.js +13 -0
  52. package/dist/esm/window.js +43 -0
  53. package/dist/types/lib/app.d.ts +2 -0
  54. package/dist/types/lib/auditThrottler.d.ts +29 -0
  55. package/dist/types/lib/config.d.ts +25 -0
  56. package/dist/types/lib/frame.d.ts +10 -0
  57. package/dist/types/lib/history.d.ts +2 -0
  58. package/dist/types/lib/host.d.ts +42 -0
  59. package/dist/types/lib/index.d.ts +2 -0
  60. package/dist/types/lib/loader.d.ts +9 -0
  61. package/dist/types/lib/logRecords.d.ts +14 -0
  62. package/dist/types/lib/logger.d.ts +1 -0
  63. package/dist/types/lib/manifestLoader.d.ts +7 -0
  64. package/dist/types/lib/scriptLoader.d.ts +6 -0
  65. package/dist/types/lib/styleLoader.d.ts +5 -0
  66. package/dist/types/lib/tests/auditThrottler.test.d.ts +1 -0
  67. package/dist/types/lib/tests/loader.test.d.ts +1 -0
  68. package/dist/types/lib/tests/loan/latest/index.d.ts +0 -0
  69. package/dist/types/lib/tests/server.d.ts +1 -0
  70. package/dist/types/lib/tests/serverHandlers.d.ts +1 -0
  71. package/dist/types/lib/tests/task/latest/index.d.ts +0 -0
  72. package/dist/types/lib/typings/guest.d.ts +67 -0
  73. package/dist/types/lib/typings/host.d.ts +60 -0
  74. package/dist/types/lib/typings/index.d.ts +3 -0
  75. package/dist/types/lib/typings/microapp.d.ts +17 -0
  76. package/dist/types/lib/utils.d.ts +3 -0
  77. package/dist/types/lib/window.d.ts +27 -0
  78. package/dist/types/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +7 -3
@@ -0,0 +1,33 @@
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 app_exports = {};
20
+ __export(app_exports, {
21
+ launchMicroApp: () => launchMicroApp
22
+ });
23
+ module.exports = __toCommonJS(app_exports);
24
+ var import_frame = require("./frame.js");
25
+ var import_loader = require("./loader.js");
26
+ const launchMicroApp = async (appConfig) => {
27
+ const frameEle = await (0, import_frame.createFrame)({ id: appConfig.id });
28
+ if (!frameEle?.contentDocument)
29
+ throw new Error("unable to create iframe for the microapp");
30
+ appConfig.documentEle = frameEle.contentDocument;
31
+ await (0, import_loader.loadApp)(appConfig);
32
+ await (0, import_loader.mountApp)(appConfig);
33
+ };
@@ -0,0 +1,60 @@
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 auditThrottler_exports = {};
20
+ __export(auditThrottler_exports, {
21
+ AuditThrottler: () => AuditThrottler
22
+ });
23
+ module.exports = __toCommonJS(auditThrottler_exports);
24
+ class AuditThrottler {
25
+ #logger;
26
+ #enabled;
27
+ #throttleMs;
28
+ #lastAudited = /* @__PURE__ */ new Map();
29
+ static DEFAULT_THROTTLE_MS = 1e4;
30
+ constructor(options) {
31
+ this.#logger = options.logger;
32
+ this.#enabled = options.enabled ?? true;
33
+ this.#throttleMs = options.throttleMs ?? AuditThrottler.DEFAULT_THROTTLE_MS;
34
+ }
35
+ get enabled() {
36
+ return this.#enabled;
37
+ }
38
+ /**
39
+ * Log a high-frequency operation. When audit is enabled and the throttle
40
+ * window allows it the payload is sent at `audit` level; otherwise `debug`.
41
+ * @param {string} key - dedup key for throttling (e.g. `invoke:loan.getField`)
42
+ * @param {LogRecord} payload - structured log payload
43
+ */
44
+ log(key, payload) {
45
+ if (!this.#enabled) {
46
+ this.#logger.debug(payload);
47
+ return;
48
+ }
49
+ if (this.#throttleMs > 0) {
50
+ const now = performance.now();
51
+ const last = this.#lastAudited.get(key);
52
+ if (last !== void 0 && now - last < this.#throttleMs) {
53
+ this.#logger.debug(payload);
54
+ return;
55
+ }
56
+ this.#lastAudited.set(key, now);
57
+ }
58
+ this.#logger.audit(payload);
59
+ }
60
+ }
@@ -0,0 +1,65 @@
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 config_exports = {};
30
+ __export(config_exports, {
31
+ getAppConfigValue: () => getAppConfigValue,
32
+ hasItem: () => hasItem,
33
+ loadAppConfig: () => loadAppConfig,
34
+ setAppConfig: () => setAppConfig,
35
+ setAppConfigValue: () => setAppConfigValue
36
+ });
37
+ module.exports = __toCommonJS(config_exports);
38
+ var import_lodash = __toESM(require("lodash"), 1);
39
+ var import_app_config = __toESM(require("./app.config.json"), 1);
40
+ var import_window = require("./window.js");
41
+ let gAppConfig = import_app_config.default;
42
+ const setAppConfig = (config) => {
43
+ gAppConfig = config;
44
+ };
45
+ const getAppConfigValue = (key = "", defaultValue = null) => import_lodash.default.clone(import_lodash.default.get(gAppConfig, key, defaultValue));
46
+ const setAppConfigValue = (key, value) => import_lodash.default.set(gAppConfig, key, value);
47
+ const hasItem = (key = "") => import_lodash.default.has(gAppConfig, key);
48
+ const parseAppConfig = (data) => {
49
+ const { activeEnv } = data;
50
+ const activeEnvConfig = data.env[activeEnv] || {};
51
+ if (data.env) delete data.env;
52
+ setAppConfig(import_lodash.default.merge(data, activeEnvConfig));
53
+ };
54
+ const loadAppConfig = (assetPath = "") => new Promise((resolve, reject) => {
55
+ fetch(`${assetPath || (0, import_window.getAssetPath)()}app.config.json`).then((response) => response.json()).then(({ data }) => {
56
+ parseAppConfig(data);
57
+ resolve();
58
+ }).catch((err) => {
59
+ reject(
60
+ new Error(
61
+ `Unable to load application configurtion file. ${err.Message}`
62
+ )
63
+ );
64
+ });
65
+ });
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="mobile-web-app-capable" content="yes" />
7
+ <link rel="icon" href="/favicon.ico" />
8
+ <title>Application</title>
9
+ <script>
10
+ (function (i, s, o, g, r, a, m) {
11
+ i['GoogleAnalyticsObject'] = r;
12
+ (i[r] =
13
+ i[r] ||
14
+ function () {
15
+ (i[r].q = i[r].q || []).push(arguments);
16
+ }),
17
+ (i[r].l = 1 * new Date());
18
+ (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
19
+ a.async = 1;
20
+ a.src = g;
21
+ m.parentNode.insertBefore(a, m);
22
+ })(
23
+ window,
24
+ document,
25
+ 'script',
26
+ 'https://www.google-analytics.com/analytics.js',
27
+ 'ga',
28
+ );
29
+ </script>
30
+ <style>
31
+ .full-width {
32
+ width: 100%;
33
+ }
34
+ .full-height {
35
+ height: 100%;
36
+ }
37
+ </style>
38
+ </head>
39
+ <body class="full-width full-height">
40
+ <noscript
41
+ >If you're seeing this message, that means
42
+ <strong>JavaScript has been disabled on your browser</strong>, please
43
+ <strong>enable JS</strong> to make this app work.</noscript
44
+ >
45
+ <div id="pui-app-container-" class="full-width full-height"></div>
46
+ </body>
47
+ </html>
@@ -0,0 +1,61 @@
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 frame_exports = {};
20
+ __export(frame_exports, {
21
+ FRAME_APP_CONTAINER_ID_PREFIX: () => FRAME_APP_CONTAINER_ID_PREFIX,
22
+ FRAME_CONTAINER_ID_PREFIX: () => FRAME_CONTAINER_ID_PREFIX,
23
+ createFrame: () => createFrame
24
+ });
25
+ module.exports = __toCommonJS(frame_exports);
26
+ const FRAME_CONTAINER_ID_PREFIX = "pui-iframe-container-";
27
+ const FRAME_APP_CONTAINER_ID_PREFIX = "pui-app-container-";
28
+ const createFrame = (options) => new Promise((resolve, reject) => {
29
+ const parentContainer = document.createElement("div");
30
+ parentContainer.setAttribute(
31
+ "style",
32
+ "display: flex;width: 100%;height: 100%;flex-direction: column;overflow: hidden;"
33
+ );
34
+ const frame = document.createElement("iframe");
35
+ frame.setAttribute("id", `${FRAME_CONTAINER_ID_PREFIX}${options.id}`);
36
+ frame.setAttribute("frameborder", "0");
37
+ frame.setAttribute("scrolling", "no");
38
+ frame.setAttribute("allowfullscreen", "true");
39
+ frame.setAttribute("allowtransparency", "true");
40
+ frame.setAttribute("allow", "microphone; camera");
41
+ if (options.sandbox) frame.setAttribute("sandbox", options.sandbox);
42
+ frame.setAttribute(
43
+ "style",
44
+ options.style ?? "flex-grow: 1;border: none;margin: 0;padding: 0;display: block;height: 100%;"
45
+ );
46
+ frame.setAttribute("src", options.src ?? "./frame.html");
47
+ frame.addEventListener("load", () => {
48
+ if (!frame.contentDocument) {
49
+ reject(new Error("Frame content window is null"));
50
+ return;
51
+ }
52
+ const documentEle = frame.contentDocument;
53
+ const ele = documentEle.getElementById(FRAME_APP_CONTAINER_ID_PREFIX);
54
+ if (ele) {
55
+ ele.id = `${ele.id}${options.id}`;
56
+ }
57
+ resolve(frame);
58
+ });
59
+ parentContainer.appendChild(frame);
60
+ document.body.appendChild(parentContainer);
61
+ });
@@ -0,0 +1,27 @@
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 history_exports = {};
20
+ __export(history_exports, {
21
+ browserHistory: () => browserHistory,
22
+ memoryHistory: () => memoryHistory
23
+ });
24
+ module.exports = __toCommonJS(history_exports);
25
+ var import_history = require("history");
26
+ const browserHistory = (0, import_history.createBrowserHistory)();
27
+ const memoryHistory = (0, import_history.createMemoryHistory)();
@@ -0,0 +1,105 @@
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 host_exports = {};
20
+ __export(host_exports, {
21
+ CMicroAppHost: () => CMicroAppHost
22
+ });
23
+ module.exports = __toCommonJS(host_exports);
24
+ var import_pubsub_js = require("pubsub-js");
25
+ var import_pui_theme = require("@elliemae/pui-theme");
26
+ var import_frame = require("./frame.js");
27
+ var import_config = require("./config.js");
28
+ var import_history2 = require("./history.js");
29
+ var import_logger = require("./logger.js");
30
+ class CMicroAppHost {
31
+ static instance;
32
+ logger;
33
+ appId;
34
+ props;
35
+ activeGuests;
36
+ onInit;
37
+ onRenewSessionTimer;
38
+ scriptingObjects;
39
+ constructor(params) {
40
+ this.appId = (0, import_config.getAppConfigValue)("appId");
41
+ this.onInit = params?.onInit;
42
+ this.logger = params?.logger || import_logger.logger;
43
+ this.onRenewSessionTimer = params?.onRenewSessionTimer;
44
+ this.props = {
45
+ systemVersion: params?.version ?? "latest",
46
+ history: params?.history ?? import_history2.browserHistory,
47
+ theme: params?.theme ?? (0, import_pui_theme.getDefaultTheme)()
48
+ };
49
+ this.activeGuests = {};
50
+ this.scriptingObjects = params?.scriptingObjects ?? {};
51
+ this.getProps = this.getProps.bind(this);
52
+ this.getLogger = this.getLogger.bind(this);
53
+ this.getGuests = this.getGuests.bind(this);
54
+ this.getGuest = this.getGuest.bind(this);
55
+ this.getObject = this.getObject.bind(this);
56
+ (0, import_config.loadAppConfig)().then(() => {
57
+ if (this.onInit) this.onInit(this.props);
58
+ }).catch(() => {
59
+ });
60
+ }
61
+ static getInstance(params) {
62
+ if (!this.instance) {
63
+ this.instance = new this(params);
64
+ }
65
+ return this.instance;
66
+ }
67
+ static isInitialized() {
68
+ return !!this.instance;
69
+ }
70
+ getProps() {
71
+ return this.props;
72
+ }
73
+ getLogger() {
74
+ return this.logger;
75
+ }
76
+ // eslint-disable-next-line @typescript-eslint/require-await
77
+ async getObject(name) {
78
+ return this.scriptingObjects[name];
79
+ }
80
+ getGuests() {
81
+ return this.activeGuests;
82
+ }
83
+ getGuest(id) {
84
+ return this.activeGuests[id] ? this.activeGuests[id] : null;
85
+ }
86
+ setAppWindowSize(appSize) {
87
+ const { appId, size } = appSize;
88
+ const frameEle = document.getElementById(
89
+ `${import_frame.FRAME_CONTAINER_ID_PREFIX}${appId}`
90
+ );
91
+ if (frameEle) {
92
+ frameEle.style.height = `${size.height}px`;
93
+ }
94
+ }
95
+ publish(eventId, data) {
96
+ return (0, import_pubsub_js.publish)(eventId, data);
97
+ }
98
+ // eslint-disable-next-line @typescript-eslint/ban-types
99
+ subscribe(eventId, listener) {
100
+ return (0, import_pubsub_js.subscribe)(eventId, listener);
101
+ }
102
+ unsubscribe(token) {
103
+ (0, import_pubsub_js.unsubscribe)(token);
104
+ }
105
+ }
package/dist/cjs/index.js CHANGED
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var index_exports = {};
20
20
  __export(index_exports, {
21
+ AuditThrottler: () => import_auditThrottler.AuditThrottler,
21
22
  Event: () => import_event2.Event,
22
23
  MessageType: () => import_messageType.MessageType,
23
24
  ProxyEvent: () => import_event.ProxyEvent,
@@ -39,3 +40,4 @@ var import_scriptingObject = require("./scriptingObject.js");
39
40
  var import_messageType = require("./messageType.js");
40
41
  var import_scriptingObjectManager = require("./scriptingObjectManager.js");
41
42
  var import_proxy = require("./proxy.js");
43
+ var import_auditThrottler = require("./auditThrottler.js");
@@ -0,0 +1,158 @@
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 loader_exports = {};
20
+ __export(loader_exports, {
21
+ loadApp: () => loadApp,
22
+ mountApp: () => mountApp,
23
+ unloadApp: () => unloadApp,
24
+ unmountApp: () => unmountApp
25
+ });
26
+ module.exports = __toCommonJS(loader_exports);
27
+ var import_host = require("./host.js");
28
+ var import_utils = require("./utils.js");
29
+ var import_logger = require("./logger.js");
30
+ var import_logRecords = require("./logRecords.js");
31
+ var import_window = require("./window.js");
32
+ var import_styleLoader = require("./styleLoader.js");
33
+ var import_scriptLoader = require("./scriptLoader.js");
34
+ var import_manifestLoader = require("./manifestLoader.js");
35
+ const APP_CONTAINER_ID_PREFIX = "pui-app-container-";
36
+ const cssType = /\.css$/;
37
+ const isCss = (fileName) => cssType.test(fileName);
38
+ const activeApps = {};
39
+ const getPathName = (url) => url ? new URL(url).pathname : "";
40
+ const initApplication = async ({
41
+ id,
42
+ name,
43
+ hostUrl,
44
+ history,
45
+ theme,
46
+ manifestPath,
47
+ homeRoute
48
+ }) => {
49
+ const app = window.emui?.[id];
50
+ if (!app) {
51
+ throw new Error(
52
+ `Application ${name} with ${id} is not found. Most probably the appId property of app.config.json is not set to ${id}`
53
+ );
54
+ }
55
+ const { init } = app;
56
+ if (!init || typeof init !== "function")
57
+ throw new Error(
58
+ `Application ${name} with id ${id} doesn't expose init method.`
59
+ );
60
+ return init({
61
+ host: import_host.CMicroAppHost.getInstance(),
62
+ hostUrl,
63
+ manifestPath,
64
+ homeRoute: homeRoute ?? getPathName(hostUrl),
65
+ prevState: null,
66
+ history,
67
+ theme,
68
+ hostBreakpoint: (0, import_window.getCurrentBreakpoint)(),
69
+ hostViewportSize: (0, import_window.getViewportSize)(),
70
+ logger: import_logger.logger
71
+ });
72
+ };
73
+ const mountApp = async ({ id, name }) => {
74
+ const app = (window.emui || {})[id] || {};
75
+ const { mount } = app;
76
+ if (!mount || typeof mount !== "function")
77
+ throw new Error(
78
+ `Application ${name} with id ${id} doesn't expose mount method.`
79
+ );
80
+ return mount({
81
+ containerId: `${APP_CONTAINER_ID_PREFIX}${id}`,
82
+ hostBreakpoint: (0, import_window.getCurrentBreakpoint)(),
83
+ hostViewportSize: (0, import_window.getViewportSize)()
84
+ });
85
+ };
86
+ const unmountApp = async ({ id, name }) => {
87
+ const app = (window.emui || {})[id];
88
+ if (!app) return null;
89
+ const { unmount } = app;
90
+ if (!unmount) return null;
91
+ if (typeof unmount !== "function")
92
+ throw new Error(
93
+ `unmount failed for application ${name} with id ${id}. unmount is not a valid function`
94
+ );
95
+ return Promise.resolve();
96
+ };
97
+ const addAppToActiveAppList = (id, elementIds) => {
98
+ const app = (window.emui || {})[id] || {};
99
+ const { getObject } = app;
100
+ activeApps[id] = { elementIds };
101
+ const host = import_host.CMicroAppHost.getInstance();
102
+ if (host) host.activeGuests[id] = getObject && getObject() || {};
103
+ return Promise.resolve();
104
+ };
105
+ const waitAndInitApplication = (appConfig, requests) => (
106
+ // wait for all assets to get downloaded
107
+ Promise.all(requests).then(addAppToActiveAppList.bind(null, appConfig.id)).then(initApplication.bind(null, appConfig)).catch((err) => {
108
+ const logRecord = import_logRecords.logRecords.APP_INIT_FAILED(appConfig.id, err.message);
109
+ import_logger.logger.error({ ...logRecord, exception: err });
110
+ throw new Error(logRecord.message);
111
+ })
112
+ );
113
+ const removeAssetsFromDOM = (id, documentEle = document) => {
114
+ const host = import_host.CMicroAppHost.getInstance();
115
+ if (host) delete host.activeGuests[id];
116
+ const { elementIds } = activeApps[id] || {};
117
+ if (elementIds) {
118
+ elementIds.forEach((elementId) => {
119
+ const ele = documentEle.getElementById(elementId);
120
+ if (ele) ele.remove();
121
+ });
122
+ delete activeApps[id];
123
+ }
124
+ };
125
+ const sanitizeAppConfig = (appConfig) => {
126
+ const { hostUrl = "" } = appConfig;
127
+ appConfig.hostUrl = (0, import_utils.getAbsoluteUrl)(hostUrl).replace(/\/?$/, "/");
128
+ };
129
+ const loadApp = async (appConfig) => {
130
+ import_logger.logger.info(import_logRecords.logRecords.APP_LOADING(appConfig.id));
131
+ sanitizeAppConfig(appConfig);
132
+ let assets = appConfig.files;
133
+ const manifest = await (0, import_manifestLoader.getAppManifest)(appConfig);
134
+ assets = (0, import_manifestLoader.getFullFileNameofAssetsFromManifest)(manifest, appConfig.files);
135
+ let counter = 0;
136
+ const requests = assets.map((fileName) => {
137
+ counter += 1;
138
+ return !isCss(fileName) ? (0, import_scriptLoader.addScriptToDOM)(appConfig, fileName, counter) : (0, import_styleLoader.addStylesToDOM)(appConfig, fileName, counter);
139
+ });
140
+ await waitAndInitApplication(appConfig, requests);
141
+ import_logger.logger.info(import_logRecords.logRecords.APP_LOADING_COMPLETE(appConfig.id));
142
+ };
143
+ const unloadApp = ({
144
+ id,
145
+ hostUrl,
146
+ documentEle
147
+ }) => {
148
+ if (!hostUrl) throw new Error("Unable to unload app. hostUrl is required");
149
+ import_logger.logger.info(import_logRecords.logRecords.APP_UNLOADING(id));
150
+ const app = (window.emui || {})[id];
151
+ if (!app) return;
152
+ removeAssetsFromDOM(id, documentEle);
153
+ (0, import_scriptLoader.removeDynamicImportedScripts)(hostUrl, documentEle);
154
+ (0, import_scriptLoader.removePrefetchLinks)(hostUrl, documentEle);
155
+ (0, import_styleLoader.removeDynamicImportedStyles)(hostUrl, documentEle);
156
+ if (window.emui && window.emui[id]) delete window.emui[id];
157
+ import_logger.logger.info(import_logRecords.logRecords.APP_UNLOADING_COMPLETE(id));
158
+ };
@@ -0,0 +1,57 @@
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 logRecords_exports = {};
20
+ __export(logRecords_exports, {
21
+ logRecords: () => logRecords
22
+ });
23
+ module.exports = __toCommonJS(logRecords_exports);
24
+ const logRecords = {
25
+ APP_CONFIG_LOAD_FAILED: {
26
+ code: "microfe01",
27
+ message: "Unable to load application configuration"
28
+ },
29
+ ASSET_NOT_FOUND_IN_MANIFEST: (assetName) => ({
30
+ code: "microfe02",
31
+ message: `Application load failed. unable to locate ${assetName} in the manifest`
32
+ }),
33
+ APP_INIT_FAILED: (appId, errMsg) => ({
34
+ code: "microfe03",
35
+ message: `Application load failed. Unable to load one or more application resources for appId: ${appId}. ${errMsg}`
36
+ }),
37
+ APP_LOADING: (appId) => ({
38
+ code: "microfe04",
39
+ message: `Application ${appId} is loading...`
40
+ }),
41
+ APP_LOADING_COMPLETE: (appId) => ({
42
+ code: "microfe05",
43
+ message: `Application ${appId} loaded`
44
+ }),
45
+ APP_UNLOADING: (appId) => ({
46
+ code: "microfe06",
47
+ message: `Application ${appId} unloading...`
48
+ }),
49
+ APP_UNLOADING_COMPLETE: (appId) => ({
50
+ code: "microfe07",
51
+ message: `Application ${appId} unloaded`
52
+ }),
53
+ SSF_HOST_OBJECT_NOT_FOUND: (name) => ({
54
+ code: "microfe08",
55
+ message: `Parent window doesn't expose SSF Object named ${name}`
56
+ })
57
+ };
@@ -0,0 +1,34 @@
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 logger_exports = {};
20
+ __export(logger_exports, {
21
+ logger: () => logger
22
+ });
23
+ module.exports = __toCommonJS(logger_exports);
24
+ var import_pui_diagnostics = require("@elliemae/pui-diagnostics");
25
+ const consoleLogger = (() => (0, import_pui_diagnostics.logger)({
26
+ transport: (0, import_pui_diagnostics.Console)(),
27
+ index: "app",
28
+ environment: "NA",
29
+ team: "app team",
30
+ appName: "ICEMT App",
31
+ appVersion: "latest",
32
+ userId: ""
33
+ }))();
34
+ const logger = window?.emui?.logger || consoleLogger;