apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, and Koa.
110 lines (107 loc) • 2.84 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined") return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
// src/hono/utils.ts
import { isMiddleware } from "hono/utils/handler";
// src/common/packageVersions.ts
import { createRequire } from "module";
function getPackageVersion(name) {
const packageJsonPath = `${name}/package.json`;
try {
return __require(packageJsonPath).version || null;
} catch (error) {
try {
const _require = createRequire(import.meta.url);
return _require(packageJsonPath).version || null;
} catch (error2) {
return null;
}
}
}
__name(getPackageVersion, "getPackageVersion");
// src/hono/utils.ts
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;
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;
}
__name(extractZodErrors, "extractZodErrors");
export {
extractZodErrors,
getAppInfo,
listEndpoints
};
//# sourceMappingURL=utils.js.map