@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.
- package/dist/index.cjs.js +561 -336
- package/dist/index.cjs.js.map +1 -1
- package/dist/{index.esm2017.js → index.esm.js} +513 -312
- package/dist/index.esm.js.map +1 -0
- package/dist/src/api.d.ts +23 -9
- package/dist/src/autoresize.d.ts +9 -0
- package/dist/src/child_helpers.d.ts +6 -5
- package/dist/src/constants.d.ts +2 -4
- package/dist/src/custom_element.d.ts +9 -0
- package/dist/src/experience_impl.d.ts +3 -4
- package/dist/src/index.d.ts +4 -4
- package/dist/src/integrations.d.ts +15 -0
- package/dist/src/loader.d.ts +2 -4
- package/dist/src/logger.d.ts +2 -4
- package/dist/src/parent_application.d.ts +2 -4
- package/dist/src/parent_application_impl.d.ts +2 -4
- package/dist/src/storage.d.ts +7 -6
- package/dist/src/storage_impl.d.ts +2 -4
- package/dist/src/types.d.ts +8 -12
- package/dist/src/utils/bridge/api.d.ts +2 -4
- package/dist/src/utils/bridge/bridge_impl.d.ts +4 -4
- package/dist/src/utils/bridge/config.d.ts +2 -4
- package/dist/src/utils/bridge/constants.d.ts +2 -4
- package/dist/src/utils/bridge/helpers.d.ts +2 -4
- package/dist/src/utils/bridge/index.d.ts +2 -4
- package/dist/src/utils/bridge/public_types.d.ts +5 -7
- package/dist/src/utils/bridge/sideeffects.d.ts +2 -4
- package/dist/src/utils/bridge/types.d.ts +2 -4
- package/dist/src/utils/htmlelement-shim.d.ts +8 -0
- package/package.json +20 -14
- package/dist/index.esm2017.js.map +0 -1
- package/dist/index.esm5.js +0 -1837
- package/dist/index.esm5.js.map +0 -1
- package/dist/src/utils/hash.d.ts +0 -19
- package/dist/src/utils/hashable.d.ts +0 -13
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { Logger, Sdk, getSdk, LogLevel } from '@monterosa/sdk-core';
|
|
2
|
-
import { createError, getGlobal, Emitter, subscribe, delay,
|
|
1
|
+
import { Logger, Sdk, getSdk, LogLevel, configure } from '@monterosa/sdk-core';
|
|
2
|
+
import { createError, getGlobal, Emitter, subscribe, delay, checkAvailability, setItem, clear, getItem, removeItem, throttle } from '@monterosa/sdk-util';
|
|
3
3
|
import { v4 } from 'uuid';
|
|
4
4
|
import { fetchListings } from '@monterosa/sdk-interact-kit';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @license
|
|
8
|
-
*
|
|
9
|
-
* launcher-kit
|
|
8
|
+
* @monterosa/sdk-launcher-kit
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
10
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
13
11
|
*
|
|
14
12
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
15
13
|
*/
|
|
@@ -35,11 +33,9 @@ const DEFAULT_HEIGHT = 250;
|
|
|
35
33
|
|
|
36
34
|
/**
|
|
37
35
|
* @license
|
|
38
|
-
*
|
|
39
|
-
* interact-kit
|
|
36
|
+
* @monterosa/sdk-interact-kit
|
|
40
37
|
*
|
|
41
|
-
*
|
|
42
|
-
* Copyright © 2023 Monterosa. All rights reserved.
|
|
38
|
+
* Copyright © 2023 Monterosa Productions Limited. All rights reserved.
|
|
43
39
|
*
|
|
44
40
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
45
41
|
*/
|
|
@@ -47,11 +43,9 @@ const logger = new Logger('@monterosa/sdk-interact-kit');
|
|
|
47
43
|
|
|
48
44
|
/**
|
|
49
45
|
* @license
|
|
50
|
-
*
|
|
51
|
-
* launcher-kit
|
|
46
|
+
* @monterosa/sdk-launcher-kit
|
|
52
47
|
*
|
|
53
|
-
*
|
|
54
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
48
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
55
49
|
*
|
|
56
50
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
57
51
|
*/
|
|
@@ -93,11 +87,9 @@ var Source;
|
|
|
93
87
|
|
|
94
88
|
/**
|
|
95
89
|
* @license
|
|
96
|
-
*
|
|
97
|
-
* launcher-kit
|
|
90
|
+
* @monterosa/sdk-launcher-kit
|
|
98
91
|
*
|
|
99
|
-
*
|
|
100
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
92
|
+
* Copyright © 2022-2024 Monterosa Productions Limited. All rights reserved.
|
|
101
93
|
*
|
|
102
94
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
103
95
|
*/
|
|
@@ -142,11 +134,9 @@ var QueryParam;
|
|
|
142
134
|
|
|
143
135
|
/**
|
|
144
136
|
* @license
|
|
145
|
-
*
|
|
146
|
-
* launcher-kit
|
|
137
|
+
* @monterosa/sdk-launcher-kit
|
|
147
138
|
*
|
|
148
|
-
*
|
|
149
|
-
* Copyright © 2024 Monterosa. All rights reserved.
|
|
139
|
+
* Copyright © 2024 Monterosa Productions Limited. All rights reserved.
|
|
150
140
|
*
|
|
151
141
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
152
142
|
*/
|
|
@@ -189,11 +179,9 @@ const BridgeErrorMessages = {
|
|
|
189
179
|
|
|
190
180
|
/**
|
|
191
181
|
* @license
|
|
192
|
-
*
|
|
193
|
-
* launcher-kit
|
|
182
|
+
* @monterosa/sdk-launcher-kit
|
|
194
183
|
*
|
|
195
|
-
*
|
|
196
|
-
* Copyright © 2024 Monterosa. All rights reserved.
|
|
184
|
+
* Copyright © 2024 Monterosa Productions Limited. All rights reserved.
|
|
197
185
|
*
|
|
198
186
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
199
187
|
*/
|
|
@@ -232,11 +220,9 @@ function setRequestTimeout(newTimeout) {
|
|
|
232
220
|
|
|
233
221
|
/**
|
|
234
222
|
* @license
|
|
235
|
-
*
|
|
236
|
-
* launcher-kit
|
|
223
|
+
* @monterosa/sdk-launcher-kit
|
|
237
224
|
*
|
|
238
|
-
*
|
|
239
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
225
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
240
226
|
*
|
|
241
227
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
242
228
|
*/
|
|
@@ -247,11 +233,9 @@ function isMessage(message) {
|
|
|
247
233
|
|
|
248
234
|
/**
|
|
249
235
|
* @license
|
|
250
|
-
*
|
|
251
|
-
* launcher-kit
|
|
236
|
+
* @monterosa/sdk-launcher-kit
|
|
252
237
|
*
|
|
253
|
-
*
|
|
254
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
238
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
255
239
|
*
|
|
256
240
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
257
241
|
*/
|
|
@@ -309,11 +293,9 @@ if (!globals$2.monterosaSdk.initialised) {
|
|
|
309
293
|
|
|
310
294
|
/**
|
|
311
295
|
* @license
|
|
312
|
-
*
|
|
313
|
-
* launcher-kit
|
|
296
|
+
* @monterosa/sdk-launcher-kit
|
|
314
297
|
*
|
|
315
|
-
*
|
|
316
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
298
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
317
299
|
*
|
|
318
300
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
319
301
|
*/
|
|
@@ -333,11 +315,9 @@ const VERSION$1 = '1.0.0';
|
|
|
333
315
|
|
|
334
316
|
/**
|
|
335
317
|
* @license
|
|
336
|
-
*
|
|
337
|
-
* launcher-kit
|
|
318
|
+
* @monterosa/sdk-launcher-kit
|
|
338
319
|
*
|
|
339
|
-
*
|
|
340
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
320
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
341
321
|
*
|
|
342
322
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
343
323
|
*/
|
|
@@ -349,6 +329,8 @@ class BridgeImpl extends Emitter {
|
|
|
349
329
|
constructor(id = v4()) {
|
|
350
330
|
super();
|
|
351
331
|
this.id = id;
|
|
332
|
+
this.recipientReady = false;
|
|
333
|
+
this.messagesQueue = [];
|
|
352
334
|
globals.monterosaSdk.emitter.on('message', this.handleMessage.bind(this));
|
|
353
335
|
}
|
|
354
336
|
static isMessage(message) {
|
|
@@ -366,10 +348,21 @@ class BridgeImpl extends Emitter {
|
|
|
366
348
|
return document.querySelector(this.iFrameSelector);
|
|
367
349
|
}
|
|
368
350
|
handleMessage(message) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
351
|
+
const { id, bridgeId, action, respondingTo } = message;
|
|
352
|
+
if (bridgeId !== this.id) {
|
|
353
|
+
return;
|
|
372
354
|
}
|
|
355
|
+
logger.log(`Received a ${respondingTo === null ? 'message' : 'response'}`, message);
|
|
356
|
+
if (action === Action.OnReady) {
|
|
357
|
+
this.recipientReady = true;
|
|
358
|
+
if (respondingTo === null) {
|
|
359
|
+
this.send(Action.OnReady, {}, Source.Sdk, id);
|
|
360
|
+
}
|
|
361
|
+
while (this.messagesQueue.length > 0) {
|
|
362
|
+
this.postMessage(this.messagesQueue.shift());
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
this.emit('message', message);
|
|
373
366
|
}
|
|
374
367
|
createMessage(action, payload, sourceName, respondingTo = null) {
|
|
375
368
|
return {
|
|
@@ -385,6 +378,10 @@ class BridgeImpl extends Emitter {
|
|
|
385
378
|
}
|
|
386
379
|
postMessage(message) {
|
|
387
380
|
var _a, _b, _c, _d;
|
|
381
|
+
if (!this.recipientReady && message.action !== Action.OnReady) {
|
|
382
|
+
this.messagesQueue.push(message);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
388
385
|
const json = JSON.stringify(message);
|
|
389
386
|
if (IS_IOS) {
|
|
390
387
|
(_b = (_a = globals.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.monterosaSdk.postMessage(json);
|
|
@@ -416,7 +413,8 @@ class BridgeImpl extends Emitter {
|
|
|
416
413
|
* Start the timeout, when it finishes it should reject Promise.race below
|
|
417
414
|
*/
|
|
418
415
|
const countdown = new Promise((_, reject) => {
|
|
419
|
-
timeoutRef = setTimeout(reject
|
|
416
|
+
timeoutRef = setTimeout(() => reject(new Error(`The request for action '${action}' exceeded the timeout ` +
|
|
417
|
+
`limit of ${timeout}ms and was aborted.`)), timeout);
|
|
420
418
|
});
|
|
421
419
|
/**
|
|
422
420
|
* Start the request and wait for the message with the respondingTo
|
|
@@ -450,11 +448,9 @@ class BridgeImpl extends Emitter {
|
|
|
450
448
|
|
|
451
449
|
/**
|
|
452
450
|
* @license
|
|
453
|
-
*
|
|
454
|
-
* launcher-kit
|
|
451
|
+
* @monterosa/sdk-launcher-kit
|
|
455
452
|
*
|
|
456
|
-
*
|
|
457
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
453
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
458
454
|
*
|
|
459
455
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
460
456
|
*/
|
|
@@ -467,7 +463,7 @@ function getBridge(id) {
|
|
|
467
463
|
if (bridges.has(id)) {
|
|
468
464
|
return bridges.get(id);
|
|
469
465
|
}
|
|
470
|
-
const bridge = new BridgeImpl();
|
|
466
|
+
const bridge = new BridgeImpl(id);
|
|
471
467
|
bridges.set(id, bridge);
|
|
472
468
|
return bridge;
|
|
473
469
|
}
|
|
@@ -648,11 +644,9 @@ function onMessage(bridged, callback) {
|
|
|
648
644
|
|
|
649
645
|
/**
|
|
650
646
|
* @license
|
|
651
|
-
*
|
|
652
|
-
* launcher-kit
|
|
647
|
+
* @monterosa/sdk-launcher-kit
|
|
653
648
|
*
|
|
654
|
-
*
|
|
655
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
649
|
+
* Copyright © 2022-2024 Monterosa Productions Limited. All rights reserved.
|
|
656
650
|
*
|
|
657
651
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
658
652
|
*/
|
|
@@ -663,8 +657,9 @@ class ExperienceImpl {
|
|
|
663
657
|
constructor(sdk, config) {
|
|
664
658
|
this.sdk = sdk;
|
|
665
659
|
this._parameters = {};
|
|
660
|
+
this.id = v4();
|
|
666
661
|
this._config = config;
|
|
667
|
-
this.bridge = getBridge(
|
|
662
|
+
this.bridge = getBridge(this.id);
|
|
668
663
|
if (config.parameters !== undefined) {
|
|
669
664
|
const reserved = Object.values(QueryParam);
|
|
670
665
|
const ignored = [];
|
|
@@ -758,11 +753,37 @@ class ExperienceImpl {
|
|
|
758
753
|
|
|
759
754
|
/**
|
|
760
755
|
* @license
|
|
761
|
-
*
|
|
762
|
-
*
|
|
756
|
+
* @monterosa/sdk-launcher-kit
|
|
757
|
+
*
|
|
758
|
+
* Copyright © 2025 Monterosa Productions Limited. All rights reserved.
|
|
759
|
+
*
|
|
760
|
+
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
761
|
+
*/
|
|
762
|
+
const integrations = new Map();
|
|
763
|
+
function addIntegration(container, integration) {
|
|
764
|
+
integrations.set(container, integration);
|
|
765
|
+
}
|
|
766
|
+
function getIntegration(container) {
|
|
767
|
+
return integrations.get(container);
|
|
768
|
+
}
|
|
769
|
+
function getIntegrations() {
|
|
770
|
+
return Array.from(integrations.values());
|
|
771
|
+
}
|
|
772
|
+
function deleteIntegration(container) {
|
|
773
|
+
integrations.delete(container);
|
|
774
|
+
}
|
|
775
|
+
function hasIntegration(containerOrExperience) {
|
|
776
|
+
if (containerOrExperience instanceof HTMLElement) {
|
|
777
|
+
return integrations.has(containerOrExperience);
|
|
778
|
+
}
|
|
779
|
+
return Array.from(integrations.values()).some((integration) => integration.experience === containerOrExperience);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* @license
|
|
784
|
+
* @monterosa/sdk-launcher-kit
|
|
763
785
|
*
|
|
764
|
-
*
|
|
765
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
786
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
766
787
|
*
|
|
767
788
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
768
789
|
*/
|
|
@@ -951,15 +972,13 @@ function unstashStyles(element) {
|
|
|
951
972
|
element.removeAttribute('data-stash');
|
|
952
973
|
}
|
|
953
974
|
|
|
954
|
-
var version = "0.
|
|
975
|
+
var version = "0.19.0-rc.2";
|
|
955
976
|
|
|
956
977
|
/**
|
|
957
978
|
* @license
|
|
958
|
-
*
|
|
959
|
-
* launcher-kit
|
|
979
|
+
* @monterosa/sdk-launcher-kit
|
|
960
980
|
*
|
|
961
|
-
*
|
|
962
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
981
|
+
* Copyright © 2022-2025 Monterosa Productions Limited. All rights reserved.
|
|
963
982
|
*
|
|
964
983
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
965
984
|
*/
|
|
@@ -969,8 +988,12 @@ var version = "0.18.0";
|
|
|
969
988
|
* @internal
|
|
970
989
|
*/
|
|
971
990
|
const VERSION = version;
|
|
972
|
-
|
|
973
|
-
|
|
991
|
+
/**
|
|
992
|
+
* Event emitter for the launcher kit.
|
|
993
|
+
*
|
|
994
|
+
* @internal
|
|
995
|
+
*/
|
|
996
|
+
const emitter = new Emitter();
|
|
974
997
|
/**
|
|
975
998
|
* Creates an iframe with the provided parameters.
|
|
976
999
|
*
|
|
@@ -1051,21 +1074,6 @@ function getExperience(sdkOrConfig, config) {
|
|
|
1051
1074
|
const experience = new ExperienceImpl(sdk, experienceConfig);
|
|
1052
1075
|
return experience;
|
|
1053
1076
|
}
|
|
1054
|
-
function onResize(experience, container) {
|
|
1055
|
-
if (!experience.config.autoresizesHeight) {
|
|
1056
|
-
return () => { };
|
|
1057
|
-
}
|
|
1058
|
-
return onSdkMessage(experience, ({ action, payload }) => {
|
|
1059
|
-
if (action === Action.OnResize) {
|
|
1060
|
-
/**
|
|
1061
|
-
* Container width is maintained the same as it is defined in the parent
|
|
1062
|
-
* page to preserve its behaviour. Only the height is updated
|
|
1063
|
-
*/
|
|
1064
|
-
// container.style.width = `${payload.width}px`;
|
|
1065
|
-
container.style.height = `${payload.height}px`;
|
|
1066
|
-
}
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
1077
|
function onUILoaded(experience) {
|
|
1070
1078
|
return new Promise((resolve) => {
|
|
1071
1079
|
const unsubscribe = onSdkMessage(experience, ({ action }) => {
|
|
@@ -1076,6 +1084,35 @@ function onUILoaded(experience) {
|
|
|
1076
1084
|
});
|
|
1077
1085
|
});
|
|
1078
1086
|
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Subscribe to the event when Experience is embedded into the container.
|
|
1089
|
+
* Also calls the callback immediately for all currently embedded Experiences.
|
|
1090
|
+
*
|
|
1091
|
+
* @param callback - Callback to be called when Experience is embedded.
|
|
1092
|
+
*/
|
|
1093
|
+
function onExperienceEmbedded(callback) {
|
|
1094
|
+
const integrations = getIntegrations();
|
|
1095
|
+
for (const integration of integrations) {
|
|
1096
|
+
if (integration.embedded) {
|
|
1097
|
+
callback(integration.experience, integration.container);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
emitter.on('embedded', callback);
|
|
1101
|
+
return () => {
|
|
1102
|
+
emitter.off('embedded', callback);
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Subscribe to the event when Experience is unmounted from the container.
|
|
1107
|
+
*
|
|
1108
|
+
* @param callback - Callback to be called when Experience is unmounted.
|
|
1109
|
+
*/
|
|
1110
|
+
function onExperienceUnmounted(callback) {
|
|
1111
|
+
emitter.on('unmounted', callback);
|
|
1112
|
+
return () => {
|
|
1113
|
+
emitter.off('unmounted', callback);
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1079
1116
|
async function experienceReady(experience) {
|
|
1080
1117
|
/**
|
|
1081
1118
|
* Bumper delay during which loading state can't be hidden even
|
|
@@ -1122,27 +1159,30 @@ async function embed(experience, containerOrId) {
|
|
|
1122
1159
|
? containerOrId
|
|
1123
1160
|
: document.getElementById(containerOrId);
|
|
1124
1161
|
if (container === null) {
|
|
1125
|
-
throw new Error(`Container element
|
|
1162
|
+
throw new Error(`Container element "${containerOrId}" not found in DOM. ` +
|
|
1163
|
+
'Please ensure the element exists before calling embed().');
|
|
1126
1164
|
}
|
|
1127
|
-
if (
|
|
1128
|
-
|
|
1165
|
+
if (hasIntegration(container)) {
|
|
1166
|
+
throw new Error('Container already contains an embedded experience. Use unmount() first ' +
|
|
1167
|
+
'to remove the existing experience before embedding a new one.');
|
|
1168
|
+
}
|
|
1169
|
+
if (hasIntegration(experience)) {
|
|
1170
|
+
throw new Error('This experience is already embedded in another container. Use unmount() ' +
|
|
1171
|
+
'to remove it from that container before embedding it into this one.');
|
|
1129
1172
|
}
|
|
1130
1173
|
const controller = new AbortController();
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1174
|
+
const integration = {
|
|
1175
|
+
container,
|
|
1133
1176
|
experience,
|
|
1134
1177
|
controller,
|
|
1135
|
-
|
|
1136
|
-
}
|
|
1178
|
+
embedded: false,
|
|
1179
|
+
};
|
|
1180
|
+
addIntegration(container, integration);
|
|
1137
1181
|
if (experience.config.supportsLoadingState === true) {
|
|
1138
1182
|
// Although showLoader is an asynchronous function, we execute
|
|
1139
1183
|
// it synchronously to embed the iframe as quickly as possible.
|
|
1140
1184
|
show(container, experience.config.loadingTemplate);
|
|
1141
1185
|
}
|
|
1142
|
-
for (const hook of embedHooks) {
|
|
1143
|
-
const unsub = hook(experience, container);
|
|
1144
|
-
hooksUnsubscribe.push(unsub);
|
|
1145
|
-
}
|
|
1146
1186
|
const url = await experience.getUrl();
|
|
1147
1187
|
if (controller.signal.aborted) {
|
|
1148
1188
|
return;
|
|
@@ -1155,6 +1195,8 @@ async function embed(experience, containerOrId) {
|
|
|
1155
1195
|
});
|
|
1156
1196
|
container.appendChild(iframe);
|
|
1157
1197
|
concealIFrame(iframe);
|
|
1198
|
+
integration.embedded = true;
|
|
1199
|
+
emitter.emit('embedded', experience, container);
|
|
1158
1200
|
await experienceReady(experience);
|
|
1159
1201
|
if (controller.signal.aborted) {
|
|
1160
1202
|
return;
|
|
@@ -1182,21 +1224,22 @@ function unmount(containerOrId) {
|
|
|
1182
1224
|
? containerOrId
|
|
1183
1225
|
: document.getElementById(containerOrId);
|
|
1184
1226
|
if (container === null) {
|
|
1185
|
-
throw new Error(`Container element
|
|
1227
|
+
throw new Error(`Container element "${containerOrId}" not found in DOM. ` +
|
|
1228
|
+
'Please ensure the element exists before calling unmount().');
|
|
1186
1229
|
}
|
|
1187
|
-
const integration =
|
|
1230
|
+
const integration = getIntegration(container);
|
|
1188
1231
|
if (!integration) {
|
|
1189
|
-
|
|
1232
|
+
throw new Error(`No experience found embedded in container "${containerOrId}". ` +
|
|
1233
|
+
'Please ensure the experience is embedded before calling unmount().');
|
|
1190
1234
|
}
|
|
1191
1235
|
integration.controller.abort();
|
|
1192
|
-
for (const unsub of integration.hooksUnsubscribe) {
|
|
1193
|
-
unsub();
|
|
1194
|
-
}
|
|
1195
1236
|
while (container.lastElementChild) {
|
|
1196
1237
|
container.removeChild(container.lastElementChild);
|
|
1197
1238
|
}
|
|
1198
|
-
|
|
1239
|
+
integration.embedded = false;
|
|
1240
|
+
deleteIntegration(container);
|
|
1199
1241
|
container.style.height = '';
|
|
1242
|
+
emitter.emit('unmounted', integration.experience, container);
|
|
1200
1243
|
}
|
|
1201
1244
|
/**
|
|
1202
1245
|
* Informs the Experience that more data should be loaded and displayed on the UI.
|
|
@@ -1210,28 +1253,19 @@ function unmount(containerOrId) {
|
|
|
1210
1253
|
function requestMoreData(experience) {
|
|
1211
1254
|
sendSdkMessage(experience, Action.OnMoreDataRequested);
|
|
1212
1255
|
}
|
|
1213
|
-
/**
|
|
1214
|
-
* @internal
|
|
1215
|
-
*/
|
|
1216
|
-
function registerEmbedHook(hook) {
|
|
1217
|
-
embedHooks.push(hook);
|
|
1218
|
-
}
|
|
1219
1256
|
function enableLogging(logLevelOrFlag = true) {
|
|
1220
1257
|
if (typeof logLevelOrFlag === 'boolean') {
|
|
1221
1258
|
logger.logLevel = logLevelOrFlag ? LogLevel.Verbose : LogLevel.Silent;
|
|
1222
1259
|
return;
|
|
1223
1260
|
}
|
|
1224
1261
|
logger.logLevel = logLevelOrFlag;
|
|
1225
|
-
}
|
|
1226
|
-
registerEmbedHook(onResize);
|
|
1262
|
+
}
|
|
1227
1263
|
|
|
1228
1264
|
/**
|
|
1229
1265
|
* @license
|
|
1230
|
-
*
|
|
1231
|
-
* launcher-kit
|
|
1266
|
+
* @monterosa/sdk-launcher-kit
|
|
1232
1267
|
*
|
|
1233
|
-
*
|
|
1234
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
1268
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
1235
1269
|
*
|
|
1236
1270
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1237
1271
|
*/
|
|
@@ -1243,11 +1277,9 @@ class ParentApplicationImpl {
|
|
|
1243
1277
|
|
|
1244
1278
|
/**
|
|
1245
1279
|
* @license
|
|
1246
|
-
*
|
|
1247
|
-
* launcher-kit
|
|
1280
|
+
* @monterosa/sdk-launcher-kit
|
|
1248
1281
|
*
|
|
1249
|
-
*
|
|
1250
|
-
* Copyright © 2023 Monterosa. All rights reserved.
|
|
1282
|
+
* Copyright © 2023 Monterosa Productions Limited. All rights reserved.
|
|
1251
1283
|
*
|
|
1252
1284
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1253
1285
|
*/
|
|
@@ -1273,174 +1305,9 @@ function getParentApplication() {
|
|
|
1273
1305
|
|
|
1274
1306
|
/**
|
|
1275
1307
|
* @license
|
|
1276
|
-
*
|
|
1277
|
-
* launcher-kit
|
|
1308
|
+
* @monterosa/sdk-launcher-kit
|
|
1278
1309
|
*
|
|
1279
|
-
*
|
|
1280
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
1281
|
-
*
|
|
1282
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1283
|
-
*/
|
|
1284
|
-
function getUrlParam(param) {
|
|
1285
|
-
let queryString = {};
|
|
1286
|
-
if (typeof window !== 'undefined') {
|
|
1287
|
-
queryString = window.location.search;
|
|
1288
|
-
}
|
|
1289
|
-
const urlParams = new URLSearchParams(queryString);
|
|
1290
|
-
return urlParams.get(param);
|
|
1291
|
-
}
|
|
1292
|
-
/**
|
|
1293
|
-
* The SDK on the parent application will by default request a child
|
|
1294
|
-
* Experience to hide its header and footer by setting a query parameter called
|
|
1295
|
-
* `micHideHeaderAndFooter` to `1`.
|
|
1296
|
-
*
|
|
1297
|
-
* This function will return true if that is the case, and false otherwise.
|
|
1298
|
-
*
|
|
1299
|
-
* When true, the developer of a child Experience is expected to hide it's headers
|
|
1300
|
-
* and footers as the parent application is actively providing them.
|
|
1301
|
-
*
|
|
1302
|
-
* You can test whether you are respecting this correctly by adding the following query
|
|
1303
|
-
* to your URL:
|
|
1304
|
-
*
|
|
1305
|
-
* "?micHideHeaderAndFooter=1"
|
|
1306
|
-
*
|
|
1307
|
-
* @returns Whether the header and footer views should be hidden.
|
|
1308
|
-
*/
|
|
1309
|
-
function shouldHideHeaderAndFooter() {
|
|
1310
|
-
return getUrlParam(QueryParam.HideHeaderAndFooter) === '1';
|
|
1311
|
-
}
|
|
1312
|
-
/**
|
|
1313
|
-
* This function will returns true if experience is embedded in autoresize height mode.
|
|
1314
|
-
*/
|
|
1315
|
-
function isAutoresizesHeight() {
|
|
1316
|
-
return getUrlParam(QueryParam.AutoresizesHeight) === '1';
|
|
1317
|
-
}
|
|
1318
|
-
/**
|
|
1319
|
-
* This function is used to notify the parent application that the Experience
|
|
1320
|
-
* is ready to be used. It's intended to be called by the Experience itself and
|
|
1321
|
-
* not by the parent application.
|
|
1322
|
-
*
|
|
1323
|
-
* @example
|
|
1324
|
-
* ```javascript
|
|
1325
|
-
* import { sendReady } from '@monterosa/sdk-launcher-kit';
|
|
1326
|
-
*
|
|
1327
|
-
* sendReady();
|
|
1328
|
-
* ```
|
|
1329
|
-
*
|
|
1330
|
-
* @returns void
|
|
1331
|
-
*/
|
|
1332
|
-
function sendReady() {
|
|
1333
|
-
const parentApp = getParentApplication();
|
|
1334
|
-
if (parentApp === null) {
|
|
1335
|
-
console.log('Unable to send finished loading UI message, as there is no parent application');
|
|
1336
|
-
return;
|
|
1337
|
-
}
|
|
1338
|
-
sendSdkMessage(parentApp, Action.OnReady);
|
|
1339
|
-
}
|
|
1340
|
-
/**
|
|
1341
|
-
* Sends a message to the SDK of the parent application informing it that
|
|
1342
|
-
* the UI of this Experience has completed loading.
|
|
1343
|
-
*
|
|
1344
|
-
* You should call this method when your UI has completed loading and you are ready to
|
|
1345
|
-
* display data to the user. This can be when your network calls have successfully requested
|
|
1346
|
-
* data and you have updated the DOM for it, or when an error has occurred and you want
|
|
1347
|
-
* to take over the UI to provide details to the user.
|
|
1348
|
-
*
|
|
1349
|
-
* The SDK will use this message to dismiss the loading indicator, allowing a seamless
|
|
1350
|
-
* transition between a native loading UI, into a fully loaded, child Experience.
|
|
1351
|
-
*
|
|
1352
|
-
* If this call is not made, the parent SDK will add a grace period to ensure the web app
|
|
1353
|
-
* has sufficient time to load, and eventually dismiss the loading state, whether Experience
|
|
1354
|
-
* is ready or not, so as to avoid scenarios were a defect leaves an infinite loading state
|
|
1355
|
-
* presented to the user.
|
|
1356
|
-
*/
|
|
1357
|
-
function sendFinishedLoadingUI() {
|
|
1358
|
-
const parentApp = getParentApplication();
|
|
1359
|
-
if (parentApp === null) {
|
|
1360
|
-
console.log('Unable to send finished loading UI message, as there is no parent application');
|
|
1361
|
-
return;
|
|
1362
|
-
}
|
|
1363
|
-
sendSdkMessage(parentApp, Action.OnUILoaded);
|
|
1364
|
-
}
|
|
1365
|
-
/**
|
|
1366
|
-
* Adds an observer for when more data is requested by the parent application
|
|
1367
|
-
*
|
|
1368
|
-
* @param callback - The callback that is triggered when a request for more data
|
|
1369
|
-
* is received
|
|
1370
|
-
* @returns The unsubscribe function. When it's called,
|
|
1371
|
-
* the observer will be removed and requests for data will no longer be received
|
|
1372
|
-
*/
|
|
1373
|
-
function onMoreDataRequested(callback) {
|
|
1374
|
-
const parentApp = getParentApplication();
|
|
1375
|
-
if (parentApp === null) {
|
|
1376
|
-
console.log('Unable to subscribe to more data event, as there is no parent application');
|
|
1377
|
-
return () => { };
|
|
1378
|
-
}
|
|
1379
|
-
return onSdkMessage(parentApp, ({ action }) => {
|
|
1380
|
-
if (action === Action.OnMoreDataRequested) {
|
|
1381
|
-
callback();
|
|
1382
|
-
}
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* Adds an observer for when experience is fully embedded and ready to accept
|
|
1387
|
-
* incoming messages
|
|
1388
|
-
*
|
|
1389
|
-
* @param experience - Experience instance
|
|
1390
|
-
* @param callback - The callback that is triggered when experience is embedded
|
|
1391
|
-
* @returns The unsubscribe function. When it's called, the observer will be
|
|
1392
|
-
* removed and ready event will not be received
|
|
1393
|
-
*/
|
|
1394
|
-
function onReady(experience, callback) {
|
|
1395
|
-
return onSdkMessage(experience, ({ action }) => {
|
|
1396
|
-
if (action === Action.OnReady) {
|
|
1397
|
-
callback();
|
|
1398
|
-
}
|
|
1399
|
-
});
|
|
1400
|
-
}
|
|
1401
|
-
/**
|
|
1402
|
-
* @internal
|
|
1403
|
-
*/
|
|
1404
|
-
const sendExperienceSizeThrottled = throttle((width, height) => {
|
|
1405
|
-
const parentApp = getParentApplication();
|
|
1406
|
-
if (parentApp === null)
|
|
1407
|
-
return;
|
|
1408
|
-
sendSdkMessage(parentApp, Action.OnResize, { width, height });
|
|
1409
|
-
}, RESIZE_THROTTLE_TIMEOUT, {
|
|
1410
|
-
leading: true,
|
|
1411
|
-
trailing: true,
|
|
1412
|
-
});
|
|
1413
|
-
/**
|
|
1414
|
-
* @internal
|
|
1415
|
-
*/
|
|
1416
|
-
function sendExperienceSize(width, height) {
|
|
1417
|
-
return sendExperienceSizeThrottled(width, height);
|
|
1418
|
-
}
|
|
1419
|
-
/**
|
|
1420
|
-
* Sets up an observer to watch for the element dimensions change and
|
|
1421
|
-
* automatically reports their changes to the parent application.
|
|
1422
|
-
*
|
|
1423
|
-
* @param element - HTML element whose dimensions need to be watched
|
|
1424
|
-
* @returns The unsubscribe function. When it's called,
|
|
1425
|
-
* the observer will be removed and element dimensions are no longer tracked
|
|
1426
|
-
*/
|
|
1427
|
-
function reportExperienceSizeChanges(element) {
|
|
1428
|
-
const observer = new ResizeObserver(() => {
|
|
1429
|
-
const width = Math.max(element.offsetWidth, element.scrollWidth);
|
|
1430
|
-
const height = Math.max(element.offsetHeight, element.scrollHeight);
|
|
1431
|
-
sendExperienceSize(width, height);
|
|
1432
|
-
});
|
|
1433
|
-
observer.observe(element);
|
|
1434
|
-
return () => observer.unobserve(element);
|
|
1435
|
-
}
|
|
1436
|
-
|
|
1437
|
-
/**
|
|
1438
|
-
* @license
|
|
1439
|
-
* storage_impl.ts
|
|
1440
|
-
* launcher-kit
|
|
1441
|
-
*
|
|
1442
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-15
|
|
1443
|
-
* Copyright © 2023 Monterosa. All rights reserved.
|
|
1310
|
+
* Copyright © 2023 Monterosa Productions Limited. All rights reserved.
|
|
1444
1311
|
*
|
|
1445
1312
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1446
1313
|
*/
|
|
@@ -1501,11 +1368,9 @@ class StorageImpl {
|
|
|
1501
1368
|
|
|
1502
1369
|
/**
|
|
1503
1370
|
* @license
|
|
1504
|
-
*
|
|
1505
|
-
* launcher-kit
|
|
1371
|
+
* @monterosa/sdk-launcher-kit
|
|
1506
1372
|
*
|
|
1507
|
-
*
|
|
1508
|
-
* Copyright © 2023 Monterosa. All rights reserved.
|
|
1373
|
+
* Copyright © 2023 Monterosa Productions Limited. All rights reserved.
|
|
1509
1374
|
*
|
|
1510
1375
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1511
1376
|
*/
|
|
@@ -1526,30 +1391,65 @@ const storage = new StorageImpl();
|
|
|
1526
1391
|
/**
|
|
1527
1392
|
* @internal
|
|
1528
1393
|
*/
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1394
|
+
const unsubs$1 = new Map();
|
|
1395
|
+
/**
|
|
1396
|
+
* @internal
|
|
1397
|
+
*/
|
|
1398
|
+
function handleExperienceEmbedded$1(experience) {
|
|
1399
|
+
const unsub = onSdkMessage(experience, (message) => {
|
|
1532
1400
|
if (!Object.values(StorageAction).includes(message.action)) {
|
|
1533
1401
|
return;
|
|
1534
1402
|
}
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1403
|
+
const { key, value } = message.payload;
|
|
1404
|
+
const respond = (payload) => respondToSdkMessage(experience, message, payload);
|
|
1405
|
+
try {
|
|
1406
|
+
switch (message.action) {
|
|
1407
|
+
case StorageAction.Read:
|
|
1408
|
+
if (key === undefined) {
|
|
1409
|
+
throw new Error('Key is required');
|
|
1410
|
+
}
|
|
1411
|
+
respond({
|
|
1412
|
+
key,
|
|
1413
|
+
value: storage.getItem(key),
|
|
1414
|
+
});
|
|
1415
|
+
break;
|
|
1416
|
+
case StorageAction.Write:
|
|
1417
|
+
if (key === undefined || value === undefined) {
|
|
1418
|
+
throw new Error('Key and value are required');
|
|
1419
|
+
}
|
|
1420
|
+
storage.setItem(key, value);
|
|
1421
|
+
respond({ key });
|
|
1422
|
+
break;
|
|
1423
|
+
case StorageAction.Remove:
|
|
1424
|
+
if (key === undefined) {
|
|
1425
|
+
throw new Error('Key is required');
|
|
1426
|
+
}
|
|
1427
|
+
storage.removeItem(key);
|
|
1428
|
+
respond({ key });
|
|
1429
|
+
break;
|
|
1430
|
+
case StorageAction.Clear:
|
|
1431
|
+
storage.clear();
|
|
1432
|
+
respond();
|
|
1433
|
+
break;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
catch (error) {
|
|
1437
|
+
if (error instanceof Error) {
|
|
1438
|
+
respond(Object.assign(Object.assign({}, (key !== undefined && { key })), { error: error.message }));
|
|
1439
|
+
}
|
|
1550
1440
|
}
|
|
1551
|
-
respondToSdkMessage(experience, message, payload);
|
|
1552
1441
|
});
|
|
1442
|
+
unsubs$1.set(experience.id, unsub);
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* @internal
|
|
1446
|
+
*/
|
|
1447
|
+
function handleExperienceUnmounted$1(experience) {
|
|
1448
|
+
const unsub = unsubs$1.get(experience.id);
|
|
1449
|
+
if (unsub) {
|
|
1450
|
+
unsub();
|
|
1451
|
+
unsubs$1.delete(experience.id);
|
|
1452
|
+
}
|
|
1553
1453
|
}
|
|
1554
1454
|
/**
|
|
1555
1455
|
* The `setStoragePersistent` function is a simple function that allows to
|
|
@@ -1596,6 +1496,9 @@ async function storageRead(key) {
|
|
|
1596
1496
|
const result = await sendSdkRequest(parentApp, StorageAction.Read, {
|
|
1597
1497
|
key,
|
|
1598
1498
|
});
|
|
1499
|
+
if (result.payload.error !== undefined) {
|
|
1500
|
+
throw new Error(result.payload.error);
|
|
1501
|
+
}
|
|
1599
1502
|
value = result.payload.value;
|
|
1600
1503
|
}
|
|
1601
1504
|
else {
|
|
@@ -1619,10 +1522,13 @@ async function storageRead(key) {
|
|
|
1619
1522
|
async function storageWrite(key, value) {
|
|
1620
1523
|
const parentApp = getParentApplication();
|
|
1621
1524
|
if (parentApp !== null) {
|
|
1622
|
-
await sendSdkRequest(parentApp, StorageAction.Write, {
|
|
1525
|
+
const result = await sendSdkRequest(parentApp, StorageAction.Write, {
|
|
1623
1526
|
key,
|
|
1624
1527
|
value,
|
|
1625
1528
|
});
|
|
1529
|
+
if (result.payload.error !== undefined) {
|
|
1530
|
+
throw new Error(result.payload.error);
|
|
1531
|
+
}
|
|
1626
1532
|
}
|
|
1627
1533
|
else {
|
|
1628
1534
|
storage.setItem(key, value);
|
|
@@ -1644,7 +1550,12 @@ async function storageWrite(key, value) {
|
|
|
1644
1550
|
async function storageRemove(key) {
|
|
1645
1551
|
const parentApp = getParentApplication();
|
|
1646
1552
|
if (parentApp !== null) {
|
|
1647
|
-
await sendSdkRequest(parentApp, StorageAction.Remove, {
|
|
1553
|
+
const result = await sendSdkRequest(parentApp, StorageAction.Remove, {
|
|
1554
|
+
key,
|
|
1555
|
+
});
|
|
1556
|
+
if (result.payload.error !== undefined) {
|
|
1557
|
+
throw new Error(result.payload.error);
|
|
1558
|
+
}
|
|
1648
1559
|
}
|
|
1649
1560
|
else {
|
|
1650
1561
|
storage.removeItem(key);
|
|
@@ -1664,14 +1575,304 @@ async function storageRemove(key) {
|
|
|
1664
1575
|
async function storageClear() {
|
|
1665
1576
|
const parentApp = getParentApplication();
|
|
1666
1577
|
if (parentApp !== null) {
|
|
1667
|
-
await sendSdkRequest(parentApp, StorageAction.Clear);
|
|
1578
|
+
const result = await sendSdkRequest(parentApp, StorageAction.Clear);
|
|
1579
|
+
if (result.payload.error !== undefined) {
|
|
1580
|
+
throw new Error(result.payload.error);
|
|
1581
|
+
}
|
|
1668
1582
|
}
|
|
1669
1583
|
else {
|
|
1670
1584
|
storage.clear();
|
|
1671
1585
|
}
|
|
1672
1586
|
return Promise.resolve();
|
|
1673
1587
|
}
|
|
1674
|
-
|
|
1588
|
+
onExperienceEmbedded(handleExperienceEmbedded$1);
|
|
1589
|
+
onExperienceUnmounted(handleExperienceUnmounted$1);
|
|
1590
|
+
|
|
1591
|
+
/**
|
|
1592
|
+
* @license
|
|
1593
|
+
* @monterosa/sdk-launcher-kit
|
|
1594
|
+
*
|
|
1595
|
+
* Copyright © 2022-2025 Monterosa Productions Limited. All rights reserved.
|
|
1596
|
+
*
|
|
1597
|
+
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1598
|
+
*/
|
|
1599
|
+
const ELEMENT_NAME = 'monterosa-experience';
|
|
1600
|
+
class MonterosaExperienceElement extends HTMLElement {
|
|
1601
|
+
async connectedCallback() {
|
|
1602
|
+
const host = this.getAttribute('host');
|
|
1603
|
+
if (host === null) {
|
|
1604
|
+
throw new Error('Host attribute is not set for Experience element');
|
|
1605
|
+
}
|
|
1606
|
+
const projectId = this.getAttribute('projectId');
|
|
1607
|
+
if (projectId === null) {
|
|
1608
|
+
throw new Error('Project attribute is not set for Experience element');
|
|
1609
|
+
}
|
|
1610
|
+
const autoresizesHeight = this.getAttribute('autoresizesHeight') !== null;
|
|
1611
|
+
const hidesHeadersAndFooters = this.getAttribute('hidesHeadersAndFooters') !== null;
|
|
1612
|
+
const persistentStorage = this.getAttribute('persistentStorage') !== null;
|
|
1613
|
+
const eventId = this.getAttribute('eventId') !== null
|
|
1614
|
+
? this.getAttribute('eventId')
|
|
1615
|
+
: undefined;
|
|
1616
|
+
const experienceUrl = this.getAttribute('experienceUrl') !== null
|
|
1617
|
+
? this.getAttribute('experienceUrl')
|
|
1618
|
+
: undefined;
|
|
1619
|
+
const allow = this.getAttribute('allow') !== null
|
|
1620
|
+
? this.getAttribute('allow')
|
|
1621
|
+
: undefined;
|
|
1622
|
+
const allowFullScreen = this.getAttribute('allowFullScreen') !== null;
|
|
1623
|
+
const parameters = {};
|
|
1624
|
+
for (let i = 0; i < this.attributes.length; i++) {
|
|
1625
|
+
const attr = this.attributes[i];
|
|
1626
|
+
if (attr.name.startsWith('param-')) {
|
|
1627
|
+
const paramName = attr.name.split('param-')[1];
|
|
1628
|
+
parameters[paramName] = attr.value;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
const sdk = configure({
|
|
1632
|
+
host,
|
|
1633
|
+
projectId,
|
|
1634
|
+
}, `${host}-${projectId}`);
|
|
1635
|
+
const experience = getExperience(sdk, {
|
|
1636
|
+
autoresizesHeight,
|
|
1637
|
+
eventId,
|
|
1638
|
+
hidesHeadersAndFooters,
|
|
1639
|
+
experienceUrl,
|
|
1640
|
+
allow,
|
|
1641
|
+
allowFullScreen,
|
|
1642
|
+
parameters,
|
|
1643
|
+
});
|
|
1644
|
+
this.style.height = '250px';
|
|
1645
|
+
this.style.display = 'block';
|
|
1646
|
+
this.style.position = 'relative';
|
|
1647
|
+
if (persistentStorage) {
|
|
1648
|
+
setStoragePersistent(true);
|
|
1649
|
+
}
|
|
1650
|
+
embed(experience, this);
|
|
1651
|
+
// eslint-disable-next-line
|
|
1652
|
+
onSdkMessage(experience, ({ payload, action }) => {
|
|
1653
|
+
switch (action) {
|
|
1654
|
+
case Action.OnReady:
|
|
1655
|
+
break;
|
|
1656
|
+
case Action.OnResize: {
|
|
1657
|
+
// const { width, height } = payload;
|
|
1658
|
+
break;
|
|
1659
|
+
}
|
|
1660
|
+
case Action.OnUILoaded:
|
|
1661
|
+
this.dispatchEvent(new CustomEvent('uiloaded', {
|
|
1662
|
+
bubbles: true,
|
|
1663
|
+
cancelable: false,
|
|
1664
|
+
composed: true,
|
|
1665
|
+
}));
|
|
1666
|
+
break;
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
disconnectedCallback() {
|
|
1671
|
+
unmount(this);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
if (!customElements.get(ELEMENT_NAME)) {
|
|
1675
|
+
customElements.define(ELEMENT_NAME, MonterosaExperienceElement);
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
/**
|
|
1679
|
+
* @license
|
|
1680
|
+
* @monterosa/sdk-launcher-kit
|
|
1681
|
+
*
|
|
1682
|
+
* Copyright © 2025 Monterosa Productions Limited. All rights reserved.
|
|
1683
|
+
*
|
|
1684
|
+
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1685
|
+
*/
|
|
1686
|
+
const unsubs = new Map();
|
|
1687
|
+
function handleExperienceEmbedded(experience, container) {
|
|
1688
|
+
if (!experience.config.autoresizesHeight) {
|
|
1689
|
+
return;
|
|
1690
|
+
}
|
|
1691
|
+
const unsub = onSdkMessage(experience, ({ action, payload }) => {
|
|
1692
|
+
if (action === Action.OnResize) {
|
|
1693
|
+
/**
|
|
1694
|
+
* Container width is maintained the same as it is defined in the parent
|
|
1695
|
+
* page to preserve its behaviour. Only the height is updated
|
|
1696
|
+
*/
|
|
1697
|
+
// container.style.width = `${payload.width}px`;
|
|
1698
|
+
container.style.height = `${payload.height}px`;
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
unsubs.set(experience.id, unsub);
|
|
1702
|
+
}
|
|
1703
|
+
function handleExperienceUnmounted(experience) {
|
|
1704
|
+
const unsub = unsubs.get(experience.id);
|
|
1705
|
+
if (unsub) {
|
|
1706
|
+
unsub();
|
|
1707
|
+
unsubs.delete(experience.id);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
onExperienceEmbedded(handleExperienceEmbedded);
|
|
1711
|
+
onExperienceUnmounted(handleExperienceUnmounted);
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* @license
|
|
1715
|
+
* @monterosa/sdk-launcher-kit
|
|
1716
|
+
*
|
|
1717
|
+
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
1718
|
+
*
|
|
1719
|
+
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1720
|
+
*/
|
|
1721
|
+
function getUrlParam(param) {
|
|
1722
|
+
let queryString = {};
|
|
1723
|
+
if (typeof window !== 'undefined') {
|
|
1724
|
+
queryString = window.location.search;
|
|
1725
|
+
}
|
|
1726
|
+
const urlParams = new URLSearchParams(queryString);
|
|
1727
|
+
return urlParams.get(param);
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* The SDK on the parent application will by default request a child
|
|
1731
|
+
* Experience to hide its header and footer by setting a query parameter called
|
|
1732
|
+
* `micHideHeaderAndFooter` to `1`.
|
|
1733
|
+
*
|
|
1734
|
+
* This function will return true if that is the case, and false otherwise.
|
|
1735
|
+
*
|
|
1736
|
+
* When true, the developer of a child Experience is expected to hide it's headers
|
|
1737
|
+
* and footers as the parent application is actively providing them.
|
|
1738
|
+
*
|
|
1739
|
+
* You can test whether you are respecting this correctly by adding the following query
|
|
1740
|
+
* to your URL:
|
|
1741
|
+
*
|
|
1742
|
+
* "?micHideHeaderAndFooter=1"
|
|
1743
|
+
*
|
|
1744
|
+
* @returns Whether the header and footer views should be hidden.
|
|
1745
|
+
*/
|
|
1746
|
+
function shouldHideHeaderAndFooter() {
|
|
1747
|
+
return getUrlParam(QueryParam.HideHeaderAndFooter) === '1';
|
|
1748
|
+
}
|
|
1749
|
+
/**
|
|
1750
|
+
* This function will returns true if experience is embedded in autoresize height mode.
|
|
1751
|
+
*/
|
|
1752
|
+
function isAutoresizesHeight() {
|
|
1753
|
+
return getUrlParam(QueryParam.AutoresizesHeight) === '1';
|
|
1754
|
+
}
|
|
1755
|
+
/**
|
|
1756
|
+
* This function is used to notify the parent application that the Experience
|
|
1757
|
+
* is ready to be used. It's intended to be called by the Experience itself and
|
|
1758
|
+
* not by the parent application.
|
|
1759
|
+
*
|
|
1760
|
+
* @example
|
|
1761
|
+
* ```javascript
|
|
1762
|
+
* import { sendReady } from '@monterosa/sdk-launcher-kit';
|
|
1763
|
+
*
|
|
1764
|
+
* sendReady();
|
|
1765
|
+
* ```
|
|
1766
|
+
*
|
|
1767
|
+
* @returns void
|
|
1768
|
+
*/
|
|
1769
|
+
function sendReady() {
|
|
1770
|
+
const parentApp = getParentApplication();
|
|
1771
|
+
if (parentApp === null) {
|
|
1772
|
+
console.log('Unable to send ready message, as there is no parent application');
|
|
1773
|
+
return;
|
|
1774
|
+
}
|
|
1775
|
+
sendSdkRequest(parentApp, Action.OnReady);
|
|
1776
|
+
}
|
|
1777
|
+
/**
|
|
1778
|
+
* Sends a message to the SDK of the parent application informing it that
|
|
1779
|
+
* the UI of this Experience has completed loading.
|
|
1780
|
+
*
|
|
1781
|
+
* You should call this method when your UI has completed loading and you are ready to
|
|
1782
|
+
* display data to the user. This can be when your network calls have successfully requested
|
|
1783
|
+
* data and you have updated the DOM for it, or when an error has occurred and you want
|
|
1784
|
+
* to take over the UI to provide details to the user.
|
|
1785
|
+
*
|
|
1786
|
+
* The SDK will use this message to dismiss the loading indicator, allowing a seamless
|
|
1787
|
+
* transition between a native loading UI, into a fully loaded, child Experience.
|
|
1788
|
+
*
|
|
1789
|
+
* If this call is not made, the parent SDK will add a grace period to ensure the web app
|
|
1790
|
+
* has sufficient time to load, and eventually dismiss the loading state, whether Experience
|
|
1791
|
+
* is ready or not, so as to avoid scenarios were a defect leaves an infinite loading state
|
|
1792
|
+
* presented to the user.
|
|
1793
|
+
*/
|
|
1794
|
+
function sendFinishedLoadingUI() {
|
|
1795
|
+
const parentApp = getParentApplication();
|
|
1796
|
+
if (parentApp === null) {
|
|
1797
|
+
console.log('Unable to send finished loading UI message, as there is no parent application');
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
sendSdkMessage(parentApp, Action.OnUILoaded);
|
|
1801
|
+
}
|
|
1802
|
+
/**
|
|
1803
|
+
* Adds an observer for when more data is requested by the parent application
|
|
1804
|
+
*
|
|
1805
|
+
* @param callback - The callback that is triggered when a request for more data
|
|
1806
|
+
* is received
|
|
1807
|
+
* @returns The unsubscribe function. When it's called,
|
|
1808
|
+
* the observer will be removed and requests for data will no longer be received
|
|
1809
|
+
*/
|
|
1810
|
+
function onMoreDataRequested(callback) {
|
|
1811
|
+
const parentApp = getParentApplication();
|
|
1812
|
+
if (parentApp === null) {
|
|
1813
|
+
console.log('Unable to subscribe to more data event, as there is no parent application');
|
|
1814
|
+
return () => { };
|
|
1815
|
+
}
|
|
1816
|
+
return onSdkMessage(parentApp, ({ action }) => {
|
|
1817
|
+
if (action === Action.OnMoreDataRequested) {
|
|
1818
|
+
callback();
|
|
1819
|
+
}
|
|
1820
|
+
});
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Adds an observer for when experience is fully embedded and ready to accept
|
|
1824
|
+
* incoming messages
|
|
1825
|
+
*
|
|
1826
|
+
* @param experience - Experience instance
|
|
1827
|
+
* @param callback - The callback that is triggered when experience is embedded
|
|
1828
|
+
* @returns The unsubscribe function. When it's called, the observer will be
|
|
1829
|
+
* removed and ready event will not be received
|
|
1830
|
+
*/
|
|
1831
|
+
function onReady(experience, callback) {
|
|
1832
|
+
return onSdkMessage(experience, ({ action }) => {
|
|
1833
|
+
if (action === Action.OnReady) {
|
|
1834
|
+
callback();
|
|
1835
|
+
}
|
|
1836
|
+
});
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* @internal
|
|
1840
|
+
*/
|
|
1841
|
+
const sendExperienceSizeThrottled = throttle((width, height) => {
|
|
1842
|
+
const parentApp = getParentApplication();
|
|
1843
|
+
if (parentApp !== null) {
|
|
1844
|
+
sendSdkMessage(parentApp, Action.OnResize, { width, height });
|
|
1845
|
+
}
|
|
1846
|
+
}, RESIZE_THROTTLE_TIMEOUT, {
|
|
1847
|
+
leading: true,
|
|
1848
|
+
trailing: true,
|
|
1849
|
+
});
|
|
1850
|
+
/**
|
|
1851
|
+
* Sends the experience size to the parent application.
|
|
1852
|
+
*
|
|
1853
|
+
* @param width - The width of the experience.
|
|
1854
|
+
* @param height - The height of the experience.
|
|
1855
|
+
*/
|
|
1856
|
+
function sendExperienceSize(width, height) {
|
|
1857
|
+
sendExperienceSizeThrottled(width, height);
|
|
1858
|
+
}
|
|
1859
|
+
/**
|
|
1860
|
+
* Sets up an observer to watch for the element dimensions change and
|
|
1861
|
+
* automatically reports their changes to the parent application.
|
|
1862
|
+
*
|
|
1863
|
+
* @param element - HTML element whose dimensions need to be watched
|
|
1864
|
+
* @returns The unsubscribe function. When it's called,
|
|
1865
|
+
* the observer will be removed and element dimensions are no longer tracked
|
|
1866
|
+
*/
|
|
1867
|
+
function reportExperienceSizeChanges(element) {
|
|
1868
|
+
const observer = new ResizeObserver(() => {
|
|
1869
|
+
const width = Math.max(element.offsetWidth, element.scrollWidth);
|
|
1870
|
+
const height = Math.max(element.offsetHeight, element.scrollHeight);
|
|
1871
|
+
sendExperienceSize(width, height);
|
|
1872
|
+
});
|
|
1873
|
+
observer.observe(element);
|
|
1874
|
+
return () => observer.unobserve(element);
|
|
1875
|
+
}
|
|
1675
1876
|
|
|
1676
|
-
export { Action, VERSION$1 as BRIDGE_VERSION, BridgeError, BridgeImpl, QueryParam, Source, StorageAction, VERSION, embed, enableLogging, getBridge, getExperience, getParentApplication, getParentBridge, isAutoresizesHeight,
|
|
1677
|
-
//# sourceMappingURL=index.
|
|
1877
|
+
export { Action, VERSION$1 as BRIDGE_VERSION, BridgeError, BridgeImpl, QueryParam, Source, StorageAction, VERSION, embed, emitter, enableLogging, getBridge, getExperience, getParentApplication, getParentBridge, handleExperienceEmbedded$1 as handleExperienceEmbedded, handleExperienceUnmounted$1 as handleExperienceUnmounted, isAutoresizesHeight, onExperienceEmbedded, onExperienceUnmounted, onMessage, onMoreDataRequested, onReady, onSdkMessage, reportExperienceSizeChanges, requestMoreData, respondToMessage, respondToSdkMessage, sendExperienceSize, sendExperienceSizeThrottled, sendFinishedLoadingUI, sendMessage, sendReady, sendRequest, sendSdkMessage, sendSdkRequest, setRequestTimeout, setStoragePersistent, shouldHideHeaderAndFooter, storage, storageClear, storageRead, storageRemove, storageWrite, unmount };
|
|
1878
|
+
//# sourceMappingURL=index.esm.js.map
|