@elliemae/ssf-host 2.29.2 → 2.31.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 (42) hide show
  1. package/dist/cjs/guest.js +75 -31
  2. package/dist/cjs/host.js +263 -79
  3. package/dist/cjs/package.json +1 -4
  4. package/dist/cjs/tests/scriptingObjects/appraisalServiceModule.js +4 -0
  5. package/dist/cjs/tests/scriptingObjects/creditServiceModule.js +4 -0
  6. package/dist/cjs/tests/scriptingObjects/floodServiceModule.js +4 -0
  7. package/dist/cjs/utils.js +8 -1
  8. package/dist/esm/guest.js +75 -31
  9. package/dist/esm/host.js +263 -79
  10. package/dist/esm/package.json +1 -4
  11. package/dist/esm/tests/scriptingObjects/appraisalServiceModule.js +4 -0
  12. package/dist/esm/tests/scriptingObjects/creditServiceModule.js +4 -0
  13. package/dist/esm/tests/scriptingObjects/floodServiceModule.js +4 -0
  14. package/dist/esm/utils.js +8 -1
  15. package/dist/public/callchain-host.html +1 -1
  16. package/dist/public/callchain-intermediate.html +1 -1
  17. package/dist/public/e2e-host.html +1 -1
  18. package/dist/public/e2e-index.html +1 -1
  19. package/dist/public/index.html +1 -1
  20. package/dist/public/js/emuiSsfHost.dd636c9bb8bbc719a7fd.js +3 -0
  21. package/dist/public/js/emuiSsfHost.dd636c9bb8bbc719a7fd.js.br +0 -0
  22. package/dist/public/js/emuiSsfHost.dd636c9bb8bbc719a7fd.js.gz +0 -0
  23. package/dist/public/js/emuiSsfHost.dd636c9bb8bbc719a7fd.js.map +1 -0
  24. package/dist/public/popup-focus-host.html +1 -1
  25. package/dist/public/v1-guest-v2-host.html +1 -1
  26. package/dist/public/v2-host-v1-guest.html +1 -1
  27. package/dist/types/lib/host.d.ts +11 -4
  28. package/dist/types/lib/tests/guestHandshake.test.d.ts +1 -0
  29. package/dist/types/lib/tests/scriptingObjects/appObjects.d.ts +2 -0
  30. package/dist/types/lib/tests/scriptingObjects/appraisalServiceModule.d.ts +1 -0
  31. package/dist/types/lib/tests/scriptingObjects/creditServiceModule.d.ts +1 -0
  32. package/dist/types/lib/tests/scriptingObjects/floodServiceModule.d.ts +1 -0
  33. package/dist/types/tsconfig.tsbuildinfo +1 -1
  34. package/dist/umd/index.js +1 -1
  35. package/dist/umd/index.js.br +0 -0
  36. package/dist/umd/index.js.gz +0 -0
  37. package/dist/umd/index.js.map +1 -1
  38. package/package.json +8 -8
  39. package/dist/public/js/emuiSsfHost.e05998eeb058c9f027f1.js +0 -3
  40. package/dist/public/js/emuiSsfHost.e05998eeb058c9f027f1.js.br +0 -0
  41. package/dist/public/js/emuiSsfHost.e05998eeb058c9f027f1.js.gz +0 -0
  42. package/dist/public/js/emuiSsfHost.e05998eeb058c9f027f1.js.map +0 -1
package/dist/cjs/guest.js CHANGED
@@ -24,6 +24,8 @@ module.exports = __toCommonJS(guest_exports);
24
24
  var import_microfe_common = require("@elliemae/microfe-common");
25
25
  var import_types = require("./types.js");
26
26
  var import_utils = require("./utils.js");
