@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.
- package/dist/index.cjs.js +171 -32
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm2017.js +120 -24
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm5.js +169 -33
- package/dist/index.esm5.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/share.d.ts +49 -0
- package/dist/src/utils/bridge/api.d.ts +0 -6
- package/dist/src/utils/bridge/public_types.d.ts +5 -1
- package/package.json +5 -5
package/dist/index.esm5.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger,
|
|
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';
|
|
@@ -161,6 +161,10 @@ var Action;
|
|
|
161
161
|
* Notifies child Experience about the request to load more data
|
|
162
162
|
*/
|
|
163
163
|
Action["OnMoreDataRequested"] = "onMoreDataRequested";
|
|
164
|
+
/**
|
|
165
|
+
* Notifies about a share request
|
|
166
|
+
*/
|
|
167
|
+
Action["OnShare"] = "onShare";
|
|
164
168
|
})(Action || (Action = {}));
|
|
165
169
|
/**
|
|
166
170
|
* @internal
|
|
@@ -230,7 +234,7 @@ var QueryParam;
|
|
|
230
234
|
*
|
|
231
235
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
232
236
|
*/
|
|
233
|
-
var _a$
|
|
237
|
+
var _a$3;
|
|
234
238
|
/**
|
|
235
239
|
* Defines a set of error codes that may be encountered when using the
|
|
236
240
|
* Launcher Kit bridge
|
|
@@ -269,14 +273,14 @@ var BridgeError;
|
|
|
269
273
|
*/
|
|
270
274
|
BridgeError["RequestTimeoutError"] = "request_timeout_error";
|
|
271
275
|
})(BridgeError || (BridgeError = {}));
|
|
272
|
-
var BridgeErrorMessages = (_a$
|
|
273
|
-
_a$
|
|
276
|
+
var BridgeErrorMessages = (_a$3 = {},
|
|
277
|
+
_a$3[BridgeError.InvalidRequestTimeoutError] = function () {
|
|
274
278
|
return 'Request timeout must be greater than 0';
|
|
275
279
|
},
|
|
276
|
-
_a$
|
|
280
|
+
_a$3[BridgeError.RequestTimeoutError] = function (action, timeout) {
|
|
277
281
|
return "Request timeout: action \"" + action + "\" did not receive a response within " + timeout + "ms";
|
|
278
282
|
},
|
|
279
|
-
_a$
|
|
283
|
+
_a$3);
|
|
280
284
|
|
|
281
285
|
/**
|
|
282
286
|
* @license
|
|
@@ -346,7 +350,7 @@ function isMessage(message) {
|
|
|
346
350
|
*
|
|
347
351
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
348
352
|
*/
|
|
349
|
-
var _a$
|
|
353
|
+
var _a$2, _b$1, _c$1, _d$1;
|
|
350
354
|
var _e, _f, _g;
|
|
351
355
|
var globals$2 = getGlobal();
|
|
352
356
|
var receiveMessage = function (message) {
|
|
@@ -378,7 +382,7 @@ function handleWindowMessage(_a) {
|
|
|
378
382
|
*/
|
|
379
383
|
// The Monterosa SDK namespace may already exist, either because it was created
|
|
380
384
|
// by a native SDK or by another web app using the JS SDK from the same scope.
|
|
381
|
-
(_a$
|
|
385
|
+
(_a$2 = globals$2.monterosaSdk) !== null && _a$2 !== void 0 ? _a$2 : (globals$2.monterosaSdk = {
|
|
382
386
|
initialised: false,
|
|
383
387
|
emitter: new Emitter(),
|
|
384
388
|
receiveMessage: receiveMessage,
|
|
@@ -407,13 +411,13 @@ if (!globals$2.monterosaSdk.initialised) {
|
|
|
407
411
|
*
|
|
408
412
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
409
413
|
*/
|
|
410
|
-
var _a, _b, _c, _d;
|
|
414
|
+
var _a$1, _b, _c, _d;
|
|
411
415
|
var globals$1 = getGlobal();
|
|
412
416
|
/**
|
|
413
417
|
* @internal
|
|
414
418
|
*/
|
|
415
419
|
var IFRAME_ID_PREFIX = 'micBridge';
|
|
416
|
-
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);
|
|
420
|
+
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);
|
|
417
421
|
var IS_ANDROID = !!((_d = globals$1.monterosaSdk) === null || _d === void 0 ? void 0 : _d.postMessage);
|
|
418
422
|
var IS_WEB = globals$1.self !== globals$1.parent;
|
|
419
423
|
/**
|
|
@@ -582,24 +586,6 @@ function getBridge(id) {
|
|
|
582
586
|
bridges.set(id, bridge);
|
|
583
587
|
return bridge;
|
|
584
588
|
}
|
|
585
|
-
/**
|
|
586
|
-
* Returns true if the page is inside an iframe.
|
|
587
|
-
*
|
|
588
|
-
* @internal
|
|
589
|
-
*/
|
|
590
|
-
function isInsideIframe() {
|
|
591
|
-
if (typeof window === 'undefined') {
|
|
592
|
-
return false;
|
|
593
|
-
}
|
|
594
|
-
try {
|
|
595
|
-
return window.self !== window.top;
|
|
596
|
-
}
|
|
597
|
-
catch (_a) {
|
|
598
|
-
// SecurityError is thrown when accessing window.top in a cross-origin iframe.
|
|
599
|
-
// If we can't access it, we're definitely in an iframe.
|
|
600
|
-
return true;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
589
|
/**
|
|
604
590
|
* @internal
|
|
605
591
|
*/
|
|
@@ -610,9 +596,6 @@ function getParentBridge() {
|
|
|
610
596
|
if (parentBridge !== undefined) {
|
|
611
597
|
return parentBridge;
|
|
612
598
|
}
|
|
613
|
-
if (!isInsideIframe()) {
|
|
614
|
-
return null;
|
|
615
|
-
}
|
|
616
599
|
var url = new URL(window.location.href);
|
|
617
600
|
var bridgeId = url.searchParams.get(QueryParam.BridgeId);
|
|
618
601
|
if (bridgeId === null) {
|
|
@@ -1076,7 +1059,7 @@ function unstashStyles(element) {
|
|
|
1076
1059
|
element.removeAttribute('data-stash');
|
|
1077
1060
|
}
|
|
1078
1061
|
|
|
1079
|
-
var version = "0.18.
|
|
1062
|
+
var version = "0.18.10";
|
|
1080
1063
|
|
|
1081
1064
|
/**
|
|
1082
1065
|
* @license
|
|
@@ -1584,5 +1567,158 @@ function reportExperienceSizeChanges(element) {
|
|
|
1584
1567
|
return function () { return observer.unobserve(element); };
|
|
1585
1568
|
}
|
|
1586
1569
|
|
|
1587
|
-
|
|
1570
|
+
/**
|
|
1571
|
+
* @license
|
|
1572
|
+
* share.ts
|
|
1573
|
+
* launcher-kit
|
|
1574
|
+
*
|
|
1575
|
+
* Copyright © 2026 Monterosa Productions Limited. All rights reserved.
|
|
1576
|
+
*
|
|
1577
|
+
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1578
|
+
*/
|
|
1579
|
+
var _a;
|
|
1580
|
+
/**
|
|
1581
|
+
* Share requests block on the native share tray which waits for user
|
|
1582
|
+
* interaction (composing a message, picking a target app, etc.). The default
|
|
1583
|
+
* bridge timeout of 20 seconds is too short for this. 5 minutes gives users
|
|
1584
|
+
* ample time while still acting as a safety net against lost messages.
|
|
1585
|
+
*/
|
|
1586
|
+
var SHARE_REQUEST_TIMEOUT = 300000;
|
|
1587
|
+
var ShareError;
|
|
1588
|
+
(function (ShareError) {
|
|
1589
|
+
ShareError["ParentAppError"] = "parent_app_error";
|
|
1590
|
+
ShareError["ShareFailed"] = "share_failed";
|
|
1591
|
+
})(ShareError || (ShareError = {}));
|
|
1592
|
+
var ShareErrorMessages = (_a = {},
|
|
1593
|
+
_a[ShareError.ParentAppError] = function (error) {
|
|
1594
|
+
return "Parent application error: " + error;
|
|
1595
|
+
},
|
|
1596
|
+
_a[ShareError.ShareFailed] = function (error) { return "Share failed: " + error; },
|
|
1597
|
+
_a);
|
|
1598
|
+
/**
|
|
1599
|
+
* Executes share using the Web Share API.
|
|
1600
|
+
*
|
|
1601
|
+
* @internal
|
|
1602
|
+
*/
|
|
1603
|
+
function executeShare(data) {
|
|
1604
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1605
|
+
var err_1;
|
|
1606
|
+
return __generator(this, function (_a) {
|
|
1607
|
+
switch (_a.label) {
|
|
1608
|
+
case 0:
|
|
1609
|
+
_a.trys.push([0, 2, , 3]);
|
|
1610
|
+
return [4 /*yield*/, navigator.share({
|
|
1611
|
+
url: data.url,
|
|
1612
|
+
title: data.title,
|
|
1613
|
+
text: data.description,
|
|
1614
|
+
})];
|
|
1615
|
+
case 1:
|
|
1616
|
+
_a.sent();
|
|
1617
|
+
return [2 /*return*/, 'success'];
|
|
1618
|
+
case 2:
|
|
1619
|
+
err_1 = _a.sent();
|
|
1620
|
+
if (err_1 instanceof DOMException && err_1.name === 'AbortError') {
|
|
1621
|
+
return [2 /*return*/, 'cancelled'];
|
|
1622
|
+
}
|
|
1623
|
+
throw createError(ShareError.ShareFailed, ShareErrorMessages, getErrorMessage(err_1));
|
|
1624
|
+
case 3: return [2 /*return*/];
|
|
1625
|
+
}
|
|
1626
|
+
});
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Initiates a share action. When running inside a parent application,
|
|
1631
|
+
* the share request is sent to the parent via the communication bridge.
|
|
1632
|
+
* When running standalone, `navigator.share()` is called directly.
|
|
1633
|
+
*
|
|
1634
|
+
* @param data - The data to share
|
|
1635
|
+
*/
|
|
1636
|
+
function share(data) {
|
|
1637
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1638
|
+
var parentApp, response;
|
|
1639
|
+
return __generator(this, function (_a) {
|
|
1640
|
+
switch (_a.label) {
|
|
1641
|
+
case 0:
|
|
1642
|
+
parentApp = getParentApplication();
|
|
1643
|
+
if (!(parentApp !== null)) return [3 /*break*/, 2];
|
|
1644
|
+
return [4 /*yield*/, sendSdkRequest(parentApp, Action.OnShare, data, SHARE_REQUEST_TIMEOUT)];
|
|
1645
|
+
case 1:
|
|
1646
|
+
response = _a.sent();
|
|
1647
|
+
if (response.payload.result === 'failure') {
|
|
1648
|
+
throw createError(ShareError.ParentAppError, ShareErrorMessages, response.payload.message);
|
|
1649
|
+
}
|
|
1650
|
+
// 'success' and 'cancelled' both resolve silently
|
|
1651
|
+
return [2 /*return*/];
|
|
1652
|
+
case 2: return [4 /*yield*/, executeShare(data)];
|
|
1653
|
+
case 3:
|
|
1654
|
+
_a.sent();
|
|
1655
|
+
return [2 /*return*/];
|
|
1656
|
+
}
|
|
1657
|
+
});
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Registers a callback to be called when a share request is received
|
|
1662
|
+
* from a child Experience.
|
|
1663
|
+
*
|
|
1664
|
+
* @param experience - The Experience instance to listen on
|
|
1665
|
+
* @param callback - Called with ShareData when a share request is received
|
|
1666
|
+
* @returns Unsubscribe function
|
|
1667
|
+
*/
|
|
1668
|
+
function onShare(experience, callback) {
|
|
1669
|
+
return onSdkMessage(experience, function (message) {
|
|
1670
|
+
if (message.action === Action.OnShare) {
|
|
1671
|
+
callback(message.payload);
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
function onExperienceEmbed(experience) {
|
|
1676
|
+
var _this = this;
|
|
1677
|
+
return onSdkMessage(experience, function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
1678
|
+
var parentApp, payload, response, result, err_2;
|
|
1679
|
+
return __generator(this, function (_a) {
|
|
1680
|
+
switch (_a.label) {
|
|
1681
|
+
case 0:
|
|
1682
|
+
if (message.action !== Action.OnShare) {
|
|
1683
|
+
return [2 /*return*/];
|
|
1684
|
+
}
|
|
1685
|
+
_a.label = 1;
|
|
1686
|
+
case 1:
|
|
1687
|
+
_a.trys.push([1, 6, , 7]);
|
|
1688
|
+
parentApp = getParentApplication();
|
|
1689
|
+
payload = void 0;
|
|
1690
|
+
if (!(parentApp !== null)) return [3 /*break*/, 3];
|
|
1691
|
+
return [4 /*yield*/, sendSdkRequest(parentApp, Action.OnShare, message.payload, SHARE_REQUEST_TIMEOUT)];
|
|
1692
|
+
case 2:
|
|
1693
|
+
response = _a.sent();
|
|
1694
|
+
payload = response.payload;
|
|
1695
|
+
return [3 /*break*/, 5];
|
|
1696
|
+
case 3: return [4 /*yield*/, executeShare(message.payload)];
|
|
1697
|
+
case 4:
|
|
1698
|
+
result = _a.sent();
|
|
1699
|
+
payload = {
|
|
1700
|
+
result: result,
|
|
1701
|
+
message: result === 'success' ? 'Share successful' : 'Share cancelled',
|
|
1702
|
+
data: {},
|
|
1703
|
+
};
|
|
1704
|
+
_a.label = 5;
|
|
1705
|
+
case 5:
|
|
1706
|
+
respondToSdkMessage(experience, message, payload);
|
|
1707
|
+
return [3 /*break*/, 7];
|
|
1708
|
+
case 6:
|
|
1709
|
+
err_2 = _a.sent();
|
|
1710
|
+
respondToSdkMessage(experience, message, {
|
|
1711
|
+
result: 'failure',
|
|
1712
|
+
message: getErrorMessage(err_2),
|
|
1713
|
+
data: {},
|
|
1714
|
+
});
|
|
1715
|
+
return [3 /*break*/, 7];
|
|
1716
|
+
case 7: return [2 /*return*/];
|
|
1717
|
+
}
|
|
1718
|
+
});
|
|
1719
|
+
}); });
|
|
1720
|
+
}
|
|
1721
|
+
registerEmbedHook(onExperienceEmbed);
|
|
1722
|
+
|
|
1723
|
+
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 };
|
|
1588
1724
|
//# sourceMappingURL=index.esm5.js.map
|