@elliemae/ssf-guest 2.29.0-alpha.0 → 2.29.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 (33) hide show
  1. package/dist/cjs/guest.js +101 -76
  2. package/dist/cjs/tests/utils.js +1 -0
  3. package/dist/cjs/utils.js +4 -4
  4. package/dist/cjs/v1-adapter.js +7 -8
  5. package/dist/esm/guest.js +101 -76
  6. package/dist/esm/tests/utils.js +1 -0
  7. package/dist/esm/utils.js +4 -4
  8. package/dist/esm/v1-adapter.js +7 -8
  9. package/dist/public/callchain-grandchild.html +1 -1
  10. package/dist/public/creditService.html +1 -1
  11. package/dist/public/e2e-guest.html +1 -1
  12. package/dist/public/index.html +1 -1
  13. package/dist/public/js/emuiSsfGuest.a4248744d3a043275636.js +3 -0
  14. package/dist/public/js/emuiSsfGuest.a4248744d3a043275636.js.br +0 -0
  15. package/dist/public/js/emuiSsfGuest.a4248744d3a043275636.js.gz +0 -0
  16. package/dist/public/js/emuiSsfGuest.a4248744d3a043275636.js.map +1 -0
  17. package/dist/public/loanValidation.html +1 -1
  18. package/dist/public/pricingService.html +1 -1
  19. package/dist/public/titleService.html +1 -1
  20. package/dist/public/v2-guest.html +1 -1
  21. package/dist/types/lib/guest.d.ts +3 -3
  22. package/dist/types/lib/tests/utils.d.ts +2 -2
  23. package/dist/types/lib/typings/window.d.ts +7 -9
  24. package/dist/types/tsconfig.tsbuildinfo +1 -1
  25. package/dist/umd/index.js +1 -1
  26. package/dist/umd/index.js.br +0 -0
  27. package/dist/umd/index.js.gz +0 -0
  28. package/dist/umd/index.js.map +1 -1
  29. package/package.json +8 -9
  30. package/dist/public/js/emuiSsfGuest.e7547c98c8ccfd0654bd.js +0 -3
  31. package/dist/public/js/emuiSsfGuest.e7547c98c8ccfd0654bd.js.br +0 -0
  32. package/dist/public/js/emuiSsfGuest.e7547c98c8ccfd0654bd.js.gz +0 -0
  33. 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 proxiedFn = ctrl[functionName];
