@elliemae/ssf-host 2.28.6 → 2.29.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.
- package/dist/cjs/guest.js +5 -5
- package/dist/cjs/host.js +180 -151
- package/dist/cjs/tests/utils.js +8 -0
- package/dist/cjs/utils.js +1 -1
- package/dist/esm/guest.js +5 -5
- package/dist/esm/host.js +180 -151
- package/dist/esm/tests/utils.js +8 -0
- package/dist/esm/utils.js +1 -1
- package/dist/public/callchain-host.html +1 -1
- package/dist/public/callchain-intermediate.html +1 -1
- package/dist/public/e2e-host.html +1 -1
- package/dist/public/e2e-index.html +1 -1
- package/dist/public/index.html +1 -1
- package/dist/public/js/emuiSsfHost.4b00d8e6203361c7da33.js +3 -0
- package/dist/public/js/emuiSsfHost.4b00d8e6203361c7da33.js.br +0 -0
- package/dist/public/js/emuiSsfHost.4b00d8e6203361c7da33.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.4b00d8e6203361c7da33.js.map +1 -0
- package/dist/public/popup-focus-host.html +1 -1
- package/dist/public/utils.js +1 -1
- package/dist/public/utils.js.br +0 -0
- package/dist/public/utils.js.gz +0 -0
- package/dist/public/utils.js.map +1 -1
- package/dist/public/v1-guest-v2-host.html +1 -1
- package/dist/public/v2-host-v1-guest.html +1 -1
- package/dist/types/lib/guest.d.ts +2 -2
- package/dist/types/lib/host.d.ts +4 -4
- package/dist/types/lib/ihost.d.ts +3 -3
- package/dist/types/lib/tests/scriptingObjects/analytics.d.ts +1 -1
- package/dist/types/lib/tests/scriptingObjects/appEvents.d.ts +2 -2
- package/dist/types/lib/tests/scriptingObjects/appObjects.d.ts +3 -3
- package/dist/types/lib/tests/scriptingObjects/appraisalServiceModule.d.ts +1 -1
- package/dist/types/lib/tests/scriptingObjects/creditServiceModule.d.ts +1 -1
- package/dist/types/lib/tests/server.d.ts +1 -1
- package/dist/types/lib/tests/utils.d.ts +21 -3
- package/dist/types/lib/utils.d.ts +2 -2
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.br +0 -0
- package/dist/umd/index.js.gz +0 -0
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/utils.js +1 -1
- package/dist/umd/utils.js.br +0 -0
- package/dist/umd/utils.js.gz +0 -0
- package/dist/umd/utils.js.map +1 -1
- package/package.json +8 -8
- package/dist/public/js/emuiSsfHost.13ebecc9684f2da752d9.js +0 -3
- package/dist/public/js/emuiSsfHost.13ebecc9684f2da752d9.js.br +0 -0
- package/dist/public/js/emuiSsfHost.13ebecc9684f2da752d9.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.13ebecc9684f2da752d9.js.map +0 -1
package/dist/cjs/guest.js
CHANGED
|
@@ -119,7 +119,7 @@ class Guest {
|
|
|
119
119
|
try {
|
|
120
120
|
this.window.document;
|
|
121
121
|
this.window.close();
|
|
122
|
-
} catch
|
|
122
|
+
} catch {
|
|
123
123
|
this.#remoting.send({
|
|
124
124
|
targetWin: this.window,
|
|
125
125
|
targetOrigin: this.origin,
|
|
@@ -148,18 +148,18 @@ class Guest {
|
|
|
148
148
|
handShake = () => new Promise((resolve) => {
|
|
149
149
|
let handShakeCount = 0;
|
|
150
150
|
const handShakeRetries = 5;
|
|
151
|
-
|
|
151
|
+
const handShakeHandleRef = {};
|
|
152
152
|
const onAck = () => {
|
|
153
|
-
clearInterval(
|
|
153
|
+
clearInterval(handShakeHandleRef.id);
|
|
154
154
|
this.#remoting.unlisten({
|
|
155
155
|
messageType: import_microfe_common.MessageType.HandShakeAck,
|
|
156
156
|
callback: onAck
|
|
157
157
|
});
|
|
158
158
|
resolve(true);
|
|
159
159
|
};
|
|
160
|
-
|
|
160
|
+
handShakeHandleRef.id = setInterval(() => {
|
|
161
161
|
if (handShakeCount >= handShakeRetries) {
|
|
162
|
-
clearInterval(
|
|
162
|
+
clearInterval(handShakeHandleRef.id);
|
|
163
163
|
this.#remoting.unlisten({
|
|
164
164
|
messageType: import_microfe_common.MessageType.HandShakeAck,
|
|
165
165
|
callback: onAck
|
package/dist/cjs/host.js
CHANGED
|
@@ -37,7 +37,6 @@ const SANDBOX_DEFAULT = [
|
|
|
37
37
|
import_types.IFrameSandboxValues.AllowSameOrigin
|
|
38
38
|
];
|
|
39
39
|
class SSFHost {
|
|
40
|
-
/* eslint-enable indent */
|
|
41
40
|
/**
|
|
42
41
|
* unique identifier for the host
|
|
43
42
|
*/
|
|
@@ -57,7 +56,6 @@ class SSFHost {
|
|
|
57
56
|
/**
|
|
58
57
|
* reference to the analytics object
|
|
59
58
|
*/
|
|
60
|
-
#analyticsObj;
|
|
61
59
|
/**
|
|
62
60
|
* list of guests
|
|
63
61
|
*/
|
|
@@ -113,31 +111,16 @@ class SSFHost {
|
|
|
113
111
|
*/
|
|
114
112
|
constructor(hostId, option) {
|
|
115
113
|
this.hostId = hostId;
|
|
116
|
-
|
|
117
|
-
if (!option?.analyticsObj) throw new Error("Analytics object is required");
|
|
114
|
+
this.#validateHostOptions(option);
|
|
118
115
|
this.#logger = option.logger;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
enabled: option?.measurePerformance,
|
|
123
|
-
samplingRatio: option?.performanceSamplingRatio,
|
|
124
|
-
onError: (msg) => this.#logger.debug(msg)
|
|
125
|
-
};
|
|
126
|
-
this.#perfTracker = new import_performanceTracker.PerformanceTracker({
|
|
127
|
-
...perfOpts,
|
|
128
|
-
dedupWindowMs: option?.performanceDedupWindowMs
|
|
129
|
-
});
|
|
130
|
-
this.#guestPerfTracker = new import_performanceTracker.PerformanceTracker({
|
|
131
|
-
...perfOpts,
|
|
132
|
-
dedupWindowMs: 0
|
|
133
|
-
});
|
|
116
|
+
const trackers = this.#createPerfTrackers(option);
|
|
117
|
+
this.#perfTracker = trackers.perfTracker;
|
|
118
|
+
this.#guestPerfTracker = trackers.guestPerfTracker;
|
|
134
119
|
this.#correlationId = (0, import_uuid.v4)();
|
|
135
120
|
this.#remoting = new import_microfe_common.Remoting(this.#logger, this.#correlationId);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.#
|
|
139
|
-
this.#onGuestEventSubscribe = option?.onGuestEventSubscribe || null;
|
|
140
|
-
this.#onGuestEventUnsubscribe = option?.onGuestEventUnsubscribe || null;
|
|
121
|
+
this.#readyStateCallback = option.readyStateCallback ?? null;
|
|
122
|
+
this.#onGuestEventSubscribe = option.onGuestEventSubscribe ?? null;
|
|
123
|
+
this.#onGuestEventUnsubscribe = option.onGuestEventUnsubscribe ?? null;
|
|
141
124
|
this.#soManager = new import_microfe_common.ScriptingObjectManager();
|
|
142
125
|
this.#remoting.initialize(window);
|
|
143
126
|
this.#connect();
|
|
@@ -146,14 +129,31 @@ class SSFHost {
|
|
|
146
129
|
`host is initialized. hostId: ${this.hostId}, correlationId: ${this.#correlationId}`
|
|
147
130
|
);
|
|
148
131
|
}
|
|
149
|
-
#
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
132
|
+
#validateHostOptions(option) {
|
|
133
|
+
if (!option?.logger) throw new Error("Logger is required");
|
|
134
|
+
if (!option?.analyticsObj) throw new Error("Analytics object is required");
|
|
135
|
+
if (option.readyStateCallback && typeof option.readyStateCallback !== "function") {
|
|
136
|
+
throw new Error("readyStateCallback must be a function");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
#createPerfTrackers(option) {
|
|
140
|
+
const perfOpts = {
|
|
141
|
+
analyticsObj: option.analyticsObj,
|
|
142
|
+
enabled: option.measurePerformance,
|
|
143
|
+
samplingRatio: option.performanceSamplingRatio,
|
|
144
|
+
onError: (msg) => this.#logger.debug(msg)
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
perfTracker: new import_performanceTracker.PerformanceTracker({
|
|
148
|
+
...perfOpts,
|
|
149
|
+
dedupWindowMs: option.performanceDedupWindowMs
|
|
150
|
+
}),
|
|
151
|
+
guestPerfTracker: new import_performanceTracker.PerformanceTracker({
|
|
152
|
+
...perfOpts,
|
|
153
|
+
dedupWindowMs: 0
|
|
154
|
+
})
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
157
|
#closeAllPopupGuests = () => {
|
|
158
158
|
const popupIds = Array.from(this.#guests.values()).filter((guest) => guest.openMode === import_types.OpenMode.Popup).map((guest) => guest.id);
|
|
159
159
|
popupIds.forEach((id) => this.unloadGuest(id));
|
|
@@ -175,10 +175,7 @@ class SSFHost {
|
|
|
175
175
|
* @param value javascript object
|
|
176
176
|
* @returns true if the object is a scripting object
|
|
177
177
|
*/
|
|
178
|
-
#isScriptingObject = (value) =>
|
|
179
|
-
// eslint-disable-next-line no-underscore-dangle, @typescript-eslint/no-unsafe-member-access
|
|
180
|
-
typeof value?._toJSON === "function"
|
|
181
|
-
);
|
|
178
|
+
#isScriptingObject = (value) => typeof value === "object" && value !== null && "_toJSON" in value && typeof value._toJSON === "function";
|
|
182
179
|
#encodeResponse = (val, guest) => {
|
|
183
180
|
if (this.#isScriptingObject(val)) {
|
|
184
181
|
if (!this.#soManager.has(
|
|
@@ -193,15 +190,6 @@ class SSFHost {
|
|
|
193
190
|
}
|
|
194
191
|
return { type: "value", value: val };
|
|
195
192
|
};
|
|
196
|
-
#encodeException = (ex) => {
|
|
197
|
-
if (typeof ex === "string") {
|
|
198
|
-
return ex;
|
|
199
|
-
}
|
|
200
|
-
if (ex instanceof Error) {
|
|
201
|
-
return ex.message;
|
|
202
|
-
}
|
|
203
|
-
return "An unexpected error occurred in the host application";
|
|
204
|
-
};
|
|
205
193
|
#dispatchConfigEvent = (guest) => {
|
|
206
194
|
if (guest.ready) {
|
|
207
195
|
this.#remoting.send({
|
|
@@ -246,7 +234,7 @@ class SSFHost {
|
|
|
246
234
|
enumerable: true,
|
|
247
235
|
writable: true
|
|
248
236
|
});
|
|
249
|
-
resolve(func
|
|
237
|
+
resolve(Reflect.apply(func, obj, functionParams));
|
|
250
238
|
});
|
|
251
239
|
};
|
|
252
240
|
#handleGuestReadyComplete = ({
|
|
@@ -653,12 +641,7 @@ class SSFHost {
|
|
|
653
641
|
* @param value
|
|
654
642
|
* @returns
|
|
655
643
|
*/
|
|
656
|
-
#isProxyEvent = (value) =>
|
|
657
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
658
|
-
value instanceof import_microfe_common.ProxyEvent || // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
659
|
-
typeof value?.subscribe === "function"
|
|
660
|
-
);
|
|
661
|
-
// support v1 scripting objects
|
|
644
|
+
#isProxyEvent = (value) => value instanceof import_microfe_common.ProxyEvent || typeof value === "object" && value !== null && "subscribe" in value && typeof value.subscribe === "function";
|
|
662
645
|
/**
|
|
663
646
|
* Register pre-rendered guest application to host
|
|
664
647
|
* @param {AttachParam} param - parameters for attaching the guest
|
|
@@ -727,6 +710,25 @@ class SSFHost {
|
|
|
727
710
|
const popupUrl = handshakeToken ? `${url}#hs=${handshakeToken}` : url;
|
|
728
711
|
return { popupUrl, handshakeToken, trusted };
|
|
729
712
|
};
|
|
713
|
+
#focusExistingPopupGuest = (guest, url, title) => {
|
|
714
|
+
if (guest.window.closed) return;
|
|
715
|
+
if ((0, import_utils.isTrustedDomain)(url)) {
|
|
716
|
+
window.open("", title);
|
|
717
|
+
} else {
|
|
718
|
+
guest.window.focus();
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
#scheduleGuestLifecycleCallback = (callback, guestId, label) => {
|
|
722
|
+
setTimeout(() => {
|
|
723
|
+
try {
|
|
724
|
+
callback?.(guestId);
|
|
725
|
+
} catch (error) {
|
|
726
|
+
this.#logger.debug(
|
|
727
|
+
`Error occurred in ${label} for guest with id '${guestId}': ${error.message}`
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
}, 0);
|
|
731
|
+
};
|
|
730
732
|
#openPopupGuest = (param) => {
|
|
731
733
|
const {
|
|
732
734
|
url,
|
|
@@ -745,13 +747,7 @@ class SSFHost {
|
|
|
745
747
|
} = popupWindowFeatures;
|
|
746
748
|
let guest = this.#getGuestForUrl(url);
|
|
747
749
|
if (guest) {
|
|
748
|
-
|
|
749
|
-
if ((0, import_utils.isTrustedDomain)(url)) {
|
|
750
|
-
window.open("", title);
|
|
751
|
-
} else {
|
|
752
|
-
guest.window.focus();
|
|
753
|
-
}
|
|
754
|
-
}
|
|
750
|
+
this.#focusExistingPopupGuest(guest, url, title);
|
|
755
751
|
} else {
|
|
756
752
|
const windowFeatures = Object.entries({ width, height, top, left }).filter(([, v]) => v).map(([k, v]) => `${k}=${v}`).join(",");
|
|
757
753
|
const { popupUrl, handshakeToken, trusted } = this.#buildPopupUrl(url);
|
|
@@ -761,27 +757,10 @@ class SSFHost {
|
|
|
761
757
|
`popup, ${windowFeatures}`
|
|
762
758
|
);
|
|
763
759
|
if (!guestWindow) {
|
|
764
|
-
|
|
765
|
-
try {
|
|
766
|
-
onError?.(guestId);
|
|
767
|
-
} catch (error) {
|
|
768
|
-
this.#logger.debug(
|
|
769
|
-
`Error occurred in onError for guest with id '${guestId}': ${error.message}`
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
}, 0);
|
|
760
|
+
this.#scheduleGuestLifecycleCallback(onError, guestId, "onError");
|
|
773
761
|
throw new Error("Failed to open guest application in popup window");
|
|
774
|
-
} else {
|
|
775
|
-
setTimeout(() => {
|
|
776
|
-
try {
|
|
777
|
-
onLoad?.(guestId);
|
|
778
|
-
} catch (error) {
|
|
779
|
-
this.#logger.debug(
|
|
780
|
-
`Error occurred in onLoad for guest with id '${guestId}': ${error.message}`
|
|
781
|
-
);
|
|
782
|
-
}
|
|
783
|
-
}, 0);
|
|
784
762
|
}
|
|
763
|
+
this.#scheduleGuestLifecycleCallback(onLoad, guestId, "onLoad");
|
|
785
764
|
if (!trusted) {
|
|
786
765
|
guestWindow.opener = null;
|
|
787
766
|
}
|
|
@@ -798,53 +777,28 @@ class SSFHost {
|
|
|
798
777
|
}
|
|
799
778
|
return guest;
|
|
800
779
|
};
|
|
801
|
-
#
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
fitToContent = false,
|
|
815
|
-
disableSandbox = false,
|
|
816
|
-
sandboxValues = [],
|
|
817
|
-
customSandboxValues = [],
|
|
818
|
-
style = "",
|
|
819
|
-
permissionPolicy = ""
|
|
820
|
-
} = options;
|
|
821
|
-
if (!title) throw new Error("title is required");
|
|
822
|
-
if (fitToContent) this.#subscribeToGuestResizeEvent();
|
|
780
|
+
#createEmbedGuestFrame = ({
|
|
781
|
+
targetElementDocument,
|
|
782
|
+
guestId,
|
|
783
|
+
title,
|
|
784
|
+
url,
|
|
785
|
+
style,
|
|
786
|
+
disableSandbox,
|
|
787
|
+
sandboxValues,
|
|
788
|
+
customSandboxValues,
|
|
789
|
+
permissionPolicy,
|
|
790
|
+
onLoad,
|
|
791
|
+
onError
|
|
792
|
+
}) => {
|
|
823
793
|
const frame = targetElementDocument.createElement("iframe");
|
|
824
794
|
frame.setAttribute("id", guestId);
|
|
825
795
|
const onFrameLoad = () => {
|
|
826
|
-
|
|
827
|
-
try {
|
|
828
|
-
onLoad?.(guestId);
|
|
829
|
-
} catch (error) {
|
|
830
|
-
this.#logger.debug(
|
|
831
|
-
`Error occurred in onLoad for guest with id '${guestId}': ${error.message}`
|
|
832
|
-
);
|
|
833
|
-
}
|
|
834
|
-
}, 0);
|
|
796
|
+
this.#scheduleGuestLifecycleCallback(onLoad, guestId, "onLoad");
|
|
835
797
|
this.#logger.debug(`frame loaded for guest with id '${guestId}'`);
|
|
836
798
|
frame.removeEventListener("load", onFrameLoad);
|
|
837
799
|
};
|
|
838
800
|
const onFrameLoadFailure = () => {
|
|
839
|
-
|
|
840
|
-
try {
|
|
841
|
-
onError?.(guestId);
|
|
842
|
-
} catch (error) {
|
|
843
|
-
this.#logger.debug(
|
|
844
|
-
`Error occurred in onError for guest with id '${guestId}': ${error.message}`
|
|
845
|
-
);
|
|
846
|
-
}
|
|
847
|
-
}, 0);
|
|
801
|
+
this.#scheduleGuestLifecycleCallback(onError, guestId, "onError");
|
|
848
802
|
this.#logger.error(`frame load failed for guest with id '${guestId}'`);
|
|
849
803
|
frame.removeEventListener("error", onFrameLoadFailure);
|
|
850
804
|
};
|
|
@@ -863,6 +817,41 @@ class SSFHost {
|
|
|
863
817
|
frame.setAttribute("title", title);
|
|
864
818
|
frame.setAttribute("src", url);
|
|
865
819
|
if (permissionPolicy) frame.setAttribute("allow", permissionPolicy);
|
|
820
|
+
return frame;
|
|
821
|
+
};
|
|
822
|
+
#mountEmbedGuest = ({
|
|
823
|
+
guestId,
|
|
824
|
+
url,
|
|
825
|
+
title,
|
|
826
|
+
searchParams,
|
|
827
|
+
targetElement,
|
|
828
|
+
targetElementDocument,
|
|
829
|
+
onLoad,
|
|
830
|
+
onError,
|
|
831
|
+
options
|
|
832
|
+
}) => {
|
|
833
|
+
const {
|
|
834
|
+
fitToContent = false,
|
|
835
|
+
disableSandbox = false,
|
|
836
|
+
sandboxValues = [],
|
|
837
|
+
customSandboxValues = [],
|
|
838
|
+
style = "",
|
|
839
|
+
permissionPolicy = ""
|
|
840
|
+
} = options;
|
|
841
|
+
if (fitToContent) this.#subscribeToGuestResizeEvent();
|
|
842
|
+
const frame = this.#createEmbedGuestFrame({
|
|
843
|
+
targetElementDocument,
|
|
844
|
+
guestId,
|
|
845
|
+
title,
|
|
846
|
+
url,
|
|
847
|
+
style,
|
|
848
|
+
disableSandbox,
|
|
849
|
+
sandboxValues,
|
|
850
|
+
customSandboxValues,
|
|
851
|
+
permissionPolicy,
|
|
852
|
+
onLoad,
|
|
853
|
+
onError
|
|
854
|
+
});
|
|
866
855
|
targetElement.appendChild(frame);
|
|
867
856
|
const guestFrameEle = targetElementDocument.getElementById(
|
|
868
857
|
guestId
|
|
@@ -877,6 +866,31 @@ class SSFHost {
|
|
|
877
866
|
openMode: import_types.OpenMode.Embed
|
|
878
867
|
});
|
|
879
868
|
};
|
|
869
|
+
#openEmbedGuest = (param) => {
|
|
870
|
+
const {
|
|
871
|
+
url,
|
|
872
|
+
title,
|
|
873
|
+
targetElement,
|
|
874
|
+
searchParams,
|
|
875
|
+
guestId,
|
|
876
|
+
onLoad,
|
|
877
|
+
onError,
|
|
878
|
+
options = {}
|
|
879
|
+
} = param;
|
|
880
|
+
if (!title) throw new Error("title is required");
|
|
881
|
+
const targetElementDocument = targetElement.ownerDocument ?? document;
|
|
882
|
+
return this.#mountEmbedGuest({
|
|
883
|
+
guestId,
|
|
884
|
+
url,
|
|
885
|
+
title,
|
|
886
|
+
searchParams,
|
|
887
|
+
targetElement,
|
|
888
|
+
targetElementDocument,
|
|
889
|
+
onLoad,
|
|
890
|
+
onError,
|
|
891
|
+
options
|
|
892
|
+
});
|
|
893
|
+
};
|
|
880
894
|
#getGuestUrl = (url, params) => {
|
|
881
895
|
let querystring = "";
|
|
882
896
|
Object.keys(params).forEach((queryParam) => {
|
|
@@ -927,9 +941,7 @@ class SSFHost {
|
|
|
927
941
|
eventOptions
|
|
928
942
|
}) => this.dispatchEvent({
|
|
929
943
|
event,
|
|
930
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
931
944
|
eventParams,
|
|
932
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
933
945
|
eventOptions
|
|
934
946
|
});
|
|
935
947
|
const token = propValue.subscribe(
|
|
@@ -939,17 +951,18 @@ class SSFHost {
|
|
|
939
951
|
propValue.unsubscribe(token);
|
|
940
952
|
});
|
|
941
953
|
} else {
|
|
942
|
-
const
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
954
|
+
const v1Proxy = propValue;
|
|
955
|
+
const token = v1Proxy.subscribe?.(
|
|
956
|
+
(_obj, params, options) => {
|
|
957
|
+
void this.dispatchEvent({
|
|
958
|
+
event,
|
|
959
|
+
eventParams: params,
|
|
960
|
+
eventOptions: options
|
|
961
|
+
});
|
|
962
|
+
}
|
|
950
963
|
);
|
|
951
964
|
unsubscribers.push(() => {
|
|
952
|
-
|
|
965
|
+
if (token) v1Proxy.unsubscribe?.(token);
|
|
953
966
|
});
|
|
954
967
|
}
|
|
955
968
|
} else if ((0, import_utils.isFunction)(propValue)) {
|
|
@@ -1012,6 +1025,30 @@ class SSFHost {
|
|
|
1012
1025
|
`host is closed. hostId: ${this.hostId}, correlationId: ${this.#correlationId}`
|
|
1013
1026
|
);
|
|
1014
1027
|
};
|
|
1028
|
+
#buildEventObject = ({
|
|
1029
|
+
scriptingObject,
|
|
1030
|
+
eventName,
|
|
1031
|
+
eventParams,
|
|
1032
|
+
eventHandler,
|
|
1033
|
+
timeout
|
|
1034
|
+
}) => {
|
|
1035
|
+
const eventObj = {
|
|
1036
|
+
object: scriptingObject._toJSON(),
|
|
1037
|
+
eventName,
|
|
1038
|
+
eventParams,
|
|
1039
|
+
eventHandler,
|
|
1040
|
+
eventOptions: {
|
|
1041
|
+
allowsFeedback: false
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
if (timeout && !Number.isNaN(timeout)) {
|
|
1045
|
+
eventObj.eventOptions = {
|
|
1046
|
+
allowsFeedback: true,
|
|
1047
|
+
timeout: Number(timeout)
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
return eventObj;
|
|
1051
|
+
};
|
|
1015
1052
|
#dispatchEventToMatchingGuests = ({
|
|
1016
1053
|
targetGuest,
|
|
1017
1054
|
guestCapabilities,
|
|
@@ -1064,22 +1101,13 @@ class SSFHost {
|
|
|
1064
1101
|
);
|
|
1065
1102
|
return Promise.resolve([]);
|
|
1066
1103
|
}
|
|
1067
|
-
const eventObj = {
|
|
1068
|
-
|
|
1069
|
-
object: scriptingObject._toJSON(),
|
|
1104
|
+
const eventObj = this.#buildEventObject({
|
|
1105
|
+
scriptingObject,
|
|
1070
1106
|
eventName: name,
|
|
1071
1107
|
eventParams,
|
|
1072
1108
|
eventHandler,
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
}
|
|
1076
|
-
};
|
|
1077
|
-
if (timeout && !Number.isNaN(timeout)) {
|
|
1078
|
-
eventObj.eventOptions = {
|
|
1079
|
-
allowsFeedback: true,
|
|
1080
|
-
timeout: Number(timeout)
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1109
|
+
timeout
|
|
1110
|
+
});
|
|
1083
1111
|
const guestPromises = [];
|
|
1084
1112
|
let eventTimingToken;
|
|
1085
1113
|
const dispatchToGuest = (guest) => {
|
|
@@ -1149,6 +1177,14 @@ class SSFHost {
|
|
|
1149
1177
|
* @returns scripting object
|
|
1150
1178
|
*/
|
|
1151
1179
|
getScriptingObject = (objectId, params) => this.#soManager.getObject(objectId, params?.guest);
|
|
1180
|
+
#resolveUniqueGuestInstanceId = (guestId) => {
|
|
1181
|
+
if (!this.#guests.has(guestId)) return guestId;
|
|
1182
|
+
let counter = 1;
|
|
1183
|
+
while (this.#guests.has(`${guestId}-${counter}`)) {
|
|
1184
|
+
counter += 1;
|
|
1185
|
+
}
|
|
1186
|
+
return `${guestId}-${counter}`;
|
|
1187
|
+
};
|
|
1152
1188
|
/**
|
|
1153
1189
|
* loads guest application inside sandboxed iframe
|
|
1154
1190
|
* @param {LoadGuestParam} param - parameters for loading the guest application
|
|
@@ -1167,21 +1203,14 @@ class SSFHost {
|
|
|
1167
1203
|
metadata
|
|
1168
1204
|
} = param;
|
|
1169
1205
|
if (!guestId) throw new Error("id for guest application is required");
|
|
1170
|
-
|
|
1171
|
-
if (this.#guests.has(instanceId)) {
|
|
1172
|
-
let counter = 1;
|
|
1173
|
-
while (this.#guests.has(`${guestId}-${counter}`)) {
|
|
1174
|
-
counter += 1;
|
|
1175
|
-
}
|
|
1176
|
-
instanceId = `${guestId}-${counter}`;
|
|
1177
|
-
}
|
|
1206
|
+
const instanceId = this.#resolveUniqueGuestInstanceId(guestId);
|
|
1178
1207
|
const { openMode = import_types.OpenMode.Embed, popupWindowFeatures = {} } = options;
|
|
1179
1208
|
const srcUrl = this.#getGuestUrl(url, searchParams);
|
|
1180
|
-
let guest = null;
|
|
1181
1209
|
this.#perfTracker.start("SSF.Guest.Load", {
|
|
1182
1210
|
appId: instanceId,
|
|
1183
1211
|
appUrl: srcUrl
|
|
1184
1212
|
});
|
|
1213
|
+
let guest;
|
|
1185
1214
|
if (openMode === import_types.OpenMode.Popup) {
|
|
1186
1215
|
guest = this.#openPopupGuest({
|
|
1187
1216
|
guestId: instanceId,
|
package/dist/cjs/tests/utils.js
CHANGED
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
21
|
createHost: () => createHost,
|
|
22
|
+
getCallContext: () => getCallContext,
|
|
22
23
|
initGuest: () => initGuest,
|
|
23
24
|
postMessage: () => postMessage,
|
|
24
25
|
releaseJSThread: () => releaseJSThread
|
|
@@ -75,3 +76,10 @@ const initGuest = (guestId, capabilities = { eventFeedback: true }) => {
|
|
|
75
76
|
const releaseJSThread = () => new Promise((resolve) => {
|
|
76
77
|
setTimeout(resolve, 0);
|
|
77
78
|
});
|
|
79
|
+
const getCallContext = (fn) => {
|
|
80
|
+
const callContext = fn.callContext;
|
|
81
|
+
if (!callContext) {
|
|
82
|
+
throw new Error("callContext not set on function");
|
|
83
|
+
}
|
|
84
|
+
return callContext;
|
|
85
|
+
};
|
package/dist/cjs/utils.js
CHANGED
package/dist/esm/guest.js
CHANGED
|
@@ -96,7 +96,7 @@ class Guest {
|
|
|
96
96
|
try {
|
|
97
97
|
this.window.document;
|
|
98
98
|
this.window.close();
|
|
99
|
-
} catch
|
|
99
|
+
} catch {
|
|
100
100
|
this.#remoting.send({
|
|
101
101
|
targetWin: this.window,
|
|
102
102
|
targetOrigin: this.origin,
|
|
@@ -125,18 +125,18 @@ class Guest {
|
|
|
125
125
|
handShake = () => new Promise((resolve) => {
|
|
126
126
|
let handShakeCount = 0;
|
|
127
127
|
const handShakeRetries = 5;
|
|
128
|
-
|
|
128
|
+
const handShakeHandleRef = {};
|
|
129
129
|
const onAck = () => {
|
|
130
|
-
clearInterval(
|
|
130
|
+
clearInterval(handShakeHandleRef.id);
|
|
131
131
|
this.#remoting.unlisten({
|
|
132
132
|
messageType: MessageType.HandShakeAck,
|
|
133
133
|
callback: onAck
|
|
134
134
|
});
|
|
135
135
|
resolve(true);
|
|
136
136
|
};
|
|
137
|
-
|
|
137
|
+
handShakeHandleRef.id = setInterval(() => {
|
|
138
138
|
if (handShakeCount >= handShakeRetries) {
|
|
139
|
-
clearInterval(
|
|
139
|
+
clearInterval(handShakeHandleRef.id);
|
|
140
140
|
this.#remoting.unlisten({
|
|
141
141
|
messageType: MessageType.HandShakeAck,
|
|
142
142
|
callback: onAck
|