@pipeline-builder/api-core
v3.3.30
Published
Core server-side utilities (auth middleware, response helpers, error codes, quota service, HTTP client, logging, AI provider catalog) shared by every Pipeline Builder backend service.
Downloads
11,834
Maintainers
Readme
@pipeline-builder/api-core
Core server-side utilities shared by every backend service in Pipeline Builder: JWT authentication middleware, structured logging, response helpers, error codes, quota enforcement, parameter parsing, validation schemas, an internal HTTP client, and the AI provider catalog.
Key Exports
Authentication Middleware
requireAuth— JWT authentication middleware (also acceptsRequireAuthOptionsforallowOrgHeaderOverrideon internal-service routes)requireAdmin,requireSystemAdmin— role gates (admin/owner; system-org admin/owner)requireFeature— feature-flag gateisSystemOrg,isSystemAdmin,isServicePrincipal— authorization checks (last one is true whenreq.user.substarts withservice:)resolveAccessModifier(req, requested)— coercesrequested='public'to'private'unless caller is admin/owner
Service-to-Service Tokens
signServiceToken({ serviceName, orgId?, orgName?, ttlSeconds? })— mints a short-lived JWT identifying the calling service. Default TTL 5 minutes.getServiceAuthHeader(opts)— convenience wrapper returningBearer <token>for direct use in fetch/axios headers.
Tokens satisfy the standard requireAuth middleware unmodified (sub: service:<name>, role: owner, type: access). Use for inter-service HTTP calls (billing → message renewals, platform → billing on register, etc.).
Request/Response Utilities
sendSuccess,sendError,sendBadRequest,sendInternalError,sendPaginated,sendPaginatedNestedextractDbError— Extract database error detailsErrorCode,getStatusForErrorCode— Standard error codes
Parameter Parsing
getParam,getRequiredParam,getParams,getOrgId,getAuthHeaderparseQueryBoolean,parseQueryInt,parseQueryString
Validation Schemas (Zod)
AIGenerateBodySchema— Validates AI generation requests (prompt, provider, model)AIGenerateFromUrlBodySchema— Validates Git URL generation requests (gitUrl, provider, model, apiKey?, repoToken?)
Internal HTTP Client
InternalHttpClient,createSafeClient— Service-to-service HTTP communicationServiceConfig,RequestOptions,HttpResponse— Client types
AI Provider Constants
AI_PROVIDER_CATALOG— Static provider/model catalogAI_PROVIDER_ENV_VARS— Provider-to-env-var mappinggetAIProviderModels— Get models for a provider
Logging
createLogger— Winston logger factory
Quota Service
QuotaService(type),createQuotaService— Quota enforcement clientQuotaType—'plugins' | 'pipelines' | 'apiCalls' | 'aiCalls'QuotaCheckResult,QuotaTier,QUOTA_TIERS,getTierLimits— Quota domain types and tier presets
Health Endpoints
createHealthRouter({ serviceName, version?, checkDependencies? })— registersGET /health(liveness; always 200 unless process is dead) andGET /ready(readiness; 503 when any dependency is'disconnected'). Use as Kubernetes/ECS liveness + readiness probes respectively.
License
Apache-2.0. See LICENSE.
