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