@monterosa/sdk-launcher-kit 0.18.0 → 0.19.0-rc.2

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.
Files changed (35) hide show
  1. package/dist/index.cjs.js +561 -336
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/{index.esm2017.js → index.esm.js} +513 -312
  4. package/dist/index.esm.js.map +1 -0
  5. package/dist/src/api.d.ts +23 -9
  6. package/dist/src/autoresize.d.ts +9 -0
  7. package/dist/src/child_helpers.d.ts +6 -5
  8. package/dist/src/constants.d.ts +2 -4
  9. package/dist/src/custom_element.d.ts +9 -0
  10. package/dist/src/experience_impl.d.ts +3 -4
  11. package/dist/src/index.d.ts +4 -4
  12. package/dist/src/integrations.d.ts +15 -0
  13. package/dist/src/loader.d.ts +2 -4
  14. package/dist/src/logger.d.ts +2 -4
  15. package/dist/src/parent_application.d.ts +2 -4
  16. package/dist/src/parent_application_impl.d.ts +2 -4
  17. package/dist/src/storage.d.ts +7 -6
  18. package/dist/src/storage_impl.d.ts +2 -4
  19. package/dist/src/types.d.ts +8 -12
  20. package/dist/src/utils/bridge/api.d.ts +2 -4
  21. package/dist/src/utils/bridge/bridge_impl.d.ts +4 -4
  22. package/dist/src/utils/bridge/config.d.ts +2 -4
  23. package/dist/src/utils/bridge/constants.d.ts +2 -4
  24. package/dist/src/utils/bridge/helpers.d.ts +2 -4
  25. package/dist/src/utils/bridge/index.d.ts +2 -4
  26. package/dist/src/utils/bridge/public_types.d.ts +5 -7
  27. package/dist/src/utils/bridge/sideeffects.d.ts +2 -4
  28. package/dist/src/utils/bridge/types.d.ts +2 -4
  29. package/dist/src/utils/htmlelement-shim.d.ts +8 -0
  30. package/package.json +20 -14
  31. package/dist/index.esm2017.js.map +0 -1
  32. package/dist/index.esm5.js +0 -1837
  33. package/dist/index.esm5.js.map +0 -1
  34. package/dist/src/utils/hash.d.ts +0 -19
  35. package/dist/src/utils/hashable.d.ts +0 -13
package/dist/index.cjs.js CHANGED
@@ -7,7 +7,7 @@ var sdkUtil = require('@monterosa/sdk-util');
7
7
  var uuid = require('uuid');
8
8
  var sdkInteractKit = require('@monterosa/sdk-interact-kit');
9
9
 
10
- /*! *****************************************************************************
10
+ /******************************************************************************
11
11
  Copyright (c) Microsoft Corporation.
12
12
 
13
13
  Permission to use, copy, modify, and/or distribute this software for any
@@ -21,7 +21,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21
21
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
22
  PERFORMANCE OF THIS SOFTWARE.
23
23
  ***************************************************************************** */
24
- /* global Reflect, Promise */
24
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
25
25
 
26
26
  var extendStatics = function(d, b) {
27
27
  extendStatics = Object.setPrototypeOf ||
@@ -60,12 +60,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
60
60
  }
61
61
 
62
62
  function __generator(thisArg, body) {
63
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
64
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
63
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
64
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
65
65
  function verb(n) { return function (v) { return step([n, v]); }; }
66
66
  function step(op) {
67
67
  if (f) throw new TypeError("Generator is already executing.");
68
- while (_) try {
68
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
69
69
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
70
70
  if (y = 0, t) op = [op[0] & 2, t.value];
71
71
  switch (op[0]) {
@@ -85,15 +85,18 @@ function __generator(thisArg, body) {
85
85
  } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
86
86
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
87
87
  }
88
- }
88
+ }
89
+
90
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
91
+ var e = new Error(message);
92
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
93
+ };
89
94
 
90
95
  /**
91
96
  * @license
92
- * constants.ts
93
- * launcher-kit
97
+ * @monterosa/sdk-launcher-kit
94
98
  *
95
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-15
96
- * Copyright © 2022 Monterosa. All rights reserved.
99
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
97
100
  *
98
101
  * More details on the license can be found at https://www.monterosa.co/sdk/license
99
102
  */
@@ -119,11 +122,9 @@ var DEFAULT_HEIGHT = 250;
119
122
 
120
123
  /**
121
124
  * @license
122
- * logger.ts
123
- * interact-kit
125
+ * @monterosa/sdk-interact-kit
124
126
  *
125
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-05-23
126
- * Copyright © 2023 Monterosa. All rights reserved.
127
+ * Copyright © 2023 Monterosa Productions Limited. All rights reserved.
127
128
  *
128
129
  * More details on the license can be found at https://www.monterosa.co/sdk/license
129
130
  */
@@ -131,11 +132,9 @@ var logger = new sdkCore.Logger('@monterosa/sdk-interact-kit');
131
132
 
132
133
  /**
133
134
  * @license
134
- * public_types.ts
135
- * launcher-kit
135
+ * @monterosa/sdk-launcher-kit
136
136
  *
137
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
138
- * Copyright © 2022 Monterosa. All rights reserved.
137
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
139
138
  *
140
139
  * More details on the license can be found at https://www.monterosa.co/sdk/license
141
140
  */
@@ -177,11 +176,9 @@ exports.Source = void 0;
177
176
 
178
177
  /**
179
178
  * @license
180
- * types.ts
181
- * launcher-kit
179
+ * @monterosa/sdk-launcher-kit
182
180
  *
183
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-01-19
184
- * Copyright © 2022 Monterosa. All rights reserved.
181
+ * Copyright © 2022-2024 Monterosa Productions Limited. All rights reserved.
185
182
  *
186
183
  * More details on the license can be found at https://www.monterosa.co/sdk/license
187
184
  */
@@ -226,11 +223,9 @@ exports.QueryParam = void 0;
226
223
 
227
224
  /**
228
225
  * @license
229
- * types.ts
230
- * launcher-kit
226
+ * @monterosa/sdk-launcher-kit
231
227
  *
232
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2024-01-02
233
- * Copyright © 2024 Monterosa. All rights reserved.
228
+ * Copyright © 2024 Monterosa Productions Limited. All rights reserved.
234
229
  *
235
230
  * More details on the license can be found at https://www.monterosa.co/sdk/license
236
231
  */
