Files
medusa-store/www/apps/docs/content/references/services/classes/services.MiddlewareService.mdx
Shahed Nasser bb87db8342 docs: prep for v2 documentation (#6710)
This PR includes documentation that preps for v2 docs (but doesn't introduce new docs).

_Note: The number of file changes in the PR is due to find-and-replace within the `references` which is unavoidable. Let me know if I should move it to another PR._

## Changes

- Change Medusa version in base OAS used for v2.
- Fix to docblock generator related to not catching all path parameters.
- Added typedoc plugin that generates ER Diagrams, which will be used specifically for data model references in commerce modules.
- Changed OAS tool to output references in `www/apps/api-reference/specs-v2` directory when the `--v2` option is used.
- Added a version switcher to the API reference to switch between V1 and V2. This switcher is enabled by an environment variable, so it won't be visible/usable at the moment.
- Upgraded docusaurus to v3.0.1
- Added new Vale rules to ensure correct spelling of Medusa Admin and module names.
- Added new components to the `docs-ui` package that will be used in future documentation changes.
2024-03-18 07:47:35 +00:00

120 lines
6.0 KiB
Plaintext

---
displayed_sidebar: servicesSidebar
---
import TypeList from "@site/src/components/TypeList"
# MiddlewareService
Orchestrates dynamic middleware registered through the Medusa Middleware API
## constructor
___
## Properties
<TypeList types={[{"name":"postAuthentication_","type":"`middlewareType`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"preAuthentication_","type":"`middlewareType`[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"preCartCreation_","type":"RequestHandler&#60;ParamsDictionary, any, any, ParsedQs, Record&#60;string, any&#62;&#62;[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"routers","type":"`Record<string, Router[]>`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="MiddlewareService"/>
___
## Methods
### addRouter
#### Parameters
<TypeList types={[{"name":"path","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"router","type":"`Router`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addRouter"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="addRouter"/>
### getRouters
#### Parameters
<TypeList types={[{"name":"path","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="getRouters"/>
#### Returns
<TypeList types={[{"name":"Router[]","type":"`Router`[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="getRouters"/>
### validateMiddleware\_
Validates a middleware function, throws if fn is not of type function.
#### Parameters
<TypeList types={[{"name":"fn","type":"`unknown`","description":"the middleware function to validate.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="validateMiddleware_"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"nothing if the middleware is a function","expandable":false,"children":[]}]} sectionTitle="validateMiddleware_"/>
### addPostAuthentication
Adds a middleware function to be called after authentication is completed.
#### Parameters
<TypeList types={[{"name":"middleware","type":"`middlewareHandlerType`","description":"the middleware function. Should return a\n middleware function.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`Record<string, unknown>`","description":"the arguments that will be passed to the\n middleware","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addPostAuthentication"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"void","expandable":false,"children":[]}]} sectionTitle="addPostAuthentication"/>
### addPreAuthentication
Adds a middleware function to be called before authentication is completed.
#### Parameters
<TypeList types={[{"name":"middleware","type":"`middlewareHandlerType`","description":"the middleware function. Should return a\n middleware function.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"options","type":"`Record<string, unknown>`","description":"the arguments that will be passed to the\n middleware","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addPreAuthentication"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"void","expandable":false,"children":[]}]} sectionTitle="addPreAuthentication"/>
### addPreCartCreation
Adds a middleware function to be called before cart creation
#### Parameters
<TypeList types={[{"name":"middleware","type":"RequestHandler&#60;ParamsDictionary, any, any, ParsedQs, Record&#60;string, any&#62;&#62;","description":"the middleware function. Should return a\n middleware function.","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="addPreCartCreation"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Adds a middleware function to be called before cart creation","expandable":false,"children":[]}]} sectionTitle="addPreCartCreation"/>
### usePostAuthentication
Adds post authentication middleware to an express app.
#### Parameters
<TypeList types={[{"name":"app","type":"`Router`","description":"the express app to add the middleware to","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="usePostAuthentication"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Adds post authentication middleware to an express app.","expandable":false,"children":[]}]} sectionTitle="usePostAuthentication"/>
### usePreAuthentication
Adds pre authentication middleware to an express app.
#### Parameters
<TypeList types={[{"name":"app","type":"`Router`","description":"the express app to add the middleware to","optional":false,"defaultValue":"","expandable":false,"children":[]}]} sectionTitle="usePreAuthentication"/>
#### Returns
<TypeList types={[{"name":"void","type":"`void`","optional":false,"defaultValue":"","description":"Adds pre authentication middleware to an express app.","expandable":false,"children":[]}]} sectionTitle="usePreAuthentication"/>
### usePreCartCreation
#### Returns
<TypeList types={[{"name":"RequestHandler&#60;ParamsDictionary, any, any, ParsedQs, Record&#60;string, any&#62;&#62;[]","type":"RequestHandler&#60;ParamsDictionary, any, any, ParsedQs, Record&#60;string, any&#62;&#62;[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} sectionTitle="usePreCartCreation"/>