@monterosa/sdk-launcher-kit 0.18.8 → 0.18.10

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.
@@ -1,4 +1,4 @@
1
- import { Logger, Sdk, getSdk, LogLevel } from '@monterosa/sdk-core';
1
+ import { Logger, getSdk, LogLevel, Sdk } from '@monterosa/sdk-core';
2
2
  import { createError, getGlobal, Emitter, getErrorMessage, subscribe, delay, throttle } from '@monterosa/sdk-util';
3
3
  import { v4 } from 'uuid';
4
4
  import { fetchListings } from '@monterosa/sdk-interact-interop';
@@ -81,6 +81,10 @@ var Action;
81
81
  * Notifies child Experience about the request to load more data
82
82
  */
83
83
  Action["OnMoreDataRequested"] = "onMoreDataRequested";
84
+ /**
85
+ * Notifies about a share request
86
+ */
87
+ Action["OnShare"] = "onShare";
84
88
  })(Action || (Action = {}));
85
89
  /**
86
90
  * @internal
@@ -477,24 +481,6 @@ function getBridge(id) {
477
481
  bridges.set(id, bridge);
478
482
  return bridge;
479
483
  }
480
- /**
481
- * Returns true if the page is inside an iframe.
482
- *
483
- * @internal
484
- */
485
- function isInsideIframe() {
486
- if (typeof window === 'undefined') {
487
- return false;
488
- }
489
- try {
490
- return window.self !== window.top;
491
- }
492
- catch (_a) {
493
- // SecurityError is thrown when accessing window.top in a cross-origin iframe.
494
- // If we can't access it, we're definitely in an iframe.
495
- return true;
496
- }
497
- }
498
484
  /**
499
485
  * @internal
500
486
  */
