@elliemae/ssf-host 2.23.7 → 2.23.8
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/host.js +510 -14
- package/dist/esm/host.js +510 -14
- package/dist/public/index.html +1 -1
- package/dist/public/js/emuiSsfHost.c95491c428f3f102185b.js +3 -0
- package/dist/public/js/emuiSsfHost.c95491c428f3f102185b.js.br +0 -0
- package/dist/public/js/emuiSsfHost.c95491c428f3f102185b.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.c95491c428f3f102185b.js.map +1 -0
- package/dist/public/v1-guest-v2-host.html +1 -1
- package/dist/public/v2-host-v1-guest.html +1 -1
- package/dist/types/lib/host.d.ts +50 -8
- package/dist/types/lib/ihost.d.ts +15 -0
- package/dist/types/lib/index.d.ts +1 -1
- package/dist/types/lib/types.d.ts +59 -0
- 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 +3 -3
- package/dist/public/js/emuiSsfHost.7d167a52cf87253649bc.js +0 -3
- package/dist/public/js/emuiSsfHost.7d167a52cf87253649bc.js.br +0 -0
- package/dist/public/js/emuiSsfHost.7d167a52cf87253649bc.js.gz +0 -0
- package/dist/public/js/emuiSsfHost.7d167a52cf87253649bc.js.map +0 -1
package/dist/esm/host.js
CHANGED
|
@@ -1172,29 +1172,525 @@ class SSFHost {
|
|
|
1172
1172
|
this.#logger.debug("Dispatched config events to all guests");
|
|
1173
1173
|
};
|
|
1174
1174
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
* @param
|
|
1177
|
-
* @
|
|
1175
|
+
* Call guest cleanup function (e.g., appCleanup, unmount) before disposal
|
|
1176
|
+
* @param options
|
|
1177
|
+
* @param options.guestEmui
|
|
1178
|
+
* @param options.cleanupFunctionName
|
|
1179
|
+
* @param options.context
|
|
1178
1180
|
*/
|
|
1179
|
-
|
|
1181
|
+
#callGuestCleanupFunction = (options) => {
|
|
1182
|
+
const { guestEmui, cleanupFunctionName, context } = options;
|
|
1183
|
+
const emuiObj = guestEmui;
|
|
1184
|
+
const cleanupFn = emuiObj[cleanupFunctionName];
|
|
1185
|
+
if (typeof cleanupFn !== "function") {
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
try {
|
|
1189
|
+
cleanupFn();
|
|
1190
|
+
this.#logger.debug(
|
|
1191
|
+
`[SSF] Called ${context} window.emui.${cleanupFunctionName}()`
|
|
1192
|
+
);
|
|
1193
|
+
} catch (e) {
|
|
1194
|
+
this.#logger.warn(
|
|
1195
|
+
`[SSF] ${context} emui.${cleanupFunctionName}() threw error: ${e.message}`
|
|
1196
|
+
);
|
|
1197
|
+
} finally {
|
|
1198
|
+
emuiObj[cleanupFunctionName] = null;
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
/**
|
|
1202
|
+
* Null all window.emui.app properties to break closure chains
|
|
1203
|
+
* @param {any} guestEmui - Guest window.emui object
|
|
1204
|
+
*/
|
|
1205
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1206
|
+
#cleanupEmuiApp = (guestEmui) => {
|
|
1207
|
+
if (!guestEmui.app) return;
|
|
1208
|
+
if (typeof guestEmui.app !== "object") return;
|
|
1209
|
+
guestEmui.app.init = null;
|
|
1210
|
+
guestEmui.app.mount = null;
|
|
1211
|
+
guestEmui.app.unmount = null;
|
|
1212
|
+
guestEmui.app.getRef = null;
|
|
1213
|
+
guestEmui.app.navigate = null;
|
|
1214
|
+
guestEmui.app = null;
|
|
1215
|
+
};
|
|
1216
|
+
/**
|
|
1217
|
+
* Null all window.elli.script properties to break SSFGuest closures
|
|
1218
|
+
* @param {Window} guestWindow - Guest window reference
|
|
1219
|
+
*/
|
|
1220
|
+
#cleanupElliScript = (guestWindow) => {
|
|
1221
|
+
try {
|
|
1222
|
+
const { elli } = guestWindow;
|
|
1223
|
+
if (!elli?.script) return;
|
|
1224
|
+
if (elli.script.guest) {
|
|
1225
|
+
elli.script.guest.create = null;
|
|
1226
|
+
elli.script.guest = null;
|
|
1227
|
+
}
|
|
1228
|
+
elli.script.connect = null;
|
|
1229
|
+
elli.script.getObject = null;
|
|
1230
|
+
elli.script.setLogLevel = null;
|
|
1231
|
+
elli.script.subscribe = null;
|
|
1232
|
+
elli.script.unsubscribe = null;
|
|
1233
|
+
elli.script = null;
|
|
1234
|
+
} catch (e) {
|
|
1235
|
+
}
|
|
1236
|
+
};
|
|
1237
|
+
/**
|
|
1238
|
+
* Clear Google Tag Manager data layer
|
|
1239
|
+
* @param {Window} guestWindow - Guest window reference
|
|
1240
|
+
* @param {string} context - Context string for logging
|
|
1241
|
+
*/
|
|
1242
|
+
#clearGtmDataLayer = (guestWindow, context) => {
|
|
1243
|
+
try {
|
|
1244
|
+
if (guestWindow.gtmDataLayer) {
|
|
1245
|
+
guestWindow.gtmDataLayer = null;
|
|
1246
|
+
this.#logger.debug(`[SSF] Cleared ${context} gtmDataLayer`);
|
|
1247
|
+
}
|
|
1248
|
+
} catch (e) {
|
|
1249
|
+
this.#logger.debug(
|
|
1250
|
+
`[SSF] Failed to cleanup ${context} gtmDataLayer: ${e.message}`
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
/**
|
|
1255
|
+
* Cleanup guest window context - nulls all window.emui and window.elli.script properties
|
|
1256
|
+
* This breaks closure retention chains and allows GC of webpack bundles, SDKs, and singletons
|
|
1257
|
+
* @param {object} options - Cleanup options
|
|
1258
|
+
* @param {Window | null} options.guestWindow - Guest window reference
|
|
1259
|
+
* @param {string} options.guestId - Guest ID for logging
|
|
1260
|
+
* @param {string} options.cleanupFunctionName - Cleanup function name to call
|
|
1261
|
+
* @param {'iframe' | 'popup'} [options.windowType] - Window type (iframe or popup)
|
|
1262
|
+
*/
|
|
1263
|
+
#cleanupGuestWindow = (options) => {
|
|
1264
|
+
const {
|
|
1265
|
+
guestWindow,
|
|
1266
|
+
guestId,
|
|
1267
|
+
cleanupFunctionName,
|
|
1268
|
+
windowType = "iframe"
|
|
1269
|
+
} = options;
|
|
1270
|
+
if (!guestWindow) {
|
|
1271
|
+
this.#logger.debug(
|
|
1272
|
+
`No ${windowType} window available for cleanup of guest ${guestId}`
|
|
1273
|
+
);
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
try {
|
|
1277
|
+
const guestEmui = guestWindow.emui;
|
|
1278
|
+
if (guestEmui) {
|
|
1279
|
+
this.#callGuestCleanupFunction({
|
|
1280
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
1281
|
+
guestEmui,
|
|
1282
|
+
cleanupFunctionName,
|
|
1283
|
+
context: `${windowType} for guest ${guestId}`
|
|
1284
|
+
});
|
|
1285
|
+
try {
|
|
1286
|
+
this.#cleanupEmuiApp(guestEmui);
|
|
1287
|
+
guestEmui.registerApp = null;
|
|
1288
|
+
guestEmui.logRocket = null;
|
|
1289
|
+
guestEmui.logRocketConfig = null;
|
|
1290
|
+
this.#logger.debug(
|
|
1291
|
+
`[SSF] Nulled all ${windowType} window.emui properties for guest ${guestId}`
|
|
1292
|
+
);
|
|
1293
|
+
} catch (e) {
|
|
1294
|
+
this.#logger.debug(
|
|
1295
|
+
`[SSF] Failed to cleanup ${windowType} window.emui: ${e.message}`
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
this.#cleanupElliScript(guestWindow);
|
|
1300
|
+
this.#logger.debug(
|
|
1301
|
+
`[SSF] Nulled all ${windowType} window.elli.script properties for guest ${guestId}`
|
|
1302
|
+
);
|
|
1303
|
+
this.#clearGtmDataLayer(
|
|
1304
|
+
guestWindow,
|
|
1305
|
+
`${windowType} for guest ${guestId}`
|
|
1306
|
+
);
|
|
1307
|
+
} catch (e) {
|
|
1308
|
+
this.#logger.debug(
|
|
1309
|
+
`[SSF] Could not access ${windowType} window for cleanup (guest ${guestId}): ${e.message}`
|
|
1310
|
+
);
|
|
1311
|
+
}
|
|
1312
|
+
};
|
|
1313
|
+
/**
|
|
1314
|
+
* Navigate window path and collect parent chain
|
|
1315
|
+
* @param {string[]} parts - Path parts to navigate
|
|
1316
|
+
* @param {string} path - Original path for error messages
|
|
1317
|
+
* @param {string} guestId - Guest ID for logging
|
|
1318
|
+
* @returns {{ parentChain: Array<{ obj: any; key: string }>, current: any } | null} Parent chain and current object, or null if path doesn't exist
|
|
1319
|
+
*/
|
|
1320
|
+
#navigateWindowPath = (parts, path, guestId) => {
|
|
1321
|
+
const parentChain = [];
|
|
1322
|
+
let current = window;
|
|
1323
|
+
for (let i = 0; i < parts.length - 1; i += 1) {
|
|
1324
|
+
const part = parts[i];
|
|
1325
|
+
if (current[part] === void 0 || current[part] === null) {
|
|
1326
|
+
this.#logger.debug(
|
|
1327
|
+
`Path "${path}" does not exist (stopped at ${part}) for guest ${guestId}`
|
|
1328
|
+
);
|
|
1329
|
+
return null;
|
|
1330
|
+
}
|
|
1331
|
+
parentChain.push({ obj: current, key: part });
|
|
1332
|
+
current = current[part];
|
|
1333
|
+
}
|
|
1334
|
+
return { parentChain, current };
|
|
1335
|
+
};
|
|
1336
|
+
/**
|
|
1337
|
+
* Clear a single window reference path
|
|
1338
|
+
* @param {string} path - Dot-separated path to window property
|
|
1339
|
+
* @param {string} guestId - Guest ID for logging
|
|
1340
|
+
*/
|
|
1341
|
+
#clearSinglePath = (path, guestId) => {
|
|
1342
|
+
try {
|
|
1343
|
+
const parts = path.split(".").filter((p) => p !== "window" && p.trim() !== "");
|
|
1344
|
+
if (parts.length === 0) {
|
|
1345
|
+
this.#logger.debug(
|
|
1346
|
+
`Invalid path "${path}" - skipping for guest ${guestId}`
|
|
1347
|
+
);
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
const result = this.#navigateWindowPath(parts, path, guestId);
|
|
1351
|
+
if (!result) return;
|
|
1352
|
+
const { parentChain, current } = result;
|
|
1353
|
+
const targetProp = parts[parts.length - 1];
|
|
1354
|
+
if (current[targetProp] === void 0) {
|
|
1355
|
+
this.#logger.debug(
|
|
1356
|
+
`Property "${targetProp}" not found in path "${path}" for guest ${guestId}`
|
|
1357
|
+
);
|
|
1358
|
+
return;
|
|
1359
|
+
}
|
|
1360
|
+
current[targetProp] = null;
|
|
1361
|
+
this.#logger.debug(
|
|
1362
|
+
`Cleared window reference: ${path} for guest ${guestId}`
|
|
1363
|
+
);
|
|
1364
|
+
this.#cleanupEmptyParents(parentChain, parts, guestId);
|
|
1365
|
+
} catch (e) {
|
|
1366
|
+
this.#logger.debug(
|
|
1367
|
+
`Failed to clear window reference "${path}" for guest ${guestId}: ${e.message}`
|
|
1368
|
+
);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
/**
|
|
1372
|
+
* Clean up empty parent objects after clearing a path
|
|
1373
|
+
* @param {Array<{ obj: any; key: string }>} parentChain - Chain of parent objects
|
|
1374
|
+
* @param {string[]} parts - Path parts for logging
|
|
1375
|
+
* @param {string} guestId - Guest ID for logging
|
|
1376
|
+
*/
|
|
1377
|
+
#cleanupEmptyParents = (parentChain, parts, guestId) => {
|
|
1378
|
+
for (let i = parentChain.length - 1; i >= 0; i -= 1) {
|
|
1379
|
+
const { obj, key } = parentChain[i];
|
|
1380
|
+
const parent = obj[key];
|
|
1381
|
+
if (!this.#isEmptyOrNullObject(parent)) {
|
|
1382
|
+
break;
|
|
1383
|
+
}
|
|
1384
|
+
obj[key] = null;
|
|
1385
|
+
this.#logger.debug(
|
|
1386
|
+
`Cleaned up empty parent object at ${parts.slice(0, i + 1).join(".")} for guest ${guestId}`
|
|
1387
|
+
);
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
/**
|
|
1391
|
+
* Recursively clear window references by path string
|
|
1392
|
+
* Handles nested paths like \"window.IMT.focusFormTitle\" or \"window.emui.app\"
|
|
1393
|
+
* Sets each reference to null and cleans up empty parent objects
|
|
1394
|
+
* @param paths - Array of dot-separated paths to window properties
|
|
1395
|
+
* @param guestId - Guest ID for logging purposes
|
|
1396
|
+
* @example
|
|
1397
|
+
* clearWindowRefs([\"window.IMT.focusFormTitle\"], \"my-guest-id\");
|
|
1398
|
+
*/
|
|
1399
|
+
#clearWindowRefs = (paths, guestId) => {
|
|
1400
|
+
if (!paths || paths.length === 0) return;
|
|
1401
|
+
paths.forEach((path) => this.#clearSinglePath(path, guestId));
|
|
1402
|
+
};
|
|
1403
|
+
/**
|
|
1404
|
+
* Check if an object is empty or only contains null/undefined values
|
|
1405
|
+
* Used to determine if parent objects should be cleaned up after nulling child properties
|
|
1406
|
+
* @param obj - Object to check
|
|
1407
|
+
* @returns true if object has no properties or all properties are null/undefined
|
|
1408
|
+
*/
|
|
1409
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1410
|
+
#isEmptyOrNullObject = (obj) => {
|
|
1411
|
+
const keys = Object.keys(obj);
|
|
1412
|
+
if (keys.length === 0) return true;
|
|
1413
|
+
return keys.every((key) => obj[key] === null || obj[key] === void 0);
|
|
1414
|
+
};
|
|
1415
|
+
/**
|
|
1416
|
+
* Unloads guest application from host with optional enhanced cleanup.
|
|
1417
|
+
*
|
|
1418
|
+
* **Basic Mode (no options):**
|
|
1419
|
+
* - Standard guest disposal
|
|
1420
|
+
* - Removes from tracking maps
|
|
1421
|
+
*
|
|
1422
|
+
* **Enhanced Mode (with options):**
|
|
1423
|
+
* - `purgeOnDestroy: true` - Uses comprehensive cleanup via `unloadGuestWithFullCleanup`
|
|
1424
|
+
* - Calls guest cleanup function (React unmount, Redux teardown)
|
|
1425
|
+
* - Closes contentWindow context
|
|
1426
|
+
* - Navigates iframe to about:blank
|
|
1427
|
+
* - Removes iframe from DOM (deferred)
|
|
1428
|
+
* - Clears all window.emui and window.elli.script references
|
|
1429
|
+
* - Disconnects FieldMutation observers
|
|
1430
|
+
* - Removes from SSF tracking
|
|
1431
|
+
*
|
|
1432
|
+
* - `windowRefsToClear` - Array of paths to window refs to clear recursively
|
|
1433
|
+
* - Example: ["window.IMT.focusFormTitle", "window.emui.customApp"]
|
|
1434
|
+
* - Each path is parsed and set to null
|
|
1435
|
+
*
|
|
1436
|
+
* - `appId` - Optional appId for targeted window.emui[appId] cleanup
|
|
1437
|
+
*
|
|
1438
|
+
* - `cleanupFunctionName` - Name of cleanup function on window.emui (default: 'unmount')
|
|
1439
|
+
* @param guestIdOrWindowOrEle - Unique id, window object, or iframe element
|
|
1440
|
+
* @param options - Optional cleanup configuration
|
|
1441
|
+
* @param options.purgeOnDestroy - When true, use comprehensive cleanup sequence
|
|
1442
|
+
* @param options.windowRefsToClear - Array of window ref paths to clear (e.g., ["window.IMT.focusFormTitle"])
|
|
1443
|
+
* @param options.appId - Optional appId for targeted cleanup
|
|
1444
|
+
* @param options.cleanupFunctionName - Guest cleanup function name (default: 'unmount')
|
|
1445
|
+
* @example
|
|
1446
|
+
* // Basic cleanup
|
|
1447
|
+
* host.unloadGuest('my-guest-id');
|
|
1448
|
+
* @example
|
|
1449
|
+
* // Enhanced cleanup with purge
|
|
1450
|
+
* host.unloadGuest('my-guest-id', {
|
|
1451
|
+
* purgeOnDestroy: true,
|
|
1452
|
+
* windowRefsToClear: ["window.IMT.focusFormTitle"],
|
|
1453
|
+
* cleanupFunctionName: 'appCleanup'
|
|
1454
|
+
* });
|
|
1455
|
+
* @example
|
|
1456
|
+
* // Enhanced cleanup with appId
|
|
1457
|
+
* host.unloadGuest('my-guest-id', {
|
|
1458
|
+
* purgeOnDestroy: true,
|
|
1459
|
+
* appId: 'workflowtasks',
|
|
1460
|
+
* cleanupFunctionName: 'cleanup'
|
|
1461
|
+
* });
|
|
1462
|
+
*/
|
|
1463
|
+
unloadGuest = (guestIdOrWindowOrEle, options) => {
|
|
1180
1464
|
const guest = this.#findGuest(guestIdOrWindowOrEle);
|
|
1181
|
-
if (guest) {
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1465
|
+
if (!guest) {
|
|
1466
|
+
this.#logger.warn("Attempted to unload unknown guest");
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
const guestId = guest.id;
|
|
1470
|
+
if (options?.purgeOnDestroy) {
|
|
1471
|
+
const cleanupFunctionName = options.cleanupFunctionName || "unmount";
|
|
1472
|
+
if (options.windowRefsToClear && options.windowRefsToClear.length > 0) {
|
|
1473
|
+
this.#clearWindowRefs(options.windowRefsToClear, guestId);
|
|
1474
|
+
}
|
|
1475
|
+
this.unloadGuestWithFullCleanup(guestId, cleanupFunctionName);
|
|
1186
1476
|
this.#logger.audit({
|
|
1187
|
-
message: `Guest
|
|
1477
|
+
message: `Guest unloaded with purge mode (windowRefs: ${options.windowRefsToClear?.length || 0})`,
|
|
1188
1478
|
...guest.getInfo()
|
|
1189
1479
|
});
|
|
1190
|
-
|
|
1480
|
+
return;
|
|
1481
|
+
}
|
|
1482
|
+
guest.dispose();
|
|
1483
|
+
this.#guestsByWindow.delete(guest.window);
|
|
1484
|
+
this.#guestsByUrl.delete(guest.url);
|
|
1485
|
+
this.#guests.delete(guest.id);
|
|
1486
|
+
this.#logger.audit({
|
|
1487
|
+
message: `Guest is removed from host`,
|
|
1488
|
+
...guest.getInfo()
|
|
1489
|
+
});
|
|
1490
|
+
this.#stopMonitoringPopupGuests();
|
|
1491
|
+
};
|
|
1492
|
+
/**
|
|
1493
|
+
* Unloads guest application with comprehensive memory leak prevention.
|
|
1494
|
+
*
|
|
1495
|
+
* This method implements industry best practices for iframe and popup cleanup to prevent
|
|
1496
|
+
* memory leaks, particularly detached window retention and webpack bundle accumulation.
|
|
1497
|
+
*
|
|
1498
|
+
* **Enhanced Cleanup Sequence for Embedded Iframes:**
|
|
1499
|
+
* 1. Call guest cleanup function (React unmount, Redux teardown, etc.)
|
|
1500
|
+
* 2. Close contentWindow context explicitly
|
|
1501
|
+
* 3. Navigate iframe to about:blank (Chrome GC recommendation)
|
|
1502
|
+
* 4. Small delay, then remove iframe from DOM
|
|
1503
|
+
* 5. Remove from SSF tracking maps
|
|
1504
|
+
* 6. Null all internal references
|
|
1505
|
+
*
|
|
1506
|
+
* **Enhanced Cleanup Sequence for Popup Windows:**
|
|
1507
|
+
* 1. Call guest cleanup function (React unmount, Redux teardown, etc.)
|
|
1508
|
+
* 2. Null all window.emui and window.elli.script references
|
|
1509
|
+
* 3. Clear Google Tag Manager data layer
|
|
1510
|
+
* 4. Close popup window explicitly
|
|
1511
|
+
* 5. Dispose guest (cleanup event listeners)
|
|
1512
|
+
* 6. Remove from SSF tracking maps
|
|
1513
|
+
*
|
|
1514
|
+
* **Memory Leak Prevention:**
|
|
1515
|
+
* - Breaks all closures from contentWindow/popup to parent
|
|
1516
|
+
* - Signals V8 to GC webpack bundle backing store strings
|
|
1517
|
+
* - Removes iframe from browser back/forward cache
|
|
1518
|
+
* - Clears all SSF remoting message handlers
|
|
1519
|
+
* - Nulls all window.emui and window.elli.script properties
|
|
1520
|
+
*
|
|
1521
|
+
* **Important:** This method does NOT clean up window.emui[appId] registry.
|
|
1522
|
+
* When using selfInitialize=true pattern, the guest application handles
|
|
1523
|
+
* its own emui registry cleanup internally.
|
|
1524
|
+
*
|
|
1525
|
+
* **Synchronous Design:** This method is intentionally synchronous to work
|
|
1526
|
+
* with React useEffect cleanup functions. Cleanup steps use setTimeout
|
|
1527
|
+
* for deferred operations rather than async/await.
|
|
1528
|
+
* @param guestIdOrWindowOrEle - unique id of the guest application or window object or dom element
|
|
1529
|
+
* @param cleanupFunctionName - name of cleanup function on window.emui (default: 'unmount')
|
|
1530
|
+
* @example
|
|
1531
|
+
* // Standard usage with app cleanup
|
|
1532
|
+
* host.unloadGuestWithFullCleanup('my-guest-id', 'appCleanup');
|
|
1533
|
+
* @example
|
|
1534
|
+
* // Usage with custom cleanup function
|
|
1535
|
+
* host.unloadGuestWithFullCleanup('my-guest-id', 'customUnmount');
|
|
1536
|
+
* @example
|
|
1537
|
+
* // Usage when guest uses default unmount
|
|
1538
|
+
* host.unloadGuestWithFullCleanup('my-guest-id');
|
|
1539
|
+
*/
|
|
1540
|
+
/**
|
|
1541
|
+
* Disconnect FieldMutation observer for an iframe body element
|
|
1542
|
+
* @param {Window | null} contentWindow - Guest iframe contentWindow
|
|
1543
|
+
* @param {string} guestId - Guest ID for logging
|
|
1544
|
+
*/
|
|
1545
|
+
#disconnectFieldMutationObserver = (contentWindow, guestId) => {
|
|
1546
|
+
try {
|
|
1547
|
+
const bodyElement = contentWindow?.document?.body;
|
|
1548
|
+
if (!bodyElement) return;
|
|
1549
|
+
const { observerReferences } = window;
|
|
1550
|
+
if (!(observerReferences instanceof Map) || !observerReferences.has(bodyElement)) {
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
const observer = observerReferences.get(bodyElement);
|
|
1554
|
+
if (observer && typeof observer.disconnect === "function") {
|
|
1555
|
+
observer.disconnect();
|
|
1556
|
+
observerReferences.delete(bodyElement);
|
|
1557
|
+
this.#logger.debug(
|
|
1558
|
+
`[SSF] Disconnected FieldMutation observer for guest ${guestId}`
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
} catch (e) {
|
|
1562
|
+
this.#logger.debug(
|
|
1563
|
+
`[SSF] Failed to disconnect FieldMutation observer for guest ${guestId}: ${e.message}`
|
|
1564
|
+
);
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1567
|
+
/**
|
|
1568
|
+
* Cleanup and remove iframe from DOM
|
|
1569
|
+
* @param {HTMLIFrameElement} iframe - Iframe element to cleanup
|
|
1570
|
+
* @param {Window | null} contentWindow - Iframe contentWindow
|
|
1571
|
+
* @param {string} guestId - Guest ID for logging
|
|
1572
|
+
*/
|
|
1573
|
+
#cleanupIframe = (iframe, contentWindow, guestId) => {
|
|
1574
|
+
try {
|
|
1575
|
+
if (contentWindow && !contentWindow.closed) {
|
|
1576
|
+
contentWindow.close();
|
|
1577
|
+
this.#logger.debug(
|
|
1578
|
+
`[SSF] Called contentWindow.close() for guest ${guestId}`
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
} catch (e) {
|
|
1582
|
+
this.#logger.debug(
|
|
1583
|
+
`[SSF] contentWindow.close() failed for guest ${guestId}: ${e.message}`
|
|
1584
|
+
);
|
|
1585
|
+
}
|
|
1586
|
+
try {
|
|
1587
|
+
if (iframe.parentNode) {
|
|
1588
|
+
iframe.src = "about:blank";
|
|
1589
|
+
this.#logger.debug(
|
|
1590
|
+
`[SSF] Navigated to about:blank for guest ${guestId}`
|
|
1591
|
+
);
|
|
1592
|
+
}
|
|
1593
|
+
} catch (e) {
|
|
1594
|
+
this.#logger.debug(
|
|
1595
|
+
`[SSF] Failed to navigate iframe to about:blank for guest ${guestId}: ${e.message}`
|
|
1596
|
+
);
|
|
1597
|
+
}
|
|
1598
|
+
setTimeout(() => {
|
|
1599
|
+
try {
|
|
1600
|
+
if (iframe.parentNode) {
|
|
1601
|
+
iframe.remove();
|
|
1602
|
+
this.#logger.debug(
|
|
1603
|
+
`[SSF] Removed iframe from DOM for guest ${guestId}`
|
|
1604
|
+
);
|
|
1605
|
+
}
|
|
1606
|
+
} catch (e) {
|
|
1607
|
+
this.#logger.warn(
|
|
1608
|
+
`[SSF] Failed to remove iframe for guest ${guestId}: ${e.message}`
|
|
1609
|
+
);
|
|
1610
|
+
}
|
|
1611
|
+
}, 10);
|
|
1612
|
+
};
|
|
1613
|
+
/**
|
|
1614
|
+
* Cleanup popup window
|
|
1615
|
+
* @param {Window | null} popupWindow - Popup window to cleanup
|
|
1616
|
+
* @param {string} guestId - Guest ID for logging
|
|
1617
|
+
*/
|
|
1618
|
+
#cleanupPopup = (popupWindow, guestId) => {
|
|
1619
|
+
try {
|
|
1620
|
+
if (popupWindow && !popupWindow.closed) {
|
|
1621
|
+
popupWindow.close();
|
|
1622
|
+
this.#logger.debug(`[SSF] Closed popup window for guest ${guestId}`);
|
|
1623
|
+
}
|
|
1624
|
+
} catch (e) {
|
|
1625
|
+
this.#logger.debug(
|
|
1626
|
+
`[SSF] Failed to close popup window for guest ${guestId}: ${e.message}`
|
|
1627
|
+
);
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
/**
|
|
1631
|
+
* Remove guest from remoting allowed senders
|
|
1632
|
+
*/
|
|
1633
|
+
#removeRemotingSender = (guest, guestId) => {
|
|
1634
|
+
try {
|
|
1635
|
+
this.#remoting.removeSender({
|
|
1636
|
+
origin: guest.origin,
|
|
1637
|
+
window: guest.window
|
|
1638
|
+
});
|
|
1639
|
+
this.#logger.debug(`[SSF] Removed remoting sender for guest ${guestId}`);
|
|
1640
|
+
} catch (e) {
|
|
1641
|
+
this.#logger.debug(
|
|
1642
|
+
`[SSF] Failed to remove remoting sender for guest ${guestId}: ${e.message}`
|
|
1643
|
+
);
|
|
1644
|
+
}
|
|
1645
|
+
};
|
|
1646
|
+
/**
|
|
1647
|
+
* Remove guest from all SSF tracking maps
|
|
1648
|
+
*/
|
|
1649
|
+
#removeGuestFromTracking = (guest, guestId) => {
|
|
1650
|
+
this.#guestsByWindow.delete(guest.window);
|
|
1651
|
+
this.#guestsByUrl.delete(guest.url);
|
|
1652
|
+
this.#guests.delete(guestId);
|
|
1653
|
+
};
|
|
1654
|
+
unloadGuestWithFullCleanup = (guestIdOrWindowOrEle, cleanupFunctionName = "unmount") => {
|
|
1655
|
+
const guest = this.#findGuest(guestIdOrWindowOrEle);
|
|
1656
|
+
if (!guest) {
|
|
1657
|
+
this.#logger.warn("Attempted to unload unknown guest");
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
const guestId = guest.id;
|
|
1661
|
+
if (guest.openMode === OpenMode.Embed && guest.domElement) {
|
|
1662
|
+
const iframe = guest.domElement;
|
|
1663
|
+
const contentWindow = guest.window;
|
|
1664
|
+
this.#cleanupGuestWindow({
|
|
1665
|
+
guestWindow: contentWindow,
|
|
1666
|
+
guestId,
|
|
1667
|
+
cleanupFunctionName,
|
|
1668
|
+
windowType: "iframe"
|
|
1669
|
+
});
|
|
1670
|
+
this.#disconnectFieldMutationObserver(contentWindow, guestId);
|
|
1671
|
+
this.#cleanupIframe(iframe, contentWindow, guestId);
|
|
1672
|
+
} else if (guest.openMode === OpenMode.Popup) {
|
|
1673
|
+
const popupWindow = guest.window;
|
|
1674
|
+
this.#cleanupGuestWindow({
|
|
1675
|
+
guestWindow: popupWindow,
|
|
1676
|
+
guestId,
|
|
1677
|
+
cleanupFunctionName,
|
|
1678
|
+
windowType: "popup"
|
|
1679
|
+
});
|
|
1680
|
+
this.#cleanupPopup(popupWindow, guestId);
|
|
1681
|
+
guest.dispose();
|
|
1191
1682
|
}
|
|
1683
|
+
this.#removeRemotingSender(guest, guestId);
|
|
1684
|
+
this.#removeGuestFromTracking(guest, guestId);
|
|
1685
|
+
this.#stopMonitoringPopupGuests();
|
|
1686
|
+
this.#logger.audit({
|
|
1687
|
+
message: `Guest unloaded with full cleanup`,
|
|
1688
|
+
...guest.getInfo()
|
|
1689
|
+
});
|
|
1192
1690
|
};
|
|
1193
1691
|
/**
|
|
1194
1692
|
* monitors guest window close action and executes the callback from host.
|
|
1195
|
-
* @param
|
|
1196
|
-
* @param id unique id of the guest application
|
|
1197
|
-
* @param param
|
|
1693
|
+
* @param {GuestCloseParam} param - Guest close parameters
|
|
1198
1694
|
*/
|
|
1199
1695
|
onGuestClose = (param) => {
|
|
1200
1696
|
const { id, guestCloseCallback } = param;
|
package/dist/public/index.html
CHANGED
|
@@ -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>Host</title><script src="https://cdn.tailwindcss.com?plugins=forms"></script><script src="https://cdn.mortgagetech.q1.ice.com/pui-diagnostics@3"></script><script defer="defer" src="js/emuiSsfHost.
|
|
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>Host</title><script src="https://cdn.tailwindcss.com?plugins=forms"></script><script src="https://cdn.mortgagetech.q1.ice.com/pui-diagnostics@3"></script><script defer="defer" src="js/emuiSsfHost.c95491c428f3f102185b.js"></script></head><body><header class="bg-indigo-300 h-10 flex place-items-center"><div class="px-2">ICE Mortgage Product</div></header><main class="mx-auto max-w-7xl px-2 sm:px-6 lg:px-8"><div class="min-w-0 flex-1 mt-4"><h1 class="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">Loan Application</h1></div><div id="successFeedback" class="hidden rounded-md bg-green-50 p-4"><div class="flex"><div class="flex-shrink-0"><svg class="h-5 w-5 text-green-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd"/></svg></div><div class="ml-3"><p class="text-sm font-medium text-green-800">Loan Saved Successfully</p></div></div></div><div id="errorFeedback" class="hidden rounded-md bg-red-50 p-4"><div class="flex"><div class="flex-shrink-0"><svg class="h-5 w-5 text-red-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z" clip-rule="evenodd"/></svg></div><div class="ml-3"><h3 class="text-sm font-medium text-red-800">Credit Score is not meeting the requirement</h3></div></div></div><div class="mt-2 sm:grid sm:grid-cols-2 sm:gap-2"><form class="px-2 py-2 space-y-8 divide-y divide-gray-200 bg-gray-50"><div class="space-y-8 divide-y divide-gray-200 sm:space-y-5"><div class="space-y-6 sm:space-y-5"><div><h3 class="text-lg font-medium leading-6 text-gray-900">Personal Information</h3></div><div class="space-y-6 sm:space-y-5"><div class="sm:grid sm:grid-cols-3 sm:items-start sm:gap-4 sm:border-gray-200"><label for="firstName" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">First name</label><div class="mt-1 sm:col-span-2 sm:mt-0"><input name="firstName" id="firstName" autocomplete="given-name" class="block w-full max-w-lg rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:max-w-xs sm:text-sm" value="John" placeholder="John"/></div></div><div class="sm:grid sm:grid-cols-3 sm:items-start sm:gap-4 sm:border-gray-200"><label for="lastName" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">Last name</label><div class="mt-1 sm:col-span-2 sm:mt-0"><input name="lastName" id="lastName" autocomplete="family-name" class="block w-full max-w-lg rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:max-w-xs sm:text-sm" value="Doe" placeholder="Doe"/></div></div><div class="sm:grid sm:grid-cols-3 sm:items-start sm:gap-4 sm:border-gray-200"><label for="ssn" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">SSN</label><div class="mt-1 sm:col-span-2 sm:mt-0"><input type="number" name="ssn" id="ssn" class="block w-full max-w-lg rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:max-w-xs sm:text-sm" value="123456789" placeholder="123456789"/></div></div></div><div><h3 class="text-lg font-medium leading-6 text-gray-900">Loan Information</h3></div><div class="space-y-6 sm:space-y-5"><div class="sm:grid sm:grid-cols-3 sm:items-start sm:gap-4 sm:border-gray-200"><label for="amount" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">Amount</label><div class="mt-1 sm:col-span-2 sm:mt-0"><input type="number" name="amount" id="amount" class="block w-full max-w-lg rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:max-w-xs sm:text-sm" value="500000" placeholder="500000"/></div></div><div class="sm:grid sm:grid-cols-3 sm:items-start sm:gap-4 sm:border-gray-200"><label for="Term" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">Term (years)</label><div class="mt-1 sm:col-span-2 sm:mt-0"><input type="number" name="term" id="term" class="block w-full max-w-lg rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:max-w-xs sm:text-sm" value="30" placeholder="30"/></div></div><div class="sm:grid sm:grid-cols-3 sm:items-start sm:gap-4 sm:border-gray-200"><label for="downPayment" class="block text-sm font-medium text-gray-700 sm:mt-px sm:pt-2">Down Payment</label><div class="mt-1 sm:col-span-2 sm:mt-0"><input type="number" name="downPayment" id="downPayment" class="block w-full max-w-lg rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:max-w-xs sm:text-sm" value="50000" placeholder="50000"/></div></div><div><h3 class="text-lg font-medium leading-6 text-gray-900">Order Services</h3></div><div class="sm:grid sm:grid-cols-3 sm:items-start sm:gap-4 sm:border-gray-200"><div class="mt-1 sm:mt-0"><button id="title" type="button" class="inline-flex items-center rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed focus:ring-offset-2"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6"><path fill-rule="evenodd" d="M7.502 6h7.128A3.375 3.375 0 0118 9.375v9.375a3 3 0 003-3V6.108c0-1.505-1.125-2.811-2.664-2.94a48.972 48.972 0 00-.673-.05A3 3 0 0015 1.5h-1.5a3 3 0 00-2.663 1.618c-.225.015-.45.032-.673.05C8.662 3.295 7.554 4.542 7.502 6zM13.5 3A1.5 1.5 0 0012 4.5h4.5A1.5 1.5 0 0015 3h-1.5z" clip-rule="evenodd"/><path fill-rule="evenodd" d="M3 9.375C3 8.339 3.84 7.5 4.875 7.5h9.75c1.036 0 1.875.84 1.875 1.875v11.25c0 1.035-.84 1.875-1.875 1.875h-9.75A1.875 1.875 0 013 20.625V9.375zM6 12a.75.75 0 01.75-.75h.008a.75.75 0 01.75.75v.008a.75.75 0 01-.75.75H6.75a.75.75 0 01-.75-.75V12zm2.25 0a.75.75 0 01.75-.75h3.75a.75.75 0 010 1.5H9a.75.75 0 01-.75-.75zM6 15a.75.75 0 01.75-.75h.008a.75.75 0 01.75.75v.008a.75.75 0 01-.75.75H6.75a.75.75 0 01-.75-.75V15zm2.25 0a.75.75 0 01.75-.75h3.75a.75.75 0 010 1.5H9a.75.75 0 01-.75-.75zM6 18a.75.75 0 01.75-.75h.008a.75.75 0 01.75.75v.008a.75.75 0 01-.75.75H6.75a.75.75 0 01-.75-.75V18zm2.25 0a.75.75 0 01.75-.75h3.75a.75.75 0 010 1.5H9a.75.75 0 01-.75-.75z" clip-rule="evenodd"/></svg> Title</button></div><div class="mt-1 sm:mt-0"><button id="credit" type="button" class="inline-flex items-center rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed focus:ring-offset-2"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6"><path fill-rule="evenodd" d="M2.25 13.5a8.25 8.25 0 018.25-8.25.75.75 0 01.75.75v6.75H18a.75.75 0 01.75.75 8.25 8.25 0 01-16.5 0z" clip-rule="evenodd"/><path fill-rule="evenodd" d="M12.75 3a.75.75 0 01.75-.75 8.25 8.25 0 018.25 8.25.75.75 0 01-.75.75h-7.5a.75.75 0 01-.75-.75V3z" clip-rule="evenodd"/></svg> Credit Score</button></div></div></div></div></div><div class="flex flex-col"><button id="saveLoan" type="button" class="rounded-md border border-transparent bg-indigo-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">Save</button></div></form><div id="aside-container" class="flex flex-col gap-4 items-start mt-4 border-2 p-2 rounded-lg border-dashed border-cyan-300 sm:mt-0"></div></div><div id="bottom-container" class="flex flex-col gap-4 items-start mt-4 p-2 sm:mt-0"></div></main><script src="./init.js" type="module"></script></body></html>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function(O,$){typeof exports=="object"&&typeof module=="object"?module.exports=$():typeof define=="function"&&define.amd?define([],$):typeof exports=="object"?exports.ice=$():(O.ice=O.ice||{},O.ice.host=$())})(globalThis,()=>(()=>{"use strict";var S={};S.d=(o,e)=>{for(var t in e)S.o(e,t)&&!S.o(o,t)&&Object.defineProperty(o,t,{enumerable:!0,get:e[t]})},S.o=(o,e)=>Object.prototype.hasOwnProperty.call(o,e),S.r=o=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})};var O={};S.r(O),S.d(O,{Event:()=>$,Guest:()=>F,IFrameSandboxValues:()=>j,OpenMode:()=>f,SANDBOX_DEFAULT:()=>W,SSFHost:()=>ie,ScriptingObject:()=>R});class ${name;objectId;id;constructor(e){const{name:t,objectId:i}=e;if(!t)throw new Error("Event name is required");if(!i)throw new Error("Scripting object id is required");this.objectId=i,this.name=t,this.id=`${this.objectId}.${this.name}`.toLowerCase()}}class A{static[Symbol.hasInstance](e){return typeof e=="object"&&e!==null&&"getType"in e&&typeof e.getType=="function"&&e.getType()==="ProxyEvent"}#t;objectId;name;id;getType(){return"ProxyEvent"}constructor(e){const{name:t,objectId:i,eventSrc:s}=e;if(!t)throw new Error("Event name is required");if(!i)throw new Error("Scripting object id is required");if(!s)throw new Error("Event source is required");this.objectId=i,this.name=t,this.#t=s,this.id=`${this.objectId}.${this.name}`.toLowerCase()}subscribe=e=>this.#t.subscribe({eventId:this.id,callback:e});unsubscribe=e=>{this.#t.unsubscribe({eventId:this.id,token:e})}}const z=o=>o instanceof $,se=(o,e)=>`${o.toLowerCase()}.${e.toLowerCase()}`,B="function",H=(o,e)=>typeof o===B&&!!e&&!e.startsWith("_");class R{#t;#i="Object";constructor(e,t){this.#t=e,this.#i=t||this.#i}get id(){return this.#t}get objectType(){return this.#i}_toJSON=()=>{const e=[],t=[];return Object.keys(this).forEach(i=>{const s=this[i];z(s)?t.push(i):H(s,i)&&e.push(i)}),{objectId:this.#t,objectType:this.#i,functions:e,events:t}};_dispose=()=>{};dispose=()=>{}}var d=(o=>(o.GuestClose="guest:close",o.GuestEventSubscribe="guest:eventSubscribe",o.GuestEventUnsubscribe="guest:eventUnsubscribe",o.GuestFocus="guest:focus",o.GuestReady="guest:ready",o.GuestReadyComplete="guest:readyComplete",o.GuestResize="guest:resize",o.HandShake="handshake",o.HandShakeAck="handshake:ack",o.HostClose="host:close",o.HostConfig="host:config",o.ListObjects="list:objects",o.ObjectEvent="object:event",o.ObjectGet="object:get",o.ObjectInvoke="object:invoke",o))(d||{}),f=(o=>(o.Popup="popup",o.Embed="embed",o))(f||{}),j=(o=>(o.AllowDownloadsWithoutUserActivation="allow-downloads-without-user-activation",o.AllowDownloads="allow-downloads",o.AllowForms="allow-forms",o.AllowModals="allow-modals",o.AllowOrientationLock="allow-orientation-lock",o.AllowPointerLock="allow-pointer-lock",o.AllowPopups="allow-popups",o.AllowPopupsToEscapeSandbox="allow-popups-to-escape-sandbox",o.AllowPresentation="allow-presentation",o.AllowSameOrigin="allow-same-origin",o.AllowScripts="allow-scripts",o.AllowStorageAccessByUserActivation="allow-storage-access-by-user-activation",o.AllowTopNavigation="allow-top-navigation",o.AllowTopNavigationByUserActivation="allow-top-navigation-by-user-activation",o))(j||{});const J=o=>{if(o==="about:blank")return"*";try{const{origin:e}=new URL(o);return e==="null"||!e?o:e}catch{const{origin:t}=new URL(o,document.baseURI);return t}},Y=o=>o.flat(1/0).filter(e=>e!==void 0);function C(o){return typeof o=="function"}class F{id;title;url;searchParams;domElement;window;openMode;origin;initialized=!1;ready=!1;capabilities;#t;#i;constructor(e){const{guestId:t,domElement:i=null,title:s,url:n,window:r,searchParams:c={},openMode:a=f.Embed,remoting:l,analyticsObj:u}=e;this.id=t,this.title=s,this.url=n,this.origin=J(n),this.searchParams=c,this.domElement=i,this.window=r,this.openMode=a,this.capabilities={},this.#i=u,this.#t=l}dispose=()=>{if(this.openMode===f.Popup&&!this.window.closed)try{this.window.document,this.window.close()}catch{this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:d.HostClose,messageBody:{}})}else this.domElement?.remove?.();this.#t.removeSender({origin:this.origin,window:this.window})};getInfo=()=>({guestId:this.id,guestTitle:this.title,guestUrl:this.url});handShake=()=>new Promise(e=>{let t=0;const i=5;let s;const n=()=>{clearInterval(s),this.#t.unlisten({messageType:d.HandShakeAck,callback:n}),e(!0)};s=setInterval(()=>{t>=i?(clearInterval(s),this.#t.unlisten({messageType:d.HandShakeAck,callback:n}),e(!1)):(this.#t.send({targetWin:this.window,targetOrigin:this.origin,messageType:d.HandShake,messageBody:{}}),t+=1)},1e3),this.#t.listen({messageType:d.HandShakeAck,callback:n})});init=()=>{this.#t.addSender({origin:this.origin,window:this.window}),this.openMode===f.Popup&&this.handShake().catch(()=>{})};dispatchEvent=(e,t)=>(this.#i.startTiming(`ScriptingObject.Event.${e.object.objectId}.${e.eventName}`,{appId:this.id,appUrl:this.url}).catch(()=>{}),this.#t.invoke({targetWin:this.window,targetOrigin:this.origin,messageType:d.ObjectEvent,messageBody:e,responseTimeoutMs:t}).finally(()=>{this.#i.endTiming(`ScriptingObject.Event.${e.object.objectId}.${e.eventName}`,{appId:this.id,appUrl:this.url}).catch(()=>{})}));send=e=>{this.#t.send({targetWin:this.window,targetOrigin:this.origin,...e})}}const U={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let G;const X=new Uint8Array(16);function K(){if(!G&&(G=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!G))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return G(X)}var Q;const h=[];for(let o=0;o<256;++o)h.push((o+256).toString(16).slice(1));function L(o,e=0){return h[o[e+0]]+h[o[e+1]]+h[o[e+2]]+h[o[e+3]]+"-"+h[o[e+4]]+h[o[e+5]]+"-"+h[o[e+6]]+h[o[e+7]]+"-"+h[o[e+8]]+h[o[e+9]]+"-"+h[o[e+10]]+h[o[e+11]]+h[o[e+12]]+h[o[e+13]]+h[o[e+14]]+h[o[e+15]]}function oe(o,e=0){const t=L(o,e);if(!Q(t))throw TypeError("Stringified UUID is invalid");return t}const re=null;function Z(o,e,t){if(U.randomUUID&&!e&&!o)return U.randomUUID();o=o||{};const i=o.random||(o.rng||K)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){t=t||0;for(let s=0;s<16;++s)e[t+s]=i[s];return e}return L(i)}const M=Z,q="elli:remoting",_="elli:remoting:response",x="elli:remoting:exception",k=({messageType:o,messageBody:e,requestId:t,onewayMsg:i=!1})=>({requestId:t??(i?null:M()),source:q,type:o,body:e}),ce=o=>{const{targetWin:e,targetOrigin:t,messageType:i,messageBody:s}=o,n=k({messageType:i,messageBody:s});e.postMessage(n,t)};class V{#t;#i;#e=new Map;#r=new Map;#s=null;#n=null;#c=new Map;#d;constructor(e,t,i){if(!e)throw new Error("logger is required");if(!t)throw new Error("correlationId is required");this.#t=t,this.#i=e,this.#d=i?.unsafeAllowAnyGuestOrigin??!1}#o=e=>this.#d?"*":e;#f=()=>{this.#s=null;const e=Date.now(),t=[];let i=null;if(this.#r.forEach((s,n)=>{const{requestId:r,cancelTime:c}=s;c&&c<=e?(this.#i.debug(`Detected response timeout for requestId: ${r}...`),t.push(n),s.resolve(void 0)):c&&(i=i===null?c:Math.min(i,c))}),t.forEach(s=>{this.#r.delete(s)}),i!==null){const s=Math.max(i-Date.now(),0);this.#a(s)}};#a=e=>{this.#s===null&&(this.#s=window.setTimeout(this.#f,e))};#b=()=>{this.#s!==null&&(window.clearTimeout(this.#s),this.#s=null)};#h=e=>{const t=this.#r.get(e);return this.#i.debug(`serving requestId: ${e}`),this.#r.delete(e),t};#m=e=>{const{requestId:t}=e;this.#i.debug(`Response received for invocation requestId: ${t}`);const i=this.#h(t);return i?(i.resolve(e.body),!0):(this.#i.debug(`Received response to stale/invalid request with requestId: ${t}`),!1)};#g=e=>{this.#i.debug(`Exception received for invocation (requestId = ${e.requestId})`);const t=this.#h(e.requestId);return t?(t.reject(new Error(e.body)),!0):(this.#i.warn(`Received exception for stale/invalid request (requestId = ${e.requestId})`),!1)};#p=({sourceWin:e,sourceOrigin:t,message:i})=>{this.#i.debug(`Received message of type "${i.type}"`);const s=this.#e.get(i.type);return s?(s.forEach(n=>{this.#i.debug(`Invoking message handler ${n.name}`),n({sourceWin:e,sourceOrigin:t,requestId:i.requestId,type:i.type,body:i.body})}),!0):!1};#u=e=>{if(this.#c.size===0||!e.source)return!1;const t=this.#c.get(e.source);return!t||e?.data?.source!==q?!1:(this.#i.debug(`Remoting: Received message of type "${e.data.type}"`),e.data.type===_?this.#m(e.data):e.data.type===x?this.#g(e.data):this.#p({sourceWin:e.source,sourceOrigin:t,message:e.data}),!0)};addSender=e=>{const{origin:t,window:i}=e;if(!t)throw new Error("origin is required");if(!i)throw new Error("window is required");this.#c.set(i,t)};initialize=e=>{this.#n&&this.#n.removeEventListener("message",this.#u),e.addEventListener("message",this.#u),this.#n=e,this.#i.debug(`initialized remoting id: ${this.#t}`)};close=()=>{this.#n&&(this.#n.removeEventListener("message",this.#u),this.#n=null),this.#b(),this.#i.debug(`closed remoting id: ${this.#t}`)};invoke=e=>{const{targetWin:t,targetOrigin:i,messageType:s,messageBody:n,responseTimeoutMs:r}=e;return new Promise((c,a)=>{const l=k({messageType:s,messageBody:n});this.#r.set(l.requestId,{requestId:l.requestId,resolve:c,reject:a,cancelTime:r?Date.now()+r:null}),t.postMessage(l,this.#o(i));const{requestId:u}=l;this.#i.debug(`Posted invocation message of type ${s} requestId: ${u||""}`),r&&(this.#i.debug(`scheduling timeout check for requestId: ${u||""} in ${r} ms`),this.#a(r))})};listen=e=>{const{messageType:t,callback:i}=e,s=this.#e.get(t)||[];s.push(i),this.#e.set(t,s)};unlisten=e=>{const{messageType:t,callback:i}=e,s=this.#e.get(t);if(!s)return;const n=s.indexOf(i);n!==-1&&s.splice(n,1)};send=e=>{const{targetWin:t,targetOrigin:i,messageType:s,messageBody:n}=e,r=k({messageType:s,messageBody:n,onewayMsg:!0});t.postMessage(r,this.#o(i)),this.#i.debug(`Posted one-way message of type "${s}"`)};removeSender=e=>{const{window:t}=e;t&&this.#c.delete(t)};respond=e=>{const{targetWin:t,targetOrigin:i,requestId:s,response:n}=e,r=k({messageType:_,messageBody:n,requestId:s});t.postMessage(r,this.#o(i)),this.#i.debug(`Response sent to caller for invocation requestId: ${s}`)};raiseException=e=>{const{targetWin:t,targetOrigin:i,requestId:s,ex:n}=e,r=n instanceof Error?n.message:n,c=k({messageType:x,messageBody:r,requestId:s});t.postMessage(c,this.#o(i)),this.#i.debug(`Exception sent to caller for invocation. requestId: ${s}`)}}const D="module";var ee=(o=>(o.USER="USER",o.PARTNER="PARTNER",o))(ee||{});class te{#t=e=>e.trim().toLowerCase();#i=new Map;#e=new Map;#r=e=>{const{so:t,guestId:i}=e,s=this.#t(t.id),n=this.#e.get(i);if(!n)this.#e.set(i,new Map([[s,e]]));else{if(n.has(s))throw new Error(`Scripting Object ${t.id} already exists for guest ${i}`);n.set(s,e)}};#s=({so:e})=>{if(e._dispose&&typeof e._dispose=="function")try{e._dispose()}catch{}};#n=({objectId:e,guestId:t})=>{if(e===D&&!t)for(const[,s]of this.#e){const n=s.get(e);if(n)return n}const i=t?this.#e.get(t):null;return i?i.get(e)??null:null};#c=({objectId:e,guestId:t}={})=>{if(t){if(!e){const s=this.#e.get(t);s&&s.forEach(this.#s),this.#e.delete(t);return}const i=this.#e.get(t);if(i){const s=i.get(e);s&&this.#s(s),i.delete(e)}}else e&&this.#e.forEach(i=>{const s=i.get(e);s&&this.#s(s),i.delete(e)})};addScriptingObject=(e,t)=>{const{guestId:i}=t||{};if(!e?.id||!e?._toJSON)throw new Error("Object is not derived from ScriptingObject");const s=this.#t(e.id);if(s===D&&!i)throw new Error("Guest id is required to add Module scripting object");if(i){this.#r({so:e,...t,guestId:i});return}if(this.#i.has(s))throw new Error(`Scripting Object ${e.id} already exists`);this.#i.set(s,{so:e,...t})};getObject=(e,t)=>{const i=this.#t(e);let s=this.#n({objectId:i,guestId:t?.id});s=s??this.#i.get(i)??null;const{so:n}=s||{};return n||null};has=(e,t)=>this.getObject(e,t)!==null;listScriptingObjects=e=>{const t=new Set(this.#i.keys()),i=this.#e.get(e);if(i)for(const s of i.keys())t.add(s);return Array.from(t)};removeScriptingObject=(e,t)=>{const i=this.#t(e);if(t)this.#c({objectId:i,guestId:t});else{this.#c({objectId:i});const s=this.#i.get(i);s&&this.#s(s),this.#i.delete(i)}};removeAllScriptingObjects=e=>{e?this.#c({guestId:e}):(this.#i.forEach(this.#s),this.#i.clear())}}class ae{__TYPE__="Proxy";id;objectType;constructor(e,t){this.id=e,this.objectType=t}}const N=o=>o?.constructor?.name==="Proxy"||o?.constructor?.name==="ScriptingObjectProxy"||o?.__TYPE__==="Proxy",W=[j.AllowScripts,j.AllowPopups,j.AllowModals,j.AllowForms,j.AllowDownloads,j.AllowSameOrigin];class ie{hostId;#t;#i;#e;#r;#s=new Map;#n=new Map;#c=new Map;#d=new Map;#o;#f=null;#a=null;#b=null;#h=null;constructor(e,t){if(this.hostId=e,!t?.logger)throw new Error("Logger is required");if(!t?.analyticsObj)throw new Error("Analytics object is required");if(this.#e=t.logger,this.#r=t.analyticsObj,this.#i=M(),this.#t=new V(this.#e,this.#i,{unsafeAllowAnyGuestOrigin:t?.unsafeAllowAnyGuestOrigin}),t?.readyStateCallback&&typeof t?.readyStateCallback!="function")throw new Error("readyStateCallback must be a function");this.#f=t?.readyStateCallback||null,this.#b=t?.onGuestEventSubscribe||null,this.#h=t?.onGuestEventUnsubscribe||null,this.#o=new te,this.#t.initialize(window),this.#M(),window.addEventListener("beforeunload",this.#u),this.#e.debug(`host is initialized. hostId: ${this.hostId}, correlationId: ${this.#i}`)}#m=(e,t)=>{const i={event:e,...t};this.#r.sendBAEvent(i).catch(s=>{this.#e.debug(`Analytics sendBAEvent failed: ${s.message}`)})};#g=(e,t)=>{this.#r.startTiming(e,t).catch(i=>{this.#e.debug(`Analytics startTiming failed: ${i.message}`)})};#p=(e,t)=>{this.#r.endTiming(e,t).catch(i=>{this.#e.debug(`Analytics endTiming failed: ${i.message}`)})};#u=()=>{Array.from(this.#s.values()).filter(t=>t.openMode===f.Popup).map(t=>t.id).forEach(t=>this.unloadGuest(t))};#l=e=>this.#n.get(e);#O=e=>this.#c.get(e)??null;#k=e=>typeof e?._toJSON=="function";#v=(e,t)=>this.#k(e)?(this.#o.has(e?.id,t)||this.#o.addScriptingObject(e,t?{guestId:t?.id}:{}),{type:"object",object:e._toJSON()}):{type:"value",value:e};#se=e=>typeof e=="string"?e:e instanceof Error?e.message:"An unexpected error occurred in the host application";#y=e=>{e.ready&&this.#t.send({targetWin:e.window,targetOrigin:e.origin,messageType:d.HostConfig,messageBody:{logLevel:this.#e.getLogLevel(),...e.getInfo()}})};#I=({guest:e,obj:t,functionName:i,functionParams:s})=>{const n=t[i];return C(n)?(this.#e.debug(`Invoking host implementation of ${t.id}.${String(i)}()`),new Promise(r=>{Object.defineProperty(n,"callContext",{value:{guest:e},configurable:!0,enumerable:!0,writable:!0}),r(n(...s))})):(this.#e.warn(`Attempt to call invalid function on object type ${t.objectType}: ${String(i)}`),Promise.reject(new Error(`Method '${i}' not found in Scripting Object '${t.id}'`)))};#E=({sourceWin:e,sourceOrigin:t,requestId:i})=>{const s=this.#l(e);if(!s){this.#e.warn(`Received ready event for unknown guest. requestId: ${i}`);return}if(!s.initialized){this.#e.warn("Guest must be initialized before it is marked as ready"),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:"Guest must be initialized before it is marked as ready"});return}if(!s.ready){s.ready=!0;const n=s.getInfo();this.#p("SSF.Guest.Load",{appId:n.guestId,appUrl:n.guestUrl}),this.#y(s),this.#f?.(s),this.#e.audit({message:"Guest is ready",...n})}};#G=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const n=this.#l(e);if(!n){this.#e.warn(`Received ready event for unknown guest. requestid = ${i}`);return}n.initialized||(n.initialized=!0,n.capabilities=s||{},this.#e.audit({message:"Guest is initialized",...n.getInfo()})),(!s||!s.onReady)&&this.#E({sourceWin:e,sourceOrigin:t,requestId:i,type:"",body:null})};#P=async({sourceWin:e})=>{if(e?.window){const t=this.#w(e);t&&!await t.handShake()&&this.unloadGuest(e)}};#T=({sourceWin:e,sourceOrigin:t,requestId:i})=>{this.#e.debug(`Processing listObjects request. requestId = ${i}`);const s=this.#l(e);if(!s)return this.#e.warn("Rejected object request from unknown guest window"),!1;const n=this.#o.listScriptingObjects(s.id);return this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:n}),this.#e.debug({message:"name of scripting objects returned",requestId:i,objects:n,...s.getInfo()}),!0};#A=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:n}=s;this.#e.debug(`Processing getObject request for object ${n}. requestId = ${i}`);const r=this.#l(e);if(!r)return this.#e.warn("Rejected object request from unknown guest window"),!1;const c=this.getScriptingObject(n,{guest:r});return c?(this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:this.#v(c,r)}),this.#e.debug({message:"Scripting Object returned",requestId:i,scriptingObject:n,...r.getInfo()}),!0):(this.#e.warn(`unknown or unauthorized object ${n} from guest ${r.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:`The requested object (${n}) is not available`}),!1)};#R=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,criteria:n,token:r}=i;this.#e.debug(`Processing guest event subscribe request for event ${s}. requestId = ${t}`);const c=this.#l(e);if(!c){this.#e.warn("Rejected event subscribe request from unknown guest window");return}setTimeout(()=>{try{this.#b?.({guestId:c.id,eventId:s,criteria:n,token:r})}catch(a){this.#e.warn(`Error in onGuestEventSubscribe callback for event ${s}: ${a.message}`)}},0)};#C=({sourceWin:e,requestId:t,body:i})=>{const{eventId:s,token:n}=i;this.#e.debug(`Processing guest event unsubscribe request for event ${s}. requestId = ${t}`);const r=this.#l(e);if(!r){this.#e.warn("Rejected event unsubscribe request from unknown guest window");return}setTimeout(()=>{try{this.#h?.({guestId:r.id,eventId:s,token:n})}catch(c){this.#e.warn(`Error in onGuestEventUnsubscribe callback for event ${s}: ${c.message}`)}},0)};#F=({sourceWin:e,requestId:t,body:i})=>{const s=this.#l(e);if(!s){this.#e.warn(`Received resize event from unknown guest. requestid = ${t}`);return}s.domElement&&(s.domElement.style.height=`${i.height}px`),this.#e.debug(`Guest ${s.id} resized to ${i.width}x${i.height}`)};#U=({sourceWin:e,sourceOrigin:t,requestId:i,body:s})=>{const{objectId:n}=s,r=this.#l(e);if(!r)return this.#e.warn("Rejected method invocation request from unknown guest window"),!1;this.#e.debug(`Function ${n}.${String(s.functionName)}() called from guest "${r.id}" (requestId = ${i})`);const c=this.getScriptingObject(n,{guest:r});if(!c)return this.#e.warn(`Invocation of unknown or unauthorized object ${n} from guest ${r.id}`),this.#t.raiseException({targetWin:e,targetOrigin:t,requestId:i,ex:`The requested object (${n}) is not available`}),!1;const a=r.getInfo();return this.#g(`ScriptingObject.API.${n}.${s.functionName}`,{appId:a.guestId,appUrl:a.guestUrl}),this.#I({guest:r,obj:c,functionName:s.functionName,functionParams:s.functionParams}).then(l=>{this.#t.respond({targetWin:e,targetOrigin:t,requestId:i,response:this.#v(l,r)}),this.#e.debug({message:"Value returned for Scripting Object method call",requestId:i,scriptingObject:n,scriptingMethod:s.functionName,...a})}).catch(l=>{this.#t.raiseException({targetWin:e,targetOrigin:r.origin,requestId:i,ex:l}),this.#e.error({message:"Exception thrown for Scripting Object method call",requestId:i,scriptingObject:n,scriptingMethod:s.functionName,...a})}).finally(()=>{this.#p(`ScriptingObject.API.${n}.${s.functionName}`,{appId:a.guestId,appUrl:a.guestUrl})}),!0};#L=()=>{this.#t.listen({messageType:d.GuestResize,callback:this.#F})};#M=()=>{this.#t.listen({messageType:d.GuestReady,callback:this.#G}),this.#t.listen({messageType:d.GuestReadyComplete,callback:this.#E}),this.#t.listen({messageType:d.GuestClose,callback:this.#P}),this.#t.listen({messageType:d.ListObjects,callback:this.#T}),this.#t.listen({messageType:d.ObjectGet,callback:this.#A}),this.#t.listen({messageType:d.ObjectInvoke,callback:this.#U}),this.#t.listen({messageType:d.GuestEventSubscribe,callback:this.#R}),this.#t.listen({messageType:d.GuestEventUnsubscribe,callback:this.#C})};#q=e=>e instanceof A||typeof e?.subscribe=="function";#S=e=>{const t=new F({...e,remoting:this.#t,analyticsObj:this.#r});return t.init(),this.#s.set(e.guestId,t),this.#n.set(t.window,t),this.#c.set(t.url,t),t};#w=e=>{if(typeof e=="string")return this.#s.get(e);const t=this.#n.get(e);return t||Array.from(this.#s.values()).find(i=>i.domElement===e)};#_=()=>{this.#a||(this.#a=setInterval(()=>{const e=[];this.#s.forEach(t=>{t.openMode===f.Popup&&t.window.closed&&e.push(t)}),e.forEach(t=>{const{id:i}=t;this.unloadGuest(i),this.#d.get(i)?.forEach(n=>{Promise.resolve(n({id:i})).catch(()=>{})})})},1e3))};#$=()=>{if(!this.#a)return;Array.from(this.#s.values()).some(t=>t.openMode===f.Popup)||(clearInterval(this.#a),this.#a=null)};#x=e=>{const{url:t,title:i,popupWindowFeatures:s={},searchParams:n,guestId:r,onLoad:c,onError:a}=e,{width:l=800,height:u=600,top:y=100,left:E=100}=s;let g=this.#O(t);if(g)g.window.closed||g.send({messageType:d.GuestFocus,messageBody:{}});else{const w=Object.entries({width:l,height:u,top:y,left:E}).filter(([,b])=>b).map(([b,p])=>`${b}=${p}`).join(","),m=window.open(t,i,`popup, ${w}`);if(m)setTimeout(()=>{try{c?.(r)}catch(b){this.#e.debug(`Error occurred in onLoad for guest with id '${r}': ${b.message}`)}},0);else throw setTimeout(()=>{try{a?.(r)}catch(b){this.#e.debug(`Error occurred in onError for guest with id '${r}': ${b.message}`)}},0),new Error("Failed to open guest application in popup window");m.opener=null,g=this.#S({guestId:r,window:m,title:i,url:t,searchParams:n,openMode:f.Popup}),this.#_()}return g};#D=e=>{const{url:t,title:i,targetElement:s,searchParams:n,guestId:r,onLoad:c,onError:a,options:l={}}=e,u=s.ownerDocument??document,{fitToContent:y=!1,disableSandbox:E=!1,sandboxValues:g=[],customSandboxValues:w=[],style:m="",permissionPolicy:b=""}=l;if(!i)throw new Error("title is required");y&&this.#L();const p=u.createElement("iframe");p.setAttribute("id",r);const P=()=>{setTimeout(()=>{try{c?.(r)}catch(T){this.#e.debug(`Error occurred in onLoad for guest with id '${r}': ${T.message}`)}},0),this.#e.debug(`frame loaded for guest with id '${r}'`),p.removeEventListener("load",P)},v=()=>{setTimeout(()=>{try{a?.(r)}catch(T){this.#e.debug(`Error occurred in onError for guest with id '${r}': ${T.message}`)}},0),this.#e.error(`frame load failed for guest with id '${r}'`),p.removeEventListener("error",v)};p.addEventListener("load",P),p.addEventListener("error",v),p.setAttribute("style",`min-width: 100%; height: 100%; border: 0px; ${m}`),E||p.setAttribute("sandbox",w.length>0?w.join(" "):[...W,...g].join(" ")),p.setAttribute("title",i),p.setAttribute("src",t),b&&p.setAttribute("allow",b),s.appendChild(p);const I=u.getElementById(r);return this.#S({guestId:r,domElement:I,window:I.contentWindow,title:i,url:t,searchParams:n,openMode:f.Embed})};#N=(e,t)=>{let i="";return Object.keys(t).forEach(s=>{i+=`${(i.length?"&":"")+encodeURIComponent(s)}=${encodeURIComponent(t[s])}`}),e+(i?(e.indexOf("?")>=0?"&":"?")+i:"")};addScriptingObject=(e,t)=>{if(N(e)){const i=this.cloneScriptingObject(e);this.#o.addScriptingObject(i,t)}else this.#o.addScriptingObject(e,t)};cloneScriptingObject=e=>{if(!e)throw new Error("proxy is required");const t=new R(e.id,e.objectType);let i=[];return Object.keys(e).forEach(s=>{const n=e[s];if(this.#q(n)){const r=new $({name:n.name||s,objectId:t.id});if(Object.defineProperty(t,s,{value:r,enumerable:!0}),n instanceof A){const c=({eventParams:l,eventOptions:u})=>this.dispatchEvent({event:r,eventParams:l,eventOptions:u}),a=n.subscribe(c);i.push(()=>{n.unsubscribe(a)})}else{const c=n.subscribe?.((a,l,u)=>this.dispatchEvent({event:r,eventParams:l,eventOptions:u}));i.push(()=>{n.unsubscribe?.(c)})}}else if(C(n)&&(Object.defineProperty(t,s,{value:async(...r)=>{const c=await n(...r);return N(c)?this.cloneScriptingObject(c):c},enumerable:!0}),s==="dispose")){const r=t.dispose;Object.defineProperty(t,s,{value:()=>(t._dispose(),r.apply(t)),enumerable:!0})}}),t._dispose=()=>{i.forEach(s=>{s?.()}),i=[]},t};close=()=>{this.#a&&(clearInterval(this.#a),this.#a=null),this.#u(),this.#t.close(),window.removeEventListener("beforeunload",this.#u),this.#e.debug(`host is closed. hostId: ${this.hostId}, correlationId: ${this.#i}`)};dispatchEvent=async e=>{const{event:{id:t,name:i},eventParams:s,eventOptions:n={}}=e,{eventHandler:r=null,timeout:c=null,window:a=null,guestId:l}=n,u=t.split(".")[0],y=l||a,E=y?this.#w(y):null,g=E?this.getScriptingObject(u,{guest:E}):this.getScriptingObject(u);if(!g)return this.#e.warn(`Attempt to dispatch event ${i} on unknown object ${u}`),Promise.resolve([]);const w={object:g._toJSON(),eventName:i,eventParams:s,eventHandler:r,eventOptions:{allowsFeedback:!1}};c&&!Number.isNaN(c)&&(w.eventOptions={allowsFeedback:!0,timeout:Number(c)});const m=[];let b=!1;const p=v=>{const I=v.getInfo();c&&v?.capabilities?.eventFeedback?(m.push(v.dispatchEvent(w,c)),b||(this.#g(`ScriptingObject.Event.${g.id}.${i}`,{appId:this.hostId,appUrl:window.location.href}),b=!0),this.#e.debug({message:"Event dispatched and awaiting feedback",scriptingEventId:t,...I})):(v.send({messageType:d.ObjectEvent,messageBody:w}),this.#e.debug({message:"Event dispatched",scriptingEventId:t,...I}))};return E?p(E):this.#s.forEach(p),await Promise.all(m).then(v=>(this.#e.debug({message:"Event feedback received",scriptingEventId:t}),Y(v))).catch(v=>{throw this.#e.error({message:"Error processing event",eventId:t,exception:v}),v}).finally(()=>{b&&this.#p(`ScriptingObject.Event.${g.id}.${i}`,{appId:this.hostId,appUrl:window.location.href})})};getGuests=()=>Array.from(this.#s.values());getScriptingObject=(e,t)=>this.#o.getObject(e,t?.guest);loadGuest=e=>{const{id:t,url:i,targetElement:s,title:n,searchParams:r={},onLoad:c,onError:a,options:l={}}=e;if(!t)throw new Error("id for guest application is required");let u=t;if(this.#s.has(u)){let m=1;for(;this.#s.has(`${t}-${m}`);)m+=1;u=`${t}-${m}`}const{openMode:y=f.Embed,popupWindowFeatures:E={}}=l,g=this.#N(i,r);let w=null;if(this.#g("SSF.Guest.Load",{appId:u,appUrl:g}),y===f.Popup)w=this.#x({guestId:u,url:g,title:n,searchParams:r,popupWindowFeatures:E,onLoad:c,onError:a});else if(y===f.Embed)w=this.#D({guestId:u,url:g,title:n,targetElement:s,searchParams:r,onLoad:c,onError:a,options:l});else throw new Error(`Invalid openMode: ${y}`);return this.#e.audit({message:"Guest loaded",...w.getInfo()}),w};loadGuests=e=>{const{id:t,url:i,targetElement:s,title:n,searchParamsList:r=[],options:c={}}=e;r.forEach((a,l)=>{this.loadGuest({id:`${t}-${l}`,url:i,title:n,targetElement:s,searchParams:a,options:c})},this)};removeAllScriptingObjects=e=>{this.#o.removeAllScriptingObjects(e)};removeScriptingObject=(e,t)=>{this.#o.removeScriptingObject(e,t)};setLogLevel=e=>{this.#e.setLogLevel(e),this.#s.forEach(this.#y),this.#e.debug("Dispatched config events to all guests")};#W=e=>{const{guestEmui:t,cleanupFunctionName:i,context:s}=e,n=t,r=n[i];if(typeof r=="function")try{r(),this.#e.debug(`[SSF] Called ${s} window.emui.${i}()`)}catch(c){this.#e.warn(`[SSF] ${s} emui.${i}() threw error: ${c.message}`)}finally{n[i]=null}};#z=e=>{e.app&&typeof e.app=="object"&&(e.app.init=null,e.app.mount=null,e.app.unmount=null,e.app.getRef=null,e.app.navigate=null,e.app=null)};#B=e=>{try{const{elli:t}=e;if(!t?.script)return;t.script.guest&&(t.script.guest.create=null,t.script.guest=null),t.script.connect=null,t.script.getObject=null,t.script.setLogLevel=null,t.script.subscribe=null,t.script.unsubscribe=null,t.script=null}catch{}};#H=(e,t)=>{try{e.gtmDataLayer&&(e.gtmDataLayer=null,this.#e.debug(`[SSF] Cleared ${t} gtmDataLayer`))}catch(i){this.#e.debug(`[SSF] Failed to cleanup ${t} gtmDataLayer: ${i.message}`)}};#j=e=>{const{guestWindow:t,guestId:i,cleanupFunctionName:s,windowType:n="iframe"}=e;if(!t){this.#e.debug(`No ${n} window available for cleanup of guest ${i}`);return}try{const r=t.emui;if(r){this.#W({guestEmui:r,cleanupFunctionName:s,context:`${n} for guest ${i}`});try{this.#z(r),r.registerApp=null,r.logRocket=null,r.logRocketConfig=null,this.#e.debug(`[SSF] Nulled all ${n} window.emui properties for guest ${i}`)}catch(c){this.#e.debug(`[SSF] Failed to cleanup ${n} window.emui: ${c.message}`)}}this.#B(t),this.#e.debug(`[SSF] Nulled all ${n} window.elli.script properties for guest ${i}`),this.#H(t,`${n} for guest ${i}`)}catch(r){this.#e.debug(`[SSF] Could not access ${n} window for cleanup (guest ${i}): ${r.message}`)}};#J=(e,t,i)=>{const s=[];let n=window;for(let r=0;r<e.length-1;r+=1){const c=e[r];if(n[c]===void 0||n[c]===null)return this.#e.debug(`Path "${t}" does not exist (stopped at ${c}) for guest ${i}`),null;s.push({obj:n,key:c}),n=n[c]}return{parentChain:s,current:n}};#Y=(e,t)=>{try{const i=e.split(".").filter(a=>a!=="window"&&a.trim()!=="");if(i.length===0){this.#e.debug(`Invalid path "${e}" - skipping for guest ${t}`);return}const s=this.#J(i,e,t);if(!s)return;const{parentChain:n,current:r}=s,c=i[i.length-1];if(r[c]===void 0){this.#e.debug(`Property "${c}" not found in path "${e}" for guest ${t}`);return}r[c]=null,this.#e.debug(`Cleared window reference: ${e} for guest ${t}`),this.#X(n,i,t)}catch(i){this.#e.debug(`Failed to clear window reference "${e}" for guest ${t}: ${i.message}`)}};#X=(e,t,i)=>{for(let s=e.length-1;s>=0;s-=1){const{obj:n,key:r}=e[s],c=n[r];if(!this.#Q(c))break;n[r]=null,this.#e.debug(`Cleaned up empty parent object at ${t.slice(0,s+1).join(".")} for guest ${i}`)}};#K=(e,t)=>{!e||e.length===0||e.forEach(i=>this.#Y(i,t))};#Q=e=>{const t=Object.keys(e);return t.length===0?!0:t.every(i=>e[i]===null||e[i]===void 0)};unloadGuest=(e,t)=>{const i=this.#w(e);if(!i){this.#e.warn("Attempted to unload unknown guest");return}const s=i.id;if(t?.purgeOnDestroy){const n=t.cleanupFunctionName||"unmount";t.windowRefsToClear&&t.windowRefsToClear.length>0&&this.#K(t.windowRefsToClear,s),this.unloadGuestWithFullCleanup(s,n),this.#e.audit({message:`Guest unloaded with purge mode (windowRefs: ${t.windowRefsToClear?.length||0})`,...i.getInfo()});return}i.dispose(),this.#n.delete(i.window),this.#c.delete(i.url),this.#s.delete(i.id),this.#e.audit({message:"Guest is removed from host",...i.getInfo()}),this.#$()};#Z=(e,t)=>{try{const i=e?.document?.body;if(!i)return;const{observerReferences:s}=window;if(!(s instanceof Map)||!s.has(i))return;const n=s.get(i);n&&typeof n.disconnect=="function"&&(n.disconnect(),s.delete(i),this.#e.debug(`[SSF] Disconnected FieldMutation observer for guest ${t}`))}catch(i){this.#e.debug(`[SSF] Failed to disconnect FieldMutation observer for guest ${t}: ${i.message}`)}};#V=(e,t,i)=>{try{t&&!t.closed&&(t.close(),this.#e.debug(`[SSF] Called contentWindow.close() for guest ${i}`))}catch(s){this.#e.debug(`[SSF] contentWindow.close() failed for guest ${i}: ${s.message}`)}try{e.parentNode&&(e.src="about:blank",this.#e.debug(`[SSF] Navigated to about:blank for guest ${i}`))}catch(s){this.#e.debug(`[SSF] Failed to navigate iframe to about:blank for guest ${i}: ${s.message}`)}setTimeout(()=>{try{e.parentNode&&(e.remove(),this.#e.debug(`[SSF] Removed iframe from DOM for guest ${i}`))}catch(s){this.#e.warn(`[SSF] Failed to remove iframe for guest ${i}: ${s.message}`)}},10)};#ee=(e,t)=>{try{e&&!e.closed&&(e.close(),this.#e.debug(`[SSF] Closed popup window for guest ${t}`))}catch(i){this.#e.debug(`[SSF] Failed to close popup window for guest ${t}: ${i.message}`)}};#te=(e,t)=>{try{this.#t.removeSender({origin:e.origin,window:e.window}),this.#e.debug(`[SSF] Removed remoting sender for guest ${t}`)}catch(i){this.#e.debug(`[SSF] Failed to remove remoting sender for guest ${t}: ${i.message}`)}};#ie=(e,t)=>{this.#n.delete(e.window),this.#c.delete(e.url),this.#s.delete(t)};unloadGuestWithFullCleanup=(e,t="unmount")=>{const i=this.#w(e);if(!i){this.#e.warn("Attempted to unload unknown guest");return}const s=i.id;if(i.openMode===f.Embed&&i.domElement){const n=i.domElement,r=i.window;this.#j({guestWindow:r,guestId:s,cleanupFunctionName:t,windowType:"iframe"}),this.#Z(r,s),this.#V(n,r,s)}else if(i.openMode===f.Popup){const n=i.window;this.#j({guestWindow:n,guestId:s,cleanupFunctionName:t,windowType:"popup"}),this.#ee(n,s),i.dispose()}this.#te(i,s),this.#ie(i,s),this.#$(),this.#e.audit({message:"Guest unloaded with full cleanup",...i.getInfo()})};onGuestClose=e=>{const{id:t,guestCloseCallback:i}=e,s=this.#d.get(t)||[];s.push(i),this.#d.set(t,s)}}return O})());
|
|
2
|
+
|
|
3
|
+
//# sourceMappingURL=emuiSsfHost.c95491c428f3f102185b.js.map
|