@haatlabs-core/nest-common
v0.10.0
Published
What every NestJS API shares below authentication: errors, validation, health checks and the Fastify app setup.
Readme
@haatlabs-core/nest-common
What every app's NestJS API shares, below authentication.
- Tokens (
CONFIG,LOGGER,APP_DB,SYSTEM_DB,REDIS,RATE_LIMITER,METRICS,PLAIN_FETCH,FETCH,MAILER,TOKEN_CIPHER,STORE_TOKENS): registered symbols, so two installed copies name the same provider. An app'sinfra/tokens.tsre-exports them beside its own. AppExceptionFilter: every error as{ error: { code, message, requestId } }; a fault of ours is INTERNAL, logged without SQL or bound values, and never shown.HtmlProblemFilterwith the providerHTML_PROBLEM_OPTIONS: a page, not JSON, for a refusal a person's browser was sent to.ZodPipe,Public/OptionalAuth(the auth mode nest-auth's guard reads).MAILERis bound by the app to@haatlabs-core/mailer'smailerFromConfig(config.mail).requireFeature/requireFeatureForover aFeatureSource, withFEATURE_ERRORS(spread intodefineErrorsby an app with plans).HealthController(/health/live,/health/ready) over the providerHEALTH_CHECKS, withpostgresCheckandredisCheck; a check may beadvisoryand cached (cacheMs).createFastifyApp(module, options): request IDs, a span per request, metrics by route pattern, helmet, cookies, CORS and the OpenAPI document.installShutdownandwarnAuthMisconfigfor the app's main.oneMonthAfter.observeHttpis given before the app exists, so an app makes its metrics inmain(with@haatlabs-core/observability/metrics) and hands the same object to its module asMETRICS.
Every @nestjs/* package, fastify, ioredis, drizzle-orm and zod are peers.
Install
pnpm add @haatlabs-core/nest-commonIt leaves these packages to your app, so the app holds one copy: @fastify/cookie, @fastify/helmet, @nestjs/common, @nestjs/core, @nestjs/platform-fastify, @nestjs/swagger, drizzle-orm, fastify, ioredis, reflect-metadata, rxjs, zod.