207
- const callerChain = proxiedFn?.callContext?.callChain;
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
- const handler = window[body.eventHandler];
398
- listeners = handler ? [{ callback: handler, token: (0, import_uuid.v4)() }] : [];
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}`
@@ -560,24 +589,24 @@ class SSFGuest {
560
589
  scriptEle.setAttribute("src", scriptUri);
561
590
  scriptEle.setAttribute("type", "module");
562
591
  await new Promise((resolve, reject) => {
563
- const handlers = {
564
- cleanup: () => {
565
- scriptEle.removeEventListener("load", handlers.onScriptLoad);
566
- scriptEle.removeEventListener("error", handlers.onScriptError);
567
- },
568
- onScriptLoad: () => {
569
- handlers.cleanup();
570
- this.#created = true;
571
- (0, import_v1_adapter.setScriptOnlyGuest)(true);
572
- resolve();
573
- },
574
- onScriptError: () => {
575
- handlers.cleanup();
576
- reject(new Error(`Failed to load script: ${scriptUri}`));
577
- }
592
+ let onScriptLoad;
593
+ let onScriptError;
594
+ const cleanup = () => {
595
+ scriptEle.removeEventListener("load", onScriptLoad);
596
+ scriptEle.removeEventListener("error", onScriptError);
578
597
  };
579
- scriptEle.addEventListener("load", handlers.onScriptLoad);
580
- scriptEle.addEventListener("error", handlers.onScriptError);
598
+ onScriptLoad = () => {
599
+ cleanup();
600
+ this.#created = true;
601
+ (0, import_v1_adapter.setScriptOnlyGuest)(true);
602
+ resolve();
603
+ };
604
+ onScriptError = () => {
605
+ cleanup();
606
+ reject(new Error(`Failed to load script: ${scriptUri}`));
607
+ };
608
+ scriptEle.addEventListener("load", onScriptLoad);
609
+ scriptEle.addEventListener("error", onScriptError);
581
610
  this.#scriptElement = containerElement.appendChild(scriptEle);
582
611
  });
583
612
  }
@@ -585,7 +614,6 @@ class SSFGuest {
585
614
  /**
586
615
  * Close the connection to the host
587
616
  */
588
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
589
617
  close = async () => {
590
618
  if (!this.#isConnected) return;
591
619
  if (this.#hostWindow && this.#hostOrigin) {
@@ -627,56 +655,49 @@ class SSFGuest {
627
655
  */
628
656
  // eslint-disable-next-line max-statements
629
657
  connect = async (param) => {
630
- if (!this.#isConnected) {
631
- let guestWindow = window;
632
- let guestOptions = { ...capabilities };
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
- });
658
+ if (this.#isConnected) {
659
+ this.#sendGuestReady(this.#buildGuestOptions(param));
660
+ return;
679
661
  }
662
+ let guestWindow = window;
663
+ if (param?.window) guestWindow = param.window;
664
+ const guestOptions = this.#buildGuestOptions(param);
665
+ const hostDetails = await (0, import_utils.getHostDetails)();
666
+ this.#hostOrigin = hostDetails.origin;
667
+ this.#hostWindow = hostDetails.window;
668
+ this.#remoting.initialize(guestWindow);
669
+ this.#remoting.addSender({
670
+ origin: this.#hostOrigin,
671
+ window: this.#hostWindow
672
+ });
673
+ this.#remoting.listen({
674
+ messageType: import_microfe_common.MessageType.ObjectEvent,
675
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
676
+ callback: this.#handleObjectEvent.bind(this)
677
+ });
678
+ this.#remoting.listen({
679
+ messageType: import_microfe_common.MessageType.HostConfig,
680
+ callback: this.#handleConfigChangeEvent.bind(this)
681
+ });
682
+ this.#remoting.listen({
683
+ messageType: import_microfe_common.MessageType.GuestFocus,
684
+ callback: this.#handleFocusEvent.bind(this)
685
+ });
686
+ this.#remoting.listen({
687
+ messageType: import_microfe_common.MessageType.HostClose,
688
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
689
+ callback: this.#handleHostClose.bind(this)
690
+ });
691
+ this.#sendGuestReady(guestOptions);
692
+ this.#isConnected = true;
693
+ this.#handleParentClose();
694
+ if (this.#usesDevConnectAPI) await this.getAuthToken();
695
+ await this.#startKeepSessionAlive();
696
+ window.addEventListener("beforeunload", this.close);
697
+ this.#logger.audit({
698
+ message: "Guest connected to host",
699
+ guestUrl: window.location.href
700
+ });
680
701
  };
681
702
  /**
682
703
  * Get bearer token to access dev connect api
@@ -720,8 +741,12 @@ class SSFGuest {
720
741
  messageType: import_microfe_common.MessageType.ObjectGet,
721
742
  messageBody: {
722
743
  objectId
723
- }
744
+ },
745
+ responseTimeoutMs: OBJECT_GET_TIMEOUT_MS
724
746
  });
747
+ if (!response?.object) {
748
+ throw new Error(`The requested object (${objectId}) is not available`);
749
+ }
725
750
  const obj = this.#fromJSON(response.object);
726
751
  this.#auditThrottler.log(`getObject:${objectId}`, {
727
752
  message: "Received scripting object from host",
@@ -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
- const timerRef = {};
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(timerRef.id);
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
- timerRef.id = setTimeout(() => {
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`)
@@ -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
- callback: ((event) => callback(
77
- event?.obj,
78
- event?.eventParams,
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 proxiedFn = ctrl[functionName];
194
- const callerChain = proxiedFn?.callContext?.callChain;
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
- const handler = window[body.eventHandler];
385
- listeners = handler ? [{ callback: handler, token: uuidv4() }] : [];
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}`
@@ -547,24 +576,24 @@ class SSFGuest {
547
576
  scriptEle.setAttribute("src", scriptUri);
548
577
  scriptEle.setAttribute("type", "module");
549
578
  await new Promise((resolve, reject) => {
550
- const handlers = {
551
- cleanup: () => {
552
- scriptEle.removeEventListener("load", handlers.onScriptLoad);
553
- scriptEle.removeEventListener("error", handlers.onScriptError);
554
- },
555
- onScriptLoad: () => {
556
- handlers.cleanup();
557
- this.#created = true;
558
- setScriptOnlyGuest(true);
559
- resolve();
560
- },
561
- onScriptError: () => {
562
- handlers.cleanup();
563
- reject(new Error(`Failed to load script: ${scriptUri}`));
564
- }
579
+ let onScriptLoad;
580
+ let onScriptError;
581
+ const cleanup = () => {
582
+ scriptEle.removeEventListener("load", onScriptLoad);
583
+ scriptEle.removeEventListener("error", onScriptError);
565
584
  };
566
- scriptEle.addEventListener("load", handlers.onScriptLoad);
567
- scriptEle.addEventListener("error", handlers.onScriptError);
585
+ onScriptLoad = () => {
586
+ cleanup();
587
+ this.#created = true;
588
+ setScriptOnlyGuest(true);
589
+ resolve();
590
+ };
591
+ onScriptError = () => {
592
+ cleanup();
593
+ reject(new Error(`Failed to load script: ${scriptUri}`));
594
+ };
595
+ scriptEle.addEventListener("load", onScriptLoad);
596
+ scriptEle.addEventListener("error", onScriptError);
568
597
  this.#scriptElement = containerElement.appendChild(scriptEle);
569
598
  });
570
599
  }
@@ -572,7 +601,6 @@ class SSFGuest {
572
601
  /**
573
602
  * Close the connection to the host
574
603
  */
575
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
576
604
  close = async () => {
577
605
  if (!this.#isConnected) return;
578
606
  if (this.#hostWindow && this.#hostOrigin) {
@@ -614,56 +642,49 @@ class SSFGuest {
614
642
  */
615
643
  // eslint-disable-next-line max-statements
616
644
  connect = async (param) => {
617
- if (!this.#isConnected) {
618
- let guestWindow = window;
619
- let guestOptions = { ...capabilities };
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
- });
645
+ if (this.#isConnected) {
646
+ this.#sendGuestReady(this.#buildGuestOptions(param));
647
+ return;
666
648
  }
649
+ let guestWindow = window;
650
+ if (param?.window) guestWindow = param.window;
651
+ const guestOptions = this.#buildGuestOptions(param);
652
+ const hostDetails = await getHostDetails();
653
+ this.#hostOrigin = hostDetails.origin;
654
+ this.#hostWindow = hostDetails.window;
655
+ this.#remoting.initialize(guestWindow);
656
+ this.#remoting.addSender({
657
+ origin: this.#hostOrigin,
658
+ window: this.#hostWindow
659
+ });
660
+ this.#remoting.listen({
661
+ messageType: MessageType.ObjectEvent,
662
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
663
+ callback: this.#handleObjectEvent.bind(this)
664
+ });
665
+ this.#remoting.listen({
666
+ messageType: MessageType.HostConfig,
667
+ callback: this.#handleConfigChangeEvent.bind(this)
668
+ });
669
+ this.#remoting.listen({
670
+ messageType: MessageType.GuestFocus,
671
+ callback: this.#handleFocusEvent.bind(this)
672
+ });
673
+ this.#remoting.listen({
674
+ messageType: MessageType.HostClose,
675
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
676
+ callback: this.#handleHostClose.bind(this)
677
+ });
678
+ this.#sendGuestReady(guestOptions);
679
+ this.#isConnected = true;
680
+ this.#handleParentClose();
681
+ if (this.#usesDevConnectAPI) await this.getAuthToken();
682
+ await this.#startKeepSessionAlive();
683
+ window.addEventListener("beforeunload", this.close);
684
+ this.#logger.audit({
685
+ message: "Guest connected to host",
686
+ guestUrl: window.location.href
687
+ });
667
688
  };
668
689
  /**
669
690
  * Get bearer token to access dev connect api
@@ -707,8 +728,12 @@ class SSFGuest {
707
728
  messageType: MessageType.ObjectGet,
708
729
  messageBody: {
709
730
  objectId
710
- }
731
+ },
732
+ responseTimeoutMs: OBJECT_GET_TIMEOUT_MS
711
733
  });
734
+ if (!response?.object) {
735
+ throw new Error(`The requested object (${objectId}) is not available`);
736
+ }
712
737
  const obj = this.#fromJSON(response.object);
713
738
  this.#auditThrottler.log(`getObject:${objectId}`, {
714
739
  message: "Received scripting object from host",
@@ -36,6 +36,7 @@ const postMessage = ({
36
36
  new MessageEvent("message", {
37
37
  source: srcWindow,
38
38
  origin: getOrigin(srcWindow.location.href),
39
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
39
40
  data: {
40
41
  source: "elli:remoting",
41
42
  ...message
package/dist/esm/utils.js CHANGED
@@ -3,7 +3,7 @@ const getParentWindowLocation = () => {
3
3
  const { parent } = window;
4
4
  try {
5
5
  return parent?.location?.href;
6
- } catch {
6
+ } catch (e) {
7
7
  return null;
8
8
  }
9
9
  };
@@ -47,14 +47,14 @@ const getHostDetails = () => new Promise((resolve, reject) => {
47
47
  if (!isEmbedded()) {
48
48
  const currentWindow = window;
49
49
  const expectedToken = getHandshakeToken();
50
- const timerRef = {};
50
+ let timer;
51
51
  const onMessage = (event) => {
52
52
  if (isHandshakeTrusted(event, expectedToken)) {
53
53
  const { source, type } = event.data || {};
54
54
  if (source === MESSAGE_SOURCE && type === MessageType.HandShake) {
55
55
  const { origin } = event;
56
56
  const hostWindow = event.source;
57
- clearTimeout(timerRef.id);
57
+ clearTimeout(timer);
58
58
  sendMessage({
59
59
  targetWin: hostWindow,
60
60
  targetOrigin: origin,
@@ -66,7 +66,7 @@ const getHostDetails = () => new Promise((resolve, reject) => {
66
66
  }
67
67
  }
68
68
  };
69
- timerRef.id = setTimeout(() => {
69
+ timer = setTimeout(() => {
70
70
  currentWindow.removeEventListener("message", onMessage);
71
71
  reject(
72
72
  new Error(`Host handshake timed out after ${HANDSHAKE_TIMEOUT_MS}ms`)