@monterosa/sdk-launcher-kit 2.0.0-rc.3 → 2.0.0-rc.5
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 +21 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -37
- package/dist/index.js.map +1 -1
- package/dist/sdk-launcher-kit.d.ts +1031 -0
- package/dist/src/tsdoc-metadata.json +11 -0
- package/dist/src/utils/bridge/api.d.ts +0 -6
- package/dist/src/utils/bridge/public_types.d.ts +7 -2
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -60,12 +60,17 @@ const logger = new sdkCore.Logger('@monterosa/sdk-launcher-kit');
|
|
|
60
60
|
*/
|
|
61
61
|
exports.Action = void 0;
|
|
62
62
|
(function (Action) {
|
|
63
|
+
/**
|
|
64
|
+
* Notifies that the communication bridge transport is ready.
|
|
65
|
+
* Auto-sent when the child bridge is created — no developer action needed.
|
|
66
|
+
*/
|
|
67
|
+
Action["OnBridgeInitialised"] = "onBridgeInitialised";
|
|
63
68
|
/**
|
|
64
69
|
* Notifies that the Experience has initialised and is ready to receive messages.
|
|
65
|
-
*
|
|
70
|
+
* Sent explicitly by the developer via `sendInitialised()`.
|
|
66
71
|
* This triggers the `initialised` lifecycle state.
|
|
67
72
|
*/
|
|
68
|
-
Action["
|
|
73
|
+
Action["OnExperienceInitialised"] = "onExperienceInitialised";
|
|
69
74
|
/**
|
|
70
75
|
* Notifies that UI of child Experience is loaded and ready to be visible.
|
|
71
76
|
* When this action is fired the loader will be hidden and
|
|
@@ -367,14 +372,15 @@ class BridgeImpl extends sdkUtil.Emitter {
|
|
|
367
372
|
return;
|
|
368
373
|
}
|
|
369
374
|
logger.log(`Received a ${respondingTo === null ? 'message' : 'response'}`, message);
|
|
370
|
-
if (action === exports.Action.
|
|
375
|
+
if (action === exports.Action.OnBridgeInitialised) {
|
|
371
376
|
this.recipientInitialised = true;
|
|
372
377
|
if (respondingTo === null) {
|
|
373
|
-
this.send(exports.Action.
|
|
378
|
+
this.send(exports.Action.OnBridgeInitialised, {}, exports.Source.Sdk, id);
|
|
374
379
|
}
|
|
375
380
|
while (this.messagesQueue.length > 0) {
|
|
376
381
|
this.postMessage(this.messagesQueue.shift());
|
|
377
382
|
}
|
|
383
|
+
return;
|
|
378
384
|
}
|
|
379
385
|
this.emit('message', message);
|
|
380
386
|
}
|
|
@@ -392,7 +398,8 @@ class BridgeImpl extends sdkUtil.Emitter {
|
|
|
392
398
|
}
|
|
393
399
|
postMessage(message) {
|
|
394
400
|
var _a, _b, _c, _d;
|
|
395
|
-
if (!this.recipientInitialised &&
|
|
401
|
+
if (!this.recipientInitialised &&
|
|
402
|
+
message.action !== exports.Action.OnBridgeInitialised) {
|
|
396
403
|
this.messagesQueue.push(message);
|
|
397
404
|
return;
|
|
398
405
|
}
|
|
@@ -482,24 +489,6 @@ function getBridge(id) {
|
|
|
482
489
|
bridges.set(id, bridge);
|
|
483
490
|
return bridge;
|
|
484
491
|
}
|
|
485
|
-
/**
|
|
486
|
-
* Returns true if the page is inside an iframe.
|
|
487
|
-
*
|
|
488
|
-
* @internal
|
|
489
|
-
*/
|
|
490
|
-
function isInsideIframe() {
|
|
491
|
-
if (typeof window === 'undefined') {
|
|
492
|
-
return false;
|
|
493
|
-
}
|
|
494
|
-
try {
|
|
495
|
-
return window.self !== window.top;
|
|
496
|
-
}
|
|
497
|
-
catch (_a) {
|
|
498
|
-
// SecurityError is thrown when accessing window.top in a cross-origin iframe.
|
|
499
|
-
// If we can't access it, we're definitely in an iframe.
|
|
500
|
-
return true;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
492
|
/**
|
|
504
493
|
* @internal
|
|
505
494
|
*/
|
|
@@ -510,15 +499,13 @@ function getParentBridge() {
|
|
|
510
499
|
if (parentBridge !== undefined) {
|
|
511
500
|
return parentBridge;
|
|
512
501
|
}
|
|
513
|
-
if (!isInsideIframe()) {
|
|
514
|
-
return null;
|
|
515
|
-
}
|
|
516
502
|
const url = new URL(window.location.href);
|
|
517
503
|
const bridgeId = url.searchParams.get(exports.QueryParam.BridgeId);
|
|
518
504
|
if (bridgeId === null) {
|
|
519
505
|
return null;
|
|
520
506
|
}
|
|
521
507
|
parentBridge = new BridgeImpl(bridgeId);
|
|
508
|
+
parentBridge.send(exports.Action.OnBridgeInitialised, {}, exports.Source.Sdk);
|
|
522
509
|
return parentBridge;
|
|
523
510
|
}
|
|
524
511
|
/**
|
|
@@ -1068,7 +1055,7 @@ function unstashStyles(element) {
|
|
|
1068
1055
|
element.removeAttribute('data-stash');
|
|
1069
1056
|
}
|
|
1070
1057
|
|
|
1071
|
-
var version = "2.0.0-rc.
|
|
1058
|
+
var version = "2.0.0-rc.5";
|
|
1072
1059
|
|
|
1073
1060
|
/**
|
|
1074
1061
|
* @license
|
|
@@ -1259,7 +1246,7 @@ async function embed(experience, containerOrId) {
|
|
|
1259
1246
|
container.appendChild(iframe);
|
|
1260
1247
|
concealIFrame(iframe);
|
|
1261
1248
|
updateExperienceState(experience, 'mounted');
|
|
1262
|
-
await waitForAction(experience, exports.Action.
|
|
1249
|
+
await waitForAction(experience, exports.Action.OnExperienceInitialised);
|
|
1263
1250
|
if (controller.signal.aborted) {
|
|
1264
1251
|
return;
|
|
1265
1252
|
}
|
|
@@ -1452,7 +1439,7 @@ class MonterosaExperienceElement extends HTMLElement {
|
|
|
1452
1439
|
// eslint-disable-next-line
|
|
1453
1440
|
onSdkMessage(experience, ({ payload, action }) => {
|
|
1454
1441
|
switch (action) {
|
|
1455
|
-
case exports.Action.
|
|
1442
|
+
case exports.Action.OnExperienceInitialised:
|
|
1456
1443
|
break;
|
|
1457
1444
|
case exports.Action.OnResize: {
|
|
1458
1445
|
// const { width, height } = payload;
|
|
@@ -1640,7 +1627,7 @@ function sendInitialised() {
|
|
|
1640
1627
|
console.log('Unable to send initialised message, as there is no parent application');
|
|
1641
1628
|
return;
|
|
1642
1629
|
}
|
|
1643
|
-
|
|
1630
|
+
sendSdkMessage(parentApp, exports.Action.OnExperienceInitialised);
|
|
1644
1631
|
}
|
|
1645
1632
|
/**
|
|
1646
1633
|
* Notifies the parent application that the Experience UI is fully loaded
|
|
@@ -1722,7 +1709,7 @@ function onReady(experience, callback) {
|
|
|
1722
1709
|
console.warn('[launcher-kit] onReady() is deprecated. Use onStateChanged(' +
|
|
1723
1710
|
"experience, (state) => { if (state === 'initialised') ... }) instead.");
|
|
1724
1711
|
return onSdkMessage(experience, ({ action }) => {
|
|
1725
|
-
if (action === exports.Action.
|
|
1712
|
+
if (action === exports.Action.OnExperienceInitialised) {
|
|
1726
1713
|
callback();
|
|
1727
1714
|
}
|
|
1728
1715
|
});
|
|
@@ -1823,8 +1810,8 @@ async function share(data) {
|
|
|
1823
1810
|
const parentApp = getParentApplication();
|
|
1824
1811
|
if (parentApp !== null) {
|
|
1825
1812
|
const response = await sendSdkRequest(parentApp, exports.Action.OnShare, data, SHARE_REQUEST_TIMEOUT);
|
|
1826
|
-
if (response.payload.
|
|
1827
|
-
throw sdkUtil.createError(exports.ShareError.ParentAppError, ShareErrorMessages, response.payload.
|
|
1813
|
+
if (response.payload.error !== undefined) {
|
|
1814
|
+
throw sdkUtil.createError(exports.ShareError.ParentAppError, ShareErrorMessages, response.payload.error);
|
|
1828
1815
|
}
|
|
1829
1816
|
// 'success' and 'cancelled' both resolve silently
|
|
1830
1817
|
return;
|
|
@@ -1871,9 +1858,7 @@ function handleExperienceEmbedded(experience) {
|
|
|
1871
1858
|
}
|
|
1872
1859
|
catch (err) {
|
|
1873
1860
|
respondToSdkMessage(experience, message, {
|
|
1874
|
-
|
|
1875
|
-
message: sdkUtil.getErrorMessage(err),
|
|
1876
|
-
data: {},
|
|
1861
|
+
error: sdkUtil.getErrorMessage(err),
|
|
1877
1862
|
});
|
|
1878
1863
|
}
|
|
1879
1864
|
});
|
|
@@ -1909,7 +1894,6 @@ exports.getExperience = getExperience;
|
|
|
1909
1894
|
exports.getParentApplication = getParentApplication;
|
|
1910
1895
|
exports.getParentBridge = getParentBridge;
|
|
1911
1896
|
exports.isAutoresizesHeight = isAutoresizesHeight;
|
|
1912
|
-
exports.isInsideIframe = isInsideIframe;
|
|
1913
1897
|
exports.onMessage = onMessage;
|
|
1914
1898
|
exports.onMoreDataRequested = onMoreDataRequested;
|
|
1915
1899
|
exports.onReady = onReady;
|