// Metro module 814 (f815). import { createStealthXhr, XHR_READYSTATE_DONE } from "./Module815"; import { debug } from "./Module817"; import { ReactNativeLibraries } from "./Module997"; function $mk117540($env) { return function(a0) { a0($env[0]); }; } let c660_2; const getDevServer = function getDevServer() { let r11; try { const Devtools = ReactNativeLibraries.Devtools; r11 = Devtools !== null ? Devtools !== void 0 ? Devtools.getDevServer() : void 0 : void 0; } catch ($e) { return void 0; } return r11; }; c660_2 = (this ? this.__awaiter : this) || function(c12492_0, c12492_1, a2, c12492_3) { let r2 = a2; let Promise2 = a2; if (!a2) { Promise2 = Promise; r2 = Promise2; } return new r2(function(a0, c23841_1) { let rejected2, step2; let c23841_0 = a0; const fulfilled2 = function fulfilled(a0) { try { step2(c12492_3.next(a0)); } catch ($e) { c23841_1($e); } }; rejected2 = function rejected(a0) { try { step2(c12492_3.throw(a0)); } catch ($e) { c23841_1($e); } }; step2 = function step(a0) { if (a0.done) { c23841_0(a0.value); } else { let env28673; let value = a0.value; const r10 = env28673 = {}; env28673[0] = value; if (!(value instanceof Promise2)) { value = new Promise2($mk117540(r10)); } value.then(fulfilled2, rejected2); } }; const r16 = c12492_3.apply(c12492_0, c12492_1 || []); c12492_3 = r16; const r18 = r16.next(); const { done, value } = r18; if (done) { a0(value); } else { let env23842; const r21 = env23842 = {}; env23842[0] = value; (value instanceof Promise2 ? value : new Promise2($mk117540(r21))).then(fulfilled2, rejected2); } }); }; export async function fetchSourceContext(stack) { return new Promise((resolve) => { let stealthXhr; L9: { L6: { try { stealthXhr = createStealthXhr(); if (stealthXhr) { const r20 = (function getSentryMetroSourceContextUrl() { const devServer = getDevServer(); if (devServer) { return `${devServer.url}__sentry/context`; } })(); if (r20) { stealthXhr.open("POST", r20, true); stealthXhr.setRequestHeader("Content-Type", "application/json"); stealthXhr.send(JSON.stringify({ stack })); stealthXhr.onreadystatechange = () => { if (stealthXhr.readyState === XHR_READYSTATE_DONE) { if (stealthXhr.status !== 200) { resolve(stack); } try { const r21 = JSON.parse(stealthXhr.responseText); const isArray = Array.isArray(r21.stack); if (isArray) { resolve(r21.stack); } else { resolve(stack); } } catch ($e) { resolve(stack); } } }; stealthXhr.onerror = () => { resolve(stack); }; break L9; } debug.error("Could not fetch source context. No dev server URL found."); resolve(stack); break L6; } resolve(stack); } catch ($e) { debug.error("Could not fetch source context.", $e); resolve(stack); break L9; } return void 0; } return void 0; } }); } export function parseErrorStack(a0) { if (ReactNativeLibraries.Devtools) { return ReactNativeLibraries.Devtools.parseErrorStack(a0); } throw new Error("React Native Devtools not available."); } export function symbolicateStackTrace(a0, a1) { if (ReactNativeLibraries.Devtools) { return ReactNativeLibraries.Devtools.symbolicateStackTrace(a0, a1); } throw new Error("React Native Devtools not available."); } export { getDevServer };