UNPKG

@embrace-io/react-native

Version:
133 lines (132 loc) 7.23 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.initialize = void 0; const react_native_1 = require("react-native"); const otlp_1 = require("./utils/otlp"); const error_1 = require("./utils/error"); const bundle_1 = require("./utils/bundle"); const EmbraceLogger_1 = require("./utils/EmbraceLogger"); const error_2 = require("./api/error"); const bundle_2 = require("./api/bundle"); const EmbraceManagerModule_1 = require("./EmbraceManagerModule"); const initialize = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* ({ sdkConfig, patch, logLevel } = { logLevel: "info" }) { var _a; const isIOS = react_native_1.Platform.OS === "ios"; const logger = new EmbraceLogger_1.default(console, logLevel); const hasNativeSDKStarted = yield EmbraceManagerModule_1.EmbraceManagerModule.isStarted(); // if the sdk started in the native side the follow condition doesn't take any effect. // neither iOS setup() nor start() will be overridden if (!hasNativeSDKStarted) { if (isIOS && !((_a = sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.ios) === null || _a === void 0 ? void 0 : _a.appId) && !(sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.exporters)) { logger.warn("'sdkConfig.ios.appId' is required to initialize Embrace's native SDK if there is no configuration for custom exporters. Please check the Embrace integration docs at https://embrace.io/docs/react-native/integration/"); return Promise.resolve(false); } const { exporters: otlpExporters } = sdkConfig || {}; const startSdkConfig = (isIOS && (sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.ios)) || {}; let isStarted; let otlpStart = null; // separating blocks for throwing their own warning messages individually. // if core/otlp blocks are combined into one try/catch and the otlp package throws an error // the core package won't be able to start the SDK as fallback // `oltpGetStart` has their own try/catch block if (otlpExporters) { if (isIOS && !startSdkConfig.appId) { logger.log("'sdkConfig.ios.appId' not found, only custom exporters will be used"); } // if package is installed/available and exporters are provided get the `start` method otlpStart = (0, otlp_1.oltpGetStart)(logger, otlpExporters); } try { // if the otlp package throws or it is not available, the core package will work as usual printing the proper messages isStarted = otlpStart ? // if OTLP exporter package is available, use it yield otlpStart(startSdkConfig) : // otherwise, uses the core package yield EmbraceManagerModule_1.EmbraceManagerModule.startNativeEmbraceSDK(startSdkConfig); } catch (e) { isStarted = false; logger.warn(`${e}`); } if (!isStarted) { logger.warn("we could not initialize Embrace's native SDK, please check the Embrace integration docs at https://embrace.io/docs/react-native/integration/"); return Promise.resolve(false); } else { logger.log("native SDK was started"); } } // setting version of React Native used by the app (0, bundle_1.setReactNativeVersion)(); // setting version of the Embrace RN package (0, bundle_1.setEmbracePackageVersion)(); if (patch) { (0, bundle_2.setJavaScriptPatch)(patch); } // On Android the Swazzler stores the computed bundle ID as part of the build process and the SDK is able to read it // at run time. On iOS however we don't retain this value so for production builds try and get it from the default // bundle path. if (isIOS && !__DEV__) { try { const bundleJs = yield EmbraceManagerModule_1.EmbraceManagerModule.getDefaultJavaScriptBundlePath(); if (bundleJs) { (0, bundle_2.setJavaScriptBundlePath)(bundleJs); } } catch (e) { logger.warn("we were unable to set the JSBundle path automatically. Please configure this manually to enable crash symbolication. For more information see https://embrace.io/docs/react-native/integration/upload-symbol-files/#pointing-the-embrace-sdk-to-the-javascript-bundle."); } } if (!ErrorUtils) { logger.warn("ErrorUtils is not defined. Not setting exception handler."); return Promise.resolve(false); } // setting the global error handler // this is available through React Native's ErrorUtils ErrorUtils.setGlobalHandler((0, error_2.handleGlobalError)(ErrorUtils.getGlobalHandler(), error_2.handleError)); if (sdkConfig === null || sdkConfig === void 0 ? void 0 : sdkConfig.trackUnhandledRejections) { try { (0, error_1.enableUnhandledRejectionTracking)(); } catch (e) { logger.warn("we were unable to setup tracking of unhandled promise rejections."); } } return Promise.resolve(true); }); exports.initialize = initialize; __exportStar(require("./api/breadcrumb"), exports); __exportStar(require("./api/bundle"), exports); __exportStar(require("./api/component"), exports); __exportStar(require("./api/error"), exports); __exportStar(require("./api/log"), exports); __exportStar(require("./api/session"), exports); __exportStar(require("./api/network"), exports); __exportStar(require("./api/user"), exports); __exportStar(require("./hooks/useEmbrace"), exports); __exportStar(require("./hooks/useEmbraceIsStarted"), exports); __exportStar(require("./hooks/useOrientationListener"), exports); __exportStar(require("./interfaces"), exports);