// Metro module 6449 (f6450). import { stripUrlQueryAndFragment } from "./Module6450"; import { ipHeaderNames, getClientIPAddress } from "./Module6451"; import { parseCookie } from "./Module6452"; import { isString, isPlainObject } from "./isInstanceOf_6375"; import { normalize } from "./normalize_6413"; import { truncate } from "./Module6377"; import { DEBUG_BUILD } from "./Module6367"; import { logger } from "./consoleSandbox_6368"; import { dropUndefinedKeys } from "./addNonEnumerableProperty_6374"; function $mk78633($env) { return (a0) => { const r2 = $env; const r1 = r2[0]; if (r1 && a0 in r1) { r2[1][a0] = r1[a0]; } }; } let c4148_2, _excluded, _excluded2, winterCGHeadersToDict, headersToDict, extractQueryParamsFromUrl; const extractRequestData = function extractRequestData(a0) { let r9; let c15742_0 = a0; let r1 = arguments[1]; if (r1 === void 0) { r1 = {}; } let include = r1.include; if (include === void 0) { include = _excluded; } let c15742_1 = include; const r17 = {}; let c15742_2 = r17; const headers = a0.headers || {}; const method = a0.method; const r10 = headers.host || a0.hostname || a0.host || ""; L16: { if (a0.protocol !== "https") { const socket = a0.socket; r9 = "http"; if (!socket) { break L16; } r9 = a0.socket.encrypted ? "https" : "http"; } else { r9 = "https"; } } const r23 = a0.originalUrl || a0.url || ""; const r25 = r23.startsWith(r9); const url = r25 ? r23 : `${r9}://${r10}${r23}`; include.forEach((item) => { if (item === "headers") { c15742_2.headers = headers; if (!c15742_1.includes("cookies")) { delete c15742_2.headers["cookie"]; } if (!c15742_1.includes("ip")) { ipHeaderNames.forEach((ipHeaderName) => { delete c15742_2.headers[ipHeaderName]; }); } } else if (item === "method") { c15742_2.method = method; } else if (item === "url") { c15742_2.url = url; } else if (item === "cookies") { c15742_2.cookies = c15742_0.cookies || headers.cookie && parseCookie(headers.cookie) || {}; } else if (item === "query_string") { c15742_2.query_string = (function extractQueryParams(a0) { let r25; const r6 = a0.originalUrl || a0.url || ""; if (r6) { const r5 = r6.startsWith("/") ? `http://dogs.are.great${r6}` : r6; try { const r14 = a0.query || new URL(r5).search.slice(1); r25 = r14.length ? r14 : void 0; } catch ($e) { return void 0; } return r25; } })(c15742_0); } else if (item === "data") { if (method !== "GET" && method !== "HEAD") { const body = c15742_0.body; if (body !== void 0) { const data = isString(body) ? body : isPlainObject(body) ? JSON.stringify(normalize(body)) : truncate(`${body}`, 1024); if (data) { c15742_2.data = data; } } } } else { const hasOwnProperty = ({}).hasOwnProperty; if (hasOwnProperty.call(c15742_0, item)) { c15742_2[item] = c15742_0[item]; } } }); return r17; }; winterCGHeadersToDict = function winterCGHeadersToDict(headers) { const r0 = {}; let c15743_0 = r0; try { headers.forEach((item, index) => { if (typeof item === "string") { c15743_0[index] = item; } }); } catch ($e) { if (DEBUG_BUILD) { logger.warn("Sentry failed extracting headers from a request object. If you see this, please file an issue."); } } return r0; }; headersToDict = function headersToDict(a0) { const r5 = Object.create(null); let c15744_0 = r5; try { Object.entries(a0).forEach((item) => { const [r13, r14] = item; if (typeof r14 === "string") { c15744_0[r13] = r14; } }); } catch ($e) { if (DEBUG_BUILD) { logger.warn("Sentry failed extracting headers from a request object. If you see this, please file an issue."); } } return r5; }; extractQueryParamsFromUrl = function extractQueryParamsFromUrl(url) { let r17; if (url) { try { const r14 = new URL(url, "http://dogs.are.great").search.slice(1); r17 = r14.length ? r14 : void 0; } catch ($e) { return void 0; } return r17; } }; c4148_2 = { ip: false, request: true, user: true }; _excluded = ["cookies", "data", "headers", "method", "query_string", "url"]; _excluded2 = ["id", "username", "email"]; export { _excluded2 as DEFAULT_USER_INCLUDES }; export function addNormalizedRequestDataToEvent(a0, a1, a2, a3) { let r110; const r4 = { ...c4148_2, ...a3 ? a3.include : a3 }; if (r4.request) { const r12 = Array.isArray(r4.request) ? [...r4.request] : [..._excluded]; if (r4.ip) { r12.push("ip"); } const r39 = Array.isArray(r12) ? r12 : _excluded; const r41 = {}; const headers2 = { ...a1.headers }; let c15745_0 = headers2; if (r39.includes("headers")) { r41.headers = headers2; if (!r12.includes("cookies")) { delete headers2["cookie"]; } if (!r12.includes("ip")) { ipHeaderNames.forEach((ipHeaderName) => { delete c15745_0[ipHeaderName]; }); } } if (r39.includes("method")) { r41.method = a1.method; } if (r39.includes("url")) { r41.url = a1.url; } if (r39.includes("cookies")) { r41.cookies = a1.cookies || (headers2.cookie ? parseCookie(headers2.cookie) : void 0) || {}; } if (r39.includes("query_string")) { r41.query_string = a1.query_string; } if (r39.includes("data")) { r41.data = a1.data; } a0.request = { ...a0.request, ...r41 }; } if (r4.user) { if (a2.user && isPlainObject(a2.user)) { let env15746; const user = a2.user; let user2 = r4.user; const r113 = env15746 = {}; env15746[0] = user; const r114 = {}; env15746[1] = r114; if (!Array.isArray(user2)) { user2 = _excluded2; } user2.forEach($mk78633(r113)); r110 = r114; } else { r110 = {}; } if (Object.keys(r110).length) { a0.user = { ...r110, ...a0.user }; } } if (r4.ip) { const ip_address = a1.headers && getClientIPAddress(a1.headers) || a2.ipAddress; if (ip_address) { a0.user = { ...a0.user, ip_address }; } } } export function addRequestDataToEvent(a0, a1, a2) { let r57; const r4 = { ...c4148_2, ...a2 ? a2.include : a2 }; if (r4.request) { const include = Array.isArray(r4.request) ? [...r4.request] : [..._excluded]; if (r4.ip) { include.push("ip"); } a0.request = { ...a0.request, ...extractRequestData(a1, { include }) }; } if (r4.user) { if (a1.user && isPlainObject(a1.user)) { let env15747; const user2 = a1.user; let user = r4.user; const r59 = env15747 = {}; env15747[0] = user2; const r60 = {}; env15747[1] = r60; if (!Array.isArray(user)) { user = _excluded2; } user.forEach($mk78633(r59)); r57 = r60; } else { r57 = {}; } if (Object.keys(r57).length) { a0.user = { ...a0.user, ...r57 }; } } if (r4.ip) { const ip_address = a1.headers && getClientIPAddress(a1.headers) || a1.ip || a1.socket && a1.socket.remoteAddress; if (ip_address) { a0.user = { ...a0.user, ip_address }; } } return a0; } export function extractPathForTransaction(a0, r3 = {}) { let r13, r14; const r1 = a0.method && a0.method.toUpperCase(); L21: { if (!r3.customRoute && !a0.route) { const r5 = a0.originalUrl || a0.url; r13 = "url"; r14 = ""; if (!r5) { break L21; } r14 = stripUrlQueryAndFragment(a0.originalUrl || a0.url || ""); r13 = "url"; } else { const r20 = r3.customRoute || `${a0.baseUrl || ""}${a0.route && a0.route.path}`; r13 = "route"; r14 = r20; } } const r29 = r3.method && r1 ? "" + r1 : ""; const r31 = r3.method && r3.path ? r29 + " " : r29; return [r3.path && r14 ? r31 + r14 : r31, r13]; } export { extractQueryParamsFromUrl }; export { extractRequestData }; export { headersToDict }; export function httpRequestToRequestData(a0) { const r7 = a0.headers || {}; const r5 = r7.host || ""; const r4 = a0.socket ? a0.socket.encrypted ? "https" : "http" : "http"; const r18 = a0.url || ""; const r20 = r18.startsWith(r4); const url2 = r20 ? r18 : `${r4}://${r5}${r18}`; const data = a0.body || void 0; const cookies = a0.cookies; return dropUndefinedKeys({ url: url2, method: a0.method, query_string: extractQueryParamsFromUrl(r18), headers: headersToDict(r7), cookies, data }); } export { winterCGHeadersToDict }; export function winterCGRequestToRequestData(a0) { const headers2 = winterCGHeadersToDict(a0.headers); return { method: a0.method, url: a0.url, query_string: extractQueryParamsFromUrl(a0.url), headers: headers2 }; }