@monterosa/sdk-launcher-kit 0.18.9 → 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.
package/dist/index.cjs.js CHANGED
@@ -165,6 +165,10 @@ exports.Action = void 0;
165
165
  * Notifies child Experience about the request to load more data
166
166
  */
167
167
  Action["OnMoreDataRequested"] = "onMoreDataRequested";
168
+ /**
169
+ * Notifies about a share request
170
+ */
171
+ Action["OnShare"] = "onShare";
168
172
  })(exports.Action || (exports.Action = {}));
169
173
  /**
170
174
  * @internal
@@ -234,7 +238,7 @@ exports.QueryParam = void 0;
234
238
  *
235
239
  * More details on the license can be found at https://www.monterosa.co/sdk/license
236
240
  */
237
- var _a$2;
241
+ var _a$3;
238
242
  /**
239
243
  * Defines a set of error codes that may be encountered when using the
240
244
  * Launcher Kit bridge
@@ -273,14 +277,14 @@ exports.BridgeError = void 0;
273
277
  */
274
278
  BridgeError["RequestTimeoutError"] = "request_timeout_error";
275
279
  })(exports.BridgeError || (exports.BridgeError = {}));
276
- var BridgeErrorMessages = (_a$2 = {},
277
- _a$2[exports.BridgeError.InvalidRequestTimeoutError] = function () {
280
+ var BridgeErrorMessages = (_a$3 = {},
281
+ _a$3[exports.BridgeError.InvalidRequestTimeoutError] = function () {
278
282
  return 'Request timeout must be greater than 0';
279
283
  },
280
- _a$2[exports.BridgeError.RequestTimeoutError] = function (action, timeout) {
284
+ _a$3[exports.BridgeError.RequestTimeoutError] = function (action, timeout) {
281
285
  return "Request timeout: action \"" + action + "\" did not receive a response within " + timeout + "ms";
282
286
  },
283
- _a$2);
287
+ _a$3);
284
288
 
285
289
  /**
286
290
  * @license
@@ -350,7 +354,7 @@ function isMessage(message) {
350
354
  *
351
355
  * More details on the license can be found at https://www.monterosa.co/sdk/license
352
356
  */
353
- var _a$1, _b$1, _c$1, _d$1;
357
+ var _a$2, _b$1, _c$1, _d$1;
354
358
  var _e, _f, _g;
355
359
  var globals$2 = sdkUtil.getGlobal();
356
360
  var receiveMessage = function (message) {
@@ -382,7 +386,7 @@ function handleWindowMessage(_a) {
382
386
  */
383
387
  // The Monterosa SDK namespace may already exist, either because it was created
384
388
  // by a native SDK or by another web app using the JS SDK from the same scope.
385
- (_a$1 = globals$2.monterosaSdk) !== null && _a$1 !== void 0 ? _a$1 : (globals$2.monterosaSdk = {
389
+ (_a$2 = globals$2.monterosaSdk) !== null && _a$2 !== void 0 ? _a$2 : (globals$2.monterosaSdk = {
386
390
  initialised: false,
387
391
  emitter: new sdkUtil.Emitter(),
388
392
  receiveMessage: receiveMessage,
@@ -411,13 +415,13 @@ if (!globals$2.monterosaSdk.initialised) {
411
415
  *
412
416
  * More details on the license can be found at https://www.monterosa.co/sdk/license
413
417
  */
414
- var _a, _b, _c, _d;
418
+ var _a$1, _b, _c, _d;
415
419
  var globals$1 = sdkUtil.getGlobal();
416
420
  /**
417
421
  * @internal
418
422
  */
419
423
  var IFRAME_ID_PREFIX = 'micBridge';
420
- var IS_IOS = !!((_c = (_b = (_a = globals$1.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.monterosaSdk) === null || _c === void 0 ? void 0 : _c.postMessage);
424
+ var IS_IOS = !!((_c = (_b = (_a$1 = globals$1.webkit) === null || _a$1 === void 0 ? void 0 : _a$1.messageHandlers) === null || _b === void 0 ? void 0 : _b.monterosaSdk) === null || _c === void 0 ? void 0 : _c.postMessage);
421
425
  var IS_ANDROID = !!((_d = globals$1.monterosaSdk) === null || _d === void 0 ? void 0 : _d.postMessage);
422
426
  var IS_WEB = globals$1.self !== globals$1.parent;
423
427
  /**
@@ -1059,7 +1063,7 @@ function unstashStyles(element) {
1059
1063
  element.removeAttribute('data-stash');
1060
1064
  }
1061
1065
 
1062
- var version = "0.18.9";
1066
+ var version = "0.18.10";
1063
1067
 
1064
1068
  /**
1065
1069
  * @license
@@ -1567,13 +1571,168 @@ function reportExperienceSizeChanges(element) {
1567
1571
  return function () { return observer.unobserve(element); };
1568
1572
  }
1569
1573
 
1574
+ /**
1575
+ * @license
1576
+ * share.ts
1577
+ * launcher-kit
1578
+ *
1579
+ * Copyright © 2026 Monterosa Productions Limited. All rights reserved.
1580
+ *
1581
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
1582
+ */
1583
+ var _a;
1584
+ /**
1585
+ * Share requests block on the native share tray which waits for user
1586
+ * interaction (composing a message, picking a target app, etc.). The default
1587
+ * bridge timeout of 20 seconds is too short for this. 5 minutes gives users
1588
+ * ample time while still acting as a safety net against lost messages.
1589
+ */
1590
+ var SHARE_REQUEST_TIMEOUT = 300000;
1591
+ exports.ShareError = void 0;
1592
+ (function (ShareError) {
1593
+ ShareError["ParentAppError"] = "parent_app_error";
1594
+ ShareError["ShareFailed"] = "share_failed";
1595
+ })(exports.ShareError || (exports.ShareError = {}));
1596
+ var ShareErrorMessages = (_a = {},
1597
+ _a[exports.ShareError.ParentAppError] = function (error) {
1598
+ return "Parent application error: " + error;
1599
+ },
1600
+ _a[exports.ShareError.ShareFailed] = function (error) { return "Share failed: " + error; },
1601
+ _a);
1602
+ /**
1603
+ * Executes share using the Web Share API.
1604
+ *
1605
+ * @internal
1606
+ */
1607
+ function executeShare(data) {
1608
+ return __awaiter(this, void 0, void 0, function () {
1609
+ var err_1;
1610
+ return __generator(this, function (_a) {
1611
+ switch (_a.label) {
1612
+ case 0:
1613
+ _a.trys.push([0, 2, , 3]);
1614
+ return [4 /*yield*/, navigator.share({
1615
+ url: data.url,
1616
+ title: data.title,
1617
+ text: data.description,
1618
+ })];
1619
+ case 1:
1620
+ _a.sent();
1621
+ return [2 /*return*/, 'success'];
1622
+ case 2:
1623
+ err_1 = _a.sent();
1624
+ if (err_1 instanceof DOMException && err_1.name === 'AbortError') {
1625
+ return [2 /*return*/, 'cancelled'];
1626
+ }
1627
+ throw sdkUtil.createError(exports.ShareError.ShareFailed, ShareErrorMessages, sdkUtil.getErrorMessage(err_1));
1628
+ case 3: return [2 /*return*/];
1629
+ }
1630
+ });
1631
+ });
1632
+ }
1633
+ /**
1634
+ * Initiates a share action. When running inside a parent application,
1635
+ * the share request is sent to the parent via the communication bridge.
1636
+ * When running standalone, `navigator.share()` is called directly.
1637
+ *
1638
+ * @param data - The data to share
1639
+ */
1640
+ function share(data) {
1641
+ return __awaiter(this, void 0, void 0, function () {
1642
+ var parentApp, response;
1643
+ return __generator(this, function (_a) {
1644
+ switch (_a.label) {
1645
+ case 0:
1646
+ parentApp = getParentApplication();
1647
+ if (!(parentApp !== null)) return [3 /*break*/, 2];
1648
+ return [4 /*yield*/, sendSdkRequest(parentApp, exports.Action.OnShare, data, SHARE_REQUEST_TIMEOUT)];
1649
+ case 1:
1650
+ response = _a.sent();
1651
+ if (response.payload.result === 'failure') {
1652
+ throw sdkUtil.createError(exports.ShareError.ParentAppError, ShareErrorMessages, response.payload.message);
1653
+ }
1654
+ // 'success' and 'cancelled' both resolve silently
1655
+ return [2 /*return*/];
1656
+ case 2: return [4 /*yield*/, executeShare(data)];
1657
+ case 3:
1658
+ _a.sent();
1659
+ return [2 /*return*/];
1660
+ }
1661
+ });
1662
+ });
1663
+ }
1664
+ /**
1665
+ * Registers a callback to be called when a share request is received
1666
+ * from a child Experience.
1667
+ *
1668
+ * @param experience - The Experience instance to listen on
1669
+ * @param callback - Called with ShareData when a share request is received
1670
+ * @returns Unsubscribe function
1671
+ */
1672
+ function onShare(experience, callback) {
1673
+ return onSdkMessage(experience, function (message) {
1674
+ if (message.action === exports.Action.OnShare) {
1675
+ callback(message.payload);
1676
+ }
1677
+ });
1678
+ }
1679
+ function onExperienceEmbed(experience) {
1680
+ var _this = this;
1681
+ return onSdkMessage(experience, function (message) { return __awaiter(_this, void 0, void 0, function () {
1682
+ var parentApp, payload, response, result, err_2;
1683
+ return __generator(this, function (_a) {
1684
+ switch (_a.label) {
1685
+ case 0:
1686
+ if (message.action !== exports.Action.OnShare) {
1687
+ return [2 /*return*/];
1688
+ }
1689
+ _a.label = 1;
1690
+ case 1:
1691
+ _a.trys.push([1, 6, , 7]);
1692
+ parentApp = getParentApplication();
1693
+ payload = void 0;
1694
+ if (!(parentApp !== null)) return [3 /*break*/, 3];
1695
+ return [4 /*yield*/, sendSdkRequest(parentApp, exports.Action.OnShare, message.payload, SHARE_REQUEST_TIMEOUT)];
1696
+ case 2:
1697
+ response = _a.sent();
1698
+ payload = response.payload;
1699
+ return [3 /*break*/, 5];
1700
+ case 3: return [4 /*yield*/, executeShare(message.payload)];
1701
+ case 4:
1702
+ result = _a.sent();
1703
+ payload = {
1704
+ result: result,
1705
+ message: result === 'success' ? 'Share successful' : 'Share cancelled',
1706
+ data: {},
1707
+ };
1708
+ _a.label = 5;
1709
+ case 5:
1710
+ respondToSdkMessage(experience, message, payload);
1711
+ return [3 /*break*/, 7];
1712
+ case 6:
1713
+ err_2 = _a.sent();
1714
+ respondToSdkMessage(experience, message, {
1715
+ result: 'failure',
1716
+ message: sdkUtil.getErrorMessage(err_2),
1717
+ data: {},
1718
+ });
1719
+ return [3 /*break*/, 7];
1720
+ case 7: return [2 /*return*/];
1721
+ }
1722
+ });
1723
+ }); });
1724
+ }
1725
+ registerEmbedHook(onExperienceEmbed);
1726
+
1570
1727
  exports.BRIDGE_VERSION = VERSION$1;
1571
1728
  exports.BridgeImpl = BridgeImpl;
1572
1729
  exports.ExperienceImpl = ExperienceImpl;
1573
1730
  exports.ParentApplicationImpl = ParentApplicationImpl;
1731
+ exports.ShareErrorMessages = ShareErrorMessages;
1574
1732
  exports.VERSION = VERSION;
1575
1733
  exports.embed = embed;
1576
1734
  exports.enableLogging = enableLogging;
1735
+ exports.executeShare = executeShare;
1577
1736
  exports.getBridge = getBridge;
1578
1737
  exports.getExperience = getExperience;
1579
1738
  exports.getParentApplication = getParentApplication;
@@ -1583,6 +1742,7 @@ exports.onMessage = onMessage;
1583
1742
  exports.onMoreDataRequested = onMoreDataRequested;
1584
1743
  exports.onReady = onReady;
1585
1744
  exports.onSdkMessage = onSdkMessage;
1745
+ exports.onShare = onShare;
1586
1746
  exports.registerEmbedHook = registerEmbedHook;
1587
1747
  exports.reportExperienceSizeChanges = reportExperienceSizeChanges;
1588
1748
  exports.requestMoreData = requestMoreData;
@@ -1597,6 +1757,7 @@ exports.sendRequest = sendRequest;
1597
1757
  exports.sendSdkMessage = sendSdkMessage;
1598
1758
  exports.sendSdkRequest = sendSdkRequest;
1599
1759
  exports.setRequestTimeout = setRequestTimeout;
1760
+ exports.share = share;
1600
1761
  exports.shouldHideHeaderAndFooter = shouldHideHeaderAndFooter;
1601
1762
  exports.unmount = unmount;
1602
1763
  //# sourceMappingURL=index.cjs.js.map