apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, Hapi, and Koa.
113 lines • 3.24 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var utils_exports = {};
__export(utils_exports, {
extractZodErrors: () => extractZodErrors,
getAppInfo: () => getAppInfo,
listEndpoints: () => listEndpoints
});
module.exports = __toCommonJS(utils_exports);
var import_handler = require("hono/utils/handler");
var import_packageVersions = require("../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 = (0, import_packageVersions.getPackageVersion)("hono");
const apitallyVersion = (0, import_packageVersions.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()) && !(0, import_handler.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");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
extractZodErrors,
getAppInfo,
listEndpoints
});
//# sourceMappingURL=utils.cjs.map