@@ -505,9 +491,6 @@ function getParentBridge() {
505
491
  if (parentBridge !== undefined) {
506
492
  return parentBridge;
507
493
  }
508
- if (!isInsideIframe()) {
509
- return null;
510
- }
511
494
  const url = new URL(window.location.href);
512
495
  const bridgeId = url.searchParams.get(QueryParam.BridgeId);
513
496
  if (bridgeId === null) {
@@ -978,7 +961,7 @@ function unstashStyles(element) {
978
961
  element.removeAttribute('data-stash');
979
962
  }
980
963
 
981
- var version = "0.18.8";
964
+ var version = "0.18.10";
982
965
 
983
966
  /**
984
967
  * @license
@@ -1468,5 +1451,118 @@ function reportExperienceSizeChanges(element) {
1468
1451
  return () => observer.unobserve(element);
1469
1452
  }
1470
1453
 
1471
- export { Action, VERSION$1 as BRIDGE_VERSION, BridgeError, BridgeImpl, ExperienceImpl, ParentApplicationImpl, QueryParam, Source, VERSION, embed, enableLogging, getBridge, getExperience, getParentApplication, getParentBridge, isAutoresizesHeight, isInsideIframe, onMessage, onMoreDataRequested, onReady, onSdkMessage, registerEmbedHook, reportExperienceSizeChanges, requestMoreData, respondToMessage, respondToSdkMessage, sendExperienceSize, sendExperienceSizeThrottled, sendFinishedLoadingUI, sendMessage, sendReady, sendRequest, sendSdkMessage, sendSdkRequest, setRequestTimeout, shouldHideHeaderAndFooter, unmount };
1454
+ /**
1455
+ * @license
1456
+ * share.ts
1457
+ * launcher-kit
1458
+ *
1459
+ * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
1460
+ *
1461
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
1462
+ */
1463
+ /**
1464
+ * Share requests block on the native share tray which waits for user
1465
+ * interaction (composing a message, picking a target app, etc.). The default
1466
+ * bridge timeout of 20 seconds is too short for this. 5 minutes gives users
1467
+ * ample time while still acting as a safety net against lost messages.
1468
+ */
1469
+ const SHARE_REQUEST_TIMEOUT = 300000;
1470
+ var ShareError;
1471
+ (function (ShareError) {
1472
+ ShareError["ParentAppError"] = "parent_app_error";
1473
+ ShareError["ShareFailed"] = "share_failed";
1474
+ })(ShareError || (ShareError = {}));
1475
+ const ShareErrorMessages = {
1476
+ [ShareError.ParentAppError]: (error) => `Parent application error: ${error}`,
1477
+ [ShareError.ShareFailed]: (error) => `Share failed: ${error}`,
1478
+ };
1479
+ /**
1480
+ * Executes share using the Web Share API.
1481
+ *
1482
+ * @internal
1483
+ */
1484
+ async function executeShare(data) {
1485
+ try {
1486
+ await navigator.share({
1487
+ url: data.url,
1488
+ title: data.title,
1489
+ text: data.description,
1490
+ });
1491
+ return 'success';
1492
+ }
1493
+ catch (err) {
1494
+ if (err instanceof DOMException && err.name === 'AbortError') {
1495
+ return 'cancelled';
1496
+ }
1497
+ throw createError(ShareError.ShareFailed, ShareErrorMessages, getErrorMessage(err));
1498
+ }
1499
+ }
1500
+ /**
1501
+ * Initiates a share action. When running inside a parent application,
1502
+ * the share request is sent to the parent via the communication bridge.
1503
+ * When running standalone, `navigator.share()` is called directly.
1504
+ *
1505
+ * @param data - The data to share
1506
+ */
1507
+ async function share(data) {
1508
+ const parentApp = getParentApplication();
1509
+ if (parentApp !== null) {
1510
+ const response = await sendSdkRequest(parentApp, Action.OnShare, data, SHARE_REQUEST_TIMEOUT);
1511
+ if (response.payload.result === 'failure') {
1512
+ throw createError(ShareError.ParentAppError, ShareErrorMessages, response.payload.message);
1513
+ }
1514
+ // 'success' and 'cancelled' both resolve silently
1515
+ return;
1516
+ }
1517
+ await executeShare(data);
1518
+ }
1519
+ /**
1520
+ * Registers a callback to be called when a share request is received
1521
+ * from a child Experience.
1522
+ *
1523
+ * @param experience - The Experience instance to listen on
1524
+ * @param callback - Called with ShareData when a share request is received
1525
+ * @returns Unsubscribe function
1526
+ */
1527
+ function onShare(experience, callback) {
1528
+ return onSdkMessage(experience, (message) => {
1529
+ if (message.action === Action.OnShare) {
1530
+ callback(message.payload);
1531
+ }
1532
+ });
1533
+ }
1534
+ function onExperienceEmbed(experience) {
1535
+ return onSdkMessage(experience, async (message) => {
1536
+ if (message.action !== Action.OnShare) {
1537
+ return;
1538
+ }
1539
+ try {
1540
+ const parentApp = getParentApplication();
1541
+ let payload;
1542
+ if (parentApp !== null) {
1543
+ const response = await sendSdkRequest(parentApp, Action.OnShare, message.payload, SHARE_REQUEST_TIMEOUT);
1544
+ payload = response.payload;
1545
+ }
1546
+ else {
1547
+ const result = await executeShare(message.payload);
1548
+ payload = {
1549
+ result,
1550
+ message: result === 'success' ? 'Share successful' : 'Share cancelled',
1551
+ data: {},
1552
+ };
1553
+ }
1554
+ respondToSdkMessage(experience, message, payload);
1555
+ }
1556
+ catch (err) {
1557
+ respondToSdkMessage(experience, message, {
1558
+ result: 'failure',
1559
+ message: getErrorMessage(err),
1560
+ data: {},
1561
+ });
1562
+ }
1563
+ });
1564
+ }
1565
+ registerEmbedHook(onExperienceEmbed);
1566
+
1567
+ export { Action, VERSION$1 as BRIDGE_VERSION, BridgeError, BridgeImpl, ExperienceImpl, ParentApplicationImpl, QueryParam, ShareError, ShareErrorMessages, Source, VERSION, embed, enableLogging, executeShare, getBridge, getExperience, getParentApplication, getParentBridge, isAutoresizesHeight, onMessage, onMoreDataRequested, onReady, onSdkMessage, onShare, registerEmbedHook, reportExperienceSizeChanges, requestMoreData, respondToMessage, respondToSdkMessage, sendExperienceSize, sendExperienceSizeThrottled, sendFinishedLoadingUI, sendMessage, sendReady, sendRequest, sendSdkMessage, sendSdkRequest, setRequestTimeout, share, shouldHideHeaderAndFooter, unmount };
1472
1568
  //# sourceMappingURL=index.esm2017.js.map