@sentry/remix
Version:
Official Sentry SDK for Remix
76 lines (72 loc) • 2.54 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const core = require('@sentry/core');
const debugBuild = require('./debug-build.js');
const formData = require('./formData.js');
const response = require('./vendor/response.js');
async function storeFormDataKeys(args, span, formDataCapture) {
try {
const clonedRequest = args.request.clone();
const formData$1 = await clonedRequest.formData();
formData.applyFormDataAttributes(span, formData$1, formDataCapture);
} catch (e) {
debugBuild.DEBUG_BUILD && core.debug.warn("Failed to read FormData from request", e);
}
}
function convertRemixRouteIdToPath(routeId) {
const path = routeId.replace(/^routes\//, "");
if (path === "_index") {
return "/";
}
const segments = path.split(".");
const pathSegments = [];
for (let i = 0; i < segments.length; i++) {
const segment = segments[i];
if (!segment) {
continue;
}
if (segment.startsWith("_") && segment !== "_index") {
continue;
}
if (segment === "_index" && i === segments.length - 1) {
continue;
}
const pathSegment = segment.endsWith("_") ? segment.slice(0, -1) : segment;
if (pathSegment === "$") {
pathSegments.push(":*");
continue;
}
if (pathSegment.startsWith("$")) {
const paramName = pathSegment.substring(1);
pathSegments.push(`:${paramName}`);
} else {
pathSegments.push(pathSegment);
}
}
const routePath = pathSegments.length > 0 ? `/${pathSegments.join("/")}` : "/";
return routePath;
}
function isCloudflareEnv() {
return typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare");
}
function getTransactionName(routes, url) {
const matches = response.matchServerRoutes(routes, url.pathname);
const match = matches?.[matches.length - 1];
if (!match) {
return [url.pathname, "url"];
}
const routeId = match.route.id || "no-route-id";
const parameterizedPath = convertRemixRouteIdToPath(routeId);
return [parameterizedPath, "route"];
}
function createRoutes(manifest, parentId) {
return Object.entries(manifest).filter(([, route]) => route.parentId === parentId).map(([id, route]) => ({
...route,
children: createRoutes(manifest, id)
}));
}
exports.convertRemixRouteIdToPath = convertRemixRouteIdToPath;
exports.createRoutes = createRoutes;
exports.getTransactionName = getTransactionName;
exports.isCloudflareEnv = isCloudflareEnv;
exports.storeFormDataKeys = storeFormDataKeys;
//# sourceMappingURL=utils.js.map