1 | var messageId = 1;
|
2 | var webviewId = "".concat(Date.now(), "-").concat(String(Math.random()).slice(-8));
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var getId = function () { return "web-".concat(messageId++, "-").concat(webviewId); };
|
12 |
|
13 | var BRIDGE = '__tuenti_webview_bridge';
|
14 | var hasAndroidPostMessage = function () {
|
15 | return !!(typeof window !== 'undefined' &&
|
16 | window.tuentiWebView &&
|
17 | window.tuentiWebView.postMessage);
|
18 | };
|
19 | var hasWebKitPostMessage = function () {
|
20 | return !!(typeof window !== 'undefined' &&
|
21 | window.webkit &&
|
22 | window.webkit.messageHandlers &&
|
23 | window.webkit.messageHandlers.tuentiWebView &&
|
24 | window.webkit.messageHandlers.tuentiWebView.postMessage);
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 | var getWebViewPostMessage = function () {
|
30 | if (typeof window === 'undefined') {
|
31 | return null;
|
32 | }
|
33 |
|
34 | if (hasAndroidPostMessage()) {
|
35 | return function (jsonMessage) {
|
36 | window.tuentiWebView.postMessage(jsonMessage);
|
37 | };
|
38 | }
|
39 |
|
40 | if (hasWebKitPostMessage()) {
|
41 | return function (jsonMessage) {
|
42 | window.webkit.messageHandlers.tuentiWebView.postMessage(jsonMessage);
|
43 | };
|
44 | }
|
45 | return null;
|
46 | };
|
47 | var messageListeners = [];
|
48 | var subscribe = function (listener) {
|
49 | messageListeners.push(listener);
|
50 | };
|
51 | var unsubscribe = function (listener) {
|
52 | messageListeners = messageListeners.filter(function (f) { return f !== listener; });
|
53 | };
|
54 | var isInIframe = function () {
|
55 | try {
|
56 | return window.self !== window.top;
|
57 | }
|
58 | catch (e) {
|
59 | return true;
|
60 | }
|
61 | };
|
62 | var isDisabledFromIframe = function () {
|
63 | var _a;
|
64 | if (typeof window === 'undefined') {
|
65 | return false;
|
66 | }
|
67 | if (!isInIframe()) {
|
68 | return false;
|
69 | }
|
70 | return !((_a = window === null || window === void 0 ? void 0 : window.frameElement) === null || _a === void 0 ? void 0 : _a.hasAttribute('data-enable-webview-bridge'));
|
71 | };
|
72 | var log = undefined;
|
73 | var setLogger = function (logger) {
|
74 | log = logger;
|
75 | };
|
76 |
|
77 |
|
78 |
|
79 | var isWebViewBridgeAvailable = function () {
|
80 | return !isDisabledFromIframe() &&
|
81 | (hasAndroidPostMessage() || hasWebKitPostMessage());
|
82 | };
|
83 |
|
84 |
|
85 |
|
86 | var postMessageToNativeApp = function (_a, timeout) {
|
87 | var type = _a.type, _b = _a.id, id = _b === void 0 ? getId() : _b, payload = _a.payload;
|
88 | var postMessage = getWebViewPostMessage();
|
89 | var message = JSON.stringify({ type: type, id: id, payload: payload });
|
90 | log === null || log === void 0 ? void 0 : log('[WebView Bridge] SEND:', message);
|
91 | if (!postMessage) {
|
92 | return Promise.reject({
|
93 | code: 500,
|
94 | reason: 'WebView postMessage not available',
|
95 | });
|
96 | }
|
97 |
|
98 | setTimeout(function () {
|
99 | postMessage(message);
|
100 | });
|
101 | return new Promise(function (resolve, reject) {
|
102 | var timedOut = false;
|
103 | var listener = function (response) {
|
104 | if (response.id === id && !timedOut) {
|
105 | if (response.type === type) {
|
106 | resolve(response.payload);
|
107 | }
|
108 | else if (response.type === 'ERROR') {
|
109 | reject(response.payload);
|
110 | }
|
111 | else {
|
112 | reject({
|
113 | code: 500,
|
114 | reason: "bad type: ".concat(response.type, ". Expecting ").concat(type),
|
115 | });
|
116 | }
|
117 | unsubscribe(listener);
|
118 | }
|
119 | };
|
120 | subscribe(listener);
|
121 | if (timeout) {
|
122 | setTimeout(function () {
|
123 | timedOut = true;
|
124 | unsubscribe(listener);
|
125 | reject({ code: 408, reason: 'request timeout' });
|
126 | }, timeout);
|
127 | }
|
128 | });
|
129 | };
|
130 |
|
131 |
|
132 |
|
133 | if (typeof window !== 'undefined') {
|
134 | window[BRIDGE] = window[BRIDGE] || {
|
135 | postMessage: function (jsonMessage) {
|
136 | log === null || log === void 0 ? void 0 : log('[WebView Bridge] RCVD:', jsonMessage);
|
137 | var message;
|
138 | try {
|
139 | message = JSON.parse(jsonMessage);
|
140 | }
|
141 | catch (e) {
|
142 | throw Error("Problem parsing webview message: ".concat(jsonMessage));
|
143 | }
|
144 | messageListeners.forEach(function (f) { return f(message); });
|
145 | },
|
146 | };
|
147 | }
|
148 | var listenToNativeMessage = function (type, handler) {
|
149 | var listener = function (message) {
|
150 | if (message.type === type) {
|
151 | Promise.resolve(handler(message.payload)).then(function (responsePayload) {
|
152 | var postMessage = getWebViewPostMessage();
|
153 | if (postMessage) {
|
154 | postMessage(JSON.stringify({
|
155 | type: message.type,
|
156 | id: message.id,
|
157 | payload: responsePayload,
|
158 | }));
|
159 | }
|
160 | });
|
161 | }
|
162 | };
|
163 | subscribe(listener);
|
164 | return function () {
|
165 | unsubscribe(listener);
|
166 | };
|
167 | };
|
168 | var onNativeEvent = function (eventHandler) {
|
169 | var handler = function (payload) {
|
170 | var response = eventHandler({
|
171 | event: payload.event,
|
172 | });
|
173 | return {
|
174 | action: response.action || 'default',
|
175 | };
|
176 | };
|
177 | return listenToNativeMessage('NATIVE_EVENT', handler);
|
178 | };
|
179 |
|
180 | var nativeConfirm = function (_a) {
|
181 | var message = _a.message, title = _a.title, acceptText = _a.acceptText, cancelText = _a.cancelText;
|
182 | if (isWebViewBridgeAvailable()) {
|
183 | return postMessageToNativeApp({
|
184 | type: 'CONFIRM',
|
185 | payload: { message: message, title: title, acceptText: acceptText, cancelText: cancelText },
|
186 | }).then(function (_a) {
|
187 | var result = _a.result;
|
188 | return result;
|
189 | });
|
190 | }
|
191 | else {
|
192 | return Promise.resolve(typeof window === 'undefined' ? false : window.confirm(message));
|
193 | }
|
194 | };
|
195 | var nativeAlert = function (_a) {
|
196 | var message = _a.message, title = _a.title, buttonText = _a.buttonText;
|
197 | if (isWebViewBridgeAvailable()) {
|
198 | return postMessageToNativeApp({
|
199 | type: 'ALERT',
|
200 | payload: { title: title, message: message, buttonText: buttonText },
|
201 | });
|
202 | }
|
203 | else {
|
204 | if (typeof window !== 'undefined') {
|
205 | window.alert(message);
|
206 | }
|
207 | return Promise.resolve();
|
208 | }
|
209 | };
|
210 | var nativeMessage = function (_a) {
|
211 | var message = _a.message, duration = _a.duration, buttonText = _a.buttonText, type = _a.type;
|
212 | if (isWebViewBridgeAvailable()) {
|
213 | return postMessageToNativeApp({
|
214 | type: 'MESSAGE',
|
215 | payload: { message: message, duration: duration, buttonText: buttonText, type: type },
|
216 | });
|
217 | }
|
218 | else {
|
219 | if (typeof window !== 'undefined') {
|
220 | window.alert(message);
|
221 | }
|
222 | return Promise.resolve();
|
223 | }
|
224 | };
|
225 |
|
226 | var TIMEOUT = 200;
|
227 | var requestSimIcc = function () {
|
228 | return postMessageToNativeApp({ type: 'SIM_ICC' }, TIMEOUT)
|
229 | .then(function (_a) {
|
230 | var icc = _a.icc;
|
231 | return icc;
|
232 | })
|
233 | .catch(function () { return null; });
|
234 | };
|
235 | var requestSimImsi = function () {
|
236 | return postMessageToNativeApp({ type: 'IMSI' }, TIMEOUT)
|
237 | .then(function (_a) {
|
238 | var imsi = _a.imsi;
|
239 | return imsi;
|
240 | })
|
241 | .catch(function () { return null; });
|
242 | };
|
243 | var requestDeviceImei = function () {
|
244 | return postMessageToNativeApp({ type: 'IMEI' }, TIMEOUT)
|
245 | .then(function (_a) {
|
246 | var imei = _a.imei;
|
247 | return imei;
|
248 | })
|
249 | .catch(function () { return null; });
|
250 | };
|
251 | var internalNavigation = function (feature) {
|
252 | return postMessageToNativeApp({
|
253 | type: 'INTERNAL_NAVIGATION',
|
254 | payload: {
|
255 | feature: feature,
|
256 | },
|
257 | });
|
258 | };
|
259 | var dismiss = function (onCompletionUrl) {
|
260 | return postMessageToNativeApp({
|
261 | type: 'DISMISS',
|
262 | payload: {
|
263 | onCompletionUrl: onCompletionUrl,
|
264 | },
|
265 | });
|
266 | };
|
267 | var requestVibration = function (type) {
|
268 | return postMessageToNativeApp({
|
269 | type: 'VIBRATION',
|
270 | payload: {
|
271 | type: type,
|
272 | },
|
273 | });
|
274 | };
|
275 | var getDiskSpaceInfo = function () {
|
276 | return postMessageToNativeApp({
|
277 | type: 'GET_DISK_SPACE_INFO',
|
278 | });
|
279 | };
|
280 | var getEsimInfo = function () {
|
281 | return postMessageToNativeApp({
|
282 | type: 'GET_ESIM_INFO',
|
283 | }).catch(function () { return ({
|
284 | supportsEsim: false,
|
285 | }); });
|
286 | };
|
287 |
|
288 | var attachToEmail = function (_a) {
|
289 | var url = _a.url, subject = _a.subject, fileName = _a.fileName, recipient = _a.recipient, body = _a.body;
|
290 | return postMessageToNativeApp({
|
291 | type: 'ATTACH_TO_EMAIL',
|
292 | payload: { url: url, subject: subject, fileName: fileName, recipient: recipient, body: body },
|
293 | });
|
294 | };
|
295 | var share = function (options) {
|
296 | return postMessageToNativeApp({
|
297 | type: 'SHARE',
|
298 | payload: options,
|
299 | });
|
300 | };
|
301 | var updateNavigationBar = function (_a) {
|
302 | var title = _a.title, expandedTitle = _a.expandedTitle, showBackButton = _a.showBackButton, showReloadButton = _a.showReloadButton, showProfileButton = _a.showProfileButton, backgroundColor = _a.backgroundColor;
|
303 | if (isWebViewBridgeAvailable()) {
|
304 | return postMessageToNativeApp({
|
305 | type: 'NAVIGATION_BAR',
|
306 | payload: {
|
307 | title: title,
|
308 | expandedTitle: expandedTitle,
|
309 | showBackButton: showBackButton,
|
310 | showReloadButton: showReloadButton,
|
311 | showProfileButton: showProfileButton,
|
312 | backgroundColor: backgroundColor,
|
313 | },
|
314 | });
|
315 | }
|
316 | else {
|
317 | if (typeof title !== 'undefined' && typeof document !== 'undefined') {
|
318 | document.title = title;
|
319 | }
|
320 | return Promise.resolve();
|
321 | }
|
322 | };
|
323 |
|
324 |
|
325 |
|
326 | var setWebViewTitle = function (title) {
|
327 | if (isWebViewBridgeAvailable()) {
|
328 | return updateNavigationBar({ title: title });
|
329 | }
|
330 | else {
|
331 | if (typeof document !== 'undefined') {
|
332 | document.title = title;
|
333 | }
|
334 | return Promise.resolve();
|
335 | }
|
336 | };
|
337 | var notifyPageLoaded = function () {
|
338 | return postMessageToNativeApp({ type: 'PAGE_LOADED' });
|
339 | };
|
340 | var notifyBridgeReady = function () {
|
341 | return postMessageToNativeApp({ type: 'BRIDGE_READY' });
|
342 | };
|
343 | var remoteConfig = null;
|
344 | var isRemoteConfigAvailable = function (key) {
|
345 | return remoteConfig.result[key] === 'true';
|
346 | };
|
347 | var isABTestingAvailable = function (key) {
|
348 | if (!remoteConfig) {
|
349 |
|
350 | var timeoutP = new Promise(function (resolve) {
|
351 | setTimeout(function () {
|
352 | resolve(false);
|
353 | }, 500);
|
354 | });
|
355 | var configP = postMessageToNativeApp({
|
356 | type: 'GET_REMOTE_CONFIG',
|
357 | }).then(function (res) {
|
358 | remoteConfig = res;
|
359 | return isRemoteConfigAvailable(key);
|
360 | });
|
361 | return Promise.race([timeoutP, configP]);
|
362 | }
|
363 | else {
|
364 | return Promise.resolve(isRemoteConfigAvailable(key));
|
365 | }
|
366 | };
|
367 | var reportStatus = function (_a) {
|
368 | var feature = _a.feature, status = _a.status, reason = _a.reason;
|
369 | return postMessageToNativeApp({
|
370 | type: 'STATUS_REPORT',
|
371 | payload: { feature: feature, status: status, reason: reason },
|
372 | });
|
373 | };
|
374 | var fetch = function (_a) {
|
375 | var url = _a.url, method = _a.method, headers = _a.headers, body = _a.body;
|
376 | if (isWebViewBridgeAvailable()) {
|
377 | return postMessageToNativeApp({
|
378 | type: 'FETCH',
|
379 | payload: { url: url, method: method, headers: headers, body: body },
|
380 | }).catch(function () { return ({
|
381 | status: 500,
|
382 | headers: {},
|
383 | body: 'Bridge call failed',
|
384 | }); });
|
385 | }
|
386 | return Promise.resolve({
|
387 | status: 500,
|
388 | headers: {},
|
389 | body: 'Bridge not available',
|
390 | });
|
391 | };
|
392 | var checkPermissionStatus = function (feature, params) {
|
393 | return postMessageToNativeApp({
|
394 | type: 'OS_PERMISSION_STATUS',
|
395 | payload: {
|
396 | feature: feature,
|
397 | params: params,
|
398 | },
|
399 | }).then(function (_a) {
|
400 | var granted = _a.granted;
|
401 | return granted;
|
402 | });
|
403 | };
|
404 | var getAppMetadata = function (appToken) {
|
405 | return postMessageToNativeApp({
|
406 | type: 'GET_APP_METADATA',
|
407 | payload: {
|
408 | appToken: appToken,
|
409 | },
|
410 | });
|
411 | };
|
412 | var setActionBehavior = function (actions) {
|
413 | return postMessageToNativeApp({
|
414 | type: 'SET_ACTION_BEHAVIOR',
|
415 | payload: {
|
416 | actions: actions,
|
417 | },
|
418 | }).catch(function () {
|
419 |
|
420 | });
|
421 | };
|
422 |
|
423 |
|
424 |
|
425 |
|
426 | var getTopazToken = function (options) {
|
427 | if (options === void 0) { options = {}; }
|
428 | return postMessageToNativeApp({
|
429 | type: 'GET_TOPAZ_TOKEN',
|
430 | payload: {},
|
431 | }, options.timeout);
|
432 | };
|
433 |
|
434 | var msToS = function (ms) { return Math.floor(ms / 1000); };
|
435 | var createCalendarEvent = function (_a) {
|
436 | var beginTime = _a.beginTime, endTime = _a.endTime, title = _a.title;
|
437 | return postMessageToNativeApp({
|
438 | type: 'CREATE_CALENDAR_EVENT',
|
439 | payload: {
|
440 | beginTime: msToS(beginTime),
|
441 | endTime: msToS(endTime),
|
442 | title: title,
|
443 | },
|
444 | });
|
445 | };
|
446 |
|
447 | var requestContact = function (_a) {
|
448 | var _b = _a === void 0 ? {} : _a, _c = _b.filter, filter = _c === void 0 ? 'phone' : _c;
|
449 | return postMessageToNativeApp({ type: 'GET_CONTACT_DATA', payload: { filter: filter } });
|
450 | };
|
451 | var fetchContactsByPhone = function (phoneNumbers) {
|
452 | return postMessageToNativeApp({
|
453 | type: 'FETCH_CONTACTS_DATA',
|
454 | payload: { phoneNumbers: phoneNumbers },
|
455 | });
|
456 | };
|
457 | var fetchPhoneNumbers = function () {
|
458 | return postMessageToNativeApp({
|
459 | type: 'FETCH_PHONE_NUMBERS',
|
460 | });
|
461 | };
|
462 | var updatePhoneNumbers = function (phoneNumbers) {
|
463 | return postMessageToNativeApp({
|
464 | type: 'UPDATE_PHONE_NUMBERS',
|
465 | payload: { phoneNumbers: phoneNumbers },
|
466 | });
|
467 | };
|
468 |
|
469 | var highlightNavigationTab = function (_a) {
|
470 | var tab = _a.tab, highlight = _a.highlight, count = _a.count;
|
471 | return postMessageToNativeApp({
|
472 | type: 'HIGHLIGHT_TAB',
|
473 | payload: {
|
474 | tab: tab,
|
475 | highlight: highlight,
|
476 | count: count,
|
477 | },
|
478 | });
|
479 | };
|
480 |
|
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 | var __assign = function() {
|
497 | __assign = Object.assign || function __assign(t) {
|
498 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
499 | s = arguments[i];
|
500 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
501 | }
|
502 | return t;
|
503 | };
|
504 | return __assign.apply(this, arguments);
|
505 | };
|
506 |
|
507 | function __rest(s, e) {
|
508 | var t = {};
|
509 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
510 | t[p] = s[p];
|
511 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
512 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
513 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
514 | t[p[i]] = s[p[i]];
|
515 | }
|
516 | return t;
|
517 | }
|
518 |
|
519 | function __awaiter(thisArg, _arguments, P, generator) {
|
520 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
521 | return new (P || (P = Promise))(function (resolve, reject) {
|
522 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
523 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
524 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
525 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
526 | });
|
527 | }
|
528 |
|
529 | function __generator(thisArg, body) {
|
530 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
531 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
532 | function verb(n) { return function (v) { return step([n, v]); }; }
|
533 | function step(op) {
|
534 | if (f) throw new TypeError("Generator is already executing.");
|
535 | while (_) try {
|
536 | 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;
|
537 | if (y = 0, t) op = [op[0] & 2, t.value];
|
538 | switch (op[0]) {
|
539 | case 0: case 1: t = op; break;
|
540 | case 4: _.label++; return { value: op[1], done: false };
|
541 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
542 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
543 | default:
|
544 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
545 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
546 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
547 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
548 | if (t[2]) _.ops.pop();
|
549 | _.trys.pop(); continue;
|
550 | }
|
551 | op = body.call(thisArg, _);
|
552 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
553 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
554 | }
|
555 | }
|
556 |
|
557 | function __read(o, n) {
|
558 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
559 | if (!m) return o;
|
560 | var i = m.call(o), r, ar = [], e;
|
561 | try {
|
562 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
563 | }
|
564 | catch (error) { e = { error: error }; }
|
565 | finally {
|
566 | try {
|
567 | if (r && !r.done && (m = i["return"])) m.call(i);
|
568 | }
|
569 | finally { if (e) throw e.error; }
|
570 | }
|
571 | return ar;
|
572 | }
|
573 |
|
574 |
|
575 | var CD_WEBAPP_INSTALLED = 4;
|
576 |
|
577 | var CD_NOVUM_UID = 7;
|
578 |
|
579 | var CD_EVENT_VALUE = 8;
|
580 | var DEFAULT_EVENT_LABEL = 'null_label';
|
581 | var DEFAULT_EVENT_VALUE = 0;
|
582 | var CALLBACK_TIMEOUT = 500;
|
583 | var MAX_TIMEOUT_TIMES = 3;
|
584 | var timeoutCounter = 0;
|
585 | var createCallback = function (resolve) {
|
586 |
|
587 |
|
588 |
|
589 |
|
590 | var tid = setTimeout(function () {
|
591 | resolve();
|
592 | timeoutCounter++;
|
593 | }, CALLBACK_TIMEOUT);
|
594 | return function () {
|
595 | clearTimeout(tid);
|
596 | timeoutCounter = 0;
|
597 | resolve();
|
598 | };
|
599 | };
|
600 | var withAnalytics = function (_a) {
|
601 | var onAndroid = _a.onAndroid, onIos = _a.onIos, onWeb = _a.onWeb;
|
602 | if (typeof window === 'undefined') {
|
603 | return Promise.resolve();
|
604 | }
|
605 | if (window.AnalyticsWebInterface) {
|
606 |
|
607 | return onAndroid(window.AnalyticsWebInterface);
|
608 | }
|
609 | else if (window.webkit &&
|
610 | window.webkit.messageHandlers &&
|
611 | window.webkit.messageHandlers.firebase) {
|
612 |
|
613 | return onIos(window.webkit.messageHandlers.firebase);
|
614 | }
|
615 | else if (
|
616 |
|
617 | window.gtag &&
|
618 | timeoutCounter < MAX_TIMEOUT_TIMES) {
|
619 |
|
620 | return onWeb(window.gtag);
|
621 | }
|
622 | else {
|
623 | return Promise.resolve();
|
624 | }
|
625 | };
|
626 | var removeAccents = function (str) {
|
627 |
|
628 |
|
629 | return str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
630 | };
|
631 | var EVENT_PARAM_NAME_CHARS_LIMIT = 40;
|
632 | var EVENT_PARAM_VALUE_CHARS_LIMIT = 100;
|
633 | var EVENT_PARAMS_LIMIT = 25;
|
634 | var sanitizeAnalyticsParam = function (str) {
|
635 | return removeAccents(str)
|
636 | .toLocaleLowerCase()
|
637 | .replace(/[^a-z0-9\s\-\_\/\|\:]/g, '')
|
638 | .replace(/\s+/g, ' ')
|
639 | .trim()
|
640 | .replace(/\s/g, '_')
|
641 | .slice(0, EVENT_PARAM_VALUE_CHARS_LIMIT);
|
642 | };
|
643 | var sanitizeAnalyticsParams = function (params) {
|
644 | var sanitizedParams = {};
|
645 | Object.entries(params).forEach(function (_a) {
|
646 | var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
647 | var sanitizedValue = value;
|
648 | var sanitizedKey = key.slice(0, EVENT_PARAM_NAME_CHARS_LIMIT);
|
649 | if (typeof value === 'string') {
|
650 |
|
651 | sanitizedValue = sanitizeAnalyticsParam(value);
|
652 | }
|
653 | sanitizedParams[sanitizedKey] = sanitizedValue;
|
654 | });
|
655 | return sanitizedParams;
|
656 | };
|
657 | var getLegacyAnalyticsEventParams = function (_a) {
|
658 | var category = _a.category, action = _a.action, label = _a.label, value = _a.value, fieldsObject = __rest(_a, ["category", "action", "label", "value"]);
|
659 | if (!label) {
|
660 | label = DEFAULT_EVENT_LABEL;
|
661 | }
|
662 | if (!value) {
|
663 | value = DEFAULT_EVENT_VALUE;
|
664 | }
|
665 | return __assign({ eventCategory: category, eventAction: action, eventLabel: removeAccents(label), eventValue: value }, fieldsObject);
|
666 | };
|
667 | var defaultEventOptions = { sanitize: true };
|
668 | var currentScreenName = '';
|
669 | var logEvent = function (event, options) {
|
670 | var sanitize = __assign(__assign({}, defaultEventOptions), options).sanitize;
|
671 | var name = event.name, params = __rest(event, ["name"]);
|
672 |
|
673 | if (!name) {
|
674 | if (!event.category || !event.action) {
|
675 | console.warn('LegacyAnalyticsEvent should have "category" and "action"', {
|
676 | category: event.category,
|
677 | action: event.action,
|
678 | });
|
679 | return Promise.resolve();
|
680 | }
|
681 | params = getLegacyAnalyticsEventParams(event);
|
682 | name = event.category;
|
683 | }
|
684 | else {
|
685 | if (Object.keys(params).length > EVENT_PARAMS_LIMIT) {
|
686 | console.warn("Trying to log FirebaseEvent with name ".concat(name, " exceeding the limit of ").concat(EVENT_PARAMS_LIMIT, " params"));
|
687 | }
|
688 | if (sanitize) {
|
689 | params = sanitizeAnalyticsParams(params);
|
690 | name = sanitizeAnalyticsParam(name);
|
691 | }
|
692 | }
|
693 |
|
694 | params = __assign(__assign({}, params), { screenName: params.screenName || currentScreenName });
|
695 | return withAnalytics({
|
696 | onAndroid: function (androidFirebase) {
|
697 | if (androidFirebase.logEvent) {
|
698 | androidFirebase.logEvent(name, JSON.stringify(params));
|
699 | }
|
700 | return Promise.resolve();
|
701 | },
|
702 | onIos: function (iosFirebase) {
|
703 | iosFirebase.postMessage({
|
704 | command: 'logEvent',
|
705 | name: name,
|
706 | parameters: params,
|
707 | });
|
708 | return Promise.resolve();
|
709 | },
|
710 | onWeb: function (gtag) {
|
711 | return new Promise(function (resolve) {
|
712 | gtag('event', name, __assign(__assign({}, params), { event_callback: createCallback(resolve) }));
|
713 | });
|
714 | },
|
715 | });
|
716 | };
|
717 | var logEcommerceEvent = function (name, params) {
|
718 |
|
719 | params = __assign(__assign({}, params), { screenName: params.screenName || currentScreenName });
|
720 | return withAnalytics({
|
721 | onAndroid: function (androidFirebase) {
|
722 | if (androidFirebase.logEvent) {
|
723 | androidFirebase.logEvent(name, JSON.stringify(params));
|
724 | }
|
725 | return Promise.resolve();
|
726 | },
|
727 | onIos: function (iosFirebase) {
|
728 | iosFirebase.postMessage({
|
729 | command: 'logEvent',
|
730 | name: name,
|
731 | parameters: params,
|
732 | });
|
733 | return Promise.resolve();
|
734 | },
|
735 | onWeb: function () {
|
736 |
|
737 | return Promise.resolve();
|
738 | },
|
739 | });
|
740 | };
|
741 | var logTiming = function (_a) {
|
742 | var _b = _a.category, category = _b === void 0 ? 'performance_timer' : _b, variable = _a.variable, value = _a.value, label = _a.label;
|
743 | if (!category || !variable || !value) {
|
744 | console.warn('Analytics timing should have "category", "variable" and "value"', { category: category, variable: variable, value: value });
|
745 | return Promise.resolve();
|
746 | }
|
747 | value = Math.round(value);
|
748 | var params = {
|
749 | timingCategory: category,
|
750 | timingVar: variable,
|
751 | timingValue: value,
|
752 | timingLabel: label,
|
753 | };
|
754 | var name = category;
|
755 | return withAnalytics({
|
756 | onAndroid: function (androidFirebase) {
|
757 | if (androidFirebase.logEvent) {
|
758 | androidFirebase.logEvent(name, JSON.stringify(params));
|
759 | }
|
760 | return Promise.resolve();
|
761 | },
|
762 | onIos: function (iosFirebase) {
|
763 | iosFirebase.postMessage({
|
764 | command: 'logEvent',
|
765 | name: name,
|
766 | parameters: params,
|
767 | });
|
768 | return Promise.resolve();
|
769 | },
|
770 | onWeb: function () {
|
771 | return new Promise(function (resolve) {
|
772 | gtag('event', name, __assign(__assign({}, params), { event_callback: createCallback(resolve) }));
|
773 | });
|
774 | },
|
775 | });
|
776 | };
|
777 | var setScreenName = function (screenName, params) {
|
778 | if (!screenName) {
|
779 | console.warn('Missing analytics screenName');
|
780 | return Promise.resolve();
|
781 | }
|
782 | var previousScreenName = currentScreenName;
|
783 | currentScreenName = screenName;
|
784 | return withAnalytics({
|
785 | onAndroid: function (androidFirebase) {
|
786 |
|
787 | if (androidFirebase.setScreenNameWithParams) {
|
788 | androidFirebase.setScreenNameWithParams(screenName, JSON.stringify(params));
|
789 | }
|
790 | else if (androidFirebase.setScreenName) {
|
791 | androidFirebase.setScreenName(screenName);
|
792 | }
|
793 | return Promise.resolve();
|
794 | },
|
795 | onIos: function (iosFirebase) {
|
796 | iosFirebase.postMessage({
|
797 | command: 'setScreenName',
|
798 | name: screenName,
|
799 | parameters: params,
|
800 | });
|
801 | return Promise.resolve();
|
802 | },
|
803 | onWeb: function (gtag) {
|
804 | return new Promise(function (resolve) {
|
805 | gtag('event', 'page_view', __assign(__assign({ screenName: screenName, page_title: screenName, previousScreenName: previousScreenName }, sanitizeAnalyticsParams(params !== null && params !== void 0 ? params : {})), { event_callback: createCallback(resolve) }));
|
806 | });
|
807 | },
|
808 | });
|
809 | };
|
810 | var setUserProperty = function (name, value) {
|
811 | if (!name || !value) {
|
812 | console.warn('Trying to set analytics user property without name or value', name, value);
|
813 | return Promise.resolve();
|
814 | }
|
815 | value = String(value);
|
816 | return withAnalytics({
|
817 | onAndroid: function (androidFirebase) {
|
818 | if (androidFirebase.setUserProperty) {
|
819 | androidFirebase.setUserProperty(name, value);
|
820 | }
|
821 | return Promise.resolve();
|
822 | },
|
823 | onIos: function (iosFirebase) {
|
824 | iosFirebase.postMessage({
|
825 | command: 'setUserProperty',
|
826 | name: name,
|
827 | value: value,
|
828 | });
|
829 | return Promise.resolve();
|
830 | },
|
831 | onWeb: function (gtag) {
|
832 | var _a;
|
833 | gtag('set', 'user_properties', (_a = {},
|
834 | _a[name] = sanitizeAnalyticsParam(value),
|
835 | _a));
|
836 | return Promise.resolve();
|
837 | },
|
838 | });
|
839 | };
|
840 | var setCustomerHash = function (hash) {
|
841 | return postMessageToNativeApp({
|
842 | type: 'SET_CUSTOMER_HASH',
|
843 | payload: {
|
844 | hash: hash,
|
845 | },
|
846 | });
|
847 | };
|
848 | var getCustomerHash = function () {
|
849 | return postMessageToNativeApp({
|
850 | type: 'GET_CUSTOMER_HASH',
|
851 | });
|
852 | };
|
853 | var setTrackingProperty = function (system, name, value) {
|
854 | return postMessageToNativeApp({
|
855 | type: 'SET_TRACKING_PROPERTY',
|
856 | payload: {
|
857 | system: system,
|
858 | name: name,
|
859 | value: value,
|
860 | },
|
861 | }).catch(function () {
|
862 |
|
863 | });
|
864 | };
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 | var renewSession = function (oldAccessToken, options) {
|
872 | if (options === void 0) { options = {}; }
|
873 | return postMessageToNativeApp({
|
874 | type: 'RENEW_SESSION',
|
875 | payload: { accessToken: oldAccessToken || null },
|
876 | }, options.timeout).then(function (_a) {
|
877 | var accessToken = _a.accessToken;
|
878 | return accessToken;
|
879 | });
|
880 | };
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 | var onSessionRenewed = function (handler) {
|
887 | return listenToNativeMessage('SESSION_RENEWED', function (_a) {
|
888 | var accessToken = _a.accessToken;
|
889 | return handler(accessToken);
|
890 | });
|
891 | };
|
892 |
|
893 |
|
894 |
|
895 | var logout = function () {
|
896 | return postMessageToNativeApp({ type: 'LOG_OUT' });
|
897 | };
|
898 |
|
899 |
|
900 |
|
901 |
|
902 | var showAppRating = function () {
|
903 | return postMessageToNativeApp({ type: 'SHOW_APP_RATING' });
|
904 | };
|
905 |
|
906 | var sheetLock = false;
|
907 | var bottomSheet = function (payload) { return __awaiter(void 0, void 0, void 0, function () {
|
908 | var tid, response, e_1;
|
909 | return __generator(this, function (_a) {
|
910 | switch (_a.label) {
|
911 | case 0:
|
912 | if (sheetLock) {
|
913 | throw {
|
914 | code: 423,
|
915 | reason: 'BottomSheet is locked. You can only have one bottom sheet in the screen',
|
916 | };
|
917 | }
|
918 | sheetLock = true;
|
919 | tid = setTimeout(function () {
|
920 | sheetLock = false;
|
921 | }, 1000);
|
922 | _a.label = 1;
|
923 | case 1:
|
924 | _a.trys.push([1, 3, , 4]);
|
925 | return [4 , postMessageToNativeApp({ type: 'SHEET', payload: payload })];
|
926 | case 2:
|
927 | response = _a.sent();
|
928 | sheetLock = false;
|
929 | clearTimeout(tid);
|
930 | return [2 , response];
|
931 | case 3:
|
932 | e_1 = _a.sent();
|
933 | sheetLock = false;
|
934 | clearTimeout(tid);
|
935 | throw e_1;
|
936 | case 4: return [2 ];
|
937 | }
|
938 | });
|
939 | }); };
|
940 | var bottomSheetSingleSelector = function (_a) {
|
941 | var title = _a.title, subtitle = _a.subtitle, description = _a.description, selectedId = _a.selectedId, items = _a.items;
|
942 | return bottomSheet({
|
943 | title: title,
|
944 | subtitle: subtitle,
|
945 | description: description,
|
946 | content: [
|
947 | {
|
948 | type: 'LIST',
|
949 | id: 'list-0',
|
950 | listType: 'SINGLE_SELECTION',
|
951 | autoSubmit: true,
|
952 | selectedIds: typeof selectedId === 'string' ? [selectedId] : [],
|
953 | items: items,
|
954 | },
|
955 | ],
|
956 | }).then(function (_a) {
|
957 | var action = _a.action, result = _a.result;
|
958 | if (action === 'SUBMIT') {
|
959 | return {
|
960 | action: action,
|
961 | selectedId: result[0].selectedIds[0],
|
962 | };
|
963 | }
|
964 | else {
|
965 | return {
|
966 | action: action,
|
967 | selectedId: null,
|
968 | };
|
969 | }
|
970 | });
|
971 | };
|
972 | var bottomSheetActionSelector = function (_a) {
|
973 | var title = _a.title, subtitle = _a.subtitle, description = _a.description, items = _a.items;
|
974 | return bottomSheet({
|
975 | title: title,
|
976 | subtitle: subtitle,
|
977 | description: description,
|
978 | content: [
|
979 | {
|
980 | type: 'LIST',
|
981 | id: 'list-0',
|
982 | listType: 'ACTIONS',
|
983 | autoSubmit: true,
|
984 | selectedIds: [],
|
985 | items: items,
|
986 | },
|
987 | ],
|
988 | }).then(function (_a) {
|
989 | var action = _a.action, result = _a.result;
|
990 | if (action === 'SUBMIT') {
|
991 | return {
|
992 | action: action,
|
993 | selectedId: result[0].selectedIds[0],
|
994 | };
|
995 | }
|
996 | else {
|
997 | return {
|
998 | action: action,
|
999 | selectedId: null,
|
1000 | };
|
1001 | }
|
1002 | });
|
1003 | };
|
1004 | var bottomSheetInfo = function (_a) {
|
1005 | var title = _a.title, subtitle = _a.subtitle, description = _a.description, items = _a.items;
|
1006 | return __awaiter(void 0, void 0, void 0, function () {
|
1007 | return __generator(this, function (_b) {
|
1008 | switch (_b.label) {
|
1009 | case 0: return [4 , bottomSheet({
|
1010 | title: title,
|
1011 | subtitle: subtitle,
|
1012 | description: description,
|
1013 | content: [
|
1014 | {
|
1015 | type: 'LIST',
|
1016 | id: 'list-0',
|
1017 | listType: 'INFORMATIVE',
|
1018 | autoSubmit: false,
|
1019 | selectedIds: [],
|
1020 | items: items,
|
1021 | },
|
1022 | ],
|
1023 | })];
|
1024 | case 1:
|
1025 | _b.sent();
|
1026 | return [2 ];
|
1027 | }
|
1028 | });
|
1029 | });
|
1030 | };
|
1031 |
|
1032 | export { CD_EVENT_VALUE, CD_NOVUM_UID, CD_WEBAPP_INSTALLED, attachToEmail, bottomSheet, bottomSheetActionSelector, bottomSheetInfo, bottomSheetSingleSelector, checkPermissionStatus, createCalendarEvent, dismiss, fetch, fetchContactsByPhone, fetchPhoneNumbers, getAppMetadata, getCustomerHash, getDiskSpaceInfo, getEsimInfo, getTopazToken, highlightNavigationTab, internalNavigation, isABTestingAvailable, isWebViewBridgeAvailable, logEcommerceEvent, logEvent, logTiming, logout, nativeAlert, nativeConfirm, nativeMessage, notifyBridgeReady, notifyPageLoaded, onNativeEvent, onSessionRenewed, renewSession, reportStatus, requestContact, requestDeviceImei, requestSimIcc, requestSimImsi, requestVibration, sanitizeAnalyticsParam, sanitizeAnalyticsParams, setActionBehavior, setCustomerHash, setLogger, setScreenName, setTrackingProperty, setUserProperty, setWebViewTitle, share, showAppRating, updateNavigationBar, updatePhoneNumbers };
|