27
+ const HAND_SHAKE_INTERVAL_MS = 1e3;
28
+ const HAND_SHAKE_RETRIES = 5;
27
29
  class Guest {
28
30
  /**
29
31
  * unique id of the guest application
@@ -81,6 +83,18 @@ class Guest {
81
83
  * one-time token for popup handshake when window.opener is unavailable
82
84
  */
83
85
  #handshakeToken;
86
+ /**
87
+ * Active popup handshake interval, if any.
88
+ */
89
+ #handShakeInterval = null;
90
+ /**
91
+ * HandShakeAck listener registered for the active handshake.
92
+ */
93
+ #handShakeAckListener = null;
94
+ /**
95
+ * Resolver for the in-flight {@link handShake} promise.
96
+ */
97
+ #handShakeResolve = null;
84
98
  /**
85
99
  * Create object representing guest application
86
100
  * @param {GuestOption} option - options for creating a guest application
@@ -115,6 +129,7 @@ class Guest {
115
129
  * clean up resources
116
130
  */
117
131
  dispose = () => {
132
+ this.#cancelHandShake(false);
118
133
  if (this.openMode === import_types.OpenMode.Popup && !this.window.closed) {
119
134
  try {
120
135
  this.window.document;
@@ -141,45 +156,74 @@ class Guest {
141
156
  guestTitle: this.title,
142
157
  guestUrl: this.url
143
158
  });
159
+ /**
160
+ * Stops an in-flight popup handshake and optionally settles its promise.
161
+ * @param resolveWith when set, resolves a pending handshake with this value
162
+ */
163
+ #cancelHandShake = (resolveWith) => {
164
+ if (this.#handShakeInterval) {
165
+ clearInterval(this.#handShakeInterval);
166
+ this.#handShakeInterval = null;
167
+ }
168
+ if (this.#handShakeAckListener) {
169
+ this.#remoting.unlisten({
170
+ messageType: import_microfe_common.MessageType.HandShakeAck,
171
+ callback: this.#handShakeAckListener
172
+ });
173
+ this.#handShakeAckListener = null;
174
+ }
175
+ const resolve = this.#handShakeResolve;
176
+ this.#handShakeResolve = null;
177
+ if (resolve && resolveWith !== void 0) {
178
+ resolve(resolveWith);
179
+ }
180
+ };
181
+ /**
182
+ * Sends one HandShake message when a handshake is still active.
183
+ */
184
+ #sendHandShake = () => {
185
+ if (!this.#handShakeResolve) return;
186
+ this.#remoting.send({
187
+ targetWin: this.window,
188
+ targetOrigin: this.origin,
189
+ messageType: import_microfe_common.MessageType.HandShake,
190
+ messageBody: this.#handshakeToken ? { handshakeToken: this.#handshakeToken } : {}
191
+ });
192
+ };
144
193
  /**
145
194
  * Handshake with the guest application in the popup window
146
195
  * @returns true if the guest popup window is open & connected
147
196
  */
148
- handShake = () => new Promise((resolve) => {
149
- let handShakeCount = 0;
150
- const handShakeRetries = 5;
151
- let handShakeHandle;
152
- const onAck = () => {
153
- clearInterval(handShakeHandle);
154
- this.#remoting.unlisten({
197
+ handShake = () => {
198
+ this.#cancelHandShake(false);
199
+ if (this.openMode !== import_types.OpenMode.Popup) {
200
+ return Promise.resolve(false);
201
+ }
202
+ return new Promise((resolve) => {
203
+ let handShakeCount = 0;
204
+ this.#handShakeResolve = resolve;
205
+ const onAck = () => {
206
+ if (!this.#handShakeResolve) return;
207
+ this.#cancelHandShake(true);
208
+ };
209
+ this.#handShakeAckListener = onAck;
210
+ this.#sendHandShake();
211
+ handShakeCount = 1;
212
+ this.#handShakeInterval = setInterval(() => {
213
+ if (!this.#handShakeResolve) return;
214
+ if (handShakeCount >= HAND_SHAKE_RETRIES) {
215
+ this.#cancelHandShake(false);
216
+ return;
217
+ }
218
+ this.#sendHandShake();
219
+ handShakeCount += 1;
220
+ }, HAND_SHAKE_INTERVAL_MS);
221
+ this.#remoting.listen({
155
222
  messageType: import_microfe_common.MessageType.HandShakeAck,
156
223
  callback: onAck
157
224
  });
158
- resolve(true);
159
- };
160
- handShakeHandle = setInterval(() => {
161
- if (handShakeCount >= handShakeRetries) {
162
- clearInterval(handShakeHandle);
163
- this.#remoting.unlisten({
164
- messageType: import_microfe_common.MessageType.HandShakeAck,
165
- callback: onAck
166
- });
167
- resolve(false);
168
- } else {
169
- this.#remoting.send({
170
- targetWin: this.window,
171
- targetOrigin: this.origin,
172
- messageType: import_microfe_common.MessageType.HandShake,
173
- messageBody: this.#handshakeToken ? { handshakeToken: this.#handshakeToken } : {}
174
- });
175
- handShakeCount += 1;
176
- }
177
- }, 1e3);
178
- this.#remoting.listen({
179
- messageType: import_microfe_common.MessageType.HandShakeAck,
180
- callback: onAck
181
225
  });
