@elliemae/ssf-guest 2.7.1 → 2.7.3

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 CHANGED
@@ -74,9 +74,9 @@ class SSFGuest {
74
74
  #hostOrigin = null;
75
75
  #hostWindow = null;
76
76
  /**
77
- * flag to get & cache auth token
77
+ * get bearer token to access api during connect operation
78
78
  */
79
- #cacheAuthToken = false;
79
+ #usesDevConnectAPI = false;
80
80
  /**
81
81
  * auth token to access api
82
82
  */
@@ -114,7 +114,7 @@ class SSFGuest {
114
114
  team,
115
115
  appName
116
116
  } = options?.logger || {};
117
- this.#cacheAuthToken = options?.cacheAuthToken ?? false;
117
+ this.#usesDevConnectAPI = options?.usesDevConnectAPI ?? false;
118
118
  this.#keepAlive = options?.keepAlive ?? false;
119
119
  this.#keepAliveInterval = options?.keepAliveInterval ?? KEEP_ALIVE_INTERVAL;
120
120
  const transport = logToConsole ? (0, import_pui_diagnostics.Console)() : (0, import_pui_diagnostics.http)(url);
@@ -316,13 +316,43 @@ class SSFGuest {
316
316
  */
317
317
  #extendTokenLifetime = async () => {
318
318
  if (!this.#authToken || !this.#authClientId || !this.#hostDomain) return;
319
- await fetch(`${this.#hostDomain}/oauth2/v1/token/introspection`, {
320
- headers: {
321
- "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
322
- },
323
- body: `token=${this.#authToken}&client_id=${this.#authClientId}`,
324
- method: "POST"
325
- });
319
+ await fetch(
320
+ `${this.#hostDomain}/oauth2/v1/token/introspection?${new URLSearchParams({
321
+ token: this.#authToken,
322
+ client_id: this.#authClientId
323
+ }).toString()}`,
324
+ {
325
+ headers: {
326
+ "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
327
+ },
328
+ method: "POST"
329
+ }
330
+ );
331
+ };
332
+ /**
333
+ * revoke token
334
+ */
335
+ #revokeToken = async () => {
336
+ if (this.#authToken && this.#authClientId && this.#hostDomain) {
337
+ try {
338
+ await fetch(
339
+ `${this.#hostDomain}/oauth2/v1/token/revocation?${new URLSearchParams(
340
+ {
341
+ token: this.#authToken,
342
+ client_id: this.#authClientId
343
+ }
344
+ ).toString()}`,
345
+ {
346
+ method: "POST"
347
+ }
348
+ );
349
+ } catch (e) {
350
+ this.#logger.error(`Error revoking token. ${e.message}`);
351
+ } finally {
352
+ this.#authToken = null;
353
+ this.#authClientId = null;
354
+ }
355
+ }
326
356
  };
327
357
  /**
328
358
  * Start session keep alive
@@ -382,7 +412,7 @@ class SSFGuest {
382
412
  /**
383
413
  * Close the connection to the host
384
414
  */
385
- close = () => {
415
+ close = async () => {
386
416
  if (!this.#isConnected) return;
387
417
  this.#remoting.send({
388
418
  targetWin: this.#hostWindow,
@@ -400,6 +430,7 @@ class SSFGuest {
400
430
  document.removeEventListener(eventType, this.#throttledKeepAlive);
401
431
  });
402
432
  }
433
+ await this.#revokeToken();
403
434
  this.#isConnected = false;
404
435
  this.#logger.audit({
405
436
  message: "Guest disconnected from host",
@@ -456,17 +487,17 @@ class SSFGuest {
456
487
  message: "Guest connected to host",
457
488
  guestUrl: window.location.href
458
489
  });
459
- await this.getAuthToken();
490
+ if (this.#usesDevConnectAPI) await this.getAuthToken();
460
491
  await this.#startKeepSessionAlive();
492
+ window.addEventListener("beforeunload", this.close);
461
493
  }
462
494
  };
463
495
  /**
464
- * Get bearer token to access api
496
+ * Get bearer token to access dev connect api
465
497
  * @returns auth token
466
498
  */
467
499
  getAuthToken = async () => {
468
- if (!this.#cacheAuthToken) return null;
469
- if (!this.#authToken) {
500
+ if (!this.#authToken && this.#isConnected) {
470
501
  try {
471
502
  const authObj = await this.getObject("Auth");
472
503
  if (authObj) {
@@ -32,7 +32,7 @@ var import_constant = require("./constant.js");
32
32
  var import_utils = require("../utils.js");
33
33
  const createGuest = ({
34
34
  keepAlive,
35
- cacheAuthToken,
35
+ usesDevConnectAPI,
36
36
  keepAliveInterval
37
37
  }) => new import__.SSFGuest({
38
38
  logger: {
@@ -42,7 +42,7 @@ const createGuest = ({
42
42
  appName: "SSF Guest"
43
43
  },
44
44
  keepAlive,
45
- cacheAuthToken,
45
+ usesDevConnectAPI,
46
46
  keepAliveInterval
47
47
  });
48
48
  const postMessage = ({
package/dist/esm/guest.js CHANGED
@@ -68,9 +68,9 @@ class SSFGuest {
68
68
  #hostOrigin = null;
69
69
  #hostWindow = null;
70
70
  /**
71
- * flag to get & cache auth token
71
+ * get bearer token to access api during connect operation
72
72
  */
73
- #cacheAuthToken = false;
73
+ #usesDevConnectAPI = false;
74
74
  /**
75
75
  * auth token to access api
76
76
  */
@@ -108,7 +108,7 @@ class SSFGuest {
108
108
  team,
109
109
  appName
110
110
  } = options?.logger || {};
111
- this.#cacheAuthToken = options?.cacheAuthToken ?? false;
111
+ this.#usesDevConnectAPI = options?.usesDevConnectAPI ?? false;
112
112
  this.#keepAlive = options?.keepAlive ?? false;
113
113
  this.#keepAliveInterval = options?.keepAliveInterval ?? KEEP_ALIVE_INTERVAL;
114
114
  const transport = logToConsole ? Console() : http(url);
@@ -310,13 +310,43 @@ class SSFGuest {
310
310
  */
311
311
  #extendTokenLifetime = async () => {
312
312
  if (!this.#authToken || !this.#authClientId || !this.#hostDomain) return;
313
- await fetch(`${this.#hostDomain}/oauth2/v1/token/introspection`, {
314
- headers: {
315
- "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
316
- },
317
- body: `token=${this.#authToken}&client_id=${this.#authClientId}`,
318
- method: "POST"
319
- });
313
+ await fetch(
314
+ `${this.#hostDomain}/oauth2/v1/token/introspection?${new URLSearchParams({
315
+ token: this.#authToken,
316
+ client_id: this.#authClientId
317
+ }).toString()}`,
318
+ {
319
+ headers: {
320
+ "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
321
+ },
322
+ method: "POST"
323
+ }
324
+ );
325
+ };
326
+ /**
327
+ * revoke token
328
+ */
329
+ #revokeToken = async () => {
330
+ if (this.#authToken && this.#authClientId && this.#hostDomain) {
331
+ try {
332
+ await fetch(
333
+ `${this.#hostDomain}/oauth2/v1/token/revocation?${new URLSearchParams(
334
+ {
335
+ token: this.#authToken,
336
+ client_id: this.#authClientId
337
+ }
338
+ ).toString()}`,
339
+ {
340
+ method: "POST"
341
+ }
342
+ );
343
+ } catch (e) {
344
+ this.#logger.error(`Error revoking token. ${e.message}`);
345
+ } finally {
346
+ this.#authToken = null;
347
+ this.#authClientId = null;
348
+ }
349
+ }
320
350
  };
321
351
  /**
322
352
  * Start session keep alive
@@ -376,7 +406,7 @@ class SSFGuest {
376
406
  /**
377
407
  * Close the connection to the host
378
408
  */
379
- close = () => {
409
+ close = async () => {
380
410
  if (!this.#isConnected) return;
381
411
  this.#remoting.send({
382
412
  targetWin: this.#hostWindow,
@@ -394,6 +424,7 @@ class SSFGuest {
394
424
  document.removeEventListener(eventType, this.#throttledKeepAlive);
395
425
  });
396
426
  }
427
+ await this.#revokeToken();
397
428
  this.#isConnected = false;
398
429
  this.#logger.audit({
399
430
  message: "Guest disconnected from host",
@@ -450,17 +481,17 @@ class SSFGuest {
450
481
  message: "Guest connected to host",
451
482
  guestUrl: window.location.href
452
483
  });
453
- await this.getAuthToken();
484
+ if (this.#usesDevConnectAPI) await this.getAuthToken();
454
485
  await this.#startKeepSessionAlive();
486
+ window.addEventListener("beforeunload", this.close);
455
487
  }
456
488
  };
457
489
  /**
458
- * Get bearer token to access api
490
+ * Get bearer token to access dev connect api
459
491
  * @returns auth token
460
492
  */
461
493
  getAuthToken = async () => {
462
- if (!this.#cacheAuthToken) return null;
463
- if (!this.#authToken) {
494
+ if (!this.#authToken && this.#isConnected) {
464
495
  try {
465
496
  const authObj = await this.getObject("Auth");
466
497
  if (authObj) {
@@ -9,7 +9,7 @@ import {
9
9
  import { getOrigin } from "../utils.js";
10
10
  const createGuest = ({
11
11
  keepAlive,
12
- cacheAuthToken,
12
+ usesDevConnectAPI,
13
13
  keepAliveInterval
14
14
  }) => new SSFGuest({
15
15
  logger: {
@@ -19,7 +19,7 @@ const createGuest = ({
19
19
  appName: "SSF Guest"
20
20
  },
21
21
  keepAlive,
22
- cacheAuthToken,
22
+ usesDevConnectAPI,
23
23
  keepAliveInterval
24
24
  });
25
25
  const postMessage = ({
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Credit Service</title><style>body{margin:0}</style><script src="https://qa.assets.rd.elliemae.io/pui-diagnostics@3"></script><script>window.addEventListener("DOMContentLoaded",(async()=>{window.__ICE__={diagnosticsUrl:"https://int.api.ellielabs.com/diagnostics/v2/logging"};const e=new URL(window.location),i=e?.searchParams?.get?.("src");window.__ICE__.ssfGuest=new ice.guest.SSFGuest({logger:{index:"creditServiceGuest",team:"ui platform",appName:"credit-service"}}),await window.__ICE__.ssfGuest.addScript(i,document.body)}))</script><script defer="defer" src="js/emuiSsfGuest.4319b0d4376113a76a39.js"></script></head><body></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><title>Credit Service</title><style>body{margin:0}</style><script src="https://qa.assets.rd.elliemae.io/pui-diagnostics@3"></script><script>window.addEventListener("DOMContentLoaded",(async()=>{window.__ICE__={diagnosticsUrl:"https://int.api.ellielabs.com/diagnostics/v2/logging"};const e=new URL(window.location),i=e?.searchParams?.get?.("src");window.__ICE__.ssfGuest=new ice.guest.SSFGuest({logger:{index:"creditServiceGuest",team:"ui platform",appName:"credit-service"}}),await window.__ICE__.ssfGuest.addScript(i,document.body)}))</script><script defer="defer" src="js/emuiSsfGuest.7973d32bede59971d5d6.js"></script></head><body></body></html>
@@ -1 +1 @@
1
- <!doctype html><html lang="en" style="height:100%"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Plugin</title><script src="https://cdn.tailwindcss.com?plugins=forms"></script><script defer="defer" src="js/emuiSsfGuest.4319b0d4376113a76a39.js"></script></head><body class="px-2 h-full"><main class="h-full"><h1 class="text-md font-bold">Credit Score Service</h1><div class="h-full mt-2"><output id="msg" class="mt-2 p-2"></output></div></main></body></html>
1
+ <!doctype html><html lang="en" style="height:100%"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Plugin</title><script src="https://cdn.tailwindcss.com?plugins=forms"></script><script defer="defer" src="js/emuiSsfGuest.7973d32bede59971d5d6.js"></script></head><body class="px-2 h-full"><main class="h-full"><h1 class="text-md font-bold">Credit Score Service</h1><div class="h-full mt-2"><output id="msg" class="mt-2 p-2"></output></div></main></body></html>