Utilities
Crumbjs comes with minimal basic general propuse utilities for jwt, logging (with log level), configuration and openapi
Logger
Level-based logging via the default logger utility, configurable through APP_MODE and/or the mode setting.
import { logger } from "@crumbjs/core";
logger.debug(a, b, c, d); // shows on mode: 'development'
logger.info(a, b, c, d); // shows on modes: 'development', 'qa', 'staging'
logger.warn(a, b, c, d); // shows on modes: 'development', 'qa', 'staging'
logger.error(a, b, c, d); // shows on modes: 'development', 'qa', 'staging', 'production'
Create a context logger using the same log level from your api
import { createLogger } from "@crumbjs/core";
const myServiceLogger = createLogger("myService");
myServiceLogger.debug("Hello there...");
// output:
// 2025-08-22T18:07:23.239Z DEBUG [myService] Hello there...
OpenAPI
Additional documentation support through the openapi utility, using provided helpers or by directly accessing the openapi3-ts builder instance.
import { openapi } from "@crumbjs/core";
// Use this before app.serve()
openapi.addSchema("myschema", myZodObject);
openapi.addTag("tagName", "tagDescription");
openapi.addServer("http://prod.example.com", "Production Server description");
openapi.builder().addExternalDocs(extDoc); // or any openapi3-ts methods
JWT
Minimal utility to sign, verify, and decode JSON Web Tokens.
import { JWT } from "@crumbjs/core";
const token = await JWT.sign<AuthPayload>(myPayload, "super-secret", 60 * 15); // 15min JWT token
const payload = await JWT.verify<AuthPayload>(token, "super-secret");
const decoded = JWT.decode<AuthPayload>(token); // decode no-verify
HTTP Client
Fluent Fetch API wrapper with Zod prevalidation and unified error handling via the Exception system, for effortless HTTP integration between crumbjs services.
import { HttpClient } from "@crumbjs/core";
const httpClient = new HttpClient("http://127.0.0.1:8080");
const { data, error } = await httpClient
.path("/v1/auth")
.prevalidate(loginRequestSchema) // prevalidate with zod before execute request
.data({
domain: "grave-brief",
email: "[email protected]",
password: "MyPassword2025!",
})
.post<{ refreshToken: string }>();
console.log("login result:", data);
const refresh = await httpClient
.path("/v1/auth")
.bearer(res.refreshToken)
.patch();
console.log("refresh result:", refresh);