@monterosa/sdk-launcher-kit 2.0.0-rc.3 → 2.0.0-rc.4

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 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
- * This also signals that the communication bridge is ready.
70
+ * Sent explicitly by the developer via `sendInitialised()`.
66
71
  * This triggers the `initialised` lifecycle state.
67
72
  */
68
- Action["OnInitialised"] = "onInitialised";
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.OnInitialised) {
375
+ if (action === exports.Action.OnBridgeInitialised) {
371
376
  this.recipientInitialised = true;
372
377
  if (respondingTo === null) {
373
- this.send(exports.Action.OnInitialised, {}, exports.Source.Sdk, id);
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 && message.action !== exports.Action.OnInitialised) {
401
+ if (!this.recipientInitialised &&
402
+ message.action !== exports.Action.OnBridgeInitialised) {
396
403
  this.messagesQueue.push(message);
397
404
  return;
398
405
  }
@@ -519,6 +526,7 @@ function getParentBridge() {
519
526
  return null;
520
527
  }
521
528
  parentBridge = new BridgeImpl(bridgeId);
529
+ parentBridge.send(exports.Action.OnBridgeInitialised, {}, exports.Source.Sdk);
522
530
  return parentBridge;
523
531
  }
524
532
  /**
@@ -1068,7 +1076,7 @@ function unstashStyles(element) {
1068
1076
  element.removeAttribute('data-stash');
1069
1077
  }
1070
1078
 
1071
- var version = "2.0.0-rc.3";
1079
+ var version = "2.0.0-rc.4";
1072
1080
 
1073
1081
  /**
1074
1082
  * @license
@@ -1259,7 +1267,7 @@ async function embed(experience, containerOrId) {
1259
1267
  container.appendChild(iframe);
1260
1268
  concealIFrame(iframe);
1261
1269
  updateExperienceState(experience, 'mounted');
1262
- await waitForAction(experience, exports.Action.OnInitialised);
1270
+ await waitForAction(experience, exports.Action.OnExperienceInitialised);
1263
1271
  if (controller.signal.aborted) {
1264
1272
  return;
1265
1273
  }
@@ -1452,7 +1460,7 @@ class MonterosaExperienceElement extends HTMLElement {
1452
1460
  // eslint-disable-next-line
1453
1461
  onSdkMessage(experience, ({ payload, action }) => {
1454
1462
  switch (action) {
1455
- case exports.Action.OnInitialised:
1463
+ case exports.Action.OnExperienceInitialised:
1456
1464
  break;
1457
1465
  case exports.Action.OnResize: {
1458
1466
  // const { width, height } = payload;
@@ -1640,7 +1648,7 @@ function sendInitialised() {
1640
1648
  console.log('Unable to send initialised message, as there is no parent application');
1641
1649
  return;
1642
1650
  }
1643
- sendSdkRequest(parentApp, exports.Action.OnInitialised);
1651
+ sendSdkMessage(parentApp, exports.Action.OnExperienceInitialised);
1644
1652
  }
1645
1653
  /**
1646
1654
  * Notifies the parent application that the Experience UI is fully loaded
@@ -1722,7 +1730,7 @@ function onReady(experience, callback) {
1722
1730
  console.warn('[launcher-kit] onReady() is deprecated. Use onStateChanged(' +
1723
1731
  "experience, (state) => { if (state === 'initialised') ... }) instead.");
1724
1732
  return onSdkMessage(experience, ({ action }) => {
1725
- if (action === exports.Action.OnInitialised) {
1733
+ if (action === exports.Action.OnExperienceInitialised) {
1726
1734
  callback();
1727
1735
  }
1728
1736
  });
@@ -1823,8 +1831,8 @@ async function share(data) {
1823
1831
  const parentApp = getParentApplication();
1824
1832
  if (parentApp !== null) {
1825
1833
  const response = await sendSdkRequest(parentApp, exports.Action.OnShare, data, SHARE_REQUEST_TIMEOUT);
1826
- if (response.payload.result === 'failure') {
1827
- throw sdkUtil.createError(exports.ShareError.ParentAppError, ShareErrorMessages, response.payload.message);
1834
+ if (response.payload.error !== undefined) {
1835
+ throw sdkUtil.createError(exports.ShareError.ParentAppError, ShareErrorMessages, response.payload.error);
1828
1836
  }
1829
1837
  // 'success' and 'cancelled' both resolve silently
1830
1838
  return;
@@ -1871,9 +1879,7 @@ function handleExperienceEmbedded(experience) {
1871
1879
  }
1872
1880
  catch (err) {
1873
1881
  respondToSdkMessage(experience, message, {
1874
- result: 'failure',
1875
- message: sdkUtil.getErrorMessage(err),
1876
- data: {},
1882
+ error: sdkUtil.getErrorMessage(err),
1877
1883
  });
1878
1884
  }
1879
1885
  });