Plugins › Escape hatches
Introduction
Content
Using content
Plugins
Operations
Deploy
Recipes
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 want | Use | |
|---|---|---|
| A route of your own: a report, a payment webhook, an import | endpoints, with access | Endpoints |
| Several writes that all happen or none do | cms.transaction() | Transactions |
| Joins, totals and queries the Local API can't express | cms.sql`…` | Raw SQL |
| Code that runs when a document is saved, deleted or read | Collection hooks | Hooks |
| After-hooks and webhooks that happen only if the save did | outbox: true | Outbox |
| To work out the user or a context (a tenant, a site) per request | onRequest | Multi-tenant |
| To change every API response (headers, logging) | onResponse | Configuration reference |
| To report failures (e.g. to Sentry) or send your own error body | onError | Configuration reference |
| A button in the admin that runs your server code | actions | Actions |
| Work on a schedule, retried when it fails | jobs | Jobs |
Events of your own (order.paid), to webhooks and listeners | events, cms.emit(), cms.on() | Your own events |
| Your site's pages to follow changes as they are saved | realtime: true, subscribe() | Realtime |
easy-cms <command> commands of your own | cliCommands | CLI |
| SQL of your own in the migrations: tables, views, indexes | migrate:create --empty | CLI |
| To move data while the schema changes | migrate:create --data | CLI |
| Sample or starting content | easy-cms seed | CLI |
| A field type with its own input | defineFieldType() | Custom field types |
| Several of these, shipped together | A plugin: (config) => config | Writing 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 withcms.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 want | Use | |
|---|---|---|
| Your own input instead of a field's, or a panel below it | admin.component, admin.after | Admin components |
| Panels in the edit page's side column | admin.sidebar | Admin components |
Pages of your own (a POS, stock, approvals) inside /admin | admin.pages | Pages and dashboard panels |
| Panels on the dashboard | admin.dashboard | Pages and dashboard panels |
| What an element receives and sends back | value, api(), change… | What the element receives |
| To write those components in Vue, React or Svelte | easy-cms build:admin | Vue, React or Svelte |
| An admin app of your own instead of this one | admin: { 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.