veryfront/utils

Import

TypeScript
import {  assertCSSPipelineIdentity,  assertStyleProfileHash,  awaitAbortable,  base64urlEncode,  base64urlEncodeBytes,  computeCodeHash,} from "veryfront/utils";

Examples

Structured logging

TypeScript
import { serverLogger } from "veryfront/utils"; serverLogger.info("Booting server", { project_id: "proj_123" });

Exports

Components

NameDescriptionSource
BREAKPOINT_LGShared breakpoint lg value.source
BREAKPOINT_MDShared breakpoint md value.source
BREAKPOINT_SMShared breakpoint sm value.source
BREAKPOINT_XLShared breakpoint xl value.source
BYTES_PER_KBShared bytes per kb value.source
DEFAULT_ALLOWED_CDN_HOSTSDefault value for allowed cdn hosts.source
DEFAULT_BUILD_CONCURRENCYDefault value for build concurrency.source
DEFAULT_DASHBOARD_PORTDefault port for development dashboard (matches veryfront.config.ts default)source
DEFAULT_LRU_MAX_ENTRIESDefault value for lru max entries.source
DEV_SERVER_ENDPOINTSShared dev server endpoints value.source
FORBIDDEN_PATH_PATTERNSShared forbidden path patterns value.source
HASH_SEED_DJB2Shared hash seed djb2 value.source
HASH_SEED_FNV1AShared hash seed fnv1 a value.source
HMR_CLIENT_RELOAD_DELAY_MSShared HMR client reload delay ms value.source
HMR_CLOSE_MESSAGE_TOO_LARGEShared HMR close message too large value.source
HMR_CLOSE_NORMALShared HMR close normal value.source
HMR_CLOSE_RATE_LIMITShared HMR close rate limit value.source
HMR_MAX_MESSAGE_SIZE_BYTESShared HMR max message size bytes value.source
HMR_MAX_MESSAGES_PER_MINUTEShared HMR max messages per minute value.source
HMR_RATE_LIMIT_WINDOW_MSShared HMR rate limit window ms value.source
HTTP_BAD_REQUESTShared HTTP bad request value.source
HTTP_CONTENT_TYPE_IMAGE_GIFShared HTTP content type image gif value.source
HTTP_CONTENT_TYPE_IMAGE_ICOShared HTTP content type image ico value.source
HTTP_CONTENT_TYPE_IMAGE_JPEGShared HTTP content type image jpeg value.source
HTTP_CONTENT_TYPE_IMAGE_PNGShared HTTP content type image png value.source
HTTP_CONTENT_TYPE_IMAGE_SVGShared HTTP content type image svg value.source
HTTP_CONTENT_TYPE_IMAGE_WEBPShared HTTP content type image webp value.source
HTTP_CONTENT_TYPESShared HTTP content types value.source
HTTP_MODULE_FETCH_TIMEOUT_MSHTTP module fetch timeout, including cold upstream module generation.source
HTTP_NETWORK_CONNECT_TIMEOUTShared HTTP network connect timeout value.source
HTTP_NOT_FOUNDShared HTTP not found value.source
HTTP_NOT_IMPLEMENTEDShared HTTP not implemented value.source
HTTP_OKShared HTTP ok value.source
HTTP_REDIRECT_FOUNDShared HTTP redirect found value.source
HTTP_SERVER_ERRORShared HTTP server error value.source
HTTP_STATUS_CLIENT_ERROR_MINShared HTTP status client error min value.source
HTTP_STATUS_REDIRECT_MINShared HTTP status redirect min value.source
HTTP_STATUS_SERVER_ERROR_MINShared HTTP status server error min value.source
HTTP_STATUS_SUCCESS_MINShared HTTP status success min value.source
HTTP_UNAVAILABLEShared HTTP unavailable value.source
IMAGE_OPTIMIZATIONShared image optimization value.source
MAX_BATCH_SIZEMaximum batch size.source
MAX_CSS_PIPELINE_IDENTITY_CODE_UNITSMaximum UTF-16 code units accepted for one complete CSS pipeline identity.source
MAX_CSS_PIPELINE_IDENTITY_UTF8_BYTESMaximum encoded UTF-8 bytes accepted for one complete CSS pipeline identity.source
MAX_PATH_LENGTHMaximum value for path length.source
MAX_PATH_TRAVERSAL_DEPTHMaximum value for path traversal depth.source
MS_PER_SECONDShared ms per second value.source
PREFETCH_DEFAULT_DELAY_MSShared prefetch default delay ms value.source
PREFETCH_DEFAULT_TIMEOUT_MSShared prefetch default timeout ms value.source
PREFETCH_MAX_SIZE_BYTESShared prefetch max size bytes value.source
REACT_DEFAULT_VERSIONShared React default version value.source
RESPONSIVE_IMAGE_WIDTH_LGShared responsive image width lg value.source
RESPONSIVE_IMAGE_WIDTHSShared responsive image widths value.source
RSC_MANIFEST_CACHE_TTL_MSShared RSC manifest cache ttl ms value.source
TSX_LAYOUT_MAX_ENTRIESShared TSX layout max entries value.source
TSX_LAYOUT_PER_PROJECT_MAX_ENTRIESPer-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
VERSIONShared version value.source
Z_INDEX_DEV_INDICATORShared z index dev indicator value.source
Z_INDEX_ERROR_OVERLAYShared z index error overlay value.source

