Pular para o conteúdo

@buntime/shared

Este conteúdo não está disponível em sua língua ainda.

@buntime/shared is the one package published outside the monorepo — to JSR. It holds the types, error classes, logger, middleware, and utilities that the runtime, plugins, and apps all depend on, so nothing is duplicated.

It uses granular exports rather than a single barrel: import exactly the subpath you need.

Terminal window
bunx jsr add @buntime/shared

Peer dependencies: hono ^4, typescript ^5, zod ^4.

SubpathWhat it provides
@buntime/shared/typesBuntimePlugin, PluginImpl, PluginContext, AppInfo, WorkerManifest, WorkerConfig
@buntime/shared/errorsAppError and the specific error classes (see below)
@buntime/shared/logger/indexcreateLogger(), getLogger(), child loggers (JSON in prod, pretty in dev)
@buntime/shared/middleware/api-keycreateApiKeyMiddleware() — shared auth gate for plugin /<base>/admin/** routes
@buntime/shared/api-keysAPI key store helpers
@buntime/shared/tursoTurso/libSQL client helpers
@buntime/shared/buildcreateAppBuilder() — the shared client/server build pipeline used by apps and plugins
@buntime/shared/utils/worker-configparseWorkerConfig(), WorkerConfigDefaults
@buntime/shared/utils/durationparseDurationToMs()"30s", "1m", "24h" → ms
@buntime/shared/utils/sizeparseSizeToBytes()"10mb", "1gb" → bytes
@buntime/shared/utils/static-handlercreateStaticHandler() — serve a SPA dir with <base href> injection
@buntime/shared/utils/globglob matching for public-route patterns
@buntime/shared/utils/zod-helpersshared Zod helpers (e.g. boolean())
@buntime/shared/utils/stringstring parsing helpers
@buntime/shared/utils/buntime-config, @buntime/shared/utils/config-validationruntime config loading and validation

Application code should never throw a generic Error. Use a specific class from @buntime/shared/errors, always with a SCREAMING_SNAKE_CASE code that clients can branch on:

import { ValidationError, NotFoundError } from "@buntime/shared/errors";
throw new ValidationError("Email is required", "MISSING_EMAIL");
throw new NotFoundError("User not found", "USER_NOT_FOUND");
// Client receives: { code: "MISSING_EMAIL", error: "Email is required" }
ClassTypical status
ValidationError400
UnauthorizedError401
ForbiddenError403
NotFoundError404
BodyTooLargeError413

Log full error details (with requestId, userId, stack) server-side, but keep the message returned to the client user-friendly.

@buntime/shared is published only via the GitHub Actions OIDC workflow — never manually from the CLI. The jsr.json and package.json versions must always match. See Publishing to JSR.