Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

docs(registry): add vendor middleware setup to requests docs

vholika0cbd5f1ecbd
diff --git a/packages/registry/registry.json b/packages/registry/registry.json
index 61fb80936..8cceeab52 100644
--- a/packages/registry/registry.json
+++ b/packages/registry/registry.json
@@ -704,7 +704,7 @@
"description": "Admin approval system powered by the Custom Fields module. Admins can list, review, accept or reject entity requests.",
"dependencies": [],
"registryDependencies": [],
- "docs": "## Prerequisites\n\nThis block requires the **Custom Fields module** (`@mercurjs/core-plugin/modules/custom-fields`). Make sure it is registered in your `medusa-config.ts`.\n\n## Configuration\n\nAdd request-related custom fields to the entities you want to support approval workflows for. Product already has a built-in `status` field, so you only need to configure custom fields for other entities.\n\nAdd these fields to your Custom Fields module options in `medusa-config.ts`:\n\n```ts\n{\n resolve: \"@mercurjs/core-plugin/modules/custom-fields\",\n options: {\n customFields: {\n ProductCollection: {\n request_status: {\n type: \"enum\",\n enum: [\"draft\", \"pending\", \"accepted\", \"rejected\"],\n defaultValue: \"draft\",\n },\n submitter_id: { type: \"string\", nullable: true },\n reviewer_id: { type: \"string\", nullable: true },\n reviewer_note: { type: \"text\", nullable: true },\n },\n // Add the same fields to other entities as needed:\n // ProductCategory, ProductType, ProductTag\n },\n },\n}\n```\n\n## Middlewares\n\nAdd the request middlewares to your `api/middlewares.ts`:\n\n```ts\nimport { defineMiddlewares } from \"@medusajs/medusa\";\nimport { adminRequestsMiddlewares } from \"./admin/requests/middlewares\";\n\nexport default defineMiddlewares({\n routes: [...adminRequestsMiddlewares],\n});\n```\n\nIf you already have a `middlewares.ts` file, merge the middleware imports and spread them into your existing `routes` array.\n\n## Database Migrations\n\nAfter updating the custom fields configuration, run migrations:\n\n```bash\nnpx medusa db:migrate\n```\n\n## Run codegen\n\nAfter installing the block, regenerate SDK types:\n\n```bash\nnpx @mercurjs/cli@canary codegen\n```\n\n## API Endpoints\n\n- `GET /admin/requests/:type` — List entities with request custom fields (filterable by `request_status`, `submitter_id`)\n- `GET /admin/requests/:type/:id` — Retrieve entity with request custom fields\n- `POST /admin/requests/:type/:id/accept` — Accept a request\n- `POST /admin/requests/:type/:id/reject` — Reject a request\n\nSupported `:type` values: `product_collection`, `product_category`, `product_type`, `product_tag`",
+ "docs": "## Prerequisites\n\nThis block requires the **Custom Fields module** (`@mercurjs/core-plugin/modules/custom-fields`). Make sure it is registered in your `medusa-config.ts`.\n\n## Configuration\n\nAdd request-related custom fields to the entities you want to support approval workflows for. Product already has a built-in `status` field, so you only need to configure custom fields for other entities.\n\nAdd these fields to your Custom Fields module options in `medusa-config.ts`:\n\n```ts\n{\n resolve: \"@mercurjs/core-plugin/modules/custom-fields\",\n options: {\n customFields: {\n ProductCollection: {\n request_status: {\n type: \"enum\",\n enum: [\"draft\", \"pending\", \"accepted\", \"rejected\"],\n defaultValue: \"draft\",\n },\n submitter_id: { type: \"string\", nullable: true },\n reviewer_id: { type: \"string\", nullable: true },\n reviewer_note: { type: \"text\", nullable: true },\n },\n // Add the same fields to other entities as needed:\n // ProductCategory, ProductType, ProductTag\n },\n },\n}\n```\n\n## Middlewares\n\nAdd the request middlewares to your `api/middlewares.ts`:\n\n```ts\nimport { defineMiddlewares } from \"@medusajs/medusa\";\nimport { adminRequestsMiddlewares } from \"./admin/requests/middlewares\";\nimport { vendorProductCollectionRequestsMiddlewares } from \"./vendor/product-collections/middlewares\";\nimport { vendorProductCategoryRequestsMiddlewares } from \"./vendor/product-categories/middlewares\";\nimport { vendorProductTypeRequestsMiddlewares } from \"./vendor/product-types/middlewares\";\nimport { vendorProductTagRequestsMiddlewares } from \"./vendor/product-tags/middlewares\";\n\nexport default defineMiddlewares({\n routes: [\n ...adminRequestsMiddlewares,\n ...vendorProductCollectionRequestsMiddlewares,\n ...vendorProductCategoryRequestsMiddlewares,\n ...vendorProductTypeRequestsMiddlewares,\n ...vendorProductTagRequestsMiddlewares,\n ],\n});\n```\n\nIf you already have a `middlewares.ts` file, merge the middleware imports and spread them into your existing `routes` array.\n\n## Database Migrations\n\nAfter updating the custom fields configuration, run migrations:\n\n```bash\nnpx medusa db:migrate\n```\n\n## Run codegen\n\nAfter installing the block, regenerate SDK types:\n\n```bash\nnpx @mercurjs/cli@canary codegen\n```\n\n## API Endpoints\n\n### Admin\n\n- `GET /admin/requests/:type` — List entities with request custom fields (filterable by `request_status`, `submitter_id`)\n- `GET /admin/requests/:type/:id` — Retrieve entity with request custom fields\n- `POST /admin/requests/:type/:id/accept` — Accept a request\n- `POST /admin/requests/:type/:id/reject` — Reject a request\n\nSupported `:type` values: `product_collection`, `product_category`, `product_type`, `product_tag`\n\n### Vendor\n\n- `GET /vendor/product-collections` — List vendor's collection requests\n- `POST /vendor/product-collections` — Create a collection request\n- `GET /vendor/product-categories` — List vendor's category requests\n- `POST /vendor/product-categories` — Create a category request\n- `GET /vendor/product-types` — List vendor's type requests\n- `POST /vendor/product-types` — Create a type request\n- `GET /vendor/product-tags` — List vendor's tag requests\n- `POST /vendor/product-tags` — Create a tag request",
"files": [
{
"path": "requests/types/index.ts",