Functions

NameDescriptionSource
assertCSSPipelineIdentityValidate and return an immutable string snapshot for cache or wire use.source
assertStyleProfileHashValidate and return the canonical style-scope profile SHA-256 identity.source
awaitAbortableAwait a value while allowing cancellation to win even when the producer ignores its signal.source
base64urlEncodeEncode a string as unpadded base64url.source
base64urlEncodeBytesEncode raw bytes as unpadded base64url.source
computeCodeHashCompute a bundle hash from fixed-field raw UTF-16 code-unit framing.source
computeHashCompute the lowercase hex SHA-256 digest of a UTF-8 string.source
computeHashBytesCompute the lowercase hex SHA-256 digest of raw bytes.source
computeIntegrityCompute integrity.source
createAbortErrorConvert an arbitrary abort reason into the framework's stable Error shape.source
createLockfileManagerCreate lockfile manager.source
createRunUserLoggerCreate run user logger.source
createSubscriberSetCreate 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
encodeBase64Encode 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
encodeBase64BytesEncode raw bytes as standard base64.source
endRequestRequest payload for end.source
fnv1aHashFNV-1a hash for strings - returns hex stringsource
getBaseLoggerGet an immutable base logger without request context awareness.source
getBundleManifestStoreReturn bundle manifest store.source
getDenoStdNodeBaseReturn Deno std node base.source
getLockfileEntryForBuildRead a lockfile entry on a build or dev-server hot path.source
getReactImportMapReturn React import map.source
hasBunRuntimeCheck whether Bun runtime is present.source
hasDenoRuntimeCheck whether Deno runtime is present.source
hasNodeProcessCheck whether node process is present.source
hasProjectIdentityControlCharactersWhether a string contains a Unicode Cc control code point.source
isCanonicalProjectSlugWhether a normalized value is a canonical hosted project slug.source
isCompiledBinaryDetect if the code is running in a compiled Deno binarysource
isCSSPipelineIdentityWhether a value is safe to compare, encode, and persist as a CSS pipeline identity.source
isEnabledCheck whether request performance timing is enabled.source
isRSCEnabledCheck whether RSC is enabled.source
isStyleProfileHashWhether a value is the canonical style-scope profile SHA-256 identity.source
isTruthyEnvValuesource
isWithinDirectorysource
memoizeMemoize.source
memoizeAsyncMemoize async.source
memoizeHashFNV-1a hash algorithm for fast, framed cache key generation. 10-15x faster than JSON.stringify() and uses 70-80% less memory.source
normalizePathNormalizes path.source
parallelMapRun parallel map.source
redactForSerializationReturns 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
redactSensitiveReturns 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
runWithRequestContextAsyncRun with request context async.source
safeJsonParseParse value as JSON without throwing; failures return { ok: false, error } so callers handle them without a surrounding try/catch.source
sanitizeUrlCredentialsStrip 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
sanitizeUrlForSpanReturn the URL form safe to attach to observability span attributes.source
setLockfileEntryForBuildPersist a lockfile entry from a build or dev-server hot path.source
shortHashCreate short hash.source
simpleHashCreate simple hash.source
sleepReturn 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
startRequestRequest payload for start.source
startTimerStarts timer.source
throwIfAbortedThrow the normalized abort reason when a signal has already been aborted.source
timeAsyncTime async.source

