UNPKG

@snowplow/react-native-tracker

Version:
772 lines (767 loc) 48.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.newPlatformContextPlugin = newPlatformContextPlugin; var _types = require("../../types.js"); var _constants = require("../../constants.js"); var _reactNative = require("react-native"); var _trackerCore = require("@snowplow/tracker-core"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; } function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function getIOSConstants() { var _NativeModules$Settin, _NativeModules$Settin2; // Example Platform info on iOS: // { // "OS": "ios", // "Version": "18.0", // "constants": { // "forceTouchAvailable": false, // "interfaceIdiom": "phone", // "isMacCatalyst": false, // "isTesting": false, // "osVersion": "18.0", // "systemName": "iOS" // }, // "isMacCatalyst": false, // "isPad": false, // "isTV": false, // "isVision": false // } // Example NativeModules.SettingsManager?.settings info on iOS: // { // "AppleLanguages": [ // "en-GB" // ], // "AppleLocale": "en_GB" // } var _ref = _reactNative.Platform, isPad = _ref.isPad, isTV = _ref.isTV, isVision = _ref.isVision, isMacCatalyst = _ref.isMacCatalyst, constants = _ref.constants; return { osType: constants.systemName, deviceManufacturer: 'Apple Inc.', osVersion: constants.osVersion, deviceModel: isPad ? 'iPad' : isTV ? 'Apple TV' : isVision ? 'Vision' : isMacCatalyst ? 'Mac' : 'iPhone', language: ((_NativeModules$Settin = _reactNative.NativeModules.SettingsManager) === null || _NativeModules$Settin === void 0 || (_NativeModules$Settin = _NativeModules$Settin.settings) === null || _NativeModules$Settin === void 0 ? void 0 : _NativeModules$Settin.AppleLocale) || ((_NativeModules$Settin2 = _reactNative.NativeModules.SettingsManager) === null || _NativeModules$Settin2 === void 0 || (_NativeModules$Settin2 = _NativeModules$Settin2.settings) === null || _NativeModules$Settin2 === void 0 ? void 0 : _NativeModules$Settin2.AppleLanguages[0]) //iOS 13 }; } function getAndroidConstants() { var _NativeModules$I18nMa; // Example Platform info on Android: // { // "OS": "android", // "Version": 33, // "constants": { // "Brand": "google", // "Manufacturer": "Google", // "Model": "sdk_gphone64_arm64", // "Release": "13", // "Version": 33, // }, // } // Example NativeModules.I18nManager info on Android: // { "localeIdentifier": "en_US" } var constants = _reactNative.Platform.constants; return { osType: 'android', deviceManufacturer: constants.Manufacturer, osVersion: constants.Release, deviceModel: constants.Model, language: (_NativeModules$I18nMa = _reactNative.NativeModules.I18nManager) === null || _NativeModules$I18nMa === void 0 ? void 0 : _NativeModules$I18nMa.localeIdentifier }; } /** * Tracks a mobile_context entity with all events if platformContext is enabled. */ function newPlatformContextPlugin() { return _newPlatformContextPlugin.apply(this, arguments); } function _newPlatformContextPlugin() { _newPlatformContextPlugin = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() { var _ref2, _ref2$platformContext, platformContext, platformContextProperties, platformContextRetriever, deviceModel, osType, deviceManufacturer, osVersion, carrier, networkType, networkTechnology, appleIdfa, appleIdfv, androidIdfa, physicalMemory, systemAvailableMemory, appAvailableMemory, batteryLevel, batteryState, lowPowerMode, availableStorage, totalStorage, isPortrait, resolution, scale, language, appSetId, appSetIdScope, refreshPlatformContext, enablePlatformContext, disablePlatformContext, contexts, _args3 = arguments; return _regeneratorRuntime().wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _ref2 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, _ref2$platformContext = _ref2.platformContext, platformContext = _ref2$platformContext === void 0 ? true : _ref2$platformContext, platformContextProperties = _ref2.platformContextProperties, platformContextRetriever = _ref2.platformContextRetriever; refreshPlatformContext = /*#__PURE__*/function () { var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() { var _platformContextPrope, _platformContextPrope2, _platformContextPrope3, _platformContextPrope4, _platformContextPrope5, _platformContextPrope6, _platformContextPrope7, _platformContextPrope8, _platformContextPrope9, _platformContextPrope10, _platformContextPrope11, _platformContextPrope12, _platformContextPrope13, _platformContextPrope14, _platformContextPrope15, _platformContextPrope16, _ref4, _platformContextPrope17, _platformContextPrope18, _platformContextPrope19; var constants; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: constants = _reactNative.Platform.OS === 'ios' ? getIOSConstants() : _reactNative.Platform.OS == 'android' ? getAndroidConstants() : undefined; if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getDeviceModel)) { _context.next = 7; break; } _context.next = 4; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getDeviceModel(); case 4: _context.t0 = _context.sent; _context.next = 8; break; case 7: _context.t0 = constants === null || constants === void 0 ? void 0 : constants.deviceModel; case 8: deviceModel = _context.t0; if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getOsType)) { _context.next = 15; break; } _context.next = 12; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getOsType(); case 12: _context.t1 = _context.sent; _context.next = 16; break; case 15: _context.t1 = constants === null || constants === void 0 ? void 0 : constants.osType; case 16: osType = _context.t1; if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getDeviceManufacturer)) { _context.next = 23; break; } _context.next = 20; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getDeviceManufacturer(); case 20: _context.t2 = _context.sent; _context.next = 24; break; case 23: _context.t2 = constants === null || constants === void 0 ? void 0 : constants.deviceManufacturer; case 24: deviceManufacturer = _context.t2; if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getOsVersion)) { _context.next = 31; break; } _context.next = 28; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getOsVersion(); case 28: _context.t3 = _context.sent; _context.next = 32; break; case 31: _context.t3 = constants === null || constants === void 0 ? void 0 : constants.osVersion; case 32: osVersion = _context.t3; if (!((_platformContextPrope = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.Carrier)) !== null && _platformContextPrope !== void 0 ? _platformContextPrope : true)) { _context.next = 44; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getCarrier)) { _context.next = 40; break; } _context.next = 37; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getCarrier(); case 37: _context.t5 = _context.sent; _context.next = 41; break; case 40: _context.t5 = undefined; case 41: _context.t4 = _context.t5; _context.next = 45; break; case 44: _context.t4 = undefined; case 45: carrier = _context.t4; if (!((_platformContextPrope2 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.NetworkType)) !== null && _platformContextPrope2 !== void 0 ? _platformContextPrope2 : true)) { _context.next = 57; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getNetworkType)) { _context.next = 53; break; } _context.next = 50; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getNetworkType(); case 50: _context.t7 = _context.sent; _context.next = 54; break; case 53: _context.t7 = undefined; case 54: _context.t6 = _context.t7; _context.next = 58; break; case 57: _context.t6 = undefined; case 58: networkType = _context.t6; if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getNetworkTechnology)) { _context.next = 65; break; } _context.next = 62; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getNetworkTechnology(); case 62: _context.t8 = _context.sent; _context.next = 66; break; case 65: _context.t8 = undefined; case 66: networkTechnology = _context.t8; if (!((_platformContextPrope3 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.AppleIdfa)) !== null && _platformContextPrope3 !== void 0 ? _platformContextPrope3 : true)) { _context.next = 78; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getAppleIdfa)) { _context.next = 74; break; } _context.next = 71; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getAppleIdfa(); case 71: _context.t10 = _context.sent; _context.next = 75; break; case 74: _context.t10 = undefined; case 75: _context.t9 = _context.t10; _context.next = 79; break; case 78: _context.t9 = undefined; case 79: appleIdfa = _context.t9; if (!((_platformContextPrope4 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.AppleIdfv)) !== null && _platformContextPrope4 !== void 0 ? _platformContextPrope4 : true)) { _context.next = 91; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getAppleIdfv)) { _context.next = 87; break; } _context.next = 84; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getAppleIdfv(); case 84: _context.t12 = _context.sent; _context.next = 88; break; case 87: _context.t12 = undefined; case 88: _context.t11 = _context.t12; _context.next = 92; break; case 91: _context.t11 = undefined; case 92: appleIdfv = _context.t11; if (!((_platformContextPrope5 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.AndroidIdfa)) !== null && _platformContextPrope5 !== void 0 ? _platformContextPrope5 : true)) { _context.next = 104; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getAndroidIdfa)) { _context.next = 100; break; } _context.next = 97; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getAndroidIdfa(); case 97: _context.t14 = _context.sent; _context.next = 101; break; case 100: _context.t14 = undefined; case 101: _context.t13 = _context.t14; _context.next = 105; break; case 104: _context.t13 = undefined; case 105: androidIdfa = _context.t13; if (!((_platformContextPrope6 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.PhysicalMemory)) !== null && _platformContextPrope6 !== void 0 ? _platformContextPrope6 : true)) { _context.next = 117; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getPhysicalMemory)) { _context.next = 113; break; } _context.next = 110; return platformContextRetriever.getPhysicalMemory(); case 110: _context.t16 = _context.sent; _context.next = 114; break; case 113: _context.t16 = undefined; case 114: _context.t15 = _context.t16; _context.next = 118; break; case 117: _context.t15 = undefined; case 118: physicalMemory = _context.t15; if (!((_platformContextPrope7 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.SystemAvailableMemory)) !== null && _platformContextPrope7 !== void 0 ? _platformContextPrope7 : true)) { _context.next = 130; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getSystemAvailableMemory)) { _context.next = 126; break; } _context.next = 123; return platformContextRetriever.getSystemAvailableMemory(); case 123: _context.t18 = _context.sent; _context.next = 127; break; case 126: _context.t18 = undefined; case 127: _context.t17 = _context.t18; _context.next = 131; break; case 130: _context.t17 = undefined; case 131: systemAvailableMemory = _context.t17; if (!((_platformContextPrope8 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.AppAvailableMemory)) !== null && _platformContextPrope8 !== void 0 ? _platformContextPrope8 : true)) { _context.next = 143; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getAppAvailableMemory)) { _context.next = 139; break; } _context.next = 136; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getAppAvailableMemory(); case 136: _context.t20 = _context.sent; _context.next = 140; break; case 139: _context.t20 = undefined; case 140: _context.t19 = _context.t20; _context.next = 144; break; case 143: _context.t19 = undefined; case 144: appAvailableMemory = _context.t19; if (!((_platformContextPrope9 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.BatteryLevel)) !== null && _platformContextPrope9 !== void 0 ? _platformContextPrope9 : true)) { _context.next = 156; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getBatteryLevel)) { _context.next = 152; break; } _context.next = 149; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getBatteryLevel(); case 149: _context.t22 = _context.sent; _context.next = 153; break; case 152: _context.t22 = undefined; case 153: _context.t21 = _context.t22; _context.next = 157; break; case 156: _context.t21 = undefined; case 157: batteryLevel = _context.t21; if (!((_platformContextPrope10 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.BatteryState)) !== null && _platformContextPrope10 !== void 0 ? _platformContextPrope10 : true)) { _context.next = 169; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getBatteryState)) { _context.next = 165; break; } _context.next = 162; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getBatteryState(); case 162: _context.t24 = _context.sent; _context.next = 166; break; case 165: _context.t24 = undefined; case 166: _context.t23 = _context.t24; _context.next = 170; break; case 169: _context.t23 = undefined; case 170: batteryState = _context.t23; if (!((_platformContextPrope11 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.LowPowerMode)) !== null && _platformContextPrope11 !== void 0 ? _platformContextPrope11 : true)) { _context.next = 182; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getLowPowerMode)) { _context.next = 178; break; } _context.next = 175; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getLowPowerMode(); case 175: _context.t26 = _context.sent; _context.next = 179; break; case 178: _context.t26 = undefined; case 179: _context.t25 = _context.t26; _context.next = 183; break; case 182: _context.t25 = undefined; case 183: lowPowerMode = _context.t25; if (!((_platformContextPrope12 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.AvailableStorage)) !== null && _platformContextPrope12 !== void 0 ? _platformContextPrope12 : true)) { _context.next = 195; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getAvailableStorage)) { _context.next = 191; break; } _context.next = 188; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getAvailableStorage(); case 188: _context.t28 = _context.sent; _context.next = 192; break; case 191: _context.t28 = undefined; case 192: _context.t27 = _context.t28; _context.next = 196; break; case 195: _context.t27 = undefined; case 196: availableStorage = _context.t27; if (!((_platformContextPrope13 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.TotalStorage)) !== null && _platformContextPrope13 !== void 0 ? _platformContextPrope13 : true)) { _context.next = 208; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getTotalStorage)) { _context.next = 204; break; } _context.next = 201; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getTotalStorage(); case 201: _context.t30 = _context.sent; _context.next = 205; break; case 204: _context.t30 = undefined; case 205: _context.t29 = _context.t30; _context.next = 209; break; case 208: _context.t29 = undefined; case 209: totalStorage = _context.t29; if (!((_platformContextPrope14 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.IsPortrait)) !== null && _platformContextPrope14 !== void 0 ? _platformContextPrope14 : true)) { _context.next = 221; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.isPortrait)) { _context.next = 217; break; } _context.next = 214; return platformContextRetriever.isPortrait(); case 214: _context.t32 = _context.sent; _context.next = 218; break; case 217: _context.t32 = undefined; case 218: _context.t31 = _context.t32; _context.next = 222; break; case 221: _context.t31 = undefined; case 222: isPortrait = _context.t31; if (!((_platformContextPrope15 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.Resolution)) !== null && _platformContextPrope15 !== void 0 ? _platformContextPrope15 : true)) { _context.next = 234; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getResolution)) { _context.next = 230; break; } _context.next = 227; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getResolution(); case 227: _context.t34 = _context.sent; _context.next = 231; break; case 230: _context.t34 = Math.floor(_reactNative.Dimensions.get('window').width) + 'x' + Math.floor(_reactNative.Dimensions.get('window').height); case 231: _context.t33 = _context.t34; _context.next = 235; break; case 234: _context.t33 = undefined; case 235: resolution = _context.t33; if (!((_platformContextPrope16 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.Scale)) !== null && _platformContextPrope16 !== void 0 ? _platformContextPrope16 : true)) { _context.next = 247; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getScale)) { _context.next = 243; break; } _context.next = 240; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getScale(); case 240: _context.t36 = _context.sent; _context.next = 244; break; case 243: _context.t36 = _reactNative.PixelRatio.get(); case 244: _context.t35 = _context.t36; _context.next = 248; break; case 247: _context.t35 = undefined; case 248: scale = _context.t35; if (!((_platformContextPrope17 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.Language)) !== null && _platformContextPrope17 !== void 0 ? _platformContextPrope17 : true)) { _context.next = 260; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getLanguage)) { _context.next = 256; break; } _context.next = 253; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getLanguage(); case 253: _context.t39 = _context.sent; _context.next = 257; break; case 256: _context.t39 = constants === null || constants === void 0 ? void 0 : constants.language; case 257: _context.t38 = _context.t39; _context.next = 261; break; case 260: _context.t38 = undefined; case 261: _context.t40 = _ref4 = _context.t38; _context.t37 = _context.t40 === null; if (_context.t37) { _context.next = 265; break; } _context.t37 = _ref4 === void 0; case 265: if (!_context.t37) { _context.next = 269; break; } _context.t41 = void 0; _context.next = 270; break; case 269: _context.t41 = _ref4.substring(0, 8); case 270: language = _context.t41; if (!((_platformContextPrope18 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.AppSetId)) !== null && _platformContextPrope18 !== void 0 ? _platformContextPrope18 : true)) { _context.next = 282; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getAppSetId)) { _context.next = 278; break; } _context.next = 275; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getAppSetId(); case 275: _context.t43 = _context.sent; _context.next = 279; break; case 278: _context.t43 = undefined; case 279: _context.t42 = _context.t43; _context.next = 283; break; case 282: _context.t42 = undefined; case 283: appSetId = _context.t42; if (!((_platformContextPrope19 = platformContextProperties === null || platformContextProperties === void 0 ? void 0 : platformContextProperties.includes(_types.PlatformContextProperty.AppSetIdScope)) !== null && _platformContextPrope19 !== void 0 ? _platformContextPrope19 : true)) { _context.next = 295; break; } if (!(platformContextRetriever !== null && platformContextRetriever !== void 0 && platformContextRetriever.getAppSetIdScope)) { _context.next = 291; break; } _context.next = 288; return platformContextRetriever === null || platformContextRetriever === void 0 ? void 0 : platformContextRetriever.getAppSetIdScope(); case 288: _context.t45 = _context.sent; _context.next = 292; break; case 291: _context.t45 = undefined; case 292: _context.t44 = _context.t45; _context.next = 296; break; case 295: _context.t44 = undefined; case 296: appSetIdScope = _context.t44; case 297: case "end": return _context.stop(); } }, _callee); })); return function refreshPlatformContext() { return _ref3.apply(this, arguments); }; }(); enablePlatformContext = /*#__PURE__*/function () { var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() { return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: platformContext = true; _context2.next = 3; return refreshPlatformContext(); case 3: case "end": return _context2.stop(); } }, _callee2); })); return function enablePlatformContext() { return _ref5.apply(this, arguments); }; }(); disablePlatformContext = function disablePlatformContext() { platformContext = false; }; if (!platformContext) { _context3.next = 7; break; } _context3.next = 7; return refreshPlatformContext(); case 7: contexts = function contexts() { // check required properties if (platformContext && osType !== undefined && osVersion !== undefined && deviceManufacturer !== undefined && deviceModel !== undefined) { return [{ schema: _constants.MOBILE_CONTEXT_SCHEMA, data: (0, _trackerCore.removeEmptyProperties)({ osType: osType, osVersion: osVersion, deviceManufacturer: deviceManufacturer, deviceModel: deviceModel, carrier: carrier, networkType: networkType, networkTechnology: networkTechnology, appleIdfa: appleIdfa, appleIdfv: appleIdfv, androidIdfa: androidIdfa, physicalMemory: physicalMemory, systemAvailableMemory: systemAvailableMemory, appAvailableMemory: appAvailableMemory, batteryLevel: batteryLevel, batteryState: batteryState, lowPowerMode: lowPowerMode, availableStorage: availableStorage, totalStorage: totalStorage, isPortrait: isPortrait, resolution: resolution, scale: scale, language: language, appSetId: appSetId, appSetIdScope: appSetIdScope }) }]; } else { return []; } }; return _context3.abrupt("return", { enablePlatformContext: enablePlatformContext, disablePlatformContext: disablePlatformContext, refreshPlatformContext: refreshPlatformContext, plugin: { contexts: contexts } }); case 9: case "end": return _context3.stop(); } }, _callee3); })); return _newPlatformContextPlugin.apply(this, arguments); } //# sourceMappingURL=index.js.map