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