182
- });
226
+ };
183
227
  /**
184
228
  * initialize guest messaging
185
229
  */
package/dist/cjs/host.js CHANGED
@@ -91,9 +91,26 @@ class SSFHost {
91
91
  */
92
92
  #readyStateCallback = null;
93
93
  /**
94
- *
94
+ * Interval handle for polling popup guests whose window was closed externally.
95
+ */
96
+ #guestLifecycleMonitor = null;
97
+ /**
98
+ * Observes embed iframe removal from the host DOM (replaces polling for embeds).
99
+ */
100
+ #embedDetachObservers = /* @__PURE__ */ new Map();
101
+ /**
102
+ * Guest ids using fitToContent; drives GuestResize Remoting listener lifecycle.
103
+ */
104
+ #fitToContentGuestIds = /* @__PURE__ */ new Set();
105
+ /**
106
+ * Guest ids currently being unloaded (guards observer + explicit double-unload).
107
+ */
108
+ #guestsUnloading = /* @__PURE__ */ new Set();
109
+ /**
110
+ * Guest ids for which {@link onGuestClose} callbacks were already invoked
111
+ * for the current close attempt (dedupes concurrent exit paths).
95
112
  */
96
- #popupGuestMonitor = null;
113
+ #guestCloseNotified = /* @__PURE__ */ new Set();
97
114
  /**
98
115
  * callback for guest event subscription
99
116
  */
@@ -149,7 +166,8 @@ class SSFHost {
149
166
  this.#soManager = new import_microfe_common.ScriptingObjectManager();
150
167
  this.#remoting.initialize(window);
151
168
  this.#connect();
152
- window.addEventListener("beforeunload", this.#closeAllPopupGuests);
169
+ window.addEventListener("beforeunload", this.#closeAllGuests);
170
+ window.addEventListener("pagehide", this.#closeAllGuests);
153
171
  this.#logger.debug(
154
172
  `host is initialized. hostId: ${this.hostId}, correlationId: ${this.#correlationId}`
155
173
  );
@@ -162,9 +180,29 @@ class SSFHost {
162
180
  );
163
181
  });
164
182
  };
165
- #closeAllPopupGuests = () => {
166
- const popupIds = Array.from(this.#guests.values()).filter((guest) => guest.openMode === import_types.OpenMode.Popup).map((guest) => guest.id);
167
- popupIds.forEach((id) => this.#unloadGuestInBackground(id));
183
+ /**
184
+ * Synchronously closes open popup guest windows.
185
+ *
186
+ * During page unload the browser may terminate the host before async
187
+ * {@link unloadGuest} (module.unloading / unmount) completes.
188
+ */
189
+ #closePopupWindowsSync = () => {
190
+ this.#guests.forEach((guest) => {
191
+ if (guest.openMode !== import_types.OpenMode.Popup || guest.window?.closed) return;
192
+ guest.dispose();
193
+ });
194
+ };
195
+ /**
196
+ * Unloads every registered guest without awaiting completion.
197
+ *
198
+ * Used on host {@link close}, `beforeunload`, and `pagehide` so embed and
199
+ * popup guests are torn down when the host page unloads.
200
+ */
201
+ #closeAllGuests = () => {
202
+ this.#closePopupWindowsSync();
203
+ Array.from(this.#guests.keys()).forEach(
204
+ (id) => this.#unloadGuestInBackground(id)
205
+ );
168
206
  };
169
207
  /**
170
208
  * get the reference to the guest application by its window
@@ -331,17 +369,18 @@ class SSFHost {
331
369
  }
332
370
  };
333
371
  /**
334
- * cleanup the guest reference when it is closed
335
- * @param param0
336
- * @param param0.sourceWin
372
+ * Handles {@link MessageType.GuestClose} from a guest application.
373
+ *
374
+ * GuestClose is authoritative: the guest has initiated shutdown, so unload
375
+ * immediately regardless of open mode (embed or popup).
376
+ * @param param remoting listener parameters
377
+ * @param param.sourceWin guest window that sent GuestClose
337
378
  */
