Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,124 @@
}
}
}
},
"/api/marketplace/plugins": {
"get": {
"summary": "List all plugins",
"description": "Returns all registered community plugins from the marketplace.",
"responses": {
"200": {
"description": "Plugin list",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["plugins", "total"],
"properties": {
"plugins": { "type": "array", "items": { "$ref": "#/components/schemas/PluginRecord" } },
"total": { "type": "integer" }
}
}
}
}
}
}
},
"post": {
"summary": "Register a new plugin",
"description": "Registers a new community plugin manifest. Requires authentication.",
"security": [{ "bearerAuth": [] }],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/PluginManifest" }
}
}
},
"responses": {
"201": {
"description": "Plugin registered",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/PluginRecord" }
}
}
},
"400": { "description": "Validation error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
"401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
"409": { "description": "Plugin already registered", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
}
}
},
"/api/marketplace/plugins/{id}": {
"get": {
"summary": "Get a plugin by ID",
"parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
"responses": {
"200": { "description": "Plugin found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PluginRecord" } } } },
"404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
}
},
"delete": {
"summary": "Remove a plugin from the registry",
"security": [{ "bearerAuth": [] }],
"parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
"responses": {
"204": { "description": "Plugin removed" },
"401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
"404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
}
}
},
"/api/marketplace/plugins/{id}/install": {
"post": {
"summary": "Install a plugin",
"description": "Marks a plugin as installed and fires the install hook. Requires authentication.",
"security": [{ "bearerAuth": [] }],
"parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
"responses": {
"200": {
"description": "Plugin installed",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": ["plugin"],
"properties": {
"plugin": { "$ref": "#/components/schemas/PluginRecord" },
"hook": {
"nullable": true,
"type": "object",
"properties": {
"ok": { "type": "boolean" },
"hook": { "type": "string" },
"pluginId": { "type": "string" },
"sandboxed": { "type": "boolean" }
}
}
}
}
}
}
},
"400": { "description": "Bad request", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
"401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
"404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
"409": { "description": "Already installed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
}
},
"delete": {
"summary": "Uninstall a plugin",
"security": [{ "bearerAuth": [] }],
"parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
"responses": {
"200": { "description": "Plugin uninstalled", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PluginRecord" } } } },
"400": { "description": "Not installed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
"401": { "description": "Unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } },
"404": { "description": "Not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }
}
}
}
},
"components": {
Expand All @@ -985,6 +1103,34 @@
}
},
"schemas": {
"PluginManifest": {
"type": "object",
"required": ["id", "name", "version", "hooks"],
"properties": {
"id": { "type": "string", "minLength": 3, "maxLength": 64, "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
"name": { "type": "string", "minLength": 1, "maxLength": 128 },
"version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$" },
"description": { "type": "string", "maxLength": 512 },
"author": { "type": "string", "maxLength": 128 },
"hooks": {
"type": "array",
"minItems": 1,
"items": { "type": "string", "enum": ["before_charge", "after_charge", "on_refund", "on_quota_exceeded"] }
},
"source_url": { "type": "string", "format": "uri" }
}
},
"PluginRecord": {
"type": "object",
"required": ["manifest", "status", "created_at"],
"properties": {
"manifest": { "$ref": "#/components/schemas/PluginManifest" },
"status": { "type": "string", "enum": ["available", "installed"] },
"installed_by": { "type": "string", "nullable": true },
"installed_at": { "type": "string", "nullable": true },
"created_at": { "type": "string" }
}
},
"BillingDeductRequest": {
"type": "object",
"required": [
Expand Down
4 changes: 4 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createExplainRouter } from './routes/admin/explain.js';
import { createUsageAnomaliesRouter } from './routes/admin/usage/anomalies.js';
import { createApiRouter } from './routes/index.js';
import { createApisRouter } from './routes/apis.js';
import { createPluginsRouter } from './routes/marketplace/plugins.js';
import { pool } from './db.js';
import {
InMemoryUsageEventsRepository,
Expand Down Expand Up @@ -300,6 +301,9 @@ export const createApp = (dependencies?: Partial<AppDependencies>) => {
}),
);

// Plugin marketplace — community-developed billing rule plugins
app.use('/api/marketplace/plugins', createPluginsRouter());

// Mount all routes including billing and limits
app.use('/api', createApiRouter({
restRateLimit,
Expand Down
Loading