Skip to Content
AutomateFile-Based Extensions

File-Based Extensions

File-based extensions are a feature of the Supabase backend. On the Buildpad Engine backend, use runtime extensions and custom services instead.

File-based extensions require access to the BuildPad Docker image to mount the extensions/ directory. Contact the BuildPad team to get access.

File-based extensions are JavaScript modules placed in the extensions/ directory. They are loaded at server startup and require a restart to pick up changes.

Structure

      • index.mjs

Module format

Every extension exports a register(sdk) function:

// extensions/my-extension/index.mjs export function register(sdk) { const { emitter, createItemsService, registerRoutes } = sdk; // Action hook — runs after item creation emitter.onAction('articles.items.create', async (meta, context) => { console.log('Article created:', meta.key); }); // Filter hook — runs before item creation, can modify payload emitter.onFilter('articles.items.create', async (payload, meta, context) => { if (!payload.title) throw new Error('Title is required'); return { ...payload, slug: payload.title.toLowerCase().replace(/\s+/g, '-'), }; }); }

Extensions are loaded at startup. Restart the server to pick up new file-based extensions.

SDK reference

SDK exportDescription
emitter.onAction(event, handler)Register non-blocking action hook
emitter.onFilter(event, handler)Register blocking filter hook
emitter.offAction(event, handler)Unregister action hook
emitter.offFilter(event, handler)Unregister filter hook
createItemsService(collection)Create an ItemsService instance
createVersionService()Create a VersionService instance
registerRoutes(config)Register custom REST endpoints

Custom REST endpoints

export function register(sdk) { sdk.registerRoutes({ name: 'my-extension', basePath: '/customers', // accessible at /api/ext/customers/* description: 'Customer API', routes: [ { method: 'GET', path: '/', description: 'List customers', requiredPermission: 'customers.read', handler: async (request, context) => { const { supabase, accountability } = context; const { data } = await supabase.from('customers').select('*'); return Response.json({ data }); }, }, { method: 'POST', path: '/', requiredPermission: 'customers.create', handler: async (request, context) => { const body = await request.json(); // ... create logic return Response.json({ data: customer }, { status: 201 }); }, }, ], }); }

All extension routes are available at /api/ext/{basePath}/.

TypeScript types

import type { FilterHandler, ActionHandler, EventContext, Accountability, } from '@microbuild/sdk';