338
- #handleGuestClose = async ({ sourceWin }) => {
339
- if (sourceWin?.window) {
340
- const guest = this.#findGuest(sourceWin);
341
- if (guest && !await guest.handShake()) {
342
- this.#unloadGuestInBackground(sourceWin);
343
- }
344
- }
379
+ #handleGuestClose = ({ sourceWin }) => {
380
+ if (!sourceWin) return;
381
+ const guest = this.#findGuest(sourceWin);
382
+ if (!guest) return;
383
+ this.#unloadGuestAndNotifyHost(guest.id);
345
384
  };
346
385
  // Handles list objects requests from the remote automation framework
347
386
  #handleListObjects = ({
@@ -514,10 +553,16 @@ class SSFHost {
514
553
  body
515
554
  }) => {
516
555
  const guest = this.#getGuestForWindow(sourceWin);
517
- if (!guest) {
518
- this.#logger.warn(
519
- `Received resize event from unknown guest. requestid = ${requestId}`
520
- );
556
+ if (!guest || !this.#fitToContentGuestIds.has(guest.id) || this.#guestsUnloading.has(guest.id)) {
557
+ if (guest) {
558
+ this.#logger.debug(
559
+ `Ignored resize event from guest ${guest.id}. requestId = ${requestId}`
560
+ );
561
+ } else {
562
+ this.#logger.warn(
563
+ `Received resize event from unknown guest. requestid = ${requestId}`
564
+ );
565
+ }
521
566
  return;
522
567
  }
523
568
  if (guest.domElement) {
@@ -612,7 +657,7 @@ class SSFHost {
612
657
  return true;
613
658
  };
614
659
  /**
615
- * subscribe to guest resize event
660
+ * Registers the shared GuestResize listener when the first fit-to-content guest loads.
616
661
  */
617
662
  #subscribeToGuestResizeEvent = () => {
618
663
  this.#remoting.listen({
@@ -620,6 +665,35 @@ class SSFHost {
620
665
  callback: this.#handleGuestResize
621
666
  });
622
667
  };
668
+ /**
669
+ * Removes the shared GuestResize listener when no fit-to-content guests remain.
670
+ */
671
+ #unsubscribeFromGuestResizeEvent = () => {
672
+ this.#remoting.unlisten({
673
+ messageType: import_microfe_common.MessageType.GuestResize,
674
+ callback: this.#handleGuestResize
675
+ });
676
+ };
677
+ /**
678
+ * Tracks a fit-to-content embed and ensures the GuestResize listener is active.
679
+ * @param guestId embed guest id
680
+ */
681
+ #registerFitToContentGuest = (guestId) => {
682
+ if (this.#fitToContentGuestIds.has(guestId)) return;
683
+ const isFirst = this.#fitToContentGuestIds.size === 0;
684
+ this.#fitToContentGuestIds.add(guestId);
685
+ if (isFirst) this.#subscribeToGuestResizeEvent();
686
+ };
687
+ /**
688
+ * Stops tracking a fit-to-content embed and unlistens when none remain.
689
+ * @param guestId embed guest id
690
+ */
691
+ #unregisterFitToContentGuest = (guestId) => {
692
+ if (!this.#fitToContentGuestIds.delete(guestId)) return;
693
+ if (this.#fitToContentGuestIds.size === 0) {
694
+ this.#unsubscribeFromGuestResizeEvent();
695
+ }
696
+ };
623
697
  /**
624
698
  * start listening to the remoting messages
625
699
  */
@@ -701,9 +775,83 @@ class SSFHost {
701
775
  (value) => value.domElement === guestIdOrWindowOrEle
702
776
  );
703
777
  };
