@elliemae/ssf-guest 2.29.0-alpha.0 → 2.29.1
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 +108 -78
- package/dist/cjs/tests/utils.js +1 -0
- package/dist/cjs/utils.js +4 -4
- package/dist/cjs/v1-adapter.js +8 -9
- package/dist/esm/guest.js +108 -78
- package/dist/esm/tests/utils.js +1 -0
- package/dist/esm/utils.js +4 -4
- package/dist/esm/v1-adapter.js +8 -9
- package/dist/public/callchain-grandchild.html +1 -1
- package/dist/public/creditService.html +1 -1
- package/dist/public/e2e-guest.html +1 -1
- package/dist/public/index.html +1 -1
- package/dist/public/js/emuiSsfGuest.5a028ebcac3f79900cb2.js +3 -0
- package/dist/public/js/emuiSsfGuest.5a028ebcac3f79900cb2.js.br +0 -0
- package/dist/public/js/emuiSsfGuest.5a028ebcac3f79900cb2.js.gz +0 -0
- package/dist/public/js/emuiSsfGuest.5a028ebcac3f79900cb2.js.map +1 -0
- package/dist/public/loanValidation.html +1 -1
- package/dist/public/pricingService.html +1 -1
- package/dist/public/titleService.html +1 -1
- package/dist/public/v2-guest.html +1 -1
- package/dist/types/lib/guest.d.ts +8 -4
- package/dist/types/lib/tests/utils.d.ts +2 -2
- package/dist/types/lib/typings/window.d.ts +7 -9
- 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/package.json +8 -9
- package/dist/public/js/emuiSsfGuest.e7547c98c8ccfd0654bd.js +0 -3
- package/dist/public/js/emuiSsfGuest.e7547c98c8ccfd0654bd.js.br +0 -0
- package/dist/public/js/emuiSsfGuest.e7547c98c8ccfd0654bd.js.gz +0 -0
- package/dist/public/js/emuiSsfGuest.e7547c98c8ccfd0654bd.js.map +0 -1
package/dist/cjs/guest.js
CHANGED
|
@@ -45,6 +45,7 @@ var ResponseType = /* @__PURE__ */ ((ResponseType2) => {
|
|
|
45
45
|
})(ResponseType || {});
|
|
46
46
|
const KEEP_ALIVE_INTERVAL = 12e4;
|
|
47
47
|
const KEEP_ALIVE_OBJECT_TIMEOUT = 2e3;
|
|
48
|
+
const OBJECT_GET_TIMEOUT_MS = 2e3;
|
|
48
49
|
const capabilities = {
|
|
49
50
|
eventFeedback: true
|
|
50
51
|
};
|
|
@@ -90,6 +91,7 @@ const getDiagnosticsAPIUrl = () => {
|
|
|
90
91
|
return diagnosticsEndpoint[hostName] || diagnosticsEndpoint["cdn.mortgagetech.q1.ice.com"];
|
|
91
92
|
};
|
|
92
93
|
class SSFGuest {
|
|
94
|
+
/* eslint-enable indent */
|
|
93
95
|
#correlationId;
|
|
94
96
|
#logger;
|
|
95
97
|
#remoting;
|
|
@@ -113,6 +115,24 @@ class SSFGuest {
|
|
|
113
115
|
}
|
|
114
116
|
return { hostWindow: this.#hostWindow, hostOrigin: this.#hostOrigin };
|
|
115
117
|
}
|
|
118
|
+
#buildGuestOptions(param) {
|
|
119
|
+
let guestOptions = { ...capabilities };
|
|
120
|
+
if (param) {
|
|
121
|
+
const restOptions = { ...param };
|
|
122
|
+
delete restOptions.window;
|
|
123
|
+
guestOptions = { ...guestOptions, ...restOptions };
|
|
124
|
+
}
|
|
125
|
+
return guestOptions;
|
|
126
|
+
}
|
|
127
|
+
#sendGuestReady(guestOptions) {
|
|
128
|
+
const { hostWindow, hostOrigin } = this.#requireHost();
|
|
129
|
+
this.#remoting.send({
|
|
130
|
+
targetWin: hostWindow,
|
|
131
|
+
targetOrigin: hostOrigin,
|
|
132
|
+
messageType: import_microfe_common.MessageType.GuestReady,
|
|
133
|
+
messageBody: guestOptions
|
|
134
|
+
});
|
|
135
|
+
}
|
|
116
136
|
/**
|
|
117
137
|
* get bearer token to access api during connect operation
|
|
118
138
|
*/
|
|
@@ -137,6 +157,10 @@ class SSFGuest {
|
|
|
137
157
|
* interval to keep host session alive.
|
|
138
158
|
*/
|
|
139
159
|
#keepAliveInterval = KEEP_ALIVE_INTERVAL;
|
|
160
|
+
/**
|
|
161
|
+
* options for the logger
|
|
162
|
+
*/
|
|
163
|
+
#loggerOptions;
|
|
140
164
|
/**
|
|
141
165
|
* throttled keep alive function
|
|
142
166
|
*/
|
|
@@ -150,11 +174,13 @@ class SSFGuest {
|
|
|
150
174
|
constructor(options) {
|
|
151
175
|
const {
|
|
152
176
|
console: logToConsole = false,
|
|
177
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
153
178
|
url = window.__ICE__?.diagnosticsUrl || getDiagnosticsAPIUrl(),
|
|
154
179
|
index = "ssf-guest-v2",
|
|
155
180
|
team = "ICE",
|
|
156
181
|
appName = "SSF Guest V2 Application"
|
|
157
182
|
} = options?.logger ?? {};
|
|
183
|
+
this.#loggerOptions = options?.logger;
|
|
158
184
|
this.#usesDevConnectAPI = options?.usesDevConnectAPI ?? false;
|
|
159
185
|
this.#keepAlive = options?.keepAlive ?? true;
|
|
160
186
|
this.#keepAliveInterval = options?.keepAliveInterval ?? KEEP_ALIVE_INTERVAL;
|
|
@@ -203,11 +229,12 @@ class SSFGuest {
|
|
|
203
229
|
soJSON.functions.forEach((functionName) => {
|
|
204
230
|
Object.defineProperty(ctrl, functionName, {
|
|
205
231
|
value: async (...args) => {
|
|
206
|
-
const
|
|
207
|
-
const callerChain =
|
|
232
|
+
const fnCallContext = ctrl[functionName]?.callContext;
|
|
233
|
+
const callerChain = fnCallContext?.callChain;
|
|
208
234
|
return this.#invoke({
|
|
209
235
|
objectId: ctrl.id,
|
|
210
236
|
functionName,
|
|
237
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
211
238
|
functionParams: [...args],
|
|
212
239
|
callerChain
|
|
213
240
|
});
|
|
@@ -394,8 +421,13 @@ class SSFGuest {
|
|
|
394
421
|
this.#logger.debug(`Received event "${eventId}" from host`);
|
|
395
422
|
let listeners;
|
|
396
423
|
if (body.eventHandler) {
|
|
397
|
-
|
|
398
|
-
|
|
424
|
+
listeners = [
|
|
425
|
+
{
|
|
426
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
427
|
+
callback: window[body.eventHandler],
|
|
428
|
+
token: (0, import_uuid.v4)()
|
|
429
|
+
}
|
|
430
|
+
];
|
|
399
431
|
} else {
|
|
400
432
|
listeners = this.#eventListeners.get(eventId) || [];
|
|
401
433
|
}
|
|
@@ -403,10 +435,7 @@ class SSFGuest {
|
|
|
403
435
|
listeners.forEach((callbackInfo) => {
|
|
404
436
|
if (callbackInfo?.callback) {
|
|
405
437
|
if (callbackInfo.criteria) {
|
|
406
|
-
const criteriaMatched = body.eventParams ? this.#matchesCriteria(
|
|
407
|
-
body.eventParams,
|
|
408
|
-
callbackInfo.criteria
|
|
409
|
-
) : false;
|
|
438
|
+
const criteriaMatched = body.eventParams ? this.#matchesCriteria(body.eventParams, callbackInfo.criteria) : false;
|
|
410
439
|
if (!criteriaMatched) {
|
|
411
440
|
this.#logger.debug(
|
|
412
441
|
`Event ${eventId} did not match criteria for subscriber ${callbackInfo.callback.name}`
|
|
@@ -552,32 +581,37 @@ class SSFGuest {
|
|
|
552
581
|
* Initialize guest using script
|
|
553
582
|
* @param {string} scriptUri uri of the script
|
|
554
583
|
* @param {HTMLElement} containerElement dom element to inject the script at
|
|
584
|
+
* @param {object} [options] additional options
|
|
585
|
+
* @param {boolean} [options.asModule=true] inject the script as an ES module
|
|
555
586
|
*/
|
|
556
|
-
addScript = async (scriptUri, containerElement) => {
|
|
587
|
+
addScript = async (scriptUri, containerElement, options = {}) => {
|
|
588
|
+
const { asModule = true } = options;
|
|
557
589
|
if (!this.#created && scriptUri) {
|
|
558
590
|
await this.connect();
|
|
559
591
|
const scriptEle = document.createElement("script");
|
|
560
592
|
scriptEle.setAttribute("src", scriptUri);
|
|
561
|
-
|
|
593
|
+
if (asModule) {
|
|
594
|
+
scriptEle.setAttribute("type", "module");
|
|
595
|
+
}
|
|
562
596
|
await new Promise((resolve, reject) => {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
}
|
|
597
|
+
let onScriptLoad;
|
|
598
|
+
let onScriptError;
|
|
599
|
+
const cleanup = () => {
|
|
600
|
+
scriptEle.removeEventListener("load", onScriptLoad);
|
|
601
|
+
scriptEle.removeEventListener("error", onScriptError);
|
|
602
|
+
};
|
|
603
|
+
onScriptLoad = () => {
|
|
604
|
+
cleanup();
|
|
605
|
+
this.#created = true;
|
|
606
|
+
(0, import_v1_adapter.setScriptOnlyGuest)(true);
|
|
607
|
+
resolve();
|
|
608
|
+
};
|
|
609
|
+
onScriptError = () => {
|
|
610
|
+
cleanup();
|
|
611
|
+
reject(new Error(`Failed to load script: ${scriptUri}`));
|
|
578
612
|
};
|
|
579
|
-
scriptEle.addEventListener("load",
|
|
580
|
-
scriptEle.addEventListener("error",
|
|
613
|
+
scriptEle.addEventListener("load", onScriptLoad);
|
|
614
|
+
scriptEle.addEventListener("error", onScriptError);
|
|
581
615
|
this.#scriptElement = containerElement.appendChild(scriptEle);
|
|
582
616
|
});
|
|
583
617
|
}
|
|
@@ -585,7 +619,6 @@ class SSFGuest {
|
|
|
585
619
|
/**
|
|
586
620
|
* Close the connection to the host
|
|
587
621
|
*/
|
|
588
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
589
622
|
close = async () => {
|
|
590
623
|
if (!this.#isConnected) return;
|
|
591
624
|
if (this.#hostWindow && this.#hostOrigin) {
|
|
@@ -627,56 +660,49 @@ class SSFGuest {
|
|
|
627
660
|
*/
|
|
628
661
|
// eslint-disable-next-line max-statements
|
|
629
662
|
connect = async (param) => {
|
|
630
|
-
if (
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (param) {
|
|
634
|
-
const { window: paramWindow, ...restOptions } = param;
|
|
635
|
-
if (paramWindow) guestWindow = paramWindow;
|
|
636
|
-
guestOptions = { ...guestOptions, ...restOptions };
|
|
637
|
-
}
|
|
638
|
-
const hostDetails = await (0, import_utils.getHostDetails)();
|
|
639
|
-
this.#hostOrigin = hostDetails.origin;
|
|
640
|
-
this.#hostWindow = hostDetails.window;
|
|
641
|
-
this.#remoting.initialize(guestWindow);
|
|
642
|
-
this.#remoting.addSender({
|
|
643
|
-
origin: this.#hostOrigin,
|
|
644
|
-
window: this.#hostWindow
|
|
645
|
-
});
|
|
646
|
-
this.#remoting.listen({
|
|
647
|
-
messageType: import_microfe_common.MessageType.ObjectEvent,
|
|
648
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
649
|
-
callback: this.#handleObjectEvent.bind(this)
|
|
650
|
-
});
|
|
651
|
-
this.#remoting.listen({
|
|
652
|
-
messageType: import_microfe_common.MessageType.HostConfig,
|
|
653
|
-
callback: this.#handleConfigChangeEvent.bind(this)
|
|
654
|
-
});
|
|
655
|
-
this.#remoting.listen({
|
|
656
|
-
messageType: import_microfe_common.MessageType.GuestFocus,
|
|
657
|
-
callback: this.#handleFocusEvent.bind(this)
|
|
658
|
-
});
|
|
659
|
-
this.#remoting.listen({
|
|
660
|
-
messageType: import_microfe_common.MessageType.HostClose,
|
|
661
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
662
|
-
callback: this.#handleHostClose.bind(this)
|
|
663
|
-
});
|
|
664
|
-
this.#remoting.send({
|
|
665
|
-
targetWin: this.#hostWindow,
|
|
666
|
-
targetOrigin: this.#hostOrigin,
|
|
667
|
-
messageType: import_microfe_common.MessageType.GuestReady,
|
|
668
|
-
messageBody: guestOptions
|
|
669
|
-
});
|
|
670
|
-
this.#isConnected = true;
|
|
671
|
-
this.#handleParentClose();
|
|
672
|
-
if (this.#usesDevConnectAPI) await this.getAuthToken();
|
|
673
|
-
await this.#startKeepSessionAlive();
|
|
674
|
-
window.addEventListener("beforeunload", this.close);
|
|
675
|
-
this.#logger.audit({
|
|
676
|
-
message: "Guest connected to host",
|
|
677
|
-
guestUrl: window.location.href
|
|
678
|
-
});
|
|
663
|
+
if (this.#isConnected) {
|
|
664
|
+
this.#sendGuestReady(this.#buildGuestOptions(param));
|
|
665
|
+
return;
|
|
679
666
|
}
|
|
667
|
+
let guestWindow = window;
|
|
668
|
+
if (param?.window) guestWindow = param.window;
|
|
669
|
+
const guestOptions = this.#buildGuestOptions(param);
|
|
670
|
+
const hostDetails = await (0, import_utils.getHostDetails)();
|
|
671
|
+
this.#hostOrigin = hostDetails.origin;
|
|
672
|
+
this.#hostWindow = hostDetails.window;
|
|
673
|
+
this.#remoting.initialize(guestWindow);
|
|
674
|
+
this.#remoting.addSender({
|
|
675
|
+
origin: this.#hostOrigin,
|
|
676
|
+
window: this.#hostWindow
|
|
677
|
+
});
|
|
678
|
+
this.#remoting.listen({
|
|
679
|
+
messageType: import_microfe_common.MessageType.ObjectEvent,
|
|
680
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
681
|
+
callback: this.#handleObjectEvent.bind(this)
|
|
682
|
+
});
|
|
683
|
+
this.#remoting.listen({
|
|
684
|
+
messageType: import_microfe_common.MessageType.HostConfig,
|
|
685
|
+
callback: this.#handleConfigChangeEvent.bind(this)
|
|
686
|
+
});
|
|
687
|
+
this.#remoting.listen({
|
|
688
|
+
messageType: import_microfe_common.MessageType.GuestFocus,
|
|
689
|
+
callback: this.#handleFocusEvent.bind(this)
|
|
690
|
+
});
|
|
691
|
+
this.#remoting.listen({
|
|
692
|
+
messageType: import_microfe_common.MessageType.HostClose,
|
|
693
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
694
|
+
callback: this.#handleHostClose.bind(this)
|
|
695
|
+
});
|
|
696
|
+
this.#sendGuestReady(guestOptions);
|
|
697
|
+
this.#isConnected = true;
|
|
698
|
+
this.#handleParentClose();
|
|
699
|
+
if (this.#usesDevConnectAPI) await this.getAuthToken();
|
|
700
|
+
await this.#startKeepSessionAlive();
|
|
701
|
+
window.addEventListener("beforeunload", this.close);
|
|
702
|
+
this.#logger.audit({
|
|
703
|
+
message: "Guest connected to host",
|
|
704
|
+
guestUrl: window.location.href
|
|
705
|
+
});
|
|
680
706
|
};
|
|
681
707
|
/**
|
|
682
708
|
* Get bearer token to access dev connect api
|
|
@@ -720,8 +746,12 @@ class SSFGuest {
|
|
|
720
746
|
messageType: import_microfe_common.MessageType.ObjectGet,
|
|
721
747
|
messageBody: {
|
|
722
748
|
objectId
|
|
723
|
-
}
|
|
749
|
+
},
|
|
750
|
+
responseTimeoutMs: OBJECT_GET_TIMEOUT_MS
|
|
724
751
|
});
|
|
752
|
+
if (!response?.object) {
|
|
753
|
+
throw new Error(`The requested object (${objectId}) is not available`);
|
|
754
|
+
}
|
|
725
755
|
const obj = this.#fromJSON(response.object);
|
|
726
756
|
this.#auditThrottler.log(`getObject:${objectId}`, {
|
|
727
757
|
message: "Received scripting object from host",
|
package/dist/cjs/tests/utils.js
CHANGED
|
@@ -59,6 +59,7 @@ const postMessage = ({
|
|
|
59
59
|
new MessageEvent("message", {
|
|
60
60
|
source: srcWindow,
|
|
61
61
|
origin: (0, import_utils.getOrigin)(srcWindow.location.href),
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
62
63
|
data: {
|
|
63
64
|
source: "elli:remoting",
|
|
64
65
|
...message
|
package/dist/cjs/utils.js
CHANGED
|
@@ -30,7 +30,7 @@ const getParentWindowLocation = () => {
|
|
|
30
30
|
const { parent } = window;
|
|
31
31
|
try {
|
|
32
32
|
return parent?.location?.href;
|
|
33
|
-
} catch {
|
|
33
|
+
} catch (e) {
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
36
36
|
};
|
|
@@ -74,14 +74,14 @@ const getHostDetails = () => new Promise((resolve, reject) => {
|
|
|
74
74
|
if (!isEmbedded()) {
|
|
75
75
|
const currentWindow = window;
|
|
76
76
|
const expectedToken = getHandshakeToken();
|
|
77
|
-
|
|
77
|
+
let timer;
|
|
78
78
|
const onMessage = (event) => {
|
|
79
79
|
if (isHandshakeTrusted(event, expectedToken)) {
|
|
80
80
|
const { source, type } = event.data || {};
|
|
81
81
|
if (source === MESSAGE_SOURCE && type === import_microfe_common.MessageType.HandShake) {
|
|
82
82
|
const { origin } = event;
|
|
83
83
|
const hostWindow = event.source;
|
|
84
|
-
clearTimeout(
|
|
84
|
+
clearTimeout(timer);
|
|
85
85
|
(0, import_microfe_common.sendMessage)({
|
|
86
86
|
targetWin: hostWindow,
|
|
87
87
|
targetOrigin: origin,
|
|
@@ -93,7 +93,7 @@ const getHostDetails = () => new Promise((resolve, reject) => {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
-
|
|
96
|
+
timer = setTimeout(() => {
|
|
97
97
|
currentWindow.removeEventListener("message", onMessage);
|
|
98
98
|
reject(
|
|
99
99
|
new Error(`Host handshake timed out after ${HANDSHAKE_TIMEOUT_MS}ms`)
|
package/dist/cjs/v1-adapter.js
CHANGED
|
@@ -40,7 +40,7 @@ const setupV1Adapter = (guestV2 = null) => {
|
|
|
40
40
|
window.elli = window.elli ?? {};
|
|
41
41
|
window.elli.script = {
|
|
42
42
|
guest: {
|
|
43
|
-
create: (scriptUri, element) => getGuest().addScript(scriptUri, element)
|
|
43
|
+
create: (scriptUri, element) => getGuest().addScript(scriptUri, element, { asModule: false })
|
|
44
44
|
},
|
|
45
45
|
connect: (params) => {
|
|
46
46
|
if (!scriptOnlyGuest)
|
|
@@ -54,9 +54,7 @@ const setupV1Adapter = (guestV2 = null) => {
|
|
|
54
54
|
console.warn(
|
|
55
55
|
"elli.script.getObject is deprecated. Please use getObject method of SSFGuest class instead, const guest = new ice.guest.SSFGuest(); await guest.getObject(objectName);"
|
|
56
56
|
);
|
|
57
|
-
return getGuest().getObject(
|
|
58
|
-
objectName
|
|
59
|
-
);
|
|
57
|
+
return getGuest().getObject(objectName);
|
|
60
58
|
},
|
|
61
59
|
setLogLevel: (level) => {
|
|
62
60
|
if (!scriptOnlyGuest)
|
|
@@ -69,24 +67,25 @@ const setupV1Adapter = (guestV2 = null) => {
|
|
|
69
67
|
subscribe: (objectId, eventName, callback, options) => {
|
|
70
68
|
if (!scriptOnlyGuest)
|
|
71
69
|
console.warn(
|
|
70
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
72
71
|
"elli.script.subscribe is deprecated. Please use subscribe method of SSFGuest class instead, const guest = new ice.guest.SSFGuest(); guest.subscribe({ eventId: `${objectId}.${eventName}`, callback: (event) => { console.log(event); });"
|
|
73
72
|
);
|
|
74
73
|
return getGuest().subscribe({
|
|
75
74
|
eventId: `${objectId}.${eventName}`,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
event?.eventOptions
|
|
80
|
-
)),
|
|
75
|
+
// eslint-disable-line @typescript-eslint/no-unsafe-assignment
|
|
76
|
+
callback: (event) => callback(event?.obj, event?.eventParams, event?.eventOptions),
|
|
77
|
+
// eslint-disable-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
81
78
|
criteria: options?.criteria
|
|
82
79
|
});
|
|
83
80
|
},
|
|
84
81
|
unsubscribe: (objectId, eventName, token) => {
|
|
85
82
|
if (!scriptOnlyGuest)
|
|
86
83
|
console.warn(
|
|
84
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
87
85
|
"elli.script.unsubscribe is deprecated. Please use unsubscribe method of SSFGuest class instead, const guest = new ice.guest.SSFGuest(); guest.unsubscribe({ eventId: `${objectId}.${eventName}`, token });"
|
|
88
86
|
);
|
|
89
87
|
return getGuest().unsubscribe({
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
90
89
|
eventId: `${objectId}.${eventName}`,
|
|
91
90
|
token
|
|
92
91
|
});
|
package/dist/esm/guest.js
CHANGED
|
@@ -32,6 +32,7 @@ var ResponseType = /* @__PURE__ */ ((ResponseType2) => {
|
|
|
32
32
|
})(ResponseType || {});
|
|
33
33
|
const KEEP_ALIVE_INTERVAL = 12e4;
|
|
34
34
|
const KEEP_ALIVE_OBJECT_TIMEOUT = 2e3;
|
|
35
|
+
const OBJECT_GET_TIMEOUT_MS = 2e3;
|
|
35
36
|
const capabilities = {
|
|
36
37
|
eventFeedback: true
|
|
37
38
|
};
|
|
@@ -77,6 +78,7 @@ const getDiagnosticsAPIUrl = () => {
|
|
|
77
78
|
return diagnosticsEndpoint[hostName] || diagnosticsEndpoint["cdn.mortgagetech.q1.ice.com"];
|
|
78
79
|
};
|
|
79
80
|
class SSFGuest {
|
|
81
|
+
/* eslint-enable indent */
|
|
80
82
|
#correlationId;
|
|
81
83
|
#logger;
|
|
82
84
|
#remoting;
|
|
@@ -100,6 +102,24 @@ class SSFGuest {
|
|
|
100
102
|
}
|
|
101
103
|
return { hostWindow: this.#hostWindow, hostOrigin: this.#hostOrigin };
|
|
102
104
|
}
|
|
105
|
+
#buildGuestOptions(param) {
|
|
106
|
+
let guestOptions = { ...capabilities };
|
|
107
|
+
if (param) {
|
|
108
|
+
const restOptions = { ...param };
|
|
109
|
+
delete restOptions.window;
|
|
110
|
+
guestOptions = { ...guestOptions, ...restOptions };
|
|
111
|
+
}
|
|
112
|
+
return guestOptions;
|
|
113
|
+
}
|
|
114
|
+
#sendGuestReady(guestOptions) {
|
|
115
|
+
const { hostWindow, hostOrigin } = this.#requireHost();
|
|
116
|
+
this.#remoting.send({
|
|
117
|
+
targetWin: hostWindow,
|
|
118
|
+
targetOrigin: hostOrigin,
|
|
119
|
+
messageType: MessageType.GuestReady,
|
|
120
|
+
messageBody: guestOptions
|
|
121
|
+
});
|
|
122
|
+
}
|
|
103
123
|
/**
|
|
104
124
|
* get bearer token to access api during connect operation
|
|
105
125
|
*/
|
|
@@ -124,6 +144,10 @@ class SSFGuest {
|
|
|
124
144
|
* interval to keep host session alive.
|
|
125
145
|
*/
|
|
126
146
|
#keepAliveInterval = KEEP_ALIVE_INTERVAL;
|
|
147
|
+
/**
|
|
148
|
+
* options for the logger
|
|
149
|
+
*/
|
|
150
|
+
#loggerOptions;
|
|
127
151
|
/**
|
|
128
152
|
* throttled keep alive function
|
|
129
153
|
*/
|
|
@@ -137,11 +161,13 @@ class SSFGuest {
|
|
|
137
161
|
constructor(options) {
|
|
138
162
|
const {
|
|
139
163
|
console: logToConsole = false,
|
|
164
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
140
165
|
url = window.__ICE__?.diagnosticsUrl || getDiagnosticsAPIUrl(),
|
|
141
166
|
index = "ssf-guest-v2",
|
|
142
167
|
team = "ICE",
|
|
143
168
|
appName = "SSF Guest V2 Application"
|
|
144
169
|
} = options?.logger ?? {};
|
|
170
|
+
this.#loggerOptions = options?.logger;
|
|
145
171
|
this.#usesDevConnectAPI = options?.usesDevConnectAPI ?? false;
|
|
146
172
|
this.#keepAlive = options?.keepAlive ?? true;
|
|
147
173
|
this.#keepAliveInterval = options?.keepAliveInterval ?? KEEP_ALIVE_INTERVAL;
|
|
@@ -190,11 +216,12 @@ class SSFGuest {
|
|
|
190
216
|
soJSON.functions.forEach((functionName) => {
|
|
191
217
|
Object.defineProperty(ctrl, functionName, {
|
|
192
218
|
value: async (...args) => {
|
|
193
|
-
const
|
|
194
|
-
const callerChain =
|
|
219
|
+
const fnCallContext = ctrl[functionName]?.callContext;
|
|
220
|
+
const callerChain = fnCallContext?.callChain;
|
|
195
221
|
return this.#invoke({
|
|
196
222
|
objectId: ctrl.id,
|
|
197
223
|
functionName,
|
|
224
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
198
225
|
functionParams: [...args],
|
|
199
226
|
callerChain
|
|
200
227
|
});
|
|
@@ -381,8 +408,13 @@ class SSFGuest {
|
|
|
381
408
|
this.#logger.debug(`Received event "${eventId}" from host`);
|
|
382
409
|
let listeners;
|
|
383
410
|
if (body.eventHandler) {
|
|
384
|
-
|
|
385
|
-
|
|
411
|
+
listeners = [
|
|
412
|
+
{
|
|
413
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
414
|
+
callback: window[body.eventHandler],
|
|
415
|
+
token: uuidv4()
|
|
416
|
+
}
|
|
417
|
+
];
|
|
386
418
|
} else {
|
|
387
419
|
listeners = this.#eventListeners.get(eventId) || [];
|
|
388
420
|
}
|
|
@@ -390,10 +422,7 @@ class SSFGuest {
|
|
|
390
422
|
listeners.forEach((callbackInfo) => {
|
|
391
423
|
if (callbackInfo?.callback) {
|
|
392
424
|
if (callbackInfo.criteria) {
|
|
393
|
-
const criteriaMatched = body.eventParams ? this.#matchesCriteria(
|
|
394
|
-
body.eventParams,
|
|
395
|
-
callbackInfo.criteria
|
|
396
|
-
) : false;
|
|
425
|
+
const criteriaMatched = body.eventParams ? this.#matchesCriteria(body.eventParams, callbackInfo.criteria) : false;
|
|
397
426
|
if (!criteriaMatched) {
|
|
398
427
|
this.#logger.debug(
|
|
399
428
|
`Event ${eventId} did not match criteria for subscriber ${callbackInfo.callback.name}`
|
|
@@ -539,32 +568,37 @@ class SSFGuest {
|
|
|
539
568
|
* Initialize guest using script
|
|
540
569
|
* @param {string} scriptUri uri of the script
|
|
541
570
|
* @param {HTMLElement} containerElement dom element to inject the script at
|
|
571
|
+
* @param {object} [options] additional options
|
|
572
|
+
* @param {boolean} [options.asModule=true] inject the script as an ES module
|
|
542
573
|
*/
|
|
543
|
-
addScript = async (scriptUri, containerElement) => {
|
|
574
|
+
addScript = async (scriptUri, containerElement, options = {}) => {
|
|
575
|
+
const { asModule = true } = options;
|
|
544
576
|
if (!this.#created && scriptUri) {
|
|
545
577
|
await this.connect();
|
|
546
578
|
const scriptEle = document.createElement("script");
|
|
547
579
|
scriptEle.setAttribute("src", scriptUri);
|
|
548
|
-
|
|
580
|
+
if (asModule) {
|
|
581
|
+
scriptEle.setAttribute("type", "module");
|
|
582
|
+
}
|
|
549
583
|
await new Promise((resolve, reject) => {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
584
|
+
let onScriptLoad;
|
|
585
|
+
let onScriptError;
|
|
586
|
+
const cleanup = () => {
|
|
587
|
+
scriptEle.removeEventListener("load", onScriptLoad);
|
|
588
|
+
scriptEle.removeEventListener("error", onScriptError);
|
|
589
|
+
};
|
|
590
|
+
onScriptLoad = () => {
|
|
591
|
+
cleanup();
|
|
592
|
+
this.#created = true;
|
|
593
|
+
setScriptOnlyGuest(true);
|
|
594
|
+
resolve();
|
|
595
|
+
};
|
|
596
|
+
onScriptError = () => {
|
|
597
|
+
cleanup();
|
|
598
|
+
reject(new Error(`Failed to load script: ${scriptUri}`));
|
|
565
599
|
};
|
|
566
|
-
scriptEle.addEventListener("load",
|
|
567
|
-
scriptEle.addEventListener("error",
|
|
600
|
+
scriptEle.addEventListener("load", onScriptLoad);
|
|
601
|
+
scriptEle.addEventListener("error", onScriptError);
|
|
568
602
|
this.#scriptElement = containerElement.appendChild(scriptEle);
|
|
569
603
|
});
|
|
570
604
|
}
|
|
@@ -572,7 +606,6 @@ class SSFGuest {
|
|
|
572
606
|
/**
|
|
573
607
|
* Close the connection to the host
|
|
574
608
|
*/
|
|
575
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
576
609
|
close = async () => {
|
|
577
610
|
if (!this.#isConnected) return;
|
|
578
611
|
if (this.#hostWindow && this.#hostOrigin) {
|
|
@@ -614,56 +647,49 @@ class SSFGuest {
|
|
|
614
647
|
*/
|
|
615
648
|
// eslint-disable-next-line max-statements
|
|
616
649
|
connect = async (param) => {
|
|
617
|
-
if (
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
if (param) {
|
|
621
|
-
const { window: paramWindow, ...restOptions } = param;
|
|
622
|
-
if (paramWindow) guestWindow = paramWindow;
|
|
623
|
-
guestOptions = { ...guestOptions, ...restOptions };
|
|
624
|
-
}
|
|
625
|
-
const hostDetails = await getHostDetails();
|
|
626
|
-
this.#hostOrigin = hostDetails.origin;
|
|
627
|
-
this.#hostWindow = hostDetails.window;
|
|
628
|
-
this.#remoting.initialize(guestWindow);
|
|
629
|
-
this.#remoting.addSender({
|
|
630
|
-
origin: this.#hostOrigin,
|
|
631
|
-
window: this.#hostWindow
|
|
632
|
-
});
|
|
633
|
-
this.#remoting.listen({
|
|
634
|
-
messageType: MessageType.ObjectEvent,
|
|
635
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
636
|
-
callback: this.#handleObjectEvent.bind(this)
|
|
637
|
-
});
|
|
638
|
-
this.#remoting.listen({
|
|
639
|
-
messageType: MessageType.HostConfig,
|
|
640
|
-
callback: this.#handleConfigChangeEvent.bind(this)
|
|
641
|
-
});
|
|
642
|
-
this.#remoting.listen({
|
|
643
|
-
messageType: MessageType.GuestFocus,
|
|
644
|
-
callback: this.#handleFocusEvent.bind(this)
|
|
645
|
-
});
|
|
646
|
-
this.#remoting.listen({
|
|
647
|
-
messageType: MessageType.HostClose,
|
|
648
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
649
|
-
callback: this.#handleHostClose.bind(this)
|
|
650
|
-
});
|
|
651
|
-
this.#remoting.send({
|
|
652
|
-
targetWin: this.#hostWindow,
|
|
653
|
-
targetOrigin: this.#hostOrigin,
|
|
654
|
-
messageType: MessageType.GuestReady,
|
|
655
|
-
messageBody: guestOptions
|
|
656
|
-
});
|
|
657
|
-
this.#isConnected = true;
|
|
658
|
-
this.#handleParentClose();
|
|
659
|
-
if (this.#usesDevConnectAPI) await this.getAuthToken();
|
|
660
|
-
await this.#startKeepSessionAlive();
|
|
661
|
-
window.addEventListener("beforeunload", this.close);
|
|
662
|
-
this.#logger.audit({
|
|
663
|
-
message: "Guest connected to host",
|
|
664
|
-
guestUrl: window.location.href
|
|
665
|
-
});
|
|
650
|
+
if (this.#isConnected) {
|
|
651
|
+
this.#sendGuestReady(this.#buildGuestOptions(param));
|
|
652
|
+
return;
|
|
666
653
|
}
|
|
654
|
+
let guestWindow = window;
|
|
655
|
+
if (param?.window) guestWindow = param.window;
|
|
656
|
+
const guestOptions = this.#buildGuestOptions(param);
|
|
657
|
+
const hostDetails = await getHostDetails();
|
|
658
|
+
this.#hostOrigin = hostDetails.origin;
|
|
659
|
+
this.#hostWindow = hostDetails.window;
|
|
660
|
+
this.#remoting.initialize(guestWindow);
|
|
661
|
+
this.#remoting.addSender({
|
|
662
|
+
origin: this.#hostOrigin,
|
|
663
|
+
window: this.#hostWindow
|
|
664
|
+
});
|
|
665
|
+
this.#remoting.listen({
|
|
666
|
+
messageType: MessageType.ObjectEvent,
|
|
667
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
668
|
+
callback: this.#handleObjectEvent.bind(this)
|
|
669
|
+
});
|
|
670
|
+
this.#remoting.listen({
|
|
671
|
+
messageType: MessageType.HostConfig,
|
|
672
|
+
callback: this.#handleConfigChangeEvent.bind(this)
|
|
673
|
+
});
|
|
674
|
+
this.#remoting.listen({
|
|
675
|
+
messageType: MessageType.GuestFocus,
|
|
676
|
+
callback: this.#handleFocusEvent.bind(this)
|
|
677
|
+
});
|
|
678
|
+
this.#remoting.listen({
|
|
679
|
+
messageType: MessageType.HostClose,
|
|
680
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
681
|
+
callback: this.#handleHostClose.bind(this)
|
|
682
|
+
});
|
|
683
|
+
this.#sendGuestReady(guestOptions);
|
|
684
|
+
this.#isConnected = true;
|
|
685
|
+
this.#handleParentClose();
|
|
686
|
+
if (this.#usesDevConnectAPI) await this.getAuthToken();
|
|
687
|
+
await this.#startKeepSessionAlive();
|
|
688
|
+
window.addEventListener("beforeunload", this.close);
|
|
689
|
+
this.#logger.audit({
|
|
690
|
+
message: "Guest connected to host",
|
|
691
|
+
guestUrl: window.location.href
|
|
692
|
+
});
|
|
667
693
|
};
|
|
668
694
|
/**
|
|
669
695
|
* Get bearer token to access dev connect api
|
|
@@ -707,8 +733,12 @@ class SSFGuest {
|
|
|
707
733
|
messageType: MessageType.ObjectGet,
|
|
708
734
|
messageBody: {
|
|
709
735
|
objectId
|
|
710
|
-
}
|
|
736
|
+
},
|
|
737
|
+
responseTimeoutMs: OBJECT_GET_TIMEOUT_MS
|
|
711
738
|
});
|
|
739
|
+
if (!response?.object) {
|
|
740
|
+
throw new Error(`The requested object (${objectId}) is not available`);
|
|
741
|
+
}
|
|
712
742
|
const obj = this.#fromJSON(response.object);
|
|
713
743
|
this.#auditThrottler.log(`getObject:${objectId}`, {
|
|
714
744
|
message: "Received scripting object from host",
|
package/dist/esm/tests/utils.js
CHANGED