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OAAO,IAEX,wBAAwB,oBAAoB,EAAS,GAAM,EAC/D,EAEA,SAAS,eAAiB,SAAU,GAChC,eAAiB,wBAAwB,UAAU,EACvD,EAEA,SAAS,aAAe,SAAU,EAAa,EAAe,EAAS,GACnE,IAAK,cACD,OAAO,IAEX,wBAAwB,oBACpB,EACA,EACA,EACA,EAER,EAEA,SAAS,WAAa,SAAU,GAC5B,eAAiB,wBAAwB,WAAW,EACxD,EAEA,SAAS,mBAAqB,SAAU,GAChC,eAAiB,MAAM,iBAAiB,IACxC,wBAAwB,mBAAmB,EAEnD,EAEA,SAAS,aAAe,SAAU,EAAK,GAC/B,eAAiB,MAAM,iBAAiB,IACxC,cAAc,aAAa,EAAK,EAExC,EAEA,SAAS,yBAA2B,WAChC,eAAiB,wBAAwB,cAC7C,EAEA,SAAS,sBAAwB,SAAU,EAAY,GACnD,eACI,wBAAwB,sBAAsB,EAAY,EAClE,EAEA,SAAS,oBAAsB,SAAU,EAAY,GACjD,eACI,wBAAwB,oBAAoB,EAAY,EAChE,EAEA,SAAS,aAAe,WACpB,OAAO,wBAAwB,cACnC,EAEA,SAAS,uBAAyB,SAAU,EAAY,GACpD,eACI,wBAAwB,0BACpB,EACA,EAEZ,EAgHA,OAAO,QAAU","file":"/npm/apminsight@5.6.1/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.48.0.\n * Original file: /npm/apminsight@5.6.1/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var dotenv = require(\"dotenv\");\ndotenv.config();\nvar agent = require(\"./lib/agent\");\nvar utils = require(\"./lib/util/utils\");\nvar packageJson = require(\"./package.json\");\nvar path = require(\"path\");\nvar fs = require(\"fs\");\nconst constants = require('./lib/constants.js');\n\nvar agentInstance;\n\nfunction includeAgentInfo(options) {\n    options = options || {};\n    var version = packageJson.version;\n    var lastIndex = version.lastIndexOf(\".\");\n    options.agentVersion = version.substring(0, lastIndex);\n    options.agentFullVersion = version;\n    options.agentInstallPath = __dirname;\n}\n\nfunction AgentAPI() {\n    if (\n        process.env.APMINSIGHT_AGENT_DISABLE &&\n        process.env.APMINSIGHT_AGENT_DISABLE.toLowerCase() == \"true\"\n    ) {\n        process.stdout.write(\"\\n[APM] Apminsight agent is disabled.\\n\");\n        return;\n    }\n    if (!agentInstance) {\n        var options = readInfoFromFile();\n        includeAgentInfo(options);\n        agent.init(options);\n        agentInstance = global.apmInsightAgentInstance;\n    }\n    return AgentAPI;\n}\n\nAgentAPI();\n\nAgentAPI.config = function () {\n    if (process.env.APMINSIGHT_AGENT_DISABLE) {\n        process.stdout.write(\"\\n[APM] Apminsight agent is disabled.\\n\");\n        return;\n    }\n    if (!agentInstance) {\n        var config = readInfoFromFile();\n        includeAgentInfo(config);\n        agent.init(config);\n        agentInstance = global.apmInsightAgentInstance;\n    }\n};\n\nAgentAPI.startWebTransaction = function (txnName, func) {\n    if (!agentInstance) {\n        return func();\n    }\n    apmInsightAgentInstance.startApiTransaction(txnName, func, false);\n};\n\nAgentAPI.startBackgroundTransaction = function (txnName, func) {\n    if (!agentInstance) {\n        return func();\n    }\n    apmInsightAgentInstance.startApiTransaction(txnName, func, true);\n};\n\nAgentAPI.endTransaction = function (err) {\n    agentInstance && apmInsightAgentInstance.endApiTxn(err);\n};\n\nAgentAPI.startTracker = function (trackerName, componentName, handler, cb) {\n    if (!agentInstance) {\n        return handler();\n    }\n    apmInsightAgentInstance.createCustomTracker(\n        trackerName,\n        componentName,\n        handler,\n        cb\n    );\n};\n\nAgentAPI.trackError = function (err) {\n    agentInstance && apmInsightAgentInstance.trackError(err);\n};\n\nAgentAPI.setTransactionName = function (name) {\n    if (agentInstance && utils.isNonEmptyString(name)) {\n        apmInsightAgentInstance.setTransactionName(name);\n    }\n};\n\nAgentAPI.addParameter = function (key, value) {\n    if (agentInstance && utils.isNonEmptyString(key)) {\n        agentInstance.addParameter(key, value);\n    }\n};\n\nAgentAPI.ignoreCurrentTransaction = function () {\n    agentInstance && apmInsightAgentInstance.ignoreCurTxn();\n};\n\nAgentAPI.incrementCustomMetric = function (metricName, incrValue) {\n    agentInstance &&\n        apmInsightAgentInstance.incrementCustomMetric(metricName, incrValue);\n};\n\nAgentAPI.averageCustomMetric = function (metricName, metricValue) {\n    agentInstance &&\n        apmInsightAgentInstance.averageCustomMetric(metricName, metricValue);\n};\n\nAgentAPI.getRumScript = function () {\n    return apmInsightAgentInstance.getRumScript();\n};\n\nAgentAPI.instrumentWebFramework = function (moduleName, moduleInfo) {\n    agentInstance &&\n        apmInsightAgentInstance.instrumentingWebFramework(\n            moduleName,\n            moduleInfo\n        );\n};\n\nfunction readInfoFromFile() {\n    var options = {};\n    if(process.env.APMINSIGHT_AUTOPROFILER_CONF_FILEPATH && fs.existsSync(process.env.APMINSIGHT_AUTOPROFILER_CONF_FILEPATH)){\n        try{\n            let oneAgentData = utils.parseIniFile(process.env.APMINSIGHT_AUTOPROFILER_CONF_FILEPATH);\n            if(!utils.isEmpty(oneAgentData)){\n                let oneAgentSectionInfo = oneAgentData[constants.oneAgentSectionInfo];\n                let autoprofilerVersion = oneAgentSectionInfo[constants.autoProfilerVersionKey];\n                let operatorVersion = oneAgentSectionInfo[constants.operatorVersionKey];\n                const encryptedLicenseKey = oneAgentSectionInfo[constants.oneAgentLicenseKey];\n                const iV = oneAgentSectionInfo[constants.oneAgentIV];\n                const saltKey = oneAgentSectionInfo[constants.oneAgentSaltKey];\n                const serverMonitorKey = oneAgentSectionInfo[constants.oneAgentServerMonitorKey];\n                const decryptedLicenseKey = encryptedLicenseKey && saltKey && iV && utils.toDecryptKey(encryptedLicenseKey, saltKey, iV);\n                if(!utils.isEmpty(decryptedLicenseKey)){\n                    options.licenseKey = encryptedLicenseKey;\n                }else{\n                    throw new Error('oneagent decryption failed with empty');\n                }\n                if(!utils.isEmpty(iV)){\n                    constants.initVector = iV;\n                }\n                if(!utils.isEmpty(saltKey)){\n                    constants.securitykey = saltKey;\n                }\n                if(!utils.isEmpty(serverMonitorKey)){\n                    options.serverMonitorKey = serverMonitorKey;\n                }\n                if(!utils.isEmpty(autoprofilerVersion)){\n                    options.autoProfilerVersion = autoprofilerVersion;\n                }\n                if(!utils.isEmpty(operatorVersion)){\n                    options.operatorVersion = operatorVersion;\n                }\n                return options;\n            }\n        }catch(error){\n            //continuing with normal flow\n            options = {};\n        }\n    }\n\n    var agentInfoPath = path.join(process.cwd(), \"apminsightnode.json\");\n    if (fs.existsSync(agentInfoPath)) {\n        try {\n            var agentData = fs.readFileSync(agentInfoPath, {\n                encoding: \"utf8\",\n                flag: \"r\"\n            });\n            if (utils.isEmpty(agentData)) {\n                utils\n                    .writeStream()\n                    .write(\"[APM] apminsightnode.json file is empty.\\n\");\n            } else {\n                options = JSON.parse(agentData);\n                var encryptedData = getEncryptedKey(options);\n                if (!utils.isBoolean(encryptedData)) {\n                    //Replacing the licenseKey with encrypted data\n                    options.licenseKey = encryptedData;\n                    //Serialize as JSON and Write it to the file\n                    try {\n                        fs.writeFileSync(\n                            agentInfoPath,\n                            JSON.stringify(options)\n                        );\n                    } catch (err) {}\n                }\n            }\n            options.agentInfoPath = agentInfoPath;\n            return options;\n        } catch (err) {\n            utils\n                .writeStream()\n                .write(\n                    \"[APM] Error while reading the apminsightnode.json file :: \" +\n                        err +\n                        \"\\n\"\n                );\n            return options;\n        }\n    } else {\n        if (\n            !(\n                process.env.APMINSIGHT_LICENSE_KEY &&\n                process.env.APMINSIGHT_APP_NAME\n            )\n        ) {\n            utils\n                .writeStream()\n                .write(\n                    \"[APM] This version of APM Insight Node.js Agent requires creation of a configuration file (apminsightnode.json) in \" +\n                        process.cwd() +\n                        \" or Use of Environment variables. Please refer the help docs for more information.\\n\"\n                );\n        }\n        return options;\n    }\n}\n\nfunction getEncryptedKey(options) {\n    //decryption is necessary to avoid encryption on already encrypted data\n    var decryptedData = utils.toDecryptKey(options.licenseKey);\n    if (utils.isBoolean(decryptedData)) {\n        var encryptedData = utils.toEncryptKey(options.licenseKey);\n        return encryptedData;\n    } else {\n        return false;\n    }\n}\n\nmodule.exports = AgentAPI;\n"]}