@privateaim/server-kit
Server-side foundation package providing logging, authentication integration, AMQP messaging, Redis, caching, and DI module infrastructure. Used by all Hub backend services.
Installation
npm install @privateaim/server-kitUsage
Logger (Winston)
import { useLogger, LoggerModule } from '@privateaim/server-kit';
const logger = useLogger();
logger.info('Service started');Message Bus (AMQP)
import { MessageBusModule } from '@privateaim/server-kit';Redis
import { RedisModule } from '@privateaim/server-kit';Authup Integration
import { AuthupModule } from '@privateaim/server-kit';Query Schema Description
describeQuerySchema() serializes a rapiq entity schema into the SchemaDescription that controllers publish under meta.schema — the static upper bound of an endpoint's queryable vocabulary. Pass RECORD_QUERY_PARAMETERS on single-record reads to advertise only the fields + relations subset a record read processes.
import { RECORD_QUERY_PARAMETERS, describeQuerySchema } from '@privateaim/server-kit';
// Collection GET — full vocabulary
return { data, meta: { ...meta, schema: describeQuerySchema(nodeSchema) } };
// Record GET — fields + relations only
return { data: entity, meta: { schema: describeQuerySchema(nodeSchema, RECORD_QUERY_PARAMETERS) } };Descriptions are memoized per (schema, parameters) and deep-frozen: the returned object is shared by reference, so never mutate it. Always spread when merging — meta: { ...meta, schema }, never meta.schema = ... (that throws under ESM strict mode).
See API Reference for the consumer-side reading rules.
Application Builder
import { BaseApplicationBuilder } from '@privateaim/server-kit';
class MyAppBuilder extends BaseApplicationBuilder {
// Add withConfig(), withDatabase(), withHTTP() etc.
}API
Exports
| Module | Description |
|---|---|
app | BaseApplicationBuilder, Application base class |
logger | Winston logger setup and LoggerModule |
message-bus | AMQP message bus module and utilities |
redis | Redis module and connection helpers |
authup | Authup authentication middleware module |
cache | Cache module (Redis-backed) |
config | Configuration reading via envix |
core/query | describeQuerySchema(), RECORD_QUERY_PARAMETERS — rapiq schema description for meta.schema |
entity-event | Entity event pub/sub system |
task-manager | Task lifecycle management |
aggregator | AMQP event aggregator base classes |
component | AMQP task consumer component base classes |
constants | Module names, injection keys |
Shared DI Modules
| Module Class | Purpose |
|---|---|
LoggerModule | Winston logger with optional telemetry transport |
RedisModule | Redis client registration |
MessageBusModule | AMQP connection and queue management |
AuthupModule | Authup middleware and token validation |
CacheModule | Redis-backed caching |
EntityEventModule | Domain event dispatching |
Dependencies
winston— Logging@ebec/http— HTTP error types@hapic/oauth2— OAuth2 client@rapiq/core— Query schema definition and description (describeQuerySchema)orkos— Module system (IModule)eldin— DI container (TypedToken)envix— Environment variable reading