n8n/packages/@n8n/backend-services
Charlie Kolb e5f56a77bb
refactor(core): Move the response errors into @n8n/backend-services (no-changelog)
Move the generic ResponseError hierarchy (BadRequestError, NotFoundError,
ForbiddenError, ...) into @n8n/backend-services and point every cli
import at the package root. 29 backend modules import these classes.

Feature-specific response errors (MFA codes, license EULA, credential
and workflow transfer, webhook not found, workflow activation and
validation) stay in cli next to the code that throws them. They extend
the generic classes from the package. WorkflowPublishBlockedError moves
because three modules import it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 10:25:06 +02:00
..
src refactor(core): Move the response errors into @n8n/backend-services (no-changelog) 2026-09-16 10:25:06 +02:00
eslint.config.mjs build(core): Add the @n8n/backend-services package (no-changelog) 2026-09-16 10:24:43 +02:00
package.json refactor(core): Move the response errors into @n8n/backend-services (no-changelog) 2026-09-16 10:25:06 +02:00
README.md refactor(core): Move the response errors into @n8n/backend-services (no-changelog) 2026-09-16 10:25:06 +02:00
tsconfig.build.json build(core): Add the @n8n/backend-services package (no-changelog) 2026-09-16 10:24:43 +02:00
tsconfig.json refactor(core): Move the response errors into @n8n/backend-services (no-changelog) 2026-09-16 10:25:06 +02:00
vite.config.ts build(core): Add the @n8n/backend-services package (no-changelog) 2026-09-16 10:24:43 +02:00

@n8n/backend-services

Backend services and HTTP error classes that many backend modules share.

Why this package exists

Backend modules live in packages/cli/src/modules/<name> today. Most of them import a small set of services from the rest of cli. A module cannot move into its own workspace package while those imports point at @/... paths in cli.

This package is the home for that shared set. It sits above @n8n/db and below n8n (cli) in the dependency graph:

flowchart TD
  cli["n8n (cli) and backend modules"] --> sc["@n8n/backend-services"]
  sc --> db["@n8n/db"]
  sc --> bc["@n8n/backend-common"]
  db --> bc

@n8n/backend-common holds the foundation that @n8n/db also needs (logger, license state, module registry, locks). @n8n/backend-services holds business and infrastructure services that need the persistence layer or that only cli and the modules consume.

What lives here

Export Purpose
ResponseError and its subclasses (BadRequestError, NotFoundError, ForbiddenError, ...) Errors that map to an HTTP status code in a REST response

Rules for adding code

  • The code must not import from n8n (cli). If it needs a cli seam, define a narrow DI port here and bind it in cli at bootstrap.
  • At least two backend modules must use the code. A service that one module uses belongs to that module.
  • Keep the file layout of cli (errors/, services/). A move with git mv keeps the history readable.
  • Add each new export to src/index.ts. Consumers import from the package root only.