Files
doneit-web/.angular/cache/14.2.12/babel-webpack/b900e9759d8b5738f1931642715f554b.json
T

1 line
26 KiB
JSON
Raw Normal View History

2023-06-30 09:54:21 +01:00
{"ast":null,"code":"import { _optionalChain } from './buildPolyfills';\nimport { isString, isPlainObject } from './is.js';\nimport { normalize } from './normalize.js';\nimport { stripUrlQueryAndFragment } from './url.js';\nvar DEFAULT_INCLUDES = {\n ip: false,\n request: true,\n transaction: true,\n user: true\n};\nvar DEFAULT_REQUEST_INCLUDES = ['cookies', 'data', 'headers', 'method', 'query_string', 'url'];\nvar DEFAULT_USER_INCLUDES = ['id', 'username', 'email'];\n\n/**\n * Sets parameterized route as transaction name e.g.: `GET /users/:id`\n * Also adds more context data on the transaction from the request\n */\nfunction addRequestDataToTransaction(transaction, req, deps) {\n if (!transaction) return;\n if (!transaction.metadata.source || transaction.metadata.source === 'url') {\n // Attempt to grab a parameterized route off of the request\n transaction.setName(...extractPathForTransaction(req, {\n path: true,\n method: true\n }));\n }\n transaction.setData('url', req.originalUrl || req.url);\n if (req.baseUrl) {\n transaction.setData('baseUrl', req.baseUrl);\n }\n transaction.setData('query', extractQueryParams(req, deps));\n}\n\n/**\n * Extracts a complete and parameterized path from the request object and uses it to construct transaction name.\n * If the parameterized transaction name cannot be extracted, we fall back to the raw URL.\n *\n * Additionally, this function determines and returns the transaction name source\n *\n * eg. GET /mountpoint/user/:id\n *\n * @param req A request object\n * @param options What to include in the transaction name (method, path, or a custom route name to be\n * used instead of the request's route)\n *\n * @returns A tuple of the fully constructed transaction name [0] and its source [1] (can be either 'route' or 'url')\n */\nfunction extractPathForTransaction(req, options = {}) {\n var method = req.method && req.method.toUpperCase();\n let path = '';\n let source = 'url';\n\n // Check to see if there's a parameterized route we can use (as there is in Express)\n if (options.customRoute || req.route) {\n path = options.customRoute || `${req.baseUrl || ''}${req.route && req.route.path}`;\n source = 'route';\n }\n\n // Otherwise, just take the original URL\n else if (req.originalUrl || req.url) {\n path = stripUrlQueryAndFragment(req.originalUrl || req.url || '');\n }\n let name = '';\n if (options.method && method) {\n name += method;\n }\n if (options.method && options.path) {\n name += ' ';\n }\n if (options.path && path) {\n name += path;\n }\n return [name, source];\n}\n\n/** JSDoc */\nfunction extractTransaction(req, type) {\n switch (type) {\n case 'path':\n {\n return extractPathForTransaction(req, {\n path: true\n })[0];\n }\n case 'handler':\n {\n return req.route && req.route.stack && req.route.stack[0] && req.route.stack[0].name || '<anonymous>';\n }\n case 'methodPath':\n default:\n {\n return extractPathForTransaction(req, {\n path: true,\n method: true\n })[0];\n }\n }\n}\n\n/** JSDoc */\nfunction extractUserData(user, keys) {\n var extractedUser = {};\n var attributes = Array.isArray(keys) ? keys : DEFAULT_USER_INCLUDES;\n attributes.forEach(key => {\n if (user && key in user) {\n extractedUser[key] = user[key];\n }\n });\n return extractedUser;\n}\n\n/**\n * Normalize data from the request object, accounting for framework differences.\n *\n * @param req The request object from which to extract data\n * @param options.include An optional array of keys to include in the normalized data. Defaults to\n * DEFAULT_REQUEST_INCLUDES if not provided.\n * @param options.deps Injected, platform-specific dependencies\n * @returns An object containing normalized request data\n */\nfunction extractRequestData(req, options) {\n const {\n include = DEFAULT_REQUEST_INCLUDES,\n deps\n } = options || {};\n var requestData = {};\n\n // headers:\n // node, express, koa, nex