apitally
Version:
Simple API monitoring & analytics for REST APIs built with Express, Fastify, NestJS, AdonisJS, Hono, H3, Elysia, and Koa.
113 lines (108 loc) • 3.52 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);
// src/adonisjs/index.ts
var adonisjs_exports = {};
__export(adonisjs_exports, {
captureError: () => captureError,
configure: () => configure,
defineConfig: () => defineConfig,
setConsumer: () => setConsumer
});
module.exports = __toCommonJS(adonisjs_exports);
// src/adonisjs/configure.ts
var import_node_url = require("url");
// src/common/paramValidation.ts
function isValidClientId(clientId) {
const regexExp = /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
return regexExp.test(clientId);
}
__name(isValidClientId, "isValidClientId");
function isValidEnv(env) {
const regexExp = /^[\w-]{1,32}$/;
return regexExp.test(env);
}
__name(isValidEnv, "isValidEnv");
// src/adonisjs/configure.ts
var import_meta = {};
var STUBS_ROOT = (0, import_node_url.fileURLToPath)(new URL("./stubs/", import_meta.url));
async function configure(command) {
const clientId = await command.prompt.ask("Apitally client ID", {
result(value) {
return value.trim().toLowerCase();
},
validate(value) {
return isValidClientId(value);
}
});
const env = await command.prompt.ask("Environment name", {
default: "dev",
result(value) {
return value.trim().toLowerCase().replaceAll("_", "-").replaceAll(" ", "-");
},
validate(value) {
return isValidEnv(value);
}
});
const codemods = await command.createCodemods();
await codemods.makeUsingStub(STUBS_ROOT, "config/apitally.stub", {});
await codemods.registerMiddleware("router", [
{
path: "apitally/adonisjs/middleware"
}
]);
await codemods.updateRcFile((rcFile) => {
rcFile.addProvider("apitally/adonisjs/provider");
});
await codemods.defineEnvVariables({
APITALLY_CLIENT_ID: clientId,
APITALLY_ENV: env
});
await codemods.defineEnvValidations({
leadingComment: "Variables for configuring the apitally package",
variables: {
APITALLY_CLIENT_ID: "Env.schema.string()",
APITALLY_ENV: "Env.schema.string.optional()"
}
});
}
__name(configure, "configure");
// src/adonisjs/index.ts
function defineConfig(config) {
return config;
}
__name(defineConfig, "defineConfig");
function captureError(error, ctx) {
if (error instanceof Error) {
ctx.apitallyError = error;
}
}
__name(captureError, "captureError");
function setConsumer(ctx, consumer) {
ctx.apitallyConsumer = consumer || void 0;
}
__name(setConsumer, "setConsumer");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
captureError,
configure,
defineConfig,
setConsumer
});
//# sourceMappingURL=index.cjs.map