Plugins › Escape hatches
Docs/Plugins/Escape hatches

Escape hatches

What you'll learn

Every place where your own TypeScript takes over from Easy CMS: routes, hooks, events, jobs, commands, tables and admin screens, and which of them go around access rules.

Before this page: Configuration, Access control.

Easy CMS gives you collections, an API and an admin from one config. When that is not enough, you write the part yourself, in the same project, and it still runs with the same users, roles and data. Each way out is listed here.

The rule behind them: the usual paths respect your access rules everywhere. A way around them exists, but you can see it in the code (overrideAccess, below), never by accident.

On the server

You wantUse
A route of your own: a report, a payment webhook, an importendpoints, with accessEndpoints
Several writes that all happen or none docms.transaction()Transactions
Joins, totals and queries the Local API can't expresscms.sql`…`Raw SQL
Code that runs when a document is saved, deleted or readCollection hooksHooks
After-hooks and webhooks that happen only if the save didoutbox: trueOutbox
To work out the user or a context (a tenant, a site) per requestonRequestMulti-tenant
To change every API response (headers, logging)onResponseConfiguration reference
To report failures (e.g. to Sentry) or send your own error bodyonErrorConfiguration reference
A button in the admin that runs your server codeactionsActions
Work on a schedule, retried when it failsjobsJobs
Events of your own (order.paid), to webhooks and listenersevents, cms.emit(), cms.on()Your own events
Your site's pages to follow changes as they are savedrealtime: true, subscribe()Realtime
easy-cms <command> commands of your owncliCommandsCLI
SQL of your own in the migrations: tables, views, indexesmigrate:create --emptyCLI
To move data while the schema changesmigrate:create --dataCLI
Sample or starting contenteasy-cms seedCLI
A field type with its own inputdefineFieldType()Custom field types
Several of these, shipped togetherA plugin: (config) => configWriting a plugin

All of them get cms, the Local API, so your code reads and writes content the same way the admin and REST do.

Your own tables

Easy CMS creates and changes only tables with its prefix (ecms_), so your app's own tables can live in the same database. See Sharing a database with your app.

  • Data Easy CMS should look after (access rules, hooks, the admin, REST): make it a collection. admin: { group: false } keeps it out of the menu.
  • Tables only your code uses: create them in a migration of your own (easy-cms migrate:create <name> --empty), so they are made with the rest wherever you deploy, and query them with cms.sql`…` (or your own client). Easy CMS adds no access rules or hooks to tables that are not collections.

In the admin

The admin is a prebuilt app. You extend it with Web Components, so any framework works (Vue, React, Svelte or none): easy-cms build:admin compiles your component to one ES module.

You wantUse
Your own input instead of a field's, or a panel below itadmin.component, admin.afterAdmin components
Panels in the edit page's side columnadmin.sidebarAdmin components
Pages of your own (a POS, stock, approvals) inside /adminadmin.pagesPages and dashboard panels
Panels on the dashboardadmin.dashboardPages and dashboard panels
What an element receives and sends backvalue, api(), change…What the element receives
To write those components in Vue, React or Svelteeasy-cms build:adminVue, React or Svelte
An admin app of your own instead of this oneadmin: { enabled: false }Turning the admin off

A page of your own can also embed another app of yours in an <iframe>.

Going around access rules

The Local API trusts your code: cms.find(), cms.update() and the rest skip access rules unless you pass the user.

// Your code, as the system: no access rules.
await cms.update('orders', id, { status: 'paid' })
 
// On behalf of someone: their access rules apply.
await cms.update('orders', id, { status: 'paid' }, { user, overrideAccess: false })

In an endpoint or action, pass { user, overrideAccess: false } whenever the request comes from a person, so they can't do there what the admin and REST would refuse them.

cms.sql always goes around them, and around hooks, validation and versions too: use it for reports and your own tables, and check who is asking before you run it for someone.

Next steps

  • Plugins: package your escape hatches to use in several projects.
  • Hooks: the order hooks run in, and what to watch for.
  • Local API: every method your code can call.
Edit this page on GitHubEasy CMS v1.56.0