apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.
88 lines • 2.11 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { isMiddleware } from "hono/utils/handler";
import { getPackageVersion } from "../common/packageVersions.js";
function getAppInfo(app, appVersion) {
const versions = [];
if (process.versions.node) {
versions.push([
"nodejs",
process.versions.node
]);
}
if (process.versions.bun) {
versions.push([
"bun",
process.versions.bun
]);
}
const honoVersion = getPackageVersion("hono");
const apitallyVersion = getPackageVersion("../..");
if (honoVersion) {
versions.push([
"hono",
honoVersion
]);
}
if (apitallyVersion) {
versions.push([
"apitally",
apitallyVersion
]);
}
if (appVersion) {
versions.push([
"app",
appVersion
]);
}
return {
paths: listEndpoints(app),
versions: Object.fromEntries(versions),
client: "js:hono"
};
}
__name(getAppInfo, "getAppInfo");
function listEndpoints(app) {
const endpoints = [];
app.routes.forEach((route) => {
if (![
"ALL",
"HEAD",
"OPTIONS"
].includes(route.method.toUpperCase()) && !isMiddleware(route.handler)) {
endpoints.push({
method: route.method.toUpperCase(),
path: route.path
});
}
});
return endpoints;
}
__name(listEndpoints, "listEndpoints");
function extractZodErrors(responseJson) {
var _a;
try {
const errors = [];
if (responseJson && responseJson.success === false && responseJson.error && responseJson.error.name === "ZodError") {
const zodError = responseJson.error;
(_a = zodError.issues) == null ? void 0 : _a.forEach((zodIssue) => {
errors.push({
loc: zodIssue.path.join("."),
msg: zodIssue.message,
type: zodIssue.code
});
});
}
return errors;
} catch (error) {
return [];
}
}
__name(extractZodErrors, "extractZodErrors");
export {
extractZodErrors,
getAppInfo,
listEndpoints
};
//# sourceMappingURL=utils.js.map