Introducing a new way to review your PRs.

Read the announcement

frappe / frappe-ui

The all-in-one toolkit for modern frontends. High-quality components, app recipes and AI-ready docs.

View on GitHub

28 documents · Updated Nov 23, 2026

docs / utility-services

Utility services

Utility services form the shared boundary between the library, a Frappe site, and browser APIs. They hold app-wide settings, turn library requests into Frappe requests, shape query and cache data, and give file-based features one upload and safety contract.

Configuration

Configuration gives an app one place to provide values that several library integrations need. The same settings can control time zones, API access, resource loading, error reporting, and upload limits.

Shared configuration

src/…/config.ts defines the public configuration contract through FrappeUIConfig. Apps set individual values with setConfig; library services read them with getConfig. This keeps app policy outside the components that consume it.

The configuration is shared across duplicated package copies. This matters when the build loads composables and Vue components through different module paths. A split configuration would make one side read different values from the other side.

References: src/…/config.ts• L3-17 src/…/config.ts• L29-62 src/…/moduleSingleton.ts• L1-30

Integration settings

Request services can use a base URL for a remote Frappe site and can add static or computed headers for authentication. Resource services can provide a custom fetcher and default document or list endpoints. The app can also provide shared handlers for server messages and fallback errors.

Upload behavior uses the same configuration channel for the maximum file size and the optional chunk size. Time-zone settings are consumed by date services, so those values affect data shown by library controls as well as request-related behavior.

References: src/…/config.ts• L3-42 src/…/frappeRequest.ts• L101-144 src/…/useFileUpload.ts• L240-247

Request boundary

The request boundary separates generic browser transport from Frappe response rules. Callers can use a simple request shape, while the Frappe-aware layer adds endpoint mapping, headers, authentication context, response unwrapping, and shared error reporting.

Frappe requests

src/…/frappeRequest.ts accepts a method name or URL and produces the response shape expected by Frappe resources. It adds the standard API path for method names, applies configured headers and CSRF data, and uses the configured base URL when the app talks to another site.

Successful responses normally resolve to Frappe's message value. Login responses remain whole payloads because callers need fields beside message. Failed responses become FrappeResourceError values with status, exception data, and server messages. The boundary reports one request failure once, even when more than one transport stage sees it.

References: src/…/frappeRequest.ts• L12-35 src/…/frappeRequest.ts• L61-77 src/…/frappeRequest.ts• L88-145 src/…/frappeRequest.ts• L146-231

Request transport

src/…/request.ts provides the generic transport contract used by the Frappe boundary. It supports query parameters for reads, JSON bodies for writes, abort signals, credentials, and response or error transforms. This keeps browser transport concerns separate from Frappe's response conventions.

References: src/…/request.ts• L1-17 src/…/request.ts• L23-59 src/…/request.ts• L61-93

Query and cache helpers

Data-fetching helpers turn reactive library inputs into stable values that can cross an HTTP or browser-storage boundary. They preserve structured Frappe query arguments and keep cached data separated by meaning and user session.

Query parameters

makeGetParams encodes plain objects and arrays as JSON so Frappe can read structured arguments such as filters and fields. parseFilters resolves reactive values and normalizes like filters for search behavior. Empty filter sets become null, which lets callers omit them instead of sending an empty query.

References: src/…/utils.ts• L4-31 src/…/utils.ts• L33-73

Cache identity

Cache helpers add a version to cache keys when the stored meaning changes. They also add the signed-in user's identity to browser cache keys. This prevents a later user from reading data left by an earlier user while preserving public data behavior for guests.

References: src/…/utils.ts• L76-121 src/…/utils.ts• L124-130

Browser file handling

Browser file services give upload-capable components a shared contract for validation, progress, results, and failure states. They support both reactive component use and direct promise-based use, so higher-level file features do not need separate upload rules.

Upload contract

src/…/useFileUpload.ts sends a file to the Frappe upload service and returns the created file record. An upload is private by default unless the caller explicitly requests a public file. The service can enforce an app-provided size limit, report progress, cancel through an abort signal, and split large files when the server supports chunked uploads.

The service classifies failures as file-size, network, server, or abort errors. useFileUpload exposes the same operation with reactive state, while the standalone upload function supports callers that only need a promise. The event-style FileUploadHandler adapts this contract for components that consume start, progress, finish, and error events.