778
+ /**
779
+ * Returns true when an embed guest's iframe is no longer in the host DOM.
780
+ * @param guest embed guest to inspect
781
+ */
782
+ #isEmbedGuestDetached = (guest) => guest.openMode === import_types.OpenMode.Embed && (!guest.domElement || !guest.domElement.isConnected);
783
+ /**
784
+ * Invokes {@link onGuestClose} callbacks registered for a guest id.
785
+ * @param guestId guest application id
786
+ */
787
+ #fireGuestCloseCallbacks = (guestId) => {
788
+ const callbacks = this.#guestCloseCallbackList.get(guestId);
789
+ callbacks?.forEach((callback) => {
790
+ Promise.resolve(callback({ id: guestId })).catch(ignoreRejectedPromise);
791
+ });
792
+ };
793
+ /**
794
+ * Starts guest unload and notifies host {@link onGuestClose} listeners.
795
+ *
796
+ * Used by {@link #handleGuestClose}, embed detach monitoring, and popup
797
+ * lifecycle polling so every exit path behaves consistently.
798
+ * @param guestId guest application id
799
+ */
800
+ #unloadGuestAndNotifyHost = (guestId) => {
801
+ if (!this.#guests.has(guestId)) return;
802
+ if (!this.#guestCloseNotified.has(guestId)) {
803
+ this.#guestCloseNotified.add(guestId);
804
+ this.#fireGuestCloseCallbacks(guestId);
805
+ }
806
+ if (!this.#guestsUnloading.has(guestId)) {
807
+ this.#unloadGuestInBackground(guestId);
808
+ }
809
+ };
810
+ /**
811
+ * Watches an embed iframe's parent for DOM removal and unloads the guest
812
+ * when the iframe is detached (including cross-origin embeds).
813
+ *
814
+ * Uses {@link #isEmbedGuestDetached} in the mutation callback so moving an
815
+ * iframe between containers does not trigger a false unload.
816
+ * @param guest embed guest whose iframe should be observed
817
+ */
818
+ #observeEmbedGuestDetach = (guest) => {
819
+ const iframe = guest.domElement;
820
+ const parent = iframe?.parentNode;
821
+ if (!iframe || !parent) return;
822
+ const observer = new MutationObserver(() => {
823
+ if (!this.#isEmbedGuestDetached(guest)) return;
824
+ this.#unobserveEmbedGuestDetach(guest.id);
825
+ this.#unloadGuestAndNotifyHost(guest.id);
826
+ });
827
+ observer.observe(parent, { childList: true });
828
+ this.#embedDetachObservers.set(guest.id, observer);
829
+ };
830
+ /**
831
+ * Stops observing embed iframe detachment for a guest.
832
+ * @param guestId guest application id
833
+ */
834
+ #unobserveEmbedGuestDetach = (guestId) => {
835
+ this.#embedDetachObservers.get(guestId)?.disconnect();
836
+ this.#embedDetachObservers.delete(guestId);
837
+ };
838
+ /**
839
+ * Disconnects all embed detach {@link MutationObserver} instances.
840
+ *
841
+ * Called from {@link close} before unloading guests.
842
+ */
843
+ #disconnectAllEmbedObservers = () => {
844
+ this.#embedDetachObservers.forEach((observer) => observer.disconnect());
845
+ this.#embedDetachObservers.clear();
846
+ };
847
+ /**
848
+ * Polls open popup guests and unloads any whose window was closed externally.
849
+ *
850
+ * Embed guests use {@link #observeEmbedGuestDetach} instead of this interval.
851
+ */
704
852
  #monitorPopupGuests = () => {
705
- if (this.#popupGuestMonitor) return;
706
- this.#popupGuestMonitor = setInterval(() => {
853
+ if (this.#guestLifecycleMonitor) return;
854
+ this.#guestLifecycleMonitor = setInterval(() => {
707
855
  const guestsToRemove = [];
708
856
  this.#guests.forEach((guest) => {
709
857
  if (guest.openMode === import_types.OpenMode.Popup && guest.window.closed) {
@@ -711,24 +859,21 @@ class SSFHost {
711
859
  }
712
860
  });
713
861
  guestsToRemove.forEach((guest) => {
714
- const { id } = guest;
715
- this.#unloadGuestInBackground(id);
716
- const callbacks = this.#guestCloseCallbackList.get(id);
717
- callbacks?.forEach((callback) => {
718
- Promise.resolve(callback({ id })).catch(() => {
719
- });
720
- });
862
+ this.#unloadGuestAndNotifyHost(guest.id);
721
863
  });
722
864
  }, 1e3);
723
865
  };
866
+ /**
867
+ * Stops the popup close poll when no popup guests remain.
868
+ */
724
869
  #stopMonitoringPopupGuests = () => {
