@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
package/dist/index.esm5.js
DELETED
|
@@ -1,1837 +0,0 @@
|
|
|
1
|
-
import { Logger, Sdk, getSdk, LogLevel } from '@monterosa/sdk-core';
|
|
2
|
-
import { createError, getGlobal, Emitter, subscribe, delay, throttle, setItem, clear, getItem, removeItem, checkAvailability } from '@monterosa/sdk-util';
|
|
3
|
-
import { v4 } from 'uuid';
|
|
4
|
-
import { fetchListings } from '@monterosa/sdk-interact-kit';
|
|
5
|
-
|
|
6
|
-
/*! *****************************************************************************
|
|
7
|
-
Copyright (c) Microsoft Corporation.
|
|
8
|
-
|
|
9
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
-
purpose with or without fee is hereby granted.
|
|
11
|
-
|
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
-
***************************************************************************** */
|
|
20
|
-
/* global Reflect, Promise */
|
|
21
|
-
|
|
22
|
-
var extendStatics = function(d, b) {
|
|
23
|
-
extendStatics = Object.setPrototypeOf ||
|
|
24
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
25
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
26
|
-
return extendStatics(d, b);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
function __extends(d, b) {
|
|
30
|
-
if (typeof b !== "function" && b !== null)
|
|
31
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
32
|
-
extendStatics(d, b);
|
|
33
|
-
function __() { this.constructor = d; }
|
|
34
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
var __assign = function() {
|
|
38
|
-
__assign = Object.assign || function __assign(t) {
|
|
39
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
40
|
-
s = arguments[i];
|
|
41
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
42
|
-
}
|
|
43
|
-
return t;
|
|
44
|
-
};
|
|
45
|
-
return __assign.apply(this, arguments);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
49
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
50
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
51
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
52
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
53
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
54
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function __generator(thisArg, body) {
|
|
59
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
60
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
61
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
62
|
-
function step(op) {
|
|
63
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
64
|
-
while (_) try {
|
|
65
|
-
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;
|
|
66
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
67
|
-
switch (op[0]) {
|
|
68
|
-
case 0: case 1: t = op; break;
|
|
69
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
70
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
71
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
72
|
-
default:
|
|
73
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
74
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
75
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
76
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
77
|
-
if (t[2]) _.ops.pop();
|
|
78
|
-
_.trys.pop(); continue;
|
|
79
|
-
}
|
|
80
|
-
op = body.call(thisArg, _);
|
|
81
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
82
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* @license
|
|
88
|
-
* constants.ts
|
|
89
|
-
* launcher-kit
|
|
90
|
-
*
|
|
91
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-15
|
|
92
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
93
|
-
*
|
|
94
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
95
|
-
*/
|
|
96
|
-
var RESIZE_THROTTLE_TIMEOUT = 25;
|
|
97
|
-
/**
|
|
98
|
-
* Duration of the loader fade IN/OUT animation
|
|
99
|
-
*/
|
|
100
|
-
var LOADER_ANIMATION_DURATION = 750;
|
|
101
|
-
/**
|
|
102
|
-
* Final cut off timeout for the loader after which it will be hidden even
|
|
103
|
-
* though Experience UI may ne not yet ready
|
|
104
|
-
*/
|
|
105
|
-
var LOADER_TIMEOUT = 5000;
|
|
106
|
-
/**
|
|
107
|
-
* Bumper timeout during which the loader still visible even though Experience
|
|
108
|
-
* UI may be ready
|
|
109
|
-
*
|
|
110
|
-
* (!) At the moment its value is 0 as loader has a fade in effect what already
|
|
111
|
-
* adds a small bumper delay before Experience is injected on the page
|
|
112
|
-
*/
|
|
113
|
-
var LOADER_BUMPER_TIMEOUT = 0;
|
|
114
|
-
var DEFAULT_HEIGHT = 250;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @license
|
|
118
|
-
* logger.ts
|
|
119
|
-
* interact-kit
|
|
120
|
-
*
|
|
121
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-05-23
|
|
122
|
-
* Copyright © 2023 Monterosa. All rights reserved.
|
|
123
|
-
*
|
|
124
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
125
|
-
*/
|
|
126
|
-
var logger = new Logger('@monterosa/sdk-interact-kit');
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @license
|
|
130
|
-
* public_types.ts
|
|
131
|
-
* launcher-kit
|
|
132
|
-
*
|
|
133
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
|
|
134
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
135
|
-
*
|
|
136
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
137
|
-
*/
|
|
138
|
-
/**
|
|
139
|
-
* A list of possible actions in communications between
|
|
140
|
-
* parent application and child Experience
|
|
141
|
-
*
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
144
|
-
var Action;
|
|
145
|
-
(function (Action) {
|
|
146
|
-
/**
|
|
147
|
-
* Notifies that communication channel is ready and
|
|
148
|
-
* messages can be {@link sendSdkMessage | sent}
|
|
149
|
-
*/
|
|
150
|
-
Action["OnReady"] = "onBridgeReady";
|
|
151
|
-
/**
|
|
152
|
-
* Notifies that intrisic size of child Experience has changed
|
|
153
|
-
*/
|
|
154
|
-
Action["OnResize"] = "onIntrinsicSizeChanged";
|
|
155
|
-
/**
|
|
156
|
-
* Notifies that UI of child Experience is loaded.
|
|
157
|
-
* When this action is fired the loader will be hidden
|
|
158
|
-
*/
|
|
159
|
-
Action["OnUILoaded"] = "onUILoaded";
|
|
160
|
-
/**
|
|
161
|
-
* Notifies child Experience about the request to load more data
|
|
162
|
-
*/
|
|
163
|
-
Action["OnMoreDataRequested"] = "onMoreDataRequested";
|
|
164
|
-
})(Action || (Action = {}));
|
|
165
|
-
/**
|
|
166
|
-
* @internal
|
|
167
|
-
*/
|
|
168
|
-
var Source;
|
|
169
|
-
(function (Source) {
|
|
170
|
-
Source["Sdk"] = "sdk";
|
|
171
|
-
Source["User"] = "user";
|
|
172
|
-
})(Source || (Source = {}));
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @license
|
|
176
|
-
* types.ts
|
|
177
|
-
* launcher-kit
|
|
178
|
-
*
|
|
179
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-01-19
|
|
180
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
181
|
-
*
|
|
182
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
183
|
-
*/
|
|
184
|
-
/**
|
|
185
|
-
* Reserved query parameter names for controlling the behaviour of Experience.
|
|
186
|
-
*/
|
|
187
|
-
var QueryParam;
|
|
188
|
-
(function (QueryParam) {
|
|
189
|
-
/**
|
|
190
|
-
* Represents the host of the application. This parameter is added by Studio
|
|
191
|
-
* and the embed URL already contains it.
|
|
192
|
-
*/
|
|
193
|
-
QueryParam["Host"] = "h";
|
|
194
|
-
/**
|
|
195
|
-
* Represents the Project Id of the application. This parameter is added by
|
|
196
|
-
* Studio and the embed URL already contains it.
|
|
197
|
-
*/
|
|
198
|
-
QueryParam["Project"] = "p";
|
|
199
|
-
/**
|
|
200
|
-
* Represents the Event Id of the application. This parameter is added to the
|
|
201
|
-
* experience URL when the eventId is provided in the experience config.
|
|
202
|
-
*/
|
|
203
|
-
QueryParam["Event"] = "e";
|
|
204
|
-
/**
|
|
205
|
-
* Used to identify the unique ID of the communication bridge between
|
|
206
|
-
* the parent application and the child experience.
|
|
207
|
-
*/
|
|
208
|
-
QueryParam["BridgeId"] = "micBridgeId";
|
|
209
|
-
/**
|
|
210
|
-
* Determines whether the header and footer views of the application should be
|
|
211
|
-
* hidden. This parameter can be used to control the visibility of the
|
|
212
|
-
* application's header and footer components.
|
|
213
|
-
*/
|
|
214
|
-
QueryParam["HideHeaderAndFooter"] = "micHideHeaderAndFooter";
|
|
215
|
-
/**
|
|
216
|
-
* Determines whether autoresize is enabled for the application. When autoresize
|
|
217
|
-
* is enabled, the application's height will adjust automatically based on its
|
|
218
|
-
* content.
|
|
219
|
-
*/
|
|
220
|
-
QueryParam["AutoresizesHeight"] = "micAutoresizesHeight";
|
|
221
|
-
})(QueryParam || (QueryParam = {}));
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* @license
|
|
225
|
-
* types.ts
|
|
226
|
-
* launcher-kit
|
|
227
|
-
*
|
|
228
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2024-01-02
|
|
229
|
-
* Copyright © 2024 Monterosa. All rights reserved.
|
|
230
|
-
*
|
|
231
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
232
|
-
*/
|
|
233
|
-
var _a$2;
|
|
234
|
-
/**
|
|
235
|
-
* Defines a set of error codes that may be encountered when using the
|
|
236
|
-
* Launcher Kit bridge
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* ```javascript
|
|
240
|
-
* try {
|
|
241
|
-
* // some code that uses the LauncherKit's bridge
|
|
242
|
-
* } catch (err) {
|
|
243
|
-
* if (err.code === BridgeError.InvalidRequestTimeoutError) {
|
|
244
|
-
* // handle invalid request timeout error
|
|
245
|
-
* } else {
|
|
246
|
-
* // handle other error types
|
|
247
|
-
* }
|
|
248
|
-
* }
|
|
249
|
-
* ```
|
|
250
|
-
*
|
|
251
|
-
* @remarks
|
|
252
|
-
* - The `BridgeError` enum provides a convenient way to handle errors
|
|
253
|
-
* encountered when using the `LauncherKit` module. By checking the code
|
|
254
|
-
* property of the caught error against the values of the enum, the error
|
|
255
|
-
* type can be determined and appropriate action taken.
|
|
256
|
-
*
|
|
257
|
-
* - The `BridgeError` enum is not intended to be instantiated or extended.
|
|
258
|
-
*/
|
|
259
|
-
var BridgeError;
|
|
260
|
-
(function (BridgeError) {
|
|
261
|
-
/**
|
|
262
|
-
* Indicates an error occurred due to an invalid timeout value being provided.
|
|
263
|
-
* This error is thrown when the specified timeout is not a positive number.
|
|
264
|
-
*/
|
|
265
|
-
BridgeError["InvalidRequestTimeoutError"] = "invalid_request_timeout_error";
|
|
266
|
-
})(BridgeError || (BridgeError = {}));
|
|
267
|
-
var BridgeErrorMessages = (_a$2 = {},
|
|
268
|
-
_a$2[BridgeError.InvalidRequestTimeoutError] = function () {
|
|
269
|
-
return 'Request timeout must be greater than 0';
|
|
270
|
-
},
|
|
271
|
-
_a$2);
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* @license
|
|
275
|
-
* config.ts
|
|
276
|
-
* launcher-kit
|
|
277
|
-
*
|
|
278
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2024-01-02
|
|
279
|
-
* Copyright © 2024 Monterosa. All rights reserved.
|
|
280
|
-
*
|
|
281
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
282
|
-
*/
|
|
283
|
-
/**
|
|
284
|
-
* @internal
|
|
285
|
-
*/
|
|
286
|
-
var Config = {
|
|
287
|
-
requestTimeout: 20000,
|
|
288
|
-
};
|
|
289
|
-
/**
|
|
290
|
-
* Sets a new timeout value for requests (default is 20_000 mseconds).
|
|
291
|
-
*
|
|
292
|
-
* This function updates the request timeout in the application's configuration.
|
|
293
|
-
* It ensures that the new timeout value is a positive number, and throws
|
|
294
|
-
* an error if the value is non-positive.
|
|
295
|
-
*
|
|
296
|
-
* @param newTimeout - The new timeout value in milliseconds. Must be
|
|
297
|
-
* a positive number.
|
|
298
|
-
*
|
|
299
|
-
* @throws
|
|
300
|
-
* Throws {@link BridgeError | BridgeError.InvalidRequestTimeoutError}
|
|
301
|
-
* if `newTimeout` is less than or equal to 0.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* ```javascript
|
|
305
|
-
* // Set the request timeout to 3000 milliseconds
|
|
306
|
-
* setRequestTimeout(3000);
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
function setRequestTimeout(newTimeout) {
|
|
310
|
-
if (newTimeout <= 0) {
|
|
311
|
-
throw createError(BridgeError.InvalidRequestTimeoutError, BridgeErrorMessages);
|
|
312
|
-
}
|
|
313
|
-
Config.requestTimeout = newTimeout;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* @license
|
|
318
|
-
* helpers.ts
|
|
319
|
-
* launcher-kit
|
|
320
|
-
*
|
|
321
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
|
|
322
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
323
|
-
*
|
|
324
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
325
|
-
*/
|
|
326
|
-
function isMessage(message) {
|
|
327
|
-
return (message instanceof Object &&
|
|
328
|
-
Object.prototype.hasOwnProperty.call(message, 'bridgeId'));
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* @license
|
|
333
|
-
* sideeffect.ts
|
|
334
|
-
* launcher-kit
|
|
335
|
-
*
|
|
336
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
|
|
337
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
338
|
-
*
|
|
339
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
340
|
-
*/
|
|
341
|
-
var _a$1, _b$1, _c$1, _d$1;
|
|
342
|
-
var _e, _f, _g;
|
|
343
|
-
var globals$2 = getGlobal();
|
|
344
|
-
var receiveMessage = function (message) {
|
|
345
|
-
if (!isMessage(message)) {
|
|
346
|
-
// data does not match message format
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
globals$2.monterosaSdk.emitter.emit('message', message);
|
|
350
|
-
};
|
|
351
|
-
function handleWindowMessage(_a) {
|
|
352
|
-
var data = _a.data;
|
|
353
|
-
try {
|
|
354
|
-
if (typeof data !== 'string') {
|
|
355
|
-
// ignore non string data
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
var message = JSON.parse(data);
|
|
359
|
-
receiveMessage(message);
|
|
360
|
-
}
|
|
361
|
-
catch (err) {
|
|
362
|
-
if (err instanceof Error) {
|
|
363
|
-
console.error(err.message);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Since this code operates as a side effect while updating the global space,
|
|
369
|
-
* we must be very careful because it may run twice, for example, when two apps
|
|
370
|
-
* using the SDK run on the same page. Additionally, the global namespace may
|
|
371
|
-
* already be updated by the Android or iOS SDKs.
|
|
372
|
-
*/
|
|
373
|
-
// The Monterosa SDK namespace may already exist, either because it was created
|
|
374
|
-
// by a native SDK or by another web app using the JS SDK from the same scope.
|
|
375
|
-
(_a$1 = globals$2.monterosaSdk) !== null && _a$1 !== void 0 ? _a$1 : (globals$2.monterosaSdk = {
|
|
376
|
-
initialised: false,
|
|
377
|
-
emitter: new Emitter(),
|
|
378
|
-
receiveMessage: receiveMessage,
|
|
379
|
-
});
|
|
380
|
-
// Each of nullish coalescing assignments will only be applied when
|
|
381
|
-
// the Monterosa SDK namespace exists at that moment and one of its properties
|
|
382
|
-
// is not defined.
|
|
383
|
-
(_b$1 = (_e = globals$2.monterosaSdk).initialised) !== null && _b$1 !== void 0 ? _b$1 : (_e.initialised = false);
|
|
384
|
-
(_c$1 = (_f = globals$2.monterosaSdk).emitter) !== null && _c$1 !== void 0 ? _c$1 : (_f.emitter = new Emitter());
|
|
385
|
-
(_d$1 = (_g = globals$2.monterosaSdk).receiveMessage) !== null && _d$1 !== void 0 ? _d$1 : (_g.receiveMessage = receiveMessage);
|
|
386
|
-
if (!globals$2.monterosaSdk.initialised) {
|
|
387
|
-
// Subscribe to the message only once for each app that uses the SDK on this page.
|
|
388
|
-
if (typeof globals$2.addEventListener !== 'undefined') {
|
|
389
|
-
globals$2.addEventListener('message', handleWindowMessage);
|
|
390
|
-
}
|
|
391
|
-
globals$2.monterosaSdk.initialised = true;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* @license
|
|
396
|
-
* constants.ts
|
|
397
|
-
* launcher-kit
|
|
398
|
-
*
|
|
399
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
|
|
400
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
401
|
-
*
|
|
402
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
403
|
-
*/
|
|
404
|
-
var _a, _b, _c, _d;
|
|
405
|
-
var globals$1 = getGlobal();
|
|
406
|
-
/**
|
|
407
|
-
* @internal
|
|
408
|
-
*/
|
|
409
|
-
var IFRAME_ID_PREFIX = 'micBridge';
|
|
410
|
-
var IS_IOS = !!((_c = (_b = (_a = globals$1.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.monterosaSdk) === null || _c === void 0 ? void 0 : _c.postMessage);
|
|
411
|
-
var IS_ANDROID = !!((_d = globals$1.monterosaSdk) === null || _d === void 0 ? void 0 : _d.postMessage);
|
|
412
|
-
var IS_WEB = globals$1.self !== globals$1.parent;
|
|
413
|
-
/**
|
|
414
|
-
* @internal
|
|
415
|
-
*/
|
|
416
|
-
var VERSION$1 = '1.0.0';
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* @license
|
|
420
|
-
* bridge_impl.ts
|
|
421
|
-
* launcher-kit
|
|
422
|
-
*
|
|
423
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
|
|
424
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
425
|
-
*
|
|
426
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
427
|
-
*/
|
|
428
|
-
var globals = getGlobal();
|
|
429
|
-
/**
|
|
430
|
-
* @internal
|
|
431
|
-
*/
|
|
432
|
-
var BridgeImpl = /** @class */ (function (_super) {
|
|
433
|
-
__extends(BridgeImpl, _super);
|
|
434
|
-
function BridgeImpl(id) {
|
|
435
|
-
if (id === void 0) { id = v4(); }
|
|
436
|
-
var _this = _super.call(this) || this;
|
|
437
|
-
_this.id = id;
|
|
438
|
-
globals.monterosaSdk.emitter.on('message', _this.handleMessage.bind(_this));
|
|
439
|
-
return _this;
|
|
440
|
-
}
|
|
441
|
-
BridgeImpl.isMessage = function (message) {
|
|
442
|
-
return (message instanceof Object &&
|
|
443
|
-
Object.prototype.hasOwnProperty.call(message, 'bridgeId') &&
|
|
444
|
-
Object.prototype.hasOwnProperty.call(message, 'action'));
|
|
445
|
-
};
|
|
446
|
-
Object.defineProperty(BridgeImpl.prototype, "iFrameId", {
|
|
447
|
-
get: function () {
|
|
448
|
-
return IFRAME_ID_PREFIX + "-" + this.id;
|
|
449
|
-
},
|
|
450
|
-
enumerable: false,
|
|
451
|
-
configurable: true
|
|
452
|
-
});
|
|
453
|
-
Object.defineProperty(BridgeImpl.prototype, "iFrameSelector", {
|
|
454
|
-
get: function () {
|
|
455
|
-
return "iframe#" + this.iFrameId;
|
|
456
|
-
},
|
|
457
|
-
enumerable: false,
|
|
458
|
-
configurable: true
|
|
459
|
-
});
|
|
460
|
-
Object.defineProperty(BridgeImpl.prototype, "childIFrame", {
|
|
461
|
-
get: function () {
|
|
462
|
-
return document.querySelector(this.iFrameSelector);
|
|
463
|
-
},
|
|
464
|
-
enumerable: false,
|
|
465
|
-
configurable: true
|
|
466
|
-
});
|
|
467
|
-
BridgeImpl.prototype.handleMessage = function (message) {
|
|
468
|
-
if (message.bridgeId === this.id) {
|
|
469
|
-
logger.log("Received a " + (message.respondingTo === null ? 'message' : 'response'), message);
|
|
470
|
-
this.emit('message', message);
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
BridgeImpl.prototype.createMessage = function (action, payload, sourceName, respondingTo) {
|
|
474
|
-
if (respondingTo === void 0) { respondingTo = null; }
|
|
475
|
-
return {
|
|
476
|
-
id: v4(),
|
|
477
|
-
respondingTo: respondingTo,
|
|
478
|
-
action: action,
|
|
479
|
-
sourceName: sourceName,
|
|
480
|
-
bridgeId: this.id,
|
|
481
|
-
payload: payload,
|
|
482
|
-
version: VERSION$1,
|
|
483
|
-
timestamp: Date.now(),
|
|
484
|
-
};
|
|
485
|
-
};
|
|
486
|
-
BridgeImpl.prototype.postMessage = function (message) {
|
|
487
|
-
var _a, _b, _c, _d;
|
|
488
|
-
var json = JSON.stringify(message);
|
|
489
|
-
if (IS_IOS) {
|
|
490
|
-
(_b = (_a = globals.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.monterosaSdk.postMessage(json);
|
|
491
|
-
}
|
|
492
|
-
if (IS_ANDROID) {
|
|
493
|
-
if ((_c = globals.monterosaSdk) === null || _c === void 0 ? void 0 : _c.postMessage) {
|
|
494
|
-
globals.monterosaSdk.postMessage(json);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
if (IS_WEB) {
|
|
498
|
-
globals.parent.postMessage(json, '*');
|
|
499
|
-
}
|
|
500
|
-
if (this.childIFrame) {
|
|
501
|
-
(_d = this.childIFrame.contentWindow) === null || _d === void 0 ? void 0 : _d.postMessage(json, '*');
|
|
502
|
-
}
|
|
503
|
-
};
|
|
504
|
-
BridgeImpl.prototype.send = function (action, payload, sourceName, respondingTo) {
|
|
505
|
-
if (payload === void 0) { payload = {}; }
|
|
506
|
-
if (sourceName === void 0) { sourceName = Source.Sdk; }
|
|
507
|
-
var message = this.createMessage(action, payload, sourceName, respondingTo);
|
|
508
|
-
logger.log("Sending a " + (message.respondingTo === null ? 'message' : 'response'), message);
|
|
509
|
-
this.postMessage(message);
|
|
510
|
-
return message;
|
|
511
|
-
};
|
|
512
|
-
BridgeImpl.prototype.request = function (action, payload, timeout, sourceName) {
|
|
513
|
-
if (payload === void 0) { payload = {}; }
|
|
514
|
-
if (timeout === void 0) { timeout = Config.requestTimeout; }
|
|
515
|
-
if (sourceName === void 0) { sourceName = Source.Sdk; }
|
|
516
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
517
|
-
var timeoutRef, handler, message, countdown, request;
|
|
518
|
-
var _this = this;
|
|
519
|
-
return __generator(this, function (_a) {
|
|
520
|
-
message = this.createMessage(action, payload, sourceName);
|
|
521
|
-
logger.log('Sending a request', message);
|
|
522
|
-
countdown = new Promise(function (_, reject) {
|
|
523
|
-
timeoutRef = setTimeout(reject, timeout);
|
|
524
|
-
});
|
|
525
|
-
request = new Promise(function (resolve) {
|
|
526
|
-
handler = function (responseMessage) {
|
|
527
|
-
if (responseMessage.respondingTo === message.id) {
|
|
528
|
-
resolve(responseMessage);
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
globals.monterosaSdk.emitter.on('message', handler);
|
|
532
|
-
_this.postMessage(message);
|
|
533
|
-
});
|
|
534
|
-
/**
|
|
535
|
-
* Start race between timeout and request
|
|
536
|
-
* - if timeout wins the promise will be rejected
|
|
537
|
-
* - if request wins then Message will be resolved
|
|
538
|
-
*/
|
|
539
|
-
return [2 /*return*/, (Promise.race([countdown, request])
|
|
540
|
-
/**
|
|
541
|
-
* As the matter of clean up we need to clear timeout id
|
|
542
|
-
* and unsubscribe from the message event
|
|
543
|
-
*/
|
|
544
|
-
.finally(function () {
|
|
545
|
-
clearTimeout(timeoutRef);
|
|
546
|
-
globals.monterosaSdk.emitter.off('message', handler);
|
|
547
|
-
}))];
|
|
548
|
-
});
|
|
549
|
-
});
|
|
550
|
-
};
|
|
551
|
-
return BridgeImpl;
|
|
552
|
-
}(Emitter));
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* @license
|
|
556
|
-
* api.ts
|
|
557
|
-
* launcher-kit
|
|
558
|
-
*
|
|
559
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
|
|
560
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
561
|
-
*
|
|
562
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
563
|
-
*/
|
|
564
|
-
var parentBridge;
|
|
565
|
-
var bridges = new Map();
|
|
566
|
-
/**
|
|
567
|
-
* @internal
|
|
568
|
-
*/
|
|
569
|
-
function getBridge(id) {
|
|
570
|
-
if (bridges.has(id)) {
|
|
571
|
-
return bridges.get(id);
|
|
572
|
-
}
|
|
573
|
-
var bridge = new BridgeImpl();
|
|
574
|
-
bridges.set(id, bridge);
|
|
575
|
-
return bridge;
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* @internal
|
|
579
|
-
*/
|
|
580
|
-
function getParentBridge() {
|
|
581
|
-
if (typeof window === 'undefined') {
|
|
582
|
-
return null;
|
|
583
|
-
}
|
|
584
|
-
if (parentBridge !== undefined) {
|
|
585
|
-
return parentBridge;
|
|
586
|
-
}
|
|
587
|
-
var url = new URL(window.location.href);
|
|
588
|
-
var bridgeId = url.searchParams.get(QueryParam.BridgeId);
|
|
589
|
-
if (bridgeId === null) {
|
|
590
|
-
return null;
|
|
591
|
-
}
|
|
592
|
-
parentBridge = new BridgeImpl(bridgeId);
|
|
593
|
-
return parentBridge;
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* @internal
|
|
597
|
-
*/
|
|
598
|
-
function sendSdkMessage(bridged, action, payload) {
|
|
599
|
-
if (payload === void 0) { payload = {}; }
|
|
600
|
-
return bridged.bridge.send(action, payload, Source.Sdk);
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
* This function allows to send a simple message with action name and payload to
|
|
604
|
-
* a recipient which can be either parent application (from Experience to parent
|
|
605
|
-
* application) or child Experience (from parent page to Experience).
|
|
606
|
-
*
|
|
607
|
-
* @remarks
|
|
608
|
-
* Usage example in parent application:
|
|
609
|
-
*
|
|
610
|
-
* @example
|
|
611
|
-
* ```typescript
|
|
612
|
-
* const experience = getExperience();
|
|
613
|
-
*
|
|
614
|
-
* // message to Experience can be sent only when its ready
|
|
615
|
-
* onUILoaded(experience, async () => {
|
|
616
|
-
* sendMessage(
|
|
617
|
-
* experience,
|
|
618
|
-
* 'my_action',
|
|
619
|
-
* { key: 'value' }
|
|
620
|
-
* );
|
|
621
|
-
* });
|
|
622
|
-
*
|
|
623
|
-
* embed(experience);
|
|
624
|
-
* ```
|
|
625
|
-
*
|
|
626
|
-
* Usage example in child Experience:
|
|
627
|
-
*
|
|
628
|
-
* @example
|
|
629
|
-
* ```typescript
|
|
630
|
-
* const parentApp = getParentApplication();
|
|
631
|
-
*
|
|
632
|
-
* if (parentApp !== null) {
|
|
633
|
-
* sendMessage(
|
|
634
|
-
* parentApp,
|
|
635
|
-
* 'my_action',
|
|
636
|
-
* { key: 'value' }
|
|
637
|
-
* );
|
|
638
|
-
* }
|
|
639
|
-
* ```
|
|
640
|
-
*
|
|
641
|
-
* @param bridged - Instance of either {@link ParentApplication} or {@link Experience}
|
|
642
|
-
* @param action - Arbitrary action name that defines purpose of the message
|
|
643
|
-
* @param payload - A key-value object that is sent in a message
|
|
644
|
-
* @returns Returns {@link Message | message}
|
|
645
|
-
*/
|
|
646
|
-
function sendMessage(bridged, action, payload) {
|
|
647
|
-
if (payload === void 0) { payload = {}; }
|
|
648
|
-
return bridged.bridge.send(action, payload, Source.User);
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* @internal
|
|
652
|
-
*/
|
|
653
|
-
function sendSdkRequest(bridged, action, payload, timeout) {
|
|
654
|
-
if (payload === void 0) { payload = {}; }
|
|
655
|
-
if (timeout === void 0) { timeout = Config.requestTimeout; }
|
|
656
|
-
return bridged.bridge.request(action, payload, timeout, Source.Sdk);
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* This function allows to send a request with action name and payload to
|
|
660
|
-
* a recipient which can be either parent application (from Experience to parent
|
|
661
|
-
* application) or child Experience (from parent page to Experience). It is similar
|
|
662
|
-
* to {@link sendMessage} with only one difference is that it returns a Promise which
|
|
663
|
-
* resolves if the recipient response with {@link respondToMessage}. Otherwise it
|
|
664
|
-
* will rejects after a certain timeout.
|
|
665
|
-
*
|
|
666
|
-
* @remarks
|
|
667
|
-
* Usage example in parent application:
|
|
668
|
-
*
|
|
669
|
-
* @example
|
|
670
|
-
* ```typescript
|
|
671
|
-
* const experience = getExperience();
|
|
672
|
-
*
|
|
673
|
-
* // request to Experience can be sent only when its ready
|
|
674
|
-
* onUILoaded(experience, async () => {
|
|
675
|
-
* const response = await sendRequest(
|
|
676
|
-
* experience,
|
|
677
|
-
* 'my_action',
|
|
678
|
-
* { key: 'value' }
|
|
679
|
-
* );
|
|
680
|
-
*
|
|
681
|
-
* console.log(response);
|
|
682
|
-
* });
|
|
683
|
-
*
|
|
684
|
-
* embed(experience);
|
|
685
|
-
* ```
|
|
686
|
-
*
|
|
687
|
-
* Usage example in child Experience:
|
|
688
|
-
*
|
|
689
|
-
* @example
|
|
690
|
-
* ```typescript
|
|
691
|
-
* const parentApp = getParentApplication();
|
|
692
|
-
*
|
|
693
|
-
* // parent application can be null if Experience is running stand alone
|
|
694
|
-
* if (parentApp !== null) {
|
|
695
|
-
* const response = await sendRequest(
|
|
696
|
-
* parentApp,
|
|
697
|
-
* 'my_action',
|
|
698
|
-
* { key: 'value' }
|
|
699
|
-
* );
|
|
700
|
-
*
|
|
701
|
-
* console.log(response);
|
|
702
|
-
* }
|
|
703
|
-
* ```
|
|
704
|
-
*
|
|
705
|
-
* @param bridged - Instance of either {@link ParentApplication} or {@link Experience}
|
|
706
|
-
* @param action - Arbitrary action name that defines purpose of the message
|
|
707
|
-
* @param payload - A key-value object that is sent as in request
|
|
708
|
-
* @param timeout - Configurable request timeout, if there is no response by
|
|
709
|
-
* the end of this timeout then returned Promise will be rejected.
|
|
710
|
-
*/
|
|
711
|
-
function sendRequest(bridged, action, payload, timeout) {
|
|
712
|
-
if (payload === void 0) { payload = {}; }
|
|
713
|
-
if (timeout === void 0) { timeout = Config.requestTimeout; }
|
|
714
|
-
return bridged.bridge.request(action, payload, timeout, Source.User);
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
* @internal
|
|
718
|
-
*/
|
|
719
|
-
function respondToSdkMessage(bridged, message, payload) {
|
|
720
|
-
if (payload === void 0) { payload = {}; }
|
|
721
|
-
bridged.bridge.send(message.action, payload, Source.Sdk, message.id);
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
* Respond to a received message. It is used to reply to a
|
|
725
|
-
* {@link sendRequest | user request}.
|
|
726
|
-
*
|
|
727
|
-
* @param bridged - Instance of either {@link ParentApplication} or {@link Experience}
|
|
728
|
-
* @param message - {@link Message | Message} to respond to
|
|
729
|
-
* @param payload - A key-value object that is sent as in response
|
|
730
|
-
*/
|
|
731
|
-
function respondToMessage(bridged, message, payload) {
|
|
732
|
-
if (payload === void 0) { payload = {}; }
|
|
733
|
-
bridged.bridge.send(message.action, payload, Source.User, message.id);
|
|
734
|
-
}
|
|
735
|
-
function onMessageFunc(bridged, source, callback) {
|
|
736
|
-
return subscribe(bridged.bridge, 'message', function (message) {
|
|
737
|
-
if (message.sourceName === source) {
|
|
738
|
-
callback(message);
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
/**
|
|
743
|
-
* @internal
|
|
744
|
-
*/
|
|
745
|
-
function onSdkMessage(bridged, callback) {
|
|
746
|
-
return onMessageFunc(bridged, Source.Sdk, callback);
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* Adds an observer for when user message is received
|
|
750
|
-
*
|
|
751
|
-
* @param bridged - Instance of either {@link ParentApplication} or {@link Experience}
|
|
752
|
-
* @param callback - The callback that is triggered when user message is received
|
|
753
|
-
* @returns The unsubscribe function. When it's called,
|
|
754
|
-
* the observer will be removed and user messages will no longer be received
|
|
755
|
-
*/
|
|
756
|
-
function onMessage(bridged, callback) {
|
|
757
|
-
return onMessageFunc(bridged, Source.User, callback);
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
/**
|
|
761
|
-
* @license
|
|
762
|
-
* experience_impl.ts
|
|
763
|
-
* launcher-kit
|
|
764
|
-
*
|
|
765
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-01-19
|
|
766
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
767
|
-
*
|
|
768
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
769
|
-
*/
|
|
770
|
-
/**
|
|
771
|
-
* @internal
|
|
772
|
-
*/
|
|
773
|
-
var ExperienceImpl = /** @class */ (function () {
|
|
774
|
-
function ExperienceImpl(sdk, config) {
|
|
775
|
-
var _this = this;
|
|
776
|
-
this.sdk = sdk;
|
|
777
|
-
this._parameters = {};
|
|
778
|
-
this._config = config;
|
|
779
|
-
this.bridge = getBridge(v4());
|
|
780
|
-
if (config.parameters !== undefined) {
|
|
781
|
-
var reserved_1 = Object.values(QueryParam);
|
|
782
|
-
var ignored_1 = [];
|
|
783
|
-
Object.entries(config.parameters).forEach(function (_a) {
|
|
784
|
-
var key = _a[0], value = _a[1];
|
|
785
|
-
if (reserved_1.includes(key)) {
|
|
786
|
-
ignored_1.push(key);
|
|
787
|
-
}
|
|
788
|
-
else {
|
|
789
|
-
_this._parameters[key] = value;
|
|
790
|
-
}
|
|
791
|
-
});
|
|
792
|
-
if (ignored_1.length === 1) {
|
|
793
|
-
console.warn("Parameter \"" + ignored_1[0] + "\" ignored as it matches reserved words");
|
|
794
|
-
}
|
|
795
|
-
if (ignored_1.length > 1) {
|
|
796
|
-
console.warn("Parameters \"" + ignored_1.join('", "') + "\" ignored as they match reserved words");
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
Object.defineProperty(ExperienceImpl.prototype, "config", {
|
|
801
|
-
get: function () {
|
|
802
|
-
var _a, _b, _c, _d;
|
|
803
|
-
return Object.assign(this._config, {
|
|
804
|
-
autoresizesHeight: (_a = this._config.autoresizesHeight) !== null && _a !== void 0 ? _a : false,
|
|
805
|
-
hidesHeadersAndFooters: (_b = this._config.hidesHeadersAndFooters) !== null && _b !== void 0 ? _b : true,
|
|
806
|
-
supportsLoadingState: (_c = this._config.supportsLoadingState) !== null && _c !== void 0 ? _c : true,
|
|
807
|
-
experienceUrl: (_d = this._config.experienceUrl) !== null && _d !== void 0 ? _d : null,
|
|
808
|
-
});
|
|
809
|
-
},
|
|
810
|
-
enumerable: false,
|
|
811
|
-
configurable: true
|
|
812
|
-
});
|
|
813
|
-
ExperienceImpl.prototype.getEmbedUrl = function () {
|
|
814
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
815
|
-
var _a, host, projectId, listings;
|
|
816
|
-
return __generator(this, function (_b) {
|
|
817
|
-
switch (_b.label) {
|
|
818
|
-
case 0:
|
|
819
|
-
if (this.embedUrl) {
|
|
820
|
-
return [2 /*return*/, Promise.resolve(this.embedUrl)];
|
|
821
|
-
}
|
|
822
|
-
_a = this.sdk.options, host = _a.host, projectId = _a.projectId;
|
|
823
|
-
return [4 /*yield*/, fetchListings(host, projectId)];
|
|
824
|
-
case 1:
|
|
825
|
-
listings = _b.sent();
|
|
826
|
-
this.embedUrl = listings.project.embed;
|
|
827
|
-
return [2 /*return*/, this.embedUrl];
|
|
828
|
-
}
|
|
829
|
-
});
|
|
830
|
-
});
|
|
831
|
-
};
|
|
832
|
-
ExperienceImpl.prototype.getUrl = function () {
|
|
833
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
834
|
-
var embedUrl, url, customUrl_1, queryParameters;
|
|
835
|
-
var _a, _b, _c, _d;
|
|
836
|
-
return __generator(this, function (_e) {
|
|
837
|
-
switch (_e.label) {
|
|
838
|
-
case 0: return [4 /*yield*/, this.getEmbedUrl()];
|
|
839
|
-
case 1:
|
|
840
|
-
embedUrl = _e.sent();
|
|
841
|
-
url = new URL(ExperienceImpl.sanitiseUrl(embedUrl));
|
|
842
|
-
// override host and project with those that are set in SDK instance
|
|
843
|
-
url.searchParams.set(QueryParam.Host, this.sdk.options.host);
|
|
844
|
-
url.searchParams.set(QueryParam.Project, this.sdk.options.projectId);
|
|
845
|
-
// if custom experienceUrl is set:
|
|
846
|
-
// * take experienceUrl as the base
|
|
847
|
-
// * search params from experienceUrl have priority
|
|
848
|
-
if (this.config.experienceUrl !== null) {
|
|
849
|
-
customUrl_1 = new URL(ExperienceImpl.sanitiseUrl(this.config.experienceUrl));
|
|
850
|
-
// apply embedUrl query parameters if they don't exist in experienceUrl
|
|
851
|
-
Array.from(url.searchParams.entries())
|
|
852
|
-
.filter(function (_a) {
|
|
853
|
-
var key = _a[0];
|
|
854
|
-
return !customUrl_1.searchParams.has(key);
|
|
855
|
-
})
|
|
856
|
-
.forEach(function (_a) {
|
|
857
|
-
var key = _a[0], value = _a[1];
|
|
858
|
-
return customUrl_1.searchParams.set(key, value);
|
|
859
|
-
});
|
|
860
|
-
url = customUrl_1;
|
|
861
|
-
}
|
|
862
|
-
queryParameters = __assign(__assign(__assign(__assign(__assign({}, (this.config.host !== undefined && (_a = {},
|
|
863
|
-
_a[QueryParam.Host] = this.config.host,
|
|
864
|
-
_a))), (this.config.projectId !== undefined && (_b = {},
|
|
865
|
-
_b[QueryParam.Project] = this.config.projectId,
|
|
866
|
-
_b))), (this.config.eventId !== undefined && (_c = {},
|
|
867
|
-
_c[QueryParam.Event] = this.config.eventId,
|
|
868
|
-
_c))), (_d = {}, _d[QueryParam.BridgeId] = this.bridge.id, _d[QueryParam.HideHeaderAndFooter] = this.config.hidesHeadersAndFooters
|
|
869
|
-
? '1'
|
|
870
|
-
: '0', _d[QueryParam.AutoresizesHeight] = this.config.autoresizesHeight ? '1' : '0', _d)), this._parameters);
|
|
871
|
-
Object.entries(queryParameters).forEach(function (_a) {
|
|
872
|
-
var key = _a[0], value = _a[1];
|
|
873
|
-
url.searchParams.set(key, value);
|
|
874
|
-
});
|
|
875
|
-
return [2 /*return*/, url.href];
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
});
|
|
879
|
-
};
|
|
880
|
-
ExperienceImpl.sanitiseUrl = function (url, options) {
|
|
881
|
-
var stripReservedParameters = (options === null || options === void 0 ? void 0 : options.stripReservedParameters) || 'mic';
|
|
882
|
-
// Ensure the URL includes a protocol.
|
|
883
|
-
if (/^http/.test(url) === false) {
|
|
884
|
-
// If none are found, use the same as the document.
|
|
885
|
-
url = "" + document.location.protocol + url;
|
|
886
|
-
}
|
|
887
|
-
var urlObj = new URL(url);
|
|
888
|
-
Object.values(QueryParam)
|
|
889
|
-
.filter(function (key) {
|
|
890
|
-
if (stripReservedParameters === 'mic') {
|
|
891
|
-
return key.startsWith('mic');
|
|
892
|
-
}
|
|
893
|
-
return key;
|
|
894
|
-
})
|
|
895
|
-
.forEach(function (key) { return urlObj.searchParams.delete(key); });
|
|
896
|
-
return urlObj.href;
|
|
897
|
-
};
|
|
898
|
-
return ExperienceImpl;
|
|
899
|
-
}());
|
|
900
|
-
|
|
901
|
-
/**
|
|
902
|
-
* @license
|
|
903
|
-
* loader.ts
|
|
904
|
-
* launcher-kit
|
|
905
|
-
*
|
|
906
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-08-04
|
|
907
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
908
|
-
*
|
|
909
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
910
|
-
*/
|
|
911
|
-
/* eslint-enable */
|
|
912
|
-
function getLoadingTemplate() {
|
|
913
|
-
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 ";
|
|
914
|
-
}
|
|
915
|
-
function embed$1(container, loadingTemplate) {
|
|
916
|
-
if (loadingTemplate === void 0) { loadingTemplate = getLoadingTemplate; }
|
|
917
|
-
/**
|
|
918
|
-
* Return existing element if it exists
|
|
919
|
-
*/
|
|
920
|
-
var loaderElement = container.querySelector('[data-role=loader]');
|
|
921
|
-
if (loaderElement !== null) {
|
|
922
|
-
return loaderElement;
|
|
923
|
-
}
|
|
924
|
-
/**
|
|
925
|
-
* Stash and apply some custom styles to container element
|
|
926
|
-
*/
|
|
927
|
-
stashStyles(container, ['minHeight', 'position']);
|
|
928
|
-
container.style.minHeight = DEFAULT_HEIGHT + "px";
|
|
929
|
-
/**
|
|
930
|
-
* Inject loader element built from the html markup template
|
|
931
|
-
*/
|
|
932
|
-
var templateElement = document.createElement('template');
|
|
933
|
-
templateElement.innerHTML = loadingTemplate().trim();
|
|
934
|
-
loaderElement = container.appendChild(templateElement.content.firstElementChild);
|
|
935
|
-
/**
|
|
936
|
-
* Setting custom data attribute to be able to distinguish element along
|
|
937
|
-
* other injected html elements if any
|
|
938
|
-
*/
|
|
939
|
-
loaderElement.setAttribute('data-role', 'loader');
|
|
940
|
-
return loaderElement;
|
|
941
|
-
}
|
|
942
|
-
function unmount$1(container) {
|
|
943
|
-
var _a;
|
|
944
|
-
var loaderElement = container.querySelector('[data-role=loader]');
|
|
945
|
-
if (loaderElement === null) {
|
|
946
|
-
return;
|
|
947
|
-
}
|
|
948
|
-
(_a = loaderElement.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(loaderElement);
|
|
949
|
-
unstashStyles(container);
|
|
950
|
-
}
|
|
951
|
-
function show(container, loadingTemplate) {
|
|
952
|
-
if (loadingTemplate === void 0) { loadingTemplate = getLoadingTemplate; }
|
|
953
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
954
|
-
var loaderElement, position;
|
|
955
|
-
return __generator(this, function (_a) {
|
|
956
|
-
switch (_a.label) {
|
|
957
|
-
case 0:
|
|
958
|
-
loaderElement = embed$1(container, loadingTemplate);
|
|
959
|
-
position = getComputedStyle(container).position;
|
|
960
|
-
/**
|
|
961
|
-
* In order to properly position the loader,
|
|
962
|
-
* the container's position should be anything but 'static'.
|
|
963
|
-
*/
|
|
964
|
-
if (position === 'static') {
|
|
965
|
-
container.style.position = 'relative';
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* Setting styles to the loader for a nice fade in animation
|
|
969
|
-
*/
|
|
970
|
-
loaderElement.style.opacity = '0';
|
|
971
|
-
/**
|
|
972
|
-
* Kicking fade animation in.
|
|
973
|
-
*/
|
|
974
|
-
setTimeout(function () {
|
|
975
|
-
loaderElement.style.transition = "all " + LOADER_ANIMATION_DURATION + "ms";
|
|
976
|
-
loaderElement.style.opacity = '1';
|
|
977
|
-
}, 0);
|
|
978
|
-
/**
|
|
979
|
-
* Wait until the animation is finished. We do not use "transitionend" event
|
|
980
|
-
* here as it will just make the code more bloated and unnecessary complex.
|
|
981
|
-
*/
|
|
982
|
-
return [4 /*yield*/, delay(LOADER_ANIMATION_DURATION)];
|
|
983
|
-
case 1:
|
|
984
|
-
/**
|
|
985
|
-
* Wait until the animation is finished. We do not use "transitionend" event
|
|
986
|
-
* here as it will just make the code more bloated and unnecessary complex.
|
|
987
|
-
*/
|
|
988
|
-
_a.sent();
|
|
989
|
-
return [2 /*return*/];
|
|
990
|
-
}
|
|
991
|
-
});
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
function hide(container) {
|
|
995
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
996
|
-
var loaderElement;
|
|
997
|
-
return __generator(this, function (_a) {
|
|
998
|
-
switch (_a.label) {
|
|
999
|
-
case 0:
|
|
1000
|
-
loaderElement = container.querySelector('[data-role=loader]');
|
|
1001
|
-
if (loaderElement === null) {
|
|
1002
|
-
return [2 /*return*/];
|
|
1003
|
-
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Kicking fade out animation.
|
|
1006
|
-
*/
|
|
1007
|
-
setTimeout(function () {
|
|
1008
|
-
loaderElement.style.opacity = '0';
|
|
1009
|
-
}, 0);
|
|
1010
|
-
/**
|
|
1011
|
-
* Wait until the animation is finished. We do not use "transitionend" event
|
|
1012
|
-
* here as it will just make the code more bloated and unnecessary complex.
|
|
1013
|
-
*/
|
|
1014
|
-
return [4 /*yield*/, delay(LOADER_ANIMATION_DURATION)];
|
|
1015
|
-
case 1:
|
|
1016
|
-
/**
|
|
1017
|
-
* Wait until the animation is finished. We do not use "transitionend" event
|
|
1018
|
-
* here as it will just make the code more bloated and unnecessary complex.
|
|
1019
|
-
*/
|
|
1020
|
-
_a.sent();
|
|
1021
|
-
unstashStyles(container);
|
|
1022
|
-
unmount$1(container);
|
|
1023
|
-
return [2 /*return*/];
|
|
1024
|
-
}
|
|
1025
|
-
});
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
|
-
function stashStyles(element, props) {
|
|
1029
|
-
var styles = getComputedStyle(element);
|
|
1030
|
-
var stash = props
|
|
1031
|
-
.map(function (prop) { return String(prop) + "=" + styles[prop]; })
|
|
1032
|
-
.join(';');
|
|
1033
|
-
element.setAttribute('data-stash', stash);
|
|
1034
|
-
}
|
|
1035
|
-
function unstashStyles(element) {
|
|
1036
|
-
var stash = element.getAttribute('data-stash');
|
|
1037
|
-
if (stash === null) {
|
|
1038
|
-
return;
|
|
1039
|
-
}
|
|
1040
|
-
var attributes = stash
|
|
1041
|
-
.split(';')
|
|
1042
|
-
.map(function (attr) { return attr.split('='); });
|
|
1043
|
-
for (var _i = 0, attributes_1 = attributes; _i < attributes_1.length; _i++) {
|
|
1044
|
-
var _a = attributes_1[_i], attr = _a[0], value = _a[1];
|
|
1045
|
-
element.style[attr] = value;
|
|
1046
|
-
}
|
|
1047
|
-
element.removeAttribute('data-stash');
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
var version = "0.18.0";
|
|
1051
|
-
|
|
1052
|
-
/**
|
|
1053
|
-
* @license
|
|
1054
|
-
* api.ts
|
|
1055
|
-
* launcher-kit
|
|
1056
|
-
*
|
|
1057
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-02-15
|
|
1058
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
1059
|
-
*
|
|
1060
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1061
|
-
*/
|
|
1062
|
-
/**
|
|
1063
|
-
* The current SDK version.
|
|
1064
|
-
*
|
|
1065
|
-
* @internal
|
|
1066
|
-
*/
|
|
1067
|
-
var VERSION = version;
|
|
1068
|
-
var integrations = new Map();
|
|
1069
|
-
var embedHooks = [];
|
|
1070
|
-
/**
|
|
1071
|
-
* Creates an iframe with the provided parameters.
|
|
1072
|
-
*
|
|
1073
|
-
* @param url Url of the web app.
|
|
1074
|
-
*
|
|
1075
|
-
* @private
|
|
1076
|
-
*/
|
|
1077
|
-
function createIFrame(url, options) {
|
|
1078
|
-
if (options === void 0) { options = {}; }
|
|
1079
|
-
var iframe = document.createElement('iframe');
|
|
1080
|
-
iframe.style.width = '100%';
|
|
1081
|
-
iframe.style.height = '100%';
|
|
1082
|
-
iframe.style.border = '0';
|
|
1083
|
-
iframe.style.display = 'block';
|
|
1084
|
-
iframe.style.boxSizing = 'border-box';
|
|
1085
|
-
iframe.setAttribute('src', url);
|
|
1086
|
-
if (options.id !== undefined) {
|
|
1087
|
-
iframe.setAttribute('id', options.id);
|
|
1088
|
-
}
|
|
1089
|
-
if (options.allow !== undefined) {
|
|
1090
|
-
iframe.setAttribute('allow', options.allow);
|
|
1091
|
-
}
|
|
1092
|
-
if (options.allowFullScreen === true) {
|
|
1093
|
-
iframe.setAttribute('allowfullscreen', '');
|
|
1094
|
-
}
|
|
1095
|
-
/**
|
|
1096
|
-
* Though scrolling attribute is deprecated we still have to rely on it as some
|
|
1097
|
-
* browsers (e.g. Chrome, as of now version 103) just ignores overflow: hidden.
|
|
1098
|
-
* Hence we are setting scrolling to no in order to eliminate scroll and calculate
|
|
1099
|
-
* width of the child Experience correctly. If scroll persists it appears on each
|
|
1100
|
-
* content change what leads to incorrect width calculation.
|
|
1101
|
-
*
|
|
1102
|
-
* Later we will look into alternatives such as iframeless Experience embed
|
|
1103
|
-
*/
|
|
1104
|
-
if (!options.scrolling) {
|
|
1105
|
-
iframe.style.overflow = 'hidden';
|
|
1106
|
-
iframe.setAttribute('scrolling', 'no');
|
|
1107
|
-
}
|
|
1108
|
-
return iframe;
|
|
1109
|
-
}
|
|
1110
|
-
function concealIFrame(iframe) {
|
|
1111
|
-
iframe.style.opacity = '0';
|
|
1112
|
-
}
|
|
1113
|
-
function revealIFrame(iframe) {
|
|
1114
|
-
iframe.style.opacity = '1';
|
|
1115
|
-
}
|
|
1116
|
-
function isSdk(value) {
|
|
1117
|
-
return value instanceof Sdk;
|
|
1118
|
-
}
|
|
1119
|
-
function getExperience(sdkOrConfig, config) {
|
|
1120
|
-
var sdk;
|
|
1121
|
-
var experienceConfig;
|
|
1122
|
-
if (isSdk(sdkOrConfig)) {
|
|
1123
|
-
/**
|
|
1124
|
-
* Interface: getExperience(sdk, config?)
|
|
1125
|
-
*/
|
|
1126
|
-
sdk = sdkOrConfig;
|
|
1127
|
-
if (config !== undefined) {
|
|
1128
|
-
experienceConfig = config;
|
|
1129
|
-
}
|
|
1130
|
-
else {
|
|
1131
|
-
experienceConfig = {};
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
else if (sdkOrConfig !== undefined) {
|
|
1135
|
-
/**
|
|
1136
|
-
* Interface: getExperience(config)
|
|
1137
|
-
*/
|
|
1138
|
-
sdk = getSdk();
|
|
1139
|
-
experienceConfig = sdkOrConfig;
|
|
1140
|
-
}
|
|
1141
|
-
else {
|
|
1142
|
-
/**
|
|
1143
|
-
* Interface: getExperience()
|
|
1144
|
-
*/
|
|
1145
|
-
sdk = getSdk();
|
|
1146
|
-
experienceConfig = {};
|
|
1147
|
-
}
|
|
1148
|
-
var experience = new ExperienceImpl(sdk, experienceConfig);
|
|
1149
|
-
return experience;
|
|
1150
|
-
}
|
|
1151
|
-
function onResize(experience, container) {
|
|
1152
|
-
if (!experience.config.autoresizesHeight) {
|
|
1153
|
-
return function () { };
|
|
1154
|
-
}
|
|
1155
|
-
return onSdkMessage(experience, function (_a) {
|
|
1156
|
-
var action = _a.action, payload = _a.payload;
|
|
1157
|
-
if (action === Action.OnResize) {
|
|
1158
|
-
/**
|
|
1159
|
-
* Container width is maintained the same as it is defined in the parent
|
|
1160
|
-
* page to preserve its behaviour. Only the height is updated
|
|
1161
|
-
*/
|
|
1162
|
-
// container.style.width = `${payload.width}px`;
|
|
1163
|
-
container.style.height = payload.height + "px";
|
|
1164
|
-
}
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
function onUILoaded(experience) {
|
|
1168
|
-
return new Promise(function (resolve) {
|
|
1169
|
-
var unsubscribe = onSdkMessage(experience, function (_a) {
|
|
1170
|
-
var action = _a.action;
|
|
1171
|
-
if (action === Action.OnUILoaded) {
|
|
1172
|
-
unsubscribe();
|
|
1173
|
-
resolve();
|
|
1174
|
-
}
|
|
1175
|
-
});
|
|
1176
|
-
});
|
|
1177
|
-
}
|
|
1178
|
-
function experienceReady(experience) {
|
|
1179
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1180
|
-
var bumper, timeout, loaded, hasFullyLoadedExperience, eitherTimeoutOrFullyLoaded;
|
|
1181
|
-
return __generator(this, function (_a) {
|
|
1182
|
-
bumper = delay(LOADER_BUMPER_TIMEOUT);
|
|
1183
|
-
timeout = delay(LOADER_TIMEOUT);
|
|
1184
|
-
loaded = onUILoaded(experience);
|
|
1185
|
-
hasFullyLoadedExperience = Promise.all([bumper, loaded]);
|
|
1186
|
-
eitherTimeoutOrFullyLoaded = Promise.race([
|
|
1187
|
-
timeout,
|
|
1188
|
-
hasFullyLoadedExperience,
|
|
1189
|
-
]);
|
|
1190
|
-
return [2 /*return*/, eitherTimeoutOrFullyLoaded];
|
|
1191
|
-
});
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Embeds web Experience app into iframe. There is only one app can be
|
|
1196
|
-
* associated with Experience and it is configured in
|
|
1197
|
-
* Monterosa / Interaction Cloud. Please refer the developer guide to get
|
|
1198
|
-
* more information on what is app and how to configure it:
|
|
1199
|
-
* {@link https://products.monterosa.co/mic/developer-guides/whats-an-app}
|
|
1200
|
-
*
|
|
1201
|
-
* @example
|
|
1202
|
-
* ```javascript
|
|
1203
|
-
* const experience = getExperience();
|
|
1204
|
-
*
|
|
1205
|
-
* embed(experience, 'container-id');
|
|
1206
|
-
* ```
|
|
1207
|
-
* @param {Experience} - An instance of Experience
|
|
1208
|
-
* @param {HTMLElement | string} containerOrId - HTML element instance or
|
|
1209
|
-
* element id where iframe is embedded into.
|
|
1210
|
-
*
|
|
1211
|
-
* @public
|
|
1212
|
-
*/
|
|
1213
|
-
function embed(experience, containerOrId) {
|
|
1214
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1215
|
-
var container, controller, hooksUnsubscribe, _i, embedHooks_1, hook, unsub, url, iframe;
|
|
1216
|
-
return __generator(this, function (_a) {
|
|
1217
|
-
switch (_a.label) {
|
|
1218
|
-
case 0:
|
|
1219
|
-
container = containerOrId instanceof HTMLElement
|
|
1220
|
-
? containerOrId
|
|
1221
|
-
: document.getElementById(containerOrId);
|
|
1222
|
-
if (container === null) {
|
|
1223
|
-
throw new Error("Container element with id \"" + containerOrId + "\" doesn't exist in DOM");
|
|
1224
|
-
}
|
|
1225
|
-
if (integrations.has(container)) {
|
|
1226
|
-
return [2 /*return*/];
|
|
1227
|
-
}
|
|
1228
|
-
controller = new AbortController();
|
|
1229
|
-
hooksUnsubscribe = [];
|
|
1230
|
-
integrations.set(container, {
|
|
1231
|
-
experience: experience,
|
|
1232
|
-
controller: controller,
|
|
1233
|
-
hooksUnsubscribe: hooksUnsubscribe,
|
|
1234
|
-
});
|
|
1235
|
-
if (experience.config.supportsLoadingState === true) {
|
|
1236
|
-
// Although showLoader is an asynchronous function, we execute
|
|
1237
|
-
// it synchronously to embed the iframe as quickly as possible.
|
|
1238
|
-
show(container, experience.config.loadingTemplate);
|
|
1239
|
-
}
|
|
1240
|
-
for (_i = 0, embedHooks_1 = embedHooks; _i < embedHooks_1.length; _i++) {
|
|
1241
|
-
hook = embedHooks_1[_i];
|
|
1242
|
-
unsub = hook(experience, container);
|
|
1243
|
-
hooksUnsubscribe.push(unsub);
|
|
1244
|
-
}
|
|
1245
|
-
return [4 /*yield*/, experience.getUrl()];
|
|
1246
|
-
case 1:
|
|
1247
|
-
url = _a.sent();
|
|
1248
|
-
if (controller.signal.aborted) {
|
|
1249
|
-
return [2 /*return*/];
|
|
1250
|
-
}
|
|
1251
|
-
iframe = createIFrame(url, {
|
|
1252
|
-
id: experience.bridge.iFrameId,
|
|
1253
|
-
scrolling: !experience.config.autoresizesHeight,
|
|
1254
|
-
allow: experience.config.allow,
|
|
1255
|
-
allowFullScreen: experience.config.allowFullScreen,
|
|
1256
|
-
});
|
|
1257
|
-
container.appendChild(iframe);
|
|
1258
|
-
concealIFrame(iframe);
|
|
1259
|
-
return [4 /*yield*/, experienceReady(experience)];
|
|
1260
|
-
case 2:
|
|
1261
|
-
_a.sent();
|
|
1262
|
-
if (controller.signal.aborted) {
|
|
1263
|
-
return [2 /*return*/];
|
|
1264
|
-
}
|
|
1265
|
-
revealIFrame(iframe);
|
|
1266
|
-
if (!(experience.config.supportsLoadingState === true)) return [3 /*break*/, 4];
|
|
1267
|
-
return [4 /*yield*/, hide(container)];
|
|
1268
|
-
case 3:
|
|
1269
|
-
_a.sent();
|
|
1270
|
-
_a.label = 4;
|
|
1271
|
-
case 4: return [2 /*return*/];
|
|
1272
|
-
}
|
|
1273
|
-
});
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
/**
|
|
1277
|
-
* Unmounts web Experience app which was previously embedded in the container.
|
|
1278
|
-
*
|
|
1279
|
-
* @example
|
|
1280
|
-
* ```javascript
|
|
1281
|
-
* unmount('container-id');
|
|
1282
|
-
* ```
|
|
1283
|
-
*
|
|
1284
|
-
* @param {HTMLElement | string} containerOrId - HTML element instance or
|
|
1285
|
-
* element id where iframe is embedded into.
|
|
1286
|
-
*
|
|
1287
|
-
* @public
|
|
1288
|
-
*/
|
|
1289
|
-
function unmount(containerOrId) {
|
|
1290
|
-
var container = containerOrId instanceof HTMLElement
|
|
1291
|
-
? containerOrId
|
|
1292
|
-
: document.getElementById(containerOrId);
|
|
1293
|
-
if (container === null) {
|
|
1294
|
-
throw new Error("Container element with id \"" + containerOrId + "\" doesn't exist in DOM");
|
|
1295
|
-
}
|
|
1296
|
-
var integration = integrations.get(container);
|
|
1297
|
-
if (!integration) {
|
|
1298
|
-
return;
|
|
1299
|
-
}
|
|
1300
|
-
integration.controller.abort();
|
|
1301
|
-
for (var _i = 0, _a = integration.hooksUnsubscribe; _i < _a.length; _i++) {
|
|
1302
|
-
var unsub = _a[_i];
|
|
1303
|
-
unsub();
|
|
1304
|
-
}
|
|
1305
|
-
while (container.lastElementChild) {
|
|
1306
|
-
container.removeChild(container.lastElementChild);
|
|
1307
|
-
}
|
|
1308
|
-
integrations.delete(container);
|
|
1309
|
-
container.style.height = '';
|
|
1310
|
-
}
|
|
1311
|
-
/**
|
|
1312
|
-
* Informs the Experience that more data should be loaded and displayed on the UI.
|
|
1313
|
-
*
|
|
1314
|
-
* @remarks
|
|
1315
|
-
* One example is when Experience renders items feed partially. Once a user scrolled
|
|
1316
|
-
* to the bottom edge of the app, more elements to load is requested.
|
|
1317
|
-
*
|
|
1318
|
-
* @param experience - Experience instance
|
|
1319
|
-
*/
|
|
1320
|
-
function requestMoreData(experience) {
|
|
1321
|
-
sendSdkMessage(experience, Action.OnMoreDataRequested);
|
|
1322
|
-
}
|
|
1323
|
-
/**
|
|
1324
|
-
* @internal
|
|
1325
|
-
*/
|
|
1326
|
-
function registerEmbedHook(hook) {
|
|
1327
|
-
embedHooks.push(hook);
|
|
1328
|
-
}
|
|
1329
|
-
function enableLogging(logLevelOrFlag) {
|
|
1330
|
-
if (logLevelOrFlag === void 0) { logLevelOrFlag = true; }
|
|
1331
|
-
if (typeof logLevelOrFlag === 'boolean') {
|
|
1332
|
-
logger.logLevel = logLevelOrFlag ? LogLevel.Verbose : LogLevel.Silent;
|
|
1333
|
-
return;
|
|
1334
|
-
}
|
|
1335
|
-
logger.logLevel = logLevelOrFlag;
|
|
1336
|
-
}
|
|
1337
|
-
registerEmbedHook(onResize);
|
|
1338
|
-
|
|
1339
|
-
/**
|
|
1340
|
-
* @license
|
|
1341
|
-
* parent_application_impl.ts
|
|
1342
|
-
* launcher-kit
|
|
1343
|
-
*
|
|
1344
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2022-07-12
|
|
1345
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
1346
|
-
*
|
|
1347
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1348
|
-
*/
|
|
1349
|
-
var ParentApplicationImpl = /** @class */ (function () {
|
|
1350
|
-
function ParentApplicationImpl(bridge) {
|
|
1351
|
-
this.bridge = bridge;
|
|
1352
|
-
}
|
|
1353
|
-
return ParentApplicationImpl;
|
|
1354
|
-
}());
|
|
1355
|
-
|
|
1356
|
-
/**
|
|
1357
|
-
* @license
|
|
1358
|
-
* parent_application.ts
|
|
1359
|
-
* launcher-kit
|
|
1360
|
-
*
|
|
1361
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-15
|
|
1362
|
-
* Copyright © 2023 Monterosa. All rights reserved.
|
|
1363
|
-
*
|
|
1364
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1365
|
-
*/
|
|
1366
|
-
var parentApplication;
|
|
1367
|
-
/**
|
|
1368
|
-
* Returns instance of parent application.
|
|
1369
|
-
*
|
|
1370
|
-
* @returns Returns {@link ParentApplication}
|
|
1371
|
-
* if an Experience resides within the parent application, and it was embedded
|
|
1372
|
-
* using {@link embed} function. Otherwise it returns `null`.
|
|
1373
|
-
*/
|
|
1374
|
-
function getParentApplication() {
|
|
1375
|
-
if (parentApplication !== undefined) {
|
|
1376
|
-
return parentApplication;
|
|
1377
|
-
}
|
|
1378
|
-
var parentBridge = getParentBridge();
|
|
1379
|
-
if (parentBridge === null) {
|
|
1380
|
-
return null;
|
|
1381
|
-
}
|
|
1382
|
-
parentApplication = new ParentApplicationImpl(parentBridge);
|
|
1383
|
-
return parentApplication;
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
/**
|
|
1387
|
-
* @license
|
|
1388
|
-
* child_helpers.ts
|
|
1389
|
-
* launcher-kit
|
|
1390
|
-
*
|
|
1391
|
-
* Created by Josep Rodriguez <josep.rodriguez@monterosa.co.uk> on 2022-07-13
|
|
1392
|
-
* Copyright © 2022 Monterosa. All rights reserved.
|
|
1393
|
-
*
|
|
1394
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1395
|
-
*/
|
|
1396
|
-
function getUrlParam(param) {
|
|
1397
|
-
var queryString = {};
|
|
1398
|
-
if (typeof window !== 'undefined') {
|
|
1399
|
-
queryString = window.location.search;
|
|
1400
|
-
}
|
|
1401
|
-
var urlParams = new URLSearchParams(queryString);
|
|
1402
|
-
return urlParams.get(param);
|
|
1403
|
-
}
|
|
1404
|
-
/**
|
|
1405
|
-
* The SDK on the parent application will by default request a child
|
|
1406
|
-
* Experience to hide its header and footer by setting a query parameter called
|
|
1407
|
-
* `micHideHeaderAndFooter` to `1`.
|
|
1408
|
-
*
|
|
1409
|
-
* This function will return true if that is the case, and false otherwise.
|
|
1410
|
-
*
|
|
1411
|
-
* When true, the developer of a child Experience is expected to hide it's headers
|
|
1412
|
-
* and footers as the parent application is actively providing them.
|
|
1413
|
-
*
|
|
1414
|
-
* You can test whether you are respecting this correctly by adding the following query
|
|
1415
|
-
* to your URL:
|
|
1416
|
-
*
|
|
1417
|
-
* "?micHideHeaderAndFooter=1"
|
|
1418
|
-
*
|
|
1419
|
-
* @returns Whether the header and footer views should be hidden.
|
|
1420
|
-
*/
|
|
1421
|
-
function shouldHideHeaderAndFooter() {
|
|
1422
|
-
return getUrlParam(QueryParam.HideHeaderAndFooter) === '1';
|
|
1423
|
-
}
|
|
1424
|
-
/**
|
|
1425
|
-
* This function will returns true if experience is embedded in autoresize height mode.
|
|
1426
|
-
*/
|
|
1427
|
-
function isAutoresizesHeight() {
|
|
1428
|
-
return getUrlParam(QueryParam.AutoresizesHeight) === '1';
|
|
1429
|
-
}
|
|
1430
|
-
/**
|
|
1431
|
-
* This function is used to notify the parent application that the Experience
|
|
1432
|
-
* is ready to be used. It's intended to be called by the Experience itself and
|
|
1433
|
-
* not by the parent application.
|
|
1434
|
-
*
|
|
1435
|
-
* @example
|
|
1436
|
-
* ```javascript
|
|
1437
|
-
* import { sendReady } from '@monterosa/sdk-launcher-kit';
|
|
1438
|
-
*
|
|
1439
|
-
* sendReady();
|
|
1440
|
-
* ```
|
|
1441
|
-
*
|
|
1442
|
-
* @returns void
|
|
1443
|
-
*/
|
|
1444
|
-
function sendReady() {
|
|
1445
|
-
var parentApp = getParentApplication();
|
|
1446
|
-
if (parentApp === null) {
|
|
1447
|
-
console.log('Unable to send finished loading UI message, as there is no parent application');
|
|
1448
|
-
return;
|
|
1449
|
-
}
|
|
1450
|
-
sendSdkMessage(parentApp, Action.OnReady);
|
|
1451
|
-
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Sends a message to the SDK of the parent application informing it that
|
|
1454
|
-
* the UI of this Experience has completed loading.
|
|
1455
|
-
*
|
|
1456
|
-
* You should call this method when your UI has completed loading and you are ready to
|
|
1457
|
-
* display data to the user. This can be when your network calls have successfully requested
|
|
1458
|
-
* data and you have updated the DOM for it, or when an error has occurred and you want
|
|
1459
|
-
* to take over the UI to provide details to the user.
|
|
1460
|
-
*
|
|
1461
|
-
* The SDK will use this message to dismiss the loading indicator, allowing a seamless
|
|
1462
|
-
* transition between a native loading UI, into a fully loaded, child Experience.
|
|
1463
|
-
*
|
|
1464
|
-
* If this call is not made, the parent SDK will add a grace period to ensure the web app
|
|
1465
|
-
* has sufficient time to load, and eventually dismiss the loading state, whether Experience
|
|
1466
|
-
* is ready or not, so as to avoid scenarios were a defect leaves an infinite loading state
|
|
1467
|
-
* presented to the user.
|
|
1468
|
-
*/
|
|
1469
|
-
function sendFinishedLoadingUI() {
|
|
1470
|
-
var parentApp = getParentApplication();
|
|
1471
|
-
if (parentApp === null) {
|
|
1472
|
-
console.log('Unable to send finished loading UI message, as there is no parent application');
|
|
1473
|
-
return;
|
|
1474
|
-
}
|
|
1475
|
-
sendSdkMessage(parentApp, Action.OnUILoaded);
|
|
1476
|
-
}
|
|
1477
|
-
/**
|
|
1478
|
-
* Adds an observer for when more data is requested by the parent application
|
|
1479
|
-
*
|
|
1480
|
-
* @param callback - The callback that is triggered when a request for more data
|
|
1481
|
-
* is received
|
|
1482
|
-
* @returns The unsubscribe function. When it's called,
|
|
1483
|
-
* the observer will be removed and requests for data will no longer be received
|
|
1484
|
-
*/
|
|
1485
|
-
function onMoreDataRequested(callback) {
|
|
1486
|
-
var parentApp = getParentApplication();
|
|
1487
|
-
if (parentApp === null) {
|
|
1488
|
-
console.log('Unable to subscribe to more data event, as there is no parent application');
|
|
1489
|
-
return function () { };
|
|
1490
|
-
}
|
|
1491
|
-
return onSdkMessage(parentApp, function (_a) {
|
|
1492
|
-
var action = _a.action;
|
|
1493
|
-
if (action === Action.OnMoreDataRequested) {
|
|
1494
|
-
callback();
|
|
1495
|
-
}
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
/**
|
|
1499
|
-
* Adds an observer for when experience is fully embedded and ready to accept
|
|
1500
|
-
* incoming messages
|
|
1501
|
-
*
|
|
1502
|
-
* @param experience - Experience instance
|
|
1503
|
-
* @param callback - The callback that is triggered when experience is embedded
|
|
1504
|
-
* @returns The unsubscribe function. When it's called, the observer will be
|
|
1505
|
-
* removed and ready event will not be received
|
|
1506
|
-
*/
|
|
1507
|
-
function onReady(experience, callback) {
|
|
1508
|
-
return onSdkMessage(experience, function (_a) {
|
|
1509
|
-
var action = _a.action;
|
|
1510
|
-
if (action === Action.OnReady) {
|
|
1511
|
-
callback();
|
|
1512
|
-
}
|
|
1513
|
-
});
|
|
1514
|
-
}
|
|
1515
|
-
/**
|
|
1516
|
-
* @internal
|
|
1517
|
-
*/
|
|
1518
|
-
var sendExperienceSizeThrottled = throttle(function (width, height) {
|
|
1519
|
-
var parentApp = getParentApplication();
|
|
1520
|
-
if (parentApp === null)
|
|
1521
|
-
return;
|
|
1522
|
-
sendSdkMessage(parentApp, Action.OnResize, { width: width, height: height });
|
|
1523
|
-
}, RESIZE_THROTTLE_TIMEOUT, {
|
|
1524
|
-
leading: true,
|
|
1525
|
-
trailing: true,
|
|
1526
|
-
});
|
|
1527
|
-
/**
|
|
1528
|
-
* @internal
|
|
1529
|
-
*/
|
|
1530
|
-
function sendExperienceSize(width, height) {
|
|
1531
|
-
return sendExperienceSizeThrottled(width, height);
|
|
1532
|
-
}
|
|
1533
|
-
/**
|
|
1534
|
-
* Sets up an observer to watch for the element dimensions change and
|
|
1535
|
-
* automatically reports their changes to the parent application.
|
|
1536
|
-
*
|
|
1537
|
-
* @param element - HTML element whose dimensions need to be watched
|
|
1538
|
-
* @returns The unsubscribe function. When it's called,
|
|
1539
|
-
* the observer will be removed and element dimensions are no longer tracked
|
|
1540
|
-
*/
|
|
1541
|
-
function reportExperienceSizeChanges(element) {
|
|
1542
|
-
var observer = new ResizeObserver(function () {
|
|
1543
|
-
var width = Math.max(element.offsetWidth, element.scrollWidth);
|
|
1544
|
-
var height = Math.max(element.offsetHeight, element.scrollHeight);
|
|
1545
|
-
sendExperienceSize(width, height);
|
|
1546
|
-
});
|
|
1547
|
-
observer.observe(element);
|
|
1548
|
-
return function () { return observer.unobserve(element); };
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
/**
|
|
1552
|
-
* @license
|
|
1553
|
-
* storage_impl.ts
|
|
1554
|
-
* launcher-kit
|
|
1555
|
-
*
|
|
1556
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-15
|
|
1557
|
-
* Copyright © 2023 Monterosa. All rights reserved.
|
|
1558
|
-
*
|
|
1559
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1560
|
-
*/
|
|
1561
|
-
var StorageImpl = /** @class */ (function () {
|
|
1562
|
-
function StorageImpl() {
|
|
1563
|
-
this.memoryStore = {};
|
|
1564
|
-
this.accessible = checkAvailability();
|
|
1565
|
-
this._persistent = false;
|
|
1566
|
-
}
|
|
1567
|
-
Object.defineProperty(StorageImpl.prototype, "persistent", {
|
|
1568
|
-
get: function () {
|
|
1569
|
-
return this._persistent;
|
|
1570
|
-
},
|
|
1571
|
-
set: function (newValue) {
|
|
1572
|
-
var oldValue = this._persistent;
|
|
1573
|
-
if (oldValue === newValue) {
|
|
1574
|
-
return;
|
|
1575
|
-
}
|
|
1576
|
-
var swapToStorage = newValue === true && this.accessible;
|
|
1577
|
-
var swapToMemory = newValue === false && this.accessible;
|
|
1578
|
-
if (swapToStorage) {
|
|
1579
|
-
for (var _i = 0, _a = Object.entries(this.memoryStore); _i < _a.length; _i++) {
|
|
1580
|
-
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
1581
|
-
setItem(key, value);
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
if (swapToMemory) {
|
|
1585
|
-
clear();
|
|
1586
|
-
}
|
|
1587
|
-
this._persistent = newValue;
|
|
1588
|
-
},
|
|
1589
|
-
enumerable: false,
|
|
1590
|
-
configurable: true
|
|
1591
|
-
});
|
|
1592
|
-
StorageImpl.prototype.getItem = function (key) {
|
|
1593
|
-
if (this.persistent && this.accessible) {
|
|
1594
|
-
return getItem(key);
|
|
1595
|
-
}
|
|
1596
|
-
if (Object.prototype.hasOwnProperty.call(this.memoryStore, key)) {
|
|
1597
|
-
return this.memoryStore[key];
|
|
1598
|
-
}
|
|
1599
|
-
return null;
|
|
1600
|
-
};
|
|
1601
|
-
StorageImpl.prototype.setItem = function (key, value) {
|
|
1602
|
-
if (this.persistent && this.accessible) {
|
|
1603
|
-
setItem(key, value);
|
|
1604
|
-
}
|
|
1605
|
-
this.memoryStore[key] = value;
|
|
1606
|
-
};
|
|
1607
|
-
StorageImpl.prototype.removeItem = function (key) {
|
|
1608
|
-
if (this.persistent && this.accessible) {
|
|
1609
|
-
removeItem(key);
|
|
1610
|
-
}
|
|
1611
|
-
delete this.memoryStore[key];
|
|
1612
|
-
};
|
|
1613
|
-
StorageImpl.prototype.clear = function () {
|
|
1614
|
-
if (this.persistent && this.accessible) {
|
|
1615
|
-
clear();
|
|
1616
|
-
}
|
|
1617
|
-
this.memoryStore = {};
|
|
1618
|
-
};
|
|
1619
|
-
return StorageImpl;
|
|
1620
|
-
}());
|
|
1621
|
-
|
|
1622
|
-
/**
|
|
1623
|
-
* @license
|
|
1624
|
-
* storage.ts
|
|
1625
|
-
* launcher-kit
|
|
1626
|
-
*
|
|
1627
|
-
* Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-15
|
|
1628
|
-
* Copyright © 2023 Monterosa. All rights reserved.
|
|
1629
|
-
*
|
|
1630
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
1631
|
-
*/
|
|
1632
|
-
/**
|
|
1633
|
-
* @internal
|
|
1634
|
-
*/
|
|
1635
|
-
var StorageAction;
|
|
1636
|
-
(function (StorageAction) {
|
|
1637
|
-
StorageAction["Read"] = "storageRead";
|
|
1638
|
-
StorageAction["Write"] = "storageWrite";
|
|
1639
|
-
StorageAction["Remove"] = "storageRemove";
|
|
1640
|
-
StorageAction["Clear"] = "storageClear";
|
|
1641
|
-
})(StorageAction || (StorageAction = {}));
|
|
1642
|
-
/**
|
|
1643
|
-
* @internal
|
|
1644
|
-
*/
|
|
1645
|
-
var storage = new StorageImpl();
|
|
1646
|
-
/**
|
|
1647
|
-
* @internal
|
|
1648
|
-
*/
|
|
1649
|
-
function listenStorageMessages(experience) {
|
|
1650
|
-
return onSdkMessage(experience, function (message) {
|
|
1651
|
-
var payload = {};
|
|
1652
|
-
if (!Object.values(StorageAction).includes(message.action)) {
|
|
1653
|
-
return;
|
|
1654
|
-
}
|
|
1655
|
-
switch (message.action) {
|
|
1656
|
-
case StorageAction.Read:
|
|
1657
|
-
payload = {
|
|
1658
|
-
value: storage.getItem(message.payload.key),
|
|
1659
|
-
};
|
|
1660
|
-
break;
|
|
1661
|
-
case StorageAction.Write:
|
|
1662
|
-
storage.setItem(message.payload.key, message.payload.value);
|
|
1663
|
-
break;
|
|
1664
|
-
case StorageAction.Remove:
|
|
1665
|
-
storage.removeItem(message.payload.key);
|
|
1666
|
-
break;
|
|
1667
|
-
case StorageAction.Clear:
|
|
1668
|
-
storage.clear();
|
|
1669
|
-
break;
|
|
1670
|
-
}
|
|
1671
|
-
respondToSdkMessage(experience, message, payload);
|
|
1672
|
-
});
|
|
1673
|
-
}
|
|
1674
|
-
/**
|
|
1675
|
-
* The `setStoragePersistent` function is a simple function that allows to
|
|
1676
|
-
* control the persistence of the SDK storage. If the argument `persistent` is
|
|
1677
|
-
* set to `true`, then the storage will be persistent across browser sessions
|
|
1678
|
-
* and if it is set to `false`, then the storage will save to memory.
|
|
1679
|
-
* It is important to note that the use of persistent storage may be subject
|
|
1680
|
-
* to laws and regulations, such as those related to data privacy and protection.
|
|
1681
|
-
*
|
|
1682
|
-
* @remarks
|
|
1683
|
-
* - We transition from persistent to memory and memory to persistent in
|
|
1684
|
-
* a seamless manner for you
|
|
1685
|
-
*
|
|
1686
|
-
* - By default we store in memory
|
|
1687
|
-
*
|
|
1688
|
-
* - The value of storage persistent persists across session (aka put it to true,
|
|
1689
|
-
* it will remain so, put it back to false, it will remain so)
|
|
1690
|
-
*
|
|
1691
|
-
* - You have the responsibility to comply with any laws and regulations, and
|
|
1692
|
-
* store only the data if you know it's valid to do so
|
|
1693
|
-
*
|
|
1694
|
-
* @param persistent - Determines whether or not SDK storage should persist
|
|
1695
|
-
* across browser sessions.
|
|
1696
|
-
*/
|
|
1697
|
-
function setStoragePersistent(persistent) {
|
|
1698
|
-
storage.persistent = persistent;
|
|
1699
|
-
}
|
|
1700
|
-
/**
|
|
1701
|
-
* The function allows to read data from the SDK storage.
|
|
1702
|
-
*
|
|
1703
|
-
* @param key - The name of the item to be read from storage.
|
|
1704
|
-
*
|
|
1705
|
-
* @throws
|
|
1706
|
-
* The function throws an error if there is a timeout reading the data
|
|
1707
|
-
* from the parent application storage.
|
|
1708
|
-
*
|
|
1709
|
-
* @returns A promise that resolves to the value
|
|
1710
|
-
* of the item in storage or `null` if the item doesn't exist.
|
|
1711
|
-
*/
|
|
1712
|
-
function storageRead(key) {
|
|
1713
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1714
|
-
var parentApp, value, result;
|
|
1715
|
-
return __generator(this, function (_a) {
|
|
1716
|
-
switch (_a.label) {
|
|
1717
|
-
case 0:
|
|
1718
|
-
parentApp = getParentApplication();
|
|
1719
|
-
value = null;
|
|
1720
|
-
if (!(parentApp !== null)) return [3 /*break*/, 2];
|
|
1721
|
-
return [4 /*yield*/, sendSdkRequest(parentApp, StorageAction.Read, {
|
|
1722
|
-
key: key,
|
|
1723
|
-
})];
|
|
1724
|
-
case 1:
|
|
1725
|
-
result = _a.sent();
|
|
1726
|
-
value = result.payload.value;
|
|
1727
|
-
return [3 /*break*/, 3];
|
|
1728
|
-
case 2:
|
|
1729
|
-
value = storage.getItem(key);
|
|
1730
|
-
_a.label = 3;
|
|
1731
|
-
case 3: return [2 /*return*/, Promise.resolve(value)];
|
|
1732
|
-
}
|
|
1733
|
-
});
|
|
1734
|
-
});
|
|
1735
|
-
}
|
|
1736
|
-
/**
|
|
1737
|
-
* The function allows to write data to the SDK storage.
|
|
1738
|
-
*
|
|
1739
|
-
* @param key - A name of the item to be stored.
|
|
1740
|
-
* @param value - A value to be stored.
|
|
1741
|
-
*
|
|
1742
|
-
* @throws
|
|
1743
|
-
* The function throws an error if there is a timeout writing the data
|
|
1744
|
-
* to the parent's application storage.
|
|
1745
|
-
*
|
|
1746
|
-
* @returns A promise that resolves to `void` once the data has
|
|
1747
|
-
* been successfully stored.
|
|
1748
|
-
*/
|
|
1749
|
-
function storageWrite(key, value) {
|
|
1750
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1751
|
-
var parentApp;
|
|
1752
|
-
return __generator(this, function (_a) {
|
|
1753
|
-
switch (_a.label) {
|
|
1754
|
-
case 0:
|
|
1755
|
-
parentApp = getParentApplication();
|
|
1756
|
-
if (!(parentApp !== null)) return [3 /*break*/, 2];
|
|
1757
|
-
return [4 /*yield*/, sendSdkRequest(parentApp, StorageAction.Write, {
|
|
1758
|
-
key: key,
|
|
1759
|
-
value: value,
|
|
1760
|
-
})];
|
|
1761
|
-
case 1:
|
|
1762
|
-
_a.sent();
|
|
1763
|
-
return [3 /*break*/, 3];
|
|
1764
|
-
case 2:
|
|
1765
|
-
storage.setItem(key, value);
|
|
1766
|
-
_a.label = 3;
|
|
1767
|
-
case 3: return [2 /*return*/, Promise.resolve()];
|
|
1768
|
-
}
|
|
1769
|
-
});
|
|
1770
|
-
});
|
|
1771
|
-
}
|
|
1772
|
-
/**
|
|
1773
|
-
* The function allows to remove an item from the SDK storage.
|
|
1774
|
-
*
|
|
1775
|
-
* @param key - A name of the item to be removed.
|
|
1776
|
-
*
|
|
1777
|
-
* @throws
|
|
1778
|
-
* The function throws an error if there is a timeout removing the data
|
|
1779
|
-
* from the parent's application storage.
|
|
1780
|
-
*
|
|
1781
|
-
* @returns A promise that resolves to `void` once the data has
|
|
1782
|
-
* been successfully removed.
|
|
1783
|
-
*/
|
|
1784
|
-
function storageRemove(key) {
|
|
1785
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1786
|
-
var parentApp;
|
|
1787
|
-
return __generator(this, function (_a) {
|
|
1788
|
-
switch (_a.label) {
|
|
1789
|
-
case 0:
|
|
1790
|
-
parentApp = getParentApplication();
|
|
1791
|
-
if (!(parentApp !== null)) return [3 /*break*/, 2];
|
|
1792
|
-
return [4 /*yield*/, sendSdkRequest(parentApp, StorageAction.Remove, { key: key })];
|
|
1793
|
-
case 1:
|
|
1794
|
-
_a.sent();
|
|
1795
|
-
return [3 /*break*/, 3];
|
|
1796
|
-
case 2:
|
|
1797
|
-
storage.removeItem(key);
|
|
1798
|
-
_a.label = 3;
|
|
1799
|
-
case 3: return [2 /*return*/, Promise.resolve()];
|
|
1800
|
-
}
|
|
1801
|
-
});
|
|
1802
|
-
});
|
|
1803
|
-
}
|
|
1804
|
-
/**
|
|
1805
|
-
* The function allows to clear all data from the SDK storage.
|
|
1806
|
-
*
|
|
1807
|
-
* @throws
|
|
1808
|
-
* The function throws an error if there is a timeout clearing the parent's
|
|
1809
|
-
* application storage.
|
|
1810
|
-
*
|
|
1811
|
-
* @returns A promise that resolves to `void` once the data has been
|
|
1812
|
-
* successfully cleared.
|
|
1813
|
-
*/
|
|
1814
|
-
function storageClear() {
|
|
1815
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1816
|
-
var parentApp;
|
|
1817
|
-
return __generator(this, function (_a) {
|
|
1818
|
-
switch (_a.label) {
|
|
1819
|
-
case 0:
|
|
1820
|
-
parentApp = getParentApplication();
|
|
1821
|
-
if (!(parentApp !== null)) return [3 /*break*/, 2];
|
|
1822
|
-
return [4 /*yield*/, sendSdkRequest(parentApp, StorageAction.Clear)];
|
|
1823
|
-
case 1:
|
|
1824
|
-
_a.sent();
|
|
1825
|
-
return [3 /*break*/, 3];
|
|
1826
|
-
case 2:
|
|
1827
|
-
storage.clear();
|
|
1828
|
-
_a.label = 3;
|
|
1829
|
-
case 3: return [2 /*return*/, Promise.resolve()];
|
|
1830
|
-
}
|
|
1831
|
-
});
|
|
1832
|
-
});
|
|
1833
|
-
}
|
|
1834
|
-
registerEmbedHook(listenStorageMessages);
|
|
1835
|
-
|
|
1836
|
-
export { Action, VERSION$1 as BRIDGE_VERSION, BridgeError, BridgeImpl, QueryParam, Source, StorageAction, VERSION, embed, enableLogging, getBridge, getExperience, getParentApplication, getParentBridge, isAutoresizesHeight, listenStorageMessages, onMessage, onMoreDataRequested, onReady, onSdkMessage, registerEmbedHook, reportExperienceSizeChanges, requestMoreData, respondToMessage, respondToSdkMessage, sendExperienceSize, sendExperienceSizeThrottled, sendFinishedLoadingUI, sendMessage, sendReady, sendRequest, sendSdkMessage, sendSdkRequest, setRequestTimeout, setStoragePersistent, shouldHideHeaderAndFooter, storage, storageClear, storageRead, storageRemove, storageWrite, unmount };
|
|
1837
|
-
//# sourceMappingURL=index.esm5.js.map
|