@@ -276,11 +271,9 @@ var BridgeErrorMessages = (_a$2 = {},
276
271
 
277
272
  /**
278
273
  * @license
279
- * config.ts
280
- * launcher-kit
274
+ * @monterosa/sdk-launcher-kit
281
275
  *
282
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2024-01-02
283
- * Copyright © 2024 Monterosa. All rights reserved.
276
+ * Copyright © 2024 Monterosa Productions Limited. All rights reserved.
284
277
  *
285
278
  * More details on the license can be found at https://www.monterosa.co/sdk/license
286
279
  */
@@ -319,11 +312,9 @@ function setRequestTimeout(newTimeout) {
319
312
 
320
313
  /**
321
314
  * @license
322
- * helpers.ts
323
- * launcher-kit
315
+ * @monterosa/sdk-launcher-kit
324
316
  *
325
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
326
- * Copyright © 2022 Monterosa. All rights reserved.
317
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
327
318
  *
328
319
  * More details on the license can be found at https://www.monterosa.co/sdk/license
329
320
  */
@@ -334,11 +325,9 @@ function isMessage(message) {
334
325
 
335
326
  /**
336
327
  * @license
337
- * sideeffect.ts
338
- * launcher-kit
328
+ * @monterosa/sdk-launcher-kit
339
329
  *
340
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
341
- * Copyright © 2022 Monterosa. All rights reserved.
330
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
342
331
  *
343
332
  * More details on the license can be found at https://www.monterosa.co/sdk/license
344
333
  */
@@ -397,11 +386,9 @@ if (!globals$2.monterosaSdk.initialised) {
397
386
 
398
387
  /**
399
388
  * @license
400
- * constants.ts
401
- * launcher-kit
389
+ * @monterosa/sdk-launcher-kit
402
390
  *
403
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
404
- * Copyright © 2022 Monterosa. All rights reserved.
391
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
405
392
  *
406
393
  * More details on the license can be found at https://www.monterosa.co/sdk/license
407
394
  */
@@ -421,11 +408,9 @@ var VERSION$1 = '1.0.0';
421
408
 
422
409
  /**
423
410
  * @license
424
- * bridge_impl.ts
425
- * launcher-kit
411
+ * @monterosa/sdk-launcher-kit
426
412
  *
427
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
428
- * Copyright © 2022 Monterosa. All rights reserved.
413
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
429
414
  *
430
415
  * More details on the license can be found at https://www.monterosa.co/sdk/license
431
416
  */
@@ -439,6 +424,8 @@ var BridgeImpl = /** @class */ (function (_super) {
439
424
  if (id === void 0) { id = uuid.v4(); }
440
425
  var _this = _super.call(this) || this;
441
426
  _this.id = id;
427
+ _this.recipientReady = false;
428
+ _this.messagesQueue = [];
442
429
  globals.monterosaSdk.emitter.on('message', _this.handleMessage.bind(_this));
443
430
  return _this;
444
431
  }
@@ -449,14 +436,14 @@ var BridgeImpl = /** @class */ (function (_super) {
449
436
  };
450
437
  Object.defineProperty(BridgeImpl.prototype, "iFrameId", {
451
438
  get: function () {
452
- return IFRAME_ID_PREFIX + "-" + this.id;
439
+ return "".concat(IFRAME_ID_PREFIX, "-").concat(this.id);
453
440
  },
454
441
  enumerable: false,
455
442
  configurable: true
456
443
  });
457
444
  Object.defineProperty(BridgeImpl.prototype, "iFrameSelector", {
458
445
  get: function () {
459
- return "iframe#" + this.iFrameId;
446
+ return "iframe#".concat(this.iFrameId);
460
447
  },
461
448
  enumerable: false,
462
449
  configurable: true
@@ -469,10 +456,21 @@ var BridgeImpl = /** @class */ (function (_super) {
469
456
  configurable: true
470
457
  });
471
458
  BridgeImpl.prototype.handleMessage = function (message) {
472
- if (message.bridgeId === this.id) {
473
- logger.log("Received a " + (message.respondingTo === null ? 'message' : 'response'), message);
474
- this.emit('message', message);
459
+ var id = message.id, bridgeId = message.bridgeId, action = message.action, respondingTo = message.respondingTo;
460
+ if (bridgeId !== this.id) {
461
+ return;
462
+ }
463
+ logger.log("Received a ".concat(respondingTo === null ? 'message' : 'response'), message);
464
+ if (action === exports.Action.OnReady) {
465
+ this.recipientReady = true;
466
+ if (respondingTo === null) {
467
+ this.send(exports.Action.OnReady, {}, exports.Source.Sdk, id);
468
+ }
469
+ while (this.messagesQueue.length > 0) {
470
+ this.postMessage(this.messagesQueue.shift());
471
+ }
475
472
  }
473
+ this.emit('message', message);
476
474
  };
477
475
  BridgeImpl.prototype.createMessage = function (action, payload, sourceName, respondingTo) {
478
476
  if (respondingTo === void 0) { respondingTo = null; }
@@ -489,6 +487,10 @@ var BridgeImpl = /** @class */ (function (_super) {
489
487
  };
490
488
  BridgeImpl.prototype.postMessage = function (message) {
491
489
  var _a, _b, _c, _d;
490
+ if (!this.recipientReady && message.action !== exports.Action.OnReady) {
491
+ this.messagesQueue.push(message);
492
+ return;
493
+ }
492
494
  var json = JSON.stringify(message);
493
495
  if (IS_IOS) {
494
496
  (_b = (_a = globals.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.monterosaSdk.postMessage(json);
@@ -509,7 +511,7 @@ var BridgeImpl = /** @class */ (function (_super) {
509
511
  if (payload === void 0) { payload = {}; }
510
512
  if (sourceName === void 0) { sourceName = exports.Source.Sdk; }
511
513
  var message = this.createMessage(action, payload, sourceName, respondingTo);
512
- logger.log("Sending a " + (message.respondingTo === null ? 'message' : 'response'), message);
514
+ logger.log("Sending a ".concat(message.respondingTo === null ? 'message' : 'response'), message);
513
515
  this.postMessage(message);
514
516
  return message;
515
517
  };
@@ -524,7 +526,10 @@ var BridgeImpl = /** @class */ (function (_super) {
524
526
  message = this.createMessage(action, payload, sourceName);
525
527
  logger.log('Sending a request', message);
526
528
  countdown = new Promise(function (_, reject) {
527
- timeoutRef = setTimeout(reject, timeout);
529
+ timeoutRef = setTimeout(function () {
530
+ return reject(new Error("The request for action '".concat(action, "' exceeded the timeout ") +
531
+ "limit of ".concat(timeout, "ms and was aborted.")));
532
+ }, timeout);
528
533
  });
529
534
  request = new Promise(function (resolve) {
530
535
  handler = function (responseMessage) {
@@ -557,11 +562,9 @@ var BridgeImpl = /** @class */ (function (_super) {
557
562
 
558
563
  /**
559
564
  * @license
560
- * api.ts
561
- * launcher-kit
565
+ * @monterosa/sdk-launcher-kit
562
566
  *
563
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
564
- * Copyright © 2022 Monterosa. All rights reserved.
567
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
565
568
  *
566
569
  * More details on the license can be found at https://www.monterosa.co/sdk/license
567
570
  */
@@ -574,7 +577,7 @@ function getBridge(id) {
574
577
  if (bridges.has(id)) {
575
578
  return bridges.get(id);
576
579
  }
577
- var bridge = new BridgeImpl();
580
+ var bridge = new BridgeImpl(id);
578
581
  bridges.set(id, bridge);
579
582
  return bridge;
580
583
  }
@@ -763,11 +766,9 @@ function onMessage(bridged, callback) {
763
766
 
764
767
  /**
765
768
  * @license
766
- * experience_impl.ts
767
- * launcher-kit
769
+ * @monterosa/sdk-launcher-kit
768
770
  *
769
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-01-19
770
- * Copyright © 2022 Monterosa. All rights reserved.
771
+ * Copyright © 2022-2024 Monterosa Productions Limited. All rights reserved.
771
772
  *
772
773
  * More details on the license can be found at https://www.monterosa.co/sdk/license
773
774
  */
@@ -779,8 +780,9 @@ var ExperienceImpl = /** @class */ (function () {
779
780
  var _this = this;
780
781
  this.sdk = sdk;
781
782
  this._parameters = {};
783
+ this.id = uuid.v4();
782
784
  this._config = config;
783
- this.bridge = getBridge(uuid.v4());
785
+ this.bridge = getBridge(this.id);
784
786
  if (config.parameters !== undefined) {
785
787
  var reserved_1 = Object.values(exports.QueryParam);
786
788
  var ignored_1 = [];
@@ -794,10 +796,10 @@ var ExperienceImpl = /** @class */ (function () {
794
796
  }
795
797
  });
796
798
  if (ignored_1.length === 1) {
797
- console.warn("Parameter \"" + ignored_1[0] + "\" ignored as it matches reserved words");
799
+ console.warn("Parameter \"".concat(ignored_1[0], "\" ignored as it matches reserved words"));
798
800
  }
799
801
  if (ignored_1.length > 1) {
800
- console.warn("Parameters \"" + ignored_1.join('", "') + "\" ignored as they match reserved words");
802
+ console.warn("Parameters \"".concat(ignored_1.join('", "'), "\" ignored as they match reserved words"));
801
803
  }
802
804
  }
803
805
  }
@@ -886,7 +888,7 @@ var ExperienceImpl = /** @class */ (function () {
886
888
  // Ensure the URL includes a protocol.
887
889
  if (/^http/.test(url) === false) {
888
890
  // If none are found, use the same as the document.
889
- url = "" + document.location.protocol + url;
891
+ url = "".concat(document.location.protocol).concat(url);
890
892
  }
891
893
  var urlObj = new URL(url);
892
894
  Object.values(exports.QueryParam)
@@ -904,17 +906,43 @@ var ExperienceImpl = /** @class */ (function () {
904
906
 
905
907
  /**
906
908
  * @license
907
- * loader.ts
908
- * launcher-kit
909
+ * @monterosa/sdk-launcher-kit
909
910
  *
910
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-08-04
911
- * Copyright © 2022 Monterosa. All rights reserved.
911
+ * Copyright © 2025 Monterosa Productions Limited. All rights reserved.
912
+ *
913
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
914
+ */
915
+ var integrations = new Map();
916
+ function addIntegration(container, integration) {
917
+ integrations.set(container, integration);
918
+ }
919
+ function getIntegration(container) {
920
+ return integrations.get(container);
921
+ }
922
+ function getIntegrations() {
923
+ return Array.from(integrations.values());
924
+ }
925
+ function deleteIntegration(container) {
926
+ integrations.delete(container);
927
+ }
928
+ function hasIntegration(containerOrExperience) {
929
+ if (containerOrExperience instanceof HTMLElement) {
930
+ return integrations.has(containerOrExperience);
931
+ }
932
+ return Array.from(integrations.values()).some(function (integration) { return integration.experience === containerOrExperience; });
933
+ }
934
+
935
+ /**
936
+ * @license
937
+ * @monterosa/sdk-launcher-kit
938
+ *
939
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
912
940
  *
913
941
  * More details on the license can be found at https://www.monterosa.co/sdk/license
914
942
  */
915
943
  /* eslint-enable */
916
944
  function getLoadingTemplate() {
917
- return "\n <div>\n <style type=\"text/css\">\n .__mic-loader {\n position: absolute;\n width: 100%;\n height: 100%;\n z-index: 9;\n box-sizing: border-box;\n text-align: center;\n background: #fff;\n }\n\n .__mic-loader__container {\n padding: 20px 0;\n gap: 20px;\n min-height: " + DEFAULT_HEIGHT + "px;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n }\n\n .__mic-loader__spinner {\n position: relative;\n width: 10px;\n height: 10px;\n border-radius: 5px;\n background-color: #0b0f1c;\n color: #0b0f1c;\n animation: mic-loader__animation 1s infinite linear alternate;\n animation-delay: 0.5s; \n }\n\n .__mic-loader__spinner::before,\n .__mic-loader__spinner::after {\n content: \"\";\n display: inline-block;\n position: absolute;\n top: 0;\n }\n\n .__mic-loader__spinner::before {\n left: -15px;\n width: 10px;\n height: 10px;\n border-radius: 5px;\n background-color: #0b0f1c;\n color: #0b0f1c;\n animation: mic-loader__animation 1s infinite alternate;\n animation-delay: 0s;\n }\n\n .__mic-loader__spinner::after {\n left: 15px;\n width: 10px;\n height: 10px;\n border-radius: 5px;\n background-color: #0b0f1c;\n color: #0b0f1c;\n animation: mic-loader__animation 1s infinite alternate;\n animation-delay: 1s;\n }\n\n @keyframes mic-loader__animation {\n 0% {\n background-color: #0b0f1c;\n }\n 50%, 100% {\n background-color: rgba(11, 15, 28, 0.2);\n }\n }\n </style>\n <div class=\"__mic-loader\">\n <div class=\"__mic-loader__container\">\n <div class=\"__mic-loader__spinner\"></div>\n </div>\n </div>\n </div>\n ";
945
+ return "\n <div>\n <style type=\"text/css\">\n .__mic-loader {\n position: absolute;\n width: 100%;\n height: 100%;\n z-index: 9;\n box-sizing: border-box;\n text-align: center;\n background: #fff;\n }\n\n .__mic-loader__container {\n padding: 20px 0;\n gap: 20px;\n min-height: ".concat(DEFAULT_HEIGHT, "px;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: center;\n }\n\n .__mic-loader__spinner {\n position: relative;\n width: 10px;\n height: 10px;\n border-radius: 5px;\n background-color: #0b0f1c;\n color: #0b0f1c;\n animation: mic-loader__animation 1s infinite linear alternate;\n animation-delay: 0.5s; \n }\n\n .__mic-loader__spinner::before,\n .__mic-loader__spinner::after {\n content: \"\";\n display: inline-block;\n position: absolute;\n top: 0;\n }\n\n .__mic-loader__spinner::before {\n left: -15px;\n width: 10px;\n height: 10px;\n border-radius: 5px;\n background-color: #0b0f1c;\n color: #0b0f1c;\n animation: mic-loader__animation 1s infinite alternate;\n animation-delay: 0s;\n }\n\n .__mic-loader__spinner::after {\n left: 15px;\n width: 10px;\n height: 10px;\n border-radius: 5px;\n background-color: #0b0f1c;\n color: #0b0f1c;\n animation: mic-loader__animation 1s infinite alternate;\n animation-delay: 1s;\n }\n\n @keyframes mic-loader__animation {\n 0% {\n background-color: #0b0f1c;\n }\n 50%, 100% {\n background-color: rgba(11, 15, 28, 0.2);\n }\n }\n </style>\n <div class=\"__mic-loader\">\n <div class=\"__mic-loader__container\">\n <div class=\"__mic-loader__spinner\"></div>\n </div>\n </div>\n </div>\n ");
918
946
  }
919
947
  function embed$1(container, loadingTemplate) {
920
948
  if (loadingTemplate === void 0) { loadingTemplate = getLoadingTemplate; }
@@ -929,7 +957,7 @@ function embed$1(container, loadingTemplate) {
929
957
  * Stash and apply some custom styles to container element
930
958
  */
931
959
  stashStyles(container, ['minHeight', 'position']);
932
- container.style.minHeight = DEFAULT_HEIGHT + "px";
960
+ container.style.minHeight = "".concat(DEFAULT_HEIGHT, "px");
933
961
  /**
934
962
  * Inject loader element built from the html markup template
935
963
  */
@@ -976,7 +1004,7 @@ function show(container, loadingTemplate) {
976
1004
  * Kicking fade animation in.
977
1005
  */
978
1006
  setTimeout(function () {
979
- loaderElement.style.transition = "all " + LOADER_ANIMATION_DURATION + "ms";
1007
+ loaderElement.style.transition = "all ".concat(LOADER_ANIMATION_DURATION, "ms");
980
1008
  loaderElement.style.opacity = '1';
981
1009
  }, 0);
982
1010
  /**
@@ -1032,7 +1060,7 @@ function hide(container) {
1032
1060
  function stashStyles(element, props) {
1033
1061
  var styles = getComputedStyle(element);
1034
1062
  var stash = props
1035
- .map(function (prop) { return String(prop) + "=" + styles[prop]; })
1063
+ .map(function (prop) { return "".concat(String(prop), "=").concat(styles[prop]); })
1036
1064
  .join(';');
1037
1065
  element.setAttribute('data-stash', stash);
1038
1066
  }
@@ -1051,15 +1079,13 @@ function unstashStyles(element) {
1051
1079
  element.removeAttribute('data-stash');
1052
1080
  }
1053
1081
 
1054
- var version = "0.18.0";
1082
+ var version = "0.19.0-rc.2";
1055
1083
 
1056
1084
  /**
1057
1085
  * @license
1058
- * api.ts
1059
- * launcher-kit
1086
+ * @monterosa/sdk-launcher-kit
1060
1087
  *
1061
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
1062
- * Copyright © 2022 Monterosa. All rights reserved.
1088
+ * Copyright © 2022-2025 Monterosa Productions Limited. All rights reserved.
1063
1089
  *
1064
1090
  * More details on the license can be found at https://www.monterosa.co/sdk/license
1065
1091
  */
@@ -1069,8 +1095,12 @@ var version = "0.18.0";
1069
1095
  * @internal
1070
1096
  */
1071
1097
  var VERSION = version;
1072
- var integrations = new Map();
1073
- var embedHooks = [];
1098
+ /**
1099
+ * Event emitter for the launcher kit.
1100
+ *
1101
+ * @internal
1102
+ */
1103
+ var emitter = new sdkUtil.Emitter();
1074
1104
  /**
1075
1105
  * Creates an iframe with the provided parameters.
1076
1106
  *
@@ -1152,22 +1182,6 @@ function getExperience(sdkOrConfig, config) {
1152
1182
  var experience = new ExperienceImpl(sdk, experienceConfig);
1153
1183
  return experience;
1154
1184
  }
1155
- function onResize(experience, container) {
1156
- if (!experience.config.autoresizesHeight) {
1157
- return function () { };
1158
- }
1159
- return onSdkMessage(experience, function (_a) {
1160
- var action = _a.action, payload = _a.payload;
1161
- if (action === exports.Action.OnResize) {
1162
- /**
1163
- * Container width is maintained the same as it is defined in the parent
1164
- * page to preserve its behaviour. Only the height is updated
1165
- */
1166
- // container.style.width = `${payload.width}px`;
1167
- container.style.height = payload.height + "px";
1168
- }
1169
- });
1170
- }
1171
1185
  function onUILoaded(experience) {
1172
1186
  return new Promise(function (resolve) {
1173
1187
  var unsubscribe = onSdkMessage(experience, function (_a) {
@@ -1179,6 +1193,36 @@ function onUILoaded(experience) {
1179
1193
  });
1180
1194
  });
1181
1195
  }
1196
+ /**
1197
+ * Subscribe to the event when Experience is embedded into the container.
1198
+ * Also calls the callback immediately for all currently embedded Experiences.
1199
+ *
1200
+ * @param callback - Callback to be called when Experience is embedded.
1201
+ */
1202
+ function onExperienceEmbedded(callback) {
1203
+ var integrations = getIntegrations();
1204
+ for (var _i = 0, integrations_1 = integrations; _i < integrations_1.length; _i++) {
1205
+ var integration = integrations_1[_i];
1206
+ if (integration.embedded) {
1207
+ callback(integration.experience, integration.container);
1208
+ }
1209
+ }
1210
+ emitter.on('embedded', callback);
1211
+ return function () {
1212
+ emitter.off('embedded', callback);
1213
+ };
1214
+ }
1215
+ /**
1216
+ * Subscribe to the event when Experience is unmounted from the container.
1217
+ *
1218
+ * @param callback - Callback to be called when Experience is unmounted.
1219
+ */
1220
+ function onExperienceUnmounted(callback) {
1221
+ emitter.on('unmounted', callback);
1222
+ return function () {
1223
+ emitter.off('unmounted', callback);
1224
+ };
1225
+ }
1182
1226
  function experienceReady(experience) {
1183
1227
  return __awaiter(this, void 0, void 0, function () {
1184
1228
  var bumper, timeout, loaded, hasFullyLoadedExperience, eitherTimeoutOrFullyLoaded;
@@ -1216,7 +1260,7 @@ function experienceReady(experience) {
1216
1260
  */
1217
1261
  function embed(experience, containerOrId) {
1218
1262
  return __awaiter(this, void 0, void 0, function () {
1219
- var container, controller, hooksUnsubscribe, _i, embedHooks_1, hook, unsub, url, iframe;
1263
+ var container, controller, integration, url, iframe;
1220
1264
  return __generator(this, function (_a) {
1221
1265
  switch (_a.label) {
1222
1266
  case 0:
@@ -1224,28 +1268,30 @@ function embed(experience, containerOrId) {
1224
1268
  ? containerOrId
1225
1269
  : document.getElementById(containerOrId);
1226
1270
  if (container === null) {
1227
- throw new Error("Container element with id \"" + containerOrId + "\" doesn't exist in DOM");
1271
+ throw new Error("Container element \"".concat(containerOrId, "\" not found in DOM. ") +
1272
+ 'Please ensure the element exists before calling embed().');
1228
1273
  }
1229
- if (integrations.has(container)) {
1230
- return [2 /*return*/];
1274
+ if (hasIntegration(container)) {
1275
+ throw new Error('Container already contains an embedded experience. Use unmount() first ' +
1276
+ 'to remove the existing experience before embedding a new one.');
1277
+ }
1278
+ if (hasIntegration(experience)) {
1279
+ throw new Error('This experience is already embedded in another container. Use unmount() ' +
1280
+ 'to remove it from that container before embedding it into this one.');
1231
1281
  }
1232
1282
  controller = new AbortController();
1233
- hooksUnsubscribe = [];
1234
- integrations.set(container, {
1283
+ integration = {
1284
+ container: container,
1235
1285
  experience: experience,
1236
1286
  controller: controller,
1237
- hooksUnsubscribe: hooksUnsubscribe,
1238
- });
1287
+ embedded: false,
1288
+ };
1289
+ addIntegration(container, integration);
1239
1290
  if (experience.config.supportsLoadingState === true) {
1240
1291
  // Although showLoader is an asynchronous function, we execute
1241
1292
  // it synchronously to embed the iframe as quickly as possible.
1242
1293
  show(container, experience.config.loadingTemplate);
1243
1294
  }
1244
- for (_i = 0, embedHooks_1 = embedHooks; _i < embedHooks_1.length; _i++) {
1245
- hook = embedHooks_1[_i];
1246
- unsub = hook(experience, container);
1247
- hooksUnsubscribe.push(unsub);
1248
- }
1249
1295
  return [4 /*yield*/, experience.getUrl()];
1250
1296
  case 1:
1251
1297
  url = _a.sent();
@@ -1260,6 +1306,8 @@ function embed(experience, containerOrId) {
1260
1306
  });
1261
1307
  container.appendChild(iframe);
1262
1308
  concealIFrame(iframe);
1309
+ integration.embedded = true;
1310
+ emitter.emit('embedded', experience, container);
1263
1311
  return [4 /*yield*/, experienceReady(experience)];
1264
1312
  case 2:
1265
1313
  _a.sent();
@@ -1295,22 +1343,22 @@ function unmount(containerOrId) {
1295
1343
  ? containerOrId
1296
1344
  : document.getElementById(containerOrId);
1297
1345
  if (container === null) {
1298
- throw new Error("Container element with id \"" + containerOrId + "\" doesn't exist in DOM");
1346
+ throw new Error("Container element \"".concat(containerOrId, "\" not found in DOM. ") +
1347
+ 'Please ensure the element exists before calling unmount().');
1299
1348
  }
1300
- var integration = integrations.get(container);
1349
+ var integration = getIntegration(container);
1301
1350
  if (!integration) {
1302
- return;
1351
+ throw new Error("No experience found embedded in container \"".concat(containerOrId, "\". ") +
1352
+ 'Please ensure the experience is embedded before calling unmount().');
1303
1353
  }
1304
1354
  integration.controller.abort();
1305
- for (var _i = 0, _a = integration.hooksUnsubscribe; _i < _a.length; _i++) {
1306
- var unsub = _a[_i];
1307
- unsub();
1308
- }
1309
1355
  while (container.lastElementChild) {
1310
1356
  container.removeChild(container.lastElementChild);
1311
1357
  }
1312
- integrations.delete(container);
1358
+ integration.embedded = false;
1359
+ deleteIntegration(container);
1313
1360
  container.style.height = '';
1361
+ emitter.emit('unmounted', integration.experience, container);
1314
1362
  }
1315
1363
  /**
1316
1364
  * Informs the Experience that more data should be loaded and displayed on the UI.
@@ -1324,12 +1372,6 @@ function unmount(containerOrId) {
1324
1372
  function requestMoreData(experience) {
1325
1373
  sendSdkMessage(experience, exports.Action.OnMoreDataRequested);
1326
1374
  }
1327
- /**
1328
- * @internal
1329
- */
1330
- function registerEmbedHook(hook) {
1331
- embedHooks.push(hook);
1332
- }
1333
1375
  function enableLogging(logLevelOrFlag) {
1334
1376
  if (logLevelOrFlag === void 0) { logLevelOrFlag = true; }
1335
1377
  if (typeof logLevelOrFlag === 'boolean') {
@@ -1337,16 +1379,13 @@ function enableLogging(logLevelOrFlag) {
1337
1379
  return;
1338
1380
  }
1339
1381
  logger.logLevel = logLevelOrFlag;
1340
- }
1341
- registerEmbedHook(onResize);
1382
+ }
1342
1383
 
1343
1384
  /**
1344
1385
  * @license
1345
- * parent_application_impl.ts
1346
- * launcher-kit
1386
+ * @monterosa/sdk-launcher-kit
1347
1387
  *
1348
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
1349
- * Copyright © 2022 Monterosa. All rights reserved.
1388
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
1350
1389
  *
1351
1390
  * More details on the license can be found at https://www.monterosa.co/sdk/license
1352
1391
  */
@@ -1359,11 +1398,9 @@ var ParentApplicationImpl = /** @class */ (function () {
1359
1398
 
1360
1399
  /**
1361
1400
  * @license
1362
- * parent_application.ts
1363
- * launcher-kit
1401
+ * @monterosa/sdk-launcher-kit
1364
1402
  *
1365
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-15
1366
- * Copyright © 2023 Monterosa. All rights reserved.
1403
+ * Copyright © 2023 Monterosa Productions Limited. All rights reserved.
1367
1404
  *
1368
1405
  * More details on the license can be found at https://www.monterosa.co/sdk/license
1369
1406
  */
@@ -1389,176 +1426,9 @@ function getParentApplication() {
1389
1426
 
1390
1427
  /**
1391
1428
  * @license
1392
- * child_helpers.ts
1393
- * launcher-kit
1394
- *
1395
- * Created by Josep Rodriguez <josep.rodriguez@monterosa.co.uk> on 2022-07-13
1396
- * Copyright © 2022 Monterosa. All rights reserved.
1397
- *
1398
- * More details on the license can be found at https://www.monterosa.co/sdk/license
1399
- */
1400
- function getUrlParam(param) {
1401
- var queryString = {};
1402
- if (typeof window !== 'undefined') {
1403
- queryString = window.location.search;
1404
- }
1405
- var urlParams = new URLSearchParams(queryString);
1406
- return urlParams.get(param);
1407
- }
1408
- /**
1409
- * The SDK on the parent application will by default request a child
1410
- * Experience to hide its header and footer by setting a query parameter called
1411
- * `micHideHeaderAndFooter` to `1`.
1412
- *
1413
- * This function will return true if that is the case, and false otherwise.
1414
- *
1415
- * When true, the developer of a child Experience is expected to hide it's headers
1416
- * and footers as the parent application is actively providing them.
1417
- *
1418
- * You can test whether you are respecting this correctly by adding the following query
1419
- * to your URL:
1420
- *
1421
- * "?micHideHeaderAndFooter=1"
1422
- *
1423
- * @returns Whether the header and footer views should be hidden.
1424
- */
1425
- function shouldHideHeaderAndFooter() {
1426
- return getUrlParam(exports.QueryParam.HideHeaderAndFooter) === '1';
1427
- }
1428
- /**
1429
- * This function will returns true if experience is embedded in autoresize height mode.
1430
- */
1431
- function isAutoresizesHeight() {
1432
- return getUrlParam(exports.QueryParam.AutoresizesHeight) === '1';
1433
- }
1434
- /**
1435
- * This function is used to notify the parent application that the Experience
1436
- * is ready to be used. It's intended to be called by the Experience itself and
1437
- * not by the parent application.
1438
- *
1439
- * @example
1440
- * ```javascript
1441
- * import { sendReady } from '@monterosa/sdk-launcher-kit';
1442
- *
1443
- * sendReady();
1444
- * ```
1445
- *
1446
- * @returns void
1447
- */
1448
- function sendReady() {
1449
- var parentApp = getParentApplication();
1450
- if (parentApp === null) {
1451
- console.log('Unable to send finished loading UI message, as there is no parent application');
1452
- return;
1453
- }
1454
- sendSdkMessage(parentApp, exports.Action.OnReady);
1455
- }
1456
- /**
1457
- * Sends a message to the SDK of the parent application informing it that
1458
- * the UI of this Experience has completed loading.
1459
- *
1460
- * You should call this method when your UI has completed loading and you are ready to
1461
- * display data to the user. This can be when your network calls have successfully requested
1462
- * data and you have updated the DOM for it, or when an error has occurred and you want
1463
- * to take over the UI to provide details to the user.
1464
- *
1465
- * The SDK will use this message to dismiss the loading indicator, allowing a seamless
1466
- * transition between a native loading UI, into a fully loaded, child Experience.
1467
- *
1468
- * If this call is not made, the parent SDK will add a grace period to ensure the web app
1469
- * has sufficient time to load, and eventually dismiss the loading state, whether Experience
1470
- * is ready or not, so as to avoid scenarios were a defect leaves an infinite loading state
1471
- * presented to the user.
1472
- */
1473
- function sendFinishedLoadingUI() {
1474
- var parentApp = getParentApplication();
1475
- if (parentApp === null) {
1476
- console.log('Unable to send finished loading UI message, as there is no parent application');
1477
- return;
1478
- }
1479
- sendSdkMessage(parentApp, exports.Action.OnUILoaded);
1480
- }
1481
- /**
1482
- * Adds an observer for when more data is requested by the parent application
1483
- *
1484
- * @param callback - The callback that is triggered when a request for more data
1485
- * is received
1486
- * @returns The unsubscribe function. When it's called,
1487
- * the observer will be removed and requests for data will no longer be received
1488
- */
1489
- function onMoreDataRequested(callback) {
1490
- var parentApp = getParentApplication();
1491
- if (parentApp === null) {
1492
- console.log('Unable to subscribe to more data event, as there is no parent application');
1493
- return function () { };
1494
- }
1495
- return onSdkMessage(parentApp, function (_a) {
1496
- var action = _a.action;
1497
- if (action === exports.Action.OnMoreDataRequested) {
1498
- callback();
1499
- }
1500
- });
1501
- }
1502
- /**
1503
- * Adds an observer for when experience is fully embedded and ready to accept
1504
- * incoming messages
1505
- *
1506
- * @param experience - Experience instance
1507
- * @param callback - The callback that is triggered when experience is embedded
1508
- * @returns The unsubscribe function. When it's called, the observer will be
1509
- * removed and ready event will not be received
1510
- */
1511
- function onReady(experience, callback) {
1512
- return onSdkMessage(experience, function (_a) {
1513
- var action = _a.action;
1514
- if (action === exports.Action.OnReady) {
1515
- callback();
1516
- }
1517
- });
1518
- }
1519
- /**
1520
- * @internal
1521
- */
1522
- var sendExperienceSizeThrottled = sdkUtil.throttle(function (width, height) {
1523
- var parentApp = getParentApplication();
1524
- if (parentApp === null)
1525
- return;
1526
- sendSdkMessage(parentApp, exports.Action.OnResize, { width: width, height: height });
1527
- }, RESIZE_THROTTLE_TIMEOUT, {
1528
- leading: true,
1529
- trailing: true,
1530
- });
1531
- /**
1532
- * @internal
1533
- */
1534
- function sendExperienceSize(width, height) {
1535
- return sendExperienceSizeThrottled(width, height);
1536
- }
1537
- /**
1538
- * Sets up an observer to watch for the element dimensions change and
1539
- * automatically reports their changes to the parent application.
1540
- *
1541
- * @param element - HTML element whose dimensions need to be watched
1542
- * @returns The unsubscribe function. When it's called,
1543
- * the observer will be removed and element dimensions are no longer tracked
1544
- */
1545
- function reportExperienceSizeChanges(element) {
1546
- var observer = new ResizeObserver(function () {
1547
- var width = Math.max(element.offsetWidth, element.scrollWidth);
1548
- var height = Math.max(element.offsetHeight, element.scrollHeight);
1549
- sendExperienceSize(width, height);
1550
- });
1551
- observer.observe(element);
1552
- return function () { return observer.unobserve(element); };
1553
- }
1554
-
1555
- /**
1556
- * @license
1557
- * storage_impl.ts
1558
- * launcher-kit
1429
+ * @monterosa/sdk-launcher-kit
1559
1430
  *
1560
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-15
1561
- * Copyright © 2023 Monterosa. All rights reserved.
1431
+ * Copyright © 2023 Monterosa Productions Limited. All rights reserved.
1562
1432
  *
1563
1433
  * More details on the license can be found at https://www.monterosa.co/sdk/license
1564
1434
  */
@@ -1625,11 +1495,9 @@ var StorageImpl = /** @class */ (function () {
1625
1495
 
1626
1496
  /**
1627
1497
  * @license
1628
- * storage.ts
1629
- * launcher-kit
1498
+ * @monterosa/sdk-launcher-kit
1630
1499
  *
1631
- * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-15
1632
- * Copyright © 2023 Monterosa. All rights reserved.
1500
+ * Copyright © 2023 Monterosa Productions Limited. All rights reserved.
1633
1501
  *
1634
1502
  * More details on the license can be found at https://www.monterosa.co/sdk/license
1635
1503
  */
@@ -1650,30 +1518,67 @@ var storage = new StorageImpl();
1650
1518
  /**
1651
1519
  * @internal
1652
1520
  */
1653
- function listenStorageMessages(experience) {
1654
- return onSdkMessage(experience, function (message) {
1655
- var payload = {};
1521
+ var unsubs$1 = new Map();
1522
+ /**
1523
+ * @internal
1524
+ */
1525
+ function handleExperienceEmbedded$1(experience) {
1526
+ var unsub = onSdkMessage(experience, function (message) {
1656
1527
  if (!Object.values(exports.StorageAction).includes(message.action)) {
1657
1528
  return;
1658
1529
  }
1659
- switch (message.action) {
1660
- case exports.StorageAction.Read:
1661
- payload = {
1662
- value: storage.getItem(message.payload.key),
1663
- };
1664
- break;
1665
- case exports.StorageAction.Write:
1666
- storage.setItem(message.payload.key, message.payload.value);
1667
- break;
1668
- case exports.StorageAction.Remove:
1669
- storage.removeItem(message.payload.key);
1670
- break;
1671
- case exports.StorageAction.Clear:
1672
- storage.clear();
1673
- break;
1530
+ var _a = message.payload, key = _a.key, value = _a.value;
1531
+ var respond = function (payload) {
1532
+ return respondToSdkMessage(experience, message, payload);
1533
+ };
1534
+ try {
1535
+ switch (message.action) {
1536
+ case exports.StorageAction.Read:
1537
+ if (key === undefined) {
1538
+ throw new Error('Key is required');
1539
+ }
1540
+ respond({
1541
+ key: key,
1542
+ value: storage.getItem(key),
1543
+ });
1544
+ break;
1545
+ case exports.StorageAction.Write:
1546
+ if (key === undefined || value === undefined) {
1547
+ throw new Error('Key and value are required');
1548
+ }
1549
+ storage.setItem(key, value);
1550
+ respond({ key: key });
1551
+ break;
1552
+ case exports.StorageAction.Remove:
1553
+ if (key === undefined) {
1554
+ throw new Error('Key is required');
1555
+ }
1556
+ storage.removeItem(key);
1557
+ respond({ key: key });
1558
+ break;
1559
+ case exports.StorageAction.Clear:
1560
+ storage.clear();
1561
+ respond();
1562
+ break;
1563
+ }
1564
+ }
1565
+ catch (error) {
1566
+ if (error instanceof Error) {
1567
+ respond(__assign(__assign({}, (key !== undefined && { key: key })), { error: error.message }));
1568
+ }
1674
1569
  }
1675
- respondToSdkMessage(experience, message, payload);
1676
1570
  });
1571
+ unsubs$1.set(experience.id, unsub);
1572
+ }
1573
+ /**
1574
+ * @internal
1575
+ */
1576
+ function handleExperienceUnmounted$1(experience) {
1577
+ var unsub = unsubs$1.get(experience.id);
1578
+ if (unsub) {
1579
+ unsub();
1580
+ unsubs$1.delete(experience.id);
1581
+ }
1677
1582
  }
1678
1583
  /**
1679
1584
  * The `setStoragePersistent` function is a simple function that allows to
@@ -1727,6 +1632,9 @@ function storageRead(key) {
1727
1632
  })];
1728
1633
  case 1:
1729
1634
  result = _a.sent();
1635
+ if (result.payload.error !== undefined) {
1636
+ throw new Error(result.payload.error);
1637
+ }
1730
1638
  value = result.payload.value;
1731
1639
  return [3 /*break*/, 3];
1732
1640
  case 2:
@@ -1752,7 +1660,7 @@ function storageRead(key) {
1752
1660
  */
1753
1661
  function storageWrite(key, value) {
1754
1662
  return __awaiter(this, void 0, void 0, function () {
1755
- var parentApp;
1663
+ var parentApp, result;
1756
1664
  return __generator(this, function (_a) {
1757
1665
  switch (_a.label) {
1758
1666
  case 0:
@@ -1763,7 +1671,10 @@ function storageWrite(key, value) {
1763
1671
  value: value,
1764
1672
  })];
1765
1673
  case 1:
1766
- _a.sent();
1674
+ result = _a.sent();
1675
+ if (result.payload.error !== undefined) {
1676
+ throw new Error(result.payload.error);
1677
+ }
1767
1678
  return [3 /*break*/, 3];
1768
1679
  case 2:
1769
1680
  storage.setItem(key, value);
@@ -1787,15 +1698,20 @@ function storageWrite(key, value) {
1787
1698
  */
1788
1699
  function storageRemove(key) {
1789
1700
  return __awaiter(this, void 0, void 0, function () {
1790
- var parentApp;
1701
+ var parentApp, result;
1791
1702
  return __generator(this, function (_a) {
1792
1703
  switch (_a.label) {
1793
1704
  case 0:
1794
1705
  parentApp = getParentApplication();
1795
1706
  if (!(parentApp !== null)) return [3 /*break*/, 2];
1796
- return [4 /*yield*/, sendSdkRequest(parentApp, exports.StorageAction.Remove, { key: key })];
1707
+ return [4 /*yield*/, sendSdkRequest(parentApp, exports.StorageAction.Remove, {
1708
+ key: key,
1709
+ })];
1797
1710
  case 1:
1798
- _a.sent();
1711
+ result = _a.sent();
1712
+ if (result.payload.error !== undefined) {
1713
+ throw new Error(result.payload.error);
1714
+ }
1799
1715
  return [3 /*break*/, 3];
1800
1716
  case 2:
1801
1717
  storage.removeItem(key);
@@ -1817,7 +1733,7 @@ function storageRemove(key) {
1817
1733
  */
1818
1734
  function storageClear() {
1819
1735
  return __awaiter(this, void 0, void 0, function () {
1820
- var parentApp;
1736
+ var parentApp, result;
1821
1737
  return __generator(this, function (_a) {
1822
1738
  switch (_a.label) {
1823
1739
  case 0:
@@ -1825,7 +1741,10 @@ function storageClear() {
1825
1741
  if (!(parentApp !== null)) return [3 /*break*/, 2];
1826
1742
  return [4 /*yield*/, sendSdkRequest(parentApp, exports.StorageAction.Clear)];
1827
1743
  case 1:
1828
- _a.sent();
1744
+ result = _a.sent();
1745
+ if (result.payload.error !== undefined) {
1746
+ throw new Error(result.payload.error);
1747
+ }
1829
1748
  return [3 /*break*/, 3];
1830
1749
  case 2:
1831
1750
  storage.clear();
@@ -1835,24 +1754,330 @@ function storageClear() {
1835
1754
  });
1836
1755
  });
1837
1756
  }
1838
- registerEmbedHook(listenStorageMessages);
1757
+ onExperienceEmbedded(handleExperienceEmbedded$1);
1758
+ onExperienceUnmounted(handleExperienceUnmounted$1);
1759
+
1760
+ /**
1761
+ * @license
1762
+ * @monterosa/sdk-launcher-kit
1763
+ *
1764
+ * Copyright © 2022-2025 Monterosa Productions Limited. All rights reserved.
1765
+ *
1766
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
1767
+ */
1768
+ var ELEMENT_NAME = 'monterosa-experience';
1769
+ var MonterosaExperienceElement = /** @class */ (function (_super) {
1770
+ __extends(MonterosaExperienceElement, _super);
1771
+ function MonterosaExperienceElement() {
1772
+ return _super !== null && _super.apply(this, arguments) || this;
1773
+ }
1774
+ MonterosaExperienceElement.prototype.connectedCallback = function () {
1775
+ return __awaiter(this, void 0, void 0, function () {
1776
+ var host, projectId, autoresizesHeight, hidesHeadersAndFooters, persistentStorage, eventId, experienceUrl, allow, allowFullScreen, parameters, i, attr, paramName, sdk, experience;
1777
+ var _this = this;
1778
+ return __generator(this, function (_a) {
1779
+ host = this.getAttribute('host');
1780
+ if (host === null) {
1781
+ throw new Error('Host attribute is not set for Experience element');
1782
+ }
1783
+ projectId = this.getAttribute('projectId');
1784
+ if (projectId === null) {
1785
+ throw new Error('Project attribute is not set for Experience element');
1786
+ }
1787
+ autoresizesHeight = this.getAttribute('autoresizesHeight') !== null;
1788
+ hidesHeadersAndFooters = this.getAttribute('hidesHeadersAndFooters') !== null;
1789
+ persistentStorage = this.getAttribute('persistentStorage') !== null;
1790
+ eventId = this.getAttribute('eventId') !== null
1791
+ ? this.getAttribute('eventId')
1792
+ : undefined;
1793
+ experienceUrl = this.getAttribute('experienceUrl') !== null
1794
+ ? this.getAttribute('experienceUrl')
1795
+ : undefined;
1796
+ allow = this.getAttribute('allow') !== null
1797
+ ? this.getAttribute('allow')
1798
+ : undefined;
1799
+ allowFullScreen = this.getAttribute('allowFullScreen') !== null;
1800
+ parameters = {};
1801
+ for (i = 0; i < this.attributes.length; i++) {
1802
+ attr = this.attributes[i];
1803
+ if (attr.name.startsWith('param-')) {
1804
+ paramName = attr.name.split('param-')[1];
1805
+ parameters[paramName] = attr.value;
1806
+ }
1807
+ }
1808
+ sdk = sdkCore.configure({
1809
+ host: host,
1810
+ projectId: projectId,
1811
+ }, "".concat(host, "-").concat(projectId));
1812
+ experience = getExperience(sdk, {
1813
+ autoresizesHeight: autoresizesHeight,
1814
+ eventId: eventId,
1815
+ hidesHeadersAndFooters: hidesHeadersAndFooters,
1816
+ experienceUrl: experienceUrl,
1817
+ allow: allow,
1818
+ allowFullScreen: allowFullScreen,
1819
+ parameters: parameters,
1820
+ });
1821
+ this.style.height = '250px';
1822
+ this.style.display = 'block';
1823
+ this.style.position = 'relative';
1824
+ if (persistentStorage) {
1825
+ setStoragePersistent(true);
1826
+ }
1827
+ embed(experience, this);
1828
+ // eslint-disable-next-line
1829
+ onSdkMessage(experience, function (_a) {
1830
+ _a.payload; var action = _a.action;
1831
+ switch (action) {
1832
+ case exports.Action.OnReady:
1833
+ break;
1834
+ case exports.Action.OnResize: {
1835
+ // const { width, height } = payload;
1836
+ break;
1837
+ }
1838
+ case exports.Action.OnUILoaded:
1839
+ _this.dispatchEvent(new CustomEvent('uiloaded', {
1840
+ bubbles: true,
1841
+ cancelable: false,
1842
+ composed: true,
1843
+ }));
1844
+ break;
1845
+ }
1846
+ });
1847
+ return [2 /*return*/];
1848
+ });
1849
+ });
1850
+ };
1851
+ MonterosaExperienceElement.prototype.disconnectedCallback = function () {
1852
+ unmount(this);
1853
+ };
1854
+ return MonterosaExperienceElement;
1855
+ }(HTMLElement));
1856
+ if (!customElements.get(ELEMENT_NAME)) {
1857
+ customElements.define(ELEMENT_NAME, MonterosaExperienceElement);
1858
+ }
1859
+
1860
+ /**
1861
+ * @license
1862
+ * @monterosa/sdk-launcher-kit
1863
+ *
1864
+ * Copyright © 2025 Monterosa Productions Limited. All rights reserved.
1865
+ *
1866
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
1867
+ */
1868
+ var unsubs = new Map();
1869
+ function handleExperienceEmbedded(experience, container) {
1870
+ if (!experience.config.autoresizesHeight) {
1871
+ return;
1872
+ }
1873
+ var unsub = onSdkMessage(experience, function (_a) {
1874
+ var action = _a.action, payload = _a.payload;
1875
+ if (action === exports.Action.OnResize) {
1876
+ /**
1877
+ * Container width is maintained the same as it is defined in the parent
1878
+ * page to preserve its behaviour. Only the height is updated
1879
+ */
1880
+ // container.style.width = `${payload.width}px`;
1881
+ container.style.height = "".concat(payload.height, "px");
1882
+ }
1883
+ });
1884
+ unsubs.set(experience.id, unsub);
1885
+ }
1886
+ function handleExperienceUnmounted(experience) {
1887
+ var unsub = unsubs.get(experience.id);
1888
+ if (unsub) {
1889
+ unsub();
1890
+ unsubs.delete(experience.id);
1891
+ }
1892
+ }
1893
+ onExperienceEmbedded(handleExperienceEmbedded);
1894
+ onExperienceUnmounted(handleExperienceUnmounted);
1895
+
1896
+ /**
1897
+ * @license
1898
+ * @monterosa/sdk-launcher-kit
1899
+ *
1900
+ * Copyright © 2022 Monterosa Productions Limited. All rights reserved.
1901
+ *
1902
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
1903
+ */
1904
+ function getUrlParam(param) {
1905
+ var queryString = {};
1906
+ if (typeof window !== 'undefined') {
1907
+ queryString = window.location.search;
1908
+ }
1909
+ var urlParams = new URLSearchParams(queryString);
1910
+ return urlParams.get(param);
1911
+ }
1912
+ /**
1913
+ * The SDK on the parent application will by default request a child
1914
+ * Experience to hide its header and footer by setting a query parameter called
1915
+ * `micHideHeaderAndFooter` to `1`.
1916
+ *
1917
+ * This function will return true if that is the case, and false otherwise.
1918
+ *
1919
+ * When true, the developer of a child Experience is expected to hide it's headers
1920
+ * and footers as the parent application is actively providing them.
1921
+ *
1922
+ * You can test whether you are respecting this correctly by adding the following query
1923
+ * to your URL:
1924
+ *
1925
+ * "?micHideHeaderAndFooter=1"
1926
+ *
1927
+ * @returns Whether the header and footer views should be hidden.
1928
+ */
1929
+ function shouldHideHeaderAndFooter() {
1930
+ return getUrlParam(exports.QueryParam.HideHeaderAndFooter) === '1';
1931
+ }
1932
+ /**
1933
+ * This function will returns true if experience is embedded in autoresize height mode.
1934
+ */
1935
+ function isAutoresizesHeight() {
1936
+ return getUrlParam(exports.QueryParam.AutoresizesHeight) === '1';
1937
+ }
1938
+ /**
1939
+ * This function is used to notify the parent application that the Experience
1940
+ * is ready to be used. It's intended to be called by the Experience itself and
1941
+ * not by the parent application.
1942
+ *
1943
+ * @example
1944
+ * ```javascript
1945
+ * import { sendReady } from '@monterosa/sdk-launcher-kit';
1946
+ *
1947
+ * sendReady();
1948
+ * ```
1949
+ *
1950
+ * @returns void
1951
+ */
1952
+ function sendReady() {
1953
+ var parentApp = getParentApplication();
1954
+ if (parentApp === null) {
1955
+ console.log('Unable to send ready message, as there is no parent application');
1956
+ return;
1957
+ }
1958
+ sendSdkRequest(parentApp, exports.Action.OnReady);
1959
+ }
1960
+ /**
1961
+ * Sends a message to the SDK of the parent application informing it that
1962
+ * the UI of this Experience has completed loading.
1963
+ *
1964
+ * You should call this method when your UI has completed loading and you are ready to
1965
+ * display data to the user. This can be when your network calls have successfully requested
1966
+ * data and you have updated the DOM for it, or when an error has occurred and you want
1967
+ * to take over the UI to provide details to the user.
1968
+ *
1969
+ * The SDK will use this message to dismiss the loading indicator, allowing a seamless
1970
+ * transition between a native loading UI, into a fully loaded, child Experience.
1971
+ *
1972
+ * If this call is not made, the parent SDK will add a grace period to ensure the web app
1973
+ * has sufficient time to load, and eventually dismiss the loading state, whether Experience
1974
+ * is ready or not, so as to avoid scenarios were a defect leaves an infinite loading state
1975
+ * presented to the user.
1976
+ */
1977
+ function sendFinishedLoadingUI() {
1978
+ var parentApp = getParentApplication();
1979
+ if (parentApp === null) {
1980
+ console.log('Unable to send finished loading UI message, as there is no parent application');
1981
+ return;
1982
+ }
1983
+ sendSdkMessage(parentApp, exports.Action.OnUILoaded);
1984
+ }
1985
+ /**
1986
+ * Adds an observer for when more data is requested by the parent application
1987
+ *
1988
+ * @param callback - The callback that is triggered when a request for more data
1989
+ * is received
1990
+ * @returns The unsubscribe function. When it's called,
1991
+ * the observer will be removed and requests for data will no longer be received
1992
+ */
1993
+ function onMoreDataRequested(callback) {
1994
+ var parentApp = getParentApplication();
1995
+ if (parentApp === null) {
1996
+ console.log('Unable to subscribe to more data event, as there is no parent application');
1997
+ return function () { };
1998
+ }
1999
+ return onSdkMessage(parentApp, function (_a) {
2000
+ var action = _a.action;
2001
+ if (action === exports.Action.OnMoreDataRequested) {
2002
+ callback();
2003
+ }
2004
+ });
2005
+ }
2006
+ /**
2007
+ * Adds an observer for when experience is fully embedded and ready to accept
2008
+ * incoming messages
2009
+ *
2010
+ * @param experience - Experience instance
2011
+ * @param callback - The callback that is triggered when experience is embedded
2012
+ * @returns The unsubscribe function. When it's called, the observer will be
2013
+ * removed and ready event will not be received
2014
+ */
2015
+ function onReady(experience, callback) {
2016
+ return onSdkMessage(experience, function (_a) {
2017
+ var action = _a.action;
2018
+ if (action === exports.Action.OnReady) {
2019
+ callback();
2020
+ }
2021
+ });
2022
+ }
2023
+ /**
2024
+ * @internal
2025
+ */
2026
+ var sendExperienceSizeThrottled = sdkUtil.throttle(function (width, height) {
2027
+ var parentApp = getParentApplication();
2028
+ if (parentApp !== null) {
2029
+ sendSdkMessage(parentApp, exports.Action.OnResize, { width: width, height: height });
2030
+ }
2031
+ }, RESIZE_THROTTLE_TIMEOUT, {
2032
+ leading: true,
2033
+ trailing: true,
2034
+ });
2035
+ /**
2036
+ * Sends the experience size to the parent application.
2037
+ *
2038
+ * @param width - The width of the experience.
2039
+ * @param height - The height of the experience.
2040
+ */
2041
+ function sendExperienceSize(width, height) {
2042
+ sendExperienceSizeThrottled(width, height);
2043
+ }
2044
+ /**
2045
+ * Sets up an observer to watch for the element dimensions change and
2046
+ * automatically reports their changes to the parent application.
2047
+ *
2048
+ * @param element - HTML element whose dimensions need to be watched
2049
+ * @returns The unsubscribe function. When it's called,
2050
+ * the observer will be removed and element dimensions are no longer tracked
2051
+ */
2052
+ function reportExperienceSizeChanges(element) {
2053
+ var observer = new ResizeObserver(function () {
2054
+ var width = Math.max(element.offsetWidth, element.scrollWidth);
2055
+ var height = Math.max(element.offsetHeight, element.scrollHeight);
2056
+ sendExperienceSize(width, height);
2057
+ });
2058
+ observer.observe(element);
2059
+ return function () { return observer.unobserve(element); };
2060
+ }
1839
2061
 
1840
2062
  exports.BRIDGE_VERSION = VERSION$1;
1841
2063
  exports.BridgeImpl = BridgeImpl;
1842
2064
  exports.VERSION = VERSION;
1843
2065
  exports.embed = embed;
2066
+ exports.emitter = emitter;
1844
2067
  exports.enableLogging = enableLogging;
1845
2068
  exports.getBridge = getBridge;
1846
2069
  exports.getExperience = getExperience;
1847
2070
  exports.getParentApplication = getParentApplication;
1848
2071
  exports.getParentBridge = getParentBridge;
2072
+ exports.handleExperienceEmbedded = handleExperienceEmbedded$1;
2073
+ exports.handleExperienceUnmounted = handleExperienceUnmounted$1;
1849
2074
  exports.isAutoresizesHeight = isAutoresizesHeight;
1850
- exports.listenStorageMessages = listenStorageMessages;
2075
+ exports.onExperienceEmbedded = onExperienceEmbedded;
2076
+ exports.onExperienceUnmounted = onExperienceUnmounted;
1851
2077
  exports.onMessage = onMessage;
1852
2078
  exports.onMoreDataRequested = onMoreDataRequested;
1853
2079
  exports.onReady = onReady;
1854
2080
  exports.onSdkMessage = onSdkMessage;
1855
- exports.registerEmbedHook = registerEmbedHook;
1856
2081
  exports.reportExperienceSizeChanges = reportExperienceSizeChanges;
1857
2082
  exports.requestMoreData = requestMoreData;
1858
2083
  exports.respondToMessage = respondToMessage;