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