Skip to content

@venturekit/runtime

Terminal window
npm install @venturekit/runtime@dev

The unified handler() function wraps your Lambda business logic:

import { handler } from '@venturekit/runtime';
// Public
export const main = handler(async (_body, ctx, logger) => {
return { status: 'ok' };
});
// Authenticated
export const main = handler(async (body, ctx, logger) => {
return { id: '123', name: body.name };
}, { scopes: ['api.write'] });

For non-HTTP Lambdas — queue consumers, scheduled crons, internal jobs — use taskHandler() / queueBatchHandler(). They expose the same middleware, logging, validation, transaction, and retry primitives as handler(), plus a TaskValidationError that bypasses the retry loop.

import { taskHandler, queueBatchHandler, TaskValidationError } from '@venturekit/runtime';

Typed request context with user info, tenant context, and metadata:

import { buildContext, extractUserContext, extractLocale } from '@venturekit/runtime';

Key fields: requestId, timestamp, method, path, user, tenant, locale, queryParams, tx, intentOutputs.

import { success, created, noContent, error, errorResponse, redirect } from '@venturekit/runtime';

Structured error classes that map to HTTP status codes:

import {
VentureError, BadRequestError, UnauthorizedError, ForbiddenError,
NotFoundError, ConflictError, PayloadTooLargeError, ValidationError,
RateLimitError, InternalError, ServiceUnavailableError, isVentureError,
} from '@venturekit/runtime';

Structured logging via Pino:

import { Logger, createLogger, logger } from '@venturekit/runtime';

Composable middleware system:

import {
compose,
loggingMiddleware,
corsMiddleware,
timeoutMiddleware,
errorBoundaryMiddleware,
rateLimitMiddleware,
requestIdMiddleware,
timingMiddleware,
apiKeyAuthMiddleware,
} from '@venturekit/runtime';
// In-process rate-limit store (auto-selected by `createDefaultRateLimiter()`
// in local dev — falls back to DynamoDB in deployed Lambdas).
import { createMemoryRateLimitStore, RATE_LIMIT_PRESETS } from '@venturekit/runtime';

CloudWatch Embedded-Metric-Format emitter — no AWS SDK call per metric, just structured logs that CloudWatch ingests as metrics:

import { createMetrics } from '@venturekit/runtime';
const metrics = createMetrics({ namespace: 'MyApp/API' });
metrics.putDimensions({ Service: 'orders', Stage: 'prod' });
metrics.putMetric('OrdersCreated', 1, 'Count');
metrics.putMetric('CheckoutDurationMs', durationMs, 'Milliseconds');
metrics.flush();
// Or wrap an async block:
await metrics.timeAsync('Checkout', () => processCheckout(body));

W3C traceparent propagation primitives — used internally by invoke() and queue dispatchers, exposed so custom integrations can join the same trace:

import {
extractTraceContext,
injectTraceHeaders,
createChildTrace,
traceFromRequest,
generateId,
TRACE_HEADERS,
} from '@venturekit/runtime';

Convert plain Node HTTP requests into Lambda events (and back) so the same handler can power both the deployed API Gateway route and the vk dev HTTP server:

import {
httpToLambdaEvent,
createLocalContext,
lambdaResultToHttp,
adaptHandler,
} from '@venturekit/runtime';

Lightweight, typed wrapper around process.env — required for the schema-validated env-var path used by the rest of the runtime:

import { env, createEnvClient } from '@venturekit/runtime';
const port = env.getNumber('PORT', 3000);
const dbUrl = env.require('DATABASE_URL');
const debug = env.getBool('DEBUG', false);

For real-time applications:

import { connectionStore } from '@venturekit/runtime/ws';
await connectionStore.save(connectionId);
await connectionStore.authenticate(connectionId, { userId, email });
await connectionStore.sendToUser(domain, stage, userId, data);
await connectionStore.broadcast(domain, stage, data);

Heavy optional modules are split into subpath imports to keep the core entry point lightweight:

SubpathDescription
@venturekit/runtime/wsWebSocket connection store (DynamoDB)
@venturekit/runtime/patternsinvoke, saga, circuit breaker, idempotency
@venturekit/runtime/queueQueue driver types + createRedisDriver for cross-process queues in dev
@venturekit/runtime/rate-limitDynamoDB-backed rate limit stores
@venturekit/runtime/secretsSSM / Secrets Manager client
@venturekit/runtime/openapiOpenAPI spec generation
@venturekit/runtime/testingTest utilities (mockEvent, mockContext, etc.)
  • @venturekit/core — required
  • pino — structured logging
  • @venturekit/data — optional peer (for transactional handlers)
  • AWS SDK — optional peers (for WebSocket connection store)