* adjusted configurations * enhancements to tool and configurations * change reference in docs * fixed issue in workflows reference * added project name * more optimizations * fix context error * added a types reference * resolved missing types * fix reference reflection types not having children * add an expand url parameter * added new option to the README * added details about new option
370 lines
6.6 KiB
Plaintext
370 lines
6.6 KiB
Plaintext
---
|
|
displayed_sidebar: servicesSidebar
|
|
---
|
|
|
|
import ParameterTypes from "@site/src/components/ParameterTypes"
|
|
|
|
# MiddlewareService
|
|
|
|
Orchestrates dynamic middleware registered through the Medusa Middleware API
|
|
|
|
## constructor
|
|
|
|
___
|
|
|
|
## Properties
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"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<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "routers",
|
|
"type": "`Record<string, Router[]>`",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
## Methods
|
|
|
|
### addPostAuthentication
|
|
|
|
Adds a middleware function to be called after authentication is completed.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"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": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "void",
|
|
"type": "`void`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "void",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### addPreAuthentication
|
|
|
|
Adds a middleware function to be called before authentication is completed.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"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": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "void",
|
|
"type": "`void`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "void",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### addPreCartCreation
|
|
|
|
Adds a middleware function to be called before cart creation
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "middleware",
|
|
"type": "RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>",
|
|
"description": "the middleware function. Should return a\n middleware function.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "void",
|
|
"type": "`void`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### addRouter
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "path",
|
|
"type": "`string`",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
},
|
|
{
|
|
"name": "router",
|
|
"type": "`Router`",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "void",
|
|
"type": "`void`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### getRouters
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "path",
|
|
"type": "`string`",
|
|
"description": "",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "Router[]",
|
|
"type": "`Router`[]",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### usePostAuthentication
|
|
|
|
Adds post authentication middleware to an express app.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "app",
|
|
"type": "`Router`",
|
|
"description": "the express app to add the middleware to",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "void",
|
|
"type": "`void`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### usePreAuthentication
|
|
|
|
Adds pre authentication middleware to an express app.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "app",
|
|
"type": "`Router`",
|
|
"description": "the express app to add the middleware to",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "void",
|
|
"type": "`void`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### usePreCartCreation
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]",
|
|
"type": "RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>[]",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"description": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
___
|
|
|
|
### validateMiddleware\_
|
|
|
|
Validates a middleware function, throws if fn is not of type function.
|
|
|
|
#### Parameters
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "fn",
|
|
"type": "`unknown`",
|
|
"description": "the middleware function to validate.",
|
|
"optional": false,
|
|
"defaultValue": "",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|
|
|
|
#### Returns
|
|
|
|
<ParameterTypes parameters={[
|
|
{
|
|
"name": "void",
|
|
"type": "`void`",
|
|
"optional": true,
|
|
"defaultValue": "",
|
|
"description": "nothing if the middleware is a function",
|
|
"expandable": false,
|
|
"children": []
|
|
}
|
|
]} />
|