725
- if (!this.#popupGuestMonitor) return;
870
+ if (!this.#guestLifecycleMonitor) return;
726
871
  const hasPopups = Array.from(this.#guests.values()).some(
727
872
  (guest) => guest.openMode === import_types.OpenMode.Popup
728
873
  );
729
874
  if (!hasPopups) {
730
- clearInterval(this.#popupGuestMonitor);
731
- this.#popupGuestMonitor = null;
875
+ clearInterval(this.#guestLifecycleMonitor);
876
+ this.#guestLifecycleMonitor = null;
732
877
  }
733
878
  };
734
879
  #buildPopupUrl = (url) => {
@@ -808,6 +953,32 @@ class SSFHost {
808
953
  }
809
954
  return guest;
810
955
  };
956
+ #notifyGuestFrameCallback = (guestId, callback, label) => {
957
+ setTimeout(() => {
958
+ try {
959
+ callback?.(guestId);
960
+ } catch (error) {
961
+ this.#logger.debug(
962
+ `Error occurred in ${label} for guest with id '${guestId}': ${error.message}`
963
+ );
964
+ }
965
+ }, 0);
966
+ };
967
+ #bindEmbedFrameEvents = (frame, guestId, callbacks = {}) => {
968
+ const { onLoad, onError } = callbacks;
969
+ const onFrameLoad = () => {
970
+ this.#notifyGuestFrameCallback(guestId, onLoad, "onLoad");
971
+ this.#logger.debug(`frame loaded for guest with id '${guestId}'`);
972
+ frame.removeEventListener("load", onFrameLoad);
973
+ };
974
+ const onFrameLoadFailure = () => {
975
+ this.#notifyGuestFrameCallback(guestId, onError, "onError");
976
+ this.#logger.error(`frame load failed for guest with id '${guestId}'`);
977
+ frame.removeEventListener("error", onFrameLoadFailure);
978
+ };
979
+ frame.addEventListener("load", onFrameLoad);
980
+ frame.addEventListener("error", onFrameLoadFailure);
981
+ };
811
982
  #openEmbedGuest = (param) => {
812
983
  const {
813
984
  url,
@@ -829,37 +1000,9 @@ class SSFHost {
829
1000
  permissionPolicy = ""
830
1001
  } = options;
831
1002
  if (!title) throw new Error("title is required");
832
- if (fitToContent) this.#subscribeToGuestResizeEvent();
833
1003
  const frame = targetElementDocument.createElement("iframe");
834
1004
  frame.setAttribute("id", guestId);
835
- const onFrameLoad = () => {
836
- setTimeout(() => {
837
- try {
838
- onLoad?.(guestId);
839
- } catch (error) {
840
- this.#logger.debug(
841
- `Error occurred in onLoad for guest with id '${guestId}': ${error.message}`
842
- );
843
- }
844
- }, 0);
845
- this.#logger.debug(`frame loaded for guest with id '${guestId}'`);
846
- frame.removeEventListener("load", onFrameLoad);
847
- };
848
- const onFrameLoadFailure = () => {
849
- setTimeout(() => {
850
- try {
851
- onError?.(guestId);
852
- } catch (error) {
853
- this.#logger.debug(
854
- `Error occurred in onError for guest with id '${guestId}': ${error.message}`
855
- );
856
- }
857
- }, 0);
858
- this.#logger.error(`frame load failed for guest with id '${guestId}'`);
859
- frame.removeEventListener("error", onFrameLoadFailure);
860
- };
861
- frame.addEventListener("load", onFrameLoad);
862
- frame.addEventListener("error", onFrameLoadFailure);
1005
+ this.#bindEmbedFrameEvents(frame, guestId, { onLoad, onError });
863
1006
  frame.setAttribute(
864
1007
  "style",
865
1008
  `min-width: 100%; height: 100%; border: 0px; ${style}`
@@ -877,7 +1020,7 @@ class SSFHost {
877
1020
  const guestFrameEle = targetElementDocument.getElementById(
878
1021
  guestId
879
1022
  );
880
- return this.#attachGuest({
1023
+ const guest = this.#attachGuest({
881
1024
  guestId,
882
1025
  domElement: guestFrameEle,
883
1026
  window: guestFrameEle.contentWindow,
@@ -886,6 +1029,9 @@ class SSFHost {
886
1029
  searchParams,
887
1030
  openMode: import_types.OpenMode.Embed
888
1031
  });
1032
+ if (fitToContent) this.#registerFitToContentGuest(guest.id);
1033
+ this.#observeEmbedGuestDetach(guest);
1034
+ return guest;
889
1035
  };
