Extensions are the primary way to add custom functionality to your EverShop store. They allow you to encapsulate features like API endpoints, event subscribers, cron jobs, and GraphQL types without modifying the core codebase.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Antony-Figueroa/my-evershop-app/llms.txt
Use this file to discover all available pages before exploring further.
What is an Extension?
An extension is a modular package that can contain:- API Endpoints - RESTful routes for custom operations
- Event Subscribers - React to system events
- Cron Jobs - Scheduled background tasks
- GraphQL Types - Custom data types and resolvers
- Page Components - Server-side rendered React components
- Middleware - Custom request processing logic
Directory Structure
A typical extension follows this structure:Creating Your First Extension
{
"name": "my-extension",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"scripts": {
"tsc": "tsc"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
{
"compilerOptions": {
"module": "NodeNext",
"target": "ES2018",
"lib": ["dom", "dom.iterable", "esnext"],
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"declaration": true,
"sourceMap": true,
"allowJs": true,
"checkJs": false,
"jsx": "react",
"outDir": "./dist",
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"allowArbitraryExtensions": true,
"strictNullChecks": true,
"isolatedModules": false,
"baseUrl": ".",
"rootDir": "./src"
},
"include": ["src"]
}
{
"system": {
"extensions": [
{
"name": "my-extension",
"resolve": "extensions/my-extension",
"enabled": true
}
]
}
}
Bootstrap File
Thebootstrap.ts file is the entry point for your extension. It’s executed when the application starts and is ideal for registering cron jobs, initializing services, or performing setup tasks.
Example: Registering a Cron Job
Here’s a real example from the sample extension:src/bootstrap.ts
The
bootstrap.ts file is optional. Only create it if you need to perform initialization tasks.Extension Configuration
Enabling/Disabling Extensions
To enable or disable an extension, modifyconfig/default.json:
Environment-Specific Configuration
You can override settings in environment-specific config files:Real-World Example: Sample Extension
The EverShop repository includes a complete sample extension that demonstrates all extension features:Best Practices
- Modular Organization - Keep related files together in feature-specific directories
- Naming Conventions - Use descriptive names that reflect the extension’s purpose
- Environment Variables - Store sensitive data in
.envfiles, not in configuration - Error Handling - Always implement proper error handling in API endpoints and subscribers
- Documentation - Include a
Readme.mdfile explaining what your extension does
Common Patterns
Extension with API Only
Extension with Subscribers Only
Extension with GraphQL
Troubleshooting
Extension Not Loading
- Verify the extension is registered in
config/default.json - Ensure
enabledis set totrue - Run
npm run buildto rebuild the application - Check for TypeScript compilation errors
Build Errors
- Verify
tsconfig.jsonis properly configured - Check that all imports are correct
- Ensure dependencies are installed:
npm install
Next Steps
API Endpoints
Learn how to create RESTful API endpoints
Event Subscribers
React to system events with subscribers
Cron Jobs
Schedule background tasks
Page Components
Build custom page components