Classes

NameDescriptionSource
MemoCacheImplement memo cache.source

Types

NameDescriptionSource
BundleCodePublic API contract for bundle code.source
BundleMetadataPublic API contract for bundle metadata.source
GlobalWithBunPublic API contract for global with Bun.source
GlobalWithDenoPublic API contract for global with Deno.source
GlobalWithProcessPublic API contract for global with process.source
HashBundleCodeSource bundle content used for hash computation.source
LockfileManagerPublic API contract for lockfile manager.source
LogEntryStructured log entry for JSON output. Fields are designed for easy Grafana/Loki filtering.source
LoggerPublic API contract for logger.source
RedactedValuesource
RequestContextContext for request.source
SafeJsonParseResultTagged-union result of safeJsonParse; narrow via the ok discriminant.source
SubscriberSetListener registry returned by createSubscriberSet.source

Constants

NameDescriptionSource
agentLoggersource
bundlerLoggersource
cliLoggersource
loggersource
rendererLoggersource
serverLoggersource

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

TypeScript
import { colorize, createRequestLogger, createRunUserLogger } from "veryfront/utils/logger";

Components

NameDescriptionSource
ANSIsource
LEVEL_COLORSsource
LEVEL_GLYPHSsource
LogComponentsCanonical component names for structured logging.source
PREFIX_WIDTHsource
TAG_WIDTHShared logger formatting utilities. This module contains pure formatting functions with no external dependencies, enabling reuse between the main logger and proxy logger.source

Functions

NameDescriptionSource
colorizeApply ANSI color codes to text if enabled.source
createRequestLoggerCreate a logger for a specific request context. Useful for binding request-specific metadata to all logs.source
createRunUserLoggerCreate run user logger.source
formatContextTextFormat context and error as indented key=value pairs. Filters out undefined values for cleaner output.source
formatErrorTextFormat a serialized error for text output.source
formatTimestampFormat a timestamp as HH:MM:SS.source
formatValueFormat a value for log output (handles strings, numbers, booleans, objects).source
getBaseLoggerGet an immutable base logger without request context awareness.source
getDefaultLevelDetermine the log level based on environment variables. Exported for testing purposes.source
getRequestContextsource
getRequestLoggersource
isRecordCheck if value is a non-null, non-array object (plain record).source
normalizeTextNormalize whitespace in text (collapse multiple spaces to single space).source
padTagPad or truncate a tag to fixed width for aligned output.source
runWithRequestContextsource
runWithRequestContextAsyncRun with request context async.source
serializeErrorSerialize an error object for structured logging.source
truncateTextTruncate text to maxLength, adding ellipsis if truncated.source

Types

NameDescriptionSource
LogComponentsource
LogEntryStructured log entry for JSON output. Fields are designed for easy Grafana/Loki filtering.source
LogFormatsource
LoggerPublic API contract for logger.source
LogLevelsource
LogLevelNamesource
LogRecordEmittersource
RequestContextContext for request.source
SerializedErrorSerialized error structure for structured logging.source

Constants

NameDescriptionSource
agentLoggersource
bundlerLoggersource
cliLoggersource
loggersource
proxyLoggersource
rendererLoggersource
serverLoggersource