For the full upload sequence and server integration contract, see File upload lifecycle.

References: src/…/useFileUpload.ts• L10-38 src/…/useFileUpload.ts• L41-114 src/…/useFileUpload.ts• L158-195 src/…/fileUploadHandler.ts• L3-57

File size policy

src/…/fileSize.ts is the shared source for size limits and user-facing size messages. It distinguishes a file rejected before a request from a file rejected by a proxy or server. This lets components show a useful reason without duplicating size rules.

References: src/…/fileSize.ts• L1-18 src/…/fileSize.ts• L21-46 src/…/useFileUpload.ts• L197-237

File conversion

src/…/file-to-base64.ts converts a browser File into a data URL when an editor flow needs file content in browser memory. It complements server upload; it does not replace the upload result or its access rules.

References: src/…/file-to-base64.ts• L1-12 src/…/media-upload-engine.ts• L22-24

URL safety

URL safety services protect browser-facing links and uploaded-file references before the library renders or uses them. They use the browser URL parser and explicit scheme or host rules rather than treating arbitrary strings as trusted URLs.

URL validation

safeHref permits relative links and approved link schemes. isSafeUrl checks absolute URLs against a caller-provided scheme set, and matchesHostname checks exact hosts or dot-boundary subdomains. Components and editor features use these rules for navigation, attachments, pasted links, uploaded files, and embedded content.

References: src/…/url-safety.ts• L13-31 src/…/url-safety.ts• L33-80 src/…/url-safety.ts• L82-114 src/…/iframe-allowlist.ts• L7-18

Service flow

The utility layer moves app policy into shared boundaries before a request or browser-facing file result reaches a component.

flowchart LR
  App[Application settings] --> Config[Shared configuration]
  Config --> Request[Frappe request boundary]
  Config --> Upload[File upload service]
  Request --> Resources[Library resources]
  Upload --> FileRecord[Uploaded file record]
  FileRecord --> Safety[URL safety checks]
  Safety --> Browser[Rendered browser feature]

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep FrappeUIConfig names and their consumers aligned. A setting can silently have no effect if its key changes in only one layer.
  • Preserve the response distinction between normal Frappe messages and the full login payload when changing request unwrapping.
  • Keep request error reporting one-shot across both response parsing and transport failure paths.
  • Keep upload error kinds and progress units consistent across upload, useFileUpload, and FileUploadHandler.
  • Treat maxFileSize and uploadChunkSize as contracts with both the app's boot data and the server's upload support.
  • Keep cache-key versioning and user namespacing aligned with the data shape and session boundary.
  • Apply URL safety checks before adding new browser-facing link, file, or embed paths.

Important failure modes

TriggerConsequenceGuard
A duplicated package copy does not share configuration stateComponents read defaults while app services use configured valuesStore process-wide configuration through the shared module singleton
A remote base URL is used with cookie authentication but credentials are omittedThe request reaches the site without the user's sessionUse the base-URL credential behavior or set the request credential mode deliberately
A server or proxy rejects a file after client validationThe user sees a generic upload failure or an incomplete upload statePreserve the upload error kind and the server-size message path
Chunking is enabled against a server without chunk supportFile pieces can be saved as separate broken filesEnable chunking only for a server that supports the chunk upload contract
A cache key is shared across users or old data shapesOne user can read stale or another user's cached dataKeep cache versioning and session namespacing in the key path
An untrusted URL reaches a link or embed without validationThe browser can navigate to or load an unsafe targetValidate its scheme and host with the shared URL safety services

Key files

FileWhy to read it
src/…/config.tsDefines the app-wide settings contract used by the utility layer.
src/…/frappeRequest.tsShows how generic requests become Frappe API interactions and errors.
src/…/request.tsDefines the transport capabilities available to request integrations.
src/…/utils.tsExplains query shaping and browser cache identity.
src/…/useFileUpload.tsDefines the shared upload result, progress, cancellation, and error contract.
src/…/fileUploadHandler.tsShows the event-oriented adapter used by file upload components.
src/…/fileSize.tsCentralizes file-size policy and messages.
src/…/url-safety.tsDefines the shared rules for browser-facing URLs and hosts.