Import
import {
__registerLogRecordEmitter,
__registerTraceContextGetter,
assertCSSPipelineIdentity,
assertStyleProfileHash,
awaitAbortable,
base64urlEncode,
} from "veryfront/utils";
Examples
Structured logging
import { serverLogger } from "veryfront/utils";
serverLogger.info("Booting server", { project_id: "proj_123" });
Exports
Components
| Name | Description | Source |
|---|---|---|
BREAKPOINT_LG | Shared breakpoint lg value. | source |
BREAKPOINT_MD | Shared breakpoint md value. | source |
BREAKPOINT_SM | Shared breakpoint sm value. | source |
BREAKPOINT_XL | Shared breakpoint xl value. | source |
BYTES_PER_KB | Shared bytes per kb value. | source |
DEFAULT_ALLOWED_CDN_HOSTS | Default value for allowed cdn hosts. | source |
DEFAULT_BUILD_CONCURRENCY | Default value for build concurrency. | source |
DEFAULT_DASHBOARD_PORT | Default port for development dashboard (matches veryfront.config.ts default) | source |
DEFAULT_LRU_MAX_ENTRIES | Default value for lru max entries. | source |
DEV_SERVER_ENDPOINTS | Shared dev server endpoints value. | source |
FORBIDDEN_PATH_PATTERNS | Shared forbidden path patterns value. | source |
HASH_SEED_DJB2 | Shared hash seed djb2 value. | source |
HASH_SEED_FNV1A | Shared hash seed fnv1 a value. | source |
HMR_CLIENT_RELOAD_DELAY_MS | Shared HMR client reload delay ms value. | source |
HMR_CLOSE_MESSAGE_TOO_LARGE | Shared HMR close message too large value. | source |
HMR_CLOSE_NORMAL | Shared HMR close normal value. | source |
HMR_CLOSE_RATE_LIMIT | Shared HMR close rate limit value. | source |
HMR_MAX_MESSAGE_SIZE_BYTES | Shared HMR max message size bytes value. | source |
HMR_MAX_MESSAGES_PER_MINUTE | Shared HMR max messages per minute value. | source |
HMR_RATE_LIMIT_WINDOW_MS | Shared HMR rate limit window ms value. | source |
HTTP_BAD_REQUEST | Shared HTTP bad request value. | source |
HTTP_CONTENT_TYPE_IMAGE_GIF | Shared HTTP content type image gif value. | source |
HTTP_CONTENT_TYPE_IMAGE_ICO | Shared HTTP content type image ico value. | source |
HTTP_CONTENT_TYPE_IMAGE_JPEG | Shared HTTP content type image jpeg value. | source |
HTTP_CONTENT_TYPE_IMAGE_PNG | Shared HTTP content type image png value. | source |
HTTP_CONTENT_TYPE_IMAGE_SVG | Shared HTTP content type image svg value. | source |
HTTP_CONTENT_TYPE_IMAGE_WEBP | Shared HTTP content type image webp value. | source |
HTTP_CONTENT_TYPES | Shared HTTP content types value. | source |
HTTP_MODULE_FETCH_TIMEOUT_MS | HTTP module fetch timeout, including cold upstream module generation. | source |
HTTP_NETWORK_CONNECT_TIMEOUT | Shared HTTP network connect timeout value. | source |
HTTP_NOT_FOUND | Shared HTTP not found value. | source |
HTTP_NOT_IMPLEMENTED | Shared HTTP not implemented value. | source |
HTTP_OK | Shared HTTP ok value. | source |
HTTP_REDIRECT_FOUND | Shared HTTP redirect found value. | source |
HTTP_SERVER_ERROR | Shared HTTP server error value. | source |
HTTP_STATUS_CLIENT_ERROR_MIN | Shared HTTP status client error min value. | source |
HTTP_STATUS_REDIRECT_MIN | Shared HTTP status redirect min value. | source |
HTTP_STATUS_SERVER_ERROR_MIN | Shared HTTP status server error min value. | source |
HTTP_STATUS_SUCCESS_MIN | Shared HTTP status success min value. | source |
HTTP_UNAVAILABLE | Shared HTTP unavailable value. | source |
IMAGE_OPTIMIZATION | Shared image optimization value. | source |
MAX_BATCH_SIZE | Maximum batch size. | source |
MAX_CSS_PIPELINE_IDENTITY_CODE_UNITS | Maximum UTF-16 code units accepted for one complete CSS pipeline identity. | source |
MAX_CSS_PIPELINE_IDENTITY_UTF8_BYTES | Maximum encoded UTF-8 bytes accepted for one complete CSS pipeline identity. | source |
MAX_PATH_LENGTH | Maximum value for path length. | source |
MAX_PATH_TRAVERSAL_DEPTH | Maximum value for path traversal depth. | source |
MS_PER_SECOND | Shared ms per second value. | source |
PREFETCH_DEFAULT_DELAY_MS | Shared prefetch default delay ms value. | source |
PREFETCH_DEFAULT_TIMEOUT_MS | Shared prefetch default timeout ms value. | source |
PREFETCH_MAX_SIZE_BYTES | Shared prefetch max size bytes value. | source |
REACT_DEFAULT_VERSION | Shared React default version value. | source |
RESPONSIVE_IMAGE_WIDTH_LG | Shared responsive image width lg value. | source |
RESPONSIVE_IMAGE_WIDTHS | Shared responsive image widths value. | source |
RSC_MANIFEST_CACHE_TTL_MS | Shared RSC manifest cache ttl ms value. | source |
TSX_LAYOUT_MAX_ENTRIES | Shared TSX layout max entries value. | source |
TSX_LAYOUT_PER_PROJECT_MAX_ENTRIES | Per-project cap for the TSX layout component cache. Prevents a single noisy tenant from evicting every other project’s cached layouts. Defaults to ceil(TSX_LAYOUT_MAX_ENTRIES / 10) so no one project consumes more than ~10 % of the global budget. Set via TSX_LAYOUT_PER_PROJECT_MAX_ENTRIES env var. | source |
VERSION | Shared version value. | source |
Z_INDEX_DEV_INDICATOR | Shared z index dev indicator value. | source |
Z_INDEX_ERROR_OVERLAY | Shared z index error overlay value. | source |
Functions
| Name | Description | Source |
|---|---|---|
__registerLogRecordEmitter | Register a process-level structured log emitter, for example an OTel bridge. | source |
__registerTraceContextGetter | Register the trace context getter. Called by trace-bridge.ts after OTLP initialization. | source |
assertCSSPipelineIdentity | Validate and return an immutable string snapshot for cache or wire use. | source |
assertStyleProfileHash | Validate and return the canonical style-scope profile SHA-256 identity. | source |
awaitAbortable | Await a value while allowing cancellation to win even when the producer ignores its signal. | source |
base64urlEncode | Encode a string as unpadded base64url. | source |
base64urlEncodeBytes | Encode raw bytes as unpadded base64url. | source |
computeCodeHash | Compute code hash. | source |
computeHash | Compute the lowercase hex SHA-256 digest of a UTF-8 string. | source |
computeHashBytes | Compute the lowercase hex SHA-256 digest of raw bytes. | source |
computeIntegrity | Compute integrity. | source |
createAbortError | Convert an arbitrary abort reason into the framework’s stable Error shape. | source |
createLockfileManager | Create lockfile manager. | source |
createRunUserLogger | Create run user logger. | source |
createSubscriberSet | Create a subscriber set: the canonical subscribe/notify observable used across modules. Notification iterates a snapshot, so a listener that unsubscribes (itself or others) mid-notify is safe, and listener errors are isolated (routed to onListenerError when provided, otherwise swallowed). | source |
encodeBase64 | Encode a string as standard base64. Latin-1 input (all code points <= 0xFF) is encoded with btoa’s binary-string semantics; input outside Latin-1 falls back to UTF-8 bytes. Callers that need guaranteed UTF-8 bytes regardless of input (e.g. data: URLs decoded as UTF-8) should use encodeBase64Bytes(new TextEncoder().encode(value)) instead. | source |
encodeBase64Bytes | Encode raw bytes as standard base64. | source |
endRequest | Request payload for end. | source |
fnv1aHash | FNV-1a hash for strings - returns hex string | source |
getBaseLogger | Get the base logger without request context awareness. Use this when you need to create a request-scoped logger in middleware. | source |
getBundleManifestStore | Return bundle manifest store. | source |
getDenoStdNodeBase | Return Deno std node base. | source |
getLockfileEntryForBuild | Read a lockfile entry on a build or dev-server hot path. | source |
getReactImportMap | Return React import map. | source |
hasBunRuntime | Check whether Bun runtime is present. | source |
hasDenoRuntime | Check whether Deno runtime is present. | source |
hasNodeProcess | Check whether node process is present. | source |
hasProjectIdentityControlCharacters | Whether a string contains a Unicode Cc control code point. | source |
isCanonicalProjectSlug | Whether a normalized value is a canonical hosted project slug. | source |
isCompiledBinary | Detect if the code is running in a compiled Deno binary | source |
isCSSPipelineIdentity | Whether a value is safe to compare, encode, and persist as a CSS pipeline identity. | source |
isEnabled | Check whether request performance timing is enabled. | source |
isRSCEnabled | Check whether RSC is enabled. | source |
isStyleProfileHash | Whether a value is the canonical style-scope profile SHA-256 identity. | source |
isTruthyEnvValue | source | |
isWithinDirectory | source | |
memoize | Memoize. | source |
memoizeAsync | Memoize async. | source |
memoizeHash | FNV-1a hash algorithm for fast, framed cache key generation. 10-15x faster than JSON.stringify() and uses 70-80% less memory. | source |
normalizePath | Normalizes path. | source |
parallelMap | Run parallel map. | source |
redactForSerialization | Returns a JSON-safe redacted snapshot of context. Sensitive keys are masked, nested values are traversed, BigInts become decimal strings, non-finite numbers become null, and unsupported or unreadable values fail closed. Objects with toJSON are snapshotted exactly once before redaction. | source |
redactSensitive | Returns a redacted copy of context while preserving the established source and runtime value shapes. Any property whose key is isSensitiveKey is replaced with REDACTED; nested records and arrays are traversed, while primitives and scalar-serializing objects retain their original types. The input is never mutated. | source |
refreshLoggerConfig | Re-read logger configuration from environment variables. Call after loading .env files so the logger picks up any overrides. The active preset (cli/server) is preserved across refreshes. | source |
registerTraceContextGetter | Register the trace context getter. Called by trace-bridge.ts after OTLP initialization. | source |
runWithRequestContextAsync | Run with request context async. | source |
safeJsonParse | Parse value as JSON without throwing; failures return { ok: false, error } so callers handle them without a surrounding try/catch. | source |
sanitizeUrlCredentials | Strip credentials from URL-shaped strings so they can be safely emitted in free-form text (error messages, stacks, lifted request_url fields). Unlike redactSensitive, which is key-based, this scrubs secrets embedded in the value itself: | source |
sanitizeUrlForSpan | Return the URL form safe to attach to observability span attributes. | source |
setLockfileEntryForBuild | Persist a lockfile entry from a build or dev-server hot path. | source |
shortHash | Create short hash. | source |
simpleHash | Create simple hash. | source |
sleep | Return a promise that resolves after ms milliseconds. If abortSignal is already aborted, throws abortSignal.reason synchronously. If it aborts while waiting, rejects with abortSignal.reason. | source |
startRequest | Request payload for start. | source |
startTimer | Starts timer. | source |
throwIfAborted | Throw the normalized abort reason when a signal has already been aborted. | source |
timeAsync | Time async. | source |
Classes
| Name | Description | Source |
|---|---|---|
MemoCache | Implement memo cache. | source |
Types
| Name | Description | Source |
|---|---|---|
BundleCode | Public API contract for bundle code. | source |
BundleMetadata | Public API contract for bundle metadata. | source |
GlobalWithBun | Public API contract for global with Bun. | source |
GlobalWithDeno | Public API contract for global with Deno. | source |
GlobalWithProcess | Public API contract for global with process. | source |
HashBundleCode | Source bundle content used for hash computation. | source |
LockfileManager | Public API contract for lockfile manager. | source |
LogEntry | Structured log entry for JSON output. Fields are designed for easy Grafana/Loki filtering. | source |
Logger | Public API contract for logger. | source |
RedactedValue | source | |
RequestContext | Context for request. | source |
SafeJsonParseResult | Tagged-union result of safeJsonParse; narrow via the ok discriminant. | source |
SubscriberSet | Listener registry returned by createSubscriberSet. | source |
Constants
Deep imports
These import paths group focused functionality under this module. Each is a separate barrel; import only what you need.veryfront/utils/logger
Utils Logger
import {
__registerLogRecordEmitter,
__registerRequestContextGetter,
__registerTraceContextGetter,
} from "veryfront/utils/logger";
Components
| Name | Description | Source |
|---|---|---|
ANSI | source | |
LEVEL_COLORS | source | |
LEVEL_GLYPHS | source | |
LogComponents | Canonical component names for structured logging. | source |
PREFIX_WIDTH | source | |
TAG_WIDTH | Shared logger formatting utilities. This module contains pure formatting functions with no external dependencies, enabling reuse between the main logger and proxy logger. | source |
Functions
| Name | Description | Source |
|---|---|---|
__registerLogRecordEmitter | Register a process-level structured log emitter, for example an OTel bridge. | source |
__registerRequestContextGetter | Register the request context getter. Called by request-context.ts during module initialization. | source |
__registerTraceContextGetter | Register the trace context getter. Called by trace-bridge.ts after OTLP initialization. | source |
__resetLogRecordEmitterForTests | Reset the process-level structured log emitter. Only intended for tests. | source |
__resetTraceContextGetterForTests | Reset the trace context getter. Only intended for testing purposes. | source |
__subscribeLogRecordEmitter | Subscribe to process-level structured log records. Returns an unregister function. | source |
colorize | Apply ANSI color codes to text if enabled. | source |
createRequestLogger | Create a logger for a specific request context. Useful for binding request-specific metadata to all logs. | source |
createRunUserLogger | Create run user logger. | source |
formatContextText | Format context and error as indented key=value pairs. Filters out undefined values for cleaner output. | source |
formatErrorText | Format a serialized error for text output. | source |
formatTimestamp | Format a timestamp as HH:MM:SS. | source |
formatValue | Format a value for log output (handles strings, numbers, booleans, objects). | source |
getBaseLogger | Get the base logger without request context awareness. Use this when you need to create a request-scoped logger in middleware. | source |
getDefaultLevel | Determine the log level based on environment variables. Exported for testing purposes. | source |
getRequestContext | source | |
getRequestLogger | source | |
isRecord | Check if value is a non-null, non-array object (plain record). | source |
normalizeText | Normalize whitespace in text (collapse multiple spaces to single space). | source |
padTag | Pad or truncate a tag to fixed width for aligned output. | source |
refreshLoggerConfig | Re-read logger configuration from environment variables. Call after loading .env files so the logger picks up any overrides. The active preset (cli/server) is preserved across refreshes. | source |
runWithRequestContext | source | |
runWithRequestContextAsync | Run with request context async. | source |
serializeError | Serialize an error object for structured logging. | source |
setLoggerPreset | Switch the text output format between server-style (timestamp + tag prefix) and CLI-style (2-space indent + glyph only, no timestamp or tag). JSON output is unaffected by this setting. Call before any framework code runs in CLI entry points so framework messages render in the CLI’s visual language. | source |
setLogLevel | Override the active log level without re-reading environment variables. Use when a verbosity flag (—verbose, —quiet) has been parsed and its effect needs to propagate to all loggers immediately. | source |
truncateText | Truncate text to maxLength, adding ellipsis if truncated. | source |
Types
| Name | Description | Source |
|---|---|---|
LogComponent | source | |
LogEntry | Structured log entry for JSON output. Fields are designed for easy Grafana/Loki filtering. | source |
LogFormat | source | |
Logger | Public API contract for logger. | source |
LogLevel | source | |
LogLevelName | source | |
LogRecordEmitter | source | |
RequestContext | Context for request. | source |
SerializedError | Serialized error structure for structured logging. | source |
Constants
| Name | Description | Source |
|---|---|---|
__resetLoggerConfigForTests | source | |
agentLogger | Shared agent logger value. | source |
bundlerLogger | Shared bundler logger value. | source |
cliLogger | source | |
logger | Shared logger value. | source |
proxyLogger | source | |
rendererLogger | Shared renderer logger value. | source |
requestContextStore | source | |
serverLogger | Shared server logger value. | source |