890
1036
  #getGuestUrl = (url, params) => {
891
1037
  let querystring = "";
@@ -1007,17 +1153,27 @@ class SSFHost {
1007
1153
  return so;
1008
1154
  };
1009
1155
  /**
1010
- * dispose the resources used by the host application
1156
+ * Disposes resources used by the host application.
1157
+ *
1158
+ * Stops guest monitors, unloads all guests (embed and popup), clears
1159
+ * guest-scoped scripting objects, close callbacks, metadata, and remoting.
1011
1160
  */
1012
1161
  close = () => {
1013
- if (this.#popupGuestMonitor) {
1014
- clearInterval(this.#popupGuestMonitor);
1015
- this.#popupGuestMonitor = null;
1162
+ if (this.#guestLifecycleMonitor) {
1163
+ clearInterval(this.#guestLifecycleMonitor);
1164
+ this.#guestLifecycleMonitor = null;
1016
1165
  }
1017
- this.#closeAllPopupGuests();
1166
+ this.#disconnectAllEmbedObservers();
1167
+ this.#closeAllGuests();
1168
+ this.#fitToContentGuestIds.clear();
1169
+ this.#guestCloseNotified.clear();
1170
+ this.#unsubscribeFromGuestResizeEvent();
1171
+ this.#guestCloseCallbackList.clear();
1172
+ this.removeAllScriptingObjects();
1018
1173
  this.#guestMetadata.clear();
1019
1174
  this.#remoting.close();
1020
- window.removeEventListener("beforeunload", this.#closeAllPopupGuests);
1175
+ window.removeEventListener("beforeunload", this.#closeAllGuests);
1176
+ window.removeEventListener("pagehide", this.#closeAllGuests);
1021
1177
  this.#logger.debug(
1022
1178
  `host is closed. hostId: ${this.hostId}, correlationId: ${this.#correlationId}`
1023
1179
  );
@@ -1329,30 +1485,58 @@ class SSFHost {
1329
1485
  });
1330
1486
  }
1331
1487
  };
1488
+ /**
1489
+ * Fire-and-forget wrapper around {@link unloadGuest} for monitors and event handlers.
1490
+ * @param guestIdOrWindowOrEle unique id, window, or iframe element of the guest
1491
+ */
1332
1492
  #unloadGuestInBackground = (guestIdOrWindowOrEle) => {
1333
1493
  this.unloadGuest(guestIdOrWindowOrEle).catch(ignoreRejectedPromise);
1334
1494
  };
1335
- /**
1336
- * unloads guest application from host
1337
- * @param guestIdOrWindowOrEle unique id of the guest application or window object or dom element of the guest application
1338
- * @throws Error if guestId or Window reference is invalid
1339
- */
1340
- unloadGuest = async (guestIdOrWindowOrEle) => {
1341
- const guest = this.#findGuest(guestIdOrWindowOrEle);
1342
- if (!guest) return;
1343
- if (!await this.#canUnloadGuest(guest)) return;
1344
- await this.#dispatchModuleUnmount(guest);
1495
+ #finalizeGuestRemoval = (guest) => {
1496
+ this.#unobserveEmbedGuestDetach(guest.id);
1497
+ this.#unregisterFitToContentGuest(guest.id);
1345
1498
  guest.dispose();
1499
+ this.removeAllScriptingObjects(guest.id);
1346
1500
  this.#guestsByWindow.delete(guest.window);
1347
1501
  this.#guestsByUrl.delete(guest.url);
1348
1502
  this.#guestMetadata.delete(guest.id);
1349
1503
  this.#guests.delete(guest.id);
1504
+ this.#guestCloseCallbackList.delete(guest.id);
1505
+ this.#guestCloseNotified.delete(guest.id);
1350
1506
  this.#logger.audit({
1351
1507
  message: `Guest is removed from host`,
1352
1508
  ...guest.getInfo()
1353
1509
  });
1354
1510
  this.#stopMonitoringPopupGuests();
1355
1511
  };
1512
+ /**
1513
+ * Unloads a guest application from the host.
1514
+ *
1515
+ * Disposes the guest, removes guest-scoped scripting objects, and clears
1516
+ * host registries. When the popup window is already closed or the embed
1517
+ * iframe was removed from the DOM, module unload veto/unmount is skipped
1518
+ * and host-side cleanup proceeds immediately.
1519
+ * @param guestIdOrWindowOrEle unique id, window, or iframe element of the guest
1520
+ */
1521
+ unloadGuest = async (guestIdOrWindowOrEle) => {
1522
+ const guest = this.#findGuest(guestIdOrWindowOrEle);
1523
+ if (!guest) return;
1524
+ if (this.#guestsUnloading.has(guest.id)) return;
1525
+ this.#guestsUnloading.add(guest.id);
1526
+ try {
1527
+ const guestContextDestroyed = Boolean(guest.window?.closed) || this.#isEmbedGuestDetached(guest);
1528
+ if (!guestContextDestroyed) {
1529
+ if (!await this.#canUnloadGuest(guest)) {
1530
+ this.#guestCloseNotified.delete(guest.id);
1531
+ return;
1532
+ }
1533
+ await this.#dispatchModuleUnmount(guest);
1534
+ }
1535
+ this.#finalizeGuestRemoval(guest);
1536
+ } finally {
1537
+ this.#guestsUnloading.delete(guest.id);
1538
+ }
1539
+ };
1356
1540
  /**
1357
1541
  * monitors guest window close action and executes the callback from host.
1358
1542
  * @param callback host callback method
@@ -1,7 +1,4 @@
1
1
  {
2
2
  "type": "commonjs",
3
- "sideEffects": false,
4
- "publishConfig": {
5
- "access": "public"
6
- }
3
+ "sideEffects": false
7
4
  }
@@ -39,6 +39,10 @@ class AppraisalService extends import_microfe_common.ScriptingObject {
39
39
  name: "Unloading",
40
40
  objectId: this.constructor.name
41
41
  });
42
+ Unmount = new import_microfe_common.Event({
43
+ name: "Unmount",
44
+ objectId: this.constructor.name
45
+ });
42
46
  onPreCommit = new import_microfe_common.Event({
43
47
  name: "onPreCommit",
44
48
  objectId: this.constructor.name
@@ -35,6 +35,10 @@ class CreditService extends import_microfe_common.ScriptingObject {
35
35
  name: "Unloading",
36
36
  objectId: this.constructor.name
37
37
  });
38
+ Unmount = new import_microfe_common.Event({
39
+ name: "Unmount",
40
+ objectId: this.constructor.name
41
+ });
38
42
  constructor() {
39
43
  super(CREDIT_SERVICE_OBJECT);
40
44
  }
@@ -35,6 +35,10 @@ class FloodService extends import_microfe_common.ScriptingObject {
35
35
  name: "Unloading",
36
36
  objectId: this.constructor.name
37
37
  });
38
+ Unmount = new import_microfe_common.Event({
39
+ name: "Unmount",
40
+ objectId: this.constructor.name
41
+ });
38
42
  constructor() {
39
43
  super("FloodService");
40
44
  this.firstName = "John";
package/dist/cjs/utils.js CHANGED
@@ -38,7 +38,13 @@ const flatten = (source) => source.flat(Infinity).filter((v) => v !== void 0);
38
38
  function isFunction(value) {
39
39
  return typeof value === "function";
40
40
  }
41
- const TRUSTED_DOMAIN_SUFFIXES = [".ice.com", ".elliemae.com", ".ellielabs.com"];
41
+ const TRUSTED_DOMAIN_SUFFIXES = [
42
+ ".ice.com",
43
+ ".elliemae.com",
44
+ ".ellielabs.com",
45
+ ".elliemae.io",
46
+ ".ellieservices.com"
47
+ ];
42
48
  const TRUSTED_HOSTNAMES = ["localhost", "127.0.0.1"];
43
49
  const getRootDomain = (hostname) => hostname.split(".").slice(-2).join(".");
44
50
  const isKnownTrustedDomain = (hostname) => TRUSTED_HOSTNAMES.includes(hostname) || TRUSTED_DOMAIN_SUFFIXES.some(
@@ -50,6 +56,7 @@ const isSameDomainFamily = (hostname) => {
50
56
  return hostRoot === guestRoot;
51
57
  };
52
58
  const isTrustedDomain = (url) => {
59
+ if (!url) return false;
53
60
  try {
54
61
  const { hostname } = new URL(url, document.baseURI);
55
62
  return isKnownTrustedDomain(hostname) || isSameDomainFamily(hostname);