react-native-analytics-debugger
Version:
The Avo react-native debugger
520 lines (462 loc) • 18.5 kB
JavaScript
// Generated by Avo VERSION 56.1.0, PLEASE EDIT WITH CARE
/* eslint-disable */
(function(exports) {
var __AVO_DEV__ = false;
var __AVO_ENV__ = null;
var __REPORT_FAILURE_AS__ = null;
var __STRICT__ = null;
var __MOBILE_DEBUGGER__ = null;
// polyfill Array.isArray
if (!Array.isArray) {
Array.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
// polyfill Object.assign
if (typeof Object.assign !== 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
if (!Object.keys) {
Object.keys = (function() {
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
return function(obj) {
if (typeof obj !== 'function' && (typeof obj !== 'object' || obj === null)) {
throw new TypeError('Object.keys called on non-object');
}
var result = [], prop, i;
for (prop in obj) {
if (hasOwnProperty.call(obj, prop)) {
result.push(prop);
}
}
if (hasDontEnumBug) {
for (i = 0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) {
result.push(dontEnums[i]);
}
}
}
return result;
};
}());
}
// polyfill Array.indexOf
if (!Array.prototype.indexOf) Array.prototype.indexOf = (function(Object, max, min){
"use strict";
return function indexOf(member, fromIndex) {
if(this===null||this===undefined)throw TypeError("Array.prototype.indexOf called on null or undefined");
var that = Object(this), Len = that.length >>> 0, i = min(fromIndex | 0, Len);
if (i < 0) i = max(0, Len+i); else if (i >= Len) return -1;
if(member===void 0){ for(; i !== Len; ++i) if(that[i]===void 0 && i in that) return i; // undefined
}else if(member !== member){ for(; i !== Len; ++i) if(that[i] !== that[i]) return i; // NaN
}else for(; i !== Len; ++i) if(that[i] === member) return i; // all else
return -1; // if the value was not found, then return -1
};
})(Object, Math.max, Math.min);
var array_difference, AvoAssert, AvoLogger;
array_difference = function array_difference(a1, a2) {
var result = [];
for (var i = 0; i < a1.length; i++) {
if (a2.indexOf(a1[i]) === -1) {
result.push(a1[i]);
}
}
return result;
}
AvoAssert = {
assertObject: function assertObject(propertyId, propName, obj) {
if (typeof obj !== 'object') {
var message = propName +
' should be of type object but you provided type ' +
typeof obj +
' with value ' +
JSON.stringify(obj);
return [{tag: 'expectedObjectType', propertyId: propertyId, message: message, actualType: typeof obj}];
} else {
return [];
}
},
assertString: function assertString(propertyId, propName, str) {
if (typeof str !== 'string') {
var message = propName +
' should be of type string but you provided type ' +
typeof str +
' with value ' +
JSON.stringify(str);
return [{tag: 'expectedStringType', propertyId: propertyId, message: message, actualType: typeof str}];
} else {
return [];
}
},
assertInt: function assertInt(propertyId, propName, int) {
if (typeof int === 'number' && int !== Math.round(int)) {
var message = propName +
' should be of type int but you provided type float with value ' +
JSON.stringify(int);
return [{tag: 'expectedIntType', propertyId: propertyId, actualType: 'float'}];
} else if (typeof int !== 'number') {
var message = propName +
' should be of type int but you provided type ' +
typeof int +
' with value ' +
JSON.stringify(int);
return [{tag: 'expectedIntType', propertyId: propertyId, message: message, actualType: typeof int}];
} else {
return [];
}
},
assertLong: function assertLong(propertyId, propName, long) {
if (typeof long === 'number' && long !== Math.round(long)) {
var message = propName +
' should be of type long but you provided type float with value ' +
JSON.stringify(long);
return [{tag: 'expectedLongType', propertyId: propertyId, actualType: 'float'}];
} else if (typeof long !== 'number') {
var message = propName +
' should be of type long but you provided type ' +
typeof long +
' with value ' +
JSON.stringify(long);
return [{tag: 'expectedLongType', propertyId: propertyId, message: message, actualType: typeof long}];
} else {
return [];
}
},
assertFloat: function assertFloat(propertyId, propName, float) {
if (typeof float !== 'number') {
var message = propName +
' should be of type float but you provided type ' +
typeof float +
' with value ' +
JSON.stringify(float);
return [{tag: 'expectedFloatType', propertyId: propertyId, message: message, actualType: typeof float}];
} else {
return [];
}
},
assertBool: function assertBool(propertyId, propName, bool) {
if (typeof bool !== 'boolean') {
var message = propName +
' should be of type boolean but you provided type ' +
typeof bool +
' with value ' +
JSON.stringify(bool);
return [{tag: 'expectedBoolType', propertyId: propertyId, message: message, actualType: typeof bool}];
} else {
return [];
}
},
assertMax: function assertMax(propertyId, propName, max, value) {
if (value > max) {
var message = propName +
' has a maximum value of ' +
max +
' but you provided the value ' +
JSON.stringify(value);
return [{tag: 'expectedMax', propertyId: propertyId, message: message}];
} else {
return [];
}
},
assertMin: function assertMin(propertyId, propName, min, value) {
if (value < min) {
var message = propName +
' has a minimum value of ' +
min +
' but you provided the value ' +
JSON.stringify(value);
return [{tag: 'expectedMin', propertyId: propertyId, message: message}];
} else {
return [];
}
},
assertList: function assertList(propertyId, propName, value) {
if (!Array.isArray(value)) {
var message = propName + ' should be of type list but you provided type ' + typeof value;
return [{tag: 'expectedList', propertyId: propertyId, message: message, actualType: typeof value}];
} else {
return [];
}
},
assertNoAdditionalProperties: function assertNoAdditionalProperties(eventName, input, spec) {
var additionalKeys = array_difference(input, spec);
if (additionalKeys.length) {
var message = "Additional properties when sending event " + eventName + ": " + JSON.stringify(additionalKeys);
return [{tag: 'expectedNoAdditionalProperties', additionalProperties: additionalKeys, message: message}];
} else {
return [];
}
},
assertNoAdditionalUserProperties: function assertNoAdditionalProperties(eventName, input, spec) {
var additionalKeys = array_difference(input, spec);
if (additionalKeys.length) {
var message = "Additional user properties when sending event " + eventName + ": " + JSON.stringify(additionalKeys);
return [{tag: 'expectedNoAdditionalUserProperties', additionalProperties: additionalKeys, message: message}];
} else {
return [];
}
}
};
AvoLogger = {
logEventSent: function logEventSent(eventName, eventProperties, userProperties) {
console.log("[avo] Event Sent:", eventName, "Event Props:", eventProperties, "User Props:", userProperties);
}
};
var _avo_invoke, _avo_invoke_meta;
var _avo_sampling_rate = 1.0;
function _avo_invoke_payload(body) {
if (typeof window === 'undefined') { return; }
if (_avo_sampling_rate > 0) {
if (Math.random() < _avo_sampling_rate) {
fetch("https://api.avo.app/i", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(body)
}).then(function(res) { return res.json(); }).then(function(data) { _avo_sampling_rate = data.sa; }).catch(function() {});
}
}
}
_avo_invoke = function _avo_invoke(env, eventId, hash, messages, origin) {
_avo_invoke_payload({
"ac": "P154NQSkhKXTz2HFu6eS",
"br": "LowQacyet",
"en": env,
"ev": eventId,
"ha": hash,
"sc": "fwtXqAc0fCLy7b7oGW40",
"se": (new Date()).toISOString(),
"so": "RMmNd_AIl",
"va": messages.length === 0,
"me": messages,
"or": origin
});
}
_avo_invoke_meta = function _avo_invoke_meta(env, type, messages, origin) {
_avo_invoke_payload({
"ac": "P154NQSkhKXTz2HFu6eS",
"br": "LowQacyet",
"en": env,
"ty": type,
"sc": "fwtXqAc0fCLy7b7oGW40",
"se": (new Date()).toISOString(),
"so": "RMmNd_AIl",
"va": messages.length === 0,
"me": messages,
"or": origin
});
}
var Client = {
CLOUD_FUNCTIONS: "Cloud Functions",
WEB: "Web",
LANDING_PAGE: "Landing Page",
CLI: "Cli",
WEB_DEBUGGER: "Web Debugger",
ANDROID_DEBUGGER: "Android Debugger",
IOS_DEBUGGER: "Ios Debugger",
REACT_NATIVE_DEBUGGER_IOS: "React Native Debugger (ios)",
REACT_NATIVE_DEBUGGER_ANDROID: "React Native Debugger (android)",
};
function assertVersion(version, label_) {
var messages = [];
messages = messages.concat(AvoAssert.assertString("2fad5bf3-7782-49a2-acc2-825daf823095", label_ ? 'Version' + ': ' + label_ : 'Version', version));
return messages;
}
function assertSchemaId(schemaId, label_) {
var messages = [];
messages = messages.concat(AvoAssert.assertString("40958e87-d69a-4d5a-98f8-b36922466787", label_ ? 'Schema Id' + ': ' + label_ : 'Schema Id', schemaId));
return messages;
}
function assertClient(client, label_) {
var messages = [];
messages = messages.concat(AvoAssert.assertString("9e5c4ff5-d5f6-4e82-b061-d5fa02755aae", label_ ? 'Client' + ': ' + label_ : 'Client', client));
if ("Cloud Functions" !== client && "Web" !== client &&
"Landing Page" !== client && "Cli" !== client &&
"Web Debugger" !== client && "Android Debugger" !== client &&
"Ios Debugger" !== client &&
"React Native Debugger (ios)" !== client &&
"React Native Debugger (android)" !== client) {
var message = (label_ ? 'Client' + ': ' + label_ : 'Client') + " should match one of the following values [ Cloud Functions | Web | Landing Page | Cli | Web Debugger | Android Debugger | Ios Debugger | React Native Debugger (ios) | React Native Debugger (android) ] but you provided the value " + client
messages = messages.concat([{tag: 'expectedStringMatch', propertyId: "9e5c4ff5-d5f6-4e82-b061-d5fa02755aae", message: message}]);
}
return messages;
}
function assertOptionalFrameLocation(frameLocation, label_) {
var messages = [];
if (frameLocation !== undefined && frameLocation !== null) {
messages = messages.concat(AvoAssert.assertString("zXjbg4Ek9", label_ ? 'Frame Location' + ': ' + label_ : 'Frame Location', frameLocation));
}
return messages;
}
var sysClient;
var sysVersion;
function setSystemProperties(properties) {
if (properties.client) {
sysClient = properties.client;
assertClient(sysClient);
}
if (properties.version) {
sysVersion = properties.version;
assertVersion(sysVersion);
}
}
function setSystemProperties_(properties) {
if (properties.client) {
sysClient = properties.client;
assertClient(sysClient);
}
if (properties.version) {
sysVersion = properties.version;
assertVersion(sysVersion);
}
}
var CustomNodeJS;
function setup_(options, systemProperties, CustomNodeJSDestination,
destinationOptions) {
if (options.validateProperties === true) {
__AVO_DEV__ = true;
}
setSystemProperties_(systemProperties);
destinationOptions = destinationOptions || {};
if (options.useProductionKey) {
} else {
}
CustomNodeJS = CustomNodeJSDestination;
CustomNodeJS.make(options.useProductionKey);
if (__AVO_DEV__) {
// debug console in Avo
_avo_invoke_meta(__AVO_ENV__, 'setup', [], 'setup');
}
}
function initAvo(options, systemProperties, destinationOptions,
CustomNodeJSDestination) {
if (__AVO_ENV__ !== null) {
return;
}
__AVO_ENV__ = options.env.toLowerCase();
if (options.strict !== undefined) {
__STRICT__ = options.strict !== false;
}
if (options.reportFailureAs !== undefined) {
__REPORT_FAILURE_AS__ = options.reportFailureAs;
}
if (options.debugger !== undefined) {
__MOBILE_DEBUGGER__ = options.debugger;
}
if (__AVO_ENV__ !== 'prod') {
__AVO_DEV__ = true;
}
setSystemProperties(systemProperties);
destinationOptions = destinationOptions || {};
if (__AVO_ENV__ === 'prod') {
}
if (__AVO_ENV__ === 'dev') {
}
CustomNodeJS = CustomNodeJSDestination;
CustomNodeJS.make(__AVO_ENV__);
if (__AVO_DEV__) {
// debug console in Avo
_avo_invoke_meta(__AVO_ENV__, 'init', [], 'init');
}
}
/**
* Debugger Started: Sent when the web debugger is started.
*
* @param {object} properties - the properties associatied with this event
* @param {string} properties.frameLocation - Describes from where the debugger was started.
* @param {string} properties.schemaId - The ID of the schema that this event is related to.
*
* @see {@link https://www.avo.app/schemas/fwtXqAc0fCLy7b7oGW40/branches/LowQacyet/events/Od3PNKHK1}
*/
function debuggerStarted(properties) {
properties = properties || {};
if ((__AVO_DEV__) || (!__AVO_DEV__ && __MOBILE_DEBUGGER__ !== null && __MOBILE_DEBUGGER__.isEnabled())) {
// assert properties
var messages = [];
messages = messages.concat(assertOptionalFrameLocation(properties.frameLocation));
messages = messages.concat(assertSchemaId(properties.schemaId));
messages = messages.concat(assertClient(sysClient));
messages = messages.concat(assertVersion(sysVersion));
messages = messages.concat(AvoAssert.assertNoAdditionalProperties("Debugger Started", Object.keys(properties), [
"frameLocation",
"schemaId"
]));
// debug console in Avo
_avo_invoke(__AVO_ENV__, "Od3PNKHK1", "ef168ad1090b94d63666f3f902416cb7692256e0a605302004021b62d203fe2e", messages.map(function(m) { return Object.assign({}, {tag: m.tag, propertyId: m.propertyId, additionalProperties: m.additionalProperties, actualType: m.actualType}); }), 'event');
AvoLogger.logEventSent("Debugger Started", {
"Frame Location": properties.frameLocation,
"Schema Id": properties.schemaId,
"Client": sysClient,
"Version": sysVersion,
}, {});
if ((__AVO_DEV__ && __MOBILE_DEBUGGER__ !== null) || (!__AVO_DEV__ && __MOBILE_DEBUGGER__ !== null && __MOBILE_DEBUGGER__.isEnabled())) {
// Avo mobile debugger
__MOBILE_DEBUGGER__.postEvent("Od3PNKHK1", Date.now(), "Debugger Started", messages, [
{id: "40958e87-d69a-4d5a-98f8-b36922466787", name: "Schema Id", value: properties.schemaId},
{id: "zXjbg4Ek9", name: "Frame Location", value: properties.frameLocation},
{id: "2fad5bf3-7782-49a2-acc2-825daf823095", name: "Version", value: sysVersion},
{id: "9e5c4ff5-d5f6-4e82-b061-d5fa02755aae", name: "Client", value: sysClient},
], []);
}
if (__AVO_DEV__ && ((__STRICT__ === null && !(__MOBILE_DEBUGGER__ !== null && __MOBILE_DEBUGGER__.isEnabled())) || __STRICT__)) {
// throw exception if messages is not empty
if (messages.length !== 0) {
throw new Error("Error sending event 'Debugger Started': " + messages[0].message)
}
} else {
messages.forEach(function(m) {
console[__REPORT_FAILURE_AS__ || (__MOBILE_DEBUGGER__ !== null && __MOBILE_DEBUGGER__.isEnabled() ? 'log' : 'error')]("[avo] " + m.message);
});
}
}
// destination CustomNodeJS
CustomNodeJS.logEvent("Debugger Started", {
"Frame Location": properties.frameLocation,
"Schema Id": properties.schemaId,
"Client": sysClient,
"Version": sysVersion,
});
}
exports.Client = Client;
exports.debuggerStarted = debuggerStarted;
exports.setSystemProperties_ = setSystemProperties_;
exports.setSystemProperties = setSystemProperties;
exports.setup_ = setup_;
exports.initAvo = initAvo;
}(typeof exports === 'undefined' ? this.Avo = {} : exports));
// AVOMODULEMAP:"Avo"
// AVOEVENTMAP:["debuggerStarted"]